@speclynx/apidom-reference 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 (112) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/NOTICE +16 -7
  3. package/README.md +0 -33
  4. package/dist/167.apidom-reference.browser.min.js +1 -1
  5. package/dist/451.apidom-reference.browser.min.js +1 -1
  6. package/dist/apidom-reference.browser.js +24594 -23365
  7. package/dist/apidom-reference.browser.min.js +1 -1
  8. package/package.json +24 -57
  9. package/src/configuration/saturated.cjs +34 -42
  10. package/src/configuration/saturated.mjs +0 -8
  11. package/src/dereference/index.cjs +4 -4
  12. package/src/dereference/index.mjs +1 -1
  13. package/src/dereference/strategies/apidom/index.cjs +7 -7
  14. package/src/dereference/strategies/apidom/index.mjs +5 -6
  15. package/src/dereference/strategies/apidom/selectors/element-id.cjs +4 -2
  16. package/src/dereference/strategies/apidom/selectors/element-id.mjs +5 -3
  17. package/src/dereference/strategies/apidom/visitor.cjs +31 -17
  18. package/src/dereference/strategies/apidom/visitor.mjs +25 -12
  19. package/src/dereference/strategies/asyncapi-2/index.cjs +6 -9
  20. package/src/dereference/strategies/asyncapi-2/index.mjs +6 -10
  21. package/src/dereference/strategies/asyncapi-2/visitor.cjs +67 -80
  22. package/src/dereference/strategies/asyncapi-2/visitor.mjs +59 -72
  23. package/src/dereference/strategies/openapi-2/index.cjs +6 -9
  24. package/src/dereference/strategies/openapi-2/index.mjs +6 -10
  25. package/src/dereference/strategies/openapi-2/visitor.cjs +91 -100
  26. package/src/dereference/strategies/openapi-2/visitor.mjs +81 -90
  27. package/src/dereference/strategies/openapi-3-0/index.cjs +6 -9
  28. package/src/dereference/strategies/openapi-3-0/index.mjs +6 -10
  29. package/src/dereference/strategies/openapi-3-0/visitor.cjs +92 -115
  30. package/src/dereference/strategies/openapi-3-0/visitor.mjs +74 -97
  31. package/src/dereference/strategies/openapi-3-1/index.cjs +6 -9
  32. package/src/dereference/strategies/openapi-3-1/index.mjs +6 -10
  33. package/src/dereference/strategies/openapi-3-1/selectors/$anchor.cjs +2 -1
  34. package/src/dereference/strategies/openapi-3-1/selectors/$anchor.mjs +3 -2
  35. package/src/dereference/strategies/openapi-3-1/selectors/uri.cjs +2 -2
  36. package/src/dereference/strategies/openapi-3-1/selectors/uri.mjs +2 -2
  37. package/src/dereference/strategies/openapi-3-1/util.cjs +3 -2
  38. package/src/dereference/strategies/openapi-3-1/util.mjs +4 -3
  39. package/src/dereference/strategies/openapi-3-1/visitor.cjs +130 -156
  40. package/src/dereference/strategies/openapi-3-1/visitor.mjs +106 -132
  41. package/src/dereference/util.cjs +2 -2
  42. package/src/dereference/util.mjs +1 -1
  43. package/src/parse/parsers/apidom-json/index.cjs +5 -5
  44. package/src/parse/parsers/apidom-json/index.mjs +2 -2
  45. package/src/parse/parsers/arazzo-json-1/index.cjs +1 -2
  46. package/src/parse/parsers/arazzo-json-1/index.mjs +1 -2
  47. package/src/parse/parsers/asyncapi-json-2/index.cjs +1 -2
  48. package/src/parse/parsers/asyncapi-json-2/index.mjs +1 -2
  49. package/src/parse/parsers/binary/index-browser.cjs +3 -3
  50. package/src/parse/parsers/binary/index-browser.mjs +1 -1
  51. package/src/parse/parsers/binary/index-node.cjs +3 -3
  52. package/src/parse/parsers/binary/index-node.mjs +1 -1
  53. package/src/parse/parsers/json/index.cjs +1 -2
  54. package/src/parse/parsers/json/index.mjs +1 -2
  55. package/src/parse/parsers/openapi-json-2/index.cjs +1 -2
  56. package/src/parse/parsers/openapi-json-2/index.mjs +1 -2
  57. package/src/parse/parsers/openapi-json-3-0/index.cjs +1 -2
  58. package/src/parse/parsers/openapi-json-3-0/index.mjs +1 -2
  59. package/src/parse/parsers/openapi-json-3-1/index.cjs +1 -2
  60. package/src/parse/parsers/openapi-json-3-1/index.mjs +1 -2
  61. package/src/resolve/index.cjs +4 -4
  62. package/src/resolve/index.mjs +1 -1
  63. package/types/File.d.ts +1 -1
  64. package/types/Reference.d.ts +1 -1
  65. package/types/ReferenceSet.d.ts +1 -1
  66. package/types/apidom-reference.d.ts +8 -9
  67. package/types/bundle/index.d.ts +1 -1
  68. package/types/bundle/strategies/BundleStrategy.d.ts +1 -1
  69. package/types/bundle/strategies/openapi-3-1/index.d.ts +1 -1
  70. package/types/dereference/index.d.ts +1 -1
  71. package/types/dereference/strategies/DereferenceStrategy.d.ts +1 -1
  72. package/types/dereference/strategies/apidom/index.d.ts +1 -1
  73. package/types/dereference/strategies/apidom/selectors/element-id.d.ts +1 -1
  74. package/types/dereference/strategies/apidom/visitor.d.ts +3 -2
  75. package/types/dereference/strategies/asyncapi-2/index.d.ts +2 -2
  76. package/types/dereference/strategies/asyncapi-2/visitor.d.ts +5 -14
  77. package/types/dereference/strategies/openapi-2/index.d.ts +2 -2
  78. package/types/dereference/strategies/openapi-2/visitor.d.ts +6 -17
  79. package/types/dereference/strategies/openapi-3-0/index.d.ts +2 -2
  80. package/types/dereference/strategies/openapi-3-0/visitor.d.ts +7 -20
  81. package/types/dereference/strategies/openapi-3-1/index.d.ts +2 -2
  82. package/types/dereference/strategies/openapi-3-1/selectors/$anchor.d.ts +1 -1
  83. package/types/dereference/strategies/openapi-3-1/selectors/uri.d.ts +1 -1
  84. package/types/dereference/strategies/openapi-3-1/util.d.ts +1 -1
  85. package/types/dereference/strategies/openapi-3-1/visitor.d.ts +8 -23
  86. package/types/dereference/util.d.ts +1 -1
  87. package/types/index.d.ts +1 -1
  88. package/types/options/index.d.ts +1 -1
  89. package/types/parse/index.d.ts +1 -1
  90. package/types/parse/parsers/Parser.d.ts +1 -1
  91. package/types/parse/parsers/apidom-json/index.d.ts +1 -1
  92. package/types/parse/parsers/arazzo-json-1/index.d.ts +1 -2
  93. package/types/parse/parsers/arazzo-yaml-1/index.d.ts +1 -1
  94. package/types/parse/parsers/asyncapi-json-2/index.d.ts +1 -2
  95. package/types/parse/parsers/asyncapi-yaml-2/index.d.ts +1 -1
  96. package/types/parse/parsers/binary/index-browser.d.ts +1 -1
  97. package/types/parse/parsers/binary/index-node.d.ts +1 -1
  98. package/types/parse/parsers/json/index.d.ts +1 -2
  99. package/types/parse/parsers/openapi-json-2/index.d.ts +1 -2
  100. package/types/parse/parsers/openapi-json-3-0/index.d.ts +1 -2
  101. package/types/parse/parsers/openapi-json-3-1/index.d.ts +1 -2
  102. package/types/parse/parsers/openapi-yaml-2/index.d.ts +1 -1
  103. package/types/parse/parsers/openapi-yaml-3-0/index.d.ts +1 -1
  104. package/types/parse/parsers/openapi-yaml-3-1/index.d.ts +1 -1
  105. package/types/parse/parsers/yaml-1-2/index.d.ts +1 -1
  106. package/types/resolve/index.d.ts +1 -1
  107. package/src/parse/parsers/api-design-systems-json/index.cjs +0 -55
  108. package/src/parse/parsers/api-design-systems-json/index.mjs +0 -49
  109. package/src/parse/parsers/api-design-systems-yaml/index.cjs +0 -54
  110. package/src/parse/parsers/api-design-systems-yaml/index.mjs +0 -48
  111. package/types/parse/parsers/api-design-systems-json/index.d.ts +0 -21
  112. package/types/parse/parsers/api-design-systems-yaml/index.d.ts +0 -20
