@speclynx/apidom-datamodel 3.2.0 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,178 +0,0 @@
1
- import { clone } from 'ramda';
2
- import ObjectSlice from "../ObjectSlice.mjs";
3
- import KeyValuePair from "../KeyValuePair.mjs";
4
- import { isElement, hasElementSourceMap, hasElementStyle } from "../predicates/index.mjs";
5
- import SourceMapElement from "../elements/SourceMap.mjs";
6
- import DeepCloneError from "./errors/DeepCloneError.mjs";
7
- import ShallowCloneError from "./errors/ShallowCloneError.mjs";
8
- /**
9
- * @public
10
- */
11
- /**
12
- * @public
13
- */
14
- const cloneDeepElement = (element, options) => {
15
- const {
16
- visited = new WeakMap()
17
- } = options;
18
- const passThroughOptions = {
19
- ...options,
20
- visited
21
- };
22
-
23
- // detect cycle and return memoized value
24
- if (visited.has(element)) {
25
- return visited.get(element);
26
- }
27
- const copy = cloneShallowElement(element);
28
- visited.set(element, copy);
29
- const {
30
- content
31
- } = element;
32
- if (Array.isArray(content)) {
33
- copy.content = content.map(el => cloneDeepElement(el, passThroughOptions));
34
- } else if (isElement(content)) {
35
- copy.content = cloneDeepElement(content, passThroughOptions);
36
- } else if (content instanceof KeyValuePair) {
37
- copy.content = cloneDeepKeyValuePair(content, passThroughOptions);
38
- } else {
39
- copy.content = content;
40
- }
41
- return copy;
42
- };
43
- const cloneDeepKeyValuePair = (kvp, options) => {
44
- const {
45
- visited = new WeakMap()
46
- } = options;
47
- const passThroughOptions = {
48
- ...options,
49
- visited
50
- };
51
- if (visited.has(kvp)) {
52
- return visited.get(kvp);
53
- }
54
- const {
55
- key,
56
- value
57
- } = kvp;
58
- const keyCopy = key !== undefined ? cloneDeepElement(key, passThroughOptions) : undefined;
59
- const valueCopy = value !== undefined ? cloneDeepElement(value, passThroughOptions) : undefined;
60
- const copy = new KeyValuePair(keyCopy, valueCopy);
61
- visited.set(kvp, copy);
62
- return copy;
63
- };
64
- const cloneDeepObjectSlice = (slice, options) => {
65
- const {
66
- visited = new WeakMap()
67
- } = options;
68
- const passThroughOptions = {
69
- ...options,
70
- visited
71
- };
72
- if (visited.has(slice)) {
73
- return visited.get(slice);
74
- }
75
- const items = [...slice].map(element => cloneDeepElement(element, passThroughOptions));
76
- const copy = new ObjectSlice(items);
77
- visited.set(slice, copy);
78
- return copy;
79
- };
80
-
81
- /**
82
- * Creates a deep clone of an ApiDOM Element, KeyValuePair, or ObjectSlice.
83
- * Handles cycles by memoizing visited objects.
84
- * @public
85
- */
86
- export const cloneDeep = (value, options = {}) => {
87
- if (value instanceof KeyValuePair) {
88
- return cloneDeepKeyValuePair(value, options);
89
- }
90
- if (value instanceof ObjectSlice) {
91
- return cloneDeepObjectSlice(value, options);
92
- }
93
- if (isElement(value)) {
94
- return cloneDeepElement(value, options);
95
- }
96
- throw new DeepCloneError("Value provided to cloneDeep function couldn't be cloned", {
97
- value
98
- });
99
- };
100
- cloneDeep.safe = value => {
101
- try {
102
- return cloneDeep(value);
103
- } catch {
104
- return value;
105
- }
106
- };
107
- const cloneShallowKeyValuePair = keyValuePair => {
108
- const {
109
- key,
110
- value
111
- } = keyValuePair;
112
- return new KeyValuePair(key, value);
113
- };
114
- const cloneShallowObjectSlice = objectSlice => {
115
- const items = [...objectSlice];
116
- return new ObjectSlice(items);
117
- };
118
- const cloneShallowElement = element => {
119
- const Ctor = element.constructor;
120
- const copy = new Ctor();
121
- copy.element = element.element;
122
- if (!element.isMetaEmpty) {
123
- copy.meta = element.meta.cloneDeep();
124
- }
125
- if (!element.isAttributesEmpty) {
126
- copy.attributes = cloneDeep(element.attributes);
127
- }
128
- if (hasElementSourceMap(element)) {
129
- SourceMapElement.transfer(element, copy);
130
- }
131
- if (hasElementStyle(element)) {
132
- copy.style = clone(element.style);
133
- }
134
- const {
135
- content
136
- } = element;
137
- if (isElement(content)) {
138
- copy.content = cloneShallowElement(content);
139
- } else if (Array.isArray(content)) {
140
- copy.content = [...content];
141
- } else if (content instanceof KeyValuePair) {
142
- copy.content = cloneShallowKeyValuePair(content);
143
- } else {
144
- copy.content = content;
145
- }
146
- return copy;
147
- };
148
-
149
- /**
150
- * Creates a shallow clone of an ApiDOM Element, KeyValuePair, or ObjectSlice.
151
- * The element itself is cloned, but content references are shared.
152
- * Meta and attributes are deep cloned to preserve semantic information.
153
- * @public
154
- */
155
- export const cloneShallow = value => {
156
- if (value instanceof KeyValuePair) {
157
- return cloneShallowKeyValuePair(value);
158
- }
159
- if (value instanceof ObjectSlice) {
160
- return cloneShallowObjectSlice(value);
161
- }
162
- if (isElement(value)) {
163
- return cloneShallowElement(value);
164
- }
165
- throw new ShallowCloneError("Value provided to cloneShallow function couldn't be cloned", {
166
- value
167
- });
168
- };
169
- cloneShallow.safe = value => {
170
- try {
171
- return cloneShallow(value);
172
- } catch {
173
- return value;
174
- }
175
- };
176
- export { default as CloneError } from "./errors/CloneError.mjs";
177
- export { default as DeepCloneError } from "./errors/DeepCloneError.mjs";
178
- export { default as ShallowCloneError } from "./errors/ShallowCloneError.mjs";
@@ -1,35 +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 _StringElement = _interopRequireDefault(require("../primitives/StringElement.cjs"));
7
- /**
8
- * AnnotationElement represents a parsing annotation (warning or error).
9
- *
10
- * The annotation's class indicates its severity:
11
- * - 'warning' - A non-fatal issue
12
- * - 'error' - A fatal issue
13
- *
14
- * @public
15
- */
16
- class AnnotationElement extends _StringElement.default {
17
- constructor(content, meta, attributes) {
18
- super(content, meta, attributes);
19
- this.element = 'annotation';
20
- }
21
-
22
- /**
23
- * The annotation code identifying the type of annotation.
24
- */
25
- get code() {
26
- if (this.hasAttributesProperty('code')) {
27
- return this.attributes.get('code');
28
- }
29
- return undefined;
30
- }
31
- set code(value) {
32
- this.attributes.set('code', value);
33
- }
34
- }
35
- var _default = exports.default = AnnotationElement;
@@ -1,30 +0,0 @@
1
- import StringElement from "../primitives/StringElement.mjs";
2
- /**
3
- * AnnotationElement represents a parsing annotation (warning or error).
4
- *
5
- * The annotation's class indicates its severity:
6
- * - 'warning' - A non-fatal issue
7
- * - 'error' - A fatal issue
8
- *
9
- * @public
10
- */
11
- class AnnotationElement extends StringElement {
12
- constructor(content, meta, attributes) {
13
- super(content, meta, attributes);
14
- this.element = 'annotation';
15
- }
16
-
17
- /**
18
- * The annotation code identifying the type of annotation.
19
- */
20
- get code() {
21
- if (this.hasAttributesProperty('code')) {
22
- return this.attributes.get('code');
23
- }
24
- return undefined;
25
- }
26
- set code(value) {
27
- this.attributes.set('code', value);
28
- }
29
- }
30
- export default AnnotationElement;
@@ -1,18 +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 _StringElement = _interopRequireDefault(require("../primitives/StringElement.cjs"));
7
- /**
8
- * CommentElement represents a comment in the source document.
9
- *
10
- * @public
11
- */
12
- class CommentElement extends _StringElement.default {
13
- constructor(content, meta, attributes) {
14
- super(content, meta, attributes);
15
- this.element = 'comment';
16
- }
17
- }
18
- var _default = exports.default = CommentElement;
@@ -1,13 +0,0 @@
1
- import StringElement from "../primitives/StringElement.mjs";
2
- /**
3
- * CommentElement represents a comment in the source document.
4
- *
5
- * @public
6
- */
7
- class CommentElement extends StringElement {
8
- constructor(content, meta, attributes) {
9
- super(content, meta, attributes);
10
- this.element = 'comment';
11
- }
12
- }
13
- export default CommentElement;
@@ -1,50 +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("../primitives/Element.cjs"));
7
- /**
8
- * LinkElement represents a hyperlink in ApiDOM.
9
- *
10
- * Hyperlinking MAY be used to link to other resources, provide links to
11
- * instructions on how to process a given element (by way of a profile or
12
- * other means), and may be used to provide meta data about the element in
13
- * which it's found. The meaning and purpose of the hyperlink is defined by
14
- * the link relation according to RFC 5988.
15
- *
16
- * @public
17
- */
18
- class LinkElement extends _Element.default {
19
- constructor(content, meta, attributes) {
20
- super(content || [], meta, attributes);
21
- this.element = 'link';
22
- }
23
-
24
- /**
25
- * The relation identifier for the link, as defined in RFC 5988.
26
- */
27
- get relation() {
28
- if (this.hasAttributesProperty('relation')) {
29
- return this.attributes.get('relation');
30
- }
31
- return undefined;
32
- }
33
- set relation(relation) {
34
- this.attributes.set('relation', relation);
35
- }
36
-
37
- /**
38
- * The URI for the given link.
39
- */
40
- get href() {
41
- if (this.hasAttributesProperty('href')) {
42
- return this.attributes.get('href');
43
- }
44
- return undefined;
45
- }
46
- set href(href) {
47
- this.attributes.set('href', href);
48
- }
49
- }
50
- var _default = exports.default = LinkElement;
@@ -1,45 +0,0 @@
1
- import Element from "../primitives/Element.mjs";
2
- /**
3
- * LinkElement represents a hyperlink in ApiDOM.
4
- *
5
- * Hyperlinking MAY be used to link to other resources, provide links to
6
- * instructions on how to process a given element (by way of a profile or
7
- * other means), and may be used to provide meta data about the element in
8
- * which it's found. The meaning and purpose of the hyperlink is defined by
9
- * the link relation according to RFC 5988.
10
- *
11
- * @public
12
- */
13
- class LinkElement extends Element {
14
- constructor(content, meta, attributes) {
15
- super(content || [], meta, attributes);
16
- this.element = 'link';
17
- }
18
-
19
- /**
20
- * The relation identifier for the link, as defined in RFC 5988.
21
- */
22
- get relation() {
23
- if (this.hasAttributesProperty('relation')) {
24
- return this.attributes.get('relation');
25
- }
26
- return undefined;
27
- }
28
- set relation(relation) {
29
- this.attributes.set('relation', relation);
30
- }
31
-
32
- /**
33
- * The URI for the given link.
34
- */
35
- get href() {
36
- if (this.hasAttributesProperty('href')) {
37
- return this.attributes.get('href');
38
- }
39
- return undefined;
40
- }
41
- set href(href) {
42
- this.attributes.set('href', href);
43
- }
44
- }
45
- export default LinkElement;
@@ -1,91 +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 _ArrayElement = _interopRequireDefault(require("../primitives/ArrayElement.cjs"));
7
- var _index = require("../predicates/index.cjs");
8
- /**
9
- * ParseResultElement represents the result of parsing a document.
10
- *
11
- * Contains the parsed API element, any result elements, and annotations
12
- * (warnings and errors) from the parsing process.
13
- *
14
- * @public
15
- */
16
- class ParseResultElement extends _ArrayElement.default {
17
- constructor(content, meta, attributes) {
18
- super(content, meta, attributes);
19
- this.element = 'parseResult';
20
- }
21
-
22
- /**
23
- * The main API element from the parse result.
24
- */
25
- get api() {
26
- return this.filter(item => (0, _index.includesClasses)(item, ['api'])).first;
27
- }
28
-
29
- /**
30
- * All result elements from the parse result.
31
- */
32
- get results() {
33
- return this.filter(item => (0, _index.includesClasses)(item, ['result']));
34
- }
35
-
36
- /**
37
- * The first result element.
38
- */
39
- get result() {
40
- return this.results.first;
41
- }
42
-
43
- /**
44
- * All annotation elements (warnings and errors).
45
- */
46
- get annotations() {
47
- return this.filter(item => item.element === 'annotation');
48
- }
49
-
50
- /**
51
- * All warning annotations.
52
- */
53
- get warnings() {
54
- return this.filter(item => item.element === 'annotation' && (0, _index.includesClasses)(item, ['warning']));
55
- }
56
-
57
- /**
58
- * All error annotations.
59
- */
60
- get errors() {
61
- return this.filter(item => item.element === 'annotation' && (0, _index.includesClasses)(item, ['error']));
62
- }
63
-
64
- /**
65
- * Whether the parse result is empty (contains only annotations).
66
- */
67
- get isEmpty() {
68
- return this.reject(item => item.element === 'annotation').length === 0;
69
- }
70
-
71
- /**
72
- * Replaces the first result element with the given replacement.
73
- * @returns true if replacement was successful, false otherwise
74
- */
75
- replaceResult(replacement) {
76
- const {
77
- result
78
- } = this;
79
- if (result === undefined) {
80
- return false;
81
- }
82
- const content = this._content;
83
- const searchIndex = content.findIndex(e => e === result);
84
- if (searchIndex === -1) {
85
- return false;
86
- }
87
- content[searchIndex] = replacement;
88
- return true;
89
- }
90
- }
91
- var _default = exports.default = ParseResultElement;
@@ -1,86 +0,0 @@
1
- import ArrayElement from "../primitives/ArrayElement.mjs";
2
- import { includesClasses } from "../predicates/index.mjs";
3
- /**
4
- * ParseResultElement represents the result of parsing a document.
5
- *
6
- * Contains the parsed API element, any result elements, and annotations
7
- * (warnings and errors) from the parsing process.
8
- *
9
- * @public
10
- */
11
- class ParseResultElement extends ArrayElement {
12
- constructor(content, meta, attributes) {
13
- super(content, meta, attributes);
14
- this.element = 'parseResult';
15
- }
16
-
17
- /**
18
- * The main API element from the parse result.
19
- */
20
- get api() {
21
- return this.filter(item => includesClasses(item, ['api'])).first;
22
- }
23
-
24
- /**
25
- * All result elements from the parse result.
26
- */
27
- get results() {
28
- return this.filter(item => includesClasses(item, ['result']));
29
- }
30
-
31
- /**
32
- * The first result element.
33
- */
34
- get result() {
35
- return this.results.first;
36
- }
37
-
38
- /**
39
- * All annotation elements (warnings and errors).
40
- */
41
- get annotations() {
42
- return this.filter(item => item.element === 'annotation');
43
- }
44
-
45
- /**
46
- * All warning annotations.
47
- */
48
- get warnings() {
49
- return this.filter(item => item.element === 'annotation' && includesClasses(item, ['warning']));
50
- }
51
-
52
- /**
53
- * All error annotations.
54
- */
55
- get errors() {
56
- return this.filter(item => item.element === 'annotation' && includesClasses(item, ['error']));
57
- }
58
-
59
- /**
60
- * Whether the parse result is empty (contains only annotations).
61
- */
62
- get isEmpty() {
63
- return this.reject(item => item.element === 'annotation').length === 0;
64
- }
65
-
66
- /**
67
- * Replaces the first result element with the given replacement.
68
- * @returns true if replacement was successful, false otherwise
69
- */
70
- replaceResult(replacement) {
71
- const {
72
- result
73
- } = this;
74
- if (result === undefined) {
75
- return false;
76
- }
77
- const content = this._content;
78
- const searchIndex = content.findIndex(e => e === result);
79
- if (searchIndex === -1) {
80
- return false;
81
- }
82
- content[searchIndex] = replacement;
83
- return true;
84
- }
85
- }
86
- export default ParseResultElement;
@@ -1,34 +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("../primitives/Element.cjs"));
7
- /**
8
- * RefElement represents a reference to another element in ApiDOM.
9
- * @public
10
- */
11
- class RefElement extends _Element.default {
12
- constructor(content, meta, attributes) {
13
- super(content || [], meta, attributes);
14
- this.element = 'ref';
15
- if (!this.path) {
16
- this.path = 'element';
17
- }
18
- }
19
-
20
- /**
21
- * Path of referenced element to transclude instead of element itself.
22
- * @defaultValue 'element'
23
- */
24
- get path() {
25
- if (this.hasAttributesProperty('path')) {
26
- return this.attributes.get('path');
27
- }
28
- return undefined;
29
- }
30
- set path(newValue) {
31
- this.attributes.set('path', newValue);
32
- }
33
- }
34
- var _default = exports.default = RefElement;
@@ -1,29 +0,0 @@
1
- import Element from "../primitives/Element.mjs";
2
- /**
3
- * RefElement represents a reference to another element in ApiDOM.
4
- * @public
5
- */
6
- class RefElement extends Element {
7
- constructor(content, meta, attributes) {
8
- super(content || [], meta, attributes);
9
- this.element = 'ref';
10
- if (!this.path) {
11
- this.path = 'element';
12
- }
13
- }
14
-
15
- /**
16
- * Path of referenced element to transclude instead of element itself.
17
- * @defaultValue 'element'
18
- */
19
- get path() {
20
- if (this.hasAttributesProperty('path')) {
21
- return this.attributes.get('path');
22
- }
23
- return undefined;
24
- }
25
- set path(newValue) {
26
- this.attributes.set('path', newValue);
27
- }
28
- }
29
- export default RefElement;