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