poe-code 14.0.51 → 14.0.52

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.
Files changed (42) hide show
  1. package/dist/index.js +287 -90
  2. package/dist/index.js.map +4 -4
  3. package/dist/metafile.json +1 -1
  4. package/package.json +1 -1
  5. package/packages/safe-js/dist/chunks/{chunk-7AIY5C3F.js → chunk-DVWTNFTV.js} +208 -48
  6. package/packages/safe-js/dist/chunks/chunk-DVWTNFTV.js.map +7 -0
  7. package/packages/safe-js/dist/chunks/{chunk-MQU3AETK.js → chunk-XIBH4BH2.js} +2 -2
  8. package/packages/safe-js/dist/cli.js +2 -2
  9. package/packages/safe-js/dist/core.js +1 -1
  10. package/packages/safe-js/dist/graph-depth.js +10 -4
  11. package/packages/safe-js/dist/index.js +2 -2
  12. package/packages/safe-js/dist/interp/cancel.js +3 -0
  13. package/packages/safe-js/dist/interp/collection-brands.d.ts +5 -0
  14. package/packages/safe-js/dist/interp/collection-brands.js +8 -0
  15. package/packages/safe-js/dist/interp/collection-iterator.d.ts +27 -0
  16. package/packages/safe-js/dist/interp/collection-iterator.js +61 -0
  17. package/packages/safe-js/dist/interp/globals/collections.js +1 -1
  18. package/packages/safe-js/dist/interp/globals/misc.js +3 -2
  19. package/packages/safe-js/dist/interp/globals/object-array.js +2 -2
  20. package/packages/safe-js/dist/interp/globals/object.js +3 -0
  21. package/packages/safe-js/dist/interp/interpreter.js +15 -10
  22. package/packages/safe-js/dist/interp/iteration.d.ts +2 -1
  23. package/packages/safe-js/dist/interp/iteration.js +4 -1
  24. package/packages/safe-js/dist/interp/methods/collection-iterator.d.ts +4 -0
  25. package/packages/safe-js/dist/interp/methods/collection-iterator.js +19 -0
  26. package/packages/safe-js/dist/interp/methods/map.js +3 -4
  27. package/packages/safe-js/dist/interp/methods/set.js +3 -3
  28. package/packages/safe-js/dist/interp/patterns.d.ts +2 -0
  29. package/packages/safe-js/dist/interp/patterns.js +20 -2
  30. package/packages/safe-js/dist/interp/promise.js +1 -1
  31. package/packages/safe-js/dist/interp/string-coercion.js +4 -0
  32. package/packages/safe-js/dist/interp/values.d.ts +4 -5
  33. package/packages/safe-js/dist/interp/values.js +42 -10
  34. package/packages/safe-js/dist/snapshot/replay-data.d.ts +10 -0
  35. package/packages/safe-js/dist/snapshot/replay-data.js +32 -0
  36. package/packages/safe-js/dist/snapshot/replay-inputs.js +15 -0
  37. package/packages/safe-js/dist/snapshot/restore.js +16 -0
  38. package/packages/safe-js/dist/snapshot/serialize.d.ts +10 -1
  39. package/packages/safe-js/dist/snapshot/serialize.js +25 -9
  40. package/packages/safe-js/dist/snapshot/validation.js +14 -1
  41. package/packages/safe-js/dist/chunks/chunk-7AIY5C3F.js.map +0 -7
  42. /package/packages/safe-js/dist/chunks/{chunk-MQU3AETK.js.map → chunk-XIBH4BH2.js.map} +0 -0
