@poe-platform/safe-js 0.1.99 → 0.1.101
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-js/chunks/{chunk-Y6QY2SFF.js → chunk-4N5UNUJB.js} +2 -2
- package/dist/safe-js/chunks/{chunk-ZFJQGJ3M.js → chunk-PCHV72VT.js} +130 -74
- package/dist/safe-js/chunks/chunk-PCHV72VT.js.map +7 -0
- package/dist/safe-js/cli.js +2 -2
- package/dist/safe-js/core.js +1 -1
- package/dist/safe-js/index.js +2 -2
- package/dist/safe-js/interp/values.d.ts +3 -1
- package/package.json +2 -2
- package/dist/safe-js/chunks/chunk-ZFJQGJ3M.js.map +0 -7
- /package/dist/safe-js/chunks/{chunk-Y6QY2SFF.js.map → chunk-4N5UNUJB.js.map} +0 -0
|
@@ -27,7 +27,7 @@ import {
|
|
|
27
27
|
validateMigrationSemantics,
|
|
28
28
|
validateSnapshotData,
|
|
29
29
|
validateSnapshotMigration
|
|
30
|
-
} from "./chunk-
|
|
30
|
+
} from "./chunk-PCHV72VT.js";
|
|
31
31
|
|
|
32
32
|
// packages/safe-js/src/migrate.ts
|
|
33
33
|
import { createHash } from "node:crypto";
|
|
@@ -8245,4 +8245,4 @@ export {
|
|
|
8245
8245
|
parseMcpConfig,
|
|
8246
8246
|
makeMcpModule
|
|
8247
8247
|
};
|
|
8248
|
-
//# sourceMappingURL=chunk-
|
|
8248
|
+
//# sourceMappingURL=chunk-4N5UNUJB.js.map
|
|
@@ -8184,6 +8184,28 @@ function isCounter(value) {
|
|
|
8184
8184
|
// packages/safe-js/src/interp/cancel.ts
|
|
8185
8185
|
import { AsyncLocalStorage as AsyncLocalStorage4 } from "node:async_hooks";
|
|
8186
8186
|
|
|
8187
|
+
// packages/safe-js/src/interp/builtin-call.ts
|
|
8188
|
+
async function invokeBuiltinClosure(closure, args, budget, context, thisValue, construct = false) {
|
|
8189
|
+
if (context?.invokeClosure !== void 0) {
|
|
8190
|
+
return context.invokeClosure(closure, args, thisValue, construct);
|
|
8191
|
+
}
|
|
8192
|
+
const leaveCall = budget.enterCall();
|
|
8193
|
+
try {
|
|
8194
|
+
const invoke = construct ? closure.construct : closure.call;
|
|
8195
|
+
if (invoke === void 0) throw new TypeError("Value is not a constructor.");
|
|
8196
|
+
const result = await invoke(args, {
|
|
8197
|
+
...context,
|
|
8198
|
+
stack: context?.stack ?? [],
|
|
8199
|
+
thisValue,
|
|
8200
|
+
invokeClosure: (target, values, receiver, asConstructor) => invokeBuiltinClosure(target, values, budget, context, receiver, asConstructor)
|
|
8201
|
+
});
|
|
8202
|
+
if (isSandboxPromise(result)) await result.synchronousPrefix;
|
|
8203
|
+
return result;
|
|
8204
|
+
} finally {
|
|
8205
|
+
leaveCall();
|
|
8206
|
+
}
|
|
8207
|
+
}
|
|
8208
|
+
|
|
8187
8209
|
// packages/safe-js/src/interp/regex/engine.ts
|
|
8188
8210
|
function matchRegex(pattern, input, lastIndex = 0) {
|
|
8189
8211
|
const startIndex = pattern.flags.global ? normalizeLastIndex(lastIndex) : 0;
|
|
@@ -8485,49 +8507,39 @@ function toMatchArray(match, input) {
|
|
|
8485
8507
|
|
|
8486
8508
|
// packages/safe-js/src/interp/string-coercion.ts
|
|
8487
8509
|
var defaultStringHook = /* @__PURE__ */ Symbol("defaultStringHook");
|
|
8510
|
+
var defaultValueHook = /* @__PURE__ */ Symbol("defaultValueHook");
|
|
8511
|
+
function sandboxNumber(value, budget, context) {
|
|
8512
|
+
if (value === null || typeof value !== "object") {
|
|
8513
|
+
if (typeof value === "function") throw new TypeError("Expected a sandbox value.");
|
|
8514
|
+
return Number(value);
|
|
8515
|
+
}
|
|
8516
|
+
return objectToPrimitive(value, budget, context, /* @__PURE__ */ new Set(), "number").then(Number);
|
|
8517
|
+
}
|
|
8488
8518
|
function sandboxString(value, budget, context, joining = /* @__PURE__ */ new Set()) {
|
|
8489
8519
|
if (value === null || typeof value !== "object") {
|
|
8490
8520
|
if (typeof value === "function") throw new TypeError("Expected a sandbox value.");
|
|
8491
8521
|
return budget.allocateString(String(value));
|
|
8492
8522
|
}
|
|
8493
|
-
|
|
8494
|
-
...context,
|
|
8495
|
-
stack: context?.stack ?? [],
|
|
8496
|
-
thisValue: context?.thisValue,
|
|
8497
|
-
invokeClosure: async (closure, args, thisValue) => {
|
|
8498
|
-
const leaveCall = budget.enterCall();
|
|
8499
|
-
try {
|
|
8500
|
-
const result = closure.call(args, { ...invocation, thisValue });
|
|
8501
|
-
if (isSandboxPromise(result)) {
|
|
8502
|
-
await result.synchronousPrefix;
|
|
8503
|
-
return result;
|
|
8504
|
-
}
|
|
8505
|
-
return await result;
|
|
8506
|
-
} finally {
|
|
8507
|
-
leaveCall();
|
|
8508
|
-
}
|
|
8509
|
-
}
|
|
8510
|
-
};
|
|
8511
|
-
return stringifyObject(value, budget, invocation, joining);
|
|
8523
|
+
return objectToPrimitive(value, budget, context, joining, "string").then((primitive) => budget.allocateString(String(primitive)));
|
|
8512
8524
|
}
|
|
8513
|
-
async function
|
|
8525
|
+
async function objectToPrimitive(value, budget, context, joining, hint) {
|
|
8514
8526
|
const leaveCall = budget.enterCall();
|
|
8515
8527
|
try {
|
|
8516
8528
|
budget.visitNode();
|
|
8517
|
-
for (const name of ["toString", "valueOf"]) {
|
|
8529
|
+
for (const name of hint === "string" ? ["toString", "valueOf"] : ["valueOf", "toString"]) {
|
|
8518
8530
|
const hook = conversionHook(value, name, budget);
|
|
8519
8531
|
let result;
|
|
8520
8532
|
if (hook === defaultStringHook) {
|
|
8521
8533
|
result = await defaultToString(value, budget, context, joining);
|
|
8534
|
+
} else if (hook === defaultValueHook) {
|
|
8535
|
+
result = isSandboxDate(value) ? dateTime(value) : value;
|
|
8522
8536
|
} else {
|
|
8523
8537
|
if (!isSandboxClosure(hook)) continue;
|
|
8524
|
-
|
|
8525
|
-
throw new TypeError("String hooks require a sandbox call context.");
|
|
8526
|
-
}
|
|
8527
|
-
result = await context.invokeClosure(hook, [], value);
|
|
8538
|
+
result = await invokeBuiltinClosure(hook, [], budget, context, value);
|
|
8528
8539
|
}
|
|
8529
8540
|
if (result === null || typeof result !== "object") {
|
|
8530
|
-
|
|
8541
|
+
if (typeof result === "function") throw new TypeError("Expected a sandbox value.");
|
|
8542
|
+
return result;
|
|
8531
8543
|
}
|
|
8532
8544
|
}
|
|
8533
8545
|
throw new TypeError("Cannot convert object to primitive value");
|
|
@@ -8549,7 +8561,7 @@ function conversionHook(value, name, budget) {
|
|
|
8549
8561
|
}
|
|
8550
8562
|
const parent = getSandboxPrototype(current, budget);
|
|
8551
8563
|
if (current === value && (implicitBuiltin || parent === null && !hasExplicitSandboxPrototype(value))) {
|
|
8552
|
-
return name === "toString" ? defaultStringHook :
|
|
8564
|
+
return name === "toString" ? defaultStringHook : defaultValueHook;
|
|
8553
8565
|
}
|
|
8554
8566
|
current = parent;
|
|
8555
8567
|
if (current !== null) {
|
|
@@ -8574,10 +8586,7 @@ async function defaultToString(value, budget, context, joining) {
|
|
|
8574
8586
|
const join = ownDataValue(value, "join");
|
|
8575
8587
|
if (!isSandboxClosure(join))
|
|
8576
8588
|
return isFloat32Array(value) ? "[object Float32Array]" : "[object Array]";
|
|
8577
|
-
|
|
8578
|
-
throw new TypeError("String hooks require a sandbox call context.");
|
|
8579
|
-
}
|
|
8580
|
-
return context.invokeClosure(join, [], value);
|
|
8589
|
+
return invokeBuiltinClosure(join, [], budget, context, value);
|
|
8581
8590
|
}
|
|
8582
8591
|
if (joining.has(value)) return "";
|
|
8583
8592
|
joining.add(value);
|
|
@@ -28080,7 +28089,9 @@ function createCoercionContext(context) {
|
|
|
28080
28089
|
stack: context.callStack,
|
|
28081
28090
|
thisValue: void 0,
|
|
28082
28091
|
compilation: context.compilation,
|
|
28083
|
-
|
|
28092
|
+
getProperty: (value, property) => getPropertyValue(value, property, context),
|
|
28093
|
+
reconcileData: (value) => reconcileDataBudget(context.budget, context.stats, context.scope, value, context.compilation, context.compilation?.parent),
|
|
28094
|
+
invokeClosure: (closure, args, thisValue, construct) => invokeSandboxClosure(closure, args, context, context.callStack, void 0, thisValue, construct)
|
|
28084
28095
|
};
|
|
28085
28096
|
}
|
|
28086
28097
|
function hasSandboxProperty(value, key, context) {
|
|
@@ -28457,7 +28468,9 @@ async function invokeSandboxClosure(callee, args, context, stack, span, thisValu
|
|
|
28457
28468
|
stack,
|
|
28458
28469
|
thisValue,
|
|
28459
28470
|
compilation: context.compilation,
|
|
28460
|
-
|
|
28471
|
+
getProperty: (value, property) => getPropertyValue(value, property, context),
|
|
28472
|
+
reconcileData: (value) => reconcileDataBudget(context.budget, context.stats, context.scope, value, context.compilation, context.compilation?.parent),
|
|
28473
|
+
invokeClosure: (closure, argumentsList, receiver, asConstructor) => invokeSandboxClosure(closure, argumentsList, context, stack, span, receiver, asConstructor),
|
|
28461
28474
|
...span === void 0 ? {} : { span }
|
|
28462
28475
|
}
|
|
28463
28476
|
]);
|
|
@@ -30153,7 +30166,7 @@ async function stringifyValue(value, state, indent) {
|
|
|
30153
30166
|
return stringifyArray(value, state, indent);
|
|
30154
30167
|
}
|
|
30155
30168
|
if (isStringifyObject(value)) {
|
|
30156
|
-
return
|
|
30169
|
+
return stringifyObject(value, state, indent);
|
|
30157
30170
|
}
|
|
30158
30171
|
return void 0;
|
|
30159
30172
|
}
|
|
@@ -30179,7 +30192,7 @@ ${indent}]`;
|
|
|
30179
30192
|
leaveStringifyObject(value, state);
|
|
30180
30193
|
}
|
|
30181
30194
|
}
|
|
30182
|
-
async function
|
|
30195
|
+
async function stringifyObject(value, state, indent) {
|
|
30183
30196
|
enterStringifyObject(value, state);
|
|
30184
30197
|
try {
|
|
30185
30198
|
const nextIndent = indent + state.gap;
|
|
@@ -30550,7 +30563,7 @@ function createObjectArrayGlobals(options) {
|
|
|
30550
30563
|
}),
|
|
30551
30564
|
from: createSandboxClosure({
|
|
30552
30565
|
sandbox: true,
|
|
30553
|
-
call: (args) => arrayFromSandboxValues(args, options.budget),
|
|
30566
|
+
call: (args, context) => arrayFromSandboxValues(args, options.budget, context),
|
|
30554
30567
|
name: "from"
|
|
30555
30568
|
}),
|
|
30556
30569
|
of: createSandboxClosure({
|
|
@@ -30584,7 +30597,7 @@ function createObjectArrayGlobals(options) {
|
|
|
30584
30597
|
}),
|
|
30585
30598
|
Number: createSandboxClosure({
|
|
30586
30599
|
sandbox: true,
|
|
30587
|
-
call: (
|
|
30600
|
+
call: (args, context) => sandboxNumber(args.length === 0 ? 0 : args[0], options.budget, context),
|
|
30588
30601
|
name: "Number",
|
|
30589
30602
|
properties: {
|
|
30590
30603
|
isFinite: createSandboxClosure({
|
|
@@ -30730,40 +30743,86 @@ function defineDataProperty2(target, key, descriptor, budget) {
|
|
|
30730
30743
|
function isAssignableSandboxTarget(value) {
|
|
30731
30744
|
return typeof value === "object" && value !== null && !isSandboxClosure(value) && !isSandboxGenerator(value) && !isSandboxMap(value) && !isSandboxSet(value) && !isSandboxPromise(value) && !isSandboxRegex(value);
|
|
30732
30745
|
}
|
|
30733
|
-
async function arrayFromSandboxValues(args, budget) {
|
|
30746
|
+
async function arrayFromSandboxValues(args, budget, context) {
|
|
30734
30747
|
const [items, mapFn, thisValue] = args;
|
|
30748
|
+
if (mapFn !== void 0 && !isSandboxClosure(mapFn)) {
|
|
30749
|
+
throw new TypeError("Array.from mapping callback must be a function.");
|
|
30750
|
+
}
|
|
30751
|
+
if (items === null || items === void 0) {
|
|
30752
|
+
throw new TypeError("Array.from requires a non-null input.");
|
|
30753
|
+
}
|
|
30754
|
+
const read = (property) => context?.getProperty !== void 0 ? context.getProperty(items, property) : getSandboxDataProperty(items, property, budget);
|
|
30735
30755
|
const iterator = getSandboxIterator(items);
|
|
30736
|
-
|
|
30737
|
-
|
|
30738
|
-
|
|
30739
|
-
|
|
30740
|
-
|
|
30741
|
-
|
|
30742
|
-
|
|
30743
|
-
|
|
30744
|
-
|
|
30745
|
-
|
|
30746
|
-
|
|
30747
|
-
|
|
30756
|
+
const constructor = context?.thisValue;
|
|
30757
|
+
let result;
|
|
30758
|
+
let currentValue;
|
|
30759
|
+
let failure;
|
|
30760
|
+
let estimatedDataSize = 0;
|
|
30761
|
+
const retained = {};
|
|
30762
|
+
budget.setRetainedValues(retained, () => [items, mapFn, constructor, result, currentValue, failure]);
|
|
30763
|
+
const checkData = (growth = 0, force = false) => {
|
|
30764
|
+
const limit = budget.limits.dataSize;
|
|
30765
|
+
if (limit === void 0) return;
|
|
30766
|
+
estimatedDataSize = Math.max(estimatedDataSize, budget.currentDataSize) + growth;
|
|
30767
|
+
if (!force && estimatedDataSize <= limit) return;
|
|
30768
|
+
if (context?.reconcileData !== void 0) context.reconcileData(result);
|
|
30769
|
+
else reconcileCompiledValues(budget, [], context?.compilation);
|
|
30770
|
+
estimatedDataSize = budget.currentDataSize;
|
|
30771
|
+
};
|
|
30772
|
+
const closeOnThrow = async (error) => {
|
|
30773
|
+
failure = isCapturedException(error) ? error.reason : error;
|
|
30774
|
+
try {
|
|
30775
|
+
await iterator?.return?.();
|
|
30776
|
+
} catch (closeError) {
|
|
30777
|
+
if (!isFatalSandboxError(error) && isFatalSandboxError(closeError)) throw closeError;
|
|
30748
30778
|
}
|
|
30749
|
-
|
|
30750
|
-
}
|
|
30751
|
-
|
|
30752
|
-
|
|
30753
|
-
if (
|
|
30754
|
-
|
|
30779
|
+
throw error;
|
|
30780
|
+
};
|
|
30781
|
+
try {
|
|
30782
|
+
let length = 0;
|
|
30783
|
+
if (iterator === void 0) {
|
|
30784
|
+
const number = await sandboxNumber(read("length"), budget, context);
|
|
30785
|
+
length = Number.isNaN(number) || number <= 0 ? 0 : Math.min(Math.trunc(number), Number.MAX_SAFE_INTEGER);
|
|
30755
30786
|
}
|
|
30756
|
-
|
|
30757
|
-
|
|
30758
|
-
|
|
30759
|
-
|
|
30760
|
-
|
|
30761
|
-
|
|
30762
|
-
|
|
30787
|
+
result = isSandboxClosure(constructor) && constructor.construct !== void 0 ? await invokeBuiltinClosure(constructor, iterator === void 0 ? [length] : [], budget, context, void 0, true) : createArrayFromConstructorArgs([length], budget);
|
|
30788
|
+
checkData(0, true);
|
|
30789
|
+
let index = 0;
|
|
30790
|
+
while (iterator !== void 0 || index < length) {
|
|
30791
|
+
try {
|
|
30792
|
+
budget.visitNode();
|
|
30793
|
+
if (iterator !== void 0 && index >= Number.MAX_SAFE_INTEGER) throw new TypeError("Array.from input is too long.");
|
|
30794
|
+
} catch (error) {
|
|
30795
|
+
await closeOnThrow(error);
|
|
30796
|
+
}
|
|
30797
|
+
if (iterator !== void 0) {
|
|
30798
|
+
const next = await iterator.next();
|
|
30799
|
+
if (typeof next !== "object" || next === null) throw new TypeError("Iterator result must be an object.");
|
|
30800
|
+
if (next.done) break;
|
|
30801
|
+
currentValue = next.value;
|
|
30802
|
+
} else {
|
|
30803
|
+
currentValue = read(index);
|
|
30804
|
+
}
|
|
30805
|
+
try {
|
|
30806
|
+
if (Array.isArray(result)) budget.allocateArrayLength(index + 1);
|
|
30807
|
+
if (mapFn !== void 0) currentValue = await invokeBuiltinClosure(mapFn, [currentValue, index], budget, context, thisValue);
|
|
30808
|
+
const key = String(index);
|
|
30809
|
+
const growth = key.length + 1 + (Array.isArray(result) ? Math.max(0, index + 1 - result.length) : 0) + (typeof currentValue === "string" ? currentValue.length : 0);
|
|
30810
|
+
const graphChanged = typeof currentValue === "object" && currentValue !== null || isSandboxClosure(result);
|
|
30811
|
+
budget.visitNode();
|
|
30812
|
+
defineOwnDataProperty(objectProperties(result, true), key, currentValue);
|
|
30813
|
+
currentValue = void 0;
|
|
30814
|
+
checkData(growth, graphChanged);
|
|
30815
|
+
} catch (error) {
|
|
30816
|
+
await closeOnThrow(error);
|
|
30817
|
+
}
|
|
30818
|
+
index += 1;
|
|
30763
30819
|
}
|
|
30764
|
-
|
|
30820
|
+
setSandboxProperty(result, "length", index, budget);
|
|
30821
|
+
checkData(0, true);
|
|
30822
|
+
return allocateProducedSandboxValue(result, budget);
|
|
30823
|
+
} finally {
|
|
30824
|
+
budget.setRetainedValues(retained, void 0);
|
|
30765
30825
|
}
|
|
30766
|
-
return budgetSandboxValue2(mappedValues, budget);
|
|
30767
30826
|
}
|
|
30768
30827
|
function createArrayFromConstructorArgs(args, budget) {
|
|
30769
30828
|
if (args.length !== 1) {
|
|
@@ -30777,14 +30836,11 @@ function createArrayFromConstructorArgs(args, budget) {
|
|
|
30777
30836
|
throw new RangeError("Invalid array length.");
|
|
30778
30837
|
}
|
|
30779
30838
|
budget.allocateArrayLength(lengthOrValue);
|
|
30780
|
-
|
|
30781
|
-
|
|
30782
|
-
|
|
30783
|
-
|
|
30784
|
-
|
|
30785
|
-
const result = await iterator.next();
|
|
30786
|
-
if (result.done) return values;
|
|
30787
|
-
values.push(result.value);
|
|
30839
|
+
const release = budget.provisionDataUsage(lengthOrValue + 1);
|
|
30840
|
+
try {
|
|
30841
|
+
return new Array(lengthOrValue);
|
|
30842
|
+
} finally {
|
|
30843
|
+
release();
|
|
30788
30844
|
}
|
|
30789
30845
|
}
|
|
30790
30846
|
function getOwnEnumerableKeys(value) {
|
|
@@ -32944,4 +33000,4 @@ export {
|
|
|
32944
33000
|
FileSnapshotBackend,
|
|
32945
33001
|
run
|
|
32946
33002
|
};
|
|
32947
|
-
//# sourceMappingURL=chunk-
|
|
33003
|
+
//# sourceMappingURL=chunk-PCHV72VT.js.map
|