@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.
Files changed (46) hide show
  1. package/LICENSES/AFL-3.0.txt +182 -0
  2. package/LICENSES/Apache-2.0.txt +202 -0
  3. package/LICENSES/BSD-3-Clause.txt +26 -0
  4. package/LICENSES/MIT.txt +9 -0
  5. package/NOTICE +74 -0
  6. package/README.md +479 -0
  7. package/dist/apidom-datamodel.browser.js +2717 -0
  8. package/dist/apidom-datamodel.browser.min.js +1 -0
  9. package/package.json +53 -0
  10. package/src/KeyValuePair.cjs +38 -0
  11. package/src/KeyValuePair.mjs +34 -0
  12. package/src/Namespace.cjs +212 -0
  13. package/src/Namespace.mjs +206 -0
  14. package/src/ObjectSlice.cjs +206 -0
  15. package/src/ObjectSlice.mjs +202 -0
  16. package/src/elements/LinkElement.cjs +44 -0
  17. package/src/elements/LinkElement.mjs +39 -0
  18. package/src/elements/RefElement.cjs +31 -0
  19. package/src/elements/RefElement.mjs +26 -0
  20. package/src/index.cjs +25 -0
  21. package/src/index.mjs +6 -0
  22. package/src/primitives/ArrayElement.cjs +176 -0
  23. package/src/primitives/ArrayElement.mjs +169 -0
  24. package/src/primitives/BooleanElement.cjs +20 -0
  25. package/src/primitives/BooleanElement.mjs +15 -0
  26. package/src/primitives/CollectionElement.cjs +194 -0
  27. package/src/primitives/CollectionElement.mjs +187 -0
  28. package/src/primitives/Element.cjs +438 -0
  29. package/src/primitives/Element.mjs +433 -0
  30. package/src/primitives/MemberElement.cjs +54 -0
  31. package/src/primitives/MemberElement.mjs +49 -0
  32. package/src/primitives/NullElement.cjs +28 -0
  33. package/src/primitives/NullElement.mjs +23 -0
  34. package/src/primitives/NumberElement.cjs +20 -0
  35. package/src/primitives/NumberElement.mjs +15 -0
  36. package/src/primitives/ObjectElement.cjs +222 -0
  37. package/src/primitives/ObjectElement.mjs +216 -0
  38. package/src/primitives/StringElement.cjs +27 -0
  39. package/src/primitives/StringElement.mjs +22 -0
  40. package/src/registration.cjs +87 -0
  41. package/src/registration.mjs +70 -0
  42. package/src/serialisers/JSONSerialiser.cjs +144 -0
  43. package/src/serialisers/JSONSerialiser.mjs +140 -0
  44. package/src/types.cjs +3 -0
  45. package/src/types.mjs +1 -0
  46. package/types/apidom-datamodel.d.ts +887 -0
