@speclynx/apidom-core 3.2.1 → 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 (51) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/dist/apidom-core.browser.js +24 -20
  3. package/package.json +5 -5
  4. package/src/fields/fixed-fields.cjs +0 -47
  5. package/src/fields/fixed-fields.mjs +0 -43
  6. package/src/fields/index.cjs +0 -8
  7. package/src/fields/index.mjs +0 -1
  8. package/src/identity/errors/ElementIdentityError.cjs +0 -22
  9. package/src/identity/errors/ElementIdentityError.mjs +0 -19
  10. package/src/identity/index.cjs +0 -64
  11. package/src/identity/index.mjs +0 -58
  12. package/src/index.cjs +0 -48
  13. package/src/index.mjs +0 -41
  14. package/src/media-types.cjs +0 -21
  15. package/src/media-types.mjs +0 -18
  16. package/src/merge/deepmerge.cjs +0 -165
  17. package/src/merge/deepmerge.mjs +0 -149
  18. package/src/merge/merge-left.cjs +0 -16
  19. package/src/merge/merge-left.mjs +0 -11
  20. package/src/merge/merge-right.cjs +0 -35
  21. package/src/merge/merge-right.mjs +0 -29
  22. package/src/namespace.cjs +0 -10
  23. package/src/namespace.mjs +0 -7
  24. package/src/refractor/plugins/dispatcher/index.cjs +0 -64
  25. package/src/refractor/plugins/dispatcher/index.mjs +0 -54
  26. package/src/refractor/plugins/element-identity.cjs +0 -31
  27. package/src/refractor/plugins/element-identity.mjs +0 -26
  28. package/src/refractor/plugins/semantic-element-identity.cjs +0 -33
  29. package/src/refractor/plugins/semantic-element-identity.mjs +0 -29
  30. package/src/refractor/toolbox.cjs +0 -47
  31. package/src/refractor/toolbox.mjs +0 -41
  32. package/src/specification.cjs +0 -63
  33. package/src/specification.mjs +0 -59
  34. package/src/transcluder/Transcluder.cjs +0 -111
  35. package/src/transcluder/Transcluder.mjs +0 -107
  36. package/src/transcluder/index.cjs +0 -19
  37. package/src/transcluder/index.mjs +0 -13
  38. package/src/transformers/dehydrate.cjs +0 -15
  39. package/src/transformers/dehydrate.mjs +0 -10
  40. package/src/transformers/from.cjs +0 -34
  41. package/src/transformers/from.mjs +0 -29
  42. package/src/transformers/serializers/json.cjs +0 -75
  43. package/src/transformers/serializers/json.mjs +0 -70
  44. package/src/transformers/serializers/value.cjs +0 -50
  45. package/src/transformers/serializers/value.mjs +0 -47
  46. package/src/transformers/serializers/yaml-1-2.cjs +0 -142
  47. package/src/transformers/serializers/yaml-1-2.mjs +0 -137
  48. package/src/transformers/sexprs.cjs +0 -31
  49. package/src/transformers/sexprs.mjs +0 -28
  50. package/src/transformers/to-string.cjs +0 -16
  51. package/src/transformers/to-string.mjs +0 -11
