@speclynx/apidom-ns-json-schema-draft-4 1.12.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 (93) hide show
  1. package/CHANGELOG.md +82 -0
  2. package/LICENSE +202 -0
  3. package/LICENSES/AFL-3.0.txt +182 -0
  4. package/LICENSES/Apache-2.0.txt +202 -0
  5. package/LICENSES/BSD-3-Clause.txt +26 -0
  6. package/LICENSES/MIT.txt +9 -0
  7. package/NOTICE +65 -0
  8. package/README.md +189 -0
  9. package/dist/apidom-ns-json-schema-draft-4.browser.js +1 -0
  10. package/package.json +64 -0
  11. package/src/elements/JSONReference.cjs +29 -0
  12. package/src/elements/JSONReference.mjs +26 -0
  13. package/src/elements/JSONSchema.cjs +296 -0
  14. package/src/elements/JSONSchema.mjs +292 -0
  15. package/src/elements/LinkDescription.cjs +65 -0
  16. package/src/elements/LinkDescription.mjs +61 -0
  17. package/src/elements/Media.cjs +29 -0
  18. package/src/elements/Media.mjs +26 -0
  19. package/src/index.cjs +66 -0
  20. package/src/index.mjs +24 -0
  21. package/src/media-types.cjs +34 -0
  22. package/src/media-types.mjs +30 -0
  23. package/src/namespace.cjs +25 -0
  24. package/src/namespace.mjs +20 -0
  25. package/src/predicates.cjs +53 -0
  26. package/src/predicates.mjs +48 -0
  27. package/src/refractor/index.cjs +53 -0
  28. package/src/refractor/index.mjs +47 -0
  29. package/src/refractor/plugins/replace-empty-element.cjs +200 -0
  30. package/src/refractor/plugins/replace-empty-element.mjs +194 -0
  31. package/src/refractor/predicates.cjs +16 -0
  32. package/src/refractor/predicates.mjs +12 -0
  33. package/src/refractor/registration.cjs +19 -0
  34. package/src/refractor/registration.mjs +10 -0
  35. package/src/refractor/specification.cjs +182 -0
  36. package/src/refractor/specification.mjs +177 -0
  37. package/src/refractor/toolbox.cjs +21 -0
  38. package/src/refractor/toolbox.mjs +15 -0
  39. package/src/refractor/visitors/FallbackVisitor.cjs +25 -0
  40. package/src/refractor/visitors/FallbackVisitor.mjs +19 -0
  41. package/src/refractor/visitors/SpecificationVisitor.cjs +74 -0
  42. package/src/refractor/visitors/SpecificationVisitor.mjs +68 -0
  43. package/src/refractor/visitors/Visitor.cjs +31 -0
  44. package/src/refractor/visitors/Visitor.mjs +28 -0
  45. package/src/refractor/visitors/generics/AlternatingVisitor.cjs +42 -0
  46. package/src/refractor/visitors/generics/AlternatingVisitor.mjs +35 -0
  47. package/src/refractor/visitors/generics/FixedFieldsVisitor.cjs +53 -0
  48. package/src/refractor/visitors/generics/FixedFieldsVisitor.mjs +46 -0
  49. package/src/refractor/visitors/generics/MapVisitor.cjs +21 -0
  50. package/src/refractor/visitors/generics/MapVisitor.mjs +15 -0
  51. package/src/refractor/visitors/generics/PatternedFieldsVisitor.cjs +53 -0
  52. package/src/refractor/visitors/generics/PatternedFieldsVisitor.mjs +47 -0
  53. package/src/refractor/visitors/json-schema/AllOfVisitor.cjs +35 -0
  54. package/src/refractor/visitors/json-schema/AllOfVisitor.mjs +29 -0
  55. package/src/refractor/visitors/json-schema/AnyOfVisitor.cjs +35 -0
  56. package/src/refractor/visitors/json-schema/AnyOfVisitor.mjs +29 -0
  57. package/src/refractor/visitors/json-schema/DefinitionsVisitor.cjs +27 -0
  58. package/src/refractor/visitors/json-schema/DefinitionsVisitor.mjs +21 -0
  59. package/src/refractor/visitors/json-schema/DependenciesVisitor.cjs +27 -0
  60. package/src/refractor/visitors/json-schema/DependenciesVisitor.mjs +21 -0
  61. package/src/refractor/visitors/json-schema/EnumVisitor.cjs +17 -0
  62. package/src/refractor/visitors/json-schema/EnumVisitor.mjs +12 -0
  63. package/src/refractor/visitors/json-schema/ItemsVisitor.cjs +37 -0
  64. package/src/refractor/visitors/json-schema/ItemsVisitor.mjs +31 -0
  65. package/src/refractor/visitors/json-schema/JSONSchemaOrJSONReferenceVisitor.cjs +24 -0
  66. package/src/refractor/visitors/json-schema/JSONSchemaOrJSONReferenceVisitor.mjs +19 -0
  67. package/src/refractor/visitors/json-schema/LinksVisitor.cjs +33 -0
  68. package/src/refractor/visitors/json-schema/LinksVisitor.mjs +27 -0
  69. package/src/refractor/visitors/json-schema/OneOfVisitor.cjs +35 -0
  70. package/src/refractor/visitors/json-schema/OneOfVisitor.mjs +29 -0
  71. package/src/refractor/visitors/json-schema/ParentSchemaAwareVisitor.cjs +20 -0
  72. package/src/refractor/visitors/json-schema/ParentSchemaAwareVisitor.mjs +16 -0
  73. package/src/refractor/visitors/json-schema/PatternPropertiesVisitor.cjs +27 -0
  74. package/src/refractor/visitors/json-schema/PatternPropertiesVisitor.mjs +21 -0
  75. package/src/refractor/visitors/json-schema/PropertiesVisitor.cjs +27 -0
  76. package/src/refractor/visitors/json-schema/PropertiesVisitor.mjs +21 -0
  77. package/src/refractor/visitors/json-schema/RequiredVisitor.cjs +17 -0
  78. package/src/refractor/visitors/json-schema/RequiredVisitor.mjs +12 -0
  79. package/src/refractor/visitors/json-schema/TypeVisitor.cjs +22 -0
  80. package/src/refractor/visitors/json-schema/TypeVisitor.mjs +17 -0
  81. package/src/refractor/visitors/json-schema/index.cjs +64 -0
  82. package/src/refractor/visitors/json-schema/index.mjs +58 -0
  83. package/src/refractor/visitors/json-schema/json-reference/$RefVisitor.cjs +17 -0
  84. package/src/refractor/visitors/json-schema/json-reference/$RefVisitor.mjs +12 -0
  85. package/src/refractor/visitors/json-schema/json-reference/index.cjs +35 -0
  86. package/src/refractor/visitors/json-schema/json-reference/index.mjs +29 -0
  87. package/src/refractor/visitors/json-schema/link-description/index.cjs +25 -0
  88. package/src/refractor/visitors/json-schema/link-description/index.mjs +19 -0
  89. package/src/refractor/visitors/json-schema/media/index.cjs +25 -0
  90. package/src/refractor/visitors/json-schema/media/index.mjs +19 -0
  91. package/src/traversal/visitor.cjs +26 -0
  92. package/src/traversal/visitor.mjs +22 -0
  93. package/types/apidom-ns-json-schema-draft-4.d.ts +905 -0