@@ -0,0 +1,176 @@
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 _CollectionElement = _interopRequireDefault(require("./CollectionElement.cjs"));
7
+ // Re-export types from CollectionElement
8
+
9
+ /**
10
+ * ArrayElement represents an array/collection of elements in ApiDOM.
11
+ *
12
+ * @typeParam T - The element type contained in the array, defaults to Element
13
+ * @public
14
+ */
15
+ class ArrayElement extends _CollectionElement.default {
16
+ // Static Fantasy Land methods
17
+ static empty() {
18
+ return new this();
19
+ }
20
+ static 'fantasy-land/empty'() {
21
+ return ArrayElement.empty();
22
+ }
23
+ constructor(content, meta, attributes) {
24
+ super(content || [], meta, attributes);
25
+ this.element = 'array';
26
+ }
27
+ primitive() {
28
+ return 'array';
29
+ }
30
+
31
+ /**
32
+ * Gets the element at the specified index.
33
+ */
34
+ get(index) {
35
+ return this._content[index];
36
+ }
37
+
38
+ /**
39
+ * Helper for returning the value of an item.
40
+ */
41
+ getValue(index) {
42
+ const item = this.get(index);
43
+ if (item) {
44
+ return item.toValue();
45
+ }
46
+ return undefined;
47
+ }
48
+
49
+ /**
50
+ * Sets the element at the specified index, or sets the content if called with one argument.
51
+ */
52
+ set(indexOrContent, value) {
53
+ if (typeof indexOrContent === 'number' && value !== undefined) {
54
+ this._content[indexOrContent] = this.refract(value);
55
+ } else {
56
+ // Delegate to parent set behavior
57
+ this.content = indexOrContent;
58
+ }
59
+ return this;
60
+ }
61
+
62
+ /**
63
+ * Removes the element at the specified index.
64
+ */
65
+ remove(index) {
66
+ return this._content.splice(index, 1)[0] ?? null;
67
+ }
68
+
69
+ /**
70
+ * Maps each element using the provided callback function.
71
+ */
72
+ map(callback, thisArg) {
73
+ return this._content.map(callback, thisArg);
74
+ }
75
+
76
+ /**
77
+ * Maps and then flattens the results.
78
+ */
79
+ flatMap(callback, thisArg) {
80
+ return this._content.flatMap(callback, thisArg);
81
+ }
82
+
83
+ /**
84
+ * Returns an array containing the truthy results of calling the given transformation.
85
+ */
86
+ compactMap(transform, thisArg) {
87
+ const results = [];
88
+ for (const element of this._content) {
89
+ const result = transform.call(thisArg, element);
90
+ if (result) {
91
+ results.push(result);
92
+ }
93
+ }
94
+ return results;
95
+ }
96
+
97
+ /**
98
+ * Filters elements using the provided callback.
99
+ */
100
+ filter(callback, thisArg) {
101
+ const filtered = this._content.filter(callback, thisArg);
102
+ return new this.constructor(filtered);
103
+ }
104
+
105
+ /**
106
+ * Rejects elements that match the provided callback.
107
+ */
108
+ reject(callback, thisArg) {
109
+ const results = [];
110
+ for (const element of this._content) {
111
+ if (!callback.call(thisArg, element)) {
112
+ results.push(element);
113
+ }
114
+ }
115
+ return new this.constructor(results);
116
+ }
117
+
118
+ /**
119
+ * Reduces the array to a single value.
120
+ * This is a reduce function specifically for datamodel arrays and objects.
121
+ * It allows for returning normal values or datamodel instances.
122
+ */
123
+ reduce(callback, initialValue) {
124
+ let startIndex;
125
+ let memo;
126
+
127
+ // Allows for defining a starting value of the reduce
128
+ if (initialValue !== undefined) {
129
+ startIndex = 0;
130
+ memo = this.refract(initialValue);
131
+ } else {
132
+ startIndex = 1;
133
+ memo = this.first;
134
+ }
135
+
136
+ // Sending each function call to the registry allows for passing datamodel
137
+ // instances through the function return.
138
+ for (let i = startIndex; i < this.length; i += 1) {
139
+ const item = this._content[i];
140
+ const result = callback(memo, item, i, this);
141
+ memo = result === undefined ? result : this.refract(result);
142
+ }
143
+ return memo;
144
+ }
145
+
146
+ /**
147
+ * Executes a provided function once for each element.
148
+ */
149
+ forEach(callback, thisArg) {
150
+ this._content.forEach((item, index) => {
151
+ callback.call(thisArg, item, index);
152
+ });
153
+ }
154
+
155
+ // Fantasy Land
156
+
157
+ /**
158
+ * Returns an empty array element.
159
+ */
160
+ empty() {
161
+ return new this.constructor([]);
162
+ }
163
+ 'fantasy-land/map'(transform) {
164
+ return new this.constructor(this.map(transform));
165
+ }
166
+ 'fantasy-land/chain'(transform) {
167
+ return this.map(element => transform(element)).reduce((a, b) => a.concat(b), this.empty());
168
+ }
169
+ 'fantasy-land/filter'(callback) {
170
+ return new this.constructor(this._content.filter(callback));
171
+ }
172
+ 'fantasy-land/reduce'(transform, initialValue) {
173
+ return this._content.reduce(transform, initialValue);
174
+ }
175
+ }
176
+ var _default = exports.default = ArrayElement;
@@ -0,0 +1,169 @@
1
+ import CollectionElement from "./CollectionElement.mjs"; // Re-export types from CollectionElement
2
+ /**
3
+ * ArrayElement represents an array/collection of elements in ApiDOM.
4
+ *
5
+ * @typeParam T - The element type contained in the array, defaults to Element
6
+ * @public
7
+ */
8
+ class ArrayElement extends CollectionElement {
9
+ // Static Fantasy Land methods
10
+ static empty() {
11
+ return new this();
12
+ }
13
+ static 'fantasy-land/empty'() {
14
+ return ArrayElement.empty();
15
+ }
16
+ constructor(content, meta, attributes) {
17
+ super(content || [], meta, attributes);
18
+ this.element = 'array';
19
+ }
20
+ primitive() {
21
+ return 'array';
22
+ }
23
+
24
+ /**
25
+ * Gets the element at the specified index.
26
+ */
27
+ get(index) {
28
+ return this._content[index];
29
+ }
30
+
31
+ /**
32
+ * Helper for returning the value of an item.
33
+ */
34
+ getValue(index) {
35
+ const item = this.get(index);
36
+ if (item) {
37
+ return item.toValue();
38
+ }
39
+ return undefined;
40
+ }
41
+
42
+ /**
43
+ * Sets the element at the specified index, or sets the content if called with one argument.
44
+ */
45
+ set(indexOrContent, value) {
46
+ if (typeof indexOrContent === 'number' && value !== undefined) {
47
+ this._content[indexOrContent] = this.refract(value);
48
+ } else {
49
+ // Delegate to parent set behavior
50
+ this.content = indexOrContent;
51
+ }
52
+ return this;
53
+ }
54
+
55
+ /**
56
+ * Removes the element at the specified index.
57
+ */
58
+ remove(index) {
59
+ return this._content.splice(index, 1)[0] ?? null;
60
+ }
61
+
62
+ /**
63
+ * Maps each element using the provided callback function.
64
+ */
65
+ map(callback, thisArg) {
66
+ return this._content.map(callback, thisArg);
67
+ }
68
+
69
+ /**
70
+ * Maps and then flattens the results.
71
+ */
72
+ flatMap(callback, thisArg) {
73
+ return this._content.flatMap(callback, thisArg);
74
+ }
75
+
76
+ /**
77
+ * Returns an array containing the truthy results of calling the given transformation.
78
+ */
79
+ compactMap(transform, thisArg) {
80
+ const results = [];
81
+ for (const element of this._content) {
82
+ const result = transform.call(thisArg, element);
83
+ if (result) {
84
+ results.push(result);
85
+ }
86
+ }
87
+ return results;
88
+ }
89
+
90
+ /**
91
+ * Filters elements using the provided callback.
92
+ */
93
+ filter(callback, thisArg) {
94
+ const filtered = this._content.filter(callback, thisArg);
95
+ return new this.constructor(filtered);
96
+ }
97
+
98
+ /**
99
+ * Rejects elements that match the provided callback.
100
+ */
101
+ reject(callback, thisArg) {
102
+ const results = [];
103
+ for (const element of this._content) {
104
+ if (!callback.call(thisArg, element)) {
105
+ results.push(element);
106
+ }
107
+ }
108
+ return new this.constructor(results);
109
+ }
110
+
111
+ /**
112
+ * Reduces the array to a single value.
113
+ * This is a reduce function specifically for datamodel arrays and objects.
114
+ * It allows for returning normal values or datamodel instances.
115
+ */
116
+ reduce(callback, initialValue) {
117
+ let startIndex;
118
+ let memo;
119
+
120
+ // Allows for defining a starting value of the reduce
121
+ if (initialValue !== undefined) {
122
+ startIndex = 0;
123
+ memo = this.refract(initialValue);
124
+ } else {
125
+ startIndex = 1;
126
+ memo = this.first;
127
+ }
128
+
129
+ // Sending each function call to the registry allows for passing datamodel
130
+ // instances through the function return.
131
+ for (let i = startIndex; i < this.length; i += 1) {
132
+ const item = this._content[i];
133
+ const result = callback(memo, item, i, this);
134
+ memo = result === undefined ? result : this.refract(result);
135
+ }
136
+ return memo;
137
+ }
138
+
139
+ /**
140
+ * Executes a provided function once for each element.
141
+ */
142
+ forEach(callback, thisArg) {
143
+ this._content.forEach((item, index) => {
144
+ callback.call(thisArg, item, index);
145
+ });
146
+ }
147
+
148
+ // Fantasy Land
149
+
150
+ /**
151
+ * Returns an empty array element.
152
+ */
153
+ empty() {
154
+ return new this.constructor([]);
155
+ }
156
+ 'fantasy-land/map'(transform) {
157
+ return new this.constructor(this.map(transform));
158
+ }
159
+ 'fantasy-land/chain'(transform) {
160
+ return this.map(element => transform(element)).reduce((a, b) => a.concat(b), this.empty());
161
+ }
162
+ 'fantasy-land/filter'(callback) {
163
+ return new this.constructor(this._content.filter(callback));
164
+ }
165
+ 'fantasy-land/reduce'(transform, initialValue) {
166
+ return this._content.reduce(transform, initialValue);
167
+ }
168
+ }
169
+ export default ArrayElement;
@@ -0,0 +1,20 @@
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
+ * BooleanElement represents a boolean value in ApiDOM.
9
+ * @public
10
+ */
11
+ class BooleanElement extends _Element.default {
12
+ constructor(content, meta, attributes) {
13
+ super(content, meta, attributes);
14
+ this.element = 'boolean';
15
+ }
16
+ primitive() {
17
+ return 'boolean';
18
+ }
19
+ }
20
+ var _default = exports.default = BooleanElement;
@@ -0,0 +1,15 @@
1
+ import Element from "./Element.mjs";
2
+ /**
3
+ * BooleanElement represents a boolean value in ApiDOM.
4
+ * @public
5
+ */
6
+ class BooleanElement extends Element {
7
+ constructor(content, meta, attributes) {
8
+ super(content, meta, attributes);
9
+ this.element = 'boolean';
10
+ }
11
+ primitive() {
12
+ return 'boolean';
13
+ }
14
+ }
15
+ export default BooleanElement;
@@ -0,0 +1,194 @@
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
+ * Condition function for finding elements.
9
+ * @public
10
+ */
11
+
12
+ /**
13
+ * Options for finding elements.
14
+ * @public
15
+ */
16
+
17
+ /**
18
+ * CollectionElement is an abstract base class for collection-like elements.
19
+ * Both ArrayElement and ObjectElement extend this class.
20
+ *
21
+ * This class contains the shared functionality between arrays and objects,
22
+ * while keeping the conflicting methods (get, set, remove, map, filter, etc.)
23
+ * in the respective subclasses.
24
+ *
25
+ * @remarks
26
+ * This is primarily an implementation detail. Use ArrayElement or ObjectElement directly.
27
+ *
28
+ * @typeParam T - The element type contained in the collection, defaults to Element
29
+ * @public
30
+ */
31
+ class CollectionElement extends _Element.default {
32
+ constructor(content, meta, attributes) {
33
+ super(content || [], meta, attributes);
34
+ }
35
+
36
+ /**
37
+ * Returns the length of the collection.
38
+ */
39
+ get length() {
40
+ return this._content.length;
41
+ }
42
+
43
+ /**
44
+ * Returns whether the collection is empty.
45
+ */
46
+ get isEmpty() {
47
+ return this.length === 0;
48
+ }
49
+
50
+ /**
51
+ * Return the first item in the collection.
52
+ */
53
+ get first() {
54
+ return this._content[0];
55
+ }
56
+
57
+ /**
58
+ * Return the second item in the collection.
59
+ */
60
+ get second() {
61
+ return this._content[1];
62
+ }
63
+
64
+ /**
65
+ * Return the last item in the collection.
66
+ */
67
+ get last() {
68
+ return this._content.at(-1);
69
+ }
70
+
71
+ /**
72
+ * Adds the given element to the end of the collection.
73
+ */
74
+ push(value) {
75
+ this._content.push(this.refract(value));
76
+ return this;
77
+ }
78
+
79
+ /**
80
+ * Alias for push.
81
+ */
82
+ add(value) {
83
+ this.push(value);
84
+ }
85
+
86
+ /**
87
+ * Removes the first element from the collection.
88
+ */
89
+ shift() {
90
+ return this._content.shift();
91
+ }
92
+
93
+ /**
94
+ * Adds the given element to the beginning of the collection.
95
+ */
96
+ unshift(value) {
97
+ this._content.unshift(this.refract(value));
98
+ }
99
+
100
+ /**
101
+ * Looks for matching children using deep equality.
102
+ */
103
+ includes(value) {
104
+ return this._content.some(element => element.equals(value));
105
+ }
106
+
107
+ /**
108
+ * Recursively search all descendants using a condition function.
109
+ */
110
+ findElements(condition, givenOptions) {
111
+ const options = givenOptions || {};
112
+ const recursive = !!options.recursive;
113
+ const results = options.results === undefined ? [] : options.results;
114
+ for (let i = 0; i < this._content.length; i += 1) {
115
+ const item = this._content[i];
116
+
117
+ // We use duck-typing here to support any registered class that
118
+ // may contain other elements.
119
+
120
+ const itemWithFindElements = item;
121
+ if (recursive && typeof itemWithFindElements.findElements === 'function') {
122
+ itemWithFindElements.findElements(condition, {
123
+ results,
124
+ recursive
125
+ });
126
+ }
127
+ if (condition(item, i, undefined)) {
128
+ results.push(item);
129
+ }
130
+ }
131
+ return results;
132
+ }
133
+
134
+ /**
135
+ * Recursively search all descendants using a condition function.
136
+ */
137
+ find(condition) {
138
+ const results = this.findElements(condition, {
139
+ recursive: true
140
+ });
141
+ return new this.ArrayElement(results);
142
+ }
143
+
144
+ /**
145
+ * Find elements by their element type name.
146
+ */
147
+ findByElement(element) {
148
+ return this.find(item => item.element === element);
149
+ }
150
+
151
+ /**
152
+ * Find elements by class name.
153
+ */
154
+ findByClass(className) {
155
+ return this.find(item => {
156
+ const classes = item.classes;
157
+ return typeof classes.includes === 'function' && classes.includes(className);
158
+ });
159
+ }
160
+
161
+ /**
162
+ * Search the tree recursively and find the element with the matching ID.
163
+ */
164
+ getById(id) {
165
+ return this.find(item => item.id.toValue() === id).first;
166
+ }
167
+
168
+ // Fantasy Land - Monoid
169
+
170
+ /**
171
+ * Returns an empty collection element.
172
+ */
173
+
174
+ 'fantasy-land/empty'() {
175
+ return this.empty();
176
+ }
177
+
178
+ /**
179
+ * Concatenates two collection elements.
180
+ */
181
+ concat(other) {
182
+ const Ctor = this.constructor;
183
+ return new Ctor(this._content.concat(other._content));
184
+ }
185
+ 'fantasy-land/concat'(other) {
186
+ return this.concat(other);
187
+ }
188
+
189
+ // Iterator support
190
+ [Symbol.iterator]() {
191
+ return this._content[Symbol.iterator]();
192
+ }
193
+ }
194
+ var _default = exports.default = CollectionElement;