foldkit-plus 0.18.0 → 0.19.0

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/cli.mjs CHANGED
@@ -3,7 +3,7 @@ import { fileURLToPath } from "node:url";
3
3
  import { existsSync, readFileSync, readdirSync, realpathSync } from "node:fs";
4
4
  import { homedir } from "node:os";
5
5
  import { dirname, join, relative, sep } from "node:path";
6
- // ../../node_modules/.pnpm/effect@4.1.0/node_modules/effect/dist/Pipeable.js
6
+ // ../../node_modules/.pnpm/effect@4.1.1/node_modules/effect/dist/Pipeable.js
7
7
  /**
8
8
  * The `Pipeable` module defines the shared interface and implementation helpers
9
9
  * for values that support Effect-style method chaining with `.pipe(...)`.
@@ -108,7 +108,7 @@ const Class$1 = /*#__PURE__*/ function() {
108
108
  PipeableBase.prototype = Prototype$1;
109
109
  return PipeableBase;
110
110
  }();
111
- // ../../node_modules/.pnpm/effect@4.1.0/node_modules/effect/dist/Function.js
111
+ // ../../node_modules/.pnpm/effect@4.1.1/node_modules/effect/dist/Function.js
112
112
  /**
113
113
  * Creates a function that can be called in data-first style or data-last
114
114
  * (`pipe`-friendly) style.
@@ -379,7 +379,7 @@ function memoizeIdempotent(f) {
379
379
  return result;
380
380
  };
381
381
  }
382
- // ../../node_modules/.pnpm/effect@4.1.0/node_modules/effect/dist/internal/equal.js
382
+ // ../../node_modules/.pnpm/effect@4.1.1/node_modules/effect/dist/internal/equal.js
383
383
  /** @internal */
384
384
  const getAllObjectKeys = (obj) => {
385
385
  const keys = new Set(Reflect.ownKeys(obj));
@@ -413,7 +413,7 @@ const bufferBytes = (buffer) => {
413
413
  return;
414
414
  }
415
415
  };
416
- // ../../node_modules/.pnpm/effect@4.1.0/node_modules/effect/dist/internal/hash.js
416
+ // ../../node_modules/.pnpm/effect@4.1.1/node_modules/effect/dist/internal/hash.js
417
417
  /**
418
418
  * Back-edge count used to avoid caching entry-point-dependent hashes.
419
419
  *
@@ -424,7 +424,7 @@ let backEdges = 0;
424
424
  const addBackEdge = () => {
425
425
  backEdges++;
426
426
  };
427
- // ../../node_modules/.pnpm/effect@4.1.0/node_modules/effect/dist/Predicate.js
427
+ // ../../node_modules/.pnpm/effect@4.1.1/node_modules/effect/dist/Predicate.js
428
428
  /**
429
429
  * Defines runtime checks for values.
430
430
  *
@@ -720,7 +720,7 @@ function isObjectKeyword(input) {
720
720
  * @since 2.0.0
721
721
  */
722
722
  const hasProperty = /*#__PURE__*/ dual(2, (self, property) => isObjectKeyword(self) && property in self);
