@speclynx/apidom-datamodel 3.2.1 → 4.0.1

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 (64) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/package.json +3 -3
  3. package/src/KeyValuePair.cjs +0 -31
  4. package/src/KeyValuePair.mjs +0 -27
  5. package/src/Metadata.cjs +0 -91
  6. package/src/Metadata.mjs +0 -87
  7. package/src/Namespace.cjs +0 -212
  8. package/src/Namespace.mjs +0 -206
  9. package/src/ObjectSlice.cjs +0 -199
  10. package/src/ObjectSlice.mjs +0 -195
  11. package/src/clone/errors/CloneError.cjs +0 -22
  12. package/src/clone/errors/CloneError.mjs +0 -19
  13. package/src/clone/errors/DeepCloneError.cjs +0 -11
  14. package/src/clone/errors/DeepCloneError.mjs +0 -6
  15. package/src/clone/errors/ShallowCloneError.cjs +0 -11
  16. package/src/clone/errors/ShallowCloneError.mjs +0 -6
  17. package/src/clone/index.cjs +0 -188
  18. package/src/clone/index.mjs +0 -178
  19. package/src/elements/Annotation.cjs +0 -35
  20. package/src/elements/Annotation.mjs +0 -30
  21. package/src/elements/Comment.cjs +0 -18
  22. package/src/elements/Comment.mjs +0 -13
  23. package/src/elements/LinkElement.cjs +0 -50
  24. package/src/elements/LinkElement.mjs +0 -45
  25. package/src/elements/ParseResult.cjs +0 -91
  26. package/src/elements/ParseResult.mjs +0 -86
  27. package/src/elements/RefElement.cjs +0 -34
  28. package/src/elements/RefElement.mjs +0 -29
  29. package/src/elements/SourceMap.cjs +0 -140
  30. package/src/elements/SourceMap.mjs +0 -134
  31. package/src/elements/Style.cjs +0 -54
  32. package/src/elements/Style.mjs +0 -48
  33. package/src/index.cjs +0 -58
  34. package/src/index.mjs +0 -11
  35. package/src/predicates/elements.cjs +0 -46
  36. package/src/predicates/elements.mjs +0 -35
  37. package/src/predicates/index.cjs +0 -77
  38. package/src/predicates/index.mjs +0 -56
  39. package/src/predicates/primitives.cjs +0 -69
  40. package/src/predicates/primitives.mjs +0 -56
  41. package/src/primitives/ArrayElement.cjs +0 -155
  42. package/src/primitives/ArrayElement.mjs +0 -148
  43. package/src/primitives/BooleanElement.cjs +0 -20
  44. package/src/primitives/BooleanElement.mjs +0 -15
  45. package/src/primitives/CollectionElement.cjs +0 -180
  46. package/src/primitives/CollectionElement.mjs +0 -173
  47. package/src/primitives/Element.cjs +0 -510
  48. package/src/primitives/Element.mjs +0 -505
  49. package/src/primitives/MemberElement.cjs +0 -58
  50. package/src/primitives/MemberElement.mjs +0 -53
  51. package/src/primitives/NullElement.cjs +0 -28
  52. package/src/primitives/NullElement.mjs +0 -23
  53. package/src/primitives/NumberElement.cjs +0 -20
  54. package/src/primitives/NumberElement.mjs +0 -15
  55. package/src/primitives/ObjectElement.cjs +0 -220
  56. package/src/primitives/ObjectElement.mjs +0 -214
  57. package/src/primitives/StringElement.cjs +0 -27
  58. package/src/primitives/StringElement.mjs +0 -22
  59. package/src/registration.cjs +0 -101
  60. package/src/registration.mjs +0 -79
  61. package/src/serialisers/JSONSerialiser.cjs +0 -230
  62. package/src/serialisers/JSONSerialiser.mjs +0 -221
  63. package/src/types.cjs +0 -3
  64. package/src/types.mjs +0 -1
