@poe-platform/safe-js 0.1.106 → 0.1.108

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.
@@ -27,7 +27,7 @@ import {
27
27
  validateMigrationSemantics,
28
28
  validateSnapshotData,
29
29
  validateSnapshotMigration
30
- } from "./chunk-FV3SMFMZ.js";
30
+ } from "./chunk-OCJ6MUNL.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-OWVEZETW.js.map
8248
+ //# sourceMappingURL=chunk-FPFTLLMZ.js.map
@@ -25362,6 +25362,20 @@ function typeTag(value) {
25362
25362
  return "Object";
25363
25363
  }
25364
25364
 
25365
+ // packages/safe-js/src/interp/data-checkpoint.ts
25366
+ function createDataCheckpoint(budget, context) {
25367
+ let estimatedDataSize = 0;
25368
+ return (value, growth = 0, force = false) => {
25369
+ const limit = budget.limits.dataSize;
25370
+ if (limit === void 0) return;
25371
+ estimatedDataSize = Math.max(estimatedDataSize, budget.currentDataSize) + growth;
25372
+ if (!force && estimatedDataSize <= limit) return;
25373
+ if (context?.reconcileData !== void 0) context.reconcileData(value);
25374
+ else reconcileCompiledValues(budget, [value], context?.compilation);
25375
+ estimatedDataSize = budget.currentDataSize;
25376
+ };
25377
+ }
25378
+
25365
25379
  // packages/safe-js/src/interp/globals/collections.ts
25366
25380
  var mapConstructors = /* @__PURE__ */ new WeakSet();
25367
25381
  var setConstructors = /* @__PURE__ */ new WeakSet();
@@ -25371,12 +25385,27 @@ function createCollectionGlobals(options) {
25371
25385
  call: () => {
25372
25386
  throw new TypeError("Constructor Map requires 'new'.");
25373
25387
  },
25374
- construct: ([source]) => {
25375
- const entries = getMapEntries(source);
25376
- if (entries instanceof Promise) {
25377
- return entries.then((resolved) => createBudgetedMap(resolved, options.budget));
25378
- }
25379
- return createBudgetedMap(entries, options.budget);
25388
+ construct: ([source], context) => {
25389
+ const map = createSandboxMap([]);
25390
+ let key;
25391
+ let value;
25392
+ return populateCollection(source, map, {
25393
+ name: "Map",
25394
+ budget: options.budget,
25395
+ context,
25396
+ retainedValues: () => [key, value],
25397
+ append: (entry) => {
25398
+ if (typeof entry !== "object" || entry === null) throw new TypeError("Map constructor requires entry objects.");
25399
+ key = context?.getProperty !== void 0 ? context.getProperty(entry, 0) : getSandboxDataProperty(entry, 0, options.budget);
25400
+ value = context?.getProperty !== void 0 ? context.getProperty(entry, 1) : getSandboxDataProperty(entry, 1, options.budget);
25401
+ const added = map.entries.has(key) ? 0 : 1;
25402
+ const growth = added + (options.budget.limits.dataSize === void 0 ? 0 : measureSandboxData([key, value]));
25403
+ options.budget.allocateCollectionEntries(map.entries.size + added);
25404
+ map.entries.set(key, value);
25405
+ key = value = void 0;
25406
+ return growth;
25407
+ }
25408
+ });
25380
25409
  },
25381
25410
  name: "Map"
25382
25411
  });
@@ -25385,12 +25414,20 @@ function createCollectionGlobals(options) {
25385
25414
  call: () => {
25386
25415
  throw new TypeError("Constructor Set requires 'new'.");
25387
25416
  },
25388
- construct: ([source]) => {
25389
- const values = getSetValues(source);
25390
- if (values instanceof Promise) {
25391
- return values.then((resolved) => createBudgetedSet(resolved, options.budget));
25392
- }
25393
- return createBudgetedSet(values, options.budget);
25417
+ construct: ([source], context) => {
25418
+ const set = createSandboxSet([]);
25419
+ return populateCollection(source, set, {
25420
+ name: "Set",
25421
+ budget: options.budget,
25422
+ context,
25423
+ append: (value) => {
25424
+ const added = set.values.has(value) ? 0 : 1;
25425
+ const growth = added + (options.budget.limits.dataSize === void 0 ? 0 : measureSandboxData([value]));
25426
+ options.budget.allocateCollectionEntries(set.values.size + added);
25427
+ set.values.add(value);
25428
+ return growth;
25429
+ }
25430
+ });
25394
25431
  },
25395
25432
  name: "Set"
25396
25433
  });
