@speclynx/apidom-reference 4.15.0 → 5.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.
@@ -0,0 +1,116 @@
1
+ import { Element, ObjectElement, ParseResultElement } from '@speclynx/apidom-datamodel';
2
+ import { type Path } from '@speclynx/apidom-traverse';
3
+ import { AsyncApi2Element } from '@speclynx/apidom-ns-asyncapi-2';
4
+ import Reference from '../../../Reference.ts';
5
+ import type { ReferenceOptions } from '../../../options/index.ts';
6
+ /**
7
+ * @public
8
+ */
9
+ export interface AsyncAPI2BundleVisitorOptions {
10
+ readonly reference: Reference;
11
+ readonly options: ReferenceOptions;
12
+ readonly assignments?: Map<string, string>;
13
+ readonly reservedNames?: Map<string, Set<string>>;
14
+ readonly refractCache?: WeakMap<Element, Map<string, Element>>;
15
+ }
16
+ /**
17
+ * @public
18
+ */
19
+ declare class AsyncAPI2BundleVisitor {
20
+ protected readonly reference: Reference;
21
+ protected readonly options: ReferenceOptions;
22
+ /**
23
+ * The base URI (without hash) of the entry document. A reference is
24
+ * considered internal when it resolves to this URI and external otherwise.
25
+ * Derived from the shared refSet's root reference.
26
+ */
27
+ protected get entryURI(): string;
28
+ /**
29
+ * The entry parse result. Derived from the shared refSet's root reference.
30
+ */
31
+ protected get entryParseResult(): ParseResultElement;
32
+ /**
33
+ * The entry document element. Hoisted external fragments are placed into its
34
+ * `components` object. The `canBundle` guard guarantees it is an
35
+ * AsyncApi2Element.
36
+ */
37
+ protected get entryResult(): AsyncApi2Element;
38
+ /**
39
+ * Shared across the entry document and every external document visitor.
40
+ * Guarantees each external fragment is hoisted exactly once and gives us a
41
+ * stable internal pointer to rewrite every referencing element to.
42
+ */
43
+ protected readonly assignments: Map<string, string>;
44
+ /**
45
+ * Component names already reserved per Components Object field. Reserved
46
+ * before recursion so collision suffixing (`Pet`, `Pet-2`, ...) accounts for
47
+ * components that are still being bundled.
48
+ */
49
+ protected readonly reservedNames: Map<string, Set<string>>;
50
+ /**
51
+ * Caches refracted fragments keyed by source element and target element type.
52
+ * The type is part of the key because the same source can be refracted into
53
+ * different semantic elements depending on the referencing context (e.g. a
54
+ * generic object referenced once as a Parameter and once as a Schema).
55
+ */
56
+ protected readonly refractCache: WeakMap<Element, Map<string, Element>>;
57
+ constructor({ reference, options, assignments, reservedNames, refractCache, }: AsyncAPI2BundleVisitorOptions);
58
+ protected getRefracted(source: Element, type: string): Element | undefined;
59
+ protected setRefracted(source: Element, type: string, refracted: Element): void;
60
+ protected toBaseURI(uri: string): string;
61
+ protected toReference(uri: string): Promise<Reference>;
62
+ /**
63
+ * Normalizes a self-reference (e.g. `./root.json#/components/schemas/Pet`)
64
+ * to a bare fragment (`#/components/schemas/Pet`) so the bundled document stays
65
+ * transferable. Bare fragments are returned unchanged.
66
+ */
67
+ protected normalizeSelfReference(ref: string): string;
68
+ /**
69
+ * Handles an error according to the `bundle.continueOnError` option.
70
+ *
71
+ * For new errors: wraps in UnresolvableReferenceError with structured
72
+ * context. For errors already wrapped by a nested visitor: prepends the
73
+ * current hop to the trace.
74
+ *
75
+ * Inner/intermediate visitors always throw to let the trace accumulate. Only
76
+ * the entry document visitor respects continueOnError (callback/swallow/throw).
77
+ */
78
+ protected handleError(message: string, error: Error, referencingElement: Element, refFieldName: string, refFieldValue: string, visitorPath: Path<Element>): void;
79
+ /**
80
+ * Lazily creates the Components Object (and the requested field within it)
81
+ * on the entry document, returning the field where a fragment is hoisted.
82
+ */
83
+ protected ensureComponentsField(field: string): ObjectElement;
84
+ /**
85
+ * Derives a component name from the referenced JSON Pointer's last token,
86
+ * falling back to the referenced file's basename.
87
+ */
88
+ protected basenameOf(jsonPointer: string, baseURI: string): string;
89
+ /**
90
+ * Computes the base component name (before collision suffixing) according to
91
+ * the configured naming strategy.
92
+ */
93
+ protected baseName(element: Element, field: string, jsonPointer: string, baseURI: string): string;
94
+ /**
95
+ * Computes a collision-free component name within the target field. A name is
96
+ * taken if it's already placed in components or reserved by a component that
97
+ * is still being bundled (reserved before recursion).
98
+ */
99
+ protected uniqueName(candidate: string, field: string): string;
100
+ /**
101
+ * Reports a collision-forced rename according to the configured severity.
102
+ * A rename means two distinct targets resolved to the same name; each keeps
103
+ * its own component (and origin), so report the rename per severity.
104
+ */
105
+ protected reportNameCollision(preferredName: string, componentName: string, field: string): void;
106
+ ReferenceElement(path: Path<Element>): Promise<void>;
107
+ /**
108
+ * AsyncAPI 2.0 has a `components.channels` field, so an external Channel Item
109
+ * Object is hoisted there and the referencing `$ref` is rewritten to an
110
+ * internal pointer — mirroring how Reference Objects are bundled. Sibling
111
+ * fields next to the `$ref` (e.g. `description`) are kept on the referencing
112
+ * element.
113
+ */
114
+ ChannelItemElement(path: Path<Element>): Promise<void>;
115
+ }
116
+ export default AsyncAPI2BundleVisitor;