@speclynx/apidom-reference 6.2.0 → 7.0.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.
Files changed (91) hide show
  1. package/CHANGELOG.md +49 -0
  2. package/README.md +45 -0
  3. package/dist/apidom-reference.browser.js +4701 -3478
  4. package/dist/apidom-reference.browser.min.js +1 -1
  5. package/package.json +29 -28
  6. package/src/File.cjs +5 -2
  7. package/src/File.mjs +5 -2
  8. package/src/bundle/strategies/arazzo-1/index.cjs +3 -2
  9. package/src/bundle/strategies/arazzo-1/index.mjs +3 -2
  10. package/src/bundle/strategies/asyncapi-2/index.cjs +3 -2
  11. package/src/bundle/strategies/asyncapi-2/index.mjs +3 -2
  12. package/src/bundle/strategies/openapi-2/index.cjs +3 -2
  13. package/src/bundle/strategies/openapi-2/index.mjs +3 -2
  14. package/src/bundle/strategies/openapi-3-0/index.cjs +3 -2
  15. package/src/bundle/strategies/openapi-3-0/index.mjs +3 -2
  16. package/src/bundle/strategies/openapi-3-1/index.cjs +3 -2
  17. package/src/bundle/strategies/openapi-3-1/index.mjs +3 -2
  18. package/src/dereference/strategies/DereferenceVisitor.cjs +588 -0
  19. package/src/dereference/strategies/DereferenceVisitor.mjs +580 -0
  20. package/src/dereference/strategies/arazzo-1/index.cjs +14 -39
  21. package/src/dereference/strategies/arazzo-1/index.mjs +15 -40
  22. package/src/dereference/strategies/arazzo-1/visitor.cjs +207 -331
  23. package/src/dereference/strategies/arazzo-1/visitor.mjs +215 -338
  24. package/src/dereference/strategies/asyncapi-2/index.cjs +11 -39
  25. package/src/dereference/strategies/asyncapi-2/index.mjs +11 -39
  26. package/src/dereference/strategies/asyncapi-2/visitor.cjs +133 -425
  27. package/src/dereference/strategies/asyncapi-2/visitor.mjs +137 -429
  28. package/src/dereference/strategies/openapi-2/index.cjs +12 -42
  29. package/src/dereference/strategies/openapi-2/index.mjs +12 -42
  30. package/src/dereference/strategies/openapi-2/visitor.cjs +168 -532
  31. package/src/dereference/strategies/openapi-2/visitor.mjs +172 -536
  32. package/src/dereference/strategies/openapi-3-0/index.cjs +12 -42
  33. package/src/dereference/strategies/openapi-3-0/index.mjs +12 -42
  34. package/src/dereference/strategies/openapi-3-0/visitor.cjs +194 -468
  35. package/src/dereference/strategies/openapi-3-0/visitor.mjs +199 -473
  36. package/src/dereference/strategies/openapi-3-1/index.cjs +16 -42
  37. package/src/dereference/strategies/openapi-3-1/index.mjs +16 -42
  38. package/src/dereference/strategies/openapi-3-1/visitor.cjs +350 -602
  39. package/src/dereference/strategies/openapi-3-1/visitor.mjs +357 -608
  40. package/src/dereference/strategies/overlay-1/index.cjs +3 -2
  41. package/src/dereference/strategies/overlay-1/index.mjs +3 -2
  42. package/src/index.cjs +0 -7
  43. package/src/index.mjs +0 -1
  44. package/src/parse/index.cjs +9 -1
  45. package/src/parse/index.mjs +9 -1
  46. package/src/parse/parsers/apidom-json/index.cjs +2 -1
  47. package/src/parse/parsers/apidom-json/index.mjs +2 -1
  48. package/src/parse/parsers/arazzo-json-1/index.cjs +2 -1
  49. package/src/parse/parsers/arazzo-json-1/index.mjs +2 -1
  50. package/src/parse/parsers/arazzo-yaml-1/index.cjs +2 -1
  51. package/src/parse/parsers/arazzo-yaml-1/index.mjs +2 -1
  52. package/src/parse/parsers/asyncapi-json-2/index.cjs +2 -1
  53. package/src/parse/parsers/asyncapi-json-2/index.mjs +2 -1
  54. package/src/parse/parsers/asyncapi-yaml-2/index.cjs +2 -1
  55. package/src/parse/parsers/asyncapi-yaml-2/index.mjs +2 -1
  56. package/src/parse/parsers/json/index.cjs +2 -1
  57. package/src/parse/parsers/json/index.mjs +2 -1
  58. package/src/parse/parsers/openapi-json-2/index.cjs +2 -1
  59. package/src/parse/parsers/openapi-json-2/index.mjs +2 -1
  60. package/src/parse/parsers/openapi-json-3-0/index.cjs +2 -1
  61. package/src/parse/parsers/openapi-json-3-0/index.mjs +2 -1
  62. package/src/parse/parsers/openapi-json-3-1/index.cjs +2 -1
  63. package/src/parse/parsers/openapi-json-3-1/index.mjs +2 -1
  64. package/src/parse/parsers/openapi-yaml-2/index.cjs +2 -1
  65. package/src/parse/parsers/openapi-yaml-2/index.mjs +2 -1
  66. package/src/parse/parsers/openapi-yaml-3-0/index.cjs +2 -1
  67. package/src/parse/parsers/openapi-yaml-3-0/index.mjs +2 -1
  68. package/src/parse/parsers/openapi-yaml-3-1/index.cjs +2 -1
  69. package/src/parse/parsers/openapi-yaml-3-1/index.mjs +2 -1
  70. package/src/parse/parsers/overlay-json-1/index.cjs +2 -1
  71. package/src/parse/parsers/overlay-json-1/index.mjs +2 -1
  72. package/src/parse/parsers/overlay-yaml-1/index.cjs +2 -1
  73. package/src/parse/parsers/overlay-yaml-1/index.mjs +2 -1
  74. package/src/parse/parsers/yaml-1-2/index.cjs +2 -1
  75. package/src/parse/parsers/yaml-1-2/index.mjs +2 -1
  76. package/types/apidom-reference.d.ts +0 -9
  77. package/types/dereference/strategies/DereferenceVisitor.d.ts +224 -0
  78. package/types/dereference/strategies/arazzo-1/index.d.ts +0 -1
  79. package/types/dereference/strategies/arazzo-1/visitor.d.ts +38 -38
  80. package/types/dereference/strategies/asyncapi-2/index.d.ts +0 -1
  81. package/types/dereference/strategies/asyncapi-2/visitor.d.ts +13 -29
  82. package/types/dereference/strategies/openapi-2/index.d.ts +0 -1
  83. package/types/dereference/strategies/openapi-2/visitor.d.ts +14 -29
  84. package/types/dereference/strategies/openapi-3-0/index.d.ts +0 -1
  85. package/types/dereference/strategies/openapi-3-0/visitor.d.ts +13 -28
  86. package/types/dereference/strategies/openapi-3-1/index.d.ts +0 -1
  87. package/types/dereference/strategies/openapi-3-1/visitor.d.ts +37 -33
  88. package/types/index.d.ts +0 -1
  89. package/src/dereference/util.cjs +0 -33
  90. package/src/dereference/util.mjs +0 -27
  91. package/types/dereference/util.d.ts +0 -9
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.default = void 0;
8
8
  var _apidomParserAdapterYaml = require("@speclynx/apidom-parser-adapter-yaml-1-2");
