@poe-platform/safe-js 0.1.453 → 0.1.455

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-E2VDSNJC.js";
30
+ } from "./chunk-TZUXEKIQ.js";
31
31
 
32
32
  // packages/safe-js/src/migrate.ts
33
33
  import { createHash } from "node:crypto";
@@ -8249,4 +8249,4 @@ export {
8249
8249
  parseMcpConfig,
8250
8250
  makeMcpModule
8251
8251
  };
8252
- //# sourceMappingURL=chunk-CEBPHXBL.js.map
8252
+ //# sourceMappingURL=chunk-JB2Z6L3C.js.map
@@ -19606,6 +19606,79 @@ function relativeIndex(numeric, length) {
19606
19606
  return integer2 < 0 ? Math.max(length + integer2, 0) : Math.min(integer2, length);
19607
19607
  }
19608
19608
 
19609
+ // packages/safe-js/src/interp/globals/group-by.ts
19610
+ function createGroupBy(budget, keyMode) {
19611
+ return createSandboxClosure({
19612
+ guest: true,
19613
+ sandbox: true,
19614
+ name: "groupBy",
19615
+ length: 2,
19616
+ call: async ([items, callback], context) => {
19617
+ if (items === null || items === void 0) throw new TypeError("groupBy requires an iterable.");
19618
+ if (!isSandboxClosure(callback)) throw new TypeError("groupBy requires a callable callback.");
19619
+ const iterator = context === void 0 ? getSandboxIterator(items, budget) : await acquireSandboxIterator(items, budget, context);
19620
+ if (iterator === void 0) throw new TypeError("groupBy requires an iterable.");
19621
+ const groups = createSandboxMap([]);
19622
+ let value;
19623
+ let key;
19624
+ const release = retainValues(budget, () => [groups, callback, iterator.retainedValue, value, key]);
19625
+ const checkpoint = createDataCheckpoint(budget, context);
19626
+ const closeOnThrow = async (error) => {
19627
+ try {
19628
+ await closeIterator(iterator, true);
19629
+ } catch (closeError) {
19630
+ if (!isFatalSandboxError(error) && isFatalSandboxError(closeError)) throw closeError;
19631
+ }
19632
+ throw error;
19633
+ };
19634
+ try {
19635
+ let index = 0;
19636
+ while (true) {
19637
+ try {
19638
+ budget.visitNode();
19639
+ if (index >= Number.MAX_SAFE_INTEGER) throw new TypeError("groupBy input exceeds the maximum index.");
19640
+ } catch (error) {
19641
+ await closeOnThrow(error);
19642
+ }
19643
+ const next = await iterator.next();
19644
+ if ((await readIteratorResult(iterator, next, "done")).value) break;
19645
+ value = (await readIteratorResult(iterator, next, "value")).value;
19646
+ try {
19647
+ key = await invokeBuiltinClosure(callback, [value, index], budget, context, void 0);
19648
+ if (keyMode === "property") key = await toPropertyKey(key, budget, context);
19649
+ let group = groups.entries.get(key);
19650
+ const added = group === void 0;
19651
+ if (group === void 0) {
19652
+ budget.allocateCollectionEntries(groups.entries.size + 1);
19653
+ group = [];
19654
+ groups.entries.set(key, group);
19655
+ }
19656
+ budget.allocateArrayLength(group.length + 1);
19657
+ group.push(value);
19658
+ const growth = 1 + (added ? 2 : 0) + (budget.limits.dataSize === void 0 ? 0 : measureSandboxData(added ? [key, value] : [value]));
19659
+ checkpoint(groups, growth);
19660
+ value = key = void 0;
19661
+ index++;
19662
+ } catch (error) {
19663
+ await closeOnThrow(error);
19664
+ }
19665
+ }
19666
+ checkpoint(groups, 0, true);
19667
+ if (keyMode === "identity") return allocateProducedSandboxValue(groups, budget);
19668
+ const result = /* @__PURE__ */ Object.create(null);
19669
+ setSandboxPrototype(result, null, budget);
19670
+ for (const [property, elements] of groups.entries) {
19671
+ budget.visitNode();
19672
+ defineOwnDataProperty(result, property, elements);
19673
+ }
19674
+ return allocateProducedSandboxValue(result, budget);
19675
+ } finally {
19676
+ release();
19677
+ }
19678
+ }
19679
+ });
19680
+ }
19681
+
19609
19682
  // packages/safe-js/src/interp/globals/numeric-parsers.ts
