functype 1.27.1 → 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-0XJEOHi_.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-BTLBc-KK.js +0 -10
- package/dist/typeclass-C61yDVYd.js +0 -1
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Type } from "../types/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Functor type class - supports mapping over wrapped values
|
|
4
|
+
*
|
|
5
|
+
* Laws:
|
|
6
|
+
* - Identity: fa.map(x => x) ≡ fa
|
|
7
|
+
* - Composition: fa.map(f).map(g) ≡ fa.map(x => g(f(x)))
|
|
8
|
+
*/
|
|
9
|
+
export interface Functor<out A extends Type> {
|
|
10
|
+
map<B extends Type>(f: (value: A) => B): Functor<B>;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Applicative functor - supports applying wrapped functions to wrapped values
|
|
14
|
+
*
|
|
15
|
+
* Laws:
|
|
16
|
+
* - Identity: pure(x => x).ap(v) ≡ v
|
|
17
|
+
* - Composition: pure(compose).ap(u).ap(v).ap(w) ≡ u.ap(v.ap(w))
|
|
18
|
+
* - Homomorphism: pure(f).ap(pure(x)) ≡ pure(f(x))
|
|
19
|
+
* - Interchange: u.ap(pure(y)) ≡ pure(f => f(y)).ap(u)
|
|
20
|
+
*/
|
|
21
|
+
export interface Applicative<out A extends Type> extends Functor<A> {
|
|
22
|
+
ap<B extends Type>(ff: Applicative<(value: A) => B>): Applicative<B>;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Monad type class - supports flat mapping (chaining) operations
|
|
26
|
+
*
|
|
27
|
+
* Laws:
|
|
28
|
+
* - Left identity: pure(a).flatMap(f) ≡ f(a)
|
|
29
|
+
* - Right identity: m.flatMap(pure) ≡ m
|
|
30
|
+
* - Associativity: m.flatMap(f).flatMap(g) ≡ m.flatMap(x => f(x).flatMap(g))
|
|
31
|
+
*/
|
|
32
|
+
export interface Monad<out A extends Type> extends Applicative<A> {
|
|
33
|
+
flatMap<B extends Type>(f: (value: A) => Monad<B>): Monad<B>;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Async monad - supports asynchronous monadic operations
|
|
37
|
+
* Extends Monad so it has map, ap, and flatMap in addition to flatMapAsync
|
|
38
|
+
*/
|
|
39
|
+
export interface AsyncMonad<out A extends Type> extends Monad<A> {
|
|
40
|
+
flatMapAsync<B extends Type>(f: (value: A) => PromiseLike<AsyncMonad<B>>): PromiseLike<AsyncMonad<B>>;
|
|
41
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Type } from "../types/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Promisable trait - supports conversion to Promise
|
|
4
|
+
*
|
|
5
|
+
* Represents containers or values that can be converted to Promise form.
|
|
6
|
+
* This enables integration with async/await patterns and Promise-based APIs
|
|
7
|
+
* while maintaining functional programming principles.
|
|
8
|
+
*
|
|
9
|
+
* @template A - The type of value contained within the Promise
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* const either: Either<string, number> = Right(42)
|
|
14
|
+
* const promise: Promise<number> = either.toPromise()
|
|
15
|
+
* // Promise resolves with 42
|
|
16
|
+
*
|
|
17
|
+
* const leftEither: Either<string, number> = Left("error")
|
|
18
|
+
* const failedPromise: Promise<number> = leftEither.toPromise()
|
|
19
|
+
* // Promise rejects with "error"
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export interface Promisable<out A extends Type> {
|
|
23
|
+
/**
|
|
24
|
+
* Converts this container to a Promise
|
|
25
|
+
*
|
|
26
|
+
* The behavior depends on the implementing container:
|
|
27
|
+
* - Success/Right/Some containers resolve with their value
|
|
28
|
+
* - Failure/Left/None containers reject with their error/default error
|
|
29
|
+
*
|
|
30
|
+
* @returns A Promise that resolves or rejects based on the container's state
|
|
31
|
+
*/
|
|
32
|
+
toPromise(): Promise<A>;
|
|
33
|
+
}
|
|
@@ -1,2 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CollectionOps, ContainerOps, Flattened } from "./ContainerOps.js";
|
|
2
|
+
import { Applicative, AsyncMonad, Functor, Monad } from "./Functor.js";
|
|
3
|
+
import { Promisable } from "./Promisable.js";
|
|
4
|
+
import { Widen, reduceRightWiden, reduceWiden } from "./variance.js";
|
|
2
5
|
export { type Applicative, type AsyncMonad, type CollectionOps, type ContainerOps, type Flattened, type Functor, type Monad, type Promisable, type Widen, reduceRightWiden, reduceWiden };
|
package/dist/typeclass/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
export{reduceRightWiden,reduceWiden}from"./variance.js";
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Variance helpers — small utilities for expressing covariance-safe signatures
|
|
3
|
+
* when TypeScript's type system doesn't offer the exact constraint we need.
|
|
4
|
+
*
|
|
5
|
+
* Motivation: Scala has lower-bound type parameters like `def reduce[B >: A](op: (B, B) => B): B`
|
|
6
|
+
* — B must be a supertype of A. TypeScript lacks lower bounds, so a naive port
|
|
7
|
+
* (`reduce<B = A>(op: (b: B, a: B) => B): B`) lets the caller pick ANY B, including
|
|
8
|
+
* unrelated types. At runtime that's a footgun: `List<number>.reduce<string>(...)` would
|
|
9
|
+
* compile but run as number addition typed as string.
|
|
10
|
+
*
|
|
11
|
+
* `Widen<A, B>` closes that gap using a conditional type. When B is truly a supertype
|
|
12
|
+
* of A (including the default case B = A), `Widen<A, B>` is B. When B is unrelated,
|
|
13
|
+
* it resolves to `never`, which makes the callback uncallable and produces a compile
|
|
14
|
+
* error at the call site.
|
|
15
|
+
*
|
|
16
|
+
* @module typeclass/variance
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* The TypeScript equivalent of Scala's `B >: A` (B is a supertype of A).
|
|
20
|
+
*
|
|
21
|
+
* Resolves to `B` when `A extends B` (i.e., B is a legitimate supertype of A, or B = A).
|
|
22
|
+
* Resolves to `never` otherwise, which renders any callback position using Widen
|
|
23
|
+
* uncallable — the user gets a compile-time error rather than a runtime type lie.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* // Inside a container interface:
|
|
28
|
+
* reduce<B = A>(op: (b: Widen<A, B>, a: Widen<A, B>) => Widen<A, B>): Widen<A, B>
|
|
29
|
+
*
|
|
30
|
+
* // Callers:
|
|
31
|
+
* list.reduce((a, b) => a + b) // B defaults to A, Widen<A,A> = A, fine
|
|
32
|
+
* list.reduce<A | "extra">(...) // A extends A | "extra", Widen = B, fine
|
|
33
|
+
* list.reduce<UnrelatedType>(...) // A doesn't extend Unrelated, Widen = never, compile error
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export type Widen<A, B> = A extends B ? B : never;
|
|
37
|
+
/**
|
|
38
|
+
* Runtime-safe `reduce` over an array whose element type `A` may be narrower than
|
|
39
|
+
* the accumulator type `B`. Centralizes the single `as unknown as B` cast that's
|
|
40
|
+
* otherwise spread across every container's implementation.
|
|
41
|
+
*
|
|
42
|
+
* Safety: the cast is sound because the `Widen<A, B>` type-level constraint at the
|
|
43
|
+
* public API layer guarantees `A <: B`. When that holds, A values flowing into the
|
|
44
|
+
* callback are valid B values at runtime — exactly what Scala's `[B >: A]` provides.
|
|
45
|
+
*
|
|
46
|
+
* @param arr - source array of A values
|
|
47
|
+
* @param op - accumulator operation typed over B (where B is A or a supertype)
|
|
48
|
+
* @returns the folded value, typed as B
|
|
49
|
+
*/
|
|
50
|
+
export declare const reduceWiden: <A, B>(arr: readonly A[], op: (b: B, a: B) => B) => B;
|
|
51
|
+
/**
|
|
52
|
+
* Right-associative variant of {@link reduceWiden}. Same safety argument.
|
|
53
|
+
*/
|
|
54
|
+
export declare const reduceRightWiden: <A, B>(arr: readonly A[], op: (b: B, a: B) => B) => B;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=(e,t)=>e.reduce(t),t=(e,t)=>e.reduceRight(t);export{t as reduceRightWiden,e as reduceWiden};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type Type = unknown;
|
package/dist/util/index.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
//#region src/util/index.d.ts
|
|
2
1
|
/**
|
|
3
2
|
* Merges two objects into a single object with the combined type.
|
|
4
3
|
*
|
|
@@ -19,5 +18,4 @@
|
|
|
19
18
|
* const merged = mergeObjects(base, extra)
|
|
20
19
|
* // merged: { a: number } & { b: number }
|
|
21
20
|
*/
|
|
22
|
-
export declare function mergeObjects<O1 extends object, O2 extends object>(object1: O1, object2: O2): O1 & O2;
|
|
23
|
-
//#endregion
|
|
21
|
+
export declare function mergeObjects<O1 extends object, O2 extends object>(object1: O1, object2: O2): O1 & O2;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Typeable } from "../typeable/Typeable.js";
|
|
2
|
+
/**
|
|
3
|
+
* Parameters for creating a Valuable instance
|
|
4
|
+
*/
|
|
5
|
+
export type ValuableParams<Tag extends string, T, V> = {
|
|
6
|
+
_tag: Tag;
|
|
7
|
+
impl: T;
|
|
8
|
+
value: V;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Represents a type that can extract its inner value. Creates a Valuable wrapper that adds value extraction capabilities.
|
|
12
|
+
* @param params - Configuration parameters
|
|
13
|
+
* @module Valuable
|
|
14
|
+
* @category Utilities
|
|
15
|
+
*/
|
|
16
|
+
export declare function Valuable<Tag extends string, V, T = object>(params: ValuableParams<Tag, T, V>): T & {
|
|
17
|
+
toValue: () => {
|
|
18
|
+
_tag: Tag;
|
|
19
|
+
value: V;
|
|
20
|
+
};
|
|
21
|
+
_tag: Tag;
|
|
22
|
+
};
|
|
23
|
+
export type Valuable<Tag extends string, V, T = object> = Typeable<Tag, T> & {
|
|
24
|
+
toValue(): {
|
|
25
|
+
_tag: Tag;
|
|
26
|
+
value: V;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Typeable as e}from"../typeable/Typeable.js";function t(t){let n=e({_tag:t._tag,impl:t.impl});return{...n,toValue:()=>({_tag:n._tag,value:t.value})}}export{t as Valuable};
|
package/dist/wire/index.d.ts
CHANGED
|
@@ -1,2 +1,40 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* A value in its serialization-safe shape — a DB row, an HTTP body, a JSONB payload, a workflow
|
|
3
|
+
* input. Wraps ANY boundary shape: a collection (`Wire<ReadonlyArray<Row>>`), a nullable field
|
|
4
|
+
* (`Wire<string | null>`), or a whole row/DTO type (`Wire<Row>`), which covers every field inside it.
|
|
5
|
+
*
|
|
6
|
+
* `null` is the shape that survives `JSON.stringify`; `Option` and `List` are not. Inside the code that
|
|
7
|
+
* transforms these values, convert with `Option(x)` / `List(xs)`.
|
|
8
|
+
*
|
|
9
|
+
* Zero runtime, zero type-level enforcement. `Wire<T>` is `T | (T & WireMark)`: the plain `T` member
|
|
10
|
+
* keeps it assignable both ways with `T` — including `null`, `undefined` and `unknown` — so call sites
|
|
11
|
+
* need no casts, and generic helpers like `findOne<R>(): Promise<Wire<R | null>>` compile. The branded
|
|
12
|
+
* member exists so TypeScript keeps the alias name instead of resolving it eagerly: inferred exports
|
|
13
|
+
* emit `Wire<Row>` in `.d.ts` files and hovers, rather than a type that names an unexported symbol
|
|
14
|
+
* (which fails a consumer's declaration build with TS4023).
|
|
15
|
+
*
|
|
16
|
+
* Value lives in three places:
|
|
17
|
+
* - `rg 'Wire<'` is the countable inventory of serialization boundaries;
|
|
18
|
+
* - the name documents intent at the declaration site;
|
|
19
|
+
* - `functype/prefer-list` and `functype/prefer-option` skip everything inside a `Wire<…>` type
|
|
20
|
+
* argument (`wireTypes` option, default `["Wire"]`), so the boundary is declared once instead of
|
|
21
|
+
* suppressed at every field.
|
|
22
|
+
*
|
|
23
|
+
* Consumer aliases compose: `type UserRow = Wire<{ … }>` — uses of `UserRow` pass the linter, and the
|
|
24
|
+
* alias declaration is the one place the boundary is stated.
|
|
25
|
+
*
|
|
26
|
+
* Migration from 1.9: `Wire<Row>` meant `ReadonlyArray<Row>`; write `Wire<ReadonlyArray<Row>>`. The
|
|
27
|
+
* change is compile-loud except for `Wire<object>` and `Wire<any>`, which accept an array either way.
|
|
28
|
+
*
|
|
29
|
+
* @category Wire
|
|
30
|
+
*/
|
|
31
|
+
declare const WIRE: unique symbol;
|
|
32
|
+
/**
|
|
33
|
+
* The phantom mark that keeps `Wire<T>` a named alias through inference and declaration emit.
|
|
34
|
+
* Exported so emitted declarations can name it; never needed in user code.
|
|
35
|
+
*/
|
|
36
|
+
export interface WireMark {
|
|
37
|
+
readonly [WIRE]?: never;
|
|
38
|
+
}
|
|
39
|
+
export type Wire<T> = T | (T & WireMark);
|
|
40
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "functype",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A functional programming library for TypeScript, using immutable data structures and type classes",
|
|
6
6
|
"keywords": [
|
|
@@ -13,7 +13,6 @@
|
|
|
13
13
|
"option",
|
|
14
14
|
"either",
|
|
15
15
|
"try",
|
|
16
|
-
"task",
|
|
17
16
|
"io",
|
|
18
17
|
"list",
|
|
19
18
|
"immutable",
|
|
@@ -34,13 +33,14 @@
|
|
|
34
33
|
"devDependencies": {
|
|
35
34
|
"@eslint/compat": "^2.1.1",
|
|
36
35
|
"@eslint/eslintrc": "^3.3.7",
|
|
37
|
-
"@types/node": "~24.19.
|
|
38
|
-
"eslint-config-functype": "2.
|
|
36
|
+
"@types/node": "~24.19.2",
|
|
37
|
+
"eslint-config-functype": "2.200.0",
|
|
38
|
+
"esbuild": "^0.28.2",
|
|
39
39
|
"eslint-plugin-functional": "^10.0.1",
|
|
40
40
|
"fast-check": "^4.10.2",
|
|
41
|
-
"globals": "^17.
|
|
41
|
+
"globals": "^17.14.0",
|
|
42
42
|
"ts-builds": "^4.5.0",
|
|
43
|
-
"tsdown": "^0.23.
|
|
43
|
+
"tsdown": "^0.23.7",
|
|
44
44
|
"tsx": "^4.23.15",
|
|
45
45
|
"typedoc": "^0.28.20",
|
|
46
46
|
"typescript": "^6.0.3"
|
|
@@ -113,11 +113,6 @@
|
|
|
113
113
|
"import": "./dist/invariant/index.js",
|
|
114
114
|
"default": "./dist/invariant/index.js"
|
|
115
115
|
},
|
|
116
|
-
"./task": {
|
|
117
|
-
"types": "./dist/core/task/index.d.ts",
|
|
118
|
-
"import": "./dist/core/task/index.js",
|
|
119
|
-
"default": "./dist/core/task/index.js"
|
|
120
|
-
},
|
|
121
116
|
"./io": {
|
|
122
117
|
"types": "./dist/io/index.d.ts",
|
|
123
118
|
"import": "./dist/io/index.js",
|
|
@@ -214,7 +209,7 @@
|
|
|
214
209
|
"docs:watch": "typedoc --watch",
|
|
215
210
|
"docs:sync": "tsx scripts/sync-docs.ts",
|
|
216
211
|
"docs:validate": "ts-builds docs:validate",
|
|
217
|
-
"
|
|
212
|
+
"size:check": "ts-builds size:check",
|
|
218
213
|
"cli-example": "npx . Option"
|
|
219
214
|
}
|
|
220
215
|
}
|
package/dist/Brand-bfnGXuum.d.ts
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
//#region src/branded/Brand.d.ts
|
|
2
|
-
type Brand<K extends string, T> = T & {
|
|
3
|
-
readonly __brand: K;
|
|
4
|
-
};
|
|
5
|
-
type Unwrap<T> = T extends Brand<string, infer U> ? U : T;
|
|
6
|
-
type ExtractBrand<T> = T extends Brand<infer K, unknown> ? K : never;
|
|
7
|
-
/**
|
|
8
|
-
* Brand is a utility for creating nominal typing in TypeScript.
|
|
9
|
-
* It creates phantom types that exist only at compile time.
|
|
10
|
-
* At runtime, the branded value IS the primitive value.
|
|
11
|
-
*
|
|
12
|
-
* @param _brand
|
|
13
|
-
* @param value - The value to brand
|
|
14
|
-
* @returns The value with phantom type brand
|
|
15
|
-
*/
|
|
16
|
-
declare function Brand<K extends string, T>(_brand: K, value: T): Brand<K, T>;
|
|
17
|
-
/**
|
|
18
|
-
* Helper to unwrap a branded value to its underlying type
|
|
19
|
-
* Works with both Brand and ValidatedBrand
|
|
20
|
-
* @param branded - The branded value (can be null or undefined)
|
|
21
|
-
* @returns The original value without the brand
|
|
22
|
-
*
|
|
23
|
-
* Note: Also exported as 'unwrap' from 'functype/branded' for convenience
|
|
24
|
-
*/
|
|
25
|
-
declare function unwrapBrand<K extends string, T>(branded: Brand<K, T>): T;
|
|
26
|
-
declare function unwrapBrand<K extends string, T>(branded: Brand<K, T> | null): T | null;
|
|
27
|
-
declare function unwrapBrand<K extends string, T>(branded: Brand<K, T> | undefined): T | undefined;
|
|
28
|
-
declare function unwrapBrand<K extends string, T>(branded: Brand<K, T> | null | undefined): T | null | undefined;
|
|
29
|
-
/**
|
|
30
|
-
* Type guard for checking if a value has a specific brand
|
|
31
|
-
* @param value - The value to check
|
|
32
|
-
* @param _brand - The brand to check for (unused at runtime)
|
|
33
|
-
* @returns True if the value has the specified brand
|
|
34
|
-
*
|
|
35
|
-
* Note: Since brands are phantom types that exist only at compile time,
|
|
36
|
-
* this function can only provide a runtime approximation. It always returns true
|
|
37
|
-
* for non-null values, as we have no way to actually check the brand at runtime.
|
|
38
|
-
* This function is primarily for API consistency and documentation purposes.
|
|
39
|
-
*/
|
|
40
|
-
declare function hasBrand<K extends string, T>(value: unknown, _brand: K): value is Brand<K, T>;
|
|
41
|
-
/**
|
|
42
|
-
* Create a branded type constructor for a specific brand
|
|
43
|
-
* @param brand - The brand name
|
|
44
|
-
* @returns A function that brands values with the specified brand
|
|
45
|
-
*/
|
|
46
|
-
declare function createBrander<K extends string, T>(brand: K): (value: T) => Brand<K, T>;
|
|
47
|
-
type BrandedString<K extends string> = Brand<K, string>;
|
|
48
|
-
type BrandedNumber<K extends string> = Brand<K, number>;
|
|
49
|
-
type BrandedBoolean<K extends string> = Brand<K, boolean>;
|
|
50
|
-
declare const BrandedString: <K extends string>(brand: K) => (value: string) => BrandedString<K>;
|
|
51
|
-
declare const BrandedNumber: <K extends string>(brand: K) => (value: number) => BrandedNumber<K>;
|
|
52
|
-
declare const BrandedBoolean: <K extends string>(brand: K) => (value: boolean) => BrandedBoolean<K>;
|
|
53
|
-
//#endregion
|
|
54
|
-
export { ExtractBrand as a, hasBrand as c, BrandedString as i, unwrapBrand as l, BrandedBoolean as n, Unwrap as o, BrandedNumber as r, createBrander as s, Brand as t };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{mergeObjects as e}from"./util/index.js";function t(t,n){return e(t,n)}export{t};
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
//#region src/companion/Companion.d.ts
|
|
2
|
-
/**
|
|
3
|
-
* Creates a function-object hybrid similar to Scala's companion objects.
|
|
4
|
-
* This utility allows creating TypeScript function objects with attached methods,
|
|
5
|
-
* mimicking Scala's class + companion object pattern without using classes.
|
|
6
|
-
*
|
|
7
|
-
* @param object The main function that will be invoked when the object is called
|
|
8
|
-
* @param companion Additional static methods to attach to the function
|
|
9
|
-
* @returns A function with the attached methods
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* const greet = (name: string) => `Hello, ${name}!`;
|
|
13
|
-
* const methods = {
|
|
14
|
-
* formal: (name: string) => `Good day, ${name}.`,
|
|
15
|
-
* casual: (name: string) => `Hey ${name}!`
|
|
16
|
-
* };
|
|
17
|
-
* const Greeter = createCompanionObject(greet, methods);
|
|
18
|
-
*
|
|
19
|
-
* // Usage:
|
|
20
|
-
* Greeter("World"); // Hello, World!
|
|
21
|
-
* Greeter.formal("Sir"); // Good day, Sir.
|
|
22
|
-
* Greeter.casual("Friend"); // Hey Friend!
|
|
23
|
-
*/
|
|
24
|
-
declare function Companion<ObjectF extends object, CompanionF extends object>(object: ObjectF, companion: CompanionF): ObjectF & CompanionF;
|
|
25
|
-
//#endregion
|
|
26
|
-
//#region src/companion/CompanionTypes.d.ts
|
|
27
|
-
/**
|
|
28
|
-
* Helper types for working with the Companion pattern
|
|
29
|
-
* @module CompanionTypes
|
|
30
|
-
*/
|
|
31
|
-
/**
|
|
32
|
-
* Extracts the companion methods type from a Companion object
|
|
33
|
-
* @typeParam T - The Companion type
|
|
34
|
-
* @example
|
|
35
|
-
* ```typescript
|
|
36
|
-
* type OptionCompanionMethods = CompanionMethods<typeof Option>
|
|
37
|
-
* // { from: ..., none: ..., fromJSON: ..., etc. }
|
|
38
|
-
* ```
|
|
39
|
-
*/
|
|
40
|
-
type CompanionMethods<T> = T extends ((...args: never[]) => unknown) & (infer C) ? C : never;
|
|
41
|
-
/**
|
|
42
|
-
* Extracts the instance type from a constructor function
|
|
43
|
-
* @typeParam T - The constructor function type
|
|
44
|
-
* @example
|
|
45
|
-
* ```typescript
|
|
46
|
-
* type OptionInstance = InstanceType<typeof Option>
|
|
47
|
-
* // Option<T>
|
|
48
|
-
* ```
|
|
49
|
-
*/
|
|
50
|
-
type InstanceType<T> = T extends ((...args: infer Args) => infer R) ? R extends ((...args: unknown[]) => unknown) ? ReturnType<R> : R : never;
|
|
51
|
-
/**
|
|
52
|
-
* Type guard to check if a value is a Companion object (has both constructor and companion methods)
|
|
53
|
-
* @param value - The value to check
|
|
54
|
-
* @returns True if value is a Companion object
|
|
55
|
-
*/
|
|
56
|
-
declare const isCompanion: (value: unknown) => value is ((...args: never[]) => unknown) & Record<string, unknown>;
|
|
57
|
-
//#endregion
|
|
58
|
-
export { Companion as i, InstanceType as n, isCompanion as r, CompanionMethods as t };
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
//#region src/invariant/Invariant.d.ts
|
|
2
|
-
/**
|
|
3
|
-
* The error `invariant()` throws: a programmer error, never an expected failure. Tagged so a top-level
|
|
4
|
-
* handler can tell "a bug fired" apart from a failure that should have been an `Either`.
|
|
5
|
-
*/
|
|
6
|
-
type InvariantViolation = Error & {
|
|
7
|
-
readonly name: "InvariantViolation";
|
|
8
|
-
readonly _tag: "InvariantViolation";
|
|
9
|
-
};
|
|
10
|
-
/**
|
|
11
|
-
* Builds an {@link InvariantViolation}. Use it directly where a branch can only be reached by a bug and
|
|
12
|
-
* there is no condition to assert, e.g. `throw InvariantViolation("unreachable: unknown variant")`.
|
|
13
|
-
*/
|
|
14
|
-
declare const InvariantViolation: (message: string) => InvariantViolation;
|
|
15
|
-
/**
|
|
16
|
-
* Asserts a condition that can only be false because of a bug, and narrows it for the code after it.
|
|
17
|
-
*
|
|
18
|
-
* Expected failures return `Either`; `invariant` is for the other kind — "upsert returned no row",
|
|
19
|
-
* "step must be non-negative", "AUTH_PROVIDER is required in production". It covers one statement, so a
|
|
20
|
-
* function can mix bug checks with `Either`-returning failure paths, and `functype/prefer-either` never
|
|
21
|
-
* sees a `throw` to report.
|
|
22
|
-
*
|
|
23
|
-
* ```ts
|
|
24
|
-
* invariant(row, "upsert returned no row") // row: Row from here on
|
|
25
|
-
* invariant(teamDomain && aud, "requires CF_ACCESS_TEAM_DOMAIN and CF_ACCESS_AUD")
|
|
26
|
-
* invariant(n >= 0, () => `step must be non-negative, got ${n}`) // message built only on failure
|
|
27
|
-
* ```
|
|
28
|
-
*
|
|
29
|
-
* @param condition - Must be truthy. Narrowed to truthy after the call.
|
|
30
|
-
* @param message - The error message, or a thunk that builds it only when the check fails.
|
|
31
|
-
* @throws {@link InvariantViolation} when `condition` is falsy.
|
|
32
|
-
*/
|
|
33
|
-
declare function invariant(condition: unknown, message: string | (() => string)): asserts condition;
|
|
34
|
-
//#endregion
|
|
35
|
-
export { invariant as n, InvariantViolation as t };
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
//#region src/logger/Logger.d.ts
|
|
2
|
-
/**
|
|
3
|
-
* Minimal Logger interface for the functype ecosystem.
|
|
4
|
-
*
|
|
5
|
-
* One shared contract every present and future sibling package can reference
|
|
6
|
-
* without inventing its own ad-hoc logger interface. Type-only — no runtime,
|
|
7
|
-
* no opinion on output format, no `console`-global dependency. Default impls
|
|
8
|
-
* live in consumer packages (e.g. `consoleBootLogger` in `functype-os/config`).
|
|
9
|
-
*
|
|
10
|
-
* Four methods, all mandatory: `debug`, `info`, `warn`, `error`. Mandatory
|
|
11
|
-
* means no defensive `logger.debug?.()` checks at call sites.
|
|
12
|
-
*
|
|
13
|
-
* Richer loggers — `DirectLogger` from `functype-log/direct` for example —
|
|
14
|
-
* structurally satisfy `Logger` because their `debug/info/warn/error(msg, meta?)`
|
|
15
|
-
* signatures are a superset. Pass them directly anywhere a `Logger` is
|
|
16
|
-
* expected; no adapter required.
|
|
17
|
-
*
|
|
18
|
-
* @category Logger
|
|
19
|
-
*/
|
|
20
|
-
interface Logger {
|
|
21
|
-
debug(message: string, metadata?: Record<string, unknown>): void;
|
|
22
|
-
info(message: string, metadata?: Record<string, unknown>): void;
|
|
23
|
-
warn(message: string, metadata?: Record<string, unknown>): void;
|
|
24
|
-
error(message: string, metadata?: Record<string, unknown>): void;
|
|
25
|
-
}
|
|
26
|
-
//#endregion
|
|
27
|
-
export { Logger as t };
|