yaml 1.3.2 → 1.6.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.
- package/README.md +4 -6
- package/browser/dist/Anchors.js +12 -10
- package/browser/dist/Document.js +170 -75
- package/browser/dist/constants.js +34 -0
- package/browser/dist/cst/Alias.js +1 -3
- package/browser/dist/cst/BlankLine.js +5 -7
- package/browser/dist/cst/BlockValue.js +4 -4
- package/browser/dist/cst/Collection.js +8 -8
- package/browser/dist/cst/CollectionItem.js +6 -8
- package/browser/dist/cst/Comment.js +5 -7
- package/browser/dist/cst/Directive.js +5 -7
- package/browser/dist/cst/Document.js +17 -11
- package/browser/dist/cst/FlowCollection.js +14 -8
- package/browser/dist/cst/Node.js +12 -40
- package/browser/dist/cst/ParseContext.js +32 -34
- package/browser/dist/cst/PlainValue.js +1 -3
- package/browser/dist/cst/QuoteDouble.js +1 -3
- package/browser/dist/cst/QuoteSingle.js +1 -3
- package/browser/dist/cst/Range.js +1 -3
- package/browser/dist/cst/getLinePos.js +1 -4
- package/browser/dist/cst/parse.js +1 -4
- package/browser/dist/deprecation.js +34 -0
- package/browser/dist/errors.js +50 -59
- package/browser/dist/index.js +37 -7
- package/browser/dist/listTagNames.js +1 -3
- package/browser/dist/schema/Alias.js +90 -10
- package/browser/dist/schema/Collection.js +3 -3
- package/browser/dist/schema/Map.js +22 -105
- package/browser/dist/schema/Merge.js +74 -1
- package/browser/dist/schema/Node.js +1 -3
- package/browser/dist/schema/Pair.js +37 -23
- package/browser/dist/schema/Scalar.js +3 -5
- package/browser/dist/schema/Seq.js +30 -7
- package/browser/dist/schema/index.js +158 -82
- package/browser/dist/schema/parseMap.js +18 -21
- package/browser/dist/schema/parseSeq.js +9 -12
- package/browser/dist/{schema/_string.js → stringify.js} +65 -73
- package/browser/dist/tags/core.js +132 -0
- package/browser/dist/tags/failsafe/index.js +17 -0
- package/browser/dist/tags/failsafe/map.js +65 -0
- package/browser/dist/tags/failsafe/seq.js +54 -0
- package/browser/dist/tags/failsafe/string.js +40 -0
- package/browser/dist/tags/index.js +50 -0
- package/browser/dist/tags/json.js +103 -0
- package/browser/dist/tags/options.js +35 -0
- package/browser/dist/{schema/_binary.js → tags/yaml-1.1/binary.js} +20 -20
- package/browser/dist/tags/yaml-1.1/index.js +177 -0
- package/browser/dist/{schema/_omap.js → tags/yaml-1.1/omap.js} +25 -25
- package/browser/dist/{schema/_pairs.js → tags/yaml-1.1/pairs.js} +9 -13
- package/browser/dist/tags/yaml-1.1/set.js +140 -0
- package/browser/dist/{schema/_timestamp.js → tags/yaml-1.1/timestamp.js} +13 -10
- package/browser/dist/test-events.js +1 -4
- package/browser/dist/toJSON.js +20 -8
- package/browser/index.js +1 -0
- package/browser/map.js +2 -1
- package/browser/pair.js +2 -1
- package/browser/parse-cst.js +1 -1
- package/browser/scalar.js +2 -1
- package/browser/schema.js +7 -3
- package/browser/seq.js +2 -1
- package/browser/types/binary.js +7 -1
- package/browser/types/omap.js +2 -1
- package/browser/types/pairs.js +2 -1
- package/browser/types/set.js +2 -1
- package/browser/types/timestamp.js +10 -1
- package/browser/types.js +11 -0
- package/browser/util.js +15 -0
- package/dist/Anchors.js +9 -8
- package/dist/Document.js +89 -45
- package/dist/constants.js +34 -0
- package/dist/cst/Alias.js +1 -3
- package/dist/cst/BlankLine.js +5 -7
- package/dist/cst/BlockValue.js +4 -4
- package/dist/cst/Collection.js +8 -8
- package/dist/cst/CollectionItem.js +6 -8
- package/dist/cst/Comment.js +5 -7
- package/dist/cst/Directive.js +5 -7
- package/dist/cst/Document.js +17 -11
- package/dist/cst/FlowCollection.js +14 -8
- package/dist/cst/Node.js +12 -40
- package/dist/cst/ParseContext.js +32 -34
- package/dist/cst/PlainValue.js +1 -3
- package/dist/cst/QuoteDouble.js +1 -3
- package/dist/cst/QuoteSingle.js +1 -3
- package/dist/cst/Range.js +1 -3
- package/dist/cst/getLinePos.js +1 -4
- package/dist/cst/parse.js +1 -4
- package/dist/deprecation.js +34 -0
- package/dist/errors.js +29 -35
- package/dist/index.js +18 -5
- package/dist/listTagNames.js +1 -3
- package/dist/schema/Alias.js +67 -12
- package/dist/schema/Map.js +10 -74
- package/dist/schema/Merge.js +31 -0
- package/dist/schema/Node.js +1 -3
- package/dist/schema/Pair.js +30 -16
- package/dist/schema/Scalar.js +3 -5
- package/dist/schema/Seq.js +9 -5
- package/dist/schema/index.js +109 -74
- package/dist/schema/parseMap.js +18 -21
- package/dist/schema/parseSeq.js +9 -12
- package/dist/{schema/_string.js → stringify.js} +56 -65
- package/dist/tags/core.js +96 -0
- package/dist/tags/failsafe/index.js +17 -0
- package/dist/tags/failsafe/map.js +33 -0
- package/dist/tags/failsafe/seq.js +34 -0
- package/dist/tags/failsafe/string.js +40 -0
- package/dist/tags/index.js +50 -0
- package/dist/tags/json.js +67 -0
- package/dist/tags/options.js +35 -0
- package/dist/{schema/_binary.js → tags/yaml-1.1/binary.js} +18 -20
- package/dist/tags/yaml-1.1/index.js +131 -0
- package/dist/{schema/_omap.js → tags/yaml-1.1/omap.js} +16 -16
- package/dist/{schema/_pairs.js → tags/yaml-1.1/pairs.js} +9 -11
- package/dist/{schema/_set.js → tags/yaml-1.1/set.js} +12 -44
- package/dist/{schema/_timestamp.js → tags/yaml-1.1/timestamp.js} +7 -10
- package/dist/test-events.js +1 -4
- package/dist/toJSON.js +15 -5
- package/index.js +1 -0
- package/map.js +2 -1
- package/package.json +23 -17
- package/pair.js +2 -1
- package/parse-cst.js +1 -1
- package/scalar.js +2 -1
- package/schema.js +7 -3
- package/seq.js +2 -1
- package/types/binary.js +7 -1
- package/types/omap.js +2 -1
- package/types/pairs.js +2 -1
- package/types/set.js +2 -1
- package/types/timestamp.js +10 -1
- package/types.js +11 -0
- package/util.js +15 -0
- package/browser/dist/polyfill.js +0 -251
- package/browser/dist/schema/_set.js +0 -212
- package/browser/dist/schema/core.js +0 -98
- package/browser/dist/schema/failsafe.js +0 -125
- package/browser/dist/schema/json.js +0 -66
- package/browser/dist/schema/yaml-1.1.js +0 -140
- package/dist/polyfill.js +0 -27
- package/dist/schema/core.js +0 -79
- package/dist/schema/failsafe.js +0 -74
- package/dist/schema/json.js +0 -56
- package/dist/schema/yaml-1.1.js +0 -115
package/dist/schema/Alias.js
CHANGED
|
@@ -5,26 +5,56 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
|
-
var
|
|
8
|
+
var _constants = require("../constants");
|
|
9
|
+
|
|
10
|
+
var _errors = require("../errors");
|
|
9
11
|
|
|
10
12
|
var _toJSON = _interopRequireDefault(require("../toJSON"));
|
|
11
13
|
|
|
12
|
-
var
|
|
14
|
+
var _Collection = _interopRequireDefault(require("./Collection"));
|
|
15
|
+
|
|
16
|
+
var _Node = _interopRequireDefault(require("./Node"));
|
|
17
|
+
|
|
18
|
+
var _Pair = _interopRequireDefault(require("./Pair"));
|
|
13
19
|
|
|
14
20
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
21
|
|
|
16
22
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
17
23
|
|
|
18
|
-
|
|
24
|
+
const getAliasCount = (node, anchors) => {
|
|
25
|
+
if (node instanceof Alias) {
|
|
26
|
+
const anchor = anchors.find(a => a.node === node.source);
|
|
27
|
+
return anchor.count * anchor.aliasCount;
|
|
28
|
+
} else if (node instanceof _Collection.default) {
|
|
29
|
+
let count = 0;
|
|
30
|
+
|
|
31
|
+
for (const item of node.items) {
|
|
32
|
+
const c = getAliasCount(item, anchors);
|
|
33
|
+
if (c > count) count = c;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return count;
|
|
37
|
+
} else if (node instanceof _Pair.default) {
|
|
38
|
+
const kc = getAliasCount(node.key, anchors);
|
|
39
|
+
const vc = getAliasCount(node.value, anchors);
|
|
40
|
+
return Math.max(kc, vc);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return 1;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
class Alias extends _Node.default {
|
|
19
47
|
static stringify({
|
|
20
48
|
range,
|
|
21
49
|
source
|
|
22
50
|
}, {
|
|
23
51
|
anchors,
|
|
24
52
|
doc,
|
|
25
|
-
implicitKey
|
|
53
|
+
implicitKey,
|
|
54
|
+
inStringifyKey
|
|
26
55
|
}) {
|
|
27
|
-
|
|
56
|
+
let anchor = Object.keys(anchors).find(a => anchors[a] === source);
|
|
57
|
+
if (!anchor && inStringifyKey) anchor = doc.anchors.getName(source) || doc.anchors.newName();
|
|
28
58
|
if (anchor) return `*${anchor}${implicitKey ? ' ' : ''}`;
|
|
29
59
|
const msg = doc.anchors.getName(source) ? 'Alias node must be after source node' : 'Source node not found for alias node';
|
|
30
60
|
throw new Error(`${msg} [${range}]`);
|
|
@@ -33,22 +63,47 @@ class Alias extends _Node2.default {
|
|
|
33
63
|
constructor(source) {
|
|
34
64
|
super();
|
|
35
65
|
this.source = source;
|
|
36
|
-
this.type =
|
|
66
|
+
this.type = _constants.Type.ALIAS;
|
|
37
67
|
}
|
|
38
68
|
|
|
39
69
|
set tag(t) {
|
|
40
70
|
throw new Error('Alias nodes cannot have tags');
|
|
41
71
|
}
|
|
42
72
|
|
|
43
|
-
toJSON(arg,
|
|
44
|
-
return (0, _toJSON.default)(this.source, arg,
|
|
73
|
+
toJSON(arg, ctx) {
|
|
74
|
+
if (!ctx) return (0, _toJSON.default)(this.source, arg, ctx);
|
|
75
|
+
const {
|
|
76
|
+
anchors,
|
|
77
|
+
maxAliasCount
|
|
78
|
+
} = ctx;
|
|
79
|
+
const anchor = anchors.find(a => a.node === this.source);
|
|
80
|
+
|
|
81
|
+
if (!anchor || !anchor.res) {
|
|
82
|
+
const msg = 'This should not happen: Alias anchor was not resolved?';
|
|
83
|
+
if (this.cstNode) throw new _errors.YAMLReferenceError(this.cstNode, msg);else throw new ReferenceError(msg);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (maxAliasCount >= 0) {
|
|
87
|
+
anchor.count += 1;
|
|
88
|
+
if (anchor.aliasCount === 0) anchor.aliasCount = getAliasCount(this.source, anchors);
|
|
89
|
+
|
|
90
|
+
if (anchor.count * anchor.aliasCount > maxAliasCount) {
|
|
91
|
+
const msg = 'Excessive alias count indicates a resource exhaustion attack';
|
|
92
|
+
if (this.cstNode) throw new _errors.YAMLReferenceError(this.cstNode, msg);else throw new ReferenceError(msg);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return anchor.res;
|
|
97
|
+
} // Only called when stringifying an alias mapping key while constructing
|
|
98
|
+
// Object output.
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
toString(ctx) {
|
|
102
|
+
return Alias.stringify(this, ctx);
|
|
45
103
|
}
|
|
46
104
|
|
|
47
105
|
}
|
|
48
106
|
|
|
49
107
|
exports.default = Alias;
|
|
50
108
|
|
|
51
|
-
_defineProperty(Alias, "default", true);
|
|
52
|
-
|
|
53
|
-
module.exports = exports.default;
|
|
54
|
-
module.exports.default = exports.default;
|
|
109
|
+
_defineProperty(Alias, "default", true);
|
package/dist/schema/Map.js
CHANGED
|
@@ -6,19 +6,14 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.findPair = findPair;
|
|
7
7
|
exports.default = void 0;
|
|
8
8
|
|
|
9
|
-
var _toJSON = _interopRequireDefault(require("../toJSON"));
|
|
10
|
-
|
|
11
9
|
var _Collection = _interopRequireDefault(require("./Collection"));
|
|
12
10
|
|
|
13
|
-
var _Merge = _interopRequireDefault(require("./Merge"));
|
|
14
|
-
|
|
15
11
|
var _Pair = _interopRequireDefault(require("./Pair"));
|
|
16
12
|
|
|
17
13
|
var _Scalar = _interopRequireDefault(require("./Scalar"));
|
|
18
14
|
|
|
19
15
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
20
16
|
|
|
21
|
-
// Published as 'yaml/map'
|
|
22
17
|
function findPair(items, key) {
|
|
23
18
|
const k = key instanceof _Scalar.default ? key.value : key;
|
|
24
19
|
|
|
@@ -61,78 +56,19 @@ class YAMLMap extends _Collection.default {
|
|
|
61
56
|
const prev = findPair(this.items, key);
|
|
62
57
|
if (prev) prev.value = value;else this.items.push(new _Pair.default(key, value));
|
|
63
58
|
}
|
|
59
|
+
/**
|
|
60
|
+
* @param {*} arg ignored
|
|
61
|
+
* @param {*} ctx Conversion context, originally set in Document#toJSON()
|
|
62
|
+
* @param {Class} Type If set, forces the returned collection type
|
|
63
|
+
* @returns {*} Instance of Type, Map, or Object
|
|
64
|
+
*/
|
|
64
65
|
|
|
65
|
-
toJSON(_, opt) {
|
|
66
|
-
if (opt && opt.mapAsMap) return this.toJSMap(opt);
|
|
67
|
-
return this.items.reduce((map, item) => {
|
|
68
|
-
if (item instanceof _Merge.default) {
|
|
69
|
-
// If the value associated with a merge key is a single mapping node,
|
|
70
|
-
// each of its key/value pairs is inserted into the current mapping,
|
|
71
|
-
// unless the key already exists in it. If the value associated with the
|
|
72
|
-
// merge key is a sequence, then this sequence is expected to contain
|
|
73
|
-
// mapping nodes and each of these nodes is merged in turn according to
|
|
74
|
-
// its order in the sequence. Keys in mapping nodes earlier in the
|
|
75
|
-
// sequence override keys specified in later mapping nodes.
|
|
76
|
-
// -- http://yaml.org/type/merge.html
|
|
77
|
-
const keys = Object.keys(map);
|
|
78
|
-
const {
|
|
79
|
-
items
|
|
80
|
-
} = item.value;
|
|
81
|
-
|
|
82
|
-
for (let i = items.length - 1; i >= 0; --i) {
|
|
83
|
-
const {
|
|
84
|
-
source
|
|
85
|
-
} = items[i];
|
|
86
|
-
|
|
87
|
-
if (source instanceof YAMLMap) {
|
|
88
|
-
const obj = source.toJSON('', opt);
|
|
89
|
-
Object.keys(obj).forEach(key => {
|
|
90
|
-
if (!keys.includes(key)) map[key] = obj[key];
|
|
91
|
-
});
|
|
92
|
-
} else {
|
|
93
|
-
throw new Error('Merge sources must be maps');
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
} else {
|
|
97
|
-
const {
|
|
98
|
-
stringKey,
|
|
99
|
-
value
|
|
100
|
-
} = item;
|
|
101
|
-
map[stringKey] = (0, _toJSON.default)(value, stringKey, opt);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
return map;
|
|
105
|
-
}, {});
|
|
106
|
-
}
|
|
107
66
|
|
|
108
|
-
|
|
109
|
-
const map = new Map();
|
|
67
|
+
toJSON(_, ctx, Type) {
|
|
68
|
+
const map = Type ? new Type() : ctx && ctx.mapAsMap ? new Map() : {};
|
|
69
|
+
if (ctx && ctx.onCreate) ctx.onCreate(map);
|
|
110
70
|
|
|
111
|
-
for (const item of this.items)
|
|
112
|
-
if (item instanceof _Merge.default) {
|
|
113
|
-
const {
|
|
114
|
-
items
|
|
115
|
-
} = item.value;
|
|
116
|
-
|
|
117
|
-
for (let i = items.length - 1; i >= 0; --i) {
|
|
118
|
-
const {
|
|
119
|
-
source
|
|
120
|
-
} = items[i];
|
|
121
|
-
|
|
122
|
-
if (source instanceof YAMLMap) {
|
|
123
|
-
for (const [key, value] of source.toJSMap(opt)) {
|
|
124
|
-
if (!map.has(key)) map.set(key, value);
|
|
125
|
-
}
|
|
126
|
-
} else {
|
|
127
|
-
throw new Error('Merge sources must be maps');
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
} else {
|
|
131
|
-
const key = (0, _toJSON.default)(item.key, '', opt);
|
|
132
|
-
const value = (0, _toJSON.default)(item.value, key, opt);
|
|
133
|
-
map.set(key, value);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
71
|
+
for (const item of this.items) item.addToJSMap(ctx, map);
|
|
136
72
|
|
|
137
73
|
return map;
|
|
138
74
|
}
|
package/dist/schema/Merge.js
CHANGED
|
@@ -5,6 +5,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = exports.MERGE_KEY = void 0;
|
|
7
7
|
|
|
8
|
+
var _Map = _interopRequireDefault(require("./Map"));
|
|
9
|
+
|
|
8
10
|
var _Pair = _interopRequireDefault(require("./Pair"));
|
|
9
11
|
|
|
10
12
|
var _Scalar = _interopRequireDefault(require("./Scalar"));
|
|
@@ -34,6 +36,35 @@ class Merge extends _Pair.default {
|
|
|
34
36
|
}
|
|
35
37
|
|
|
36
38
|
this.type = 'MERGE_PAIR';
|
|
39
|
+
} // If the value associated with a merge key is a single mapping node, each of
|
|
40
|
+
// its key/value pairs is inserted into the current mapping, unless the key
|
|
41
|
+
// already exists in it. If the value associated with the merge key is a
|
|
42
|
+
// sequence, then this sequence is expected to contain mapping nodes and each
|
|
43
|
+
// of these nodes is merged in turn according to its order in the sequence.
|
|
44
|
+
// Keys in mapping nodes earlier in the sequence override keys specified in
|
|
45
|
+
// later mapping nodes. -- http://yaml.org/type/merge.html
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
addToJSMap(ctx, map) {
|
|
49
|
+
for (const _ref of this.value.items) {
|
|
50
|
+
const {
|
|
51
|
+
source
|
|
52
|
+
} = _ref;
|
|
53
|
+
if (!(source instanceof _Map.default)) throw new Error('Merge sources must be maps');
|
|
54
|
+
const srcMap = source.toJSON(null, ctx, Map);
|
|
55
|
+
|
|
56
|
+
for (const [key, value] of srcMap) {
|
|
57
|
+
if (map instanceof Map) {
|
|
58
|
+
if (!map.has(key)) map.set(key, value);
|
|
59
|
+
} else if (map instanceof Set) {
|
|
60
|
+
map.add(key);
|
|
61
|
+
} else {
|
|
62
|
+
if (!map.hasOwnProperty(key)) map[key] = value;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return map;
|
|
37
68
|
}
|
|
38
69
|
|
|
39
70
|
toString(ctx, onComment) {
|
package/dist/schema/Node.js
CHANGED
package/dist/schema/Pair.js
CHANGED
|
@@ -18,6 +18,19 @@ var _Scalar = _interopRequireDefault(require("./Scalar"));
|
|
|
18
18
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
19
|
|
|
20
20
|
// Published as 'yaml/pair'
|
|
21
|
+
const stringifyKey = (key, jsKey, ctx) => {
|
|
22
|
+
if (jsKey === null) return '';
|
|
23
|
+
if (typeof jsKey !== 'object') return String(jsKey);
|
|
24
|
+
if (key instanceof _Node.default && ctx && ctx.doc) return key.toString({
|
|
25
|
+
anchors: {},
|
|
26
|
+
doc: ctx.doc,
|
|
27
|
+
indent: '',
|
|
28
|
+
inFlow: true,
|
|
29
|
+
inStringifyKey: true
|
|
30
|
+
});
|
|
31
|
+
return JSON.stringify(jsKey);
|
|
32
|
+
};
|
|
33
|
+
|
|
21
34
|
class Pair extends _Node.default {
|
|
22
35
|
constructor(key, value = null) {
|
|
23
36
|
super();
|
|
@@ -35,22 +48,25 @@ class Pair extends _Node.default {
|
|
|
35
48
|
this.key.commentBefore = cb;
|
|
36
49
|
}
|
|
37
50
|
|
|
38
|
-
|
|
39
|
-
const key = (0, _toJSON.default)(this.key);
|
|
40
|
-
|
|
41
|
-
if (
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
51
|
+
addToJSMap(ctx, map) {
|
|
52
|
+
const key = (0, _toJSON.default)(this.key, '', ctx);
|
|
53
|
+
|
|
54
|
+
if (map instanceof Map) {
|
|
55
|
+
const value = (0, _toJSON.default)(this.value, key, ctx);
|
|
56
|
+
map.set(key, value);
|
|
57
|
+
} else if (map instanceof Set) {
|
|
58
|
+
map.add(key);
|
|
59
|
+
} else {
|
|
60
|
+
const stringKey = stringifyKey(this.key, key, ctx);
|
|
61
|
+
map[stringKey] = (0, _toJSON.default)(this.value, stringKey, ctx);
|
|
45
62
|
}
|
|
46
|
-
|
|
63
|
+
|
|
64
|
+
return map;
|
|
47
65
|
}
|
|
48
66
|
|
|
49
|
-
toJSON(_,
|
|
50
|
-
const pair = {};
|
|
51
|
-
|
|
52
|
-
pair[sk] = (0, _toJSON.default)(this.value, sk, opt);
|
|
53
|
-
return pair;
|
|
67
|
+
toJSON(_, ctx) {
|
|
68
|
+
const pair = ctx && ctx.mapAsMap ? new Map() : {};
|
|
69
|
+
return this.addToJSMap(ctx, pair);
|
|
54
70
|
}
|
|
55
71
|
|
|
56
72
|
toString(ctx, onComment, onChompKeep) {
|
|
@@ -124,6 +140,4 @@ class Pair extends _Node.default {
|
|
|
124
140
|
|
|
125
141
|
}
|
|
126
142
|
|
|
127
|
-
exports.default = Pair;
|
|
128
|
-
module.exports = exports.default;
|
|
129
|
-
module.exports.default = exports.default;
|
|
143
|
+
exports.default = Pair;
|
package/dist/schema/Scalar.js
CHANGED
|
@@ -18,8 +18,8 @@ class Scalar extends _Node.default {
|
|
|
18
18
|
this.value = value;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
toJSON(arg,
|
|
22
|
-
return
|
|
21
|
+
toJSON(arg, ctx) {
|
|
22
|
+
return ctx && ctx.keep ? this.value : (0, _toJSON.default)(this.value, arg, ctx);
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
toString() {
|
|
@@ -28,6 +28,4 @@ class Scalar extends _Node.default {
|
|
|
28
28
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
exports.default = Scalar;
|
|
32
|
-
module.exports = exports.default;
|
|
33
|
-
module.exports.default = exports.default;
|
|
31
|
+
exports.default = Scalar;
|
package/dist/schema/Seq.js
CHANGED
|
@@ -50,8 +50,14 @@ class YAMLSeq extends _Collection.default {
|
|
|
50
50
|
this.items[idx] = value;
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
toJSON(_,
|
|
54
|
-
|
|
53
|
+
toJSON(_, ctx) {
|
|
54
|
+
const seq = [];
|
|
55
|
+
if (ctx && ctx.onCreate) ctx.onCreate(seq);
|
|
56
|
+
let i = 0;
|
|
57
|
+
|
|
58
|
+
for (const item of this.items) seq.push((0, _toJSON.default)(item, String(i++), ctx));
|
|
59
|
+
|
|
60
|
+
return seq;
|
|
55
61
|
}
|
|
56
62
|
|
|
57
63
|
toString(ctx, onComment, onChompKeep) {
|
|
@@ -69,6 +75,4 @@ class YAMLSeq extends _Collection.default {
|
|
|
69
75
|
|
|
70
76
|
}
|
|
71
77
|
|
|
72
|
-
exports.default = YAMLSeq;
|
|
73
|
-
module.exports = exports.default;
|
|
74
|
-
module.exports.default = exports.default;
|
|
78
|
+
exports.default = YAMLSeq;
|
package/dist/schema/index.js
CHANGED
|
@@ -5,71 +5,84 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
|
-
var
|
|
8
|
+
var _deprecation = require("../deprecation");
|
|
9
|
+
|
|
10
|
+
var _constants = require("../constants");
|
|
9
11
|
|
|
10
12
|
var _errors = require("../errors");
|
|
11
13
|
|
|
12
|
-
var
|
|
14
|
+
var _stringify = require("../stringify");
|
|
13
15
|
|
|
14
|
-
var
|
|
16
|
+
var _tags = require("../tags");
|
|
15
17
|
|
|
16
|
-
var
|
|
18
|
+
var _string = require("../tags/failsafe/string");
|
|
17
19
|
|
|
18
|
-
var
|
|
20
|
+
var _Alias = _interopRequireDefault(require("./Alias"));
|
|
19
21
|
|
|
20
|
-
var
|
|
22
|
+
var _Collection = _interopRequireDefault(require("./Collection"));
|
|
21
23
|
|
|
22
|
-
var
|
|
24
|
+
var _Node = _interopRequireDefault(require("./Node"));
|
|
23
25
|
|
|
24
26
|
var _Pair = _interopRequireDefault(require("./Pair"));
|
|
25
27
|
|
|
26
28
|
var _Scalar = _interopRequireDefault(require("./Scalar"));
|
|
27
29
|
|
|
28
|
-
var _string = require("./_string");
|
|
29
|
-
|
|
30
|
-
var _yaml = _interopRequireDefault(require("./yaml-1.1"));
|
|
31
|
-
|
|
32
|
-
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
|
|
33
|
-
|
|
34
30
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
35
31
|
|
|
36
32
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
37
33
|
|
|
38
34
|
const isMap = ({
|
|
39
35
|
type
|
|
40
|
-
}) => type ===
|
|
36
|
+
}) => type === _constants.Type.FLOW_MAP || type === _constants.Type.MAP;
|
|
41
37
|
|
|
42
38
|
const isSeq = ({
|
|
43
39
|
type
|
|
44
|
-
}) => type ===
|
|
40
|
+
}) => type === _constants.Type.FLOW_SEQ || type === _constants.Type.SEQ;
|
|
45
41
|
|
|
46
42
|
class Schema {
|
|
47
|
-
static defaultStringify(value) {
|
|
48
|
-
return JSON.stringify(value);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
43
|
constructor({
|
|
44
|
+
customTags,
|
|
52
45
|
merge,
|
|
53
46
|
schema,
|
|
54
|
-
tags
|
|
47
|
+
tags: deprecatedCustomTags
|
|
55
48
|
}) {
|
|
56
49
|
this.merge = !!merge;
|
|
57
50
|
this.name = schema;
|
|
58
|
-
this.tags =
|
|
51
|
+
this.tags = _tags.schemas[schema.replace(/\W/g, '')]; // 'yaml-1.1' -> 'yaml11'
|
|
59
52
|
|
|
60
53
|
if (!this.tags) {
|
|
61
|
-
const keys = Object.keys(
|
|
62
|
-
throw new Error(`Unknown schema; use one of ${keys
|
|
54
|
+
const keys = Object.keys(_tags.schemas).map(key => JSON.stringify(key)).join(', ');
|
|
55
|
+
throw new Error(`Unknown schema "${schema}"; use one of ${keys}`);
|
|
63
56
|
}
|
|
64
57
|
|
|
65
|
-
if (
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
58
|
+
if (!customTags && deprecatedCustomTags) {
|
|
59
|
+
customTags = deprecatedCustomTags;
|
|
60
|
+
(0, _deprecation.warnOptionDeprecation)('tags', 'customTags');
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (Array.isArray(customTags)) {
|
|
64
|
+
for (const tag of customTags) this.tags = this.tags.concat(tag);
|
|
65
|
+
} else if (typeof customTags === 'function') {
|
|
66
|
+
this.tags = customTags(this.tags.slice());
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
for (let i = 0; i < this.tags.length; ++i) {
|
|
70
|
+
const tag = this.tags[i];
|
|
71
|
+
|
|
72
|
+
if (typeof tag === 'string') {
|
|
73
|
+
const tagObj = _tags.tags[tag];
|
|
74
|
+
|
|
75
|
+
if (!tagObj) {
|
|
76
|
+
const keys = Object.keys(_tags.tags).map(key => JSON.stringify(key)).join(', ');
|
|
77
|
+
throw new Error(`Unknown custom tag "${tag}"; use one of ${keys}`);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
this.tags[i] = tagObj;
|
|
81
|
+
}
|
|
69
82
|
}
|
|
70
83
|
}
|
|
71
84
|
|
|
72
|
-
createNode(value, wrapScalars, tag,
|
|
85
|
+
createNode(value, wrapScalars, tag, ctx) {
|
|
73
86
|
let tagObj;
|
|
74
87
|
|
|
75
88
|
if (tag) {
|
|
@@ -78,18 +91,49 @@ class Schema {
|
|
|
78
91
|
tagObj = match.find(t => !t.format) || match[0];
|
|
79
92
|
if (!tagObj) throw new Error(`Tag ${tag} not found`);
|
|
80
93
|
} else {
|
|
81
|
-
|
|
94
|
+
// TODO: deprecate/remove class check
|
|
95
|
+
tagObj = this.tags.find(t => (t.identify && t.identify(value) || t.class && value instanceof t.class) && !t.format);
|
|
82
96
|
|
|
83
97
|
if (!tagObj) {
|
|
84
|
-
if (value == null) return new _Scalar.default(null);
|
|
85
98
|
if (typeof value.toJSON === 'function') value = value.toJSON();
|
|
86
99
|
if (typeof value !== 'object') return wrapScalars ? new _Scalar.default(value) : value;
|
|
87
|
-
tagObj = value instanceof Map ?
|
|
100
|
+
tagObj = value instanceof Map ? _tags.tags.map : value[Symbol.iterator] ? _tags.tags.seq : _tags.tags.map;
|
|
88
101
|
}
|
|
89
102
|
}
|
|
90
103
|
|
|
91
|
-
if (
|
|
92
|
-
|
|
104
|
+
if (!ctx) ctx = {
|
|
105
|
+
wrapScalars
|
|
106
|
+
};else ctx.wrapScalars = wrapScalars;
|
|
107
|
+
|
|
108
|
+
if (ctx.onTagObj) {
|
|
109
|
+
ctx.onTagObj(tagObj);
|
|
110
|
+
delete ctx.onTagObj;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const obj = {};
|
|
114
|
+
|
|
115
|
+
if (value && typeof value === 'object' && ctx.prevObjects) {
|
|
116
|
+
const prev = ctx.prevObjects.find(o => o.value === value);
|
|
117
|
+
|
|
118
|
+
if (prev) {
|
|
119
|
+
const alias = new _Alias.default(prev); // leaves source dirty; must be cleaned by caller
|
|
120
|
+
|
|
121
|
+
ctx.aliasNodes.push(alias);
|
|
122
|
+
return alias;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
obj.value = value;
|
|
126
|
+
ctx.prevObjects.push(obj);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
obj.node = tagObj.createNode ? tagObj.createNode(this, value, ctx) : wrapScalars ? new _Scalar.default(value) : value;
|
|
130
|
+
return obj.node;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
createPair(key, value, ctx) {
|
|
134
|
+
const k = this.createNode(key, ctx.wrapScalars, null, ctx);
|
|
135
|
+
const v = this.createNode(value, ctx.wrapScalars, null, ctx);
|
|
136
|
+
return new _Pair.default(k, v);
|
|
93
137
|
} // falls back to string on no match
|
|
94
138
|
|
|
95
139
|
|
|
@@ -107,7 +151,8 @@ class Schema {
|
|
|
107
151
|
const match = str.match(test);
|
|
108
152
|
|
|
109
153
|
if (match) {
|
|
110
|
-
|
|
154
|
+
let res = resolve.apply(null, match);
|
|
155
|
+
if (!(res instanceof _Scalar.default)) res = new _Scalar.default(res);
|
|
111
156
|
if (format) res.format = format;
|
|
112
157
|
return res;
|
|
113
158
|
}
|
|
@@ -134,7 +179,7 @@ class Schema {
|
|
|
134
179
|
if (!(res instanceof _Collection.default)) res = new _Scalar.default(res);
|
|
135
180
|
node.resolved = res;
|
|
136
181
|
} else {
|
|
137
|
-
const str = (0, _string.
|
|
182
|
+
const str = (0, _string.resolveString)(doc, node);
|
|
138
183
|
|
|
139
184
|
if (typeof str === 'string' && tags.length > 0) {
|
|
140
185
|
node.resolved = this.resolveScalar(str, tags);
|
|
@@ -147,7 +192,7 @@ class Schema {
|
|
|
147
192
|
}
|
|
148
193
|
|
|
149
194
|
if (!node.resolved) return null;
|
|
150
|
-
if (tagName) node.resolved.tag = tagName;
|
|
195
|
+
if (tagName && node.tag) node.resolved.tag = tagName;
|
|
151
196
|
return node.resolved;
|
|
152
197
|
}
|
|
153
198
|
|
|
@@ -176,33 +221,12 @@ class Schema {
|
|
|
176
221
|
if (match.length > 0) return match.find(t => t.format === item.format) || match[0];
|
|
177
222
|
}
|
|
178
223
|
|
|
179
|
-
if (item.value === null) {
|
|
180
|
-
const tagObj = this.tags.find(t => t.class === null && !t.format);
|
|
181
|
-
if (!tagObj) throw new Error('Tag not resolved for null value');
|
|
182
|
-
return tagObj;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
224
|
let tagObj, obj;
|
|
186
225
|
|
|
187
226
|
if (item instanceof _Scalar.default) {
|
|
188
|
-
|
|
189
|
-
case 'boolean':
|
|
190
|
-
obj = new Boolean();
|
|
191
|
-
break;
|
|
192
|
-
|
|
193
|
-
case 'number':
|
|
194
|
-
obj = new Number();
|
|
195
|
-
break;
|
|
196
|
-
|
|
197
|
-
case 'string':
|
|
198
|
-
obj = new String();
|
|
199
|
-
break;
|
|
200
|
-
|
|
201
|
-
default:
|
|
202
|
-
obj = item.value;
|
|
203
|
-
}
|
|
227
|
+
obj = item.value; // TODO: deprecate/remove class check
|
|
204
228
|
|
|
205
|
-
const match = this.tags.filter(t => t.
|
|
229
|
+
const match = this.tags.filter(t => t.identify && t.identify(obj) || t.class && obj instanceof t.class);
|
|
206
230
|
tagObj = match.find(t => t.format === item.format) || match.find(t => !t.format);
|
|
207
231
|
} else {
|
|
208
232
|
obj = item;
|
|
@@ -230,7 +254,7 @@ class Schema {
|
|
|
230
254
|
props.push(`&${anchor}`);
|
|
231
255
|
}
|
|
232
256
|
|
|
233
|
-
if (node.tag
|
|
257
|
+
if (node.tag) {
|
|
234
258
|
props.push(doc.stringifyTag(node.tag));
|
|
235
259
|
} else if (!tagObj.default) {
|
|
236
260
|
props.push(doc.stringifyTag(tagObj.tag));
|
|
@@ -241,13 +265,34 @@ class Schema {
|
|
|
241
265
|
|
|
242
266
|
stringify(item, ctx, onComment, onChompKeep) {
|
|
243
267
|
let tagObj;
|
|
244
|
-
|
|
268
|
+
|
|
269
|
+
if (!(item instanceof _Node.default)) {
|
|
270
|
+
const createCtx = {
|
|
271
|
+
aliasNodes: [],
|
|
272
|
+
onTagObj: o => tagObj = o,
|
|
273
|
+
prevObjects: []
|
|
274
|
+
};
|
|
275
|
+
item = this.createNode(item, true, null, createCtx);
|
|
276
|
+
const {
|
|
277
|
+
anchors
|
|
278
|
+
} = ctx.doc;
|
|
279
|
+
|
|
280
|
+
for (const alias of createCtx.aliasNodes) {
|
|
281
|
+
alias.source = alias.source.node;
|
|
282
|
+
let name = anchors.getName(alias.source);
|
|
283
|
+
|
|
284
|
+
if (!name) {
|
|
285
|
+
name = anchors.newName();
|
|
286
|
+
anchors.map[name] = alias.source;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
|
|
245
291
|
ctx.tags = this;
|
|
246
292
|
if (item instanceof _Pair.default) return item.toString(ctx, onComment, onChompKeep);
|
|
247
293
|
if (!tagObj) tagObj = this.getTagObject(item);
|
|
248
294
|
const props = this.stringifyProps(item, tagObj, ctx);
|
|
249
|
-
const
|
|
250
|
-
const str = stringify(item, ctx, onComment, onChompKeep);
|
|
295
|
+
const str = typeof tagObj.stringify === 'function' ? tagObj.stringify(item, ctx, onComment, onChompKeep) : item instanceof _Collection.default ? item.toString(ctx, onComment, onChompKeep) : (0, _stringify.stringifyString)(item, ctx, onComment, onChompKeep);
|
|
251
296
|
return props ? item instanceof _Collection.default && str[0] !== '{' && str[0] !== '[' ? `${props}\n${ctx.indent}${str}` : `${props} ${str}` : str;
|
|
252
297
|
}
|
|
253
298
|
|
|
@@ -261,14 +306,4 @@ _defineProperty(Schema, "defaultTags", {
|
|
|
261
306
|
MAP: 'tag:yaml.org,2002:map',
|
|
262
307
|
SEQ: 'tag:yaml.org,2002:seq',
|
|
263
308
|
STR: 'tag:yaml.org,2002:str'
|
|
264
|
-
});
|
|
265
|
-
|
|
266
|
-
_defineProperty(Schema, "tags", {
|
|
267
|
-
core: _core.default,
|
|
268
|
-
failsafe: _failsafe.default,
|
|
269
|
-
json: _json.default,
|
|
270
|
-
'yaml-1.1': _yaml.default
|
|
271
|
-
});
|
|
272
|
-
|
|
273
|
-
module.exports = exports.default;
|
|
274
|
-
module.exports.default = exports.default;
|
|
309
|
+
});
|