resultar 2.0.0-beta.1 → 2.0.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,719 +1,4 @@
1
- //#region src/error.ts
2
- const defaultErrorConfig = { withStackTrace: false };
3
- const createResultarError = (message, result, config = defaultErrorConfig) => {
4
- return {
5
- name: "ResultarError",
6
- data: result.isOk() ? {
7
- type: "Ok",
8
- value: result.value
9
- } : {
10
- type: "Err",
11
- value: result.error
12
- },
13
- message,
14
- stack: config.withStackTrace ? (/* @__PURE__ */ new Error()).stack : void 0
15
- };
16
- };
17
- //#endregion
18
- //#region src/utils.ts
19
- /**
20
- * Short circuits on the FIRST Err value that we find
21
- */
22
- const combineResultList = (resultList) => {
23
- const values = [];
24
- for (const result of resultList) {
25
- if (result.isErr()) return err(result.error);
26
- values.push(result.value);
27
- }
28
- return ok(values);
29
- };
30
- const combineResultAsyncList = (asyncResultList) => ResultAsync.fromSafePromise(Promise.all(asyncResultList)).andThen(combineResultList);
31
- /**
32
- * Give a list of all the errors we find
33
- */
34
- const combineResultListWithAllErrors = (resultList) => {
35
- let acc = ok([]);
36
- for (const result of resultList) if (result.isErr() && acc.isErr()) acc.error.push(result.error);
37
- else if (result.isErr() && acc.isOk()) acc = err([result.error]);
38
- else if (result.isOk() && acc.isOk()) acc.value.push(result.value);
39
- return acc;
40
- };
41
- const combineResultAsyncListWithAllErrors = (asyncResultList) => ResultAsync.fromSafePromise(Promise.all(asyncResultList)).andThen(combineResultListWithAllErrors);
42
- //#endregion
43
- //#region src/result.ts
44
- const hasTag$1 = (value, tag) => typeof value === "object" && value !== null && "_tag" in value && value._tag === tag;
45
- /**
46
- * Runtime namespace for Result constructors and static helpers.
47
- */
48
- var ResultNamespace = class {
49
- static [Symbol.hasInstance](value) {
50
- return value instanceof Ok || value instanceof Err;
51
- }
52
- /**
53
- * Creates a `Result` by running a function that might throw.
54
- * If the function throws, the error will be caught and returned as an `Err`.
55
- * If the function succeeds, the value will be wrapped in an `Ok`.
56
- *
57
- * @param fn - The function to execute, which might throw an error
58
- * @param errorFn - Optional function to transform the thrown error before wrapping in `Err`
59
- * @returns A `Result` containing either the function's return value or the caught error
60
- */
61
- static tryCatch(fn, errorFn) {
62
- try {
63
- return ok(fn());
64
- } catch (error) {
65
- if (errorFn) return err(errorFn(error));
66
- return err(error);
67
- }
68
- }
69
- /**
70
- * Wraps a function with a try catch, creating a new function with the same
71
- * arguments but returning `Ok` if successful, `Err` if the function throws
72
- *
73
- * @param fn function to wrap with ok on success or err on failure
74
- * @param errorFn when an error is thrown, this will wrap the error result if provided
75
- */
76
- static fromThrowable(fn, errorFn) {
77
- return (...args) => {
78
- try {
79
- return ok(fn(...args));
80
- } catch (error) {
81
- if (errorFn) return err(errorFn(error));
82
- return err(error);
83
- }
84
- };
85
- }
86
- static ok(value) {
87
- return ok(value);
88
- }
89
- /**
90
- * Creates a new `Result` instance representing a successful operation with an undefined value.
91
- *
92
- * @return {Result<undefined, E>} A new `Result` instance with an undefined value.
93
- */
94
- static unit() {
95
- return unit();
96
- }
97
- static err(error) {
98
- return err(error);
99
- }
100
- static combine(resultList) {
101
- return combineResultList(resultList);
102
- }
103
- static combineWithAllErrors(resultList) {
104
- return combineResultListWithAllErrors(resultList);
105
- }
106
- };
107
- const Result = ResultNamespace;
108
- var Ok = class {
109
- constructor(value) {
110
- this.value = value;
111
- }
112
- isOk() {
113
- return true;
114
- }
115
- isErr() {
116
- return false;
117
- }
118
- map(f) {
119
- return ok(f(this.value));
120
- }
121
- filterOrElse(predicate, onFalse) {
122
- if (predicate(this.value)) return ok(this.value);
123
- return err(onFalse(this.value));
124
- }
125
- mapErr(_fn) {
126
- return ok(this.value);
127
- }
128
- andThen(f) {
129
- return f(this.value);
130
- }
131
- if(fCondition) {
132
- return { true: (fTrue) => ({ false: (fFalse) => fCondition(this.value) ? fTrue(this.value) : fFalse(this.value) }) };
133
- }
134
- orElse(_f) {
135
- return ok(this.value);
136
- }
137
- catchTag(_tag, _f) {
138
- return ok(this.value);
139
- }
140
- catchTags(_handlers) {
141
- return ok(this.value);
142
- }
143
- asyncAndThen(f) {
144
- return f(this.value);
145
- }
146
- asyncMap(f) {
147
- return ResultAsync.fromSafePromise(f(this.value));
148
- }
149
- unwrapOr(_defaultValue) {
150
- return this.value;
151
- }
152
- match(fnOk, _fnErr) {
153
- return fnOk(this.value);
154
- }
155
- matchTags(fnOk, _handlers) {
156
- return fnOk(this.value);
157
- }
158
- matchTagsPartial(fnOk, _handlers, _fallback) {
159
- return fnOk(this.value);
160
- }
161
- pipe(...fns) {
162
- const first = fns[0];
163
- if (!first) return this;
164
- let input = first(this);
165
- for (const fn of fns.slice(1)) input = fn(input);
166
- return input;
167
- }
168
- log(fn) {
169
- try {
170
- fn(this.value, void 0);
171
- } catch {}
172
- return this;
173
- }
174
- tap(fn) {
175
- try {
176
- fn(this.value);
177
- } catch {}
178
- return this;
179
- }
180
- tapError(_fn) {
181
- return this;
182
- }
183
- finally(f) {
184
- const resultDisposable = new DisposableResult(this, f);
185
- try {
186
- return resultDisposable;
187
- } finally {
188
- try {
189
- resultDisposable[Symbol.dispose]();
190
- } catch {}
191
- }
192
- }
193
- unwrapOrThrow() {
194
- return this.value;
195
- }
196
- _unsafeUnwrap(_config) {
197
- return this.value;
198
- }
199
- _unsafeUnwrapErr(config) {
200
- throw createResultarError("Called `_unsafeUnwrapErr` on an Ok", this, config);
201
- }
202
- *[Symbol.iterator]() {
203
- return this.value;
204
- }
205
- safeUnwrap() {
206
- const { value } = this;
207
- return (function* () {
208
- return value;
209
- })();
210
- }
211
- };
212
- var Err = class {
213
- constructor(error) {
214
- this.error = error;
215
- }
216
- isOk() {
217
- return false;
218
- }
219
- isErr() {
220
- return true;
221
- }
222
- map(_f) {
223
- return err(this.error);
224
- }
225
- filterOrElse(_predicate, _onFalse) {
226
- return err(this.error);
227
- }
228
- mapErr(fn) {
229
- return err(fn(this.error));
230
- }
231
- andThen(_f) {
232
- return err(this.error);
233
- }
234
- if(_fCondition) {
235
- return { true: (_fTrue) => ({ false: (_fFalse) => err(this.error) }) };
236
- }
237
- orElse(f) {
238
- return f(this.error);
239
- }
240
- catchTag(tag, f) {
241
- if (hasTag$1(this.error, tag)) return f(this.error);
242
- return err(this.error);
243
- }
244
- catchTags(handlers) {
245
- const error = this.error;
246
- if (typeof error === "object" && error !== null && "_tag" in error) {
247
- const handler = handlers[error._tag];
248
- if (handler !== void 0) return handler(error);
249
- }
250
- return err(error);
251
- }
252
- asyncAndThen(_f) {
253
- return errAsync(this.error);
254
- }
255
- asyncMap(_f) {
256
- return errAsync(this.error);
257
- }
258
- unwrapOr(defaultValue) {
259
- return defaultValue;
260
- }
261
- match(_fnOk, fnErr) {
262
- return fnErr(this.error);
263
- }
264
- matchTags(_fnOk, handlers) {
265
- const error = this.error;
266
- if (typeof error === "object" && error !== null && "_tag" in error) {
267
- const handler = handlers[error._tag];
268
- if (handler !== void 0) return handler(error);
269
- }
270
- if (handlers.Error) return handlers.Error(error);
271
- throw error;
272
- }
273
- matchTagsPartial(_fnOk, handlers, fallback) {
274
- const error = this.error;
275
- const errorHandler = handlers.Error;
276
- if (typeof error === "object" && error !== null && "_tag" in error) {
277
- const handler = handlers[error._tag];
278
- if (handler !== void 0) return handler(error);
279
- }
280
- if (errorHandler) return errorHandler(error);
281
- return fallback(error);
282
- }
283
- pipe(...fns) {
284
- const first = fns[0];
285
- if (!first) return this;
286
- let input = first(this);
287
- for (const fn of fns.slice(1)) input = fn(input);
288
- return input;
289
- }
290
- log(fn) {
291
- try {
292
- fn(void 0, this.error);
293
- } catch {}
294
- return this;
295
- }
296
- tap(_fn) {
297
- return this;
298
- }
299
- tapError(fn) {
300
- try {
301
- fn(this.error);
302
- } catch {}
303
- return this;
304
- }
305
- finally(f) {
306
- const resultDisposable = new DisposableResult(this, f);
307
- try {
308
- return resultDisposable;
309
- } finally {
310
- try {
311
- resultDisposable[Symbol.dispose]();
312
- } catch {}
313
- }
314
- }
315
- unwrapOrThrow() {
316
- throw this.error;
317
- }
318
- _unsafeUnwrap(config) {
319
- throw createResultarError("Called `_unsafeUnwrap` on an Err", this, config);
320
- }
321
- _unsafeUnwrapErr(_config) {
322
- return this.error;
323
- }
324
- *[Symbol.iterator]() {
325
- yield this;
326
- return this;
327
- }
328
- safeUnwrap() {
329
- const { error } = this;
330
- return (function* () {
331
- yield err(error);
332
- throw new Error("Do not use this generator out of `safeTry`");
333
- })();
334
- }
335
- };
336
- /**
337
- * A `Disposable` is an object that has a `dispose` method that can be used to
338
- * clean up resources.
339
- */
340
- var DisposableResult = class {
341
- constructor(result, finalizer) {
342
- this.result = result;
343
- this.finalizer = finalizer;
344
- }
345
- get value() {
346
- return this.result.isOk() ? this.result.value : void 0;
347
- }
348
- get error() {
349
- return this.result.isErr() ? this.result.error : void 0;
350
- }
351
- _unsafeUnwrap(config) {
352
- return this.result._unsafeUnwrap(config);
353
- }
354
- _unsafeUnwrapErr(config) {
355
- return this.result._unsafeUnwrapErr(config);
356
- }
357
- isOk() {
358
- return this.result.isOk();
359
- }
360
- isErr() {
361
- return this.result.isErr();
362
- }
363
- unwrapOr(defaultValue) {
364
- return this.result.unwrapOr(defaultValue);
365
- }
366
- [Symbol.dispose]() {
367
- this.finalizer(this.result.isOk() ? this.result.value : void 0, this.result.isErr() ? this.result.error : void 0);
368
- }
369
- };
370
- function safeTry(body) {
371
- const n = body().next();
372
- if (n instanceof Promise) return new ResultAsync(n.then((r) => r.value));
373
- return n.value;
374
- }
375
- function ok(value) {
376
- return new Ok(value);
377
- }
378
- function err(error) {
379
- return new Err(error);
380
- }
381
- const fromThrowable = Result.fromThrowable;
382
- function unit() {
383
- return ok(void 0);
384
- }
385
- const tryCatch = Result.tryCatch;
386
- //#endregion
387
- //#region src/result-async.ts
388
- const hasTag = (value, tag) => typeof value === "object" && value !== null && "_tag" in value && value._tag === tag;
389
- var DisposableResultAsync = class {
390
- innerPromise;
391
- constructor(res) {
392
- this.innerPromise = res;
393
- }
394
- then(successCallback, failureCallback) {
395
- return this.innerPromise.then(successCallback, failureCallback);
396
- }
397
- };
398
- /**
399
- * Represents an asynchronous Result type that wraps a Promise of a Result<T, E>.
400
- * This class provides a way to handle asynchronous operations that may succeed with a value of type T
401
- * or fail with an error of type E.
402
- *
403
- * @template T - The type of the success value
404
- * @template E - The type of the error value
405
- *
406
- * @implements {PromiseLike<Result<T, E>>}
407
- *
408
- * @example
409
- * ```typescript
410
- * // Create a successful async result
411
- * const okAsync = ResultAsync.okAsync(42);
412
- *
413
- * // Create a failed async result
414
- * const errAsync = ResultAsync.errAsync(new Error("Something went wrong"));
415
- *
416
- * // Transform a Promise into a ResultAsync
417
- * const resultFromPromise = ResultAsync.fromPromise(
418
- * fetch("https://api.example.com/data"),
419
- * (error) => new Error(`API call failed: ${error}`)
420
- * );
421
- * ```
422
- *
423
- * @remarks
424
- * ResultAsync implements the PromiseLike interface, allowing it to be used with async/await syntax.
425
- * It provides various utility methods for transforming and combining results, similar to the Result type,
426
- * but operating in an asynchronous context.
427
- *
428
- * The class includes methods for:
429
- * - Creating ResultAsync instances (okAsync, errAsync, fromPromise)
430
- * - Transforming values (map, mapErr)
431
- * - Chaining operations (andThen, orElse)
432
- * - Error handling (tapError)
433
- * - Conditional branching (if)
434
- * - Combining multiple ResultAsync instances (combine, combineWithAllErrors)
435
- */
436
- var ResultAsync = class ResultAsync {
437
- static okAsync(value) {
438
- return new ResultAsync(Promise.resolve(Result.ok(value)));
439
- }
440
- /**
441
- * Returns a ResultAsync that is immediately resolved with a Result.ok(undefined) value.
442
- *
443
- * @return {ResultAsync<undefined, E>} A ResultAsync instance with undefined as the value type and E as the error type.
444
- */
445
- static unitAsync() {
446
- return new ResultAsync(Promise.resolve(Result.unit()));
447
- }
448
- static errAsync(error) {
449
- return new ResultAsync(Promise.resolve(Result.err(error)));
450
- }
451
- static tryCatch(fn, errorFn) {
452
- return new ResultAsync((typeof fn === "function" ? Promise.try(fn) : fn).then((value) => Result.ok(value)).catch((error) => {
453
- if (errorFn) return Result.err(errorFn(error));
454
- return Result.err(error);
455
- }));
456
- }
457
- static fromSafePromise(promise) {
458
- return new ResultAsync(promise.then((value) => Result.ok(value)));
459
- }
460
- static fromPromise(promise, errorFn) {
461
- return new ResultAsync(promise.then((value) => Result.ok(value)).catch((error) => Result.err(errorFn(error))));
462
- }
463
- static combine(asyncResultList) {
464
- return combineResultAsyncList(asyncResultList);
465
- }
466
- static combineWithAllErrors(asyncResultList) {
467
- return combineResultAsyncListWithAllErrors(asyncResultList);
468
- }
469
- /**
470
- * Wraps a async function with a try catch, creating a new function with the same
471
- * arguments but returning `Ok` if successful, `Err` if the function throws
472
- *
473
- * @param fn function to wrap with ok on success or err on failure
474
- * @param errorFn when an error is thrown, this will wrap the error result if provided
475
- * @returns a new function that returns a `ResultAsync`
476
- */
477
- static fromThrowable(fn, errorFn) {
478
- return (...args) => new ResultAsync((async () => {
479
- try {
480
- const v = await fn(...args);
481
- return Result.ok(v);
482
- } catch (error) {
483
- const e = errorFn ? errorFn(error) : error;
484
- return Result.err(e);
485
- }
486
- })());
487
- }
488
- innerPromise;
489
- constructor(res) {
490
- this.innerPromise = res;
491
- }
492
- then(successCallback, failureCallback) {
493
- return this.innerPromise.then(successCallback, failureCallback);
494
- }
495
- mapErr(f) {
496
- return new ResultAsync(this.innerPromise.then(async (res) => {
497
- if (res.isOk()) return Result.ok(res.value);
498
- return Result.err(await f(res.error));
499
- }));
500
- }
501
- map(f) {
502
- return new ResultAsync(this.innerPromise.then(async (res) => {
503
- if (res.isErr()) return Result.err(res.error);
504
- return Result.ok(await f(res.value));
505
- }));
506
- }
507
- filterOrElse(predicate, onFalse) {
508
- return new ResultAsync(this.innerPromise.then(async (res) => {
509
- if (res.isErr()) return Result.err(res.error);
510
- if (await predicate(res.value)) return Result.ok(res.value);
511
- return Result.err(await onFalse(res.value));
512
- }));
513
- }
514
- andThen(f) {
515
- return new ResultAsync(this.innerPromise.then((res) => {
516
- if (res.isErr()) return Result.err(res.error);
517
- const next = f(res.value);
518
- return next instanceof ResultAsync ? next.innerPromise : next;
519
- }));
520
- }
521
- if(fCondition) {
522
- return { true: (fTrue) => ({ false: (fFalse) => new ResultAsync(this.innerPromise.then(async (res) => {
523
- if (res.isOk()) return fCondition(res.value) ? fTrue(res.value) : fFalse(res.value);
524
- return errAsync(res.error);
525
- })) }) };
526
- }
527
- orElse(f) {
528
- return new ResultAsync(this.innerPromise.then((res) => {
529
- if (res.isErr()) {
530
- const next = f(res.error);
531
- return next instanceof ResultAsync ? next.innerPromise : next;
532
- }
533
- return Result.ok(res.value);
534
- }));
535
- }
536
- catchTag(tag, f) {
537
- return new ResultAsync(this.innerPromise.then((res) => {
538
- if (res.isOk()) return Result.ok(res.value);
539
- if (hasTag(res.error, tag)) {
540
- const next = f(res.error);
541
- return next instanceof ResultAsync ? next.innerPromise : next;
542
- }
543
- return Result.err(res.error);
544
- }));
545
- }
546
- catchTags(handlers) {
547
- return new ResultAsync(this.innerPromise.then((res) => {
548
- if (res.isOk()) return Result.ok(res.value);
549
- const error = res.error;
550
- if (typeof error === "object" && error !== null && "_tag" in error) {
551
- const handler = handlers[error._tag];
552
- if (handler !== void 0) {
553
- const next = handler(error);
554
- return next instanceof ResultAsync ? next.innerPromise : next;
555
- }
556
- }
557
- return Result.err(error);
558
- }));
559
- }
560
- async match(ok, fnErr) {
561
- return this.innerPromise.then((res) => res.match(ok, fnErr));
562
- }
563
- async matchTags(ok, handlers) {
564
- return this.innerPromise.then((res) => {
565
- if (res.isOk()) return ok(res.value);
566
- const error = res.error;
567
- if (typeof error === "object" && error !== null && "_tag" in error) {
568
- const handler = handlers[error._tag];
569
- if (handler !== void 0) return handler(error);
570
- }
571
- if (handlers.Error) return handlers.Error(error);
572
- throw error;
573
- });
574
- }
575
- async matchTagsPartial(ok, handlers, fallback) {
576
- return this.innerPromise.then((res) => {
577
- if (res.isOk()) return ok(res.value);
578
- const error = res.error;
579
- const errorHandler = handlers.Error;
580
- if (typeof error === "object" && error !== null && "_tag" in error) {
581
- const handler = handlers[error._tag];
582
- if (handler !== void 0) return handler(error);
583
- }
584
- if (errorHandler) return errorHandler(error);
585
- return fallback(error);
586
- });
587
- }
588
- async unwrapOr(t) {
589
- return this.innerPromise.then((res) => res.unwrapOr(t));
590
- }
591
- async unwrapOrThrow() {
592
- return this.innerPromise.then((res) => res.unwrapOrThrow());
593
- }
594
- pipe(...fns) {
595
- const first = fns[0];
596
- if (!first) return this;
597
- let input = first(this);
598
- for (const fn of fns.slice(1)) input = fn(input);
599
- return input;
600
- }
601
- /**
602
- * Runs a side effect for either variant and preserves the original async result.
603
- *
604
- * For `Ok`, the callback receives `(value, undefined)`.
605
- * For `Err`, the callback receives `(undefined, error)`.
606
- * Callback errors and rejected callback promises are intentionally ignored.
607
- *
608
- * Use `map`, `mapErr`, `andThen`, or `orElse` when the callback should
609
- * transform the result.
610
- */
611
- log(f) {
612
- return new ResultAsync(this.innerPromise.then(async (res) => {
613
- if (res.isOk()) {
614
- try {
615
- await f(res.value);
616
- } catch {}
617
- return okAsync(res.value);
618
- }
619
- try {
620
- await f(void 0, res.error);
621
- } catch {}
622
- return errAsync(res.error);
623
- }));
624
- }
625
- /**
626
- * Runs a side effect only for the `Ok` variant and preserves the original async result.
627
- *
628
- * Callback errors and rejected callback promises are intentionally ignored.
629
- * Use `map` or `andThen` when the callback should transform the value.
630
- */
631
- tap(f) {
632
- return new ResultAsync(this.innerPromise.then(async (res) => {
633
- if (res.isErr()) return errAsync(res.error);
634
- try {
635
- await f(res.value);
636
- } catch {}
637
- return okAsync(res.value);
638
- }));
639
- }
640
- /**
641
- * Runs a side effect only for the `Err` variant and preserves the original async result.
642
- *
643
- * Callback errors and rejected callback promises are intentionally ignored.
644
- * Use `mapErr` or `orElse` when the callback should transform the error.
645
- */
646
- tapError(f) {
647
- return new ResultAsync(this.innerPromise.then(async (res) => {
648
- if (res.isErr()) {
649
- try {
650
- await f(res.error);
651
- } catch {}
652
- return errAsync(res.error);
653
- }
654
- return okAsync(res.value);
655
- }));
656
- }
657
- /**
658
- * Runs a cleanup side effect with `(value, error)` after the inner promise
659
- * settles to a `Result`, then preserves the original async result.
660
- *
661
- * Callback errors and rejected callback promises are intentionally ignored.
662
- */
663
- finally(f) {
664
- return new DisposableResultAsync(this.innerPromise.then(async (res) => {
665
- try {
666
- await f(res.isOk() ? res.value : void 0, res.isErr() ? res.error : void 0);
667
- } catch {}
668
- return res;
669
- }));
670
- }
671
- async *[Symbol.asyncIterator]() {
672
- const result = await this.innerPromise;
673
- if (result.isOk()) return result.value;
674
- yield err(result.error);
675
- return void 0;
676
- }
677
- /**
678
- * @deprecated will be removed in 2.0.0.
679
- *
680
- * You can use `safeTry` without this method.
681
- * @example
682
- * ```typescript
683
- * safeTry(async function* () {
684
- * const okValue = yield* yourResult
685
- * })
686
- * ```
687
- * Emulates Rust's `?` operator in `safeTry`'s body. See also `safeTry`.
688
- */
689
- async *safeUnwrap() {
690
- const result = await this.innerPromise;
691
- if (result.isOk()) return result.value;
692
- yield err(result.error);
693
- throw new Error("Do not use this generator out of `safeTry`");
694
- }
695
- };
696
- /**
697
- * @deprecated Use `safeTry` instead.
698
- * @see `safeTry`
699
- *
700
- * This will be removed in the next major version.
701
- */
702
- function safeTryAsync(body) {
703
- return new ResultAsync((async () => {
704
- const n = await body().next();
705
- if (n.value.isOk()) return okAsync(n.value.value);
706
- return errAsync(n.value.error);
707
- })());
708
- }
709
- const okAsync = ResultAsync.okAsync;
710
- const errAsync = ResultAsync.errAsync;
711
- const fromPromise = ResultAsync.fromPromise;
712
- const fromSafePromise = ResultAsync.fromSafePromise;
713
- const unitAsync = ResultAsync.unitAsync;
714
- const fromThrowableAsync = ResultAsync.fromThrowable;
715
- const tryCatchAsync = ResultAsync.tryCatch;
716
- //#endregion
1
+ import { _ as unit, a as fromSafePromise, c as tryCatchAsync, d as Result, f as err, g as tryCatch, h as safeTry, i as fromPromise, l as unitAsync, m as ok, n as ResultAsync, o as fromThrowableAsync, p as fromThrowable, r as errAsync, s as okAsync, t as DisposableResultAsync, u as DisposableResult } from "./result-async-CdlVdXgX.js";
717
2
  //#region src/tagged-error.ts
