@digi4care/omo-slim-decision-layer 0.0.0-stage → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +96 -2
- package/dist/config.d.ts +6 -0
- package/dist/hooks/interview-inject.d.ts +2 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +4324 -0
- package/dist/model/record.d.ts +320 -0
- package/dist/prompts/decision-discipline.d.ts +1 -0
- package/dist/register/register.d.ts +144 -0
- package/dist/schema/generate.d.ts +1 -0
- package/dist/src/config.d.ts +6 -0
- package/dist/src/hooks/interview-inject.d.ts +2 -0
- package/dist/src/index.d.ts +6 -0
- package/dist/src/model/record.d.ts +320 -0
- package/dist/src/prompts/decision-discipline.d.ts +1 -0
- package/dist/src/register/register.d.ts +144 -0
- package/dist/src/schema/generate.d.ts +1 -0
- package/dist/src/tools/index.d.ts +4 -0
- package/dist/src/tools/paths.d.ts +16 -0
- package/dist/tools/index.d.ts +4 -0
- package/dist/tools/paths.d.ts +16 -0
- package/package.json +72 -4
- package/schema/register.schema.json +381 -0
- package/skills/decision-layer/SKILL.md +37 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,4324 @@
|
|
|
1
|
+
// src/prompts/decision-discipline.ts
|
|
2
|
+
var DECISION_DISCIPLINE_PROMPT = `At the end of this interview, the outcome is not yet a decision. Record it in the decision register.
|
|
3
|
+
|
|
4
|
+
Record in \`.decisions/register.yaml\` (following \`schema/register.schema.json\`):
|
|
5
|
+
- the problem as a requirement record;
|
|
6
|
+
- what is fixed and non-negotiable as a constraint record;
|
|
7
|
+
- every assumption you could not verify as an assumption record, with \`needed_to_close\`;
|
|
8
|
+
- the decision itself as a decision record, with rejected alternatives and consequences.
|
|
9
|
+
|
|
10
|
+
\`.decisions/register.yaml\` is the single source of truth. You call \`decision-add\` yourself to add records; do not write a second set of files next to the register. Always run \`decision-validate\` after writing. Only ratify (\`decision-ratify\`) when the user explicitly asks you to.`;
|
|
11
|
+
|
|
12
|
+
// src/hooks/interview-inject.ts
|
|
13
|
+
var SENTINEL = "<!-- decision-layer:inject v1 -->";
|
|
14
|
+
function isTextPart(part) {
|
|
15
|
+
return part.type === "text";
|
|
16
|
+
}
|
|
17
|
+
function createInterviewInjectHook() {
|
|
18
|
+
return async (input, output) => {
|
|
19
|
+
try {
|
|
20
|
+
if (input.command !== "interview") {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
const parts = output.parts;
|
|
24
|
+
if (!Array.isArray(parts)) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
const alreadyInjected = parts.some((part) => isTextPart(part) && part.text.includes(SENTINEL));
|
|
28
|
+
if (alreadyInjected) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
const injected = {
|
|
32
|
+
id: `decision-layer-inject-${input.sessionID}`,
|
|
33
|
+
sessionID: input.sessionID,
|
|
34
|
+
messageID: "",
|
|
35
|
+
type: "text",
|
|
36
|
+
text: `${SENTINEL}
|
|
37
|
+
${DECISION_DISCIPLINE_PROMPT}`,
|
|
38
|
+
synthetic: true
|
|
39
|
+
};
|
|
40
|
+
parts.push(injected);
|
|
41
|
+
} catch (error) {
|
|
42
|
+
console.warn("[decision-layer] interview inject failed:", error);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// src/tools/index.ts
|
|
48
|
+
import fs4 from "node:fs";
|
|
49
|
+
import path4 from "node:path";
|
|
50
|
+
|
|
51
|
+
// node_modules/js-yaml/dist/js-yaml.mjs
|
|
52
|
+
/*! js-yaml 5.4.3 https://github.com/nodeca/js-yaml @license MIT */
|
|
53
|
+
var NOT_RESOLVED = Symbol("NOT_RESOLVED");
|
|
54
|
+
function defineScalarTag(tagName, options) {
|
|
55
|
+
return {
|
|
56
|
+
tagName,
|
|
57
|
+
nodeKind: "scalar",
|
|
58
|
+
implicit: options.implicit ?? false,
|
|
59
|
+
matchByTagPrefix: options.matchByTagPrefix ?? false,
|
|
60
|
+
implicitFirstChars: options.implicitFirstChars ?? null,
|
|
61
|
+
resolve: options.resolve,
|
|
62
|
+
identify: options.identify,
|
|
63
|
+
represent: options.represent ?? ((data) => String(data)),
|
|
64
|
+
representTagName: options.representTagName ?? (() => tagName)
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
function defineSequenceTag(tagName, options) {
|
|
68
|
+
const carrierIsResult = options.finalize === undefined;
|
|
69
|
+
return {
|
|
70
|
+
tagName,
|
|
71
|
+
nodeKind: "sequence",
|
|
72
|
+
implicit: false,
|
|
73
|
+
matchByTagPrefix: options.matchByTagPrefix ?? false,
|
|
74
|
+
create: options.create,
|
|
75
|
+
addItem: options.addItem,
|
|
76
|
+
finalize: options.finalize ?? ((carrier) => carrier),
|
|
77
|
+
carrierIsResult,
|
|
78
|
+
identify: options.identify,
|
|
79
|
+
represent: options.represent ?? ((data) => data),
|
|
80
|
+
representTagName: options.representTagName ?? (() => tagName)
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
function defineMappingTag(tagName, options) {
|
|
84
|
+
const carrierIsResult = options.finalize === undefined;
|
|
85
|
+
return {
|
|
86
|
+
tagName,
|
|
87
|
+
nodeKind: "mapping",
|
|
88
|
+
implicit: false,
|
|
89
|
+
matchByTagPrefix: options.matchByTagPrefix ?? false,
|
|
90
|
+
create: options.create,
|
|
91
|
+
addPair: options.addPair,
|
|
92
|
+
has: options.has,
|
|
93
|
+
keys: options.keys,
|
|
94
|
+
get: options.get,
|
|
95
|
+
finalize: options.finalize ?? ((carrier) => carrier),
|
|
96
|
+
carrierIsResult,
|
|
97
|
+
identify: options.identify,
|
|
98
|
+
represent: options.represent ?? ((data) => data),
|
|
99
|
+
representTagName: options.representTagName ?? (() => tagName)
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
var strTag = defineScalarTag("tag:yaml.org,2002:str", {
|
|
103
|
+
resolve: (source) => source,
|
|
104
|
+
identify: (data) => typeof data === "string"
|
|
105
|
+
});
|
|
106
|
+
var NULL_VALUES$1 = [
|
|
107
|
+
"",
|
|
108
|
+
"~",
|
|
109
|
+
"null",
|
|
110
|
+
"Null",
|
|
111
|
+
"NULL"
|
|
112
|
+
];
|
|
113
|
+
var nullCoreTag = defineScalarTag("tag:yaml.org,2002:null", {
|
|
114
|
+
implicit: true,
|
|
115
|
+
implicitFirstChars: [
|
|
116
|
+
"",
|
|
117
|
+
"~",
|
|
118
|
+
"n",
|
|
119
|
+
"N"
|
|
120
|
+
],
|
|
121
|
+
resolve: (source) => {
|
|
122
|
+
if (NULL_VALUES$1.indexOf(source) !== -1)
|
|
123
|
+
return null;
|
|
124
|
+
return NOT_RESOLVED;
|
|
125
|
+
},
|
|
126
|
+
identify: (object) => object === null,
|
|
127
|
+
represent: () => "null"
|
|
128
|
+
});
|
|
129
|
+
var nullJsonTag = defineScalarTag("tag:yaml.org,2002:null", {
|
|
130
|
+
implicit: true,
|
|
131
|
+
implicitFirstChars: ["n"],
|
|
132
|
+
resolve: (source, isExplicit) => {
|
|
133
|
+
if (source === "null" || isExplicit && source === "")
|
|
134
|
+
return null;
|
|
135
|
+
return NOT_RESOLVED;
|
|
136
|
+
},
|
|
137
|
+
identify: (object) => object === null,
|
|
138
|
+
represent: () => "null"
|
|
139
|
+
});
|
|
140
|
+
var NULL_VALUES = [
|
|
141
|
+
"",
|
|
142
|
+
"~",
|
|
143
|
+
"null",
|
|
144
|
+
"Null",
|
|
145
|
+
"NULL"
|
|
146
|
+
];
|
|
147
|
+
var nullYaml11Tag = defineScalarTag("tag:yaml.org,2002:null", {
|
|
148
|
+
implicit: true,
|
|
149
|
+
implicitFirstChars: [
|
|
150
|
+
"",
|
|
151
|
+
"~",
|
|
152
|
+
"n",
|
|
153
|
+
"N"
|
|
154
|
+
],
|
|
155
|
+
resolve: (source) => {
|
|
156
|
+
if (NULL_VALUES.indexOf(source) !== -1)
|
|
157
|
+
return null;
|
|
158
|
+
return NOT_RESOLVED;
|
|
159
|
+
},
|
|
160
|
+
identify: (object) => object === null,
|
|
161
|
+
represent: () => "null"
|
|
162
|
+
});
|
|
163
|
+
var TRUE_VALUES$2 = [
|
|
164
|
+
"true",
|
|
165
|
+
"True",
|
|
166
|
+
"TRUE"
|
|
167
|
+
];
|
|
168
|
+
var FALSE_VALUES$2 = [
|
|
169
|
+
"false",
|
|
170
|
+
"False",
|
|
171
|
+
"FALSE"
|
|
172
|
+
];
|
|
173
|
+
var boolCoreTag = defineScalarTag("tag:yaml.org,2002:bool", {
|
|
174
|
+
implicit: true,
|
|
175
|
+
implicitFirstChars: [
|
|
176
|
+
"t",
|
|
177
|
+
"T",
|
|
178
|
+
"f",
|
|
179
|
+
"F"
|
|
180
|
+
],
|
|
181
|
+
resolve: (source) => {
|
|
182
|
+
if (TRUE_VALUES$2.indexOf(source) !== -1)
|
|
183
|
+
return true;
|
|
184
|
+
if (FALSE_VALUES$2.indexOf(source) !== -1)
|
|
185
|
+
return false;
|
|
186
|
+
return NOT_RESOLVED;
|
|
187
|
+
},
|
|
188
|
+
identify: (object) => Object.prototype.toString.call(object) === "[object Boolean]",
|
|
189
|
+
represent: (object) => object ? "true" : "false"
|
|
190
|
+
});
|
|
191
|
+
var TRUE_VALUES$1 = ["true"];
|
|
192
|
+
var FALSE_VALUES$1 = ["false"];
|
|
193
|
+
var boolJsonTag = defineScalarTag("tag:yaml.org,2002:bool", {
|
|
194
|
+
implicit: true,
|
|
195
|
+
implicitFirstChars: ["t", "f"],
|
|
196
|
+
resolve: (source) => {
|
|
197
|
+
if (TRUE_VALUES$1.indexOf(source) !== -1)
|
|
198
|
+
return true;
|
|
199
|
+
if (FALSE_VALUES$1.indexOf(source) !== -1)
|
|
200
|
+
return false;
|
|
201
|
+
return NOT_RESOLVED;
|
|
202
|
+
},
|
|
203
|
+
identify: (object) => Object.prototype.toString.call(object) === "[object Boolean]",
|
|
204
|
+
represent: (object) => object ? "true" : "false"
|
|
205
|
+
});
|
|
206
|
+
var TRUE_VALUES = [
|
|
207
|
+
"true",
|
|
208
|
+
"True",
|
|
209
|
+
"TRUE",
|
|
210
|
+
"y",
|
|
211
|
+
"Y",
|
|
212
|
+
"yes",
|
|
213
|
+
"Yes",
|
|
214
|
+
"YES",
|
|
215
|
+
"on",
|
|
216
|
+
"On",
|
|
217
|
+
"ON"
|
|
218
|
+
];
|
|
219
|
+
var FALSE_VALUES = [
|
|
220
|
+
"false",
|
|
221
|
+
"False",
|
|
222
|
+
"FALSE",
|
|
223
|
+
"n",
|
|
224
|
+
"N",
|
|
225
|
+
"no",
|
|
226
|
+
"No",
|
|
227
|
+
"NO",
|
|
228
|
+
"off",
|
|
229
|
+
"Off",
|
|
230
|
+
"OFF"
|
|
231
|
+
];
|
|
232
|
+
var boolYaml11Tag = defineScalarTag("tag:yaml.org,2002:bool", {
|
|
233
|
+
implicit: true,
|
|
234
|
+
implicitFirstChars: [
|
|
235
|
+
"y",
|
|
236
|
+
"Y",
|
|
237
|
+
"n",
|
|
238
|
+
"N",
|
|
239
|
+
"t",
|
|
240
|
+
"T",
|
|
241
|
+
"f",
|
|
242
|
+
"F",
|
|
243
|
+
"o",
|
|
244
|
+
"O"
|
|
245
|
+
],
|
|
246
|
+
resolve: (source) => {
|
|
247
|
+
if (TRUE_VALUES.indexOf(source) !== -1)
|
|
248
|
+
return true;
|
|
249
|
+
if (FALSE_VALUES.indexOf(source) !== -1)
|
|
250
|
+
return false;
|
|
251
|
+
return NOT_RESOLVED;
|
|
252
|
+
},
|
|
253
|
+
identify: (object) => Object.prototype.toString.call(object) === "[object Boolean]",
|
|
254
|
+
represent: (object) => object ? "true" : "false"
|
|
255
|
+
});
|
|
256
|
+
var YAML_INTEGER_IMPLICIT_PATTERN$1 = /* @__PURE__ */ new RegExp("^(?:0o[0-7]+|0x[0-9a-fA-F]+|[-+]?[0-9]+)$");
|
|
257
|
+
var YAML_INTEGER_EXPLICIT_PATTERN$1 = /* @__PURE__ */ new RegExp("^(?:[-+]?0b[0-1]+|[-+]?0o[0-7]+|[-+]?0x[0-9a-fA-F]+|[-+]?[0-9]+)$");
|
|
258
|
+
function parseYamlInteger$2(source) {
|
|
259
|
+
let value = source;
|
|
260
|
+
let sign = 1;
|
|
261
|
+
if (value[0] === "-" || value[0] === "+") {
|
|
262
|
+
if (value[0] === "-")
|
|
263
|
+
sign = -1;
|
|
264
|
+
value = value.slice(1);
|
|
265
|
+
}
|
|
266
|
+
if (value.startsWith("0b"))
|
|
267
|
+
return sign * parseInt(value.slice(2), 2);
|
|
268
|
+
if (value.startsWith("0o"))
|
|
269
|
+
return sign * parseInt(value.slice(2), 8);
|
|
270
|
+
if (value.startsWith("0x"))
|
|
271
|
+
return sign * parseInt(value.slice(2), 16);
|
|
272
|
+
return sign * parseInt(value, 10);
|
|
273
|
+
}
|
|
274
|
+
function resolveYamlInteger$2(source, isExplicit) {
|
|
275
|
+
if (isExplicit) {
|
|
276
|
+
if (!YAML_INTEGER_EXPLICIT_PATTERN$1.test(source))
|
|
277
|
+
return NOT_RESOLVED;
|
|
278
|
+
} else if (!YAML_INTEGER_IMPLICIT_PATTERN$1.test(source))
|
|
279
|
+
return NOT_RESOLVED;
|
|
280
|
+
const result = parseYamlInteger$2(source);
|
|
281
|
+
return Number.isFinite(result) ? result : NOT_RESOLVED;
|
|
282
|
+
}
|
|
283
|
+
var intCoreTag = defineScalarTag("tag:yaml.org,2002:int", {
|
|
284
|
+
implicit: true,
|
|
285
|
+
implicitFirstChars: [
|
|
286
|
+
"-",
|
|
287
|
+
"+",
|
|
288
|
+
..."0123456789"
|
|
289
|
+
],
|
|
290
|
+
resolve: resolveYamlInteger$2,
|
|
291
|
+
identify: (object) => Number.isInteger(object) && !Object.is(object, -0) && object.toString(10).indexOf("e") < 0,
|
|
292
|
+
represent: (object) => object.toString(10)
|
|
293
|
+
});
|
|
294
|
+
var YAML_INTEGER_IMPLICIT_PATTERN = /* @__PURE__ */ new RegExp("^-?(?:0|[1-9][0-9]*)$");
|
|
295
|
+
var YAML_INTEGER_EXPLICIT_PATTERN = /* @__PURE__ */ new RegExp("^(?:[-+]?0b[0-1]+|[-+]?0o[0-7]+|[-+]?0x[0-9a-fA-F]+|[-+]?[0-9]+)$");
|
|
296
|
+
function parseYamlInteger$1(source) {
|
|
297
|
+
let value = source;
|
|
298
|
+
let sign = 1;
|
|
299
|
+
if (value[0] === "-" || value[0] === "+") {
|
|
300
|
+
if (value[0] === "-")
|
|
301
|
+
sign = -1;
|
|
302
|
+
value = value.slice(1);
|
|
303
|
+
}
|
|
304
|
+
if (value.startsWith("0b"))
|
|
305
|
+
return sign * parseInt(value.slice(2), 2);
|
|
306
|
+
if (value.startsWith("0o"))
|
|
307
|
+
return sign * parseInt(value.slice(2), 8);
|
|
308
|
+
if (value.startsWith("0x"))
|
|
309
|
+
return sign * parseInt(value.slice(2), 16);
|
|
310
|
+
return sign * parseInt(value, 10);
|
|
311
|
+
}
|
|
312
|
+
function resolveYamlInteger$1(source, isExplicit) {
|
|
313
|
+
if (isExplicit) {
|
|
314
|
+
if (!YAML_INTEGER_EXPLICIT_PATTERN.test(source))
|
|
315
|
+
return NOT_RESOLVED;
|
|
316
|
+
} else if (!YAML_INTEGER_IMPLICIT_PATTERN.test(source))
|
|
317
|
+
return NOT_RESOLVED;
|
|
318
|
+
const result = parseYamlInteger$1(source);
|
|
319
|
+
return Number.isFinite(result) ? result : NOT_RESOLVED;
|
|
320
|
+
}
|
|
321
|
+
var intJsonTag = defineScalarTag("tag:yaml.org,2002:int", {
|
|
322
|
+
implicit: true,
|
|
323
|
+
implicitFirstChars: ["-", ..."0123456789"],
|
|
324
|
+
resolve: resolveYamlInteger$1,
|
|
325
|
+
identify: (object) => Number.isInteger(object) && !Object.is(object, -0) && object.toString(10).indexOf("e") < 0,
|
|
326
|
+
represent: (object) => object.toString(10)
|
|
327
|
+
});
|
|
328
|
+
var YAML_INTEGER_PATTERN = /* @__PURE__ */ new RegExp("^(?:[-+]?0b[0-1_]+|[-+]?0[0-7_]+|[-+]?0x[0-9a-fA-F_]+|[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+|[-+]?(?:0|[1-9][0-9_]*))$");
|
|
329
|
+
function parseYamlInteger(source) {
|
|
330
|
+
let value = source.replace(/_/g, "");
|
|
331
|
+
let sign = 1;
|
|
332
|
+
if (value[0] === "-" || value[0] === "+") {
|
|
333
|
+
if (value[0] === "-")
|
|
334
|
+
sign = -1;
|
|
335
|
+
value = value.slice(1);
|
|
336
|
+
}
|
|
337
|
+
if (value.startsWith("0b"))
|
|
338
|
+
return sign * parseInt(value.slice(2), 2);
|
|
339
|
+
if (value.startsWith("0x"))
|
|
340
|
+
return sign * parseInt(value.slice(2), 16);
|
|
341
|
+
if (value.includes(":")) {
|
|
342
|
+
let result = 0;
|
|
343
|
+
for (const part of value.split(":"))
|
|
344
|
+
result = result * 60 + Number(part);
|
|
345
|
+
return sign * result;
|
|
346
|
+
}
|
|
347
|
+
if (value !== "0" && value[0] === "0")
|
|
348
|
+
return sign * parseInt(value, 8);
|
|
349
|
+
return sign * parseInt(value, 10);
|
|
350
|
+
}
|
|
351
|
+
function resolveYamlInteger(source) {
|
|
352
|
+
if (!YAML_INTEGER_PATTERN.test(source))
|
|
353
|
+
return NOT_RESOLVED;
|
|
354
|
+
const result = parseYamlInteger(source);
|
|
355
|
+
return Number.isFinite(result) ? result : NOT_RESOLVED;
|
|
356
|
+
}
|
|
357
|
+
var intYaml11Tag = defineScalarTag("tag:yaml.org,2002:int", {
|
|
358
|
+
implicit: true,
|
|
359
|
+
implicitFirstChars: [
|
|
360
|
+
"-",
|
|
361
|
+
"+",
|
|
362
|
+
..."0123456789"
|
|
363
|
+
],
|
|
364
|
+
resolve: resolveYamlInteger,
|
|
365
|
+
identify: (object) => Number.isInteger(object) && !Object.is(object, -0) && object.toString(10).indexOf("e") < 0,
|
|
366
|
+
represent: (object) => object.toString(10)
|
|
367
|
+
});
|
|
368
|
+
var YAML_FLOAT_PATTERN$1 = /* @__PURE__ */ new RegExp("^(?:[-+]?[0-9]+(?:\\.[0-9]*)?(?:[eE][-+]?[0-9]+)?|[-+]?\\.[0-9]+(?:[eE][-+]?[0-9]+)?|[-+]?\\.(?:inf|Inf|INF)|\\.(?:nan|NaN|NAN))$");
|
|
369
|
+
var YAML_FLOAT_SPECIAL_PATTERN$1 = /* @__PURE__ */ new RegExp("^(?:[-+]?\\.(?:inf|Inf|INF)|\\.(?:nan|NaN|NAN))$");
|
|
370
|
+
function resolveYamlFloat$2(source) {
|
|
371
|
+
if (!YAML_FLOAT_PATTERN$1.test(source))
|
|
372
|
+
return NOT_RESOLVED;
|
|
373
|
+
let value = source.toLowerCase();
|
|
374
|
+
const sign = value[0] === "-" ? -1 : 1;
|
|
375
|
+
if ("+-".includes(value[0]))
|
|
376
|
+
value = value.slice(1);
|
|
377
|
+
if (value === ".inf")
|
|
378
|
+
return sign === 1 ? Number.POSITIVE_INFINITY : Number.NEGATIVE_INFINITY;
|
|
379
|
+
if (value === ".nan")
|
|
380
|
+
return NaN;
|
|
381
|
+
const result = sign * parseFloat(value);
|
|
382
|
+
if (Number.isFinite(result) || YAML_FLOAT_SPECIAL_PATTERN$1.test(source))
|
|
383
|
+
return result;
|
|
384
|
+
return NOT_RESOLVED;
|
|
385
|
+
}
|
|
386
|
+
function representYamlFloat$2(object) {
|
|
387
|
+
if (isNaN(object))
|
|
388
|
+
return ".nan";
|
|
389
|
+
if (object === Number.POSITIVE_INFINITY)
|
|
390
|
+
return ".inf";
|
|
391
|
+
if (object === Number.NEGATIVE_INFINITY)
|
|
392
|
+
return "-.inf";
|
|
393
|
+
if (Object.is(object, -0))
|
|
394
|
+
return "-0.0";
|
|
395
|
+
const result = object.toString(10);
|
|
396
|
+
return /^[-+]?[0-9]+e/.test(result) ? result.replace("e", ".e") : result;
|
|
397
|
+
}
|
|
398
|
+
var floatCoreTag = defineScalarTag("tag:yaml.org,2002:float", {
|
|
399
|
+
implicit: true,
|
|
400
|
+
implicitFirstChars: [
|
|
401
|
+
"-",
|
|
402
|
+
"+",
|
|
403
|
+
".",
|
|
404
|
+
..."0123456789"
|
|
405
|
+
],
|
|
406
|
+
resolve: resolveYamlFloat$2,
|
|
407
|
+
identify: (object) => typeof object === "number" && (!Number.isInteger(object) || Object.is(object, -0) || object.toString(10).indexOf("e") >= 0),
|
|
408
|
+
represent: representYamlFloat$2
|
|
409
|
+
});
|
|
410
|
+
var YAML_FLOAT_IMPLICIT_PATTERN = /* @__PURE__ */ new RegExp("^-?(?:0|[1-9][0-9]*)(?:\\.[0-9]*)?(?:[eE][-+]?[0-9]+)?$");
|
|
411
|
+
var YAML_FLOAT_EXPLICIT_PATTERN = /* @__PURE__ */ new RegExp("^(?:[-+]?[0-9]+(?:\\.[0-9]*)?(?:[eE][-+]?[0-9]+)?|[-+]?\\.[0-9]+(?:[eE][-+]?[0-9]+)?|[-+]?\\.(?:inf|Inf|INF)|\\.(?:nan|NaN|NAN))$");
|
|
412
|
+
function resolveYamlFloat$1(source, isExplicit) {
|
|
413
|
+
if (isExplicit) {
|
|
414
|
+
if (!YAML_FLOAT_EXPLICIT_PATTERN.test(source))
|
|
415
|
+
return NOT_RESOLVED;
|
|
416
|
+
let value = source.toLowerCase();
|
|
417
|
+
const sign = value[0] === "-" ? -1 : 1;
|
|
418
|
+
if ("+-".includes(value[0]))
|
|
419
|
+
value = value.slice(1);
|
|
420
|
+
if (value === ".inf")
|
|
421
|
+
return sign === 1 ? Number.POSITIVE_INFINITY : Number.NEGATIVE_INFINITY;
|
|
422
|
+
if (value === ".nan")
|
|
423
|
+
return NaN;
|
|
424
|
+
const result2 = sign * parseFloat(value);
|
|
425
|
+
return Number.isFinite(result2) ? result2 : NOT_RESOLVED;
|
|
426
|
+
}
|
|
427
|
+
if (!YAML_FLOAT_IMPLICIT_PATTERN.test(source))
|
|
428
|
+
return NOT_RESOLVED;
|
|
429
|
+
const result = Number(source);
|
|
430
|
+
if (Number.isFinite(result))
|
|
431
|
+
return result;
|
|
432
|
+
return NOT_RESOLVED;
|
|
433
|
+
}
|
|
434
|
+
function representYamlFloat$1(object) {
|
|
435
|
+
if (isNaN(object))
|
|
436
|
+
return ".nan";
|
|
437
|
+
if (object === Number.POSITIVE_INFINITY)
|
|
438
|
+
return ".inf";
|
|
439
|
+
if (object === Number.NEGATIVE_INFINITY)
|
|
440
|
+
return "-.inf";
|
|
441
|
+
if (Object.is(object, -0))
|
|
442
|
+
return "-0.0";
|
|
443
|
+
const result = object.toString(10);
|
|
444
|
+
return /^[-+]?[0-9]+e/.test(result) ? result.replace("e", ".e") : result;
|
|
445
|
+
}
|
|
446
|
+
var floatJsonTag = defineScalarTag("tag:yaml.org,2002:float", {
|
|
447
|
+
implicit: true,
|
|
448
|
+
implicitFirstChars: ["-", ..."0123456789"],
|
|
449
|
+
resolve: resolveYamlFloat$1,
|
|
450
|
+
identify: (object) => typeof object === "number" && (!Number.isInteger(object) || Object.is(object, -0) || object.toString(10).indexOf("e") >= 0),
|
|
451
|
+
represent: representYamlFloat$1
|
|
452
|
+
});
|
|
453
|
+
var YAML_FLOAT_PATTERN = /* @__PURE__ */ new RegExp("^(?:[-+]?(?:(?:[0-9][0-9_]*)?\\.[0-9_]*)(?:[eE][-+][0-9]+)?|[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+\\.[0-9_]*|[-+]?\\.(?:inf|Inf|INF)|\\.(?:nan|NaN|NAN))$");
|
|
454
|
+
var YAML_FLOAT_SPECIAL_PATTERN = /* @__PURE__ */ new RegExp("^(?:[-+]?\\.(?:inf|Inf|INF)|\\.(?:nan|NaN|NAN))$");
|
|
455
|
+
function resolveYamlFloat(source) {
|
|
456
|
+
if (!YAML_FLOAT_PATTERN.test(source))
|
|
457
|
+
return NOT_RESOLVED;
|
|
458
|
+
let value = source.toLowerCase().replace(/_/g, "");
|
|
459
|
+
const sign = value[0] === "-" ? -1 : 1;
|
|
460
|
+
if ("+-".includes(value[0]))
|
|
461
|
+
value = value.slice(1);
|
|
462
|
+
if (value === ".inf")
|
|
463
|
+
return sign === 1 ? Number.POSITIVE_INFINITY : Number.NEGATIVE_INFINITY;
|
|
464
|
+
if (value === ".nan")
|
|
465
|
+
return NaN;
|
|
466
|
+
let result = 0;
|
|
467
|
+
if (value.includes(":")) {
|
|
468
|
+
for (const part of value.split(":"))
|
|
469
|
+
result = result * 60 + Number(part);
|
|
470
|
+
result *= sign;
|
|
471
|
+
} else
|
|
472
|
+
result = sign * parseFloat(value);
|
|
473
|
+
if (Number.isFinite(result) || YAML_FLOAT_SPECIAL_PATTERN.test(source))
|
|
474
|
+
return result;
|
|
475
|
+
return NOT_RESOLVED;
|
|
476
|
+
}
|
|
477
|
+
function representYamlFloat(object) {
|
|
478
|
+
if (isNaN(object))
|
|
479
|
+
return ".nan";
|
|
480
|
+
if (object === Number.POSITIVE_INFINITY)
|
|
481
|
+
return ".inf";
|
|
482
|
+
if (object === Number.NEGATIVE_INFINITY)
|
|
483
|
+
return "-.inf";
|
|
484
|
+
if (Object.is(object, -0))
|
|
485
|
+
return "-0.0";
|
|
486
|
+
const result = object.toString(10);
|
|
487
|
+
return /^[-+]?[0-9]+e/.test(result) ? result.replace("e", ".e") : result;
|
|
488
|
+
}
|
|
489
|
+
var floatYaml11Tag = defineScalarTag("tag:yaml.org,2002:float", {
|
|
490
|
+
implicit: true,
|
|
491
|
+
implicitFirstChars: [
|
|
492
|
+
"-",
|
|
493
|
+
"+",
|
|
494
|
+
".",
|
|
495
|
+
..."0123456789"
|
|
496
|
+
],
|
|
497
|
+
resolve: resolveYamlFloat,
|
|
498
|
+
identify: (object) => typeof object === "number" && (!Number.isInteger(object) || Object.is(object, -0) || object.toString(10).indexOf("e") >= 0),
|
|
499
|
+
represent: representYamlFloat
|
|
500
|
+
});
|
|
501
|
+
var mergeTag = defineScalarTag("tag:yaml.org,2002:merge", {
|
|
502
|
+
implicit: true,
|
|
503
|
+
implicitFirstChars: ["<"],
|
|
504
|
+
resolve: (source, isExplicit) => {
|
|
505
|
+
if (source === "<<" || isExplicit && source === "")
|
|
506
|
+
return "<<";
|
|
507
|
+
return NOT_RESOLVED;
|
|
508
|
+
},
|
|
509
|
+
identify: () => false
|
|
510
|
+
});
|
|
511
|
+
var BASE64_PATTERN = /^[A-Za-z0-9+/]*={0,2}$/;
|
|
512
|
+
function resolveYamlBinary(source) {
|
|
513
|
+
const input = source.replace(/\s/g, "");
|
|
514
|
+
if (input.length % 4 !== 0 || !BASE64_PATTERN.test(input))
|
|
515
|
+
return NOT_RESOLVED;
|
|
516
|
+
const binary = atob(input);
|
|
517
|
+
const result = new Uint8Array(binary.length);
|
|
518
|
+
for (let index = 0;index < binary.length; index++)
|
|
519
|
+
result[index] = binary.charCodeAt(index);
|
|
520
|
+
return result;
|
|
521
|
+
}
|
|
522
|
+
function representYamlBinary(object) {
|
|
523
|
+
let binary = "";
|
|
524
|
+
for (let index = 0;index < object.length; index++)
|
|
525
|
+
binary += String.fromCharCode(object[index]);
|
|
526
|
+
return btoa(binary);
|
|
527
|
+
}
|
|
528
|
+
var binaryTag = defineScalarTag("tag:yaml.org,2002:binary", {
|
|
529
|
+
resolve: resolveYamlBinary,
|
|
530
|
+
identify: (object) => Object.prototype.toString.call(object) === "[object Uint8Array]",
|
|
531
|
+
represent: representYamlBinary
|
|
532
|
+
});
|
|
533
|
+
var YAML_DATE_REGEXP = /* @__PURE__ */ new RegExp("^([0-9][0-9][0-9][0-9])-([0-9][0-9])-([0-9][0-9])$");
|
|
534
|
+
var YAML_TIMESTAMP_REGEXP = /* @__PURE__ */ new RegExp("^([0-9][0-9][0-9][0-9])-([0-9][0-9]?)-([0-9][0-9]?)(?:[Tt]|[ \\t]+)([0-9][0-9]?):([0-9][0-9]):([0-9][0-9])(?:\\.([0-9]*))?(?:[ \\t]*(Z|([-+])([0-9][0-9]?)(?::([0-9][0-9]))?))?$");
|
|
535
|
+
function makeUtcDate(year, month, day, hour = 0, minute = 0, second = 0, fraction = 0) {
|
|
536
|
+
const date = new Date(Date.UTC(year, month, day, hour, minute, second, fraction));
|
|
537
|
+
date.setUTCFullYear(year, month, day);
|
|
538
|
+
return date;
|
|
539
|
+
}
|
|
540
|
+
function resolveYamlTimestamp(source) {
|
|
541
|
+
let match = YAML_DATE_REGEXP.exec(source);
|
|
542
|
+
if (match === null)
|
|
543
|
+
match = YAML_TIMESTAMP_REGEXP.exec(source);
|
|
544
|
+
if (match === null)
|
|
545
|
+
return NOT_RESOLVED;
|
|
546
|
+
const year = +match[1];
|
|
547
|
+
const month = +match[2] - 1;
|
|
548
|
+
const day = +match[3];
|
|
549
|
+
if (!match[4]) {
|
|
550
|
+
const date2 = makeUtcDate(year, month, day);
|
|
551
|
+
if (date2.getUTCFullYear() !== year || date2.getUTCMonth() !== month || date2.getUTCDate() !== day)
|
|
552
|
+
return NOT_RESOLVED;
|
|
553
|
+
return date2;
|
|
554
|
+
}
|
|
555
|
+
const hour = +match[4];
|
|
556
|
+
const minute = +match[5];
|
|
557
|
+
const second = +match[6];
|
|
558
|
+
let fraction = 0;
|
|
559
|
+
if (hour > 23 || minute > 59 || second > 59)
|
|
560
|
+
return NOT_RESOLVED;
|
|
561
|
+
if (match[7]) {
|
|
562
|
+
let value = match[7].slice(0, 3);
|
|
563
|
+
while (value.length < 3)
|
|
564
|
+
value += "0";
|
|
565
|
+
fraction = +value;
|
|
566
|
+
}
|
|
567
|
+
const date = makeUtcDate(year, month, day, hour, minute, second, fraction);
|
|
568
|
+
if (date.getUTCFullYear() !== year || date.getUTCMonth() !== month || date.getUTCDate() !== day)
|
|
569
|
+
return NOT_RESOLVED;
|
|
570
|
+
if (match[9]) {
|
|
571
|
+
const offsetHour = +match[10];
|
|
572
|
+
const offsetMinute = +(match[11] || 0);
|
|
573
|
+
if (offsetHour > 23 || offsetMinute > 59)
|
|
574
|
+
return NOT_RESOLVED;
|
|
575
|
+
const offset = (offsetHour * 60 + offsetMinute) * 60000;
|
|
576
|
+
date.setTime(date.getTime() - (match[9] === "-" ? -offset : offset));
|
|
577
|
+
}
|
|
578
|
+
return date;
|
|
579
|
+
}
|
|
580
|
+
var timestampTag = defineScalarTag("tag:yaml.org,2002:timestamp", {
|
|
581
|
+
implicit: true,
|
|
582
|
+
implicitFirstChars: [..."0123456789"],
|
|
583
|
+
resolve: resolveYamlTimestamp,
|
|
584
|
+
identify: (object) => object instanceof Date,
|
|
585
|
+
represent: (object) => object.toISOString()
|
|
586
|
+
});
|
|
587
|
+
var seqTag = defineSequenceTag("tag:yaml.org,2002:seq", {
|
|
588
|
+
create: () => [],
|
|
589
|
+
addItem: (container, item) => {
|
|
590
|
+
container.push(item);
|
|
591
|
+
},
|
|
592
|
+
identify: Array.isArray
|
|
593
|
+
});
|
|
594
|
+
function isPlainObject(data) {
|
|
595
|
+
if (data === null || typeof data !== "object" || Array.isArray(data))
|
|
596
|
+
return false;
|
|
597
|
+
const prototype = Object.getPrototypeOf(data);
|
|
598
|
+
return prototype === null || prototype === Object.prototype;
|
|
599
|
+
}
|
|
600
|
+
function pick(object, keys) {
|
|
601
|
+
const result = {};
|
|
602
|
+
for (const key of keys)
|
|
603
|
+
if (object[key] !== undefined)
|
|
604
|
+
result[key] = object[key];
|
|
605
|
+
return result;
|
|
606
|
+
}
|
|
607
|
+
var omapTag = defineSequenceTag("tag:yaml.org,2002:omap", {
|
|
608
|
+
create: () => ({
|
|
609
|
+
list: [],
|
|
610
|
+
seen: /* @__PURE__ */ new Set
|
|
611
|
+
}),
|
|
612
|
+
addItem: (carrier, item) => {
|
|
613
|
+
let key;
|
|
614
|
+
if (item instanceof Map) {
|
|
615
|
+
if (item.size !== 1)
|
|
616
|
+
return "cannot resolve an ordered map item";
|
|
617
|
+
key = item.keys().next().value;
|
|
618
|
+
} else if (isPlainObject(item)) {
|
|
619
|
+
const itemKeys = Object.keys(item);
|
|
620
|
+
if (itemKeys.length !== 1)
|
|
621
|
+
return "cannot resolve an ordered map item";
|
|
622
|
+
key = itemKeys[0];
|
|
623
|
+
} else
|
|
624
|
+
return "cannot resolve an ordered map item";
|
|
625
|
+
if (carrier.seen.has(key))
|
|
626
|
+
return "duplicate key in ordered map";
|
|
627
|
+
carrier.seen.add(key);
|
|
628
|
+
carrier.list.push(item);
|
|
629
|
+
return "";
|
|
630
|
+
},
|
|
631
|
+
finalize: (carrier) => carrier.list,
|
|
632
|
+
identify: () => false
|
|
633
|
+
});
|
|
634
|
+
var pairsTag = defineSequenceTag("tag:yaml.org,2002:pairs", {
|
|
635
|
+
create: () => [],
|
|
636
|
+
addItem: (container, item) => {
|
|
637
|
+
if (item instanceof Map) {
|
|
638
|
+
if (item.size !== 1)
|
|
639
|
+
return "cannot resolve a pairs item";
|
|
640
|
+
container.push(item.entries().next().value);
|
|
641
|
+
return "";
|
|
642
|
+
}
|
|
643
|
+
if (Object.prototype.toString.call(item) !== "[object Object]")
|
|
644
|
+
return "cannot resolve a pairs item";
|
|
645
|
+
const object = item;
|
|
646
|
+
const keys = Object.keys(object);
|
|
647
|
+
if (keys.length !== 1)
|
|
648
|
+
return "cannot resolve a pairs item";
|
|
649
|
+
container.push([keys[0], object[keys[0]]]);
|
|
650
|
+
return "";
|
|
651
|
+
},
|
|
652
|
+
identify: () => false
|
|
653
|
+
});
|
|
654
|
+
var mapTag = defineMappingTag("tag:yaml.org,2002:map", {
|
|
655
|
+
create: () => ({}),
|
|
656
|
+
identify: isPlainObject,
|
|
657
|
+
represent: (o) => {
|
|
658
|
+
const map = /* @__PURE__ */ new Map;
|
|
659
|
+
for (const key of Object.keys(o))
|
|
660
|
+
map.set(key, o[key]);
|
|
661
|
+
return map;
|
|
662
|
+
},
|
|
663
|
+
addPair: (container, key, value) => {
|
|
664
|
+
if (key !== null && typeof key === "object")
|
|
665
|
+
return "object-based map does not support complex keys";
|
|
666
|
+
const normalizedKey = String(key);
|
|
667
|
+
if (normalizedKey === "__proto__")
|
|
668
|
+
Object.defineProperty(container, normalizedKey, {
|
|
669
|
+
value,
|
|
670
|
+
enumerable: true,
|
|
671
|
+
configurable: true,
|
|
672
|
+
writable: true
|
|
673
|
+
});
|
|
674
|
+
else
|
|
675
|
+
container[normalizedKey] = value;
|
|
676
|
+
return "";
|
|
677
|
+
},
|
|
678
|
+
has: (container, key) => {
|
|
679
|
+
if (key !== null && typeof key === "object")
|
|
680
|
+
return false;
|
|
681
|
+
return Object.prototype.hasOwnProperty.call(container, String(key));
|
|
682
|
+
},
|
|
683
|
+
keys: (container) => Object.keys(container),
|
|
684
|
+
get: (container, key) => {
|
|
685
|
+
const normalizedKey = String(key);
|
|
686
|
+
if (!Object.prototype.hasOwnProperty.call(container, normalizedKey))
|
|
687
|
+
return null;
|
|
688
|
+
return container[normalizedKey];
|
|
689
|
+
}
|
|
690
|
+
});
|
|
691
|
+
var setTag = defineMappingTag("tag:yaml.org,2002:set", {
|
|
692
|
+
create: () => /* @__PURE__ */ new Set,
|
|
693
|
+
identify: (data) => data instanceof Set,
|
|
694
|
+
represent: (data) => {
|
|
695
|
+
const map = /* @__PURE__ */ new Map;
|
|
696
|
+
for (const key of data)
|
|
697
|
+
map.set(key, null);
|
|
698
|
+
return map;
|
|
699
|
+
},
|
|
700
|
+
addPair: (container, key, value) => {
|
|
701
|
+
if (value !== null)
|
|
702
|
+
return "cannot resolve a set item";
|
|
703
|
+
container.add(key);
|
|
704
|
+
return "";
|
|
705
|
+
},
|
|
706
|
+
has: (container, key) => container.has(key),
|
|
707
|
+
keys: (container) => container.keys(),
|
|
708
|
+
get: () => null
|
|
709
|
+
});
|
|
710
|
+
function createTagDefinitionMap() {
|
|
711
|
+
return {
|
|
712
|
+
scalar: Object.create(null),
|
|
713
|
+
sequence: Object.create(null),
|
|
714
|
+
mapping: Object.create(null)
|
|
715
|
+
};
|
|
716
|
+
}
|
|
717
|
+
function createTagDefinitionListMap() {
|
|
718
|
+
return {
|
|
719
|
+
scalar: [],
|
|
720
|
+
sequence: [],
|
|
721
|
+
mapping: []
|
|
722
|
+
};
|
|
723
|
+
}
|
|
724
|
+
function compileTags(tags) {
|
|
725
|
+
const result = [];
|
|
726
|
+
for (const tag of tags) {
|
|
727
|
+
let index = result.length;
|
|
728
|
+
for (let previousIndex = 0;previousIndex < result.length; previousIndex++) {
|
|
729
|
+
const previous = result[previousIndex];
|
|
730
|
+
if (previous.nodeKind === tag.nodeKind && previous.tagName === tag.tagName && previous.matchByTagPrefix === tag.matchByTagPrefix) {
|
|
731
|
+
index = previousIndex;
|
|
732
|
+
break;
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
result[index] = tag;
|
|
736
|
+
}
|
|
737
|
+
return result;
|
|
738
|
+
}
|
|
739
|
+
var Schema = class Schema2 {
|
|
740
|
+
tags;
|
|
741
|
+
implicitScalarTags;
|
|
742
|
+
implicitScalarByFirstChar;
|
|
743
|
+
implicitScalarAnyFirstChar;
|
|
744
|
+
defaultScalarTag;
|
|
745
|
+
defaultSequenceTag;
|
|
746
|
+
defaultMappingTag;
|
|
747
|
+
exact;
|
|
748
|
+
prefix;
|
|
749
|
+
constructor(tags) {
|
|
750
|
+
const compiledTags = compileTags(tags);
|
|
751
|
+
const implicitScalarTags = [];
|
|
752
|
+
const exact = createTagDefinitionMap();
|
|
753
|
+
const prefix = createTagDefinitionListMap();
|
|
754
|
+
for (const tag of compiledTags) {
|
|
755
|
+
if (tag.nodeKind === "scalar" && tag.implicit) {
|
|
756
|
+
if (tag.matchByTagPrefix)
|
|
757
|
+
throw new Error("Implicit scalar tags cannot match by tag prefix");
|
|
758
|
+
implicitScalarTags.push(tag);
|
|
759
|
+
}
|
|
760
|
+
switch (tag.nodeKind) {
|
|
761
|
+
case "scalar":
|
|
762
|
+
if (tag.matchByTagPrefix)
|
|
763
|
+
prefix.scalar.push(tag);
|
|
764
|
+
else
|
|
765
|
+
exact.scalar[tag.tagName] = tag;
|
|
766
|
+
break;
|
|
767
|
+
case "sequence":
|
|
768
|
+
if (tag.matchByTagPrefix)
|
|
769
|
+
prefix.sequence.push(tag);
|
|
770
|
+
else
|
|
771
|
+
exact.sequence[tag.tagName] = tag;
|
|
772
|
+
break;
|
|
773
|
+
case "mapping":
|
|
774
|
+
if (tag.matchByTagPrefix)
|
|
775
|
+
prefix.mapping.push(tag);
|
|
776
|
+
else
|
|
777
|
+
exact.mapping[tag.tagName] = tag;
|
|
778
|
+
break;
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
const implicitScalarAnyFirstChar = implicitScalarTags.filter((tag) => tag.implicitFirstChars === null);
|
|
782
|
+
const keys = /* @__PURE__ */ new Set;
|
|
783
|
+
for (const tag of implicitScalarTags)
|
|
784
|
+
if (tag.implicitFirstChars !== null)
|
|
785
|
+
for (const key of tag.implicitFirstChars)
|
|
786
|
+
keys.add(key);
|
|
787
|
+
const implicitScalarByFirstChar = /* @__PURE__ */ new Map;
|
|
788
|
+
for (const key of keys)
|
|
789
|
+
implicitScalarByFirstChar.set(key, implicitScalarTags.filter((tag) => tag.implicitFirstChars === null || tag.implicitFirstChars.indexOf(key) !== -1));
|
|
790
|
+
const defaultScalarTag = exact.scalar["tag:yaml.org,2002:str"];
|
|
791
|
+
if (!defaultScalarTag)
|
|
792
|
+
throw new Error("schema does not define the default scalar tag (tag:yaml.org,2002:str)");
|
|
793
|
+
this.tags = compiledTags;
|
|
794
|
+
this.implicitScalarTags = implicitScalarTags;
|
|
795
|
+
this.implicitScalarByFirstChar = implicitScalarByFirstChar;
|
|
796
|
+
this.implicitScalarAnyFirstChar = implicitScalarAnyFirstChar;
|
|
797
|
+
this.defaultScalarTag = defaultScalarTag;
|
|
798
|
+
this.defaultSequenceTag = exact.sequence["tag:yaml.org,2002:seq"];
|
|
799
|
+
this.defaultMappingTag = exact.mapping["tag:yaml.org,2002:map"];
|
|
800
|
+
this.exact = exact;
|
|
801
|
+
this.prefix = prefix;
|
|
802
|
+
}
|
|
803
|
+
lookupScalarTag(tagName) {
|
|
804
|
+
const exactTag = this.exact.scalar[tagName];
|
|
805
|
+
if (exactTag)
|
|
806
|
+
return exactTag;
|
|
807
|
+
for (const tag of this.prefix.scalar)
|
|
808
|
+
if (tagName.startsWith(tag.tagName))
|
|
809
|
+
return tag;
|
|
810
|
+
}
|
|
811
|
+
lookupSequenceTag(tagName) {
|
|
812
|
+
const exactTag = this.exact.sequence[tagName];
|
|
813
|
+
if (exactTag)
|
|
814
|
+
return exactTag;
|
|
815
|
+
for (const tag of this.prefix.sequence)
|
|
816
|
+
if (tagName.startsWith(tag.tagName))
|
|
817
|
+
return tag;
|
|
818
|
+
}
|
|
819
|
+
lookupMappingTag(tagName) {
|
|
820
|
+
const exactTag = this.exact.mapping[tagName];
|
|
821
|
+
if (exactTag)
|
|
822
|
+
return exactTag;
|
|
823
|
+
for (const tag of this.prefix.mapping)
|
|
824
|
+
if (tagName.startsWith(tag.tagName))
|
|
825
|
+
return tag;
|
|
826
|
+
}
|
|
827
|
+
resolveImplicitScalarTag(source) {
|
|
828
|
+
const candidates = this.implicitScalarByFirstChar.get(source.charAt(0)) ?? this.implicitScalarAnyFirstChar;
|
|
829
|
+
for (const tag2 of candidates) {
|
|
830
|
+
const value = tag2.resolve(source, false, tag2.tagName);
|
|
831
|
+
if (value !== NOT_RESOLVED)
|
|
832
|
+
return {
|
|
833
|
+
value,
|
|
834
|
+
tag: tag2
|
|
835
|
+
};
|
|
836
|
+
}
|
|
837
|
+
const tag = this.defaultScalarTag;
|
|
838
|
+
return {
|
|
839
|
+
value: tag.resolve(source, false, tag.tagName),
|
|
840
|
+
tag
|
|
841
|
+
};
|
|
842
|
+
}
|
|
843
|
+
withTags(...tags) {
|
|
844
|
+
let flatTags = [];
|
|
845
|
+
for (const tag of tags)
|
|
846
|
+
flatTags = flatTags.concat(tag);
|
|
847
|
+
return new Schema2([...this.tags, ...flatTags]);
|
|
848
|
+
}
|
|
849
|
+
};
|
|
850
|
+
var FAILSAFE_SCHEMA = new Schema([
|
|
851
|
+
strTag,
|
|
852
|
+
seqTag,
|
|
853
|
+
mapTag
|
|
854
|
+
]);
|
|
855
|
+
var JSON_SCHEMA = new Schema([
|
|
856
|
+
...FAILSAFE_SCHEMA.tags,
|
|
857
|
+
nullJsonTag,
|
|
858
|
+
boolJsonTag,
|
|
859
|
+
intJsonTag,
|
|
860
|
+
floatJsonTag
|
|
861
|
+
]);
|
|
862
|
+
var CORE_SCHEMA = new Schema([
|
|
863
|
+
...FAILSAFE_SCHEMA.tags,
|
|
864
|
+
nullCoreTag,
|
|
865
|
+
boolCoreTag,
|
|
866
|
+
intCoreTag,
|
|
867
|
+
floatCoreTag
|
|
868
|
+
]);
|
|
869
|
+
var YAML11_SCHEMA = new Schema([
|
|
870
|
+
...FAILSAFE_SCHEMA.tags,
|
|
871
|
+
nullYaml11Tag,
|
|
872
|
+
boolYaml11Tag,
|
|
873
|
+
intYaml11Tag,
|
|
874
|
+
floatYaml11Tag,
|
|
875
|
+
timestampTag,
|
|
876
|
+
mergeTag,
|
|
877
|
+
binaryTag,
|
|
878
|
+
omapTag,
|
|
879
|
+
pairsTag,
|
|
880
|
+
setTag
|
|
881
|
+
]);
|
|
882
|
+
var DUMP_SCHEMA = YAML11_SCHEMA.withTags({
|
|
883
|
+
...intYaml11Tag,
|
|
884
|
+
resolve: (source, isExplicit, tagName) => {
|
|
885
|
+
const result = intYaml11Tag.resolve(source, isExplicit, tagName);
|
|
886
|
+
return result === NOT_RESOLVED ? intCoreTag.resolve(source, isExplicit, tagName) : result;
|
|
887
|
+
}
|
|
888
|
+
}, {
|
|
889
|
+
...floatYaml11Tag,
|
|
890
|
+
resolve: (source, isExplicit, tagName) => {
|
|
891
|
+
const result = floatYaml11Tag.resolve(source, isExplicit, tagName);
|
|
892
|
+
return result === NOT_RESOLVED ? floatCoreTag.resolve(source, isExplicit, tagName) : result;
|
|
893
|
+
}
|
|
894
|
+
});
|
|
895
|
+
var realMapTag = defineMappingTag("tag:yaml.org,2002:map", {
|
|
896
|
+
create: () => /* @__PURE__ */ new Map,
|
|
897
|
+
addPair: (container, key, value) => {
|
|
898
|
+
container.set(key, value);
|
|
899
|
+
return "";
|
|
900
|
+
},
|
|
901
|
+
has: (container, key) => container.has(key),
|
|
902
|
+
keys: (container) => container.keys(),
|
|
903
|
+
get: (container, key) => container.get(key),
|
|
904
|
+
identify: (data) => data instanceof Map || isPlainObject(data),
|
|
905
|
+
represent: (data) => {
|
|
906
|
+
if (data instanceof Map)
|
|
907
|
+
return data;
|
|
908
|
+
const map = /* @__PURE__ */ new Map;
|
|
909
|
+
const obj = data;
|
|
910
|
+
for (const key of Object.keys(obj))
|
|
911
|
+
map.set(key, obj[key]);
|
|
912
|
+
return map;
|
|
913
|
+
}
|
|
914
|
+
});
|
|
915
|
+
function normalizeKey(key) {
|
|
916
|
+
if (Array.isArray(key)) {
|
|
917
|
+
const array = Array.prototype.slice.call(key);
|
|
918
|
+
for (let index = 0;index < array.length; index++) {
|
|
919
|
+
if (Array.isArray(array[index]))
|
|
920
|
+
return null;
|
|
921
|
+
if (typeof array[index] === "object" && Object.prototype.toString.call(array[index]) === "[object Object]")
|
|
922
|
+
array[index] = "[object Object]";
|
|
923
|
+
}
|
|
924
|
+
return String(array);
|
|
925
|
+
}
|
|
926
|
+
if (typeof key === "object" && Object.prototype.toString.call(key) === "[object Object]")
|
|
927
|
+
return "[object Object]";
|
|
928
|
+
return String(key);
|
|
929
|
+
}
|
|
930
|
+
var legacyMapTag = defineMappingTag("tag:yaml.org,2002:map", {
|
|
931
|
+
create: () => ({}),
|
|
932
|
+
identify: isPlainObject,
|
|
933
|
+
represent: (o) => {
|
|
934
|
+
const map = /* @__PURE__ */ new Map;
|
|
935
|
+
for (const key of Object.keys(o))
|
|
936
|
+
map.set(key, o[key]);
|
|
937
|
+
return map;
|
|
938
|
+
},
|
|
939
|
+
addPair: (container, key, value) => {
|
|
940
|
+
const normalizedKey = normalizeKey(key);
|
|
941
|
+
if (normalizedKey === null)
|
|
942
|
+
return "nested arrays are not supported inside keys";
|
|
943
|
+
if (normalizedKey === "__proto__")
|
|
944
|
+
Object.defineProperty(container, normalizedKey, {
|
|
945
|
+
value,
|
|
946
|
+
enumerable: true,
|
|
947
|
+
configurable: true,
|
|
948
|
+
writable: true
|
|
949
|
+
});
|
|
950
|
+
else
|
|
951
|
+
container[normalizedKey] = value;
|
|
952
|
+
return "";
|
|
953
|
+
},
|
|
954
|
+
has: (container, key) => {
|
|
955
|
+
const normalizedKey = normalizeKey(key);
|
|
956
|
+
return normalizedKey !== null && Object.prototype.hasOwnProperty.call(container, normalizedKey);
|
|
957
|
+
},
|
|
958
|
+
keys: (container) => Object.keys(container),
|
|
959
|
+
get: (container, key) => {
|
|
960
|
+
const normalizedKey = String(key);
|
|
961
|
+
if (!Object.prototype.hasOwnProperty.call(container, normalizedKey))
|
|
962
|
+
return null;
|
|
963
|
+
return container[normalizedKey];
|
|
964
|
+
}
|
|
965
|
+
});
|
|
966
|
+
var DEFAULT_SNIPPET_OPTIONS = {
|
|
967
|
+
maxLength: 79,
|
|
968
|
+
indent: 1,
|
|
969
|
+
linesBefore: 3,
|
|
970
|
+
linesAfter: 2
|
|
971
|
+
};
|
|
972
|
+
function getLine(buffer, lineStart, lineEnd, position, maxLineLength) {
|
|
973
|
+
let head = "";
|
|
974
|
+
let tail = "";
|
|
975
|
+
const maxHalfLength = Math.floor(maxLineLength / 2) - 1;
|
|
976
|
+
if (position - lineStart > maxHalfLength) {
|
|
977
|
+
head = " ... ";
|
|
978
|
+
lineStart = position - maxHalfLength + head.length;
|
|
979
|
+
}
|
|
980
|
+
if (lineEnd - position > maxHalfLength) {
|
|
981
|
+
tail = " ...";
|
|
982
|
+
lineEnd = position + maxHalfLength - tail.length;
|
|
983
|
+
}
|
|
984
|
+
return {
|
|
985
|
+
str: head + buffer.slice(lineStart, lineEnd).replace(/\t/g, "→") + tail,
|
|
986
|
+
pos: position - lineStart + head.length
|
|
987
|
+
};
|
|
988
|
+
}
|
|
989
|
+
function padStart(string, max) {
|
|
990
|
+
return " ".repeat(Math.max(max - string.length, 0)) + string;
|
|
991
|
+
}
|
|
992
|
+
function makeSnippet(mark, options) {
|
|
993
|
+
if (!mark.buffer)
|
|
994
|
+
return null;
|
|
995
|
+
const opts = {
|
|
996
|
+
...DEFAULT_SNIPPET_OPTIONS,
|
|
997
|
+
...options
|
|
998
|
+
};
|
|
999
|
+
const re = /\r?\n|\r|\0/g;
|
|
1000
|
+
const lineStarts = [0];
|
|
1001
|
+
const lineEnds = [];
|
|
1002
|
+
let match;
|
|
1003
|
+
let foundLineNo = -1;
|
|
1004
|
+
while (match = re.exec(mark.buffer)) {
|
|
1005
|
+
lineEnds.push(match.index);
|
|
1006
|
+
lineStarts.push(match.index + match[0].length);
|
|
1007
|
+
if (mark.position <= match.index && foundLineNo < 0)
|
|
1008
|
+
foundLineNo = lineStarts.length - 2;
|
|
1009
|
+
}
|
|
1010
|
+
if (foundLineNo < 0)
|
|
1011
|
+
foundLineNo = lineStarts.length - 1;
|
|
1012
|
+
let result = "";
|
|
1013
|
+
const lineNoLength = Math.min(mark.line + opts.linesAfter, lineEnds.length).toString().length;
|
|
1014
|
+
const maxLineLength = opts.maxLength - (opts.indent + lineNoLength + 3);
|
|
1015
|
+
for (let i = 1;i <= opts.linesBefore; i++) {
|
|
1016
|
+
if (foundLineNo - i < 0)
|
|
1017
|
+
break;
|
|
1018
|
+
const line2 = getLine(mark.buffer, lineStarts[foundLineNo - i], lineEnds[foundLineNo - i], mark.position - (lineStarts[foundLineNo] - lineStarts[foundLineNo - i]), maxLineLength);
|
|
1019
|
+
result = `${" ".repeat(opts.indent)}${padStart((mark.line - i + 1).toString(), lineNoLength)} | ${line2.str}
|
|
1020
|
+
${result}`;
|
|
1021
|
+
}
|
|
1022
|
+
const line = getLine(mark.buffer, lineStarts[foundLineNo], lineEnds[foundLineNo], mark.position, maxLineLength);
|
|
1023
|
+
result += `${" ".repeat(opts.indent)}${padStart((mark.line + 1).toString(), lineNoLength)} | ${line.str}
|
|
1024
|
+
`;
|
|
1025
|
+
result += `${"-".repeat(opts.indent + lineNoLength + 3 + line.pos)}^
|
|
1026
|
+
`;
|
|
1027
|
+
for (let i = 1;i <= opts.linesAfter; i++) {
|
|
1028
|
+
if (foundLineNo + i >= lineEnds.length)
|
|
1029
|
+
break;
|
|
1030
|
+
const line2 = getLine(mark.buffer, lineStarts[foundLineNo + i], lineEnds[foundLineNo + i], mark.position - (lineStarts[foundLineNo] - lineStarts[foundLineNo + i]), maxLineLength);
|
|
1031
|
+
result += `${" ".repeat(opts.indent)}${padStart((mark.line + i + 1).toString(), lineNoLength)} | ${line2.str}
|
|
1032
|
+
`;
|
|
1033
|
+
}
|
|
1034
|
+
return result.replace(/\n$/, "");
|
|
1035
|
+
}
|
|
1036
|
+
function formatError(exception, compact) {
|
|
1037
|
+
let where = "";
|
|
1038
|
+
if (!exception.mark)
|
|
1039
|
+
return exception.reason;
|
|
1040
|
+
if (exception.mark.name)
|
|
1041
|
+
where += `in "${exception.mark.name}" `;
|
|
1042
|
+
where += `(${exception.mark.line + 1}:${exception.mark.column + 1})`;
|
|
1043
|
+
if (!compact && exception.mark.snippet)
|
|
1044
|
+
where += `
|
|
1045
|
+
|
|
1046
|
+
${exception.mark.snippet}`;
|
|
1047
|
+
return `${exception.reason} ${where}`;
|
|
1048
|
+
}
|
|
1049
|
+
var YAMLException = class YAMLException2 extends Error {
|
|
1050
|
+
reason;
|
|
1051
|
+
mark;
|
|
1052
|
+
constructor(reason, mark) {
|
|
1053
|
+
super();
|
|
1054
|
+
this.name = "YAMLException";
|
|
1055
|
+
this.reason = reason;
|
|
1056
|
+
this.mark = mark;
|
|
1057
|
+
this.message = formatError(this, false);
|
|
1058
|
+
if (Error.captureStackTrace)
|
|
1059
|
+
Error.captureStackTrace(this, this.constructor);
|
|
1060
|
+
}
|
|
1061
|
+
toString(compact) {
|
|
1062
|
+
return `${this.name}: ${formatError(this, compact)}`;
|
|
1063
|
+
}
|
|
1064
|
+
static throwAt(source, position, message, filename = "") {
|
|
1065
|
+
let line = 0;
|
|
1066
|
+
let lineStart = 0;
|
|
1067
|
+
for (let index = 0;index < position; index++) {
|
|
1068
|
+
const ch = source.charCodeAt(index);
|
|
1069
|
+
if (ch === 10) {
|
|
1070
|
+
line++;
|
|
1071
|
+
lineStart = index + 1;
|
|
1072
|
+
} else if (ch === 13) {
|
|
1073
|
+
line++;
|
|
1074
|
+
if (source.charCodeAt(index + 1) === 10)
|
|
1075
|
+
index++;
|
|
1076
|
+
lineStart = index + 1;
|
|
1077
|
+
}
|
|
1078
|
+
}
|
|
1079
|
+
const mark = {
|
|
1080
|
+
name: filename,
|
|
1081
|
+
buffer: source,
|
|
1082
|
+
position,
|
|
1083
|
+
line,
|
|
1084
|
+
column: position - lineStart
|
|
1085
|
+
};
|
|
1086
|
+
mark.snippet = makeSnippet(mark);
|
|
1087
|
+
throw new YAMLException2(message, mark);
|
|
1088
|
+
}
|
|
1089
|
+
};
|
|
1090
|
+
var EVENT_ID = {
|
|
1091
|
+
DOCUMENT: 1,
|
|
1092
|
+
SEQUENCE: 2,
|
|
1093
|
+
MAPPING: 3,
|
|
1094
|
+
SCALAR: 4,
|
|
1095
|
+
ALIAS: 5,
|
|
1096
|
+
POP: 6
|
|
1097
|
+
};
|
|
1098
|
+
var SCALAR_STYLE = {
|
|
1099
|
+
PLAIN: 1,
|
|
1100
|
+
SINGLE_QUOTED: 2,
|
|
1101
|
+
DOUBLE_QUOTED: 3,
|
|
1102
|
+
LITERAL_BLOCK: 4,
|
|
1103
|
+
FOLDED_BLOCK: 5
|
|
1104
|
+
};
|
|
1105
|
+
var COLLECTION_STYLE = {
|
|
1106
|
+
BLOCK: 1,
|
|
1107
|
+
FLOW: 2
|
|
1108
|
+
};
|
|
1109
|
+
var CHOMPING_MODE = {
|
|
1110
|
+
CLIP: 1,
|
|
1111
|
+
STRIP: 2,
|
|
1112
|
+
KEEP: 3
|
|
1113
|
+
};
|
|
1114
|
+
var NO_RANGE$3 = -1;
|
|
1115
|
+
function simpleEscapeSequence(c) {
|
|
1116
|
+
switch (c) {
|
|
1117
|
+
case 48:
|
|
1118
|
+
return "\x00";
|
|
1119
|
+
case 97:
|
|
1120
|
+
return "\x07";
|
|
1121
|
+
case 98:
|
|
1122
|
+
return "\b";
|
|
1123
|
+
case 116:
|
|
1124
|
+
return "\t";
|
|
1125
|
+
case 9:
|
|
1126
|
+
return "\t";
|
|
1127
|
+
case 110:
|
|
1128
|
+
return `
|
|
1129
|
+
`;
|
|
1130
|
+
case 118:
|
|
1131
|
+
return "\v";
|
|
1132
|
+
case 102:
|
|
1133
|
+
return "\f";
|
|
1134
|
+
case 114:
|
|
1135
|
+
return "\r";
|
|
1136
|
+
case 101:
|
|
1137
|
+
return "\x1B";
|
|
1138
|
+
case 32:
|
|
1139
|
+
return " ";
|
|
1140
|
+
case 34:
|
|
1141
|
+
return '"';
|
|
1142
|
+
case 47:
|
|
1143
|
+
return "/";
|
|
1144
|
+
case 92:
|
|
1145
|
+
return "\\";
|
|
1146
|
+
case 78:
|
|
1147
|
+
return "
";
|
|
1148
|
+
case 95:
|
|
1149
|
+
return " ";
|
|
1150
|
+
case 76:
|
|
1151
|
+
return "\u2028";
|
|
1152
|
+
case 80:
|
|
1153
|
+
return "\u2029";
|
|
1154
|
+
default:
|
|
1155
|
+
return "";
|
|
1156
|
+
}
|
|
1157
|
+
}
|
|
1158
|
+
var simpleEscapeCheck = new Array(256);
|
|
1159
|
+
var simpleEscapeMap = new Array(256);
|
|
1160
|
+
for (let i = 0;i < 256; i++) {
|
|
1161
|
+
simpleEscapeCheck[i] = simpleEscapeSequence(i) ? 1 : 0;
|
|
1162
|
+
simpleEscapeMap[i] = simpleEscapeSequence(i);
|
|
1163
|
+
}
|
|
1164
|
+
function charFromCodepoint(c) {
|
|
1165
|
+
if (c <= 65535)
|
|
1166
|
+
return String.fromCharCode(c);
|
|
1167
|
+
return String.fromCharCode((c - 65536 >> 10) + 55296, (c - 65536 & 1023) + 56320);
|
|
1168
|
+
}
|
|
1169
|
+
function fromHexCode$1(c) {
|
|
1170
|
+
if (c >= 48 && c <= 57)
|
|
1171
|
+
return c - 48;
|
|
1172
|
+
return (c | 32) - 97 + 10;
|
|
1173
|
+
}
|
|
1174
|
+
function escapedHexLen$1(c) {
|
|
1175
|
+
if (c === 120)
|
|
1176
|
+
return 2;
|
|
1177
|
+
if (c === 117)
|
|
1178
|
+
return 4;
|
|
1179
|
+
return 8;
|
|
1180
|
+
}
|
|
1181
|
+
function skipFoldedBreaks(input, position, end) {
|
|
1182
|
+
let breaks = 0;
|
|
1183
|
+
while (position < end) {
|
|
1184
|
+
const ch = input.charCodeAt(position);
|
|
1185
|
+
if (ch === 10) {
|
|
1186
|
+
breaks++;
|
|
1187
|
+
position++;
|
|
1188
|
+
} else if (ch === 13) {
|
|
1189
|
+
breaks++;
|
|
1190
|
+
position++;
|
|
1191
|
+
if (input.charCodeAt(position) === 10)
|
|
1192
|
+
position++;
|
|
1193
|
+
} else if (ch === 32 || ch === 9)
|
|
1194
|
+
position++;
|
|
1195
|
+
else
|
|
1196
|
+
break;
|
|
1197
|
+
}
|
|
1198
|
+
return {
|
|
1199
|
+
position,
|
|
1200
|
+
breaks
|
|
1201
|
+
};
|
|
1202
|
+
}
|
|
1203
|
+
function foldedBreaks(count) {
|
|
1204
|
+
if (count === 1)
|
|
1205
|
+
return " ";
|
|
1206
|
+
return `
|
|
1207
|
+
`.repeat(count - 1);
|
|
1208
|
+
}
|
|
1209
|
+
function getPlainValue(input, start, end) {
|
|
1210
|
+
let result = "";
|
|
1211
|
+
let position = start;
|
|
1212
|
+
let captureStart = start;
|
|
1213
|
+
let captureEnd = start;
|
|
1214
|
+
while (position < end) {
|
|
1215
|
+
const ch = input.charCodeAt(position);
|
|
1216
|
+
if (ch === 10 || ch === 13) {
|
|
1217
|
+
result += input.slice(captureStart, captureEnd);
|
|
1218
|
+
const fold = skipFoldedBreaks(input, position, end);
|
|
1219
|
+
result += foldedBreaks(fold.breaks);
|
|
1220
|
+
position = captureStart = captureEnd = fold.position;
|
|
1221
|
+
} else {
|
|
1222
|
+
position++;
|
|
1223
|
+
if (ch !== 32 && ch !== 9)
|
|
1224
|
+
captureEnd = position;
|
|
1225
|
+
}
|
|
1226
|
+
}
|
|
1227
|
+
return result + input.slice(captureStart, captureEnd);
|
|
1228
|
+
}
|
|
1229
|
+
function getSingleQuotedValue(input, start, end) {
|
|
1230
|
+
let result = "";
|
|
1231
|
+
let position = start;
|
|
1232
|
+
let captureStart = start;
|
|
1233
|
+
let captureEnd = start;
|
|
1234
|
+
while (position < end) {
|
|
1235
|
+
const ch = input.charCodeAt(position);
|
|
1236
|
+
if (ch === 39) {
|
|
1237
|
+
result += input.slice(captureStart, position) + "'";
|
|
1238
|
+
position += 2;
|
|
1239
|
+
captureStart = captureEnd = position;
|
|
1240
|
+
} else if (ch === 10 || ch === 13) {
|
|
1241
|
+
result += input.slice(captureStart, captureEnd);
|
|
1242
|
+
const fold = skipFoldedBreaks(input, position, end);
|
|
1243
|
+
result += foldedBreaks(fold.breaks);
|
|
1244
|
+
position = captureStart = captureEnd = fold.position;
|
|
1245
|
+
} else {
|
|
1246
|
+
position++;
|
|
1247
|
+
if (ch !== 32 && ch !== 9)
|
|
1248
|
+
captureEnd = position;
|
|
1249
|
+
}
|
|
1250
|
+
}
|
|
1251
|
+
return result + input.slice(captureStart, end);
|
|
1252
|
+
}
|
|
1253
|
+
function getDoubleQuotedValue(input, start, end) {
|
|
1254
|
+
let result = "";
|
|
1255
|
+
let position = start;
|
|
1256
|
+
let captureStart = start;
|
|
1257
|
+
let captureEnd = start;
|
|
1258
|
+
while (position < end) {
|
|
1259
|
+
const ch = input.charCodeAt(position);
|
|
1260
|
+
if (ch === 92) {
|
|
1261
|
+
result += input.slice(captureStart, position);
|
|
1262
|
+
position++;
|
|
1263
|
+
const escaped = input.charCodeAt(position);
|
|
1264
|
+
if (escaped === 10 || escaped === 13)
|
|
1265
|
+
position = skipFoldedBreaks(input, position, end).position;
|
|
1266
|
+
else if (escaped < 256 && simpleEscapeCheck[escaped]) {
|
|
1267
|
+
result += simpleEscapeMap[escaped];
|
|
1268
|
+
position++;
|
|
1269
|
+
} else {
|
|
1270
|
+
let hexLength = escapedHexLen$1(escaped);
|
|
1271
|
+
let hexResult = 0;
|
|
1272
|
+
for (;hexLength > 0; hexLength--) {
|
|
1273
|
+
position++;
|
|
1274
|
+
const digit = fromHexCode$1(input.charCodeAt(position));
|
|
1275
|
+
hexResult = (hexResult << 4) + digit;
|
|
1276
|
+
}
|
|
1277
|
+
result += charFromCodepoint(hexResult);
|
|
1278
|
+
position++;
|
|
1279
|
+
}
|
|
1280
|
+
captureStart = captureEnd = position;
|
|
1281
|
+
} else if (ch === 10 || ch === 13) {
|
|
1282
|
+
result += input.slice(captureStart, captureEnd);
|
|
1283
|
+
const fold = skipFoldedBreaks(input, position, end);
|
|
1284
|
+
result += foldedBreaks(fold.breaks);
|
|
1285
|
+
position = captureStart = captureEnd = fold.position;
|
|
1286
|
+
} else {
|
|
1287
|
+
position++;
|
|
1288
|
+
if (ch !== 32 && ch !== 9)
|
|
1289
|
+
captureEnd = position;
|
|
1290
|
+
}
|
|
1291
|
+
}
|
|
1292
|
+
return result + input.slice(captureStart, end);
|
|
1293
|
+
}
|
|
1294
|
+
function getBlockValue(input, start, end, indent, chomping, folded) {
|
|
1295
|
+
const textIndent = indent < 0 ? 0 : indent;
|
|
1296
|
+
const region = input.slice(start, end).replace(/\r\n?/g, `
|
|
1297
|
+
`);
|
|
1298
|
+
const lines = region === "" ? [] : (region.endsWith(`
|
|
1299
|
+
`) ? region.slice(0, -1) : region).split(`
|
|
1300
|
+
`);
|
|
1301
|
+
let result = "";
|
|
1302
|
+
let didReadContent = false;
|
|
1303
|
+
let emptyLines = 0;
|
|
1304
|
+
let atMoreIndented = false;
|
|
1305
|
+
for (const line of lines) {
|
|
1306
|
+
let column = 0;
|
|
1307
|
+
while (column < textIndent && line.charCodeAt(column) === 32)
|
|
1308
|
+
column++;
|
|
1309
|
+
if (indent < 0 || column >= line.length) {
|
|
1310
|
+
emptyLines++;
|
|
1311
|
+
continue;
|
|
1312
|
+
}
|
|
1313
|
+
const content = line.slice(textIndent);
|
|
1314
|
+
const first = content.charCodeAt(0);
|
|
1315
|
+
if (folded)
|
|
1316
|
+
if (first === 32 || first === 9) {
|
|
1317
|
+
atMoreIndented = true;
|
|
1318
|
+
result += `
|
|
1319
|
+
`.repeat(didReadContent ? 1 + emptyLines : emptyLines);
|
|
1320
|
+
} else if (atMoreIndented) {
|
|
1321
|
+
atMoreIndented = false;
|
|
1322
|
+
result += `
|
|
1323
|
+
`.repeat(emptyLines + 1);
|
|
1324
|
+
} else if (emptyLines === 0) {
|
|
1325
|
+
if (didReadContent)
|
|
1326
|
+
result += " ";
|
|
1327
|
+
} else
|
|
1328
|
+
result += `
|
|
1329
|
+
`.repeat(emptyLines);
|
|
1330
|
+
else
|
|
1331
|
+
result += `
|
|
1332
|
+
`.repeat(didReadContent ? 1 + emptyLines : emptyLines);
|
|
1333
|
+
result += content;
|
|
1334
|
+
didReadContent = true;
|
|
1335
|
+
emptyLines = 0;
|
|
1336
|
+
}
|
|
1337
|
+
if (chomping === CHOMPING_MODE.KEEP)
|
|
1338
|
+
result += `
|
|
1339
|
+
`.repeat(didReadContent ? 1 + emptyLines : emptyLines);
|
|
1340
|
+
else if (chomping !== CHOMPING_MODE.STRIP) {
|
|
1341
|
+
if (didReadContent)
|
|
1342
|
+
result += `
|
|
1343
|
+
`;
|
|
1344
|
+
}
|
|
1345
|
+
return result;
|
|
1346
|
+
}
|
|
1347
|
+
function getScalarValue(input, scalar) {
|
|
1348
|
+
if (scalar.valueStart === NO_RANGE$3)
|
|
1349
|
+
return "";
|
|
1350
|
+
const { valueStart, valueEnd } = scalar;
|
|
1351
|
+
if (scalar.fast)
|
|
1352
|
+
return input.slice(valueStart, valueEnd);
|
|
1353
|
+
switch (scalar.style) {
|
|
1354
|
+
case SCALAR_STYLE.SINGLE_QUOTED:
|
|
1355
|
+
return getSingleQuotedValue(input, valueStart, valueEnd);
|
|
1356
|
+
case SCALAR_STYLE.DOUBLE_QUOTED:
|
|
1357
|
+
return getDoubleQuotedValue(input, valueStart, valueEnd);
|
|
1358
|
+
case SCALAR_STYLE.LITERAL_BLOCK:
|
|
1359
|
+
return getBlockValue(input, valueStart, valueEnd, scalar.indent, scalar.chomping, false);
|
|
1360
|
+
case SCALAR_STYLE.FOLDED_BLOCK:
|
|
1361
|
+
return getBlockValue(input, valueStart, valueEnd, scalar.indent, scalar.chomping, true);
|
|
1362
|
+
default:
|
|
1363
|
+
return getPlainValue(input, valueStart, valueEnd);
|
|
1364
|
+
}
|
|
1365
|
+
}
|
|
1366
|
+
var DEFAULT_TAG_HANDLERS = Object.assign(Object.create(null), {
|
|
1367
|
+
"!": "!",
|
|
1368
|
+
"!!": "tag:yaml.org,2002:"
|
|
1369
|
+
});
|
|
1370
|
+
function tagPercentEncode(source) {
|
|
1371
|
+
return encodeURI(source).replace(/!/g, "%21");
|
|
1372
|
+
}
|
|
1373
|
+
function tagNameFull(rawTag, tagHandlers) {
|
|
1374
|
+
if (rawTag.startsWith("!<") && rawTag.endsWith(">"))
|
|
1375
|
+
return decodeURIComponent(rawTag.slice(2, -1));
|
|
1376
|
+
const handleEnd = rawTag.indexOf("!", 1);
|
|
1377
|
+
const handle = handleEnd === -1 ? "!" : rawTag.slice(0, handleEnd + 1);
|
|
1378
|
+
const prefix = tagHandlers?.[handle] ?? DEFAULT_TAG_HANDLERS[handle] ?? handle;
|
|
1379
|
+
return decodeURIComponent(prefix) + decodeURIComponent(rawTag.slice(handle.length));
|
|
1380
|
+
}
|
|
1381
|
+
function tagNameShort(fullTag) {
|
|
1382
|
+
let tag = fullTag;
|
|
1383
|
+
if (tag.charCodeAt(0) === 33) {
|
|
1384
|
+
tag = tag.slice(1);
|
|
1385
|
+
return `!${tagPercentEncode(tag)}`;
|
|
1386
|
+
}
|
|
1387
|
+
if (tag.slice(0, 18) === "tag:yaml.org,2002:")
|
|
1388
|
+
return `!!${tagPercentEncode(tag.slice(18))}`;
|
|
1389
|
+
return `!<${tagPercentEncode(tag)}>`;
|
|
1390
|
+
}
|
|
1391
|
+
var NO_RANGE$2 = -1;
|
|
1392
|
+
var MERGE_TAG_NAME = "tag:yaml.org,2002:merge";
|
|
1393
|
+
var DEFAULT_CONSTRUCTOR_OPTIONS = {
|
|
1394
|
+
filename: "",
|
|
1395
|
+
schema: CORE_SCHEMA,
|
|
1396
|
+
json: false,
|
|
1397
|
+
maxTotalMergeKeys: 1e4,
|
|
1398
|
+
maxAliases: -1
|
|
1399
|
+
};
|
|
1400
|
+
function eventPosition$1(event) {
|
|
1401
|
+
if ("tagStart" in event && event.tagStart !== NO_RANGE$2)
|
|
1402
|
+
return event.tagStart;
|
|
1403
|
+
if ("anchorStart" in event && event.anchorStart !== NO_RANGE$2)
|
|
1404
|
+
return event.anchorStart;
|
|
1405
|
+
if ("valueStart" in event && event.valueStart !== NO_RANGE$2)
|
|
1406
|
+
return event.valueStart;
|
|
1407
|
+
if ("start" in event)
|
|
1408
|
+
return event.start;
|
|
1409
|
+
return 0;
|
|
1410
|
+
}
|
|
1411
|
+
function throwError$1(state, message) {
|
|
1412
|
+
YAMLException.throwAt(state.source, state.position, message, state.filename);
|
|
1413
|
+
}
|
|
1414
|
+
function finalizeCollection(state, position, tag, carrier) {
|
|
1415
|
+
try {
|
|
1416
|
+
return tag.finalize(carrier);
|
|
1417
|
+
} catch (error) {
|
|
1418
|
+
if (error instanceof YAMLException)
|
|
1419
|
+
throw error;
|
|
1420
|
+
YAMLException.throwAt(state.source, position, error instanceof Error ? error.message : String(error), state.filename);
|
|
1421
|
+
}
|
|
1422
|
+
}
|
|
1423
|
+
function constructScalar(state, event) {
|
|
1424
|
+
const source = getScalarValue(state.source, event);
|
|
1425
|
+
const rawTag = event.tagStart === NO_RANGE$2 ? "" : state.source.slice(event.tagStart, event.tagEnd);
|
|
1426
|
+
const strTag2 = state.schema.defaultScalarTag;
|
|
1427
|
+
if (rawTag !== "") {
|
|
1428
|
+
if (rawTag === "!")
|
|
1429
|
+
return {
|
|
1430
|
+
value: source,
|
|
1431
|
+
tag: strTag2
|
|
1432
|
+
};
|
|
1433
|
+
const tagName = tagNameFull(rawTag, state.tagHandlers);
|
|
1434
|
+
const scalarTag = state.schema.lookupScalarTag(tagName);
|
|
1435
|
+
if (scalarTag) {
|
|
1436
|
+
const result = scalarTag.resolve(source, true, tagName);
|
|
1437
|
+
if (result === NOT_RESOLVED)
|
|
1438
|
+
throwError$1(state, `cannot resolve a node with !<${tagName}> explicit tag`);
|
|
1439
|
+
return {
|
|
1440
|
+
value: result,
|
|
1441
|
+
tag: scalarTag
|
|
1442
|
+
};
|
|
1443
|
+
}
|
|
1444
|
+
const collectionTagDef = state.schema.lookupMappingTag(tagName) ?? state.schema.lookupSequenceTag(tagName);
|
|
1445
|
+
if (collectionTagDef) {
|
|
1446
|
+
if (source !== "")
|
|
1447
|
+
throwError$1(state, `cannot resolve a node with !<${tagName}> explicit tag`);
|
|
1448
|
+
const carrier = collectionTagDef.create(tagName);
|
|
1449
|
+
return {
|
|
1450
|
+
value: collectionTagDef.carrierIsResult ? carrier : finalizeCollection(state, state.position, collectionTagDef, carrier),
|
|
1451
|
+
tag: collectionTagDef
|
|
1452
|
+
};
|
|
1453
|
+
}
|
|
1454
|
+
throwError$1(state, `unknown scalar tag !<${tagName}>`);
|
|
1455
|
+
}
|
|
1456
|
+
if (event.style === SCALAR_STYLE.PLAIN)
|
|
1457
|
+
return state.schema.resolveImplicitScalarTag(source);
|
|
1458
|
+
return {
|
|
1459
|
+
value: strTag2.resolve(source, false, strTag2.tagName),
|
|
1460
|
+
tag: strTag2
|
|
1461
|
+
};
|
|
1462
|
+
}
|
|
1463
|
+
function collectionTagName(state, event, defaultTagName) {
|
|
1464
|
+
const rawTag = event.tagStart === NO_RANGE$2 ? "" : state.source.slice(event.tagStart, event.tagEnd);
|
|
1465
|
+
return rawTag === "" || rawTag === "!" ? defaultTagName : tagNameFull(rawTag, state.tagHandlers);
|
|
1466
|
+
}
|
|
1467
|
+
function isMappingTag(tag) {
|
|
1468
|
+
return tag.nodeKind === "mapping";
|
|
1469
|
+
}
|
|
1470
|
+
function chargeMergeWork(state) {
|
|
1471
|
+
state.totalMergeKeys++;
|
|
1472
|
+
if (state.maxTotalMergeKeys !== -1 && state.totalMergeKeys > state.maxTotalMergeKeys)
|
|
1473
|
+
throwError$1(state, `merge keys exceeded maxTotalMergeKeys (${state.maxTotalMergeKeys})`);
|
|
1474
|
+
}
|
|
1475
|
+
function mergeKeys(state, frame, source, sourceTag) {
|
|
1476
|
+
chargeMergeWork(state);
|
|
1477
|
+
for (const sourceKey of sourceTag.keys(source)) {
|
|
1478
|
+
chargeMergeWork(state);
|
|
1479
|
+
if (frame.tag.has(frame.value, sourceKey))
|
|
1480
|
+
continue;
|
|
1481
|
+
const err = frame.tag.addPair(frame.value, sourceKey, sourceTag.get(source, sourceKey));
|
|
1482
|
+
if (err)
|
|
1483
|
+
throwError$1(state, err);
|
|
1484
|
+
frame.overridable ??= /* @__PURE__ */ new Set;
|
|
1485
|
+
frame.overridable.add(sourceKey);
|
|
1486
|
+
}
|
|
1487
|
+
}
|
|
1488
|
+
function mergeSource(state, frame, source, sourceTag) {
|
|
1489
|
+
state.position = frame.keyPosition;
|
|
1490
|
+
if (isMappingTag(sourceTag))
|
|
1491
|
+
mergeKeys(state, frame, source, sourceTag);
|
|
1492
|
+
else if (sourceTag.nodeKind === "sequence" && Array.isArray(source)) {
|
|
1493
|
+
if (source.length > 100)
|
|
1494
|
+
throwError$1(state, "abnormal merge sequence size");
|
|
1495
|
+
for (const element of source) {
|
|
1496
|
+
const elementTag = state.nodeTags.get(element);
|
|
1497
|
+
if (!elementTag)
|
|
1498
|
+
throwError$1(state, "cannot merge mappings; the provided source object is unacceptable");
|
|
1499
|
+
mergeKeys(state, frame, element, elementTag);
|
|
1500
|
+
}
|
|
1501
|
+
} else
|
|
1502
|
+
throwError$1(state, "cannot merge mappings; the provided source object is unacceptable");
|
|
1503
|
+
}
|
|
1504
|
+
function addMappingValue(state, frame, key, value, tag) {
|
|
1505
|
+
state.position = frame.keyPosition;
|
|
1506
|
+
if (frame.keyIsMerge) {
|
|
1507
|
+
mergeSource(state, frame, value, tag);
|
|
1508
|
+
return;
|
|
1509
|
+
}
|
|
1510
|
+
if (!state.json && frame.tag.has(frame.value, key) && !frame.overridable?.has(key))
|
|
1511
|
+
throwError$1(state, "duplicated mapping key");
|
|
1512
|
+
const err = frame.tag.addPair(frame.value, key, value);
|
|
1513
|
+
if (err)
|
|
1514
|
+
throwError$1(state, err);
|
|
1515
|
+
frame.overridable?.delete(key);
|
|
1516
|
+
}
|
|
1517
|
+
function addValue(state, value, tag) {
|
|
1518
|
+
const frame = state.frames[state.frames.length - 1];
|
|
1519
|
+
if (frame.kind === "document") {
|
|
1520
|
+
frame.value = value;
|
|
1521
|
+
frame.hasValue = true;
|
|
1522
|
+
} else if (frame.kind === "sequence") {
|
|
1523
|
+
if (isMappingTag(tag))
|
|
1524
|
+
state.nodeTags.set(value, tag);
|
|
1525
|
+
const err = frame.tag.addItem(frame.value, value, frame.index++);
|
|
1526
|
+
if (err)
|
|
1527
|
+
throwError$1(state, err);
|
|
1528
|
+
} else if (frame.hasKey) {
|
|
1529
|
+
const key = frame.key;
|
|
1530
|
+
frame.key = undefined;
|
|
1531
|
+
frame.hasKey = false;
|
|
1532
|
+
addMappingValue(state, frame, key, value, tag);
|
|
1533
|
+
} else {
|
|
1534
|
+
frame.key = value;
|
|
1535
|
+
frame.keyPosition = state.position;
|
|
1536
|
+
frame.hasKey = true;
|
|
1537
|
+
frame.keyIsMerge = tag.tagName === MERGE_TAG_NAME;
|
|
1538
|
+
}
|
|
1539
|
+
}
|
|
1540
|
+
function storeAnchor(state, event, value, tag, isValueFinal) {
|
|
1541
|
+
if (event.anchorStart !== NO_RANGE$2) {
|
|
1542
|
+
const anchor = {
|
|
1543
|
+
value,
|
|
1544
|
+
tag,
|
|
1545
|
+
isValueFinal
|
|
1546
|
+
};
|
|
1547
|
+
state.anchors.set(state.source.slice(event.anchorStart, event.anchorEnd), anchor);
|
|
1548
|
+
return anchor;
|
|
1549
|
+
}
|
|
1550
|
+
return null;
|
|
1551
|
+
}
|
|
1552
|
+
function constructFromEvents(events, options) {
|
|
1553
|
+
const state = {
|
|
1554
|
+
...DEFAULT_CONSTRUCTOR_OPTIONS,
|
|
1555
|
+
...options,
|
|
1556
|
+
events,
|
|
1557
|
+
documents: [],
|
|
1558
|
+
eventIndex: 0,
|
|
1559
|
+
position: 0,
|
|
1560
|
+
frames: [],
|
|
1561
|
+
anchors: /* @__PURE__ */ new Map,
|
|
1562
|
+
nodeTags: /* @__PURE__ */ new Map,
|
|
1563
|
+
tagHandlers: Object.create(null),
|
|
1564
|
+
totalMergeKeys: 0,
|
|
1565
|
+
aliasCount: 0
|
|
1566
|
+
};
|
|
1567
|
+
while (state.eventIndex < state.events.length) {
|
|
1568
|
+
const event = state.events[state.eventIndex++];
|
|
1569
|
+
state.position = eventPosition$1(event);
|
|
1570
|
+
switch (event.type) {
|
|
1571
|
+
case EVENT_ID.DOCUMENT:
|
|
1572
|
+
state.anchors = /* @__PURE__ */ new Map;
|
|
1573
|
+
state.nodeTags = /* @__PURE__ */ new Map;
|
|
1574
|
+
state.aliasCount = 0;
|
|
1575
|
+
state.tagHandlers = Object.create(null);
|
|
1576
|
+
for (const directive of event.directives)
|
|
1577
|
+
if (directive.kind === "tag")
|
|
1578
|
+
state.tagHandlers[directive.handle] = directive.prefix;
|
|
1579
|
+
state.frames.push({
|
|
1580
|
+
kind: "document",
|
|
1581
|
+
position: state.position,
|
|
1582
|
+
value: undefined,
|
|
1583
|
+
hasValue: false
|
|
1584
|
+
});
|
|
1585
|
+
break;
|
|
1586
|
+
case EVENT_ID.SCALAR: {
|
|
1587
|
+
const { value, tag } = constructScalar(state, event);
|
|
1588
|
+
storeAnchor(state, event, value, tag, true);
|
|
1589
|
+
addValue(state, value, tag);
|
|
1590
|
+
break;
|
|
1591
|
+
}
|
|
1592
|
+
case EVENT_ID.SEQUENCE: {
|
|
1593
|
+
const tagName = collectionTagName(state, event, "tag:yaml.org,2002:seq");
|
|
1594
|
+
const tag = state.schema.lookupSequenceTag(tagName);
|
|
1595
|
+
if (!tag)
|
|
1596
|
+
throwError$1(state, `unknown sequence tag !<${tagName}>`);
|
|
1597
|
+
const value = tag.create(tagName);
|
|
1598
|
+
const anchor = storeAnchor(state, event, value, tag, tag.carrierIsResult);
|
|
1599
|
+
state.frames.push({
|
|
1600
|
+
kind: "sequence",
|
|
1601
|
+
position: state.position,
|
|
1602
|
+
value,
|
|
1603
|
+
tag,
|
|
1604
|
+
anchor,
|
|
1605
|
+
index: 0
|
|
1606
|
+
});
|
|
1607
|
+
break;
|
|
1608
|
+
}
|
|
1609
|
+
case EVENT_ID.MAPPING: {
|
|
1610
|
+
const tagName = collectionTagName(state, event, "tag:yaml.org,2002:map");
|
|
1611
|
+
const tag = state.schema.lookupMappingTag(tagName);
|
|
1612
|
+
if (!tag)
|
|
1613
|
+
throwError$1(state, `unknown mapping tag !<${tagName}>`);
|
|
1614
|
+
const value = tag.create(tagName);
|
|
1615
|
+
const anchor = storeAnchor(state, event, value, tag, tag.carrierIsResult);
|
|
1616
|
+
state.frames.push({
|
|
1617
|
+
kind: "mapping",
|
|
1618
|
+
position: state.position,
|
|
1619
|
+
value,
|
|
1620
|
+
tag,
|
|
1621
|
+
anchor,
|
|
1622
|
+
key: undefined,
|
|
1623
|
+
keyPosition: state.position,
|
|
1624
|
+
hasKey: false,
|
|
1625
|
+
keyIsMerge: false,
|
|
1626
|
+
overridable: null
|
|
1627
|
+
});
|
|
1628
|
+
break;
|
|
1629
|
+
}
|
|
1630
|
+
case EVENT_ID.ALIAS: {
|
|
1631
|
+
if (state.maxAliases !== -1 && ++state.aliasCount > state.maxAliases)
|
|
1632
|
+
throwError$1(state, `aliases exceeded maxAliases (${state.maxAliases})`);
|
|
1633
|
+
const name = state.source.slice(event.anchorStart, event.anchorEnd);
|
|
1634
|
+
const anchor = state.anchors.get(name);
|
|
1635
|
+
if (!anchor)
|
|
1636
|
+
throwError$1(state, `unidentified alias "${name}"`);
|
|
1637
|
+
if (!anchor.isValueFinal)
|
|
1638
|
+
throwError$1(state, `recursive alias "${name}" is not supported for tag ${anchor.tag.tagName} because it uses finalize()`);
|
|
1639
|
+
addValue(state, anchor.value, anchor.tag);
|
|
1640
|
+
break;
|
|
1641
|
+
}
|
|
1642
|
+
case EVENT_ID.POP: {
|
|
1643
|
+
const frame = state.frames.pop();
|
|
1644
|
+
if (frame.kind === "mapping" && frame.hasKey) {
|
|
1645
|
+
state.position = frame.keyPosition;
|
|
1646
|
+
throwError$1(state, "incomplete mapping pair in event stream");
|
|
1647
|
+
}
|
|
1648
|
+
if (frame.kind === "document")
|
|
1649
|
+
state.documents.push(frame.value);
|
|
1650
|
+
else {
|
|
1651
|
+
const value = frame.tag.carrierIsResult ? frame.value : finalizeCollection(state, frame.position, frame.tag, frame.value);
|
|
1652
|
+
if (frame.anchor) {
|
|
1653
|
+
frame.anchor.value = value;
|
|
1654
|
+
frame.anchor.isValueFinal = true;
|
|
1655
|
+
}
|
|
1656
|
+
addValue(state, value, frame.tag);
|
|
1657
|
+
}
|
|
1658
|
+
break;
|
|
1659
|
+
}
|
|
1660
|
+
}
|
|
1661
|
+
}
|
|
1662
|
+
return state.documents;
|
|
1663
|
+
}
|
|
1664
|
+
var NO_RANGE$1 = -1;
|
|
1665
|
+
var HAS_OWN = Object.prototype.hasOwnProperty;
|
|
1666
|
+
var CONTEXT_FLOW_IN = 1;
|
|
1667
|
+
var CONTEXT_FLOW_OUT = 2;
|
|
1668
|
+
var CONTEXT_BLOCK_IN = 3;
|
|
1669
|
+
var CONTEXT_BLOCK_OUT = 4;
|
|
1670
|
+
var PATTERN_NON_PRINTABLE = /[\x00-\x08\x0B\x0C\x0E-\x1F\x7F-\x84\x86-\x9F\uFFFE\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]/;
|
|
1671
|
+
var PATTERN_FLOW_INDICATORS = /[,\[\]{}]/;
|
|
1672
|
+
var PATTERN_TAG_HANDLE = /^(?:!|!!|![0-9A-Za-z-]+!)$/;
|
|
1673
|
+
var NS_URI_CHAR = String.raw`(?:%[0-9A-Fa-f]{2}|[0-9A-Za-z\-#;/?:@&=+$,_.!~*'()\[\]])`;
|
|
1674
|
+
var NS_TAG_CHAR = String.raw`(?:%[0-9A-Fa-f]{2}|[0-9A-Za-z\-#;/?:@&=+$.~*'()_])`;
|
|
1675
|
+
var PATTERN_TAG_URI = new RegExp(`^(?:${NS_URI_CHAR})*$`);
|
|
1676
|
+
var PATTERN_TAG_SUFFIX = new RegExp(`^(?:${NS_TAG_CHAR})+$`);
|
|
1677
|
+
var PATTERN_TAG_PREFIX = new RegExp(`^(?:!(?:${NS_URI_CHAR})*|${NS_TAG_CHAR}(?:${NS_URI_CHAR})*)$`);
|
|
1678
|
+
var DEFAULT_PARSER_OPTIONS = {
|
|
1679
|
+
filename: "",
|
|
1680
|
+
maxDepth: 100
|
|
1681
|
+
};
|
|
1682
|
+
function addDocumentEvent(state, explicitStart, explicitEnd) {
|
|
1683
|
+
state.events.push({
|
|
1684
|
+
type: EVENT_ID.DOCUMENT,
|
|
1685
|
+
explicitStart,
|
|
1686
|
+
explicitEnd,
|
|
1687
|
+
directives: state.directives
|
|
1688
|
+
});
|
|
1689
|
+
}
|
|
1690
|
+
function addSequenceEvent(state, start, anchorStart, anchorEnd, tagStart, tagEnd, style) {
|
|
1691
|
+
state.events.push({
|
|
1692
|
+
type: EVENT_ID.SEQUENCE,
|
|
1693
|
+
start,
|
|
1694
|
+
anchorStart,
|
|
1695
|
+
anchorEnd,
|
|
1696
|
+
tagStart,
|
|
1697
|
+
tagEnd,
|
|
1698
|
+
style
|
|
1699
|
+
});
|
|
1700
|
+
}
|
|
1701
|
+
function addMappingEvent(state, start, anchorStart, anchorEnd, tagStart, tagEnd, style) {
|
|
1702
|
+
state.events.push({
|
|
1703
|
+
type: EVENT_ID.MAPPING,
|
|
1704
|
+
start,
|
|
1705
|
+
anchorStart,
|
|
1706
|
+
anchorEnd,
|
|
1707
|
+
tagStart,
|
|
1708
|
+
tagEnd,
|
|
1709
|
+
style
|
|
1710
|
+
});
|
|
1711
|
+
}
|
|
1712
|
+
function insertFlowPairMappingEvent(state, snapshot) {
|
|
1713
|
+
state.events.splice(snapshot.eventsLength, 0, {
|
|
1714
|
+
type: EVENT_ID.MAPPING,
|
|
1715
|
+
start: snapshot.position,
|
|
1716
|
+
anchorStart: NO_RANGE$1,
|
|
1717
|
+
anchorEnd: NO_RANGE$1,
|
|
1718
|
+
tagStart: NO_RANGE$1,
|
|
1719
|
+
tagEnd: NO_RANGE$1,
|
|
1720
|
+
style: COLLECTION_STYLE.FLOW
|
|
1721
|
+
});
|
|
1722
|
+
}
|
|
1723
|
+
function addScalarEvent(state, valueStart, valueEnd, anchorStart, anchorEnd, tagStart, tagEnd, style, chomping = CHOMPING_MODE.CLIP, indent = -1, fast = false) {
|
|
1724
|
+
state.events.push({
|
|
1725
|
+
type: EVENT_ID.SCALAR,
|
|
1726
|
+
valueStart,
|
|
1727
|
+
valueEnd,
|
|
1728
|
+
anchorStart,
|
|
1729
|
+
anchorEnd,
|
|
1730
|
+
tagStart,
|
|
1731
|
+
tagEnd,
|
|
1732
|
+
style,
|
|
1733
|
+
chomping,
|
|
1734
|
+
indent,
|
|
1735
|
+
fast
|
|
1736
|
+
});
|
|
1737
|
+
}
|
|
1738
|
+
function addAliasEvent(state, anchorStart, anchorEnd) {
|
|
1739
|
+
state.events.push({
|
|
1740
|
+
type: EVENT_ID.ALIAS,
|
|
1741
|
+
anchorStart,
|
|
1742
|
+
anchorEnd
|
|
1743
|
+
});
|
|
1744
|
+
}
|
|
1745
|
+
function addPopEvent(state) {
|
|
1746
|
+
state.events.push({ type: EVENT_ID.POP });
|
|
1747
|
+
}
|
|
1748
|
+
function addEmptyScalarEvent(state) {
|
|
1749
|
+
addScalarEvent(state, NO_RANGE$1, NO_RANGE$1, NO_RANGE$1, NO_RANGE$1, NO_RANGE$1, NO_RANGE$1, SCALAR_STYLE.PLAIN);
|
|
1750
|
+
}
|
|
1751
|
+
function emptyProperties() {
|
|
1752
|
+
return {
|
|
1753
|
+
anchorStart: NO_RANGE$1,
|
|
1754
|
+
anchorEnd: NO_RANGE$1,
|
|
1755
|
+
tagStart: NO_RANGE$1,
|
|
1756
|
+
tagEnd: NO_RANGE$1
|
|
1757
|
+
};
|
|
1758
|
+
}
|
|
1759
|
+
function snapshotState(state) {
|
|
1760
|
+
return {
|
|
1761
|
+
position: state.position,
|
|
1762
|
+
line: state.line,
|
|
1763
|
+
lineStart: state.lineStart,
|
|
1764
|
+
lineIndent: state.lineIndent,
|
|
1765
|
+
firstTabInLine: state.firstTabInLine,
|
|
1766
|
+
eventsLength: state.events.length
|
|
1767
|
+
};
|
|
1768
|
+
}
|
|
1769
|
+
function restoreState(state, snapshot) {
|
|
1770
|
+
state.position = snapshot.position;
|
|
1771
|
+
state.line = snapshot.line;
|
|
1772
|
+
state.lineStart = snapshot.lineStart;
|
|
1773
|
+
state.lineIndent = snapshot.lineIndent;
|
|
1774
|
+
state.firstTabInLine = snapshot.firstTabInLine;
|
|
1775
|
+
state.events.length = snapshot.eventsLength;
|
|
1776
|
+
}
|
|
1777
|
+
function throwError(state, message) {
|
|
1778
|
+
YAMLException.throwAt(state.input.slice(0, state.length), state.position, message, state.filename);
|
|
1779
|
+
}
|
|
1780
|
+
function isEol(c) {
|
|
1781
|
+
return c === 10 || c === 13;
|
|
1782
|
+
}
|
|
1783
|
+
function isWhiteSpace(c) {
|
|
1784
|
+
return c === 9 || c === 32;
|
|
1785
|
+
}
|
|
1786
|
+
function isWsOrEol(c) {
|
|
1787
|
+
return isWhiteSpace(c) || isEol(c);
|
|
1788
|
+
}
|
|
1789
|
+
function isWsOrEolOrEnd(c) {
|
|
1790
|
+
return c === 0 || isWsOrEol(c);
|
|
1791
|
+
}
|
|
1792
|
+
function isFlowIndicator(c) {
|
|
1793
|
+
return c === 44 || c === 91 || c === 93 || c === 123 || c === 125;
|
|
1794
|
+
}
|
|
1795
|
+
function fromDecimalCode(c) {
|
|
1796
|
+
return c >= 48 && c <= 57 ? c - 48 : -1;
|
|
1797
|
+
}
|
|
1798
|
+
function fromHexCode(c) {
|
|
1799
|
+
if (c >= 48 && c <= 57)
|
|
1800
|
+
return c - 48;
|
|
1801
|
+
const lc = c | 32;
|
|
1802
|
+
if (lc >= 97 && lc <= 102)
|
|
1803
|
+
return lc - 97 + 10;
|
|
1804
|
+
return -1;
|
|
1805
|
+
}
|
|
1806
|
+
function escapedHexLen(c) {
|
|
1807
|
+
if (c === 120)
|
|
1808
|
+
return 2;
|
|
1809
|
+
if (c === 117)
|
|
1810
|
+
return 4;
|
|
1811
|
+
if (c === 85)
|
|
1812
|
+
return 8;
|
|
1813
|
+
return 0;
|
|
1814
|
+
}
|
|
1815
|
+
function isSimpleEscape(c) {
|
|
1816
|
+
return c === 48 || c === 97 || c === 98 || c === 116 || c === 9 || c === 110 || c === 118 || c === 102 || c === 114 || c === 101 || c === 32 || c === 34 || c === 47 || c === 92 || c === 78 || c === 95 || c === 76 || c === 80;
|
|
1817
|
+
}
|
|
1818
|
+
function consumeLineBreak(state) {
|
|
1819
|
+
if (state.input.charCodeAt(state.position) === 10)
|
|
1820
|
+
state.position++;
|
|
1821
|
+
else {
|
|
1822
|
+
state.position++;
|
|
1823
|
+
if (state.input.charCodeAt(state.position) === 10)
|
|
1824
|
+
state.position++;
|
|
1825
|
+
}
|
|
1826
|
+
state.line++;
|
|
1827
|
+
state.lineStart = state.position;
|
|
1828
|
+
state.lineIndent = 0;
|
|
1829
|
+
state.firstTabInLine = -1;
|
|
1830
|
+
}
|
|
1831
|
+
function skipSeparationSpace(state, allowComments) {
|
|
1832
|
+
let lineBreaks = 0;
|
|
1833
|
+
let ch = state.input.charCodeAt(state.position);
|
|
1834
|
+
let hasSeparation = state.position === state.lineStart || isWsOrEol(state.input.charCodeAt(state.position - 1));
|
|
1835
|
+
while (ch !== 0) {
|
|
1836
|
+
while (isWhiteSpace(ch)) {
|
|
1837
|
+
hasSeparation = true;
|
|
1838
|
+
if (ch === 9 && state.firstTabInLine === -1)
|
|
1839
|
+
state.firstTabInLine = state.position;
|
|
1840
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1841
|
+
}
|
|
1842
|
+
if (allowComments && hasSeparation && ch === 35)
|
|
1843
|
+
do
|
|
1844
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1845
|
+
while (!isEol(ch) && ch !== 0);
|
|
1846
|
+
if (!isEol(ch))
|
|
1847
|
+
break;
|
|
1848
|
+
consumeLineBreak(state);
|
|
1849
|
+
lineBreaks++;
|
|
1850
|
+
hasSeparation = true;
|
|
1851
|
+
ch = state.input.charCodeAt(state.position);
|
|
1852
|
+
while (ch === 32) {
|
|
1853
|
+
state.lineIndent++;
|
|
1854
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1855
|
+
}
|
|
1856
|
+
}
|
|
1857
|
+
return lineBreaks;
|
|
1858
|
+
}
|
|
1859
|
+
function testDocumentSeparator(state, position = state.position) {
|
|
1860
|
+
const ch = state.input.charCodeAt(position);
|
|
1861
|
+
if ((ch === 45 || ch === 46) && ch === state.input.charCodeAt(position + 1) && ch === state.input.charCodeAt(position + 2)) {
|
|
1862
|
+
const following = state.input.charCodeAt(position + 3);
|
|
1863
|
+
return following === 0 || isWsOrEol(following);
|
|
1864
|
+
}
|
|
1865
|
+
return false;
|
|
1866
|
+
}
|
|
1867
|
+
function skipByteOrderMark(state) {
|
|
1868
|
+
if (state.position === state.lineStart && state.input.charCodeAt(state.position) === 65279) {
|
|
1869
|
+
state.position++;
|
|
1870
|
+
state.lineStart = state.position;
|
|
1871
|
+
}
|
|
1872
|
+
}
|
|
1873
|
+
function testDocumentBoundary(state) {
|
|
1874
|
+
if (state.position !== state.lineStart)
|
|
1875
|
+
return false;
|
|
1876
|
+
if (testDocumentSeparator(state))
|
|
1877
|
+
return true;
|
|
1878
|
+
if (state.input.charCodeAt(state.position) !== 65279)
|
|
1879
|
+
return false;
|
|
1880
|
+
const snapshot = snapshotState(state);
|
|
1881
|
+
skipByteOrderMark(state);
|
|
1882
|
+
skipSeparationSpace(state, true);
|
|
1883
|
+
const ch = state.input.charCodeAt(state.position);
|
|
1884
|
+
const result = state.position === state.lineStart && (ch === 37 || ch === 45 && testDocumentSeparator(state));
|
|
1885
|
+
restoreState(state, snapshot);
|
|
1886
|
+
return result;
|
|
1887
|
+
}
|
|
1888
|
+
function skipUntilLineEnd(state) {
|
|
1889
|
+
let ch = state.input.charCodeAt(state.position);
|
|
1890
|
+
while (ch !== 0 && !isEol(ch))
|
|
1891
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1892
|
+
}
|
|
1893
|
+
function checkPrintable(state, start, end) {
|
|
1894
|
+
if (PATTERN_NON_PRINTABLE.test(state.input.slice(start, end)))
|
|
1895
|
+
throwError(state, "the stream contains non-printable characters");
|
|
1896
|
+
}
|
|
1897
|
+
function readTagProperty(state, props, inFlow) {
|
|
1898
|
+
if (state.input.charCodeAt(state.position) !== 33)
|
|
1899
|
+
return false;
|
|
1900
|
+
if (props.tagStart !== NO_RANGE$1)
|
|
1901
|
+
throwError(state, "duplication of a tag property");
|
|
1902
|
+
const start = state.position;
|
|
1903
|
+
let isVerbatim = false;
|
|
1904
|
+
let isNamed = false;
|
|
1905
|
+
let tagHandle = "!";
|
|
1906
|
+
let ch = state.input.charCodeAt(++state.position);
|
|
1907
|
+
if (ch === 60) {
|
|
1908
|
+
isVerbatim = true;
|
|
1909
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1910
|
+
} else if (ch === 33) {
|
|
1911
|
+
isNamed = true;
|
|
1912
|
+
tagHandle = "!!";
|
|
1913
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1914
|
+
}
|
|
1915
|
+
let suffixStart = state.position;
|
|
1916
|
+
let tagName;
|
|
1917
|
+
if (isVerbatim) {
|
|
1918
|
+
while (ch !== 0 && ch !== 62)
|
|
1919
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1920
|
+
if (ch !== 62)
|
|
1921
|
+
throwError(state, "unexpected end of the stream within a verbatim tag");
|
|
1922
|
+
tagName = state.input.slice(suffixStart, state.position);
|
|
1923
|
+
state.position++;
|
|
1924
|
+
} else {
|
|
1925
|
+
while (ch !== 0 && !isWsOrEol(ch) && !(inFlow && isFlowIndicator(ch))) {
|
|
1926
|
+
if (ch === 33)
|
|
1927
|
+
if (!isNamed) {
|
|
1928
|
+
tagHandle = state.input.slice(suffixStart - 1, state.position + 1);
|
|
1929
|
+
if (!PATTERN_TAG_HANDLE.test(tagHandle))
|
|
1930
|
+
throwError(state, "named tag handle cannot contain such characters");
|
|
1931
|
+
isNamed = true;
|
|
1932
|
+
suffixStart = state.position + 1;
|
|
1933
|
+
} else
|
|
1934
|
+
throwError(state, "tag suffix cannot contain exclamation marks");
|
|
1935
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1936
|
+
}
|
|
1937
|
+
tagName = state.input.slice(suffixStart, state.position);
|
|
1938
|
+
if (PATTERN_FLOW_INDICATORS.test(tagName))
|
|
1939
|
+
throwError(state, "tag suffix cannot contain flow indicator characters");
|
|
1940
|
+
}
|
|
1941
|
+
if (tagName && !(isVerbatim ? PATTERN_TAG_URI.test(tagName) : PATTERN_TAG_SUFFIX.test(tagName)))
|
|
1942
|
+
throwError(state, `tag name cannot contain such characters: ${tagName}`);
|
|
1943
|
+
if (!isVerbatim && tagHandle !== "!" && tagHandle !== "!!" && !HAS_OWN.call(state.tagHandlers, tagHandle))
|
|
1944
|
+
throwError(state, `undeclared tag handle "${tagHandle}"`);
|
|
1945
|
+
props.tagStart = start;
|
|
1946
|
+
props.tagEnd = state.position;
|
|
1947
|
+
return true;
|
|
1948
|
+
}
|
|
1949
|
+
function readAnchorProperty(state, props) {
|
|
1950
|
+
if (state.input.charCodeAt(state.position) !== 38)
|
|
1951
|
+
return false;
|
|
1952
|
+
if (props.anchorStart !== NO_RANGE$1)
|
|
1953
|
+
throwError(state, "duplication of an anchor property");
|
|
1954
|
+
state.position++;
|
|
1955
|
+
const start = state.position;
|
|
1956
|
+
while (state.input.charCodeAt(state.position) !== 0 && !isWsOrEol(state.input.charCodeAt(state.position)) && !isFlowIndicator(state.input.charCodeAt(state.position)))
|
|
1957
|
+
state.position++;
|
|
1958
|
+
if (state.position === start)
|
|
1959
|
+
throwError(state, "name of an anchor node must contain at least one character");
|
|
1960
|
+
props.anchorStart = start;
|
|
1961
|
+
props.anchorEnd = state.position;
|
|
1962
|
+
return true;
|
|
1963
|
+
}
|
|
1964
|
+
function readAlias(state, props) {
|
|
1965
|
+
if (state.input.charCodeAt(state.position) !== 42)
|
|
1966
|
+
return false;
|
|
1967
|
+
if (props.anchorStart !== NO_RANGE$1 || props.tagStart !== NO_RANGE$1)
|
|
1968
|
+
throwError(state, "alias node should not have any properties");
|
|
1969
|
+
state.position++;
|
|
1970
|
+
const start = state.position;
|
|
1971
|
+
while (state.input.charCodeAt(state.position) !== 0 && !isWsOrEol(state.input.charCodeAt(state.position)) && !isFlowIndicator(state.input.charCodeAt(state.position)))
|
|
1972
|
+
state.position++;
|
|
1973
|
+
if (state.position === start)
|
|
1974
|
+
throwError(state, "name of an alias node must contain at least one character");
|
|
1975
|
+
addAliasEvent(state, start, state.position);
|
|
1976
|
+
return true;
|
|
1977
|
+
}
|
|
1978
|
+
function readFlowScalarBreak(state, nodeIndent) {
|
|
1979
|
+
skipSeparationSpace(state, false);
|
|
1980
|
+
if (state.lineIndent < nodeIndent)
|
|
1981
|
+
throwError(state, "deficient indentation");
|
|
1982
|
+
}
|
|
1983
|
+
function readSingleQuotedScalar(state, nodeIndent, props) {
|
|
1984
|
+
if (state.input.charCodeAt(state.position) !== 39)
|
|
1985
|
+
return false;
|
|
1986
|
+
state.position++;
|
|
1987
|
+
const start = state.position;
|
|
1988
|
+
let simple = true;
|
|
1989
|
+
while (state.input.charCodeAt(state.position) !== 0) {
|
|
1990
|
+
const ch = state.input.charCodeAt(state.position);
|
|
1991
|
+
if (ch === 39) {
|
|
1992
|
+
if (state.input.charCodeAt(state.position + 1) === 39) {
|
|
1993
|
+
simple = false;
|
|
1994
|
+
state.position += 2;
|
|
1995
|
+
continue;
|
|
1996
|
+
}
|
|
1997
|
+
const end = state.position;
|
|
1998
|
+
state.position++;
|
|
1999
|
+
addScalarEvent(state, start, end, props.anchorStart, props.anchorEnd, props.tagStart, props.tagEnd, SCALAR_STYLE.SINGLE_QUOTED, CHOMPING_MODE.CLIP, -1, simple);
|
|
2000
|
+
return true;
|
|
2001
|
+
}
|
|
2002
|
+
if (isEol(ch)) {
|
|
2003
|
+
simple = false;
|
|
2004
|
+
readFlowScalarBreak(state, nodeIndent);
|
|
2005
|
+
} else if (state.position === state.lineStart && testDocumentSeparator(state))
|
|
2006
|
+
throwError(state, "unexpected end of the document within a single quoted scalar");
|
|
2007
|
+
else if (ch !== 9 && ch < 32)
|
|
2008
|
+
throwError(state, "expected valid JSON character");
|
|
2009
|
+
else
|
|
2010
|
+
state.position++;
|
|
2011
|
+
}
|
|
2012
|
+
throwError(state, "unexpected end of the stream within a single quoted scalar");
|
|
2013
|
+
}
|
|
2014
|
+
function readDoubleQuotedScalar(state, nodeIndent, props) {
|
|
2015
|
+
if (state.input.charCodeAt(state.position) !== 34)
|
|
2016
|
+
return false;
|
|
2017
|
+
state.position++;
|
|
2018
|
+
const start = state.position;
|
|
2019
|
+
let simple = true;
|
|
2020
|
+
while (state.input.charCodeAt(state.position) !== 0) {
|
|
2021
|
+
const ch = state.input.charCodeAt(state.position);
|
|
2022
|
+
if (ch === 34) {
|
|
2023
|
+
const end = state.position;
|
|
2024
|
+
state.position++;
|
|
2025
|
+
addScalarEvent(state, start, end, props.anchorStart, props.anchorEnd, props.tagStart, props.tagEnd, SCALAR_STYLE.DOUBLE_QUOTED, CHOMPING_MODE.CLIP, -1, simple);
|
|
2026
|
+
return true;
|
|
2027
|
+
}
|
|
2028
|
+
if (ch === 92) {
|
|
2029
|
+
simple = false;
|
|
2030
|
+
const escaped = state.input.charCodeAt(++state.position);
|
|
2031
|
+
if (isEol(escaped))
|
|
2032
|
+
readFlowScalarBreak(state, nodeIndent);
|
|
2033
|
+
else if (isSimpleEscape(escaped))
|
|
2034
|
+
state.position++;
|
|
2035
|
+
else {
|
|
2036
|
+
let hexLength = escapedHexLen(escaped);
|
|
2037
|
+
if (hexLength === 0)
|
|
2038
|
+
throwError(state, "unknown escape sequence");
|
|
2039
|
+
while (hexLength-- > 0) {
|
|
2040
|
+
state.position++;
|
|
2041
|
+
if (fromHexCode(state.input.charCodeAt(state.position)) < 0)
|
|
2042
|
+
throwError(state, "expected hexadecimal character");
|
|
2043
|
+
}
|
|
2044
|
+
state.position++;
|
|
2045
|
+
}
|
|
2046
|
+
} else if (isEol(ch)) {
|
|
2047
|
+
simple = false;
|
|
2048
|
+
readFlowScalarBreak(state, nodeIndent);
|
|
2049
|
+
} else if (state.position === state.lineStart && testDocumentSeparator(state))
|
|
2050
|
+
throwError(state, "unexpected end of the document within a double quoted scalar");
|
|
2051
|
+
else if (ch !== 9 && ch < 32)
|
|
2052
|
+
throwError(state, "expected valid JSON character");
|
|
2053
|
+
else
|
|
2054
|
+
state.position++;
|
|
2055
|
+
}
|
|
2056
|
+
throwError(state, "unexpected end of the stream within a double quoted scalar");
|
|
2057
|
+
}
|
|
2058
|
+
function readBlockScalar(state, parentIndent, props) {
|
|
2059
|
+
const ch = state.input.charCodeAt(state.position);
|
|
2060
|
+
let chomping = CHOMPING_MODE.CLIP;
|
|
2061
|
+
let indent = -1;
|
|
2062
|
+
let detectedIndent = false;
|
|
2063
|
+
if (ch !== 124 && ch !== 62)
|
|
2064
|
+
return false;
|
|
2065
|
+
const style = ch === 124 ? SCALAR_STYLE.LITERAL_BLOCK : SCALAR_STYLE.FOLDED_BLOCK;
|
|
2066
|
+
state.position++;
|
|
2067
|
+
while (state.input.charCodeAt(state.position) !== 0) {
|
|
2068
|
+
const current = state.input.charCodeAt(state.position);
|
|
2069
|
+
const digit = fromDecimalCode(current);
|
|
2070
|
+
if (current === 43 || current === 45) {
|
|
2071
|
+
if (chomping !== CHOMPING_MODE.CLIP)
|
|
2072
|
+
throwError(state, "repeat of a chomping mode identifier");
|
|
2073
|
+
chomping = current === 43 ? CHOMPING_MODE.KEEP : CHOMPING_MODE.STRIP;
|
|
2074
|
+
state.position++;
|
|
2075
|
+
} else if (digit >= 0) {
|
|
2076
|
+
if (digit === 0)
|
|
2077
|
+
throwError(state, "bad explicit indentation width of a block scalar; it cannot be less than one");
|
|
2078
|
+
if (detectedIndent)
|
|
2079
|
+
throwError(state, "repeat of an indentation width identifier");
|
|
2080
|
+
indent = parentIndent + digit - 1;
|
|
2081
|
+
detectedIndent = true;
|
|
2082
|
+
state.position++;
|
|
2083
|
+
} else
|
|
2084
|
+
break;
|
|
2085
|
+
}
|
|
2086
|
+
let hadWhitespace = false;
|
|
2087
|
+
while (isWhiteSpace(state.input.charCodeAt(state.position))) {
|
|
2088
|
+
hadWhitespace = true;
|
|
2089
|
+
state.position++;
|
|
2090
|
+
}
|
|
2091
|
+
if (hadWhitespace && state.input.charCodeAt(state.position) === 35)
|
|
2092
|
+
skipUntilLineEnd(state);
|
|
2093
|
+
if (isEol(state.input.charCodeAt(state.position)))
|
|
2094
|
+
consumeLineBreak(state);
|
|
2095
|
+
else if (state.input.charCodeAt(state.position) !== 0)
|
|
2096
|
+
throwError(state, "a line break is expected");
|
|
2097
|
+
let contentIndent = detectedIndent ? indent : -1;
|
|
2098
|
+
let maxLeadingIndent = 0;
|
|
2099
|
+
const valueStart = state.position;
|
|
2100
|
+
let valueEnd = state.position;
|
|
2101
|
+
while (state.input.charCodeAt(state.position) !== 0) {
|
|
2102
|
+
const linePosition = state.position;
|
|
2103
|
+
let column = 0;
|
|
2104
|
+
while (state.input.charCodeAt(linePosition + column) === 32)
|
|
2105
|
+
column++;
|
|
2106
|
+
const first = state.input.charCodeAt(linePosition + column);
|
|
2107
|
+
if (first === 0) {
|
|
2108
|
+
if (contentIndent >= 0) {
|
|
2109
|
+
if (column > contentIndent)
|
|
2110
|
+
valueEnd = linePosition + column;
|
|
2111
|
+
} else if (column > 0)
|
|
2112
|
+
valueEnd = linePosition + column;
|
|
2113
|
+
break;
|
|
2114
|
+
}
|
|
2115
|
+
if (testDocumentBoundary(state))
|
|
2116
|
+
break;
|
|
2117
|
+
if (!detectedIndent && contentIndent === -1 && isEol(first))
|
|
2118
|
+
maxLeadingIndent = Math.max(maxLeadingIndent, column);
|
|
2119
|
+
if (!detectedIndent && contentIndent === -1 && !isEol(first)) {
|
|
2120
|
+
if (first === 9 && column < parentIndent) {
|
|
2121
|
+
state.position = linePosition + column;
|
|
2122
|
+
throwError(state, "tab characters must not be used in indentation");
|
|
2123
|
+
}
|
|
2124
|
+
if (column >= parentIndent && column < maxLeadingIndent) {
|
|
2125
|
+
state.position = linePosition + column;
|
|
2126
|
+
throwError(state, "bad indentation of a mapping entry");
|
|
2127
|
+
}
|
|
2128
|
+
}
|
|
2129
|
+
if (contentIndent === -1 && first !== 0 && !isEol(first) && column < parentIndent) {
|
|
2130
|
+
state.lineIndent = column;
|
|
2131
|
+
state.position = linePosition + column;
|
|
2132
|
+
break;
|
|
2133
|
+
}
|
|
2134
|
+
if (!detectedIndent && first !== 0 && !isEol(first) && contentIndent === -1)
|
|
2135
|
+
contentIndent = column;
|
|
2136
|
+
const requiredIndent = contentIndent === -1 ? parentIndent + 1 : contentIndent;
|
|
2137
|
+
if (first !== 0 && !isEol(first) && column < requiredIndent) {
|
|
2138
|
+
state.lineIndent = column;
|
|
2139
|
+
state.position = linePosition + column;
|
|
2140
|
+
break;
|
|
2141
|
+
}
|
|
2142
|
+
skipUntilLineEnd(state);
|
|
2143
|
+
valueEnd = state.position;
|
|
2144
|
+
if (isEol(state.input.charCodeAt(state.position))) {
|
|
2145
|
+
consumeLineBreak(state);
|
|
2146
|
+
valueEnd = state.position;
|
|
2147
|
+
}
|
|
2148
|
+
}
|
|
2149
|
+
checkPrintable(state, valueStart, valueEnd);
|
|
2150
|
+
addScalarEvent(state, valueStart, valueEnd, props.anchorStart, props.anchorEnd, props.tagStart, props.tagEnd, style, chomping, contentIndent);
|
|
2151
|
+
return true;
|
|
2152
|
+
}
|
|
2153
|
+
function canStartPlainScalar(state, nodeContext) {
|
|
2154
|
+
const ch = state.input.charCodeAt(state.position);
|
|
2155
|
+
const inFlow = nodeContext === CONTEXT_FLOW_IN;
|
|
2156
|
+
if (ch === 0 || isWsOrEol(ch) || ch === 35 || ch === 38 || ch === 42 || ch === 33 || ch === 124 || ch === 62 || ch === 39 || ch === 34 || ch === 37 || ch === 64 || ch === 96 || inFlow && isFlowIndicator(ch))
|
|
2157
|
+
return false;
|
|
2158
|
+
if (ch === 63 || ch === 45) {
|
|
2159
|
+
const following = state.input.charCodeAt(state.position + 1);
|
|
2160
|
+
if (isWsOrEolOrEnd(following) || inFlow && isFlowIndicator(following))
|
|
2161
|
+
return false;
|
|
2162
|
+
}
|
|
2163
|
+
return true;
|
|
2164
|
+
}
|
|
2165
|
+
function readPlainScalar(state, nodeIndent, nodeContext, props) {
|
|
2166
|
+
if (!canStartPlainScalar(state, nodeContext))
|
|
2167
|
+
return false;
|
|
2168
|
+
const start = state.position;
|
|
2169
|
+
let end = state.position;
|
|
2170
|
+
let ch = state.input.charCodeAt(state.position);
|
|
2171
|
+
const inFlow = nodeContext === CONTEXT_FLOW_IN;
|
|
2172
|
+
let multiline = false;
|
|
2173
|
+
while (ch !== 0) {
|
|
2174
|
+
if (testDocumentBoundary(state))
|
|
2175
|
+
break;
|
|
2176
|
+
if (ch === 58) {
|
|
2177
|
+
const following = state.input.charCodeAt(state.position + 1);
|
|
2178
|
+
if (isWsOrEolOrEnd(following) || inFlow && isFlowIndicator(following))
|
|
2179
|
+
break;
|
|
2180
|
+
} else if (ch === 35) {
|
|
2181
|
+
if (isWsOrEol(state.input.charCodeAt(state.position - 1)))
|
|
2182
|
+
break;
|
|
2183
|
+
} else if (inFlow && isFlowIndicator(ch))
|
|
2184
|
+
break;
|
|
2185
|
+
else if (isEol(ch)) {
|
|
2186
|
+
const savedPosition = state.position;
|
|
2187
|
+
const savedLine = state.line;
|
|
2188
|
+
const savedLineStart = state.lineStart;
|
|
2189
|
+
const savedLineIndent = state.lineIndent;
|
|
2190
|
+
skipSeparationSpace(state, false);
|
|
2191
|
+
if (state.lineIndent >= nodeIndent) {
|
|
2192
|
+
multiline = true;
|
|
2193
|
+
ch = state.input.charCodeAt(state.position);
|
|
2194
|
+
continue;
|
|
2195
|
+
}
|
|
2196
|
+
state.position = savedPosition;
|
|
2197
|
+
state.line = savedLine;
|
|
2198
|
+
state.lineStart = savedLineStart;
|
|
2199
|
+
state.lineIndent = savedLineIndent;
|
|
2200
|
+
break;
|
|
2201
|
+
}
|
|
2202
|
+
if (!isWhiteSpace(ch))
|
|
2203
|
+
end = state.position + 1;
|
|
2204
|
+
ch = state.input.charCodeAt(++state.position);
|
|
2205
|
+
}
|
|
2206
|
+
if (end === start)
|
|
2207
|
+
return false;
|
|
2208
|
+
checkPrintable(state, start, end);
|
|
2209
|
+
addScalarEvent(state, start, end, props.anchorStart, props.anchorEnd, props.tagStart, props.tagEnd, SCALAR_STYLE.PLAIN, CHOMPING_MODE.CLIP, -1, !multiline);
|
|
2210
|
+
return true;
|
|
2211
|
+
}
|
|
2212
|
+
function skipFlowSeparationSpace(state, nodeIndent) {
|
|
2213
|
+
const startLine = state.line;
|
|
2214
|
+
skipSeparationSpace(state, true);
|
|
2215
|
+
if (state.line > startLine && state.lineIndent < nodeIndent || state.firstTabInLine !== -1 && state.lineIndent < nodeIndent)
|
|
2216
|
+
throwError(state, "deficient indentation");
|
|
2217
|
+
}
|
|
2218
|
+
function readFlowCollection(state, nodeIndent, props) {
|
|
2219
|
+
const ch = state.input.charCodeAt(state.position);
|
|
2220
|
+
const isMapping = ch === 123;
|
|
2221
|
+
const start = state.position;
|
|
2222
|
+
let readNext = true;
|
|
2223
|
+
if (ch !== 91 && ch !== 123)
|
|
2224
|
+
return false;
|
|
2225
|
+
const terminator = isMapping ? 125 : 93;
|
|
2226
|
+
if (isMapping)
|
|
2227
|
+
addMappingEvent(state, start, props.anchorStart, props.anchorEnd, props.tagStart, props.tagEnd, COLLECTION_STYLE.FLOW);
|
|
2228
|
+
else
|
|
2229
|
+
addSequenceEvent(state, start, props.anchorStart, props.anchorEnd, props.tagStart, props.tagEnd, COLLECTION_STYLE.FLOW);
|
|
2230
|
+
state.position++;
|
|
2231
|
+
while (state.input.charCodeAt(state.position) !== 0) {
|
|
2232
|
+
skipFlowSeparationSpace(state, nodeIndent);
|
|
2233
|
+
let ch2 = state.input.charCodeAt(state.position);
|
|
2234
|
+
if (ch2 === terminator) {
|
|
2235
|
+
state.position++;
|
|
2236
|
+
addPopEvent(state);
|
|
2237
|
+
return true;
|
|
2238
|
+
} else if (!readNext)
|
|
2239
|
+
throwError(state, "missed comma between flow collection entries");
|
|
2240
|
+
else if (ch2 === 44)
|
|
2241
|
+
throwError(state, "expected the node content, but found ','");
|
|
2242
|
+
let isPair = false;
|
|
2243
|
+
let isExplicitPair = false;
|
|
2244
|
+
if (ch2 === 63 && isWsOrEol(state.input.charCodeAt(state.position + 1))) {
|
|
2245
|
+
isPair = isExplicitPair = true;
|
|
2246
|
+
state.position += 1;
|
|
2247
|
+
skipFlowSeparationSpace(state, nodeIndent);
|
|
2248
|
+
}
|
|
2249
|
+
const entryLine = state.line;
|
|
2250
|
+
const entryStart = snapshotState(state);
|
|
2251
|
+
const keyWasRead = parseNode(state, nodeIndent, CONTEXT_FLOW_IN, false, true);
|
|
2252
|
+
skipFlowSeparationSpace(state, nodeIndent);
|
|
2253
|
+
ch2 = state.input.charCodeAt(state.position);
|
|
2254
|
+
if ((isMapping || isExplicitPair || state.line === entryLine) && ch2 === 58) {
|
|
2255
|
+
isPair = true;
|
|
2256
|
+
state.position++;
|
|
2257
|
+
skipFlowSeparationSpace(state, nodeIndent);
|
|
2258
|
+
if (!isMapping) {
|
|
2259
|
+
insertFlowPairMappingEvent(state, entryStart);
|
|
2260
|
+
if (!keyWasRead)
|
|
2261
|
+
addEmptyScalarEvent(state);
|
|
2262
|
+
} else if (!keyWasRead)
|
|
2263
|
+
addEmptyScalarEvent(state);
|
|
2264
|
+
if (!parseNode(state, nodeIndent, CONTEXT_FLOW_IN, false, true))
|
|
2265
|
+
addEmptyScalarEvent(state);
|
|
2266
|
+
skipFlowSeparationSpace(state, nodeIndent);
|
|
2267
|
+
if (!isMapping)
|
|
2268
|
+
addPopEvent(state);
|
|
2269
|
+
} else if (isMapping && isPair) {
|
|
2270
|
+
if (!keyWasRead)
|
|
2271
|
+
addEmptyScalarEvent(state);
|
|
2272
|
+
addEmptyScalarEvent(state);
|
|
2273
|
+
} else if (isMapping)
|
|
2274
|
+
addEmptyScalarEvent(state);
|
|
2275
|
+
else if (isPair) {
|
|
2276
|
+
insertFlowPairMappingEvent(state, entryStart);
|
|
2277
|
+
if (!keyWasRead)
|
|
2278
|
+
addEmptyScalarEvent(state);
|
|
2279
|
+
addEmptyScalarEvent(state);
|
|
2280
|
+
addPopEvent(state);
|
|
2281
|
+
}
|
|
2282
|
+
ch2 = state.input.charCodeAt(state.position);
|
|
2283
|
+
if (ch2 === 44) {
|
|
2284
|
+
readNext = true;
|
|
2285
|
+
state.position++;
|
|
2286
|
+
} else
|
|
2287
|
+
readNext = false;
|
|
2288
|
+
}
|
|
2289
|
+
throwError(state, "unexpected end of the stream within a flow collection");
|
|
2290
|
+
}
|
|
2291
|
+
function readBlockSequence(state, nodeIndent, props) {
|
|
2292
|
+
if (state.firstTabInLine !== -1 || state.input.charCodeAt(state.position) !== 45 || !isWsOrEolOrEnd(state.input.charCodeAt(state.position + 1)))
|
|
2293
|
+
return false;
|
|
2294
|
+
addSequenceEvent(state, state.position, props.anchorStart, props.anchorEnd, props.tagStart, props.tagEnd, COLLECTION_STYLE.BLOCK);
|
|
2295
|
+
while (state.input.charCodeAt(state.position) === 45 && isWsOrEolOrEnd(state.input.charCodeAt(state.position + 1))) {
|
|
2296
|
+
if (state.firstTabInLine !== -1) {
|
|
2297
|
+
state.position = state.firstTabInLine;
|
|
2298
|
+
throwError(state, "tab characters must not be used in indentation");
|
|
2299
|
+
}
|
|
2300
|
+
const entryLine = state.line;
|
|
2301
|
+
state.position++;
|
|
2302
|
+
const hadBreak = skipSeparationSpace(state, true) > 0;
|
|
2303
|
+
if (state.firstTabInLine !== -1 && state.input.charCodeAt(state.position) === 45 && isWsOrEolOrEnd(state.input.charCodeAt(state.position + 1)))
|
|
2304
|
+
throwError(state, "bad indentation of a sequence entry");
|
|
2305
|
+
if (hadBreak && state.lineIndent <= nodeIndent)
|
|
2306
|
+
addEmptyScalarEvent(state);
|
|
2307
|
+
else
|
|
2308
|
+
parseNode(state, nodeIndent, CONTEXT_BLOCK_IN, false, true);
|
|
2309
|
+
skipSeparationSpace(state, true);
|
|
2310
|
+
if (state.lineIndent < nodeIndent || state.position >= state.length)
|
|
2311
|
+
break;
|
|
2312
|
+
if (state.lineIndent > nodeIndent)
|
|
2313
|
+
throwError(state, "bad indentation of a sequence entry");
|
|
2314
|
+
if (state.line === entryLine && state.input.charCodeAt(state.position) === 45 && isWsOrEolOrEnd(state.input.charCodeAt(state.position + 1)))
|
|
2315
|
+
throwError(state, "bad indentation of a sequence entry");
|
|
2316
|
+
}
|
|
2317
|
+
addPopEvent(state);
|
|
2318
|
+
return true;
|
|
2319
|
+
}
|
|
2320
|
+
function readBlockMapping(state, nodeIndent, flowIndent, props) {
|
|
2321
|
+
let atExplicitKey = false;
|
|
2322
|
+
let detected = false;
|
|
2323
|
+
let mappingOpened = false;
|
|
2324
|
+
let pendingExplicitKey = false;
|
|
2325
|
+
if (state.firstTabInLine !== -1)
|
|
2326
|
+
return false;
|
|
2327
|
+
let ch = state.input.charCodeAt(state.position);
|
|
2328
|
+
while (ch !== 0) {
|
|
2329
|
+
if (!atExplicitKey && state.firstTabInLine !== -1) {
|
|
2330
|
+
state.position = state.firstTabInLine;
|
|
2331
|
+
throwError(state, "tab characters must not be used in indentation");
|
|
2332
|
+
}
|
|
2333
|
+
const following = state.input.charCodeAt(state.position + 1);
|
|
2334
|
+
const entryLine = state.line;
|
|
2335
|
+
if ((ch === 63 || ch === 58) && isWsOrEolOrEnd(following)) {
|
|
2336
|
+
if (!mappingOpened) {
|
|
2337
|
+
addMappingEvent(state, state.position, props.anchorStart, props.anchorEnd, props.tagStart, props.tagEnd, COLLECTION_STYLE.BLOCK);
|
|
2338
|
+
mappingOpened = true;
|
|
2339
|
+
}
|
|
2340
|
+
if (ch === 63) {
|
|
2341
|
+
if (atExplicitKey)
|
|
2342
|
+
addEmptyScalarEvent(state);
|
|
2343
|
+
detected = true;
|
|
2344
|
+
atExplicitKey = true;
|
|
2345
|
+
} else if (atExplicitKey)
|
|
2346
|
+
atExplicitKey = false;
|
|
2347
|
+
else {
|
|
2348
|
+
addEmptyScalarEvent(state);
|
|
2349
|
+
detected = true;
|
|
2350
|
+
atExplicitKey = false;
|
|
2351
|
+
}
|
|
2352
|
+
state.position += 1;
|
|
2353
|
+
pendingExplicitKey = true;
|
|
2354
|
+
} else {
|
|
2355
|
+
if (atExplicitKey) {
|
|
2356
|
+
addEmptyScalarEvent(state);
|
|
2357
|
+
atExplicitKey = false;
|
|
2358
|
+
}
|
|
2359
|
+
const beforeKey = snapshotState(state);
|
|
2360
|
+
if (!parseNode(state, flowIndent, CONTEXT_FLOW_OUT, false, true))
|
|
2361
|
+
break;
|
|
2362
|
+
if (state.line === entryLine) {
|
|
2363
|
+
ch = state.input.charCodeAt(state.position);
|
|
2364
|
+
while (isWhiteSpace(ch))
|
|
2365
|
+
ch = state.input.charCodeAt(++state.position);
|
|
2366
|
+
if (ch === 58) {
|
|
2367
|
+
ch = state.input.charCodeAt(++state.position);
|
|
2368
|
+
if (!isWsOrEolOrEnd(ch))
|
|
2369
|
+
throwError(state, "a whitespace character is expected after the key-value separator within a block mapping");
|
|
2370
|
+
if (!mappingOpened) {
|
|
2371
|
+
state.events.splice(beforeKey.eventsLength, 0, {
|
|
2372
|
+
type: EVENT_ID.MAPPING,
|
|
2373
|
+
start: beforeKey.position,
|
|
2374
|
+
anchorStart: props.anchorStart,
|
|
2375
|
+
anchorEnd: props.anchorEnd,
|
|
2376
|
+
tagStart: props.tagStart,
|
|
2377
|
+
tagEnd: props.tagEnd,
|
|
2378
|
+
style: COLLECTION_STYLE.BLOCK
|
|
2379
|
+
});
|
|
2380
|
+
mappingOpened = true;
|
|
2381
|
+
}
|
|
2382
|
+
detected = true;
|
|
2383
|
+
atExplicitKey = false;
|
|
2384
|
+
pendingExplicitKey = false;
|
|
2385
|
+
} else if (detected)
|
|
2386
|
+
throwError(state, "expected ':' after a mapping key");
|
|
2387
|
+
else {
|
|
2388
|
+
if (props.anchorStart !== NO_RANGE$1 || props.tagStart !== NO_RANGE$1) {
|
|
2389
|
+
restoreState(state, beforeKey);
|
|
2390
|
+
return false;
|
|
2391
|
+
}
|
|
2392
|
+
return true;
|
|
2393
|
+
}
|
|
2394
|
+
} else if (detected)
|
|
2395
|
+
throwError(state, "can not read a block mapping entry; a multiline key may not be an implicit key");
|
|
2396
|
+
else {
|
|
2397
|
+
if (props.anchorStart !== NO_RANGE$1 || props.tagStart !== NO_RANGE$1) {
|
|
2398
|
+
restoreState(state, beforeKey);
|
|
2399
|
+
return false;
|
|
2400
|
+
}
|
|
2401
|
+
return true;
|
|
2402
|
+
}
|
|
2403
|
+
}
|
|
2404
|
+
if (parseNode(state, nodeIndent, CONTEXT_BLOCK_OUT, true, pendingExplicitKey))
|
|
2405
|
+
pendingExplicitKey = false;
|
|
2406
|
+
if (!atExplicitKey) {
|
|
2407
|
+
if (pendingExplicitKey) {
|
|
2408
|
+
addEmptyScalarEvent(state);
|
|
2409
|
+
pendingExplicitKey = false;
|
|
2410
|
+
}
|
|
2411
|
+
}
|
|
2412
|
+
skipSeparationSpace(state, true);
|
|
2413
|
+
ch = state.input.charCodeAt(state.position);
|
|
2414
|
+
if ((state.line === entryLine || state.lineIndent > nodeIndent) && ch !== 0)
|
|
2415
|
+
throwError(state, "bad indentation of a mapping entry");
|
|
2416
|
+
else if (state.lineIndent < nodeIndent)
|
|
2417
|
+
break;
|
|
2418
|
+
}
|
|
2419
|
+
if (!detected)
|
|
2420
|
+
return false;
|
|
2421
|
+
if (atExplicitKey)
|
|
2422
|
+
addEmptyScalarEvent(state);
|
|
2423
|
+
if (mappingOpened)
|
|
2424
|
+
addPopEvent(state);
|
|
2425
|
+
return true;
|
|
2426
|
+
}
|
|
2427
|
+
function parseNode(state, parentIndent, nodeContext, allowToSeek, allowCompact, allowPropertyMapping = true) {
|
|
2428
|
+
if (state.depth >= state.maxDepth)
|
|
2429
|
+
throwError(state, `nesting exceeded maxDepth (${state.maxDepth})`);
|
|
2430
|
+
state.depth++;
|
|
2431
|
+
let indentStatus = 1;
|
|
2432
|
+
let atNewLine = false;
|
|
2433
|
+
let hasContent = false;
|
|
2434
|
+
let propertyStart = null;
|
|
2435
|
+
const props = emptyProperties();
|
|
2436
|
+
let allowBlockScalars = nodeContext === CONTEXT_BLOCK_OUT || nodeContext === CONTEXT_BLOCK_IN;
|
|
2437
|
+
let allowBlockCollections = allowBlockScalars;
|
|
2438
|
+
const allowBlockStyles = allowBlockScalars;
|
|
2439
|
+
if (allowToSeek && skipSeparationSpace(state, true)) {
|
|
2440
|
+
atNewLine = true;
|
|
2441
|
+
if (state.lineIndent > parentIndent)
|
|
2442
|
+
indentStatus = 1;
|
|
2443
|
+
else if (state.lineIndent === parentIndent)
|
|
2444
|
+
indentStatus = 0;
|
|
2445
|
+
else
|
|
2446
|
+
indentStatus = -1;
|
|
2447
|
+
}
|
|
2448
|
+
if (indentStatus === 1)
|
|
2449
|
+
while (true) {
|
|
2450
|
+
const ch = state.input.charCodeAt(state.position);
|
|
2451
|
+
const propertyState = snapshotState(state);
|
|
2452
|
+
if (atNewLine && indentStatus !== 1 && (ch === 33 || ch === 38))
|
|
2453
|
+
break;
|
|
2454
|
+
if (atNewLine && allowBlockStyles && (props.tagStart !== NO_RANGE$1 || props.anchorStart !== NO_RANGE$1) && (ch === 33 || ch === 38)) {
|
|
2455
|
+
const fallbackState = snapshotState(state);
|
|
2456
|
+
const flowIndent = parentIndent + 1;
|
|
2457
|
+
if (readBlockMapping(state, state.position - state.lineStart, flowIndent, props) && state.events[fallbackState.eventsLength]?.type === EVENT_ID.MAPPING) {
|
|
2458
|
+
state.depth--;
|
|
2459
|
+
return true;
|
|
2460
|
+
}
|
|
2461
|
+
restoreState(state, fallbackState);
|
|
2462
|
+
}
|
|
2463
|
+
if (atNewLine && (ch === 33 && props.tagStart !== NO_RANGE$1 || ch === 38 && props.anchorStart !== NO_RANGE$1))
|
|
2464
|
+
break;
|
|
2465
|
+
if (!readTagProperty(state, props, nodeContext === CONTEXT_FLOW_IN) && !readAnchorProperty(state, props))
|
|
2466
|
+
break;
|
|
2467
|
+
if (propertyStart === null)
|
|
2468
|
+
propertyStart = propertyState;
|
|
2469
|
+
if (skipSeparationSpace(state, true)) {
|
|
2470
|
+
atNewLine = true;
|
|
2471
|
+
allowBlockCollections = allowBlockStyles;
|
|
2472
|
+
if (state.lineIndent > parentIndent)
|
|
2473
|
+
indentStatus = 1;
|
|
2474
|
+
else if (state.lineIndent === parentIndent)
|
|
2475
|
+
indentStatus = 0;
|
|
2476
|
+
else
|
|
2477
|
+
indentStatus = -1;
|
|
2478
|
+
} else
|
|
2479
|
+
allowBlockCollections = false;
|
|
2480
|
+
}
|
|
2481
|
+
if (allowBlockCollections)
|
|
2482
|
+
allowBlockCollections = atNewLine || allowCompact;
|
|
2483
|
+
if (indentStatus === 1 || nodeContext === CONTEXT_BLOCK_OUT) {
|
|
2484
|
+
const flowIndent = nodeContext === CONTEXT_FLOW_IN || nodeContext === CONTEXT_FLOW_OUT ? parentIndent : parentIndent + 1;
|
|
2485
|
+
const blockIndent = state.position - state.lineStart;
|
|
2486
|
+
if (indentStatus === 1)
|
|
2487
|
+
if (allowBlockCollections && (readBlockSequence(state, blockIndent, props) || readBlockMapping(state, blockIndent, flowIndent, props)) || readFlowCollection(state, flowIndent, props))
|
|
2488
|
+
hasContent = true;
|
|
2489
|
+
else {
|
|
2490
|
+
const ch = state.input.charCodeAt(state.position);
|
|
2491
|
+
if (propertyStart !== null && allowPropertyMapping && allowBlockStyles && !allowBlockCollections && ch !== 124 && ch !== 62) {
|
|
2492
|
+
const fallbackState = snapshotState(state);
|
|
2493
|
+
const propertyIndent = propertyStart.position - propertyStart.lineStart;
|
|
2494
|
+
restoreState(state, propertyStart);
|
|
2495
|
+
if (readBlockMapping(state, propertyIndent, flowIndent, emptyProperties()) && state.events[fallbackState.eventsLength]?.type === EVENT_ID.MAPPING)
|
|
2496
|
+
hasContent = true;
|
|
2497
|
+
else
|
|
2498
|
+
restoreState(state, fallbackState);
|
|
2499
|
+
}
|
|
2500
|
+
if (!hasContent && (allowBlockScalars && readBlockScalar(state, flowIndent, props) || readSingleQuotedScalar(state, flowIndent, props) || readDoubleQuotedScalar(state, flowIndent, props) || readAlias(state, props) || readPlainScalar(state, flowIndent, nodeContext, props)))
|
|
2501
|
+
hasContent = true;
|
|
2502
|
+
}
|
|
2503
|
+
else if (indentStatus === 0)
|
|
2504
|
+
hasContent = allowBlockCollections && readBlockSequence(state, blockIndent, props);
|
|
2505
|
+
}
|
|
2506
|
+
allowBlockScalars = allowBlockScalars && !hasContent;
|
|
2507
|
+
if (!hasContent && (props.anchorStart !== NO_RANGE$1 || props.tagStart !== NO_RANGE$1 || allowBlockScalars)) {
|
|
2508
|
+
addScalarEvent(state, NO_RANGE$1, NO_RANGE$1, props.anchorStart, props.anchorEnd, props.tagStart, props.tagEnd, SCALAR_STYLE.PLAIN);
|
|
2509
|
+
hasContent = true;
|
|
2510
|
+
}
|
|
2511
|
+
state.depth--;
|
|
2512
|
+
return hasContent || props.anchorStart !== NO_RANGE$1 || props.tagStart !== NO_RANGE$1;
|
|
2513
|
+
}
|
|
2514
|
+
function readDirective(state) {
|
|
2515
|
+
if (state.lineIndent > 0 || state.input.charCodeAt(state.position) !== 37)
|
|
2516
|
+
return false;
|
|
2517
|
+
state.position++;
|
|
2518
|
+
const nameStart = state.position;
|
|
2519
|
+
while (state.input.charCodeAt(state.position) !== 0 && !isWsOrEol(state.input.charCodeAt(state.position)))
|
|
2520
|
+
state.position++;
|
|
2521
|
+
const name = state.input.slice(nameStart, state.position);
|
|
2522
|
+
const args = [];
|
|
2523
|
+
if (name.length === 0)
|
|
2524
|
+
throwError(state, "directive name must not be less than one character in length");
|
|
2525
|
+
while (state.input.charCodeAt(state.position) !== 0 && !isEol(state.input.charCodeAt(state.position))) {
|
|
2526
|
+
while (isWhiteSpace(state.input.charCodeAt(state.position)))
|
|
2527
|
+
state.position++;
|
|
2528
|
+
if (state.input.charCodeAt(state.position) === 35 || isEol(state.input.charCodeAt(state.position)) || state.input.charCodeAt(state.position) === 0)
|
|
2529
|
+
break;
|
|
2530
|
+
const start = state.position;
|
|
2531
|
+
while (state.input.charCodeAt(state.position) !== 0 && !isWsOrEol(state.input.charCodeAt(state.position)))
|
|
2532
|
+
state.position++;
|
|
2533
|
+
args.push(state.input.slice(start, state.position));
|
|
2534
|
+
}
|
|
2535
|
+
if (isEol(state.input.charCodeAt(state.position)))
|
|
2536
|
+
consumeLineBreak(state);
|
|
2537
|
+
if (name === "YAML") {
|
|
2538
|
+
if (state.directives.some((directive) => directive.kind === "yaml"))
|
|
2539
|
+
throwError(state, "duplication of %YAML directive");
|
|
2540
|
+
if (args.length !== 1)
|
|
2541
|
+
throwError(state, "YAML directive accepts exactly one argument");
|
|
2542
|
+
const match = /^([0-9]+)\.([0-9]+)$/.exec(args[0]);
|
|
2543
|
+
if (match === null)
|
|
2544
|
+
throwError(state, "ill-formed argument of the YAML directive");
|
|
2545
|
+
if (parseInt(match[1], 10) !== 1)
|
|
2546
|
+
throwError(state, "unacceptable YAML version of the document");
|
|
2547
|
+
state.directives.push({
|
|
2548
|
+
kind: "yaml",
|
|
2549
|
+
version: args[0]
|
|
2550
|
+
});
|
|
2551
|
+
} else if (name === "TAG") {
|
|
2552
|
+
if (args.length !== 2)
|
|
2553
|
+
throwError(state, "TAG directive accepts exactly two arguments");
|
|
2554
|
+
const [handle, prefix] = args;
|
|
2555
|
+
if (!PATTERN_TAG_HANDLE.test(handle))
|
|
2556
|
+
throwError(state, "ill-formed tag handle (first argument) of the TAG directive");
|
|
2557
|
+
if (HAS_OWN.call(state.tagHandlers, handle))
|
|
2558
|
+
throwError(state, `there is a previously declared suffix for "${handle}" tag handle`);
|
|
2559
|
+
if (!PATTERN_TAG_PREFIX.test(prefix))
|
|
2560
|
+
throwError(state, "ill-formed tag prefix (second argument) of the TAG directive");
|
|
2561
|
+
state.tagHandlers[handle] = prefix;
|
|
2562
|
+
state.directives.push({
|
|
2563
|
+
kind: "tag",
|
|
2564
|
+
handle,
|
|
2565
|
+
prefix
|
|
2566
|
+
});
|
|
2567
|
+
}
|
|
2568
|
+
return true;
|
|
2569
|
+
}
|
|
2570
|
+
function readDocument(state) {
|
|
2571
|
+
state.directives = [];
|
|
2572
|
+
state.tagHandlers = Object.create(null);
|
|
2573
|
+
let hasDirectives = false;
|
|
2574
|
+
skipSeparationSpace(state, true);
|
|
2575
|
+
while (readDirective(state)) {
|
|
2576
|
+
hasDirectives = true;
|
|
2577
|
+
skipSeparationSpace(state, true);
|
|
2578
|
+
}
|
|
2579
|
+
let explicitStart = false;
|
|
2580
|
+
let explicitEnd = false;
|
|
2581
|
+
let allowCompact = true;
|
|
2582
|
+
if (state.lineIndent === 0 && state.input.charCodeAt(state.position) === 45 && state.input.charCodeAt(state.position + 1) === 45 && state.input.charCodeAt(state.position + 2) === 45 && isWsOrEolOrEnd(state.input.charCodeAt(state.position + 3))) {
|
|
2583
|
+
explicitStart = true;
|
|
2584
|
+
const markerLine = state.line;
|
|
2585
|
+
state.position += 3;
|
|
2586
|
+
skipSeparationSpace(state, true);
|
|
2587
|
+
allowCompact = state.line > markerLine;
|
|
2588
|
+
} else if (hasDirectives)
|
|
2589
|
+
throwError(state, "directives end mark is expected");
|
|
2590
|
+
const documentEventIndex = state.events.length;
|
|
2591
|
+
if (!explicitStart && state.position === state.lineStart && state.input.charCodeAt(state.position) === 46 && testDocumentSeparator(state)) {
|
|
2592
|
+
state.position += 3;
|
|
2593
|
+
skipSeparationSpace(state, true);
|
|
2594
|
+
return;
|
|
2595
|
+
}
|
|
2596
|
+
addDocumentEvent(state, explicitStart, false);
|
|
2597
|
+
if (!parseNode(state, state.lineIndent - 1, CONTEXT_BLOCK_OUT, false, allowCompact, allowCompact))
|
|
2598
|
+
addEmptyScalarEvent(state);
|
|
2599
|
+
skipSeparationSpace(state, true);
|
|
2600
|
+
if (state.position === state.lineStart && testDocumentSeparator(state)) {
|
|
2601
|
+
explicitEnd = state.input.charCodeAt(state.position) === 46;
|
|
2602
|
+
if (explicitEnd) {
|
|
2603
|
+
const markerLine = state.line;
|
|
2604
|
+
state.position += 3;
|
|
2605
|
+
skipSeparationSpace(state, true);
|
|
2606
|
+
if (state.line === markerLine && state.position < state.length)
|
|
2607
|
+
throwError(state, "end of the stream or a document separator is expected");
|
|
2608
|
+
}
|
|
2609
|
+
}
|
|
2610
|
+
const documentEvent = state.events[documentEventIndex];
|
|
2611
|
+
if (documentEvent?.type === EVENT_ID.DOCUMENT)
|
|
2612
|
+
documentEvent.explicitEnd = explicitEnd;
|
|
2613
|
+
addPopEvent(state);
|
|
2614
|
+
if (!explicitEnd && state.position < state.length && !testDocumentBoundary(state))
|
|
2615
|
+
throwError(state, "end of the stream or a document separator is expected");
|
|
2616
|
+
}
|
|
2617
|
+
function parseEvents(input, options) {
|
|
2618
|
+
const length = input.length;
|
|
2619
|
+
const state = {
|
|
2620
|
+
...DEFAULT_PARSER_OPTIONS,
|
|
2621
|
+
...options,
|
|
2622
|
+
input: `${input}\x00`,
|
|
2623
|
+
length,
|
|
2624
|
+
position: 0,
|
|
2625
|
+
line: 0,
|
|
2626
|
+
lineStart: 0,
|
|
2627
|
+
lineIndent: 0,
|
|
2628
|
+
firstTabInLine: -1,
|
|
2629
|
+
depth: 0,
|
|
2630
|
+
directives: [],
|
|
2631
|
+
tagHandlers: Object.create(null),
|
|
2632
|
+
events: []
|
|
2633
|
+
};
|
|
2634
|
+
const nullpos = input.indexOf("\x00");
|
|
2635
|
+
if (nullpos !== -1)
|
|
2636
|
+
YAMLException.throwAt(input, nullpos, "null byte is not allowed in input", state.filename);
|
|
2637
|
+
while (state.position < state.length) {
|
|
2638
|
+
skipByteOrderMark(state);
|
|
2639
|
+
skipSeparationSpace(state, true);
|
|
2640
|
+
if (state.position >= state.length)
|
|
2641
|
+
break;
|
|
2642
|
+
const documentStart = state.position;
|
|
2643
|
+
readDocument(state);
|
|
2644
|
+
if (state.position === documentStart)
|
|
2645
|
+
throwError(state, "can not read a document");
|
|
2646
|
+
}
|
|
2647
|
+
return state.events;
|
|
2648
|
+
}
|
|
2649
|
+
var DEFAULT_LOAD_OPTIONS = {
|
|
2650
|
+
...DEFAULT_PARSER_OPTIONS,
|
|
2651
|
+
...DEFAULT_CONSTRUCTOR_OPTIONS
|
|
2652
|
+
};
|
|
2653
|
+
function loadDocuments(input, options = {}) {
|
|
2654
|
+
const opts = {
|
|
2655
|
+
...DEFAULT_LOAD_OPTIONS,
|
|
2656
|
+
...options
|
|
2657
|
+
};
|
|
2658
|
+
const source = String(input);
|
|
2659
|
+
const PARSER_OPT_KEYS = Object.keys(DEFAULT_PARSER_OPTIONS);
|
|
2660
|
+
const CONSTRUCTOR_OPT_KEYS = Object.keys(DEFAULT_CONSTRUCTOR_OPTIONS);
|
|
2661
|
+
return constructFromEvents(parseEvents(source, pick(opts, PARSER_OPT_KEYS)), {
|
|
2662
|
+
...pick(opts, CONSTRUCTOR_OPT_KEYS),
|
|
2663
|
+
source
|
|
2664
|
+
});
|
|
2665
|
+
}
|
|
2666
|
+
function load(input, options) {
|
|
2667
|
+
const documents = loadDocuments(input, options);
|
|
2668
|
+
if (documents.length === 0)
|
|
2669
|
+
throw new YAMLException("expected a document, but the input is empty");
|
|
2670
|
+
if (documents.length === 1)
|
|
2671
|
+
return documents[0];
|
|
2672
|
+
throw new YAMLException("expected a single document in the stream, but found more");
|
|
2673
|
+
}
|
|
2674
|
+
var INVALID = Symbol("INVALID");
|
|
2675
|
+
function buildRepresentTypes(schema) {
|
|
2676
|
+
const defaultTags = new Set([
|
|
2677
|
+
schema.defaultScalarTag,
|
|
2678
|
+
schema.defaultSequenceTag,
|
|
2679
|
+
schema.defaultMappingTag
|
|
2680
|
+
].filter((t) => t !== undefined));
|
|
2681
|
+
const implicitScalars = schema.implicitScalarTags;
|
|
2682
|
+
const explicitTags = schema.tags.filter((t) => !(t.nodeKind === "scalar" && t.implicit) && !defaultTags.has(t));
|
|
2683
|
+
const defaultTagsLast = schema.tags.filter((t) => defaultTags.has(t));
|
|
2684
|
+
return [
|
|
2685
|
+
...implicitScalars.map((tag) => ({
|
|
2686
|
+
tag,
|
|
2687
|
+
implicitTag: true
|
|
2688
|
+
})),
|
|
2689
|
+
...explicitTags.map((tag) => ({
|
|
2690
|
+
tag,
|
|
2691
|
+
implicitTag: false
|
|
2692
|
+
})),
|
|
2693
|
+
...defaultTagsLast.map((tag) => ({
|
|
2694
|
+
tag,
|
|
2695
|
+
implicitTag: true
|
|
2696
|
+
}))
|
|
2697
|
+
];
|
|
2698
|
+
}
|
|
2699
|
+
function matchTag(state, object) {
|
|
2700
|
+
for (let index = 0, length = state.representTypes.length;index < length; index += 1) {
|
|
2701
|
+
const { tag, implicitTag } = state.representTypes[index];
|
|
2702
|
+
if (tag.identify(object)) {
|
|
2703
|
+
let tagName;
|
|
2704
|
+
if (tag.matchByTagPrefix)
|
|
2705
|
+
tagName = tag.representTagName(object);
|
|
2706
|
+
else
|
|
2707
|
+
tagName = tag.tagName;
|
|
2708
|
+
return {
|
|
2709
|
+
tag,
|
|
2710
|
+
tagName,
|
|
2711
|
+
implicitTag
|
|
2712
|
+
};
|
|
2713
|
+
}
|
|
2714
|
+
}
|
|
2715
|
+
return null;
|
|
2716
|
+
}
|
|
2717
|
+
function build(state, object) {
|
|
2718
|
+
if (!state.noRefs && object !== null && typeof object === "object") {
|
|
2719
|
+
const existing = state.refs.get(object);
|
|
2720
|
+
if (existing) {
|
|
2721
|
+
if (existing.anchor === undefined)
|
|
2722
|
+
existing.anchor = `ref_${state.refCounter++}`;
|
|
2723
|
+
return {
|
|
2724
|
+
kind: "alias",
|
|
2725
|
+
anchor: existing.anchor
|
|
2726
|
+
};
|
|
2727
|
+
}
|
|
2728
|
+
}
|
|
2729
|
+
const matched = matchTag(state, object);
|
|
2730
|
+
if (!matched) {
|
|
2731
|
+
if (object === undefined)
|
|
2732
|
+
return INVALID;
|
|
2733
|
+
if (state.skipInvalid)
|
|
2734
|
+
return INVALID;
|
|
2735
|
+
throw new YAMLException(`unacceptable kind of an object to dump ${Object.prototype.toString.call(object)}`);
|
|
2736
|
+
}
|
|
2737
|
+
const { tag, tagName, implicitTag } = matched;
|
|
2738
|
+
const nodeTagName = implicitTag ? tagName : tagNameShort(tagName);
|
|
2739
|
+
if (tag.nodeKind === "scalar")
|
|
2740
|
+
return {
|
|
2741
|
+
kind: "scalar",
|
|
2742
|
+
tag: nodeTagName,
|
|
2743
|
+
tagged: !implicitTag,
|
|
2744
|
+
style: SCALAR_STYLE.PLAIN,
|
|
2745
|
+
value: tag.represent(object)
|
|
2746
|
+
};
|
|
2747
|
+
if (tag.nodeKind === "sequence") {
|
|
2748
|
+
const container = tag.represent(object);
|
|
2749
|
+
const node2 = {
|
|
2750
|
+
kind: "sequence",
|
|
2751
|
+
tag: nodeTagName,
|
|
2752
|
+
tagged: !implicitTag,
|
|
2753
|
+
style: COLLECTION_STYLE.BLOCK,
|
|
2754
|
+
items: []
|
|
2755
|
+
};
|
|
2756
|
+
if (!state.noRefs)
|
|
2757
|
+
state.refs.set(object, node2);
|
|
2758
|
+
for (let index = 0, length = container.length;index < length; index += 1) {
|
|
2759
|
+
let item = build(state, container[index]);
|
|
2760
|
+
if (item === INVALID && container[index] === undefined)
|
|
2761
|
+
item = build(state, null);
|
|
2762
|
+
if (item === INVALID)
|
|
2763
|
+
continue;
|
|
2764
|
+
node2.items.push(item);
|
|
2765
|
+
}
|
|
2766
|
+
return node2;
|
|
2767
|
+
}
|
|
2768
|
+
const map = tag.represent(object);
|
|
2769
|
+
const node = {
|
|
2770
|
+
kind: "mapping",
|
|
2771
|
+
tag: nodeTagName,
|
|
2772
|
+
tagged: !implicitTag,
|
|
2773
|
+
style: COLLECTION_STYLE.BLOCK,
|
|
2774
|
+
items: []
|
|
2775
|
+
};
|
|
2776
|
+
if (!state.noRefs)
|
|
2777
|
+
state.refs.set(object, node);
|
|
2778
|
+
for (const [objectKey, objectValue] of map) {
|
|
2779
|
+
const key = build(state, objectKey);
|
|
2780
|
+
if (key === INVALID)
|
|
2781
|
+
continue;
|
|
2782
|
+
const value = build(state, objectValue);
|
|
2783
|
+
if (value === INVALID)
|
|
2784
|
+
continue;
|
|
2785
|
+
node.items.push({
|
|
2786
|
+
key,
|
|
2787
|
+
value
|
|
2788
|
+
});
|
|
2789
|
+
}
|
|
2790
|
+
return node;
|
|
2791
|
+
}
|
|
2792
|
+
function jsToAst(input, schema, options = {}) {
|
|
2793
|
+
const root = build({
|
|
2794
|
+
representTypes: buildRepresentTypes(schema),
|
|
2795
|
+
noRefs: options.noRefs ?? false,
|
|
2796
|
+
skipInvalid: options.skipInvalid ?? false,
|
|
2797
|
+
refs: /* @__PURE__ */ new Map,
|
|
2798
|
+
refCounter: 0
|
|
2799
|
+
}, input);
|
|
2800
|
+
return [{
|
|
2801
|
+
contents: root === INVALID ? null : root,
|
|
2802
|
+
directives: []
|
|
2803
|
+
}];
|
|
2804
|
+
}
|
|
2805
|
+
var VISIT_BREAK = Symbol("visit:break");
|
|
2806
|
+
var VISIT_SKIP = Symbol("visit:skip");
|
|
2807
|
+
function visitNode(node, visitor, ctx) {
|
|
2808
|
+
const control = visitor(node, ctx);
|
|
2809
|
+
if (control === VISIT_BREAK)
|
|
2810
|
+
return true;
|
|
2811
|
+
if (control === VISIT_SKIP)
|
|
2812
|
+
return false;
|
|
2813
|
+
const depth = ctx.depth + 1;
|
|
2814
|
+
switch (node.kind) {
|
|
2815
|
+
case "sequence":
|
|
2816
|
+
for (const item of node.items)
|
|
2817
|
+
if (visitNode(item, visitor, {
|
|
2818
|
+
depth,
|
|
2819
|
+
parent: node,
|
|
2820
|
+
isKey: false
|
|
2821
|
+
}))
|
|
2822
|
+
return true;
|
|
2823
|
+
break;
|
|
2824
|
+
case "mapping":
|
|
2825
|
+
for (const { key, value } of node.items) {
|
|
2826
|
+
if (visitNode(key, visitor, {
|
|
2827
|
+
depth,
|
|
2828
|
+
parent: node,
|
|
2829
|
+
isKey: true
|
|
2830
|
+
}))
|
|
2831
|
+
return true;
|
|
2832
|
+
if (visitNode(value, visitor, {
|
|
2833
|
+
depth,
|
|
2834
|
+
parent: node,
|
|
2835
|
+
isKey: false
|
|
2836
|
+
}))
|
|
2837
|
+
return true;
|
|
2838
|
+
}
|
|
2839
|
+
break;
|
|
2840
|
+
}
|
|
2841
|
+
return false;
|
|
2842
|
+
}
|
|
2843
|
+
function visit(documents, visitor) {
|
|
2844
|
+
for (const doc of documents)
|
|
2845
|
+
if (doc.contents && visitNode(doc.contents, visitor, {
|
|
2846
|
+
depth: 0,
|
|
2847
|
+
parent: null,
|
|
2848
|
+
isKey: false
|
|
2849
|
+
}))
|
|
2850
|
+
return;
|
|
2851
|
+
}
|
|
2852
|
+
function hasBit(mask, bit) {
|
|
2853
|
+
return (mask & 1 << bit) !== 0;
|
|
2854
|
+
}
|
|
2855
|
+
var DEFAULT_SCALAR_STYLE_RULES = {
|
|
2856
|
+
applyQuoteFlowKeysOption,
|
|
2857
|
+
doubleQuoteForInvisibles,
|
|
2858
|
+
doubleQuoteWhitespaceOnly,
|
|
2859
|
+
applyForceQuotesOption,
|
|
2860
|
+
tryLongOrMultilineAsBlock,
|
|
2861
|
+
quoteInvalidPlain,
|
|
2862
|
+
fallbackToDoubleQuoted
|
|
2863
|
+
};
|
|
2864
|
+
function _preferredQuotedStyle(layout) {
|
|
2865
|
+
if (layout.presenterOptions.quoteStyle === "single" && hasBit(layout.allowedStylesMask, SCALAR_STYLE.SINGLE_QUOTED))
|
|
2866
|
+
return SCALAR_STYLE.SINGLE_QUOTED;
|
|
2867
|
+
return SCALAR_STYLE.DOUBLE_QUOTED;
|
|
2868
|
+
}
|
|
2869
|
+
function applyQuoteFlowKeysOption(layout) {
|
|
2870
|
+
if (!layout.presenterOptions.quoteFlowKeys)
|
|
2871
|
+
return;
|
|
2872
|
+
if (!layout.isKey || !layout.flowOnly || layout.style !== SCALAR_STYLE.PLAIN)
|
|
2873
|
+
return;
|
|
2874
|
+
layout.style = SCALAR_STYLE.DOUBLE_QUOTED;
|
|
2875
|
+
}
|
|
2876
|
+
function doubleQuoteForInvisibles(layout) {
|
|
2877
|
+
if (layout.style === SCALAR_STYLE.PLAIN && /[\t\x7F-\xA0\u2028\u2029\uFEFF\uFFFE\uFFFF]/.test(layout.node.value))
|
|
2878
|
+
layout.style = SCALAR_STYLE.DOUBLE_QUOTED;
|
|
2879
|
+
}
|
|
2880
|
+
function doubleQuoteWhitespaceOnly(layout) {
|
|
2881
|
+
if (layout.style === SCALAR_STYLE.PLAIN && /^\s+$/.test(layout.node.value))
|
|
2882
|
+
layout.style = SCALAR_STYLE.DOUBLE_QUOTED;
|
|
2883
|
+
}
|
|
2884
|
+
function applyForceQuotesOption(layout) {
|
|
2885
|
+
if (!layout.presenterOptions.forceQuotes)
|
|
2886
|
+
return;
|
|
2887
|
+
if (layout.isKey || layout.style !== SCALAR_STYLE.PLAIN)
|
|
2888
|
+
return;
|
|
2889
|
+
if (layout.node.tag !== layout.presenterOptions.schema.defaultScalarTag.tagName)
|
|
2890
|
+
return;
|
|
2891
|
+
layout.style = layout.node.value.includes(`
|
|
2892
|
+
`) ? SCALAR_STYLE.DOUBLE_QUOTED : _preferredQuotedStyle(layout);
|
|
2893
|
+
}
|
|
2894
|
+
function tryLongOrMultilineAsBlock(layout) {
|
|
2895
|
+
if (layout.style !== SCALAR_STYLE.PLAIN || layout.isKey)
|
|
2896
|
+
return;
|
|
2897
|
+
const value = layout.node.value;
|
|
2898
|
+
const multiline = value.indexOf(`
|
|
2899
|
+
`) !== -1;
|
|
2900
|
+
if (!hasBit(layout.allowedStylesMask, SCALAR_STYLE.LITERAL_BLOCK)) {
|
|
2901
|
+
if (multiline)
|
|
2902
|
+
layout.style = SCALAR_STYLE.DOUBLE_QUOTED;
|
|
2903
|
+
return;
|
|
2904
|
+
}
|
|
2905
|
+
const w = layout.presenterOptions.lineWidth;
|
|
2906
|
+
if (w === -1) {
|
|
2907
|
+
if (multiline)
|
|
2908
|
+
layout.style = SCALAR_STYLE.LITERAL_BLOCK;
|
|
2909
|
+
return;
|
|
2910
|
+
}
|
|
2911
|
+
const availableWidth = Math.max(Math.min(w, 40), w - layout.shiftOfContent);
|
|
2912
|
+
let position = 0;
|
|
2913
|
+
let shouldFold = false;
|
|
2914
|
+
while (position <= value.length) {
|
|
2915
|
+
let lineEnd = value.length;
|
|
2916
|
+
const nextLineBreak = value.indexOf(`
|
|
2917
|
+
`, position);
|
|
2918
|
+
if (nextLineBreak !== -1)
|
|
2919
|
+
lineEnd = nextLineBreak;
|
|
2920
|
+
const line = value.slice(position, lineEnd);
|
|
2921
|
+
if (line.length > availableWidth && line[0] !== " " && / [^ \t]/.test(line))
|
|
2922
|
+
shouldFold = true;
|
|
2923
|
+
if (nextLineBreak === -1)
|
|
2924
|
+
break;
|
|
2925
|
+
position = nextLineBreak + 1;
|
|
2926
|
+
}
|
|
2927
|
+
if (shouldFold)
|
|
2928
|
+
layout.style = SCALAR_STYLE.FOLDED_BLOCK;
|
|
2929
|
+
else if (multiline)
|
|
2930
|
+
layout.style = SCALAR_STYLE.LITERAL_BLOCK;
|
|
2931
|
+
}
|
|
2932
|
+
function quoteInvalidPlain(layout) {
|
|
2933
|
+
if (layout.style === SCALAR_STYLE.PLAIN && !hasBit(layout.allowedStylesMask, SCALAR_STYLE.PLAIN))
|
|
2934
|
+
layout.style = _preferredQuotedStyle(layout);
|
|
2935
|
+
}
|
|
2936
|
+
function fallbackToDoubleQuoted(layout) {
|
|
2937
|
+
if (!hasBit(layout.allowedStylesMask, layout.style))
|
|
2938
|
+
layout.style = SCALAR_STYLE.DOUBLE_QUOTED;
|
|
2939
|
+
}
|
|
2940
|
+
function setBit(mask, bit) {
|
|
2941
|
+
return mask | 1 << bit;
|
|
2942
|
+
}
|
|
2943
|
+
var SRC_C_PRINTABLE = "[\\x09\\x0A\\x0D\\x20-\\x7E\\x85\\xA0-\\uD7FF\\uE000-\\uFFFD\\u{10000}-\\u{10FFFF}]";
|
|
2944
|
+
var SRC_B_CHAR = "[\\n\\r]";
|
|
2945
|
+
var SRC_C_BYTE_ORDER_MARK = "\\uFEFF";
|
|
2946
|
+
var SRC_S_WHITE = "[ \\t]";
|
|
2947
|
+
var SRC_NB_CHAR = `(?:(?!(?:${SRC_B_CHAR}|${SRC_C_BYTE_ORDER_MARK}))${SRC_C_PRINTABLE})`;
|
|
2948
|
+
var SRC_NS_CHAR = `(?:(?!${SRC_S_WHITE})${SRC_NB_CHAR})`;
|
|
2949
|
+
var SRC_NB_JSON = "[\\x09\\x20-\\uD7FF\\uE000-\\uFFFF\\u{10000}-\\u{10FFFF}]";
|
|
2950
|
+
var SRC_C_INDICATOR = "[-?:,\\[\\]{}#&*!|>'\"%@`]";
|
|
2951
|
+
var SRC_C_FLOW_INDICATOR = "[,\\[\\]{}]";
|
|
2952
|
+
var SRC_NS_PLAIN_SAFE_FLOW_OUT = SRC_NS_CHAR;
|
|
2953
|
+
var SRC_NS_PLAIN_SAFE_FLOW_IN = `(?:(?!${SRC_C_FLOW_INDICATOR})${SRC_NS_CHAR})`;
|
|
2954
|
+
var SRC_NS_PLAIN_FIRST_FLOW_OUT = `(?:(?:(?!${SRC_C_INDICATOR})${SRC_NS_CHAR})|[?:-](?=${SRC_NS_PLAIN_SAFE_FLOW_OUT}))`;
|
|
2955
|
+
var SRC_NS_PLAIN_FIRST_FLOW_IN = `(?:(?:(?!${SRC_C_INDICATOR})${SRC_NS_CHAR})|[?:-](?=${SRC_NS_PLAIN_SAFE_FLOW_IN}))`;
|
|
2956
|
+
var SRC_NS_PLAIN_CHAR_FLOW_OUT = `(?:(?:(?![:#])${SRC_NS_PLAIN_SAFE_FLOW_OUT})|:(?=${SRC_NS_PLAIN_SAFE_FLOW_OUT}))#*`;
|
|
2957
|
+
var SRC_NS_PLAIN_CHAR_FLOW_IN = `(?:(?:(?![:#])${SRC_NS_PLAIN_SAFE_FLOW_IN})|:(?=${SRC_NS_PLAIN_SAFE_FLOW_IN}))#*`;
|
|
2958
|
+
var SRC_NB_NS_PLAIN_IN_LINE_FLOW_OUT = `(?:${SRC_S_WHITE}*${SRC_NS_PLAIN_CHAR_FLOW_OUT})*`;
|
|
2959
|
+
var SRC_NB_NS_PLAIN_IN_LINE_FLOW_IN = `(?:${SRC_S_WHITE}*${SRC_NS_PLAIN_CHAR_FLOW_IN})*`;
|
|
2960
|
+
var SRC_NS_PLAIN_ONE_LINE_FLOW_OUT = `${SRC_NS_PLAIN_FIRST_FLOW_OUT}#*${SRC_NB_NS_PLAIN_IN_LINE_FLOW_OUT}`;
|
|
2961
|
+
var SRC_NS_PLAIN_ONE_LINE_FLOW_IN = `${SRC_NS_PLAIN_FIRST_FLOW_IN}#*${SRC_NB_NS_PLAIN_IN_LINE_FLOW_IN}`;
|
|
2962
|
+
var SRC_NS_PLAIN_ONE_LINE_BLOCK_KEY = SRC_NS_PLAIN_ONE_LINE_FLOW_OUT;
|
|
2963
|
+
var SRC_NS_PLAIN_ONE_LINE_FLOW_KEY = SRC_NS_PLAIN_ONE_LINE_FLOW_IN;
|
|
2964
|
+
var SRC_S_NS_PLAIN_NEXT_LINE_FLOW_OUT = `\\n+${SRC_NS_PLAIN_CHAR_FLOW_OUT}${SRC_NB_NS_PLAIN_IN_LINE_FLOW_OUT}`;
|
|
2965
|
+
var SRC_S_NS_PLAIN_NEXT_LINE_FLOW_IN = `\\n+${SRC_NS_PLAIN_CHAR_FLOW_IN}${SRC_NB_NS_PLAIN_IN_LINE_FLOW_IN}`;
|
|
2966
|
+
var SRC_NS_PLAIN_MULTI_LINE_FLOW_OUT = `${SRC_NS_PLAIN_ONE_LINE_FLOW_OUT}(?:${SRC_S_NS_PLAIN_NEXT_LINE_FLOW_OUT})*`;
|
|
2967
|
+
var SRC_NS_PLAIN_MULTI_LINE_FLOW_IN = `${SRC_NS_PLAIN_ONE_LINE_FLOW_IN}(?:${SRC_S_NS_PLAIN_NEXT_LINE_FLOW_IN})*`;
|
|
2968
|
+
var NS_PLAIN_FLOW_OUT = new RegExp(`^(?:${SRC_NS_PLAIN_MULTI_LINE_FLOW_OUT})$`, "u");
|
|
2969
|
+
var NS_PLAIN_FLOW_IN = new RegExp(`^(?:${SRC_NS_PLAIN_MULTI_LINE_FLOW_IN})$`, "u");
|
|
2970
|
+
var NS_PLAIN_BLOCK_KEY = new RegExp(`^(?:${SRC_NS_PLAIN_ONE_LINE_BLOCK_KEY})$`, "u");
|
|
2971
|
+
var NS_PLAIN_FLOW_KEY = new RegExp(`^(?:${SRC_NS_PLAIN_ONE_LINE_FLOW_KEY})$`, "u");
|
|
2972
|
+
var NB_SINGLE_ONE_LINE = new RegExp(`^(?:${SRC_NB_JSON})*$`, "u");
|
|
2973
|
+
var NB_SINGLE_MULTI_LINE = new RegExp(`^(?:${SRC_NB_JSON}|\\n)*$`, "u");
|
|
2974
|
+
var BLOCK_SCALAR_CONTENT = new RegExp(`^(?:${SRC_NB_CHAR}|\\n)*$`, "u");
|
|
2975
|
+
var C_FORBIDDEN_FIRST_LINE = /^(?:---|\.\.\.)(?=$|[ \t\n\r])/;
|
|
2976
|
+
var C_FORBIDDEN_CONTENT = /^(?:---|\.\.\.)(?=$|[ \t\n\r])/m;
|
|
2977
|
+
function canUsePlain(layout) {
|
|
2978
|
+
const str = layout.node.value;
|
|
2979
|
+
if (str !== "") {
|
|
2980
|
+
if (!(layout.isKey ? layout.flowOnly ? NS_PLAIN_FLOW_KEY : NS_PLAIN_BLOCK_KEY : layout.flowOnly ? NS_PLAIN_FLOW_IN : NS_PLAIN_FLOW_OUT).test(str))
|
|
2981
|
+
return false;
|
|
2982
|
+
if (layout.shiftOfFirstLine === 0 && C_FORBIDDEN_FIRST_LINE.test(str))
|
|
2983
|
+
return false;
|
|
2984
|
+
if (layout.shiftOfContent === 0) {
|
|
2985
|
+
const firstLineBreak = str.indexOf(`
|
|
2986
|
+
`);
|
|
2987
|
+
if (firstLineBreak !== -1) {
|
|
2988
|
+
const content = str.slice(firstLineBreak + 1);
|
|
2989
|
+
if (C_FORBIDDEN_CONTENT.test(content))
|
|
2990
|
+
return false;
|
|
2991
|
+
}
|
|
2992
|
+
}
|
|
2993
|
+
}
|
|
2994
|
+
const resolvedTag = layout.presenterOptions.schema.resolveImplicitScalarTag(str).tag.tagName;
|
|
2995
|
+
if (!layout.node.tagged && resolvedTag !== layout.node.tag)
|
|
2996
|
+
return false;
|
|
2997
|
+
if (!layout.node.tagged && str === "=" && resolvedTag === layout.presenterOptions.schema.defaultScalarTag.tagName)
|
|
2998
|
+
return false;
|
|
2999
|
+
return true;
|
|
3000
|
+
}
|
|
3001
|
+
function canUseSingleQuoted(layout) {
|
|
3002
|
+
const str = layout.node.value;
|
|
3003
|
+
if (!(layout.isKey ? NB_SINGLE_ONE_LINE : NB_SINGLE_MULTI_LINE).test(str))
|
|
3004
|
+
return false;
|
|
3005
|
+
if (/[ \t]\n|\n[ \t]/.test(str))
|
|
3006
|
+
return false;
|
|
3007
|
+
if (!layout.isKey && layout.shiftOfContent === 0) {
|
|
3008
|
+
const firstLineBreak = str.indexOf(`
|
|
3009
|
+
`);
|
|
3010
|
+
if (firstLineBreak !== -1 && C_FORBIDDEN_CONTENT.test(str.slice(firstLineBreak + 1)))
|
|
3011
|
+
return false;
|
|
3012
|
+
}
|
|
3013
|
+
return true;
|
|
3014
|
+
}
|
|
3015
|
+
function canUseBlock(layout) {
|
|
3016
|
+
if (layout.flowOnly || !BLOCK_SCALAR_CONTENT.test(layout.node.value))
|
|
3017
|
+
return false;
|
|
3018
|
+
const contentIndent = layout.shiftOfContent - layout.shiftOfParent;
|
|
3019
|
+
if (contentIndent < 1)
|
|
3020
|
+
return false;
|
|
3021
|
+
if (contentIndent > 9 && /^\n* /.test(layout.node.value))
|
|
3022
|
+
return false;
|
|
3023
|
+
if (layout.shiftOfContent === 0 && C_FORBIDDEN_CONTENT.test(layout.node.value))
|
|
3024
|
+
return false;
|
|
3025
|
+
return true;
|
|
3026
|
+
}
|
|
3027
|
+
function detectAllowedStyles(layout) {
|
|
3028
|
+
let mask = setBit(0, SCALAR_STYLE.DOUBLE_QUOTED);
|
|
3029
|
+
if (canUsePlain(layout))
|
|
3030
|
+
mask = setBit(mask, SCALAR_STYLE.PLAIN);
|
|
3031
|
+
if (canUseSingleQuoted(layout))
|
|
3032
|
+
mask = setBit(mask, SCALAR_STYLE.SINGLE_QUOTED);
|
|
3033
|
+
if (canUseBlock(layout))
|
|
3034
|
+
mask = setBit(setBit(mask, SCALAR_STYLE.LITERAL_BLOCK), SCALAR_STYLE.FOLDED_BLOCK);
|
|
3035
|
+
layout.allowedStylesMask = mask;
|
|
3036
|
+
}
|
|
3037
|
+
function renderScalar(layout) {
|
|
3038
|
+
switch (layout.style) {
|
|
3039
|
+
case SCALAR_STYLE.PLAIN:
|
|
3040
|
+
return renderPlain(layout);
|
|
3041
|
+
case SCALAR_STYLE.SINGLE_QUOTED:
|
|
3042
|
+
return renderSingleQuoted(layout);
|
|
3043
|
+
case SCALAR_STYLE.LITERAL_BLOCK:
|
|
3044
|
+
return renderLiteralBlock(layout);
|
|
3045
|
+
case SCALAR_STYLE.FOLDED_BLOCK:
|
|
3046
|
+
return renderFoldedBlock(layout);
|
|
3047
|
+
case SCALAR_STYLE.DOUBLE_QUOTED:
|
|
3048
|
+
return renderDoubleQuoted(layout);
|
|
3049
|
+
}
|
|
3050
|
+
}
|
|
3051
|
+
function renderPlain(layout) {
|
|
3052
|
+
return encodeFlowBreaks(layout.node.value, layout.shiftOfContent);
|
|
3053
|
+
}
|
|
3054
|
+
function renderSingleQuoted(layout) {
|
|
3055
|
+
return `'${encodeFlowBreaks(layout.node.value, layout.shiftOfContent).replace(/'/g, "''")}'`;
|
|
3056
|
+
}
|
|
3057
|
+
function renderLiteralBlock(layout) {
|
|
3058
|
+
const value = layout.node.value;
|
|
3059
|
+
return "|" + blockHeader(value, layout.shiftOfParent, layout.shiftOfContent) + dropEndingNewline(indentString(value, layout.shiftOfContent));
|
|
3060
|
+
}
|
|
3061
|
+
function renderFoldedBlock(layout) {
|
|
3062
|
+
const value = layout.node.value;
|
|
3063
|
+
const w = layout.presenterOptions.lineWidth;
|
|
3064
|
+
let availableWidth = Infinity;
|
|
3065
|
+
if (w !== -1)
|
|
3066
|
+
availableWidth = Math.max(Math.min(w, 40), w - layout.shiftOfContent);
|
|
3067
|
+
return ">" + blockHeader(value, layout.shiftOfParent, layout.shiftOfContent) + dropEndingNewline(indentString(foldBlockScalar(value, availableWidth), layout.shiftOfContent));
|
|
3068
|
+
}
|
|
3069
|
+
function renderDoubleQuoted(layout) {
|
|
3070
|
+
return `"${escapeString(layout.node.value)}"`;
|
|
3071
|
+
}
|
|
3072
|
+
function encodeFlowBreaks(string, shiftOfContent) {
|
|
3073
|
+
let nextLF = string.indexOf(`
|
|
3074
|
+
`);
|
|
3075
|
+
if (nextLF === -1)
|
|
3076
|
+
return string;
|
|
3077
|
+
const pad = " ".repeat(shiftOfContent);
|
|
3078
|
+
let result = string.slice(0, nextLF);
|
|
3079
|
+
const lineRe = /(\n+)([^\n]*)/g;
|
|
3080
|
+
lineRe.lastIndex = nextLF;
|
|
3081
|
+
let match;
|
|
3082
|
+
while (match = lineRe.exec(string)) {
|
|
3083
|
+
const breaks = match[1].length;
|
|
3084
|
+
const line = match[2];
|
|
3085
|
+
result += `
|
|
3086
|
+
`.repeat(breaks + 1) + pad + line;
|
|
3087
|
+
}
|
|
3088
|
+
return result;
|
|
3089
|
+
}
|
|
3090
|
+
function indentString(string, spaces) {
|
|
3091
|
+
const indent = " ".repeat(spaces);
|
|
3092
|
+
let position = 0;
|
|
3093
|
+
let result = "";
|
|
3094
|
+
const length = string.length;
|
|
3095
|
+
while (position < length) {
|
|
3096
|
+
let line;
|
|
3097
|
+
const next = string.indexOf(`
|
|
3098
|
+
`, position);
|
|
3099
|
+
if (next === -1) {
|
|
3100
|
+
line = string.slice(position);
|
|
3101
|
+
position = length;
|
|
3102
|
+
} else {
|
|
3103
|
+
line = string.slice(position, next + 1);
|
|
3104
|
+
position = next + 1;
|
|
3105
|
+
}
|
|
3106
|
+
if (line.length && line !== `
|
|
3107
|
+
`)
|
|
3108
|
+
result += indent;
|
|
3109
|
+
result += line;
|
|
3110
|
+
}
|
|
3111
|
+
return result;
|
|
3112
|
+
}
|
|
3113
|
+
function needIndentIndicator(string) {
|
|
3114
|
+
return /^\n* /.test(string);
|
|
3115
|
+
}
|
|
3116
|
+
function blockHeader(string, shiftOfParent, shiftOfContent) {
|
|
3117
|
+
const indentIndicator = needIndentIndicator(string) ? String(shiftOfContent - shiftOfParent) : "";
|
|
3118
|
+
const clip = string[string.length - 1] === `
|
|
3119
|
+
`;
|
|
3120
|
+
return `${indentIndicator}${clip && (string[string.length - 2] === `
|
|
3121
|
+
` || string === `
|
|
3122
|
+
`) ? "+" : clip ? "" : "-"}
|
|
3123
|
+
`;
|
|
3124
|
+
}
|
|
3125
|
+
function dropEndingNewline(string) {
|
|
3126
|
+
return string[string.length - 1] === `
|
|
3127
|
+
` ? string.slice(0, -1) : string;
|
|
3128
|
+
}
|
|
3129
|
+
function isMoreIndented(char) {
|
|
3130
|
+
return char === " " || char === "\t";
|
|
3131
|
+
}
|
|
3132
|
+
function foldLine(line, width) {
|
|
3133
|
+
if (line === "" || isMoreIndented(line[0]))
|
|
3134
|
+
return line;
|
|
3135
|
+
const breakRe = / [^ \t]/g;
|
|
3136
|
+
let match;
|
|
3137
|
+
let start = 0;
|
|
3138
|
+
let end;
|
|
3139
|
+
let curr = 0;
|
|
3140
|
+
let next = 0;
|
|
3141
|
+
let result = "";
|
|
3142
|
+
while (match = breakRe.exec(line)) {
|
|
3143
|
+
next = match.index;
|
|
3144
|
+
if (next - start > width) {
|
|
3145
|
+
end = curr > start ? curr : next;
|
|
3146
|
+
result += `
|
|
3147
|
+
${line.slice(start, end)}`;
|
|
3148
|
+
start = end + 1;
|
|
3149
|
+
}
|
|
3150
|
+
curr = next;
|
|
3151
|
+
}
|
|
3152
|
+
result += `
|
|
3153
|
+
`;
|
|
3154
|
+
if (line.length - start > width && curr > start)
|
|
3155
|
+
result += `${line.slice(start, curr)}
|
|
3156
|
+
${line.slice(curr + 1)}`;
|
|
3157
|
+
else
|
|
3158
|
+
result += line.slice(start);
|
|
3159
|
+
return result.slice(1);
|
|
3160
|
+
}
|
|
3161
|
+
function foldBlockScalar(string, width) {
|
|
3162
|
+
const lineRe = /(\n+)([^\n]*)/g;
|
|
3163
|
+
let nextLF = string.indexOf(`
|
|
3164
|
+
`);
|
|
3165
|
+
if (nextLF === -1)
|
|
3166
|
+
nextLF = string.length;
|
|
3167
|
+
lineRe.lastIndex = nextLF;
|
|
3168
|
+
let result = foldLine(string.slice(0, nextLF), width);
|
|
3169
|
+
let prevMoreIndented = string[0] === `
|
|
3170
|
+
` || isMoreIndented(string[0]);
|
|
3171
|
+
let moreIndented;
|
|
3172
|
+
let match;
|
|
3173
|
+
while (match = lineRe.exec(string)) {
|
|
3174
|
+
const prefix = match[1];
|
|
3175
|
+
const line = match[2];
|
|
3176
|
+
moreIndented = line !== "" && isMoreIndented(line[0]);
|
|
3177
|
+
result += prefix + (!prevMoreIndented && !moreIndented && line !== "" ? `
|
|
3178
|
+
` : "") + foldLine(line, width);
|
|
3179
|
+
prevMoreIndented = moreIndented;
|
|
3180
|
+
}
|
|
3181
|
+
return result;
|
|
3182
|
+
}
|
|
3183
|
+
var CHARACTERS_TO_ESCAPE = /["\\\x00-\x1F\x7F-\xA0\u2028\u2029\uD800-\uDFFF\uFEFF\uFFFE\uFFFF]/gu;
|
|
3184
|
+
function escapeCharacter(character) {
|
|
3185
|
+
switch (character) {
|
|
3186
|
+
case "\x00":
|
|
3187
|
+
return "\\0";
|
|
3188
|
+
case "\x07":
|
|
3189
|
+
return "\\a";
|
|
3190
|
+
case "\b":
|
|
3191
|
+
return "\\b";
|
|
3192
|
+
case "\t":
|
|
3193
|
+
return "\\t";
|
|
3194
|
+
case `
|
|
3195
|
+
`:
|
|
3196
|
+
return "\\n";
|
|
3197
|
+
case "\v":
|
|
3198
|
+
return "\\v";
|
|
3199
|
+
case "\f":
|
|
3200
|
+
return "\\f";
|
|
3201
|
+
case "\r":
|
|
3202
|
+
return "\\r";
|
|
3203
|
+
case "\x1B":
|
|
3204
|
+
return "\\e";
|
|
3205
|
+
case '"':
|
|
3206
|
+
return "\\\"";
|
|
3207
|
+
case "\\":
|
|
3208
|
+
return "\\\\";
|
|
3209
|
+
case "
":
|
|
3210
|
+
return "\\N";
|
|
3211
|
+
case " ":
|
|
3212
|
+
return "\\_";
|
|
3213
|
+
case "\u2028":
|
|
3214
|
+
return "\\L";
|
|
3215
|
+
case "\u2029":
|
|
3216
|
+
return "\\P";
|
|
3217
|
+
}
|
|
3218
|
+
const code = character.charCodeAt(0);
|
|
3219
|
+
const hex = code.toString(16).toUpperCase();
|
|
3220
|
+
if (code <= 255)
|
|
3221
|
+
return `\\x${"0".repeat(2 - hex.length)}${hex}`;
|
|
3222
|
+
return `\\u${"0".repeat(4 - hex.length)}${hex}`;
|
|
3223
|
+
}
|
|
3224
|
+
function escapeString(string) {
|
|
3225
|
+
return string.replace(CHARACTERS_TO_ESCAPE, escapeCharacter);
|
|
3226
|
+
}
|
|
3227
|
+
var CHAR_LINE_FEED = 10;
|
|
3228
|
+
var DEFAULT_PRESENTER_OPTIONS = {
|
|
3229
|
+
indent: 2,
|
|
3230
|
+
seqNoIndent: false,
|
|
3231
|
+
seqInlineFirst: true,
|
|
3232
|
+
lineWidth: 80,
|
|
3233
|
+
flowBracketPadding: false,
|
|
3234
|
+
flowSkipCommaSpace: false,
|
|
3235
|
+
flowSkipColonSpace: false,
|
|
3236
|
+
quoteFlowKeys: false,
|
|
3237
|
+
quoteStyle: "single",
|
|
3238
|
+
forceQuotes: false,
|
|
3239
|
+
scalarStyleRules: Object.keys(DEFAULT_SCALAR_STYLE_RULES).map((name) => Reflect.get(DEFAULT_SCALAR_STYLE_RULES, name)),
|
|
3240
|
+
tagBeforeAnchor: false
|
|
3241
|
+
};
|
|
3242
|
+
function nodeTagShort(node) {
|
|
3243
|
+
return node.tagged ? node.tag : tagNameShort(node.tag);
|
|
3244
|
+
}
|
|
3245
|
+
function createPresenterState(options) {
|
|
3246
|
+
const opts = {
|
|
3247
|
+
...DEFAULT_PRESENTER_OPTIONS,
|
|
3248
|
+
...options
|
|
3249
|
+
};
|
|
3250
|
+
if (opts.flowSkipColonSpace)
|
|
3251
|
+
opts.quoteFlowKeys = true;
|
|
3252
|
+
return {
|
|
3253
|
+
...opts,
|
|
3254
|
+
defaultScalarTagName: opts.schema.defaultScalarTag.tagName,
|
|
3255
|
+
openEnded: false
|
|
3256
|
+
};
|
|
3257
|
+
}
|
|
3258
|
+
function generateNextLine(state, level) {
|
|
3259
|
+
return `
|
|
3260
|
+
${" ".repeat(state.indent * level)}`;
|
|
3261
|
+
}
|
|
3262
|
+
function scalarLayout(state, node, parent, level, isKey, flowOnly) {
|
|
3263
|
+
return {
|
|
3264
|
+
node,
|
|
3265
|
+
parent,
|
|
3266
|
+
level,
|
|
3267
|
+
isKey,
|
|
3268
|
+
flowOnly,
|
|
3269
|
+
shiftOfParent: level === 0 ? -1 : state.indent * (level - 1),
|
|
3270
|
+
shiftOfContent: state.indent * Math.max(1, level),
|
|
3271
|
+
shiftOfFirstLine: level === 0 ? 0 : state.indent * level,
|
|
3272
|
+
presenterOptions: state,
|
|
3273
|
+
allowedStylesMask: 0,
|
|
3274
|
+
style: node.style
|
|
3275
|
+
};
|
|
3276
|
+
}
|
|
3277
|
+
function writeFlowSequence(state, level, node) {
|
|
3278
|
+
let result = "";
|
|
3279
|
+
for (let index = 0, length = node.items.length;index < length; index += 1) {
|
|
3280
|
+
const item = writeNode(state, level, node.items[index], node, {}).text;
|
|
3281
|
+
if (index > 0)
|
|
3282
|
+
result += `,${!state.flowSkipCommaSpace ? " " : ""}`;
|
|
3283
|
+
result += item;
|
|
3284
|
+
}
|
|
3285
|
+
const pad = state.flowBracketPadding && node.items.length > 0 ? " " : "";
|
|
3286
|
+
return `[${pad}${result}${pad}]`;
|
|
3287
|
+
}
|
|
3288
|
+
function writeBlockSequence(state, level, node, compact) {
|
|
3289
|
+
let result = "";
|
|
3290
|
+
for (let index = 0, length = node.items.length;index < length; index += 1) {
|
|
3291
|
+
const item = writeNode(state, level + 1, node.items[index], node, {
|
|
3292
|
+
block: true,
|
|
3293
|
+
compact: state.seqInlineFirst,
|
|
3294
|
+
isblockseq: true
|
|
3295
|
+
}).text;
|
|
3296
|
+
if (!compact || result !== "")
|
|
3297
|
+
result += generateNextLine(state, level);
|
|
3298
|
+
if (item === "" || CHAR_LINE_FEED === item.charCodeAt(0))
|
|
3299
|
+
result += "-";
|
|
3300
|
+
else
|
|
3301
|
+
result += "- ";
|
|
3302
|
+
result += item;
|
|
3303
|
+
}
|
|
3304
|
+
return result;
|
|
3305
|
+
}
|
|
3306
|
+
function writeFlowMapping(state, level, node) {
|
|
3307
|
+
let result = "";
|
|
3308
|
+
for (const { key, value } of node.items) {
|
|
3309
|
+
let pairBuffer = "";
|
|
3310
|
+
if (result !== "")
|
|
3311
|
+
pairBuffer += `,${!state.flowSkipCommaSpace ? " " : ""}`;
|
|
3312
|
+
const keyRender = writeNode(state, level, key, node, { iskey: true });
|
|
3313
|
+
const keyText = keyRender.text;
|
|
3314
|
+
const valueText = writeNode(state, level, value, node, {}).text;
|
|
3315
|
+
const sep = state.flowSkipColonSpace || valueText === "" ? "" : " ";
|
|
3316
|
+
const keyIsBareProps = key.kind === "scalar" && keyRender.noBody && (key.tagged || key.anchor !== undefined);
|
|
3317
|
+
const keyColonSep = key.kind === "alias" || keyIsBareProps ? " " : "";
|
|
3318
|
+
pairBuffer += `${keyText}${keyColonSep}:${sep}${valueText}`;
|
|
3319
|
+
result += pairBuffer;
|
|
3320
|
+
}
|
|
3321
|
+
const pad = state.flowBracketPadding && result !== "" ? " " : "";
|
|
3322
|
+
return `{${pad}${result}${pad}}`;
|
|
3323
|
+
}
|
|
3324
|
+
function writeBlockMapping(state, level, node, compact) {
|
|
3325
|
+
let result = "";
|
|
3326
|
+
for (let index = 0, length = node.items.length;index < length; index += 1) {
|
|
3327
|
+
let pairBuffer = "";
|
|
3328
|
+
if (!compact || result !== "")
|
|
3329
|
+
pairBuffer += generateNextLine(state, level);
|
|
3330
|
+
const { key, value } = node.items[index];
|
|
3331
|
+
const keyIsBlock = (key.kind === "mapping" || key.kind === "sequence") && key.style === COLLECTION_STYLE.BLOCK && key.items.length !== 0 || key.kind === "scalar" && (key.style === SCALAR_STYLE.LITERAL_BLOCK || key.style === SCALAR_STYLE.FOLDED_BLOCK);
|
|
3332
|
+
const keyRender = keyIsBlock ? writeNode(state, level + 1, key, node, {
|
|
3333
|
+
block: true,
|
|
3334
|
+
compact: true,
|
|
3335
|
+
isblockseq: !cannotBeCompact(state, key, level + 1)
|
|
3336
|
+
}) : writeNode(state, level + 1, key, node, {
|
|
3337
|
+
block: true,
|
|
3338
|
+
compact: true,
|
|
3339
|
+
iskey: true
|
|
3340
|
+
});
|
|
3341
|
+
const keyText = keyRender.text;
|
|
3342
|
+
const keyHasLineBreak = key.kind === "scalar" && key.value.indexOf(`
|
|
3343
|
+
`) !== -1;
|
|
3344
|
+
const keyIsTooLong = keyText.length > 1024 && /^[\s\S]{1025}/u.test(keyText);
|
|
3345
|
+
const explicitPair = keyIsBlock || keyHasLineBreak || keyIsTooLong;
|
|
3346
|
+
if (explicitPair)
|
|
3347
|
+
if (keyText && CHAR_LINE_FEED === keyText.charCodeAt(0))
|
|
3348
|
+
pairBuffer += "?";
|
|
3349
|
+
else
|
|
3350
|
+
pairBuffer += "? ";
|
|
3351
|
+
pairBuffer += keyText;
|
|
3352
|
+
if (explicitPair)
|
|
3353
|
+
pairBuffer += generateNextLine(state, level);
|
|
3354
|
+
const valueText = writeNode(state, level + 1, value, node, {
|
|
3355
|
+
block: true,
|
|
3356
|
+
compact: explicitPair,
|
|
3357
|
+
isblockseq: explicitPair && !cannotBeCompact(state, value, level + 1)
|
|
3358
|
+
}).text;
|
|
3359
|
+
const keyIsBareProps = key.kind === "scalar" && keyRender.noBody && (key.tagged || key.anchor !== undefined);
|
|
3360
|
+
const keyColonSep = !explicitPair && (key.kind === "alias" || keyIsBareProps) ? " " : "";
|
|
3361
|
+
if (valueText === "" || CHAR_LINE_FEED === valueText.charCodeAt(0))
|
|
3362
|
+
pairBuffer += `${keyColonSep}:`;
|
|
3363
|
+
else
|
|
3364
|
+
pairBuffer += `${keyColonSep}: `;
|
|
3365
|
+
pairBuffer += valueText;
|
|
3366
|
+
result += pairBuffer;
|
|
3367
|
+
}
|
|
3368
|
+
return result;
|
|
3369
|
+
}
|
|
3370
|
+
function cannotBeCompact(state, node, level) {
|
|
3371
|
+
if (node.kind === "alias")
|
|
3372
|
+
return true;
|
|
3373
|
+
return node.tagged || node.anchor !== undefined || state.indent < 2 && level > 0;
|
|
3374
|
+
}
|
|
3375
|
+
function writeNode(state, level, node, parent, ctx) {
|
|
3376
|
+
if (node.kind === "alias") {
|
|
3377
|
+
state.openEnded = false;
|
|
3378
|
+
return {
|
|
3379
|
+
text: `*${node.anchor}`,
|
|
3380
|
+
noBody: false
|
|
3381
|
+
};
|
|
3382
|
+
}
|
|
3383
|
+
const { block = false, iskey = false, isblockseq = false } = ctx;
|
|
3384
|
+
let compact = ctx.compact ?? false;
|
|
3385
|
+
const hasAnchor = node.anchor !== undefined;
|
|
3386
|
+
if (cannotBeCompact(state, node, level))
|
|
3387
|
+
compact = false;
|
|
3388
|
+
let body;
|
|
3389
|
+
let shouldPrintTag = node.tagged;
|
|
3390
|
+
const useBlockCollection = block && (node.kind === "mapping" || node.kind === "sequence") && node.style === COLLECTION_STYLE.BLOCK && node.items.length !== 0;
|
|
3391
|
+
if (node.kind === "mapping")
|
|
3392
|
+
if (useBlockCollection)
|
|
3393
|
+
body = writeBlockMapping(state, level, node, compact);
|
|
3394
|
+
else
|
|
3395
|
+
body = writeFlowMapping(state, level, node);
|
|
3396
|
+
else if (node.kind === "sequence")
|
|
3397
|
+
if (useBlockCollection)
|
|
3398
|
+
if (state.seqNoIndent && !isblockseq && level > 0)
|
|
3399
|
+
body = writeBlockSequence(state, level - 1, node, compact);
|
|
3400
|
+
else
|
|
3401
|
+
body = writeBlockSequence(state, level, node, compact);
|
|
3402
|
+
else
|
|
3403
|
+
body = writeFlowSequence(state, level, node);
|
|
3404
|
+
else {
|
|
3405
|
+
const layout = scalarLayout(state, node, parent, level, iskey, !block);
|
|
3406
|
+
detectAllowedStyles(layout);
|
|
3407
|
+
for (const rule of state.scalarStyleRules)
|
|
3408
|
+
rule(layout);
|
|
3409
|
+
body = renderScalar(layout);
|
|
3410
|
+
state.openEnded = (layout.style === SCALAR_STYLE.LITERAL_BLOCK || layout.style === SCALAR_STYLE.FOLDED_BLOCK) && (node.value === `
|
|
3411
|
+
` || node.value.endsWith(`
|
|
3412
|
+
|
|
3413
|
+
`));
|
|
3414
|
+
shouldPrintTag = node.tagged || body === "" && layout.flowOnly && parent?.kind === "sequence" && !hasAnchor || layout.style !== SCALAR_STYLE.PLAIN && node.tag !== state.defaultScalarTagName;
|
|
3415
|
+
}
|
|
3416
|
+
if ((node.kind === "mapping" || node.kind === "sequence") && !useBlockCollection)
|
|
3417
|
+
state.openEnded = false;
|
|
3418
|
+
if (useBlockCollection && compact && level > 0 && state.indent > 2)
|
|
3419
|
+
body = `${" ".repeat(state.indent - 2)}${body}`;
|
|
3420
|
+
const noBody = body === "";
|
|
3421
|
+
let text = body;
|
|
3422
|
+
if (shouldPrintTag || hasAnchor) {
|
|
3423
|
+
const props = [];
|
|
3424
|
+
const tag = shouldPrintTag ? nodeTagShort(node) : null;
|
|
3425
|
+
const anchor = hasAnchor ? `&${node.anchor}` : null;
|
|
3426
|
+
if (state.tagBeforeAnchor) {
|
|
3427
|
+
if (tag !== null)
|
|
3428
|
+
props.push(tag);
|
|
3429
|
+
if (anchor !== null)
|
|
3430
|
+
props.push(anchor);
|
|
3431
|
+
} else {
|
|
3432
|
+
if (anchor !== null)
|
|
3433
|
+
props.push(anchor);
|
|
3434
|
+
if (tag !== null)
|
|
3435
|
+
props.push(tag);
|
|
3436
|
+
}
|
|
3437
|
+
const sep = body === "" || body.charCodeAt(0) === CHAR_LINE_FEED ? "" : " ";
|
|
3438
|
+
text = `${props.join(" ")}${sep}${body}`;
|
|
3439
|
+
}
|
|
3440
|
+
return {
|
|
3441
|
+
text,
|
|
3442
|
+
noBody
|
|
3443
|
+
};
|
|
3444
|
+
}
|
|
3445
|
+
function rootStartsOwnLine(node) {
|
|
3446
|
+
return (node.kind === "sequence" || node.kind === "mapping") && node.style === COLLECTION_STYLE.BLOCK && node.items.length !== 0 && !node.tagged && node.anchor === undefined;
|
|
3447
|
+
}
|
|
3448
|
+
function writeDocumentDirectives(doc) {
|
|
3449
|
+
let result = "";
|
|
3450
|
+
for (const directive of doc.directives) {
|
|
3451
|
+
if (directive.kind === "yaml") {
|
|
3452
|
+
result += `%YAML ${directive.version}
|
|
3453
|
+
`;
|
|
3454
|
+
continue;
|
|
3455
|
+
}
|
|
3456
|
+
const { handle, prefix } = directive;
|
|
3457
|
+
result += `%TAG ${handle} ${prefix}
|
|
3458
|
+
`;
|
|
3459
|
+
}
|
|
3460
|
+
return result;
|
|
3461
|
+
}
|
|
3462
|
+
function present(documents, options) {
|
|
3463
|
+
const state = createPresenterState(options);
|
|
3464
|
+
let result = "";
|
|
3465
|
+
let previousEnded = false;
|
|
3466
|
+
for (let index = 0;index < documents.length; index += 1) {
|
|
3467
|
+
const doc = documents[index];
|
|
3468
|
+
state.openEnded = false;
|
|
3469
|
+
const directives = writeDocumentDirectives(doc);
|
|
3470
|
+
const hasDirectives = directives !== "";
|
|
3471
|
+
const marker = doc.explicitStart || hasDirectives || index > 0 && !previousEnded;
|
|
3472
|
+
result += directives;
|
|
3473
|
+
if (doc.contents === null) {
|
|
3474
|
+
if (marker)
|
|
3475
|
+
result += `---
|
|
3476
|
+
`;
|
|
3477
|
+
} else if (marker) {
|
|
3478
|
+
const body = writeNode(state, 0, doc.contents, null, {
|
|
3479
|
+
block: true,
|
|
3480
|
+
compact: true
|
|
3481
|
+
}).text;
|
|
3482
|
+
const sep = body === "" ? "" : hasDirectives || rootStartsOwnLine(doc.contents) ? `
|
|
3483
|
+
` : " ";
|
|
3484
|
+
result += `---${sep}${body}
|
|
3485
|
+
`;
|
|
3486
|
+
} else
|
|
3487
|
+
result += writeNode(state, 0, doc.contents, null, {
|
|
3488
|
+
block: true,
|
|
3489
|
+
compact: true
|
|
3490
|
+
}).text + `
|
|
3491
|
+
`;
|
|
3492
|
+
previousEnded = doc.explicitEnd || state.openEnded;
|
|
3493
|
+
if (previousEnded)
|
|
3494
|
+
result += `...
|
|
3495
|
+
`;
|
|
3496
|
+
}
|
|
3497
|
+
return result;
|
|
3498
|
+
}
|
|
3499
|
+
var DEFAULT_DUMP_OPTIONS = {
|
|
3500
|
+
...DEFAULT_PRESENTER_OPTIONS,
|
|
3501
|
+
schema: DUMP_SCHEMA,
|
|
3502
|
+
skipInvalid: false,
|
|
3503
|
+
noRefs: false,
|
|
3504
|
+
flowLevel: -1,
|
|
3505
|
+
sortKeys: false,
|
|
3506
|
+
transform: () => {}
|
|
3507
|
+
};
|
|
3508
|
+
function defaultCompareFn(a, b) {
|
|
3509
|
+
const x = String(a);
|
|
3510
|
+
const y = String(b);
|
|
3511
|
+
if (x < y)
|
|
3512
|
+
return -1;
|
|
3513
|
+
if (x > y)
|
|
3514
|
+
return 1;
|
|
3515
|
+
return 0;
|
|
3516
|
+
}
|
|
3517
|
+
function dump(input, options = {}) {
|
|
3518
|
+
const opts = {
|
|
3519
|
+
...DEFAULT_DUMP_OPTIONS,
|
|
3520
|
+
...options
|
|
3521
|
+
};
|
|
3522
|
+
const documents = jsToAst(input, opts.schema, {
|
|
3523
|
+
noRefs: opts.noRefs,
|
|
3524
|
+
skipInvalid: opts.skipInvalid
|
|
3525
|
+
});
|
|
3526
|
+
if (opts.flowLevel >= 0)
|
|
3527
|
+
visit(documents, (node, ctx) => {
|
|
3528
|
+
if (ctx.depth < opts.flowLevel)
|
|
3529
|
+
return;
|
|
3530
|
+
if (node.kind === "sequence" || node.kind === "mapping")
|
|
3531
|
+
node.style = COLLECTION_STYLE.FLOW;
|
|
3532
|
+
return VISIT_SKIP;
|
|
3533
|
+
});
|
|
3534
|
+
if (opts.sortKeys) {
|
|
3535
|
+
const compareFn = opts.sortKeys === true ? defaultCompareFn : opts.sortKeys;
|
|
3536
|
+
visit(documents, (node) => {
|
|
3537
|
+
if (node.kind !== "mapping")
|
|
3538
|
+
return;
|
|
3539
|
+
node.items.sort((a, b) => compareFn(a.key.kind === "scalar" ? a.key.value : "", b.key.kind === "scalar" ? b.key.value : ""));
|
|
3540
|
+
});
|
|
3541
|
+
}
|
|
3542
|
+
opts.transform(documents);
|
|
3543
|
+
return present(documents, {
|
|
3544
|
+
...pick(opts, Object.keys(DEFAULT_PRESENTER_OPTIONS)),
|
|
3545
|
+
schema: opts.schema
|
|
3546
|
+
});
|
|
3547
|
+
}
|
|
3548
|
+
var EVENT_DOCUMENT = EVENT_ID.DOCUMENT;
|
|
3549
|
+
var EVENT_SEQUENCE = EVENT_ID.SEQUENCE;
|
|
3550
|
+
var EVENT_MAPPING = EVENT_ID.MAPPING;
|
|
3551
|
+
var EVENT_SCALAR = EVENT_ID.SCALAR;
|
|
3552
|
+
var EVENT_ALIAS = EVENT_ID.ALIAS;
|
|
3553
|
+
var EVENT_POP = EVENT_ID.POP;
|
|
3554
|
+
var SCALAR_STYLE_PLAIN = SCALAR_STYLE.PLAIN;
|
|
3555
|
+
var SCALAR_STYLE_SINGLE_QUOTED = SCALAR_STYLE.SINGLE_QUOTED;
|
|
3556
|
+
var SCALAR_STYLE_DOUBLE_QUOTED = SCALAR_STYLE.DOUBLE_QUOTED;
|
|
3557
|
+
var SCALAR_STYLE_LITERAL_BLOCK = SCALAR_STYLE.LITERAL_BLOCK;
|
|
3558
|
+
var SCALAR_STYLE_FOLDED_BLOCK = SCALAR_STYLE.FOLDED_BLOCK;
|
|
3559
|
+
var COLLECTION_STYLE_BLOCK = COLLECTION_STYLE.BLOCK;
|
|
3560
|
+
var COLLECTION_STYLE_FLOW = COLLECTION_STYLE.FLOW;
|
|
3561
|
+
var CHOMPING_CLIP = CHOMPING_MODE.CLIP;
|
|
3562
|
+
var CHOMPING_STRIP = CHOMPING_MODE.STRIP;
|
|
3563
|
+
var CHOMPING_KEEP = CHOMPING_MODE.KEEP;
|
|
3564
|
+
|
|
3565
|
+
// src/tools/index.ts
|
|
3566
|
+
import { z as z4 } from "zod";
|
|
3567
|
+
|
|
3568
|
+
// src/model/record.ts
|
|
3569
|
+
import { z } from "zod";
|
|
3570
|
+
var RecordTypes = ["REQ", "CONSTRAINT", "ASSUMPTION", "DEC"];
|
|
3571
|
+
var RecordStatuses = ["proposed", "accepted", "rejected", "superseded"];
|
|
3572
|
+
var LinkRelations = ["refines", "depends_on", "constrains", "relates_to"];
|
|
3573
|
+
var TypeOrder = {
|
|
3574
|
+
REQ: 0,
|
|
3575
|
+
CONSTRAINT: 1,
|
|
3576
|
+
ASSUMPTION: 2,
|
|
3577
|
+
DEC: 3
|
|
3578
|
+
};
|
|
3579
|
+
function recordIdPattern(type) {
|
|
3580
|
+
return new RegExp(`^${type}-\\d{4}$`);
|
|
3581
|
+
}
|
|
3582
|
+
var RecordId = z.string().superRefine((val, ctx) => {
|
|
3583
|
+
const type = RecordTypes.find((t) => val.startsWith(`${t}-`));
|
|
3584
|
+
if (!type) {
|
|
3585
|
+
ctx.addIssue({
|
|
3586
|
+
code: z.ZodIssueCode.custom,
|
|
3587
|
+
message: `Record id must start with a valid type prefix (${RecordTypes.join(", ")})`
|
|
3588
|
+
});
|
|
3589
|
+
return;
|
|
3590
|
+
}
|
|
3591
|
+
if (!recordIdPattern(type).test(val)) {
|
|
3592
|
+
ctx.addIssue({
|
|
3593
|
+
code: z.ZodIssueCode.custom,
|
|
3594
|
+
message: `Record id for type ${type} must match ${type}-NNNN (four digits, zero-padded)`
|
|
3595
|
+
});
|
|
3596
|
+
}
|
|
3597
|
+
});
|
|
3598
|
+
var LinkSchema = z.object({
|
|
3599
|
+
type: z.enum(LinkRelations),
|
|
3600
|
+
target: RecordId,
|
|
3601
|
+
rationale: z.string().min(1, "Link rationale is required")
|
|
3602
|
+
});
|
|
3603
|
+
var BaseRecordFields = {
|
|
3604
|
+
schema_version: z.literal("1.0"),
|
|
3605
|
+
title: z.string().min(1, "Title is required"),
|
|
3606
|
+
status: z.enum(RecordStatuses),
|
|
3607
|
+
owner: z.string().min(1, "Owner is required"),
|
|
3608
|
+
change_authority: z.string().min(1, "Change authority is required"),
|
|
3609
|
+
supersedes: z.array(RecordId).default([]),
|
|
3610
|
+
status_reason: z.string().optional(),
|
|
3611
|
+
links: z.array(LinkSchema).default([])
|
|
3612
|
+
};
|
|
3613
|
+
function createRecordSchema(type) {
|
|
3614
|
+
return z.object({
|
|
3615
|
+
...BaseRecordFields,
|
|
3616
|
+
type: z.literal(type),
|
|
3617
|
+
id: RecordId.superRefine((val, ctx) => {
|
|
3618
|
+
if (!val.startsWith(`${type}-`)) {
|
|
3619
|
+
ctx.addIssue({
|
|
3620
|
+
code: z.ZodIssueCode.custom,
|
|
3621
|
+
message: `Id must start with ${type}- for a ${type} record`
|
|
3622
|
+
});
|
|
3623
|
+
}
|
|
3624
|
+
})
|
|
3625
|
+
});
|
|
3626
|
+
}
|
|
3627
|
+
var ReqRecordSchema = createRecordSchema("REQ");
|
|
3628
|
+
var ConstraintRecordSchema = createRecordSchema("CONSTRAINT");
|
|
3629
|
+
var AssumptionRecordSchema = createRecordSchema("ASSUMPTION").extend({
|
|
3630
|
+
needed_to_close: z.string().min(1, "needed_to_close is required")
|
|
3631
|
+
});
|
|
3632
|
+
var DecRecordSchema = createRecordSchema("DEC").extend({
|
|
3633
|
+
decision: z.string().min(1, "Decision is required"),
|
|
3634
|
+
alternatives_rejected: z.array(z.object({
|
|
3635
|
+
alternative: z.string().min(1, "Alternative is required"),
|
|
3636
|
+
rejected_because: z.string().min(1, "Rejection reason is required")
|
|
3637
|
+
})).default([]),
|
|
3638
|
+
consequences: z.string().min(1, "Consequences are required")
|
|
3639
|
+
});
|
|
3640
|
+
var RecordSchema = z.discriminatedUnion("type", [
|
|
3641
|
+
ReqRecordSchema,
|
|
3642
|
+
ConstraintRecordSchema,
|
|
3643
|
+
AssumptionRecordSchema,
|
|
3644
|
+
DecRecordSchema
|
|
3645
|
+
]);
|
|
3646
|
+
var BaseAddInputFields = {
|
|
3647
|
+
title: z.string().min(1, "Title is required"),
|
|
3648
|
+
owner: z.string().optional(),
|
|
3649
|
+
change_authority: z.string().optional(),
|
|
3650
|
+
supersedes: z.array(RecordId).optional(),
|
|
3651
|
+
links: z.array(LinkSchema).optional()
|
|
3652
|
+
};
|
|
3653
|
+
var AddRecordInputSchema = z.discriminatedUnion("type", [
|
|
3654
|
+
z.object({ ...BaseAddInputFields, type: z.literal("REQ") }),
|
|
3655
|
+
z.object({ ...BaseAddInputFields, type: z.literal("CONSTRAINT") }),
|
|
3656
|
+
z.object({
|
|
3657
|
+
...BaseAddInputFields,
|
|
3658
|
+
type: z.literal("ASSUMPTION"),
|
|
3659
|
+
needed_to_close: z.string().min(1, "needed_to_close is required")
|
|
3660
|
+
}),
|
|
3661
|
+
z.object({
|
|
3662
|
+
...BaseAddInputFields,
|
|
3663
|
+
type: z.literal("DEC"),
|
|
3664
|
+
decision: z.string().min(1, "Decision is required"),
|
|
3665
|
+
alternatives_rejected: z.array(z.object({
|
|
3666
|
+
alternative: z.string().min(1, "Alternative is required"),
|
|
3667
|
+
rejected_because: z.string().min(1, "Rejection reason is required")
|
|
3668
|
+
})).optional(),
|
|
3669
|
+
consequences: z.string().min(1, "Consequences are required")
|
|
3670
|
+
})
|
|
3671
|
+
]);
|
|
3672
|
+
function sortRecords(records) {
|
|
3673
|
+
return [...records].sort((a, b) => {
|
|
3674
|
+
const typeDiff = TypeOrder[a.type] - TypeOrder[b.type];
|
|
3675
|
+
if (typeDiff !== 0)
|
|
3676
|
+
return typeDiff;
|
|
3677
|
+
const aNum = Number.parseInt(a.id.split("-")[1], 10);
|
|
3678
|
+
const bNum = Number.parseInt(b.id.split("-")[1], 10);
|
|
3679
|
+
return aNum - bNum;
|
|
3680
|
+
});
|
|
3681
|
+
}
|
|
3682
|
+
|
|
3683
|
+
// src/register/register.ts
|
|
3684
|
+
import fs from "node:fs";
|
|
3685
|
+
import path from "node:path";
|
|
3686
|
+
import { z as z2 } from "zod";
|
|
3687
|
+
var WorkspaceSchema = z2.object({
|
|
3688
|
+
id: z2.string().min(1, "Workspace id is required"),
|
|
3689
|
+
title: z2.string().min(1, "Workspace title is required"),
|
|
3690
|
+
owner: z2.string().min(1, "Workspace owner is required"),
|
|
3691
|
+
change_authority: z2.string().min(1, "Workspace change_authority is required")
|
|
3692
|
+
});
|
|
3693
|
+
var RegisterSchema = z2.object({
|
|
3694
|
+
schema_version: z2.literal("1.0"),
|
|
3695
|
+
workspace: WorkspaceSchema,
|
|
3696
|
+
records: z2.array(RecordSchema)
|
|
3697
|
+
});
|
|
3698
|
+
var allowedTransitions = {
|
|
3699
|
+
proposed: ["accepted", "rejected", "superseded"]
|
|
3700
|
+
};
|
|
3701
|
+
var RegisterKeyOrder = {
|
|
3702
|
+
schema_version: 0,
|
|
3703
|
+
workspace: 1,
|
|
3704
|
+
records: 2
|
|
3705
|
+
};
|
|
3706
|
+
var WorkspaceKeyOrder = {
|
|
3707
|
+
id: 0,
|
|
3708
|
+
title: 1,
|
|
3709
|
+
owner: 2,
|
|
3710
|
+
change_authority: 3
|
|
3711
|
+
};
|
|
3712
|
+
var RecordKeyOrder = {
|
|
3713
|
+
schema_version: 0,
|
|
3714
|
+
id: 1,
|
|
3715
|
+
type: 2,
|
|
3716
|
+
title: 3,
|
|
3717
|
+
status: 4,
|
|
3718
|
+
owner: 5,
|
|
3719
|
+
change_authority: 6,
|
|
3720
|
+
supersedes: 7,
|
|
3721
|
+
status_reason: 8,
|
|
3722
|
+
links: 9,
|
|
3723
|
+
needed_to_close: 10,
|
|
3724
|
+
decision: 11,
|
|
3725
|
+
alternatives_rejected: 12,
|
|
3726
|
+
consequences: 13
|
|
3727
|
+
};
|
|
3728
|
+
var LinkKeyOrder = {
|
|
3729
|
+
type: 0,
|
|
3730
|
+
target: 1,
|
|
3731
|
+
rationale: 2
|
|
3732
|
+
};
|
|
3733
|
+
var AlternativeKeyOrder = {
|
|
3734
|
+
alternative: 0,
|
|
3735
|
+
rejected_because: 1
|
|
3736
|
+
};
|
|
3737
|
+
function formatZodError(filePath, error) {
|
|
3738
|
+
const issues = error.issues.map((issue) => {
|
|
3739
|
+
const location = issue.path.length > 0 ? issue.path.join(".") : "<root>";
|
|
3740
|
+
return `${location}: ${issue.message}`;
|
|
3741
|
+
}).join("; ");
|
|
3742
|
+
return `Validation failed for ${filePath}: ${issues}`;
|
|
3743
|
+
}
|
|
3744
|
+
function validateLinkIntegrity(register) {
|
|
3745
|
+
const ids = new Set(register.records.map((r) => r.id));
|
|
3746
|
+
for (const record of register.records) {
|
|
3747
|
+
for (const link of record.links) {
|
|
3748
|
+
if (!ids.has(link.target)) {
|
|
3749
|
+
return `Record ${record.id} links to non-existent target ${link.target}`;
|
|
3750
|
+
}
|
|
3751
|
+
}
|
|
3752
|
+
for (const target of record.supersedes) {
|
|
3753
|
+
if (!ids.has(target)) {
|
|
3754
|
+
return `Record ${record.id} supersedes non-existent target ${target}`;
|
|
3755
|
+
}
|
|
3756
|
+
}
|
|
3757
|
+
}
|
|
3758
|
+
}
|
|
3759
|
+
function sortObjectKeys(obj, order) {
|
|
3760
|
+
const sorted = {};
|
|
3761
|
+
const entries = Object.entries(obj).sort((a, b) => {
|
|
3762
|
+
const aOrder = order[a[0]] ?? Number.MAX_SAFE_INTEGER;
|
|
3763
|
+
const bOrder = order[b[0]] ?? Number.MAX_SAFE_INTEGER;
|
|
3764
|
+
if (aOrder !== bOrder)
|
|
3765
|
+
return aOrder - bOrder;
|
|
3766
|
+
return a[0].localeCompare(b[0]);
|
|
3767
|
+
});
|
|
3768
|
+
for (const [key, value] of entries) {
|
|
3769
|
+
sorted[key] = value;
|
|
3770
|
+
}
|
|
3771
|
+
return sorted;
|
|
3772
|
+
}
|
|
3773
|
+
function normalizeRecord(record) {
|
|
3774
|
+
const base = sortObjectKeys(record, RecordKeyOrder);
|
|
3775
|
+
if (base.status_reason === undefined) {
|
|
3776
|
+
delete base.status_reason;
|
|
3777
|
+
}
|
|
3778
|
+
if (Array.isArray(base.links)) {
|
|
3779
|
+
base.links = base.links.map((link) => sortObjectKeys(link, LinkKeyOrder));
|
|
3780
|
+
}
|
|
3781
|
+
if (Array.isArray(base.alternatives_rejected)) {
|
|
3782
|
+
base.alternatives_rejected = base.alternatives_rejected.map((alt) => sortObjectKeys(alt, AlternativeKeyOrder));
|
|
3783
|
+
}
|
|
3784
|
+
return base;
|
|
3785
|
+
}
|
|
3786
|
+
function serializeRegister(register) {
|
|
3787
|
+
const sortedWorkspace = sortObjectKeys(register.workspace, WorkspaceKeyOrder);
|
|
3788
|
+
const sortedRecords = sortRecords(register.records).map(normalizeRecord);
|
|
3789
|
+
const normalized = sortObjectKeys({
|
|
3790
|
+
schema_version: register.schema_version,
|
|
3791
|
+
workspace: sortedWorkspace,
|
|
3792
|
+
records: sortedRecords
|
|
3793
|
+
}, RegisterKeyOrder);
|
|
3794
|
+
return dump(normalized, {
|
|
3795
|
+
noRefs: true,
|
|
3796
|
+
lineWidth: -1,
|
|
3797
|
+
quoteStyle: "double",
|
|
3798
|
+
sortKeys: false
|
|
3799
|
+
});
|
|
3800
|
+
}
|
|
3801
|
+
function allocateId(records, type) {
|
|
3802
|
+
const existing = records.filter((r) => r.type === type).map((r) => Number.parseInt(r.id.split("-")[1], 10));
|
|
3803
|
+
const max = existing.length > 0 ? Math.max(...existing) : 0;
|
|
3804
|
+
const next = max + 1;
|
|
3805
|
+
if (next > 9999) {
|
|
3806
|
+
throw new Error(`No available id for type ${type} (max 9999)`);
|
|
3807
|
+
}
|
|
3808
|
+
return `${type}-${String(next).padStart(4, "0")}`;
|
|
3809
|
+
}
|
|
3810
|
+
function readRegister(filePath) {
|
|
3811
|
+
let content;
|
|
3812
|
+
try {
|
|
3813
|
+
content = fs.readFileSync(filePath, "utf-8");
|
|
3814
|
+
} catch (err) {
|
|
3815
|
+
throw new Error(`Cannot read register at ${filePath}: ${err instanceof Error ? err.message : String(err)}`);
|
|
3816
|
+
}
|
|
3817
|
+
let parsed;
|
|
3818
|
+
try {
|
|
3819
|
+
parsed = load(content);
|
|
3820
|
+
} catch (err) {
|
|
3821
|
+
throw new Error(`Invalid YAML at ${filePath}: ${err instanceof Error ? err.message : String(err)}`);
|
|
3822
|
+
}
|
|
3823
|
+
const result = RegisterSchema.safeParse(parsed);
|
|
3824
|
+
if (!result.success) {
|
|
3825
|
+
throw new Error(formatZodError(filePath, result.error));
|
|
3826
|
+
}
|
|
3827
|
+
return result.data;
|
|
3828
|
+
}
|
|
3829
|
+
function validateRegisterFile(filePath) {
|
|
3830
|
+
const register = readRegister(filePath);
|
|
3831
|
+
const linkError = validateLinkIntegrity(register);
|
|
3832
|
+
if (linkError) {
|
|
3833
|
+
throw new Error(`${filePath}: ${linkError}`);
|
|
3834
|
+
}
|
|
3835
|
+
}
|
|
3836
|
+
function writeRegister(filePath, register) {
|
|
3837
|
+
const result = RegisterSchema.safeParse(register);
|
|
3838
|
+
if (!result.success) {
|
|
3839
|
+
throw new Error(formatZodError(filePath, result.error));
|
|
3840
|
+
}
|
|
3841
|
+
const linkError = validateLinkIntegrity(register);
|
|
3842
|
+
if (linkError) {
|
|
3843
|
+
throw new Error(`${filePath}: ${linkError}`);
|
|
3844
|
+
}
|
|
3845
|
+
const serialized = serializeRegister(register);
|
|
3846
|
+
const dir = path.dirname(filePath);
|
|
3847
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
3848
|
+
fs.writeFileSync(filePath, serialized, "utf-8");
|
|
3849
|
+
}
|
|
3850
|
+
function initRegister(filePath, workspace) {
|
|
3851
|
+
if (fs.existsSync(filePath)) {
|
|
3852
|
+
throw new Error(`Register already exists at ${filePath}`);
|
|
3853
|
+
}
|
|
3854
|
+
const register = {
|
|
3855
|
+
schema_version: "1.0",
|
|
3856
|
+
workspace,
|
|
3857
|
+
records: []
|
|
3858
|
+
};
|
|
3859
|
+
writeRegister(filePath, register);
|
|
3860
|
+
}
|
|
3861
|
+
function addRecord(filePath, input) {
|
|
3862
|
+
if (!fs.existsSync(filePath)) {
|
|
3863
|
+
throw new Error(`Register not found at ${filePath}. Run the decision-init tool first to create a new register.`);
|
|
3864
|
+
}
|
|
3865
|
+
const register = readRegister(filePath);
|
|
3866
|
+
const id = allocateId(register.records, input.type);
|
|
3867
|
+
const owner = input.owner ?? register.workspace.owner;
|
|
3868
|
+
const change_authority = input.change_authority ?? register.workspace.change_authority;
|
|
3869
|
+
const base = {
|
|
3870
|
+
schema_version: "1.0",
|
|
3871
|
+
id,
|
|
3872
|
+
type: input.type,
|
|
3873
|
+
title: input.title,
|
|
3874
|
+
status: "proposed",
|
|
3875
|
+
owner,
|
|
3876
|
+
change_authority,
|
|
3877
|
+
supersedes: input.supersedes ?? [],
|
|
3878
|
+
links: input.links ?? []
|
|
3879
|
+
};
|
|
3880
|
+
let record;
|
|
3881
|
+
switch (input.type) {
|
|
3882
|
+
case "REQ":
|
|
3883
|
+
case "CONSTRAINT":
|
|
3884
|
+
record = { ...base, type: input.type };
|
|
3885
|
+
break;
|
|
3886
|
+
case "ASSUMPTION":
|
|
3887
|
+
record = { ...base, type: input.type, needed_to_close: input.needed_to_close };
|
|
3888
|
+
break;
|
|
3889
|
+
case "DEC":
|
|
3890
|
+
record = {
|
|
3891
|
+
...base,
|
|
3892
|
+
type: input.type,
|
|
3893
|
+
decision: input.decision,
|
|
3894
|
+
alternatives_rejected: input.alternatives_rejected ?? [],
|
|
3895
|
+
consequences: input.consequences
|
|
3896
|
+
};
|
|
3897
|
+
break;
|
|
3898
|
+
}
|
|
3899
|
+
register.records.push(record);
|
|
3900
|
+
writeRegister(filePath, register);
|
|
3901
|
+
return record;
|
|
3902
|
+
}
|
|
3903
|
+
function transitionRecord(filePath, id, target, reason) {
|
|
3904
|
+
const register = readRegister(filePath);
|
|
3905
|
+
const record = register.records.find((r) => r.id === id);
|
|
3906
|
+
if (!record) {
|
|
3907
|
+
throw new Error(`Record ${id} not found`);
|
|
3908
|
+
}
|
|
3909
|
+
if (record.status === target) {
|
|
3910
|
+
return record;
|
|
3911
|
+
}
|
|
3912
|
+
const allowed = allowedTransitions[record.status] ?? [];
|
|
3913
|
+
if (!allowed.includes(target)) {
|
|
3914
|
+
throw new Error(`Invalid status transition from ${record.status} to ${target} for record ${id}`);
|
|
3915
|
+
}
|
|
3916
|
+
record.status = target;
|
|
3917
|
+
if (reason) {
|
|
3918
|
+
record.status_reason = reason;
|
|
3919
|
+
}
|
|
3920
|
+
writeRegister(filePath, register);
|
|
3921
|
+
return record;
|
|
3922
|
+
}
|
|
3923
|
+
function ratifyRecord(filePath, id) {
|
|
3924
|
+
return transitionRecord(filePath, id, "accepted");
|
|
3925
|
+
}
|
|
3926
|
+
function rejectRecord(filePath, id, reason) {
|
|
3927
|
+
return transitionRecord(filePath, id, "rejected", reason);
|
|
3928
|
+
}
|
|
3929
|
+
function supersedeRecord(filePath, oldId, newRecordInput, reason) {
|
|
3930
|
+
const register = readRegister(filePath);
|
|
3931
|
+
const oldRecord = register.records.find((r) => r.id === oldId);
|
|
3932
|
+
if (!oldRecord) {
|
|
3933
|
+
throw new Error(`Record ${oldId} not found`);
|
|
3934
|
+
}
|
|
3935
|
+
if (oldRecord.status === "superseded") {
|
|
3936
|
+
throw new Error(`Record ${oldId} is already superseded`);
|
|
3937
|
+
}
|
|
3938
|
+
const newId = allocateId(register.records, newRecordInput.type);
|
|
3939
|
+
const owner = newRecordInput.owner ?? register.workspace.owner;
|
|
3940
|
+
const change_authority = newRecordInput.change_authority ?? register.workspace.change_authority;
|
|
3941
|
+
const base = {
|
|
3942
|
+
schema_version: "1.0",
|
|
3943
|
+
id: newId,
|
|
3944
|
+
type: newRecordInput.type,
|
|
3945
|
+
title: newRecordInput.title,
|
|
3946
|
+
status: "proposed",
|
|
3947
|
+
owner,
|
|
3948
|
+
change_authority,
|
|
3949
|
+
supersedes: [oldId],
|
|
3950
|
+
links: newRecordInput.links ?? []
|
|
3951
|
+
};
|
|
3952
|
+
let newRecord;
|
|
3953
|
+
switch (newRecordInput.type) {
|
|
3954
|
+
case "REQ":
|
|
3955
|
+
case "CONSTRAINT":
|
|
3956
|
+
newRecord = { ...base, type: newRecordInput.type };
|
|
3957
|
+
break;
|
|
3958
|
+
case "ASSUMPTION":
|
|
3959
|
+
newRecord = {
|
|
3960
|
+
...base,
|
|
3961
|
+
type: newRecordInput.type,
|
|
3962
|
+
needed_to_close: newRecordInput.needed_to_close
|
|
3963
|
+
};
|
|
3964
|
+
break;
|
|
3965
|
+
case "DEC":
|
|
3966
|
+
newRecord = {
|
|
3967
|
+
...base,
|
|
3968
|
+
type: newRecordInput.type,
|
|
3969
|
+
decision: newRecordInput.decision,
|
|
3970
|
+
alternatives_rejected: newRecordInput.alternatives_rejected ?? [],
|
|
3971
|
+
consequences: newRecordInput.consequences
|
|
3972
|
+
};
|
|
3973
|
+
break;
|
|
3974
|
+
}
|
|
3975
|
+
oldRecord.status = "superseded";
|
|
3976
|
+
if (reason) {
|
|
3977
|
+
oldRecord.status_reason = reason;
|
|
3978
|
+
}
|
|
3979
|
+
register.records.push(newRecord);
|
|
3980
|
+
writeRegister(filePath, register);
|
|
3981
|
+
return newRecord;
|
|
3982
|
+
}
|
|
3983
|
+
|
|
3984
|
+
// src/tools/paths.ts
|
|
3985
|
+
import fs3 from "node:fs";
|
|
3986
|
+
import path3 from "node:path";
|
|
3987
|
+
|
|
3988
|
+
// src/config.ts
|
|
3989
|
+
import fs2 from "node:fs";
|
|
3990
|
+
import path2 from "node:path";
|
|
3991
|
+
import { z as z3 } from "zod";
|
|
3992
|
+
var ConfigSchema = z3.object({
|
|
3993
|
+
registerPath: z3.string().default(".decisions/register.yaml")
|
|
3994
|
+
});
|
|
3995
|
+
function loadConfig(worktree) {
|
|
3996
|
+
const configPath = path2.resolve(worktree, ".opencode", "decision-layer.json");
|
|
3997
|
+
if (!fs2.existsSync(configPath)) {
|
|
3998
|
+
return ConfigSchema.parse({});
|
|
3999
|
+
}
|
|
4000
|
+
let raw;
|
|
4001
|
+
try {
|
|
4002
|
+
raw = JSON.parse(fs2.readFileSync(configPath, "utf-8"));
|
|
4003
|
+
} catch (err) {
|
|
4004
|
+
throw new Error(`Invalid config at ${configPath}: ${err instanceof Error ? err.message : String(err)}`);
|
|
4005
|
+
}
|
|
4006
|
+
const result = ConfigSchema.safeParse(raw);
|
|
4007
|
+
if (!result.success) {
|
|
4008
|
+
throw new Error(`Invalid config at ${configPath}: ${result.error.message}`);
|
|
4009
|
+
}
|
|
4010
|
+
return result.data;
|
|
4011
|
+
}
|
|
4012
|
+
|
|
4013
|
+
// src/tools/paths.ts
|
|
4014
|
+
function isUsableRoot(candidate) {
|
|
4015
|
+
if (typeof candidate !== "string" || candidate === "")
|
|
4016
|
+
return false;
|
|
4017
|
+
const resolved = path3.resolve(candidate);
|
|
4018
|
+
if (resolved === "/")
|
|
4019
|
+
return false;
|
|
4020
|
+
try {
|
|
4021
|
+
return fs3.statSync(resolved).isDirectory();
|
|
4022
|
+
} catch {
|
|
4023
|
+
return false;
|
|
4024
|
+
}
|
|
4025
|
+
}
|
|
4026
|
+
function resolveProjectRoot(ctx) {
|
|
4027
|
+
if (isUsableRoot(ctx.worktree)) {
|
|
4028
|
+
return path3.resolve(ctx.worktree);
|
|
4029
|
+
}
|
|
4030
|
+
if (isUsableRoot(ctx.directory)) {
|
|
4031
|
+
return path3.resolve(ctx.directory);
|
|
4032
|
+
}
|
|
4033
|
+
throw new Error("Cannot resolve a project root: worktree and directory are missing, empty, " + 'missing on disk, or resolve to "/". Refusing to touch the decision register there.');
|
|
4034
|
+
}
|
|
4035
|
+
function withinWorktree(root, target) {
|
|
4036
|
+
const resolvedRoot = path3.resolve(root);
|
|
4037
|
+
const resolvedTarget = path3.resolve(target);
|
|
4038
|
+
const relative = path3.relative(resolvedRoot, resolvedTarget);
|
|
4039
|
+
return !relative.startsWith("..") && !path3.isAbsolute(relative);
|
|
4040
|
+
}
|
|
4041
|
+
function resolveRegisterPath(root) {
|
|
4042
|
+
const resolvedRoot = path3.resolve(root);
|
|
4043
|
+
if (resolvedRoot === "/") {
|
|
4044
|
+
throw new Error('Refusing to use "/" as the project root for the decision register');
|
|
4045
|
+
}
|
|
4046
|
+
const config = loadConfig(resolvedRoot);
|
|
4047
|
+
const registerPath = path3.resolve(resolvedRoot, config.registerPath);
|
|
4048
|
+
if (!withinWorktree(resolvedRoot, registerPath)) {
|
|
4049
|
+
throw new Error(`Configured register path escapes worktree: ${config.registerPath}`);
|
|
4050
|
+
}
|
|
4051
|
+
return registerPath;
|
|
4052
|
+
}
|
|
4053
|
+
function resolveToolPath(root, filePath) {
|
|
4054
|
+
const resolvedRoot = path3.resolve(root);
|
|
4055
|
+
if (resolvedRoot === "/") {
|
|
4056
|
+
throw new Error('Refusing to use "/" as the project root for the decision register');
|
|
4057
|
+
}
|
|
4058
|
+
const resolved = path3.resolve(resolvedRoot, filePath);
|
|
4059
|
+
if (!withinWorktree(resolvedRoot, resolved)) {
|
|
4060
|
+
throw new Error(`Path escapes worktree: ${filePath}`);
|
|
4061
|
+
}
|
|
4062
|
+
return resolved;
|
|
4063
|
+
}
|
|
4064
|
+
|
|
4065
|
+
// src/tools/index.ts
|
|
4066
|
+
function readBodyFile(filePath) {
|
|
4067
|
+
if (!fs4.existsSync(filePath)) {
|
|
4068
|
+
throw new Error(`Body file not found: ${filePath}`);
|
|
4069
|
+
}
|
|
4070
|
+
const content = fs4.readFileSync(filePath, "utf-8");
|
|
4071
|
+
const trimmed = content.trim();
|
|
4072
|
+
if (!trimmed)
|
|
4073
|
+
return {};
|
|
4074
|
+
const parsed = load(content);
|
|
4075
|
+
if (parsed === null || parsed === undefined)
|
|
4076
|
+
return {};
|
|
4077
|
+
if (typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
4078
|
+
throw new Error(`Body file must contain a YAML object: ${filePath}`);
|
|
4079
|
+
}
|
|
4080
|
+
return parsed;
|
|
4081
|
+
}
|
|
4082
|
+
function parseRecordInput(base, body) {
|
|
4083
|
+
const merged = { ...base, ...body };
|
|
4084
|
+
const result = AddRecordInputSchema.safeParse(merged);
|
|
4085
|
+
if (!result.success) {
|
|
4086
|
+
throw new Error(`Invalid record input: ${result.error.message}`);
|
|
4087
|
+
}
|
|
4088
|
+
return result.data;
|
|
4089
|
+
}
|
|
4090
|
+
function recordToTableRow(record) {
|
|
4091
|
+
return `${record.id} ${record.type} ${record.status} ${record.title}`;
|
|
4092
|
+
}
|
|
4093
|
+
function generateMarkdownView(register) {
|
|
4094
|
+
const lines = [];
|
|
4095
|
+
lines.push(`# Decision Register: ${register.workspace.title}`);
|
|
4096
|
+
lines.push("");
|
|
4097
|
+
lines.push(`- Workspace ID: ${register.workspace.id}`);
|
|
4098
|
+
lines.push(`- Owner: ${register.workspace.owner}`);
|
|
4099
|
+
lines.push(`- Change authority: ${register.workspace.change_authority}`);
|
|
4100
|
+
lines.push("");
|
|
4101
|
+
lines.push(`## Records (${register.records.length})`);
|
|
4102
|
+
lines.push("");
|
|
4103
|
+
for (const record of register.records) {
|
|
4104
|
+
lines.push(`### ${record.id} — ${record.title}`);
|
|
4105
|
+
lines.push("");
|
|
4106
|
+
lines.push(`- Type: ${record.type}`);
|
|
4107
|
+
lines.push(`- Status: ${record.status}`);
|
|
4108
|
+
lines.push(`- Owner: ${record.owner}`);
|
|
4109
|
+
lines.push(`- Change authority: ${record.change_authority}`);
|
|
4110
|
+
if (record.supersedes.length > 0) {
|
|
4111
|
+
lines.push(`- Supersedes: ${record.supersedes.join(", ")}`);
|
|
4112
|
+
}
|
|
4113
|
+
if (record.status_reason !== undefined) {
|
|
4114
|
+
lines.push(`- Status reason: ${record.status_reason}`);
|
|
4115
|
+
}
|
|
4116
|
+
if (record.links.length > 0) {
|
|
4117
|
+
lines.push("- Links:");
|
|
4118
|
+
for (const link of record.links) {
|
|
4119
|
+
lines.push(` - ${link.type} ${link.target}: ${link.rationale}`);
|
|
4120
|
+
}
|
|
4121
|
+
}
|
|
4122
|
+
if (record.type === "ASSUMPTION") {
|
|
4123
|
+
lines.push(`- Needed to close: ${record.needed_to_close}`);
|
|
4124
|
+
}
|
|
4125
|
+
if (record.type === "DEC") {
|
|
4126
|
+
lines.push(`- Decision: ${record.decision}`);
|
|
4127
|
+
if (record.alternatives_rejected.length > 0) {
|
|
4128
|
+
lines.push("- Alternatives rejected:");
|
|
4129
|
+
for (const alt of record.alternatives_rejected) {
|
|
4130
|
+
lines.push(` - ${alt.alternative}: ${alt.rejected_because}`);
|
|
4131
|
+
}
|
|
4132
|
+
}
|
|
4133
|
+
lines.push(`- Consequences: ${record.consequences}`);
|
|
4134
|
+
}
|
|
4135
|
+
lines.push("");
|
|
4136
|
+
}
|
|
4137
|
+
return lines.join(`
|
|
4138
|
+
`);
|
|
4139
|
+
}
|
|
4140
|
+
function makeTool(description, args, execute) {
|
|
4141
|
+
return {
|
|
4142
|
+
description,
|
|
4143
|
+
args,
|
|
4144
|
+
execute
|
|
4145
|
+
};
|
|
4146
|
+
}
|
|
4147
|
+
function createDecisionTools() {
|
|
4148
|
+
return {
|
|
4149
|
+
"decision-add": makeTool("Add a proposed decision record to the register", {
|
|
4150
|
+
type: z4.enum(RecordTypes),
|
|
4151
|
+
title: z4.string().min(1),
|
|
4152
|
+
body: z4.string().optional().describe("Path to YAML file with additional record fields")
|
|
4153
|
+
}, async (args, ctx) => {
|
|
4154
|
+
const root = resolveProjectRoot(ctx);
|
|
4155
|
+
const registerPath = resolveRegisterPath(root);
|
|
4156
|
+
const body = args.body ? readBodyFile(resolveToolPath(root, args.body)) : {};
|
|
4157
|
+
const input = parseRecordInput({ type: args.type, title: args.title }, body);
|
|
4158
|
+
const record = addRecord(registerPath, input);
|
|
4159
|
+
return `Added ${record.id} (${record.status})`;
|
|
4160
|
+
}),
|
|
4161
|
+
"decision-ratify": makeTool("Ratify a proposed record (proposed -> accepted)", {
|
|
4162
|
+
id: z4.string()
|
|
4163
|
+
}, async (args, ctx) => {
|
|
4164
|
+
const root = resolveProjectRoot(ctx);
|
|
4165
|
+
const registerPath = resolveRegisterPath(root);
|
|
4166
|
+
const before = readRegister(registerPath).records.find((r) => r.id === args.id);
|
|
4167
|
+
if (before && before.status === "accepted") {
|
|
4168
|
+
return `Record ${args.id} is already accepted (no-op)`;
|
|
4169
|
+
}
|
|
4170
|
+
const record = ratifyRecord(registerPath, args.id);
|
|
4171
|
+
return `Ratified ${record.id} -> ${record.status}`;
|
|
4172
|
+
}),
|
|
4173
|
+
"decision-reject": makeTool("Reject a proposed record (proposed -> rejected)", {
|
|
4174
|
+
id: z4.string(),
|
|
4175
|
+
reason: z4.string().min(1)
|
|
4176
|
+
}, async (args, ctx) => {
|
|
4177
|
+
const root = resolveProjectRoot(ctx);
|
|
4178
|
+
const registerPath = resolveRegisterPath(root);
|
|
4179
|
+
const before = readRegister(registerPath).records.find((r) => r.id === args.id);
|
|
4180
|
+
if (before && before.status === "rejected") {
|
|
4181
|
+
return `Record ${args.id} is already rejected (no-op)`;
|
|
4182
|
+
}
|
|
4183
|
+
const record = rejectRecord(registerPath, args.id, args.reason);
|
|
4184
|
+
return `Rejected ${record.id}: ${args.reason}`;
|
|
4185
|
+
}),
|
|
4186
|
+
"decision-supersede": makeTool("Supersede a record with a new proposed record", {
|
|
4187
|
+
id: z4.string(),
|
|
4188
|
+
by: z4.string().describe("Path to YAML file describing the new record"),
|
|
4189
|
+
reason: z4.string().optional().describe("Reason stored as status_reason on the superseded record")
|
|
4190
|
+
}, async (args, ctx) => {
|
|
4191
|
+
const root = resolveProjectRoot(ctx);
|
|
4192
|
+
const registerPath = resolveRegisterPath(root);
|
|
4193
|
+
const body = readBodyFile(resolveToolPath(root, args.by));
|
|
4194
|
+
const input = parseRecordInput({}, body);
|
|
4195
|
+
const record = supersedeRecord(registerPath, args.id, input, args.reason);
|
|
4196
|
+
return `Superseded ${args.id} with ${record.id}`;
|
|
4197
|
+
}),
|
|
4198
|
+
"decision-list": makeTool("List decision records", {
|
|
4199
|
+
status: z4.enum(RecordStatuses).optional(),
|
|
4200
|
+
type: z4.enum(RecordTypes).optional()
|
|
4201
|
+
}, async (args, ctx) => {
|
|
4202
|
+
const root = resolveProjectRoot(ctx);
|
|
4203
|
+
const registerPath = resolveRegisterPath(root);
|
|
4204
|
+
const register = readRegister(registerPath);
|
|
4205
|
+
let records = register.records;
|
|
4206
|
+
if (args.status)
|
|
4207
|
+
records = records.filter((r) => r.status === args.status);
|
|
4208
|
+
if (args.type)
|
|
4209
|
+
records = records.filter((r) => r.type === args.type);
|
|
4210
|
+
if (records.length === 0)
|
|
4211
|
+
return "No records found";
|
|
4212
|
+
const header = "ID\tTYPE\tSTATUS\tTITLE";
|
|
4213
|
+
const rows = records.map(recordToTableRow);
|
|
4214
|
+
return [header, ...rows].join(`
|
|
4215
|
+
`);
|
|
4216
|
+
}),
|
|
4217
|
+
"decision-query": makeTool("Query record traceability", {
|
|
4218
|
+
orphan: z4.boolean().optional(),
|
|
4219
|
+
for: z4.string().optional()
|
|
4220
|
+
}, async (args, ctx) => {
|
|
4221
|
+
const root = resolveProjectRoot(ctx);
|
|
4222
|
+
const registerPath = resolveRegisterPath(root);
|
|
4223
|
+
const register = readRegister(registerPath);
|
|
4224
|
+
if (args.orphan) {
|
|
4225
|
+
const linked = new Set;
|
|
4226
|
+
for (const r of register.records) {
|
|
4227
|
+
for (const link of r.links) {
|
|
4228
|
+
linked.add(link.target);
|
|
4229
|
+
linked.add(r.id);
|
|
4230
|
+
}
|
|
4231
|
+
for (const s of r.supersedes) {
|
|
4232
|
+
linked.add(s);
|
|
4233
|
+
linked.add(r.id);
|
|
4234
|
+
}
|
|
4235
|
+
}
|
|
4236
|
+
const orphans = register.records.filter((r) => !linked.has(r.id));
|
|
4237
|
+
if (orphans.length === 0)
|
|
4238
|
+
return "No orphan records";
|
|
4239
|
+
return ["Orphan records:", ...orphans.map((r) => r.id)].join(`
|
|
4240
|
+
`);
|
|
4241
|
+
}
|
|
4242
|
+
if (args.for) {
|
|
4243
|
+
const targetId = args.for;
|
|
4244
|
+
const target = register.records.find((r) => r.id === targetId);
|
|
4245
|
+
if (!target)
|
|
4246
|
+
return `Record ${targetId} not found`;
|
|
4247
|
+
const related = new Set;
|
|
4248
|
+
related.add(target);
|
|
4249
|
+
for (const r of register.records) {
|
|
4250
|
+
if (r.links.some((l) => l.target === targetId))
|
|
4251
|
+
related.add(r);
|
|
4252
|
+
if (target.links.some((l) => l.target === r.id))
|
|
4253
|
+
related.add(r);
|
|
4254
|
+
if (r.supersedes.includes(targetId))
|
|
4255
|
+
related.add(r);
|
|
4256
|
+
if (target.supersedes.includes(r.id))
|
|
4257
|
+
related.add(r);
|
|
4258
|
+
}
|
|
4259
|
+
return Array.from(related).map((r) => `${r.id} (${r.type}, ${r.status}): ${r.title}`).join(`
|
|
4260
|
+
`);
|
|
4261
|
+
}
|
|
4262
|
+
return "Specify --orphan or --for <id>";
|
|
4263
|
+
}),
|
|
4264
|
+
"decision-validate": makeTool("Validate the register file against the schema", {}, async (_args, ctx) => {
|
|
4265
|
+
const root = resolveProjectRoot(ctx);
|
|
4266
|
+
const registerPath = resolveRegisterPath(root);
|
|
4267
|
+
try {
|
|
4268
|
+
validateRegisterFile(registerPath);
|
|
4269
|
+
return `Register is valid: ${registerPath}`;
|
|
4270
|
+
} catch (err) {
|
|
4271
|
+
return `Register validation failed: ${err instanceof Error ? err.message : String(err)}`;
|
|
4272
|
+
}
|
|
4273
|
+
}),
|
|
4274
|
+
"decision-view": makeTool("Generate a markdown view of the register", {}, async (_args, ctx) => {
|
|
4275
|
+
const root = resolveProjectRoot(ctx);
|
|
4276
|
+
const registerPath = resolveRegisterPath(root);
|
|
4277
|
+
const register = readRegister(registerPath);
|
|
4278
|
+
const viewPath = path4.resolve(root, ".decisions", "views", "register.md");
|
|
4279
|
+
if (!withinWorktree(root, viewPath)) {
|
|
4280
|
+
throw new Error("View path escapes worktree");
|
|
4281
|
+
}
|
|
4282
|
+
fs4.mkdirSync(path4.dirname(viewPath), { recursive: true });
|
|
4283
|
+
const markdown = generateMarkdownView(register);
|
|
4284
|
+
fs4.writeFileSync(viewPath, markdown, "utf-8");
|
|
4285
|
+
return `View written to ${viewPath}`;
|
|
4286
|
+
}),
|
|
4287
|
+
"decision-init": makeTool("Create an empty decision register at .decisions/register.yaml (refuses to overwrite)", {
|
|
4288
|
+
id: z4.string().min(1).describe("Workspace slug"),
|
|
4289
|
+
title: z4.string().min(1),
|
|
4290
|
+
owner: z4.string().min(1),
|
|
4291
|
+
change_authority: z4.string().min(1)
|
|
4292
|
+
}, async (args, ctx) => {
|
|
4293
|
+
const root = resolveProjectRoot(ctx);
|
|
4294
|
+
const registerPath = resolveRegisterPath(root);
|
|
4295
|
+
if (fs4.existsSync(registerPath)) {
|
|
4296
|
+
return `Register already exists at ${registerPath}; not overwriting.`;
|
|
4297
|
+
}
|
|
4298
|
+
initRegister(registerPath, {
|
|
4299
|
+
id: args.id,
|
|
4300
|
+
title: args.title,
|
|
4301
|
+
owner: args.owner,
|
|
4302
|
+
change_authority: args.change_authority
|
|
4303
|
+
});
|
|
4304
|
+
fs4.mkdirSync(path4.resolve(root, ".decisions", "views"), { recursive: true });
|
|
4305
|
+
return `Initialized empty register at ${registerPath}`;
|
|
4306
|
+
})
|
|
4307
|
+
};
|
|
4308
|
+
}
|
|
4309
|
+
|
|
4310
|
+
// src/index.ts
|
|
4311
|
+
var DecisionLayer = async () => {
|
|
4312
|
+
const hooks = {
|
|
4313
|
+
"command.execute.before": createInterviewInjectHook(),
|
|
4314
|
+
tool: createDecisionTools()
|
|
4315
|
+
};
|
|
4316
|
+
return hooks;
|
|
4317
|
+
};
|
|
4318
|
+
var src_default = {
|
|
4319
|
+
id: "omo-slim-decision-layer",
|
|
4320
|
+
server: DecisionLayer
|
|
4321
|
+
};
|
|
4322
|
+
export {
|
|
4323
|
+
src_default as default
|
|
4324
|
+
};
|