@speclynx/apidom-core 3.2.1 → 4.0.1
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 +8 -0
- package/dist/apidom-core.browser.js +24 -20
- package/package.json +5 -5
- package/src/fields/fixed-fields.cjs +0 -47
- package/src/fields/fixed-fields.mjs +0 -43
- package/src/fields/index.cjs +0 -8
- package/src/fields/index.mjs +0 -1
- package/src/identity/errors/ElementIdentityError.cjs +0 -22
- package/src/identity/errors/ElementIdentityError.mjs +0 -19
- package/src/identity/index.cjs +0 -64
- package/src/identity/index.mjs +0 -58
- package/src/index.cjs +0 -48
- package/src/index.mjs +0 -41
- package/src/media-types.cjs +0 -21
- package/src/media-types.mjs +0 -18
- package/src/merge/deepmerge.cjs +0 -165
- package/src/merge/deepmerge.mjs +0 -149
- package/src/merge/merge-left.cjs +0 -16
- package/src/merge/merge-left.mjs +0 -11
- package/src/merge/merge-right.cjs +0 -35
- package/src/merge/merge-right.mjs +0 -29
- package/src/namespace.cjs +0 -10
- package/src/namespace.mjs +0 -7
- package/src/refractor/plugins/dispatcher/index.cjs +0 -64
- package/src/refractor/plugins/dispatcher/index.mjs +0 -54
- package/src/refractor/plugins/element-identity.cjs +0 -31
- package/src/refractor/plugins/element-identity.mjs +0 -26
- package/src/refractor/plugins/semantic-element-identity.cjs +0 -33
- package/src/refractor/plugins/semantic-element-identity.mjs +0 -29
- package/src/refractor/toolbox.cjs +0 -47
- package/src/refractor/toolbox.mjs +0 -41
- package/src/specification.cjs +0 -63
- package/src/specification.mjs +0 -59
- package/src/transcluder/Transcluder.cjs +0 -111
- package/src/transcluder/Transcluder.mjs +0 -107
- package/src/transcluder/index.cjs +0 -19
- package/src/transcluder/index.mjs +0 -13
- package/src/transformers/dehydrate.cjs +0 -15
- package/src/transformers/dehydrate.mjs +0 -10
- package/src/transformers/from.cjs +0 -34
- package/src/transformers/from.mjs +0 -29
- package/src/transformers/serializers/json.cjs +0 -75
- package/src/transformers/serializers/json.mjs +0 -70
- package/src/transformers/serializers/value.cjs +0 -50
- package/src/transformers/serializers/value.mjs +0 -47
- package/src/transformers/serializers/yaml-1-2.cjs +0 -142
- package/src/transformers/serializers/yaml-1-2.mjs +0 -137
- package/src/transformers/sexprs.cjs +0 -31
- package/src/transformers/sexprs.mjs +0 -28
- package/src/transformers/to-string.cjs +0 -16
- package/src/transformers/to-string.mjs +0 -11
|
@@ -1,47 +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 _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;
|
|
@@ -1,41 +0,0 @@
|
|
|
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;
|
package/src/specification.cjs
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
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;
|
package/src/specification.mjs
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { mapObjIndexed, path, has, propSatisfies } from 'ramda';
|
|
2
|
-
import { isPlainObject, trimCharsStart, isString } from 'ramda-adjunct';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Base type for resolved specification objects.
|
|
6
|
-
* Extend this in namespace packages to add specific type information.
|
|
7
|
-
* @public
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
const specCache = new WeakMap();
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Resolves a specification object by:
|
|
14
|
-
* 1. Dereferencing all $ref pointers
|
|
15
|
-
* 2. Building elementMap from objects with `element` property
|
|
16
|
-
* 3. Caching results for efficiency
|
|
17
|
-
*
|
|
18
|
-
* @public
|
|
19
|
-
*/
|
|
20
|
-
export const resolveSpecification = specification => {
|
|
21
|
-
if (specCache.has(specification)) {
|
|
22
|
-
return specCache.get(specification);
|
|
23
|
-
}
|
|
24
|
-
const elementMap = {};
|
|
25
|
-
const traverse = (obj, root, currentPath) => {
|
|
26
|
-
// Collect element mapping
|
|
27
|
-
if (typeof obj.element === 'string') {
|
|
28
|
-
elementMap[obj.element] = obj.$visitor ? [...currentPath, '$visitor'] : currentPath;
|
|
29
|
-
}
|
|
30
|
-
return mapObjIndexed((val, key) => {
|
|
31
|
-
const newPath = [...currentPath, key];
|
|
32
|
-
if (isPlainObject(val) && has('$ref', val) && propSatisfies(isString, '$ref', val)) {
|
|
33
|
-
const $ref = path(['$ref'], val);
|
|
34
|
-
const pointer = trimCharsStart('#/', $ref);
|
|
35
|
-
const resolved = path(pointer.split('/'), root);
|
|
36
|
-
// merge extra properties (e.g. alias) from the $ref object into the resolved value
|
|
37
|
-
const {
|
|
38
|
-
$ref: _,
|
|
39
|
-
...rest
|
|
40
|
-
} = val;
|
|
41
|
-
if (Object.keys(rest).length > 0 && isPlainObject(resolved)) {
|
|
42
|
-
return {
|
|
43
|
-
...resolved,
|
|
44
|
-
...rest
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
return resolved;
|
|
48
|
-
}
|
|
49
|
-
if (isPlainObject(val)) {
|
|
50
|
-
return traverse(val, root, newPath);
|
|
51
|
-
}
|
|
52
|
-
return val;
|
|
53
|
-
}, obj);
|
|
54
|
-
};
|
|
55
|
-
const resolved = traverse(specification, specification, []);
|
|
56
|
-
resolved.elementMap = elementMap;
|
|
57
|
-
specCache.set(specification, resolved);
|
|
58
|
-
return resolved;
|
|
59
|
-
};
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
exports.__esModule = true;
|
|
4
|
-
exports.default = void 0;
|
|
5
|
-
var _apidomDatamodel = require("@speclynx/apidom-datamodel");
|
|
6
|
-
var _ramdaAdjunct = require("ramda-adjunct");
|
|
7
|
-
const computeEdges = (element, edges = new WeakMap()) => {
|
|
8
|
-
if ((0, _apidomDatamodel.isMemberElement)(element)) {
|
|
9
|
-
// @ts-ignore
|
|
10
|
-
edges.set(element.key, element);
|
|
11
|
-
// @ts-ignore
|
|
12
|
-
computeEdges(element.key, edges);
|
|
13
|
-
// @ts-ignore
|
|
14
|
-
edges.set(element.value, element);
|
|
15
|
-
// @ts-ignore
|
|
16
|
-
computeEdges(element.value, edges);
|
|
17
|
-
} else {
|
|
18
|
-
element.children.forEach(childElement => {
|
|
19
|
-
edges.set(childElement, element);
|
|
20
|
-
computeEdges(childElement, edges);
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
return edges;
|
|
24
|
-
};
|
|
25
|
-
const transcludeChildOfMemberElement = (search, replace, edges) => {
|
|
26
|
-
const memberElement = edges.get(search);
|
|
27
|
-
if (!(0, _apidomDatamodel.isMemberElement)(memberElement)) {
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
if (memberElement.key === search) {
|
|
31
|
-
memberElement.key = replace;
|
|
32
|
-
edges.delete(search);
|
|
33
|
-
edges.set(replace, memberElement);
|
|
34
|
-
}
|
|
35
|
-
if (memberElement.value === search) {
|
|
36
|
-
memberElement.value = replace;
|
|
37
|
-
edges.delete(search);
|
|
38
|
-
edges.set(replace, memberElement);
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
const transcludeChildOfObjectElement = (search, replace, edges) => {
|
|
42
|
-
const objectElement = edges.get(search);
|
|
43
|
-
if (!(0, _apidomDatamodel.isObjectElement)(objectElement)) {
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
objectElement.content = objectElement.map((value, key, member) => {
|
|
47
|
-
if (member === search) {
|
|
48
|
-
edges.delete(search);
|
|
49
|
-
edges.set(replace, objectElement);
|
|
50
|
-
return replace;
|
|
51
|
-
}
|
|
52
|
-
return member;
|
|
53
|
-
});
|
|
54
|
-
};
|
|
55
|
-
const transcludeChildOfArrayElement = (search, replace, edges) => {
|
|
56
|
-
const arrayElement = edges.get(search);
|
|
57
|
-
if (!(0, _apidomDatamodel.isArrayElement)(arrayElement)) {
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
arrayElement.content = arrayElement.map(element => {
|
|
61
|
-
if (element === search) {
|
|
62
|
-
edges.delete(search);
|
|
63
|
-
edges.set(replace, arrayElement);
|
|
64
|
-
return replace;
|
|
65
|
-
}
|
|
66
|
-
return element;
|
|
67
|
-
});
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* This is a mutating stamp. If you don't want your Element to be mutated,
|
|
72
|
-
* clone in before passing it to initializer of this stamp.
|
|
73
|
-
* @public
|
|
74
|
-
*/
|
|
75
|
-
|
|
76
|
-
class Transcluder {
|
|
77
|
-
element;
|
|
78
|
-
edges;
|
|
79
|
-
constructor({
|
|
80
|
-
element
|
|
81
|
-
}) {
|
|
82
|
-
this.element = element;
|
|
83
|
-
}
|
|
84
|
-
transclude(search, replace) {
|
|
85
|
-
// shortcut 1. - replacing entire ApiDOM tree
|
|
86
|
-
if (search === this.element) return replace;
|
|
87
|
-
// shortcut 2. - replacing nothing
|
|
88
|
-
if (search === replace) return this.element;
|
|
89
|
-
this.edges = this.edges ?? computeEdges(this.element);
|
|
90
|
-
const parent = this.edges.get(search);
|
|
91
|
-
if ((0, _ramdaAdjunct.isUndefined)(parent)) {
|
|
92
|
-
return undefined;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* This predicate must be first because ObjectElement extends ArrayElement.
|
|
97
|
-
* isArrayElement returns true for ObjectElements.
|
|
98
|
-
* (classical problems with polymorphism)
|
|
99
|
-
*/
|
|
100
|
-
if ((0, _apidomDatamodel.isObjectElement)(parent)) {
|
|
101
|
-
// @ts-ignore
|
|
102
|
-
transcludeChildOfObjectElement(search, replace, this.edges);
|
|
103
|
-
} else if ((0, _apidomDatamodel.isArrayElement)(parent)) {
|
|
104
|
-
transcludeChildOfArrayElement(search, replace, this.edges);
|
|
105
|
-
} else if ((0, _apidomDatamodel.isMemberElement)(parent)) {
|
|
106
|
-
transcludeChildOfMemberElement(search, replace, this.edges);
|
|
107
|
-
}
|
|
108
|
-
return this.element;
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
var _default = exports.default = Transcluder;
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import { isObjectElement, isArrayElement, isMemberElement } from '@speclynx/apidom-datamodel';
|
|
2
|
-
import { isUndefined } from 'ramda-adjunct';
|
|
3
|
-
const computeEdges = (element, edges = new WeakMap()) => {
|
|
4
|
-
if (isMemberElement(element)) {
|
|
5
|
-
// @ts-ignore
|
|
6
|
-
edges.set(element.key, element);
|
|
7
|
-
// @ts-ignore
|
|
8
|
-
computeEdges(element.key, edges);
|
|
9
|
-
// @ts-ignore
|
|
10
|
-
edges.set(element.value, element);
|
|
11
|
-
// @ts-ignore
|
|
12
|
-
computeEdges(element.value, edges);
|
|
13
|
-
} else {
|
|
14
|
-
element.children.forEach(childElement => {
|
|
15
|
-
edges.set(childElement, element);
|
|
16
|
-
computeEdges(childElement, edges);
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
return edges;
|
|
20
|
-
};
|
|
21
|
-
const transcludeChildOfMemberElement = (search, replace, edges) => {
|
|
22
|
-
const memberElement = edges.get(search);
|
|
23
|
-
if (!isMemberElement(memberElement)) {
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
if (memberElement.key === search) {
|
|
27
|
-
memberElement.key = replace;
|
|
28
|
-
edges.delete(search);
|
|
29
|
-
edges.set(replace, memberElement);
|
|
30
|
-
}
|
|
31
|
-
if (memberElement.value === search) {
|
|
32
|
-
memberElement.value = replace;
|
|
33
|
-
edges.delete(search);
|
|
34
|
-
edges.set(replace, memberElement);
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
const transcludeChildOfObjectElement = (search, replace, edges) => {
|
|
38
|
-
const objectElement = edges.get(search);
|
|
39
|
-
if (!isObjectElement(objectElement)) {
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
objectElement.content = objectElement.map((value, key, member) => {
|
|
43
|
-
if (member === search) {
|
|
44
|
-
edges.delete(search);
|
|
45
|
-
edges.set(replace, objectElement);
|
|
46
|
-
return replace;
|
|
47
|
-
}
|
|
48
|
-
return member;
|
|
49
|
-
});
|
|
50
|
-
};
|
|
51
|
-
const transcludeChildOfArrayElement = (search, replace, edges) => {
|
|
52
|
-
const arrayElement = edges.get(search);
|
|
53
|
-
if (!isArrayElement(arrayElement)) {
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
arrayElement.content = arrayElement.map(element => {
|
|
57
|
-
if (element === search) {
|
|
58
|
-
edges.delete(search);
|
|
59
|
-
edges.set(replace, arrayElement);
|
|
60
|
-
return replace;
|
|
61
|
-
}
|
|
62
|
-
return element;
|
|
63
|
-
});
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* This is a mutating stamp. If you don't want your Element to be mutated,
|
|
68
|
-
* clone in before passing it to initializer of this stamp.
|
|
69
|
-
* @public
|
|
70
|
-
*/
|
|
71
|
-
|
|
72
|
-
class Transcluder {
|
|
73
|
-
element;
|
|
74
|
-
edges;
|
|
75
|
-
constructor({
|
|
76
|
-
element
|
|
77
|
-
}) {
|
|
78
|
-
this.element = element;
|
|
79
|
-
}
|
|
80
|
-
transclude(search, replace) {
|
|
81
|
-
// shortcut 1. - replacing entire ApiDOM tree
|
|
82
|
-
if (search === this.element) return replace;
|
|
83
|
-
// shortcut 2. - replacing nothing
|
|
84
|
-
if (search === replace) return this.element;
|
|
85
|
-
this.edges = this.edges ?? computeEdges(this.element);
|
|
86
|
-
const parent = this.edges.get(search);
|
|
87
|
-
if (isUndefined(parent)) {
|
|
88
|
-
return undefined;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* This predicate must be first because ObjectElement extends ArrayElement.
|
|
93
|
-
* isArrayElement returns true for ObjectElements.
|
|
94
|
-
* (classical problems with polymorphism)
|
|
95
|
-
*/
|
|
96
|
-
if (isObjectElement(parent)) {
|
|
97
|
-
// @ts-ignore
|
|
98
|
-
transcludeChildOfObjectElement(search, replace, this.edges);
|
|
99
|
-
} else if (isArrayElement(parent)) {
|
|
100
|
-
transcludeChildOfArrayElement(search, replace, this.edges);
|
|
101
|
-
} else if (isMemberElement(parent)) {
|
|
102
|
-
transcludeChildOfMemberElement(search, replace, this.edges);
|
|
103
|
-
}
|
|
104
|
-
return this.element;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
export default Transcluder;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
|
|
4
|
-
exports.__esModule = true;
|
|
5
|
-
exports.transclude = exports.default = void 0;
|
|
6
|
-
var _Transcluder = _interopRequireDefault(require("./Transcluder.cjs"));
|
|
7
|
-
/**
|
|
8
|
-
* This is a mutating function. If you don't want your Element to be mutated,
|
|
9
|
-
* clone in before passing it to this function.
|
|
10
|
-
* @public
|
|
11
|
-
*/
|
|
12
|
-
const transclude = (search, replace, element) => {
|
|
13
|
-
const transcluder = new _Transcluder.default({
|
|
14
|
-
element
|
|
15
|
-
});
|
|
16
|
-
return transcluder.transclude(search, replace);
|
|
17
|
-
};
|
|
18
|
-
exports.transclude = transclude;
|
|
19
|
-
var _default = exports.default = _Transcluder.default;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import Transcluder from "./Transcluder.mjs";
|
|
2
|
-
/**
|
|
3
|
-
* This is a mutating function. If you don't want your Element to be mutated,
|
|
4
|
-
* clone in before passing it to this function.
|
|
5
|
-
* @public
|
|
6
|
-
*/
|
|
7
|
-
export const transclude = (search, replace, element) => {
|
|
8
|
-
const transcluder = new Transcluder({
|
|
9
|
-
element
|
|
10
|
-
});
|
|
11
|
-
return transcluder.transclude(search, replace);
|
|
12
|
-
};
|
|
13
|
-
export default Transcluder;
|
|
@@ -1,15 +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
|
-
/**
|
|
8
|
-
* Creates a refract representation of an Element.
|
|
9
|
-
* https://github.com/refractproject/refract-spec
|
|
10
|
-
* @public
|
|
11
|
-
*/
|
|
12
|
-
const dehydrate = (element, namespace = _namespace.default) => {
|
|
13
|
-
return namespace.toRefract(element);
|
|
14
|
-
};
|
|
15
|
-
var _default = exports.default = dehydrate;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import defaultNamespaceInstance from "../namespace.mjs";
|
|
2
|
-
/**
|
|
3
|
-
* Creates a refract representation of an Element.
|
|
4
|
-
* https://github.com/refractproject/refract-spec
|
|
5
|
-
* @public
|
|
6
|
-
*/
|
|
7
|
-
const dehydrate = (element, namespace = defaultNamespaceInstance) => {
|
|
8
|
-
return namespace.toRefract(element);
|
|
9
|
-
};
|
|
10
|
-
export default dehydrate;
|
|
@@ -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 _ramda = require("ramda");
|
|
7
|
-
var _ramdaAdjunct = require("ramda-adjunct");
|
|
8
|
-
var _namespace = _interopRequireDefault(require("../namespace.cjs"));
|
|
9
|
-
/**
|
|
10
|
-
* Transforms data to an Element from a particular namespace.
|
|
11
|
-
*
|
|
12
|
-
* The name of the function was originally `from`,
|
|
13
|
-
* but it was renamed to `fromFn` to avoid issues with Parcel.js:
|
|
14
|
-
*
|
|
15
|
-
* - https://github.com/parcel-bundler/parcel/issues/9473
|
|
16
|
-
* - https://github.com/swagger-api/swagger-ui/issues/9466#issuecomment-1881053410
|
|
17
|
-
* @public
|
|
18
|
-
*/
|
|
19
|
-
const fromFn = (data, namespace = _namespace.default) => {
|
|
20
|
-
if ((0, _ramdaAdjunct.isString)(data)) {
|
|
21
|
-
// JSON serialized refract
|
|
22
|
-
try {
|
|
23
|
-
return namespace.fromRefract(JSON.parse(data));
|
|
24
|
-
} catch {
|
|
25
|
-
// noop
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
if ((0, _ramdaAdjunct.isPlainObject)(data) && (0, _ramda.has)('element', data)) {
|
|
29
|
-
// refract javascript structure
|
|
30
|
-
return namespace.fromRefract(data);
|
|
31
|
-
}
|
|
32
|
-
return namespace.toElement(data);
|
|
33
|
-
};
|
|
34
|
-
var _default = exports.default = fromFn;
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { has } from 'ramda';
|
|
2
|
-
import { isPlainObject, isString } from 'ramda-adjunct';
|
|
3
|
-
import defaultNamespace from "../namespace.mjs";
|
|
4
|
-
/**
|
|
5
|
-
* Transforms data to an Element from a particular namespace.
|
|
6
|
-
*
|
|
7
|
-
* The name of the function was originally `from`,
|
|
8
|
-
* but it was renamed to `fromFn` to avoid issues with Parcel.js:
|
|
9
|
-
*
|
|
10
|
-
* - https://github.com/parcel-bundler/parcel/issues/9473
|
|
11
|
-
* - https://github.com/swagger-api/swagger-ui/issues/9466#issuecomment-1881053410
|
|
12
|
-
* @public
|
|
13
|
-
*/
|
|
14
|
-
const fromFn = (data, namespace = defaultNamespace) => {
|
|
15
|
-
if (isString(data)) {
|
|
16
|
-
// JSON serialized refract
|
|
17
|
-
try {
|
|
18
|
-
return namespace.fromRefract(JSON.parse(data));
|
|
19
|
-
} catch {
|
|
20
|
-
// noop
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
if (isPlainObject(data) && has('element', data)) {
|
|
24
|
-
// refract javascript structure
|
|
25
|
-
return namespace.fromRefract(data);
|
|
26
|
-
}
|
|
27
|
-
return namespace.toElement(data);
|
|
28
|
-
};
|
|
29
|
-
export default fromFn;
|
|
@@ -1,75 +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 _apidomDatamodel = require("@speclynx/apidom-datamodel");
|
|
7
|
-
var _value = _interopRequireDefault(require("./value.cjs"));
|
|
8
|
-
const getStyle = element => {
|
|
9
|
-
return element.style?.json ?? {};
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* @public
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Builds a POJO from an ApiDOM element tree. Numbers with rawContent
|
|
18
|
-
* are replaced with sentinel strings; all other values go through toValue().
|
|
19
|
-
*/
|
|
20
|
-
const toPojo = (element, sentinels) => {
|
|
21
|
-
const visited = new WeakSet();
|
|
22
|
-
const convert = node => {
|
|
23
|
-
if (!(0, _apidomDatamodel.isElement)(node)) return node;
|
|
24
|
-
if (visited.has(node)) return null;
|
|
25
|
-
visited.add(node);
|
|
26
|
-
if ((0, _apidomDatamodel.isObjectElement)(node)) {
|
|
27
|
-
const obj = {};
|
|
28
|
-
node.forEach((value, key) => {
|
|
29
|
-
const k = (0, _apidomDatamodel.isElement)(key) ? (0, _value.default)(key) : key;
|
|
30
|
-
if (typeof k === 'string') obj[k] = convert(value);
|
|
31
|
-
});
|
|
32
|
-
return obj;
|
|
33
|
-
}
|
|
34
|
-
if ((0, _apidomDatamodel.isArrayElement)(node)) {
|
|
35
|
-
const arr = [];
|
|
36
|
-
node.forEach(item => arr.push(convert(item)));
|
|
37
|
-
return arr;
|
|
38
|
-
}
|
|
39
|
-
if ((0, _apidomDatamodel.isRefElement)(node)) return String((0, _value.default)(node));
|
|
40
|
-
if ((0, _apidomDatamodel.isLinkElement)(node)) return (0, _apidomDatamodel.isStringElement)(node.href) ? (0, _value.default)(node.href) : '';
|
|
41
|
-
|
|
42
|
-
// number with rawContent — substitute with sentinel
|
|
43
|
-
if ((0, _apidomDatamodel.isNumberElement)(node)) {
|
|
44
|
-
const style = getStyle(node);
|
|
45
|
-
if (typeof style.rawContent === 'string') {
|
|
46
|
-
const sentinel = `\0RAW${sentinels.size}\0`;
|
|
47
|
-
sentinels.set(sentinel, style.rawContent);
|
|
48
|
-
return sentinel;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
return (0, _value.default)(node);
|
|
52
|
-
};
|
|
53
|
-
return convert(element);
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* @public
|
|
58
|
-
*/
|
|
59
|
-
const serializer = (element, replacer, space, options) => {
|
|
60
|
-
if (options?.preserveStyle) {
|
|
61
|
-
const style = getStyle(element);
|
|
62
|
-
const indent = typeof space === 'number' ? space : typeof style.indent === 'number' ? style.indent : 0;
|
|
63
|
-
const sentinels = new Map();
|
|
64
|
-
const pojo = toPojo(element, sentinels);
|
|
65
|
-
let serialized = JSON.stringify(pojo, null, indent);
|
|
66
|
-
|
|
67
|
-
// replace quoted sentinels with raw number representations
|
|
68
|
-
for (const [sentinel, raw] of sentinels) {
|
|
69
|
-
serialized = serialized.replace(JSON.stringify(sentinel), raw);
|
|
70
|
-
}
|
|
71
|
-
return serialized;
|
|
72
|
-
}
|
|
73
|
-
return JSON.stringify((0, _value.default)(element), replacer, space);
|
|
74
|
-
};
|
|
75
|
-
var _default = exports.default = serializer;
|