@speclynx/apidom-core 2.2.0 → 2.2.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.
- package/CHANGELOG.md +10 -0
- package/dist/apidom-core.browser.js +9103 -226
- package/dist/apidom-core.browser.min.js +1 -1
- package/package.json +7 -6
- package/src/transformers/serializers/yaml-1-2.cjs +17 -80
- package/src/transformers/serializers/yaml-1-2.mjs +18 -82
- package/types/apidom-core.d.ts +13 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@speclynx/apidom-core",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.2",
|
|
4
4
|
"description": "Tools for manipulating ApiDOM structures.",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public",
|
|
@@ -40,13 +40,14 @@
|
|
|
40
40
|
"license": "Apache-2.0",
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"@babel/runtime-corejs3": "^7.28.4",
|
|
43
|
-
"@speclynx/apidom-datamodel": "^2.2.
|
|
44
|
-
"@speclynx/apidom-error": "^2.2.
|
|
45
|
-
"@speclynx/apidom-traverse": "^2.2.
|
|
43
|
+
"@speclynx/apidom-datamodel": "^2.2.2",
|
|
44
|
+
"@speclynx/apidom-error": "^2.2.2",
|
|
45
|
+
"@speclynx/apidom-traverse": "^2.2.2",
|
|
46
46
|
"ramda": "~0.32.0",
|
|
47
47
|
"ramda-adjunct": "^6.0.0",
|
|
48
48
|
"short-unique-id": "^5.3.2",
|
|
49
|
-
"ts-mixer": "^6.0.4"
|
|
49
|
+
"ts-mixer": "^6.0.4",
|
|
50
|
+
"yaml": "^2.8.2"
|
|
50
51
|
},
|
|
51
52
|
"files": [
|
|
52
53
|
"src/**/*.mjs",
|
|
@@ -58,5 +59,5 @@
|
|
|
58
59
|
"README.md",
|
|
59
60
|
"CHANGELOG.md"
|
|
60
61
|
],
|
|
61
|
-
"gitHead": "
|
|
62
|
+
"gitHead": "220dbc19c94e58d28ea05d05c4eaf2f5dc0c5fbc"
|
|
62
63
|
}
|
|
@@ -3,92 +3,29 @@
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
|
|
4
4
|
exports.__esModule = true;
|
|
5
5
|
exports.default = void 0;
|
|
6
|
-
var
|
|
6
|
+
var _yaml = require("yaml");
|
|
7
7
|
var _value = _interopRequireDefault(require("./value.cjs"));
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
indent;
|
|
12
|
-
constructor({
|
|
13
|
-
directive = false,
|
|
14
|
-
indent = 0
|
|
15
|
-
} = {}) {
|
|
16
|
-
this.result = directive ? '%YAML 1.2\n---\n' : '';
|
|
17
|
-
this.indent = indent;
|
|
18
|
-
}
|
|
19
|
-
NumberElement(path) {
|
|
20
|
-
this.result += (0, _value.default)(path.node);
|
|
21
|
-
}
|
|
22
|
-
BooleanElement(path) {
|
|
23
|
-
const value = (0, _value.default)(path.node);
|
|
24
|
-
this.result += value ? 'true' : 'false';
|
|
25
|
-
}
|
|
26
|
-
StringElement(path) {
|
|
27
|
-
// for simplicity and avoiding ambiguity we always wrap strings in quotes
|
|
28
|
-
this.result += JSON.stringify((0, _value.default)(path.node));
|
|
29
|
-
}
|
|
30
|
-
NullElement() {
|
|
31
|
-
this.result += 'null';
|
|
32
|
-
}
|
|
33
|
-
ArrayElement(path) {
|
|
34
|
-
const element = path.node;
|
|
35
|
-
if (element.length === 0) {
|
|
36
|
-
this.result += '[]';
|
|
37
|
-
path.skip();
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
element.forEach(item => {
|
|
41
|
-
const visitor = new YamlVisitor({
|
|
42
|
-
indent: this.indent + 1
|
|
43
|
-
});
|
|
44
|
-
const indent = YamlVisitor.indentChar.repeat(this.indent);
|
|
45
|
-
(0, _apidomTraverse.traverse)(item, visitor);
|
|
46
|
-
const {
|
|
47
|
-
result
|
|
48
|
-
} = visitor;
|
|
49
|
-
this.result += result.startsWith('\n') ? `\n${indent}-${result}` : `\n${indent}- ${result}`;
|
|
50
|
-
});
|
|
51
|
-
path.skip();
|
|
52
|
-
}
|
|
53
|
-
ObjectElement(path) {
|
|
54
|
-
const element = path.node;
|
|
55
|
-
if (element.length === 0) {
|
|
56
|
-
this.result += '{}';
|
|
57
|
-
path.skip();
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
element.forEach((value, key) => {
|
|
61
|
-
const keyVisitor = new YamlVisitor({
|
|
62
|
-
indent: this.indent + 1
|
|
63
|
-
});
|
|
64
|
-
const valueVisitor = new YamlVisitor({
|
|
65
|
-
indent: this.indent + 1
|
|
66
|
-
});
|
|
67
|
-
const indent = YamlVisitor.indentChar.repeat(this.indent);
|
|
68
|
-
(0, _apidomTraverse.traverse)(key, keyVisitor);
|
|
69
|
-
(0, _apidomTraverse.traverse)(value, valueVisitor);
|
|
70
|
-
const {
|
|
71
|
-
result: keyResult
|
|
72
|
-
} = keyVisitor;
|
|
73
|
-
const {
|
|
74
|
-
result: valueResult
|
|
75
|
-
} = valueVisitor;
|
|
76
|
-
this.result += valueResult.startsWith('\n') ? `\n${indent}${keyResult}:${valueResult}` : `\n${indent}${keyResult}: ${valueResult}`;
|
|
77
|
-
});
|
|
78
|
-
path.skip();
|
|
79
|
-
}
|
|
80
|
-
}
|
|
8
|
+
/**
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
81
11
|
|
|
82
12
|
/**
|
|
83
13
|
* @public
|
|
84
14
|
*/
|
|
85
15
|
const serializer = (element, {
|
|
86
|
-
directive = false
|
|
16
|
+
directive = false,
|
|
17
|
+
aliasDuplicateObjects = false,
|
|
18
|
+
...options
|
|
87
19
|
} = {}) => {
|
|
88
|
-
const
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
20
|
+
const allOptions = {
|
|
21
|
+
aliasDuplicateObjects,
|
|
22
|
+
...options
|
|
23
|
+
};
|
|
24
|
+
if (directive) {
|
|
25
|
+
const doc = new _yaml.Document((0, _value.default)(element), allOptions);
|
|
26
|
+
doc.directives.yaml.explicit = true;
|
|
27
|
+
return doc.toString(allOptions);
|
|
28
|
+
}
|
|
29
|
+
return (0, _yaml.stringify)((0, _value.default)(element), allOptions);
|
|
93
30
|
};
|
|
94
31
|
var _default = exports.default = serializer;
|
|
@@ -1,89 +1,25 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
indent;
|
|
7
|
-
constructor({
|
|
8
|
-
directive = false,
|
|
9
|
-
indent = 0
|
|
10
|
-
} = {}) {
|
|
11
|
-
this.result = directive ? '%YAML 1.2\n---\n' : '';
|
|
12
|
-
this.indent = indent;
|
|
13
|
-
}
|
|
14
|
-
NumberElement(path) {
|
|
15
|
-
this.result += serializeValue(path.node);
|
|
16
|
-
}
|
|
17
|
-
BooleanElement(path) {
|
|
18
|
-
const value = serializeValue(path.node);
|
|
19
|
-
this.result += value ? 'true' : 'false';
|
|
20
|
-
}
|
|
21
|
-
StringElement(path) {
|
|
22
|
-
// for simplicity and avoiding ambiguity we always wrap strings in quotes
|
|
23
|
-
this.result += JSON.stringify(serializeValue(path.node));
|
|
24
|
-
}
|
|
25
|
-
NullElement() {
|
|
26
|
-
this.result += 'null';
|
|
27
|
-
}
|
|
28
|
-
ArrayElement(path) {
|
|
29
|
-
const element = path.node;
|
|
30
|
-
if (element.length === 0) {
|
|
31
|
-
this.result += '[]';
|
|
32
|
-
path.skip();
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
element.forEach(item => {
|
|
36
|
-
const visitor = new YamlVisitor({
|
|
37
|
-
indent: this.indent + 1
|
|
38
|
-
});
|
|
39
|
-
const indent = YamlVisitor.indentChar.repeat(this.indent);
|
|
40
|
-
traverse(item, visitor);
|
|
41
|
-
const {
|
|
42
|
-
result
|
|
43
|
-
} = visitor;
|
|
44
|
-
this.result += result.startsWith('\n') ? `\n${indent}-${result}` : `\n${indent}- ${result}`;
|
|
45
|
-
});
|
|
46
|
-
path.skip();
|
|
47
|
-
}
|
|
48
|
-
ObjectElement(path) {
|
|
49
|
-
const element = path.node;
|
|
50
|
-
if (element.length === 0) {
|
|
51
|
-
this.result += '{}';
|
|
52
|
-
path.skip();
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
element.forEach((value, key) => {
|
|
56
|
-
const keyVisitor = new YamlVisitor({
|
|
57
|
-
indent: this.indent + 1
|
|
58
|
-
});
|
|
59
|
-
const valueVisitor = new YamlVisitor({
|
|
60
|
-
indent: this.indent + 1
|
|
61
|
-
});
|
|
62
|
-
const indent = YamlVisitor.indentChar.repeat(this.indent);
|
|
63
|
-
traverse(key, keyVisitor);
|
|
64
|
-
traverse(value, valueVisitor);
|
|
65
|
-
const {
|
|
66
|
-
result: keyResult
|
|
67
|
-
} = keyVisitor;
|
|
68
|
-
const {
|
|
69
|
-
result: valueResult
|
|
70
|
-
} = valueVisitor;
|
|
71
|
-
this.result += valueResult.startsWith('\n') ? `\n${indent}${keyResult}:${valueResult}` : `\n${indent}${keyResult}: ${valueResult}`;
|
|
72
|
-
});
|
|
73
|
-
path.skip();
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
1
|
+
import { Document, stringify } from 'yaml';
|
|
2
|
+
import toValue from "./value.mjs";
|
|
3
|
+
/**
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
77
6
|
/**
|
|
78
7
|
* @public
|
|
79
8
|
*/
|
|
80
9
|
const serializer = (element, {
|
|
81
|
-
directive = false
|
|
10
|
+
directive = false,
|
|
11
|
+
aliasDuplicateObjects = false,
|
|
12
|
+
...options
|
|
82
13
|
} = {}) => {
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
14
|
+
const allOptions = {
|
|
15
|
+
aliasDuplicateObjects,
|
|
16
|
+
...options
|
|
17
|
+
};
|
|
18
|
+
if (directive) {
|
|
19
|
+
const doc = new Document(toValue(element), allOptions);
|
|
20
|
+
doc.directives.yaml.explicit = true;
|
|
21
|
+
return doc.toString(allOptions);
|
|
22
|
+
}
|
|
23
|
+
return stringify(toValue(element), allOptions);
|
|
88
24
|
};
|
|
89
25
|
export default serializer;
|
package/types/apidom-core.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { ApiDOMErrorOptions } from '@speclynx/apidom-error';
|
|
2
2
|
import { ApiDOMStructuredError } from '@speclynx/apidom-error';
|
|
3
3
|
import { ArrayElement } from '@speclynx/apidom-datamodel';
|
|
4
|
+
import { CreateNodeOptions } from 'yaml';
|
|
5
|
+
import { DocumentOptions } from 'yaml';
|
|
4
6
|
import { Element as Element_2 } from '@speclynx/apidom-datamodel';
|
|
5
7
|
import { hasElementSourceMap } from '@speclynx/apidom-datamodel';
|
|
6
8
|
import { includesClasses } from '@speclynx/apidom-datamodel';
|
|
@@ -23,8 +25,10 @@ import { isStringElement } from '@speclynx/apidom-datamodel';
|
|
|
23
25
|
import { Namespace } from '@speclynx/apidom-datamodel';
|
|
24
26
|
import { ObjectElement } from '@speclynx/apidom-datamodel';
|
|
25
27
|
import { Path } from '@speclynx/apidom-traverse';
|
|
28
|
+
import { SchemaOptions } from 'yaml';
|
|
26
29
|
import ShortUniqueId from 'short-unique-id';
|
|
27
30
|
import { StringElement } from '@speclynx/apidom-datamodel';
|
|
31
|
+
import { ToStringOptions } from 'yaml';
|
|
28
32
|
|
|
29
33
|
/**
|
|
30
34
|
* @public
|
|
@@ -326,9 +330,7 @@ export declare const toValue: <T extends Element_2 | unknown>(element: T) => unk
|
|
|
326
330
|
/**
|
|
327
331
|
* @public
|
|
328
332
|
*/
|
|
329
|
-
export declare const toYAML: (element: Element_2, { directive }?:
|
|
330
|
-
directive?: boolean | undefined;
|
|
331
|
-
}) => string;
|
|
333
|
+
export declare const toYAML: (element: Element_2, { directive, aliasDuplicateObjects, ...options }?: YamlSerializerOptions) => string;
|
|
332
334
|
|
|
333
335
|
/**
|
|
334
336
|
* This is a mutating function. If you don't want your Element to be mutated,
|
|
@@ -351,4 +353,12 @@ export declare class Transcluder {
|
|
|
351
353
|
transclude(search: Element_2, replace: Element_2): Element_2 | undefined;
|
|
352
354
|
}
|
|
353
355
|
|
|
356
|
+
/**
|
|
357
|
+
* @public
|
|
358
|
+
*/
|
|
359
|
+
export declare interface YamlSerializerOptions extends DocumentOptions, Pick<CreateNodeOptions, 'aliasDuplicateObjects'>, Pick<SchemaOptions, 'sortMapEntries'>, ToStringOptions {
|
|
360
|
+
/** Include %YAML directive and document marker */
|
|
361
|
+
directive?: boolean;
|
|
362
|
+
}
|
|
363
|
+
|
|
354
364
|
export { }
|