@@ -0,0 +1,177 @@
1
+ import FallbackVisitor from "./visitors/FallbackVisitor.mjs";
2
+ import JSONSchemaVisitor from "./visitors/json-schema/index.mjs";
3
+ import JSONSchemaItemsVisitor from "./visitors/json-schema/ItemsVisitor.mjs";
4
+ import JSONSchemaRequiredVisitor from "./visitors/json-schema/RequiredVisitor.mjs";
5
+ import JSONSchemaPropertiesVisitor from "./visitors/json-schema/PropertiesVisitor.mjs";
6
+ import JSONSchemaPatternPropertiesVisitor from "./visitors/json-schema/PatternPropertiesVisitor.mjs";
7
+ import JSONSchemaDependenciesVisitor from "./visitors/json-schema/DependenciesVisitor.mjs";
8
+ import JSONSchemaEnumVisitor from "./visitors/json-schema/EnumVisitor.mjs";
9
+ import JSONSchemaTypeVisitor from "./visitors/json-schema/TypeVisitor.mjs";
10
+ import JSONSchemaAllOfVisitor from "./visitors/json-schema/AllOfVisitor.mjs";
11
+ import JSONSchemaAnyOfVisitor from "./visitors/json-schema/AnyOfVisitor.mjs";
12
+ import JSONSchemaOneOfVisitor from "./visitors/json-schema/OneOfVisitor.mjs";
13
+ import JSONSchemaDefinitionsVisitor from "./visitors/json-schema/DefinitionsVisitor.mjs";
14
+ import JSONSchemaLinksVisitor from "./visitors/json-schema/LinksVisitor.mjs";
15
+ import JSONReferenceVisitor from "./visitors/json-schema/json-reference/index.mjs";
16
+ import JSONReference$RefVisitor from "./visitors/json-schema/json-reference/$RefVisitor.mjs";
17
+ import JSONSchemaOrJSONReferenceVisitor from "./visitors/json-schema/JSONSchemaOrJSONReferenceVisitor.mjs";
18
+ import MediaVisitor from "./visitors/json-schema/media/index.mjs";
19
+ import LinkDescriptionVisitor from "./visitors/json-schema/link-description/index.mjs";
20
+ /**
21
+ * Specification object allows us to have complete control over visitors
22
+ * when traversing the ApiDOM.
23
+ * Specification also allows us to create amended refractors from
24
+ * existing ones by manipulating it.
25
+ *
26
+ * Note: Specification object allows to use absolute internal JSON pointers.
27
+ * @public
28
+ */
29
+ const specification = {
30
+ visitors: {
31
+ value: FallbackVisitor,
32
+ JSONSchemaOrJSONReferenceVisitor,
33
+ document: {
34
+ objects: {
35
+ JSONSchema: {
36
+ $visitor: JSONSchemaVisitor,
37
+ fixedFields: {
38
+ // core vocabulary
39
+ id: {
40
+ $ref: '#/visitors/value'
41
+ },
42
+ $schema: {
43
+ $ref: '#/visitors/value'
44
+ },
45
+ // validation vocabulary
46
+ // validation keywords for numeric instances (number and integer)
47
+ multipleOf: {
48
+ $ref: '#/visitors/value'
49
+ },
50
+ maximum: {
51
+ $ref: '#/visitors/value'
52
+ },
53
+ exclusiveMaximum: {
54
+ $ref: '#/visitors/value'
55
+ },
56
+ minimum: {
57
+ $ref: '#/visitors/value'
58
+ },
59
+ exclusiveMinimum: {
60
+ $ref: '#/visitors/value'
61
+ },
62
+ // validation keywords for strings
63
+ maxLength: {
64
+ $ref: '#/visitors/value'
65
+ },
66
+ minLength: {
67
+ $ref: '#/visitors/value'
68
+ },
69
+ pattern: {
70
+ $ref: '#/visitors/value'
71
+ },
72
+ // validation keywords for arrays
73
+ additionalItems: JSONSchemaOrJSONReferenceVisitor,
74
+ items: JSONSchemaItemsVisitor,
75
+ maxItems: {
76
+ $ref: '#/visitors/value'
77
+ },
78
+ minItems: {
79
+ $ref: '#/visitors/value'
80
+ },
81
+ uniqueItems: {
82
+ $ref: '#/visitors/value'
83
+ },
84
+ // validation keywords for objects
85
+ maxProperties: {
86
+ $ref: '#/visitors/value'
87
+ },
88
+ minProperties: {
89
+ $ref: '#/visitors/value'
90
+ },
91
+ required: JSONSchemaRequiredVisitor,
92
+ properties: JSONSchemaPropertiesVisitor,
93
+ additionalProperties: JSONSchemaOrJSONReferenceVisitor,
94
+ patternProperties: JSONSchemaPatternPropertiesVisitor,
95
+ dependencies: JSONSchemaDependenciesVisitor,
96
+ // validation keywords for any instance type
97
+ enum: JSONSchemaEnumVisitor,
98
+ type: JSONSchemaTypeVisitor,
99
+ allOf: JSONSchemaAllOfVisitor,
100
+ anyOf: JSONSchemaAnyOfVisitor,
101
+ oneOf: JSONSchemaOneOfVisitor,
102
+ not: JSONSchemaOrJSONReferenceVisitor,
103
+ definitions: JSONSchemaDefinitionsVisitor,
104
+ // metadata keywords
105
+ title: {
106
+ $ref: '#/visitors/value'
107
+ },
108
+ description: {
109
+ $ref: '#/visitors/value'
110
+ },
111
+ default: {
112
+ $ref: '#/visitors/value'
113
+ },
114
+ // semantic validation with "format"
115
+ format: {
116
+ $ref: '#/visitors/value'
117
+ },
118
+ // JSON Hyper-Schema
119
+ base: {
120
+ $ref: '#/visitors/value'
121
+ },
122
+ links: JSONSchemaLinksVisitor,
123
+ media: {
124
+ $ref: '#/visitors/document/objects/Media'
125
+ },
126
+ readOnly: {
127
+ $ref: '#/visitors/value'
128
+ }
129
+ }
130
+ },
131
+ JSONReference: {
132
+ $visitor: JSONReferenceVisitor,
133
+ fixedFields: {
134
+ $ref: JSONReference$RefVisitor
135
+ }
136
+ },
137
+ Media: {
138
+ $visitor: MediaVisitor,
139
+ fixedFields: {
140
+ binaryEncoding: {
141
+ $ref: '#/visitors/value'
142
+ },
143
+ type: {
144
+ $ref: '#/visitors/value'
145
+ }
146
+ }
147
+ },
148
+ LinkDescription: {
149
+ $visitor: LinkDescriptionVisitor,
150
+ fixedFields: {
151
+ href: {
152
+ $ref: '#/visitors/value'
153
+ },
154
+ rel: {
155
+ $ref: '#/visitors/value'
156
+ },
157
+ title: {
158
+ $ref: '#/visitors/value'
159
+ },
160
+ targetSchema: JSONSchemaOrJSONReferenceVisitor,
161
+ mediaType: {
162
+ $ref: '#/visitors/value'
163
+ },
164
+ method: {
165
+ $ref: '#/visitors/value'
166
+ },
167
+ encType: {
168
+ $ref: '#/visitors/value'
169
+ },
170
+ schema: JSONSchemaOrJSONReferenceVisitor
171
+ }
172
+ }
173
+ }
174
+ }
175
+ }
176
+ };
177
+ export default specification;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
4
+ var _interopRequireWildcard = require("@babel/runtime-corejs3/helpers/interopRequireWildcard").default;
5
+ exports.__esModule = true;
6
+ exports.default = void 0;
7
+ var _apidomCore = require("@speclynx/apidom-core");
8
+ var jsonSchemaDraft4Predicates = _interopRequireWildcard(require("../predicates.cjs"));
9
+ var _namespace = _interopRequireDefault(require("../namespace.cjs"));
10
+ const createToolbox = () => {
11
+ const namespace = (0, _apidomCore.createNamespace)(_namespace.default);
12
+ const predicates = {
13
+ ...jsonSchemaDraft4Predicates,
14
+ isStringElement: _apidomCore.isStringElement
15
+ };
16
+ return {
17
+ predicates,
18
+ namespace
19
+ };
20
+ };
21
+ var _default = exports.default = createToolbox;
@@ -0,0 +1,15 @@
1
+ import { createNamespace, isStringElement } from '@speclynx/apidom-core';
2
+ import * as jsonSchemaDraft4Predicates from "../predicates.mjs";
3
+ import jsonSchemaDraft4Namespace from "../namespace.mjs";
4
+ const createToolbox = () => {
5
+ const namespace = createNamespace(jsonSchemaDraft4Namespace);
6
+ const predicates = {
7
+ ...jsonSchemaDraft4Predicates,
8
+ isStringElement
9
+ };
10
+ return {
11
+ predicates,
12
+ namespace
13
+ };
14
+ };
15
+ export default createToolbox;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
4
+ exports.__esModule = true;
5
+ exports.default = void 0;
6
+ var _apidomCore = require("@speclynx/apidom-core");
7
+ var _Visitor = _interopRequireDefault(require("./Visitor.cjs"));
8
+ /**
9
+ * This visitor is responsible for falling back to current traversed element
10
+ * Given JSONSchemaVisitor expects ObjectElement to be traversed. If
11
+ * different Element is provided FallBackVisitor is responsible to assigning
12
+ * this Element as current element.
13
+ * @public
14
+ */
15
+
16
+ /**
17
+ * @public
18
+ */
19
+ class FallbackVisitor extends _Visitor.default {
20
+ enter(element) {
21
+ this.element = (0, _apidomCore.cloneDeep)(element);
22
+ return _apidomCore.BREAK;
23
+ }
24
+ }
25
+ var _default = exports.default = FallbackVisitor;
@@ -0,0 +1,19 @@
1
+ import { BREAK, cloneDeep } from '@speclynx/apidom-core';
2
+ import Visitor from "./Visitor.mjs";
3
+ /**
4
+ * This visitor is responsible for falling back to current traversed element
5
+ * Given JSONSchemaVisitor expects ObjectElement to be traversed. If
6
+ * different Element is provided FallBackVisitor is responsible to assigning
7
+ * this Element as current element.
8
+ * @public
9
+ */
10
+ /**
11
+ * @public
12
+ */
13
+ class FallbackVisitor extends Visitor {
14
+ enter(element) {
15
+ this.element = cloneDeep(element);
16
+ return BREAK;
17
+ }
18
+ }
19
+ export default FallbackVisitor;
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
4
+ exports.__esModule = true;
5
+ exports.default = void 0;
6
+ var _ramda = require("ramda");
7
+ var _ramdaAdjunct = require("ramda-adjunct");
8
+ var _apidomCore = require("@speclynx/apidom-core");
9
+ var _Visitor = _interopRequireDefault(require("./Visitor.cjs"));
10
+ var _FallbackVisitor = _interopRequireDefault(require("./FallbackVisitor.cjs"));
11
+ /**
12
+ * This is a base Type for every visitor that does
13
+ * internal look-ups to retrieve other child visitors.
14
+ * @public
15
+ */
16
+
17
+ /**
18
+ * @public
19
+ */
20
+ class SpecificationVisitor extends _Visitor.default {
21
+ specObj;
22
+ passingOptionsNames = ['specObj', 'parent'];
23
+ constructor({
24
+ specObj,
25
+ ...rest
26
+ }) {
27
+ super({
28
+ ...rest
29
+ });
30
+ this.specObj = specObj;
31
+ }
32
+ retrievePassingOptions() {
33
+ return (0, _ramda.pick)(this.passingOptionsNames, this);
34
+ }
35
+ retrieveFixedFields(specPath) {
36
+ const fixedFields = (0, _ramda.path)(['visitors', ...specPath, 'fixedFields'], this.specObj);
37
+ if (typeof fixedFields === 'object' && fixedFields !== null) {
38
+ return Object.keys(fixedFields);
39
+ }
40
+ return [];
41
+ }
42
+ retrieveVisitor(specPath) {
43
+ if ((0, _ramda.pathSatisfies)(_ramdaAdjunct.isFunction, ['visitors', ...specPath], this.specObj)) {
44
+ return (0, _ramda.path)(['visitors', ...specPath], this.specObj);
45
+ }
46
+ return (0, _ramda.path)(['visitors', ...specPath, '$visitor'], this.specObj);
47
+ }
48
+ retrieveVisitorInstance(specPath, options = {}) {
49
+ const passingOpts = this.retrievePassingOptions();
50
+ const VisitorClz = this.retrieveVisitor(specPath);
51
+ const visitorOpts = {
52
+ ...passingOpts,
53
+ ...options
54
+ };
55
+ return new VisitorClz(visitorOpts);
56
+ }
57
+ toRefractedElement(specPath, element, options = {}) {
58
+ /**
59
+ * This is `Visitor shortcut`: mechanism for short-circuiting the traversal and replacing
60
+ * it by basic node cloning.
61
+ *
62
+ * Visiting the element is equivalent to cloning it if the prototype of a visitor
63
+ * is the same as the prototype of FallbackVisitor. If that's the case, we can avoid
64
+ * bootstrapping the traversal cycle for fields that don't require any special visiting.
65
+ */
66
+ const visitor = this.retrieveVisitorInstance(specPath, options);
67
+ if (visitor instanceof _FallbackVisitor.default && visitor?.constructor === _FallbackVisitor.default) {
68
+ return (0, _apidomCore.cloneDeep)(element);
69
+ }
70
+ (0, _apidomCore.visit)(element, visitor, options);
71
+ return visitor.element;
72
+ }
73
+ }
74
+ var _default = exports.default = SpecificationVisitor;
@@ -0,0 +1,68 @@
1
+ import { pathSatisfies, path, pick } from 'ramda';
2
+ import { isFunction } from 'ramda-adjunct';
3
+ import { visit, cloneDeep } from '@speclynx/apidom-core';
4
+ import Visitor from "./Visitor.mjs";
5
+ import FallbackVisitor from "./FallbackVisitor.mjs";
6
+ /**
7
+ * This is a base Type for every visitor that does
8
+ * internal look-ups to retrieve other child visitors.
9
+ * @public
10
+ */
11
+ /**
12
+ * @public
13
+ */
14
+ class SpecificationVisitor extends Visitor {
15
+ specObj;
16
+ passingOptionsNames = ['specObj', 'parent'];
17
+ constructor({
18
+ specObj,
19
+ ...rest
20
+ }) {
21
+ super({
22
+ ...rest
23
+ });
24
+ this.specObj = specObj;
25
+ }
26
+ retrievePassingOptions() {
27
+ return pick(this.passingOptionsNames, this);
28
+ }
29
+ retrieveFixedFields(specPath) {
30
+ const fixedFields = path(['visitors', ...specPath, 'fixedFields'], this.specObj);
31
+ if (typeof fixedFields === 'object' && fixedFields !== null) {
32
+ return Object.keys(fixedFields);
33
+ }
34
+ return [];
35
+ }
36
+ retrieveVisitor(specPath) {
37
+ if (pathSatisfies(isFunction, ['visitors', ...specPath], this.specObj)) {
38
+ return path(['visitors', ...specPath], this.specObj);
39
+ }
40
+ return path(['visitors', ...specPath, '$visitor'], this.specObj);
41
+ }
42
+ retrieveVisitorInstance(specPath, options = {}) {
43
+ const passingOpts = this.retrievePassingOptions();
44
+ const VisitorClz = this.retrieveVisitor(specPath);
45
+ const visitorOpts = {
46
+ ...passingOpts,
47
+ ...options
48
+ };
49
+ return new VisitorClz(visitorOpts);
50
+ }
51
+ toRefractedElement(specPath, element, options = {}) {
52
+ /**
53
+ * This is `Visitor shortcut`: mechanism for short-circuiting the traversal and replacing
54
+ * it by basic node cloning.
55
+ *
56
+ * Visiting the element is equivalent to cloning it if the prototype of a visitor
57
+ * is the same as the prototype of FallbackVisitor. If that's the case, we can avoid
58
+ * bootstrapping the traversal cycle for fields that don't require any special visiting.
59
+ */
60
+ const visitor = this.retrieveVisitorInstance(specPath, options);
61
+ if (visitor instanceof FallbackVisitor && visitor?.constructor === FallbackVisitor) {
62
+ return cloneDeep(element);
63
+ }
64
+ visit(element, visitor, options);
65
+ return visitor.element;
66
+ }
67
+ }
68
+ export default SpecificationVisitor;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports.default = void 0;
5
+ var _apidomCore = require("@speclynx/apidom-core");
6
+ /**
7
+ * @public
8
+ */
9
+
10
+ /**
11
+ * @public
12
+ */
13
+ class Visitor {
14
+ element;
15
+ constructor(options) {
16
+ Object.assign(this, options);
17
+ }
18
+ copyMetaAndAttributes(from, to) {
19
+ if (from.meta.length > 0 || to.meta.length > 0) {
20
+ to.meta = (0, _apidomCore.deepmerge)(to.meta, from.meta);
21
+ if ((0, _apidomCore.hasElementSourceMap)(from)) {
22
+ // avoid deep merging of source maps
23
+ to.meta.set('sourceMap', from.meta.get('sourceMap'));
24
+ }
25
+ }
26
+ if (from.attributes.length > 0 || from.meta.length > 0) {
27
+ to.attributes = (0, _apidomCore.deepmerge)(to.attributes, from.attributes);
28
+ }
29
+ }
30
+ }
31
+ var _default = exports.default = Visitor;
@@ -0,0 +1,28 @@
1
+ import { hasElementSourceMap, deepmerge } from '@speclynx/apidom-core';
2
+
3
+ /**
4
+ * @public
5
+ */
6
+
7
+ /**
8
+ * @public
9
+ */
10
+ class Visitor {
11
+ element;
12
+ constructor(options) {
13
+ Object.assign(this, options);
14
+ }
15
+ copyMetaAndAttributes(from, to) {
16
+ if (from.meta.length > 0 || to.meta.length > 0) {
17
+ to.meta = deepmerge(to.meta, from.meta);
18
+ if (hasElementSourceMap(from)) {
19
+ // avoid deep merging of source maps
20
+ to.meta.set('sourceMap', from.meta.get('sourceMap'));
21
+ }
22
+ }
23
+ if (from.attributes.length > 0 || from.meta.length > 0) {
24
+ to.attributes = deepmerge(to.attributes, from.attributes);
25
+ }
26
+ }
27
+ }
28
+ export default Visitor;
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
4
+ exports.__esModule = true;
5
+ exports.default = void 0;
6
+ var _ramda = require("ramda");
7
+ var _ramdaAdjunct = require("ramda-adjunct");
8
+ var _apidomCore = require("@speclynx/apidom-core");
9
+ var _SpecificationVisitor = _interopRequireDefault(require("../SpecificationVisitor.cjs"));
10
+ /**
11
+ * @public
12
+ */
13
+
14
+ /**
15
+ * @public
16
+ */
17
+
18
+ /**
19
+ * @public
20
+ */
21
+ class AlternatingVisitor extends _SpecificationVisitor.default {
22
+ alternator;
23
+ constructor({
24
+ alternator,
25
+ ...rest
26
+ }) {
27
+ super({
28
+ ...rest
29
+ });
30
+ this.alternator = alternator;
31
+ }
32
+ enter(element) {
33
+ const functions = this.alternator.map(({
34
+ predicate,
35
+ specPath
36
+ }) => (0, _ramda.ifElse)(predicate, (0, _ramda.always)(specPath), _ramdaAdjunct.stubUndefined));
37
+ const specPath = (0, _ramdaAdjunct.dispatch)(functions)(element);
38
+ this.element = this.toRefractedElement(specPath, element);
39
+ return _apidomCore.BREAK;
40
+ }
41
+ }
42
+ var _default = exports.default = AlternatingVisitor;
@@ -0,0 +1,35 @@
1
+ import { ifElse, always } from 'ramda';
2
+ import { dispatch, stubUndefined } from 'ramda-adjunct';
3
+ import { BREAK } from '@speclynx/apidom-core';
4
+ import SpecificationVisitor from "../SpecificationVisitor.mjs";
5
+ /**
6
+ * @public
7
+ */
8
+ /**
9
+ * @public
10
+ */
11
+ /**
12
+ * @public
13
+ */
14
+ class AlternatingVisitor extends SpecificationVisitor {
15
+ alternator;
16
+ constructor({
17
+ alternator,
18
+ ...rest
19
+ }) {
20
+ super({
21
+ ...rest
22
+ });
23
+ this.alternator = alternator;
24
+ }
25
+ enter(element) {
26
+ const functions = this.alternator.map(({
27
+ predicate,
28
+ specPath
29
+ }) => ifElse(predicate, always(specPath), stubUndefined));
30
+ const specPath = dispatch(functions)(element);
31
+ this.element = this.toRefractedElement(specPath, element);
32
+ return BREAK;
33
+ }
34
+ }
35
+ export default AlternatingVisitor;
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
4
+ exports.__esModule = true;
5
+ exports.default = void 0;
6
+ var _apidomCore = require("@speclynx/apidom-core");
7
+ var _SpecificationVisitor = _interopRequireDefault(require("../SpecificationVisitor.cjs"));
8
+ /**
9
+ * @public
10
+ */
11
+
12
+ /**
13
+ * @public
14
+ */
15
+
16
+ /**
17
+ * @public
18
+ */
19
+ class FixedFieldsVisitor extends _SpecificationVisitor.default {
20
+ specPath;
21
+ ignoredFields;
22
+ constructor({
23
+ specPath,
24
+ ignoredFields,
25
+ ...rest
26
+ }) {
27
+ super({
28
+ ...rest
29
+ });
30
+ this.specPath = specPath;
31
+ this.ignoredFields = ignoredFields || [];
32
+ }
33
+ ObjectElement(objectElement) {
34
+ const specPath = this.specPath(objectElement);
35
+ const fields = this.retrieveFixedFields(specPath);
36
+
37
+ // @ts-ignore
38
+ objectElement.forEach((value, key, memberElement) => {
39
+ if ((0, _apidomCore.isStringElement)(key) && fields.includes((0, _apidomCore.toValue)(key)) && !this.ignoredFields.includes((0, _apidomCore.toValue)(key))) {
40
+ const fixedFieldElement = this.toRefractedElement([...specPath, 'fixedFields', (0, _apidomCore.toValue)(key)], value);
41
+ const newMemberElement = new _apidomCore.MemberElement((0, _apidomCore.cloneDeep)(key), fixedFieldElement);
42
+ this.copyMetaAndAttributes(memberElement, newMemberElement);
43
+ newMemberElement.classes.push('fixed-field');
44
+ this.element.content.push(newMemberElement);
45
+ } else if (!this.ignoredFields.includes((0, _apidomCore.toValue)(key))) {
46
+ this.element.content.push((0, _apidomCore.cloneDeep)(memberElement));
47
+ }
48
+ });
49
+ this.copyMetaAndAttributes(objectElement, this.element);
50
+ return _apidomCore.BREAK;
51
+ }
52
+ }
53
+ var _default = exports.default = FixedFieldsVisitor;
@@ -0,0 +1,46 @@
1
+ import { isStringElement, MemberElement, BREAK, cloneDeep, toValue } from '@speclynx/apidom-core';
2
+ import SpecificationVisitor from "../SpecificationVisitor.mjs";
3
+ /**
4
+ * @public
5
+ */
6
+ /**
7
+ * @public
8
+ */
9
+ /**
10
+ * @public
11
+ */
12
+ class FixedFieldsVisitor extends SpecificationVisitor {
13
+ specPath;
14
+ ignoredFields;
15
+ constructor({
16
+ specPath,
17
+ ignoredFields,
18
+ ...rest
19
+ }) {
20
+ super({
21
+ ...rest
22
+ });
23
+ this.specPath = specPath;
24
+ this.ignoredFields = ignoredFields || [];
25
+ }
26
+ ObjectElement(objectElement) {
27
+ const specPath = this.specPath(objectElement);
28
+ const fields = this.retrieveFixedFields(specPath);
29
+
30
+ // @ts-ignore
31
+ objectElement.forEach((value, key, memberElement) => {
32
+ if (isStringElement(key) && fields.includes(toValue(key)) && !this.ignoredFields.includes(toValue(key))) {
33
+ const fixedFieldElement = this.toRefractedElement([...specPath, 'fixedFields', toValue(key)], value);
34
+ const newMemberElement = new MemberElement(cloneDeep(key), fixedFieldElement);
35
+ this.copyMetaAndAttributes(memberElement, newMemberElement);
36
+ newMemberElement.classes.push('fixed-field');
37
+ this.element.content.push(newMemberElement);
38
+ } else if (!this.ignoredFields.includes(toValue(key))) {
39
+ this.element.content.push(cloneDeep(memberElement));
40
+ }
41
+ });
42
+ this.copyMetaAndAttributes(objectElement, this.element);
43
+ return BREAK;
44
+ }
45
+ }
46
+ export default FixedFieldsVisitor;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
4
+ exports.__esModule = true;
5
+ exports.default = void 0;
6
+ var _ramdaAdjunct = require("ramda-adjunct");
7
+ var _PatternedFieldsVisitor = _interopRequireDefault(require("./PatternedFieldsVisitor.cjs"));
8
+ /**
9
+ * @public
10
+ */
11
+
12
+ /**
13
+ * @public
14
+ */
15
+ class MapVisitor extends _PatternedFieldsVisitor.default {
16
+ constructor(options) {
17
+ super(options);
18
+ this.fieldPatternPredicate = _ramdaAdjunct.isNonEmptyString;
19
+ }
20
+ }
21
+ var _default = exports.default = MapVisitor;
@@ -0,0 +1,15 @@
1
+ import { isNonEmptyString } from 'ramda-adjunct';
2
+ import PatternedFieldsVisitor from "./PatternedFieldsVisitor.mjs";
3
+ /**
4
+ * @public
5
+ */
6
+ /**
7
+ * @public
8
+ */
9
+ class MapVisitor extends PatternedFieldsVisitor {
10
+ constructor(options) {
11
+ super(options);
12
+ this.fieldPatternPredicate = isNonEmptyString;
13
+ }
14
+ }
15
+ export default MapVisitor;