@speclynx/apidom-ns-json-schema-2019-09 1.12.1 → 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.
Files changed (54) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/NOTICE +16 -7
  3. package/README.md +25 -26
  4. package/dist/apidom-ns-json-schema-2019-09.browser.js +1 -1
  5. package/package.json +11 -9
  6. package/src/elements/JSONSchema.cjs +7 -7
  7. package/src/elements/JSONSchema.mjs +7 -8
  8. package/src/elements/LinkDescription.cjs +5 -0
  9. package/src/elements/LinkDescription.mjs +5 -0
  10. package/src/index.cjs +11 -19
  11. package/src/index.mjs +4 -5
  12. package/src/predicates.cjs +9 -16
  13. package/src/predicates.mjs +5 -15
  14. package/src/refractor/index.cjs +38 -18
  15. package/src/refractor/index.mjs +33 -16
  16. package/src/refractor/inspect.cjs +43 -0
  17. package/src/refractor/inspect.mjs +37 -0
  18. package/src/refractor/plugins/replace-empty-element.cjs +34 -28
  19. package/src/refractor/plugins/replace-empty-element.mjs +14 -8
  20. package/src/refractor/specification.cjs +5 -2
  21. package/src/refractor/specification.mjs +5 -2
  22. package/src/refractor/toolbox.cjs +8 -3
  23. package/src/refractor/toolbox.mjs +6 -2
  24. package/src/refractor/visitors/json-schema/$defsVisitor.cjs +4 -5
  25. package/src/refractor/visitors/json-schema/$defsVisitor.mjs +3 -6
  26. package/src/refractor/visitors/json-schema/$refVisitor.cjs +2 -3
  27. package/src/refractor/visitors/json-schema/$refVisitor.mjs +2 -3
  28. package/src/refractor/visitors/json-schema/$vocabularyVisitor.cjs +2 -3
  29. package/src/refractor/visitors/json-schema/$vocabularyVisitor.mjs +2 -3
  30. package/src/refractor/visitors/json-schema/AllOfVisitor.cjs +7 -7
  31. package/src/refractor/visitors/json-schema/AllOfVisitor.mjs +6 -8
  32. package/src/refractor/visitors/json-schema/AnyOfVisitor.cjs +7 -7
  33. package/src/refractor/visitors/json-schema/AnyOfVisitor.mjs +6 -8
  34. package/src/refractor/visitors/json-schema/DependentRequiredVisitor.cjs +2 -3
  35. package/src/refractor/visitors/json-schema/DependentRequiredVisitor.mjs +2 -3
  36. package/src/refractor/visitors/json-schema/DependentSchemasVisitor.cjs +4 -5
  37. package/src/refractor/visitors/json-schema/DependentSchemasVisitor.mjs +3 -6
  38. package/src/refractor/visitors/json-schema/ItemsVisitor.cjs +13 -13
  39. package/src/refractor/visitors/json-schema/ItemsVisitor.mjs +12 -14
  40. package/src/refractor/visitors/json-schema/OneOfVisitor.cjs +7 -7
  41. package/src/refractor/visitors/json-schema/OneOfVisitor.mjs +6 -8
  42. package/src/refractor/visitors/json-schema/PatternPropertiesVisitor.cjs +4 -5
  43. package/src/refractor/visitors/json-schema/PatternPropertiesVisitor.mjs +3 -6
  44. package/src/refractor/visitors/json-schema/PropertiesVisitor.cjs +4 -5
  45. package/src/refractor/visitors/json-schema/PropertiesVisitor.mjs +3 -6
  46. package/src/refractor/visitors/json-schema/bases.cjs +23 -0
  47. package/src/refractor/visitors/json-schema/bases.mjs +20 -0
  48. package/src/refractor/visitors/json-schema/index.cjs +6 -6
  49. package/src/refractor/visitors/json-schema/index.mjs +5 -5
  50. package/types/apidom-ns-json-schema-2019-09.d.ts +141 -307
  51. package/src/refractor/registration.cjs +0 -13
  52. package/src/refractor/registration.mjs +0 -6
  53. package/src/traversal/visitor.cjs +0 -15
  54. package/src/traversal/visitor.mjs +0 -11
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@speclynx/apidom-ns-json-schema-2019-09",
3
- "version": "1.12.1",
3
+ "version": "2.0.1",
4
4
  "description": "JSON Schema 2019-09 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-2019-09.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,12 @@
43
43
  "license": "Apache-2.0",