@@ -4,16 +4,14 @@ var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequ
4
4
  var _interopRequireWildcard = require("@babel/runtime-corejs3/helpers/interopRequireWildcard").default;
5
5
  exports.__esModule = true;
6
6
  exports.default = void 0;
7
- var _apidomCore = require("@speclynx/apidom-core");
7
+ var _apidomDatamodel = require("@speclynx/apidom-datamodel");
8
+ var _apidomTraverse = require("@speclynx/apidom-traverse");
8
9
  var _apidomNsAsyncapi = _interopRequireWildcard(require("@speclynx/apidom-ns-asyncapi-2"));
9
10
  var _DereferenceStrategy = _interopRequireDefault(require("../DereferenceStrategy.cjs"));
10
11
  var _Reference = _interopRequireDefault(require("../../../Reference.cjs"));
11
12
  var _ReferenceSet = _interopRequireDefault(require("../../../ReferenceSet.cjs"));
12
13
  var _visitor = _interopRequireDefault(require("./visitor.cjs"));
13
14
  exports.AsyncAPI2DereferenceVisitor = _visitor.default;
14
- // @ts-ignore
15
- const visitAsync = _apidomCore.visit[Symbol.for('nodejs.util.promisify.custom')];
16
-
17
15
  /**
18
16
  * @public
19
17
  */
