@aerovato/operator-helper 1.0.0 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -323,13 +323,13 @@ var require_directives = __commonJS((exports) => {
323
323
  onError5(0, "%YAML directive should contain exactly one part");
324
324
  return false;
325
325
  }
326
- const [version2] = parts;
327
- if (version2 === "1.1" || version2 === "1.2") {
328
- this.yaml.version = version2;
326
+ const [version] = parts;
327
+ if (version === "1.1" || version === "1.2") {
328
+ this.yaml.version = version;
329
329
  return true;
330
330
  } else {
331
- const isValid = /^\d+\.\d+$/.test(version2);
332
- onError5(6, `Unsupported YAML version ${version2}`, isValid);
331
+ const isValid = /^\d+\.\d+$/.test(version);
332
+ onError5(6, `Unsupported YAML version ${version}`, isValid);
333
333
  return false;
334
334
  }
335
335
  }
@@ -726,8 +726,8 @@ var require_createNode = __commonJS((exports) => {
726
726
  var defaultTagPrefix = "tag:yaml.org,2002:";
727
727
  function findTagObject(value, tagName, tags) {
728
728
  if (tagName) {
729
- const match6 = tags.filter((t) => t.tag === tagName);
730
- const tagObj = match6.find((t) => !t.format) ?? match6[0];
729
+ const match7 = tags.filter((t) => t.tag === tagName);
730
+ const tagObj = match7.find((t) => !t.format) ?? match7[0];
731
731
  if (!tagObj)
732
732
  throw new Error(`Tag ${tagName} not found`);
733
733
  return tagObj;
@@ -1407,21 +1407,21 @@ var require_stringify = __commonJS((exports) => {
1407
1407
  }
1408
1408
  function getTagObject(tags, item) {
1409
1409
  if (item.tag) {
1410
- const match6 = tags.filter((t) => t.tag === item.tag);
1411
- if (match6.length > 0)
1412
- return match6.find((t) => t.format === item.format) ?? match6[0];
1410
+ const match7 = tags.filter((t) => t.tag === item.tag);
1411
+ if (match7.length > 0)
1412
+ return match7.find((t) => t.format === item.format) ?? match7[0];
1413
1413
  }
1414
1414
  let tagObj = undefined;
1415
1415
  let obj;
1416
1416
  if (identity3.isScalar(item)) {
1417
1417
  obj = item.value;
1418
- let match6 = tags.filter((t) => t.identify?.(obj));
1419
- if (match6.length > 1) {
1420
- const testMatch = match6.filter((t) => t.test);
1418
+ let match7 = tags.filter((t) => t.identify?.(obj));
1419
+ if (match7.length > 1) {
1420
+ const testMatch = match7.filter((t) => t.test);
1421
1421
  if (testMatch.length > 0)
1422
- match6 = testMatch;
1422
+ match7 = testMatch;
1423
1423
  }
1424
- tagObj = match6.find((t) => t.format === item.format) ?? match6.find((t) => !t.format);
1424
+ tagObj = match7.find((t) => t.format === item.format) ?? match7.find((t) => !t.format);
1425
1425
  } else {
1426
1426
  obj = item;
1427
1427
  tagObj = tags.find((t) => t.nodeClass && obj instanceof t.nodeClass);
@@ -2945,13 +2945,13 @@ var require_timestamp = __commonJS((exports) => {
2945
2945
  tag: "tag:yaml.org,2002:timestamp",
2946
2946
  test: RegExp("^([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})" + "(?:" + "(?:t|T|[ \\t]+)" + "([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2}(\\.[0-9]+)?)" + "(?:[ \\t]*(Z|[-+][012]?[0-9](?::[0-9]{2})?))?" + ")?$"),
2947
2947
  resolve(str) {
2948
- const match6 = str.match(timestamp.test);
2949
- if (!match6)
2948
+ const match7 = str.match(timestamp.test);
2949
+ if (!match7)
2950
2950
  throw new Error("!!timestamp expects a date, starting with yyyy-mm-dd");
2951
- const [, year, month, day, hour, minute, second] = match6.map(Number);
2952
- const millisec = match6[7] ? Number((match6[7] + "00").substr(1, 3)) : 0;
2951
+ const [, year, month, day, hour, minute, second] = match7.map(Number);
2952
+ const millisec = match7[7] ? Number((match7[7] + "00").substr(1, 3)) : 0;
2953
2953
  let date = Date.UTC(year, month - 1, day, hour || 0, minute || 0, second || 0, millisec);
2954
- const tz = match6[8];
2954
+ const tz = match7[8];
2955
2955
  if (tz && tz !== "Z") {
2956
2956
  let d = parseSexagesimal(tz, false);
2957
2957
  if (Math.abs(d) < 30)
@@ -3248,14 +3248,14 @@ var require_Document = __commonJS((exports) => {
3248
3248
  version: "1.2"
3249
3249
  }, options);
3250
3250
  this.options = opt;
3251
- let { version: version2 } = opt;
3251
+ let { version } = opt;
3252
3252
  if (options?._directives) {
3253
3253
  this.directives = options._directives.atDocument();
3254
3254
  if (this.directives.yaml.explicit)
3255
- version2 = this.directives.yaml.version;
3255
+ version = this.directives.yaml.version;
3256
3256
  } else
3257
- this.directives = new directives.Directives({ version: version2 });
3258
- this.setSchema(version2, options);
3257
+ this.directives = new directives.Directives({ version });
3258
+ this.setSchema(version, options);
3259
3259
  this.contents = value === undefined ? null : this.createNode(value, _replacer, options);
3260
3260
  }
3261
3261
  clone() {
@@ -3371,11 +3371,11 @@ var require_Document = __commonJS((exports) => {
3371
3371
  this.contents.setIn(path, value);
3372
3372
  }
3373
3373
  }
3374
- setSchema(version2, options = {}) {
3375
- if (typeof version2 === "number")
3376
- version2 = String(version2);
3374
+ setSchema(version, options = {}) {
3375
+ if (typeof version === "number")
3376
+ version = String(version);
3377
3377
  let opt;
3378
- switch (version2) {
3378
+ switch (version) {
3379
3379
  case "1.1":
3380
3380
  if (this.directives)
3381
3381
  this.directives.yaml.version = "1.1";
@@ -3386,9 +3386,9 @@ var require_Document = __commonJS((exports) => {
3386
3386
  case "1.2":
3387
3387
  case "next":
3388
3388
  if (this.directives)
3389
- this.directives.yaml.version = version2;
3389
+ this.directives.yaml.version = version;
3390
3390
  else
3391
- this.directives = new directives.Directives({ version: version2 });
3391
+ this.directives = new directives.Directives({ version });
3392
3392
  opt = { resolveKnownTags: true, schema: "core" };
3393
3393
  break;
3394
3394
  case null:
@@ -3397,7 +3397,7 @@ var require_Document = __commonJS((exports) => {
3397
3397
  opt = null;
3398
3398
  break;
3399
3399
  default: {
3400
- const sv = JSON.stringify(version2);
3400
+ const sv = JSON.stringify(version);
3401
3401
  throw new Error(`Expected '1.1', '1.2' or null as first argument, but found: ${sv}`);
3402
3402
  }
3403
3403
  }
@@ -4431,15 +4431,15 @@ var require_resolve_flow_scalar = __commonJS((exports) => {
4431
4431
  first = /(.*?)[ \t]*\r?\n/sy;
4432
4432
  line = /[ \t]*(.*?)[ \t]*\r?\n/sy;
4433
4433
  }
4434
- let match6 = first.exec(source);
4435
- if (!match6)
4434
+ let match7 = first.exec(source);
4435
+ if (!match7)
4436
4436
  return source;
4437
- let res = match6[1];
4437
+ let res = match7[1];
4438
4438
  let sep = " ";
4439
4439
  let pos = first.lastIndex;
4440
4440
  line.lastIndex = pos;
4441
- while (match6 = line.exec(source)) {
4442
- if (match6[1] === "") {
4441
+ while (match7 = line.exec(source)) {
4442
+ if (match7[1] === "") {
4443
4443
  if (sep === `
4444
4444
  `)
4445
4445
  res += sep;
@@ -4447,15 +4447,15 @@ var require_resolve_flow_scalar = __commonJS((exports) => {
4447
4447
  sep = `
4448
4448
  `;
4449
4449
  } else {
4450
- res += sep + match6[1];
4450
+ res += sep + match7[1];
4451
4451
  sep = " ";
4452
4452
  }
4453
4453
  pos = line.lastIndex;
4454
4454
  }
4455
4455
  const last = /[ \t]*(.*)/sy;
4456
4456
  last.lastIndex = pos;
4457
- match6 = last.exec(source);
4458
- return res + sep + (match6?.[1] ?? "");
4457
+ match7 = last.exec(source);
4458
+ return res + sep + (match7?.[1] ?? "");
4459
4459
  }
4460
4460
  function doubleQuotedValue(source, onError5) {
4461
4461
  let res = "";
@@ -7522,10 +7522,10 @@ var require_supports_colors = __commonJS((exports, module) => {
7522
7522
  return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
7523
7523
  }
7524
7524
  if ("TERM_PROGRAM" in env) {
7525
- var version2 = parseInt((env.TERM_PROGRAM_VERSION || "").split(".")[0], 10);
7525
+ var version = parseInt((env.TERM_PROGRAM_VERSION || "").split(".")[0], 10);
7526
7526
  switch (env.TERM_PROGRAM) {
7527
7527
  case "iTerm.app":
7528
- return version2 >= 3 ? 3 : 2;
7528
+ return version >= 3 ? 3 : 2;
7529
7529
  case "Hyper":
7530
7530
  return 3;
7531
7531
  case "Apple_Terminal":
@@ -7959,8 +7959,8 @@ var require_colors = __commonJS((exports, module) => {
7959
7959
  var code = ansiStyles[nestedStyles[i]];
7960
7960
  str = code.open + str.replace(code.closeRe, code.open) + code.close;
7961
7961
  if (newLinesPresent) {
7962
- str = str.replace(newLineRegex, function(match6) {
7963
- return code.close + match6 + code.open;
7962
+ str = str.replace(newLineRegex, function(match7) {
7963
+ return code.close + match7 + code.open;
7964
7964
  });
7965
7965
  }
7966
7966
  }
@@ -8671,15 +8671,16 @@ var require_table = __commonJS((exports, module) => {
8671
8671
  });
8672
8672
 
8673
8673
  // src/index.ts
8674
+ import { spawnSync } from "node:child_process";
8674
8675
  import { homedir } from "node:os";
8675
- // ../../node_modules/.bun/@effect+platform-node@4.0.0-beta.98+421eccb9593286ba/node_modules/@effect/platform-node/dist/NodeChildProcessSpawner.js
8676
+ // ../../node_modules/.bun/@effect+platform-node@4.0.0-beta.107+a2edc8a872f58f99/node_modules/@effect/platform-node/dist/NodeChildProcessSpawner.js
8676
8677
  var exports_NodeChildProcessSpawner = {};
8677
8678
  __export(exports_NodeChildProcessSpawner, {
8678
8679
  layer: () => layer2,
8679
8680
  flattenCommand: () => flattenCommand
8680
8681
  });
8681
8682
 
8682
- // ../../node_modules/.bun/effect@4.0.0-beta.98/node_modules/effect/dist/Pipeable.js
8683
+ // ../../node_modules/.bun/effect@4.0.0-beta.107/node_modules/effect/dist/Pipeable.js
8683
8684
  var pipeArguments = (self, args) => {
8684
8685
  switch (args.length) {
8685
8686
  case 0:
@@ -8722,7 +8723,7 @@ var Class = /* @__PURE__ */ function() {
8722
8723
  return PipeableBase;
8723
8724
  }();
8724
8725
 
8725
- // ../../node_modules/.bun/effect@4.0.0-beta.98/node_modules/effect/dist/Function.js
8726
+ // ../../node_modules/.bun/effect@4.0.0-beta.107/node_modules/effect/dist/Function.js
8726
8727
  var dual = function(arity, body) {
8727
8728
  if (typeof arity === "function") {
8728
8729
  return function() {
@@ -8813,7 +8814,7 @@ function flow(ab, bc, cd, de, ef, fg, gh, hi, ij) {
8813
8814
  return;
8814
8815
  }
8815
8816
 
8816
- // ../../node_modules/.bun/effect@4.0.0-beta.98/node_modules/effect/dist/internal/equal.js
8817
+ // ../../node_modules/.bun/effect@4.0.0-beta.107/node_modules/effect/dist/internal/equal.js
8817
8818
  var getAllObjectKeys = (obj) => {
8818
8819
  const keys = new Set(Reflect.ownKeys(obj));
8819
8820
  if (obj.constructor === Object)
@@ -8837,7 +8838,7 @@ var getAllObjectKeys = (obj) => {
8837
8838
  };
8838
8839
  var byReferenceInstances = /* @__PURE__ */ new WeakSet;
8839
8840
 
8840
- // ../../node_modules/.bun/effect@4.0.0-beta.98/node_modules/effect/dist/Predicate.js
8841
+ // ../../node_modules/.bun/effect@4.0.0-beta.107/node_modules/effect/dist/Predicate.js
8841
8842
  function isString(input) {
8842
8843
  return typeof input === "string";
8843
8844
  }
@@ -8865,7 +8866,7 @@ function isIterable(input) {
8865
8866
  return hasProperty(input, Symbol.iterator) || isString(input);
8866
8867
  }
8867
8868
 
8868
- // ../../node_modules/.bun/effect@4.0.0-beta.98/node_modules/effect/dist/Hash.js
8869
+ // ../../node_modules/.bun/effect@4.0.0-beta.107/node_modules/effect/dist/Hash.js
8869
8870
  var symbol = "~effect/interfaces/Hash";
8870
8871
  var hash = (self) => {
8871
8872
  switch (typeof self) {
@@ -8886,6 +8887,9 @@ var hash = (self) => {
8886
8887
  if (self === null) {
8887
8888
  return string("null");
8888
8889
  } else if (self instanceof Date) {
8890
+ if (Number.isNaN(self.getTime())) {
8891
+ return string("Invalid Date");
8892
+ }
8889
8893
  return string(self.toISOString());
8890
8894
  } else if (self instanceof RegExp) {
8891
8895
  return string(self.toString());
@@ -8901,6 +8905,8 @@ var hash = (self) => {
8901
8905
  return self[symbol]();
8902
8906
  } else if (typeof self === "function") {
8903
8907
  return random(self);
8908
+ } else if (self instanceof DataView) {
8909
+ return array(new Uint8Array(self.buffer, self.byteOffset, self.byteLength));
8904
8910
  } else if (Array.isArray(self) || ArrayBuffer.isView(self)) {
8905
8911
  return array(self);
8906
8912
  } else if (self instanceof Map) {
@@ -8984,7 +8990,7 @@ function withVisitedTracking(obj, fn) {
8984
8990
  return result;
8985
8991
  }
8986
8992
 
8987
- // ../../node_modules/.bun/effect@4.0.0-beta.98/node_modules/effect/dist/Equal.js
8993
+ // ../../node_modules/.bun/effect@4.0.0-beta.107/node_modules/effect/dist/Equal.js
8988
8994
  var symbol2 = "~effect/interfaces/Equal";
8989
8995
  function equals() {
8990
8996
  if (arguments.length === 1) {
@@ -9036,7 +9042,9 @@ function compareObjects(self, that) {
9036
9042
  } else if (self instanceof Date) {
9037
9043
  if (!(that instanceof Date))
9038
9044
  return false;
9039
- return self.toISOString() === that.toISOString();
9045
+ const selfTime = self.getTime();
9046
+ const thatTime = that.getTime();
9047
+ return selfTime === thatTime || Number.isNaN(selfTime) && Number.isNaN(thatTime);
9040
9048
  } else if (self instanceof RegExp) {
9041
9049
  if (!(that instanceof RegExp))
9042
9050
  return false;
@@ -9059,9 +9067,14 @@ function compareObjects(self, that) {
9059
9067
  }
9060
9068
  return compareArrays(self, that);
9061
9069
  } else if (ArrayBuffer.isView(self)) {
9062
- if (!ArrayBuffer.isView(that) || self.byteLength !== that.byteLength) {
9070
+ const selfIsDataView = self instanceof DataView;
9071
+ if (!ArrayBuffer.isView(that) || self.byteLength !== that.byteLength || selfIsDataView !== that instanceof DataView) {
9063
9072
  return false;
9064
9073
  }
9074
+ if (selfIsDataView) {
9075
+ const thatDataView = that;
9076
+ return compareTypedArrays(new Uint8Array(self.buffer, self.byteOffset, self.byteLength), new Uint8Array(thatDataView.buffer, thatDataView.byteOffset, thatDataView.byteLength));
9077
+ }
9065
9078
  return compareTypedArrays(self, that);
9066
9079
  } else if (self instanceof Map) {
9067
9080
  if (!(that instanceof Map) || self.size !== that.size) {
@@ -9130,10 +9143,14 @@ function compareRecords(self, that) {
9130
9143
  }
9131
9144
  function makeCompareMap(keyEquivalence, valueEquivalence) {
9132
9145
  return function compareMaps(self, that) {
9146
+ const thatEntries = Array.from(that);
9133
9147
  for (const [selfKey, selfValue] of self) {
9134
9148
  let found = false;
9135
- for (const [thatKey, thatValue] of that) {
9149
+ for (let i = 0;i < thatEntries.length; i++) {
9150
+ const [thatKey, thatValue] = thatEntries[i];
9136
9151
  if (keyEquivalence(selfKey, thatKey) && valueEquivalence(selfValue, thatValue)) {
9152
+ thatEntries[i] = thatEntries[thatEntries.length - 1];
9153
+ thatEntries.pop();
9137
9154
  found = true;
9138
9155
  break;
9139
9156
  }
@@ -9148,10 +9165,14 @@ function makeCompareMap(keyEquivalence, valueEquivalence) {
9148
9165
  var compareMaps = /* @__PURE__ */ makeCompareMap(compareBoth, compareBoth);
9149
9166
  function makeCompareSet(equivalence) {
9150
9167
  return function compareSets(self, that) {
9168
+ const thatValues = Array.from(that);
9151
9169
  for (const selfValue of self) {
9152
9170
  let found = false;
9153
- for (const thatValue of that) {
9171
+ for (let i = 0;i < thatValues.length; i++) {
9172
+ const thatValue = thatValues[i];
9154
9173
  if (equivalence(selfValue, thatValue)) {
9174
+ thatValues[i] = thatValues[thatValues.length - 1];
9175
+ thatValues.pop();
9155
9176
  found = true;
9156
9177
  break;
9157
9178
  }
@@ -9171,7 +9192,7 @@ var byReferenceUnsafe = (obj) => {
9171
9192
  return obj;
9172
9193
  };
9173
9194
 
9174
- // ../../node_modules/.bun/effect@4.0.0-beta.98/node_modules/effect/dist/Redactable.js
9195
+ // ../../node_modules/.bun/effect@4.0.0-beta.107/node_modules/effect/dist/Redactable.js
9175
9196
  var symbolRedactable = /* @__PURE__ */ Symbol.for("~effect/Redactable");
9176
9197
  var isRedactable = (u) => hasProperty(u, symbolRedactable);
9177
9198
  function redact(u) {
@@ -9183,18 +9204,21 @@ function getRedacted(redactable) {
9183
9204
  return redactable[symbolRedactable](globalThis[currentFiberTypeId]?.context ?? emptyContext);
9184
9205
  }
9185
9206
  var currentFiberTypeId = "~effect/Fiber/currentFiber";
9207
+ var emptyMap = /* @__PURE__ */ new Map;
9186
9208
  var emptyContext = {
9187
9209
  "~effect/Context": {},
9188
- mapUnsafe: /* @__PURE__ */ new Map,
9210
+ base: emptyMap,
9211
+ depth: 0,
9212
+ mapUnsafe: emptyMap,
9189
9213
  pipe() {
9190
9214
  return pipeArguments(this, arguments);
9191
9215
  }
9192
9216
  };
9193
9217
 
9194
- // ../../node_modules/.bun/effect@4.0.0-beta.98/node_modules/effect/dist/Formatter.js
9218
+ // ../../node_modules/.bun/effect@4.0.0-beta.107/node_modules/effect/dist/Formatter.js
9195
9219
  function format(input, options) {
9196
9220
  const space = options?.space ?? 0;
9197
- const seen = new WeakSet;
9221
+ const ancestors = new WeakSet;
9198
9222
  const gap = !space ? "" : typeof space === "number" ? " ".repeat(space) : space;
9199
9223
  const ind = (d) => gap.repeat(d);
9200
9224
  const wrap = (v, body) => {
@@ -9210,16 +9234,15 @@ function format(input, options) {
9210
9234
  };
9211
9235
  function recur(v, d = 0) {
9212
9236
  if (Array.isArray(v)) {
9213
- if (seen.has(v))
9237
+ if (ancestors.has(v))
9214
9238
  return CIRCULAR;
9215
- seen.add(v);
9216
- if (!gap || v.length <= 1)
9217
- return `[${v.map((x) => recur(x, d)).join(",")}]`;
9218
- const inner = v.map((x) => recur(x, d + 1)).join(`,
9219
- ` + ind(d + 1));
9220
- return `[
9221
- ${ind(d + 1)}${inner}
9239
+ ancestors.add(v);
9240
+ const output = !gap || v.length <= 1 ? `[${v.map((x) => recur(x, d)).join(",")}]` : `[
9241
+ ${ind(d + 1)}${v.map((x) => recur(x, d + 1)).join(`,
9242
+ ` + ind(d + 1))}
9222
9243
  ${ind(d)}]`;
9244
+ ancestors.delete(v);
9245
+ return output;
9223
9246
  }
9224
9247
  if (v instanceof Date)
9225
9248
  return formatDate(v);
@@ -9237,24 +9260,29 @@ ${ind(d)}]`;
9237
9260
  if (typeof v === "bigint")
9238
9261
  return String(v) + "n";
9239
9262
  if (typeof v === "object" || typeof v === "function") {
9240
- if (seen.has(v))
9263
+ if (ancestors.has(v))
9241
9264
  return CIRCULAR;
9242
- seen.add(v);
9243
- if (symbolRedactable in v)
9244
- return format(getRedacted(v));
9245
- if (Symbol.iterator in v) {
9246
- return `${v.constructor.name}(${recur(Array.from(v), d)})`;
9247
- }
9248
- const keys = ownKeys(v);
9249
- if (!gap || keys.length <= 1) {
9250
- const body2 = `{${keys.map((k) => `${formatPropertyKey(k)}:${recur(v[k], d)}`).join(",")}}`;
9251
- return wrap(v, body2);
9252
- }
9253
- const body = `{
9265
+ ancestors.add(v);
9266
+ let output;
9267
+ if (symbolRedactable in v) {
9268
+ output = format(getRedacted(v));
9269
+ } else if (Symbol.iterator in v) {
9270
+ output = `${v.constructor.name}(${recur(Array.from(v), d)})`;
9271
+ } else {
9272
+ const keys = ownKeys(v);
9273
+ if (!gap || keys.length <= 1) {
9274
+ const body = `{${keys.map((k) => `${formatPropertyKey(k)}:${recur(v[k], d)}`).join(",")}}`;
9275
+ output = wrap(v, body);
9276
+ } else {
9277
+ const body = `{
9254
9278
  ${keys.map((k) => `${ind(d + 1)}${formatPropertyKey(k)}: ${recur(v[k], d + 1)}`).join(`,
9255
9279
  `)}
9256
9280
  ${ind(d)}}`;
9257
- return wrap(v, body);
9281
+ output = wrap(v, body);
9282
+ }
9283
+ }
9284
+ ancestors.delete(v);
9285
+ return output;
9258
9286
  }
9259
9287
  return String(v);
9260
9288
  }
@@ -9294,10 +9322,10 @@ function formatJson(input, options) {
9294
9322
  }
9295
9323
  ancestors.push(redacted);
9296
9324
  return redacted;
9297
- }, options?.space);
9325
+ }, options?.space) ?? "null";
9298
9326
  }
9299
9327
 
9300
- // ../../node_modules/.bun/effect@4.0.0-beta.98/node_modules/effect/dist/Inspectable.js
9328
+ // ../../node_modules/.bun/effect@4.0.0-beta.107/node_modules/effect/dist/Inspectable.js
9301
9329
  var NodeInspectSymbol = /* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom");
9302
9330
  var toJson = (input) => {
9303
9331
  try {
@@ -9335,7 +9363,7 @@ var BaseProto = {
9335
9363
  }
9336
9364
  };
9337
9365
 
9338
- // ../../node_modules/.bun/effect@4.0.0-beta.98/node_modules/effect/dist/Utils.js
9366
+ // ../../node_modules/.bun/effect@4.0.0-beta.107/node_modules/effect/dist/Utils.js
9339
9367
  class SingleShotGen {
9340
9368
  called = false;
9341
9369
  self;
@@ -9374,7 +9402,28 @@ var pickInternalCall = () => {
9374
9402
  };
9375
9403
  var internalCall = /* @__PURE__ */ pickInternalCall();
9376
9404
 
9377
- // ../../node_modules/.bun/effect@4.0.0-beta.98/node_modules/effect/dist/internal/core.js
9405
+ // ../../node_modules/.bun/effect@4.0.0-beta.107/node_modules/effect/dist/internal/record.js
9406
+ function assignProperty(self, key, value) {
9407
+ if (key === "__proto__") {
9408
+ Object.defineProperty(self, key, {
9409
+ value,
9410
+ writable: true,
9411
+ enumerable: true,
9412
+ configurable: true
9413
+ });
9414
+ } else {
9415
+ self[key] = value;
9416
+ }
9417
+ }
9418
+ function assignProperties(self, source) {
9419
+ for (const key of Reflect.ownKeys(source)) {
9420
+ if (Object.prototype.propertyIsEnumerable.call(source, key)) {
9421
+ assignProperty(self, key, source[key]);
9422
+ }
9423
+ }
9424
+ }
9425
+
9426
+ // ../../node_modules/.bun/effect@4.0.0-beta.107/node_modules/effect/dist/internal/core.js
9378
9427
  var EffectTypeId = `~effect/Effect`;
9379
9428
  var ExitTypeId = `~effect/Exit`;
9380
9429
  var effectVariance = {
@@ -9596,12 +9645,12 @@ var makePrimitive = (options) => {
9596
9645
  };
9597
9646
  var makeExit = (options) => {
9598
9647
  const Proto = {
9599
- ...makePrimitiveProto(options),
9600
9648
  [ExitTypeId]: ExitTypeId,
9601
9649
  _tag: options.op,
9602
9650
  get [options.prop]() {
9603
9651
  return this[args];
9604
9652
  },
9653
+ ...makePrimitiveProto(options),
9605
9654
  toString() {
9606
9655
  return `${options.op}(${format(this[args])})`;
9607
9656
  },
@@ -9655,7 +9704,7 @@ var exitFailCause = /* @__PURE__ */ makeExit({
9655
9704
  while (fiber.interruptible && fiber._interruptedCause && cont) {
9656
9705
  cont = fiber.getCont(contE);
9657
9706
  }
9658
- return cont ? cont[contE](cause, fiber, annotated ? undefined : this) : fiber.yieldWith(annotated ? this : exitFailCause(cause));
9707
+ return cont ? cont[contE](cause, fiber, annotated ? undefined : this) : fiber.yieldWith(annotated ? exitFailCause(cause) : this);
9659
9708
  }
9660
9709
  });
9661
9710
  var exitFail = (e) => exitFailCause(causeFail(e));
@@ -9688,7 +9737,7 @@ var Error2 = /* @__PURE__ */ function() {
9688
9737
  cause: args2.cause
9689
9738
  } : undefined);
9690
9739
  if (args2) {
9691
- Object.assign(this, args2);
9740
+ assignProperties(this, args2);
9692
9741
  Object.defineProperty(this, plainArgsSymbol, {
9693
9742
  value: args2,
9694
9743
  enumerable: false
@@ -9745,7 +9794,7 @@ var done = (value) => {
9745
9794
  return exitFail(Done(value));
9746
9795
  };
9747
9796
 
9748
- // ../../node_modules/.bun/effect@4.0.0-beta.98/node_modules/effect/dist/Reducer.js
9797
+ // ../../node_modules/.bun/effect@4.0.0-beta.107/node_modules/effect/dist/Reducer.js
9749
9798
  function make(combine2, initialValue, combineAll) {
9750
9799
  return {
9751
9800
  combine: combine2,
@@ -9760,13 +9809,13 @@ function make(combine2, initialValue, combineAll) {
9760
9809
  };
9761
9810
  }
9762
9811
 
9763
- // ../../node_modules/.bun/effect@4.0.0-beta.98/node_modules/effect/dist/Equivalence.js
9812
+ // ../../node_modules/.bun/effect@4.0.0-beta.107/node_modules/effect/dist/Equivalence.js
9764
9813
  var make2 = (isEquivalent) => (self, that) => self === that || isEquivalent(self, that);
9765
9814
 
9766
- // ../../node_modules/.bun/effect@4.0.0-beta.98/node_modules/effect/dist/internal/array.js
9815
+ // ../../node_modules/.bun/effect@4.0.0-beta.107/node_modules/effect/dist/internal/array.js
9767
9816
  var isArrayNonEmpty = (self) => self.length > 0;
9768
9817
 
9769
- // ../../node_modules/.bun/effect@4.0.0-beta.98/node_modules/effect/dist/internal/doNotation.js
9818
+ // ../../node_modules/.bun/effect@4.0.0-beta.107/node_modules/effect/dist/internal/doNotation.js
9770
9819
  var let_ = (map) => dual(3, (self, name, f) => map(self, (a) => ({
9771
9820
  ...a,
9772
9821
  [name]: f(a)
@@ -9779,7 +9828,7 @@ var bind = (map, flatMap) => dual(3, (self, name, f) => flatMap(self, (a) => map
9779
9828
  [name]: b
9780
9829
  }))));
9781
9830
 
9782
- // ../../node_modules/.bun/effect@4.0.0-beta.98/node_modules/effect/dist/Option.js
9831
+ // ../../node_modules/.bun/effect@4.0.0-beta.107/node_modules/effect/dist/Option.js
9783
9832
  var exports_Option = {};
9784
9833
  __export(exports_Option, {
9785
9834
  zipWith: () => zipWith,
@@ -9844,14 +9893,14 @@ __export(exports_Option, {
9844
9893
  Do: () => Do
9845
9894
  });
9846
9895
 
9847
- // ../../node_modules/.bun/effect@4.0.0-beta.98/node_modules/effect/dist/Combiner.js
9896
+ // ../../node_modules/.bun/effect@4.0.0-beta.107/node_modules/effect/dist/Combiner.js
9848
9897
  function make3(combine2) {
9849
9898
  return {
9850
9899
  combine: combine2
9851
9900
  };
9852
9901
  }
9853
9902
 
9854
- // ../../node_modules/.bun/effect@4.0.0-beta.98/node_modules/effect/dist/internal/option.js
9903
+ // ../../node_modules/.bun/effect@4.0.0-beta.107/node_modules/effect/dist/internal/option.js
9855
9904
  var TypeId = "~effect/data/Option";
9856
9905
  var CommonProto = {
9857
9906
  [TypeId]: {
@@ -9917,7 +9966,7 @@ var some = (value) => {
9917
9966
  return a;
9918
9967
  };
9919
9968
 
9920
- // ../../node_modules/.bun/effect@4.0.0-beta.98/node_modules/effect/dist/internal/result.js
9969
+ // ../../node_modules/.bun/effect@4.0.0-beta.107/node_modules/effect/dist/internal/result.js
9921
9970
  var TypeId2 = "~effect/data/Result";
9922
9971
  var CommonProto2 = {
9923
9972
  [TypeId2]: {
@@ -9986,7 +10035,7 @@ var getFailure = (self) => isSuccess(self) ? none : some(self.failure);
9986
10035
  var getSuccess = (self) => isFailure(self) ? none : some(self.success);
9987
10036
  var fromOption = /* @__PURE__ */ dual(2, (self, onNone) => isNone(self) ? fail(onNone()) : succeed(self.value));
9988
10037
 
9989
- // ../../node_modules/.bun/effect@4.0.0-beta.98/node_modules/effect/dist/Order.js
10038
+ // ../../node_modules/.bun/effect@4.0.0-beta.107/node_modules/effect/dist/Order.js
9990
10039
  function make4(compare) {
9991
10040
  return (self, that) => self === that ? 0 : compare(self, that);
9992
10041
  }
@@ -10002,7 +10051,7 @@ var Number2 = /* @__PURE__ */ make4((self, that) => {
10002
10051
  var mapInput = /* @__PURE__ */ dual(2, (self, f) => make4((b1, b2) => self(f(b1), f(b2))));
10003
10052
  var isGreaterThan = (O) => dual(2, (self, that) => O(self, that) === 1);
10004
10053
 
10005
- // ../../node_modules/.bun/effect@4.0.0-beta.98/node_modules/effect/dist/Option.js
10054
+ // ../../node_modules/.bun/effect@4.0.0-beta.107/node_modules/effect/dist/Option.js
10006
10055
  var none2 = () => none;
10007
10056
  var some2 = some;
10008
10057
  var isOption2 = isOption;
@@ -10100,7 +10149,7 @@ var all = (input) => {
10100
10149
  if (isNone2(o)) {
10101
10150
  return none2();
10102
10151
  }
10103
- out[key] = o.value;
10152
+ assignProperty(out, key, o.value);
10104
10153
  }
10105
10154
  return some2(out);
10106
10155
  };
@@ -10184,7 +10233,7 @@ function makeReducerFailFast(reducer) {
10184
10233
  });
10185
10234
  }
10186
10235
 
10187
- // ../../node_modules/.bun/effect@4.0.0-beta.98/node_modules/effect/dist/Result.js
10236
+ // ../../node_modules/.bun/effect@4.0.0-beta.107/node_modules/effect/dist/Result.js
10188
10237
  var exports_Result = {};
10189
10238
  __export(exports_Result, {
10190
10239
  void: () => void_2,
@@ -10259,8 +10308,8 @@ var mapBoth = /* @__PURE__ */ dual(2, (self, {
10259
10308
  onFailure,
10260
10309
  onSuccess
10261
10310
  }) => isFailure2(self) ? fail2(onFailure(self.failure)) : succeed2(onSuccess(self.success)));
10262
- var mapError = /* @__PURE__ */ dual(2, (self, f) => isFailure2(self) ? fail2(f(self.failure)) : succeed2(self.success));
10263
- var map2 = /* @__PURE__ */ dual(2, (self, f) => isSuccess2(self) ? succeed2(f(self.success)) : fail2(self.failure));
10311
+ var mapError = /* @__PURE__ */ dual(2, (self, f) => isFailure2(self) ? fail2(f(self.failure)) : self);
10312
+ var map2 = /* @__PURE__ */ dual(2, (self, f) => isSuccess2(self) ? succeed2(f(self.success)) : self);
10264
10313
  var match2 = /* @__PURE__ */ dual(2, (self, {
10265
10314
  onFailure,
10266
10315
  onSuccess
@@ -10304,7 +10353,7 @@ var all2 = (input) => {
10304
10353
  if (isFailure2(e)) {
10305
10354
  return e;
10306
10355
  }
10307
- out[key] = e.success;
10356
+ assignProperty(out, key, e.success);
10308
10357
  }
10309
10358
  return succeed2(out);
10310
10359
  };
@@ -10339,7 +10388,7 @@ var tap2 = /* @__PURE__ */ dual(2, (self, f) => {
10339
10388
  return self;
10340
10389
  });
10341
10390
 
10342
- // ../../node_modules/.bun/effect@4.0.0-beta.98/node_modules/effect/dist/Iterable.js
10391
+ // ../../node_modules/.bun/effect@4.0.0-beta.107/node_modules/effect/dist/Iterable.js
10343
10392
  var makeBy = (f, options) => {
10344
10393
  const max = options?.length !== undefined ? Math.max(1, Math.floor(options.length)) : Infinity;
10345
10394
  return {
@@ -10391,19 +10440,20 @@ var flatten2 = (self) => ({
10391
10440
  const outerIterator = self[Symbol.iterator]();
10392
10441
  let innerIterator;
10393
10442
  function next() {
10394
- if (innerIterator === undefined) {
10395
- const next2 = outerIterator.next();
10396
- if (next2.done) {
10397
- return next2;
10443
+ while (true) {
10444
+ if (innerIterator === undefined) {
10445
+ const next2 = outerIterator.next();
10446
+ if (next2.done) {
10447
+ return next2;
10448
+ }
10449
+ innerIterator = next2.value[Symbol.iterator]();
10450
+ }
10451
+ const result = innerIterator.next();
10452
+ if (!result.done) {
10453
+ return result;
10398
10454
  }
10399
- innerIterator = next2.value[Symbol.iterator]();
10400
- }
10401
- const result = innerIterator.next();
10402
- if (result.done) {
10403
10455
  innerIterator = undefined;
10404
- return next();
10405
10456
  }
10406
- return result;
10407
10457
  }
10408
10458
  return {
10409
10459
  next
@@ -10435,7 +10485,7 @@ var filter2 = /* @__PURE__ */ dual(2, (self, predicate) => ({
10435
10485
  }
10436
10486
  }));
10437
10487
 
10438
- // ../../node_modules/.bun/effect@4.0.0-beta.98/node_modules/effect/dist/Array.js
10488
+ // ../../node_modules/.bun/effect@4.0.0-beta.107/node_modules/effect/dist/Array.js
10439
10489
  var Array2 = globalThis.Array;
10440
10490
  var allocate = (n) => new Array2(n);
10441
10491
  var makeBy2 = /* @__PURE__ */ dual(2, (n, f) => {
@@ -10453,7 +10503,7 @@ var isArray = Array2.isArray;
10453
10503
  var isArrayNonEmpty2 = isArrayNonEmpty;
10454
10504
  var isReadonlyArrayNonEmpty = isArrayNonEmpty;
10455
10505
  function isOutOfBounds(i, as2) {
10456
- return i < 0 || i >= as2.length;
10506
+ return !Number.isFinite(i) || i < 0 || i >= as2.length;
10457
10507
  }
10458
10508
  var getUnsafe = /* @__PURE__ */ dual(2, (self, index) => {
10459
10509
  const i = Math.floor(index);
@@ -10462,27 +10512,35 @@ var getUnsafe = /* @__PURE__ */ dual(2, (self, index) => {
10462
10512
  }
10463
10513
  return self[i];
10464
10514
  });
10465
- var headNonEmpty = /* @__PURE__ */ getUnsafe(0);
10466
10515
  var lastNonEmpty = (self) => self[self.length - 1];
10467
- var tailNonEmpty = (self) => self.slice(1);
10468
10516
  var sort = /* @__PURE__ */ dual(2, (self, O) => {
10469
10517
  const out = Array2.from(self);
10470
10518
  out.sort(O);
10471
10519
  return out;
10472
10520
  });
10473
- var unionWith = /* @__PURE__ */ dual(3, (self, that, isEquivalent) => {
10521
+ var hashBucketsAdd = (buckets, value) => {
10522
+ const hash2 = hash(value);
10523
+ const bucket = buckets.get(hash2);
10524
+ if (bucket === undefined) {
10525
+ buckets.set(hash2, [value]);
10526
+ return true;
10527
+ }
10528
+ for (const previous of bucket) {
10529
+ if (equals(previous, value)) {
10530
+ return false;
10531
+ }
10532
+ }
10533
+ bucket.push(value);
10534
+ return true;
10535
+ };
10536
+ var union = /* @__PURE__ */ dual(2, (self, that) => {
10474
10537
  const a = fromIterable2(self);
10475
10538
  const b = fromIterable2(that);
10476
10539
  if (isReadonlyArrayNonEmpty(a)) {
10477
- if (isReadonlyArrayNonEmpty(b)) {
10478
- const dedupe = dedupeWith(isEquivalent);
10479
- return dedupe(appendAll(a, b));
10480
- }
10481
- return a;
10540
+ return isReadonlyArrayNonEmpty(b) ? dedupe(appendAll(a, b)) : a;
10482
10541
  }
10483
10542
  return b;
10484
10543
  });
10485
- var union = /* @__PURE__ */ dual(2, (self, that) => unionWith(self, that, asEquivalence()));
10486
10544
  var empty = () => [];
10487
10545
  var of = (a) => [a];
10488
10546
  var map3 = /* @__PURE__ */ dual(2, (self, f) => self.map(f));
@@ -10510,27 +10568,26 @@ var partition = /* @__PURE__ */ dual(2, (self, f) => {
10510
10568
  }
10511
10569
  return [excluded, satisfying];
10512
10570
  });
10513
- var dedupeWith = /* @__PURE__ */ dual(2, (self, isEquivalent) => {
10571
+ var dedupe = (self) => {
10514
10572
  const input = fromIterable2(self);
10515
- if (isReadonlyArrayNonEmpty(input)) {
10516
- const out = [headNonEmpty(input)];
10517
- const rest = tailNonEmpty(input);
10518
- for (const r of rest) {
10519
- if (out.every((a) => !isEquivalent(r, a))) {
10520
- out.push(r);
10521
- }
10573
+ if (input.length < 2) {
10574
+ return [...input];
10575
+ }
10576
+ const buckets = new Map;
10577
+ const out = [];
10578
+ for (const value of input) {
10579
+ if (hashBucketsAdd(buckets, value)) {
10580
+ out.push(value);
10522
10581
  }
10523
- return out;
10524
10582
  }
10525
- return [];
10526
- });
10583
+ return out;
10584
+ };
10527
10585
 
10528
- // ../../node_modules/.bun/effect@4.0.0-beta.98/node_modules/effect/dist/Context.js
10586
+ // ../../node_modules/.bun/effect@4.0.0-beta.107/node_modules/effect/dist/Context.js
10529
10587
  var exports_Context = {};
10530
10588
  __export(exports_Context, {
10531
10589
  pick: () => pick,
10532
10590
  omit: () => omit,
10533
- mutate: () => mutate,
10534
10591
  mergeAll: () => mergeAll,
10535
10592
  merge: () => merge2,
10536
10593
  makeUnsafe: () => makeUnsafe,
@@ -10538,8 +10595,9 @@ __export(exports_Context, {
10538
10595
  isReference: () => isReference,
10539
10596
  isKey: () => isKey,
10540
10597
  isContext: () => isContext,
10598
+ hasSameCache: () => hasSameCache,
10541
10599
  getUnsafe: () => getUnsafe2,
10542
- getReferenceUnsafe: () => getReferenceUnsafe,
10600
+ getOrUndefinedUnsafe: () => getOrUndefinedUnsafe,
10543
10601
  getOrUndefined: () => getOrUndefined3,
10544
10602
  getOrElse: () => getOrElse3,
10545
10603
  getOption: () => getOption,
@@ -10552,61 +10610,33 @@ __export(exports_Context, {
10552
10610
  Reference: () => Reference
10553
10611
  });
10554
10612
 
10555
- // ../../node_modules/.bun/effect@4.0.0-beta.98/node_modules/effect/dist/Effectable.js
10613
+ // ../../node_modules/.bun/effect@4.0.0-beta.107/node_modules/effect/dist/Effectable.js
10556
10614
  var Prototype2 = (options) => makePrimitiveProto({
10557
10615
  op: options.label,
10558
10616
  [evaluate]: options.evaluate
10559
10617
  });
10560
10618
 
10561
- // ../../node_modules/.bun/effect@4.0.0-beta.98/node_modules/effect/dist/internal/stackTraceLimit.js
10562
- var ObjectGetOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
10563
- var ObjectPrototypeHasOwnProperty = Object.prototype.hasOwnProperty;
10564
- var ObjectIsExtensible = Object.isExtensible;
10565
- var isStackTraceLimitWritable = () => {
10566
- const desc = ObjectGetOwnPropertyDescriptor(Error, "stackTraceLimit");
10567
- if (desc === undefined) {
10568
- return ObjectIsExtensible(Error);
10569
- }
10570
- return ObjectPrototypeHasOwnProperty.call(desc, "writable") ? desc.writable === true : desc.set !== undefined;
10571
- };
10572
- var canWriteStackTraceLimit = /* @__PURE__ */ isStackTraceLimitWritable();
10573
- var getStackTraceLimit = () => Error.stackTraceLimit;
10574
- var setStackTraceLimit = (value) => {
10575
- if (canWriteStackTraceLimit) {
10576
- Error.stackTraceLimit = value;
10577
- }
10578
- };
10579
-
10580
- // ../../node_modules/.bun/effect@4.0.0-beta.98/node_modules/effect/dist/Context.js
10619
+ // ../../node_modules/.bun/effect@4.0.0-beta.107/node_modules/effect/dist/Context.js
10581
10620
  var ServiceTypeId = "~effect/Context/Service";
10582
10621
  var Service = function() {
10583
- const prevLimit = getStackTraceLimit();
10584
- setStackTraceLimit(2);
10585
- const err = new Error;
10586
- setStackTraceLimit(prevLimit);
10587
10622
  function KeyClass() {}
10588
10623
  const self = KeyClass;
10589
10624
  Object.setPrototypeOf(self, ServiceProto);
10590
- Object.defineProperty(self, "stack", {
10591
- get() {
10592
- return err.stack;
10593
- }
10594
- });
10595
- if (arguments.length > 0) {
10596
- self.key = arguments[0];
10597
- if (arguments[1]?.defaultValue) {
10625
+ const init = (key, options) => {
10626
+ self.key = key;
10627
+ if (options?.defaultValue) {
10598
10628
  self[ReferenceTypeId] = ReferenceTypeId;
10599
- self.defaultValue = arguments[1].defaultValue;
10629
+ self.defaultValue = options.defaultValue;
10600
10630
  }
10601
- return self;
10602
- }
10603
- return function(key, options) {
10604
- self.key = key;
10605
10631
  if (options?.make) {
10606
10632
  self.make = options.make;
10607
10633
  }
10634
+ if (options?.fiberCached) {
10635
+ cacheKeys.add(key);
10636
+ }
10608
10637
  return self;
10609
10638
  };
10639
+ return arguments.length > 0 ? init(arguments[0], arguments[1]) : init;
10610
10640
  };
10611
10641
  var ServiceProto = {
10612
10642
  [ServiceTypeId]: ServiceTypeId,
@@ -10619,8 +10649,7 @@ var ServiceProto = {
10619
10649
  toJSON() {
10620
10650
  return {
10621
10651
  _id: "Service",
10622
- key: this.key,
10623
- stack: this.stack
10652
+ key: this.key
10624
10653
  };
10625
10654
  },
10626
10655
  of(self) {
@@ -10636,19 +10665,67 @@ var ServiceProto = {
10636
10665
  return withFiber((fiber) => exitSucceed(f(get(fiber.context, this))));
10637
10666
  }
10638
10667
  };
10668
+ var cacheKeys = /* @__PURE__ */ new Set;
10639
10669
  var ReferenceTypeId = "~effect/Context/Reference";
10640
10670
  var TypeId3 = "~effect/Context";
10641
- var makeUnsafe = (mapUnsafe) => {
10671
+ var MaxDepth = 8;
10672
+ var FlattenAfterBaseHits = 8;
10673
+ var makeImpl = (cacheRoot, base, overlay, depth) => {
10642
10674
  const self = Object.create(Proto);
10643
- self.mapUnsafe = mapUnsafe;
10644
- self.mutable = false;
10675
+ self.cacheRoot = cacheRoot ?? self;
10676
+ self.base = base;
10677
+ self.overlay = overlay;
10678
+ self.depth = depth;
10679
+ self._flat = undefined;
10680
+ self.baseHits = 0;
10645
10681
  return self;
10646
10682
  };
10683
+ var applyOverlays = (map4, overlay) => {
10684
+ if (!overlay)
10685
+ return;
10686
+ applyOverlays(map4, overlay.parent);
10687
+ map4.set(overlay.key, overlay.value);
10688
+ };
10689
+ var flatten3 = (self) => {
10690
+ if (self._flat)
10691
+ return self._flat;
10692
+ if (!self.overlay)
10693
+ return self._flat = self.base;
10694
+ const map4 = new Map(self.base);
10695
+ applyOverlays(map4, self.overlay);
10696
+ return self._flat = map4;
10697
+ };
10698
+ var withFlat = (self, f) => {
10699
+ const map4 = new Map(self.mapUnsafe);
10700
+ f(map4);
10701
+ return makeUnsafe(map4);
10702
+ };
10703
+ var notFound = /* @__PURE__ */ Symbol();
10704
+ var lookup = (self, key) => {
10705
+ const impl = self;
10706
+ for (let overlay = impl.overlay;overlay; overlay = overlay.parent) {
10707
+ if (overlay.key === key)
10708
+ return overlay.value;
10709
+ }
10710
+ const value = impl.base.get(key);
10711
+ if (value === undefined && !impl.base.has(key))
10712
+ return notFound;
10713
+ if (impl.overlay && ++impl.baseHits >= FlattenAfterBaseHits) {
10714
+ impl.base = flatten3(impl);
10715
+ impl.overlay = undefined;
10716
+ impl.depth = 0;
10717
+ }
10718
+ return value;
10719
+ };
10720
+ var makeUnsafe = (mapUnsafe) => makeImpl(undefined, mapUnsafe, undefined, 0);
10647
10721
  var Proto = {
10648
10722
  ...PipeInspectableProto,
10649
10723
  [TypeId3]: {
10650
10724
  _Services: (_) => _
10651
10725
  },
10726
+ get mapUnsafe() {
10727
+ return flatten3(this);
10728
+ },
10652
10729
  toJSON() {
10653
10730
  return {
10654
10731
  _id: "Context",
@@ -10659,12 +10736,15 @@ var Proto = {
10659
10736
  };
10660
10737
  },
10661
10738
  [symbol2](that) {
10662
- if (!isContext(that) || this.mapUnsafe.size !== that.mapUnsafe.size)
10739
+ if (!isContext(that))
10740
+ return false;
10741
+ const self = this.mapUnsafe;
10742
+ const other = that.mapUnsafe;
10743
+ if (self.size !== other.size)
10663
10744
  return false;
10664
- for (const k of this.mapUnsafe.keys()) {
10665
- if (!that.mapUnsafe.has(k) || !equals(this.mapUnsafe.get(k), that.mapUnsafe.get(k))) {
10745
+ for (const [key, value] of self) {
10746
+ if (!other.has(key) || !equals(value, other.get(key)))
10666
10747
  return false;
10667
- }
10668
10748
  }
10669
10749
  return true;
10670
10750
  },
@@ -10672,44 +10752,49 @@ var Proto = {
10672
10752
  return number(this.mapUnsafe.size);
10673
10753
  }
10674
10754
  };
10755
+ var hasSameCache = (self, that) => self.cacheRoot === that.cacheRoot;
10675
10756
  var isContext = (u) => hasProperty(u, TypeId3);
10676
10757
  var isKey = (u) => hasProperty(u, ServiceTypeId);
10677
- var isReference = (u) => hasProperty(u, ReferenceTypeId);
10758
+ var isReference = (u) => !!u[ReferenceTypeId];
10678
10759
  var empty2 = () => emptyContext2;
10679
10760
  var emptyContext2 = /* @__PURE__ */ makeUnsafe(/* @__PURE__ */ new Map);
10680
10761
  var make5 = (key, service) => makeUnsafe(new Map([[key.key, service]]));
10681
- var add = /* @__PURE__ */ dual(3, (self, key, service) => withMapUnsafe(self, (map4) => {
10682
- map4.set(key.key, service);
10683
- }));
10684
- var addOrOmit = /* @__PURE__ */ dual(3, (self, key, service) => withMapUnsafe(self, (map4) => {
10685
- if (service._tag === "None") {
10686
- map4.delete(key.key);
10687
- } else {
10688
- map4.set(key.key, service.value);
10689
- }
10690
- }));
10762
+ var add = /* @__PURE__ */ dual(3, (self, key, service) => {
10763
+ const impl = self;
10764
+ const cacheRoot = cacheKeys.has(key.key) ? undefined : impl.cacheRoot;
10765
+ if (impl.depth >= MaxDepth) {
10766
+ const map4 = new Map(impl.mapUnsafe);
10767
+ map4.set(key.key, service);
10768
+ return makeImpl(cacheRoot, map4, undefined, 0);
10769
+ }
10770
+ return makeImpl(cacheRoot, impl.base, {
10771
+ key: key.key,
10772
+ value: service,
10773
+ parent: impl.overlay
10774
+ }, impl.depth + 1);
10775
+ });
10776
+ var addOrOmit = /* @__PURE__ */ dual(3, (self, key, service) => service._tag === "None" ? omit(key)(self) : add(self, key, service.value));
10691
10777
  var getOrElse3 = /* @__PURE__ */ dual(3, (self, key, orElse3) => {
10692
- if (self.mapUnsafe.has(key.key)) {
10693
- return self.mapUnsafe.get(key.key);
10694
- }
10778
+ const value = lookup(self, key.key);
10779
+ if (value !== notFound)
10780
+ return value;
10695
10781
  return isReference(key) ? getDefaultValue(key) : orElse3();
10696
10782
  });
10697
- var getOrUndefined3 = /* @__PURE__ */ dual(2, (self, key) => self.mapUnsafe.get(key.key));
10783
+ var getOrUndefined3 = /* @__PURE__ */ dual(2, (self, key) => getOrUndefinedUnsafe(self, key.key));
10784
+ var getOrUndefinedUnsafe = (self, key) => {
10785
+ const value = lookup(self, key);
10786
+ return value === notFound ? undefined : value;
10787
+ };
10698
10788
  var getUnsafe2 = /* @__PURE__ */ dual(2, (self, service) => {
10699
- if (!self.mapUnsafe.has(service.key)) {
10700
- if (ReferenceTypeId in service)
10789
+ const value = lookup(self, service.key);
10790
+ if (value === notFound) {
10791
+ if (isReference(service))
10701
10792
  return getDefaultValue(service);
10702
10793
  throw serviceNotFoundError(service);
10703
10794
  }
10704
- return self.mapUnsafe.get(service.key);
10795
+ return value;
10705
10796
  });
10706
10797
  var get = getUnsafe2;
10707
- var getReferenceUnsafe = (self, service) => {
10708
- if (!self.mapUnsafe.has(service.key)) {
10709
- return getDefaultValue(service);
10710
- }
10711
- return self.mapUnsafe.get(service.key);
10712
- };
10713
10798
  var defaultValueCacheKey = "~effect/Context/defaultValue";
10714
10799
  var getDefaultValue = (ref) => {
10715
10800
  if (defaultValueCacheKey in ref) {
@@ -10719,16 +10804,6 @@ var getDefaultValue = (ref) => {
10719
10804
  };
10720
10805
  var serviceNotFoundError = (service) => {
10721
10806
  const error = new Error(`Service not found${service.key ? `: ${String(service.key)}` : ""}`);
10722
- if (service.stack) {
10723
- const lines = service.stack.split(`
10724
- `);
10725
- if (lines.length > 2) {
10726
- const afterAt = lines[2].match(/at (.*)/);
10727
- if (afterAt) {
10728
- error.message = error.message + ` (defined at ${afterAt[1]})`;
10729
- }
10730
- }
10731
- }
10732
10807
  if (error.stack) {
10733
10808
  const lines = error.stack.split(`
10734
10809
  `);
@@ -10739,9 +10814,9 @@ var serviceNotFoundError = (service) => {
10739
10814
  return error;
10740
10815
  };
10741
10816
  var getOption = /* @__PURE__ */ dual(2, (self, service) => {
10742
- if (self.mapUnsafe.has(service.key)) {
10743
- return some2(self.mapUnsafe.get(service.key));
10744
- }
10817
+ const value = lookup(self, service.key);
10818
+ if (value !== notFound)
10819
+ return some2(value);
10745
10820
  return isReference(service) ? some2(getDefaultValue(service)) : none2();
10746
10821
  });
10747
10822
  var merge2 = /* @__PURE__ */ dual(2, (self, that) => {
@@ -10749,9 +10824,7 @@ var merge2 = /* @__PURE__ */ dual(2, (self, that) => {
10749
10824
  return that;
10750
10825
  if (that.mapUnsafe.size === 0)
10751
10826
  return self;
10752
- return withMapUnsafe(self, (map4) => {
10753
- that.mapUnsafe.forEach((value, key) => map4.set(key, value));
10754
- });
10827
+ return withFlat(self, (map4) => that.mapUnsafe.forEach((value, key) => map4.set(key, value)));
10755
10828
  });
10756
10829
  var mergeAll = (...ctxs) => {
10757
10830
  const map4 = new Map;
@@ -10762,45 +10835,40 @@ var mergeAll = (...ctxs) => {
10762
10835
  }
10763
10836
  return makeUnsafe(map4);
10764
10837
  };
10765
- var pick = (...services) => (self) => withMapUnsafe(self, (map4) => {
10766
- const keySet = new Set(services.map((key) => key.key));
10767
- map4.forEach((_, key) => {
10768
- if (keySet.has(key))
10769
- return;
10770
- map4.delete(key);
10771
- });
10772
- });
10773
- var omit = (...keys) => (self) => withMapUnsafe(self, (map4) => {
10838
+ var pick = (...services) => (self) => {
10839
+ const keep = new Set(services.map((key) => key.key));
10840
+ return withFlat(self, (map4) => map4.forEach((_, key) => {
10841
+ if (!keep.has(key))
10842
+ map4.delete(key);
10843
+ }));
10844
+ };
10845
+ var omit = (...keys) => (self) => withFlat(self, (map4) => {
10774
10846
  for (let i = 0;i < keys.length; i++) {
10775
10847
  map4.delete(keys[i].key);
10776
10848
  }
10777
10849
  });
10778
- var mutate = /* @__PURE__ */ dual(2, (self, f) => {
10779
- const next = makeUnsafe(new Map(self.mapUnsafe));
10780
- next.mutable = true;
10781
- const result = f(next);
10782
- result.mutable = false;
10783
- return result;
10784
- });
10785
- var withMapUnsafe = (self, f) => {
10786
- if (self.mutable) {
10787
- f(self.mapUnsafe);
10788
- return self;
10789
- }
10790
- const map4 = new Map(self.mapUnsafe);
10791
- f(map4);
10792
- return makeUnsafe(map4);
10793
- };
10794
10850
  var Reference = Service;
10795
10851
 
10796
- // ../../node_modules/.bun/effect@4.0.0-beta.98/node_modules/effect/dist/Duration.js
10852
+ // ../../node_modules/.bun/effect@4.0.0-beta.107/node_modules/effect/dist/Duration.js
10797
10853
  var TypeId4 = "~effect/time/Duration";
10798
10854
  var bigint0 = /* @__PURE__ */ BigInt(0);
10799
10855
  var bigint1 = /* @__PURE__ */ BigInt(1);
10856
+ var bigint2 = /* @__PURE__ */ BigInt(2);
10857
+ var bigint10 = /* @__PURE__ */ BigInt(10);
10800
10858
  var bigint1e3 = /* @__PURE__ */ BigInt(1000);
10801
10859
  var roundTiesAwayFromZero = (input) => BigInt(input < 0 ? Math.ceil(input - 0.5) : Math.floor(input + 0.5));
10802
10860
  var roundMillisToNanos = (millis) => roundTiesAwayFromZero(millis * 1e6);
10803
- var parseNanos = (input, scale) => input.includes(".") ? roundTiesAwayFromZero(Number(input) * Number(scale)) : BigInt(input) * scale;
10861
+ var parseNanos = (input, scale) => {
10862
+ const decimalIndex = input.indexOf(".");
10863
+ if (decimalIndex === -1)
10864
+ return BigInt(input) * scale;
10865
+ const isNegative = input[0] === "-";
10866
+ const fractional = input.slice(decimalIndex + 1);
10867
+ const fractionalScale = bigint10 ** BigInt(fractional.length);
10868
+ const scaled = (BigInt(input.slice(isNegative ? 1 : 0, decimalIndex)) * fractionalScale + BigInt(fractional)) * scale;
10869
+ const rounded = scaled / fractionalScale + (scaled % fractionalScale * bigint2 >= fractionalScale ? bigint1 : bigint0);
10870
+ return isNegative ? -rounded : rounded;
10871
+ };
10804
10872
  var DURATION_REGEXP = /^(-?\d+(?:\.\d+)?)\s+(nanos?|micros?|millis?|seconds?|minutes?|hours?|days?|weeks?)$/;
10805
10873
  var fromInputUnsafe = (input) => {
10806
10874
  switch (typeof input) {
@@ -10905,7 +10973,16 @@ var negativeInfinityDurationValue = {
10905
10973
  var DurationProto = {
10906
10974
  [TypeId4]: TypeId4,
10907
10975
  [symbol]() {
10908
- return structure(this.value);
10976
+ switch (this.value._tag) {
10977
+ case "Millis": {
10978
+ const nanos = this.value.millis * 1e6;
10979
+ return Number.isFinite(nanos) ? hash(roundTiesAwayFromZero(nanos)) : number(this.value.millis);
10980
+ }
10981
+ case "Nanos":
10982
+ return hash(this.value.nanos);
10983
+ default:
10984
+ return structure(this.value);
10985
+ }
10909
10986
  },
10910
10987
  [symbol2](that) {
10911
10988
  return isDuration(that) && equals2(this, that);
@@ -11065,7 +11142,7 @@ var subtract = /* @__PURE__ */ dual(2, (self, that) => matchPair(self, that, {
11065
11142
  }));
11066
11143
  var equals2 = /* @__PURE__ */ dual(2, (self, that) => Equivalence(self, that));
11067
11144
 
11068
- // ../../node_modules/.bun/effect@4.0.0-beta.98/node_modules/effect/dist/Filter.js
11145
+ // ../../node_modules/.bun/effect@4.0.0-beta.107/node_modules/effect/dist/Filter.js
11069
11146
  var composePassthrough = /* @__PURE__ */ dual(2, (left, right) => (input) => {
11070
11147
  const leftOut = left(input);
11071
11148
  if (isFailure2(leftOut))
@@ -11076,8 +11153,9 @@ var composePassthrough = /* @__PURE__ */ dual(2, (left, right) => (input) => {
11076
11153
  return rightOut;
11077
11154
  });
11078
11155
 
11079
- // ../../node_modules/.bun/effect@4.0.0-beta.98/node_modules/effect/dist/Scheduler.js
11156
+ // ../../node_modules/.bun/effect@4.0.0-beta.107/node_modules/effect/dist/Scheduler.js
11080
11157
  var Scheduler = /* @__PURE__ */ Reference("effect/Scheduler", {
11158
+ fiberCached: true,
11081
11159
  defaultValue: () => new MixedScheduler
11082
11160
  });
11083
11161
  var setImmediate = "setImmediate" in globalThis ? (f) => {
@@ -11087,6 +11165,16 @@ var setImmediate = "setImmediate" in globalThis ? (f) => {
11087
11165
  const timer = setTimeout(f, 0);
11088
11166
  return () => clearTimeout(timer);
11089
11167
  };
11168
+ var setMicrotask = (f) => {
11169
+ let cancelled = false;
11170
+ queueMicrotask(() => {
11171
+ if (!cancelled)
11172
+ f();
11173
+ });
11174
+ return () => {
11175
+ cancelled = true;
11176
+ };
11177
+ };
11090
11178
 
11091
11179
  class PriorityBuckets {
11092
11180
  buckets = [];
@@ -11118,9 +11206,9 @@ class PriorityBuckets {
11118
11206
  class MixedScheduler {
11119
11207
  executionMode;
11120
11208
  setImmediate;
11121
- constructor(executionMode = "async", setImmediateFn = setImmediate) {
11209
+ constructor(executionMode = "async", setImmediateFn) {
11122
11210
  this.executionMode = executionMode;
11123
- this.setImmediate = setImmediateFn;
11211
+ this.setImmediate = setImmediateFn ?? (executionMode === "sync" ? setMicrotask : setImmediate);
11124
11212
  }
11125
11213
  shouldYield(fiber) {
11126
11214
  return fiber.currentOpCount >= fiber.maxOpsBeforeYield;
@@ -11167,16 +11255,20 @@ class MixedSchedulerDispatcher {
11167
11255
  }
11168
11256
  }
11169
11257
  var MaxOpsBeforeYield = /* @__PURE__ */ Reference("effect/Scheduler/MaxOpsBeforeYield", {
11258
+ fiberCached: true,
11170
11259
  defaultValue: () => 2048
11171
11260
  });
11172
11261
  var PreventSchedulerYield = /* @__PURE__ */ Reference("effect/Scheduler/PreventSchedulerYield", {
11262
+ fiberCached: true,
11173
11263
  defaultValue: () => false
11174
11264
  });
11175
11265
 
11176
- // ../../node_modules/.bun/effect@4.0.0-beta.98/node_modules/effect/dist/Tracer.js
11266
+ // ../../node_modules/.bun/effect@4.0.0-beta.107/node_modules/effect/dist/Tracer.js
11177
11267
  var ParentSpanKey = "effect/Tracer/ParentSpan";
11178
11268
 
11179
- class ParentSpan extends (/* @__PURE__ */ Service()(ParentSpanKey)) {
11269
+ class ParentSpan extends (/* @__PURE__ */ Service()(ParentSpanKey, {
11270
+ fiberCached: true
11271
+ })) {
11180
11272
  }
11181
11273
  var make7 = (options) => options;
11182
11274
  var DisablePropagation = /* @__PURE__ */ Reference("effect/Tracer/DisablePropagation", {
@@ -11190,6 +11282,7 @@ var MinimumTraceLevel = /* @__PURE__ */ Reference("effect/Tracer/MinimumTraceLev
11190
11282
  });
11191
11283
  var TracerKey = "effect/Tracer";
11192
11284
  var Tracer = /* @__PURE__ */ Reference(TracerKey, {
11285
+ fiberCached: true,
11193
11286
  defaultValue: () => make7({
11194
11287
  span: (options) => new NativeSpan(options)
11195
11288
  })
@@ -11255,17 +11348,15 @@ var randomHexString = /* @__PURE__ */ function() {
11255
11348
  };
11256
11349
  }();
11257
11350
 
11258
- // ../../node_modules/.bun/effect@4.0.0-beta.98/node_modules/effect/dist/internal/metric.js
11351
+ // ../../node_modules/.bun/effect@4.0.0-beta.107/node_modules/effect/dist/internal/metric.js
11259
11352
  var FiberRuntimeMetricsKey = "effect/observability/Metric/FiberRuntimeMetricsKey";
11260
11353
 
11261
- // ../../node_modules/.bun/effect@4.0.0-beta.98/node_modules/effect/dist/internal/references.js
11262
- var CurrentConcurrency = /* @__PURE__ */ Reference("effect/References/CurrentConcurrency", {
11263
- defaultValue: () => "unbounded"
11264
- });
11354
+ // ../../node_modules/.bun/effect@4.0.0-beta.107/node_modules/effect/dist/internal/references.js
11265
11355
  var CurrentErrorReporters = /* @__PURE__ */ Reference("effect/ErrorReporter/CurrentErrorReporters", {
11266
11356
  defaultValue: () => new Set
11267
11357
  });
11268
11358
  var CurrentStackFrame = /* @__PURE__ */ Reference("effect/References/CurrentStackFrame", {
11359
+ fiberCached: true,
11269
11360
  defaultValue: constUndefined
11270
11361
  });
11271
11362
  var TracerEnabled = /* @__PURE__ */ Reference("effect/References/TracerEnabled", {
@@ -11284,16 +11375,34 @@ var CurrentLogAnnotations = /* @__PURE__ */ Reference("effect/References/Current
11284
11375
  defaultValue: () => ({})
11285
11376
  });
11286
11377
  var CurrentLogLevel = /* @__PURE__ */ Reference("effect/References/CurrentLogLevel", {
11378
+ fiberCached: true,
11287
11379
  defaultValue: () => "Info"
11288
11380
  });
11289
11381
  var MinimumLogLevel = /* @__PURE__ */ Reference("effect/References/MinimumLogLevel", {
11382
+ fiberCached: true,
11290
11383
  defaultValue: () => "Info"
11291
11384
  });
11292
11385
  var CurrentLogSpans = /* @__PURE__ */ Reference("effect/References/CurrentLogSpans", {
11293
11386
  defaultValue: () => []
11294
11387
  });
11295
11388
 
11296
- // ../../node_modules/.bun/effect@4.0.0-beta.98/node_modules/effect/dist/internal/tracer.js
11389
+ // ../../node_modules/.bun/effect@4.0.0-beta.107/node_modules/effect/dist/internal/stackTraceLimit.js
11390
+ var isStackTraceLimitWritable = () => {
11391
+ const desc = Object.getOwnPropertyDescriptor(Error, "stackTraceLimit");
11392
+ if (desc === undefined) {
11393
+ return Object.isExtensible(Error);
11394
+ }
11395
+ return Object.hasOwn(desc, "writable") ? desc.writable === true : desc.set !== undefined;
11396
+ };
11397
+ var canWriteStackTraceLimit = /* @__PURE__ */ isStackTraceLimitWritable();
11398
+ var getStackTraceLimit = () => Error.stackTraceLimit;
11399
+ var setStackTraceLimit = (value) => {
11400
+ if (canWriteStackTraceLimit) {
11401
+ Error.stackTraceLimit = value;
11402
+ }
11403
+ };
11404
+
11405
+ // ../../node_modules/.bun/effect@4.0.0-beta.107/node_modules/effect/dist/internal/tracer.js
11297
11406
  var addSpanStackTrace = (options) => {
11298
11407
  if (options?.captureStackTrace === false) {
11299
11408
  return options;
@@ -11327,10 +11436,7 @@ var makeStackCleaner = (line) => (stack) => {
11327
11436
  };
11328
11437
  var spanCleaner = /* @__PURE__ */ makeStackCleaner(3);
11329
11438
 
11330
- // ../../node_modules/.bun/effect@4.0.0-beta.98/node_modules/effect/dist/internal/version.js
11331
- var version = "dev";
11332
-
11333
- // ../../node_modules/.bun/effect@4.0.0-beta.98/node_modules/effect/dist/internal/effect.js
11439
+ // ../../node_modules/.bun/effect@4.0.0-beta.107/node_modules/effect/dist/internal/effect.js
11334
11440
  class Interrupt extends ReasonBase {
11335
11441
  fiberId;
11336
11442
  constructor(fiberId, annotations = constEmptyAnnotations) {
@@ -11567,7 +11673,7 @@ ${prefix}}`;
11567
11673
  }
11568
11674
  return stack;
11569
11675
  };
11570
- var FiberTypeId = `~effect/Fiber/${version}`;
11676
+ var FiberTypeId = "~effect/Fiber";
11571
11677
  var fiberVariance = {
11572
11678
  _A: identity,
11573
11679
  _E: identity
@@ -11583,7 +11689,6 @@ class FiberImpl {
11583
11689
  this.setContext(context);
11584
11690
  this.id = ++fiberIdStore.id;
11585
11691
  this.currentOpCount = 0;
11586
- this.currentLoopCount = 0;
11587
11692
  this.interruptible = interruptible;
11588
11693
  this._stack = [];
11589
11694
  this._observers = [];
@@ -11591,20 +11696,22 @@ class FiberImpl {
11591
11696
  this._children = undefined;
11592
11697
  this._interruptedCause = undefined;
11593
11698
  this._yielded = undefined;
11699
+ this._running = false;
11700
+ this._deferredInterrupt = false;
11594
11701
  this.runtimeMetrics?.recordFiberStart(this.context);
11595
11702
  }
11596
11703
  [FiberTypeId];
11597
11704
  id;
11598
11705
  interruptible;
11599
11706
  currentOpCount;
11600
- currentLoopCount;
11601
11707
  _stack;
11602
11708
  _observers;
11603
11709
  _exit;
11604
- _currentExit;
11605
11710
  _children;
11606
11711
  _interruptedCause;
11607
11712
  _yielded;
11713
+ _running;
11714
+ _deferredInterrupt;
11608
11715
  context;
11609
11716
  currentScheduler;
11610
11717
  currentTracerContext;
@@ -11620,7 +11727,7 @@ class FiberImpl {
11620
11727
  return this._dispatcher ??= this.currentScheduler.makeDispatcher();
11621
11728
  }
11622
11729
  getRef(ref) {
11623
- return getReferenceUnsafe(this.context, ref);
11730
+ return get(this.context, ref);
11624
11731
  }
11625
11732
  addObserver(cb) {
11626
11733
  if (this._exit) {
@@ -11648,7 +11755,11 @@ class FiberImpl {
11648
11755
  }
11649
11756
  this._interruptedCause = this._interruptedCause ? causeCombine(this._interruptedCause, cause) : cause;
11650
11757
  if (this.interruptible) {
11651
- this.evaluate(failCause(this._interruptedCause));
11758
+ if (this._running) {
11759
+ this._deferredInterrupt = true;
11760
+ } else {
11761
+ this.evaluate(failCause(this._interruptedCause));
11762
+ }
11652
11763
  }
11653
11764
  }
11654
11765
  pollUnsafe() {
@@ -11676,16 +11787,24 @@ class FiberImpl {
11676
11787
  this._observers[i](exit);
11677
11788
  }
11678
11789
  this._observers.length = 0;
11790
+ this._stack.length = 0;
11791
+ this._children = undefined;
11792
+ this.context = empty2();
11679
11793
  }
11680
11794
  runLoop(effect) {
11681
11795
  const prevFiber = globalThis[currentFiberTypeId];
11682
11796
  globalThis[currentFiberTypeId] = this;
11797
+ const prevRunning = this._running;
11798
+ this._running = true;
11683
11799
  let yielding = false;
11684
11800
  let current = effect;
11685
11801
  this.currentOpCount = 0;
11686
- const currentLoop = ++this.currentLoopCount;
11687
11802
  try {
11688
11803
  while (true) {
11804
+ if (this._deferredInterrupt) {
11805
+ this._deferredInterrupt = false;
11806
+ current = failCause(this._interruptedCause);
11807
+ }
11689
11808
  this.currentOpCount++;
11690
11809
  if (!yielding && !this.currentPreventYield && this.currentScheduler.shouldYield(this)) {
11691
11810
  yielding = true;
@@ -11693,13 +11812,16 @@ class FiberImpl {
11693
11812
  current = flatMap3(yieldNow, () => prev);
11694
11813
  }
11695
11814
  current = this.currentTracerContext ? this.currentTracerContext(current, this) : current[evaluate](this);
11696
- if (currentLoop !== this.currentLoopCount) {
11697
- return Yield;
11698
- } else if (current === Yield) {
11815
+ if (current === Yield) {
11699
11816
  const yielded = this._yielded;
11700
11817
  if (ExitTypeId in yielded) {
11818
+ this._deferredInterrupt = false;
11701
11819
  this._yielded = undefined;
11702
11820
  return yielded;
11821
+ } else if (this._deferredInterrupt) {
11822
+ this._yielded = undefined;
11823
+ yielded();
11824
+ continue;
11703
11825
  }
11704
11826
  return Yield;
11705
11827
  }
@@ -11710,10 +11832,15 @@ class FiberImpl {
11710
11832
  }
11711
11833
  return this.runLoop(exitDie(error));
11712
11834
  } finally {
11835
+ this._running = prevRunning;
11713
11836
  globalThis[currentFiberTypeId] = prevFiber;
11714
11837
  }
11715
11838
  }
11716
11839
  getCont(symbol3) {
11840
+ if (this._deferredInterrupt) {
11841
+ this._deferredInterrupt = false;
11842
+ return deferredInterruptCont;
11843
+ }
11717
11844
  while (true) {
11718
11845
  const op = this._stack.pop();
11719
11846
  if (!op)
@@ -11738,26 +11865,37 @@ class FiberImpl {
11738
11865
  return pipeArguments(this, arguments);
11739
11866
  }
11740
11867
  setContext(context) {
11868
+ const previous = this.context;
11741
11869
  this.context = context;
11870
+ if (previous !== undefined && hasSameCache(previous, context))
11871
+ return;
11742
11872
  const scheduler = this.getRef(Scheduler);
11743
11873
  if (scheduler !== this.currentScheduler) {
11744
11874
  this.currentScheduler = scheduler;
11745
11875
  this._dispatcher = undefined;
11746
11876
  }
11747
- this.currentSpan = context.mapUnsafe.get(ParentSpanKey);
11877
+ this.currentSpan = getOrUndefinedUnsafe(context, ParentSpanKey);
11748
11878
  this.currentLogLevel = this.getRef(CurrentLogLevel);
11749
11879
  this.minimumLogLevel = this.getRef(MinimumLogLevel);
11750
- this.currentStackFrame = context.mapUnsafe.get(CurrentStackFrame.key);
11880
+ this.currentStackFrame = this.getRef(CurrentStackFrame);
11751
11881
  this.maxOpsBeforeYield = this.getRef(MaxOpsBeforeYield);
11752
11882
  this.currentPreventYield = this.getRef(PreventSchedulerYield);
11753
- this.runtimeMetrics = context.mapUnsafe.get(FiberRuntimeMetricsKey);
11754
- const currentTracer = context.mapUnsafe.get(TracerKey);
11883
+ this.runtimeMetrics = getOrUndefinedUnsafe(context, FiberRuntimeMetricsKey);
11884
+ const currentTracer = getOrUndefinedUnsafe(context, TracerKey);
11755
11885
  this.currentTracerContext = currentTracer ? currentTracer["context"] : undefined;
11756
11886
  }
11757
11887
  get currentSpanLocal() {
11758
11888
  return this.currentSpan?._tag === "Span" ? this.currentSpan : undefined;
11759
11889
  }
11760
11890
  }
11891
+ var deferredInterruptCont = {
11892
+ [contA](_value, fiber) {
11893
+ return failCause(fiber._interruptedCause);
11894
+ },
11895
+ [contE](_cause, fiber) {
11896
+ return failCause(fiber._interruptedCause);
11897
+ }
11898
+ };
11761
11899
  var fiberMiddleware = {
11762
11900
  interruptChildren: undefined
11763
11901
  };
@@ -11765,7 +11903,7 @@ var fiberStackAnnotations = (fiber) => {
11765
11903
  if (!fiber.currentStackFrame)
11766
11904
  return;
11767
11905
  const annotations = new Map;
11768
- annotations.set(StackTraceKey.key, fiber.currentStackFrame);
11906
+ annotations.set(InterruptorStackTrace.key, fiber.currentStackFrame);
11769
11907
  return makeUnsafe(annotations);
11770
11908
  };
11771
11909
  var fiberInterruptChildren = (fiber) => {
@@ -11841,6 +11979,10 @@ var fiberJoinAll = (self) => callback((resume) => {
11841
11979
  }
11842
11980
  }));
11843
11981
  }
11982
+ return sync(() => {
11983
+ failed = true;
11984
+ cancels.forEach((cancel) => cancel());
11985
+ });
11844
11986
  });
11845
11987
  var fiberInterrupt = (self) => withFiber((fiber) => fiberInterruptAs(self, fiber.id));
11846
11988
  var fiberInterruptAs = /* @__PURE__ */ dual((args2) => hasProperty(args2[0], FiberTypeId), (self, fiberId, annotations) => withFiber((parent) => {
@@ -11851,10 +11993,12 @@ var fiberInterruptAs = /* @__PURE__ */ dual((args2) => hasProperty(args2[0], Fib
11851
11993
  }));
11852
11994
  var fiberInterruptAll = (fibers) => withFiber((parent) => {
11853
11995
  const annotations = fiberStackAnnotations(parent);
11996
+ let fiberArr = empty();
11854
11997
  for (const fiber of fibers) {
11855
11998
  fiber.interruptUnsafe(parent.id, annotations);
11999
+ fiberArr.push(fiber);
11856
12000
  }
11857
- return asVoid2(fiberAwaitAll(fibers));
12001
+ return asVoid2(fiberAwaitAll(fiberArr));
11858
12002
  });
11859
12003
  var succeed3 = exitSucceed;
11860
12004
  var failCause = exitFailCause;
@@ -12215,7 +12359,7 @@ var flatMapEager = /* @__PURE__ */ dual(2, (self, f) => {
12215
12359
  }
12216
12360
  return flatMap3(self, f);
12217
12361
  });
12218
- var flatten3 = (self) => flatMap3(self, identity);
12362
+ var flatten4 = (self) => flatMap3(self, identity);
12219
12363
  var map4 = /* @__PURE__ */ dual(2, (self, f) => flatMap3(self, (a) => succeed3(internalCall(() => f(a)))));
12220
12364
  var mapEager = /* @__PURE__ */ dual(2, (self, f) => effectIsExit(self) ? exitMap(self, f) : map4(self, f));
12221
12365
  var mapErrorEager = /* @__PURE__ */ dual(2, (self, f) => effectIsExit(self) ? exitMapError(self, f) : mapError2(self, f));
@@ -12254,6 +12398,7 @@ var exitMapBoth = /* @__PURE__ */ dual(2, (self, options) => {
12254
12398
  return exitFail(options.onFailure(error.success));
12255
12399
  });
12256
12400
  var exitZipRight = /* @__PURE__ */ dual(2, (self, that) => exitIsSuccess(self) ? that : self);
12401
+ var exitMatch = /* @__PURE__ */ dual(2, (self, options) => exitIsSuccess(self) ? options.onSuccess(self.value) : options.onFailure(self.cause));
12257
12402
  var exitAsVoidAll = (exits) => {
12258
12403
  const failures = [];
12259
12404
  for (const exit of exits) {
@@ -12284,6 +12429,24 @@ var updateService = /* @__PURE__ */ dual(3, (self, service2, f) => updateContext
12284
12429
  return s;
12285
12430
  return add(s, service2, next);
12286
12431
  }));
12432
+ var updateServiceScoped = (service2, update, options) => uninterruptible(withFiber((fiber2) => {
12433
+ const original = getUnsafe2(fiber2.context, service2);
12434
+ const updated = update(original);
12435
+ fiber2.setContext(add(fiber2.context, service2, updated));
12436
+ return scopeAddFinalizerExit(getUnsafe2(fiber2.context, scopeTag), (_) => {
12437
+ const current = getUnsafe2(fiber2.context, service2);
12438
+ let next;
12439
+ if (options?.reset === undefined) {
12440
+ if (current !== updated)
12441
+ return void_3;
12442
+ next = original;
12443
+ } else {
12444
+ next = options.reset(original, updated, current);
12445
+ }
12446
+ fiber2.setContext(add(fiber2.context, service2, next));
12447
+ return void_3;
12448
+ });
12449
+ }));
12287
12450
  var context = () => getContext;
12288
12451
  var getContext = /* @__PURE__ */ withFiber((fiber2) => succeed3(fiber2.context));
12289
12452
  var contextWith = (f) => withFiber((fiber2) => f(fiber2.context));
@@ -12306,7 +12469,6 @@ var provideServiceImpl = (self, service2, implementation) => updateContext(self,
12306
12469
  return add(s, service2, implementation);
12307
12470
  });
12308
12471
  var provideServiceEffect = /* @__PURE__ */ dual(3, (self, service2, acquire) => flatMap3(acquire, (implementation) => provideService(self, service2, implementation)));
12309
- var withConcurrency = /* @__PURE__ */ provideService(CurrentConcurrency);
12310
12472
  var zip = /* @__PURE__ */ dual((args2) => isEffect(args2[1]), (self, that, options) => zipWith2(self, that, (a, a2) => [a, a2], options));
12311
12473
  var zipWith2 = /* @__PURE__ */ dual((args2) => isEffect(args2[1]), (self, that, f, options) => options?.concurrent ? map4(all3([self, that], {
12312
12474
  concurrency: 2
@@ -12556,8 +12718,8 @@ var timeout = /* @__PURE__ */ dual(2, (self, duration) => timeoutOrElse(self, {
12556
12718
  }));
12557
12719
  var timeoutOption = /* @__PURE__ */ dual(2, (self, duration) => raceFirst(asSome(self), as2(sleep(duration), none2())));
12558
12720
  var timed = (self) => clockWith((clock) => {
12559
- const start = clock.currentTimeNanosUnsafe();
12560
- return map4(self, (a) => [nanos(clock.currentTimeNanosUnsafe() - start), a]);
12721
+ const start = clock.monotonicTimeNanosUnsafe();
12722
+ return map4(self, (a) => [nanos(clock.monotonicTimeNanosUnsafe() - start), a]);
12561
12723
  });
12562
12724
  var ScopeTypeId = "~effect/Scope";
12563
12725
  var ScopeCloseableTypeId = "~effect/Scope/Closeable";
@@ -12767,14 +12929,16 @@ var setInterruptible = /* @__PURE__ */ makePrimitive({
12767
12929
  });
12768
12930
  var setInterruptibleTrue = /* @__PURE__ */ setInterruptible(true);
12769
12931
  var setInterruptibleFalse = /* @__PURE__ */ setInterruptible(false);
12770
- var interruptible = (self) => withFiber((fiber2) => {
12771
- if (fiber2.interruptible)
12772
- return self;
12932
+ var setFiberInterruptible = (fiber2) => {
12773
12933
  fiber2.interruptible = true;
12774
12934
  fiber2._stack.push(setInterruptibleFalse);
12775
12935
  if (fiber2._interruptedCause)
12776
12936
  return failCause(fiber2._interruptedCause);
12777
- return self;
12937
+ };
12938
+ var interruptible = (self) => withFiber((fiber2) => {
12939
+ if (fiber2.interruptible)
12940
+ return self;
12941
+ return setFiberInterruptible(fiber2) ?? self;
12778
12942
  });
12779
12943
  var uninterruptibleMask = (f) => withFiber((fiber2) => {
12780
12944
  if (!fiber2.interruptible)
@@ -12786,9 +12950,9 @@ var uninterruptibleMask = (f) => withFiber((fiber2) => {
12786
12950
  var interruptibleMask = (f) => withFiber((fiber2) => {
12787
12951
  if (fiber2.interruptible)
12788
12952
  return f(identity);
12789
- fiber2.interruptible = true;
12790
- fiber2._stack.push(setInterruptibleFalse);
12791
- return f(uninterruptible);
12953
+ const interrupted = setFiberInterruptible(fiber2);
12954
+ const effect = f(uninterruptible);
12955
+ return interrupted ?? effect;
12792
12956
  });
12793
12957
  var abortSignal = /* @__PURE__ */ map4(/* @__PURE__ */ acquireRelease(/* @__PURE__ */ sync(() => new AbortController), (controller) => sync(() => controller.abort())), (_) => _.signal);
12794
12958
  var all3 = (arg, options) => {
@@ -12800,7 +12964,7 @@ var all3 = (arg, options) => {
12800
12964
  return suspend(() => {
12801
12965
  const out = {};
12802
12966
  return as2(forEach(Object.entries(arg), ([key, effect]) => map4(options?.mode === "result" ? result(effect) : effect, (value) => {
12803
- out[key] = value;
12967
+ assignProperty(out, key, value);
12804
12968
  }), {
12805
12969
  discard: true,
12806
12970
  concurrency: options?.concurrency
@@ -12808,6 +12972,23 @@ var all3 = (arg, options) => {
12808
12972
  });
12809
12973
  };
12810
12974
  var partition2 = /* @__PURE__ */ dual((args2) => isIterable(args2[0]) && !isEffect(args2[0]), (elements, f, options) => map4(forEach(elements, (a, i) => result(f(a, i)), options), (results) => partition(results, identity)));
12975
+ var reduce = /* @__PURE__ */ dual(3, (elements, zero2, f) => {
12976
+ const arr = fromIterable2(elements);
12977
+ if (arr.length === 0)
12978
+ return sync(zero2);
12979
+ return suspend(() => {
12980
+ let index = 0;
12981
+ let state = zero2();
12982
+ return map4(whileLoop({
12983
+ while: () => index < arr.length,
12984
+ body: () => f(state, arr[index], index),
12985
+ step(next) {
12986
+ state = next;
12987
+ index++;
12988
+ }
12989
+ }), () => state);
12990
+ });
12991
+ });
12811
12992
  var validate = /* @__PURE__ */ dual((args2) => isIterable(args2[0]) && !isEffect(args2[0]), (elements, f, options) => flatMap3(partition2(elements, f, {
12812
12993
  concurrency: options?.concurrency
12813
12994
  }), ([excluded, satisfying]) => {
@@ -12870,8 +13051,8 @@ var whileLoop = /* @__PURE__ */ makePrimitive({
12870
13051
  return exitVoid;
12871
13052
  }
12872
13053
  });
12873
- var forEach = /* @__PURE__ */ dual((args2) => typeof args2[1] === "function", (iterable, f, options) => withFiber((parent) => {
12874
- const concurrencyOption = options?.concurrency === "inherit" ? parent.getRef(CurrentConcurrency) : options?.concurrency ?? 1;
13054
+ var forEach = /* @__PURE__ */ dual((args2) => typeof args2[1] === "function", (iterable, f, options) => suspend(() => {
13055
+ const concurrencyOption = options?.concurrency ?? 1;
12875
13056
  const concurrency = concurrencyOption === "unbounded" ? Number.POSITIVE_INFINITY : Math.max(1, concurrencyOption);
12876
13057
  if (concurrency === 1) {
12877
13058
  return forEachSequential(iterable, f, options);
@@ -12908,10 +13089,25 @@ var forEachSequential = (iterable, f, options) => suspend(() => {
12908
13089
  var iterateEagerImpl = (options) => {
12909
13090
  const onItem = options.onItem;
12910
13091
  const step = options.step;
13092
+ const runSequential = (state, items, index, end) => {
13093
+ for (;index < end; index++) {
13094
+ const item = items[index];
13095
+ const effect = onItem(state, item, index);
13096
+ if (!effectIsExit(effect)) {
13097
+ return flatMap3(exit(effect), (itemExit) => step(state, item, itemExit, index) ?? runSequential(state, items, index + 1, end) ?? void_3);
13098
+ }
13099
+ const terminal = step(state, item, effect, index);
13100
+ if (terminal)
13101
+ return terminal._tag === "Failure" ? terminal : undefined;
13102
+ }
13103
+ };
12911
13104
  return (state, items, opts) => {
12912
- let index = opts?.start ?? 0;
13105
+ let index = 0;
12913
13106
  const end = opts?.end ?? items.length;
12914
13107
  const concurrency = opts?.concurrency ?? 1;
13108
+ if (concurrency === 1) {
13109
+ return runSequential(state, items, 0, end);
13110
+ }
12915
13111
  const orderedStep = opts?.orderedStep === true && concurrency > 1;
12916
13112
  let done2 = false;
12917
13113
  let parentFiber;
@@ -12922,6 +13118,13 @@ var iterateEagerImpl = (options) => {
12922
13118
  let effect;
12923
13119
  let nextIndex = index;
12924
13120
  const exits = orderedStep ? new Array(end) : undefined;
13121
+ const failDefect = (error) => {
13122
+ const defect = exitDie(error);
13123
+ terminal = defect;
13124
+ done2 = true;
13125
+ interrupted = true;
13126
+ return fibers && fibers.size > 0 ? flatMap3(uninterruptible(fiberInterruptAll(Array.from(fibers))), () => defect) : defect;
13127
+ };
12925
13128
  const runStep = (item, exit2, currentIndex) => {
12926
13129
  if (!orderedStep)
12927
13130
  return step(state, item, exit2, currentIndex);
@@ -12948,18 +13151,18 @@ var iterateEagerImpl = (options) => {
12948
13151
  terminal = runStep(item, eff, index);
12949
13152
  if (terminal)
12950
13153
  break;
12951
- } else if (concurrency === 1) {
12952
- return flatMap3(exit(eff), (exit2) => {
12953
- terminal = runStep(item, exit2, index);
12954
- index++;
12955
- return terminal ?? go() ?? void_3;
12956
- });
12957
13154
  } else if (!parentFiber) {
12958
13155
  return callback((cb) => {
12959
13156
  parentFiber = getCurrentFiber();
13157
+ fibers = new Set;
12960
13158
  effect = eff;
12961
13159
  resume = cb;
12962
- const result2 = go();
13160
+ let result2;
13161
+ try {
13162
+ result2 = go();
13163
+ } catch (error) {
13164
+ return cb(failDefect(error));
13165
+ }
12963
13166
  if (result2)
12964
13167
  return cb(result2);
12965
13168
  return suspend(() => {
@@ -12977,38 +13180,39 @@ var iterateEagerImpl = (options) => {
12977
13180
  break;
12978
13181
  continue;
12979
13182
  }
12980
- if (fibers)
12981
- fibers.add(fiber2);
12982
- else
12983
- fibers = new Set([fiber2]);
13183
+ fibers.add(fiber2);
12984
13184
  const currentIndex = index;
12985
13185
  fiber2.addObserver((exit2) => {
12986
13186
  fibers.delete(fiber2);
12987
- if (terminal) {
12988
- if (!interrupted && exit2._tag === "Failure") {
12989
- for (const reason of exit2.cause.reasons) {
12990
- if (reason._tag === "Interrupt")
12991
- continue;
12992
- else if (terminal._tag === "Failure") {
12993
- terminal.cause.reasons.push(reason);
12994
- } else {
12995
- terminal = exitFailCause(causeFromReasons([reason]));
13187
+ try {
13188
+ if (terminal) {
13189
+ if (!interrupted && exit2._tag === "Failure") {
13190
+ for (const reason of exit2.cause.reasons) {
13191
+ if (reason._tag === "Interrupt")
13192
+ continue;
13193
+ else if (terminal._tag === "Failure") {
13194
+ terminal.cause.reasons.push(reason);
13195
+ } else {
13196
+ terminal = exitFailCause(causeFromReasons([reason]));
13197
+ }
12996
13198
  }
12997
13199
  }
13200
+ } else {
13201
+ const result2 = runStep(item, exit2, currentIndex);
13202
+ if (result2) {
13203
+ terminal = result2._tag === "Failure" ? exitFailCause(causeFromReasons(result2.cause.reasons.slice())) : result2;
13204
+ go();
13205
+ }
12998
13206
  }
12999
- } else {
13000
- const result2 = runStep(item, exit2, currentIndex);
13001
- if (result2) {
13002
- terminal = result2._tag === "Failure" ? exitFailCause(causeFromReasons(result2.cause.reasons.slice())) : result2;
13003
- go();
13207
+ if (paused) {
13208
+ const eff2 = go();
13209
+ if (eff2)
13210
+ resume(eff2);
13211
+ } else if (done2 && fibers.size === 0) {
13212
+ resume(terminal ?? void_3);
13004
13213
  }
13005
- }
13006
- if (paused) {
13007
- const eff2 = go();
13008
- if (eff2)
13009
- resume(eff2);
13010
- } else if (done2 && fibers.size === 0) {
13011
- resume(terminal ?? void_3);
13214
+ } catch (error) {
13215
+ resume(failDefect(error));
13012
13216
  }
13013
13217
  });
13014
13218
  if (fibers.size < concurrency)
@@ -13106,28 +13310,29 @@ var forkChild = /* @__PURE__ */ dual((args2) => isEffect(args2[0]), (self, optio
13106
13310
  return succeed3(forkUnsafe(fiber2, self, options?.startImmediately, false, options?.uninterruptible ?? false));
13107
13311
  }));
13108
13312
  var forkUnsafe = (parent, effect, immediate = false, daemon = false, uninterruptible2 = false) => {
13109
- const interruptible2 = uninterruptible2 === "inherit" ? parent.interruptible : !uninterruptible2;
13110
- const child = new FiberImpl(parent.context, interruptible2);
13313
+ const parentRuntime = parent;
13314
+ const interruptible2 = uninterruptible2 === "inherit" ? parentRuntime.interruptible : !uninterruptible2;
13315
+ const child = new FiberImpl(parentRuntime.context, interruptible2);
13111
13316
  if (immediate) {
13112
13317
  child.evaluate(effect);
13113
13318
  } else {
13114
- parent.currentDispatcher.scheduleTask(() => child.evaluate(effect), 0);
13319
+ parentRuntime.currentDispatcher.scheduleTask(() => child.evaluate(effect), 0);
13115
13320
  }
13116
13321
  if (!daemon && !child._exit) {
13117
- parent.children().add(child);
13118
- child.addObserver(() => parent._children.delete(child));
13322
+ parentRuntime.children().add(child);
13323
+ child.addObserver(() => parentRuntime._children.delete(child));
13119
13324
  }
13120
13325
  return child;
13121
13326
  };
13122
13327
  var forkDetach = /* @__PURE__ */ dual((args2) => isEffect(args2[0]), (self, options) => withFiber((fiber2) => succeed3(forkUnsafe(fiber2, self, options?.startImmediately, true, options?.uninterruptible))));
13123
13328
  var awaitAllChildren = (self) => withFiber((fiber2) => {
13124
- const initialChildren = fiber2._children && fromIterable2(fiber2._children);
13329
+ const initialChildren = fiber2._children && new Set(fiber2._children);
13125
13330
  return onExit(self, (_) => {
13126
13331
  let children = fiber2._children;
13127
13332
  if (children === undefined || children.size === 0) {
13128
13333
  return void_3;
13129
13334
  } else if (initialChildren) {
13130
- children = filter2(children, (child) => !initialChildren.includes(child));
13335
+ children = filter2(children, (child) => !initialChildren.has(child));
13131
13336
  }
13132
13337
  return asVoid2(fiberAwaitAll(children));
13133
13338
  });
@@ -13223,7 +13428,7 @@ var runSyncExitWith = (context2) => {
13223
13428
  const fiber2 = runFork2(effect, {
13224
13429
  scheduler
13225
13430
  });
13226
- fiber2.currentDispatcher?.flush();
13431
+ fiber2._dispatcher?.flush();
13227
13432
  return fiber2._exit ?? exitDie(new AsyncFiberError(fiber2));
13228
13433
  };
13229
13434
  };
@@ -13243,27 +13448,43 @@ var succeedFalse = /* @__PURE__ */ succeed3(false);
13243
13448
 
13244
13449
  class Latch {
13245
13450
  waiters = [];
13246
- scheduled = false;
13451
+ scheduled = undefined;
13247
13452
  _isOpen;
13248
13453
  constructor(isOpen) {
13249
13454
  this._isOpen = isOpen;
13250
13455
  }
13251
13456
  scheduleUnsafe(fiber2) {
13252
- if (this.scheduled || this.waiters.length === 0) {
13457
+ if (this.waiters.length === 0) {
13253
13458
  return succeedTrue;
13254
13459
  }
13255
- this.scheduled = true;
13256
- fiber2.currentDispatcher.scheduleTask(this.flushWaiters, 0);
13460
+ if (this.scheduled === undefined) {
13461
+ this.scheduled = this.waiters;
13462
+ fiber2.currentDispatcher.scheduleTask(this.flushScheduled, 0);
13463
+ } else {
13464
+ for (let i = 0;i < this.waiters.length; i++) {
13465
+ this.scheduled.push(this.waiters[i]);
13466
+ }
13467
+ }
13468
+ this.waiters = [];
13257
13469
  return succeedTrue;
13258
13470
  }
13259
- flushWaiters = () => {
13260
- this.scheduled = false;
13471
+ flushScheduled = () => {
13472
+ if (this.scheduled === undefined)
13473
+ return;
13474
+ const waiters = this.scheduled;
13475
+ this.scheduled = undefined;
13476
+ for (let i = 0;i < waiters.length; i++) {
13477
+ waiters[i](exitVoid);
13478
+ }
13479
+ };
13480
+ flushWaiters() {
13261
13481
  const waiters = this.waiters;
13262
13482
  this.waiters = [];
13483
+ this.flushScheduled();
13263
13484
  for (let i = 0;i < waiters.length; i++) {
13264
13485
  waiters[i](exitVoid);
13265
13486
  }
13266
- };
13487
+ }
13267
13488
  open = /* @__PURE__ */ withFiber((fiber2) => {
13268
13489
  if (this._isOpen)
13269
13490
  return succeedFalse;
@@ -13284,9 +13505,14 @@ class Latch {
13284
13505
  }
13285
13506
  this.waiters.push(resume);
13286
13507
  return sync(() => {
13287
- const index = this.waiters.indexOf(resume);
13508
+ let index = this.waiters.indexOf(resume);
13288
13509
  if (index !== -1) {
13289
13510
  this.waiters.splice(index, 1);
13511
+ } else if (this.scheduled !== undefined) {
13512
+ index = this.scheduled.indexOf(resume);
13513
+ if (index !== -1) {
13514
+ this.scheduled.splice(index, 1);
13515
+ }
13290
13516
  }
13291
13517
  });
13292
13518
  });
@@ -13420,11 +13646,8 @@ var useSpan = (name, ...args2) => {
13420
13646
  return withFiber((fiber2) => {
13421
13647
  const span = makeSpanUnsafe(fiber2, name, options);
13422
13648
  const clock = fiber2.getRef(ClockRef);
13423
- return onExit(internalCall(() => evaluate2(span)), (exit2) => sync(() => {
13424
- if (span.status._tag === "Ended")
13425
- return;
13426
- span.end(clock.currentTimeNanosUnsafe(), exit2);
13427
- }));
13649
+ const timingEnabled = fiber2.getRef(TracerTimingEnabled);
13650
+ return onExit(internalCall(() => evaluate2(span)), (exit2) => endSpan(span, exit2, clock, timingEnabled));
13428
13651
  });
13429
13652
  };
13430
13653
  var provideParentSpan = /* @__PURE__ */ provideService(ParentSpan);
@@ -13455,13 +13678,16 @@ var withSpan = function() {
13455
13678
  return (self, ...args2) => useSpan(name, fnArg ? fnArg(...args2) : options, (span) => withParentSpan(self, span, traceOptions));
13456
13679
  };
13457
13680
  var annotateSpans = /* @__PURE__ */ dual((args2) => isEffect(args2[0]), (effect, ...args2) => updateService(effect, TracerSpanAnnotations, (annotations) => {
13458
- const newAnnotations = {
13681
+ const newAnnotations = args2.length === 1 ? {
13682
+ ...annotations,
13683
+ ...args2[0]
13684
+ } : {
13459
13685
  ...annotations
13460
13686
  };
13461
13687
  if (args2.length === 1) {
13462
- Object.assign(newAnnotations, args2[0]);
13688
+ return newAnnotations;
13463
13689
  } else {
13464
- newAnnotations[args2[0]] = args2[1];
13690
+ assignProperty(newAnnotations, args2[0], args2[1]);
13465
13691
  }
13466
13692
  return newAnnotations;
13467
13693
  }));
@@ -13494,9 +13720,13 @@ class ClockImpl {
13494
13720
  }
13495
13721
  currentTimeMillis = /* @__PURE__ */ sync(() => this.currentTimeMillisUnsafe());
13496
13722
  currentTimeNanosUnsafe() {
13497
- return processOrPerformanceNow();
13723
+ return wallTimeNanos();
13498
13724
  }
13499
13725
  currentTimeNanos = /* @__PURE__ */ sync(() => this.currentTimeNanosUnsafe());
13726
+ monotonicTimeNanosUnsafe() {
13727
+ return monotonicNowNanos();
13728
+ }
13729
+ monotonicTimeNanos = /* @__PURE__ */ sync(() => this.monotonicTimeNanosUnsafe());
13500
13730
  sleep(duration) {
13501
13731
  return this.sleepMillis(toMillis(duration));
13502
13732
  }
@@ -13512,24 +13742,41 @@ class ClockImpl {
13512
13742
  });
13513
13743
  }
13514
13744
  }
13515
- var performanceNowNanos = /* @__PURE__ */ function() {
13516
- const bigint1e6 = /* @__PURE__ */ BigInt(1e6);
13517
- if (typeof performance === "undefined" || typeof performance.now === "undefined") {
13518
- return () => BigInt(Date.now()) * bigint1e6;
13745
+ var nanosPerMilli = /* @__PURE__ */ BigInt(1e6);
13746
+ var monotonicNowNanos = /* @__PURE__ */ function() {
13747
+ const processHrtime = globalThis.process?.hrtime;
13748
+ if (typeof processHrtime?.bigint === "function") {
13749
+ return () => processHrtime.bigint();
13519
13750
  }
13520
- let origin;
13751
+ if (typeof performance !== "undefined" && typeof performance.now === "function") {
13752
+ return () => BigInt(Math.round(performance.now() * 1e6));
13753
+ }
13754
+ let previous = /* @__PURE__ */ BigInt(0);
13521
13755
  return () => {
13522
- origin ??= BigInt(Date.now()) * bigint1e6 - BigInt(Math.round(performance.now() * 1e6));
13523
- return origin + BigInt(Math.round(performance.now() * 1e6));
13756
+ const current = BigInt(Date.now()) * nanosPerMilli;
13757
+ if (current > previous) {
13758
+ previous = current;
13759
+ }
13760
+ return previous;
13524
13761
  };
13525
13762
  }();
13526
- var processOrPerformanceNow = /* @__PURE__ */ function() {
13527
- const processHrtime = typeof process === "object" && "hrtime" in process && typeof process.hrtime.bigint === "function" ? process.hrtime : undefined;
13528
- if (!processHrtime) {
13529
- return performanceNowNanos;
13530
- }
13531
- const origin = /* @__PURE__ */ BigInt(/* @__PURE__ */ Date.now()) * /* @__PURE__ */ BigInt(1e6) - /* @__PURE__ */ processHrtime.bigint();
13532
- return () => origin + processHrtime.bigint();
13763
+ var wallTimeNanos = /* @__PURE__ */ function() {
13764
+ const reanchorThresholdNanos = /* @__PURE__ */ BigInt(1e9);
13765
+ let origin;
13766
+ return () => {
13767
+ const monotonic = monotonicNowNanos();
13768
+ const wall = BigInt(Date.now()) * nanosPerMilli;
13769
+ if (origin === undefined) {
13770
+ origin = wall - monotonic;
13771
+ } else {
13772
+ const projected = origin + monotonic;
13773
+ const skew = wall > projected ? wall - projected : projected - wall;
13774
+ if (skew > reanchorThresholdNanos) {
13775
+ origin = wall - monotonic;
13776
+ }
13777
+ }
13778
+ return origin + monotonic;
13779
+ };
13533
13780
  }();
13534
13781
  var clockWith = (f) => withFiber((fiber2) => f(fiber2.getRef(ClockRef)));
13535
13782
  var sleep = (duration) => clockWith((clock) => clock.sleep(fromInputUnsafe(duration)));
@@ -13612,7 +13859,7 @@ var annotateLogsScoped = function() {
13612
13859
  };
13613
13860
  for (let i = 0;i < entries.length; i++) {
13614
13861
  const [key, value] = entries[i];
13615
- next[key] = value;
13862
+ assignProperty(next, key, value);
13616
13863
  }
13617
13864
  fiber2.setContext(add(fiber2.context, CurrentLogAnnotations, next));
13618
13865
  return scopeAddFinalizerExit(getUnsafe2(fiber2.context, scopeTag), (_) => {
@@ -13624,8 +13871,8 @@ var annotateLogsScoped = function() {
13624
13871
  const [key, value] = entries[i];
13625
13872
  if (current[key] !== value)
13626
13873
  continue;
13627
- if (key in prev) {
13628
- next2[key] = prev[key];
13874
+ if (Object.hasOwn(prev, key)) {
13875
+ assignProperty(next2, key, prev[key]);
13629
13876
  } else {
13630
13877
  delete next2[key];
13631
13878
  }
@@ -13755,7 +14002,7 @@ var tracerLogger = /* @__PURE__ */ loggerMake(({
13755
14002
  return;
13756
14003
  const attributes = {};
13757
14004
  for (const [key, value] of Object.entries(annotations)) {
13758
- attributes[key] = value;
14005
+ assignProperty(attributes, key, value);
13759
14006
  }
13760
14007
  attributes["effect.fiberId"] = fiber2.id;
13761
14008
  attributes["effect.logLevel"] = logLevel.toUpperCase();
@@ -13786,7 +14033,7 @@ var reportCauseUnsafe = (fiber2, cause, defectsOnly) => {
13786
14033
  reporters.forEach((reporter) => reporter.report(opts));
13787
14034
  };
13788
14035
 
13789
- // ../../node_modules/.bun/effect@4.0.0-beta.98/node_modules/effect/dist/Deferred.js
14036
+ // ../../node_modules/.bun/effect@4.0.0-beta.107/node_modules/effect/dist/Deferred.js
13790
14037
  var TypeId5 = "~effect/Deferred";
13791
14038
  var DeferredProto = {
13792
14039
  [TypeId5]: {
@@ -13832,7 +14079,7 @@ var doneUnsafe = (self, effect) => {
13832
14079
  return true;
13833
14080
  };
13834
14081
 
13835
- // ../../node_modules/.bun/effect@4.0.0-beta.98/node_modules/effect/dist/Effect.js
14082
+ // ../../node_modules/.bun/effect@4.0.0-beta.107/node_modules/effect/dist/Effect.js
13836
14083
  var exports_Effect = {};
13837
14084
  __export(exports_Effect, {
13838
14085
  zipWith: () => zipWith3,
@@ -13850,12 +14097,12 @@ __export(exports_Effect, {
13850
14097
  withFiber: () => withFiber2,
13851
14098
  withExecutionPlan: () => withExecutionPlan2,
13852
14099
  withErrorReporting: () => withErrorReporting2,
13853
- withConcurrency: () => withConcurrency2,
13854
14100
  whileLoop: () => whileLoop2,
13855
14101
  when: () => when2,
13856
14102
  void: () => void_5,
13857
14103
  validate: () => validate2,
13858
14104
  useSpan: () => useSpan2,
14105
+ updateServiceScoped: () => updateServiceScoped2,
13859
14106
  updateService: () => updateService3,
13860
14107
  updateContext: () => updateContext2,
13861
14108
  unwrapReason: () => unwrapReason2,
@@ -13925,6 +14172,7 @@ __export(exports_Effect, {
13925
14172
  replicate: () => replicate2,
13926
14173
  repeatOrElse: () => repeatOrElse2,
13927
14174
  repeat: () => repeat3,
14175
+ reduce: () => reduce2,
13928
14176
  raceFirst: () => raceFirst2,
13929
14177
  raceAllFirst: () => raceAllFirst2,
13930
14178
  raceAll: () => raceAll2,
@@ -13953,7 +14201,7 @@ __export(exports_Effect, {
13953
14201
  matchCauseEffect: () => matchCauseEffect2,
13954
14202
  matchCauseEager: () => matchCauseEager2,
13955
14203
  matchCause: () => matchCause2,
13956
- match: () => match5,
14204
+ match: () => match6,
13957
14205
  mapErrorEager: () => mapErrorEager2,
13958
14206
  mapError: () => mapError3,
13959
14207
  mapEager: () => mapEager2,
@@ -13994,7 +14242,7 @@ __export(exports_Effect, {
13994
14242
  fnUntraced: () => fnUntraced2,
13995
14243
  fn: () => fn2,
13996
14244
  flip: () => flip3,
13997
- flatten: () => flatten4,
14245
+ flatten: () => flatten5,
13998
14246
  flatMapEager: () => flatMapEager2,
13999
14247
  flatMap: () => flatMap5,
14000
14248
  firstSuccessOf: () => firstSuccessOf2,
@@ -14017,7 +14265,7 @@ __export(exports_Effect, {
14017
14265
  eventually: () => eventually2,
14018
14266
  ensuring: () => ensuring2,
14019
14267
  effectify: () => effectify,
14020
- die: () => die3,
14268
+ die: () => die4,
14021
14269
  delay: () => delay2,
14022
14270
  currentSpan: () => currentSpan2,
14023
14271
  currentParentSpan: () => currentParentSpan2,
@@ -14063,17 +14311,19 @@ __export(exports_Effect, {
14063
14311
  Do: () => Do4
14064
14312
  });
14065
14313
 
14066
- // ../../node_modules/.bun/effect@4.0.0-beta.98/node_modules/effect/dist/Exit.js
14314
+ // ../../node_modules/.bun/effect@4.0.0-beta.107/node_modules/effect/dist/Exit.js
14067
14315
  var isExit2 = isExit;
14068
14316
  var succeed4 = exitSucceed;
14069
14317
  var failCause3 = exitFailCause;
14070
14318
  var fail4 = exitFail;
14319
+ var die2 = exitDie;
14071
14320
  var interrupt2 = exitInterrupt;
14072
14321
  var void_4 = exitVoid;
14073
14322
  var isSuccess4 = exitIsSuccess;
14074
14323
  var isFailure4 = exitIsFailure;
14324
+ var match5 = exitMatch;
14075
14325
 
14076
- // ../../node_modules/.bun/effect@4.0.0-beta.98/node_modules/effect/dist/Layer.js
14326
+ // ../../node_modules/.bun/effect@4.0.0-beta.107/node_modules/effect/dist/Layer.js
14077
14327
  var exports_Layer = {};
14078
14328
  __export(exports_Layer, {
14079
14329
  withSpan: () => withSpan2,
@@ -14122,13 +14372,13 @@ __export(exports_Layer, {
14122
14372
  CurrentMemoMap: () => CurrentMemoMap
14123
14373
  });
14124
14374
 
14125
- // ../../node_modules/.bun/effect@4.0.0-beta.98/node_modules/effect/dist/References.js
14375
+ // ../../node_modules/.bun/effect@4.0.0-beta.107/node_modules/effect/dist/References.js
14126
14376
  var CurrentLogAnnotations2 = CurrentLogAnnotations;
14127
14377
  var CurrentLogSpans2 = CurrentLogSpans;
14128
14378
  var CurrentStackFrame2 = CurrentStackFrame;
14129
14379
  var TracerTimingEnabled2 = TracerTimingEnabled;
14130
14380
 
14131
- // ../../node_modules/.bun/effect@4.0.0-beta.98/node_modules/effect/dist/Scope.js
14381
+ // ../../node_modules/.bun/effect@4.0.0-beta.107/node_modules/effect/dist/Scope.js
14132
14382
  var Scope = scopeTag;
14133
14383
  var makeUnsafe3 = scopeMakeUnsafe;
14134
14384
  var provide = provideScope;
@@ -14137,7 +14387,7 @@ var addFinalizer2 = scopeAddFinalizer;
14137
14387
  var forkUnsafe2 = scopeForkUnsafe;
14138
14388
  var close = scopeClose;
14139
14389
 
14140
- // ../../node_modules/.bun/effect@4.0.0-beta.98/node_modules/effect/dist/Layer.js
14390
+ // ../../node_modules/.bun/effect@4.0.0-beta.107/node_modules/effect/dist/Layer.js
14141
14391
  var TypeId6 = "~effect/Layer";
14142
14392
  var MemoMapTypeId = "~effect/Layer/MemoMap";
14143
14393
  var memoMapReuse = (entry, scope2) => {
@@ -14207,11 +14457,13 @@ class MemoMapImpl {
14207
14457
  return this.parent?.get(layer, scope2);
14208
14458
  }
14209
14459
  getOrElseMemoize(layer, scope2, build) {
14210
- const existing = this.get(layer, scope2);
14211
- if (existing) {
14212
- return existing;
14213
- }
14214
- return memoMapBuild(this, layer, scope2, build);
14460
+ return suspend(() => {
14461
+ const existing = this.get(layer, scope2);
14462
+ if (existing) {
14463
+ return existing;
14464
+ }
14465
+ return memoMapBuild(this, layer, scope2, build);
14466
+ });
14215
14467
  }
14216
14468
  }
14217
14469
  var makeMemoMapUnsafe = () => new MemoMapImpl;
@@ -14365,7 +14617,7 @@ var provideSpanStackFrame2 = (name, stack) => {
14365
14617
  }));
14366
14618
  };
14367
14619
 
14368
- // ../../node_modules/.bun/effect@4.0.0-beta.98/node_modules/effect/dist/ExecutionPlan.js
14620
+ // ../../node_modules/.bun/effect@4.0.0-beta.107/node_modules/effect/dist/ExecutionPlan.js
14369
14621
  var TypeId7 = "~effect/ExecutionPlan";
14370
14622
  var Proto2 = {
14371
14623
  [TypeId7]: TypeId7,
@@ -14392,9 +14644,9 @@ var CurrentMetadata = /* @__PURE__ */ Reference("effect/ExecutionPlan/CurrentMet
14392
14644
  })
14393
14645
  });
14394
14646
 
14395
- // ../../node_modules/.bun/effect@4.0.0-beta.98/node_modules/effect/dist/Cause.js
14647
+ // ../../node_modules/.bun/effect@4.0.0-beta.107/node_modules/effect/dist/Cause.js
14396
14648
  var fail5 = causeFail;
14397
- var die2 = causeDie;
14649
+ var die3 = causeDie;
14398
14650
  var hasInterruptsOnly2 = hasInterruptsOnly;
14399
14651
  var squash = causeSquash;
14400
14652
  var hasFails2 = hasFails;
@@ -14405,7 +14657,7 @@ var done3 = done;
14405
14657
  var ExceededCapacityError2 = ExceededCapacityError;
14406
14658
  var UnknownError2 = UnknownError;
14407
14659
 
14408
- // ../../node_modules/.bun/effect@4.0.0-beta.98/node_modules/effect/dist/Data.js
14660
+ // ../../node_modules/.bun/effect@4.0.0-beta.107/node_modules/effect/dist/Data.js
14409
14661
  var exports_Data = {};
14410
14662
  __export(exports_Data, {
14411
14663
  taggedEnum: () => taggedEnum,
@@ -14418,7 +14670,7 @@ var Class2 = class extends Class {
14418
14670
  constructor(props) {
14419
14671
  super();
14420
14672
  if (props) {
14421
- Object.assign(this, props);
14673
+ assignProperties(this, props);
14422
14674
  }
14423
14675
  }
14424
14676
  };
@@ -14452,21 +14704,21 @@ function taggedMatch() {
14452
14704
  var Error3 = Error2;
14453
14705
  var TaggedError2 = TaggedError;
14454
14706
 
14455
- // ../../node_modules/.bun/effect@4.0.0-beta.98/node_modules/effect/dist/Clock.js
14707
+ // ../../node_modules/.bun/effect@4.0.0-beta.107/node_modules/effect/dist/Clock.js
14456
14708
  var Clock = ClockRef;
14457
14709
 
14458
- // ../../node_modules/.bun/effect@4.0.0-beta.98/node_modules/effect/dist/Number.js
14710
+ // ../../node_modules/.bun/effect@4.0.0-beta.107/node_modules/effect/dist/Number.js
14459
14711
  var Number3 = globalThis.Number;
14460
14712
  var nextPow2 = (n) => {
14461
14713
  const nextPow = Math.ceil(Math.log(n) / Math.log(2));
14462
14714
  return Math.max(Math.pow(2, nextPow), 2);
14463
14715
  };
14464
14716
 
14465
- // ../../node_modules/.bun/effect@4.0.0-beta.98/node_modules/effect/dist/String.js
14717
+ // ../../node_modules/.bun/effect@4.0.0-beta.107/node_modules/effect/dist/String.js
14466
14718
  var String2 = globalThis.String;
14467
14719
  var isString2 = isString;
14468
14720
 
14469
- // ../../node_modules/.bun/effect@4.0.0-beta.98/node_modules/effect/dist/Pull.js
14721
+ // ../../node_modules/.bun/effect@4.0.0-beta.107/node_modules/effect/dist/Pull.js
14470
14722
  var catchDone = /* @__PURE__ */ dual(2, (effect2, f) => catchCauseFilter(effect2, filterDoneLeftover, (l) => f(l)));
14471
14723
  var isDoneCause = (cause) => cause.reasons.some(isDoneFailure);
14472
14724
  var isDoneFailure = (failure) => failure._tag === "Fail" && isDone3(failure.error);
@@ -14484,7 +14736,7 @@ var matchEffect2 = /* @__PURE__ */ dual(2, (self, options) => matchCauseEffect(s
14484
14736
  }
14485
14737
  }));
14486
14738
 
14487
- // ../../node_modules/.bun/effect@4.0.0-beta.98/node_modules/effect/dist/Schedule.js
14739
+ // ../../node_modules/.bun/effect@4.0.0-beta.107/node_modules/effect/dist/Schedule.js
14488
14740
  var TypeId8 = "~effect/Schedule";
14489
14741
  var CurrentMetadata2 = /* @__PURE__ */ Reference("effect/Schedule/CurrentMetadata", {
14490
14742
  defaultValue: /* @__PURE__ */ constant({
@@ -14578,11 +14830,11 @@ var while_ = /* @__PURE__ */ dual(2, (self, predicate) => fromStep(map4(toStep(s
14578
14830
  })));
14579
14831
  var forever3 = /* @__PURE__ */ spaced(zero);
14580
14832
 
14581
- // ../../node_modules/.bun/effect@4.0.0-beta.98/node_modules/effect/dist/internal/layer.js
14833
+ // ../../node_modules/.bun/effect@4.0.0-beta.107/node_modules/effect/dist/internal/layer.js
14582
14834
  var provideLayer = (self, layer, options) => scopedWith((scope2) => flatMap3(options?.local ? buildWithMemoMap(layer, makeMemoMapUnsafe(), scope2) : buildWithScope(layer, scope2), (context2) => provideContext(self, context2)));
14583
14835
  var provide3 = /* @__PURE__ */ dual((args2) => isEffect(args2[0]), (self, source, options) => isContext(source) ? provideContext(self, source) : provideLayer(self, Array.isArray(source) ? mergeAll2(...source) : source, options));
14584
14836
 
14585
- // ../../node_modules/.bun/effect@4.0.0-beta.98/node_modules/effect/dist/internal/schedule.js
14837
+ // ../../node_modules/.bun/effect@4.0.0-beta.107/node_modules/effect/dist/internal/schedule.js
14586
14838
  var repeatOrElse = /* @__PURE__ */ dual(3, (self, schedule, orElse3) => flatMap3(toStepWithMetadata(schedule), (step) => {
14587
14839
  let meta = CurrentMetadata2.defaultValue();
14588
14840
  return catch_(forever2(tap3(flatMap3(suspend(() => provideService(self, CurrentMetadata2, meta)), step), (meta_) => sync(() => {
@@ -14653,8 +14905,52 @@ var buildFromOptions = (options) => {
14653
14905
  return schedule;
14654
14906
  };
14655
14907
 
14656
- // ../../node_modules/.bun/effect@4.0.0-beta.98/node_modules/effect/dist/internal/executionPlan.js
14657
- var withExecutionPlan = /* @__PURE__ */ dual(2, (self, plan) => suspend(() => {
14908
+ // ../../node_modules/.bun/effect@4.0.0-beta.107/node_modules/effect/dist/internal/executionPlan.js
14909
+ var makeEventEmitter = (onEvent, currentMetadata) => {
14910
+ let lastStepIndex = -1;
14911
+ let stepAttempt = 0;
14912
+ const emit = (event) => ignoreCause(onEvent(event));
14913
+ return {
14914
+ begin: clockWith((clock) => suspend(() => {
14915
+ const meta = currentMetadata();
14916
+ if (meta.stepIndex !== lastStepIndex) {
14917
+ lastStepIndex = meta.stepIndex;
14918
+ stepAttempt = 0;
14919
+ }
14920
+ stepAttempt++;
14921
+ const state = {
14922
+ attempt: meta.attempt,
14923
+ stepAttempt,
14924
+ stepIndex: meta.stepIndex,
14925
+ startNanos: clock.monotonicTimeNanosUnsafe()
14926
+ };
14927
+ return as2(emit({
14928
+ _tag: "AttemptStart",
14929
+ attempt: state.attempt,
14930
+ stepAttempt: state.stepAttempt,
14931
+ stepIndex: state.stepIndex
14932
+ }), state);
14933
+ })),
14934
+ end: (state, exit2) => clockWith((clock) => {
14935
+ const duration = nanos(clock.monotonicTimeNanosUnsafe() - state.startNanos);
14936
+ return emit(exit2._tag === "Success" ? {
14937
+ _tag: "AttemptSuccess",
14938
+ attempt: state.attempt,
14939
+ stepAttempt: state.stepAttempt,
14940
+ stepIndex: state.stepIndex,
14941
+ duration
14942
+ } : {
14943
+ _tag: "AttemptFailure",
14944
+ attempt: state.attempt,
14945
+ stepAttempt: state.stepAttempt,
14946
+ stepIndex: state.stepIndex,
14947
+ duration,
14948
+ cause: exit2.cause
14949
+ });
14950
+ })
14951
+ };
14952
+ };
14953
+ var withExecutionPlan = /* @__PURE__ */ dual((args2) => isEffect(args2[0]), (self, plan, options) => suspend(() => {
14658
14954
  let i = 0;
14659
14955
  let meta = {
14660
14956
  attempt: 0,
@@ -14667,12 +14963,14 @@ var withExecutionPlan = /* @__PURE__ */ dual(2, (self, plan) => suspend(() => {
14667
14963
  };
14668
14964
  return meta;
14669
14965
  }));
14966
+ const emitter = options?.onEvent === undefined ? undefined : makeEventEmitter(options.onEvent, () => meta);
14967
+ const instrument = emitter === undefined ? identity : (attempt) => uninterruptibleMask((restore) => flatMap3(emitter.begin, (state) => onExit(restore(attempt), (exit2) => emitter.end(state, exit2))));
14670
14968
  let result2;
14671
14969
  return flatMap3(whileLoop({
14672
14970
  while: () => i < plan.steps.length && (result2 === undefined || isFailure2(result2)),
14673
14971
  body() {
14674
14972
  const step = plan.steps[i];
14675
- let nextEffect = provideMeta(provide3(self, step.provide));
14973
+ let nextEffect = provideMeta(instrument(provide3(self, step.provide)));
14676
14974
  if (result2) {
14677
14975
  let attempted = false;
14678
14976
  const wrapped = nextEffect;
@@ -14713,7 +15011,7 @@ var scheduleFromStep = (step, first) => {
14713
15011
  };
14714
15012
  var scheduleOnce = /* @__PURE__ */ recurs(1);
14715
15013
 
14716
- // ../../node_modules/.bun/effect@4.0.0-beta.98/node_modules/effect/dist/Request.js
15014
+ // ../../node_modules/.bun/effect@4.0.0-beta.107/node_modules/effect/dist/Request.js
14717
15015
  var TypeId9 = "~effect/Request";
14718
15016
  var requestVariance = /* @__PURE__ */ byReferenceUnsafe({
14719
15017
  _E: (_) => _,
@@ -14726,7 +15024,7 @@ var RequestPrototype = {
14726
15024
  };
14727
15025
  var makeEntry = (options) => options;
14728
15026
 
14729
- // ../../node_modules/.bun/effect@4.0.0-beta.98/node_modules/effect/dist/internal/request.js
15027
+ // ../../node_modules/.bun/effect@4.0.0-beta.107/node_modules/effect/dist/internal/request.js
14730
15028
  var request = /* @__PURE__ */ dual(2, (self, resolver) => {
14731
15029
  const withResolver = (resolver2) => callback((resume) => {
14732
15030
  const entry = addEntry(resolver2, self, resume, getCurrentFiber());
@@ -14842,7 +15140,7 @@ function runBatch(batch) {
14842
15140
  return batch.run;
14843
15141
  }
14844
15142
 
14845
- // ../../node_modules/.bun/effect@4.0.0-beta.98/node_modules/effect/dist/Metric.js
15143
+ // ../../node_modules/.bun/effect@4.0.0-beta.107/node_modules/effect/dist/Metric.js
14846
15144
  var CurrentMetricAttributesKey = "effect/Metric/CurrentMetricAttributes";
14847
15145
  var CurrentMetricAttributes = /* @__PURE__ */ Reference(CurrentMetricAttributesKey, {
14848
15146
  defaultValue: () => ({})
@@ -14999,7 +15297,7 @@ class HistogramMetric extends Metric$ {
14999
15297
  let count = 0;
15000
15298
  let sum2 = 0;
15001
15299
  let min2 = Number.MAX_VALUE;
15002
- let max2 = Number.MIN_VALUE;
15300
+ let max2 = -Number.MAX_VALUE;
15003
15301
  map3(sort(bounds, Number2), (n, i) => {
15004
15302
  boundaries[i] = n;
15005
15303
  });
@@ -15076,7 +15374,7 @@ class SummaryMetric extends Metric$ {
15076
15374
  let count = 0;
15077
15375
  let sum2 = 0;
15078
15376
  let min2 = Number.MAX_VALUE;
15079
- let max2 = Number.MIN_VALUE;
15377
+ let max2 = -Number.MAX_VALUE;
15080
15378
  const snapshot = (now) => {
15081
15379
  const builder = [];
15082
15380
  let i = 0;
@@ -15154,10 +15452,7 @@ function makeHooks(get2, update2, modify) {
15154
15452
  };
15155
15453
  }
15156
15454
  function serializeAttributes(attributes) {
15157
- return serializeEntries(Array.isArray(attributes) ? attributes : Object.entries(attributes));
15158
- }
15159
- function serializeEntries(entries) {
15160
- return entries.map(([key, value]) => `${key}=${value}`).join(",");
15455
+ return JSON.stringify(Array.isArray(attributes) ? attributes : Object.entries(attributes));
15161
15456
  }
15162
15457
  function mergeAttributes(self, other) {
15163
15458
  return {
@@ -15168,18 +15463,19 @@ function mergeAttributes(self, other) {
15168
15463
  function attributesToRecord(attributes) {
15169
15464
  if (isNotUndefined(attributes) && Array.isArray(attributes)) {
15170
15465
  return attributes.reduce((acc, [key, value]) => {
15171
- acc[key] = value;
15466
+ assignProperty(acc, key, value);
15172
15467
  return acc;
15173
15468
  }, {});
15174
15469
  }
15175
15470
  return attributes;
15176
15471
  }
15177
15472
 
15178
- // ../../node_modules/.bun/effect@4.0.0-beta.98/node_modules/effect/dist/Effect.js
15473
+ // ../../node_modules/.bun/effect@4.0.0-beta.107/node_modules/effect/dist/Effect.js
15179
15474
  var TypeId11 = EffectTypeId;
15180
15475
  var isEffect2 = isEffect;
15181
15476
  var all4 = all3;
15182
15477
  var partition3 = partition2;
15478
+ var reduce2 = reduce;
15183
15479
  var validate2 = validate;
15184
15480
  var findFirst2 = findFirst;
15185
15481
  var findFirstFilter2 = findFirstFilter;
@@ -15205,7 +15501,7 @@ var fail6 = fail3;
15205
15501
  var failSync2 = failSync;
15206
15502
  var failCause4 = failCause;
15207
15503
  var failCauseSync2 = failCauseSync;
15208
- var die3 = die;
15504
+ var die4 = die;
15209
15505
  var try_3 = try_2;
15210
15506
  var yieldNow2 = yieldNow;
15211
15507
  var yieldNowWith2 = yieldNowWith;
@@ -15215,7 +15511,7 @@ var fromOption4 = fromOption3;
15215
15511
  var transposeOption3 = transposeOption2;
15216
15512
  var fromNullishOr4 = fromNullishOr3;
15217
15513
  var flatMap5 = flatMap3;
15218
- var flatten4 = flatten3;
15514
+ var flatten5 = flatten4;
15219
15515
  var andThen4 = andThen3;
15220
15516
  var tap5 = tap3;
15221
15517
  var result2 = result;
@@ -15278,7 +15574,7 @@ var filterMapOrElse2 = filterMapOrElse;
15278
15574
  var filterOrFail3 = filterOrFail2;
15279
15575
  var filterMapOrFail2 = filterMapOrFail;
15280
15576
  var when2 = when;
15281
- var match5 = match4;
15577
+ var match6 = match4;
15282
15578
  var matchEager2 = matchEager;
15283
15579
  var matchCause2 = matchCause;
15284
15580
  var matchCauseEager2 = matchCauseEager;
@@ -15296,9 +15592,9 @@ var service2 = service;
15296
15592
  var serviceOption2 = serviceOption;
15297
15593
  var updateContext2 = updateContext;
15298
15594
  var updateService3 = updateService;
15595
+ var updateServiceScoped2 = updateServiceScoped;
15299
15596
  var provideService2 = provideService;
15300
15597
  var provideServiceEffect2 = provideServiceEffect;
15301
- var withConcurrency2 = withConcurrency;
15302
15598
  var scope2 = scope;
15303
15599
  var scoped2 = scoped;
15304
15600
  var scopedWith2 = scopedWith;
@@ -15382,13 +15678,16 @@ var logDebug = /* @__PURE__ */ logWithLevel("Debug");
15382
15678
  var logTrace = /* @__PURE__ */ logWithLevel("Trace");
15383
15679
  var withLogger = /* @__PURE__ */ dual(2, (effect2, logger) => updateService(effect2, CurrentLoggers, (loggers) => new Set([...loggers, logger])));
15384
15680
  var annotateLogs = /* @__PURE__ */ dual((args2) => isEffect2(args2[0]), (effect2, ...args2) => updateService(effect2, CurrentLogAnnotations2, (annotations) => {
15385
- const newAnnotations = {
15681
+ const newAnnotations = args2.length === 1 ? {
15682
+ ...annotations,
15683
+ ...args2[0]
15684
+ } : {
15386
15685
  ...annotations
15387
15686
  };
15388
15687
  if (args2.length === 1) {
15389
- Object.assign(newAnnotations, args2[0]);
15688
+ return newAnnotations;
15390
15689
  } else {
15391
- newAnnotations[args2[0]] = args2[1];
15690
+ assignProperty(newAnnotations, args2[0], args2[1]);
15392
15691
  }
15393
15692
  return newAnnotations;
15394
15693
  }));
@@ -15414,9 +15713,9 @@ var trackDefects = /* @__PURE__ */ dual((args2) => isEffect2(args2[0]), (self, m
15414
15713
  return update(metric, input);
15415
15714
  }));
15416
15715
  var trackDuration = /* @__PURE__ */ dual((args2) => isEffect2(args2[0]), (self, metric, f) => clockWith2((clock) => {
15417
- const startTime = clock.currentTimeNanosUnsafe();
15716
+ const startTime = clock.monotonicTimeNanosUnsafe();
15418
15717
  return onExit2(self, () => {
15419
- const endTime = clock.currentTimeNanosUnsafe();
15718
+ const endTime = clock.monotonicTimeNanosUnsafe();
15420
15719
  const duration = subtract(fromInputUnsafe(endTime), fromInputUnsafe(startTime));
15421
15720
  const input = f === undefined ? duration : internalCall(() => f(duration));
15422
15721
  return update(metric, input);
@@ -15456,9 +15755,9 @@ var tx = (effect2) => withFiber2((fiber3) => {
15456
15755
  });
15457
15756
  var isTransactionConsistent = (state) => {
15458
15757
  for (const [ref, {
15459
- version: version2
15758
+ version
15460
15759
  }] of state.journal) {
15461
- if (ref.version !== version2) {
15760
+ if (ref.version !== version) {
15462
15761
  return false;
15463
15762
  }
15464
15763
  }
@@ -15515,7 +15814,7 @@ var effectify = (fn3, onError3, onSyncError) => (...args2) => callback2((resume)
15515
15814
  }
15516
15815
  });
15517
15816
  } catch (err) {
15518
- resume(onSyncError ? fail6(onSyncError(err, args2)) : die3(err));
15817
+ resume(onSyncError ? fail6(onSyncError(err, args2)) : die4(err));
15519
15818
  }
15520
15819
  });
15521
15820
  var satisfiesSuccessType2 = () => (effect2) => effect2;
@@ -15528,7 +15827,7 @@ var flatMapEager2 = flatMapEager;
15528
15827
  var catchEager2 = catchEager;
15529
15828
  var fnUntracedEager2 = fnUntracedEager;
15530
15829
 
15531
- // ../../node_modules/.bun/effect@4.0.0-beta.98/node_modules/effect/dist/FileSystem.js
15830
+ // ../../node_modules/.bun/effect@4.0.0-beta.107/node_modules/effect/dist/FileSystem.js
15532
15831
  var exports_FileSystem = {};
15533
15832
  __export(exports_FileSystem, {
15534
15833
  makeNoop: () => makeNoop,
@@ -15543,20 +15842,10 @@ __export(exports_FileSystem, {
15543
15842
  KiB: () => KiB,
15544
15843
  GiB: () => GiB,
15545
15844
  FileTypeId: () => FileTypeId,
15546
- FileSystem: () => FileSystem,
15547
- FileDescriptor: () => FileDescriptor
15845
+ FileSystem: () => FileSystem
15548
15846
  });
15549
15847
 
15550
- // ../../node_modules/.bun/effect@4.0.0-beta.98/node_modules/effect/dist/Brand.js
15551
- function nominal() {
15552
- return Object.assign((input) => input, {
15553
- option: (input) => some2(input),
15554
- result: (input) => succeed2(input),
15555
- is: (_) => true
15556
- });
15557
- }
15558
-
15559
- // ../../node_modules/.bun/effect@4.0.0-beta.98/node_modules/effect/dist/PlatformError.js
15848
+ // ../../node_modules/.bun/effect@4.0.0-beta.107/node_modules/effect/dist/PlatformError.js
15560
15849
  var exports_PlatformError = {};
15561
15850
  __export(exports_PlatformError, {
15562
15851
  systemError: () => systemError,
@@ -15600,21 +15889,44 @@ class PlatformError extends (/* @__PURE__ */ TaggedError2("PlatformError")) {
15600
15889
  var systemError = (options) => new PlatformError(new SystemError(options));
15601
15890
  var badArgument = (options) => new PlatformError(new BadArgument(options));
15602
15891
 
15603
- // ../../node_modules/.bun/effect@4.0.0-beta.98/node_modules/effect/dist/Fiber.js
15604
- var TypeId13 = `~effect/Fiber/${version}`;
15892
+ // ../../node_modules/.bun/effect@4.0.0-beta.107/node_modules/effect/dist/Fiber.js
15893
+ var await_ = fiberAwait;
15605
15894
  var join = fiberJoin;
15606
15895
  var joinAll = fiberJoinAll;
15607
15896
  var interrupt4 = fiberInterrupt;
15608
15897
  var getCurrent = getCurrentFiber;
15609
15898
  var runIn = fiberRunIn;
15610
15899
 
15611
- // ../../node_modules/.bun/effect@4.0.0-beta.98/node_modules/effect/dist/Latch.js
15900
+ // ../../node_modules/.bun/effect@4.0.0-beta.107/node_modules/effect/dist/Latch.js
15612
15901
  var makeUnsafe4 = makeLatchUnsafe;
15613
15902
  var make8 = makeLatch;
15614
15903
 
15615
- // ../../node_modules/.bun/effect@4.0.0-beta.98/node_modules/effect/dist/MutableList.js
15904
+ // ../../node_modules/.bun/effect@4.0.0-beta.107/node_modules/effect/dist/MutableRef.js
15905
+ var TypeId13 = "~effect/MutableRef";
15906
+ var MutableRefProto = {
15907
+ [TypeId13]: TypeId13,
15908
+ ...PipeInspectableProto,
15909
+ toJSON() {
15910
+ return {
15911
+ _id: "MutableRef",
15912
+ current: toJson(this.current)
15913
+ };
15914
+ }
15915
+ };
15916
+ var make9 = (value) => {
15917
+ const ref = Object.create(MutableRefProto);
15918
+ ref.current = value;
15919
+ return ref;
15920
+ };
15921
+ var get2 = (self) => self.current;
15922
+ var set = /* @__PURE__ */ dual(2, (self, value) => {
15923
+ self.current = value;
15924
+ return self;
15925
+ });
15926
+
15927
+ // ../../node_modules/.bun/effect@4.0.0-beta.107/node_modules/effect/dist/MutableList.js
15616
15928
  var Empty = /* @__PURE__ */ Symbol.for("effect/MutableList/Empty");
15617
- var make9 = () => ({
15929
+ var make10 = () => ({
15618
15930
  head: undefined,
15619
15931
  tail: undefined,
15620
15932
  length: 0
@@ -15642,6 +15954,8 @@ var prepend = (self, message) => {
15642
15954
  offset: 0,
15643
15955
  next: self.head
15644
15956
  };
15957
+ if (!self.tail)
15958
+ self.tail = self.head;
15645
15959
  self.length++;
15646
15960
  };
15647
15961
  var appendAll2 = (self, messages) => appendAllUnsafe(self, fromIterable2(messages), !Array.isArray(messages));
@@ -15741,6 +16055,8 @@ var take = (self) => {
15741
16055
  return message;
15742
16056
  };
15743
16057
  var toArrayN = (self, n) => {
16058
+ if (n <= 0)
16059
+ return [];
15744
16060
  const length = Math.min(n, self.length);
15745
16061
  const out = new Array(length);
15746
16062
  let index = 0;
@@ -15766,6 +16082,10 @@ var filter6 = (self, f) => {
15766
16082
  }
15767
16083
  chunk = chunk.next;
15768
16084
  }
16085
+ if (array2.length === 0) {
16086
+ clear(self);
16087
+ return;
16088
+ }
15769
16089
  self.head = self.tail = {
15770
16090
  array: array2,
15771
16091
  mutable: true,
@@ -15776,33 +16096,10 @@ var filter6 = (self, f) => {
15776
16096
  };
15777
16097
  var remove = (self, value) => filter6(self, (v) => v !== value);
15778
16098
 
15779
- // ../../node_modules/.bun/effect@4.0.0-beta.98/node_modules/effect/dist/MutableRef.js
15780
- var TypeId14 = "~effect/MutableRef";
15781
- var MutableRefProto = {
15782
- [TypeId14]: TypeId14,
15783
- ...PipeInspectableProto,
15784
- toJSON() {
15785
- return {
15786
- _id: "MutableRef",
15787
- current: toJson(this.current)
15788
- };
15789
- }
15790
- };
15791
- var make10 = (value) => {
15792
- const ref = Object.create(MutableRefProto);
15793
- ref.current = value;
15794
- return ref;
15795
- };
15796
- var get2 = (self) => self.current;
15797
- var set = /* @__PURE__ */ dual(2, (self, value) => {
15798
- self.current = value;
15799
- return self;
15800
- });
15801
-
15802
- // ../../node_modules/.bun/effect@4.0.0-beta.98/node_modules/effect/dist/PubSub.js
15803
- var TypeId15 = "~effect/PubSub";
16099
+ // ../../node_modules/.bun/effect@4.0.0-beta.107/node_modules/effect/dist/PubSub.js
16100
+ var TypeId14 = "~effect/PubSub";
15804
16101
  var SubscriptionTypeId = "~effect/PubSub/Subscription";
15805
- var make11 = (options) => sync3(() => makePubSubUnsafe(options.atomicPubSub(), new Map, makeUnsafe3(), makeUnsafe4(false), make10(false), options.strategy()));
16102
+ var make11 = (options) => sync3(() => makePubSubUnsafe(options.atomicPubSub(), new Map, makeUnsafe3(), makeUnsafe4(false), make9(false), options.strategy()));
15806
16103
  var bounded = (capacity) => make11({
15807
16104
  atomicPubSub: () => makeAtomicBounded(capacity),
15808
16105
  strategy: () => new BackPressureStrategy
@@ -15873,6 +16170,7 @@ var unsubscribe = (self) => uninterruptible2(withFiber2((state) => {
15873
16170
  }).pipe(tap5(() => sync3(() => {
15874
16171
  self.subscribers.delete(self.subscription);
15875
16172
  self.subscription.unsubscribe();
16173
+ self.replayWindow.close();
15876
16174
  self.strategy.onPubSubEmptySpaceUnsafe(self.pubsub, self.subscribers);
15877
16175
  })), when2(self.shutdownHook.open), asVoid3);
15878
16176
  }));
@@ -15941,10 +16239,11 @@ var removeSubscribers = (subscribers, subscription, pollers) => {
15941
16239
  subscribers.delete(subscription);
15942
16240
  }
15943
16241
  };
15944
- var makeSubscriptionUnsafe = (pubsub, subscribers, strategy) => new SubscriptionImpl(pubsub, subscribers, pubsub.subscribe(), make9(), makeUnsafe4(false), make10(false), strategy, pubsub.replayWindow());
16242
+ var makeSubscriptionUnsafe = (pubsub, subscribers, strategy) => new SubscriptionImpl(pubsub, subscribers, pubsub.subscribe(), make10(), makeUnsafe4(false), make9(false), strategy, pubsub.replayWindow());
15945
16243
 
15946
16244
  class BoundedPubSubArb {
15947
16245
  array;
16246
+ replayIndices;
15948
16247
  publisherIndex = 0;
15949
16248
  subscribers;
15950
16249
  subscriberCount = 0;
@@ -15957,6 +16256,9 @@ class BoundedPubSubArb {
15957
16256
  this.array = Array.from({
15958
16257
  length: capacity
15959
16258
  });
16259
+ this.replayIndices = replayBuffer ? Array.from({
16260
+ length: capacity
16261
+ }) : [];
15960
16262
  this.subscribers = Array.from({
15961
16263
  length: capacity
15962
16264
  });
@@ -15977,15 +16279,16 @@ class BoundedPubSubArb {
15977
16279
  if (this.isFull()) {
15978
16280
  return false;
15979
16281
  }
16282
+ const replayIndex = this.replayBuffer?.offer(value);
15980
16283
  if (this.subscriberCount !== 0) {
15981
16284
  const index = this.publisherIndex % this.capacity;
15982
16285
  this.array[index] = value;
16286
+ if (replayIndex !== undefined) {
16287
+ this.replayIndices[index] = replayIndex;
16288
+ }
15983
16289
  this.subscribers[index] = this.subscriberCount;
15984
16290
  this.publisherIndex += 1;
15985
16291
  }
15986
- if (this.replayBuffer) {
15987
- this.replayBuffer.offer(value);
15988
- }
15989
16292
  return true;
15990
16293
  }
15991
16294
  publishAll(elements) {
@@ -16009,23 +16312,23 @@ class BoundedPubSubArb {
16009
16312
  const a = chunk[iteratorIndex++];
16010
16313
  const index = this.publisherIndex % this.capacity;
16011
16314
  this.array[index] = a;
16315
+ const replayIndex = this.replayBuffer?.offer(a);
16316
+ if (replayIndex !== undefined) {
16317
+ this.replayIndices[index] = replayIndex;
16318
+ }
16012
16319
  this.subscribers[index] = this.subscriberCount;
16013
16320
  this.publisherIndex += 1;
16014
- if (this.replayBuffer) {
16015
- this.replayBuffer.offer(a);
16016
- }
16017
16321
  }
16018
16322
  return chunk.slice(iteratorIndex);
16019
16323
  }
16020
16324
  slide() {
16021
16325
  if (this.subscribersIndex !== this.publisherIndex) {
16022
16326
  const index = this.subscribersIndex % this.capacity;
16327
+ const value = this.array[index];
16023
16328
  this.array[index] = AbsentValue;
16024
16329
  this.subscribers[index] = 0;
16025
16330
  this.subscribersIndex += 1;
16026
- }
16027
- if (this.replayBuffer) {
16028
- this.replayBuffer.slide();
16331
+ this.replayBuffer?.slide(value, this.replayIndices[index]);
16029
16332
  }
16030
16333
  }
16031
16334
  subscribe() {
@@ -16115,6 +16418,7 @@ class BoundedPubSubArbSubscription {
16115
16418
 
16116
16419
  class BoundedPubSubPow2 {
16117
16420
  array;
16421
+ replayIndices;
16118
16422
  mask;
16119
16423
  publisherIndex = 0;
16120
16424
  subscribers;
@@ -16128,6 +16432,9 @@ class BoundedPubSubPow2 {
16128
16432
  this.array = Array.from({
16129
16433
  length: capacity
16130
16434
  });
16435
+ this.replayIndices = replayBuffer ? Array.from({
16436
+ length: capacity
16437
+ }) : [];
16131
16438
  this.mask = capacity - 1;
16132
16439
  this.subscribers = Array.from({
16133
16440
  length: capacity
@@ -16149,15 +16456,16 @@ class BoundedPubSubPow2 {
16149
16456
  if (this.isFull()) {
16150
16457
  return false;
16151
16458
  }
16459
+ const replayIndex = this.replayBuffer?.offer(value);
16152
16460
  if (this.subscriberCount !== 0) {
16153
16461
  const index = this.publisherIndex & this.mask;
16154
16462
  this.array[index] = value;
16463
+ if (replayIndex !== undefined) {
16464
+ this.replayIndices[index] = replayIndex;
16465
+ }
16155
16466
  this.subscribers[index] = this.subscriberCount;
16156
16467
  this.publisherIndex += 1;
16157
16468
  }
16158
- if (this.replayBuffer) {
16159
- this.replayBuffer.offer(value);
16160
- }
16161
16469
  return true;
16162
16470
  }
16163
16471
  publishAll(elements) {
@@ -16181,23 +16489,23 @@ class BoundedPubSubPow2 {
16181
16489
  const elem = chunk[iteratorIndex++];
16182
16490
  const index = this.publisherIndex & this.mask;
16183
16491
  this.array[index] = elem;
16492
+ const replayIndex = this.replayBuffer?.offer(elem);
16493
+ if (replayIndex !== undefined) {
16494
+ this.replayIndices[index] = replayIndex;
16495
+ }
16184
16496
  this.subscribers[index] = this.subscriberCount;
16185
16497
  this.publisherIndex += 1;
16186
- if (this.replayBuffer) {
16187
- this.replayBuffer.offer(elem);
16188
- }
16189
16498
  }
16190
16499
  return chunk.slice(iteratorIndex);
16191
16500
  }
16192
16501
  slide() {
16193
16502
  if (this.subscribersIndex !== this.publisherIndex) {
16194
16503
  const index = this.subscribersIndex & this.mask;
16504
+ const value = this.array[index];
16195
16505
  this.array[index] = AbsentValue;
16196
16506
  this.subscribers[index] = 0;
16197
16507
  this.subscribersIndex += 1;
16198
- }
16199
- if (this.replayBuffer) {
16200
- this.replayBuffer.slide();
16508
+ this.replayBuffer?.slide(value, this.replayIndices[index]);
16201
16509
  }
16202
16510
  }
16203
16511
  subscribe() {
@@ -16290,6 +16598,7 @@ class BoundedPubSubSingle {
16290
16598
  subscriberCount = 0;
16291
16599
  subscribers = 0;
16292
16600
  value = AbsentValue;
16601
+ replayIndex = 0;
16293
16602
  capacity = 1;
16294
16603
  replayBuffer;
16295
16604
  constructor(replayBuffer) {
@@ -16314,14 +16623,15 @@ class BoundedPubSubSingle {
16314
16623
  if (this.isFull()) {
16315
16624
  return false;
16316
16625
  }
16626
+ const replayIndex = this.replayBuffer?.offer(value);
16317
16627
  if (this.subscriberCount !== 0) {
16318
16628
  this.value = value;
16629
+ if (replayIndex !== undefined) {
16630
+ this.replayIndex = replayIndex;
16631
+ }
16319
16632
  this.subscribers = this.subscriberCount;
16320
16633
  this.publisherIndex += 1;
16321
16634
  }
16322
- if (this.replayBuffer) {
16323
- this.replayBuffer.offer(value);
16324
- }
16325
16635
  return true;
16326
16636
  }
16327
16637
  publishAll(elements) {
@@ -16343,11 +16653,10 @@ class BoundedPubSubSingle {
16343
16653
  }
16344
16654
  slide() {
16345
16655
  if (this.isFull()) {
16656
+ const value = this.value;
16346
16657
  this.subscribers = 0;
16347
16658
  this.value = AbsentValue;
16348
- }
16349
- if (this.replayBuffer) {
16350
- this.replayBuffer.slide();
16659
+ this.replayBuffer?.slide(value, this.replayIndex);
16351
16660
  }
16352
16661
  }
16353
16662
  subscribe() {
@@ -16412,6 +16721,7 @@ class BoundedPubSubSingleSubscription {
16412
16721
  class UnboundedPubSub {
16413
16722
  publisherHead = {
16414
16723
  value: AbsentValue,
16724
+ replayIndex: undefined,
16415
16725
  subscribers: 0,
16416
16726
  next: null
16417
16727
  };
@@ -16436,19 +16746,19 @@ class UnboundedPubSub {
16436
16746
  return this.publisherIndex - this.subscribersIndex;
16437
16747
  }
16438
16748
  publish(value) {
16749
+ const replayIndex = this.replayBuffer?.offer(value);
16439
16750
  const subscribers = this.publisherTail.subscribers;
16440
16751
  if (subscribers !== 0) {
16441
- this.publisherTail.next = {
16752
+ const node = {
16442
16753
  value,
16754
+ replayIndex,
16443
16755
  subscribers,
16444
16756
  next: null
16445
16757
  };
16758
+ this.publisherTail.next = node;
16446
16759
  this.publisherTail = this.publisherTail.next;
16447
16760
  this.publisherIndex += 1;
16448
16761
  }
16449
- if (this.replayBuffer) {
16450
- this.replayBuffer.offer(value);
16451
- }
16452
16762
  return true;
16453
16763
  }
16454
16764
  publishAll(elements) {
@@ -16463,12 +16773,12 @@ class UnboundedPubSub {
16463
16773
  }
16464
16774
  slide() {
16465
16775
  if (this.publisherHead !== this.publisherTail) {
16776
+ const node = this.publisherHead.next;
16777
+ const value = node.value;
16466
16778
  this.publisherHead = this.publisherHead.next;
16467
16779
  this.publisherHead.value = AbsentValue;
16468
16780
  this.subscribersIndex += 1;
16469
- }
16470
- if (this.replayBuffer) {
16471
- this.replayBuffer.slide();
16781
+ this.replayBuffer?.slide(value, node.replayIndex);
16472
16782
  }
16473
16783
  }
16474
16784
  subscribe() {
@@ -16603,7 +16913,7 @@ class SubscriptionImpl {
16603
16913
  }
16604
16914
 
16605
16915
  class PubSubImpl {
16606
- [TypeId15] = {
16916
+ [TypeId14] = {
16607
16917
  _A: identity
16608
16918
  };
16609
16919
  pubsub;
@@ -16632,7 +16942,7 @@ var ensureCapacity = (capacity) => {
16632
16942
  };
16633
16943
 
16634
16944
  class BackPressureStrategy {
16635
- publishers = /* @__PURE__ */ make9();
16945
+ publishers = /* @__PURE__ */ make10();
16636
16946
  get shutdown() {
16637
16947
  return withFiber2((fiber3) => forEach2(takeAll(this.publishers), ([_, deferred, last]) => last ? interruptWith(deferred, fiber3.id) : void_5, {
16638
16948
  concurrency: "unbounded",
@@ -16781,21 +17091,31 @@ class ReplayBuffer {
16781
17091
  capacity;
16782
17092
  head = {
16783
17093
  value: AbsentValue,
17094
+ index: 0,
16784
17095
  next: null
16785
17096
  };
16786
17097
  tail = this.head;
17098
+ slideValues = [];
16787
17099
  size = 0;
16788
17100
  index = 0;
17101
+ publisherIndex = 0;
16789
17102
  constructor(capacity) {
16790
17103
  this.capacity = capacity;
16791
17104
  }
16792
- slide() {
17105
+ slide(value, publisherIndex) {
17106
+ this.slideValues[this.index % this.capacity] = {
17107
+ value,
17108
+ index: publisherIndex
17109
+ };
16793
17110
  this.index++;
16794
17111
  }
16795
17112
  offer(a) {
17113
+ const index = this.publisherIndex++;
16796
17114
  this.tail.value = a;
17115
+ this.tail.index = index;
16797
17116
  this.tail.next = {
16798
17117
  value: AbsentValue,
17118
+ index: 0,
16799
17119
  next: null
16800
17120
  };
16801
17121
  this.tail = this.tail.next;
@@ -16804,6 +17124,7 @@ class ReplayBuffer {
16804
17124
  } else {
16805
17125
  this.size += 1;
16806
17126
  }
17127
+ return index;
16807
17128
  }
16808
17129
  offerAll(as4) {
16809
17130
  for (const a of as4) {
@@ -16813,47 +17134,65 @@ class ReplayBuffer {
16813
17134
  }
16814
17135
 
16815
17136
  class ReplayWindowImpl {
16816
- head;
16817
- index;
16818
- remaining;
16819
17137
  buffer;
17138
+ values;
17139
+ index = 0;
17140
+ remaining;
17141
+ slideIndex;
17142
+ newestIndex = -1;
16820
17143
  constructor(buffer) {
16821
17144
  this.buffer = buffer;
16822
- this.index = buffer.index;
16823
17145
  this.remaining = buffer.size;
16824
- this.head = buffer.head;
16825
- }
16826
- fastForward() {
16827
- while (this.index < this.buffer.index) {
16828
- this.head = this.head.next;
16829
- this.index++;
17146
+ this.slideIndex = buffer.index;
17147
+ this.values = new Array(this.remaining);
17148
+ let node = buffer.head;
17149
+ for (let i = 0;i < this.remaining; i++) {
17150
+ this.values[i] = node.value;
17151
+ this.newestIndex = node.index;
17152
+ node = node.next;
17153
+ }
17154
+ }
17155
+ close() {
17156
+ this.values.length = 0;
17157
+ this.remaining = 0;
17158
+ }
17159
+ sync() {
17160
+ const slides = this.buffer.index - this.slideIndex;
17161
+ if (slides === 0 || this.remaining === 0) {
17162
+ return;
16830
17163
  }
17164
+ const count = Math.min(slides, this.buffer.capacity);
17165
+ const start = this.buffer.index - count;
17166
+ for (let i = 0;i < count; i++) {
17167
+ const entry = this.buffer.slideValues[(start + i) % this.buffer.capacity];
17168
+ if (entry.index > this.newestIndex) {
17169
+ this.index = (this.index + 1) % this.values.length;
17170
+ this.values[(this.index + this.remaining - 1) % this.values.length] = entry.value;
17171
+ this.newestIndex = entry.index;
17172
+ }
17173
+ }
17174
+ this.slideIndex = this.buffer.index;
16831
17175
  }
16832
17176
  take() {
16833
17177
  if (this.remaining === 0) {
16834
17178
  return;
16835
- } else if (this.index < this.buffer.index) {
16836
- this.fastForward();
16837
17179
  }
17180
+ this.sync();
17181
+ const value = this.values[this.index];
17182
+ this.values[this.index] = AbsentValue;
17183
+ this.index = (this.index + 1) % this.values.length;
16838
17184
  this.remaining--;
16839
- const value = this.head.value;
16840
- this.head = this.head.next;
17185
+ if (this.remaining === 0) {
17186
+ this.close();
17187
+ }
16841
17188
  return value;
16842
17189
  }
16843
17190
  takeN(n) {
16844
- if (this.remaining === 0) {
16845
- return [];
16846
- } else if (this.index < this.buffer.index) {
16847
- this.fastForward();
16848
- }
16849
17191
  const len = Math.min(n, this.remaining);
16850
17192
  const items = new Array(len);
16851
17193
  for (let i = 0;i < len; i++) {
16852
- const value = this.head.value;
16853
- this.head = this.head.next;
16854
- items[i] = value;
17194
+ items[i] = this.take();
16855
17195
  }
16856
- this.remaining -= len;
16857
17196
  return items;
16858
17197
  }
16859
17198
  takeAll() {
@@ -16866,11 +17205,14 @@ var emptyReplayWindow = {
16866
17205
  return;
16867
17206
  },
16868
17207
  takeN: () => [],
16869
- takeAll: () => []
17208
+ takeAll: () => [],
17209
+ close: () => {
17210
+ return;
17211
+ }
16870
17212
  };
16871
17213
 
16872
- // ../../node_modules/.bun/effect@4.0.0-beta.98/node_modules/effect/dist/Queue.js
16873
- var TypeId16 = "~effect/Queue";
17214
+ // ../../node_modules/.bun/effect@4.0.0-beta.107/node_modules/effect/dist/Queue.js
17215
+ var TypeId15 = "~effect/Queue";
16874
17216
  var EnqueueTypeId = "~effect/Queue/Enqueue";
16875
17217
  var DequeueTypeId = "~effect/Queue/Dequeue";
16876
17218
  var variance = {
@@ -16878,7 +17220,7 @@ var variance = {
16878
17220
  _E: identity
16879
17221
  };
16880
17222
  var QueueProto = {
16881
- [TypeId16]: variance,
17223
+ [TypeId15]: variance,
16882
17224
  [EnqueueTypeId]: variance,
16883
17225
  [DequeueTypeId]: variance,
16884
17226
  ...PipeInspectableProto,
@@ -16895,7 +17237,7 @@ var make12 = (options) => withFiber((fiber3) => {
16895
17237
  self.dispatcher = fiber3.currentDispatcher;
16896
17238
  self.capacity = options?.capacity ?? Number.POSITIVE_INFINITY;
16897
17239
  self.strategy = options?.strategy ?? "suspend";
16898
- self.messages = make9();
17240
+ self.messages = make10();
16899
17241
  self.scheduleRunning = false;
16900
17242
  self.state = {
16901
17243
  _tag: "Open",
@@ -17196,8 +17538,22 @@ var finalize = (self, exit3) => {
17196
17538
  openState.awaiters.clear();
17197
17539
  };
17198
17540
 
17199
- // ../../node_modules/.bun/effect@4.0.0-beta.98/node_modules/effect/dist/Semaphore.js
17541
+ // ../../node_modules/.bun/effect@4.0.0-beta.107/node_modules/effect/dist/Semaphore.js
17200
17542
  var makeUnsafe5 = (permits) => new SemaphoreImpl(permits);
17543
+ var waitForPermits = (self, n, effect2) => callback((resume) => {
17544
+ if (self.free >= n)
17545
+ return resume(effect2);
17546
+ const observer = () => {
17547
+ if (self.free < n)
17548
+ return;
17549
+ self.waiters.delete(observer);
17550
+ resume(effect2);
17551
+ };
17552
+ self.waiters.add(observer);
17553
+ return sync(() => {
17554
+ self.waiters.delete(observer);
17555
+ });
17556
+ });
17201
17557
 
17202
17558
  class SemaphoreImpl {
17203
17559
  waiters = /* @__PURE__ */ new Set;
@@ -17212,63 +17568,64 @@ class SemaphoreImpl {
17212
17568
  take(n) {
17213
17569
  const take4 = suspend(() => {
17214
17570
  if (this.free < n) {
17215
- return callback((resume) => {
17216
- if (this.free >= n)
17217
- return resume(take4);
17218
- const observer = () => {
17219
- if (this.free < n)
17220
- return;
17221
- this.waiters.delete(observer);
17222
- resume(take4);
17223
- };
17224
- this.waiters.add(observer);
17225
- return sync(() => {
17226
- this.waiters.delete(observer);
17227
- });
17228
- });
17571
+ return waitForPermits(this, n, take4);
17229
17572
  }
17230
17573
  this.taken += n;
17231
17574
  return succeed3(n);
17232
17575
  });
17233
17576
  return take4;
17234
17577
  }
17235
- updateTakenUnsafe(fiber3, f) {
17236
- this.taken = f(this.taken);
17578
+ takeIfAvailable(n) {
17579
+ return suspend(() => {
17580
+ if (this.free < n)
17581
+ return succeed3(false);
17582
+ this.taken += n;
17583
+ return succeed3(true);
17584
+ });
17585
+ }
17586
+ releaseUnsafe(fiber3, n) {
17587
+ this.taken -= n;
17237
17588
  if (this.waiters.size > 0) {
17238
17589
  fiber3.currentDispatcher.scheduleTask(() => {
17239
- const iter = this.waiters.values();
17240
- let item = iter.next();
17241
- while (item.done === false && this.free > 0) {
17242
- item.value();
17243
- item = iter.next();
17590
+ for (const observer of this.waiters) {
17591
+ if (this.free <= 0)
17592
+ break;
17593
+ observer();
17244
17594
  }
17245
17595
  }, 0);
17246
17596
  }
17247
17597
  return this.free;
17248
17598
  }
17249
- updateTaken(f) {
17250
- return withFiber((fiber3) => succeed3(this.updateTakenUnsafe(fiber3, f)));
17251
- }
17252
17599
  resize(permits) {
17253
17600
  return withFiber((fiber3) => {
17254
17601
  this.permits = permits;
17255
17602
  if (this.free < 0)
17256
17603
  return void_3;
17257
- this.updateTakenUnsafe(fiber3, (taken) => taken);
17604
+ this.releaseUnsafe(fiber3, 0);
17258
17605
  return void_3;
17259
17606
  });
17260
17607
  }
17261
17608
  release(n) {
17262
- return this.updateTaken((taken) => taken - n);
17609
+ return withFiber((fiber3) => succeed3(this.releaseUnsafe(fiber3, n)));
17263
17610
  }
17264
17611
  get releaseAll() {
17265
- return this.updateTaken((_) => 0);
17612
+ return withFiber((fiber3) => succeed3(this.releaseUnsafe(fiber3, this.taken)));
17266
17613
  }
17267
17614
  withPermits(n) {
17268
- return (self) => uninterruptibleMask((restore) => flatMap3(restore(this.take(n)), (permits) => onExitPrimitive(restore(self), () => {
17269
- this.updateTakenUnsafe(getCurrentFiber(), (taken) => taken - permits);
17270
- return;
17271
- }, true)));
17615
+ return (self) => uninterruptibleMask((restore) => {
17616
+ const acquire = suspend(() => {
17617
+ if (this.free < n) {
17618
+ const wait = waitForPermits(this, n, void_3);
17619
+ return flatMap3(restore(wait), () => acquire);
17620
+ }
17621
+ this.taken += n;
17622
+ return onExitPrimitive(restore(self), () => {
17623
+ this.releaseUnsafe(getCurrentFiber(), n);
17624
+ return;
17625
+ }, true);
17626
+ });
17627
+ return acquire;
17628
+ });
17272
17629
  }
17273
17630
  withPermit = /* @__PURE__ */ this.withPermits(1);
17274
17631
  withPermitsIfAvailable(n) {
@@ -17277,21 +17634,21 @@ class SemaphoreImpl {
17277
17634
  return succeedNone2;
17278
17635
  this.taken += n;
17279
17636
  return onExitPrimitive(restore(asSome(self)), () => {
17280
- this.updateTakenUnsafe(getCurrentFiber(), (taken) => taken - n);
17637
+ this.releaseUnsafe(getCurrentFiber(), n);
17281
17638
  return;
17282
17639
  }, true);
17283
17640
  });
17284
17641
  }
17285
17642
  }
17286
17643
 
17287
- // ../../node_modules/.bun/effect@4.0.0-beta.98/node_modules/effect/dist/Take.js
17644
+ // ../../node_modules/.bun/effect@4.0.0-beta.107/node_modules/effect/dist/Take.js
17288
17645
  var toPull = (take4) => isExit2(take4) ? isSuccess4(take4) ? done3(take4.value) : take4 : succeed6(take4);
17289
17646
 
17290
- // ../../node_modules/.bun/effect@4.0.0-beta.98/node_modules/effect/dist/Channel.js
17291
- var TypeId17 = "~effect/Channel";
17292
- var isChannel = (u) => hasProperty(u, TypeId17);
17647
+ // ../../node_modules/.bun/effect@4.0.0-beta.107/node_modules/effect/dist/Channel.js
17648
+ var TypeId16 = "~effect/Channel";
17649
+ var isChannel = (u) => hasProperty(u, TypeId16);
17293
17650
  var ChannelProto = {
17294
- [TypeId17]: {
17651
+ [TypeId16]: {
17295
17652
  _Env: identity,
17296
17653
  _InErr: identity,
17297
17654
  _InElem: identity,
@@ -17365,7 +17722,7 @@ var fail7 = (error) => fromPull(succeed6(fail6(error)));
17365
17722
  var failSync3 = (evaluate2) => fromPull(failSync2(evaluate2));
17366
17723
  var failCause6 = (cause) => fromPull(failCause4(cause));
17367
17724
  var failCauseSync3 = (evaluate2) => fromPull(failCauseSync2(evaluate2));
17368
- var die4 = (defect) => failCause6(die2(defect));
17725
+ var die5 = (defect) => failCause6(die3(defect));
17369
17726
  var fromEffect = (effect2) => fromPull(sync3(() => {
17370
17727
  let done4 = false;
17371
17728
  return suspend3(() => {
@@ -17381,6 +17738,35 @@ var fromQueueArray = (queue) => fromPull(succeed6(takeAll3(queue)));
17381
17738
  var fromSubscriptionArray = (subscription) => fromPull(succeed6(onInterrupt2(takeAll2(subscription), () => done3())));
17382
17739
  var fromPubSubArray = (pubsub) => unwrap2(map5(subscribe(pubsub), fromSubscriptionArray));
17383
17740
  var fromPubSubTake = (pubsub) => unwrap2(map5(subscribe(pubsub), (sub) => fromEffectTake(take2(sub))));
17741
+ var fromReadableStream = (options) => fromTransform((_, scope3) => readableStreamToPullUnsafe({
17742
+ scope: scope3,
17743
+ readable: options.evaluate(),
17744
+ onError: options.onError,
17745
+ releaseLockOnEnd: options.releaseLockOnEnd
17746
+ }));
17747
+ var readableStreamToPullUnsafe = (options) => {
17748
+ const reader = options.readable.getReader();
17749
+ const exit3 = options.exit ?? make9(undefined);
17750
+ const pull = suspend3(() => {
17751
+ if (exit3.current)
17752
+ return exit3.current;
17753
+ return matchCauseEffect2(tryPromise2({
17754
+ try: () => reader.read(),
17755
+ catch: options.onError
17756
+ }), {
17757
+ onFailure: (cause) => exit3.current ?? failCause4(cause),
17758
+ onSuccess: ({
17759
+ done: done4,
17760
+ value
17761
+ }) => {
17762
+ if (exit3.current)
17763
+ return exit3.current;
17764
+ return done4 ? done3() : succeed6(of(value));
17765
+ }
17766
+ });
17767
+ });
17768
+ return as3(addFinalizer2(options.scope, options.releaseLockOnEnd ? sync3(() => reader.releaseLock()) : promise2(() => reader.cancel().catch(constVoid))), pull);
17769
+ };
17384
17770
  var fromAsyncIterable = (iterable, onError3) => fromTransform(fnUntraced2(function* (_, scope3) {
17385
17771
  const iter = iterable[Symbol.asyncIterator]();
17386
17772
  if (iter.return) {
@@ -17428,7 +17814,7 @@ var mapEffectConcurrent = (self, f, options) => fromTransformBracket(fnUntraced2
17428
17814
  } else {
17429
17815
  const effects = yield* bounded2(concurrencyN - 2);
17430
17816
  yield* addFinalizer2(forkedScope, shutdown2(queue));
17431
- yield* take3(effects).pipe(flatten4, flatMap5((value) => offer(queue, value)), forever4({
17817
+ yield* take3(effects).pipe(flatten5, flatMap5((value) => offer(queue, value)), forever4({
17432
17818
  disableYield: true
17433
17819
  }), catchCause3((cause) => failCause5(queue, cause)), forkIn2(forkedScope));
17434
17820
  let errorCause;
@@ -17704,7 +18090,7 @@ var catchReasons3 = /* @__PURE__ */ dual((args2) => isChannel(args2[0]), (self,
17704
18090
  });
17705
18091
  });
17706
18092
  var mapError4 = /* @__PURE__ */ dual(2, (self, f) => catch_4(self, (err) => fail7(f(err))));
17707
- var orDie4 = (self) => catch_4(self, die4);
18093
+ var orDie4 = (self) => catch_4(self, die5);
17708
18094
  var ignore3 = /* @__PURE__ */ dual((args2) => isChannel(args2[0]), (self, options) => {
17709
18095
  if (!options?.log) {
17710
18096
  return catch_4(self, () => empty4);
@@ -17756,9 +18142,16 @@ var mergeAll3 = /* @__PURE__ */ dual(2, (channels, {
17756
18142
  const pull = yield* toTransform(channels)(upstream, scope3);
17757
18143
  yield* gen4(function* () {
17758
18144
  while (true) {
17759
- if (semaphore)
17760
- yield* semaphore.take(1);
17761
- const channel = yield* pull;
18145
+ let pullFiber;
18146
+ if (semaphore) {
18147
+ if (fibers.size < concurrencyN) {
18148
+ yield* semaphore.take(1);
18149
+ } else {
18150
+ pullFiber = yield* forkChild2(pull);
18151
+ yield* raceFirst2(semaphore.take(1), andThen4(join(pullFiber), never2));
18152
+ }
18153
+ }
18154
+ const channel = pullFiber === undefined ? yield* pull : yield* join(pullFiber);
17762
18155
  const childScope = forkUnsafe2(forkedScope);
17763
18156
  const childPull = yield* toTransform(channel)(upstream, childScope);
17764
18157
  while (fibers.size >= concurrencyN) {
@@ -17787,7 +18180,13 @@ var mergeAll3 = /* @__PURE__ */ dual(2, (channels, {
17787
18180
  doneLatch.closeUnsafe();
17788
18181
  fibers.add(fiber3);
17789
18182
  }
17790
- }).pipe(catchCause3((cause) => doneLatch.whenOpen(failCause5(queue, cause))), forkIn2(forkedScope));
18183
+ }).pipe(catchCause3((cause) => {
18184
+ const halt = filterDone(cause);
18185
+ if (isSuccess2(halt)) {
18186
+ return doneLatch.whenOpen(failCause5(queue, cause));
18187
+ }
18188
+ return failCause5(queue, cause);
18189
+ }), forkIn2(forkedScope));
17791
18190
  return take3(queue);
17792
18191
  })));
17793
18192
  var merge4 = /* @__PURE__ */ dual((args2) => isChannel(args2[0]) && isChannel(args2[1]), (left, right, options) => fromTransformBracket(fnUntraced2(function* (upstream, _scope, forkedScope) {
@@ -17904,8 +18303,8 @@ var splitLines = () => fromTransform((upstream, _scope) => sync3(() => {
17904
18303
  }));
17905
18304
  var pipeTo = /* @__PURE__ */ dual(2, (self, that) => fromTransform((upstream, scope3) => flatMap5(toTransform(self)(upstream, scope3), (upstream2) => toTransform(that)(upstream2, scope3))));
17906
18305
  var pipeToOrFail = /* @__PURE__ */ dual(2, (self, that) => fromTransform((upstream, scope3) => flatMap5(toTransform(self)(upstream, scope3), (upstream2) => {
17907
- const upstreamPull = catchCause3(upstream2, (cause) => isDoneCause(cause) ? failCause4(cause) : die3(Done2(cause)));
17908
- return map5(toTransform(that)(upstreamPull, scope3), (pull) => catchDefect2(pull, (defect) => isDone3(defect) ? failCause4(defect.value) : die3(defect)));
18306
+ const upstreamPull = catchCause3(upstream2, (cause) => isDoneCause(cause) ? failCause4(cause) : die4(Done2(cause)));
18307
+ return map5(toTransform(that)(upstreamPull, scope3), (pull) => catchDefect2(pull, (defect) => isDone3(defect) ? failCause4(defect.value) : die4(defect)));
17909
18308
  })));
17910
18309
  var unwrap2 = (channel) => fromTransform((upstream, scope3) => {
17911
18310
  let pull;
@@ -17945,12 +18344,16 @@ var interruptWhen = /* @__PURE__ */ dual(2, (self, effect2) => merge4(self, from
17945
18344
  }));
17946
18345
  var haltWhen = /* @__PURE__ */ dual(2, (self, effect2) => fromTransformBracket(fnUntraced2(function* (upstream, scope3, forkedScope) {
17947
18346
  const pull = yield* toTransform(self)(upstream, scope3);
17948
- let haltCause = undefined;
17949
- yield* effect2.pipe(catchCause3((cause) => {
17950
- haltCause = cause;
17951
- return void_5;
17952
- }), forkIn2(forkedScope));
17953
- return suspend3(() => haltCause ? failCause4(haltCause) : pull);
18347
+ const fiber3 = yield* forkIn2(effect2, forkedScope, {
18348
+ startImmediately: true
18349
+ });
18350
+ return suspend3(() => {
18351
+ const exit3 = fiber3.pollUnsafe();
18352
+ return exit3 === undefined ? pull : match5(exit3, {
18353
+ onFailure: failCause4,
18354
+ onSuccess: done3
18355
+ });
18356
+ });
17954
18357
  })));
17955
18358
  var onError3 = /* @__PURE__ */ dual(2, (self, finalizer) => onExit3(self, (exit3) => isFailure4(exit3) ? finalizer(exit3.cause) : void_5));
17956
18359
  var onExit3 = /* @__PURE__ */ dual(2, (self, finalizer) => fromTransformBracket((upstream, scope3, forkedScope) => addFinalizerExit(forkedScope, finalizer).pipe(andThen4(toTransform(self)(upstream, scope3)))));
@@ -18002,6 +18405,28 @@ var runForEach = /* @__PURE__ */ dual(2, (self, f) => runWith(self, (pull) => fo
18002
18405
  var runForEachWhile = /* @__PURE__ */ dual(2, (self, f) => runWith(self, (pull) => pull.pipe(flatMap5(f), flatMap5((cont) => cont ? void_5 : done3()), forever4({
18003
18406
  disableYield: true
18004
18407
  }))));
18408
+ var mkUint8Array = (self) => map5(runFold(self, () => ({
18409
+ bytes: 0,
18410
+ arrays: []
18411
+ }), (acc, chunk) => {
18412
+ for (let i = 0;i < chunk.length; i++) {
18413
+ acc.bytes += chunk[i].length;
18414
+ acc.arrays.push(chunk[i]);
18415
+ }
18416
+ return acc;
18417
+ }), ({
18418
+ arrays,
18419
+ bytes
18420
+ }) => {
18421
+ const result3 = new Uint8Array(bytes);
18422
+ let offset = 0;
18423
+ for (let i = 0;i < arrays.length; i++) {
18424
+ const array2 = arrays[i];
18425
+ result3.set(array2, offset);
18426
+ offset += array2.length;
18427
+ }
18428
+ return result3;
18429
+ });
18005
18430
  var runHead = (self) => suspend3(() => {
18006
18431
  let head = none2();
18007
18432
  return runWith(self, (pull) => pull.pipe(asSome2, flatMap5((head_) => {
@@ -18080,15 +18505,15 @@ var toPubSubTake = /* @__PURE__ */ dual(2, /* @__PURE__ */ fnUntraced2(function*
18080
18505
  return pubsub;
18081
18506
  }));
18082
18507
 
18083
- // ../../node_modules/.bun/effect@4.0.0-beta.98/node_modules/effect/dist/internal/stream.js
18084
- var TypeId18 = "~effect/Stream";
18508
+ // ../../node_modules/.bun/effect@4.0.0-beta.107/node_modules/effect/dist/internal/stream.js
18509
+ var TypeId17 = "~effect/Stream";
18085
18510
  var streamVariance = {
18086
18511
  _R: identity,
18087
18512
  _E: identity,
18088
18513
  _A: identity
18089
18514
  };
18090
18515
  var StreamProto = {
18091
- [TypeId18]: streamVariance,
18516
+ [TypeId17]: streamVariance,
18092
18517
  pipe() {
18093
18518
  return pipeArguments(this, arguments);
18094
18519
  }
@@ -18099,8 +18524,8 @@ var fromChannel = (channel) => {
18099
18524
  return self;
18100
18525
  };
18101
18526
 
18102
- // ../../node_modules/.bun/effect@4.0.0-beta.98/node_modules/effect/dist/Sink.js
18103
- var TypeId19 = "~effect/Sink";
18527
+ // ../../node_modules/.bun/effect@4.0.0-beta.107/node_modules/effect/dist/Sink.js
18528
+ var TypeId18 = "~effect/Sink";
18104
18529
  var endVoid = /* @__PURE__ */ succeed6([undefined]);
18105
18530
  var sinkVariance = {
18106
18531
  _A: identity,
@@ -18110,12 +18535,12 @@ var sinkVariance = {
18110
18535
  _R: identity
18111
18536
  };
18112
18537
  var SinkProto = {
18113
- [TypeId19]: sinkVariance,
18538
+ [TypeId18]: sinkVariance,
18114
18539
  pipe() {
18115
18540
  return pipeArguments(this, arguments);
18116
18541
  }
18117
18542
  };
18118
- var isSink = (u) => hasProperty(u, TypeId19);
18543
+ var isSink = (u) => hasProperty(u, TypeId18);
18119
18544
  var fromChannel2 = (channel) => fromTransform2((upstream, scope3) => toTransform(channel)(upstream, scope3).pipe(flatMap5(forever4({
18120
18545
  disableYield: true
18121
18546
  })), catchDone(succeed6)));
@@ -18166,7 +18591,7 @@ var forEachArray = (f) => fromTransform2((upstream) => upstream.pipe(flatMap5(f)
18166
18591
  }), catchDone(() => endVoid)));
18167
18592
  var unwrap3 = (effect2) => fromChannel2(unwrap2(map5(effect2, toChannel)));
18168
18593
 
18169
- // ../../node_modules/.bun/effect@4.0.0-beta.98/node_modules/effect/dist/Stream.js
18594
+ // ../../node_modules/.bun/effect@4.0.0-beta.107/node_modules/effect/dist/Stream.js
18170
18595
  var exports_Stream = {};
18171
18596
  __export(exports_Stream, {
18172
18597
  zipWithPreviousAndNext: () => zipWithPreviousAndNext,
@@ -18279,8 +18704,9 @@ __export(exports_Stream, {
18279
18704
  onError: () => onError4,
18280
18705
  onEnd: () => onEnd2,
18281
18706
  never: () => never4,
18282
- mkUint8Array: () => mkUint8Array,
18707
+ mkUint8Array: () => mkUint8Array2,
18283
18708
  mkString: () => mkString,
18709
+ mkArrayBuffer: () => mkArrayBuffer,
18284
18710
  mergeRight: () => mergeRight,
18285
18711
  mergeResult: () => mergeResult,
18286
18712
  mergeLeft: () => mergeLeft,
@@ -18298,6 +18724,7 @@ __export(exports_Stream, {
18298
18724
  mapAccum: () => mapAccum2,
18299
18725
  map: () => map7,
18300
18726
  make: () => make16,
18727
+ limitBytes: () => limitBytes,
18301
18728
  let: () => let_6,
18302
18729
  iterate: () => iterate,
18303
18730
  isStream: () => isStream,
@@ -18316,7 +18743,7 @@ __export(exports_Stream, {
18316
18743
  groupAdjacentBy: () => groupAdjacentBy,
18317
18744
  fromSubscription: () => fromSubscription,
18318
18745
  fromSchedule: () => fromSchedule,
18319
- fromReadableStream: () => fromReadableStream,
18746
+ fromReadableStream: () => fromReadableStream2,
18320
18747
  fromQueue: () => fromQueue,
18321
18748
  fromPull: () => fromPull2,
18322
18749
  fromPubSubTake: () => fromPubSubTake2,
@@ -18340,7 +18767,7 @@ __export(exports_Stream, {
18340
18767
  flattenIterable: () => flattenIterable,
18341
18768
  flattenEffect: () => flattenEffect,
18342
18769
  flattenArray: () => flattenArray2,
18343
- flatten: () => flatten5,
18770
+ flatten: () => flatten6,
18344
18771
  flatMap: () => flatMap7,
18345
18772
  filterMapEffect: () => filterMapEffect3,
18346
18773
  filterMap: () => filterMap4,
@@ -18362,7 +18789,7 @@ __export(exports_Stream, {
18362
18789
  drop: () => drop,
18363
18790
  drainFork: () => drainFork,
18364
18791
  drain: () => drain3,
18365
- die: () => die5,
18792
+ die: () => die6,
18366
18793
  decodeText: () => decodeText,
18367
18794
  debounce: () => debounce,
18368
18795
  crossWith: () => crossWith,
@@ -18396,15 +18823,15 @@ __export(exports_Stream, {
18396
18823
  aggregateWithin: () => aggregateWithin,
18397
18824
  aggregate: () => aggregate,
18398
18825
  accumulate: () => accumulate,
18399
- TypeId: () => TypeId23,
18826
+ TypeId: () => TypeId22,
18400
18827
  Do: () => Do5,
18401
18828
  DefaultChunkSize: () => DefaultChunkSize2
18402
18829
  });
18403
18830
 
18404
- // ../../node_modules/.bun/effect@4.0.0-beta.98/node_modules/effect/dist/MutableHashMap.js
18405
- var TypeId20 = "~effect/collections/MutableHashMap";
18831
+ // ../../node_modules/.bun/effect@4.0.0-beta.107/node_modules/effect/dist/MutableHashMap.js
18832
+ var TypeId19 = "~effect/collections/MutableHashMap";
18406
18833
  var MutableHashMapProto = {
18407
- [TypeId20]: TypeId20,
18834
+ [TypeId19]: TypeId19,
18408
18835
  [Symbol.iterator]() {
18409
18836
  return this.backing[Symbol.iterator]();
18410
18837
  },
@@ -18524,10 +18951,10 @@ var clear2 = (self) => {
18524
18951
  };
18525
18952
  var size = (self) => self.backing.size;
18526
18953
 
18527
- // ../../node_modules/.bun/effect@4.0.0-beta.98/node_modules/effect/dist/RcMap.js
18528
- var TypeId21 = "~effect/RcMap";
18954
+ // ../../node_modules/.bun/effect@4.0.0-beta.107/node_modules/effect/dist/RcMap.js
18955
+ var TypeId20 = "~effect/RcMap";
18529
18956
  var makeUnsafe6 = (options) => ({
18530
- [TypeId21]: TypeId21,
18957
+ [TypeId20]: TypeId20,
18531
18958
  lookup: options.lookup,
18532
18959
  context: options.context,
18533
18960
  scope: options.scope,
@@ -18643,8 +19070,8 @@ var touch = /* @__PURE__ */ dual(2, (self, key) => clockWith2((clock) => {
18643
19070
  return void_5;
18644
19071
  }));
18645
19072
 
18646
- // ../../node_modules/.bun/effect@4.0.0-beta.98/node_modules/effect/dist/internal/rcRef.js
18647
- var TypeId22 = "~effect/RcRef";
19073
+ // ../../node_modules/.bun/effect@4.0.0-beta.107/node_modules/effect/dist/internal/rcRef.js
19074
+ var TypeId21 = "~effect/RcRef";
18648
19075
  var stateEmpty = {
18649
19076
  _tag: "Empty"
18650
19077
  };
@@ -18657,7 +19084,7 @@ var variance2 = {
18657
19084
  };
18658
19085
 
18659
19086
  class RcRefImpl {
18660
- [TypeId22] = variance2;
19087
+ [TypeId21] = variance2;
18661
19088
  pipe() {
18662
19089
  return pipeArguments(this, arguments);
18663
19090
  }
@@ -18684,7 +19111,7 @@ var make14 = (options) => withFiber2((fiber3) => {
18684
19111
  return close2;
18685
19112
  }), ref);
18686
19113
  });
18687
- var getState = (self) => uninterruptibleMask2((restore) => {
19114
+ var getState = (self) => uninterruptibleMask2(function loop(restore) {
18688
19115
  switch (self.state._tag) {
18689
19116
  case "Closed": {
18690
19117
  return interrupt3;
@@ -18695,18 +19122,23 @@ var getState = (self) => uninterruptibleMask2((restore) => {
18695
19122
  }
18696
19123
  case "Empty": {
18697
19124
  const scope3 = makeUnsafe3();
18698
- return self.semaphore.withPermits(1)(restore(provideContext2(self.acquire, add(self.context, Scope, scope3))).pipe(map5((value) => {
18699
- const state = {
18700
- _tag: "Acquired",
18701
- value,
18702
- scope: scope3,
18703
- fiber: undefined,
18704
- refCount: 1,
18705
- invalidated: false
18706
- };
18707
- self.state = state;
18708
- return state;
18709
- })));
19125
+ return self.semaphore.withPermit(suspend3(() => {
19126
+ if (self.state._tag !== "Empty") {
19127
+ return loop(restore);
19128
+ }
19129
+ return restore(provideContext2(self.acquire, add(self.context, Scope, scope3))).pipe(map5((value) => {
19130
+ const state = {
19131
+ _tag: "Acquired",
19132
+ value,
19133
+ scope: scope3,
19134
+ fiber: undefined,
19135
+ refCount: 1,
19136
+ invalidated: false
19137
+ };
19138
+ self.state = state;
19139
+ return state;
19140
+ }), onExit2((exit3) => isFailure4(exit3) ? close(scope3, exit3) : void_5));
19141
+ }));
18710
19142
  }
18711
19143
  }
18712
19144
  });
@@ -18742,13 +19174,13 @@ var get5 = /* @__PURE__ */ fnUntraced2(function* (self_) {
18742
19174
  return state.value;
18743
19175
  });
18744
19176
 
18745
- // ../../node_modules/.bun/effect@4.0.0-beta.98/node_modules/effect/dist/RcRef.js
19177
+ // ../../node_modules/.bun/effect@4.0.0-beta.107/node_modules/effect/dist/RcRef.js
18746
19178
  var make15 = make14;
18747
19179
  var get6 = get5;
18748
19180
 
18749
- // ../../node_modules/.bun/effect@4.0.0-beta.98/node_modules/effect/dist/Stream.js
18750
- var TypeId23 = "~effect/Stream";
18751
- var isStream = (u) => hasProperty(u, TypeId23);
19181
+ // ../../node_modules/.bun/effect@4.0.0-beta.107/node_modules/effect/dist/Stream.js
19182
+ var TypeId22 = "~effect/Stream";
19183
+ var isStream = (u) => hasProperty(u, TypeId22);
18752
19184
  var DefaultChunkSize2 = DefaultChunkSize;
18753
19185
  var fromChannel3 = fromChannel;
18754
19186
  var fromEffect2 = (effect2) => fromChannel3(fromEffect(map5(effect2, of)));
@@ -18797,7 +19229,7 @@ var suspend5 = (stream) => fromChannel3(suspend4(() => stream().channel));
18797
19229
  var fail9 = (error) => fromChannel3(fail7(error));
18798
19230
  var failSync4 = (evaluate2) => fromChannel3(failSync3(evaluate2));
18799
19231
  var failCause7 = (cause) => fromChannel3(failCause6(cause));
18800
- var die5 = (defect) => fromChannel3(die4(defect));
19232
+ var die6 = (defect) => fromChannel3(die5(defect));
18801
19233
  var failCauseSync4 = (evaluate2) => fromChannel3(failCauseSync3(evaluate2));
18802
19234
  var fromIteratorSucceed = (iterator, maxChunkSize) => fromChannel3(fromIteratorArray(() => iterator, maxChunkSize));
18803
19235
  var fromIterable3 = (iterable, options) => Array.isArray(iterable) && options?.chunkSize === undefined ? fromArray2(iterable) : fromChannel3(fromIterableArray(iterable, options?.chunkSize));
@@ -18809,17 +19241,7 @@ var fromArrays = (...arrays) => fromChannel3(fromArray(filter3(arrays, isReadonl
18809
19241
  var fromQueue = (queue) => fromChannel3(fromQueueArray(queue));
18810
19242
  var fromPubSub = (pubsub) => fromChannel3(fromPubSubArray(pubsub));
18811
19243
  var fromPubSubTake2 = (pubsub) => fromChannel3(fromPubSubTake(pubsub));
18812
- var fromReadableStream = (options) => fromChannel3(fromTransform(fnUntraced2(function* (_, scope3) {
18813
- const reader = options.evaluate().getReader();
18814
- yield* addFinalizer2(scope3, options.releaseLockOnEnd ? sync3(() => reader.releaseLock()) : promise2(() => reader.cancel().catch(constVoid)));
18815
- return flatMap5(tryPromise2({
18816
- try: () => reader.read(),
18817
- catch: (reason) => options.onError(reason)
18818
- }), ({
18819
- done: done4,
18820
- value
18821
- }) => done4 ? done3() : succeed6(of(value)));
18822
- })));
19244
+ var fromReadableStream2 = (options) => fromChannel3(fromReadableStream(options));
18823
19245
  var fromAsyncIterable2 = (iterable, onError4) => fromChannel3(fromAsyncIterableArray(iterable, onError4));
18824
19246
  var fromSchedule = (schedule3) => fromPull2(map5(toStepWithSleep(schedule3), (step) => catchDone(map5(step(undefined), of), () => done3())));
18825
19247
  var fromSubscription = (pubsub) => fromChannel3(fromSubscriptionArray(pubsub));
@@ -18860,15 +19282,16 @@ var paginate = (s, f) => fromPull2(sync3(() => {
18860
19282
  }));
18861
19283
  var iterate = (value, next) => unfold(value, (a) => succeed6([a, next(a)]));
18862
19284
  var range2 = (min2, max2, chunkSize = DefaultChunkSize) => min2 > max2 ? empty6 : fromPull2(sync3(() => {
19285
+ const size2 = Math.max(1, chunkSize);
18863
19286
  let start = min2;
18864
19287
  let done4 = false;
18865
19288
  return suspend3(() => {
18866
19289
  if (done4)
18867
19290
  return done3();
18868
19291
  const remaining = max2 - start + 1;
18869
- if (remaining > chunkSize) {
18870
- const chunk2 = range(start, start + chunkSize - 1);
18871
- start += chunkSize;
19292
+ if (remaining > size2) {
19293
+ const chunk2 = range(start, start + size2 - 1);
19294
+ start += size2;
18872
19295
  return succeed6(chunk2);
18873
19296
  }
18874
19297
  const chunk = range(start, start + remaining - 1);
@@ -18939,7 +19362,7 @@ var tapSink = /* @__PURE__ */ dual(2, (self, sink) => transformPullBracket(self,
18939
19362
  })));
18940
19363
  var flatMap7 = /* @__PURE__ */ dual((args2) => isStream(args2[0]), (self, f, options) => self.channel.pipe(flattenArray, flatMap6((a) => f(a).channel, options), fromChannel3));
18941
19364
  var switchMap2 = /* @__PURE__ */ dual((args2) => isStream(args2[0]), (self, f, options) => self.channel.pipe(flattenArray, switchMap((a) => f(a).channel, options), fromChannel3));
18942
- var flatten5 = /* @__PURE__ */ dual((args2) => isStream(args2[0]), (self, options) => flatMap7(self, identity, options));
19365
+ var flatten6 = /* @__PURE__ */ dual((args2) => isStream(args2[0]), (self, options) => flatMap7(self, identity, options));
18943
19366
  var flattenArray2 = (self) => fromChannel3(flattenArray(self.channel));
18944
19367
  var drain3 = (self) => fromChannel3(drain(self.channel));
18945
19368
  var drainFork = /* @__PURE__ */ dual(2, (self, that) => mergeEffect2(self, runDrain2(that)));
@@ -18981,7 +19404,7 @@ var timeoutOrElse3 = /* @__PURE__ */ dual(2, (self, options) => {
18981
19404
  const remaining = deadline - clock.currentTimeMillisUnsafe();
18982
19405
  if (remaining > 0)
18983
19406
  continue;
18984
- return yield* die3(timeoutSymbol);
19407
+ return yield* die4(timeoutSymbol);
18985
19408
  }
18986
19409
  })), {
18987
19410
  haltStrategy: "left"
@@ -19010,14 +19433,14 @@ var repeatElements = /* @__PURE__ */ dual(2, (self, schedule4) => fromChannel3(f
19010
19433
  var forever6 = (self) => fromChannel3(forever5(self.channel));
19011
19434
  var flattenIterable = (self) => flatMap7(self, fromIterable3);
19012
19435
  var flattenTake2 = (self) => self.channel.pipe(flattenArray, flattenTake, fromChannel3);
19013
- var concat = /* @__PURE__ */ dual(2, (self, that) => flatten5(fromArray2([self, that])));
19436
+ var concat = /* @__PURE__ */ dual(2, (self, that) => flatten6(fromArray2([self, that])));
19014
19437
  var prepend2 = /* @__PURE__ */ dual(2, (self, values) => concat(fromIterable3(values), self));
19015
19438
  var merge5 = /* @__PURE__ */ dual((args2) => isStream(args2[0]) && isStream(args2[1]), (self, that, options) => fromChannel3(merge4(toChannel2(self), toChannel2(that), options)));
19016
19439
  var mergeEffect2 = /* @__PURE__ */ dual(2, (self, effect2) => self.channel.pipe(mergeEffect(effect2), fromChannel3));
19017
19440
  var mergeResult = /* @__PURE__ */ dual(2, (self, that) => merge5(map7(self, succeed2), map7(that, fail2)));
19018
19441
  var mergeLeft = /* @__PURE__ */ dual(2, (left, right) => mergeEffect2(left, runDrain2(right)));
19019
19442
  var mergeRight = /* @__PURE__ */ dual(2, (left, right) => mergeEffect2(right, runDrain2(left)));
19020
- var mergeAll4 = /* @__PURE__ */ dual(2, (streams, options) => flatten5(fromIterable3(streams), options));
19443
+ var mergeAll4 = /* @__PURE__ */ dual(2, (streams, options) => flatten6(fromIterable3(streams), options));
19021
19444
  var cross = /* @__PURE__ */ dual(2, (left, right) => crossWith(left, right, (l, r) => [l, r]));
19022
19445
  var crossWith = /* @__PURE__ */ dual(3, (left, right, f) => flatMap7(left, (l) => map7(right, (r) => f(l, r))));
19023
19446
  var zipWith4 = /* @__PURE__ */ dual(3, (left, right, f) => zipWithArray(left, right, zipArrays(f)));
@@ -19262,7 +19685,7 @@ var catchTags3 = /* @__PURE__ */ dual((args2) => isStream(args2[0]), (self, case
19262
19685
  });
19263
19686
  var catchReason4 = /* @__PURE__ */ dual((args2) => isStream(args2[0]), (self, errorTag, reasonTag, f, orElse3) => fromChannel3(catchReason3(toChannel2(self), errorTag, reasonTag, (reason, error) => f(reason, error).channel, orElse3 && ((reason, error) => orElse3(reason, error).channel))));
19264
19687
  var catchReasons4 = /* @__PURE__ */ dual((args2) => isStream(args2[0]), (self, errorTag, cases, orElse3) => {
19265
- const handlers = {};
19688
+ const handlers = Object.create(null);
19266
19689
  for (const key of Object.keys(cases)) {
19267
19690
  const handler = cases[key];
19268
19691
  handlers[key] = (reason, error) => handler(reason, error).channel;
@@ -19279,6 +19702,14 @@ var orDie5 = (self) => fromChannel3(orDie4(self.channel));
19279
19702
  var ignore4 = /* @__PURE__ */ dual((args2) => isStream(args2[0]), (self, options) => fromChannel3(ignore3(self.channel, options)));
19280
19703
  var ignoreCause4 = /* @__PURE__ */ dual((args2) => isStream(args2[0]), (self, options) => fromChannel3(ignoreCause3(self.channel, options)));
19281
19704
  var retry4 = /* @__PURE__ */ dual(2, (self, policy) => fromChannel3(retry3(self.channel, policy)));
19705
+ var retryWithoutReset = (self, schedule4) => unwrap4(map5(toStepWithMetadata(schedule4), (step) => {
19706
+ let meta = CurrentMetadata2.defaultValue();
19707
+ const loop = () => catch_5(provideServiceEffect4(self, CurrentMetadata2, sync3(() => meta)), (error) => unwrap4(catchDone(map5(step(error), (meta_) => {
19708
+ meta = meta_;
19709
+ return unwrap4(as3(yieldNow2, loop()));
19710
+ }), () => succeed6(fail9(error)))));
19711
+ return loop();
19712
+ }));
19282
19713
  var withExecutionPlan3 = /* @__PURE__ */ dual((args2) => isStream(args2[0]), (self, policy, options) => suspend5(() => {
19283
19714
  const preventFallbackOnPartialStream = options?.preventFallbackOnPartialStream ?? false;
19284
19715
  let i = 0;
@@ -19293,13 +19724,24 @@ var withExecutionPlan3 = /* @__PURE__ */ dual((args2) => isStream(args2[0]), (se
19293
19724
  };
19294
19725
  return meta;
19295
19726
  }));
19727
+ const emitter = options?.onEvent === undefined ? undefined : makeEventEmitter(options.onEvent, () => meta);
19728
+ let attemptState;
19729
+ const instrument = emitter === undefined ? identity : (attempt) => onExit4(onStart2(attempt, map5(emitter.begin, (state) => {
19730
+ attemptState = state;
19731
+ })), (exit3) => suspend3(() => {
19732
+ if (attemptState === undefined)
19733
+ return void_5;
19734
+ const state = attemptState;
19735
+ attemptState = undefined;
19736
+ return emitter.end(state, exit3);
19737
+ }));
19296
19738
  let lastError = none2();
19297
19739
  const loop = suspend5(() => {
19298
19740
  const step = policy.steps[i];
19299
19741
  if (!step) {
19300
19742
  return fail9(getOrThrow(lastError));
19301
19743
  }
19302
- let nextStream = provideMeta(provide6(self, step.provide));
19744
+ let nextStream = provideMeta(instrument(provide6(self, step.provide)));
19303
19745
  let receivedElements = false;
19304
19746
  if (isSome2(lastError)) {
19305
19747
  const error = lastError.value;
@@ -19311,10 +19753,10 @@ var withExecutionPlan3 = /* @__PURE__ */ dual((args2) => isStream(args2[0]), (se
19311
19753
  attempted = true;
19312
19754
  return fail9(error);
19313
19755
  });
19314
- nextStream = retry4(nextStream, scheduleFromStep(step, false));
19756
+ nextStream = retryWithoutReset(nextStream, scheduleFromStep(step, false));
19315
19757
  } else {
19316
19758
  const schedule4 = scheduleFromStep(step, true);
19317
- nextStream = schedule4 ? retry4(nextStream, schedule4) : nextStream;
19759
+ nextStream = schedule4 ? retryWithoutReset(nextStream, schedule4) : nextStream;
19318
19760
  }
19319
19761
  return catch_5(preventFallbackOnPartialStream ? onFirst2(nextStream, (_) => {
19320
19762
  receivedElements = true;
@@ -19331,7 +19773,21 @@ var withExecutionPlan3 = /* @__PURE__ */ dual((args2) => isStream(args2[0]), (se
19331
19773
  return loop;
19332
19774
  }));
19333
19775
  var take5 = /* @__PURE__ */ dual(2, (self, n) => n < 1 ? empty6 : takeUntil(self, (_, i) => i === n - 1));
19334
- var takeRight = /* @__PURE__ */ dual(2, (self, n) => mapAccumArray(self, make9, (list, arr) => {
19776
+ var limitBytes = /* @__PURE__ */ dual(3, (self, bytes, onLimitReached) => suspend5(() => {
19777
+ const limit = BigInt(bytes);
19778
+ let size2 = BigInt(0);
19779
+ let limitReached = false;
19780
+ return concat(takeWhile(self, (chunk) => {
19781
+ const nextSize = size2 + BigInt(chunk.length);
19782
+ if (nextSize > limit) {
19783
+ limitReached = true;
19784
+ return false;
19785
+ }
19786
+ size2 = nextSize;
19787
+ return true;
19788
+ }), suspend5(() => limitReached ? onLimitReached() : empty6));
19789
+ }));
19790
+ var takeRight = /* @__PURE__ */ dual(2, (self, n) => mapAccumArray(self, make10, (list, arr) => {
19335
19791
  appendAll2(list, arr);
19336
19792
  if (list.length > n) {
19337
19793
  takeNVoid(list, list.length - n);
@@ -19466,7 +19922,7 @@ var dropRight = /* @__PURE__ */ dual(2, (self, n) => {
19466
19922
  if (n <= 0)
19467
19923
  return self;
19468
19924
  return transformPull2(self, (pull, _scope) => sync3(() => {
19469
- const list = make9();
19925
+ const list = make10();
19470
19926
  const emit = flatMap5(pull, (arr) => {
19471
19927
  appendAllUnsafe(list, arr);
19472
19928
  const toTake = list.length - n;
@@ -19523,11 +19979,17 @@ var rechunk = /* @__PURE__ */ dual(2, (self, target) => {
19523
19979
  var sliding2 = /* @__PURE__ */ dual(2, (self, chunkSize) => slidingSize(self, chunkSize, 1));
19524
19980
  var slidingSize = /* @__PURE__ */ dual(3, (self, chunkSize, stepSize) => transformPull2(self, (upstream, _scope) => sync3(() => {
19525
19981
  let cause = null;
19526
- const list = make9();
19982
+ const list = make10();
19527
19983
  let emitted = false;
19984
+ let skip = 0;
19528
19985
  const pull = matchCauseEffect2(upstream, {
19529
19986
  onSuccess(arr) {
19530
19987
  appendAllUnsafe(list, arr);
19988
+ if (skip > 0) {
19989
+ const length = list.length;
19990
+ takeNVoid(list, skip);
19991
+ skip = Math.max(0, skip - length);
19992
+ }
19531
19993
  if (list.length < chunkSize)
19532
19994
  return pull;
19533
19995
  emitted = true;
@@ -19537,10 +19999,12 @@ var slidingSize = /* @__PURE__ */ dual(3, (self, chunkSize, stepSize) => transfo
19537
19999
  chunks2.push(takeN(list, chunkSize));
19538
20000
  } else {
19539
20001
  chunks2.push(toArrayN(list, chunkSize));
19540
- if (chunkSize === 1) {
20002
+ if (chunkSize === 1 && stepSize <= 0) {
19541
20003
  take(list);
19542
20004
  } else {
20005
+ const length = list.length;
19543
20006
  takeNVoid(list, stepSize);
20007
+ skip = Math.max(0, stepSize - length);
19544
20008
  }
19545
20009
  }
19546
20010
  }
@@ -19608,7 +20072,7 @@ var mapAccumEffect = /* @__PURE__ */ dual((args2) => isStream(args2[0]), (self,
19608
20072
  return isReadonlyArrayNonEmpty(arr) ? of(arr) : emptyArr;
19609
20073
  }
19610
20074
  } : undefined), fromChannel3));
19611
- var mapAccumArrayEffect = /* @__PURE__ */ dual((args2) => isStream(args2), (self, initial, f, options) => self.channel.pipe(mapAccum(initial, (state, a) => map5(f(state, a), ([state2, values]) => [state2, isReadonlyArrayNonEmpty(values) ? of(values) : emptyArr]), options?.onHalt ? {
20075
+ var mapAccumArrayEffect = /* @__PURE__ */ dual((args2) => isStream(args2[0]), (self, initial, f, options) => self.channel.pipe(mapAccum(initial, (state, a) => map5(f(state, a), ([state2, values]) => [state2, isReadonlyArrayNonEmpty(values) ? of(values) : emptyArr]), options?.onHalt ? {
19612
20076
  onHalt(state) {
19613
20077
  const arr = options.onHalt(state);
19614
20078
  return isReadonlyArrayNonEmpty(arr) ? of(arr) : emptyArr;
@@ -19874,9 +20338,10 @@ var aggregateWithin = /* @__PURE__ */ dual(3, (self, sink, schedule4) => fromCha
19874
20338
  let leftover;
19875
20339
  let sinkHasInput = false;
19876
20340
  const step = yield* toStepWithSleep(schedule4);
19877
- const stepToBuffer = suspend3(function loop() {
19878
- return step(lastOutput).pipe(flatMap5(() => !sinkHasInput ? loop() : offer(buffer3, scheduleStep)), flatMap5(() => never2), catchDone(() => done3()));
20341
+ const stepLoop = suspend3(function loop() {
20342
+ return flatMap5(step(lastOutput), () => !sinkHasInput ? loop() : offer(buffer3, scheduleStep));
19879
20343
  });
20344
+ const stepToBuffer = stepLoop.pipe(flatMap5(() => never2), catchDone(() => done3()));
19880
20345
  const pullFromBuffer = take3(buffer3).pipe(flatMap5((arr) => {
19881
20346
  if (arr === scheduleStep) {
19882
20347
  return done3();
@@ -20134,28 +20599,8 @@ var runForEachArray = /* @__PURE__ */ dual(2, (self, f) => runForEach(self.chann
20134
20599
  var runDrain2 = (self) => runDrain(self.channel);
20135
20600
  var toPull3 = (self) => toPull2(self.channel);
20136
20601
  var mkString = (self) => runFold(self.channel, () => "", (acc, chunk) => acc + chunk.join(""));
20137
- var mkUint8Array = (self) => map5(runFold(self.channel, () => ({
20138
- bytes: 0,
20139
- arrays: []
20140
- }), (acc, chunk) => {
20141
- for (let i = 0;i < chunk.length; i++) {
20142
- acc.bytes += chunk[i].length;
20143
- acc.arrays.push(chunk[i]);
20144
- }
20145
- return acc;
20146
- }), ({
20147
- arrays,
20148
- bytes
20149
- }) => {
20150
- const result4 = new Uint8Array(bytes);
20151
- let offset = 0;
20152
- for (let i = 0;i < arrays.length; i++) {
20153
- const array2 = arrays[i];
20154
- result4.set(array2, offset);
20155
- offset += array2.length;
20156
- }
20157
- return result4;
20158
- });
20602
+ var mkArrayBuffer = (self) => map5(mkUint8Array(self.channel), (bytes) => bytes.buffer);
20603
+ var mkUint8Array2 = (self) => mkUint8Array(self.channel);
20159
20604
  var toReadableStreamWith = /* @__PURE__ */ dual((args2) => isStream(args2[0]), (self, context3, options) => {
20160
20605
  let currentResolve = undefined;
20161
20606
  let fiber3 = undefined;
@@ -20196,36 +20641,66 @@ var toReadableStreamEffect = /* @__PURE__ */ dual((args2) => isStream(args2[0]),
20196
20641
  var toAsyncIterableWith = /* @__PURE__ */ dual(2, (self, context3) => ({
20197
20642
  [Symbol.asyncIterator]() {
20198
20643
  const runPromise3 = runPromiseWith2(context3);
20199
- const runPromiseExit3 = runPromiseExitWith2(context3);
20644
+ const runFork3 = runForkWith2(context3);
20200
20645
  const scope3 = makeUnsafe3();
20201
20646
  let pull;
20202
20647
  let currentIter;
20648
+ let currentFiber;
20649
+ let closePromise;
20650
+ const close2 = (exit3) => {
20651
+ if (closePromise)
20652
+ return closePromise;
20653
+ const fiber3 = currentFiber;
20654
+ closePromise = runPromise3(as3(andThen4(fiber3 ? interrupt4(fiber3) : void_5, close(scope3, exit3)), {
20655
+ done: true,
20656
+ value: undefined
20657
+ }));
20658
+ return closePromise;
20659
+ };
20660
+ const closeAndReportError = async (exit3) => {
20661
+ try {
20662
+ await close2(exit3);
20663
+ } catch (error) {
20664
+ await runPromise3(logError("Suppressed error while closing Stream async iterator", error));
20665
+ }
20666
+ };
20203
20667
  return {
20204
20668
  async next() {
20669
+ if (closePromise)
20670
+ return closePromise;
20205
20671
  if (currentIter) {
20206
20672
  const next = currentIter.next();
20207
20673
  if (!next.done)
20208
20674
  return next;
20209
20675
  currentIter = undefined;
20210
20676
  }
20211
- pull ??= await runPromise3(toPullScoped(self.channel, scope3));
20212
- const exit3 = await runPromiseExit3(pull);
20677
+ const fiber3 = runFork3(pull ?? flatMap5(toPullScoped(self.channel, scope3), (nextPull) => {
20678
+ pull = nextPull;
20679
+ return nextPull;
20680
+ }));
20681
+ currentFiber = fiber3;
20682
+ const exit3 = await runPromise3(await_(fiber3));
20683
+ if (currentFiber === fiber3) {
20684
+ currentFiber = undefined;
20685
+ }
20213
20686
  if (isSuccess4(exit3)) {
20214
20687
  currentIter = exit3.value[Symbol.iterator]();
20215
20688
  return currentIter.next();
20216
20689
  } else if (isDoneCause(exit3.cause)) {
20217
- return {
20218
- done: true,
20219
- value: undefined
20220
- };
20690
+ return close2(void_4);
20691
+ }
20692
+ if (closePromise && hasInterruptsOnly2(exit3.cause)) {
20693
+ return closePromise;
20221
20694
  }
20695
+ await closeAndReportError(exit3);
20222
20696
  throw squash(exit3.cause);
20223
20697
  },
20224
- return(_) {
20225
- return runPromise3(as3(close(scope3, void_4), {
20226
- done: true,
20227
- value: undefined
20228
- }));
20698
+ return() {
20699
+ return close2(void_4);
20700
+ },
20701
+ async throw(error) {
20702
+ await closeAndReportError(die2(error));
20703
+ throw error;
20229
20704
  }
20230
20705
  };
20231
20706
  }
@@ -20238,8 +20713,8 @@ var toPubSubTake2 = /* @__PURE__ */ dual(2, (self, options) => toPubSubTake(self
20238
20713
  var toQueue = /* @__PURE__ */ dual(2, (self, options) => toQueueArray(self.channel, options));
20239
20714
  var runIntoQueue = /* @__PURE__ */ dual(2, (self, queue) => runIntoQueueArray(self.channel, queue));
20240
20715
 
20241
- // ../../node_modules/.bun/effect@4.0.0-beta.98/node_modules/effect/dist/FileSystem.js
20242
- var TypeId24 = "~effect/platform/FileSystem";
20716
+ // ../../node_modules/.bun/effect@4.0.0-beta.107/node_modules/effect/dist/FileSystem.js
20717
+ var TypeId23 = "~effect/platform/FileSystem";
20243
20718
  var Size = (bytes) => typeof bytes === "bigint" ? bytes : BigInt(bytes);
20244
20719
  var KiB = (n) => Size(n * 1024);
20245
20720
  var MiB = (n) => Size(n * 1024 * 1024);
@@ -20251,7 +20726,7 @@ var PiB = (n) => Size(BigInt(n) * bigintPiB);
20251
20726
  var FileSystem = /* @__PURE__ */ Service("effect/platform/FileSystem");
20252
20727
  var make17 = (impl) => FileSystem.of({
20253
20728
  ...impl,
20254
- [TypeId24]: TypeId24,
20729
+ [TypeId23]: TypeId23,
20255
20730
  exists: (path) => pipe(impl.access(path), as3(true), catchTag3("PlatformError", (e) => e.reason._tag === "NotFound" ? succeed6(false) : fail6(e))),
20256
20731
  readFileString: (path, encoding) => flatMap5(impl.readFile(path), (_) => try_3({
20257
20732
  try: () => new TextDecoder(encoding).decode(_),
@@ -20300,7 +20775,7 @@ var make17 = (impl) => FileSystem.of({
20300
20775
  })
20301
20776
  }), (_) => impl.writeFile(path, _, options))
20302
20777
  });
20303
- var notFound = (method, path) => systemError({
20778
+ var notFound2 = (method, path) => systemError({
20304
20779
  module: "FileSystem",
20305
20780
  method,
20306
20781
  _tag: "NotFound",
@@ -20308,115 +20783,114 @@ var notFound = (method, path) => systemError({
20308
20783
  pathOrDescriptor: path
20309
20784
  });
20310
20785
  var makeNoop = (fileSystem) => FileSystem.of({
20311
- [TypeId24]: TypeId24,
20786
+ [TypeId23]: TypeId23,
20312
20787
  access(path) {
20313
- return fail6(notFound("access", path));
20788
+ return fail6(notFound2("access", path));
20314
20789
  },
20315
20790
  chmod(path) {
20316
- return fail6(notFound("chmod", path));
20791
+ return fail6(notFound2("chmod", path));
20317
20792
  },
20318
20793
  chown(path) {
20319
- return fail6(notFound("chown", path));
20794
+ return fail6(notFound2("chown", path));
20320
20795
  },
20321
20796
  copy(path) {
20322
- return fail6(notFound("copy", path));
20797
+ return fail6(notFound2("copy", path));
20323
20798
  },
20324
20799
  copyFile(path) {
20325
- return fail6(notFound("copyFile", path));
20800
+ return fail6(notFound2("copyFile", path));
20326
20801
  },
20327
20802
  glob(pattern) {
20328
- return fail6(notFound("glob", pattern));
20803
+ return fail6(notFound2("glob", pattern));
20329
20804
  },
20330
20805
  exists() {
20331
20806
  return succeed6(false);
20332
20807
  },
20333
20808
  link(path) {
20334
- return fail6(notFound("link", path));
20809
+ return fail6(notFound2("link", path));
20335
20810
  },
20336
20811
  makeDirectory() {
20337
- return die3("not implemented");
20812
+ return die4("not implemented");
20338
20813
  },
20339
20814
  makeTempDirectory() {
20340
- return die3("not implemented");
20815
+ return die4("not implemented");
20341
20816
  },
20342
20817
  makeTempDirectoryScoped() {
20343
- return die3("not implemented");
20818
+ return die4("not implemented");
20344
20819
  },
20345
20820
  makeTempFile() {
20346
- return die3("not implemented");
20821
+ return die4("not implemented");
20347
20822
  },
20348
20823
  makeTempFileScoped() {
20349
- return die3("not implemented");
20824
+ return die4("not implemented");
20350
20825
  },
20351
20826
  open(path) {
20352
- return fail6(notFound("open", path));
20827
+ return fail6(notFound2("open", path));
20353
20828
  },
20354
20829
  readDirectory(path) {
20355
- return fail6(notFound("readDirectory", path));
20830
+ return fail6(notFound2("readDirectory", path));
20356
20831
  },
20357
20832
  readFile(path) {
20358
- return fail6(notFound("readFile", path));
20833
+ return fail6(notFound2("readFile", path));
20359
20834
  },
20360
20835
  readFileString(path) {
20361
- return fail6(notFound("readFileString", path));
20836
+ return fail6(notFound2("readFileString", path));
20362
20837
  },
20363
20838
  readLink(path) {
20364
- return fail6(notFound("readLink", path));
20839
+ return fail6(notFound2("readLink", path));
20365
20840
  },
20366
20841
  realPath(path) {
20367
- return fail6(notFound("realPath", path));
20842
+ return fail6(notFound2("realPath", path));
20368
20843
  },
20369
20844
  remove() {
20370
20845
  return void_5;
20371
20846
  },
20372
20847
  rename(oldPath) {
20373
- return fail6(notFound("rename", oldPath));
20848
+ return fail6(notFound2("rename", oldPath));
20374
20849
  },
20375
20850
  sink(path) {
20376
- return fail8(notFound("sink", path));
20851
+ return fail8(notFound2("sink", path));
20377
20852
  },
20378
20853
  stat(path) {
20379
- return fail6(notFound("stat", path));
20854
+ return fail6(notFound2("stat", path));
20380
20855
  },
20381
20856
  stream(path) {
20382
- return fail9(notFound("stream", path));
20857
+ return fail9(notFound2("stream", path));
20383
20858
  },
20384
20859
  symlink(fromPath) {
20385
- return fail6(notFound("symlink", fromPath));
20860
+ return fail6(notFound2("symlink", fromPath));
20386
20861
  },
20387
20862
  truncate(path) {
20388
- return fail6(notFound("truncate", path));
20863
+ return fail6(notFound2("truncate", path));
20389
20864
  },
20390
20865
  utimes(path) {
20391
- return fail6(notFound("utimes", path));
20866
+ return fail6(notFound2("utimes", path));
20392
20867
  },
20393
20868
  watch(path) {
20394
- return fail9(notFound("watch", path));
20869
+ return fail9(notFound2("watch", path));
20395
20870
  },
20396
20871
  writeFile(path) {
20397
- return fail6(notFound("writeFile", path));
20872
+ return fail6(notFound2("writeFile", path));
20398
20873
  },
20399
20874
  writeFileString(path) {
20400
- return fail6(notFound("writeFileString", path));
20875
+ return fail6(notFound2("writeFileString", path));
20401
20876
  },
20402
20877
  ...fileSystem
20403
20878
  });
20404
20879
  var layerNoop = (fileSystem) => succeed5(FileSystem)(makeNoop(fileSystem));
20405
20880
  var FileTypeId = "~effect/platform/FileSystem/File";
20406
20881
  var isFile = (u) => hasProperty(u, FileTypeId);
20407
- var FileDescriptor = /* @__PURE__ */ nominal();
20408
20882
 
20409
20883
  class WatchBackend extends (/* @__PURE__ */ Service()("effect/platform/FileSystem/WatchBackend")) {
20410
20884
  }
20411
20885
 
20412
- // ../../node_modules/.bun/effect@4.0.0-beta.98/node_modules/effect/dist/Path.js
20886
+ // ../../node_modules/.bun/effect@4.0.0-beta.107/node_modules/effect/dist/Path.js
20413
20887
  var exports_Path = {};
20414
20888
  __export(exports_Path, {
20415
20889
  layer: () => layer,
20416
- TypeId: () => TypeId25,
20890
+ TypeId: () => TypeId24,
20417
20891
  Path: () => Path
20418
20892
  });
20419
- var TypeId25 = "~effect/platform/Path";
20893
+ var TypeId24 = "~effect/platform/Path";
20420
20894
  var Path = /* @__PURE__ */ Service("effect/Path");
20421
20895
  function normalizeStringPosix(path, allowAboveRoot) {
20422
20896
  let res = "";
@@ -20593,7 +21067,7 @@ function encodePathChars(filepath) {
20593
21067
  return filepath;
20594
21068
  }
20595
21069
  var posixImpl = /* @__PURE__ */ Path.of({
20596
- [TypeId25]: TypeId25,
21070
+ [TypeId24]: TypeId24,
20597
21071
  resolve,
20598
21072
  normalize(path) {
20599
21073
  if (path.length === 0)
@@ -20900,7 +21374,7 @@ var posixImpl = /* @__PURE__ */ Path.of({
20900
21374
  });
20901
21375
  var layer = /* @__PURE__ */ succeed5(Path)(posixImpl);
20902
21376
 
20903
- // ../../node_modules/.bun/effect@4.0.0-beta.98/node_modules/effect/dist/unstable/process/ChildProcess.js
21377
+ // ../../node_modules/.bun/effect@4.0.0-beta.107/node_modules/effect/dist/unstable/process/ChildProcess.js
20904
21378
  var exports_ChildProcess = {};
20905
21379
  __export(exports_ChildProcess, {
20906
21380
  setEnv: () => setEnv,
@@ -20915,7 +21389,7 @@ __export(exports_ChildProcess, {
20915
21389
  fdName: () => fdName
20916
21390
  });
20917
21391
 
20918
- // ../../node_modules/.bun/effect@4.0.0-beta.98/node_modules/effect/dist/unstable/process/ChildProcessSpawner.js
21392
+ // ../../node_modules/.bun/effect@4.0.0-beta.107/node_modules/effect/dist/unstable/process/ChildProcessSpawner.js
20919
21393
  var exports_ChildProcessSpawner = {};
20920
21394
  __export(exports_ChildProcessSpawner, {
20921
21395
  makeHandle: () => makeHandle,
@@ -20924,6 +21398,17 @@ __export(exports_ChildProcessSpawner, {
20924
21398
  ExitCode: () => ExitCode,
20925
21399
  ChildProcessSpawner: () => ChildProcessSpawner
20926
21400
  });
21401
+
21402
+ // ../../node_modules/.bun/effect@4.0.0-beta.107/node_modules/effect/dist/Brand.js
21403
+ function nominal() {
21404
+ return Object.assign((input) => input, {
21405
+ option: (input) => some2(input),
21406
+ result: (input) => succeed2(input),
21407
+ is: (_) => true
21408
+ });
21409
+ }
21410
+
21411
+ // ../../node_modules/.bun/effect@4.0.0-beta.107/node_modules/effect/dist/unstable/process/ChildProcessSpawner.js
20927
21412
  var ExitCode = /* @__PURE__ */ nominal();
20928
21413
  var ProcessId = /* @__PURE__ */ nominal();
20929
21414
  var HandleTypeId = "~effect/ChildProcessSpawner/ChildProcessHandle";
@@ -20937,7 +21422,9 @@ var HandleProto = {
20937
21422
  };
20938
21423
  }
20939
21424
  };
20940
- var makeHandle = (params) => Object.assign(Object.create(HandleProto), params);
21425
+ var makeHandle = (params) => Object.setPrototypeOf({
21426
+ ...params
21427
+ }, HandleProto);
20941
21428
  var make18 = (spawn) => {
20942
21429
  const streamString = (command, options) => spawn(command).pipe(map5((handle) => decodeText(options?.includeStderr === true ? handle.all : handle.stdout)), unwrap4);
20943
21430
  const streamLines = (command, options) => splitLines2(streamString(command, options));
@@ -20954,8 +21441,8 @@ var make18 = (spawn) => {
20954
21441
  class ChildProcessSpawner extends (/* @__PURE__ */ Service()("effect/process/ChildProcessSpawner")) {
20955
21442
  }
20956
21443
 
20957
- // ../../node_modules/.bun/effect@4.0.0-beta.98/node_modules/effect/dist/unstable/process/ChildProcess.js
20958
- var TypeId26 = "~effect/unstable/process/ChildProcess";
21444
+ // ../../node_modules/.bun/effect@4.0.0-beta.107/node_modules/effect/dist/unstable/process/ChildProcess.js
21445
+ var TypeId25 = "~effect/unstable/process/ChildProcess";
20959
21446
  var Proto3 = {
20960
21447
  .../* @__PURE__ */ Prototype2({
20961
21448
  label: "Command",
@@ -20963,9 +21450,9 @@ var Proto3 = {
20963
21450
  return getUnsafe2(fiber3.context, ChildProcessSpawner).spawn(this);
20964
21451
  }
20965
21452
  }),
20966
- [TypeId26]: TypeId26
21453
+ [TypeId25]: TypeId25
20967
21454
  };
20968
- var isCommand = (u) => hasProperty(u, TypeId26);
21455
+ var isCommand = (u) => hasProperty(u, TypeId25);
20969
21456
  var isStandardCommand = (command) => command._tag === "StandardCommand";
20970
21457
  var isPipedCommand = (command) => command._tag === "PipedCommand";
20971
21458
  var makeStandardCommand = (command, args2, options) => Object.assign(Object.create(Proto3), {
@@ -21067,10 +21554,10 @@ var setEnv = /* @__PURE__ */ dual(2, (self, env) => {
21067
21554
  });
21068
21555
  var isTemplateString = (u) => Array.isArray(u) && ("raw" in u) && Array.isArray(u.raw);
21069
21556
  var parseFdName = (name) => {
21070
- const match6 = /^fd(\d+)$/.exec(name);
21071
- if (match6 === null)
21557
+ const match7 = /^fd(\d+)$/.exec(name);
21558
+ if (match7 === null)
21072
21559
  return;
21073
- const fd = parseInt(match6[1], 10);
21560
+ const fd = parseInt(match7[1], 10);
21074
21561
  return fd >= 3 ? fd : undefined;
21075
21562
  };
21076
21563
  var fdName = (fd) => `fd${fd}`;
@@ -21155,11 +21642,22 @@ var splitByWhitespaces = (template, rawTemplate) => {
21155
21642
  };
21156
21643
  var concatTokens = (prevTokens, nextTokens, isSeparated) => isSeparated || prevTokens.length === 0 || nextTokens.length === 0 ? [...prevTokens, ...nextTokens] : [...prevTokens.slice(0, -1), `${prevTokens.at(-1)}${nextTokens.at(0)}`, ...nextTokens.slice(1)];
21157
21644
 
21158
- // ../../node_modules/.bun/@effect+platform-node-shared@4.0.0-beta.98+74997d64abff4185/node_modules/@effect/platform-node-shared/dist/NodeChildProcessSpawner.js
21645
+ // ../../node_modules/.bun/@effect+platform-node-shared@4.0.0-beta.107+572e5a9a9ccc3c07/node_modules/@effect/platform-node-shared/dist/NodeChildProcessSpawner.js
21159
21646
  import * as NodeChildProcess from "node:child_process";
21160
21647
  import { PassThrough } from "node:stream";
21161
21648
 
21162
- // ../../node_modules/.bun/@effect+platform-node-shared@4.0.0-beta.98+74997d64abff4185/node_modules/@effect/platform-node-shared/dist/internal/utils.js
21649
+ // ../../node_modules/.bun/@effect+platform-node-shared@4.0.0-beta.107+572e5a9a9ccc3c07/node_modules/@effect/platform-node-shared/dist/internal/nodeChildProcessSpawner.js
21650
+ var buildSpawnOptions = (options, base, platform) => {
21651
+ const detached = options.detached ?? platform !== "win32";
21652
+ return {
21653
+ ...base,
21654
+ detached,
21655
+ shell: options.shell,
21656
+ windowsHide: options.windowsHide ?? !detached
21657
+ };
21658
+ };
21659
+
21660
+ // ../../node_modules/.bun/@effect+platform-node-shared@4.0.0-beta.107+572e5a9a9ccc3c07/node_modules/@effect/platform-node-shared/dist/internal/utils.js
21163
21661
  var handleErrnoException = (module, method) => (err, [path]) => {
21164
21662
  let reason = "Unknown";
21165
21663
  switch (err.code) {
@@ -21195,7 +21693,7 @@ var handleErrnoException = (module, method) => (err, [path]) => {
21195
21693
  });
21196
21694
  };
21197
21695
 
21198
- // ../../node_modules/.bun/@effect+platform-node-shared@4.0.0-beta.98+74997d64abff4185/node_modules/@effect/platform-node-shared/dist/NodeSink.js
21696
+ // ../../node_modules/.bun/@effect+platform-node-shared@4.0.0-beta.107+572e5a9a9ccc3c07/node_modules/@effect/platform-node-shared/dist/NodeSink.js
21199
21697
  var fromWritable = (options) => fromChannel2(mapDone(fromWritableChannel(options), (_) => [_]));
21200
21698
  var fromWritableChannel = (options) => fromTransform((pull) => {
21201
21699
  const writable = options.evaluate();
@@ -21235,7 +21733,7 @@ var pullIntoWritable = (options) => options.pull.pipe(flatMap5((chunk) => {
21235
21733
  });
21236
21734
  }) : identity);
21237
21735
 
21238
- // ../../node_modules/.bun/@effect+platform-node-shared@4.0.0-beta.98+74997d64abff4185/node_modules/@effect/platform-node-shared/dist/NodeStream.js
21736
+ // ../../node_modules/.bun/@effect+platform-node-shared@4.0.0-beta.107+572e5a9a9ccc3c07/node_modules/@effect/platform-node-shared/dist/NodeStream.js
21239
21737
  var fromReadable = (options) => fromChannel3(fromReadableChannel(options));
21240
21738
  var fromReadableChannel = (options) => fromTransform((_, scope3) => readableToPullUnsafe({
21241
21739
  scope: scope3,
@@ -21247,7 +21745,7 @@ var fromReadableChannel = (options) => fromTransform((_, scope3) => readableToPu
21247
21745
  var readableToPullUnsafe = (options) => {
21248
21746
  const readable = options.readable;
21249
21747
  const closeOnDone = options.closeOnDone ?? true;
21250
- const exit3 = options.exit ?? make10(undefined);
21748
+ const exit3 = options.exit ?? make9(undefined);
21251
21749
  const latch = makeUnsafe4(false);
21252
21750
  function onReadable() {
21253
21751
  latch.openUnsafe();
@@ -21295,7 +21793,7 @@ var readableToPullUnsafe = (options) => {
21295
21793
  };
21296
21794
  var defaultOnError = (error) => new UnknownError2(error);
21297
21795
 
21298
- // ../../node_modules/.bun/@effect+platform-node-shared@4.0.0-beta.98+74997d64abff4185/node_modules/@effect/platform-node-shared/dist/NodeChildProcessSpawner.js
21796
+ // ../../node_modules/.bun/@effect+platform-node-shared@4.0.0-beta.107+572e5a9a9ccc3c07/node_modules/@effect/platform-node-shared/dist/NodeChildProcessSpawner.js
21299
21797
  var toError = (error) => error instanceof globalThis.Error ? error : new globalThis.Error(String(error));
21300
21798
  var toPlatformError = (method, error, command) => {
21301
21799
  const {
@@ -21307,6 +21805,9 @@ var toPlatformError = (method, error, command) => {
21307
21805
  }, "");
21308
21806
  return handleErrnoException("ChildProcess", method)(error, [commandStr]);
21309
21807
  };
21808
+ var taskkill = (childProcess, onExit5 = () => {}) => NodeChildProcess.execFile("taskkill", ["/pid", String(childProcess.pid), "/T", "/F"], {
21809
+ windowsHide: true
21810
+ }, onExit5);
21310
21811
  var make21 = /* @__PURE__ */ gen4(function* () {
21311
21812
  const fs = yield* FileSystem;
21312
21813
  const path = yield* Path;
@@ -21525,7 +22026,7 @@ var make21 = /* @__PURE__ */ gen4(function* () {
21525
22026
  const killProcessGroup = (command, childProcess, signal) => {
21526
22027
  if (globalThis.process.platform === "win32") {
21527
22028
  return callback2((resume) => {
21528
- NodeChildProcess.exec(`taskkill /pid ${childProcess.pid} /T /F`, (error) => {
22029
+ taskkill(childProcess, (error) => {
21529
22030
  if (error) {
21530
22031
  resume(fail6(toPlatformError("kill", toError(error), command)));
21531
22032
  } else {
@@ -21543,7 +22044,7 @@ var make21 = /* @__PURE__ */ gen4(function* () {
21543
22044
  };
21544
22045
  const killProcessGroupOnExit = (childProcess, signal) => {
21545
22046
  if (globalThis.process.platform === "win32") {
21546
- NodeChildProcess.exec(`taskkill /pid ${childProcess.pid} /T /F`, () => {});
22047
+ taskkill(childProcess);
21547
22048
  return;
21548
22049
  }
21549
22050
  try {
@@ -21594,13 +22095,11 @@ var make21 = /* @__PURE__ */ gen4(function* () {
21594
22095
  const cwd = yield* resolveWorkingDirectory(cmd.options);
21595
22096
  const env = resolveEnvironment(cmd.options);
21596
22097
  const stdio = buildStdioArray(stdinConfig, stdoutConfig, stderrConfig, resolvedAdditionalFds);
21597
- const [childProcess, exitSignal] = yield* acquireRelease2(spawn2(cmd, {
22098
+ const [childProcess, exitSignal] = yield* acquireRelease2(spawn2(cmd, buildSpawnOptions(cmd.options, {
21598
22099
  cwd,
21599
22100
  env,
21600
- stdio,
21601
- detached: cmd.options.detached ?? process.platform !== "win32",
21602
- shell: cmd.options.shell
21603
- }), fnUntraced2(function* ([childProcess2, exitSignal2]) {
22101
+ stdio
22102
+ }, process.platform)), fnUntraced2(function* ([childProcess2, exitSignal2]) {
21604
22103
  const exited = yield* isDone2(exitSignal2);
21605
22104
  const killWithTimeout = withTimeout(childProcess2, cmd, cmd.options);
21606
22105
  if (exited) {
@@ -21613,7 +22112,7 @@ var make21 = /* @__PURE__ */ gen4(function* () {
21613
22112
  if (!isReferenced) {
21614
22113
  return yield* void_5;
21615
22114
  }
21616
- return yield* killWithTimeout((command, childProcess3, signal) => catch_3(killProcessGroup(command, childProcess3, signal), () => killProcess(command, childProcess3, signal))).pipe(andThen4(_await(exitSignal2)), ignore2);
22115
+ return yield* killWithTimeout((command, childProcess3, signal) => killProcessGroup(command, childProcess3, signal).pipe(catch_3(() => killProcess(command, childProcess3, signal)), andThen4(_await(exitSignal2)))).pipe(ignore2);
21617
22116
  }));
21618
22117
  const pid = ProcessId(childProcess.pid);
21619
22118
  childProcess.on("exit", (code) => {
@@ -21654,7 +22153,7 @@ var make21 = /* @__PURE__ */ gen4(function* () {
21654
22153
  });
21655
22154
  const kill = (options) => {
21656
22155
  const killWithTimeout = withTimeout(childProcess, cmd, options);
21657
- return killWithTimeout((command, childProcess2, signal) => catch_3(killProcessGroup(command, childProcess2, signal), () => killProcess(command, childProcess2, signal))).pipe(andThen4(_await(exitSignal)), asVoid3);
22156
+ return killWithTimeout((command, childProcess2, signal) => killProcessGroup(command, childProcess2, signal).pipe(catch_3(() => killProcess(command, childProcess2, signal)), andThen4(_await(exitSignal)))).pipe(asVoid3);
21658
22157
  };
21659
22158
  return makeHandle({
21660
22159
  pid,
@@ -21718,6 +22217,9 @@ var make21 = /* @__PURE__ */ gen4(function* () {
21718
22217
  }
21719
22218
  }
21720
22219
  const handle = handles[handles.length - 1];
22220
+ const kill = (options) => forEach2([...handles].reverse(), (handle2) => ignore2(handle2.kill(options)), {
22221
+ discard: true
22222
+ });
21721
22223
  const unref = gen4(function* () {
21722
22224
  const rerefs = [];
21723
22225
  for (const handle2 of handles) {
@@ -21731,7 +22233,7 @@ var make21 = /* @__PURE__ */ gen4(function* () {
21731
22233
  pid: handle.pid,
21732
22234
  exitCode: handle.exitCode,
21733
22235
  isRunning: handle.isRunning,
21734
- kill: handle.kill,
22236
+ kill,
21735
22237
  stdin: handle.stdin,
21736
22238
  stdout: handle.stdout,
21737
22239
  stderr: handle.stderr,
@@ -21749,21 +22251,21 @@ var layer2 = /* @__PURE__ */ effect(ChildProcessSpawner, make21);
21749
22251
  var flattenCommand = (command) => {
21750
22252
  const commands = [];
21751
22253
  const pipeOptions = [];
21752
- const flatten6 = (cmd) => {
22254
+ const flatten7 = (cmd) => {
21753
22255
  switch (cmd._tag) {
21754
22256
  case "StandardCommand": {
21755
22257
  commands.push(cmd);
21756
22258
  break;
21757
22259
  }
21758
22260
  case "PipedCommand": {
21759
- flatten6(cmd.left);
22261
+ flatten7(cmd.left);
21760
22262
  pipeOptions.push(cmd.options);
21761
- flatten6(cmd.right);
22263
+ flatten7(cmd.right);
21762
22264
  break;
21763
22265
  }
21764
22266
  }
21765
22267
  };
21766
- flatten6(command);
22268
+ flatten7(command);
21767
22269
  if (commands.length === 0) {
21768
22270
  throw new Error("flattenCommand produced empty commands array");
21769
22271
  }
@@ -21774,13 +22276,13 @@ var flattenCommand = (command) => {
21774
22276
  pipeOptions
21775
22277
  };
21776
22278
  };
21777
- // ../../node_modules/.bun/@effect+platform-node@4.0.0-beta.98+421eccb9593286ba/node_modules/@effect/platform-node/dist/NodeFileSystem.js
22279
+ // ../../node_modules/.bun/@effect+platform-node@4.0.0-beta.107+a2edc8a872f58f99/node_modules/@effect/platform-node/dist/NodeFileSystem.js
21778
22280
  var exports_NodeFileSystem = {};
21779
22281
  __export(exports_NodeFileSystem, {
21780
22282
  layer: () => layer4
21781
22283
  });
21782
22284
 
21783
- // ../../node_modules/.bun/@effect+platform-node-shared@4.0.0-beta.98+74997d64abff4185/node_modules/@effect/platform-node-shared/dist/NodeFileSystem.js
22285
+ // ../../node_modules/.bun/@effect+platform-node-shared@4.0.0-beta.107+572e5a9a9ccc3c07/node_modules/@effect/platform-node-shared/dist/NodeFileSystem.js
21784
22286
  import * as Crypto from "node:crypto";
21785
22287
  import * as NFS from "node:fs";
21786
22288
  import * as OS from "node:os";
@@ -21868,7 +22370,7 @@ var makeTempDirectoryScoped = /* @__PURE__ */ (() => {
21868
22370
  var openFactory = (method) => {
21869
22371
  const nodeOpen = effectify(NFS.open, handleErrnoException("FileSystem", method), handleBadArgument(method));
21870
22372
  const nodeClose = effectify(NFS.close, handleErrnoException("FileSystem", method), handleBadArgument(method));
21871
- return (path, options) => pipe(acquireRelease2(nodeOpen(path, options?.flag ?? "r", options?.mode), (fd) => orDie3(nodeClose(fd))), map5((fd) => makeFile(FileDescriptor(fd), options?.flag?.startsWith("a") ?? false)));
22373
+ return (path, options) => pipe(acquireRelease2(nodeOpen(path, options?.flag ?? "r", options?.mode), (fd) => orDie3(nodeClose(fd))), map5((fd) => makeFile(fd, options?.flag?.startsWith("a") ?? false)));
21872
22374
  };
21873
22375
  var open2 = /* @__PURE__ */ openFactory("open");
21874
22376
  var makeFile = /* @__PURE__ */ (() => {
@@ -21906,7 +22408,7 @@ var makeFile = /* @__PURE__ */ (() => {
21906
22408
  } else if (from === "current") {
21907
22409
  this.position = this.position + offsetSize;
21908
22410
  }
21909
- return this.position;
22411
+ return Size(this.position);
21910
22412
  });
21911
22413
  }
21912
22414
  read(buffer3) {
@@ -22073,9 +22575,9 @@ var utimes2 = /* @__PURE__ */ (() => {
22073
22575
  const nodeUtimes = /* @__PURE__ */ effectify(NFS.utimes, /* @__PURE__ */ handleErrnoException("FileSystem", "utime"), /* @__PURE__ */ handleBadArgument("utime"));
22074
22576
  return (path, atime, mtime) => nodeUtimes(path, atime, mtime);
22075
22577
  })();
22076
- var watchNode = (path) => callback3((queue) => acquireRelease2(sync3(() => {
22578
+ var watchNode = (path, options) => callback3((queue) => acquireRelease2(sync3(() => {
22077
22579
  const watcher = NFS.watch(path, {
22078
- recursive: true
22580
+ recursive: options?.recursive ?? false
22079
22581
  }, (event, path2) => {
22080
22582
  if (!path2)
22081
22583
  return;
@@ -22116,7 +22618,7 @@ var watchNode = (path) => callback3((queue) => acquireRelease2(sync3(() => {
22116
22618
  });
22117
22619
  return watcher;
22118
22620
  }), (watcher) => sync3(() => watcher.close())));
22119
- var watch2 = (backend, path) => stat2(path).pipe(map5((stat3) => backend.pipe(flatMap((_) => _.register(path, stat3)), getOrElse(() => watchNode(path)))), unwrap4);
22621
+ var watch2 = (backend, path, options) => stat2(path).pipe(map5((stat3) => backend.pipe(flatMap((_) => _.register(path, stat3, options)), getOrElse(() => watchNode(path, options)))), unwrap4);
22120
22622
  var writeFile2 = (path, data, options) => callback2((resume, signal) => {
22121
22623
  try {
22122
22624
  NFS.writeFile(path, data, {
@@ -22158,16 +22660,16 @@ var makeFileSystem = /* @__PURE__ */ map5(/* @__PURE__ */ serviceOption2(WatchBa
22158
22660
  symlink: symlink2,
22159
22661
  truncate: truncate2,
22160
22662
  utimes: utimes2,
22161
- watch(path) {
22162
- return watch2(backend, path);
22663
+ watch(path, options) {
22664
+ return watch2(backend, path, options);
22163
22665
  },
22164
22666
  writeFile: writeFile2
22165
22667
  }));
22166
22668
  var layer3 = /* @__PURE__ */ effect(FileSystem)(makeFileSystem);
22167
22669
 
22168
- // ../../node_modules/.bun/@effect+platform-node@4.0.0-beta.98+421eccb9593286ba/node_modules/@effect/platform-node/dist/NodeFileSystem.js
22670
+ // ../../node_modules/.bun/@effect+platform-node@4.0.0-beta.107+a2edc8a872f58f99/node_modules/@effect/platform-node/dist/NodeFileSystem.js
22169
22671
  var layer4 = layer3;
22170
- // ../../node_modules/.bun/@effect+platform-node@4.0.0-beta.98+421eccb9593286ba/node_modules/@effect/platform-node/dist/NodePath.js
22672
+ // ../../node_modules/.bun/@effect+platform-node@4.0.0-beta.107+a2edc8a872f58f99/node_modules/@effect/platform-node/dist/NodePath.js
22171
22673
  var exports_NodePath = {};
22172
22674
  __export(exports_NodePath, {
22173
22675
  layerWin32: () => layerWin322,
@@ -22175,55 +22677,58 @@ __export(exports_NodePath, {
22175
22677
  layer: () => layer6
22176
22678
  });
22177
22679
 
22178
- // ../../node_modules/.bun/@effect+platform-node-shared@4.0.0-beta.98+74997d64abff4185/node_modules/@effect/platform-node-shared/dist/NodePath.js
22680
+ // ../../node_modules/.bun/@effect+platform-node-shared@4.0.0-beta.107+572e5a9a9ccc3c07/node_modules/@effect/platform-node-shared/dist/NodePath.js
22179
22681
  import * as NodePath from "node:path";
22180
22682
  import * as NodeUrl from "node:url";
22181
- var fromFileUrl2 = (url) => try_3({
22182
- try: () => NodeUrl.fileURLToPath(url),
22183
- catch: (cause) => new BadArgument({
22184
- module: "Path",
22185
- method: "fromFileUrl",
22186
- cause
22187
- })
22188
- });
22189
- var toFileUrl2 = (path) => try_3({
22190
- try: () => NodeUrl.pathToFileURL(path),
22191
- catch: (cause) => new BadArgument({
22192
- module: "Path",
22193
- method: "toFileUrl",
22194
- cause
22683
+ var fileUrlOps = (windows) => ({
22684
+ fromFileUrl: (url) => try_3({
22685
+ try: () => NodeUrl.fileURLToPath(url, {
22686
+ windows
22687
+ }),
22688
+ catch: (cause) => new BadArgument({
22689
+ module: "Path",
22690
+ method: "fromFileUrl",
22691
+ cause
22692
+ })
22693
+ }),
22694
+ toFileUrl: (path) => try_3({
22695
+ try: () => NodeUrl.pathToFileURL(path, {
22696
+ windows
22697
+ }),
22698
+ catch: (cause) => new BadArgument({
22699
+ module: "Path",
22700
+ method: "toFileUrl",
22701
+ cause
22702
+ })
22195
22703
  })
22196
22704
  });
22197
22705
  var layerPosix = /* @__PURE__ */ succeed5(Path)({
22198
- [TypeId25]: TypeId25,
22706
+ [TypeId24]: TypeId24,
22199
22707
  ...NodePath.posix,
22200
- fromFileUrl: fromFileUrl2,
22201
- toFileUrl: toFileUrl2
22708
+ .../* @__PURE__ */ fileUrlOps(false)
22202
22709
  });
22203
22710
  var layerWin32 = /* @__PURE__ */ succeed5(Path)({
22204
- [TypeId25]: TypeId25,
22711
+ [TypeId24]: TypeId24,
22205
22712
  ...NodePath.win32,
22206
- fromFileUrl: fromFileUrl2,
22207
- toFileUrl: toFileUrl2
22713
+ .../* @__PURE__ */ fileUrlOps(true)
22208
22714
  });
22209
22715
  var layer5 = /* @__PURE__ */ succeed5(Path)({
22210
- [TypeId25]: TypeId25,
22716
+ [TypeId24]: TypeId24,
22211
22717
  ...NodePath,
22212
- fromFileUrl: fromFileUrl2,
22213
- toFileUrl: toFileUrl2
22718
+ .../* @__PURE__ */ fileUrlOps(undefined)
22214
22719
  });
22215
22720
 
22216
- // ../../node_modules/.bun/@effect+platform-node@4.0.0-beta.98+421eccb9593286ba/node_modules/@effect/platform-node/dist/NodePath.js
22721
+ // ../../node_modules/.bun/@effect+platform-node@4.0.0-beta.107+a2edc8a872f58f99/node_modules/@effect/platform-node/dist/NodePath.js
22217
22722
  var layer6 = layer5;
22218
22723
  var layerPosix2 = layerPosix;
22219
22724
  var layerWin322 = layerWin32;
22220
- // ../../node_modules/.bun/@effect+platform-node@4.0.0-beta.98+421eccb9593286ba/node_modules/@effect/platform-node/dist/NodeRuntime.js
22725
+ // ../../node_modules/.bun/@effect+platform-node@4.0.0-beta.107+a2edc8a872f58f99/node_modules/@effect/platform-node/dist/NodeRuntime.js
22221
22726
  var exports_NodeRuntime = {};
22222
22727
  __export(exports_NodeRuntime, {
22223
22728
  runMain: () => runMain2
22224
22729
  });
22225
22730
 
22226
- // ../../node_modules/.bun/effect@4.0.0-beta.98/node_modules/effect/dist/Runtime.js
22731
+ // ../../node_modules/.bun/effect@4.0.0-beta.107/node_modules/effect/dist/Runtime.js
22227
22732
  var defaultTeardown = (exit3, onExit5) => {
22228
22733
  if (isSuccess4(exit3))
22229
22734
  return onExit5(0);
@@ -22271,7 +22776,7 @@ var getErrorReported = (u) => {
22271
22776
  return true;
22272
22777
  };
22273
22778
 
22274
- // ../../node_modules/.bun/@effect+platform-node-shared@4.0.0-beta.98+74997d64abff4185/node_modules/@effect/platform-node-shared/dist/NodeRuntime.js
22779
+ // ../../node_modules/.bun/@effect+platform-node-shared@4.0.0-beta.107+572e5a9a9ccc3c07/node_modules/@effect/platform-node-shared/dist/NodeRuntime.js
22275
22780
  var runMain = /* @__PURE__ */ makeRunMain(({
22276
22781
  fiber: fiber3,
22277
22782
  teardown
@@ -22294,9 +22799,9 @@ var runMain = /* @__PURE__ */ makeRunMain(({
22294
22799
  process.on("SIGTERM", onSigint);
22295
22800
  });
22296
22801
 
22297
- // ../../node_modules/.bun/@effect+platform-node@4.0.0-beta.98+421eccb9593286ba/node_modules/@effect/platform-node/dist/NodeRuntime.js
22802
+ // ../../node_modules/.bun/@effect+platform-node@4.0.0-beta.107+a2edc8a872f58f99/node_modules/@effect/platform-node/dist/NodeRuntime.js
22298
22803
  var runMain2 = runMain;
22299
- // ../../node_modules/.bun/effect@4.0.0-beta.98/node_modules/effect/dist/Console.js
22804
+ // ../../node_modules/.bun/effect@4.0.0-beta.107/node_modules/effect/dist/Console.js
22300
22805
  var exports_Console = {};
22301
22806
  __export(exports_Console, {
22302
22807
  withTime: () => withTime,
@@ -22395,23 +22900,24 @@ var withTime = /* @__PURE__ */ dual((args2) => isEffect(args2[0]), (self, label)
22395
22900
  // package.json
22396
22901
  var package_default = {
22397
22902
  name: "@aerovato/operator-helper",
22398
- version: "1.0.0",
22903
+ version: "1.0.2",
22399
22904
  description: "Installation and setup CLI for Operator Memory",
22400
22905
  license: "BSD-3-Clause",
22401
22906
  author: "Aerovato Research",
22402
- homepage: "https://github.com/aerovato/operator#readme",
22907
+ homepage: "https://github.com/aerovato/operator-memory#readme",
22403
22908
  bugs: {
22404
- url: "https://github.com/aerovato/operator/issues"
22909
+ url: "https://github.com/aerovato/operator-memory/issues"
22405
22910
  },
22406
22911
  repository: {
22407
22912
  type: "git",
22408
- url: "git+https://github.com/aerovato/operator.git",
22913
+ url: "git+https://github.com/aerovato/operator-memory.git",
22409
22914
  directory: "packages/helper"
22410
22915
  },
22411
22916
  dependencies: {
22412
- "@effect/platform-node": "4.0.0-beta.98",
22917
+ "@effect/platform-node": "4.0.0-beta.107",
22918
+ "@effect/platform-node-shared": "4.0.0-beta.107",
22413
22919
  "cli-table3": "^0.6.5",
22414
- effect: "4.0.0-beta.98",
22920
+ effect: "4.0.0-beta.107",
22415
22921
  yaml: "^2.9.0"
22416
22922
  },
22417
22923
  bin: {
@@ -22735,7 +23241,22 @@ var PROJECT_SHARED_README_TEMPLATE = `# Operator Memory
22735
23241
 
22736
23242
  This directory holds project knowledge and instructions used by Operator Memory. Operator Memory turns agent work into lasting project knowledge—instructions, specifications, codebase indexes, and related documents agents own and maintain.
22737
23243
 
22738
- Learn more: https://github.com/aerovato/operator
23244
+ ##### Learn more: https://github.com/aerovato/operator-memory
23245
+
23246
+ ---
23247
+
23248
+ Install now:
23249
+
23250
+ \`\`\`
23251
+ # With NPM
23252
+ npm install --global @aerovato/operator-helper
23253
+
23254
+ # With Bun
23255
+ bun add --global --minimum-release-age 0 @aerovato/operator-helper@latest
23256
+
23257
+ # Install OpenCode plugin
23258
+ operator-helper install opencode
23259
+ \`\`\`
22739
23260
  `;
22740
23261
 
22741
23262
  // src/templates/project/setup.ts
@@ -23378,7 +23899,7 @@ var installOpenCode = exports_Effect.fn("installOpenCode")(function* (context3)
23378
23899
  const fileSystem = yield* exports_FileSystem.FileSystem;
23379
23900
  const path = yield* exports_Path.Path;
23380
23901
  const spawner = yield* exports_ChildProcessSpawner.ChildProcessSpawner;
23381
- const cacheRoot = process.platform === "win32" ? process.env.LOCALAPPDATA ?? path.join(context3.home, "AppData", "Local") : process.env.XDG_CACHE_HOME ?? path.join(context3.home, ".cache");
23902
+ const cacheRoot = process.env.XDG_CACHE_HOME || path.join(context3.home, ".cache");
23382
23903
  const isCacheRemoved = yield* fileSystem.remove(path.join(cacheRoot, "opencode", "packages", "@aerovato", "operator-opencode@latest"), {
23383
23904
  recursive: true,
23384
23905
  force: true
@@ -23989,6 +24510,80 @@ ${renderTable([["User Instructions", `${USER_PATH} (${Buffer.byteLength(content)
23989
24510
  };
23990
24511
  });
23991
24512
 
24513
+ // src/cli.ts
24514
+ var HELP = `Operator Helper
24515
+
24516
+ USER COMMANDS
24517
+
24518
+ ${renderTable([
24519
+ ["help", "Show help for operator-helper"],
24520
+ ["version", "Show the installed version"],
24521
+ ["operator-helper install opencode", "Install or update the OpenCode plugin"]
24522
+ ])}
24523
+
24524
+ AGENT COMMANDS
24525
+
24526
+ ${renderTable([
24527
+ ["operator-helper user status", "Show User Instructions status"],
24528
+ ["operator-helper user init", "Initialize User Instructions without overwriting content"],
24529
+ ["operator-helper user guide", "Print the agent guide for completing User Setup"],
24530
+ [
24531
+ "operator-helper project status",
24532
+ "Show Project Private, Shared, Git ignore, and tracking status"
24533
+ ],
24534
+ ["operator-helper project init", "Initialize project partitions and global Git ignore"],
24535
+ ["operator-helper project guide", "Print the agent guide for completing Project Setup"],
24536
+ ["operator-helper index status", "Show Private and Shared main Project Index status"],
24537
+ ["operator-helper index guide", "Print the agent guide for building or refreshing indexes"],
24538
+ ["operator-helper index lint", "Check Project Index structure and frontmatter"],
24539
+ ["operator-helper memory check", "Check that all Operator memory can be loaded"]
24540
+ ])}`;
24541
+ function runCli(arguments_, context3) {
24542
+ return exports_Effect.gen(function* () {
24543
+ if (arguments_.length === 1 && arguments_[0] === "help") {
24544
+ return { exitCode: 0, output: HELP };
24545
+ }
24546
+ if (arguments_.length === 1 && arguments_[0] === "version") {
24547
+ return { exitCode: 0, output: context3.version };
24548
+ }
24549
+ if (arguments_.length !== 2) {
24550
+ return { exitCode: 2, output: HELP };
24551
+ }
24552
+ const command = `${arguments_[0]} ${arguments_[1]}`;
24553
+ switch (command) {
24554
+ case "user status":
24555
+ return yield* userStatus(context3);
24556
+ case "user init":
24557
+ return yield* userInit(context3);
24558
+ case "user guide":
24559
+ return yield* userGuide();
24560
+ case "project status":
24561
+ return yield* projectStatus(context3);
24562
+ case "project init":
24563
+ return yield* projectInit(context3);
24564
+ case "project guide":
24565
+ return yield* projectGuide();
24566
+ case "index status":
24567
+ return yield* indexStatus(context3);
24568
+ case "index guide":
24569
+ return yield* indexGuide();
24570
+ case "index lint":
24571
+ return yield* indexLint(context3);
24572
+ case "memory check":
24573
+ return yield* memoryCheck(context3);
24574
+ case "install opencode":
24575
+ return yield* installOpenCode(context3);
24576
+ default:
24577
+ return {
24578
+ exitCode: 2,
24579
+ output: `Unknown command: ${command}
24580
+
24581
+ ${HELP}`
24582
+ };
24583
+ }
24584
+ }).pipe(exports_Effect.catch((error2) => exports_Effect.succeed(fileFailure(error2))));
24585
+ }
24586
+
23992
24587
  // src/npm-registry.ts
23993
24588
  class NpmRegistryError extends exports_Data.TaggedError("NpmRegistryError") {
23994
24589
  }
@@ -24024,59 +24619,27 @@ var NpmRegistry;
24024
24619
  }));
24025
24620
  })(NpmRegistry ||= {});
24026
24621
 
24027
- // src/commands/upgrade.ts
24622
+ // src/update.ts
24028
24623
  var HELPER_PACKAGE = "@aerovato/operator-helper";
24029
- var updateNotice = exports_Effect.fn("updateNotice")(function* (currentVersion) {
24624
+ var UPDATE_TIMEOUT = "60 seconds";
24625
+ var autoUpdate = exports_Effect.fn("autoUpdate")(function* (currentVersion, context3) {
24030
24626
  const registry = yield* NpmRegistry.Service;
24031
24627
  const latest = yield* registry.latestVersion(HELPER_PACKAGE).pipe(exports_Effect.option);
24032
24628
  if (exports_Option.isNone(latest) || !isNewerVersion(currentVersion, latest.value)) {
24033
- return null;
24629
+ return { status: "current" };
24034
24630
  }
24035
- return `Operator Helper ${latest.value} is available. Run operator-helper upgrade.`;
24036
- });
24037
- var upgrade = exports_Effect.fn("upgrade")(function* (context3) {
24038
24631
  const spawner = yield* exports_ChildProcessSpawner.ChildProcessSpawner;
24039
24632
  const channel = yield* detectInstallationChannel(spawner, context3.cwd);
24040
24633
  if (channel === "unknown") {
24041
- return {
24042
- exitCode: 1,
24043
- output: `✗ ${[
24044
- "Could not determine how Operator Helper was installed.",
24045
- "Upgrade manually using your original installation method.",
24046
- "",
24047
- "bun add --global --minimum-release-age 0 @aerovato/operator-helper@latest",
24048
- "NPM_CONFIG_MIN_RELEASE_AGE=0 npm install --global @aerovato/operator-helper@latest"
24049
- ].join(`
24050
- `)}`
24051
- };
24634
+ return { status: "unknown", latest: latest.value };
24052
24635
  }
24053
- const command = channel === "bun" ? exports_ChildProcess.make("bun", ["add", "--global", "--minimum-release-age", "0", `${HELPER_PACKAGE}@latest`], { cwd: context3.cwd }) : exports_ChildProcess.make("npm", ["install", "--global", `${HELPER_PACKAGE}@latest`], {
24636
+ const command = channel === "bun" ? exports_ChildProcess.make("bun", ["add", "--global", "--minimum-release-age", "0", `${HELPER_PACKAGE}@${latest.value}`], { cwd: context3.cwd }) : exports_ChildProcess.make("npm", ["install", "--global", `${HELPER_PACKAGE}@${latest.value}`], {
24054
24637
  cwd: context3.cwd,
24055
24638
  env: { NPM_CONFIG_MIN_RELEASE_AGE: "0" },
24056
24639
  extendEnv: true
24057
24640
  });
24058
- const execution = yield* run2(spawner, command).pipe(exports_Effect.result);
24059
- if (exports_Result.isFailure(execution)) {
24060
- const message = execution.failure instanceof exports_PlatformError.PlatformError ? execution.failure.reason.description ?? execution.failure.message : getErrorMessage(execution.failure);
24061
- return {
24062
- exitCode: 1,
24063
- output: `✗ ${[
24064
- `Could not upgrade with ${channel}: ${message}`,
24065
- "",
24066
- "Upgrade manually using your original installation method.",
24067
- "",
24068
- "bun add --global --minimum-release-age 0 @aerovato/operator-helper@latest",
24069
- "NPM_CONFIG_MIN_RELEASE_AGE=0 npm install --global @aerovato/operator-helper@latest"
24070
- ].join(`
24071
- `)}`
24072
- };
24073
- }
24074
- const output = [execution.success.stdout.trim(), execution.success.stderr.trim()].filter(Boolean).join(`
24075
- `);
24076
- return execution.success.exitCode === 0 ? { exitCode: 0, output } : {
24077
- exitCode: execution.success.exitCode,
24078
- output: output || "Operator Helper upgrade failed"
24079
- };
24641
+ const execution = yield* run2(spawner, command).pipe(exports_Effect.timeout(UPDATE_TIMEOUT), exports_Effect.option);
24642
+ return exports_Option.isSome(execution) && execution.value.exitCode === 0 ? { status: "updated" } : { status: "failed" };
24080
24643
  });
24081
24644
  function detectInstallationChannel(spawner, cwd) {
24082
24645
  return exports_Effect.gen(function* () {
@@ -24120,91 +24683,14 @@ function isNewerVersion(current, latest) {
24120
24683
  return false;
24121
24684
  }
24122
24685
  function parseVersion(value) {
24123
- const match6 = /^(\d+)\.(\d+)\.(\d+)/.exec(value);
24124
- if (match6 === null)
24686
+ const match7 = /^(\d+)\.(\d+)\.(\d+)/.exec(value);
24687
+ if (match7 === null)
24125
24688
  return null;
24126
- return [Number(match6[1]), Number(match6[2]), Number(match6[3])];
24127
- }
24128
-
24129
- // src/cli.ts
24130
- var HELP = `Operator Helper
24131
-
24132
- USER COMMANDS
24133
-
24134
- ${renderTable([
24135
- ["help", "Show help for operator-helper"],
24136
- ["version", "Show the installed version"],
24137
- ["operator-helper install opencode", "Install or update the OpenCode plugin"],
24138
- ["operator-helper upgrade", "Upgrade Operator Helper"]
24139
- ])}
24140
-
24141
- AGENT COMMANDS
24142
-
24143
- ${renderTable([
24144
- ["operator-helper user status", "Show User Instructions status"],
24145
- ["operator-helper user init", "Initialize User Instructions without overwriting content"],
24146
- ["operator-helper user guide", "Print the agent guide for completing User Setup"],
24147
- [
24148
- "operator-helper project status",
24149
- "Show Project Private, Shared, Git ignore, and tracking status"
24150
- ],
24151
- ["operator-helper project init", "Initialize project partitions and global Git ignore"],
24152
- ["operator-helper project guide", "Print the agent guide for completing Project Setup"],
24153
- ["operator-helper index status", "Show Private and Shared main Project Index status"],
24154
- ["operator-helper index guide", "Print the agent guide for building or refreshing indexes"],
24155
- ["operator-helper index lint", "Check Project Index structure and frontmatter"],
24156
- ["operator-helper memory check", "Check that all Operator memory can be loaded"]
24157
- ])}`;
24158
- function runCli(arguments_, context3) {
24159
- return exports_Effect.gen(function* () {
24160
- if (arguments_.length === 1 && arguments_[0] === "help") {
24161
- return { exitCode: 0, output: HELP };
24162
- }
24163
- if (arguments_.length === 1 && arguments_[0] === "version") {
24164
- return { exitCode: 0, output: context3.version };
24165
- }
24166
- if (arguments_.length === 1 && arguments_[0] === "upgrade") {
24167
- return yield* upgrade(context3);
24168
- }
24169
- if (arguments_.length !== 2) {
24170
- return { exitCode: 2, output: HELP };
24171
- }
24172
- const command = `${arguments_[0]} ${arguments_[1]}`;
24173
- switch (command) {
24174
- case "user status":
24175
- return yield* userStatus(context3);
24176
- case "user init":
24177
- return yield* userInit(context3);
24178
- case "user guide":
24179
- return yield* userGuide();
24180
- case "project status":
24181
- return yield* projectStatus(context3);
24182
- case "project init":
24183
- return yield* projectInit(context3);
24184
- case "project guide":
24185
- return yield* projectGuide();
24186
- case "index status":
24187
- return yield* indexStatus(context3);
24188
- case "index guide":
24189
- return yield* indexGuide();
24190
- case "index lint":
24191
- return yield* indexLint(context3);
24192
- case "memory check":
24193
- return yield* memoryCheck(context3);
24194
- case "install opencode":
24195
- return yield* installOpenCode(context3);
24196
- default:
24197
- return {
24198
- exitCode: 2,
24199
- output: `Unknown command: ${command}
24200
-
24201
- ${HELP}`
24202
- };
24203
- }
24204
- }).pipe(exports_Effect.catch((error2) => exports_Effect.succeed(fileFailure(error2))));
24689
+ return [Number(match7[1]), Number(match7[2]), Number(match7[3])];
24205
24690
  }
24206
24691
 
24207
24692
  // src/index.ts
24693
+ var SKIP_UPDATE_ENVIRONMENT_VARIABLE = "OPERATOR_HELPER_SKIP_UPDATE";
24208
24694
  var ChildProcessLayer = exports_NodeChildProcessSpawner.layer.pipe(exports_Layer.provide(exports_NodeFileSystem.layer), exports_Layer.provide(exports_NodePath.layer));
24209
24695
  var LiveLayers = exports_Layer.mergeAll(exports_NodeFileSystem.layer, exports_NodePath.layer, ChildProcessLayer, NpmRegistry.layer, GitRunner.layer.pipe(exports_Layer.provide(ChildProcessLayer), exports_Layer.provide(exports_NodeFileSystem.layer), exports_Layer.provide(exports_NodePath.layer)));
24210
24696
  var main = exports_Effect.gen(function* () {
@@ -24212,21 +24698,37 @@ var main = exports_Effect.gen(function* () {
24212
24698
  arguments: process.argv.slice(2),
24213
24699
  cwd: process.cwd(),
24214
24700
  home: homedir(),
24215
- xdgConfigHome: process.env.XDG_CONFIG_HOME ?? null
24701
+ xdgConfigHome: process.env.XDG_CONFIG_HOME ?? null,
24702
+ version: package_default.version
24216
24703
  };
24217
- const notice = yield* updateNotice(package_default.version);
24218
- if (notice !== null) {
24219
- yield* exports_Console.warn(notice);
24704
+ if (process.env[SKIP_UPDATE_ENVIRONMENT_VARIABLE] !== "1") {
24705
+ const update2 = yield* autoUpdate(package_default.version, environment);
24706
+ if (update2.status === "updated") {
24707
+ const entrypoint = process.argv[1];
24708
+ if (entrypoint !== undefined) {
24709
+ const rerun = spawnSync(process.execPath, [entrypoint, ...environment.arguments], {
24710
+ cwd: environment.cwd,
24711
+ env: { ...process.env, [SKIP_UPDATE_ENVIRONMENT_VARIABLE]: "1" },
24712
+ stdio: "inherit"
24713
+ });
24714
+ if (rerun.error === undefined && rerun.status !== null) {
24715
+ process.exitCode = rerun.status;
24716
+ return;
24717
+ }
24718
+ }
24719
+ } else if (update2.status === "unknown") {
24720
+ yield* exports_Console.warn(`Operator Helper ${update2.latest} is available, but automatic update could not determine whether Bun or npm owns this installation. Ask the user to update operator-helper manually using the original installation method.`);
24721
+ }
24220
24722
  }
24221
24723
  const result4 = yield* runCli(environment.arguments, {
24222
24724
  cwd: environment.cwd,
24223
24725
  home: environment.home,
24224
24726
  xdgConfigHome: environment.xdgConfigHome,
24225
- version: package_default.version
24727
+ version: environment.version
24226
24728
  });
24227
24729
  yield* exports_Console.log(result4.output);
24228
24730
  process.exitCode = result4.exitCode;
24229
24731
  }).pipe(exports_Effect.provide(LiveLayers));
24230
24732
  exports_NodeRuntime.runMain(main);
24231
24733
 
24232
- //# debugId=0884F2498EA99A6764756E2164756E21
24734
+ //# debugId=D773290F0860260964756E2164756E21