@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,144 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports.default = void 0;
5
+ /**
6
+ * Serialized representation of an Element in JSON Refract format.
7
+ * @public
8
+ */
9
+
10
+ /**
11
+ * Serialized representation of a KeyValuePair in JSON Refract format.
12
+ * @public
13
+ */
14
+
15
+ /**
16
+ * Possible content types in a serialized element.
17
+ * @public
18
+ */
19
+
20
+ /**
21
+ * Input document format for deserialization.
22
+ * @public
23
+ */
24
+
25
+ /**
26
+ * JSONSerialiser handles serialization and deserialization of ApiDOM elements
27
+ * to and from JSON Refract format.
28
+ * @public
29
+ */
30
+ class JSONSerialiser {
31
+ namespace;
32
+
33
+ // This will be set via prototype assignment to avoid circular dependency
34
+
35
+ constructor(namespace) {
36
+ this.namespace = namespace || new this.Namespace();
37
+ }
38
+
39
+ /**
40
+ * Serializes an Element to JSON Refract format.
41
+ */
42
+ serialise(element) {
43
+ if (!(element instanceof this.namespace.elements.Element)) {
44
+ throw new TypeError(`Given element \`${element}\` is not an Element instance`);
45
+ }
46
+ const payload = {
47
+ element: element.element
48
+ };
49
+ if (element._meta && element._meta.length > 0) {
50
+ payload.meta = this.serialiseObject(element.meta);
51
+ }
52
+ if (element._attributes && element._attributes.length > 0) {
53
+ payload.attributes = this.serialiseObject(element.attributes);
54
+ }
55
+ const content = this.serialiseContent(element.content);
56
+ if (content !== undefined) {
57
+ payload.content = content;
58
+ }
59
+ return payload;
60
+ }
61
+
62
+ /**
63
+ * Deserializes a JSON Refract document to an Element.
64
+ */
65
+ deserialise(value) {
66
+ if (!value.element) {
67
+ throw new Error('Given value is not an object containing an element name');
68
+ }
69
+ const ElementClass = this.namespace.getElementClass(value.element);
70
+ const element = new ElementClass();
71
+ if (element.element !== value.element) {
72
+ element.element = value.element;
73
+ }
74
+ if (value.meta) {
75
+ this.deserialiseObject(value.meta, element.meta);
76
+ }
77
+ if (value.attributes) {
78
+ this.deserialiseObject(value.attributes, element.attributes);
79
+ }
80
+ const content = this.deserialiseContent(value.content);
81
+ if (content !== undefined || element.content === null) {
82
+ element.content = content;
83
+ }
84
+ return element;
85
+ }
86
+ serialiseContent(content) {
87
+ if (content instanceof this.namespace.elements.Element) {
88
+ return this.serialise(content);
89
+ }
90
+ if (content instanceof this.namespace.KeyValuePair) {
91
+ const kvp = content;
92
+ const pair = {
93
+ key: this.serialise(kvp.key)
94
+ };
95
+ if (kvp.value) {
96
+ pair.value = this.serialise(kvp.value);
97
+ }
98
+ return pair;
99
+ }
100
+ if (content && Array.isArray(content)) {
101
+ if (content.length === 0) {
102
+ return undefined;
103
+ }
104
+ return content.map(item => this.serialise(item));
105
+ }
106
+ return content;
107
+ }
108
+ deserialiseContent(content) {
109
+ if (content) {
110
+ if (content.element) {
111
+ return this.deserialise(content);
112
+ }
113
+ if (content.key) {
114
+ const pair = new this.namespace.KeyValuePair(this.deserialise(content.key));
115
+ if (content.value) {
116
+ pair.value = this.deserialise(content.value);
117
+ }
118
+ return pair;
119
+ }
120
+ if (Array.isArray(content)) {
121
+ return content.map(item => this.deserialise(item));
122
+ }
123
+ }
124
+ return content;
125
+ }
126
+ serialiseObject(obj) {
127
+ const result = {};
128
+ obj.forEach((value, key) => {
129
+ if (value) {
130
+ result[key.toValue()] = this.serialise(value);
131
+ }
132
+ });
133
+ if (Object.keys(result).length === 0) {
134
+ return undefined;
135
+ }
136
+ return result;
137
+ }
138
+ deserialiseObject(from, to) {
139
+ Object.keys(from).forEach(key => {
140
+ to.set(key, this.deserialise(from[key]));
141
+ });
142
+ }
143
+ }
144
+ var _default = exports.default = JSONSerialiser;
@@ -0,0 +1,140 @@
1
+ /**
2
+ * Serialized representation of an Element in JSON Refract format.
3
+ * @public
4
+ */
5
+
6
+ /**
7
+ * Serialized representation of a KeyValuePair in JSON Refract format.
8
+ * @public
9
+ */
10
+
11
+ /**
12
+ * Possible content types in a serialized element.
13
+ * @public
14
+ */
15
+
16
+ /**
17
+ * Input document format for deserialization.
18
+ * @public
19
+ */
20
+
21
+ /**
22
+ * JSONSerialiser handles serialization and deserialization of ApiDOM elements
23
+ * to and from JSON Refract format.
24
+ * @public
25
+ */
26
+ class JSONSerialiser {
27
+ namespace;
28
+
29
+ // This will be set via prototype assignment to avoid circular dependency
30
+
31
+ constructor(namespace) {
32
+ this.namespace = namespace || new this.Namespace();
33
+ }
34
+
35
+ /**
36
+ * Serializes an Element to JSON Refract format.
37
+ */
38
+ serialise(element) {
39
+ if (!(element instanceof this.namespace.elements.Element)) {
40
+ throw new TypeError(`Given element \`${element}\` is not an Element instance`);
41
+ }
42
+ const payload = {
43
+ element: element.element
44
+ };
45
+ if (element._meta && element._meta.length > 0) {
46
+ payload.meta = this.serialiseObject(element.meta);
47
+ }
48
+ if (element._attributes && element._attributes.length > 0) {
49
+ payload.attributes = this.serialiseObject(element.attributes);
50
+ }
51
+ const content = this.serialiseContent(element.content);
52
+ if (content !== undefined) {
53
+ payload.content = content;
54
+ }
55
+ return payload;
56
+ }
57
+
58
+ /**
59
+ * Deserializes a JSON Refract document to an Element.
60
+ */
61
+ deserialise(value) {
62
+ if (!value.element) {
63
+ throw new Error('Given value is not an object containing an element name');
64
+ }
65
+ const ElementClass = this.namespace.getElementClass(value.element);
66
+ const element = new ElementClass();
67
+ if (element.element !== value.element) {
68
+ element.element = value.element;
69
+ }
70
+ if (value.meta) {
71
+ this.deserialiseObject(value.meta, element.meta);
72
+ }
73
+ if (value.attributes) {
74
+ this.deserialiseObject(value.attributes, element.attributes);
75
+ }
76
+ const content = this.deserialiseContent(value.content);
77
+ if (content !== undefined || element.content === null) {
78
+ element.content = content;
79
+ }
80
+ return element;
81
+ }
82
+ serialiseContent(content) {
83
+ if (content instanceof this.namespace.elements.Element) {
84
+ return this.serialise(content);
85
+ }
86
+ if (content instanceof this.namespace.KeyValuePair) {
87
+ const kvp = content;
88
+ const pair = {
89
+ key: this.serialise(kvp.key)
90
+ };
91
+ if (kvp.value) {
92
+ pair.value = this.serialise(kvp.value);
93
+ }
94
+ return pair;
95
+ }
96
+ if (content && Array.isArray(content)) {
97
+ if (content.length === 0) {
98
+ return undefined;
99
+ }
100
+ return content.map(item => this.serialise(item));
101
+ }
102
+ return content;
103
+ }
104
+ deserialiseContent(content) {
105
+ if (content) {
106
+ if (content.element) {
107
+ return this.deserialise(content);
108
+ }
109
+ if (content.key) {
110
+ const pair = new this.namespace.KeyValuePair(this.deserialise(content.key));
111
+ if (content.value) {
112
+ pair.value = this.deserialise(content.value);
113
+ }
114
+ return pair;
115
+ }
116
+ if (Array.isArray(content)) {
117
+ return content.map(item => this.deserialise(item));
118
+ }
119
+ }
120
+ return content;
121
+ }
122
+ serialiseObject(obj) {
123
+ const result = {};
124
+ obj.forEach((value, key) => {
125
+ if (value) {
126
+ result[key.toValue()] = this.serialise(value);
127
+ }
128
+ });
129
+ if (Object.keys(result).length === 0) {
130
+ return undefined;
131
+ }
132
+ return result;
133
+ }
134
+ deserialiseObject(from, to) {
135
+ Object.keys(from).forEach(key => {
136
+ to.set(key, this.deserialise(from[key]));
137
+ });
138
+ }
139
+ }
140
+ export default JSONSerialiser;
package/src/types.cjs ADDED
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
package/src/types.mjs ADDED
@@ -0,0 +1 @@
1
+ export {};