@poe-platform/safe-bash 0.1.508 → 0.1.509

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/dist/safe-bash/chunks/chunk-4OKU6JXB.js +5279 -0
  2. package/dist/safe-bash/chunks/chunk-4OKU6JXB.js.map +7 -0
  3. package/dist/safe-bash/chunks/chunk-5HT35GTV.js +520 -0
  4. package/dist/safe-bash/chunks/chunk-5HT35GTV.js.map +7 -0
  5. package/dist/safe-bash/chunks/{chunk-3ISDVRIM.js → chunk-B637PJBS.js} +19 -523
  6. package/dist/safe-bash/chunks/chunk-B637PJBS.js.map +7 -0
  7. package/dist/safe-bash/commands/structured/query-core.d.ts +35 -0
  8. package/dist/safe-bash/commands/structured/query-core.d.ts.map +1 -0
  9. package/dist/safe-bash/commands/structured/query-core.js +588 -0
  10. package/dist/safe-bash/commands/structured/query-core.js.map +1 -0
  11. package/dist/safe-bash/commands/xml/index.browser.js +2 -1
  12. package/dist/safe-bash/commands/yq/accounting.d.ts +64 -0
  13. package/dist/safe-bash/commands/yq/accounting.d.ts.map +1 -0
  14. package/dist/safe-bash/commands/yq/accounting.js +257 -0
  15. package/dist/safe-bash/commands/yq/accounting.js.map +1 -0
  16. package/dist/safe-bash/commands/yq/encoder.d.ts +6 -0
  17. package/dist/safe-bash/commands/yq/encoder.d.ts.map +1 -0
  18. package/dist/safe-bash/commands/yq/encoder.js +240 -0
  19. package/dist/safe-bash/commands/yq/encoder.js.map +1 -0
  20. package/dist/safe-bash/commands/yq/errors.d.ts +15 -0
  21. package/dist/safe-bash/commands/yq/errors.d.ts.map +1 -0
  22. package/dist/safe-bash/commands/yq/errors.js +37 -0
  23. package/dist/safe-bash/commands/yq/errors.js.map +1 -0
  24. package/dist/safe-bash/commands/yq/index.browser.js +12 -0
  25. package/dist/safe-bash/commands/yq/index.browser.js.map +7 -0
  26. package/dist/safe-bash/commands/yq/index.d.ts +9 -0
  27. package/dist/safe-bash/commands/yq/index.d.ts.map +1 -0
  28. package/dist/safe-bash/commands/yq/index.js +719 -0
  29. package/dist/safe-bash/commands/yq/index.js.map +1 -0
  30. package/dist/safe-bash/commands/yq/parser.d.ts +5 -0
  31. package/dist/safe-bash/commands/yq/parser.d.ts.map +1 -0
  32. package/dist/safe-bash/commands/yq/parser.js +1326 -0
  33. package/dist/safe-bash/commands/yq/parser.js.map +1 -0
  34. package/dist/safe-bash/commands/yq/toml.d.ts +5 -0
  35. package/dist/safe-bash/commands/yq/toml.d.ts.map +1 -0
  36. package/dist/safe-bash/commands/yq/toml.js +690 -0
  37. package/dist/safe-bash/commands/yq/toml.js.map +1 -0
  38. package/dist/safe-bash/core.browser.js +221 -2171
  39. package/dist/safe-bash/core.browser.js.map +4 -4
  40. package/dist/safe-bash/core.d.ts +1 -0
  41. package/dist/safe-bash/core.d.ts.map +1 -1
  42. package/dist/safe-bash/core.js +1 -0
  43. package/dist/safe-bash/core.js.map +1 -1
  44. package/package.json +8 -2
  45. package/dist/safe-bash/chunks/chunk-3ISDVRIM.js.map +0 -7
