Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(ns-json-schema-draft-7): use API Extractor for TypeScript rollup #4545

Merged
merged 2 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
"extends": "../../../../api-extractor.json"
}
11 changes: 0 additions & 11 deletions packages/apidom-ns-json-schema-draft-7/config/rollup/types.dist.js

This file was deleted.

8 changes: 4 additions & 4 deletions packages/apidom-ns-json-schema-draft-7/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
"unpkg": "./dist/apidom-ns-json-schema-draft-7.browser.min.js",
"main": "./src/index.cjs",
"exports": {
"types": "./types/dist.d.ts",
"types": "./types/apidom-ns-json-schema-draft-7.d.ts",
"import": "./src/index.mjs",
"require": "./src/index.cjs"
},
"types": "./types/dist.d.ts",
"types": "./types/apidom-ns-json-schema-draft-7.d.ts",
"scripts": {
"build": "npm run clean && run-p --max-parallel ${CPU_CORES:-2} typescript:declaration build:es build:cjs build:umd:browser",
"build:es": "cross-env BABEL_ENV=es babel src --out-dir src --extensions '.ts' --out-file-extension '.mjs' --root-mode 'upward'",
Expand All @@ -30,7 +30,7 @@
"test": "npm run build:es && cross-env BABEL_ENV=es babel test --out-dir test --extensions '.ts' --out-file-extension '.mjs' --root-mode 'upward' && cross-env NODE_ENV=test mocha",
"test:update-snapshots": "cross-env UPDATE_SNAPSHOT=1 mocha",
"typescript:check-types": "tsc --noEmit && tsc -p ./test/tsconfig.json --noEmit",
"typescript:declaration": "tsc -p tsconfig.declaration.json && rollup -c config/rollup/types.dist.js",
"typescript:declaration": "tsc -p tsconfig.declaration.json && api-extractor run -l -c ./config/api-extractor/api-extractor.json 2>&1 | shx grep -v 'Visitor_base'",
"prepack": "copyfiles -u 3 ../../LICENSES/* LICENSES && copyfiles -u 2 ../../NOTICE .",
"postpack": "rimraf NOTICE LICENSES"
},
Expand All @@ -54,7 +54,7 @@
"src/**/*.mjs",
"src/**/*.cjs",
"dist/",
"types/dist.d.ts",
"types/apidom-ns-json-schema-draft-7.d.ts",
"LICENSES",
"NOTICE",
"README.md",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import {
} from '@swagger-api/apidom-ns-json-schema-draft-6';

/* eslint-disable class-methods-use-this */

