cdk8s-operator 0.1.406 → 0.1.408
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 +3 -3
- package/lib/operator.js +1 -1
- 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 +2 -2
- 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
|
@@ -0,0 +1,467 @@
|
|
|
1
|
+
import { _ as _defineProperty, d as defaultTagPrefix, e as defaultTags } from './PlainValue-183afbad.js';
|
|
2
|
+
import { d as YAMLMap, g as resolveMap, Y as YAMLSeq, h as resolveSeq, j as resolveString, c as stringifyString, s as strOptions, S as Scalar, n as nullOptions, a as boolOptions, i as intOptions, k as stringifyNumber, N as Node, A as Alias, P as Pair } from './resolveSeq-67caf78a.js';
|
|
3
|
+
import { b as binary, o as omap, p as pairs, s as set, i as intTime, f as floatTime, t as timestamp, a as warnOptionDeprecation } from './warnings-5e4358fe.js';
|
|
4
|
+
|
|
5
|
+
function createMap(schema, obj, ctx) {
|
|
6
|
+
const map = new YAMLMap(schema);
|
|
7
|
+
if (obj instanceof Map) {
|
|
8
|
+
for (const [key, value] of obj) map.items.push(schema.createPair(key, value, ctx));
|
|
9
|
+
} else if (obj && typeof obj === 'object') {
|
|
10
|
+
for (const key of Object.keys(obj)) map.items.push(schema.createPair(key, obj[key], ctx));
|
|
11
|
+
}
|
|
12
|
+
if (typeof schema.sortMapEntries === 'function') {
|
|
13
|
+
map.items.sort(schema.sortMapEntries);
|
|
14
|
+
}
|
|
15
|
+
return map;
|
|
16
|
+
}
|
|
17
|
+
const map = {
|
|
18
|
+
createNode: createMap,
|
|
19
|
+
default: true,
|
|
20
|
+
nodeClass: YAMLMap,
|
|
21
|
+
tag: 'tag:yaml.org,2002:map',
|
|
22
|
+
resolve: resolveMap
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
function createSeq(schema, obj, ctx) {
|
|
26
|
+
const seq = new YAMLSeq(schema);
|
|
27
|
+
if (obj && obj[Symbol.iterator]) {
|
|
28
|
+
for (const it of obj) {
|
|
29
|
+
const v = schema.createNode(it, ctx.wrapScalars, null, ctx);
|
|
30
|
+
seq.items.push(v);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return seq;
|
|
34
|
+
}
|
|
35
|
+
const seq = {
|
|
36
|
+
createNode: createSeq,
|
|
37
|
+
default: true,
|
|
38
|
+
nodeClass: YAMLSeq,
|
|
39
|
+
tag: 'tag:yaml.org,2002:seq',
|
|
40
|
+
resolve: resolveSeq
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const string = {
|
|
44
|
+
identify: value => typeof value === 'string',
|
|
45
|
+
default: true,
|
|
46
|
+
tag: 'tag:yaml.org,2002:str',
|
|
47
|
+
resolve: resolveString,
|
|
48
|
+
stringify(item, ctx, onComment, onChompKeep) {
|
|
49
|
+
ctx = Object.assign({
|
|
50
|
+
actualString: true
|
|
51
|
+
}, ctx);
|
|
52
|
+
return stringifyString(item, ctx, onComment, onChompKeep);
|
|
53
|
+
},
|
|
54
|
+
options: strOptions
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const failsafe = [map, seq, string];
|
|
58
|
+
|
|
59
|
+
/* global BigInt */
|
|
60
|
+
const intIdentify$2 = value => typeof value === 'bigint' || Number.isInteger(value);
|
|
61
|
+
const intResolve$1 = (src, part, radix) => intOptions.asBigInt ? BigInt(src) : parseInt(part, radix);
|
|
62
|
+
function intStringify$1(node, radix, prefix) {
|
|
63
|
+
const {
|
|
64
|
+
value
|
|
65
|
+
} = node;
|
|
66
|
+
if (intIdentify$2(value) && value >= 0) return prefix + value.toString(radix);
|
|
67
|
+
return stringifyNumber(node);
|
|
68
|
+
}
|
|
69
|
+
const nullObj = {
|
|
70
|
+
identify: value => value == null,
|
|
71
|
+
createNode: (schema, value, ctx) => ctx.wrapScalars ? new Scalar(null) : null,
|
|
72
|
+
default: true,
|
|
73
|
+
tag: 'tag:yaml.org,2002:null',
|
|
74
|
+
test: /^(?:~|[Nn]ull|NULL)?$/,
|
|
75
|
+
resolve: () => null,
|
|
76
|
+
options: nullOptions,
|
|
77
|
+
stringify: () => nullOptions.nullStr
|
|
78
|
+
};
|
|
79
|
+
const boolObj = {
|
|
80
|
+
identify: value => typeof value === 'boolean',
|
|
81
|
+
default: true,
|
|
82
|
+
tag: 'tag:yaml.org,2002:bool',
|
|
83
|
+
test: /^(?:[Tt]rue|TRUE|[Ff]alse|FALSE)$/,
|
|
84
|
+
resolve: str => str[0] === 't' || str[0] === 'T',
|
|
85
|
+
options: boolOptions,
|
|
86
|
+
stringify: ({
|
|
87
|
+
value
|
|
88
|
+
}) => value ? boolOptions.trueStr : boolOptions.falseStr
|
|
89
|
+
};
|
|
90
|
+
const octObj = {
|
|
91
|
+
identify: value => intIdentify$2(value) && value >= 0,
|
|
92
|
+
default: true,
|
|
93
|
+
tag: 'tag:yaml.org,2002:int',
|
|
94
|
+
format: 'OCT',
|
|
95
|
+
test: /^0o([0-7]+)$/,
|
|
96
|
+
resolve: (str, oct) => intResolve$1(str, oct, 8),
|
|
97
|
+
options: intOptions,
|
|
98
|
+
stringify: node => intStringify$1(node, 8, '0o')
|
|
99
|
+
};
|
|
100
|
+
const intObj = {
|
|
101
|
+
identify: intIdentify$2,
|
|
102
|
+
default: true,
|
|
103
|
+
tag: 'tag:yaml.org,2002:int',
|
|
104
|
+
test: /^[-+]?[0-9]+$/,
|
|
105
|
+
resolve: str => intResolve$1(str, str, 10),
|
|
106
|
+
options: intOptions,
|
|
107
|
+
stringify: stringifyNumber
|
|
108
|
+
};
|
|
109
|
+
const hexObj = {
|
|
110
|
+
identify: value => intIdentify$2(value) && value >= 0,
|
|
111
|
+
default: true,
|
|
112
|
+
tag: 'tag:yaml.org,2002:int',
|
|
113
|
+
format: 'HEX',
|
|
114
|
+
test: /^0x([0-9a-fA-F]+)$/,
|
|
115
|
+
resolve: (str, hex) => intResolve$1(str, hex, 16),
|
|
116
|
+
options: intOptions,
|
|
117
|
+
stringify: node => intStringify$1(node, 16, '0x')
|
|
118
|
+
};
|
|
119
|
+
const nanObj = {
|
|
120
|
+
identify: value => typeof value === 'number',
|
|
121
|
+
default: true,
|
|
122
|
+
tag: 'tag:yaml.org,2002:float',
|
|
123
|
+
test: /^(?:[-+]?\.inf|(\.nan))$/i,
|
|
124
|
+
resolve: (str, nan) => nan ? NaN : str[0] === '-' ? Number.NEGATIVE_INFINITY : Number.POSITIVE_INFINITY,
|
|
125
|
+
stringify: stringifyNumber
|
|
126
|
+
};
|
|
127
|
+
const expObj = {
|
|
128
|
+
identify: value => typeof value === 'number',
|
|
129
|
+
default: true,
|
|
130
|
+
tag: 'tag:yaml.org,2002:float',
|
|
131
|
+
format: 'EXP',
|
|
132
|
+
test: /^[-+]?(?:\.[0-9]+|[0-9]+(?:\.[0-9]*)?)[eE][-+]?[0-9]+$/,
|
|
133
|
+
resolve: str => parseFloat(str),
|
|
134
|
+
stringify: ({
|
|
135
|
+
value
|
|
136
|
+
}) => Number(value).toExponential()
|
|
137
|
+
};
|
|
138
|
+
const floatObj = {
|
|
139
|
+
identify: value => typeof value === 'number',
|
|
140
|
+
default: true,
|
|
141
|
+
tag: 'tag:yaml.org,2002:float',
|
|
142
|
+
test: /^[-+]?(?:\.([0-9]+)|[0-9]+\.([0-9]*))$/,
|
|
143
|
+
resolve(str, frac1, frac2) {
|
|
144
|
+
const frac = frac1 || frac2;
|
|
145
|
+
const node = new Scalar(parseFloat(str));
|
|
146
|
+
if (frac && frac[frac.length - 1] === '0') node.minFractionDigits = frac.length;
|
|
147
|
+
return node;
|
|
148
|
+
},
|
|
149
|
+
stringify: stringifyNumber
|
|
150
|
+
};
|
|
151
|
+
const core = failsafe.concat([nullObj, boolObj, octObj, intObj, hexObj, nanObj, expObj, floatObj]);
|
|
152
|
+
|
|
153
|
+
/* global BigInt */
|
|
154
|
+
const intIdentify$1 = value => typeof value === 'bigint' || Number.isInteger(value);
|
|
155
|
+
const stringifyJSON = ({
|
|
156
|
+
value
|
|
157
|
+
}) => JSON.stringify(value);
|
|
158
|
+
const json = [map, seq, {
|
|
159
|
+
identify: value => typeof value === 'string',
|
|
160
|
+
default: true,
|
|
161
|
+
tag: 'tag:yaml.org,2002:str',
|
|
162
|
+
resolve: resolveString,
|
|
163
|
+
stringify: stringifyJSON
|
|
164
|
+
}, {
|
|
165
|
+
identify: value => value == null,
|
|
166
|
+
createNode: (schema, value, ctx) => ctx.wrapScalars ? new Scalar(null) : null,
|
|
167
|
+
default: true,
|
|
168
|
+
tag: 'tag:yaml.org,2002:null',
|
|
169
|
+
test: /^null$/,
|
|
170
|
+
resolve: () => null,
|
|
171
|
+
stringify: stringifyJSON
|
|
172
|
+
}, {
|
|
173
|
+
identify: value => typeof value === 'boolean',
|
|
174
|
+
default: true,
|
|
175
|
+
tag: 'tag:yaml.org,2002:bool',
|
|
176
|
+
test: /^true|false$/,
|
|
177
|
+
resolve: str => str === 'true',
|
|
178
|
+
stringify: stringifyJSON
|
|
179
|
+
}, {
|
|
180
|
+
identify: intIdentify$1,
|
|
181
|
+
default: true,
|
|
182
|
+
tag: 'tag:yaml.org,2002:int',
|
|
183
|
+
test: /^-?(?:0|[1-9][0-9]*)$/,
|
|
184
|
+
resolve: str => intOptions.asBigInt ? BigInt(str) : parseInt(str, 10),
|
|
185
|
+
stringify: ({
|
|
186
|
+
value
|
|
187
|
+
}) => intIdentify$1(value) ? value.toString() : JSON.stringify(value)
|
|
188
|
+
}, {
|
|
189
|
+
identify: value => typeof value === 'number',
|
|
190
|
+
default: true,
|
|
191
|
+
tag: 'tag:yaml.org,2002:float',
|
|
192
|
+
test: /^-?(?:0|[1-9][0-9]*)(?:\.[0-9]*)?(?:[eE][-+]?[0-9]+)?$/,
|
|
193
|
+
resolve: str => parseFloat(str),
|
|
194
|
+
stringify: stringifyJSON
|
|
195
|
+
}];
|
|
196
|
+
json.scalarFallback = str => {
|
|
197
|
+
throw new SyntaxError(`Unresolved plain scalar ${JSON.stringify(str)}`);
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
/* global BigInt */
|
|
201
|
+
const boolStringify = ({
|
|
202
|
+
value
|
|
203
|
+
}) => value ? boolOptions.trueStr : boolOptions.falseStr;
|
|
204
|
+
const intIdentify = value => typeof value === 'bigint' || Number.isInteger(value);
|
|
205
|
+
function intResolve(sign, src, radix) {
|
|
206
|
+
let str = src.replace(/_/g, '');
|
|
207
|
+
if (intOptions.asBigInt) {
|
|
208
|
+
switch (radix) {
|
|
209
|
+
case 2:
|
|
210
|
+
str = `0b${str}`;
|
|
211
|
+
break;
|
|
212
|
+
case 8:
|
|
213
|
+
str = `0o${str}`;
|
|
214
|
+
break;
|
|
215
|
+
case 16:
|
|
216
|
+
str = `0x${str}`;
|
|
217
|
+
break;
|
|
218
|
+
}
|
|
219
|
+
const n = BigInt(str);
|
|
220
|
+
return sign === '-' ? BigInt(-1) * n : n;
|
|
221
|
+
}
|
|
222
|
+
const n = parseInt(str, radix);
|
|
223
|
+
return sign === '-' ? -1 * n : n;
|
|
224
|
+
}
|
|
225
|
+
function intStringify(node, radix, prefix) {
|
|
226
|
+
const {
|
|
227
|
+
value
|
|
228
|
+
} = node;
|
|
229
|
+
if (intIdentify(value)) {
|
|
230
|
+
const str = value.toString(radix);
|
|
231
|
+
return value < 0 ? '-' + prefix + str.substr(1) : prefix + str;
|
|
232
|
+
}
|
|
233
|
+
return stringifyNumber(node);
|
|
234
|
+
}
|
|
235
|
+
const yaml11 = failsafe.concat([{
|
|
236
|
+
identify: value => value == null,
|
|
237
|
+
createNode: (schema, value, ctx) => ctx.wrapScalars ? new Scalar(null) : null,
|
|
238
|
+
default: true,
|
|
239
|
+
tag: 'tag:yaml.org,2002:null',
|
|
240
|
+
test: /^(?:~|[Nn]ull|NULL)?$/,
|
|
241
|
+
resolve: () => null,
|
|
242
|
+
options: nullOptions,
|
|
243
|
+
stringify: () => nullOptions.nullStr
|
|
244
|
+
}, {
|
|
245
|
+
identify: value => typeof value === 'boolean',
|
|
246
|
+
default: true,
|
|
247
|
+
tag: 'tag:yaml.org,2002:bool',
|
|
248
|
+
test: /^(?:Y|y|[Yy]es|YES|[Tt]rue|TRUE|[Oo]n|ON)$/,
|
|
249
|
+
resolve: () => true,
|
|
250
|
+
options: boolOptions,
|
|
251
|
+
stringify: boolStringify
|
|
252
|
+
}, {
|
|
253
|
+
identify: value => typeof value === 'boolean',
|
|
254
|
+
default: true,
|
|
255
|
+
tag: 'tag:yaml.org,2002:bool',
|
|
256
|
+
test: /^(?:N|n|[Nn]o|NO|[Ff]alse|FALSE|[Oo]ff|OFF)$/i,
|
|
257
|
+
resolve: () => false,
|
|
258
|
+
options: boolOptions,
|
|
259
|
+
stringify: boolStringify
|
|
260
|
+
}, {
|
|
261
|
+
identify: intIdentify,
|
|
262
|
+
default: true,
|
|
263
|
+
tag: 'tag:yaml.org,2002:int',
|
|
264
|
+
format: 'BIN',
|
|
265
|
+
test: /^([-+]?)0b([0-1_]+)$/,
|
|
266
|
+
resolve: (str, sign, bin) => intResolve(sign, bin, 2),
|
|
267
|
+
stringify: node => intStringify(node, 2, '0b')
|
|
268
|
+
}, {
|
|
269
|
+
identify: intIdentify,
|
|
270
|
+
default: true,
|
|
271
|
+
tag: 'tag:yaml.org,2002:int',
|
|
272
|
+
format: 'OCT',
|
|
273
|
+
test: /^([-+]?)0([0-7_]+)$/,
|
|
274
|
+
resolve: (str, sign, oct) => intResolve(sign, oct, 8),
|
|
275
|
+
stringify: node => intStringify(node, 8, '0')
|
|
276
|
+
}, {
|
|
277
|
+
identify: intIdentify,
|
|
278
|
+
default: true,
|
|
279
|
+
tag: 'tag:yaml.org,2002:int',
|
|
280
|
+
test: /^([-+]?)([0-9][0-9_]*)$/,
|
|
281
|
+
resolve: (str, sign, abs) => intResolve(sign, abs, 10),
|
|
282
|
+
stringify: stringifyNumber
|
|
283
|
+
}, {
|
|
284
|
+
identify: intIdentify,
|
|
285
|
+
default: true,
|
|
286
|
+
tag: 'tag:yaml.org,2002:int',
|
|
287
|
+
format: 'HEX',
|
|
288
|
+
test: /^([-+]?)0x([0-9a-fA-F_]+)$/,
|
|
289
|
+
resolve: (str, sign, hex) => intResolve(sign, hex, 16),
|
|
290
|
+
stringify: node => intStringify(node, 16, '0x')
|
|
291
|
+
}, {
|
|
292
|
+
identify: value => typeof value === 'number',
|
|
293
|
+
default: true,
|
|
294
|
+
tag: 'tag:yaml.org,2002:float',
|
|
295
|
+
test: /^(?:[-+]?\.inf|(\.nan))$/i,
|
|
296
|
+
resolve: (str, nan) => nan ? NaN : str[0] === '-' ? Number.NEGATIVE_INFINITY : Number.POSITIVE_INFINITY,
|
|
297
|
+
stringify: stringifyNumber
|
|
298
|
+
}, {
|
|
299
|
+
identify: value => typeof value === 'number',
|
|
300
|
+
default: true,
|
|
301
|
+
tag: 'tag:yaml.org,2002:float',
|
|
302
|
+
format: 'EXP',
|
|
303
|
+
test: /^[-+]?([0-9][0-9_]*)?(\.[0-9_]*)?[eE][-+]?[0-9]+$/,
|
|
304
|
+
resolve: str => parseFloat(str.replace(/_/g, '')),
|
|
305
|
+
stringify: ({
|
|
306
|
+
value
|
|
307
|
+
}) => Number(value).toExponential()
|
|
308
|
+
}, {
|
|
309
|
+
identify: value => typeof value === 'number',
|
|
310
|
+
default: true,
|
|
311
|
+
tag: 'tag:yaml.org,2002:float',
|
|
312
|
+
test: /^[-+]?(?:[0-9][0-9_]*)?\.([0-9_]*)$/,
|
|
313
|
+
resolve(str, frac) {
|
|
314
|
+
const node = new Scalar(parseFloat(str.replace(/_/g, '')));
|
|
315
|
+
if (frac) {
|
|
316
|
+
const f = frac.replace(/_/g, '');
|
|
317
|
+
if (f[f.length - 1] === '0') node.minFractionDigits = f.length;
|
|
318
|
+
}
|
|
319
|
+
return node;
|
|
320
|
+
},
|
|
321
|
+
stringify: stringifyNumber
|
|
322
|
+
}], binary, omap, pairs, set, intTime, floatTime, timestamp);
|
|
323
|
+
|
|
324
|
+
const schemas = {
|
|
325
|
+
core,
|
|
326
|
+
failsafe,
|
|
327
|
+
json,
|
|
328
|
+
yaml11
|
|
329
|
+
};
|
|
330
|
+
const tags = {
|
|
331
|
+
binary,
|
|
332
|
+
bool: boolObj,
|
|
333
|
+
float: floatObj,
|
|
334
|
+
floatExp: expObj,
|
|
335
|
+
floatNaN: nanObj,
|
|
336
|
+
floatTime,
|
|
337
|
+
int: intObj,
|
|
338
|
+
intHex: hexObj,
|
|
339
|
+
intOct: octObj,
|
|
340
|
+
intTime,
|
|
341
|
+
map,
|
|
342
|
+
null: nullObj,
|
|
343
|
+
omap,
|
|
344
|
+
pairs,
|
|
345
|
+
seq,
|
|
346
|
+
set,
|
|
347
|
+
timestamp
|
|
348
|
+
};
|
|
349
|
+
|
|
350
|
+
function findTagObject(value, tagName, tags) {
|
|
351
|
+
if (tagName) {
|
|
352
|
+
const match = tags.filter(t => t.tag === tagName);
|
|
353
|
+
const tagObj = match.find(t => !t.format) || match[0];
|
|
354
|
+
if (!tagObj) throw new Error(`Tag ${tagName} not found`);
|
|
355
|
+
return tagObj;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
// TODO: deprecate/remove class check
|
|
359
|
+
return tags.find(t => (t.identify && t.identify(value) || t.class && value instanceof t.class) && !t.format);
|
|
360
|
+
}
|
|
361
|
+
function createNode(value, tagName, ctx) {
|
|
362
|
+
if (value instanceof Node) return value;
|
|
363
|
+
const {
|
|
364
|
+
defaultPrefix,
|
|
365
|
+
onTagObj,
|
|
366
|
+
prevObjects,
|
|
367
|
+
schema,
|
|
368
|
+
wrapScalars
|
|
369
|
+
} = ctx;
|
|
370
|
+
if (tagName && tagName.startsWith('!!')) tagName = defaultPrefix + tagName.slice(2);
|
|
371
|
+
let tagObj = findTagObject(value, tagName, schema.tags);
|
|
372
|
+
if (!tagObj) {
|
|
373
|
+
if (typeof value.toJSON === 'function') value = value.toJSON();
|
|
374
|
+
if (!value || typeof value !== 'object') return wrapScalars ? new Scalar(value) : value;
|
|
375
|
+
tagObj = value instanceof Map ? map : value[Symbol.iterator] ? seq : map;
|
|
376
|
+
}
|
|
377
|
+
if (onTagObj) {
|
|
378
|
+
onTagObj(tagObj);
|
|
379
|
+
delete ctx.onTagObj;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
// Detect duplicate references to the same object & use Alias nodes for all
|
|
383
|
+
// after first. The `obj` wrapper allows for circular references to resolve.
|
|
384
|
+
const obj = {
|
|
385
|
+
value: undefined,
|
|
386
|
+
node: undefined
|
|
387
|
+
};
|
|
388
|
+
if (value && typeof value === 'object' && prevObjects) {
|
|
389
|
+
const prev = prevObjects.get(value);
|
|
390
|
+
if (prev) {
|
|
391
|
+
const alias = new Alias(prev); // leaves source dirty; must be cleaned by caller
|
|
392
|
+
ctx.aliasNodes.push(alias); // defined along with prevObjects
|
|
393
|
+
return alias;
|
|
394
|
+
}
|
|
395
|
+
obj.value = value;
|
|
396
|
+
prevObjects.set(value, obj);
|
|
397
|
+
}
|
|
398
|
+
obj.node = tagObj.createNode ? tagObj.createNode(ctx.schema, value, ctx) : wrapScalars ? new Scalar(value) : value;
|
|
399
|
+
if (tagName && obj.node instanceof Node) obj.node.tag = tagName;
|
|
400
|
+
return obj.node;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
function getSchemaTags(schemas, knownTags, customTags, schemaId) {
|
|
404
|
+
let tags = schemas[schemaId.replace(/\W/g, '')]; // 'yaml-1.1' -> 'yaml11'
|
|
405
|
+
if (!tags) {
|
|
406
|
+
const keys = Object.keys(schemas).map(key => JSON.stringify(key)).join(', ');
|
|
407
|
+
throw new Error(`Unknown schema "${schemaId}"; use one of ${keys}`);
|
|
408
|
+
}
|
|
409
|
+
if (Array.isArray(customTags)) {
|
|
410
|
+
for (const tag of customTags) tags = tags.concat(tag);
|
|
411
|
+
} else if (typeof customTags === 'function') {
|
|
412
|
+
tags = customTags(tags.slice());
|
|
413
|
+
}
|
|
414
|
+
for (let i = 0; i < tags.length; ++i) {
|
|
415
|
+
const tag = tags[i];
|
|
416
|
+
if (typeof tag === 'string') {
|
|
417
|
+
const tagObj = knownTags[tag];
|
|
418
|
+
if (!tagObj) {
|
|
419
|
+
const keys = Object.keys(knownTags).map(key => JSON.stringify(key)).join(', ');
|
|
420
|
+
throw new Error(`Unknown custom tag "${tag}"; use one of ${keys}`);
|
|
421
|
+
}
|
|
422
|
+
tags[i] = tagObj;
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
return tags;
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
const sortMapEntriesByKey = (a, b) => a.key < b.key ? -1 : a.key > b.key ? 1 : 0;
|
|
429
|
+
class Schema {
|
|
430
|
+
// TODO: remove in v2
|
|
431
|
+
|
|
432
|
+
constructor({
|
|
433
|
+
customTags,
|
|
434
|
+
merge,
|
|
435
|
+
schema,
|
|
436
|
+
sortMapEntries,
|
|
437
|
+
tags: deprecatedCustomTags
|
|
438
|
+
}) {
|
|
439
|
+
this.merge = !!merge;
|
|
440
|
+
this.name = schema;
|
|
441
|
+
this.sortMapEntries = sortMapEntries === true ? sortMapEntriesByKey : sortMapEntries || null;
|
|
442
|
+
if (!customTags && deprecatedCustomTags) warnOptionDeprecation('tags', 'customTags');
|
|
443
|
+
this.tags = getSchemaTags(schemas, tags, customTags || deprecatedCustomTags, schema);
|
|
444
|
+
}
|
|
445
|
+
createNode(value, wrapScalars, tagName, ctx) {
|
|
446
|
+
const baseCtx = {
|
|
447
|
+
defaultPrefix: Schema.defaultPrefix,
|
|
448
|
+
schema: this,
|
|
449
|
+
wrapScalars
|
|
450
|
+
};
|
|
451
|
+
const createCtx = ctx ? Object.assign(ctx, baseCtx) : baseCtx;
|
|
452
|
+
return createNode(value, tagName, createCtx);
|
|
453
|
+
}
|
|
454
|
+
createPair(key, value, ctx) {
|
|
455
|
+
if (!ctx) ctx = {
|
|
456
|
+
wrapScalars: true
|
|
457
|
+
};
|
|
458
|
+
const k = this.createNode(key, ctx.wrapScalars, null, ctx);
|
|
459
|
+
const v = this.createNode(value, ctx.wrapScalars, null, ctx);
|
|
460
|
+
return new Pair(k, v);
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
_defineProperty(Schema, "defaultPrefix", defaultTagPrefix);
|
|
464
|
+
// TODO: remove in v2
|
|
465
|
+
_defineProperty(Schema, "defaultTags", defaultTags);
|
|
466
|
+
|
|
467
|
+
export { Schema as S };
|