19610
19683
  function createNumericParsers(budget) {
19611
19684
  return {
@@ -22030,6 +22103,7 @@ function createObjectArrayGlobals(options) {
22030
22103
  call: ([left, right]) => Reflect.apply(Object.is, Object, [left, right]),
22031
22104
  name: "is"
22032
22105
  }),
22106
+ groupBy: createGroupBy(options.budget, "property"),
22033
22107
  fromEntries: createSandboxClosure({
22034
22108
  sandbox: true,
22035
22109
  call: ([value], context) => {
@@ -30655,6 +30729,91 @@ function defineDataProperty2(target, key, value) {
30655
30729
  });
30656
30730
  }
30657
30731
 
30732
+ // packages/safe-js/src/interp/globals/set-operations.ts
30733
+ var setOperationNames = ["union", "intersection", "difference", "symmetricDifference", "isSubsetOf", "isSupersetOf", "isDisjointFrom"];
30734
+ function createSetOperation(name, budget) {
30735
+ return createSandboxClosure({
30736
+ guest: true,
30737
+ sandbox: true,
30738
+ name,
30739
+ length: 1,
30740
+ call: async ([other], context) => {
30741
+ const receiver = context?.thisValue;
30742
+ if (!isSandboxSet(receiver)) throw new TypeError(`Set.prototype.${name} requires a Set receiver.`);
30743
+ if (typeof other !== "object" || other === null) throw new TypeError("Expected a set-like object.");
30744
+ const read = async (object, key) => context?.getProperty !== void 0 ? context.getProperty(object, key) : readPropertyDescriptor(getSandboxPropertyDescriptor(object, key, budget) ?? { value: void 0 }, object, context);
30745
+ const iterationContext = { ...context, thisValue: receiver, stack: context?.stack ?? [], getProperty: read };
30746
+ const result = createSandboxSet([]);
30747
+ let iterator;
30748
+ let current;
30749
+ let has;
30750
+ let keys;
30751
+ const release = retainValues(budget, () => [receiver, other, result, current, has, keys, iterator?.retainedValue]);
30752
+ const checkpoint = createDataCheckpoint(budget, context);
30753
+ const add = (value) => {
30754
+ budget.visitNode();
30755
+ if (result.values.has(value)) return;
30756
+ budget.allocateCollectionEntries(result.values.size + 1);
30757
+ result.values.add(value);
30758
+ checkpoint(result, 1 + (budget.limits.dataSize === void 0 ? 0 : measureSandboxData([value])));
30759
+ };
30760
+ try {
30761
+ const numericSize = await sandboxNumber(await read(other, "size"), budget, context);
30762
+ if (Number.isNaN(numericSize)) throw new TypeError("Invalid set-like size.");
30763
+ const size = Math.trunc(numericSize);
30764
+ if (size < 0) throw new RangeError("Negative set-like size.");
30765
+ has = await read(other, "has");
30766
+ if (!isSandboxClosure(has)) throw new TypeError("Set-like has must be callable.");
30767
+ keys = await read(other, "keys");
30768
+ if (!isSandboxClosure(keys)) throw new TypeError("Set-like keys must be callable.");
30769
+ if (name === "isSubsetOf" && receiver.values.size > size || name === "isSupersetOf" && receiver.values.size < size) return false;
30770
+ const visitReceiver = name === "isSubsetOf" || (name === "intersection" || name === "difference" || name === "isDisjointFrom") && receiver.values.size <= size;
30771
+ if (name === "union" || name === "symmetricDifference")
30772
+ iterator = await getSandboxIteratorFromMethod(other, keys, budget, iterationContext);
30773
+ if (name === "union" || name === "symmetricDifference" || name === "difference")
30774
+ for (const value of receiver.values) add(value);
30775
+ if (visitReceiver) {
30776
+ const target = name === "difference" ? result : receiver;
30777
+ const cursor = enterKeyedCollectionCallback(target, target.values, budget);
30778
+ try {
30779
+ for (let next = cursor.next(); !next.done; next = cursor.next()) {
30780
+ current = next.value;
30781
+ const found = Boolean(await invokeBuiltinClosure(has, [current], budget, context, other));
30782
+ if (name === "isSubsetOf" && !found || name === "isDisjointFrom" && found) return false;
30783
+ if (name === "intersection" && found) add(current);
30784
+ if (name === "difference" && found) result.values.delete(current);
30785
+ current = void 0;
30786
+ }
30787
+ } finally {
30788
+ cursor.leave();
30789
+ }
30790
+ } else {
30791
+ iterator ??= await getSandboxIteratorFromMethod(other, keys, budget, iterationContext);
30792
+ while (true) {
30793
+ budget.visitNode();
30794
+ const next = await iterator.next();
30795
+ if ((await readIteratorResult(iterator, next, "done")).value) break;
30796
+ current = (await readIteratorResult(iterator, next, "value")).value;
30797
+ const found = receiver.values.has(current);
30798
+ if (name === "isSupersetOf" && !found || name === "isDisjointFrom" && found) {
30799
+ await closeIterator(iterator);
30800
+ return false;
30801
+ }
30802
+ if (name === "union" || name === "intersection" && found || name === "symmetricDifference" && !found) add(current);
30803
+ else if (name === "difference" || name === "symmetricDifference" && found) result.values.delete(current);
30804
+ current = void 0;
30805
+ }
30806
+ }
30807
+ if (name === "isSubsetOf" || name === "isSupersetOf" || name === "isDisjointFrom") return true;
30808
+ checkpoint(result, 0, true);
30809
+ return allocateProducedSandboxValue(result, budget);
30810
+ } finally {
30811
+ release();
30812
+ }
30813
+ }
30814
+ });
30815
+ }
30816
+
30658
30817
  // packages/safe-js/src/interp/globals/collection-prototypes.ts
30659
30818
  function installCollectionPrototypes(budget, mapConstructor, setConstructor) {
30660
30819
  const mapMethods = Object.fromEntries([...mapMethodNames].map((name) => [name, createSandboxClosure({
@@ -30686,6 +30845,7 @@ function installCollectionPrototypes(budget, mapConstructor, setConstructor) {
30686
30845
  }
30687
30846
  })]));
30688
30847
  setMethods.keys = setMethods.values;
30848
+ for (const name of setOperationNames) setMethods[name] = createSetOperation(name, budget);
30689
30849
  const mapSize = createSandboxClosure({
30690
30850
  guest: true,
30691
30851
  sandbox: true,
@@ -30835,6 +30995,11 @@ function createCollectionGlobals(options) {
30835
30995
  name: "Set"
30836
30996
  });
30837
30997
  mapConstructors.add(mapConstructor);
30998
+ Object.defineProperty(materializeFunctionProperties(mapConstructor), "groupBy", {
30999
+ value: createGroupBy(options.budget, "identity"),
31000
+ writable: true,
31001
+ configurable: true
31002
+ });
30838
31003
  setConstructors.add(setConstructor);
30839
31004
  installCollectionPrototypes(options.budget, mapConstructor, setConstructor);
30840
31005
  return { Map: mapConstructor, Set: setConstructor };
@@ -55816,4 +55981,4 @@ The above copyright notice and this permission notice shall be included in all c
55816
55981
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
55817
55982
 
55818
55983
  */
55819
- //# sourceMappingURL=chunk-E2VDSNJC.js.map
55984
+ //# sourceMappingURL=chunk-TZUXEKIQ.js.map