@speclynx/apidom-datamodel 1.12.2
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.
- package/LICENSES/AFL-3.0.txt +182 -0
- package/LICENSES/Apache-2.0.txt +202 -0
- package/LICENSES/BSD-3-Clause.txt +26 -0
- package/LICENSES/MIT.txt +9 -0
- package/NOTICE +74 -0
- package/README.md +479 -0
- package/dist/apidom-datamodel.browser.js +2717 -0
- package/dist/apidom-datamodel.browser.min.js +1 -0
- package/package.json +53 -0
- package/src/KeyValuePair.cjs +38 -0
- package/src/KeyValuePair.mjs +34 -0
- package/src/Namespace.cjs +212 -0
- package/src/Namespace.mjs +206 -0
- package/src/ObjectSlice.cjs +206 -0
- package/src/ObjectSlice.mjs +202 -0
- package/src/elements/LinkElement.cjs +44 -0
- package/src/elements/LinkElement.mjs +39 -0
- package/src/elements/RefElement.cjs +31 -0
- package/src/elements/RefElement.mjs +26 -0
- package/src/index.cjs +25 -0
- package/src/index.mjs +6 -0
- package/src/primitives/ArrayElement.cjs +176 -0
- package/src/primitives/ArrayElement.mjs +169 -0
- package/src/primitives/BooleanElement.cjs +20 -0
- package/src/primitives/BooleanElement.mjs +15 -0
- package/src/primitives/CollectionElement.cjs +194 -0
- package/src/primitives/CollectionElement.mjs +187 -0
- package/src/primitives/Element.cjs +438 -0
- package/src/primitives/Element.mjs +433 -0
- package/src/primitives/MemberElement.cjs +54 -0
- package/src/primitives/MemberElement.mjs +49 -0
- package/src/primitives/NullElement.cjs +28 -0
- package/src/primitives/NullElement.mjs +23 -0
- package/src/primitives/NumberElement.cjs +20 -0
- package/src/primitives/NumberElement.mjs +15 -0
- package/src/primitives/ObjectElement.cjs +222 -0
- package/src/primitives/ObjectElement.mjs +216 -0
- package/src/primitives/StringElement.cjs +27 -0
- package/src/primitives/StringElement.mjs +22 -0
- package/src/registration.cjs +87 -0
- package/src/registration.mjs +70 -0
- package/src/serialisers/JSONSerialiser.cjs +144 -0
- package/src/serialisers/JSONSerialiser.mjs +140 -0
- package/src/types.cjs +3 -0
- package/src/types.mjs +1 -0
- package/types/apidom-datamodel.d.ts +887 -0
|
@@ -0,0 +1,887 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ArrayElement represents an array/collection of elements in ApiDOM.
|
|
3
|
+
*
|
|
4
|
+
* @typeParam T - The element type contained in the array, defaults to Element
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
export declare class ArrayElement<T extends Element_2 = Element_2> extends CollectionElement<T> {
|
|
8
|
+
static empty<T extends Element_2 = Element_2>(): ArrayElement<T>;
|
|
9
|
+
static 'fantasy-land/empty'<T extends Element_2 = Element_2>(): ArrayElement<T>;
|
|
10
|
+
constructor(content?: unknown[], meta?: Meta, attributes?: Attributes);
|
|
11
|
+
primitive(): string;
|
|
12
|
+
/**
|
|
13
|
+
* Gets the element at the specified index.
|
|
14
|
+
*/
|
|
15
|
+
get(index: number): T | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* Helper for returning the value of an item.
|
|
18
|
+
*/
|
|
19
|
+
getValue(index: number): unknown;
|
|
20
|
+
/**
|
|
21
|
+
* Sets the element at the specified index, or sets the content if called with one argument.
|
|
22
|
+
*/
|
|
23
|
+
set(indexOrContent: number | unknown, value?: unknown): this;
|
|
24
|
+
/**
|
|
25
|
+
* Removes the element at the specified index.
|
|
26
|
+
*/
|
|
27
|
+
remove(index: number): T | null;
|
|
28
|
+
/**
|
|
29
|
+
* Maps each element using the provided callback function.
|
|
30
|
+
*/
|
|
31
|
+
map<U>(callback: (element: T, index: number, array: T[]) => U, thisArg?: unknown): U[];
|
|
32
|
+
/**
|
|
33
|
+
* Maps and then flattens the results.
|
|
34
|
+
*/
|
|
35
|
+
flatMap<U>(callback: (element: T, index: number, array: T[]) => U | U[], thisArg?: unknown): U[];
|
|
36
|
+
/**
|
|
37
|
+
* Returns an array containing the truthy results of calling the given transformation.
|
|
38
|
+
*/
|
|
39
|
+
compactMap<U>(transform: (element: T) => U | undefined | null, thisArg?: unknown): U[];
|
|
40
|
+
/**
|
|
41
|
+
* Filters elements using the provided callback.
|
|
42
|
+
*/
|
|
43
|
+
filter(callback: (element: T) => boolean, thisArg?: unknown): ArrayElement<T>;
|
|
44
|
+
/**
|
|
45
|
+
* Rejects elements that match the provided callback.
|
|
46
|
+
*/
|
|
47
|
+
reject(callback: (element: T) => boolean, thisArg?: unknown): ArrayElement<T>;
|
|
48
|
+
/**
|
|
49
|
+
* Reduces the array to a single value.
|
|
50
|
+
* This is a reduce function specifically for datamodel arrays and objects.
|
|
51
|
+
* It allows for returning normal values or datamodel instances.
|
|
52
|
+
*/
|
|
53
|
+
reduce<U>(callback: (memo: U, item: T, index: number, arr: this) => U, initialValue?: U): U;
|
|
54
|
+
/**
|
|
55
|
+
* Executes a provided function once for each element.
|
|
56
|
+
*/
|
|
57
|
+
forEach(callback: (element: T, index: number) => void, thisArg?: unknown): void;
|
|
58
|
+
/**
|
|
59
|
+
* Returns an empty array element.
|
|
60
|
+
*/
|
|
61
|
+
empty(): ArrayElement<T>;
|
|
62
|
+
'fantasy-land/map'(transform: (element: T) => T): ArrayElement<T>;
|
|
63
|
+
'fantasy-land/chain'(transform: (element: T) => ArrayElement<T>): ArrayElement<T>;
|
|
64
|
+
'fantasy-land/filter'(callback: (element: T) => boolean): ArrayElement<T>;
|
|
65
|
+
'fantasy-land/reduce'<U>(transform: (acc: U, element: T) => U, initialValue: U): U;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Attributes associated with an element.
|
|
70
|
+
* Can be a plain object or an ObjectElement.
|
|
71
|
+
* Attributes are element-specific properties beyond the standard meta.
|
|
72
|
+
* @public
|
|
73
|
+
*/
|
|
74
|
+
export declare type Attributes = Record<string, unknown> | ObjectElement;
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* BooleanElement represents a boolean value in ApiDOM.
|
|
78
|
+
* @public
|
|
79
|
+
*/
|
|
80
|
+
export declare class BooleanElement extends Element_2 {
|
|
81
|
+
constructor(content?: boolean, meta?: Meta, attributes?: Attributes);
|
|
82
|
+
primitive(): string;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Type for cloneable objects.
|
|
87
|
+
* @public
|
|
88
|
+
*/
|
|
89
|
+
export declare interface Cloneable<T> {
|
|
90
|
+
clone(): T;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* CollectionElement is an abstract base class for collection-like elements.
|
|
95
|
+
* Both ArrayElement and ObjectElement extend this class.
|
|
96
|
+
*
|
|
97
|
+
* This class contains the shared functionality between arrays and objects,
|
|
98
|
+
* while keeping the conflicting methods (get, set, remove, map, filter, etc.)
|
|
99
|
+
* in the respective subclasses.
|
|
100
|
+
*
|
|
101
|
+
* @remarks
|
|
102
|
+
* This is primarily an implementation detail. Use ArrayElement or ObjectElement directly.
|
|
103
|
+
*
|
|
104
|
+
* @typeParam T - The element type contained in the collection, defaults to Element
|
|
105
|
+
* @public
|
|
106
|
+
*/
|
|
107
|
+
export declare abstract class CollectionElement<T extends Element_2 = Element_2> extends Element_2 {
|
|
108
|
+
protected _content: T[];
|
|
109
|
+
constructor(content?: unknown[], meta?: Meta, attributes?: Attributes);
|
|
110
|
+
/**
|
|
111
|
+
* Returns the length of the collection.
|
|
112
|
+
*/
|
|
113
|
+
get length(): number;
|
|
114
|
+
/**
|
|
115
|
+
* Returns whether the collection is empty.
|
|
116
|
+
*/
|
|
117
|
+
get isEmpty(): boolean;
|
|
118
|
+
/**
|
|
119
|
+
* Return the first item in the collection.
|
|
120
|
+
*/
|
|
121
|
+
get first(): T | undefined;
|
|
122
|
+
/**
|
|
123
|
+
* Return the second item in the collection.
|
|
124
|
+
*/
|
|
125
|
+
get second(): T | undefined;
|
|
126
|
+
/**
|
|
127
|
+
* Return the last item in the collection.
|
|
128
|
+
*/
|
|
129
|
+
get last(): T | undefined;
|
|
130
|
+
/**
|
|
131
|
+
* Adds the given element to the end of the collection.
|
|
132
|
+
*/
|
|
133
|
+
push(value: unknown): this;
|
|
134
|
+
/**
|
|
135
|
+
* Alias for push.
|
|
136
|
+
*/
|
|
137
|
+
add(value: unknown): void;
|
|
138
|
+
/**
|
|
139
|
+
* Removes the first element from the collection.
|
|
140
|
+
*/
|
|
141
|
+
shift(): T | undefined;
|
|
142
|
+
/**
|
|
143
|
+
* Adds the given element to the beginning of the collection.
|
|
144
|
+
*/
|
|
145
|
+
unshift(value: unknown): void;
|
|
146
|
+
/**
|
|
147
|
+
* Looks for matching children using deep equality.
|
|
148
|
+
*/
|
|
149
|
+
includes(value: unknown): boolean;
|
|
150
|
+
/**
|
|
151
|
+
* Recursively search all descendants using a condition function.
|
|
152
|
+
*/
|
|
153
|
+
findElements(condition: FindCondition, givenOptions?: FindOptions): Element_2[];
|
|
154
|
+
/**
|
|
155
|
+
* Recursively search all descendants using a condition function.
|
|
156
|
+
*/
|
|
157
|
+
find(condition: FindCondition): ArrayElement;
|
|
158
|
+
/**
|
|
159
|
+
* Find elements by their element type name.
|
|
160
|
+
*/
|
|
161
|
+
findByElement(element: string): ArrayElement;
|
|
162
|
+
/**
|
|
163
|
+
* Find elements by class name.
|
|
164
|
+
*/
|
|
165
|
+
findByClass(className: string): ArrayElement;
|
|
166
|
+
/**
|
|
167
|
+
* Search the tree recursively and find the element with the matching ID.
|
|
168
|
+
*/
|
|
169
|
+
getById(id: string): Element_2 | undefined;
|
|
170
|
+
/**
|
|
171
|
+
* Returns an empty collection element.
|
|
172
|
+
*/
|
|
173
|
+
abstract empty(): CollectionElement<T>;
|
|
174
|
+
'fantasy-land/empty'(): CollectionElement<T>;
|
|
175
|
+
/**
|
|
176
|
+
* Concatenates two collection elements.
|
|
177
|
+
*/
|
|
178
|
+
concat(other: CollectionElement<T>): CollectionElement<T>;
|
|
179
|
+
'fantasy-land/concat'(other: CollectionElement<T>): CollectionElement<T>;
|
|
180
|
+
[Symbol.iterator](): IterableIterator<T>;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Tuple of detection test and element class.
|
|
185
|
+
* @public
|
|
186
|
+
*/
|
|
187
|
+
export declare type DetectionEntry = [DetectionTest, ElementClass];
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Function to test if a value should be converted to a specific element type.
|
|
191
|
+
* @public
|
|
192
|
+
*/
|
|
193
|
+
export declare type DetectionTest = (value: unknown) => boolean;
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Base Element class that all ApiDOM elements extend.
|
|
197
|
+
*
|
|
198
|
+
* Elements are the core building blocks of ApiDOM. Each element has:
|
|
199
|
+
* - An `element` property identifying its type
|
|
200
|
+
* - Optional `content` holding the element's value
|
|
201
|
+
* - Optional `meta` for metadata (id, classes, title, description, links)
|
|
202
|
+
* - Optional `attributes` for element-specific properties
|
|
203
|
+
*
|
|
204
|
+
* @public
|
|
205
|
+
*/
|
|
206
|
+
declare class Element_2 implements Cloneable<Element_2>, ToValue, Equatable, Freezable {
|
|
207
|
+
/**
|
|
208
|
+
* The element type identifier.
|
|
209
|
+
* @internal
|
|
210
|
+
*/
|
|
211
|
+
protected _storedElement: string;
|
|
212
|
+
/**
|
|
213
|
+
* The element's content/value.
|
|
214
|
+
* @internal
|
|
215
|
+
*/
|
|
216
|
+
protected _content?: ElementContent;
|
|
217
|
+
/**
|
|
218
|
+
* Metadata about this element.
|
|
219
|
+
* @internal
|
|
220
|
+
*/
|
|
221
|
+
protected _meta?: Element_2;
|
|
222
|
+
/**
|
|
223
|
+
* Element-specific attributes.
|
|
224
|
+
* @internal
|
|
225
|
+
*/
|
|
226
|
+
protected _attributes?: Element_2;
|
|
227
|
+
/**
|
|
228
|
+
* Parent element reference (set when tree is frozen).
|
|
229
|
+
*/
|
|
230
|
+
parent?: Element_2;
|
|
231
|
+
/** @internal ObjectElement constructor for creating meta/attributes */
|
|
232
|
+
ObjectElement: new (content?: Record<string, unknown>) => ObjectElement;
|
|
233
|
+
/** @internal ArrayElement constructor for creating arrays */
|
|
234
|
+
ArrayElement: new (content?: Element_2[]) => ArrayElement;
|
|
235
|
+
/** @internal MemberElement constructor for creating object members */
|
|
236
|
+
MemberElement: new (key?: unknown, value?: unknown) => Element_2;
|
|
237
|
+
/** @internal RefElement constructor for creating references */
|
|
238
|
+
RefElement: new (content?: unknown) => Element_2 & {
|
|
239
|
+
path?: Element_2;
|
|
240
|
+
};
|
|
241
|
+
/** @internal Function to convert values to elements */
|
|
242
|
+
refract: (value: unknown) => Element_2;
|
|
243
|
+
constructor(content?: unknown, meta?: Meta, attributes?: Attributes);
|
|
244
|
+
/**
|
|
245
|
+
* The element type identifier (e.g., 'string', 'object', 'array').
|
|
246
|
+
*/
|
|
247
|
+
get element(): string;
|
|
248
|
+
set element(value: string);
|
|
249
|
+
/**
|
|
250
|
+
* The element's content/value.
|
|
251
|
+
*/
|
|
252
|
+
get content(): ElementContent;
|
|
253
|
+
set content(value: unknown);
|
|
254
|
+
/**
|
|
255
|
+
* Metadata about this element (id, classes, title, description, links).
|
|
256
|
+
* Lazily creates an ObjectElement if not set.
|
|
257
|
+
*/
|
|
258
|
+
get meta(): ObjectElement;
|
|
259
|
+
set meta(value: Meta);
|
|
260
|
+
/**
|
|
261
|
+
* Element-specific attributes.
|
|
262
|
+
* Lazily creates an ObjectElement if not set.
|
|
263
|
+
*/
|
|
264
|
+
get attributes(): ObjectElement;
|
|
265
|
+
set attributes(value: Attributes);
|
|
266
|
+
/** Unique identifier for this element. */
|
|
267
|
+
get id(): Element_2;
|
|
268
|
+
set id(value: Element_2 | string);
|
|
269
|
+
/** CSS-like class names. */
|
|
270
|
+
get classes(): Element_2;
|
|
271
|
+
set classes(value: Element_2 | unknown[]);
|
|
272
|
+
/** Human-readable title. */
|
|
273
|
+
get title(): Element_2;
|
|
274
|
+
set title(value: Element_2 | string);
|
|
275
|
+
/** Human-readable description. */
|
|
276
|
+
get description(): Element_2;
|
|
277
|
+
set description(value: Element_2 | string);
|
|
278
|
+
/** Hyperlinks associated with this element. */
|
|
279
|
+
get links(): Element_2;
|
|
280
|
+
set links(value: Element_2 | unknown[]);
|
|
281
|
+
/** Returns direct children of this element. */
|
|
282
|
+
get children(): Element_2[];
|
|
283
|
+
/** Whether this element is frozen (immutable). */
|
|
284
|
+
get isFrozen(): boolean;
|
|
285
|
+
/**
|
|
286
|
+
* Freezes the element tree, making it immutable.
|
|
287
|
+
* Sets up parent references for tree traversal.
|
|
288
|
+
*/
|
|
289
|
+
freeze(): void;
|
|
290
|
+
/**
|
|
291
|
+
* Creates a deep clone of this element.
|
|
292
|
+
*/
|
|
293
|
+
clone(): Element_2;
|
|
294
|
+
/**
|
|
295
|
+
* Converts the element to its JavaScript value representation.
|
|
296
|
+
*/
|
|
297
|
+
toValue(): unknown;
|
|
298
|
+
/**
|
|
299
|
+
* Checks deep equality with another value.
|
|
300
|
+
*/
|
|
301
|
+
equals(value: unknown): boolean;
|
|
302
|
+
/**
|
|
303
|
+
* Returns the primitive type name for this element.
|
|
304
|
+
* Override in subclasses (e.g., 'string', 'number', 'array').
|
|
305
|
+
*/
|
|
306
|
+
primitive(): string | undefined;
|
|
307
|
+
/**
|
|
308
|
+
* Sets the content of this element.
|
|
309
|
+
* @returns this for chaining
|
|
310
|
+
*/
|
|
311
|
+
set(content: unknown): this;
|
|
312
|
+
/**
|
|
313
|
+
* Creates a RefElement pointing to this element.
|
|
314
|
+
* @param path - Optional path within the referenced element
|
|
315
|
+
* @throws Error if this element has no ID
|
|
316
|
+
*/
|
|
317
|
+
toRef(path?: string): Element_2;
|
|
318
|
+
/**
|
|
319
|
+
* Gets a meta property, creating it with default value if not present.
|
|
320
|
+
*/
|
|
321
|
+
protected getMetaProperty(name: string, defaultValue: unknown): Element_2;
|
|
322
|
+
/**
|
|
323
|
+
* Sets a meta property.
|
|
324
|
+
*/
|
|
325
|
+
protected setMetaProperty(name: string, value: unknown): void;
|
|
326
|
+
}
|
|
327
|
+
export { Element_2 as Element }
|
|
328
|
+
|
|
329
|
+
/**
|
|
330
|
+
* Constructor type for Element classes.
|
|
331
|
+
* @public
|
|
332
|
+
*/
|
|
333
|
+
export declare type ElementClass = new (...args: any[]) => Element_2;
|
|
334
|
+
|
|
335
|
+
/**
|
|
336
|
+
* Valid content types for an Element.
|
|
337
|
+
* @public
|
|
338
|
+
*/
|
|
339
|
+
export declare type ElementContent = Element_2 | Element_2[] | KeyValuePair | string | number | bigint | symbol | boolean | null | undefined;
|
|
340
|
+
|
|
341
|
+
/**
|
|
342
|
+
* Map of registered element classes.
|
|
343
|
+
* @public
|
|
344
|
+
*/
|
|
345
|
+
export declare interface ElementsMap {
|
|
346
|
+
Element: ElementClass;
|
|
347
|
+
[key: string]: ElementClass;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
/**
|
|
351
|
+
* Type for objects that support deep equality comparison.
|
|
352
|
+
* @public
|
|
353
|
+
*/
|
|
354
|
+
export declare interface Equatable {
|
|
355
|
+
equals(value: unknown): boolean;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
/**
|
|
359
|
+
* Condition function for finding elements.
|
|
360
|
+
* @public
|
|
361
|
+
*/
|
|
362
|
+
export declare type FindCondition = (item: Element_2, keyOrIndex: Element_2 | number, member?: Element_2) => boolean;
|
|
363
|
+
|
|
364
|
+
/**
|
|
365
|
+
* Options for finding elements.
|
|
366
|
+
* @public
|
|
367
|
+
*/
|
|
368
|
+
export declare interface FindOptions {
|
|
369
|
+
recursive?: boolean;
|
|
370
|
+
results?: Element_2[];
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
/**
|
|
374
|
+
* Type for freezable objects (immutable after freeze).
|
|
375
|
+
* @public
|
|
376
|
+
*/
|
|
377
|
+
export declare interface Freezable {
|
|
378
|
+
freeze(): void;
|
|
379
|
+
readonly isFrozen: boolean;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
/**
|
|
383
|
+
* JSONSerialiser handles serialization and deserialization of ApiDOM elements
|
|
384
|
+
* to and from JSON Refract format.
|
|
385
|
+
* @public
|
|
386
|
+
*/
|
|
387
|
+
export declare class JSONSerialiser {
|
|
388
|
+
namespace: Namespace;
|
|
389
|
+
Namespace: typeof Namespace;
|
|
390
|
+
constructor(namespace?: Namespace);
|
|
391
|
+
/**
|
|
392
|
+
* Serializes an Element to JSON Refract format.
|
|
393
|
+
*/
|
|
394
|
+
serialise(element: Element_2): SerializedElement;
|
|
395
|
+
/**
|
|
396
|
+
* Deserializes a JSON Refract document to an Element.
|
|
397
|
+
*/
|
|
398
|
+
deserialise(value: RefractDocument): Element_2;
|
|
399
|
+
protected serialiseContent(content: unknown): SerializedContent;
|
|
400
|
+
protected deserialiseContent(content: unknown): unknown;
|
|
401
|
+
protected serialiseObject(obj: ObjectElement): Record<string, SerializedElement> | undefined;
|
|
402
|
+
protected deserialiseObject(from: Record<string, RefractDocument>, to: ObjectElement): void;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
/**
|
|
406
|
+
* Represents a key-value pair used in MemberElement content.
|
|
407
|
+
* This is used internally to store object member data.
|
|
408
|
+
*
|
|
409
|
+
* @typeParam K - Key element type
|
|
410
|
+
* @typeParam V - Value element type
|
|
411
|
+
* @public
|
|
412
|
+
*/
|
|
413
|
+
export declare class KeyValuePair<K extends Element_2 = Element_2, V extends Element_2 = Element_2> implements Cloneable<KeyValuePair<K, V>> {
|
|
414
|
+
key: K | undefined;
|
|
415
|
+
value: V | undefined;
|
|
416
|
+
constructor(key?: K, value?: V);
|
|
417
|
+
/**
|
|
418
|
+
* Creates a deep clone of the KeyValuePair.
|
|
419
|
+
*/
|
|
420
|
+
clone(): KeyValuePair<K, V>;
|
|
421
|
+
/**
|
|
422
|
+
* Converts to a plain JavaScript object representation.
|
|
423
|
+
*/
|
|
424
|
+
toValue(): {
|
|
425
|
+
key: unknown;
|
|
426
|
+
value: unknown;
|
|
427
|
+
};
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
/**
|
|
431
|
+
* LinkElement represents a hyperlink in ApiDOM.
|
|
432
|
+
*
|
|
433
|
+
* Hyperlinking MAY be used to link to other resources, provide links to
|
|
434
|
+
* instructions on how to process a given element (by way of a profile or
|
|
435
|
+
* other means), and may be used to provide meta data about the element in
|
|
436
|
+
* which it's found. The meaning and purpose of the hyperlink is defined by
|
|
437
|
+
* the link relation according to RFC 5988.
|
|
438
|
+
*
|
|
439
|
+
* @public
|
|
440
|
+
*/
|
|
441
|
+
export declare class LinkElement extends Element_2 {
|
|
442
|
+
constructor(content?: unknown, meta?: Meta, attributes?: Attributes);
|
|
443
|
+
/**
|
|
444
|
+
* The relation identifier for the link, as defined in RFC 5988.
|
|
445
|
+
*/
|
|
446
|
+
get relation(): Element_2 | undefined;
|
|
447
|
+
set relation(relation: string | Element_2 | undefined);
|
|
448
|
+
/**
|
|
449
|
+
* The URI for the given link.
|
|
450
|
+
*/
|
|
451
|
+
get href(): Element_2 | undefined;
|
|
452
|
+
set href(href: string | Element_2 | undefined);
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
/**
|
|
456
|
+
* MemberElement represents a key-value pair member in an ObjectElement.
|
|
457
|
+
*
|
|
458
|
+
* The member's content is always a KeyValuePair containing:
|
|
459
|
+
* - `key`: The key element (typically a StringElement)
|
|
460
|
+
* - `value`: The value element (any Element type)
|
|
461
|
+
*
|
|
462
|
+
* @typeParam K - The key element type, defaults to Element
|
|
463
|
+
* @typeParam V - The value element type, defaults to Element
|
|
464
|
+
* @public
|
|
465
|
+
*/
|
|
466
|
+
export declare class MemberElement<K extends Element_2 = Element_2, V extends Element_2 = Element_2> extends Element_2 {
|
|
467
|
+
protected _content: KeyValuePair;
|
|
468
|
+
constructor(key?: unknown, value?: unknown, meta?: Meta, attributes?: Attributes);
|
|
469
|
+
primitive(): string;
|
|
470
|
+
/**
|
|
471
|
+
* The key element of this member.
|
|
472
|
+
*/
|
|
473
|
+
get key(): K | undefined;
|
|
474
|
+
set key(value: unknown);
|
|
475
|
+
/**
|
|
476
|
+
* The value element of this member.
|
|
477
|
+
*/
|
|
478
|
+
get value(): V | undefined;
|
|
479
|
+
set value(value: unknown);
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
/**
|
|
483
|
+
* Metadata associated with an element.
|
|
484
|
+
* Can be a plain object or an ObjectElement.
|
|
485
|
+
* Common meta properties include: id, classes, title, description, links.
|
|
486
|
+
* @public
|
|
487
|
+
*/
|
|
488
|
+
export declare type Meta = Record<string, unknown> | ObjectElement;
|
|
489
|
+
|
|
490
|
+
/**
|
|
491
|
+
* A refract element implementation with an extensible namespace, able to
|
|
492
|
+
* load other namespaces into it.
|
|
493
|
+
*
|
|
494
|
+
* The namespace allows you to register your own classes to be instantiated
|
|
495
|
+
* when a particular refract element is encountered, and allows you to specify
|
|
496
|
+
* which elements get instantiated for existing JavaScript objects.
|
|
497
|
+
*
|
|
498
|
+
* @public
|
|
499
|
+
*/
|
|
500
|
+
export declare class Namespace {
|
|
501
|
+
elementMap: Record<string, ElementClass>;
|
|
502
|
+
elementDetection: DetectionEntry[];
|
|
503
|
+
Element: typeof Element_2;
|
|
504
|
+
KeyValuePair: typeof KeyValuePair;
|
|
505
|
+
protected _elements?: ElementsMap;
|
|
506
|
+
protected _attributeElementKeys: string[];
|
|
507
|
+
protected _attributeElementArrayKeys: string[];
|
|
508
|
+
constructor(options?: NamespaceOptions);
|
|
509
|
+
/**
|
|
510
|
+
* Use a namespace plugin or load a generic plugin.
|
|
511
|
+
*/
|
|
512
|
+
use(plugin: NamespacePlugin): this;
|
|
513
|
+
/**
|
|
514
|
+
* Use the default namespace. This preloads all the default elements
|
|
515
|
+
* into this registry instance.
|
|
516
|
+
*/
|
|
517
|
+
useDefault(): this;
|
|
518
|
+
/**
|
|
519
|
+
* Register a new element class for an element.
|
|
520
|
+
*/
|
|
521
|
+
register(name: string, ElementClass: ElementClass): this;
|
|
522
|
+
/**
|
|
523
|
+
* Unregister a previously registered class for an element.
|
|
524
|
+
*/
|
|
525
|
+
unregister(name: string): this;
|
|
526
|
+
/**
|
|
527
|
+
* Add a new detection function to determine which element
|
|
528
|
+
* class to use when converting existing JS instances into
|
|
529
|
+
* refract elements.
|
|
530
|
+
*/
|
|
531
|
+
detect(test: DetectionTest, ElementClass: ElementClass, givenPrepend?: boolean): this;
|
|
532
|
+
/**
|
|
533
|
+
* Convert an existing JavaScript object into refract element instances.
|
|
534
|
+
* If the item passed in is already refracted, then it is returned unmodified.
|
|
535
|
+
*/
|
|
536
|
+
toElement(value: unknown): Element_2 | undefined;
|
|
537
|
+
/**
|
|
538
|
+
* Get an element class given an element name.
|
|
539
|
+
*/
|
|
540
|
+
getElementClass(element: string): ElementClass;
|
|
541
|
+
/**
|
|
542
|
+
* Convert a refract document into refract element instances.
|
|
543
|
+
*/
|
|
544
|
+
fromRefract(doc: Record<string, unknown>): Element_2;
|
|
545
|
+
/**
|
|
546
|
+
* Convert an element to a Refracted JSON object.
|
|
547
|
+
*/
|
|
548
|
+
toRefract(element: Element_2): ReturnType<JSONSerialiser['serialise']>;
|
|
549
|
+
/**
|
|
550
|
+
* Get an object that contains all registered element classes, where
|
|
551
|
+
* the key is the PascalCased element name and the value is the class.
|
|
552
|
+
*/
|
|
553
|
+
get elements(): ElementsMap;
|
|
554
|
+
/**
|
|
555
|
+
* Convenience method for getting a JSON Serialiser configured with the
|
|
556
|
+
* current namespace.
|
|
557
|
+
*/
|
|
558
|
+
get serialiser(): JSONSerialiser;
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
/**
|
|
562
|
+
* Options for Namespace constructor.
|
|
563
|
+
* @public
|
|
564
|
+
*/
|
|
565
|
+
export declare interface NamespaceOptions {
|
|
566
|
+
noDefault?: boolean;
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
/**
|
|
570
|
+
* Plugin interface for extending Namespace.
|
|
571
|
+
* @public
|
|
572
|
+
*/
|
|
573
|
+
export declare interface NamespacePlugin {
|
|
574
|
+
namespace?: (options: {
|
|
575
|
+
base: Namespace;
|
|
576
|
+
}) => void;
|
|
577
|
+
load?: (options: {
|
|
578
|
+
base: Namespace;
|
|
579
|
+
}) => void;
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
/**
|
|
583
|
+
* NullElement represents a null value in ApiDOM.
|
|
584
|
+
* @public
|
|
585
|
+
*/
|
|
586
|
+
export declare class NullElement extends Element_2 {
|
|
587
|
+
constructor(content?: null, meta?: Meta, attributes?: Attributes);
|
|
588
|
+
primitive(): string;
|
|
589
|
+
/**
|
|
590
|
+
* NullElement cannot have its value changed.
|
|
591
|
+
* @throws Error - NullElement value cannot be modified
|
|
592
|
+
*/
|
|
593
|
+
set(_content?: unknown): this;
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
/**
|
|
597
|
+
* NumberElement represents a numeric value in ApiDOM.
|
|
598
|
+
* @public
|
|
599
|
+
*/
|
|
600
|
+
export declare class NumberElement extends Element_2 {
|
|
601
|
+
constructor(content?: number, meta?: Meta, attributes?: Attributes);
|
|
602
|
+
primitive(): string;
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
/**
|
|
606
|
+
* ObjectElement represents an object/dictionary of key-value pairs in ApiDOM.
|
|
607
|
+
*
|
|
608
|
+
* @typeParam K - The key element type, defaults to Element
|
|
609
|
+
* @typeParam V - The value element type, defaults to Element
|
|
610
|
+
* @public
|
|
611
|
+
*/
|
|
612
|
+
export declare class ObjectElement<K extends Element_2 = Element_2, V extends Element_2 = Element_2> extends CollectionElement<MemberElement<K, V>> {
|
|
613
|
+
constructor(content?: Record<string, unknown> | MemberElement<K, V>[], meta?: Meta, attributes?: Attributes);
|
|
614
|
+
primitive(): string;
|
|
615
|
+
toValue(): Record<string, unknown>;
|
|
616
|
+
/**
|
|
617
|
+
* Gets the value element for the given key.
|
|
618
|
+
*/
|
|
619
|
+
get(name: string): V | undefined;
|
|
620
|
+
/**
|
|
621
|
+
* Helper for returning the value of an item by key.
|
|
622
|
+
*/
|
|
623
|
+
getValue(name: string): unknown;
|
|
624
|
+
/**
|
|
625
|
+
* Gets the member element for the given key.
|
|
626
|
+
*/
|
|
627
|
+
getMember(name: string | undefined): MemberElement<K, V> | undefined;
|
|
628
|
+
/**
|
|
629
|
+
* Removes the member with the given key.
|
|
630
|
+
*/
|
|
631
|
+
remove(name: string): MemberElement<K, V> | null;
|
|
632
|
+
/**
|
|
633
|
+
* Gets the key element for the given key name.
|
|
634
|
+
*/
|
|
635
|
+
getKey(name: string): K | undefined;
|
|
636
|
+
/**
|
|
637
|
+
* Set allows either a key/value pair to be given or an object.
|
|
638
|
+
* If an object is given, each key is set to its respective value.
|
|
639
|
+
*/
|
|
640
|
+
set(keyOrObject: string | Record<string, unknown>, value?: unknown): this;
|
|
641
|
+
/**
|
|
642
|
+
* Returns an array of all keys' values.
|
|
643
|
+
*/
|
|
644
|
+
keys(): unknown[];
|
|
645
|
+
/**
|
|
646
|
+
* Returns an array of all values' values.
|
|
647
|
+
*/
|
|
648
|
+
values(): unknown[];
|
|
649
|
+
/**
|
|
650
|
+
* Returns whether the object has the given key.
|
|
651
|
+
*/
|
|
652
|
+
hasKey(value: string): boolean;
|
|
653
|
+
/**
|
|
654
|
+
* Returns an array of [key, value] pairs.
|
|
655
|
+
*/
|
|
656
|
+
items(): [unknown, unknown][];
|
|
657
|
+
/**
|
|
658
|
+
* Maps over the member elements, calling callback with (value, key, member).
|
|
659
|
+
*/
|
|
660
|
+
map<U>(callback: ObjectElementCallback<K, V, U>, thisArg?: unknown): U[];
|
|
661
|
+
/**
|
|
662
|
+
* Returns an array containing the truthy results of calling the given transformation.
|
|
663
|
+
*/
|
|
664
|
+
compactMap<U>(callback: ObjectElementCallback<K, V, U | undefined | null>, thisArg?: unknown): U[];
|
|
665
|
+
/**
|
|
666
|
+
* Filters member elements using the provided callback.
|
|
667
|
+
*/
|
|
668
|
+
filter(callback: ObjectElementCallback<K, V, boolean>, thisArg?: unknown): ObjectSlice;
|
|
669
|
+
/**
|
|
670
|
+
* Rejects member elements that match the provided callback.
|
|
671
|
+
*/
|
|
672
|
+
reject(callback: ObjectElementCallback<K, V, boolean>, thisArg?: unknown): ObjectSlice;
|
|
673
|
+
/**
|
|
674
|
+
* Executes a provided function once for each member element.
|
|
675
|
+
*/
|
|
676
|
+
forEach(callback: (value: V, key: K, member: MemberElement<K, V>) => void, thisArg?: unknown): void;
|
|
677
|
+
/**
|
|
678
|
+
* Reduces the object to a single value.
|
|
679
|
+
* Callback receives (memo, value, key, member, obj).
|
|
680
|
+
*/
|
|
681
|
+
reduce<U>(callback: (memo: U, value: V, key: K, member: MemberElement<K, V>, obj: this) => U, initialValue?: U): U;
|
|
682
|
+
/**
|
|
683
|
+
* Returns an empty object element.
|
|
684
|
+
*/
|
|
685
|
+
empty(): ObjectElement<K, V>;
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
/**
|
|
689
|
+
* Callback type for ObjectElement iteration methods.
|
|
690
|
+
* @public
|
|
691
|
+
*/
|
|
692
|
+
export declare type ObjectElementCallback<K extends Element_2, V extends Element_2, U> = (value: V, key: K, member: MemberElement<K, V>) => U;
|
|
693
|
+
|
|
694
|
+
/**
|
|
695
|
+
* ObjectSlice is a collection wrapper for MemberElement arrays.
|
|
696
|
+
* It provides functional methods with (value, key, member) callback signatures,
|
|
697
|
+
* which is the standard pattern for iterating over object-like structures.
|
|
698
|
+
*
|
|
699
|
+
* Unlike ArraySlice, ObjectSlice uses composition rather than inheritance
|
|
700
|
+
* because its callback signatures are fundamentally different.
|
|
701
|
+
*
|
|
702
|
+
* @public
|
|
703
|
+
*/
|
|
704
|
+
export declare class ObjectSlice {
|
|
705
|
+
readonly elements: MemberElement[];
|
|
706
|
+
constructor(elements?: MemberElement[]);
|
|
707
|
+
/**
|
|
708
|
+
* Converts all member elements to their JavaScript values.
|
|
709
|
+
* Returns an array of \{ key, value \} objects.
|
|
710
|
+
*/
|
|
711
|
+
toValue(): Array<{
|
|
712
|
+
key: unknown;
|
|
713
|
+
value: unknown;
|
|
714
|
+
}>;
|
|
715
|
+
/**
|
|
716
|
+
* Maps over the member elements, calling callback with (value, key, member).
|
|
717
|
+
* @param callback - Function to execute for each member
|
|
718
|
+
* @param thisArg - Value to use as this when executing callback
|
|
719
|
+
*/
|
|
720
|
+
map<U>(callback: ObjectSliceCallback<U>, thisArg?: unknown): U[];
|
|
721
|
+
/**
|
|
722
|
+
* Filters member elements using the provided callback.
|
|
723
|
+
* @param callback - Function that receives (value, key, member) and returns boolean
|
|
724
|
+
* @param thisArg - Value to use as this when executing callback
|
|
725
|
+
*/
|
|
726
|
+
filter(callback: ObjectSliceCallback<boolean>, thisArg?: unknown): ObjectSlice;
|
|
727
|
+
/**
|
|
728
|
+
* Rejects member elements that match the provided callback.
|
|
729
|
+
* @param callback - Function that receives (value, key, member) and returns boolean
|
|
730
|
+
* @param thisArg - Value to use as this when executing callback
|
|
731
|
+
*/
|
|
732
|
+
reject(callback: ObjectSliceCallback<boolean>, thisArg?: unknown): ObjectSlice;
|
|
733
|
+
/**
|
|
734
|
+
* Executes a provided function once for each member element.
|
|
735
|
+
* @param callback - Function that receives (value, key, member, index)
|
|
736
|
+
* @param thisArg - Value to use as this when executing callback
|
|
737
|
+
*/
|
|
738
|
+
forEach(callback: ObjectSliceForEachCallback, thisArg?: unknown): void;
|
|
739
|
+
/**
|
|
740
|
+
* Returns the first member element that satisfies the callback.
|
|
741
|
+
* @param callback - Function that receives (value, key, member) and returns boolean
|
|
742
|
+
* @param thisArg - Value to use as this when executing callback
|
|
743
|
+
*/
|
|
744
|
+
find(callback: ObjectSliceCallback<boolean>, thisArg?: unknown): MemberElement | undefined;
|
|
745
|
+
/**
|
|
746
|
+
* Returns an array of all keys' values.
|
|
747
|
+
*/
|
|
748
|
+
keys(): unknown[];
|
|
749
|
+
/**
|
|
750
|
+
* Returns an array of all values' values.
|
|
751
|
+
*/
|
|
752
|
+
values(): unknown[];
|
|
753
|
+
/**
|
|
754
|
+
* Returns the number of elements in the slice.
|
|
755
|
+
*/
|
|
756
|
+
get length(): number;
|
|
757
|
+
/**
|
|
758
|
+
* Returns whether the slice is empty.
|
|
759
|
+
*/
|
|
760
|
+
get isEmpty(): boolean;
|
|
761
|
+
/**
|
|
762
|
+
* Returns the first element in the slice or undefined if empty.
|
|
763
|
+
*/
|
|
764
|
+
get first(): MemberElement | undefined;
|
|
765
|
+
/**
|
|
766
|
+
* Gets the element at the specified index.
|
|
767
|
+
* @param index - The index of the element to get
|
|
768
|
+
*/
|
|
769
|
+
get(index: number): MemberElement | undefined;
|
|
770
|
+
/**
|
|
771
|
+
* Adds the given member element to the end of the slice.
|
|
772
|
+
* @param member - The member element to add
|
|
773
|
+
*/
|
|
774
|
+
push(member: MemberElement): this;
|
|
775
|
+
/**
|
|
776
|
+
* Creates a deep clone of the ObjectSlice.
|
|
777
|
+
*/
|
|
778
|
+
clone(): ObjectSlice;
|
|
779
|
+
/**
|
|
780
|
+
* Determines whether the slice includes a member with the given key value.
|
|
781
|
+
* @param keyValue - The key value to search for
|
|
782
|
+
*/
|
|
783
|
+
includesKey(keyValue: unknown): boolean;
|
|
784
|
+
/**
|
|
785
|
+
* Iterator support - allows for...of loops.
|
|
786
|
+
*/
|
|
787
|
+
[Symbol.iterator](): IterableIterator<MemberElement>;
|
|
788
|
+
}
|
|
789
|
+
|
|
790
|
+
/**
|
|
791
|
+
* Callback type for ObjectSlice iteration methods.
|
|
792
|
+
* Receives (value, key, member) - the standard pattern for object-like iteration.
|
|
793
|
+
* @public
|
|
794
|
+
*/
|
|
795
|
+
export declare type ObjectSliceCallback<U> = (value: Element_2, key: Element_2, member: MemberElement) => U;
|
|
796
|
+
|
|
797
|
+
/**
|
|
798
|
+
* Callback type for ObjectSlice forEach that also receives the index.
|
|
799
|
+
* @public
|
|
800
|
+
*/
|
|
801
|
+
export declare type ObjectSliceForEachCallback = (value: Element_2, key: Element_2, member: MemberElement, index: number) => void;
|
|
802
|
+
|
|
803
|
+
/**
|
|
804
|
+
* Primitive JavaScript values that can be element content.
|
|
805
|
+
* @public
|
|
806
|
+
*/
|
|
807
|
+
export declare type PrimitiveValue = string | number | boolean | null | undefined;
|
|
808
|
+
|
|
809
|
+
/**
|
|
810
|
+
* RefElement represents a reference to another element in ApiDOM.
|
|
811
|
+
* @public
|
|
812
|
+
*/
|
|
813
|
+
export declare class RefElement extends Element_2 {
|
|
814
|
+
constructor(content?: unknown, meta?: Meta, attributes?: Attributes);
|
|
815
|
+
/**
|
|
816
|
+
* Path of referenced element to transclude instead of element itself.
|
|
817
|
+
* @defaultValue 'element'
|
|
818
|
+
*/
|
|
819
|
+
get path(): Element_2 | undefined;
|
|
820
|
+
set path(newValue: string | Element_2 | undefined);
|
|
821
|
+
}
|
|
822
|
+
|
|
823
|
+
/**
|
|
824
|
+
* Refracts a JSON type to ApiDOM elements.
|
|
825
|
+
* @public
|
|
826
|
+
*/
|
|
827
|
+
export declare function refract(value: unknown): Element_2;
|
|
828
|
+
|
|
829
|
+
/**
|
|
830
|
+
* Input document format for deserialization.
|
|
831
|
+
* @public
|
|
832
|
+
*/
|
|
833
|
+
export declare interface RefractDocument {
|
|
834
|
+
element: string;
|
|
835
|
+
meta?: Record<string, unknown>;
|
|
836
|
+
attributes?: Record<string, unknown>;
|
|
837
|
+
content?: unknown;
|
|
838
|
+
}
|
|
839
|
+
|
|
840
|
+
/**
|
|
841
|
+
* Possible content types in a serialized element.
|
|
842
|
+
* @public
|
|
843
|
+
*/
|
|
844
|
+
export declare type SerializedContent = SerializedElement | SerializedElement[] | SerializedKeyValuePair | string | number | boolean | null | undefined;
|
|
845
|
+
|
|
846
|
+
/**
|
|
847
|
+
* Serialized representation of an Element in JSON Refract format.
|
|
848
|
+
* @public
|
|
849
|
+
*/
|
|
850
|
+
export declare interface SerializedElement {
|
|
851
|
+
element: string;
|
|
852
|
+
meta?: Record<string, SerializedElement>;
|
|
853
|
+
attributes?: Record<string, SerializedElement>;
|
|
854
|
+
content?: SerializedContent;
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
/**
|
|
858
|
+
* Serialized representation of a KeyValuePair in JSON Refract format.
|
|
859
|
+
* @public
|
|
860
|
+
*/
|
|
861
|
+
export declare interface SerializedKeyValuePair {
|
|
862
|
+
key: SerializedElement;
|
|
863
|
+
value?: SerializedElement;
|
|
864
|
+
}
|
|
865
|
+
|
|
866
|
+
/**
|
|
867
|
+
* StringElement represents a string value in ApiDOM.
|
|
868
|
+
* @public
|
|
869
|
+
*/
|
|
870
|
+
export declare class StringElement extends Element_2 {
|
|
871
|
+
constructor(content?: string, meta?: Meta, attributes?: Attributes);
|
|
872
|
+
primitive(): string;
|
|
873
|
+
/**
|
|
874
|
+
* The length of the string.
|
|
875
|
+
*/
|
|
876
|
+
get length(): number;
|
|
877
|
+
}
|
|
878
|
+
|
|
879
|
+
/**
|
|
880
|
+
* Type for objects that can convert to JavaScript values.
|
|
881
|
+
* @public
|
|
882
|
+
*/
|
|
883
|
+
export declare interface ToValue<T = unknown> {
|
|
884
|
+
toValue(): T;
|
|
885
|
+
}
|
|
886
|
+
|
|
887
|
+
export { }
|