nolo-cli 0.61.0-alpha.2 → 0.62.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/{_executeModel-CKT6RGTL.js → _executeModel-R26QYY66.js} +13 -12
  2. package/{agentDeleteCommand-VN7NPXQ4.js → agentDeleteCommand-6GNQA4J4.js} +1 -1
  3. package/{agentEmailCommands-F2TNAV4A.js → agentEmailCommands-HH67CYKD.js} +13 -12
  4. package/{agentListCommands-OSM2ANI3.js → agentListCommands-23XW3OPZ.js} +1 -1
  5. package/{agentMachineCommands-MTPWYVRV.js → agentMachineCommands-HXHASEWO.js} +2 -2
  6. package/{agentRecordCommands-VWAWTVVC.js → agentRecordCommands-UHTQJVGC.js} +13 -12
  7. package/{agentRunCommand-PLZOBNVK.js → agentRunCommand-OAMT77EX.js} +14 -13
  8. package/{agentRuntimeLocal-XCJLRWQE.js → agentRuntimeLocal-QBK4H3T2.js} +1 -1
  9. package/{agentSlice-F6DOP4IW.js → agentSlice-7XJH5WQF.js} +1 -1
  10. package/{appDeleteCommands-3BCFTRFJ.js → appDeleteCommands-AX2O6VDV.js} +1 -1
  11. package/{appDeployCommands-B4GMHCYA.js → appDeployCommands-L5ZR26CB.js} +1 -1
  12. package/{appDeployStatusCommands-4MN36WIG.js → appDeployStatusCommands-5HQHELRA.js} +1 -1
  13. package/{appGetCommands-4GJIEUAX.js → appGetCommands-HVSYOS57.js} +1 -1
  14. package/{appListCommands-CHU53GSX.js → appListCommands-XV2FPTWX.js} +1 -1
  15. package/{chatQueueReduxAdapter-HNSQXNIR.js → chatQueueReduxAdapter-F3R253JE.js} +2 -2
  16. package/{chunk-6HIGYUBQ.js → chunk-6XIE5ZGI.js} +1 -1
  17. package/{chunk-B7DXRX7F.js → chunk-7KELZLC2.js} +4 -4
  18. package/chunk-AETZ7AD6.js +274 -0
  19. package/{chunk-2HPRMEEZ.js → chunk-CQ2OZMLQ.js} +10 -10
  20. package/{chunk-ES6CVKVD.js → chunk-DWYSDNOH.js} +3 -3
  21. package/{chunk-DZZL7UBV.js → chunk-E3YVTQWT.js} +1 -1
  22. package/chunk-E4MARS3Q.js +114 -0
  23. package/{chunk-HQP7HJDL.js → chunk-F44FAXP2.js} +3 -3
  24. package/{chunk-7UF7CQ6B.js → chunk-GSXDRMDO.js} +2 -2
  25. package/{chunk-EY7V7REW.js → chunk-KHCLMKZZ.js} +6 -280
  26. package/{chunk-4C4ST2YE.js → chunk-KSCXMC6U.js} +3 -3
  27. package/{chunk-AVE2YR4F.js → chunk-N6HLMLKE.js} +1 -1
  28. package/{chunk-GAL47RNP.js → chunk-NO42UD73.js} +1 -1
  29. package/{chunk-HLU5Q2GV.js → chunk-NRRPKMM7.js} +1 -1
  30. package/{chunk-37QVS7BU.js → chunk-SKIRVYEI.js} +3 -3
  31. package/{chunk-3JWKQDA4.js → chunk-SYNKICCB.js} +1 -1
  32. package/{chunk-D5XKNNUV.js → chunk-TBHAHL33.js} +8 -8
  33. package/{chunk-IYCUMIYS.js → chunk-VAKVNHK5.js} +5 -5
  34. package/{chunk-HBPV76EK.js → chunk-VHO3TMQZ.js} +8 -8
  35. package/{chunk-7O7KH4X5.js → chunk-Z5MHFBJZ.js} +5 -5
  36. package/{codingSkills-VDXQYWX4.js → codingSkills-TKROLCBA.js} +3 -2
  37. package/{contentThunks-7YG2ZYQC.js → contentThunks-OZPK5B4Z.js} +3 -3
  38. package/{createAgentAutomationAction-PJQSCAIO.js → createAgentAutomationAction-LCIBGE5T.js} +3 -3
  39. package/{createDialogAction-SFEJX6SP.js → createDialogAction-JPJZMHJE.js} +6 -5
  40. package/{createPageAction-B7WRHOQO.js → createPageAction-6P2WLNHO.js} +5 -4
  41. package/{dialogCommands-VL2X22QC.js → dialogCommands-WAFKC3KK.js} +1 -1
  42. package/{dialogSlice-ANMACABO.js → dialogSlice-R5RZHFTU.js} +2 -2
  43. package/{docCreateCommands-ITLGZ5YI.js → docCreateCommands-GHGB42S7.js} +4 -3
  44. package/{docDeleteCommands-LH3YNL4C.js → docDeleteCommands-Y5I7ZEX4.js} +4 -3
  45. package/{docReadCommands-YAJ77F36.js → docReadCommands-BMXM6J7T.js} +4 -3
  46. package/{docStore-D4HGHPWI.js → docStore-DKWZ6XJ5.js} +1 -1
  47. package/{docUpdateCommands-DQBOMH2G.js → docUpdateCommands-QNABH3M2.js} +4 -3
  48. package/{handleSendMessageAction-DF2OABGW.js → handleSendMessageAction-UQGKM4UX.js} +2 -2
  49. package/index.js +40 -40
  50. package/{machineCommands-JXDYQ5LB.js → machineCommands-YDAIPYU5.js} +13 -12
  51. package/{machineWsRunDispatch-3QHI7JX5.js → machineWsRunDispatch-O6RM2ECT.js} +13 -12
  52. package/package.json +1 -1
  53. package/{readlineWorkspace-KVZTEAHB.js → readlineWorkspace-5DP3AJWN.js} +14 -13
  54. package/{runAgentClientLoop-KGTEL7ZP.js → runAgentClientLoop-Y6HWP2PT.js} +11 -10
  55. package/{skillDiscovery-NTRLM6KP.js → skillDiscovery-CYUCJMAG.js} +2 -1
  56. package/{spaceCommands-KNAYWMCZ.js → spaceCommands-CLN45IE3.js} +1 -1
  57. package/{streamAgentChatTurn-FLYPTXKZ.js → streamAgentChatTurn-6WFQJ4DY.js} +12 -11
  58. package/{tools-CVLUXK6P.js → tools-RR53D65Q.js} +9 -8
  59. package/{updateDialogTitleAction-HWJIZEIV.js → updateDialogTitleAction-WXS3AKOL.js} +3 -3
  60. package/chunk-AQMVUA7N.js +0 -2575
