functype 0.9.5 → 0.10.1

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.
@@ -1,5 +1,149 @@
1
1
  import { T as Type, a as Typeable, S as Serializable, F as Foldable, P as Pipe } from './Serializable-CK9upOU0.js';
2
2
 
3
+ /**
4
+ * Universal operations that work on any container (single-value or collection).
5
+ * These operations make sense for Option, Either, Try, List, Set, etc.
6
+ *
7
+ * @typeParam A - The type of value(s) in the container
8
+ */
9
+ interface ContainerOps<A extends Type> {
10
+ /**
11
+ * Counts elements that satisfy the predicate.
12
+ * For single-value containers: returns 0 or 1
13
+ * For collections: returns the count of matching elements
14
+ */
15
+ count(p: (x: A) => boolean): number;
16
+ /**
17
+ * Finds the first element that satisfies the predicate.
18
+ * For single-value containers: returns Some(value) if predicate matches, None otherwise
19
+ * For collections: returns the first matching element wrapped in Option
20
+ */
21
+ find(p: (a: A) => boolean): Option<A>;
22
+ /**
23
+ * Tests whether any element satisfies the predicate.
24
+ * For single-value containers: tests the single value
25
+ * For collections: returns true if any element matches
26
+ */
27
+ exists(p: (a: A) => boolean): boolean;
28
+ /**
29
+ * Applies an effect function to each element.
30
+ * For single-value containers: applies to the value if present
31
+ * For collections: applies to each element
32
+ */
33
+ forEach(f: (a: A) => void): void;
34
+ }
35
+ /**
36
+ * Operations specific to collections (List, Set, etc.).
37
+ * These operations don't make sense for single-value containers.
38
+ *
39
+ * @typeParam A - The element type
40
+ * @typeParam Self - The collection type itself for proper return types
41
+ */
42
+ interface CollectionOps<A extends Type, Self> {
43
+ /**
44
+ * Drops the first n elements from the collection.
45
+ */
46
+ drop(n: number): Self;
47
+ /**
48
+ * Drops the last n elements from the collection.
49
+ */
50
+ dropRight(n: number): Self;
51
+ /**
52
+ * Drops elements from the start while the predicate is true.
53
+ */
54
+ dropWhile(p: (a: A) => boolean): Self;
55
+ /**
56
+ * Flattens a collection of collections into a single collection.
57
+ */
58
+ flatten<B>(): Self;
59
+ /**
60
+ * Gets the first element of the collection.
61
+ */
62
+ get head(): A | undefined;
63
+ /**
64
+ * Gets the first element wrapped in Option.
65
+ */
66
+ get headOption(): Option<A>;
67
+ /**
68
+ * Converts the collection to an array.
69
+ */
70
+ toArray<B = A>(): B[];
71
+ }
72
+
73
+ /**
74
+ * Functor type class - supports mapping over wrapped values
75
+ *
76
+ * Laws:
77
+ * - Identity: fa.map(x => x) ≡ fa
78
+ * - Composition: fa.map(f).map(g) ≡ fa.map(x => g(f(x)))
79
+ */
80
+ interface Functor<A extends Type> {
81
+ map<B extends Type>(f: (value: A) => B): Functor<B>;
82
+ }
83
+ /**
84
+ * Applicative functor - supports applying wrapped functions to wrapped values
85
+ *
86
+ * Laws:
87
+ * - Identity: pure(x => x).ap(v) ≡ v
88
+ * - Composition: pure(compose).ap(u).ap(v).ap(w) ≡ u.ap(v.ap(w))
89
+ * - Homomorphism: pure(f).ap(pure(x)) ≡ pure(f(x))
90
+ * - Interchange: u.ap(pure(y)) ≡ pure(f => f(y)).ap(u)
91
+ */
92
+ interface Applicative<A extends Type> extends Functor<A> {
93
+ ap<B extends Type>(ff: Applicative<(value: A) => B>): Applicative<B>;
94
+ }
95
+ /**
96
+ * Monad type class - supports flat mapping (chaining) operations
97
+ *
98
+ * Laws:
99
+ * - Left identity: pure(a).flatMap(f) ≡ f(a)
100
+ * - Right identity: m.flatMap(pure) ≡ m
101
+ * - Associativity: m.flatMap(f).flatMap(g) ≡ m.flatMap(x => f(x).flatMap(g))
102
+ */
103
+ interface Monad<A extends Type> extends Applicative<A> {
104
+ flatMap<B extends Type>(f: (value: A) => Monad<B>): Monad<B>;
105
+ }
106
+ /**
107
+ * Async monad - supports asynchronous monadic operations
108
+ * Extends Monad so it has map, ap, and flatMap in addition to flatMapAsync
109
+ */
110
+ interface AsyncMonad<A extends Type> extends Monad<A> {
111
+ flatMapAsync<B extends Type>(f: (value: A) => PromiseLike<AsyncMonad<B>>): PromiseLike<AsyncMonad<B>>;
112
+ }
113
+
114
+ /**
115
+ * Promisable trait - supports conversion to Promise
116
+ *
117
+ * Represents containers or values that can be converted to Promise form.
118
+ * This enables integration with async/await patterns and Promise-based APIs
119
+ * while maintaining functional programming principles.
120
+ *
121
+ * @template A - The type of value contained within the Promise
122
+ *
123
+ * @example
124
+ * ```typescript
125
+ * const either: Either<string, number> = Right(42)
126
+ * const promise: Promise<number> = either.toPromise()
127
+ * // Promise resolves with 42
128
+ *
129
+ * const leftEither: Either<string, number> = Left("error")
130
+ * const failedPromise: Promise<number> = leftEither.toPromise()
131
+ * // Promise rejects with "error"
132
+ * ```
133
+ */
134
+ interface Promisable<A extends Type> {
135
+ /**
136
+ * Converts this container to a Promise
137
+ *
138
+ * The behavior depends on the implementing container:
139
+ * - Success/Right/Some containers resolve with their value
140
+ * - Failure/Left/None containers reject with their error/default error
141
+ *
142
+ * @returns A Promise that resolves or rejects based on the container's state
143
+ */
144
+ toPromise(): Promise<A>;
145
+ }
146
+
3
147
  /**
4
148
  * Creates a Some variant of Option containing a value.
5
149
  * @param value - The value to wrap in Some
@@ -31,7 +175,7 @@ declare const OptionConstructor: <T extends Type>(value: T | null | undefined) =
31
175
  * It's used to handle potentially null or undefined values in a type-safe way.
32
176
  * @typeParam T - The type of the value contained in the Option
33
177
  */
