@poe-platform/safe-bash 0.1.756 → 0.1.757
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/image-ast/index.browser.js +4 -4
- package/dist/image-ast/index.js +4 -4
- package/dist/safe-bash/chunks/{chunk-LESPJ3OG.js → chunk-WNWIBBJZ.js} +15 -2
- package/dist/safe-bash/command-chunks/{chunk-S4J6MSLY.js → chunk-444OTXM7.js} +3 -3
- package/dist/safe-bash/command-chunks/{chunk-6AIOGLZO.js → chunk-CE6Z2ULX.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-5VSGEE6J.js → chunk-F4IQCXZG.js} +5 -5
- package/dist/safe-bash/command-chunks/{chunk-F5MORDSU.js → chunk-FDNCPZQS.js} +32 -1
- package/dist/safe-bash/command-chunks/{chunk-SG3ZDZCX.js → chunk-FLMLM7Y4.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-CT3FB722.js → chunk-J7UMKBRK.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-QQOAK7JQ.js → chunk-KKJCKPTA.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-7KS6PX4U.js → chunk-KSIGF4AG.js} +3 -3
- package/dist/safe-bash/command-chunks/{chunk-4HQ7WYSI.js → chunk-MED2BOOW.js} +30 -5
- package/dist/safe-bash/command-chunks/{chunk-JRNLDPLI.js → chunk-OZSWW23M.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-DKQ5REXF.js → chunk-QDPRSPHQ.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-WOPU2VWF.js → chunk-RID3B5RE.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-DVZCHNB5.js → chunk-S4MLIYSN.js} +7 -7
- package/dist/safe-bash/command-chunks/{chunk-REYTQLLB.js → chunk-TT2DMDBY.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-UGX6MXDD.js → chunk-UIIT4ULR.js} +3 -3
- package/dist/safe-bash/command-chunks/{chunk-A6NFLWZI.js → chunk-WKPOGTZY.js} +22 -6
- package/dist/safe-bash/command-chunks/{chunk-3DOHQQJR.js → chunk-Y64PA6IA.js} +8 -8
- package/dist/safe-bash/command-chunks/{chunk-6Z7OS3TZ.js → chunk-ZP5KDHB4.js} +7 -7
- package/dist/safe-bash/commands/pandoc/index.d.ts +1 -1
- package/dist/safe-bash/commands/pandoc/index.js +5 -3
- package/dist/safe-bash/commands/python/index.browser.js +1 -1
- package/dist/safe-bash/commands/python/index.js +6 -0
- package/dist/safe-bash/commands/python/jspi.js +11 -2
- package/dist/safe-bash/core.browser.js +6 -4
- package/dist/safe-bash-command-csvkit/index.js +8 -8
- package/dist/safe-bash-command-soffice/index.js +16 -16
- package/dist/safe-bash-command-ssconvert/core.js +8 -8
- package/dist/safe-bash-command-ssconvert/formats/csv.js +9 -9
- package/dist/safe-bash-command-ssconvert/formats/ods.js +8 -8
- package/dist/safe-bash-command-ssconvert/formats/spreadsheetml.js +1 -1
- package/dist/safe-bash-command-ssconvert/formats/xls.js +9 -8
- package/dist/safe-bash-command-ssconvert/formats/xlsx.js +8 -8
- package/dist/safe-bash-command-ssconvert/index.js +107 -27
- package/dist/safe-bash-contracts/filesystem-descriptor.js +1 -1
- package/dist/safe-bash-contracts/filesystem-output.js +1 -1
- package/dist/safe-bash-mcp/index.js +4 -4
- package/dist/spreadsheet-engine/formulas/ast.d.ts +13 -0
- package/dist/spreadsheet-engine/formulas/conventions.js +1 -1
- package/dist/spreadsheet-engine/formulas/dependencies.js +2 -2
- package/dist/spreadsheet-engine/formulas/evaluator.js +2 -2
- package/dist/spreadsheet-engine/formulas/named-expressions.d.ts +2 -2
- package/dist/spreadsheet-engine/formulas/named-expressions.js +31 -5
- package/dist/spreadsheet-engine/formulas/parser.js +34 -0
- package/dist/spreadsheet-engine/formulas/rewriting.js +19 -1
- package/dist/spreadsheet-engine/formulas/serialization.js +6 -0
- package/dist/spreadsheet-format-xls/biff-write-formulas.js +2 -0
- package/dist/xlsx-ast/formula-semantics.js +2 -0
- package/package.json +2 -2
- package/dist/safe-bash/chunks/browser-ECQX6GMK.js +0 -6766
- package/dist/safe-bash/chunks/bz2-4OP3OWW3.js +0 -8
- package/dist/safe-bash/chunks/chunk-22XPAAOI.js +0 -173
- package/dist/safe-bash/chunks/chunk-44WUNUPV.js +0 -649
- package/dist/safe-bash/chunks/chunk-4E3SGG37.js +0 -876
- package/dist/safe-bash/chunks/chunk-4QTSSQKP.js +0 -898
- package/dist/safe-bash/chunks/chunk-5UVGPVXP.js +0 -410
- package/dist/safe-bash/chunks/chunk-64OE6Q6X.js +0 -3487
- package/dist/safe-bash/chunks/chunk-6IIFUPN2.js +0 -1526
- package/dist/safe-bash/chunks/chunk-BENDLTQD.js +0 -7065
- package/dist/safe-bash/chunks/chunk-BMO5LWEX.js +0 -534
- package/dist/safe-bash/chunks/chunk-BPMCPTNP.js +0 -1920
- package/dist/safe-bash/chunks/chunk-BRJTAWP5.js +0 -2955
- package/dist/safe-bash/chunks/chunk-C3GEIN7Q.js +0 -20054
- package/dist/safe-bash/chunks/chunk-CBVANNKK.js +0 -174814
- package/dist/safe-bash/chunks/chunk-CEWCRI6H.js +0 -2813
- package/dist/safe-bash/chunks/chunk-CGL53DQQ.js +0 -37
- package/dist/safe-bash/chunks/chunk-CTYJJD4O.js +0 -869
- package/dist/safe-bash/chunks/chunk-CWSS4MQA.js +0 -7
- package/dist/safe-bash/chunks/chunk-DLIGMTCP.js +0 -3266
- package/dist/safe-bash/chunks/chunk-EMAJ7WUW.js +0 -1031
- package/dist/safe-bash/chunks/chunk-FDKIZ2IJ.js +0 -1950
- package/dist/safe-bash/chunks/chunk-FZWJ2A7V.js +0 -3093
- package/dist/safe-bash/chunks/chunk-G2VCIF2J.js +0 -22
- package/dist/safe-bash/chunks/chunk-GVKBUQDX.js +0 -2649
- package/dist/safe-bash/chunks/chunk-IO2OGW3E.js +0 -28051
- package/dist/safe-bash/chunks/chunk-ISCZG7WA.js +0 -2648
- package/dist/safe-bash/chunks/chunk-JCN3FXLP.js +0 -38983
- package/dist/safe-bash/chunks/chunk-KJHDD4A2.js +0 -759
- package/dist/safe-bash/chunks/chunk-LB6HVRXS.js +0 -857
- package/dist/safe-bash/chunks/chunk-LLWAJOZH.js +0 -15
- package/dist/safe-bash/chunks/chunk-LMUKYZIJ.js +0 -708
- package/dist/safe-bash/chunks/chunk-M5SCNKIK.js +0 -2012
- package/dist/safe-bash/chunks/chunk-MJPFHANT.js +0 -3350
- package/dist/safe-bash/chunks/chunk-MZQW2DOL.js +0 -82
- package/dist/safe-bash/chunks/chunk-NB2V7EOY.js +0 -1348
- package/dist/safe-bash/chunks/chunk-NJVGOIYN.js +0 -17
- package/dist/safe-bash/chunks/chunk-OLNZHDIQ.js +0 -5141
- package/dist/safe-bash/chunks/chunk-OSUXMC43.js +0 -2317
- package/dist/safe-bash/chunks/chunk-OUUVROTM.js +0 -38
- package/dist/safe-bash/chunks/chunk-PA6GYKBQ.js +0 -151
- package/dist/safe-bash/chunks/chunk-PEFHZ226.js +0 -6957
- package/dist/safe-bash/chunks/chunk-QBB5P5KW.js +0 -4839
- package/dist/safe-bash/chunks/chunk-RSAWYAEH.js +0 -973
- package/dist/safe-bash/chunks/chunk-UWLYRWT4.js +0 -739
- package/dist/safe-bash/chunks/chunk-V463NBQH.js +0 -13
- package/dist/safe-bash/chunks/chunk-WPUALYUS.js +0 -843
- package/dist/safe-bash/chunks/chunk-XHKFSRGU.js +0 -5747
- package/dist/safe-bash/chunks/chunk-XHRCLZ3N.js +0 -13391
- package/dist/safe-bash/chunks/chunk-XPF5XHLY.js +0 -15
- package/dist/safe-bash/chunks/chunk-ZBFOWARG.js +0 -305
- package/dist/safe-bash/chunks/chunk-ZG7GWQ5P.js +0 -1859
- package/dist/safe-bash/chunks/model-store-EIY3ZQLZ.js +0 -10
- package/dist/safe-bash/chunks/pdf-renderer-CMF3CSVU.js +0 -22
- package/dist/safe-bash/chunks/pptx-ZL6L7KP2-O425BFIU.js +0 -30658
- package/dist/safe-bash/chunks/src-HHEPGR7U.js +0 -18969
- package/dist/safe-bash/chunks/src-MXIKQCIC.js +0 -187
- package/dist/safe-bash/chunks/usage-6TGVA2OM.js +0 -35
- package/dist/safe-bash/chunks/xz-EGQGQUEI.js +0 -8
- package/dist/safe-bash/chunks/xz-K2E2WLM6.js +0 -9
- package/dist/safe-bash/chunks/zstd-6JBLP5EF.js +0 -8
- package/dist/safe-bash/git_rust-C3QYOAZL.wasm +0 -0
|
@@ -1,3266 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
YqError,
|
|
3
|
-
YqLedger,
|
|
4
|
-
aliasFailure,
|
|
5
|
-
copyAlias,
|
|
6
|
-
fromJqLimit,
|
|
7
|
-
limit,
|
|
8
|
-
parseTomlDocument,
|
|
9
|
-
resolveYqLimits,
|
|
10
|
-
yqCaps
|
|
11
|
-
} from "./chunk-4QTSSQKP.js";
|
|
12
|
-
import {
|
|
13
|
-
Interpreter,
|
|
14
|
-
parse
|
|
15
|
-
} from "./chunk-OLNZHDIQ.js";
|
|
16
|
-
import {
|
|
17
|
-
Budget,
|
|
18
|
-
Decimal,
|
|
19
|
-
JqError,
|
|
20
|
-
JqLimitError,
|
|
21
|
-
encoder,
|
|
22
|
-
interruptible,
|
|
23
|
-
isNumber,
|
|
24
|
-
numberText,
|
|
25
|
-
object,
|
|
26
|
-
objectKeys,
|
|
27
|
-
put,
|
|
28
|
-
utf8ByteLength,
|
|
29
|
-
wellFormed
|
|
30
|
-
} from "./chunk-44WUNUPV.js";
|
|
31
|
-
import {
|
|
32
|
-
escaping_exports
|
|
33
|
-
} from "./chunk-LLWAJOZH.js";
|
|
34
|
-
import {
|
|
35
|
-
builtInDirectContextExecutors,
|
|
36
|
-
path_exports
|
|
37
|
-
} from "./chunk-ISCZG7WA.js";
|
|
38
|
-
import {
|
|
39
|
-
init_platform
|
|
40
|
-
} from "./chunk-ZG7GWQ5P.js";
|
|
41
|
-
|
|
42
|
-
// packages/safe-bash/src/commands/yq/index.ts
|
|
43
|
-
init_platform();
|
|
44
|
-
|
|
45
|
-
// packages/safe-bash-command-yq/src/index.ts
|
|
46
|
-
init_platform();
|
|
47
|
-
import {
|
|
48
|
-
commandRuntimeIdentity,
|
|
49
|
-
createOutputOperation,
|
|
50
|
-
FsError,
|
|
51
|
-
getCommandArguments,
|
|
52
|
-
readBytes
|
|
53
|
-
} from "../../safe-bash-contracts/index.js";
|
|
54
|
-
import { shellValueByteLength } from "../../safe-bash-contracts/value.js";
|
|
55
|
-
import { yieldTurn as yieldTurn2 } from "../../safe-bash-contracts/yield.js";
|
|
56
|
-
|
|
57
|
-
// packages/safe-bash-query-engine/src/query-core.ts
|
|
58
|
-
init_platform();
|
|
59
|
-
import { yieldTurn } from "../../safe-bash-contracts/yield.js";
|
|
60
|
-
var checkpointWidth = 1023;
|
|
61
|
-
var yqQueryLimits = Object.freeze({
|
|
62
|
-
maxInputBytes: Infinity,
|
|
63
|
-
maxValueBytes: Infinity,
|
|
64
|
-
maxOutputBytes: Infinity,
|
|
65
|
-
maxSourceBytes: Infinity,
|
|
66
|
-
maxDepth: Infinity,
|
|
67
|
-
maxAstDepth: Infinity,
|
|
68
|
-
maxSteps: Infinity,
|
|
69
|
-
maxResults: Infinity,
|
|
70
|
-
maxCollectionSize: Infinity
|
|
71
|
-
});
|
|
72
|
-
var YqValueFailure = class extends Error {
|
|
73
|
-
constructor(code) {
|
|
74
|
-
super(code);
|
|
75
|
-
this.code = code;
|
|
76
|
-
}
|
|
77
|
-
code;
|
|
78
|
-
};
|
|
79
|
-
function assertNonnegativeSafe(value, name) {
|
|
80
|
-
if (!Number.isSafeInteger(value) || value < 0) throw new RangeError(`${name} must be a nonnegative safe integer`);
|
|
81
|
-
}
|
|
82
|
-
function checkedAdd(current, incoming, limitName, limit2) {
|
|
83
|
-
assertNonnegativeSafe(incoming, "count");
|
|
84
|
-
if (incoming > limit2 - current) throw new JqLimitError(limitName);
|
|
85
|
-
return current + incoming;
|
|
86
|
-
}
|
|
87
|
-
function throwSignal(signal) {
|
|
88
|
-
if (signal.aborted) throw signal.reason;
|
|
89
|
-
}
|
|
90
|
-
function scalarBytes(value) {
|
|
91
|
-
return utf8ByteLength(isNumber(value) ? numberText(value) : JSON.stringify(value));
|
|
92
|
-
}
|
|
93
|
-
function validateNumber(value) {
|
|
94
|
-
const numeric = value instanceof Decimal ? value.double : value;
|
|
95
|
-
if (!Number.isFinite(numeric)) throw new YqValueFailure("SCHEMA_NONFINITE_NUMBER");
|
|
96
|
-
if (Number.isInteger(numeric) && !Number.isSafeInteger(numeric)) {
|
|
97
|
-
throw new YqValueFailure("SCHEMA_UNSAFE_INTEGER");
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
function jsonEscape(codePoint) {
|
|
101
|
-
if (codePoint === 34) return '\\"';
|
|
102
|
-
if (codePoint === 92) return "\\\\";
|
|
103
|
-
if (codePoint === 8) return "\\b";
|
|
104
|
-
if (codePoint === 12) return "\\f";
|
|
105
|
-
if (codePoint === 10) return "\\n";
|
|
106
|
-
if (codePoint === 13) return "\\r";
|
|
107
|
-
if (codePoint === 9) return "\\t";
|
|
108
|
-
if (codePoint < 32) return `\\u${codePoint.toString(16).padStart(4, "0")}`;
|
|
109
|
-
return String.fromCodePoint(codePoint);
|
|
110
|
-
}
|
|
111
|
-
function jsonEscapedBytes(codePoint) {
|
|
112
|
-
if (codePoint < 32 && ![8, 9, 10, 12, 13].includes(codePoint)) return 6;
|
|
113
|
-
if (codePoint === 34 || codePoint === 92 || codePoint === 8 || codePoint === 9 || codePoint === 10 || codePoint === 12 || codePoint === 13) return 2;
|
|
114
|
-
return codePoint <= 127 ? 1 : codePoint <= 2047 ? 2 : codePoint <= 65535 ? 3 : 4;
|
|
115
|
-
}
|
|
116
|
-
var RESOLVED_VOID = Promise.resolve();
|
|
117
|
-
var OwnedWork = class {
|
|
118
|
-
#budget;
|
|
119
|
-
#signal;
|
|
120
|
-
#state = { pending: 0, activeReservation: false, accepting: true, terminal: false };
|
|
121
|
-
#active = /* @__PURE__ */ new Set();
|
|
122
|
-
#activeAbandon;
|
|
123
|
-
constructor(budget, signal) {
|
|
124
|
-
this.#budget = budget;
|
|
125
|
-
this.#signal = signal;
|
|
126
|
-
}
|
|
127
|
-
assertOpen() {
|
|
128
|
-
throwSignal(this.#signal);
|
|
129
|
-
if (!this.#state.accepting || this.#state.terminal) throw new Error("yq query session is closed");
|
|
130
|
-
}
|
|
131
|
-
chargeSync(units = 1) {
|
|
132
|
-
if ((units | 0) === units && units > 0 && !this.#state.activeReservation && this.#state.pending + units <= checkpointWidth) {
|
|
133
|
-
this.assertOpen();
|
|
134
|
-
this.#budget.step(units);
|
|
135
|
-
this.#state.pending += units;
|
|
136
|
-
return void 0;
|
|
137
|
-
}
|
|
138
|
-
return this.#track(this.#charge(units));
|
|
139
|
-
}
|
|
140
|
-
charge(units = 1) {
|
|
141
|
-
const p = this.chargeSync(units);
|
|
142
|
-
if (p) return p;
|
|
143
|
-
return RESOLVED_VOID;
|
|
144
|
-
}
|
|
145
|
-
async #charge(units = 1) {
|
|
146
|
-
if (!Number.isSafeInteger(units) || units <= 0) throw new RangeError("units must be a positive safe integer");
|
|
147
|
-
this.assertOpen();
|
|
148
|
-
if (this.#state.activeReservation) throw new Error("owned work cannot interleave with a prepaid reservation");
|
|
149
|
-
let remaining = units;
|
|
150
|
-
while (remaining > 0) {
|
|
151
|
-
this.assertOpen();
|
|
152
|
-
if (this.#state.pending === checkpointWidth) {
|
|
153
|
-
try {
|
|
154
|
-
await this.#budget.tickSync();
|
|
155
|
-
} catch (failure) {
|
|
156
|
-
throwSignal(this.#signal);
|
|
157
|
-
throw failure;
|
|
158
|
-
}
|
|
159
|
-
this.assertOpen();
|
|
160
|
-
this.#state.pending = 0;
|
|
161
|
-
}
|
|
162
|
-
const admitted = Math.min(remaining, checkpointWidth - this.#state.pending);
|
|
163
|
-
this.#budget.step(admitted);
|
|
164
|
-
this.#state.pending += admitted;
|
|
165
|
-
remaining -= admitted;
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
admitInputBytes(bytes) {
|
|
169
|
-
this.assertOpen();
|
|
170
|
-
this.#budget.inputBytes = checkedAdd(this.#budget.inputBytes, bytes, "maxInputBytes", this.#budget.limits.maxInputBytes);
|
|
171
|
-
}
|
|
172
|
-
admitOutputBytes(bytes) {
|
|
173
|
-
this.assertOpen();
|
|
174
|
-
this.#budget.outputBytes = checkedAdd(this.#budget.outputBytes, bytes, "maxOutputBytes", this.#budget.limits.maxOutputBytes);
|
|
175
|
-
}
|
|
176
|
-
admitResult() {
|
|
177
|
-
this.assertOpen();
|
|
178
|
-
this.#budget.results = checkedAdd(this.#budget.results, 1, "maxResults", this.#budget.limits.maxResults);
|
|
179
|
-
}
|
|
180
|
-
measure(value) {
|
|
181
|
-
return this.#track(this.#measure(value));
|
|
182
|
-
}
|
|
183
|
-
measureSync(value) {
|
|
184
|
-
if (this.#budget.limits.maxDepth >= 0 && (value === null || typeof value === "boolean" || typeof value === "number" || value instanceof Decimal || typeof value === "string" && value.length <= 256)) {
|
|
185
|
-
this.assertOpen();
|
|
186
|
-
const p = this.chargeSync(1);
|
|
187
|
-
if (p === void 0) {
|
|
188
|
-
this.assertOpen();
|
|
189
|
-
if (value === null || typeof value === "boolean") {
|
|
190
|
-
return this.#addMeasured(0, scalarBytes(value));
|
|
191
|
-
}
|
|
192
|
-
if (typeof value === "number" || value instanceof Decimal) {
|
|
193
|
-
validateNumber(value);
|
|
194
|
-
return this.#addMeasured(0, utf8ByteLength(numberText(value)));
|
|
195
|
-
}
|
|
196
|
-
if (typeof value === "string") {
|
|
197
|
-
const p2 = value.length > 0 ? this.chargeSync(value.length) : void 0;
|
|
198
|
-
if (p2 === void 0) {
|
|
199
|
-
this.assertOpen();
|
|
200
|
-
if (!wellFormed(value)) throw new YqValueFailure("ENCODE_INVALID_UNICODE");
|
|
201
|
-
let total = 2;
|
|
202
|
-
for (let i = 0; i < value.length; i++) {
|
|
203
|
-
const code = value.charCodeAt(i);
|
|
204
|
-
if (code === 34 || code === 92 || code === 8 || code === 12 || code === 10 || code === 13 || code === 9) total += 2;
|
|
205
|
-
else if (code < 32) total += 6;
|
|
206
|
-
else if (code < 128) total += 1;
|
|
207
|
-
else {
|
|
208
|
-
const cp = value.codePointAt(i);
|
|
209
|
-
total += cp <= 2047 ? 2 : cp <= 65535 ? 3 : 4;
|
|
210
|
-
if (cp > 65535) i++;
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
return this.#addMeasured(0, total);
|
|
214
|
-
}
|
|
215
|
-
return this.#track(p2.then(() => this.#measure(value)));
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
if (p !== void 0) return this.#track(p.then(() => this.#measure(value)));
|
|
219
|
-
}
|
|
220
|
-
return this.measure(value);
|
|
221
|
-
}
|
|
222
|
-
async #measure(value) {
|
|
223
|
-
this.assertOpen();
|
|
224
|
-
let bytes = 0;
|
|
225
|
-
const ancestors = /* @__PURE__ */ new Set();
|
|
226
|
-
const stack = [{ kind: "value", value, depth: 0 }];
|
|
227
|
-
while (stack.length > 0) {
|
|
228
|
-
const item = stack.pop();
|
|
229
|
-
if (item.kind === "leave") {
|
|
230
|
-
ancestors.delete(item.value);
|
|
231
|
-
continue;
|
|
232
|
-
}
|
|
233
|
-
{
|
|
234
|
-
const _p = this.chargeSync(1);
|
|
235
|
-
if (_p) await _p;
|
|
236
|
-
}
|
|
237
|
-
this.assertOpen();
|
|
238
|
-
if (item.depth > this.#budget.limits.maxDepth) throw new JqLimitError("maxDepth");
|
|
239
|
-
const current = item.value;
|
|
240
|
-
if (current === null || typeof current === "boolean") {
|
|
241
|
-
bytes = this.#addMeasured(bytes, scalarBytes(current));
|
|
242
|
-
} else if (typeof current === "number" || current instanceof Decimal) {
|
|
243
|
-
validateNumber(current);
|
|
244
|
-
const text = numberText(current);
|
|
245
|
-
await this.#visitText(text, false);
|
|
246
|
-
this.assertOpen();
|
|
247
|
-
bytes = this.#addMeasured(bytes, utf8ByteLength(text));
|
|
248
|
-
} else if (typeof current === "string") {
|
|
249
|
-
if (!wellFormed(current)) throw new YqValueFailure("ENCODE_INVALID_UNICODE");
|
|
250
|
-
const escaped = await this.#visitText(current, true);
|
|
251
|
-
this.assertOpen();
|
|
252
|
-
bytes = this.#addMeasured(bytes, escaped + 2);
|
|
253
|
-
} else if (typeof current === "object") {
|
|
254
|
-
const objectValue = current;
|
|
255
|
-
if (ancestors.has(objectValue)) throw new YqValueFailure("ENCODE_CYCLIC_GRAPH");
|
|
256
|
-
const prototype = Object.getPrototypeOf(objectValue);
|
|
257
|
-
const array = Array.isArray(current);
|
|
258
|
-
if (!array && prototype !== null && prototype !== Object.prototype) {
|
|
259
|
-
throw new YqValueFailure("ENCODE_UNSUPPORTED_VALUE");
|
|
260
|
-
}
|
|
261
|
-
if (item.depth + 1 > this.#budget.limits.maxDepth) throw new JqLimitError("maxDepth");
|
|
262
|
-
const keys = array ? Object.keys(current) : objectKeys(current);
|
|
263
|
-
this.#budget.collection(keys.length);
|
|
264
|
-
bytes = this.#addMeasured(bytes, 2 + Math.max(0, keys.length - 1));
|
|
265
|
-
ancestors.add(objectValue);
|
|
266
|
-
stack.push({ kind: "leave", value: objectValue });
|
|
267
|
-
for (let index = keys.length - 1; index >= 0; index--) {
|
|
268
|
-
const key = keys[index];
|
|
269
|
-
if (!array) {
|
|
270
|
-
if (!wellFormed(key)) throw new YqValueFailure("ENCODE_INVALID_UNICODE");
|
|
271
|
-
const escaped = await this.#visitText(key, true);
|
|
272
|
-
this.assertOpen();
|
|
273
|
-
bytes = this.#addMeasured(bytes, escaped + 3);
|
|
274
|
-
}
|
|
275
|
-
stack.push({ kind: "value", value: current[key], depth: item.depth + 1 });
|
|
276
|
-
}
|
|
277
|
-
} else {
|
|
278
|
-
throw new YqValueFailure("ENCODE_UNSUPPORTED_VALUE");
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
this.assertOpen();
|
|
282
|
-
return bytes;
|
|
283
|
-
}
|
|
284
|
-
stringifyJson(value, options) {
|
|
285
|
-
return this.#track(this.#stringifyJson(value, options));
|
|
286
|
-
}
|
|
287
|
-
async #stringifyJson(value, options) {
|
|
288
|
-
if (options.maxBytes !== Infinity) assertNonnegativeSafe(options.maxBytes, "maxBytes");
|
|
289
|
-
const fragments = [];
|
|
290
|
-
let bytes = 0;
|
|
291
|
-
const append = async (fragment) => {
|
|
292
|
-
const fragmentBytes = utf8ByteLength(fragment);
|
|
293
|
-
if (fragmentBytes > options.maxBytes - bytes) throw new JqLimitError(options.limitName);
|
|
294
|
-
if (fragmentBytes > 0) await this.charge(Math.ceil(fragmentBytes / 1024));
|
|
295
|
-
this.assertOpen();
|
|
296
|
-
fragments.push(fragment);
|
|
297
|
-
bytes += fragmentBytes;
|
|
298
|
-
};
|
|
299
|
-
const reserveFragment = (projectedBytes) => {
|
|
300
|
-
if (!Number.isSafeInteger(projectedBytes) || projectedBytes < 0 || projectedBytes > options.maxBytes - bytes) {
|
|
301
|
-
throw new JqLimitError(options.limitName);
|
|
302
|
-
}
|
|
303
|
-
bytes += projectedBytes;
|
|
304
|
-
};
|
|
305
|
-
const appendReserved = async (fragment, projectedBytes) => {
|
|
306
|
-
if (utf8ByteLength(fragment) !== projectedBytes) throw new Error("escaped fragment projection mismatch");
|
|
307
|
-
if (projectedBytes > 0) await this.charge(Math.ceil(projectedBytes / 1024));
|
|
308
|
-
this.assertOpen();
|
|
309
|
-
fragments.push(fragment);
|
|
310
|
-
};
|
|
311
|
-
const appendIndent = async (depth) => {
|
|
312
|
-
const indentBytes = depth * 2;
|
|
313
|
-
if (!Number.isSafeInteger(indentBytes) || indentBytes > options.maxBytes - bytes) throw new JqLimitError(options.limitName);
|
|
314
|
-
await append(" ".repeat(depth));
|
|
315
|
-
};
|
|
316
|
-
const appendString = async (text) => {
|
|
317
|
-
if (!wellFormed(text)) throw new YqValueFailure("ENCODE_INVALID_UNICODE");
|
|
318
|
-
await append('"');
|
|
319
|
-
for (let start = 0; start < text.length; ) {
|
|
320
|
-
let end = start;
|
|
321
|
-
let codePoints = 0;
|
|
322
|
-
let projectedBytes = 0;
|
|
323
|
-
while (end < text.length && codePoints < 256) {
|
|
324
|
-
const codePoint = text.codePointAt(end);
|
|
325
|
-
projectedBytes += jsonEscapedBytes(codePoint);
|
|
326
|
-
end += codePoint > 65535 ? 2 : 1;
|
|
327
|
-
codePoints++;
|
|
328
|
-
}
|
|
329
|
-
reserveFragment(projectedBytes);
|
|
330
|
-
let fragment = "";
|
|
331
|
-
for (let index = start; index < end; ) {
|
|
332
|
-
const codePoint = text.codePointAt(index);
|
|
333
|
-
fragment += jsonEscape(codePoint);
|
|
334
|
-
index += codePoint > 65535 ? 2 : 1;
|
|
335
|
-
}
|
|
336
|
-
await this.charge(codePoints);
|
|
337
|
-
this.assertOpen();
|
|
338
|
-
await appendReserved(fragment, projectedBytes);
|
|
339
|
-
this.assertOpen();
|
|
340
|
-
start = end;
|
|
341
|
-
}
|
|
342
|
-
this.assertOpen();
|
|
343
|
-
await append('"');
|
|
344
|
-
};
|
|
345
|
-
const ancestors = /* @__PURE__ */ new Set();
|
|
346
|
-
const encode = async (current, depth) => {
|
|
347
|
-
{
|
|
348
|
-
const _p = this.chargeSync(1);
|
|
349
|
-
if (_p) await _p;
|
|
350
|
-
}
|
|
351
|
-
this.assertOpen();
|
|
352
|
-
if (depth > this.#budget.limits.maxDepth) throw new JqLimitError("maxDepth");
|
|
353
|
-
if (current === null || typeof current === "boolean") {
|
|
354
|
-
await append(JSON.stringify(current));
|
|
355
|
-
} else if (typeof current === "number" || current instanceof Decimal) {
|
|
356
|
-
validateNumber(current);
|
|
357
|
-
await append(numberText(current));
|
|
358
|
-
} else if (typeof current === "string") {
|
|
359
|
-
await appendString(current);
|
|
360
|
-
} else if (typeof current === "object") {
|
|
361
|
-
const objectValue = current;
|
|
362
|
-
if (ancestors.has(objectValue)) throw new YqValueFailure("ENCODE_CYCLIC_GRAPH");
|
|
363
|
-
const array = Array.isArray(current);
|
|
364
|
-
const prototype = Object.getPrototypeOf(objectValue);
|
|
365
|
-
if (!array && prototype !== null && prototype !== Object.prototype) throw new YqValueFailure("ENCODE_UNSUPPORTED_VALUE");
|
|
366
|
-
if (depth + 1 > this.#budget.limits.maxDepth) throw new JqLimitError("maxDepth");
|
|
367
|
-
const keys = array ? Object.keys(current) : objectKeys(current);
|
|
368
|
-
this.#budget.collection(keys.length);
|
|
369
|
-
ancestors.add(objectValue);
|
|
370
|
-
try {
|
|
371
|
-
await append(array ? "[" : "{");
|
|
372
|
-
if (options.pretty && keys.length > 0) await append("\n");
|
|
373
|
-
for (let index = 0; index < keys.length; index++) {
|
|
374
|
-
const key = keys[index];
|
|
375
|
-
if (index > 0) await append(options.pretty ? ",\n" : ",");
|
|
376
|
-
if (options.pretty) await appendIndent(depth + 1);
|
|
377
|
-
if (!array) {
|
|
378
|
-
if (!wellFormed(key)) throw new YqValueFailure("ENCODE_INVALID_UNICODE");
|
|
379
|
-
await appendString(key);
|
|
380
|
-
await append(options.pretty ? ": " : ":");
|
|
381
|
-
}
|
|
382
|
-
await encode(current[key], depth + 1);
|
|
383
|
-
}
|
|
384
|
-
if (options.pretty && keys.length > 0) {
|
|
385
|
-
await append("\n");
|
|
386
|
-
await appendIndent(depth);
|
|
387
|
-
}
|
|
388
|
-
await append(array ? "]" : "}");
|
|
389
|
-
} finally {
|
|
390
|
-
ancestors.delete(objectValue);
|
|
391
|
-
}
|
|
392
|
-
} else {
|
|
393
|
-
throw new YqValueFailure("ENCODE_UNSUPPORTED_VALUE");
|
|
394
|
-
}
|
|
395
|
-
};
|
|
396
|
-
await encode(value, 0);
|
|
397
|
-
this.assertOpen();
|
|
398
|
-
if (bytes > options.maxBytes) throw new JqLimitError(options.limitName);
|
|
399
|
-
return fragments.join("");
|
|
400
|
-
}
|
|
401
|
-
reserve(ordinaryUnits) {
|
|
402
|
-
assertNonnegativeSafe(ordinaryUnits, "ordinaryUnits");
|
|
403
|
-
this.assertOpen();
|
|
404
|
-
if (this.#state.activeReservation) throw new Error("nested owned reservation");
|
|
405
|
-
const startPending = this.#state.pending;
|
|
406
|
-
let checkpoints = 0;
|
|
407
|
-
let targetPending = startPending;
|
|
408
|
-
if (ordinaryUnits > 0) {
|
|
409
|
-
if (ordinaryUnits > Number.MAX_SAFE_INTEGER - startPending) throw new RangeError("owned reservation overflow");
|
|
410
|
-
const sum = startPending + ordinaryUnits;
|
|
411
|
-
checkpoints = Math.floor((sum - 1) / checkpointWidth);
|
|
412
|
-
targetPending = sum - checkpoints * checkpointWidth;
|
|
413
|
-
}
|
|
414
|
-
if (checkpoints > Number.MAX_SAFE_INTEGER - ordinaryUnits) throw new RangeError("owned reservation overflow");
|
|
415
|
-
const total = ordinaryUnits + checkpoints;
|
|
416
|
-
this.#budget.step(total);
|
|
417
|
-
this.assertOpen();
|
|
418
|
-
this.#state.activeReservation = true;
|
|
419
|
-
let ordinaryRemaining = ordinaryUnits;
|
|
420
|
-
let checkpointRemaining = checkpoints;
|
|
421
|
-
let executionPending = startPending;
|
|
422
|
-
let active = true;
|
|
423
|
-
let releaseReservation;
|
|
424
|
-
const reservationLifetime = new Promise((resolve) => {
|
|
425
|
-
releaseReservation = resolve;
|
|
426
|
-
});
|
|
427
|
-
this.#active.add(reservationLifetime);
|
|
428
|
-
void reservationLifetime.finally(() => this.#active.delete(reservationLifetime));
|
|
429
|
-
const fail = () => {
|
|
430
|
-
active = false;
|
|
431
|
-
this.#state.activeReservation = false;
|
|
432
|
-
this.#state.terminal = true;
|
|
433
|
-
this.#activeAbandon = void 0;
|
|
434
|
-
releaseReservation();
|
|
435
|
-
throw new Error("invalid prepaid owned-work schedule");
|
|
436
|
-
};
|
|
437
|
-
const abandon = () => {
|
|
438
|
-
if (!active) return;
|
|
439
|
-
active = false;
|
|
440
|
-
this.#state.activeReservation = false;
|
|
441
|
-
this.#state.terminal = true;
|
|
442
|
-
this.#activeAbandon = void 0;
|
|
443
|
-
releaseReservation();
|
|
444
|
-
};
|
|
445
|
-
this.#activeAbandon = abandon;
|
|
446
|
-
const beforeUnit = async () => {
|
|
447
|
-
if (!active || ordinaryRemaining === 0) fail();
|
|
448
|
-
this.assertOpen();
|
|
449
|
-
if (executionPending === checkpointWidth) {
|
|
450
|
-
if (checkpointRemaining === 0) fail();
|
|
451
|
-
checkpointRemaining--;
|
|
452
|
-
throwSignal(this.#signal);
|
|
453
|
-
try {
|
|
454
|
-
await yieldTurn(this.#signal);
|
|
455
|
-
} catch (failure) {
|
|
456
|
-
if (this.#signal.aborted) throw this.#signal.reason;
|
|
457
|
-
throw failure;
|
|
458
|
-
}
|
|
459
|
-
this.assertOpen();
|
|
460
|
-
executionPending = 0;
|
|
461
|
-
} else {
|
|
462
|
-
await Promise.resolve();
|
|
463
|
-
this.assertOpen();
|
|
464
|
-
}
|
|
465
|
-
ordinaryRemaining--;
|
|
466
|
-
executionPending++;
|
|
467
|
-
};
|
|
468
|
-
return Object.freeze({
|
|
469
|
-
beforeUnit: () => this.#track(beforeUnit()),
|
|
470
|
-
finish: () => {
|
|
471
|
-
if (!active || ordinaryRemaining !== 0 || checkpointRemaining !== 0 || executionPending !== targetPending) fail();
|
|
472
|
-
this.assertOpen();
|
|
473
|
-
active = false;
|
|
474
|
-
this.#state.pending = targetPending;
|
|
475
|
-
this.#state.activeReservation = false;
|
|
476
|
-
this.#activeAbandon = void 0;
|
|
477
|
-
releaseReservation();
|
|
478
|
-
},
|
|
479
|
-
abandon
|
|
480
|
-
});
|
|
481
|
-
}
|
|
482
|
-
async close() {
|
|
483
|
-
this.#state.accepting = false;
|
|
484
|
-
this.#activeAbandon?.();
|
|
485
|
-
await Promise.allSettled([...this.#active]);
|
|
486
|
-
}
|
|
487
|
-
#addMeasured(current, incoming) {
|
|
488
|
-
if (incoming > this.#budget.limits.maxValueBytes - current) throw new JqLimitError("maxValueBytes");
|
|
489
|
-
return current + incoming;
|
|
490
|
-
}
|
|
491
|
-
async #visitText(text, escaped) {
|
|
492
|
-
if (!wellFormed(text)) throw new YqValueFailure("ENCODE_INVALID_UNICODE");
|
|
493
|
-
let encodedBytes = 0;
|
|
494
|
-
let payloadBytes = 0;
|
|
495
|
-
let codePoints = 0;
|
|
496
|
-
for (const character of text) {
|
|
497
|
-
const fragment = escaped ? jsonEscape(character.codePointAt(0)) : character;
|
|
498
|
-
const bytes = utf8ByteLength(fragment);
|
|
499
|
-
if (bytes > this.#budget.limits.maxValueBytes - encodedBytes) throw new JqLimitError("maxValueBytes");
|
|
500
|
-
encodedBytes += bytes;
|
|
501
|
-
payloadBytes += utf8ByteLength(character);
|
|
502
|
-
codePoints++;
|
|
503
|
-
if (codePoints === 256) {
|
|
504
|
-
{
|
|
505
|
-
const _p = this.chargeSync(codePoints);
|
|
506
|
-
if (_p) await _p;
|
|
507
|
-
}
|
|
508
|
-
this.assertOpen();
|
|
509
|
-
codePoints = 0;
|
|
510
|
-
}
|
|
511
|
-
}
|
|
512
|
-
if (codePoints > 0) {
|
|
513
|
-
{
|
|
514
|
-
const _p = this.chargeSync(codePoints);
|
|
515
|
-
if (_p) await _p;
|
|
516
|
-
}
|
|
517
|
-
this.assertOpen();
|
|
518
|
-
}
|
|
519
|
-
if (payloadBytes > 0) {
|
|
520
|
-
{
|
|
521
|
-
const _p = this.chargeSync(Math.ceil(payloadBytes / 1024));
|
|
522
|
-
if (_p) await _p;
|
|
523
|
-
}
|
|
524
|
-
this.assertOpen();
|
|
525
|
-
}
|
|
526
|
-
return encodedBytes;
|
|
527
|
-
}
|
|
528
|
-
#track(promise) {
|
|
529
|
-
this.#active.add(promise);
|
|
530
|
-
void promise.finally(() => this.#active.delete(promise)).catch(() => {
|
|
531
|
-
});
|
|
532
|
-
return promise;
|
|
533
|
-
}
|
|
534
|
-
};
|
|
535
|
-
var QuerySession = class {
|
|
536
|
-
ownedWork;
|
|
537
|
-
#signal;
|
|
538
|
-
#variables = /* @__PURE__ */ new Map();
|
|
539
|
-
#budget;
|
|
540
|
-
#interpreter;
|
|
541
|
-
#ast;
|
|
542
|
-
#compileAttempted = false;
|
|
543
|
-
#accepting = true;
|
|
544
|
-
#active;
|
|
545
|
-
#activeReturn;
|
|
546
|
-
#closePromise;
|
|
547
|
-
constructor(signal, limits = {}) {
|
|
548
|
-
if (!(signal instanceof AbortSignal)) throw new TypeError("signal must be an AbortSignal");
|
|
549
|
-
this.#signal = signal;
|
|
550
|
-
this.#budget = new Budget(Object.freeze({ ...yqQueryLimits, ...limits }), signal);
|
|
551
|
-
this.#interpreter = new Interpreter(this.#budget, this.#variables);
|
|
552
|
-
this.ownedWork = new OwnedWork(this.#budget, signal);
|
|
553
|
-
}
|
|
554
|
-
compileOnce(source) {
|
|
555
|
-
this.#assertAdmission();
|
|
556
|
-
if (this.#compileAttempted) throw new Error("yq query compilation was already attempted");
|
|
557
|
-
this.#compileAttempted = true;
|
|
558
|
-
this.#ast = parse(source, this.#variables, this.#budget);
|
|
559
|
-
}
|
|
560
|
-
run(input) {
|
|
561
|
-
const session = this;
|
|
562
|
-
return (async function* () {
|
|
563
|
-
session.#assertAdmission();
|
|
564
|
-
if (!session.#ast) throw new Error("yq query was not compiled successfully");
|
|
565
|
-
if (session.#active) throw new Error("overlapping yq query runs are not allowed");
|
|
566
|
-
const iterator = session.#interpreter.run(session.#ast, input);
|
|
567
|
-
session.#active = iterator;
|
|
568
|
-
session.#activeReturn = void 0;
|
|
569
|
-
try {
|
|
570
|
-
while (true) {
|
|
571
|
-
let next;
|
|
572
|
-
try {
|
|
573
|
-
next = await iterator.next();
|
|
574
|
-
} catch (failure) {
|
|
575
|
-
throwSignal(session.#signal);
|
|
576
|
-
throw failure;
|
|
577
|
-
}
|
|
578
|
-
session.#assertAdmission();
|
|
579
|
-
if (next.done) return;
|
|
580
|
-
yield next.value;
|
|
581
|
-
session.#assertAdmission();
|
|
582
|
-
}
|
|
583
|
-
} finally {
|
|
584
|
-
try {
|
|
585
|
-
await session.#returnActive(iterator);
|
|
586
|
-
} finally {
|
|
587
|
-
if (session.#active === iterator) session.#active = void 0;
|
|
588
|
-
}
|
|
589
|
-
}
|
|
590
|
-
})();
|
|
591
|
-
}
|
|
592
|
-
close() {
|
|
593
|
-
if (this.#closePromise) return this.#closePromise;
|
|
594
|
-
this.#accepting = false;
|
|
595
|
-
this.#closePromise = (async () => {
|
|
596
|
-
const failures = [];
|
|
597
|
-
const active = this.#active;
|
|
598
|
-
if (active) {
|
|
599
|
-
try {
|
|
600
|
-
await this.#returnActive(active);
|
|
601
|
-
} catch (failure) {
|
|
602
|
-
failures.push(failure);
|
|
603
|
-
}
|
|
604
|
-
}
|
|
605
|
-
try {
|
|
606
|
-
await this.ownedWork.close();
|
|
607
|
-
} catch (failure) {
|
|
608
|
-
failures.push(failure);
|
|
609
|
-
}
|
|
610
|
-
if (failures.length === 1) throw failures[0];
|
|
611
|
-
if (failures.length > 1) throw new AggregateError(failures, "yq query session cleanup failed");
|
|
612
|
-
})();
|
|
613
|
-
void this.#closePromise.catch(() => {
|
|
614
|
-
});
|
|
615
|
-
return this.#closePromise;
|
|
616
|
-
}
|
|
617
|
-
#assertAdmission() {
|
|
618
|
-
throwSignal(this.#signal);
|
|
619
|
-
if (!this.#accepting) throw new Error("yq query session is closed");
|
|
620
|
-
}
|
|
621
|
-
#returnActive(iterator) {
|
|
622
|
-
if (this.#active === iterator && this.#activeReturn) return this.#activeReturn;
|
|
623
|
-
const returned = Promise.resolve().then(() => iterator.return(void 0));
|
|
624
|
-
if (this.#active === iterator) this.#activeReturn = returned;
|
|
625
|
-
void returned.catch(() => {
|
|
626
|
-
});
|
|
627
|
-
return returned;
|
|
628
|
-
}
|
|
629
|
-
};
|
|
630
|
-
function createYqQuerySession(options) {
|
|
631
|
-
if (typeof options !== "object" || options === null) throw new TypeError("options must be an object");
|
|
632
|
-
return new QuerySession(options.signal, options.limits);
|
|
633
|
-
}
|
|
634
|
-
|
|
635
|
-
// packages/safe-bash-command-yq/src/encoder.ts
|
|
636
|
-
init_platform();
|
|
637
|
-
var Fragments = class {
|
|
638
|
-
constructor(work, maxBytes) {
|
|
639
|
-
this.work = work;
|
|
640
|
-
this.maxBytes = maxBytes;
|
|
641
|
-
}
|
|
642
|
-
work;
|
|
643
|
-
maxBytes;
|
|
644
|
-
parts = [];
|
|
645
|
-
bytes = 0;
|
|
646
|
-
async append(fragment) {
|
|
647
|
-
const bytes = utf8ByteLength(fragment);
|
|
648
|
-
if (bytes > this.maxBytes - this.bytes) throw new JqLimitError("maxOutputBytes");
|
|
649
|
-
if (bytes > 0) {
|
|
650
|
-
const _p = this.work.chargeSync ? this.work.chargeSync(Math.ceil(bytes / 1024)) : this.work.charge(Math.ceil(bytes / 1024));
|
|
651
|
-
if (_p) await _p;
|
|
652
|
-
}
|
|
653
|
-
this.work.assertOpen();
|
|
654
|
-
this.parts.push(fragment);
|
|
655
|
-
this.bytes += bytes;
|
|
656
|
-
}
|
|
657
|
-
reserve(bytes) {
|
|
658
|
-
if (!Number.isSafeInteger(bytes) || bytes < 0 || bytes > this.maxBytes - this.bytes) {
|
|
659
|
-
throw new JqLimitError("maxOutputBytes");
|
|
660
|
-
}
|
|
661
|
-
this.bytes += bytes;
|
|
662
|
-
}
|
|
663
|
-
async appendReserved(fragment, bytes) {
|
|
664
|
-
if (utf8ByteLength(fragment) !== bytes) throw new Error("escaped fragment projection mismatch");
|
|
665
|
-
if (bytes > 0) {
|
|
666
|
-
const _p = this.work.chargeSync ? this.work.chargeSync(Math.ceil(bytes / 1024)) : this.work.charge(Math.ceil(bytes / 1024));
|
|
667
|
-
if (_p) await _p;
|
|
668
|
-
}
|
|
669
|
-
this.work.assertOpen();
|
|
670
|
-
this.parts.push(fragment);
|
|
671
|
-
}
|
|
672
|
-
async indent(depth) {
|
|
673
|
-
const bytes = depth * 2;
|
|
674
|
-
if (!Number.isSafeInteger(bytes) || bytes > this.maxBytes - this.bytes) throw new JqLimitError("maxOutputBytes");
|
|
675
|
-
if (bytes > 0) {
|
|
676
|
-
const _p = this.work.chargeSync ? this.work.chargeSync(Math.ceil(bytes / 1024)) : this.work.charge(Math.ceil(bytes / 1024));
|
|
677
|
-
if (_p) await _p;
|
|
678
|
-
}
|
|
679
|
-
this.work.assertOpen();
|
|
680
|
-
this.parts.push(" ".repeat(depth));
|
|
681
|
-
this.bytes += bytes;
|
|
682
|
-
}
|
|
683
|
-
finish() {
|
|
684
|
-
this.work.assertOpen();
|
|
685
|
-
return this.parts.join("");
|
|
686
|
-
}
|
|
687
|
-
};
|
|
688
|
-
function yamlEscape(codePoint) {
|
|
689
|
-
if (codePoint === 0) return "\\u0000";
|
|
690
|
-
if (codePoint === 34) return '\\"';
|
|
691
|
-
if (codePoint === 92) return "\\\\";
|
|
692
|
-
if (codePoint === 8) return "\\b";
|
|
693
|
-
if (codePoint === 9) return "\\t";
|
|
694
|
-
if (codePoint === 10) return "\\n";
|
|
695
|
-
if (codePoint === 12) return "\\f";
|
|
696
|
-
if (codePoint === 13) return "\\r";
|
|
697
|
-
if (codePoint === 27) return "\\e";
|
|
698
|
-
if (codePoint < 32 || codePoint === 127 || codePoint >= 128 && codePoint <= 159 || codePoint === 65534 || codePoint === 65535) {
|
|
699
|
-
if (codePoint <= 65535) return `\\u${codePoint.toString(16).padStart(4, "0")}`;
|
|
700
|
-
return `\\U${codePoint.toString(16).padStart(8, "0")}`;
|
|
701
|
-
}
|
|
702
|
-
return String.fromCodePoint(codePoint);
|
|
703
|
-
}
|
|
704
|
-
function yamlEscapedBytes(codePoint) {
|
|
705
|
-
if (codePoint === 0 || codePoint < 32 && ![8, 9, 10, 12, 13, 27].includes(codePoint) || codePoint === 127 || codePoint >= 128 && codePoint <= 159 || codePoint === 65534 || codePoint === 65535) return 6;
|
|
706
|
-
if (codePoint === 34 || codePoint === 92 || codePoint === 8 || codePoint === 9 || codePoint === 10 || codePoint === 12 || codePoint === 13 || codePoint === 27) return 2;
|
|
707
|
-
return codePoint <= 127 ? 1 : codePoint <= 2047 ? 2 : codePoint <= 65535 ? 3 : 4;
|
|
708
|
-
}
|
|
709
|
-
async function quoted(text, output) {
|
|
710
|
-
if (!wellFormed(text)) throw new YqValueFailure("ENCODE_INVALID_UNICODE");
|
|
711
|
-
await output.append('"');
|
|
712
|
-
for (let start = 0; start < text.length; ) {
|
|
713
|
-
let end = start;
|
|
714
|
-
let codePoints = 0;
|
|
715
|
-
let projectedBytes = 0;
|
|
716
|
-
while (end < text.length && codePoints < 256) {
|
|
717
|
-
const codePoint = text.codePointAt(end);
|
|
718
|
-
projectedBytes += yamlEscapedBytes(codePoint);
|
|
719
|
-
end += codePoint > 65535 ? 2 : 1;
|
|
720
|
-
codePoints++;
|
|
721
|
-
}
|
|
722
|
-
output.reserve(projectedBytes);
|
|
723
|
-
let fragment = "";
|
|
724
|
-
for (let index = start; index < end; ) {
|
|
725
|
-
const codePoint = text.codePointAt(index);
|
|
726
|
-
fragment += yamlEscape(codePoint);
|
|
727
|
-
index += codePoint > 65535 ? 2 : 1;
|
|
728
|
-
}
|
|
729
|
-
{
|
|
730
|
-
const _p = output.work.chargeSync ? output.work.chargeSync(codePoints) : output.work.charge(codePoints);
|
|
731
|
-
if (_p) await _p;
|
|
732
|
-
}
|
|
733
|
-
output.work.assertOpen();
|
|
734
|
-
await output.appendReserved(fragment, projectedBytes);
|
|
735
|
-
output.work.assertOpen();
|
|
736
|
-
start = end;
|
|
737
|
-
}
|
|
738
|
-
output.work.assertOpen();
|
|
739
|
-
await output.append('"');
|
|
740
|
-
}
|
|
741
|
-
function isCollection(value) {
|
|
742
|
-
return value !== null && typeof value === "object" && !(value instanceof Decimal);
|
|
743
|
-
}
|
|
744
|
-
function nonemptyCollection(value) {
|
|
745
|
-
if (!isCollection(value)) return false;
|
|
746
|
-
return Array.isArray(value) ? value.length > 0 : objectKeys(value).length > 0;
|
|
747
|
-
}
|
|
748
|
-
async function inline(value, output) {
|
|
749
|
-
{
|
|
750
|
-
const _p = output.work.chargeSync ? output.work.chargeSync(1) : output.work.charge(1);
|
|
751
|
-
if (_p) await _p;
|
|
752
|
-
}
|
|
753
|
-
output.work.assertOpen();
|
|
754
|
-
if (value === null || typeof value === "boolean") await output.append(JSON.stringify(value));
|
|
755
|
-
else if (typeof value === "number" || value instanceof Decimal) {
|
|
756
|
-
const numeric = value instanceof Decimal ? value.double : value;
|
|
757
|
-
if (!Number.isFinite(numeric)) throw new YqValueFailure("SCHEMA_NONFINITE_NUMBER");
|
|
758
|
-
if (Number.isInteger(numeric) && !Number.isSafeInteger(numeric)) throw new YqValueFailure("SCHEMA_UNSAFE_INTEGER");
|
|
759
|
-
await output.append(numberText(value));
|
|
760
|
-
} else if (typeof value === "string") await quoted(value, output);
|
|
761
|
-
else if (Array.isArray(value) && value.length === 0) await output.append("[]");
|
|
762
|
-
else if (!Array.isArray(value) && objectKeys(value).length === 0) await output.append("{}");
|
|
763
|
-
else throw new YqValueFailure("ENCODE_UNSUPPORTED_VALUE");
|
|
764
|
-
}
|
|
765
|
-
async function mappingBlock(value, output, depth, firstInline) {
|
|
766
|
-
const keys = objectKeys(value);
|
|
767
|
-
for (let index = 0; index < keys.length; index++) {
|
|
768
|
-
if (index > 0) await output.append("\n");
|
|
769
|
-
if (!(firstInline && index === 0)) await output.indent(depth);
|
|
770
|
-
await quoted(keys[index], output);
|
|
771
|
-
await output.append(":");
|
|
772
|
-
const item = value[keys[index]];
|
|
773
|
-
if (nonemptyCollection(item)) {
|
|
774
|
-
await output.append("\n");
|
|
775
|
-
await block(item, output, depth + 1);
|
|
776
|
-
} else {
|
|
777
|
-
await output.append(" ");
|
|
778
|
-
await inline(item, output);
|
|
779
|
-
}
|
|
780
|
-
}
|
|
781
|
-
}
|
|
782
|
-
async function block(value, output, depth) {
|
|
783
|
-
{
|
|
784
|
-
const _p = output.work.chargeSync ? output.work.chargeSync(1) : output.work.charge(1);
|
|
785
|
-
if (_p) await _p;
|
|
786
|
-
}
|
|
787
|
-
output.work.assertOpen();
|
|
788
|
-
if (!nonemptyCollection(value)) {
|
|
789
|
-
await output.indent(depth);
|
|
790
|
-
await inline(value, output);
|
|
791
|
-
return;
|
|
792
|
-
}
|
|
793
|
-
if (Array.isArray(value)) {
|
|
794
|
-
for (let index = 0; index < value.length; index++) {
|
|
795
|
-
if (index > 0) await output.append("\n");
|
|
796
|
-
await output.indent(depth);
|
|
797
|
-
await output.append("-");
|
|
798
|
-
const item = value[index];
|
|
799
|
-
if (isCollection(item) && !Array.isArray(item) && objectKeys(item).length > 0) {
|
|
800
|
-
{
|
|
801
|
-
const _p = output.work.chargeSync ? output.work.chargeSync(1) : output.work.charge(1);
|
|
802
|
-
if (_p) await _p;
|
|
803
|
-
}
|
|
804
|
-
output.work.assertOpen();
|
|
805
|
-
await output.append(" ");
|
|
806
|
-
await mappingBlock(item, output, depth + 1, true);
|
|
807
|
-
} else if (nonemptyCollection(item)) {
|
|
808
|
-
await output.append("\n");
|
|
809
|
-
await block(item, output, depth + 1);
|
|
810
|
-
} else {
|
|
811
|
-
await output.append(" ");
|
|
812
|
-
await inline(item, output);
|
|
813
|
-
}
|
|
814
|
-
}
|
|
815
|
-
return;
|
|
816
|
-
}
|
|
817
|
-
await mappingBlock(value, output, depth, false);
|
|
818
|
-
}
|
|
819
|
-
async function encodeYaml(value, work, maxBytes) {
|
|
820
|
-
if (maxBytes !== Infinity && (!Number.isSafeInteger(maxBytes) || maxBytes < 0)) throw new RangeError("maxBytes must be a nonnegative safe integer or Infinity");
|
|
821
|
-
const output = new Fragments(work, maxBytes);
|
|
822
|
-
if (nonemptyCollection(value)) await block(value, output, 0);
|
|
823
|
-
else await inline(value, output);
|
|
824
|
-
work.assertOpen();
|
|
825
|
-
return output.finish();
|
|
826
|
-
}
|
|
827
|
-
async function encodeJson(value, work, pretty, maxBytes) {
|
|
828
|
-
return work.stringifyJson(value, { pretty, maxBytes, limitName: "maxOutputBytes" });
|
|
829
|
-
}
|
|
830
|
-
async function encodeRaw(text, work, maxBytes) {
|
|
831
|
-
if (!wellFormed(text)) throw new YqValueFailure("ENCODE_INVALID_UNICODE");
|
|
832
|
-
let bytes = 0;
|
|
833
|
-
let codePoints = 0;
|
|
834
|
-
for (const character of text) {
|
|
835
|
-
const incoming = utf8ByteLength(character);
|
|
836
|
-
if (incoming > maxBytes - bytes) throw new JqLimitError("maxOutputBytes");
|
|
837
|
-
bytes += incoming;
|
|
838
|
-
codePoints++;
|
|
839
|
-
if (codePoints === 256) {
|
|
840
|
-
await work.charge(codePoints);
|
|
841
|
-
work.assertOpen();
|
|
842
|
-
codePoints = 0;
|
|
843
|
-
}
|
|
844
|
-
}
|
|
845
|
-
if (codePoints > 0) await work.charge(codePoints);
|
|
846
|
-
work.assertOpen();
|
|
847
|
-
if (bytes > 0) await work.charge(Math.ceil(bytes / 1024));
|
|
848
|
-
work.assertOpen();
|
|
849
|
-
return text;
|
|
850
|
-
}
|
|
851
|
-
|
|
852
|
-
// packages/safe-bash-command-yq/src/parser.ts
|
|
853
|
-
init_platform();
|
|
854
|
-
var integerPattern = /^(?:[+-]?[0-9]+|0o[0-7]+|0x[0-9a-fA-F]+)$/u;
|
|
855
|
-
var floatPattern = /^[+-]?(?:(?:[0-9]+(?:\.[0-9]*)?|\.[0-9]+)(?:[eE][+-]?[0-9]+)?|\.(?:inf|Inf|INF|nan|NaN|NAN))$/u;
|
|
856
|
-
function syntax(line, column) {
|
|
857
|
-
return new YqError("input", "INPUT_YAML_SYNTAX", 5, void 0, line, column);
|
|
858
|
-
}
|
|
859
|
-
function structure(line, column) {
|
|
860
|
-
return new YqError("input", "INPUT_DOCUMENT_STRUCTURE", 5, void 0, line, column);
|
|
861
|
-
}
|
|
862
|
-
function schema(code, line, column) {
|
|
863
|
-
return new YqError("schema", code, 5, void 0, line, column);
|
|
864
|
-
}
|
|
865
|
-
function countCodePoints(text) {
|
|
866
|
-
let count = 0;
|
|
867
|
-
for (const unused of text) {
|
|
868
|
-
void unused;
|
|
869
|
-
count++;
|
|
870
|
-
}
|
|
871
|
-
return count;
|
|
872
|
-
}
|
|
873
|
-
function utf8Width(codePoint) {
|
|
874
|
-
return codePoint <= 127 ? 1 : codePoint <= 2047 ? 2 : codePoint <= 65535 ? 3 : 4;
|
|
875
|
-
}
|
|
876
|
-
function compactStringBytes(text) {
|
|
877
|
-
let bytes = 2;
|
|
878
|
-
for (const character of text) {
|
|
879
|
-
const point = character.codePointAt(0);
|
|
880
|
-
if (point === 34 || point === 92 || point === 8 || point === 12 || point === 10 || point === 13 || point === 9) bytes += 2;
|
|
881
|
-
else if (point < 32) bytes += 6;
|
|
882
|
-
else bytes += utf8ByteLength(character);
|
|
883
|
-
}
|
|
884
|
-
return bytes;
|
|
885
|
-
}
|
|
886
|
-
function compactScalarBytes(value) {
|
|
887
|
-
if (typeof value === "string") return compactStringBytes(value);
|
|
888
|
-
if (isNumber(value)) return utf8ByteLength(numberText(value));
|
|
889
|
-
return utf8ByteLength(JSON.stringify(value));
|
|
890
|
-
}
|
|
891
|
-
function indentation(line) {
|
|
892
|
-
let index = 0;
|
|
893
|
-
while (line[index] === " ") index++;
|
|
894
|
-
if (line[index] === " ") throw syntax();
|
|
895
|
-
return index;
|
|
896
|
-
}
|
|
897
|
-
function stripComment(text) {
|
|
898
|
-
let single = false;
|
|
899
|
-
let double = false;
|
|
900
|
-
let escaped = false;
|
|
901
|
-
let flowDepth = 0;
|
|
902
|
-
for (let index = 0; index < text.length; index++) {
|
|
903
|
-
const character = text[index];
|
|
904
|
-
if (double) {
|
|
905
|
-
if (escaped) escaped = false;
|
|
906
|
-
else if (character === "\\") escaped = true;
|
|
907
|
-
else if (character === '"') double = false;
|
|
908
|
-
continue;
|
|
909
|
-
}
|
|
910
|
-
if (single) {
|
|
911
|
-
if (character === "'" && text[index + 1] === "'") index++;
|
|
912
|
-
else if (character === "'") single = false;
|
|
913
|
-
continue;
|
|
914
|
-
}
|
|
915
|
-
if (character === '"') double = true;
|
|
916
|
-
else if (character === "'") single = true;
|
|
917
|
-
else if (character === "[" || character === "{") flowDepth++;
|
|
918
|
-
else if (character === "]" || character === "}") flowDepth--;
|
|
919
|
-
else if (character === "#" && (index === 0 || /[ \t\r\n]/u.test(text[index - 1]))) {
|
|
920
|
-
return flowDepth > 0 ? text.trimEnd() : text.slice(0, index).trimEnd();
|
|
921
|
-
}
|
|
922
|
-
}
|
|
923
|
-
return single || double ? text : text.trimEnd();
|
|
924
|
-
}
|
|
925
|
-
function mappingColon(text, flow = false) {
|
|
926
|
-
let single = false;
|
|
927
|
-
let double = false;
|
|
928
|
-
let escaped = false;
|
|
929
|
-
let depth = 0;
|
|
930
|
-
for (let index = 0; index < text.length; index++) {
|
|
931
|
-
const character = text[index];
|
|
932
|
-
if (double) {
|
|
933
|
-
if (escaped) escaped = false;
|
|
934
|
-
else if (character === "\\") escaped = true;
|
|
935
|
-
else if (character === '"') double = false;
|
|
936
|
-
continue;
|
|
937
|
-
}
|
|
938
|
-
if (single) {
|
|
939
|
-
if (character === "'" && text[index + 1] === "'") index++;
|
|
940
|
-
else if (character === "'") single = false;
|
|
941
|
-
continue;
|
|
942
|
-
}
|
|
943
|
-
if (character === '"') double = true;
|
|
944
|
-
else if (character === "'") single = true;
|
|
945
|
-
else if (character === "[" || character === "{") depth++;
|
|
946
|
-
else if (character === "]" || character === "}") depth--;
|
|
947
|
-
else if (character === ":" && depth === 0 && (flow || index + 1 === text.length || /[ \t]/u.test(text[index + 1]))) return index;
|
|
948
|
-
}
|
|
949
|
-
return -1;
|
|
950
|
-
}
|
|
951
|
-
function checkedExponent(text) {
|
|
952
|
-
let index = 0;
|
|
953
|
-
let negative = false;
|
|
954
|
-
if (text[index] === "+" || text[index] === "-") {
|
|
955
|
-
negative = text[index] === "-";
|
|
956
|
-
index++;
|
|
957
|
-
}
|
|
958
|
-
let value = 0;
|
|
959
|
-
for (; index < text.length; index++) {
|
|
960
|
-
const digit = text.charCodeAt(index) - 48;
|
|
961
|
-
if (digit < 0 || digit > 9) throw syntax();
|
|
962
|
-
value = value > 2e9 ? 2000000001 : value * 10 + digit;
|
|
963
|
-
}
|
|
964
|
-
return negative ? -value : value;
|
|
965
|
-
}
|
|
966
|
-
function decimalText(digits, exponent, negative) {
|
|
967
|
-
const sign = negative ? "-" : "";
|
|
968
|
-
const adjusted = exponent + digits.length - 1;
|
|
969
|
-
if (exponent > 0 || adjusted < -6) {
|
|
970
|
-
return `${sign}${digits[0]}${digits.length > 1 ? `.${digits.slice(1)}` : ""}E${adjusted >= 0 ? "+" : ""}${adjusted}`;
|
|
971
|
-
}
|
|
972
|
-
const point = digits.length + exponent;
|
|
973
|
-
if (point <= 0) return `${sign}0.${"0".repeat(-point)}${digits}`;
|
|
974
|
-
return `${sign}${digits.slice(0, point)}${point < digits.length ? `.${digits.slice(point)}` : ""}`;
|
|
975
|
-
}
|
|
976
|
-
function exactSafeIntegral(digits, exponent) {
|
|
977
|
-
if (digits === "0" || exponent < 0) return true;
|
|
978
|
-
const length = digits.length + exponent;
|
|
979
|
-
if (length < 16) return true;
|
|
980
|
-
if (length > 16) return false;
|
|
981
|
-
const boundary = "9007199254740991";
|
|
982
|
-
for (let index = 0; index < digits.length; index++) {
|
|
983
|
-
if (digits[index] < boundary[index]) return true;
|
|
984
|
-
if (digits[index] > boundary[index]) return false;
|
|
985
|
-
}
|
|
986
|
-
for (let index = digits.length; index < boundary.length; index++) if (boundary[index] !== "0") return true;
|
|
987
|
-
return true;
|
|
988
|
-
}
|
|
989
|
-
function parseDecimal(raw) {
|
|
990
|
-
const negative = raw[0] === "-";
|
|
991
|
-
const unsigned = raw[0] === "+" || raw[0] === "-" ? raw.slice(1) : raw;
|
|
992
|
-
const exponentMarker = unsigned.search(/[eE]/u);
|
|
993
|
-
const coefficient = exponentMarker < 0 ? unsigned : unsigned.slice(0, exponentMarker);
|
|
994
|
-
const explicit = exponentMarker < 0 ? 0 : checkedExponent(unsigned.slice(exponentMarker + 1));
|
|
995
|
-
const point = coefficient.indexOf(".");
|
|
996
|
-
const fractional = point < 0 ? 0 : coefficient.length - point - 1;
|
|
997
|
-
let exponent = explicit - fractional;
|
|
998
|
-
let digits = coefficient.replace(".", "").replace(/^0+/u, "") || "0";
|
|
999
|
-
if (digits !== "0") {
|
|
1000
|
-
let trailing = 0;
|
|
1001
|
-
while (digits.length - trailing > 1 && digits[digits.length - trailing - 1] === "0") trailing++;
|
|
1002
|
-
if (trailing > 0) {
|
|
1003
|
-
digits = digits.slice(0, -trailing);
|
|
1004
|
-
exponent += trailing;
|
|
1005
|
-
}
|
|
1006
|
-
}
|
|
1007
|
-
if (exponent < -1147483646 || exponent > 999999999) throw schema("SCHEMA_DECIMAL_RANGE");
|
|
1008
|
-
if (!exactSafeIntegral(digits, exponent)) throw schema("SCHEMA_UNSAFE_INTEGER");
|
|
1009
|
-
const text = decimalText(digits, exponent, negative);
|
|
1010
|
-
const double = Number(`${negative ? "-" : ""}${digits}e${exponent}`);
|
|
1011
|
-
if (!Number.isFinite(double)) throw schema("SCHEMA_NONFINITE_NUMBER");
|
|
1012
|
-
if (Number.isInteger(double) && !Number.isSafeInteger(double)) throw schema("SCHEMA_UNSAFE_INTEGER");
|
|
1013
|
-
return new Decimal(digits, exponent, negative, text, double);
|
|
1014
|
-
}
|
|
1015
|
-
function parseBasedInteger(raw) {
|
|
1016
|
-
const negative = raw[0] === "-";
|
|
1017
|
-
const unsigned = raw[0] === "+" || raw[0] === "-" ? raw.slice(1) : raw;
|
|
1018
|
-
const base = unsigned.startsWith("0x") ? 16 : unsigned.startsWith("0o") ? 8 : 10;
|
|
1019
|
-
const digits = base === 10 ? unsigned : unsigned.slice(2);
|
|
1020
|
-
let value = 0;
|
|
1021
|
-
for (const character of digits) {
|
|
1022
|
-
const digit = Number.parseInt(character, base);
|
|
1023
|
-
if (value > Math.floor((Number.MAX_SAFE_INTEGER - digit) / base)) throw schema("SCHEMA_UNSAFE_INTEGER");
|
|
1024
|
-
value = value * base + digit;
|
|
1025
|
-
}
|
|
1026
|
-
return negative ? -value : value;
|
|
1027
|
-
}
|
|
1028
|
-
function scalarFromPlain(raw, explicitTag) {
|
|
1029
|
-
if (explicitTag === "str") return raw;
|
|
1030
|
-
const nullMatch = /^(?:~|null|Null|NULL)$/u.test(raw);
|
|
1031
|
-
const boolMatch = /^(?:true|True|TRUE|false|False|FALSE)$/u.test(raw);
|
|
1032
|
-
const intMatch = integerPattern.test(raw);
|
|
1033
|
-
const floatMatch = floatPattern.test(raw);
|
|
1034
|
-
if (explicitTag === "null") {
|
|
1035
|
-
if (!nullMatch) throw schema("SCHEMA_TAG_LEXEME_MISMATCH");
|
|
1036
|
-
return null;
|
|
1037
|
-
}
|
|
1038
|
-
if (explicitTag === "bool") {
|
|
1039
|
-
if (!boolMatch) throw schema("SCHEMA_TAG_LEXEME_MISMATCH");
|
|
1040
|
-
return /^true$/iu.test(raw);
|
|
1041
|
-
}
|
|
1042
|
-
if (explicitTag === "int") {
|
|
1043
|
-
if (!intMatch) throw schema("SCHEMA_TAG_LEXEME_MISMATCH");
|
|
1044
|
-
return parseBasedInteger(raw);
|
|
1045
|
-
}
|
|
1046
|
-
if (explicitTag === "float") {
|
|
1047
|
-
if (!(floatMatch || intMatch && /^[+-]?[0-9]+$/u.test(raw))) throw schema("SCHEMA_TAG_LEXEME_MISMATCH");
|
|
1048
|
-
if (/^[+-]?\.(?:inf|Inf|INF|nan|NaN|NAN)$/u.test(raw)) throw schema("SCHEMA_NONFINITE_NUMBER");
|
|
1049
|
-
return parseDecimal(raw);
|
|
1050
|
-
}
|
|
1051
|
-
if (nullMatch) return null;
|
|
1052
|
-
if (boolMatch) return /^true$/iu.test(raw);
|
|
1053
|
-
if (intMatch) return parseBasedInteger(raw);
|
|
1054
|
-
if (floatMatch) {
|
|
1055
|
-
if (/^[+-]?\.(?:inf|Inf|INF|nan|NaN|NAN)$/u.test(raw)) throw schema("SCHEMA_NONFINITE_NUMBER");
|
|
1056
|
-
return parseDecimal(raw);
|
|
1057
|
-
}
|
|
1058
|
-
return raw;
|
|
1059
|
-
}
|
|
1060
|
-
function normalizeTag(raw) {
|
|
1061
|
-
const expanded = raw.startsWith("!!") ? `tag:yaml.org,2002:${raw.slice(2)}` : raw.startsWith("!<") && raw.endsWith(">") ? raw.slice(2, -1) : raw;
|
|
1062
|
-
if (expanded === "!") throw schema("SCHEMA_UNSUPPORTED_TAG");
|
|
1063
|
-
const prefix = "tag:yaml.org,2002:";
|
|
1064
|
-
if (!expanded.startsWith(prefix)) throw schema("SCHEMA_UNSUPPORTED_TAG");
|
|
1065
|
-
const name = expanded.slice(prefix.length);
|
|
1066
|
-
if (!["map", "seq", "str", "null", "bool", "int", "float"].includes(name)) throw schema("SCHEMA_UNSUPPORTED_TAG");
|
|
1067
|
-
return name;
|
|
1068
|
-
}
|
|
1069
|
-
function scanQuotedWhitespace(raw, start, end) {
|
|
1070
|
-
let position = start;
|
|
1071
|
-
let breaks = 0;
|
|
1072
|
-
while (position < end) {
|
|
1073
|
-
const character = raw[position];
|
|
1074
|
-
if (character === "\r" || character === "\n") {
|
|
1075
|
-
breaks++;
|
|
1076
|
-
if (character === "\r" && position + 1 < end && raw[position + 1] === "\n") position++;
|
|
1077
|
-
} else if (character !== " " && character !== " ") break;
|
|
1078
|
-
position++;
|
|
1079
|
-
}
|
|
1080
|
-
return { end: position, breaks };
|
|
1081
|
-
}
|
|
1082
|
-
function decodeDouble(raw) {
|
|
1083
|
-
let result = "";
|
|
1084
|
-
for (let index = 1; index < raw.length - 1; index++) {
|
|
1085
|
-
const character = raw[index];
|
|
1086
|
-
if (" \r\n".includes(character)) {
|
|
1087
|
-
const whitespace = scanQuotedWhitespace(raw, index, raw.length - 1);
|
|
1088
|
-
result += whitespace.breaks === 0 ? raw.slice(index, whitespace.end) : whitespace.breaks === 1 ? " " : "\n".repeat(whitespace.breaks - 1);
|
|
1089
|
-
index = whitespace.end - 1;
|
|
1090
|
-
continue;
|
|
1091
|
-
}
|
|
1092
|
-
if (character !== "\\") {
|
|
1093
|
-
const codePoint2 = raw.codePointAt(index);
|
|
1094
|
-
if (codePoint2 === 0) throw syntax();
|
|
1095
|
-
result += String.fromCodePoint(codePoint2);
|
|
1096
|
-
if (codePoint2 > 65535) index++;
|
|
1097
|
-
continue;
|
|
1098
|
-
}
|
|
1099
|
-
const escape = raw[++index];
|
|
1100
|
-
if (escape === void 0) throw syntax();
|
|
1101
|
-
const simple = {
|
|
1102
|
-
"0": "\0",
|
|
1103
|
-
a: "\x07",
|
|
1104
|
-
b: "\b",
|
|
1105
|
-
t: " ",
|
|
1106
|
-
" ": " ",
|
|
1107
|
-
n: "\n",
|
|
1108
|
-
v: "\v",
|
|
1109
|
-
f: "\f",
|
|
1110
|
-
r: "\r",
|
|
1111
|
-
e: "\x1B",
|
|
1112
|
-
" ": " ",
|
|
1113
|
-
'"': '"',
|
|
1114
|
-
"/": "/",
|
|
1115
|
-
"\\": "\\",
|
|
1116
|
-
N: "\x85",
|
|
1117
|
-
_: "\xA0",
|
|
1118
|
-
L: "\u2028",
|
|
1119
|
-
P: "\u2029"
|
|
1120
|
-
};
|
|
1121
|
-
if (Object.hasOwn(simple, escape)) {
|
|
1122
|
-
result += simple[escape];
|
|
1123
|
-
continue;
|
|
1124
|
-
}
|
|
1125
|
-
if (escape === "\n" || escape === "\r") {
|
|
1126
|
-
const whitespace = scanQuotedWhitespace(raw, index, raw.length - 1);
|
|
1127
|
-
result += "\n".repeat(whitespace.breaks - 1);
|
|
1128
|
-
index = whitespace.end - 1;
|
|
1129
|
-
continue;
|
|
1130
|
-
}
|
|
1131
|
-
const digits = escape === "x" ? 2 : escape === "u" ? 4 : escape === "U" ? 8 : 0;
|
|
1132
|
-
if (digits === 0) throw syntax();
|
|
1133
|
-
const hex = raw.slice(index + 1, index + 1 + digits);
|
|
1134
|
-
if (hex.length !== digits || !/^[0-9a-fA-F]+$/u.test(hex)) throw syntax();
|
|
1135
|
-
let codePoint = Number.parseInt(hex, 16);
|
|
1136
|
-
index += digits;
|
|
1137
|
-
if (escape === "u" && codePoint >= 55296 && codePoint <= 56319) {
|
|
1138
|
-
const next = raw.slice(index + 1, index + 7);
|
|
1139
|
-
if (!/^\\u[0-9a-fA-F]{4}$/u.test(next)) throw syntax();
|
|
1140
|
-
const low = Number.parseInt(next.slice(2), 16);
|
|
1141
|
-
if (low < 56320 || low > 57343) throw syntax();
|
|
1142
|
-
codePoint = 65536 + (codePoint - 55296) * 1024 + low - 56320;
|
|
1143
|
-
index += 6;
|
|
1144
|
-
} else if (codePoint >= 55296 && codePoint <= 57343) throw syntax();
|
|
1145
|
-
if (codePoint > 1114111) throw syntax();
|
|
1146
|
-
result += String.fromCodePoint(codePoint);
|
|
1147
|
-
}
|
|
1148
|
-
if (!wellFormed(result)) throw syntax();
|
|
1149
|
-
return result;
|
|
1150
|
-
}
|
|
1151
|
-
function projectDoubleBytes(raw, start = 0, end = raw.length) {
|
|
1152
|
-
let bytes = 0;
|
|
1153
|
-
for (let index = start + 1; index < end - 1; index++) {
|
|
1154
|
-
const character = raw[index];
|
|
1155
|
-
if (" \r\n".includes(character)) {
|
|
1156
|
-
const whitespace = scanQuotedWhitespace(raw, index, end - 1);
|
|
1157
|
-
bytes += whitespace.breaks === 0 ? whitespace.end - index : Math.max(1, whitespace.breaks - 1);
|
|
1158
|
-
index = whitespace.end - 1;
|
|
1159
|
-
continue;
|
|
1160
|
-
}
|
|
1161
|
-
if (character !== "\\") {
|
|
1162
|
-
const codePoint2 = raw.codePointAt(index);
|
|
1163
|
-
if (codePoint2 === 0) throw syntax();
|
|
1164
|
-
bytes += utf8Width(codePoint2);
|
|
1165
|
-
if (codePoint2 > 65535) index++;
|
|
1166
|
-
continue;
|
|
1167
|
-
}
|
|
1168
|
-
const escape = raw[++index];
|
|
1169
|
-
if (escape === void 0) throw syntax();
|
|
1170
|
-
const simpleWidths = {
|
|
1171
|
-
"0": 1,
|
|
1172
|
-
a: 1,
|
|
1173
|
-
b: 1,
|
|
1174
|
-
t: 1,
|
|
1175
|
-
" ": 1,
|
|
1176
|
-
n: 1,
|
|
1177
|
-
v: 1,
|
|
1178
|
-
f: 1,
|
|
1179
|
-
r: 1,
|
|
1180
|
-
e: 1,
|
|
1181
|
-
" ": 1,
|
|
1182
|
-
'"': 1,
|
|
1183
|
-
"/": 1,
|
|
1184
|
-
"\\": 1,
|
|
1185
|
-
N: 2,
|
|
1186
|
-
_: 2,
|
|
1187
|
-
L: 3,
|
|
1188
|
-
P: 3
|
|
1189
|
-
};
|
|
1190
|
-
if (Object.hasOwn(simpleWidths, escape)) {
|
|
1191
|
-
bytes += simpleWidths[escape];
|
|
1192
|
-
continue;
|
|
1193
|
-
}
|
|
1194
|
-
if (escape === "\n" || escape === "\r") {
|
|
1195
|
-
const whitespace = scanQuotedWhitespace(raw, index, end - 1);
|
|
1196
|
-
bytes += whitespace.breaks - 1;
|
|
1197
|
-
index = whitespace.end - 1;
|
|
1198
|
-
continue;
|
|
1199
|
-
}
|
|
1200
|
-
const digits = escape === "x" ? 2 : escape === "u" ? 4 : escape === "U" ? 8 : 0;
|
|
1201
|
-
if (digits === 0) throw syntax();
|
|
1202
|
-
const hex = raw.slice(index + 1, index + 1 + digits);
|
|
1203
|
-
if (hex.length !== digits || !/^[0-9a-fA-F]+$/u.test(hex)) throw syntax();
|
|
1204
|
-
let codePoint = Number.parseInt(hex, 16);
|
|
1205
|
-
index += digits;
|
|
1206
|
-
if (escape === "u" && codePoint >= 55296 && codePoint <= 56319) {
|
|
1207
|
-
const next = raw.slice(index + 1, index + 7);
|
|
1208
|
-
if (!/^\\u[0-9a-fA-F]{4}$/u.test(next)) throw syntax();
|
|
1209
|
-
const low = Number.parseInt(next.slice(2), 16);
|
|
1210
|
-
if (low < 56320 || low > 57343) throw syntax();
|
|
1211
|
-
codePoint = 65536 + (codePoint - 55296) * 1024 + low - 56320;
|
|
1212
|
-
index += 6;
|
|
1213
|
-
} else if (codePoint >= 55296 && codePoint <= 57343) throw syntax();
|
|
1214
|
-
if (codePoint > 1114111) throw syntax();
|
|
1215
|
-
bytes += utf8Width(codePoint);
|
|
1216
|
-
}
|
|
1217
|
-
return bytes;
|
|
1218
|
-
}
|
|
1219
|
-
function decodeSingle(raw) {
|
|
1220
|
-
let result = "";
|
|
1221
|
-
for (let index = 1; index < raw.length - 1; index++) {
|
|
1222
|
-
const character = raw[index];
|
|
1223
|
-
if (" \r\n".includes(character)) {
|
|
1224
|
-
const whitespace = scanQuotedWhitespace(raw, index, raw.length - 1);
|
|
1225
|
-
result += whitespace.breaks === 0 ? raw.slice(index, whitespace.end) : whitespace.breaks === 1 ? " " : "\n".repeat(whitespace.breaks - 1);
|
|
1226
|
-
index = whitespace.end - 1;
|
|
1227
|
-
} else {
|
|
1228
|
-
result += character;
|
|
1229
|
-
if (character === "'" && raw[index + 1] === "'") index++;
|
|
1230
|
-
}
|
|
1231
|
-
}
|
|
1232
|
-
return result;
|
|
1233
|
-
}
|
|
1234
|
-
function projectSingleBytes(raw, start = 0, end = raw.length) {
|
|
1235
|
-
let bytes = 0;
|
|
1236
|
-
for (let index = start + 1; index < end - 1; index++) {
|
|
1237
|
-
const character = raw[index];
|
|
1238
|
-
if (character === "'" && raw[index + 1] === "'") {
|
|
1239
|
-
bytes++;
|
|
1240
|
-
index++;
|
|
1241
|
-
} else if (" \r\n".includes(character)) {
|
|
1242
|
-
const whitespace = scanQuotedWhitespace(raw, index, end - 1);
|
|
1243
|
-
bytes += whitespace.breaks === 0 ? whitespace.end - index : Math.max(1, whitespace.breaks - 1);
|
|
1244
|
-
index = whitespace.end - 1;
|
|
1245
|
-
} else {
|
|
1246
|
-
const codePoint = raw.codePointAt(index);
|
|
1247
|
-
bytes += utf8Width(codePoint);
|
|
1248
|
-
if (codePoint > 65535) index++;
|
|
1249
|
-
}
|
|
1250
|
-
}
|
|
1251
|
-
return bytes;
|
|
1252
|
-
}
|
|
1253
|
-
function plainBounds(source, start, end) {
|
|
1254
|
-
while (start < end && /\s/u.test(source[start])) start++;
|
|
1255
|
-
while (end > start && /\s/u.test(source[end - 1])) end--;
|
|
1256
|
-
return [start, end];
|
|
1257
|
-
}
|
|
1258
|
-
function projectPlainBytes(source, start, end) {
|
|
1259
|
-
[start, end] = plainBounds(source, start, end);
|
|
1260
|
-
let bytes = 0;
|
|
1261
|
-
for (let index = start; index < end; ) {
|
|
1262
|
-
if (source[index] === "\n") {
|
|
1263
|
-
index++;
|
|
1264
|
-
while (index < end && (source[index] === " " || source[index] === " ")) index++;
|
|
1265
|
-
bytes++;
|
|
1266
|
-
continue;
|
|
1267
|
-
}
|
|
1268
|
-
const codePoint = source.codePointAt(index);
|
|
1269
|
-
bytes += utf8Width(codePoint);
|
|
1270
|
-
index += codePoint > 65535 ? 2 : 1;
|
|
1271
|
-
}
|
|
1272
|
-
return bytes;
|
|
1273
|
-
}
|
|
1274
|
-
function blockPartText(part) {
|
|
1275
|
-
return part.empty ? "" : part.lineText.slice(part.contentIndent);
|
|
1276
|
-
}
|
|
1277
|
-
function blockPartBytes(part) {
|
|
1278
|
-
if (part.empty) return 0;
|
|
1279
|
-
let bytes = 0;
|
|
1280
|
-
for (let index = part.contentIndent; index < part.lineText.length; ) {
|
|
1281
|
-
const codePoint = part.lineText.codePointAt(index);
|
|
1282
|
-
bytes += utf8Width(codePoint);
|
|
1283
|
-
index += codePoint > 65535 ? 2 : 1;
|
|
1284
|
-
}
|
|
1285
|
-
return bytes;
|
|
1286
|
-
}
|
|
1287
|
-
function blockScalarUnchomped(parts, style) {
|
|
1288
|
-
if (style === "literal") {
|
|
1289
|
-
let value2 = parts.map(blockPartText).join("\n");
|
|
1290
|
-
if (parts.at(-1)?.hadBreak) value2 += "\n";
|
|
1291
|
-
return value2;
|
|
1292
|
-
}
|
|
1293
|
-
let value = "";
|
|
1294
|
-
for (let index = 0; index < parts.length; index++) {
|
|
1295
|
-
const current = parts[index];
|
|
1296
|
-
value += blockPartText(current);
|
|
1297
|
-
if (index < parts.length - 1) {
|
|
1298
|
-
const next = parts[index + 1];
|
|
1299
|
-
if (current.empty) value += next.empty ? "\n" : "";
|
|
1300
|
-
else value += next.empty || current.moreIndented || next.moreIndented ? "\n" : " ";
|
|
1301
|
-
} else if (current.hadBreak) value += "\n";
|
|
1302
|
-
}
|
|
1303
|
-
return value;
|
|
1304
|
-
}
|
|
1305
|
-
function projectBlockScalarBytes(parts, style, chomping) {
|
|
1306
|
-
let bytes = 0;
|
|
1307
|
-
let trailingBreaks = 0;
|
|
1308
|
-
const addPart = (part) => {
|
|
1309
|
-
bytes += blockPartBytes(part);
|
|
1310
|
-
if (!part.empty) trailingBreaks = 0;
|
|
1311
|
-
};
|
|
1312
|
-
const addBreak = () => {
|
|
1313
|
-
bytes++;
|
|
1314
|
-
trailingBreaks++;
|
|
1315
|
-
};
|
|
1316
|
-
if (style === "literal") {
|
|
1317
|
-
for (let index = 0; index < parts.length; index++) {
|
|
1318
|
-
if (index > 0) addBreak();
|
|
1319
|
-
addPart(parts[index]);
|
|
1320
|
-
}
|
|
1321
|
-
if (parts.at(-1)?.hadBreak) addBreak();
|
|
1322
|
-
} else {
|
|
1323
|
-
for (let index = 0; index < parts.length; index++) {
|
|
1324
|
-
const current = parts[index];
|
|
1325
|
-
addPart(current);
|
|
1326
|
-
if (index < parts.length - 1) {
|
|
1327
|
-
const next = parts[index + 1];
|
|
1328
|
-
if (current.empty && next.empty || !current.empty && (next.empty || current.moreIndented || next.moreIndented)) addBreak();
|
|
1329
|
-
else if (!current.empty) {
|
|
1330
|
-
bytes++;
|
|
1331
|
-
trailingBreaks = 0;
|
|
1332
|
-
}
|
|
1333
|
-
} else if (current.hadBreak) addBreak();
|
|
1334
|
-
}
|
|
1335
|
-
}
|
|
1336
|
-
if (chomping === "+") return bytes;
|
|
1337
|
-
const hasContent = parts.some((item) => !item.empty);
|
|
1338
|
-
return bytes - trailingBreaks + (chomping === "clip" && hasContent && parts.at(-1)?.hadBreak ? 1 : 0);
|
|
1339
|
-
}
|
|
1340
|
-
function buildBlockScalar(parts, style, chomping) {
|
|
1341
|
-
let value = blockScalarUnchomped(parts, style);
|
|
1342
|
-
const hasContent = parts.some((item) => !item.empty);
|
|
1343
|
-
if (chomping === "clip") value = hasContent && parts.at(-1)?.hadBreak ? `${value.replace(/\n+$/u, "")}
|
|
1344
|
-
` : value.replace(/\n+$/u, "");
|
|
1345
|
-
if (chomping === "-") value = value.replace(/\n+$/u, "");
|
|
1346
|
-
return value;
|
|
1347
|
-
}
|
|
1348
|
-
var FlowParser = class {
|
|
1349
|
-
constructor(source, composer, line) {
|
|
1350
|
-
this.source = source;
|
|
1351
|
-
this.composer = composer;
|
|
1352
|
-
this.line = line;
|
|
1353
|
-
}
|
|
1354
|
-
source;
|
|
1355
|
-
composer;
|
|
1356
|
-
line;
|
|
1357
|
-
#position = 0;
|
|
1358
|
-
parse() {
|
|
1359
|
-
const n0 = this.#node();
|
|
1360
|
-
if (n0 instanceof Promise) {
|
|
1361
|
-
return n0.then((node) => {
|
|
1362
|
-
this.#space();
|
|
1363
|
-
if (this.#position !== this.source.length) throw syntax(this.line, this.#position + 1);
|
|
1364
|
-
return node;
|
|
1365
|
-
});
|
|
1366
|
-
}
|
|
1367
|
-
this.#space();
|
|
1368
|
-
if (this.#position !== this.source.length) throw syntax(this.line, this.#position + 1);
|
|
1369
|
-
return n0;
|
|
1370
|
-
}
|
|
1371
|
-
#node(keyMode = false) {
|
|
1372
|
-
this.#space();
|
|
1373
|
-
const c0 = this.source[this.#position];
|
|
1374
|
-
if (c0 !== "!" && c0 !== "&" && c0 !== "*" && c0 !== void 0) {
|
|
1375
|
-
if (c0 === '"' || c0 === "'") return this.#quoted();
|
|
1376
|
-
if (c0 !== "[" && c0 !== "{") return this.#plain(keyMode);
|
|
1377
|
-
}
|
|
1378
|
-
return this.#nodeSlow(keyMode);
|
|
1379
|
-
}
|
|
1380
|
-
async #nodeSlow(keyMode = false) {
|
|
1381
|
-
let tag;
|
|
1382
|
-
let anchor;
|
|
1383
|
-
while (true) {
|
|
1384
|
-
if (this.source.startsWith("!!", this.#position)) {
|
|
1385
|
-
if (tag !== void 0) throw syntax(this.line, this.#position + 1);
|
|
1386
|
-
const match = /^!![^\s,[\]{}]+/u.exec(this.source.slice(this.#position));
|
|
1387
|
-
if (!match) throw syntax(this.line, this.#position + 1);
|
|
1388
|
-
tag = normalizeTag(match[0]);
|
|
1389
|
-
this.#position += match[0].length;
|
|
1390
|
-
this.#space();
|
|
1391
|
-
} else if (this.source.startsWith("!<", this.#position)) {
|
|
1392
|
-
if (tag !== void 0) throw syntax(this.line, this.#position + 1);
|
|
1393
|
-
const end = this.source.indexOf(">", this.#position + 2);
|
|
1394
|
-
if (end < 0) throw syntax(this.line, this.#position + 1);
|
|
1395
|
-
tag = normalizeTag(this.source.slice(this.#position, end + 1));
|
|
1396
|
-
this.#position = end + 1;
|
|
1397
|
-
this.#space();
|
|
1398
|
-
} else if (this.source[this.#position] === "!") {
|
|
1399
|
-
throw schema("SCHEMA_UNSUPPORTED_TAG", this.line, this.#position + 1);
|
|
1400
|
-
} else if (this.source[this.#position] === "&") {
|
|
1401
|
-
if (anchor !== void 0) throw syntax(this.line, this.#position + 1);
|
|
1402
|
-
const match = /^&([^\s,[\]{}]+)/u.exec(this.source.slice(this.#position));
|
|
1403
|
-
if (!match) throw syntax(this.line, this.#position + 1);
|
|
1404
|
-
anchor = match[1];
|
|
1405
|
-
this.#position += match[0].length;
|
|
1406
|
-
this.#space();
|
|
1407
|
-
} else break;
|
|
1408
|
-
}
|
|
1409
|
-
const record = anchor === void 0 ? void 0 : this.composer.beginAnchor(anchor);
|
|
1410
|
-
let parsed;
|
|
1411
|
-
const character = this.source[this.#position];
|
|
1412
|
-
if (character === "[") parsed = await this.#sequence();
|
|
1413
|
-
else if (character === "{") parsed = await this.#mapping();
|
|
1414
|
-
else if (character === '"' || character === "'") {
|
|
1415
|
-
const q = this.#quoted();
|
|
1416
|
-
parsed = q instanceof Promise ? await q : q;
|
|
1417
|
-
} else if (character === "*") parsed = await this.#alias();
|
|
1418
|
-
else if (character === void 0 && tag !== void 0) {
|
|
1419
|
-
const s = this.composer.scalar("", null);
|
|
1420
|
-
if (s) await s;
|
|
1421
|
-
parsed = { value: null, style: "plain", raw: "" };
|
|
1422
|
-
} else {
|
|
1423
|
-
const p = this.#plain(keyMode);
|
|
1424
|
-
parsed = p instanceof Promise ? await p : p;
|
|
1425
|
-
}
|
|
1426
|
-
parsed = this.composer.applyTag(parsed, tag);
|
|
1427
|
-
if (record) this.composer.completeAnchor(record, parsed.value);
|
|
1428
|
-
return { ...parsed, ...tag === void 0 ? {} : { explicitTag: tag } };
|
|
1429
|
-
}
|
|
1430
|
-
async #sequence() {
|
|
1431
|
-
this.composer.enterCollection();
|
|
1432
|
-
try {
|
|
1433
|
-
this.#position++;
|
|
1434
|
-
{
|
|
1435
|
-
const n = this.composer.node();
|
|
1436
|
-
if (n) await n;
|
|
1437
|
-
}
|
|
1438
|
-
this.composer.collection();
|
|
1439
|
-
const result = [];
|
|
1440
|
-
this.#space();
|
|
1441
|
-
if (this.source[this.#position] === "]") {
|
|
1442
|
-
this.#position++;
|
|
1443
|
-
return { value: result };
|
|
1444
|
-
}
|
|
1445
|
-
while (true) {
|
|
1446
|
-
this.composer.member(result.length + 1);
|
|
1447
|
-
this.composer.member(1);
|
|
1448
|
-
const start = this.#position;
|
|
1449
|
-
const v0 = this.#node();
|
|
1450
|
-
let value = v0 instanceof Promise ? await v0 : v0;
|
|
1451
|
-
this.#space();
|
|
1452
|
-
if (this.source[this.#position] === ":") {
|
|
1453
|
-
if (this.source.slice(start, this.#position).includes("\n")) throw syntax(this.line, this.#position + 1);
|
|
1454
|
-
this.#position++;
|
|
1455
|
-
this.composer.enterCollection();
|
|
1456
|
-
try {
|
|
1457
|
-
const m0 = this.#node();
|
|
1458
|
-
const mapped = m0 instanceof Promise ? await m0 : m0;
|
|
1459
|
-
{
|
|
1460
|
-
const n = this.composer.node();
|
|
1461
|
-
if (n) await n;
|
|
1462
|
-
}
|
|
1463
|
-
this.composer.collection();
|
|
1464
|
-
const pair = object();
|
|
1465
|
-
this.composer.mappingEntry(pair, value, mapped.value, true, true);
|
|
1466
|
-
value = { value: pair };
|
|
1467
|
-
} finally {
|
|
1468
|
-
this.composer.leaveCollection();
|
|
1469
|
-
}
|
|
1470
|
-
}
|
|
1471
|
-
result.push(value.value);
|
|
1472
|
-
this.#space();
|
|
1473
|
-
if (this.source[this.#position] === "]") {
|
|
1474
|
-
this.#position++;
|
|
1475
|
-
return { value: result };
|
|
1476
|
-
}
|
|
1477
|
-
if (this.source[this.#position] !== ",") throw syntax(this.line, this.#position + 1);
|
|
1478
|
-
this.#position++;
|
|
1479
|
-
this.#space();
|
|
1480
|
-
if (this.source[this.#position] === "]") {
|
|
1481
|
-
this.#position++;
|
|
1482
|
-
return { value: result };
|
|
1483
|
-
}
|
|
1484
|
-
}
|
|
1485
|
-
} finally {
|
|
1486
|
-
this.composer.leaveCollection();
|
|
1487
|
-
}
|
|
1488
|
-
}
|
|
1489
|
-
async #mapping() {
|
|
1490
|
-
this.composer.enterCollection();
|
|
1491
|
-
try {
|
|
1492
|
-
this.#position++;
|
|
1493
|
-
{
|
|
1494
|
-
const n = this.composer.node();
|
|
1495
|
-
if (n) await n;
|
|
1496
|
-
}
|
|
1497
|
-
this.composer.collection();
|
|
1498
|
-
const result = object();
|
|
1499
|
-
let members = 0;
|
|
1500
|
-
this.#space();
|
|
1501
|
-
if (this.source[this.#position] === "}") {
|
|
1502
|
-
this.#position++;
|
|
1503
|
-
return { value: result };
|
|
1504
|
-
}
|
|
1505
|
-
while (true) {
|
|
1506
|
-
this.composer.member(++members);
|
|
1507
|
-
const k0 = this.#node(true);
|
|
1508
|
-
const key = k0 instanceof Promise ? await k0 : k0;
|
|
1509
|
-
this.#space();
|
|
1510
|
-
if (this.source[this.#position] !== ":") throw syntax(this.line, this.#position + 1);
|
|
1511
|
-
this.#position++;
|
|
1512
|
-
const v0 = this.#node();
|
|
1513
|
-
const value = v0 instanceof Promise ? await v0 : v0;
|
|
1514
|
-
this.composer.mappingEntry(result, key, value.value, true, true);
|
|
1515
|
-
this.#space();
|
|
1516
|
-
if (this.source[this.#position] === "}") {
|
|
1517
|
-
this.#position++;
|
|
1518
|
-
return { value: result };
|
|
1519
|
-
}
|
|
1520
|
-
if (this.source[this.#position] !== ",") throw syntax(this.line, this.#position + 1);
|
|
1521
|
-
this.#position++;
|
|
1522
|
-
this.#space();
|
|
1523
|
-
if (this.source[this.#position] === "}") {
|
|
1524
|
-
this.#position++;
|
|
1525
|
-
return { value: result };
|
|
1526
|
-
}
|
|
1527
|
-
}
|
|
1528
|
-
} finally {
|
|
1529
|
-
this.composer.leaveCollection();
|
|
1530
|
-
}
|
|
1531
|
-
}
|
|
1532
|
-
#quoted() {
|
|
1533
|
-
const quote = this.source[this.#position];
|
|
1534
|
-
const start = this.#position++;
|
|
1535
|
-
let escaped = false;
|
|
1536
|
-
while (this.#position < this.source.length) {
|
|
1537
|
-
const character = this.source[this.#position++];
|
|
1538
|
-
if (quote === '"') {
|
|
1539
|
-
if (!escaped && character === '"') break;
|
|
1540
|
-
if (!escaped && character === "\\") escaped = true;
|
|
1541
|
-
else escaped = false;
|
|
1542
|
-
} else if (character === "'" && this.source[this.#position] === "'") this.#position++;
|
|
1543
|
-
else if (character === "'") break;
|
|
1544
|
-
}
|
|
1545
|
-
if (this.source[this.#position - 1] !== quote) throw syntax(this.line, start + 1);
|
|
1546
|
-
const projectedBytes = quote === '"' ? projectDoubleBytes(this.source, start, this.#position) : projectSingleBytes(this.source, start, this.#position);
|
|
1547
|
-
this.composer.admitScalar(projectedBytes);
|
|
1548
|
-
const raw = this.source.slice(start, this.#position);
|
|
1549
|
-
const value = quote === '"' ? decodeDouble(raw) : decodeSingle(raw);
|
|
1550
|
-
const style = quote === '"' ? "double" : "single";
|
|
1551
|
-
const s = this.composer.scalar(value, value, true);
|
|
1552
|
-
if (s) return s.then(() => ({ value, style }));
|
|
1553
|
-
return { value, style };
|
|
1554
|
-
}
|
|
1555
|
-
async #alias() {
|
|
1556
|
-
const match = /^\*([^\s,[\]{}]+)/u.exec(this.source.slice(this.#position));
|
|
1557
|
-
if (!match) throw syntax(this.line, this.#position + 1);
|
|
1558
|
-
this.#position += match[0].length;
|
|
1559
|
-
return { value: await this.composer.alias(match[1]) };
|
|
1560
|
-
}
|
|
1561
|
-
#plain(keyMode) {
|
|
1562
|
-
const start = this.#position;
|
|
1563
|
-
let depth = 0;
|
|
1564
|
-
while (this.#position < this.source.length) {
|
|
1565
|
-
const character = this.source[this.#position];
|
|
1566
|
-
if (character === "#" && /[ \t\r\n]/u.test(this.source[this.#position - 1] ?? "")) break;
|
|
1567
|
-
if (character === "[" || character === "{") depth++;
|
|
1568
|
-
if (character === "]" || character === "}") {
|
|
1569
|
-
if (depth === 0) break;
|
|
1570
|
-
depth--;
|
|
1571
|
-
}
|
|
1572
|
-
if (depth === 0 && (character === "," || character === "]" || character === "}")) break;
|
|
1573
|
-
if (depth === 0 && character === ":" && (keyMode || /[\s,\]}]/u.test(this.source[this.#position + 1] ?? ""))) break;
|
|
1574
|
-
this.#position++;
|
|
1575
|
-
}
|
|
1576
|
-
const projectedBytes = projectPlainBytes(this.source, start, this.#position);
|
|
1577
|
-
this.composer.admitScalar(projectedBytes);
|
|
1578
|
-
const raw = this.source.slice(start, this.#position).trim().replace(/\r?\n[ \t]*/gu, " ");
|
|
1579
|
-
if (raw.length === 0) throw syntax(this.line, start + 1);
|
|
1580
|
-
const value = scalarFromPlain(raw);
|
|
1581
|
-
const s = this.composer.scalar(typeof value === "string" ? value : raw, value, true);
|
|
1582
|
-
if (s) return s.then(() => ({ value, style: "plain", raw }));
|
|
1583
|
-
return { value, style: "plain", raw };
|
|
1584
|
-
}
|
|
1585
|
-
#space() {
|
|
1586
|
-
while (this.#position < this.source.length) {
|
|
1587
|
-
const character = this.source[this.#position];
|
|
1588
|
-
if (/[ \t\r\n]/u.test(character)) this.#position++;
|
|
1589
|
-
else if (character === "#") {
|
|
1590
|
-
while (this.#position < this.source.length && this.source[this.#position] !== "\n") this.#position++;
|
|
1591
|
-
} else break;
|
|
1592
|
-
}
|
|
1593
|
-
}
|
|
1594
|
-
};
|
|
1595
|
-
var Composer = class {
|
|
1596
|
-
constructor(work, ledger, futureAnchors) {
|
|
1597
|
-
this.work = work;
|
|
1598
|
-
this.ledger = ledger;
|
|
1599
|
-
this.#futureAnchors = new Set(futureAnchors);
|
|
1600
|
-
}
|
|
1601
|
-
work;
|
|
1602
|
-
ledger;
|
|
1603
|
-
#anchors = /* @__PURE__ */ new Map();
|
|
1604
|
-
#futureAnchors;
|
|
1605
|
-
#collectionDepth = 0;
|
|
1606
|
-
node() {
|
|
1607
|
-
const _p = this.work.chargeSync ? this.work.chargeSync(1) : this.work.charge(1);
|
|
1608
|
-
if (_p) return _p.then(() => {
|
|
1609
|
-
this.work.assertOpen();
|
|
1610
|
-
this.ledger.admitNode();
|
|
1611
|
-
});
|
|
1612
|
-
this.work.assertOpen();
|
|
1613
|
-
this.ledger.admitNode();
|
|
1614
|
-
return void 0;
|
|
1615
|
-
}
|
|
1616
|
-
enterCollection() {
|
|
1617
|
-
this.work.assertOpen();
|
|
1618
|
-
if (this.#collectionDepth >= yqCaps.maxDepth) throw limit("LIMIT_MAX_DEPTH");
|
|
1619
|
-
this.#collectionDepth++;
|
|
1620
|
-
}
|
|
1621
|
-
leaveCollection() {
|
|
1622
|
-
this.#collectionDepth--;
|
|
1623
|
-
}
|
|
1624
|
-
admitScalar(bytes) {
|
|
1625
|
-
this.ledger.admitScalar(bytes);
|
|
1626
|
-
}
|
|
1627
|
-
scalar(text, value = text, admitted = false) {
|
|
1628
|
-
if (text.length <= 256 && this.work.chargeSync) {
|
|
1629
|
-
let ascii = true;
|
|
1630
|
-
for (let i = 0; i < text.length; i++) {
|
|
1631
|
-
if (text.charCodeAt(i) >= 128) {
|
|
1632
|
-
ascii = false;
|
|
1633
|
-
break;
|
|
1634
|
-
}
|
|
1635
|
-
}
|
|
1636
|
-
if (ascii) {
|
|
1637
|
-
const totalUnits = 1 + text.length + (text.length > 0 ? 1 : 0);
|
|
1638
|
-
const _p = this.work.chargeSync(totalUnits);
|
|
1639
|
-
if (_p !== void 0) return _p.then(() => {
|
|
1640
|
-
this.work.assertOpen();
|
|
1641
|
-
this.ledger.admitNode();
|
|
1642
|
-
if (!admitted) this.ledger.admitScalar(text.length);
|
|
1643
|
-
this.ledger.admitValueBytes(compactScalarBytes(value));
|
|
1644
|
-
});
|
|
1645
|
-
this.work.assertOpen();
|
|
1646
|
-
this.ledger.admitNode();
|
|
1647
|
-
if (!admitted) this.ledger.admitScalar(text.length);
|
|
1648
|
-
this.ledger.admitValueBytes(compactScalarBytes(value));
|
|
1649
|
-
return void 0;
|
|
1650
|
-
}
|
|
1651
|
-
}
|
|
1652
|
-
return this.#scalarSlow(text, value, admitted);
|
|
1653
|
-
}
|
|
1654
|
-
async #scalarSlow(text, value = text, admitted = false) {
|
|
1655
|
-
{
|
|
1656
|
-
const _p = this.work.chargeSync ? this.work.chargeSync(1) : this.work.charge(1);
|
|
1657
|
-
if (_p) await _p;
|
|
1658
|
-
}
|
|
1659
|
-
this.work.assertOpen();
|
|
1660
|
-
this.ledger.admitNode();
|
|
1661
|
-
const bytes = utf8ByteLength(text);
|
|
1662
|
-
if (!admitted) this.ledger.admitScalar(bytes);
|
|
1663
|
-
let codePoints = 0;
|
|
1664
|
-
for (const unused of text) {
|
|
1665
|
-
void unused;
|
|
1666
|
-
codePoints++;
|
|
1667
|
-
if (codePoints === 256) {
|
|
1668
|
-
{
|
|
1669
|
-
const _p = this.work.chargeSync ? this.work.chargeSync(codePoints) : this.work.charge(codePoints);
|
|
1670
|
-
if (_p) await _p;
|
|
1671
|
-
}
|
|
1672
|
-
this.work.assertOpen();
|
|
1673
|
-
codePoints = 0;
|
|
1674
|
-
}
|
|
1675
|
-
}
|
|
1676
|
-
if (codePoints > 0) {
|
|
1677
|
-
const _p = this.work.chargeSync ? this.work.chargeSync(codePoints) : this.work.charge(codePoints);
|
|
1678
|
-
if (_p) await _p;
|
|
1679
|
-
}
|
|
1680
|
-
this.work.assertOpen();
|
|
1681
|
-
if (bytes > 0) {
|
|
1682
|
-
const _p = this.work.chargeSync ? this.work.chargeSync(Math.ceil(bytes / 1024)) : this.work.charge(Math.ceil(bytes / 1024));
|
|
1683
|
-
if (_p) await _p;
|
|
1684
|
-
}
|
|
1685
|
-
this.work.assertOpen();
|
|
1686
|
-
this.ledger.admitValueBytes(compactScalarBytes(value));
|
|
1687
|
-
}
|
|
1688
|
-
collection() {
|
|
1689
|
-
this.ledger.admitValueBytes(2);
|
|
1690
|
-
}
|
|
1691
|
-
member(size) {
|
|
1692
|
-
if (size > yqCaps.maxCollectionSize) throw limit("LIMIT_MAX_COLLECTION_SIZE");
|
|
1693
|
-
if (size > 1) this.ledger.admitValueBytes(1);
|
|
1694
|
-
}
|
|
1695
|
-
mappingEntry(target, key, value, implicit, memberAdmitted = false) {
|
|
1696
|
-
if (typeof key.value !== "string") throw schema("SCHEMA_NONSTRING_KEY");
|
|
1697
|
-
if (implicit && countCodePoints(key.value) > 1024) throw syntax();
|
|
1698
|
-
if (key.style === "plain" && key.explicitTag === void 0 && key.value === "<<") throw schema("SCHEMA_PLAIN_MERGE_KEY");
|
|
1699
|
-
if (Object.hasOwn(target, key.value)) throw schema("SCHEMA_DUPLICATE_KEY");
|
|
1700
|
-
if (!memberAdmitted) {
|
|
1701
|
-
if (yqCaps.maxCollectionSize === Infinity) {
|
|
1702
|
-
let hasExisting = false;
|
|
1703
|
-
for (const k in target) {
|
|
1704
|
-
if (Object.hasOwn(target, k)) {
|
|
1705
|
-
hasExisting = true;
|
|
1706
|
-
break;
|
|
1707
|
-
}
|
|
1708
|
-
}
|
|
1709
|
-
if (hasExisting) this.ledger.admitValueBytes(1);
|
|
1710
|
-
} else {
|
|
1711
|
-
this.member(objectKeys(target).length + 1);
|
|
1712
|
-
}
|
|
1713
|
-
}
|
|
1714
|
-
this.ledger.admitValueBytes(1);
|
|
1715
|
-
put(target, key.value, value);
|
|
1716
|
-
}
|
|
1717
|
-
beginAnchor(name) {
|
|
1718
|
-
this.ledger.admitAnchor();
|
|
1719
|
-
this.#futureAnchors.delete(name);
|
|
1720
|
-
const record = { name, pending: true };
|
|
1721
|
-
this.#anchors.set(name, record);
|
|
1722
|
-
return record;
|
|
1723
|
-
}
|
|
1724
|
-
completeAnchor(record, value) {
|
|
1725
|
-
record.pending = false;
|
|
1726
|
-
record.value = value;
|
|
1727
|
-
}
|
|
1728
|
-
async alias(name) {
|
|
1729
|
-
const record = this.#anchors.get(name);
|
|
1730
|
-
if (!record) throw aliasFailure(this.#futureAnchors.has(name) ? "ALIAS_FORWARD" : "ALIAS_UNDEFINED");
|
|
1731
|
-
if (record.pending || record.value === void 0) throw aliasFailure("ALIAS_CURRENT_NODE");
|
|
1732
|
-
return copyAlias(record.value, this.ledger, this.work);
|
|
1733
|
-
}
|
|
1734
|
-
applyTag(node, tag) {
|
|
1735
|
-
if (tag === void 0) return node;
|
|
1736
|
-
const collection = Array.isArray(node.value) ? "seq" : node.value !== null && typeof node.value === "object" && !(node.value instanceof Decimal) ? "map" : "scalar";
|
|
1737
|
-
if (tag === "map" || tag === "seq") {
|
|
1738
|
-
if (collection !== tag) throw schema("SCHEMA_TAG_KIND_MISMATCH");
|
|
1739
|
-
return node;
|
|
1740
|
-
}
|
|
1741
|
-
if (collection !== "scalar") throw schema("SCHEMA_TAG_KIND_MISMATCH");
|
|
1742
|
-
const raw = node.raw ?? (typeof node.value === "string" ? node.value : node.value instanceof Decimal ? node.value.text : String(node.value));
|
|
1743
|
-
const value = scalarFromPlain(raw, tag);
|
|
1744
|
-
return { value, ...node.style === void 0 ? {} : { style: node.style }, explicitTag: tag, ...node.raw === void 0 ? {} : { raw: node.raw } };
|
|
1745
|
-
}
|
|
1746
|
-
};
|
|
1747
|
-
var BlockParser = class {
|
|
1748
|
-
constructor(lines, composer) {
|
|
1749
|
-
this.lines = lines;
|
|
1750
|
-
this.composer = composer;
|
|
1751
|
-
}
|
|
1752
|
-
lines;
|
|
1753
|
-
composer;
|
|
1754
|
-
#index = 0;
|
|
1755
|
-
async parse() {
|
|
1756
|
-
this.#skip();
|
|
1757
|
-
if (this.#index >= this.lines.length) {
|
|
1758
|
-
await this.composer.scalar("", null);
|
|
1759
|
-
return null;
|
|
1760
|
-
}
|
|
1761
|
-
const indent = indentation(this.lines[this.#index].text);
|
|
1762
|
-
const node = await this.#node(indent);
|
|
1763
|
-
this.#skip();
|
|
1764
|
-
if (this.#index < this.lines.length) throw syntax(this.lines[this.#index].number, 1);
|
|
1765
|
-
return node.value;
|
|
1766
|
-
}
|
|
1767
|
-
async #node(indent) {
|
|
1768
|
-
this.#skip();
|
|
1769
|
-
const line = this.lines[this.#index];
|
|
1770
|
-
if (!line) {
|
|
1771
|
-
await this.composer.scalar("", null);
|
|
1772
|
-
return { value: null, style: "plain" };
|
|
1773
|
-
}
|
|
1774
|
-
const actual = indentation(line.text);
|
|
1775
|
-
if (actual !== indent) throw syntax(line.number, actual + 1);
|
|
1776
|
-
const content = stripComment(line.text.slice(indent));
|
|
1777
|
-
if (/^-(?:[ \t]|$)/u.test(content)) return this.#sequence(indent);
|
|
1778
|
-
if (content.startsWith("? ") || mappingColon(content) >= 0) return this.#mapping(indent);
|
|
1779
|
-
this.#index++;
|
|
1780
|
-
return this.#inlineOrBlock(content, indent, line.number);
|
|
1781
|
-
}
|
|
1782
|
-
async #sequence(indent) {
|
|
1783
|
-
this.composer.enterCollection();
|
|
1784
|
-
try {
|
|
1785
|
-
await this.composer.node();
|
|
1786
|
-
this.composer.collection();
|
|
1787
|
-
const result = [];
|
|
1788
|
-
while (this.#index < this.lines.length) {
|
|
1789
|
-
this.#skip();
|
|
1790
|
-
const line = this.lines[this.#index];
|
|
1791
|
-
if (!line || indentation(line.text) !== indent) break;
|
|
1792
|
-
const content = stripComment(line.text.slice(indent));
|
|
1793
|
-
if (!/^-(?:[ \t]|$)/u.test(content)) break;
|
|
1794
|
-
this.composer.member(result.length + 1);
|
|
1795
|
-
this.#index++;
|
|
1796
|
-
const rest = content.slice(1).trimStart();
|
|
1797
|
-
const childIndent = indent + (content.length - rest.length);
|
|
1798
|
-
let item;
|
|
1799
|
-
if (rest.length === 0) {
|
|
1800
|
-
this.#skip();
|
|
1801
|
-
const next = this.lines[this.#index];
|
|
1802
|
-
item = next && indentation(next.text) > indent ? await this.#node(indentation(next.text)) : { value: null, style: "plain" };
|
|
1803
|
-
if (!next || indentation(next.text) <= indent) await this.composer.scalar("", null);
|
|
1804
|
-
} else if (/^-(?:[ \t]|$)/u.test(rest)) {
|
|
1805
|
-
this.lines[this.#index - 1] = { ...line, text: `${" ".repeat(childIndent)}${rest}` };
|
|
1806
|
-
this.#index--;
|
|
1807
|
-
item = await this.#sequence(childIndent);
|
|
1808
|
-
} else if (mappingColon(rest) >= 0) {
|
|
1809
|
-
item = await this.#inlineMappingItem(rest, childIndent, line.number);
|
|
1810
|
-
} else item = await this.#inlineOrBlock(rest, indent, line.number);
|
|
1811
|
-
result.push(item.value);
|
|
1812
|
-
}
|
|
1813
|
-
return { value: result };
|
|
1814
|
-
} finally {
|
|
1815
|
-
this.composer.leaveCollection();
|
|
1816
|
-
}
|
|
1817
|
-
}
|
|
1818
|
-
async #inlineMappingItem(first, indent, lineNumber) {
|
|
1819
|
-
this.composer.enterCollection();
|
|
1820
|
-
try {
|
|
1821
|
-
{
|
|
1822
|
-
const _n = this.composer.node();
|
|
1823
|
-
if (_n) await _n;
|
|
1824
|
-
}
|
|
1825
|
-
this.composer.collection();
|
|
1826
|
-
const result = object();
|
|
1827
|
-
let members = 1;
|
|
1828
|
-
this.composer.member(members);
|
|
1829
|
-
{
|
|
1830
|
-
const _m = this.#mappingLine(result, first, indent, lineNumber, true);
|
|
1831
|
-
if (_m) await _m;
|
|
1832
|
-
}
|
|
1833
|
-
while (this.#index < this.lines.length) {
|
|
1834
|
-
this.#skip();
|
|
1835
|
-
const line = this.lines[this.#index];
|
|
1836
|
-
if (!line || indentation(line.text) !== indent) break;
|
|
1837
|
-
const content = stripComment(line.text.slice(indent));
|
|
1838
|
-
if (mappingColon(content) < 0) break;
|
|
1839
|
-
this.composer.member(++members);
|
|
1840
|
-
this.#index++;
|
|
1841
|
-
{
|
|
1842
|
-
const _m = this.#mappingLine(result, content, indent, line.number, true);
|
|
1843
|
-
if (_m) await _m;
|
|
1844
|
-
}
|
|
1845
|
-
}
|
|
1846
|
-
return { value: result };
|
|
1847
|
-
} finally {
|
|
1848
|
-
this.composer.leaveCollection();
|
|
1849
|
-
}
|
|
1850
|
-
}
|
|
1851
|
-
async #mapping(indent) {
|
|
1852
|
-
this.composer.enterCollection();
|
|
1853
|
-
try {
|
|
1854
|
-
{
|
|
1855
|
-
const _n = this.composer.node();
|
|
1856
|
-
if (_n) await _n;
|
|
1857
|
-
}
|
|
1858
|
-
this.composer.collection();
|
|
1859
|
-
const result = object();
|
|
1860
|
-
let members = 0;
|
|
1861
|
-
while (this.#index < this.lines.length) {
|
|
1862
|
-
this.#skip();
|
|
1863
|
-
const line = this.lines[this.#index];
|
|
1864
|
-
if (!line || indentation(line.text) !== indent) break;
|
|
1865
|
-
const content = stripComment(line.text.slice(indent));
|
|
1866
|
-
if (content.startsWith("? ")) {
|
|
1867
|
-
this.composer.member(++members);
|
|
1868
|
-
this.#index++;
|
|
1869
|
-
const key = await this.#inlineOrBlock(content.slice(2).trimStart(), indent, line.number);
|
|
1870
|
-
this.#skip();
|
|
1871
|
-
const valueLine = this.lines[this.#index];
|
|
1872
|
-
if (!valueLine || indentation(valueLine.text) !== indent || !stripComment(valueLine.text.slice(indent)).startsWith(":")) throw syntax(line.number, 1);
|
|
1873
|
-
this.#index++;
|
|
1874
|
-
const valueText = stripComment(valueLine.text.slice(indent)).slice(1).trimStart();
|
|
1875
|
-
const value = valueText.length > 0 ? await this.#inlineOrBlock(valueText, indent, valueLine.number) : await this.#nestedOrNull(indent);
|
|
1876
|
-
this.composer.mappingEntry(result, key, value.value, false, true);
|
|
1877
|
-
continue;
|
|
1878
|
-
}
|
|
1879
|
-
const colon = mappingColon(content);
|
|
1880
|
-
if (colon < 0) break;
|
|
1881
|
-
this.composer.member(++members);
|
|
1882
|
-
this.#index++;
|
|
1883
|
-
{
|
|
1884
|
-
const _m = this.#mappingLine(result, content, indent, line.number, true);
|
|
1885
|
-
if (_m) await _m;
|
|
1886
|
-
}
|
|
1887
|
-
}
|
|
1888
|
-
return { value: result };
|
|
1889
|
-
} finally {
|
|
1890
|
-
this.composer.leaveCollection();
|
|
1891
|
-
}
|
|
1892
|
-
}
|
|
1893
|
-
#mappingLine(target, content, indent, lineNumber, memberAdmitted) {
|
|
1894
|
-
const colon = mappingColon(content);
|
|
1895
|
-
if (colon < 0) throw syntax(lineNumber, 1);
|
|
1896
|
-
const keyText = content.slice(0, colon).trimEnd();
|
|
1897
|
-
const valueText = content.slice(colon + 1).trimStart();
|
|
1898
|
-
const k0 = this.#inlineOrBlock(keyText, indent, lineNumber);
|
|
1899
|
-
if (k0 instanceof Promise) {
|
|
1900
|
-
return k0.then(async (key) => {
|
|
1901
|
-
const v02 = valueText.length > 0 ? this.#inlineOrBlock(valueText, indent, lineNumber) : this.#nestedOrNull(indent);
|
|
1902
|
-
const value = v02 instanceof Promise ? await v02 : v02;
|
|
1903
|
-
this.composer.mappingEntry(target, key, value.value, true, memberAdmitted);
|
|
1904
|
-
});
|
|
1905
|
-
}
|
|
1906
|
-
const v0 = valueText.length > 0 ? this.#inlineOrBlock(valueText, indent, lineNumber) : this.#nestedOrNull(indent);
|
|
1907
|
-
if (v0 instanceof Promise) {
|
|
1908
|
-
return v0.then((value) => {
|
|
1909
|
-
this.composer.mappingEntry(target, k0, value.value, true, memberAdmitted);
|
|
1910
|
-
});
|
|
1911
|
-
}
|
|
1912
|
-
this.composer.mappingEntry(target, k0, v0.value, true, memberAdmitted);
|
|
1913
|
-
return void 0;
|
|
1914
|
-
}
|
|
1915
|
-
async #nestedOrNull(parentIndent) {
|
|
1916
|
-
this.#skip();
|
|
1917
|
-
const next = this.lines[this.#index];
|
|
1918
|
-
if (next && indentation(next.text) > parentIndent) return this.#node(indentation(next.text));
|
|
1919
|
-
if (next && indentation(next.text) === parentIndent && /^-(?:[ \t]|$)/u.test(stripComment(next.text.slice(parentIndent)))) {
|
|
1920
|
-
return this.#node(parentIndent);
|
|
1921
|
-
}
|
|
1922
|
-
await this.composer.scalar("", null);
|
|
1923
|
-
return { value: null, style: "plain" };
|
|
1924
|
-
}
|
|
1925
|
-
#inlineOrBlock(content, parentIndent, lineNumber) {
|
|
1926
|
-
if (content.length > 0 && content.length <= 256 && this.composer.work.chargeSync) {
|
|
1927
|
-
const c0 = content.charCodeAt(0);
|
|
1928
|
-
if (c0 !== 124 && c0 !== 62 && c0 !== 33 && c0 !== 38 && c0 !== 42 && c0 !== 91 && c0 !== 123 && c0 !== 34 && c0 !== 39) {
|
|
1929
|
-
let simplePlain = true;
|
|
1930
|
-
for (let i = 0; i < content.length; i++) {
|
|
1931
|
-
const ch = content.charCodeAt(i);
|
|
1932
|
-
if (ch === 34 || ch === 39 || ch === 91 || ch === 93 || ch === 123 || ch === 125 || ch === 35) {
|
|
1933
|
-
simplePlain = false;
|
|
1934
|
-
break;
|
|
1935
|
-
}
|
|
1936
|
-
}
|
|
1937
|
-
if (simplePlain) {
|
|
1938
|
-
const p = this.composer.work.chargeSync(content.length);
|
|
1939
|
-
if (p === void 0) {
|
|
1940
|
-
this.composer.work.assertOpen();
|
|
1941
|
-
return new FlowParser(content, this.composer, lineNumber).parse();
|
|
1942
|
-
}
|
|
1943
|
-
return p.then(() => {
|
|
1944
|
-
this.composer.work.assertOpen();
|
|
1945
|
-
return new FlowParser(content, this.composer, lineNumber).parse();
|
|
1946
|
-
});
|
|
1947
|
-
}
|
|
1948
|
-
}
|
|
1949
|
-
}
|
|
1950
|
-
return this.#inlineOrBlockSlow(content, parentIndent, lineNumber);
|
|
1951
|
-
}
|
|
1952
|
-
async #inlineOrBlockSlow(content, parentIndent, lineNumber) {
|
|
1953
|
-
const property = /^(?:(!![^\s]+|!<[^>]+>|!)\s+)?(?:&([^\s]+)\s+)?([|>])([1-9]?[+-]?|[+-]?[1-9]?)$/u.exec(content);
|
|
1954
|
-
if (property) return this.#blockScalar(property, parentIndent, lineNumber);
|
|
1955
|
-
if (/^[|>]/u.test(content)) throw syntax(lineNumber, 1);
|
|
1956
|
-
const fragments = [content];
|
|
1957
|
-
let fragment = content;
|
|
1958
|
-
let single = false;
|
|
1959
|
-
let double = false;
|
|
1960
|
-
let escaped = false;
|
|
1961
|
-
let depth = 0;
|
|
1962
|
-
let negativeDepth = false;
|
|
1963
|
-
let balanced = false;
|
|
1964
|
-
while (true) {
|
|
1965
|
-
let inComment = false;
|
|
1966
|
-
for (let start = 0; start < fragment.length; start += 256) {
|
|
1967
|
-
const end = Math.min(start + 256, fragment.length);
|
|
1968
|
-
{
|
|
1969
|
-
const _p = this.composer.work.chargeSync ? this.composer.work.chargeSync(end - start) : this.composer.work.charge(end - start);
|
|
1970
|
-
if (_p) await _p;
|
|
1971
|
-
}
|
|
1972
|
-
this.composer.work.assertOpen();
|
|
1973
|
-
for (let index = start; index < end; index++) {
|
|
1974
|
-
if (inComment) continue;
|
|
1975
|
-
const character = fragment[index];
|
|
1976
|
-
if (double) {
|
|
1977
|
-
if (escaped) escaped = false;
|
|
1978
|
-
else if (character === "\\") escaped = true;
|
|
1979
|
-
else if (character === '"') double = false;
|
|
1980
|
-
} else if (single) {
|
|
1981
|
-
if (character === "'") single = false;
|
|
1982
|
-
} else if (character === '"') double = true;
|
|
1983
|
-
else if (character === "'") single = true;
|
|
1984
|
-
else if (character === "#" && (index === 0 || ` \r
|
|
1985
|
-
,[]{}"'`.includes(fragment[index - 1]))) inComment = true;
|
|
1986
|
-
else if (character === "[" || character === "{") depth++;
|
|
1987
|
-
else if (character === "]" || character === "}") {
|
|
1988
|
-
depth--;
|
|
1989
|
-
if (depth < 0) negativeDepth = true;
|
|
1990
|
-
}
|
|
1991
|
-
}
|
|
1992
|
-
}
|
|
1993
|
-
balanced = !single && !double && (negativeDepth || depth === 0);
|
|
1994
|
-
if (balanced || this.#index >= this.lines.length) break;
|
|
1995
|
-
const continuation = this.lines[this.#index++].text;
|
|
1996
|
-
fragment = `
|
|
1997
|
-
${single || double ? continuation : continuation.trimStart()}`;
|
|
1998
|
-
fragments.push(fragment);
|
|
1999
|
-
}
|
|
2000
|
-
if (!balanced) throw syntax(lineNumber, 1);
|
|
2001
|
-
return new FlowParser(fragments.join(""), this.composer, lineNumber).parse();
|
|
2002
|
-
}
|
|
2003
|
-
async #blockScalar(match, parentIndent, lineNumber) {
|
|
2004
|
-
const tag = match[1] === void 0 ? void 0 : normalizeTag(match[1]);
|
|
2005
|
-
const anchorName = match[2];
|
|
2006
|
-
const style = match[3] === "|" ? "literal" : "folded";
|
|
2007
|
-
const header = match[4] ?? "";
|
|
2008
|
-
const digitMatch = /[1-9]/u.exec(header);
|
|
2009
|
-
const chomping = header.includes("+") ? "+" : header.includes("-") ? "-" : "clip";
|
|
2010
|
-
let contentIndent = digitMatch ? parentIndent + Number(digitMatch[0]) : -1;
|
|
2011
|
-
if (contentIndent < 0) {
|
|
2012
|
-
for (let cursor = this.#index; cursor < this.lines.length; cursor++) {
|
|
2013
|
-
if (this.lines[cursor].text.trim().length > 0) {
|
|
2014
|
-
contentIndent = Math.max(parentIndent + 1, indentation(this.lines[cursor].text));
|
|
2015
|
-
break;
|
|
2016
|
-
}
|
|
2017
|
-
}
|
|
2018
|
-
if (contentIndent < 0) contentIndent = parentIndent + 1;
|
|
2019
|
-
}
|
|
2020
|
-
const values = [];
|
|
2021
|
-
while (this.#index < this.lines.length) {
|
|
2022
|
-
const line = this.lines[this.#index];
|
|
2023
|
-
const actual = indentation(line.text);
|
|
2024
|
-
if (line.text.trim().length > 0 && actual < contentIndent) break;
|
|
2025
|
-
this.#index++;
|
|
2026
|
-
const empty = line.text.trim().length === 0;
|
|
2027
|
-
values.push({ lineText: line.text, contentIndent, empty, moreIndented: !empty && actual > contentIndent, hadBreak: line.hadBreak });
|
|
2028
|
-
}
|
|
2029
|
-
const projectedBytes = projectBlockScalarBytes(values, style, chomping);
|
|
2030
|
-
this.composer.admitScalar(projectedBytes);
|
|
2031
|
-
const value = buildBlockScalar(values, style, chomping);
|
|
2032
|
-
const record = anchorName === void 0 ? void 0 : this.composer.beginAnchor(anchorName);
|
|
2033
|
-
await this.composer.scalar(value, value, true);
|
|
2034
|
-
let node = { value, style };
|
|
2035
|
-
node = await this.composer.applyTag(node, tag);
|
|
2036
|
-
if (record) this.composer.completeAnchor(record, node.value);
|
|
2037
|
-
void lineNumber;
|
|
2038
|
-
return node;
|
|
2039
|
-
}
|
|
2040
|
-
#skip() {
|
|
2041
|
-
while (this.#index < this.lines.length) {
|
|
2042
|
-
const line = this.lines[this.#index];
|
|
2043
|
-
const indent = indentation(line.text);
|
|
2044
|
-
const content = line.text.slice(indent);
|
|
2045
|
-
if (content.trim().length > 0 && !content.startsWith("#")) return;
|
|
2046
|
-
this.#index++;
|
|
2047
|
-
}
|
|
2048
|
-
}
|
|
2049
|
-
};
|
|
2050
|
-
async function* documents(text, work, maxSourceLines, lineOffset = 0) {
|
|
2051
|
-
let current = [];
|
|
2052
|
-
let explicit = false;
|
|
2053
|
-
let ended = false;
|
|
2054
|
-
let directives = 0;
|
|
2055
|
-
let sawContent = false;
|
|
2056
|
-
const take = (force) => {
|
|
2057
|
-
const document2 = force || sawContent || explicit ? { lines: current, explicit, rawBytes: current.reduce((sum, line) => sum + line.rawBytes, 0) } : void 0;
|
|
2058
|
-
current = [];
|
|
2059
|
-
explicit = false;
|
|
2060
|
-
sawContent = false;
|
|
2061
|
-
directives = 0;
|
|
2062
|
-
return document2;
|
|
2063
|
-
};
|
|
2064
|
-
let start = 0;
|
|
2065
|
-
let count = 0;
|
|
2066
|
-
let scanned = 0;
|
|
2067
|
-
for (let index = 0; index < text.length; index++) {
|
|
2068
|
-
if (++scanned === 256) {
|
|
2069
|
-
const _p = work.chargeSync ? work.chargeSync(scanned) : work.charge(scanned);
|
|
2070
|
-
if (_p) await _p;
|
|
2071
|
-
work.assertOpen();
|
|
2072
|
-
scanned = 0;
|
|
2073
|
-
}
|
|
2074
|
-
const character = text[index];
|
|
2075
|
-
const hadBreak = character === "\r" || character === "\n";
|
|
2076
|
-
if (!hadBreak && index + 1 < text.length) continue;
|
|
2077
|
-
if (++count > maxSourceLines - lineOffset) throw limit("LIMIT_MAX_SOURCE_LINES");
|
|
2078
|
-
work.assertOpen();
|
|
2079
|
-
const rawLine = text.slice(start, hadBreak ? index : index + 1);
|
|
2080
|
-
if (character === "\r" && text[index + 1] === "\n") index++;
|
|
2081
|
-
start = index + 1;
|
|
2082
|
-
const original = { text: rawLine, number: lineOffset + count, rawBytes: utf8ByteLength(rawLine) + (hadBreak ? 1 : 0), hadBreak };
|
|
2083
|
-
let line = original;
|
|
2084
|
-
if (line.number === 1 && line.text.startsWith("\uFEFF")) line = { ...line, text: line.text.slice(1) };
|
|
2085
|
-
if (ended && line.text.startsWith("\uFEFF")) line = { ...line, text: line.text.slice(1) };
|
|
2086
|
-
const trimmed = stripComment(line.text).trim();
|
|
2087
|
-
if (line.text.startsWith("%")) {
|
|
2088
|
-
if (sawContent || explicit || ended) throw structure(line.number, 1);
|
|
2089
|
-
if (trimmed !== "%YAML 1.2" || directives > 0) throw schema("SCHEMA_UNSUPPORTED_DIRECTIVE", line.number, 1);
|
|
2090
|
-
directives++;
|
|
2091
|
-
continue;
|
|
2092
|
-
}
|
|
2093
|
-
if (/^---[ \t]*(?:#.*)?$/u.test(line.text)) {
|
|
2094
|
-
if (sawContent || explicit) {
|
|
2095
|
-
const document2 = take(false);
|
|
2096
|
-
if (document2) yield document2;
|
|
2097
|
-
}
|
|
2098
|
-
explicit = true;
|
|
2099
|
-
ended = false;
|
|
2100
|
-
continue;
|
|
2101
|
-
}
|
|
2102
|
-
if (/^\.\.\.[ \t]*(?:#.*)?$/u.test(line.text)) {
|
|
2103
|
-
if (!sawContent && !explicit) {
|
|
2104
|
-
ended = true;
|
|
2105
|
-
continue;
|
|
2106
|
-
}
|
|
2107
|
-
const document2 = take(true);
|
|
2108
|
-
if (document2) yield document2;
|
|
2109
|
-
ended = true;
|
|
2110
|
-
continue;
|
|
2111
|
-
}
|
|
2112
|
-
if (ended) {
|
|
2113
|
-
if (trimmed === "") continue;
|
|
2114
|
-
ended = false;
|
|
2115
|
-
}
|
|
2116
|
-
if (directives > 0 && !explicit && trimmed !== "") throw structure(line.number, 1);
|
|
2117
|
-
current.push(line);
|
|
2118
|
-
if (trimmed !== "") sawContent = true;
|
|
2119
|
-
}
|
|
2120
|
-
if (scanned > 0) {
|
|
2121
|
-
const _p = work.chargeSync ? work.chargeSync(scanned) : work.charge(scanned);
|
|
2122
|
-
if (_p) await _p;
|
|
2123
|
-
work.assertOpen();
|
|
2124
|
-
}
|
|
2125
|
-
const document = take(false);
|
|
2126
|
-
if (document) yield document;
|
|
2127
|
-
}
|
|
2128
|
-
function futureAnchorNames(lines) {
|
|
2129
|
-
const names = [];
|
|
2130
|
-
for (const line of lines) {
|
|
2131
|
-
if (!line.text.includes("&")) continue;
|
|
2132
|
-
const source = stripComment(line.text);
|
|
2133
|
-
const matcher = /(?:^|[\s[,{}])&([^\s[\],{}]+)/gu;
|
|
2134
|
-
for (const match of source.matchAll(matcher)) names.push(match[1]);
|
|
2135
|
-
}
|
|
2136
|
-
return names;
|
|
2137
|
-
}
|
|
2138
|
-
async function* parseYamlDocuments(text, work, ledger, admittedRawBytes, lineOffset = 0) {
|
|
2139
|
-
if (!wellFormed(text)) throw new YqError("input", "INPUT_INVALID_UTF8", 5);
|
|
2140
|
-
let admitted = false;
|
|
2141
|
-
for await (const document of documents(text, work, ledger.limits.maxSourceLines, lineOffset)) {
|
|
2142
|
-
ledger.beginDocument(admittedRawBytes !== void 0 && !admitted ? admittedRawBytes : document.rawBytes);
|
|
2143
|
-
admitted = true;
|
|
2144
|
-
let singleQuoted = false;
|
|
2145
|
-
let doubleQuoted = false;
|
|
2146
|
-
let escaped = false;
|
|
2147
|
-
for (const line of document.lines) {
|
|
2148
|
-
let codePoints = 0;
|
|
2149
|
-
for (let index = 0; index < line.text.length; index++) {
|
|
2150
|
-
const character = line.text[index];
|
|
2151
|
-
const point = line.text.codePointAt(index);
|
|
2152
|
-
if (doubleQuoted) {
|
|
2153
|
-
if (escaped) escaped = false;
|
|
2154
|
-
else if (character === "\\") escaped = true;
|
|
2155
|
-
else if (character === '"') doubleQuoted = false;
|
|
2156
|
-
if (!(point === 9 || point >= 32)) throw syntax(line.number, index + 1);
|
|
2157
|
-
} else if (singleQuoted) {
|
|
2158
|
-
if (character === "'" && line.text[index + 1] === "'") index++;
|
|
2159
|
-
else if (character === "'") singleQuoted = false;
|
|
2160
|
-
if (!(point === 9 || point >= 32)) throw syntax(line.number, index + 1);
|
|
2161
|
-
} else {
|
|
2162
|
-
if (character === '"') doubleQuoted = true;
|
|
2163
|
-
else if (character === "'") singleQuoted = true;
|
|
2164
|
-
const printable = point === 9 || point >= 32 && point <= 126 || point === 133 || point >= 160 && point <= 55295 || point >= 57344 && point <= 65533 || point >= 65536 && point <= 1114111;
|
|
2165
|
-
if (!printable) throw syntax(line.number, index + 1);
|
|
2166
|
-
if (point === 65279) throw structure(line.number, index + 1);
|
|
2167
|
-
}
|
|
2168
|
-
codePoints++;
|
|
2169
|
-
if (point > 65535) index++;
|
|
2170
|
-
if (codePoints === 256) {
|
|
2171
|
-
await work.charge(codePoints);
|
|
2172
|
-
work.assertOpen();
|
|
2173
|
-
codePoints = 0;
|
|
2174
|
-
}
|
|
2175
|
-
}
|
|
2176
|
-
if (codePoints > 0) await work.charge(codePoints);
|
|
2177
|
-
work.assertOpen();
|
|
2178
|
-
}
|
|
2179
|
-
const composer = new Composer(work, ledger, futureAnchorNames(document.lines));
|
|
2180
|
-
const value = await new BlockParser(document.lines, composer).parse();
|
|
2181
|
-
work.assertOpen();
|
|
2182
|
-
yield value;
|
|
2183
|
-
}
|
|
2184
|
-
}
|
|
2185
|
-
|
|
2186
|
-
// packages/safe-bash-command-yq/src/index.ts
|
|
2187
|
-
var help = "virtual-bash restricted YAML/TOML profile\nusage: yq [eval|e] [OPTION ...] [--] [FILTER [FILE ...]]\n yq [eval|e] --help\n yq [eval|e] --version\noptions:\n -p, --input-format FORMAT FORMAT is yaml (default) or toml\n --input-format=FORMAT same as above\n -o, --output-format FORMAT FORMAT is yaml or json\n --output-format=FORMAT same as above\n -c, --compact-output compact JSON; requires -o json\n -r, --unwrapScalar raw strings; requires -o json\n -h, --help show this help (sole argument)\n --version show profile identity (sole argument)\n";
|
|
2188
|
-
var version = "virtual-bash restricted YAML/TOML profile\n";
|
|
2189
|
-
var diagnosticFallback = "yq: limit: DIAGNOSTIC_TRUNCATED\n";
|
|
2190
|
-
var RawDocumentFramer = class {
|
|
2191
|
-
#ranges = [];
|
|
2192
|
-
#offset = 0;
|
|
2193
|
-
#frameStart = 0;
|
|
2194
|
-
#frameLine = 0;
|
|
2195
|
-
#lineStart = 0;
|
|
2196
|
-
#lineNumber = 0;
|
|
2197
|
-
#line = "";
|
|
2198
|
-
#pendingCr = false;
|
|
2199
|
-
#frameBytes = 0;
|
|
2200
|
-
#lineBytes = 0;
|
|
2201
|
-
#lineCouldBeMarker = true;
|
|
2202
|
-
#markerComment = false;
|
|
2203
|
-
#leadingWhitespace = true;
|
|
2204
|
-
#lineHasContent = false;
|
|
2205
|
-
#bomBytes = 0;
|
|
2206
|
-
#hasContent = false;
|
|
2207
|
-
admit(chunk) {
|
|
2208
|
-
for (const byte of chunk) {
|
|
2209
|
-
this.#offset++;
|
|
2210
|
-
if (this.#pendingCr && byte !== 10) {
|
|
2211
|
-
this.#pendingCr = false;
|
|
2212
|
-
this.#finishLine(this.#offset - 1);
|
|
2213
|
-
}
|
|
2214
|
-
this.#lineBytes++;
|
|
2215
|
-
if (this.#lineBytes > yqCaps.maxDocumentBytes) throw new YqError("limit", "LIMIT_MAX_DOCUMENT_BYTES", 5);
|
|
2216
|
-
if (this.#pendingCr) {
|
|
2217
|
-
this.#pendingCr = false;
|
|
2218
|
-
this.#finishLine(this.#offset);
|
|
2219
|
-
continue;
|
|
2220
|
-
}
|
|
2221
|
-
if (this.#lineStart === this.#frameStart && this.#lineBytes <= 3) {
|
|
2222
|
-
const expected = this.#lineBytes === 1 ? 239 : this.#lineBytes === 2 && this.#bomBytes === 1 ? 187 : this.#lineBytes === 3 && this.#bomBytes === 2 ? 191 : void 0;
|
|
2223
|
-
if (byte === expected) {
|
|
2224
|
-
this.#bomBytes++;
|
|
2225
|
-
continue;
|
|
2226
|
-
}
|
|
2227
|
-
if (this.#bomBytes > 0) {
|
|
2228
|
-
this.#lineCouldBeMarker = false;
|
|
2229
|
-
this.#lineHasContent = true;
|
|
2230
|
-
this.#leadingWhitespace = false;
|
|
2231
|
-
}
|
|
2232
|
-
}
|
|
2233
|
-
if (this.#leadingWhitespace && byte !== 32 && byte !== 9 && byte !== 13 && byte !== 10) {
|
|
2234
|
-
this.#lineHasContent = byte !== 35 && byte !== 37;
|
|
2235
|
-
this.#leadingWhitespace = false;
|
|
2236
|
-
}
|
|
2237
|
-
if (this.#lineCouldBeMarker && byte !== 13 && byte !== 10 && !this.#markerComment) {
|
|
2238
|
-
if (this.#line.length < 3) {
|
|
2239
|
-
if (this.#line.length === 0 ? byte === 45 || byte === 46 : byte === this.#line.charCodeAt(0)) {
|
|
2240
|
-
this.#line += String.fromCharCode(byte);
|
|
2241
|
-
} else {
|
|
2242
|
-
this.#lineCouldBeMarker = false;
|
|
2243
|
-
}
|
|
2244
|
-
} else if (byte === 32 || byte === 9) {
|
|
2245
|
-
if (this.#line.length === 3) this.#line += " ";
|
|
2246
|
-
} else if (byte === 35) {
|
|
2247
|
-
this.#markerComment = true;
|
|
2248
|
-
} else {
|
|
2249
|
-
this.#lineCouldBeMarker = false;
|
|
2250
|
-
}
|
|
2251
|
-
}
|
|
2252
|
-
if (!this.#lineCouldBeMarker && this.#lineBytes > yqCaps.maxDocumentBytes - this.#frameBytes) {
|
|
2253
|
-
throw new YqError("limit", "LIMIT_MAX_DOCUMENT_BYTES", 5);
|
|
2254
|
-
}
|
|
2255
|
-
if (byte === 13) this.#pendingCr = true;
|
|
2256
|
-
else if (byte === 10) this.#finishLine(this.#offset);
|
|
2257
|
-
}
|
|
2258
|
-
}
|
|
2259
|
-
finish(bytes) {
|
|
2260
|
-
if (this.#lineBytes > 0) {
|
|
2261
|
-
this.#pendingCr = false;
|
|
2262
|
-
this.#finishLine(this.#offset);
|
|
2263
|
-
}
|
|
2264
|
-
if (this.#frameStart < this.#offset) this.#ranges.push({ start: this.#frameStart, end: this.#offset, lineOffset: this.#frameLine });
|
|
2265
|
-
return this.#ranges.map((range) => ({
|
|
2266
|
-
bytes: bytes.subarray(range.start, range.end),
|
|
2267
|
-
rawBytes: range.end - range.start,
|
|
2268
|
-
lineOffset: range.lineOffset
|
|
2269
|
-
}));
|
|
2270
|
-
}
|
|
2271
|
-
#finishLine(end) {
|
|
2272
|
-
const marker = this.#lineCouldBeMarker && this.#line.startsWith("---");
|
|
2273
|
-
const endMarker = this.#lineCouldBeMarker && this.#line.startsWith("...");
|
|
2274
|
-
if (marker && this.#hasContent && this.#lineStart > this.#frameStart) {
|
|
2275
|
-
this.#ranges.push({ start: this.#frameStart, end: this.#lineStart, lineOffset: this.#frameLine });
|
|
2276
|
-
this.#frameStart = this.#lineStart;
|
|
2277
|
-
this.#frameLine = this.#lineNumber;
|
|
2278
|
-
this.#frameBytes = this.#lineBytes;
|
|
2279
|
-
this.#hasContent = false;
|
|
2280
|
-
} else {
|
|
2281
|
-
if (this.#lineBytes > yqCaps.maxDocumentBytes - this.#frameBytes) throw new YqError("limit", "LIMIT_MAX_DOCUMENT_BYTES", 5);
|
|
2282
|
-
this.#frameBytes += this.#lineBytes;
|
|
2283
|
-
}
|
|
2284
|
-
if (this.#lineHasContent && !marker && !endMarker) this.#hasContent = true;
|
|
2285
|
-
if (endMarker && this.#frameStart < end) {
|
|
2286
|
-
this.#ranges.push({ start: this.#frameStart, end, lineOffset: this.#frameLine });
|
|
2287
|
-
this.#frameStart = end;
|
|
2288
|
-
this.#frameLine = this.#lineNumber + 1;
|
|
2289
|
-
this.#frameBytes = 0;
|
|
2290
|
-
this.#hasContent = false;
|
|
2291
|
-
}
|
|
2292
|
-
this.#line = "";
|
|
2293
|
-
this.#lineBytes = 0;
|
|
2294
|
-
this.#lineCouldBeMarker = true;
|
|
2295
|
-
this.#markerComment = false;
|
|
2296
|
-
this.#leadingWhitespace = true;
|
|
2297
|
-
this.#lineHasContent = false;
|
|
2298
|
-
this.#bomBytes = 0;
|
|
2299
|
-
this.#lineStart = end;
|
|
2300
|
-
this.#lineNumber++;
|
|
2301
|
-
}
|
|
2302
|
-
};
|
|
2303
|
-
var SinkFailure = class {
|
|
2304
|
-
constructor(reason) {
|
|
2305
|
-
this.reason = reason;
|
|
2306
|
-
}
|
|
2307
|
-
reason;
|
|
2308
|
-
};
|
|
2309
|
-
var InvocationOwner = class {
|
|
2310
|
-
#accepting = true;
|
|
2311
|
-
#callbacks = [];
|
|
2312
|
-
#closePromise;
|
|
2313
|
-
assertOpen(signal) {
|
|
2314
|
-
if (signal.aborted) throw signal.reason;
|
|
2315
|
-
if (!this.#accepting) throw new Error("yq invocation is closed");
|
|
2316
|
-
}
|
|
2317
|
-
register(cleanup) {
|
|
2318
|
-
if (!this.#accepting) throw new Error("yq invocation is closed");
|
|
2319
|
-
if (typeof cleanup !== "function") throw new TypeError("cleanup must be callable");
|
|
2320
|
-
this.#callbacks.push(cleanup);
|
|
2321
|
-
}
|
|
2322
|
-
close() {
|
|
2323
|
-
if (this.#closePromise) return this.#closePromise;
|
|
2324
|
-
this.#accepting = false;
|
|
2325
|
-
this.#closePromise = (async () => {
|
|
2326
|
-
const results = await Promise.allSettled(this.#callbacks.map(async (cleanup) => cleanup()));
|
|
2327
|
-
const failures = results.filter((result) => result.status === "rejected").map((result) => result.reason);
|
|
2328
|
-
if (failures.length === 1) throw failures[0];
|
|
2329
|
-
if (failures.length > 1) throw new AggregateError(failures, "yq invocation cleanup failed");
|
|
2330
|
-
})();
|
|
2331
|
-
void this.#closePromise.catch(() => {
|
|
2332
|
-
});
|
|
2333
|
-
return this.#closePromise;
|
|
2334
|
-
}
|
|
2335
|
-
};
|
|
2336
|
-
function cli(code) {
|
|
2337
|
-
return new YqError("cli", code, 2);
|
|
2338
|
-
}
|
|
2339
|
-
function preflightArguments(context) {
|
|
2340
|
-
const args = context.args;
|
|
2341
|
-
if (args.length > yqCaps.maxArgvEntries) throw cli("CLI_ARGV_ENTRIES_LIMIT");
|
|
2342
|
-
let bytes = 0;
|
|
2343
|
-
for (const argument of args) {
|
|
2344
|
-
if (!wellFormed(argument)) throw cli("CLI_INVALID_UNICODE");
|
|
2345
|
-
const incoming = utf8ByteLength(argument);
|
|
2346
|
-
if (incoming > yqCaps.maxArgvUtf8Bytes - bytes) throw cli("CLI_ARGV_BYTES_LIMIT");
|
|
2347
|
-
bytes += incoming;
|
|
2348
|
-
}
|
|
2349
|
-
const carrier = getCommandArguments(context);
|
|
2350
|
-
bytes = 0;
|
|
2351
|
-
const decoder = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true });
|
|
2352
|
-
for (let index = 0; index < args.length; index++) {
|
|
2353
|
-
const incoming = shellValueByteLength(carrier.values[index]);
|
|
2354
|
-
if (incoming > yqCaps.maxArgvUtf8Bytes - bytes) throw cli("CLI_ARGV_BYTES_LIMIT");
|
|
2355
|
-
bytes += incoming;
|
|
2356
|
-
let decoded;
|
|
2357
|
-
try {
|
|
2358
|
-
decoded = decoder.decode(carrier.bytes(index));
|
|
2359
|
-
} catch {
|
|
2360
|
-
throw cli("CLI_INVALID_UNICODE");
|
|
2361
|
-
}
|
|
2362
|
-
if (decoded !== args[index]) throw cli("CLI_INVALID_UNICODE");
|
|
2363
|
-
}
|
|
2364
|
-
}
|
|
2365
|
-
function isInformationForm(args) {
|
|
2366
|
-
const offset = args[0] === "eval" || args[0] === "e" ? 1 : 0;
|
|
2367
|
-
if (args.length !== offset + 1) return void 0;
|
|
2368
|
-
const token = args[offset];
|
|
2369
|
-
if (token === "-h" || token === "--help") return "help";
|
|
2370
|
-
if (token === "--version") return "version";
|
|
2371
|
-
return void 0;
|
|
2372
|
-
}
|
|
2373
|
-
function parseArguments(args, inputFormat) {
|
|
2374
|
-
let index = args[0] === "eval" || args[0] === "e" ? 1 : 0;
|
|
2375
|
-
if (args[0] === "eval-all" || args[0] === "ea") throw cli("CLI_UNSUPPORTED_COMMAND");
|
|
2376
|
-
let ended = false;
|
|
2377
|
-
let inputFormatSeen = false;
|
|
2378
|
-
let format = "yaml";
|
|
2379
|
-
let explicitJson = false;
|
|
2380
|
-
let formatSeen = false;
|
|
2381
|
-
let compact = false;
|
|
2382
|
-
let compactSeen = false;
|
|
2383
|
-
let raw = false;
|
|
2384
|
-
let rawSeen = false;
|
|
2385
|
-
const operands = [];
|
|
2386
|
-
const refused = /^(?:-s|-n|-p|-i|--slurp|--null-input|--input-format|--yaml-schema|--schema|--json-schema|--failsafe-schema|--inplace|--in-place|--allow-lossy-write|--write|--split-exp|--front-matter|--xml|--properties|--color-output)(?:=.*)?$/u;
|
|
2387
|
-
for (; index < args.length; index++) {
|
|
2388
|
-
const argument = args[index];
|
|
2389
|
-
if (!ended && argument === "--") {
|
|
2390
|
-
ended = true;
|
|
2391
|
-
continue;
|
|
2392
|
-
}
|
|
2393
|
-
if (!ended && (argument === "-p" || argument === "--input-format" || argument.startsWith("--input-format="))) {
|
|
2394
|
-
if (inputFormatSeen) throw cli("CLI_DUPLICATE_OPTION");
|
|
2395
|
-
const value = argument.startsWith("--input-format=") ? argument.slice("--input-format=".length) : args[++index];
|
|
2396
|
-
if (value === void 0 || value === "") throw cli("CLI_MISSING_OPTION_VALUE");
|
|
2397
|
-
if (value !== "yaml" && value !== "toml") throw cli("CLI_INVALID_OPTION_VALUE");
|
|
2398
|
-
inputFormatSeen = true;
|
|
2399
|
-
inputFormat = value;
|
|
2400
|
-
continue;
|
|
2401
|
-
}
|
|
2402
|
-
if (!ended && (argument === "-o" || argument === "--output-format")) {
|
|
2403
|
-
if (formatSeen) throw cli("CLI_DUPLICATE_OPTION");
|
|
2404
|
-
const value = args[++index];
|
|
2405
|
-
if (value === void 0) throw cli("CLI_MISSING_OPTION_VALUE");
|
|
2406
|
-
if (value !== "yaml" && value !== "json") throw cli("CLI_INVALID_OPTION_VALUE");
|
|
2407
|
-
formatSeen = true;
|
|
2408
|
-
format = value;
|
|
2409
|
-
explicitJson = value === "json";
|
|
2410
|
-
continue;
|
|
2411
|
-
}
|
|
2412
|
-
if (!ended && argument.startsWith("--output-format=")) {
|
|
2413
|
-
if (formatSeen) throw cli("CLI_DUPLICATE_OPTION");
|
|
2414
|
-
const value = argument.slice("--output-format=".length);
|
|
2415
|
-
if (value === "") throw cli("CLI_MISSING_OPTION_VALUE");
|
|
2416
|
-
if (value !== "yaml" && value !== "json") throw cli("CLI_INVALID_OPTION_VALUE");
|
|
2417
|
-
formatSeen = true;
|
|
2418
|
-
format = value;
|
|
2419
|
-
explicitJson = value === "json";
|
|
2420
|
-
continue;
|
|
2421
|
-
}
|
|
2422
|
-
if (!ended && (argument === "-c" || argument === "--compact-output")) {
|
|
2423
|
-
if (compactSeen) throw cli("CLI_DUPLICATE_OPTION");
|
|
2424
|
-
compactSeen = true;
|
|
2425
|
-
compact = true;
|
|
2426
|
-
continue;
|
|
2427
|
-
}
|
|
2428
|
-
if (!ended && (argument === "-r" || argument === "--unwrapScalar")) {
|
|
2429
|
-
if (rawSeen) throw cli("CLI_DUPLICATE_OPTION");
|
|
2430
|
-
rawSeen = true;
|
|
2431
|
-
raw = true;
|
|
2432
|
-
continue;
|
|
2433
|
-
}
|
|
2434
|
-
if (!ended && refused.test(argument)) throw cli("CLI_UNSUPPORTED_OPTION");
|
|
2435
|
-
if (!ended && argument.startsWith("-") && argument !== "-") throw cli("CLI_UNKNOWN_OPTION");
|
|
2436
|
-
operands.push(argument);
|
|
2437
|
-
}
|
|
2438
|
-
if ((compact || raw) && !explicitJson) throw cli("CLI_INCOMPATIBLE_OPTIONS");
|
|
2439
|
-
const filter = operands[0] ?? ".";
|
|
2440
|
-
const files = operands.slice(1);
|
|
2441
|
-
let stdinSeen = false;
|
|
2442
|
-
for (const file of files) {
|
|
2443
|
-
if (file === "-") {
|
|
2444
|
-
if (stdinSeen) throw cli("CLI_DUPLICATE_STDIN");
|
|
2445
|
-
stdinSeen = true;
|
|
2446
|
-
} else if (utf8ByteLength(file) > yqCaps.maxVfsOperandPathBytes) throw cli("CLI_VFS_OPERAND_LIMIT");
|
|
2447
|
-
}
|
|
2448
|
-
return { inputFormat, format, explicitJson, compact, raw, filter, files };
|
|
2449
|
-
}
|
|
2450
|
-
function displayedSource(source) {
|
|
2451
|
-
if (source === "<stdin>") return source;
|
|
2452
|
-
const parts = ['"'];
|
|
2453
|
-
let bytes = 2;
|
|
2454
|
-
let truncated = false;
|
|
2455
|
-
for (const character of source) {
|
|
2456
|
-
const encoded = (0, escaping_exports.escapeText)(JSON.stringify(character).slice(1, -1), "diagnostic");
|
|
2457
|
-
const incoming = utf8ByteLength(encoded);
|
|
2458
|
-
if (incoming > yqCaps.maxDisplayedFilenameBytes - bytes) {
|
|
2459
|
-
truncated = true;
|
|
2460
|
-
break;
|
|
2461
|
-
}
|
|
2462
|
-
parts.push(encoded);
|
|
2463
|
-
bytes += incoming;
|
|
2464
|
-
}
|
|
2465
|
-
if (truncated) {
|
|
2466
|
-
while (parts.length > 1 && utf8ByteLength(parts.join("")) + 4 > yqCaps.maxDisplayedFilenameBytes) parts.pop();
|
|
2467
|
-
parts.push("...");
|
|
2468
|
-
}
|
|
2469
|
-
parts.push('"');
|
|
2470
|
-
return parts.join("");
|
|
2471
|
-
}
|
|
2472
|
-
function diagnostic(error) {
|
|
2473
|
-
let location = "";
|
|
2474
|
-
if (error.source !== void 0) {
|
|
2475
|
-
location = ` at ${displayedSource(error.source)}`;
|
|
2476
|
-
if (error.line !== void 0 && error.column !== void 0) location += `:${error.line}:${error.column}`;
|
|
2477
|
-
}
|
|
2478
|
-
return `yq: ${error.category}: ${error.code}${location}
|
|
2479
|
-
`;
|
|
2480
|
-
}
|
|
2481
|
-
function classifyValueFailure(error) {
|
|
2482
|
-
const category = error.code.startsWith("ENCODE_") ? "encode" : "schema";
|
|
2483
|
-
return new YqError(category, error.code, 5);
|
|
2484
|
-
}
|
|
2485
|
-
function withSource(error, source) {
|
|
2486
|
-
if (error.source !== void 0) return error;
|
|
2487
|
-
return new YqError(error.category, error.code, error.status, source, error.line, error.column);
|
|
2488
|
-
}
|
|
2489
|
-
async function collectSource(context, owner, session, sourceName, source, vfs, inputFormat) {
|
|
2490
|
-
let producer;
|
|
2491
|
-
let finished = false;
|
|
2492
|
-
let producerReturn;
|
|
2493
|
-
const closeProducer = () => {
|
|
2494
|
-
if (producerReturn) return producerReturn;
|
|
2495
|
-
if (!producer || finished || !producer.return) return Promise.resolve({ done: true, value: void 0 });
|
|
2496
|
-
producerReturn = Promise.resolve().then(() => producer.return());
|
|
2497
|
-
return producerReturn;
|
|
2498
|
-
};
|
|
2499
|
-
owner.register(async () => {
|
|
2500
|
-
await closeProducer();
|
|
2501
|
-
});
|
|
2502
|
-
let iterator;
|
|
2503
|
-
let returned;
|
|
2504
|
-
owner.register(async () => {
|
|
2505
|
-
if (iterator?.return) {
|
|
2506
|
-
returned ??= Promise.resolve().then(() => iterator.return());
|
|
2507
|
-
await returned;
|
|
2508
|
-
}
|
|
2509
|
-
});
|
|
2510
|
-
iterator = readBytes({ [Symbol.asyncIterator]() {
|
|
2511
|
-
owner.assertOpen(context.signal);
|
|
2512
|
-
producer = source[Symbol.asyncIterator]();
|
|
2513
|
-
return {
|
|
2514
|
-
async next() {
|
|
2515
|
-
owner.assertOpen(context.signal);
|
|
2516
|
-
const next = await producer.next();
|
|
2517
|
-
if (next.done) finished = true;
|
|
2518
|
-
return next;
|
|
2519
|
-
},
|
|
2520
|
-
return: closeProducer
|
|
2521
|
-
};
|
|
2522
|
-
} }, context.signal)[Symbol.asyncIterator]();
|
|
2523
|
-
const chunks = [];
|
|
2524
|
-
const framer = inputFormat === "yaml" ? new RawDocumentFramer() : void 0;
|
|
2525
|
-
let size = 0;
|
|
2526
|
-
let chunksSinceYield = 0;
|
|
2527
|
-
while (true) {
|
|
2528
|
-
let next;
|
|
2529
|
-
try {
|
|
2530
|
-
next = await iterator.next();
|
|
2531
|
-
} catch (failure) {
|
|
2532
|
-
if (context.signal.aborted) throw context.signal.reason;
|
|
2533
|
-
if (vfs && failure instanceof FsError) throw new YqError("vfs", "VFS_INPUT_READ", 2, sourceName);
|
|
2534
|
-
throw failure;
|
|
2535
|
-
}
|
|
2536
|
-
owner.assertOpen(context.signal);
|
|
2537
|
-
if (next.done) break;
|
|
2538
|
-
const chunk = next.value;
|
|
2539
|
-
await session.ownedWork.charge(1);
|
|
2540
|
-
if (++chunksSinceYield === 1024) {
|
|
2541
|
-
await yieldTurn2(context.signal);
|
|
2542
|
-
chunksSinceYield = 0;
|
|
2543
|
-
}
|
|
2544
|
-
owner.assertOpen(context.signal);
|
|
2545
|
-
if (chunk.byteLength === 0) continue;
|
|
2546
|
-
session.ownedWork.admitInputBytes(chunk.byteLength);
|
|
2547
|
-
if (chunk.byteLength > yqCaps.maxInputBytes - size) throw fromJqLimit(new JqLimitError("maxInputBytes"));
|
|
2548
|
-
if (inputFormat === "toml" && chunk.byteLength > yqCaps.maxDocumentBytes - size) throw new YqError("limit", "LIMIT_MAX_DOCUMENT_BYTES", 5);
|
|
2549
|
-
framer?.admit(chunk);
|
|
2550
|
-
const owned = new Uint8Array(chunk);
|
|
2551
|
-
owner.assertOpen(context.signal);
|
|
2552
|
-
chunks.push(owned);
|
|
2553
|
-
size += owned.byteLength;
|
|
2554
|
-
}
|
|
2555
|
-
owner.assertOpen(context.signal);
|
|
2556
|
-
const bytes = new Uint8Array(size);
|
|
2557
|
-
let offset = 0;
|
|
2558
|
-
for (const chunk of chunks) {
|
|
2559
|
-
bytes.set(chunk, offset);
|
|
2560
|
-
offset += chunk.byteLength;
|
|
2561
|
-
}
|
|
2562
|
-
owner.assertOpen(context.signal);
|
|
2563
|
-
return framer ? framer.finish(bytes) : [{ bytes, rawBytes: size, lineOffset: 0 }];
|
|
2564
|
-
}
|
|
2565
|
-
async function sourceFrames(context, owner, session, sourceName, inputFormat) {
|
|
2566
|
-
if (sourceName === "-") return collectSource(context, owner, session, "<stdin>", context.stdin, false, inputFormat);
|
|
2567
|
-
const path = (0, path_exports.pathOf)(context, sourceName);
|
|
2568
|
-
await session.ownedWork.charge();
|
|
2569
|
-
owner.assertOpen(context.signal);
|
|
2570
|
-
let capabilities;
|
|
2571
|
-
try {
|
|
2572
|
-
capabilities = context.fs.capabilitiesFor ? await interruptible(() => context.fs.capabilitiesFor(path, { signal: context.signal }), context.signal) : context.fs.capabilities;
|
|
2573
|
-
} catch (failure) {
|
|
2574
|
-
if (context.signal.aborted) throw context.signal.reason;
|
|
2575
|
-
if (failure instanceof FsError) throw new YqError("vfs", "VFS_INPUT_OPEN", 2, sourceName);
|
|
2576
|
-
throw failure;
|
|
2577
|
-
}
|
|
2578
|
-
owner.assertOpen(context.signal);
|
|
2579
|
-
if (context.fs.readStream && capabilities.streamingRead !== false) {
|
|
2580
|
-
let source;
|
|
2581
|
-
try {
|
|
2582
|
-
source = context.fs.readStream(path, { signal: context.signal });
|
|
2583
|
-
} catch (failure) {
|
|
2584
|
-
if (context.signal.aborted) throw context.signal.reason;
|
|
2585
|
-
if (failure instanceof FsError) throw new YqError("vfs", "VFS_INPUT_OPEN", 2, sourceName);
|
|
2586
|
-
throw failure;
|
|
2587
|
-
}
|
|
2588
|
-
return collectSource(context, owner, session, sourceName, source, true, inputFormat);
|
|
2589
|
-
}
|
|
2590
|
-
let bytes;
|
|
2591
|
-
try {
|
|
2592
|
-
bytes = await context.fs.readFile(path, { signal: context.signal, ...Number.isFinite(inputFormat === "toml" ? yqCaps.maxDocumentBytes : yqCaps.maxInputBytes) ? { maxBytes: inputFormat === "toml" ? yqCaps.maxDocumentBytes : yqCaps.maxInputBytes } : {} });
|
|
2593
|
-
} catch (failure) {
|
|
2594
|
-
if (context.signal.aborted) throw context.signal.reason;
|
|
2595
|
-
if (inputFormat === "toml" && failure instanceof FsError && failure.code === "EFBIG") throw new YqError("limit", "LIMIT_MAX_DOCUMENT_BYTES", 5);
|
|
2596
|
-
if (failure instanceof FsError) throw new YqError("vfs", "VFS_INPUT_READ", 2, sourceName);
|
|
2597
|
-
throw failure;
|
|
2598
|
-
}
|
|
2599
|
-
owner.assertOpen(context.signal);
|
|
2600
|
-
session.ownedWork.admitInputBytes(bytes.byteLength);
|
|
2601
|
-
if (inputFormat === "toml") {
|
|
2602
|
-
if (bytes.byteLength > yqCaps.maxDocumentBytes) throw new YqError("limit", "LIMIT_MAX_DOCUMENT_BYTES", 5);
|
|
2603
|
-
return [{ bytes: new Uint8Array(bytes), rawBytes: bytes.byteLength, lineOffset: 0 }];
|
|
2604
|
-
}
|
|
2605
|
-
const framer = new RawDocumentFramer();
|
|
2606
|
-
framer.admit(bytes);
|
|
2607
|
-
const owned = new Uint8Array(bytes);
|
|
2608
|
-
owner.assertOpen(context.signal);
|
|
2609
|
-
return framer.finish(owned);
|
|
2610
|
-
}
|
|
2611
|
-
function decodeDocument(bytes, inputFormat) {
|
|
2612
|
-
try {
|
|
2613
|
-
return new TextDecoder("utf-8", { fatal: true, ignoreBOM: inputFormat === "toml" }).decode(bytes);
|
|
2614
|
-
} catch {
|
|
2615
|
-
throw new YqError("input", "INPUT_INVALID_UTF8", 5);
|
|
2616
|
-
}
|
|
2617
|
-
}
|
|
2618
|
-
async function writeOperation(operation, bytes, owner, callerSignal) {
|
|
2619
|
-
owner.assertOpen(callerSignal);
|
|
2620
|
-
try {
|
|
2621
|
-
await operation.output.write(bytes);
|
|
2622
|
-
} catch (failure) {
|
|
2623
|
-
throw new SinkFailure(failure);
|
|
2624
|
-
}
|
|
2625
|
-
owner.assertOpen(callerSignal);
|
|
2626
|
-
}
|
|
2627
|
-
async function runCommand(context, owner, inputFormat, limits) {
|
|
2628
|
-
const ledger = new YqLedger(limits);
|
|
2629
|
-
let session;
|
|
2630
|
-
let stdout;
|
|
2631
|
-
let stderr;
|
|
2632
|
-
const stdoutOperation = () => {
|
|
2633
|
-
stdout ??= createOutputOperation({ signal: context.signal, registerCleanup: (cleanup) => owner.register(cleanup) }, context.stdout);
|
|
2634
|
-
return stdout;
|
|
2635
|
-
};
|
|
2636
|
-
const stderrOperation = () => {
|
|
2637
|
-
stderr ??= createOutputOperation({ signal: context.signal, registerCleanup: (cleanup) => owner.register(cleanup) }, context.stderr);
|
|
2638
|
-
return stderr;
|
|
2639
|
-
};
|
|
2640
|
-
const emitDiagnostic = async (error) => {
|
|
2641
|
-
const preferred = encoder.encode(diagnostic(error));
|
|
2642
|
-
const fallback = encoder.encode(diagnosticFallback);
|
|
2643
|
-
const selected = ledger.canAdmitDiagnostic(preferred.byteLength) ? preferred : ledger.canAdmitDiagnostic(fallback.byteLength) ? fallback : void 0;
|
|
2644
|
-
if (!selected) return;
|
|
2645
|
-
ledger.admitDiagnostic(selected.byteLength);
|
|
2646
|
-
session?.ownedWork.admitOutputBytes(selected.byteLength);
|
|
2647
|
-
await writeOperation(stderrOperation(), selected, owner, context.signal);
|
|
2648
|
-
};
|
|
2649
|
-
try {
|
|
2650
|
-
preflightArguments(context);
|
|
2651
|
-
const info = isInformationForm(context.args);
|
|
2652
|
-
if (context.args.some((argument) => argument === "-h" || argument === "--help" || argument === "--version") && info === void 0) {
|
|
2653
|
-
throw cli("CLI_INFO_COMBINATION");
|
|
2654
|
-
}
|
|
2655
|
-
if (info) {
|
|
2656
|
-
const bytes = encoder.encode(info === "help" ? help : version);
|
|
2657
|
-
ledger.admitStdout(bytes.byteLength);
|
|
2658
|
-
await writeOperation(stdoutOperation(), bytes, owner, context.signal);
|
|
2659
|
-
return { exitCode: 0 };
|
|
2660
|
-
}
|
|
2661
|
-
const options = parseArguments(context.args, inputFormat);
|
|
2662
|
-
if (utf8ByteLength(options.filter) > yqCaps.maxQuerySourceBytes) throw new YqError("limit", "LIMIT_MAX_QUERY_SOURCE_BYTES", 5);
|
|
2663
|
-
owner.register(async () => session?.close());
|
|
2664
|
-
session = createYqQuerySession({ signal: context.signal, limits });
|
|
2665
|
-
try {
|
|
2666
|
-
session.compileOnce(options.filter);
|
|
2667
|
-
} catch (failure) {
|
|
2668
|
-
if (failure instanceof JqLimitError) throw fromJqLimit(failure);
|
|
2669
|
-
if (failure instanceof JqError) throw new YqError("query", "QUERY_COMPILE_FAILED", 3);
|
|
2670
|
-
throw failure;
|
|
2671
|
-
}
|
|
2672
|
-
const files = options.files.length > 0 ? options.files : ["-"];
|
|
2673
|
-
let emitted = 0;
|
|
2674
|
-
for (const file of files) {
|
|
2675
|
-
const sourceName = file === "-" ? "<stdin>" : file;
|
|
2676
|
-
let frames;
|
|
2677
|
-
try {
|
|
2678
|
-
frames = await sourceFrames(context, owner, session, file, options.inputFormat);
|
|
2679
|
-
} catch (failure) {
|
|
2680
|
-
throw failure instanceof YqError ? withSource(failure, sourceName) : failure;
|
|
2681
|
-
}
|
|
2682
|
-
owner.assertOpen(context.signal);
|
|
2683
|
-
for (const frame of frames) {
|
|
2684
|
-
ledger.admitDocumentBytes(frame.rawBytes);
|
|
2685
|
-
let input;
|
|
2686
|
-
try {
|
|
2687
|
-
input = decodeDocument(frame.bytes, options.inputFormat);
|
|
2688
|
-
} catch (failure) {
|
|
2689
|
-
throw failure instanceof YqError ? withSource(failure, sourceName) : failure;
|
|
2690
|
-
}
|
|
2691
|
-
owner.assertOpen(context.signal);
|
|
2692
|
-
try {
|
|
2693
|
-
const documents2 = options.inputFormat === "toml" ? [await parseTomlDocument(input, session.ownedWork, ledger, frame.rawBytes)] : parseYamlDocuments(input, session.ownedWork, ledger, frame.rawBytes, frame.lineOffset);
|
|
2694
|
-
for await (const document of documents2) {
|
|
2695
|
-
owner.assertOpen(context.signal);
|
|
2696
|
-
try {
|
|
2697
|
-
await session.ownedWork.measure(document);
|
|
2698
|
-
} catch (failure) {
|
|
2699
|
-
if (failure instanceof JqLimitError) throw fromJqLimit(failure);
|
|
2700
|
-
if (failure instanceof YqValueFailure) throw classifyValueFailure(failure);
|
|
2701
|
-
throw failure;
|
|
2702
|
-
}
|
|
2703
|
-
owner.assertOpen(context.signal);
|
|
2704
|
-
const iterator = session.run(document);
|
|
2705
|
-
const firstBatchedResult = emitted + 2;
|
|
2706
|
-
let outBatch;
|
|
2707
|
-
let outBatchUsed = 0;
|
|
2708
|
-
const flushOutBatch = async () => {
|
|
2709
|
-
if (outBatchUsed > 0) {
|
|
2710
|
-
const slice = outBatch.subarray(0, outBatchUsed);
|
|
2711
|
-
outBatchUsed = 0;
|
|
2712
|
-
await writeOperation(stdoutOperation(), slice, owner, context.signal);
|
|
2713
|
-
}
|
|
2714
|
-
};
|
|
2715
|
-
try {
|
|
2716
|
-
while (true) {
|
|
2717
|
-
let next;
|
|
2718
|
-
try {
|
|
2719
|
-
next = await iterator.next();
|
|
2720
|
-
} catch (failure) {
|
|
2721
|
-
await flushOutBatch();
|
|
2722
|
-
if (context.signal.aborted) throw context.signal.reason;
|
|
2723
|
-
if (failure instanceof JqLimitError) throw fromJqLimit(failure);
|
|
2724
|
-
if (failure instanceof JqError) throw new YqError("query", "QUERY_RUNTIME_FAILED", 5, sourceName);
|
|
2725
|
-
throw failure;
|
|
2726
|
-
}
|
|
2727
|
-
owner.assertOpen(context.signal);
|
|
2728
|
-
if (next.done) break;
|
|
2729
|
-
try {
|
|
2730
|
-
const m = session.ownedWork.measureSync ? session.ownedWork.measureSync(next.value) : session.ownedWork.measure(next.value);
|
|
2731
|
-
if (m instanceof Promise) await m;
|
|
2732
|
-
} catch (failure) {
|
|
2733
|
-
await flushOutBatch();
|
|
2734
|
-
if (failure instanceof JqLimitError) throw fromJqLimit(failure);
|
|
2735
|
-
if (failure instanceof YqValueFailure) throw classifyValueFailure(failure);
|
|
2736
|
-
throw failure;
|
|
2737
|
-
}
|
|
2738
|
-
owner.assertOpen(context.signal);
|
|
2739
|
-
session.ownedWork.admitResult();
|
|
2740
|
-
const separator = emitted === 0 || options.format === "json" ? "" : "---\n";
|
|
2741
|
-
const suffixBytes = utf8ByteLength(separator) + 1;
|
|
2742
|
-
const remaining = yqCaps.stdoutCapBytes - ledger.stdoutBytes;
|
|
2743
|
-
if (suffixBytes > remaining) {
|
|
2744
|
-
await flushOutBatch();
|
|
2745
|
-
throw new YqError("limit", "LIMIT_MAX_OUTPUT_BYTES", 5, sourceName);
|
|
2746
|
-
}
|
|
2747
|
-
let encoded;
|
|
2748
|
-
try {
|
|
2749
|
-
if (options.format === "yaml") {
|
|
2750
|
-
const e = encodeYaml(next.value, session.ownedWork, remaining - suffixBytes);
|
|
2751
|
-
encoded = e instanceof Promise ? await e : e;
|
|
2752
|
-
} else if (options.raw && typeof next.value === "string") {
|
|
2753
|
-
encoded = await encodeRaw(next.value, session.ownedWork, remaining - 1);
|
|
2754
|
-
} else {
|
|
2755
|
-
encoded = await encodeJson(next.value, session.ownedWork, !options.compact, remaining - 1);
|
|
2756
|
-
}
|
|
2757
|
-
} catch (failure) {
|
|
2758
|
-
await flushOutBatch();
|
|
2759
|
-
if (failure instanceof JqLimitError) throw fromJqLimit(failure);
|
|
2760
|
-
if (failure instanceof YqValueFailure) throw classifyValueFailure(failure);
|
|
2761
|
-
throw failure;
|
|
2762
|
-
}
|
|
2763
|
-
owner.assertOpen(context.signal);
|
|
2764
|
-
const encodedBytes = utf8ByteLength(encoded);
|
|
2765
|
-
const outputBytes = encodedBytes + suffixBytes;
|
|
2766
|
-
try {
|
|
2767
|
-
ledger.admitStdout(outputBytes);
|
|
2768
|
-
session.ownedWork.admitOutputBytes(outputBytes);
|
|
2769
|
-
} catch (failure) {
|
|
2770
|
-
await flushOutBatch();
|
|
2771
|
-
throw failure;
|
|
2772
|
-
}
|
|
2773
|
-
owner.assertOpen(context.signal);
|
|
2774
|
-
if (emitted < firstBatchedResult || outputBytes >= 8192) {
|
|
2775
|
-
await flushOutBatch();
|
|
2776
|
-
const output = new Uint8Array(outputBytes);
|
|
2777
|
-
let offset = 0;
|
|
2778
|
-
if (separator !== "") offset += encoder.encodeInto(separator, output).written;
|
|
2779
|
-
offset += encoder.encodeInto(encoded, output.subarray(offset)).written;
|
|
2780
|
-
output[offset] = 10;
|
|
2781
|
-
owner.assertOpen(context.signal);
|
|
2782
|
-
await writeOperation(stdoutOperation(), output, owner, context.signal);
|
|
2783
|
-
} else {
|
|
2784
|
-
const batch = outBatch ??= new Uint8Array(16384);
|
|
2785
|
-
if (outBatchUsed + outputBytes > batch.byteLength) await flushOutBatch();
|
|
2786
|
-
if (separator !== "") outBatchUsed += encoder.encodeInto(separator, batch.subarray(outBatchUsed)).written;
|
|
2787
|
-
outBatchUsed += encoder.encodeInto(encoded, batch.subarray(outBatchUsed)).written;
|
|
2788
|
-
batch[outBatchUsed++] = 10;
|
|
2789
|
-
}
|
|
2790
|
-
emitted++;
|
|
2791
|
-
}
|
|
2792
|
-
await flushOutBatch();
|
|
2793
|
-
} finally {
|
|
2794
|
-
outBatchUsed = 0;
|
|
2795
|
-
await iterator.return(void 0);
|
|
2796
|
-
owner.assertOpen(context.signal);
|
|
2797
|
-
}
|
|
2798
|
-
}
|
|
2799
|
-
} catch (failure) {
|
|
2800
|
-
throw failure instanceof YqError ? withSource(failure, sourceName) : failure;
|
|
2801
|
-
}
|
|
2802
|
-
}
|
|
2803
|
-
}
|
|
2804
|
-
return { exitCode: 0 };
|
|
2805
|
-
} catch (failure) {
|
|
2806
|
-
if (context.signal.aborted) throw context.signal.reason;
|
|
2807
|
-
if (failure instanceof SinkFailure) throw failure.reason;
|
|
2808
|
-
let normal;
|
|
2809
|
-
if (failure instanceof YqError) normal = failure;
|
|
2810
|
-
else if (failure instanceof JqLimitError) normal = fromJqLimit(failure);
|
|
2811
|
-
else if (failure instanceof YqValueFailure) normal = classifyValueFailure(failure);
|
|
2812
|
-
if (!normal) throw failure;
|
|
2813
|
-
await emitDiagnostic(normal);
|
|
2814
|
-
return { exitCode: normal.status };
|
|
2815
|
-
}
|
|
2816
|
-
}
|
|
2817
|
-
async function execute(context, inputFormat, limits) {
|
|
2818
|
-
const owner = new InvocationOwner();
|
|
2819
|
-
context.registerCleanup?.(() => owner.close());
|
|
2820
|
-
let result;
|
|
2821
|
-
let primary;
|
|
2822
|
-
let hasPrimary = false;
|
|
2823
|
-
try {
|
|
2824
|
-
result = await runCommand(context, owner, inputFormat, limits);
|
|
2825
|
-
} catch (failure) {
|
|
2826
|
-
primary = failure;
|
|
2827
|
-
hasPrimary = true;
|
|
2828
|
-
}
|
|
2829
|
-
let cleanup;
|
|
2830
|
-
let hasCleanup = false;
|
|
2831
|
-
try {
|
|
2832
|
-
await owner.close();
|
|
2833
|
-
} catch (failure) {
|
|
2834
|
-
cleanup = failure;
|
|
2835
|
-
hasCleanup = true;
|
|
2836
|
-
}
|
|
2837
|
-
if (context.signal.aborted) throw context.signal.reason;
|
|
2838
|
-
if (hasPrimary) throw primary;
|
|
2839
|
-
if (hasCleanup) throw cleanup;
|
|
2840
|
-
return result;
|
|
2841
|
-
}
|
|
2842
|
-
function admittedOptions(options) {
|
|
2843
|
-
if (typeof options !== "object" || options === null) throw new TypeError("options must be an object");
|
|
2844
|
-
if (Object.keys(options).some((key) => key !== "replace" && key !== "inputFormat" && key !== "limits")) throw new TypeError("unsupported yq option");
|
|
2845
|
-
const { replace = false, inputFormat = "yaml" } = options;
|
|
2846
|
-
if (typeof replace !== "boolean") throw new TypeError("replace must be a boolean");
|
|
2847
|
-
if (inputFormat !== "yaml" && inputFormat !== "toml") throw new TypeError("inputFormat must be yaml or toml");
|
|
2848
|
-
return { replace, inputFormat, limits: resolveYqLimits(options.limits) };
|
|
2849
|
-
}
|
|
2850
|
-
function createYqCommand(options = {}) {
|
|
2851
|
-
const { inputFormat, limits } = admittedOptions(options);
|
|
2852
|
-
return Object.freeze({
|
|
2853
|
-
name: "yq",
|
|
2854
|
-
runtimeIdentity: commandRuntimeIdentity,
|
|
2855
|
-
description: "Bounded restricted YAML/TOML query and formatter",
|
|
2856
|
-
execute: (context) => execute(context, inputFormat, limits)
|
|
2857
|
-
});
|
|
2858
|
-
}
|
|
2859
|
-
function createYqCommands(options = {}) {
|
|
2860
|
-
return Object.freeze([createYqCommand(options)]);
|
|
2861
|
-
}
|
|
2862
|
-
|
|
2863
|
-
// packages/safe-bash/src/commands/yq/index.ts
|
|
2864
|
-
function isDefaultYqOptions(options) {
|
|
2865
|
-
return options?.limits === void 0 && (options?.inputFormat === void 0 || options.inputFormat === "yaml");
|
|
2866
|
-
}
|
|
2867
|
-
function createYqCommand2(options = {}) {
|
|
2868
|
-
const def = createYqCommand(options);
|
|
2869
|
-
if (isDefaultYqOptions(options)) builtInDirectContextExecutors.add(def.execute);
|
|
2870
|
-
return def;
|
|
2871
|
-
}
|
|
2872
|
-
function createYqCommands2(options = {}) {
|
|
2873
|
-
const defs = createYqCommands(options);
|
|
2874
|
-
if (isDefaultYqOptions(options)) {
|
|
2875
|
-
for (let i = 0; i < defs.length; i++) builtInDirectContextExecutors.add(defs[i].execute);
|
|
2876
|
-
}
|
|
2877
|
-
return defs;
|
|
2878
|
-
}
|
|
2879
|
-
function yqCommands(options = {}) {
|
|
2880
|
-
const commands = createYqCommands2(options);
|
|
2881
|
-
const replace = options.replace ?? false;
|
|
2882
|
-
return {
|
|
2883
|
-
name: "yq-commands",
|
|
2884
|
-
setup(host) {
|
|
2885
|
-
if (!replace) {
|
|
2886
|
-
for (const cmd of commands) {
|
|
2887
|
-
if (host.commands.has(cmd.name)) throw new Error(`Command already registered: ${cmd.name}`);
|
|
2888
|
-
}
|
|
2889
|
-
}
|
|
2890
|
-
for (const cmd of commands) host.commands.register(cmd, { replace });
|
|
2891
|
-
}
|
|
2892
|
-
};
|
|
2893
|
-
}
|
|
2894
|
-
var syncYqDecoder = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true });
|
|
2895
|
-
function parseSimpleYamlScalar(raw) {
|
|
2896
|
-
const s = raw.trim();
|
|
2897
|
-
if (s === "" || s === "null" || s === "~" || s === "Null" || s === "NULL") return null;
|
|
2898
|
-
if (s === "true" || s === "True" || s === "TRUE") return true;
|
|
2899
|
-
if (s === "false" || s === "False" || s === "FALSE") return false;
|
|
2900
|
-
if (/^[+-]?[0-9]+$/.test(s)) {
|
|
2901
|
-
const n = Number(s);
|
|
2902
|
-
if (Number.isSafeInteger(n)) return n;
|
|
2903
|
-
}
|
|
2904
|
-
if (/^[+-]?(?:[0-9]+\.[0-9]+|\.[0-9]+)$/.test(s)) {
|
|
2905
|
-
const n = Number(s);
|
|
2906
|
-
if (Number.isFinite(n)) return n;
|
|
2907
|
-
}
|
|
2908
|
-
if (s.startsWith('"') && s.endsWith('"') || s.startsWith("'") && s.endsWith("'")) {
|
|
2909
|
-
if (s.startsWith('"')) {
|
|
2910
|
-
try {
|
|
2911
|
-
return JSON.parse(s);
|
|
2912
|
-
} catch {
|
|
2913
|
-
return void 0;
|
|
2914
|
-
}
|
|
2915
|
-
}
|
|
2916
|
-
return s.slice(1, -1).replaceAll("''", "'");
|
|
2917
|
-
}
|
|
2918
|
-
if (/[\[\]{}&*!|>%@`]/.test(s)) return void 0;
|
|
2919
|
-
return s;
|
|
2920
|
-
}
|
|
2921
|
-
function parseSimpleYamlOrToml(text, format) {
|
|
2922
|
-
for (const line of text.split("\n")) {
|
|
2923
|
-
if (line.includes("#") && (line.includes('"') || line.includes("'"))) return void 0;
|
|
2924
|
-
}
|
|
2925
|
-
const trimmed = text.trim();
|
|
2926
|
-
if (!trimmed) return void 0;
|
|
2927
|
-
if (format === "yaml" && (trimmed.startsWith("{") || trimmed.startsWith("["))) {
|
|
2928
|
-
try {
|
|
2929
|
-
return JSON.parse(trimmed);
|
|
2930
|
-
} catch {
|
|
2931
|
-
}
|
|
2932
|
-
}
|
|
2933
|
-
if (format === "toml") {
|
|
2934
|
-
const root = {};
|
|
2935
|
-
let cur = root;
|
|
2936
|
-
for (const rawLine of text.split(/\r?\n/)) {
|
|
2937
|
-
const line = rawLine.replace(/#.*$/, "").trim();
|
|
2938
|
-
if (!line) continue;
|
|
2939
|
-
if (line.startsWith("[[")) return void 0;
|
|
2940
|
-
if (line.startsWith("[") && line.endsWith("]")) {
|
|
2941
|
-
const sec = line.slice(1, -1).trim();
|
|
2942
|
-
if (!/^[A-Za-z0-9_.-]+$/.test(sec)) return void 0;
|
|
2943
|
-
cur = root;
|
|
2944
|
-
for (const part of sec.split(".")) {
|
|
2945
|
-
if (typeof cur[part] !== "object" || cur[part] === null || Array.isArray(cur[part])) cur[part] = {};
|
|
2946
|
-
cur = cur[part];
|
|
2947
|
-
}
|
|
2948
|
-
continue;
|
|
2949
|
-
}
|
|
2950
|
-
const eq = line.indexOf("=");
|
|
2951
|
-
if (eq <= 0) return void 0;
|
|
2952
|
-
const k = line.slice(0, eq).trim();
|
|
2953
|
-
const vRaw = line.slice(eq + 1).trim();
|
|
2954
|
-
if (!/^[A-Za-z0-9_-]+$/.test(k)) return void 0;
|
|
2955
|
-
const v = parseSimpleYamlScalar(vRaw);
|
|
2956
|
-
if (v === void 0) return void 0;
|
|
2957
|
-
cur[k] = v;
|
|
2958
|
-
}
|
|
2959
|
-
return root;
|
|
2960
|
-
}
|
|
2961
|
-
const lines = [];
|
|
2962
|
-
for (const rawLine of text.split(/\r?\n/)) {
|
|
2963
|
-
if (rawLine.includes(" ")) return void 0;
|
|
2964
|
-
const noComment = rawLine.replace(/(^|\s)#.*$/, "");
|
|
2965
|
-
const t = noComment.trim();
|
|
2966
|
-
if (!t || t === "---" || t === "...") continue;
|
|
2967
|
-
let indent = 0;
|
|
2968
|
-
while (indent < noComment.length && noComment[indent] === " ") indent++;
|
|
2969
|
-
lines.push({ indent, text: t });
|
|
2970
|
-
}
|
|
2971
|
-
if (lines.length === 0) return null;
|
|
2972
|
-
let idx = 0;
|
|
2973
|
-
function parseBlock(baseIndent) {
|
|
2974
|
-
if (idx >= lines.length) return null;
|
|
2975
|
-
if (lines[idx].text.startsWith("- ") || lines[idx].text === "-") {
|
|
2976
|
-
const arr = [];
|
|
2977
|
-
while (idx < lines.length && lines[idx].indent === baseIndent) {
|
|
2978
|
-
const l = lines[idx].text;
|
|
2979
|
-
if (!l.startsWith("-") || l.length > 1 && l[1] !== " ") return void 0;
|
|
2980
|
-
const rest = l.slice(1).trim();
|
|
2981
|
-
idx++;
|
|
2982
|
-
if (!rest) {
|
|
2983
|
-
if (idx < lines.length && lines[idx].indent > baseIndent) {
|
|
2984
|
-
const sub = parseBlock(lines[idx].indent);
|
|
2985
|
-
if (sub === void 0) return void 0;
|
|
2986
|
-
arr.push(sub);
|
|
2987
|
-
} else arr.push(null);
|
|
2988
|
-
} else if (rest.includes(": ") || rest.endsWith(":")) {
|
|
2989
|
-
const colon = rest.indexOf(":");
|
|
2990
|
-
const key = rest.slice(0, colon).trim();
|
|
2991
|
-
const valRest = rest.slice(colon + 1).trim();
|
|
2992
|
-
if (!/^[A-Za-z0-9_.-]+$/.test(key)) return void 0;
|
|
2993
|
-
const itemObj = {};
|
|
2994
|
-
if (!valRest) {
|
|
2995
|
-
if (idx < lines.length && lines[idx].indent > baseIndent + 2) {
|
|
2996
|
-
const sub = parseBlock(lines[idx].indent);
|
|
2997
|
-
if (sub === void 0) return void 0;
|
|
2998
|
-
itemObj[key] = sub;
|
|
2999
|
-
} else {
|
|
3000
|
-
itemObj[key] = null;
|
|
3001
|
-
}
|
|
3002
|
-
} else {
|
|
3003
|
-
const parsedVal = parseSimpleYamlScalar(valRest);
|
|
3004
|
-
if (parsedVal === void 0) return void 0;
|
|
3005
|
-
itemObj[key] = parsedVal;
|
|
3006
|
-
}
|
|
3007
|
-
const propIndent = baseIndent + 2;
|
|
3008
|
-
while (idx < lines.length && lines[idx].indent === propIndent && !lines[idx].text.startsWith("-")) {
|
|
3009
|
-
const pl = lines[idx].text;
|
|
3010
|
-
const pColon = pl.indexOf(":");
|
|
3011
|
-
if (pColon <= 0) return void 0;
|
|
3012
|
-
const pKey = pl.slice(0, pColon).trim();
|
|
3013
|
-
const pRest = pl.slice(pColon + 1).trim();
|
|
3014
|
-
if (!/^[A-Za-z0-9_.-]+$/.test(pKey)) return void 0;
|
|
3015
|
-
idx++;
|
|
3016
|
-
if (!pRest) {
|
|
3017
|
-
if (idx < lines.length && lines[idx].indent > propIndent) {
|
|
3018
|
-
const sub = parseBlock(lines[idx].indent);
|
|
3019
|
-
if (sub === void 0) return void 0;
|
|
3020
|
-
itemObj[pKey] = sub;
|
|
3021
|
-
} else {
|
|
3022
|
-
itemObj[pKey] = null;
|
|
3023
|
-
}
|
|
3024
|
-
} else {
|
|
3025
|
-
const pv = parseSimpleYamlScalar(pRest);
|
|
3026
|
-
if (pv === void 0) return void 0;
|
|
3027
|
-
itemObj[pKey] = pv;
|
|
3028
|
-
}
|
|
3029
|
-
}
|
|
3030
|
-
arr.push(itemObj);
|
|
3031
|
-
} else {
|
|
3032
|
-
const val = parseSimpleYamlScalar(rest);
|
|
3033
|
-
if (val === void 0) return void 0;
|
|
3034
|
-
arr.push(val);
|
|
3035
|
-
}
|
|
3036
|
-
}
|
|
3037
|
-
return arr;
|
|
3038
|
-
}
|
|
3039
|
-
const obj = {};
|
|
3040
|
-
while (idx < lines.length && lines[idx].indent === baseIndent) {
|
|
3041
|
-
const l = lines[idx].text;
|
|
3042
|
-
const colon = l.indexOf(":");
|
|
3043
|
-
if (colon <= 0) return void 0;
|
|
3044
|
-
const key = l.slice(0, colon).trim();
|
|
3045
|
-
const rest = l.slice(colon + 1).trim();
|
|
3046
|
-
if (!/^[A-Za-z0-9_.-]+$/.test(key)) return void 0;
|
|
3047
|
-
idx++;
|
|
3048
|
-
if (!rest) {
|
|
3049
|
-
if (idx < lines.length && lines[idx].indent > baseIndent) {
|
|
3050
|
-
const sub = parseBlock(lines[idx].indent);
|
|
3051
|
-
if (sub === void 0) return void 0;
|
|
3052
|
-
obj[key] = sub;
|
|
3053
|
-
} else {
|
|
3054
|
-
obj[key] = null;
|
|
3055
|
-
}
|
|
3056
|
-
} else {
|
|
3057
|
-
const val = parseSimpleYamlScalar(rest);
|
|
3058
|
-
if (val === void 0) return void 0;
|
|
3059
|
-
obj[key] = val;
|
|
3060
|
-
}
|
|
3061
|
-
}
|
|
3062
|
-
return obj;
|
|
3063
|
-
}
|
|
3064
|
-
const parsed = parseBlock(lines[0].indent);
|
|
3065
|
-
if (idx !== lines.length) return void 0;
|
|
3066
|
-
return parsed;
|
|
3067
|
-
}
|
|
3068
|
-
var lastYqText;
|
|
3069
|
-
var lastYqInputFormat;
|
|
3070
|
-
var lastYqJsonStr;
|
|
3071
|
-
function evalSyncYqPrep(inBytes, opArgs, readFileSync) {
|
|
3072
|
-
if (inBytes.byteLength > 8192 || opArgs.length > 14) return void 0;
|
|
3073
|
-
let nullInput = false;
|
|
3074
|
-
const extraJqArgs = [];
|
|
3075
|
-
let idx = opArgs[0] === "eval" || opArgs[0] === "e" ? 1 : 0;
|
|
3076
|
-
if (opArgs[0] === "eval-all" || opArgs[0] === "ea") return void 0;
|
|
3077
|
-
let ended = false;
|
|
3078
|
-
let inputFormat = "yaml";
|
|
3079
|
-
let format = "yaml";
|
|
3080
|
-
let explicitJson = false;
|
|
3081
|
-
let compact = false;
|
|
3082
|
-
let raw = false;
|
|
3083
|
-
const operands = [];
|
|
3084
|
-
for (; idx < opArgs.length; idx++) {
|
|
3085
|
-
const a = opArgs[idx];
|
|
3086
|
-
if (!ended && a === "--") {
|
|
3087
|
-
ended = true;
|
|
3088
|
-
continue;
|
|
3089
|
-
}
|
|
3090
|
-
if (!ended && (a === "-p" || a.startsWith("-p") || a === "--input-format" || a.startsWith("--input-format="))) {
|
|
3091
|
-
const v = a.startsWith("--input-format=") ? a.slice(15) : a.startsWith("-p=") ? a.slice(3) : a.length > 2 && a.startsWith("-p") ? a.slice(2) : opArgs[++idx];
|
|
3092
|
-
if (v !== "yaml" && v !== "toml") return void 0;
|
|
3093
|
-
inputFormat = v;
|
|
3094
|
-
continue;
|
|
3095
|
-
}
|
|
3096
|
-
if (!ended && (a === "-o" || a.startsWith("-o") || a === "--output-format" || a.startsWith("--output-format="))) {
|
|
3097
|
-
const v = a.startsWith("--output-format=") ? a.slice(16) : a.startsWith("-o=") ? a.slice(3) : a.length > 2 && a.startsWith("-o") ? a.slice(2) : opArgs[++idx];
|
|
3098
|
-
if (v !== "yaml" && v !== "json") return void 0;
|
|
3099
|
-
format = v;
|
|
3100
|
-
explicitJson = v === "json";
|
|
3101
|
-
continue;
|
|
3102
|
-
}
|
|
3103
|
-
if (!ended && (a === "-c" || a === "--compact-output")) {
|
|
3104
|
-
compact = true;
|
|
3105
|
-
continue;
|
|
3106
|
-
}
|
|
3107
|
-
if (!ended && (a === "-r" || a === "--unwrapScalar")) {
|
|
3108
|
-
raw = true;
|
|
3109
|
-
continue;
|
|
3110
|
-
}
|
|
3111
|
-
if (!ended && (a === "-n" || a === "--null-input")) {
|
|
3112
|
-
nullInput = true;
|
|
3113
|
-
continue;
|
|
3114
|
-
}
|
|
3115
|
-
if (!ended && (a === "--arg" || a === "--argjson")) {
|
|
3116
|
-
if (idx + 2 >= opArgs.length) return void 0;
|
|
3117
|
-
extraJqArgs.push(a, opArgs[idx + 1], opArgs[idx + 2]);
|
|
3118
|
-
idx += 2;
|
|
3119
|
-
continue;
|
|
3120
|
-
}
|
|
3121
|
-
if (!ended && a.startsWith("-") && a !== "-") return void 0;
|
|
3122
|
-
operands.push(a);
|
|
3123
|
-
}
|
|
3124
|
-
if ((compact || raw) && !explicitJson) return void 0;
|
|
3125
|
-
const filter = operands[0] ?? ".";
|
|
3126
|
-
const files = operands.slice(1);
|
|
3127
|
-
if (files.length > 1) return void 0;
|
|
3128
|
-
let srcBytes = inBytes;
|
|
3129
|
-
if (files.length === 1 && files[0] !== "-") {
|
|
3130
|
-
if (!readFileSync) return void 0;
|
|
3131
|
-
const fBytes = readFileSync(files[0]);
|
|
3132
|
-
if (!fBytes || fBytes.byteLength > 8192) return void 0;
|
|
3133
|
-
srcBytes = fBytes;
|
|
3134
|
-
}
|
|
3135
|
-
let text;
|
|
3136
|
-
try {
|
|
3137
|
-
text = syncYqDecoder.decode(srcBytes);
|
|
3138
|
-
} catch {
|
|
3139
|
-
return void 0;
|
|
3140
|
-
}
|
|
3141
|
-
let jsonStr;
|
|
3142
|
-
if (nullInput) {
|
|
3143
|
-
jsonStr = "null";
|
|
3144
|
-
} else if (text === lastYqText && inputFormat === lastYqInputFormat && lastYqJsonStr !== void 0) {
|
|
3145
|
-
jsonStr = lastYqJsonStr;
|
|
3146
|
-
} else {
|
|
3147
|
-
const doc = parseSimpleYamlOrToml(text, inputFormat);
|
|
3148
|
-
if (doc === void 0) return void 0;
|
|
3149
|
-
jsonStr = JSON.stringify(doc);
|
|
3150
|
-
lastYqText = text;
|
|
3151
|
-
lastYqInputFormat = inputFormat;
|
|
3152
|
-
lastYqJsonStr = jsonStr;
|
|
3153
|
-
}
|
|
3154
|
-
const jqArgs = [];
|
|
3155
|
-
if (format === "json") {
|
|
3156
|
-
if (raw && compact) jqArgs.push("-rc");
|
|
3157
|
-
else if (raw) jqArgs.push("-r");
|
|
3158
|
-
else if (compact) jqArgs.push("-c");
|
|
3159
|
-
} else {
|
|
3160
|
-
jqArgs.push("-c");
|
|
3161
|
-
}
|
|
3162
|
-
if (nullInput) jqArgs.push("-n");
|
|
3163
|
-
jqArgs.push(...extraJqArgs, filter);
|
|
3164
|
-
return { jsonStr, jqArgs, format };
|
|
3165
|
-
}
|
|
3166
|
-
function formatYamlScalarSync(val) {
|
|
3167
|
-
if (val === null) return "null";
|
|
3168
|
-
if (typeof val === "boolean" || typeof val === "number") return String(val);
|
|
3169
|
-
if (typeof val === "string") {
|
|
3170
|
-
for (const character of val) {
|
|
3171
|
-
const point = character.codePointAt(0);
|
|
3172
|
-
if (point === 27 || point === 127 || point >= 128 && point <= 159 || point === 65534 || point === 65535) return void 0;
|
|
3173
|
-
}
|
|
3174
|
-
return JSON.stringify(val);
|
|
3175
|
-
}
|
|
3176
|
-
return void 0;
|
|
3177
|
-
}
|
|
3178
|
-
function formatYamlNodeLinesSync(val, indent, out) {
|
|
3179
|
-
const scalar = formatYamlScalarSync(val);
|
|
3180
|
-
if (scalar !== void 0) {
|
|
3181
|
-
out.push(`${indent}${scalar}`);
|
|
3182
|
-
return true;
|
|
3183
|
-
}
|
|
3184
|
-
if (Array.isArray(val)) {
|
|
3185
|
-
if (val.length === 0) {
|
|
3186
|
-
out.push(`${indent}[]`);
|
|
3187
|
-
return true;
|
|
3188
|
-
}
|
|
3189
|
-
for (const item of val) {
|
|
3190
|
-
const s = formatYamlScalarSync(item);
|
|
3191
|
-
if (s !== void 0) {
|
|
3192
|
-
out.push(`${indent}- ${s}`);
|
|
3193
|
-
} else if (item && typeof item === "object" && !Array.isArray(item)) {
|
|
3194
|
-
const entries = Object.entries(item);
|
|
3195
|
-
if (entries.length === 0) {
|
|
3196
|
-
out.push(`${indent}- {}`);
|
|
3197
|
-
} else {
|
|
3198
|
-
for (let i = 0; i < entries.length; i++) {
|
|
3199
|
-
const [k, v] = entries[i];
|
|
3200
|
-
const key = formatYamlScalarSync(k);
|
|
3201
|
-
if (key === void 0) return false;
|
|
3202
|
-
const prefix = i === 0 ? `${indent}- ` : `${indent} `;
|
|
3203
|
-
const sv = formatYamlScalarSync(v);
|
|
3204
|
-
if (sv !== void 0 || Array.isArray(v) && v.length === 0 || v && typeof v === "object" && !Array.isArray(v) && Object.keys(v).length === 0) {
|
|
3205
|
-
const emptyCol = Array.isArray(v) ? "[]" : v && typeof v === "object" ? "{}" : sv;
|
|
3206
|
-
out.push(`${prefix}${key}: ${emptyCol}`);
|
|
3207
|
-
} else {
|
|
3208
|
-
out.push(`${prefix}${key}:`);
|
|
3209
|
-
if (!formatYamlNodeLinesSync(v, `${indent} `, out)) return false;
|
|
3210
|
-
}
|
|
3211
|
-
}
|
|
3212
|
-
}
|
|
3213
|
-
} else {
|
|
3214
|
-
out.push(`${indent}-`);
|
|
3215
|
-
if (!formatYamlNodeLinesSync(item, `${indent} `, out)) return false;
|
|
3216
|
-
}
|
|
3217
|
-
}
|
|
3218
|
-
return true;
|
|
3219
|
-
}
|
|
3220
|
-
if (typeof val === "object" && val !== null) {
|
|
3221
|
-
const entries = Object.entries(val);
|
|
3222
|
-
if (entries.length === 0) {
|
|
3223
|
-
out.push(`${indent}{}`);
|
|
3224
|
-
return true;
|
|
3225
|
-
}
|
|
3226
|
-
for (const [k, v] of entries) {
|
|
3227
|
-
const key = formatYamlScalarSync(k);
|
|
3228
|
-
if (key === void 0) return false;
|
|
3229
|
-
const s = formatYamlScalarSync(v);
|
|
3230
|
-
if (s !== void 0 || Array.isArray(v) && v.length === 0 || v && typeof v === "object" && !Array.isArray(v) && Object.keys(v).length === 0) {
|
|
3231
|
-
const emptyCol = Array.isArray(v) ? "[]" : v && typeof v === "object" ? "{}" : s;
|
|
3232
|
-
out.push(`${indent}${key}: ${emptyCol}`);
|
|
3233
|
-
} else {
|
|
3234
|
-
out.push(`${indent}${key}:`);
|
|
3235
|
-
if (!formatYamlNodeLinesSync(v, `${indent} `, out)) return false;
|
|
3236
|
-
}
|
|
3237
|
-
}
|
|
3238
|
-
return true;
|
|
3239
|
-
}
|
|
3240
|
-
return false;
|
|
3241
|
-
}
|
|
3242
|
-
function formatSyncYqYamlLines(jsonLines) {
|
|
3243
|
-
const out = [];
|
|
3244
|
-
for (const line of jsonLines) {
|
|
3245
|
-
let val;
|
|
3246
|
-
try {
|
|
3247
|
-
val = JSON.parse(line);
|
|
3248
|
-
} catch {
|
|
3249
|
-
return void 0;
|
|
3250
|
-
}
|
|
3251
|
-
const document = [];
|
|
3252
|
-
if (!formatYamlNodeLinesSync(val, "", document)) return void 0;
|
|
3253
|
-
out.push(document.join("\n"));
|
|
3254
|
-
}
|
|
3255
|
-
return out.length === 0 ? "" : out.join("\n---\n") + "\n";
|
|
3256
|
-
}
|
|
3257
|
-
|
|
3258
|
-
export {
|
|
3259
|
-
createYqQuerySession,
|
|
3260
|
-
createYqCommand2 as createYqCommand,
|
|
3261
|
-
createYqCommands2 as createYqCommands,
|
|
3262
|
-
yqCommands,
|
|
3263
|
-
evalSyncYqPrep,
|
|
3264
|
-
formatSyncYqYamlLines
|
|
3265
|
-
};
|
|
3266
|
-
//# sourceMappingURL=chunk-DLIGMTCP.js.map
|