/**
* @public
*/
class JSONSchema extends JSONSchemaElement {
constructor(content?: Record<string, unknown>, meta?: Meta, attributes?: Attributes) {
super(content, meta, attributes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { LinkDescriptionElement } from '@swagger-api/apidom-ns-json-schema-draft

/**
* URI: https://datatracker.ietf.org/doc/html/draft-wright-json-schema-hyperschema-01#section-6
* @public
*/

class LinkDescription extends LinkDescriptionElement {
Expand Down
1 change: 1 addition & 0 deletions packages/apidom-ns-json-schema-draft-7/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export {
} from '@swagger-api/apidom-core';

export { default as mediaTypes, JSONSchemaDraft7MediaTypes } from './media-types.ts';
export type { Format } from './media-types.ts';

// eslint-disable-next-line no-restricted-exports
export { default } from './namespace.ts';
Expand Down
11 changes: 10 additions & 1 deletion packages/apidom-ns-json-schema-draft-7/src/media-types.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import { last } from 'ramda';
import { MediaTypes } from '@swagger-api/apidom-core';

type Format = 'generic' | 'json' | 'yaml';
/**
* @public
*/
export type Format = 'generic' | 'json' | 'yaml';

/**
* @public
*/
export class JSONSchemaDraft7MediaTypes extends MediaTypes<string> {
filterByFormat(format: Format = 'generic') {
const effectiveFormat = format === 'generic' ? 'schema;version' : format;
Expand All @@ -22,6 +28,9 @@ export class JSONSchemaDraft7MediaTypes extends MediaTypes<string> {
}
}

/**
* @public
*/
const mediaTypes = new JSONSchemaDraft7MediaTypes(
'application/schema;version=draft-07',
'application/schema+json;version=draft-07',
Expand Down
3 changes: 3 additions & 0 deletions packages/apidom-ns-json-schema-draft-7/src/namespace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import { JSONReferenceElement } from '@swagger-api/apidom-ns-json-schema-draft-6
import JSONSchemaElement from './elements/JSONSchema.ts';
import LinkDescriptionElement from './elements/LinkDescription.ts';

/**
* @public
*/
const jsonSchemaDraft7 = {
namespace: (options: NamespacePluginOptions) => {
const { base } = options;
Expand Down
6 changes: 6 additions & 0 deletions packages/apidom-ns-json-schema-draft-7/src/predicates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import LinkDescriptionElement from './elements/LinkDescription.ts';

export { isJSONReferenceElement } from '@swagger-api/apidom-ns-json-schema-draft-6';

/**
* @public
*/
export const isJSONSchemaElement = createPredicate(
({ hasBasicElementProps, isElementType, primitiveEq }) => {
return (element: unknown): element is JSONSchemaElement =>
Expand All @@ -15,6 +18,9 @@ export const isJSONSchemaElement = createPredicate(
},
);

/**
* @public
*/
export const isLinkDescriptionElement = createPredicate(
({ hasBasicElementProps, isElementType, primitiveEq }) => {
return (element: unknown): element is LinkDescriptionElement =>
Expand Down
6 changes: 6 additions & 0 deletions packages/apidom-ns-json-schema-draft-7/src/refractor/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import specification from './specification.ts';
import { keyMap, getNodeType } from '../traversal/visitor.ts';
import createToolbox from './toolbox.ts';

/**
* @public
*/
const refract = <T extends Element>(
value: unknown,
{
Expand Down Expand Up @@ -43,6 +46,9 @@ const refract = <T extends Element>(
});
};

/**
* @public
*/
export const createRefractor =
(specPath: string[]) =>
(value: unknown, options = {}) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,9 @@ const findElementFactory = (ancestor: any, keyName: string) => {
: keyMapping[keyName];
};

/**
* @public
*/
const plugin = () => () => {
return {
visitor: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,16 @@ import {

import JSONSchemaElement from '../../../elements/JSONSchema.ts';

/**
* @public
*/
export interface JSONSchemaVisitorOptions
extends FixedFieldsVisitorOptions,
FallbackVisitorOptions {}

/**
* @public
*/
class JSONSchemaVisitor extends Mixin(FixedFieldsVisitor, FallbackVisitor) {
public declare element: JSONSchemaElement;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,16 @@ import {

import LinkDescriptionElement from '../../../../elements/LinkDescription.ts';

/**
* @public
*/
export interface LinkDescriptionVisitorOptions
extends FixedFieldsVisitorOptions,
FallbackVisitorOptions {}

/**
* @public
*/
class LinkDescriptionVisitor extends Mixin(FixedFieldsVisitor, FallbackVisitor) {
public declare readonly element: LinkDescriptionElement;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import { keyMap as keyMapBase, isElement, Element } from '@swagger-api/apidom-core';

// getNodeType :: Node -> String
/**
* @public
*/
export const getNodeType = <T extends Element>(element: T): string | undefined => {
if (!isElement(element)) {
return undefined;
}
return `${element.element.charAt(0).toUpperCase() + element.element.slice(1)}Element`;
};

/**
* @public
*/
export const keyMap = {
JSONSchemaDraft7Element: ['content'],
JSONReferenceElement: ['content'],
Expand Down
Loading