@speclynx/apidom-ns-json-schema-2020-12 1.12.2 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@speclynx/apidom-ns-json-schema-2020-12",
3
- "version": "1.12.2",
3
+ "version": "2.0.1",
4
4
  "description": "JSON Schema 2020-12 namespace for ApiDOM.",
5
5
  "publishConfig": {
6
6
  "access": "public",
@@ -9,8 +9,8 @@
9
9
  },
10
10
  "type": "module",
11
11
  "sideEffects": [
12
- "./src/refractor/registration.mjs",
13
- "./src/refractor/registration.cjs"
12
+ "./src/refractor/inspect.mjs",
13
+ "./src/refractor/inspect.cjs"
14
14
  ],
15
15
  "unpkg": "./dist/apidom-ns-json-schema-2020-12.browser.min.js",
16
16
  "main": "./src/index.cjs",
@@ -31,7 +31,7 @@
31
31
  "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",
32
32
  "test:update-snapshots": "cross-env UPDATE_SNAPSHOT=1 mocha",
33
33
  "typescript:check-types": "tsc --noEmit && tsc -p ./test/tsconfig.json --noEmit",
34
- "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'",
34
+ "typescript:declaration": "tsc -p tsconfig.declaration.json && api-extractor run -l -c ./config/api-extractor/api-extractor.json",
35
35
  "prepack": "copyfiles -u 3 ../../LICENSES/* LICENSES && copyfiles -u 2 ../../NOTICE .",
36
36
  "postpack": "rimraf NOTICE LICENSES"
37
37
  },
@@ -43,10 +43,11 @@
43
43
  "license": "Apache-2.0",
44
44
  "dependencies": {
45
45
  "@babel/runtime-corejs3": "^7.28.4",
46
- "@speclynx/apidom-core": "^1.12.2",
47
- "@speclynx/apidom-error": "^1.12.2",
48
- "@speclynx/apidom-ns-json-schema-2019-09": "^1.12.2",
49
- "@types/ramda": "~0.30.0",
46
+ "@speclynx/apidom-core": "^2.0.1",
47
+ "@speclynx/apidom-datamodel": "^2.0.1",
48
+ "@speclynx/apidom-error": "^2.0.1",
49
+ "@speclynx/apidom-ns-json-schema-2019-09": "^2.0.1",
50
+ "@speclynx/apidom-traverse": "^2.0.1",
50
51
  "ramda": "~0.32.0",
51
52
  "ramda-adjunct": "^6.0.0",
52
53
  "ts-mixer": "^6.0.4"
@@ -61,5 +62,5 @@
61
62
  "README.md",
62
63
  "CHANGELOG.md"
63
64
  ],
64
- "gitHead": "8c77c8183cb058797925e09a0b5399612e3a2e39"
65
+ "gitHead": "6a9caf87f445f76ffd69afa760990ffa784bc82d"
65
66
  }
@@ -1,6 +1,5 @@
1
1
  import { UnsupportedOperationError } from '@speclynx/apidom-error';
2
2
  import { JSONSchemaElement } from '@speclynx/apidom-ns-json-schema-2019-09';
3
-
4
3
  /**
5
4
  * @public
6
5
  */
package/src/index.cjs CHANGED
@@ -3,18 +3,7 @@
3
3
  var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
4
4
  var _interopRequireWildcard = require("@babel/runtime-corejs3/helpers/interopRequireWildcard").default;
5
5
  exports.__esModule = true;
