t3code-cli 0.7.0 → 0.9.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.
Files changed (82) hide show
  1. package/README.md +90 -35
  2. package/dist/application.js +1 -1
  3. package/dist/auth.js +1 -2
  4. package/dist/bin.js +241 -45
  5. package/dist/cli.js +1 -1
  6. package/dist/config.js +1 -3
  7. package/dist/connection.js +1 -4
  8. package/dist/index.js +1 -4
  9. package/dist/layout.js +1 -1
  10. package/dist/orchestration.js +1 -1
  11. package/dist/rpc.js +1 -1
  12. package/dist/runtime.js +1 -2
  13. package/dist/scope.js +1 -1
  14. package/dist/shared.js +85492 -0
  15. package/dist/src/application/layer.d.ts +86 -2
  16. package/dist/src/application/models.d.ts +1 -0
  17. package/dist/src/application/projects.d.ts +10 -1
  18. package/dist/src/application/service.d.ts +30 -1
  19. package/dist/src/application/shell-sequence.d.ts +9 -0
  20. package/dist/src/application/thread-commands.d.ts +27 -1
  21. package/dist/src/application/thread-wait.d.ts +9 -0
  22. package/dist/src/application/threads.d.ts +102 -2
  23. package/dist/src/cli-path/layer.d.ts +3 -0
  24. package/dist/src/cli-path/service.d.ts +8 -0
  25. package/dist/src/domain/helpers.d.ts +9 -0
  26. package/dist/src/domain/model-config.d.ts +3 -0
  27. package/dist/src/domain/thread-activities.d.ts +14 -0
  28. package/dist/src/domain/thread-lifecycle.d.ts +10 -0
  29. package/dist/src/orchestration/layer.d.ts +215 -0
  30. package/dist/src/rpc/layer.d.ts +466 -0
  31. package/dist/src/rpc/ws-group.d.ts +142 -0
  32. package/dist/src/runtime/layer.d.ts +1 -1
  33. package/dist/t3tools.js +2 -2
  34. package/dist/upstream-t3code/packages/contracts/src/environmentHttp.d.ts +33 -10
  35. package/dist/upstream-t3code/packages/contracts/src/ipc.d.ts +6 -0
  36. package/dist/upstream-t3code/packages/contracts/src/orchestration.d.ts +657 -1
  37. package/dist/upstream-t3code/packages/contracts/src/provider.d.ts +14 -0
  38. package/dist/upstream-t3code/packages/contracts/src/providerRuntime.d.ts +175 -1
  39. package/dist/upstream-t3code/packages/contracts/src/rpc.d.ts +492 -0
  40. package/dist/upstream-t3code/packages/contracts/src/server.d.ts +45 -0
  41. package/dist/upstream-t3code/packages/contracts/src/settings.d.ts +21 -0
  42. package/dist/upstream-t3code/packages/contracts/src/terminal.d.ts +6 -3
  43. package/package.json +2 -2
  44. package/src/application/service.ts +32 -0
  45. package/src/application/thread-commands.ts +45 -0
  46. package/src/application/threads.ts +100 -1
  47. package/src/cli/error.ts +15 -0
  48. package/src/cli/message-input.ts +30 -0
  49. package/src/cli/thread-format.ts +47 -0
  50. package/src/cli/thread.ts +8 -0
  51. package/src/cli/threads/approve.ts +61 -0
  52. package/src/cli/threads/archive.ts +18 -3
  53. package/src/cli/threads/callback.ts +92 -0
  54. package/src/cli/threads/respond.ts +70 -0
  55. package/src/cli/threads/show.ts +43 -0
  56. package/src/cli-path/layer.ts +10 -0
  57. package/src/cli-path/service.ts +7 -0
  58. package/src/domain/thread-activities.test.ts +321 -0
  59. package/src/domain/thread-activities.ts +244 -0
  60. package/src/domain/thread-lifecycle.ts +2 -0
  61. package/src/runtime/layer.ts +2 -0
  62. package/dist/Context-DueQ9iMH.js +0 -4916
  63. package/dist/Path-D8WPdPwR.js +0 -11406
  64. package/dist/Schema-DsQxYh6_.js +0 -13581
  65. package/dist/UrlParams-BA6gBvaY.js +0 -205
  66. package/dist/base-dir-R12OMDso.js +0 -20
  67. package/dist/error-B2t1bAP9.js +0 -169
  68. package/dist/error-BHRnjLux.js +0 -15
  69. package/dist/error-jwMt3VoW.js +0 -54
  70. package/dist/flags-CM7_iGdA.js +0 -13371
  71. package/dist/layer-CfC5qZol.js +0 -1508
  72. package/dist/layer-DHhKS5jd.js +0 -13
  73. package/dist/layer-DUv99vsS.js +0 -72
  74. package/dist/layer-DvHnKBYj.js +0 -29466
  75. package/dist/layer-MqCKkIGD.js +0 -1206
  76. package/dist/scope-GycYiJ54.js +0 -29
  77. package/dist/service-CLmRO2Dp.js +0 -8
  78. package/dist/service-ybOWV9pL.js +0 -5
  79. package/dist/src-KdbHqrex.js +0 -8874
  80. package/dist/transport-D3zBdZ1h.js +0 -539
  81. package/dist/url-SlsaG8nY.js +0 -165
  82. /package/dist/{chunk-B5meny8j.js → rolldown-runtime.js} +0 -0