@@ -25404,71 +25441,68 @@ function isSandboxMapConstructor(value) {
25404
25441
  function isSandboxSetConstructor(value) {
25405
25442
  return typeof value === "object" && value !== null && setConstructors.has(value);
25406
25443
  }
25407
- function getMapEntries(source) {
25408
- if (source === void 0 || source === null) {
25409
- return [];
25410
- }
25411
- if (isSandboxMap(source)) {
25412
- return [...source.entries];
25413
- }
25414
- if (Array.isArray(source)) {
25415
- return validateMapEntries(source);
25416
- }
25444
+ function populateCollection(source, collection, { name, budget, context, append, retainedValues }) {
25445
+ budget.allocateCollectionEntries(0);
25446
+ if (source === void 0 || source === null) return collection;
25417
25447
  const iterator = getSandboxIterator(source);
25418
- if (iterator?.generator !== true) {
25419
- throw new TypeError("Map constructor argument must be an array of pairs or a Map.");
25420
- }
25421
- return collectMapEntries(iterator);
25422
- }
25423
- async function collectMapEntries(iterator) {
25424
- const sourceEntries = [];
25425
- while (true) {
25426
- const result = await iterator.next();
25427
- if (result.done) break;
25428
- sourceEntries.push(result.value);
25429
- }
25430
- return validateMapEntries(sourceEntries);
25431
- }
25432
- function validateMapEntries(sourceEntries) {
25433
- return sourceEntries.map((entry) => {
25434
- if (!Array.isArray(entry)) {
25435
- throw new TypeError("Map constructor entries must be arrays.");
25448
+ if (iterator === void 0) throw new TypeError(`${name} constructor requires an iterable.`);
25449
+ let entry;
25450
+ let failure;
25451
+ const retained = {};
25452
+ budget.setRetainedValues(retained, () => [source, collection, entry, failure, ...retainedValues?.() ?? []]);
25453
+ const checkData = createDataCheckpoint(budget, context);
25454
+ const closeOnThrow = (error) => {
25455
+ failure = isCapturedException(error) ? error.reason : error;
25456
+ const rethrow = (closeError) => {
25457
+ if (!isFatalSandboxError(error) && isFatalSandboxError(closeError)) throw closeError;
25458
+ throw error;
25459
+ };
25460
+ try {
25461
+ const closing = iterator.return?.();
25462
+ if (iterator.generator) return Promise.resolve(closing).then(() => {
25463
+ throw error;
25464
+ }, rethrow);
25465
+ } catch (closeError) {
25466
+ return rethrow(closeError);
25436
25467
  }
25437
- return [entry[0], entry[1]];
25438
- });
25439
- }
25440
- function getSetValues(source) {
25441
- if (source === void 0 || source === null) {
25442
- return [];
25443
- }
25444
- if (isSandboxSet(source)) {
25445
- return [...source.values];
25446
- }
25447
- if (typeof source === "string") return [...source];
25448
- if (Array.isArray(source)) return [...source];
25449
- const iterator = getSandboxIterator(source);
25450
- if (iterator?.generator === true) {
25451
- return collectSetValues(iterator);
25468
+ throw error;
25469
+ };
25470
+ const consume = (result) => {
25471
+ if (typeof result !== "object" || result === null) throw new TypeError("Iterator result must be an object.");
25472
+ if (result.done) return true;
25473
+ entry = result.value;
25474
+ try {
25475
+ budget.visitNode();
25476
+ const growth = append(entry);
25477
+ entry = void 0;
25478
+ checkData(collection, growth);
25479
+ } catch (error) {
25480
+ return closeOnThrow(error);
25481
+ }
25482
+ return false;
25483
+ };
25484
+ if (iterator.generator) {
25485
+ return (async () => {
25486
+ try {
25487
+ checkData(collection, 0, true);
25488
+ while (!await consume(await iterator.next())) {
25489
+ }
25490
+ checkData(collection, 0, true);
25491
+ return collection;
25492
+ } finally {
25493
+ budget.setRetainedValues(retained, void 0);
25494
+ }
25495
+ })();
25452
25496
  }
25453
- throw new TypeError("Set constructor argument must be an array, string, or Set.");
25454
- }
25455
- async function collectSetValues(iterator) {
25456
- const values = [];
25457
- while (true) {
25458
- const result = await iterator.next();
25459
- if (result.done) break;
25460
- values.push(result.value);
25497
+ try {
25498
+ checkData(collection, 0, true);
25499
+ while (!consume(iterator.next())) {
25500
+ }
25501
+ checkData(collection, 0, true);
25502
+ return collection;
25503
+ } finally {
25504
+ budget.setRetainedValues(retained, void 0);
25461
25505
  }
25462
- return values;
25463
- }
25464
- function createBudgetedMap(entries, budget) {
25465
- const map = createSandboxMap(entries);
25466
- budget.allocateCollectionEntries(map.entries.size);
25467
- return map;
25468
- }
25469
- function createBudgetedSet(values, budget) {
25470
- budget.allocateCollectionEntries(new Set(values).size);
25471
- return createSandboxSet(values);
25472
25506
  }
25473
25507
 
25474
25508
  // packages/safe-js/src/interp/globals/float32array.ts
@@ -30836,18 +30870,6 @@ async function arrayFromSandboxValues(args, budget, context) {
30836
30870
  budget.setRetainedValues(retained, void 0);
30837
30871
  }
30838
30872
  }
30839
- function createDataCheckpoint(budget, context) {
30840
- let estimatedDataSize = 0;
30841
- return (value, growth = 0, force = false) => {
30842
- const limit = budget.limits.dataSize;
30843
- if (limit === void 0) return;
30844
- estimatedDataSize = Math.max(estimatedDataSize, budget.currentDataSize) + growth;
30845
- if (!force && estimatedDataSize <= limit) return;
30846
- if (context?.reconcileData !== void 0) context.reconcileData(value);
30847
- else reconcileCompiledValues(budget, [value], context?.compilation);
30848
- estimatedDataSize = budget.currentDataSize;
30849
- };
30850
- }
30851
30873
  function createArrayFromConstructorArgs(args, budget) {
30852
30874
  if (args.length !== 1) {
30853
30875
  return budgetSandboxValue2(Reflect.apply(Array, Array, [...args]), budget);
@@ -33023,4 +33045,4 @@ export {
33023
33045
  FileSnapshotBackend,
33024
33046
  run
33025
33047
  };
33026
- //# sourceMappingURL=chunk-FV3SMFMZ.js.map
33048
+ //# sourceMappingURL=chunk-OCJ6MUNL.js.map