44
44
  "dependencies": {
45
45
  "@babel/runtime-corejs3": "^7.28.4",
46
- "@speclynx/apidom-core": "^1.12.1",
47
- "@speclynx/apidom-error": "^1.12.1",
48
- "@speclynx/apidom-ns-json-schema-draft-7": "^1.12.1",
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-draft-6": "^2.0.1",
50
+ "@speclynx/apidom-ns-json-schema-draft-7": "^2.0.1",
51
+ "@speclynx/apidom-traverse": "^2.0.1",
50
52
  "ramda": "~0.32.0",
51
53
  "ramda-adjunct": "^6.0.0",
52
54
  "ts-mixer": "^6.0.4"
@@ -61,5 +63,5 @@
61
63
  "README.md",
62
64
  "CHANGELOG.md"
63
65
  ],
64
- "gitHead": "49be88493f922c4ace2e4ebc0f23387ccb62c4fc"
66
+ "gitHead": "6a9caf87f445f76ffd69afa760990ffa784bc82d"
65
67
  }
@@ -58,7 +58,7 @@ class JSONSchema extends _apidomNsJsonSchemaDraft.JSONSchemaElement {
58
58
  get definitions() {
59
59
  throw new _apidomError.UnsupportedOperationError('definitions keyword from Validation vocabulary has been renamed to $defs.');
60
60
  }
61
- set definitions(definitions) {
61
+ set definitions(_definitions) {
62
62
  throw new _apidomError.UnsupportedOperationError('definitions keyword from Validation vocabulary has been renamed to $defs.');
63
63
  }
64
64
 
@@ -101,20 +101,20 @@ class JSONSchema extends _apidomNsJsonSchemaDraft.JSONSchemaElement {
101
101
  get dependencies() {
102
102
  throw new _apidomError.UnsupportedOperationError('dependencies keyword from Validation vocabulary has been renamed to dependentSchemas.');
103
103
  }
104
- set dependencies(dependencies) {
104
+ set dependencies(_dependencies) {
105
105
  throw new _apidomError.UnsupportedOperationError('dependencies keyword from Validation vocabulary has been renamed to dependentSchemas.');
106
106
  }
107
- get items() {
107
+ get itemsField() {
108
108
  return this.get('items');
109
109
  }
110
- set items(items) {
110
+ set itemsField(items) {
111
111
  this.set('items', items);
112
112
  }
113
- get containsProp() {
113
+ get contains() {
114
114
  return this.get('contains');
115
115
  }
116
- set containsProp(containsProp) {
117
- this.set('contains', containsProp);
116
+ set contains(contains) {
117
+ this.set('contains', contains);
118
118
  }
119
119
  get additionalProperties() {
120
120
  return this.get('additionalProperties');
@@ -1,6 +1,5 @@
1
1
  import { UnsupportedOperationError } from '@speclynx/apidom-error';
2
2
  import { JSONSchemaElement } from '@speclynx/apidom-ns-json-schema-draft-7';
3
-
4
3
  /**
5
4
  * @public
6
5
  */
@@ -55,7 +54,7 @@ class JSONSchema extends JSONSchemaElement {
55
54
  get definitions() {
56
55
  throw new UnsupportedOperationError('definitions keyword from Validation vocabulary has been renamed to $defs.');
57
56
  }
58
- set definitions(definitions) {
57
+ set definitions(_definitions) {
59
58
  throw new UnsupportedOperationError('definitions keyword from Validation vocabulary has been renamed to $defs.');
60
59
  }
61
60
 
@@ -98,20 +97,20 @@ class JSONSchema extends JSONSchemaElement {
98
97
  get dependencies() {
99
98
  throw new UnsupportedOperationError('dependencies keyword from Validation vocabulary has been renamed to dependentSchemas.');
100
99
  }
101
- set dependencies(dependencies) {
100
+ set dependencies(_dependencies) {
102
101
  throw new UnsupportedOperationError('dependencies keyword from Validation vocabulary has been renamed to dependentSchemas.');
103
102
  }
104
- get items() {
103
+ get itemsField() {
105
104
  return this.get('items');
106
105
  }
107
- set items(items) {
106
+ set itemsField(items) {
108
107
  this.set('items', items);
109
108
  }
110
- get containsProp() {
109
+ get contains() {
111
110
  return this.get('contains');
112
111
  }
113
- set containsProp(containsProp) {
114
- this.set('contains', containsProp);
112
+ set contains(contains) {
113
+ this.set('contains', contains);
115
114
  }
116
115
  get additionalProperties() {
117
116
  return this.get('additionalProperties');
@@ -9,6 +9,11 @@ var _apidomNsJsonSchemaDraft = require("@speclynx/apidom-ns-json-schema-draft-7"
9
9
  */
10
10
 
11
11
  class LinkDescription extends _apidomNsJsonSchemaDraft.LinkDescriptionElement {
12
+ constructor(content, meta, attributes) {
13
+ super(content, meta, attributes);
14
+ this.element = 'linkDescription';
15
+ }
16
+
12
17
  /**
13
18
  * Link Target Attributes.
14
19
  *
@@ -5,6 +5,11 @@ import { LinkDescriptionElement } from '@speclynx/apidom-ns-json-schema-draft-7'
5
5
  */
6
6
 
7
7
  class LinkDescription extends LinkDescriptionElement {
8
+ constructor(content, meta, attributes) {
9
+ super(content, meta, attributes);
10
+ this.element = 'linkDescription';
11
+ }
12
+
8
13
  /**
9
14
  * Link Target Attributes.
10
15
  *
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.keyMap = 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.getNodeType = exports.default = exports.createRefractor = exports.Visitor = exports.SpecificationVisitor = exports.PropertiesVisitor = exports.PatternedFieldsVisitor = exports.PatternPropertiesVisitor = exports.ParentSchemaAwareVisitor = exports.OneOfVisitor = exports.MapVisitor = exports.LinkDescriptionVisitor = exports.LinkDescriptionElement = exports.JSONSchemaVisitor = exports.JSONSchemaElement = exports.JSONSchema201909MediaTypes = 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.isMediaElement = exports.isLinkDescriptionElement = exports.isJSONSchemaElement = exports.isJSONReferenceElement = exports.default = exports.Visitor = exports.SpecificationVisitor = exports.PropertiesVisitor = exports.PatternedFieldsVisitor = exports.PatternPropertiesVisitor = exports.ParentSchemaAwareVisitor = exports.OneOfVisitor = exports.MapVisitor = exports.LinkDescriptionVisitor = exports.LinkDescriptionElement = exports.JSONSchemaVisitor = exports.JSONSchemaElement = exports.JSONSchema201909MediaTypes = 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.JSONSchema201909MediaTypes = _mediaTypes.JSONSchema201909MediaTypes;
@@ -24,10 +13,13 @@ 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");
21
+ exports.isJSONReferenceElement = _predicates.isJSONReferenceElement;
22
+ exports.isMediaElement = _predicates.isMediaElement;
31
23
  exports.isJSONSchemaElement = _predicates.isJSONSchemaElement;
32
24
  exports.isLinkDescriptionElement = _predicates.isLinkDescriptionElement;
33
25
  var _apidomNsJsonSchemaDraft = require("@speclynx/apidom-ns-json-schema-draft-7");
@@ -39,6 +31,9 @@ exports.MapVisitor = _apidomNsJsonSchemaDraft.MapVisitor;
39
31
  exports.AlternatingVisitor = _apidomNsJsonSchemaDraft.AlternatingVisitor;
40
32
  exports.ParentSchemaAwareVisitor = _apidomNsJsonSchemaDraft.ParentSchemaAwareVisitor;
41
33
  exports.Visitor = _apidomNsJsonSchemaDraft.Visitor;
34
+ var _bases = require("./refractor/visitors/json-schema/bases.cjs");
35
+ exports.BaseSchemaArrayVisitor = _bases.BaseSchemaArrayVisitor;
36
+ exports.BaseSchemaMapVisitor = _bases.BaseSchemaMapVisitor;
42
37
  var _index2 = _interopRequireDefault(require("./refractor/visitors/json-schema/index.cjs"));
43
38
  exports.JSONSchemaVisitor = _index2.default;
44
39
  var _index3 = _interopRequireDefault(require("./refractor/visitors/json-schema/link-description/index.cjs"));
@@ -65,9 +60,6 @@ var _PatternPropertiesVisitor = _interopRequireDefault(require("./refractor/visi
65
60
  exports.PatternPropertiesVisitor = _PatternPropertiesVisitor.default;
66
61
  var _PropertiesVisitor = _interopRequireDefault(require("./refractor/visitors/json-schema/PropertiesVisitor.cjs"));
67
62
  exports.PropertiesVisitor = _PropertiesVisitor.default;
68
- var _visitor = require("./traversal/visitor.cjs");
69
- exports.keyMap = _visitor.keyMap;
70
- exports.getNodeType = _visitor.getNodeType;
71
- var _registration = require("./refractor/registration.cjs");
72
- exports.JSONSchemaElement = _registration.JSONSchemaElement;
73
- exports.LinkDescriptionElement = _registration.LinkDescriptionElement;
63
+ var _inspect = require("./refractor/inspect.cjs");
64
+ exports.JSONSchemaElement = _inspect.JSONSchemaElement;
65
+ exports.LinkDescriptionElement = _inspect.LinkDescriptionElement;
package/src/index.mjs CHANGED
@@ -1,11 +1,11 @@
1
- export { isRefElement, isLinkElement, isMemberElement, isObjectElement, isArrayElement, isBooleanElement, isNullElement, isElement, isNumberElement, isStringElement } from '@speclynx/apidom-core';
2
1
  export { default as mediaTypes, JSONSchema201909MediaTypes } 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
- export { isJSONSchemaElement, isLinkDescriptionElement } from "./predicates.mjs";
6
+ export { isJSONReferenceElement, isMediaElement, isJSONSchemaElement, isLinkDescriptionElement } from "./predicates.mjs";
8
7
  export { SpecificationVisitor, FallbackVisitor, FixedFieldsVisitor, PatternedFieldsVisitor, MapVisitor, AlternatingVisitor, ParentSchemaAwareVisitor, Visitor } from '@speclynx/apidom-ns-json-schema-draft-7';
8
+ export { BaseSchemaArrayVisitor, BaseSchemaMapVisitor } from "./refractor/visitors/json-schema/bases.mjs";
9
9
  export { default as JSONSchemaVisitor } from "./refractor/visitors/json-schema/index.mjs";
10
10
  export { default as LinkDescriptionVisitor } from "./refractor/visitors/json-schema/link-description/index.mjs";
11
11
  export { default as $defsVisitor } from "./refractor/visitors/json-schema/$defsVisitor.mjs";
@@ -19,8 +19,7 @@ export { default as ItemsVisitor } from "./refractor/visitors/json-schema/ItemsV
19
19
  export { default as OneOfVisitor } from "./refractor/visitors/json-schema/OneOfVisitor.mjs";
20
20
  export { default as PatternPropertiesVisitor } from "./refractor/visitors/json-schema/PatternPropertiesVisitor.mjs";
21
21
  export { default as PropertiesVisitor } from "./refractor/visitors/json-schema/PropertiesVisitor.mjs";
22
- export { keyMap, getNodeType } from "./traversal/visitor.mjs";
23
22
  /**
24
23
  * JSON Schema 2019-09 specification elements.
25
24
  */
26
- export { JSONSchemaElement, LinkDescriptionElement } from "./refractor/registration.mjs";
25
+ export { JSONSchemaElement, LinkDescriptionElement } from "./refractor/inspect.mjs";
@@ -2,28 +2,21 @@
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
4
4
  exports.__esModule = true;
5
- exports.isLinkDescriptionElement = exports.isJSONSchemaElement = void 0;
6
- var _apidomCore = require("@speclynx/apidom-core");
5
+ exports.isMediaElement = exports.isLinkDescriptionElement = exports.isJSONSchemaElement = exports.isJSONReferenceElement = void 0;
7
6
  var _JSONSchema = _interopRequireDefault(require("./elements/JSONSchema.cjs"));
8
7
  var _LinkDescription = _interopRequireDefault(require("./elements/LinkDescription.cjs"));
8
+ var _apidomNsJsonSchemaDraft = require("@speclynx/apidom-ns-json-schema-draft-7");
9
+ exports.isJSONReferenceElement = _apidomNsJsonSchemaDraft.isJSONReferenceElement;
10
+ var _apidomNsJsonSchemaDraft2 = require("@speclynx/apidom-ns-json-schema-draft-6");
11
+ exports.isMediaElement = _apidomNsJsonSchemaDraft2.isMediaElement;
9
12
  /**
10
13
  * @public
11
14
  */
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('JSONSchema201909', element) && primitiveEq('object', element);
18
- });
15
+ const isJSONSchemaElement = element => element instanceof _JSONSchema.default;
19
16
 
20
17
  /**
21
18
  * @public
22
19
  */
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
- });
20
+ exports.isJSONSchemaElement = isJSONSchemaElement;
21
+ const isLinkDescriptionElement = element => element instanceof _LinkDescription.default;
22
+ exports.isLinkDescriptionElement = isLinkDescriptionElement;
@@ -1,24 +1,14 @@
1
- import { createPredicate } from '@speclynx/apidom-core';
2
1
  import JSONSchemaElement from "./elements/JSONSchema.mjs";
3
2
  import LinkDescriptionElement from "./elements/LinkDescription.mjs";
3
+ export { isJSONReferenceElement } from '@speclynx/apidom-ns-json-schema-draft-7';
4
+ export { isMediaElement } from '@speclynx/apidom-ns-json-schema-draft-6';
5
+
4
6
  /**
5
7
  * @public
6
8
  */
7
- export const isJSONSchemaElement = createPredicate(({
8
- hasBasicElementProps,
9
- isElementType,
10
- primitiveEq
11
- }) => {
12
- return element => element instanceof JSONSchemaElement || hasBasicElementProps(element) && isElementType('JSONSchema201909', element) && primitiveEq('object', element);
13
- });
9
+ export const isJSONSchemaElement = element => element instanceof JSONSchemaElement;
14
10
 
15
11
  /**
16
12
  * @public
17
13
  */
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
- });
14
+ 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 = 'jSONSchema201909',
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: 'jSONSchema201909'
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 = 'jSONSchema201909',
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: 'jSONSchema201909'
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 };