723
- // ../../node_modules/.pnpm/effect@4.1.0/node_modules/effect/dist/Hash.js
723
+ // ../../node_modules/.pnpm/effect@4.1.1/node_modules/effect/dist/Hash.js
724
724
  /**
725
725
  * Computes Effect hash values and defines the interface for objects that want
726
726
  * to provide their own hash implementation. Hashes are small numeric
@@ -809,7 +809,7 @@ const hash = (self) => {
809
809
  const seen = backEdges;
810
810
  let h;
811
811
  try {
812
- if ("~effect/Hash" in self) h = self[symbol$1]();
812
+ if (isHash(self)) h = self[symbol$1]();
813
813
  else if (typeof self === "function") h = random(self);
814
814
  else if (isArrayBufferLike(self)) {
815
815
  const bytes = bufferBytes(self);
@@ -926,6 +926,40 @@ const combine = /*#__PURE__*/ dual(2, (self, b) => mix(Math.imul(self, 265443576
926
926
  * @since 2.0.0
927
927
  */
928
928
  const optimize = (n) => n & 3221225471 | n >>> 1 & 1073741824;
929
+ /**
930
+ * Checks whether a value implements the Hash interface.
931
+ *
932
+ * **When to use**
933
+ *
934
+ * Use to detect whether an unknown value provides a custom hash implementation.
935
+ *
936
+ * **Details**
937
+ *
938
+ * This function determines whether a given value has a function under the Hash
939
+ * symbol, indicating that it can provide its own hash value implementation.
940
+ * Data that merely carries the key, such as parsed JSON, is hashed as data.
941
+ *
942
+ * **Example** (Checking for Hash support)
943
+ *
944
+ * ```ts import.meta.vitest
945
+ * import { Hash } from "effect"
946
+ *
947
+ * class MyHashable implements Hash.Hash {
948
+ * [Hash.symbol]() {
949
+ * return 42
950
+ * }
951
+ * }
952
+ *
953
+ * Hash.isHash(new MyHashable()) // => true
954
+ * Hash.isHash({}) // => false
955
+ * Hash.isHash("string") // => false
956
+ * ```
957
+ *
958
+ * @stability stable
959
+ * @category guards
960
+ * @since 2.0.0
961
+ */
962
+ const isHash = (u) => hasProperty(u, "~effect/Hash") && typeof u["~effect/Hash"] === "function";
929
963
  const float64 = /*#__PURE__*/ new DataView(/*#__PURE__*/ new ArrayBuffer(8));
930
964
  /**
931
965
  * Computes a hash value for a number.
@@ -1118,7 +1152,7 @@ const hashSet = /*#__PURE__*/ unordered(setSeed, (element) => combine(setSeed, h
1118
1152
  const randomHashCache = /*#__PURE__*/ new WeakMap();
1119
1153
  const hashCache = /*#__PURE__*/ new WeakMap();
1120
1154
  const visitedObjects = /*#__PURE__*/ new WeakSet();
1121
- // ../../node_modules/.pnpm/effect@4.1.0/node_modules/effect/dist/Equal.js
1155
+ // ../../node_modules/.pnpm/effect@4.1.1/node_modules/effect/dist/Equal.js
1122
1156
  /**
1123
1157
  * Defines the unique string identifier for the `Equal` interface.
1124
1158
  *
@@ -1282,8 +1316,8 @@ const equalEntries = (self, that) => compareBoth(self[0], that[0]) && compareBot
1282
1316
  * **Details**
1283
1317
  *
1284
1318
  * - Pure function, no side effects.
1285
- * - Returns `true` if and only if `u` has a property keyed by
1286
- * {@link symbol}.
1319
+ * - Returns `true` if and only if `u` has a function keyed by {@link symbol}.
1320
+ * Data that merely carries the key, such as parsed JSON, is not `Equal`.
1287
1321
  * - Acts as a TypeScript type guard, narrowing the input to {@link Equal}.
1288
1322
  *
1289
1323
  * **Example** (Checking Equal values)
@@ -1312,8 +1346,8 @@ const equalEntries = (self, that) => compareBoth(self[0], that[0]) && compareBot
1312
1346
  * @category guards
1313
1347
  * @since 2.0.0
1314
1348
  */
1315
- const isEqual = (u) => hasProperty(u, symbol);
1316
- // ../../node_modules/.pnpm/effect@4.1.0/node_modules/effect/dist/Redactable.js
1349
+ const isEqual = (u) => hasProperty(u, "~effect/Equal") && typeof u["~effect/Equal"] === "function";
1350
+ // ../../node_modules/.pnpm/effect@4.1.1/node_modules/effect/dist/Redactable.js
1317
1351
  /**
1318
1352
  * Defines the symbol used to identify objects that implement the {@link Redactable}
1319
1353
  * protocol.
@@ -1435,7 +1469,7 @@ const emptyContext$1 = {
1435
1469
  return pipeArguments(this, arguments);
1436
1470
  }
1437
1471
  };
1438
- // ../../node_modules/.pnpm/effect@4.1.0/node_modules/effect/dist/Formatter.js
1472
+ // ../../node_modules/.pnpm/effect@4.1.1/node_modules/effect/dist/Formatter.js
1439
1473
  /**
1440
1474
  * Formats JavaScript values into readable strings.
1441
1475
  *
@@ -1611,7 +1645,7 @@ function safeGet(input, key) {
1611
1645
  return "[property access threw]";
1612
1646
  }
1613
1647
  }
1614
- // ../../node_modules/.pnpm/effect@4.1.0/node_modules/effect/dist/Inspectable.js
1648
+ // ../../node_modules/.pnpm/effect@4.1.1/node_modules/effect/dist/Inspectable.js
1615
1649
  /**
1616
1650
  * Controls how values appear in logs and debugging output.
1617
1651
  *
@@ -1739,7 +1773,7 @@ const BaseProto = {
1739
1773
  return format$1(this.toJSON());
1740
1774
  }
1741
1775
  };
1742
- // ../../node_modules/.pnpm/effect@4.1.0/node_modules/effect/dist/internal/stackTraceLimit.js
1776
+ // ../../node_modules/.pnpm/effect@4.1.1/node_modules/effect/dist/internal/stackTraceLimit.js
1743
1777
  /**
1744
1778
  * Check if `Error.stackTraceLimit` is writable.
1745
1779
  * Returns `false` if the property is frozen, non-writable, or `Error` is non-extensible.
@@ -1770,7 +1804,7 @@ const getStackTraceLimit = () => Error.stackTraceLimit;
1770
1804
  const setStackTraceLimit = (value) => {
1771
1805
  if (canWriteStackTraceLimit) Error.stackTraceLimit = value;
1772
1806
  };
1773
- // ../../node_modules/.pnpm/effect@4.1.0/node_modules/effect/dist/Utils.js
1807
+ // ../../node_modules/.pnpm/effect@4.1.1/node_modules/effect/dist/Utils.js
1774
1808
  /**
1775
1809
  * Yields its wrapped value exactly once, then completes with the value sent
1776
1810
  * back in.
@@ -1852,7 +1886,7 @@ const pickInternalCall = () => {
1852
1886
  };
1853
1887
  /** @internal */
1854
1888
  const internalCall = /*#__PURE__*/ pickInternalCall();
1855
- // ../../node_modules/.pnpm/effect@4.1.0/node_modules/effect/dist/internal/record.js
1889
+ // ../../node_modules/.pnpm/effect@4.1.1/node_modules/effect/dist/internal/record.js
1856
1890
  /** @internal */
1857
1891
  function assignProperty(self, key, value) {
1858
1892
  if (key === "__proto__") Object.defineProperty(self, key, {
@@ -1871,7 +1905,7 @@ function assignProperties(self, source) {
1871
1905
  }
1872
1906
  for (const key of Reflect.ownKeys(source)) if (Object.prototype.propertyIsEnumerable.call(source, key)) assignProperty(self, key, source[key]);
1873
1907
  }
1874
- // ../../node_modules/.pnpm/effect@4.1.0/node_modules/effect/dist/internal/core.js
1908
+ // ../../node_modules/.pnpm/effect@4.1.1/node_modules/effect/dist/internal/core.js
1875
1909
  /** @internal */
1876
1910
  const EffectTypeId = `~effect/Effect`;
1877
1911
  /** @internal */
@@ -2251,7 +2285,7 @@ const TaggedError$1 = (tag) => {
2251
2285
  const DoneTypeId = "~effect/Cause/Done";
2252
2286
  /** @internal */
2253
2287
  const isDone = (u) => hasProperty(u, DoneTypeId);
2254
- // ../../node_modules/.pnpm/effect@4.1.0/node_modules/effect/dist/Effectable.js
2288
+ // ../../node_modules/.pnpm/effect@4.1.1/node_modules/effect/dist/Effectable.js
2255
2289
  /**
2256
2290
  * Create a low-level `Effect` prototype.
2257
2291
  *
@@ -2276,7 +2310,7 @@ const Prototype = (options) => makePrimitiveProto({
2276
2310
  op: options.label,
2277
2311
  [evaluate]: options.evaluate
2278
2312
  });
2279
- // ../../node_modules/.pnpm/effect@4.1.0/node_modules/effect/dist/internal/option.js
2313
+ // ../../node_modules/.pnpm/effect@4.1.1/node_modules/effect/dist/internal/option.js
2280
2314
  /**
2281
2315
  * @since 2.0.0
2282
2316
  */
@@ -2346,7 +2380,7 @@ const SomeImpl = function(value) {
2346
2380
  SomeImpl.prototype = SomeProto;
2347
2381
  /** @internal */
2348
2382
  const some$1 = (value) => new SomeImpl(value);
2349
- // ../../node_modules/.pnpm/effect@4.1.0/node_modules/effect/dist/internal/result.js
2383
+ // ../../node_modules/.pnpm/effect@4.1.1/node_modules/effect/dist/internal/result.js
2350
2384
  const TypeId$14 = "~effect/Result";
2351
2385
  const CommonProto = {
2352
2386
  [TypeId$14]: {
@@ -2415,7 +2449,7 @@ const SuccessImpl = function(success) {
2415
2449
  this.success = success;
2416
2450
  };
2417
2451
  SuccessImpl.prototype = SuccessProto;
2418
- // ../../node_modules/.pnpm/effect@4.1.0/node_modules/effect/dist/Order.js
2452
+ // ../../node_modules/.pnpm/effect@4.1.1/node_modules/effect/dist/Order.js
2419
2453
  /**
2420
2454
  * Defines comparison functions for ordered values.
2421
2455
  *
@@ -2497,7 +2531,7 @@ function make$10(compare) {
2497
2531
  * @since 4.0.0
2498
2532
  */
2499
2533
  const String$4 = /*#__PURE__*/ make$10((self, that) => self < that ? -1 : 1);
2500
- // ../../node_modules/.pnpm/effect@4.1.0/node_modules/effect/dist/Option.js
2534
+ // ../../node_modules/.pnpm/effect@4.1.1/node_modules/effect/dist/Option.js
2501
2535
  /**
2502
2536
  * Creates an `Option` representing the absence of a value.
2503
2537
  *
@@ -2851,7 +2885,7 @@ const flatMap$3 = /*#__PURE__*/ dual(2, (self, f) => isNone(self) ? none() : f(s
2851
2885
  * @since 2.0.0
2852
2886
  */
2853
2887
  const exists = /*#__PURE__*/ dual(2, (self, refinement) => isNone(self) ? false : refinement(self.value));
2854
- // ../../node_modules/.pnpm/effect@4.1.0/node_modules/effect/dist/Context.js
2888
+ // ../../node_modules/.pnpm/effect@4.1.1/node_modules/effect/dist/Context.js
2855
2889
  /**
2856
2890
  * Runtime type identifier attached to `Context` service keys and used by
2857
2891
  * `isKey` to recognize them.
@@ -3331,13 +3365,13 @@ const serviceNotFoundError = (service) => {
3331
3365
  * @since 3.11.0
3332
3366
  */
3333
3367
  const Reference = Service;
3334
- // ../../node_modules/.pnpm/effect@4.1.0/node_modules/effect/dist/internal/array.js
3368
+ // ../../node_modules/.pnpm/effect@4.1.1/node_modules/effect/dist/internal/array.js
3335
3369
  /**
3336
3370
  * @since 2.0.0
3337
3371
  */
3338
3372
  /** @internal */
3339
3373
  const isArrayNonEmpty$1 = (self) => self.length > 0;
3340
- // ../../node_modules/.pnpm/effect@4.1.0/node_modules/effect/dist/Array.js
3374
+ // ../../node_modules/.pnpm/effect@4.1.1/node_modules/effect/dist/Array.js
3341
3375
  /**
3342
3376
  * Exposes the global array constructor.
3343
3377
  *
@@ -3486,7 +3520,7 @@ const empty = () => [];
3486
3520
  * @since 2.0.0
3487
3521
  */
3488
3522
  const map$2 = /*#__PURE__*/ dual(2, (self, f) => self.map(f));
3489
- // ../../node_modules/.pnpm/effect@4.1.0/node_modules/effect/dist/Duration.js
3523
+ // ../../node_modules/.pnpm/effect@4.1.1/node_modules/effect/dist/Duration.js
3490
3524
  const TypeId$12 = "~effect/Duration";
3491
3525
  const bigint0$1 = /*#__PURE__*/ BigInt(0);
3492
3526
  const bigint1$1 = /*#__PURE__*/ BigInt(1);
@@ -3899,7 +3933,7 @@ const Equivalence$3 = (self, that) => matchPair(self, that, {
3899
3933
  * @since 2.0.0
3900
3934
  */
3901
3935
  const equals = /*#__PURE__*/ dual(2, (self, that) => Equivalence$3(self, that));
3902
- // ../../node_modules/.pnpm/effect@4.1.0/node_modules/effect/dist/Scheduler.js
3936
+ // ../../node_modules/.pnpm/effect@4.1.1/node_modules/effect/dist/Scheduler.js
3903
3937
  /**
3904
3938
  * Controls how runnable Effect fiber tasks are dispatched.
3905
3939
  *
@@ -4182,7 +4216,7 @@ const PreventSchedulerYield = /*#__PURE__*/ Reference("effect/Scheduler/PreventS
4182
4216
  * @since 2.0.0
4183
4217
  */
4184
4218
  const TaggedError = TaggedError$1;
4185
- // ../../node_modules/.pnpm/effect@4.1.0/node_modules/effect/dist/Tracer.js
4219
+ // ../../node_modules/.pnpm/effect@4.1.1/node_modules/effect/dist/Tracer.js
4186
4220
  /**
4187
4221
  * Defines the string key for the parent-span context service.
4188
4222
  *
@@ -4218,10 +4252,10 @@ const ParentSpanKey = "effect/Tracer/ParentSpan";
4218
4252
  * @since 4.0.0
4219
4253
  */
4220
4254
  const TracerKey = "effect/Tracer";
4221
- // ../../node_modules/.pnpm/effect@4.1.0/node_modules/effect/dist/internal/metric.js
4255
+ // ../../node_modules/.pnpm/effect@4.1.1/node_modules/effect/dist/internal/metric.js
4222
4256
  /** @internal */
4223
4257
  const FiberRuntimeMetricsKey = "effect/Metric/FiberRuntimeMetrics";
4224
- // ../../node_modules/.pnpm/effect@4.1.0/node_modules/effect/dist/internal/references.js
4258
+ // ../../node_modules/.pnpm/effect@4.1.1/node_modules/effect/dist/internal/references.js
4225
4259
  /** @internal */
4226
4260
  const CurrentStackFrame = /*#__PURE__*/ Reference("effect/References/CurrentStackFrame", {
4227
4261
  fiberCached: true,
@@ -4242,7 +4276,7 @@ const MinimumLogLevel = /*#__PURE__*/ Reference("effect/References/MinimumLogLev
4242
4276
  fiberCached: true,
4243
4277
  defaultValue: () => "Info"
4244
4278
  });
4245
- // ../../node_modules/.pnpm/effect@4.1.0/node_modules/effect/dist/internal/effect.js
4279
+ // ../../node_modules/.pnpm/effect@4.1.1/node_modules/effect/dist/internal/effect.js
4246
4280
  /** @internal */
4247
4281
  var Interrupt = class extends ReasonBase {
4248
4282
  constructor(fiberId, annotations = constEmptyAnnotations) {
@@ -4402,6 +4436,12 @@ var FiberImpl = class {
4402
4436
  this._stack.length = 0;
4403
4437
  this._children = void 0;
4404
4438
  this.context = empty$1();
4439
+ const cache = this.cache;
4440
+ if (cache.span !== void 0 || cache.stackFrame !== void 0) this.cache = {
4441
+ ...cache,
4442
+ span: void 0,
4443
+ stackFrame: void 0
4444
+ };
4405
4445
  }
4406
4446
  runLoop(effect) {
4407
4447
  const prevFiber = globalThis[currentFiberTypeId];
@@ -4605,6 +4645,18 @@ const failCauseSync$1 = (evaluate) => suspend$1(() => failCause$1(evaluate()));
4605
4645
  const die$2 = (defect) => exitDie(defect);
4606
4646
  /** @internal */
4607
4647
  const void_$1 = /*#__PURE__*/ succeed$3(void 0);
4648
+ /** @internal */
4649
+ const try_$1 = (options) => {
4650
+ const evaluate = typeof options === "function" ? options : options.try;
4651
+ const catcher = typeof options === "function" ? (cause) => new UnknownError(cause, "An error occurred in Effect.try") : options.catch;
4652
+ return suspend$1(() => {
4653
+ try {
4654
+ return succeed$3(evaluate());
4655
+ } catch (err) {
4656
+ return fail$3(catcher(err));
4657
+ }
4658
+ });
4659
+ };
4608
4660
  const callbackOptions = /*#__PURE__*/ function() {
4609
4661
  const Proto = /*#__PURE__*/ makePrimitiveProto({
4610
4662
  op: "Async",
@@ -5013,6 +5065,18 @@ var AsyncFiberError = class extends (/*#__PURE__*/ TaggedError$1("AsyncFiberErro
5013
5065
  });
5014
5066
  }
5015
5067
  };
5068
+ /** @internal */
5069
+ const UnknownErrorTypeId = "~effect/Cause/UnknownError";
5070
+ /** @internal */
5071
+ var UnknownError = class extends (/*#__PURE__*/ TaggedError$1("UnknownError")) {
5072
+ [UnknownErrorTypeId] = UnknownErrorTypeId;
5073
+ constructor(cause, message) {
5074
+ super({
5075
+ message,
5076
+ cause
5077
+ });
5078
+ }
5079
+ };
5016
5080
  const colors = {
5017
5081
  bold: "1",
5018
5082
  red: "31",
@@ -5026,7 +5090,7 @@ const colors = {
5026
5090
  bgBrightRed: "101"
5027
5091
  };
5028
5092
  colors.gray, colors.blue, colors.green, colors.yellow, colors.red, colors.bgBrightRed, colors.black;
5029
- // ../../node_modules/.pnpm/effect@4.1.0/node_modules/effect/dist/Cause.js
5093
+ // ../../node_modules/.pnpm/effect@4.1.1/node_modules/effect/dist/Cause.js
5030
5094
  /**
5031
5095
  * Narrows a `Reason` to `Fail`.
5032
5096
  *
@@ -5111,7 +5175,7 @@ const die$1 = causeDie;
5111
5175
  * @since 2.0.0
5112
5176
  */
5113
5177
  const map = causeMap;
5114
- // ../../node_modules/.pnpm/effect@4.1.0/node_modules/effect/dist/Exit.js
5178
+ // ../../node_modules/.pnpm/effect@4.1.1/node_modules/effect/dist/Exit.js
5115
5179
  /**
5116
5180
  * Creates a successful Exit containing the given value.
5117
5181
  *
@@ -5229,7 +5293,7 @@ const void_ = exitVoid;
5229
5293
  * @since 2.0.0
5230
5294
  */
5231
5295
  const isSuccess = exitIsSuccess;
5232
- // ../../node_modules/.pnpm/effect@4.1.0/node_modules/effect/dist/internal/dateTime.js
5296
+ // ../../node_modules/.pnpm/effect@4.1.1/node_modules/effect/dist/internal/dateTime.js
5233
5297
  /** @internal */
5234
5298
  const TypeId$11 = "~effect/DateTime";
5235
5299
  /** @internal */
@@ -5246,8 +5310,32 @@ const Proto$4 = {
5246
5310
  return toDateUtc$1(this).toJSON();
5247
5311
  }
5248
5312
  };
5249
- ({ ...Proto$4 });
5250
- ({ ...Proto$4 });
5313
+ const ProtoUtc = {
5314
+ ...Proto$4,
5315
+ _tag: "Utc",
5316
+ [symbol$1]() {
5317
+ return number$1(this.epochMilliseconds);
5318
+ },
5319
+ [symbol](that) {
5320
+ return isDateTime$1(that) && that._tag === "Utc" && this.epochMilliseconds === that.epochMilliseconds;
5321
+ },
5322
+ toString() {
5323
+ return `DateTime.Utc(${toDateUtc$1(this).toJSON()})`;
5324
+ }
5325
+ };
5326
+ const ProtoZoned = {
5327
+ ...Proto$4,
5328
+ _tag: "Zoned",
5329
+ [symbol$1]() {
5330
+ return combine(number$1(this.epochMilliseconds))(hash(this.zone));
5331
+ },
5332
+ [symbol](that) {
5333
+ return isDateTime$1(that) && that._tag === "Zoned" && this.epochMilliseconds === that.epochMilliseconds && equals$1(this.zone, that.zone);
5334
+ },
5335
+ toString() {
5336
+ return `DateTime.Zoned(${formatIsoZoned(this)})`;
5337
+ }
5338
+ };
5251
5339
  const ProtoTimeZone = {
5252
5340
  [TimeZoneTypeId]: TimeZoneTypeId,
5253
5341
  [NodeInspectSymbol]() {
@@ -5256,8 +5344,90 @@ const ProtoTimeZone = {
5256
5344
  };
5257
5345
  ({ ...ProtoTimeZone });
5258
5346
  ({ ...ProtoTimeZone });
5347
+ const cacheSlot = {
5348
+ value: void 0,
5349
+ enumerable: false,
5350
+ writable: true
5351
+ };
5352
+ const sealedCaches = /*#__PURE__*/ new WeakMap();
5353
+ const cacheAccessor = (key, slots) => ({
5354
+ get() {
5355
+ return Object.isExtensible(this) ? void 0 : sealedCaches.get(this)?.[key];
5356
+ },
5357
+ set(value) {
5358
+ if (Object.isExtensible(this)) {
5359
+ for (const slot of slots) Object.defineProperty(this, slot, cacheSlot);
5360
+ this[key] = value;
5361
+ } else {
5362
+ let caches = sealedCaches.get(this);
5363
+ if (caches === void 0) {
5364
+ caches = {};
5365
+ sealedCaches.set(this, caches);
5366
+ }
5367
+ caches[key] = value;
5368
+ }
5369
+ }
5370
+ });
5371
+ const zonedSlots = [
5372
+ "partsUtc",
5373
+ "adjustedEpochMilliseconds",
5374
+ "partsAdjusted"
5375
+ ];
5376
+ Object.defineProperty(ProtoUtc, "partsUtc", cacheAccessor("partsUtc", ["partsUtc"]));
5377
+ Object.defineProperties(ProtoZoned, {
5378
+ partsUtc: cacheAccessor("partsUtc", zonedSlots),
5379
+ adjustedEpochMilliseconds: cacheAccessor("adjustedEpochMilliseconds", zonedSlots),
5380
+ partsAdjusted: cacheAccessor("partsAdjusted", zonedSlots)
5381
+ });
5382
+ /** @internal */
5383
+ const isDateTime$1 = (u) => hasProperty(u, TypeId$11);
5259
5384
  /** @internal */
5260
5385
  const toDateUtc$1 = (self) => new Date(self.epochMilliseconds);
5386
+ /** @internal */
5387
+ const toDate = (self) => {
5388
+ if (self._tag === "Utc") return new Date(self.epochMilliseconds);
5389
+ else if (self.zone._tag === "Offset") return new Date(self.epochMilliseconds + self.zone.offset);
5390
+ else if (self.adjustedEpochMilliseconds !== void 0) return new Date(self.adjustedEpochMilliseconds);
5391
+ let bc = false;
5392
+ const parts = self.zone.format.formatToParts(self.epochMilliseconds).filter((_) => {
5393
+ if (_.type === "era") {
5394
+ bc = _.value === "BC";
5395
+ return false;
5396
+ }
5397
+ return _.type !== "literal";
5398
+ });
5399
+ const year = Number(parts[2].value);
5400
+ const date = /* @__PURE__ */ new Date(0);
5401
+ date.setUTCFullYear(bc ? 1 - year : year, Number(parts[0].value) - 1, Number(parts[1].value));
5402
+ date.setUTCHours(Number(parts[3].value), Number(parts[4].value), Number(parts[5].value), parts[6]?.type === "fractionalSecond" ? Number(parts[6].value) : (self.epochMilliseconds % 1e3 + 1e3) % 1e3);
5403
+ self.adjustedEpochMilliseconds = date.getTime();
5404
+ return date;
5405
+ };
5406
+ /** @internal */
5407
+ const zonedOffset = (self) => {
5408
+ return toDate(self).getTime() - toEpochMillis$1(self);
5409
+ };
5410
+ const offsetToString = (offset) => {
5411
+ const abs = Math.abs(offset);
5412
+ let hours = Math.floor(abs / 36e5);
5413
+ let minutes = Math.round(abs % 36e5 / 6e4);
5414
+ if (minutes === 60) {
5415
+ hours += 1;
5416
+ minutes = 0;
5417
+ }
5418
+ return `${offset < 0 ? "-" : "+"}${String(hours).padStart(2, "0")}:${String(minutes).padStart(2, "0")}`;
5419
+ };
5420
+ /** @internal */
5421
+ const zonedOffsetIso = (self) => offsetToString(zonedOffset(self));
5422
+ /** @internal */
5423
+ const toEpochMillis$1 = (self) => self.epochMilliseconds;
5424
+ /** @internal */
5425
+ const formatIsoOffset = (self) => {
5426
+ const date = toDate(self);
5427
+ return self._tag === "Utc" ? date.toISOString() : `${date.toISOString().slice(0, -1)}${zonedOffsetIso(self)}`;
5428
+ };
5429
+ /** @internal */
5430
+ const formatIsoZoned = (self) => self.zone._tag === "Offset" ? formatIsoOffset(self) : `${formatIsoOffset(self)}[${self.zone.id}]`;
5261
5431
  /**
5262
5432
  * Creates an `Effect` that always succeeds with a given value.
5263
5433
  *
@@ -5477,6 +5647,7 @@ const failCauseSync = failCauseSync$1;
5477
5647
  * @since 2.0.0
5478
5648
  */
5479
5649
  const die = die$2;
5650
+ const try_ = try_$1;
5480
5651
  /**
5481
5652
  * Chains effects to produce new `Effect` instances, useful for combining
5482
5653
  * operations that depend on previous results.
@@ -5791,7 +5962,7 @@ const flatMapEager = flatMapEager$1;
5791
5962
  * @since 4.0.0
5792
5963
  */
5793
5964
  const fnUntracedEager = fnUntracedEager$1;
5794
- // ../../node_modules/.pnpm/effect@4.1.0/node_modules/effect/dist/BigDecimal.js
5965
+ // ../../node_modules/.pnpm/effect@4.1.1/node_modules/effect/dist/BigDecimal.js
5795
5966
  /**
5796
5967
  * Decimal numbers and arithmetic for cases where JavaScript `number` rounding
5797
5968
  * is not precise enough. A `BigDecimal` stores digits as a `bigint` plus a
@@ -5799,6 +5970,9 @@ const fnUntracedEager = fnUntracedEager$1;
5799
5970
  * divide, round, and format decimal values such as money, quantities, and
5800
5971
  * measurements.
5801
5972
  *
5973
+ * Parsed scales are limited to ±10,000, and operations that align scales throw
5974
+ * a `RangeError` when the scales differ by more than 20,000.
5975
+ *
5802
5976
  * @stability stable
5803
5977
  * @since 2.0.0
5804
5978
  */
@@ -5932,13 +6106,17 @@ const normalize = (self) => {
5932
6106
  if (self.value === bigint0) self.normalized = zero;
5933
6107
  else {
5934
6108
  const digits = `${self.value}`;
5935
- let end = digits.length;
5936
- while (digits[end - 1] === "0") end--;
5937
- self.normalized = makeNormalized(BigInt(digits.slice(0, end)), self.scale - (digits.length - end));
6109
+ const zeros = trailingZeros(digits);
6110
+ self.normalized = makeNormalized(BigInt(digits.slice(0, digits.length - zeros)), self.scale - zeros);
5938
6111
  }
5939
6112
  }
5940
6113
  return self.normalized;
5941
6114
  };
6115
+ const trailingZeros = (digits) => {
6116
+ let end = digits.length;
6117
+ while (digits[end - 1] === "0") end--;
6118
+ return digits.length - end;
6119
+ };
5942
6120
  const MAX_COMPARISON_SCALE_ALIGNMENT = 100;
5943
6121
  const comparisonPowersOfTen = [bigint1];
5944
6122
  const compareBigInt = (self, that) => self === that ? 0 : self < that ? -1 : 1;
@@ -6084,7 +6262,7 @@ codes[/*#__PURE__*/ "=".charCodeAt(0)] = 0;
6084
6262
  ({ ...PipeInspectableProto });
6085
6263
  BaseProto.toString, BaseProto[NodeInspectSymbol];
6086
6264
  ({ ...PipeInspectableProto });
6087
- // ../../node_modules/.pnpm/effect@4.1.0/node_modules/effect/dist/internal/schema/annotations.js
6265
+ // ../../node_modules/.pnpm/effect@4.1.1/node_modules/effect/dist/internal/schema/annotations.js
6088
6266
  /** @internal */
6089
6267
  function resolve$1(ast) {
6090
6268
  return ast.checks ? ast.checks[ast.checks.length - 1].annotations : ast.annotations;
@@ -6099,7 +6277,7 @@ const getExpected = /*#__PURE__*/ memoize((ast) => {
6099
6277
  if (typeof identifier === "string") return identifier;
6100
6278
  return ast.getExpected(getExpected);
6101
6279
  });
6102
- // ../../node_modules/.pnpm/effect@4.1.0/node_modules/effect/dist/internal/schema/parser.js
6280
+ // ../../node_modules/.pnpm/effect@4.1.1/node_modules/effect/dist/internal/schema/parser.js
6103
6281
  /** @internal */
6104
6282
  const missing = /*#__PURE__*/ Symbol();
6105
6283
  /** @internal */
@@ -6112,7 +6290,7 @@ const sameExit = /*#__PURE__*/ succeed(missing);
6112
6290
  const toOption = (value) => value === missing ? none() : some(value);
6113
6291
  /** @internal */
6114
6292
  const fromOptionExit = (option) => option._tag === "None" ? missingExit : succeed(option.value);
6115
- // ../../node_modules/.pnpm/effect@4.1.0/node_modules/effect/dist/SchemaIssue.js
6293
+ // ../../node_modules/.pnpm/effect@4.1.1/node_modules/effect/dist/SchemaIssue.js
6116
6294
  /**
6117
6295
  * Describes problems found while decoding, encoding, or checking data with
6118
6296
  * schemas.
@@ -6605,7 +6783,7 @@ function findMessage(issue) {
6605
6783
  const message = (issue._tag === "Filter" ? issue.filter.annotations : "annotations" in issue ? issue.annotations : issue.ast.annotations)?.[issue._tag === "MissingKey" ? "messageMissingKey" : issue._tag === "UnexpectedKey" ? "messageUnexpectedKey" : "message"];
6606
6784
  if (typeof message === "string") return message;
6607
6785
  }
6608
- // ../../node_modules/.pnpm/effect@4.1.0/node_modules/effect/dist/internal/schema/cause.js
6786
+ // ../../node_modules/.pnpm/effect@4.1.1/node_modules/effect/dist/internal/schema/cause.js
6609
6787
  /** @internal */
6610
6788
  function getSchemaIssue(cause) {
6611
6789
  let issue;
@@ -6621,8 +6799,12 @@ function getSchemaIssueOrThrow(cause, message) {
6621
6799
  if (issue === void 0) throw new Error(message, { cause });
6622
6800
  return issue;
6623
6801
  }
6624
- // ../../node_modules/.pnpm/effect@4.1.0/node_modules/effect/dist/SchemaGetter.js
6802
+ // ../../node_modules/.pnpm/effect@4.1.1/node_modules/effect/dist/SchemaGetter.js
6625
6803
  const makeGetter = (fields) => Object.assign(Object.create(Prototype$1), fields);
6804
+ const passthrough_$1 = /*#__PURE__*/ makeGetter({ _tag: "Passthrough" });
6805
+ function passthrough$1() {
6806
+ return passthrough_$1;
6807
+ }
6626
6808
  /**
6627
6809
  * Creates a getter that applies a pure function to present values.
6628
6810
  *
@@ -6668,6 +6850,49 @@ function transform$1(f) {
6668
6850
  });
6669
6851
  }
6670
6852
  /**
6853
+ * Creates a getter that applies an effectful transformation to present values.
6854
+ *
6855
+ * **When to use**
6856
+ *
6857
+ * Use when you need a schema getter for a transformation that may fail, require
6858
+ * Effect services, or run asynchronously.
6859
+ *
6860
+ * **Details**
6861
+ *
6862
+ * - Skips `None` inputs — only called when a value is present.
6863
+ * - On success, wraps the result in `Some`.
6864
+ * - On failure, propagates the `Issue`.
6865
+ *
6866
+ * **Example** (Parsing with failure)
6867
+ *
6868
+ * ```ts import.meta.vitest
6869
+ * import { Effect, Option, SchemaGetter, SchemaIssue } from "effect"
6870
+ *
6871
+ * const safeParseInt = SchemaGetter.transformEffect<number, string>(
6872
+ * (s, options) => {
6873
+ * const n = parseInt(s, 10)
6874
+ * return isNaN(n)
6875
+ * ? Effect.fail(new SchemaIssue.InvalidValue({ message: "not an integer" }, s, options))
6876
+ * : Effect.succeed(n)
6877
+ * }
6878
+ * )
6879
+ * await Effect.runPromise(SchemaGetter.run(safeParseInt, Option.some("42"), {})) // => Option.some(42)
6880
+ * ```
6881
+ *
6882
+ * @see {@link transform} when transformation cannot fail
6883
+ * @see {@link transformOptionalEffect} when you need full `Option` control over the output
6884
+ *
6885
+ * @stability stable
6886
+ * @category transforming
6887
+ * @since 4.0.0
6888
+ */
6889
+ function transformEffect$1(f) {
6890
+ return makeGetter({
6891
+ _tag: "TransformEffect",
6892
+ transform: f
6893
+ });
6894
+ }
6895
+ /**
6671
6896
  * Coerces any value to a `string` using the global `String()` constructor.
6672
6897
  *
6673
6898
  * **When to use**
@@ -6728,7 +6953,62 @@ function String$3() {
6728
6953
  function Number$3() {
6729
6954
  return transform$1(globalThis.Number);
6730
6955
  }
6731
- // ../../node_modules/.pnpm/effect@4.1.0/node_modules/effect/dist/SchemaTransformation.js
6956
+ function parseJson(options) {
6957
+ return transformEffect$1((input, parseOptions) => try_({
6958
+ try: () => JSON.parse(input, options?.reviver),
6959
+ catch: () => new InvalidValue({ expected: "a valid JSON string" }, input, parseOptions)
6960
+ }));
6961
+ }
6962
+ /**
6963
+ * Stringifies a present value using `JSON.stringify`.
6964
+ *
6965
+ * **When to use**
6966
+ *
6967
+ * Use when you need a schema getter to serialize a present decoded value to
6968
+ * JSON text during encoding.
6969
+ *
6970
+ * **Details**
6971
+ *
6972
+ * - Skips `None` inputs.
6973
+ * - If `JSON.stringify` throws or returns `undefined`, fails with
6974
+ * `SchemaIssue.InvalidValue`.
6975
+ * - Supports optional `replacer` and `space` options, matching
6976
+ * `JSON.stringify`.
6977
+ *
6978
+ * **Example** (Stringifying JSON)
6979
+ *
6980
+ * ```ts import.meta.vitest
6981
+ * import { Effect, Option, SchemaGetter } from "effect"
6982
+ *
6983
+ * const stringify = SchemaGetter.stringifyJson()
6984
+ * const result = await Effect.runPromise(SchemaGetter.run(stringify, Option.some({ a: 1 }), {}))
6985
+ * result // => Option.some("{\"a\":1}")
6986
+ * ```
6987
+ *
6988
+ * @see {@link parseJson} for the inverse operation
6989
+ *
6990
+ * @stability stable
6991
+ * @category encoding
6992
+ * @since 4.0.0
6993
+ */
6994
+ function stringifyJson(options) {
6995
+ return transformEffect$1((input, parseOptions) => try_({
6996
+ try: () => {
6997
+ const output = JSON.stringify(input, options?.replacer, options?.space);
6998
+ if (output === void 0) throw new TypeError("Value cannot be represented as JSON");
6999
+ return output;
7000
+ },
7001
+ catch: () => new InvalidValue({ expected: "a JSON-serializable value" }, input, parseOptions)
7002
+ }));
7003
+ }
7004
+ // ../../node_modules/.pnpm/effect@4.1.1/node_modules/effect/dist/internal/schema/content.js
7005
+ const ContentTypeId = /*#__PURE__*/ Symbol.for("~effect/Schema/content");
7006
+ /** @internal */
7007
+ function setContent(operation, content) {
7008
+ Object.defineProperty(operation, ContentTypeId, { value: content });
7009
+ return operation;
7010
+ }
7011
+ // ../../node_modules/.pnpm/effect@4.1.1/node_modules/effect/dist/SchemaTransformation.js
6732
7012
  /**
6733
7013
  * Constructs schema middleware from its decode and encode functions.
6734
7014
  *
@@ -6772,6 +7052,80 @@ const Transformation = class extends Class$1 {
6772
7052
  }
6773
7053
  };
6774
7054
  /**
7055
+ * Returns `true` if `u` is a `Transformation` instance.
7056
+ *
7057
+ * **When to use**
7058
+ *
7059
+ * Use to check whether a value is already a schema transformation before
7060
+ * wrapping it.
7061
+ *
7062
+ * **Details**
7063
+ *
7064
+ * - Pure predicate, no side effects.
7065
+ * - Acts as a TypeScript type guard.
7066
+ *
7067
+ * **Example** (Checking a value)
7068
+ *
7069
+ * ```ts import.meta.vitest
7070
+ * import { SchemaTransformation } from "effect"
7071
+ *
7072
+ * SchemaTransformation.isTransformation(SchemaTransformation.trim()) // => true
7073
+ * SchemaTransformation.isTransformation({ decode: null, encode: null }) // => false
7074
+ * ```
7075
+ *
7076
+ * @see {@link Transformation}
7077
+ * @see {@link makeTransformation}
7078
+ *
7079
+ * @stability stable
7080
+ * @category guards
7081
+ * @since 4.0.0
7082
+ */
7083
+ function isTransformation(u) {
7084
+ return hasProperty(u, TypeId$4) && u[TypeId$4] === TypeId$4;
7085
+ }
7086
+ /**
7087
+ * Constructs a `Transformation` from an object with `decode` and `encode`
7088
+ * `Getter`s. If the input is already a `Transformation`, returns it as-is.
7089
+ *
7090
+ * **When to use**
7091
+ *
7092
+ * Use when you already have schema getter instances and want to pair them into
7093
+ * a schema transformation.
7094
+ * - You want idempotent wrapping (won't double-wrap).
7095
+ *
7096
+ * **Details**
7097
+ *
7098
+ * - Returns the input unchanged if it is already a `Transformation`.
7099
+ *
7100
+ * **Example** (Wrapping existing getters)
7101
+ *
7102
+ * ```ts import.meta.vitest
7103
+ * import { SchemaGetter, SchemaTransformation } from "effect"
7104
+ *
7105
+ * const t = SchemaTransformation.makeTransformation({
7106
+ * decode: SchemaGetter.transform<number, string>((s) => Number(s)),
7107
+ * encode: SchemaGetter.transform<string, number>((n) => String(n))
7108
+ * })
7109
+ * t._tag // => "Transformation"
7110
+ * ```
7111
+ *
7112
+ * @see {@link transform} — simpler constructor from pure functions
7113
+ * @see {@link transformEffect} — constructor from effectful functions
7114
+ * @see {@link Transformation}
7115
+ *
7116
+ * @stability stable
7117
+ * @category constructors
7118
+ * @since 3.10.0
7119
+ */
7120
+ const makeTransformation = (options) => {
7121
+ if (isTransformation(options)) return options;
7122
+ return new Transformation(options.decode, options.encode);
7123
+ };
7124
+ const passthrough_ = /*#__PURE__*/ new Transformation(/*#__PURE__*/ passthrough$1(), /*#__PURE__*/ passthrough$1());
7125
+ function passthrough() {
7126
+ return passthrough_;
7127
+ }
7128
+ /**
6775
7129
  * Decodes a `string` into a `number` and encodes a `number` back to a
6776
7130
  * `string`.
6777
7131
  *
@@ -6806,7 +7160,48 @@ const Transformation = class extends Class$1 {
6806
7160
  * @since 4.0.0
6807
7161
  */
6808
7162
  const numberFromString = /*#__PURE__*/ new Transformation(/*#__PURE__*/ Number$3(), /*#__PURE__*/ String$3());
6809
- // ../../node_modules/.pnpm/effect@4.1.0/node_modules/effect/dist/SchemaAST.js
7163
+ /**
7164
+ * Decodes a JSON string with `JSON.parse` and encodes a value with
7165
+ * `JSON.stringify`.
7166
+ *
7167
+ * **When to use**
7168
+ *
7169
+ * Use when you need a schema transformation to decode JSON stored or
7170
+ * transmitted as a string, usually before composing with another schema that
7171
+ * validates the parsed structure.
7172
+ *
7173
+ * **Details**
7174
+ *
7175
+ * The `reviver` option is passed to `JSON.parse` during decoding. The
7176
+ * `replacer` and `space` options are passed to `JSON.stringify` during
7177
+ * encoding. Decode fails with `InvalidValue` for invalid JSON, and encode can
7178
+ * fail with `InvalidValue` when `JSON.stringify` cannot serialize the value.
7179
+ *
7180
+ * **Example** (Parsing JSON)
7181
+ *
7182
+ * ```ts import.meta.vitest
7183
+ * import { Schema, SchemaTransformation } from "effect"
7184
+ *
7185
+ * const schema = Schema.String.pipe(
7186
+ * Schema.decodeTo(Schema.Unknown, SchemaTransformation.fromJsonString())
7187
+ * )
7188
+ * Schema.decodeSync(schema)("{\"ok\":true}") // => { ok: true }
7189
+ * ```
7190
+ *
7191
+ * @see {@link uint8ArrayFromBase64String}
7192
+ * @see {@link fromFormData}
7193
+ *
7194
+ * @stability stable
7195
+ * @category decoding
7196
+ * @since 4.0.0
7197
+ */
7198
+ function fromJsonString$1(options) {
7199
+ return new Transformation(parseJson(options ?? {}), setContent(stringifyJson(options), {
7200
+ mediaType: "application/json",
7201
+ preserveSchema: options?.reviver === void 0 && options?.replacer === void 0
7202
+ }));
7203
+ }
7204
+ // ../../node_modules/.pnpm/effect@4.1.1/node_modules/effect/dist/SchemaAST.js
6810
7205
  /**
6811
7206
  * Represents Effect schemas as runtime trees.
6812
7207
  *
@@ -8298,6 +8693,10 @@ function applyToSelfOrLastLinkEncodingIdempotent(f, options) {
8298
8693
  }
8299
8694
  return memoizeIdempotent(out);
8300
8695
  }
8696
+ function appendTransformation(from, transformation, to) {
8697
+ const link = new Link(from, transformation);
8698
+ return replaceEncoding(to, to.encoding ? [...to.encoding, link] : [link]);
8699
+ }
8301
8700
  function mapOrSame(as, f) {
8302
8701
  let out;
8303
8702
  for (let i = 0; i < as.length; i++) {
@@ -8327,6 +8726,27 @@ const optionalKey = /*#__PURE__*/ memoizeIdempotent((ast) => {
8327
8726
  const optionalKeyLastLink = /*#__PURE__*/ applyToLastLink(optionalKey);
8328
8727
  /** @internal */
8329
8728
  const optional$1 = /*#__PURE__*/ memoize((ast) => optionalKey(new Union$1([ast, undefined_])));
8729
+ /**
8730
+ * Attaches a `Transformation` to the `to` AST, making it decode from the
8731
+ * `from` AST and encode back to it.
8732
+ *
8733
+ * **Details**
8734
+ *
8735
+ * This is the low-level primitive behind `Schema.decodeTo`. It appends a
8736
+ * {@link Link} to the `to` node's encoding chain.
8737
+ *
8738
+ * - Returns a new AST with the same type as `to`.
8739
+ *
8740
+ * @see {@link Link}
8741
+ * @see {@link Encoding}
8742
+ * @see {@link flip}
8743
+ * @stability stable
8744
+ * @category transforming
8745
+ * @since 4.0.0
8746
+ */
8747
+ function decodeTo$1(from, to, transformation) {
8748
+ return appendTransformation(from, transformation, to);
8749
+ }
8330
8750
  function parseParameter(ast) {
8331
8751
  const literals = [];
8332
8752
  const parameters = [];
@@ -8574,7 +8994,7 @@ function getConstructorDescriptor(ast) {
8574
8994
  const getDescriptor = ast.annotations?.[CONSTRUCTOR_ANNOTATION_KEY];
8575
8995
  return isFunction(getDescriptor) ? getDescriptor(ast.typeParameters) : void 0;
8576
8996
  }
8577
- // ../../node_modules/.pnpm/effect@4.1.0/node_modules/effect/dist/internal/schema/interpreter.js
8997
+ // ../../node_modules/.pnpm/effect@4.1.1/node_modules/effect/dist/internal/schema/interpreter.js
8578
8998
  const flatMapTransformation = (result, current, f) => result === sameExit ? f(current) : flatMapEager(result, f);
8579
8999
  function compileTransformation(transformation) {
8580
9000
  const apply = compileTransformationUnsafe(transformation);
@@ -8722,7 +9142,7 @@ function compile(ast, compile, compileField, base, specialize) {
8722
9142
  });
8723
9143
  };
8724
9144
  }
8725
- // ../../node_modules/.pnpm/effect@4.1.0/node_modules/effect/dist/internal/schema/compilerRegistry.js
9145
+ // ../../node_modules/.pnpm/effect@4.1.1/node_modules/effect/dist/internal/schema/compilerRegistry.js
8726
9146
  /** @internal */
8727
9147
  const invalid = /*#__PURE__*/ Symbol();
8728
9148
  const cache = /*#__PURE__*/ new WeakMap();
@@ -8752,7 +9172,7 @@ function resolve(ast) {
8752
9172
  cache.set(ast, entry);
8753
9173
  return entry;
8754
9174
  }
8755
- // ../../node_modules/.pnpm/effect@4.1.0/node_modules/effect/dist/SchemaParser.js
9175
+ // ../../node_modules/.pnpm/effect@4.1.1/node_modules/effect/dist/SchemaParser.js
8756
9176
  /**
8757
9177
  * Runs schemas against real values.
8758
9178
  *
@@ -8877,6 +9297,10 @@ function decodeUnknownEffect$1(schema, options) {
8877
9297
  const parser = run(schema.ast);
8878
9298
  return options === void 0 ? parser : (input, overrideOptions) => parser(input, mergeParseOptions(options, overrideOptions));
8879
9299
  }
9300
+ /** @internal */
9301
+ function decodeUnknownOption$1(schema, options) {
9302
+ return asOption(decodeUnknownEffect$1(schema, options));
9303
+ }
8880
9304
  const mergeParseOptions = (options, overrideOptions) => overrideOptions ? {
8881
9305
  ...options,
8882
9306
  ...overrideOptions
@@ -8903,6 +9327,19 @@ function runWithCompiler(compiler, ast) {
8903
9327
  return result["~effect/Effect/args"] === missing ? getValue(missing) : result;
8904
9328
  };
8905
9329
  }
9330
+ function asExit(parser) {
9331
+ return (input, options) => runSyncExit(parser(input, options));
9332
+ }
9333
+ /** @internal */
9334
+ function asOption(parser) {
9335
+ const parserExit = asExit(parser);
9336
+ return (input, options) => {
9337
+ const exit = parserExit(input, options);
9338
+ if (isSuccess(exit)) return some(exit.value);
9339
+ getSchemaIssueOrThrow(exit.cause, "Option adapter can only return none for schema issues");
9340
+ return none();
9341
+ };
9342
+ }
8906
9343
  function runSync(effect, message) {
8907
9344
  const exit = runSyncExit(effect);
8908
9345
  if (isSuccess(exit)) return exit.value;
@@ -8936,7 +9373,7 @@ function constructSync(entry, input, options) {
8936
9373
  }
8937
9374
  const normalCompiler = (ast) => resolve(ast).parser;
8938
9375
  const constructorCompiler = (ast) => resolve(ast).makeEffect;
8939
- // ../../node_modules/.pnpm/effect@4.1.0/node_modules/effect/dist/internal/schema/make.js
9376
+ // ../../node_modules/.pnpm/effect@4.1.1/node_modules/effect/dist/internal/schema/make.js
8940
9377
  /** @internal */
8941
9378
  const TypeId$2 = "~effect/Schema/Schema";
8942
9379
  const RebuildOptions = /*#__PURE__*/ Symbol();
@@ -8992,7 +9429,7 @@ function make$1(ast, options) {
8992
9429
  self.ast = ast;
8993
9430
  return self;
8994
9431
  }
8995
- // ../../node_modules/.pnpm/effect@4.1.0/node_modules/effect/dist/Struct.js
9432
+ // ../../node_modules/.pnpm/effect@4.1.1/node_modules/effect/dist/Struct.js
8996
9433
  /**
8997
9434
  * Wraps a plain function as a {@link Lambda} value so it can be used with
8998
9435
  * {@link map}, {@link mapPick}, and {@link mapOmit}.
@@ -9031,7 +9468,7 @@ function make$1(ast, options) {
9031
9468
  * @since 4.0.0
9032
9469
  */
9033
9470
  const lambda = (f) => f;
9034
- // ../../node_modules/.pnpm/effect@4.1.0/node_modules/effect/dist/internal/schemaError.js
9471
+ // ../../node_modules/.pnpm/effect@4.1.1/node_modules/effect/dist/internal/schemaError.js
9035
9472
  const SchemaErrorTypeId = "~effect/Schema/SchemaError";
9036
9473
  function isSchemaError$1(u) {
9037
9474
  return hasProperty(u, "~effect/Schema/SchemaError") && u["~effect/Schema/SchemaError"] === "~effect/Schema/SchemaError";
@@ -9176,6 +9613,34 @@ function decodeUnknownEffect(schema, options) {
9176
9613
  };
9177
9614
  }
9178
9615
  /**
9616
+ * Decodes an `unknown` input against a schema, returning an `Option` that is
9617
+ * `Some` with the decoded value on success or `None` for schema mismatches.
9618
+ *
9619
+ * **When to use**
9620
+ *
9621
+ * Use when you do not know the input type statically and only need to know
9622
+ * whether decoding succeeded.
9623
+ *
9624
+ * **Details**
9625
+ *
9626
+ * Prefer this over {@link decodeUnknownExit} or {@link decodeUnknownEffect}
9627
+ * when you don't need error details. For input already typed as the schema's
9628
+ * `Encoded` type use {@link decodeOption}.
9629
+ * Options may be provided either when creating the decoder or when applying it;
9630
+ * application options override creation options.
9631
+ *
9632
+ * **Gotchas**
9633
+ *
9634
+ * Only causes made entirely of schema issues are converted to `None`. Causes
9635
+ * that contain defects, interruptions, or other non-schema reasons throw
9636
+ * instead.
9637
+ *
9638
+ * @stability stable
9639
+ * @category decoding
9640
+ * @since 3.10.0
9641
+ */
9642
+ const decodeUnknownOption = decodeUnknownOption$1;
9643
+ /**
9179
9644
  * Decodes an `unknown` input against a schema synchronously, returning the
9180
9645
  * decoded value or throwing a {@link SchemaError} for schema mismatches.
9181
9646
  *
@@ -9433,8 +9898,50 @@ function Union(members, options) {
9433
9898
  * @since 3.10.0
9434
9899
  */
9435
9900
  const UndefinedOr = /*#__PURE__*/ lambda((self) => Union([self, Undefined]));
9901
+ function decodeTo(to, transformation) {
9902
+ return (from) => {
9903
+ return make(decodeTo$1(from.ast, to.ast, transformation ? makeTransformation(transformation) : passthrough()), {
9904
+ from,
9905
+ to
9906
+ });
9907
+ };
9908
+ }
9436
9909
  globalThis.RegExp;
9437
9910
  globalThis.URL;
9911
+ const JsonString = /*#__PURE__*/ String$1.annotate({ expected: "a string that will be decoded as JSON" });
9912
+ /**
9913
+ * Returns a schema that decodes a JSON string and then decodes the parsed value
9914
+ * using the given schema.
9915
+ *
9916
+ * **Details**
9917
+ *
9918
+ * This is useful when working with JSON-encoded strings where the actual
9919
+ * structure of the value is known and described by an existing schema.
9920
+ *
9921
+ * During decoding, the resulting schema first parses the input string as JSON,
9922
+ * using `reviver` when provided, and then runs the provided schema on the
9923
+ * parsed result. During encoding, it first encodes with the provided schema and
9924
+ * then passes the result to `JSON.stringify` with the optional `replacer` and
9925
+ * `space`.
9926
+ *
9927
+ * **Example** (Formatting encoded JSON)
9928
+ *
9929
+ * ```ts import.meta.vitest
9930
+ * import { Schema } from "effect"
9931
+ *
9932
+ * const schema = Schema.Struct({ a: Schema.Number })
9933
+ * const schemaFromJsonString = Schema.fromJsonString(schema, { space: 2 })
9934
+ *
9935
+ * Schema.encodeSync(schemaFromJsonString)({ a: 1 }) // => "{\n \"a\": 1\n}"
9936
+ * ```
9937
+ *
9938
+ * @stability stable
9939
+ * @category schemas
9940
+ * @since 4.0.0
9941
+ */
9942
+ function fromJsonString(schema, options) {
9943
+ return JsonString.pipe(decodeTo(schema, fromJsonString$1(options)));
9944
+ }
9438
9945
  globalThis.File;
9439
9946
  globalThis.URLSearchParams;
9440
9947
  globalThis.Uint8Array;
@@ -9723,208 +10230,11 @@ const outlineText = (docs, topic) => match$2(topic, {
9723
10230
  });
9724
10231
  /** The topics there are, for a `--list` of one that is not. */
9725
10232
  const topicsOf = (docs) => [...new Set(docs.map((doc) => doc.topic))];
9726
- // src/project.ts
10233
+ // src/setup.ts
9727
10234
  /**
9728
- * What the CLI reads from the disk: the project in a folder, its package
9729
- * manager, and this package's own manifest.
9730
- */
9731
- const Versions = Record(String$1, String$1);
9732
- const Manifest = Struct({
9733
- name: optional(String$1),
9734
- version: optional(String$1),
9735
- dependencies: optional(Versions),
9736
- devDependencies: optional(Versions),
9737
- peerDependencies: optional(Versions),
9738
- setup: optional(Struct({
9739
- effect: String$1,
9740
- foldkit: String$1
9741
- }))
9742
- });
9743
- const readManifest = (path) => decodeUnknownSync(Manifest)(JSON.parse(readFileSync(path, "utf8")));
9744
- /**
9745
- * A project's folder and those above it, up to its repository's root and no
9746
- * further, and never into the home folder: a file left there says nothing
9747
- * about this project. A folder that is no project has none.
9748
- */
9749
- const projectFolders = (folder) => {
9750
- const folders = [];
9751
- const project = existsSync(join(folder, "package.json"));
9752
- for (let at = folder; project && at !== homedir(); at = dirname(at)) {
9753
- folders.push(at);
9754
- if (existsSync(join(at, ".git")) || dirname(at) === at) break;
9755
- }
9756
- return folders;
9757
- };
9758
- /**
9759
- * Where pnpm reads `folder`'s `overrides` and `peerDependencyRules`: the
9760
- * workspace root, the nearest folder at or above it with a
9761
- * `pnpm-workspace.yaml`, since pnpm ignores them in a member's `package.json`.
9762
- * There, the root `package.json`'s `pnpm` field if it already has one, else
9763
- * the YAML; with no workspace, the project's own `package.json`.
9764
- */
9765
- const pnpmSettingsIn = (folder) => {
9766
- const root = projectFolders(folder).find((at) => existsSync(join(at, "pnpm-workspace.yaml")));
9767
- if (root === void 0) return {
9768
- folder: ".",
9769
- file: "package.json"
9770
- };
9771
- const manifest = join(root, "package.json");
9772
- const field = existsSync(manifest) && Object.hasOwn(JSON.parse(readFileSync(manifest, "utf8")), "pnpm");
9773
- return {
9774
- folder: relative(folder, root).split(sep).join("/") || ".",
9775
- file: field ? "package.json" : "pnpm-workspace.yaml"
9776
- };
9777
- };
9778
- /** The project in `folder`, if it is one. */
9779
- const projectIn = (folder) => {
9780
- const path = join(folder, "package.json");
9781
- if (!existsSync(path)) return none();
9782
- const manifest = readManifest(path);
9783
- return some({
9784
- name: manifest.name ?? "this project",
9785
- versions: {
9786
- ...manifest.peerDependencies,
9787
- ...manifest.devDependencies,
9788
- ...manifest.dependencies
9789
- },
9790
- gitattributes: projectFolders(folder).some((at) => existsSync(join(at, ".gitattributes"))),
9791
- pnpmSettings: pnpmSettingsIn(folder)
9792
- });
9793
- };
9794
- /**
9795
- * The project's package manager by its lockfile, here or in a project folder
9796
- * above (a workspace keeps one at its root), else the one running this.
9797
- */
9798
- const managerIn = (folder) => {
9799
- const locks = [
9800
- ["pnpm-lock.yaml", "pnpm"],
9801
- ["bun.lock", "bun"],
9802
- ["bun.lockb", "bun"],
9803
- ["yarn.lock", "yarn"],
9804
- ["package-lock.json", "npm"]
9805
- ];
9806
- for (const at of projectFolders(folder)) {
9807
- const locked = locks.find(([file]) => existsSync(join(at, file)));
9808
- if (locked !== void 0) return locked[1];
9809
- }
9810
- const agent = process.env["npm_config_user_agent"] ?? "";
9811
- return locks.map(([, manager]) => manager).find((manager) => agent.startsWith(`${manager}/`)) ?? "npm";
9812
- };
9813
- /** A failure the reader can act on, printed as its message alone. */
9814
- var Refusal = class extends Error {};
9815
- /** The Foldkit Plus packages a manifest names: its own `foldkit-*` dependencies and peers. */
9816
- const familyOf = (manifest) => Object.keys({
9817
- ...manifest.dependencies,
9818
- ...manifest.peerDependencies
9819
- }).filter((name) => name.startsWith("foldkit-"));
9820
- /**
9821
- * Where an `import` from `base` finds `name`: the nearest `node_modules` above
9822
- * it that holds the package, with links resolved, so a package's own
9823
- * dependencies are found beside it in pnpm's store. ESM reads neither
9824
- * `NODE_PATH` nor the global folders, which `require.resolve.paths` adds.
9825
- */
9826
- const installedFrom = (base, name) => {
9827
- for (let at = base;; at = dirname(at)) {
9828
- const candidate = join(at, "node_modules", name);
9829
- if (existsSync(join(candidate, "package.json"))) return some(realpathSync(candidate));
9830
- if (dirname(at) === at) return none();
9831
- }
9832
- };
9833
- /** The `foldkit-plus` skill nearest the project: in a dot-folder's `skills/` here, above, or at home. */
9834
- const skillIn = (folder) => {
9835
- for (const at of [...projectFolders(folder), homedir()]) {
9836
- const skill = (existsSync(at) ? readdirSync(at, { withFileTypes: true }).filter((entry) => entry.isDirectory() && entry.name.startsWith(".")) : []).map((entry) => join(at, entry.name, "skills", "foldkit-plus")).find((dir) => existsSync(join(dir, "SKILL.md")));
9837
- if (skill !== void 0) return some(skill);
9838
- }
9839
- return none();
9840
- };
9841
- const declarationFiles = (dir) => existsSync(dir) ? readdirSync(dir, { withFileTypes: true }).flatMap((entry) => entry.isDirectory() ? declarationFiles(join(dir, entry.name)) : /\.d\.m?ts$/.test(entry.name) ? [join(dir, entry.name)] : []) : [];
9842
- const topicOf = (name) => name.replace(/^foldkit-/, "");
9843
- /**
9844
- * The documents of what is installed in `folder`: the README of each Foldkit
9845
- * Plus package Node would load there, and the skill's files if it is
9846
- * installed. `family` is the packages this CLI knows of; an installed
9847
- * `foldkit-plus` adds those it knows. Refuses a folder with no project, a
9848
- * package the project names but has not installed, and a project with none.
9849
- */
9850
- const libraryIn = (folder, family) => {
9851
- const project = projectIn(folder);
9852
- if (isNone(project)) throw new Refusal(`There is no package.json in ${folder}: run this in the application's folder.`);
9853
- const plus = installedFrom(folder, "foldkit-plus");
9854
- const names = /* @__PURE__ */ new Set([
9855
- "foldkit-plus",
9856
- ...family,
9857
- ...match$2(plus, {
9858
- onNone: () => [],
9859
- onSome: (dir) => familyOf(readManifest(join(dir, "package.json")))
9860
- })
9861
- ]);
9862
- const installed = [];
9863
- for (const name of [...names].sort()) {
9864
- const named = project.value.versions[name] !== void 0;
9865
- const fromProject = () => installedFrom(folder, name);
9866
- const dir = named ? fromProject() : orElse(flatMap$3(plus, (at) => installedFrom(at, name)), fromProject);
9867
- match$2(dir, {
9868
- onNone: () => {
9869
- if (named) throw new Refusal(`package.json names ${name}, but it is not installed in ${folder}: run the install first.`);
9870
- },
9871
- onSome: (at) => {
9872
- const version = readManifest(join(at, "package.json")).version ?? "unversioned";
9873
- installed.push({
9874
- name,
9875
- version,
9876
- dir: at
9877
- });
9878
- }
9879
- });
9880
- }
9881
- if (installed.length === 0) throw new Refusal(`No Foldkit Plus package is installed in ${folder}. \`npx foldkit-plus setup\` says how to install one.`);
9882
- const skill = match$2(skillIn(folder), {
9883
- onNone: () => [],
9884
- onSome: (dir) => {
9885
- const front = readFileSync(join(dir, "SKILL.md"), "utf8");
9886
- const version = /^\s+version:\s*['"]?([^'"\s]+)/m.exec(front)?.[1] ?? "unversioned";
9887
- const references = join(dir, "references");
9888
- return [join(dir, "SKILL.md"), ...existsSync(references) ? readdirSync(references).filter((file) => file.endsWith(".md")).sort().map((file) => join(references, file)) : []].map((path) => ({
9889
- topic: path.endsWith("SKILL.md") ? "skill" : relative(references, path).slice(0, -3),
9890
- label: `foldkit-plus skill ${version} ${relative(dir, path).split(sep).join("/")}`,
9891
- path,
9892
- text: readFileSync(path, "utf8")
9893
- }));
9894
- }
9895
- });
9896
- const readmes = installed.flatMap((each) => {
9897
- const path = join(each.dir, "README.md");
9898
- return existsSync(path) ? [{
9899
- topic: topicOf(each.name),
9900
- label: `${each.name}@${each.version} README.md`,
9901
- path,
9902
- text: readFileSync(path, "utf8")
9903
- }] : [];
9904
- });
9905
- return {
9906
- docs: [...skill, ...readmes],
9907
- declarations: (symbol) => {
9908
- const seen = /* @__PURE__ */ new Set();
9909
- return installed.filter((each) => each.name !== "foldkit-plus").flatMap((each) => declarationFiles(join(each.dir, "dist")).flatMap((path) => declarationsIn({
9910
- topic: topicOf(each.name),
9911
- origin: `${each.name}@${each.version}`,
9912
- path,
9913
- text: readFileSync(path, "utf8")
9914
- }, symbol))).filter((found) => {
9915
- const key = [...found.comment, ...found.signature].join("\n");
9916
- if (seen.has(key)) return false;
9917
- seen.add(key);
9918
- return true;
9919
- });
9920
- }
9921
- };
9922
- };
9923
- // src/setup.ts
9924
- /**
9925
- * What `npx foldkit-plus setup` prints: instructions a coding agent can follow
9926
- * in order, for the project it is run in. Pure: the CLI reads the project and
9927
- * this package's manifest and passes them in, so a test can give any project.
10235
+ * What `npx foldkit-plus setup` prints: instructions a coding agent can follow
10236
+ * in order, for the project it is run in. Pure: the CLI reads the project and
10237
+ * this package's manifest and passes them in, so a test can give any project.
9928
10238
  */
9929
10239
  const SITE = "https://foldkit-plus.pages.dev";
9930
10240
  const REPOSITORY = "https://github.com/doeixd/foldkit-plus";
@@ -10138,6 +10448,21 @@ const effectPackages = [
10138
10448
  "@effect/platform-node-shared",
10139
10449
  "@effect/sql-sqlite-node"
10140
10450
  ];
10451
+ const releaseOf = (version) => /^(\d+)\.(\d+)\.(\d+)$/.exec(version)?.slice(1).map(Number) ?? [];
10452
+ /**
10453
+ * The Effect release setup pins: the one this release is tested on, or a later
10454
+ * patch of the same minor that the project's lockfile already holds. npm keeps
10455
+ * a locked package that an override contradicts rather than move it down, so
10456
+ * pinning 4.1.0 left the 4.1.1 that `@foldkit/vite-plugin`'s `~4.1.0` had
10457
+ * locked under it, which `npm ls` calls invalid.
10458
+ */
10459
+ const effectRelease = (tested, locked) => {
10460
+ const [major, minor] = releaseOf(tested);
10461
+ return locked.reduce((newest, version) => {
10462
+ const [lockedMajor, lockedMinor, patch = -1] = releaseOf(version);
10463
+ return lockedMajor === major && lockedMinor === minor && patch > (releaseOf(newest)[2] ?? -1) ? version : newest;
10464
+ }, tested);
10465
+ };
10141
10466
  /** A YAML key, quoted where `@` would start something else. */
10142
10467
  const yamlKey = (key) => key.startsWith("@") ? `'${key}'` : key;
10143
10468
  /**
@@ -10222,7 +10547,11 @@ const setupGuide = ({ project, manager, versions }) => {
10222
10547
  "@effect/platform-browser",
10223
10548
  ...listed
10224
10549
  ]);
10225
- const pins = pinsOf(manager, versions.effect, moved, match$2(project, {
10550
+ const effect = effectRelease(versions.effect, match$2(project, {
10551
+ onNone: () => [],
10552
+ onSome: (found) => found.locked
10553
+ }));
10554
+ const pins = pinsOf(manager, effect, moved, match$2(project, {
10226
10555
  onNone: () => ({
10227
10556
  folder: ".",
10228
10557
  file: "package.json"
@@ -10231,7 +10560,7 @@ const setupGuide = ({ project, manager, versions }) => {
10231
10560
  }));
10232
10561
  const uiPeer = exists(project, (found) => found.versions["@foldkit/devtools"] !== void 0 && found.versions["@foldkit/ui"] === void 0);
10233
10562
  const install = addCommand(manager, [
10234
- ...manager === "npm" ? [] : effectPackages.filter((name) => moved.has(name)).map((name) => `${name}@${versions.effect}`),
10563
+ ...manager === "npm" ? [] : effectPackages.filter((name) => moved.has(name)).map((name) => `${name}@${effect}`),
10235
10564
  `foldkit@${versions.foldkit}`,
10236
10565
  ...uiPeer ? [`@foldkit/ui@${versions.foldkit}`] : [],
10237
10566
  "foldkit-plus"
@@ -10255,7 +10584,7 @@ const setupGuide = ({ project, manager, versions }) => {
10255
10584
  onSome: (found) => [
10256
10585
  `This is \`${found.name}\`, installed with ${manager}.`,
10257
10586
  "",
10258
- finding(found, "effect", versions.effect),
10587
+ finding(found, "effect", effect),
10259
10588
  finding(found, "foldkit", versions.foldkit),
10260
10589
  ...uiPeer ? [`- \`@foldkit/devtools\` peers on \`@foldkit/ui\`, which the project does not name: step 2 adds \`@foldkit/ui@${versions.foldkit}\`, since a manager left to choose takes the newest, which may need a newer Effect.`] : [],
10261
10590
  ...found.gitattributes ? ["- `.gitattributes` is there: leave it as it is."] : [
@@ -10285,7 +10614,7 @@ const setupGuide = ({ project, manager, versions }) => {
10285
10614
  "",
10286
10615
  "## 2. Install",
10287
10616
  "",
10288
- `Foldkit and its tooling name one Effect release exactly, and Foldkit Plus is tested on ${versions.effect}. To install one copy of each Effect package, at that release, first merge this into \`${pins.file}\`, keeping what it holds (${pinsWhy[manager]}${pins.file === "package.json" ? "" : "; pnpm reads them only at the workspace root"}):`,
10617
+ `Foldkit and its tooling take one Effect minor, and Foldkit Plus is tested on ${versions.effect}.${effect === versions.effect ? "" : ` The lockfile already holds ${effect}, a later patch of that minor, and npm keeps a locked package rather than move it down to an override, so the pins name ${effect}.`} To install one copy of each Effect package, at that release, first merge this into \`${pins.file}\`, keeping what it holds (${pinsWhy[manager]}${pins.file === "package.json" ? "" : "; pnpm reads them only at the workspace root"}):`,
10289
10618
  "",
10290
10619
  `\`\`\`${pins.language}`,
10291
10620
  pins.text,
@@ -10347,6 +10676,218 @@ const setupGuide = ({ project, manager, versions }) => {
10347
10676
  ""
10348
10677
  ].join("\n");
10349
10678
  };
10679
+ // src/project.ts
10680
+ /**
10681
+ * What the CLI reads from the disk: the project in a folder, its package
10682
+ * manager, and this package's own manifest.
10683
+ */
10684
+ const Versions = Record(String$1, String$1);
10685
+ const Manifest = Struct({
10686
+ name: optional(String$1),
10687
+ version: optional(String$1),
10688
+ dependencies: optional(Versions),
10689
+ devDependencies: optional(Versions),
10690
+ peerDependencies: optional(Versions),
10691
+ setup: optional(Struct({
10692
+ effect: String$1,
10693
+ foldkit: String$1
10694
+ }))
10695
+ });
10696
+ const readManifest = (path) => decodeUnknownSync(Manifest)(JSON.parse(readFileSync(path, "utf8")));
10697
+ /**
10698
+ * A project's folder and those above it, up to its repository's root and no
10699
+ * further, and never into the home folder: a file left there says nothing
10700
+ * about this project. A folder that is no project has none.
10701
+ */
10702
+ const projectFolders = (folder) => {
10703
+ const folders = [];
10704
+ const project = existsSync(join(folder, "package.json"));
10705
+ for (let at = folder; project && at !== homedir(); at = dirname(at)) {
10706
+ folders.push(at);
10707
+ if (existsSync(join(at, ".git")) || dirname(at) === at) break;
10708
+ }
10709
+ return folders;
10710
+ };
10711
+ /**
10712
+ * Where pnpm reads `folder`'s `overrides` and `peerDependencyRules`: the
10713
+ * workspace root, the nearest folder at or above it with a
10714
+ * `pnpm-workspace.yaml`, since pnpm ignores them in a member's `package.json`.
10715
+ * There, the root `package.json`'s `pnpm` field if it already has one, else
10716
+ * the YAML; with no workspace, the project's own `package.json`.
10717
+ */
10718
+ const pnpmSettingsIn = (folder) => {
10719
+ const root = projectFolders(folder).find((at) => existsSync(join(at, "pnpm-workspace.yaml")));
10720
+ if (root === void 0) return {
10721
+ folder: ".",
10722
+ file: "package.json"
10723
+ };
10724
+ const manifest = join(root, "package.json");
10725
+ const field = existsSync(manifest) && Object.hasOwn(JSON.parse(readFileSync(manifest, "utf8")), "pnpm");
10726
+ return {
10727
+ folder: relative(folder, root).split(sep).join("/") || ".",
10728
+ file: field ? "package.json" : "pnpm-workspace.yaml"
10729
+ };
10730
+ };
10731
+ const NpmLock = Struct({ packages: Record(String$1, Struct({ version: optional(String$1) })) });
10732
+ /**
10733
+ * The versions of Effect's packages in the nearest npm lockfile, keyed by
10734
+ * install path (`node_modules/@foldkit/vite-plugin/node_modules/effect`). One
10735
+ * npm cannot read holds none.
10736
+ */
10737
+ const lockedEffect = (folder) => {
10738
+ const lock = projectFolders(folder).map((at) => join(at, "package-lock.json")).find(existsSync);
10739
+ if (lock === void 0) return [];
10740
+ return match$2(decodeUnknownOption(fromJsonString(NpmLock))(readFileSync(lock, "utf8")), {
10741
+ onNone: () => [],
10742
+ onSome: ({ packages }) => Object.entries(packages).flatMap(([path, entry]) => entry.version !== void 0 && effectPackages.some((name) => path.endsWith(`node_modules/${name}`)) ? [entry.version] : [])
10743
+ });
10744
+ };
10745
+ /** The project in `folder`, if it is one. */
10746
+ const projectIn = (folder) => {
10747
+ const path = join(folder, "package.json");
10748
+ if (!existsSync(path)) return none();
10749
+ const manifest = readManifest(path);
10750
+ return some({
10751
+ name: manifest.name ?? "this project",
10752
+ versions: {
10753
+ ...manifest.peerDependencies,
10754
+ ...manifest.devDependencies,
10755
+ ...manifest.dependencies
10756
+ },
10757
+ gitattributes: projectFolders(folder).some((at) => existsSync(join(at, ".gitattributes"))),
10758
+ pnpmSettings: pnpmSettingsIn(folder),
10759
+ locked: lockedEffect(folder)
10760
+ });
10761
+ };
10762
+ /**
10763
+ * The project's package manager by its lockfile, here or in a project folder
10764
+ * above (a workspace keeps one at its root), else the one running this.
10765
+ */
10766
+ const managerIn = (folder) => {
10767
+ const locks = [
10768
+ ["pnpm-lock.yaml", "pnpm"],
10769
+ ["bun.lock", "bun"],
10770
+ ["bun.lockb", "bun"],
10771
+ ["yarn.lock", "yarn"],
10772
+ ["package-lock.json", "npm"]
10773
+ ];
10774
+ for (const at of projectFolders(folder)) {
10775
+ const locked = locks.find(([file]) => existsSync(join(at, file)));
10776
+ if (locked !== void 0) return locked[1];
10777
+ }
10778
+ const agent = process.env["npm_config_user_agent"] ?? "";
10779
+ return locks.map(([, manager]) => manager).find((manager) => agent.startsWith(`${manager}/`)) ?? "npm";
10780
+ };
10781
+ /** A failure the reader can act on, printed as its message alone. */
10782
+ var Refusal = class extends Error {};
10783
+ /** The Foldkit Plus packages a manifest names: its own `foldkit-*` dependencies and peers. */
10784
+ const familyOf = (manifest) => Object.keys({
10785
+ ...manifest.dependencies,
10786
+ ...manifest.peerDependencies
10787
+ }).filter((name) => name.startsWith("foldkit-"));
10788
+ /**
10789
+ * Where an `import` from `base` finds `name`: the nearest `node_modules` above
10790
+ * it that holds the package, with links resolved, so a package's own
10791
+ * dependencies are found beside it in pnpm's store. ESM reads neither
10792
+ * `NODE_PATH` nor the global folders, which `require.resolve.paths` adds.
10793
+ */
10794
+ const installedFrom = (base, name) => {
10795
+ for (let at = base;; at = dirname(at)) {
10796
+ const candidate = join(at, "node_modules", name);
10797
+ if (existsSync(join(candidate, "package.json"))) return some(realpathSync(candidate));
10798
+ if (dirname(at) === at) return none();
10799
+ }
10800
+ };
10801
+ /** The `foldkit-plus` skill nearest the project: in a dot-folder's `skills/` here, above, or at home. */
10802
+ const skillIn = (folder) => {
10803
+ for (const at of [...projectFolders(folder), homedir()]) {
10804
+ const skill = (existsSync(at) ? readdirSync(at, { withFileTypes: true }).filter((entry) => entry.isDirectory() && entry.name.startsWith(".")) : []).map((entry) => join(at, entry.name, "skills", "foldkit-plus")).find((dir) => existsSync(join(dir, "SKILL.md")));
10805
+ if (skill !== void 0) return some(skill);
10806
+ }
10807
+ return none();
10808
+ };
10809
+ const declarationFiles = (dir) => existsSync(dir) ? readdirSync(dir, { withFileTypes: true }).flatMap((entry) => entry.isDirectory() ? declarationFiles(join(dir, entry.name)) : /\.d\.m?ts$/.test(entry.name) ? [join(dir, entry.name)] : []) : [];
10810
+ const topicOf = (name) => name.replace(/^foldkit-/, "");
10811
+ /**
10812
+ * The documents of what is installed in `folder`: the README of each Foldkit
10813
+ * Plus package Node would load there, and the skill's files if it is
10814
+ * installed. `family` is the packages this CLI knows of; an installed
10815
+ * `foldkit-plus` adds those it knows. Refuses a folder with no project, a
10816
+ * package the project names but has not installed, and a project with none.
10817
+ */
10818
+ const libraryIn = (folder, family) => {
10819
+ const project = projectIn(folder);
10820
+ if (isNone(project)) throw new Refusal(`There is no package.json in ${folder}: run this in the application's folder.`);
10821
+ const plus = installedFrom(folder, "foldkit-plus");
10822
+ const names = /* @__PURE__ */ new Set([
10823
+ "foldkit-plus",
10824
+ ...family,
10825
+ ...match$2(plus, {
10826
+ onNone: () => [],
10827
+ onSome: (dir) => familyOf(readManifest(join(dir, "package.json")))
10828
+ })
10829
+ ]);
10830
+ const installed = [];
10831
+ for (const name of [...names].sort()) {
10832
+ const named = project.value.versions[name] !== void 0;
10833
+ const fromProject = () => installedFrom(folder, name);
10834
+ const dir = named ? fromProject() : orElse(flatMap$3(plus, (at) => installedFrom(at, name)), fromProject);
10835
+ match$2(dir, {
10836
+ onNone: () => {
10837
+ if (named) throw new Refusal(`package.json names ${name}, but it is not installed in ${folder}: run the install first.`);
10838
+ },
10839
+ onSome: (at) => {
10840
+ const version = readManifest(join(at, "package.json")).version ?? "unversioned";
10841
+ installed.push({
10842
+ name,
10843
+ version,
10844
+ dir: at
10845
+ });
10846
+ }
10847
+ });
10848
+ }
10849
+ if (installed.length === 0) throw new Refusal(`No Foldkit Plus package is installed in ${folder}. \`npx foldkit-plus setup\` says how to install one.`);
10850
+ const skill = match$2(skillIn(folder), {
10851
+ onNone: () => [],
10852
+ onSome: (dir) => {
10853
+ const front = readFileSync(join(dir, "SKILL.md"), "utf8");
10854
+ const version = /^\s+version:\s*['"]?([^'"\s]+)/m.exec(front)?.[1] ?? "unversioned";
10855
+ const references = join(dir, "references");
10856
+ return [join(dir, "SKILL.md"), ...existsSync(references) ? readdirSync(references).filter((file) => file.endsWith(".md")).sort().map((file) => join(references, file)) : []].map((path) => ({
10857
+ topic: path.endsWith("SKILL.md") ? "skill" : relative(references, path).slice(0, -3),
10858
+ label: `foldkit-plus skill ${version} ${relative(dir, path).split(sep).join("/")}`,
10859
+ path,
10860
+ text: readFileSync(path, "utf8")
10861
+ }));
10862
+ }
10863
+ });
10864
+ const readmes = installed.flatMap((each) => {
10865
+ const path = join(each.dir, "README.md");
10866
+ return existsSync(path) ? [{
10867
+ topic: topicOf(each.name),
10868
+ label: `${each.name}@${each.version} README.md`,
10869
+ path,
10870
+ text: readFileSync(path, "utf8")
10871
+ }] : [];
10872
+ });
10873
+ return {
10874
+ docs: [...skill, ...readmes],
10875
+ declarations: (symbol) => {
10876
+ const seen = /* @__PURE__ */ new Set();
10877
+ return installed.filter((each) => each.name !== "foldkit-plus").flatMap((each) => declarationFiles(join(each.dir, "dist")).flatMap((path) => declarationsIn({
10878
+ topic: topicOf(each.name),
10879
+ origin: `${each.name}@${each.version}`,
10880
+ path,
10881
+ text: readFileSync(path, "utf8")
10882
+ }, symbol))).filter((found) => {
10883
+ const key = [...found.comment, ...found.signature].join("\n");
10884
+ if (seen.has(key)) return false;
10885
+ seen.add(key);
10886
+ return true;
10887
+ });
10888
+ }
10889
+ };
10890
+ };
10350
10891
  // src/cli.ts
10351
10892
  /**
10352
10893
  * `npx foldkit-plus`: `setup` prints `setup.ts`'s instructions for the project