9
+ var _mediaTypes = require("@swaggerexpert/media-types");
9
10
  var _ParserError = _interopRequireDefault(require("../../../errors/ParserError.cjs"));
10
11
  var _Parser = _interopRequireDefault(require("../Parser.cjs"));
11
12
  /**
@@ -32,7 +33,7 @@ class YAML1Parser extends _Parser.default {
32
33
  }
33
34
  async canParse(file) {
34
35
  const hasSupportedFileExtension = this.fileExtensions.length === 0 ? true : this.fileExtensions.includes(file.extension);
35
- const hasSupportedMediaType = this.mediaTypes.includes(file.mediaType);
36
+ const hasSupportedMediaType = (0, _mediaTypes.selectBestMatch)(this.mediaTypes, file.mediaType) !== null;
36
37
  if (!hasSupportedFileExtension) return false;
37
38
  if (hasSupportedMediaType) return true;
38
39
  if (!hasSupportedMediaType) {
@@ -1,4 +1,5 @@
1
1
  import { parse, mediaTypes as YAMLMediaTypes, detect } from '@speclynx/apidom-parser-adapter-yaml-1-2';
2
+ import { selectBestMatch } from '@swaggerexpert/media-types';
2
3
  import ParserError from "../../../errors/ParserError.mjs";
3
4
  import Parser from "../Parser.mjs";
4
5
  /**
@@ -24,7 +25,7 @@ class YAML1Parser extends Parser {
24
25
  }
25
26
  async canParse(file) {
26
27
  const hasSupportedFileExtension = this.fileExtensions.length === 0 ? true : this.fileExtensions.includes(file.extension);
27
- const hasSupportedMediaType = this.mediaTypes.includes(file.mediaType);
28
+ const hasSupportedMediaType = selectBestMatch(this.mediaTypes, file.mediaType) !== null;
28
29
  if (!hasSupportedFileExtension) return false;
29
30
  if (hasSupportedMediaType) return true;
30
31
  if (!hasSupportedMediaType) {
@@ -143,15 +143,6 @@ declare const cwd: () => string;
143
143
  */
144
144
  export declare const dereference: (uri: string, options?: {}) => Promise<ParseResultElement>;
145
145
 
146
- /**
147
- * @public
148
- */
149
- export declare class DereferenceAncestorLineage<T extends Element_2> extends Array<Set<T>> {
150
- includesCycle(element: T): boolean;
151
- includes(searchElement: Set<T> | T, fromIndex?: number): boolean;
152
- findItem(predicate: (item: T) => boolean): T | undefined;
153
- }
154
-
155
146
  /**
156
147
  * @public
157
148
  */
