Skip to content

Commit

Permalink
chore(ns-api-design-systems): use API Extractor for TypeScript rollup (
Browse files Browse the repository at this point in the history
  • Loading branch information
glowcloud authored Nov 25, 2024
1 parent a0cf66f commit cf569dc
Show file tree
Hide file tree
Showing 36 changed files with 182 additions and 17 deletions.
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-api-design-systems/config/rollup/types.dist.js

This file was deleted.

8 changes: 4 additions & 4 deletions packages/apidom-ns-api-design-systems/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
"unpkg": "./dist/apidom-ns-api-design-systems.browser.min.js",
"main": "./src/index.cjs",
"exports": {
"types": "./types/dist.d.ts",
"types": "./types/apidom-ns-api-design-systems.d.ts",
"import": "./src/index.mjs",
"require": "./src/index.cjs"
},
"types": "./types/dist.d.ts",
"types": "./types/apidom-ns-api-design-systems.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-api-design-systems.d.ts",
"LICENSES",
"NOTICE",
"README.md",
Expand Down
3 changes: 3 additions & 0 deletions packages/apidom-ns-api-design-systems/src/elements/Info.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { ObjectElement, StringElement, Attributes, Meta } from '@swagger-api/apidom-core';

/**
* @public
*/
class Info extends ObjectElement {
constructor(content?: Record<string, unknown>, meta?: Meta, attributes?: Attributes) {
super(content, meta, attributes);
Expand Down
3 changes: 3 additions & 0 deletions packages/apidom-ns-api-design-systems/src/elements/Main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import {

import InfoElement from './Info.ts';

/**
* @public
*/
class Main extends ObjectElement {
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 @@ -2,6 +2,9 @@ import { ObjectElement, StringElement, Attributes, Meta } from '@swagger-api/api

import RequirementLevelElement from './RequirementLevel.ts';

/**
* @public
*/
class Principle extends ObjectElement {
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 @@ -9,6 +9,9 @@ import {
import StandardIdentifierElement from './StandardIdentifier.ts';
import RequirementLevelElement from './RequirementLevel.ts';

/**
* @public
*/
class Requirement extends ObjectElement {
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
@@ -1,5 +1,8 @@
import { StringElement, Attributes, Meta } from '@swagger-api/apidom-core';

/**
* @public
*/
class RequirementLevel extends StringElement {
constructor(content?: string, meta?: Meta, attributes?: Attributes) {
super(content, meta, attributes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import {

import StandardIdentifierElement from './StandardIdentifier.ts';

/**
* @public
*/
class Scenario extends ObjectElement {
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 @@ -2,6 +2,9 @@ import { ObjectElement, StringElement, Attributes, Meta } from '@swagger-api/api

import RequirementLevelElement from './RequirementLevel.ts';

/**
* @public
*/
class Standard extends ObjectElement {
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
@@ -1,5 +1,8 @@
import { ArrayElement, Attributes, Meta } from '@swagger-api/apidom-core';

/**
* @public
*/
class StandardIdentifier extends ArrayElement {
constructor(content?: string[], meta?: Meta, attributes?: Attributes) {
super(content, meta, attributes);
Expand Down
3 changes: 3 additions & 0 deletions packages/apidom-ns-api-design-systems/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@ export {
} from '@swagger-api/apidom-core';

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

// eslint-disable-next-line no-restricted-exports
export { default } from './namespace.ts';

export type { default as specificationObj } from './refractor/specification.ts';

export { default as refractPluginOpenApi3_1StandardIdentifierSelectors } from './refractor/plugins/openapi-3-1/standard-identifier-selectors.ts';
export { default as refractPluginOpenApi3_1StandardIdentifierAccessors } from './refractor/plugins/openapi-3-1/standard-identifier-accessors.ts';
export { default as validateOpenAPI3_1 } from './validator/openapi-3-1/validator.ts';
Expand Down
11 changes: 10 additions & 1 deletion packages/apidom-ns-api-design-systems/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 ApiDesignSystemsMediaTypes extends MediaTypes<string> {
filterByFormat(format: Format = 'generic') {
const effectiveFormat = format === 'generic' ? 'apidesignsystems;version' : format;
Expand All @@ -24,6 +30,9 @@ export class ApiDesignSystemsMediaTypes extends MediaTypes<string> {
}
}

/**
* @public
*/
const mediaTypes = new ApiDesignSystemsMediaTypes(
'application/vnd.aai.apidesignsystems;version=2021-05-07',
'application/vnd.aai.apidesignsystems+json;version=2021-05-07',
Expand Down
3 changes: 3 additions & 0 deletions packages/apidom-ns-api-design-systems/src/namespace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import ScenarioElement from './elements/Scenario.ts';
import StandardElement from './elements/Standard.ts';
import StandardIdentifierElement from './elements/StandardIdentifier.ts';

/**
* @public
*/
const apiDesignSystems = {
namespace: (options: NamespacePluginOptions) => {
const { base } = options;
Expand Down
24 changes: 24 additions & 0 deletions packages/apidom-ns-api-design-systems/src/predicates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import ScenarioElement from './elements/Scenario.ts';
import StandardElement from './elements/Standard.ts';
import StandardIdentifierElement from './elements/StandardIdentifier.ts';

/**
* @public
*/
export const isMainElement = createPredicate(
({ hasBasicElementProps, isElementType, primitiveEq }) => {
return (element: unknown): element is MainElement =>
Expand All @@ -19,6 +22,9 @@ export const isMainElement = createPredicate(
},
);

/**
* @public
*/
export const isInfoElement = createPredicate(
({ hasBasicElementProps, isElementType, primitiveEq }) => {
return (element: unknown): element is InfoElement =>
Expand All @@ -29,6 +35,9 @@ export const isInfoElement = createPredicate(
},
);

/**
* @public
*/
export const isPrincipleElement = createPredicate(
({ hasBasicElementProps, isElementType, primitiveEq }) => {
return (element: unknown): element is PrincipleElement =>
Expand All @@ -39,6 +48,9 @@ export const isPrincipleElement = createPredicate(
},
);

/**
* @public
*/
export const isRequirementElement = createPredicate(
({ hasBasicElementProps, isElementType, primitiveEq }) => {
return (element: unknown): element is RequirementElement =>
Expand All @@ -49,6 +61,9 @@ export const isRequirementElement = createPredicate(
},
);

/**
* @public
*/
export const isRequirementLevelElement = createPredicate(
({ hasBasicElementProps, isElementType, primitiveEq }) => {
return (element: unknown): element is RequirementLevelElement =>
Expand All @@ -59,6 +74,9 @@ export const isRequirementLevelElement = createPredicate(
},
);

/**
* @public
*/
export const isScenarioElement = createPredicate(
({ hasBasicElementProps, isElementType, primitiveEq }) => {
return (element: unknown): element is ScenarioElement =>
Expand All @@ -69,6 +87,9 @@ export const isScenarioElement = createPredicate(
},
);

/**
* @public
*/
export const isStandardElement = createPredicate(
({ hasBasicElementProps, isElementType, primitiveEq }) => {
return (element: unknown): element is StandardElement =>
Expand All @@ -79,6 +100,9 @@ export const isStandardElement = createPredicate(
},
);

/**
* @public
*/
export const isStandardIdentifierElement = createPredicate(
({ hasBasicElementProps, isElementType, primitiveEq }) => {
return (element: unknown): element is StandardIdentifierElement =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import {
isObjectElement,
} from '@swagger-api/apidom-ns-openapi-3-1';

/**
* @public
*/
const plugin = () => () => {
return {
visitor: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import {
isObjectElement,
} from '@swagger-api/apidom-ns-openapi-3-1';

/**
* @public
*/
const plugin = () => () => {
let operationIdentifiers: string[][] = [];
let responseIdentifiers: string[][] = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import MainScenariosVisitor from './visitors/api-design-systems/main/ScenariosVi
* existing ones by manipulating it.
*
* Note: Specification object allows to use absolute internal JSON pointers.
* @public
*/
const specification = {
visitors: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import Visitor, { VisitorOptions } from './Visitor.ts';

export type { VisitorOptions as FallbackVisitorOptions };

/**
* @public
*/
class FallbackVisitor extends Visitor {
enter(element: Element) {
this.element = cloneDeep(element);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@ import type specification from '../specification.ts';
/**
* This is a base class for every visitor that does
* internal look-ups to retrieve other child visitors.
* @public
*/
export interface SpecificationVisitorOptions extends VisitorOptions {
readonly specObj: typeof specification;
}

/**
* @public
*/
class SpecificationVisitor extends Visitor {
protected readonly specObj: typeof specification;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import { Element, ObjectElement, hasElementSourceMap, deepmerge } from '@swagger-api/apidom-core';

/**
* @public
*/
export interface VisitorOptions {}

/**
* @public
*/
class Visitor {
public element!: Element;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,14 @@ import FixedFieldsVisitor, {
FixedFieldsVisitorOptions,
} from '../../generics/FixedFieldsVisitor.ts';

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@ import { ArrayElement, Element, BREAK } from '@swagger-api/apidom-core';
import FallbackVisitor, { FallbackVisitorOptions } from '../../FallbackVisitor.ts';
import SpecificationVisitor, { SpecificationVisitorOptions } from '../../SpecificationVisitor.ts';

/**
* @public
*/
export interface PrinciplesVisitorOptions
extends SpecificationVisitorOptions,
FallbackVisitorOptions {}

/**
* @public
*/
class PrinciplesVisitor extends Mixin(SpecificationVisitor, FallbackVisitor) {
public declare readonly element: ArrayElement;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@ import { ArrayElement, Element, BREAK } from '@swagger-api/apidom-core';
import FallbackVisitor, { FallbackVisitorOptions } from '../../FallbackVisitor.ts';
import SpecificationVisitor, { SpecificationVisitorOptions } from '../../SpecificationVisitor.ts';

/**
* @public
*/
export interface ScenariosVisitorOptions
extends SpecificationVisitorOptions,
FallbackVisitorOptions {}

/**
* @public
*/
class ScenariosVisitor extends Mixin(SpecificationVisitor, FallbackVisitor) {
public declare readonly element: ArrayElement;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@ import { ArrayElement, Element, BREAK } from '@swagger-api/apidom-core';
import FallbackVisitor, { FallbackVisitorOptions } from '../../FallbackVisitor.ts';
import SpecificationVisitor, { SpecificationVisitorOptions } from '../../SpecificationVisitor.ts';

/**
* @public
*/
export interface StandardsVisitorOptions
extends SpecificationVisitorOptions,
FallbackVisitorOptions {}

/**
* @public
*/
class StandardsVisitor extends Mixin(SpecificationVisitor, FallbackVisitor) {
public declare readonly element: ArrayElement;

Expand Down
Loading

0 comments on commit cf569dc

Please sign in to comment.