package/chunk-AQMVUA7N.js DELETED
@@ -1,2575 +0,0 @@
1
- import {
2
- buildSkillDiscoveryLayer
3
- } from "./chunk-DVINR3PL.js";
4
-
5
- // packages/agent-runtime/skillDiscovery.ts
6
- import { existsSync, readFileSync, readdirSync, statSync } from "node:fs";
7
- import { join } from "node:path";
8
-
9
- // node_modules/js-yaml/dist/js-yaml.mjs
10
- var NOT_RESOLVED = Symbol("NOT_RESOLVED");
11
- function defineScalarTag(tagName, options) {
12
- return {
13
- tagName,
14
- nodeKind: "scalar",
15
- implicit: options.implicit ?? false,
16
- matchByTagPrefix: options.matchByTagPrefix ?? false,
17
- implicitFirstChars: options.implicitFirstChars ?? null,
18
- resolve: options.resolve,
19
- identify: options.identify,
20
- represent: options.represent ?? ((data) => String(data)),
21
- representTagName: options.representTagName ?? (() => tagName)
22
- };
23
- }
24
- function defineSequenceTag(tagName, options) {
25
- const carrierIsResult = options.finalize === void 0;
26
- return {
27
- tagName,
28
- nodeKind: "sequence",
29
- implicit: false,
30
- matchByTagPrefix: options.matchByTagPrefix ?? false,
31
- create: options.create,
32
- addItem: options.addItem,
33
- finalize: options.finalize ?? ((carrier) => carrier),
34
- carrierIsResult,
35
- identify: options.identify,
36
- represent: options.represent ?? ((data) => data),
37
- representTagName: options.representTagName ?? (() => tagName)
38
- };
39
- }
40
- function defineMappingTag(tagName, options) {
41
- const carrierIsResult = options.finalize === void 0;
42
- return {
43
- tagName,
44
- nodeKind: "mapping",
45
- implicit: false,
46
- matchByTagPrefix: options.matchByTagPrefix ?? false,
47
- create: options.create,
48
- addPair: options.addPair,
49
- has: options.has,
50
- keys: options.keys,
51
- get: options.get,
52
- finalize: options.finalize ?? ((carrier) => carrier),
53
- carrierIsResult,
54
- identify: options.identify,
55
- represent: options.represent ?? ((data) => data),
56
- representTagName: options.representTagName ?? (() => tagName)
57
- };
58
- }
59
- var strTag = defineScalarTag("tag:yaml.org,2002:str", {
60
- resolve: (source) => source,
61
- identify: (data) => typeof data === "string"
62
- });
63
- var NULL_VALUES$1 = [
64
- "",
65
- "~",
66
- "null",
67
- "Null",
68
- "NULL"
69
- ];
70
- var nullCoreTag = defineScalarTag("tag:yaml.org,2002:null", {
71
- implicit: true,
72
- implicitFirstChars: [
73
- "",
74
- "~",
75
- "n",
76
- "N"
77
- ],
78
- resolve: (source) => {
79
- if (NULL_VALUES$1.indexOf(source) !== -1) return null;
80
- return NOT_RESOLVED;
81
- },
82
- identify: (object) => object === null,
83
- represent: () => "null"
84
- });
85
- var nullJsonTag = defineScalarTag("tag:yaml.org,2002:null", {
86
- implicit: true,
87
- implicitFirstChars: ["n"],
88
- resolve: (source, isExplicit) => {
89
- if (source === "null" || isExplicit && source === "") return null;
90
- return NOT_RESOLVED;
91
- },
92
- identify: (object) => object === null,
93
- represent: () => "null"
94
- });
95
- var NULL_VALUES = [
96
- "",
97
- "~",
98
- "null",
99
- "Null",
100
- "NULL"
101
- ];
102
- var nullYaml11Tag = defineScalarTag("tag:yaml.org,2002:null", {
103
- implicit: true,
104
- implicitFirstChars: [
105
- "",
106
- "~",
107
- "n",
108
- "N"
109
- ],
110
- resolve: (source) => {
111
- if (NULL_VALUES.indexOf(source) !== -1) return null;
112
- return NOT_RESOLVED;
113
- },
114
- identify: (object) => object === null,
115
- represent: () => "null"
116
- });
117
- var TRUE_VALUES$2 = [
118
- "true",
119
- "True",
120
- "TRUE"
121
- ];
122
- var FALSE_VALUES$2 = [
123
- "false",
124
- "False",
125
- "FALSE"
126
- ];
127
- var boolCoreTag = defineScalarTag("tag:yaml.org,2002:bool", {
128
- implicit: true,
129
- implicitFirstChars: [
130
- "t",
131
- "T",
132
- "f",
133
- "F"
134
- ],
135
- resolve: (source) => {
136
- if (TRUE_VALUES$2.indexOf(source) !== -1) return true;
137
- if (FALSE_VALUES$2.indexOf(source) !== -1) return false;
138
- return NOT_RESOLVED;
139
- },
140
- identify: (object) => Object.prototype.toString.call(object) === "[object Boolean]",
141
- represent: (object) => object ? "true" : "false"
142
- });
143
- var TRUE_VALUES$1 = ["true"];
144
- var FALSE_VALUES$1 = ["false"];
145
- var boolJsonTag = defineScalarTag("tag:yaml.org,2002:bool", {
146
- implicit: true,
147
- implicitFirstChars: ["t", "f"],
148
- resolve: (source) => {
149
- if (TRUE_VALUES$1.indexOf(source) !== -1) return true;
150
- if (FALSE_VALUES$1.indexOf(source) !== -1) return false;
151
- return NOT_RESOLVED;
152
- },
153
- identify: (object) => Object.prototype.toString.call(object) === "[object Boolean]",
154
- represent: (object) => object ? "true" : "false"
155
- });
156
- var TRUE_VALUES = [
157
- "true",
158
- "True",
159
- "TRUE",
160
- "y",
161
- "Y",
162
- "yes",
163
- "Yes",
164
- "YES",
165
- "on",
166
- "On",
167
- "ON"
168
- ];
169
- var FALSE_VALUES = [
170
- "false",
171
- "False",
172
- "FALSE",
173
- "n",
174
- "N",
175
- "no",
176
- "No",
177
- "NO",
178
- "off",
179
- "Off",
180
- "OFF"
181
- ];
182
- var boolYaml11Tag = defineScalarTag("tag:yaml.org,2002:bool", {
183
- implicit: true,
184
- implicitFirstChars: [
185
- "y",
186
- "Y",
187
- "n",
188
- "N",
189
- "t",
190
- "T",
191
- "f",
192
- "F",
193
- "o",
194
- "O"
195
- ],
196
- resolve: (source) => {
197
- if (TRUE_VALUES.indexOf(source) !== -1) return true;
198
- if (FALSE_VALUES.indexOf(source) !== -1) return false;
199
- return NOT_RESOLVED;
200
- },
201
- identify: (object) => Object.prototype.toString.call(object) === "[object Boolean]",
202
- represent: (object) => object ? "true" : "false"
203
- });
204
- var YAML_INTEGER_IMPLICIT_PATTERN$1 = /* @__PURE__ */ new RegExp("^(?:0o[0-7]+|0x[0-9a-fA-F]+|[-+]?[0-9]+)$");
205
- var YAML_INTEGER_EXPLICIT_PATTERN$1 = /* @__PURE__ */ new RegExp("^(?:[-+]?0b[0-1]+|[-+]?0o[0-7]+|[-+]?0x[0-9a-fA-F]+|[-+]?[0-9]+)$");
206
- function parseYamlInteger$2(source) {
207
- let value = source;
208
- let sign = 1;
209
- if (value[0] === "-" || value[0] === "+") {
210
- if (value[0] === "-") sign = -1;
211
- value = value.slice(1);
212
- }
213
- if (value.startsWith("0b")) return sign * parseInt(value.slice(2), 2);
214
- if (value.startsWith("0o")) return sign * parseInt(value.slice(2), 8);
215
- if (value.startsWith("0x")) return sign * parseInt(value.slice(2), 16);
216
- return sign * parseInt(value, 10);
217
- }
218
- function resolveYamlInteger$2(source, isExplicit) {
219
- if (isExplicit) {
220
- if (!YAML_INTEGER_EXPLICIT_PATTERN$1.test(source)) return NOT_RESOLVED;
221
- } else if (!YAML_INTEGER_IMPLICIT_PATTERN$1.test(source)) return NOT_RESOLVED;
222
- const result = parseYamlInteger$2(source);
223
- return Number.isFinite(result) ? result : NOT_RESOLVED;
224
- }
225
- var intCoreTag = defineScalarTag("tag:yaml.org,2002:int", {
226
- implicit: true,
227
- implicitFirstChars: [
228
- "-",
229
- "+",
230
- ..."0123456789"
231
- ],
232
- resolve: resolveYamlInteger$2,
233
- identify: (object) => Number.isInteger(object) && !Object.is(object, -0) && object.toString(10).indexOf("e") < 0,
234
- represent: (object) => object.toString(10)
235
- });
236
- var YAML_INTEGER_IMPLICIT_PATTERN = /* @__PURE__ */ new RegExp("^-?(?:0|[1-9][0-9]*)$");
237
- var YAML_INTEGER_EXPLICIT_PATTERN = /* @__PURE__ */ new RegExp("^(?:[-+]?0b[0-1]+|[-+]?0o[0-7]+|[-+]?0x[0-9a-fA-F]+|[-+]?[0-9]+)$");
238
- function parseYamlInteger$1(source) {
239
- let value = source;
240
- let sign = 1;
241
- if (value[0] === "-" || value[0] === "+") {
242
- if (value[0] === "-") sign = -1;
243
- value = value.slice(1);
244
- }
245
- if (value.startsWith("0b")) return sign * parseInt(value.slice(2), 2);
246
- if (value.startsWith("0o")) return sign * parseInt(value.slice(2), 8);
247
- if (value.startsWith("0x")) return sign * parseInt(value.slice(2), 16);
248
- return sign * parseInt(value, 10);
249
- }
250
- function resolveYamlInteger$1(source, isExplicit) {
251
- if (isExplicit) {
252
- if (!YAML_INTEGER_EXPLICIT_PATTERN.test(source)) return NOT_RESOLVED;
253
- } else if (!YAML_INTEGER_IMPLICIT_PATTERN.test(source)) return NOT_RESOLVED;
254
- const result = parseYamlInteger$1(source);
255
- return Number.isFinite(result) ? result : NOT_RESOLVED;
256
- }
257
- var intJsonTag = defineScalarTag("tag:yaml.org,2002:int", {
258
- implicit: true,
259
- implicitFirstChars: ["-", ..."0123456789"],
260
- resolve: resolveYamlInteger$1,
261
- identify: (object) => Number.isInteger(object) && !Object.is(object, -0) && object.toString(10).indexOf("e") < 0,
262
- represent: (object) => object.toString(10)
263
- });
264
- 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_]*))$");
265
- function parseYamlInteger(source) {
266
- let value = source.replace(/_/g, "");
267
- let sign = 1;
268
- if (value[0] === "-" || value[0] === "+") {
269
- if (value[0] === "-") sign = -1;
270
- value = value.slice(1);
271
- }
272
- if (value.startsWith("0b")) return sign * parseInt(value.slice(2), 2);
273
- if (value.startsWith("0x")) return sign * parseInt(value.slice(2), 16);
274
- if (value.includes(":")) {
275
- let result = 0;
276
- for (const part of value.split(":")) result = result * 60 + Number(part);
277
- return sign * result;
278
- }
279
- if (value !== "0" && value[0] === "0") return sign * parseInt(value, 8);
280
- return sign * parseInt(value, 10);
281
- }
282
- function resolveYamlInteger(source) {
283
- if (!YAML_INTEGER_PATTERN.test(source)) return NOT_RESOLVED;
284
- const result = parseYamlInteger(source);
285
- return Number.isFinite(result) ? result : NOT_RESOLVED;
286
- }
287
- var intYaml11Tag = defineScalarTag("tag:yaml.org,2002:int", {
288
- implicit: true,
289
- implicitFirstChars: [
290
- "-",
291
- "+",
292
- ..."0123456789"
293
- ],
294
- resolve: resolveYamlInteger,
295
- identify: (object) => Number.isInteger(object) && !Object.is(object, -0) && object.toString(10).indexOf("e") < 0,
296
- represent: (object) => object.toString(10)
297
- });
298
- 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))$");
299
- var YAML_FLOAT_SPECIAL_PATTERN$1 = /* @__PURE__ */ new RegExp("^(?:[-+]?\\.(?:inf|Inf|INF)|\\.(?:nan|NaN|NAN))$");
300
- function resolveYamlFloat$2(source) {
301
- if (!YAML_FLOAT_PATTERN$1.test(source)) return NOT_RESOLVED;
302
- let value = source.toLowerCase();
303
- const sign = value[0] === "-" ? -1 : 1;
304
- if ("+-".includes(value[0])) value = value.slice(1);
305
- if (value === ".inf") return sign === 1 ? Number.POSITIVE_INFINITY : Number.NEGATIVE_INFINITY;
306
- if (value === ".nan") return NaN;
307
- const result = sign * parseFloat(value);
308
- if (Number.isFinite(result) || YAML_FLOAT_SPECIAL_PATTERN$1.test(source)) return result;
309
- return NOT_RESOLVED;
310
- }
311
- function representYamlFloat$2(object) {
312
- if (isNaN(object)) return ".nan";
313
- if (object === Number.POSITIVE_INFINITY) return ".inf";
314
- if (object === Number.NEGATIVE_INFINITY) return "-.inf";
315
- if (Object.is(object, -0)) return "-0.0";
316
- const result = object.toString(10);
317
- return /^[-+]?[0-9]+e/.test(result) ? result.replace("e", ".e") : result;
318
- }
319
- var floatCoreTag = defineScalarTag("tag:yaml.org,2002:float", {
320
- implicit: true,
321
- implicitFirstChars: [
322
- "-",
323
- "+",
324
- ".",
325
- ..."0123456789"
326
- ],
327
- resolve: resolveYamlFloat$2,
328
- identify: (object) => typeof object === "number" && (!Number.isInteger(object) || Object.is(object, -0) || object.toString(10).indexOf("e") >= 0),
329
- represent: representYamlFloat$2
330
- });
331
- var YAML_FLOAT_IMPLICIT_PATTERN = /* @__PURE__ */ new RegExp("^-?(?:0|[1-9][0-9]*)(?:\\.[0-9]*)?(?:[eE][-+]?[0-9]+)?$");
332
- 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))$");
333
- function resolveYamlFloat$1(source, isExplicit) {
334
- if (isExplicit) {
335
- if (!YAML_FLOAT_EXPLICIT_PATTERN.test(source)) return NOT_RESOLVED;
336
- let value = source.toLowerCase();
337
- const sign = value[0] === "-" ? -1 : 1;
338
- if ("+-".includes(value[0])) value = value.slice(1);
339
- if (value === ".inf") return sign === 1 ? Number.POSITIVE_INFINITY : Number.NEGATIVE_INFINITY;
340
- if (value === ".nan") return NaN;
341
- const result2 = sign * parseFloat(value);
342
- return Number.isFinite(result2) ? result2 : NOT_RESOLVED;
343
- }
344
- if (!YAML_FLOAT_IMPLICIT_PATTERN.test(source)) return NOT_RESOLVED;
345
- const result = Number(source);
346
- if (Number.isFinite(result)) return result;
347
- return NOT_RESOLVED;
348
- }
349
- function representYamlFloat$1(object) {
350
- if (isNaN(object)) return ".nan";
351
- if (object === Number.POSITIVE_INFINITY) return ".inf";
352
- if (object === Number.NEGATIVE_INFINITY) return "-.inf";
353
- if (Object.is(object, -0)) return "-0.0";
354
- const result = object.toString(10);
355
- return /^[-+]?[0-9]+e/.test(result) ? result.replace("e", ".e") : result;
356
- }
357
- var floatJsonTag = defineScalarTag("tag:yaml.org,2002:float", {
358
- implicit: true,
359
- implicitFirstChars: ["-", ..."0123456789"],
360
- resolve: resolveYamlFloat$1,
361
- identify: (object) => typeof object === "number" && (!Number.isInteger(object) || Object.is(object, -0) || object.toString(10).indexOf("e") >= 0),
362
- represent: representYamlFloat$1
363
- });
364
- 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))$");
365
- var YAML_FLOAT_SPECIAL_PATTERN = /* @__PURE__ */ new RegExp("^(?:[-+]?\\.(?:inf|Inf|INF)|\\.(?:nan|NaN|NAN))$");
366
- function resolveYamlFloat(source) {
367
- if (!YAML_FLOAT_PATTERN.test(source)) return NOT_RESOLVED;
368
- let value = source.toLowerCase().replace(/_/g, "");
369
- const sign = value[0] === "-" ? -1 : 1;
370
- if ("+-".includes(value[0])) value = value.slice(1);
371
- if (value === ".inf") return sign === 1 ? Number.POSITIVE_INFINITY : Number.NEGATIVE_INFINITY;
372
- if (value === ".nan") return NaN;
373
- let result = 0;
374
- if (value.includes(":")) {
375
- for (const part of value.split(":")) result = result * 60 + Number(part);
376
- result *= sign;
377
- } else result = sign * parseFloat(value);
378
- if (Number.isFinite(result) || YAML_FLOAT_SPECIAL_PATTERN.test(source)) return result;
379
- return NOT_RESOLVED;
380
- }
381
- function representYamlFloat(object) {
382
- if (isNaN(object)) return ".nan";
383
- if (object === Number.POSITIVE_INFINITY) return ".inf";
384
- if (object === Number.NEGATIVE_INFINITY) return "-.inf";
385
- if (Object.is(object, -0)) return "-0.0";
386
- const result = object.toString(10);
387
- return /^[-+]?[0-9]+e/.test(result) ? result.replace("e", ".e") : result;
388
- }
389
- var floatYaml11Tag = defineScalarTag("tag:yaml.org,2002:float", {
390
- implicit: true,
391
- implicitFirstChars: [
392
- "-",
393
- "+",
394
- ".",
395
- ..."0123456789"
396
- ],
397
- resolve: resolveYamlFloat,
398
- identify: (object) => typeof object === "number" && (!Number.isInteger(object) || Object.is(object, -0) || object.toString(10).indexOf("e") >= 0),
399
- represent: representYamlFloat
400
- });
401
- var mergeTag = defineScalarTag("tag:yaml.org,2002:merge", {
402
- implicit: true,
403
- implicitFirstChars: ["<"],
404
- resolve: (source, isExplicit) => {
405
- if (source === "<<" || isExplicit && source === "") return "<<";
406
- return NOT_RESOLVED;
407
- },
408
- identify: () => false
409
- });
410
- var BASE64_PATTERN = /^[A-Za-z0-9+/]*={0,2}$/;
411
- function resolveYamlBinary(source) {
412
- const input = source.replace(/\s/g, "");
413
- if (input.length % 4 !== 0 || !BASE64_PATTERN.test(input)) return NOT_RESOLVED;
414
- const binary = atob(input);
415
- const result = new Uint8Array(binary.length);
416
- for (let index = 0; index < binary.length; index++) result[index] = binary.charCodeAt(index);
417
- return result;
418
- }
419
- function representYamlBinary(object) {
420
- let binary = "";
421
- for (let index = 0; index < object.length; index++) binary += String.fromCharCode(object[index]);
422
- return btoa(binary);
423
- }
424
- var binaryTag = defineScalarTag("tag:yaml.org,2002:binary", {
425
- resolve: resolveYamlBinary,
426
- identify: (object) => Object.prototype.toString.call(object) === "[object Uint8Array]",
427
- represent: representYamlBinary
428
- });
429
- var YAML_DATE_REGEXP = /* @__PURE__ */ new RegExp("^([0-9][0-9][0-9][0-9])-([0-9][0-9])-([0-9][0-9])$");
430
- 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]))?))?$");
431
- function makeUtcDate(year, month, day, hour = 0, minute = 0, second = 0, fraction = 0) {
432
- const date = new Date(Date.UTC(year, month, day, hour, minute, second, fraction));
433
- date.setUTCFullYear(year, month, day);
434
- return date;
435
- }
436
- function resolveYamlTimestamp(source) {
437
- let match = YAML_DATE_REGEXP.exec(source);
438
- if (match === null) match = YAML_TIMESTAMP_REGEXP.exec(source);
439
- if (match === null) return NOT_RESOLVED;
440
- const year = +match[1];
441
- const month = +match[2] - 1;
442
- const day = +match[3];
443
- if (!match[4]) {
444
- const date2 = makeUtcDate(year, month, day);
445
- if (date2.getUTCFullYear() !== year || date2.getUTCMonth() !== month || date2.getUTCDate() !== day) return NOT_RESOLVED;
446
- return date2;
447
- }
448
- const hour = +match[4];
449
- const minute = +match[5];
450
- const second = +match[6];
451
- let fraction = 0;
452
- if (hour > 23 || minute > 59 || second > 59) return NOT_RESOLVED;
453
- if (match[7]) {
454
- let value = match[7].slice(0, 3);
455
- while (value.length < 3) value += "0";
456
- fraction = +value;
457
- }
458
- const date = makeUtcDate(year, month, day, hour, minute, second, fraction);
459
- if (date.getUTCFullYear() !== year || date.getUTCMonth() !== month || date.getUTCDate() !== day) return NOT_RESOLVED;
460
- if (match[9]) {
461
- const offsetHour = +match[10];
462
- const offsetMinute = +(match[11] || 0);
463
- if (offsetHour > 23 || offsetMinute > 59) return NOT_RESOLVED;
464
- const offset = (offsetHour * 60 + offsetMinute) * 6e4;
465
- date.setTime(date.getTime() - (match[9] === "-" ? -offset : offset));
466
- }
467
- return date;
468
- }
469
- var timestampTag = defineScalarTag("tag:yaml.org,2002:timestamp", {
470
- implicit: true,
471
- implicitFirstChars: [..."0123456789"],
472
- resolve: resolveYamlTimestamp,
473
- identify: (object) => object instanceof Date,
474
- represent: (object) => object.toISOString()
475
- });
476
- var seqTag = defineSequenceTag("tag:yaml.org,2002:seq", {
477
- create: () => [],
478
- addItem: (container, item) => {
479
- container.push(item);
480
- },
481
- identify: Array.isArray
482
- });
483
- function isPlainObject(data) {
484
- if (data === null || typeof data !== "object" || Array.isArray(data)) return false;
485
- const prototype = Object.getPrototypeOf(data);
486
- return prototype === null || prototype === Object.prototype;
487
- }
488
- function pick(object, keys) {
489
- const result = {};
490
- for (const key of keys) if (object[key] !== void 0) result[key] = object[key];
491
- return result;
492
- }
493
- var omapTag = defineSequenceTag("tag:yaml.org,2002:omap", {
494
- create: () => ({
495
- list: [],
496
- seen: /* @__PURE__ */ new Set()
497
- }),
498
- addItem: (carrier, item) => {
499
- let key;
500
- if (item instanceof Map) {
501
- if (item.size !== 1) return "cannot resolve an ordered map item";
502
- key = item.keys().next().value;
503
- } else if (isPlainObject(item)) {
504
- const itemKeys = Object.keys(item);
505
- if (itemKeys.length !== 1) return "cannot resolve an ordered map item";
506
- key = itemKeys[0];
507
- } else return "cannot resolve an ordered map item";
508
- if (carrier.seen.has(key)) return "duplicate key in ordered map";
509
- carrier.seen.add(key);
510
- carrier.list.push(item);
511
- return "";
512
- },
513
- finalize: (carrier) => carrier.list,
514
- identify: () => false
515
- });
516
- var pairsTag = defineSequenceTag("tag:yaml.org,2002:pairs", {
517
- create: () => [],
518
- addItem: (container, item) => {
519
- if (item instanceof Map) {
520
- if (item.size !== 1) return "cannot resolve a pairs item";
521
- container.push(item.entries().next().value);
522
- return "";
523
- }
524
- if (Object.prototype.toString.call(item) !== "[object Object]") return "cannot resolve a pairs item";
525
- const object = item;
526
- const keys = Object.keys(object);
527
- if (keys.length !== 1) return "cannot resolve a pairs item";
528
- container.push([keys[0], object[keys[0]]]);
529
- return "";
530
- },
531
- identify: () => false
532
- });
533
- var mapTag = defineMappingTag("tag:yaml.org,2002:map", {
534
- create: () => ({}),
535
- identify: isPlainObject,
536
- represent: (o) => {
537
- const map = /* @__PURE__ */ new Map();
538
- for (const key of Object.keys(o)) map.set(key, o[key]);
539
- return map;
540
- },
541
- addPair: (container, key, value) => {
542
- if (key !== null && typeof key === "object") return "object-based map does not support complex keys";
543
- const normalizedKey = String(key);
544
- if (normalizedKey === "__proto__") Object.defineProperty(container, normalizedKey, {
545
- value,
546
- enumerable: true,
547
- configurable: true,
548
- writable: true
549
- });
550
- else container[normalizedKey] = value;
551
- return "";
552
- },
553
- has: (container, key) => {
554
- if (key !== null && typeof key === "object") return false;
555
- return Object.prototype.hasOwnProperty.call(container, String(key));
556
- },
557
- keys: (container) => Object.keys(container),
558
- get: (container, key) => {
559
- const normalizedKey = String(key);
560
- if (!Object.prototype.hasOwnProperty.call(container, normalizedKey)) return null;
561
- return container[normalizedKey];
562
- }
563
- });
564
- var setTag = defineMappingTag("tag:yaml.org,2002:set", {
565
- create: () => /* @__PURE__ */ new Set(),
566
- identify: (data) => data instanceof Set,
567
- represent: (data) => {
568
- const map = /* @__PURE__ */ new Map();
569
- for (const key of data) map.set(key, null);
570
- return map;
571
- },
572
- addPair: (container, key, value) => {
573
- if (value !== null) return "cannot resolve a set item";
574
- container.add(key);
575
- return "";
576
- },
577
- has: (container, key) => container.has(key),
578
- keys: (container) => container.keys(),
579
- get: () => null
580
- });
581
- function createTagDefinitionMap() {
582
- return {
583
- scalar: /* @__PURE__ */ Object.create(null),
584
- sequence: /* @__PURE__ */ Object.create(null),
585
- mapping: /* @__PURE__ */ Object.create(null)
586
- };
587
- }
588
- function createTagDefinitionListMap() {
589
- return {
590
- scalar: [],
591
- sequence: [],
592
- mapping: []
593
- };
594
- }
595
- function compileTags(tags) {
596
- const result = [];
597
- for (const tag of tags) {
598
- let index = result.length;
599
- for (let previousIndex = 0; previousIndex < result.length; previousIndex++) {
600
- const previous = result[previousIndex];
601
- if (previous.nodeKind === tag.nodeKind && previous.tagName === tag.tagName && previous.matchByTagPrefix === tag.matchByTagPrefix) {
602
- index = previousIndex;
603
- break;
604
- }
605
- }
606
- result[index] = tag;
607
- }
608
- return result;
609
- }
610
- var Schema = class Schema2 {
611
- tags;
612
- /** @internal */
613
- implicitScalarTags;
614
- /**
615
- * Dispatch implicit scalar resolvers by `source.charAt(0)`. Each bucket holds
616
- * the resolvers that may match that key, in schema order; a key absent from
617
- * the map uses
618
- * {@link Schema.implicitScalarAnyFirstChar}
619
- * (resolvers that declared no first-char constraint, so they apply to any
620
- * first character).
621
- */
622
- implicitScalarByFirstChar;
623
- implicitScalarAnyFirstChar;
624
- /**
625
- * The default scalar tag (`!!str`), resolved once so the composer's fallback
626
- * for unresolved plain scalars avoids a keyed lookup per scalar.
627
- *
628
- * @internal
629
- */
630
- defaultScalarTag;
631
- /**
632
- * The default container tags (`!!seq` / `!!map`), used by the dumper: when a
633
- * value is identified by its default tag, the tag is implicit and not
634
- * printed. Undefined if the schema does not define them (then such values
635
- * can't be dumped).
636
- *
637
- * @internal
638
- */
639
- defaultSequenceTag;
640
- /** @internal */
641
- defaultMappingTag;
642
- exact;
643
- prefix;
644
- constructor(tags) {
645
- const compiledTags = compileTags(tags);
646
- const implicitScalarTags = [];
647
- const exact = createTagDefinitionMap();
648
- const prefix = createTagDefinitionListMap();
649
- for (const tag of compiledTags) {
650
- if (tag.nodeKind === "scalar" && tag.implicit) {
651
- if (tag.matchByTagPrefix) throw new Error("Implicit scalar tags cannot match by tag prefix");
652
- implicitScalarTags.push(tag);
653
- }
654
- switch (tag.nodeKind) {
655
- case "scalar":
656
- if (tag.matchByTagPrefix) prefix.scalar.push(tag);
657
- else exact.scalar[tag.tagName] = tag;
658
- break;
659
- case "sequence":
660
- if (tag.matchByTagPrefix) prefix.sequence.push(tag);
661
- else exact.sequence[tag.tagName] = tag;
662
- break;
663
- case "mapping":
664
- if (tag.matchByTagPrefix) prefix.mapping.push(tag);
665
- else exact.mapping[tag.tagName] = tag;
666
- break;
667
- }
668
- }
669
- const implicitScalarAnyFirstChar = implicitScalarTags.filter((tag) => tag.implicitFirstChars === null);
670
- const keys = /* @__PURE__ */ new Set();
671
- for (const tag of implicitScalarTags) if (tag.implicitFirstChars !== null) for (const key of tag.implicitFirstChars) keys.add(key);
672
- const implicitScalarByFirstChar = /* @__PURE__ */ new Map();
673
- for (const key of keys) implicitScalarByFirstChar.set(key, implicitScalarTags.filter((tag) => tag.implicitFirstChars === null || tag.implicitFirstChars.indexOf(key) !== -1));
674
- const defaultScalarTag = exact.scalar["tag:yaml.org,2002:str"];
675
- if (!defaultScalarTag) throw new Error("schema does not define the default scalar tag (tag:yaml.org,2002:str)");
676
- this.tags = compiledTags;
677
- this.implicitScalarTags = implicitScalarTags;
678
- this.implicitScalarByFirstChar = implicitScalarByFirstChar;
679
- this.implicitScalarAnyFirstChar = implicitScalarAnyFirstChar;
680
- this.defaultScalarTag = defaultScalarTag;
681
- this.defaultSequenceTag = exact.sequence["tag:yaml.org,2002:seq"];
682
- this.defaultMappingTag = exact.mapping["tag:yaml.org,2002:map"];
683
- this.exact = exact;
684
- this.prefix = prefix;
685
- }
686
- /** @internal */
687
- lookupScalarTag(tagName) {
688
- const exactTag = this.exact.scalar[tagName];
689
- if (exactTag) return exactTag;
690
- for (const tag of this.prefix.scalar) if (tagName.startsWith(tag.tagName)) return tag;
691
- }
692
- /** @internal */
693
- lookupSequenceTag(tagName) {
694
- const exactTag = this.exact.sequence[tagName];
695
- if (exactTag) return exactTag;
696
- for (const tag of this.prefix.sequence) if (tagName.startsWith(tag.tagName)) return tag;
697
- }
698
- /** @internal */
699
- lookupMappingTag(tagName) {
700
- const exactTag = this.exact.mapping[tagName];
701
- if (exactTag) return exactTag;
702
- for (const tag of this.prefix.mapping) if (tagName.startsWith(tag.tagName)) return tag;
703
- }
704
- /** @internal */
705
- resolveImplicitScalarTag(source) {
706
- const candidates = this.implicitScalarByFirstChar.get(source.charAt(0)) ?? this.implicitScalarAnyFirstChar;
707
- for (const tag2 of candidates) {
708
- const value = tag2.resolve(source, false, tag2.tagName);
709
- if (value !== NOT_RESOLVED) return {
710
- value,
711
- tag: tag2
712
- };
713
- }
714
- const tag = this.defaultScalarTag;
715
- return {
716
- value: tag.resolve(source, false, tag.tagName),
717
- tag
718
- };
719
- }
720
- /**
721
- * Creates a new schema with the specified tags added. If a tag already
722
- * exists, it is replaced by the specified tag.
723
- *
724
- * @example
725
- *
726
- * ```javascript
727
- * import { CORE_SCHEMA, mergeTag, realMapTag } from 'js-yaml'
728
- *
729
- * const schema = CORE_SCHEMA.withTags(mergeTag, realMapTag)
730
- * ```
731
- */
732
- withTags(...tags) {
733
- let flatTags = [];
734
- for (const tag of tags) flatTags = flatTags.concat(tag);
735
- return new Schema2([...this.tags, ...flatTags]);
736
- }
737
- };
738
- var FAILSAFE_SCHEMA = new Schema([
739
- strTag,
740
- seqTag,
741
- mapTag
742
- ]);
743
- var JSON_SCHEMA = new Schema([
744
- ...FAILSAFE_SCHEMA.tags,
745
- nullJsonTag,
746
- boolJsonTag,
747
- intJsonTag,
748
- floatJsonTag
749
- ]);
750
- var CORE_SCHEMA = new Schema([
751
- ...FAILSAFE_SCHEMA.tags,
752
- nullCoreTag,
753
- boolCoreTag,
754
- intCoreTag,
755
- floatCoreTag
756
- ]);
757
- var YAML11_SCHEMA = new Schema([
758
- ...FAILSAFE_SCHEMA.tags,
759
- nullYaml11Tag,
760
- boolYaml11Tag,
761
- intYaml11Tag,
762
- floatYaml11Tag,
763
- timestampTag,
764
- mergeTag,
765
- binaryTag,
766
- omapTag,
767
- pairsTag,
768
- setTag
769
- ]);
770
- var DUMP_SCHEMA = YAML11_SCHEMA.withTags({
771
- ...intYaml11Tag,
772
- resolve: (source, isExplicit, tagName) => {
773
- const result = intYaml11Tag.resolve(source, isExplicit, tagName);
774
- return result === NOT_RESOLVED ? intCoreTag.resolve(source, isExplicit, tagName) : result;
775
- }
776
- }, {
777
- ...floatYaml11Tag,
778
- resolve: (source, isExplicit, tagName) => {
779
- const result = floatYaml11Tag.resolve(source, isExplicit, tagName);
780
- return result === NOT_RESOLVED ? floatCoreTag.resolve(source, isExplicit, tagName) : result;
781
- }
782
- });
783
- var realMapTag = defineMappingTag("tag:yaml.org,2002:map", {
784
- create: () => /* @__PURE__ */ new Map(),
785
- addPair: (container, key, value) => {
786
- container.set(key, value);
787
- return "";
788
- },
789
- has: (container, key) => container.has(key),
790
- keys: (container) => container.keys(),
791
- get: (container, key) => container.get(key),
792
- identify: (data) => data instanceof Map || isPlainObject(data),
793
- represent: (data) => {
794
- if (data instanceof Map) return data;
795
- const map = /* @__PURE__ */ new Map();
796
- const obj = data;
797
- for (const key of Object.keys(obj)) map.set(key, obj[key]);
798
- return map;
799
- }
800
- });
801
- function normalizeKey(key) {
802
- if (Array.isArray(key)) {
803
- const array = Array.prototype.slice.call(key);
804
- for (let index = 0; index < array.length; index++) {
805
- if (Array.isArray(array[index])) return null;
806
- if (typeof array[index] === "object" && Object.prototype.toString.call(array[index]) === "[object Object]") array[index] = "[object Object]";
807
- }
808
- return String(array);
809
- }
810
- if (typeof key === "object" && Object.prototype.toString.call(key) === "[object Object]") return "[object Object]";
811
- return String(key);
812
- }
813
- var legacyMapTag = defineMappingTag("tag:yaml.org,2002:map", {
814
- create: () => ({}),
815
- identify: isPlainObject,
816
- represent: (o) => {
817
- const map = /* @__PURE__ */ new Map();
818
- for (const key of Object.keys(o)) map.set(key, o[key]);
819
- return map;
820
- },
821
- addPair: (container, key, value) => {
822
- const normalizedKey = normalizeKey(key);
823
- if (normalizedKey === null) return "nested arrays are not supported inside keys";
824
- if (normalizedKey === "__proto__") Object.defineProperty(container, normalizedKey, {
825
- value,
826
- enumerable: true,
827
- configurable: true,
828
- writable: true
829
- });
830
- else container[normalizedKey] = value;
831
- return "";
832
- },
833
- has: (container, key) => {
834
- const normalizedKey = normalizeKey(key);
835
- return normalizedKey !== null && Object.prototype.hasOwnProperty.call(container, normalizedKey);
836
- },
837
- keys: (container) => Object.keys(container),
838
- get: (container, key) => {
839
- const normalizedKey = String(key);
840
- if (!Object.prototype.hasOwnProperty.call(container, normalizedKey)) return null;
841
- return container[normalizedKey];
842
- }
843
- });
844
- var DEFAULT_SNIPPET_OPTIONS = {
845
- maxLength: 79,
846
- indent: 1,
847
- linesBefore: 3,
848
- linesAfter: 2
849
- };
850
- function getLine(buffer, lineStart, lineEnd, position, maxLineLength) {
851
- let head = "";
852
- let tail = "";
853
- const maxHalfLength = Math.floor(maxLineLength / 2) - 1;
854
- if (position - lineStart > maxHalfLength) {
855
- head = " ... ";
856
- lineStart = position - maxHalfLength + head.length;
857
- }
858
- if (lineEnd - position > maxHalfLength) {
859
- tail = " ...";
860
- lineEnd = position + maxHalfLength - tail.length;
861
- }
862
- return {
863
- str: head + buffer.slice(lineStart, lineEnd).replace(/\t/g, "\u2192") + tail,
864
- pos: position - lineStart + head.length
865
- };
866
- }
867
- function padStart(string, max) {
868
- return " ".repeat(Math.max(max - string.length, 0)) + string;
869
- }
870
- function makeSnippet(mark, options) {
871
- if (!mark.buffer) return null;
872
- const opts = {
873
- ...DEFAULT_SNIPPET_OPTIONS,
874
- ...options
875
- };
876
- const re = /\r?\n|\r|\0/g;
877
- const lineStarts = [0];
878
- const lineEnds = [];
879
- let match;
880
- let foundLineNo = -1;
881
- while (match = re.exec(mark.buffer)) {
882
- lineEnds.push(match.index);
883
- lineStarts.push(match.index + match[0].length);
884
- if (mark.position <= match.index && foundLineNo < 0) foundLineNo = lineStarts.length - 2;
885
- }
886
- if (foundLineNo < 0) foundLineNo = lineStarts.length - 1;
887
- let result = "";
888
- const lineNoLength = Math.min(mark.line + opts.linesAfter, lineEnds.length).toString().length;
889
- const maxLineLength = opts.maxLength - (opts.indent + lineNoLength + 3);
890
- for (let i = 1; i <= opts.linesBefore; i++) {
891
- if (foundLineNo - i < 0) break;
892
- const line2 = getLine(mark.buffer, lineStarts[foundLineNo - i], lineEnds[foundLineNo - i], mark.position - (lineStarts[foundLineNo] - lineStarts[foundLineNo - i]), maxLineLength);
893
- result = `${" ".repeat(opts.indent)}${padStart((mark.line - i + 1).toString(), lineNoLength)} | ${line2.str}
894
- ${result}`;
895
- }
896
- const line = getLine(mark.buffer, lineStarts[foundLineNo], lineEnds[foundLineNo], mark.position, maxLineLength);
897
- result += `${" ".repeat(opts.indent)}${padStart((mark.line + 1).toString(), lineNoLength)} | ${line.str}
898
- `;
899
- result += `${"-".repeat(opts.indent + lineNoLength + 3 + line.pos)}^
900
- `;
901
- for (let i = 1; i <= opts.linesAfter; i++) {
902
- if (foundLineNo + i >= lineEnds.length) break;
903
- const line2 = getLine(mark.buffer, lineStarts[foundLineNo + i], lineEnds[foundLineNo + i], mark.position - (lineStarts[foundLineNo] - lineStarts[foundLineNo + i]), maxLineLength);
904
- result += `${" ".repeat(opts.indent)}${padStart((mark.line + i + 1).toString(), lineNoLength)} | ${line2.str}
905
- `;
906
- }
907
- return result.replace(/\n$/, "");
908
- }
909
- function formatError(exception, compact) {
910
- let where = "";
911
- if (!exception.mark) return exception.reason;
912
- if (exception.mark.name) where += `in "${exception.mark.name}" `;
913
- where += `(${exception.mark.line + 1}:${exception.mark.column + 1})`;
914
- if (!compact && exception.mark.snippet) where += `
915
-
916
- ${exception.mark.snippet}`;
917
- return `${exception.reason} ${where}`;
918
- }
919
- var YAMLException = class YAMLException2 extends Error {
920
- reason;
921
- mark;
922
- /**
923
- * Optional `mark` contains source snippet data. Usually, use
924
- * {@link YAMLException.throwAt} instead of passing it directly.
925
- */
926
- constructor(reason, mark) {
927
- super();
928
- this.name = "YAMLException";
929
- this.reason = reason;
930
- this.mark = mark;
931
- this.message = formatError(this, false);
932
- if (Error.captureStackTrace) Error.captureStackTrace(this, this.constructor);
933
- }
934
- /**
935
- * Returns the formatted error, omitting the source snippet in compact mode.
936
- */
937
- toString(compact) {
938
- return `${this.name}: ${formatError(this, compact)}`;
939
- }
940
- /**
941
- * Builds a YAMLException with a source snippet and throws it. `source` is
942
- * the raw input text; `position` is an offset into it.
943
- */
944
- static throwAt(source, position, message, filename = "") {
945
- let line = 0;
946
- let lineStart = 0;
947
- for (let index = 0; index < position; index++) {
948
- const ch = source.charCodeAt(index);
949
- if (ch === 10) {
950
- line++;
951
- lineStart = index + 1;
952
- } else if (ch === 13) {
953
- line++;
954
- if (source.charCodeAt(index + 1) === 10) index++;
955
- lineStart = index + 1;
956
- }
957
- }
958
- const mark = {
959
- name: filename,
960
- buffer: source,
961
- position,
962
- line,
963
- column: position - lineStart
964
- };
965
- mark.snippet = makeSnippet(mark);
966
- throw new YAMLException2(message, mark);
967
- }
968
- };
969
- var EVENT_ID = {
970
- DOCUMENT: 1,
971
- SEQUENCE: 2,
972
- MAPPING: 3,
973
- SCALAR: 4,
974
- ALIAS: 5,
975
- POP: 6
976
- };
977
- var SCALAR_STYLE = {
978
- PLAIN: 1,
979
- SINGLE_QUOTED: 2,
980
- DOUBLE_QUOTED: 3,
981
- LITERAL_BLOCK: 4,
982
- FOLDED_BLOCK: 5
983
- };
984
- var COLLECTION_STYLE = {
985
- BLOCK: 1,
986
- FLOW: 2
987
- };
988
- var CHOMPING_MODE = {
989
- CLIP: 1,
990
- STRIP: 2,
991
- KEEP: 3
992
- };
993
- var NO_RANGE$3 = -1;
994
- function simpleEscapeSequence(c) {
995
- switch (c) {
996
- case 48:
997
- return "\0";
998
- case 97:
999
- return "\x07";
1000
- case 98:
1001
- return "\b";
1002
- case 116:
1003
- return " ";
1004
- case 9:
1005
- return " ";
1006
- case 110:
1007
- return "\n";
1008
- case 118:
1009
- return "\v";
1010
- case 102:
1011
- return "\f";
1012
- case 114:
1013
- return "\r";
1014
- case 101:
1015
- return "\x1B";
1016
- case 32:
1017
- return " ";
1018
- case 34:
1019
- return '"';
1020
- case 47:
1021
- return "/";
1022
- case 92:
1023
- return "\\";
1024
- case 78:
1025
- return "\x85";
1026
- case 95:
1027
- return "\xA0";
1028
- case 76:
1029
- return "\u2028";
1030
- case 80:
1031
- return "\u2029";
1032
- default:
1033
- return "";
1034
- }
1035
- }
1036
- var simpleEscapeCheck = new Array(256);
1037
- var simpleEscapeMap = new Array(256);
1038
- for (let i = 0; i < 256; i++) {
1039
- simpleEscapeCheck[i] = simpleEscapeSequence(i) ? 1 : 0;
1040
- simpleEscapeMap[i] = simpleEscapeSequence(i);
1041
- }
1042
- function charFromCodepoint(c) {
1043
- if (c <= 65535) return String.fromCharCode(c);
1044
- return String.fromCharCode((c - 65536 >> 10) + 55296, (c - 65536 & 1023) + 56320);
1045
- }
1046
- function fromHexCode$1(c) {
1047
- if (c >= 48 && c <= 57) return c - 48;
1048
- return (c | 32) - 97 + 10;
1049
- }
1050
- function escapedHexLen$1(c) {
1051
- if (c === 120) return 2;
1052
- if (c === 117) return 4;
1053
- return 8;
1054
- }
1055
- function skipFoldedBreaks(input, position, end) {
1056
- let breaks = 0;
1057
- while (position < end) {
1058
- const ch = input.charCodeAt(position);
1059
- if (ch === 10) {
1060
- breaks++;
1061
- position++;
1062
- } else if (ch === 13) {
1063
- breaks++;
1064
- position++;
1065
- if (input.charCodeAt(position) === 10) position++;
1066
- } else if (ch === 32 || ch === 9) position++;
1067
- else break;
1068
- }
1069
- return {
1070
- position,
1071
- breaks
1072
- };
1073
- }
1074
- function foldedBreaks(count) {
1075
- if (count === 1) return " ";
1076
- return "\n".repeat(count - 1);
1077
- }
1078
- function getPlainValue(input, start, end) {
1079
- let result = "";
1080
- let position = start;
1081
- let captureStart = start;
1082
- let captureEnd = start;
1083
- while (position < end) {
1084
- const ch = input.charCodeAt(position);
1085
- if (ch === 10 || ch === 13) {
1086
- result += input.slice(captureStart, captureEnd);
1087
- const fold = skipFoldedBreaks(input, position, end);
1088
- result += foldedBreaks(fold.breaks);
1089
- position = captureStart = captureEnd = fold.position;
1090
- } else {
1091
- position++;
1092
- if (ch !== 32 && ch !== 9) captureEnd = position;
1093
- }
1094
- }
1095
- return result + input.slice(captureStart, captureEnd);
1096
- }
1097
- function getSingleQuotedValue(input, start, end) {
1098
- let result = "";
1099
- let position = start;
1100
- let captureStart = start;
1101
- let captureEnd = start;
1102
- while (position < end) {
1103
- const ch = input.charCodeAt(position);
1104
- if (ch === 39) {
1105
- result += input.slice(captureStart, position) + "'";
1106
- position += 2;
1107
- captureStart = captureEnd = position;
1108
- } else if (ch === 10 || ch === 13) {
1109
- result += input.slice(captureStart, captureEnd);
1110
- const fold = skipFoldedBreaks(input, position, end);
1111
- result += foldedBreaks(fold.breaks);
1112
- position = captureStart = captureEnd = fold.position;
1113
- } else {
1114
- position++;
1115
- if (ch !== 32 && ch !== 9) captureEnd = position;
1116
- }
1117
- }
1118
- return result + input.slice(captureStart, end);
1119
- }
1120
- function getDoubleQuotedValue(input, start, end) {
1121
- let result = "";
1122
- let position = start;
1123
- let captureStart = start;
1124
- let captureEnd = start;
1125
- while (position < end) {
1126
- const ch = input.charCodeAt(position);
1127
- if (ch === 92) {
1128
- result += input.slice(captureStart, position);
1129
- position++;
1130
- const escaped = input.charCodeAt(position);
1131
- if (escaped === 10 || escaped === 13) position = skipFoldedBreaks(input, position, end).position;
1132
- else if (escaped < 256 && simpleEscapeCheck[escaped]) {
1133
- result += simpleEscapeMap[escaped];
1134
- position++;
1135
- } else {
1136
- let hexLength = escapedHexLen$1(escaped);
1137
- let hexResult = 0;
1138
- for (; hexLength > 0; hexLength--) {
1139
- position++;
1140
- const digit = fromHexCode$1(input.charCodeAt(position));
1141
- hexResult = (hexResult << 4) + digit;
1142
- }
1143
- result += charFromCodepoint(hexResult);
1144
- position++;
1145
- }
1146
- captureStart = captureEnd = position;
1147
- } else if (ch === 10 || ch === 13) {
1148
- result += input.slice(captureStart, captureEnd);
1149
- const fold = skipFoldedBreaks(input, position, end);
1150
- result += foldedBreaks(fold.breaks);
1151
- position = captureStart = captureEnd = fold.position;
1152
- } else {
1153
- position++;
1154
- if (ch !== 32 && ch !== 9) captureEnd = position;
1155
- }
1156
- }
1157
- return result + input.slice(captureStart, end);
1158
- }
1159
- function getBlockValue(input, start, end, indent, chomping, folded) {
1160
- const textIndent = indent < 0 ? 0 : indent;
1161
- const region = input.slice(start, end).replace(/\r\n?/g, "\n");
1162
- const lines = region === "" ? [] : (region.endsWith("\n") ? region.slice(0, -1) : region).split("\n");
1163
- let result = "";
1164
- let didReadContent = false;
1165
- let emptyLines = 0;
1166
- let atMoreIndented = false;
1167
- for (const line of lines) {
1168
- let column = 0;
1169
- while (column < textIndent && line.charCodeAt(column) === 32) column++;
1170
- if (indent < 0 || column >= line.length) {
1171
- emptyLines++;
1172
- continue;
1173
- }
1174
- const content = line.slice(textIndent);
1175
- const first = content.charCodeAt(0);
1176
- if (folded) if (first === 32 || first === 9) {
1177
- atMoreIndented = true;
1178
- result += "\n".repeat(didReadContent ? 1 + emptyLines : emptyLines);
1179
- } else if (atMoreIndented) {
1180
- atMoreIndented = false;
1181
- result += "\n".repeat(emptyLines + 1);
1182
- } else if (emptyLines === 0) {
1183
- if (didReadContent) result += " ";
1184
- } else result += "\n".repeat(emptyLines);
1185
- else result += "\n".repeat(didReadContent ? 1 + emptyLines : emptyLines);
1186
- result += content;
1187
- didReadContent = true;
1188
- emptyLines = 0;
1189
- }
1190
- if (chomping === CHOMPING_MODE.KEEP) result += "\n".repeat(didReadContent ? 1 + emptyLines : emptyLines);
1191
- else if (chomping !== CHOMPING_MODE.STRIP) {
1192
- if (didReadContent) result += "\n";
1193
- }
1194
- return result;
1195
- }
1196
- function getScalarValue(input, scalar) {
1197
- if (scalar.valueStart === NO_RANGE$3) return "";
1198
- const { valueStart, valueEnd } = scalar;
1199
- if (scalar.fast) return input.slice(valueStart, valueEnd);
1200
- switch (scalar.style) {
1201
- case SCALAR_STYLE.SINGLE_QUOTED:
1202
- return getSingleQuotedValue(input, valueStart, valueEnd);
1203
- case SCALAR_STYLE.DOUBLE_QUOTED:
1204
- return getDoubleQuotedValue(input, valueStart, valueEnd);
1205
- case SCALAR_STYLE.LITERAL_BLOCK:
1206
- return getBlockValue(input, valueStart, valueEnd, scalar.indent, scalar.chomping, false);
1207
- case SCALAR_STYLE.FOLDED_BLOCK:
1208
- return getBlockValue(input, valueStart, valueEnd, scalar.indent, scalar.chomping, true);
1209
- default:
1210
- return getPlainValue(input, valueStart, valueEnd);
1211
- }
1212
- }
1213
- var DEFAULT_TAG_HANDLERS = Object.assign(/* @__PURE__ */ Object.create(null), {
1214
- "!": "!",
1215
- "!!": "tag:yaml.org,2002:"
1216
- });
1217
- function tagNameFull(rawTag, tagHandlers) {
1218
- if (rawTag.startsWith("!<") && rawTag.endsWith(">")) return decodeURIComponent(rawTag.slice(2, -1));
1219
- const handleEnd = rawTag.indexOf("!", 1);
1220
- const handle = handleEnd === -1 ? "!" : rawTag.slice(0, handleEnd + 1);
1221
- const prefix = tagHandlers?.[handle] ?? DEFAULT_TAG_HANDLERS[handle] ?? handle;
1222
- return decodeURIComponent(prefix) + decodeURIComponent(rawTag.slice(handle.length));
1223
- }
1224
- var NO_RANGE$2 = -1;
1225
- var MERGE_TAG_NAME = "tag:yaml.org,2002:merge";
1226
- var DEFAULT_CONSTRUCTOR_OPTIONS = {
1227
- filename: "",
1228
- schema: CORE_SCHEMA,
1229
- json: false,
1230
- maxTotalMergeKeys: 1e4,
1231
- maxAliases: -1
1232
- };
1233
- function eventPosition$1(event) {
1234
- if ("tagStart" in event && event.tagStart !== NO_RANGE$2) return event.tagStart;
1235
- if ("anchorStart" in event && event.anchorStart !== NO_RANGE$2) return event.anchorStart;
1236
- if ("valueStart" in event && event.valueStart !== NO_RANGE$2) return event.valueStart;
1237
- if ("start" in event) return event.start;
1238
- return 0;
1239
- }
1240
- function throwError$1(state, message) {
1241
- YAMLException.throwAt(state.source, state.position, message, state.filename);
1242
- }
1243
- function finalizeCollection(state, position, tag, carrier) {
1244
- try {
1245
- return tag.finalize(carrier);
1246
- } catch (error) {
1247
- if (error instanceof YAMLException) throw error;
1248
- YAMLException.throwAt(state.source, position, error instanceof Error ? error.message : String(error), state.filename);
1249
- }
1250
- }
1251
- function constructScalar(state, event) {
1252
- const source = getScalarValue(state.source, event);
1253
- const rawTag = event.tagStart === NO_RANGE$2 ? "" : state.source.slice(event.tagStart, event.tagEnd);
1254
- const strTag2 = state.schema.defaultScalarTag;
1255
- if (rawTag !== "") {
1256
- if (rawTag === "!") return {
1257
- value: source,
1258
- tag: strTag2
1259
- };
1260
- const tagName = tagNameFull(rawTag, state.tagHandlers);
1261
- const scalarTag = state.schema.lookupScalarTag(tagName);
1262
- if (scalarTag) {
1263
- const result = scalarTag.resolve(source, true, tagName);
1264
- if (result === NOT_RESOLVED) throwError$1(state, `cannot resolve a node with !<${tagName}> explicit tag`);
1265
- return {
1266
- value: result,
1267
- tag: scalarTag
1268
- };
1269
- }
1270
- const collectionTagDef = state.schema.lookupMappingTag(tagName) ?? state.schema.lookupSequenceTag(tagName);
1271
- if (collectionTagDef) {
1272
- if (source !== "") throwError$1(state, `cannot resolve a node with !<${tagName}> explicit tag`);
1273
- const carrier = collectionTagDef.create(tagName);
1274
- return {
1275
- value: collectionTagDef.carrierIsResult ? carrier : finalizeCollection(state, state.position, collectionTagDef, carrier),
1276
- tag: collectionTagDef
1277
- };
1278
- }
1279
- throwError$1(state, `unknown scalar tag !<${tagName}>`);
1280
- }
1281
- if (event.style === SCALAR_STYLE.PLAIN) return state.schema.resolveImplicitScalarTag(source);
1282
- return {
1283
- value: strTag2.resolve(source, false, strTag2.tagName),
1284
- tag: strTag2
1285
- };
1286
- }
1287
- function collectionTagName(state, event, defaultTagName) {
1288
- const rawTag = event.tagStart === NO_RANGE$2 ? "" : state.source.slice(event.tagStart, event.tagEnd);
1289
- return rawTag === "" || rawTag === "!" ? defaultTagName : tagNameFull(rawTag, state.tagHandlers);
1290
- }
1291
- function isMappingTag(tag) {
1292
- return tag.nodeKind === "mapping";
1293
- }
1294
- function chargeMergeWork(state) {
1295
- state.totalMergeKeys++;
1296
- if (state.maxTotalMergeKeys !== -1 && state.totalMergeKeys > state.maxTotalMergeKeys) throwError$1(state, `merge keys exceeded maxTotalMergeKeys (${state.maxTotalMergeKeys})`);
1297
- }
1298
- function mergeKeys(state, frame, source, sourceTag) {
1299
- chargeMergeWork(state);
1300
- for (const sourceKey of sourceTag.keys(source)) {
1301
- chargeMergeWork(state);
1302
- if (frame.tag.has(frame.value, sourceKey)) continue;
1303
- const err = frame.tag.addPair(frame.value, sourceKey, sourceTag.get(source, sourceKey));
1304
- if (err) throwError$1(state, err);
1305
- frame.overridable ??= /* @__PURE__ */ new Set();
1306
- frame.overridable.add(sourceKey);
1307
- }
1308
- }
1309
- function mergeSource(state, frame, source, sourceTag) {
1310
- state.position = frame.keyPosition;
1311
- if (isMappingTag(sourceTag)) mergeKeys(state, frame, source, sourceTag);
1312
- else if (sourceTag.nodeKind === "sequence" && Array.isArray(source)) {
1313
- if (source.length > 100) throwError$1(state, "abnormal merge sequence size");
1314
- for (const element of source) {
1315
- const elementTag = state.nodeTags.get(element);
1316
- if (!elementTag) throwError$1(state, "cannot merge mappings; the provided source object is unacceptable");
1317
- mergeKeys(state, frame, element, elementTag);
1318
- }
1319
- } else throwError$1(state, "cannot merge mappings; the provided source object is unacceptable");
1320
- }
1321
- function addMappingValue(state, frame, key, value, tag) {
1322
- state.position = frame.keyPosition;
1323
- if (frame.keyIsMerge) {
1324
- mergeSource(state, frame, value, tag);
1325
- return;
1326
- }
1327
- if (!state.json && frame.tag.has(frame.value, key) && !frame.overridable?.has(key)) throwError$1(state, "duplicated mapping key");
1328
- const err = frame.tag.addPair(frame.value, key, value);
1329
- if (err) throwError$1(state, err);
1330
- frame.overridable?.delete(key);
1331
- }
1332
- function addValue(state, value, tag) {
1333
- const frame = state.frames[state.frames.length - 1];
1334
- if (frame.kind === "document") {
1335
- frame.value = value;
1336
- frame.hasValue = true;
1337
- } else if (frame.kind === "sequence") {
1338
- if (isMappingTag(tag)) state.nodeTags.set(value, tag);
1339
- const err = frame.tag.addItem(frame.value, value, frame.index++);
1340
- if (err) throwError$1(state, err);
1341
- } else if (frame.hasKey) {
1342
- const key = frame.key;
1343
- frame.key = void 0;
1344
- frame.hasKey = false;
1345
- addMappingValue(state, frame, key, value, tag);
1346
- } else {
1347
- frame.key = value;
1348
- frame.keyPosition = state.position;
1349
- frame.hasKey = true;
1350
- frame.keyIsMerge = tag.tagName === MERGE_TAG_NAME;
1351
- }
1352
- }
1353
- function storeAnchor(state, event, value, tag, isValueFinal) {
1354
- if (event.anchorStart !== NO_RANGE$2) {
1355
- const anchor = {
1356
- value,
1357
- tag,
1358
- isValueFinal
1359
- };
1360
- state.anchors.set(state.source.slice(event.anchorStart, event.anchorEnd), anchor);
1361
- return anchor;
1362
- }
1363
- return null;
1364
- }
1365
- function constructFromEvents(events, options) {
1366
- const state = {
1367
- ...DEFAULT_CONSTRUCTOR_OPTIONS,
1368
- ...options,
1369
- events,
1370
- documents: [],
1371
- eventIndex: 0,
1372
- position: 0,
1373
- frames: [],
1374
- anchors: /* @__PURE__ */ new Map(),
1375
- nodeTags: /* @__PURE__ */ new Map(),
1376
- tagHandlers: /* @__PURE__ */ Object.create(null),
1377
- totalMergeKeys: 0,
1378
- aliasCount: 0
1379
- };
1380
- while (state.eventIndex < state.events.length) {
1381
- const event = state.events[state.eventIndex++];
1382
- state.position = eventPosition$1(event);
1383
- switch (event.type) {
1384
- case EVENT_ID.DOCUMENT:
1385
- state.anchors = /* @__PURE__ */ new Map();
1386
- state.nodeTags = /* @__PURE__ */ new Map();
1387
- state.aliasCount = 0;
1388
- state.tagHandlers = /* @__PURE__ */ Object.create(null);
1389
- for (const directive of event.directives) if (directive.kind === "tag") state.tagHandlers[directive.handle] = directive.prefix;
1390
- state.frames.push({
1391
- kind: "document",
1392
- position: state.position,
1393
- value: void 0,
1394
- hasValue: false
1395
- });
1396
- break;
1397
- case EVENT_ID.SCALAR: {
1398
- const { value, tag } = constructScalar(state, event);
1399
- storeAnchor(state, event, value, tag, true);
1400
- addValue(state, value, tag);
1401
- break;
1402
- }
1403
- case EVENT_ID.SEQUENCE: {
1404
- const tagName = collectionTagName(state, event, "tag:yaml.org,2002:seq");
1405
- const tag = state.schema.lookupSequenceTag(tagName);
1406
- if (!tag) throwError$1(state, `unknown sequence tag !<${tagName}>`);
1407
- const value = tag.create(tagName);
1408
- const anchor = storeAnchor(state, event, value, tag, tag.carrierIsResult);
1409
- state.frames.push({
1410
- kind: "sequence",
1411
- position: state.position,
1412
- value,
1413
- tag,
1414
- anchor,
1415
- index: 0
1416
- });
1417
- break;
1418
- }
1419
- case EVENT_ID.MAPPING: {
1420
- const tagName = collectionTagName(state, event, "tag:yaml.org,2002:map");
1421
- const tag = state.schema.lookupMappingTag(tagName);
1422
- if (!tag) throwError$1(state, `unknown mapping tag !<${tagName}>`);
1423
- const value = tag.create(tagName);
1424
- const anchor = storeAnchor(state, event, value, tag, tag.carrierIsResult);
1425
- state.frames.push({
1426
- kind: "mapping",
1427
- position: state.position,
1428
- value,
1429
- tag,
1430
- anchor,
1431
- key: void 0,
1432
- keyPosition: state.position,
1433
- hasKey: false,
1434
- keyIsMerge: false,
1435
- overridable: null
1436
- });
1437
- break;
1438
- }
1439
- case EVENT_ID.ALIAS: {
1440
- if (state.maxAliases !== -1 && ++state.aliasCount > state.maxAliases) throwError$1(state, `aliases exceeded maxAliases (${state.maxAliases})`);
1441
- const name = state.source.slice(event.anchorStart, event.anchorEnd);
1442
- const anchor = state.anchors.get(name);
1443
- if (!anchor) throwError$1(state, `unidentified alias "${name}"`);
1444
- if (!anchor.isValueFinal) throwError$1(state, `recursive alias "${name}" is not supported for tag ${anchor.tag.tagName} because it uses finalize()`);
1445
- addValue(state, anchor.value, anchor.tag);
1446
- break;
1447
- }
1448
- case EVENT_ID.POP: {
1449
- const frame = state.frames.pop();
1450
- if (frame.kind === "mapping" && frame.hasKey) {
1451
- state.position = frame.keyPosition;
1452
- throwError$1(state, "incomplete mapping pair in event stream");
1453
- }
1454
- if (frame.kind === "document") state.documents.push(frame.value);
1455
- else {
1456
- const value = frame.tag.carrierIsResult ? frame.value : finalizeCollection(state, frame.position, frame.tag, frame.value);
1457
- if (frame.anchor) {
1458
- frame.anchor.value = value;
1459
- frame.anchor.isValueFinal = true;
1460
- }
1461
- addValue(state, value, frame.tag);
1462
- }
1463
- break;
1464
- }
1465
- }
1466
- }
1467
- return state.documents;
1468
- }
1469
- var NO_RANGE$1 = -1;
1470
- var HAS_OWN = Object.prototype.hasOwnProperty;
1471
- var CONTEXT_FLOW_IN = 1;
1472
- var CONTEXT_FLOW_OUT = 2;
1473
- var CONTEXT_BLOCK_IN = 3;
1474
- var CONTEXT_BLOCK_OUT = 4;
1475
- var PATTERN_NON_PRINTABLE = /[\x00-\x08\x0B\x0C\x0E-\x1F\x7F-\x84\x86-\x9F\uFFFE\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]/;
1476
- var PATTERN_FLOW_INDICATORS = /[,\[\]{}]/;
1477
- var PATTERN_TAG_HANDLE = /^(?:!|!!|![0-9A-Za-z-]+!)$/;
1478
- var NS_URI_CHAR = String.raw`(?:%[0-9A-Fa-f]{2}|[0-9A-Za-z\-#;/?:@&=+$,_.!~*'()\[\]])`;
1479
- var NS_TAG_CHAR = String.raw`(?:%[0-9A-Fa-f]{2}|[0-9A-Za-z\-#;/?:@&=+$.~*'()_])`;
1480
- var PATTERN_TAG_URI = new RegExp(`^(?:${NS_URI_CHAR})*$`);
1481
- var PATTERN_TAG_SUFFIX = new RegExp(`^(?:${NS_TAG_CHAR})+$`);
1482
- var PATTERN_TAG_PREFIX = new RegExp(`^(?:!(?:${NS_URI_CHAR})*|${NS_TAG_CHAR}(?:${NS_URI_CHAR})*)$`);
1483
- var DEFAULT_PARSER_OPTIONS = {
1484
- filename: "",
1485
- maxDepth: 100
1486
- };
1487
- function addDocumentEvent(state, explicitStart, explicitEnd) {
1488
- state.events.push({
1489
- type: EVENT_ID.DOCUMENT,
1490
- explicitStart,
1491
- explicitEnd,
1492
- directives: state.directives
1493
- });
1494
- }
1495
- function addSequenceEvent(state, start, anchorStart, anchorEnd, tagStart, tagEnd, style) {
1496
- state.events.push({
1497
- type: EVENT_ID.SEQUENCE,
1498
- start,
1499
- anchorStart,
1500
- anchorEnd,
1501
- tagStart,
1502
- tagEnd,
1503
- style
1504
- });
1505
- }
1506
- function addMappingEvent(state, start, anchorStart, anchorEnd, tagStart, tagEnd, style) {
1507
- state.events.push({
1508
- type: EVENT_ID.MAPPING,
1509
- start,
1510
- anchorStart,
1511
- anchorEnd,
1512
- tagStart,
1513
- tagEnd,
1514
- style
1515
- });
1516
- }
1517
- function insertFlowPairMappingEvent(state, snapshot) {
1518
- state.events.splice(snapshot.eventsLength, 0, {
1519
- type: EVENT_ID.MAPPING,
1520
- start: snapshot.position,
1521
- anchorStart: NO_RANGE$1,
1522
- anchorEnd: NO_RANGE$1,
1523
- tagStart: NO_RANGE$1,
1524
- tagEnd: NO_RANGE$1,
1525
- style: COLLECTION_STYLE.FLOW
1526
- });
1527
- }
1528
- function addScalarEvent(state, valueStart, valueEnd, anchorStart, anchorEnd, tagStart, tagEnd, style, chomping = CHOMPING_MODE.CLIP, indent = -1, fast = false) {
1529
- state.events.push({
1530
- type: EVENT_ID.SCALAR,
1531
- valueStart,
1532
- valueEnd,
1533
- anchorStart,
1534
- anchorEnd,
1535
- tagStart,
1536
- tagEnd,
1537
- style,
1538
- chomping,
1539
- indent,
1540
- fast
1541
- });
1542
- }
1543
- function addAliasEvent(state, anchorStart, anchorEnd) {
1544
- state.events.push({
1545
- type: EVENT_ID.ALIAS,
1546
- anchorStart,
1547
- anchorEnd
1548
- });
1549
- }
1550
- function addPopEvent(state) {
1551
- state.events.push({ type: EVENT_ID.POP });
1552
- }
1553
- function addEmptyScalarEvent(state) {
1554
- addScalarEvent(state, NO_RANGE$1, NO_RANGE$1, NO_RANGE$1, NO_RANGE$1, NO_RANGE$1, NO_RANGE$1, SCALAR_STYLE.PLAIN);
1555
- }
1556
- function emptyProperties() {
1557
- return {
1558
- anchorStart: NO_RANGE$1,
1559
- anchorEnd: NO_RANGE$1,
1560
- tagStart: NO_RANGE$1,
1561
- tagEnd: NO_RANGE$1
1562
- };
1563
- }
1564
- function snapshotState(state) {
1565
- return {
1566
- position: state.position,
1567
- line: state.line,
1568
- lineStart: state.lineStart,
1569
- lineIndent: state.lineIndent,
1570
- firstTabInLine: state.firstTabInLine,
1571
- eventsLength: state.events.length
1572
- };
1573
- }
1574
- function restoreState(state, snapshot) {
1575
- state.position = snapshot.position;
1576
- state.line = snapshot.line;
1577
- state.lineStart = snapshot.lineStart;
1578
- state.lineIndent = snapshot.lineIndent;
1579
- state.firstTabInLine = snapshot.firstTabInLine;
1580
- state.events.length = snapshot.eventsLength;
1581
- }
1582
- function throwError(state, message) {
1583
- YAMLException.throwAt(state.input.slice(0, state.length), state.position, message, state.filename);
1584
- }
1585
- function isEol(c) {
1586
- return c === 10 || c === 13;
1587
- }
1588
- function isWhiteSpace(c) {
1589
- return c === 9 || c === 32;
1590
- }
1591
- function isWsOrEol(c) {
1592
- return isWhiteSpace(c) || isEol(c);
1593
- }
1594
- function isWsOrEolOrEnd(c) {
1595
- return c === 0 || isWsOrEol(c);
1596
- }
1597
- function isFlowIndicator(c) {
1598
- return c === 44 || c === 91 || c === 93 || c === 123 || c === 125;
1599
- }
1600
- function fromDecimalCode(c) {
1601
- return c >= 48 && c <= 57 ? c - 48 : -1;
1602
- }
1603
- function fromHexCode(c) {
1604
- if (c >= 48 && c <= 57) return c - 48;
1605
- const lc = c | 32;
1606
- if (lc >= 97 && lc <= 102) return lc - 97 + 10;
1607
- return -1;
1608
- }
1609
- function escapedHexLen(c) {
1610
- if (c === 120) return 2;
1611
- if (c === 117) return 4;
1612
- if (c === 85) return 8;
1613
- return 0;
1614
- }
1615
- function isSimpleEscape(c) {
1616
- 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;
1617
- }
1618
- function consumeLineBreak(state) {
1619
- if (state.input.charCodeAt(state.position) === 10) state.position++;
1620
- else {
1621
- state.position++;
1622
- if (state.input.charCodeAt(state.position) === 10) state.position++;
1623
- }
1624
- state.line++;
1625
- state.lineStart = state.position;
1626
- state.lineIndent = 0;
1627
- state.firstTabInLine = -1;
1628
- }
1629
- function skipSeparationSpace(state, allowComments) {
1630
- let lineBreaks = 0;
1631
- let ch = state.input.charCodeAt(state.position);
1632
- let hasSeparation = state.position === state.lineStart || isWsOrEol(state.input.charCodeAt(state.position - 1));
1633
- while (ch !== 0) {
1634
- while (isWhiteSpace(ch)) {
1635
- hasSeparation = true;
1636
- if (ch === 9 && state.firstTabInLine === -1) state.firstTabInLine = state.position;
1637
- ch = state.input.charCodeAt(++state.position);
1638
- }
1639
- if (allowComments && hasSeparation && ch === 35) do
1640
- ch = state.input.charCodeAt(++state.position);
1641
- while (!isEol(ch) && ch !== 0);
1642
- if (!isEol(ch)) break;
1643
- consumeLineBreak(state);
1644
- lineBreaks++;
1645
- hasSeparation = true;
1646
- ch = state.input.charCodeAt(state.position);
1647
- while (ch === 32) {
1648
- state.lineIndent++;
1649
- ch = state.input.charCodeAt(++state.position);
1650
- }
1651
- }
1652
- return lineBreaks;
1653
- }
1654
- function testDocumentSeparator(state, position = state.position) {
1655
- const ch = state.input.charCodeAt(position);
1656
- if ((ch === 45 || ch === 46) && ch === state.input.charCodeAt(position + 1) && ch === state.input.charCodeAt(position + 2)) {
1657
- const following = state.input.charCodeAt(position + 3);
1658
- return following === 0 || isWsOrEol(following);
1659
- }
1660
- return false;
1661
- }
1662
- function skipByteOrderMark(state) {
1663
- if (state.position === state.lineStart && state.input.charCodeAt(state.position) === 65279) {
1664
- state.position++;
1665
- state.lineStart = state.position;
1666
- }
1667
- }
1668
- function testDocumentBoundary(state) {
1669
- if (state.position !== state.lineStart) return false;
1670
- if (testDocumentSeparator(state)) return true;
1671
- if (state.input.charCodeAt(state.position) !== 65279) return false;
1672
- const snapshot = snapshotState(state);
1673
- skipByteOrderMark(state);
1674
- skipSeparationSpace(state, true);
1675
- const ch = state.input.charCodeAt(state.position);
1676
- const result = state.position === state.lineStart && (ch === 37 || ch === 45 && testDocumentSeparator(state));
1677
- restoreState(state, snapshot);
1678
- return result;
1679
- }
1680
- function skipUntilLineEnd(state) {
1681
- let ch = state.input.charCodeAt(state.position);
1682
- while (ch !== 0 && !isEol(ch)) ch = state.input.charCodeAt(++state.position);
1683
- }
1684
- function checkPrintable(state, start, end) {
1685
- if (PATTERN_NON_PRINTABLE.test(state.input.slice(start, end))) throwError(state, "the stream contains non-printable characters");
1686
- }
1687
- function readTagProperty(state, props, inFlow) {
1688
- if (state.input.charCodeAt(state.position) !== 33) return false;
1689
- if (props.tagStart !== NO_RANGE$1) throwError(state, "duplication of a tag property");
1690
- const start = state.position;
1691
- let isVerbatim = false;
1692
- let isNamed = false;
1693
- let tagHandle = "!";
1694
- let ch = state.input.charCodeAt(++state.position);
1695
- if (ch === 60) {
1696
- isVerbatim = true;
1697
- ch = state.input.charCodeAt(++state.position);
1698
- } else if (ch === 33) {
1699
- isNamed = true;
1700
- tagHandle = "!!";
1701
- ch = state.input.charCodeAt(++state.position);
1702
- }
1703
- let suffixStart = state.position;
1704
- let tagName;
1705
- if (isVerbatim) {
1706
- while (ch !== 0 && ch !== 62) ch = state.input.charCodeAt(++state.position);
1707
- if (ch !== 62) throwError(state, "unexpected end of the stream within a verbatim tag");
1708
- tagName = state.input.slice(suffixStart, state.position);
1709
- state.position++;
1710
- } else {
1711
- while (ch !== 0 && !isWsOrEol(ch) && !(inFlow && isFlowIndicator(ch))) {
1712
- if (ch === 33) if (!isNamed) {
1713
- tagHandle = state.input.slice(suffixStart - 1, state.position + 1);
1714
- if (!PATTERN_TAG_HANDLE.test(tagHandle)) throwError(state, "named tag handle cannot contain such characters");
1715
- isNamed = true;
1716
- suffixStart = state.position + 1;
1717
- } else throwError(state, "tag suffix cannot contain exclamation marks");
1718
- ch = state.input.charCodeAt(++state.position);
1719
- }
1720
- tagName = state.input.slice(suffixStart, state.position);
1721
- if (PATTERN_FLOW_INDICATORS.test(tagName)) throwError(state, "tag suffix cannot contain flow indicator characters");
1722
- }
1723
- if (tagName && !(isVerbatim ? PATTERN_TAG_URI.test(tagName) : PATTERN_TAG_SUFFIX.test(tagName))) throwError(state, `tag name cannot contain such characters: ${tagName}`);
1724
- if (!isVerbatim && tagHandle !== "!" && tagHandle !== "!!" && !HAS_OWN.call(state.tagHandlers, tagHandle)) throwError(state, `undeclared tag handle "${tagHandle}"`);
1725
- props.tagStart = start;
1726
- props.tagEnd = state.position;
1727
- return true;
1728
- }
1729
- function readAnchorProperty(state, props) {
1730
- if (state.input.charCodeAt(state.position) !== 38) return false;
1731
- if (props.anchorStart !== NO_RANGE$1) throwError(state, "duplication of an anchor property");
1732
- state.position++;
1733
- const start = state.position;
1734
- while (state.input.charCodeAt(state.position) !== 0 && !isWsOrEol(state.input.charCodeAt(state.position)) && !isFlowIndicator(state.input.charCodeAt(state.position))) state.position++;
1735
- if (state.position === start) throwError(state, "name of an anchor node must contain at least one character");
1736
- props.anchorStart = start;
1737
- props.anchorEnd = state.position;
1738
- return true;
1739
- }
1740
- function readAlias(state, props) {
1741
- if (state.input.charCodeAt(state.position) !== 42) return false;
1742
- if (props.anchorStart !== NO_RANGE$1 || props.tagStart !== NO_RANGE$1) throwError(state, "alias node should not have any properties");
1743
- state.position++;
1744
- const start = state.position;
1745
- while (state.input.charCodeAt(state.position) !== 0 && !isWsOrEol(state.input.charCodeAt(state.position)) && !isFlowIndicator(state.input.charCodeAt(state.position))) state.position++;
1746
- if (state.position === start) throwError(state, "name of an alias node must contain at least one character");
1747
- addAliasEvent(state, start, state.position);
1748
- return true;
1749
- }
1750
- function readFlowScalarBreak(state, nodeIndent) {
1751
- skipSeparationSpace(state, false);
1752
- if (state.lineIndent < nodeIndent) throwError(state, "deficient indentation");
1753
- }
1754
- function readSingleQuotedScalar(state, nodeIndent, props) {
1755
- if (state.input.charCodeAt(state.position) !== 39) return false;
1756
- state.position++;
1757
- const start = state.position;
1758
- let simple = true;
1759
- while (state.input.charCodeAt(state.position) !== 0) {
1760
- const ch = state.input.charCodeAt(state.position);
1761
- if (ch === 39) {
1762
- if (state.input.charCodeAt(state.position + 1) === 39) {
1763
- simple = false;
1764
- state.position += 2;
1765
- continue;
1766
- }
1767
- const end = state.position;
1768
- state.position++;
1769
- addScalarEvent(state, start, end, props.anchorStart, props.anchorEnd, props.tagStart, props.tagEnd, SCALAR_STYLE.SINGLE_QUOTED, CHOMPING_MODE.CLIP, -1, simple);
1770
- return true;
1771
- }
1772
- if (isEol(ch)) {
1773
- simple = false;
1774
- readFlowScalarBreak(state, nodeIndent);
1775
- } else if (state.position === state.lineStart && testDocumentSeparator(state)) throwError(state, "unexpected end of the document within a single quoted scalar");
1776
- else if (ch !== 9 && ch < 32) throwError(state, "expected valid JSON character");
1777
- else state.position++;
1778
- }
1779
- throwError(state, "unexpected end of the stream within a single quoted scalar");
1780
- }
1781
- function readDoubleQuotedScalar(state, nodeIndent, props) {
1782
- if (state.input.charCodeAt(state.position) !== 34) return false;
1783
- state.position++;
1784
- const start = state.position;
1785
- let simple = true;
1786
- while (state.input.charCodeAt(state.position) !== 0) {
1787
- const ch = state.input.charCodeAt(state.position);
1788
- if (ch === 34) {
1789
- const end = state.position;
1790
- state.position++;
1791
- addScalarEvent(state, start, end, props.anchorStart, props.anchorEnd, props.tagStart, props.tagEnd, SCALAR_STYLE.DOUBLE_QUOTED, CHOMPING_MODE.CLIP, -1, simple);
1792
- return true;
1793
- }
1794
- if (ch === 92) {
1795
- simple = false;
1796
- const escaped = state.input.charCodeAt(++state.position);
1797
- if (isEol(escaped)) readFlowScalarBreak(state, nodeIndent);
1798
- else if (isSimpleEscape(escaped)) state.position++;
1799
- else {
1800
- let hexLength = escapedHexLen(escaped);
1801
- if (hexLength === 0) throwError(state, "unknown escape sequence");
1802
- while (hexLength-- > 0) {
1803
- state.position++;
1804
- if (fromHexCode(state.input.charCodeAt(state.position)) < 0) throwError(state, "expected hexadecimal character");
1805
- }
1806
- state.position++;
1807
- }
1808
- } else if (isEol(ch)) {
1809
- simple = false;
1810
- readFlowScalarBreak(state, nodeIndent);
1811
- } else if (state.position === state.lineStart && testDocumentSeparator(state)) throwError(state, "unexpected end of the document within a double quoted scalar");
1812
- else if (ch !== 9 && ch < 32) throwError(state, "expected valid JSON character");
1813
- else state.position++;
1814
- }
1815
- throwError(state, "unexpected end of the stream within a double quoted scalar");
1816
- }
1817
- function readBlockScalar(state, parentIndent, props) {
1818
- const ch = state.input.charCodeAt(state.position);
1819
- let chomping = CHOMPING_MODE.CLIP;
1820
- let indent = -1;
1821
- let detectedIndent = false;
1822
- if (ch !== 124 && ch !== 62) return false;
1823
- const style = ch === 124 ? SCALAR_STYLE.LITERAL_BLOCK : SCALAR_STYLE.FOLDED_BLOCK;
1824
- state.position++;
1825
- while (state.input.charCodeAt(state.position) !== 0) {
1826
- const current = state.input.charCodeAt(state.position);
1827
- const digit = fromDecimalCode(current);
1828
- if (current === 43 || current === 45) {
1829
- if (chomping !== CHOMPING_MODE.CLIP) throwError(state, "repeat of a chomping mode identifier");
1830
- chomping = current === 43 ? CHOMPING_MODE.KEEP : CHOMPING_MODE.STRIP;
1831
- state.position++;
1832
- } else if (digit >= 0) {
1833
- if (digit === 0) throwError(state, "bad explicit indentation width of a block scalar; it cannot be less than one");
1834
- if (detectedIndent) throwError(state, "repeat of an indentation width identifier");
1835
- indent = parentIndent + digit - 1;
1836
- detectedIndent = true;
1837
- state.position++;
1838
- } else break;
1839
- }
1840
- let hadWhitespace = false;
1841
- while (isWhiteSpace(state.input.charCodeAt(state.position))) {
1842
- hadWhitespace = true;
1843
- state.position++;
1844
- }
1845
- if (hadWhitespace && state.input.charCodeAt(state.position) === 35) skipUntilLineEnd(state);
1846
- if (isEol(state.input.charCodeAt(state.position))) consumeLineBreak(state);
1847
- else if (state.input.charCodeAt(state.position) !== 0) throwError(state, "a line break is expected");
1848
- let contentIndent = detectedIndent ? indent : -1;
1849
- let maxLeadingIndent = 0;
1850
- const valueStart = state.position;
1851
- let valueEnd = state.position;
1852
- while (state.input.charCodeAt(state.position) !== 0) {
1853
- const linePosition = state.position;
1854
- let column = 0;
1855
- while (state.input.charCodeAt(linePosition + column) === 32) column++;
1856
- const first = state.input.charCodeAt(linePosition + column);
1857
- if (first === 0) {
1858
- if (contentIndent >= 0) {
1859
- if (column > contentIndent) valueEnd = linePosition + column;
1860
- } else if (column > 0) valueEnd = linePosition + column;
1861
- break;
1862
- }
1863
- if (testDocumentBoundary(state)) break;
1864
- if (!detectedIndent && contentIndent === -1 && isEol(first)) maxLeadingIndent = Math.max(maxLeadingIndent, column);
1865
- if (!detectedIndent && contentIndent === -1 && !isEol(first)) {
1866
- if (first === 9 && column < parentIndent) {
1867
- state.position = linePosition + column;
1868
- throwError(state, "tab characters must not be used in indentation");
1869
- }
1870
- if (column < maxLeadingIndent) {
1871
- state.position = linePosition + column;
1872
- throwError(state, "bad indentation of a mapping entry");
1873
- }
1874
- }
1875
- if (contentIndent === -1 && first !== 0 && !isEol(first) && column < parentIndent) {
1876
- state.lineIndent = column;
1877
- state.position = linePosition + column;
1878
- break;
1879
- }
1880
- if (!detectedIndent && first !== 0 && !isEol(first) && contentIndent === -1) contentIndent = column;
1881
- const requiredIndent = contentIndent === -1 ? parentIndent + 1 : contentIndent;
1882
- if (first !== 0 && !isEol(first) && column < requiredIndent) {
1883
- state.lineIndent = column;
1884
- state.position = linePosition + column;
1885
- break;
1886
- }
1887
- skipUntilLineEnd(state);
1888
- valueEnd = state.position;
1889
- if (isEol(state.input.charCodeAt(state.position))) {
1890
- consumeLineBreak(state);
1891
- valueEnd = state.position;
1892
- }
1893
- }
1894
- checkPrintable(state, valueStart, valueEnd);
1895
- addScalarEvent(state, valueStart, valueEnd, props.anchorStart, props.anchorEnd, props.tagStart, props.tagEnd, style, chomping, contentIndent);
1896
- return true;
1897
- }
1898
- function canStartPlainScalar(state, nodeContext) {
1899
- const ch = state.input.charCodeAt(state.position);
1900
- const inFlow = nodeContext === CONTEXT_FLOW_IN;
1901
- 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)) return false;
1902
- if (ch === 63 || ch === 45) {
1903
- const following = state.input.charCodeAt(state.position + 1);
1904
- if (isWsOrEolOrEnd(following) || inFlow && isFlowIndicator(following)) return false;
1905
- }
1906
- return true;
1907
- }
1908
- function readPlainScalar(state, nodeIndent, nodeContext, props) {
1909
- if (!canStartPlainScalar(state, nodeContext)) return false;
1910
- const start = state.position;
1911
- let end = state.position;
1912
- let ch = state.input.charCodeAt(state.position);
1913
- const inFlow = nodeContext === CONTEXT_FLOW_IN;
1914
- let multiline = false;
1915
- while (ch !== 0) {
1916
- if (testDocumentBoundary(state)) break;
1917
- if (ch === 58) {
1918
- const following = state.input.charCodeAt(state.position + 1);
1919
- if (isWsOrEolOrEnd(following) || inFlow && isFlowIndicator(following)) break;
1920
- } else if (ch === 35) {
1921
- if (isWsOrEol(state.input.charCodeAt(state.position - 1))) break;
1922
- } else if (inFlow && isFlowIndicator(ch)) break;
1923
- else if (isEol(ch)) {
1924
- const savedPosition = state.position;
1925
- const savedLine = state.line;
1926
- const savedLineStart = state.lineStart;
1927
- const savedLineIndent = state.lineIndent;
1928
- skipSeparationSpace(state, false);
1929
- if (state.lineIndent >= nodeIndent) {
1930
- multiline = true;
1931
- ch = state.input.charCodeAt(state.position);
1932
- continue;
1933
- }
1934
- state.position = savedPosition;
1935
- state.line = savedLine;
1936
- state.lineStart = savedLineStart;
1937
- state.lineIndent = savedLineIndent;
1938
- break;
1939
- }
1940
- if (!isWhiteSpace(ch)) end = state.position + 1;
1941
- ch = state.input.charCodeAt(++state.position);
1942
- }
1943
- if (end === start) return false;
1944
- checkPrintable(state, start, end);
1945
- addScalarEvent(state, start, end, props.anchorStart, props.anchorEnd, props.tagStart, props.tagEnd, SCALAR_STYLE.PLAIN, CHOMPING_MODE.CLIP, -1, !multiline);
1946
- return true;
1947
- }
1948
- function skipFlowSeparationSpace(state, nodeIndent) {
1949
- const startLine = state.line;
1950
- skipSeparationSpace(state, true);
1951
- if (state.line > startLine && state.lineIndent < nodeIndent || state.firstTabInLine !== -1 && state.lineIndent < nodeIndent) throwError(state, "deficient indentation");
1952
- }
1953
- function readFlowCollection(state, nodeIndent, props) {
1954
- const ch = state.input.charCodeAt(state.position);
1955
- const isMapping = ch === 123;
1956
- const start = state.position;
1957
- let readNext = true;
1958
- if (ch !== 91 && ch !== 123) return false;
1959
- const terminator = isMapping ? 125 : 93;
1960
- if (isMapping) addMappingEvent(state, start, props.anchorStart, props.anchorEnd, props.tagStart, props.tagEnd, COLLECTION_STYLE.FLOW);
1961
- else addSequenceEvent(state, start, props.anchorStart, props.anchorEnd, props.tagStart, props.tagEnd, COLLECTION_STYLE.FLOW);
1962
- state.position++;
1963
- while (state.input.charCodeAt(state.position) !== 0) {
1964
- skipFlowSeparationSpace(state, nodeIndent);
1965
- let ch2 = state.input.charCodeAt(state.position);
1966
- if (ch2 === terminator) {
1967
- state.position++;
1968
- addPopEvent(state);
1969
- return true;
1970
- } else if (!readNext) throwError(state, "missed comma between flow collection entries");
1971
- else if (ch2 === 44) throwError(state, "expected the node content, but found ','");
1972
- let isPair = false;
1973
- let isExplicitPair = false;
1974
- if (ch2 === 63 && isWsOrEol(state.input.charCodeAt(state.position + 1))) {
1975
- isPair = isExplicitPair = true;
1976
- state.position += 1;
1977
- skipFlowSeparationSpace(state, nodeIndent);
1978
- }
1979
- const entryLine = state.line;
1980
- const entryStart = snapshotState(state);
1981
- const keyWasRead = parseNode(state, nodeIndent, CONTEXT_FLOW_IN, false, true);
1982
- skipFlowSeparationSpace(state, nodeIndent);
1983
- ch2 = state.input.charCodeAt(state.position);
1984
- if ((isMapping || isExplicitPair || state.line === entryLine) && ch2 === 58) {
1985
- isPair = true;
1986
- state.position++;
1987
- skipFlowSeparationSpace(state, nodeIndent);
1988
- if (!isMapping) {
1989
- insertFlowPairMappingEvent(state, entryStart);
1990
- if (!keyWasRead) addEmptyScalarEvent(state);
1991
- } else if (!keyWasRead) addEmptyScalarEvent(state);
1992
- if (!parseNode(state, nodeIndent, CONTEXT_FLOW_IN, false, true)) addEmptyScalarEvent(state);
1993
- skipFlowSeparationSpace(state, nodeIndent);
1994
- if (!isMapping) addPopEvent(state);
1995
- } else if (isMapping && isPair) {
1996
- if (!keyWasRead) addEmptyScalarEvent(state);
1997
- addEmptyScalarEvent(state);
1998
- } else if (isMapping) addEmptyScalarEvent(state);
1999
- else if (isPair) {
2000
- insertFlowPairMappingEvent(state, entryStart);
2001
- if (!keyWasRead) addEmptyScalarEvent(state);
2002
- addEmptyScalarEvent(state);
2003
- addPopEvent(state);
2004
- }
2005
- ch2 = state.input.charCodeAt(state.position);
2006
- if (ch2 === 44) {
2007
- readNext = true;
2008
- state.position++;
2009
- } else readNext = false;
2010
- }
2011
- throwError(state, "unexpected end of the stream within a flow collection");
2012
- }
2013
- function readBlockSequence(state, nodeIndent, props) {
2014
- if (state.firstTabInLine !== -1 || state.input.charCodeAt(state.position) !== 45 || !isWsOrEolOrEnd(state.input.charCodeAt(state.position + 1))) return false;
2015
- addSequenceEvent(state, state.position, props.anchorStart, props.anchorEnd, props.tagStart, props.tagEnd, COLLECTION_STYLE.BLOCK);
2016
- while (state.input.charCodeAt(state.position) === 45 && isWsOrEolOrEnd(state.input.charCodeAt(state.position + 1))) {
2017
- if (state.firstTabInLine !== -1) {
2018
- state.position = state.firstTabInLine;
2019
- throwError(state, "tab characters must not be used in indentation");
2020
- }
2021
- const entryLine = state.line;
2022
- state.position++;
2023
- const hadBreak = skipSeparationSpace(state, true) > 0;
2024
- if (state.firstTabInLine !== -1 && state.input.charCodeAt(state.position) === 45 && isWsOrEolOrEnd(state.input.charCodeAt(state.position + 1))) throwError(state, "bad indentation of a sequence entry");
2025
- if (hadBreak && state.lineIndent <= nodeIndent) addEmptyScalarEvent(state);
2026
- else parseNode(state, nodeIndent, CONTEXT_BLOCK_IN, false, true);
2027
- skipSeparationSpace(state, true);
2028
- if (state.lineIndent < nodeIndent || state.position >= state.length) break;
2029
- if (state.lineIndent > nodeIndent) throwError(state, "bad indentation of a sequence entry");
2030
- if (state.line === entryLine && state.input.charCodeAt(state.position) === 45 && isWsOrEolOrEnd(state.input.charCodeAt(state.position + 1))) throwError(state, "bad indentation of a sequence entry");
2031
- }
2032
- addPopEvent(state);
2033
- return true;
2034
- }
2035
- function readBlockMapping(state, nodeIndent, flowIndent, props) {
2036
- let atExplicitKey = false;
2037
- let detected = false;
2038
- let mappingOpened = false;
2039
- let pendingExplicitKey = false;
2040
- if (state.firstTabInLine !== -1) return false;
2041
- let ch = state.input.charCodeAt(state.position);
2042
- while (ch !== 0) {
2043
- if (!atExplicitKey && state.firstTabInLine !== -1) {
2044
- state.position = state.firstTabInLine;
2045
- throwError(state, "tab characters must not be used in indentation");
2046
- }
2047
- const following = state.input.charCodeAt(state.position + 1);
2048
- const entryLine = state.line;
2049
- if ((ch === 63 || ch === 58) && isWsOrEolOrEnd(following)) {
2050
- if (!mappingOpened) {
2051
- addMappingEvent(state, state.position, props.anchorStart, props.anchorEnd, props.tagStart, props.tagEnd, COLLECTION_STYLE.BLOCK);
2052
- mappingOpened = true;
2053
- }
2054
- if (ch === 63) {
2055
- if (atExplicitKey) addEmptyScalarEvent(state);
2056
- detected = true;
2057
- atExplicitKey = true;
2058
- } else if (atExplicitKey) atExplicitKey = false;
2059
- else {
2060
- addEmptyScalarEvent(state);
2061
- detected = true;
2062
- atExplicitKey = false;
2063
- }
2064
- state.position += 1;
2065
- pendingExplicitKey = true;
2066
- } else {
2067
- if (atExplicitKey) {
2068
- addEmptyScalarEvent(state);
2069
- atExplicitKey = false;
2070
- }
2071
- const beforeKey = snapshotState(state);
2072
- if (!parseNode(state, flowIndent, CONTEXT_FLOW_OUT, false, true)) break;
2073
- if (state.line === entryLine) {
2074
- ch = state.input.charCodeAt(state.position);
2075
- while (isWhiteSpace(ch)) ch = state.input.charCodeAt(++state.position);
2076
- if (ch === 58) {
2077
- ch = state.input.charCodeAt(++state.position);
2078
- if (!isWsOrEolOrEnd(ch)) throwError(state, "a whitespace character is expected after the key-value separator within a block mapping");
2079
- if (!mappingOpened) {
2080
- restoreState(state, beforeKey);
2081
- addMappingEvent(state, beforeKey.position, props.anchorStart, props.anchorEnd, props.tagStart, props.tagEnd, COLLECTION_STYLE.BLOCK);
2082
- mappingOpened = true;
2083
- parseNode(state, flowIndent, CONTEXT_FLOW_OUT, false, true);
2084
- ch = state.input.charCodeAt(state.position);
2085
- while (isWhiteSpace(ch)) ch = state.input.charCodeAt(++state.position);
2086
- state.position++;
2087
- }
2088
- detected = true;
2089
- atExplicitKey = false;
2090
- pendingExplicitKey = false;
2091
- } else if (detected) throwError(state, "expected ':' after a mapping key");
2092
- else {
2093
- if (props.anchorStart !== NO_RANGE$1 || props.tagStart !== NO_RANGE$1) {
2094
- restoreState(state, beforeKey);
2095
- return false;
2096
- }
2097
- return true;
2098
- }
2099
- } else if (detected) throwError(state, "can not read a block mapping entry; a multiline key may not be an implicit key");
2100
- else {
2101
- if (props.anchorStart !== NO_RANGE$1 || props.tagStart !== NO_RANGE$1) {
2102
- restoreState(state, beforeKey);
2103
- return false;
2104
- }
2105
- return true;
2106
- }
2107
- }
2108
- if (parseNode(state, nodeIndent, CONTEXT_BLOCK_OUT, true, pendingExplicitKey)) pendingExplicitKey = false;
2109
- if (!atExplicitKey) {
2110
- if (pendingExplicitKey) {
2111
- addEmptyScalarEvent(state);
2112
- pendingExplicitKey = false;
2113
- }
2114
- }
2115
- skipSeparationSpace(state, true);
2116
- ch = state.input.charCodeAt(state.position);
2117
- if ((state.line === entryLine || state.lineIndent > nodeIndent) && ch !== 0) throwError(state, "bad indentation of a mapping entry");
2118
- else if (state.lineIndent < nodeIndent) break;
2119
- }
2120
- if (!detected) return false;
2121
- if (atExplicitKey) addEmptyScalarEvent(state);
2122
- if (mappingOpened) addPopEvent(state);
2123
- return true;
2124
- }
2125
- function parseNode(state, parentIndent, nodeContext, allowToSeek, allowCompact, allowPropertyMapping = true) {
2126
- if (state.depth >= state.maxDepth) throwError(state, `nesting exceeded maxDepth (${state.maxDepth})`);
2127
- state.depth++;
2128
- let indentStatus = 1;
2129
- let atNewLine = false;
2130
- let hasContent = false;
2131
- let propertyStart = null;
2132
- const props = emptyProperties();
2133
- let allowBlockScalars = nodeContext === CONTEXT_BLOCK_OUT || nodeContext === CONTEXT_BLOCK_IN;
2134
- let allowBlockCollections = allowBlockScalars;
2135
- const allowBlockStyles = allowBlockScalars;
2136
- if (allowToSeek && skipSeparationSpace(state, true)) {
2137
- atNewLine = true;
2138
- if (state.lineIndent > parentIndent) indentStatus = 1;
2139
- else if (state.lineIndent === parentIndent) indentStatus = 0;
2140
- else indentStatus = -1;
2141
- }
2142
- if (indentStatus === 1) while (true) {
2143
- const ch = state.input.charCodeAt(state.position);
2144
- const propertyState = snapshotState(state);
2145
- if (atNewLine && indentStatus !== 1 && (ch === 33 || ch === 38)) break;
2146
- if (atNewLine && allowBlockStyles && (props.tagStart !== NO_RANGE$1 || props.anchorStart !== NO_RANGE$1) && (ch === 33 || ch === 38)) {
2147
- const fallbackState = snapshotState(state);
2148
- const flowIndent = parentIndent + 1;
2149
- if (readBlockMapping(state, state.position - state.lineStart, flowIndent, props) && state.events[fallbackState.eventsLength]?.type === EVENT_ID.MAPPING) {
2150
- state.depth--;
2151
- return true;
2152
- }
2153
- restoreState(state, fallbackState);
2154
- }
2155
- if (atNewLine && (ch === 33 && props.tagStart !== NO_RANGE$1 || ch === 38 && props.anchorStart !== NO_RANGE$1)) break;
2156
- if (!readTagProperty(state, props, nodeContext === CONTEXT_FLOW_IN) && !readAnchorProperty(state, props)) break;
2157
- if (propertyStart === null) propertyStart = propertyState;
2158
- if (skipSeparationSpace(state, true)) {
2159
- atNewLine = true;
2160
- allowBlockCollections = allowBlockStyles;
2161
- if (state.lineIndent > parentIndent) indentStatus = 1;
2162
- else if (state.lineIndent === parentIndent) indentStatus = 0;
2163
- else indentStatus = -1;
2164
- } else allowBlockCollections = false;
2165
- }
2166
- if (allowBlockCollections) allowBlockCollections = atNewLine || allowCompact;
2167
- if (indentStatus === 1 || nodeContext === CONTEXT_BLOCK_OUT) {
2168
- const flowIndent = nodeContext === CONTEXT_FLOW_IN || nodeContext === CONTEXT_FLOW_OUT ? parentIndent : parentIndent + 1;
2169
- const blockIndent = state.position - state.lineStart;
2170
- if (indentStatus === 1) if (allowBlockCollections && (readBlockSequence(state, blockIndent, props) || readBlockMapping(state, blockIndent, flowIndent, props)) || readFlowCollection(state, flowIndent, props)) hasContent = true;
2171
- else {
2172
- const ch = state.input.charCodeAt(state.position);
2173
- if (propertyStart !== null && allowPropertyMapping && allowBlockStyles && !allowBlockCollections && ch !== 124 && ch !== 62) {
2174
- const fallbackState = snapshotState(state);
2175
- const propertyIndent = propertyStart.position - propertyStart.lineStart;
2176
- restoreState(state, propertyStart);
2177
- if (readBlockMapping(state, propertyIndent, flowIndent, emptyProperties()) && state.events[fallbackState.eventsLength]?.type === EVENT_ID.MAPPING) hasContent = true;
2178
- else restoreState(state, fallbackState);
2179
- }
2180
- if (!hasContent && (allowBlockScalars && readBlockScalar(state, flowIndent, props) || readSingleQuotedScalar(state, flowIndent, props) || readDoubleQuotedScalar(state, flowIndent, props) || readAlias(state, props) || readPlainScalar(state, flowIndent, nodeContext, props))) hasContent = true;
2181
- }
2182
- else if (indentStatus === 0) hasContent = allowBlockCollections && readBlockSequence(state, blockIndent, props);
2183
- }
2184
- allowBlockScalars = allowBlockScalars && !hasContent;
2185
- if (!hasContent && (props.anchorStart !== NO_RANGE$1 || props.tagStart !== NO_RANGE$1 || allowBlockScalars)) {
2186
- addScalarEvent(state, NO_RANGE$1, NO_RANGE$1, props.anchorStart, props.anchorEnd, props.tagStart, props.tagEnd, SCALAR_STYLE.PLAIN);
2187
- hasContent = true;
2188
- }
2189
- state.depth--;
2190
- return hasContent || props.anchorStart !== NO_RANGE$1 || props.tagStart !== NO_RANGE$1;
2191
- }
2192
- function readDirective(state) {
2193
- if (state.lineIndent > 0 || state.input.charCodeAt(state.position) !== 37) return false;
2194
- state.position++;
2195
- const nameStart = state.position;
2196
- while (state.input.charCodeAt(state.position) !== 0 && !isWsOrEol(state.input.charCodeAt(state.position))) state.position++;
2197
- const name = state.input.slice(nameStart, state.position);
2198
- const args = [];
2199
- if (name.length === 0) throwError(state, "directive name must not be less than one character in length");
2200
- while (state.input.charCodeAt(state.position) !== 0 && !isEol(state.input.charCodeAt(state.position))) {
2201
- while (isWhiteSpace(state.input.charCodeAt(state.position))) state.position++;
2202
- if (state.input.charCodeAt(state.position) === 35 || isEol(state.input.charCodeAt(state.position)) || state.input.charCodeAt(state.position) === 0) break;
2203
- const start = state.position;
2204
- while (state.input.charCodeAt(state.position) !== 0 && !isWsOrEol(state.input.charCodeAt(state.position))) state.position++;
2205
- args.push(state.input.slice(start, state.position));
2206
- }
2207
- if (isEol(state.input.charCodeAt(state.position))) consumeLineBreak(state);
2208
- if (name === "YAML") {
2209
- if (state.directives.some((directive) => directive.kind === "yaml")) throwError(state, "duplication of %YAML directive");
2210
- if (args.length !== 1) throwError(state, "YAML directive accepts exactly one argument");
2211
- const match = /^([0-9]+)\.([0-9]+)$/.exec(args[0]);
2212
- if (match === null) throwError(state, "ill-formed argument of the YAML directive");
2213
- if (parseInt(match[1], 10) !== 1) throwError(state, "unacceptable YAML version of the document");
2214
- state.directives.push({
2215
- kind: "yaml",
2216
- version: args[0]
2217
- });
2218
- } else if (name === "TAG") {
2219
- if (args.length !== 2) throwError(state, "TAG directive accepts exactly two arguments");
2220
- const [handle, prefix] = args;
2221
- if (!PATTERN_TAG_HANDLE.test(handle)) throwError(state, "ill-formed tag handle (first argument) of the TAG directive");
2222
- if (HAS_OWN.call(state.tagHandlers, handle)) throwError(state, `there is a previously declared suffix for "${handle}" tag handle`);
2223
- if (!PATTERN_TAG_PREFIX.test(prefix)) throwError(state, "ill-formed tag prefix (second argument) of the TAG directive");
2224
- state.tagHandlers[handle] = prefix;
2225
- state.directives.push({
2226
- kind: "tag",
2227
- handle,
2228
- prefix
2229
- });
2230
- }
2231
- return true;
2232
- }
2233
- function readDocument(state) {
2234
- state.directives = [];
2235
- state.tagHandlers = /* @__PURE__ */ Object.create(null);
2236
- let hasDirectives = false;
2237
- skipSeparationSpace(state, true);
2238
- while (readDirective(state)) {
2239
- hasDirectives = true;
2240
- skipSeparationSpace(state, true);
2241
- }
2242
- let explicitStart = false;
2243
- let explicitEnd = false;
2244
- let allowCompact = true;
2245
- 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))) {
2246
- explicitStart = true;
2247
- const markerLine = state.line;
2248
- state.position += 3;
2249
- skipSeparationSpace(state, true);
2250
- allowCompact = state.line > markerLine;
2251
- } else if (hasDirectives) throwError(state, "directives end mark is expected");
2252
- const documentEventIndex = state.events.length;
2253
- if (!explicitStart && state.position === state.lineStart && state.input.charCodeAt(state.position) === 46 && testDocumentSeparator(state)) {
2254
- state.position += 3;
2255
- skipSeparationSpace(state, true);
2256
- return;
2257
- }
2258
- addDocumentEvent(state, explicitStart, false);
2259
- if (!parseNode(state, state.lineIndent - 1, CONTEXT_BLOCK_OUT, false, allowCompact, allowCompact)) addEmptyScalarEvent(state);
2260
- skipSeparationSpace(state, true);
2261
- if (state.position === state.lineStart && testDocumentSeparator(state)) {
2262
- explicitEnd = state.input.charCodeAt(state.position) === 46;
2263
- if (explicitEnd) {
2264
- const markerLine = state.line;
2265
- state.position += 3;
2266
- skipSeparationSpace(state, true);
2267
- if (state.line === markerLine && state.position < state.length) throwError(state, "end of the stream or a document separator is expected");
2268
- }
2269
- }
2270
- const documentEvent = state.events[documentEventIndex];
2271
- if (documentEvent?.type === EVENT_ID.DOCUMENT) documentEvent.explicitEnd = explicitEnd;
2272
- addPopEvent(state);
2273
- if (!explicitEnd && state.position < state.length && !testDocumentBoundary(state)) throwError(state, "end of the stream or a document separator is expected");
2274
- }
2275
- function parseEvents(input, options) {
2276
- const length = input.length;
2277
- const state = {
2278
- ...DEFAULT_PARSER_OPTIONS,
2279
- ...options,
2280
- input: `${input}\0`,
2281
- length,
2282
- position: 0,
2283
- line: 0,
2284
- lineStart: 0,
2285
- lineIndent: 0,
2286
- firstTabInLine: -1,
2287
- depth: 0,
2288
- directives: [],
2289
- tagHandlers: /* @__PURE__ */ Object.create(null),
2290
- events: []
2291
- };
2292
- const nullpos = input.indexOf("\0");
2293
- if (nullpos !== -1) YAMLException.throwAt(input, nullpos, "null byte is not allowed in input", state.filename);
2294
- while (state.position < state.length) {
2295
- skipByteOrderMark(state);
2296
- skipSeparationSpace(state, true);
2297
- if (state.position >= state.length) break;
2298
- const documentStart = state.position;
2299
- readDocument(state);
2300
- if (state.position === documentStart)
2301
- throwError(state, "can not read a document");
2302
- }
2303
- return state.events;
2304
- }
2305
- var DEFAULT_LOAD_OPTIONS = {
2306
- ...DEFAULT_PARSER_OPTIONS,
2307
- ...DEFAULT_CONSTRUCTOR_OPTIONS
2308
- };
2309
- function loadDocuments(input, options = {}) {
2310
- const opts = {
2311
- ...DEFAULT_LOAD_OPTIONS,
2312
- ...options
2313
- };
2314
- const source = String(input);
2315
- const PARSER_OPT_KEYS = Object.keys(DEFAULT_PARSER_OPTIONS);
2316
- const CONSTRUCTOR_OPT_KEYS = Object.keys(DEFAULT_CONSTRUCTOR_OPTIONS);
2317
- return constructFromEvents(parseEvents(source, pick(opts, PARSER_OPT_KEYS)), {
2318
- ...pick(opts, CONSTRUCTOR_OPT_KEYS),
2319
- source
2320
- });
2321
- }
2322
- function load(input, options) {
2323
- const documents = loadDocuments(input, options);
2324
- if (documents.length === 0) throw new YAMLException("expected a document, but the input is empty");
2325
- if (documents.length === 1) return documents[0];
2326
- throw new YAMLException("expected a single document in the stream, but found more");
2327
- }
2328
- var INVALID = Symbol("INVALID");
2329
- var VISIT_BREAK = Symbol("visit:break");
2330
- var VISIT_SKIP = Symbol("visit:skip");
2331
- function hasBit(mask, bit) {
2332
- return (mask & 1 << bit) !== 0;
2333
- }
2334
- var DEFAULT_SCALAR_STYLE_RULES = {
2335
- applyQuoteFlowKeysOption,
2336
- doubleQuoteForInvisibles,
2337
- doubleQuoteWhitespaceOnly,
2338
- applyForceQuotesOption,
2339
- tryLongOrMultilineAsBlock,
2340
- quoteInvalidPlain,
2341
- fallbackToDoubleQuoted
2342
- };
2343
- function _preferredQuotedStyle(layout) {
2344
- if (layout.presenterOptions.quoteStyle === "single" && hasBit(layout.allowedStylesMask, SCALAR_STYLE.SINGLE_QUOTED)) return SCALAR_STYLE.SINGLE_QUOTED;
2345
- return SCALAR_STYLE.DOUBLE_QUOTED;
2346
- }
2347
- function applyQuoteFlowKeysOption(layout) {
2348
- if (!layout.presenterOptions.quoteFlowKeys) return;
2349
- if (!layout.isKey || !layout.flowOnly || layout.style !== SCALAR_STYLE.PLAIN) return;
2350
- layout.style = SCALAR_STYLE.DOUBLE_QUOTED;
2351
- }
2352
- function doubleQuoteForInvisibles(layout) {
2353
- if (layout.style === SCALAR_STYLE.PLAIN && /[\t\x7F-\xA0\u2028\u2029\uFEFF\uFFFE\uFFFF]/.test(layout.node.value)) layout.style = SCALAR_STYLE.DOUBLE_QUOTED;
2354
- }
2355
- function doubleQuoteWhitespaceOnly(layout) {
2356
- if (layout.style === SCALAR_STYLE.PLAIN && /^\s+$/.test(layout.node.value)) layout.style = SCALAR_STYLE.DOUBLE_QUOTED;
2357
- }
2358
- function applyForceQuotesOption(layout) {
2359
- if (!layout.presenterOptions.forceQuotes) return;
2360
- if (layout.isKey || layout.style !== SCALAR_STYLE.PLAIN) return;
2361
- if (layout.node.tag !== layout.presenterOptions.schema.defaultScalarTag.tagName) return;
2362
- layout.style = layout.node.value.includes("\n") ? SCALAR_STYLE.DOUBLE_QUOTED : _preferredQuotedStyle(layout);
2363
- }
2364
- function tryLongOrMultilineAsBlock(layout) {
2365
- if (layout.style !== SCALAR_STYLE.PLAIN || layout.isKey) return;
2366
- const value = layout.node.value;
2367
- const multiline = value.indexOf("\n") !== -1;
2368
- if (!hasBit(layout.allowedStylesMask, SCALAR_STYLE.LITERAL_BLOCK)) {
2369
- if (multiline) layout.style = SCALAR_STYLE.DOUBLE_QUOTED;
2370
- return;
2371
- }
2372
- const w = layout.presenterOptions.lineWidth;
2373
- if (w === -1) {
2374
- if (multiline) layout.style = SCALAR_STYLE.LITERAL_BLOCK;
2375
- return;
2376
- }
2377
- const availableWidth = Math.max(Math.min(w, 40), w - layout.shiftOfContent);
2378
- let position = 0;
2379
- let shouldFold = false;
2380
- while (position <= value.length) {
2381
- let lineEnd = value.length;
2382
- const nextLineBreak = value.indexOf("\n", position);
2383
- if (nextLineBreak !== -1) lineEnd = nextLineBreak;
2384
- const line = value.slice(position, lineEnd);
2385
- if (line.length > availableWidth && line[0] !== " " && / [^ \t]/.test(line)) shouldFold = true;
2386
- if (nextLineBreak === -1) break;
2387
- position = nextLineBreak + 1;
2388
- }
2389
- if (shouldFold) layout.style = SCALAR_STYLE.FOLDED_BLOCK;
2390
- else if (multiline) layout.style = SCALAR_STYLE.LITERAL_BLOCK;
2391
- }
2392
- function quoteInvalidPlain(layout) {
2393
- if (layout.style === SCALAR_STYLE.PLAIN && !hasBit(layout.allowedStylesMask, SCALAR_STYLE.PLAIN)) layout.style = _preferredQuotedStyle(layout);
2394
- }
2395
- function fallbackToDoubleQuoted(layout) {
2396
- if (!hasBit(layout.allowedStylesMask, layout.style)) layout.style = SCALAR_STYLE.DOUBLE_QUOTED;
2397
- }
2398
- var SRC_C_PRINTABLE = "[\\x09\\x0A\\x0D\\x20-\\x7E\\x85\\xA0-\\uD7FF\\uE000-\\uFFFD\\u{10000}-\\u{10FFFF}]";
2399
- var SRC_B_CHAR = "[\\n\\r]";
2400
- var SRC_C_BYTE_ORDER_MARK = "\\uFEFF";
2401
- var SRC_S_WHITE = "[ \\t]";
2402
- var SRC_NB_CHAR = `(?:(?!(?:${SRC_B_CHAR}|${SRC_C_BYTE_ORDER_MARK}))${SRC_C_PRINTABLE})`;
2403
- var SRC_NS_CHAR = `(?:(?!${SRC_S_WHITE})${SRC_NB_CHAR})`;
2404
- var SRC_NB_JSON = "[\\x09\\x20-\\uD7FF\\uE000-\\uFFFF\\u{10000}-\\u{10FFFF}]";
2405
- var SRC_C_INDICATOR = "[-?:,\\[\\]{}#&*!|>'\"%@`]";
2406
- var SRC_C_FLOW_INDICATOR = "[,\\[\\]{}]";
2407
- var SRC_NS_PLAIN_SAFE_FLOW_OUT = SRC_NS_CHAR;
2408
- var SRC_NS_PLAIN_SAFE_FLOW_IN = `(?:(?!${SRC_C_FLOW_INDICATOR})${SRC_NS_CHAR})`;
2409
- var SRC_NS_PLAIN_FIRST_FLOW_OUT = `(?:(?:(?!${SRC_C_INDICATOR})${SRC_NS_CHAR})|[?:-](?=${SRC_NS_PLAIN_SAFE_FLOW_OUT}))`;
2410
- var SRC_NS_PLAIN_FIRST_FLOW_IN = `(?:(?:(?!${SRC_C_INDICATOR})${SRC_NS_CHAR})|[?:-](?=${SRC_NS_PLAIN_SAFE_FLOW_IN}))`;
2411
- var SRC_NS_PLAIN_CHAR_FLOW_OUT = `(?:(?:(?![:#])${SRC_NS_PLAIN_SAFE_FLOW_OUT})|:(?=${SRC_NS_PLAIN_SAFE_FLOW_OUT}))#*`;
2412
- var SRC_NS_PLAIN_CHAR_FLOW_IN = `(?:(?:(?![:#])${SRC_NS_PLAIN_SAFE_FLOW_IN})|:(?=${SRC_NS_PLAIN_SAFE_FLOW_IN}))#*`;
2413
- var SRC_NB_NS_PLAIN_IN_LINE_FLOW_OUT = `(?:${SRC_S_WHITE}*${SRC_NS_PLAIN_CHAR_FLOW_OUT})*`;
2414
- var SRC_NB_NS_PLAIN_IN_LINE_FLOW_IN = `(?:${SRC_S_WHITE}*${SRC_NS_PLAIN_CHAR_FLOW_IN})*`;
2415
- var SRC_NS_PLAIN_ONE_LINE_FLOW_OUT = `${SRC_NS_PLAIN_FIRST_FLOW_OUT}#*${SRC_NB_NS_PLAIN_IN_LINE_FLOW_OUT}`;
2416
- var SRC_NS_PLAIN_ONE_LINE_FLOW_IN = `${SRC_NS_PLAIN_FIRST_FLOW_IN}#*${SRC_NB_NS_PLAIN_IN_LINE_FLOW_IN}`;
2417
- var SRC_NS_PLAIN_ONE_LINE_BLOCK_KEY = SRC_NS_PLAIN_ONE_LINE_FLOW_OUT;
2418
- var SRC_NS_PLAIN_ONE_LINE_FLOW_KEY = SRC_NS_PLAIN_ONE_LINE_FLOW_IN;
2419
- var SRC_S_NS_PLAIN_NEXT_LINE_FLOW_OUT = `\\n+${SRC_NS_PLAIN_CHAR_FLOW_OUT}${SRC_NB_NS_PLAIN_IN_LINE_FLOW_OUT}`;
2420
- var SRC_S_NS_PLAIN_NEXT_LINE_FLOW_IN = `\\n+${SRC_NS_PLAIN_CHAR_FLOW_IN}${SRC_NB_NS_PLAIN_IN_LINE_FLOW_IN}`;
2421
- var SRC_NS_PLAIN_MULTI_LINE_FLOW_OUT = `${SRC_NS_PLAIN_ONE_LINE_FLOW_OUT}(?:${SRC_S_NS_PLAIN_NEXT_LINE_FLOW_OUT})*`;
2422
- var SRC_NS_PLAIN_MULTI_LINE_FLOW_IN = `${SRC_NS_PLAIN_ONE_LINE_FLOW_IN}(?:${SRC_S_NS_PLAIN_NEXT_LINE_FLOW_IN})*`;
2423
- var NS_PLAIN_FLOW_OUT = new RegExp(`^(?:${SRC_NS_PLAIN_MULTI_LINE_FLOW_OUT})$`, "u");
2424
- var NS_PLAIN_FLOW_IN = new RegExp(`^(?:${SRC_NS_PLAIN_MULTI_LINE_FLOW_IN})$`, "u");
2425
- var NS_PLAIN_BLOCK_KEY = new RegExp(`^(?:${SRC_NS_PLAIN_ONE_LINE_BLOCK_KEY})$`, "u");
2426
- var NS_PLAIN_FLOW_KEY = new RegExp(`^(?:${SRC_NS_PLAIN_ONE_LINE_FLOW_KEY})$`, "u");
2427
- var NB_SINGLE_ONE_LINE = new RegExp(`^(?:${SRC_NB_JSON})*$`, "u");
2428
- var NB_SINGLE_MULTI_LINE = new RegExp(`^(?:${SRC_NB_JSON}|\\n)*$`, "u");
2429
- var BLOCK_SCALAR_CONTENT = new RegExp(`^(?:${SRC_NB_CHAR}|\\n)*$`, "u");
2430
- var DEFAULT_PRESENTER_OPTIONS = {
2431
- indent: 2,
2432
- seqNoIndent: false,
2433
- seqInlineFirst: true,
2434
- lineWidth: 80,
2435
- flowBracketPadding: false,
2436
- flowSkipCommaSpace: false,
2437
- flowSkipColonSpace: false,
2438
- quoteFlowKeys: false,
2439
- quoteStyle: "single",
2440
- forceQuotes: false,
2441
- scalarStyleRules: Object.keys(DEFAULT_SCALAR_STYLE_RULES).map((name) => Reflect.get(DEFAULT_SCALAR_STYLE_RULES, name)),
2442
- tagBeforeAnchor: false
2443
- };
2444
- var DEFAULT_DUMP_OPTIONS = {
2445
- ...DEFAULT_PRESENTER_OPTIONS,
2446
- schema: DUMP_SCHEMA,
2447
- skipInvalid: false,
2448
- noRefs: false,
2449
- flowLevel: -1,
2450
- sortKeys: false,
2451
- transform: () => {
2452
- }
2453
- };
2454
- var EVENT_DOCUMENT = EVENT_ID.DOCUMENT;
2455
- var EVENT_SEQUENCE = EVENT_ID.SEQUENCE;
2456
- var EVENT_MAPPING = EVENT_ID.MAPPING;
2457
- var EVENT_SCALAR = EVENT_ID.SCALAR;
2458
- var EVENT_ALIAS = EVENT_ID.ALIAS;
2459
- var EVENT_POP = EVENT_ID.POP;
2460
- var SCALAR_STYLE_PLAIN = SCALAR_STYLE.PLAIN;
2461
- var SCALAR_STYLE_SINGLE_QUOTED = SCALAR_STYLE.SINGLE_QUOTED;
2462
- var SCALAR_STYLE_DOUBLE_QUOTED = SCALAR_STYLE.DOUBLE_QUOTED;
2463
- var SCALAR_STYLE_LITERAL_BLOCK = SCALAR_STYLE.LITERAL_BLOCK;
2464
- var SCALAR_STYLE_FOLDED_BLOCK = SCALAR_STYLE.FOLDED_BLOCK;
2465
- var COLLECTION_STYLE_BLOCK = COLLECTION_STYLE.BLOCK;
2466
- var COLLECTION_STYLE_FLOW = COLLECTION_STYLE.FLOW;
2467
- var CHOMPING_CLIP = CHOMPING_MODE.CLIP;
2468
- var CHOMPING_STRIP = CHOMPING_MODE.STRIP;
2469
- var CHOMPING_KEEP = CHOMPING_MODE.KEEP;
2470
-
2471
- // packages/agent-runtime/skillDiscovery.ts
2472
- var SKILL_SCAN_DIRS = [".agents/skills"];
2473
- var MAX_DISCOVERED_SKILLS = 50;
2474
- var MAX_DISCOVERY_DESC_BUDGET = 4e3;
2475
- var MIN_DESC_LENGTH = 80;
2476
- function parseSkillFrontmatter(filePath) {
2477
- try {
2478
- const content = readFileSync(filePath, "utf8").slice(0, 2048);
2479
- const fmMatch = content.match(/^---\n([\s\S]*?)\n---/);
2480
- if (!fmMatch) return {};
2481
- const fm = (() => {
2482
- try {
2483
- return load(fmMatch[1]);
2484
- } catch (err) {
2485
- console.warn(
2486
- `[skillDiscovery] failed to parse frontmatter: ${filePath}: ${err.message}`
2487
- );
2488
- throw err;
2489
- }
2490
- })();
2491
- if (!fm || typeof fm !== "object") return {};
2492
- const name = typeof fm.name === "string" ? fm.name : void 0;
2493
- const rawDesc = fm.description;
2494
- const description = typeof rawDesc === "string" ? rawDesc : rawDesc == null ? void 0 : String(rawDesc);
2495
- const sanitizeName = (s) => s?.trim().replace(/^["']|["']$/g, "").replace(/[\n\r]+/g, " ").slice(0, 200);
2496
- const sanitizeDesc = (s) => s?.trim().replace(/^["']|["']$/g, "").replace(/[\n\r]+/g, " ").slice(0, 200);
2497
- return { name: sanitizeName(name), description: sanitizeDesc(description) };
2498
- } catch {
2499
- return {};
2500
- }
2501
- }
2502
- function discoverSkills(cwd) {
2503
- const skills = [];
2504
- for (const dir of SKILL_SCAN_DIRS) {
2505
- if (skills.length >= MAX_DISCOVERED_SKILLS) break;
2506
- const absDir = join(cwd, dir);
2507
- if (!existsSync(absDir) || !statSync(absDir).isDirectory()) continue;
2508
- try {
2509
- for (const entry of readdirSync(absDir)) {
2510
- if (skills.length >= MAX_DISCOVERED_SKILLS) break;
2511
- const skillMdPath = join(absDir, entry, "SKILL.md");
2512
- if (existsSync(skillMdPath)) {
2513
- const { name, description } = parseSkillFrontmatter(skillMdPath);
2514
- skills.push({ name: name ?? entry, description: description ?? "", relativePath: join(dir, entry, "SKILL.md") });
2515
- continue;
2516
- }
2517
- }
2518
- } catch {
2519
- }
2520
- }
2521
- const totalDescLen = skills.reduce((sum, s) => sum + s.description.length, 0);
2522
- if (totalDescLen > MAX_DISCOVERY_DESC_BUDGET && skills.length > 0) {
2523
- const scale = MAX_DISCOVERY_DESC_BUDGET / totalDescLen;
2524
- for (const s of skills) {
2525
- const targetLen = Math.max(MIN_DESC_LENGTH, Math.floor(s.description.length * scale));
2526
- if (s.description.length > targetLen) {
2527
- s.description = s.description.slice(0, targetLen).trimEnd();
2528
- }
2529
- }
2530
- }
2531
- return skills;
2532
- }
2533
- function resolveSkillByName(cwd, name) {
2534
- const trimmed = name.trim();
2535
- if (!trimmed || trimmed.includes("/") || trimmed.includes("\\") || trimmed.includes("..")) {
2536
- return null;
2537
- }
2538
- const agentsDir = join(cwd, ".agents", "skills", trimmed);
2539
- const agentsSkillMd = join(agentsDir, "SKILL.md");
2540
- if (existsSync(agentsSkillMd)) return agentsSkillMd;
2541
- const agentsParent = join(cwd, ".agents", "skills");
2542
- if (existsSync(agentsParent) && statSync(agentsParent).isDirectory()) {
2543
- try {
2544
- for (const entry of readdirSync(agentsParent)) {
2545
- const candidate = join(agentsParent, entry, "SKILL.md");
2546
- if (!existsSync(candidate)) continue;
2547
- try {
2548
- const { name: fmName } = parseSkillFrontmatter(candidate);
2549
- if (fmName && fmName === trimmed) return candidate;
2550
- } catch {
2551
- }
2552
- }
2553
- } catch {
2554
- }
2555
- }
2556
- return null;
2557
- }
2558
- function buildSkillDiscoveryContextLayer(cwd) {
2559
- try {
2560
- return buildSkillDiscoveryLayer(discoverSkills(cwd), cwd);
2561
- } catch {
2562
- return null;
2563
- }
2564
- }
2565
- function buildSkillDiscoveryContextBlock(cwd) {
2566
- return buildSkillDiscoveryContextLayer(cwd)?.content ?? null;
2567
- }
2568
-
2569
- export {
2570
- parseSkillFrontmatter,
2571
- discoverSkills,
2572
- resolveSkillByName,
2573
- buildSkillDiscoveryContextLayer,
2574
- buildSkillDiscoveryContextBlock
2575
- };