6
- exports.specificationObj = exports.refractorPluginReplaceEmptyElement = exports.refract = exports.mediaTypes = exports.isStringElement = exports.isRefElement = exports.isObjectElement = exports.isNumberElement = exports.isNullElement = exports.isMemberElement = exports.isLinkElement = exports.isLinkDescriptionElement = exports.isJSONSchemaElement = exports.isElement = exports.isBooleanElement = exports.isArrayElement = exports.default = exports.createRefractor = exports.Visitor = exports.SpecificationVisitor = exports.PropertiesVisitor = exports.PrefixItemsVisitor = exports.PatternedFieldsVisitor = exports.PatternPropertiesVisitor = exports.ParentSchemaAwareVisitor = exports.OneOfVisitor = exports.MapVisitor = exports.LinkDescriptionVisitor = exports.LinkDescriptionElement = exports.JSONSchemaVisitor = exports.JSONSchemaElement = exports.JSONSchema202012MediaTypes = exports.ItemsVisitor = exports.FixedFieldsVisitor = exports.FallbackVisitor = exports.DependentSchemasVisitor = exports.DependentRequiredVisitor = exports.AnyOfVisitor = exports.AlternatingVisitor = exports.AllOfVisitor = exports.$vocabularyVisitor = exports.$refVisitor = exports.$defsVisitor = void 0;
7
- var _apidomCore = require("@speclynx/apidom-core");
8
- exports.isRefElement = _apidomCore.isRefElement;
9
- exports.isLinkElement = _apidomCore.isLinkElement;
10
- exports.isMemberElement = _apidomCore.isMemberElement;
11
- exports.isObjectElement = _apidomCore.isObjectElement;
12
- exports.isArrayElement = _apidomCore.isArrayElement;
13
- exports.isBooleanElement = _apidomCore.isBooleanElement;
14
- exports.isNullElement = _apidomCore.isNullElement;
15
- exports.isElement = _apidomCore.isElement;
16
- exports.isNumberElement = _apidomCore.isNumberElement;
17
- exports.isStringElement = _apidomCore.isStringElement;
6
+ exports.specificationObj = exports.refractorPluginReplaceEmptyElement = exports.refractLinkDescription = exports.refractJSONSchema = exports.refract = exports.mediaTypes = exports.isLinkDescriptionElement = exports.isJSONSchemaElement = exports.default = exports.Visitor = exports.SpecificationVisitor = exports.PropertiesVisitor = exports.PrefixItemsVisitor = exports.PatternedFieldsVisitor = exports.PatternPropertiesVisitor = exports.ParentSchemaAwareVisitor = exports.OneOfVisitor = exports.MapVisitor = exports.LinkDescriptionVisitor = exports.LinkDescriptionElement = exports.JSONSchemaVisitor = exports.JSONSchemaElement = exports.JSONSchema202012MediaTypes = exports.ItemsVisitor = exports.FixedFieldsVisitor = exports.FallbackVisitor = exports.DependentSchemasVisitor = exports.DependentRequiredVisitor = exports.BaseSchemaMapVisitor = exports.BaseSchemaArrayVisitor = exports.AnyOfVisitor = exports.AlternatingVisitor = exports.AllOfVisitor = exports.$vocabularyVisitor = exports.$refVisitor = exports.$defsVisitor = void 0;
18
7
  var _mediaTypes = _interopRequireWildcard(require("./media-types.cjs"));
19
8
  exports.mediaTypes = _mediaTypes.default;
20
9
  exports.JSONSchema202012MediaTypes = _mediaTypes.JSONSchema202012MediaTypes;
