@speclynx/apidom-reference 4.14.0 → 4.16.0

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.
@@ -0,0 +1,409 @@
1
+ import { none } from 'ramda';
2
+ import { isElement, isObjectElement, isStringElement, AnnotationElement, cloneDeep } from '@speclynx/apidom-datamodel';
3
+ import { toValue, toYAML, fixedFields } from '@speclynx/apidom-core';
4
+ import { traverseAsync } from '@speclynx/apidom-traverse';
5
+ import { evaluate as jsonPointerEvaluate, escape, URIFragmentIdentifier } from '@speclynx/apidom-json-pointer';
6
+ import { ComponentsElement, ComponentsInputsElement } from '@speclynx/apidom-ns-arazzo-1';
7
+ import BundleError from "../../../errors/BundleError.mjs";
8
+ import UnresolvableReferenceError from "../../../errors/UnresolvableReferenceError.mjs";
9
+ import MaximumBundleDepthError from "../../../errors/MaximumBundleDepthError.mjs";
10
+ import MaximumResolveDepthError from "../../../errors/MaximumResolveDepthError.mjs";
11
+ import EvaluationJsonSchemaUriError from "../../../errors/EvaluationJsonSchemaUriError.mjs";
12
+ import * as url from "../../../util/url.mjs";
13
+ import parse from "../../../parse/index.mjs";
14
+ import Reference from "../../../Reference.mjs";
15
+ import File from "../../../File.mjs";
16
+ import { isAnchor, uriToAnchor, evaluate as $anchorEvaluate } from "../../../dereference/strategies/arazzo-1/selectors/$anchor.mjs";
17
+ import { evaluate as uriEvaluate } from "../../../dereference/strategies/arazzo-1/selectors/uri.mjs";
18
+ import { resolveSchema$refField, resolveSchema$idField, maybeRefractToJSONSchemaElement } from "../../../dereference/strategies/arazzo-1/util.mjs";
19
+ import { toPascalCase, sanitizeComponentName, uniqueName as resolveUniqueName } from "../../util.mjs";
20
+ /**
21
+ * The Components Object field where embedded JSON Schema resources are hoisted.
22
+ * Sourced from the Components Object fixed fields so it cannot drift from the
23
+ * namespace definition.
24
+ */
25
+ const cf = fixedFields(ComponentsElement, {
26
+ indexed: true
27
+ });
28
+
29
+ /**
30
+ * @public
31
+ */
32
+
33
+ /**
34
+ * @public
35
+ */
36
+ class Arazzo1BundleVisitor {
37
+ reference;
38
+ options;
39
+
40
+ /**
41
+ * The entry parse result. Derived from the shared refSet's root reference.
42
+ */
43
+ get entryParseResult() {
44
+ return this.reference.refSet.rootRef.value;
45
+ }
46
+
47
+ /**
48
+ * The entry document element. Embedded external schema resources are placed
49
+ * into its `components.inputs` object. The `canBundle` guard guarantees it is
50
+ * an ArazzoSpecification1Element.
51
+ */
52
+ get entryResult() {
53
+ return this.entryParseResult.result;
54
+ }
55
+
56
+ /**
57
+ * Shared across the entry document and every external document visitor.
58
+ * Guarantees each external resource is embedded exactly once, keyed by its
59
+ * resource URI.
60
+ */
61
+ assignments;
62
+
63
+ /**
64
+ * Component names already reserved per Components Object field. Reserved
65
+ * before recursion so collision suffixing (`Pet`, `Pet-2`, ...) accounts for
66
+ * components that are still being bundled.
67
+ */
68
+ reservedNames;
69
+ constructor({
70
+ reference,
71
+ options,
72
+ assignments = new Map(),
73
+ reservedNames = new Map()
74
+ }) {
75
+ this.reference = reference;
76
+ this.options = options;
77
+ this.assignments = assignments;
78
+ this.reservedNames = reservedNames;
79
+ }
80
+ toBaseURI(uri) {
81
+ return url.resolve(this.reference.uri, url.sanitize(url.stripHash(uri)));
82
+ }
83
+ async toReference(uri) {
84
+ // detect maximum depth of resolution
85
+ if (this.reference.depth >= this.options.resolve.maxDepth) {
86
+ throw new MaximumResolveDepthError(`Maximum resolution depth of ${this.options.resolve.maxDepth} has been exceeded by file "${this.reference.uri}"`, {
87
+ maxDepth: this.options.resolve.maxDepth,
88
+ uri: this.reference.uri
89
+ });
90
+ }
91
+ const baseURI = this.toBaseURI(uri);
92
+ const {
93
+ refSet
94
+ } = this.reference;
95
+
96
+ // we've already processed this Reference in past
97
+ if (refSet.has(baseURI)) {
98
+ return refSet.find(ref => ref.uri === baseURI);
99
+ }
100
+ const parseResult = await parse(url.unsanitize(baseURI), {
101
+ ...this.options,
102
+ parse: {
103
+ ...this.options.parse,
104
+ mediaType: 'text/plain'
105
+ }
106
+ });
107
+ const reference = new Reference({
108
+ uri: baseURI,
109
+ value: parseResult,
110
+ depth: this.reference.depth + 1
111
+ });
112
+ refSet.add(reference);
113
+ return reference;
114
+ }
115
+
116
+ /**
117
+ * Handles an error according to the `bundle.continueOnError` option.
118
+ *
119
+ * For new errors: wraps in UnresolvableReferenceError with structured
120
+ * context. For errors already wrapped by a nested visitor: prepends the
121
+ * current hop to the trace.
122
+ *
123
+ * Inner/intermediate visitors always throw to let the trace accumulate. Only
124
+ * the entry document visitor respects continueOnError (callback/swallow/throw).
125
+ */
126
+ handleError(message, error, referencingElement, refFieldName, refFieldValue, visitorPath) {
127
+ // a collision reported as `error` is a deliberate hard stop with no
128
+ // resolution-failure analog, so pass it through unchanged. A maxDepth
129
+ // breach (MaximumBundleDepthError, which also extends BundleError) is a
130
+ // resolution failure and flows through below — wrapped and subject to
131
+ // continueOnError, like dereferencing.
132
+ if (error instanceof BundleError && !(error instanceof MaximumBundleDepthError)) {
133
+ throw error;
134
+ }
135
+ const {
136
+ continueOnError
137
+ } = this.options.bundle;
138
+ const isEntryDocument = url.stripHash(this.reference.refSet?.rootRef?.uri ?? '') === this.reference.uri;
139
+ const uri = this.reference.uri;
140
+ const type = referencingElement.element;
141
+ const codeFrame = toYAML(referencingElement);
142
+ const location = visitorPath.formatPath();
143
+ const hop = {
144
+ uri,
145
+ type,
146
+ refFieldName,
147
+ refFieldValue,
148
+ location,
149
+ codeFrame
150
+ };
151
+ let unresolvedError;
152
+ if (error instanceof UnresolvableReferenceError) {
153
+ // @ts-ignore
154
+ error.trace = [hop, ...error.trace];
155
+ unresolvedError = error;
156
+ } else {
157
+ unresolvedError = new UnresolvableReferenceError(message, {
158
+ cause: error,
159
+ type,
160
+ uri,
161
+ location,
162
+ codeFrame,
163
+ refFieldName,
164
+ refFieldValue,
165
+ trace: []
166
+ });
167
+ }
168
+ if (!isEntryDocument || continueOnError === false) throw unresolvedError;
169
+ if (typeof continueOnError === 'function') continueOnError(unresolvedError);
170
+ }
171
+
172
+ /**
173
+ * Lazily creates the Components Object (and the `inputs` field within it) on
174
+ * the entry document, returning the field where a resource is embedded.
175
+ */
176
+ ensureInputsField() {
177
+ const entryResult = this.entryResult;
178
+ let components = entryResult.components;
179
+ if (!isObjectElement(components)) {
180
+ components = new ComponentsElement();
181
+ entryResult.components = components;
182
+ }
183
+ let inputs = components.get(cf.inputs.name);
184
+ if (!isObjectElement(inputs)) {
185
+ inputs = new ComponentsInputsElement();
186
+ components.set(cf.inputs.name, inputs);
187
+ }
188
+ return inputs;
189
+ }
190
+
191
+ /**
192
+ * Computes the base component name (before collision suffixing) according to
193
+ * the configured naming strategy.
194
+ */
195
+ baseName(element, baseURI) {
196
+ // strategy specific options take precedence over the top-level bundle options
197
+ const componentNamesStrategy = this.options.bundle.strategyOpts['arazzo-1']?.componentNamesStrategy ?? this.options.bundle.componentNamesStrategy;
198
+ const fallback = url.getBasename(baseURI) || 'Schema';
199
+ if (typeof componentNamesStrategy === 'function') {
200
+ const resolved = componentNamesStrategy({
201
+ element,
202
+ field: cf.inputs.name,
203
+ jsonPointer: '',
204
+ baseURI
205
+ });
206
+ if (typeof resolved === 'string' && resolved !== '') {
207
+ return resolved;
208
+ }
209
+ return fallback;
210
+ }
211
+ if (componentNamesStrategy === 'title') {
212
+ const title = isObjectElement(element) ? toValue(element.get('title')) : undefined;
213
+ if (typeof title === 'string' && title.trim() !== '') {
214
+ const name = sanitizeComponentName(toPascalCase(title));
215
+ if (name !== '') return name;
216
+ }
217
+ // fall back to basename when no usable title is present
218
+ }
219
+ return fallback;
220
+ }
221
+
222
+ /**
223
+ * Computes a collision-free component name within `components.inputs`. A name
224
+ * is taken if it's already placed in inputs or reserved by a component that is
225
+ * still being bundled (reserved before recursion).
226
+ */
227
+ uniqueName(candidate) {
228
+ const field = cf.inputs.name;
229
+ const inputs = this.ensureInputsField();
230
+ const reserved = this.reservedNames.get(field) ?? new Set();
231
+ return resolveUniqueName(candidate, name => inputs.hasKey(name) || reserved.has(name));
232
+ }
233
+
234
+ /**
235
+ * Reports a collision-forced rename according to the configured severity.
236
+ * A rename means two distinct targets resolved to the same name; each keeps
237
+ * its own component (and origin), so report the rename per severity.
238
+ */
239
+ reportNameCollision(preferredName, componentName) {
240
+ // strategy specific options take precedence over the top-level bundle options
241
+ const onComponentNameCollision = this.options.bundle.strategyOpts['arazzo-1']?.onComponentNameCollision ?? this.options.bundle.onComponentNameCollision;
242
+ if (componentName === preferredName || onComponentNameCollision === 'off') {
243
+ return;
244
+ }
245
+ const message = `Component "${preferredName}" in components/${cf.inputs.name} is referenced with the same name but different content. Renamed to "${componentName}".`;
246
+ if (onComponentNameCollision === 'error') {
247
+ throw new BundleError(message);
248
+ }
249
+ const annotation = new AnnotationElement(message);
250
+ annotation.classes.push('warning');
251
+ annotation.code = 'bundle-component-name-collision';
252
+ // append (never prepend) so the result element stays ahead of annotations
253
+ this.entryParseResult.content.push(annotation);
254
+ }
255
+
256
+ /**
257
+ * JSON Schema Objects in Arazzo (used by Input Objects and inline schemas) are
258
+ * a JSON Schema 2020-12 dialect — the only external reference type Arazzo
259
+ * defines. They are bundled per the JSON Schema Compound Document rules: the
260
+ * external schema RESOURCE is embedded verbatim into `components.inputs`
261
+ * (carrying its `$id`), and the referencing `$ref` is left UNCHANGED — it
262
+ * keeps resolving against the embedded resource's `$id`. This mirrors the
263
+ * openapi-3-1 strategy's Schema Object handling.
264
+ */
265
+ async JSONSchemaElement(path) {
266
+ const referencingElement = path.node;
267
+
268
+ // skip current referencing schema as $ref keyword was not defined
269
+ if (!isStringElement(referencingElement.$ref)) {
270
+ return;
271
+ }
272
+ const $ref = toValue(referencingElement.$ref);
273
+ try {
274
+ // compute baseURI using rules around $id and $ref keywords. The current
275
+ // document's URI is the retrieval URI — derive it directly (not via
276
+ // toReference) so an internal $ref needs no resolution and never trips the
277
+ // resolve.maxDepth guard.
278
+ const retrievalURI = this.reference.uri;
279
+ const $refBaseURI = resolveSchema$refField(retrievalURI, referencingElement);
280
+ const $refBaseURIStrippedHash = url.stripHash($refBaseURI);
281
+ const file = new File({
282
+ uri: $refBaseURIStrippedHash
283
+ });
284
+ const isUnknownURI = none(r => r.canRead(file), this.options.resolve.resolvers);
285
+ const isURL = !isUnknownURI;
286
+ const isInternalReference = url.stripHash(this.reference.uri) === $refBaseURIStrippedHash;
287
+ const isExternalReference = !isInternalReference;
288
+
289
+ // internal Schema Object $refs resolve against the in-document $id graph;
290
+ // leaving them untouched keeps that resolution valid. A JSON Schema $ref is
291
+ // never normalized to a bare fragment.
292
+ if (isInternalReference) {
293
+ return;
294
+ }
295
+
296
+ // honor the resolve.external switch
297
+ if (!this.options.resolve.external && isExternalReference) {
298
+ return;
299
+ }
300
+
301
+ // detect maximum depth of bundling before fetching the external resource
302
+ if (this.reference.depth >= this.options.bundle.maxDepth) {
303
+ throw new MaximumBundleDepthError(`Maximum bundle depth of "${this.options.bundle.maxDepth}" has been exceeded in file "${this.reference.uri}"`, {
304
+ maxDepth: this.options.bundle.maxDepth,
305
+ uri: this.reference.uri
306
+ });
307
+ }
308
+
309
+ // locate the external schema resource the $ref targets, reusing the
310
+ // dereference strategy's classification. First try to resolve the target
311
+ // as a canonical URI / URL against the current document's $id graph; if
312
+ // that fails, fall back to fetching the external document and resolving
313
+ // the fragment there as a $anchor or JSON Pointer.
314
+ let schemaReference = this.reference;
315
+ try {
316
+ const referenceAsSchema = maybeRefractToJSONSchemaElement(schemaReference.value.result);
317
+ uriEvaluate($refBaseURI, referenceAsSchema);
318
+ } catch (error) {
319
+ if (isURL && error instanceof EvaluationJsonSchemaUriError) {
320
+ if (isAnchor(uriToAnchor($refBaseURI))) {
321
+ schemaReference = await this.toReference(url.unsanitize($refBaseURI));
322
+ const selector = uriToAnchor($refBaseURI);
323
+ const referenceAsSchema = maybeRefractToJSONSchemaElement(schemaReference.value.result);
324
+ $anchorEvaluate(selector, referenceAsSchema);
325
+ } else {
326
+ schemaReference = await this.toReference(url.unsanitize($refBaseURI));
327
+ const selector = URIFragmentIdentifier.fromURIReference($refBaseURI);
328
+ const referenceAsSchema = maybeRefractToJSONSchemaElement(schemaReference.value.result);
329
+ jsonPointerEvaluate(referenceAsSchema, selector);
330
+ }
331
+ } else {
332
+ throw error;
333
+ }
334
+ }
335
+
336
+ // a $ref that resolves (by $id/$anchor/pointer) within the current document
337
+ // is internal even when its URI form (e.g. a URN or absolute $id) is not a
338
+ // bare fragment. Leave it untouched — it resolves against the in-document
339
+ // $id graph, and embedding the current document into itself would be wrong.
340
+ if (url.stripHash(schemaReference.uri) === url.stripHash(this.reference.uri)) {
341
+ return;
342
+ }
343
+
344
+ // the resource to embed is the WHOLE external document (its root schema),
345
+ // identified by its $id. A $ref into a fragment of the document embeds the
346
+ // entire document resource once; the fragment keeps resolving against the
347
+ // embedded $id.
348
+ const resourceRoot = maybeRefractToJSONSchemaElement(schemaReference.value.result);
349
+ const resourceBaseURI = resolveSchema$idField(url.stripHash(schemaReference.uri), resourceRoot) ?? url.stripHash(schemaReference.uri);
350
+ const field = cf.inputs.name;
351
+ const canonicalKey = `${field}\t${resourceBaseURI}`;
352
+
353
+ // resource already embedded (or being embedded) — leave the referencing
354
+ // $ref untouched and stop. This also terminates circular external schema
355
+ // references, since the assignment is reserved BEFORE recursion.
356
+ if (this.assignments.has(canonicalKey)) {
357
+ path.skip();
358
+ return;
359
+ }
360
+
361
+ // own a copy of the resource and ensure it carries a $id so the unchanged
362
+ // $ref still resolves against it once embedded
363
+ const embeddedElement = cloneDeep(resourceRoot);
364
+ if (!isStringElement(embeddedElement.$id)) {
365
+ embeddedElement.set('$id', resourceBaseURI);
366
+ }
367
+
368
+ // the embedded thing is the WHOLE resource (keyed by its $id), so its name
369
+ // is derived from the resource URI
370
+ const preferredName = this.baseName(embeddedElement, resourceBaseURI);
371
+ const componentName = this.uniqueName(preferredName);
372
+ this.reportNameCollision(preferredName, componentName);
373
+
374
+ // reserve the assignment and component name before recursing so circular
375
+ // external schema references terminate
376
+ this.assignments.set(canonicalKey, `#/components/${field}/${escape(componentName)}`);
377
+ if (!this.reservedNames.has(field)) this.reservedNames.set(field, new Set());
378
+ this.reservedNames.get(field).add(componentName);
379
+
380
+ // bundle external references contained within the embedded resource;
381
+ // nested external resources land flat in the same components.inputs
382
+ const visitor = new Arazzo1BundleVisitor({
383
+ reference: schemaReference,
384
+ options: this.options,
385
+ assignments: this.assignments,
386
+ reservedNames: this.reservedNames
387
+ });
388
+ const bundledElement = await traverseAsync(embeddedElement, visitor, {
389
+ mutable: true
390
+ });
391
+
392
+ // annotate the embedded resource with info about its origin
393
+ if (isElement(bundledElement)) {
394
+ bundledElement.meta.set('ref-origin', schemaReference.uri);
395
+ }
396
+
397
+ // place the embedded resource into the entry document's components.inputs
398
+ this.ensureInputsField().set(componentName, bundledElement);
399
+
400
+ // the referencing $ref is left UNCHANGED — it resolves against the
401
+ // embedded resource's $id
402
+ path.skip();
403
+ } catch (error) {
404
+ this.handleError(`Error while bundling JSON Schema Object. Cannot resolve $ref "${$ref}": ${error.message}`, error, referencingElement, '$ref', $ref, path);
405
+ path.skip();
406
+ }
407
+ }
408
+ }
409
+ export default Arazzo1BundleVisitor;
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ Object.defineProperty(exports, "AsyncAPI2BundleVisitor", {
8
+ enumerable: true,
9
+ get: function () {
10
+ return _visitor.default;
11
+ }
12
+ });
13
+ exports.default = void 0;
14
+ var _apidomDatamodel = require("@speclynx/apidom-datamodel");
15
+ var _apidomTraverse = require("@speclynx/apidom-traverse");
16
+ var _apidomNsAsyncapi = require("@speclynx/apidom-ns-asyncapi-2");
17
+ var _Reference = _interopRequireDefault(require("../../../Reference.cjs"));
18
+ var _ReferenceSet = _interopRequireDefault(require("../../../ReferenceSet.cjs"));
19
+ var _BundleStrategy = _interopRequireDefault(require("../BundleStrategy.cjs"));
20
+ var _visitor = _interopRequireDefault(require("./visitor.cjs"));
21
+ /**
22
+ * @public
23
+ */
24
+
25
+ /**
26
+ * @public
27
+ */
28
+ class AsyncAPI2BundleStrategy extends _BundleStrategy.default {
29
+ constructor(options) {
30
+ super({
31
+ ...(options ?? {}),
32
+ name: 'asyncapi-2'
33
+ });
34
+ }
35
+ canBundle(file) {
36
+ // assert by media type
37
+ if (file.mediaType !== 'text/plain') {
38
+ return _apidomNsAsyncapi.mediaTypes.includes(file.mediaType);
39
+ }
40
+
41
+ // assert by inspecting ApiDOM
42
+ return (0, _apidomNsAsyncapi.isAsyncApi2Element)(file.parseResult?.result);
43
+ }
44
+ async bundle(file, options) {
45
+ const immutableRefSet = options.bundle.refSet ?? new _ReferenceSet.default();
46
+ const mutableRefSet = new _ReferenceSet.default();
47
+ let refSet = immutableRefSet;
48
+ let reference;
49
+
50
+ // determine the initial reference
51
+ if (!immutableRefSet.has(file.uri)) {
52
+ reference = new _Reference.default({
53
+ uri: file.uri,
54
+ value: file.parseResult
55
+ });
56
+ immutableRefSet.add(reference);
57
+ } else {
58
+ // pre-computed refSet was provided as configuration option
59
+ reference = immutableRefSet.find(ref => ref.uri === file.uri);
60
+ }
61
+
62
+ /**
63
+ * Clone refSet due the bundling process being mutable.
64
+ * We don't want to mutate the original refSet and the references.
65
+ */
66
+ if (options.bundle.immutable) {
67
+ immutableRefSet.refs.map(ref => new _Reference.default({
68
+ ...ref,
69
+ value: (0, _apidomDatamodel.cloneDeep)(ref.value)
70
+ })).forEach(ref => mutableRefSet.add(ref));
71
+ reference = mutableRefSet.find(ref => ref.uri === file.uri);
72
+ refSet = mutableRefSet;
73
+ }
74
+ const visitor = new _visitor.default({
75
+ reference: reference,
76
+ options
77
+ });
78
+ await (0, _apidomTraverse.traverseAsync)(refSet.rootRef.value, visitor, {
79
+ mutable: true
80
+ });
81
+ const parseResult = reference.value;
82
+
83
+ /**
84
+ * Release all memory if this refSet was not provided as a configuration option.
85
+ * If provided as configuration option, then provider is responsible for cleanup.
86
+ */
87
+ if (options.bundle.refSet === null) {
88
+ immutableRefSet.clean();
89
+ }
90
+ mutableRefSet.clean();
91
+ return parseResult;
92
+ }
93
+ }
94
+ var _default = exports.default = AsyncAPI2BundleStrategy;
@@ -0,0 +1,81 @@
1
+ import { cloneDeep } from '@speclynx/apidom-datamodel';
2
+ import { traverseAsync } from '@speclynx/apidom-traverse';
3
+ import { mediaTypes, isAsyncApi2Element } from '@speclynx/apidom-ns-asyncapi-2';
4
+ import Reference from "../../../Reference.mjs";
5
+ import ReferenceSet from "../../../ReferenceSet.mjs";
6
+ import BundleStrategy from "../BundleStrategy.mjs";
7
+ import AsyncAPI2BundleVisitor from "./visitor.mjs";
8
+ /**
9
+ * @public
10
+ */
11
+ /**
12
+ * @public
13
+ */
14
+ class AsyncAPI2BundleStrategy extends BundleStrategy {
15
+ constructor(options) {
16
+ super({
17
+ ...(options ?? {}),
18
+ name: 'asyncapi-2'
19
+ });
20
+ }
21
+ canBundle(file) {
22
+ // assert by media type
23
+ if (file.mediaType !== 'text/plain') {
24
+ return mediaTypes.includes(file.mediaType);
25
+ }
26
+
27
+ // assert by inspecting ApiDOM
28
+ return isAsyncApi2Element(file.parseResult?.result);
29
+ }
30
+ async bundle(file, options) {
31
+ const immutableRefSet = options.bundle.refSet ?? new ReferenceSet();
32
+ const mutableRefSet = new ReferenceSet();
33
+ let refSet = immutableRefSet;
34
+ let reference;
35
+
36
+ // determine the initial reference
37
+ if (!immutableRefSet.has(file.uri)) {
38
+ reference = new Reference({
39
+ uri: file.uri,
40
+ value: file.parseResult
41
+ });
42
+ immutableRefSet.add(reference);
43
+ } else {
44
+ // pre-computed refSet was provided as configuration option
45
+ reference = immutableRefSet.find(ref => ref.uri === file.uri);
46
+ }
47
+
48
+ /**
49
+ * Clone refSet due the bundling process being mutable.
50
+ * We don't want to mutate the original refSet and the references.
51
+ */
52
+ if (options.bundle.immutable) {
53
+ immutableRefSet.refs.map(ref => new Reference({
54
+ ...ref,
55
+ value: cloneDeep(ref.value)
56
+ })).forEach(ref => mutableRefSet.add(ref));
57
+ reference = mutableRefSet.find(ref => ref.uri === file.uri);
58
+ refSet = mutableRefSet;
59
+ }
60
+ const visitor = new AsyncAPI2BundleVisitor({
61
+ reference: reference,
62
+ options
63
+ });
64
+ await traverseAsync(refSet.rootRef.value, visitor, {
65
+ mutable: true
66
+ });
67
+ const parseResult = reference.value;
68
+
69
+ /**
70
+ * Release all memory if this refSet was not provided as a configuration option.
71
+ * If provided as configuration option, then provider is responsible for cleanup.
72
+ */
73
+ if (options.bundle.refSet === null) {
74
+ immutableRefSet.clean();
75
+ }
76
+ mutableRefSet.clean();
77
+ return parseResult;
78
+ }
79
+ }
80
+ export { AsyncAPI2BundleVisitor };
81
+ export default AsyncAPI2BundleStrategy;