@systemfsoftware/stryker-js-vitest-runner 7.1.0 → 7.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/README.md +9 -13
- package/dist/index.mjs +1 -1
- package/dist/main.mjs +57943 -53702
- package/dist/stryker-setup.mjs +1827 -17
- package/package.json +19 -19
package/dist/stryker-setup.mjs
CHANGED
|
@@ -1,22 +1,1840 @@
|
|
|
1
1
|
import { afterAll, afterEach, beforeAll, beforeEach, inject } from "vitest";
|
|
2
|
-
//#region
|
|
2
|
+
//#region ../../node_modules/.pnpm/effect@4.0.0-rc.117/node_modules/effect/dist/Pipeable.js
|
|
3
|
+
/**
|
|
4
|
+
* The `Pipeable` module defines the shared interface and implementation helpers
|
|
5
|
+
* for values that support Effect-style method chaining with `.pipe(...)`.
|
|
6
|
+
*
|
|
7
|
+
* A `Pipeable` value can pass itself through a sequence of unary functions from
|
|
8
|
+
* left to right, so code can be written as `value.pipe(f, g, h)` instead of
|
|
9
|
+
* deeply nesting calls. This is the method form used by many Effect data types
|
|
10
|
+
* to compose transformations, validations, and effectful operations while
|
|
11
|
+
* keeping the original value as the starting point of the pipeline.
|
|
12
|
+
*
|
|
13
|
+
* @since 2.0.0
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* Applies a `pipe` method's variadic arguments to an initial value from left
|
|
17
|
+
* to right.
|
|
18
|
+
*
|
|
19
|
+
* **When to use**
|
|
20
|
+
*
|
|
21
|
+
* Use to implement a custom `.pipe(...)` method from JavaScript's `arguments`
|
|
22
|
+
* object.
|
|
23
|
+
*
|
|
24
|
+
* **Details**
|
|
25
|
+
*
|
|
26
|
+
* This helper is intended for implementing `Pipeable.pipe` methods that
|
|
27
|
+
* receive JavaScript's `arguments` object. With no functions it returns the
|
|
28
|
+
* original value; otherwise it feeds each result into the next function.
|
|
29
|
+
*
|
|
30
|
+
* **Example** (Implementing a pipe method)
|
|
31
|
+
*
|
|
32
|
+
* ```ts import.meta.vitest
|
|
33
|
+
* import { Pipeable } from "effect"
|
|
34
|
+
*
|
|
35
|
+
* class NumberBox {
|
|
36
|
+
* constructor(readonly value: number) {}
|
|
37
|
+
*
|
|
38
|
+
* pipe(..._fns: ReadonlyArray<(value: number) => number>): number {
|
|
39
|
+
* return Pipeable.pipeArguments(this.value, arguments) as number
|
|
40
|
+
* }
|
|
41
|
+
* }
|
|
42
|
+
*
|
|
43
|
+
* const result = new NumberBox(5).pipe(
|
|
44
|
+
* (n) => n + 2,
|
|
45
|
+
* (n) => n * 3
|
|
46
|
+
* )
|
|
47
|
+
* result // => 21
|
|
48
|
+
* ```
|
|
49
|
+
*
|
|
50
|
+
* @category combinators
|
|
51
|
+
* @since 2.0.0
|
|
52
|
+
*/
|
|
53
|
+
const pipeArguments = (self, args) => {
|
|
54
|
+
switch (args.length) {
|
|
55
|
+
case 0: return self;
|
|
56
|
+
case 1: return args[0](self);
|
|
57
|
+
case 2: return args[1](args[0](self));
|
|
58
|
+
case 3: return args[2](args[1](args[0](self)));
|
|
59
|
+
case 4: return args[3](args[2](args[1](args[0](self))));
|
|
60
|
+
case 5: return args[4](args[3](args[2](args[1](args[0](self)))));
|
|
61
|
+
case 6: return args[5](args[4](args[3](args[2](args[1](args[0](self))))));
|
|
62
|
+
case 7: return args[6](args[5](args[4](args[3](args[2](args[1](args[0](self)))))));
|
|
63
|
+
case 8: return args[7](args[6](args[5](args[4](args[3](args[2](args[1](args[0](self))))))));
|
|
64
|
+
case 9: return args[8](args[7](args[6](args[5](args[4](args[3](args[2](args[1](args[0](self)))))))));
|
|
65
|
+
default: {
|
|
66
|
+
let ret = self;
|
|
67
|
+
for (let i = 0, len = args.length; i < len; i++) ret = args[i](ret);
|
|
68
|
+
return ret;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
//#endregion
|
|
73
|
+
//#region ../../node_modules/.pnpm/effect@4.0.0-rc.117/node_modules/effect/dist/Function.js
|
|
74
|
+
/**
|
|
75
|
+
* Creates a function that can be called in data-first style or data-last
|
|
76
|
+
* (`pipe`-friendly) style.
|
|
77
|
+
*
|
|
78
|
+
* **When to use**
|
|
79
|
+
*
|
|
80
|
+
* Use to expose one implementation through both direct and `pipe`-friendly
|
|
81
|
+
* call styles.
|
|
82
|
+
*
|
|
83
|
+
* **Details**
|
|
84
|
+
*
|
|
85
|
+
* Pass either the arity of the uncurried function or a predicate that decides
|
|
86
|
+
* whether the current call is data-first. Arity is the common case. Use a
|
|
87
|
+
* predicate when optional arguments make arity ambiguous.
|
|
88
|
+
*
|
|
89
|
+
* **Example** (Selecting data-first or data-last style by arity)
|
|
90
|
+
*
|
|
91
|
+
* ```ts import.meta.vitest
|
|
92
|
+
* import { Function, pipe } from "effect"
|
|
93
|
+
*
|
|
94
|
+
* const sum = Function.dual<
|
|
95
|
+
* (that: number) => (self: number) => number,
|
|
96
|
+
* (self: number, that: number) => number
|
|
97
|
+
* >(2, (self, that) => self + that)
|
|
98
|
+
*
|
|
99
|
+
* sum(2, 3) // => 5
|
|
100
|
+
* pipe(2, sum(3)) // => 5
|
|
101
|
+
* ```
|
|
102
|
+
*
|
|
103
|
+
* **Example** (Defining overloads with call signatures)
|
|
104
|
+
*
|
|
105
|
+
* ```ts import.meta.vitest
|
|
106
|
+
* import { Function, pipe } from "effect"
|
|
107
|
+
*
|
|
108
|
+
* const sum: {
|
|
109
|
+
* (that: number): (self: number) => number
|
|
110
|
+
* (self: number, that: number): number
|
|
111
|
+
* } = Function.dual(2, (self: number, that: number): number => self + that)
|
|
112
|
+
*
|
|
113
|
+
* sum(2, 3) // => 5
|
|
114
|
+
* pipe(2, sum(3)) // => 5
|
|
115
|
+
* ```
|
|
116
|
+
*
|
|
117
|
+
* **Example** (Selecting data-first or data-last style with a predicate)
|
|
118
|
+
*
|
|
119
|
+
* ```ts import.meta.vitest
|
|
120
|
+
* import { Function, pipe } from "effect"
|
|
121
|
+
*
|
|
122
|
+
* const sum = Function.dual<
|
|
123
|
+
* (that: number) => (self: number) => number,
|
|
124
|
+
* (self: number, that: number) => number
|
|
125
|
+
* >(
|
|
126
|
+
* (args) => args.length === 2,
|
|
127
|
+
* (self, that) => self + that
|
|
128
|
+
* )
|
|
129
|
+
*
|
|
130
|
+
* sum(2, 3) // => 5
|
|
131
|
+
* pipe(2, sum(3)) // => 5
|
|
132
|
+
* ```
|
|
133
|
+
*
|
|
134
|
+
* @category combinators
|
|
135
|
+
* @since 2.0.0
|
|
136
|
+
*/
|
|
137
|
+
const dual = function(arity, body) {
|
|
138
|
+
if (typeof arity === "function") return function() {
|
|
139
|
+
return arity(arguments) ? body.apply(this, arguments) : (self) => body(self, ...arguments);
|
|
140
|
+
};
|
|
141
|
+
switch (arity) {
|
|
142
|
+
case 0:
|
|
143
|
+
case 1: throw new RangeError(`Invalid arity ${arity}`);
|
|
144
|
+
case 2: return function(a, b) {
|
|
145
|
+
if (arguments.length >= 2) return body(a, b);
|
|
146
|
+
return function(self) {
|
|
147
|
+
return body(self, a);
|
|
148
|
+
};
|
|
149
|
+
};
|
|
150
|
+
case 3: return function(a, b, c) {
|
|
151
|
+
if (arguments.length >= 3) return body(a, b, c);
|
|
152
|
+
return function(self) {
|
|
153
|
+
return body(self, a, b);
|
|
154
|
+
};
|
|
155
|
+
};
|
|
156
|
+
default: return function() {
|
|
157
|
+
if (arguments.length >= arity) return body.apply(this, arguments);
|
|
158
|
+
const args = arguments;
|
|
159
|
+
return function(self) {
|
|
160
|
+
return body(self, ...args);
|
|
161
|
+
};
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
/**
|
|
166
|
+
* Returns its input argument unchanged.
|
|
167
|
+
*
|
|
168
|
+
* **When to use**
|
|
169
|
+
*
|
|
170
|
+
* Use to return a value unchanged where a function is required.
|
|
171
|
+
*
|
|
172
|
+
* **Example** (Returning the same value)
|
|
173
|
+
*
|
|
174
|
+
* ```ts import.meta.vitest
|
|
175
|
+
* import { identity } from "effect"
|
|
176
|
+
*
|
|
177
|
+
* identity(5) // => 5
|
|
178
|
+
* ```
|
|
179
|
+
*
|
|
180
|
+
* @category combinators
|
|
181
|
+
* @since 2.0.0
|
|
182
|
+
*/
|
|
183
|
+
const identity = (a) => a;
|
|
184
|
+
//#endregion
|
|
185
|
+
//#region ../../node_modules/.pnpm/effect@4.0.0-rc.117/node_modules/effect/dist/internal/equal.js
|
|
186
|
+
/** @internal */
|
|
187
|
+
const getAllObjectKeys = (obj) => {
|
|
188
|
+
const keys = new Set(Reflect.ownKeys(obj));
|
|
189
|
+
if (obj.constructor === Object) return keys;
|
|
190
|
+
if (obj instanceof Error) keys.delete("stack");
|
|
191
|
+
const proto = Object.getPrototypeOf(obj);
|
|
192
|
+
let current = proto;
|
|
193
|
+
while (current !== null && current !== Object.prototype) {
|
|
194
|
+
const ownKeys = Reflect.ownKeys(current);
|
|
195
|
+
for (let i = 0; i < ownKeys.length; i++) keys.add(ownKeys[i]);
|
|
196
|
+
current = Object.getPrototypeOf(current);
|
|
197
|
+
}
|
|
198
|
+
if (keys.has("constructor") && typeof obj.constructor === "function" && proto === obj.constructor.prototype) keys.delete("constructor");
|
|
199
|
+
return keys;
|
|
200
|
+
};
|
|
201
|
+
/** @internal */
|
|
202
|
+
const byReferenceInstances = /*#__PURE__*/ new WeakSet();
|
|
203
|
+
//#endregion
|
|
204
|
+
//#region ../../node_modules/.pnpm/effect@4.0.0-rc.117/node_modules/effect/dist/Predicate.js
|
|
205
|
+
/**
|
|
206
|
+
* Defines runtime checks for values.
|
|
207
|
+
*
|
|
208
|
+
* A `Predicate<A>` returns `true` or `false` for an `A`. A
|
|
209
|
+
* `Refinement<A, B>` is a predicate that also narrows the TypeScript type when
|
|
210
|
+
* it succeeds. This module includes guards for common JavaScript values,
|
|
211
|
+
* property and tag checks, tuple and struct checks, boolean combinators, and
|
|
212
|
+
* helpers for composing predicates and refinements.
|
|
213
|
+
*
|
|
214
|
+
* @since 2.0.0
|
|
215
|
+
*/
|
|
216
|
+
/**
|
|
217
|
+
* Checks whether a value is a `function`.
|
|
218
|
+
*
|
|
219
|
+
* **When to use**
|
|
220
|
+
*
|
|
221
|
+
* Use when you need a `Predicate` guard to narrow an `unknown` value to a
|
|
222
|
+
* callable function.
|
|
223
|
+
*
|
|
224
|
+
* **Details**
|
|
225
|
+
*
|
|
226
|
+
* Uses `typeof input === "function"`.
|
|
227
|
+
*
|
|
228
|
+
* **Example** (Guarding functions)
|
|
229
|
+
*
|
|
230
|
+
* ```ts import.meta.vitest
|
|
231
|
+
* import { Predicate } from "effect"
|
|
232
|
+
*
|
|
233
|
+
* const data: unknown = () => 1
|
|
234
|
+
*
|
|
235
|
+
* if (Predicate.isFunction(data)) {
|
|
236
|
+
* data() // => 1
|
|
237
|
+
* }
|
|
238
|
+
* ```
|
|
239
|
+
*
|
|
240
|
+
* @see {@link isObjectKeyword}
|
|
241
|
+
* @category guards
|
|
242
|
+
* @since 2.0.0
|
|
243
|
+
*/
|
|
244
|
+
function isFunction(input) {
|
|
245
|
+
return typeof input === "function";
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Checks whether a value is an `object` in the JavaScript sense (objects, arrays, functions).
|
|
249
|
+
*
|
|
250
|
+
* **When to use**
|
|
251
|
+
*
|
|
252
|
+
* Use when you need a `Predicate` guard that accepts arrays and functions as
|
|
253
|
+
* well as objects.
|
|
254
|
+
*
|
|
255
|
+
* **Details**
|
|
256
|
+
*
|
|
257
|
+
* Returns `true` for arrays and functions, and `false` for `null`.
|
|
258
|
+
*
|
|
259
|
+
* **Example** (Checking object keywords)
|
|
260
|
+
*
|
|
261
|
+
* ```ts import.meta.vitest
|
|
262
|
+
* import { Predicate } from "effect"
|
|
263
|
+
*
|
|
264
|
+
* Predicate.isObjectKeyword(() => 1) // => true
|
|
265
|
+
* Predicate.isObjectKeyword(null) // => false
|
|
266
|
+
* ```
|
|
267
|
+
*
|
|
268
|
+
* @see {@link isObject}
|
|
269
|
+
* @see {@link isObjectOrArray}
|
|
270
|
+
* @category guards
|
|
271
|
+
* @since 4.0.0
|
|
272
|
+
*/
|
|
273
|
+
function isObjectKeyword(input) {
|
|
274
|
+
return typeof input === "object" && input !== null || isFunction(input);
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Checks whether a value has a given property key.
|
|
278
|
+
*
|
|
279
|
+
* **When to use**
|
|
280
|
+
*
|
|
281
|
+
* Use when you need a `Predicate` guard for property access on `unknown`
|
|
282
|
+
* values with a simple structural object check.
|
|
283
|
+
*
|
|
284
|
+
* **Details**
|
|
285
|
+
*
|
|
286
|
+
* Uses the `in` operator and `isObjectKeyword`. This does not check property
|
|
287
|
+
* value types.
|
|
288
|
+
*
|
|
289
|
+
* **Example** (Guarding object properties)
|
|
290
|
+
*
|
|
291
|
+
* ```ts import.meta.vitest
|
|
292
|
+
* import { Predicate } from "effect"
|
|
293
|
+
*
|
|
294
|
+
* const hasName = Predicate.hasProperty("name")
|
|
295
|
+
* const data: unknown = { name: "Ada" }
|
|
296
|
+
*
|
|
297
|
+
* if (hasName(data)) {
|
|
298
|
+
* data.name // => "Ada"
|
|
299
|
+
* }
|
|
300
|
+
* ```
|
|
301
|
+
*
|
|
302
|
+
* @see {@link isTagged}
|
|
303
|
+
* @see {@link isObjectKeyword}
|
|
304
|
+
* @category guards
|
|
305
|
+
* @since 2.0.0
|
|
306
|
+
*/
|
|
307
|
+
const hasProperty = /*#__PURE__*/ dual(2, (self, property) => isObjectKeyword(self) && property in self);
|
|
308
|
+
//#endregion
|
|
309
|
+
//#region ../../node_modules/.pnpm/effect@4.0.0-rc.117/node_modules/effect/dist/Hash.js
|
|
310
|
+
/**
|
|
311
|
+
* Computes Effect hash values and defines the interface for objects that want
|
|
312
|
+
* to provide their own hash implementation. Hashes are small numeric
|
|
313
|
+
* fingerprints used by Effect data structures to bucket values quickly; they
|
|
314
|
+
* are not cryptographic digests and they are not proof that two values are
|
|
315
|
+
* equal. The module also includes helpers for primitive, structure, array, and
|
|
316
|
+
* reference-based hashes, plus functions for combining and optimizing numeric
|
|
317
|
+
* hash values.
|
|
318
|
+
*
|
|
319
|
+
* @since 2.0.0
|
|
320
|
+
*/
|
|
321
|
+
/**
|
|
322
|
+
* Defines the unique identifier used to identify objects that implement the Hash interface.
|
|
323
|
+
*
|
|
324
|
+
* **When to use**
|
|
325
|
+
*
|
|
326
|
+
* Use as the computed property key for the method that supplies a custom hash
|
|
327
|
+
* value on a `Hash` implementor.
|
|
328
|
+
*
|
|
329
|
+
* @see {@link Hash} for the interface implemented with this symbol
|
|
330
|
+
* @see {@link isHash} for checking whether a value implements `Hash`
|
|
331
|
+
* @see {@link hash} for computing hash values
|
|
332
|
+
*
|
|
333
|
+
* @category symbols
|
|
334
|
+
* @since 2.0.0
|
|
335
|
+
*/
|
|
336
|
+
const symbol$1 = "~effect/Hash";
|
|
337
|
+
/**
|
|
338
|
+
* Computes a hash value for any given value.
|
|
339
|
+
*
|
|
340
|
+
* **When to use**
|
|
341
|
+
*
|
|
342
|
+
* Use to compute an Effect hash for primitives, collections, and hashable
|
|
343
|
+
* objects.
|
|
344
|
+
*
|
|
345
|
+
* **Details**
|
|
346
|
+
*
|
|
347
|
+
* This function can hash primitives (numbers, strings, booleans, etc.) as well as
|
|
348
|
+
* objects, arrays, and other complex data structures. It automatically handles
|
|
349
|
+
* different types and provides a consistent hash value for equivalent inputs.
|
|
350
|
+
*
|
|
351
|
+
* **Gotchas**
|
|
352
|
+
*
|
|
353
|
+
* Objects being hashed must be treated as immutable after their first hash
|
|
354
|
+
* computation. Hash results are cached, so mutating an object after hashing will
|
|
355
|
+
* lead to stale cached values and broken hash-based operations. For mutable
|
|
356
|
+
* objects, implement a custom `Hash` interface that hashes the object reference
|
|
357
|
+
* rather than its content.
|
|
358
|
+
*
|
|
359
|
+
* **Example** (Hashing different values)
|
|
360
|
+
*
|
|
361
|
+
* ```ts import.meta.vitest
|
|
362
|
+
* import { Hash } from "effect"
|
|
363
|
+
*
|
|
364
|
+
* Hash.hash(42) === Hash.hash(42) // => true
|
|
365
|
+
* Hash.hash("hello") === Hash.hash("hello") // => true
|
|
366
|
+
* Hash.hash([1, 2, 3]) === Hash.hash([1, 2, 3]) // => true
|
|
367
|
+
* ```
|
|
368
|
+
*
|
|
369
|
+
* @category hashing
|
|
370
|
+
* @since 2.0.0
|
|
371
|
+
*/
|
|
372
|
+
const hash = (self) => {
|
|
373
|
+
switch (typeof self) {
|
|
374
|
+
case "number": return number(self);
|
|
375
|
+
case "bigint": return string(self.toString(10));
|
|
376
|
+
case "string": return string(self);
|
|
377
|
+
case "undefined": return string("undefined");
|
|
378
|
+
case "function":
|
|
379
|
+
case "object": if (self === null) return string("null");
|
|
380
|
+
else if (self instanceof Date) {
|
|
381
|
+
if (Number.isNaN(self.getTime())) return string("Invalid Date");
|
|
382
|
+
return string(self.toISOString());
|
|
383
|
+
} else if (self instanceof RegExp) return string(self.toString());
|
|
384
|
+
else {
|
|
385
|
+
if (byReferenceInstances.has(self)) return random(self);
|
|
386
|
+
if (hashCache.has(self)) return hashCache.get(self);
|
|
387
|
+
const h = withVisitedTracking$1(self, () => {
|
|
388
|
+
if (isHash(self)) return self[symbol$1]();
|
|
389
|
+
else if (typeof self === "function") return random(self);
|
|
390
|
+
else if (self instanceof DataView) return array(new Uint8Array(self.buffer, self.byteOffset, self.byteLength));
|
|
391
|
+
else if (Array.isArray(self) || ArrayBuffer.isView(self)) return array(self);
|
|
392
|
+
else if (self instanceof Map) return hashMap(self);
|
|
393
|
+
else if (self instanceof Set) return hashSet(self);
|
|
394
|
+
return structure(self);
|
|
395
|
+
});
|
|
396
|
+
hashCache.set(self, h);
|
|
397
|
+
return h;
|
|
398
|
+
}
|
|
399
|
+
default: return string(String(self));
|
|
400
|
+
}
|
|
401
|
+
};
|
|
402
|
+
/**
|
|
403
|
+
* Generates a random hash value for an object and caches it.
|
|
404
|
+
*
|
|
405
|
+
* **When to use**
|
|
406
|
+
*
|
|
407
|
+
* Use to hash an object by reference identity instead of structural content.
|
|
408
|
+
*
|
|
409
|
+
* **Details**
|
|
410
|
+
*
|
|
411
|
+
* This function creates a random hash value for objects that don't have their own
|
|
412
|
+
* hash implementation. The hash value is cached using a WeakMap, so the same object
|
|
413
|
+
* will always return the same hash value during its lifetime.
|
|
414
|
+
*
|
|
415
|
+
* **Example** (Hashing objects by reference)
|
|
416
|
+
*
|
|
417
|
+
* ```ts import.meta.vitest
|
|
418
|
+
* import { Hash } from "effect"
|
|
419
|
+
*
|
|
420
|
+
* const obj1 = { a: 1 }
|
|
421
|
+
* const obj2 = { a: 1 }
|
|
422
|
+
*
|
|
423
|
+
* Hash.random(obj1) === Hash.random(obj1) // => true
|
|
424
|
+
*
|
|
425
|
+
* typeof Hash.random(obj2) // => "number"
|
|
426
|
+
* ```
|
|
427
|
+
*
|
|
428
|
+
* @category hashing
|
|
429
|
+
* @since 2.0.0
|
|
430
|
+
*/
|
|
431
|
+
const random = (self) => {
|
|
432
|
+
if (!randomHashCache.has(self)) randomHashCache.set(self, number(Math.floor(Math.random() * Number.MAX_SAFE_INTEGER)));
|
|
433
|
+
return randomHashCache.get(self);
|
|
434
|
+
};
|
|
435
|
+
/**
|
|
436
|
+
* Combines two hash values into a single hash value.
|
|
437
|
+
*
|
|
438
|
+
* **When to use**
|
|
439
|
+
*
|
|
440
|
+
* Use to build a hash for a composite value by folding together hash values for
|
|
441
|
+
* its parts.
|
|
442
|
+
*
|
|
443
|
+
* **Details**
|
|
444
|
+
*
|
|
445
|
+
* Supports both direct and pipeable usage. The implementation combines two
|
|
446
|
+
* hash values with `(self * 53) ^ b`.
|
|
447
|
+
*
|
|
448
|
+
* **Example** (Combining hash values)
|
|
449
|
+
*
|
|
450
|
+
* ```ts import.meta.vitest
|
|
451
|
+
* import { Hash, pipe } from "effect"
|
|
452
|
+
*
|
|
453
|
+
* const hash1 = Hash.hash("hello")
|
|
454
|
+
* const hash2 = Hash.hash("world")
|
|
455
|
+
*
|
|
456
|
+
* const combined = Hash.combine(hash2)(hash1)
|
|
457
|
+
* combined === pipe(hash1, Hash.combine(hash2)) // => true
|
|
458
|
+
* ```
|
|
459
|
+
*
|
|
460
|
+
* @see {@link hash} for computing hash values from arbitrary inputs
|
|
461
|
+
* @see {@link structureKeys} for hashing selected object fields without manual combination
|
|
462
|
+
*
|
|
463
|
+
* @category hashing
|
|
464
|
+
* @since 2.0.0
|
|
465
|
+
*/
|
|
466
|
+
const combine = /*#__PURE__*/ dual(2, (self, b) => self * 53 ^ b);
|
|
467
|
+
/**
|
|
468
|
+
* Applies bit manipulation techniques to optimize a hash value.
|
|
469
|
+
*
|
|
470
|
+
* **When to use**
|
|
471
|
+
*
|
|
472
|
+
* Use to improve the bit distribution of a raw numeric hash value.
|
|
473
|
+
*
|
|
474
|
+
* **Details**
|
|
475
|
+
*
|
|
476
|
+
* This function takes a hash value and applies bitwise operations to improve
|
|
477
|
+
* the distribution of hash values, reducing the likelihood of collisions.
|
|
478
|
+
*
|
|
479
|
+
* **Example** (Optimizing a hash value)
|
|
480
|
+
*
|
|
481
|
+
* ```ts import.meta.vitest
|
|
482
|
+
* import { Hash } from "effect"
|
|
483
|
+
*
|
|
484
|
+
* Hash.optimize(1234567890) // => 160826066
|
|
485
|
+
* ```
|
|
486
|
+
*
|
|
487
|
+
* @category hashing
|
|
488
|
+
* @since 2.0.0
|
|
489
|
+
*/
|
|
490
|
+
const optimize = (n) => n & 3221225471 | n >>> 1 & 1073741824;
|
|
491
|
+
/**
|
|
492
|
+
* Checks whether a value implements the Hash interface.
|
|
493
|
+
*
|
|
494
|
+
* **When to use**
|
|
495
|
+
*
|
|
496
|
+
* Use to detect whether an unknown value provides a custom hash implementation.
|
|
497
|
+
*
|
|
498
|
+
* **Details**
|
|
499
|
+
*
|
|
500
|
+
* This function determines whether a given value has the Hash symbol property,
|
|
501
|
+
* indicating that it can provide its own hash value implementation.
|
|
502
|
+
*
|
|
503
|
+
* **Example** (Checking for Hash support)
|
|
504
|
+
*
|
|
505
|
+
* ```ts import.meta.vitest
|
|
506
|
+
* import { Hash } from "effect"
|
|
507
|
+
*
|
|
508
|
+
* class MyHashable implements Hash.Hash {
|
|
509
|
+
* [Hash.symbol]() {
|
|
510
|
+
* return 42
|
|
511
|
+
* }
|
|
512
|
+
* }
|
|
513
|
+
*
|
|
514
|
+
* Hash.isHash(new MyHashable()) // => true
|
|
515
|
+
* Hash.isHash({}) // => false
|
|
516
|
+
* Hash.isHash("string") // => false
|
|
517
|
+
* ```
|
|
518
|
+
*
|
|
519
|
+
* @category guards
|
|
520
|
+
* @since 2.0.0
|
|
521
|
+
*/
|
|
522
|
+
const isHash = (u) => hasProperty(u, symbol$1);
|
|
523
|
+
/**
|
|
524
|
+
* Computes a hash value for a number.
|
|
525
|
+
*
|
|
526
|
+
* **When to use**
|
|
527
|
+
*
|
|
528
|
+
* Use to hash a JavaScript number with Effect's numeric hash semantics.
|
|
529
|
+
*
|
|
530
|
+
* **Details**
|
|
531
|
+
*
|
|
532
|
+
* This function creates a hash value for numeric inputs, handling special cases
|
|
533
|
+
* like NaN, Infinity, and -Infinity with distinct hash values. It uses bitwise operations to ensure good distribution
|
|
534
|
+
* of hash values across different numeric inputs.
|
|
535
|
+
*
|
|
536
|
+
* **Example** (Hashing numbers)
|
|
537
|
+
*
|
|
538
|
+
* ```ts import.meta.vitest
|
|
539
|
+
* import { Hash } from "effect"
|
|
540
|
+
*
|
|
541
|
+
* Number.isInteger(Hash.number(42)) // => true
|
|
542
|
+
* Number.isInteger(Hash.number(3.14)) // => true
|
|
543
|
+
* Hash.number(NaN) === Hash.number(NaN) // => true
|
|
544
|
+
* Hash.number(Infinity) === Hash.number(Infinity) // => true
|
|
545
|
+
* Hash.number(100) === Hash.number(100) // => true
|
|
546
|
+
* ```
|
|
547
|
+
*
|
|
548
|
+
* @category hashing
|
|
549
|
+
* @since 2.0.0
|
|
550
|
+
*/
|
|
551
|
+
const number = (n) => {
|
|
552
|
+
if (n !== n || n === Infinity || n === -Infinity) return string(String(n));
|
|
553
|
+
let h = n | 0;
|
|
554
|
+
if (h !== n) h ^= n * 4294967295;
|
|
555
|
+
while (n > 4294967295) h ^= n /= 4294967295;
|
|
556
|
+
return optimize(h);
|
|
557
|
+
};
|
|
558
|
+
/**
|
|
559
|
+
* Computes a hash value for a string using the djb2 algorithm.
|
|
560
|
+
*
|
|
561
|
+
* **When to use**
|
|
562
|
+
*
|
|
563
|
+
* Use when you need a string field to contribute to a custom structural hash
|
|
564
|
+
* implementation.
|
|
565
|
+
*
|
|
566
|
+
* **Details**
|
|
567
|
+
*
|
|
568
|
+
* This function implements a variation of the djb2 hash algorithm, which is
|
|
569
|
+
* known for its good distribution properties and speed. It processes each
|
|
570
|
+
* character of the string to produce a consistent hash value.
|
|
571
|
+
*
|
|
572
|
+
* **Example** (Hashing strings)
|
|
573
|
+
*
|
|
574
|
+
* ```ts import.meta.vitest
|
|
575
|
+
* import { Hash } from "effect"
|
|
576
|
+
*
|
|
577
|
+
* Hash.string("hello") // => 181380007
|
|
578
|
+
* Hash.string("world") // => 164394279
|
|
579
|
+
* Hash.string("") // => 5381
|
|
580
|
+
* Hash.string("test") === Hash.string("test") // => true
|
|
581
|
+
* ```
|
|
582
|
+
*
|
|
583
|
+
* @category hashing
|
|
584
|
+
* @since 2.0.0
|
|
585
|
+
*/
|
|
586
|
+
const string = (str) => {
|
|
587
|
+
let h = 5381, i = str.length;
|
|
588
|
+
while (i) h = h * 33 ^ str.charCodeAt(--i);
|
|
589
|
+
return optimize(h);
|
|
590
|
+
};
|
|
591
|
+
/**
|
|
592
|
+
* Computes a hash value for an object using only the specified keys.
|
|
593
|
+
*
|
|
594
|
+
* **When to use**
|
|
595
|
+
*
|
|
596
|
+
* Use to hash an object by a selected set of property keys.
|
|
597
|
+
*
|
|
598
|
+
* **Details**
|
|
599
|
+
*
|
|
600
|
+
* This function allows you to hash an object by considering only specific keys,
|
|
601
|
+
* which is useful when you want to create a hash based on a subset of an object's
|
|
602
|
+
* properties.
|
|
603
|
+
*
|
|
604
|
+
* **Example** (Hashing selected object keys)
|
|
605
|
+
*
|
|
606
|
+
* ```ts import.meta.vitest
|
|
607
|
+
* import { Hash } from "effect"
|
|
608
|
+
*
|
|
609
|
+
* const person = { name: "John", age: 30, city: "New York" }
|
|
610
|
+
*
|
|
611
|
+
* const hash1 = Hash.structureKeys(person, ["name", "age"])
|
|
612
|
+
* const hash2 = Hash.structureKeys(person, ["name", "city"])
|
|
613
|
+
*
|
|
614
|
+
* hash1 // => -590673747
|
|
615
|
+
* hash2 // => 284850673
|
|
616
|
+
*
|
|
617
|
+
* const person2 = { name: "John", age: 30, city: "Boston" }
|
|
618
|
+
* const hash3 = Hash.structureKeys(person2, ["name", "age"])
|
|
619
|
+
* hash1 === hash3 // => true
|
|
620
|
+
* ```
|
|
621
|
+
*
|
|
622
|
+
* @category hashing
|
|
623
|
+
* @since 2.0.0
|
|
624
|
+
*/
|
|
625
|
+
const structureKeys = (o, keys) => {
|
|
626
|
+
let h = 12289;
|
|
627
|
+
for (const key of keys) h ^= combine(hash(key), hash(o[key]));
|
|
628
|
+
return optimize(h);
|
|
629
|
+
};
|
|
630
|
+
/**
|
|
631
|
+
* Computes a structural hash for an object using Effect's object key collection.
|
|
632
|
+
*
|
|
633
|
+
* **When to use**
|
|
634
|
+
*
|
|
635
|
+
* Use to hash an object from all structural keys collected by Effect.
|
|
636
|
+
*
|
|
637
|
+
* **Details**
|
|
638
|
+
*
|
|
639
|
+
* The hash is based on the object's structural keys and their values, including
|
|
640
|
+
* symbol keys and relevant prototype keys for non-plain objects.
|
|
641
|
+
*
|
|
642
|
+
* **Example** (Hashing object structures)
|
|
643
|
+
*
|
|
644
|
+
* ```ts import.meta.vitest
|
|
645
|
+
* import { Hash } from "effect"
|
|
646
|
+
*
|
|
647
|
+
* const obj1 = { name: "John", age: 30 }
|
|
648
|
+
* const obj2 = { name: "Jane", age: 25 }
|
|
649
|
+
* const obj3 = { name: "John", age: 30 }
|
|
650
|
+
*
|
|
651
|
+
* Hash.structure(obj1) // => -590673747
|
|
652
|
+
* Hash.structure(obj2) // => -590160631
|
|
653
|
+
* Hash.structure(obj3) // => -590673747
|
|
654
|
+
* Hash.structure(obj1) === Hash.structure(obj3) // => true
|
|
655
|
+
* ```
|
|
656
|
+
*
|
|
657
|
+
* @category hashing
|
|
658
|
+
* @since 2.0.0
|
|
659
|
+
*/
|
|
660
|
+
const structure = (o) => structureKeys(o, getAllObjectKeys(o));
|
|
661
|
+
const iterableWith = (seed, f) => (iter) => {
|
|
662
|
+
let h = seed;
|
|
663
|
+
for (const element of iter) h ^= f(element);
|
|
664
|
+
return optimize(h);
|
|
665
|
+
};
|
|
666
|
+
/**
|
|
667
|
+
* Computes a hash value for an iterable by hashing all of its elements.
|
|
668
|
+
*
|
|
669
|
+
* **When to use**
|
|
670
|
+
*
|
|
671
|
+
* Use to hash the values yielded by an iterable with Effect hash semantics.
|
|
672
|
+
*
|
|
673
|
+
* **Details**
|
|
674
|
+
*
|
|
675
|
+
* The implementation folds element hashes from the seed `6151` with XOR and
|
|
676
|
+
* then optimizes the final hash.
|
|
677
|
+
*
|
|
678
|
+
* **Gotchas**
|
|
679
|
+
*
|
|
680
|
+
* A hash is not an equality proof. Because this implementation uses XOR,
|
|
681
|
+
* reordered inputs can produce the same hash.
|
|
682
|
+
*
|
|
683
|
+
* **Example** (Hashing arrays)
|
|
684
|
+
*
|
|
685
|
+
* ```ts import.meta.vitest
|
|
686
|
+
* import { Hash } from "effect"
|
|
687
|
+
*
|
|
688
|
+
* const arr1 = [1, 2, 3]
|
|
689
|
+
* const arr2 = [1, 2, 3]
|
|
690
|
+
* const arr3 = [3, 2, 1]
|
|
691
|
+
*
|
|
692
|
+
* Hash.array(arr1) // => 6151
|
|
693
|
+
* Hash.array(arr2) // => 6151
|
|
694
|
+
* Hash.array(arr3) // => 6151
|
|
695
|
+
* Hash.array(arr1) === Hash.array(arr2) // => true
|
|
696
|
+
* Hash.array(arr1) === Hash.array(arr3) // => true
|
|
697
|
+
* ```
|
|
698
|
+
*
|
|
699
|
+
* @see {@link hash} for the general-purpose hash dispatcher
|
|
700
|
+
*
|
|
701
|
+
* @category hashing
|
|
702
|
+
* @since 2.0.0
|
|
703
|
+
*/
|
|
704
|
+
const array = /*#__PURE__*/ iterableWith(6151, hash);
|
|
705
|
+
const hashMap = /*#__PURE__*/ iterableWith(/*#__PURE__*/ string("Map"), ([k, v]) => combine(hash(k), hash(v)));
|
|
706
|
+
const hashSet = /*#__PURE__*/ iterableWith(/*#__PURE__*/ string("Set"), hash);
|
|
707
|
+
const randomHashCache = /*#__PURE__*/ new WeakMap();
|
|
708
|
+
const hashCache = /*#__PURE__*/ new WeakMap();
|
|
709
|
+
const visitedObjects = /*#__PURE__*/ new WeakSet();
|
|
710
|
+
function withVisitedTracking$1(obj, fn) {
|
|
711
|
+
if (visitedObjects.has(obj)) return string("[Circular]");
|
|
712
|
+
visitedObjects.add(obj);
|
|
713
|
+
const result = fn();
|
|
714
|
+
visitedObjects.delete(obj);
|
|
715
|
+
return result;
|
|
716
|
+
}
|
|
717
|
+
//#endregion
|
|
718
|
+
//#region ../../node_modules/.pnpm/effect@4.0.0-rc.117/node_modules/effect/dist/Equal.js
|
|
719
|
+
/**
|
|
720
|
+
* Defines the unique string identifier for the `Equal` interface.
|
|
721
|
+
*
|
|
722
|
+
* **When to use**
|
|
723
|
+
*
|
|
724
|
+
* Use when you implement custom equality and need the computed property key for
|
|
725
|
+
* the equality method.
|
|
726
|
+
*
|
|
727
|
+
* **Details**
|
|
728
|
+
*
|
|
729
|
+
* This is a pure constant with no allocation or side effects.
|
|
730
|
+
*
|
|
731
|
+
* **Example** (Implementing Equal on a class)
|
|
732
|
+
*
|
|
733
|
+
* ```ts import.meta.vitest
|
|
734
|
+
* import { Equal, Hash } from "effect"
|
|
735
|
+
*
|
|
736
|
+
* class UserId implements Equal.Equal {
|
|
737
|
+
* constructor(readonly id: string) {}
|
|
738
|
+
*
|
|
739
|
+
* [Equal.symbol](that: Equal.Equal): boolean {
|
|
740
|
+
* return that instanceof UserId && this.id === that.id
|
|
741
|
+
* }
|
|
742
|
+
*
|
|
743
|
+
* [Hash.symbol](): number {
|
|
744
|
+
* return Hash.string(this.id)
|
|
745
|
+
* }
|
|
746
|
+
* }
|
|
747
|
+
*
|
|
748
|
+
* Equal.equals(new UserId("1"), new UserId("1")) // => true
|
|
749
|
+
* Equal.equals(new UserId("1"), new UserId("2")) // => false
|
|
750
|
+
* ```
|
|
751
|
+
*
|
|
752
|
+
* @see {@link Equal} — the interface that uses this symbol
|
|
753
|
+
* @see {@link isEqual} — type guard for `Equal` implementors
|
|
754
|
+
* @category symbols
|
|
755
|
+
* @since 2.0.0
|
|
756
|
+
*/
|
|
757
|
+
const symbol = "~effect/Equal";
|
|
758
|
+
function equals() {
|
|
759
|
+
if (arguments.length === 1) return (self) => compareBoth(self, arguments[0]);
|
|
760
|
+
return compareBoth(arguments[0], arguments[1]);
|
|
761
|
+
}
|
|
762
|
+
function compareBoth(self, that) {
|
|
763
|
+
if (self === that) return true;
|
|
764
|
+
if (self == null || that == null) return false;
|
|
765
|
+
const selfType = typeof self;
|
|
766
|
+
if (selfType !== typeof that) return false;
|
|
767
|
+
if (selfType === "number" && self !== self && that !== that) return true;
|
|
768
|
+
if (selfType !== "object" && selfType !== "function") return false;
|
|
769
|
+
if (byReferenceInstances.has(self) || byReferenceInstances.has(that)) return false;
|
|
770
|
+
return withCache(self, that, compareObjects);
|
|
771
|
+
}
|
|
772
|
+
/** Helper to run comparison with proper visited tracking */
|
|
773
|
+
function withVisitedTracking(self, that, fn) {
|
|
774
|
+
const hasLeft = visitedLeft.has(self);
|
|
775
|
+
const hasRight = visitedRight.has(that);
|
|
776
|
+
if (hasLeft && hasRight) return true;
|
|
777
|
+
if (hasLeft || hasRight) return false;
|
|
778
|
+
visitedLeft.add(self);
|
|
779
|
+
visitedRight.add(that);
|
|
780
|
+
const result = fn();
|
|
781
|
+
visitedLeft.delete(self);
|
|
782
|
+
visitedRight.delete(that);
|
|
783
|
+
return result;
|
|
784
|
+
}
|
|
785
|
+
const visitedLeft = /*#__PURE__*/ new WeakSet();
|
|
786
|
+
const visitedRight = /*#__PURE__*/ new WeakSet();
|
|
787
|
+
/** Helper to perform cached object comparison */
|
|
788
|
+
function compareObjects(self, that) {
|
|
789
|
+
if (hash(self) !== hash(that)) return false;
|
|
790
|
+
else if (self instanceof Date) {
|
|
791
|
+
if (!(that instanceof Date)) return false;
|
|
792
|
+
const selfTime = self.getTime();
|
|
793
|
+
const thatTime = that.getTime();
|
|
794
|
+
return selfTime === thatTime || Number.isNaN(selfTime) && Number.isNaN(thatTime);
|
|
795
|
+
} else if (self instanceof RegExp) {
|
|
796
|
+
if (!(that instanceof RegExp)) return false;
|
|
797
|
+
return self.toString() === that.toString();
|
|
798
|
+
}
|
|
799
|
+
const selfIsEqual = isEqual(self);
|
|
800
|
+
const thatIsEqual = isEqual(that);
|
|
801
|
+
if (selfIsEqual !== thatIsEqual) return false;
|
|
802
|
+
const bothEquals = selfIsEqual && thatIsEqual;
|
|
803
|
+
if (typeof self === "function" && !bothEquals) return false;
|
|
804
|
+
return withVisitedTracking(self, that, () => {
|
|
805
|
+
if (bothEquals) return self[symbol](that);
|
|
806
|
+
else if (Array.isArray(self)) {
|
|
807
|
+
if (!Array.isArray(that) || self.length !== that.length) return false;
|
|
808
|
+
return compareArrays(self, that);
|
|
809
|
+
} else if (ArrayBuffer.isView(self)) {
|
|
810
|
+
const selfIsDataView = self instanceof DataView;
|
|
811
|
+
if (!ArrayBuffer.isView(that) || self.byteLength !== that.byteLength || selfIsDataView !== that instanceof DataView) return false;
|
|
812
|
+
if (selfIsDataView) {
|
|
813
|
+
const thatDataView = that;
|
|
814
|
+
return compareTypedArrays(new Uint8Array(self.buffer, self.byteOffset, self.byteLength), new Uint8Array(thatDataView.buffer, thatDataView.byteOffset, thatDataView.byteLength));
|
|
815
|
+
}
|
|
816
|
+
return compareTypedArrays(self, that);
|
|
817
|
+
} else if (self instanceof Map) {
|
|
818
|
+
if (!(that instanceof Map) || self.size !== that.size) return false;
|
|
819
|
+
return compareMaps(self, that);
|
|
820
|
+
} else if (self instanceof Set) {
|
|
821
|
+
if (!(that instanceof Set) || self.size !== that.size) return false;
|
|
822
|
+
return compareSets(self, that);
|
|
823
|
+
}
|
|
824
|
+
return compareRecords(self, that);
|
|
825
|
+
});
|
|
826
|
+
}
|
|
827
|
+
function withCache(self, that, f) {
|
|
828
|
+
let selfMap = equalityCache.get(self);
|
|
829
|
+
if (!selfMap) {
|
|
830
|
+
selfMap = /* @__PURE__ */ new WeakMap();
|
|
831
|
+
equalityCache.set(self, selfMap);
|
|
832
|
+
} else if (selfMap.has(that)) return selfMap.get(that);
|
|
833
|
+
const result = f(self, that);
|
|
834
|
+
selfMap.set(that, result);
|
|
835
|
+
let thatMap = equalityCache.get(that);
|
|
836
|
+
if (!thatMap) {
|
|
837
|
+
thatMap = /* @__PURE__ */ new WeakMap();
|
|
838
|
+
equalityCache.set(that, thatMap);
|
|
839
|
+
}
|
|
840
|
+
thatMap.set(self, result);
|
|
841
|
+
return result;
|
|
842
|
+
}
|
|
843
|
+
const equalityCache = /*#__PURE__*/ new WeakMap();
|
|
844
|
+
function compareArrays(self, that) {
|
|
845
|
+
for (let i = 0; i < self.length; i++) if (!compareBoth(self[i], that[i])) return false;
|
|
846
|
+
return true;
|
|
847
|
+
}
|
|
848
|
+
function compareTypedArrays(self, that) {
|
|
849
|
+
if (self.length !== that.length) return false;
|
|
850
|
+
for (let i = 0; i < self.length; i++) if (self[i] !== that[i]) return false;
|
|
851
|
+
return true;
|
|
852
|
+
}
|
|
853
|
+
function compareRecords(self, that) {
|
|
854
|
+
const selfKeys = getAllObjectKeys(self);
|
|
855
|
+
const thatKeys = getAllObjectKeys(that);
|
|
856
|
+
if (selfKeys.size !== thatKeys.size) return false;
|
|
857
|
+
for (const key of selfKeys) if (!thatKeys.has(key) || !compareBoth(self[key], that[key])) return false;
|
|
858
|
+
return true;
|
|
859
|
+
}
|
|
860
|
+
/** @internal */
|
|
861
|
+
function makeCompareMap(keyEquivalence, valueEquivalence) {
|
|
862
|
+
return function compareMaps(self, that) {
|
|
863
|
+
const thatEntries = Array.from(that);
|
|
864
|
+
for (const [selfKey, selfValue] of self) {
|
|
865
|
+
let found = false;
|
|
866
|
+
for (let i = 0; i < thatEntries.length; i++) {
|
|
867
|
+
const [thatKey, thatValue] = thatEntries[i];
|
|
868
|
+
if (keyEquivalence(selfKey, thatKey) && valueEquivalence(selfValue, thatValue)) {
|
|
869
|
+
thatEntries[i] = thatEntries[thatEntries.length - 1];
|
|
870
|
+
thatEntries.pop();
|
|
871
|
+
found = true;
|
|
872
|
+
break;
|
|
873
|
+
}
|
|
874
|
+
}
|
|
875
|
+
if (!found) return false;
|
|
876
|
+
}
|
|
877
|
+
return true;
|
|
878
|
+
};
|
|
879
|
+
}
|
|
880
|
+
const compareMaps = /*#__PURE__*/ makeCompareMap(compareBoth, compareBoth);
|
|
881
|
+
/** @internal */
|
|
882
|
+
function makeCompareSet(equivalence) {
|
|
883
|
+
return function compareSets(self, that) {
|
|
884
|
+
const thatValues = Array.from(that);
|
|
885
|
+
for (const selfValue of self) {
|
|
886
|
+
let found = false;
|
|
887
|
+
for (let i = 0; i < thatValues.length; i++) {
|
|
888
|
+
const thatValue = thatValues[i];
|
|
889
|
+
if (equivalence(selfValue, thatValue)) {
|
|
890
|
+
thatValues[i] = thatValues[thatValues.length - 1];
|
|
891
|
+
thatValues.pop();
|
|
892
|
+
found = true;
|
|
893
|
+
break;
|
|
894
|
+
}
|
|
895
|
+
}
|
|
896
|
+
if (!found) return false;
|
|
897
|
+
}
|
|
898
|
+
return true;
|
|
899
|
+
};
|
|
900
|
+
}
|
|
901
|
+
const compareSets = /*#__PURE__*/ makeCompareSet(compareBoth);
|
|
902
|
+
/**
|
|
903
|
+
* Checks whether a value implements the {@link Equal} interface.
|
|
904
|
+
*
|
|
905
|
+
* **When to use**
|
|
906
|
+
*
|
|
907
|
+
* Use when you need generic utility code to distinguish `Equal` implementors
|
|
908
|
+
* from plain values before calling `[Equal.symbol]` directly.
|
|
909
|
+
*
|
|
910
|
+
* **Details**
|
|
911
|
+
*
|
|
912
|
+
* - Pure function, no side effects.
|
|
913
|
+
* - Returns `true` if and only if `u` has a property keyed by
|
|
914
|
+
* {@link symbol}.
|
|
915
|
+
* - Acts as a TypeScript type guard, narrowing the input to {@link Equal}.
|
|
916
|
+
*
|
|
917
|
+
* **Example** (Checking Equal values)
|
|
918
|
+
*
|
|
919
|
+
* ```ts import.meta.vitest
|
|
920
|
+
* import { Equal, Hash } from "effect"
|
|
921
|
+
*
|
|
922
|
+
* class Token implements Equal.Equal {
|
|
923
|
+
* constructor(readonly value: string) {}
|
|
924
|
+
* [Equal.symbol](that: Equal.Equal): boolean {
|
|
925
|
+
* return that instanceof Token && this.value === that.value
|
|
926
|
+
* }
|
|
927
|
+
* [Hash.symbol](): number {
|
|
928
|
+
* return Hash.string(this.value)
|
|
929
|
+
* }
|
|
930
|
+
* }
|
|
931
|
+
*
|
|
932
|
+
* Equal.isEqual(new Token("abc")) // => true
|
|
933
|
+
* Equal.isEqual({ x: 1 }) // => false
|
|
934
|
+
* Equal.isEqual(42) // => false
|
|
935
|
+
* ```
|
|
936
|
+
*
|
|
937
|
+
* @see {@link Equal} — the interface being checked
|
|
938
|
+
* @see {@link symbol} — the property key that signals `Equal` support
|
|
939
|
+
* @category guards
|
|
940
|
+
* @since 2.0.0
|
|
941
|
+
*/
|
|
942
|
+
const isEqual = (u) => hasProperty(u, symbol);
|
|
943
|
+
//#endregion
|
|
944
|
+
//#region ../../node_modules/.pnpm/effect@4.0.0-rc.117/node_modules/effect/dist/Redactable.js
|
|
945
|
+
/**
|
|
946
|
+
* Defines the symbol used to identify objects that implement the {@link Redactable}
|
|
947
|
+
* protocol.
|
|
948
|
+
*
|
|
949
|
+
* **When to use**
|
|
950
|
+
*
|
|
951
|
+
* Use as the property key when implementing the `Redactable` protocol.
|
|
952
|
+
*
|
|
953
|
+
* **Details**
|
|
954
|
+
*
|
|
955
|
+
* Add a method under this key to make an object redactable. The method receives
|
|
956
|
+
* the current `Context` and must return the replacement value. The symbol is
|
|
957
|
+
* registered globally via `Symbol.for("~effect/Redactable")`, so it is
|
|
958
|
+
* identical across multiple copies of the library at runtime.
|
|
959
|
+
*
|
|
960
|
+
* **Example** (Masking an API key)
|
|
961
|
+
*
|
|
962
|
+
* ```ts import.meta.vitest
|
|
963
|
+
* import { Context, Redactable } from "effect"
|
|
964
|
+
*
|
|
965
|
+
* class ApiKey {
|
|
966
|
+
* constructor(readonly raw: string) {}
|
|
967
|
+
*
|
|
968
|
+
* [Redactable.symbolRedactable](_ctx: Context.Context<never>) {
|
|
969
|
+
* return this.raw.slice(0, 4) + "..."
|
|
970
|
+
* }
|
|
971
|
+
* }
|
|
972
|
+
*
|
|
973
|
+
* Redactable.redact(new ApiKey("secret-key")) // => "secr..."
|
|
974
|
+
* ```
|
|
975
|
+
*
|
|
976
|
+
* @see {@link Redactable} for the interface this symbol belongs to
|
|
977
|
+
* @see {@link isRedactable} to check whether a value has this symbol
|
|
978
|
+
* @category symbols
|
|
979
|
+
* @since 3.10.0
|
|
980
|
+
*/
|
|
981
|
+
const symbolRedactable = /*#__PURE__*/ Symbol.for("~effect/Redactable");
|
|
982
|
+
/**
|
|
983
|
+
* Type guard that checks whether a value implements the {@link Redactable}
|
|
984
|
+
* interface.
|
|
985
|
+
*
|
|
986
|
+
* **When to use**
|
|
987
|
+
*
|
|
988
|
+
* Use to narrow an unknown value before calling redaction-specific helpers.
|
|
989
|
+
*
|
|
990
|
+
* @see {@link Redactable} for the interface being checked
|
|
991
|
+
* @see {@link redact} to apply redaction if the value is redactable
|
|
992
|
+
* @category guards
|
|
993
|
+
* @since 3.10.0
|
|
994
|
+
*/
|
|
995
|
+
const isRedactable = (u) => hasProperty(u, symbolRedactable);
|
|
996
|
+
/**
|
|
997
|
+
* Returns a redacted value if it implements {@link Redactable}, otherwise returns it
|
|
998
|
+
* unchanged.
|
|
999
|
+
*
|
|
1000
|
+
* **When to use**
|
|
1001
|
+
*
|
|
1002
|
+
* Use as the general-purpose entry point for redaction when the input may
|
|
1003
|
+
* or may not implement the redaction protocol.
|
|
1004
|
+
*
|
|
1005
|
+
* **Details**
|
|
1006
|
+
*
|
|
1007
|
+
* This function calls {@link isRedactable} and, when it returns `true`,
|
|
1008
|
+
* delegates to {@link getRedacted}.
|
|
1009
|
+
*
|
|
1010
|
+
* **Gotchas**
|
|
1011
|
+
*
|
|
1012
|
+
* Redaction is not recursive. Nested redactable values inside the returned
|
|
1013
|
+
* object are not automatically redacted.
|
|
1014
|
+
*
|
|
1015
|
+
* @see {@link isRedactable} to check before redacting
|
|
1016
|
+
* @see {@link getRedacted} for the lower-level variant for known redactables
|
|
1017
|
+
* @category destructors
|
|
1018
|
+
* @since 3.10.0
|
|
1019
|
+
*/
|
|
1020
|
+
function redact(u) {
|
|
1021
|
+
if (isRedactable(u)) return getRedacted(u);
|
|
1022
|
+
return u;
|
|
1023
|
+
}
|
|
1024
|
+
/**
|
|
1025
|
+
* Returns the result of calling `[symbolRedactable]` on a value that is
|
|
1026
|
+
* already known to be {@link Redactable}.
|
|
1027
|
+
*
|
|
1028
|
+
* **When to use**
|
|
1029
|
+
*
|
|
1030
|
+
* Use when you need to read the redacted representation from a value already
|
|
1031
|
+
* verified as `Redactable`.
|
|
1032
|
+
*
|
|
1033
|
+
* **Details**
|
|
1034
|
+
*
|
|
1035
|
+
* This function reads the current fiber's `Context` from the global fiber
|
|
1036
|
+
* reference and passes it to the redaction method.
|
|
1037
|
+
*
|
|
1038
|
+
* **Gotchas**
|
|
1039
|
+
*
|
|
1040
|
+
* If no fiber is active, an empty `Context` is passed to the redaction method.
|
|
1041
|
+
*
|
|
1042
|
+
* @see {@link redact} for the higher-level variant that handles non-redactable values
|
|
1043
|
+
* @see {@link isRedactable} for the type guard to verify before calling this
|
|
1044
|
+
* @category destructors
|
|
1045
|
+
* @since 4.0.0
|
|
1046
|
+
*/
|
|
1047
|
+
function getRedacted(redactable) {
|
|
1048
|
+
return redactable[symbolRedactable](globalThis["~effect/Fiber/currentFiber"]?.context ?? emptyContext);
|
|
1049
|
+
}
|
|
1050
|
+
const emptyMap = /*#__PURE__*/ new Map();
|
|
1051
|
+
const emptyContext = {
|
|
1052
|
+
"~effect/Context": {},
|
|
1053
|
+
base: emptyMap,
|
|
1054
|
+
depth: 0,
|
|
1055
|
+
mapUnsafe: emptyMap,
|
|
1056
|
+
pipe() {
|
|
1057
|
+
return pipeArguments(this, arguments);
|
|
1058
|
+
}
|
|
1059
|
+
};
|
|
1060
|
+
//#endregion
|
|
1061
|
+
//#region ../../node_modules/.pnpm/effect@4.0.0-rc.117/node_modules/effect/dist/Formatter.js
|
|
1062
|
+
/**
|
|
1063
|
+
* Formats JavaScript values into readable strings.
|
|
1064
|
+
*
|
|
1065
|
+
* `format` is intended for logs, diagnostics, and error messages. It handles
|
|
1066
|
+
* primitives, objects, arrays, dates, regular expressions, maps, sets, class
|
|
1067
|
+
* instances, errors, circular references, and redactable values. `formatJson`
|
|
1068
|
+
* wraps JSON formatting with redaction and circular-reference handling, and the
|
|
1069
|
+
* module also includes helpers for property keys, paths, and dates.
|
|
1070
|
+
*
|
|
1071
|
+
* @since 4.0.0
|
|
1072
|
+
*/
|
|
1073
|
+
/**
|
|
1074
|
+
* Converts any JavaScript value into a human-readable string.
|
|
1075
|
+
*
|
|
1076
|
+
* **When to use**
|
|
1077
|
+
*
|
|
1078
|
+
* Use when you need to format arbitrary JavaScript values for debugging,
|
|
1079
|
+
* logging, or error messages.
|
|
1080
|
+
*
|
|
1081
|
+
* **Details**
|
|
1082
|
+
*
|
|
1083
|
+
* - Output is **not** valid JSON; use {@link formatJson} when you need
|
|
1084
|
+
* parseable JSON.
|
|
1085
|
+
* - Handles `BigInt`, `Symbol`, `Set`, `Map`, `Date`, `RegExp`, and class
|
|
1086
|
+
* instances that `JSON.stringify` cannot represent.
|
|
1087
|
+
* - Circular references are shown as `"[Circular]"` instead of throwing.
|
|
1088
|
+
* - Failures while inspecting a value are rendered as diagnostic placeholders instead of throwing.
|
|
1089
|
+
* - Primitives: stringified naturally (`null`, `undefined`, `123`, `true`).
|
|
1090
|
+
* Strings are JSON-quoted.
|
|
1091
|
+
* - Objects with a custom `toString` (not `Object.prototype.toString`):
|
|
1092
|
+
* `toString()` is called unless `ignoreToString` is `true`.
|
|
1093
|
+
* - Errors with a `cause`: formatted as `"<message> (cause: <cause>)"`.
|
|
1094
|
+
* - Iterables (`Set`, `Map`, etc.): formatted as
|
|
1095
|
+
* `ClassName([...elements])`.
|
|
1096
|
+
* - Class instances: wrapped as `ClassName({...})`.
|
|
1097
|
+
* - `Redactable` values are automatically redacted.
|
|
1098
|
+
* - Arrays/objects with 0–1 entries are inline; larger ones are
|
|
1099
|
+
* pretty-printed when `space` is set.
|
|
1100
|
+
* - `space` — indentation unit (number of spaces, or a string like
|
|
1101
|
+
* `"\t"`). Defaults to `0` (compact).
|
|
1102
|
+
* - `ignoreToString` — skip calling `toString()`. Defaults to `false`.
|
|
1103
|
+
*
|
|
1104
|
+
* **Example** (Formatting compact output)
|
|
1105
|
+
*
|
|
1106
|
+
* ```ts import.meta.vitest
|
|
1107
|
+
* import { Formatter } from "effect"
|
|
1108
|
+
*
|
|
1109
|
+
* Formatter.format({ a: 1, b: [2, 3] }) // => "{\"a\":1,\"b\":[2,3]}"
|
|
1110
|
+
* ```
|
|
1111
|
+
*
|
|
1112
|
+
* **Example** (Pretty-printed output)
|
|
1113
|
+
*
|
|
1114
|
+
* ```ts import.meta.vitest
|
|
1115
|
+
* import { Formatter } from "effect"
|
|
1116
|
+
*
|
|
1117
|
+
* const output = Formatter.format({ a: 1, b: [2, 3] }, { space: 2 })
|
|
1118
|
+
* output // => "{\n \"a\": 1,\n \"b\": [\n 2,\n 3\n ]\n}"
|
|
1119
|
+
* ```
|
|
1120
|
+
*
|
|
1121
|
+
* **Example** (Handling circular references)
|
|
1122
|
+
*
|
|
1123
|
+
* ```ts import.meta.vitest
|
|
1124
|
+
* import { Formatter } from "effect"
|
|
1125
|
+
*
|
|
1126
|
+
* const obj: any = { name: "loop" }
|
|
1127
|
+
* obj.self = obj
|
|
1128
|
+
* Formatter.format(obj) // => "{\"name\":\"loop\",\"self\":[Circular]}"
|
|
1129
|
+
* ```
|
|
1130
|
+
*
|
|
1131
|
+
* @see {@link formatJson}
|
|
1132
|
+
* @see {@link Formatter}
|
|
1133
|
+
* @category formatting
|
|
1134
|
+
* @since 2.0.0
|
|
1135
|
+
*/
|
|
1136
|
+
function format(input, options) {
|
|
1137
|
+
const space = options?.space ?? 0;
|
|
1138
|
+
const ancestors = /* @__PURE__ */ new WeakSet();
|
|
1139
|
+
const gap = !space ? "" : typeof space === "number" ? " ".repeat(space) : space;
|
|
1140
|
+
const ind = (d) => gap.repeat(d);
|
|
1141
|
+
const wrap = (v, body) => {
|
|
1142
|
+
const ctor = v?.constructor;
|
|
1143
|
+
return ctor && ctor !== Object.prototype.constructor && ctor.name ? `${ctor.name}(${body})` : body;
|
|
1144
|
+
};
|
|
1145
|
+
const ownKeys = (o) => {
|
|
1146
|
+
try {
|
|
1147
|
+
return Reflect.ownKeys(o);
|
|
1148
|
+
} catch {
|
|
1149
|
+
return ["[ownKeys threw]"];
|
|
1150
|
+
}
|
|
1151
|
+
};
|
|
1152
|
+
function recur(v, d = 0) {
|
|
1153
|
+
try {
|
|
1154
|
+
return recurUnsafe(v, d);
|
|
1155
|
+
} catch {
|
|
1156
|
+
if (typeof v === "object" && v !== null || typeof v === "function") ancestors.delete(v);
|
|
1157
|
+
return "[inspection threw]";
|
|
1158
|
+
}
|
|
1159
|
+
}
|
|
1160
|
+
function recurUnsafe(v, d = 0) {
|
|
1161
|
+
if (typeof v === "string") return JSON.stringify(v);
|
|
1162
|
+
if (typeof v === "number" || v == null || typeof v === "boolean" || typeof v === "symbol") return String(v);
|
|
1163
|
+
if (typeof v === "bigint") return String(v) + "n";
|
|
1164
|
+
if (typeof v === "object" || typeof v === "function") {
|
|
1165
|
+
if (ancestors.has(v)) return CIRCULAR;
|
|
1166
|
+
ancestors.add(v);
|
|
1167
|
+
let output;
|
|
1168
|
+
if (symbolRedactable in v) output = recur(getRedacted(v), d);
|
|
1169
|
+
else if (Array.isArray(v)) output = !gap || v.length <= 1 ? `[${v.map((x) => recur(x, d)).join(",")}]` : `[\n${ind(d + 1)}${v.map((x) => recur(x, d + 1)).join(",\n" + ind(d + 1))}\n${ind(d)}]`;
|
|
1170
|
+
else if (v instanceof Date) output = formatDate(v);
|
|
1171
|
+
else if (!options?.ignoreToString && hasProperty(v, "toString") && typeof v["toString"] === "function" && v["toString"] !== Object.prototype.toString && v["toString"] !== Array.prototype.toString) {
|
|
1172
|
+
const s = safeToString(v);
|
|
1173
|
+
output = v instanceof Error && v.cause !== void 0 ? `${s} (cause: ${recur(v.cause, d)})` : s;
|
|
1174
|
+
} else if (Symbol.iterator in v) output = `${v.constructor.name}(${recur(Array.from(v), d)})`;
|
|
1175
|
+
else {
|
|
1176
|
+
const keys = ownKeys(v);
|
|
1177
|
+
if (!gap || keys.length <= 1) {
|
|
1178
|
+
const body = `{${keys.map((k) => `${formatPropertyKey(k)}:${recur(safeGet(v, k), d)}`).join(",")}}`;
|
|
1179
|
+
output = wrap(v, body);
|
|
1180
|
+
} else {
|
|
1181
|
+
const body = `{\n${keys.map((k) => `${ind(d + 1)}${formatPropertyKey(k)}: ${recur(safeGet(v, k), d + 1)}`).join(",\n")}\n${ind(d)}}`;
|
|
1182
|
+
output = wrap(v, body);
|
|
1183
|
+
}
|
|
1184
|
+
}
|
|
1185
|
+
ancestors.delete(v);
|
|
1186
|
+
return output;
|
|
1187
|
+
}
|
|
1188
|
+
return String(v);
|
|
1189
|
+
}
|
|
1190
|
+
return recur(input, 0);
|
|
1191
|
+
}
|
|
1192
|
+
const CIRCULAR = "[Circular]";
|
|
1193
|
+
/**
|
|
1194
|
+
* @internal
|
|
1195
|
+
*/
|
|
1196
|
+
function formatPropertyKey(name) {
|
|
1197
|
+
return typeof name === "string" ? JSON.stringify(name) : String(name);
|
|
1198
|
+
}
|
|
1199
|
+
/**
|
|
1200
|
+
* Formats a `Date` as an ISO 8601 string, returning `"Invalid Date"` for
|
|
1201
|
+
* invalid dates instead of throwing.
|
|
1202
|
+
*
|
|
1203
|
+
* @internal
|
|
1204
|
+
*/
|
|
1205
|
+
function formatDate(date) {
|
|
1206
|
+
try {
|
|
1207
|
+
return date.toISOString();
|
|
1208
|
+
} catch {
|
|
1209
|
+
return "Invalid Date";
|
|
1210
|
+
}
|
|
1211
|
+
}
|
|
1212
|
+
function safeToString(input) {
|
|
1213
|
+
try {
|
|
1214
|
+
const s = input.toString();
|
|
1215
|
+
return typeof s === "string" ? s : String(s);
|
|
1216
|
+
} catch {
|
|
1217
|
+
return "[toString threw]";
|
|
1218
|
+
}
|
|
1219
|
+
}
|
|
1220
|
+
function safeGet(input, key) {
|
|
1221
|
+
try {
|
|
1222
|
+
return input[key];
|
|
1223
|
+
} catch {
|
|
1224
|
+
return "[property access threw]";
|
|
1225
|
+
}
|
|
1226
|
+
}
|
|
1227
|
+
//#endregion
|
|
1228
|
+
//#region ../../node_modules/.pnpm/effect@4.0.0-rc.117/node_modules/effect/dist/Inspectable.js
|
|
1229
|
+
/**
|
|
1230
|
+
* Defines the symbol used by Node.js for custom object inspection.
|
|
1231
|
+
*
|
|
1232
|
+
* **When to use**
|
|
1233
|
+
*
|
|
1234
|
+
* Use to implement Node.js custom inspection for a value.
|
|
1235
|
+
*
|
|
1236
|
+
* **Details**
|
|
1237
|
+
*
|
|
1238
|
+
* This symbol is recognized by Node.js's `util.inspect()` function and the REPL
|
|
1239
|
+
* for custom object representation. When an object has a method with this symbol,
|
|
1240
|
+
* it will be called to determine how the object should be displayed.
|
|
1241
|
+
*
|
|
1242
|
+
* **Example** (Defining custom Node inspection)
|
|
1243
|
+
*
|
|
1244
|
+
* ```ts import.meta.vitest
|
|
1245
|
+
* import { Inspectable } from "effect"
|
|
1246
|
+
*
|
|
1247
|
+
* class CustomObject {
|
|
1248
|
+
* constructor(private value: string) {}
|
|
1249
|
+
*
|
|
1250
|
+
* [Inspectable.NodeInspectSymbol]() {
|
|
1251
|
+
* return `CustomObject(${this.value})`
|
|
1252
|
+
* }
|
|
1253
|
+
* }
|
|
1254
|
+
*
|
|
1255
|
+
* const obj = new CustomObject("hello")
|
|
1256
|
+
* obj[Inspectable.NodeInspectSymbol]() // => "CustomObject(hello)"
|
|
1257
|
+
* ```
|
|
1258
|
+
*
|
|
1259
|
+
* @category symbols
|
|
1260
|
+
* @since 2.0.0
|
|
1261
|
+
*/
|
|
1262
|
+
const NodeInspectSymbol = /*#__PURE__*/ Symbol.for("nodejs.util.inspect.custom");
|
|
1263
|
+
/**
|
|
1264
|
+
* Converts a value to its structured inspection representation.
|
|
1265
|
+
*
|
|
1266
|
+
* **When to use**
|
|
1267
|
+
*
|
|
1268
|
+
* Use when you need the structured representation of an inspectable value
|
|
1269
|
+
* without risking unhandled errors.
|
|
1270
|
+
*
|
|
1271
|
+
* **Details**
|
|
1272
|
+
*
|
|
1273
|
+
* This function applies redaction before extracting data from objects that
|
|
1274
|
+
* implement `toJSON`, recursively processes arrays, and handles errors
|
|
1275
|
+
* gracefully. Plain objects are returned unchanged, so the result is not
|
|
1276
|
+
* guaranteed to be accepted by `JSON.stringify`; it may still contain values
|
|
1277
|
+
* such as `BigInt`, functions, or circular references.
|
|
1278
|
+
*
|
|
1279
|
+
* @see {@link toStringUnknown} for converting unknown values to strings
|
|
1280
|
+
*
|
|
1281
|
+
* @category converting
|
|
1282
|
+
* @since 4.0.0
|
|
1283
|
+
*/
|
|
1284
|
+
const toJson = (input) => {
|
|
1285
|
+
try {
|
|
1286
|
+
input = redact(input);
|
|
1287
|
+
if (hasProperty(input, "toJSON") && isFunction(input["toJSON"]) && input["toJSON"].length === 0) return input.toJSON();
|
|
1288
|
+
else if (Array.isArray(input)) return input.map(toJson);
|
|
1289
|
+
return input;
|
|
1290
|
+
} catch {
|
|
1291
|
+
return "[toJSON threw]";
|
|
1292
|
+
}
|
|
1293
|
+
};
|
|
1294
|
+
//#endregion
|
|
1295
|
+
//#region ../../node_modules/.pnpm/effect@4.0.0-rc.117/node_modules/effect/dist/Utils.js
|
|
1296
|
+
/**
|
|
1297
|
+
* Yields its wrapped value exactly once through an `IterableIterator`.
|
|
1298
|
+
*
|
|
1299
|
+
* **When to use**
|
|
1300
|
+
*
|
|
1301
|
+
* Use to implement `[Symbol.iterator]()` on Effect-like types so they can be
|
|
1302
|
+
* `yield*`-ed inside generator functions, such as `Effect.gen` and
|
|
1303
|
+
* `Option.gen`.
|
|
1304
|
+
*
|
|
1305
|
+
* **Details**
|
|
1306
|
+
*
|
|
1307
|
+
* The first call to `next()` returns `{ value: self, done: false }`. Every
|
|
1308
|
+
* subsequent call returns `{ value: a, done: true }` where `a` is the argument
|
|
1309
|
+
* passed to `next()`. `[Symbol.iterator]()` returns a **new** `SingleShotGen`
|
|
1310
|
+
* wrapping the same value, so the outer type can be iterated multiple times.
|
|
1311
|
+
*
|
|
1312
|
+
* **Example** (Yielding a wrapped value in a generator)
|
|
1313
|
+
*
|
|
1314
|
+
* ```ts import.meta.vitest
|
|
1315
|
+
* import { Utils } from "effect"
|
|
1316
|
+
*
|
|
1317
|
+
* const gen = new Utils.SingleShotGen<string, number>("hello")
|
|
1318
|
+
*
|
|
1319
|
+
* gen.next(0) // => { value: "hello", done: false }
|
|
1320
|
+
*
|
|
1321
|
+
* gen.next(42) // => { value: 42, done: true }
|
|
1322
|
+
* ```
|
|
1323
|
+
*
|
|
1324
|
+
* @see {@link Gen} for the type-level signature that relies on `SingleShotGen`
|
|
1325
|
+
* @category constructors
|
|
1326
|
+
* @since 2.0.0
|
|
1327
|
+
*/
|
|
1328
|
+
var SingleShotGen = class SingleShotGen {
|
|
1329
|
+
called = false;
|
|
1330
|
+
self;
|
|
1331
|
+
constructor(self) {
|
|
1332
|
+
this.self = self;
|
|
1333
|
+
}
|
|
1334
|
+
/**
|
|
1335
|
+
* Yields the stored value once, then completes with the value sent back in.
|
|
1336
|
+
*
|
|
1337
|
+
* **When to use**
|
|
1338
|
+
*
|
|
1339
|
+
* Use to advance a `SingleShotGen` through its single yield and completion
|
|
1340
|
+
* step.
|
|
1341
|
+
*
|
|
1342
|
+
* @since 2.0.0
|
|
1343
|
+
*/
|
|
1344
|
+
next(a) {
|
|
1345
|
+
return this.called ? {
|
|
1346
|
+
value: a,
|
|
1347
|
+
done: true
|
|
1348
|
+
} : (this.called = true, {
|
|
1349
|
+
value: this.self,
|
|
1350
|
+
done: false
|
|
1351
|
+
});
|
|
1352
|
+
}
|
|
1353
|
+
/**
|
|
1354
|
+
* Creates a fresh single-shot iterator over the stored value.
|
|
1355
|
+
*
|
|
1356
|
+
* **When to use**
|
|
1357
|
+
*
|
|
1358
|
+
* Use to iterate the wrapped value again without reusing the consumed
|
|
1359
|
+
* iterator state.
|
|
1360
|
+
*
|
|
1361
|
+
* @since 2.0.0
|
|
1362
|
+
*/
|
|
1363
|
+
[Symbol.iterator]() {
|
|
1364
|
+
return new SingleShotGen(this.self);
|
|
1365
|
+
}
|
|
1366
|
+
};
|
|
1367
|
+
//#endregion
|
|
1368
|
+
//#region ../../node_modules/.pnpm/effect@4.0.0-rc.117/node_modules/effect/dist/internal/core.js
|
|
1369
|
+
/** @internal */
|
|
1370
|
+
const EffectTypeId = `~effect/Effect`;
|
|
1371
|
+
`${EffectTypeId}`;
|
|
1372
|
+
`${EffectTypeId}`;
|
|
1373
|
+
`${EffectTypeId}`;
|
|
1374
|
+
`${EffectTypeId}`;
|
|
1375
|
+
`${EffectTypeId}`;
|
|
1376
|
+
`${EffectTypeId}`;
|
|
1377
|
+
/** @internal */
|
|
1378
|
+
const PipeInspectableProto = {
|
|
1379
|
+
pipe() {
|
|
1380
|
+
return pipeArguments(this, arguments);
|
|
1381
|
+
},
|
|
1382
|
+
toJSON() {
|
|
1383
|
+
return { ...this };
|
|
1384
|
+
},
|
|
1385
|
+
toString() {
|
|
1386
|
+
return format(this.toJSON(), {
|
|
1387
|
+
ignoreToString: true,
|
|
1388
|
+
space: 2
|
|
1389
|
+
});
|
|
1390
|
+
},
|
|
1391
|
+
[NodeInspectSymbol]() {
|
|
1392
|
+
return this.toJSON();
|
|
1393
|
+
}
|
|
1394
|
+
};
|
|
1395
|
+
({ ...PipeInspectableProto });
|
|
1396
|
+
//#endregion
|
|
1397
|
+
//#region ../../node_modules/.pnpm/effect@4.0.0-rc.117/node_modules/effect/dist/internal/result.js
|
|
1398
|
+
const TypeId$1 = "~effect/Result";
|
|
1399
|
+
const CommonProto = {
|
|
1400
|
+
[TypeId$1]: {
|
|
1401
|
+
/* v8 ignore next 2 */
|
|
1402
|
+
_A: (_) => _,
|
|
1403
|
+
_E: (_) => _
|
|
1404
|
+
},
|
|
1405
|
+
...PipeInspectableProto,
|
|
1406
|
+
[Symbol.iterator]() {
|
|
1407
|
+
return new SingleShotGen(this);
|
|
1408
|
+
}
|
|
1409
|
+
};
|
|
1410
|
+
const SuccessProto = /*#__PURE__*/ Object.assign(/*#__PURE__*/ Object.create(CommonProto), {
|
|
1411
|
+
_tag: "Success",
|
|
1412
|
+
_op: "Success",
|
|
1413
|
+
[symbol](that) {
|
|
1414
|
+
return isResult$1(that) && isSuccess$1(that) && equals(this.success, that.success);
|
|
1415
|
+
},
|
|
1416
|
+
[symbol$1]() {
|
|
1417
|
+
return combine(hash(this._tag))(hash(this.success));
|
|
1418
|
+
},
|
|
1419
|
+
toString() {
|
|
1420
|
+
return `success(${format(this.success)})`;
|
|
1421
|
+
},
|
|
1422
|
+
toJSON() {
|
|
1423
|
+
return {
|
|
1424
|
+
_id: "Result",
|
|
1425
|
+
_tag: this._tag,
|
|
1426
|
+
value: toJson(this.success)
|
|
1427
|
+
};
|
|
1428
|
+
}
|
|
1429
|
+
});
|
|
1430
|
+
const FailureProto = /*#__PURE__*/ Object.assign(/*#__PURE__*/ Object.create(CommonProto), {
|
|
1431
|
+
_tag: "Failure",
|
|
1432
|
+
_op: "Failure",
|
|
1433
|
+
[symbol](that) {
|
|
1434
|
+
return isResult$1(that) && isFailure(that) && equals(this.failure, that.failure);
|
|
1435
|
+
},
|
|
1436
|
+
[symbol$1]() {
|
|
1437
|
+
return combine(hash(this._tag))(hash(this.failure));
|
|
1438
|
+
},
|
|
1439
|
+
toString() {
|
|
1440
|
+
return `failure(${format(this.failure)})`;
|
|
1441
|
+
},
|
|
1442
|
+
toJSON() {
|
|
1443
|
+
return {
|
|
1444
|
+
_id: "Result",
|
|
1445
|
+
_tag: this._tag,
|
|
1446
|
+
failure: toJson(this.failure)
|
|
1447
|
+
};
|
|
1448
|
+
}
|
|
1449
|
+
});
|
|
1450
|
+
/** @internal */
|
|
1451
|
+
const isResult$1 = (input) => hasProperty(input, TypeId$1);
|
|
1452
|
+
/** @internal */
|
|
1453
|
+
const isFailure = (result) => result._tag === "Failure";
|
|
1454
|
+
/** @internal */
|
|
1455
|
+
const isSuccess$1 = (result) => result._tag === "Success";
|
|
1456
|
+
/** @internal */
|
|
1457
|
+
const FailureImpl = function(failure) {
|
|
1458
|
+
this.failure = failure;
|
|
1459
|
+
};
|
|
1460
|
+
FailureImpl.prototype = FailureProto;
|
|
1461
|
+
/** @internal */
|
|
1462
|
+
const fail$1 = (failure) => new FailureImpl(failure);
|
|
1463
|
+
/** @internal */
|
|
1464
|
+
const SuccessImpl = function(success) {
|
|
1465
|
+
this.success = success;
|
|
1466
|
+
};
|
|
1467
|
+
SuccessImpl.prototype = SuccessProto;
|
|
1468
|
+
/** @internal */
|
|
1469
|
+
const succeed$1 = (success) => new SuccessImpl(success);
|
|
1470
|
+
//#endregion
|
|
1471
|
+
//#region ../../node_modules/.pnpm/effect@4.0.0-rc.117/node_modules/effect/dist/Result.js
|
|
1472
|
+
/**
|
|
1473
|
+
* Creates a `Result` holding a `Success` value.
|
|
1474
|
+
*
|
|
1475
|
+
* **Details**
|
|
1476
|
+
*
|
|
1477
|
+
* - Use when you have a value and want to lift it into the `Result` type
|
|
1478
|
+
* - The error type `E` defaults to `never`
|
|
1479
|
+
*
|
|
1480
|
+
* **Example** (Wrapping a value)
|
|
1481
|
+
*
|
|
1482
|
+
* ```ts import.meta.vitest
|
|
1483
|
+
* import { Result } from "effect"
|
|
1484
|
+
*
|
|
1485
|
+
* Result.succeed(42) // => Result.succeed(42)
|
|
1486
|
+
* ```
|
|
1487
|
+
*
|
|
1488
|
+
* @see {@link fail} to create a Failure
|
|
1489
|
+
* @see {@link void_ void} for a pre-built `Success<void>`
|
|
1490
|
+
*
|
|
1491
|
+
* @category constructors
|
|
1492
|
+
* @since 4.0.0
|
|
1493
|
+
*/
|
|
1494
|
+
const succeed = succeed$1;
|
|
1495
|
+
/**
|
|
1496
|
+
* Creates a `Result` holding a `Failure` value.
|
|
1497
|
+
*
|
|
1498
|
+
* **When to use**
|
|
1499
|
+
*
|
|
1500
|
+
* Use to represent a failed `Result` with a typed failure value.
|
|
1501
|
+
*
|
|
1502
|
+
* **Details**
|
|
1503
|
+
*
|
|
1504
|
+
* - The success type `A` defaults to `never`
|
|
1505
|
+
*
|
|
1506
|
+
* **Example** (Creating a failure)
|
|
1507
|
+
*
|
|
1508
|
+
* ```ts import.meta.vitest
|
|
1509
|
+
* import { Result } from "effect"
|
|
1510
|
+
*
|
|
1511
|
+
* Result.fail("Something went wrong") // => Result.fail("Something went wrong")
|
|
1512
|
+
* ```
|
|
1513
|
+
*
|
|
1514
|
+
* @see {@link succeed} to create a Success
|
|
1515
|
+
* @see {@link mapError} to transform the error
|
|
1516
|
+
*
|
|
1517
|
+
* @category constructors
|
|
1518
|
+
* @since 4.0.0
|
|
1519
|
+
*/
|
|
1520
|
+
const fail = fail$1;
|
|
1521
|
+
/**
|
|
1522
|
+
* Checks whether a value is a `Result` (either `Success` or `Failure`).
|
|
1523
|
+
*
|
|
1524
|
+
* **When to use**
|
|
1525
|
+
*
|
|
1526
|
+
* Use to validate unknown input before operating on it as a `Result`.
|
|
1527
|
+
*
|
|
1528
|
+
* **Details**
|
|
1529
|
+
*
|
|
1530
|
+
* - Returns `true` for both `Success` and `Failure` variants
|
|
1531
|
+
* - Acts as a TypeScript type guard, narrowing to `Result<unknown, unknown>`
|
|
1532
|
+
*
|
|
1533
|
+
* **Example** (Checking if a value is a Result)
|
|
1534
|
+
*
|
|
1535
|
+
* ```ts import.meta.vitest
|
|
1536
|
+
* import { Result } from "effect"
|
|
1537
|
+
*
|
|
1538
|
+
* Result.isResult(Result.succeed(1)) // => true
|
|
1539
|
+
*
|
|
1540
|
+
* Result.isResult({ value: 1 }) // => false
|
|
1541
|
+
* ```
|
|
1542
|
+
*
|
|
1543
|
+
* @see {@link isSuccess} / {@link isFailure} to narrow to a specific variant
|
|
1544
|
+
*
|
|
1545
|
+
* @category guards
|
|
1546
|
+
* @since 4.0.0
|
|
1547
|
+
*/
|
|
1548
|
+
const isResult = isResult$1;
|
|
1549
|
+
/**
|
|
1550
|
+
* Checks whether a `Result` is a `Success`.
|
|
1551
|
+
*
|
|
1552
|
+
* **When to use**
|
|
1553
|
+
*
|
|
1554
|
+
* Use to narrow a known `Result` to the `Success` variant.
|
|
1555
|
+
*
|
|
1556
|
+
* **Details**
|
|
1557
|
+
*
|
|
1558
|
+
* - Acts as a TypeScript type guard, narrowing to `Success<A, E>`
|
|
1559
|
+
* - After narrowing, you can access `.success` to read the value
|
|
1560
|
+
*
|
|
1561
|
+
* **Example** (Narrowing to success)
|
|
1562
|
+
*
|
|
1563
|
+
* ```ts import.meta.vitest
|
|
1564
|
+
* import { Result } from "effect"
|
|
1565
|
+
*
|
|
1566
|
+
* const result = Result.succeed(42)
|
|
1567
|
+
*
|
|
1568
|
+
* if (Result.isSuccess(result)) {
|
|
1569
|
+
* result.success // => 42
|
|
1570
|
+
* }
|
|
1571
|
+
* ```
|
|
1572
|
+
*
|
|
1573
|
+
* @see {@link isFailure} for the opposite check
|
|
1574
|
+
* @see {@link isResult} to check if a value is any Result
|
|
1575
|
+
*
|
|
1576
|
+
* @category guards
|
|
1577
|
+
* @since 4.0.0
|
|
1578
|
+
*/
|
|
1579
|
+
const isSuccess = isSuccess$1;
|
|
1580
|
+
const ValueMatcherProto = {
|
|
1581
|
+
["~effect/Match/Matcher"]: {
|
|
1582
|
+
_input: identity,
|
|
1583
|
+
_filters: identity,
|
|
1584
|
+
_result: identity,
|
|
1585
|
+
_return: identity,
|
|
1586
|
+
_flavor: identity
|
|
1587
|
+
},
|
|
1588
|
+
_tag: "ValueMatcher",
|
|
1589
|
+
add(_case) {
|
|
1590
|
+
if (isSuccess(this.value)) return this;
|
|
1591
|
+
if (_case._tag === "When" && _case.guard(this.provided) === true) return makeValueMatcher(this.provided, succeed(_case.evaluate(this.provided)));
|
|
1592
|
+
else if (_case._tag === "Not" && _case.guard(this.provided) === false) return makeValueMatcher(this.provided, succeed(_case.evaluate(this.provided)));
|
|
1593
|
+
return this;
|
|
1594
|
+
},
|
|
1595
|
+
pipe() {
|
|
1596
|
+
return pipeArguments(this, arguments);
|
|
1597
|
+
}
|
|
1598
|
+
};
|
|
1599
|
+
function makeValueMatcher(provided, value) {
|
|
1600
|
+
const matcher = Object.create(ValueMatcherProto);
|
|
1601
|
+
matcher.provided = provided;
|
|
1602
|
+
matcher.value = value;
|
|
1603
|
+
return matcher;
|
|
1604
|
+
}
|
|
1605
|
+
const makeWhen = (guard, evaluate) => ({
|
|
1606
|
+
_tag: "When",
|
|
1607
|
+
guard,
|
|
1608
|
+
evaluate
|
|
1609
|
+
});
|
|
1610
|
+
const makePredicate = (pattern) => {
|
|
1611
|
+
if (typeof pattern === "function") return pattern;
|
|
1612
|
+
else if (Array.isArray(pattern)) {
|
|
1613
|
+
const predicates = pattern.map(makePredicate);
|
|
1614
|
+
const len = predicates.length;
|
|
1615
|
+
return (u) => {
|
|
1616
|
+
if (!Array.isArray(u)) return false;
|
|
1617
|
+
for (let i = 0; i < len; i++) if (predicates[i](u[i]) === false) return false;
|
|
1618
|
+
return true;
|
|
1619
|
+
};
|
|
1620
|
+
} else if (pattern !== null && typeof pattern === "object") {
|
|
1621
|
+
const keysAndPredicates = Reflect.ownKeys(pattern).map((key) => [key, makePredicate(pattern[key])]);
|
|
1622
|
+
const len = keysAndPredicates.length;
|
|
1623
|
+
return (u) => {
|
|
1624
|
+
if (typeof u !== "object" || u === null) return false;
|
|
1625
|
+
for (let i = 0; i < len; i++) {
|
|
1626
|
+
const [key, predicate] = keysAndPredicates[i];
|
|
1627
|
+
if (!(key in u) || predicate(u[key]) === false) return false;
|
|
1628
|
+
}
|
|
1629
|
+
return true;
|
|
1630
|
+
};
|
|
1631
|
+
}
|
|
1632
|
+
return (u) => u === pattern;
|
|
1633
|
+
};
|
|
1634
|
+
/** @internal */
|
|
1635
|
+
const value$1 = (i) => makeValueMatcher(i, fail(i));
|
|
1636
|
+
/** @internal */
|
|
1637
|
+
const when$1 = (pattern, f) => (self) => self.add(makeWhen(makePredicate(pattern), f));
|
|
1638
|
+
/** @internal */
|
|
1639
|
+
const orElse$1 = (f) => (self) => {
|
|
1640
|
+
const toResult = result(self);
|
|
1641
|
+
if (isResult(toResult)) return toResult._tag === "Success" ? toResult.success : f(toResult.failure);
|
|
1642
|
+
return (...args) => {
|
|
1643
|
+
const a = toResult(...args);
|
|
1644
|
+
return isSuccess(a) ? a.success : f(a.failure, ...args);
|
|
1645
|
+
};
|
|
1646
|
+
};
|
|
1647
|
+
/** @internal */
|
|
1648
|
+
const result = (self) => {
|
|
1649
|
+
if (self._tag === "ValueMatcher") return self.value;
|
|
1650
|
+
const len = self.cases.length;
|
|
1651
|
+
if (len === 1) {
|
|
1652
|
+
const _case = self.cases[0];
|
|
1653
|
+
return (...args) => {
|
|
1654
|
+
const input = self.select(...args);
|
|
1655
|
+
if (_case._tag === "When" && _case.guard(input) === true) return succeed(_case.evaluate(input, ...args));
|
|
1656
|
+
else if (_case._tag === "Not" && _case.guard(input) === false) return succeed(_case.evaluate(input, ...args));
|
|
1657
|
+
return fail(input);
|
|
1658
|
+
};
|
|
1659
|
+
}
|
|
1660
|
+
return (...args) => {
|
|
1661
|
+
const input = self.select(...args);
|
|
1662
|
+
for (let i = 0; i < len; i++) {
|
|
1663
|
+
const _case = self.cases[i];
|
|
1664
|
+
if (_case._tag === "When" && _case.guard(input) === true) return succeed(_case.evaluate(input, ...args));
|
|
1665
|
+
else if (_case._tag === "Not" && _case.guard(input) === false) return succeed(_case.evaluate(input, ...args));
|
|
1666
|
+
}
|
|
1667
|
+
return fail(input);
|
|
1668
|
+
};
|
|
1669
|
+
};
|
|
1670
|
+
//#endregion
|
|
1671
|
+
//#region ../../node_modules/.pnpm/effect@4.0.0-rc.117/node_modules/effect/dist/Match.js
|
|
1672
|
+
/**
|
|
1673
|
+
* Builds pattern matchers for TypeScript values.
|
|
1674
|
+
*
|
|
1675
|
+
* `Match` lets you add ordered cases and then finish them with a result,
|
|
1676
|
+
* fallback, `Option`, or exhaustive check. Use `Match.type` to define a
|
|
1677
|
+
* reusable matcher for a type, or `Match.value` to match one value immediately.
|
|
1678
|
+
* Cases can match literal values, predicates, object shapes, tags, negated
|
|
1679
|
+
* patterns, and common checks such as strings, numbers, records, and class
|
|
1680
|
+
* instances.
|
|
1681
|
+
*
|
|
1682
|
+
* @since 4.0.0
|
|
1683
|
+
*/
|
|
1684
|
+
/**
|
|
1685
|
+
* Creates a matcher from a specific value.
|
|
1686
|
+
*
|
|
1687
|
+
* **When to use**
|
|
1688
|
+
*
|
|
1689
|
+
* Use to match one concrete input immediately.
|
|
1690
|
+
*
|
|
1691
|
+
* **Details**
|
|
1692
|
+
*
|
|
1693
|
+
* This function allows you to define a `Matcher` directly from a given value,
|
|
1694
|
+
* rather than from a type. This is useful when working with known values,
|
|
1695
|
+
* enabling structured pattern matching on objects, primitives, or any data
|
|
1696
|
+
* structure.
|
|
1697
|
+
*
|
|
1698
|
+
* Once the matcher is created, you can use pattern-matching functions like
|
|
1699
|
+
* {@link when} to define how different cases should be handled.
|
|
1700
|
+
*
|
|
1701
|
+
* **Example** (Matching an Object by Property)
|
|
1702
|
+
*
|
|
1703
|
+
* ```ts import.meta.vitest
|
|
1704
|
+
* import { Match } from "effect"
|
|
1705
|
+
*
|
|
1706
|
+
* const input = { name: "John", age: 30 }
|
|
1707
|
+
*
|
|
1708
|
+
* // Create a matcher for the specific object
|
|
1709
|
+
* const result = Match.value(input).pipe(
|
|
1710
|
+
* // Match when the 'name' property is "John"
|
|
1711
|
+
* Match.when(
|
|
1712
|
+
* { name: "John" },
|
|
1713
|
+
* (user) => `${user.name} is ${user.age} years old`
|
|
1714
|
+
* ),
|
|
1715
|
+
* // Provide a fallback if no match is found
|
|
1716
|
+
* Match.orElse(() => "Oh, not John")
|
|
1717
|
+
* )
|
|
1718
|
+
*
|
|
1719
|
+
* result // => "John is 30 years old"
|
|
1720
|
+
* ```
|
|
1721
|
+
*
|
|
1722
|
+
* @see {@link type} for creating a matcher from a specific type.
|
|
1723
|
+
*
|
|
1724
|
+
* @category constructors
|
|
1725
|
+
* @since 4.0.0
|
|
1726
|
+
*/
|
|
1727
|
+
const value = value$1;
|
|
1728
|
+
/**
|
|
1729
|
+
* Defines a condition for matching values.
|
|
1730
|
+
*
|
|
1731
|
+
* **When to use**
|
|
1732
|
+
*
|
|
1733
|
+
* Use to add one positive pattern case to a `Match.type` or `Match.value`
|
|
1734
|
+
* pipeline when a direct value, predicate, or structured object pattern should
|
|
1735
|
+
* run a handler for matching input.
|
|
1736
|
+
*
|
|
1737
|
+
* **Details**
|
|
1738
|
+
*
|
|
1739
|
+
* Supports both direct value comparisons and predicate functions. If the
|
|
1740
|
+
* pattern matches, the associated function is executed and the matched input is
|
|
1741
|
+
* removed from the remaining cases tracked by the matcher.
|
|
1742
|
+
*
|
|
1743
|
+
* **Example** (Matching with values and predicates)
|
|
1744
|
+
*
|
|
1745
|
+
* ```ts import.meta.vitest
|
|
1746
|
+
* import { Match } from "effect"
|
|
1747
|
+
*
|
|
1748
|
+
* // Create a matcher for objects with an "age" property
|
|
1749
|
+
* const match = Match.type<{ age: number }>().pipe(
|
|
1750
|
+
* // Match when age is greater than 18
|
|
1751
|
+
* Match.when(
|
|
1752
|
+
* { age: (age: number) => age > 18 },
|
|
1753
|
+
* (user: { age: number }) => `Age: ${user.age}`
|
|
1754
|
+
* ),
|
|
1755
|
+
* // Match when age is exactly 18
|
|
1756
|
+
* Match.when({ age: 18 }, () => "You can vote"),
|
|
1757
|
+
* // Fallback case for all other ages
|
|
1758
|
+
* Match.orElse((user: { age: number }) => `${user.age} is too young`)
|
|
1759
|
+
* )
|
|
1760
|
+
*
|
|
1761
|
+
* match({ age: 20 }) // => "Age: 20"
|
|
1762
|
+
*
|
|
1763
|
+
* match({ age: 18 }) // => "You can vote"
|
|
1764
|
+
*
|
|
1765
|
+
* match({ age: 4 }) // => "4 is too young"
|
|
1766
|
+
* ```
|
|
1767
|
+
*
|
|
1768
|
+
* @see {@link whenOr} for handling any one of several patterns with the same handler
|
|
1769
|
+
* @see {@link whenAnd} for requiring all provided patterns to match before running a handler
|
|
1770
|
+
* @see {@link not} for handling inputs that do not match a pattern
|
|
1771
|
+
* @see {@link orElse} for providing a fallback when no pattern case matches
|
|
1772
|
+
*
|
|
1773
|
+
* @category defining patterns
|
|
1774
|
+
* @since 4.0.0
|
|
1775
|
+
*/
|
|
1776
|
+
const when = when$1;
|
|
1777
|
+
/**
|
|
1778
|
+
* Provides a fallback value when no patterns match.
|
|
1779
|
+
*
|
|
1780
|
+
* **When to use**
|
|
1781
|
+
*
|
|
1782
|
+
* Use to finalize a matcher with a fallback for unmatched input.
|
|
1783
|
+
*
|
|
1784
|
+
* **Details**
|
|
1785
|
+
*
|
|
1786
|
+
* This function ensures that a matcher always returns a valid result, even if
|
|
1787
|
+
* no defined patterns match. It acts as a default case, similar to the
|
|
1788
|
+
* `default` clause in a `switch` statement or the final `else` in an `if-else`
|
|
1789
|
+
* chain.
|
|
1790
|
+
*
|
|
1791
|
+
* **Example** (Providing a default value when no patterns match)
|
|
1792
|
+
*
|
|
1793
|
+
* ```ts import.meta.vitest
|
|
1794
|
+
* import { Match } from "effect"
|
|
1795
|
+
*
|
|
1796
|
+
* // Create a matcher for string or number values
|
|
1797
|
+
* const match = Match.type<string | number>().pipe(
|
|
1798
|
+
* // Match when the value is "a"
|
|
1799
|
+
* Match.when("a", () => "ok"),
|
|
1800
|
+
* // Fallback when no patterns match
|
|
1801
|
+
* Match.orElse(() => "fallback")
|
|
1802
|
+
* )
|
|
1803
|
+
*
|
|
1804
|
+
* match("a") // => "ok"
|
|
1805
|
+
*
|
|
1806
|
+
* match("b") // => "fallback"
|
|
1807
|
+
* ```
|
|
1808
|
+
*
|
|
1809
|
+
* @see {@link option} for finalizing unmatched input as `Option.none`
|
|
1810
|
+
* @see {@link result} for returning unmatched input as a `Result` failure
|
|
1811
|
+
* @see {@link orElseAbsurd} for finalizing when unmatched input should be impossible
|
|
1812
|
+
*
|
|
1813
|
+
* @category completion
|
|
1814
|
+
* @since 4.0.0
|
|
1815
|
+
*/
|
|
1816
|
+
const orElse = orElse$1;
|
|
1817
|
+
//#endregion
|
|
1818
|
+
//#region sandbox/stryker-setup.ts
|
|
3
1819
|
const globalNamespace = inject("globalNamespace");
|
|
4
1820
|
const mutantActivation = inject("mutantActivation");
|
|
5
1821
|
const mode = inject("mode");
|
|
6
1822
|
const ns = globalThis[globalNamespace] ?? (globalThis[globalNamespace] = {});
|
|
7
1823
|
ns.hitLimit = inject("hitLimit");
|
|
8
|
-
|
|
1824
|
+
const registerMutantRunHooks = () => {
|
|
9
1825
|
beforeAll(() => {
|
|
10
1826
|
ns.hitCount = 0;
|
|
11
1827
|
});
|
|
12
|
-
|
|
13
|
-
else beforeAll(() => {
|
|
1828
|
+
value(mutantActivation).pipe(when("static", () => {
|
|
14
1829
|
ns.activeMutant = inject("activeMutant");
|
|
15
|
-
})
|
|
1830
|
+
}), orElse(() => beforeAll(() => {
|
|
1831
|
+
ns.activeMutant = inject("activeMutant");
|
|
1832
|
+
})));
|
|
16
1833
|
afterAll(({}, suite) => {
|
|
17
1834
|
suite.meta.hitCount = ns.hitCount;
|
|
18
1835
|
});
|
|
19
|
-
}
|
|
1836
|
+
};
|
|
1837
|
+
const registerDryRunHooks = () => {
|
|
20
1838
|
ns.activeMutant = void 0;
|
|
21
1839
|
beforeEach(({ task }) => {
|
|
22
1840
|
ns.currentTestId = toRawTestId(task);
|
|
@@ -27,18 +1845,10 @@ if (mode === "mutant") {
|
|
|
27
1845
|
afterAll(({}, suite) => {
|
|
28
1846
|
suite.meta.mutantCoverage = ns.mutantCoverage;
|
|
29
1847
|
});
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const nameParts = [name];
|
|
33
|
-
let currentSuite = suite;
|
|
34
|
-
while (currentSuite) {
|
|
35
|
-
nameParts.unshift(currentSuite.name);
|
|
36
|
-
currentSuite = currentSuite.suite;
|
|
37
|
-
}
|
|
38
|
-
return nameParts.join(" ").trim();
|
|
39
|
-
}
|
|
1848
|
+
};
|
|
1849
|
+
value(mode).pipe(when("mutant", registerMutantRunHooks), orElse(registerDryRunHooks));
|
|
40
1850
|
function toRawTestId(test) {
|
|
41
|
-
return `${test.file.filepath}#${
|
|
1851
|
+
return `${test.file.filepath}#${test.fullTestName}`;
|
|
42
1852
|
}
|
|
43
1853
|
//#endregion
|
|
44
1854
|
export {};
|