@@ -1,4916 +0,0 @@
1
- //#region node_modules/.pnpm/effect@4.0.0-beta.78/node_modules/effect/dist/Pipeable.js
2
- /**
3
- * The `Pipeable` module defines the shared interface and implementation helpers
4
- * for values that support Effect-style method chaining with `.pipe(...)`.
5
- *
6
- * A `Pipeable` value can pass itself through a sequence of unary functions from
7
- * left to right, so code can be written as `value.pipe(f, g, h)` instead of
8
- * deeply nesting calls. This is the method form used by many Effect data types
9
- * to compose transformations, validations, and effectful operations while
10
- * keeping the original value as the starting point of the pipeline.
11
- *
12
- * **Common tasks**
13
- *
14
- * - Type values that expose a `.pipe(...)` method with the {@link Pipeable} interface
15
- * - Implement a custom `.pipe(...)` method with {@link pipeArguments}
16
- * - Reuse the standard implementation through {@link Prototype}, {@link Class}, or {@link Mixin}
17
- *
18
- * **Gotchas**
19
- *
20
- * - Each function receives the result of the previous function, not the original value
21
- * - The overloads preserve precise types for long pipelines, but very long chains may be easier to read when split
22
- *
23
- * @since 2.0.0
24
- */
25
- /**
26
- * Applies a `pipe` method's variadic arguments to an initial value from left
27
- * to right.
28
- *
29
- * **When to use**
30
- *
31
- * Use to implement a custom `.pipe(...)` method from JavaScript's `arguments`
32
- * object.
33
- *
34
- * **Details**
35
- *
36
- * This helper is intended for implementing `Pipeable.pipe` methods that
37
- * receive JavaScript's `arguments` object. With no functions it returns the
38
- * original value; otherwise it feeds each result into the next function.
39
- *
40
- * **Example** (Implementing a pipe method)
41
- *
42
- * ```ts
43
- * import { Pipeable } from "effect"
44
- *
45
- * class NumberBox {
46
- * constructor(readonly value: number) {}
47
- *
48
- * pipe(..._fns: ReadonlyArray<(value: number) => number>): number {
49
- * return Pipeable.pipeArguments(this.value, arguments) as number
50
- * }
51
- * }
52
- *
53
- * const result = new NumberBox(5).pipe(
54
- * (n) => n + 2,
55
- * (n) => n * 3
56
- * )
57
- * console.log(result) // 21
58
- * ```
59
- *
60
- * @category combinators
61
- * @since 2.0.0
62
- */
63
- const pipeArguments = (self, args) => {
64
- switch (args.length) {
65
- case 0: return self;
66
- case 1: return args[0](self);
67
- case 2: return args[1](args[0](self));
68
- case 3: return args[2](args[1](args[0](self)));
69
- case 4: return args[3](args[2](args[1](args[0](self))));
70
- case 5: return args[4](args[3](args[2](args[1](args[0](self)))));
71
- case 6: return args[5](args[4](args[3](args[2](args[1](args[0](self))))));
72
- case 7: return args[6](args[5](args[4](args[3](args[2](args[1](args[0](self)))))));
73
- case 8: return args[7](args[6](args[5](args[4](args[3](args[2](args[1](args[0](self))))))));
74
- case 9: return args[8](args[7](args[6](args[5](args[4](args[3](args[2](args[1](args[0](self)))))))));
75
- default: {
76
- let ret = self;
77
- for (let i = 0, len = args.length; i < len; i++) ret = args[i](ret);
78
- return ret;
79
- }
80
- }
81
- };
82
- /**
83
- * Reusable prototype that implements `Pipeable.pipe`.
84
- *
85
- * **When to use**
86
- *
87
- * Use when classes or object prototypes can reuse this value when they need the
88
- * standard pipe implementation backed by `pipeArguments`.
89
- *
90
- * @category prototypes
91
- * @since 3.15.0
92
- */
93
- const Prototype$1 = { pipe() {
94
- return pipeArguments(this, arguments);
95
- } };
96
- /**
97
- * Provides a base constructor whose instances implement the standard `Pipeable.pipe`
98
- * method.
99
- *
100
- * **When to use**
101
- *
102
- * Use when you need to define a class that supports Effect-style method
103
- * chaining through `.pipe(...)`.
104
- *
105
- * @category constructors
106
- * @since 3.15.0
107
- */
108
- const Class$1 = /*#__PURE__*/ function() {
109
- function PipeableBase() {}
110
- PipeableBase.prototype = Prototype$1;
111
- return PipeableBase;
112
- }();
113
- //#endregion
114
- //#region node_modules/.pnpm/effect@4.0.0-beta.78/node_modules/effect/dist/Function.js
115
- /**
116
- * Creates a function that can be called in data-first style or data-last
117
- * (`pipe`-friendly) style.
118
- *
119
- * **When to use**
120
- *
121
- * Use to expose one implementation through both direct and `pipe`-friendly
122
- * call styles.
123
- *
124
- * **Details**
125
- *
126
- * Pass either the arity of the uncurried function or a predicate that decides
127
- * whether the current call is data-first. Arity is the common case. Use a
128
- * predicate when optional arguments make arity ambiguous.
129
- *
130
- * **Example** (Using arity to determine data-first or data-last style)
131
- *
132
- * ```ts
133
- * import { Function, pipe } from "effect"
134
- *
135
- * const sum = Function.dual<
136
- * (that: number) => (self: number) => number,
137
- * (self: number, that: number) => number
138
- * >(2, (self, that) => self + that)
139
- *
140
- * console.log(sum(2, 3)) // 5
141
- * console.log(pipe(2, sum(3))) // 5
142
- * ```
143
- *
144
- * **Example** (Using call signatures to define the overloads)
145
- *
146
- * ```ts
147
- * import { Function, pipe } from "effect"
148
- *
149
- * const sum: {
150
- * (that: number): (self: number) => number
151
- * (self: number, that: number): number
152
- * } = Function.dual(2, (self: number, that: number): number => self + that)
153
- *
154
- * console.log(sum(2, 3)) // 5
155
- * console.log(pipe(2, sum(3))) // 5
156
- * ```
157
- *
158
- * **Example** (Using a predicate to determine data-first or data-last style)
159
- *
160
- * ```ts
161
- * import { Function, pipe } from "effect"
162
- *
163
- * const sum = Function.dual<
164
- * (that: number) => (self: number) => number,
165
- * (self: number, that: number) => number
166
- * >(
167
- * (args) => args.length === 2,
168
- * (self, that) => self + that
169
- * )
170
- *
171
- * console.log(sum(2, 3)) // 5
172
- * console.log(pipe(2, sum(3))) // 5
173
- * ```
174
- *
175
- * @category combinators
176
- * @since 2.0.0
177
- */
178
- const dual = function(arity, body) {
179
- if (typeof arity === "function") return function() {
180
- return arity(arguments) ? body.apply(this, arguments) : (self) => body(self, ...arguments);
181
- };
182
- switch (arity) {
183
- case 0:
184
- case 1: throw new RangeError(`Invalid arity ${arity}`);
185
- case 2: return function(a, b) {
186
- if (arguments.length >= 2) return body(a, b);
187
- return function(self) {
188
- return body(self, a);
189
- };
190
- };
191
- case 3: return function(a, b, c) {
192
- if (arguments.length >= 3) return body(a, b, c);
193
- return function(self) {
194
- return body(self, a, b);
195
- };
196
- };
197
- default: return function() {
198
- if (arguments.length >= arity) return body.apply(this, arguments);
199
- const args = arguments;
200
- return function(self) {
201
- return body(self, ...args);
202
- };
203
- };
204
- }
205
- };
206
- /**
207
- * Returns its input argument unchanged.
208
- *
209
- * **When to use**
210
- *
211
- * Use to return a value unchanged where a function is required.
212
- *
213
- * **Example** (Returning the same value)
214
- *
215
- * ```ts
216
- * import { identity } from "effect"
217
- * import * as assert from "node:assert"
218
- *
219
- * assert.deepStrictEqual(identity(5), 5)
220
- * ```
221
- *
222
- * @category combinators
223
- * @since 2.0.0
224
- */
225
- const identity = (a) => a;
226
- /**
227
- * Creates a zero-argument function that always returns the provided value.
228
- *
229
- * **When to use**
230
- *
231
- * Use when you need a thunk or callback that returns the same value on every
232
- * invocation.
233
- *
234
- * **Example** (Creating a constant thunk)
235
- *
236
- * ```ts
237
- * import { Function } from "effect"
238
- * import * as assert from "node:assert"
239
- *
240
- * const constNull = Function.constant(null)
241
- *
242
- * assert.deepStrictEqual(constNull(), null)
243
- * assert.deepStrictEqual(constNull(), null)
244
- * ```
245
- *
246
- * @category constructors
247
- * @since 2.0.0
248
- */
249
- const constant = (value) => () => value;
250
- /**
251
- * Returns `true` when called.
252
- *
253
- * **When to use**
254
- *
255
- * Use when you need a thunk that returns `true` on every invocation.
256
- *
257
- * **Example** (Returning true from a thunk)
258
- *
259
- * ```ts
260
- * import { Function } from "effect"
261
- * import * as assert from "node:assert"
262
- *
263
- * assert.deepStrictEqual(Function.constTrue(), true)
264
- * ```
265
- *
266
- * @category constants
267
- * @since 2.0.0
268
- */
269
- const constTrue = /*#__PURE__*/ constant(true);
270
- /**
271
- * Returns `false` when called.
272
- *
273
- * **When to use**
274
- *
275
- * Use when you need a thunk that returns `false` on every invocation.
276
- *
277
- * **Example** (Returning false from a thunk)
278
- *
279
- * ```ts
280
- * import { Function } from "effect"
281
- * import * as assert from "node:assert"
282
- *
283
- * assert.deepStrictEqual(Function.constFalse(), false)
284
- * ```
285
- *
286
- * @category constants
287
- * @since 2.0.0
288
- */
289
- const constFalse = /*#__PURE__*/ constant(false);
290
- /**
291
- * Returns `undefined` when called.
292
- *
293
- * **When to use**
294
- *
295
- * Use when you need a thunk that returns `undefined` on every invocation.
296
- *
297
- * **Example** (Returning undefined from a thunk)
298
- *
299
- * ```ts
300
- * import { Function } from "effect"
301
- * import * as assert from "node:assert"
302
- *
303
- * assert.deepStrictEqual(Function.constUndefined(), undefined)
304
- * ```
305
- *
306
- * @category constants
307
- * @since 2.0.0
308
- */
309
- const constUndefined = /*#__PURE__*/ constant(void 0);
310
- /**
311
- * Returns no meaningful value when called.
312
- *
313
- * **When to use**
314
- *
315
- * Use when you need a thunk that is called only for its effect and has no
316
- * meaningful return value.
317
- *
318
- * **Example** (Returning void from a thunk)
319
- *
320
- * ```ts
321
- * import { Function } from "effect"
322
- * import * as assert from "node:assert"
323
- *
324
- * assert.deepStrictEqual(Function.constVoid(), undefined)
325
- * ```
326
- *
327
- * @category constants
328
- * @since 2.0.0
329
- */
330
- const constVoid = constUndefined;
331
- function pipe(a, ...args) {
332
- return pipeArguments(a, args);
333
- }
334
- function flow(ab, bc, cd, de, ef, fg, gh, hi, ij) {
335
- switch (arguments.length) {
336
- case 1: return ab;
337
- case 2: return function() {
338
- return bc(ab.apply(this, arguments));
339
- };
340
- case 3: return function() {
341
- return cd(bc(ab.apply(this, arguments)));
342
- };
343
- case 4: return function() {
344
- return de(cd(bc(ab.apply(this, arguments))));
345
- };
346
- case 5: return function() {
347
- return ef(de(cd(bc(ab.apply(this, arguments)))));
348
- };
349
- case 6: return function() {
350
- return fg(ef(de(cd(bc(ab.apply(this, arguments))))));
351
- };
352
- case 7: return function() {
353
- return gh(fg(ef(de(cd(bc(ab.apply(this, arguments)))))));
354
- };
355
- case 8: return function() {
356
- return hi(gh(fg(ef(de(cd(bc(ab.apply(this, arguments))))))));
357
- };
358
- case 9: return function() {
359
- return ij(hi(gh(fg(ef(de(cd(bc(ab.apply(this, arguments)))))))));
360
- };
361
- }
362
- }
363
- /**
364
- * Creates a memoized function whose input is an object, caching results by
365
- * object identity.
366
- *
367
- * **When to use**
368
- *
369
- * Use to reuse the result of a synchronous computation whose output is stable
370
- * for a given object reference.
371
- *
372
- * **Details**
373
- *
374
- * Each memoized wrapper owns a private `WeakMap` keyed by object identity.
375
- * Cached `undefined` results are still returned because the cache is checked
376
- * with `WeakMap.has`.
377
- *
378
- * **Gotchas**
379
- *
380
- * Structurally equal objects do not share cache entries. If the same object is
381
- * mutated after its first call, later calls still return the cached result for
382
- * that reference.
383
- *
384
- * @category caching
385
- * @since 4.0.0
386
- */
387
- function memoize(f) {
388
- const cache = /* @__PURE__ */ new WeakMap();
389
- return (a) => {
390
- if (cache.has(a)) return cache.get(a);
391
- const result = f(a);
392
- cache.set(a, result);
393
- return result;
394
- };
395
- }
396
- //#endregion
397
- //#region node_modules/.pnpm/effect@4.0.0-beta.78/node_modules/effect/dist/internal/equal.js
398
- /** @internal */
399
- const getAllObjectKeys = (obj) => {
400
- const keys = new Set(Reflect.ownKeys(obj));
401
- if (obj.constructor === Object) return keys;
402
- if (obj instanceof Error) keys.delete("stack");
403
- const proto = Object.getPrototypeOf(obj);
404
- let current = proto;
405
- while (current !== null && current !== Object.prototype) {
406
- const ownKeys = Reflect.ownKeys(current);
407
- for (let i = 0; i < ownKeys.length; i++) keys.add(ownKeys[i]);
408
- current = Object.getPrototypeOf(current);
409
- }
410
- if (keys.has("constructor") && typeof obj.constructor === "function" && proto === obj.constructor.prototype) keys.delete("constructor");
411
- return keys;
412
- };
413
- /** @internal */
414
- const byReferenceInstances = /*#__PURE__*/ new WeakSet();
415
- //#endregion
416
- //#region node_modules/.pnpm/effect@4.0.0-beta.78/node_modules/effect/dist/Predicate.js
417
- /**
418
- * Predicates are small boolean functions for checking values at runtime.
419
- * Refinements are predicates that also narrow TypeScript types after a
420
- * successful check. This module provides primitive guards for common JavaScript
421
- * values and combinators for building larger checks from smaller ones.
422
- *
423
- * **Mental model**
424
- *
425
- * - A `Predicate<A>` is `(a: A) => boolean`
426
- * - A `Refinement<A, B>` is `(a: A) => a is B`; when it returns `true`,
427
- * TypeScript can treat the value as `B`
428
- * - Guards such as {@link isString}, {@link isNumber}, and {@link isObject}
429
- * refine `unknown` values into useful runtime types
430
- * - Combinators such as {@link and}, {@link or}, {@link not}, and {@link xor}
431
- * build new predicates while preserving refinement information where possible
432
- * - {@link Tuple} and {@link Struct} lift element and property predicates to
433
- * tuple-like arrays and object shapes
434
- *
435
- * **Common tasks**
436
- *
437
- * - Check primitive runtime types: {@link isString}, {@link isNumber},
438
- * {@link isBoolean}, {@link isBigInt}, {@link isSymbol}
439
- * - Check object-like values: {@link isObject}, {@link isObjectOrArray},
440
- * {@link hasProperty}, {@link isTagged}
441
- * - Combine predicates: {@link and}, {@link or}, {@link not}, {@link xor}
442
- * - Reuse a predicate on derived input: {@link mapInput}
443
- * - Compose refinements that narrow in stages: {@link compose}
444
- * - Validate tuple or object shapes: {@link Tuple}, {@link Struct}
445
- *
446
- * **Gotchas**
447
- *
448
- * - Predicates only return `true` or `false`; they do not explain why a value
449
- * failed a check
450
- * - {@link isTruthy} uses JavaScript truthiness, so `0`, `""`, and `false`
451
- * are rejected
452
- * - {@link isObject} excludes arrays; use {@link isObjectOrArray} when arrays
453
- * should also pass
454
- * - {@link isIterable} accepts strings because strings are iterable in
455
- * JavaScript
456
- * - {@link isPromise} and {@link isPromiseLike} are structural checks, not
457
- * `instanceof` checks
458
- * - {@link isTupleOf} and {@link isTupleOfAtLeast} check length only, not
459
- * element types
460
- *
461
- * **Quickstart**
462
- *
463
- * **Example** (Filter by a predicate)
464
- *
465
- * ```ts
466
- * import { Predicate } from "effect"
467
- *
468
- * const values: Array<unknown> = ["one", 2, "three", null]
469
- * const strings = values.filter(Predicate.isString)
470
- *
471
- * console.log(strings)
472
- * // Output: ["one", "three"]
473
- * ```
474
- *
475
- * **See also**
476
- *
477
- * - {@link Predicate} for plain boolean checks
478
- * - {@link Refinement} for checks that narrow types
479
- * - {@link Struct} and {@link Tuple} for checking compound values
480
- *
481
- * @since 2.0.0
482
- */
483
- /**
484
- * Checks whether a value is a `string`.
485
- *
486
- * **When to use**
487
- *
488
- * Use when you need a `Predicate` guard to narrow an `unknown` value to a
489
- * string.
490
- *
491
- * **Details**
492
- *
493
- * Uses `typeof input === "string"`.
494
- *
495
- * **Example** (Guard string)
496
- *
497
- * ```ts
498
- * import { Predicate } from "effect"
499
- *
500
- * const data: unknown = "hi"
501
- *
502
- * if (Predicate.isString(data)) {
503
- * console.log(data.toUpperCase())
504
- * }
505
- * ```
506
- *
507
- * @see {@link isNumber}
508
- * @see {@link isBoolean}
509
- * @see {@link Refinement}
510
- * @category guards
511
- * @since 2.0.0
512
- */
513
- function isString(input) {
514
- return typeof input === "string";
515
- }
516
- /**
517
- * Checks whether a value is a `number`.
518
- *
519
- * **When to use**
520
- *
521
- * Use when you need a `Predicate` guard to narrow an `unknown` value to a
522
- * number.
523
- *
524
- * **Details**
525
- *
526
- * Uses `typeof input === "number"` and does not exclude `NaN` or `Infinity`.
527
- *
528
- * **Example** (Guard number)
529
- *
530
- * ```ts
531
- * import { Predicate } from "effect"
532
- *
533
- * const data: unknown = 42
534
- *
535
- * if (Predicate.isNumber(data)) {
536
- * console.log(data + 1)
537
- * }
538
- * ```
539
- *
540
- * @see {@link isBigInt}
541
- * @see {@link isString}
542
- * @category guards
543
- * @since 2.0.0
544
- */
545
- function isNumber(input) {
546
- return typeof input === "number";
547
- }
548
- /**
549
- * Checks whether a value is a `boolean`.
550
- *
551
- * **When to use**
552
- *
553
- * Use when you need a `Predicate` guard to narrow an `unknown` value to a
554
- * boolean.
555
- *
556
- * **Details**
557
- *
558
- * Uses `typeof input === "boolean"`.
559
- *
560
- * **Example** (Guard boolean)
561
- *
562
- * ```ts
563
- * import { Predicate } from "effect"
564
- *
565
- * const data: unknown = true
566
- *
567
- * if (Predicate.isBoolean(data)) {
568
- * console.log(data ? "yes" : "no")
569
- * }
570
- * ```
571
- *
572
- * @see {@link isString}
573
- * @see {@link isNumber}
574
- * @category guards
575
- * @since 2.0.0
576
- */
577
- function isBoolean(input) {
578
- return typeof input === "boolean";
579
- }
580
- /**
581
- * Checks whether a value is a `bigint`.
582
- *
583
- * **When to use**
584
- *
585
- * Use when you need a `Predicate` guard to narrow an `unknown` value to a
586
- * bigint.
587
- *
588
- * **Details**
589
- *
590
- * Uses `typeof input === "bigint"`.
591
- *
592
- * **Example** (Guard bigint)
593
- *
594
- * ```ts
595
- * import { Predicate } from "effect"
596
- *
597
- * const data: unknown = 1n
598
- *
599
- * if (Predicate.isBigInt(data)) {
600
- * console.log(data + 2n)
601
- * }
602
- * ```
603
- *
604
- * @see {@link isNumber}
605
- * @category guards
606
- * @since 2.0.0
607
- */
608
- function isBigInt(input) {
609
- return typeof input === "bigint";
610
- }
611
- /**
612
- * Checks whether a value is a `symbol`.
613
- *
614
- * **When to use**
615
- *
616
- * Use when you need a `Predicate` guard to narrow an `unknown` value to a
617
- * symbol.
618
- *
619
- * **Details**
620
- *
621
- * Uses `typeof input === "symbol"`.
622
- *
623
- * **Example** (Guard symbol)
624
- *
625
- * ```ts
626
- * import { Predicate } from "effect"
627
- *
628
- * const data: unknown = Symbol.for("id")
629
- *
630
- * if (Predicate.isSymbol(data)) {
631
- * console.log(data.description)
632
- * }
633
- * ```
634
- *
635
- * @see {@link isPropertyKey}
636
- * @category guards
637
- * @since 2.0.0
638
- */
639
- function isSymbol(input) {
640
- return typeof input === "symbol";
641
- }
642
- /**
643
- * Checks whether a value is a valid `PropertyKey` (string, number, or symbol).
644
- *
645
- * **When to use**
646
- *
647
- * Use when you need a `Predicate` guard for unknown property keys before
648
- * indexing.
649
- *
650
- * **Details**
651
- *
652
- * Uses `isString`, `isNumber`, and `isSymbol`.
653
- *
654
- * **Example** (Guard property key)
655
- *
656
- * ```ts
657
- * import { Predicate } from "effect"
658
- *
659
- * const key: unknown = "name"
660
- * const obj: Record<PropertyKey, unknown> = { name: "Ada" }
661
- *
662
- * if (Predicate.isPropertyKey(key) && key in obj) {
663
- * console.log(obj[key])
664
- * }
665
- * ```
666
- *
667
- * @see {@link isString}
668
- * @see {@link isNumber}
669
- * @see {@link isSymbol}
670
- * @category guards
671
- * @since 4.0.0
672
- */
673
- function isPropertyKey(u) {
674
- return isString(u) || isNumber(u) || isSymbol(u);
675
- }
676
- /**
677
- * Checks whether a value is a `function`.
678
- *
679
- * **When to use**
680
- *
681
- * Use when you need a `Predicate` guard to narrow an `unknown` value to a
682
- * callable function.
683
- *
684
- * **Details**
685
- *
686
- * Uses `typeof input === "function"`.
687
- *
688
- * **Example** (Guard function)
689
- *
690
- * ```ts
691
- * import { Predicate } from "effect"
692
- *
693
- * const data: unknown = () => 1
694
- *
695
- * if (Predicate.isFunction(data)) {
696
- * console.log(data())
697
- * }
698
- * ```
699
- *
700
- * @see {@link isObjectKeyword}
701
- * @category guards
702
- * @since 2.0.0
703
- */
704
- function isFunction(input) {
705
- return typeof input === "function";
706
- }
707
- /**
708
- * Checks whether a value is `undefined`.
709
- *
710
- * **When to use**
711
- *
712
- * Use when you need a `Predicate` guard for values that are exactly
713
- * `undefined`.
714
- *
715
- * **Details**
716
- *
717
- * Uses `input === undefined`.
718
- *
719
- * **Example** (Guard undefined)
720
- *
721
- * ```ts
722
- * import { Predicate } from "effect"
723
- *
724
- * const data: unknown = undefined
725
- *
726
- * console.log(Predicate.isUndefined(data))
727
- * ```
728
- *
729
- * @see {@link isNotUndefined}
730
- * @see {@link isNullish}
731
- * @category guards
732
- * @since 2.0.0
733
- */
734
- function isUndefined(input) {
735
- return input === void 0;
736
- }
737
- /**
738
- * Checks whether a value is not `undefined`.
739
- *
740
- * **When to use**
741
- *
742
- * Use when you need a `Predicate` refinement that filters out `undefined`
743
- * while preserving other falsy values.
744
- *
745
- * **Details**
746
- *
747
- * Returns a refinement that excludes `undefined`.
748
- *
749
- * **Example** (Filter undefined)
750
- *
751
- * ```ts
752
- * import { Predicate } from "effect"
753
- *
754
- * const values = [1, undefined, 2]
755
- * const defined = values.filter(Predicate.isNotUndefined)
756
- *
757
- * console.log(defined)
758
- * ```
759
- *
760
- * @see {@link isUndefined}
761
- * @see {@link isNotNullish}
762
- * @category guards
763
- * @since 2.0.0
764
- */
765
- function isNotUndefined(input) {
766
- return input !== void 0;
767
- }
768
- /**
769
- * Checks whether a value is not `null`.
770
- *
771
- * **When to use**
772
- *
773
- * Use when you need a `Predicate` refinement that filters out `null` while
774
- * preserving other falsy values.
775
- *
776
- * **Details**
777
- *
778
- * Returns a refinement that excludes `null`.
779
- *
780
- * **Example** (Filter null)
781
- *
782
- * ```ts
783
- * import { Predicate } from "effect"
784
- *
785
- * const values = [1, null, 2]
786
- * const nonNull = values.filter(Predicate.isNotNull)
787
- *
788
- * console.log(nonNull)
789
- * ```
790
- *
791
- * @see {@link isNull}
792
- * @see {@link isNotNullish}
793
- * @category guards
794
- * @since 2.0.0
795
- */
796
- function isNotNull(input) {
797
- return input !== null;
798
- }
799
- /**
800
- * Checks whether a value is `null` or `undefined`.
801
- *
802
- * **When to use**
803
- *
804
- * Use when you need a `Predicate` guard for nullish values.
805
- *
806
- * **Details**
807
- *
808
- * Uses `input === null || input === undefined`.
809
- *
810
- * **Example** (Guard nullish)
811
- *
812
- * ```ts
813
- * import { Predicate } from "effect"
814
- *
815
- * const values = [0, null, "", undefined]
816
- * const nullish = values.filter(Predicate.isNullish)
817
- *
818
- * console.log(nullish)
819
- * ```
820
- *
821
- * @see {@link isNotNullish}
822
- * @see {@link isUndefined}
823
- * @see {@link isNull}
824
- * @category guards
825
- * @since 4.0.0
826
- */
827
- function isNullish(input) {
828
- return input === null || input === void 0;
829
- }
830
- /**
831
- * Checks whether a value is not `null` and not `undefined`.
832
- *
833
- * **When to use**
834
- *
835
- * Use when you need a `Predicate` refinement that filters out nullish values
836
- * but keeps other falsy ones.
837
- *
838
- * **Details**
839
- *
840
- * Uses `input != null`.
841
- *
842
- * **Example** (Filter non-nullish)
843
- *
844
- * ```ts
845
- * import { Predicate } from "effect"
846
- *
847
- * const values = [0, null, "", undefined]
848
- * const present = values.filter(Predicate.isNotNullish)
849
- *
850
- * console.log(present)
851
- * ```
852
- *
853
- * @see {@link isNullish}
854
- * @see {@link isNotNull}
855
- * @see {@link isNotUndefined}
856
- * @category guards
857
- * @since 4.0.0
858
- */
859
- function isNotNullish(input) {
860
- return input != null;
861
- }
862
- /**
863
- * Type guard that always returns `false`.
864
- *
865
- * **When to use**
866
- *
867
- * Use when you need a `Predicate` that never accepts, e.g. in default branches.
868
- *
869
- * **Example** (Never matches)
870
- *
871
- * ```ts
872
- * import { Predicate } from "effect"
873
- *
874
- * console.log(Predicate.isNever("anything"))
875
- * ```
876
- *
877
- * @see {@link isUnknown}
878
- * @category guards
879
- * @since 2.0.0
880
- */
881
- function isNever(_) {
882
- return false;
883
- }
884
- /**
885
- * Type guard that always returns `true`.
886
- *
887
- * **When to use**
888
- *
889
- * Use when you need a `Predicate` that always accepts, e.g. as a placeholder.
890
- *
891
- * **Example** (Always matches)
892
- *
893
- * ```ts
894
- * import { Predicate } from "effect"
895
- *
896
- * console.log(Predicate.isUnknown(123))
897
- * ```
898
- *
899
- * @see {@link isNever}
900
- * @category guards
901
- * @since 2.0.0
902
- */
903
- function isUnknown(_) {
904
- return true;
905
- }
906
- /**
907
- * Checks whether a value is a non-null object value that is not an array.
908
- *
909
- * **When to use**
910
- *
911
- * Use to narrow unknown input to a non-null, non-array object with a
912
- * `Predicate` guard.
913
- *
914
- * **Details**
915
- *
916
- * This is a structural runtime check using `typeof input === "object"`, so it
917
- * also accepts object instances such as `Date`, `Map`, class instances, and
918
- * typed arrays. It excludes `null` and arrays.
919
- *
920
- * **Example** (Guard object)
921
- *
922
- * ```ts
923
- * import { Predicate } from "effect"
924
- *
925
- * console.log(Predicate.isObject({ a: 1 }))
926
- * console.log(Predicate.isObject([1, 2]))
927
- * ```
928
- *
929
- * @see {@link isObjectOrArray}
930
- * @see {@link isReadonlyObject}
931
- * @category guards
932
- * @since 2.0.0
933
- */
934
- function isObject(input) {
935
- return typeof input === "object" && input !== null && !Array.isArray(input);
936
- }
937
- /**
938
- * Checks whether a value is an `object` in the JavaScript sense (objects, arrays, functions).
939
- *
940
- * **When to use**
941
- *
942
- * Use when you need a `Predicate` guard that accepts arrays and functions as
943
- * well as objects.
944
- *
945
- * **Details**
946
- *
947
- * Returns `true` for arrays and functions, and `false` for `null`.
948
- *
949
- * **Example** (Object keyword)
950
- *
951
- * ```ts
952
- * import { Predicate } from "effect"
953
- *
954
- * console.log(Predicate.isObjectKeyword(() => 1))
955
- * console.log(Predicate.isObjectKeyword(null))
956
- * ```
957
- *
958
- * @see {@link isObject}
959
- * @see {@link isObjectOrArray}
960
- * @category guards
961
- * @since 4.0.0
962
- */
963
- function isObjectKeyword(input) {
964
- return typeof input === "object" && input !== null || isFunction(input);
965
- }
966
- /**
967
- * Checks whether a value has a given property key.
968
- *
969
- * **When to use**
970
- *
971
- * Use when you need a `Predicate` guard for property access on `unknown`
972
- * values with a simple structural object check.
973
- *
974
- * **Details**
975
- *
976
- * Uses the `in` operator and `isObjectKeyword`. This does not check property
977
- * value types.
978
- *
979
- * **Example** (Guard property)
980
- *
981
- * ```ts
982
- * import { Predicate } from "effect"
983
- *
984
- * const hasName = Predicate.hasProperty("name")
985
- * const data: unknown = { name: "Ada" }
986
- *
987
- * if (hasName(data)) {
988
- * console.log(data.name)
989
- * }
990
- * ```
991
- *
992
- * @see {@link isTagged}
993
- * @see {@link isObjectKeyword}
994
- * @category guards
995
- * @since 2.0.0
996
- */
997
- const hasProperty = /*#__PURE__*/ dual(2, (self, property) => isObjectKeyword(self) && property in self);
998
- /**
999
- * Checks whether a value has a `_tag` property equal to the given tag.
1000
- *
1001
- * **When to use**
1002
- *
1003
- * Use when you model tagged unions with a `_tag` field and want a quick
1004
- * `Predicate` guard for tagged values.
1005
- *
1006
- * **Details**
1007
- *
1008
- * Uses `hasProperty` and strict equality on `_tag`.
1009
- *
1010
- * **Example** (Guard tagged)
1011
- *
1012
- * ```ts
1013
- * import { Predicate } from "effect"
1014
- *
1015
- * const isOk = Predicate.isTagged("Ok")
1016
- *
1017
- * console.log(isOk({ _tag: "Ok", value: 1 }))
1018
- * ```
1019
- *
1020
- * @see {@link hasProperty}
1021
- * @category guards
1022
- * @since 2.0.0
1023
- */
1024
- const isTagged = /*#__PURE__*/ dual(2, (self, tag) => hasProperty(self, "_tag") && self["_tag"] === tag);
1025
- /**
1026
- * Checks whether a value is an `Error`.
1027
- *
1028
- * **When to use**
1029
- *
1030
- * Use when you need a `Predicate` guard for errors caught from unknown sources.
1031
- *
1032
- * **Details**
1033
- *
1034
- * Uses `instanceof Error`.
1035
- *
1036
- * **Example** (Guard error)
1037
- *
1038
- * ```ts
1039
- * import { Predicate } from "effect"
1040
- *
1041
- * const data: unknown = new Error("boom")
1042
- *
1043
- * console.log(Predicate.isError(data))
1044
- * ```
1045
- *
1046
- * @see {@link isUnknown}
1047
- * @category guards
1048
- * @since 2.0.0
1049
- */
1050
- function isError(input) {
1051
- return input instanceof Error;
1052
- }
1053
- /**
1054
- * Checks whether a value is iterable.
1055
- *
1056
- * **When to use**
1057
- *
1058
- * Use when you need a `Predicate` guard before iterating an unknown value.
1059
- *
1060
- * **Details**
1061
- *
1062
- * Accepts strings as iterable and uses `hasProperty` for `Symbol.iterator`.
1063
- *
1064
- * **Example** (Guard iterable)
1065
- *
1066
- * ```ts
1067
- * import { Predicate } from "effect"
1068
- *
1069
- * const data: unknown = [1, 2, 3]
1070
- *
1071
- * console.log(Predicate.isIterable(data))
1072
- * ```
1073
- *
1074
- * @see {@link isSet}
1075
- * @see {@link isMap}
1076
- * @category guards
1077
- * @since 2.0.0
1078
- */
1079
- function isIterable(input) {
1080
- return hasProperty(input, Symbol.iterator) || isString(input);
1081
- }
1082
- //#endregion
1083
- //#region node_modules/.pnpm/effect@4.0.0-beta.78/node_modules/effect/dist/Hash.js
1084
- /**
1085
- * The `Hash` module computes Effect hash values and defines the interface for
1086
- * objects that want to provide their own hash implementation. Hashes are small
1087
- * numeric fingerprints used by Effect data structures to bucket values quickly;
1088
- * they are not cryptographic digests and they are not proof that two values are
1089
- * equal.
1090
- *
1091
- * **Mental model**
1092
- *
1093
- * - {@link hash} dispatches by JavaScript type and handles primitives,
1094
- * arrays, typed arrays, maps, sets, plain objects, dates, regular
1095
- * expressions, and custom hashable objects
1096
- * - Objects can implement {@link Hash} by defining a method at {@link symbol}
1097
- * - Structural object hashes are cached, so repeated hashing of the same object
1098
- * is cheap after the first computation
1099
- * - {@link random} gives reference-stable hash values for values that should
1100
- * be hashed by identity
1101
- * - Lower-level helpers such as {@link combine}, {@link string},
1102
- * {@link number}, {@link structure}, {@link structureKeys}, and
1103
- * {@link array} are useful when implementing custom hashes
1104
- *
1105
- * **Quickstart**
1106
- *
1107
- * **Example** (Implementing a custom hash)
1108
- *
1109
- * ```ts
1110
- * import { Hash } from "effect"
1111
- *
1112
- * class UserKey implements Hash.Hash {
1113
- * constructor(
1114
- * readonly id: string,
1115
- * readonly region: string
1116
- * ) {}
1117
- *
1118
- * [Hash.symbol](): number {
1119
- * return Hash.combine(Hash.string(this.region))(Hash.string(this.id))
1120
- * }
1121
- * }
1122
- *
1123
- * const value = Hash.hash(new UserKey("user-1", "eu"))
1124
- * ```
1125
- *
1126
- * **Gotchas**
1127
- *
1128
- * - Hash collisions are possible; hash-based collections also need equality
1129
- * semantics to decide whether two values are actually the same
1130
- * - Do not mutate an object after hashing it structurally, because the cached
1131
- * hash can become stale
1132
- * - Use {@link random} or a custom {@link Hash} implementation for mutable
1133
- * objects that should be compared by reference identity
1134
- *
1135
- * @since 2.0.0
1136
- */
1137
- /**
1138
- * Defines the unique identifier used to identify objects that implement the Hash interface.
1139
- *
1140
- * **When to use**
1141
- *
1142
- * Use as the computed property key for the method that supplies a custom hash
1143
- * value on a `Hash` implementor.
1144
- *
1145
- * @see {@link Hash} for the interface implemented with this symbol
1146
- * @see {@link isHash} for checking whether a value implements `Hash`
1147
- * @see {@link hash} for computing hash values
1148
- *
1149
- * @category symbols
1150
- * @since 2.0.0
1151
- */
1152
- const symbol$1 = "~effect/interfaces/Hash";
1153
- /**
1154
- * Computes a hash value for any given value.
1155
- *
1156
- * **When to use**
1157
- *
1158
- * Use to compute an Effect hash for primitives, collections, and hashable
1159
- * objects.
1160
- *
1161
- * **Details**
1162
- *
1163
- * This function can hash primitives (numbers, strings, booleans, etc.) as well as
1164
- * objects, arrays, and other complex data structures. It automatically handles
1165
- * different types and provides a consistent hash value for equivalent inputs.
1166
- *
1167
- * **Gotchas**
1168
- *
1169
- * Objects being hashed must be treated as immutable after their first hash
1170
- * computation. Hash results are cached, so mutating an object after hashing will
1171
- * lead to stale cached values and broken hash-based operations. For mutable
1172
- * objects, implement a custom `Hash` interface that hashes the object reference
1173
- * rather than its content.
1174
- *
1175
- * **Example** (Hashing different values)
1176
- *
1177
- * ```ts
1178
- * import { Hash } from "effect"
1179
- *
1180
- * // Hash primitive values
1181
- * console.log(Hash.hash(42)) // numeric hash
1182
- * console.log(Hash.hash("hello")) // string hash
1183
- * console.log(Hash.hash(true)) // boolean hash
1184
- *
1185
- * // Hash objects and arrays
1186
- * console.log(Hash.hash({ name: "John", age: 30 }))
1187
- * console.log(Hash.hash([1, 2, 3]))
1188
- * console.log(Hash.hash({ id: "user-1", roles: ["admin", "editor"] }))
1189
- * ```
1190
- *
1191
- * @category hashing
1192
- * @since 2.0.0
1193
- */
1194
- const hash = (self) => {
1195
- switch (typeof self) {
1196
- case "number": return number(self);
1197
- case "bigint": return string(self.toString(10));
1198
- case "boolean": return string(String(self));
1199
- case "symbol": return string(String(self));
1200
- case "string": return string(self);
1201
- case "undefined": return string("undefined");
1202
- case "function":
1203
- case "object": if (self === null) return string("null");
1204
- else if (self instanceof Date) return string(self.toISOString());
1205
- else if (self instanceof RegExp) return string(self.toString());
1206
- else {
1207
- if (byReferenceInstances.has(self)) return random(self);
1208
- if (hashCache.has(self)) return hashCache.get(self);
1209
- const h = withVisitedTracking$1(self, () => {
1210
- if (isHash(self)) return self[symbol$1]();
1211
- else if (typeof self === "function") return random(self);
1212
- else if (Array.isArray(self) || ArrayBuffer.isView(self)) return array(self);
1213
- else if (self instanceof Map) return hashMap(self);
1214
- else if (self instanceof Set) return hashSet(self);
1215
- return structure(self);
1216
- });
1217
- hashCache.set(self, h);
1218
- return h;
1219
- }
1220
- default: throw new Error(`BUG: unhandled typeof ${typeof self} - please report an issue at https://github.com/Effect-TS/effect/issues`);
1221
- }
1222
- };
1223
- /**
1224
- * Generates a random hash value for an object and caches it.
1225
- *
1226
- * **When to use**
1227
- *
1228
- * Use to hash an object by reference identity instead of structural content.
1229
- *
1230
- * **Details**
1231
- *
1232
- * This function creates a random hash value for objects that don't have their own
1233
- * hash implementation. The hash value is cached using a WeakMap, so the same object
1234
- * will always return the same hash value during its lifetime.
1235
- *
1236
- * **Example** (Hashing objects by reference)
1237
- *
1238
- * ```ts
1239
- * import { Hash } from "effect"
1240
- *
1241
- * const obj1 = { a: 1 }
1242
- * const obj2 = { a: 1 }
1243
- *
1244
- * // Same object always returns the same hash
1245
- * console.log(Hash.random(obj1) === Hash.random(obj1)) // true
1246
- *
1247
- * // Different objects get different hashes
1248
- * console.log(Hash.random(obj1) === Hash.random(obj2)) // false
1249
- * ```
1250
- *
1251
- * @category hashing
1252
- * @since 2.0.0
1253
- */
1254
- const random = (self) => {
1255
- if (!randomHashCache.has(self)) randomHashCache.set(self, number(Math.floor(Math.random() * Number.MAX_SAFE_INTEGER)));
1256
- return randomHashCache.get(self);
1257
- };
1258
- /**
1259
- * Combines two hash values into a single hash value.
1260
- *
1261
- * **When to use**
1262
- *
1263
- * Use to build a hash for a composite value by folding together hash values for
1264
- * its parts.
1265
- *
1266
- * **Details**
1267
- *
1268
- * Supports both direct and pipeable usage. The implementation combines two
1269
- * hash values with `(self * 53) ^ b`.
1270
- *
1271
- * **Example** (Combining hash values)
1272
- *
1273
- * ```ts
1274
- * import { Hash, pipe } from "effect"
1275
- *
1276
- * // Can also be used with pipe
1277
- *
1278
- * const hash1 = Hash.hash("hello")
1279
- * const hash2 = Hash.hash("world")
1280
- *
1281
- * // Combine two hash values
1282
- * const combined = Hash.combine(hash2)(hash1)
1283
- * console.log(combined)
1284
- * const result = pipe(hash1, Hash.combine(hash2))
1285
- * ```
1286
- *
1287
- * @see {@link hash} for computing hash values from arbitrary inputs
1288
- * @see {@link structureKeys} for hashing selected object fields without manual combination
1289
- *
1290
- * @category hashing
1291
- * @since 2.0.0
1292
- */
1293
- const combine = /*#__PURE__*/ dual(2, (self, b) => self * 53 ^ b);
1294
- /**
1295
- * Applies bit manipulation techniques to optimize a hash value.
1296
- *
1297
- * **When to use**
1298
- *
1299
- * Use to improve the bit distribution of a raw numeric hash value.
1300
- *
1301
- * **Details**
1302
- *
1303
- * This function takes a hash value and applies bitwise operations to improve
1304
- * the distribution of hash values, reducing the likelihood of collisions.
1305
- *
1306
- * **Example** (Optimizing a hash value)
1307
- *
1308
- * ```ts
1309
- * import { Hash } from "effect"
1310
- *
1311
- * const rawHash = 1234567890
1312
- * const optimizedHash = Hash.optimize(rawHash)
1313
- * console.log(optimizedHash) // optimized hash value
1314
- *
1315
- * // Often used internally by other hash functions
1316
- * const stringHash = Hash.optimize(Hash.string("hello"))
1317
- * ```
1318
- *
1319
- * @category hashing
1320
- * @since 2.0.0
1321
- */
1322
- const optimize = (n) => n & 3221225471 | n >>> 1 & 1073741824;
1323
- /**
1324
- * Checks whether a value implements the Hash interface.
1325
- *
1326
- * **When to use**
1327
- *
1328
- * Use to detect whether an unknown value provides a custom hash implementation.
1329
- *
1330
- * **Details**
1331
- *
1332
- * This function determines whether a given value has the Hash symbol property,
1333
- * indicating that it can provide its own hash value implementation.
1334
- *
1335
- * **Example** (Checking for Hash support)
1336
- *
1337
- * ```ts
1338
- * import { Hash } from "effect"
1339
- *
1340
- * class MyHashable implements Hash.Hash {
1341
- * [Hash.symbol]() {
1342
- * return 42
1343
- * }
1344
- * }
1345
- *
1346
- * const obj = new MyHashable()
1347
- * console.log(Hash.isHash(obj)) // true
1348
- * console.log(Hash.isHash({})) // false
1349
- * console.log(Hash.isHash("string")) // false
1350
- * ```
1351
- *
1352
- * @category guards
1353
- * @since 2.0.0
1354
- */
1355
- const isHash = (u) => hasProperty(u, symbol$1);
1356
- /**
1357
- * Computes a hash value for a number.
1358
- *
1359
- * **When to use**
1360
- *
1361
- * Use to hash a JavaScript number with Effect's numeric hash semantics.
1362
- *
1363
- * **Details**
1364
- *
1365
- * This function creates a hash value for numeric inputs, handling special cases
1366
- * like NaN, Infinity, and -Infinity with distinct hash values. It uses bitwise operations to ensure good distribution
1367
- * of hash values across different numeric inputs.
1368
- *
1369
- * **Example** (Hashing numbers)
1370
- *
1371
- * ```ts
1372
- * import { Hash } from "effect"
1373
- *
1374
- * console.log(Hash.number(42)) // hash of 42
1375
- * console.log(Hash.number(3.14)) // hash of 3.14
1376
- * console.log(Hash.number(NaN)) // hash of "NaN"
1377
- * console.log(Hash.number(Infinity)) // 0 (special case)
1378
- *
1379
- * // Same numbers produce the same hash
1380
- * console.log(Hash.number(100) === Hash.number(100)) // true
1381
- * ```
1382
- *
1383
- * @category hashing
1384
- * @since 2.0.0
1385
- */
1386
- const number = (n) => {
1387
- if (n !== n) return string("NaN");
1388
- if (n === Infinity) return string("Infinity");
1389
- if (n === -Infinity) return string("-Infinity");
1390
- let h = n | 0;
1391
- if (h !== n) h ^= n * 4294967295;
1392
- while (n > 4294967295) h ^= n /= 4294967295;
1393
- return optimize(h);
1394
- };
1395
- /**
1396
- * Computes a hash value for a string using the djb2 algorithm.
1397
- *
1398
- * **When to use**
1399
- *
1400
- * Use when you need a string field to contribute to a custom structural hash
1401
- * implementation.
1402
- *
1403
- * **Details**
1404
- *
1405
- * This function implements a variation of the djb2 hash algorithm, which is
1406
- * known for its good distribution properties and speed. It processes each
1407
- * character of the string to produce a consistent hash value.
1408
- *
1409
- * **Example** (Hashing strings)
1410
- *
1411
- * ```ts
1412
- * import { Hash } from "effect"
1413
- *
1414
- * console.log(Hash.string("hello")) // hash of "hello"
1415
- * console.log(Hash.string("world")) // hash of "world"
1416
- * console.log(Hash.string("")) // hash of empty string
1417
- *
1418
- * // Same strings produce the same hash
1419
- * console.log(Hash.string("test") === Hash.string("test")) // true
1420
- * ```
1421
- *
1422
- * @category hashing
1423
- * @since 2.0.0
1424
- */
1425
- const string = (str) => {
1426
- let h = 5381, i = str.length;
1427
- while (i) h = h * 33 ^ str.charCodeAt(--i);
1428
- return optimize(h);
1429
- };
1430
- /**
1431
- * Computes a hash value for an object using only the specified keys.
1432
- *
1433
- * **When to use**
1434
- *
1435
- * Use to hash an object by a selected set of property keys.
1436
- *
1437
- * **Details**
1438
- *
1439
- * This function allows you to hash an object by considering only specific keys,
1440
- * which is useful when you want to create a hash based on a subset of an object's
1441
- * properties.
1442
- *
1443
- * **Example** (Hashing selected object keys)
1444
- *
1445
- * ```ts
1446
- * import { Hash } from "effect"
1447
- *
1448
- * const person = { name: "John", age: 30, city: "New York" }
1449
- *
1450
- * // Hash only specific keys
1451
- * const hash1 = Hash.structureKeys(person, ["name", "age"])
1452
- * const hash2 = Hash.structureKeys(person, ["name", "city"])
1453
- *
1454
- * console.log(hash1) // hash based on name and age
1455
- * console.log(hash2) // hash based on name and city
1456
- *
1457
- * // Same keys produce the same hash
1458
- * const person2 = { name: "John", age: 30, city: "Boston" }
1459
- * const hash3 = Hash.structureKeys(person2, ["name", "age"])
1460
- * console.log(hash1 === hash3) // true
1461
- * ```
1462
- *
1463
- * @category hashing
1464
- * @since 2.0.0
1465
- */
1466
- const structureKeys = (o, keys) => {
1467
- let h = 12289;
1468
- for (const key of keys) h ^= combine(hash(key), hash(o[key]));
1469
- return optimize(h);
1470
- };
1471
- /**
1472
- * Computes a structural hash for an object using Effect's object key collection.
1473
- *
1474
- * **When to use**
1475
- *
1476
- * Use to hash an object from all structural keys collected by Effect.
1477
- *
1478
- * **Details**
1479
- *
1480
- * The hash is based on the object's structural keys and their values, including
1481
- * symbol keys and relevant prototype keys for non-plain objects.
1482
- *
1483
- * **Example** (Hashing object structures)
1484
- *
1485
- * ```ts
1486
- * import { Hash } from "effect"
1487
- *
1488
- * const obj1 = { name: "John", age: 30 }
1489
- * const obj2 = { name: "Jane", age: 25 }
1490
- * const obj3 = { name: "John", age: 30 }
1491
- *
1492
- * console.log(Hash.structure(obj1)) // hash of obj1
1493
- * console.log(Hash.structure(obj2)) // different hash
1494
- * console.log(Hash.structure(obj3)) // same as obj1
1495
- *
1496
- * // Objects with same properties produce same hash
1497
- * console.log(Hash.structure(obj1) === Hash.structure(obj3)) // true
1498
- * ```
1499
- *
1500
- * @category hashing
1501
- * @since 2.0.0
1502
- */
1503
- const structure = (o) => structureKeys(o, getAllObjectKeys(o));
1504
- const iterableWith = (seed, f) => (iter) => {
1505
- let h = seed;
1506
- for (const element of iter) h ^= f(element);
1507
- return optimize(h);
1508
- };
1509
- /**
1510
- * Computes a hash value for an iterable by hashing all of its elements.
1511
- *
1512
- * **When to use**
1513
- *
1514
- * Use to hash the values yielded by an iterable with Effect hash semantics.
1515
- *
1516
- * **Details**
1517
- *
1518
- * The implementation folds element hashes from the seed `6151` with XOR and
1519
- * then optimizes the final hash.
1520
- *
1521
- * **Gotchas**
1522
- *
1523
- * A hash is not an equality proof. Because this implementation uses XOR,
1524
- * reordered inputs can produce the same hash.
1525
- *
1526
- * **Example** (Hashing arrays)
1527
- *
1528
- * ```ts
1529
- * import { Hash } from "effect"
1530
- *
1531
- * const arr1 = [1, 2, 3]
1532
- * const arr2 = [1, 2, 3]
1533
- * const arr3 = [3, 2, 1]
1534
- *
1535
- * console.log(Hash.array(arr1)) // hash of [1, 2, 3]
1536
- * console.log(Hash.array(arr2)) // same hash as arr1
1537
- * console.log(Hash.array(arr3)) // may match reordered inputs
1538
- *
1539
- * console.log(Hash.array(arr1) === Hash.array(arr2)) // true
1540
- * console.log(Hash.array(arr1) === Hash.array(arr3)) // true
1541
- * ```
1542
- *
1543
- * @see {@link hash} for the general-purpose hash dispatcher
1544
- *
1545
- * @category hashing
1546
- * @since 2.0.0
1547
- */
1548
- const array = /*#__PURE__*/ iterableWith(6151, hash);
1549
- const hashMap = /*#__PURE__*/ iterableWith(/*#__PURE__*/ string("Map"), ([k, v]) => combine(hash(k), hash(v)));
1550
- const hashSet = /*#__PURE__*/ iterableWith(/*#__PURE__*/ string("Set"), hash);
1551
- const randomHashCache = /*#__PURE__*/ new WeakMap();
1552
- const hashCache = /*#__PURE__*/ new WeakMap();
1553
- const visitedObjects = /*#__PURE__*/ new WeakSet();
1554
- function withVisitedTracking$1(obj, fn) {
1555
- if (visitedObjects.has(obj)) return string("[Circular]");
1556
- visitedObjects.add(obj);
1557
- const result = fn();
1558
- visitedObjects.delete(obj);
1559
- return result;
1560
- }
1561
- //#endregion
1562
- //#region node_modules/.pnpm/effect@4.0.0-beta.78/node_modules/effect/dist/Equal.js
1563
- /**
1564
- * Defines the unique string identifier for the `Equal` interface.
1565
- *
1566
- * **When to use**
1567
- *
1568
- * Use when you implement custom equality and need the computed property key for
1569
- * the equality method.
1570
- *
1571
- * **Details**
1572
- *
1573
- * This is a pure constant with no allocation or side effects.
1574
- *
1575
- * **Example** (Implementing Equal on a Class)
1576
- *
1577
- * ```ts
1578
- * import { Equal, Hash } from "effect"
1579
- *
1580
- * class UserId implements Equal.Equal {
1581
- * constructor(readonly id: string) {}
1582
- *
1583
- * [Equal.symbol](that: Equal.Equal): boolean {
1584
- * return that instanceof UserId && this.id === that.id
1585
- * }
1586
- *
1587
- * [Hash.symbol](): number {
1588
- * return Hash.string(this.id)
1589
- * }
1590
- * }
1591
- * ```
1592
- *
1593
- * @see {@link Equal} — the interface that uses this symbol
1594
- * @see {@link isEqual} — type guard for `Equal` implementors
1595
- * @category symbols
1596
- * @since 2.0.0
1597
- */
1598
- const symbol = "~effect/interfaces/Equal";
1599
- function equals() {
1600
- if (arguments.length === 1) return (self) => compareBoth(self, arguments[0]);
1601
- return compareBoth(arguments[0], arguments[1]);
1602
- }
1603
- function compareBoth(self, that) {
1604
- if (self === that) return true;
1605
- if (self == null || that == null) return false;
1606
- const selfType = typeof self;
1607
- if (selfType !== typeof that) return false;
1608
- if (selfType === "number" && self !== self && that !== that) return true;
1609
- if (selfType !== "object" && selfType !== "function") return false;
1610
- if (byReferenceInstances.has(self) || byReferenceInstances.has(that)) return false;
1611
- return withCache(self, that, compareObjects);
1612
- }
1613
- /** Helper to run comparison with proper visited tracking */
1614
- function withVisitedTracking(self, that, fn) {
1615
- const hasLeft = visitedLeft.has(self);
1616
- const hasRight = visitedRight.has(that);
1617
- if (hasLeft && hasRight) return true;
1618
- if (hasLeft || hasRight) return false;
1619
- visitedLeft.add(self);
1620
- visitedRight.add(that);
1621
- const result = fn();
1622
- visitedLeft.delete(self);
1623
- visitedRight.delete(that);
1624
- return result;
1625
- }
1626
- const visitedLeft = /*#__PURE__*/ new WeakSet();
1627
- const visitedRight = /*#__PURE__*/ new WeakSet();
1628
- /** Helper to perform cached object comparison */
1629
- function compareObjects(self, that) {
1630
- if (hash(self) !== hash(that)) return false;
1631
- else if (self instanceof Date) {
1632
- if (!(that instanceof Date)) return false;
1633
- return self.toISOString() === that.toISOString();
1634
- } else if (self instanceof RegExp) {
1635
- if (!(that instanceof RegExp)) return false;
1636
- return self.toString() === that.toString();
1637
- }
1638
- const selfIsEqual = isEqual(self);
1639
- const thatIsEqual = isEqual(that);
1640
- if (selfIsEqual !== thatIsEqual) return false;
1641
- const bothEquals = selfIsEqual && thatIsEqual;
1642
- if (typeof self === "function" && !bothEquals) return false;
1643
- return withVisitedTracking(self, that, () => {
1644
- if (bothEquals) return self[symbol](that);
1645
- else if (Array.isArray(self)) {
1646
- if (!Array.isArray(that) || self.length !== that.length) return false;
1647
- return compareArrays(self, that);
1648
- } else if (ArrayBuffer.isView(self)) {
1649
- if (!ArrayBuffer.isView(that) || self.byteLength !== that.byteLength) return false;
1650
- return compareTypedArrays(self, that);
1651
- } else if (self instanceof Map) {
1652
- if (!(that instanceof Map) || self.size !== that.size) return false;
1653
- return compareMaps(self, that);
1654
- } else if (self instanceof Set) {
1655
- if (!(that instanceof Set) || self.size !== that.size) return false;
1656
- return compareSets(self, that);
1657
- }
1658
- return compareRecords(self, that);
1659
- });
1660
- }
1661
- function withCache(self, that, f) {
1662
- let selfMap = equalityCache.get(self);
1663
- if (!selfMap) {
1664
- selfMap = /* @__PURE__ */ new WeakMap();
1665
- equalityCache.set(self, selfMap);
1666
- } else if (selfMap.has(that)) return selfMap.get(that);
1667
- const result = f(self, that);
1668
- selfMap.set(that, result);
1669
- let thatMap = equalityCache.get(that);
1670
- if (!thatMap) {
1671
- thatMap = /* @__PURE__ */ new WeakMap();
1672
- equalityCache.set(that, thatMap);
1673
- }
1674
- thatMap.set(self, result);
1675
- return result;
1676
- }
1677
- const equalityCache = /*#__PURE__*/ new WeakMap();
1678
- function compareArrays(self, that) {
1679
- for (let i = 0; i < self.length; i++) if (!compareBoth(self[i], that[i])) return false;
1680
- return true;
1681
- }
1682
- function compareTypedArrays(self, that) {
1683
- if (self.length !== that.length) return false;
1684
- for (let i = 0; i < self.length; i++) if (self[i] !== that[i]) return false;
1685
- return true;
1686
- }
1687
- function compareRecords(self, that) {
1688
- const selfKeys = getAllObjectKeys(self);
1689
- const thatKeys = getAllObjectKeys(that);
1690
- if (selfKeys.size !== thatKeys.size) return false;
1691
- for (const key of selfKeys) if (!thatKeys.has(key) || !compareBoth(self[key], that[key])) return false;
1692
- return true;
1693
- }
1694
- /** @internal */
1695
- function makeCompareMap(keyEquivalence, valueEquivalence) {
1696
- return function compareMaps(self, that) {
1697
- for (const [selfKey, selfValue] of self) {
1698
- let found = false;
1699
- for (const [thatKey, thatValue] of that) if (keyEquivalence(selfKey, thatKey) && valueEquivalence(selfValue, thatValue)) {
1700
- found = true;
1701
- break;
1702
- }
1703
- if (!found) return false;
1704
- }
1705
- return true;
1706
- };
1707
- }
1708
- const compareMaps = /*#__PURE__*/ makeCompareMap(compareBoth, compareBoth);
1709
- /** @internal */
1710
- function makeCompareSet(equivalence) {
1711
- return function compareSets(self, that) {
1712
- for (const selfValue of self) {
1713
- let found = false;
1714
- for (const thatValue of that) if (equivalence(selfValue, thatValue)) {
1715
- found = true;
1716
- break;
1717
- }
1718
- if (!found) return false;
1719
- }
1720
- return true;
1721
- };
1722
- }
1723
- const compareSets = /*#__PURE__*/ makeCompareSet(compareBoth);
1724
- /**
1725
- * Checks whether a value implements the {@link Equal} interface.
1726
- *
1727
- * **When to use**
1728
- *
1729
- * Use when you need generic utility code to distinguish `Equal` implementors
1730
- * from plain values before calling `[Equal.symbol]` directly.
1731
- *
1732
- * **Details**
1733
- *
1734
- * - Pure function, no side effects.
1735
- * - Returns `true` if and only if `u` has a property keyed by
1736
- * {@link symbol}.
1737
- * - Acts as a TypeScript type guard, narrowing the input to {@link Equal}.
1738
- *
1739
- * **Example** (Type Guard)
1740
- *
1741
- * ```ts
1742
- * import { Equal, Hash } from "effect"
1743
- *
1744
- * class Token implements Equal.Equal {
1745
- * constructor(readonly value: string) {}
1746
- * [Equal.symbol](that: Equal.Equal): boolean {
1747
- * return that instanceof Token && this.value === that.value
1748
- * }
1749
- * [Hash.symbol](): number {
1750
- * return Hash.string(this.value)
1751
- * }
1752
- * }
1753
- *
1754
- * console.log(Equal.isEqual(new Token("abc"))) // true
1755
- * console.log(Equal.isEqual({ x: 1 })) // false
1756
- * console.log(Equal.isEqual(42)) // false
1757
- * ```
1758
- *
1759
- * @see {@link Equal} — the interface being checked
1760
- * @see {@link symbol} — the property key that signals `Equal` support
1761
- * @category guards
1762
- * @since 2.0.0
1763
- */
1764
- const isEqual = (u) => hasProperty(u, symbol);
1765
- /**
1766
- * Wraps {@link equals} as an `Equivalence<A>`.
1767
- *
1768
- * **When to use**
1769
- *
1770
- * Use when you want to pass `Equal.equals` to APIs that require an
1771
- * `Equivalence`.
1772
- *
1773
- * **Details**
1774
- *
1775
- * - Returns a function `(a: A, b: A) => boolean` that delegates to
1776
- * {@link equals}.
1777
- * - Pure; allocates a thin wrapper on each call.
1778
- *
1779
- * **Example** (Deduplicating with Equal Semantics)
1780
- *
1781
- * ```ts
1782
- * import { Array, Equal } from "effect"
1783
- *
1784
- * const eq = Equal.asEquivalence<number>()
1785
- * const result = Array.dedupeWith([1, 2, 2, 3, 1], eq)
1786
- * console.log(result) // [1, 2, 3]
1787
- * ```
1788
- *
1789
- * @see {@link equals} — the underlying comparison function
1790
- * @category instances
1791
- * @since 4.0.0
1792
- */
1793
- const asEquivalence = () => equals;
1794
- //#endregion
1795
- //#region node_modules/.pnpm/effect@4.0.0-beta.78/node_modules/effect/dist/Redactable.js
1796
- /**
1797
- * Defines the symbol used to identify objects that implement the {@link Redactable}
1798
- * protocol.
1799
- *
1800
- * **When to use**
1801
- *
1802
- * Use as the property key when implementing the `Redactable` protocol.
1803
- *
1804
- * **Details**
1805
- *
1806
- * Add a method under this key to make an object redactable. The method receives
1807
- * the current `Context` and must return the replacement value. The symbol is
1808
- * registered globally via `Symbol.for("~effect/Redactable")`, so it is
1809
- * identical across multiple copies of the library at runtime.
1810
- *
1811
- * **Example** (Masking an API key)
1812
- *
1813
- * ```ts
1814
- * import { Context, Redactable } from "effect"
1815
- *
1816
- * class ApiKey {
1817
- * constructor(readonly raw: string) {}
1818
- *
1819
- * [Redactable.symbolRedactable](_ctx: Context.Context<never>) {
1820
- * return this.raw.slice(0, 4) + "..."
1821
- * }
1822
- * }
1823
- * ```
1824
- *
1825
- * @see {@link Redactable} for the interface this symbol belongs to
1826
- * @see {@link isRedactable} to check whether a value has this symbol
1827
- * @category symbols
1828
- * @since 3.10.0
1829
- */
1830
- const symbolRedactable = /*#__PURE__*/ Symbol.for("~effect/Redactable");
1831
- /**
1832
- * Type guard that checks whether a value implements the {@link Redactable}
1833
- * interface.
1834
- *
1835
- * **When to use**
1836
- *
1837
- * Use to narrow an unknown value before calling redaction-specific helpers.
1838
- *
1839
- * @see {@link Redactable} for the interface being checked
1840
- * @see {@link redact} to apply redaction if the value is redactable
1841
- * @category guards
1842
- * @since 3.10.0
1843
- */
1844
- const isRedactable = (u) => hasProperty(u, symbolRedactable);
1845
- /**
1846
- * Returns a redacted value if it implements {@link Redactable}, otherwise returns it
1847
- * unchanged.
1848
- *
1849
- * **When to use**
1850
- *
1851
- * Use as the general-purpose entry point for redaction when the input may
1852
- * or may not implement the redaction protocol.
1853
- *
1854
- * **Details**
1855
- *
1856
- * This function calls {@link isRedactable} and, when it returns `true`,
1857
- * delegates to {@link getRedacted}.
1858
- *
1859
- * **Gotchas**
1860
- *
1861
- * Redaction is not recursive. Nested redactable values inside the returned
1862
- * object are not automatically redacted.
1863
- *
1864
- * @see {@link isRedactable} to check before redacting
1865
- * @see {@link getRedacted} for the lower-level variant for known redactables
1866
- * @category destructors
1867
- * @since 3.10.0
1868
- */
1869
- function redact(u) {
1870
- if (isRedactable(u)) return getRedacted(u);
1871
- return u;
1872
- }
1873
- /**
1874
- * Returns the result of calling `[symbolRedactable]` on a value that is
1875
- * already known to be {@link Redactable}.
1876
- *
1877
- * **When to use**
1878
- *
1879
- * Use when you need to read the redacted representation from a value already
1880
- * verified as `Redactable`.
1881
- *
1882
- * **Details**
1883
- *
1884
- * This function reads the current fiber's `Context` from the global fiber
1885
- * reference and passes it to the redaction method.
1886
- *
1887
- * **Gotchas**
1888
- *
1889
- * If no fiber is active, an empty `Context` is passed to the redaction method.
1890
- *
1891
- * @see {@link redact} for the higher-level variant that handles non-redactable values
1892
- * @see {@link isRedactable} for the type guard to verify before calling this
1893
- * @category destructors
1894
- * @since 4.0.0
1895
- */
1896
- function getRedacted(redactable) {
1897
- return redactable[symbolRedactable](globalThis["~effect/Fiber/currentFiber"]?.context ?? emptyContext$1);
1898
- }
1899
- /** @internal */
1900
- const currentFiberTypeId = "~effect/Fiber/currentFiber";
1901
- const emptyContext$1 = {
1902
- "~effect/Context": {},
1903
- mapUnsafe: /*#__PURE__*/ new Map(),
1904
- pipe() {
1905
- return pipeArguments(this, arguments);
1906
- }
1907
- };
1908
- //#endregion
1909
- //#region node_modules/.pnpm/effect@4.0.0-beta.78/node_modules/effect/dist/Formatter.js
1910
- /**
1911
- * Utilities for converting arbitrary JavaScript values into human-readable
1912
- * strings, with support for circular references, redaction, and common JS
1913
- * types that `JSON.stringify` handles poorly.
1914
- *
1915
- * Mental model:
1916
- * - A `Formatter<Value, Format>` is a callable `(value: Value) => Format`.
1917
- * - {@link format} is the general-purpose pretty-printer: it handles
1918
- * primitives, arrays, objects, `BigInt`, `Symbol`, `Date`, `RegExp`,
1919
- * `Set`, `Map`, class instances, and circular references.
1920
- * - {@link formatJson} is a safe `JSON.stringify` wrapper that silently
1921
- * drops circular references and applies redaction.
1922
- * - Both functions accept a `space` option for indentation control.
1923
- *
1924
- * Common tasks:
1925
- * - Pretty-print any value for debugging / logging -> {@link format}
1926
- * - Serialize to JSON safely (no circular throws) -> {@link formatJson}
1927
- * - Format a single object property key -> {@link formatPropertyKey}
1928
- * - Format a property path like `["a"]["b"]` -> {@link formatPath}
1929
- * - Format a `Date` to ISO string safely -> {@link formatDate}
1930
- *
1931
- * Gotchas:
1932
- * - {@link format} output is **not** valid JSON; use {@link formatJson} when
1933
- * you need parseable JSON.
1934
- * - {@link format} calls `toString()` on objects by default; pass
1935
- * `ignoreToString: true` to disable.
1936
- * - {@link formatJson} silently omits circular references (the key is
1937
- * dropped from the output).
1938
- * - Values implementing the `Redactable` protocol are automatically
1939
- * redacted by both {@link format} and {@link formatJson}.
1940
- *
1941
- * **Example** (Pretty-print a value)
1942
- *
1943
- * ```ts
1944
- * import { Formatter } from "effect"
1945
- *
1946
- * const obj = { name: "Alice", scores: [100, 97] }
1947
- * console.log(Formatter.format(obj))
1948
- * // {"name":"Alice","scores":[100,97]}
1949
- *
1950
- * console.log(Formatter.format(obj, { space: 2 }))
1951
- * // {
1952
- * // "name": "Alice",
1953
- * // "scores": [
1954
- * // 100,
1955
- * // 97
1956
- * // ]
1957
- * // }
1958
- * ```
1959
- *
1960
- * See also: {@link Formatter}, {@link format}, {@link formatJson}
1961
- *
1962
- * @since 4.0.0
1963
- */
1964
- /**
1965
- * Converts any JavaScript value into a human-readable string.
1966
- *
1967
- * **When to use**
1968
- *
1969
- * Use when you need to format arbitrary JavaScript values for debugging,
1970
- * logging, or error messages.
1971
- *
1972
- * **Details**
1973
- *
1974
- * - Output is **not** valid JSON; use {@link formatJson} when you need
1975
- * parseable JSON.
1976
- * - Handles `BigInt`, `Symbol`, `Set`, `Map`, `Date`, `RegExp`, and class
1977
- * instances that `JSON.stringify` cannot represent.
1978
- * - Circular references are shown as `"[Circular]"` instead of throwing.
1979
- * - Primitives: stringified naturally (`null`, `undefined`, `123`, `true`).
1980
- * Strings are JSON-quoted.
1981
- * - Objects with a custom `toString` (not `Object.prototype.toString`):
1982
- * `toString()` is called unless `ignoreToString` is `true`.
1983
- * - Errors with a `cause`: formatted as `"<message> (cause: <cause>)"`.
1984
- * - Iterables (`Set`, `Map`, etc.): formatted as
1985
- * `ClassName([...elements])`.
1986
- * - Class instances: wrapped as `ClassName({...})`.
1987
- * - `Redactable` values are automatically redacted.
1988
- * - Arrays/objects with 0–1 entries are inline; larger ones are
1989
- * pretty-printed when `space` is set.
1990
- * - `space` — indentation unit (number of spaces, or a string like
1991
- * `"\t"`). Defaults to `0` (compact).
1992
- * - `ignoreToString` — skip calling `toString()`. Defaults to `false`.
1993
- *
1994
- * **Example** (Compact output)
1995
- *
1996
- * ```ts
1997
- * import { Formatter } from "effect"
1998
- *
1999
- * console.log(Formatter.format({ a: 1, b: [2, 3] }))
2000
- * // {"a":1,"b":[2,3]}
2001
- * ```
2002
- *
2003
- * **Example** (Pretty-printed output)
2004
- *
2005
- * ```ts
2006
- * import { Formatter } from "effect"
2007
- *
2008
- * console.log(Formatter.format({ a: 1, b: [2, 3] }, { space: 2 }))
2009
- * // {
2010
- * // "a": 1,
2011
- * // "b": [
2012
- * // 2,
2013
- * // 3
2014
- * // ]
2015
- * // }
2016
- * ```
2017
- *
2018
- * **Example** (Circular reference handling)
2019
- *
2020
- * ```ts
2021
- * import { Formatter } from "effect"
2022
- *
2023
- * const obj: any = { name: "loop" }
2024
- * obj.self = obj
2025
- * console.log(Formatter.format(obj))
2026
- * // {"name":"loop","self":[Circular]}
2027
- * ```
2028
- *
2029
- * @see {@link formatJson}
2030
- * @see {@link Formatter}
2031
- * @category formatting
2032
- * @since 2.0.0
2033
- */
2034
- function format(input, options) {
2035
- const space = options?.space ?? 0;
2036
- const seen = /* @__PURE__ */ new WeakSet();
2037
- const gap = !space ? "" : typeof space === "number" ? " ".repeat(space) : space;
2038
- const ind = (d) => gap.repeat(d);
2039
- const wrap = (v, body) => {
2040
- const ctor = v?.constructor;
2041
- return ctor && ctor !== Object.prototype.constructor && ctor.name ? `${ctor.name}(${body})` : body;
2042
- };
2043
- const ownKeys = (o) => {
2044
- try {
2045
- return Reflect.ownKeys(o);
2046
- } catch {
2047
- return ["[ownKeys threw]"];
2048
- }
2049
- };
2050
- function recur(v, d = 0) {
2051
- if (Array.isArray(v)) {
2052
- if (seen.has(v)) return CIRCULAR;
2053
- seen.add(v);
2054
- if (!gap || v.length <= 1) return `[${v.map((x) => recur(x, d)).join(",")}]`;
2055
- const inner = v.map((x) => recur(x, d + 1)).join(",\n" + ind(d + 1));
2056
- return `[\n${ind(d + 1)}${inner}\n${ind(d)}]`;
2057
- }
2058
- if (v instanceof Date) return formatDate(v);
2059
- if (!options?.ignoreToString && hasProperty(v, "toString") && typeof v["toString"] === "function" && v["toString"] !== Object.prototype.toString && v["toString"] !== Array.prototype.toString) {
2060
- const s = safeToString(v);
2061
- if (v instanceof Error && v.cause) return `${s} (cause: ${recur(v.cause, d)})`;
2062
- return s;
2063
- }
2064
- if (typeof v === "string") return JSON.stringify(v);
2065
- if (typeof v === "number" || v == null || typeof v === "boolean" || typeof v === "symbol") return String(v);
2066
- if (typeof v === "bigint") return String(v) + "n";
2067
- if (typeof v === "object" || typeof v === "function") {
2068
- if (seen.has(v)) return CIRCULAR;
2069
- seen.add(v);
2070
- if (symbolRedactable in v) return format(getRedacted(v));
2071
- if (Symbol.iterator in v) return `${v.constructor.name}(${recur(Array.from(v), d)})`;
2072
- const keys = ownKeys(v);
2073
- if (!gap || keys.length <= 1) return wrap(v, `{${keys.map((k) => `${formatPropertyKey(k)}:${recur(v[k], d)}`).join(",")}}`);
2074
- return wrap(v, `{\n${keys.map((k) => `${ind(d + 1)}${formatPropertyKey(k)}: ${recur(v[k], d + 1)}`).join(",\n")}\n${ind(d)}}`);
2075
- }
2076
- return String(v);
2077
- }
2078
- return recur(input, 0);
2079
- }
2080
- const CIRCULAR = "[Circular]";
2081
- /**
2082
- * @internal
2083
- */
2084
- function formatPropertyKey(name) {
2085
- return typeof name === "string" ? JSON.stringify(name) : String(name);
2086
- }
2087
- /**
2088
- * Formats an array of property keys as a bracket-notation path string.
2089
- *
2090
- * @internal
2091
- */
2092
- function formatPath(path) {
2093
- return path.map((key) => `[${formatPropertyKey(key)}]`).join("");
2094
- }
2095
- /**
2096
- * Formats a `Date` as an ISO 8601 string, returning `"Invalid Date"` for
2097
- * invalid dates instead of throwing.
2098
- *
2099
- * @internal
2100
- */
2101
- function formatDate(date) {
2102
- try {
2103
- return date.toISOString();
2104
- } catch {
2105
- return "Invalid Date";
2106
- }
2107
- }
2108
- function safeToString(input) {
2109
- try {
2110
- const s = input.toString();
2111
- return typeof s === "string" ? s : String(s);
2112
- } catch {
2113
- return "[toString threw]";
2114
- }
2115
- }
2116
- /**
2117
- * Stringifies a value to JSON safely, silently dropping circular references.
2118
- *
2119
- * **When to use**
2120
- *
2121
- * Use when you need valid JSON output, unlike `format`, and the input may
2122
- * contain circular references that should be silently omitted rather than
2123
- * throwing a `TypeError`.
2124
- *
2125
- * **Details**
2126
- *
2127
- * Uses `JSON.stringify` internally with a replacer that tracks the current
2128
- * object ancestry. Circular references are replaced with `undefined`, which
2129
- * omits them from object output. `Redactable` values are automatically redacted
2130
- * before serialization. Values not supported by JSON, such as `BigInt`,
2131
- * `Symbol`, `undefined`, and functions, follow standard `JSON.stringify`
2132
- * behavior. The `space` parameter controls indentation and defaults to `0`.
2133
- *
2134
- * **Example** (Compact JSON)
2135
- *
2136
- * ```ts
2137
- * import { Formatter } from "effect"
2138
- *
2139
- * console.log(Formatter.formatJson({ name: "Alice", age: 30 }))
2140
- * // {"name":"Alice","age":30}
2141
- * ```
2142
- *
2143
- * **Example** (Circular reference handling)
2144
- *
2145
- * ```ts
2146
- * import { Formatter } from "effect"
2147
- *
2148
- * const obj: any = { name: "test" }
2149
- * obj.self = obj
2150
- * console.log(Formatter.formatJson(obj))
2151
- * // {"name":"test"}
2152
- * ```
2153
- *
2154
- * **Example** (Pretty-printed JSON)
2155
- *
2156
- * ```ts
2157
- * import { Formatter } from "effect"
2158
- *
2159
- * console.log(Formatter.formatJson({ name: "Alice", age: 30 }, { space: 2 }))
2160
- * // {
2161
- * // "name": "Alice",
2162
- * // "age": 30
2163
- * // }
2164
- * ```
2165
- *
2166
- * @see {@link format}
2167
- * @see {@link Formatter}
2168
- * @category serialization
2169
- * @since 4.0.0
2170
- */
2171
- function formatJson(input, options) {
2172
- const ancestors = [];
2173
- return JSON.stringify(input, function(_key, value) {
2174
- const redacted = redact(value);
2175
- if (typeof redacted !== "object" || redacted === null) return redacted;
2176
- while (ancestors.length > 0 && ancestors[ancestors.length - 1] !== this) ancestors.pop();
2177
- if (ancestors.includes(redacted)) return;
2178
- ancestors.push(redacted);
2179
- return redacted;
2180
- }, options?.space);
2181
- }
2182
- //#endregion
2183
- //#region node_modules/.pnpm/effect@4.0.0-beta.78/node_modules/effect/dist/Inspectable.js
2184
- /**
2185
- * Inspection protocol for stable string, JSON, and Node.js representations.
2186
- *
2187
- * This module is the small bridge used by Effect data types to explain
2188
- * themselves in logs, REPLs, test failures, and JSON-like diagnostics. Implement
2189
- * `Inspectable` or extend {@link Class} when a value should expose one
2190
- * representation to `toString`, `toJSON`, and Node's `util.inspect`; use
2191
- * {@link toJson} and {@link toStringUnknown} when formatting values supplied by
2192
- * user code.
2193
- *
2194
- * ## Mental model
2195
- *
2196
- * Inspectable values choose their own JSON representation. {@link BaseProto}
2197
- * and {@link Class} derive `toString()` from that representation with the
2198
- * formatter and expose the same value through {@link NodeInspectSymbol}.
2199
- * {@link toJson} is defensive: it calls zero-argument `toJSON` methods,
2200
- * recurses through arrays, returns `"[toJSON threw]"` if a custom serializer
2201
- * fails, and applies redaction to other values.
2202
- *
2203
- * ## Common tasks
2204
- *
2205
- * - Extend {@link Class} for classes that only need to define `toJSON`.
2206
- * - Reuse {@link BaseProto} for object prototypes that should share standard
2207
- * inspection behavior.
2208
- * - Format unknown diagnostic values with {@link toStringUnknown}.
2209
- * - Implement {@link NodeInspectSymbol} when integrating directly with
2210
- * Node.js inspection.
2211
- *
2212
- * ## Gotchas
2213
- *
2214
- * `toJson` is meant for inspection, not canonical persistence. It catches
2215
- * `toJSON` failures, does not deeply traverse arbitrary objects, and may
2216
- * replace redactable values according to current redaction behavior. Keep
2217
- * custom `toJSON` implementations side-effect free so logging and debugging do
2218
- * not change program state.
2219
- *
2220
- * **Example** (Creating inspectable values)
2221
- *
2222
- * ```ts
2223
- * import { Inspectable } from "effect"
2224
- *
2225
- * class User extends Inspectable.Class {
2226
- * constructor(
2227
- * readonly id: number,
2228
- * readonly name: string
2229
- * ) {
2230
- * super()
2231
- * }
2232
- *
2233
- * toJSON() {
2234
- * return {
2235
- * _tag: "User",
2236
- * id: this.id,
2237
- * name: this.name,
2238
- * }
2239
- * }
2240
- * }
2241
- *
2242
- * const user = new User(1, "Alice")
2243
- * console.log(user.toString())
2244
- * console.log(user[Inspectable.NodeInspectSymbol]())
2245
- * ```
2246
- *
2247
- * @since 2.0.0
2248
- */
2249
- /**
2250
- * Defines the symbol used by Node.js for custom object inspection.
2251
- *
2252
- * **When to use**
2253
- *
2254
- * Use to implement Node.js custom inspection for a value.
2255
- *
2256
- * **Details**
2257
- *
2258
- * This symbol is recognized by Node.js's `util.inspect()` function and the REPL
2259
- * for custom object representation. When an object has a method with this symbol,
2260
- * it will be called to determine how the object should be displayed.
2261
- *
2262
- * **Example** (Defining custom Node inspection)
2263
- *
2264
- * ```ts
2265
- * import { Inspectable } from "effect"
2266
- *
2267
- * class CustomObject {
2268
- * constructor(private value: string) {}
2269
- *
2270
- * [Inspectable.NodeInspectSymbol]() {
2271
- * return `CustomObject(${this.value})`
2272
- * }
2273
- * }
2274
- *
2275
- * const obj = new CustomObject("hello")
2276
- * console.log(obj) // Displays: CustomObject(hello)
2277
- * ```
2278
- *
2279
- * @category symbols
2280
- * @since 2.0.0
2281
- */
2282
- const NodeInspectSymbol = /*#__PURE__*/ Symbol.for("nodejs.util.inspect.custom");
2283
- /**
2284
- * Converts a value to a JSON-serializable representation safely.
2285
- *
2286
- * **When to use**
2287
- *
2288
- * Use when you need a safe, JSON-serializable representation of a value
2289
- * without risking unhandled errors.
2290
- *
2291
- * **Details**
2292
- *
2293
- * This function attempts to extract JSON data from objects that implement the
2294
- * `toJSON` method, recursively processes arrays, and handles errors gracefully.
2295
- * For objects that don't have a `toJSON` method, it applies redaction to
2296
- * protect sensitive information.
2297
- *
2298
- * @see {@link toStringUnknown} for converting unknown values to strings
2299
- *
2300
- * @category converting
2301
- * @since 4.0.0
2302
- */
2303
- const toJson = (input) => {
2304
- try {
2305
- if (hasProperty(input, "toJSON") && isFunction(input["toJSON"]) && input["toJSON"].length === 0) return input.toJSON();
2306
- else if (Array.isArray(input)) return input.map(toJson);
2307
- } catch {
2308
- return "[toJSON threw]";
2309
- }
2310
- return redact(input);
2311
- };
2312
- /**
2313
- * Converts an unknown value to a string for diagnostics.
2314
- *
2315
- * **When to use**
2316
- *
2317
- * Use to produce a diagnostic string from a value whose runtime type is unknown.
2318
- *
2319
- * **Details**
2320
- *
2321
- * Strings are returned unchanged. Objects are formatted as JSON using the
2322
- * provided whitespace setting when possible, and values that cannot be
2323
- * formatted are converted with `String`.
2324
- *
2325
- * @category converting
2326
- * @since 2.0.0
2327
- */
2328
- const toStringUnknown = (u, whitespace = 2) => {
2329
- if (typeof u === "string") return u;
2330
- try {
2331
- return typeof u === "object" ? formatJson(u, { space: whitespace }) : String(u);
2332
- } catch {
2333
- return String(u);
2334
- }
2335
- };
2336
- /**
2337
- * A base prototype object that implements the {@link Inspectable} interface.
2338
- *
2339
- * **When to use**
2340
- *
2341
- * Use as a prototype for plain objects that should share standard inspectable behavior.
2342
- *
2343
- * **Details**
2344
- *
2345
- * This object provides default implementations for the {@link Inspectable} methods.
2346
- * It can be used as a prototype for objects that want to be inspectable,
2347
- * or as a mixin to add inspection capabilities to existing objects.
2348
- *
2349
- * **Example** (Using the base inspectable prototype)
2350
- *
2351
- * ```ts
2352
- * import { Inspectable } from "effect"
2353
- *
2354
- * // Use as prototype
2355
- * const myObject = Object.create(Inspectable.BaseProto)
2356
- * myObject.name = "example"
2357
- * myObject.value = 42
2358
- *
2359
- * console.log(myObject.toString()) // Pretty printed representation
2360
- *
2361
- * // Or extend in a constructor
2362
- * function MyClass(this: any, name: string) {
2363
- * this.name = name
2364
- * }
2365
- * MyClass.prototype = Object.create(Inspectable.BaseProto)
2366
- * MyClass.prototype.constructor = MyClass
2367
- * ```
2368
- *
2369
- * @category prototypes
2370
- * @since 2.0.0
2371
- */
2372
- const BaseProto = {
2373
- toJSON() {
2374
- return toJson(this);
2375
- },
2376
- [NodeInspectSymbol]() {
2377
- return this.toJSON();
2378
- },
2379
- toString() {
2380
- return format(this.toJSON());
2381
- }
2382
- };
2383
- /**
2384
- * Provides an abstract base class that implements the Inspectable interface.
2385
- *
2386
- * **When to use**
2387
- *
2388
- * Use as a base class for inspectable objects that define their own JSON representation.
2389
- *
2390
- * **Details**
2391
- *
2392
- * This class provides a convenient way to create inspectable objects by extending it.
2393
- * Subclasses only need to implement the `toJSON()` method, and they automatically
2394
- * get proper `toString()` and Node.js inspection support.
2395
- *
2396
- * **Example** (Extending the inspectable base class)
2397
- *
2398
- * ```ts
2399
- * import { Inspectable } from "effect"
2400
- *
2401
- * class User extends Inspectable.Class {
2402
- * constructor(
2403
- * public readonly id: number,
2404
- * public readonly name: string,
2405
- * public readonly email: string
2406
- * ) {
2407
- * super()
2408
- * }
2409
- *
2410
- * toJSON() {
2411
- * return {
2412
- * _tag: "User",
2413
- * id: this.id,
2414
- * name: this.name,
2415
- * email: this.email
2416
- * }
2417
- * }
2418
- * }
2419
- *
2420
- * const user = new User(1, "Alice", "alice@example.com")
2421
- * console.log(user.toString()) // Pretty printed JSON with _tag, id, name, email
2422
- * console.log(user) // In Node.js, shows the same formatted output
2423
- * ```
2424
- *
2425
- * @category classes
2426
- * @since 2.0.0
2427
- */
2428
- var Class = class {
2429
- /**
2430
- * Node.js custom inspection method.
2431
- *
2432
- * **When to use**
2433
- *
2434
- * Use to expose the class JSON representation to Node.js inspection.
2435
- *
2436
- * @since 2.0.0
2437
- */
2438
- [NodeInspectSymbol]() {
2439
- return this.toJSON();
2440
- }
2441
- /**
2442
- * Returns a formatted string representation of this object.
2443
- *
2444
- * **When to use**
2445
- *
2446
- * Use to format the class JSON representation as a string.
2447
- *
2448
- * @since 2.0.0
2449
- */
2450
- toString() {
2451
- return format(this.toJSON());
2452
- }
2453
- };
2454
- //#endregion
2455
- //#region node_modules/.pnpm/effect@4.0.0-beta.78/node_modules/effect/dist/Utils.js
2456
- /**
2457
- * Yields its wrapped value exactly once through an `IterableIterator`.
2458
- *
2459
- * **When to use**
2460
- *
2461
- * Use to implement `[Symbol.iterator]()` on Effect-like types so they can be
2462
- * `yield*`-ed inside generator functions, such as `Effect.gen` and
2463
- * `Option.gen`.
2464
- *
2465
- * **Details**
2466
- *
2467
- * The first call to `next()` returns `{ value: self, done: false }`. Every
2468
- * subsequent call returns `{ value: a, done: true }` where `a` is the argument
2469
- * passed to `next()`. `[Symbol.iterator]()` returns a **new** `SingleShotGen`
2470
- * wrapping the same value, so the outer type can be iterated multiple times.
2471
- *
2472
- * **Example** (Yielding a wrapped value in a generator)
2473
- *
2474
- * ```ts
2475
- * import { Utils } from "effect"
2476
- *
2477
- * const gen = new Utils.SingleShotGen<string, number>("hello")
2478
- *
2479
- * // First call yields the wrapped value
2480
- * console.log(gen.next(0))
2481
- * // { value: "hello", done: false }
2482
- *
2483
- * // Second call signals completion with the provided value
2484
- * console.log(gen.next(42))
2485
- * // { value: 42, done: true }
2486
- * ```
2487
- *
2488
- * @see {@link Gen} for the type-level signature that relies on `SingleShotGen`
2489
- * @category constructors
2490
- * @since 2.0.0
2491
- */
2492
- var SingleShotGen = class SingleShotGen {
2493
- called = false;
2494
- self;
2495
- constructor(self) {
2496
- this.self = self;
2497
- }
2498
- /**
2499
- * Yields the stored value once, then completes with the value sent back in.
2500
- *
2501
- * **When to use**
2502
- *
2503
- * Use to advance a `SingleShotGen` through its single yield and completion
2504
- * step.
2505
- *
2506
- * @since 2.0.0
2507
- */
2508
- next(a) {
2509
- return this.called ? {
2510
- value: a,
2511
- done: true
2512
- } : (this.called = true, {
2513
- value: this.self,
2514
- done: false
2515
- });
2516
- }
2517
- /**
2518
- * Creates a fresh single-shot iterator over the stored value.
2519
- *
2520
- * **When to use**
2521
- *
2522
- * Use to iterate the wrapped value again without reusing the consumed
2523
- * iterator state.
2524
- *
2525
- * @since 2.0.0
2526
- */
2527
- [Symbol.iterator]() {
2528
- return new SingleShotGen(this.self);
2529
- }
2530
- };
2531
- const InternalTypeId = "~effect/Utils/internal";
2532
- const standard = { [InternalTypeId]: (body) => {
2533
- return body();
2534
- } };
2535
- const forced = { [InternalTypeId]: (body) => {
2536
- try {
2537
- return body();
2538
- } finally {}
2539
- } };
2540
- /** @internal */
2541
- const internalCall = /*#__PURE__*/ standard[InternalTypeId](() => (/* @__PURE__ */ new Error()).stack)?.includes(InternalTypeId) === true ? standard[InternalTypeId] : forced[InternalTypeId];
2542
- //#endregion
2543
- //#region node_modules/.pnpm/effect@4.0.0-beta.78/node_modules/effect/dist/internal/core.js
2544
- /** @internal */
2545
- const EffectTypeId = `~effect/Effect`;
2546
- /** @internal */
2547
- const ExitTypeId = `~effect/Exit`;
2548
- const effectVariance = {
2549
- _A: identity,
2550
- _E: identity,
2551
- _R: identity
2552
- };
2553
- /** @internal */
2554
- const identifier = `${EffectTypeId}/identifier`;
2555
- /** @internal */
2556
- const args = `${EffectTypeId}/args`;
2557
- /** @internal */
2558
- const evaluate = `${EffectTypeId}/evaluate`;
2559
- /** @internal */
2560
- const contA = `${EffectTypeId}/successCont`;
2561
- /** @internal */
2562
- const contE = `${EffectTypeId}/failureCont`;
2563
- /** @internal */
2564
- const contAll = `${EffectTypeId}/ensureCont`;
2565
- /** @internal */
2566
- const Yield = /*#__PURE__*/ Symbol.for("effect/Effect/Yield");
2567
- /** @internal */
2568
- const PipeInspectableProto = {
2569
- pipe() {
2570
- return pipeArguments(this, arguments);
2571
- },
2572
- toJSON() {
2573
- return { ...this };
2574
- },
2575
- toString() {
2576
- return format(this.toJSON(), {
2577
- ignoreToString: true,
2578
- space: 2
2579
- });
2580
- },
2581
- [NodeInspectSymbol]() {
2582
- return this.toJSON();
2583
- }
2584
- };
2585
- /** @internal */
2586
- const EffectProto = {
2587
- [EffectTypeId]: effectVariance,
2588
- ...PipeInspectableProto,
2589
- [Symbol.iterator]() {
2590
- return new SingleShotGen(this);
2591
- },
2592
- toJSON() {
2593
- return {
2594
- _id: "Effect",
2595
- op: this[identifier],
2596
- ...args in this ? { args: this[args] } : void 0
2597
- };
2598
- }
2599
- };
2600
- /** @internal */
2601
- const isEffect = (u) => hasProperty(u, EffectTypeId);
2602
- /** @internal */
2603
- const isExit = (u) => hasProperty(u, ExitTypeId);
2604
- /** @internal */
2605
- const CauseTypeId = "~effect/Cause";
2606
- /** @internal */
2607
- const CauseReasonTypeId = "~effect/Cause/Reason";
2608
- /** @internal */
2609
- const isCause = (self) => hasProperty(self, CauseTypeId);
2610
- /** @internal */
2611
- const isCauseReason = (self) => hasProperty(self, CauseReasonTypeId);
2612
- /** @internal */
2613
- var CauseImpl = class {
2614
- [CauseTypeId];
2615
- reasons;
2616
- constructor(failures) {
2617
- this[CauseTypeId] = CauseTypeId;
2618
- this.reasons = failures;
2619
- }
2620
- pipe() {
2621
- return pipeArguments(this, arguments);
2622
- }
2623
- toJSON() {
2624
- return {
2625
- _id: "Cause",
2626
- failures: this.reasons.map((f) => f.toJSON())
2627
- };
2628
- }
2629
- toString() {
2630
- return `Cause(${format(this.reasons)})`;
2631
- }
2632
- [NodeInspectSymbol]() {
2633
- return this.toJSON();
2634
- }
2635
- [symbol](that) {
2636
- return isCause(that) && this.reasons.length === that.reasons.length && this.reasons.every((e, i) => equals(e, that.reasons[i]));
2637
- }
2638
- [symbol$1]() {
2639
- return array(this.reasons);
2640
- }
2641
- };
2642
- const annotationsMap = /*#__PURE__*/ new WeakMap();
2643
- /** @internal */
2644
- var ReasonBase = class {
2645
- [CauseReasonTypeId];
2646
- annotations;
2647
- _tag;
2648
- constructor(_tag, annotations, originalError) {
2649
- this[CauseReasonTypeId] = CauseReasonTypeId;
2650
- this._tag = _tag;
2651
- if (annotations !== constEmptyAnnotations && typeof originalError === "object" && originalError !== null && annotations.size > 0) {
2652
- const prevAnnotations = annotationsMap.get(originalError);
2653
- if (prevAnnotations) annotations = new Map([...prevAnnotations, ...annotations]);
2654
- annotationsMap.set(originalError, annotations);
2655
- }
2656
- this.annotations = annotations;
2657
- }
2658
- annotate(annotations, options) {
2659
- if (annotations.mapUnsafe.size === 0) return this;
2660
- const newAnnotations = new Map(this.annotations);
2661
- annotations.mapUnsafe.forEach((value, key) => {
2662
- if (options?.overwrite !== true && newAnnotations.has(key)) return;
2663
- newAnnotations.set(key, value);
2664
- });
2665
- const self = Object.assign(Object.create(Object.getPrototypeOf(this)), this);
2666
- self.annotations = newAnnotations;
2667
- return self;
2668
- }
2669
- pipe() {
2670
- return pipeArguments(this, arguments);
2671
- }
2672
- toString() {
2673
- return format(this);
2674
- }
2675
- [NodeInspectSymbol]() {
2676
- return this.toString();
2677
- }
2678
- };
2679
- /** @internal */
2680
- const constEmptyAnnotations = /*#__PURE__*/ new Map();
2681
- /** @internal */
2682
- var Fail = class extends ReasonBase {
2683
- error;
2684
- constructor(error, annotations = constEmptyAnnotations) {
2685
- super("Fail", annotations, error);
2686
- this.error = error;
2687
- }
2688
- toString() {
2689
- return `Fail(${format(this.error)})`;
2690
- }
2691
- toJSON() {
2692
- return {
2693
- _tag: "Fail",
2694
- error: this.error
2695
- };
2696
- }
2697
- [symbol](that) {
2698
- return isFailReason(that) && equals(this.error, that.error) && equals(this.annotations, that.annotations);
2699
- }
2700
- [symbol$1]() {
2701
- return combine(string(this._tag))(combine(hash(this.error))(hash(this.annotations)));
2702
- }
2703
- };
2704
- /** @internal */
2705
- const causeFromReasons = (reasons) => new CauseImpl(reasons);
2706
- /** @internal */
2707
- const causeEmpty = /*#__PURE__*/ new CauseImpl([]);
2708
- /** @internal */
2709
- const causeFail = (error) => new CauseImpl([new Fail(error)]);
2710
- /** @internal */
2711
- var Die = class extends ReasonBase {
2712
- defect;
2713
- constructor(defect, annotations = constEmptyAnnotations) {
2714
- super("Die", annotations, defect);
2715
- this.defect = defect;
2716
- }
2717
- toString() {
2718
- return `Die(${format(this.defect)})`;
2719
- }
2720
- toJSON() {
2721
- return {
2722
- _tag: "Die",
2723
- defect: this.defect
2724
- };
2725
- }
2726
- [symbol](that) {
2727
- return isDieReason(that) && equals(this.defect, that.defect) && equals(this.annotations, that.annotations);
2728
- }
2729
- [symbol$1]() {
2730
- return combine(string(this._tag))(combine(hash(this.defect))(hash(this.annotations)));
2731
- }
2732
- };
2733
- /** @internal */
2734
- const causeDie = (defect) => new CauseImpl([new Die(defect)]);
2735
- /** @internal */
2736
- const causeAnnotate = /*#__PURE__*/ dual((args) => isCause(args[0]), (self, annotations, options) => {
2737
- if (annotations.mapUnsafe.size === 0) return self;
2738
- return new CauseImpl(self.reasons.map((f) => f.annotate(annotations, options)));
2739
- });
2740
- /** @internal */
2741
- const isFailReason = (self) => self._tag === "Fail";
2742
- /** @internal */
2743
- const isDieReason = (self) => self._tag === "Die";
2744
- /** @internal */
2745
- const isInterruptReason = (self) => self._tag === "Interrupt";
2746
- function defaultEvaluate(_fiber) {
2747
- return exitDie(`Effect.evaluate: Not implemented`);
2748
- }
2749
- /** @internal */
2750
- const makePrimitiveProto = (options) => ({
2751
- ...EffectProto,
2752
- [identifier]: options.op,
2753
- [evaluate]: options[evaluate] ?? defaultEvaluate,
2754
- [contA]: options[contA],
2755
- [contE]: options[contE],
2756
- [contAll]: options[contAll]
2757
- });
2758
- /** @internal */
2759
- const makePrimitive = (options) => {
2760
- const Proto = makePrimitiveProto(options);
2761
- return function() {
2762
- const self = Object.create(Proto);
2763
- self[args] = options.single === false ? arguments : arguments[0];
2764
- return self;
2765
- };
2766
- };
2767
- /** @internal */
2768
- const makeExit = (options) => {
2769
- const Proto = {
2770
- ...makePrimitiveProto(options),
2771
- [ExitTypeId]: ExitTypeId,
2772
- _tag: options.op,
2773
- get [options.prop]() {
2774
- return this[args];
2775
- },
2776
- toString() {
2777
- return `${options.op}(${format(this[args])})`;
2778
- },
2779
- toJSON() {
2780
- return {
2781
- _id: "Exit",
2782
- _tag: options.op,
2783
- [options.prop]: this[args]
2784
- };
2785
- },
2786
- [symbol](that) {
2787
- return isExit(that) && that._tag === this._tag && equals(this[args], that[args]);
2788
- },
2789
- [symbol$1]() {
2790
- return combine(string(options.op), hash(this[args]));
2791
- }
2792
- };
2793
- return function(value) {
2794
- const self = Object.create(Proto);
2795
- self[args] = value;
2796
- return self;
2797
- };
2798
- };
2799
- /** @internal */
2800
- const exitSucceed = /*#__PURE__*/ makeExit({
2801
- op: "Success",
2802
- prop: "value",
2803
- [evaluate](fiber) {
2804
- const cont = fiber.getCont(contA);
2805
- return cont ? cont[contA](this[args], fiber, this) : fiber.yieldWith(this);
2806
- }
2807
- });
2808
- /** @internal */
2809
- const StackTraceKey = { key: "effect/Cause/StackTrace" };
2810
- /** @internal */
2811
- const InterruptorStackTrace = { key: "effect/Cause/InterruptorStackTrace" };
2812
- /** @internal */
2813
- const exitFailCause = /*#__PURE__*/ makeExit({
2814
- op: "Failure",
2815
- prop: "cause",
2816
- [evaluate](fiber) {
2817
- let cause = this[args];
2818
- let annotated = false;
2819
- if (fiber.currentStackFrame) {
2820
- cause = causeAnnotate(cause, { mapUnsafe: new Map([[StackTraceKey.key, fiber.currentStackFrame]]) });
2821
- annotated = true;
2822
- }
2823
- let cont = fiber.getCont(contE);
2824
- while (fiber.interruptible && fiber._interruptedCause && cont) cont = fiber.getCont(contE);
2825
- return cont ? cont[contE](cause, fiber, annotated ? void 0 : this) : fiber.yieldWith(annotated ? this : exitFailCause(cause));
2826
- }
2827
- });
2828
- /** @internal */
2829
- const exitFail = (e) => exitFailCause(causeFail(e));
2830
- /** @internal */
2831
- const exitDie = (defect) => exitFailCause(causeDie(defect));
2832
- /** @internal */
2833
- const withFiber = /*#__PURE__*/ makePrimitive({
2834
- op: "WithFiber",
2835
- [evaluate](fiber) {
2836
- return this[args](fiber);
2837
- }
2838
- });
2839
- /** @internal */
2840
- const YieldableError = /*#__PURE__*/ function() {
2841
- class YieldableError extends globalThis.Error {}
2842
- const proto = /*#__PURE__*/ makePrimitiveProto({
2843
- op: "YieldableError",
2844
- [evaluate]() {
2845
- return exitFail(this);
2846
- }
2847
- });
2848
- delete proto.toString;
2849
- Object.assign(YieldableError.prototype, proto);
2850
- return YieldableError;
2851
- }();
2852
- /** @internal */
2853
- const Error$1 = /*#__PURE__*/ function() {
2854
- const plainArgsSymbol = /*#__PURE__*/ Symbol.for("effect/Data/Error/plainArgs");
2855
- return class Base extends YieldableError {
2856
- constructor(args) {
2857
- super(args?.message, args?.cause ? { cause: args.cause } : void 0);
2858
- if (args) {
2859
- Object.assign(this, args);
2860
- Object.defineProperty(this, plainArgsSymbol, {
2861
- value: args,
2862
- enumerable: false
2863
- });
2864
- }
2865
- }
2866
- toJSON() {
2867
- return {
2868
- ...this[plainArgsSymbol],
2869
- ...this
2870
- };
2871
- }
2872
- };
2873
- }();
2874
- /** @internal */
2875
- const TaggedError = (tag) => {
2876
- class Base extends Error$1 {
2877
- _tag = tag;
2878
- }
2879
- Base.prototype.name = tag;
2880
- return Base;
2881
- };
2882
- TaggedError("NoSuchElementError");
2883
- /** @internal */
2884
- const DoneTypeId = "~effect/Cause/Done";
2885
- /** @internal */
2886
- const isDone = (u) => hasProperty(u, DoneTypeId);
2887
- const DoneVoid = {
2888
- [DoneTypeId]: DoneTypeId,
2889
- _tag: "Done",
2890
- value: void 0
2891
- };
2892
- /** @internal */
2893
- const Done = (value) => {
2894
- if (value === void 0) return DoneVoid;
2895
- return {
2896
- [DoneTypeId]: DoneTypeId,
2897
- _tag: "Done",
2898
- value
2899
- };
2900
- };
2901
- const doneVoid = /*#__PURE__*/ exitFail(DoneVoid);
2902
- /** @internal */
2903
- const done = (value) => {
2904
- if (value === void 0) return doneVoid;
2905
- return exitFail(Done(value));
2906
- };
2907
- //#endregion
2908
- //#region node_modules/.pnpm/effect@4.0.0-beta.78/node_modules/effect/dist/Effectable.js
2909
- /**
2910
- * Create a low-level `Effect` prototype.
2911
- *
2912
- * **When to use**
2913
- *
2914
- * Use when you need to create a custom Effect-like value without extending a
2915
- * class, by providing a label and an evaluate function that receives the
2916
- * current fiber.
2917
- *
2918
- * **Details**
2919
- *
2920
- * When the effect is evaluated, it calls `evaluate` with the current fiber.
2921
- *
2922
- * @see {@link Class} for a class-based approach to defining custom Effect values
2923
- *
2924
- * @category prototypes
2925
- * @since 4.0.0
2926
- */
2927
- const Prototype = (options) => makePrimitiveProto({
2928
- op: options.label,
2929
- [evaluate]: options.evaluate
2930
- });
2931
- //#endregion
2932
- //#region node_modules/.pnpm/effect@4.0.0-beta.78/node_modules/effect/dist/Equivalence.js
2933
- /**
2934
- * Creates a custom equivalence relation with an optimized reference equality check.
2935
- *
2936
- * **When to use**
2937
- *
2938
- * Use when you need an equality rule that the built-in instances and input
2939
- * mapping helpers cannot express, and you can provide a law-abiding comparison.
2940
- *
2941
- * **Details**
2942
- *
2943
- * The returned equivalence first checks reference equality (`===`) for
2944
- * performance. If the values are not the same reference, it falls back to the
2945
- * provided equivalence function, which must satisfy reflexive, symmetric, and
2946
- * transitive properties.
2947
- *
2948
- * **Example** (Case-insensitive string equivalence)
2949
- *
2950
- * ```ts
2951
- * import { Equivalence } from "effect"
2952
- *
2953
- * const caseInsensitive = Equivalence.make<string>((a, b) =>
2954
- * a.toLowerCase() === b.toLowerCase()
2955
- * )
2956
- *
2957
- * console.log(caseInsensitive("Hello", "HELLO")) // true
2958
- * console.log(caseInsensitive("foo", "bar")) // false
2959
- *
2960
- * // Same reference optimization
2961
- * const str = "test"
2962
- * console.log(caseInsensitive(str, str)) // true (fast path)
2963
- * ```
2964
- *
2965
- * **Example** (Numeric tolerance equivalence)
2966
- *
2967
- * ```ts
2968
- * import { Equivalence } from "effect"
2969
- *
2970
- * const tolerance = Equivalence.make<number>((a, b) => Math.abs(a - b) < 0.0001)
2971
- *
2972
- * console.log(tolerance(1.0, 1.001)) // false
2973
- * console.log(tolerance(1.0, 1.00001)) // true
2974
- * ```
2975
- *
2976
- * @see {@link strictEqual}
2977
- * @see {@link mapInput}
2978
- * @category constructors
2979
- * @since 2.0.0
2980
- */
2981
- const make$2 = (isEquivalent) => (self, that) => self === that || isEquivalent(self, that);
2982
- const isStrictEquivalent = (x, y) => x === y;
2983
- /**
2984
- * Creates an equivalence relation that uses strict equality (`===`) to compare values.
2985
- *
2986
- * **When to use**
2987
- *
2988
- * Use when you need strict equality (`===`) as the comparison.
2989
- *
2990
- * **Details**
2991
- *
2992
- * Uses JavaScript's strict equality operator (`===`). Primitives compare by
2993
- * value. Objects compare by reference, so only the same object instance is
2994
- * equivalent. Use this as a building block for more complex equivalences via
2995
- * `mapInput` or `combine`.
2996
- *
2997
- * **Gotchas**
2998
- *
2999
- * `NaN !== NaN`, so `NaN` values are never considered equivalent.
3000
- *
3001
- * **Example** (Primitive types)
3002
- *
3003
- * ```ts
3004
- * import { Equivalence } from "effect"
3005
- *
3006
- * const strictEq = Equivalence.strictEqual<number>()
3007
- *
3008
- * console.log(strictEq(1, 1)) // true
3009
- * console.log(strictEq(1, 2)) // false
3010
- * console.log(strictEq(NaN, NaN)) // false (NaN !== NaN)
3011
- * ```
3012
- *
3013
- * **Example** (Reference equality for objects)
3014
- *
3015
- * ```ts
3016
- * import { Equivalence } from "effect"
3017
- *
3018
- * const obj = { value: 42 }
3019
- * const strictObjEq = Equivalence.strictEqual<typeof obj>()
3020
- *
3021
- * console.log(strictObjEq(obj, obj)) // true
3022
- * console.log(strictObjEq(obj, { value: 42 })) // false (different references)
3023
- * ```
3024
- *
3025
- * @see {@link make}
3026
- * @see `Equal` for structural equality
3027
- * @category constructors
3028
- * @since 4.0.0
3029
- */
3030
- const strictEqual = () => isStrictEquivalent;
3031
- /**
3032
- * Creates an equivalence for tuples with heterogeneous element types.
3033
- *
3034
- * **When to use**
3035
- *
3036
- * Use when you need an `Equivalence` for fixed-length tuples with per-position
3037
- * equivalences.
3038
- *
3039
- * **Details**
3040
- *
3041
- * Tuples must have the same length; different lengths are never equivalent.
3042
- * Each equivalence is applied to the corresponding element position. The result
3043
- * returns `true` only if all elements are equivalent according to their
3044
- * respective equivalences, and it also satisfies reflexive, symmetric, and
3045
- * transitive properties.
3046
- *
3047
- * **Example** (Homogeneous tuple equivalence)
3048
- *
3049
- * ```ts
3050
- * import { Equivalence } from "effect"
3051
- *
3052
- * const stringTupleEq = Equivalence.Tuple([
3053
- * Equivalence.strictEqual<string>(),
3054
- * Equivalence.strictEqual<string>(),
3055
- * Equivalence.strictEqual<string>()
3056
- * ])
3057
- *
3058
- * const tuple1 = ["hello", "world", "test"] as const
3059
- * const tuple2 = ["hello", "world", "test"] as const
3060
- * const tuple3 = ["hello", "world", "different"] as const
3061
- *
3062
- * console.log(stringTupleEq(tuple1, tuple2)) // true
3063
- * console.log(stringTupleEq(tuple1, tuple3)) // false (different third element)
3064
- * ```
3065
- *
3066
- * **Example** (Tuple with custom equivalences)
3067
- *
3068
- * ```ts
3069
- * import { Equivalence } from "effect"
3070
- *
3071
- * const caseInsensitive = Equivalence.mapInput(
3072
- * Equivalence.strictEqual<string>(),
3073
- * (s: string) => s.toLowerCase()
3074
- * )
3075
- *
3076
- * const customTupleEq = Equivalence.Tuple([
3077
- * caseInsensitive,
3078
- * caseInsensitive,
3079
- * caseInsensitive
3080
- * ])
3081
- *
3082
- * console.log(
3083
- * customTupleEq(["Hello", "World", "Test"], ["HELLO", "WORLD", "TEST"])
3084
- * ) // true
3085
- * ```
3086
- *
3087
- * @category combinators
3088
- * @since 4.0.0
3089
- */
3090
- function Tuple(elements) {
3091
- return make$2((self, that) => {
3092
- if (self.length !== that.length) return false;
3093
- for (let i = 0; i < self.length; i++) if (!elements[i](self[i], that[i])) return false;
3094
- return true;
3095
- });
3096
- }
3097
- /**
3098
- * @since 4.0.0
3099
- */
3100
- function Array_(item) {
3101
- return make$2((self, that) => {
3102
- if (self.length !== that.length) return false;
3103
- for (let i = 0; i < self.length; i++) if (!item(self[i], that[i])) return false;
3104
- return true;
3105
- });
3106
- }
3107
- //#endregion
3108
- //#region node_modules/.pnpm/effect@4.0.0-beta.78/node_modules/effect/dist/internal/option.js
3109
- /**
3110
- * @since 2.0.0
3111
- */
3112
- const TypeId$2 = "~effect/data/Option";
3113
- const CommonProto$1 = {
3114
- [TypeId$2]: { _A: (_) => _ },
3115
- ...PipeInspectableProto,
3116
- [Symbol.iterator]() {
3117
- return new SingleShotGen(this);
3118
- }
3119
- };
3120
- const SomeProto = /*#__PURE__*/ Object.assign(/*#__PURE__*/ Object.create(CommonProto$1), {
3121
- _tag: "Some",
3122
- _op: "Some",
3123
- [symbol](that) {
3124
- return isOption$1(that) && isSome$1(that) && equals(this.value, that.value);
3125
- },
3126
- [symbol$1]() {
3127
- return combine(hash(this._tag))(hash(this.value));
3128
- },
3129
- toString() {
3130
- return `some(${format(this.value)})`;
3131
- },
3132
- toJSON() {
3133
- return {
3134
- _id: "Option",
3135
- _tag: this._tag,
3136
- value: toJson(this.value)
3137
- };
3138
- }
3139
- });
3140
- Object.defineProperty(SomeProto, "valueOrUndefined", { get() {
3141
- return this.value;
3142
- } });
3143
- const NoneHash = /*#__PURE__*/ hash("None");
3144
- const NoneProto = /*#__PURE__*/ Object.assign(/*#__PURE__*/ Object.create(CommonProto$1), {
3145
- _tag: "None",
3146
- _op: "None",
3147
- valueOrUndefined: void 0,
3148
- [symbol](that) {
3149
- return isOption$1(that) && isNone$1(that);
3150
- },
3151
- [symbol$1]() {
3152
- return NoneHash;
3153
- },
3154
- toString() {
3155
- return `none()`;
3156
- },
3157
- toJSON() {
3158
- return {
3159
- _id: "Option",
3160
- _tag: this._tag
3161
- };
3162
- }
3163
- });
3164
- /** @internal */
3165
- const isOption$1 = (input) => hasProperty(input, TypeId$2);
3166
- /** @internal */
3167
- const isNone$1 = (fa) => fa._tag === "None";
3168
- /** @internal */
3169
- const isSome$1 = (fa) => fa._tag === "Some";
3170
- /** @internal */
3171
- const none$1 = /*#__PURE__*/ Object.create(NoneProto);
3172
- /** @internal */
3173
- const some$1 = (value) => {
3174
- const a = Object.create(SomeProto);
3175
- a.value = value;
3176
- return a;
3177
- };
3178
- //#endregion
3179
- //#region node_modules/.pnpm/effect@4.0.0-beta.78/node_modules/effect/dist/internal/result.js
3180
- const TypeId$1 = "~effect/data/Result";
3181
- const CommonProto = {
3182
- [TypeId$1]: {
3183
- /* v8 ignore next 2 */
3184
- _A: (_) => _,
3185
- _E: (_) => _
3186
- },
3187
- ...PipeInspectableProto,
3188
- [Symbol.iterator]() {
3189
- return new SingleShotGen(this);
3190
- }
3191
- };
3192
- const SuccessProto = /*#__PURE__*/ Object.assign(/*#__PURE__*/ Object.create(CommonProto), {
3193
- _tag: "Success",
3194
- _op: "Success",
3195
- [symbol](that) {
3196
- return isResult(that) && isSuccess(that) && equals(this.success, that.success);
3197
- },
3198
- [symbol$1]() {
3199
- return combine(hash(this._tag))(hash(this.success));
3200
- },
3201
- toString() {
3202
- return `success(${format(this.success)})`;
3203
- },
3204
- toJSON() {
3205
- return {
3206
- _id: "Result",
3207
- _tag: this._tag,
3208
- value: toJson(this.success)
3209
- };
3210
- }
3211
- });
3212
- const FailureProto = /*#__PURE__*/ Object.assign(/*#__PURE__*/ Object.create(CommonProto), {
3213
- _tag: "Failure",
3214
- _op: "Failure",
3215
- [symbol](that) {
3216
- return isResult(that) && isFailure(that) && equals(this.failure, that.failure);
3217
- },
3218
- [symbol$1]() {
3219
- return combine(hash(this._tag))(hash(this.failure));
3220
- },
3221
- toString() {
3222
- return `failure(${format(this.failure)})`;
3223
- },
3224
- toJSON() {
3225
- return {
3226
- _id: "Result",
3227
- _tag: this._tag,
3228
- failure: toJson(this.failure)
3229
- };
3230
- }
3231
- });
3232
- /** @internal */
3233
- const isResult = (input) => hasProperty(input, TypeId$1);
3234
- /** @internal */
3235
- const isFailure = (result) => result._tag === "Failure";
3236
- /** @internal */
3237
- const isSuccess = (result) => result._tag === "Success";
3238
- /** @internal */
3239
- const fail = (failure) => {
3240
- const a = Object.create(FailureProto);
3241
- a.failure = failure;
3242
- return a;
3243
- };
3244
- /** @internal */
3245
- const succeed = (success) => {
3246
- const a = Object.create(SuccessProto);
3247
- a.success = success;
3248
- return a;
3249
- };
3250
- //#endregion
3251
- //#region node_modules/.pnpm/effect@4.0.0-beta.78/node_modules/effect/dist/Order.js
3252
- /**
3253
- * The `Order` module defines total orderings: pure comparison functions that
3254
- * decide whether one value is less than, equal to, or greater than another. An
3255
- * `Order<A>` returns a normalized {@link Ordering} (`-1`, `0`, or `1`), making
3256
- * it suitable for sorting, finding minimum and maximum values, range checks, and
3257
- * building ordered data structures.
3258
- *
3259
- * **Mental model**
3260
- *
3261
- * - An {@link Order} is a comparator with laws: totality, antisymmetry, and
3262
- * transitivity. If those laws do not hold, sorting and range operations can
3263
- * produce surprising results.
3264
- * - `-1` means the left value comes before the right value, `0` means they are
3265
- * equal for this ordering, and `1` means the left value comes after the right
3266
- * value.
3267
- * - Primitive orders such as {@link Number}, {@link String}, {@link Boolean},
3268
- * {@link BigInt}, and {@link Date} are building blocks.
3269
- * - Use {@link mapInput} to compare larger values by a field or derived key.
3270
- * - Use {@link combine} or {@link combineAll} for tie-breaking, where the first
3271
- * non-zero comparison result wins.
3272
- *
3273
- * **Common tasks**
3274
- *
3275
- * - Create a custom order from a comparison function with {@link make}.
3276
- * - Sort or compare using built-in orders such as {@link Number} and
3277
- * {@link String}.
3278
- * - Compare records and tuples with {@link Struct} and {@link Tuple}.
3279
- * - Compare arrays lexicographically with {@link Array}.
3280
- * - Convert an order into predicates with {@link isLessThan},
3281
- * {@link isGreaterThan}, {@link isLessThanOrEqualTo}, and
3282
- * {@link isGreaterThanOrEqualTo}.
3283
- * - Select boundaries with {@link min}, {@link max}, {@link clamp}, and
3284
- * {@link isBetween}.
3285
- *
3286
- * **Gotchas**
3287
- *
3288
- * - {@link make} returns `0` immediately when `self === that`; the custom
3289
- * comparison function is not called for identical references.
3290
- * - {@link Number} treats all `NaN` values as equal to each other and less than
3291
- * every non-`NaN` number.
3292
- * - {@link Array} compares elements first and length second. {@link Tuple}
3293
- * compares a fixed number of positions.
3294
- * - {@link Struct} compares fields in the key order of the object passed to it,
3295
- * so put the highest-priority fields first.
3296
- * - {@link min} and {@link max} return the first argument when two values
3297
- * compare as equal.
3298
- *
3299
- * **Example** (Sorting by multiple fields)
3300
- *
3301
- * ```ts
3302
- * import { Array, Order } from "effect"
3303
- *
3304
- * interface User {
3305
- * readonly name: string
3306
- * readonly age: number
3307
- * }
3308
- *
3309
- * const byAge = Order.mapInput(Order.Number, (user: User) => user.age)
3310
- * const byName = Order.mapInput(Order.String, (user: User) => user.name)
3311
- * const byAgeThenName = Order.combine(byAge, byName)
3312
- *
3313
- * const users = [
3314
- * { name: "Charlie", age: 30 },
3315
- * { name: "Bob", age: 25 },
3316
- * { name: "Alice", age: 30 }
3317
- * ]
3318
- *
3319
- * const sorted = Array.sort(users, byAgeThenName)
3320
- * console.log(sorted.map((user) => user.name))
3321
- * // ["Bob", "Alice", "Charlie"]
3322
- * ```
3323
- *
3324
- * **See also**
3325
- *
3326
- * - {@link Ordering} for the normalized comparison result type.
3327
- * - `Equivalence` for equality without less-than or greater-than.
3328
- * - {@link Reducer} for combining orders with reducer-style APIs.
3329
- *
3330
- * @since 2.0.0
3331
- */
3332
- /**
3333
- * Creates a new `Order` instance from a comparison function.
3334
- *
3335
- * **When to use**
3336
- *
3337
- * Use when you need a sorting rule not covered by the built-in orders or input
3338
- * mapping helpers, and you can provide a total comparison.
3339
- *
3340
- * **Details**
3341
- *
3342
- * Uses reference equality (`===`) as a shortcut: if `self === that`, it returns
3343
- * `0` without calling the comparison function. The comparison function should
3344
- * return `-1`, `0`, or `1`, and the returned order satisfies total ordering
3345
- * laws when the comparison function does.
3346
- *
3347
- * **Example** (Creating an Order)
3348
- *
3349
- * ```ts
3350
- * import { Order } from "effect"
3351
- *
3352
- * const byAge = Order.make<{ name: string; age: number }>((self, that) => {
3353
- * if (self.age < that.age) return -1
3354
- * if (self.age > that.age) return 1
3355
- * return 0
3356
- * })
3357
- *
3358
- * console.log(byAge({ name: "Alice", age: 30 }, { name: "Bob", age: 25 })) // 1
3359
- * console.log(byAge({ name: "Alice", age: 25 }, { name: "Bob", age: 30 })) // -1
3360
- * ```
3361
- *
3362
- * @see {@link mapInput} to transform an order by mapping the input type
3363
- * @see {@link combine} to combine multiple orders
3364
- * @category constructors
3365
- * @since 2.0.0
3366
- */
3367
- function make$1(compare) {
3368
- return (self, that) => self === that ? 0 : compare(self, that);
3369
- }
3370
- /**
3371
- * Order instance for numbers that compares them numerically.
3372
- *
3373
- * **When to use**
3374
- *
3375
- * Use when you need numeric ordering for numbers.
3376
- *
3377
- * **Details**
3378
- *
3379
- * `0` is considered equal to `-0`. All `NaN` values are considered equal to
3380
- * each other, and any `NaN` is considered less than any non-`NaN` number. All
3381
- * other values use standard numeric comparison.
3382
- *
3383
- * **Example** (Number Ordering)
3384
- *
3385
- * ```ts
3386
- * import { Order } from "effect"
3387
- *
3388
- * console.log(Order.Number(1, 1)) // 0
3389
- * console.log(Order.Number(1, 2)) // -1
3390
- * console.log(Order.Number(2, 1)) // 1
3391
- *
3392
- * console.log(Order.Number(0, -0)) // 0
3393
- * console.log(Order.Number(NaN, 1)) // -1
3394
- * ```
3395
- *
3396
- * @see {@link mapInput} to compare objects by a number property
3397
- * @see {@link BigInt} for bigint comparisons
3398
- * @category instances
3399
- * @since 4.0.0
3400
- */
3401
- const Number$1 = /*#__PURE__*/ make$1((self, that) => {
3402
- if (globalThis.Number.isNaN(self) && globalThis.Number.isNaN(that)) return 0;
3403
- if (globalThis.Number.isNaN(self)) return -1;
3404
- if (globalThis.Number.isNaN(that)) return 1;
3405
- return self < that ? -1 : 1;
3406
- });
3407
- /**
3408
- * Order instance for bigints that compares them numerically.
3409
- *
3410
- * **When to use**
3411
- *
3412
- * Use when you need numeric ordering for `bigint` values.
3413
- *
3414
- * **Details**
3415
- *
3416
- * Uses standard numeric comparison for bigint values and handles arbitrarily
3417
- * large integers.
3418
- *
3419
- * **Example** (BigInt Ordering)
3420
- *
3421
- * ```ts
3422
- * import { Order } from "effect"
3423
- *
3424
- * console.log(Order.BigInt(1n, 2n)) // -1
3425
- * console.log(Order.BigInt(2n, 1n)) // 1
3426
- * console.log(Order.BigInt(1n, 1n)) // 0
3427
- * ```
3428
- *
3429
- * @see {@link Number} for regular number comparisons
3430
- * @see {@link mapInput} to compare objects by a bigint property
3431
- * @category instances
3432
- * @since 4.0.0
3433
- */
3434
- const BigInt = /*#__PURE__*/ make$1((self, that) => self < that ? -1 : 1);
3435
- /**
3436
- * Transforms an `Order` on type `A` into an `Order` on type `B` by providing a function that
3437
- * maps values of type `B` to values of type `A`.
3438
- *
3439
- * **When to use**
3440
- *
3441
- * Use when you need to adapt an `Order` to compare a larger value by one
3442
- * derived property.
3443
- *
3444
- * **Details**
3445
- *
3446
- * Applies the mapping function to both values before comparison. The mapping
3447
- * function should be pure and not have side effects so the ordering properties
3448
- * of the original order are preserved.
3449
- *
3450
- * **Example** (Mapping Input)
3451
- *
3452
- * ```ts
3453
- * import { Order } from "effect"
3454
- *
3455
- * const byLength = Order.mapInput(Order.Number, (s: string) => s.length)
3456
- *
3457
- * console.log(byLength("a", "bb")) // -1
3458
- * console.log(byLength("bb", "a")) // 1
3459
- * console.log(byLength("aa", "bb")) // 0
3460
- * ```
3461
- *
3462
- * @see {@link combine} to combine mapped orders for multi-criteria comparison
3463
- * @see {@link Struct} to create orders for structs with multiple fields
3464
- * @category mapping
3465
- * @since 2.0.0
3466
- */
3467
- const mapInput = /*#__PURE__*/ dual(2, (self, f) => make$1((b1, b2) => self(f(b1), f(b2))));
3468
- /**
3469
- * Order instance for `Date` objects that compares them chronologically by their timestamp.
3470
- *
3471
- * **When to use**
3472
- *
3473
- * Use when you need chronological ordering for JavaScript date values.
3474
- *
3475
- * **Details**
3476
- *
3477
- * Compares dates by their underlying timestamp in milliseconds since the epoch.
3478
- * Earlier dates are less than later dates. Invalid dates are compared through
3479
- * their `getTime()` result.
3480
- *
3481
- * **Example** (Date Ordering)
3482
- *
3483
- * ```ts
3484
- * import { Order } from "effect"
3485
- *
3486
- * const date1 = new Date("2023-01-01")
3487
- * const date2 = new Date("2023-01-02")
3488
- *
3489
- * console.log(Order.Date(date1, date2)) // -1
3490
- * console.log(Order.Date(date2, date1)) // 1
3491
- * console.log(Order.Date(date1, date1)) // 0
3492
- * ```
3493
- *
3494
- * @see {@link mapInput} to compare objects by a date property
3495
- * @category instances
3496
- * @since 2.0.0
3497
- */
3498
- const Date$1 = /*#__PURE__*/ mapInput(Number$1, (date) => date.getTime());
3499
- /**
3500
- * Checks whether one value is strictly less than another according to the given order.
3501
- *
3502
- * **When to use**
3503
- *
3504
- * Use when you need a boolean less-than predicate using an `Order`.
3505
- *
3506
- * **Details**
3507
- *
3508
- * Returns `true` if the order returns `-1`, meaning the first value is less
3509
- * than the second. Equal or greater values return `false`.
3510
- *
3511
- * **Example** (Less Than)
3512
- *
3513
- * ```ts
3514
- * import { Order } from "effect"
3515
- *
3516
- * const isLessThanNumber = Order.isLessThan(Order.Number)
3517
- *
3518
- * console.log(isLessThanNumber(1, 2)) // true
3519
- * console.log(isLessThanNumber(2, 1)) // false
3520
- * console.log(isLessThanNumber(1, 1)) // false
3521
- * ```
3522
- *
3523
- * @see {@link isLessThanOrEqualTo} for non-strict less than or equal
3524
- * @see {@link isGreaterThan} for strict greater than
3525
- * @category predicates
3526
- * @since 4.0.0
3527
- */
3528
- const isLessThan = (O) => dual(2, (self, that) => O(self, that) === -1);
3529
- /**
3530
- * Checks whether one value is strictly greater than another according to the given order.
3531
- *
3532
- * **When to use**
3533
- *
3534
- * Use when you need a boolean greater-than predicate using an `Order`.
3535
- *
3536
- * **Details**
3537
- *
3538
- * Returns `true` if the order returns `1`, meaning the first value is greater
3539
- * than the second. Equal or lesser values return `false`.
3540
- *
3541
- * **Example** (Greater Than)
3542
- *
3543
- * ```ts
3544
- * import { Order } from "effect"
3545
- *
3546
- * const isGreaterThanNumber = Order.isGreaterThan(Order.Number)
3547
- *
3548
- * console.log(isGreaterThanNumber(2, 1)) // true
3549
- * console.log(isGreaterThanNumber(1, 2)) // false
3550
- * console.log(isGreaterThanNumber(1, 1)) // false
3551
- * ```
3552
- *
3553
- * @see {@link isGreaterThanOrEqualTo} for non-strict greater than or equal
3554
- * @see {@link isLessThan} for strict less than
3555
- * @category predicates
3556
- * @since 4.0.0
3557
- */
3558
- const isGreaterThan = (O) => dual(2, (self, that) => O(self, that) === 1);
3559
- /**
3560
- * Checks whether one value is less than or equal to another according to the given order.
3561
- *
3562
- * **When to use**
3563
- *
3564
- * Use when you need a boolean less-than-or-equal predicate using an `Order`.
3565
- *
3566
- * **Details**
3567
- *
3568
- * Returns `true` if the order returns `-1` or `0`, and returns `false` only if
3569
- * the order returns `1`.
3570
- *
3571
- * **Example** (Less Than Or Equal)
3572
- *
3573
- * ```ts
3574
- * import { Order } from "effect"
3575
- *
3576
- * const isLessThanOrEqualToNumber = Order.isLessThanOrEqualTo(Order.Number)
3577
- *
3578
- * console.log(isLessThanOrEqualToNumber(1, 2)) // true
3579
- * console.log(isLessThanOrEqualToNumber(1, 1)) // true
3580
- * console.log(isLessThanOrEqualToNumber(2, 1)) // false
3581
- * ```
3582
- *
3583
- * @see {@link isLessThan} for strict less than
3584
- * @see {@link isGreaterThan} for strict greater than
3585
- * @category predicates
3586
- * @since 4.0.0
3587
- */
3588
- const isLessThanOrEqualTo = (O) => dual(2, (self, that) => O(self, that) !== 1);
3589
- /**
3590
- * Checks whether one value is greater than or equal to another according to the given order.
3591
- *
3592
- * **When to use**
3593
- *
3594
- * Use when you need a boolean greater-than-or-equal predicate using an
3595
- * `Order`.
3596
- *
3597
- * **Details**
3598
- *
3599
- * Returns `true` if the order returns `1` or `0`, and returns `false` only if
3600
- * the order returns `-1`.
3601
- *
3602
- * **Example** (Greater Than Or Equal)
3603
- *
3604
- * ```ts
3605
- * import { Order } from "effect"
3606
- *
3607
- * const isGreaterThanOrEqualToNumber = Order.isGreaterThanOrEqualTo(Order.Number)
3608
- *
3609
- * console.log(isGreaterThanOrEqualToNumber(2, 1)) // true
3610
- * console.log(isGreaterThanOrEqualToNumber(1, 1)) // true
3611
- * console.log(isGreaterThanOrEqualToNumber(1, 2)) // false
3612
- * ```
3613
- *
3614
- * @see {@link isGreaterThan} for strict greater than
3615
- * @see {@link isLessThanOrEqualTo} for less than or equal
3616
- * @category predicates
3617
- * @since 4.0.0
3618
- */
3619
- const isGreaterThanOrEqualTo = (O) => dual(2, (self, that) => O(self, that) !== -1);
3620
- /**
3621
- * Returns the minimum of two values according to the given order. If they are equal, returns the first argument.
3622
- *
3623
- * **When to use**
3624
- *
3625
- * Use when you need to select the smaller of two values according to an
3626
- * `Order`.
3627
- *
3628
- * **Details**
3629
- *
3630
- * Returns the value that compares as less than or equal to the other value. If
3631
- * values are equal, the first argument is returned.
3632
- *
3633
- * **Example** (Minimum Value)
3634
- *
3635
- * ```ts
3636
- * import { Order } from "effect"
3637
- *
3638
- * const minNumber = Order.min(Order.Number)
3639
- *
3640
- * console.log(minNumber(1, 2)) // 1
3641
- * console.log(minNumber(2, 1)) // 1
3642
- * console.log(minNumber(1, 1)) // 1
3643
- * ```
3644
- *
3645
- * @see {@link max} for the maximum of two values
3646
- * @see {@link clamp} to clamp a value between min and max
3647
- * @category comparisons
3648
- * @since 2.0.0
3649
- */
3650
- const min = (O) => dual(2, (self, that) => self === that || O(self, that) < 1 ? self : that);
3651
- //#endregion
3652
- //#region node_modules/.pnpm/effect@4.0.0-beta.78/node_modules/effect/dist/Option.js
3653
- /**
3654
- * Creates an `Option` representing the absence of a value.
3655
- *
3656
- * **When to use**
3657
- *
3658
- * Use to represent a missing or uninitialized value, such as returning "no
3659
- * result" from a function.
3660
- *
3661
- * **Details**
3662
- *
3663
- * - Returns `Option<never>`, which is a subtype of `Option<A>` for any `A`
3664
- * - Always returns the same singleton instance
3665
- *
3666
- * **Example** (Creating an empty Option)
3667
- *
3668
- * ```ts
3669
- * import { Option } from "effect"
3670
- *
3671
- * // ┌─── Option<never>
3672
- * // ▼
3673
- * const noValue = Option.none()
3674
- *
3675
- * console.log(noValue)
3676
- * // Output: { _id: 'Option', _tag: 'None' }
3677
- * ```
3678
- *
3679
- * @see {@link some} for the opposite operation.
3680
- *
3681
- * @category constructors
3682
- * @since 2.0.0
3683
- */
3684
- const none = () => none$1;
3685
- /**
3686
- * Wraps the given value into an `Option` to represent its presence.
3687
- *
3688
- * **When to use**
3689
- *
3690
- * Use to wrap a known present value as `Option`
3691
- * - Returning a successful result from a partial function
3692
- *
3693
- * **Details**
3694
- *
3695
- * - Always returns `Some<A>`
3696
- * - Does not filter `null` or `undefined`; use {@link fromNullishOr} for that
3697
- *
3698
- * **Example** (Wrapping a value)
3699
- *
3700
- * ```ts
3701
- * import { Option } from "effect"
3702
- *
3703
- * // ┌─── Option<number>
3704
- * // ▼
3705
- * const value = Option.some(1)
3706
- *
3707
- * console.log(value)
3708
- * // Output: { _id: 'Option', _tag: 'Some', value: 1 }
3709
- * ```
3710
- *
3711
- * @see {@link none} for the opposite operation.
3712
- *
3713
- * @category constructors
3714
- * @since 2.0.0
3715
- */
3716
- const some = some$1;
3717
- /**
3718
- * Determines whether the given value is an `Option`.
3719
- *
3720
- * **When to use**
3721
- *
3722
- * Use to validate unknown values at runtime boundaries, such as type-narrowing
3723
- * in union types.
3724
- *
3725
- * **Details**
3726
- *
3727
- * - Returns `true` for both `Some` and `None` instances
3728
- * - Acts as a type guard, narrowing the input to `Option<unknown>`
3729
- *
3730
- * **Example** (Checking if a value is an Option)
3731
- *
3732
- * ```ts
3733
- * import { Option } from "effect"
3734
- *
3735
- * console.log(Option.isOption(Option.some(1)))
3736
- * // Output: true
3737
- *
3738
- * console.log(Option.isOption(Option.none()))
3739
- * // Output: true
3740
- *
3741
- * console.log(Option.isOption({}))
3742
- * // Output: false
3743
- * ```
3744
- *
3745
- * @see {@link isNone} to check for `None` specifically
3746
- * @see {@link isSome} to check for `Some` specifically
3747
- *
3748
- * @category guards
3749
- * @since 2.0.0
3750
- */
3751
- const isOption = isOption$1;
3752
- /**
3753
- * Checks whether an `Option` is `None` (absent).
3754
- *
3755
- * **When to use**
3756
- *
3757
- * Use when you need to branch on an absent `Option` before accessing `.value`.
3758
- *
3759
- * **Details**
3760
- *
3761
- * - Acts as a type guard, narrowing to `None<A>`
3762
- *
3763
- * **Example** (Checking for None)
3764
- *
3765
- * ```ts
3766
- * import { Option } from "effect"
3767
- *
3768
- * console.log(Option.isNone(Option.some(1)))
3769
- * // Output: false
3770
- *
3771
- * console.log(Option.isNone(Option.none()))
3772
- * // Output: true
3773
- * ```
3774
- *
3775
- * @see {@link isSome} for the opposite check.
3776
- *
3777
- * @category guards
3778
- * @since 2.0.0
3779
- */
3780
- const isNone = isNone$1;
3781
- /**
3782
- * Checks whether an `Option` contains a value (`Some`).
3783
- *
3784
- * **When to use**
3785
- *
3786
- * Use when you need to branch on a present `Option` before accessing `.value`.
3787
- *
3788
- * **Details**
3789
- *
3790
- * - Acts as a type guard, narrowing to `Some<A>`
3791
- *
3792
- * **Example** (Checking for Some)
3793
- *
3794
- * ```ts
3795
- * import { Option } from "effect"
3796
- *
3797
- * console.log(Option.isSome(Option.some(1)))
3798
- * // Output: true
3799
- *
3800
- * console.log(Option.isSome(Option.none()))
3801
- * // Output: false
3802
- * ```
3803
- *
3804
- * @see {@link isNone} for the opposite check.
3805
- *
3806
- * @category guards
3807
- * @since 2.0.0
3808
- */
3809
- const isSome = isSome$1;
3810
- /**
3811
- * Pattern-matches on an `Option`, handling both `None` and `Some` cases.
3812
- *
3813
- * **When to use**
3814
- *
3815
- * Use when you need to handle both `Some` and `None` in one expression and
3816
- * transform an `Option` into a plain value.
3817
- *
3818
- * **Details**
3819
- *
3820
- * - If `None`, calls `onNone` and returns its result
3821
- * - If `Some`, calls `onSome` with the value and returns its result
3822
- * - Supports the `dual` API (data-last and data-first)
3823
- *
3824
- * **Example** (Matching on an Option)
3825
- *
3826
- * ```ts
3827
- * import { Option } from "effect"
3828
- *
3829
- * const message = Option.match(Option.some(1), {
3830
- * onNone: () => "Option is empty",
3831
- * onSome: (value) => `Option has a value: ${value}`
3832
- * })
3833
- *
3834
- * console.log(message)
3835
- * // Output: "Option has a value: 1"
3836
- * ```
3837
- *
3838
- * @see {@link getOrElse} for unwrapping with a default
3839
- *
3840
- * @category pattern matching
3841
- * @since 2.0.0
3842
- */
3843
- const match = /*#__PURE__*/ dual(2, (self, { onNone, onSome }) => isNone(self) ? onNone() : onSome(self.value));
3844
- /**
3845
- * Extracts the value from a `Some`, or evaluates a fallback thunk on `None`.
3846
- *
3847
- * **When to use**
3848
- *
3849
- * Use when providing a default value for an absent `Option`
3850
- * - Unwrapping with lazy evaluation of the fallback
3851
- *
3852
- * **Details**
3853
- *
3854
- * - `Some` → returns the inner value
3855
- * - `None` → calls `onNone()` and returns its result
3856
- * - `onNone` is only called when needed (lazy)
3857
- *
3858
- * **Example** (Unwrapping with a fallback)
3859
- *
3860
- * ```ts
3861
- * import { Option } from "effect"
3862
- *
3863
- * console.log(Option.some(1).pipe(Option.getOrElse(() => 0)))
3864
- * // Output: 1
3865
- *
3866
- * console.log(Option.none().pipe(Option.getOrElse(() => 0)))
3867
- * // Output: 0
3868
- * ```
3869
- *
3870
- * @see {@link getOrNull} to fall back to `null`
3871
- * @see {@link getOrUndefined} to fall back to `undefined`
3872
- * @see {@link getOrThrow} to throw on `None`
3873
- *
3874
- * @category getters
3875
- * @since 2.0.0
3876
- */
3877
- const getOrElse$1 = /*#__PURE__*/ dual(2, (self, onNone) => isNone(self) ? onNone() : self.value);
3878
- /**
3879
- * Converts a nullable value (`null` or `undefined`) into an `Option`.
3880
- *
3881
- * **When to use**
3882
- *
3883
- * Use when you need JavaScript nullish values to become absence at an API
3884
- * boundary while all other values, including falsy ones, remain present.
3885
- *
3886
- * **Details**
3887
- *
3888
- * - `null` or `undefined` → `None`
3889
- * - Any other value → `Some` (typed as `NonNullable<A>`)
3890
- *
3891
- * **Example** (From nullable values)
3892
- *
3893
- * ```ts
3894
- * import { Option } from "effect"
3895
- *
3896
- * console.log(Option.fromNullishOr(undefined))
3897
- * // Output: { _id: 'Option', _tag: 'None' }
3898
- *
3899
- * console.log(Option.fromNullishOr(null))
3900
- * // Output: { _id: 'Option', _tag: 'None' }
3901
- *
3902
- * console.log(Option.fromNullishOr(1))
3903
- * // Output: { _id: 'Option', _tag: 'Some', value: 1 }
3904
- * ```
3905
- *
3906
- * @see {@link fromNullOr} to only treat `null` as absent
3907
- * @see {@link fromUndefinedOr} to only treat `undefined` as absent
3908
- * @see {@link liftNullishOr} to lift a nullable-returning function
3909
- *
3910
- * @category converting
3911
- * @since 4.0.0
3912
- */
3913
- const fromNullishOr = (a) => a == null ? none() : some(a);
3914
- /**
3915
- * Converts a possibly `undefined` value into an `Option`, leaving `null`
3916
- * as a valid `Some`.
3917
- *
3918
- * **When to use**
3919
- *
3920
- * Use when you want to treat only `undefined` as absent while preserving `null`
3921
- * as a meaningful value.
3922
- *
3923
- * **Details**
3924
- *
3925
- * - `undefined` → `None`
3926
- * - Any other value (including `null`) → `Some`
3927
- *
3928
- * **Example** (From possibly-undefined values)
3929
- *
3930
- * ```ts
3931
- * import { Option } from "effect"
3932
- *
3933
- * console.log(Option.fromUndefinedOr(undefined))
3934
- * // Output: { _id: 'Option', _tag: 'None' }
3935
- *
3936
- * console.log(Option.fromUndefinedOr(null))
3937
- * // Output: { _id: 'Option', _tag: 'Some', value: null }
3938
- *
3939
- * console.log(Option.fromUndefinedOr(42))
3940
- * // Output: { _id: 'Option', _tag: 'Some', value: 42 }
3941
- * ```
3942
- *
3943
- * @see {@link fromNullishOr} to treat both `null` and `undefined` as absent
3944
- * @see {@link fromNullOr} to only treat `null` as absent
3945
- *
3946
- * @category converting
3947
- * @since 4.0.0
3948
- */
3949
- const fromUndefinedOr = (a) => a === void 0 ? none() : some(a);
3950
- /**
3951
- * Extracts the value from a `Some`, or returns `undefined` for `None`.
3952
- *
3953
- * **When to use**
3954
- *
3955
- * Use when you need to pass absent `Option` values to APIs that expect
3956
- * `undefined`.
3957
- *
3958
- * **Details**
3959
- *
3960
- * - `Some` → the inner value
3961
- * - `None` → `undefined`
3962
- *
3963
- * **Example** (Unwrapping to undefined)
3964
- *
3965
- * ```ts
3966
- * import { Option } from "effect"
3967
- *
3968
- * console.log(Option.getOrUndefined(Option.some(1)))
3969
- * // Output: 1
3970
- *
3971
- * console.log(Option.getOrUndefined(Option.none()))
3972
- * // Output: undefined
3973
- * ```
3974
- *
3975
- * @see {@link getOrNull} to return `null` instead
3976
- * @see {@link getOrElse} for a custom fallback
3977
- *
3978
- * @category getters
3979
- * @since 2.0.0
3980
- */
3981
- const getOrUndefined = /*#__PURE__*/ getOrElse$1(constUndefined);
3982
- /**
3983
- * Lifts a function that may throw into one that returns an `Option`.
3984
- *
3985
- * **When to use**
3986
- *
3987
- * Use to wrap exception-throwing APIs (e.g. `JSON.parse`) for safe usage
3988
- *
3989
- * **Details**
3990
- *
3991
- * - If the function returns normally → `Some` with the result
3992
- * - If the function throws → `None` (exception is swallowed)
3993
- *
3994
- * **Example** (Lifting JSON.parse)
3995
- *
3996
- * ```ts
3997
- * import { Option } from "effect"
3998
- *
3999
- * const parse = Option.liftThrowable(JSON.parse)
4000
- *
4001
- * console.log(parse("1"))
4002
- * // Output: { _id: 'Option', _tag: 'Some', value: 1 }
4003
- *
4004
- * console.log(parse(""))
4005
- * // Output: { _id: 'Option', _tag: 'None' }
4006
- * ```
4007
- *
4008
- * @see {@link liftNullishOr} for nullable-returning functions
4009
- *
4010
- * @category converting
4011
- * @since 2.0.0
4012
- */
4013
- const liftThrowable = (f) => (...a) => {
4014
- try {
4015
- return some(f(...a));
4016
- } catch {
4017
- return none();
4018
- }
4019
- };
4020
- /**
4021
- * Extracts the value from a `Some`, or throws a default `Error` for `None`.
4022
- *
4023
- * **When to use**
4024
- *
4025
- * Use when you need quick fail-fast unwrapping of an `Option` and a generic
4026
- * error is acceptable.
4027
- *
4028
- * **Details**
4029
- *
4030
- * - `Some` → returns the inner value
4031
- * - `None` → throws `new Error("getOrThrow called on a None")`
4032
- *
4033
- * **Example** (Throwing a default error)
4034
- *
4035
- * ```ts
4036
- * import { Option } from "effect"
4037
- *
4038
- * console.log(Option.getOrThrow(Option.some(1)))
4039
- * // Output: 1
4040
- *
4041
- * Option.getOrThrow(Option.none())
4042
- * // throws Error: getOrThrow called on a None
4043
- * ```
4044
- *
4045
- * @see {@link getOrThrowWith} for a custom error
4046
- * @see {@link getOrElse} for a non-throwing alternative
4047
- *
4048
- * @category converting
4049
- * @since 2.0.0
4050
- */
4051
- const getOrThrow = /*#__PURE__*/ (/* @__PURE__ */ dual(2, (self, onNone) => {
4052
- if (isSome(self)) return self.value;
4053
- throw onNone();
4054
- }))(() => /* @__PURE__ */ new Error("getOrThrow called on a None"));
4055
- /**
4056
- * Transforms the value inside a `Some` using the provided function, leaving
4057
- * `None` unchanged.
4058
- *
4059
- * **When to use**
4060
- *
4061
- * Use to apply a pure transformation to an `Option`'s present value, especially
4062
- * when chaining transformations in a pipeline.
4063
- *
4064
- * **Details**
4065
- *
4066
- * - `Some` → applies `f` and wraps the result in a new `Some`
4067
- * - `None` → returns `None` unchanged
4068
- *
4069
- * **Example** (Mapping over an Option)
4070
- *
4071
- * ```ts
4072
- * import { Option } from "effect"
4073
- *
4074
- * console.log(Option.map(Option.some(2), (n) => n * 2))
4075
- * // Output: { _id: 'Option', _tag: 'Some', value: 4 }
4076
- *
4077
- * console.log(Option.map(Option.none(), (n: number) => n * 2))
4078
- * // Output: { _id: 'Option', _tag: 'None' }
4079
- * ```
4080
- *
4081
- * @see {@link flatMap} when `f` returns an `Option`
4082
- * @see {@link as} to replace the value with a constant
4083
- *
4084
- * @category mapping
4085
- * @since 2.0.0
4086
- */
4087
- const map = /*#__PURE__*/ dual(2, (self, f) => isNone(self) ? none() : some(f(self.value)));
4088
- /**
4089
- * Applies a function that returns an `Option` to the value of a `Some`,
4090
- * flattening the result. Returns `None` if the input is `None`.
4091
- *
4092
- * **When to use**
4093
- *
4094
- * Use when you need to chain dependent `Option` computations where each step
4095
- * may return `None`.
4096
- *
4097
- * **Details**
4098
- *
4099
- * - `Some` → applies `f` to the value and returns its `Option` result
4100
- * - `None` → returns `None` without calling `f`
4101
- * - Equivalent to `map` followed by {@link flatten}
4102
- *
4103
- * **Example** (Chaining optional lookups)
4104
- *
4105
- * ```ts
4106
- * import { Option } from "effect"
4107
- *
4108
- * interface User {
4109
- * readonly name: string
4110
- * readonly address: Option.Option<{ readonly street: Option.Option<string> }>
4111
- * }
4112
- *
4113
- * const user: User = {
4114
- * name: "John",
4115
- * address: Option.some({ street: Option.some("123 Main St") })
4116
- * }
4117
- *
4118
- * const street = user.address.pipe(
4119
- * Option.flatMap((addr) => addr.street)
4120
- * )
4121
- *
4122
- * console.log(street)
4123
- * // Output: { _id: 'Option', _tag: 'Some', value: '123 Main St' }
4124
- * ```
4125
- *
4126
- * @see {@link map} when `f` returns a plain value
4127
- * @see {@link andThen} for a more flexible variant
4128
- * @see {@link flatten} to unwrap a nested `Option<Option<A>>`
4129
- *
4130
- * @category sequencing
4131
- * @since 2.0.0
4132
- */
4133
- const flatMap = /*#__PURE__*/ dual(2, (self, f) => isNone(self) ? none() : f(self.value));
4134
- /**
4135
- * Filters an `Option` using a predicate. Returns `None` if the predicate is
4136
- * not satisfied or the input is `None`.
4137
- *
4138
- * **When to use**
4139
- *
4140
- * Use when you need to discard an `Option`'s present value when it does not
4141
- * meet a condition, while narrowing the type via a refinement predicate.
4142
- *
4143
- * **Details**
4144
- *
4145
- * - `None` → `None`
4146
- * - `Some` where `predicate(value)` is `true` → `Some(value)`
4147
- * - `Some` where `predicate(value)` is `false` → `None`
4148
- * - Supports refinements for type narrowing
4149
- *
4150
- * **Example** (Filtering with a predicate)
4151
- *
4152
- * ```ts
4153
- * import { Option } from "effect"
4154
- *
4155
- * const removeEmpty = (input: Option.Option<string>) =>
4156
- * Option.filter(input, (value) => value !== "")
4157
- *
4158
- * console.log(removeEmpty(Option.some("hello")))
4159
- * // Output: { _id: 'Option', _tag: 'Some', value: 'hello' }
4160
- *
4161
- * console.log(removeEmpty(Option.some("")))
4162
- * // Output: { _id: 'Option', _tag: 'None' }
4163
- *
4164
- * console.log(removeEmpty(Option.none()))
4165
- * // Output: { _id: 'Option', _tag: 'None' }
4166
- * ```
4167
- *
4168
- * @see {@link filterMap} to transform and filter simultaneously
4169
- * @see {@link exists} to test without filtering
4170
- *
4171
- * @category filtering
4172
- * @since 2.0.0
4173
- */
4174
- const filter = /*#__PURE__*/ dual(2, (self, predicate) => isNone(self) ? none() : predicate(self.value) ? some(self.value) : none());
4175
- /**
4176
- * Creates an `Equivalence` for `Option<A>` from an `Equivalence` for `A`.
4177
- *
4178
- * **When to use**
4179
- *
4180
- * Use when you need equality to treat two `None` values as equal and compare
4181
- * two `Some` values with a supplied equality rule.
4182
- *
4183
- * **Details**
4184
- *
4185
- * - `None` vs `None` → `true`
4186
- * - `Some` vs `None` (or vice versa) → `false`
4187
- * - `Some(a)` vs `Some(b)` → delegates to the provided `Equivalence`
4188
- *
4189
- * **Example** (Comparing Options)
4190
- *
4191
- * ```ts
4192
- * import { Equivalence, Option } from "effect"
4193
- *
4194
- * const eq = Option.makeEquivalence(Equivalence.strictEqual<number>())
4195
- *
4196
- * console.log(eq(Option.some(1), Option.some(1)))
4197
- * // Output: true
4198
- *
4199
- * console.log(eq(Option.some(1), Option.some(2)))
4200
- * // Output: false
4201
- *
4202
- * console.log(eq(Option.none(), Option.none()))
4203
- * // Output: true
4204
- * ```
4205
- *
4206
- * @category instances
4207
- * @since 4.0.0
4208
- */
4209
- const makeEquivalence = (isEquivalent) => make$2((x, y) => isNone(x) ? isNone(y) : isNone(y) ? false : isEquivalent(x.value, y.value));
4210
- //#endregion
4211
- //#region node_modules/.pnpm/effect@4.0.0-beta.78/node_modules/effect/dist/Context.js
4212
- /**
4213
- * Runtime type identifier attached to `Context` service keys and used by
4214
- * `isKey` to recognize them.
4215
- *
4216
- * @category type IDs
4217
- * @since 4.0.0
4218
- */
4219
- const ServiceTypeId = "~effect/Context/Service";
4220
- /**
4221
- * Creates a `Context` service key.
4222
- *
4223
- * **When to use**
4224
- *
4225
- * Use when you need to define a context service key for a dependency that must
4226
- * be provided by the surrounding context.
4227
- *
4228
- * **Details**
4229
- *
4230
- * Call `Context.Service("Key")` for a function-style key, or use the two-stage
4231
- * form `Context.Service<Self, Shape>()("Key")` for class-style service
4232
- * declarations. The returned key can be yielded as an Effect and passed to
4233
- * `Context.make`, `Context.add`, and the Context getter functions.
4234
- *
4235
- * **Gotchas**
4236
- *
4237
- * The string key is the runtime identity of the service. Reusing the same key
4238
- * string for unrelated services makes them occupy the same slot in a
4239
- * `Context`.
4240
- *
4241
- * **Example** (Creating service keys)
4242
- *
4243
- * ```ts
4244
- * import { Context } from "effect"
4245
- *
4246
- * // Create a simple service
4247
- * const Database = Context.Service<{
4248
- * query: (sql: string) => string
4249
- * }>("Database")
4250
- *
4251
- * // Create a service class
4252
- * class Config extends Context.Service<Config, {
4253
- * port: number
4254
- * }>()("Config") {}
4255
- *
4256
- * // Use the services to create contexts
4257
- * const db = Context.make(Database, {
4258
- * query: (sql) => `Result: ${sql}`
4259
- * })
4260
- * const config = Context.make(Config, { port: 8080 })
4261
- * ```
4262
- *
4263
- * @see {@link Reference} for service keys with default values
4264
- *
4265
- * @category constructors
4266
- * @since 4.0.0
4267
- */
4268
- const Service = function() {
4269
- const prevLimit = Error.stackTraceLimit;
4270
- Error.stackTraceLimit = 2;
4271
- const err = /* @__PURE__ */ new Error();
4272
- Error.stackTraceLimit = prevLimit;
4273
- function KeyClass() {}
4274
- const self = KeyClass;
4275
- Object.setPrototypeOf(self, ServiceProto);
4276
- Object.defineProperty(self, "stack", { get() {
4277
- return err.stack;
4278
- } });
4279
- if (arguments.length > 0) {
4280
- self.key = arguments[0];
4281
- if (arguments[1]?.defaultValue) {
4282
- self[ReferenceTypeId] = ReferenceTypeId;
4283
- self.defaultValue = arguments[1].defaultValue;
4284
- }
4285
- return self;
4286
- }
4287
- return function(key, options) {
4288
- self.key = key;
4289
- if (options?.make) self.make = options.make;
4290
- return self;
4291
- };
4292
- };
4293
- const ServiceProto = {
4294
- [ServiceTypeId]: ServiceTypeId,
4295
- .../*#__PURE__*/ Prototype({
4296
- label: "Service",
4297
- evaluate(fiber) {
4298
- return exitSucceed(get(fiber.context, this));
4299
- }
4300
- }),
4301
- toJSON() {
4302
- return {
4303
- _id: "Service",
4304
- key: this.key,
4305
- stack: this.stack
4306
- };
4307
- },
4308
- of(self) {
4309
- return self;
4310
- },
4311
- context(self) {
4312
- return make(this, self);
4313
- },
4314
- use(f) {
4315
- return withFiber((fiber) => f(get(fiber.context, this)));
4316
- },
4317
- useSync(f) {
4318
- return withFiber((fiber) => exitSucceed(f(get(fiber.context, this))));
4319
- }
4320
- };
4321
- const ReferenceTypeId = "~effect/Context/Reference";
4322
- const TypeId = "~effect/Context";
4323
- /**
4324
- * Creates a `Context` from an existing service map.
4325
- *
4326
- * **When to use**
4327
- *
4328
- * Use when constructing a low-level `Context` from a trusted map whose lifecycle
4329
- * you control.
4330
- *
4331
- * **Gotchas**
4332
- *
4333
- * This is unsafe because later mutation of the provided map can affect the
4334
- * created `Context`. Prefer `empty`, `make`, `add`, or `merge` for normal
4335
- * Context construction.
4336
- *
4337
- * **Example** (Creating a context from a map)
4338
- *
4339
- * ```ts
4340
- * import { Context } from "effect"
4341
- *
4342
- * // Create a context from a Map (unsafe)
4343
- * const map = new Map([
4344
- * ["Logger", { log: (msg: string) => console.log(msg) }]
4345
- * ])
4346
- *
4347
- * const context = Context.makeUnsafe(map)
4348
- * ```
4349
- *
4350
- * @category constructors
4351
- * @since 4.0.0
4352
- */
4353
- const makeUnsafe = (mapUnsafe) => {
4354
- const self = Object.create(Proto);
4355
- self.mapUnsafe = mapUnsafe;
4356
- self.mutable = false;
4357
- return self;
4358
- };
4359
- const Proto = {
4360
- ...PipeInspectableProto,
4361
- [TypeId]: { _Services: (_) => _ },
4362
- toJSON() {
4363
- return {
4364
- _id: "Context",
4365
- services: Array.from(this.mapUnsafe).map(([key, value]) => ({
4366
- key,
4367
- value
4368
- }))
4369
- };
4370
- },
4371
- [symbol](that) {
4372
- if (!isContext(that) || this.mapUnsafe.size !== that.mapUnsafe.size) return false;
4373
- for (const k of this.mapUnsafe.keys()) if (!that.mapUnsafe.has(k) || !equals(this.mapUnsafe.get(k), that.mapUnsafe.get(k))) return false;
4374
- return true;
4375
- },
4376
- [symbol$1]() {
4377
- return number(this.mapUnsafe.size);
4378
- }
4379
- };
4380
- /**
4381
- * Checks whether the provided argument is a `Context`.
4382
- *
4383
- * **When to use**
4384
- *
4385
- * Use to narrow an unknown value before passing it to APIs that require a
4386
- * `Context`.
4387
- *
4388
- * **Details**
4389
- *
4390
- * This checks the runtime `Context` marker and does not inspect which services
4391
- * the context contains.
4392
- *
4393
- * **Gotchas**
4394
- *
4395
- * This guard only proves that the value is a `Context`; it does not prove that
4396
- * any specific service is present.
4397
- *
4398
- * **Example** (Checking for contexts)
4399
- *
4400
- * ```ts
4401
- * import { Context } from "effect"
4402
- * import * as assert from "node:assert"
4403
- *
4404
- * assert.strictEqual(Context.isContext(Context.empty()), true)
4405
- * ```
4406
- *
4407
- * @see {@link isKey} for checking service keys
4408
- * @see {@link isReference} for checking references with defaults
4409
- *
4410
- * @category guards
4411
- * @since 2.0.0
4412
- */
4413
- const isContext = (u) => hasProperty(u, TypeId);
4414
- /**
4415
- * Checks whether the provided argument is a `Reference`.
4416
- *
4417
- * **Example** (Checking for references)
4418
- *
4419
- * ```ts
4420
- * import { Context } from "effect"
4421
- * import * as assert from "node:assert"
4422
- *
4423
- * const LoggerRef = Context.Reference("Logger", {
4424
- * defaultValue: () => ({ log: (msg: string) => console.log(msg) })
4425
- * })
4426
- *
4427
- * assert.strictEqual(Context.isReference(LoggerRef), true)
4428
- * assert.strictEqual(Context.isReference(Context.Service("Key")), false)
4429
- * ```
4430
- *
4431
- * @category guards
4432
- * @since 3.11.0
4433
- */
4434
- const isReference = (u) => hasProperty(u, ReferenceTypeId);
4435
- /**
4436
- * Returns an empty `Context`.
4437
- *
4438
- * **Example** (Creating an empty context)
4439
- *
4440
- * ```ts
4441
- * import { Context } from "effect"
4442
- * import * as assert from "node:assert"
4443
- *
4444
- * assert.strictEqual(Context.isContext(Context.empty()), true)
4445
- * ```
4446
- *
4447
- * @category constructors
4448
- * @since 2.0.0
4449
- */
4450
- const empty = () => emptyContext;
4451
- const emptyContext = /*#__PURE__*/ makeUnsafe(/*#__PURE__*/ new Map());
4452
- /**
4453
- * Creates a new `Context` with a single service associated to the key.
4454
- *
4455
- * **Example** (Creating a context with one service)
4456
- *
4457
- * ```ts
4458
- * import { Context } from "effect"
4459
- * import * as assert from "node:assert"
4460
- *
4461
- * const Port = Context.Service<{ PORT: number }>("Port")
4462
- *
4463
- * const context = Context.make(Port, { PORT: 8080 })
4464
- *
4465
- * assert.deepStrictEqual(Context.get(context, Port), { PORT: 8080 })
4466
- * ```
4467
- *
4468
- * @category constructors
4469
- * @since 2.0.0
4470
- */
4471
- const make = (key, service) => makeUnsafe(new Map([[key.key, service]]));
4472
- /**
4473
- * Adds a service to a given `Context`.
4474
- *
4475
- * **When to use**
4476
- *
4477
- * Use when you need to store a known service value in a `Context`.
4478
- *
4479
- * **Details**
4480
- *
4481
- * If the context already contains the same service key, the new service
4482
- * replaces the previous one.
4483
- *
4484
- * **Example** (Adding a service to a context)
4485
- *
4486
- * ```ts
4487
- * import { Context, pipe } from "effect"
4488
- * import * as assert from "node:assert"
4489
- *
4490
- * const Port = Context.Service<{ PORT: number }>("Port")
4491
- * const Timeout = Context.Service<{ TIMEOUT: number }>("Timeout")
4492
- *
4493
- * const someContext = Context.make(Port, { PORT: 8080 })
4494
- *
4495
- * const context = pipe(
4496
- * someContext,
4497
- * Context.add(Timeout, { TIMEOUT: 5000 })
4498
- * )
4499
- *
4500
- * assert.deepStrictEqual(Context.get(context, Port), { PORT: 8080 })
4501
- * assert.deepStrictEqual(Context.get(context, Timeout), { TIMEOUT: 5000 })
4502
- * ```
4503
- *
4504
- * @see {@link addOrOmit} for adding or removing a service from an `Option`
4505
- *
4506
- * @category adders
4507
- * @since 2.0.0
4508
- */
4509
- const add = /*#__PURE__*/ dual(3, (self, key, service) => withMapUnsafe(self, (map) => {
4510
- map.set(key.key, service);
4511
- }));
4512
- /**
4513
- * Gets the service for a key, or evaluates the fallback when a non-reference
4514
- * key is absent.
4515
- *
4516
- * **When to use**
4517
- *
4518
- * Use when you need a fallback for a missing `Context.Service` key while still
4519
- * resolving `Context.Reference` defaults.
4520
- *
4521
- * **Details**
4522
- *
4523
- * If the key is a `Context.Reference` and no override is stored in the
4524
- * context, its cached default value is returned instead of the fallback.
4525
- *
4526
- * **Gotchas**
4527
- *
4528
- * The fallback is not evaluated for missing `Context.Reference` keys because
4529
- * references resolve to their default value.
4530
- *
4531
- * **Example** (Falling back for missing services)
4532
- *
4533
- * ```ts
4534
- * import { Context } from "effect"
4535
- *
4536
- * const Logger = Context.Service<{ log: (msg: string) => void }>("Logger")
4537
- * const Database = Context.Service<{ query: (sql: string) => string }>(
4538
- * "Database"
4539
- * )
4540
- *
4541
- * const context = Context.make(Logger, {
4542
- * log: (msg: string) => console.log(msg)
4543
- * })
4544
- *
4545
- * const logger = Context.getOrElse(context, Logger, () => ({ log: () => {} }))
4546
- * const database = Context.getOrElse(
4547
- * context,
4548
- * Database,
4549
- * () => ({ query: () => "fallback" })
4550
- * )
4551
- *
4552
- * console.log(logger === Context.get(context, Logger)) // true
4553
- * console.log(database.query("SELECT 1")) // "fallback"
4554
- * ```
4555
- *
4556
- * @see {@link getOption} for returning `Option.none` when a non-reference key is missing
4557
- *
4558
- * @category getters
4559
- * @since 3.7.0
4560
- */
4561
- const getOrElse = /*#__PURE__*/ dual(3, (self, key, orElse) => {
4562
- if (self.mapUnsafe.has(key.key)) return self.mapUnsafe.get(key.key);
4563
- return isReference(key) ? getDefaultValue(key) : orElse();
4564
- });
4565
- /**
4566
- * Gets the service for a key, throwing if an absent non-reference key cannot be
4567
- * resolved.
4568
- *
4569
- * **When to use**
4570
- *
4571
- * Use when you need to read a service from a context whose type does not prove
4572
- * the service is present.
4573
- *
4574
- * **Details**
4575
- *
4576
- * If the key is a `Context.Reference` and no override is stored in the
4577
- * context, its cached default value is returned. For absent non-reference keys,
4578
- * this function throws a runtime error.
4579
- *
4580
- * **Example** (Getting services unsafely)
4581
- *
4582
- * ```ts
4583
- * import { Context } from "effect"
4584
- * import * as assert from "node:assert"
4585
- *
4586
- * const Port = Context.Service<{ PORT: number }>("Port")
4587
- * const Timeout = Context.Service<{ TIMEOUT: number }>("Timeout")
4588
- *
4589
- * const context = Context.make(Port, { PORT: 8080 })
4590
- *
4591
- * assert.deepStrictEqual(Context.getUnsafe(context, Port), { PORT: 8080 })
4592
- * assert.throws(() => Context.getUnsafe(context, Timeout))
4593
- * ```
4594
- *
4595
- * @see {@link get} for type-checked service access
4596
- * @see {@link getOption} for optional service access
4597
- *
4598
- * @category unsafe
4599
- * @since 4.0.0
4600
- */
4601
- const getUnsafe = /*#__PURE__*/ dual(2, (self, service) => {
4602
- if (!self.mapUnsafe.has(service.key)) {
4603
- if (ReferenceTypeId in service) return getDefaultValue(service);
4604
- throw serviceNotFoundError(service);
4605
- }
4606
- return self.mapUnsafe.get(service.key);
4607
- });
4608
- /**
4609
- * Gets a service from the context that corresponds to the given key.
4610
- *
4611
- * **When to use**
4612
- *
4613
- * Use when you need type-checked access to a service already included in the
4614
- * context type.
4615
- *
4616
- * **Example** (Getting a service from a context)
4617
- *
4618
- * ```ts
4619
- * import { Context, pipe } from "effect"
4620
- * import * as assert from "node:assert"
4621
- *
4622
- * const Port = Context.Service<{ PORT: number }>("Port")
4623
- * const Timeout = Context.Service<{ TIMEOUT: number }>("Timeout")
4624
- *
4625
- * const context = pipe(
4626
- * Context.make(Port, { PORT: 8080 }),
4627
- * Context.add(Timeout, { TIMEOUT: 5000 })
4628
- * )
4629
- *
4630
- * assert.deepStrictEqual(Context.get(context, Timeout), { TIMEOUT: 5000 })
4631
- * ```
4632
- *
4633
- * @see {@link getOption} for optional service access
4634
- * @see {@link getOrElse} for fallback values
4635
- *
4636
- * @category getters
4637
- * @since 2.0.0
4638
- */
4639
- const get = getUnsafe;
4640
- /**
4641
- * Gets the value for a `Context.Reference`, returning its cached default when
4642
- * the context does not contain an override.
4643
- *
4644
- * **When to use**
4645
- *
4646
- * Use when you need a `Context.Reference` value resolved from either a stored
4647
- * override or the reference's default value.
4648
- *
4649
- * **Details**
4650
- *
4651
- * Stored overrides take precedence. If no override is present, the reference's
4652
- * default value is computed lazily and cached on the reference itself.
4653
- *
4654
- * **Gotchas**
4655
- *
4656
- * Mutable default values can be shared across contexts unless an override is
4657
- * provided, because the default is cached on the `Context.Reference`.
4658
- *
4659
- * **Example** (Getting reference defaults unsafely)
4660
- *
4661
- * ```ts
4662
- * import { Context } from "effect"
4663
- *
4664
- * const LoggerRef = Context.Reference("Logger", {
4665
- * defaultValue: () => ({ log: (msg: string) => console.log(msg) })
4666
- * })
4667
- *
4668
- * const context = Context.empty()
4669
- * const logger = Context.getReferenceUnsafe(context, LoggerRef)
4670
- *
4671
- * console.log(typeof logger.log) // "function"
4672
- * ```
4673
- *
4674
- * @see {@link getUnsafe} for unsafe access with any service key
4675
- * @see {@link get} for type-checked reference-aware access
4676
- * @see {@link getOption} for optional access to non-reference keys
4677
- *
4678
- * @category unsafe
4679
- * @since 4.0.0
4680
- */
4681
- const getReferenceUnsafe = (self, service) => {
4682
- if (!self.mapUnsafe.has(service.key)) return getDefaultValue(service);
4683
- return self.mapUnsafe.get(service.key);
4684
- };
4685
- const defaultValueCacheKey = "~effect/Context/defaultValue";
4686
- const getDefaultValue = (ref) => {
4687
- if (defaultValueCacheKey in ref) return ref[defaultValueCacheKey];
4688
- return ref[defaultValueCacheKey] = ref.defaultValue();
4689
- };
4690
- const serviceNotFoundError = (service) => {
4691
- const error = /* @__PURE__ */ new Error(`Service not found${service.key ? `: ${String(service.key)}` : ""}`);
4692
- if (service.stack) {
4693
- const lines = service.stack.split("\n");
4694
- if (lines.length > 2) {
4695
- const afterAt = lines[2].match(/at (.*)/);
4696
- if (afterAt) error.message = error.message + ` (defined at ${afterAt[1]})`;
4697
- }
4698
- }
4699
- if (error.stack) {
4700
- const lines = error.stack.split("\n");
4701
- lines.splice(1, 3);
4702
- error.stack = lines.join("\n");
4703
- }
4704
- return error;
4705
- };
4706
- /**
4707
- * Gets the service for a key safely wrapped in an `Option`.
4708
- *
4709
- * **When to use**
4710
- *
4711
- * Use when you need to read a `Context` service as an `Option` so absence is
4712
- * represented as data.
4713
- *
4714
- * **Details**
4715
- *
4716
- * Returns `Option.some` when the service is stored in the context. If the key
4717
- * is a `Context.Reference` and no override is stored, returns `Option.some` of
4718
- * the cached default value. Missing non-reference keys return `Option.none`.
4719
- *
4720
- * **Example** (Getting optional services)
4721
- *
4722
- * ```ts
4723
- * import { Context, Option } from "effect"
4724
- * import * as assert from "node:assert"
4725
- *
4726
- * const Port = Context.Service<{ PORT: number }>("Port")
4727
- * const Timeout = Context.Service<{ TIMEOUT: number }>("Timeout")
4728
- *
4729
- * const context = Context.make(Port, { PORT: 8080 })
4730
- *
4731
- * assert.deepStrictEqual(
4732
- * Context.getOption(context, Port),
4733
- * Option.some({ PORT: 8080 })
4734
- * )
4735
- * assert.deepStrictEqual(Context.getOption(context, Timeout), Option.none())
4736
- * ```
4737
- *
4738
- * @see {@link getOrElse} for returning a fallback value directly
4739
- *
4740
- * @category getters
4741
- * @since 2.0.0
4742
- */
4743
- const getOption = /*#__PURE__*/ dual(2, (self, service) => {
4744
- if (self.mapUnsafe.has(service.key)) return some(self.mapUnsafe.get(service.key));
4745
- return isReference(service) ? some(getDefaultValue(service)) : none();
4746
- });
4747
- /**
4748
- * Merges two `Context`s into one.
4749
- *
4750
- * **When to use**
4751
- *
4752
- * Use when you need to combine two contexts.
4753
- *
4754
- * **Details**
4755
- *
4756
- * When both contexts contain the same service key, the service from `that`
4757
- * overrides the service from `self`.
4758
- *
4759
- * **Example** (Merging two contexts)
4760
- *
4761
- * ```ts
4762
- * import { Context } from "effect"
4763
- * import * as assert from "node:assert"
4764
- *
4765
- * const Port = Context.Service<{ PORT: number }>("Port")
4766
- * const Timeout = Context.Service<{ TIMEOUT: number }>("Timeout")
4767
- *
4768
- * const firstContext = Context.make(Port, { PORT: 8080 })
4769
- * const secondContext = Context.make(Timeout, { TIMEOUT: 5000 })
4770
- *
4771
- * const context = Context.merge(firstContext, secondContext)
4772
- *
4773
- * assert.deepStrictEqual(Context.get(context, Port), { PORT: 8080 })
4774
- * assert.deepStrictEqual(Context.get(context, Timeout), { TIMEOUT: 5000 })
4775
- * ```
4776
- *
4777
- * @see {@link mergeAll} for merging more than two contexts at once
4778
- *
4779
- * @category combining
4780
- * @since 2.0.0
4781
- */
4782
- const merge = /*#__PURE__*/ dual(2, (self, that) => {
4783
- if (self.mapUnsafe.size === 0) return that;
4784
- if (that.mapUnsafe.size === 0) return self;
4785
- return withMapUnsafe(self, (map) => {
4786
- that.mapUnsafe.forEach((value, key) => map.set(key, value));
4787
- });
4788
- });
4789
- /**
4790
- * Merges any number of `Context`s into one.
4791
- *
4792
- * **When to use**
4793
- *
4794
- * Use when you need to combine a variadic list of contexts.
4795
- *
4796
- * **Details**
4797
- *
4798
- * When multiple contexts contain the same service key, the service from the
4799
- * last context with that key is kept.
4800
- *
4801
- * **Example** (Merging multiple contexts)
4802
- *
4803
- * ```ts
4804
- * import { Context } from "effect"
4805
- * import * as assert from "node:assert"
4806
- *
4807
- * const Port = Context.Service<{ PORT: number }>("Port")
4808
- * const Timeout = Context.Service<{ TIMEOUT: number }>("Timeout")
4809
- * const Host = Context.Service<{ HOST: string }>("Host")
4810
- *
4811
- * const firstContext = Context.make(Port, { PORT: 8080 })
4812
- * const secondContext = Context.make(Timeout, { TIMEOUT: 5000 })
4813
- * const thirdContext = Context.make(Host, { HOST: "localhost" })
4814
- *
4815
- * const context = Context.mergeAll(
4816
- * firstContext,
4817
- * secondContext,
4818
- * thirdContext
4819
- * )
4820
- *
4821
- * assert.deepStrictEqual(Context.get(context, Port), { PORT: 8080 })
4822
- * assert.deepStrictEqual(Context.get(context, Timeout), { TIMEOUT: 5000 })
4823
- * assert.deepStrictEqual(Context.get(context, Host), { HOST: "localhost" })
4824
- * ```
4825
- *
4826
- * @see {@link merge} for merging two contexts
4827
- *
4828
- * @category combining
4829
- * @since 3.12.0
4830
- */
4831
- const mergeAll = (...ctxs) => {
4832
- const map = /* @__PURE__ */ new Map();
4833
- for (let i = 0; i < ctxs.length; i++) ctxs[i].mapUnsafe.forEach((value, key) => {
4834
- map.set(key, value);
4835
- });
4836
- return makeUnsafe(map);
4837
- };
4838
- /**
4839
- * Performs a series of mutations on a `Context`. Prevents unnecessary copying
4840
- * of the underlying map when multiple mutations are needed.
4841
- *
4842
- * **When to use**
4843
- *
4844
- * Use to apply several `Context` transformations in one callback while copying
4845
- * the underlying service map only once.
4846
- *
4847
- * @see {@link add} for adding or replacing a service
4848
- * @see {@link addOrOmit} for adding or removing a service from an `Option`
4849
- * @see {@link merge} for combining two contexts
4850
- * @see {@link pick} for keeping selected services
4851
- * @see {@link omit} for removing selected services
4852
- *
4853
- * @category mutations
4854
- * @since 4.0.0
4855
- */
4856
- const mutate = /*#__PURE__*/ dual(2, (self, f) => {
4857
- const next = makeUnsafe(new Map(self.mapUnsafe));
4858
- next.mutable = true;
4859
- const result = f(next);
4860
- result.mutable = false;
4861
- return result;
4862
- });
4863
- const withMapUnsafe = (self, f) => {
4864
- if (self.mutable) {
4865
- f(self.mapUnsafe);
4866
- return self;
4867
- }
4868
- const map = new Map(self.mapUnsafe);
4869
- f(map);
4870
- return makeUnsafe(map);
4871
- };
4872
- /**
4873
- * Creates a context key with a default value.
4874
- *
4875
- * **When to use**
4876
- *
4877
- * Use when you need to define a context key with a lazily computed default
4878
- * value.
4879
- *
4880
- * **Details**
4881
- *
4882
- * `Context.Reference` allows you to create a key that can hold a value. You
4883
- * can provide a default value for the service, which will automatically be used
4884
- * when the context is accessed, or override it with a custom implementation
4885
- * when needed. The default value is computed lazily and cached on the
4886
- * reference.
4887
- *
4888
- * **Example** (Creating references with default values)
4889
- *
4890
- * ```ts
4891
- * import { Context } from "effect"
4892
- *
4893
- * // Create a reference with a default value
4894
- * const LoggerRef = Context.Reference("Logger", {
4895
- * defaultValue: () => ({ log: (msg: string) => console.log(msg) })
4896
- * })
4897
- *
4898
- * // The reference provides the default value when accessed from an empty context
4899
- * const context = Context.empty()
4900
- * const logger = Context.get(context, LoggerRef)
4901
- *
4902
- * // You can also override the default value
4903
- * const customContext = Context.make(LoggerRef, {
4904
- * log: (msg: string) => `Custom: ${msg}`
4905
- * })
4906
- * const customLogger = Context.get(customContext, LoggerRef)
4907
- * ```
4908
- *
4909
- * @see {@link Service} for required services without default values
4910
- *
4911
- * @category references
4912
- * @since 3.11.0
4913
- */
4914
- const Reference = Service;
4915
- //#endregion
4916
- export { Done as $, hash as $t, none as A, identity as An, isInterruptReason as At, mapInput as B, format as Bt, isNone as C, constFalse as Cn, exitSucceed as Ct, makeEquivalence as D, constant as Dn, isEffect as Dt, liftThrowable as E, constVoid as En, isDone as Et, isGreaterThan as F, BaseProto as Ft, succeed as G, currentFiberTypeId as Gt, fail as H, formatJson as Ht, isGreaterThanOrEqualTo as I, Class as It, make$2 as J, asEquivalence as Jt, Array_ as K, redact as Kt, isLessThan as L, NodeInspectSymbol as Lt, BigInt as M, pipe as Mn, makePrimitiveProto as Mt, Date$1 as N, Class$1 as Nn, withFiber as Nt, map as O, dual as On, isExit as Ot, Number$1 as P, pipeArguments as Pn, internalCall as Pt, Die as Q, combine as Qt, isLessThanOrEqualTo as R, toJson as Rt, getOrUndefined as S, isUnknown as Sn, exitFailCause as St, isSome as T, constUndefined as Tn, isCauseReason as Tt, isFailure as U, formatPath as Ut, min as V, formatDate as Vt, isSuccess as W, formatPropertyKey as Wt, Prototype as X, symbol as Xt, strictEqual as Y, equals as Yt, CauseImpl as Z, array as Zt, flatMap as _, isObject as _n, contE as _t, get as a, hasProperty as an, ReasonBase as at, getOrElse$1 as b, isTagged as bn, exitDie as bt, getReferenceUnsafe as c, isError as cn, Yield as ct, make as d, isNever as dn, causeEmpty as dt, number as en, Error$1 as et, makeUnsafe as f, isNotNull as fn, causeFail as ft, filter as g, isNumber as gn, contAll as gt, mutate as h, isNullish as hn, contA as ht, empty as i, symbol$1 as in, PipeInspectableProto as it, some as j, memoize as jn, makePrimitive as jt, match as k, flow as kn, isFailReason as kt, getUnsafe as l, isFunction as ln, args as lt, mergeAll as m, isNotUndefined as mn, constEmptyAnnotations as mt, Service as n, string as nn, Fail as nt, getOption as o, isBigInt as on, StackTraceKey as ot, merge as p, isNotNullish as pn, causeFromReasons as pt, Tuple as q, symbolRedactable as qt, add as r, structure as rn, InterruptorStackTrace as rt, getOrElse as s, isBoolean as sn, TaggedError as st, Reference as t, random as tn, ExitTypeId as tt, isContext as u, isIterable as un, causeAnnotate as ut, fromNullishOr as v, isPropertyKey as vn, done as vt, isOption as w, constTrue as wn, isCause as wt, getOrThrow as x, isUndefined as xn, exitFail as xt, fromUndefinedOr as y, isString as yn, evaluate as yt, make$1 as z, toStringUnknown as zt };