@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,90 @@
1
+ import { Element, ObjectElement, ParseResultElement } from '@speclynx/apidom-datamodel';
2
+ import { type Path } from '@speclynx/apidom-traverse';
3
+ import { ArazzoSpecification1Element } from '@speclynx/apidom-ns-arazzo-1';
4
+ import Reference from '../../../Reference.ts';
5
+ import type { ReferenceOptions } from '../../../options/index.ts';
6
+ /**
7
+ * @public
8
+ */
9
+ export interface Arazzo1BundleVisitorOptions {
10
+ readonly reference: Reference;
11
+ readonly options: ReferenceOptions;
12
+ readonly assignments?: Map<string, string>;
13
+ readonly reservedNames?: Map<string, Set<string>>;
14
+ }
15
+ /**
16
+ * @public
17
+ */
18
+ declare class Arazzo1BundleVisitor {
19
+ protected readonly reference: Reference;
20
+ protected readonly options: ReferenceOptions;
21
+ /**
22
+ * The entry parse result. Derived from the shared refSet's root reference.
23
+ */
24
+ protected get entryParseResult(): ParseResultElement;
25
+ /**
26
+ * The entry document element. Embedded external schema resources are placed
27
+ * into its `components.inputs` object. The `canBundle` guard guarantees it is
28
+ * an ArazzoSpecification1Element.
29
+ */
30
+ protected get entryResult(): ArazzoSpecification1Element;
31
+ /**
32
+ * Shared across the entry document and every external document visitor.
33
+ * Guarantees each external resource is embedded exactly once, keyed by its
34
+ * resource URI.
35
+ */
36
+ protected readonly assignments: Map<string, string>;
37
+ /**
38
+ * Component names already reserved per Components Object field. Reserved
39
+ * before recursion so collision suffixing (`Pet`, `Pet-2`, ...) accounts for
40
+ * components that are still being bundled.
41
+ */
42
+ protected readonly reservedNames: Map<string, Set<string>>;
43
+ constructor({ reference, options, assignments, reservedNames, }: Arazzo1BundleVisitorOptions);
44
+ protected toBaseURI(uri: string): string;
45
+ protected toReference(uri: string): Promise<Reference>;
46
+ /**
47
+ * Handles an error according to the `bundle.continueOnError` option.
48
+ *
49
+ * For new errors: wraps in UnresolvableReferenceError with structured
50
+ * context. For errors already wrapped by a nested visitor: prepends the
51
+ * current hop to the trace.
52
+ *
53
+ * Inner/intermediate visitors always throw to let the trace accumulate. Only
54
+ * the entry document visitor respects continueOnError (callback/swallow/throw).
55
+ */
56
+ protected handleError(message: string, error: Error, referencingElement: Element, refFieldName: string, refFieldValue: string, visitorPath: Path<Element>): void;
57
+ /**
58
+ * Lazily creates the Components Object (and the `inputs` field within it) on
59
+ * the entry document, returning the field where a resource is embedded.
60
+ */
61
+ protected ensureInputsField(): ObjectElement;
62
+ /**
63
+ * Computes the base component name (before collision suffixing) according to
64
+ * the configured naming strategy.
65
+ */
66
+ protected baseName(element: Element, baseURI: string): string;
67
+ /**
68
+ * Computes a collision-free component name within `components.inputs`. A name
69
+ * is taken if it's already placed in inputs or reserved by a component that is
70
+ * still being bundled (reserved before recursion).
71
+ */
72
+ protected uniqueName(candidate: string): string;
73
+ /**
74
+ * Reports a collision-forced rename according to the configured severity.
75
+ * A rename means two distinct targets resolved to the same name; each keeps
76
+ * its own component (and origin), so report the rename per severity.
77
+ */
78
+ protected reportNameCollision(preferredName: string, componentName: string): void;
79
+ /**
80
+ * JSON Schema Objects in Arazzo (used by Input Objects and inline schemas) are
81
+ * a JSON Schema 2020-12 dialect — the only external reference type Arazzo
82
+ * defines. They are bundled per the JSON Schema Compound Document rules: the
83
+ * external schema RESOURCE is embedded verbatim into `components.inputs`
84
+ * (carrying its `$id`), and the referencing `$ref` is left UNCHANGED — it
85
+ * keeps resolving against the embedded resource's `$id`. This mirrors the
86
+ * openapi-3-1 strategy's Schema Object handling.
87
+ */
88
+ JSONSchemaElement(path: Path<Element>): Promise<void>;
89
+ }
90
+ export default Arazzo1BundleVisitor;
@@ -0,0 +1,31 @@
1
+ import { ParseResultElement } from '@speclynx/apidom-datamodel';
2
+ import File from '../../../File.ts';
3
+ import BundleStrategy, { BundleStrategyOptions } from '../BundleStrategy.ts';
4
+ import AsyncAPI2BundleVisitor from './visitor.ts';
5
+ import type { ReferenceOptions } from '../../../options/index.ts';
6
+ export type { default as DereferenceStrategy, DereferenceStrategyOptions, } from '../../../dereference/strategies/DereferenceStrategy.ts';
7
+ export type { default as File, FileOptions } from '../../../File.ts';
8
+ export type { default as Reference, ReferenceOptions } from '../../../Reference.ts';
9
+ export type { default as ReferenceSet, ReferenceSetOptions } from '../../../ReferenceSet.ts';
10
+ export type { AsyncAPI2BundleVisitorOptions } from './visitor.ts';
11
+ export type { ReferenceOptions as ApiDOMReferenceOptions, ReferenceBundleOptions as ApiDOMReferenceBundleOptions, ReferenceDereferenceOptions as ApiDOMReferenceDereferenceOptions, ReferenceParseOptions as ApiDOMReferenceParseOptions, ReferenceResolveOptions as ApiDOMReferenceResolveOptions, } from '../../../options/index.ts';
12
+ export type { default as Parser, ParserOptions } from '../../../parse/parsers/Parser.ts';
13
+ export type { default as Resolver, ResolverOptions } from '../../../resolve/resolvers/Resolver.ts';
14
+ export type { default as ResolveStrategy, ResolveStrategyOptions, } from '../../../resolve/strategies/ResolveStrategy.ts';
15
+ export type { default as BundleStrategy, BundleStrategyOptions } from '../BundleStrategy.ts';
16
+ export type { ComponentNamesStrategy, ComponentNameResolver, ComponentNameResolverArgs, ComponentNameCollisionSeverity, } from '../../../options/index.ts';
17
+ /**
18
+ * @public
19
+ */
20
+ export interface AsyncAPI2BundleStrategyOptions extends Omit<BundleStrategyOptions, 'name'> {
21
+ }
22
+ /**
23
+ * @public
24
+ */
25
+ declare class AsyncAPI2BundleStrategy extends BundleStrategy {
26
+ constructor(options?: AsyncAPI2BundleStrategyOptions);
27
+ canBundle(file: File): boolean;
28
+ bundle(file: File, options: ReferenceOptions): Promise<ParseResultElement>;
29
+ }
30
+ export { AsyncAPI2BundleVisitor };
31
+ export default AsyncAPI2BundleStrategy;
@@ -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;