cdk8s-operator 0.1.407 → 0.1.409
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/.jsii +4 -4
- package/lib/operator.js +3 -3
- package/lib/server.js +1 -1
- package/node_modules/yaml/browser/dist/PlainValue-183afbad.js +751 -0
- package/node_modules/yaml/browser/dist/Schema-9530c078.js +467 -0
- package/node_modules/yaml/browser/dist/index.js +436 -746
- package/node_modules/yaml/browser/dist/legacy-exports.js +3 -3
- package/node_modules/yaml/browser/dist/parse-cst.js +1290 -1689
- package/node_modules/yaml/browser/dist/resolveSeq-67caf78a.js +1835 -0
- package/node_modules/yaml/browser/dist/types.js +4 -4
- package/node_modules/yaml/browser/dist/util.js +2 -2
- package/node_modules/yaml/browser/dist/warnings-5e4358fe.js +348 -0
- package/node_modules/yaml/dist/{Document-9b4560a1.js → Document-a8d0fbf9.js} +11 -131
- package/node_modules/yaml/dist/{PlainValue-ec8e588e.js → PlainValue-516d5bc2.js} +35 -146
- package/node_modules/yaml/dist/{Schema-88e323a7.js → Schema-bcc6c2d7.js} +10 -66
- package/node_modules/yaml/dist/index.js +5 -17
- package/node_modules/yaml/dist/legacy-exports.js +3 -3
- package/node_modules/yaml/dist/parse-cst.js +45 -291
- package/node_modules/yaml/dist/{resolveSeq-d03cb037.js → resolveSeq-95613e94.js} +44 -346
- package/node_modules/yaml/dist/test-events.js +28 -44
- package/node_modules/yaml/dist/types.js +4 -4
- package/node_modules/yaml/dist/util.js +2 -2
- package/node_modules/yaml/dist/{warnings-1000a372.js → warnings-793925ce.js} +16 -73
- package/node_modules/yaml/package.json +2 -3
- package/package.json +6 -6
- package/node_modules/yaml/browser/dist/PlainValue-b8036b75.js +0 -1275
- package/node_modules/yaml/browser/dist/Schema-e94716c8.js +0 -682
- package/node_modules/yaml/browser/dist/resolveSeq-492ab440.js +0 -2419
- package/node_modules/yaml/browser/dist/warnings-df54cb69.js +0 -499
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { d as defaultTagPrefix, _ as _createForOfIteratorHelper, a as _typeof, b as _createClass, c as _classCallCheck, e as _defineProperty, Y as YAMLSyntaxError, T as Type, f as YAMLWarning, g as YAMLSemanticError, h as _slicedToArray, i as YAMLError, j as _inherits, k as _createSuper } from './PlainValue-b8036b75.js';
|
|
2
1
|
import { parse as parse$1 } from './parse-cst.js';
|
|
3
|
-
import {
|
|
4
|
-
import { S as
|
|
5
|
-
import {
|
|
2
|
+
import { d as defaultTagPrefix, _ as _defineProperty, T as Type, Y as YAMLSyntaxError, a as YAMLWarning, b as YAMLSemanticError, c as YAMLError } from './PlainValue-183afbad.js';
|
|
3
|
+
import { b as binaryOptions, a as boolOptions, i as intOptions, n as nullOptions, s as strOptions, N as Node, P as Pair, S as Scalar, c as stringifyString, A as Alias, Y as YAMLSeq, d as YAMLMap, M as Merge, C as Collection, r as resolveNode, e as isEmptyPath, t as toJSON, f as addComment } from './resolveSeq-67caf78a.js';
|
|
4
|
+
import { S as Schema } from './Schema-9530c078.js';
|
|
5
|
+
import { w as warn } from './warnings-5e4358fe.js';
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
const defaultOptions = {
|
|
8
8
|
anchorPrefix: 'a',
|
|
9
9
|
customTags: null,
|
|
10
10
|
indent: 2,
|
|
@@ -19,49 +19,39 @@ var defaultOptions = {
|
|
|
19
19
|
simpleKeys: false,
|
|
20
20
|
version: '1.2'
|
|
21
21
|
};
|
|
22
|
-
|
|
22
|
+
const scalarOptions = {
|
|
23
23
|
get binary() {
|
|
24
24
|
return binaryOptions;
|
|
25
25
|
},
|
|
26
|
-
|
|
27
26
|
set binary(opt) {
|
|
28
27
|
Object.assign(binaryOptions, opt);
|
|
29
28
|
},
|
|
30
|
-
|
|
31
29
|
get bool() {
|
|
32
30
|
return boolOptions;
|
|
33
31
|
},
|
|
34
|
-
|
|
35
32
|
set bool(opt) {
|
|
36
33
|
Object.assign(boolOptions, opt);
|
|
37
34
|
},
|
|
38
|
-
|
|
39
35
|
get int() {
|
|
40
36
|
return intOptions;
|
|
41
37
|
},
|
|
42
|
-
|
|
43
38
|
set int(opt) {
|
|
44
39
|
Object.assign(intOptions, opt);
|
|
45
40
|
},
|
|
46
|
-
|
|
47
41
|
get null() {
|
|
48
42
|
return nullOptions;
|
|
49
43
|
},
|
|
50
|
-
|
|
51
44
|
set null(opt) {
|
|
52
45
|
Object.assign(nullOptions, opt);
|
|
53
46
|
},
|
|
54
|
-
|
|
55
47
|
get str() {
|
|
56
48
|
return strOptions;
|
|
57
49
|
},
|
|
58
|
-
|
|
59
50
|
set str(opt) {
|
|
60
51
|
Object.assign(strOptions, opt);
|
|
61
52
|
}
|
|
62
|
-
|
|
63
53
|
};
|
|
64
|
-
|
|
54
|
+
const documentOptions = {
|
|
65
55
|
'1.0': {
|
|
66
56
|
schema: 'yaml-1.1',
|
|
67
57
|
merge: true,
|
|
@@ -99,280 +89,196 @@ var documentOptions = {
|
|
|
99
89
|
|
|
100
90
|
function stringifyTag(doc, tag) {
|
|
101
91
|
if ((doc.version || doc.options.version) === '1.0') {
|
|
102
|
-
|
|
92
|
+
const priv = tag.match(/^tag:private\.yaml\.org,2002:([^:/]+)$/);
|
|
103
93
|
if (priv) return '!' + priv[1];
|
|
104
|
-
|
|
105
|
-
return vocab ?
|
|
94
|
+
const vocab = tag.match(/^tag:([a-zA-Z0-9-]+)\.yaml\.org,2002:(.*)/);
|
|
95
|
+
return vocab ? `!${vocab[1]}/${vocab[2]}` : `!${tag.replace(/^tag:/, '')}`;
|
|
106
96
|
}
|
|
107
|
-
|
|
108
|
-
var p = doc.tagPrefixes.find(function (p) {
|
|
109
|
-
return tag.indexOf(p.prefix) === 0;
|
|
110
|
-
});
|
|
111
|
-
|
|
97
|
+
let p = doc.tagPrefixes.find(p => tag.indexOf(p.prefix) === 0);
|
|
112
98
|
if (!p) {
|
|
113
|
-
|
|
114
|
-
p = dtp && dtp.find(
|
|
115
|
-
return tag.indexOf(p.prefix) === 0;
|
|
116
|
-
});
|
|
99
|
+
const dtp = doc.getDefaults().tagPrefixes;
|
|
100
|
+
p = dtp && dtp.find(p => tag.indexOf(p.prefix) === 0);
|
|
117
101
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
'}': '%7D'
|
|
128
|
-
}[ch];
|
|
129
|
-
});
|
|
102
|
+
if (!p) return tag[0] === '!' ? tag : `!<${tag}>`;
|
|
103
|
+
const suffix = tag.substr(p.prefix.length).replace(/[!,[\]{}]/g, ch => ({
|
|
104
|
+
'!': '%21',
|
|
105
|
+
',': '%2C',
|
|
106
|
+
'[': '%5B',
|
|
107
|
+
']': '%5D',
|
|
108
|
+
'{': '%7B',
|
|
109
|
+
'}': '%7D'
|
|
110
|
+
})[ch]);
|
|
130
111
|
return p.handle + suffix;
|
|
131
112
|
}
|
|
132
113
|
|
|
133
114
|
function getTagObject(tags, item) {
|
|
134
115
|
if (item instanceof Alias) return Alias;
|
|
135
|
-
|
|
136
116
|
if (item.tag) {
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
});
|
|
140
|
-
if (match.length > 0) return match.find(function (t) {
|
|
141
|
-
return t.format === item.format;
|
|
142
|
-
}) || match[0];
|
|
117
|
+
const match = tags.filter(t => t.tag === item.tag);
|
|
118
|
+
if (match.length > 0) return match.find(t => t.format === item.format) || match[0];
|
|
143
119
|
}
|
|
144
|
-
|
|
145
|
-
var tagObj, obj;
|
|
146
|
-
|
|
120
|
+
let tagObj, obj;
|
|
147
121
|
if (item instanceof Scalar) {
|
|
148
|
-
obj = item.value;
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
tagObj = _match.find(function (t) {
|
|
155
|
-
return t.format === item.format;
|
|
156
|
-
}) || _match.find(function (t) {
|
|
157
|
-
return !t.format;
|
|
158
|
-
});
|
|
122
|
+
obj = item.value;
|
|
123
|
+
// TODO: deprecate/remove class check
|
|
124
|
+
const match = tags.filter(t => t.identify && t.identify(obj) || t.class && obj instanceof t.class);
|
|
125
|
+
tagObj = match.find(t => t.format === item.format) || match.find(t => !t.format);
|
|
159
126
|
} else {
|
|
160
127
|
obj = item;
|
|
161
|
-
tagObj = tags.find(
|
|
162
|
-
return t.nodeClass && obj instanceof t.nodeClass;
|
|
163
|
-
});
|
|
128
|
+
tagObj = tags.find(t => t.nodeClass && obj instanceof t.nodeClass);
|
|
164
129
|
}
|
|
165
|
-
|
|
166
130
|
if (!tagObj) {
|
|
167
|
-
|
|
168
|
-
throw new Error(
|
|
131
|
+
const name = obj && obj.constructor ? obj.constructor.name : typeof obj;
|
|
132
|
+
throw new Error(`Tag not resolved for ${name} value`);
|
|
169
133
|
}
|
|
170
|
-
|
|
171
134
|
return tagObj;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
function stringifyProps(node, tagObj, _ref) {
|
|
176
|
-
var anchors = _ref.anchors,
|
|
177
|
-
doc = _ref.doc;
|
|
178
|
-
var props = [];
|
|
179
|
-
var anchor = doc.anchors.getName(node);
|
|
135
|
+
}
|
|
180
136
|
|
|
137
|
+
// needs to be called before value stringifier to allow for circular anchor refs
|
|
138
|
+
function stringifyProps(node, tagObj, {
|
|
139
|
+
anchors,
|
|
140
|
+
doc
|
|
141
|
+
}) {
|
|
142
|
+
const props = [];
|
|
143
|
+
const anchor = doc.anchors.getName(node);
|
|
181
144
|
if (anchor) {
|
|
182
145
|
anchors[anchor] = node;
|
|
183
|
-
props.push(
|
|
146
|
+
props.push(`&${anchor}`);
|
|
184
147
|
}
|
|
185
|
-
|
|
186
148
|
if (node.tag) {
|
|
187
149
|
props.push(stringifyTag(doc, node.tag));
|
|
188
150
|
} else if (!tagObj.default) {
|
|
189
151
|
props.push(stringifyTag(doc, tagObj.tag));
|
|
190
152
|
}
|
|
191
|
-
|
|
192
153
|
return props.join(' ');
|
|
193
154
|
}
|
|
194
|
-
|
|
195
155
|
function stringify$1(item, ctx, onComment, onChompKeep) {
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
156
|
+
const {
|
|
157
|
+
anchors,
|
|
158
|
+
schema
|
|
159
|
+
} = ctx.doc;
|
|
160
|
+
let tagObj;
|
|
201
161
|
if (!(item instanceof Node)) {
|
|
202
|
-
|
|
162
|
+
const createCtx = {
|
|
203
163
|
aliasNodes: [],
|
|
204
|
-
onTagObj:
|
|
205
|
-
return tagObj = o;
|
|
206
|
-
},
|
|
164
|
+
onTagObj: o => tagObj = o,
|
|
207
165
|
prevObjects: new Map()
|
|
208
166
|
};
|
|
209
167
|
item = schema.createNode(item, true, null, createCtx);
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
var alias = _step.value;
|
|
217
|
-
alias.source = alias.source.node;
|
|
218
|
-
var name = anchors.getName(alias.source);
|
|
219
|
-
|
|
220
|
-
if (!name) {
|
|
221
|
-
name = anchors.newName();
|
|
222
|
-
anchors.map[name] = alias.source;
|
|
223
|
-
}
|
|
168
|
+
for (const alias of createCtx.aliasNodes) {
|
|
169
|
+
alias.source = alias.source.node;
|
|
170
|
+
let name = anchors.getName(alias.source);
|
|
171
|
+
if (!name) {
|
|
172
|
+
name = anchors.newName();
|
|
173
|
+
anchors.map[name] = alias.source;
|
|
224
174
|
}
|
|
225
|
-
} catch (err) {
|
|
226
|
-
_iterator.e(err);
|
|
227
|
-
} finally {
|
|
228
|
-
_iterator.f();
|
|
229
175
|
}
|
|
230
176
|
}
|
|
231
|
-
|
|
232
177
|
if (item instanceof Pair) return item.toString(ctx, onComment, onChompKeep);
|
|
233
178
|
if (!tagObj) tagObj = getTagObject(schema.tags, item);
|
|
234
|
-
|
|
179
|
+
const props = stringifyProps(item, tagObj, ctx);
|
|
235
180
|
if (props.length > 0) ctx.indentAtStart = (ctx.indentAtStart || 0) + props.length + 1;
|
|
236
|
-
|
|
181
|
+
const str = typeof tagObj.stringify === 'function' ? tagObj.stringify(item, ctx, onComment, onChompKeep) : item instanceof Scalar ? stringifyString(item, ctx, onComment, onChompKeep) : item.toString(ctx, onComment, onChompKeep);
|
|
237
182
|
if (!props) return str;
|
|
238
|
-
return item instanceof Scalar || str[0] === '{' || str[0] === '[' ?
|
|
183
|
+
return item instanceof Scalar || str[0] === '{' || str[0] === '[' ? `${props} ${str}` : `${props}\n${ctx.indent}${str}`;
|
|
239
184
|
}
|
|
240
185
|
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
186
|
+
class Anchors {
|
|
187
|
+
static validAnchorNode(node) {
|
|
188
|
+
return node instanceof Scalar || node instanceof YAMLSeq || node instanceof YAMLMap;
|
|
189
|
+
}
|
|
190
|
+
constructor(prefix) {
|
|
245
191
|
_defineProperty(this, "map", Object.create(null));
|
|
246
|
-
|
|
247
192
|
this.prefix = prefix;
|
|
248
193
|
}
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
var merge = new Merge();
|
|
262
|
-
|
|
263
|
-
for (var _len = arguments.length, sources = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
264
|
-
sources[_key] = arguments[_key];
|
|
194
|
+
createAlias(node, name) {
|
|
195
|
+
this.setAnchor(node, name);
|
|
196
|
+
return new Alias(node);
|
|
197
|
+
}
|
|
198
|
+
createMergePair(...sources) {
|
|
199
|
+
const merge = new Merge();
|
|
200
|
+
merge.value.items = sources.map(s => {
|
|
201
|
+
if (s instanceof Alias) {
|
|
202
|
+
if (s.source instanceof YAMLMap) return s;
|
|
203
|
+
} else if (s instanceof YAMLMap) {
|
|
204
|
+
return this.createAlias(s);
|
|
265
205
|
}
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
value: function getNames() {
|
|
289
|
-
return Object.keys(this.map);
|
|
290
|
-
}
|
|
291
|
-
}, {
|
|
292
|
-
key: "getNode",
|
|
293
|
-
value: function getNode(name) {
|
|
294
|
-
return this.map[name];
|
|
206
|
+
throw new Error('Merge sources must be Map nodes or their Aliases');
|
|
207
|
+
});
|
|
208
|
+
return merge;
|
|
209
|
+
}
|
|
210
|
+
getName(node) {
|
|
211
|
+
const {
|
|
212
|
+
map
|
|
213
|
+
} = this;
|
|
214
|
+
return Object.keys(map).find(a => map[a] === node);
|
|
215
|
+
}
|
|
216
|
+
getNames() {
|
|
217
|
+
return Object.keys(this.map);
|
|
218
|
+
}
|
|
219
|
+
getNode(name) {
|
|
220
|
+
return this.map[name];
|
|
221
|
+
}
|
|
222
|
+
newName(prefix) {
|
|
223
|
+
if (!prefix) prefix = this.prefix;
|
|
224
|
+
const names = Object.keys(this.map);
|
|
225
|
+
for (let i = 1; true; ++i) {
|
|
226
|
+
const name = `${prefix}${i}`;
|
|
227
|
+
if (!names.includes(name)) return name;
|
|
295
228
|
}
|
|
296
|
-
}
|
|
297
|
-
key: "newName",
|
|
298
|
-
value: function newName(prefix) {
|
|
299
|
-
if (!prefix) prefix = this.prefix;
|
|
300
|
-
var names = Object.keys(this.map);
|
|
301
|
-
|
|
302
|
-
for (var i = 1; true; ++i) {
|
|
303
|
-
var name = "".concat(prefix).concat(i);
|
|
304
|
-
if (!names.includes(name)) return name;
|
|
305
|
-
}
|
|
306
|
-
} // During parsing, map & aliases contain CST nodes
|
|
307
|
-
|
|
308
|
-
}, {
|
|
309
|
-
key: "resolveNodes",
|
|
310
|
-
value: function resolveNodes() {
|
|
311
|
-
var map = this.map,
|
|
312
|
-
_cstAliases = this._cstAliases;
|
|
313
|
-
Object.keys(map).forEach(function (a) {
|
|
314
|
-
map[a] = map[a].resolved;
|
|
315
|
-
});
|
|
316
|
-
|
|
317
|
-
_cstAliases.forEach(function (a) {
|
|
318
|
-
a.source = a.source.resolved;
|
|
319
|
-
});
|
|
229
|
+
}
|
|
320
230
|
|
|
321
|
-
|
|
231
|
+
// During parsing, map & aliases contain CST nodes
|
|
232
|
+
resolveNodes() {
|
|
233
|
+
const {
|
|
234
|
+
map,
|
|
235
|
+
_cstAliases
|
|
236
|
+
} = this;
|
|
237
|
+
Object.keys(map).forEach(a => {
|
|
238
|
+
map[a] = map[a].resolved;
|
|
239
|
+
});
|
|
240
|
+
_cstAliases.forEach(a => {
|
|
241
|
+
a.source = a.source.resolved;
|
|
242
|
+
});
|
|
243
|
+
delete this._cstAliases;
|
|
244
|
+
}
|
|
245
|
+
setAnchor(node, name) {
|
|
246
|
+
if (node != null && !Anchors.validAnchorNode(node)) {
|
|
247
|
+
throw new Error('Anchors may only be set for Scalar, Seq and Map nodes');
|
|
322
248
|
}
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
var prev = node && Object.keys(map).find(function (a) {
|
|
336
|
-
return map[a] === node;
|
|
337
|
-
});
|
|
338
|
-
|
|
339
|
-
if (prev) {
|
|
340
|
-
if (!name) {
|
|
341
|
-
return prev;
|
|
342
|
-
} else if (prev !== name) {
|
|
343
|
-
delete map[prev];
|
|
344
|
-
map[name] = node;
|
|
345
|
-
}
|
|
346
|
-
} else {
|
|
347
|
-
if (!name) {
|
|
348
|
-
if (!node) return null;
|
|
349
|
-
name = this.newName();
|
|
350
|
-
}
|
|
351
|
-
|
|
249
|
+
if (name && /[\x00-\x19\s,[\]{}]/.test(name)) {
|
|
250
|
+
throw new Error('Anchor names must not contain whitespace or control characters');
|
|
251
|
+
}
|
|
252
|
+
const {
|
|
253
|
+
map
|
|
254
|
+
} = this;
|
|
255
|
+
const prev = node && Object.keys(map).find(a => map[a] === node);
|
|
256
|
+
if (prev) {
|
|
257
|
+
if (!name) {
|
|
258
|
+
return prev;
|
|
259
|
+
} else if (prev !== name) {
|
|
260
|
+
delete map[prev];
|
|
352
261
|
map[name] = node;
|
|
353
262
|
}
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
return node instanceof Scalar || node instanceof YAMLSeq || node instanceof YAMLMap;
|
|
263
|
+
} else {
|
|
264
|
+
if (!name) {
|
|
265
|
+
if (!node) return null;
|
|
266
|
+
name = this.newName();
|
|
267
|
+
}
|
|
268
|
+
map[name] = node;
|
|
361
269
|
}
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
}();
|
|
366
|
-
|
|
367
|
-
var visit = function visit(node, tags) {
|
|
368
|
-
if (node && _typeof(node) === 'object') {
|
|
369
|
-
var tag = node.tag;
|
|
270
|
+
return name;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
370
273
|
|
|
274
|
+
const visit = (node, tags) => {
|
|
275
|
+
if (node && typeof node === 'object') {
|
|
276
|
+
const {
|
|
277
|
+
tag
|
|
278
|
+
} = node;
|
|
371
279
|
if (node instanceof Collection) {
|
|
372
280
|
if (tag) tags[tag] = true;
|
|
373
|
-
node.items.forEach(
|
|
374
|
-
return visit(n, tags);
|
|
375
|
-
});
|
|
281
|
+
node.items.forEach(n => visit(n, tags));
|
|
376
282
|
} else if (node instanceof Pair) {
|
|
377
283
|
visit(node.key, tags);
|
|
378
284
|
visit(node.value, tags);
|
|
@@ -380,197 +286,135 @@ var visit = function visit(node, tags) {
|
|
|
380
286
|
if (tag) tags[tag] = true;
|
|
381
287
|
}
|
|
382
288
|
}
|
|
383
|
-
|
|
384
289
|
return tags;
|
|
385
290
|
};
|
|
386
|
-
|
|
387
|
-
var listTagNames = function listTagNames(node) {
|
|
388
|
-
return Object.keys(visit(node, {}));
|
|
389
|
-
};
|
|
291
|
+
const listTagNames = node => Object.keys(visit(node, {}));
|
|
390
292
|
|
|
391
293
|
function parseContents(doc, contents) {
|
|
392
|
-
|
|
294
|
+
const comments = {
|
|
393
295
|
before: [],
|
|
394
296
|
after: []
|
|
395
297
|
};
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
if (
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
body = res;
|
|
421
|
-
} else if (node.comment !== null) {
|
|
422
|
-
var cc = body === undefined ? comments.before : comments.after;
|
|
423
|
-
cc.push(node.comment);
|
|
424
|
-
} else if (node.type === Type.BLANK_LINE) {
|
|
425
|
-
spaceBefore = true;
|
|
426
|
-
|
|
427
|
-
if (body === undefined && comments.before.length > 0 && !doc.commentBefore) {
|
|
428
|
-
// space-separated comments at start are parsed as document comments
|
|
429
|
-
doc.commentBefore = comments.before.join('\n');
|
|
430
|
-
comments.before = [];
|
|
431
|
-
}
|
|
298
|
+
let body = undefined;
|
|
299
|
+
let spaceBefore = false;
|
|
300
|
+
for (const node of contents) {
|
|
301
|
+
if (node.valueRange) {
|
|
302
|
+
if (body !== undefined) {
|
|
303
|
+
const msg = 'Document contains trailing content not separated by a ... or --- line';
|
|
304
|
+
doc.errors.push(new YAMLSyntaxError(node, msg));
|
|
305
|
+
break;
|
|
306
|
+
}
|
|
307
|
+
const res = resolveNode(doc, node);
|
|
308
|
+
if (spaceBefore) {
|
|
309
|
+
res.spaceBefore = true;
|
|
310
|
+
spaceBefore = false;
|
|
311
|
+
}
|
|
312
|
+
body = res;
|
|
313
|
+
} else if (node.comment !== null) {
|
|
314
|
+
const cc = body === undefined ? comments.before : comments.after;
|
|
315
|
+
cc.push(node.comment);
|
|
316
|
+
} else if (node.type === Type.BLANK_LINE) {
|
|
317
|
+
spaceBefore = true;
|
|
318
|
+
if (body === undefined && comments.before.length > 0 && !doc.commentBefore) {
|
|
319
|
+
// space-separated comments at start are parsed as document comments
|
|
320
|
+
doc.commentBefore = comments.before.join('\n');
|
|
321
|
+
comments.before = [];
|
|
432
322
|
}
|
|
433
323
|
}
|
|
434
|
-
} catch (err) {
|
|
435
|
-
_iterator.e(err);
|
|
436
|
-
} finally {
|
|
437
|
-
_iterator.f();
|
|
438
324
|
}
|
|
439
|
-
|
|
440
325
|
doc.contents = body || null;
|
|
441
|
-
|
|
442
326
|
if (!body) {
|
|
443
327
|
doc.comment = comments.before.concat(comments.after).join('\n') || null;
|
|
444
328
|
} else {
|
|
445
|
-
|
|
446
|
-
|
|
329
|
+
const cb = comments.before.join('\n');
|
|
447
330
|
if (cb) {
|
|
448
|
-
|
|
449
|
-
cbNode.commentBefore = cbNode.commentBefore ?
|
|
331
|
+
const cbNode = body instanceof Collection && body.items[0] ? body.items[0] : body;
|
|
332
|
+
cbNode.commentBefore = cbNode.commentBefore ? `${cb}\n${cbNode.commentBefore}` : cb;
|
|
450
333
|
}
|
|
451
|
-
|
|
452
334
|
doc.comment = comments.after.join('\n') || null;
|
|
453
335
|
}
|
|
454
336
|
}
|
|
455
337
|
|
|
456
|
-
function resolveTagDirective(
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
handle = _directive$parameters[0],
|
|
461
|
-
prefix = _directive$parameters[1];
|
|
462
|
-
|
|
338
|
+
function resolveTagDirective({
|
|
339
|
+
tagPrefixes
|
|
340
|
+
}, directive) {
|
|
341
|
+
const [handle, prefix] = directive.parameters;
|
|
463
342
|
if (!handle || !prefix) {
|
|
464
|
-
|
|
343
|
+
const msg = 'Insufficient parameters given for %TAG directive';
|
|
465
344
|
throw new YAMLSemanticError(directive, msg);
|
|
466
345
|
}
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
})) {
|
|
471
|
-
var _msg = 'The %TAG directive must only be given at most once per handle in the same document.';
|
|
472
|
-
throw new YAMLSemanticError(directive, _msg);
|
|
346
|
+
if (tagPrefixes.some(p => p.handle === handle)) {
|
|
347
|
+
const msg = 'The %TAG directive must only be given at most once per handle in the same document.';
|
|
348
|
+
throw new YAMLSemanticError(directive, msg);
|
|
473
349
|
}
|
|
474
|
-
|
|
475
350
|
return {
|
|
476
|
-
handle
|
|
477
|
-
prefix
|
|
351
|
+
handle,
|
|
352
|
+
prefix
|
|
478
353
|
};
|
|
479
354
|
}
|
|
480
|
-
|
|
481
355
|
function resolveYamlDirective(doc, directive) {
|
|
482
|
-
|
|
483
|
-
version = _directive$parameters2[0];
|
|
484
|
-
|
|
356
|
+
let [version] = directive.parameters;
|
|
485
357
|
if (directive.name === 'YAML:1.0') version = '1.0';
|
|
486
|
-
|
|
487
358
|
if (!version) {
|
|
488
|
-
|
|
359
|
+
const msg = 'Insufficient parameters given for %YAML directive';
|
|
489
360
|
throw new YAMLSemanticError(directive, msg);
|
|
490
361
|
}
|
|
491
|
-
|
|
492
362
|
if (!documentOptions[version]) {
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
doc.warnings.push(new YAMLWarning(directive, _msg2));
|
|
363
|
+
const v0 = doc.version || doc.options.version;
|
|
364
|
+
const msg = `Document will be parsed as YAML ${v0} rather than YAML ${version}`;
|
|
365
|
+
doc.warnings.push(new YAMLWarning(directive, msg));
|
|
498
366
|
}
|
|
499
|
-
|
|
500
367
|
return version;
|
|
501
368
|
}
|
|
502
|
-
|
|
503
369
|
function parseDirectives(doc, directives, prevDoc) {
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
}
|
|
539
|
-
|
|
540
|
-
hasDirectives = true;
|
|
541
|
-
break;
|
|
542
|
-
|
|
543
|
-
default:
|
|
544
|
-
if (name) {
|
|
545
|
-
var _msg3 = "YAML only supports %TAG and %YAML directives, and not %".concat(name);
|
|
546
|
-
|
|
547
|
-
doc.warnings.push(new YAMLWarning(directive, _msg3));
|
|
548
|
-
}
|
|
549
|
-
|
|
550
|
-
}
|
|
551
|
-
|
|
552
|
-
if (comment) directiveComments.push(comment);
|
|
370
|
+
const directiveComments = [];
|
|
371
|
+
let hasDirectives = false;
|
|
372
|
+
for (const directive of directives) {
|
|
373
|
+
const {
|
|
374
|
+
comment,
|
|
375
|
+
name
|
|
376
|
+
} = directive;
|
|
377
|
+
switch (name) {
|
|
378
|
+
case 'TAG':
|
|
379
|
+
try {
|
|
380
|
+
doc.tagPrefixes.push(resolveTagDirective(doc, directive));
|
|
381
|
+
} catch (error) {
|
|
382
|
+
doc.errors.push(error);
|
|
383
|
+
}
|
|
384
|
+
hasDirectives = true;
|
|
385
|
+
break;
|
|
386
|
+
case 'YAML':
|
|
387
|
+
case 'YAML:1.0':
|
|
388
|
+
if (doc.version) {
|
|
389
|
+
const msg = 'The %YAML directive must only be given at most once per document.';
|
|
390
|
+
doc.errors.push(new YAMLSemanticError(directive, msg));
|
|
391
|
+
}
|
|
392
|
+
try {
|
|
393
|
+
doc.version = resolveYamlDirective(doc, directive);
|
|
394
|
+
} catch (error) {
|
|
395
|
+
doc.errors.push(error);
|
|
396
|
+
}
|
|
397
|
+
hasDirectives = true;
|
|
398
|
+
break;
|
|
399
|
+
default:
|
|
400
|
+
if (name) {
|
|
401
|
+
const msg = `YAML only supports %TAG and %YAML directives, and not %${name}`;
|
|
402
|
+
doc.warnings.push(new YAMLWarning(directive, msg));
|
|
403
|
+
}
|
|
553
404
|
}
|
|
554
|
-
|
|
555
|
-
_iterator.e(err);
|
|
556
|
-
} finally {
|
|
557
|
-
_iterator.f();
|
|
405
|
+
if (comment) directiveComments.push(comment);
|
|
558
406
|
}
|
|
559
|
-
|
|
560
407
|
if (prevDoc && !hasDirectives && '1.1' === (doc.version || prevDoc.version || doc.options.version)) {
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
};
|
|
569
|
-
|
|
408
|
+
const copyTagPrefix = ({
|
|
409
|
+
handle,
|
|
410
|
+
prefix
|
|
411
|
+
}) => ({
|
|
412
|
+
handle,
|
|
413
|
+
prefix
|
|
414
|
+
});
|
|
570
415
|
doc.tagPrefixes = prevDoc.tagPrefixes.map(copyTagPrefix);
|
|
571
416
|
doc.version = prevDoc.version;
|
|
572
417
|
}
|
|
573
|
-
|
|
574
418
|
doc.commentBefore = directiveComments.join('\n') || null;
|
|
575
419
|
}
|
|
576
420
|
|
|
@@ -578,11 +422,8 @@ function assertCollection(contents) {
|
|
|
578
422
|
if (contents instanceof Collection) return true;
|
|
579
423
|
throw new Error('Expected a YAML collection as document contents');
|
|
580
424
|
}
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
function Document(options) {
|
|
584
|
-
_classCallCheck(this, Document);
|
|
585
|
-
|
|
425
|
+
class Document$1 {
|
|
426
|
+
constructor(options) {
|
|
586
427
|
this.anchors = new Anchors(options.anchorPrefix);
|
|
587
428
|
this.commentBefore = null;
|
|
588
429
|
this.comment = null;
|
|
@@ -595,408 +436,257 @@ var Document$1 = /*#__PURE__*/function () {
|
|
|
595
436
|
this.version = null;
|
|
596
437
|
this.warnings = [];
|
|
597
438
|
}
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
}
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
return this.contents.delete(key);
|
|
616
|
-
}
|
|
617
|
-
}, {
|
|
618
|
-
key: "deleteIn",
|
|
619
|
-
value: function deleteIn(path) {
|
|
620
|
-
if (isEmptyPath(path)) {
|
|
621
|
-
if (this.contents == null) return false;
|
|
622
|
-
this.contents = null;
|
|
623
|
-
return true;
|
|
624
|
-
}
|
|
625
|
-
|
|
626
|
-
assertCollection(this.contents);
|
|
627
|
-
return this.contents.deleteIn(path);
|
|
628
|
-
}
|
|
629
|
-
}, {
|
|
630
|
-
key: "getDefaults",
|
|
631
|
-
value: function getDefaults() {
|
|
632
|
-
return Document.defaults[this.version] || Document.defaults[this.options.version] || {};
|
|
633
|
-
}
|
|
634
|
-
}, {
|
|
635
|
-
key: "get",
|
|
636
|
-
value: function get(key, keepScalar) {
|
|
637
|
-
return this.contents instanceof Collection ? this.contents.get(key, keepScalar) : undefined;
|
|
638
|
-
}
|
|
639
|
-
}, {
|
|
640
|
-
key: "getIn",
|
|
641
|
-
value: function getIn(path, keepScalar) {
|
|
642
|
-
if (isEmptyPath(path)) return !keepScalar && this.contents instanceof Scalar ? this.contents.value : this.contents;
|
|
643
|
-
return this.contents instanceof Collection ? this.contents.getIn(path, keepScalar) : undefined;
|
|
644
|
-
}
|
|
645
|
-
}, {
|
|
646
|
-
key: "has",
|
|
647
|
-
value: function has(key) {
|
|
648
|
-
return this.contents instanceof Collection ? this.contents.has(key) : false;
|
|
649
|
-
}
|
|
650
|
-
}, {
|
|
651
|
-
key: "hasIn",
|
|
652
|
-
value: function hasIn(path) {
|
|
653
|
-
if (isEmptyPath(path)) return this.contents !== undefined;
|
|
654
|
-
return this.contents instanceof Collection ? this.contents.hasIn(path) : false;
|
|
439
|
+
add(value) {
|
|
440
|
+
assertCollection(this.contents);
|
|
441
|
+
return this.contents.add(value);
|
|
442
|
+
}
|
|
443
|
+
addIn(path, value) {
|
|
444
|
+
assertCollection(this.contents);
|
|
445
|
+
this.contents.addIn(path, value);
|
|
446
|
+
}
|
|
447
|
+
delete(key) {
|
|
448
|
+
assertCollection(this.contents);
|
|
449
|
+
return this.contents.delete(key);
|
|
450
|
+
}
|
|
451
|
+
deleteIn(path) {
|
|
452
|
+
if (isEmptyPath(path)) {
|
|
453
|
+
if (this.contents == null) return false;
|
|
454
|
+
this.contents = null;
|
|
455
|
+
return true;
|
|
655
456
|
}
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
457
|
+
assertCollection(this.contents);
|
|
458
|
+
return this.contents.deleteIn(path);
|
|
459
|
+
}
|
|
460
|
+
getDefaults() {
|
|
461
|
+
return Document$1.defaults[this.version] || Document$1.defaults[this.options.version] || {};
|
|
462
|
+
}
|
|
463
|
+
get(key, keepScalar) {
|
|
464
|
+
return this.contents instanceof Collection ? this.contents.get(key, keepScalar) : undefined;
|
|
465
|
+
}
|
|
466
|
+
getIn(path, keepScalar) {
|
|
467
|
+
if (isEmptyPath(path)) return !keepScalar && this.contents instanceof Scalar ? this.contents.value : this.contents;
|
|
468
|
+
return this.contents instanceof Collection ? this.contents.getIn(path, keepScalar) : undefined;
|
|
469
|
+
}
|
|
470
|
+
has(key) {
|
|
471
|
+
return this.contents instanceof Collection ? this.contents.has(key) : false;
|
|
472
|
+
}
|
|
473
|
+
hasIn(path) {
|
|
474
|
+
if (isEmptyPath(path)) return this.contents !== undefined;
|
|
475
|
+
return this.contents instanceof Collection ? this.contents.hasIn(path) : false;
|
|
476
|
+
}
|
|
477
|
+
set(key, value) {
|
|
478
|
+
assertCollection(this.contents);
|
|
479
|
+
this.contents.set(key, value);
|
|
480
|
+
}
|
|
481
|
+
setIn(path, value) {
|
|
482
|
+
if (isEmptyPath(path)) this.contents = value;else {
|
|
659
483
|
assertCollection(this.contents);
|
|
660
|
-
this.contents.
|
|
484
|
+
this.contents.setIn(path, value);
|
|
661
485
|
}
|
|
662
|
-
}
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
486
|
+
}
|
|
487
|
+
setSchema(id, customTags) {
|
|
488
|
+
if (!id && !customTags && this.schema) return;
|
|
489
|
+
if (typeof id === 'number') id = id.toFixed(1);
|
|
490
|
+
if (id === '1.0' || id === '1.1' || id === '1.2') {
|
|
491
|
+
if (this.version) this.version = id;else this.options.version = id;
|
|
492
|
+
delete this.options.schema;
|
|
493
|
+
} else if (id && typeof id === 'string') {
|
|
494
|
+
this.options.schema = id;
|
|
669
495
|
}
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
496
|
+
if (Array.isArray(customTags)) this.options.customTags = customTags;
|
|
497
|
+
const opt = Object.assign({}, this.getDefaults(), this.options);
|
|
498
|
+
this.schema = new Schema(opt);
|
|
499
|
+
}
|
|
500
|
+
parse(node, prevDoc) {
|
|
501
|
+
if (this.options.keepCstNodes) this.cstNode = node;
|
|
502
|
+
if (this.options.keepNodeTypes) this.type = 'DOCUMENT';
|
|
503
|
+
const {
|
|
504
|
+
directives = [],
|
|
505
|
+
contents = [],
|
|
506
|
+
directivesEndMarker,
|
|
507
|
+
error,
|
|
508
|
+
valueRange
|
|
509
|
+
} = node;
|
|
510
|
+
if (error) {
|
|
511
|
+
if (!error.source) error.source = this;
|
|
512
|
+
this.errors.push(error);
|
|
686
513
|
}
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
error = node.error,
|
|
698
|
-
valueRange = node.valueRange;
|
|
699
|
-
|
|
700
|
-
if (error) {
|
|
701
|
-
if (!error.source) error.source = this;
|
|
702
|
-
this.errors.push(error);
|
|
703
|
-
}
|
|
704
|
-
|
|
705
|
-
parseDirectives(this, directives, prevDoc);
|
|
706
|
-
if (directivesEndMarker) this.directivesEndMarker = true;
|
|
707
|
-
this.range = valueRange ? [valueRange.start, valueRange.end] : null;
|
|
708
|
-
this.setSchema();
|
|
709
|
-
this.anchors._cstAliases = [];
|
|
710
|
-
parseContents(this, contents);
|
|
711
|
-
this.anchors.resolveNodes();
|
|
712
|
-
|
|
713
|
-
if (this.options.prettyErrors) {
|
|
714
|
-
var _iterator = _createForOfIteratorHelper(this.errors),
|
|
715
|
-
_step;
|
|
716
|
-
|
|
717
|
-
try {
|
|
718
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
719
|
-
var _error = _step.value;
|
|
720
|
-
if (_error instanceof YAMLError) _error.makePretty();
|
|
721
|
-
}
|
|
722
|
-
} catch (err) {
|
|
723
|
-
_iterator.e(err);
|
|
724
|
-
} finally {
|
|
725
|
-
_iterator.f();
|
|
726
|
-
}
|
|
727
|
-
|
|
728
|
-
var _iterator2 = _createForOfIteratorHelper(this.warnings),
|
|
729
|
-
_step2;
|
|
730
|
-
|
|
731
|
-
try {
|
|
732
|
-
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
733
|
-
var warn = _step2.value;
|
|
734
|
-
if (warn instanceof YAMLError) warn.makePretty();
|
|
735
|
-
}
|
|
736
|
-
} catch (err) {
|
|
737
|
-
_iterator2.e(err);
|
|
738
|
-
} finally {
|
|
739
|
-
_iterator2.f();
|
|
740
|
-
}
|
|
741
|
-
}
|
|
742
|
-
|
|
743
|
-
return this;
|
|
514
|
+
parseDirectives(this, directives, prevDoc);
|
|
515
|
+
if (directivesEndMarker) this.directivesEndMarker = true;
|
|
516
|
+
this.range = valueRange ? [valueRange.start, valueRange.end] : null;
|
|
517
|
+
this.setSchema();
|
|
518
|
+
this.anchors._cstAliases = [];
|
|
519
|
+
parseContents(this, contents);
|
|
520
|
+
this.anchors.resolveNodes();
|
|
521
|
+
if (this.options.prettyErrors) {
|
|
522
|
+
for (const error of this.errors) if (error instanceof YAMLError) error.makePretty();
|
|
523
|
+
for (const warn of this.warnings) if (warn instanceof YAMLError) warn.makePretty();
|
|
744
524
|
}
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
525
|
+
return this;
|
|
526
|
+
}
|
|
527
|
+
listNonDefaultTags() {
|
|
528
|
+
return listTagNames(this.contents).filter(t => t.indexOf(Schema.defaultPrefix) !== 0);
|
|
529
|
+
}
|
|
530
|
+
setTagPrefix(handle, prefix) {
|
|
531
|
+
if (handle[0] !== '!' || handle[handle.length - 1] !== '!') throw new Error('Handle must start and end with !');
|
|
532
|
+
if (prefix) {
|
|
533
|
+
const prev = this.tagPrefixes.find(p => p.handle === handle);
|
|
534
|
+
if (prev) prev.prefix = prefix;else this.tagPrefixes.push({
|
|
535
|
+
handle,
|
|
536
|
+
prefix
|
|
750
537
|
});
|
|
538
|
+
} else {
|
|
539
|
+
this.tagPrefixes = this.tagPrefixes.filter(p => p.handle !== handle);
|
|
751
540
|
}
|
|
752
|
-
}
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
541
|
+
}
|
|
542
|
+
toJSON(arg, onAnchor) {
|
|
543
|
+
const {
|
|
544
|
+
keepBlobsInJSON,
|
|
545
|
+
mapAsMap,
|
|
546
|
+
maxAliasCount
|
|
547
|
+
} = this.options;
|
|
548
|
+
const keep = keepBlobsInJSON && (typeof arg !== 'string' || !(this.contents instanceof Scalar));
|
|
549
|
+
const ctx = {
|
|
550
|
+
doc: this,
|
|
551
|
+
indentStep: ' ',
|
|
552
|
+
keep,
|
|
553
|
+
mapAsMap: keep && !!mapAsMap,
|
|
554
|
+
maxAliasCount,
|
|
555
|
+
stringify: stringify$1 // Requiring directly in Pair would create circular dependencies
|
|
556
|
+
};
|
|
557
|
+
const anchorNames = Object.keys(this.anchors.map);
|
|
558
|
+
if (anchorNames.length > 0) ctx.anchors = new Map(anchorNames.map(name => [this.anchors.map[name], {
|
|
559
|
+
alias: [],
|
|
560
|
+
aliasCount: 0,
|
|
561
|
+
count: 1
|
|
562
|
+
}]));
|
|
563
|
+
const res = toJSON(this.contents, arg, ctx);
|
|
564
|
+
if (typeof onAnchor === 'function' && ctx.anchors) for (const {
|
|
565
|
+
count,
|
|
566
|
+
res
|
|
567
|
+
} of ctx.anchors.values()) onAnchor(res, count);
|
|
568
|
+
return res;
|
|
569
|
+
}
|
|
570
|
+
toString() {
|
|
571
|
+
if (this.errors.length > 0) throw new Error('Document with errors cannot be stringified');
|
|
572
|
+
const indentSize = this.options.indent;
|
|
573
|
+
if (!Number.isInteger(indentSize) || indentSize <= 0) {
|
|
574
|
+
const s = JSON.stringify(indentSize);
|
|
575
|
+
throw new Error(`"indent" option must be a positive integer, not ${s}`);
|
|
770
576
|
}
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
mapAsMap = _this$options.mapAsMap,
|
|
779
|
-
maxAliasCount = _this$options.maxAliasCount;
|
|
780
|
-
var keep = keepBlobsInJSON && (typeof arg !== 'string' || !(this.contents instanceof Scalar));
|
|
781
|
-
var ctx = {
|
|
782
|
-
doc: this,
|
|
783
|
-
indentStep: ' ',
|
|
784
|
-
keep: keep,
|
|
785
|
-
mapAsMap: keep && !!mapAsMap,
|
|
786
|
-
maxAliasCount: maxAliasCount,
|
|
787
|
-
stringify: stringify$1 // Requiring directly in Pair would create circular dependencies
|
|
788
|
-
|
|
789
|
-
};
|
|
790
|
-
var anchorNames = Object.keys(this.anchors.map);
|
|
791
|
-
if (anchorNames.length > 0) ctx.anchors = new Map(anchorNames.map(function (name) {
|
|
792
|
-
return [_this.anchors.map[name], {
|
|
793
|
-
alias: [],
|
|
794
|
-
aliasCount: 0,
|
|
795
|
-
count: 1
|
|
796
|
-
}];
|
|
797
|
-
}));
|
|
798
|
-
|
|
799
|
-
var res = toJSON(this.contents, arg, ctx);
|
|
800
|
-
|
|
801
|
-
if (typeof onAnchor === 'function' && ctx.anchors) {
|
|
802
|
-
var _iterator3 = _createForOfIteratorHelper(ctx.anchors.values()),
|
|
803
|
-
_step3;
|
|
804
|
-
|
|
805
|
-
try {
|
|
806
|
-
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
807
|
-
var _step3$value = _step3.value,
|
|
808
|
-
count = _step3$value.count,
|
|
809
|
-
_res = _step3$value.res;
|
|
810
|
-
onAnchor(_res, count);
|
|
811
|
-
}
|
|
812
|
-
} catch (err) {
|
|
813
|
-
_iterator3.e(err);
|
|
814
|
-
} finally {
|
|
815
|
-
_iterator3.f();
|
|
816
|
-
}
|
|
577
|
+
this.setSchema();
|
|
578
|
+
const lines = [];
|
|
579
|
+
let hasDirectives = false;
|
|
580
|
+
if (this.version) {
|
|
581
|
+
let vd = '%YAML 1.2';
|
|
582
|
+
if (this.schema.name === 'yaml-1.1') {
|
|
583
|
+
if (this.version === '1.0') vd = '%YAML:1.0';else if (this.version === '1.1') vd = '%YAML 1.1';
|
|
817
584
|
}
|
|
818
|
-
|
|
819
|
-
|
|
585
|
+
lines.push(vd);
|
|
586
|
+
hasDirectives = true;
|
|
820
587
|
}
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
var s = JSON.stringify(indentSize);
|
|
829
|
-
throw new Error("\"indent\" option must be a positive integer, not ".concat(s));
|
|
830
|
-
}
|
|
831
|
-
|
|
832
|
-
this.setSchema();
|
|
833
|
-
var lines = [];
|
|
834
|
-
var hasDirectives = false;
|
|
835
|
-
|
|
836
|
-
if (this.version) {
|
|
837
|
-
var vd = '%YAML 1.2';
|
|
838
|
-
|
|
839
|
-
if (this.schema.name === 'yaml-1.1') {
|
|
840
|
-
if (this.version === '1.0') vd = '%YAML:1.0';else if (this.version === '1.1') vd = '%YAML 1.1';
|
|
841
|
-
}
|
|
842
|
-
|
|
843
|
-
lines.push(vd);
|
|
588
|
+
const tagNames = this.listNonDefaultTags();
|
|
589
|
+
this.tagPrefixes.forEach(({
|
|
590
|
+
handle,
|
|
591
|
+
prefix
|
|
592
|
+
}) => {
|
|
593
|
+
if (tagNames.some(t => t.indexOf(prefix) === 0)) {
|
|
594
|
+
lines.push(`%TAG ${handle} ${prefix}`);
|
|
844
595
|
hasDirectives = true;
|
|
845
596
|
}
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
doc: this,
|
|
869
|
-
indent: '',
|
|
870
|
-
indentStep: ' '.repeat(indentSize),
|
|
871
|
-
stringify: stringify$1 // Requiring directly in nodes would create circular dependencies
|
|
872
|
-
|
|
873
|
-
};
|
|
874
|
-
var chompKeep = false;
|
|
875
|
-
var contentComment = null;
|
|
876
|
-
|
|
877
|
-
if (this.contents) {
|
|
878
|
-
if (this.contents instanceof Node) {
|
|
879
|
-
if (this.contents.spaceBefore && (hasDirectives || this.directivesEndMarker)) lines.push('');
|
|
880
|
-
if (this.contents.commentBefore) lines.push(this.contents.commentBefore.replace(/^/gm, '#')); // top-level block scalars need to be indented if followed by a comment
|
|
881
|
-
|
|
882
|
-
ctx.forceBlockIndent = !!this.comment;
|
|
883
|
-
contentComment = this.contents.comment;
|
|
884
|
-
}
|
|
885
|
-
|
|
886
|
-
var onChompKeep = contentComment ? null : function () {
|
|
887
|
-
return chompKeep = true;
|
|
888
|
-
};
|
|
889
|
-
var body = stringify$1(this.contents, ctx, function () {
|
|
890
|
-
return contentComment = null;
|
|
891
|
-
}, onChompKeep);
|
|
892
|
-
lines.push(addComment(body, '', contentComment));
|
|
893
|
-
} else if (this.contents !== undefined) {
|
|
894
|
-
lines.push(stringify$1(this.contents, ctx));
|
|
895
|
-
}
|
|
896
|
-
|
|
897
|
-
if (this.comment) {
|
|
898
|
-
if ((!chompKeep || contentComment) && lines[lines.length - 1] !== '') lines.push('');
|
|
899
|
-
lines.push(this.comment.replace(/^/gm, '#'));
|
|
597
|
+
});
|
|
598
|
+
if (hasDirectives || this.directivesEndMarker) lines.push('---');
|
|
599
|
+
if (this.commentBefore) {
|
|
600
|
+
if (hasDirectives || !this.directivesEndMarker) lines.unshift('');
|
|
601
|
+
lines.unshift(this.commentBefore.replace(/^/gm, '#'));
|
|
602
|
+
}
|
|
603
|
+
const ctx = {
|
|
604
|
+
anchors: Object.create(null),
|
|
605
|
+
doc: this,
|
|
606
|
+
indent: '',
|
|
607
|
+
indentStep: ' '.repeat(indentSize),
|
|
608
|
+
stringify: stringify$1 // Requiring directly in nodes would create circular dependencies
|
|
609
|
+
};
|
|
610
|
+
let chompKeep = false;
|
|
611
|
+
let contentComment = null;
|
|
612
|
+
if (this.contents) {
|
|
613
|
+
if (this.contents instanceof Node) {
|
|
614
|
+
if (this.contents.spaceBefore && (hasDirectives || this.directivesEndMarker)) lines.push('');
|
|
615
|
+
if (this.contents.commentBefore) lines.push(this.contents.commentBefore.replace(/^/gm, '#'));
|
|
616
|
+
// top-level block scalars need to be indented if followed by a comment
|
|
617
|
+
ctx.forceBlockIndent = !!this.comment;
|
|
618
|
+
contentComment = this.contents.comment;
|
|
900
619
|
}
|
|
901
|
-
|
|
902
|
-
|
|
620
|
+
const onChompKeep = contentComment ? null : () => chompKeep = true;
|
|
621
|
+
const body = stringify$1(this.contents, ctx, () => contentComment = null, onChompKeep);
|
|
622
|
+
lines.push(addComment(body, '', contentComment));
|
|
623
|
+
} else if (this.contents !== undefined) {
|
|
624
|
+
lines.push(stringify$1(this.contents, ctx));
|
|
903
625
|
}
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
}
|
|
908
|
-
|
|
626
|
+
if (this.comment) {
|
|
627
|
+
if ((!chompKeep || contentComment) && lines[lines.length - 1] !== '') lines.push('');
|
|
628
|
+
lines.push(this.comment.replace(/^/gm, '#'));
|
|
629
|
+
}
|
|
630
|
+
return lines.join('\n') + '\n';
|
|
631
|
+
}
|
|
632
|
+
}
|
|
909
633
|
_defineProperty(Document$1, "defaults", documentOptions);
|
|
910
634
|
|
|
911
|
-
function createNode(value) {
|
|
912
|
-
var wrapScalars = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
913
|
-
var tag = arguments.length > 2 ? arguments[2] : undefined;
|
|
914
|
-
|
|
635
|
+
function createNode(value, wrapScalars = true, tag) {
|
|
915
636
|
if (tag === undefined && typeof wrapScalars === 'string') {
|
|
916
637
|
tag = wrapScalars;
|
|
917
638
|
wrapScalars = true;
|
|
918
639
|
}
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
var schema = new Schema(options);
|
|
640
|
+
const options = Object.assign({}, Document$1.defaults[defaultOptions.version], defaultOptions);
|
|
641
|
+
const schema = new Schema(options);
|
|
922
642
|
return schema.createNode(value, wrapScalars, tag);
|
|
923
643
|
}
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
var _super = _createSuper(Document);
|
|
929
|
-
|
|
930
|
-
function Document(options) {
|
|
931
|
-
_classCallCheck(this, Document);
|
|
932
|
-
|
|
933
|
-
return _super.call(this, Object.assign({}, defaultOptions, options));
|
|
644
|
+
class Document extends Document$1 {
|
|
645
|
+
constructor(options) {
|
|
646
|
+
super(Object.assign({}, defaultOptions, options));
|
|
934
647
|
}
|
|
935
|
-
|
|
936
|
-
return Document;
|
|
937
|
-
}(Document$1);
|
|
938
|
-
|
|
648
|
+
}
|
|
939
649
|
function parseAllDocuments(src, options) {
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
948
|
-
var cstDoc = _step.value;
|
|
949
|
-
var doc = new Document(options);
|
|
950
|
-
doc.parse(cstDoc, prev);
|
|
951
|
-
stream.push(doc);
|
|
952
|
-
prev = doc;
|
|
953
|
-
}
|
|
954
|
-
} catch (err) {
|
|
955
|
-
_iterator.e(err);
|
|
956
|
-
} finally {
|
|
957
|
-
_iterator.f();
|
|
650
|
+
const stream = [];
|
|
651
|
+
let prev;
|
|
652
|
+
for (const cstDoc of parse$1(src)) {
|
|
653
|
+
const doc = new Document(options);
|
|
654
|
+
doc.parse(cstDoc, prev);
|
|
655
|
+
stream.push(doc);
|
|
656
|
+
prev = doc;
|
|
958
657
|
}
|
|
959
|
-
|
|
960
658
|
return stream;
|
|
961
659
|
}
|
|
962
|
-
|
|
963
660
|
function parseDocument(src, options) {
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
661
|
+
const cst = parse$1(src);
|
|
662
|
+
const doc = new Document(options).parse(cst[0]);
|
|
967
663
|
if (cst.length > 1) {
|
|
968
|
-
|
|
664
|
+
const errMsg = 'Source contains multiple documents; please use YAML.parseAllDocuments()';
|
|
969
665
|
doc.errors.unshift(new YAMLSemanticError(cst[1], errMsg));
|
|
970
666
|
}
|
|
971
|
-
|
|
972
667
|
return doc;
|
|
973
668
|
}
|
|
974
|
-
|
|
975
669
|
function parse(src, options) {
|
|
976
|
-
|
|
977
|
-
doc.warnings.forEach(
|
|
978
|
-
return warn(warning);
|
|
979
|
-
});
|
|
670
|
+
const doc = parseDocument(src, options);
|
|
671
|
+
doc.warnings.forEach(warning => warn(warning));
|
|
980
672
|
if (doc.errors.length > 0) throw doc.errors[0];
|
|
981
673
|
return doc.toJSON();
|
|
982
674
|
}
|
|
983
|
-
|
|
984
675
|
function stringify(value, options) {
|
|
985
|
-
|
|
676
|
+
const doc = new Document(options);
|
|
986
677
|
doc.contents = value;
|
|
987
678
|
return String(doc);
|
|
988
679
|
}
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
parseAllDocuments: parseAllDocuments,
|
|
680
|
+
const YAML = {
|
|
681
|
+
createNode,
|
|
682
|
+
defaultOptions,
|
|
683
|
+
Document,
|
|
684
|
+
parse,
|
|
685
|
+
parseAllDocuments,
|
|
996
686
|
parseCST: parse$1,
|
|
997
|
-
parseDocument
|
|
998
|
-
scalarOptions
|
|
999
|
-
stringify
|
|
687
|
+
parseDocument,
|
|
688
|
+
scalarOptions,
|
|
689
|
+
stringify
|
|
1000
690
|
};
|
|
1001
691
|
|
|
1002
692
|
export { YAML };
|