@@ -24,7 +13,8 @@ var _replaceEmptyElement = _interopRequireDefault(require("./refractor/plugins/r
24
13
  exports.refractorPluginReplaceEmptyElement = _replaceEmptyElement.default;
25
14
  var _index = _interopRequireWildcard(require("./refractor/index.cjs"));
26
15
  exports.refract = _index.default;
27
- exports.createRefractor = _index.createRefractor;
16
+ exports.refractJSONSchema = _index.refractJSONSchema;
17
+ exports.refractLinkDescription = _index.refractLinkDescription;
28
18
  var _specification = _interopRequireDefault(require("./refractor/specification.cjs"));
29
19
  exports.specificationObj = _specification.default;
30
20
  var _predicates = require("./predicates.cjs");
@@ -50,12 +40,14 @@ exports.ItemsVisitor = _apidomNsJsonSchema.ItemsVisitor;
50
40
  exports.OneOfVisitor = _apidomNsJsonSchema.OneOfVisitor;
51
41
  exports.PatternPropertiesVisitor = _apidomNsJsonSchema.PatternPropertiesVisitor;
52
42
  exports.PropertiesVisitor = _apidomNsJsonSchema.PropertiesVisitor;
43
+ exports.BaseSchemaArrayVisitor = _apidomNsJsonSchema.BaseSchemaArrayVisitor;
44
+ exports.BaseSchemaMapVisitor = _apidomNsJsonSchema.BaseSchemaMapVisitor;
53
45
  var _index2 = _interopRequireDefault(require("./refractor/visitors/json-schema/index.cjs"));
54
46
  exports.JSONSchemaVisitor = _index2.default;
55
47
  var _index3 = _interopRequireDefault(require("./refractor/visitors/json-schema/link-description/index.cjs"));
56
48
  exports.LinkDescriptionVisitor = _index3.default;
57
49
  var _PrefixItemsVisitor = _interopRequireDefault(require("./refractor/visitors/json-schema/PrefixItemsVisitor.cjs"));
58
50
  exports.PrefixItemsVisitor = _PrefixItemsVisitor.default;
59
- var _registration = require("./refractor/registration.cjs");
60
- exports.JSONSchemaElement = _registration.JSONSchemaElement;
61
- exports.LinkDescriptionElement = _registration.LinkDescriptionElement;
51
+ var _inspect = require("./refractor/inspect.cjs");
52
+ exports.JSONSchemaElement = _inspect.JSONSchemaElement;
53
+ exports.LinkDescriptionElement = _inspect.LinkDescriptionElement;
package/src/index.mjs CHANGED
@@ -1,8 +1,7 @@
1
- export { isRefElement, isLinkElement, isMemberElement, isObjectElement, isArrayElement, isBooleanElement, isNullElement, isElement, isNumberElement, isStringElement } from '@speclynx/apidom-core';
2
1
  export { default as mediaTypes, JSONSchema202012MediaTypes } from "./media-types.mjs";
3
2
  export { default } from "./namespace.mjs";
4
3
  export { default as refractorPluginReplaceEmptyElement } from "./refractor/plugins/replace-empty-element.mjs";
5
- export { default as refract, createRefractor } from "./refractor/index.mjs";
4
+ export { default as refract, refractJSONSchema, refractLinkDescription } from "./refractor/index.mjs";
6
5
  export { default as specificationObj } from "./refractor/specification.mjs";
7
6
  export { isJSONSchemaElement, isLinkDescriptionElement } from "./predicates.mjs";
8
7
  export { SpecificationVisitor, FallbackVisitor, FixedFieldsVisitor, PatternedFieldsVisitor, MapVisitor, AlternatingVisitor, ParentSchemaAwareVisitor, Visitor } from '@speclynx/apidom-ns-json-schema-2019-09';
@@ -20,7 +19,8 @@ export { OneOfVisitor } from '@speclynx/apidom-ns-json-schema-2019-09';
20
19
  export { PatternPropertiesVisitor } from '@speclynx/apidom-ns-json-schema-2019-09';
21
20
  export { PropertiesVisitor } from '@speclynx/apidom-ns-json-schema-2019-09';
22
21
  export { default as PrefixItemsVisitor } from "./refractor/visitors/json-schema/PrefixItemsVisitor.mjs";
22
+ export { BaseSchemaArrayVisitor, BaseSchemaMapVisitor } from '@speclynx/apidom-ns-json-schema-2019-09';
23
23
  /**
24
24
  * JSON Schema 2020-12 specification elements.
25
25
  */
26
- export { JSONSchemaElement, LinkDescriptionElement } from "./refractor/registration.mjs";
26
+ export { JSONSchemaElement, LinkDescriptionElement } from "./refractor/inspect.mjs";
@@ -3,27 +3,16 @@
3
3
  var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
4
4
  exports.__esModule = true;
5
5
  exports.isLinkDescriptionElement = exports.isJSONSchemaElement = void 0;
6
- var _apidomCore = require("@speclynx/apidom-core");
7
6
  var _JSONSchema = _interopRequireDefault(require("./elements/JSONSchema.cjs"));
8
7
  var _LinkDescription = _interopRequireDefault(require("./elements/LinkDescription.cjs"));
9
8
  /**
10
9
  * @public
11
10
  */
12
- const isJSONSchemaElement = exports.isJSONSchemaElement = (0, _apidomCore.createPredicate)(({
13
- hasBasicElementProps,
14
- isElementType,
15
- primitiveEq
16
- }) => {
17
- return element => element instanceof _JSONSchema.default || hasBasicElementProps(element) && isElementType('JSONSchema202012', element) && primitiveEq('object', element);
18
- });
11
+ const isJSONSchemaElement = element => element instanceof _JSONSchema.default;
19
12
 
20
13
  /**
21
14
  * @public
22
15
  */
23
- const isLinkDescriptionElement = exports.isLinkDescriptionElement = (0, _apidomCore.createPredicate)(({
24
- hasBasicElementProps,
25
- isElementType,
26
- primitiveEq
27
- }) => {
28
- return element => element instanceof _LinkDescription.default || hasBasicElementProps(element) && isElementType('linkDescription', element) && primitiveEq('object', element);
29
- });
16
+ exports.isJSONSchemaElement = isJSONSchemaElement;
17
+ const isLinkDescriptionElement = element => element instanceof _LinkDescription.default;
18
+ exports.isLinkDescriptionElement = isLinkDescriptionElement;
@@ -1,24 +1,11 @@
1
- import { createPredicate } from '@speclynx/apidom-core';
2
1
  import JSONSchemaElement from "./elements/JSONSchema.mjs";
3
2
  import LinkDescriptionElement from "./elements/LinkDescription.mjs";
4
3
  /**
5
4
  * @public
6
5
  */
7
- export const isJSONSchemaElement = createPredicate(({
8
- hasBasicElementProps,
9
- isElementType,
10
- primitiveEq
11
- }) => {
12
- return element => element instanceof JSONSchemaElement || hasBasicElementProps(element) && isElementType('JSONSchema202012', element) && primitiveEq('object', element);
13
- });
6
+ export const isJSONSchemaElement = element => element instanceof JSONSchemaElement;
14
7
 
15
8
  /**
16
9
  * @public
17
10
  */
18
- export const isLinkDescriptionElement = createPredicate(({
19
- hasBasicElementProps,
20
- isElementType,
21
- primitiveEq
22
- }) => {
23
- return element => element instanceof LinkDescriptionElement || hasBasicElementProps(element) && isElementType('linkDescription', element) && primitiveEq('object', element);
24
- });
11
+ export const isLinkDescriptionElement = element => element instanceof LinkDescriptionElement;
@@ -2,53 +2,73 @@
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
4
4
  exports.__esModule = true;
5
- exports.default = exports.createRefractor = void 0;
6
- var _ramda = require("ramda");
5
+ exports.refractLinkDescription = exports.refractJSONSchema = exports.default = void 0;
7
6
  var _apidomCore = require("@speclynx/apidom-core");
7
+ var _apidomTraverse = require("@speclynx/apidom-traverse");
8
+ var _apidomDatamodel = require("@speclynx/apidom-datamodel");
9
+ var _ramda = require("ramda");
8
10
  var _specification = _interopRequireDefault(require("./specification.cjs"));
9
- var _visitor = require("../traversal/visitor.cjs");
10
11
  var _toolbox = _interopRequireDefault(require("./toolbox.cjs"));
12
+ /**
13
+ * @public
14
+ */
15
+
16
+ /**
17
+ * @public
18
+ */
19
+
11
20
  /**
12
21
  * @public
13
22
  */
14
23
  const refract = (value, {
15
- specPath = ['visitors', 'document', 'objects', 'JSONSchema', '$visitor'],
24
+ element = 'jSONSchema202012',
16
25
  plugins = [],
17
26
  specificationObj = _specification.default
18
27
  } = {}) => {
19
- const element = (0, _apidomCore.refract)(value);
20
- const resolvedSpec = (0, _apidomCore.dereference)(specificationObj);
28
+ const genericElement = (0, _apidomDatamodel.refract)(value);
29
+ const resolvedSpec = (0, _apidomCore.resolveSpecification)(specificationObj);
30
+ const elementMap = resolvedSpec.elementMap;
31
+ const specPath = elementMap[element];
32
+ if (!specPath) {
33
+ throw new Error(`Unknown element type: "${element}"`);
34
+ }
21
35
 
22
36
  /**
23
37
  * This is where generic ApiDOM becomes semantic (namespace applied).
24
38
  * We don't allow consumers to hook into this translation.
25
- * Though we allow consumers to define their onw plugins on already transformed ApiDOM.
39
+ * Though we allow consumers to define their own plugins on already transformed ApiDOM.
26
40
  */
27
41
  const RootVisitorClass = (0, _ramda.path)(specPath, resolvedSpec);
28
42
  const rootVisitor = new RootVisitorClass({
29
43
  specObj: resolvedSpec
30
44
  });
31
- (0, _apidomCore.visit)(element, rootVisitor);
45
+ (0, _apidomTraverse.traverse)(genericElement, rootVisitor);
32
46
 
33
47
  /**
34
- * Run plugins only when necessary.
35
48
  * Running plugins visitors means extra single traversal === performance hit.
36
49
  */
37
50
  return (0, _apidomCore.dispatchRefractorPlugins)(rootVisitor.element, plugins, {
38
- toolboxCreator: _toolbox.default,
39
- visitorOptions: {
40
- keyMap: _visitor.keyMap,
41
- nodeTypeGetter: _visitor.getNodeType
42
- }
51
+ toolboxCreator: _toolbox.default
43
52
  });
44
53
  };
45
54
 
46
55
  /**
56
+ * Refracts a value into a JSONSchemaElement.
57
+ * @public
58
+ */
59
+ const refractJSONSchema = (value, options = {}) => refract(value, {
60
+ ...options,
61
+ element: 'jSONSchema202012'
62
+ });
63
+
64
+ /**
65
+ * Refracts a value into a LinkDescriptionElement.
47
66
  * @public
48
67
  */
49
- const createRefractor = specPath => (value, options = {}) => refract(value, {
50
- specPath,
51
- ...options
68
+ exports.refractJSONSchema = refractJSONSchema;
69
+ const refractLinkDescription = (value, options = {}) => refract(value, {
70
+ ...options,
71
+ element: 'linkDescription'
52
72
  });
53
- exports.createRefractor = createRefractor;
73
+ exports.refractLinkDescription = refractLinkDescription;
54
74
  var _default = exports.default = refract;
@@ -1,48 +1,65 @@
1
+ import { resolveSpecification, dispatchRefractorPlugins } from '@speclynx/apidom-core';
2
+ import { traverse } from '@speclynx/apidom-traverse';
3
+ import { refract as baseRefract } from '@speclynx/apidom-datamodel';
1
4
  import { path } from 'ramda';
2
- import { visit, dereference, refract as baseRefract, dispatchRefractorPlugins } from '@speclynx/apidom-core';
3
5
  import specification from "./specification.mjs";
4
- import { keyMap, getNodeType } from "../traversal/visitor.mjs";
5
6
  import createToolbox from "./toolbox.mjs";
7
+ /**
8
+ * @public
9
+ */
10
+ /**
11
+ * @public
12
+ */
6
13
  /**
7
14
  * @public
8
15
  */
9
16
  const refract = (value, {
10
- specPath = ['visitors', 'document', 'objects', 'JSONSchema', '$visitor'],
17
+ element = 'jSONSchema202012',
11
18
  plugins = [],
12
19
  specificationObj = specification
13
20
  } = {}) => {
14
- const element = baseRefract(value);
15
- const resolvedSpec = dereference(specificationObj);
21
+ const genericElement = baseRefract(value);
22
+ const resolvedSpec = resolveSpecification(specificationObj);
23
+ const elementMap = resolvedSpec.elementMap;
24
+ const specPath = elementMap[element];
25
+ if (!specPath) {
26
+ throw new Error(`Unknown element type: "${element}"`);
27
+ }
16
28
 
17
29
  /**
18
30
  * This is where generic ApiDOM becomes semantic (namespace applied).
19
31
  * We don't allow consumers to hook into this translation.
20
- * Though we allow consumers to define their onw plugins on already transformed ApiDOM.
32
+ * Though we allow consumers to define their own plugins on already transformed ApiDOM.
21
33
  */
22
34
  const RootVisitorClass = path(specPath, resolvedSpec);
23
35
  const rootVisitor = new RootVisitorClass({
24
36
  specObj: resolvedSpec
25
37
  });
26
- visit(element, rootVisitor);
38
+ traverse(genericElement, rootVisitor);
27
39
 
28
40
  /**
29
- * Run plugins only when necessary.
30
41
  * Running plugins visitors means extra single traversal === performance hit.
31
42
  */
32
43
  return dispatchRefractorPlugins(rootVisitor.element, plugins, {
33
- toolboxCreator: createToolbox,
34
- visitorOptions: {
35
- keyMap,
36
- nodeTypeGetter: getNodeType
37
- }
44
+ toolboxCreator: createToolbox
38
45
  });
39
46
  };
40
47
 
41
48
  /**
49
+ * Refracts a value into a JSONSchemaElement.
50
+ * @public
51
+ */
52
+ export const refractJSONSchema = (value, options = {}) => refract(value, {
53
+ ...options,
54
+ element: 'jSONSchema202012'
55
+ });
56
+
57
+ /**
58
+ * Refracts a value into a LinkDescriptionElement.
42
59
  * @public
43
60
  */
44
- export const createRefractor = specPath => (value, options = {}) => refract(value, {
45
- specPath,
46
- ...options
61
+ export const refractLinkDescription = (value, options = {}) => refract(value, {
62
+ ...options,
63
+ element: 'linkDescription'
47
64
  });
48
65
  export default refract;
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
4
+ exports.__esModule = true;
5
+ var _apidomCore = require("@speclynx/apidom-core");
6
+ var _ramdaAdjunct = require("ramda-adjunct");
7
+ var _JSONSchema = _interopRequireDefault(require("../elements/JSONSchema.cjs"));
8
+ exports.JSONSchemaElement = _JSONSchema.default;
9
+ var _LinkDescription = _interopRequireDefault(require("../elements/LinkDescription.cjs"));
10
+ exports.LinkDescriptionElement = _LinkDescription.default;
11
+ var _specification = _interopRequireDefault(require("./specification.cjs"));
12
+ /**
13
+ * @public
14
+ */
15
+
16
+ // Resolve specification to dereference $ref pointers
17
+ const resolvedSpec = (0, _apidomCore.resolveSpecification)(_specification.default);
18
+
19
+ // Extract fixed fields as list of { name, alias?, $visitor }
20
+ const getFixedFields = fixedFieldsSpec => {
21
+ return Object.entries(fixedFieldsSpec).map(([name, fieldSpec]) => {
22
+ if ((0, _ramdaAdjunct.isPlainObject)(fieldSpec)) {
23
+ return {
24
+ name,
25
+ ...fieldSpec
26
+ };
27
+ }
28
+ return {
29
+ name,
30
+ $visitor: fieldSpec
31
+ };
32
+ });
33
+ };
34
+
35
+ // Define lazy getters for fixedFields on element classes
36
+ Object.defineProperty(_JSONSchema.default, 'fixedFields', {
37
+ get: () => getFixedFields(resolvedSpec.visitors.document.objects.JSONSchema.fixedFields),
38
+ enumerable: true
39
+ });
40
+ Object.defineProperty(_LinkDescription.default, 'fixedFields', {
41
+ get: () => getFixedFields(resolvedSpec.visitors.document.objects.LinkDescription.fixedFields),
42
+ enumerable: true
43
+ });
@@ -0,0 +1,37 @@
1
+ import { resolveSpecification } from '@speclynx/apidom-core';
2
+ import { isPlainObject } from 'ramda-adjunct';
3
+ import JSONSchemaElement from "../elements/JSONSchema.mjs";
4
+ import LinkDescriptionElement from "../elements/LinkDescription.mjs";
5
+ import specification from "./specification.mjs";
6
+ /**
7
+ * @public
8
+ */
9
+ // Resolve specification to dereference $ref pointers
10
+ const resolvedSpec = resolveSpecification(specification);
11
+
12
+ // Extract fixed fields as list of { name, alias?, $visitor }
13
+ const getFixedFields = fixedFieldsSpec => {
14
+ return Object.entries(fixedFieldsSpec).map(([name, fieldSpec]) => {
15
+ if (isPlainObject(fieldSpec)) {
16
+ return {
17
+ name,
18
+ ...fieldSpec
19
+ };
20
+ }
21
+ return {
22
+ name,
23
+ $visitor: fieldSpec
24
+ };
25
+ });
26
+ };
27
+
28
+ // Define lazy getters for fixedFields on element classes
29
+ Object.defineProperty(JSONSchemaElement, 'fixedFields', {
30
+ get: () => getFixedFields(resolvedSpec.visitors.document.objects.JSONSchema.fixedFields),
31
+ enumerable: true
32
+ });
33
+ Object.defineProperty(LinkDescriptionElement, 'fixedFields', {
34
+ get: () => getFixedFields(resolvedSpec.visitors.document.objects.LinkDescription.fixedFields),
35
+ enumerable: true
36
+ });
37
+ export { JSONSchemaElement, LinkDescriptionElement };
@@ -3,10 +3,11 @@
3
3
  var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
4
4
  exports.__esModule = true;
5
5
  exports.default = void 0;
6
+ var _apidomDatamodel = require("@speclynx/apidom-datamodel");
6
7
  var _apidomCore = require("@speclynx/apidom-core");
8
+ var _apidomTraverse = require("@speclynx/apidom-traverse");
7
9
  var _JSONSchema = _interopRequireDefault(require("../../elements/JSONSchema.cjs"));
8
10
  var _LinkDescription = _interopRequireDefault(require("../../elements/LinkDescription.cjs"));
9
- var _visitor = require("../../traversal/visitor.cjs");
10
11
  /**
11
12
  * JSON Schema 2020-12 specification elements.
12
13
  */
@@ -45,11 +46,11 @@ var _visitor = require("../../traversal/visitor.cjs");
45
46
  * (JSONSchemaElement))
46
47
  */
47
48
 
48
- const isEmptyElement = element => (0, _apidomCore.isStringElement)(element) && (0, _apidomCore.includesClasses)(['yaml-e-node', 'yaml-e-scalar'], element);
49
+ const isEmptyElement = element => (0, _apidomDatamodel.isStringElement)(element) && (0, _apidomDatamodel.includesClasses)(element, ['yaml-e-node', 'yaml-e-scalar']);
49
50
  const schema = {
50
51
  JSONSchema202012Element: {
51
52
  prefixItems(...args) {
52
- const element = new _apidomCore.ArrayElement(...args);
53
+ const element = new _apidomDatamodel.ArrayElement(...args);
53
54
  element.classes.push('json-schema-prefixItems');
54
55
  return element;
55
56
  },
@@ -60,12 +61,12 @@ const schema = {
60
61
  return new _JSONSchema.default(...args);
61
62
  },
62
63
  required(...args) {
63
- const element = new _apidomCore.ArrayElement(...args);
64
+ const element = new _apidomDatamodel.ArrayElement(...args);
64
65
  element.classes.push('json-schema-required');
65
66
  return element;
66
67
  },
67
68
  properties(...args) {
68
- const element = new _apidomCore.ObjectElement(...args);
69
+ const element = new _apidomDatamodel.ObjectElement(...args);
69
70
  element.classes.push('json-schema-properties');
70
71
  return element;
71
72
  },
@@ -73,12 +74,12 @@ const schema = {
73
74
  return new _JSONSchema.default(...args);
74
75
  },
75
76
  patternProperties(...args) {
76
- const element = new _apidomCore.ObjectElement(...args);
77
+ const element = new _apidomDatamodel.ObjectElement(...args);
77
78
  element.classes.push('json-schema-patternProperties');
78
79
  return element;
79
80
  },
80
81
  dependentSchemas(...args) {
81
- const element = new _apidomCore.ObjectElement(...args);
82
+ const element = new _apidomDatamodel.ObjectElement(...args);
82
83
  element.classes.push('json-schema-dependentSchemas');
83
84
  return element;
84
85
  },
@@ -86,22 +87,22 @@ const schema = {
86
87
  return new _JSONSchema.default(...args);
87
88
  },
88
89
  enum(...args) {
89
- const element = new _apidomCore.ArrayElement(...args);
90
+ const element = new _apidomDatamodel.ArrayElement(...args);
90
91
  element.classes.push('json-schema-enum');
91
92
  return element;
92
93
  },
93
94
  allOf(...args) {
94
- const element = new _apidomCore.ArrayElement(...args);
95
+ const element = new _apidomDatamodel.ArrayElement(...args);
95
96
  element.classes.push('json-schema-allOf');
96
97
  return element;
97
98
  },
98
99
  anyOf(...args) {
99
- const element = new _apidomCore.ArrayElement(...args);
100
+ const element = new _apidomDatamodel.ArrayElement(...args);
100
101
  element.classes.push('json-schema-anyOf');
101
102
  return element;
102
103
  },
103
104
  oneOf(...args) {
104
- const element = new _apidomCore.ArrayElement(...args);
105
+ const element = new _apidomDatamodel.ArrayElement(...args);
105
106
  element.classes.push('json-schema-oneOf');
106
107
  return element;
107
108
  },
@@ -118,22 +119,22 @@ const schema = {
118
119
  return new _JSONSchema.default(...args);
119
120
  },
120
121
  $defs(...args) {
121
- const element = new _apidomCore.ObjectElement(...args);
122
+ const element = new _apidomDatamodel.ObjectElement(...args);
122
123
  element.classes.push('json-schema-$defs');
123
124
  return element;
124
125
  },
125
126
  examples(...args) {
126
- const element = new _apidomCore.ArrayElement(...args);
127
+ const element = new _apidomDatamodel.ArrayElement(...args);
127
128
  element.classes.push('json-schema-examples');
128
129
  return element;
129
130
  },
130
131
  links(...args) {
131
- const element = new _apidomCore.ArrayElement(...args);
132
+ const element = new _apidomDatamodel.ArrayElement(...args);
132
133
  element.classes.push('json-schema-links');
133
134
  return element;
134
135
  },
135
136
  $vocabulary(...args) {
136
- const element = new _apidomCore.ObjectElement(...args);
137
+ const element = new _apidomDatamodel.ObjectElement(...args);
137
138
  element.classes.push('json-schema-$vocabulary');
138
139
  return element;
139
140
  },
@@ -144,7 +145,7 @@ const schema = {
144
145
  return new _JSONSchema.default(...args);
145
146
  },
146
147
  $dependentRequired(...args) {
147
- const element = new _apidomCore.ObjectElement(...args);
148
+ const element = new _apidomDatamodel.ObjectElement(...args);
148
149
  element.classes.push('json-schema-$dependentRequired');
149
150
  return element;
150
151
  },
@@ -152,7 +153,7 @@ const schema = {
152
153
  return new _JSONSchema.default(...args);
153
154
  },
154
155
  type(...args) {
155
- const element = new _apidomCore.ArrayElement(...args);
156
+ const element = new _apidomDatamodel.ArrayElement(...args);
156
157
  element.classes.push('json-schema-type');
157
158
  return element;
158
159
  }
@@ -168,13 +169,13 @@ const schema = {
168
169
  return new _JSONSchema.default(...args);
169
170
  },
170
171
  templatePointers(...args) {
171
- return new _apidomCore.ObjectElement(...args);
172
+ return new _apidomDatamodel.ObjectElement(...args);
172
173
  },
173
174
  templateRequired(...args) {
174
- return new _apidomCore.ArrayElement(...args);
175
+ return new _apidomDatamodel.ArrayElement(...args);
175
176
  },
176
177
  targetHints(...args) {
177
- return new _apidomCore.ObjectElement(...args);
178
+ return new _apidomDatamodel.ObjectElement(...args);
178
179
  },
179
180
  headerSchema(...args) {
180
181
  return new _JSONSchema.default(...args);
@@ -227,7 +228,7 @@ const schema = {
227
228
  }
228
229
  };
229
230
  const findElementFactory = (ancestor, keyName) => {
230
- const elementType = (0, _visitor.getNodeType)(ancestor); // @ts-ignore
231
+ const elementType = (0, _apidomTraverse.getNodeType)(ancestor); // @ts-ignore
231
232
  const keyMapping = schema[elementType] || schema[(0, _apidomCore.toValue)(ancestor.classes.first)];
232
233
  return typeof keyMapping === 'undefined' ? undefined : Object.hasOwn(keyMapping, '[key: *]') ? keyMapping['[key: *]'] : keyMapping[keyName];
233
234
  };
@@ -238,25 +239,30 @@ const findElementFactory = (ancestor, keyName) => {
238
239
  const plugin = () => () => {
239
240
  return {
240
241
  visitor: {
241
- StringElement(element, key, parent, path, ancestors) {
242
- if (!isEmptyElement(element)) return undefined;
243
- const lineage = [...ancestors, parent].filter(_apidomCore.isElement);
242
+ StringElement(path) {
243
+ const element = path.node;
244
+ if (!isEmptyElement(element)) return;
245
+
246
+ // getAncestorNodes() returns [parent, grandparent, ..., root], so reverse to get [root, ..., parent]
247
+ const lineage = path.getAncestorNodes().reverse().filter(_apidomDatamodel.isElement);
244
248
  const parentElement = lineage.at(-1);
245
249
  let elementFactory;
246
250
  let context;
247
- if ((0, _apidomCore.isArrayElement)(parentElement)) {
251
+ if ((0, _apidomDatamodel.isArrayElement)(parentElement)) {
248
252
  context = element;
249
253
  elementFactory = findElementFactory(parentElement, '<*>');
250
- } else if ((0, _apidomCore.isMemberElement)(parentElement)) {
254
+ } else if ((0, _apidomDatamodel.isMemberElement)(parentElement)) {
251
255
  context = lineage.at(-2);
252
256
  elementFactory = findElementFactory(context, (0, _apidomCore.toValue)(parentElement.key));
253
257
  }
254
258
 
255
259
  // no element factory found
256
- if (typeof elementFactory !== 'function') return undefined;
257
- return elementFactory.call({
260
+ if (typeof elementFactory !== 'function') return;
261
+ const replacement = elementFactory.call({
258
262
  context
259
- }, undefined, (0, _apidomCore.cloneDeep)(element.meta), (0, _apidomCore.cloneDeep)(element.attributes));
263
+ }, undefined, (0, _apidomDatamodel.cloneDeep)(element.meta), (0, _apidomDatamodel.cloneDeep)(element.attributes));
264
+ _apidomDatamodel.SourceMapElement.transfer(element, replacement);
265
+ path.replaceWith(replacement);
260
266
  }
261
267
  }
262
268
  };