@@ -1,505 +0,0 @@
1
- import { equals } from 'ramda';
2
- import Metadata from "../Metadata.mjs";
3
- import KeyValuePair from "../KeyValuePair.mjs";
4
- import ObjectSlice from "../ObjectSlice.mjs"; // shared singleton for frozen elements with no meta — avoids allocation on every access
5
- const FROZEN_EMPTY_METADATA = Object.freeze(new Metadata());
6
-
7
- /**
8
- * Valid content types for an Element.
9
- * @public
10
- */
11
-
12
- /**
13
- * Base Element class that all ApiDOM elements extend.
14
- *
15
- * Elements are the core building blocks of ApiDOM. Each element has:
16
- * - An `element` property identifying its type
17
- * - Optional `content` holding the element's value
18
- * - Optional `meta` for metadata (id, classes, title, description, links)
19
- * - Optional `attributes` for element-specific properties
20
- *
21
- * @public
22
- */
23
- class Element {
24
- // ============================================================
25
- // Public Properties
26
- // ============================================================
27
-
28
- /**
29
- * Parent element reference (set when tree is frozen).
30
- */
31
- parent;
32
-
33
- /**
34
- * Format-specific style information for round-trip preservation.
35
- * Each format owns its own namespace (e.g., `yaml`, `json`).
36
- */
37
- style;
38
-
39
- // ============================================================================
40
- // Source Position (LSP-compatible, TextDocument-compatible, UTF-16 code units)
41
- // web-tree-sitter automatically provides position data in UTF-16 code units.
42
- // ============================================================================
43
-
44
- /**
45
- * Starting line number (0-based).
46
- * Compatible with LSP Position.line.
47
- */
48
- startLine;
49
-
50
- /**
51
- * Starting character offset within the line (0-based, UTF-16 code units).
52
- * Compatible with LSP Position.character.
53
- */
54
- startCharacter;
55
-
56
- /**
57
- * Starting offset from beginning of document (UTF-16 code units).
58
- * Can be used directly as JavaScript string index.
59
- */
60
- startOffset;
61
-
62
- /**
63
- * Ending line number (0-based).
64
- * Compatible with LSP Position.line.
65
- */
66
- endLine;
67
-
68
- /**
69
- * Ending character offset within the line (0-based, UTF-16 code units).
70
- * Compatible with LSP Position.character.
71
- */
72
- endCharacter;
73
-
74
- /**
75
- * Ending offset from beginning of document (UTF-16 code units).
76
- * Can be used directly as JavaScript string index.
77
- */
78
- endOffset;
79
-
80
- // ============================================================
81
- // Protected Properties
82
- // ============================================================
83
-
84
- /**
85
- * The element type identifier.
86
- * @internal
87
- */
88
- _storedElement = 'element';
89
-
90
- /**
91
- * The element's content/value.
92
- * @internal
93
- */
94
- _content;
95
-
96
- /**
97
- * Metadata about this element.
98
- * @internal
99
- */
100
- _meta;
101
-
102
- /**
103
- * Element-specific attributes.
104
- * @internal
105
- */
106
- _attributes;
107
-
108
- // ============================================================
109
- // Prototype-assigned properties (set in registration.ts)
110
- // Using 'declare' allows TypeScript to know about these
111
- // without generating runtime code.
112
- // ============================================================
113
-
114
- /** @internal ObjectElement constructor for creating meta/attributes */
115
-
116
- /** @internal ArrayElement constructor for creating arrays */
117
-
118
- /** @internal MemberElement constructor for creating object members */
119
-
120
- /** @internal RefElement constructor for creating references */
121
-
122
- /** @internal Function to convert values to elements */
123
-
124
- constructor(content, meta, attributes) {
125
- if (meta !== undefined) {
126
- this.meta = meta;
127
- }
128
- if (attributes !== undefined) {
129
- this.attributes = attributes;
130
- }
131
- if (content !== undefined) {
132
- this.content = content;
133
- }
134
- }
135
-
136
- // ============================================================
137
- // Core Properties
138
- // ============================================================
139
-
140
- /**
141
- * The element type identifier (e.g., 'string', 'object', 'array').
142
- */
143
- get element() {
144
- return this._storedElement;
145
- }
146
- set element(value) {
147
- this._storedElement = value;
148
- }
149
-
150
- /**
151
- * The element's content/value.
152
- */
153
- get content() {
154
- return this._content;
155
- }
156
- set content(value) {
157
- // Already an element
158
- if (value instanceof Element) {
159
- this._content = value;
160
- return;
161
- }
162
-
163
- // Primitives (inlined for performance - avoids 8 function calls)
164
- if (value === null || value === undefined || typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean' || typeof value === 'bigint' || typeof value === 'symbol') {
165
- this._content = value;
166
- return;
167
- }
168
-
169
- // KeyValuePair
170
- if (value instanceof KeyValuePair) {
171
- this._content = value;
172
- return;
173
- }
174
-
175
- // ObjectSlice - extract elements array
176
- if (value instanceof ObjectSlice) {
177
- this._content = value.elements;
178
- return;
179
- }
180
-
181
- // Array - refract each item
182
- if (Array.isArray(value)) {
183
- this._content = value.map(item => this.refract(item));
184
- return;
185
- }
186
-
187
- // Plain object - convert to MemberElements
188
- if (typeof value === 'object') {
189
- this._content = Object.entries(value).map(([key, val]) => new this.MemberElement(key, val));
190
- return;
191
- }
192
- throw new Error(`Cannot set content to value of type ${typeof value}`);
193
- }
194
-
195
- /**
196
- * Metadata about this element (id, classes, title, description, links).
197
- * Lazily creates a Metadata instance if not set.
198
- */
199
- get meta() {
200
- if (!this._meta) {
201
- if (this.isFrozen) return FROZEN_EMPTY_METADATA;
202
- this._meta = new Metadata();
203
- }
204
- return this._meta;
205
- }
206
- set meta(value) {
207
- if (value instanceof Metadata) {
208
- this._meta = value;
209
- } else if (value && typeof value === 'object') {
210
- const meta = new Metadata();
211
- Object.assign(meta, value);
212
- this._meta = meta;
213
- }
214
- }
215
-
216
- /**
217
- * Element-specific attributes.
218
- * Lazily creates an ObjectElement if not set.
219
- */
220
- get attributes() {
221
- if (!this._attributes) {
222
- if (this.isFrozen) {
223
- const attributes = new this.ObjectElement();
224
- attributes.freeze();
225
- return attributes;
226
- }
227
- this._attributes = new this.ObjectElement();
228
- }
229
- return this._attributes;
230
- }
231
- set attributes(value) {
232
- if (value instanceof Element) {
233
- this._attributes = value;
234
- } else {
235
- this.attributes.set(value ?? {});
236
- }
237
- }
238
-
239
- // ============================================================
240
- // Meta Property Shortcuts
241
- // ============================================================
242
-
243
- /** Unique identifier for this element. */
244
- get id() {
245
- if (!this.hasMetaProperty('id')) {
246
- if (this.isFrozen) return '';
247
- this.setMetaProperty('id', '');
248
- }
249
- return this.meta.get('id');
250
- }
251
- set id(value) {
252
- this.setMetaProperty('id', value);
253
- }
254
-
255
- /** CSS-like class names. */
256
- get classes() {
257
- if (!this.hasMetaProperty('classes')) {
258
- if (this.isFrozen) return [];
259
- this.setMetaProperty('classes', []);
260
- }
261
- return this.meta.get('classes');
262
- }
263
- set classes(value) {
264
- this.setMetaProperty('classes', value);
265
- }
266
-
267
- /** Hyperlinks associated with this element. */
268
- get links() {
269
- if (!this.hasMetaProperty('links')) {
270
- if (this.isFrozen) {
271
- const empty = new this.ArrayElement();
272
- empty.freeze();
273
- return empty;
274
- }
275
- this.setMetaProperty('links', new this.ArrayElement());
276
- }
277
- return this.meta.get('links');
278
- }
279
- set links(value) {
280
- this.setMetaProperty('links', value);
281
- }
282
-
283
- // ============================================================
284
- // Tree Navigation
285
- // ============================================================
286
-
287
- /** Returns direct children of this element. */
288
- get children() {
289
- const {
290
- _content: content
291
- } = this;
292
- if (Array.isArray(content)) {
293
- return content;
294
- }
295
- if (content instanceof KeyValuePair) {
296
- const children = [];
297
- if (content.key) children.push(content.key);
298
- if (content.value) children.push(content.value);
299
- return children;
300
- }
301
- if (content instanceof Element) {
302
- return [content];
303
- }
304
- return [];
305
- }
306
-
307
- // ============================================================
308
- // Freezable Implementation
309
- // ============================================================
310
-
311
- /** Whether this element is frozen (immutable). */
312
- get isFrozen() {
313
- return Object.isFrozen(this);
314
- }
315
-
316
- /**
317
- * Freezes the element tree, making it immutable.
318
- * Sets up parent references for tree traversal.
319
- */
320
- freeze() {
321
- if (this.isFrozen) return;
322
-
323
- // Freeze meta and attributes
324
- if (this._meta) {
325
- this._meta.freeze();
326
- }
327
- if (this._attributes) {
328
- this._attributes.parent = this;
329
- this._attributes.freeze();
330
- }
331
-
332
- // Freeze children
333
- for (const child of this.children) {
334
- child.parent = this;
335
- child.freeze();
336
- }
337
-
338
- // Freeze content array if applicable
339
- if (Array.isArray(this._content)) {
340
- Object.freeze(this._content);
341
- }
342
- Object.freeze(this);
343
- }
344
-
345
- // ============================================================
346
- // ToValue Implementation
347
- // ============================================================
348
-
349
- /**
350
- * Converts the element to its JavaScript value representation.
351
- */
352
- toValue() {
353
- const {
354
- _content
355
- } = this;
356
- if (_content instanceof Element) {
357
- return _content.toValue();
358
- }
359
- if (_content instanceof KeyValuePair) {
360
- return _content.toValue();
361
- }
362
- if (Array.isArray(_content)) {
363
- return _content.map(el => el.toValue());
364
- }
365
- return _content;
366
- }
367
-
368
- // ============================================================
369
- // Equatable Implementation
370
- // ============================================================
371
-
372
- /**
373
- * Checks deep equality with another value.
374
- */
375
- equals(value) {
376
- const compareTo = value instanceof Element ? value.toValue() : value;
377
- return equals(this.toValue(), compareTo);
378
- }
379
-
380
- // ============================================================
381
- // Element Type
382
- // ============================================================
383
-
384
- /**
385
- * Returns the primitive type name for this element.
386
- * Override in subclasses (e.g., 'string', 'number', 'array').
387
- */
388
- primitive() {
389
- return undefined;
390
- }
391
-
392
- // ============================================================
393
- // Content Operations
394
- // ============================================================
395
-
396
- /**
397
- * Sets the content of this element.
398
- * @returns this for chaining
399
- */
400
- set(content) {
401
- this.content = content;
402
- return this;
403
- }
404
-
405
- // ============================================================
406
- // Reference Creation
407
- // ============================================================
408
-
409
- /**
410
- * Creates a RefElement pointing to this element.
411
- * @param path - Optional path within the referenced element
412
- * @throws Error if this element has no ID
413
- */
414
- toRef(path) {
415
- const idValue = this.id;
416
- if (idValue === '') {
417
- throw new Error('Cannot create reference to an element without an ID');
418
- }
419
- const ref = new this.RefElement(idValue);
420
- if (typeof path === 'string') {
421
- ref.path = this.refract(path);
422
- }
423
- return ref;
424
- }
425
-
426
- /**
427
- * Gets a meta property value.
428
- *
429
- * When the property doesn't exist:
430
- * - With defaultValue: returns the provided default value
431
- * - Without defaultValue: returns undefined
432
- */
433
-
434
- getMetaProperty(name, defaultValue) {
435
- if (!this.hasMetaProperty(name)) {
436
- return defaultValue;
437
- }
438
- return this.meta.get(name);
439
- }
440
-
441
- /**
442
- * Sets a meta property.
443
- */
444
- setMetaProperty(name, value) {
445
- this.meta.set(name, value);
446
- }
447
-
448
- /**
449
- * Checks whether a meta property exists.
450
- */
451
- hasMetaProperty(name) {
452
- return this._meta !== undefined && this._meta.hasKey(name);
453
- }
454
-
455
- /**
456
- * Checks if meta is empty.
457
- */
458
- get isMetaEmpty() {
459
- return this._meta === undefined || this._meta.isEmpty;
460
- }
461
-
462
- /**
463
- * Gets an attribute property, creating it with default value if not present.
464
- */
465
- getAttributesProperty(name, defaultValue) {
466
- if (!this.hasAttributesProperty(name)) {
467
- if (this.isFrozen) {
468
- const element = this.refract(defaultValue);
469
- element.freeze();
470
- return element;
471
- }
472
- this.attributes.set(name, defaultValue);
473
- }
474
- return this.attributes.get(name);
475
- }
476
-
477
- /**
478
- * Sets an attributes property.
479
- */
480
- setAttributesProperty(name, value) {
481
- this.attributes.set(name, value);
482
- }
483
-
484
- /**
485
- * Checks whether an attributes property exists.
486
- */
487
- hasAttributesProperty(name) {
488
- if (!this.isAttributesEmpty) {
489
- return this.attributes.hasKey(name);
490
- }
491
- return false;
492
- }
493
-
494
- /**
495
- * Checks if attributes is empty.
496
- */
497
- get isAttributesEmpty() {
498
- return this._attributes === undefined || this.attributes.isEmpty;
499
- }
500
- }
501
-
502
- // Re-export types for convenience
503
-
504
- export { Metadata };
505
- export default Element;
@@ -1,58 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
4
- exports.__esModule = true;
5
- exports.default = void 0;
6
- var _KeyValuePair = _interopRequireDefault(require("../KeyValuePair.cjs"));
7
- var _Element = _interopRequireDefault(require("./Element.cjs"));
8
- /**
9
- * MemberElement represents a key-value pair member in an ObjectElement.
10
- *
11
- * The member's content is always a KeyValuePair containing:
12
- * - `key`: The key element (typically a StringElement)
13
- * - `value`: The value element (any Element type)
14
- *
15
- * @typeParam K - The key element type, defaults to Element
16
- * @typeParam V - The value element type, defaults to Element
17
- * @public
18
- */
19
- class MemberElement extends _Element.default {
20
- constructor(key, value, meta, attributes) {
21
- super(new _KeyValuePair.default(), meta, attributes);
22
- this.element = 'member';
23
- if (key !== undefined) {
24
- this.key = key;
25
- }
26
-
27
- // Note: We check arguments.length to distinguish between:
28
- // - new MemberElement('key') - value not provided, don't set
29
- // - new MemberElement('key', undefined) - value explicitly undefined, set it
30
- if (arguments.length >= 2) {
31
- this.value = value;
32
- }
33
- }
34
- primitive() {
35
- return 'member';
36
- }
37
-
38
- /**
39
- * The key element of this member.
40
- */
41
- get key() {
42
- return this._content.key;
43
- }
44
- set key(value) {
45
- this._content.key = this.refract(value);
46
- }
47
-
48
- /**
49
- * The value element of this member.
50
- */
51
- get value() {
52
- return this._content.value;
53
- }
54
- set value(value) {
55
- this._content.value = value === undefined ? undefined : this.refract(value);
56
- }
57
- }
58
- var _default = exports.default = MemberElement;
@@ -1,53 +0,0 @@
1
- import KeyValuePair from "../KeyValuePair.mjs";
2
- import Element from "./Element.mjs";
3
- /**
4
- * MemberElement represents a key-value pair member in an ObjectElement.
5
- *
6
- * The member's content is always a KeyValuePair containing:
7
- * - `key`: The key element (typically a StringElement)
8
- * - `value`: The value element (any Element type)
9
- *
10
- * @typeParam K - The key element type, defaults to Element
11
- * @typeParam V - The value element type, defaults to Element
12
- * @public
13
- */
14
- class MemberElement extends Element {
15
- constructor(key, value, meta, attributes) {
16
- super(new KeyValuePair(), meta, attributes);
17
- this.element = 'member';
18
- if (key !== undefined) {
19
- this.key = key;
20
- }
21
-
22
- // Note: We check arguments.length to distinguish between:
23
- // - new MemberElement('key') - value not provided, don't set
24
- // - new MemberElement('key', undefined) - value explicitly undefined, set it
25
- if (arguments.length >= 2) {
26
- this.value = value;
27
- }
28
- }
29
- primitive() {
30
- return 'member';
31
- }
32
-
33
- /**
34
- * The key element of this member.
35
- */
36
- get key() {
37
- return this._content.key;
38
- }
39
- set key(value) {
40
- this._content.key = this.refract(value);
41
- }
42
-
43
- /**
44
- * The value element of this member.
45
- */
46
- get value() {
47
- return this._content.value;
48
- }
49
- set value(value) {
50
- this._content.value = value === undefined ? undefined : this.refract(value);
51
- }
52
- }
53
- export default MemberElement;
@@ -1,28 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
4
- exports.__esModule = true;
5
- exports.default = void 0;
6
- var _Element = _interopRequireDefault(require("./Element.cjs"));
7
- /**
8
- * NullElement represents a null value in ApiDOM.
9
- * @public
10
- */
11
- class NullElement extends _Element.default {
12
- constructor(content, meta, attributes) {
13
- super(content ?? null, meta, attributes);
14
- this.element = 'null';
15
- }
16
- primitive() {
17
- return 'null';
18
- }
19
-
20
- /**
21
- * NullElement cannot have its value changed.
22
- * @throws Error - NullElement value cannot be modified
23
- */
24
- set(_content) {
25
- throw new Error('Cannot set the value of null');
26
- }
27
- }
28
- var _default = exports.default = NullElement;
@@ -1,23 +0,0 @@
1
- import Element from "./Element.mjs";
2
- /**
3
- * NullElement represents a null value in ApiDOM.
4
- * @public
5
- */
6
- class NullElement extends Element {
7
- constructor(content, meta, attributes) {
8
- super(content ?? null, meta, attributes);
9
- this.element = 'null';
10
- }
11
- primitive() {
12
- return 'null';
13
- }
14
-
15
- /**
16
- * NullElement cannot have its value changed.
17
- * @throws Error - NullElement value cannot be modified
18
- */
19
- set(_content) {
20
- throw new Error('Cannot set the value of null');
21
- }
22
- }
23
- export default NullElement;
@@ -1,20 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
4
- exports.__esModule = true;
5
- exports.default = void 0;
6
- var _Element = _interopRequireDefault(require("./Element.cjs"));
7
- /**
8
- * NumberElement represents a numeric value in ApiDOM.
9
- * @public
10
- */
11
- class NumberElement extends _Element.default {
12
- constructor(content, meta, attributes) {
13
- super(content, meta, attributes);
14
- this.element = 'number';
15
- }
16
- primitive() {
17
- return 'number';
18
- }
19
- }
20
- var _default = exports.default = NumberElement;
@@ -1,15 +0,0 @@
1
- import Element from "./Element.mjs";
2
- /**
3
- * NumberElement represents a numeric value in ApiDOM.
4
- * @public
5
- */
6
- class NumberElement extends Element {
7
- constructor(content, meta, attributes) {
8
- super(content, meta, attributes);
9
- this.element = 'number';
10
- }
11
- primitive() {
12
- return 'number';
13
- }
14
- }
15
- export default NumberElement;