34
- interface Option<T extends Type> extends Functype<T, "Some" | "None"> {
178
+ interface Option<T extends Type> extends Functype<T, "Some" | "None">, Promisable<T> {
35
179
  /** The contained value (undefined for None) */
36
180
  readonly value: T | undefined;
37
181
  /** Whether this Option contains no value */
@@ -40,12 +184,18 @@ interface Option<T extends Type> extends Functype<T, "Some" | "None"> {
40
184
  * Returns true if this Option is a Some (contains a value)
41
185
  * @returns true if this Option contains a value, false otherwise
42
186
  */
43
- isSome(): boolean;
187
+ isSome(): this is Option<T> & {
188
+ value: T;
189
+ isEmpty: false;
190
+ };
44
191
  /**
45
192
  * Returns true if this Option is a None (contains no value)
46
193
  * @returns true if this Option is empty, false otherwise
47
194
  */
48
- isNone(): boolean;
195
+ isNone(): this is Option<T> & {
196
+ value: undefined;
197
+ isEmpty: true;
198
+ };
49
199
  /**
50
200
  * Extracts the value if present
51
201
  * @throws Error if the Option is None
@@ -402,117 +552,6 @@ declare const MatchableUtils: {
402
552
  when: <A, R>(predicate: (value: A) => boolean, handler: (value: A) => R) => (value: A) => R | undefined;
403
553
  };
404
554
 
405
- /**
406
- * Universal operations that work on any container (single-value or collection).
407
- * These operations make sense for Option, Either, Try, List, Set, etc.
408
- *
409
- * @typeParam A - The type of value(s) in the container
410
- */
411
- interface ContainerOps<A extends Type> {
412
- /**
413
- * Counts elements that satisfy the predicate.
414
- * For single-value containers: returns 0 or 1
415
- * For collections: returns the count of matching elements
416
- */
417
- count(p: (x: A) => boolean): number;
418
- /**
419
- * Finds the first element that satisfies the predicate.
420
- * For single-value containers: returns Some(value) if predicate matches, None otherwise
421
- * For collections: returns the first matching element wrapped in Option
422
- */
423
- find(p: (a: A) => boolean): Option<A>;
424
- /**
425
- * Tests whether any element satisfies the predicate.
426
- * For single-value containers: tests the single value
427
- * For collections: returns true if any element matches
428
- */
429
- exists(p: (a: A) => boolean): boolean;
430
- /**
431
- * Applies an effect function to each element.
432
- * For single-value containers: applies to the value if present
433
- * For collections: applies to each element
434
- */
435
- forEach(f: (a: A) => void): void;
436
- }
437
- /**
438
- * Operations specific to collections (List, Set, etc.).
439
- * These operations don't make sense for single-value containers.
440
- *
441
- * @typeParam A - The element type
442
- * @typeParam Self - The collection type itself for proper return types
443
- */
444
- interface CollectionOps<A extends Type, Self> {
445
- /**
446
- * Drops the first n elements from the collection.
447
- */
448
- drop(n: number): Self;
449
- /**
450
- * Drops the last n elements from the collection.
451
- */
452
- dropRight(n: number): Self;
453
- /**
454
- * Drops elements from the start while the predicate is true.
455
- */
456
- dropWhile(p: (a: A) => boolean): Self;
457
- /**
458
- * Flattens a collection of collections into a single collection.
459
- */
460
- flatten<B>(): Self;
461
- /**
462
- * Gets the first element of the collection.
463
- */
464
- get head(): A | undefined;
465
- /**
466
- * Gets the first element wrapped in Option.
467
- */
468
- get headOption(): Option<A>;
469
- /**
470
- * Converts the collection to an array.
471
- */
472
- toArray<B = A>(): B[];
473
- }
474
-
475
- /**
476
- * Functor type class - supports mapping over wrapped values
477
- *
478
- * Laws:
479
- * - Identity: fa.map(x => x) ≡ fa
480
- * - Composition: fa.map(f).map(g) ≡ fa.map(x => g(f(x)))
481
- */
482
- interface Functor<A extends Type> {
483
- map<B extends Type>(f: (value: A) => B): Functor<B>;
484
- }
485
- /**
486
- * Applicative functor - supports applying wrapped functions to wrapped values
487
- *
488
- * Laws:
489
- * - Identity: pure(x => x).ap(v) ≡ v
490
- * - Composition: pure(compose).ap(u).ap(v).ap(w) ≡ u.ap(v.ap(w))
491
- * - Homomorphism: pure(f).ap(pure(x)) ≡ pure(f(x))
492
- * - Interchange: u.ap(pure(y)) ≡ pure(f => f(y)).ap(u)
493
- */
494
- interface Applicative<A extends Type> extends Functor<A> {
495
- ap<B extends Type>(ff: Applicative<(value: A) => B>): Applicative<B>;
496
- }
497
- /**
498
- * Monad type class - supports flat mapping (chaining) operations
499
- *
500
- * Laws:
501
- * - Left identity: pure(a).flatMap(f) ≡ f(a)
502
- * - Right identity: m.flatMap(pure) ≡ m
503
- * - Associativity: m.flatMap(f).flatMap(g) ≡ m.flatMap(x => f(x).flatMap(g))
504
- */
505
- interface Monad<A extends Type> extends Applicative<A> {
506
- flatMap<B extends Type>(f: (value: A) => Monad<B>): Monad<B>;
507
- }
508
- /**
509
- * Async monad - supports asynchronous monadic operations
510
- * Extends Monad so it has map, ap, and flatMap in addition to flatMapAsync
511
- */
512
- interface AsyncMonad<A extends Type> extends Monad<A> {
513
- flatMapAsync<B extends Type>(f: (value: A) => PromiseLike<AsyncMonad<B>>): PromiseLike<AsyncMonad<B>>;
514
- }
515
-
516
555
  /**
517
556
  * Traversable typeclass for data structures that can be traversed through
518
557
  */
@@ -589,11 +628,17 @@ declare const tryCatchAsync: <L extends Type, R extends Type>(f: () => Promise<R
589
628
  * @module Either
590
629
  * @category Core
591
630
  */
592
- interface Either<L extends Type, R extends Type> extends FunctypeBase<R, "Left" | "Right">, PromiseLike<R> {
631
+ interface Either<L extends Type, R extends Type> extends FunctypeBase<R, "Left" | "Right">, Promisable<R> {
593
632
  readonly _tag: "Left" | "Right";
594
633
  value: L | R;
595
- isLeft: () => boolean;
596
- isRight: () => boolean;
634
+ isLeft(): this is Either<L, R> & {
635
+ readonly _tag: "Left";
636
+ value: L;
637
+ };
638
+ isRight(): this is Either<L, R> & {
639
+ readonly _tag: "Right";
640
+ value: R;
641
+ };
597
642
  get: () => R;
598
643
  getOrElse: (defaultValue: R) => R;
599
644
  getOrThrow: (error?: Error) => R;
@@ -668,4 +713,4 @@ declare const Either: {
668
713
  fromBinary: <L extends Type, R extends Type>(binary: string) => Either<L, R>;
669
714
  };
670
715
 
671
- export { type Applicative as A, type Collection as C, Either as E, type FunctypeBase as F, List as L, type Matchable as M, None as N, Option as O, Right as R, Some as S, type Traversable as T, type Extractable as a, type TestEither as b, Left as c, isLeft as d, TypeCheckRight as e, TypeCheckLeft as f, tryCatchAsync as g, isExtractable as h, isRight as i, type Functype as j, type FunctypeCollection as k, MatchableUtils as l, OptionConstructor as m, Set as n, type CollectionOps as o, type ContainerOps as p, type AsyncMonad as q, type Functor as r, type Monad as s, tryCatch as t };
716
+ export { type Applicative as A, type Collection as C, Either as E, type FunctypeBase as F, List as L, type Matchable as M, None as N, Option as O, type Promisable as P, Right as R, Some as S, type Traversable as T, type Extractable as a, type TestEither as b, Left as c, isLeft as d, TypeCheckRight as e, TypeCheckLeft as f, tryCatchAsync as g, isExtractable as h, isRight as i, type Functype as j, type FunctypeCollection as k, MatchableUtils as l, OptionConstructor as m, Set as n, type CollectionOps as o, type ContainerOps as p, type AsyncMonad as q, type Functor as r, type Monad as s, tryCatch as t };
@@ -0,0 +1,43 @@
1
+ import {a,b as b$1}from'./chunk-BQJB6CCW.mjs';import {a as a$1}from'./chunk-YBBRJTHY.mjs';import le from'safe-stable-stringify';var W=Set;var N=e=>{let t=new W(e),r={_tag:"Set",[Symbol.iterator]:()=>t[Symbol.iterator](),add:n=>N([...t,n]),remove:n=>{let o=new W(t);return o.delete(n),N(o)},contains:n=>t.has(n),has:n=>t.has(n),map:n=>N(Array.from(t).map(n)),ap:n=>{let o=new W;for(let a of t)for(let s of n)o.add(s(a));return N(o)},flatMap:n=>{let o=new W;for(let a of t)for(let s of n(a))o.add(s);return N(o)},flatMapAsync:async n=>{let o=new W;for(let a of t){let s=await n(a);for(let i of s)o.add(i);}return N(o)},fold:(n,o)=>{if(t.size===0)return n();let a=Array.from(t);if(a.length===0)return n();let s=a[0];return s===void 0?n():o(s)},foldLeft:n=>o=>{let a=n;for(let s of t)a=o(a,s);return a},foldRight:n=>o=>Array.from(t).reduceRight((s,i)=>o(i,s),n),get size(){return t.size},get isEmpty(){return t.size===0},reduce:n=>{let o=Array.from(t);if(o.length===0)throw new Error("Cannot reduce empty Set");return o.reduce(n)},reduceRight:n=>{let o=Array.from(t);if(o.length===0)throw new Error("Cannot reduceRight empty Set");return o.reduceRight(n)},count:n=>{let o=0;for(let a of t)n(a)&&o++;return o},find:n=>{for(let o of t)if(n(o))return d(o);return d(null)},exists:n=>{for(let o of t)if(n(o))return true;return false},forEach:n=>{t.forEach(n);},filter:n=>{let o=new W;for(let a of t)n(a)&&o.add(a);return N(o)},filterNot:n=>{let o=new W;for(let a of t)n(a)||o.add(a);return N(o)},drop:n=>N(Array.from(t).slice(n)),dropRight:n=>N(Array.from(t).slice(0,-n)),dropWhile:n=>{let o=Array.from(t),a=o.findIndex(s=>!n(s));return N(a===-1?[]:o.slice(a))},flatten:()=>{let n=new W;for(let o of t)if(Array.isArray(o))for(let a of o)n.add(a);else if(o&&typeof o=="object"&&Symbol.iterator in o)for(let a of o)n.add(a);else n.add(o);return N(n)},get head(){return Array.from(t)[0]},get headOption(){let n=Array.from(t)[0];return d(n)},toList:()=>y(Array.from(t)),toSet:()=>r,toArray:()=>Array.from(t),toString:()=>`Set(${Array.from(t).toString()})`,toValue:()=>({_tag:"Set",value:Array.from(t)}),pipe:n=>n(Array.from(t)),serialize:()=>({toJSON:()=>JSON.stringify({_tag:"Set",value:Array.from(t)}),toYAML:()=>`_tag: Set
2
+ value: ${JSON.stringify(Array.from(t))}`,toBinary:()=>Buffer.from(JSON.stringify({_tag:"Set",value:Array.from(t)})).toString("base64")})};return r},Ge=e=>N(e),Se={fromJSON:e=>{let t=JSON.parse(e);return G(t.value)},fromYAML:e=>{let r=e.split(`
3
+ `)[1]?.split(": ")[1];if(!r)return G([]);let n=JSON.parse(r);return G(n)},fromBinary:e=>{let t=Buffer.from(e,"base64").toString();return Se.fromJSON(t)}},G=a(Ge,Se);function fe({_tag:e,impl:t}){return {...t,_tag:e}}function he(e,t){return !e||typeof e!="object"||!("_tag"in e)?false:t?e._tag===t:true}var v=e=>{let t=Array.from(e??[]),r={_tag:"List",[Symbol.iterator]:()=>t[Symbol.iterator](),get size(){return t.length},get length(){return t.length},map:n=>v(t.map(n)),ap:n=>v(t.flatMap(o=>Array.from(n).map(a=>a(o)))),flatMap:n=>v(t.flatMap(o=>Array.from(n(o)))),flatMapAsync:async n=>{let o=await Promise.all(t.map(async a=>await n(a)));return v(o.flatMap(a=>Array.from(a)))},forEach:n=>t.forEach(n),contains:n=>t.includes(n),count:n=>t.filter(n).length,exists:n=>t.some(n),filter:n=>v(t.filter(n)),filterNot:n=>v(t.filter(o=>!n(o))),filterType:n=>v(t.filter(o=>he(o,n))),find:(n,o)=>{let a=t.find(s=>n(s)&&(o?he(s,o):true));return d(a)},get head(){return t[0]},get headOption(){return t.length>0?d(t[0]):k()},get isEmpty(){return t.length===0},toArray:()=>[...t],reduce:n=>t.reduce(n),reduceRight:n=>t.reduceRight(n),fold:(n,o)=>{if(t.length===0)return n();let a=t[0];return o(a)},foldLeft:n=>o=>t.reduce(o,n),foldRight:n=>o=>t.reduceRight((a,s)=>o(s,a),n),match:n=>t.length===0?n.Empty():n.NonEmpty([...t]),remove:n=>v(t.filter(o=>o!==n)),removeAt:n=>n<0||n>=t.length?r:v([...t.slice(0,n),...t.slice(n+1)]),add:n=>v([...t,n]),get:n=>d(t[n]),concat:n=>v([...t,...n.toArray()]),drop:n=>v(t.slice(n)),dropRight:n=>v(t.slice(0,-n)),dropWhile:n=>v(t.slice(t.findIndex(o=>!n(o)))),flatten:()=>v(t.flatMap(n=>Array.isArray(n)?n:[n])),toList:()=>r,toSet:()=>G(t),toString:()=>`List(${le(t)})`,toValue:()=>({_tag:"List",value:t}),pipe:n=>n([...t]),serialize:()=>({toJSON:()=>JSON.stringify({_tag:"List",value:t}),toYAML:()=>`_tag: List
4
+ value: ${le(t)}`,toBinary:()=>Buffer.from(JSON.stringify({_tag:"List",value:t})).toString("base64")})};return r},He=e=>v(e),Oe={fromJSON:e=>{let t=JSON.parse(e);return y(t.value)},fromYAML:e=>{let r=e.split(`
5
+ `)[1]?.split(": ")[1];if(!r)return y([]);let n=JSON.parse(r);return y(n)},fromBinary:e=>{let t=Buffer.from(e,"base64").toString();return Oe.fromJSON(t)}},y=a(He,Oe);var Ne=e=>({_tag:"Right",value:e,isLeft(){return false},isRight(){return true},get:()=>e,getOrElse:t=>e,getOrThrow:()=>e,orElse:t=>c(e),orNull:()=>e,orUndefined:()=>e,map:t=>c(t(e)),ap:t=>t._tag==="Right"?c(t.value(e)):p(t.value),mapAsync:t=>t(e).then(r=>c(r)).catch(r=>Promise.resolve(p(r))),merge:t=>t.isLeft()?p(t.value):c([e,t.value]),flatMap:t=>t(e),flatMapAsync:t=>t(e).catch(r=>p(r)),toOption:()=>U(e),toList:()=>y([e]),toJSON(){return {_tag:"Right",value:e}},toString:()=>`Right(${le(e)})`,*[Symbol.iterator](){yield e;},*yield(){yield e;},traverse:t=>{let r=t(e);return r.isLeft()?p(r.value):c([r.value])},*lazyMap(t){yield c(t(e));},tap:t=>(t(e),c(e)),tapLeft:t=>c(e),mapLeft:t=>c(e),bimap:(t,r)=>c(r(e)),fold:(t,r)=>r(e),foldLeft:t=>r=>r(t,e),foldRight:t=>r=>r(e,t),match:t=>t.Right(e),swap:()=>p(e),toPromise:()=>Promise.resolve(e),toValue:()=>({_tag:"Right",value:e}),pipeEither:(t,r)=>r(e),pipe:t=>t(e),serialize:()=>({toJSON:()=>JSON.stringify({_tag:"Right",value:e}),toYAML:()=>`_tag: Right
6
+ value: ${le(e)}`,toBinary:()=>Buffer.from(JSON.stringify({_tag:"Right",value:e})).toString("base64")}),get size(){return 1},get isEmpty(){return false},contains:t=>e===t,reduce:t=>e,reduceRight:t=>e,count:t=>t(e)?1:0,find:t=>t(e)?U(e):k(),exists:t=>t(e),forEach:t=>t(e)}),_e=e=>({_tag:"Left",value:e,isLeft(){return true},isRight(){return false},get:()=>{throw new Error(`Cannot call get() on Left(${le(e)})`)},getOrElse:t=>t,getOrThrow:t=>{throw t??e},orElse:t=>t,orNull:()=>null,orUndefined:()=>{},map:t=>p(e),ap:t=>p(e),mapAsync:t=>Promise.resolve(p(e)),merge:t=>p(e),flatMap:t=>p(e),flatMapAsync:t=>Promise.resolve(p(e)),toOption:()=>k(),toList:()=>y(),toJSON(){return {_tag:"Left",value:e}},toString:()=>`Left(${le(e)})`,*[Symbol.iterator](){},*yield(){},traverse:t=>p(e),*lazyMap(t){yield p(e);},tap:t=>p(e),tapLeft:t=>(t(e),p(e)),mapLeft:t=>p(t(e)),bimap:(t,r)=>p(t(e)),fold:(t,r)=>t(e),foldLeft:t=>r=>t,foldRight:t=>r=>t,match:t=>t.Left(e),swap:()=>c(e),toPromise:()=>Promise.reject(e),toValue:()=>({_tag:"Left",value:e}),pipeEither:(t,r)=>t(e),pipe:t=>t(e),serialize:()=>({toJSON:()=>JSON.stringify({_tag:"Left",value:e}),toYAML:()=>`_tag: Left
7
+ value: ${le(e)}`,toBinary:()=>Buffer.from(JSON.stringify({_tag:"Left",value:e})).toString("base64")}),get size(){return 0},get isEmpty(){return true},contains:t=>false,reduce:t=>{throw new Error("Cannot reduce a Left")},reduceRight:t=>{throw new Error("Cannot reduceRight a Left")},count:t=>0,find:t=>k(),exists:t=>false,forEach:t=>{}}),c=e=>Ne(e),p=e=>_e(e),Mt=e=>e.isRight(),Vt=e=>e.isLeft(),Ct=(e,t)=>{try{return c(e())}catch(r){return p(t(r))}},Ze=e=>Ne(e);console.assert(Ze);var Xe=e=>_e(e);console.assert(Xe);var zt=async(e,t)=>{try{let r=await e();return c(r)}catch(r){return p(t(r))}},Pe={sequence:e=>e.reduce((t,r)=>t.isLeft()?t:r.isLeft()?p(r.value):t.map(n=>[...n,r.value]),c([])),traverse:(e,t)=>Pe.sequence(e.map(t)),fromNullable:(e,t)=>e==null?p(t):c(e),fromPredicate:(e,t,r)=>t(e)?c(e):p(r),ap:(e,t)=>e.flatMap(r=>t.map(r)),fromPromise:async(e,t)=>{try{let r=await e;return c(r)}catch(r){return p(t(r))}},fromJSON:e=>{let t=JSON.parse(e);return t._tag==="Right"?c(t.value):p(t.value)},fromYAML:e=>{let t=e.split(`
8
+ `),r=t[0]?.split(": ")[1],n=t[1]?.split(": ")[1];if(!r||!n)throw new Error("Invalid YAML format for Either");let o=JSON.parse(n);return r==="Right"?c(o):p(o)},fromBinary:e=>{let t=Buffer.from(e,"base64").toString();return Pe.fromJSON(t)}};function M(e,t){return {brand:e,validate:t,of:r=>t(r)?d(a$1(e,r)):d.none(),from:r=>t(r)?c(a$1(e,r)):p(`Invalid ${e}: validation failed`),unsafeOf:r=>{if(!t(r))throw new Error(`Invalid ${e}: validation failed`);return a$1(e,r)},is:r=>{try{return t(r)}catch{return false}},unwrap:r=>r,refine:(r,n)=>M(r,o=>t(o)&&n(o))}}var et=M("PositiveNumber",e=>e>0),Jt=M("NonNegativeNumber",e=>e>=0),Wt=M("IntegerNumber",e=>Number.isInteger(e)),jt=et.refine("PositiveInteger",e=>Number.isInteger(e)),qt=M("NonEmptyString",e=>e.length>0),Yt=M("EmailAddress",e=>/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e)),Qt=M("UrlString",e=>{try{return new URL(e),!0}catch{return !1}}),Gt=M("UUID",e=>/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(e)),Ht=M("ISO8601Date",e=>!isNaN(Date.parse(e))&&/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/.test(e));function Zt(e,t,r){return M(e,n=>n>=t&&n<=r)}function Xt(e,t,r){return M(e,n=>n.length>=t&&n.length<=r)}function er(e,t){return M(e,r=>t.test(r))}var Ae=e=>{let t=n=>typeof n=="function"?n():n,r={when:(n,o)=>e.resolved?r:n?Ae({resolved:true,value:t(o)}):r,elseWhen:(n,o)=>e.resolved?r:n?Ae({resolved:true,value:t(o)}):r,else:n=>e.resolved?e.value:t(n),getOrThrow:()=>{if(!e.resolved)throw new Error("Conditional expression has no matching condition");return e.value}};return r},Ie=()=>Ae({resolved:false}),tt={of:()=>Ie(),match:e=>t=>{let r=t[e];if(r===void 0)throw new Error(`No case defined for value: ${String(e)}`);return typeof r=="function"?r():r},lazy:()=>{let e={resolved:false},t={when:(r,n)=>(e.resolved||r()&&(e.resolved=true,e.value=n()),t),elseWhen:(r,n)=>(e.resolved||r()&&(e.resolved=true,e.value=n()),t),else:r=>e.resolved?e.value:r()};return t}},nr=a(Ie,tt);var te=(e,t)=>t===e?true:typeof t=="function"?t(e):t&&typeof t=="object"&&"_"in t?t._(e):typeof t=="object"&&t!==null&&typeof e=="object"&&e!==null?Object.entries(t).every(([r,n])=>{let o=e[r];return te(o,n)}):false,H=e=>{let t=(o,a)=>typeof o=="function"?o(a):o,r=()=>{for(let{pattern:o,result:a}of e.patterns)if(te(e.value,o))return {matched:true,result:t(a,e.value)};return {matched:false}},n={case:(o,a)=>{if(e.resolved)return n;let s={...e,patterns:[...e.patterns,{pattern:o,result:a}]};return te(e.value,o)?H({...s,resolved:true,result:t(a,e.value)}):H(s)},caseValue:(o,a)=>{if(e.resolved)return n;if(e.value===o){let s=typeof a=="function"?a():a;return H({...e,resolved:true,result:s})}return n},caseValues:(o,a)=>{if(e.resolved)return n;if(o.includes(e.value)){let s=typeof a=="function"?a():a;return H({...e,resolved:true,result:s})}return n},when:(o,a)=>n.case(o,a),caseAny:(o,a)=>{if(e.resolved)return n;for(let s of o)if(te(e.value,s))return H({...e,resolved:true,result:t(a,e.value),patterns:[...e.patterns,{pattern:s,result:a}]});return H({...e,patterns:[...e.patterns,...o.map(s=>({pattern:s,result:a}))]})},default:o=>e.resolved?e.result:t(o,e.value),exhaustive:()=>{let o=r();if(!o.matched)throw new Error(`Non-exhaustive match. No pattern matched value: ${JSON.stringify(e.value)}`);return o.result},getOrThrow:o=>{let a=r();if(!a.matched)throw new Error(o??`No matching pattern for value: ${JSON.stringify(e.value)}`);return a.result},toOption:()=>{let o=r();return o.matched?d(o.result):d.none()}};return n},rt=e=>H({value:e,resolved:false,patterns:[]}),nt={exhaustive:e=>t=>{let r=e[t];if(r===void 0)throw new Error(`No case defined for value: ${String(t)}`);return r},partial:e=>({withDefault:t=>r=>{let n=e[r];return n!==void 0?typeof n=="function"?n(r):n:typeof t=="function"?t(r):t}}),withGuards:e=>({withDefault:t=>r=>{for(let[n,o]of e)if(n(r))return typeof o=="function"?o(r):o;return typeof t=="function"?t(r):t}}),struct:()=>{let e=[],t={case:(r,n)=>(e.push({pattern:r,handler:n}),t),build:()=>r=>{for(let{pattern:n,handler:o}of e)if(te(r,n))return o(r);throw new Error(`No matching pattern for value: ${JSON.stringify(r)}`)}};return t},builder:()=>{let e=[],t,r={case:(n,o)=>(e.push({pattern:n,result:o}),r),when:(n,o)=>(e.push({pattern:n,result:o}),r),default:n=>(t=n,{build:()=>o=>{for(let{pattern:a,result:s}of e)if(te(o,a))return typeof s=="function"?s(o):s;if(t!==void 0)return typeof t=="function"?t(o):t;throw new Error(`No matching pattern for value: ${JSON.stringify(o)}`)}})};return r}},ir=a(rt,nt);function re(e,t){return {...fe({_tag:e,impl:t}),toString(){return `${e}()`}}}var me="Throwable",x=class e extends Error{constructor(r,n){super(r,{cause:n?.cause});this._tag=me;this.name=n?.taskInfo?.name??me,Object.defineProperties(this,{_tag:{value:me,writable:false,configurable:false},data:{value:n?.data,writable:false,configurable:false},taskInfo:{value:n?.taskInfo,writable:false,configurable:false},name:{value:n?.taskInfo?.name??me,writable:false,configurable:false}}),n?.cause&&Object.defineProperty(this,"cause",{value:n.cause,writable:false,configurable:false}),n?.stack?this.stack=n.stack:Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor);}static apply(r,n,o){if(r instanceof Error){let u=new e(r.message,{data:n,cause:r.cause??void 0,stack:r.stack??void 0,taskInfo:o});for(let l of Object.keys(r))if(!(l in u)){let E=u,g=r;E[l]=g[l];}return u}if(r&&typeof r=="object"){let u=r,l=typeof u.message=="string"?u.message:typeof u.error=="string"?u.error:`Object error: ${JSON.stringify(u,Object.getOwnPropertyNames(u).filter(g=>u[g]!==void 0))}`,E=new e(l,{data:n??u,taskInfo:o});for(let g of Object.keys(u))if(!(g in E)){let P=E;P[g]=u[g];}return E}if(typeof r=="function"){let u=r.name??"anonymous function",l=r.toString().substring(0,100)+(r.toString().length>100?"...":"");return new e(`Function error: ${u}`,{data:n??{functionType:typeof r,functionName:u,functionString:l},taskInfo:o})}let a=typeof r,s=r===null?"null":r===void 0?"undefined":String(r);if(a==="number"){let u=r,l=Number.isNaN(u)?"Number error: NaN":Number.isFinite(u)?`Number error: ${u}`:`Number error: ${u>0?"Infinity":"-Infinity"}`;return new e(l,{data:n??{errorType:a,errorValue:u,originalError:r},taskInfo:o})}if(a==="bigint")return new e(`BigInt error: ${r}n`,{data:n??{errorType:a,errorValue:String(r),originalError:r},taskInfo:o});if(a==="boolean")return new e(`Boolean error: ${r}`,{data:n??{errorType:a,errorValue:r,originalError:r},taskInfo:o});if(a==="symbol"){let u=r.description??"unnamed symbol";return new e(`Symbol error: Symbol(${u})`,{data:n??{errorType:a,symbolDescription:u,originalError:r},taskInfo:o})}let i=typeof r=="string"?r:`${a.charAt(0).toUpperCase()+a.slice(1)} error: ${s}`;return new e(i,{data:n??{errorType:a,errorValue:s,originalError:r},taskInfo:o})}};var L=e=>{let t=new Promise((r,n)=>{try{e(r,n);}catch(o){n(o);}});return {_tag:"FPromise",map:r=>L((n,o)=>{t.then(a=>{try{n(r(a));}catch(s){o(s);}}).catch(o);}),flatMap:r=>L((n,o)=>{t.then(a=>{try{let s=r(a);"_tag"in s&&s._tag==="FPromise"?s.then(n,o):Promise.resolve(s).then(n,o);}catch(s){o(s);}}).catch(o);}),flatMapAsync:async r=>{let n=await t,o=r(n);return o instanceof Promise?o:new Promise((a,s)=>{o.then(a,s);})},tap:r=>L((n,o)=>{t.then(a=>{try{r(a),n(a);}catch(s){o(s);}}).catch(o);}),mapError:r=>L((n,o)=>{t.then(n).catch(a=>{try{let s={originalError:a,stack:a instanceof Error?a.stack:void 0,timestamp:Date.now()};o(r(a,s));}catch(s){o(s);}});}),tapError:r=>L((n,o)=>{t.then(n).catch(a=>{try{r(a),o(a);}catch(s){o(s);}});}),recover:r=>L(n=>{t.then(n).catch(()=>n(r));}),recoverWith:r=>L(n=>{t.then(n).catch(o=>{try{n(r(o));}catch{n(null);}});}),recoverWithF:r=>L((n,o)=>{t.then(n).catch(a=>{try{r(a).then(n,o);}catch(s){o(s);}});}),filterError:(r,n)=>L((o,a)=>{t.then(o).catch(s=>{if(r(s))try{n(s).then(o,a);}catch(i){a(i);}else a(s);});}),logError:r=>L((n,o)=>{t.then(n).catch(a=>{try{let s={originalError:a,stack:a instanceof Error?a.stack:void 0,timestamp:Date.now()};r(a,s);}catch{}finally{o(a);}});}),then:(r,n)=>t.then(r,n),toPromise:()=>t,toEither:async()=>{try{let r=await t;return c(r)}catch(r){return p(r)}},fold:(r,n)=>L((o,a)=>{t.then(s=>{try{o(n(s));}catch(i){a(i);}}).catch(s=>{try{o(r(s));}catch(i){a(i);}});})}},ot={resolve:e=>L(t=>t(e)),reject:e=>L((t,r)=>r(e)),from:e=>L((t,r)=>{e.then(t).catch(r);}),fromEither:e=>e.isRight()?L(t=>t(e.value)):L((t,r)=>r(e.value)),all:e=>L((t,r)=>{Promise.all(e.map(n=>n instanceof Promise?n:Promise.resolve(n))).then(t).catch(r);}),allSettled:e=>L(t=>{let r=[],n=0;if(e.length===0){t([]);return}e.forEach((o,a)=>{Promise.resolve(o).then(s=>{r[a]=c(s),n++,n===e.length&&t(r);}).catch(s=>{r[a]=p(s),n++,n===e.length&&t(r);});});}),race:e=>L((t,r)=>{Promise.race(e).then(t,r);}),any:e=>L((t,r)=>{if(typeof Promise.any=="function")Promise.any(e).then(t,r);else {let n=0,o=[];if(e.length===0){r(new AggregateError([],"All promises were rejected"));return}e.forEach((a,s)=>{Promise.resolve(a).then(t).catch(i=>{o[s]=i,n++,n===e.length&&r(new AggregateError(o,"All promises were rejected"));});});}}),retryWithBackoff:(e,t)=>{let{maxRetries:r,baseDelay:n=100,shouldRetry:o=()=>true}=t;return L((a,s)=>{let i=0,u=()=>{e().toPromise().then(a).catch(l=>{if(i++,i<=r&&o(l,i)){let E=n*Math.pow(2,i-1);setTimeout(u,E);}else s(l);});};u();})}},Re=a(L,ot);function A(e){let t=e;return {get(){return t},set(n){t=n;},update(n){t=n(t);},getAndSet(n){let o=t;return t=n,o},updateAndGet(n){return t=n(t),t},getAndUpdate(n){let o=t;return t=n(t),o},compareAndSet(n,o){return t===n?(t=o,true):false},modify(n){let[o,a]=n(t);return t=o,a}}}A.of=A;var ne=(e=0)=>{let t=A(e),r=e;return {get:()=>t.get(),set:n=>t.set(n),increment:()=>t.updateAndGet(n=>n+1),decrement:()=>t.updateAndGet(n=>n-1),reset:()=>t.set(r),compareAndSet:(n,o)=>t.compareAndSet(n,o)}};var ye=()=>{let e=A([]);return {add:t=>e.update(r=>[...r,t]),addAll:t=>e.update(r=>[...r,...t]),build:()=>e.get(),clear:()=>e.set([]),size:()=>e.get().length}};function at(e){return e instanceof Error&&typeof e=="object"&&true&&e._tag==="Throwable"}var Me=(e,t,r)=>{let n=r?.name??"TaskException",o=r?.description??"Unspecified TaskException",a={name:n,description:o},s=x.apply(e,t,a);return {...re("TaskException",p(s)),_task:a}},Ve=(e,t)=>{let r=t?.name??"TaskResult",n=t?.description??"Unspecified TaskResult";return {...re("TaskResult",c(e)),_task:{name:r,description:n}}},Le=()=>{let e=new AbortController,t=ye();return {token:{get isCancelled(){return e.signal.aborted},get signal(){return e.signal},onCancel(n){e.signal.aborted?n():t.add(n);}},cancel(){e.signal.aborted||(e.abort(),t.build().forEach(n=>{try{n();}catch(o){console.error("Error in cancellation callback:",o);}}));}}},st=e=>{let t=e?.name??"Task",r=e?.description??"",n={Async:(o,a=u=>u,s=()=>{},i)=>Re((u,l)=>{(async()=>{let E=A(false),g=A(null),P=A(()=>{});if(i){if(i.isCancelled){try{await s();}catch(R){l(x.apply(R,void 0,{name:t,description:r}));return}l(x.apply(new Error("Task was cancelled before execution started"),void 0,{name:t,description:r}));return}let S=()=>{E.set(true),g.set(new Error("Task was cancelled during execution"));};i.onCancel(S),P.set(()=>{});}try{let S=await o();if(E.get()){try{await s();}catch(R){l(x.apply(R,void 0,{name:t,description:r}));return}g.get()?l(x.apply(g.get(),void 0,{name:t,description:r})):l(x.apply(new Error("Task was cancelled during execution"),void 0,{name:t,description:r}));return}try{await s();}catch(R){l(x.apply(R,void 0,{name:t,description:r}));return}u(S);}catch(S){if(E.get()){try{await s();}catch(R){l(x.apply(R,void 0,{name:t,description:r}));return}g.get()?l(x.apply(g.get(),void 0,{name:t,description:r})):l(x.apply(new Error("Task was cancelled during execution"),void 0,{name:t,description:r}));return}try{await s();}catch(R){l(x.apply(R,void 0,{name:t,description:r}));return}try{if(S instanceof Error&&at(S)){let R=new Error(`${t}: ${S.message}`),Z=x.apply(R,void 0,{name:t,description:r});Object.defineProperty(Z,"cause",{value:S,writable:!1,configurable:!1}),Promise.resolve().then(()=>{try{a(S);}catch(q){console.error("Error in error handler:",q);}}),l(Z);}else {let R=await a(S);l(x.apply(R,void 0,{name:t,description:r}));}}catch(R){l(x.apply(R,void 0,{name:t,description:r}));}}finally{P.get()();}})().catch(l);}),Sync:(o,a=i=>i,s=()=>{})=>{try{return Ve(o(),{name:t,description:r})}catch(i){return Me(a(i),void 0,{name:t,description:r})}finally{s();}},AsyncWithProgress:(o,a,s=l=>l,i=()=>{},u)=>{let l=E=>{let g=Math.max(0,Math.min(100,E));g<=100&&a(g);};return n.Async(()=>o(l),s,i,u)}};return {...re("Task",n),_type:"Task"}},Ce={success:(e,t)=>Ve(e,t),fail:(e,t,r)=>Me(e,t,r),getErrorChain:e=>{if(!e)return [];let t=ye();t.add(e);let r=A(e);for(;r.get()&&r.get().cause;){let{cause:n}=r.get();if(n)t.add(n),r.set(n);else break;if(t.size()>100)break}return t.build()},formatErrorChain:(e,t)=>{let r=Ce.getErrorChain(e),n=t?.separator??`
9
+ `;return r.map((o,a)=>{if(!o)return `${a>0?"\u21B3 ":""}Unknown error`;let{taskInfo:s}=o,i=t?.includeTasks&&s?.name?`[${s.name}] `:"",u=o.message??"No message",l=A(`${a>0?"\u21B3 ":""}${i}${u}`);return t?.includeStackTrace&&o.stack&&l.set(`${l.get()}
10
+ ${o.stack.split(`
11
+ `).slice(1).join(`
12
+ `)}`),l.get()}).join(n)},fromPromise:(e,t)=>(...r)=>z(t??{name:"PromiseTask",description:"Task from Promise"}).Async(()=>e(...r),o=>o),toPromise:e=>new Promise((t,r)=>{e.isRight()?t(e.value):r(e.value);}),race:(e,t,r)=>{let n=r?.name??"TaskRace",o=r?.description??"Race between multiple tasks";return z({name:n,description:o}).Async(async()=>{let s=ye();e.forEach(u=>s.add(u));let i=A(void 0);if(typeof t=="number"&&t>0){let u=Re((l,E)=>{i.set(setTimeout(()=>{E(new Error(`Task race timed out after ${t}ms`));},t));});s.add(u);}try{return await new Promise((u,l)=>{s.build().forEach(E=>{E.then(g=>u(g),g=>l(g));});})}finally{i.get()&&clearTimeout(i.get());}},s=>s)},fromNodeCallback:(e,t)=>{let r=t?.name??"NodeCallbackTask",n=t?.description??"Task from Node.js callback function",o={name:r,description:n};return (...a)=>z(o).Async(()=>new Promise((s,i)=>{try{e(...a,(u,l)=>{u?i(u):s(l);});}catch(u){i(u);}}),s=>s)},createCancellationTokenSource:Le,cancellable:(e,t)=>{let r=Le();return {task:z(t).Async(()=>e(r.token),o=>o,()=>{},r.token),cancel:()=>r.cancel()}},withProgress:(e,t=()=>{},r)=>{let n=Le(),o=A(0),a=i=>{o.set(Math.max(0,Math.min(100,i))),t(o.get());};return {task:z(r).Async(()=>e(a,n.token),i=>i,()=>{},n.token),cancel:()=>n.cancel(),currentProgress:()=>o.get()}}},z=a(st,Ce);var ze={includeTasks:true,includeStackTrace:false,separator:`
13
+ `,includeData:false,maxStackFrames:3,title:"Error",colors:false};function Fe(e){let t=new WeakSet;return JSON.stringify(e,(r,n)=>{if(typeof n=="bigint")return `${n.toString()}n`;if(typeof n=="object"&&n!==null){if(t.has(n))return "[Circular Reference]";t.add(n);}return r==="stack"&&typeof n=="string"?ge(n):n},2)}function ge(e){if(e===void 0||e==="")return "";let t=e.split(`
14
+ `),r=t[0],n=t.slice(1).map(o=>o.trim());return [r,...n].join(`
15
+ `)}function vr(e,t){let r={...ze,...t},n=e instanceof Error?e:x.apply(e),o=z?.getErrorChain?z.getErrorChain(n):[n],a=r.colors?`\x1B[31m${r.title}:\x1B[0m ${n.message}`:`${r.title}: ${n.message}`,s=o.map((u,l)=>{let E=" ".repeat(l),g=l>0?"\u21B3 ":"",{taskInfo:P}=u,S=r.includeTasks&&P?.name?r.colors?`\x1B[36m[${P.name}]\x1B[0m `:`[${P.name}] `:"",R=`${E}${g}${S}${u.message}`;if(r.includeStackTrace&&u.stack){let q=ge(u.stack).split(`
16
+ `).slice(1),X=r.maxStackFrames??ze.maxStackFrames??3,ce=q.slice(0,X).map(Te=>`${E} ${r.colors?"\x1B[90m":""}${Te}${r.colors?"\x1B[0m":""}`).join(`
17
+ `);R+=`
18
+ ${ce}`,q.length>X&&(R+=`
19
+ ${E} ${r.colors?"\x1B[90m":""}...${q.length-X} more stack frames${r.colors?"\x1B[0m":""}`);}return R}).join(r.separator),i=`${a}
20
+
21
+ ${s}`;if(r.includeData){let{data:u}=n;if(u){let l=r.colors?`
22
+
23
+ \x1B[33mContext:\x1B[0m
24
+ ${Fe(u)}`:`
25
+
26
+ Context:
27
+ ${Fe(u)}`;i+=l;}}return i}function Sr(){return function(t){if(!t)return t;let r=t instanceof Error?t:new Error(String(t)),n={message:r.message,name:r.name||"Error",stack:r.stack?ge(r.stack):void 0};if(r.taskInfo&&(n.taskInfo=r.taskInfo),r.data&&(n.data=r.data),typeof z?.getErrorChain=="function")try{let o=z.getErrorChain(r);o.length>1&&(n.errorChain=z.formatErrorChain(r,{includeTasks:!0}),n.structuredErrorChain=o.map(a=>({message:a.message,name:a.name,taskInfo:a.taskInfo,stack:a.stack?ge(a.stack):void 0})));}catch{}return Object.getOwnPropertyNames(r).forEach(o=>{if(!n[o]){let a=r[o];n[o]=a;}}),n}}var Or=e=>{let t=new Error(e);return t.name="ParseError",t};var F=(e,t,r,n)=>{let o=x.apply(t,r,{name:e,description:t});return Object.assign(o,{code:e,message:t,status:it(e),context:r,timestamp:new Date().toISOString(),traceId:n?.traceId})},it=e=>({VALIDATION_FAILED:400,BAD_REQUEST:400,AUTH_REQUIRED:401,PERMISSION_DENIED:403,NOT_FOUND:404,TIMEOUT:408,CONFLICT:409,RATE_LIMITED:429,INTERNAL_ERROR:500,NETWORK_ERROR:503})[e],ut={validation:(e,t,r)=>F("VALIDATION_FAILED",`Validation failed: ${e} ${r}`,{field:e,value:t,rule:r}),network:(e,t,r)=>F("NETWORK_ERROR",`Network error: ${t} ${e}${r?` (${r})`:""}`,{url:e,method:t,statusCode:r}),auth:(e,t)=>F("AUTH_REQUIRED",`Authentication required: ${e}${t?` (role: ${t})`:""}`,{resource:e,requiredRole:t}),notFound:(e,t)=>F("NOT_FOUND",`Not found: ${e} with id ${t}`,{resource:e,id:t}),permission:(e,t,r)=>F("PERMISSION_DENIED",`Permission denied: cannot ${e} ${t}`,{action:e,resource:t,userId:r}),rateLimit:(e,t,r)=>F("RATE_LIMITED",`Rate limit exceeded: ${e} requests per ${t}`,{limit:e,window:t,retryAfter:r}),internal:e=>F("INTERNAL_ERROR",`Internal server error: ${e}`,{errorId:e,timestamp:new Date().toISOString()}),badRequest:(e,t)=>F("BAD_REQUEST",`Bad request: ${e}`,{reason:e,expected:t}),conflict:(e,t)=>F("CONFLICT",`Conflict: ${e} already exists with value ${t}`,{resource:e,conflictingValue:t}),timeout:(e,t)=>F("TIMEOUT",`Request timeout: ${t} exceeded ${e}ms`,{duration:e,operation:t}),isTypedError:e=>typeof e=="object"&&e!==null&&"code"in e&&"message"in e&&"status"in e&&"context"in e&&"_tag"in e&&e._tag==="Throwable",hasCode:(e,t)=>e.code===t},b=Object.assign(F,ut);var w=e=>{let t={_tag:"LazyList",[Symbol.iterator]:()=>e[Symbol.iterator](),map:r=>w((function*(){for(let n of e)yield r(n);})()),flatMap:r=>w((function*(){for(let n of e)yield*r(n);})()),filter:r=>w((function*(){for(let n of e)r(n)&&(yield n);})()),take:r=>w((function*(){let n=ne(0);for(let o of e){if(n.get()>=r)break;yield o,n.increment();}})()),drop:r=>w((function*(){let n=ne(0);for(let o of e)n.get()>=r&&(yield o),n.increment();})()),takeWhile:r=>w((function*(){for(let n of e){if(!r(n))break;yield n;}})()),dropWhile:r=>w((function*(){let n=A(true);for(let o of e)n.get()&&r(o)||(n.set(false),yield o);})()),concat:r=>w((function*(){yield*e,yield*r;})()),zip:r=>w((function*(){let n=e[Symbol.iterator](),o=r[Symbol.iterator]();for(;;){let a=n.next(),s=o.next();if(a.done||s.done)break;yield [a.value,s.value];}})()),toList:()=>y(Array.from(e)),toArray:()=>Array.from(e),forEach:r=>{for(let n of e)r(n);},reduce:(r,n)=>{let o=A(n);for(let a of e)o.set(r(o.get(),a));return o.get()},find:r=>{for(let n of e)if(r(n))return d(n);return d.none()},some:r=>{for(let n of e)if(r(n))return true;return false},every:r=>{for(let n of e)if(!r(n))return false;return true},count:()=>{let r=ne(0);for(let n of e)r.increment();return r.get()},first:()=>{let n=e[Symbol.iterator]().next();return n.done?d.none():d(n.value)},last:()=>{let r=A(void 0),n=A(false);for(let o of e)r.set(o),n.set(true);return n.get()?d(r.get()):d.none()},fold:(r,n)=>{let a=e[Symbol.iterator]().next();return a.done?r():n(a.value)},foldLeft:r=>n=>{let o=A(r);for(let a of e)o.set(n(o.get(),a));return o.get()},foldRight:r=>n=>Array.from(e).reduceRight((a,s)=>n(s,a),r),pipe:r=>r(t),serialize:()=>{let r=Array.from(e);return {toJSON:()=>JSON.stringify({_tag:"LazyList",value:r}),toYAML:()=>`_tag: LazyList
28
+ value: ${le(r)}`,toBinary:()=>Buffer.from(JSON.stringify({_tag:"LazyList",value:r})).toString("base64")}},toString:()=>{let n=[],o=ne(0),a=A(false);for(let i of e)if(o.get()<10)n.push(i),o.increment();else {a.set(true);break}let s=n.map(i=>String(i)).join(", ");return a.get()?`LazyList(${s}, ...)`:`LazyList(${s})`}};return t},pt=e=>w(e),ct={empty:()=>w([]),of:e=>w([e]),from:(...e)=>w(e),iterate:(e,t)=>w((function*(){let r=A(e);for(;;)yield r.get(),r.set(t(r.get()));})()),generate:e=>w((function*(){for(;;)yield e();})()),range:(e,t,r=1)=>w((function*(){if(r===0)throw new Error("Step cannot be zero");let n=A(e);if(r>0)for(;n.get()<t;)yield n.get(),n.set(n.get()+r);else for(;n.get()>t;)yield n.get(),n.set(n.get()+r);})()),repeat:(e,t)=>w((function*(){if(t===void 0)for(;;)yield e;else {let r=ne(0);for(;r.get()<t;)yield e,r.increment();}})()),cycle:e=>w((function*(){let t=Array.from(e);if(t.length!==0)for(;;)yield*t;})())},Kr=a(pt,ct);var _={rule:e=>t=>{if(e==="email")return typeof t!="string"||!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(t)?p(b.validation("value",t,"must be a valid email")):c(t);if(e==="url")try{return new URL(String(t)),c(t)}catch{return p(b.validation("value",t,"must be a valid URL"))}if(e==="uuid")return typeof t!="string"||!/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(t)?p(b.validation("value",t,"must be a valid UUID")):c(t);if(e==="required")return t==null||t===""?p(b.validation("value",t,"is required")):c(t);if(e==="numeric")return typeof t!="number"&&!/^\d+$/.test(String(t))?p(b.validation("value",t,"must be numeric")):c(t);if(e==="alpha")return typeof t!="string"||!/^[a-zA-Z]+$/.test(t)?p(b.validation("value",t,"must contain only letters")):c(t);if(e==="alphanumeric")return typeof t!="string"||!/^[a-zA-Z0-9]+$/.test(t)?p(b.validation("value",t,"must be alphanumeric")):c(t);if(e.startsWith("min:")){let r=Number(e.split(":")[1]),n=Number(t);return isNaN(n)||n<r?p(b.validation("value",t,`must be at least ${r}`)):c(t)}if(e.startsWith("max:")){let r=Number(e.split(":")[1]),n=Number(t);return isNaN(n)||n>r?p(b.validation("value",t,`must be at most ${r}`)):c(t)}if(e.startsWith("minLength:")){let r=Number(e.split(":")[1]);return String(t).length<r?p(b.validation("value",t,`must be at least ${r} characters`)):c(t)}if(e.startsWith("maxLength:")){let r=Number(e.split(":")[1]);return String(t).length>r?p(b.validation("value",t,`must be at most ${r} characters`)):c(t)}if(e.startsWith("pattern:")){let r=e.substring(8);return new RegExp(r).test(String(t))?c(t):p(b.validation("value",t,`must match pattern ${r}`))}if(e.startsWith("in:")){let r=e.substring(3).split(",");return r.includes(String(t))?c(t):p(b.validation("value",t,`must be one of: ${r.join(", ")}`))}if(e.startsWith("notIn:")){let r=e.substring(6).split(",");return r.includes(String(t))?p(b.validation("value",t,`must not be one of: ${r.join(", ")}`)):c(t)}if(e==="date"){let r=new Date(String(t));return isNaN(r.getTime())?p(b.validation("value",t,"must be a valid date")):c(t)}if(e==="future"){let r=new Date(String(t));return isNaN(r.getTime())||r<=new Date?p(b.validation("value",t,"must be a future date")):c(t)}if(e==="past"){let r=new Date(String(t));return isNaN(r.getTime())||r>=new Date?p(b.validation("value",t,"must be a past date")):c(t)}return c(t)},combine:(...e)=>t=>{for(let r of e){let n=r(t);if(n.isLeft())return n}return c(t)},custom:(e,t)=>r=>e(r)?c(r):p(b.validation("value",r,t)),form:(e,t)=>{let r=[],n={};for(let[o,a]of Object.entries(e)){let s=t[o],i=a(s);if(i.isLeft()){let u=i.fold(E=>E,()=>{throw new Error("Should not be left")}),l=b.validation(o,s,u.context.rule);r.push(l);}else n[o]=i.get();}return r.length>0?p(y(r)):c(n)}},Tt={..._,validators:{email:_.rule("email"),url:_.rule("url"),uuid:_.rule("uuid"),required:_.rule("required"),numeric:_.rule("numeric"),positiveNumber:_.combine(_.rule("numeric"),_.rule("min:0")),nonEmptyString:_.combine(_.rule("required"),_.custom(e=>typeof e=="string"&&e.trim().length>0,"must not be empty"))}},jr=Object.assign(_.rule,Tt);function dt(e){return e!=null&&typeof e=="object"&&"getOrElse"in e&&typeof e.getOrElse=="function"&&"getOrThrow"in e&&typeof e.getOrThrow=="function"&&"get"in e&&typeof e.get=="function"&&"orElse"in e&&typeof e.orElse=="function"&&"orNull"in e&&typeof e.orNull=="function"&&"orUndefined"in e&&typeof e.orUndefined=="function"}var en={toOption:e=>e.fold(()=>k(),t=>U(t)),toList:e=>e.fold(()=>y([]),t=>y([t])),toEither:(e,t)=>e.fold(()=>p(t),r=>c(r)),isEmpty:e=>e.fold(()=>true,()=>false),size:e=>e.fold(()=>0,()=>1)};var Y=e=>e!==null&&typeof e=="object"&&(e._tag==="Some"||e._tag==="None"),$=e=>e!==null&&typeof e=="object"&&e._tag==="List",oe=e=>e!==null&&typeof e=="object"&&(e._tag==="Left"||e._tag==="Right"),ae=e=>e!==null&&typeof e=="object"&&(e._tag==="Success"||e._tag==="Failure"),K=()=>{let e=(s,i)=>{if(Y(s))return s.map(u=>i(u));if($(s))return s.map(u=>i(u));if(oe(s))return s.map(u=>i(u));if(ae(s))return s.map(u=>i(u));throw new Error(`Unsupported functor type: ${JSON.stringify(s)}`)},t=s=>{if(Y(s))return s.get();if($(s)){let i=s.toArray();if(i.length>0&&$(i[0])){let u=[];for(let l of i)$(l)&&u.push(...l.toArray());return y(u)}return s.flatten()}if(oe(s))return s.isRight()?s.fold(()=>null,i=>i):s;if(ae(s))return s.isSuccess()?s.get():s;throw new Error(`Unsupported functor type for flatten: ${JSON.stringify(s)}`)},r=(s,i)=>{if(Y(s))return s.flatMap(u=>i(u));if($(s))return s.flatMap(u=>i(u));if(oe(s))return s.flatMap(u=>i(u));if(ae(s))return s.flatMap(u=>i(u));throw new Error(`Unsupported functor type for flatMap: ${JSON.stringify(s)}`)},n=(s,i)=>{if(Y(s)&&Y(i))return s.flatMap(u=>i.map(l=>u(l)));if($(s)&&$(i))return s.flatMap(u=>i.map(l=>u(l)));if(oe(s)&&oe(i))return s.flatMap(u=>i.map(l=>u(l)));if(ae(s)&&ae(i))return s.flatMap(u=>i.map(l=>u(l)));throw new Error(`Unsupported functor type for ap: ${JSON.stringify(s)}`)},o=s=>{if(Y(s)){let i=s;if(i.isEmpty)return y([d.none()]);let u=i.get();if($(u))return u.map(l=>d(l));throw new Error("Unsupported inner container type for sequence")}if($(s)){let u=s.toArray();if(u.length===0)return d.none();let l=u[0];if(Y(l)){for(let g of u)if(g.isEmpty)return d.none();let E=u.map(g=>g.get());return d(y(E))}throw new Error("Unsupported inner container type for sequence")}throw new Error(`Unsupported outer container type for sequence: ${JSON.stringify(s)}`)};return {...re("HKT",{map:e,flatten:t,flatMap:r,ap:n,sequence:o,traverse:(s,i)=>o(e(s,u=>i(u)))}),_type:"HKT"}},se=K();K.map=(e,t)=>se.map(e,t);K.flatten=e=>se.flatten(e);K.flatMap=(e,t)=>se.flatMap(e,t);K.ap=(e,t)=>se.ap(e,t);K.sequence=e=>se.sequence(e);K.traverse=(e,t)=>se.traverse(e,t);K.isOption=Y;K.isList=$;K.isEither=oe;K.isTry=ae;function sn(e){return {id:e,isSame:r=>r.id===e}}var Ee=e=>({_tag:"Success",error:void 0,isSuccess(){return true},isFailure(){return false},get:()=>e,getOrElse:t=>e,getOrThrow:t=>e,orElse:t=>Ee(e),orNull:()=>e,orUndefined:()=>e,orThrow:t=>e,toEither:()=>c(e),map:t=>be(()=>t(e)),ap:t=>t.map(r=>r(e)),flatMap:t=>t(e),flatMapAsync:async t=>t(e),fold:(t,r)=>r(e),match:t=>t.Success(e),foldLeft:t=>r=>r(t,e),foldRight:t=>r=>r(e,t),toString:()=>`Success(${le(e)})`,toPromise:()=>Promise.resolve(e),toValue:()=>({_tag:"Success",value:e}),pipe:t=>t(e),serialize:()=>({toJSON:()=>JSON.stringify({_tag:"Success",value:e}),toYAML:()=>`_tag: Success
29
+ value: ${le(e)}`,toBinary:()=>Buffer.from(JSON.stringify({_tag:"Success",value:e})).toString("base64")}),get size(){return 1},get isEmpty(){return false},contains:t=>e===t,reduce:t=>e,reduceRight:t=>e,count:t=>t(e)?1:0,find:t=>t(e)?d(e):d(void 0),exists:t=>t(e),forEach:t=>t(e)}),D=e=>({_tag:"Failure",error:e,isSuccess(){return false},isFailure(){return true},get:()=>{throw e},getOrElse:t=>t,getOrThrow:t=>{throw t??e},orElse:t=>t,orNull:()=>null,orUndefined:()=>{},orThrow:t=>{throw t},toEither:()=>p(e),map:t=>D(e),ap:t=>D(e),flatMap:t=>D(e),flatMapAsync:t=>Promise.resolve(D(e)),fold:(t,r)=>t(e),match:t=>t.Failure(e),foldLeft:t=>r=>t,foldRight:t=>r=>t,toString:()=>`Failure(${le(e)}))`,toPromise:()=>Promise.reject(e),toValue:()=>({_tag:"Failure",value:e}),pipe:t=>{throw e},serialize:()=>({toJSON:()=>JSON.stringify({_tag:"Failure",error:e.message,stack:e.stack}),toYAML:()=>`_tag: Failure
30
+ error: ${e.message}
31
+ stack: ${e.stack}`,toBinary:()=>Buffer.from(JSON.stringify({_tag:"Failure",error:e.message,stack:e.stack})).toString("base64")}),get size(){return 0},get isEmpty(){return true},contains:t=>false,reduce:t=>{throw new Error("Cannot reduce a Failure")},reduceRight:t=>{throw new Error("Cannot reduceRight a Failure")},count:t=>0,find:t=>d(null),exists:t=>false,forEach:t=>{}}),ft=e=>{try{return Ee(e())}catch(t){return D(t instanceof Error?t:new Error(String(t)))}},Ke={fromJSON:e=>{let t=JSON.parse(e);if(t._tag==="Success")return Ee(t.value);{let r=new Error(t.error);return t.stack&&(r.stack=t.stack),D(r)}},fromYAML:e=>{let t=e.split(`
32
+ `),r=t[0]?.split(": ")[1];if(!r)return D(new Error("Invalid YAML format for Try"));if(r==="Success"){let n=t[1]?.split(": ")[1];if(!n)return D(new Error("Invalid YAML format for Try Success"));let o=JSON.parse(n);return Ee(o)}else {let n=t[1]?.split(": ")[1];if(!n)return D(new Error("Invalid YAML format for Try Failure"));let o=t[2]?.split(": "),a=o&&o.length>1?o.slice(1).join(": "):void 0,s=new Error(n);return a&&(s.stack=a),D(s)}},fromBinary:e=>{let t=Buffer.from(e,"base64").toString();return Ke.fromJSON(t)}},be=a(ft,Ke);var Q=e=>{let t=false,r,n,o=false,a=()=>{if(!t)try{r=e(),t=!0;}catch(i){throw n=i,o=true,t=true,i}if(o)throw n;return r};return {_tag:"Lazy",get isEvaluated(){return t},get:a,getOrElse:i=>{try{return a()}catch{return i}},getOrNull:()=>{try{return a()}catch{return null}},orNull:()=>{try{return a()}catch{return null}},getOrThrow:i=>{try{return a()}catch(u){throw i??u}},orElse:i=>V(()=>{try{return a()}catch{return i.get()}}),orUndefined:()=>{try{return a()}catch{return}},map:i=>V(()=>i(a())),ap:i=>V(()=>i.get()(a())),mapAsync:async i=>{let u=a(),l=await i(u);return V(()=>l)},flatMap:i=>V(()=>i(a()).get()),flatMapAsync:async i=>{let u=a(),l=await i(u);return V(()=>l.get())},filter:i=>V(()=>{let u=a();return i(u)?U(u):k}),recover:i=>V(()=>{try{return a()}catch(u){return i(u)}}),recoverWith:i=>V(()=>{try{return a()}catch(u){return i(u).get()}}),toOption:()=>{try{return U(a())}catch{return k}},toEither:()=>{try{return c(a())}catch(i){return p(i)}},toEitherWith:i=>{try{return c(a())}catch(u){return p(i(u))}},toTry:()=>be(()=>a()),tap:i=>V(()=>{let u=a();return i(u),u}),tapError:i=>V(()=>{try{return a()}catch(u){throw i(u),u}}),fold:i=>i(a()),foldWith:(i,u)=>{try{return u(a())}catch(l){return i(l)}},foldLeft:i=>u=>u(i,a()),foldRight:i=>u=>u(a(),i),match:i=>i.Lazy(a()),toString:()=>t&&!o?`Lazy(${le(r)})`:t&&o?`Lazy(<error: ${n instanceof Error?n.message:String(n)}>)`:"Lazy(<not evaluated>)",toValue:()=>t&&!o?{_tag:"Lazy",evaluated:true,value:r}:{_tag:"Lazy",evaluated:false},get size(){try{return a(),1}catch{return 0}},get isEmpty(){try{return a(),!1}catch{return true}},contains:i=>{try{return a()===i}catch{return false}},reduce:i=>a(),reduceRight:i=>a(),count:i=>{try{return i(a())?1:0}catch{return 0}},find:i=>{try{let u=a();return i(u)?U(u):k}catch{return k}},exists:i=>{try{return i(a())}catch{return false}},forEach:i=>{try{i(a());}catch{}},pipe:i=>i(a()),serialize:()=>({toJSON:()=>JSON.stringify(t&&!o?{_tag:"Lazy",evaluated:true,value:r}:{_tag:"Lazy",evaluated:false}),toYAML:()=>t&&!o?`_tag: Lazy
33
+ evaluated: true
34
+ value: ${le(r)}`:`_tag: Lazy
35
+ evaluated: false`,toBinary:()=>Buffer.from(JSON.stringify(t&&!o?{_tag:"Lazy",evaluated:true,value:r}:{_tag:"Lazy",evaluated:false})).toString("base64")}),typeable:"Lazy"}},mt={of:e=>Q(e),fromValue:e=>Q(()=>e),fromOption:(e,t)=>Q(()=>e._tag==="Some"?e.value:t()),fromTry:e=>Q(()=>e.get()),fromEither:e=>Q(()=>e.fold(t=>{throw t},t=>t)),fromPromise:e=>Q(()=>{throw new Error("Promise not yet resolved. Use await on the promise before creating Lazy.")}),fail:e=>Q(()=>{throw e})},V=a(Q,mt);var pe=Map;var j=e=>{let r={values:new pe(e)},n=()=>Array.from(r.values.entries()).map(([T,m])=>b$1([T,m])),o=T=>j(new pe(r.values).set(T.toArray()[0],T.toArray()[1]).entries()),a=T=>{let m=new pe(r.values);return m.delete(T)?j(m.entries()):j(r.values.entries())},s=T=>{let m=T.toArray();return r.values.get(m[0])===m[1]},i=()=>r.values.size,u=T=>j(Array.from(r.values.entries()).map(([m,I])=>[m,T(I)])),l=T=>{let m=j(r.values.entries()).toList();return j(m.flatMap(T).toArray())},E=T=>{let m=[];for(let[I,ee]of r.values.entries()){let ue=T.get(I);ue._tag==="Some"&&ue.value&&m.push([I,ue.value(ee)]);}return j(m)},g=async T=>{let m=new pe;for(let[I,ee]of r.values.entries()){let ue=await T(ee);for(let qe of ue.toList()){let[Ye,Qe]=qe.toArray();m.set(Ye,Qe);}}return j(m.entries())},P=T=>y(n()).reduce(T),S=T=>y(n()).reduceRight(T),R=T=>m=>y(n()).foldLeft(T)(m),Z=T=>m=>y(n()).foldRight(T)(m),q=T=>d(r.values.get(T)),X=(T,m)=>d(r.values.get(T)).getOrElse(m),ie=()=>r.values.size===0,ce=(T,m)=>d(r.values.get(T)).orElse(m),Te=(T,m)=>{if(ie())return T();let I=n();if(I.length===0)return T();let ee=I[0];return ee===void 0?T():m(ee)},Ue=()=>y(n()),f=()=>G(n()),B=()=>`Map(${n().toString()})`,O=T=>ie()?T.Empty():T.NonEmpty(n());return {_tag:"Map",[Symbol.iterator]:()=>r.values.entries(),add:o,remove:a,contains:s,get size(){return i()},map:u,ap:E,flatMap:l,flatMapAsync:g,reduce:P,reduceRight:S,foldLeft:R,foldRight:Z,fold:Te,match:O,get:q,getOrElse:X,get isEmpty(){return ie()},orElse:ce,toList:Ue,toSet:f,toString:B,toValue:()=>({_tag:"Map",value:Array.from(r.values.entries())}),pipe:T=>T(Array.from(r.values.entries())),serialize:()=>({toJSON:()=>JSON.stringify({_tag:"Map",value:Array.from(r.values.entries())}),toYAML:()=>`_tag: Map
36
+ value: ${JSON.stringify(Array.from(r.values.entries()))}`,toBinary:()=>Buffer.from(JSON.stringify({_tag:"Map",value:Array.from(r.values.entries())})).toString("base64")})}},yt=e=>j(e),De={fromJSON:e=>{let t=JSON.parse(e);return ke(t.value)},fromYAML:e=>{let r=e.split(`
37
+ `)[1]?.split(": ")[1];if(!r)return ke([]);let n=JSON.parse(r);return ke(n)},fromBinary:e=>{let t=Buffer.from(e,"base64").toString();return De.fromJSON(t)}},ke=a(yt,De);var gt={default:e=>t=>e(t),when:(e,t)=>r=>e(r)?t(r):void 0};var C=(e=[])=>{let t="Stack",r=[...e],n=()=>r.length,o=()=>r.length===0;return {_tag:t,get size(){return n()},get isEmpty(){return o()},contains:f=>r.includes(f),reduce:f=>{if(r.length===0)throw new Error("Cannot reduce an empty stack");return r.reduce(f)},reduceRight:f=>{if(r.length===0)throw new Error("Cannot reduce an empty stack");return r.reduceRight(f)},push:f=>C([...r,f]),pop:()=>{if(o())return [C([]),d(null)];let f=[...r],B=f.pop();return [C(f),d(B)]},peek:()=>o()?d(null):d(r[r.length-1]),map:f=>C(r.map(f)),flatMap:f=>o()?C([]):r.reduce((B,O)=>f(O).toArray().reduce((m,I)=>m.push(I),B),C([])),ap:f=>{let B=[];return r.forEach(O=>{f.toArray().forEach(T=>{B.push(T(O));});}),C(B)},flatMapAsync:async f=>o()?C([]):(await Promise.all(r.map(async O=>await f(O)))).reduce((O,T)=>T.toArray().reduce((m,I)=>m.push(I),O),C([])),toList:()=>y(r),toArray:()=>[...r],toString:()=>`Stack(${r.join(", ")})`,fold:(f,B)=>{if(o())return f();let O=r[r.length-1];return O!==void 0?B(O):f()},foldLeft:f=>B=>r.reduce(B,f),foldRight:f=>B=>r.reduceRight((O,T)=>B(T,O),f),match:f=>o()?f.Empty():f.NonEmpty([...r]),toValue:()=>({_tag:"Stack",value:r}),pipe:f=>f([...r]),serialize:()=>({toJSON:()=>JSON.stringify({_tag:"Stack",value:r}),toYAML:()=>`_tag: Stack
38
+ value: ${JSON.stringify(r)}`,toBinary:()=>Buffer.from(JSON.stringify({_tag:"Stack",value:r})).toString("base64")})}},Et=(e=[])=>C(e),Je={empty:()=>C([]),of:e=>C([e]),fromJSON:e=>{let t=JSON.parse(e);return we(t.value)},fromYAML:e=>{let r=e.split(`
39
+ `)[1]?.split(": ")[1];if(!r)return we([]);let n=JSON.parse(r);return we(n)},fromBinary:e=>{let t=Buffer.from(e,"base64").toString();return Je.fromJSON(t)}},we=a(Et,Je);function Fn(e){let t=fe({_tag:e._tag,impl:e.impl});return {...t,toValue:()=>({_tag:t._tag,value:e.value})}}var U=e=>({_tag:"Some",value:e,isEmpty:false,isSome(){return true},isNone(){return false},get:()=>e,getOrElse:()=>e,getOrThrow:()=>e,orElse:t=>U(e),orNull:()=>e,orUndefined:()=>e,map:t=>U(t(e)),ap:t=>t._tag==="Some"&&t.value?U(t.value(e)):J,filter(t){return t(e)?U(e):J},count:t=>t(e)?1:0,find:t=>t(e)?U(e):J,exists:t=>t(e),forEach:t=>t(e),fold:(t,r)=>r(e),match:t=>t.Some(e),flatMap:t=>t(e),flatMapAsync:async t=>await t(e),reduce:t=>t(void 0,e),reduceRight:t=>t(void 0,e),foldLeft:t=>r=>r(t,e),foldRight:t=>r=>r(e,t),toList:()=>y([e]),contains:t=>t===e,size:1,toEither:t=>c(e),toPromise:()=>Promise.resolve(e),toString:()=>`Some(${le(e)})`,toValue:()=>({_tag:"Some",value:e}),pipe:t=>t(e),serialize:()=>({toJSON:()=>JSON.stringify({_tag:"Some",value:e}),toYAML:()=>`_tag: Some
40
+ value: ${le(e)}`,toBinary:()=>Buffer.from(JSON.stringify({_tag:"Some",value:e})).toString("base64")})}),J={_tag:"None",value:void 0,isEmpty:true,isSome(){return false},isNone(){return true},get:()=>{throw new Error("Cannot call get() on None")},getOrElse:e=>e,getOrThrow(e){throw e},orElse:e=>e,orNull:()=>null,orUndefined:()=>{},map:e=>J,ap:e=>J,filter(e){return J},count:e=>0,find:e=>J,exists:e=>false,forEach:e=>{},flatMap:e=>J,flatMapAsync:e=>Promise.resolve(J),reduce:()=>{},reduceRight:()=>{},fold:(e,t)=>e(),match:e=>e.None(),foldLeft:e=>()=>e,foldRight:e=>()=>e,toList:()=>y([]),contains:()=>false,size:0,toEither:e=>p(e),toPromise:()=>Promise.reject(new Error("Cannot convert None to Promise")),toString:()=>"None",toValue:()=>({_tag:"None",value:void 0}),pipe:e=>e(void 0),serialize:()=>({toJSON:()=>JSON.stringify({_tag:"None",value:null}),toYAML:()=>`_tag: None
41
+ value: null`,toBinary:()=>Buffer.from(JSON.stringify({_tag:"None",value:null})).toString("base64")})},k=()=>J,ht=e=>e!=null?U(e):k(),je={from:e=>d(e),none:()=>k(),fromJSON:e=>{let t=JSON.parse(e);return t._tag==="Some"?U(t.value):k()},fromYAML:e=>{let t=e.split(`
42
+ `),r=t[0]?.split(": ")[1],n=t[1]?.split(": ")[1];if(!r||!n)return k();let o=n==="null"?null:JSON.parse(n);return r==="Some"?U(o):k()},fromBinary:e=>{let t=Buffer.from(e,"base64").toString();return je.fromJSON(t)}},d=a(ht,je);export{K as $,Ht as A,Zt as B,Xt as C,er as D,nr as E,ir as F,re as G,me as H,x as I,ot as J,Re as K,A as L,at as M,Me as N,Ve as O,Le as P,z as Q,Fe as R,ge as S,vr as T,Sr as U,Or as V,b as W,Kr as X,jr as Y,dt as Z,en as _,U as a,sn as aa,k as b,be as ba,ht as c,V as ca,d,pe as da,G as e,ke as ea,fe as f,gt as fa,he as g,we as ga,y as h,Fn as ha,c as i,p as j,Mt as k,Vt as l,Ct as m,Ze as n,Xe as o,zt as p,Pe as q,M as r,et as s,Jt as t,Wt as u,jt as v,qt as w,Yt as x,Qt as y,Gt as z};//# sourceMappingURL=chunk-CUVJYVJC.mjs.map
43
+ //# sourceMappingURL=chunk-CUVJYVJC.mjs.map