@@ -0,0 +1,224 @@
1
+ import { Element } from '@speclynx/apidom-datamodel';
2
+ import { type Path } from '@speclynx/apidom-traverse';
3
+ import Reference from '../../Reference.ts';
4
+ import type { ReferenceOptions } from '../../options/index.ts';
5
+ /**
6
+ * Whether the element is generic ApiDOM: an instance of a primitive element class itself.
7
+ * Semantic elements may carry a primitive element name (e.g. a map of components named
8
+ * `object`), so the name alone doesn't tell.
9
+ * @internal
10
+ */
11
+ export declare const isGenericElement: (element: Element) => boolean;
12
+ /**
13
+ * A source dereferenced as one type: the source as that semantic type, with every reference
14
+ * within it transcluded. `element` exists from the start, so references leading back to
15
+ * an element still being dereferenced (cycles) can be transcluded with it.
16
+ * @internal
17
+ */
18
+ export interface DereferencedElement {
19
+ element: Element;
20
+ done: boolean;
21
+ height: number;
22
+ alias: boolean;
23
+ unresolved: boolean;
24
+ }
25
+ /**
26
+ * How a referencing element is transcluded with the dereferenced target of its reference.
27
+ * @internal
28
+ */
29
+ export interface TransclusionSpec {
30
+ /**
31
+ * The element transcluded in place of the referencing element, built from the dereferenced
32
+ * target (which may still be being dereferenced when the reference leads back to it).
33
+ */
34
+ readonly toTranscludedElement: (referencingElement: Element, target: Element) => Element;
35
+ /**
36
+ * Field holding the reference of an alias, for references merging their target with
37
+ * the fields next to them (e.g. `$ref`): a target that is an alias whose reference never
38
+ * reaches a value is merged without that field, so only the fields along the chain remain.
39
+ * Without it, a referencing element leading to such an alias is kept as written.
40
+ */
41
+ readonly aliasField?: string;
42
+ /**
43
+ * What a circular reference is reported and replaced with: the RefElement content and meta
44
+ * for `dereference.circular: 'replace'`, the error details for `'error'`.
45
+ */
46
+ readonly circular: {
47
+ readonly uri: string;
48
+ readonly meta: Record<string, unknown>;
49
+ readonly details: Record<string, unknown>;
50
+ };
51
+ }
52
+ /**
53
+ * A transclusion to perform.
54
+ * @internal
55
+ */
56
+ export interface Transclusion extends TransclusionSpec {
57
+ readonly target: DereferencedElement;
58
+ readonly back: boolean;
59
+ readonly keep: boolean;
60
+ readonly attachment: boolean;
61
+ }
62
+ /**
63
+ * The target of a reference: the source element, the type the reference expects, and the
64
+ * document the source belongs to. `context` is passed to the visitor dereferencing the source.
65
+ * @internal
66
+ */
67
+ export interface DereferenceTarget<TContext = unknown> {
68
+ readonly source: Element;
69
+ readonly type: string;
70
+ readonly reference: Reference;
71
+ readonly context: TContext;
72
+ }
73
+ /**
74
+ * State shared by all the visitors of a single dereference run.
75
+ * @internal
76
+ */
77
+ export interface DereferenceRun {
78
+ readonly dereferenced: WeakMap<Element, Map<string, DereferencedElement>>;
79
+ readonly refracted: WeakMap<Element, Map<string, Element>>;
80
+ readonly inPlace: boolean;
81
+ readonly copies: WeakMap<object, object>;
82
+ readonly transcluded: WeakSet<Element>;
83
+ readonly failed: WeakSet<Element>;
84
+ readonly reported: Set<string>;
85
+ readonly undo: (() => void)[];
86
+ }
87
+ /**
88
+ * @internal
89
+ */
90
+ export interface DereferenceVisitorOptions {
91
+ readonly reference: Reference;
92
+ readonly options: ReferenceOptions;
93
+ }
94
+ /**
95
+ * Dereferences a document by the type each reference expects of its target. With the immutable
96
+ * option the documents aren't edited and the result is a new tree; otherwise they're
97
+ * dereferenced in place.
98
+ *
99
+ * Every referenced structure is dereferenced once per type the references reaching it expect.
100
+ * A source is dereferenced as a type in two steps. First it's traversed, and for each reference
101
+ * within it the target is located, dereferenced as the expected type, and recorded as
102
+ * a transclusion. Then the referencing elements are transcluded with the dereferenced targets.
103
+ * A dereferenced element is shared by all the references leading to it; a reference leading
104
+ * to an element still being dereferenced is a cycle.
105
+ *
106
+ * Strategies provide the handlers locating the targets of their references, the refraction to
107
+ * their semantic types and the visitors dereferencing the targets.
108
+ * @internal
109
+ */
110
+ declare abstract class DereferenceVisitor<TContext = unknown> {
111
+ protected readonly reference: Reference;
112
+ protected readonly options: ReferenceOptions;
113
+ /**
114
+ * Base URI of the current document for resolving relative references.
115
+ */
116
+ protected readonly baseURI: string;
117
+ protected run: DereferenceRun;
118
+ /**
119
+ * Map from the elements of the source the visitor traverses to their copies.
120
+ */
121
+ protected cloneMap?: WeakMap<object, object>;
122
+ /**
123
+ * Source the visitor traverses a refraction of, when it's dereferenced as another type.
124
+ */
125
+ protected refractedFrom?: Element;
126
+ /**
127
+ * Transclusions to perform, keyed by the (copy of the) referencing element.
128
+ */
129
+ protected readonly transclusions: Map<Element, Transclusion>;
130
+ /**
131
+ * Number of references followed to reach the source the visitor traverses.
132
+ */
133
+ protected depth: number;
134
+ /**
135
+ * The source the visitor traverses, dereferenced.
136
+ */
137
+ protected current?: DereferencedElement;
138
+ constructor({ reference, options }: DereferenceVisitorOptions);
139
+ /**
140
+ * Name of the strategy, for strategy specific options.
141
+ */
142
+ protected abstract get strategyName(): string;
143
+ /**
144
+ * Creates the visitor dereferencing a source of the given document.
145
+ */
146
+ protected abstract createVisitor(reference: Reference, context: TContext): DereferenceVisitor;
147
+ /**
148
+ * Refracts a generic element to the given type.
149
+ */
150
+ protected abstract refractTo(element: Element, type: string): Element;
151
+ /**
152
+ * Whether the element is of the given type, so it needs no refraction.
153
+ */
154
+ protected isOfType(element: Element, type: string): boolean;
155
+ /**
156
+ * Base URI of a document: its retrieval URI unless the document identifies itself otherwise.
157
+ */
158
+ protected toDocumentBaseURI(reference: Reference): string;
159
+ /**
160
+ * A document already loaded in the run identified by the URI other than by its retrieval URI.
161
+ */
162
+ protected findReferenceByIdentity(_uri: string): Reference | undefined;
163
+ /**
164
+ * Dereferences the element, which belongs to the document of the visitor's reference.
165
+ * With the immutable option the element isn't edited and its dereferenced copy is returned;
166
+ * otherwise it's dereferenced in place and returned.
167
+ */
168
+ dereference<T extends Element>(element: T, context: TContext): Promise<T>;
169
+ protected toBaseURI(uri: string): string;
170
+ protected toReference(uri: string): Promise<Reference>;
171
+ /**
172
+ * Handles an error according to the continueOnError option.
173
+ *
174
+ * For new errors: wraps in UnresolvableReferenceError with structured context
175
+ * (type, uri, location, codeFrame, refFieldName, refFieldValue, trace).
176
+ * For errors already wrapped by a nested visitor: prepends the current hop to the trace.
177
+ *
178
+ * Inner/intermediate visitors always throw to let the trace accumulate.
179
+ * Only the entry document visitor respects continueOnError (callback/swallow/throw),
180
+ * and reports the failure of a referencing element once.
181
+ */
182
+ protected handleError(message: string, error: Error, referencingElement: Element, refFieldName: string, refFieldValue: string, visitorPath: Path<Element>): void;
183
+ /**
184
+ * The source as the given semantic type: the source itself when it's of that type, otherwise
185
+ * its refraction to that type, made once per dereference run. The refraction is made from
186
+ * the source dereferenced as its own type, so it doesn't depend on which reference
187
+ * reaches the source first.
188
+ */
189
+ protected toSemantic(target: DereferenceTarget<TContext>, depth: number): Promise<Element>;
190
+ /**
191
+ * Dereferences the source as the given type, once per dereference run. `depth` is the number
192
+ * of references followed to reach the source.
193
+ */
194
+ protected dereferenceAs(target: DereferenceTarget<TContext>, depth: number): Promise<DereferencedElement>;
195
+ /**
196
+ * Dereferences the target of a reference as the expected type and records the transclusion.
197
+ */
198
+ protected addTransclusion(path: Path<Element>, target: DereferenceTarget<TContext>, spec: TransclusionSpec): Promise<void>;
199
+ /**
200
+ * Records the transclusion of a referencing element with a target that isn't dereferenced:
201
+ * the target as the expected type is attached as it is, e.g. an Operation Object to the Link
202
+ * Object pointing at it. Attached targets never form cycles.
203
+ */
204
+ protected addAttachment(path: Path<Element>, target: DereferenceTarget<TContext>, toTranscludedElement: TransclusionSpec['toTranscludedElement']): Promise<void>;
205
+ /**
206
+ * Transcludes every referencing element within the element with its dereferenced target.
207
+ */
208
+ protected transclude(element: Element): Element;
209
+ /**
210
+ * The element transcluded in place of a referencing element.
211
+ */
212
+ protected toTranscludedElement(referencingElement: Element, transclusion: Transclusion): Element;
213
+ /**
214
+ * Whether the element is transcluded in place of a referencing element, in this run or,
215
+ * when dereferencing in place, in an earlier one: transcluded elements carry the `ref-type` meta,
216
+ * which only dereferencing sets (bundling annotates hoisted elements with `ref-origin` only).
217
+ */
218
+ protected isTranscluded(element: Element): boolean;
219
+ /**
220
+ * Dereferenced in place, a source may already hold transcluded elements.
221
+ */
222
+ enter(path: Path<Element>): void;
223
+ }
224
+ export default DereferenceVisitor;
@@ -13,7 +13,6 @@ export type { default as Parser, ParserOptions } from '../../../parse/parsers/Pa
13
13
  export type { default as Resolver, ResolverOptions } from '../../../resolve/resolvers/Resolver.ts';
