diff --git a/package-lock.json b/package-lock.json index 9d9cf9fc4b..19a4ec061e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -38226,7 +38226,7 @@ "@types/ramda": "~0.29.6", "ramda": "~0.29.1", "ramda-adjunct": "^4.1.1", - "stampit": "^4.3.2" + "ts-mixer": "^6.0.3" } }, "packages/apidom-parser": { diff --git a/packages/apidom-ns-openapi-3-0/src/refractor/visitors/SpecificationVisitor.ts b/packages/apidom-ns-openapi-3-0/src/refractor/visitors/SpecificationVisitor.ts index 143be36c4b..0baa62fc4d 100644 --- a/packages/apidom-ns-openapi-3-0/src/refractor/visitors/SpecificationVisitor.ts +++ b/packages/apidom-ns-openapi-3-0/src/refractor/visitors/SpecificationVisitor.ts @@ -53,7 +53,11 @@ const SpecificationVisitor = stampit(Visitor, { retrieveVisitorInstance(specPath, options = {}) { const passingOpts = this.retrievePassingOptions(); - return this.retrieveVisitor(specPath)({ ...passingOpts, ...options }); + const VisitorClz = this.retrieveVisitor(specPath) as typeof Visitor; + const visitorOpts = { ...passingOpts, ...options }; + + // @ts-ignore + return new VisitorClz(visitorOpts as any); }, toRefractedElement(specPath: string[], element, options = {}) { diff --git a/packages/apidom-ns-workflows-1/package.json b/packages/apidom-ns-workflows-1/package.json index 21bb55e1cc..f6f9582694 100644 --- a/packages/apidom-ns-workflows-1/package.json +++ b/packages/apidom-ns-workflows-1/package.json @@ -47,7 +47,7 @@ "@types/ramda": "~0.29.6", "ramda": "~0.29.1", "ramda-adjunct": "^4.1.1", - "stampit": "^4.3.2" + "ts-mixer": "^6.0.3" }, "files": [ "cjs/", diff --git a/packages/apidom-ns-workflows-1/src/index.ts b/packages/apidom-ns-workflows-1/src/index.ts index a1357838f3..fb4fb52c27 100644 --- a/packages/apidom-ns-workflows-1/src/index.ts +++ b/packages/apidom-ns-workflows-1/src/index.ts @@ -50,13 +50,6 @@ export { export { isWorkflowsSpecificationExtension } from './refractor/predicates'; -export { default as FixedFieldsVisitor } from './refractor/visitors/generics/FixedFieldsVisitor'; -export { default as MapVisitor } from './refractor/visitors/generics/MapVisitor'; -export { default as MixedFieldsVisitor } from './refractor/visitors/generics/MixedFieldsVisitor'; -export { default as FallbackVisitor } from './refractor/visitors/FallbackVisitor'; -export { default as SpecificationVisitor } from './refractor/visitors/SpecificationVisitor'; -export { default as Visitor } from './refractor/visitors/Visitor'; - export { keyMap, getNodeType } from './traversal/visitor'; // Workflows 1.0.0 elements diff --git a/packages/apidom-ns-workflows-1/src/refractor/index.ts b/packages/apidom-ns-workflows-1/src/refractor/index.ts index 13d22cddea..c2b80aa56c 100644 --- a/packages/apidom-ns-workflows-1/src/refractor/index.ts +++ b/packages/apidom-ns-workflows-1/src/refractor/index.ts @@ -1,4 +1,3 @@ -import { invokeArgs } from 'ramda-adjunct'; import { visit, Element, @@ -6,7 +5,9 @@ import { refract as baseRefract, dispatchRefractorPlugins, } from '@swagger-api/apidom-core'; +import { path } from 'ramda'; +import type VisitorClass from './visitors/Visitor'; import specification from './specification'; import { keyMap, getNodeType } from '../traversal/visitor'; import createToolbox from './toolbox'; @@ -26,9 +27,10 @@ const refract = ( * We don't allow consumers to hook into this translation. * Though we allow consumers to define their onw plugins on already transformed ApiDOM. */ - const rootVisitor = invokeArgs(specPath, [], resolvedSpec); - // @ts-ignore - visit(element, rootVisitor, { state: { specObj: resolvedSpec } }); + const RootVisitorClass = path(specPath, resolvedSpec) as typeof VisitorClass; + const rootVisitor = new RootVisitorClass({ specObj: resolvedSpec }); + + visit(element, rootVisitor); /** * Running plugins visitors means extra single traversal === performance hit. @@ -36,7 +38,7 @@ const refract = ( return dispatchRefractorPlugins(rootVisitor.element, plugins, { toolboxCreator: createToolbox, visitorOptions: { keyMap, nodeTypeGetter: getNodeType }, - }); + }) as T; }; export const createRefractor = diff --git a/packages/apidom-ns-workflows-1/src/refractor/predicates.ts b/packages/apidom-ns-workflows-1/src/refractor/predicates.ts index bd8fc9f3f5..4615820efc 100644 --- a/packages/apidom-ns-workflows-1/src/refractor/predicates.ts +++ b/packages/apidom-ns-workflows-1/src/refractor/predicates.ts @@ -11,9 +11,7 @@ export interface ReferenceLikeElement extends ObjectElement { hasKey: (value: '$ref') => true; } -// eslint-disable-next-line import/prefer-default-export export const isWorkflowsSpecificationExtension = (element: MemberElement): boolean => { - // @ts-ignore return isStringElement(element.key) && startsWith('x-', toValue(element.key)); }; diff --git a/packages/apidom-ns-workflows-1/src/refractor/visitors/FallbackVisitor.ts b/packages/apidom-ns-workflows-1/src/refractor/visitors/FallbackVisitor.ts index f770c9afa6..ffb2a69e95 100644 --- a/packages/apidom-ns-workflows-1/src/refractor/visitors/FallbackVisitor.ts +++ b/packages/apidom-ns-workflows-1/src/refractor/visitors/FallbackVisitor.ts @@ -1,7 +1,6 @@ -import stampit from 'stampit'; import { Element, BREAK, cloneDeep } from '@swagger-api/apidom-core'; -import Visitor from './Visitor'; +import Visitor, { VisitorOptions } from './Visitor'; /** * This visitor is responsible for falling back to current traversed element. @@ -9,13 +8,14 @@ import Visitor from './Visitor'; * different Element is provided FallBackVisitor is responsible to assigning * this Element as current element. */ -const FallbackVisitor = stampit(Visitor, { - methods: { - enter(element: Element) { - this.element = cloneDeep(element); - return BREAK; - }, - }, -}); + +export type { VisitorOptions as FallbackVisitorOptions }; + +class FallbackVisitor extends Visitor { + enter(element: Element) { + this.element = cloneDeep(element); + return BREAK; + } +} export default FallbackVisitor; diff --git a/packages/apidom-ns-workflows-1/src/refractor/visitors/SpecificationExtensionVisitor.ts b/packages/apidom-ns-workflows-1/src/refractor/visitors/SpecificationExtensionVisitor.ts index 2388cc3dda..dd41b39e61 100644 --- a/packages/apidom-ns-workflows-1/src/refractor/visitors/SpecificationExtensionVisitor.ts +++ b/packages/apidom-ns-workflows-1/src/refractor/visitors/SpecificationExtensionVisitor.ts @@ -1,17 +1,16 @@ -import stampit from 'stampit'; import { MemberElement, BREAK, cloneDeep } from '@swagger-api/apidom-core'; import SpecificationVisitor from './SpecificationVisitor'; -const SpecificationExtensionVisitor = stampit(SpecificationVisitor, { - methods: { - MemberElement(memberElement: MemberElement) { - this.element = cloneDeep(memberElement); - this.element.classes.push('specification-extension'); +class SpecificationExtensionVisitor extends SpecificationVisitor { + public declare element: MemberElement; - return BREAK; - }, - }, -}); + MemberElement(memberElement: MemberElement) { + this.element = cloneDeep(memberElement); + this.element.classes.push('specification-extension'); + + return BREAK; + } +} export default SpecificationExtensionVisitor; diff --git a/packages/apidom-ns-workflows-1/src/refractor/visitors/SpecificationVisitor.ts b/packages/apidom-ns-workflows-1/src/refractor/visitors/SpecificationVisitor.ts index 1e8b9c83f4..8ccc5456f1 100644 --- a/packages/apidom-ns-workflows-1/src/refractor/visitors/SpecificationVisitor.ts +++ b/packages/apidom-ns-workflows-1/src/refractor/visitors/SpecificationVisitor.ts @@ -1,77 +1,77 @@ -import stampit from 'stampit'; import { pathSatisfies, path, pick } from 'ramda'; -import { isFunction, isUndefined } from 'ramda-adjunct'; +import { isFunction } from 'ramda-adjunct'; import { visit, cloneDeep } from '@swagger-api/apidom-core'; import { keyMap, getNodeType } from '../../traversal/visitor'; -import Visitor from './Visitor'; +import Visitor, { VisitorOptions } from './Visitor'; +import FallbackVisitor from './FallbackVisitor'; +import type specification from '../specification'; /** * This is a base Type for every visitor that does * internal look-ups to retrieve other child visitors. */ -const SpecificationVisitor = stampit(Visitor, { - props: { - specObj: null, - passingOptionsNames: ['specObj'], - }, - // @ts-ignore - init({ specObj = this.specObj }) { +export interface SpecificationVisitorOptions extends VisitorOptions { + readonly specObj: typeof specification; +} + +class SpecificationVisitor extends Visitor { + protected readonly specObj!: typeof specification; + + protected readonly passingOptionsNames = ['specObj']; + + constructor({ specObj, ...rest }: SpecificationVisitorOptions) { + super({ ...rest }); this.specObj = specObj; - }, - methods: { - retrievePassingOptions() { - return pick(this.passingOptionsNames, this); - }, + } + + retrievePassingOptions() { + return pick(this.passingOptionsNames as (keyof this)[], this); + } - retrieveFixedFields(specPath) { - const fixedFields = path(['visitors', ...specPath, 'fixedFields'], this.specObj); - if (typeof fixedFields === 'object' && fixedFields !== null) { - return Object.keys(fixedFields); - } - return []; - }, + retrieveFixedFields(specPath: string[]) { + const fixedFields = path(['visitors', ...specPath, 'fixedFields'], this.specObj); + if (typeof fixedFields === 'object' && fixedFields !== null) { + return Object.keys(fixedFields); + } + return []; + } - retrieveVisitor(specPath) { - if (pathSatisfies(isFunction, ['visitors', ...specPath], this.specObj)) { - return path(['visitors', ...specPath], this.specObj); - } + retrieveVisitor(specPath: string[]) { + if (pathSatisfies(isFunction, ['visitors', ...specPath], this.specObj)) { + return path(['visitors', ...specPath], this.specObj); + } - return path(['visitors', ...specPath, '$visitor'], this.specObj); - }, + return path(['visitors', ...specPath, '$visitor'], this.specObj); + } - retrieveVisitorInstance(specPath, options = {}) { - const passingOpts = this.retrievePassingOptions(); + retrieveVisitorInstance(specPath: string[], options = {}): Visitor { + const passingOpts = this.retrievePassingOptions(); + const VisitorClz = this.retrieveVisitor(specPath) as typeof Visitor; + const visitorOpts = { ...passingOpts, ...options }; - return this.retrieveVisitor(specPath)({ ...passingOpts, ...options }); - }, + return new VisitorClz(visitorOpts); + } - toRefractedElement(specPath: string[], element, options = {}) { - /** - * This is `Visitor shortcut`: mechanism for short circuiting the traversal and replacing - * it by basic node cloning. - * - * Visiting the element is equivalent to cloning it if the prototype of a visitor - * is the same as the prototype of FallbackVisitor. If that's the case, we can avoid - * bootstrapping the traversal cycle for fields that don't require any special visiting. - */ - const visitor = this.retrieveVisitorInstance(specPath, options); - const visitorPrototype = Object.getPrototypeOf(visitor); + toRefractedElement(specPath: string[], element: any, options = {}) { + /** + * This is `Visitor shortcut`: mechanism for short-circuiting the traversal and replacing + * it by basic node cloning. + * + * Visiting the element is equivalent to cloning it if the prototype of a visitor + * is the same as the prototype of FallbackVisitor. If that's the case, we can avoid + * bootstrapping the traversal cycle for fields that don't require any special visiting. + */ + const visitor = this.retrieveVisitorInstance(specPath, options); - if (isUndefined(this.fallbackVisitorPrototype)) { - this.fallbackVisitorPrototype = Object.getPrototypeOf( - this.retrieveVisitorInstance(['value']), - ); - } - if (this.fallbackVisitorPrototype === visitorPrototype) { - return cloneDeep(element); - } + if (visitor instanceof FallbackVisitor && visitor?.constructor === FallbackVisitor) { + return cloneDeep(element); + } - // standard processing continues - visit(element, visitor, { keyMap, ...options, nodeTypeGetter: getNodeType }); - return visitor.element; - }, - }, -}); + // @ts-ignore + visit(element, visitor, { keyMap, ...options, nodeTypeGetter: getNodeType }); + return visitor.element; + } +} export default SpecificationVisitor; diff --git a/packages/apidom-ns-workflows-1/src/refractor/visitors/Visitor.ts b/packages/apidom-ns-workflows-1/src/refractor/visitors/Visitor.ts index dbb6fe9ab7..b4dcad7c84 100644 --- a/packages/apidom-ns-workflows-1/src/refractor/visitors/Visitor.ts +++ b/packages/apidom-ns-workflows-1/src/refractor/visitors/Visitor.ts @@ -1,18 +1,21 @@ -import stampit from 'stampit'; -import { hasElementSourceMap } from '@swagger-api/apidom-core'; +import { hasElementSourceMap, Element } from '@swagger-api/apidom-core'; -const Visitor = stampit({ - props: { - element: null, - }, - methods: { - copyMetaAndAttributes(from, to) { - // copy sourcemaps - if (hasElementSourceMap(from)) { - to.meta.set('sourceMap', from.meta.get('sourceMap')); - } - }, - }, -}); +export interface VisitorOptions {} + +class Visitor { + public element!: Element; + + constructor(options: VisitorOptions = {}) { + Object.assign(this, options); + } + + // eslint-disable-next-line class-methods-use-this + public copyMetaAndAttributes(from: Element, to: Element) { + // copy sourcemaps + if (hasElementSourceMap(from)) { + to.meta.set('sourceMap', from.meta.get('sourceMap')); + } + } +} export default Visitor; diff --git a/packages/apidom-ns-workflows-1/src/refractor/visitors/generics/FixedFieldsVisitor.ts b/packages/apidom-ns-workflows-1/src/refractor/visitors/generics/FixedFieldsVisitor.ts index ae911e8fcc..cd0e0078b9 100644 --- a/packages/apidom-ns-workflows-1/src/refractor/visitors/generics/FixedFieldsVisitor.ts +++ b/packages/apidom-ns-workflows-1/src/refractor/visitors/generics/FixedFieldsVisitor.ts @@ -1,5 +1,3 @@ -import stampit from 'stampit'; -import { noop } from 'ramda-adjunct'; import { isStringElement, MemberElement, @@ -7,71 +5,83 @@ import { BREAK, cloneDeep, toValue, + ObjectElement, } from '@swagger-api/apidom-core'; -import SpecificationVisitor from '../SpecificationVisitor'; +import SpecificationVisitor, { SpecificationVisitorOptions } from '../SpecificationVisitor'; import { isWorkflowsSpecificationExtension } from '../../predicates'; -const FixedFieldsVisitor = stampit(SpecificationVisitor, { - props: { - specPath: noop, - ignoredFields: [], - canSupportSpecificationExtensions: true, - specificationExtensionPredicate: isWorkflowsSpecificationExtension, - }, - init({ - // @ts-ignore - specPath = this.specPath, - // @ts-ignore - ignoredFields = this.ignoredFields, - // @ts-ignore - canSupportSpecificationExtensions = this.canSupportSpecificationExtensions, - // @ts-ignore - specificationExtensionPredicate = this.specificationExtensionPredicate, - } = {}) { +export type SpecPath = (element: unknown) => T; + +export interface FixedFieldsVisitorOptions extends SpecificationVisitorOptions { + readonly specPath: SpecPath; + readonly ignoredFields?: string[]; + readonly canSupportSpecificationExtensions?: boolean; + readonly specificationExtensionPredicate?: typeof isWorkflowsSpecificationExtension; +} + +class FixedFieldsVisitor extends SpecificationVisitor { + protected specPath: SpecPath; + + protected ignoredFields: string[] = []; + + protected canSupportSpecificationExtensions: boolean = true; + + protected specificationExtensionPredicate = isWorkflowsSpecificationExtension; + + constructor({ + specPath, + ignoredFields, + canSupportSpecificationExtensions, + specificationExtensionPredicate, + ...rest + }: FixedFieldsVisitorOptions) { + super({ ...rest }); this.specPath = specPath; - this.ignoredFields = ignoredFields; - this.canSupportSpecificationExtensions = canSupportSpecificationExtensions; - this.specificationExtensionPredicate = specificationExtensionPredicate; - }, - methods: { - ObjectElement(objectElement) { - const specPath = this.specPath(objectElement); - const fields = this.retrieveFixedFields(specPath); + this.ignoredFields = ignoredFields || []; - objectElement.forEach((value: Element, key: Element, memberElement: MemberElement) => { - if ( - isStringElement(key) && - fields.includes(toValue(key)) && - !this.ignoredFields.includes(toValue(key)) - ) { - const fixedFieldElement = this.toRefractedElement( - [...specPath, 'fixedFields', toValue(key)], - value, - ); - const newMemberElement = new MemberElement(cloneDeep(key), fixedFieldElement); - this.copyMetaAndAttributes(memberElement, newMemberElement); - newMemberElement.classes.push('fixed-field'); - this.element.content.push(newMemberElement); - } else if ( - this.canSupportSpecificationExtensions && - this.specificationExtensionPredicate(memberElement) - ) { - const extensionElement = this.toRefractedElement( - ['document', 'extension'], - memberElement, - ); - this.element.content.push(extensionElement); - } else if (!this.ignoredFields.includes(toValue(key))) { - this.element.content.push(cloneDeep(memberElement)); - } - }); + if (typeof canSupportSpecificationExtensions === 'boolean') { + this.canSupportSpecificationExtensions = canSupportSpecificationExtensions; + } + if (typeof specificationExtensionPredicate === 'function') { + this.specificationExtensionPredicate = specificationExtensionPredicate; + } + } + + ObjectElement(objectElement: ObjectElement) { + const specPath = this.specPath(objectElement); + const fields = this.retrieveFixedFields(specPath); + + // @ts-ignore + objectElement.forEach((value: Element, key: Element, memberElement: MemberElement) => { + if ( + isStringElement(key) && + fields.includes(toValue(key)) && + !this.ignoredFields.includes(toValue(key)) + ) { + const fixedFieldElement = this.toRefractedElement( + [...specPath, 'fixedFields', toValue(key)], + value, + ); + const newMemberElement = new MemberElement(cloneDeep(key), fixedFieldElement); + this.copyMetaAndAttributes(memberElement, newMemberElement); + newMemberElement.classes.push('fixed-field'); + this.element.content.push(newMemberElement); + } else if ( + this.canSupportSpecificationExtensions && + this.specificationExtensionPredicate(memberElement) + ) { + const extensionElement = this.toRefractedElement(['document', 'extension'], memberElement); + this.element.content.push(extensionElement); + } else if (!this.ignoredFields.includes(toValue(key))) { + this.element.content.push(cloneDeep(memberElement)); + } + }); - this.copyMetaAndAttributes(objectElement, this.element); + this.copyMetaAndAttributes(objectElement, this.element); - return BREAK; - }, - }, -}); + return BREAK; + } +} export default FixedFieldsVisitor; diff --git a/packages/apidom-ns-workflows-1/src/refractor/visitors/generics/MapVisitor.ts b/packages/apidom-ns-workflows-1/src/refractor/visitors/generics/MapVisitor.ts index 8b04bab69c..26138397ca 100644 --- a/packages/apidom-ns-workflows-1/src/refractor/visitors/generics/MapVisitor.ts +++ b/packages/apidom-ns-workflows-1/src/refractor/visitors/generics/MapVisitor.ts @@ -1,12 +1,18 @@ -import stampit from 'stampit'; import { isNonEmptyString } from 'ramda-adjunct'; -import PatternedFieldsVisitor from './PatternedFieldsVisitor'; +import PatternedFieldsVisitor, { + SpecPath, + PatternedFieldsVisitorOptions, +} from './PatternedFieldsVisitor'; -const MapVisitor = stampit(PatternedFieldsVisitor, { - props: { - fieldPatternPredicate: isNonEmptyString, - }, -}); +export type { SpecPath }; +export interface MapVisitorOptions extends PatternedFieldsVisitorOptions {} + +class MapVisitor extends PatternedFieldsVisitor { + constructor(options: MapVisitorOptions) { + super(options); + this.fieldPatternPredicate = isNonEmptyString; + } +} export default MapVisitor; diff --git a/packages/apidom-ns-workflows-1/src/refractor/visitors/generics/MixedFieldsVisitor.ts b/packages/apidom-ns-workflows-1/src/refractor/visitors/generics/MixedFieldsVisitor.ts deleted file mode 100644 index 405902ab16..0000000000 --- a/packages/apidom-ns-workflows-1/src/refractor/visitors/generics/MixedFieldsVisitor.ts +++ /dev/null @@ -1,40 +0,0 @@ -import stampit from 'stampit'; -import { difference } from 'ramda'; -import { noop } from 'ramda-adjunct'; -import { ObjectElement, BREAK } from '@swagger-api/apidom-core'; - -import FixedFieldsVisitor from './FixedFieldsVisitor'; -import PatternedFieldsVisitor from './PatternedFieldsVisitor'; - -const MixedFieldsVisitor = stampit(FixedFieldsVisitor, PatternedFieldsVisitor, { - props: { - specPathFixedFields: noop, - specPathPatternedFields: noop, - }, - methods: { - ObjectElement(objectElement: ObjectElement) { - const { specPath, ignoredFields } = this; - - try { - this.specPath = this.specPathFixedFields; - const fixedFields = this.retrieveFixedFields(this.specPath(objectElement)); - // let FixedFieldsVisitor only process fixed fields and leave rest to PatternedFieldsVisitor - this.ignoredFields = [...ignoredFields, ...difference(objectElement.keys(), fixedFields)]; - // @ts-ignore - FixedFieldsVisitor.compose.methods.ObjectElement.call(this, objectElement); - - this.specPath = this.specPathPatternedFields; - this.ignoredFields = fixedFields; - // @ts-ignore - PatternedFieldsVisitor.compose.methods.ObjectElement.call(this, objectElement); - } catch (e) { - this.specPath = specPath; - throw e; - } - - return BREAK; - }, - }, -}); - -export default MixedFieldsVisitor; diff --git a/packages/apidom-ns-workflows-1/src/refractor/visitors/generics/PatternedFieldsVisitor.ts b/packages/apidom-ns-workflows-1/src/refractor/visitors/generics/PatternedFieldsVisitor.ts index 529c34798a..a09077179d 100644 --- a/packages/apidom-ns-workflows-1/src/refractor/visitors/generics/PatternedFieldsVisitor.ts +++ b/packages/apidom-ns-workflows-1/src/refractor/visitors/generics/PatternedFieldsVisitor.ts @@ -1,6 +1,4 @@ -import stampit from 'stampit'; import { F as stubFalse } from 'ramda'; -import { noop } from 'ramda-adjunct'; import { ObjectElement, Element, @@ -10,65 +8,82 @@ import { toValue, } from '@swagger-api/apidom-core'; -import SpecificationVisitor from '../SpecificationVisitor'; +import type { SpecPath } from './FixedFieldsVisitor'; +import SpecificationVisitor, { SpecificationVisitorOptions } from '../SpecificationVisitor'; import { isWorkflowsSpecificationExtension } from '../../predicates'; -const PatternedFieldsJsonObjectVisitor = stampit(SpecificationVisitor, { - props: { - fieldPatternPredicate: stubFalse, - specPath: noop, - ignoredFields: [], - canSupportSpecificationExtensions: false, - specificationExtensionPredicate: isWorkflowsSpecificationExtension, - }, - init({ - // @ts-ignore - specPath = this.specPath, - // @ts-ignore - ignoredFields = this.ignoredFields, - // @ts-ignore - canSupportSpecificationExtensions = this.canSupportSpecificationExtensions, - // @ts-ignore - specificationExtensionPredicate = this.specificationExtensionPredicate, - } = {}) { +export type { SpecPath }; + +export interface PatternedFieldsVisitorOptions extends SpecificationVisitorOptions { + readonly specPath: SpecPath; + readonly ignoredFields?: string[]; + readonly fieldPatternPredicate?: (...args: unknown[]) => boolean; + readonly canSupportSpecificationExtensions?: boolean; + readonly specificationExtensionPredicate?: typeof isWorkflowsSpecificationExtension; +} + +class PatternedFieldsVisitor extends SpecificationVisitor { + protected specPath: SpecPath; + + protected ignoredFields: string[]; + + protected fieldPatternPredicate: (value: unknown) => boolean = stubFalse; + + protected canSupportSpecificationExtensions: boolean = false; + + protected specificationExtensionPredicate = isWorkflowsSpecificationExtension; + + constructor({ + specPath, + ignoredFields, + fieldPatternPredicate, + canSupportSpecificationExtensions, + specificationExtensionPredicate, + ...rest + }: PatternedFieldsVisitorOptions) { + super({ ...rest }); this.specPath = specPath; - this.ignoredFields = ignoredFields; - this.canSupportSpecificationExtensions = canSupportSpecificationExtensions; - this.specificationExtensionPredicate = specificationExtensionPredicate; - }, - methods: { - ObjectElement(objectElement: ObjectElement) { - // @ts-ignore - objectElement.forEach((value: Element, key: Element, memberElement: MemberElement) => { - if ( - this.canSupportSpecificationExtensions && - this.specificationExtensionPredicate(memberElement) - ) { - const extensionElement = this.toRefractedElement( - ['document', 'extension'], - memberElement, - ); - this.element.content.push(extensionElement); - } else if ( - !this.ignoredFields.includes(toValue(key)) && - this.fieldPatternPredicate(toValue(key)) - ) { - const specPath = this.specPath(value); - const patternedFieldElement = this.toRefractedElement(specPath, value); - const newMemberElement = new MemberElement(cloneDeep(key), patternedFieldElement); - this.copyMetaAndAttributes(memberElement, newMemberElement); - newMemberElement.classes.push('patterned-field'); - this.element.content.push(newMemberElement); - } else if (!this.ignoredFields.includes(toValue(key))) { - this.element.content.push(cloneDeep(memberElement)); - } - }); + this.ignoredFields = ignoredFields || []; + + if (typeof fieldPatternPredicate === 'function') { + this.fieldPatternPredicate = fieldPatternPredicate; + } + if (typeof canSupportSpecificationExtensions === 'boolean') { + this.canSupportSpecificationExtensions = canSupportSpecificationExtensions; + } + if (typeof specificationExtensionPredicate === 'function') { + this.specificationExtensionPredicate = specificationExtensionPredicate; + } + } + + ObjectElement(objectElement: ObjectElement) { + // @ts-ignore + objectElement.forEach((value: Element, key: Element, memberElement: MemberElement) => { + if ( + this.canSupportSpecificationExtensions && + this.specificationExtensionPredicate(memberElement) + ) { + const extensionElement = this.toRefractedElement(['document', 'extension'], memberElement); + this.element.content.push(extensionElement); + } else if ( + !this.ignoredFields.includes(toValue(key)) && + this.fieldPatternPredicate(toValue(key)) + ) { + const specPath = this.specPath(value); + const patternedFieldElement = this.toRefractedElement(specPath, value); + const newMemberElement = new MemberElement(cloneDeep(key), patternedFieldElement); + this.copyMetaAndAttributes(memberElement, newMemberElement); + newMemberElement.classes.push('patterned-field'); + this.element.content.push(newMemberElement); + } else if (!this.ignoredFields.includes(toValue(key))) { + this.element.content.push(cloneDeep(memberElement)); + } + }); - this.copyMetaAndAttributes(objectElement, this.element); + this.copyMetaAndAttributes(objectElement, this.element); - return BREAK; - }, - }, -}); + return BREAK; + } +} -export default PatternedFieldsJsonObjectVisitor; +export default PatternedFieldsVisitor; diff --git a/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/FailureActionCriteriaVisitor.ts b/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/FailureActionCriteriaVisitor.ts index d4e322e869..31dd869f03 100644 --- a/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/FailureActionCriteriaVisitor.ts +++ b/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/FailureActionCriteriaVisitor.ts @@ -1,28 +1,30 @@ -import stampit from 'stampit'; +import { Mixin } from 'ts-mixer'; import { ArrayElement, Element, BREAK } from '@swagger-api/apidom-core'; import FailureActionCriteriaElement from '../../../elements/nces/FailureActionCriteria'; -import SpecificationVisitor from '../SpecificationVisitor'; +import SpecificationVisitor, { SpecificationVisitorOptions } from '../SpecificationVisitor'; import FallbackVisitor from '../FallbackVisitor'; -const FailureActionCriteriaVisitor = stampit(SpecificationVisitor, FallbackVisitor, { - init() { +class FailureActionCriteriaVisitor extends Mixin(SpecificationVisitor, FallbackVisitor) { + public readonly element: FailureActionCriteriaElement; + + constructor(options: SpecificationVisitorOptions) { + super(options); this.element = new FailureActionCriteriaElement(); - }, - methods: { - ArrayElement(arrayElement: ArrayElement) { - arrayElement.forEach((item: Element): void => { - const specPath = ['document', 'objects', 'Criterion']; - const element = this.toRefractedElement(specPath, item); - - this.element.push(element); - }); - - this.copyMetaAndAttributes(arrayElement, this.element); - - return BREAK; - }, - }, -}); + } + + ArrayElement(arrayElement: ArrayElement) { + arrayElement.forEach((item: Element): void => { + const specPath = ['document', 'objects', 'Criterion']; + const element = this.toRefractedElement(specPath, item); + + this.element.push(element); + }); + + this.copyMetaAndAttributes(arrayElement, this.element); + + return BREAK; + } +} export default FailureActionCriteriaVisitor; diff --git a/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/ParametersVisitor.ts b/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/ParametersVisitor.ts index f5b922feef..1cc2df8cd7 100644 --- a/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/ParametersVisitor.ts +++ b/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/ParametersVisitor.ts @@ -1,36 +1,38 @@ -import stampit from 'stampit'; +import { Mixin } from 'ts-mixer'; import { ArrayElement, Element, BREAK } from '@swagger-api/apidom-core'; import FallbackVisitor from '../FallbackVisitor'; -import SpecificationVisitor from '../SpecificationVisitor'; +import SpecificationVisitor, { SpecificationVisitorOptions } from '../SpecificationVisitor'; import { isReferenceLikeElement } from '../../predicates'; import { isReferenceElement } from '../../../predicates'; -const ParametersVisitor = stampit(SpecificationVisitor, FallbackVisitor, { - init() { +class ParametersVisitor extends Mixin(SpecificationVisitor, FallbackVisitor) { + public readonly element: ArrayElement; + + constructor(options: SpecificationVisitorOptions) { + super(options); this.element = new ArrayElement(); this.element.classes.push('parameters'); - }, - methods: { - ArrayElement(arrayElement: ArrayElement) { - arrayElement.forEach((item: Element): void => { - const specPath = isReferenceLikeElement(item) - ? ['document', 'objects', 'Reference'] - : ['document', 'objects', 'Parameter']; - const element = this.toRefractedElement(specPath, item); - - if (isReferenceElement(element)) { - element.setMetaProperty('referenced-element', 'parameter'); - } - - this.element.push(element); - }); - - this.copyMetaAndAttributes(arrayElement, this.element); - - return BREAK; - }, - }, -}); + } + + ArrayElement(arrayElement: ArrayElement) { + arrayElement.forEach((item: Element): void => { + const specPath = isReferenceLikeElement(item) + ? ['document', 'objects', 'Reference'] + : ['document', 'objects', 'Parameter']; + const element = this.toRefractedElement(specPath, item); + + if (isReferenceElement(element)) { + element.setMetaProperty('referenced-element', 'parameter'); + } + + this.element.push(element); + }); + + this.copyMetaAndAttributes(arrayElement, this.element); + + return BREAK; + } +} export default ParametersVisitor; diff --git a/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/SourceDescriptionsVisitor.ts b/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/SourceDescriptionsVisitor.ts index 764354b854..b1453e8c0e 100644 --- a/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/SourceDescriptionsVisitor.ts +++ b/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/SourceDescriptionsVisitor.ts @@ -1,28 +1,30 @@ -import stampit from 'stampit'; +import { Mixin } from 'ts-mixer'; import { ArrayElement, Element, BREAK } from '@swagger-api/apidom-core'; import SourceDescriptionsElement from '../../../elements/nces/SourceDescriptions'; -import SpecificationVisitor from '../SpecificationVisitor'; +import SpecificationVisitor, { SpecificationVisitorOptions } from '../SpecificationVisitor'; import FallbackVisitor from '../FallbackVisitor'; -const SourceDescriptionsVisitor = stampit(SpecificationVisitor, FallbackVisitor, { - init() { +class SourceDescriptionsVisitor extends Mixin(SpecificationVisitor, FallbackVisitor) { + public readonly element: SourceDescriptionsElement; + + constructor(options: SpecificationVisitorOptions) { + super(options); this.element = new SourceDescriptionsElement(); - }, - methods: { - ArrayElement(arrayElement: ArrayElement) { - arrayElement.forEach((item: Element): void => { - const specPath = ['document', 'objects', 'SourceDescription']; - const element = this.toRefractedElement(specPath, item); - - this.element.push(element); - }); - - this.copyMetaAndAttributes(arrayElement, this.element); - - return BREAK; - }, - }, -}); + } + + ArrayElement(arrayElement: ArrayElement) { + arrayElement.forEach((item: Element): void => { + const specPath = ['document', 'objects', 'SourceDescription']; + const element = this.toRefractedElement(specPath, item); + + this.element.push(element); + }); + + this.copyMetaAndAttributes(arrayElement, this.element); + + return BREAK; + } +} export default SourceDescriptionsVisitor; diff --git a/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/SuccessActionCriteriaVisitor.ts b/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/SuccessActionCriteriaVisitor.ts index 2f7550757d..2e6f39e024 100644 --- a/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/SuccessActionCriteriaVisitor.ts +++ b/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/SuccessActionCriteriaVisitor.ts @@ -1,28 +1,30 @@ -import stampit from 'stampit'; +import { Mixin } from 'ts-mixer'; import { ArrayElement, Element, BREAK } from '@swagger-api/apidom-core'; import SuccessActionCriteriaElement from '../../../elements/nces/SuccessActionCriteria'; -import SpecificationVisitor from '../SpecificationVisitor'; +import SpecificationVisitor, { SpecificationVisitorOptions } from '../SpecificationVisitor'; import FallbackVisitor from '../FallbackVisitor'; -const SuccessActionCriteriaVisitor = stampit(SpecificationVisitor, FallbackVisitor, { - init() { +class SuccessActionCriteriaVisitor extends Mixin(SpecificationVisitor, FallbackVisitor) { + public readonly element: SuccessActionCriteriaElement; + + constructor(options: SpecificationVisitorOptions) { + super(options); this.element = new SuccessActionCriteriaElement(); - }, - methods: { - ArrayElement(arrayElement: ArrayElement) { - arrayElement.forEach((item: Element): void => { - const specPath = ['document', 'objects', 'Criterion']; - const element = this.toRefractedElement(specPath, item); - - this.element.push(element); - }); - - this.copyMetaAndAttributes(arrayElement, this.element); - - return BREAK; - }, - }, -}); + } + + ArrayElement(arrayElement: ArrayElement) { + arrayElement.forEach((item: Element): void => { + const specPath = ['document', 'objects', 'Criterion']; + const element = this.toRefractedElement(specPath, item); + + this.element.push(element); + }); + + this.copyMetaAndAttributes(arrayElement, this.element); + + return BREAK; + } +} export default SuccessActionCriteriaVisitor; diff --git a/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/WorkflowsSpecVisitor.ts b/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/WorkflowsSpecVisitor.ts index c2f0c94bff..3806d05453 100644 --- a/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/WorkflowsSpecVisitor.ts +++ b/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/WorkflowsSpecVisitor.ts @@ -1,21 +1,21 @@ -import stampit from 'stampit'; +import { Mixin } from 'ts-mixer'; import { StringElement, BREAK, toValue } from '@swagger-api/apidom-core'; import FallbackVisitor from '../FallbackVisitor'; import SpecificationVisitor from '../SpecificationVisitor'; import WorkflowsSpecElement from '../../../elements/WorkflowsSpec'; -const WorkflowsSpecVisitor = stampit(SpecificationVisitor, FallbackVisitor, { - methods: { - StringElement(stringElement: StringElement) { - const workflowsSpecElement = new WorkflowsSpecElement(toValue(stringElement)); +class WorkflowsSpecVisitor extends Mixin(SpecificationVisitor, FallbackVisitor) { + public declare element: WorkflowsSpecElement; - this.copyMetaAndAttributes(stringElement, workflowsSpecElement); + StringElement(stringElement: StringElement) { + const workflowsSpecElement = new WorkflowsSpecElement(toValue(stringElement)); - this.element = workflowsSpecElement; - return BREAK; - }, - }, -}); + this.copyMetaAndAttributes(stringElement, workflowsSpecElement); + this.element = workflowsSpecElement; + + return BREAK; + } +} export default WorkflowsSpecVisitor; diff --git a/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/WorkflowsVisitor.ts b/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/WorkflowsVisitor.ts index 84fd3e78a8..a0345004ff 100644 --- a/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/WorkflowsVisitor.ts +++ b/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/WorkflowsVisitor.ts @@ -1,28 +1,30 @@ -import stampit from 'stampit'; +import { Mixin } from 'ts-mixer'; import { ArrayElement, Element, BREAK } from '@swagger-api/apidom-core'; import WorkflowsElement from '../../../elements/nces/Workflows'; -import SpecificationVisitor from '../SpecificationVisitor'; +import SpecificationVisitor, { SpecificationVisitorOptions } from '../SpecificationVisitor'; import FallbackVisitor from '../FallbackVisitor'; -const WorkflowsVisitor = stampit(SpecificationVisitor, FallbackVisitor, { - init() { +class WorkflowsVisitor extends Mixin(SpecificationVisitor, FallbackVisitor) { + public readonly element: WorkflowsElement; + + constructor(options: SpecificationVisitorOptions) { + super(options); this.element = new WorkflowsElement(); - }, - methods: { - ArrayElement(arrayElement: ArrayElement) { - arrayElement.forEach((item: Element): void => { - const specPath = ['document', 'objects', 'Workflow']; - const element = this.toRefractedElement(specPath, item); - - this.element.push(element); - }); - - this.copyMetaAndAttributes(arrayElement, this.element); - - return BREAK; - }, - }, -}); + } + + ArrayElement(arrayElement: ArrayElement) { + arrayElement.forEach((item: Element): void => { + const specPath = ['document', 'objects', 'Workflow']; + const element = this.toRefractedElement(specPath, item); + + this.element.push(element); + }); + + this.copyMetaAndAttributes(arrayElement, this.element); + + return BREAK; + } +} export default WorkflowsVisitor; diff --git a/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/components/InputsVisitor.ts b/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/components/InputsVisitor.ts index 145cd7169e..459fbad46e 100644 --- a/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/components/InputsVisitor.ts +++ b/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/components/InputsVisitor.ts @@ -1,17 +1,20 @@ -import stampit from 'stampit'; +import { Mixin } from 'ts-mixer'; import { always } from 'ramda'; import ComponentsInputsElement from '../../../../elements/nces/ComponentsInputs'; -import MapVisitor from '../../generics/MapVisitor'; +import MapVisitor, { MapVisitorOptions, SpecPath } from '../../generics/MapVisitor'; import FallbackVisitor from '../../FallbackVisitor'; -const InputsVisitor = stampit(MapVisitor, FallbackVisitor, { - props: { - specPath: always(['document', 'objects', 'JSONSchema']), - }, - init() { +class InputsVisitor extends Mixin(MapVisitor, FallbackVisitor) { + public declare readonly element: ComponentsInputsElement; + + protected declare readonly specPath: SpecPath<['document', 'objects', 'JSONSchema']>; + + constructor(options: MapVisitorOptions) { + super(options); this.element = new ComponentsInputsElement(); - }, -}); + this.specPath = always(['document', 'objects', 'JSONSchema']); + } +} export default InputsVisitor; diff --git a/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/components/ParametersVisitor.ts b/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/components/ParametersVisitor.ts index f20813eb49..ad3440c448 100644 --- a/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/components/ParametersVisitor.ts +++ b/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/components/ParametersVisitor.ts @@ -1,17 +1,20 @@ -import stampit from 'stampit'; +import { Mixin } from 'ts-mixer'; import { always } from 'ramda'; import ComponentsParametersElement from '../../../../elements/nces/ComponentsParameters'; import FallbackVisitor from '../../FallbackVisitor'; -import MapVisitor from '../../generics/MapVisitor'; +import MapVisitor, { SpecPath } from '../../generics/MapVisitor'; -const ParametersVisitor = stampit(MapVisitor, FallbackVisitor, { - props: { - specPath: always(['document', 'objects', 'Parameter']), - }, - init() { +class ParametersVisitor extends Mixin(MapVisitor, FallbackVisitor) { + public declare readonly element: ComponentsParametersElement; + + protected declare readonly specPath: SpecPath<['document', 'objects', 'Parameter']>; + + constructor(options = {}) { + super(options); this.element = new ComponentsParametersElement(); - }, -}); + this.specPath = always(['document', 'objects', 'Parameter']); + } +} export default ParametersVisitor; diff --git a/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/components/index.ts b/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/components/index.ts index 420cb951b4..66f3abca11 100644 --- a/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/components/index.ts +++ b/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/components/index.ts @@ -1,18 +1,26 @@ -import stampit from 'stampit'; +import { Mixin } from 'ts-mixer'; import { always } from 'ramda'; import ComponentsElement from '../../../../elements/Components'; -import FixedFieldsVisitor from '../../generics/FixedFieldsVisitor'; +import FixedFieldsVisitor, { + FixedFieldsVisitorOptions, + SpecPath, +} from '../../generics/FixedFieldsVisitor'; import FallbackVisitor from '../../FallbackVisitor'; -const ComponentsVisitor = stampit(FixedFieldsVisitor, FallbackVisitor, { - props: { - specPath: always(['document', 'objects', 'Components']), - canSupportSpecificationExtensions: true, - }, - init() { +class ComponentsVisitor extends Mixin(FixedFieldsVisitor, FallbackVisitor) { + public declare readonly element: ComponentsElement; + + protected declare readonly specPath: SpecPath<['document', 'objects', 'Components']>; + + protected declare readonly canSupportSpecificationExtensions: true; + + constructor(options: FixedFieldsVisitorOptions) { + super(options); this.element = new ComponentsElement(); - }, -}); + this.specPath = always(['document', 'objects', 'Components']); + this.canSupportSpecificationExtensions = true; + } +} export default ComponentsVisitor; diff --git a/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/criterion/index.ts b/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/criterion/index.ts index 26ca4ac57e..a07c445762 100644 --- a/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/criterion/index.ts +++ b/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/criterion/index.ts @@ -1,18 +1,26 @@ -import stampit from 'stampit'; +import { Mixin } from 'ts-mixer'; import { always } from 'ramda'; import CriterionElement from '../../../../elements/Criterion'; import FallbackVisitor from '../../FallbackVisitor'; -import FixedFieldsVisitor from '../../generics/FixedFieldsVisitor'; +import FixedFieldsVisitor, { + FixedFieldsVisitorOptions, + SpecPath, +} from '../../generics/FixedFieldsVisitor'; -const CriterionVisitor = stampit(FixedFieldsVisitor, FallbackVisitor, { - props: { - specPath: always(['document', 'objects', 'Criterion']), - canSupportSpecificationExtensions: true, - }, - init() { +class CriterionVisitor extends Mixin(FixedFieldsVisitor, FallbackVisitor) { + public declare readonly element: CriterionElement; + + protected declare readonly specPath: SpecPath<['document', 'objects', 'Criterion']>; + + protected declare readonly canSupportSpecificationExtensions: true; + + constructor(options: FixedFieldsVisitorOptions) { + super(options); this.element = new CriterionElement(); - }, -}); + this.specPath = always(['document', 'objects', 'Criterion']); + this.canSupportSpecificationExtensions = true; + } +} export default CriterionVisitor; diff --git a/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/failure-action/index.ts b/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/failure-action/index.ts index da0019b89a..181fa77a9b 100644 --- a/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/failure-action/index.ts +++ b/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/failure-action/index.ts @@ -1,18 +1,26 @@ -import stampit from 'stampit'; +import { Mixin } from 'ts-mixer'; import { always } from 'ramda'; import FailureActionElement from '../../../../elements/FailureAction'; import FallbackVisitor from '../../FallbackVisitor'; -import FixedFieldsVisitor from '../../generics/FixedFieldsVisitor'; +import FixedFieldsVisitor, { + FixedFieldsVisitorOptions, + SpecPath, +} from '../../generics/FixedFieldsVisitor'; -const FailureActionVisitor = stampit(FixedFieldsVisitor, FallbackVisitor, { - props: { - specPath: always(['document', 'objects', 'FailureAction']), - canSupportSpecificationExtensions: true, - }, - init() { +class FailureActionVisitor extends Mixin(FixedFieldsVisitor, FallbackVisitor) { + public declare readonly element: FailureActionElement; + + protected declare readonly specPath: SpecPath<['document', 'objects', 'FailureAction']>; + + protected declare readonly canSupportSpecificationExtensions: true; + + constructor(options: FixedFieldsVisitorOptions) { + super(options); this.element = new FailureActionElement(); - }, -}); + this.specPath = always(['document', 'objects', 'FailureAction']); + this.canSupportSpecificationExtensions = true; + } +} export default FailureActionVisitor; diff --git a/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/index.ts b/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/index.ts index 9b069758e3..9fce2b2860 100644 --- a/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/index.ts +++ b/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/index.ts @@ -1,27 +1,31 @@ -import stampit from 'stampit'; +import { Mixin } from 'ts-mixer'; import { always } from 'ramda'; import { ObjectElement } from '@swagger-api/apidom-core'; -import FixedFieldsVisitor from '../generics/FixedFieldsVisitor'; +import FixedFieldsVisitor, { + FixedFieldsVisitorOptions, + SpecPath, +} from '../generics/FixedFieldsVisitor'; import FallbackVisitor from '../FallbackVisitor'; import WorkflowsSpecification1Element from '../../../elements/WorkflowsSpecification1'; -const WorkflowsSpecificationVisitor = stampit(FixedFieldsVisitor, FallbackVisitor, { - props: { - specPath: always(['document', 'objects', 'WorkflowsSpecification']), - canSupportSpecificationExtensions: true, - }, - init() { +class WorkflowsSpecificationVisitor extends Mixin(FixedFieldsVisitor, FallbackVisitor) { + public readonly element: WorkflowsSpecification1Element; + + protected readonly specPath: SpecPath<['document', 'objects', 'WorkflowsSpecification']>; + + protected readonly canSupportSpecificationExtensions: true; + + constructor(options: FixedFieldsVisitorOptions) { + super(options); this.element = new WorkflowsSpecification1Element(); - }, - methods: { - ObjectElement(objectElement: ObjectElement) { - this.unrefractedElement = objectElement; + this.specPath = always(['document', 'objects', 'WorkflowsSpecification']); + this.canSupportSpecificationExtensions = true; + } - // @ts-ignore - return FixedFieldsVisitor.compose.methods.ObjectElement.call(this, objectElement); - }, - }, -}); + ObjectElement(objectElement: ObjectElement) { + return FixedFieldsVisitor.prototype.ObjectElement.call(this, objectElement); + } +} export default WorkflowsSpecificationVisitor; diff --git a/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/info/VersionVisitor.ts b/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/info/VersionVisitor.ts index 717d4fde83..e285bb193d 100644 --- a/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/info/VersionVisitor.ts +++ b/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/info/VersionVisitor.ts @@ -1,18 +1,18 @@ -import stampit from 'stampit'; -import { StringElement, BREAK, cloneDeep } from '@swagger-api/apidom-core'; +import { StringElement } from '@swagger-api/apidom-core'; import FallbackVisitor from '../../FallbackVisitor'; -const VersionVisitor = stampit(FallbackVisitor, { - methods: { - StringElement(stringElement: StringElement) { - this.element = cloneDeep(stringElement); - this.element.classes.push('workflow-version'); - this.element.classes.push('version'); +class VersionVisitor extends FallbackVisitor { + public declare readonly element: StringElement; - return BREAK; - }, - }, -}); + StringElement(stringElement: StringElement) { + const result = super.enter(stringElement); + + this.element.classes.push('workflow-version'); + this.element.classes.push('version'); + + return result; + } +} export default VersionVisitor; diff --git a/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/info/index.ts b/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/info/index.ts index 2fe1403ab2..6dc6c6c616 100644 --- a/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/info/index.ts +++ b/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/info/index.ts @@ -1,18 +1,26 @@ -import stampit from 'stampit'; +import { Mixin } from 'ts-mixer'; import { always } from 'ramda'; import InfoElement from '../../../../elements/Info'; import FallbackVisitor from '../../FallbackVisitor'; -import FixedFieldsVisitor from '../../generics/FixedFieldsVisitor'; +import FixedFieldsVisitor, { + FixedFieldsVisitorOptions, + SpecPath, +} from '../../generics/FixedFieldsVisitor'; -const InfoVisitor = stampit(FixedFieldsVisitor, FallbackVisitor, { - props: { - specPath: always(['document', 'objects', 'Info']), - canSupportSpecificationExtensions: true, - }, - init() { +class InfoVisitor extends Mixin(FixedFieldsVisitor, FallbackVisitor) { + public declare readonly element: InfoElement; + + protected declare readonly specPath: SpecPath<['document', 'objects', 'Info']>; + + protected declare readonly canSupportSpecificationExtensions: true; + + constructor(options: FixedFieldsVisitorOptions) { + super(options); this.element = new InfoElement(); - }, -}); + this.specPath = always(['document', 'objects', 'Info']); + this.canSupportSpecificationExtensions = true; + } +} export default InfoVisitor; diff --git a/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/json-schema/index.ts b/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/json-schema/index.ts index e44d6fffea..289628cf64 100644 --- a/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/json-schema/index.ts +++ b/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/json-schema/index.ts @@ -1,12 +1,11 @@ import { always } from 'ramda'; -import stampit from 'stampit'; import { specificationObj as OpenApi3_1Specification } from '@swagger-api/apidom-ns-openapi-3-1'; import JSONSchemaElement from '../../../../elements/JSONSchema'; const { $visitor: SchemaVisitor } = OpenApi3_1Specification.visitors.document.objects.Schema; -const JSONSchemaVisitor = stampit(SchemaVisitor, { +const JSONSchemaVisitor = SchemaVisitor.compose({ props: { specPath: always(['document', 'objects', 'JSONSchema']), canSupportSpecificationExtensions: false, diff --git a/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/parameter/index.ts b/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/parameter/index.ts index 6bbeb6fdea..270d330929 100644 --- a/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/parameter/index.ts +++ b/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/parameter/index.ts @@ -1,18 +1,26 @@ -import stampit from 'stampit'; +import { Mixin } from 'ts-mixer'; import { always } from 'ramda'; import ParameterElement from '../../../../elements/Parameter'; import FallbackVisitor from '../../FallbackVisitor'; -import FixedFieldsVisitor from '../../generics/FixedFieldsVisitor'; +import FixedFieldsVisitor, { + FixedFieldsVisitorOptions, + SpecPath, +} from '../../generics/FixedFieldsVisitor'; -const ParameterVisitor = stampit(FixedFieldsVisitor, FallbackVisitor, { - props: { - specPath: always(['document', 'objects', 'Parameter']), - canSupportSpecificationExtensions: true, - }, - init() { +class ParameterVisitor extends Mixin(FixedFieldsVisitor, FallbackVisitor) { + public declare readonly element: ParameterElement; + + protected declare readonly specPath: SpecPath<['document', 'objects', 'Parameter']>; + + protected declare readonly canSupportSpecificationExtensions: true; + + constructor(options: FixedFieldsVisitorOptions) { + super(options); this.element = new ParameterElement(); - }, -}); + this.specPath = always(['document', 'objects', 'Parameter']); + this.canSupportSpecificationExtensions = true; + } +} export default ParameterVisitor; diff --git a/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/reference/$RefVisitor.ts b/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/reference/$RefVisitor.ts index b142b7a4ad..730f7ae416 100644 --- a/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/reference/$RefVisitor.ts +++ b/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/reference/$RefVisitor.ts @@ -1,17 +1,15 @@ -import stampit from 'stampit'; -import { StringElement, BREAK, cloneDeep } from '@swagger-api/apidom-core'; +import { StringElement } from '@swagger-api/apidom-core'; import FallbackVisitor from '../../FallbackVisitor'; -const $RefVisitor = stampit(FallbackVisitor, { - methods: { - StringElement(stringElement: StringElement) { - this.element = cloneDeep(stringElement); - this.element.classes.push('reference-value'); +export class $RefVisitor extends FallbackVisitor { + public declare readonly element: StringElement; - return BREAK; - }, - }, -}); + StringElement(stringElement: StringElement) { + const result = super.enter(stringElement); + this.element.classes.push('reference-value'); + return result; + } +} export default $RefVisitor; diff --git a/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/reference/index.ts b/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/reference/index.ts index 62d8e01e7b..4c5b21d176 100644 --- a/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/reference/index.ts +++ b/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/reference/index.ts @@ -1,32 +1,38 @@ -import stampit from 'stampit'; +import { Mixin } from 'ts-mixer'; import { always } from 'ramda'; import { ObjectElement, isStringElement } from '@swagger-api/apidom-core'; import ReferenceElement from '../../../../elements/Reference'; -import FixedFieldsVisitor from '../../generics/FixedFieldsVisitor'; +import FixedFieldsVisitor, { + FixedFieldsVisitorOptions, + SpecPath, +} from '../../generics/FixedFieldsVisitor'; import FallbackVisitor from '../../FallbackVisitor'; -const ReferenceVisitor = stampit(FixedFieldsVisitor, FallbackVisitor, { - props: { - specPath: always(['document', 'objects', 'Reference']), - canSupportSpecificationExtensions: false, - }, - init() { +class ReferenceVisitor extends Mixin(FixedFieldsVisitor, FallbackVisitor) { + public declare readonly element: ReferenceElement; + + protected declare readonly specPath: SpecPath<['document', 'objects', 'Reference']>; + + protected declare readonly canSupportSpecificationExtensions: false; + + constructor(options: FixedFieldsVisitorOptions) { + super(options); this.element = new ReferenceElement(); - }, - methods: { - ObjectElement(objectElement: ObjectElement) { - // @ts-ignore - const result = FixedFieldsVisitor.compose.methods.ObjectElement.call(this, objectElement); - - // mark this ReferenceElement with reference metadata - if (isStringElement(this.element.$ref)) { - this.element.classes.push('reference-element'); - } - - return result; - }, - }, -}); + this.specPath = always(['document', 'objects', 'Reference']); + this.canSupportSpecificationExtensions = false; + } + + ObjectElement(objectElement: ObjectElement) { + const result = FixedFieldsVisitor.prototype.ObjectElement.call(this, objectElement); + + // mark this ReferenceElement with reference metadata + if (isStringElement(this.element.$ref)) { + this.element.classes.push('reference-element'); + } + + return result; + } +} export default ReferenceVisitor; diff --git a/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/source-description/UrlVisitor.ts b/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/source-description/UrlVisitor.ts index d37d395d80..98e06c8558 100644 --- a/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/source-description/UrlVisitor.ts +++ b/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/source-description/UrlVisitor.ts @@ -1,17 +1,15 @@ -import stampit from 'stampit'; -import { StringElement, BREAK, cloneDeep } from '@swagger-api/apidom-core'; +import { StringElement } from '@swagger-api/apidom-core'; import FallbackVisitor from '../../FallbackVisitor'; -const UrlVisitor = stampit(FallbackVisitor, { - methods: { - StringElement(stringElement: StringElement) { - this.element = cloneDeep(stringElement); - this.element.classes.push('source-description-url'); +class UrlVisitor extends FallbackVisitor { + public declare readonly element: StringElement; - return BREAK; - }, - }, -}); + StringElement(stringElement: StringElement) { + const result = super.enter(stringElement); + this.element.classes.push('source-description-url'); + return result; + } +} export default UrlVisitor; diff --git a/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/source-description/index.ts b/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/source-description/index.ts index 3f970ae479..e046ab43d7 100644 --- a/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/source-description/index.ts +++ b/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/source-description/index.ts @@ -1,18 +1,26 @@ -import stampit from 'stampit'; +import { Mixin } from 'ts-mixer'; import { always } from 'ramda'; import SourceDescriptionElement from '../../../../elements/SourceDescription'; import FallbackVisitor from '../../FallbackVisitor'; -import FixedFieldsVisitor from '../../generics/FixedFieldsVisitor'; +import FixedFieldsVisitor, { + FixedFieldsVisitorOptions, + SpecPath, +} from '../../generics/FixedFieldsVisitor'; -const SourceDescriptionVisitor = stampit(FixedFieldsVisitor, FallbackVisitor, { - props: { - specPath: always(['document', 'objects', 'SourceDescription']), - canSupportSpecificationExtensions: true, - }, - init() { +class SourceDescriptionVisitor extends Mixin(FixedFieldsVisitor, FallbackVisitor) { + public declare readonly element: SourceDescriptionElement; + + protected declare readonly specPath: SpecPath<['document', 'objects', 'SourceDescription']>; + + protected declare readonly canSupportSpecificationExtensions: true; + + constructor(options: FixedFieldsVisitorOptions) { + super(options); this.element = new SourceDescriptionElement(); - }, -}); + this.specPath = always(['document', 'objects', 'SourceDescription']); + this.canSupportSpecificationExtensions = true; + } +} export default SourceDescriptionVisitor; diff --git a/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/step/DependsOnVisitor.ts b/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/step/DependsOnVisitor.ts index 895723931c..286914efaf 100644 --- a/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/step/DependsOnVisitor.ts +++ b/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/step/DependsOnVisitor.ts @@ -1,20 +1,21 @@ -import stampit from 'stampit'; import { ArrayElement, BREAK, cloneDeep } from '@swagger-api/apidom-core'; import StepDependsOnElement from '../../../../elements/nces/StepDependsOn'; -import FallbackVisitor from '../../FallbackVisitor'; +import FallbackVisitor, { FallbackVisitorOptions } from '../../FallbackVisitor'; -const DependsOnVisitor = stampit(FallbackVisitor, { - init() { +class DependsOnVisitor extends FallbackVisitor { + public declare element: StepDependsOnElement; + + constructor(options: FallbackVisitorOptions) { + super(options); this.element = new StepDependsOnElement(); - }, - methods: { - ArrayElement(arrayElement: ArrayElement) { - this.element = this.element.concat(cloneDeep(arrayElement)); + } + + ArrayElement(arrayElement: ArrayElement) { + this.element = this.element.concat(cloneDeep(arrayElement)); - return BREAK; - }, - }, -}); + return BREAK; + } +} export default DependsOnVisitor; diff --git a/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/step/OnFailureVisitor.ts b/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/step/OnFailureVisitor.ts index 0a6e507a79..0b557330be 100644 --- a/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/step/OnFailureVisitor.ts +++ b/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/step/OnFailureVisitor.ts @@ -1,28 +1,30 @@ -import stampit from 'stampit'; +import { Mixin } from 'ts-mixer'; import { ArrayElement, Element, BREAK } from '@swagger-api/apidom-core'; import StepOnFailureElement from '../../../../elements/nces/StepOnFailure'; -import SpecificationVisitor from '../../SpecificationVisitor'; +import SpecificationVisitor, { SpecificationVisitorOptions } from '../../SpecificationVisitor'; import FallbackVisitor from '../../FallbackVisitor'; -const OnFailureVisitor = stampit(SpecificationVisitor, FallbackVisitor, { - init() { +class OnFailureVisitor extends Mixin(SpecificationVisitor, FallbackVisitor) { + public declare readonly element: StepOnFailureElement; + + constructor(options: SpecificationVisitorOptions) { + super(options); this.element = new StepOnFailureElement(); - }, - methods: { - ArrayElement(arrayElement: ArrayElement) { - arrayElement.forEach((item: Element): void => { - const specPath = ['document', 'objects', 'FailureAction']; - const element = this.toRefractedElement(specPath, item); - - this.element.push(element); - }); - - this.copyMetaAndAttributes(arrayElement, this.element); - - return BREAK; - }, - }, -}); + } + + ArrayElement(arrayElement: ArrayElement) { + arrayElement.forEach((item: Element): void => { + const specPath = ['document', 'objects', 'FailureAction']; + const element = this.toRefractedElement(specPath, item); + + this.element.push(element); + }); + + this.copyMetaAndAttributes(arrayElement, this.element); + + return BREAK; + } +} export default OnFailureVisitor; diff --git a/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/step/OnSuccessVisitor.ts b/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/step/OnSuccessVisitor.ts index d08a8e44e0..48cc24b5e5 100644 --- a/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/step/OnSuccessVisitor.ts +++ b/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/step/OnSuccessVisitor.ts @@ -1,28 +1,30 @@ -import stampit from 'stampit'; +import { Mixin } from 'ts-mixer'; import { ArrayElement, Element, BREAK } from '@swagger-api/apidom-core'; import StepOnSuccessElement from '../../../../elements/nces/StepOnSuccess'; -import SpecificationVisitor from '../../SpecificationVisitor'; +import SpecificationVisitor, { SpecificationVisitorOptions } from '../../SpecificationVisitor'; import FallbackVisitor from '../../FallbackVisitor'; -const OnSuccessVisitor = stampit(SpecificationVisitor, FallbackVisitor, { - init() { +class OnSuccessVisitor extends Mixin(SpecificationVisitor, FallbackVisitor) { + public declare readonly element: StepOnSuccessElement; + + constructor(options: SpecificationVisitorOptions) { + super(options); this.element = new StepOnSuccessElement(); - }, - methods: { - ArrayElement(arrayElement: ArrayElement) { - arrayElement.forEach((item: Element): void => { - const specPath = ['document', 'objects', 'SuccessAction']; - const element = this.toRefractedElement(specPath, item); - - this.element.push(element); - }); - - this.copyMetaAndAttributes(arrayElement, this.element); - - return BREAK; - }, - }, -}); + } + + ArrayElement(arrayElement: ArrayElement) { + arrayElement.forEach((item: Element): void => { + const specPath = ['document', 'objects', 'SuccessAction']; + const element = this.toRefractedElement(specPath, item); + + this.element.push(element); + }); + + this.copyMetaAndAttributes(arrayElement, this.element); + + return BREAK; + } +} export default OnSuccessVisitor; diff --git a/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/step/OutputsVisitor.ts b/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/step/OutputsVisitor.ts index 3eb1d33505..58cad58d66 100644 --- a/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/step/OutputsVisitor.ts +++ b/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/step/OutputsVisitor.ts @@ -1,17 +1,20 @@ -import stampit from 'stampit'; +import { Mixin } from 'ts-mixer'; import { always } from 'ramda'; -import MapVisitor from '../../generics/MapVisitor'; +import MapVisitor, { MapVisitorOptions, SpecPath } from '../../generics/MapVisitor'; import FallbackVisitor from '../../FallbackVisitor'; import StepOutputsElement from '../../../../elements/nces/StepOutputs'; -const OutputsVisitor = stampit(MapVisitor, FallbackVisitor, { - props: { - specPath: always(['value']), - }, - init() { +class OutputsVisitor extends Mixin(MapVisitor, FallbackVisitor) { + public declare readonly element: StepOutputsElement; + + protected declare readonly specPath: SpecPath<['value']>; + + constructor(options: MapVisitorOptions) { + super(options); this.element = new StepOutputsElement(); - }, -}); + this.specPath = always(['value']); + } +} export default OutputsVisitor; diff --git a/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/step/ParametersVisitor.ts b/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/step/ParametersVisitor.ts index 55ee752fa3..ae829a825a 100644 --- a/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/step/ParametersVisitor.ts +++ b/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/step/ParametersVisitor.ts @@ -1,36 +1,38 @@ -import stampit from 'stampit'; +import { Mixin } from 'ts-mixer'; import { ArrayElement, Element, BREAK } from '@swagger-api/apidom-core'; import FallbackVisitor from '../../FallbackVisitor'; -import SpecificationVisitor from '../../SpecificationVisitor'; +import SpecificationVisitor, { SpecificationVisitorOptions } from '../../SpecificationVisitor'; import { isReferenceLikeElement } from '../../../predicates'; import { isReferenceElement } from '../../../../predicates'; import StepParametersElement from '../../../../elements/nces/StepParameters'; -const ParametersVisitor = stampit(SpecificationVisitor, FallbackVisitor, { - init() { +class ParametersVisitor extends Mixin(SpecificationVisitor, FallbackVisitor) { + public declare readonly element: StepParametersElement; + + constructor(options: SpecificationVisitorOptions) { + super(options); this.element = new StepParametersElement(); - }, - methods: { - ArrayElement(arrayElement: ArrayElement) { - arrayElement.forEach((item: Element): void => { - const specPath = isReferenceLikeElement(item) - ? ['document', 'objects', 'Reference'] - : ['document', 'objects', 'Parameter']; - const element = this.toRefractedElement(specPath, item); - - if (isReferenceElement(element)) { - element.setMetaProperty('referenced-element', 'parameter'); - } - - this.element.push(element); - }); - - this.copyMetaAndAttributes(arrayElement, this.element); - - return BREAK; - }, - }, -}); + } + + ArrayElement(arrayElement: ArrayElement) { + arrayElement.forEach((item: Element): void => { + const specPath = isReferenceLikeElement(item) + ? ['document', 'objects', 'Reference'] + : ['document', 'objects', 'Parameter']; + const element = this.toRefractedElement(specPath, item); + + if (isReferenceElement(element)) { + element.setMetaProperty('referenced-element', 'parameter'); + } + + this.element.push(element); + }); + + this.copyMetaAndAttributes(arrayElement, this.element); + + return BREAK; + } +} export default ParametersVisitor; diff --git a/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/step/SuccessCriteriaVisitor.ts b/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/step/SuccessCriteriaVisitor.ts index 00337f0117..4601154bf1 100644 --- a/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/step/SuccessCriteriaVisitor.ts +++ b/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/step/SuccessCriteriaVisitor.ts @@ -1,28 +1,30 @@ -import stampit from 'stampit'; +import { Mixin } from 'ts-mixer'; import { ArrayElement, Element, BREAK } from '@swagger-api/apidom-core'; import StepSuccessCriteriaElement from '../../../../elements/nces/StepSuccessCriteria'; -import SpecificationVisitor from '../../SpecificationVisitor'; +import SpecificationVisitor, { SpecificationVisitorOptions } from '../../SpecificationVisitor'; import FallbackVisitor from '../../FallbackVisitor'; -const SuccessCriteriaVisitor = stampit(SpecificationVisitor, FallbackVisitor, { - init() { +class SuccessCriteriaVisitor extends Mixin(SpecificationVisitor, FallbackVisitor) { + public declare readonly element: StepSuccessCriteriaElement; + + constructor(options: SpecificationVisitorOptions) { + super(options); this.element = new StepSuccessCriteriaElement(); - }, - methods: { - ArrayElement(arrayElement: ArrayElement) { - arrayElement.forEach((item: Element): void => { - const specPath = ['document', 'objects', 'Criterion']; - const element = this.toRefractedElement(specPath, item); - - this.element.push(element); - }); - - this.copyMetaAndAttributes(arrayElement, this.element); - - return BREAK; - }, - }, -}); + } + + ArrayElement(arrayElement: ArrayElement) { + arrayElement.forEach((item: Element): void => { + const specPath = ['document', 'objects', 'Criterion']; + const element = this.toRefractedElement(specPath, item); + + this.element.push(element); + }); + + this.copyMetaAndAttributes(arrayElement, this.element); + + return BREAK; + } +} export default SuccessCriteriaVisitor; diff --git a/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/step/index.ts b/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/step/index.ts index 4933578384..61ffbb92b5 100644 --- a/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/step/index.ts +++ b/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/step/index.ts @@ -1,18 +1,26 @@ -import stampit from 'stampit'; +import { Mixin } from 'ts-mixer'; import { always } from 'ramda'; import StepElement from '../../../../elements/Step'; import FallbackVisitor from '../../FallbackVisitor'; -import FixedFieldsVisitor from '../../generics/FixedFieldsVisitor'; +import FixedFieldsVisitor, { + FixedFieldsVisitorOptions, + SpecPath, +} from '../../generics/FixedFieldsVisitor'; -const StepVisitor = stampit(FixedFieldsVisitor, FallbackVisitor, { - props: { - specPath: always(['document', 'objects', 'Step']), - canSupportSpecificationExtensions: true, - }, - init() { +class StepVisitor extends Mixin(FixedFieldsVisitor, FallbackVisitor) { + public declare readonly element: StepElement; + + protected declare readonly specPath: SpecPath<['document', 'objects', 'Step']>; + + protected declare readonly canSupportSpecificationExtensions: true; + + constructor(options: FixedFieldsVisitorOptions) { + super(options); this.element = new StepElement(); - }, -}); + this.specPath = always(['document', 'objects', 'Step']); + this.canSupportSpecificationExtensions = true; + } +} export default StepVisitor; diff --git a/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/success-action/index.ts b/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/success-action/index.ts index 06bba2f14b..9ce445b701 100644 --- a/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/success-action/index.ts +++ b/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/success-action/index.ts @@ -1,18 +1,26 @@ -import stampit from 'stampit'; +import { Mixin } from 'ts-mixer'; import { always } from 'ramda'; import SuccessActionElement from '../../../../elements/SuccessAction'; import FallbackVisitor from '../../FallbackVisitor'; -import FixedFieldsVisitor from '../../generics/FixedFieldsVisitor'; +import FixedFieldsVisitor, { + FixedFieldsVisitorOptions, + SpecPath, +} from '../../generics/FixedFieldsVisitor'; -const SuccessActionVisitor = stampit(FixedFieldsVisitor, FallbackVisitor, { - props: { - specPath: always(['document', 'objects', 'SuccessAction']), - canSupportSpecificationExtensions: true, - }, - init() { +class SuccessActionVisitor extends Mixin(FixedFieldsVisitor, FallbackVisitor) { + public declare readonly element: SuccessActionElement; + + protected declare readonly specPath: SpecPath<['document', 'objects', 'SuccessAction']>; + + protected declare readonly canSupportSpecificationExtensions: true; + + constructor(options: FixedFieldsVisitorOptions) { + super(options); this.element = new SuccessActionElement(); - }, -}); + this.specPath = always(['document', 'objects', 'SuccessAction']); + this.canSupportSpecificationExtensions = true; + } +} export default SuccessActionVisitor; diff --git a/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/workflow/OutputsVisitor.ts b/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/workflow/OutputsVisitor.ts index 153ce73dca..ff41c4e874 100644 --- a/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/workflow/OutputsVisitor.ts +++ b/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/workflow/OutputsVisitor.ts @@ -1,17 +1,20 @@ -import stampit from 'stampit'; +import { Mixin } from 'ts-mixer'; import { always } from 'ramda'; -import MapVisitor from '../../generics/MapVisitor'; +import MapVisitor, { MapVisitorOptions, SpecPath } from '../../generics/MapVisitor'; import FallbackVisitor from '../../FallbackVisitor'; import WorkflowOutputsElement from '../../../../elements/nces/WorkflowOutputs'; -const OutputsVisitor = stampit(MapVisitor, FallbackVisitor, { - props: { - specPath: always(['value']), - }, - init() { +class OutputsVisitor extends Mixin(MapVisitor, FallbackVisitor) { + public declare readonly element: WorkflowOutputsElement; + + protected declare readonly specPath: SpecPath<['value']>; + + constructor(options: MapVisitorOptions) { + super(options); this.element = new WorkflowOutputsElement(); - }, -}); + this.specPath = always(['value']); + } +} export default OutputsVisitor; diff --git a/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/workflow/StepsVisitor.ts b/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/workflow/StepsVisitor.ts index 0af02b6288..56a2f8f048 100644 --- a/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/workflow/StepsVisitor.ts +++ b/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/workflow/StepsVisitor.ts @@ -1,28 +1,30 @@ -import stampit from 'stampit'; +import { Mixin } from 'ts-mixer'; import { ArrayElement, Element, BREAK } from '@swagger-api/apidom-core'; import WorkflowStepsElement from '../../../../elements/nces/WorkflowSteps'; -import SpecificationVisitor from '../../SpecificationVisitor'; +import SpecificationVisitor, { SpecificationVisitorOptions } from '../../SpecificationVisitor'; import FallbackVisitor from '../../FallbackVisitor'; -const StepsVisitor = stampit(SpecificationVisitor, FallbackVisitor, { - init() { +class StepsVisitor extends Mixin(SpecificationVisitor, FallbackVisitor) { + public declare readonly element: WorkflowStepsElement; + + constructor(options: SpecificationVisitorOptions) { + super(options); this.element = new WorkflowStepsElement(); - }, - methods: { - ArrayElement(arrayElement: ArrayElement) { - arrayElement.forEach((item: Element): void => { - const specPath = ['document', 'objects', 'Step']; - const element = this.toRefractedElement(specPath, item); - - this.element.push(element); - }); - - this.copyMetaAndAttributes(arrayElement, this.element); - - return BREAK; - }, - }, -}); + } + + ArrayElement(arrayElement: ArrayElement) { + arrayElement.forEach((item: Element): void => { + const specPath = ['document', 'objects', 'Step']; + const element = this.toRefractedElement(specPath, item); + + this.element.push(element); + }); + + this.copyMetaAndAttributes(arrayElement, this.element); + + return BREAK; + } +} export default StepsVisitor; diff --git a/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/workflow/index.ts b/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/workflow/index.ts index 0f0d2eb590..178d2f1d41 100644 --- a/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/workflow/index.ts +++ b/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/workflow/index.ts @@ -1,18 +1,26 @@ -import stampit from 'stampit'; +import { Mixin } from 'ts-mixer'; import { always } from 'ramda'; import WorkflowElement from '../../../../elements/Workflow'; import FallbackVisitor from '../../FallbackVisitor'; -import FixedFieldsVisitor from '../../generics/FixedFieldsVisitor'; +import FixedFieldsVisitor, { + FixedFieldsVisitorOptions, + SpecPath, +} from '../../generics/FixedFieldsVisitor'; -const WorkflowVisitor = stampit(FixedFieldsVisitor, FallbackVisitor, { - props: { - specPath: always(['document', 'objects', 'Workflow']), - canSupportSpecificationExtensions: true, - }, - init() { +class WorkflowVisitor extends Mixin(FixedFieldsVisitor, FallbackVisitor) { + public declare readonly element: WorkflowElement; + + protected declare readonly specPath: SpecPath<['document', 'objects', 'Workflow']>; + + protected declare readonly canSupportSpecificationExtensions: true; + + constructor(options: FixedFieldsVisitorOptions) { + super(options); this.element = new WorkflowElement(); - }, -}); + this.specPath = always(['document', 'objects', 'Workflow']); + this.canSupportSpecificationExtensions = true; + } +} export default WorkflowVisitor;