package/dist/index.js CHANGED
@@ -12249,7 +12249,7 @@ function matchSubsequence(query, text5) {
12249
12249
  const textCharacters = Array.from(text5);
12250
12250
  let previousStates = [];
12251
12251
  for (let queryIndex = 0; queryIndex < queryCharacters.length; queryIndex += 1) {
12252
- const states = [];
12252
+ const states2 = [];
12253
12253
  let offset = 0;
12254
12254
  for (let textIndex = 0; textIndex < textCharacters.length; textIndex += 1) {
12255
12255
  const character2 = textCharacters[textIndex];
@@ -12260,7 +12260,7 @@ function matchSubsequence(query, text5) {
12260
12260
  }
12261
12261
  const positions = character2.length === 2 ? [position, position + 1] : [position];
12262
12262
  if (queryIndex === 0) {
12263
- states[textIndex] = {
12263
+ states2[textIndex] = {
12264
12264
  score: characterScore(textCharacters, textIndex, void 0) + Math.max(0, EARLY_MATCH_BONUS - position),
12265
12265
  positions
12266
12266
  };
@@ -12275,12 +12275,12 @@ function matchSubsequence(query, text5) {
12275
12275
  score: previous.score + characterScore(textCharacters, textIndex, previousIndex),
12276
12276
  positions: [...previous.positions, ...positions]
12277
12277
  };
12278
- if (isBetterMatch(next, states[textIndex])) {
12279
- states[textIndex] = next;
12278
+ if (isBetterMatch(next, states2[textIndex])) {
12279
+ states2[textIndex] = next;
12280
12280
  }
12281
12281
  }
12282
12282
  }
12283
- previousStates = states;
12283
+ previousStates = states2;
12284
12284
  if (!previousStates.some((state) => state !== void 0)) {
12285
12285
  return void 0;
12286
12286
  }
@@ -21524,14 +21524,14 @@ function validateMachine(machine) {
21524
21524
  if (!hasOwnRecordField(machine, "states") || !isStateList(machine.states)) {
21525
21525
  throw new TypeError("State machine states must be a string array.");
21526
21526
  }
21527
- const states = new Set(machine.states);
21527
+ const states2 = new Set(machine.states);
21528
21528
  if (machine.states.some((state) => !hasVisibleName(state))) {
21529
21529
  throw new Error("State names must not be empty.");
21530
21530
  }
21531
21531
  if (!hasOwnRecordField(machine, "initial") || typeof machine.initial !== "string") {
21532
21532
  throw new TypeError("State machine initial must be a string.");
21533
21533
  }
21534
- if (!states.has(machine.initial)) {
21534
+ if (!states2.has(machine.initial)) {
21535
21535
  throw new Error(`Initial state "${machine.initial}" is not declared.`);
21536
21536
  }
21537
21537
  if (!hasOwnRecordField(machine, "events") || !isRecord9(machine.events)) {
@@ -21550,12 +21550,12 @@ function validateMachine(machine) {
21550
21550
  if (!hasOwnRecordField(event, "to") || typeof event.to !== "string") {
21551
21551
  throw new TypeError(`Event "${eventName}" target state must be a string.`);
21552
21552
  }
21553
- if (!states.has(event.to)) {
21553
+ if (!states2.has(event.to)) {
21554
21554
  throw new Error(`Event "${eventName}" references unknown target state "${event.to}".`);
21555
21555
  }
21556
21556
  if (event.from !== "*") {
21557
21557
  for (const fromState of event.from) {
21558
- if (!states.has(fromState)) {
21558
+ if (!states2.has(fromState)) {
21559
21559
  throw new Error(`Event "${eventName}" references unknown source state "${fromState}".`);
21560
21560
  }
21561
21561
  }
@@ -23953,13 +23953,13 @@ async function ghIssuesBackend(deps) {
23953
23953
  }
23954
23954
  function createProjectSession(project, field, labelPrefix) {
23955
23955
  const statusOptions = new Map(field.options.map((option) => [option.name, option.id]));
23956
- const states = field.options.map((option) => option.name);
23956
+ const states2 = field.options.map((option) => option.name);
23957
23957
  const events = Object.fromEntries(
23958
- states.map((state) => [state, Object.freeze({ from: "*", to: state })])
23958
+ states2.map((state) => [state, Object.freeze({ from: "*", to: state })])
23959
23959
  );
23960
23960
  const stateMachine = Object.freeze({
23961
- states: Object.freeze([...states]),
23962
- initial: states[0],
23961
+ states: Object.freeze([...states2]),
23962
+ initial: states2[0],
23963
23963
  events: Object.freeze(events)
23964
23964
  });
23965
23965
  return Object.freeze({
@@ -80210,8 +80210,8 @@ function hasEmptyStringValue(value) {
80210
80210
  }
80211
80211
  return Object.values(value).some((entry) => hasEmptyStringValue(entry));
80212
80212
  }
80213
- function hasOwnState(states, state) {
80214
- return Object.prototype.hasOwnProperty.call(states, state);
80213
+ function hasOwnState(states2, state) {
80214
+ return Object.prototype.hasOwnProperty.call(states2, state);
80215
80215
  }
80216
80216
  function getOwnEntry29(record2, key3) {
80217
80217
  return Object.prototype.hasOwnProperty.call(record2, key3) ? record2[key3] : void 0;
@@ -80245,7 +80245,7 @@ import path98 from "node:path";
80245
80245
  function resolveConfig2(raw, cwd) {
80246
80246
  const rawConfig = isRecord31(raw) ? raw : {};
80247
80247
  const scoped = resolveScope(maestroConfigScope, rawConfig, process.env);
80248
- const { states, stateOrder } = parseStates(getOwnEntry30(rawConfig, "states"));
80248
+ const { states: states2, stateOrder } = parseStates(getOwnEntry30(rawConfig, "states"));
80249
80249
  const polling = scoped.polling;
80250
80250
  const workspace = scoped.workspace;
80251
80251
  const agent3 = scoped.agent;
@@ -80254,9 +80254,9 @@ function resolveConfig2(raw, cwd) {
80254
80254
  }
80255
80255
  return {
80256
80256
  tasks: resolveTasks(getOwnEntry30(rawConfig, "tasks"), cwd),
80257
- states,
80258
- activeStateNames: stateOrder.filter((name) => states[name]?.prompt !== void 0),
80259
- terminalStateNames: stateOrder.filter((name) => states[name]?.terminal === true),
80257
+ states: states2,
80258
+ activeStateNames: stateOrder.filter((name) => states2[name]?.prompt !== void 0),
80259
+ terminalStateNames: stateOrder.filter((name) => states2[name]?.terminal === true),
80260
80260
  stateOrder,
80261
80261
  polling: {
80262
80262
  intervalMs: readPositiveInteger(
@@ -80289,13 +80289,13 @@ function resolveConfig2(raw, cwd) {
80289
80289
  }
80290
80290
  function parseStates(value) {
80291
80291
  validateStateDefinitions(value);
80292
- const states = /* @__PURE__ */ Object.create(null);
80292
+ const states2 = /* @__PURE__ */ Object.create(null);
80293
80293
  const stateOrder = [];
80294
80294
  const entries = value instanceof Map ? value.entries() : Object.entries(value);
80295
80295
  for (const [name, rawDefinition] of entries) {
80296
80296
  const stateName = String(name);
80297
80297
  const definition = rawDefinition;
80298
- Object.defineProperty(states, stateName, {
80298
+ Object.defineProperty(states2, stateName, {
80299
80299
  configurable: true,
80300
80300
  enumerable: true,
80301
80301
  value: parseStateDefinition(definition),
@@ -80303,7 +80303,7 @@ function parseStates(value) {
80303
80303
  });
80304
80304
  stateOrder.push(stateName);
80305
80305
  }
80306
- return { states, stateOrder };
80306
+ return { states: states2, stateOrder };
80307
80307
  }
80308
80308
  function parseStateDefinition(definition) {
80309
80309
  const state = {};
@@ -81573,8 +81573,8 @@ var init_phases = __esm({
81573
81573
  function isRunningPhase(phase) {
81574
81574
  return phase === "running-step";
81575
81575
  }
81576
- function hasOwnState2(states, state) {
81577
- return Object.prototype.hasOwnProperty.call(states, state);
81576
+ function hasOwnState2(states2, state) {
81577
+ return Object.prototype.hasOwnProperty.call(states2, state);
81578
81578
  }
81579
81579
  function isAbortError5(error3) {
81580
81580
  return error3 instanceof Error && error3.name === "AbortError";
@@ -82697,7 +82697,7 @@ function createStateStore(stateDir, fs31 = nodeFs7) {
82697
82697
  }
82698
82698
  throw error3;
82699
82699
  }
82700
- const states = [];
82700
+ const states2 = [];
82701
82701
  for (const entry of [...entries].sort()) {
82702
82702
  if (entry.startsWith(REMOVED_STATE_PREFIX)) {
82703
82703
  continue;
@@ -82716,10 +82716,10 @@ function createStateStore(stateDir, fs31 = nodeFs7) {
82716
82716
  }
82717
82717
  const state = await read(entry);
82718
82718
  if (state !== null) {
82719
- states.push(state);
82719
+ states2.push(state);
82720
82720
  }
82721
82721
  }
82722
- return states;
82722
+ return states2;
82723
82723
  }
82724
82724
  async function remove2(id) {
82725
82725
  const processDir = resolveProcessDir(stateDir, id);
@@ -102105,13 +102105,13 @@ function markApprovalsBuiltIn(group) {
102105
102105
  function isApprovalsBuiltIn(node) {
102106
102106
  return node.kind === "group" && node[approvalsGroupSymbol] === true;
102107
102107
  }
102108
- async function loadApprovals(tasks, states = []) {
102109
- if (states.length === 0) {
102108
+ async function loadApprovals(tasks, states2 = []) {
102109
+ if (states2.length === 0) {
102110
102110
  return tasks.all();
102111
102111
  }
102112
102112
  const seenIds = /* @__PURE__ */ new Set();
102113
102113
  const approvals = [];
102114
- for (const state of states) {
102114
+ for (const state of states2) {
102115
102115
  const matching = await tasks.all({
102116
102116
  state
102117
102117
  });
@@ -125759,6 +125759,84 @@ var init_arguments = __esm({
125759
125759
  }
125760
125760
  });
125761
125761
 
125762
+ // packages/safe-js/src/interp/collection-iterator.ts
125763
+ function isSandboxCollectionIterator(value) {
125764
+ return typeof value === "object" && value !== null && states.has(value);
125765
+ }
125766
+ function createSandboxCollectionIterator(collection, method) {
125767
+ return restoreSandboxCollectionIterator({ collection, collectionKind: collection.kind, method, index: 0, exhausted: false });
125768
+ }
125769
+ function restoreSandboxCollectionIterator(snapshot2, target = /* @__PURE__ */ Object.create(null)) {
125770
+ const { collection, collectionKind, method, index, exhausted } = snapshot2;
125771
+ if (collection !== void 0 && collection.kind !== collectionKind)
125772
+ throw new TypeError("Collection iterator source has the wrong brand.");
125773
+ if (!exhausted && collection === void 0)
125774
+ throw new TypeError("Live collection iterator requires its source collection.");
125775
+ const iterator = exhausted ? void 0 : nativeIterator(collection, method);
125776
+ for (let skipped = 0; skipped < index; skipped += 1) {
125777
+ if (iterator === void 0 || iterator.next().done)
125778
+ throw new TypeError("Collection iterator cursor exceeds its source.");
125779
+ }
125780
+ states.set(target, { collection: exhausted ? void 0 : collection, collectionKind, method, exhausted, iterator });
125781
+ return target;
125782
+ }
125783
+ function collectionIteratorState(value) {
125784
+ const state = states.get(value);
125785
+ if (state === void 0) throw new TypeError("Expected a collection iterator.");
125786
+ return state;
125787
+ }
125788
+ function snapshotCollectionIterator(value) {
125789
+ const state = collectionIteratorState(value);
125790
+ if (state.exhausted) return { ...state, index: 0 };
125791
+ const collection = state.collection;
125792
+ const size = collection.kind === "map" ? collection.entries.size : collection.values.size;
125793
+ let remaining = 0;
125794
+ while (!state.iterator.next().done) remaining += 1;
125795
+ const snapshot2 = { ...state, index: size - remaining };
125796
+ restoreSandboxCollectionIterator(snapshot2, value);
125797
+ return snapshot2;
125798
+ }
125799
+ function nextCollectionIterator(value, budget) {
125800
+ const state = states.get(value);
125801
+ budget?.visitNode();
125802
+ if (state.exhausted) return { value: void 0, done: true };
125803
+ const result = state.iterator.next();
125804
+ if (result.done) {
125805
+ state.exhausted = true;
125806
+ state.collection = void 0;
125807
+ state.iterator = void 0;
125808
+ return { value: void 0, done: true };
125809
+ }
125810
+ if (state.method === "entries") budget?.allocateArrayLength(2);
125811
+ return { value: result.value, done: false };
125812
+ }
125813
+ function nativeIterator(collection, method) {
125814
+ return collection.kind === "map" ? collection.entries[method]() : collection.values[method]();
125815
+ }
125816
+ var states;
125817
+ var init_collection_iterator = __esm({
125818
+ "packages/safe-js/src/interp/collection-iterator.ts"() {
125819
+ "use strict";
125820
+ states = /* @__PURE__ */ new WeakMap();
125821
+ }
125822
+ });
125823
+
125824
+ // packages/safe-js/src/interp/collection-brands.ts
125825
+ function isSandboxMap(value) {
125826
+ return typeof value === "object" && value !== null && sandboxMapBrand in value;
125827
+ }
125828
+ function isSandboxSet(value) {
125829
+ return typeof value === "object" && value !== null && sandboxSetBrand in value;
125830
+ }
125831
+ var sandboxMapBrand, sandboxSetBrand;
125832
+ var init_collection_brands = __esm({
125833
+ "packages/safe-js/src/interp/collection-brands.ts"() {
125834
+ "use strict";
125835
+ sandboxMapBrand = /* @__PURE__ */ Symbol("SandboxMap");
125836
+ sandboxSetBrand = /* @__PURE__ */ Symbol("SandboxSet");
125837
+ }
125838
+ });
125839
+
125762
125840
  // packages/safe-js/src/graph-depth.ts
125763
125841
  function assertSandboxDataDepth(depth) {
125764
125842
  if (depth > MAX_DATA_DEPTH) {
@@ -125804,16 +125882,19 @@ function graphEntries(value) {
125804
125882
  if (isSandboxArguments(value)) {
125805
125883
  return getSandboxArgumentEntries(value).map(([key3, entry]) => [`.${key3}`, entry]);
125806
125884
  }
125807
- if (value instanceof Map) {
125808
- return [...value.entries()].flatMap(([key3, entry], index) => [
125885
+ const map = isSandboxMap(value) ? value.entries : value instanceof Map ? value : void 0;
125886
+ if (map !== void 0) {
125887
+ return [...map.entries()].flatMap(([key3, entry], index) => [
125809
125888
  [`.<map>[${index}].key`, key3],
125810
125889
  [`.<map>[${index}].value`, entry]
125811
125890
  ]);
125812
125891
  }
125813
- if (value instanceof Set) {
125814
- return [...value.values()].map((entry, index) => [`.<set>[${index}]`, entry]);
125892
+ const set = isSandboxSet(value) ? value.values : value instanceof Set ? value : void 0;
125893
+ if (set !== void 0) {
125894
+ return [...set.values()].map((entry, index) => [`.<set>[${index}]`, entry]);
125815
125895
  }
125816
125896
  const entries = [];
125897
+ if (isSandboxCollectionIterator(value)) entries.push([".<collection>", collectionIteratorState(value).collection]);
125817
125898
  for (const key3 of Object.keys(value)) {
125818
125899
  const descriptor = Object.getOwnPropertyDescriptor(value, key3);
125819
125900
  if (descriptor !== void 0 && "value" in descriptor)
@@ -125828,6 +125909,8 @@ var init_graph_depth = __esm({
125828
125909
  init_shape();
125829
125910
  init_budget2();
125830
125911
  init_arguments();
125912
+ init_collection_iterator();
125913
+ init_collection_brands();
125831
125914
  MAX_DATA_DEPTH = 1024;
125832
125915
  SnapshotBudgetError = class extends Error {
125833
125916
  code = "budgetExceeded";
@@ -127159,6 +127242,14 @@ function encodeReplayData(value, options = {}) {
127159
127242
  };
127160
127243
  }
127161
127244
  nodes[id] = { ...storage2, properties, extensible: Object.isExtensible(entry) };
127245
+ } else if (isSandboxCollectionIterator(entry)) {
127246
+ const snapshot2 = snapshotCollectionIterator(entry);
127247
+ const properties = /* @__PURE__ */ Object.create(null);
127248
+ for (const [key3, descriptor] of Object.entries(Object.getOwnPropertyDescriptors(entry))) {
127249
+ if (!("value" in descriptor)) throw new TypeError(`Cannot record replay data accessor '${key3}'.`);
127250
+ properties[key3] = { value: child(descriptor.value, JSON.stringify(["property", key3])), configurable: descriptor.configurable === true, enumerable: descriptor.enumerable === true, writable: descriptor.writable === true };
127251
+ }
127252
+ nodes[id] = { kind: "collection-iterator", collectionKind: snapshot2.collectionKind, method: snapshot2.method, collection: child(snapshot2.collection, "<collection>"), index: snapshot2.index, exhausted: snapshot2.exhausted, properties, extensible: Object.isExtensible(entry) };
127162
127253
  } else if (isSandboxMap(entry)) {
127163
127254
  nodes[id] = {
127164
127255
  kind: "map",
@@ -127217,6 +127308,7 @@ function decodeReplayData(input, options = {}, parent) {
127217
127308
  const graph = record(input);
127218
127309
  const nodes = list(own(graph, "nodes"));
127219
127310
  const restored = /* @__PURE__ */ new Map();
127311
+ const initializeIterators = [];
127220
127312
  const decode = (entry, depth = 0) => {
127221
127313
  if (depth > MAX_DATA_DEPTH) throw new TypeError("Replay data exceeds the nesting limit.");
127222
127314
  if (entry === null || typeof entry === "boolean" || typeof entry === "string") return entry;
@@ -127309,6 +127401,23 @@ function decodeReplayData(input, options = {}, parent) {
127309
127401
  if (!node.extensible) Object.preventExtensions(result3);
127310
127402
  return result3;
127311
127403
  }
127404
+ if (kind === "collection-iterator") {
127405
+ const collectionKind = own(node, "collectionKind");
127406
+ const method = own(node, "method");
127407
+ const index = own(node, "index");
127408
+ const exhausted = own(node, "exhausted");
127409
+ if (collectionKind !== "map" && collectionKind !== "set" || method !== "keys" && method !== "values" && method !== "entries" || typeof index !== "number" || !Number.isSafeInteger(index) || index < 0 || typeof exhausted !== "boolean" || typeof node.extensible !== "boolean") throw new TypeError("Invalid replay collection iterator.");
127410
+ const result3 = restoreSandboxCollectionIterator({ collection: void 0, collectionKind, method, index: 0, exhausted: true });
127411
+ restored.set(id, result3);
127412
+ const collection = child(own(node, "collection"));
127413
+ if (collection !== void 0 && !isSandboxMap(collection) && !isSandboxSet(collection)) throw new TypeError("Invalid replay collection iterator source.");
127414
+ initializeIterators.push(() => {
127415
+ restoreSandboxCollectionIterator({ collection, collectionKind, method, index, exhausted }, result3);
127416
+ });
127417
+ defineProperties(result3, record(own(node, "properties")), child);
127418
+ if (!node.extensible) Object.preventExtensions(result3);
127419
+ return result3;
127420
+ }
127312
127421
  if (kind === "map") {
127313
127422
  const result3 = createSandboxMap();
127314
127423
  restored.set(id, result3);
@@ -127365,6 +127474,7 @@ function decodeReplayData(input, options = {}, parent) {
127365
127474
  return result2;
127366
127475
  };
127367
127476
  const result = decode(own(graph, "root"));
127477
+ for (const initialize of initializeIterators) initialize();
127368
127478
  if (parent !== void 0) compilation.forward(compilation.tickets, parent);
127369
127479
  return result;
127370
127480
  } finally {
@@ -127407,6 +127517,7 @@ var init_replay_data = __esm({
127407
127517
  "packages/safe-js/src/snapshot/replay-data.ts"() {
127408
127518
  "use strict";
127409
127519
  init_graph_depth();
127520
+ init_collection_iterator();
127410
127521
  init_object_model();
127411
127522
  init_compile_guard();
127412
127523
  init_float32();
@@ -128492,7 +128603,7 @@ async function objectToPrimitive(value, budget, context, joining, hint) {
128492
128603
  }
128493
128604
  }
128494
128605
  function conversionHook(value, name, budget) {
128495
- const implicitBuiltin = !hasExplicitSandboxPrototype(value) && (Array.isArray(value) || isSandboxDate(value) || isFloat32Array(value) || sandboxErrorTypes.has(value) || isSandboxClosure(value) || isSandboxMap(value) || isSandboxSet(value) || isSandboxPromise(value) || isSandboxRegex(value) || isSandboxGenerator(value) || isGuestHostObject(value));
128606
+ const implicitBuiltin = !hasExplicitSandboxPrototype(value) && (Array.isArray(value) || isSandboxDate(value) || isFloat32Array(value) || sandboxErrorTypes.has(value) || isSandboxClosure(value) || isSandboxMap(value) || isSandboxSet(value) || isSandboxCollectionIterator(value) || isSandboxPromise(value) || isSandboxRegex(value) || isSandboxGenerator(value) || isGuestHostObject(value));
128496
128607
  let current = value;
128497
128608
  let depth = 0;
128498
128609
  while (current !== null) {
@@ -128518,6 +128629,7 @@ function conversionHook(value, name, budget) {
128518
128629
  async function defaultToString(value, budget, context, joining) {
128519
128630
  if (isSandboxMap(value)) return "[object Map]";
128520
128631
  if (isSandboxSet(value)) return "[object Set]";
128632
+ if (isSandboxCollectionIterator(value)) return collectionIteratorState(value).collectionKind === "map" ? "[object Map Iterator]" : "[object Set Iterator]";
128521
128633
  if (isSandboxGenerator(value)) return "[object Generator]";
128522
128634
  if (isSandboxRegex(value)) {
128523
128635
  return budget.allocateString(
@@ -128574,6 +128686,7 @@ var init_string_coercion = __esm({
128574
128686
  init_float32();
128575
128687
  init_graph_depth();
128576
128688
  init_host_capabilities();
128689
+ init_collection_iterator();
128577
128690
  init_object_model();
128578
128691
  init_regex();
128579
128692
  init_values();
@@ -129106,7 +129219,8 @@ var init_running_state = __esm({
129106
129219
  });
129107
129220
 
129108
129221
  // packages/safe-js/src/interp/iteration.ts
129109
- function getSandboxIterator(value) {
129222
+ function getSandboxIterator(value, budget) {
129223
+ if (isSandboxCollectionIterator(value)) return { next: () => nextCollectionIterator(value, budget), snapshotIndex: () => 0 };
129110
129224
  if (isGuestHostObject(value)) return getHostObjectIterator(value);
129111
129225
  if (isFloat32Array(value)) {
129112
129226
  return syncIterator(Float32Array.prototype.values.call(value));
@@ -129210,6 +129324,7 @@ var init_iteration = __esm({
129210
129324
  init_running_state();
129211
129325
  init_float32();
129212
129326
  init_host_capabilities();
129327
+ init_collection_iterator();
129213
129328
  }
129214
129329
  });
129215
129330
 
@@ -129684,7 +129799,7 @@ async function settleIterable(iterable, method, budget, constructor, context) {
129684
129799
  const promiseResolve = readPromiseReceiverProperty(constructor, "resolve", prototype);
129685
129800
  if (!isSandboxClosure(promiseResolve))
129686
129801
  throw new TypeError("Promise constructor requires a callable resolve.");
129687
- const iterator = getSandboxIterator(iterable);
129802
+ const iterator = getSandboxIterator(iterable, budget);
129688
129803
  if (iterator === void 0) throw new TypeError("Promise helpers require an iterable.");
129689
129804
  let index = 0;
129690
129805
  while (true) {
@@ -130139,6 +130254,7 @@ function registerCancelablePromises(value, signal) {
130139
130254
  } else if (isSandboxSet(current)) {
130140
130255
  for (const entry of current.values) pending.push(entry);
130141
130256
  } else {
130257
+ if (isSandboxCollectionIterator(current)) pending.push(collectionIteratorState(current).collection);
130142
130258
  for (const descriptor of Object.values(Object.getOwnPropertyDescriptors(current))) {
130143
130259
  if ("value" in descriptor) pending.push(descriptor.value);
130144
130260
  }
@@ -130240,6 +130356,7 @@ var activeCancellation, sandboxPromises, cancelableOutcomes;
130240
130356
  var init_cancel2 = __esm({
130241
130357
  "packages/safe-js/src/interp/cancel.ts"() {
130242
130358
  "use strict";
130359
+ init_collection_iterator();
130243
130360
  init_object_model();
130244
130361
  init_values();
130245
130362
  init_promise_tracker();
@@ -130418,15 +130535,9 @@ function getSandboxRegexPattern(regex) {
130418
130535
  function isSandboxClosure(value) {
130419
130536
  return typeof value === "object" && value !== null && sandboxClosureBrand in value;
130420
130537
  }
130421
- function isSandboxMap(value) {
130422
- return typeof value === "object" && value !== null && sandboxMapBrand in value;
130423
- }
130424
130538
  function isSandboxPromise(value) {
130425
130539
  return typeof value === "object" && value !== null && sandboxPromiseBrand in value;
130426
130540
  }
130427
- function isSandboxSet(value) {
130428
- return typeof value === "object" && value !== null && sandboxSetBrand in value;
130429
- }
130430
130541
  function isSandboxGenerator(value) {
130431
130542
  return typeof value === "object" && value !== null && sandboxGeneratorBrand in value;
130432
130543
  }
@@ -130439,14 +130550,18 @@ function deepCopyToSandbox(value) {
130439
130550
  });
130440
130551
  }
130441
130552
  function cloneSandboxValue(value) {
130442
- return copyToSandbox(
130553
+ const initializeIterators = [];
130554
+ const copy = copyToSandbox(
130443
130555
  value,
130444
130556
  {
130445
- seen: /* @__PURE__ */ new WeakMap()
130557
+ seen: /* @__PURE__ */ new WeakMap(),
130558
+ initializeIterators
130446
130559
  },
130447
130560
  "<root>",
130448
130561
  true
130449
130562
  );
130563
+ for (const initialize of initializeIterators) initialize();
130564
+ return copy;
130450
130565
  }
130451
130566
  function allocateProducedSandboxValue(value, budget) {
130452
130567
  allocateSandboxValue2(value, budget, /* @__PURE__ */ new WeakSet());
@@ -130511,6 +130626,14 @@ function measureSandboxData(values, options = {}) {
130511
130626
  }
130512
130627
  return;
130513
130628
  }
130629
+ if (isSandboxCollectionIterator(value)) {
130630
+ visit(collectionIteratorState(value).collection, depth + 1);
130631
+ for (const [key3, descriptor] of Object.entries(Object.getOwnPropertyDescriptors(value))) {
130632
+ usage += key3.length + 1;
130633
+ if ("value" in descriptor) visit(descriptor.value, depth + 1);
130634
+ }
130635
+ return;
130636
+ }
130514
130637
  if (isSandboxSet(value)) {
130515
130638
  usage += value.values.size;
130516
130639
  for (const entry of value.values) visit(entry, depth + 1);
@@ -130619,6 +130742,24 @@ function copyToSandbox(value, state, path193 = "<root>", cloneSandboxCollections
130619
130742
  if (isSandboxClosure(value) || isSandboxGenerator(value) || isSandboxRegex(value) || isSandboxPromise(value)) {
130620
130743
  return value;
130621
130744
  }
130745
+ if (isSandboxCollectionIterator(value)) {
130746
+ if (hasGuestObjectState(value)) throw new TypeError("Guest prototype links and custom descriptors cannot be copied as data.");
130747
+ if (!cloneSandboxCollections) return value;
130748
+ const existing = state.seen.get(value);
130749
+ if (existing !== void 0) return existing;
130750
+ const snapshot2 = snapshotCollectionIterator(value);
130751
+ const copy = restoreSandboxCollectionIterator({ ...snapshot2, collection: void 0, index: 0, exhausted: true });
130752
+ state.seen.set(value, copy);
130753
+ const collection = copyToSandbox(snapshot2.collection, state, `${path193}.<collection>`, true, depth + 1);
130754
+ if (collection !== void 0 && !isSandboxMap(collection) && !isSandboxSet(collection)) throw new TypeError("Invalid cloned collection iterator source.");
130755
+ state.initializeIterators.push(() => {
130756
+ restoreSandboxCollectionIterator({ ...snapshot2, collection }, copy);
130757
+ });
130758
+ for (const entry of getEnumerableObjectEntries(value, path193)) {
130759
+ defineOwnDataProperty(copy, entry.key, copyToSandbox(entry.value, state, joinPath(path193, entry.key), true, depth + 1));
130760
+ }
130761
+ return copy;
130762
+ }
130622
130763
  if (typeof value === "object" && value !== null && hasGuestObjectState(value)) {
130623
130764
  throw new TypeError("Guest prototype links and custom descriptors cannot be copied as data.");
130624
130765
  }
@@ -130874,6 +131015,9 @@ function copyFromSandbox(value, state, path193 = "<root>", options, depth = 0) {
130874
131015
  if (isSandboxGenerator(value)) {
130875
131016
  throw new TypeError("Sandbox generators cannot cross into host values.");
130876
131017
  }
131018
+ if (isSandboxCollectionIterator(value)) {
131019
+ throw new TypeError("Sandbox collection iterators cannot cross into host values.");
131020
+ }
130877
131021
  if (isSandboxRegex(value)) {
130878
131022
  throw new TypeError("Invalid sandbox RegExp brand.");
130879
131023
  }
@@ -131099,11 +131243,13 @@ function joinPath(path193, key3) {
131099
131243
  function joinArrayPath(path193, key3) {
131100
131244
  return isArrayIndexKey(key3) ? `${path193}[${key3}]` : joinPath(path193, key3);
131101
131245
  }
131102
- var sandboxClosureBrand, sandboxGeneratorBrand, sandboxMapBrand, sandboxPromiseBrand, sandboxRegexBrand, sandboxRegexPattern, sandboxSetBrand, sandboxRetainedValues;
131246
+ var sandboxClosureBrand, sandboxGeneratorBrand, sandboxPromiseBrand, sandboxRegexBrand, sandboxRegexPattern, sandboxRetainedValues;
131103
131247
  var init_values = __esm({
131104
131248
  "packages/safe-js/src/interp/values.ts"() {
131105
131249
  "use strict";
131106
131250
  init_otel2();
131251
+ init_collection_brands();
131252
+ init_collection_iterator();
131107
131253
  init_date();
131108
131254
  init_host_capabilities();
131109
131255
  init_compile_guard();
@@ -131118,13 +131264,12 @@ var init_values = __esm({
131118
131264
  init_object_model();
131119
131265
  init_arguments();
131120
131266
  init_arguments();
131267
+ init_collection_brands();
131121
131268
  sandboxClosureBrand = /* @__PURE__ */ Symbol("SandboxClosure");
131122
131269
  sandboxGeneratorBrand = /* @__PURE__ */ Symbol("SandboxGenerator");
131123
- sandboxMapBrand = /* @__PURE__ */ Symbol("SandboxMap");
131124
131270
  sandboxPromiseBrand = /* @__PURE__ */ Symbol("SandboxPromise");
131125
131271
  sandboxRegexBrand = /* @__PURE__ */ Symbol("SandboxRegex");
131126
131272
  sandboxRegexPattern = /* @__PURE__ */ Symbol("SandboxRegexPattern");
131127
- sandboxSetBrand = /* @__PURE__ */ Symbol("SandboxSet");
131128
131273
  sandboxRetainedValues = /* @__PURE__ */ Symbol("SandboxRetainedValues");
131129
131274
  }
131130
131275
  });
@@ -131714,6 +131859,7 @@ function validateTaggedValue(record2, path193, state) {
131714
131859
  case "object":
131715
131860
  case "map":
131716
131861
  case "set":
131862
+ case "collection-iterator":
131717
131863
  return;
131718
131864
  }
131719
131865
  }
@@ -143707,13 +143853,27 @@ async function bindAssignmentPattern2(pattern, value, target, scope, context) {
143707
143853
  return bindPattern2(pattern.left, defaultValue.value, target, scope, context);
143708
143854
  }
143709
143855
  async function bindArrayPattern2(pattern, value, target, scope, context) {
143710
- const values = getArrayPatternValues(value);
143856
+ const iterator = isSandboxCollectionIterator(value) ? value : void 0;
143857
+ const values = iterator === void 0 ? getArrayPatternValues(value) : void 0;
143711
143858
  for (let index = 0; index < pattern.elements.length; index += 1) {
143712
143859
  const element = pattern.elements[index];
143713
143860
  if (element === null) {
143861
+ if (iterator !== void 0) nextCollectionIterator(iterator, context.budget);
143714
143862
  continue;
143715
143863
  }
143716
- const elementValue = element.type === "RestElement" ? values.slice(index) : values[index];
143864
+ let elementValue;
143865
+ if (iterator === void 0) {
143866
+ elementValue = element.type === "RestElement" ? values.slice(index) : values[index];
143867
+ } else if (element.type === "RestElement") {
143868
+ const rest = [];
143869
+ for (let entry = nextCollectionIterator(iterator, context.budget); !entry.done; entry = nextCollectionIterator(iterator, context.budget)) {
143870
+ context.budget?.allocateArrayLength(rest.length + 1);
143871
+ rest.push(entry.value);
143872
+ }
143873
+ elementValue = rest;
143874
+ } else {
143875
+ elementValue = nextCollectionIterator(iterator, context.budget).value;
143876
+ }
143717
143877
  const binding = await bindPattern2(element, elementValue, target, scope, context);
143718
143878
  if (!binding.ok) {
143719
143879
  return binding;
@@ -143845,6 +144005,7 @@ function defineProperty(target, key3, value) {
143845
144005
  var init_patterns = __esm({
143846
144006
  "packages/safe-js/src/interp/patterns.ts"() {
143847
144007
  "use strict";
144008
+ init_collection_iterator();
143848
144009
  init_values();
143849
144010
  }
143850
144011
  });
@@ -144771,14 +144932,9 @@ async function callMapMethod(target, methodName, args, options, stack = []) {
144771
144932
  return void 0;
144772
144933
  }
144773
144934
  case "keys":
144774
- return allocateProducedSandboxValue([...target.entries.keys()], options.budget);
144775
144935
  case "values":
144776
- return allocateProducedSandboxValue([...target.entries.values()], options.budget);
144777
144936
  case "entries":
144778
- return allocateProducedSandboxValue(
144779
- [...target.entries].map(([key3, value]) => [key3, value]),
144780
- options.budget
144781
- );
144937
+ return createSandboxCollectionIterator(target, methodName);
144782
144938
  }
144783
144939
  }
144784
144940
  var mapMethodNames;
@@ -144788,6 +144944,7 @@ var init_map = __esm({
144788
144944
  init_values();
144789
144945
  init_running_state();
144790
144946
  init_collection_callback();
144947
+ init_collection_iterator();
144791
144948
  mapMethodNames = /* @__PURE__ */ new Set([
144792
144949
  "get",
144793
144950
  "set",
@@ -145409,12 +145566,8 @@ async function callSetMethod(target, methodName, args, options, stack = []) {
145409
145566
  }
145410
145567
  case "keys":
145411
145568
  case "values":
145412
- return allocateProducedSandboxValue([...target.values], options.budget);
145413
145569
  case "entries":
145414
- return allocateProducedSandboxValue(
145415
- [...target.values].map((value) => [value, value]),
145416
- options.budget
145417
- );
145570
+ return createSandboxCollectionIterator(target, methodName);
145418
145571
  }
145419
145572
  }
145420
145573
  var setMethodNames;
@@ -145424,6 +145577,7 @@ var init_set = __esm({
145424
145577
  init_values();
145425
145578
  init_running_state();
145426
145579
  init_collection_callback();
145580
+ init_collection_iterator();
145427
145581
  setMethodNames = /* @__PURE__ */ new Set([
145428
145582
  "add",
145429
145583
  "has",
@@ -145616,6 +145770,7 @@ function typeTag(value) {
145616
145770
  if (isSandboxRegex(value)) return "RegExp";
145617
145771
  if (isSandboxMap(value)) return "Map";
145618
145772
  if (isSandboxSet(value)) return "Set";
145773
+ if (isSandboxCollectionIterator(value)) return collectionIteratorState(value).collectionKind === "map" ? "Map Iterator" : "Set Iterator";
145619
145774
  if (isSandboxPromise(value)) return "Promise";
145620
145775
  if (isSandboxGenerator(value)) return "Generator";
145621
145776
  if (isFloat32Array(value)) return "Float32Array";
@@ -145629,6 +145784,7 @@ var init_object2 = __esm({
145629
145784
  init_exceptions();
145630
145785
  init_float32();
145631
145786
  init_host_capabilities();
145787
+ init_collection_iterator();
145632
145788
  init_object_model();
145633
145789
  init_string_coercion();
145634
145790
  init_values();
@@ -145721,7 +145877,7 @@ function isSandboxSetConstructor(value) {
145721
145877
  function populateCollection(source, collection, { name, budget, context, append, retainedValues }) {
145722
145878
  budget.allocateCollectionEntries(0);
145723
145879
  if (source === void 0 || source === null) return collection;
145724
- const iterator = getSandboxIterator(source);
145880
+ const iterator = getSandboxIterator(source, budget);
145725
145881
  if (iterator === void 0) throw new TypeError(`${name} constructor requires an iterable.`);
145726
145882
  let entry;
145727
145883
  let failure;
@@ -145796,6 +145952,30 @@ var init_collections = __esm({
145796
145952
  }
145797
145953
  });
145798
145954
 
145955
+ // packages/safe-js/src/interp/methods/collection-iterator.ts
145956
+ function getCollectionIteratorMember(target, property, budget) {
145957
+ if (Object.hasOwn(target, property)) return target[property];
145958
+ if (property !== "next") return void 0;
145959
+ const { collectionKind } = collectionIteratorState(target);
145960
+ return createSandboxClosure({
145961
+ sandbox: true,
145962
+ name: "next",
145963
+ call: (_args, context) => {
145964
+ const receiver = context?.thisValue;
145965
+ if (!isSandboxCollectionIterator(receiver) || collectionIteratorState(receiver).collectionKind !== collectionKind)
145966
+ throw new TypeError("Iterator next requires a matching collection iterator receiver.");
145967
+ return nextCollectionIterator(receiver, budget);
145968
+ }
145969
+ });
145970
+ }
145971
+ var init_collection_iterator2 = __esm({
145972
+ "packages/safe-js/src/interp/methods/collection-iterator.ts"() {
145973
+ "use strict";
145974
+ init_collection_iterator();
145975
+ init_values();
145976
+ }
145977
+ });
145978
+
145799
145979
  // packages/safe-js/src/interp/globals/float32array.ts
145800
145980
  function createFloat32ArrayGlobal(budget) {
145801
145981
  const constructor = createSandboxClosure({
@@ -146954,6 +147134,9 @@ function isRestorableBindingValue(value, seen = /* @__PURE__ */ new WeakSet()) {
146954
147134
  }
146955
147135
  if (seen.has(value)) return true;
146956
147136
  seen.add(value);
147137
+ if (isSandboxCollectionIterator(value)) {
147138
+ return isRestorableBindingValue(collectionIteratorState(value).collection, seen);
147139
+ }
146957
147140
  if (isSandboxMap(value)) {
146958
147141
  for (const [key3, entry] of value.entries) {
146959
147142
  if (!isRestorableBindingValue(key3, seen) || !isRestorableBindingValue(entry, seen)) {
@@ -147196,7 +147379,7 @@ async function evaluateForOfStatement(node, context) {
147196
147379
  const restored = context.scope.consumeRestoredBinding(restoredIteration.values[0]);
147197
147380
  if (restored.found && Array.isArray(restored.value)) {
147198
147381
  restoredEntry = { done: false, value: restored.value[1] };
147199
- if (isSandboxMap(restored.value[0]) || isSandboxSet(restored.value[0])) {
147382
+ if (isSandboxMap(restored.value[0]) || isSandboxSet(restored.value[0]) || isSandboxCollectionIterator(restored.value[0])) {
147200
147383
  return evaluateForOfIterator(node, restored.value[0], context, restoredEntry);
147201
147384
  }
147202
147385
  }
@@ -147244,7 +147427,7 @@ async function evaluateForOfStatement(node, context) {
147244
147427
  };
147245
147428
  }
147246
147429
  async function evaluateForOfIterator(node, value, context, restoredEntry) {
147247
- const iterator = getSandboxIterator(value);
147430
+ const iterator = getSandboxIterator(value, context.budget);
147248
147431
  if (iterator === void 0) {
147249
147432
  throw new TypeError(`${String(value)} is not a supported iterable`);
147250
147433
  }
@@ -147543,7 +147726,7 @@ function createLoopIterationContext(context, scope) {
147543
147726
  if (context.activeLoopIterations.size === 0) return snapshot2;
147544
147727
  snapshot2.loopIterations = {};
147545
147728
  for (const [nodeId, iteration] of context.activeLoopIterations) {
147546
- if (typeof iteration !== "number" && (isSandboxMap(iteration.values[0]) || isSandboxSet(iteration.values[0]))) {
147729
+ if (typeof iteration !== "number" && (isSandboxMap(iteration.values[0]) || isSandboxSet(iteration.values[0]) || isSandboxCollectionIterator(iteration.values[0]))) {
147547
147730
  const bindingName = `#for-of:${nodeId}`;
147548
147731
  snapshot2.bindings[bindingName] = iteration.values;
147549
147732
  snapshot2.loopIterations[nodeId] = { index: iteration.index, values: [bindingName] };
@@ -147670,7 +147853,7 @@ async function evaluateYieldDelegate(node, context) {
147670
147853
  if (argument.kind !== "normal") {
147671
147854
  return argument;
147672
147855
  }
147673
- const iterator = getSandboxIterator(argument.value);
147856
+ const iterator = getSandboxIterator(argument.value, context.budget);
147674
147857
  if (iterator === void 0) {
147675
147858
  throw new TypeError(`${String(argument.value)} is not a supported iterable`);
147676
147859
  }
@@ -147880,6 +148063,7 @@ function getPropertyValue(target, property, context) {
147880
148063
  if (isSandboxDate(target)) return getDateMember(property, context.budget, context.compilation?.owner);
147881
148064
  if (isSandboxMap(target)) return getMapMember(target, property, createMapMethodOptions(context));
147882
148065
  if (isSandboxSet(target)) return getSetMember(target, property, createSetMethodOptions(context));
148066
+ if (isSandboxCollectionIterator(target)) return getCollectionIteratorMember(target, property, context.budget);
147883
148067
  if (isSandboxGenerator(target)) return getGeneratorMember(target, property, context.budget);
147884
148068
  if (isSandboxClosure(target)) return getClosureMemberValue(target, property, context);
147885
148069
  if (isSandboxPromise(target)) return getPromiseMember(property, context.budget);
@@ -147892,6 +148076,7 @@ function getPropertyValue(target, property, context) {
147892
148076
  function createPatternContext(context, scope = context.scope, evaluate = evaluateNode2) {
147893
148077
  const evaluationContext = { ...context, scope };
147894
148078
  return {
148079
+ budget: context.budget,
147895
148080
  evaluate: (node) => evaluate(node, evaluationContext),
147896
148081
  toPropertyKey: (value) => toPropertyKey(value, context.budget, createCoercionContext(evaluationContext)),
147897
148082
  getProperty: (value, key3) => getPropertyValue(value, key3, evaluationContext),
@@ -148399,7 +148584,7 @@ function hasSandboxProperty(value, key3, context) {
148399
148584
  while (typeof current === "object" && current !== null) {
148400
148585
  if (isGuestHostObject(current)) return hasHostObjectMember(current, key3);
148401
148586
  if (hasOwnSandboxProperty(current, key3, false)) return true;
148402
- if (Array.isArray(current) || !isPlainSandboxObject(current) || isSandboxDate(current) || isFloat32Array(current) || isSandboxGenerator(current)) {
148587
+ if (Array.isArray(current) || !isPlainSandboxObject(current) || isSandboxDate(current) || isFloat32Array(current) || isSandboxGenerator(current) || isSandboxCollectionIterator(current)) {
148403
148588
  return getPropertyValue(current, key3, context) !== void 0;
148404
148589
  }
148405
148590
  current = getSandboxPrototype(current, context.budget);
@@ -148609,7 +148794,7 @@ function getMemberValue(target, property, context) {
148609
148794
  while (typeof current === "object" && current !== null) {
148610
148795
  if (isSandboxClosure(current)) return getClosureMemberValue(current, property, context);
148611
148796
  if (Array.isArray(current)) return getArrayMemberValue(current, property, context);
148612
- if (!isPlainSandboxObject(current) || isSandboxGenerator(current) || isFloat32Array(current)) {
148797
+ if (!isPlainSandboxObject(current) || isSandboxGenerator(current) || isSandboxCollectionIterator(current) || isFloat32Array(current)) {
148613
148798
  return getPropertyValue(current, property, context);
148614
148799
  }
148615
148800
  if (Object.hasOwn(current, String(property))) return current[String(property)];
@@ -148824,7 +149009,7 @@ async function evaluateSpreadElement(node, context) {
148824
149009
  result: value
148825
149010
  };
148826
149011
  }
148827
- const iterator = getSpreadIterator(value.value);
149012
+ const iterator = getSandboxIterator(value.value, context.budget);
148828
149013
  if (iterator === void 0) {
148829
149014
  throw new TypeError("Spread arguments must evaluate to an iterable.");
148830
149015
  }
@@ -148894,9 +149079,6 @@ function describeObjectSpreadValue(value) {
148894
149079
  }
148895
149080
  return typeof value;
148896
149081
  }
148897
- function getSpreadIterator(value) {
148898
- return getSandboxIterator(value);
148899
- }
148900
149082
  async function closeIterator(iterator) {
148901
149083
  if (iterator.generator && iterator.return !== void 0) {
148902
149084
  await iterator.return();
@@ -148960,6 +149142,8 @@ var init_interpreter = __esm({
148960
149142
  init_error();
148961
149143
  init_object2();
148962
149144
  init_collections();
149145
+ init_collection_iterator();
149146
+ init_collection_iterator2();
148963
149147
  init_float32array2();
148964
149148
  init_float32();
148965
149149
  init_date();
@@ -150815,8 +150999,8 @@ function structuredCloneSandboxValue(value, budget) {
150815
150999
  return allocateProducedSandboxValue(clone, budget);
150816
151000
  }
150817
151001
  function assertStructuredCloneable(value, seen) {
150818
- if (isSandboxClosure(value) || isSandboxPromise(value)) {
150819
- throw new TypeError("structuredClone() cannot clone closures or promises.");
151002
+ if (isSandboxClosure(value) || isSandboxPromise(value) || isSandboxCollectionIterator(value)) {
151003
+ throw new TypeError("structuredClone() cannot clone closures, promises, or collection iterators.");
150820
151004
  }
150821
151005
  if (typeof value !== "object" || value === null || seen.has(value)) {
150822
151006
  return;
@@ -150842,6 +151026,7 @@ function assertStructuredCloneable(value, seen) {
150842
151026
  var init_misc = __esm({
150843
151027
  "packages/safe-js/src/interp/globals/misc.ts"() {
150844
151028
  "use strict";
151029
+ init_collection_iterator();
150845
151030
  init_graph_depth();
150846
151031
  init_values();
150847
151032
  }
@@ -150951,7 +151136,7 @@ function createObjectArrayGlobals(options) {
150951
151136
  fromEntries: createSandboxClosure({
150952
151137
  sandbox: true,
150953
151138
  call: ([value], context) => {
150954
- const iterator = getSandboxIterator(value);
151139
+ const iterator = getSandboxIterator(value, options.budget);
150955
151140
  if (iterator === void 0) {
150956
151141
  throw new TypeError("Object.fromEntries requires an iterable.");
150957
151142
  }
@@ -151214,7 +151399,7 @@ async function arrayFromSandboxValues(args, budget, context) {
151214
151399
  throw new TypeError("Array.from requires a non-null input.");
151215
151400
  }
151216
151401
  const read = (property) => context?.getProperty !== void 0 ? context.getProperty(items, property) : getSandboxDataProperty(items, property, budget);
151217
- const iterator = getSandboxIterator(items);
151402
+ const iterator = getSandboxIterator(items, budget);
151218
151403
  const constructor = context?.thisValue;
151219
151404
  let result;
151220
151405
  let currentValue;
@@ -152823,6 +153008,7 @@ var init_serialize = __esm({
152823
153008
  "packages/safe-js/src/snapshot/serialize.ts"() {
152824
153009
  "use strict";
152825
153010
  init_hash();
153011
+ init_collection_iterator();
152826
153012
  init_object_model();
152827
153013
  init_shape();
152828
153014
  init_graph_depth();
@@ -152885,6 +153071,16 @@ function prepareReplayInputs(current, saved, preparePromise, onCapabilityRestore
152885
153071
  throw new TypeError("Invalid replay input capability path.");
152886
153072
  let value = current;
152887
153073
  for (const key3 of path193) {
153074
+ if (isSandboxCollectionIterator(value)) {
153075
+ if (key3 === "<collection>") value = collectionIteratorState(value).collection;
153076
+ else {
153077
+ const property = JSON.parse(key3);
153078
+ if (!Array.isArray(property) || property.length !== 2 || property[0] !== "property" || typeof property[1] !== "string") throw new TypeError("Invalid replay input iterator capability path.");
153079
+ const descriptor2 = Object.getOwnPropertyDescriptor(value, property[1]);
153080
+ value = descriptor2 !== void 0 && "value" in descriptor2 ? descriptor2.value : void 0;
153081
+ }
153082
+ continue;
153083
+ }
152888
153084
  if (isSandboxMap(value)) {
152889
153085
  const [kind, ordinal] = key3.split(":");
152890
153086
  const index = Number(ordinal);
@@ -152945,11 +153141,11 @@ function prepareReplayInputs(current, saved, preparePromise, onCapabilityRestore
152945
153141
  return { values: restored, snapshot: structuredClone(saved) };
152946
153142
  }
152947
153143
  function assertReplayInputShape(restored) {
152948
- if (restored === null || typeof restored !== "object" || Array.isArray(restored) || isSandboxClosure(restored) || isSandboxPromise(restored) || isSandboxMap(restored) || isSandboxSet(restored))
153144
+ if (restored === null || typeof restored !== "object" || Array.isArray(restored) || isSandboxClosure(restored) || isSandboxPromise(restored) || isSandboxCollectionIterator(restored) || isSandboxMap(restored) || isSandboxSet(restored))
152949
153145
  throw new TypeError("Invalid replay inputs.");
152950
153146
  const values = restored;
152951
153147
  for (const key3 of ["bindings", "imports"]) {
152952
- if (values[key3] === null || typeof values[key3] !== "object" || Array.isArray(values[key3]) || isSandboxClosure(values[key3]) || isSandboxPromise(values[key3]) || isSandboxMap(values[key3]) || isSandboxSet(values[key3]))
153148
+ if (values[key3] === null || typeof values[key3] !== "object" || Array.isArray(values[key3]) || isSandboxClosure(values[key3]) || isSandboxPromise(values[key3]) || isSandboxCollectionIterator(values[key3]) || isSandboxMap(values[key3]) || isSandboxSet(values[key3]))
152953
153149
  throw new TypeError(`Invalid replay input ${key3}.`);
152954
153150
  }
152955
153151
  if (values.entryPointArgs !== void 0 && !Array.isArray(values.entryPointArgs))
@@ -152959,6 +153155,7 @@ var validationPromise;
152959
153155
  var init_replay_inputs = __esm({
152960
153156
  "packages/safe-js/src/snapshot/replay-inputs.ts"() {
152961
153157
  "use strict";
153158
+ init_collection_iterator();
152962
153159
  init_values();
152963
153160
  init_replay_data();
152964
153161
  init_compile_guard();
@@ -158976,11 +159173,11 @@ async function resolveWorkflowTasksOptions(options) {
158976
159173
  };
158977
159174
  }
158978
159175
  function readGateStates(frontmatter) {
158979
- const states = asRecord6(frontmatter.states);
158980
- if (states === void 0) {
159176
+ const states2 = asRecord6(frontmatter.states);
159177
+ if (states2 === void 0) {
158981
159178
  return [];
158982
159179
  }
158983
- return Object.entries(states).filter(([, definition]) => asRecord6(definition)?.gate === true).map(([name]) => name);
159180
+ return Object.entries(states2).filter(([, definition]) => asRecord6(definition)?.gate === true).map(([name]) => name);
158984
159181
  }
158985
159182
  async function readWorkflowFrontmatter(workflowPath) {
158986
159183
  const workflowContent = await readWorkflow(workflowPath);
@@ -159011,11 +159208,11 @@ function readTaskListOptions(frontmatter, workflowPath) {
159011
159208
  }
159012
159209
  return resolved;
159013
159210
  }
159014
- function createAnyToAnyStateMachine(states) {
159211
+ function createAnyToAnyStateMachine(states2) {
159015
159212
  return {
159016
- initial: states[0],
159017
- states,
159018
- events: Object.fromEntries(states.map((state) => [state, { from: "*", to: state }]))
159213
+ initial: states2[0],
159214
+ states: states2,
159215
+ events: Object.fromEntries(states2.map((state) => [state, { from: "*", to: state }]))
159019
159216
  };
159020
159217
  }
159021
159218
  function parseProject(value) {
@@ -159036,9 +159233,9 @@ function parseProject(value) {
159036
159233
  }
159037
159234
  function resolveRequiredStates(statesOption, frontmatter) {
159038
159235
  if (statesOption !== void 0) {
159039
- const states = parseStatesCsv(statesOption);
159040
- if (states.length > 0) {
159041
- return states;
159236
+ const states2 = parseStatesCsv(statesOption);
159237
+ if (states2.length > 0) {
159238
+ return states2;
159042
159239
  }
159043
159240
  throw new TasksOptionsError(
159044
159241
  "missing_required_states",
@@ -159088,8 +159285,8 @@ function readLegacyTopLevelStates(frontmatter) {
159088
159285
  ]);
159089
159286
  }
159090
159287
  function readDeclaredStates(value) {
159091
- const states = asRecord6(value);
159092
- return states === void 0 ? [] : Object.keys(states);
159288
+ const states2 = asRecord6(value);
159289
+ return states2 === void 0 ? [] : Object.keys(states2);
159093
159290
  }
159094
159291
  function readTasksRepo(frontmatter) {
159095
159292
  const tasks = asRecord6(getOwnEntry37(frontmatter, "tasks"));