14
14
  export type { default as ResolveStrategy, ResolveStrategyOptions, } from '../../../resolve/strategies/ResolveStrategy.ts';
15
15
  export type { default as BundleStrategy, BundleStrategyOptions, } from '../../../bundle/strategies/BundleStrategy.ts';
16
- export type { AncestorLineage } from '../../util.ts';
17
16
  /**
18
17
  * @public
19
18
  */
@@ -1,70 +1,70 @@
1
1
  import { Element } from '@speclynx/apidom-datamodel';
2
2
  import { type Path } from '@speclynx/apidom-traverse';
3
3
  import { type Schema$idIndex } from './selectors/uri.ts';
4
+ import DereferenceVisitor from '../DereferenceVisitor.ts';
4
5
  import Reference from '../../../Reference.ts';
5
- import { AncestorLineage } from '../../util.ts';
6
6
  import type { ReferenceOptions } from '../../../options/index.ts';
7
+ /**
8
+ * Context of a source being dereferenced: the `$id`s of the JSON Schema elements enclosing it.
9
+ */
10
+ interface Arazzo1DereferenceContext {
11
+ readonly ancestorSchema$ids: string[];
12
+ }
7
13
  /**
8
14
  * @public
9
15
  */
10
16
  export interface Arazzo1DereferenceVisitorOptions {
11
17
  readonly reference: Reference;
12
18
  readonly options: ReferenceOptions;
13
- readonly indirections?: Element[];
14
19
  readonly schema$idIndex?: Schema$idIndex;
15
- readonly ancestors?: AncestorLineage<Element>;
16
- readonly visited?: WeakSet<Element>;
17
20
  readonly ancestorSchema$ids?: string[];
18
21
  }
