@speclynx/apidom-core 4.0.2 → 4.0.4
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.
- package/CHANGELOG.md +12 -0
- package/package.json +5 -5
- package/src/fields/fixed-fields.cjs +47 -0
- package/src/fields/fixed-fields.mjs +43 -0
- package/src/fields/index.cjs +8 -0
- package/src/fields/index.mjs +1 -0
- package/src/identity/errors/ElementIdentityError.cjs +22 -0
- package/src/identity/errors/ElementIdentityError.mjs +19 -0
- package/src/identity/index.cjs +64 -0
- package/src/identity/index.mjs +58 -0
- package/src/index.cjs +48 -0
- package/src/index.mjs +41 -0
- package/src/media-types.cjs +21 -0
- package/src/media-types.mjs +18 -0
- package/src/merge/deepmerge.cjs +165 -0
- package/src/merge/deepmerge.mjs +149 -0
- package/src/merge/merge-left.cjs +16 -0
- package/src/merge/merge-left.mjs +11 -0
- package/src/merge/merge-right.cjs +35 -0
- package/src/merge/merge-right.mjs +29 -0
- package/src/namespace.cjs +10 -0
- package/src/namespace.mjs +7 -0
- package/src/refractor/plugins/dispatcher/index.cjs +64 -0
- package/src/refractor/plugins/dispatcher/index.mjs +54 -0
- package/src/refractor/plugins/element-identity.cjs +31 -0
- package/src/refractor/plugins/element-identity.mjs +26 -0
- package/src/refractor/plugins/semantic-element-identity.cjs +33 -0
- package/src/refractor/plugins/semantic-element-identity.mjs +29 -0
- package/src/refractor/toolbox.cjs +47 -0
- package/src/refractor/toolbox.mjs +41 -0
- package/src/specification.cjs +63 -0
- package/src/specification.mjs +59 -0
- package/src/transcluder/Transcluder.cjs +111 -0
- package/src/transcluder/Transcluder.mjs +107 -0
- package/src/transcluder/index.cjs +19 -0
- package/src/transcluder/index.mjs +13 -0
- package/src/transformers/dehydrate.cjs +15 -0
- package/src/transformers/dehydrate.mjs +10 -0
- package/src/transformers/from.cjs +34 -0
- package/src/transformers/from.mjs +29 -0
- package/src/transformers/serializers/json.cjs +75 -0
- package/src/transformers/serializers/json.mjs +70 -0
- package/src/transformers/serializers/value.cjs +50 -0
- package/src/transformers/serializers/value.mjs +47 -0
- package/src/transformers/serializers/yaml-1-2.cjs +142 -0
- package/src/transformers/serializers/yaml-1-2.mjs +137 -0
- package/src/transformers/sexprs.cjs +31 -0
- package/src/transformers/sexprs.mjs +28 -0
- package/src/transformers/to-string.cjs +16 -0
- package/src/transformers/to-string.mjs +11 -0
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { ObjectElement, isObjectElement, isArrayElement, cloneDeep, cloneShallow } from '@speclynx/apidom-datamodel';
|
|
2
|
+
import toValue from "../transformers/serializers/value.mjs";
|
|
3
|
+
/**
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* @public
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* @public
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* @public
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* @public
|
|
20
|
+
*/
|
|
21
|
+
/**
|
|
22
|
+
* @public
|
|
23
|
+
*/
|
|
24
|
+
/**
|
|
25
|
+
* @public
|
|
26
|
+
*/
|
|
27
|
+
/**
|
|
28
|
+
* @public
|
|
29
|
+
*/
|
|
30
|
+
/**
|
|
31
|
+
* @public
|
|
32
|
+
*/
|
|
33
|
+
export const emptyElement = element => {
|
|
34
|
+
const meta = !element.isMetaEmpty ? element.meta.cloneDeep() : undefined;
|
|
35
|
+
const attributes = !element.isAttributesEmpty ? cloneDeep(element.attributes) : undefined;
|
|
36
|
+
|
|
37
|
+
// @ts-ignore
|
|
38
|
+
return new element.constructor(undefined, meta, attributes);
|
|
39
|
+
};
|
|
40
|
+
const cloneUnlessOtherwiseSpecified = (element, options) => options.clone && options.isMergeableElement(element) ? deepmerge(emptyElement(element), element, options) : element;
|
|
41
|
+
const getMergeFunction = (keyElement, options) => {
|
|
42
|
+
if (typeof options.customMerge !== 'function') {
|
|
43
|
+
return deepmerge;
|
|
44
|
+
}
|
|
45
|
+
const customMerge = options.customMerge(keyElement, options);
|
|
46
|
+
return typeof customMerge === 'function' ? customMerge : deepmerge;
|
|
47
|
+
};
|
|
48
|
+
const getMetaMergeFunction = options => {
|
|
49
|
+
if (typeof options.customMetaMerge !== 'function') {
|
|
50
|
+
return targetMeta => targetMeta.cloneDeep();
|
|
51
|
+
}
|
|
52
|
+
return options.customMetaMerge;
|
|
53
|
+
};
|
|
54
|
+
const getAttributesMergeFunction = options => {
|
|
55
|
+
if (typeof options.customAttributesMerge !== 'function') {
|
|
56
|
+
return targetAttributes => cloneDeep(targetAttributes);
|
|
57
|
+
}
|
|
58
|
+
return options.customAttributesMerge;
|
|
59
|
+
};
|
|
60
|
+
const mergeArrayElement = (targetElement, sourceElement, options) => {
|
|
61
|
+
const Ctor = targetElement.constructor;
|
|
62
|
+
const merged = targetElement.concat(sourceElement);
|
|
63
|
+
return new Ctor(merged.map(item => cloneUnlessOtherwiseSpecified(item, options)));
|
|
64
|
+
};
|
|
65
|
+
const mergeObjectElement = (targetElement, sourceElement, options) => {
|
|
66
|
+
const destination = isObjectElement(targetElement) ? emptyElement(targetElement) : emptyElement(sourceElement);
|
|
67
|
+
if (isObjectElement(targetElement)) {
|
|
68
|
+
targetElement.forEach((value, key, member) => {
|
|
69
|
+
const clonedMember = cloneShallow(member);
|
|
70
|
+
clonedMember.value = cloneUnlessOtherwiseSpecified(value, options);
|
|
71
|
+
destination.content.push(clonedMember);
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
sourceElement.forEach((value, key, member) => {
|
|
75
|
+
const keyValue = toValue(key);
|
|
76
|
+
let clonedMember;
|
|
77
|
+
if (isObjectElement(targetElement) && targetElement.hasKey(keyValue) && options.isMergeableElement(value)) {
|
|
78
|
+
const targetValue = targetElement.get(keyValue);
|
|
79
|
+
clonedMember = cloneShallow(member);
|
|
80
|
+
clonedMember.value = getMergeFunction(key, options)(targetValue, value, options);
|
|
81
|
+
} else {
|
|
82
|
+
clonedMember = cloneShallow(member);
|
|
83
|
+
clonedMember.value = cloneUnlessOtherwiseSpecified(value, options);
|
|
84
|
+
}
|
|
85
|
+
destination.remove(keyValue);
|
|
86
|
+
destination.content.push(clonedMember);
|
|
87
|
+
});
|
|
88
|
+
return destination;
|
|
89
|
+
};
|
|
90
|
+
export const defaultOptions = {
|
|
91
|
+
clone: true,
|
|
92
|
+
isMergeableElement: element => isObjectElement(element) || isArrayElement(element),
|
|
93
|
+
arrayElementMerge: mergeArrayElement,
|
|
94
|
+
objectElementMerge: mergeObjectElement,
|
|
95
|
+
customMerge: undefined,
|
|
96
|
+
customMetaMerge: undefined,
|
|
97
|
+
customAttributesMerge: undefined
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* @public
|
|
102
|
+
*/
|
|
103
|
+
const deepmerge = (targetElement, sourceElement, options) => {
|
|
104
|
+
const mergedOptions = {
|
|
105
|
+
...defaultOptions,
|
|
106
|
+
...options
|
|
107
|
+
};
|
|
108
|
+
mergedOptions.isMergeableElement = mergedOptions.isMergeableElement ?? defaultOptions.isMergeableElement;
|
|
109
|
+
mergedOptions.arrayElementMerge = mergedOptions.arrayElementMerge ?? defaultOptions.arrayElementMerge;
|
|
110
|
+
mergedOptions.objectElementMerge = mergedOptions.objectElementMerge ?? defaultOptions.objectElementMerge;
|
|
111
|
+
const sourceIsArrayElement = isArrayElement(sourceElement);
|
|
112
|
+
const targetIsArrayElement = isArrayElement(targetElement);
|
|
113
|
+
const sourceAndTargetTypesMatch = sourceIsArrayElement === targetIsArrayElement;
|
|
114
|
+
if (!sourceAndTargetTypesMatch) {
|
|
115
|
+
return cloneUnlessOtherwiseSpecified(sourceElement, mergedOptions);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// merging two elements
|
|
119
|
+
const mergedElement = sourceIsArrayElement && typeof mergedOptions.arrayElementMerge === 'function' ? mergedOptions.arrayElementMerge(targetElement, sourceElement, mergedOptions) : mergedOptions.objectElementMerge(targetElement, sourceElement, mergedOptions);
|
|
120
|
+
|
|
121
|
+
// merging meta & attributes
|
|
122
|
+
if (!targetElement.isMetaEmpty && !sourceElement.isMetaEmpty) {
|
|
123
|
+
mergedElement.meta = getMetaMergeFunction(mergedOptions)(targetElement.meta, sourceElement.meta);
|
|
124
|
+
} else if (!targetElement.isMetaEmpty) {
|
|
125
|
+
mergedElement.meta = targetElement.meta.cloneDeep();
|
|
126
|
+
} else if (!sourceElement.isMetaEmpty) {
|
|
127
|
+
mergedElement.meta = sourceElement.meta.cloneDeep();
|
|
128
|
+
}
|
|
129
|
+
if (!targetElement.isAttributesEmpty && !sourceElement.isAttributesEmpty) {
|
|
130
|
+
mergedElement.attributes = getAttributesMergeFunction(mergedOptions)(targetElement.attributes, sourceElement.attributes);
|
|
131
|
+
} else if (!targetElement.isAttributesEmpty) {
|
|
132
|
+
mergedElement.attributes = cloneDeep(targetElement.attributes);
|
|
133
|
+
} else if (!sourceElement.isAttributesEmpty) {
|
|
134
|
+
mergedElement.attributes = cloneDeep(sourceElement.attributes);
|
|
135
|
+
}
|
|
136
|
+
return mergedElement;
|
|
137
|
+
};
|
|
138
|
+
deepmerge.all = (list, options) => {
|
|
139
|
+
if (!Array.isArray(list)) {
|
|
140
|
+
throw new TypeError('First argument of deepmerge should be an array.');
|
|
141
|
+
}
|
|
142
|
+
if (list.length === 0) {
|
|
143
|
+
return new ObjectElement();
|
|
144
|
+
}
|
|
145
|
+
return list.reduce((target, source) => {
|
|
146
|
+
return deepmerge(target, source, options);
|
|
147
|
+
}, emptyElement(list[0]));
|
|
148
|
+
};
|
|
149
|
+
export default deepmerge;
|
|
@@ -0,0 +1,16 @@
|
|
|
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 _mergeRight = _interopRequireDefault(require("./merge-right.cjs"));
|
|
7
|
+
/**
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
const mergeLeft = (...[sourceElement, targetElement, options]) => {
|
|
11
|
+
return (0, _mergeRight.default)(targetElement, sourceElement, options);
|
|
12
|
+
};
|
|
13
|
+
mergeLeft.all = (...[list, options]) => {
|
|
14
|
+
return _mergeRight.default.all([...list].reverse(), options);
|
|
15
|
+
};
|
|
16
|
+
var _default = exports.default = mergeLeft;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import mergeRight from "./merge-right.mjs";
|
|
2
|
+
/**
|
|
3
|
+
* @public
|
|
4
|
+
*/
|
|
5
|
+
const mergeLeft = (...[sourceElement, targetElement, options]) => {
|
|
6
|
+
return mergeRight(targetElement, sourceElement, options);
|
|
7
|
+
};
|
|
8
|
+
mergeLeft.all = (...[list, options]) => {
|
|
9
|
+
return mergeRight.all([...list].reverse(), options);
|
|
10
|
+
};
|
|
11
|
+
export default mergeLeft;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireWildcard = require("@babel/runtime-corejs3/helpers/interopRequireWildcard").default;
|
|
4
|
+
exports.__esModule = true;
|
|
5
|
+
exports.default = void 0;
|
|
6
|
+
var _apidomDatamodel = require("@speclynx/apidom-datamodel");
|
|
7
|
+
var _deepmerge = _interopRequireWildcard(require("./deepmerge.cjs"));
|
|
8
|
+
/**
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @public
|
|
14
|
+
*/
|
|
15
|
+
const mergeRight = (targetElement, sourceElement, options) => {
|
|
16
|
+
const mergedOptions = {
|
|
17
|
+
..._deepmerge.defaultOptions,
|
|
18
|
+
...options,
|
|
19
|
+
customMerge: () => (target, source) => source,
|
|
20
|
+
clone: false
|
|
21
|
+
};
|
|
22
|
+
return (0, _deepmerge.default)(targetElement, sourceElement, mergedOptions);
|
|
23
|
+
};
|
|
24
|
+
mergeRight.all = (list, options) => {
|
|
25
|
+
if (!Array.isArray(list)) {
|
|
26
|
+
throw new TypeError('First argument of mergeRight should be an array.');
|
|
27
|
+
}
|
|
28
|
+
if (list.length === 0) {
|
|
29
|
+
return new _apidomDatamodel.ObjectElement();
|
|
30
|
+
}
|
|
31
|
+
return list.reduce((target, source) => {
|
|
32
|
+
return mergeRight(target, source, options);
|
|
33
|
+
}, (0, _deepmerge.emptyElement)(list[0]));
|
|
34
|
+
};
|
|
35
|
+
var _default = exports.default = mergeRight;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { ObjectElement } from '@speclynx/apidom-datamodel';
|
|
2
|
+
import deepmerge, { defaultOptions as defaultDeepmergeOptions, emptyElement } from "./deepmerge.mjs";
|
|
3
|
+
/**
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
const mergeRight = (targetElement, sourceElement, options) => {
|
|
10
|
+
const mergedOptions = {
|
|
11
|
+
...defaultDeepmergeOptions,
|
|
12
|
+
...options,
|
|
13
|
+
customMerge: () => (target, source) => source,
|
|
14
|
+
clone: false
|
|
15
|
+
};
|
|
16
|
+
return deepmerge(targetElement, sourceElement, mergedOptions);
|
|
17
|
+
};
|
|
18
|
+
mergeRight.all = (list, options) => {
|
|
19
|
+
if (!Array.isArray(list)) {
|
|
20
|
+
throw new TypeError('First argument of mergeRight should be an array.');
|
|
21
|
+
}
|
|
22
|
+
if (list.length === 0) {
|
|
23
|
+
return new ObjectElement();
|
|
24
|
+
}
|
|
25
|
+
return list.reduce((target, source) => {
|
|
26
|
+
return mergeRight(target, source, options);
|
|
27
|
+
}, emptyElement(list[0]));
|
|
28
|
+
};
|
|
29
|
+
export default mergeRight;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.default = void 0;
|
|
5
|
+
var _apidomDatamodel = require("@speclynx/apidom-datamodel");
|
|
6
|
+
/**
|
|
7
|
+
* Default namespace instance with all base elements registered.
|
|
8
|
+
*/
|
|
9
|
+
const namespace = new _apidomDatamodel.Namespace();
|
|
10
|
+
var _default = exports.default = namespace;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
|
|
4
|
+
exports.__esModule = true;
|
|
5
|
+
exports.dispatchPluginsSync = exports.dispatchPluginsAsync = void 0;
|
|
6
|
+
var _apidomTraverse = require("@speclynx/apidom-traverse");
|
|
7
|
+
var _ramda = require("ramda");
|
|
8
|
+
var _ramdaAdjunct = require("ramda-adjunct");
|
|
9
|
+
var _toolbox = _interopRequireDefault(require("../../toolbox.cjs"));
|
|
10
|
+
/**
|
|
11
|
+
* @public
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @public
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @public
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
const defaultDispatchPluginsOptions = {
|
|
23
|
+
toolboxCreator: _toolbox.default,
|
|
24
|
+
visitorOptions: {
|
|
25
|
+
exposeEdits: true
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* @public
|
|
31
|
+
*/
|
|
32
|
+
const dispatchPluginsSync = (element, plugins, options = {}) => {
|
|
33
|
+
if (plugins.length === 0) return element;
|
|
34
|
+
const mergedOptions = (0, _ramda.mergeDeepRight)(defaultDispatchPluginsOptions, options);
|
|
35
|
+
const {
|
|
36
|
+
toolboxCreator,
|
|
37
|
+
visitorOptions
|
|
38
|
+
} = mergedOptions;
|
|
39
|
+
const toolbox = toolboxCreator();
|
|
40
|
+
const pluginsSpecs = plugins.map(plugin => plugin(toolbox));
|
|
41
|
+
const mergedPluginsVisitor = (0, _apidomTraverse.mergeVisitors)(pluginsSpecs.map((0, _ramda.propOr)({}, 'visitor')), visitorOptions);
|
|
42
|
+
pluginsSpecs.forEach((0, _ramdaAdjunct.invokeArgs)(['pre'], []));
|
|
43
|
+
const newElement = (0, _apidomTraverse.traverse)(element, mergedPluginsVisitor);
|
|
44
|
+
pluginsSpecs.forEach((0, _ramdaAdjunct.invokeArgs)(['post'], []));
|
|
45
|
+
return newElement;
|
|
46
|
+
};
|
|
47
|
+
exports.dispatchPluginsSync = dispatchPluginsSync;
|
|
48
|
+
const dispatchPluginsAsync = async (element, plugins, options = {}) => {
|
|
49
|
+
if (plugins.length === 0) return element;
|
|
50
|
+
const mergedOptions = (0, _ramda.mergeDeepRight)(defaultDispatchPluginsOptions, options);
|
|
51
|
+
const {
|
|
52
|
+
toolboxCreator,
|
|
53
|
+
visitorOptions
|
|
54
|
+
} = mergedOptions;
|
|
55
|
+
const toolbox = toolboxCreator();
|
|
56
|
+
const pluginsSpecs = plugins.map(plugin => plugin(toolbox));
|
|
57
|
+
const mergedPluginsVisitor = (0, _apidomTraverse.mergeVisitorsAsync)(pluginsSpecs.map((0, _ramda.propOr)({}, 'visitor')), visitorOptions);
|
|
58
|
+
await Promise.allSettled(pluginsSpecs.map((0, _ramdaAdjunct.invokeArgs)(['pre'], [])));
|
|
59
|
+
const newElement = await (0, _apidomTraverse.traverseAsync)(element, mergedPluginsVisitor);
|
|
60
|
+
await Promise.allSettled(pluginsSpecs.map((0, _ramdaAdjunct.invokeArgs)(['post'], [])));
|
|
61
|
+
return newElement;
|
|
62
|
+
};
|
|
63
|
+
exports.dispatchPluginsAsync = dispatchPluginsAsync;
|
|
64
|
+
dispatchPluginsSync[Symbol.for('nodejs.util.promisify.custom')] = dispatchPluginsAsync;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { traverse, traverseAsync, mergeVisitors, mergeVisitorsAsync } from '@speclynx/apidom-traverse';
|
|
2
|
+
import { mergeDeepRight, propOr } from 'ramda';
|
|
3
|
+
import { invokeArgs } from 'ramda-adjunct';
|
|
4
|
+
import createToolbox from "../../toolbox.mjs";
|
|
5
|
+
/**
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* @public
|
|
13
|
+
*/
|
|
14
|
+
const defaultDispatchPluginsOptions = {
|
|
15
|
+
toolboxCreator: createToolbox,
|
|
16
|
+
visitorOptions: {
|
|
17
|
+
exposeEdits: true
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @public
|
|
23
|
+
*/
|
|
24
|
+
export const dispatchPluginsSync = (element, plugins, options = {}) => {
|
|
25
|
+
if (plugins.length === 0) return element;
|
|
26
|
+
const mergedOptions = mergeDeepRight(defaultDispatchPluginsOptions, options);
|
|
27
|
+
const {
|
|
28
|
+
toolboxCreator,
|
|
29
|
+
visitorOptions
|
|
30
|
+
} = mergedOptions;
|
|
31
|
+
const toolbox = toolboxCreator();
|
|
32
|
+
const pluginsSpecs = plugins.map(plugin => plugin(toolbox));
|
|
33
|
+
const mergedPluginsVisitor = mergeVisitors(pluginsSpecs.map(propOr({}, 'visitor')), visitorOptions);
|
|
34
|
+
pluginsSpecs.forEach(invokeArgs(['pre'], []));
|
|
35
|
+
const newElement = traverse(element, mergedPluginsVisitor);
|
|
36
|
+
pluginsSpecs.forEach(invokeArgs(['post'], []));
|
|
37
|
+
return newElement;
|
|
38
|
+
};
|
|
39
|
+
export const dispatchPluginsAsync = async (element, plugins, options = {}) => {
|
|
40
|
+
if (plugins.length === 0) return element;
|
|
41
|
+
const mergedOptions = mergeDeepRight(defaultDispatchPluginsOptions, options);
|
|
42
|
+
const {
|
|
43
|
+
toolboxCreator,
|
|
44
|
+
visitorOptions
|
|
45
|
+
} = mergedOptions;
|
|
46
|
+
const toolbox = toolboxCreator();
|
|
47
|
+
const pluginsSpecs = plugins.map(plugin => plugin(toolbox));
|
|
48
|
+
const mergedPluginsVisitor = mergeVisitorsAsync(pluginsSpecs.map(propOr({}, 'visitor')), visitorOptions);
|
|
49
|
+
await Promise.allSettled(pluginsSpecs.map(invokeArgs(['pre'], [])));
|
|
50
|
+
const newElement = await traverseAsync(element, mergedPluginsVisitor);
|
|
51
|
+
await Promise.allSettled(pluginsSpecs.map(invokeArgs(['post'], [])));
|
|
52
|
+
return newElement;
|
|
53
|
+
};
|
|
54
|
+
dispatchPluginsSync[Symbol.for('nodejs.util.promisify.custom')] = dispatchPluginsAsync;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.default = void 0;
|
|
5
|
+
var _index = require("../../identity/index.cjs");
|
|
6
|
+
/**
|
|
7
|
+
* Plugin for decorating every element in ApiDOM tree with UUID.
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
const plugin = ({
|
|
12
|
+
length = 6
|
|
13
|
+
} = {}) => () => {
|
|
14
|
+
let identityManager;
|
|
15
|
+
return {
|
|
16
|
+
pre() {
|
|
17
|
+
identityManager = new _index.IdentityManager({
|
|
18
|
+
length
|
|
19
|
+
});
|
|
20
|
+
},
|
|
21
|
+
visitor: {
|
|
22
|
+
enter(path) {
|
|
23
|
+
path.node.id = identityManager.identify(path.node);
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
post() {
|
|
27
|
+
identityManager = null;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
var _default = exports.default = plugin;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { IdentityManager } from "../../identity/index.mjs";
|
|
2
|
+
/**
|
|
3
|
+
* Plugin for decorating every element in ApiDOM tree with UUID.
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
6
|
+
const plugin = ({
|
|
7
|
+
length = 6
|
|
8
|
+
} = {}) => () => {
|
|
9
|
+
let identityManager;
|
|
10
|
+
return {
|
|
11
|
+
pre() {
|
|
12
|
+
identityManager = new IdentityManager({
|
|
13
|
+
length
|
|
14
|
+
});
|
|
15
|
+
},
|
|
16
|
+
visitor: {
|
|
17
|
+
enter(path) {
|
|
18
|
+
path.node.id = identityManager.identify(path.node);
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
post() {
|
|
22
|
+
identityManager = null;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
export default plugin;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.default = void 0;
|
|
5
|
+
var _apidomDatamodel = require("@speclynx/apidom-datamodel");
|
|
6
|
+
var _index = require("../../identity/index.cjs");
|
|
7
|
+
/**
|
|
8
|
+
* Plugin for decorating every semantic element in ApiDOM tree with UUID.
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
11
|
+
const plugin = ({
|
|
12
|
+
length = 6
|
|
13
|
+
} = {}) => () => {
|
|
14
|
+
let identityManager;
|
|
15
|
+
return {
|
|
16
|
+
pre() {
|
|
17
|
+
identityManager = new _index.IdentityManager({
|
|
18
|
+
length
|
|
19
|
+
});
|
|
20
|
+
},
|
|
21
|
+
visitor: {
|
|
22
|
+
enter(path) {
|
|
23
|
+
if (!(0, _apidomDatamodel.isPrimitiveElement)(path.node)) {
|
|
24
|
+
path.node.id = identityManager.identify(path.node);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
post() {
|
|
29
|
+
identityManager = null;
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
var _default = exports.default = plugin;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { isPrimitiveElement } from '@speclynx/apidom-datamodel';
|
|
2
|
+
import { IdentityManager } from "../../identity/index.mjs";
|
|
3
|
+
/**
|
|
4
|
+
* Plugin for decorating every semantic element in ApiDOM tree with UUID.
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
const plugin = ({
|
|
8
|
+
length = 6
|
|
9
|
+
} = {}) => () => {
|
|
10
|
+
let identityManager;
|
|
11
|
+
return {
|
|
12
|
+
pre() {
|
|
13
|
+
identityManager = new IdentityManager({
|
|
14
|
+
length
|
|
15
|
+
});
|
|
16
|
+
},
|
|
17
|
+
visitor: {
|
|
18
|
+
enter(path) {
|
|
19
|
+
if (!isPrimitiveElement(path.node)) {
|
|
20
|
+
path.node.id = identityManager.identify(path.node);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
post() {
|
|
25
|
+
identityManager = null;
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
export default plugin;
|
|
@@ -0,0 +1,47 @@
|
|
|
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 _apidomDatamodel = require("@speclynx/apidom-datamodel");
|
|
7
|
+
var _namespace = _interopRequireDefault(require("../namespace.cjs"));
|
|
8
|
+
/**
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
const predicates = {
|
|
13
|
+
isElement: _apidomDatamodel.isElement,
|
|
14
|
+
isStringElement: _apidomDatamodel.isStringElement,
|
|
15
|
+
isNumberElement: _apidomDatamodel.isNumberElement,
|
|
16
|
+
isNullElement: _apidomDatamodel.isNullElement,
|
|
17
|
+
isBooleanElement: _apidomDatamodel.isBooleanElement,
|
|
18
|
+
isArrayElement: _apidomDatamodel.isArrayElement,
|
|
19
|
+
isObjectElement: _apidomDatamodel.isObjectElement,
|
|
20
|
+
isMemberElement: _apidomDatamodel.isMemberElement,
|
|
21
|
+
isPrimitiveElement: _apidomDatamodel.isPrimitiveElement,
|
|
22
|
+
isLinkElement: _apidomDatamodel.isLinkElement,
|
|
23
|
+
isRefElement: _apidomDatamodel.isRefElement,
|
|
24
|
+
isAnnotationElement: _apidomDatamodel.isAnnotationElement,
|
|
25
|
+
isCommentElement: _apidomDatamodel.isCommentElement,
|
|
26
|
+
isParseResultElement: _apidomDatamodel.isParseResultElement,
|
|
27
|
+
isSourceMapElement: _apidomDatamodel.isSourceMapElement,
|
|
28
|
+
hasElementStyle: _apidomDatamodel.hasElementStyle,
|
|
29
|
+
hasElementSourceMap: _apidomDatamodel.hasElementSourceMap,
|
|
30
|
+
includesSymbols: _apidomDatamodel.includesSymbols,
|
|
31
|
+
includesClasses: _apidomDatamodel.includesClasses
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* @public
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* @public
|
|
40
|
+
*/
|
|
41
|
+
const createToolbox = () => {
|
|
42
|
+
return {
|
|
43
|
+
predicates,
|
|
44
|
+
namespace: _namespace.default
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
var _default = exports.default = createToolbox;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { isElement, isStringElement, isNumberElement, isNullElement, isBooleanElement, isArrayElement, isObjectElement, isMemberElement, isPrimitiveElement, isLinkElement, isRefElement, isAnnotationElement, isCommentElement, isParseResultElement, isSourceMapElement, hasElementStyle, hasElementSourceMap, includesSymbols, includesClasses } from '@speclynx/apidom-datamodel';
|
|
2
|
+
import defaultNamespace from "../namespace.mjs";
|
|
3
|
+
/**
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
6
|
+
const predicates = {
|
|
7
|
+
isElement,
|
|
8
|
+
isStringElement,
|
|
9
|
+
isNumberElement,
|
|
10
|
+
isNullElement,
|
|
11
|
+
isBooleanElement,
|
|
12
|
+
isArrayElement,
|
|
13
|
+
isObjectElement,
|
|
14
|
+
isMemberElement,
|
|
15
|
+
isPrimitiveElement,
|
|
16
|
+
isLinkElement,
|
|
17
|
+
isRefElement,
|
|
18
|
+
isAnnotationElement,
|
|
19
|
+
isCommentElement,
|
|
20
|
+
isParseResultElement,
|
|
21
|
+
isSourceMapElement,
|
|
22
|
+
hasElementStyle,
|
|
23
|
+
hasElementSourceMap,
|
|
24
|
+
includesSymbols,
|
|
25
|
+
includesClasses
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @public
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @public
|
|
34
|
+
*/
|
|
35
|
+
const createToolbox = () => {
|
|
36
|
+
return {
|
|
37
|
+
predicates,
|
|
38
|
+
namespace: defaultNamespace
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
export default createToolbox;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.resolveSpecification = void 0;
|
|
5
|
+
var _ramda = require("ramda");
|
|
6
|
+
var _ramdaAdjunct = require("ramda-adjunct");
|
|
7
|
+
/**
|
|
8
|
+
* Base type for resolved specification objects.
|
|
9
|
+
* Extend this in namespace packages to add specific type information.
|
|
10
|
+
* @public
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
const specCache = new WeakMap();
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Resolves a specification object by:
|
|
17
|
+
* 1. Dereferencing all $ref pointers
|
|
18
|
+
* 2. Building elementMap from objects with `element` property
|
|
19
|
+
* 3. Caching results for efficiency
|
|
20
|
+
*
|
|
21
|
+
* @public
|
|
22
|
+
*/
|
|
23
|
+
const resolveSpecification = specification => {
|
|
24
|
+
if (specCache.has(specification)) {
|
|
25
|
+
return specCache.get(specification);
|
|
26
|
+
}
|
|
27
|
+
const elementMap = {};
|
|
28
|
+
const traverse = (obj, root, currentPath) => {
|
|
29
|
+
// Collect element mapping
|
|
30
|
+
if (typeof obj.element === 'string') {
|
|
31
|
+
elementMap[obj.element] = obj.$visitor ? [...currentPath, '$visitor'] : currentPath;
|
|
32
|
+
}
|
|
33
|
+
return (0, _ramda.mapObjIndexed)((val, key) => {
|
|
34
|
+
const newPath = [...currentPath, key];
|
|
35
|
+
if ((0, _ramdaAdjunct.isPlainObject)(val) && (0, _ramda.has)('$ref', val) && (0, _ramda.propSatisfies)(_ramdaAdjunct.isString, '$ref', val)) {
|
|
36
|
+
const $ref = (0, _ramda.path)(['$ref'], val);
|
|
37
|
+
const pointer = (0, _ramdaAdjunct.trimCharsStart)('#/', $ref);
|
|
38
|
+
const resolved = (0, _ramda.path)(pointer.split('/'), root);
|
|
39
|
+
// merge extra properties (e.g. alias) from the $ref object into the resolved value
|
|
40
|
+
const {
|
|
41
|
+
$ref: _,
|
|
42
|
+
...rest
|
|
43
|
+
} = val;
|
|
44
|
+
if (Object.keys(rest).length > 0 && (0, _ramdaAdjunct.isPlainObject)(resolved)) {
|
|
45
|
+
return {
|
|
46
|
+
...resolved,
|
|
47
|
+
...rest
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
return resolved;
|
|
51
|
+
}
|
|
52
|
+
if ((0, _ramdaAdjunct.isPlainObject)(val)) {
|
|
53
|
+
return traverse(val, root, newPath);
|
|
54
|
+
}
|
|
55
|
+
return val;
|
|
56
|
+
}, obj);
|
|
57
|
+
};
|
|
58
|
+
const resolved = traverse(specification, specification, []);
|
|
59
|
+
resolved.elementMap = elementMap;
|
|
60
|
+
specCache.set(specification, resolved);
|
|
61
|
+
return resolved;
|
|
62
|
+
};
|
|
63
|
+
exports.resolveSpecification = resolveSpecification;
|