@@ -1,70 +0,0 @@
1
- import { isElement, isObjectElement, isArrayElement, isRefElement, isLinkElement, isStringElement, isNumberElement } from '@speclynx/apidom-datamodel';
2
- import toValue from "./value.mjs";
3
- const getStyle = element => {
4
- return element.style?.json ?? {};
5
- };
6
-
7
- /**
8
- * @public
9
- */
10
-
11
- /**
12
- * Builds a POJO from an ApiDOM element tree. Numbers with rawContent
13
- * are replaced with sentinel strings; all other values go through toValue().
14
- */
15
- const toPojo = (element, sentinels) => {
16
- const visited = new WeakSet();
17
- const convert = node => {
18
- if (!isElement(node)) return node;
19
- if (visited.has(node)) return null;
20
- visited.add(node);
21
- if (isObjectElement(node)) {
22
- const obj = {};
23
- node.forEach((value, key) => {
24
- const k = isElement(key) ? toValue(key) : key;
25
- if (typeof k === 'string') obj[k] = convert(value);
26
- });
27
- return obj;
28
- }
29
- if (isArrayElement(node)) {
30
- const arr = [];
31
- node.forEach(item => arr.push(convert(item)));
32
- return arr;
33
- }
34
- if (isRefElement(node)) return String(toValue(node));
35
- if (isLinkElement(node)) return isStringElement(node.href) ? toValue(node.href) : '';
36
-
37
- // number with rawContent — substitute with sentinel
38
- if (isNumberElement(node)) {
39
- const style = getStyle(node);
40
- if (typeof style.rawContent === 'string') {
41
- const sentinel = `\0RAW${sentinels.size}\0`;
42
- sentinels.set(sentinel, style.rawContent);
43
- return sentinel;
44
- }
45
- }
46
- return toValue(node);
47
- };
48
- return convert(element);
49
- };
50
-
51
- /**
52
- * @public
53
- */
54
- const serializer = (element, replacer, space, options) => {
55
- if (options?.preserveStyle) {
56
- const style = getStyle(element);
57
- const indent = typeof space === 'number' ? space : typeof style.indent === 'number' ? style.indent : 0;
58
- const sentinels = new Map();
59
- const pojo = toPojo(element, sentinels);
60
- let serialized = JSON.stringify(pojo, null, indent);
61
-
62
- // replace quoted sentinels with raw number representations
63
- for (const [sentinel, raw] of sentinels) {
64
- serialized = serialized.replace(JSON.stringify(sentinel), raw);
65
- }
66
- return serialized;
67
- }
68
- return JSON.stringify(toValue(element), replacer, space);
69
- };
70
- export default serializer;
@@ -1,50 +0,0 @@
1
- "use strict";
2
-
3
- exports.__esModule = true;
4
- exports.default = void 0;
5
- var _apidomDatamodel = require("@speclynx/apidom-datamodel");
6
- /**
7
- * Transforms the ApiDOM into JavaScript POJO.
8
- * This POJO would be the result of interpreting the ApiDOM
9
- * into JavaScript structure.
10
- * @public
11
- */
12
- const serializer = element => {
13
- if (!(0, _apidomDatamodel.isElement)(element)) return element;
14
-
15
- // Shortcut optimization for primitive element types
16
- if ((0, _apidomDatamodel.isStringElement)(element) || (0, _apidomDatamodel.isNumberElement)(element) || (0, _apidomDatamodel.isBooleanElement)(element) || (0, _apidomDatamodel.isNullElement)(element)) {
17
- return element.toValue();
18
- }
19
-
20
- // WeakMap for cycle handling - stores references to already-visited elements
21
- const references = new WeakMap();
22
- const serialize = node => {
23
- if (!(0, _apidomDatamodel.isElement)(node)) return node;
24
- if ((0, _apidomDatamodel.isObjectElement)(node)) {
25
- if (references.has(node)) return references.get(node);
26
- const obj = {};
27
- references.set(node, obj);
28
- node.forEach((value, key) => {
29
- const k = serialize(key);
30
- const v = serialize(value);
31
- if (typeof k === 'string') obj[k] = v;
32
- });
33
- return obj;
34
- }
35
- if ((0, _apidomDatamodel.isArrayElement)(node)) {
36
- if (references.has(node)) return references.get(node);
37
- const arr = [];
38
- references.set(node, arr);
39
- node.forEach(item => arr.push(serialize(item)));
40
- return arr;
41
- }
42
- if ((0, _apidomDatamodel.isRefElement)(node)) return String(node.toValue());
43
- if ((0, _apidomDatamodel.isLinkElement)(node)) {
44
- return (0, _apidomDatamodel.isStringElement)(node.href) ? node.href.toValue() : '';
45
- }
46
- return node.toValue();
47
- };
48
- return serialize(element);
49
- };
50
- var _default = exports.default = serializer;
@@ -1,47 +0,0 @@
1
- import { isElement, isObjectElement, isArrayElement, isRefElement, isLinkElement, isStringElement, isBooleanElement, isNumberElement, isNullElement } from '@speclynx/apidom-datamodel';
2
-
3
- /**
4
- * Transforms the ApiDOM into JavaScript POJO.
5
- * This POJO would be the result of interpreting the ApiDOM
6
- * into JavaScript structure.
7
- * @public
8
- */
9
- const serializer = element => {
10
- if (!isElement(element)) return element;
11
-
12
- // Shortcut optimization for primitive element types
13
- if (isStringElement(element) || isNumberElement(element) || isBooleanElement(element) || isNullElement(element)) {
14
- return element.toValue();
15
- }
16
-
17
- // WeakMap for cycle handling - stores references to already-visited elements
18
- const references = new WeakMap();
19
- const serialize = node => {
20
- if (!isElement(node)) return node;
21
- if (isObjectElement(node)) {
22
- if (references.has(node)) return references.get(node);
23
- const obj = {};
24
- references.set(node, obj);
25
- node.forEach((value, key) => {
26
- const k = serialize(key);
27
- const v = serialize(value);
28
- if (typeof k === 'string') obj[k] = v;
29
- });
30
- return obj;
31
- }
32
- if (isArrayElement(node)) {
33
- if (references.has(node)) return references.get(node);
34
- const arr = [];
35
- references.set(node, arr);
36
- node.forEach(item => arr.push(serialize(item)));
37
- return arr;
38
- }
39
- if (isRefElement(node)) return String(node.toValue());
40
- if (isLinkElement(node)) {
41
- return isStringElement(node.href) ? node.href.toValue() : '';
42
- }
43
- return node.toValue();
44
- };
45
- return serialize(element);
46
- };
47
- export default serializer;
@@ -1,142 +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 _yaml = require("yaml");
7
- var _apidomDatamodel = require("@speclynx/apidom-datamodel");
8
- var _value = _interopRequireDefault(require("./value.cjs"));
9
- const getStyle = element => {
10
- return element.style?.yaml ?? {};
11
- };
12
-
13
- // map our scalarStyle strings to YAML library Scalar.Type constants
14
- const scalarStyleMap = {
15
- Plain: _yaml.Scalar.PLAIN,
16
- SingleQuoted: _yaml.Scalar.QUOTE_SINGLE,
17
- DoubleQuoted: _yaml.Scalar.QUOTE_DOUBLE,
18
- Literal: _yaml.Scalar.BLOCK_LITERAL,
19
- Folded: _yaml.Scalar.BLOCK_FOLDED
20
- };
21
-
22
- // the YAML library prefixes comments with '#' only (no space), so we add ' ' to get '# comment'
23
- const applyComments = (node, style) => {
24
- if (style.comment) node.comment = ` ${style.comment}`;
25
- if (style.commentBefore) node.commentBefore = ` ${style.commentBefore}`;
26
- };
27
-
28
- /**
29
- * @public
30
- */
31
-
32
- /**
33
- * Converts an ApiDOM element tree to YAML library AST nodes,
34
- * preserving style information from `element.style.yaml`.
35
- */
36
- const toYAMLNode = (element, visited) => {
37
- if (!(0, _apidomDatamodel.isElement)(element)) return element;
38
-
39
- // cycle detection
40
- if (visited.has(element)) return undefined;
41
- visited.add(element);
42
- const style = getStyle(element);
43
- if ((0, _apidomDatamodel.isObjectElement)(element)) {
44
- const map = new _yaml.YAMLMap();
45
- map.flow = style.styleGroup === 'Flow';
46
- applyComments(map, style);
47
- element.forEach((value, key, member) => {
48
- const memberStyle = (0, _apidomDatamodel.isMemberElement)(member) ? getStyle(member) : {};
49
- const keyNode = toYAMLNode(key, visited);
50
- const valueNode = toYAMLNode(value, visited);
51
- const pair = new _yaml.Pair(keyNode, valueNode);
52
- if (memberStyle.commentBefore && (0, _yaml.isNode)(keyNode)) {
53
- keyNode.commentBefore = ` ${memberStyle.commentBefore}`;
54
- }
55
- if (memberStyle.comment && (0, _yaml.isNode)(valueNode)) {
56
- valueNode.comment = ` ${memberStyle.comment}`;
57
- }
58
- map.items.push(pair);
59
- });
60
- return map;
61
- }
62
- if ((0, _apidomDatamodel.isArrayElement)(element)) {
63
- const seq = new _yaml.YAMLSeq();
64
- seq.flow = style.styleGroup === 'Flow';
65
- applyComments(seq, style);
66
- element.forEach(item => {
67
- seq.items.push(toYAMLNode(item, visited));
68
- });
69
- return seq;
70
- }
71
- if ((0, _apidomDatamodel.isRefElement)(element)) {
72
- return new _yaml.Scalar(String((0, _value.default)(element)));
73
- }
74
- if ((0, _apidomDatamodel.isLinkElement)(element)) {
75
- return new _yaml.Scalar((0, _apidomDatamodel.isStringElement)(element.href) ? (0, _value.default)(element.href) : '');
76
- }
77
-
78
- // scalar element (string, number, boolean, null)
79
- const scalarType = style.scalarStyle ? scalarStyleMap[style.scalarStyle] : undefined;
80
- const scalar = new _yaml.Scalar((0, _value.default)(element));
81
- if (scalarType) {
82
- scalar.type = scalarType;
83
- }
84
-
85
- // use rawContent to infer YAML library format hints for plain scalars that resolved to numbers;
86
- // only applies to Plain style — quoted scalars are always strings in YAML.
87
- // note: the YAML library may normalize the representation (e.g. 1.0e10 -> 1e+10, 0x1A -> 0x1a)
88
- // while preserving the format category (exponential, hex, octal, fractional digits)
89
- if (style.rawContent && style.scalarStyle === 'Plain' && typeof scalar.value === 'number') {
90
- if (/[eE]/.test(style.rawContent)) {
91
- scalar.format = 'EXP';
92
- } else if (/^0x/i.test(style.rawContent)) {
93
- scalar.format = 'HEX';
94
- } else if (/^0o/i.test(style.rawContent)) {
95
- scalar.format = 'OCT';
96
- }
97
- const dotMatch = style.rawContent.match(/\.(\d+)/);
98
- if (dotMatch) {
99
- scalar.minFractionDigits = dotMatch[1].length;
100
- }
101
- }
102
- applyComments(scalar, style);
103
- return scalar;
104
- };
105
-
106
- /**
107
- * @public
108
- */
109
- const serializer = (element, {
110
- directive = false,
111
- preserveStyle = false,
112
- aliasDuplicateObjects = false,
113
- ...options
114
- } = {}) => {
115
- const allOptions = {
116
- aliasDuplicateObjects,
117
- ...options
118
- };
119
- if (preserveStyle) {
120
- const style = getStyle(element);
121
- if (options.indent === undefined && typeof style.indent === 'number') {
122
- allOptions.indent = style.indent;
123
- }
124
- if (typeof style.flowCollectionPadding === 'boolean') {
125
- allOptions.flowCollectionPadding = style.flowCollectionPadding;
126
- }
127
- const rootNode = toYAMLNode(element, new WeakSet());
128
- const doc = new _yaml.Document(undefined, allOptions);
129
- doc.contents = rootNode;
130
- if (directive) {
131
- doc.directives.yaml.explicit = true;
132
- }
133
- return doc.toString(allOptions);
134
- }
135
- if (directive) {
136
- const doc = new _yaml.Document((0, _value.default)(element), allOptions);
137
- doc.directives.yaml.explicit = true;
138
- return doc.toString(allOptions);
139
- }
140
- return (0, _yaml.stringify)((0, _value.default)(element), allOptions);
141
- };
142
- var _default = exports.default = serializer;
@@ -1,137 +0,0 @@
1
- import { Document, stringify, isNode, Scalar, YAMLMap, YAMLSeq, Pair } from 'yaml';
2
- import { isElement, isObjectElement, isArrayElement, isRefElement, isLinkElement, isStringElement, isMemberElement } from '@speclynx/apidom-datamodel';
3
- import toValue from "./value.mjs";
4
- const getStyle = element => {
5
- return element.style?.yaml ?? {};
6
- };
7
-
8
- // map our scalarStyle strings to YAML library Scalar.Type constants
9
- const scalarStyleMap = {
10
- Plain: Scalar.PLAIN,
11
- SingleQuoted: Scalar.QUOTE_SINGLE,
12
- DoubleQuoted: Scalar.QUOTE_DOUBLE,
13
- Literal: Scalar.BLOCK_LITERAL,
14
- Folded: Scalar.BLOCK_FOLDED
15
- };
16
-
17
- // the YAML library prefixes comments with '#' only (no space), so we add ' ' to get '# comment'
18
- const applyComments = (node, style) => {
19
- if (style.comment) node.comment = ` ${style.comment}`;
20
- if (style.commentBefore) node.commentBefore = ` ${style.commentBefore}`;
21
- };
22
-
23
- /**
24
- * @public
25
- */
26
-
27
- /**
28
- * Converts an ApiDOM element tree to YAML library AST nodes,
29
- * preserving style information from `element.style.yaml`.
30
- */
31
- const toYAMLNode = (element, visited) => {
32
- if (!isElement(element)) return element;
33
-
34
- // cycle detection
35
- if (visited.has(element)) return undefined;
36
- visited.add(element);
37
- const style = getStyle(element);
38
- if (isObjectElement(element)) {
39
- const map = new YAMLMap();
40
- map.flow = style.styleGroup === 'Flow';
41
- applyComments(map, style);
42
- element.forEach((value, key, member) => {
43
- const memberStyle = isMemberElement(member) ? getStyle(member) : {};
44
- const keyNode = toYAMLNode(key, visited);
45
- const valueNode = toYAMLNode(value, visited);
46
- const pair = new Pair(keyNode, valueNode);
47
- if (memberStyle.commentBefore && isNode(keyNode)) {
48
- keyNode.commentBefore = ` ${memberStyle.commentBefore}`;
49
- }
50
- if (memberStyle.comment && isNode(valueNode)) {
51
- valueNode.comment = ` ${memberStyle.comment}`;
52
- }
53
- map.items.push(pair);
54
- });
55
- return map;
56
- }
57
- if (isArrayElement(element)) {
58
- const seq = new YAMLSeq();
59
- seq.flow = style.styleGroup === 'Flow';
60
- applyComments(seq, style);
61
- element.forEach(item => {
62
- seq.items.push(toYAMLNode(item, visited));
63
- });
64
- return seq;
65
- }
66
- if (isRefElement(element)) {
67
- return new Scalar(String(toValue(element)));
68
- }
69
- if (isLinkElement(element)) {
70
- return new Scalar(isStringElement(element.href) ? toValue(element.href) : '');
71
- }
72
-
73
- // scalar element (string, number, boolean, null)
74
- const scalarType = style.scalarStyle ? scalarStyleMap[style.scalarStyle] : undefined;
75
- const scalar = new Scalar(toValue(element));
76
- if (scalarType) {
77
- scalar.type = scalarType;
78
- }
79
-
80
- // use rawContent to infer YAML library format hints for plain scalars that resolved to numbers;
81
- // only applies to Plain style — quoted scalars are always strings in YAML.
82
- // note: the YAML library may normalize the representation (e.g. 1.0e10 -> 1e+10, 0x1A -> 0x1a)
83
- // while preserving the format category (exponential, hex, octal, fractional digits)
84
- if (style.rawContent && style.scalarStyle === 'Plain' && typeof scalar.value === 'number') {
85
- if (/[eE]/.test(style.rawContent)) {
86
- scalar.format = 'EXP';
87
- } else if (/^0x/i.test(style.rawContent)) {
88
- scalar.format = 'HEX';
89
- } else if (/^0o/i.test(style.rawContent)) {
90
- scalar.format = 'OCT';
91
- }
92
- const dotMatch = style.rawContent.match(/\.(\d+)/);
93
- if (dotMatch) {
94
- scalar.minFractionDigits = dotMatch[1].length;
95
- }
96
- }
97
- applyComments(scalar, style);
98
- return scalar;
99
- };
100
-
101
- /**
102
- * @public
103
- */
104
- const serializer = (element, {
105
- directive = false,
106
- preserveStyle = false,
107
- aliasDuplicateObjects = false,
108
- ...options
109
- } = {}) => {
110
- const allOptions = {
111
- aliasDuplicateObjects,
112
- ...options
113
- };
114
- if (preserveStyle) {
115
- const style = getStyle(element);
116
- if (options.indent === undefined && typeof style.indent === 'number') {
117
- allOptions.indent = style.indent;
118
- }
119
- if (typeof style.flowCollectionPadding === 'boolean') {
120
- allOptions.flowCollectionPadding = style.flowCollectionPadding;
121
- }
122
- const rootNode = toYAMLNode(element, new WeakSet());
123
- const doc = new Document(undefined, allOptions);
124
- doc.contents = rootNode;
125
- if (directive) {
126
- doc.directives.yaml.explicit = true;
127
- }
128
- return doc.toString(allOptions);
129
- }
130
- if (directive) {
131
- const doc = new Document(toValue(element), allOptions);
132
- doc.directives.yaml.explicit = true;
133
- return doc.toString(allOptions);
134
- }
135
- return stringify(toValue(element), allOptions);
136
- };
137
- export default serializer;
@@ -1,31 +0,0 @@
1
- "use strict";
2
-
3
- exports.__esModule = true;
4
- exports.default = void 0;
5
- var _apidomTraverse = require("@speclynx/apidom-traverse");
6
- /**
7
- * Transforms ApiDOM into S-expressions (Symbolic Expressions).
8
- * @public
9
- */
10
- const sexprs = element => {
11
- let result = '';
12
- let nestingLevel = 0;
13
- (0, _apidomTraverse.traverse)(element, {
14
- enter(path) {
15
- const {
16
- element: elementName
17
- } = path.node;
18
- const capitalizedElementName = elementName.charAt(0).toUpperCase() + elementName.slice(1);
19
- const indent = ' '.repeat(nestingLevel);
20
- result += nestingLevel > 0 ? '\n' : '';
21
- result += `${indent}(${capitalizedElementName}Element`;
22
- nestingLevel += 1;
23
- },
24
- leave() {
25
- nestingLevel -= 1;
26
- result += ')';
27
- }
28
- });
29
- return result;
30
- };
31
- var _default = exports.default = sexprs;
@@ -1,28 +0,0 @@
1
- import { traverse } from '@speclynx/apidom-traverse';
2
-
3
- /**
4
- * Transforms ApiDOM into S-expressions (Symbolic Expressions).
5
- * @public
6
- */
7
- const sexprs = element => {
8
- let result = '';
9
- let nestingLevel = 0;
10
- traverse(element, {
11
- enter(path) {
12
- const {
13
- element: elementName
14
- } = path.node;
15
- const capitalizedElementName = elementName.charAt(0).toUpperCase() + elementName.slice(1);
16
- const indent = ' '.repeat(nestingLevel);
17
- result += nestingLevel > 0 ? '\n' : '';
18
- result += `${indent}(${capitalizedElementName}Element`;
19
- nestingLevel += 1;
20
- },
21
- leave() {
22
- nestingLevel -= 1;
23
- result += ')';
24
- }
25
- });
26
- return result;
27
- };
28
- export default sexprs;
@@ -1,16 +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 _namespace = _interopRequireDefault(require("../namespace.cjs"));
7
- var _dehydrate = _interopRequireDefault(require("./dehydrate.cjs"));
8
- /**
9
- * Create a refracted string representation of an Element.
10
- * @public
11
- */
12
- const toString = (element, namespace = _namespace.default) => {
13
- const refractStructure = (0, _dehydrate.default)(element, namespace);
14
- return JSON.stringify(refractStructure);
15
- };
16
- var _default = exports.default = toString;
@@ -1,11 +0,0 @@
1
- import defaultNamespace from "../namespace.mjs";
2
- import dehydrate from "./dehydrate.mjs";
3
- /**
4
- * Create a refracted string representation of an Element.
5
- * @public
6
- */
7
- const toString = (element, namespace = defaultNamespace) => {
8
- const refractStructure = dehydrate(element, namespace);
9
- return JSON.stringify(refractStructure);
10
- };
11
- export default toString;