functype 1.27.2 → 2.0.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/README.md +63 -88
- package/dist/_virtual/_rolldown/runtime.js +1 -0
- package/dist/branded/ValidatedBrand.d.ts +122 -0
- package/dist/branded/ValidatedBrand.js +1 -0
- package/dist/branded/index.d.ts +52 -2
- package/dist/cli/data.d.ts +37 -0
- package/dist/cli/data.js +1 -0
- package/dist/cli/exports.d.ts +5 -46
- package/dist/cli/exports.js +1 -1
- package/dist/cli/formatters.js +4 -0
- package/dist/cli/full-interfaces.d.ts +6 -0
- package/dist/cli/full-interfaces.js +1139 -0
- package/dist/cli/index.js +3 -6
- package/dist/cli/interfaces.generated.js +1 -0
- package/dist/collections/index.d.ts +13 -0
- package/dist/companion/Companion.d.ts +23 -0
- package/dist/companion/Companion.js +1 -0
- package/dist/companion/CompanionTypes.d.ts +30 -0
- package/dist/{CompanionTypes-BVqO7Kc2.js → companion/CompanionTypes.js} +1 -1
- package/dist/companion/index.d.ts +2 -1
- package/dist/companion/index.js +1 -1
- package/dist/conditional/Cond.d.ts +147 -0
- package/dist/conditional/Cond.js +1 -0
- package/dist/conditional/Match.d.ts +295 -0
- package/dist/conditional/Match.js +1 -0
- package/dist/conditional/index.d.ts +3 -2
- package/dist/conditional/index.js +1 -1
- package/dist/core/base/Base.d.ts +12 -0
- package/dist/core/base/Base.js +1 -0
- package/dist/core/throwable/Throwable.d.ts +38 -0
- package/dist/core/throwable/Throwable.js +1 -0
- package/dist/decoder/Decoder.d.ts +15 -0
- package/dist/decoder/DecoderCompanion.js +1 -0
- package/dist/decoder/DecoderError.d.ts +56 -0
- package/dist/decoder/DecoderError.js +2 -0
- package/dist/decoder/Encoder.d.ts +15 -0
- package/dist/decoder/index.d.ts +71 -2
- package/dist/decoder/index.js +1 -1
- package/dist/decoder/tagged.js +1 -0
- package/dist/do/index.d.ts +246 -2
- package/dist/do/index.js +1 -1
- package/dist/do/protocol.d.ts +29 -0
- package/dist/either/index.d.ts +279 -2
- package/dist/either/index.js +1 -1
- package/dist/error/ErrorChain.d.ts +60 -0
- package/dist/error/ErrorChain.js +4 -0
- package/dist/error/ErrorFormatter.d.ts +67 -0
- package/dist/error/ErrorFormatter.js +6 -0
- package/dist/error/ParseError.d.ts +6 -0
- package/dist/error/ParseError.js +1 -0
- package/dist/error/typed/TypedError.d.ts +146 -0
- package/dist/error/typed/TypedError.js +1 -0
- package/dist/error/typed/Validation.d.ts +76 -0
- package/dist/error/typed/Validation.js +1 -0
- package/dist/extractable/Extractable.d.ts +62 -0
- package/dist/extractable/Extractable.js +1 -0
- package/dist/fetch/Http.d.ts +32 -0
- package/dist/fetch/Http.js +1 -0
- package/dist/fetch/HttpClient.d.ts +80 -0
- package/dist/fetch/HttpClient.js +1 -0
- package/dist/fetch/HttpError.d.ts +57 -0
- package/dist/fetch/HttpError.js +1 -0
- package/dist/fetch/HttpRequest.d.ts +103 -0
- package/dist/fetch/index.d.ts +5 -2
- package/dist/fetch/index.js +1 -1
- package/dist/foldable/Foldable.d.ts +27 -0
- package/dist/foldable/index.d.ts +55 -0
- package/dist/foldable/index.js +1 -0
- package/dist/functype/Functype.d.ts +76 -0
- package/dist/functype/FunctypeSum.d.ts +39 -0
- package/dist/functype/index.d.ts +4 -2
- package/dist/hkt/index.d.ts +68 -0
- package/dist/hkt/index.js +1 -0
- package/dist/identity/Identity.d.ts +34 -0
- package/dist/identity/Identity.js +1 -0
- package/dist/index.d.ts +74 -8
- package/dist/index.js +1 -1
- package/dist/internal/base64.js +1 -0
- package/dist/internal/call-alone.js +1 -0
- package/dist/internal/concurrency.d.ts +11 -0
- package/dist/internal/concurrency.js +1 -0
- package/dist/internal/define.js +1 -0
- package/dist/internal/mutation-utils.js +1 -0
- package/dist/internal/signal.js +1 -0
- package/dist/internal/stringify.js +1 -0
- package/dist/invariant/index.d.ts +32 -2
- package/dist/io/Context.d.ts +112 -0
- package/dist/io/Context.js +1 -0
- package/dist/io/Exit.d.ts +249 -0
- package/dist/io/Exit.js +1 -0
- package/dist/io/IO.d.ts +1243 -0
- package/dist/io/IO.js +1 -0
- package/dist/io/Layer.d.ts +139 -0
- package/dist/io/Layer.js +1 -0
- package/dist/io/SpanTracer.d.ts +78 -0
- package/dist/io/SpanTracer.js +1 -0
- package/dist/io/Tag.d.ts +75 -0
- package/dist/io/Tag.js +1 -0
- package/dist/io/TestClock.d.ts +133 -0
- package/dist/io/TestClock.js +1 -0
- package/dist/io/index.d.ts +41 -2
- package/dist/io/index.js +1 -1
- package/dist/lazy/Lazy.d.ts +312 -0
- package/dist/lazy/Lazy.js +1 -0
- package/dist/lazy/index.d.ts +2 -2
- package/dist/lazy/index.js +1 -1
- package/dist/list/LazyList.d.ts +182 -0
- package/dist/list/LazyList.js +1 -0
- package/dist/list/index.d.ts +137 -2
- package/dist/list/index.js +1 -1
- package/dist/logger/index.d.ts +24 -2
- package/dist/map/index.d.ts +95 -2
- package/dist/map/index.js +1 -1
- package/dist/map/shim.d.ts +13 -0
- package/dist/map/shim.js +1 -0
- package/dist/matchable/Matchable.d.ts +38 -0
- package/dist/matchable/Matchable.js +1 -0
- package/dist/obj/Obj.d.ts +212 -0
- package/dist/obj/Obj.js +1 -0
- package/dist/obj/index.d.ts +2 -2
- package/dist/obj/index.js +1 -1
- package/dist/option/index.d.ts +304 -2
- package/dist/option/index.js +1 -1
- package/dist/package.json.js +1 -0
- package/dist/pipe/index.d.ts +14 -0
- package/dist/ref/Ref.d.ts +77 -0
- package/dist/ref/Ref.js +1 -0
- package/dist/reshapeable/Reshapeable.d.ts +90 -0
- package/dist/serializable/Serializable.d.ts +39 -0
- package/dist/serialization/Serialization.d.ts +147 -0
- package/dist/serialization/Serialization.js +1 -0
- package/dist/serialization/SerializationCompanion.d.ts +125 -0
- package/dist/serialization/SerializationCompanion.js +1 -0
- package/dist/serialization/error-envelope.d.ts +44 -0
- package/dist/serialization/error-envelope.js +1 -0
- package/dist/serialization/index.d.ts +4 -2
- package/dist/serialization/index.js +1 -1
- package/dist/set/index.d.ts +106 -2
- package/dist/set/index.js +1 -1
- package/dist/stack/Stack.d.ts +120 -0
- package/dist/stack/Stack.js +1 -0
- package/dist/traced/TraceEvent.d.ts +27 -0
- package/dist/traced/TracedOption.d.ts +46 -0
- package/dist/traced/TracedOption.js +1 -0
- package/dist/traced/Tracer.d.ts +26 -0
- package/dist/traversable/KVTraversable.d.ts +14 -0
- package/dist/traversable/Traversable.d.ts +30 -0
- package/dist/try/index.d.ts +238 -2
- package/dist/try/index.js +1 -1
- package/dist/tuple/index.d.ts +92 -2
- package/dist/tuple/index.js +1 -1
- package/dist/typeable/Typeable.d.ts +40 -0
- package/dist/typeable/Typeable.js +1 -0
- package/dist/typeclass/ContainerOps.d.ts +131 -0
- package/dist/typeclass/Functor.d.ts +41 -0
- package/dist/typeclass/Promisable.d.ts +33 -0
- package/dist/typeclass/index.d.ts +4 -1
- package/dist/typeclass/index.js +1 -1
- package/dist/typeclass/variance.d.ts +54 -0
- package/dist/typeclass/variance.js +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/util/index.d.ts +1 -3
- package/dist/valuable/Valuable.d.ts +28 -0
- package/dist/valuable/Valuable.js +1 -0
- package/dist/wire/index.d.ts +40 -2
- package/package.json +7 -12
- package/dist/Brand-bfnGXuum.d.ts +0 -54
- package/dist/Companion-DiOMBHDG.js +0 -1
- package/dist/CompanionTypes-Cc90cQ4P.d.ts +0 -58
- package/dist/Invariant-DEan-SxV.d.ts +0 -35
- package/dist/Logger-BmprRS8v.d.ts +0 -27
- package/dist/Tuple-B8KM-H8Y.d.ts +0 -213
- package/dist/Wire-3hvw0Ogg.d.ts +0 -42
- package/dist/core/task/index.d.ts +0 -2
- package/dist/core/task/index.js +0 -1
- package/dist/full-interfaces-BadxJrCt.js +0 -1202
- package/dist/index-CLYh2qZu.d.ts +0 -6649
- package/dist/rolldown-runtime-DK3Fl9T5.js +0 -1
- package/dist/serialization-9_SyrfdG.js +0 -3
- package/dist/src-BQPeS6p2.js +0 -10
- package/dist/typeclass-C61yDVYd.js +0 -1
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Foldable } from "../foldable/Foldable.js";
|
|
2
|
+
import { Serializable } from "../serializable/Serializable.js";
|
|
3
|
+
import { Typeable } from "../typeable/Typeable.js";
|
|
4
|
+
import { AsyncMonad } from "../typeclass/Functor.js";
|
|
5
|
+
import { Type } from "../types/index.js";
|
|
6
|
+
/**
|
|
7
|
+
* Base interface for sum-type containers (Either, Try, etc.) that are NOT iterables.
|
|
8
|
+
*
|
|
9
|
+
* Unlike `FunctypeBase`, this base deliberately excludes `Traversable` — which bundles
|
|
10
|
+
* `reduce` / `reduceRight` / `size` / `isEmpty`. Those methods force A-invariance on their
|
|
11
|
+
* containers (signature `(f: (A, A) => A) => A` puts A in both contravariant and covariant
|
|
12
|
+
* positions) and have no semantic meaning for disjoint-union types where the "success"
|
|
13
|
+
* branch is 0-or-1, not a collection.
|
|
14
|
+
*
|
|
15
|
+
* Sum types that extend `FunctypeSum` can be declared covariant in their type parameter
|
|
16
|
+
* (`interface Foo<out A>`) without structural check failures. This mirrors Scala's model:
|
|
17
|
+
* `Either[+L, +R]` and `Try[+T]` do not extend `Iterable`; only `Option[+A]` extends the
|
|
18
|
+
* lighter `IterableOnce[+A]`.
|
|
19
|
+
*
|
|
20
|
+
* Only the covariance-safe subset of `ContainerOps` is included inline: `contains`,
|
|
21
|
+
* `exists`, `every` and `forEach` all place A only in contravariant (callback input) position.
|
|
22
|
+
* `find` (returns `Option<A>`) and `count` are intentionally omitted — if a sum type
|
|
23
|
+
* needs them it can declare them directly.
|
|
24
|
+
*
|
|
25
|
+
* @typeParam A - the type of the "success" branch value
|
|
26
|
+
* @typeParam Tag - the discriminant tag (e.g., `"Left" | "Right"`, `"Success" | "Failure"`)
|
|
27
|
+
*/
|
|
28
|
+
export interface FunctypeSum<A extends Type, Tag extends string = string> extends AsyncMonad<A>, Foldable<A>, Serializable<A>, Typeable<Tag> {
|
|
29
|
+
readonly _tag: Tag;
|
|
30
|
+
readonly [Symbol.toStringTag]: string;
|
|
31
|
+
contains(value: A): boolean;
|
|
32
|
+
exists(p: (a: A) => boolean): boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Tests whether the success value, if there is one, satisfies the predicate. The dual of
|
|
35
|
+
* `exists`, and Scala's `forall`: with no success value it gives `true`, as `[].every(p)` does.
|
|
36
|
+
*/
|
|
37
|
+
every(p: (a: A) => boolean): boolean;
|
|
38
|
+
forEach(f: (a: A) => void): void;
|
|
39
|
+
}
|
package/dist/functype/index.d.ts
CHANGED
|
@@ -1,2 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { Functype, FunctypeBase, FunctypeCollection, FunctypeCore, FunctypeValue } from "./Functype.js";
|
|
2
|
+
import { FunctypeSum } from "./FunctypeSum.js";
|
|
3
|
+
import { Concurrency, ConcurrencyOptions } from "../internal/concurrency.js";
|
|
4
|
+
export { type Concurrency, type ConcurrencyOptions, Functype, FunctypeBase, FunctypeCollection, FunctypeCore, FunctypeSum, FunctypeValue };
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { Either } from "../either/index.js";
|
|
2
|
+
import { List } from "../list/index.js";
|
|
3
|
+
import { Option } from "../option/index.js";
|
|
4
|
+
import { Try } from "../try/index.js";
|
|
5
|
+
import { Type } from "../types/index.js";
|
|
6
|
+
/**
|
|
7
|
+
* Type function for representing higher-kinded types
|
|
8
|
+
*/
|
|
9
|
+
export type Kind<F, A> = F extends ((arg: infer T) => infer R) ? R : never;
|
|
10
|
+
/**
|
|
11
|
+
* Type constructors for common Functype data types
|
|
12
|
+
*/
|
|
13
|
+
export type OptionKind = <A>(a: A) => Option<A>;
|
|
14
|
+
export type ListKind = <A>(a: A) => List<A>;
|
|
15
|
+
export type EitherKind<E> = <A>(a: A) => Either<E, A>;
|
|
16
|
+
export type TryKind = <A>(a: A) => Try<A>;
|
|
17
|
+
/**
|
|
18
|
+
* Generic container types for type-safe operations
|
|
19
|
+
* @internal
|
|
20
|
+
*/
|
|
21
|
+
type Mappable<T> = {
|
|
22
|
+
map<U>(f: (value: T) => U): unknown;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* @internal
|
|
26
|
+
*/
|
|
27
|
+
type Flattenable = {
|
|
28
|
+
flatten(): unknown;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* @internal
|
|
32
|
+
*/
|
|
33
|
+
type FlatMappable<T> = {
|
|
34
|
+
flatMap<U>(f: (value: T) => unknown): unknown;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Universal type that includes all potential return types from the HKT functions
|
|
38
|
+
* Used to avoid 'any' usage which the linter prohibits
|
|
39
|
+
*/
|
|
40
|
+
export type UniversalContainer = Option<unknown> | List<unknown> | Either<unknown, unknown> | Try<unknown>;
|
|
41
|
+
/**
|
|
42
|
+
* HKT provides utilities for working with higher-kinded types
|
|
43
|
+
* This allows writing generic code that works across different
|
|
44
|
+
* container types like Option, List, Either, etc.
|
|
45
|
+
*/
|
|
46
|
+
export declare const HKT: {
|
|
47
|
+
(): {
|
|
48
|
+
_tag: string;
|
|
49
|
+
map: <F, A, B>(fa: unknown, f: (a: A) => B) => unknown;
|
|
50
|
+
flatten: <F, A>(ffa: unknown) => unknown;
|
|
51
|
+
flatMap: <F, A, B>(fa: unknown, f: (a: A) => unknown) => unknown;
|
|
52
|
+
ap: <F, A, B>(ff: unknown, fa: unknown) => unknown;
|
|
53
|
+
sequence: <F, G, A>(fga: unknown) => unknown;
|
|
54
|
+
traverse: <F, G, A, B>(fa: unknown, f: (a: A) => unknown) => unknown;
|
|
55
|
+
_type: string;
|
|
56
|
+
};
|
|
57
|
+
map<F = unknown, A = unknown, B = unknown>(fa: unknown, f: (a: A) => B): unknown;
|
|
58
|
+
flatten<F = unknown, A = unknown>(ffa: unknown): unknown;
|
|
59
|
+
flatMap<F = unknown, A = unknown, B = unknown>(fa: unknown, f: (a: A) => unknown): unknown;
|
|
60
|
+
ap<F = unknown, A = unknown, B = unknown>(ff: unknown, fa: unknown): unknown;
|
|
61
|
+
sequence<F = unknown, G = unknown, A = unknown>(fga: unknown): unknown;
|
|
62
|
+
traverse<F = unknown, G = unknown, A = unknown, B = unknown>(fa: unknown, f: (a: A) => unknown): unknown;
|
|
63
|
+
isOption: <T extends Type>(value: unknown) => value is Option<T> & Mappable<T> & FlatMappable<T>;
|
|
64
|
+
isList: <T extends Type>(value: unknown) => value is List<T> & Mappable<T> & Flattenable & FlatMappable<T>;
|
|
65
|
+
isEither: <E extends Type, A extends Type>(value: unknown) => value is Either<E, A> & Mappable<A> & FlatMappable<A>;
|
|
66
|
+
isTry: <T extends Type>(value: unknown) => value is Try<T> & Mappable<T> & FlatMappable<T>;
|
|
67
|
+
};
|
|
68
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{List as e}from"../list/index.js";import{Option as t}from"../option/index.js";const n=e=>typeof e==`object`&&!!e&&(e._tag===`Some`||e._tag===`None`),r=e=>typeof e==`object`&&!!e&&e._tag===`List`,i=e=>typeof e==`object`&&!!e&&(e._tag===`Left`||e._tag===`Right`),a=e=>typeof e==`object`&&!!e&&(e._tag===`Success`||e._tag===`Failure`),o=()=>{let o=(e,t)=>{if(n(e)||r(e)||i(e)||a(e))return e.map(e=>t(e));throw Error(`Unsupported functor type: ${JSON.stringify(e)}`)},s=t=>{if(n(t))return t.orThrow();if(r(t)){let n=t.toArray();if(n.length>0&&r(n[0])){let t=[];for(let e of n)r(e)&&t.push(...e.toArray());return e(t)}return t.flatten()}if(i(t))return t.isRight()?t.fold(()=>null,e=>e):t;if(a(t))return t.isSuccess()?t.orThrow():t;throw Error(`Unsupported functor type for flatten: ${JSON.stringify(t)}`)},c=(e,t)=>{if(n(e)||r(e)||i(e)||a(e))return e.flatMap(e=>t(e));throw Error(`Unsupported functor type for flatMap: ${JSON.stringify(e)}`)},l=(e,t)=>{if(n(e)&&n(t)||r(e)&&r(t)||i(e)&&i(t)||a(e)&&a(t))return e.flatMap(e=>t.map(t=>e(t)));throw Error(`Unsupported functor type for ap: ${JSON.stringify(e)}`)},u=i=>{if(n(i)){let n=i;if(n.isEmpty)return e([t.none()]);let a=n.orThrow();if(r(a))return a.map(e=>t(e));throw Error(`Unsupported inner container type for sequence`)}if(r(i)){let r=i.toArray();if(r.length===0)return t.none();let a=r[0];if(n(a)){for(let e of r)if(e.isEmpty)return t.none();let n=r.map(e=>e.orThrow());return t(e(n))}throw Error(`Unsupported inner container type for sequence`)}throw Error(`Unsupported outer container type for sequence: ${JSON.stringify(i)}`)};return{_tag:`HKT`,map:o,flatten:s,flatMap:c,ap:l,sequence:u,traverse:(e,t)=>u(o(e,e=>t(e))),_type:`HKT`}},s=o();o.map=(e,t)=>s.map(e,t),o.flatten=e=>s.flatten(e),o.flatMap=(e,t)=>s.flatMap(e,t),o.ap=(e,t)=>s.ap(e,t),o.sequence=e=>s.sequence(e),o.traverse=(e,t)=>s.traverse(e,t),o.isOption=n,o.isList=r,o.isEither=i,o.isTry=a;export{o as HKT};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Identity — a trivial container carrying a single tagged value.
|
|
3
|
+
* Covariant in T (`<out T>`). `isSame` takes `Identity<unknown>` so that
|
|
4
|
+
* cross-type equality checks (semantically always `false` for unrelated types)
|
|
5
|
+
* don't block variance — mirroring the `contains(unknown)` pattern used on
|
|
6
|
+
* List/Set/Map.
|
|
7
|
+
*/
|
|
8
|
+
export type Identity<out T> = {
|
|
9
|
+
readonly _tag: "Identity";
|
|
10
|
+
readonly id: T;
|
|
11
|
+
/** True when `other` holds the same value, compared with `===`. */
|
|
12
|
+
isSame(other: Identity<unknown>): boolean;
|
|
13
|
+
};
|
|
14
|
+
declare const IdentityConstructor: <T>(value: T) => Identity<T>;
|
|
15
|
+
declare const IdentityStatics: {
|
|
16
|
+
/**
|
|
17
|
+
* Creates an Identity. Alias for Identity constructor.
|
|
18
|
+
* @param value - The value to wrap
|
|
19
|
+
* @returns Identity instance
|
|
20
|
+
*/
|
|
21
|
+
of: <T>(value: T) => Identity<T>;
|
|
22
|
+
/**
|
|
23
|
+
* Creates an Identity. Same as of.
|
|
24
|
+
* @param value - The value to wrap
|
|
25
|
+
* @returns Identity instance
|
|
26
|
+
*/
|
|
27
|
+
pure: <T>(value: T) => Identity<T>;
|
|
28
|
+
};
|
|
29
|
+
export declare const Identity: IdentityCompanion;
|
|
30
|
+
/** The type of `Identity`: its constructor and its statics, named so that errors and hovers print `IdentityCompanion`. */
|
|
31
|
+
export interface IdentityCompanion extends IdentityConstructorType, IdentityStaticsType {}
|
|
32
|
+
type IdentityConstructorType = typeof IdentityConstructor;
|
|
33
|
+
type IdentityStaticsType = typeof IdentityStatics;
|
|
34
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Companion as e}from"../companion/Companion.js";import{define as t}from"../internal/define.js";const n=t()(`Identity`,{isSame(e){return e.id===this.id}}),r=e=>{let t=Object.create(n);return t._tag=`Identity`,t.id=e,t},i=e(r,{of:e=>r(e),pure:e=>r(e)});export{i as Identity};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,74 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
|
|
1
|
+
import { BoundedNumber, BoundedString, EmailAddress, ISO8601Date, IntegerNumber, NonEmptyString, NonNegativeNumber, PatternString, PositiveInteger, PositiveNumber, UUID, UrlString, ValidatedBrand, ValidatedBrandCompanion } from "./branded/ValidatedBrand.js";
|
|
2
|
+
import { Brand, BrandedBoolean, BrandedNumber, BrandedString, ExtractBrand, Unwrap, createBrander, hasBrand, unwrap as unwrapBrand } from "./branded/index.js";
|
|
3
|
+
import { Collection } from "./collections/index.js";
|
|
4
|
+
import { Companion } from "./companion/Companion.js";
|
|
5
|
+
import { Cond, CondCompanion } from "./conditional/Cond.js";
|
|
6
|
+
import { DoResult, Doable } from "./do/protocol.js";
|
|
7
|
+
import { Concurrency, ConcurrencyOptions } from "./internal/concurrency.js";
|
|
8
|
+
import { ParseError } from "./error/ParseError.js";
|
|
9
|
+
import { Extractable, isExtractable } from "./extractable/Extractable.js";
|
|
10
|
+
import { CollectionOps, ContainerOps, Flattened } from "./typeclass/ContainerOps.js";
|
|
11
|
+
import { Applicative, AsyncMonad, Functor, Monad } from "./typeclass/Functor.js";
|
|
12
|
+
import { Promisable } from "./typeclass/Promisable.js";
|
|
13
|
+
import { Widen, reduceRightWiden, reduceWiden } from "./typeclass/variance.js";
|
|
14
|
+
import { CompanionMethods, InstanceType, isCompanion } from "./companion/CompanionTypes.js";
|
|
15
|
+
import { Base } from "./core/base/Base.js";
|
|
16
|
+
import { NAME, Throwable, ThrowableType } from "./core/throwable/Throwable.js";
|
|
17
|
+
import { Decoder, DecoderCompanion } from "./decoder/index.js";
|
|
18
|
+
import { $, Do, DoAsync, DoGenerator, EmptyListError, FailureError, FailureErrorType, LeftError, LeftErrorType, NoneError, isDoCapable, unwrap } from "./do/index.js";
|
|
19
|
+
import { Either, EitherBase, EitherCompanion, Left, LeftOf, Right, RightOf, TestEither, TypeCheckLeft, TypeCheckRight, isLeft, isRight, tryCatch, tryCatchAsync } from "./either/index.js";
|
|
20
|
+
import { SerializedError, deserializeError, serializeError } from "./serialization/error-envelope.js";
|
|
21
|
+
import { FUNCTYPE_MARKER, FunctypeEnvelope, ParsedEnvelope, SerializationResult, createSerializationCompanion, createSerializer, createTaggedSerializer, envelope, expectMarker, fromBinary, fromJSON, taggedEnvelope } from "./serialization/SerializationCompanion.js";
|
|
22
|
+
import { FoldableUtils } from "./foldable/index.js";
|
|
23
|
+
import { Foldable } from "./foldable/Foldable.js";
|
|
24
|
+
import { EitherKind, HKT, Kind, ListKind, OptionKind, TryKind, UniversalContainer } from "./hkt/index.js";
|
|
25
|
+
import { Identity, IdentityCompanion } from "./identity/Identity.js";
|
|
26
|
+
import { LazyList, LazyListCompanion } from "./list/LazyList.js";
|
|
27
|
+
import { List, ListCompanion } from "./list/index.js";
|
|
28
|
+
import { Matchable, MatchableUtils } from "./matchable/Matchable.js";
|
|
29
|
+
import { Logger } from "./logger/index.js";
|
|
30
|
+
import { Functype, FunctypeBase, FunctypeCollection, FunctypeCore, FunctypeValue } from "./functype/Functype.js";
|
|
31
|
+
import { FunctypeSum } from "./functype/FunctypeSum.js";
|
|
32
|
+
import { Map, MapCompanion } from "./map/index.js";
|
|
33
|
+
import { ESMap, ESMapType } from "./map/shim.js";
|
|
34
|
+
import { Obj, ObjCompanion } from "./obj/Obj.js";
|
|
35
|
+
import { DecoderError, DecoderErrorCompanion, DecoderErrorComposite, DecoderErrorLeaf } from "./decoder/DecoderError.js";
|
|
36
|
+
import { Encoder } from "./decoder/Encoder.js";
|
|
37
|
+
import { None, NoneOf, Option, OptionBase, OptionCompanion, OptionConstructor, Some, SomeOf } from "./option/index.js";
|
|
38
|
+
import { Pipe } from "./pipe/index.js";
|
|
39
|
+
import { ErrorChainFormatOptions, TaggedThrowable, formatErrorChain, getErrorChain, isTaggedThrowable } from "./error/ErrorChain.js";
|
|
40
|
+
import { ErrorChainElement, ErrorFormatterOptions, ErrorWithTaskInfo, TaskErrorInfo, createErrorSerializer, formatError, formatStackTrace, safeStringify } from "./error/ErrorFormatter.js";
|
|
41
|
+
import { ErrorCode, ErrorMessage, ErrorStatus, TypedError, TypedErrorContext } from "./error/typed/TypedError.js";
|
|
42
|
+
import { FieldValidation, FormValidation, Validation, ValidationRule, Validator } from "./error/typed/Validation.js";
|
|
43
|
+
import { Tag, TagService } from "./io/Tag.js";
|
|
44
|
+
import { Context, ContextServices, HasService } from "./io/Context.js";
|
|
45
|
+
import { DieExitOf, Exit, ExitBase, ExitCompanion, ExitTag, FailureExitOf, InterruptedExitOf, SuccessExitOf } from "./io/Exit.js";
|
|
46
|
+
import { Layer, LayerError, LayerInput, LayerOutput } from "./io/Layer.js";
|
|
47
|
+
import { SpanAttributes, SpanTracer } from "./io/SpanTracer.js";
|
|
48
|
+
import { IO, IOCompanion, InterruptedError, RIO, RepeatExhausted, Task, TimeoutError, UIO, UnsupportedSyncOperationError } from "./io/IO.js";
|
|
49
|
+
import { TestClock, TestClockTag, TestContext } from "./io/TestClock.js";
|
|
50
|
+
import { DecodeError, HttpError, HttpErrorCompanion, HttpMethod, HttpStatusError, NetworkError, ResponseDecodeError } from "./fetch/HttpError.js";
|
|
51
|
+
import { HttpMethodOptions, HttpQueryParams, HttpRequestOptions, HttpRequestView, HttpResponse, ParseMode } from "./fetch/HttpRequest.js";
|
|
52
|
+
import { HttpClient, HttpClientConfig } from "./fetch/HttpClient.js";
|
|
53
|
+
import { Http, HttpCompanion } from "./fetch/Http.js";
|
|
54
|
+
import { Reshapeable } from "./reshapeable/Reshapeable.js";
|
|
55
|
+
import { Serializable, SerializableEnvelope, SerializationMethods } from "./serializable/Serializable.js";
|
|
56
|
+
import { JSONValue, Serialization_d_exports } from "./serialization/Serialization.js";
|
|
57
|
+
import { InvariantViolation, invariant } from "./invariant/index.js";
|
|
58
|
+
import { Lazy, LazyCompanion } from "./lazy/Lazy.js";
|
|
59
|
+
import { Set, SetCompanion } from "./set/index.js";
|
|
60
|
+
import { Stack, StackCompanion } from "./stack/Stack.js";
|
|
61
|
+
import { KVTraversable } from "./traversable/KVTraversable.js";
|
|
62
|
+
import { Reducible, Traversable } from "./traversable/Traversable.js";
|
|
63
|
+
import { FailureOf, SuccessOf, Try, TryBase, TryCompanion, TypeNames } from "./try/index.js";
|
|
64
|
+
import { Tuple, TupleCompanion } from "./tuple/index.js";
|
|
65
|
+
import { Ref, RefCompanion } from "./ref/Ref.js";
|
|
66
|
+
import { ExtractTag, Typeable, TypeableParams, isTypeable } from "./typeable/Typeable.js";
|
|
67
|
+
import { Type } from "./types/index.js";
|
|
68
|
+
import { TraceEvent, TraceOp } from "./traced/TraceEvent.js";
|
|
69
|
+
import { Tracer } from "./traced/Tracer.js";
|
|
70
|
+
import { TracedOption } from "./traced/TracedOption.js";
|
|
71
|
+
import { Valuable, ValuableParams } from "./valuable/Valuable.js";
|
|
72
|
+
import { Wire, WireMark } from "./wire/index.js";
|
|
73
|
+
import { Match, MatchCompanion, UntypedMatch } from "./conditional/Match.js";
|
|
74
|
+
export { $, type Applicative, type AsyncMonad, Base, BoundedNumber, BoundedString, Brand, BrandedBoolean, type BrandedBoolean as BrandedBooleanType, BrandedNumber, type BrandedNumber as BrandedNumberType, BrandedString, type BrandedString as BrandedStringType, Collection, type CollectionOps, Companion, CompanionMethods, type Concurrency, type ConcurrencyOptions, Cond, CondCompanion, type ContainerOps, Context, type ContextServices, type Context as ContextType, type DecodeError, Decoder, DecoderCompanion, DecoderError, type DecoderErrorCompanion, type DecoderErrorComposite, type DecoderErrorLeaf, type DieExitOf, Do, DoAsync, DoGenerator, type DoResult, type Doable, ESMap, ESMapType, Either, EitherBase, EitherCompanion, EitherKind, EmailAddress, EmptyListError, type Encoder, ErrorChainElement, ErrorChainFormatOptions, ErrorCode, ErrorFormatterOptions, ErrorMessage, ErrorStatus, ErrorWithTaskInfo, Exit, type ExitBase, type ExitCompanion, type ExitTag, type Exit as ExitType, type ExtractBrand, ExtractTag, type Extractable, FUNCTYPE_MARKER, FailureError, FailureErrorType, type FailureExitOf, FailureOf, FieldValidation, type Flattened, Foldable, FoldableUtils, FormValidation, type Functor, Functype, FunctypeBase, FunctypeCollection, FunctypeCore, FunctypeEnvelope, FunctypeSum, FunctypeValue, HKT, type HasService, Http, HttpClient, type HttpClientConfig, type HttpCompanion, HttpError, type HttpErrorCompanion, HttpError as HttpErrors, type HttpMethod, type HttpMethodOptions, type HttpQueryParams, type HttpRequestOptions, type HttpRequestView, type HttpResponse, type HttpStatusError, IO, type IOCompanion, type Task as IOTask, type IO as IOType, ISO8601Date, Identity, IdentityCompanion, InstanceType, IntegerNumber, InterruptedError, type InterruptedExitOf, InvariantViolation, type JSONValue, KVTraversable, Kind, Layer, type LayerError, type LayerInput, type LayerOutput, type Layer as LayerType, Lazy, type LazyCompanion, LazyList, LazyListCompanion, type Lazy as LazyType, Left, LeftError, LeftErrorType, LeftOf, List, ListCompanion, ListKind, type Logger, Map, MapCompanion, Match, MatchCompanion, type Matchable, MatchableUtils, type Monad, NAME, type NetworkError, NonEmptyString, NonNegativeNumber, None, NoneError, NoneOf, Obj, ObjCompanion, Option, OptionBase, OptionCompanion, OptionConstructor, OptionKind, ParseError, type ParseMode, ParsedEnvelope, PatternString, Pipe, PositiveInteger, PositiveNumber, type Promisable, type RIO, Reducible, Ref, type RefCompanion, type Ref as RefType, RepeatExhausted, type Reshapeable, type ResponseDecodeError, Right, RightOf, Serializable, SerializableEnvelope, Serialization_d_exports as Serialization, SerializationMethods, SerializationResult, SerializedError, Set, SetCompanion, Some, SomeOf, type SpanAttributes, SpanTracer, Stack, StackCompanion, type SuccessExitOf, SuccessOf, Tag, type TagService, type Tag as TagType, TaggedThrowable, TaskErrorInfo, TestClock, TestClockTag, type TestClock as TestClockType, TestContext, type TestContext as TestContextType, TestEither, Throwable, ThrowableType, TimeoutError, type TraceEvent, type TraceOp, TracedOption, type Tracer, Traversable, Try, TryBase, TryCompanion, TryKind, Tuple, TupleCompanion, Type, TypeCheckLeft, TypeCheckRight, TypeNames, Typeable, TypeableParams, TypedError, TypedErrorContext, type UIO, UUID, UniversalContainer, UnsupportedSyncOperationError, UntypedMatch, type Unwrap, UrlString, ValidatedBrand, type ValidatedBrandCompanion, type ValidatedBrand as ValidatedBrandType, Validation, ValidationRule, Validator, Valuable, ValuableParams, type Widen, type Wire, type WireMark, createBrander, createErrorSerializer, createSerializationCompanion, createSerializer, createTaggedSerializer, deserializeError, envelope, expectMarker, formatError, formatErrorChain, formatStackTrace, fromBinary, fromJSON, getErrorChain, hasBrand, invariant, isCompanion, isDoCapable, isExtractable, isLeft, isRight, isTaggedThrowable, isTypeable, reduceRightWiden, reduceWiden, safeStringify, serializeError, taggedEnvelope, tryCatch, tryCatchAsync, unwrap, unwrapBrand };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{BoundedNumber as ee,BoundedString as te,EmailAddress as ne,ISO8601Date as e,IntegerNumber as t,NonEmptyString as n,NonNegativeNumber as r,PatternString as i,PositiveInteger as a,PositiveNumber as o,UUID as s,UrlString as c,ValidatedBrand as l}from"./branded/ValidatedBrand.js";import{ParseError as u}from"./error/ParseError.js";import{Brand as d,BrandedBoolean as f,BrandedNumber as p,BrandedString as m,createBrander as h,hasBrand as g,unwrap as _}from"./branded/index.js";import{deserializeError as v,serializeError as y}from"./serialization/error-envelope.js";import{FUNCTYPE_MARKER as b,createSerializationCompanion as x,createSerializer as S,createTaggedSerializer as C,envelope as w,expectMarker as T,fromBinary as E,fromJSON as D,taggedEnvelope as O}from"./serialization/SerializationCompanion.js";import{Companion as k}from"./companion/Companion.js";import{reduceRightWiden as A,reduceWiden as j}from"./typeclass/variance.js";import{isCompanion as M}from"./companion/CompanionTypes.js";import{Ref as N}from"./ref/Ref.js";import{Base as P}from"./core/base/Base.js";import{NAME as F,Throwable as I}from"./core/throwable/Throwable.js";import{Decoder as L}from"./decoder/index.js";import{$ as R,Do as z,DoAsync as B,EmptyListError as V,FailureError as H,LeftError as U,NoneError as W,isDoCapable as G,unwrap as K}from"./do/index.js";import{Either as q,Left as J,Right as Y,TypeCheckLeft as X,TypeCheckRight as Z,isLeft as re,isRight as ie,tryCatch as ae,tryCatchAsync as oe}from"./either/index.js";import{FoldableUtils as se}from"./foldable/index.js";import{HKT as Q}from"./hkt/index.js";import{Cond as ce}from"./conditional/Cond.js";import{Match as le}from"./conditional/Match.js";import{Identity as ue}from"./identity/Identity.js";import{LazyList as de}from"./list/LazyList.js";import{List as fe}from"./list/index.js";import{Map as pe}from"./map/index.js";import{ESMap as me}from"./map/shim.js";import{DecoderError as he}from"./decoder/DecoderError.js";import{Obj as ge}from"./obj/Obj.js";import{None as _e,Option as ve,OptionConstructor as ye,Some as be}from"./option/index.js";import{formatErrorChain as xe,getErrorChain as Se,isTaggedThrowable as Ce}from"./error/ErrorChain.js";import{createErrorSerializer as we,formatError as Te,formatStackTrace as Ee,safeStringify as De}from"./error/ErrorFormatter.js";import{TypedError as Oe}from"./error/typed/TypedError.js";import{Validation as ke}from"./error/typed/Validation.js";import{isExtractable as Ae}from"./extractable/Extractable.js";import{Context as je}from"./io/Context.js";import{Exit as Me}from"./io/Exit.js";import{Tag as Ne}from"./io/Tag.js";import{SpanTracer as Pe}from"./io/SpanTracer.js";import{IO as Fe,InterruptedError as Ie,RepeatExhausted as Le,TimeoutError as Re,UnsupportedSyncOperationError as ze}from"./io/IO.js";import{Layer as Be}from"./io/Layer.js";import{TestClock as Ve,TestClockTag as He,TestContext as Ue}from"./io/TestClock.js";import{HttpClient as We}from"./fetch/HttpClient.js";import{HttpError as $}from"./fetch/HttpError.js";import{Http as Ge}from"./fetch/Http.js";import{Serialization_exports as Ke}from"./serialization/Serialization.js";import{Set as qe}from"./set/index.js";import{Stack as Je}from"./stack/Stack.js";import{InvariantViolation as Ye,invariant as Xe}from"./invariant/index.js";import{Lazy as Ze}from"./lazy/Lazy.js";import{MatchableUtils as Qe}from"./matchable/Matchable.js";import{Try as $e}from"./try/index.js";import{Tuple as et}from"./tuple/index.js";import{Typeable as tt,isTypeable as nt}from"./typeable/Typeable.js";import{TracedOption as rt}from"./traced/TracedOption.js";import{Valuable as it}from"./valuable/Valuable.js";export{R as $,P as Base,ee as BoundedNumber,te as BoundedString,d as Brand,f as BrandedBoolean,p as BrandedNumber,m as BrandedString,k as Companion,ce as Cond,je as Context,L as Decoder,he as DecoderError,z as Do,B as DoAsync,me as ESMap,q as Either,ne as EmailAddress,V as EmptyListError,Me as Exit,b as FUNCTYPE_MARKER,H as FailureError,se as FoldableUtils,Q as HKT,Ge as Http,We as HttpClient,$ as HttpError,$ as HttpErrors,Fe as IO,e as ISO8601Date,ue as Identity,t as IntegerNumber,Ie as InterruptedError,Ye as InvariantViolation,Be as Layer,Ze as Lazy,de as LazyList,J as Left,U as LeftError,fe as List,pe as Map,le as Match,Qe as MatchableUtils,F as NAME,n as NonEmptyString,r as NonNegativeNumber,_e as None,W as NoneError,ge as Obj,ve as Option,ye as OptionConstructor,u as ParseError,i as PatternString,a as PositiveInteger,o as PositiveNumber,N as Ref,Le as RepeatExhausted,Y as Right,Ke as Serialization,qe as Set,be as Some,Pe as SpanTracer,Je as Stack,Ne as Tag,Ve as TestClock,He as TestClockTag,Ue as TestContext,I as Throwable,Re as TimeoutError,rt as TracedOption,$e as Try,et as Tuple,X as TypeCheckLeft,Z as TypeCheckRight,tt as Typeable,Oe as TypedError,s as UUID,ze as UnsupportedSyncOperationError,c as UrlString,l as ValidatedBrand,ke as Validation,it as Valuable,h as createBrander,we as createErrorSerializer,x as createSerializationCompanion,S as createSerializer,C as createTaggedSerializer,v as deserializeError,w as envelope,T as expectMarker,Te as formatError,xe as formatErrorChain,Ee as formatStackTrace,E as fromBinary,D as fromJSON,Se as getErrorChain,g as hasBrand,Xe as invariant,M as isCompanion,G as isDoCapable,Ae as isExtractable,re as isLeft,ie as isRight,Ce as isTaggedThrowable,nt as isTypeable,A as reduceRightWiden,j as reduceWiden,De as safeStringify,y as serializeError,O as taggedEnvelope,ae as tryCatch,oe as tryCatchAsync,K as unwrap,_ as unwrapBrand};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=32768,t=t=>{let n=new TextEncoder().encode(t),r=Array.from({length:Math.ceil(n.length/e)},(t,r)=>String.fromCharCode(...n.subarray(r*e,(r+1)*e)));return btoa(r.join(``))},n=e=>{let t=e.replace(/\s+/g,``).replace(/-/g,`+`).replace(/_/g,`/`),n=t.padEnd(Math.ceil(t.length/4)*4,`=`),r=atob(n),i=new Uint8Array(r.length);for(let e=0;e<r.length;e++)i[e]=r.charCodeAt(e);return new TextDecoder(`utf-8`,{ignoreBOM:!0}).decode(i)};export{n as base64ToUtf8,t as utf8ToBase64};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=e=>e(),t=(e,t)=>e(t);export{e as callAlone0,t as callAlone1};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bounded-concurrency traversal shared by the async collection methods and `Either.traverseAsync`.
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* How many calls may run at once: a positive integer, or `"unbounded"` to start them all together.
|
|
6
|
+
* `1` runs them one after another, in input order.
|
|
7
|
+
*/
|
|
8
|
+
export type Concurrency = number | "unbounded";
|
|
9
|
+
export type ConcurrencyOptions = {
|
|
10
|
+
readonly concurrency?: Concurrency;
|
|
11
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=(e,t)=>{if(e===`unbounded`)return t;if(!Number.isInteger(e)||e<1)throw RangeError(`concurrency must be a positive integer or "unbounded", got ${String(e)}`);return Math.min(e,t)},t=async(t,n,r,i=()=>!1)=>{let a=Array.from(t),o=[],s={next:0,stopped:!1},c=async()=>{if(s.stopped||s.next>=a.length)return;let e=s.next;s.next=e+1;try{let t=await n(a[e]);o[e]={value:t},i(t)&&(s.stopped=!0)}catch(e){throw s.stopped=!0,e}return c()};return await Promise.all(Array.from({length:e(r,a.length)},c)),o.flatMap(e=>[e.value])};export{t as traverseWithConcurrency,e as workerCount};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=()=>(e,t)=>{let n=function(){};Object.defineProperty(n,"name",{value:e});let r=n.prototype;return Reflect.ownKeys(t).forEach(e=>{let n=Object.getOwnPropertyDescriptor(t,e);n&&Object.defineProperty(r,e,{...n,enumerable:!1})}),Object.freeze(r)};export{e as define};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Ref as e}from"../ref/Ref.js";const t=(t=0)=>{let n=e(t),r=t;return{get:()=>n.get(),set:e=>n.set(e),increment:()=>n.updateAndGet(e=>e+1),decrement:()=>n.updateAndGet(e=>e-1),reset:()=>n.set(r),compareAndSet:(e,t)=>n.compareAndSet(e,t)}},n=()=>{let t=e([]);return{add:e=>t.update(t=>[...t,e]),addAll:e=>t.update(t=>[...t,...e]),build:()=>t.get(),clear:()=>t.set([]),size:()=>t.get().length}};export{n as ArrayBuilder,t as Counter};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=e=>{let t=e.filter(e=>e!==void 0),[n]=t;if(n!==void 0&&t.length===1)return{signal:n,dispose:()=>{}};let r=new AbortController,i=t.find(e=>e.aborted);if(i)return r.abort(i.reason),{signal:r.signal,dispose:()=>{}};let a=t.map(e=>{let t=()=>r.abort(e.reason);return e.addEventListener(`abort`,t,{once:!0}),()=>e.removeEventListener(`abort`,t)});return{signal:r.signal,dispose:()=>a.forEach(e=>e())}};export{e as anySignal};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function e(e){if(e===void 0||typeof e==`symbol`||typeof e==`function`)return;let t=/* @__PURE__ */ new Set;function n(e){if(e===null)return`null`;switch(typeof e){case`string`:return JSON.stringify(e);case`number`:return isFinite(e)?String(e):`null`;case`boolean`:return String(e);case`bigint`:return`"${e}"`;case`undefined`:case`symbol`:case`function`:return}let r=e;if(t.has(r))return`"[Circular]"`;t.add(r);try{if(`toJSON`in r&&typeof r.toJSON==`function`)return n(r.toJSON());if(Array.isArray(r))return`[${r.map(e=>n(e)??`null`).join(`,`)}]`;let e=Object.keys(r).sort(),t=[];for(let i of e){let e=n(r[i]);e!==void 0&&t.push(`${JSON.stringify(i)}:${e}`)}return`{${t.join(`,`)}}`}finally{t.delete(r)}}try{return n(e)}catch{return}}const t=e=>e instanceof Error||Object.prototype.toString.call(e)===`[object Error]`;function n(n){try{return t(n)?String(n):e(n)}catch{return e(n)}}export{e as safeStringify,n as showValue};
|
|
@@ -1,2 +1,32 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* The error `invariant()` throws: a programmer error, never an expected failure. Tagged so a top-level
|
|
3
|
+
* handler can tell "a bug fired" apart from a failure that should have been an `Either`.
|
|
4
|
+
*/
|
|
5
|
+
export type InvariantViolation = Error & {
|
|
6
|
+
readonly name: "InvariantViolation";
|
|
7
|
+
readonly _tag: "InvariantViolation";
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Builds an {@link InvariantViolation}. Use it directly where a branch can only be reached by a bug and
|
|
11
|
+
* there is no condition to assert, e.g. `throw InvariantViolation("unreachable: unknown variant")`.
|
|
12
|
+
*/
|
|
13
|
+
export declare const InvariantViolation: (message: string) => InvariantViolation;
|
|
14
|
+
/**
|
|
15
|
+
* Asserts a condition that can only be false because of a bug, and narrows it for the code after it.
|
|
16
|
+
*
|
|
17
|
+
* Expected failures return `Either`; `invariant` is for the other kind — "upsert returned no row",
|
|
18
|
+
* "step must be non-negative", "AUTH_PROVIDER is required in production". It covers one statement, so a
|
|
19
|
+
* function can mix bug checks with `Either`-returning failure paths, and `functype/prefer-either` never
|
|
20
|
+
* sees a `throw` to report.
|
|
21
|
+
*
|
|
22
|
+
* ```ts
|
|
23
|
+
* invariant(row, "upsert returned no row") // row: Row from here on
|
|
24
|
+
* invariant(teamDomain && aud, "requires CF_ACCESS_TEAM_DOMAIN and CF_ACCESS_AUD")
|
|
25
|
+
* invariant(n >= 0, () => `step must be non-negative, got ${n}`) // message built only on failure
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* @param condition - Must be truthy. Narrowed to truthy after the call.
|
|
29
|
+
* @param message - The error message, or a thunk that builds it only when the check fails.
|
|
30
|
+
* @throws {@link InvariantViolation} when `condition` is falsy.
|
|
31
|
+
*/
|
|
32
|
+
export declare function invariant(condition: unknown, message: string | (() => string)): asserts condition;
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { Option } from "../option/index.js";
|
|
2
|
+
import { Type } from "../types/index.js";
|
|
3
|
+
import { Tag } from "./Tag.js";
|
|
4
|
+
/**
|
|
5
|
+
* Context module - service container for dependency injection.
|
|
6
|
+
* @module Context
|
|
7
|
+
* @category IO
|
|
8
|
+
*
|
|
9
|
+
* Context is an immutable container that holds service implementations
|
|
10
|
+
* identified by their Tags.
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Context holds service implementations for dependency injection.
|
|
14
|
+
* It's an immutable container that maps Tags to their implementations.
|
|
15
|
+
*
|
|
16
|
+
* @typeParam R - The services contained in this context (intersection type)
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* const ctx = Context.empty()
|
|
21
|
+
* .add(Logger, consoleLogger)
|
|
22
|
+
* .add(Database, pgDatabase)
|
|
23
|
+
*
|
|
24
|
+
* // Access a service
|
|
25
|
+
* const logger = ctx.get(Logger) // Option<Logger>
|
|
26
|
+
* const loggerUnsafe = ctx.unsafeGet(Logger) // Logger (throws if missing)
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export interface Context<R extends Type> {
|
|
30
|
+
/**
|
|
31
|
+
* Type brand
|
|
32
|
+
* @internal
|
|
33
|
+
*/
|
|
34
|
+
readonly _tag: "Context";
|
|
35
|
+
/**
|
|
36
|
+
* Phantom type for requirements
|
|
37
|
+
* @internal
|
|
38
|
+
*/
|
|
39
|
+
readonly _R?: R;
|
|
40
|
+
/**
|
|
41
|
+
* Internal service map
|
|
42
|
+
* @internal
|
|
43
|
+
*/
|
|
44
|
+
readonly services: ReadonlyMap<string, Type>;
|
|
45
|
+
/**
|
|
46
|
+
* Gets a service from the context.
|
|
47
|
+
* @param tag - The tag identifying the service
|
|
48
|
+
* @returns Some(service) if found, None otherwise
|
|
49
|
+
*/
|
|
50
|
+
get<S extends Type>(tag: Tag<S>): Option<S>;
|
|
51
|
+
/**
|
|
52
|
+
* Gets a service from the context, throwing if not found.
|
|
53
|
+
* @param tag - The tag identifying the service
|
|
54
|
+
* @returns The service
|
|
55
|
+
* @throws Error if service not found
|
|
56
|
+
*/
|
|
57
|
+
unsafeGet<S extends Type>(tag: Tag<S>): S;
|
|
58
|
+
/**
|
|
59
|
+
* Checks if a service exists in the context.
|
|
60
|
+
* @param tag - The tag to check
|
|
61
|
+
* @returns true if the service exists
|
|
62
|
+
*/
|
|
63
|
+
has<S extends Type>(tag: Tag<S>): boolean;
|
|
64
|
+
/**
|
|
65
|
+
* Adds a service to the context, returning a new context.
|
|
66
|
+
* @param tag - The tag for the service
|
|
67
|
+
* @param service - The service implementation
|
|
68
|
+
* @returns A new context with the service added
|
|
69
|
+
*/
|
|
70
|
+
add<S extends Type>(tag: Tag<S>, service: S): Context<R & S>;
|
|
71
|
+
/**
|
|
72
|
+
* Merges another context into this one.
|
|
73
|
+
* @param other - The context to merge
|
|
74
|
+
* @returns A new context with all services from both
|
|
75
|
+
*/
|
|
76
|
+
merge<R2 extends Type>(other: Context<R2>): Context<R & R2>;
|
|
77
|
+
/**
|
|
78
|
+
* Returns the number of services in this context.
|
|
79
|
+
*/
|
|
80
|
+
readonly size: number;
|
|
81
|
+
/**
|
|
82
|
+
* String representation
|
|
83
|
+
*/
|
|
84
|
+
toString(): string;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Context companion object with utility methods
|
|
88
|
+
*/
|
|
89
|
+
export declare const Context: {
|
|
90
|
+
/**
|
|
91
|
+
* Creates an empty context with no services.
|
|
92
|
+
*/
|
|
93
|
+
empty: <R extends Type = never>() => Context<R>;
|
|
94
|
+
/**
|
|
95
|
+
* Creates a context with a single service.
|
|
96
|
+
* @param tag - The tag for the service
|
|
97
|
+
* @param service - The service implementation
|
|
98
|
+
*/
|
|
99
|
+
make: <S extends Type>(tag: Tag<S>, service: S) => Context<S>;
|
|
100
|
+
/**
|
|
101
|
+
* Checks if a value is a Context.
|
|
102
|
+
*/
|
|
103
|
+
isContext: <R extends Type>(value: unknown) => value is Context<R>;
|
|
104
|
+
};
|
|
105
|
+
/**
|
|
106
|
+
* Type helper to extract requirements from a Context
|
|
107
|
+
*/
|
|
108
|
+
export type ContextServices<C> = C extends Context<infer R> ? R : never;
|
|
109
|
+
/**
|
|
110
|
+
* Type helper to check if a context provides a service
|
|
111
|
+
*/
|
|
112
|
+
export type HasService<C, S> = S extends ContextServices<C> ? true : false;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{define as e}from"../internal/define.js";import{None as t,Some as n}from"../option/index.js";const r=e()(`Context`,{get(e){let r=this.services.get(e.id);return r===void 0?t():n(i(r))},unsafeGet(e){let t=this.services.get(e.id);if(t===void 0)throw Error(`Service not found: ${e.id}`);return i(t)},has(e){return this.services.has(e.id)},add(e,t){let n=new Map(this.services);return n.set(e.id,t),a(n)},merge(e){let t=new Map(this.services);for(let[n,r]of e.services)t.set(n,r);return a(t)},get size(){return this.services.size},toString(){return`Context(${Array.from(this.services.keys()).join(`, `)})`}}),i=e=>e,a=e=>{let t=Object.create(r);return t._tag=`Context`,t.services=e,Object.freeze(t)},o={empty:()=>a(/* @__PURE__ */ new Map),make:(e,t)=>{let n=/* @__PURE__ */ new Map;return n.set(e.id,t),a(n)},isContext:e=>typeof e==`object`&&!!e&&e._tag===`Context`};export{o as Context};
|