718
3
  const defaultBaseError = Error;
719
4
  const defaultMessageTemplate = "$message";
@@ -814,7 +99,7 @@ function createTaggedError(options) {
814
99
  messageTemplate: this.messageTemplate,
815
100
  name: this.name
816
101
  };
817
- if (this.cause !== void 0) json.cause = serializeCause(this.cause);
102
+ if (this.cause !== void 0) json["cause"] = serializeCause(this.cause);
818
103
  for (const [key, value] of Object.entries(this)) if (!(key in json) && key !== "cause" && key !== "stack") json[key] = value;
819
104
  return json;
820
105
  }
@@ -838,6 +123,6 @@ const matchErrorPartial = (error, handlers, fallback) => {
838
123
  return fallback(error);
839
124
  };
840
125
  //#endregion
841
- export { Result, ResultAsync, createTaggedError, err, errAsync, findCause, fromPromise, fromSafePromise, fromThrowable, fromThrowableAsync, isError, matchError, matchErrorPartial, ok, okAsync, safeTry, safeTryAsync, tryCatch, tryCatchAsync, unit, unitAsync };
126
+ export { DisposableResult, DisposableResultAsync, Result, ResultAsync, createTaggedError, err, errAsync, findCause, fromPromise, fromSafePromise, fromThrowable, fromThrowableAsync, isError, matchError, matchErrorPartial, ok, okAsync, safeTry, tryCatch, tryCatchAsync, unit, unitAsync };
842
127
 
843
128
  //# sourceMappingURL=index.js.map