@poe-platform/safe-js 0.1.452 → 0.1.454

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.
@@ -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) => {
@@ -28545,7 +28619,7 @@ async function buildLocaleTag(input, optionsInput, budget, context) {
28545
28619
  }
28546
28620
  const updated = Object.values(base).filter((value) => value !== void 0).join("-") + canonical.slice(native.baseName.length);
28547
28621
  const extension = unicodeKeywords(updated);
28548
- const optionTypes3 = [
28622
+ const optionTypes4 = [
28549
28623
  ["calendar", "ca", "unicodeType"],
28550
28624
  ["collation", "co", "unicodeType"],
28551
28625
  ["firstDayOfWeek", "fw", "unicodeType"],
@@ -28554,7 +28628,7 @@ async function buildLocaleTag(input, optionsInput, budget, context) {
28554
28628
  ["numeric", "kn", "boolean"],
28555
28629
  ["numberingSystem", "nu", "unicodeType"]
28556
28630
  ];
28557
- for (const [key, extensionKey, type] of optionTypes3) {
28631
+ for (const [key, extensionKey, type] of optionTypes4) {
28558
28632
  let value = await readIntlProperty(options, key, budget, context);
28559
28633
  if (value === void 0) continue;
28560
28634
  if (key === "firstDayOfWeek") {
@@ -28597,20 +28671,43 @@ function formatList(value, strings, parts) {
28597
28671
  return Reflect.apply(parts ? formatToParts2 : format, listFormatState(value).native, [strings]);
28598
28672
  }
28599
28673
 
28600
- // packages/safe-js/src/interp/intl-numberformat.ts
28674
+ // packages/safe-js/src/interp/intl-relativetimeformat.ts
28675
+ var NativeRelativeTimeFormat = Intl.RelativeTimeFormat;
28676
+ var resolvedOptions3 = NativeRelativeTimeFormat.prototype.resolvedOptions;
28677
+ var format2 = NativeRelativeTimeFormat.prototype.format;
28678
+ var formatToParts3 = NativeRelativeTimeFormat.prototype.formatToParts;
28601
28679
  var states7 = /* @__PURE__ */ new WeakMap();
28680
+ function createSandboxRelativeTimeFormat(locales2, options) {
28681
+ const native = new NativeRelativeTimeFormat(locales2, options);
28682
+ const value = /* @__PURE__ */ Object.create(null);
28683
+ states7.set(value, { native, options: Reflect.apply(resolvedOptions3, native, []) });
28684
+ return value;
28685
+ }
28686
+ function isSandboxRelativeTimeFormat(value) {
28687
+ return typeof value === "object" && value !== null && states7.has(value);
28688
+ }
28689
+ function relativeTimeFormatState(value) {
28690
+ if (!isSandboxRelativeTimeFormat(value)) throw new TypeError("Intl.RelativeTimeFormat requires a RelativeTimeFormat receiver.");
28691
+ return states7.get(value);
28692
+ }
28693
+ function formatRelativeTime(value, amount, unit, parts) {
28694
+ return Reflect.apply(parts ? formatToParts3 : format2, relativeTimeFormatState(value).native, [amount, unit]);
28695
+ }
28696
+
28697
+ // packages/safe-js/src/interp/intl-numberformat.ts
28698
+ var states8 = /* @__PURE__ */ new WeakMap();
28602
28699
  function createSandboxNumberFormat(locales2, options) {
28603
28700
  const native = createNumberFormatter(locales2, options);
28604
28701
  const value = /* @__PURE__ */ Object.create(null);
28605
- states7.set(value, { native, options: numberFormatterOptions2(native) });
28702
+ states8.set(value, { native, options: numberFormatterOptions2(native) });
28606
28703
  return value;
28607
28704
  }
28608
28705
  function isSandboxNumberFormat(value) {
28609
- return typeof value === "object" && value !== null && states7.has(value);
28706
+ return typeof value === "object" && value !== null && states8.has(value);
28610
28707
  }
28611
28708
  function numberFormatState(value) {
28612
28709
  if (!isSandboxNumberFormat(value)) throw new TypeError("Intl.NumberFormat requires a NumberFormat receiver.");
28613
- return states7.get(value);
28710
+ return states8.get(value);
28614
28711
  }
28615
28712
  async function numberFormatValue(value, budget, context) {
28616
28713
  const primitive = typeof value === "object" && value !== null ? await objectToPrimitive(value, budget, context, /* @__PURE__ */ new Set(), "number") : value;
@@ -28965,9 +29062,10 @@ function captureGuestHeapNode(value, encode) {
28965
29062
  }
28966
29063
  if (isSandboxLocale(value)) return { kind: "guest-locale", tag: localeTag(value), state: captureObjectState(value, encode) };
28967
29064
  if (isSandboxListFormat(value)) return { kind: "guest-listformat", options: { ...listFormatState(value).options }, state: captureObjectState(value, encode) };
29065
+ if (isSandboxRelativeTimeFormat(value)) return { kind: "guest-relativetimeformat", options: { ...relativeTimeFormatState(value).options }, state: captureObjectState(value, encode) };
28968
29066
  if (isSandboxNumberFormat(value)) {
28969
- const { options, format: format2 } = numberFormatState(value);
28970
- return { kind: "guest-numberformat", options: { ...options }, ...format2 === void 0 ? {} : { format: encode(format2) }, state: captureObjectState(value, encode) };
29067
+ const { options, format: format3 } = numberFormatState(value);
29068
+ return { kind: "guest-numberformat", options: { ...options }, ...format3 === void 0 ? {} : { format: encode(format3) }, state: captureObjectState(value, encode) };
28971
29069
  }
28972
29070
  if (isSandboxCollator(value)) {
28973
29071
  const { options, compare } = collatorState(value);
@@ -30811,6 +30909,11 @@ function createCollectionGlobals(options) {
30811
30909
  name: "Set"
30812
30910
  });
30813
30911
  mapConstructors.add(mapConstructor);
30912
+ Object.defineProperty(materializeFunctionProperties(mapConstructor), "groupBy", {
30913
+ value: createGroupBy(options.budget, "identity"),
30914
+ writable: true,
30915
+ configurable: true
30916
+ });
30814
30917
  setConstructors.add(setConstructor);
30815
30918
  installCollectionPrototypes(options.budget, mapConstructor, setConstructor);
30816
30919
  return { Map: mapConstructor, Set: setConstructor };
@@ -33509,6 +33612,100 @@ function createListFormatConstructor(budget) {
33509
33612
  return constructor;
33510
33613
  }
33511
33614
 
33615
+ // packages/safe-js/src/interp/globals/intl-relativetimeformat.ts
33616
+ var supportedLocalesOf5 = Intl.RelativeTimeFormat.supportedLocalesOf;
33617
+ var optionTypes3 = [
33618
+ ["localeMatcher", ["lookup", "best fit"]],
33619
+ ["numberingSystem", "unicodeType"],
33620
+ ["style", ["long", "short", "narrow"]],
33621
+ ["numeric", ["always", "auto"]]
33622
+ ];
33623
+ function createRelativeTimeFormatConstructor(budget) {
33624
+ const prototype = createIntrinsicObject();
33625
+ const constructor = createSandboxClosure({
33626
+ guest: true,
33627
+ sandbox: true,
33628
+ name: "RelativeTimeFormat",
33629
+ length: 0,
33630
+ call: () => {
33631
+ throw new TypeError("Constructor RelativeTimeFormat requires 'new'.");
33632
+ },
33633
+ construct: async ([input, options], context) => {
33634
+ const target = context?.newTarget;
33635
+ const selected = target === void 0 || target === constructor ? prototype : context?.getProperty !== void 0 ? await context.getProperty(target, "prototype") : await readPropertyDescriptor(getSandboxPropertyDescriptor(target, "prototype", budget) ?? { value: void 0 }, target, context);
33636
+ let locales2 = [];
33637
+ const converted = /* @__PURE__ */ Object.create(null);
33638
+ const release = retainValues(budget, () => [selected, locales2, converted]);
33639
+ try {
33640
+ locales2 = await canonicalizeGuestLocales(input, budget, context);
33641
+ const source = intlOptionsObject(options, budget);
33642
+ for (const [key, type] of optionTypes3) {
33643
+ const raw = await readIntlProperty(source, key, budget, context);
33644
+ if (raw !== void 0) converted[key] = await convertIntlOption(raw, key, type, budget, context);
33645
+ }
33646
+ const value = createSandboxRelativeTimeFormat(locales2, converted);
33647
+ setSandboxPrototype(value, typeof selected === "object" && selected !== null ? selected : prototype, budget);
33648
+ return allocateProducedSandboxValue(value, budget);
33649
+ } finally {
33650
+ release();
33651
+ }
33652
+ }
33653
+ });
33654
+ const properties = materializeFunctionProperties(constructor);
33655
+ Object.defineProperty(properties, "prototype", { value: prototype, writable: false, configurable: false });
33656
+ Object.defineProperty(properties, "supportedLocalesOf", { value: createSandboxClosure({
33657
+ guest: true,
33658
+ sandbox: true,
33659
+ name: "supportedLocalesOf",
33660
+ length: 1,
33661
+ call: async ([input, options], context) => {
33662
+ const locales2 = await canonicalizeGuestLocales(input, budget, context);
33663
+ const release = retainValues(budget, () => [locales2]);
33664
+ try {
33665
+ const source = intlOptionsObject(options, budget);
33666
+ const raw = await readIntlProperty(source, "localeMatcher", budget, context);
33667
+ const matcher = raw === void 0 ? void 0 : await convertIntlOption(raw, "localeMatcher", ["lookup", "best fit"], budget, context);
33668
+ return allocateProducedSandboxValue(supportedLocalesOf5(locales2, { localeMatcher: matcher }), budget);
33669
+ } finally {
33670
+ release();
33671
+ }
33672
+ }
33673
+ }), writable: true, configurable: true });
33674
+ Object.defineProperties(prototype, {
33675
+ constructor: { value: constructor, writable: true, configurable: true },
33676
+ [Symbol.toStringTag]: { value: "Intl.RelativeTimeFormat", configurable: true },
33677
+ resolvedOptions: { value: createSandboxClosure({
33678
+ guest: true,
33679
+ sandbox: true,
33680
+ name: "resolvedOptions",
33681
+ length: 0,
33682
+ call: (_args, context) => allocateProducedSandboxValue({ ...relativeTimeFormatState(context?.thisValue).options }, budget)
33683
+ }), writable: true, configurable: true }
33684
+ });
33685
+ for (const method of ["format", "formatToParts"]) {
33686
+ Object.defineProperty(prototype, method, { value: createSandboxClosure({
33687
+ guest: true,
33688
+ sandbox: true,
33689
+ name: method,
33690
+ length: 2,
33691
+ call: async ([input, unit], context) => {
33692
+ const receiver = context?.thisValue;
33693
+ relativeTimeFormatState(receiver);
33694
+ const release = retainValues(budget, () => [receiver, input, unit]);
33695
+ try {
33696
+ const value = await sandboxNumber(input, budget, context);
33697
+ const convertedUnit = await sandboxString(unit, budget, context);
33698
+ budget.visitNode(convertedUnit.length);
33699
+ return allocateProducedSandboxValue(formatRelativeTime(receiver, value, convertedUnit, method === "formatToParts"), budget);
33700
+ } finally {
33701
+ release();
33702
+ }
33703
+ }
33704
+ }), writable: true, configurable: true });
33705
+ }
33706
+ return constructor;
33707
+ }
33708
+
33512
33709
  // packages/safe-js/src/interp/globals/intl.ts
33513
33710
  var supportedValuesOf = Intl.supportedValuesOf;
33514
33711
  function createIntlGlobal(budget) {
@@ -33525,10 +33722,12 @@ function createIntlGlobal(budget) {
33525
33722
  const collator = createCollatorConstructor(budget);
33526
33723
  const numberFormat = createNumberFormatConstructor(budget);
33527
33724
  const listFormat = createListFormatConstructor(budget);
33725
+ const relativeTimeFormat = createRelativeTimeFormatConstructor(budget);
33528
33726
  Object.defineProperty(intl, "Locale", { value: locale, writable: true, configurable: true });
33529
33727
  Object.defineProperty(intl, "Collator", { value: collator, writable: true, configurable: true });
33530
33728
  Object.defineProperty(intl, "NumberFormat", { value: numberFormat, writable: true, configurable: true });
33531
33729
  Object.defineProperty(intl, "ListFormat", { value: listFormat, writable: true, configurable: true });
33730
+ Object.defineProperty(intl, "RelativeTimeFormat", { value: relativeTimeFormat, writable: true, configurable: true });
33532
33731
  for (const [name, call] of Object.entries(methods2)) {
33533
33732
  const closure = createSandboxClosure({ guest: true, sandbox: true, name, length: 1, call });
33534
33733
  Object.defineProperty(intl, name, { value: closure, writable: true, configurable: true });
@@ -33652,7 +33851,7 @@ function validateGuestHeapNode(raw, heap, maxArrayLength = 4294967295) {
33652
33851
  createRawJson(node.text);
33653
33852
  return true;
33654
33853
  }
33655
- if (!["module-function", "async-generator-driver", "async-generator-handler", "async-function-driver", "async-function-handler", "thenable-state", "thenable-resolver", "construction-environment", "capability-executor", "promise-aggregate", "aggregate-entry", "aggregate-handler", "intrinsic", "bound-function", "promise-resolver", "pending-promise", "promise-reaction", "promise-adoption", "adoption-resolver", "guest-function", "guest-class", "guest-generator", "scope-frame", "guest-object", "guest-array", "guest-boxed", "guest-date", "guest-locale", "guest-listformat", "guest-numberformat", "guest-collator", "guest-regex", "guest-promise", "array-iterator", "string-iterator", "async-disposable-stack", "async-cleanup", "async-cleanup-handler", "disposable-stack", "iterator-wrapper", "iterator-helper", "guest-collection-iterator", "guest-regexp-iterator", "map", "set"].includes(String(node.kind))) return false;
33854
+ if (!["module-function", "async-generator-driver", "async-generator-handler", "async-function-driver", "async-function-handler", "thenable-state", "thenable-resolver", "construction-environment", "capability-executor", "promise-aggregate", "aggregate-entry", "aggregate-handler", "intrinsic", "bound-function", "promise-resolver", "pending-promise", "promise-reaction", "promise-adoption", "adoption-resolver", "guest-function", "guest-class", "guest-generator", "scope-frame", "guest-object", "guest-array", "guest-boxed", "guest-date", "guest-locale", "guest-listformat", "guest-relativetimeformat", "guest-numberformat", "guest-collator", "guest-regex", "guest-promise", "array-iterator", "string-iterator", "async-disposable-stack", "async-cleanup", "async-cleanup-handler", "disposable-stack", "iterator-wrapper", "iterator-helper", "guest-collection-iterator", "guest-regexp-iterator", "map", "set"].includes(String(node.kind))) return false;
33656
33855
  const reference = (value, kinds) => {
33657
33856
  const ref = record2(value);
33658
33857
  fields(ref, ["kind", "id"]);
@@ -33931,8 +34130,8 @@ function validateGuestHeapNode(raw, heap, maxArrayLength = 4294967295) {
33931
34130
  if (Object.keys(options).length !== Object.keys(restored).length || Object.keys(restored).some((key) => options[key] !== restored[key]))
33932
34131
  throw new TypeError("Invalid resolved NumberFormat options.");
33933
34132
  if (node.format !== void 0) {
33934
- const format2 = reference(node.format, ["bound-function"]);
33935
- if (reference(format2.thisValue) !== node || array(format2.args).length !== 0 || format2.name !== "" || format2.length !== 1 || reference(format2.target, ["intrinsic"]).id !== '["%NumberFormatFormat%"]')
34133
+ const format3 = reference(node.format, ["bound-function"]);
34134
+ if (reference(format3.thisValue) !== node || array(format3.args).length !== 0 || format3.name !== "" || format3.length !== 1 || reference(format3.target, ["intrinsic"]).id !== '["%NumberFormatFormat%"]')
33936
34135
  throw new TypeError("Invalid cached NumberFormat function.");
33937
34136
  }
33938
34137
  state(node.state);
@@ -33945,6 +34144,15 @@ function validateGuestHeapNode(raw, heap, maxArrayLength = 4294967295) {
33945
34144
  const restored = listFormatState(createSandboxListFormat(options.locale, options)).options;
33946
34145
  if (names.some((key) => options[key] !== restored[key])) throw new TypeError("Invalid resolved ListFormat options.");
33947
34146
  state(node.state);
34147
+ } else if (node.kind === "guest-relativetimeformat") {
34148
+ fields(node, ["kind", "options", "state"]);
34149
+ const options = record2(node.options);
34150
+ const names = ["locale", "numberingSystem", "style", "numeric"];
34151
+ fields(options, [...names]);
34152
+ if (names.some((key) => typeof options[key] !== "string")) throw new TypeError("Invalid RelativeTimeFormat option type.");
34153
+ const restored = relativeTimeFormatState(createSandboxRelativeTimeFormat(options.locale, options)).options;
34154
+ if (names.some((key) => options[key] !== restored[key])) throw new TypeError("Invalid resolved RelativeTimeFormat options.");
34155
+ state(node.state);
33948
34156
  } else if (node.kind === "guest-collator") {
33949
34157
  fields(node, ["kind", "options", "state"], ["compare"]);
33950
34158
  const options = record2(node.options);
@@ -37701,6 +37909,7 @@ function measureSandboxData(values, options = {}) {
37701
37909
  if (isSandboxDate(value)) usage += 8;
37702
37910
  if (isSandboxLocale(value)) usage += localeTag(value).length;
37703
37911
  if (isSandboxListFormat(value)) visit(listFormatState(value).options, depth + 1);
37912
+ if (isSandboxRelativeTimeFormat(value)) visit(relativeTimeFormatState(value).options, depth + 1);
37704
37913
  if (isSandboxNumberFormat(value)) {
37705
37914
  const state = numberFormatState(value);
37706
37915
  visit(state.options, depth + 1);
@@ -55686,4 +55895,4 @@ The above copyright notice and this permission notice shall be included in all c
55686
55895
  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.
55687
55896
 
55688
55897
  */
55689
- //# sourceMappingURL=chunk-GJPSM3AB.js.map
55898
+ //# sourceMappingURL=chunk-GYKATDHU.js.map