@poe-platform/safe-bash 0.1.726 → 0.1.727
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/safe-bash/chunks/{chunk-6VZX7ESE.js → chunk-26N7BLXE.js} +3 -3
- package/dist/safe-bash/chunks/{chunk-ZZ7JQBPX.js → chunk-4A2OLEML.js} +2 -2
- package/dist/safe-bash/chunks/{chunk-LTREB3HX.js → chunk-54MC6XF5.js} +4 -4
- package/dist/safe-bash/chunks/{chunk-Z3CCN6Y2.js → chunk-6J5FUESH.js} +2 -2
- package/dist/safe-bash/chunks/{chunk-YR5RZBWS.js → chunk-6TBFZ5JE.js} +2 -2
- package/dist/safe-bash/chunks/{chunk-6HJNJ625.js → chunk-7MMYQG3P.js} +2 -2
- package/dist/safe-bash/chunks/{chunk-WTZZX4LV.js → chunk-A4MB2KXV.js} +2 -2
- package/dist/safe-bash/chunks/{chunk-EM2JW7ZH.js → chunk-ATYJKRBZ.js} +2 -2
- package/dist/safe-bash/chunks/{chunk-VV24PRPB.js → chunk-AZQOEGP3.js} +1050 -101
- package/dist/safe-bash/chunks/chunk-AZQOEGP3.js.map +7 -0
- package/dist/safe-bash/chunks/{chunk-EFMXWUYE.js → chunk-B6JEJ6AT.js} +2 -2
- package/dist/safe-bash/chunks/{chunk-JFGGQUYP.js → chunk-BFXGHT3R.js} +2 -2
- package/dist/safe-bash/chunks/{chunk-RP5IZOOR.js → chunk-BJYV5J65.js} +1050 -101
- package/dist/safe-bash/chunks/chunk-BJYV5J65.js.map +7 -0
- package/dist/safe-bash/chunks/{chunk-HNHOPD3P.js → chunk-DIEFWGXO.js} +46 -26
- package/dist/safe-bash/chunks/{chunk-HNHOPD3P.js.map → chunk-DIEFWGXO.js.map} +2 -2
- package/dist/safe-bash/chunks/{chunk-SME47P4B.js → chunk-DV6EZOKM.js} +46 -26
- package/dist/safe-bash/chunks/{chunk-SME47P4B.js.map → chunk-DV6EZOKM.js.map} +2 -2
- package/dist/safe-bash/chunks/{chunk-646RTREQ.js → chunk-EEDOYIPC.js} +2 -2
- package/dist/safe-bash/chunks/{chunk-OFAAHWL5.js → chunk-GCQ5A2T2.js} +2 -2
- package/dist/safe-bash/chunks/{chunk-MJW4KSKV.js → chunk-GLPJEDLY.js} +2 -2
- package/dist/safe-bash/chunks/{chunk-FOOJWH7J.js → chunk-GO5OKPBO.js} +4 -4
- package/dist/safe-bash/chunks/{chunk-5JANWFJ3.js → chunk-GWYXCCGO.js} +4 -4
- package/dist/safe-bash/chunks/{chunk-DPHRNHPT.js → chunk-H6KJ4L22.js} +2 -2
- package/dist/safe-bash/chunks/{chunk-FLX2BZBF.js → chunk-HGBYIDAK.js} +4 -4
- package/dist/safe-bash/chunks/{chunk-VGJIDLZM.js → chunk-KS5VSJYM.js} +15 -8
- package/dist/safe-bash/chunks/chunk-KS5VSJYM.js.map +7 -0
- package/dist/safe-bash/chunks/{chunk-PO3Z7W3A.js → chunk-MUHYGUFD.js} +4 -4
- package/dist/safe-bash/chunks/{chunk-5DLGYPGJ.js → chunk-PDSTXORC.js} +126 -58
- package/dist/safe-bash/chunks/chunk-PDSTXORC.js.map +7 -0
- package/dist/safe-bash/chunks/{chunk-TIHMU25L.js → chunk-PQ37GDJF.js} +3 -3
- package/dist/safe-bash/chunks/{chunk-OTM5RCWZ.js → chunk-QNEDWYC2.js} +15 -8
- package/dist/safe-bash/chunks/chunk-QNEDWYC2.js.map +7 -0
- package/dist/safe-bash/chunks/{chunk-LZ7FUN6K.js → chunk-RHHDOA67.js} +5 -5
- package/dist/safe-bash/chunks/{chunk-DSCL3VA2.js → chunk-SJ3B26XV.js} +4 -4
- package/dist/safe-bash/chunks/{chunk-6JBTVWHH.js → chunk-SWACYEIT.js} +5 -5
- package/dist/safe-bash/chunks/{chunk-7UJW7TYR.js → chunk-TD6NWAUK.js} +126 -58
- package/dist/safe-bash/chunks/chunk-TD6NWAUK.js.map +7 -0
- package/dist/safe-bash/chunks/{chunk-Q4I754TV.js → chunk-THOBFD5C.js} +2 -2
- package/dist/safe-bash/chunks/{chunk-XELW5O3R.js → chunk-U2STHT7S.js} +2 -2
- package/dist/safe-bash/chunks/{chunk-5X4SOSTT.js → chunk-UJHE5PTK.js} +2 -2
- package/dist/safe-bash/chunks/{chunk-B6YFFKYG.js → chunk-X4I3RHTC.js} +5 -1
- package/dist/safe-bash/chunks/chunk-X4I3RHTC.js.map +7 -0
- package/dist/safe-bash/chunks/{chunk-YOK5UHA7.js → chunk-XKXFX3RH.js} +5 -1
- package/dist/safe-bash/chunks/chunk-XKXFX3RH.js.map +7 -0
- package/dist/safe-bash/chunks/{chunk-PLCYP2E5.js → chunk-XV4K3UUF.js} +2 -2
- package/dist/safe-bash/commands/csplit/index.browser.js +2 -2
- package/dist/safe-bash/commands/factor/index.browser.js +2 -2
- package/dist/safe-bash/commands/getopt/index.browser.js +2 -2
- package/dist/safe-bash/commands/hexdump/index.browser.js +2 -2
- package/dist/safe-bash/commands/iconv/index.browser.js +2 -2
- package/dist/safe-bash/commands/internal.d.ts.map +1 -1
- package/dist/safe-bash/commands/internal.js +4 -3
- package/dist/safe-bash/commands/internal.js.map +1 -1
- package/dist/safe-bash/commands/line-endings/index.browser.js +2 -2
- package/dist/safe-bash/commands/llm/index.browser.js +4 -4
- package/dist/safe-bash/commands/network/index.browser.js +4 -4
- package/dist/safe-bash/commands/node/index.browser.js +4 -4
- package/dist/safe-bash/commands/pandoc/index.js.map +1 -1
- package/dist/safe-bash/commands/pr/index.browser.js +3 -3
- package/dist/safe-bash/commands/python/index.browser.js +2 -2
- package/dist/safe-bash/commands/record-buffer.d.ts.map +1 -1
- package/dist/safe-bash/commands/record-buffer.js +12 -4
- package/dist/safe-bash/commands/record-buffer.js.map +1 -1
- package/dist/safe-bash/commands/regex-execution/bounded-provider.d.ts.map +1 -1
- package/dist/safe-bash/commands/regex-execution/bounded-provider.js +75 -8
- package/dist/safe-bash/commands/regex-execution/bounded-provider.js.map +1 -1
- package/dist/safe-bash/commands/regex-execution/ere/limits.d.ts +1 -1
- package/dist/safe-bash/commands/regex-execution/ere/limits.d.ts.map +1 -1
- package/dist/safe-bash/commands/regex-execution/ere/limits.js +6 -4
- package/dist/safe-bash/commands/regex-execution/ere/limits.js.map +1 -1
- package/dist/safe-bash/commands/regex-execution/portable.d.ts.map +1 -1
- package/dist/safe-bash/commands/regex-execution/portable.js +7 -2
- package/dist/safe-bash/commands/regex-execution/portable.js.map +1 -1
- package/dist/safe-bash/commands/regex-execution/protocol.d.ts +2 -0
- package/dist/safe-bash/commands/regex-execution/protocol.d.ts.map +1 -1
- package/dist/safe-bash/commands/regex-execution/protocol.js +26 -0
- package/dist/safe-bash/commands/regex-execution/protocol.js.map +1 -1
- package/dist/safe-bash/commands/regex-execution/utf8.d.ts +1 -1
- package/dist/safe-bash/commands/regex-execution/utf8.d.ts.map +1 -1
- package/dist/safe-bash/commands/regex-execution/utf8.js +26 -2
- package/dist/safe-bash/commands/regex-execution/utf8.js.map +1 -1
- package/dist/safe-bash/commands/search/grep.d.ts.map +1 -1
- package/dist/safe-bash/commands/search/grep.js +109 -15
- package/dist/safe-bash/commands/search/grep.js.map +1 -1
- package/dist/safe-bash/commands/search/matcher.d.ts +1 -1
- package/dist/safe-bash/commands/search/matcher.d.ts.map +1 -1
- package/dist/safe-bash/commands/search/matcher.js +2 -0
- package/dist/safe-bash/commands/search/matcher.js.map +1 -1
- package/dist/safe-bash/commands/search/shared.d.ts.map +1 -1
- package/dist/safe-bash/commands/search/shared.js +23 -12
- package/dist/safe-bash/commands/search/shared.js.map +1 -1
- package/dist/safe-bash/commands/standard.d.ts.map +1 -1
- package/dist/safe-bash/commands/standard.js +22 -0
- package/dist/safe-bash/commands/standard.js.map +1 -1
- package/dist/safe-bash/commands/streams.d.ts.map +1 -1
- package/dist/safe-bash/commands/streams.js +54 -10
- package/dist/safe-bash/commands/streams.js.map +1 -1
- package/dist/safe-bash/commands/structured/input.d.ts.map +1 -1
- package/dist/safe-bash/commands/structured/input.js +484 -55
- package/dist/safe-bash/commands/structured/input.js.map +1 -1
- package/dist/safe-bash/commands/structured/interpreter.d.ts +3 -0
- package/dist/safe-bash/commands/structured/interpreter.d.ts.map +1 -1
- package/dist/safe-bash/commands/structured/interpreter.js +157 -1
- package/dist/safe-bash/commands/structured/interpreter.js.map +1 -1
- package/dist/safe-bash/commands/structured/jq.d.ts.map +1 -1
- package/dist/safe-bash/commands/structured/jq.js +50 -24
- package/dist/safe-bash/commands/structured/jq.js.map +1 -1
- package/dist/safe-bash/commands/structured/limits.d.ts +5 -0
- package/dist/safe-bash/commands/structured/limits.d.ts.map +1 -1
- package/dist/safe-bash/commands/structured/limits.js +51 -36
- package/dist/safe-bash/commands/structured/limits.js.map +1 -1
- package/dist/safe-bash/commands/structured/numbers.d.ts +1 -0
- package/dist/safe-bash/commands/structured/numbers.d.ts.map +1 -1
- package/dist/safe-bash/commands/structured/numbers.js +32 -0
- package/dist/safe-bash/commands/structured/numbers.js.map +1 -1
- package/dist/safe-bash/commands/text-programs/awk-reader.d.ts +1 -0
- package/dist/safe-bash/commands/text-programs/awk-reader.d.ts.map +1 -1
- package/dist/safe-bash/commands/text-programs/awk-reader.js +41 -5
- package/dist/safe-bash/commands/text-programs/awk-reader.js.map +1 -1
- package/dist/safe-bash/commands/text-programs/awk-retention.d.ts +1 -0
- package/dist/safe-bash/commands/text-programs/awk-retention.d.ts.map +1 -1
- package/dist/safe-bash/commands/text-programs/awk-retention.js +9 -0
- package/dist/safe-bash/commands/text-programs/awk-retention.js.map +1 -1
- package/dist/safe-bash/commands/text-programs/awk-runtime.d.ts +13 -0
- package/dist/safe-bash/commands/text-programs/awk-runtime.d.ts.map +1 -1
- package/dist/safe-bash/commands/text-programs/awk-runtime.js +421 -83
- package/dist/safe-bash/commands/text-programs/awk-runtime.js.map +1 -1
- package/dist/safe-bash/commands/text-programs/awk-values.d.ts.map +1 -1
- package/dist/safe-bash/commands/text-programs/awk-values.js +21 -0
- package/dist/safe-bash/commands/text-programs/awk-values.js.map +1 -1
- package/dist/safe-bash/commands/text-programs/regex.d.ts +15 -2
- package/dist/safe-bash/commands/text-programs/regex.d.ts.map +1 -1
- package/dist/safe-bash/commands/text-programs/regex.js +501 -13
- package/dist/safe-bash/commands/text-programs/regex.js.map +1 -1
- package/dist/safe-bash/commands/text-programs/sed.d.ts.map +1 -1
- package/dist/safe-bash/commands/text-programs/sed.js +242 -102
- package/dist/safe-bash/commands/text-programs/sed.js.map +1 -1
- package/dist/safe-bash/commands/text-programs/shared.d.ts +2 -0
- package/dist/safe-bash/commands/text-programs/shared.d.ts.map +1 -1
- package/dist/safe-bash/commands/text-programs/shared.js +36 -0
- package/dist/safe-bash/commands/text-programs/shared.js.map +1 -1
- package/dist/safe-bash/commands/text.d.ts.map +1 -1
- package/dist/safe-bash/commands/text.js +136 -19
- package/dist/safe-bash/commands/text.js.map +1 -1
- package/dist/safe-bash/commands/tsort/index.browser.js +2 -2
- package/dist/safe-bash/commands/xml/index.browser.js +5 -5
- package/dist/safe-bash/commands/yq/index.browser.js +5 -5
- package/dist/safe-bash/contracts/yield.d.ts +1 -0
- package/dist/safe-bash/contracts/yield.d.ts.map +1 -1
- package/dist/safe-bash/contracts/yield.js +3 -0
- package/dist/safe-bash/contracts/yield.js.map +1 -1
- package/dist/safe-bash/core.browser.js +1052 -256
- package/dist/safe-bash/core.browser.js.map +3 -3
- package/dist/safe-bash/plugins/composition.d.ts +1 -0
- package/dist/safe-bash/plugins/composition.d.ts.map +1 -1
- package/dist/safe-bash/plugins/composition.js +80 -2
- package/dist/safe-bash/plugins/composition.js.map +1 -1
- package/dist/safe-bash/plugins/index.d.ts.map +1 -1
- package/dist/safe-bash/plugins/index.js +2 -2
- package/dist/safe-bash/plugins/index.js.map +1 -1
- package/dist/safe-bash-command-fold/arguments.d.ts +1 -1
- package/dist/safe-bash-command-fold/contracts.d.ts +2 -1
- package/dist/safe-bash-command-fold/engine.d.ts +1 -1
- package/dist/safe-bash-command-fold/index.js +10 -8
- package/dist/safe-bash-command-fold/index.js.map +2 -2
- package/dist/safe-bash-command-sips/index.js +231 -67
- package/dist/safe-bash-command-sips/index.js.map +2 -2
- package/dist/safe-bash-command-unrtf/contracts.d.ts +5 -2
- package/dist/safe-bash-command-unrtf/index.js +6 -5
- package/dist/safe-bash-command-unrtf/index.js.map +2 -2
- package/dist/safe-playwright-cloudflare/browser-run-code.js +22 -6
- package/package.json +2 -2
- package/dist/safe-bash/chunks/chunk-5DLGYPGJ.js.map +0 -7
- package/dist/safe-bash/chunks/chunk-7UJW7TYR.js.map +0 -7
- package/dist/safe-bash/chunks/chunk-B6YFFKYG.js.map +0 -7
- package/dist/safe-bash/chunks/chunk-OTM5RCWZ.js.map +0 -7
- package/dist/safe-bash/chunks/chunk-RP5IZOOR.js.map +0 -7
- package/dist/safe-bash/chunks/chunk-VGJIDLZM.js.map +0 -7
- package/dist/safe-bash/chunks/chunk-VV24PRPB.js.map +0 -7
- package/dist/safe-bash/chunks/chunk-YOK5UHA7.js.map +0 -7
- /package/dist/safe-bash/chunks/{chunk-6VZX7ESE.js.map → chunk-26N7BLXE.js.map} +0 -0
- /package/dist/safe-bash/chunks/{chunk-ZZ7JQBPX.js.map → chunk-4A2OLEML.js.map} +0 -0
- /package/dist/safe-bash/chunks/{chunk-LTREB3HX.js.map → chunk-54MC6XF5.js.map} +0 -0
- /package/dist/safe-bash/chunks/{chunk-Z3CCN6Y2.js.map → chunk-6J5FUESH.js.map} +0 -0
- /package/dist/safe-bash/chunks/{chunk-YR5RZBWS.js.map → chunk-6TBFZ5JE.js.map} +0 -0
- /package/dist/safe-bash/chunks/{chunk-6HJNJ625.js.map → chunk-7MMYQG3P.js.map} +0 -0
- /package/dist/safe-bash/chunks/{chunk-WTZZX4LV.js.map → chunk-A4MB2KXV.js.map} +0 -0
- /package/dist/safe-bash/chunks/{chunk-EM2JW7ZH.js.map → chunk-ATYJKRBZ.js.map} +0 -0
- /package/dist/safe-bash/chunks/{chunk-EFMXWUYE.js.map → chunk-B6JEJ6AT.js.map} +0 -0
- /package/dist/safe-bash/chunks/{chunk-JFGGQUYP.js.map → chunk-BFXGHT3R.js.map} +0 -0
- /package/dist/safe-bash/chunks/{chunk-646RTREQ.js.map → chunk-EEDOYIPC.js.map} +0 -0
- /package/dist/safe-bash/chunks/{chunk-OFAAHWL5.js.map → chunk-GCQ5A2T2.js.map} +0 -0
- /package/dist/safe-bash/chunks/{chunk-MJW4KSKV.js.map → chunk-GLPJEDLY.js.map} +0 -0
- /package/dist/safe-bash/chunks/{chunk-FOOJWH7J.js.map → chunk-GO5OKPBO.js.map} +0 -0
- /package/dist/safe-bash/chunks/{chunk-5JANWFJ3.js.map → chunk-GWYXCCGO.js.map} +0 -0
- /package/dist/safe-bash/chunks/{chunk-DPHRNHPT.js.map → chunk-H6KJ4L22.js.map} +0 -0
- /package/dist/safe-bash/chunks/{chunk-FLX2BZBF.js.map → chunk-HGBYIDAK.js.map} +0 -0
- /package/dist/safe-bash/chunks/{chunk-PO3Z7W3A.js.map → chunk-MUHYGUFD.js.map} +0 -0
- /package/dist/safe-bash/chunks/{chunk-TIHMU25L.js.map → chunk-PQ37GDJF.js.map} +0 -0
- /package/dist/safe-bash/chunks/{chunk-LZ7FUN6K.js.map → chunk-RHHDOA67.js.map} +0 -0
- /package/dist/safe-bash/chunks/{chunk-DSCL3VA2.js.map → chunk-SJ3B26XV.js.map} +0 -0
- /package/dist/safe-bash/chunks/{chunk-6JBTVWHH.js.map → chunk-SWACYEIT.js.map} +0 -0
- /package/dist/safe-bash/chunks/{chunk-Q4I754TV.js.map → chunk-THOBFD5C.js.map} +0 -0
- /package/dist/safe-bash/chunks/{chunk-XELW5O3R.js.map → chunk-U2STHT7S.js.map} +0 -0
- /package/dist/safe-bash/chunks/{chunk-5X4SOSTT.js.map → chunk-UJHE5PTK.js.map} +0 -0
- /package/dist/safe-bash/chunks/{chunk-PLCYP2E5.js.map → chunk-XV4K3UUF.js.map} +0 -0
|
@@ -2,10 +2,10 @@ import {
|
|
|
2
2
|
assertCommandRequirements,
|
|
3
3
|
inputRequirements,
|
|
4
4
|
pathOf
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-KS5VSJYM.js";
|
|
6
6
|
import {
|
|
7
7
|
writeDiagnostic
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-A4MB2KXV.js";
|
|
9
9
|
import {
|
|
10
10
|
PublicDiagnostic,
|
|
11
11
|
publicDiagnosticMessage
|
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
import {
|
|
14
14
|
monotonicNow,
|
|
15
15
|
yieldTurn
|
|
16
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-X4I3RHTC.js";
|
|
17
17
|
import {
|
|
18
18
|
FsError,
|
|
19
19
|
readBytes,
|
|
@@ -44,6 +44,10 @@ var Decimal = class {
|
|
|
44
44
|
text;
|
|
45
45
|
double;
|
|
46
46
|
};
|
|
47
|
+
var SMALL_DECIMALS = Array.from({ length: 1025 }, (_, i) => {
|
|
48
|
+
const s = String(i);
|
|
49
|
+
return new Decimal(s, 0, false, s, i);
|
|
50
|
+
});
|
|
47
51
|
function isNumber(value) {
|
|
48
52
|
return typeof value === "number" || value instanceof Decimal;
|
|
49
53
|
}
|
|
@@ -51,6 +55,33 @@ function numberValue(value) {
|
|
|
51
55
|
return typeof value === "number" ? value : value.double;
|
|
52
56
|
}
|
|
53
57
|
function numericToken(token, budget) {
|
|
58
|
+
const len = token.length;
|
|
59
|
+
if (len >= 1 && len <= 15) {
|
|
60
|
+
const first = token.charCodeAt(0);
|
|
61
|
+
if (first === 48 && len === 1) {
|
|
62
|
+
budget.step(2);
|
|
63
|
+
budget.text(token);
|
|
64
|
+
return SMALL_DECIMALS[0];
|
|
65
|
+
}
|
|
66
|
+
if (first >= 49 && first <= 57) {
|
|
67
|
+
let val = first - 48;
|
|
68
|
+
let allDigits = true;
|
|
69
|
+
for (let i = 1; i < len; i++) {
|
|
70
|
+
const c = token.charCodeAt(i);
|
|
71
|
+
if (c < 48 || c > 57) {
|
|
72
|
+
allDigits = false;
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
val = val * 10 + (c - 48);
|
|
76
|
+
}
|
|
77
|
+
if (allDigits) {
|
|
78
|
+
budget.step(2);
|
|
79
|
+
budget.text(token);
|
|
80
|
+
if (val <= 1024) return SMALL_DECIMALS[val];
|
|
81
|
+
return new Decimal(token, 0, false, token, val);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
54
85
|
budget.step(Math.ceil(token.length / 32));
|
|
55
86
|
const end = token.indexOf("\0");
|
|
56
87
|
const text = end < 0 ? token : token.slice(0, end);
|
|
@@ -212,6 +243,26 @@ var Budget = class {
|
|
|
212
243
|
this.steps += count;
|
|
213
244
|
if (this.steps > this.limits.maxSteps) throw new JqLimitError("maxSteps");
|
|
214
245
|
}
|
|
246
|
+
get currentSteps() {
|
|
247
|
+
return this.steps;
|
|
248
|
+
}
|
|
249
|
+
restoreSteps(steps) {
|
|
250
|
+
this.steps = steps;
|
|
251
|
+
}
|
|
252
|
+
needsYield() {
|
|
253
|
+
return this.steps >= this.nextYield || (this.steps & 31) === 0 && monotonicNow() - this.lastYield >= 25;
|
|
254
|
+
}
|
|
255
|
+
tickSync(count = 1) {
|
|
256
|
+
this.step(count);
|
|
257
|
+
if (this.steps >= this.nextYield || (this.steps & 31) === 0 && monotonicNow() - this.lastYield >= 25) {
|
|
258
|
+
return yieldTurn(this.signal).then(() => {
|
|
259
|
+
this.signal.throwIfAborted();
|
|
260
|
+
this.nextYield = this.steps + 1024;
|
|
261
|
+
this.lastYield = monotonicNow();
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
return void 0;
|
|
265
|
+
}
|
|
215
266
|
async tick(count = 1) {
|
|
216
267
|
this.step(count);
|
|
217
268
|
if (this.steps >= this.nextYield || monotonicNow() - this.lastYield >= 25) {
|
|
@@ -228,41 +279,40 @@ var Budget = class {
|
|
|
228
279
|
if (text.length > this.limits.maxValueBytes || text.length * 3 > this.limits.maxValueBytes && import_buffer.Buffer.byteLength(text) > this.limits.maxValueBytes) throw new JqLimitError("maxValueBytes");
|
|
229
280
|
}
|
|
230
281
|
value(value) {
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
} else {
|
|
245
|
-
const keys = keyOrders.get(current) ?? Object.keys(current);
|
|
246
|
-
this.collection(keys.length);
|
|
247
|
-
bytes2 += 2 + Math.max(0, keys.length - 1);
|
|
248
|
-
for (let index = 0; index < keys.length; index++) {
|
|
249
|
-
const key = keys[index];
|
|
250
|
-
this.text(key);
|
|
251
|
-
bytes2 += scalarJsonByteLength(key, this) + 1;
|
|
252
|
-
if (bytes2 > this.limits.maxValueBytes) throw new JqLimitError("maxValueBytes");
|
|
253
|
-
visit(current[key], depth + 1);
|
|
254
|
-
}
|
|
282
|
+
return this.visitValue(value, 0, 0);
|
|
283
|
+
}
|
|
284
|
+
visitValue(current, depth, bytes2) {
|
|
285
|
+
this.step();
|
|
286
|
+
if (depth > this.limits.maxDepth) throw new JqLimitError("maxDepth");
|
|
287
|
+
if (current !== null && typeof current === "object" && !(current instanceof Decimal)) {
|
|
288
|
+
if (depth + 1 > this.limits.maxDepth) throw new JqLimitError("maxDepth");
|
|
289
|
+
if (Array.isArray(current)) {
|
|
290
|
+
this.collection(current.length);
|
|
291
|
+
bytes2 += 2 + Math.max(0, current.length - 1);
|
|
292
|
+
for (let index = 0; index < current.length; index++) {
|
|
293
|
+
if (bytes2 > this.limits.maxValueBytes) throw new JqLimitError("maxValueBytes");
|
|
294
|
+
bytes2 = this.visitValue(current[index], depth + 1, bytes2);
|
|
255
295
|
}
|
|
256
296
|
} else {
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
297
|
+
const keys = keyOrders.get(current) ?? Object.keys(current);
|
|
298
|
+
this.collection(keys.length);
|
|
299
|
+
bytes2 += 2 + Math.max(0, keys.length - 1);
|
|
300
|
+
for (let index = 0; index < keys.length; index++) {
|
|
301
|
+
const key = keys[index];
|
|
302
|
+
this.text(key);
|
|
303
|
+
bytes2 += scalarJsonByteLength(key, this) + 1;
|
|
304
|
+
if (bytes2 > this.limits.maxValueBytes) throw new JqLimitError("maxValueBytes");
|
|
305
|
+
bytes2 = this.visitValue(current[key], depth + 1, bytes2);
|
|
260
306
|
}
|
|
261
|
-
bytes2 += scalarJsonByteLength(current, this);
|
|
262
307
|
}
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
308
|
+
} else {
|
|
309
|
+
if (typeof current === "string") {
|
|
310
|
+
this.step(current.length);
|
|
311
|
+
this.text(current);
|
|
312
|
+
}
|
|
313
|
+
bytes2 += scalarJsonByteLength(current, this);
|
|
314
|
+
}
|
|
315
|
+
if (bytes2 > this.limits.maxValueBytes) throw new JqLimitError("maxValueBytes");
|
|
266
316
|
return bytes2;
|
|
267
317
|
}
|
|
268
318
|
};
|
|
@@ -450,6 +500,189 @@ var JsonParser = class {
|
|
|
450
500
|
counts = /* @__PURE__ */ new WeakMap();
|
|
451
501
|
closed = /* @__PURE__ */ new WeakSet();
|
|
452
502
|
lastKey = /* @__PURE__ */ new WeakMap();
|
|
503
|
+
isQuotedUnescaped() {
|
|
504
|
+
return this.quoted && !this.escaped && this.bom >= 3;
|
|
505
|
+
}
|
|
506
|
+
isUnquotedReady() {
|
|
507
|
+
return !this.quoted && this.bom >= 3;
|
|
508
|
+
}
|
|
509
|
+
isTopLevelIdle() {
|
|
510
|
+
return !this.quoted && !this.escaped && this.stack.length === 0 && this.token === "" && this.next === void 0 && !this.stream;
|
|
511
|
+
}
|
|
512
|
+
tryParseFlatLine(fullText, start, end) {
|
|
513
|
+
const byteLen = end - start;
|
|
514
|
+
if (byteLen < 2 || byteLen > this.budget.limits.maxValueBytes) return void 0;
|
|
515
|
+
if (fullText.charCodeAt(start) !== 123 || fullText.charCodeAt(end - 1) !== 125) return void 0;
|
|
516
|
+
if (this.budget.limits.maxDepth < 1) return void 0;
|
|
517
|
+
const obj = object();
|
|
518
|
+
let pos = start + 1;
|
|
519
|
+
let count = 0;
|
|
520
|
+
if (pos < end - 1) {
|
|
521
|
+
while (true) {
|
|
522
|
+
if (fullText.charCodeAt(pos) !== 34) return void 0;
|
|
523
|
+
pos++;
|
|
524
|
+
const keyStart = pos;
|
|
525
|
+
while (pos < end - 1) {
|
|
526
|
+
const c = fullText.charCodeAt(pos);
|
|
527
|
+
if (c === 34) break;
|
|
528
|
+
if (c < 32 || c >= 127 || c === 92) return void 0;
|
|
529
|
+
pos++;
|
|
530
|
+
}
|
|
531
|
+
if (pos >= end - 1) return void 0;
|
|
532
|
+
const key = fullText.slice(keyStart, pos);
|
|
533
|
+
if (Object.hasOwn(obj, key)) return void 0;
|
|
534
|
+
pos++;
|
|
535
|
+
if (fullText.charCodeAt(pos) !== 58) return void 0;
|
|
536
|
+
pos++;
|
|
537
|
+
if (pos >= end - 1) return void 0;
|
|
538
|
+
const vFirst = fullText.charCodeAt(pos);
|
|
539
|
+
let val;
|
|
540
|
+
if (vFirst === 34) {
|
|
541
|
+
pos++;
|
|
542
|
+
const vStart = pos;
|
|
543
|
+
while (pos < end - 1) {
|
|
544
|
+
const c = fullText.charCodeAt(pos);
|
|
545
|
+
if (c === 34) break;
|
|
546
|
+
if (c < 32 || c >= 127 || c === 92) return void 0;
|
|
547
|
+
pos++;
|
|
548
|
+
}
|
|
549
|
+
if (pos >= end - 1) return void 0;
|
|
550
|
+
val = fullText.slice(vStart, pos);
|
|
551
|
+
pos++;
|
|
552
|
+
} else if (vFirst === 116) {
|
|
553
|
+
if (fullText.charCodeAt(pos + 1) !== 114 || fullText.charCodeAt(pos + 2) !== 117 || fullText.charCodeAt(pos + 3) !== 101) return void 0;
|
|
554
|
+
val = true;
|
|
555
|
+
pos += 4;
|
|
556
|
+
} else if (vFirst === 102) {
|
|
557
|
+
if (fullText.charCodeAt(pos + 1) !== 97 || fullText.charCodeAt(pos + 2) !== 108 || fullText.charCodeAt(pos + 3) !== 115 || fullText.charCodeAt(pos + 4) !== 101) return void 0;
|
|
558
|
+
val = false;
|
|
559
|
+
pos += 5;
|
|
560
|
+
} else if (vFirst === 110) {
|
|
561
|
+
if (fullText.charCodeAt(pos + 1) !== 117 || fullText.charCodeAt(pos + 2) !== 108 || fullText.charCodeAt(pos + 3) !== 108) return void 0;
|
|
562
|
+
val = null;
|
|
563
|
+
pos += 4;
|
|
564
|
+
} else if (vFirst >= 48 && vFirst <= 57) {
|
|
565
|
+
const nStart = pos;
|
|
566
|
+
let num = vFirst - 48;
|
|
567
|
+
pos++;
|
|
568
|
+
if (vFirst === 48) {
|
|
569
|
+
const nextC = fullText.charCodeAt(pos);
|
|
570
|
+
if (nextC !== 44 && nextC !== 125) return void 0;
|
|
571
|
+
val = SMALL_DECIMALS[0];
|
|
572
|
+
} else {
|
|
573
|
+
while (pos < end - 1) {
|
|
574
|
+
const c = fullText.charCodeAt(pos);
|
|
575
|
+
if (c < 48 || c > 57) break;
|
|
576
|
+
num = num * 10 + (c - 48);
|
|
577
|
+
pos++;
|
|
578
|
+
}
|
|
579
|
+
if (pos - nStart > 15) return void 0;
|
|
580
|
+
const nextC = fullText.charCodeAt(pos);
|
|
581
|
+
if (nextC !== 44 && nextC !== 125) return void 0;
|
|
582
|
+
if (num <= 1024) val = SMALL_DECIMALS[num];
|
|
583
|
+
else {
|
|
584
|
+
const s = fullText.slice(nStart, pos);
|
|
585
|
+
val = new Decimal(s, 0, false, s, num);
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
} else if (vFirst === 91) {
|
|
589
|
+
pos++;
|
|
590
|
+
const arr = [];
|
|
591
|
+
if (fullText.charCodeAt(pos) === 93) {
|
|
592
|
+
pos++;
|
|
593
|
+
} else {
|
|
594
|
+
while (pos < end - 1) {
|
|
595
|
+
const eFirst = fullText.charCodeAt(pos);
|
|
596
|
+
let elem;
|
|
597
|
+
if (eFirst === 34) {
|
|
598
|
+
pos++;
|
|
599
|
+
const sStart = pos;
|
|
600
|
+
while (pos < end - 1) {
|
|
601
|
+
const c = fullText.charCodeAt(pos);
|
|
602
|
+
if (c === 34) break;
|
|
603
|
+
if (c < 32 || c >= 127 || c === 92) return void 0;
|
|
604
|
+
pos++;
|
|
605
|
+
}
|
|
606
|
+
if (pos >= end - 1) return void 0;
|
|
607
|
+
elem = fullText.slice(sStart, pos);
|
|
608
|
+
pos++;
|
|
609
|
+
} else if (eFirst >= 48 && eFirst <= 57) {
|
|
610
|
+
const nStart = pos;
|
|
611
|
+
let num = eFirst - 48;
|
|
612
|
+
pos++;
|
|
613
|
+
if (eFirst !== 48) {
|
|
614
|
+
while (pos < end - 1) {
|
|
615
|
+
const c = fullText.charCodeAt(pos);
|
|
616
|
+
if (c < 48 || c > 57) break;
|
|
617
|
+
num = num * 10 + (c - 48);
|
|
618
|
+
pos++;
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
if (pos - nStart > 15) return void 0;
|
|
622
|
+
const nextC = fullText.charCodeAt(pos);
|
|
623
|
+
if (nextC !== 44 && nextC !== 93) return void 0;
|
|
624
|
+
if (num <= 1024) elem = SMALL_DECIMALS[num];
|
|
625
|
+
else {
|
|
626
|
+
const s = fullText.slice(nStart, pos);
|
|
627
|
+
elem = new Decimal(s, 0, false, s, num);
|
|
628
|
+
}
|
|
629
|
+
} else {
|
|
630
|
+
return void 0;
|
|
631
|
+
}
|
|
632
|
+
arr.push(elem);
|
|
633
|
+
if (arr.length > this.budget.limits.maxCollectionSize) return void 0;
|
|
634
|
+
const aSep = fullText.charCodeAt(pos);
|
|
635
|
+
if (aSep === 44) {
|
|
636
|
+
pos++;
|
|
637
|
+
continue;
|
|
638
|
+
}
|
|
639
|
+
if (aSep === 93) {
|
|
640
|
+
pos++;
|
|
641
|
+
break;
|
|
642
|
+
}
|
|
643
|
+
return void 0;
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
val = arr;
|
|
647
|
+
} else {
|
|
648
|
+
return void 0;
|
|
649
|
+
}
|
|
650
|
+
count++;
|
|
651
|
+
if (count > this.budget.limits.maxCollectionSize) return void 0;
|
|
652
|
+
put(obj, key, val);
|
|
653
|
+
const sep = fullText.charCodeAt(pos);
|
|
654
|
+
if (sep === 44) {
|
|
655
|
+
pos++;
|
|
656
|
+
continue;
|
|
657
|
+
}
|
|
658
|
+
if (sep === 125 && pos === end - 1) break;
|
|
659
|
+
return void 0;
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
this.bom = 3;
|
|
663
|
+
this.offset += byteLen + 1;
|
|
664
|
+
this.line++;
|
|
665
|
+
this.column = 0;
|
|
666
|
+
this.bytes = 0;
|
|
667
|
+
this.budget.step(count * 3 + 2);
|
|
668
|
+
return obj;
|
|
669
|
+
}
|
|
670
|
+
appendQuotedSpan(span) {
|
|
671
|
+
const len = span.length;
|
|
672
|
+
this.offset += len;
|
|
673
|
+
this.column += len;
|
|
674
|
+
this.bytes += len;
|
|
675
|
+
if (this.bytes > this.budget.limits.maxValueBytes) throw new JqLimitError("maxValueBytes");
|
|
676
|
+
this.token += span;
|
|
677
|
+
}
|
|
678
|
+
appendTokenSpan(span) {
|
|
679
|
+
const len = span.length;
|
|
680
|
+
this.offset += len;
|
|
681
|
+
this.column += len;
|
|
682
|
+
this.bytes += len;
|
|
683
|
+
if (this.bytes > this.budget.limits.maxValueBytes) throw new JqLimitError("maxValueBytes");
|
|
684
|
+
this.token += span;
|
|
685
|
+
}
|
|
453
686
|
path() {
|
|
454
687
|
const path = [];
|
|
455
688
|
for (const frame of this.stack) {
|
|
@@ -707,7 +940,8 @@ async function* readChunks(source, budget) {
|
|
|
707
940
|
const newline = chunk.indexOf(10, offset);
|
|
708
941
|
const end = Math.min(newline < 0 ? chunk.length : newline + 1, offset + 16384);
|
|
709
942
|
budget.step(Math.ceil((end - offset) / 1024));
|
|
710
|
-
|
|
943
|
+
const p1 = budget.tickSync();
|
|
944
|
+
if (p1) await p1;
|
|
711
945
|
if (newline >= 0 && end === newline + 1) {
|
|
712
946
|
budget.inputLocation.line++;
|
|
713
947
|
budget.inputLocation.complete = true;
|
|
@@ -737,53 +971,170 @@ async function* jsonValues(source, budget, options = {}) {
|
|
|
737
971
|
let line = 1;
|
|
738
972
|
let column = 0;
|
|
739
973
|
let nulTail;
|
|
740
|
-
|
|
741
|
-
for (const
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
if (
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
974
|
+
try {
|
|
975
|
+
for await (const rawChunk of readBytes(source, budget.signal)) {
|
|
976
|
+
await budget.tick();
|
|
977
|
+
budget.inputBytes += rawChunk.byteLength;
|
|
978
|
+
if (budget.inputBytes > budget.limits.maxInputBytes) throw new JqLimitError("maxInputBytes");
|
|
979
|
+
const fullText = import_buffer.Buffer.isBuffer(rawChunk) ? rawChunk.toString("latin1") : import_buffer.Buffer.from(rawChunk.buffer, rawChunk.byteOffset, rawChunk.byteLength).toString("latin1");
|
|
980
|
+
let chunkOffset = 0;
|
|
981
|
+
while (chunkOffset < fullText.length) {
|
|
982
|
+
if (budget.inputLocation.complete) budget.inputLocation = { ...budget.inputLocation, complete: false };
|
|
983
|
+
const newline = fullText.indexOf("\n", chunkOffset);
|
|
984
|
+
const segEnd = Math.min(newline < 0 ? fullText.length : newline + 1, chunkOffset + 16384);
|
|
985
|
+
budget.step(Math.ceil((segEnd - chunkOffset) / 1024));
|
|
986
|
+
const pt = budget.tickSync();
|
|
987
|
+
if (pt) await pt;
|
|
988
|
+
if (newline >= 0 && segEnd === newline + 1) {
|
|
989
|
+
budget.inputLocation.line++;
|
|
990
|
+
budget.inputLocation.complete = true;
|
|
991
|
+
if (nulTail === void 0 && active && !failed && !options.sequence && !options.stream && !options.streamErrors && parser.isTopLevelIdle()) {
|
|
992
|
+
const fastObj = parser.tryParseFlatLine(fullText, chunkOffset, newline);
|
|
993
|
+
if (fastObj !== void 0) {
|
|
994
|
+
line++;
|
|
995
|
+
column = 0;
|
|
996
|
+
scanned += segEnd - chunkOffset;
|
|
997
|
+
if (scanned >= 1024) {
|
|
998
|
+
scanned &= 1023;
|
|
999
|
+
const p = budget.tickSync();
|
|
1000
|
+
if (p) await p;
|
|
1001
|
+
}
|
|
1002
|
+
yield fastObj;
|
|
1003
|
+
chunkOffset = segEnd;
|
|
1004
|
+
continue;
|
|
1005
|
+
}
|
|
764
1006
|
}
|
|
765
1007
|
}
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
1008
|
+
for (let index = chunkOffset; index < segEnd; index++) {
|
|
1009
|
+
if ((++scanned & 1023) === 0) {
|
|
1010
|
+
const p = budget.tickSync();
|
|
1011
|
+
if (p) await p;
|
|
1012
|
+
}
|
|
1013
|
+
if (nulTail === void 0 && active && !failed) {
|
|
1014
|
+
if (parser.isQuotedUnescaped()) {
|
|
1015
|
+
let end = index;
|
|
1016
|
+
while (end < segEnd) {
|
|
1017
|
+
const code = fullText.charCodeAt(end);
|
|
1018
|
+
if (code === 34 || code === 92 || code === 10 || code === 0 || code === 30) break;
|
|
1019
|
+
end++;
|
|
1020
|
+
}
|
|
1021
|
+
if (end > index) {
|
|
1022
|
+
parser.appendQuotedSpan(fullText.slice(index, end));
|
|
1023
|
+
column += end - index;
|
|
1024
|
+
scanned += end - index - 1;
|
|
1025
|
+
index = end - 1;
|
|
1026
|
+
continue;
|
|
1027
|
+
}
|
|
1028
|
+
} else if (parser.isUnquotedReady()) {
|
|
1029
|
+
const firstCode = fullText.charCodeAt(index);
|
|
1030
|
+
if (firstCode > 32 && firstCode !== 34 && firstCode !== 44 && firstCode !== 58 && firstCode !== 91 && firstCode !== 93 && firstCode !== 123 && firstCode !== 125 && firstCode !== 30) {
|
|
1031
|
+
let end = index + 1;
|
|
1032
|
+
while (end < segEnd) {
|
|
1033
|
+
const c = fullText.charCodeAt(end);
|
|
1034
|
+
if (c <= 32 || c === 34 || c === 44 || c === 58 || c === 91 || c === 93 || c === 123 || c === 125 || c === 30) break;
|
|
1035
|
+
end++;
|
|
1036
|
+
}
|
|
1037
|
+
if (end > index + 1) {
|
|
1038
|
+
parser.appendTokenSpan(fullText.slice(index, end));
|
|
1039
|
+
column += end - index;
|
|
1040
|
+
scanned += end - index - 1;
|
|
1041
|
+
index = end - 1;
|
|
1042
|
+
continue;
|
|
1043
|
+
}
|
|
1044
|
+
}
|
|
1045
|
+
}
|
|
1046
|
+
}
|
|
1047
|
+
const character = fullText[index];
|
|
1048
|
+
if (character === "\0" && nulTail === void 0) nulTail = "";
|
|
1049
|
+
if (nulTail !== void 0) {
|
|
1050
|
+
nulTail += character;
|
|
1051
|
+
if (nulTail.length > budget.limits.maxValueBytes) throw new JqLimitError("maxValueBytes");
|
|
1052
|
+
if (character === "\n") {
|
|
1053
|
+
const tail = nulTail;
|
|
1054
|
+
nulTail = void 0;
|
|
1055
|
+
for (let ti = 0; ti < tail.length; ti++) {
|
|
1056
|
+
if ((++scanned & 1023) === 0) {
|
|
1057
|
+
const p = budget.tickSync();
|
|
1058
|
+
if (p) await p;
|
|
1059
|
+
}
|
|
1060
|
+
const tc = tail[ti];
|
|
1061
|
+
if (tc === "\n") {
|
|
1062
|
+
line++;
|
|
1063
|
+
column = 0;
|
|
1064
|
+
} else column++;
|
|
1065
|
+
if (options.sequence && tc === "") {
|
|
1066
|
+
if (active && !failed) {
|
|
1067
|
+
try {
|
|
1068
|
+
yield* values(parser.finish({ line, column, eof: false }));
|
|
1069
|
+
} catch (error) {
|
|
1070
|
+
yield* failure(error, true);
|
|
1071
|
+
}
|
|
1072
|
+
}
|
|
1073
|
+
parser = new JsonParser(budget, options.stream, line, column);
|
|
1074
|
+
active = true;
|
|
1075
|
+
failed = false;
|
|
1076
|
+
continue;
|
|
1077
|
+
}
|
|
1078
|
+
if (!active) continue;
|
|
1079
|
+
if (!failed) {
|
|
1080
|
+
try {
|
|
1081
|
+
const produced = parser.feed(tc);
|
|
1082
|
+
if (options.stream) {
|
|
1083
|
+
if (parser.events.length) yield* parser.events.splice(0);
|
|
1084
|
+
} else if (produced !== void 0) {
|
|
1085
|
+
yield produced;
|
|
1086
|
+
}
|
|
1087
|
+
} catch (error) {
|
|
1088
|
+
yield* failure(error);
|
|
1089
|
+
}
|
|
1090
|
+
}
|
|
1091
|
+
if (failed && options.streamErrors && !options.sequence && tc === "\n") {
|
|
1092
|
+
parser = new JsonParser(budget, true, line, column);
|
|
1093
|
+
failed = false;
|
|
1094
|
+
}
|
|
1095
|
+
}
|
|
1096
|
+
}
|
|
1097
|
+
continue;
|
|
1098
|
+
}
|
|
1099
|
+
if (character === "\n") {
|
|
1100
|
+
line++;
|
|
1101
|
+
column = 0;
|
|
1102
|
+
} else column++;
|
|
1103
|
+
if (options.sequence && character === "") {
|
|
1104
|
+
if (active && !failed) {
|
|
1105
|
+
try {
|
|
1106
|
+
yield* values(parser.finish({ line, column, eof: false }));
|
|
1107
|
+
} catch (error) {
|
|
1108
|
+
yield* failure(error, true);
|
|
1109
|
+
}
|
|
1110
|
+
}
|
|
1111
|
+
parser = new JsonParser(budget, options.stream, line, column);
|
|
1112
|
+
active = true;
|
|
1113
|
+
failed = false;
|
|
1114
|
+
continue;
|
|
1115
|
+
}
|
|
1116
|
+
if (!active) continue;
|
|
1117
|
+
if (!failed) {
|
|
1118
|
+
try {
|
|
1119
|
+
const produced = parser.feed(character);
|
|
1120
|
+
if (options.stream) {
|
|
1121
|
+
if (parser.events.length) yield* parser.events.splice(0);
|
|
1122
|
+
} else if (produced !== void 0) {
|
|
1123
|
+
yield produced;
|
|
1124
|
+
}
|
|
1125
|
+
} catch (error) {
|
|
1126
|
+
yield* failure(error);
|
|
1127
|
+
}
|
|
1128
|
+
}
|
|
1129
|
+
if (failed && options.streamErrors && !options.sequence && character === "\n") {
|
|
1130
|
+
parser = new JsonParser(budget, true, line, column);
|
|
1131
|
+
failed = false;
|
|
1132
|
+
}
|
|
777
1133
|
}
|
|
778
|
-
|
|
779
|
-
if (failed && options.streamErrors && !options.sequence && character === "\n") {
|
|
780
|
-
parser = new JsonParser(budget, true, line, column);
|
|
781
|
-
failed = false;
|
|
1134
|
+
chunkOffset = segEnd;
|
|
782
1135
|
}
|
|
783
1136
|
}
|
|
784
|
-
|
|
785
|
-
try {
|
|
786
|
-
for await (const chunk of readChunks(source, budget)) yield* scan(import_buffer.Buffer.from(chunk.buffer, chunk.byteOffset, chunk.byteLength).toString("latin1"));
|
|
1137
|
+
budget.inputLocation.complete = true;
|
|
787
1138
|
if (active && !failed) {
|
|
788
1139
|
try {
|
|
789
1140
|
yield* values(parser.finish(options.sequence ? { line, column, eof: true } : void 0));
|
|
@@ -945,13 +1296,65 @@ async function measureValue(value, budget, depth = 0, maxBytes = budget.limits.m
|
|
|
945
1296
|
return bytes2;
|
|
946
1297
|
}
|
|
947
1298
|
async function stringify(value, budget, format = false, maxBytes = budget.limits.maxValueBytes, limitName = "maxValueBytes", asStringValue = false) {
|
|
948
|
-
|
|
1299
|
+
const p0 = budget.tickSync(0);
|
|
1300
|
+
if (p0) await p0;
|
|
1301
|
+
const isCompactPlain = !asStringValue && (format === false || typeof format === "object" && format.indent === "" && !format.ascii && !format.color);
|
|
1302
|
+
if (isCompactPlain && value !== null && typeof value === "object" && !Array.isArray(value) && !isNumber(value) && budget.limits.maxDepth >= 1) {
|
|
1303
|
+
let fastOk = true;
|
|
1304
|
+
let out = "{";
|
|
1305
|
+
let count = 0;
|
|
1306
|
+
for (const key of objectKeyIterator(value)) {
|
|
1307
|
+
for (let i = 0; i < key.length; i++) {
|
|
1308
|
+
const c = key.charCodeAt(i);
|
|
1309
|
+
if (c < 32 || c >= 127 || c === 34 || c === 92) {
|
|
1310
|
+
fastOk = false;
|
|
1311
|
+
break;
|
|
1312
|
+
}
|
|
1313
|
+
}
|
|
1314
|
+
if (!fastOk) break;
|
|
1315
|
+
const v = value[key];
|
|
1316
|
+
let vStr;
|
|
1317
|
+
if (typeof v === "number" && Number.isFinite(v)) {
|
|
1318
|
+
vStr = Object.is(v, -0) ? "-0" : String(v);
|
|
1319
|
+
} else if (isNumber(v) && typeof v === "object" && Number.isFinite(v.double)) {
|
|
1320
|
+
vStr = v.text;
|
|
1321
|
+
} else if (typeof v === "boolean") {
|
|
1322
|
+
vStr = v ? "true" : "false";
|
|
1323
|
+
} else if (v === null) {
|
|
1324
|
+
vStr = "null";
|
|
1325
|
+
} else if (typeof v === "string") {
|
|
1326
|
+
for (let i = 0; i < v.length; i++) {
|
|
1327
|
+
const c = v.charCodeAt(i);
|
|
1328
|
+
if (c < 32 || c >= 127 || c === 34 || c === 92) {
|
|
1329
|
+
fastOk = false;
|
|
1330
|
+
break;
|
|
1331
|
+
}
|
|
1332
|
+
}
|
|
1333
|
+
if (!fastOk) break;
|
|
1334
|
+
vStr = `"${v}"`;
|
|
1335
|
+
} else {
|
|
1336
|
+
fastOk = false;
|
|
1337
|
+
break;
|
|
1338
|
+
}
|
|
1339
|
+
if (count++) out += ",";
|
|
1340
|
+
out += `"${key}":${vStr}`;
|
|
1341
|
+
budget.collection(count);
|
|
1342
|
+
}
|
|
1343
|
+
if (fastOk) {
|
|
1344
|
+
out += "}";
|
|
1345
|
+
if (out.length > maxBytes) throw new JqLimitError(limitName);
|
|
1346
|
+
const pEnd2 = budget.tickSync(out.length + count * 4 + 2);
|
|
1347
|
+
if (pEnd2) await pEnd2;
|
|
1348
|
+
return out;
|
|
1349
|
+
}
|
|
1350
|
+
}
|
|
949
1351
|
const parts = [];
|
|
950
1352
|
let bytes2 = 0;
|
|
951
1353
|
let units = 0;
|
|
952
1354
|
let stringBytes = 2;
|
|
953
1355
|
for (const fragment of jsonFragments(value, budget, format)) {
|
|
954
|
-
|
|
1356
|
+
const pf = budget.tickSync(0);
|
|
1357
|
+
if (pf) await pf;
|
|
955
1358
|
bytes2 += fragment.bytes;
|
|
956
1359
|
if (bytes2 > maxBytes) throw new JqLimitError(limitName);
|
|
957
1360
|
const text = renderJsonFragment(fragment, budget);
|
|
@@ -964,7 +1367,8 @@ async function stringify(value, budget, format = false, maxBytes = budget.limits
|
|
|
964
1367
|
units += text.length;
|
|
965
1368
|
parts.push(text);
|
|
966
1369
|
}
|
|
967
|
-
|
|
1370
|
+
const pEnd = budget.tickSync(units);
|
|
1371
|
+
if (pEnd) await pEnd;
|
|
968
1372
|
return parts.join("");
|
|
969
1373
|
}
|
|
970
1374
|
|
|
@@ -1499,8 +1903,19 @@ var Budget6 = class {
|
|
|
1499
1903
|
if ((++this.checkpoints & 255) === 0 || monotonicNow() - this.lastYield >= 25) {
|
|
1500
1904
|
await yieldTurn(this.context.signal);
|
|
1501
1905
|
this.lastYield = monotonicNow();
|
|
1906
|
+
this.context.signal.throwIfAborted();
|
|
1502
1907
|
}
|
|
1908
|
+
}
|
|
1909
|
+
checkpointSync() {
|
|
1503
1910
|
this.context.signal.throwIfAborted();
|
|
1911
|
+
const count = ++this.checkpoints;
|
|
1912
|
+
if ((count & 255) === 0 || (count & 31) === 0 && monotonicNow() - this.lastYield >= 25) {
|
|
1913
|
+
return yieldTurn(this.context.signal).then(() => {
|
|
1914
|
+
this.lastYield = monotonicNow();
|
|
1915
|
+
this.context.signal.throwIfAborted();
|
|
1916
|
+
});
|
|
1917
|
+
}
|
|
1918
|
+
return void 0;
|
|
1504
1919
|
}
|
|
1505
1920
|
};
|
|
1506
1921
|
function byteString(text) {
|
|
@@ -1529,24 +1944,27 @@ async function readProgram(context, file) {
|
|
|
1529
1944
|
const contents = await context.fs.readFile(virtualPath(context, file), { signal: context.signal });
|
|
1530
1945
|
return import_buffer.Buffer.from(contents).toString("latin1");
|
|
1531
1946
|
}
|
|
1532
|
-
async function*
|
|
1947
|
+
async function* lineRecordBatches(context, files, budget) {
|
|
1533
1948
|
const names = files.length ? files : ["-"];
|
|
1534
1949
|
for (let fileIndex = 0; fileIndex < names.length; fileIndex++) {
|
|
1535
1950
|
const file = names[fileIndex];
|
|
1536
1951
|
let pending = "";
|
|
1537
1952
|
for await (const chunk of input(context, file)) {
|
|
1538
1953
|
budget.step();
|
|
1539
|
-
const text = import_buffer.Buffer.from(chunk).toString("latin1");
|
|
1954
|
+
const text = import_buffer.Buffer.isBuffer(chunk) ? chunk.toString("latin1") : import_buffer.Buffer.from(chunk.buffer, chunk.byteOffset, chunk.byteLength).toString("latin1");
|
|
1540
1955
|
let start = 0;
|
|
1541
1956
|
let end;
|
|
1957
|
+
const batch = [];
|
|
1542
1958
|
while ((end = text.indexOf("\n", start)) >= 0) {
|
|
1543
|
-
|
|
1959
|
+
const slice = pending ? pending + text.slice(start, end) : text.slice(start, end);
|
|
1960
|
+
batch.push({ text: budget.check(slice), terminated: true, file, fileIndex });
|
|
1544
1961
|
pending = "";
|
|
1545
1962
|
start = end + 1;
|
|
1546
1963
|
}
|
|
1547
|
-
pending = budget.check(pending + text.slice(start));
|
|
1964
|
+
pending = budget.check(pending ? pending + text.slice(start) : text.slice(start));
|
|
1965
|
+
if (batch.length > 0) yield batch;
|
|
1548
1966
|
}
|
|
1549
|
-
if (pending) yield { text: pending, terminated: false, file, fileIndex };
|
|
1967
|
+
if (pending) yield [{ text: pending, terminated: false, file, fileIndex }];
|
|
1550
1968
|
}
|
|
1551
1969
|
}
|
|
1552
1970
|
function command(name, run) {
|
|
@@ -1748,7 +2166,11 @@ var Pattern = class {
|
|
|
1748
2166
|
let groups = 0;
|
|
1749
2167
|
let depth = 0;
|
|
1750
2168
|
const closedGroups = /* @__PURE__ */ new Set();
|
|
1751
|
-
const characterNode = (character) => ({
|
|
2169
|
+
const characterNode = (character) => ({
|
|
2170
|
+
type: "character",
|
|
2171
|
+
...ignoreCase ? {} : { literal: character },
|
|
2172
|
+
accepts: (candidate) => ignoreCase ? candidate.toLowerCase() === character.toLowerCase() : candidate === character
|
|
2173
|
+
});
|
|
1752
2174
|
const escaped = () => {
|
|
1753
2175
|
const character = source[offset++];
|
|
1754
2176
|
if (character === void 0) throw new ProgramError("trailing backslash in regular expression");
|
|
@@ -1910,12 +2332,14 @@ var Pattern = class {
|
|
|
1910
2332
|
parsed;
|
|
1911
2333
|
anchored;
|
|
1912
2334
|
linear = false;
|
|
2335
|
+
literalMatch;
|
|
2336
|
+
simpleRepeatMatch;
|
|
1913
2337
|
backreferences = false;
|
|
1914
2338
|
async prepare(budget) {
|
|
1915
2339
|
if (!this.parsed) return;
|
|
1916
2340
|
const { root, counts } = this.parsed;
|
|
1917
2341
|
budget.step(counts.get(root) + 1);
|
|
1918
|
-
await budget.checkpoint();
|
|
2342
|
+
await (budget.checkpointSync ? budget.checkpointSync() : budget.checkpoint());
|
|
1919
2343
|
const code = [];
|
|
1920
2344
|
const ignoreCase = this.ignoreCase;
|
|
1921
2345
|
const emit = (instruction) => {
|
|
@@ -1925,7 +2349,7 @@ var Pattern = class {
|
|
|
1925
2349
|
if (counts.get(node) === 0) return;
|
|
1926
2350
|
yield;
|
|
1927
2351
|
if (node.type === "character") {
|
|
1928
|
-
emit({ kind: "character", accepts: node.accepts });
|
|
2352
|
+
emit({ kind: "character", ...node.literal !== void 0 ? { literal: node.literal } : {}, accepts: node.accepts });
|
|
1929
2353
|
return;
|
|
1930
2354
|
}
|
|
1931
2355
|
if (node.type === "backreference") {
|
|
@@ -1994,14 +2418,84 @@ var Pattern = class {
|
|
|
1994
2418
|
let work = 0;
|
|
1995
2419
|
for (const ignored of compile(root)) {
|
|
1996
2420
|
if (++work % 64 === 0) {
|
|
1997
|
-
await budget.checkpoint();
|
|
2421
|
+
await (budget.checkpointSync ? budget.checkpointSync() : budget.checkpoint());
|
|
1998
2422
|
budget.step(0);
|
|
1999
2423
|
}
|
|
2000
2424
|
}
|
|
2001
2425
|
emit({ kind: "match" });
|
|
2002
|
-
await budget.checkpoint();
|
|
2426
|
+
await (budget.checkpointSync ? budget.checkpointSync() : budget.checkpoint());
|
|
2003
2427
|
budget.step(0);
|
|
2004
2428
|
this.linear = code.every((instruction) => instruction.kind === "character" || instruction.kind === "begin" || instruction.kind === "end" || instruction.kind === "match");
|
|
2429
|
+
if (this.linear && !this.ignoreCase && this.dialect !== "jq") {
|
|
2430
|
+
let validLiteral = true;
|
|
2431
|
+
let anchoredStart = false;
|
|
2432
|
+
let anchoredEnd = false;
|
|
2433
|
+
let literalValue = "";
|
|
2434
|
+
for (let i = 0; i < code.length - 1; i++) {
|
|
2435
|
+
const inst = code[i];
|
|
2436
|
+
if (inst.kind === "begin") {
|
|
2437
|
+
if (i === 0) anchoredStart = true;
|
|
2438
|
+
else {
|
|
2439
|
+
validLiteral = false;
|
|
2440
|
+
break;
|
|
2441
|
+
}
|
|
2442
|
+
} else if (inst.kind === "end") {
|
|
2443
|
+
if (i === code.length - 2) anchoredEnd = true;
|
|
2444
|
+
else {
|
|
2445
|
+
validLiteral = false;
|
|
2446
|
+
break;
|
|
2447
|
+
}
|
|
2448
|
+
} else if (inst.kind === "character" && inst.literal !== void 0) {
|
|
2449
|
+
literalValue += inst.literal;
|
|
2450
|
+
} else {
|
|
2451
|
+
validLiteral = false;
|
|
2452
|
+
break;
|
|
2453
|
+
}
|
|
2454
|
+
}
|
|
2455
|
+
if (validLiteral) {
|
|
2456
|
+
this.literalMatch = { value: literalValue, anchoredStart, anchoredEnd, groups: [literalValue] };
|
|
2457
|
+
}
|
|
2458
|
+
} else if (!this.ignoreCase && this.dialect !== "jq" && root.type === "sequence" && this.groupCount <= 1) {
|
|
2459
|
+
let startIdx = 0;
|
|
2460
|
+
let endIdx = root.nodes.length;
|
|
2461
|
+
let anchoredStart = false;
|
|
2462
|
+
let anchoredEnd = false;
|
|
2463
|
+
if (startIdx < endIdx && root.nodes[startIdx]?.type === "begin") {
|
|
2464
|
+
anchoredStart = true;
|
|
2465
|
+
startIdx++;
|
|
2466
|
+
}
|
|
2467
|
+
if (startIdx < endIdx && root.nodes[endIdx - 1]?.type === "end") {
|
|
2468
|
+
anchoredEnd = true;
|
|
2469
|
+
endIdx--;
|
|
2470
|
+
}
|
|
2471
|
+
if (startIdx < endIdx) {
|
|
2472
|
+
let prefix = "";
|
|
2473
|
+
let prefixValid = true;
|
|
2474
|
+
for (let i = startIdx; i < endIdx - 1; i++) {
|
|
2475
|
+
const n = root.nodes[i];
|
|
2476
|
+
if (n.type === "character" && n.literal !== void 0) {
|
|
2477
|
+
prefix += n.literal;
|
|
2478
|
+
} else {
|
|
2479
|
+
prefixValid = false;
|
|
2480
|
+
break;
|
|
2481
|
+
}
|
|
2482
|
+
}
|
|
2483
|
+
const tail = root.nodes[endIdx - 1];
|
|
2484
|
+
const captured = tail.type === "group" && tail.index === 1 && this.groupCount === 1;
|
|
2485
|
+
const rawInner = captured ? tail.node : this.groupCount === 0 ? tail : void 0;
|
|
2486
|
+
const repeatNode = rawInner?.type === "sequence" && rawInner.nodes.length === 1 ? rawInner.nodes[0] : rawInner;
|
|
2487
|
+
if (prefixValid && (anchoredStart || prefix.length > 0) && repeatNode?.type === "repeat" && repeatNode.minimum >= 1 && repeatNode.maximum === Infinity && !repeatNode.lazy && repeatNode.node.type === "character") {
|
|
2488
|
+
this.simpleRepeatMatch = {
|
|
2489
|
+
prefix,
|
|
2490
|
+
anchoredStart,
|
|
2491
|
+
anchoredEnd,
|
|
2492
|
+
captured,
|
|
2493
|
+
minimum: repeatNode.minimum,
|
|
2494
|
+
accepts: repeatNode.node.accepts
|
|
2495
|
+
};
|
|
2496
|
+
}
|
|
2497
|
+
}
|
|
2498
|
+
}
|
|
2005
2499
|
this.backreferences = code.some((instruction) => instruction.kind === "backreference");
|
|
2006
2500
|
this.code = code;
|
|
2007
2501
|
this.parsed = void 0;
|
|
@@ -2013,7 +2507,7 @@ var Pattern = class {
|
|
|
2013
2507
|
let storage = 0;
|
|
2014
2508
|
let checkpoints = 0;
|
|
2015
2509
|
while (pending.length) {
|
|
2016
|
-
if (++checkpoints % 64 === 1) await budget.checkpoint();
|
|
2510
|
+
if (++checkpoints % 64 === 1) await (budget.checkpointSync ? budget.checkpointSync() : budget.checkpoint());
|
|
2017
2511
|
budget.step();
|
|
2018
2512
|
const state = pending.pop();
|
|
2019
2513
|
if (options.end !== void 0 && state.position > options.end) continue;
|
|
@@ -2079,17 +2573,219 @@ var Pattern = class {
|
|
|
2079
2573
|
}
|
|
2080
2574
|
return void 0;
|
|
2081
2575
|
}
|
|
2576
|
+
canFindSync() {
|
|
2577
|
+
return this.code.length > 0 && this.dialect !== "jq" && Boolean(this.literalMatch || this.simpleRepeatMatch);
|
|
2578
|
+
}
|
|
2579
|
+
findSyncFast(text, budget, from = 0) {
|
|
2580
|
+
if (this.simpleRepeatMatch) {
|
|
2581
|
+
const { prefix, anchoredStart: anchoredStart2, anchoredEnd: anchoredEnd2, captured, minimum, accepts } = this.simpleRepeatMatch;
|
|
2582
|
+
if (from > text.length || anchoredStart2 && from > 0) return void 0;
|
|
2583
|
+
let found2 = -1;
|
|
2584
|
+
let matchEnd = -1;
|
|
2585
|
+
let groupStart = -1;
|
|
2586
|
+
let groupEnd = -1;
|
|
2587
|
+
if (anchoredStart2) {
|
|
2588
|
+
if (text.startsWith(prefix)) {
|
|
2589
|
+
const pos = prefix.length;
|
|
2590
|
+
let cursor = pos;
|
|
2591
|
+
while (cursor < text.length && accepts(text[cursor])) cursor++;
|
|
2592
|
+
if (cursor - pos >= minimum && (!anchoredEnd2 || cursor === text.length)) {
|
|
2593
|
+
found2 = 0;
|
|
2594
|
+
matchEnd = cursor;
|
|
2595
|
+
groupStart = pos;
|
|
2596
|
+
groupEnd = cursor;
|
|
2597
|
+
}
|
|
2598
|
+
}
|
|
2599
|
+
} else {
|
|
2600
|
+
let searchFrom = from;
|
|
2601
|
+
while (searchFrom <= text.length - prefix.length) {
|
|
2602
|
+
const idx = text.indexOf(prefix, searchFrom);
|
|
2603
|
+
if (idx < 0) break;
|
|
2604
|
+
const pos = idx + prefix.length;
|
|
2605
|
+
let cursor = pos;
|
|
2606
|
+
while (cursor < text.length && accepts(text[cursor])) cursor++;
|
|
2607
|
+
if (cursor - pos >= minimum && (!anchoredEnd2 || cursor === text.length)) {
|
|
2608
|
+
found2 = idx;
|
|
2609
|
+
matchEnd = cursor;
|
|
2610
|
+
groupStart = pos;
|
|
2611
|
+
groupEnd = cursor;
|
|
2612
|
+
break;
|
|
2613
|
+
}
|
|
2614
|
+
searchFrom = idx + 1;
|
|
2615
|
+
}
|
|
2616
|
+
}
|
|
2617
|
+
const positionsTried2 = anchoredStart2 ? 1 : found2 >= 0 ? found2 - from + 1 : text.length - from + 1;
|
|
2618
|
+
const len2 = found2 >= 0 ? matchEnd - found2 : 0;
|
|
2619
|
+
budget.step(positionsTried2 * 2 + (found2 >= 0 ? this.code.length * 2 + len2 : 0));
|
|
2620
|
+
if (found2 < 0) return void 0;
|
|
2621
|
+
if (len2 > budget.maxBufferBytes) throw new ProgramError("text buffer limit exceeded");
|
|
2622
|
+
const full = text.slice(found2, matchEnd);
|
|
2623
|
+
const groups2 = captured ? [full, text.slice(groupStart, groupEnd)] : [full];
|
|
2624
|
+
return { start: found2, end: matchEnd, groups: groups2 };
|
|
2625
|
+
}
|
|
2626
|
+
const { value, anchoredStart, anchoredEnd, groups } = this.literalMatch;
|
|
2627
|
+
const len = value.length;
|
|
2628
|
+
if (from > text.length || anchoredStart && from > 0) return void 0;
|
|
2629
|
+
let found = -1;
|
|
2630
|
+
if (anchoredStart && anchoredEnd) {
|
|
2631
|
+
if (from === 0 && text.length === len && text === value) found = 0;
|
|
2632
|
+
} else if (anchoredStart) {
|
|
2633
|
+
if (from === 0 && text.startsWith(value)) found = 0;
|
|
2634
|
+
} else if (anchoredEnd) {
|
|
2635
|
+
const candidate = text.length - len;
|
|
2636
|
+
if (candidate >= from && text.endsWith(value)) found = candidate;
|
|
2637
|
+
} else {
|
|
2638
|
+
found = text.indexOf(value, from);
|
|
2639
|
+
}
|
|
2640
|
+
const positionsTried = anchoredStart ? 1 : found >= 0 ? found - from + 1 : text.length - from + 1;
|
|
2641
|
+
budget.step(positionsTried * 2 + (found >= 0 ? this.code.length * 2 + len : 0));
|
|
2642
|
+
if (found < 0) return void 0;
|
|
2643
|
+
if (len > budget.maxBufferBytes) throw new ProgramError("text buffer limit exceeded");
|
|
2644
|
+
return { start: found, end: found + len, groups };
|
|
2645
|
+
}
|
|
2646
|
+
tryFindSync(text, budget, from = 0) {
|
|
2647
|
+
if (this.code.length && this.simpleRepeatMatch && this.dialect !== "jq") {
|
|
2648
|
+
const initialCheck2 = budget.checkpointSync ? budget.checkpointSync() : budget.checkpoint();
|
|
2649
|
+
if (initialCheck2) return initialCheck2.then(() => this.find(text, budget, from));
|
|
2650
|
+
return this.execSimpleRepeat(text, budget, from);
|
|
2651
|
+
}
|
|
2652
|
+
if (!this.code.length || !this.literalMatch || this.dialect === "jq") {
|
|
2653
|
+
return this.find(text, budget, from);
|
|
2654
|
+
}
|
|
2655
|
+
const initialCheck = budget.checkpointSync ? budget.checkpointSync() : budget.checkpoint();
|
|
2656
|
+
if (initialCheck) return initialCheck.then(() => this.find(text, budget, from));
|
|
2657
|
+
const { value, anchoredStart, anchoredEnd, groups } = this.literalMatch;
|
|
2658
|
+
const len = value.length;
|
|
2659
|
+
if (from > text.length || anchoredStart && from > 0) return void 0;
|
|
2660
|
+
let found = -1;
|
|
2661
|
+
if (anchoredStart && anchoredEnd) {
|
|
2662
|
+
if (from === 0 && text.length === len && text === value) found = 0;
|
|
2663
|
+
} else if (anchoredStart) {
|
|
2664
|
+
if (from === 0 && text.startsWith(value)) found = 0;
|
|
2665
|
+
} else if (anchoredEnd) {
|
|
2666
|
+
const candidate = text.length - len;
|
|
2667
|
+
if (candidate >= from && text.endsWith(value)) found = candidate;
|
|
2668
|
+
} else {
|
|
2669
|
+
found = text.indexOf(value, from);
|
|
2670
|
+
}
|
|
2671
|
+
const positionsTried = anchoredStart ? 1 : found >= 0 ? found - from + 1 : text.length - from + 1;
|
|
2672
|
+
const stepCount = positionsTried * 2 + (found >= 0 ? this.code.length * 2 + len : 0);
|
|
2673
|
+
budget.step(stepCount);
|
|
2674
|
+
if (stepCount >= 64) {
|
|
2675
|
+
const midCheck = budget.checkpointSync ? budget.checkpointSync() : budget.checkpoint();
|
|
2676
|
+
if (midCheck) {
|
|
2677
|
+
if (found < 0) return midCheck.then(() => void 0);
|
|
2678
|
+
if (len > budget.maxBufferBytes) throw new ProgramError("text buffer limit exceeded");
|
|
2679
|
+
return midCheck.then(() => ({ start: found, end: found + len, groups }));
|
|
2680
|
+
}
|
|
2681
|
+
}
|
|
2682
|
+
if (found < 0) return void 0;
|
|
2683
|
+
if (len > budget.maxBufferBytes) throw new ProgramError("text buffer limit exceeded");
|
|
2684
|
+
const endCheck = budget.checkpointSync ? budget.checkpointSync() : budget.checkpoint();
|
|
2685
|
+
if (endCheck) return endCheck.then(() => ({ start: found, end: found + len, groups }));
|
|
2686
|
+
return { start: found, end: found + len, groups };
|
|
2687
|
+
}
|
|
2688
|
+
execSimpleRepeat(text, budget, from) {
|
|
2689
|
+
const { prefix, anchoredStart, anchoredEnd, captured, minimum, accepts } = this.simpleRepeatMatch;
|
|
2690
|
+
if (from > text.length || anchoredStart && from > 0) return void 0;
|
|
2691
|
+
let found = -1;
|
|
2692
|
+
let matchEnd = -1;
|
|
2693
|
+
let groupStart = -1;
|
|
2694
|
+
let groupEnd = -1;
|
|
2695
|
+
if (anchoredStart) {
|
|
2696
|
+
if (text.startsWith(prefix)) {
|
|
2697
|
+
const pos = prefix.length;
|
|
2698
|
+
let cursor = pos;
|
|
2699
|
+
while (cursor < text.length && accepts(text[cursor])) cursor++;
|
|
2700
|
+
if (cursor - pos >= minimum && (!anchoredEnd || cursor === text.length)) {
|
|
2701
|
+
found = 0;
|
|
2702
|
+
matchEnd = cursor;
|
|
2703
|
+
groupStart = pos;
|
|
2704
|
+
groupEnd = cursor;
|
|
2705
|
+
}
|
|
2706
|
+
}
|
|
2707
|
+
} else {
|
|
2708
|
+
let searchFrom = from;
|
|
2709
|
+
while (searchFrom <= text.length - prefix.length) {
|
|
2710
|
+
const idx = text.indexOf(prefix, searchFrom);
|
|
2711
|
+
if (idx < 0) break;
|
|
2712
|
+
const pos = idx + prefix.length;
|
|
2713
|
+
let cursor = pos;
|
|
2714
|
+
while (cursor < text.length && accepts(text[cursor])) cursor++;
|
|
2715
|
+
if (cursor - pos >= minimum && (!anchoredEnd || cursor === text.length)) {
|
|
2716
|
+
found = idx;
|
|
2717
|
+
matchEnd = cursor;
|
|
2718
|
+
groupStart = pos;
|
|
2719
|
+
groupEnd = cursor;
|
|
2720
|
+
break;
|
|
2721
|
+
}
|
|
2722
|
+
searchFrom = idx + 1;
|
|
2723
|
+
}
|
|
2724
|
+
}
|
|
2725
|
+
const positionsTried = anchoredStart ? 1 : found >= 0 ? found - from + 1 : text.length - from + 1;
|
|
2726
|
+
const len = found >= 0 ? matchEnd - found : 0;
|
|
2727
|
+
const stepCount = positionsTried * 2 + (found >= 0 ? this.code.length * 2 + len : 0);
|
|
2728
|
+
budget.step(stepCount);
|
|
2729
|
+
const finish = () => {
|
|
2730
|
+
if (found < 0) return void 0;
|
|
2731
|
+
if (len > budget.maxBufferBytes) throw new ProgramError("text buffer limit exceeded");
|
|
2732
|
+
const full = text.slice(found, matchEnd);
|
|
2733
|
+
const groups = captured ? [full, text.slice(groupStart, groupEnd)] : [full];
|
|
2734
|
+
return { start: found, end: matchEnd, groups };
|
|
2735
|
+
};
|
|
2736
|
+
if (stepCount >= 64) {
|
|
2737
|
+
const midCheck = budget.checkpointSync ? budget.checkpointSync() : budget.checkpoint();
|
|
2738
|
+
if (midCheck) return midCheck.then(finish);
|
|
2739
|
+
}
|
|
2740
|
+
const endCheck = budget.checkpointSync ? budget.checkpointSync() : budget.checkpoint();
|
|
2741
|
+
if (endCheck) return endCheck.then(finish);
|
|
2742
|
+
return finish();
|
|
2743
|
+
}
|
|
2082
2744
|
async find(text, budget, from = 0) {
|
|
2083
2745
|
if (!this.code.length) await this.prepare(budget);
|
|
2084
2746
|
if (this.dialect === "jq") return (await this.findJq(text, budget, from))?.match;
|
|
2085
|
-
|
|
2747
|
+
if (this.simpleRepeatMatch) {
|
|
2748
|
+
const initialCheck2 = budget.checkpointSync ? budget.checkpointSync() : budget.checkpoint();
|
|
2749
|
+
if (initialCheck2) await initialCheck2;
|
|
2750
|
+
return await this.execSimpleRepeat(text, budget, from);
|
|
2751
|
+
}
|
|
2752
|
+
const initialCheck = budget.checkpointSync ? budget.checkpointSync() : budget.checkpoint();
|
|
2753
|
+
if (initialCheck) await initialCheck;
|
|
2754
|
+
if (this.literalMatch) {
|
|
2755
|
+
const { value, anchoredStart, anchoredEnd, groups } = this.literalMatch;
|
|
2756
|
+
const len = value.length;
|
|
2757
|
+
if (from > text.length || anchoredStart && from > 0) return void 0;
|
|
2758
|
+
let found = -1;
|
|
2759
|
+
if (anchoredStart && anchoredEnd) {
|
|
2760
|
+
if (from === 0 && text.length === len && text === value) found = 0;
|
|
2761
|
+
} else if (anchoredStart) {
|
|
2762
|
+
if (from === 0 && text.startsWith(value)) found = 0;
|
|
2763
|
+
} else if (anchoredEnd) {
|
|
2764
|
+
const candidate = text.length - len;
|
|
2765
|
+
if (candidate >= from && text.endsWith(value)) found = candidate;
|
|
2766
|
+
} else {
|
|
2767
|
+
found = text.indexOf(value, from);
|
|
2768
|
+
}
|
|
2769
|
+
const positionsTried = anchoredStart ? 1 : found >= 0 ? found - from + 1 : text.length - from + 1;
|
|
2770
|
+
const stepCount = positionsTried * 2 + (found >= 0 ? this.code.length * 2 + len : 0);
|
|
2771
|
+
budget.step(stepCount);
|
|
2772
|
+
if (stepCount >= 64) {
|
|
2773
|
+
const midCheck = budget.checkpointSync ? budget.checkpointSync() : budget.checkpoint();
|
|
2774
|
+
if (midCheck) await midCheck;
|
|
2775
|
+
}
|
|
2776
|
+
if (found < 0) return void 0;
|
|
2777
|
+
if (len > budget.maxBufferBytes) throw new ProgramError("text buffer limit exceeded");
|
|
2778
|
+
const endCheck = budget.checkpointSync ? budget.checkpointSync() : budget.checkpoint();
|
|
2779
|
+
if (endCheck) await endCheck;
|
|
2780
|
+
return { start: found, end: found + len, groups };
|
|
2781
|
+
}
|
|
2086
2782
|
let units = 0;
|
|
2087
2783
|
const work = (count = 1) => {
|
|
2088
2784
|
budget.step(count);
|
|
2089
2785
|
units += count;
|
|
2090
2786
|
if (units < 64) return void 0;
|
|
2091
2787
|
units %= 64;
|
|
2092
|
-
return budget.checkpoint();
|
|
2788
|
+
return budget.checkpointSync ? budget.checkpointSync() : budget.checkpoint();
|
|
2093
2789
|
};
|
|
2094
2790
|
if (this.linear) {
|
|
2095
2791
|
for (let start = from; start <= text.length && (!this.anchored || start === 0); start++) {
|
|
@@ -2106,7 +2802,7 @@ var Pattern = class {
|
|
|
2106
2802
|
const copied = work(position - start);
|
|
2107
2803
|
if (copied) await copied;
|
|
2108
2804
|
const match = { start, end: position, groups: [text.slice(start, position)] };
|
|
2109
|
-
await budget.checkpoint();
|
|
2805
|
+
await (budget.checkpointSync ? budget.checkpointSync() : budget.checkpoint());
|
|
2110
2806
|
return match;
|
|
2111
2807
|
}
|
|
2112
2808
|
}
|
|
@@ -2281,7 +2977,7 @@ var Pattern = class {
|
|
|
2281
2977
|
const end = bestCaptures[index * 2 + 1];
|
|
2282
2978
|
groups.push(begin === void 0 || end === void 0 ? void 0 : text.slice(begin, end));
|
|
2283
2979
|
}
|
|
2284
|
-
await budget.checkpoint();
|
|
2980
|
+
await (budget.checkpointSync ? budget.checkpointSync() : budget.checkpoint());
|
|
2285
2981
|
return { start: bestStart, end: bestEnd, groups };
|
|
2286
2982
|
}
|
|
2287
2983
|
return void 0;
|
|
@@ -2296,7 +2992,7 @@ async function replacementLength(replacement, match, budget, available, syntax)
|
|
|
2296
2992
|
let length = 0;
|
|
2297
2993
|
let tokens = 0;
|
|
2298
2994
|
for (let index = 0; index < replacement.length; index++) {
|
|
2299
|
-
if (tokens++ % 256 === 0) await budget.checkpoint();
|
|
2995
|
+
if (tokens++ % 256 === 0) await (budget.checkpointSync ? budget.checkpointSync() : budget.checkpoint());
|
|
2300
2996
|
budget.step();
|
|
2301
2997
|
const character = replacement[index];
|
|
2302
2998
|
let size = 1;
|
|
@@ -2322,7 +3018,7 @@ async function replacementText(replacement, match, buffer, budget, syntax) {
|
|
|
2322
3018
|
let literal = 0;
|
|
2323
3019
|
let tokens = 0;
|
|
2324
3020
|
for (let index = 0; index < replacement.length; index++) {
|
|
2325
|
-
if (tokens++ % 256 === 0) await budget.checkpoint();
|
|
3021
|
+
if (tokens++ % 256 === 0) await (budget.checkpointSync ? budget.checkpointSync() : budget.checkpoint());
|
|
2326
3022
|
budget.step();
|
|
2327
3023
|
const character = replacement[index];
|
|
2328
3024
|
if (character !== "&" && (character !== "\\" || index + 1 === replacement.length)) continue;
|
|
@@ -2344,7 +3040,138 @@ async function replacementText(replacement, match, buffer, budget, syntax) {
|
|
|
2344
3040
|
}
|
|
2345
3041
|
await buffer.append(replacement, literal);
|
|
2346
3042
|
}
|
|
3043
|
+
function expandReplacementSync(replacement, match, budget, available, syntax) {
|
|
3044
|
+
if (!replacement.includes("&") && !replacement.includes("\\")) {
|
|
3045
|
+
budget.step(replacement.length * 2 + 1);
|
|
3046
|
+
if (replacement.length > available) throw new ProgramError("text buffer limit exceeded");
|
|
3047
|
+
return replacement;
|
|
3048
|
+
}
|
|
3049
|
+
let out = "";
|
|
3050
|
+
for (let index = 0; index < replacement.length; index++) {
|
|
3051
|
+
budget.step();
|
|
3052
|
+
const character = replacement[index];
|
|
3053
|
+
let piece = character;
|
|
3054
|
+
if (character === "&") {
|
|
3055
|
+
budget.step();
|
|
3056
|
+
piece = match.groups[0] ?? "";
|
|
3057
|
+
} else if (character === "\\" && index + 1 < replacement.length) {
|
|
3058
|
+
budget.step();
|
|
3059
|
+
const next = replacement[++index];
|
|
3060
|
+
if (syntax === "awk") {
|
|
3061
|
+
piece = next === "&" || next === "\\" ? next : `\\${next}`;
|
|
3062
|
+
} else if (next >= "0" && next <= "9") {
|
|
3063
|
+
budget.step();
|
|
3064
|
+
piece = match.groups[Number(next)] ?? "";
|
|
3065
|
+
} else {
|
|
3066
|
+
piece = next === "n" ? "\n" : next === "t" ? " " : next;
|
|
3067
|
+
}
|
|
3068
|
+
}
|
|
3069
|
+
if (piece.length > available - out.length) throw new ProgramError("text buffer limit exceeded");
|
|
3070
|
+
out += piece;
|
|
3071
|
+
}
|
|
3072
|
+
budget.step(out.length + 1);
|
|
3073
|
+
return out;
|
|
3074
|
+
}
|
|
3075
|
+
function trySubstituteSync(text, pattern, replacement, budget, global, occurrence = 1, syntax = "sed") {
|
|
3076
|
+
if (pattern.canFindSync() && text.length <= 4096 && replacement.length <= 256) {
|
|
3077
|
+
const check = budget.checkpointSync ? budget.checkpointSync() : budget.checkpoint();
|
|
3078
|
+
if (check) return substitute(text, pattern, replacement, budget, global, occurrence, syntax);
|
|
3079
|
+
let search = 0;
|
|
3080
|
+
let consumed = 0;
|
|
3081
|
+
let previousEnd = -1;
|
|
3082
|
+
let encountered = 0;
|
|
3083
|
+
let count = 0;
|
|
3084
|
+
let out = "";
|
|
3085
|
+
while (search <= text.length) {
|
|
3086
|
+
budget.step();
|
|
3087
|
+
const match = pattern.findSyncFast(text, budget, search);
|
|
3088
|
+
if (!match) break;
|
|
3089
|
+
if (match.start === match.end && match.start === previousEnd) {
|
|
3090
|
+
search = match.end + 1;
|
|
3091
|
+
continue;
|
|
3092
|
+
}
|
|
3093
|
+
encountered++;
|
|
3094
|
+
if (encountered >= occurrence) {
|
|
3095
|
+
const prefixLen = match.start - consumed;
|
|
3096
|
+
if (out.length + prefixLen > budget.maxBufferBytes) {
|
|
3097
|
+
throw new ProgramError("text buffer limit exceeded");
|
|
3098
|
+
}
|
|
3099
|
+
if (prefixLen > 0) out += text.slice(consumed, match.start);
|
|
3100
|
+
const rep = expandReplacementSync(replacement, match, budget, budget.maxBufferBytes - out.length, syntax);
|
|
3101
|
+
out += rep;
|
|
3102
|
+
consumed = match.end;
|
|
3103
|
+
count++;
|
|
3104
|
+
if (!global) break;
|
|
3105
|
+
}
|
|
3106
|
+
previousEnd = match.end;
|
|
3107
|
+
search = match.end === match.start ? match.end + 1 : match.end;
|
|
3108
|
+
}
|
|
3109
|
+
if (count > 0) {
|
|
3110
|
+
const tailLen = text.length - consumed;
|
|
3111
|
+
if (out.length + tailLen > budget.maxBufferBytes) {
|
|
3112
|
+
throw new ProgramError("text buffer limit exceeded");
|
|
3113
|
+
}
|
|
3114
|
+
if (tailLen > 0) out += text.slice(consumed);
|
|
3115
|
+
} else {
|
|
3116
|
+
out = budget.check(text);
|
|
3117
|
+
}
|
|
3118
|
+
const postCheck = budget.checkpointSync ? budget.checkpointSync() : budget.checkpoint();
|
|
3119
|
+
if (postCheck) return postCheck.then(() => ({ text: out, count }));
|
|
3120
|
+
return { text: out, count };
|
|
3121
|
+
}
|
|
3122
|
+
if (!global && occurrence === 1 && !replacement.includes("&") && !replacement.includes("\\")) {
|
|
3123
|
+
const check = budget.checkpointSync ? budget.checkpointSync() : budget.checkpoint();
|
|
3124
|
+
if (check) return substitute(text, pattern, replacement, budget, global, occurrence, syntax);
|
|
3125
|
+
budget.step();
|
|
3126
|
+
const matchOrPromise = pattern.tryFindSync(text, budget, 0);
|
|
3127
|
+
if (matchOrPromise instanceof Promise) {
|
|
3128
|
+
return matchOrPromise.then((match2) => {
|
|
3129
|
+
if (!match2) {
|
|
3130
|
+
budget.step(0);
|
|
3131
|
+
return { text: budget.check(text), count: 0 };
|
|
3132
|
+
}
|
|
3133
|
+
const newLen2 = text.length - (match2.end - match2.start) + replacement.length;
|
|
3134
|
+
if (newLen2 > budget.maxBufferBytes || match2.start + replacement.length > budget.maxBufferBytes) {
|
|
3135
|
+
throw new ProgramError("text buffer limit exceeded");
|
|
3136
|
+
}
|
|
3137
|
+
budget.step(replacement.length * 2 + 1);
|
|
3138
|
+
const out2 = (match2.start === 0 ? "" : text.slice(0, match2.start)) + replacement + (match2.end === text.length ? "" : text.slice(match2.end));
|
|
3139
|
+
return { text: budget.check(out2), count: 1 };
|
|
3140
|
+
});
|
|
3141
|
+
}
|
|
3142
|
+
const match = matchOrPromise;
|
|
3143
|
+
if (!match) {
|
|
3144
|
+
budget.step(0);
|
|
3145
|
+
return { text: budget.check(text), count: 0 };
|
|
3146
|
+
}
|
|
3147
|
+
const newLen = text.length - (match.end - match.start) + replacement.length;
|
|
3148
|
+
if (newLen > budget.maxBufferBytes || match.start + replacement.length > budget.maxBufferBytes) {
|
|
3149
|
+
throw new ProgramError("text buffer limit exceeded");
|
|
3150
|
+
}
|
|
3151
|
+
budget.step(replacement.length * 2 + 1);
|
|
3152
|
+
const out = (match.start === 0 ? "" : text.slice(0, match.start)) + replacement + (match.end === text.length ? "" : text.slice(match.end));
|
|
3153
|
+
return { text: budget.check(out), count: 1 };
|
|
3154
|
+
}
|
|
3155
|
+
return substitute(text, pattern, replacement, budget, global, occurrence, syntax);
|
|
3156
|
+
}
|
|
2347
3157
|
async function substitute(text, pattern, replacement, budget, global, occurrence = 1, syntax = "sed") {
|
|
3158
|
+
if (!global && occurrence === 1 && !replacement.includes("&") && !replacement.includes("\\")) {
|
|
3159
|
+
const check = budget.checkpointSync ? budget.checkpointSync() : budget.checkpoint();
|
|
3160
|
+
if (check) await check;
|
|
3161
|
+
budget.step();
|
|
3162
|
+
const match = await pattern.find(text, budget, 0);
|
|
3163
|
+
if (!match) {
|
|
3164
|
+
budget.step(0);
|
|
3165
|
+
return { text: budget.check(text), count: 0 };
|
|
3166
|
+
}
|
|
3167
|
+
const newLen = text.length - (match.end - match.start) + replacement.length;
|
|
3168
|
+
if (newLen > budget.maxBufferBytes || match.start + replacement.length > budget.maxBufferBytes) {
|
|
3169
|
+
throw new ProgramError("text buffer limit exceeded");
|
|
3170
|
+
}
|
|
3171
|
+
budget.step(replacement.length * 2 + 1);
|
|
3172
|
+
const out = (match.start === 0 ? "" : text.slice(0, match.start)) + replacement + (match.end === text.length ? "" : text.slice(match.end));
|
|
3173
|
+
return { text: budget.check(out), count: 1 };
|
|
3174
|
+
}
|
|
2348
3175
|
let search = 0;
|
|
2349
3176
|
let consumed = 0;
|
|
2350
3177
|
let previousEnd = -1;
|
|
@@ -2353,7 +3180,7 @@ async function substitute(text, pattern, replacement, budget, global, occurrence
|
|
|
2353
3180
|
const result = new ReplacementBuffer(budget);
|
|
2354
3181
|
try {
|
|
2355
3182
|
while (search <= text.length) {
|
|
2356
|
-
await budget.checkpoint();
|
|
3183
|
+
await (budget.checkpointSync ? budget.checkpointSync() : budget.checkpoint());
|
|
2357
3184
|
budget.step();
|
|
2358
3185
|
const match = await pattern.find(text, budget, search);
|
|
2359
3186
|
if (!match) break;
|
|
@@ -2759,6 +3586,8 @@ async function* splitRegex(input2, source, budget) {
|
|
|
2759
3586
|
|
|
2760
3587
|
// packages/safe-bash/src/commands/structured/interpreter.ts
|
|
2761
3588
|
var deleted = /* @__PURE__ */ Symbol("deleted");
|
|
3589
|
+
var NOT_SINGLE = /* @__PURE__ */ Symbol("NOT_SINGLE");
|
|
3590
|
+
var EMPTY_RESULTS = [];
|
|
2762
3591
|
var UserError = class extends JqError {
|
|
2763
3592
|
constructor(value, message) {
|
|
2764
3593
|
super(message);
|
|
@@ -2766,6 +3595,14 @@ var UserError = class extends JqError {
|
|
|
2766
3595
|
}
|
|
2767
3596
|
value;
|
|
2768
3597
|
};
|
|
3598
|
+
function exactFiniteNumber(value) {
|
|
3599
|
+
if (typeof value === "number") return Number.isFinite(value) ? value : void 0;
|
|
3600
|
+
if (value instanceof Object && "double" in value && "digits" in value && "exponent" in value) {
|
|
3601
|
+
const d = value;
|
|
3602
|
+
if (d.digits.length <= 15 && d.exponent === 0 && Number.isFinite(d.double)) return d.double;
|
|
3603
|
+
}
|
|
3604
|
+
return void 0;
|
|
3605
|
+
}
|
|
2769
3606
|
var Interpreter = class _Interpreter {
|
|
2770
3607
|
constructor(budget, variables, frame) {
|
|
2771
3608
|
this.budget = budget;
|
|
@@ -2778,6 +3615,116 @@ var Interpreter = class _Interpreter {
|
|
|
2778
3615
|
filters = /* @__PURE__ */ new Map();
|
|
2779
3616
|
labels = /* @__PURE__ */ new Map();
|
|
2780
3617
|
labelSequence = { next: 0 };
|
|
3618
|
+
tryRunSync(ast, input2) {
|
|
3619
|
+
const savedSteps = this.budget.currentSteps;
|
|
3620
|
+
const res = this.tryRunSyncInternal(ast, input2);
|
|
3621
|
+
if (res === void 0) this.budget.restoreSteps(savedSteps);
|
|
3622
|
+
return res;
|
|
3623
|
+
}
|
|
3624
|
+
tryRunSyncInternal(ast, input2) {
|
|
3625
|
+
if (this.budget.needsYield()) return void 0;
|
|
3626
|
+
if (ast.kind === "binary" && ast.operator === "|") {
|
|
3627
|
+
this.budget.step();
|
|
3628
|
+
const leftResults = this.tryRunSyncInternal(ast.left, input2);
|
|
3629
|
+
if (!leftResults) return void 0;
|
|
3630
|
+
if (leftResults.length === 0) return EMPTY_RESULTS;
|
|
3631
|
+
if (leftResults.length === 1) return this.tryRunSyncInternal(ast.right, leftResults[0]);
|
|
3632
|
+
const out = [];
|
|
3633
|
+
for (const item of leftResults) {
|
|
3634
|
+
const rightResults = this.tryRunSyncInternal(ast.right, item);
|
|
3635
|
+
if (!rightResults) return void 0;
|
|
3636
|
+
out.push(...rightResults);
|
|
3637
|
+
}
|
|
3638
|
+
return out;
|
|
3639
|
+
}
|
|
3640
|
+
if (ast.kind === "call" && ast.name === "select" && ast.args.length === 1) {
|
|
3641
|
+
this.budget.step();
|
|
3642
|
+
const cond = this.tryEvalSingle(ast.args[0], input2);
|
|
3643
|
+
if (cond === NOT_SINGLE) return void 0;
|
|
3644
|
+
return truth(cond) ? [input2] : EMPTY_RESULTS;
|
|
3645
|
+
}
|
|
3646
|
+
const single = this.tryEvalSingle(ast, input2);
|
|
3647
|
+
if (single !== NOT_SINGLE) return [single];
|
|
3648
|
+
return void 0;
|
|
3649
|
+
}
|
|
3650
|
+
tryEvalSingle(ast, input2) {
|
|
3651
|
+
if (this.budget.needsYield()) return NOT_SINGLE;
|
|
3652
|
+
switch (ast.kind) {
|
|
3653
|
+
case "identity":
|
|
3654
|
+
this.budget.step();
|
|
3655
|
+
return input2;
|
|
3656
|
+
case "literal":
|
|
3657
|
+
this.budget.step();
|
|
3658
|
+
return ast.value;
|
|
3659
|
+
case "index": {
|
|
3660
|
+
this.budget.step();
|
|
3661
|
+
const idx = this.tryEvalSingle(ast.index, input2);
|
|
3662
|
+
if (typeof idx !== "string") return NOT_SINGLE;
|
|
3663
|
+
const base = this.tryEvalSingle(ast.base, input2);
|
|
3664
|
+
if (base === NOT_SINGLE || !(base === null || isObject(base))) return NOT_SINGLE;
|
|
3665
|
+
return base === null ? null : Object.hasOwn(base, idx) ? base[idx] : null;
|
|
3666
|
+
}
|
|
3667
|
+
case "binary": {
|
|
3668
|
+
this.budget.step();
|
|
3669
|
+
const op = ast.operator;
|
|
3670
|
+
if (op === "and" || op === "or") {
|
|
3671
|
+
const left = this.tryEvalSingle(ast.left, input2);
|
|
3672
|
+
if (left === NOT_SINGLE) return NOT_SINGLE;
|
|
3673
|
+
if (op === "and" && !truth(left)) return false;
|
|
3674
|
+
if (op === "or" && truth(left)) return true;
|
|
3675
|
+
const right = this.tryEvalSingle(ast.right, input2);
|
|
3676
|
+
if (right === NOT_SINGLE) return NOT_SINGLE;
|
|
3677
|
+
return truth(right);
|
|
3678
|
+
}
|
|
3679
|
+
if (op === "+" || op === "-" || op === "*" || op === "==" || op === "!=" || op === "<" || op === "<=" || op === ">" || op === ">=") {
|
|
3680
|
+
const rightVal = this.tryEvalSingle(ast.right, input2);
|
|
3681
|
+
if (rightVal === NOT_SINGLE) return NOT_SINGLE;
|
|
3682
|
+
const right = exactFiniteNumber(rightVal);
|
|
3683
|
+
if (right === void 0) return NOT_SINGLE;
|
|
3684
|
+
const leftVal = this.tryEvalSingle(ast.left, input2);
|
|
3685
|
+
if (leftVal === NOT_SINGLE) return NOT_SINGLE;
|
|
3686
|
+
const left = exactFiniteNumber(leftVal);
|
|
3687
|
+
if (left === void 0) return NOT_SINGLE;
|
|
3688
|
+
let res;
|
|
3689
|
+
if (op === "+") res = left + right;
|
|
3690
|
+
else if (op === "-") res = left - right;
|
|
3691
|
+
else if (op === "*") res = left * right;
|
|
3692
|
+
else if (op === "==") res = left === right;
|
|
3693
|
+
else if (op === "!=") res = left !== right;
|
|
3694
|
+
else if (op === "<") res = left < right;
|
|
3695
|
+
else if (op === "<=") res = left <= right;
|
|
3696
|
+
else if (op === ">") res = left > right;
|
|
3697
|
+
else res = left >= right;
|
|
3698
|
+
this.budget.step();
|
|
3699
|
+
return res;
|
|
3700
|
+
}
|
|
3701
|
+
return NOT_SINGLE;
|
|
3702
|
+
}
|
|
3703
|
+
case "object": {
|
|
3704
|
+
this.budget.step();
|
|
3705
|
+
const result = object();
|
|
3706
|
+
for (let i = 0; i < ast.fields.length; i++) {
|
|
3707
|
+
const f = ast.fields[i];
|
|
3708
|
+
const key = this.tryEvalSingle(f.key, input2);
|
|
3709
|
+
if (typeof key !== "string") return NOT_SINGLE;
|
|
3710
|
+
let val;
|
|
3711
|
+
if (f.value) {
|
|
3712
|
+
val = this.tryEvalSingle(f.value, input2);
|
|
3713
|
+
} else if (input2 === null || isObject(input2)) {
|
|
3714
|
+
val = input2 === null ? null : Object.hasOwn(input2, key) ? input2[key] : null;
|
|
3715
|
+
} else {
|
|
3716
|
+
return NOT_SINGLE;
|
|
3717
|
+
}
|
|
3718
|
+
if (val === NOT_SINGLE) return NOT_SINGLE;
|
|
3719
|
+
put(result, key, val);
|
|
3720
|
+
}
|
|
3721
|
+
this.budget.value(result);
|
|
3722
|
+
return result;
|
|
3723
|
+
}
|
|
3724
|
+
default:
|
|
3725
|
+
return NOT_SINGLE;
|
|
3726
|
+
}
|
|
3727
|
+
}
|
|
2781
3728
|
binding(name, value) {
|
|
2782
3729
|
const depth = (this.frame?.depth ?? 0) + 1;
|
|
2783
3730
|
if (depth > this.budget.limits.maxAstDepth) throw new JqLimitError("maxAstDepth");
|
|
@@ -2821,7 +3768,8 @@ var Interpreter = class _Interpreter {
|
|
|
2821
3768
|
return result;
|
|
2822
3769
|
}
|
|
2823
3770
|
async *run(ast, input2) {
|
|
2824
|
-
|
|
3771
|
+
const p = this.budget.tickSync();
|
|
3772
|
+
if (p) await p;
|
|
2825
3773
|
switch (ast.kind) {
|
|
2826
3774
|
case "parameter": {
|
|
2827
3775
|
const filter = this.filters.get(ast);
|
|
@@ -4668,9 +5616,10 @@ export {
|
|
|
4668
5616
|
write,
|
|
4669
5617
|
input,
|
|
4670
5618
|
readProgram,
|
|
4671
|
-
|
|
5619
|
+
lineRecordBatches,
|
|
4672
5620
|
command,
|
|
4673
5621
|
Pattern,
|
|
5622
|
+
trySubstituteSync,
|
|
4674
5623
|
substitute,
|
|
4675
5624
|
Decimal,
|
|
4676
5625
|
isNumber,
|
|
@@ -4699,4 +5648,4 @@ export {
|
|
|
4699
5648
|
moduleProgram,
|
|
4700
5649
|
parse
|
|
4701
5650
|
};
|
|
4702
|
-
//# sourceMappingURL=chunk-
|
|
5651
|
+
//# sourceMappingURL=chunk-BJYV5J65.js.map
|