@@ -1,3 +1,20 @@
1
+ import {
2
+ createXmlCommands,
3
+ defaultXmlQueryLimits,
4
+ xmlCommands
5
+ } from "./chunks/chunk-5HT35GTV.js";
6
+ import {
7
+ Interpreter,
8
+ createOutputOperation,
9
+ createYqCommand,
10
+ createYqCommands,
11
+ jsonValues,
12
+ parse,
13
+ parseJson,
14
+ rawValues,
15
+ stringify,
16
+ yqCommands
17
+ } from "./chunks/chunk-4OKU6JXB.js";
1
18
  import {
2
19
  Budget,
3
20
  CommandArgumentIdentityError,
@@ -16,17 +33,13 @@ import {
16
33
  codeOf,
17
34
  collectBytes,
18
35
  collectText,
19
- compareNumbers,
20
36
  concatShellValues,
21
37
  concatenate,
22
38
  copyObject,
23
39
  createBytePipe,
24
40
  createCommandArguments,
25
- createXmlCommands,
26
- decimalNumber,
27
41
  decoder,
28
42
  defaultJqLimits,
29
- defaultXmlQueryLimits,
30
43
  define,
31
44
  diagnostic,
32
45
  dirname,
@@ -46,18 +59,11 @@ import {
46
59
  isAbsolutePath,
47
60
  isErrnoCode,
48
61
  isFsError,
49
- isNumber,
50
- isObject,
51
62
  isPathWithin,
52
63
  joinPath,
53
64
  lines,
54
65
  monotonicNow,
55
- numberValue,
56
- numericToken,
57
66
  object,
58
- objectKeyIterator,
59
- objectKeys,
60
- objectSize,
61
67
  options,
62
68
  output,
63
69
  outputFailure,
@@ -70,12 +76,10 @@ import {
70
76
  readBytes,
71
77
  registerYieldCheckpoint,
72
78
  relativePath,
73
- remove,
74
79
  replaceArgument,
75
80
  requireOperands,
76
81
  resolveJqLimits,
77
82
  resolvePath,
78
- scalarJson,
79
83
  scheduleTurn,
80
84
  shellValueByteLength,
81
85
  shellValueBytes,
@@ -93,9 +97,8 @@ import {
93
97
  writeBytes,
94
98
  writeDiagnostic,
95
99
  writeText,
96
- xmlCommands,
97
100
  yieldTurn
98
- } from "./chunks/chunk-3ISDVRIM.js";
101
+ } from "./chunks/chunk-B637PJBS.js";
99
102
 
100
103
  // packages/safe-bash/src/core.browser.ts
101
104
  init_platform();
@@ -107,132 +110,6 @@ init_platform();
107
110
  init_platform();
108
111
  import { ACCESS_MODES } from "@poe-platform/safe-fs/core";
109
112
 
110
- // packages/safe-bash/src/contracts/output.ts
111
- init_platform();
112
- function createOutputOperation(context2, destination2) {
113
- const controller = new AbortController();
114
- const signal = controller.signal;
115
- const capability = destination2.ownedOutput;
116
- const callbacks2 = [];
117
- const children = [];
118
- const closedReason = new Error("Output operation is closed");
119
- let accepting = true;
120
- let drain;
121
- const assertOpen = () => {
122
- context2.signal.throwIfAborted();
123
- signal.throwIfAborted();
124
- if (!accepting) throw closedReason;
125
- };
126
- const close = () => {
127
- if (drain) return drain;
128
- accepting = false;
129
- drain = Promise.resolve().then(async () => {
130
- try {
131
- const results = await Promise.allSettled(callbacks2.map(async (cleanup) => cleanup()));
132
- const failures = results.filter((result2) => result2.status === "rejected").map((result2) => result2.reason);
133
- if (failures.length === 1) throw failures[0];
134
- if (failures.length) throw new AggregateError(failures, "Output operation cleanup failed");
135
- } finally {
136
- context2.signal.removeEventListener("abort", callerAbort);
137
- capability?.consumerClosed.removeEventListener("abort", outputAbort);
138
- }
139
- });
140
- void drain.catch(() => {
141
- });
142
- for (const child of children) void child.close().catch(() => {
143
- });
144
- return drain;
145
- };
146
- const abort = (reason) => {
147
- controller.abort(reason);
148
- void close().catch(() => {
149
- });
150
- };
151
- const callerAbort = () => abort(context2.signal.reason);
152
- const outputAbort = () => abort(capability?.consumerClosed.reason);
153
- const registerCleanup = (cleanup) => {
154
- assertOpen();
155
- if (typeof cleanup !== "function") throw new TypeError("Cleanup must be callable");
156
- callbacks2.push(cleanup);
157
- };
158
- const wait2 = (pending) => new Promise((resolve, reject) => {
159
- const aborted = () => reject(signal.reason);
160
- if (signal.aborted) aborted();
161
- else signal.addEventListener("abort", aborted, { once: true });
162
- pending.then((value2) => {
163
- signal.removeEventListener("abort", aborted);
164
- resolve(value2);
165
- }, (error) => {
166
- signal.removeEventListener("abort", aborted);
167
- reject(error);
168
- });
169
- });
170
- context2.registerCleanup?.(close);
171
- if (context2.signal.aborted) callerAbort();
172
- else if (capability?.consumerClosed.aborted) outputAbort();
173
- else {
174
- context2.signal.addEventListener("abort", callerAbort, { once: true });
175
- capability?.consumerClosed.addEventListener("abort", outputAbort, { once: true });
176
- }
177
- return {
178
- signal,
179
- output: {
180
- ...destination2[outputFailure] ? { [outputFailure]: destination2[outputFailure] } : {},
181
- async write(chunk) {
182
- assertOpen();
183
- await writeBytes(capability ?? destination2, chunk, signal);
184
- }
185
- },
186
- registerCleanup,
187
- child(destination3) {
188
- assertOpen();
189
- const child = createOutputOperation({ signal, registerCleanup }, destination3);
190
- children.push(child);
191
- return child;
192
- },
193
- async acquire(start, release) {
194
- assertOpen();
195
- let resource;
196
- let settled;
197
- const admitted = new Promise((resolve) => {
198
- settled = resolve;
199
- });
200
- let released;
201
- const dispose = () => {
202
- released ??= admitted.then(async () => {
203
- if (resource) await release(resource.value);
204
- });
205
- return released;
206
- };
207
- registerCleanup(dispose);
208
- let acquisition;
209
- try {
210
- acquisition = Promise.resolve(start(signal));
211
- } catch (error) {
212
- acquisition = Promise.reject(error);
213
- }
214
- const pending = acquisition.then(async (value2) => {
215
- resource = { value: value2 };
216
- settled();
217
- if (!accepting) {
218
- await dispose();
219
- throw signal.aborted ? signal.reason : closedReason;
220
- }
221
- return value2;
222
- }, (error) => {
223
- settled();
224
- throw error;
225
- });
226
- return wait2(pending);
227
- },
228
- close,
229
- abort(reason) {
230
- abort(reason);
231
- return close();
232
- }
233
- };
234
- }
235
-
236
113
  // packages/safe-bash/src/contracts/plugin.ts
237
114
  init_platform();
238
115
  function composeMiddleware(middleware, terminal) {
@@ -1208,15 +1085,15 @@ function* matchExprSteps(descriptor2, subject, options3 = {}) {
1208
1085
  if (start < 0 || end < start || end - start > input3.values.length - state.position) break;
1209
1086
  work.charge(end - start);
1210
1087
  if (work.checkpoint()) yield;
1211
- let equal2 = true;
1088
+ let equal = true;
1212
1089
  for (let offset = 0; offset < end - start; offset++) {
1213
1090
  if (input3.values[start + offset] !== input3.values[state.position + offset]) {
1214
- equal2 = false;
1091
+ equal = false;
1215
1092
  break;
1216
1093
  }
1217
1094
  if ((offset + 1) % 256 === 0) yield;
1218
1095
  }
1219
- if (!equal2) break;
1096
+ if (!equal) break;
1220
1097
  state.position += end - start;
1221
1098
  if (end > start) {
1222
1099
  work.allocate(1);
@@ -2675,8 +2552,8 @@ async function moveAcrossDevices(context2, source2, target, noClobber, budget) {
2675
2552
  const targetStat = await optionalStat(context2, target);
2676
2553
  if (noClobber && targetStat) return false;
2677
2554
  if (source2 === target || compareCopyIdentity(sourceStat, targetStat) === "same") return false;
2678
- const compare5 = (origin, destination2, stat, existing2) => stat.type === "symlink" || existing2.type === "symlink" ? Promise.resolve(compareCopyIdentity(stat, existing2)) : compareObservedEntries(context2.fs, origin, stat, context2.fs, destination2, existing2, { signal: context2.signal });
2679
- const rootIdentity = targetStat ? await compare5(source2, target, sourceStat, targetStat) : "unknown";
2555
+ const compare4 = (origin, destination2, stat, existing2) => stat.type === "symlink" || existing2.type === "symlink" ? Promise.resolve(compareCopyIdentity(stat, existing2)) : compareObservedEntries(context2.fs, origin, stat, context2.fs, destination2, existing2, { signal: context2.signal });
2556
+ const rootIdentity = targetStat ? await compare4(source2, target, sourceStat, targetStat) : "unknown";
2680
2557
  if (rootIdentity === "same") return false;
2681
2558
  if (source2 === "/") throw new FsError("EBUSY", { path: source2 });
2682
2559
  if (sourceStat.type === "directory") {
@@ -2695,7 +2572,7 @@ async function moveAcrossDevices(context2, source2, target, noClobber, budget) {
2695
2572
  await budget.step();
2696
2573
  if (depth > 128) throw new FsError("EFBIG", { message: "cross-device move depth limit exceeded" });
2697
2574
  if (existing2) {
2698
- const identity2 = depth === 0 ? rootIdentity : await compare5(origin, destination2, stat, existing2);
2575
+ const identity2 = depth === 0 ? rootIdentity : await compare4(origin, destination2, stat, existing2);
2699
2576
  if (identity2 === "same") throw new FsError("EINVAL", { path: origin, dest: destination2, message: "move source and destination are aliases" });
2700
2577
  if (identity2 === "unknown") throw new FsError("ENOTSUP", { path: origin, dest: destination2, message: "existing move destination lacks authoritative distinctness" });
2701
2578
  if (stat.type === "directory" !== (existing2.type === "directory")) throw new FsError(existing2.type === "directory" ? "EISDIR" : "ENOTDIR", { path: destination2 });
@@ -2708,9 +2585,9 @@ async function moveAcrossDevices(context2, source2, target, noClobber, budget) {
2708
2585
  }
2709
2586
  plan.push({ source: origin, target: destination2, stat, targetStat: existing2, link });
2710
2587
  if (stat.type === "directory") {
2711
- const entries3 = await context2.fs.readdir(origin, { signal: context2.signal });
2712
- if (entries3.length > budget.remaining) throw new FsError("EFBIG", { message: "cross-device move entry limit exceeded" });
2713
- for (const entry of entries3.sort((left, right) => left.name < right.name ? -1 : left.name > right.name ? 1 : 0)) {
2588
+ const entries2 = await context2.fs.readdir(origin, { signal: context2.signal });
2589
+ if (entries2.length > budget.remaining) throw new FsError("EFBIG", { message: "cross-device move entry limit exceeded" });
2590
+ for (const entry of entries2.sort((left, right) => left.name < right.name ? -1 : left.name > right.name ? 1 : 0)) {
2714
2591
  const child = joinPath(origin, entry.name), childTarget = joinPath(destination2, entry.name);
2715
2592
  await visit(child, childTarget, await context2.fs.lstat(child, { signal: context2.signal }), await optionalStat(context2, childTarget), depth + 1);
2716
2593
  }
@@ -2784,21 +2661,21 @@ function createDirectoryReader(maxEntries = 1e4) {
2784
2661
  }
2785
2662
  return async (context2, path, ordered = false) => {
2786
2663
  context2.signal.throwIfAborted();
2787
- const entries3 = await context2.fs.readdir(path, { signal: context2.signal, maxEntries });
2664
+ const entries2 = await context2.fs.readdir(path, { signal: context2.signal, maxEntries });
2788
2665
  context2.signal.throwIfAborted();
2789
- if (entries3.length > maxEntries) {
2666
+ if (entries2.length > maxEntries) {
2790
2667
  throw new FsError("EFBIG", { syscall: "readdir", path, message: "directory entry limit exceeded" });
2791
2668
  }
2792
2669
  await yieldTurn(context2.signal);
2793
2670
  if (ordered) {
2794
- for (let index = 1; index < entries3.length; index++) {
2671
+ for (let index = 1; index < entries2.length; index++) {
2795
2672
  if (index % 256 === 0) await yieldTurn(context2.signal);
2796
- if (entries3[index - 1].name > entries3[index].name) {
2797
- return entries3.slice().sort((left, right) => left.name < right.name ? -1 : left.name > right.name ? 1 : 0);
2673
+ if (entries2[index - 1].name > entries2[index].name) {
2674
+ return entries2.slice().sort((left, right) => left.name < right.name ? -1 : left.name > right.name ? 1 : 0);
2798
2675
  }
2799
2676
  }
2800
2677
  }
2801
- return entries3;
2678
+ return entries2;
2802
2679
  };
2803
2680
  }
2804
2681
 
@@ -3297,9 +3174,9 @@ function filesystemCommands(maxDirectoryEntries) {
3297
3174
  }
3298
3175
  return { path, display: display2, stat };
3299
3176
  };
3300
- const order = async (entries4, lexical = false) => {
3177
+ const order = async (entries3, lexical = false) => {
3301
3178
  await yieldTurn(context2.signal);
3302
- if (sort !== "name" || !lexical) entries4.sort((left, right) => {
3179
+ if (sort !== "name" || !lexical) entries3.sort((left, right) => {
3303
3180
  context2.signal.throwIfAborted();
3304
3181
  if (sort !== "name") {
3305
3182
  const key = sort === "time" ? "mtimeMs" : "size";
@@ -3308,7 +3185,7 @@ function filesystemCommands(maxDirectoryEntries) {
3308
3185
  }
3309
3186
  return left.display < right.display ? -1 : left.display > right.display ? 1 : 0;
3310
3187
  });
3311
- if (parsed.flags.has("r")) entries4.reverse();
3188
+ if (parsed.flags.has("r")) entries3.reverse();
3312
3189
  await yieldTurn(context2.signal);
3313
3190
  };
3314
3191
  const humanSize = (size, path) => {
@@ -3360,8 +3237,8 @@ function filesystemCommands(maxDirectoryEntries) {
3360
3237
  `);
3361
3238
  outputWritten = true;
3362
3239
  }
3363
- const entries4 = await readDirectory(context2, path, true);
3364
- const names = entries4.map((entry) => entry.name).filter((name2) => parsed.flags.has("a") || parsed.flags.has("A") || !name2.startsWith("."));
3240
+ const entries3 = await readDirectory(context2, path, true);
3241
+ const names = entries3.map((entry) => entry.name).filter((name2) => parsed.flags.has("a") || parsed.flags.has("A") || !name2.startsWith("."));
3365
3242
  if (parsed.flags.has("a")) for (const name2 of [".", ".."]) {
3366
3243
  const index = names.findIndex((entry) => entry > name2);
3367
3244
  names.splice(index < 0 ? names.length : index, 0, name2);
@@ -3381,14 +3258,14 @@ function filesystemCommands(maxDirectoryEntries) {
3381
3258
  ancestors.delete(physical);
3382
3259
  }
3383
3260
  };
3384
- const entries3 = [];
3261
+ const entries2 = [];
3385
3262
  let admitted = 0;
3386
3263
  const result2 = await eachOperand(context2, operands, async (operand) => {
3387
3264
  if (admitted++ % 128 === 0) await yieldTurn(context2.signal);
3388
- entries3.push(await inspect3(pathOf(context2, operand), operand, true));
3265
+ entries2.push(await inspect3(pathOf(context2, operand), operand, true));
3389
3266
  });
3390
- const files = entries3.filter((entry) => parsed.flags.has("d") || entry.stat.type !== "directory");
3391
- const directories = entries3.filter((entry) => !parsed.flags.has("d") && entry.stat.type === "directory");
3267
+ const files = entries2.filter((entry) => parsed.flags.has("d") || entry.stat.type !== "directory");
3268
+ const directories = entries2.filter((entry) => !parsed.flags.has("d") && entry.stat.type === "directory");
3392
3269
  await order(files);
3393
3270
  await order(directories);
3394
3271
  for (const entry of [...files, ...directories]) {
@@ -3838,7 +3715,7 @@ async function followTail(caller, selection, cap, select, scheduler = tailFollow
3838
3715
  if (selection.mode === "F" && selection.names.includes("-")) throw new FsError("ENOTSUP", { message: "cannot follow standard input by name" });
3839
3716
  const session = new FollowSession(caller, cap, scheduler);
3840
3717
  const context2 = session.context;
3841
- const entries3 = selection.names.map((name2) => ({ name: name2, reader: void 0, identity: void 0, offset: 0, error: void 0, active: name2 !== "-" }));
3718
+ const entries2 = selection.names.map((name2) => ({ name: name2, reader: void 0, identity: void 0, offset: 0, error: void 0, active: name2 !== "-" }));
3842
3719
  let lastHeader;
3843
3720
  let exitCode = 0;
3844
3721
  let primary;
@@ -3901,7 +3778,7 @@ async function followTail(caller, selection, cap, select, scheduler = tailFollow
3901
3778
  return stat;
3902
3779
  };
3903
3780
  try {
3904
- for (const entry of entries3) {
3781
+ for (const entry of entries2) {
3905
3782
  if (entry.name === "-") {
3906
3783
  await header3(entry);
3907
3784
  await select(context2, session.input(selection.idleMs));
@@ -3940,12 +3817,12 @@ async function followTail(caller, selection, cap, select, scheduler = tailFollow
3940
3817
  }
3941
3818
  }
3942
3819
  acknowledged = scheduler.now();
3943
- if (selection.idleMs !== 0 && !(selection.positive && !selection.bytes && entries3.some((entry) => entry.error === "EISDIR"))) {
3944
- while (entries3.some((entry) => entry.active)) {
3820
+ if (selection.idleMs !== 0 && !(selection.positive && !selection.bytes && entries2.some((entry) => entry.error === "EISDIR"))) {
3821
+ while (entries2.some((entry) => entry.active)) {
3945
3822
  session.assertOpen();
3946
3823
  if (selection.idleMs !== void 0 && scheduler.now() - acknowledged >= selection.idleMs) break;
3947
3824
  const round = [];
3948
- for (const entry of entries3) {
3825
+ for (const entry of entries2) {
3949
3826
  if (!entry.active) continue;
3950
3827
  let stat;
3951
3828
  if (selection.mode === "F") stat = await acquire(entry, false);
@@ -3989,7 +3866,7 @@ async function followTail(caller, selection, cap, select, scheduler = tailFollow
3989
3866
  }
3990
3867
  }
3991
3868
  await yieldTurn(caller.signal);
3992
- if (!progressed && entries3.some((entry) => entry.active)) {
3869
+ if (!progressed && entries2.some((entry) => entry.active)) {
3993
3870
  const remaining = selection.idleMs === void 0 ? 100 : Math.min(100, selection.idleMs - (scheduler.now() - acknowledged));
3994
3871
  if (remaining <= 0) break;
3995
3872
  await session.wait(void 0, remaining);
@@ -4521,7 +4398,7 @@ var SortWork = class {
4521
4398
  }
4522
4399
  }
4523
4400
  };
4524
- async function sortRecords(records4, compare5, work) {
4401
+ async function sortRecords(records4, compare4, work) {
4525
4402
  if (records4.length < 2) return records4;
4526
4403
  let source2 = records4;
4527
4404
  let target = new Array(records4.length);
@@ -4534,7 +4411,7 @@ async function sortRecords(records4, compare5, work) {
4534
4411
  for (let index = begin; index < end; index++) {
4535
4412
  const checkpoint = work.charge();
4536
4413
  if (checkpoint) await checkpoint;
4537
- if (left < middle && (right === end || await compare5(source2[left], source2[right]) <= 0)) target[index] = source2[left++];
4414
+ if (left < middle && (right === end || await compare4(source2[left], source2[right]) <= 0)) target[index] = source2[left++];
4538
4415
  else target[index] = source2[right++];
4539
4416
  }
4540
4417
  }
@@ -4887,7 +4764,7 @@ function textCommands() {
4887
4764
  return numericKeyFlags.has("r") ? -result2 : result2;
4888
4765
  };
4889
4766
  }
4890
- const compare5 = async (left, right) => {
4767
+ const compare4 = async (left, right) => {
4891
4768
  const result2 = await keyCompare(left, right);
4892
4769
  return result2 || (simple || parsed.flags.has("s") || parsed.flags.has("u") ? 0 : await compareSortBytes(left, right, work) * direction);
4893
4770
  };
@@ -4904,7 +4781,7 @@ function textCommands() {
4904
4781
  return;
4905
4782
  }
4906
4783
  return (async () => {
4907
- if (records4.length && (await compare5(records4.at(-1), bytes3) > 0 || parsed.flags.has("u") && await keyCompare(records4.at(-1), bytes3) === 0)) {
4784
+ if (records4.length && (await compare4(records4.at(-1), bytes3) > 0 || parsed.flags.has("u") && await keyCompare(records4.at(-1), bytes3) === 0)) {
4908
4785
  await diagnostic(context2, new PublicDiagnostic(`disorder at record ${records4.length + 1}`));
4909
4786
  return false;
4910
4787
  }
@@ -4918,7 +4795,7 @@ function textCommands() {
4918
4795
  }
4919
4796
  }
4920
4797
  if (parsed.flags.has("c")) return { exitCode };
4921
- const ordered = await sortRecords(records4, compare5, work);
4798
+ const ordered = await sortRecords(records4, compare4, work);
4922
4799
  const sorted = (async function* () {
4923
4800
  let previous;
4924
4801
  let buffer = new Uint8Array(64 * 1024);
@@ -5138,7 +5015,7 @@ function predicateCommands() {
5138
5015
  if (args.length === 1) return { exitCode: args[0] ? 0 : 1 };
5139
5016
  if (args.length === 2 && args[0] === "!") return { exitCode: args[1] ? 1 : 0 };
5140
5017
  const unary2 = /* @__PURE__ */ new Set(["-n", "-z", "-e", "-a", "-f", "-c", "-d", "-L", "-h", "-s", "-r", "-w", "-x"]);
5141
- const binary3 = /* @__PURE__ */ new Set(["=", "==", "!=", "<", ">", "-eq", "-ne", "-lt", "-le", "-gt", "-ge", "-nt", "-ot", "-ef"]);
5018
+ const binary2 = /* @__PURE__ */ new Set(["=", "==", "!=", "<", ">", "-eq", "-ne", "-lt", "-le", "-gt", "-ge", "-nt", "-ot", "-ef"]);
5142
5019
  let offset = 0;
5143
5020
  const number4 = (text3) => {
5144
5021
  if (!/^[ \t]*[+-]?[0-9]+[ \t]*$/u.test(text3)) throw new UsageError(`integer expression expected: '${text3}'`);
@@ -5147,7 +5024,7 @@ function predicateCommands() {
5147
5024
  const primary = (depth) => {
5148
5025
  const token = args[offset++];
5149
5026
  if (token === void 0) throw new UsageError("argument expected");
5150
- if ((token === "!" || token === "(") && !binary3.has(args[offset] ?? "")) {
5027
+ if ((token === "!" || token === "(") && !binary2.has(args[offset] ?? "")) {
5151
5028
  if (depth >= maxExpressionDepth) throw new UsageError(`expression nesting exceeds ${maxExpressionDepth}`);
5152
5029
  if (token === "!") {
5153
5030
  const inner2 = primary(depth + 1);
@@ -5158,7 +5035,7 @@ function predicateCommands() {
5158
5035
  return inner;
5159
5036
  }
5160
5037
  const operator = args[offset];
5161
- if (operator !== void 0 && binary3.has(operator)) {
5038
+ if (operator !== void 0 && binary2.has(operator)) {
5162
5039
  offset++;
5163
5040
  const right = args[offset++];
5164
5041
  if (right === void 0) throw new UsageError("binary operator requires two operands");
@@ -5490,9 +5367,9 @@ async function parseEnvOptions(args, environment, signal, argumentValues) {
5490
5367
  } else {
5491
5368
  flags3.add(key);
5492
5369
  if (content !== void 0) {
5493
- const entries3 = values.get(key) ?? [];
5494
- entries3.push(content);
5495
- values.set(key, entries3);
5370
+ const entries2 = values.get(key) ?? [];
5371
+ entries2.push(content);
5372
+ values.set(key, entries2);
5496
5373
  }
5497
5374
  }
5498
5375
  };
@@ -7102,7 +6979,7 @@ async function substitute(text3, pattern, replacement, budget, global, occurrenc
7102
6979
  }
7103
6980
 
7104
6981
  // packages/safe-bash/src/commands/text-programs/sed.ts
7105
- function parse(source2, extended, separator, maxProgramInstructions) {
6982
+ function parse2(source2, extended, separator, maxProgramInstructions) {
7106
6983
  if (source2.length > 1024 * 1024) throw new ProgramError("sed program exceeds 1 MiB");
7107
6984
  const result2 = [];
7108
6985
  const groups = [];
@@ -7364,13 +7241,13 @@ async function execute2(program, context2, files, quiet, budget, separator, outp
7364
7241
  appended.push(item);
7365
7242
  };
7366
7243
  let substituted = false;
7367
- let deleted2 = false;
7244
+ let deleted = false;
7368
7245
  let quit = false;
7369
7246
  let status2 = 0;
7370
7247
  const print = () => emit2(pattern + (record4.terminated ? separator : ""), record4.terminated);
7371
7248
  const flush = async (printPattern = true) => {
7372
7249
  await assertPathRequirements(context2, sedRequirements, ["script-read"], appended.flatMap((item) => item.file === void 0 ? [] : [item.file]));
7373
- if (printPattern && !quiet && !deleted2) await print();
7250
+ if (printPattern && !quiet && !deleted) await print();
7374
7251
  if (outputState.stdoutUnterminated && (appended.length || quit)) {
7375
7252
  await write(context2, separator);
7376
7253
  outputState.stdoutUnterminated = false;
@@ -7466,13 +7343,13 @@ async function execute2(program, context2, files, quiet, budget, separator, outp
7466
7343
  break;
7467
7344
  }
7468
7345
  case "d":
7469
- deleted2 = true;
7346
+ deleted = true;
7470
7347
  pc = program.length;
7471
7348
  continue;
7472
7349
  case "D": {
7473
7350
  const end = pattern.indexOf(separator);
7474
7351
  if (end < 0) {
7475
- deleted2 = true;
7352
+ deleted = true;
7476
7353
  pc = program.length;
7477
7354
  } else {
7478
7355
  pattern = pattern.slice(end + 1);
@@ -7499,7 +7376,7 @@ async function execute2(program, context2, files, quiet, budget, separator, outp
7499
7376
  break;
7500
7377
  case "c":
7501
7378
  if (!instruction.second || ending || instruction.negate || (await peekNext()).done) await emit2(instruction.text);
7502
- deleted2 = true;
7379
+ deleted = true;
7503
7380
  pc = program.length;
7504
7381
  continue;
7505
7382
  case "h":
@@ -7638,7 +7515,7 @@ function sedCommand(options3 = {}) {
7638
7515
  sources2.push(byteString(files.shift()));
7639
7516
  }
7640
7517
  if (sources2[0]?.startsWith("#n")) quiet = true;
7641
- const program = parse(sources2.join("\n"), extended, separator, maxProgramInstructions);
7518
+ const program = parse2(sources2.join("\n"), extended, separator, maxProgramInstructions);
7642
7519
  const outputFiles = program.flatMap((instruction) => instruction.kind !== "r" && instruction.file !== void 0 ? [instruction.file] : []);
7643
7520
  await assertPathRequirements(context2, sedRequirements, ["script-output"], outputFiles);
7644
7521
  if (inPlace !== void 0 || outputFiles.length) {
@@ -8270,13 +8147,13 @@ var AwkParser = class {
8270
8147
  continue;
8271
8148
  }
8272
8149
  if (print && (token === ">" || token === ">>" || token === "|")) break;
8273
- const precedence3 = Object.hasOwn(precedences, token) ? precedences[token] : void 0;
8274
- if (precedence3 !== void 0) {
8275
- if (precedence3 < minimum) break;
8150
+ const precedence2 = Object.hasOwn(precedences, token) ? precedences[token] : void 0;
8151
+ if (precedence2 !== void 0) {
8152
+ if (precedence2 < minimum) break;
8276
8153
  this.advance();
8277
8154
  this.newlines();
8278
- const right = this.expression(precedence3 === 1 || token === "^" ? precedence3 : precedence3 + 1, print);
8279
- if (precedence3 === 1 && !isLvalue(left)) throw new ProgramError("assignment requires an assignable expression");
8155
+ const right = this.expression(precedence2 === 1 || token === "^" ? precedence2 : precedence2 + 1, print);
8156
+ if (precedence2 === 1 && !isLvalue(left)) throw new ProgramError("assignment requires an assignable expression");
8280
8157
  if (token === "in") {
8281
8158
  if (right.kind !== "variable") throw new ProgramError("right operand of 'in' must be an array name");
8282
8159
  this.arrays.add(right.name);
@@ -9046,10 +8923,10 @@ var AwkRuntime = class {
9046
8923
  size += key.length + textSize(part);
9047
8924
  }
9048
8925
  const allocation = this.arrays.get(target);
9049
- const entries3 = this.retention.replace(allocation.bytes, size, () => parts.map((part, index) => [String(index + 1), ownScalar(part)]));
9050
- this.entries += entries3.length - target.entries.size;
8926
+ const entries2 = this.retention.replace(allocation.bytes, size, () => parts.map((part, index) => [String(index + 1), ownScalar(part)]));
8927
+ this.entries += entries2.length - target.entries.size;
9051
8928
  target.entries.clear();
9052
- for (const [key, part] of entries3) target.entries.set(key, part);
8929
+ for (const [key, part] of entries2) target.entries.set(key, part);
9053
8930
  allocation.bytes = size;
9054
8931
  return numeric(parts.length);
9055
8932
  }
@@ -9374,1836 +9251,6 @@ init_platform();
9374
9251
 
9375
9252
  // packages/safe-bash/src/commands/structured/jq.ts
9376
9253
  init_platform();
9377
-
9378
- // packages/safe-bash/src/commands/structured/input.ts
9379
- init_platform();
9380
- var JqParseError = class extends JqError {
9381
- constructor(detail, offset, line = 1, column = offset, located = true) {
9382
- super(detail);
9383
- this.detail = detail;
9384
- this.offset = offset;
9385
- this.line = line;
9386
- this.column = column;
9387
- this.located = located;
9388
- }
9389
- detail;
9390
- offset;
9391
- line;
9392
- column;
9393
- located;
9394
- diagnostic() {
9395
- return this.located ? `${this.detail} at line ${this.line}, column ${this.column}` : this.detail;
9396
- }
9397
- };
9398
- function decodeUtf8(bytes3, budget) {
9399
- const points = [];
9400
- budget.step(Math.ceil(bytes3.length / 1024));
9401
- let block = "";
9402
- for (let offset = 0; offset < bytes3.length; ) {
9403
- if (offset % 1024 === 0) {
9404
- budget.signal.throwIfAborted();
9405
- points.push(block);
9406
- block = "";
9407
- }
9408
- const first = bytes3.charCodeAt(offset);
9409
- let length = first < 128 ? 1 : first >= 194 && first <= 223 ? 2 : first >= 224 && first <= 239 ? 3 : first >= 240 && first <= 244 ? 4 : 1;
9410
- let point = first < 128 ? first : -1;
9411
- if (length > bytes3.length - offset) length = bytes3.length - offset;
9412
- else if (length > 1) {
9413
- point = first & 127 >> length;
9414
- for (let index = 1; index < length; index++) {
9415
- const next = bytes3.charCodeAt(offset + index);
9416
- if (next < 128 || next > 191) {
9417
- point = -1;
9418
- length = index;
9419
- break;
9420
- }
9421
- point = point << 6 | next & 63;
9422
- }
9423
- if (point < [0, 0, 128, 2048, 65536][length] || point > 1114111 || point >= 55296 && point <= 57343) point = -1;
9424
- }
9425
- block += String.fromCodePoint(point < 0 ? 65533 : point);
9426
- offset += length;
9427
- }
9428
- return points.join("") + block;
9429
- }
9430
- var JsonParser = class {
9431
- constructor(budget) {
9432
- this.budget = budget;
9433
- }
9434
- budget;
9435
- stack = [];
9436
- next;
9437
- token = "";
9438
- quoted = false;
9439
- escaped = false;
9440
- bom = 0;
9441
- bytes = 0;
9442
- depth = 0;
9443
- offset = 0;
9444
- line = 1;
9445
- column = 0;
9446
- fail(detail, located = true) {
9447
- throw new JqParseError(detail, this.offset, this.line, this.column, located);
9448
- }
9449
- accept(value2) {
9450
- this.budget.step();
9451
- if (this.next !== void 0) this.fail("Expected separator between values");
9452
- this.next = value2;
9453
- }
9454
- literal(eof = false) {
9455
- if (!this.token) return;
9456
- const text3 = this.token;
9457
- const pattern = text3[0] === "t" ? "true" : text3[0] === "f" ? "false" : text3.startsWith("nu") ? "null" : void 0;
9458
- let value2;
9459
- if (pattern) {
9460
- if (text3 !== pattern) this.fail("Invalid literal" + (eof ? " at EOF" : ""));
9461
- value2 = pattern === "true" ? true : pattern === "false" ? false : null;
9462
- } else {
9463
- value2 = numericToken(text3, this.budget);
9464
- if (value2 === void 0) this.fail("Invalid numeric literal" + (eof ? " at EOF" : ""));
9465
- }
9466
- this.accept(value2);
9467
- this.token = "";
9468
- }
9469
- string() {
9470
- let result2 = "";
9471
- let start = 0;
9472
- for (let index = 0; index < this.token.length; index++) {
9473
- if (index % 1024 === 0) this.budget.step();
9474
- const character = this.token[index];
9475
- if (character === "\\") {
9476
- result2 += decodeUtf8(this.token.slice(start, index), this.budget);
9477
- const escaped3 = this.token[++index];
9478
- if (escaped3 === "u") {
9479
- const digits = this.token.slice(index + 1, index + 5);
9480
- if (digits.length < 4) this.fail("Invalid \\uXXXX escape");
9481
- if (!/^[0-9a-f]{4}$/iu.test(digits)) this.fail("Invalid characters in \\uXXXX escape");
9482
- let point = parseInt(digits, 16);
9483
- index += 4;
9484
- if (point >= 55296 && point <= 56319) {
9485
- const tail = this.token.slice(index + 1, index + 7);
9486
- const low = /^\\u[0-9a-f]{4}$/iu.test(tail) ? parseInt(tail.slice(2), 16) : 0;
9487
- if (low < 56320 || low > 57343) this.fail("Invalid \\uXXXX\\uXXXX surrogate pair escape");
9488
- point = 65536 + (point - 55296 << 10) + low - 56320;
9489
- index += 6;
9490
- }
9491
- result2 += String.fromCodePoint(point >= 56320 && point <= 57343 ? 65533 : point);
9492
- } else {
9493
- const escapes = { '"': '"', "\\": "\\", "/": "/", b: "\b", f: "\f", n: "\n", r: "\r", t: " " };
9494
- if (escaped3 === void 0 || !Object.hasOwn(escapes, escaped3)) this.fail("Invalid escape");
9495
- result2 += escapes[escaped3];
9496
- }
9497
- start = index + 1;
9498
- } else if (character.charCodeAt(0) < 32) this.fail("Invalid string: control characters from U+0000 through U+001F must be escaped");
9499
- }
9500
- result2 += decodeUtf8(this.token.slice(start), this.budget);
9501
- this.budget.text(result2);
9502
- return result2;
9503
- }
9504
- done() {
9505
- if (this.stack.length || this.next === void 0) return void 0;
9506
- const value2 = this.next;
9507
- this.next = void 0;
9508
- this.budget.value(value2);
9509
- this.bytes = 0;
9510
- return value2;
9511
- }
9512
- append() {
9513
- const parent = this.stack.at(-1);
9514
- if (Array.isArray(parent)) {
9515
- this.budget.collection(parent.length + 1);
9516
- parent.push(this.next);
9517
- } else if (typeof parent === "string") {
9518
- const container = this.stack.at(-2);
9519
- if (!Object.hasOwn(container, parent)) this.budget.collection(objectSize(container) + 1);
9520
- put(container, parent, this.next);
9521
- this.stack.pop();
9522
- } else this.fail("Objects must consist of key:value pairs");
9523
- this.next = void 0;
9524
- }
9525
- structure(character) {
9526
- const parent = this.stack.at(-1);
9527
- if (character === "[" || character === "{") {
9528
- if (this.next !== void 0) this.fail("Expected separator between values");
9529
- if (++this.depth > this.budget.limits.maxDepth) throw new JqLimitError("maxDepth");
9530
- this.stack.push(character === "[" ? [] : object());
9531
- } else if (character === ":") {
9532
- if (this.next === void 0) this.fail("Expected string key before ':'");
9533
- if (!parent || Array.isArray(parent) || typeof parent === "string") this.fail("':' not as part of an object");
9534
- if (typeof this.next !== "string") this.fail("Object keys must be strings");
9535
- this.stack.push(this.next);
9536
- this.next = void 0;
9537
- } else if (character === ",") {
9538
- if (this.next === void 0) this.fail("Expected value before ','");
9539
- if (!this.stack.length) this.fail("',' not as part of an object or array");
9540
- this.append();
9541
- } else if (character === "]") {
9542
- if (!Array.isArray(parent)) this.fail("Unmatched ']'");
9543
- if (this.next !== void 0) this.append();
9544
- else if (parent.length) this.fail("Expected another array element");
9545
- this.next = this.stack.pop();
9546
- this.depth--;
9547
- } else if (character === "}") {
9548
- if (!this.stack.length) this.fail("Unmatched '}'");
9549
- if (this.next !== void 0) {
9550
- if (typeof parent !== "string") this.fail("Objects must consist of key:value pairs");
9551
- this.append();
9552
- } else {
9553
- if (typeof parent === "string" || Array.isArray(parent)) this.fail("Unmatched '}'");
9554
- if (objectSize(parent)) this.fail("Expected another key-value pair");
9555
- }
9556
- this.next = this.stack.pop();
9557
- this.depth--;
9558
- }
9559
- }
9560
- feed(character) {
9561
- this.offset++;
9562
- if (this.bom < 3) {
9563
- if (character.charCodeAt(0) === [239, 187, 191][this.bom]) {
9564
- this.bom++;
9565
- return void 0;
9566
- }
9567
- if (this.bom) this.fail("Malformed BOM", false);
9568
- this.bom = 3;
9569
- }
9570
- if (character === "\n") {
9571
- this.line++;
9572
- this.column = 0;
9573
- } else this.column++;
9574
- const space = character === " " || character === " " || character === "\r" || character === "\n";
9575
- const structure = "[]{}:,".includes(character);
9576
- const endsScalar = !this.quoted && !this.stack.length && this.token !== "" && (space || structure || character === '"');
9577
- if (!endsScalar && (this.bytes || !space)) {
9578
- if (++this.bytes > this.budget.limits.maxValueBytes) throw new JqLimitError("maxValueBytes");
9579
- }
9580
- if (this.quoted) {
9581
- if (character === '"' && !this.escaped) {
9582
- this.accept(this.string());
9583
- this.token = "";
9584
- this.quoted = false;
9585
- return this.done();
9586
- }
9587
- this.token += character;
9588
- this.escaped = character === "\\" && !this.escaped;
9589
- return void 0;
9590
- }
9591
- if (!space && !structure && character !== '"') {
9592
- this.token += character;
9593
- return void 0;
9594
- }
9595
- this.literal();
9596
- const output2 = this.done();
9597
- if (character === '"') this.quoted = true;
9598
- else if (structure) this.structure(character);
9599
- if (output2 !== void 0 && (this.quoted || this.stack.length)) this.bytes = 1;
9600
- return this.done() ?? output2;
9601
- }
9602
- finish() {
9603
- if (this.quoted) this.fail("Unfinished string at EOF");
9604
- this.literal(true);
9605
- if (this.stack.length) this.fail("Unfinished JSON term at EOF");
9606
- return this.done();
9607
- }
9608
- };
9609
- function parseJson(input3, budget, byteEncoded = false) {
9610
- const text3 = byteEncoded ? input3 : import_buffer.Buffer.from(input3).toString("latin1");
9611
- if (text3.length > budget.limits.maxValueBytes) throw new JqLimitError("maxValueBytes");
9612
- const parser = new JsonParser(budget);
9613
- let value2;
9614
- const accept = (next) => {
9615
- if (next === void 0) return;
9616
- if (value2 !== void 0) throw new JqParseError("Unexpected extra JSON values", 0, 1, 0, false);
9617
- value2 = next;
9618
- };
9619
- for (let index = 0; index < text3.length; index++) {
9620
- if (index % 1024 === 0) budget.step();
9621
- accept(parser.feed(text3[index]));
9622
- }
9623
- accept(parser.finish());
9624
- if (value2 === void 0) throw new JqParseError("Expected JSON value", 0, 1, 0, false);
9625
- return value2;
9626
- }
9627
- async function* readChunks(source2, budget) {
9628
- for await (const chunk of readBytes(source2, budget.signal)) {
9629
- await budget.tick();
9630
- budget.inputBytes += chunk.byteLength;
9631
- if (budget.inputBytes > budget.limits.maxInputBytes) throw new JqLimitError("maxInputBytes");
9632
- let offset = 0;
9633
- while (offset < chunk.length) {
9634
- if (budget.inputLocation.complete) budget.inputLocation = { ...budget.inputLocation, complete: false };
9635
- const newline = chunk.indexOf(10, offset);
9636
- const end = Math.min(newline < 0 ? chunk.length : newline + 1, offset + 16384);
9637
- budget.step(Math.ceil((end - offset) / 1024));
9638
- await budget.tick();
9639
- if (newline >= 0 && end === newline + 1) {
9640
- budget.inputLocation.line++;
9641
- budget.inputLocation.complete = true;
9642
- }
9643
- yield chunk.subarray(offset, end);
9644
- offset = end;
9645
- }
9646
- }
9647
- budget.inputLocation.complete = true;
9648
- }
9649
- async function* jsonValues(source2, budget) {
9650
- const parser = new JsonParser(budget);
9651
- let scanned = 0;
9652
- let nulTail;
9653
- async function* scan(text3, completeLine = false) {
9654
- for (const character of text3) {
9655
- if (++scanned % 1024 === 0) await budget.tick();
9656
- if (!completeLine && character === "\0" && nulTail === void 0) nulTail = "";
9657
- if (nulTail !== void 0) {
9658
- nulTail += character;
9659
- if (nulTail.length > budget.limits.maxValueBytes) throw new JqLimitError("maxValueBytes");
9660
- if (character === "\n") {
9661
- const tail = nulTail;
9662
- nulTail = void 0;
9663
- yield* scan(tail, true);
9664
- }
9665
- continue;
9666
- }
9667
- const value2 = parser.feed(character);
9668
- if (value2 !== void 0) yield value2;
9669
- }
9670
- }
9671
- try {
9672
- for await (const chunk of readChunks(source2, budget)) yield* scan(import_buffer.Buffer.from(chunk).toString("latin1"));
9673
- const value2 = parser.finish();
9674
- if (value2 !== void 0) yield value2;
9675
- } catch (error) {
9676
- if (!(error instanceof JqParseError)) throw error;
9677
- throw new JqError(`parse error: ${error.diagnostic()}`);
9678
- }
9679
- }
9680
- async function* rawValues(sources2, budget, slurp) {
9681
- let buffer = "";
9682
- let bytes3 = 2;
9683
- const append = (text3) => {
9684
- bytes3 += import_buffer.Buffer.byteLength(JSON.stringify(text3)) - 2;
9685
- if (bytes3 > budget.limits.maxValueBytes) throw new JqLimitError("maxValueBytes");
9686
- buffer += text3;
9687
- };
9688
- for await (const source2 of sources2) {
9689
- let pending = "";
9690
- for await (const chunk of readChunks(source2, budget)) {
9691
- await budget.tick();
9692
- pending += import_buffer.Buffer.from(chunk).toString("latin1");
9693
- if (pending.length + bytes3 - (!slurp && pending.endsWith("\n") ? 1 : 0) > budget.limits.maxValueBytes) throw new JqLimitError("maxValueBytes");
9694
- if (pending.endsWith("\n")) {
9695
- append(decodeUtf8(slurp ? pending : pending.slice(0, -1), budget));
9696
- pending = "";
9697
- if (!slurp) {
9698
- budget.value(buffer);
9699
- yield buffer;
9700
- buffer = "";
9701
- bytes3 = 2;
9702
- }
9703
- }
9704
- }
9705
- append(decodeUtf8(pending, budget));
9706
- }
9707
- if (slurp || buffer) {
9708
- budget.value(buffer);
9709
- yield buffer;
9710
- }
9711
- }
9712
- function* quotedFragments(value2, budget) {
9713
- yield { text: '"', bytes: 1 };
9714
- let offset = 0;
9715
- while (offset < value2.length) {
9716
- const start = offset;
9717
- const limit = Math.min(start + 32, value2.length);
9718
- budget.step(limit - start);
9719
- let bytes3 = 0;
9720
- while (offset < limit) {
9721
- const code = value2.charCodeAt(offset);
9722
- if (code >= 55296 && code <= 56319 && offset + 1 === limit && limit < value2.length) break;
9723
- if (code >= 55296 && code <= 56319 && offset + 1 < limit) {
9724
- const next = value2.charCodeAt(offset + 1);
9725
- if (next >= 56320 && next <= 57343) {
9726
- bytes3 += 4;
9727
- offset += 2;
9728
- continue;
9729
- }
9730
- }
9731
- if (code === 34 || code === 92 || code === 8 || code === 9 || code === 10 || code === 12 || code === 13) bytes3 += 2;
9732
- else if (code < 32 || code >= 55296 && code <= 57343) bytes3 += 6;
9733
- else bytes3 += code < 128 ? 1 : code < 2048 ? 2 : 3;
9734
- offset++;
9735
- }
9736
- yield { value: value2, start, end: offset, bytes: bytes3, quoted: true };
9737
- }
9738
- yield { text: '"', bytes: 1 };
9739
- }
9740
- function renderJsonFragment(fragment, budget) {
9741
- if ("text" in fragment) return fragment.text;
9742
- budget.step(fragment.end - fragment.start);
9743
- const text3 = fragment.value.slice(fragment.start, fragment.end);
9744
- return fragment.quoted ? JSON.stringify(text3).slice(1, -1) : text3;
9745
- }
9746
- function* jsonFragments(value2, budget, pretty = false, depth = 0) {
9747
- budget.step();
9748
- if (depth > budget.limits.maxDepth) throw new JqLimitError("maxDepth");
9749
- if (typeof value2 === "string") {
9750
- yield* quotedFragments(value2, budget);
9751
- return;
9752
- }
9753
- if (value2 === null || typeof value2 !== "object" || isNumber(value2)) {
9754
- const text3 = scalarJson(value2, budget);
9755
- for (let start = 0; start < text3.length; start += 32) {
9756
- const end = Math.min(start + 32, text3.length);
9757
- budget.step(end - start);
9758
- yield { value: text3, start, end, bytes: end - start, quoted: false };
9759
- }
9760
- return;
9761
- }
9762
- if (depth + 1 > budget.limits.maxDepth) throw new JqLimitError("maxDepth");
9763
- const array2 = Array.isArray(value2);
9764
- if (array2) budget.collection(value2.length);
9765
- yield { text: array2 ? "[" : "{", bytes: 1 };
9766
- let count2 = 0;
9767
- const keys = array2 ? value2.keys() : objectKeyIterator(value2);
9768
- for (const key of keys) {
9769
- budget.step();
9770
- budget.collection(count2 + 1);
9771
- if (count2++) yield { text: ",", bytes: 1 };
9772
- if (pretty) {
9773
- const bytes3 = 1 + 2 * (depth + 1);
9774
- budget.step(bytes3);
9775
- yield { text: `
9776
- ${" ".repeat(depth + 1)}`, bytes: bytes3 };
9777
- }
9778
- if (!array2) {
9779
- yield* quotedFragments(String(key), budget);
9780
- yield { text: pretty ? ": " : ":", bytes: pretty ? 2 : 1 };
9781
- }
9782
- yield* jsonFragments(value2[key], budget, pretty, depth + 1);
9783
- }
9784
- if (pretty && count2) {
9785
- const bytes3 = 1 + 2 * depth;
9786
- budget.step(bytes3);
9787
- yield { text: `
9788
- ${" ".repeat(depth)}`, bytes: bytes3 };
9789
- }
9790
- yield { text: array2 ? "]" : "}", bytes: 1 };
9791
- }
9792
- async function measureValue(value2, budget, depth = 0, maxBytes = budget.limits.maxValueBytes) {
9793
- await budget.tick(0);
9794
- let bytes3 = 0;
9795
- for (const fragment of jsonFragments(value2, budget, false, depth)) {
9796
- await budget.tick(0);
9797
- bytes3 += fragment.bytes;
9798
- if (bytes3 > maxBytes) throw new JqLimitError("maxValueBytes");
9799
- }
9800
- return bytes3;
9801
- }
9802
- async function stringify(value2, budget, pretty = false, maxBytes = budget.limits.maxValueBytes, limitName = "maxValueBytes", asStringValue = false) {
9803
- await budget.tick(0);
9804
- const parts = [];
9805
- let bytes3 = 0;
9806
- let units = 0;
9807
- let stringBytes = 2;
9808
- for (const fragment of jsonFragments(value2, budget, pretty)) {
9809
- await budget.tick(0);
9810
- bytes3 += fragment.bytes;
9811
- if (bytes3 > maxBytes) throw new JqLimitError(limitName);
9812
- const text3 = renderJsonFragment(fragment, budget);
9813
- if (asStringValue) {
9814
- for (const encoded2 of quotedFragments(text3, budget)) stringBytes += encoded2.bytes;
9815
- stringBytes -= 2;
9816
- if (stringBytes > budget.limits.maxValueBytes) throw new JqLimitError("maxValueBytes");
9817
- }
9818
- budget.step();
9819
- units += text3.length;
9820
- parts.push(text3);
9821
- }
9822
- await budget.tick(units);
9823
- return parts.join("");
9824
- }
9825
-
9826
- // packages/safe-bash/src/commands/structured/interpreter.ts
9827
- init_platform();
9828
-
9829
- // packages/safe-bash/src/commands/structured/split.ts
9830
- init_platform();
9831
- async function splitString2(input3, separator, budget) {
9832
- await budget.tick();
9833
- if (typeof input3 !== "string" || typeof separator !== "string") {
9834
- throw new JqError("split input and separator must be strings");
9835
- }
9836
- const guaranteedFitUnits = Math.floor((budget.limits.maxValueBytes - 2) / 6);
9837
- for (const operand of [input3, separator]) {
9838
- if (operand.length <= guaranteedFitUnits) budget.step();
9839
- else budget.value(operand);
9840
- }
9841
- const result2 = [];
9842
- let bytes3 = 2;
9843
- const append = (start, end) => {
9844
- budget.collection(result2.length + 1);
9845
- const part = input3.slice(start, end);
9846
- bytes3 += budget.value(part) + (result2.length ? 1 : 0);
9847
- if (bytes3 > budget.limits.maxValueBytes) throw new JqLimitError("maxValueBytes");
9848
- result2.push(part);
9849
- };
9850
- if (separator.length === 0) {
9851
- let offset = 0;
9852
- for (const character of input3) {
9853
- await budget.tick();
9854
- append(offset, offset + character.length);
9855
- offset += character.length;
9856
- }
9857
- } else if (input3.length !== 0) {
9858
- if (separator.length > input3.length) append(0, input3.length);
9859
- else {
9860
- const prefixes = new Int32Array(separator.length);
9861
- let matched = 0;
9862
- for (let index = 1; index < separator.length; index++) {
9863
- await budget.tick();
9864
- while (matched > 0 && separator[index] !== separator[matched]) {
9865
- await budget.tick();
9866
- matched = prefixes[matched - 1];
9867
- }
9868
- if (separator[index] === separator[matched]) matched++;
9869
- prefixes[index] = matched;
9870
- }
9871
- matched = 0;
9872
- let start = 0;
9873
- for (let index = 0; index < input3.length; index++) {
9874
- await budget.tick();
9875
- while (matched > 0 && input3[index] !== separator[matched]) {
9876
- await budget.tick();
9877
- matched = prefixes[matched - 1];
9878
- }
9879
- if (input3[index] === separator[matched]) matched++;
9880
- if (matched === separator.length) {
9881
- append(start, index + 1 - separator.length);
9882
- start = index + 1;
9883
- matched = 0;
9884
- }
9885
- }
9886
- append(start, input3.length);
9887
- }
9888
- }
9889
- budget.value(result2);
9890
- return result2;
9891
- }
9892
-
9893
- // packages/safe-bash/src/commands/structured/values.ts
9894
- init_platform();
9895
- function type(value2) {
9896
- return value2 === null ? "null" : isNumber(value2) ? "number" : Array.isArray(value2) ? "array" : typeof value2;
9897
- }
9898
- function describe(value2, budget) {
9899
- const parts = [];
9900
- let length = 0;
9901
- for (const fragment of jsonFragments(value2, budget)) {
9902
- const text4 = renderJsonFragment(fragment, budget);
9903
- budget.step(text4.length);
9904
- const bytes4 = import_buffer.Buffer.from(text4);
9905
- const retained = Math.min(15 - length, bytes4.length);
9906
- parts.push(bytes4.subarray(0, retained));
9907
- length += retained;
9908
- if (length === 15) break;
9909
- }
9910
- const bytes3 = import_buffer.Buffer.concat(parts, length);
9911
- const text3 = length < 15 ? bytes3.toString() : `${bytes3.subarray(0, 11).toString()}...`;
9912
- return `${type(value2)} (${text3})`;
9913
- }
9914
- async function stringCompare(left, right, budget) {
9915
- await budget.tick(1 + Math.ceil(Math.min(left.length, right.length) / 32));
9916
- let leftOffset = 0;
9917
- let rightOffset = 0;
9918
- let points = 0;
9919
- while (leftOffset < left.length && rightOffset < right.length) {
9920
- if (points++ % 32 === 0) await budget.tick(0);
9921
- const leftPoint = left.codePointAt(leftOffset);
9922
- const rightPoint = right.codePointAt(rightOffset);
9923
- if (leftPoint !== rightPoint) return leftPoint < rightPoint ? -1 : 1;
9924
- leftOffset += leftPoint > 65535 ? 2 : 1;
9925
- rightOffset += rightPoint > 65535 ? 2 : 1;
9926
- }
9927
- return leftOffset < left.length ? 1 : rightOffset < right.length ? -1 : 0;
9928
- }
9929
- async function stableSort(items, budget, comparator) {
9930
- await budget.tick(0);
9931
- budget.collection(items.length);
9932
- if (items.length < 2) return;
9933
- await budget.tick(items.length);
9934
- const scratch = new Array(items.length);
9935
- let source2 = items;
9936
- let target = scratch;
9937
- for (let width = 1; width < items.length; width *= 2) {
9938
- for (let start = 0; start < items.length; start += width * 2) {
9939
- const middle = Math.min(start + width, items.length);
9940
- const end = Math.min(start + width * 2, items.length);
9941
- let left = start;
9942
- let right = middle;
9943
- for (let index = start; index < end; index++) {
9944
- await budget.tick();
9945
- if (left < middle && (right >= end || await comparator(source2[left], source2[right]) <= 0)) target[index] = source2[left++];
9946
- else target[index] = source2[right++];
9947
- }
9948
- }
9949
- const previous = source2;
9950
- source2 = target;
9951
- target = previous;
9952
- }
9953
- if (source2 !== items) for (let index = 0; index < items.length; index++) {
9954
- await budget.tick();
9955
- items[index] = source2[index];
9956
- }
9957
- }
9958
- async function sortedKeys(value2, budget) {
9959
- await budget.tick(0);
9960
- const keys = [];
9961
- for (const key of objectKeyIterator(value2)) {
9962
- await budget.tick();
9963
- budget.collection(keys.length + 1);
9964
- keys.push(key);
9965
- }
9966
- await stableSort(keys, budget, (left, right) => stringCompare(left, right, budget));
9967
- return keys;
9968
- }
9969
- async function compare2(left, right, budget) {
9970
- await budget.tick();
9971
- const rank3 = (value2) => value2 === null ? 0 : value2 === false ? 1 : value2 === true ? 2 : isNumber(value2) ? 3 : typeof value2 === "string" ? 4 : Array.isArray(value2) ? 5 : 6;
9972
- const difference = rank3(left) - rank3(right);
9973
- if (difference) return Math.sign(difference);
9974
- if (isNumber(left) && isNumber(right)) return compareNumbers(left, right, budget);
9975
- if (typeof left === "string" && typeof right === "string") return stringCompare(left, right, budget);
9976
- if (left === right && !Array.isArray(left) && !isObject(left)) return 0;
9977
- if (Array.isArray(left) && Array.isArray(right)) {
9978
- for (let index = 0; index < Math.min(left.length, right.length); index++) {
9979
- const result2 = await compare2(left[index], right[index], budget);
9980
- if (result2) return result2;
9981
- }
9982
- return Math.sign(left.length - right.length);
9983
- }
9984
- if (isObject(left) && isObject(right)) {
9985
- const keys = await sortedKeys(left, budget);
9986
- const otherKeys = await sortedKeys(right, budget);
9987
- const keyDifference = await compare2(keys, otherKeys, budget);
9988
- if (keyDifference) return keyDifference;
9989
- for (const key of keys) {
9990
- const result2 = await compare2(left[key], right[key], budget);
9991
- if (result2) return result2;
9992
- }
9993
- }
9994
- return 0;
9995
- }
9996
- function equal(left, right, budget) {
9997
- budget.step();
9998
- if (left === right) return true;
9999
- if (isNumber(left) && isNumber(right)) return compareNumbers(left, right, budget) === 0;
10000
- if (Array.isArray(left) && Array.isArray(right)) return left.length === right.length && left.every((value2, index) => equal(value2, right[index], budget));
10001
- if (isObject(left) && isObject(right)) {
10002
- const keys = objectKeys(left);
10003
- return keys.length === objectKeys(right).length && keys.every((key) => Object.hasOwn(right, key) && equal(left[key], right[key], budget));
10004
- }
10005
- return false;
10006
- }
10007
- async function* entries(value2, budget) {
10008
- budget.signal.throwIfAborted();
10009
- if (Array.isArray(value2)) {
10010
- budget.collection(value2.length);
10011
- for (let index = 0; index < value2.length; index++) {
10012
- await budget.tick(2);
10013
- yield [index, value2[index]];
10014
- }
10015
- return;
10016
- }
10017
- if (isObject(value2)) {
10018
- let count2 = 0;
10019
- for (const key of objectKeyIterator(value2)) {
10020
- await budget.tick(2);
10021
- budget.collection(++count2);
10022
- yield [key, value2[key]];
10023
- }
10024
- return;
10025
- }
10026
- throw new JqError(`Cannot iterate over ${describe(value2, budget)}`);
10027
- }
10028
- function indexValue(value2, index) {
10029
- if (typeof index === "string") {
10030
- if (value2 === null) return null;
10031
- if (isObject(value2)) return Object.hasOwn(value2, index) ? value2[index] : null;
10032
- } else if (isNumber(index) && Number.isFinite(numberValue(index))) {
10033
- if (value2 === null) return null;
10034
- const integer9 = Math.trunc(numberValue(index));
10035
- if (Array.isArray(value2)) return value2[integer9 < 0 ? value2.length + integer9 : integer9] ?? null;
10036
- }
10037
- throw new JqError(`Cannot index ${type(value2)} with ${type(index)}${typeof index === "string" && import_buffer.Buffer.byteLength(index) < 30 ? ` ${JSON.stringify(index)}` : ""}`);
10038
- }
10039
- async function sliceValue(value2, start, end, budget) {
10040
- if (start !== null && (!isNumber(start) || !Number.isSafeInteger(numberValue(start)))) throw new JqError("slice start must be an integer or null");
10041
- if (end !== null && (!isNumber(end) || !Number.isSafeInteger(numberValue(end)))) throw new JqError("slice end must be an integer or null");
10042
- budget.signal.throwIfAborted();
10043
- let first = start === null ? 0 : numberValue(start);
10044
- let last = end === null ? void 0 : numberValue(end);
10045
- if (value2 === null) return null;
10046
- if (Array.isArray(value2)) return value2.slice(first, last);
10047
- if (typeof value2 !== "string") throw new JqError(`cannot slice ${type(value2)}`);
10048
- if (last === 0 || last !== void 0 && first < 0 === last < 0 && first >= last) return "";
10049
- if (first < 0 || last !== void 0 && last < 0) {
10050
- let length = 0;
10051
- for (let offset2 = 0; offset2 < value2.length; length++) {
10052
- await budget.tick();
10053
- offset2 += value2.codePointAt(offset2) > 65535 ? 2 : 1;
10054
- }
10055
- if (first < 0) first = Math.max(0, length + first);
10056
- if (last !== void 0 && last < 0) last = Math.max(0, length + last);
10057
- if (last !== void 0 && first >= last) return "";
10058
- }
10059
- let firstOffset = first === 0 ? 0 : value2.length;
10060
- let offset = 0;
10061
- const stop = last ?? first;
10062
- for (let point = 0; point < stop && offset < value2.length; ) {
10063
- await budget.tick();
10064
- offset += value2.codePointAt(offset) > 65535 ? 2 : 1;
10065
- if (++point === first) firstOffset = offset;
10066
- }
10067
- return value2.slice(firstOffset, last === void 0 ? void 0 : offset);
10068
- }
10069
- function contains(value2, sought, budget) {
10070
- budget.step();
10071
- if (typeof value2 === "string" && typeof sought === "string") return value2.includes(sought);
10072
- if (Array.isArray(value2) && Array.isArray(sought)) return sought.every((item) => value2.some((candidate) => contains(candidate, item, budget)));
10073
- if (isObject(value2) && isObject(sought)) return objectKeys(sought).every((key) => Object.hasOwn(value2, key) && contains(value2[key], sought[key], budget));
10074
- return type(value2) === type(sought) && equal(value2, sought, budget);
10075
- }
10076
- async function binary(operator, left, right, budget) {
10077
- budget.step();
10078
- if (["==", "!=", "<", "<=", ">", ">="].includes(operator)) {
10079
- if (operator === "==") return equal(left, right, budget);
10080
- if (operator === "!=") return !equal(left, right, budget);
10081
- const order = await compare2(left, right, budget);
10082
- switch (operator) {
10083
- case "<":
10084
- return order < 0;
10085
- case "<=":
10086
- return order <= 0;
10087
- case ">":
10088
- return order > 0;
10089
- default:
10090
- return order >= 0;
10091
- }
10092
- }
10093
- if (operator === "+") {
10094
- if (left === null) return right;
10095
- if (right === null) return left;
10096
- if (isNumber(left) && isNumber(right)) return numberValue(left) + numberValue(right);
10097
- if (typeof left === "string" && typeof right === "string") {
10098
- budget.step(left.length + right.length);
10099
- const result2 = left + right;
10100
- budget.text(result2);
10101
- return result2;
10102
- }
10103
- if (Array.isArray(left) && Array.isArray(right)) {
10104
- budget.collection(left.length + right.length);
10105
- return [...left, ...right];
10106
- }
10107
- if (isObject(left) && isObject(right)) {
10108
- const result2 = copyObject(left, right);
10109
- budget.collection(objectKeys(result2).length);
10110
- return result2;
10111
- }
10112
- }
10113
- if (operator === "-" && Array.isArray(left) && Array.isArray(right)) return left.filter((item) => !right.some((other) => equal(item, other, budget)));
10114
- if (operator === "*" && isObject(left) && isObject(right)) {
10115
- const result2 = copyObject(left);
10116
- for (const key of objectKeys(right)) {
10117
- const value2 = right[key];
10118
- put(result2, key, Object.hasOwn(left, key) && isObject(left[key]) && isObject(value2) ? await binary("*", left[key], value2, budget) : value2);
10119
- }
10120
- budget.collection(objectKeys(result2).length);
10121
- return result2;
10122
- }
10123
- if (operator === "*" && (typeof left === "string" && isNumber(right) || typeof right === "string" && isNumber(left))) {
10124
- const text3 = typeof left === "string" ? left : right;
10125
- const count2 = numberValue(isNumber(left) ? left : right);
10126
- if (count2 < 0) return null;
10127
- if (text3 === "") return "";
10128
- if (!Number.isFinite(count2) || import_buffer.Buffer.byteLength(text3) * Math.floor(count2) > budget.limits.maxValueBytes) throw new JqLimitError("maxValueBytes");
10129
- const result2 = text3.repeat(Math.floor(count2));
10130
- budget.text(result2);
10131
- return result2;
10132
- }
10133
- if (operator === "/" && typeof left === "string" && typeof right === "string") {
10134
- const result2 = right === "" ? Array.from(left) : left.split(right);
10135
- budget.collection(result2.length);
10136
- return result2;
10137
- }
10138
- if (isNumber(left) && isNumber(right)) {
10139
- const first = numberValue(left);
10140
- const second = numberValue(right);
10141
- if (operator === "%" && (Number.isNaN(first) || Number.isNaN(second))) return NaN;
10142
- if (operator === "/" && second === 0 || operator === "%" && Math.trunc(second) === 0) throw new JqError(`${describe(left, budget)} and ${describe(right, budget)} cannot be divided${operator === "%" ? " (remainder)" : ""} because the divisor is zero`);
10143
- if (operator === "-") return first - second;
10144
- if (operator === "*") return first * second;
10145
- if (operator === "/") return first / second;
10146
- if (operator === "%") {
10147
- const integer9 = (value2) => value2 >= 2 ** 63 ? 9223372036854775807n : value2 <= -(2 ** 63) ? -9223372036854775808n : BigInt(Math.trunc(value2));
10148
- return Number(integer9(first) % integer9(second));
10149
- }
10150
- }
10151
- if (operator === "+") throw new JqError(`${describe(left, budget)} and ${describe(right, budget)} cannot be added`);
10152
- if (operator === "-") throw new JqError(`${describe(left, budget)} and ${describe(right, budget)} cannot be subtracted`);
10153
- throw new JqError(`cannot apply ${operator} to ${type(left)} and ${type(right)}`);
10154
- }
10155
-
10156
- // packages/safe-bash/src/commands/structured/interpreter.ts
10157
- var deleted = /* @__PURE__ */ Symbol("deleted");
10158
- var Interpreter = class _Interpreter {
10159
- constructor(budget, variables, frame) {
10160
- this.budget = budget;
10161
- this.variables = variables;
10162
- this.frame = frame;
10163
- }
10164
- budget;
10165
- variables;
10166
- frame;
10167
- async collect(ast, input3) {
10168
- const result2 = [];
10169
- let bytes3 = 2;
10170
- for await (const value2 of this.run(ast, input3)) {
10171
- this.budget.collection(result2.length + 1);
10172
- bytes3 += this.budget.value(value2) + (result2.length ? 1 : 0);
10173
- if (bytes3 > this.budget.limits.maxValueBytes) throw new JqLimitError("maxValueBytes");
10174
- result2.push(value2);
10175
- }
10176
- this.budget.value(result2);
10177
- return result2;
10178
- }
10179
- async *run(ast, input3) {
10180
- await this.budget.tick();
10181
- switch (ast.kind) {
10182
- case "identity":
10183
- yield input3;
10184
- return;
10185
- case "literal":
10186
- yield ast.value;
10187
- return;
10188
- case "variable": {
10189
- for (let frame = this.frame; frame; frame = frame.parent) {
10190
- await this.budget.tick();
10191
- if (frame.name === ast.name) {
10192
- yield frame.value;
10193
- return;
10194
- }
10195
- }
10196
- yield this.variables.get(ast.name);
10197
- return;
10198
- }
10199
- case "descend":
10200
- yield* this.descend(input3);
10201
- return;
10202
- case "try":
10203
- try {
10204
- yield* this.run(ast.body, input3);
10205
- } catch (error) {
10206
- if (!(error instanceof JqError) || error instanceof JqLimitError || this.budget.signal.aborted) throw error;
10207
- if (ast.handler) yield* this.run(ast.handler, error.message);
10208
- }
10209
- return;
10210
- case "reduce":
10211
- case "foreach": {
10212
- const depth = (this.frame?.depth ?? 0) + 1;
10213
- if (depth > this.budget.limits.maxAstDepth) throw new JqLimitError("maxAstDepth");
10214
- let sourceInput = input3;
10215
- for await (const initial of this.run(ast.init, input3)) {
10216
- let accumulator = initial;
10217
- for await (const value2 of this.run(ast.source, sourceInput)) {
10218
- await this.budget.tick();
10219
- const scope = new _Interpreter(this.budget, this.variables, { name: ast.name, value: value2, parent: this.frame, depth });
10220
- const previous = accumulator;
10221
- accumulator = null;
10222
- for await (const updated of scope.run(ast.update, previous)) {
10223
- await this.budget.tick();
10224
- accumulator = updated;
10225
- if (ast.kind === "foreach") {
10226
- if (ast.extract) yield* scope.run(ast.extract, updated);
10227
- else yield updated;
10228
- }
10229
- }
10230
- }
10231
- if (ast.kind === "reduce") {
10232
- sourceInput = null;
10233
- yield accumulator;
10234
- }
10235
- }
10236
- return;
10237
- }
10238
- case "unary":
10239
- for await (const value2 of this.run(ast.operand, input3)) {
10240
- if (!isNumber(value2)) throw new JqError("negation requires a number");
10241
- yield -numberValue(value2);
10242
- }
10243
- return;
10244
- case "optional":
10245
- try {
10246
- yield* this.run(ast.operand, input3);
10247
- } catch (error) {
10248
- if (!(error instanceof JqError) || error instanceof JqLimitError || this.budget.signal.aborted) throw error;
10249
- }
10250
- return;
10251
- case "index":
10252
- for await (const index of this.run(ast.index, input3)) for await (const base of this.run(ast.base, input3)) yield indexValue(base, index);
10253
- return;
10254
- case "slice":
10255
- for await (const start of ast.start ? this.run(ast.start, input3) : [null])
10256
- for await (const end of ast.end ? this.run(ast.end, input3) : [null])
10257
- for await (const base of this.run(ast.base, input3)) {
10258
- await this.budget.tick();
10259
- yield await sliceValue(base, start, end, this.budget);
10260
- }
10261
- return;
10262
- case "iterate":
10263
- for await (const base of this.run(ast.base, input3)) for await (const [, value2] of entries(base, this.budget)) {
10264
- await this.budget.tick();
10265
- yield value2;
10266
- }
10267
- return;
10268
- case "array":
10269
- yield ast.body ? await this.collect(ast.body, input3) : [];
10270
- return;
10271
- case "object": {
10272
- if (!ast.fields.length) {
10273
- yield object();
10274
- return;
10275
- }
10276
- const stack = [this.field(ast.fields[0], object(), input3)];
10277
- try {
10278
- while (stack.length) {
10279
- const next = await stack[stack.length - 1].next();
10280
- if (next.done) {
10281
- stack.pop();
10282
- continue;
10283
- }
10284
- if (stack.length === ast.fields.length) yield next.value;
10285
- else stack.push(this.field(ast.fields[stack.length], next.value, input3));
10286
- }
10287
- } finally {
10288
- for (const iterator of stack.reverse()) await iterator.return(void 0);
10289
- }
10290
- return;
10291
- }
10292
- case "if":
10293
- for await (const condition of this.run(ast.condition, input3)) yield* this.run(truth(condition) ? ast.yes : ast.no, input3);
10294
- return;
10295
- case "binary": {
10296
- const operator = ast.operator;
10297
- if (operator === "|") {
10298
- for await (const value2 of this.run(ast.left, input3)) yield* this.run(ast.right, value2);
10299
- return;
10300
- }
10301
- if (operator === ",") {
10302
- yield* this.run(ast.left, input3);
10303
- yield* this.run(ast.right, input3);
10304
- return;
10305
- }
10306
- if (operator === "//") {
10307
- let found = false;
10308
- for await (const value2 of this.run(ast.left, input3)) if (truth(value2)) {
10309
- found = true;
10310
- yield value2;
10311
- }
10312
- if (!found) yield* this.run(ast.right, input3);
10313
- return;
10314
- }
10315
- if (["=", "|=", "+=", "-=", "*=", "/=", "%=", "//="].includes(operator)) {
10316
- yield* this.assign(ast.left, ast.right, operator, input3);
10317
- return;
10318
- }
10319
- if (operator === "and" || operator === "or") {
10320
- for await (const left of this.run(ast.left, input3)) {
10321
- if (operator === "and" && !truth(left)) {
10322
- yield false;
10323
- continue;
10324
- }
10325
- if (operator === "or" && truth(left)) {
10326
- yield true;
10327
- continue;
10328
- }
10329
- for await (const right of this.run(ast.right, input3)) yield truth(right);
10330
- }
10331
- return;
10332
- }
10333
- for await (const right of this.run(ast.right, input3)) {
10334
- for await (const left of this.run(ast.left, input3)) {
10335
- const result2 = await binary(operator, left, right, this.budget);
10336
- this.budget.value(result2);
10337
- yield result2;
10338
- }
10339
- }
10340
- return;
10341
- }
10342
- case "call":
10343
- yield* this.call(ast.name, ast.args, input3);
10344
- return;
10345
- }
10346
- }
10347
- async *descend(input3, depth = 0) {
10348
- await this.budget.tick();
10349
- if (depth > this.budget.limits.maxDepth) throw new JqLimitError("maxDepth");
10350
- yield input3;
10351
- if (Array.isArray(input3)) {
10352
- if (depth + 1 > this.budget.limits.maxDepth) throw new JqLimitError("maxDepth");
10353
- this.budget.collection(input3.length);
10354
- for (const value2 of input3) yield* this.descend(value2, depth + 1);
10355
- } else if (isObject(input3)) {
10356
- if (depth + 1 > this.budget.limits.maxDepth) throw new JqLimitError("maxDepth");
10357
- const keys = objectKeys(input3);
10358
- this.budget.collection(keys.length);
10359
- for (const key of keys) yield* this.descend(input3[key], depth + 1);
10360
- }
10361
- }
10362
- async *field(field, previous, input3) {
10363
- for await (const key of this.run(field.key, input3)) {
10364
- if (typeof key !== "string") throw new JqError("object keys must be strings");
10365
- for await (const value2 of this.run(field.value, input3)) {
10366
- const item = copyObject(previous);
10367
- put(item, key, value2);
10368
- this.budget.value(item);
10369
- yield item;
10370
- }
10371
- }
10372
- }
10373
- async *paths(ast, input3) {
10374
- await this.budget.tick();
10375
- if (ast.kind === "identity") {
10376
- yield [];
10377
- return;
10378
- }
10379
- if (ast.kind === "binary" && ast.operator === ",") {
10380
- yield* this.paths(ast.left, input3);
10381
- yield* this.paths(ast.right, input3);
10382
- return;
10383
- }
10384
- if (ast.kind !== "index" && ast.kind !== "iterate") throw new JqError("unsupported assignment path");
10385
- if (ast.kind === "index") {
10386
- for await (const key of this.run(ast.index, input3)) for await (const path of this.paths(ast.base, input3)) {
10387
- let base = input3;
10388
- for (const component of path) base = indexValue(base, component);
10389
- if (typeof key !== "string" && (!isNumber(key) || !Number.isFinite(numberValue(key)))) throw new JqError("assignment index must be a string or finite number");
10390
- indexValue(base, key);
10391
- const integer9 = isNumber(key) ? Math.trunc(numberValue(key)) : key;
10392
- yield [...path, typeof integer9 === "number" && integer9 < 0 && Array.isArray(base) ? base.length + integer9 : integer9];
10393
- }
10394
- return;
10395
- }
10396
- for await (const path of this.paths(ast.base, input3)) {
10397
- let base = input3;
10398
- for (const component of path) base = indexValue(base, component);
10399
- for await (const [key] of entries(base, this.budget)) {
10400
- await this.budget.tick();
10401
- yield [...path, key];
10402
- }
10403
- }
10404
- }
10405
- set(input3, path, value2, depth = 0) {
10406
- this.budget.step();
10407
- if (depth > this.budget.limits.maxDepth) throw new JqLimitError("maxDepth");
10408
- if (depth === path.length) return value2 === deleted ? null : value2;
10409
- const key = path[depth];
10410
- if (value2 === deleted && (input3 === null || typeof key === "string" && isObject(input3) && !Object.hasOwn(input3, key) || typeof key === "number" && Array.isArray(input3) && (key < 0 || key >= input3.length))) return input3;
10411
- const previous = indexValue(input3, key);
10412
- const remove2 = value2 === deleted && depth === path.length - 1;
10413
- if (typeof key === "string") {
10414
- if (input3 !== null && !isObject(input3)) throw new JqError("object assignment requires object or null");
10415
- const result3 = copyObject(input3);
10416
- if (remove2) remove(result3, key);
10417
- else put(result3, key, this.set(previous, path, value2, depth + 1));
10418
- this.budget.collection(objectKeys(result3).length);
10419
- return result3;
10420
- }
10421
- if (key < 0) throw new JqError("array index out of bounds");
10422
- if (input3 !== null && !Array.isArray(input3)) throw new JqError("array assignment requires array or null");
10423
- const result2 = input3 === null ? [] : [...input3];
10424
- if (remove2) {
10425
- if (key < result2.length) result2.splice(key, 1);
10426
- } else {
10427
- this.budget.collection(Math.max(result2.length, key + 1));
10428
- while (result2.length <= key) result2.push(null);
10429
- result2[key] = this.set(previous, path, value2, depth + 1);
10430
- }
10431
- return result2;
10432
- }
10433
- async *assign(left, right, operator, input3) {
10434
- if (operator !== "|=") {
10435
- for await (const value2 of this.run(right, input3)) {
10436
- let result3 = input3;
10437
- for await (const path of this.paths(left, input3)) {
10438
- let previous = result3;
10439
- for (const key of path) previous = indexValue(previous, key);
10440
- const assigned = operator === "=" ? value2 : operator === "//=" ? truth(previous) ? previous : value2 : await binary(operator.slice(0, -1), previous, value2, this.budget);
10441
- result3 = this.set(result3, path, assigned);
10442
- this.budget.value(result3);
10443
- }
10444
- yield result3;
10445
- }
10446
- return;
10447
- }
10448
- const paths = [];
10449
- for await (const path of this.paths(left, input3)) {
10450
- this.budget.collection(paths.length + 1);
10451
- paths.push(path);
10452
- }
10453
- let result2 = input3;
10454
- const deletions = [];
10455
- for (const path of paths) {
10456
- let previous = result2;
10457
- for (const key of path) previous = indexValue(previous, key);
10458
- let value2 = deleted;
10459
- for await (const output2 of this.run(right, previous)) {
10460
- value2 = output2;
10461
- break;
10462
- }
10463
- if (value2 === deleted) deletions.push(path);
10464
- else {
10465
- result2 = this.set(result2, path, value2);
10466
- this.budget.value(result2);
10467
- }
10468
- }
10469
- await stableSort(deletions, this.budget, async (first, second) => -await compare2(first, second, this.budget));
10470
- let lastDeletion;
10471
- for (const path of deletions) {
10472
- if (!lastDeletion || await compare2(lastDeletion, path, this.budget) !== 0) result2 = this.set(result2, path, deleted);
10473
- lastDeletion = path;
10474
- }
10475
- this.budget.value(result2);
10476
- yield result2;
10477
- }
10478
- async *call(name2, args, input3) {
10479
- const budget = this.budget;
10480
- if (name2 === "empty") return;
10481
- if (name2 === "select") {
10482
- for await (const value2 of this.run(args[0], input3)) if (truth(value2)) yield input3;
10483
- return;
10484
- }
10485
- if (name2 === "values") {
10486
- if (input3 !== null) yield input3;
10487
- return;
10488
- }
10489
- const filters = { strings: "string", numbers: "number", booleans: "boolean", arrays: "array", objects: "object", nulls: "null" };
10490
- if (Object.hasOwn(filters, name2)) {
10491
- if (type(input3) === filters[name2]) yield input3;
10492
- return;
10493
- }
10494
- if (name2 === "scalars" || name2 === "iterables") {
10495
- if ((isObject(input3) || Array.isArray(input3)) === (name2 === "iterables")) yield input3;
10496
- return;
10497
- }
10498
- if (name2 === "type") {
10499
- yield type(input3);
10500
- return;
10501
- }
10502
- if (name2 === "nan" || name2 === "infinite") {
10503
- yield name2 === "nan" ? NaN : Infinity;
10504
- return;
10505
- }
10506
- if (name2 === "isnan" || name2 === "isinfinite" || name2 === "isfinite") {
10507
- const value2 = isNumber(input3) ? numberValue(input3) : void 0;
10508
- const infinite = value2 === Infinity || value2 === -Infinity;
10509
- yield name2 === "isnan" ? value2 !== void 0 && Number.isNaN(value2) : name2 === "isinfinite" ? infinite : value2 !== void 0 && !infinite;
10510
- return;
10511
- }
10512
- if (name2 === "not") {
10513
- yield !truth(input3);
10514
- return;
10515
- }
10516
- if (name2 === "length") {
10517
- if (input3 === null) yield 0;
10518
- else if (isNumber(input3)) yield Math.abs(numberValue(input3));
10519
- else if (typeof input3 === "string") {
10520
- await budget.tick(input3.length);
10521
- let length = 0;
10522
- for (let offset = 0; offset < input3.length; length++) {
10523
- if (length % 32 === 0) await budget.tick(0);
10524
- offset += input3.codePointAt(offset) > 65535 ? 2 : 1;
10525
- }
10526
- yield length;
10527
- } else if (Array.isArray(input3)) yield input3.length;
10528
- else if (isObject(input3)) {
10529
- let length = 0;
10530
- for (const key of objectKeyIterator(input3)) {
10531
- await budget.tick();
10532
- void key;
10533
- length++;
10534
- }
10535
- yield length;
10536
- } else throw new JqError("boolean has no length");
10537
- return;
10538
- }
10539
- if (name2 === "keys" || name2 === "keys_unsorted") {
10540
- let result2;
10541
- if (Array.isArray(input3)) {
10542
- budget.collection(input3.length);
10543
- await budget.tick(input3.length);
10544
- result2 = [];
10545
- let bytes3 = 2;
10546
- if (bytes3 > budget.limits.maxValueBytes) throw new JqLimitError("maxValueBytes");
10547
- for (let index = 0; index < input3.length; index++) {
10548
- await budget.tick();
10549
- bytes3 += String(index).length + (index ? 1 : 0);
10550
- if (bytes3 > budget.limits.maxValueBytes) throw new JqLimitError("maxValueBytes");
10551
- result2.push(index);
10552
- }
10553
- } else if (isObject(input3)) {
10554
- let bytes3 = 2;
10555
- let count2 = 0;
10556
- if (bytes3 > budget.limits.maxValueBytes) throw new JqLimitError("maxValueBytes");
10557
- for (const key of objectKeyIterator(input3)) {
10558
- await budget.tick();
10559
- budget.collection(++count2);
10560
- const separator = count2 > 1 ? 1 : 0;
10561
- bytes3 += separator + await measureValue(key, budget, 1, budget.limits.maxValueBytes - bytes3 - separator);
10562
- }
10563
- if (name2 === "keys") result2 = await sortedKeys(input3, budget);
10564
- else {
10565
- result2 = [];
10566
- for (const key of objectKeyIterator(input3)) {
10567
- await budget.tick();
10568
- budget.collection(result2.length + 1);
10569
- result2.push(key);
10570
- }
10571
- }
10572
- } else throw new JqError("keys requires an object or array");
10573
- yield result2;
10574
- return;
10575
- }
10576
- if (name2 === "map" || name2 === "map_values") {
10577
- const result2 = name2 === "map_values" && isObject(input3) ? object() : [];
10578
- let bytes3 = 2;
10579
- for await (const [key, value2] of entries(input3, budget)) for await (const mapped of this.run(args[0], value2)) {
10580
- bytes3 += budget.value(mapped) + 1 + (Array.isArray(result2) ? 0 : import_buffer.Buffer.byteLength(JSON.stringify(String(key))) + 1);
10581
- if (bytes3 - 1 > budget.limits.maxValueBytes) throw new JqLimitError("maxValueBytes");
10582
- if (Array.isArray(result2)) {
10583
- budget.collection(result2.length + 1);
10584
- result2.push(mapped);
10585
- } else put(result2, String(key), mapped);
10586
- if (name2 === "map_values") break;
10587
- }
10588
- budget.value(result2);
10589
- yield result2;
10590
- return;
10591
- }
10592
- if (name2 === "has" || name2 === "contains") {
10593
- for await (const argument2 of this.run(args[0], input3)) {
10594
- if (name2 === "contains") {
10595
- if (type(input3) !== type(argument2)) throw new JqError("contains requires matching types");
10596
- yield contains(input3, argument2, budget);
10597
- } else if (input3 === null) yield false;
10598
- else if (isObject(input3) && typeof argument2 === "string") yield Object.hasOwn(input3, argument2);
10599
- else if (Array.isArray(input3) && isNumber(argument2)) yield Math.trunc(numberValue(argument2)) >= 0 && Math.trunc(numberValue(argument2)) < input3.length;
10600
- else throw new JqError("has requires object/string or array/number");
10601
- }
10602
- return;
10603
- }
10604
- if (name2 === "split") {
10605
- for await (const separator of this.run(args[0], input3)) {
10606
- yield await splitString2(input3, separator, budget);
10607
- }
10608
- return;
10609
- }
10610
- if (name2 === "join") {
10611
- for await (const separator of this.run(args[0], input3)) {
10612
- const separatorBytes = budget.value(separator);
10613
- let result2 = "";
10614
- let bytes3 = 2;
10615
- let first = true;
10616
- const append = (text3, encodedBytes) => {
10617
- bytes3 += encodedBytes - 2;
10618
- if (bytes3 > budget.limits.maxValueBytes) throw new JqLimitError("maxValueBytes");
10619
- result2 += text3;
10620
- };
10621
- for await (const [, item] of entries(input3, budget)) {
10622
- await budget.tick();
10623
- if (!first && separator !== null) {
10624
- if (typeof separator !== "string") await binary("+", result2, separator, budget);
10625
- if (typeof separator !== "string") throw new JqError("join separator must be a string or null when used");
10626
- append(separator, separatorBytes);
10627
- }
10628
- first = false;
10629
- if (isObject(item) || Array.isArray(item)) await binary("+", result2, item, budget);
10630
- const text3 = item === null ? "" : typeof item === "string" ? item : await stringify(item, budget);
10631
- append(text3, budget.value(text3));
10632
- }
10633
- budget.value(result2);
10634
- yield result2;
10635
- }
10636
- return;
10637
- }
10638
- if (name2 === "first" || name2 === "last") {
10639
- if (!args.length) {
10640
- if (!Array.isArray(input3) && input3 !== null) throw new JqError(`${name2} requires an array`);
10641
- yield input3 === null ? null : input3[name2 === "first" ? 0 : input3.length - 1] ?? null;
10642
- return;
10643
- }
10644
- let last;
10645
- for await (const value2 of this.run(args[0], input3)) {
10646
- if (name2 === "first") {
10647
- yield value2;
10648
- return;
10649
- }
10650
- last = value2;
10651
- }
10652
- if (name2 === "last") yield last ?? null;
10653
- return;
10654
- }
10655
- if (name2 === "limit") {
10656
- for await (const argument2 of this.run(args[0], input3)) {
10657
- if (!isNumber(argument2) || !Number.isSafeInteger(numberValue(argument2)) || numberValue(argument2) < 0) throw new JqError("limit requires a nonnegative integer");
10658
- const count2 = numberValue(argument2);
10659
- if (count2 === 0) continue;
10660
- let emitted = 0;
10661
- for await (const value2 of this.run(args[1], input3)) {
10662
- yield value2;
10663
- if (++emitted >= count2) break;
10664
- }
10665
- }
10666
- return;
10667
- }
10668
- if (name2 === "range") {
10669
- for await (const start of args.length === 1 ? [0] : this.run(args[0], input3))
10670
- for await (const end of this.run(args[args.length === 1 ? 0 : 1], input3))
10671
- for await (const increment of args[2] ? this.run(args[2], input3) : [1]) {
10672
- if (!isNumber(start) || !isNumber(end) || !isNumber(increment)) throw new JqError("range requires numbers");
10673
- const step = numberValue(increment);
10674
- const stop = numberValue(end);
10675
- if (step === 0) continue;
10676
- for (let value2 = start; step > 0 ? numberValue(value2) < stop : numberValue(value2) > stop; ) {
10677
- await budget.tick();
10678
- yield value2;
10679
- const next = numberValue(value2) + step;
10680
- if (!Number.isFinite(next)) throw new JqError("nonfinite range increment");
10681
- if (next === numberValue(value2)) throw new JqError("range increment makes no progress");
10682
- value2 = next;
10683
- }
10684
- }
10685
- return;
10686
- }
10687
- if (name2 === "tostring" || name2 === "tojson") {
10688
- if (typeof input3 === "string" && name2 === "tostring") {
10689
- await measureValue(input3, budget);
10690
- yield input3;
10691
- } else yield await stringify(input3, budget, false, budget.limits.maxValueBytes, "maxValueBytes", true);
10692
- return;
10693
- }
10694
- if (name2 === "tonumber" || name2 === "fromjson") {
10695
- if (name2 === "tonumber" && isNumber(input3)) {
10696
- yield input3;
10697
- return;
10698
- }
10699
- if (typeof input3 !== "string") throw new JqError(name2 === "fromjson" ? `${describe(input3, budget)} only strings can be parsed` : `${describe(input3, budget)} cannot be parsed as a number`);
10700
- let result2;
10701
- try {
10702
- result2 = parseJson(input3, budget);
10703
- } catch (error) {
10704
- if (!(error instanceof JqParseError)) throw error;
10705
- throw new JqError(`${error.diagnostic()} (while parsing '${input3.split("\0", 1)[0]}')`);
10706
- }
10707
- if (name2 === "tonumber" && !isNumber(result2)) throw new JqError(`${describe(input3, budget)} cannot be parsed as a number`);
10708
- yield result2;
10709
- return;
10710
- }
10711
- if (name2 === "to_entries") {
10712
- if (Array.isArray(input3)) await budget.tick(input3.length);
10713
- const result2 = [];
10714
- let bytes3 = 2;
10715
- if (bytes3 > budget.limits.maxValueBytes) throw new JqLimitError("maxValueBytes");
10716
- for await (const [key, value2] of entries(input3, budget)) {
10717
- budget.collection(result2.length + 1);
10718
- budget.collection(2);
10719
- const overhead = 17 + (result2.length ? 1 : 0);
10720
- const keyBytes3 = await measureValue(key, budget, 2, budget.limits.maxValueBytes - bytes3 - overhead);
10721
- const valueBytes = await measureValue(value2, budget, 2, budget.limits.maxValueBytes - bytes3 - overhead - keyBytes3);
10722
- await budget.tick(4);
10723
- bytes3 += overhead + keyBytes3 + valueBytes;
10724
- const entry = object();
10725
- put(entry, "key", key);
10726
- put(entry, "value", value2);
10727
- result2.push(entry);
10728
- }
10729
- yield result2;
10730
- return;
10731
- }
10732
- if (name2 === "from_entries" || name2 === "with_entries") {
10733
- let values = input3;
10734
- if (name2 === "with_entries") {
10735
- values = [];
10736
- let bytes3 = 2;
10737
- for await (const [key, value2] of entries(input3, budget)) for await (const mapped of this.run(args[0], copyObject({ key, value: value2 }))) {
10738
- budget.collection(values.length + 1);
10739
- bytes3 += budget.value(mapped) + (values.length ? 1 : 0);
10740
- if (bytes3 > budget.limits.maxValueBytes) throw new JqLimitError("maxValueBytes");
10741
- values.push(mapped);
10742
- }
10743
- }
10744
- const result2 = object();
10745
- for await (const [, entry] of entries(values, budget)) {
10746
- await budget.tick();
10747
- if (!isObject(entry)) throw new JqError(`Cannot index ${type(entry)} with string "key"`);
10748
- const key = ["key", "Key", "name", "Name"].find((candidate) => Object.hasOwn(entry, candidate) && truth(entry[candidate]));
10749
- const value2 = ["value", "Value"].find((candidate) => Object.hasOwn(entry, candidate));
10750
- if (key === void 0 || typeof entry[key] !== "string") throw new JqError("from_entries requires string keys");
10751
- put(result2, entry[key], value2 === void 0 ? null : entry[value2]);
10752
- }
10753
- budget.value(result2);
10754
- yield result2;
10755
- return;
10756
- }
10757
- if (name2 === "any" || name2 === "all") {
10758
- const generator = args.length === 2 ? args[0] : { kind: "iterate", base: { kind: "identity" } };
10759
- const condition = args[args.length === 2 ? 1 : 0] ?? { kind: "identity" };
10760
- for await (const item of this.run(generator, input3)) {
10761
- for await (const value2 of this.run(condition, item)) {
10762
- await budget.tick();
10763
- if (truth(value2) === (name2 === "any")) {
10764
- yield name2 === "any";
10765
- return;
10766
- }
10767
- }
10768
- }
10769
- yield name2 === "all";
10770
- return;
10771
- }
10772
- if (!Array.isArray(input3)) {
10773
- if (name2 === "unique" && !isObject(input3)) throw new JqError(`Cannot iterate over ${describe(input3, budget)}`);
10774
- if (name2 === "sort") throw new JqError(`${describe(input3, budget)} cannot be sorted, as it is not an array`);
10775
- throw new JqError(`${name2} requires an array`);
10776
- }
10777
- if (name2 === "reverse") {
10778
- await budget.tick(input3.length);
10779
- await measureValue(input3, budget);
10780
- const result2 = [];
10781
- for (let index = input3.length - 1; index >= 0; index--) {
10782
- await budget.tick(0);
10783
- result2.push(input3[index]);
10784
- }
10785
- yield result2;
10786
- return;
10787
- }
10788
- if (name2 === "add") {
10789
- let result2 = null;
10790
- for (const item of input3) {
10791
- await budget.tick();
10792
- result2 = await binary("+", result2, item, budget);
10793
- budget.value(result2);
10794
- }
10795
- yield result2;
10796
- return;
10797
- }
10798
- const keyed = [];
10799
- let keyBytes2 = 0;
10800
- for (const value2 of input3) {
10801
- await budget.tick();
10802
- const key = args[0] ? await this.collect(args[0], value2) : value2;
10803
- keyBytes2 += budget.value(key);
10804
- if (keyBytes2 > budget.limits.maxValueBytes) throw new JqLimitError("maxValueBytes");
10805
- keyed.push({ value: value2, key });
10806
- }
10807
- await stableSort(keyed, budget, (left, right) => compare2(left.key, right.key, budget));
10808
- if (name2 === "min" || name2 === "min_by" || name2 === "max" || name2 === "max_by") {
10809
- yield keyed[name2.startsWith("min") ? 0 : keyed.length - 1]?.value ?? null;
10810
- return;
10811
- }
10812
- if (name2 === "sort" || name2 === "sort_by") {
10813
- yield keyed.map((item) => item.value);
10814
- return;
10815
- }
10816
- if (name2 === "unique" || name2 === "unique_by") {
10817
- yield keyed.filter((item, index) => index === 0 || !equal(item.key, keyed[index - 1].key, budget)).map((item) => item.value);
10818
- return;
10819
- }
10820
- if (name2 === "group_by") {
10821
- const groups = [];
10822
- let previous;
10823
- for (const item of keyed) {
10824
- if (previous === void 0 || !equal(previous, item.key, budget)) groups.push([]);
10825
- groups[groups.length - 1].push(item.value);
10826
- previous = item.key;
10827
- }
10828
- budget.value(groups);
10829
- yield groups;
10830
- return;
10831
- }
10832
- throw new JqError(`unsupported function ${name2}`);
10833
- }
10834
- };
10835
-
10836
- // packages/safe-bash/src/commands/structured/parser.ts
10837
- init_platform();
10838
- var precedence = Object.freeze({
10839
- "|": 1,
10840
- ",": 2,
10841
- "=": 3,
10842
- "|=": 3,
10843
- "+=": 3,
10844
- "-=": 3,
10845
- "*=": 3,
10846
- "/=": 3,
10847
- "%=": 3,
10848
- "//=": 3,
10849
- "//": 4,
10850
- or: 5,
10851
- and: 6,
10852
- "==": 7,
10853
- "!=": 7,
10854
- "<": 7,
10855
- ">": 7,
10856
- "<=": 7,
10857
- ">=": 7,
10858
- "+": 8,
10859
- "-": 8,
10860
- "*": 9,
10861
- "/": 9,
10862
- "%": 9
10863
- });
10864
- var functions = Object.freeze({
10865
- empty: [0],
10866
- select: [1],
10867
- map: [1],
10868
- map_values: [1],
10869
- length: [0],
10870
- keys: [0],
10871
- keys_unsorted: [0],
10872
- values: [0],
10873
- type: [0],
10874
- has: [1],
10875
- contains: [1],
10876
- sort: [0],
10877
- sort_by: [1],
10878
- unique: [0],
10879
- unique_by: [1],
10880
- group_by: [1],
10881
- add: [0],
10882
- not: [0],
10883
- reverse: [0],
10884
- first: [0, 1],
10885
- last: [0, 1],
10886
- limit: [2],
10887
- range: [1, 2, 3],
10888
- join: [1],
10889
- split: [1],
10890
- tostring: [0],
10891
- tonumber: [0],
10892
- tojson: [0],
10893
- fromjson: [0],
10894
- to_entries: [0],
10895
- from_entries: [0],
10896
- with_entries: [1],
10897
- min: [0],
10898
- max: [0],
10899
- min_by: [1],
10900
- max_by: [1],
10901
- any: [0, 1, 2],
10902
- all: [0, 1, 2],
10903
- strings: [0],
10904
- numbers: [0],
10905
- booleans: [0],
10906
- arrays: [0],
10907
- objects: [0],
10908
- nulls: [0],
10909
- scalars: [0],
10910
- iterables: [0],
10911
- nan: [0],
10912
- infinite: [0],
10913
- isnan: [0],
10914
- isinfinite: [0],
10915
- isfinite: [0]
10916
- });
10917
- function tokenize(source2) {
10918
- const tokens2 = [];
10919
- let offset = 0;
10920
- while (offset < source2.length) {
10921
- const character = source2[offset];
10922
- if (/\s/u.test(character)) {
10923
- offset++;
10924
- continue;
10925
- }
10926
- if (character === "#") {
10927
- while (offset < source2.length && source2[offset] !== "\n") offset++;
10928
- continue;
10929
- }
10930
- const start = offset;
10931
- if (character === '"') {
10932
- offset++;
10933
- let escaped3 = false;
10934
- while (offset < source2.length) {
10935
- const current = source2[offset++];
10936
- if (!escaped3 && current === '"') break;
10937
- if (!escaped3 && current === "\\") escaped3 = true;
10938
- else escaped3 = false;
10939
- }
10940
- const text3 = source2.slice(start, offset).replace(/[\x00-\x1f]/gu, (character2) => `\\u${character2.charCodeAt(0).toString(16).padStart(4, "0")}`);
10941
- try {
10942
- if (!wellFormed(JSON.parse(text3))) throw new Error();
10943
- } catch {
10944
- throw new JqError(`invalid string at offset ${start}`, 3);
10945
- }
10946
- tokens2.push({ text: text3, offset: start, kind: "string" });
10947
- continue;
10948
- }
10949
- const number4 = /^(?:[0-9]+(?:\.[0-9]*)?|\.[0-9]+)(?:[eE][+-]?[0-9]+)?/u.exec(source2.slice(offset));
10950
- if (number4) {
10951
- tokens2.push({ text: number4[0], offset, kind: "number" });
10952
- offset += number4[0].length;
10953
- continue;
10954
- }
10955
- const name2 = /^[A-Za-z_][A-Za-z_0-9]*/u.exec(source2.slice(offset));
10956
- if (name2) {
10957
- tokens2.push({ text: name2[0], offset, kind: "name" });
10958
- offset += name2[0].length;
10959
- continue;
10960
- }
10961
- if (source2.startsWith("..", offset)) {
10962
- tokens2.push({ text: "..", offset, kind: "symbol" });
10963
- offset += 2;
10964
- continue;
10965
- }
10966
- const symbol = /^(?:\/\/=|\|=|\+=|-=|\*=|\/=|%=|==|!=|<=|>=|\/\/|[.\[\]{}(),:;?$|+*/%<>=-])/u.exec(source2.slice(offset));
10967
- if (!symbol) throw new JqError(`unexpected character at offset ${offset}`, 3);
10968
- tokens2.push({ text: symbol[0], offset, kind: "symbol" });
10969
- offset += symbol[0].length;
10970
- }
10971
- tokens2.push({ text: "", offset, kind: "end" });
10972
- return tokens2;
10973
- }
10974
- function isPath(ast) {
10975
- const pending = [ast];
10976
- while (pending.length) {
10977
- const node = pending.pop();
10978
- if (node.kind === "identity") continue;
10979
- if (node.kind === "index" || node.kind === "iterate") pending.push(node.base);
10980
- else if (node.kind === "binary" && node.operator === ",") pending.push(node.left, node.right);
10981
- else return false;
10982
- }
10983
- return true;
10984
- }
10985
- function parse2(source2, variables, budget) {
10986
- const limits = budget.limits;
10987
- if (import_buffer.Buffer.byteLength(source2) > limits.maxSourceBytes) throw new JqLimitError("maxSourceBytes");
10988
- const tokens2 = tokenize(source2);
10989
- let position = 0;
10990
- let nesting = 0;
10991
- const unresolved = /* @__PURE__ */ new Map();
10992
- const bindings = /* @__PURE__ */ new Map();
10993
- const peek = () => tokens2[Math.min(position, tokens2.length - 1)];
10994
- const take = () => {
10995
- const token = peek();
10996
- if (token.kind !== "end") position++;
10997
- return token;
10998
- };
10999
- const accept = (text3) => {
11000
- if (peek().text !== text3) return false;
11001
- take();
11002
- return true;
11003
- };
11004
- const fail4 = (message3) => {
11005
- throw new JqError(`${message3} at offset ${peek().offset}`, 3);
11006
- };
11007
- const diagnostic4 = (token, message3) => {
11008
- const prefix3 = source2.slice(0, token.offset);
11009
- const line = prefix3.split("\n").length;
11010
- const start = prefix3.lastIndexOf("\n") + 1;
11011
- const end = source2.indexOf("\n", start);
11012
- const context2 = source2.slice(start, end < 0 ? source2.length : end);
11013
- return `error: ${message3} at <top-level>, line ${line}:
11014
- ${context2}${" ".repeat(import_buffer.Buffer.byteLength(prefix3.slice(start)))}`;
11015
- };
11016
- const syntaxError = (token, expectEnd = false) => {
11017
- const name2 = token.kind === "end" ? "end of file" : token.kind === "name" ? "IDENT" : token.kind === "number" || token.kind === "string" ? "LITERAL" : `'${token.text}'`;
11018
- const location = token.kind === "end" ? tokens2[Math.max(0, position - 1)] : token;
11019
- throw new JqError(`${diagnostic4(location, `syntax error, unexpected ${name2}${expectEnd ? ", expecting end of file" : ""} (Unix shell quoting issues?)`)}
11020
- jq: 1 compile error`, 3);
11021
- };
11022
- const expect = (text3) => {
11023
- if (!accept(text3)) fail4(`expected '${text3}'`);
11024
- };
11025
- const literal = (value2) => ({ kind: "literal", value: value2 });
11026
- const conditional = () => {
11027
- const condition = expression();
11028
- expect("then");
11029
- const yes = expression();
11030
- if (accept("elif")) return { kind: "if", condition, yes, no: guardedConditional() };
11031
- expect("else");
11032
- const no = expression();
11033
- expect("end");
11034
- return { kind: "if", condition, yes, no };
11035
- };
11036
- const guardedConditional = () => {
11037
- if (++nesting > limits.maxAstDepth) throw new JqLimitError("maxAstDepth");
11038
- try {
11039
- return conditional();
11040
- } finally {
11041
- nesting--;
11042
- }
11043
- };
11044
- const expression = (minimum = 0, stopComma = false) => {
11045
- if (++nesting > limits.maxAstDepth) throw new JqLimitError("maxAstDepth");
11046
- try {
11047
- let left = primary();
11048
- while (true) {
11049
- const operator = peek().text;
11050
- const priority = Object.hasOwn(precedence, operator) ? precedence[operator] : -1;
11051
- if (priority < minimum || stopComma && operator === ",") break;
11052
- take();
11053
- const assignment = priority === 3;
11054
- if (assignment && !isPath(left)) fail4("unsupported assignment path");
11055
- const right = expression(priority + (assignment ? 0 : 1), stopComma);
11056
- left = { kind: "binary", operator, left, right };
11057
- }
11058
- return left;
11059
- } finally {
11060
- nesting--;
11061
- }
11062
- };
11063
- const primary = () => {
11064
- const token = take();
11065
- let result2;
11066
- if (token.text === "..") result2 = { kind: "descend" };
11067
- else if (token.text === "try") {
11068
- const body = expression(10);
11069
- result2 = { kind: "try", body, handler: accept("catch") ? expression(10) : void 0 };
11070
- } else if (token.text === "reduce" || token.text === "foreach") {
11071
- const source3 = expression(10);
11072
- expect("as");
11073
- expect("$");
11074
- const name2 = take();
11075
- if (name2.kind !== "name") fail4("expected variable name");
11076
- expect("(");
11077
- const init = expression();
11078
- expect(";");
11079
- const previous = bindings.get(name2.text) ?? 0;
11080
- bindings.set(name2.text, previous + 1);
11081
- try {
11082
- const update = expression();
11083
- const extract = token.text === "foreach" && accept(";") ? expression() : void 0;
11084
- expect(")");
11085
- result2 = { kind: token.text, source: source3, name: name2.text, init, update, extract };
11086
- } finally {
11087
- if (previous) bindings.set(name2.text, previous);
11088
- else bindings.delete(name2.text);
11089
- }
11090
- } else if (token.text === ".") {
11091
- result2 = { kind: "identity" };
11092
- if (peek().kind === "name" && peek().offset === token.offset + 1 || peek().kind === "string") {
11093
- const key = take();
11094
- result2 = { kind: "index", base: result2, index: literal(key.kind === "string" ? JSON.parse(key.text) : key.text) };
11095
- }
11096
- } else if (token.text === "(") {
11097
- result2 = expression();
11098
- expect(")");
11099
- } else if (token.text === "[") {
11100
- result2 = { kind: "array", body: peek().text === "]" ? void 0 : expression() };
11101
- expect("]");
11102
- } else if (token.text === "{") {
11103
- const fields2 = [];
11104
- if (peek().text !== "}") do {
11105
- const keyToken = take();
11106
- let key;
11107
- if (keyToken.text === "(") {
11108
- key = expression();
11109
- expect(")");
11110
- } else if (keyToken.kind === "string" || keyToken.kind === "name") key = literal(keyToken.kind === "string" ? JSON.parse(keyToken.text) : keyToken.text);
11111
- else fail4("expected object key");
11112
- const value2 = accept(":") ? expression(0, true) : key.kind === "literal" ? { kind: "index", base: { kind: "identity" }, index: key } : fail4("expected ':'");
11113
- fields2.push({ key, value: value2 });
11114
- } while (accept(","));
11115
- expect("}");
11116
- result2 = { kind: "object", fields: fields2 };
11117
- } else if (token.text === "$") {
11118
- const name2 = take();
11119
- if (name2.kind !== "name") fail4("expected variable name");
11120
- if (!bindings.has(name2.text) && !variables.has(name2.text)) fail4(`undefined variable $${name2.text}`);
11121
- result2 = { kind: "variable", name: name2.text };
11122
- } else if (token.text === "-") result2 = { kind: "unary", operand: expression(10) };
11123
- else if (token.text === "if") result2 = guardedConditional();
11124
- else if (token.kind === "string") result2 = literal(JSON.parse(token.text));
11125
- else if (token.kind === "number") {
11126
- result2 = literal(decimalNumber(token.text, budget));
11127
- } else if (["true", "false", "null"].includes(token.text)) result2 = literal(JSON.parse(token.text));
11128
- else if (token.kind === "name") {
11129
- const args = [];
11130
- if (accept("(")) {
11131
- if (peek().text !== ")") do {
11132
- args.push(expression());
11133
- } while (accept(";"));
11134
- expect(")");
11135
- }
11136
- if (token.text === "split" && args.length === 2) fail4("unsupported function split/2");
11137
- result2 = { kind: "call", name: token.text, args };
11138
- if (!Object.hasOwn(functions, token.text) || !functions[token.text].includes(args.length)) unresolved.set(result2, token);
11139
- } else syntaxError(token, nesting === 1);
11140
- while (true) {
11141
- if (accept("?")) result2 = { kind: "optional", operand: result2 };
11142
- else if (accept(".")) {
11143
- const key = take();
11144
- if (key.kind !== "name" && key.kind !== "string") fail4("expected property name");
11145
- result2 = { kind: "index", base: result2, index: literal(key.kind === "string" ? JSON.parse(key.text) : key.text) };
11146
- } else if (accept("[")) {
11147
- if (accept("]")) result2 = { kind: "iterate", base: result2 };
11148
- else {
11149
- const start = peek().text === ":" ? void 0 : expression();
11150
- if (accept(":")) {
11151
- const end = peek().text === "]" ? void 0 : expression();
11152
- expect("]");
11153
- result2 = { kind: "slice", base: result2, start, end };
11154
- } else {
11155
- expect("]");
11156
- result2 = { kind: "index", base: result2, index: start };
11157
- }
11158
- }
11159
- } else break;
11160
- }
11161
- return result2;
11162
- };
11163
- const ast = expression();
11164
- if (peek().kind !== "end") syntaxError(peek(), true);
11165
- const pending = [{ node: ast, depth: 1 }];
11166
- const errors = [];
11167
- let errorBytes = 0;
11168
- while (pending.length) {
11169
- const { node, depth } = pending.pop();
11170
- if (depth > limits.maxAstDepth) throw new JqLimitError("maxAstDepth");
11171
- const token = unresolved.get(node);
11172
- if (token && node.kind === "call") {
11173
- const message3 = diagnostic4(token, `${node.name}/${node.args.length} is not defined`);
11174
- errorBytes += import_buffer.Buffer.byteLength(message3) + 5;
11175
- if (errorBytes > limits.maxOutputBytes) throw new JqLimitError("maxOutputBytes");
11176
- errors.push(message3);
11177
- continue;
11178
- }
11179
- const children = [];
11180
- if (node.kind === "binary") children.push(node.left, node.right);
11181
- else if (node.kind === "unary" || node.kind === "optional") children.push(node.operand);
11182
- else if (node.kind === "index") children.push(node.base, node.index);
11183
- else if (node.kind === "iterate") children.push(node.base);
11184
- else if (node.kind === "slice") {
11185
- children.push(node.base);
11186
- if (node.start) children.push(node.start);
11187
- if (node.end) children.push(node.end);
11188
- } else if (node.kind === "array" && node.body) children.push(node.body);
11189
- else if (node.kind === "object") for (const field of node.fields) children.push(field.key, field.value);
11190
- else if (node.kind === "call") children.push(...node.args);
11191
- else if (node.kind === "if") children.push(node.condition, node.yes, node.no);
11192
- else if (node.kind === "try") {
11193
- children.push(node.body);
11194
- if (node.handler) children.push(node.handler);
11195
- } else if (node.kind === "reduce" || node.kind === "foreach") {
11196
- children.push(node.source, node.init, node.update);
11197
- if (node.extract) children.push(node.extract);
11198
- }
11199
- for (const child of children.reverse()) pending.push({ node: child, depth: depth + 1 });
11200
- }
11201
- if (errors.length) throw new JqError(`${errors.join("\njq: ")}
11202
- jq: ${errors.length} compile error${errors.length === 1 ? "" : "s"}`, 3);
11203
- return ast;
11204
- }
11205
-
11206
- // packages/safe-bash/src/commands/structured/jq.ts
11207
9254
  function argumentsFor(args, budget) {
11208
9255
  budget.collection(args.length);
11209
9256
  let argumentBytes = 0;
@@ -11357,7 +9404,7 @@ async function execute3(context2, limits) {
11357
9404
  try {
11358
9405
  const options3 = argumentsFor(context2.args, budget);
11359
9406
  const source2 = options3.programFile === void 0 ? options3.source : await readProgram2(context2, options3.programFile, limits);
11360
- const ast = parse2(source2, options3.variables, budget);
9407
+ const ast = parse(source2, options3.variables, budget);
11361
9408
  const interpreter = new Interpreter(budget, options3.variables);
11362
9409
  let last;
11363
9410
  let status2 = 0;
@@ -12116,7 +10163,7 @@ async function diagnostic2(context2, error) {
12116
10163
  await writeDiagnostic(context2.stderr, `rg: ${publicDiagnosticMessage(error, context2.onInternalError)}
12117
10164
  `, context2.signal);
12118
10165
  }
12119
- async function* lines2(source2, limits, state, binary3, nullData) {
10166
+ async function* lines2(source2, limits, state, binary2, nullData) {
12120
10167
  let pending = import_buffer.Buffer.alloc(0);
12121
10168
  let offset = 0;
12122
10169
  let number4 = 0;
@@ -12125,16 +10172,16 @@ async function* lines2(source2, limits, state, binary3, nullData) {
12125
10172
  await limits.tick();
12126
10173
  const chunk = import_buffer.Buffer.from(data2);
12127
10174
  if (state.bytesRead + chunk.length > limits.maxFileBytes) throw new SearchError("input file byte limit exceeded");
12128
- const nul = nullData || binary3 === "text" ? -1 : chunk.indexOf(0);
10175
+ const nul = nullData || binary2 === "text" ? -1 : chunk.indexOf(0);
12129
10176
  if (nul >= 0 && state.binaryOffset === null) state.binaryOffset = state.bytesRead + nul;
12130
10177
  state.bytesRead += chunk.length;
12131
- if (nul >= 0 && binary3 === "skip") {
10178
+ if (nul >= 0 && binary2 === "skip") {
12132
10179
  state.skipped = true;
12133
10180
  return;
12134
10181
  }
12135
10182
  let start = 0;
12136
10183
  for (let end = 0; end < chunk.length; end++) {
12137
- if (chunk[end] !== delimiter && !(binary3 === "binary" && chunk[end] === 0)) continue;
10184
+ if (chunk[end] !== delimiter && !(binary2 === "binary" && chunk[end] === 0)) continue;
12138
10185
  if (pending.length + end - start > limits.maxLineBytes) throw new SearchError("line byte limit exceeded");
12139
10186
  const content = import_buffer.Buffer.concat([pending, chunk.subarray(start, end)]);
12140
10187
  const bytes3 = import_buffer.Buffer.concat([content, import_buffer.Buffer.from([delimiter])]);
@@ -12173,9 +10220,9 @@ var Printer = class {
12173
10220
  lastFile;
12174
10221
  lastLine = 0;
12175
10222
  headings = /* @__PURE__ */ new Set();
12176
- async event(type2, value2) {
10223
+ async event(type, value2) {
12177
10224
  const ordered = (input3) => input3 && typeof input3 === "object" && !Array.isArray(input3) ? Object.fromEntries(Object.entries(input3).sort(([left], [right]) => left < right ? -1 : left > right ? 1 : 0).map(([key, item]) => [key, ordered(item)])) : input3;
12178
- await this.limits.output(`${JSON.stringify(type2 === "summary" ? ordered({ type: type2, data: value2 }) : { type: type2, data: value2 })}
10225
+ await this.limits.output(`${JSON.stringify(type === "summary" ? ordered({ type, data: value2 }) : { type, data: value2 })}
12179
10226
  `);
12180
10227
  }
12181
10228
  async filename(label) {
@@ -12417,8 +10464,8 @@ var Walker = class {
12417
10464
  const parents2 = new Map(ancestors);
12418
10465
  parents2.set(canonical, label || ".");
12419
10466
  const local = await this.load(path, rules, repository);
12420
- const entries3 = (await this.context.fs.readdir(path, { signal: this.context.signal })).sort((left, right) => import_buffer.Buffer.compare(import_buffer.Buffer.from(left.name), import_buffer.Buffer.from(right.name)));
12421
- for (const entry of entries3) {
10467
+ const entries2 = (await this.context.fs.readdir(path, { signal: this.context.signal })).sort((left, right) => import_buffer.Buffer.compare(import_buffer.Buffer.from(left.name), import_buffer.Buffer.from(right.name)));
10468
+ for (const entry of entries2) {
12422
10469
  await this.limits.tick();
12423
10470
  if (++this.limits.files > this.limits.maxFiles) throw new SearchError("filesystem entry limit exceeded");
12424
10471
  const child = `${path.replace(/\/$/u, "")}/${entry.name}`;
@@ -12426,8 +10473,8 @@ var Walker = class {
12426
10473
  try {
12427
10474
  if (entry.type === "symlink" && !this.args.follow) continue;
12428
10475
  if (entry.type === "symlink") await assertPathRequirements(this.context, searchRequirements, ["metadata"], [child]);
12429
- const type2 = entry.type === "symlink" ? (await this.context.fs.stat(child, { signal: this.context.signal })).type : entry.type;
12430
- if (entry.type === "symlink" && type2 === "directory") {
10476
+ const type = entry.type === "symlink" ? (await this.context.fs.stat(child, { signal: this.context.signal })).type : entry.type;
10477
+ if (entry.type === "symlink" && type === "directory") {
12431
10478
  await assertPathRequirements(this.context, searchRequirements, ["canonical"], [child]);
12432
10479
  const destination2 = await this.context.fs.realpath(child, { signal: this.context.signal });
12433
10480
  if (parents2.has(destination2)) {
@@ -12435,9 +10482,9 @@ var Walker = class {
12435
10482
  continue;
12436
10483
  }
12437
10484
  }
12438
- if (!await this.accepted(child, entry.name, type2 === "directory", local.rules)) continue;
12439
- if (type2 === "directory") yield* this.directory(child, display2, depth + 1, parents2, local.rules, local.repository);
12440
- else if (type2 === "file") yield { path: child, label: display2, explicit: false, recursive: true };
10485
+ if (!await this.accepted(child, entry.name, type === "directory", local.rules)) continue;
10486
+ if (type === "directory") yield* this.directory(child, display2, depth + 1, parents2, local.rules, local.repository);
10487
+ else if (type === "file") yield { path: child, label: display2, explicit: false, recursive: true };
12441
10488
  } catch (error) {
12442
10489
  this.context.signal.throwIfAborted();
12443
10490
  if (error instanceof SearchError || error instanceof RegexExecutionError) throw error;
@@ -12516,7 +10563,7 @@ async function searchFile(context2, args, limits, matcher, printer, target, stdi
12516
10563
  totals.searches = 1;
12517
10564
  if (args.maxCount === 0) return { found: false, stats: totals };
12518
10565
  const state = { bytesRead: 0, bytesSearched: 0, binaryOffset: null, skipped: false };
12519
- const binary3 = args.binary === "text" ? "text" : args.binary === "binary" || target.explicit ? "binary" : "skip";
10566
+ const binary2 = args.binary === "text" ? "text" : args.binary === "binary" || target.explicit ? "binary" : "skip";
12520
10567
  const source2 = target.path === "-" ? readBytes(stdin, limits.signal) : readBytes(requiredFileInput(context2, searchRequirements, "file", target.path, limits.maxFileBytes), limits.signal);
12521
10568
  const before = [];
12522
10569
  let beforeBytes = 0;
@@ -12533,10 +10580,10 @@ async function searchFile(context2, args, limits, matcher, printer, target, stdi
12533
10580
  if (args.mode === "json") await printer.event("begin", { path: data(import_buffer.Buffer.from(target.label)) });
12534
10581
  };
12535
10582
  const selectedOutput = !args.quiet && (args.mode === "lines" || args.mode === "json");
12536
- const binaryOutput = selectedOutput && args.mode === "lines" && binary3 === "binary";
12537
- const available2 = new AvailableRecords(args.nullData ? 0 : 10, limits.maxLineBytes, binary3 === "binary" ? 0 : -1);
10583
+ const binaryOutput = selectedOutput && args.mode === "lines" && binary2 === "binary";
10584
+ const available2 = new AvailableRecords(args.nullData ? 0 : 10, limits.maxLineBytes, binary2 === "binary" ? 0 : -1);
12538
10585
  const batchSize = () => Number.isFinite(args.maxCount) || args.quiet && args.mode !== "json" || args.mode === "with" || args.mode === "without" || binaryOutput && state.binaryOffset !== null ? 1 : 128;
12539
- records: for await (const batch of available2.batches(lines2(available2.source(source2), limits, state, binary3, args.nullData), (line) => line.content.length, batchSize)) {
10586
+ records: for await (const batch of available2.batches(lines2(available2.source(source2), limits, state, binary2, args.nullData), (line) => line.content.length, batchSize)) {
12540
10587
  const rows2 = batch.map((line) => ({ bytes: args.crlf && line.content.at(-1) === 13 ? line.content.subarray(0, -1) : line.content, all: args.onlyMatching || args.mode === "json" || args.mode === "matches", terminated: line.bytes.length !== line.content.length }));
12541
10588
  const results = await matcher.batch(rows2);
12542
10589
  for (let index = 0; index < batch.length; index++) {
@@ -16364,7 +14411,7 @@ var dext = new Uint8Array([
16364
14411
  64,
16365
14412
  64
16366
14413
  ]);
16367
- var inflate_table = (type2, lens, lens_index, codes, table, table_index, work, opts) => {
14414
+ var inflate_table = (type, lens, lens_index, codes, table, table_index, work, opts) => {
16368
14415
  const bits = opts.bits;
16369
14416
  let len = 0;
16370
14417
  let sym = 0;
@@ -16405,14 +14452,14 @@ var inflate_table = (type2, lens, lens_index, codes, table, table_index, work, o
16405
14452
  left -= count2[len];
16406
14453
  if (left < 0) return -1;
16407
14454
  }
16408
- if (left > 0 && (type2 === CODES$1 || max !== 1)) return -1;
14455
+ if (left > 0 && (type === CODES$1 || max !== 1)) return -1;
16409
14456
  offs[1] = 0;
16410
14457
  for (len = 1; len < MAXBITS; len++) offs[len + 1] = offs[len] + count2[len];
16411
14458
  for (sym = 0; sym < codes; sym++) if (lens[lens_index + sym] !== 0) work[offs[lens[lens_index + sym]]++] = sym;
16412
- if (type2 === CODES$1) {
14459
+ if (type === CODES$1) {
16413
14460
  base = extra = work;
16414
14461
  match = 20;
16415
- } else if (type2 === LENS$1) {
14462
+ } else if (type === LENS$1) {
16416
14463
  base = lbase;
16417
14464
  extra = lext;
16418
14465
  match = 257;
@@ -16430,7 +14477,7 @@ var inflate_table = (type2, lens, lens_index, codes, table, table_index, work, o
16430
14477
  low = -1;
16431
14478
  used = 1 << root;
16432
14479
  mask = used - 1;
16433
- if (type2 === LENS$1 && used > ENOUGH_LENS$1 || type2 === DISTS$1 && used > ENOUGH_DISTS$1) return 1;
14480
+ if (type === LENS$1 && used > ENOUGH_LENS$1 || type === DISTS$1 && used > ENOUGH_DISTS$1) return 1;
16434
14481
  for (; ; ) {
16435
14482
  here_bits = len - drop;
16436
14483
  if (work[sym] + 1 < match) {
@@ -16473,7 +14520,7 @@ var inflate_table = (type2, lens, lens_index, codes, table, table_index, work, o
16473
14520
  left <<= 1;
16474
14521
  }
16475
14522
  used += 1 << curr;
16476
- if (type2 === LENS$1 && used > ENOUGH_LENS$1 || type2 === DISTS$1 && used > ENOUGH_DISTS$1) return 1;
14523
+ if (type === LENS$1 && used > ENOUGH_LENS$1 || type === DISTS$1 && used > ENOUGH_DISTS$1) return 1;
16477
14524
  low = huff & mask;
16478
14525
  table[low] = root << 24 | curr << 16 | next - table_index | 0;
16479
14526
  }
@@ -18249,7 +16296,7 @@ var ToolError = class extends PublicDiagnostic {
18249
16296
  }
18250
16297
  exitCode;
18251
16298
  };
18252
- var Budget11 = class {
16299
+ var Budget7 = class {
18253
16300
  constructor(context2, options3) {
18254
16301
  this.context = context2;
18255
16302
  this.limits = {
@@ -18384,7 +16431,7 @@ function definition(name2, options3, run4) {
18384
16431
  async execute(context2) {
18385
16432
  context2.signal.throwIfAborted();
18386
16433
  try {
18387
- return { exitCode: await run4(context2, new Budget11(context2, options3)) };
16434
+ return { exitCode: await run4(context2, new Budget7(context2, options3)) };
18388
16435
  } catch (error) {
18389
16436
  context2.signal.throwIfAborted();
18390
16437
  const message3 = publicDiagnosticMessage(error, context2.onInternalError);
@@ -18742,8 +16789,8 @@ async function run(context2, budget) {
18742
16789
  const names = /* @__PURE__ */ new Set();
18743
16790
  for (const path of [leftStat ? left : void 0, rightStat ? right : void 0]) {
18744
16791
  if (path === void 0) continue;
18745
- const entries3 = await host(context2, () => context2.fs.readdir(pathOf(context2, path), { signal: context2.signal }));
18746
- for (const entry of entries3) {
16792
+ const entries2 = await host(context2, () => context2.fs.readdir(pathOf(context2, path), { signal: context2.signal }));
16793
+ for (const entry of entries2) {
18747
16794
  budget.step();
18748
16795
  if (!entry.name || entry.name === "." || entry.name === ".." || /[\/\\\0\r\n\t]/u.test(entry.name)) throw new ToolError("unsafe directory entry name");
18749
16796
  names.add(entry.name);
@@ -19430,9 +17477,9 @@ async function backupName(path, budget) {
19430
17477
  const parent = dirname(path);
19431
17478
  if (!await inspect(budget, parent)) return `${path}.orig`;
19432
17479
  const prefix3 = `${basename(path)}.~`;
19433
- const entries3 = await host(budget.context, () => budget.context.fs.readdir(parent, { signal: budget.context.signal }));
17480
+ const entries2 = await host(budget.context, () => budget.context.fs.readdir(parent, { signal: budget.context.signal }));
19434
17481
  let maximum = 0n;
19435
- for (const entry of entries3) {
17482
+ for (const entry of entries2) {
19436
17483
  budget.file();
19437
17484
  await budget.checkpoint();
19438
17485
  if (!entry.name || /[/\0]/u.test(entry.name) || entry.name === "." || entry.name === "..") throw new ToolError("unsafe directory entry in backup directory");
@@ -19524,9 +17571,9 @@ async function pruneDirectories(parents2, budget) {
19524
17571
  if (!stat) continue;
19525
17572
  if (stat.type !== "directory") throw new ToolError(`pruning path changed type: ${parent}`);
19526
17573
  try {
19527
- const entries3 = await host(budget.context, () => budget.context.fs.readdir(parent, { signal: budget.context.signal }));
19528
- budget.step(entries3.length);
19529
- if (entries3.length) continue;
17574
+ const entries2 = await host(budget.context, () => budget.context.fs.readdir(parent, { signal: budget.context.signal }));
17575
+ budget.step(entries2.length);
17576
+ if (entries2.length) continue;
19530
17577
  const rmdir = budget.context.fs.rmdir;
19531
17578
  if (!rmdir) throw new FsError("ENOTSUP", { syscall: "rmdir", path: parent });
19532
17579
  try {
@@ -19803,9 +17850,9 @@ async function run2(context2, budget) {
19803
17850
  const current = preview.has(path) ? preview.get(path) : await inspect(budget, path) ? await budget.read(path) : void 0;
19804
17851
  const applied = await applyContent(item.patch, current ?? "", current !== void 0, options3, budget);
19805
17852
  if (!applied) return;
19806
- const remove2 = applied.result === "" && (applied.deletion || options3.removeEmpty);
19807
- preview.set(path, remove2 ? void 0 : applied.result);
19808
- if (!remove2) for (let parent = dirname(path); parent !== "/"; parent = dirname(parent)) previewParents.add(parent);
17853
+ const remove = applied.result === "" && (applied.deletion || options3.removeEmpty);
17854
+ preview.set(path, remove ? void 0 : applied.result);
17855
+ if (!remove) for (let parent = dirname(path); parent !== "/"; parent = dirname(parent)) previewParents.add(parent);
19809
17856
  }
19810
17857
  } : void 0);
19811
17858
  const targets = new Set(authorized.flatMap((item) => item.selected === void 0 ? [] : [resolvePath(context2.cwd, item.selected)]));
@@ -19874,16 +17921,16 @@ ${sourcePatch.hunks.length} out of ${sourcePatch.hunks.length} hunks ignored
19874
17921
  }
19875
17922
  if (backupPath !== void 0) backupPaths.add(backupPath);
19876
17923
  if (rejectPath !== void 0) rejectPaths.add(rejectPath);
19877
- const remove2 = result2 === "" && (deletion || options3.removeEmpty);
17924
+ const remove = result2 === "" && (deletion || options3.removeEmpty);
19878
17925
  const item = {
19879
17926
  path,
19880
17927
  original,
19881
17928
  result: result2,
19882
- remove: remove2,
17929
+ remove,
19883
17930
  ...backup === void 0 ? prior?.backup === void 0 ? {} : { backup: prior.backup } : { backup },
19884
17931
  ...backupPath === void 0 ? {} : { backupPath },
19885
17932
  ...rejectPath === void 0 ? {} : { rejectPath, reject: rejected },
19886
- parents: remove2 ? pruneParents(name2, context2.cwd) : []
17933
+ parents: remove ? pruneParents(name2, context2.cwd) : []
19887
17934
  };
19888
17935
  let message3 = options3.quiet ? "" : `${options3.dryRun ? "checking" : "patching"} file ${name2}
19889
17936
  `;
@@ -19906,7 +17953,7 @@ ${sourcePatch.hunks.length} out of ${sourcePatch.hunks.length} hunks ignored
19906
17953
  touched.add(path);
19907
17954
  if (options3.atomic) {
19908
17955
  staged.set(path, item);
19909
- if (!remove2) for (let parent = dirname(path); parent !== "/"; parent = dirname(parent)) stagedParents.add(parent);
17956
+ if (!remove) for (let parent = dirname(path); parent !== "/"; parent = dirname(parent)) stagedParents.add(parent);
19910
17957
  } else if (!options3.dryRun) {
19911
17958
  publishing = true;
19912
17959
  await publish(item, budget, rejects);
@@ -20017,8 +18064,8 @@ function metadataCommand(name2, handler) {
20017
18064
  }
20018
18065
  } };
20019
18066
  }
20020
- function permissionString(mode, type2) {
20021
- let text3 = type2 === "directory" ? "d" : type2 === "symlink" ? "l" : type2 === "character" ? "c" : "-";
18067
+ function permissionString(mode, type) {
18068
+ let text3 = type === "directory" ? "d" : type === "symlink" ? "l" : type === "character" ? "c" : "-";
20022
18069
  for (const [read, write2, execute5, special2, lower, upper] of [
20023
18070
  [256, 128, 64, 2048, "s", "S"],
20024
18071
  [32, 16, 8, 1024, "s", "S"],
@@ -20116,9 +18163,9 @@ function createChmodCommand(configuration = {}) {
20116
18163
  const deferred = stat.type === "directory" && parsed.flags.has("R") && (stat.mode & 511 & ~mode) !== 0;
20117
18164
  if (!deferred) await apply();
20118
18165
  if (stat.type === "directory" && parsed.flags.has("R")) {
20119
- const entries3 = await context2.fs.readdir(target, { signal: context2.signal });
20120
- if (entries3.length > configured.limits.maxEntries) throw new FsError("EFBIG", { message: "metadata traversal limit exceeded" });
20121
- for (const entry of entries3) {
18166
+ const entries2 = await context2.fs.readdir(target, { signal: context2.signal });
18167
+ if (entries2.length > configured.limits.maxEntries) throw new FsError("EFBIG", { message: "metadata traversal limit exceeded" });
18168
+ for (const entry of entries2) {
20122
18169
  if (!entry.name || entry.name === "." || entry.name === ".." || entry.name.includes("/") || entry.name.includes("\0")) throw new FsError("EIO", { message: "invalid directory entry" });
20123
18170
  try {
20124
18171
  await visit(`${target.replace(/\/$/u, "")}/${entry.name}`, `${display2.replace(/\/$/u, "")}/${entry.name}`, depth + 1, false);
@@ -20624,7 +18671,7 @@ function display(path) {
20624
18671
  return `\\${character.charCodeAt(0).toString(8).padStart(3, "0")}`;
20625
18672
  });
20626
18673
  }
20627
- var Budget18 = class {
18674
+ var Budget14 = class {
20628
18675
  constructor(context2, limits) {
20629
18676
  this.context = context2;
20630
18677
  this.limits = limits;
@@ -21022,7 +19069,7 @@ async function parseOptions2(context2, limits) {
21022
19069
  if (archive !== "-") checkPath(archive, limits);
21023
19070
  return { mode, archive, gzip, verbose: verbose2, strip, format: format2, cwd, operands, excludes };
21024
19071
  }
21025
- function tokenize2(pattern) {
19072
+ function tokenize(pattern) {
21026
19073
  const characters = Array.from(pattern);
21027
19074
  const tokens2 = [];
21028
19075
  for (let index = 0; index < characters.length; index++) {
@@ -21059,7 +19106,7 @@ function tokenize2(pattern) {
21059
19106
  var Exclusions = class {
21060
19107
  constructor(patterns2, maxWork = 1e7) {
21061
19108
  this.maxWork = maxWork;
21062
- this.patterns = patterns2.map(tokenize2);
19109
+ this.patterns = patterns2.map(tokenize);
21063
19110
  }
21064
19111
  maxWork;
21065
19112
  patterns;
@@ -21098,7 +19145,7 @@ function safeName(name2) {
21098
19145
  }
21099
19146
  async function manifest(context2, options3, budget) {
21100
19147
  const exclusions = new Exclusions(options3.excludes, budget.limits.maxPatternSteps);
21101
- const entries3 = [];
19148
+ const entries2 = [];
21102
19149
  let output2;
21103
19150
  let outputStat;
21104
19151
  if (options3.archive !== "-") {
@@ -21178,7 +19225,7 @@ async function manifest(context2, options3, budget) {
21178
19225
  }
21179
19226
  const headers = encodeEntry(entry, budget.limits);
21180
19227
  if (options3.format === "ustar" && headers.length > 1) fail2(`metadata requires PAX format: ${display(name2)}`);
21181
- entries3.push({ path, stat, entry });
19228
+ entries2.push({ path, stat, entry });
21182
19229
  if (stat.type === "directory") {
21183
19230
  const children = await operation(context2, () => context2.fs.readdir(path, { signal: context2.signal }));
21184
19231
  if (children.length > budget.limits.maxMembers - budget.members) fail2("member/header limit exceeded");
@@ -21195,7 +19242,7 @@ async function manifest(context2, options3, budget) {
21195
19242
  if (operand.name.split("/").includes("..")) await budget.output("tar: removing member-name prefix through '..'\n", true);
21196
19243
  await visit(vfsPath(operand.cwd, operand.name), safeName(operand.name), 0, true);
21197
19244
  }
21198
- return { entries: entries3, ...output2 === void 0 ? {} : { output: output2 }, ...outputStat === void 0 ? {} : { outputStat } };
19245
+ return { entries: entries2, ...output2 === void 0 ? {} : { output: output2 }, ...outputStat === void 0 ? {} : { outputStat } };
21199
19246
  }
21200
19247
  async function unchanged3(context2, source2) {
21201
19248
  const current = await operation(context2, () => context2.fs.lstat(source2.path, { signal: context2.signal }));
@@ -21205,9 +19252,9 @@ async function unchanged3(context2, source2) {
21205
19252
  if (target !== source2.entry.linkname) fail2("source symlink changed while archiving");
21206
19253
  }
21207
19254
  }
21208
- async function* createArchive(context2, entries3, options3, budget) {
19255
+ async function* createArchive(context2, entries2, options3, budget) {
21209
19256
  let headers = 0;
21210
- for (const source2 of entries3) {
19257
+ for (const source2 of entries2) {
21211
19258
  await unchanged3(context2, source2);
21212
19259
  const encoded2 = encodeEntry(source2.entry, budget.limits);
21213
19260
  headers += encoded2.length > 1 ? 2 : 1;
@@ -21418,14 +19465,14 @@ async function metadata2(context2, path, entry) {
21418
19465
  }
21419
19466
  }
21420
19467
  function verbose(entry) {
21421
- const type2 = entry.type === "5" ? "d" : entry.type === "2" ? "l" : entry.type === "1" ? "h" : "-";
19468
+ const type = entry.type === "5" ? "d" : entry.type === "2" ? "l" : entry.type === "1" ? "h" : "-";
21422
19469
  let permissions = "";
21423
19470
  for (const bit of [256, 128, 64, 32, 16, 8, 4, 2, 1]) permissions += entry.mode & bit ? bit & 292 ? "r" : bit & 146 ? "w" : "x" : "-";
21424
19471
  for (const [offset, special2, execute5, lower, upper] of [[2, 2048, 64, "s", "S"], [5, 1024, 8, "s", "S"], [8, 512, 1, "t", "T"]]) {
21425
19472
  if (entry.mode & special2) permissions = permissions.slice(0, offset) + (entry.mode & execute5 ? lower : upper) + permissions.slice(offset + 1);
21426
19473
  }
21427
19474
  const suffix2 = entry.type === "2" ? ` -> ${display(entry.linkname)}` : entry.type === "1" ? ` link to ${display(entry.linkname)}` : "";
21428
- return `${type2}${permissions} ${entry.uid ?? "-"}/${entry.gid ?? "-"} ${entry.size} ${entry.mtime ?? "-"} ${display(entry.name)}${suffix2}
19475
+ return `${type}${permissions} ${entry.uid ?? "-"}/${entry.gid ?? "-"} ${entry.size} ${entry.mtime ?? "-"} ${display(entry.name)}${suffix2}
21429
19476
  `;
21430
19477
  }
21431
19478
  async function readArchive(context2, source2, options3, budget) {
@@ -21613,7 +19660,7 @@ function createTarCommand(options3 = {}) {
21613
19660
  const context2 = { ...original, signal };
21614
19661
  try {
21615
19662
  const parsed = await parseOptions2(context2, limits);
21616
- const budget = new Budget18(context2, limits);
19663
+ const budget = new Budget14(context2, limits);
21617
19664
  if (parsed.mode === "c") {
21618
19665
  const prepared = await manifest(context2, parsed, budget);
21619
19666
  let source2 = bounded(createArchive(context2, prepared.entries, parsed, budget), limits.maxArchiveBytes, signal, limits.chunkSize);
@@ -21707,7 +19754,7 @@ function requireCLocale(context2) {
21707
19754
  throw new FsError("ENOTSUP", { message: "table ordering supports only the C/POSIX byte locale; set LC_ALL=C" });
21708
19755
  }
21709
19756
  }
21710
- function compare3(left, right, fold2 = false) {
19757
+ function compare2(left, right, fold2 = false) {
21711
19758
  for (let offset = 0; offset < Math.min(left.length, right.length); offset++) {
21712
19759
  let first = left[offset], second = right[offset];
21713
19760
  if (fold2 && first >= 65 && first <= 90) first += 32;
@@ -21716,7 +19763,7 @@ function compare3(left, right, fold2 = false) {
21716
19763
  }
21717
19764
  return left.length - right.length;
21718
19765
  }
21719
- var Budget21 = class {
19766
+ var Budget17 = class {
21720
19767
  constructor(context2, limits) {
21721
19768
  this.context = context2;
21722
19769
  this.limits = limits;
@@ -21861,7 +19908,7 @@ var OrderCheck = class {
21861
19908
  warned = /* @__PURE__ */ new Set();
21862
19909
  async check(previous, next, file, fold2 = false) {
21863
19910
  if (this.mode === "none" || this.mode === "default" && !this.unpaired || this.warned.has(file)) return;
21864
- if (previous && next && compare3(previous, next, fold2) > 0) {
19911
+ if (previous && next && compare2(previous, next, fold2) > 0) {
21865
19912
  const message3 = `file ${file} is not in sorted order`;
21866
19913
  if (this.mode === "check") fail3(message3);
21867
19914
  this.warned.add(file);
@@ -21893,7 +19940,7 @@ function delimiters(text3) {
21893
19940
  function createPasteCommand(options3 = {}) {
21894
19941
  const limits = settings3(options3);
21895
19942
  return command3("paste", async (context2) => {
21896
- const budget = new Budget21(context2, limits), files = [];
19943
+ const budget = new Budget17(context2, limits), files = [];
21897
19944
  let serial = false, separator = 10, list = [Uint8Array.of(9)], literal = false;
21898
19945
  for (let index = 0; index < context2.args.length; index++) {
21899
19946
  const token = context2.args[index];
@@ -21986,7 +20033,7 @@ init_platform();
21986
20033
  function createCommCommand(options3 = {}) {
21987
20034
  const limits = settings3(options3);
21988
20035
  return command3("comm", async (context2) => {
21989
- const budget = new Budget21(context2, limits), files = [], suppressed = /* @__PURE__ */ new Set();
20036
+ const budget = new Budget17(context2, limits), files = [], suppressed = /* @__PURE__ */ new Set();
21990
20037
  let separator = 10, delimiter = Uint8Array.of(9), literal = false, total = false, mode = "default";
21991
20038
  let delimiterSet = false;
21992
20039
  for (let index = 0; index < context2.args.length; index++) {
@@ -22019,7 +20066,7 @@ function createCommCommand(options3 = {}) {
22019
20066
  let value2;
22020
20067
  [value2, index] = argument(context2.args, index, token.includes("=") ? token.slice(19) : void 0, token);
22021
20068
  const candidate = value2 ? encode2(value2) : Uint8Array.of(0);
22022
- if (delimiterSet && compare3(candidate, delimiter) !== 0) fail3("multiple conflicting output delimiters");
20069
+ if (delimiterSet && compare2(candidate, delimiter) !== 0) fail3("multiple conflicting output delimiters");
22023
20070
  delimiter = candidate;
22024
20071
  delimiterSet = true;
22025
20072
  continue;
@@ -22039,7 +20086,7 @@ function createCommCommand(options3 = {}) {
22039
20086
  const totals = [0n, 0n, 0n];
22040
20087
  while (rows2[0] !== void 0 || rows2[1] !== void 0) {
22041
20088
  await budget.step();
22042
- const comparison = rows2[0] === void 0 ? 1 : rows2[1] === void 0 ? -1 : compare3(rows2[0], rows2[1]);
20089
+ const comparison = rows2[0] === void 0 ? 1 : rows2[1] === void 0 ? -1 : compare2(rows2[0], rows2[1]);
22043
20090
  const column = comparison < 0 ? 0 : comparison > 0 ? 1 : 2;
22044
20091
  totals[column] = totals[column] + 1n;
22045
20092
  if (column !== 2) order.unpaired = true;
@@ -22196,7 +20243,7 @@ function split3(bytes3, options3, budget) {
22196
20243
  function createJoinCommand(factory = {}) {
22197
20244
  const limits = settings3(factory);
22198
20245
  return command3("join", async (context2) => {
22199
- const budget = new Budget21(context2, limits), options3 = parse7(context2, budget);
20246
+ const budget = new Budget17(context2, limits), options3 = parse7(context2, budget);
22200
20247
  requireCLocale(context2);
22201
20248
  const inputs2 = new Inputs(context2, budget, options3.separator), order = new OrderCheck(options3.order, context2);
22202
20249
  const terminator = Uint8Array.of(options3.separator), delimiter = Uint8Array.of(options3.delimiter ?? 32);
@@ -22246,7 +20293,7 @@ function createJoinCommand(factory = {}) {
22246
20293
  }
22247
20294
  while (rows2[0] && rows2[1]) {
22248
20295
  await budget.step();
22249
- const comparison = compare3(rows2[0].key, rows2[1].key, options3.fold);
20296
+ const comparison = compare2(rows2[0].key, rows2[1].key, options3.fold);
22250
20297
  if (comparison !== 0) {
22251
20298
  const file = comparison < 0 ? 0 : 1;
22252
20299
  if (options3.unpaired.has(file)) await emit2(file === 0 ? rows2[file] : void 0, file === 1 ? rows2[file] : void 0);
@@ -22257,7 +20304,7 @@ function createJoinCommand(factory = {}) {
22257
20304
  const key = rows2[0].key, groups = [[], []];
22258
20305
  let groupBytes = 0, groupRecords = 0;
22259
20306
  for (let file = 0; file < 2; file++) {
22260
- while (rows2[file] && compare3(rows2[file].key, key, options3.fold) === 0) {
20307
+ while (rows2[file] && compare2(rows2[file].key, key, options3.fold) === 0) {
22261
20308
  const row = rows2[file];
22262
20309
  groupBytes += row.bytes.length;
22263
20310
  budget.check(groupBytes, limits.maxGroupBytes, "join group byte");
@@ -22616,9 +20663,9 @@ function tabs(specifications) {
22616
20663
  const stops = [];
22617
20664
  let absoluteRepeat = 0, relativeRepeat = 0;
22618
20665
  for (const specification of specifications) {
22619
- const entries3 = specification.split(/[, \t]+/u);
20666
+ const entries2 = specification.split(/[, \t]+/u);
22620
20667
  let marker = "";
22621
- for (const entry of entries3) {
20668
+ for (const entry of entries2) {
22622
20669
  if (!entry) continue;
22623
20670
  const prefix3 = entry.match(/^[+/]+/u)?.[0] ?? "";
22624
20671
  if (prefix3) marker = prefix3.at(-1);
@@ -23628,7 +21675,7 @@ async function interruptible2(operation2, signal) {
23628
21675
  }).then(resolve, reject).finally(() => signal.removeEventListener("abort", abort));
23629
21676
  });
23630
21677
  }
23631
- var Budget22 = class {
21678
+ var Budget18 = class {
23632
21679
  constructor(limits, signal) {
23633
21680
  this.limits = limits;
23634
21681
  this.signal = signal;
@@ -23902,7 +21949,7 @@ async function run3(context2, limits) {
23902
21949
  const args = parseArguments(context2.args, limits);
23903
21950
  const controller = new AbortController();
23904
21951
  const signal = AbortSignal.any([context2.signal, controller.signal]);
23905
- const budget = new Budget22(limits, signal);
21952
+ const budget = new Budget18(limits, signal);
23906
21953
  const outputs = new Outputs(context2, budget);
23907
21954
  const names = new Names(args, limits);
23908
21955
  let cursor;
@@ -25446,7 +23493,7 @@ init_platform();
25446
23493
 
25447
23494
  // packages/safe-bash/src/commands/file/classify.ts
25448
23495
  init_platform();
25449
- var binary2 = { description: "data", mime: "application/octet-stream", encoding: "binary" };
23496
+ var binary = { description: "data", mime: "application/octet-stream", encoding: "binary" };
25450
23497
  function result(description, mime, encoding = "binary") {
25451
23498
  return { description, mime, encoding };
25452
23499
  }
@@ -25485,9 +23532,9 @@ function magic(bytes3) {
25485
23532
  }
25486
23533
  }
25487
23534
  if (bytes3.length >= 52 && matches2(bytes3, [127, 69, 76, 70]) && [1, 2].includes(bytes3[4]) && [1, 2].includes(bytes3[5]) && bytes3[6] === 1 && (bytes3[4] === 1 || bytes3.length >= 64)) {
25488
- const type2 = view.getUint16(16, bytes3[5] === 1);
25489
- const mime = type2 === 1 ? "application/x-object" : type2 === 2 ? "application/x-executable" : type2 === 3 ? "application/x-sharedlib" : "application/octet-stream";
25490
- return result(`ELF ${bytes3[4] === 1 ? "32" : "64"}-bit ${type2 === 2 ? "executable" : type2 === 3 ? "shared object" : "object"}`, mime);
23535
+ const type = view.getUint16(16, bytes3[5] === 1);
23536
+ const mime = type === 1 ? "application/x-object" : type === 2 ? "application/x-executable" : type === 3 ? "application/x-sharedlib" : "application/octet-stream";
23537
+ return result(`ELF ${bytes3[4] === 1 ? "32" : "64"}-bit ${type === 2 ? "executable" : type === 3 ? "shared object" : "object"}`, mime);
25491
23538
  }
25492
23539
  if (bytes3.length >= 64 && ascii(bytes3, 0, 2) === "MZ") {
25493
23540
  const offset = view.getUint32(60, true);
@@ -25503,10 +23550,10 @@ function magic(bytes3) {
25503
23550
  return void 0;
25504
23551
  }
25505
23552
  function classify(bytes3, complete4) {
25506
- if (!bytes3.length) return complete4 ? result("empty", "inode/x-empty") : binary2;
23553
+ if (!bytes3.length) return complete4 ? result("empty", "inode/x-empty") : binary;
25507
23554
  const recognized = magic(bytes3);
25508
23555
  if (recognized) return recognized;
25509
- if (matches2(bytes3, [255, 254, 0, 0]) || matches2(bytes3, [0, 0, 254, 255])) return binary2;
23556
+ if (matches2(bytes3, [255, 254, 0, 0]) || matches2(bytes3, [0, 0, 254, 255])) return binary;
25510
23557
  let encoding = "utf-8";
25511
23558
  let bom = 0;
25512
23559
  if (matches2(bytes3, [239, 187, 191])) bom = 3;
@@ -25521,12 +23568,12 @@ function classify(bytes3, complete4) {
25521
23568
  try {
25522
23569
  text3 = new TextDecoder(encoding, { fatal: true }).decode(bytes3, { stream: !complete4 });
25523
23570
  } catch {
25524
- return binary2;
23571
+ return binary;
25525
23572
  }
25526
- if (!text3.length && bytes3.length > bom) return binary2;
23573
+ if (!text3.length && bytes3.length > bom) return binary;
25527
23574
  for (const character of text3) {
25528
23575
  const code = character.codePointAt(0);
25529
- if (code < 32 && ![8, 9, 10, 12, 13, 27].includes(code) || code >= 127 && code <= 159) return binary2;
23576
+ if (code < 32 && ![8, 9, 10, 12, 13, 27].includes(code) || code >= 127 && code <= 159) return binary;
25530
23577
  }
25531
23578
  if (!bom && encoding === "utf-8" && bytes3.every((value2) => value2 < 128)) encoding = "us-ascii";
25532
23579
  if (complete4 && /^[\x20\t\r\n]*(?:\{|\[)/u.test(text3)) {
@@ -25805,7 +23852,7 @@ async function prefix2(source2, budget, signal, controller) {
25805
23852
  }
25806
23853
  return { bytes: bytes3, complete: complete4 };
25807
23854
  }
25808
- async function inspect2(context2, name2, follow, describe2, budget, stdinUsed) {
23855
+ async function inspect2(context2, name2, follow, describe, budget, stdinUsed) {
25809
23856
  if (name2 === "-") {
25810
23857
  if (stdinUsed) return classify(new Uint8Array(), true);
25811
23858
  const sample2 = await prefix2(context2.stdin, budget, budget.signal);
@@ -25823,8 +23870,8 @@ async function inspect2(context2, name2, follow, describe2, budget, stdinUsed) {
25823
23870
  if (stat.type === "symlink") {
25824
23871
  if (follow) throw new FsError("ENOTSUP", { path, message: "followed stat returned a symbolic link" });
25825
23872
  const target = fs.readlink ? await budget.host(() => fs.readlink(path, { signal: budget.signal })) : void 0;
25826
- const rendered = target === void 0 ? void 0 : await budget.escapeName(target, true, describe2);
25827
- return { description: rendered === void 0 || !describe2 ? "symbolic link" : `symbolic link to ${rendered}`, mime: "inode/symlink", encoding: "binary" };
23873
+ const rendered = target === void 0 ? void 0 : await budget.escapeName(target, true, describe);
23874
+ return { description: rendered === void 0 || !describe ? "symbolic link" : `symbolic link to ${rendered}`, mime: "inode/symlink", encoding: "binary" };
25828
23875
  }
25829
23876
  if (stat.type !== "file") throw new FsError("ENOTSUP", { path, message: "unsupported filesystem entry type" });
25830
23877
  let sample;
@@ -26201,7 +24248,7 @@ function diagnostics(context2, maximum) {
26201
24248
  await writeBytes(context2.stderr, bytes3, context2.signal);
26202
24249
  };
26203
24250
  }
26204
- var ColumnBudget = class _ColumnBudget extends Budget21 {
24251
+ var ColumnBudget = class _ColumnBudget extends Budget17 {
26205
24252
  constructor(context2, columnLimits) {
26206
24253
  super(context2, readerSettings(columnLimits));
26207
24254
  this.columnLimits = columnLimits;
@@ -26588,7 +24635,7 @@ init_platform();
26588
24635
 
26589
24636
  // packages/safe-bash/src/commands/html-to-markdown/budget.ts
26590
24637
  init_platform();
26591
- var Budget24 = class {
24638
+ var Budget20 = class {
26592
24639
  constructor(context2, limits) {
26593
24640
  this.context = context2;
26594
24641
  this.limits = limits;
@@ -27689,7 +25736,7 @@ function createHtmlToMarkdownCommand(options3 = {}) {
27689
25736
  const parsed = argumentsFor2(context2.args, limits);
27690
25737
  operation2 = createOutputOperation(context2, context2.stdout);
27691
25738
  const work = { ...context2, signal: operation2.signal, stdout: operation2.output, registerCleanup: operation2.registerCleanup };
27692
- const budget = new Budget24(work, limits);
25739
+ const budget = new Budget20(work, limits);
27693
25740
  if (parsed.info !== void 0) await budget.emit(parsed.info);
27694
25741
  else {
27695
25742
  inputs2 = new Inputs2(work, budget);
@@ -27966,7 +26013,7 @@ var DuLimitError = class extends FsError {
27966
26013
  super("EFBIG", { message: `du ${label} limit exceeded` });
27967
26014
  }
27968
26015
  };
27969
- var Budget25 = class {
26016
+ var Budget21 = class {
27970
26017
  constructor(context2, limits, caller = context2) {
27971
26018
  this.context = context2;
27972
26019
  this.limits = limits;
@@ -28165,20 +26212,20 @@ var Walker3 = class {
28165
26212
  }
28166
26213
  async children(path, display2) {
28167
26214
  const { context: context2, limits } = this.budget;
28168
- let entries3;
26215
+ let entries2;
28169
26216
  try {
28170
- entries3 = await this.budget.fs(() => context2.fs.readdir(path, { signal: context2.signal }));
26217
+ entries2 = await this.budget.fs(() => context2.fs.readdir(path, { signal: context2.signal }));
28171
26218
  } catch (error) {
28172
26219
  await this.failure(error, display2);
28173
26220
  return void 0;
28174
26221
  }
28175
- if (!Array.isArray(entries3)) {
26222
+ if (!Array.isArray(entries2)) {
28176
26223
  await this.failure(new PublicDiagnostic("invalid directory listing"), display2);
28177
26224
  return void 0;
28178
26225
  }
28179
- this.budget.check(entries3.length, limits.maxDirectoryEntries, "directory entry");
26226
+ this.budget.check(entries2.length, limits.maxDirectoryEntries, "directory entry");
28180
26227
  const names = /* @__PURE__ */ new Set();
28181
- for (const entry of entries3) {
26228
+ for (const entry of entries2) {
28182
26229
  this.budget.step();
28183
26230
  if (!entry || typeof entry.name !== "string") {
28184
26231
  await this.failure(new PublicDiagnostic("invalid directory entry"), display2);
@@ -28191,7 +26238,7 @@ var Walker3 = class {
28191
26238
  }
28192
26239
  names.add(entry.name);
28193
26240
  }
28194
- return entries3.slice().sort((left, right) => {
26241
+ return entries2.slice().sort((left, right) => {
28195
26242
  this.budget.step(1 + Math.min(left.name.length, right.name.length));
28196
26243
  return left.name < right.name ? -1 : left.name > right.name ? 1 : 0;
28197
26244
  });
@@ -28222,9 +26269,9 @@ var Walker3 = class {
28222
26269
  } else amount = { bytes: bytes3, complete: true };
28223
26270
  if (this.duplicate(stat)) return { bytes: 0, complete: amount.complete };
28224
26271
  if (stat.type === "directory") {
28225
- const entries3 = await this.children(path, display2);
28226
- if (entries3 === void 0) amount = { ...amount, complete: false };
28227
- else for (const entry of entries3) {
26272
+ const entries2 = await this.children(path, display2);
26273
+ if (entries2 === void 0) amount = { ...amount, complete: false };
26274
+ else for (const entry of entries2) {
28228
26275
  this.budget.step();
28229
26276
  const suffix2 = display2.endsWith("/") ? "" : "/";
28230
26277
  this.budget.check(path.length + entry.name.length + 1, limits.maxPathBytes, "path/name");
@@ -28261,7 +26308,7 @@ function createDuCommand(options3 = {}) {
28261
26308
  }, get stdout() {
28262
26309
  return operation2?.output ?? context2.stdout;
28263
26310
  } };
28264
- const budget = new Budget25(work, limits, context2);
26311
+ const budget = new Budget21(work, limits, context2);
28265
26312
  context2.registerCleanup?.(budget.close);
28266
26313
  try {
28267
26314
  const args = parse11(budget);
@@ -28354,7 +26401,7 @@ function settings13(options3) {
28354
26401
  ]) if (limits[key] > maximum) throw new RangeError(`expr ${key} exceeds worker ceiling ${maximum}`);
28355
26402
  return Object.freeze(limits);
28356
26403
  }
28357
- var Budget26 = class {
26404
+ var Budget22 = class {
28358
26405
  constructor(context2, limits) {
28359
26406
  this.context = context2;
28360
26407
  this.limits = limits;
@@ -28512,7 +26559,7 @@ function arithmetic(operator, left, right, budget) {
28512
26559
  budget.check(resultText.length - (result2 < 0n ? 1 : 0), budget.limits.maxNumericDigits, "arithmetic result digits");
28513
26560
  return { number: result2, text: resultText };
28514
26561
  }
28515
- function compare4(left, right, budget) {
26562
+ function compare3(left, right, budget) {
28516
26563
  if (numericShape(left, budget) && numericShape(right, budget)) {
28517
26564
  const first = integer4(left, budget), second = integer4(right, budget);
28518
26565
  return first < second ? -1 : first > second ? 1 : 0;
@@ -28547,9 +26594,9 @@ async function evaluateCall(operator, values, budget, match) {
28547
26594
  const candidateEnd = nextCharacter(accept, candidate, unicode);
28548
26595
  budget.charge(1 + end2 - offset);
28549
26596
  if (end2 - offset === candidateEnd - candidate) {
28550
- let equal2 = true;
28551
- for (let byte = 0; byte < end2 - offset; byte++) if (subject[offset + byte] !== accept[candidate + byte]) equal2 = false;
28552
- if (equal2) return smallInteger(position2, budget);
26597
+ let equal = true;
26598
+ for (let byte = 0; byte < end2 - offset; byte++) if (subject[offset + byte] !== accept[candidate + byte]) equal = false;
26599
+ if (equal) return smallInteger(position2, budget);
28553
26600
  }
28554
26601
  candidate = candidateEnd;
28555
26602
  await budget.yield();
@@ -28572,7 +26619,7 @@ async function evaluateCall(operator, values, budget, match) {
28572
26619
  }
28573
26620
  async function evaluateBinary(operator, left, right, budget, match) {
28574
26621
  if (["<", "<=", "=", "==", "!=", ">=", ">"].includes(operator)) {
28575
- const order = compare4(left, right, budget);
26622
+ const order = compare3(left, right, budget);
28576
26623
  return smallInteger(Number(operator === "<" ? order < 0 : operator === "<=" ? order <= 0 : operator === ">" ? order > 0 : operator === ">=" ? order >= 0 : operator === "!=" ? order !== 0 : order === 0), budget);
28577
26624
  }
28578
26625
  if (operator === ":") return match(bytes2(left, budget), bytes2(right, budget), utf8Profile(budget.context));
@@ -28669,13 +26716,13 @@ async function evaluateExpression(args, budget, match, start = 0) {
28669
26716
  let left = await prefix3(depth, active);
28670
26717
  while (position < args.length) {
28671
26718
  const operator = args[position];
28672
- const precedence3 = precedences2.get(operator);
28673
- if (precedence3 === void 0 || precedence3 < minimum) break;
26719
+ const precedence2 = precedences2.get(operator);
26720
+ if (precedence2 === void 0 || precedence2 < minimum) break;
28674
26721
  position++;
28675
26722
  const logical = operator === "|" || operator === "&";
28676
26723
  const leftTruth = left.active && logical ? truth3(left.value, budget) : false;
28677
26724
  const enabled = operator === "|" ? !leftTruth : operator === "&" ? leftTruth : true;
28678
- const right = await expression(precedence3 + 1, depth + 1, active && enabled);
26725
+ const right = await expression(precedence2 + 1, depth + 1, active && enabled);
28679
26726
  const resultDepth = 1 + Math.max(left.depth, right.depth);
28680
26727
  await node(resultDepth);
28681
26728
  if (!left.active) left = { active: false, depth: resultDepth };
@@ -28702,7 +26749,7 @@ function createExprCommandWithExecutor(executor, options3 = {}) {
28702
26749
  return { name: "expr", description: "Evaluate bounded integer and string expressions", async execute(context2) {
28703
26750
  return withRegexSession(context2, executor, async (session) => {
28704
26751
  context2.signal.throwIfAborted();
28705
- const budget = new Budget26(context2, limits);
26752
+ const budget = new Budget22(context2, limits);
28706
26753
  let output2;
28707
26754
  let exitCode = 0;
28708
26755
  try {
@@ -30476,7 +28523,7 @@ function prepareArithmetic(source2, budget = new ParseBudget()) {
30476
28523
  return { source: source2, error };
30477
28524
  }
30478
28525
  }
30479
- var precedence2 = {
28526
+ var precedence = {
30480
28527
  ",": 1,
30481
28528
  "=": 2,
30482
28529
  "+=": 2,
@@ -30583,7 +28630,7 @@ function parseArithmetic(source2, offset = 0, budget = new ParseBudget()) {
30583
28630
  left = { kind: "unary", operator, operand: left, postfix: true, start };
30584
28631
  continue;
30585
28632
  }
30586
- const priority = Object.hasOwn(precedence2, operator) ? precedence2[operator] : 0;
28633
+ const priority = Object.hasOwn(precedence, operator) ? precedence[operator] : 0;
30587
28634
  if (priority < minimum || priority === 0) break;
30588
28635
  cursor++;
30589
28636
  budget.admit();
@@ -30625,7 +28672,7 @@ function arithmeticEnd(source2, start) {
30625
28672
  function evaluateArithmetic(program, variables, budget = new ParseBudget()) {
30626
28673
  const visiting = /* @__PURE__ */ new Set();
30627
28674
  let steps = 0;
30628
- const binary3 = (operator, left, right, offset) => {
28675
+ const binary2 = (operator, left, right, offset) => {
30629
28676
  switch (operator) {
30630
28677
  case "+":
30631
28678
  return left + right;
@@ -30727,8 +28774,8 @@ function evaluateArithmetic(program, variables, budget = new ParseBudget()) {
30727
28774
  }
30728
28775
  } else if (frame.kind === "right") {
30729
28776
  const { node } = frame;
30730
- if (node.operator !== "=") value2 = binary3(precedence2[node.operator] === 2 ? node.operator.slice(0, -1) : node.operator, frame.left, value2, node.right.start ?? 0);
30731
- if (precedence2[node.operator] === 2) variables[node.left.name] = String(BigInt.asIntN(64, value2));
28777
+ if (node.operator !== "=") value2 = binary2(precedence[node.operator] === 2 ? node.operator.slice(0, -1) : node.operator, frame.left, value2, node.right.start ?? 0);
28778
+ if (precedence[node.operator] === 2) variables[node.left.name] = String(BigInt.asIntN(64, value2));
30732
28779
  value2 = BigInt.asIntN(64, value2);
30733
28780
  } else value2 = BigInt(value2 !== 0n);
30734
28781
  }
@@ -31939,7 +29986,7 @@ var Parser4 = class {
31939
29986
  const head = compoundHead(word, this.budget);
31940
29987
  if (head && this.is("(")) {
31941
29988
  this.advance();
31942
- const entries3 = [];
29989
+ const entries2 = [];
31943
29990
  this.newlines();
31944
29991
  while (this.current.kind === "word") {
31945
29992
  const original = this.advance().word;
@@ -31948,14 +29995,14 @@ var Parser4 = class {
31948
29995
  this.budget.admit();
31949
29996
  compoundEntryWords.set(entry, original);
31950
29997
  }
31951
- entries3.push(entry);
29998
+ entries2.push(entry);
31952
29999
  this.newlines();
31953
30000
  }
31954
30001
  if (!this.is(")")) this.error("Unsupported indexed-array compound assignment");
31955
30002
  const end = this.advance().end;
31956
30003
  this.budget.admit(2);
31957
30004
  word = { offset: word.offset, parts: word.parts, spelling: this.lexer.source.slice(word.offset, end) };
31958
- setArrayAssignment(word, { kind: "compound", ...head, entries: entries3 });
30005
+ setArrayAssignment(word, { kind: "compound", ...head, entries: entries2 });
31959
30006
  } else {
31960
30007
  const assignment = words.every((previous) => getArrayAssignment(previous) || scalarAssignmentName(previous)) ? elementAssignment(word, this.budget) : void 0;
31961
30008
  if (assignment) setArrayAssignment(word, assignment);
@@ -32303,10 +30350,10 @@ var ValueStore = class _ValueStore {
32303
30350
  throw error;
32304
30351
  }
32305
30352
  }
32306
- replace(entries3, action) {
30353
+ replace(entries2, action) {
32307
30354
  const staged = /* @__PURE__ */ new Map();
32308
30355
  try {
32309
- for (const [name2, value2] of entries3) {
30356
+ for (const [name2, value2] of entries2) {
32310
30357
  const held = this.scope.hold(value2);
32311
30358
  staged.get(name2)?.release();
32312
30359
  staged.set(name2, held);
@@ -34939,7 +32986,7 @@ function resolveLimits(...limits) {
34939
32986
  return result2;
34940
32987
  }
34941
32988
  var budgetedSinks = /* @__PURE__ */ new WeakMap();
34942
- var Budget29 = class {
32989
+ var Budget25 = class {
34943
32990
  constructor(limits, signal, onInternalError) {
34944
32991
  this.limits = limits;
34945
32992
  this.onInternalError = onInternalError;
@@ -35596,14 +33643,14 @@ var DirectoryStackWork = class {
35596
33643
  await writeText(this.stdout, text3);
35597
33644
  this.signal.throwIfAborted();
35598
33645
  }
35599
- async display(cwd, entries3, options3, home) {
33646
+ async display(cwd, entries2, options3, home) {
35600
33647
  await this.scan(cwd, "path");
35601
33648
  const homeBytes = !options3.long && home !== void 0 ? await this.scan(home, "HOME") : 0;
35602
33649
  const start = options3.index ?? 0;
35603
- const end = options3.index ?? entries3.length;
33650
+ const end = options3.index ?? entries2.length;
35604
33651
  for (let index = start; index <= end; index++) {
35605
33652
  await this.charge(1);
35606
- let entry = index === 0 ? cwd : entries3[index - 1];
33653
+ let entry = index === 0 ? cwd : entries2[index - 1];
35607
33654
  if (homeBytes > 1 && home !== void 0 && entry.length >= home.length) {
35608
33655
  let matches3 = true;
35609
33656
  for (let offset = 0; offset < home.length; offset++) {
@@ -38780,9 +36827,9 @@ ${prefix3} line ${offset + line}: \`${source2.split("\n")[line - 1] ?? ""}'
38780
36827
  const bytes3 = tail.bytes - removedBytes + extraBytes;
38781
36828
  if (!Number.isSafeInteger(bytes3) || bytes3 < 0 || bytes3 > 4194304) work.fail("directory stack exceeds 4194304 UTF-8 bytes");
38782
36829
  await work.charge(length);
38783
- const entries3 = new Array(length);
38784
- for (let index = 0; index < length; index++) entries3[index] = entry(index);
38785
- return { entries: entries3, bytes: bytes3 };
36830
+ const entries2 = new Array(length);
36831
+ for (let index = 0; index < length; index++) entries2[index] = entry(index);
36832
+ return { entries: entries2, bytes: bytes3 };
38786
36833
  };
38787
36834
  const publish4 = async (next) => {
38788
36835
  await work.flushWork();
@@ -40270,15 +38317,15 @@ ${prefix3} line ${offset + line}: \`${source2.split("\n")[line - 1] ?? ""}'
40270
38317
  try {
40271
38318
  const matches3 = await compilePattern(segment2, work);
40272
38319
  for (const candidate of candidates) {
40273
- let entries3;
38320
+ let entries2;
40274
38321
  try {
40275
38322
  const pending = this.fs.readdir(pathOf(state, candidate || "."), { signal: this.signal });
40276
- entries3 = arrayStore(state) ? await interruptible3(pending, this.signal) : await pending;
38323
+ entries2 = arrayStore(state) ? await interruptible3(pending, this.signal) : await pending;
40277
38324
  } catch (error) {
40278
38325
  if (["ENOENT", "ENOTDIR", "EACCES"].includes(errorCode(error) ?? "")) continue;
40279
38326
  throw error;
40280
38327
  }
40281
- for (const entry of entries3) {
38328
+ for (const entry of entries2) {
40282
38329
  if (entry.name !== "." && entry.name !== ".." && (state.dotglob || !entry.name.startsWith(".") || segment2.startsWith(".")) && await matches3(entry.name)) {
40283
38330
  addCandidate(`${candidate}${candidate && candidate !== "/" ? "/" : ""}${entry.name}`);
40284
38331
  }
@@ -40818,7 +38865,7 @@ var Shell = class {
40818
38865
  if (this.#disposed) throw new Error("Shell is disposed");
40819
38866
  if (options3.onInternalError !== void 0 && typeof options3.onInternalError !== "function") throw new TypeError("onInternalError must be callable");
40820
38867
  warnIfHostProcessEnv(options3.env);
40821
- const budget = new Budget29(resolveLimits(this.#options.limits, options3.limits), options3.signal, options3.onInternalError ?? this.#options.onInternalError);
38868
+ const budget = new Budget25(resolveLimits(this.#options.limits, options3.limits), options3.signal, options3.onInternalError ?? this.#options.onInternalError);
40822
38869
  const scope = new InvocationScope(options3.signal);
40823
38870
  const cancellationState = new RuntimeCancellationState();
40824
38871
  const owner = new RootInvocationCancellationOwner(scope);
@@ -41444,9 +39491,9 @@ async function compareEntries(filesystem, path, peer, peerPath, options3 = {}) {
41444
39491
  const other = await resolveEntryView(peer, peerPath, options3);
41445
39492
  return compareResolvedEntries(own, other, options3);
41446
39493
  }
41447
- var entries2 = /* @__PURE__ */ new WeakMap();
39494
+ var entries = /* @__PURE__ */ new WeakMap();
41448
39495
  function getOwnedS3Entry(view) {
41449
- return entries2.get(view.filesystem)?.(view);
39496
+ return entries.get(view.filesystem)?.(view);
41450
39497
  }
41451
39498
  var responses = /* @__PURE__ */ new WeakMap();
41452
39499
  var observations = /* @__PURE__ */ new WeakMap();
@@ -43712,9 +41759,9 @@ var WebDavFileSystem = class {
43712
41759
  limit = directoryEntryLimit(options3, path);
43713
41760
  }
43714
41761
  const normalized = normalize(path);
43715
- const entries22 = await this.entries(normalized, "1", options3, true, limit);
43716
- if (entries22.get(normalized).type !== "directory") fail32("ENOTDIR", "readdir", path);
43717
- return [...entries22].filter(([member2]) => member2 !== normalized).map(([member2, stat]) => ({ name: member2.slice(member2.lastIndexOf("/") + 1), type: stat.type })).sort((left, right) => left.name < right.name ? -1 : left.name > right.name ? 1 : 0);
41762
+ const entries2 = await this.entries(normalized, "1", options3, true, limit);
41763
+ if (entries2.get(normalized).type !== "directory") fail32("ENOTDIR", "readdir", path);
41764
+ return [...entries2].filter(([member2]) => member2 !== normalized).map(([member2, stat]) => ({ name: member2.slice(member2.lastIndexOf("/") + 1), type: stat.type })).sort((left, right) => left.name < right.name ? -1 : left.name > right.name ? 1 : 0);
43718
41765
  }
43719
41766
  async readFile(path, options3 = {}) {
43720
41767
  const normalized = normalize(path);
@@ -43905,9 +41952,9 @@ var WebDavFileSystem = class {
43905
41952
  await this.atomicRmdir(normalized, path, options3);
43906
41953
  return;
43907
41954
  }
43908
- const entries22 = await this.readdir(path, options3);
41955
+ const entries2 = await this.readdir(path, options3);
43909
41956
  if (options3.signal?.aborted) fail32("ECANCELED", "rmdir", path);
43910
- if (entries22.length) fail32("ENOTEMPTY", "rmdir", path);
41957
+ if (entries2.length) fail32("ENOTEMPTY", "rmdir", path);
43911
41958
  this.unsupported("rmdir", path);
43912
41959
  } catch (error) {
43913
41960
  if (isFsError2(error) && (error.syscall !== "rmdir" || error.path !== path)) {
@@ -44056,14 +42103,14 @@ var WebDavFileSystem = class {
44056
42103
  const discovery = davChild(root, "lockdiscovery");
44057
42104
  const active = discovery && davChild(discovery, "activelock");
44058
42105
  const scope = active && davChild(active, "lockscope");
44059
- const type2 = active && davChild(active, "locktype");
42106
+ const type = active && davChild(active, "locktype");
44060
42107
  const depth = active && davChild(active, "depth");
44061
42108
  const lockToken = active && davChild(active, "locktoken");
44062
42109
  const href = lockToken && davChild(lockToken, "href");
44063
42110
  const lockRoot = active && davChild(active, "lockroot");
44064
42111
  const rootHref = lockRoot && davChild(lockRoot, "href");
44065
42112
  const timeout = active && davChild(active, "timeout");
44066
- if (root.namespace !== "DAV:" || root.localName !== "prop" || !scope || !davChild(scope, "exclusive") || davChild(scope, "shared") || !type2 || !davChild(type2, "write") || !depth || scalar2(depth) !== "infinity" || !href || `<${scalar2(href)}>` !== token || lockRoot !== void 0 && (!rootHref || this.hrefPath(scalar2(rootHref)) !== path) || !timeout || !/^Second-[1-9]\d*$/i.test(scalar2(timeout)) || Number(scalar2(timeout).slice(7)) > 4294967295) {
42113
+ if (root.namespace !== "DAV:" || root.localName !== "prop" || !scope || !davChild(scope, "exclusive") || davChild(scope, "shared") || !type || !davChild(type, "write") || !depth || scalar2(depth) !== "infinity" || !href || `<${scalar2(href)}>` !== token || lockRoot !== void 0 && (!rootHref || this.hrefPath(scalar2(rootHref)) !== path) || !timeout || !/^Second-[1-9]\d*$/i.test(scalar2(timeout)) || Number(scalar2(timeout).slice(7)) > 4294967295) {
44067
42114
  fail32("ENOTSUP", "LOCK", path, "server did not grant a finite exclusive depth-infinity write lock");
44068
42115
  }
44069
42116
  }, collection, (response, late) => {
@@ -44132,9 +42179,9 @@ var WebDavFileSystem = class {
44132
42179
  body: `<d:propertyupdate xmlns:d="DAV:" xmlns:v="${timestampNamespace}"><d:set><d:prop><v:timestamps>${metadata3}</v:timestamps></d:prop></d:set></d:propertyupdate>`
44133
42180
  }, async (response, signal) => {
44134
42181
  if (response.status !== 207) this.httpError(response.status, "PROPPATCH", path);
44135
- const entries22 = await this.multistatus(response, signal);
44136
- if (entries22.length !== 1) throw new Error("PROPPATCH must report the requested resource");
44137
- const entry = entries22[0];
42182
+ const entries2 = await this.multistatus(response, signal);
42183
+ if (entries2.length !== 1) throw new Error("PROPPATCH must report the requested resource");
42184
+ const entry = entries2[0];
44138
42185
  const href = davChild(entry, "href");
44139
42186
  if (!href || this.hrefPath(scalar2(href)) !== normalized) fail32("EACCES", "PROPPATCH", path, "unexpected response resource");
44140
42187
  const status2 = davChild(entry, "status");
@@ -44234,7 +42281,7 @@ function guestOptions(value2) {
44234
42281
  const options3 = record3(value2, "shell options");
44235
42282
  onlyKeys(options3, ["cwd", "env", "stdin"]);
44236
42283
  const env = options3.env === void 0 ? void 0 : record3(options3.env, "env");
44237
- const entries3 = env === void 0 ? void 0 : Object.entries(env).map(([key, entry]) => {
42284
+ const entries2 = env === void 0 ? void 0 : Object.entries(env).map(([key, entry]) => {
44238
42285
  if (key.includes("\0") || key.includes("=")) throw new TypeError("Invalid environment key");
44239
42286
  const text3 = stringValue(entry, `env.${key}`);
44240
42287
  if (text3.includes("\0")) throw new TypeError("Invalid environment value");
@@ -44243,7 +42290,7 @@ function guestOptions(value2) {
44243
42290
  return {
44244
42291
  ...options3.cwd === void 0 ? {} : { cwd: stringValue(options3.cwd, "cwd") },
44245
42292
  ...options3.stdin === void 0 ? {} : { stdin: stringValue(options3.stdin, "stdin") },
44246
- ...entries3 === void 0 ? {} : { env: Object.fromEntries(entries3) }
42293
+ ...entries2 === void 0 ? {} : { env: Object.fromEntries(entries2) }
44247
42294
  };
44248
42295
  }
44249
42296
  function makeSafeJsShellModule(executor, options3) {
@@ -44346,10 +42393,10 @@ var Text = class {
44346
42393
  }
44347
42394
  this.append("]");
44348
42395
  } else {
44349
- const entries3 = record3(value2, "output value");
42396
+ const entries2 = record3(value2, "output value");
44350
42397
  this.append("{");
44351
42398
  let first = true;
44352
- for (const [key, item] of Object.entries(entries3)) {
42399
+ for (const [key, item] of Object.entries(entries2)) {
44353
42400
  if (item === void 0) continue;
44354
42401
  if (!first) this.append(",");
44355
42402
  first = false;
@@ -45061,6 +43108,8 @@ export {
45061
43108
  createWhichCommand,
45062
43109
  createWhichCommands,
45063
43110
  createXmlCommands,
43111
+ createYqCommand,
43112
+ createYqCommands,
45064
43113
  defaultJqLimits,
45065
43114
  defaultMemoryFileSystemLimits2 as defaultMemoryFileSystemLimits,
45066
43115
  defaultSafeJsLimits,
@@ -45113,6 +43162,7 @@ export {
45113
43162
  whichCommands,
45114
43163
  writeBytes,
45115
43164
  writeText,
45116
- xmlCommands
43165
+ xmlCommands,
43166
+ yqCommands
45117
43167
  };
45118
43168
  //# sourceMappingURL=core.browser.js.map