@@ -38,7 +36,7 @@ class AsyncAPI2DereferenceStrategy extends _DereferenceStrategy.default {
38
36
  return (0, _apidomNsAsyncapi.isAsyncApi2Element)(file.parseResult?.api);
39
37
  }
40
38
  async dereference(file, options) {
41
- const namespace = (0, _apidomCore.createNamespace)(_apidomNsAsyncapi.default);
39
+ const namespace = new _apidomDatamodel.Namespace().use(_apidomNsAsyncapi.default);
42
40
  const immutableRefSet = options.dereference.refSet ?? new _ReferenceSet.default();
43
41
  const mutableRefSet = new _ReferenceSet.default();
44
42
  let refSet = immutableRefSet;
@@ -61,7 +59,7 @@ class AsyncAPI2DereferenceStrategy extends _DereferenceStrategy.default {
61
59
  if (options.dereference.immutable) {
62
60
  immutableRefSet.refs.map(ref => new _Reference.default({
63
61
  ...ref,
64
- value: (0, _apidomCore.cloneDeep)(ref.value)
62
+ value: (0, _apidomDatamodel.cloneDeep)(ref.value)
65
63
  })).forEach(ref => mutableRefSet.add(ref));
66
64
  reference = mutableRefSet.find(ref => ref.uri === file.uri);
67
65
  refSet = mutableRefSet;
@@ -71,9 +69,8 @@ class AsyncAPI2DereferenceStrategy extends _DereferenceStrategy.default {
71
69
  namespace,
72
70
  options
73
71
  });
74
- const dereferencedElement = await visitAsync(refSet.rootRef.value, visitor, {
75
- keyMap: _apidomNsAsyncapi.keyMap,
76
- nodeTypeGetter: _apidomNsAsyncapi.getNodeType
72
+ const dereferencedElement = await (0, _apidomTraverse.traverseAsync)(refSet.rootRef.value, visitor, {
73
+ mutable: true
77
74
  });
78
75
 
79
76
  /**
@@ -1,16 +1,13 @@
1
- import { createNamespace, visit, cloneDeep } from '@speclynx/apidom-core';
2
- import asyncApi2Namespace, { getNodeType, isAsyncApi2Element, keyMap, mediaTypes } from '@speclynx/apidom-ns-asyncapi-2';
1
+ import { Namespace, cloneDeep } from '@speclynx/apidom-datamodel';
2
+ import { traverseAsync } from '@speclynx/apidom-traverse';
3
+ import asyncApi2Namespace, { isAsyncApi2Element, mediaTypes } from '@speclynx/apidom-ns-asyncapi-2';
3
4
  import DereferenceStrategy from "../DereferenceStrategy.mjs";
4
5
  import Reference from "../../../Reference.mjs";
5
6
  import ReferenceSet from "../../../ReferenceSet.mjs";
6
7
  import AsyncAPI2DereferenceVisitor from "./visitor.mjs";
7
- // @ts-ignore
8
- const visitAsync = visit[Symbol.for('nodejs.util.promisify.custom')];
9
-
10
8
  /**
11
9
  * @public
12
10
  */
13
-
14
11
  /**
15
12
  * @public
16
13
  */
@@ -31,7 +28,7 @@ class AsyncAPI2DereferenceStrategy extends DereferenceStrategy {
31
28
  return isAsyncApi2Element(file.parseResult?.api);
32
29
  }
33
30
  async dereference(file, options) {
34
- const namespace = createNamespace(asyncApi2Namespace);
31
+ const namespace = new Namespace().use(asyncApi2Namespace);
35
32
  const immutableRefSet = options.dereference.refSet ?? new ReferenceSet();
36
33
  const mutableRefSet = new ReferenceSet();
37
34
  let refSet = immutableRefSet;
@@ -64,9 +61,8 @@ class AsyncAPI2DereferenceStrategy extends DereferenceStrategy {
64
61
  namespace,
65
62
  options
66
63
  });
67
- const dereferencedElement = await visitAsync(refSet.rootRef.value, visitor, {
68
- keyMap,
69
- nodeTypeGetter: getNodeType
64
+ const dereferencedElement = await traverseAsync(refSet.rootRef.value, visitor, {
65
+ mutable: true
70
66
  });
71
67
 
72
68
  /**
@@ -3,10 +3,12 @@
3
3
  var _interopRequireWildcard = require("@babel/runtime-corejs3/helpers/interopRequireWildcard").default;
4
4
  var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
5
5
  exports.__esModule = true;
6
- exports.mutationReplacer = exports.default = void 0;
6
+ exports.default = void 0;
7
7
  var _ramda = require("ramda");
8
+ var _apidomDatamodel = require("@speclynx/apidom-datamodel");
8
9
  var _apidomCore = require("@speclynx/apidom-core");
9
10
  var _apidomError = require("@speclynx/apidom-error");
11
+ var _apidomTraverse = require("@speclynx/apidom-traverse");
10
12
  var _apidomJsonPointer = require("@speclynx/apidom-json-pointer");
11
13
  var _apidomNsAsyncapi = require("@speclynx/apidom-ns-asyncapi-2");
12
14
  var _MaximumDereferenceDepthError = _interopRequireDefault(require("../../../errors/MaximumDereferenceDepthError.cjs"));
@@ -15,28 +17,13 @@ var _util = require("../../util.cjs");
15
17
  var url = _interopRequireWildcard(require("../../../util/url.cjs"));
16
18
  var _index = _interopRequireDefault(require("../../../parse/index.cjs"));
17
19
  var _Reference = _interopRequireDefault(require("../../../Reference.cjs"));
18
- // @ts-ignore
19
- const visitAsync = _apidomCore.visit[Symbol.for('nodejs.util.promisify.custom')];
20
-
21
20
  // initialize element identity manager
22
21
  const identityManager = new _apidomCore.IdentityManager();
23
22
 
24
23
  /**
25
- * Custom mutation replacer.
26
24
  * @public
27
25
  */
28
- const mutationReplacer = (newElement, oldElement, key, parent) => {
29
- if ((0, _apidomCore.isMemberElement)(parent)) {
30
- parent.value = newElement;
31
- } else if (Array.isArray(parent)) {
32
- parent[key] = newElement;
33
- }
34
- };
35
26
 
36
- /**
37
- * @public
38
- */
39
- exports.mutationReplacer = mutationReplacer;
40
27
  /**
41
28
  * @public
42
29
  */
@@ -90,7 +77,7 @@ class AsyncAPI2DereferenceVisitor {
90
77
  // register new mutable reference with a refSet
91
78
  const mutableReference = new _Reference.default({
92
79
  uri: baseURI,
93
- value: (0, _apidomCore.cloneDeep)(parseResult),
80
+ value: (0, _apidomDatamodel.cloneDeep)(parseResult),
94
81
  depth: this.reference.depth + 1
95
82
  });
96
83
  refSet.add(mutableReference);
@@ -105,21 +92,25 @@ class AsyncAPI2DereferenceVisitor {
105
92
  }
106
93
  return mutableReference;
107
94
  }
108
- toAncestorLineage(ancestors) {
95
+ toAncestorLineage(path) {
109
96
  /**
110
97
  * Compute full ancestors lineage.
111
98
  * Ancestors are flatten to unwrap all Element instances.
112
99
  */
113
- const directAncestors = new Set(ancestors.filter(_apidomCore.isElement));
100
+ const ancestorNodes = path.getAncestorNodes();
101
+ const directAncestors = new Set(ancestorNodes.filter(_apidomDatamodel.isElement));
114
102
  const ancestorsLineage = new _util.AncestorLineage(...this.ancestors, directAncestors);
115
103
  return [ancestorsLineage, directAncestors];
116
104
  }
117
- async ReferenceElement(referencingElement, key, parent, path, ancestors, link) {
105
+ async ReferenceElement(path) {
106
+ const referencingElement = path.node;
107
+
118
108
  // skip current referencing element as it's already been access
119
109
  if (this.indirections.includes(referencingElement)) {
120
- return false;
110
+ path.skip();
111
+ return;
121
112
  }
122
- const [ancestorsLineage, directAncestors] = this.toAncestorLineage([...ancestors, parent]);
113
+ const [ancestorsLineage, directAncestors] = this.toAncestorLineage(path);
123
114
  const retrievalURI = this.toBaseURI((0, _apidomCore.toValue)(referencingElement.$ref));
124
115
  const isInternalReference = url.stripHash(this.reference.uri) === retrievalURI;
125
116
  const isExternalReference = !isInternalReference;
@@ -127,12 +118,14 @@ class AsyncAPI2DereferenceVisitor {
127
118
  // ignore resolving internal Reference Objects
128
119
  if (!this.options.resolve.internal && isInternalReference) {
129
120
  // skip traversing this reference and all it's child elements
130
- return false;
121
+ path.skip();
122
+ return;
131
123
  }
132
124
  // ignore resolving external Reference Objects
133
125
  if (!this.options.resolve.external && isExternalReference) {
134
126
  // skip traversing this reference and all it's child elements
135
- return false;
127
+ path.skip();
128
+ return;
136
129
  }
137
130
  const reference = await this.toReference((0, _apidomCore.toValue)(referencingElement.$ref));
138
131
  const $refBaseURI = url.resolve(retrievalURI, (0, _apidomCore.toValue)(referencingElement.$ref));
@@ -146,20 +139,21 @@ class AsyncAPI2DereferenceVisitor {
146
139
  /**
147
140
  * Applying semantics to a referenced element if semantics are missing.
148
141
  */
149
- if ((0, _apidomCore.isPrimitiveElement)(referencedElement)) {
142
+ if ((0, _apidomDatamodel.isPrimitiveElement)(referencedElement)) {
150
143
  const referencedElementType = (0, _apidomCore.toValue)(referencingElement.meta.get('referenced-element'));
151
144
  const cacheKey = `${referencedElementType}-${(0, _apidomCore.toValue)(identityManager.identify(referencedElement))}`;
152
145
  if (this.refractCache.has(cacheKey)) {
153
146
  referencedElement = this.refractCache.get(cacheKey);
154
147
  } else if ((0, _apidomNsAsyncapi.isReferenceLikeElement)(referencedElement)) {
155
148
  // handling indirect references
156
- referencedElement = _apidomNsAsyncapi.ReferenceElement.refract(referencedElement);
157
- referencedElement.setMetaProperty('referenced-element', referencedElementType);
149
+ referencedElement = (0, _apidomNsAsyncapi.refractReference)(referencedElement);
150
+ referencedElement.meta.set('referenced-element', referencedElementType);
158
151
  this.refractCache.set(cacheKey, referencedElement);
159
152
  } else {
160
153
  // handling direct references
161
- const ElementClass = this.namespace.getElementClass(referencedElementType);
162
- referencedElement = ElementClass.refract(referencedElement);
154
+ referencedElement = (0, _apidomNsAsyncapi.refract)(referencedElement, {
155
+ element: referencedElementType
156
+ });
163
157
  this.refractCache.set(cacheKey, referencedElement);
164
158
  }
165
159
  }
@@ -180,15 +174,16 @@ class AsyncAPI2DereferenceVisitor {
180
174
  if (this.options.dereference.circular === 'error') {
181
175
  throw new _apidomError.ApiDOMError('Circular reference detected');
182
176
  } else if (this.options.dereference.circular === 'replace') {
183
- const refElement = new _apidomCore.RefElement(referencedElement.id, {
177
+ const refElement = new _apidomDatamodel.RefElement(referencedElement.id, {
184
178
  type: 'reference',
185
179
  uri: reference.uri,
186
180
  $ref: (0, _apidomCore.toValue)(referencingElement.$ref)
187
181
  });
188
182
  const replacer = this.options.dereference.strategyOpts['asyncapi-2']?.circularReplacer ?? this.options.dereference.circularReplacer;
189
183
  const replacement = replacer(refElement);
190
- link.replaceWith(replacement, mutationReplacer);
191
- return !parent ? replacement : false;
184
+ this.indirections.pop();
185
+ path.replaceWith(replacement);
186
+ return;
192
187
  }
193
188
  }
194
189
 
@@ -214,9 +209,8 @@ class AsyncAPI2DereferenceVisitor {
214
209
  refractCache: this.refractCache,
215
210
  ancestors: ancestorsLineage
216
211
  });
217
- referencedElement = await visitAsync(referencedElement, visitor, {
218
- keyMap: _apidomNsAsyncapi.keyMap,
219
- nodeTypeGetter: _apidomNsAsyncapi.getNodeType
212
+ referencedElement = await (0, _apidomTraverse.traverseAsync)(referencedElement, visitor, {
213
+ mutable: true
220
214
  });
221
215
 
222
216
  // remove referencing reference from ancestors lineage
@@ -226,57 +220,55 @@ class AsyncAPI2DereferenceVisitor {
226
220
 
227
221
  // Boolean JSON Schemas
228
222
  if ((0, _apidomNsAsyncapi.isBooleanJsonSchemaElement)(referencedElement)) {
229
- const booleanJsonSchemaElement = (0, _apidomCore.cloneDeep)(referencedElement);
223
+ const booleanJsonSchemaElement = (0, _apidomDatamodel.cloneDeep)(referencedElement);
230
224
  // assign unique id to merged element
231
- booleanJsonSchemaElement.setMetaProperty('id', identityManager.generateId());
225
+ booleanJsonSchemaElement.meta.set('id', identityManager.generateId());
232
226
  // annotate referenced element with info about original referencing element
233
- booleanJsonSchemaElement.setMetaProperty('ref-fields', {
227
+ booleanJsonSchemaElement.meta.set('ref-fields', {
234
228
  $ref: (0, _apidomCore.toValue)(referencingElement.$ref)
235
229
  });
236
230
  // annotate referenced element with info about origin
237
- booleanJsonSchemaElement.setMetaProperty('ref-origin', reference.uri);
231
+ booleanJsonSchemaElement.meta.set('ref-origin', reference.uri);
238
232
  // annotate fragment with info about referencing element
239
- booleanJsonSchemaElement.setMetaProperty('ref-referencing-element-id', (0, _apidomCore.cloneDeep)(identityManager.identify(referencingElement)));
240
- link.replaceWith(booleanJsonSchemaElement, mutationReplacer);
241
- return !parent ? booleanJsonSchemaElement : false;
233
+ booleanJsonSchemaElement.meta.set('ref-referencing-element-id', (0, _apidomDatamodel.cloneDeep)(identityManager.identify(referencingElement)));
234
+ path.replaceWith(booleanJsonSchemaElement);
235
+ return;
242
236
  }
243
237
 
244
238
  /**
245
239
  * Creating a new version of referenced element to avoid modifying the original one.
246
240
  */
247
- const mergedElement = (0, _apidomCore.cloneShallow)(referencedElement);
241
+ const mergedElement = (0, _apidomDatamodel.cloneShallow)(referencedElement);
248
242
  // assign unique id to merged element
249
- mergedElement.setMetaProperty('id', identityManager.generateId());
243
+ mergedElement.meta.set('id', identityManager.generateId());
250
244
  // annotate referenced element with info about original referencing element
251
- mergedElement.setMetaProperty('ref-fields', {
245
+ mergedElement.meta.set('ref-fields', {
252
246
  $ref: (0, _apidomCore.toValue)(referencingElement.$ref)
253
247
  });
254
248
  // annotate fragment with info about origin
255
- mergedElement.setMetaProperty('ref-origin', reference.uri);
249
+ mergedElement.meta.set('ref-origin', reference.uri);
256
250
  // annotate fragment with info about referencing element
257
- mergedElement.setMetaProperty('ref-referencing-element-id', (0, _apidomCore.cloneDeep)(identityManager.identify(referencingElement)));
251
+ mergedElement.meta.set('ref-referencing-element-id', (0, _apidomDatamodel.cloneDeep)(identityManager.identify(referencingElement)));
258
252
 
259
253
  /**
260
254
  * Transclude referencing element with merged referenced element.
261
255
  */
262
- link.replaceWith(mergedElement, mutationReplacer);
263
-
264
- /**
265
- * We're at the root of the tree, so we're just replacing the entire tree.
266
- */
267
- return !parent ? mergedElement : false;
256
+ path.replaceWith(mergedElement);
268
257
  }
269
- async ChannelItemElement(referencingElement, key, parent, path, ancestors, link) {
258
+ async ChannelItemElement(path) {
259
+ const referencingElement = path.node;
260
+
270
261
  // ignore ChannelItemElement without $ref field
271
- if (!(0, _apidomCore.isStringElement)(referencingElement.$ref)) {
272
- return undefined;
262
+ if (!(0, _apidomDatamodel.isStringElement)(referencingElement.$ref)) {
263
+ return;
273
264
  }
274
265
 
275
266
  // skip current referencing element as it's already been access
276
267
  if (this.indirections.includes(referencingElement)) {
277
- return false;
268
+ path.skip();
269
+ return;
278
270
  }
279
- const [ancestorsLineage, directAncestors] = this.toAncestorLineage([...ancestors, parent]);
271
+ const [ancestorsLineage, directAncestors] = this.toAncestorLineage(path);
280
272
  const retrievalURI = this.toBaseURI((0, _apidomCore.toValue)(referencingElement.$ref));
281
273
  const isInternalReference = url.stripHash(this.reference.uri) === retrievalURI;
282
274
  const isExternalReference = !isInternalReference;
@@ -284,12 +276,12 @@ class AsyncAPI2DereferenceVisitor {
284
276
  // ignore resolving internal Channel Item Objects
285
277
  if (!this.options.resolve.internal && isInternalReference) {
286
278
  // skip traversing this channel item but traverse all it's child elements
287
- return undefined;
279
+ return;
288
280
  }
289
281
  // ignore resolving external Channel Item Objects
290
282
  if (!this.options.resolve.external && isExternalReference) {
291
283
  // skip traversing this channel item but traverse all it's child elements
292
- return undefined;
284
+ return;
293
285
  }
294
286
  const reference = await this.toReference((0, _apidomCore.toValue)(referencingElement.$ref));
295
287
  const $refBaseURI = url.resolve(retrievalURI, (0, _apidomCore.toValue)(referencingElement.$ref));
@@ -303,12 +295,12 @@ class AsyncAPI2DereferenceVisitor {
303
295
  /**
304
296
  * Applying semantics to a referenced element if semantics are missing.
305
297
  */
306
- if ((0, _apidomCore.isPrimitiveElement)(referencedElement)) {
298
+ if ((0, _apidomDatamodel.isPrimitiveElement)(referencedElement)) {
307
299
  const cacheKey = `channel-item-${(0, _apidomCore.toValue)(identityManager.identify(referencedElement))}`;
308
300
  if (this.refractCache.has(cacheKey)) {
309
301
  referencedElement = this.refractCache.get(cacheKey);
310
302
  } else {
311
- referencedElement = _apidomNsAsyncapi.ChannelItemElement.refract(referencedElement);
303
+ referencedElement = (0, _apidomNsAsyncapi.refractChannelItem)(referencedElement);
312
304
  this.refractCache.set(cacheKey, referencedElement);
313
305
  }
314
306
  }
@@ -329,15 +321,16 @@ class AsyncAPI2DereferenceVisitor {
329
321
  if (this.options.dereference.circular === 'error') {
330
322
  throw new _apidomError.ApiDOMError('Circular reference detected');
331
323
  } else if (this.options.dereference.circular === 'replace') {
332
- const refElement = new _apidomCore.RefElement(referencedElement.id, {
324
+ const refElement = new _apidomDatamodel.RefElement(referencedElement.id, {
333
325
  type: 'channel-item',
334
326
  uri: reference.uri,
335
327
  $ref: (0, _apidomCore.toValue)(referencingElement.$ref)
336
328
  });
337
329
  const replacer = this.options.dereference.strategyOpts['asyncapi-2']?.circularReplacer ?? this.options.dereference.circularReplacer;
338
330
  const replacement = replacer(refElement);
339
- link.replaceWith(replacement, mutationReplacer);
340
- return !parent ? replacement : undefined;
331
+ this.indirections.pop();
332
+ path.replaceWith(replacement);
333
+ return;
341
334
  }
342
335
  }
343
336
 
@@ -352,7 +345,7 @@ class AsyncAPI2DereferenceVisitor {
352
345
  */
353
346
  const isNonRootDocument = url.stripHash(reference.refSet.rootRef.uri) !== reference.uri;
354
347
  const shouldDetectCircular = ['error', 'replace'].includes(this.options.dereference.circular);
355
- if ((isExternalReference || isNonRootDocument || (0, _apidomNsAsyncapi.isChannelItemElement)(referencedElement) && (0, _apidomCore.isStringElement)(referencedElement.$ref) || shouldDetectCircular) && !ancestorsLineage.includesCycle(referencedElement)) {
348
+ if ((isExternalReference || isNonRootDocument || (0, _apidomNsAsyncapi.isChannelItemElement)(referencedElement) && (0, _apidomDatamodel.isStringElement)(referencedElement.$ref) || shouldDetectCircular) && !ancestorsLineage.includesCycle(referencedElement)) {
356
349
  // append referencing reference to ancestors lineage
357
350
  directAncestors.add(referencingElement);
358
351
  const visitor = new AsyncAPI2DereferenceVisitor({
@@ -363,9 +356,8 @@ class AsyncAPI2DereferenceVisitor {
363
356
  refractCache: this.refractCache,
364
357
  ancestors: ancestorsLineage
365
358
  });
366
- referencedElement = await visitAsync(referencedElement, visitor, {
367
- keyMap: _apidomNsAsyncapi.keyMap,
368
- nodeTypeGetter: _apidomNsAsyncapi.getNodeType
359
+ referencedElement = await (0, _apidomTraverse.traverseAsync)(referencedElement, visitor, {
360
+ mutable: true
369
361
  });
370
362
 
371
363
  // remove referencing reference from ancestors lineage
@@ -377,9 +369,9 @@ class AsyncAPI2DereferenceVisitor {
377
369
  * Creating a new version of Channel Item by merging fields from referenced Channel Item with referencing one.
378
370
  */
379
371
  if ((0, _apidomNsAsyncapi.isChannelItemElement)(referencedElement)) {
380
- const mergedElement = new _apidomNsAsyncapi.ChannelItemElement([...referencedElement.content], (0, _apidomCore.cloneDeep)(referencedElement.meta), (0, _apidomCore.cloneDeep)(referencedElement.attributes));
372
+ const mergedElement = (0, _apidomDatamodel.cloneShallow)(referencedElement);
381
373
  // assign unique id to merged element
382
- mergedElement.setMetaProperty('id', identityManager.generateId());
374
+ mergedElement.meta.set('id', identityManager.generateId());
383
375
  // existing keywords from referencing ChannelItemElement overrides ones from referenced ChannelItemElement
384
376
  referencingElement.forEach((value, keyElement, item) => {
385
377
  mergedElement.remove((0, _apidomCore.toValue)(keyElement));
@@ -388,25 +380,20 @@ class AsyncAPI2DereferenceVisitor {
388
380
  mergedElement.remove('$ref');
389
381
 
390
382
  // annotate referenced element with info about original referencing element
391
- mergedElement.setMetaProperty('ref-fields', {
383
+ mergedElement.meta.set('ref-fields', {
392
384
  $ref: (0, _apidomCore.toValue)(referencingElement.$ref)
393
385
  });
394
386
  // annotate referenced with info about origin
395
- mergedElement.setMetaProperty('ref-origin', reference.uri);
387
+ mergedElement.meta.set('ref-origin', reference.uri);
396
388
  // annotate fragment with info about referencing element
397
- mergedElement.setMetaProperty('ref-referencing-element-id', (0, _apidomCore.cloneDeep)(identityManager.identify(referencingElement)));
389
+ mergedElement.meta.set('ref-referencing-element-id', (0, _apidomDatamodel.cloneDeep)(identityManager.identify(referencingElement)));
398
390
  referencedElement = mergedElement;
399
391
  }
400
392
 
401
393
  /**
402
394
  * Transclude referencing element with merged referenced element.
403
395
  */
404
- link.replaceWith(referencedElement, mutationReplacer);
405
-
406
- /**
407
- * We're at the root of the tree, so we're just replacing the entire tree.
408
- */
409
- return !parent ? referencedElement : undefined;
396
+ path.replaceWith(referencedElement);
410
397
  }
411
398
  }
412
399
  var _default = exports.default = AsyncAPI2DereferenceVisitor;