19
22
  /**
23
+ * Dereferences an Arazzo document. Reusable Objects expect the type of their
24
+ * `referenced-element` meta, JSON Schema `$ref`s expect a JSON Schema.
25
+ *
20
26
  * @public
21
27
  */
22
- declare class Arazzo1DereferenceVisitor {
23
- protected readonly indirections: Element[];
24
- protected readonly reference: Reference;
25
- /**
26
- * Base URI of the current document for resolving relative references.
27
- * Honors the Arazzo `$self` field when present, otherwise falls back
28
- * to the retrieval URI (`this.reference.uri`).
29
- */
30
- protected readonly baseURI: string;
31
- protected readonly options: ReferenceOptions;
28
+ declare class Arazzo1DereferenceVisitor extends DereferenceVisitor<Arazzo1DereferenceContext> {
32
29
  /**
33
- * Index of `$id`-bearing schemas per document, shared across nested visitors
34
- * of a single dereference run so it never outlives mutations of the documents.
30
+ * Index of `$id`-bearing schemas per document, shared across the visitors
31
+ * of a single dereference run.
35
32
  */
36
33
  protected readonly schema$idIndex: Schema$idIndex;
37
- protected readonly visited: WeakSet<Element>;
38
34
  /**
39
35
  * `$id`s of the JSON Schema elements enclosing the traversal root within its
40
36
  * document (outermost first). Empty when the root is the document itself; a
41
- * nested visitor traversing a fragment is seeded with the `$id`s of the
42
- * schemas the fragment sits under, so the `$ref`s and `$id`s within resolve
43
- * against the same base as they would from the document root.
37
+ * visitor traversing a fragment is seeded with the `$id`s of the schemas the
38
+ * fragment sits under, so the `$ref`s and `$id`s within resolve against the
39
+ * same base as they would from the document root.
44
40
  */
45
41
  protected readonly ancestorSchema$ids: string[];
42
+ constructor({ reference, options, schema$idIndex, ancestorSchema$ids, }: Arazzo1DereferenceVisitorOptions);
43
+ protected get strategyName(): string;
44
+ protected createVisitor(reference: Reference, { ancestorSchema$ids }: Arazzo1DereferenceContext): Arazzo1DereferenceVisitor;
45
+ protected refractTo(element: Element, type: string): Element;
46
+ protected isOfType(element: Element, type: string): boolean;
47
+ /**
48
+ * Honors the Arazzo `$self` field when present, otherwise falls back to the retrieval URI.
49
+ */
50
+ protected toDocumentBaseURI(reference: Reference): string;
51
+ /**
52
+ * Identity-based referencing: URI matches `$self` of an already processed Arazzo document.
53
+ */
54
+ protected findReferenceByIdentity(uri: string): Reference | undefined;
46
55
  /**
47
- * Tracks element ancestors across dive-deep traversal boundaries.
48
- * Used for cycle detection: if a referenced element is found in
49
- * the ancestor lineage, a circular reference is detected.
56
+ * A document as JSON Schema for locating schemas within it: a generic document is
57
+ * refracted to JSON Schema once per dereference run, a semantic one is used as it is.
50
58
  */
51
- protected readonly ancestors: AncestorLineage<Element>;
52
- constructor({ reference, options, indirections, schema$idIndex, ancestors, visited, ancestorSchema$ids, }: Arazzo1DereferenceVisitorOptions);
53
- protected toAncestorLineage(path: Path<Element>): [AncestorLineage<Element>, Set<Element>];
54
- protected toBaseURI(uri: string): string;
55
- protected toReference(uri: string): Promise<Reference>;
59
+ protected toJSONSchemaDocument(document: Element): Element;
56
60
  /**
57
- * Handles an error according to the continueOnError option.
58
- *
59
- * For new errors: wraps in UnresolvableReferenceError with structured context
60
- * (type, uri, location, codeFrame, refFieldName, refFieldValue, trace).
61
- * For errors already wrapped by a nested visitor: prepends the current hop to the trace.
62
- *
63
- * Inner/intermediate visitors always throw to let the trace accumulate.
64
- * Only the entry document visitor respects continueOnError (callback/swallow/throw).
61
+ * Indexes the `$id`-bearing schemas of a document for the run. Transcluded elements aren't
62
+ * indexed: they're copies of structures indexed where they're defined,
63
+ * and in a document dereferenced in place their shared structure would be walked once per path.
65
64
  */
66
- protected handleError(message: string, error: Error, referencingElement: Element, refFieldName: string, refFieldValue: string, visitorPath: Path<Element>): void;
67
- ReusableElement(path: Path<Element>): void;
65
+ protected index$ids(element: Element): void;
66
+ enter(path: Path<Element>): void;
67
+ ReusableElement(path: Path<Element>): Promise<void>;
68
68
  JSONSchemaElement(path: Path<Element>): Promise<void>;
69
69
  }
70
70
  export default Arazzo1DereferenceVisitor;
@@ -13,7 +13,6 @@ export type { default as Parser, ParserOptions } from '../../../parse/parsers/Pa
13
13
  export type { default as Resolver, ResolverOptions } from '../../../resolve/resolvers/Resolver.ts';
14
14
  export type { default as ResolveStrategy, ResolveStrategyOptions, } from '../../../resolve/strategies/ResolveStrategy.ts';
15
15
  export type { default as BundleStrategy, BundleStrategyOptions, } from '../../../bundle/strategies/BundleStrategy.ts';
16
- export type { AncestorLineage } from '../../util.ts';
17
16
  /**
18
17
  * @public
19
18
  */
@@ -1,6 +1,6 @@
1
1
  import { Element } from '@speclynx/apidom-datamodel';
2
- import { type Path } from '@speclynx/apidom-traverse';
3
- import { AncestorLineage } from '../../util.ts';
2
+ import type { Path } from '@speclynx/apidom-traverse';
3
+ import DereferenceVisitor from '../DereferenceVisitor.ts';
4
4
  import Reference from '../../../Reference.ts';
5
5
  import type { ReferenceOptions } from '../../../options/index.ts';
6
6
  /**
@@ -9,41 +9,25 @@ import type { ReferenceOptions } from '../../../options/index.ts';
9
9
  export interface AsyncAPI2DereferenceVisitorOptions {
10
10
  readonly reference: Reference;
11
11
  readonly options: ReferenceOptions;
12
- readonly indirections?: Element[];
13
- readonly refractCache?: WeakMap<Element, Element>;
14
- readonly ancestors?: AncestorLineage<Element>;
15
- readonly visited?: WeakSet<Element>;
16
12
  }
17
13
  /**
14
+ * Dereferences an AsyncAPI 2 document. Reference Objects expect the type of their
15
+ * `referenced-element` meta, Channel Item `$ref`s a Channel Item Object.
16
+ *
18
17
  * @public
19
18
  */
20
- declare class AsyncAPI2DereferenceVisitor {
21
- protected readonly indirections: Element[];
22
- protected readonly reference: Reference;
23
- protected readonly options: ReferenceOptions;
24
- protected readonly refractCache: WeakMap<Element, Element>;
25
- protected readonly visited: WeakSet<Element>;
19
+ declare class AsyncAPI2DereferenceVisitor extends DereferenceVisitor<undefined> {
20
+ protected get strategyName(): string;
21
+ protected createVisitor(reference: Reference): AsyncAPI2DereferenceVisitor;
26
22
  /**
27
- * Tracks element ancestors across dive-deep traversal boundaries.
28
- * Used for cycle detection: if a referenced element is found in
29
- * the ancestor lineage, a circular reference is detected.
23
+ * A Reference Object stands for the type its reference expects: it's dereferenced as that type.
30
24
  */
31
- protected readonly ancestors: AncestorLineage<Element>;
32
- constructor({ reference, options, indirections, ancestors, refractCache, visited, }: AsyncAPI2DereferenceVisitorOptions);
33
- protected toAncestorLineage(path: Path<Element>): [AncestorLineage<Element>, Set<Element>];
34
- protected toBaseURI(uri: string): string;
35
- protected toReference(uri: string): Promise<Reference>;
25
+ protected isOfType(element: Element, type: string): boolean;
36
26
  /**
37
- * Handles an error according to the continueOnError option.
38
- *
39
- * For new errors: wraps in UnresolvableReferenceError with structured context
40
- * (type, uri, location, codeFrame, refFieldName, refFieldValue, trace).
41
- * For errors already wrapped by a nested visitor: prepends the current hop to the trace.
42
- *
43
- * Inner/intermediate visitors always throw to let the trace accumulate.
44
- * Only the entry document visitor respects continueOnError (callback/swallow/throw).
27
+ * A generic structure holding a `$ref` is a Reference Object to the expected type,
28
+ * unless the type has its own `$ref` field (Channel Item Object).
45
29
  */
46
- protected handleError(message: string, error: Error, referencingElement: Element, refFieldName: string, refFieldValue: string, visitorPath: Path<Element>): void;
30
+ protected refractTo(element: Element, type: string): Element;
47
31
  ReferenceElement(path: Path<Element>): Promise<void>;
48
32
  ChannelItemElement(path: Path<Element>): Promise<void>;
49
33
  }
@@ -13,7 +13,6 @@ export type { default as Parser, ParserOptions } from '../../../parse/parsers/Pa
13
13
  export type { default as Resolver, ResolverOptions } from '../../../resolve/resolvers/Resolver.ts';
14
14
  export type { default as ResolveStrategy, ResolveStrategyOptions, } from '../../../resolve/strategies/ResolveStrategy.ts';
15
15
  export type { default as BundleStrategy, BundleStrategyOptions, } from '../../../bundle/strategies/BundleStrategy.ts';
16
- export type { AncestorLineage } from '../../util.ts';
17
16
  export type { AsyncAPI2DereferenceVisitorOptions } from '../asyncapi-2/visitor.ts';
18
17
  /**
19
18
  * @public
@@ -1,6 +1,6 @@
1
1
  import { Element } from '@speclynx/apidom-datamodel';
2
- import { type Path } from '@speclynx/apidom-traverse';
3
- import { AncestorLineage } from '../../util.ts';
2
+ import type { Path } from '@speclynx/apidom-traverse';
3
+ import DereferenceVisitor from '../DereferenceVisitor.ts';
4
4
  import Reference from '../../../Reference.ts';
5
5
  import type { ReferenceOptions } from '../../../options/index.ts';
6
6
  /**
@@ -9,41 +9,26 @@ import type { ReferenceOptions } from '../../../options/index.ts';
9
9
  export interface OpenAPI2DereferenceVisitorOptions {
10
10
  readonly reference: Reference;
11
11
  readonly options: ReferenceOptions;
12
- readonly indirections?: Element[];
13
- readonly refractCache?: WeakMap<Element, Element>;
14
- readonly ancestors?: AncestorLineage<Element>;
15
- readonly visited?: WeakSet<Element>;
16
12
  }
17
13
  /**
14
+ * Dereferences an OpenAPI 2.0 document. Reference Objects and JSON Reference Objects expect
15
+ * the type of their `referenced-element` meta, Path Item `$ref`s a Path Item Object.
16
+ *
18
17
  * @public
19
18
  */
20
- declare class OpenAPI2DereferenceVisitor {
21
- protected readonly indirections: Element[];
22
- protected readonly reference: Reference;
23
- protected readonly options: ReferenceOptions;
24
- protected readonly refractCache: WeakMap<Element, Element>;
25
- protected readonly visited: WeakSet<Element>;
19
+ declare class OpenAPI2DereferenceVisitor extends DereferenceVisitor<undefined> {
20
+ protected get strategyName(): string;
21
+ protected createVisitor(reference: Reference): OpenAPI2DereferenceVisitor;
26
22
  /**
27
- * Tracks element ancestors across dive-deep traversal boundaries.
28
- * Used for cycle detection: if a referenced element is found in
29
- * the ancestor lineage, a circular reference is detected.
23
+ * A (JSON) Reference Object stands for the type its reference expects: it's dereferenced as that type.
30
24
  */
31
- protected readonly ancestors: AncestorLineage<Element>;
32
- constructor({ reference, options, indirections, ancestors, refractCache, visited, }: OpenAPI2DereferenceVisitorOptions);
33
- protected toAncestorLineage(path: Path<Element>): [AncestorLineage<Element>, Set<Element>];
34
- protected toBaseURI(uri: string): string;
35
- protected toReference(uri: string): Promise<Reference>;
25
+ protected isOfType(element: Element, type: string): boolean;
36
26
  /**
37
- * Handles an error according to the continueOnError option.
38
- *
39
- * For new errors: wraps in UnresolvableReferenceError with structured context
40
- * (type, uri, location, codeFrame, refFieldName, refFieldValue, trace).
41
- * For errors already wrapped by a nested visitor: prepends the current hop to the trace.
42
- *
43
- * Inner/intermediate visitors always throw to let the trace accumulate.
44
- * Only the entry document visitor respects continueOnError (callback/swallow/throw).
27
+ * A generic structure holding a `$ref` is a reference to the expected type: a JSON Reference
28
+ * Object for a Schema Object, a Reference Object otherwise, unless the type has its own `$ref`
29
+ * field (Path Item Object).
45
30
  */
46
- protected handleError(message: string, error: Error, referencingElement: Element, refFieldName: string, refFieldValue: string, visitorPath: Path<Element>): void;
31
+ protected refractTo(element: Element, type: string): Element;
47
32
  ReferenceElement(path: Path<Element>): Promise<void>;
48
33
  PathItemElement(path: Path<Element>): Promise<void>;
49
34
  JSONReferenceElement(path: Path<Element>): Promise<void>;
@@ -13,7 +13,6 @@ export type { default as Parser, ParserOptions } from '../../../parse/parsers/Pa
13
13
  export type { default as Resolver, ResolverOptions } from '../../../resolve/resolvers/Resolver.ts';
14
14
  export type { default as ResolveStrategy, ResolveStrategyOptions, } from '../../../resolve/strategies/ResolveStrategy.ts';
15
15
  export type { default as BundleStrategy, BundleStrategyOptions, } from '../../../bundle/strategies/BundleStrategy.ts';
16
- export type { AncestorLineage } from '../../util.ts';
17
16
  /**
18
17
  * @public
19
18
  */
@@ -1,7 +1,7 @@
1
1
  import { Element } from '@speclynx/apidom-datamodel';
2
2
  import { type Path } from '@speclynx/apidom-traverse';
3
+ import DereferenceVisitor from '../DereferenceVisitor.ts';
3
4
  import Reference from '../../../Reference.ts';
4
- import { AncestorLineage } from '../../util.ts';
5
5
  import type { ReferenceOptions } from '../../../options/index.ts';
6
6
  /**
7
7
  * @public
@@ -9,41 +9,26 @@ import type { ReferenceOptions } from '../../../options/index.ts';
9
9
  export interface OpenAPI3_0DereferenceVisitorOptions {
10
10
  readonly reference: Reference;
11
11
  readonly options: ReferenceOptions;
12
- readonly indirections?: Element[];
13
- readonly refractCache?: WeakMap<Element, Element>;
14
- readonly ancestors?: AncestorLineage<Element>;
15
- readonly visited?: WeakSet<Element>;
16
12
  }
17
13
  /**
14
+ * Dereferences an OpenAPI 3.0 document. Reference Objects expect the type of their
15
+ * `referenced-element` meta, Path Item `$ref`s a Path Item Object. Link Objects get the
16
+ * Operation Object they point at attached, Example Objects the external value.
17
+ *
18
18
  * @public
19
19
  */
20
- declare class OpenAPI3_0DereferenceVisitor {
21
- protected readonly indirections: Element[];
22
- protected readonly reference: Reference;
23
- protected readonly options: ReferenceOptions;
24
- protected readonly refractCache: WeakMap<Element, Element>;
25
- protected readonly visited: WeakSet<Element>;
20
+ declare class OpenAPI3_0DereferenceVisitor extends DereferenceVisitor<undefined> {
21
+ protected get strategyName(): string;
22
+ protected createVisitor(reference: Reference): OpenAPI3_0DereferenceVisitor;
26
23
  /**
27
- * Tracks element ancestors across dive-deep traversal boundaries.
28
- * Used for cycle detection: if a referenced element is found in
29
- * the ancestor lineage, a circular reference is detected.
24
+ * A Reference Object stands for the type its reference expects: it's dereferenced as that type.
30
25
  */
31
- protected readonly ancestors: AncestorLineage<Element>;
32
- constructor({ reference, options, indirections, ancestors, refractCache, visited, }: OpenAPI3_0DereferenceVisitorOptions);
33
- protected toAncestorLineage(path: Path<Element>): [AncestorLineage<Element>, Set<Element>];
34
- protected toBaseURI(uri: string): string;
35
- protected toReference(uri: string): Promise<Reference>;
26
+ protected isOfType(element: Element, type: string): boolean;
36
27
  /**
37
- * Handles an error according to the continueOnError option.
38
- *
39
- * For new errors: wraps in UnresolvableReferenceError with structured context
40
- * (type, uri, location, codeFrame, refFieldName, refFieldValue, trace).
41
- * For errors already wrapped by a nested visitor: prepends the current hop to the trace.
42
- *
43
- * Inner/intermediate visitors always throw to let the trace accumulate.
44
- * Only the entry document visitor respects continueOnError (callback/swallow/throw).
28
+ * A generic structure holding a `$ref` is a Reference Object to the expected type,
29
+ * unless the type has its own `$ref` field (Path Item Object).
45
30
  */
46
- protected handleError(message: string, error: Error, referencingElement: Element, refFieldName: string, refFieldValue: string, visitorPath: Path<Element>): void;
31
+ protected refractTo(element: Element, type: string): Element;
47
32
  ReferenceElement(path: Path<Element>): Promise<void>;
48
33
  PathItemElement(path: Path<Element>): Promise<void>;
49
34
  LinkElement(path: Path<Element>): Promise<void>;
@@ -13,7 +13,6 @@ export type { default as Parser, ParserOptions } from '../../../parse/parsers/Pa
13
13
  export type { default as Resolver, ResolverOptions } from '../../../resolve/resolvers/Resolver.ts';
14
14
  export type { default as ResolveStrategy, ResolveStrategyOptions, } from '../../../resolve/strategies/ResolveStrategy.ts';
15
15
  export type { default as BundleStrategy, BundleStrategyOptions, } from '../../../bundle/strategies/BundleStrategy.ts';
16
- export type { AncestorLineage } from '../../util.ts';
17
16
  /**
18
17
  * @public
19
18
  */