effect 4.0.0-beta.27 → 4.0.0-beta.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Brand.d.ts +1 -1
- package/dist/Brand.d.ts.map +1 -1
- package/dist/Brand.js +1 -1
- package/dist/Brand.js.map +1 -1
- package/dist/ConfigProvider.d.ts +1 -1
- package/dist/Cron.d.ts +1 -1
- package/dist/Data.d.ts +1 -1
- package/dist/Data.d.ts.map +1 -1
- package/dist/Data.js.map +1 -1
- package/dist/Effect.d.ts +300 -184
- package/dist/Effect.d.ts.map +1 -1
- package/dist/Effect.js +99 -61
- package/dist/Effect.js.map +1 -1
- package/dist/Encoding.d.ts +1 -1
- package/dist/Exit.d.ts +24 -12
- package/dist/Exit.d.ts.map +1 -1
- package/dist/Exit.js +8 -4
- package/dist/Exit.js.map +1 -1
- package/dist/Fiber.d.ts +1 -0
- package/dist/Fiber.d.ts.map +1 -1
- package/dist/Fiber.js.map +1 -1
- package/dist/Function.d.ts +1 -9
- package/dist/Function.d.ts.map +1 -1
- package/dist/Function.js +2 -10
- package/dist/Function.js.map +1 -1
- package/dist/Graph.d.ts +1 -1
- package/dist/Newtype.d.ts +291 -0
- package/dist/Newtype.d.ts.map +1 -0
- package/dist/Newtype.js +161 -0
- package/dist/Newtype.js.map +1 -0
- package/dist/PlatformError.d.ts +2 -2
- package/dist/References.d.ts +6 -1
- package/dist/References.d.ts.map +1 -1
- package/dist/References.js +6 -1
- package/dist/References.js.map +1 -1
- package/dist/RequestResolver.d.ts +19 -19
- package/dist/RequestResolver.js +10 -10
- package/dist/RequestResolver.js.map +1 -1
- package/dist/Schedule.d.ts +142 -80
- package/dist/Schedule.d.ts.map +1 -1
- package/dist/Schedule.js +58 -32
- package/dist/Schedule.js.map +1 -1
- package/dist/Scheduler.d.ts +9 -0
- package/dist/Scheduler.d.ts.map +1 -1
- package/dist/Scheduler.js +11 -0
- package/dist/Scheduler.js.map +1 -1
- package/dist/Schema.d.ts +1 -1
- package/dist/Schema.d.ts.map +1 -1
- package/dist/Schema.js +3 -1
- package/dist/Schema.js.map +1 -1
- package/dist/SchemaAST.d.ts.map +1 -1
- package/dist/SchemaAST.js +1 -1
- package/dist/SchemaAST.js.map +1 -1
- package/dist/Stdio.d.ts +6 -2
- package/dist/Stdio.d.ts.map +1 -1
- package/dist/Stdio.js +2 -2
- package/dist/Stdio.js.map +1 -1
- package/dist/Stream.d.ts +8 -4
- package/dist/Stream.d.ts.map +1 -1
- package/dist/Stream.js +8 -4
- package/dist/Stream.js.map +1 -1
- package/dist/Types.d.ts +1 -22
- package/dist/Types.d.ts.map +1 -1
- package/dist/index.d.ts +71 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +71 -3
- package/dist/index.js.map +1 -1
- package/dist/internal/effect.js +3 -1
- package/dist/internal/effect.js.map +1 -1
- package/dist/unstable/ai/LanguageModel.d.ts +12 -28
- package/dist/unstable/ai/LanguageModel.d.ts.map +1 -1
- package/dist/unstable/ai/LanguageModel.js +4 -18
- package/dist/unstable/ai/LanguageModel.js.map +1 -1
- package/dist/unstable/ai/McpSchema.d.ts +20 -1
- package/dist/unstable/ai/McpSchema.d.ts.map +1 -1
- package/dist/unstable/ai/McpSchema.js +8 -0
- package/dist/unstable/ai/McpSchema.js.map +1 -1
- package/dist/unstable/ai/McpServer.d.ts +65 -12
- package/dist/unstable/ai/McpServer.d.ts.map +1 -1
- package/dist/unstable/ai/McpServer.js +159 -45
- package/dist/unstable/ai/McpServer.js.map +1 -1
- package/dist/unstable/ai/Toolkit.d.ts +1 -1
- package/dist/unstable/ai/Toolkit.d.ts.map +1 -1
- package/dist/unstable/ai/Toolkit.js +4 -11
- package/dist/unstable/ai/Toolkit.js.map +1 -1
- package/dist/unstable/ai/internal/codec-transformer.js +0 -5
- package/dist/unstable/ai/internal/codec-transformer.js.map +1 -1
- package/dist/unstable/cli/Prompt.js +35 -8
- package/dist/unstable/cli/Prompt.js.map +1 -1
- package/dist/unstable/cluster/Message.d.ts +5 -5
- package/dist/unstable/cluster/Reply.d.ts +3 -3
- package/dist/unstable/encoding/Msgpack.d.ts +1 -1
- package/dist/unstable/encoding/Ndjson.d.ts +1 -1
- package/dist/unstable/encoding/Sse.d.ts +1 -1
- package/dist/unstable/eventlog/EventJournal.d.ts +1 -1
- package/dist/unstable/eventlog/EventLogRemote.d.ts +1 -1
- package/dist/unstable/http/Cookies.d.ts +45 -1
- package/dist/unstable/http/Cookies.d.ts.map +1 -1
- package/dist/unstable/http/Cookies.js +22 -0
- package/dist/unstable/http/Cookies.js.map +1 -1
- package/dist/unstable/http/HttpBody.d.ts +1 -1
- package/dist/unstable/http/HttpClient.d.ts.map +1 -1
- package/dist/unstable/http/HttpClient.js +3 -7
- package/dist/unstable/http/HttpClient.js.map +1 -1
- package/dist/unstable/http/HttpClientError.d.ts +7 -7
- package/dist/unstable/http/HttpClientRequest.d.ts +5 -0
- package/dist/unstable/http/HttpClientRequest.d.ts.map +1 -1
- package/dist/unstable/http/HttpClientRequest.js +21 -17
- package/dist/unstable/http/HttpClientRequest.js.map +1 -1
- package/dist/unstable/http/HttpEffect.d.ts +7 -0
- package/dist/unstable/http/HttpEffect.d.ts.map +1 -1
- package/dist/unstable/http/HttpEffect.js +6 -0
- package/dist/unstable/http/HttpEffect.js.map +1 -1
- package/dist/unstable/http/HttpServerError.d.ts +6 -6
- package/dist/unstable/http/HttpServerRequest.d.ts +11 -0
- package/dist/unstable/http/HttpServerRequest.d.ts.map +1 -1
- package/dist/unstable/http/HttpServerRequest.js +291 -1
- package/dist/unstable/http/HttpServerRequest.js.map +1 -1
- package/dist/unstable/http/HttpServerResponse.d.ts +47 -1
- package/dist/unstable/http/HttpServerResponse.d.ts.map +1 -1
- package/dist/unstable/http/HttpServerResponse.js +227 -0
- package/dist/unstable/http/HttpServerResponse.js.map +1 -1
- package/dist/unstable/http/HttpStaticServer.d.ts +69 -0
- package/dist/unstable/http/HttpStaticServer.d.ts.map +1 -0
- package/dist/unstable/http/HttpStaticServer.js +353 -0
- package/dist/unstable/http/HttpStaticServer.js.map +1 -0
- package/dist/unstable/http/Multipart.d.ts +1 -1
- package/dist/unstable/http/UrlParams.d.ts +1 -1
- package/dist/unstable/http/index.d.ts +4 -0
- package/dist/unstable/http/index.d.ts.map +1 -1
- package/dist/unstable/http/index.js +4 -0
- package/dist/unstable/http/index.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiGroup.d.ts +1 -0
- package/dist/unstable/httpapi/HttpApiGroup.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiGroup.js.map +1 -1
- package/dist/unstable/persistence/KeyValueStore.d.ts +1 -1
- package/dist/unstable/reactivity/Atom.d.ts +7 -2
- package/dist/unstable/reactivity/Atom.d.ts.map +1 -1
- package/dist/unstable/reactivity/Atom.js +33 -15
- package/dist/unstable/reactivity/Atom.js.map +1 -1
- package/dist/unstable/reactivity/AtomHttpApi.d.ts +4 -6
- package/dist/unstable/reactivity/AtomHttpApi.d.ts.map +1 -1
- package/dist/unstable/reactivity/AtomHttpApi.js +39 -9
- package/dist/unstable/reactivity/AtomHttpApi.js.map +1 -1
- package/dist/unstable/reactivity/AtomRegistry.js +26 -2
- package/dist/unstable/reactivity/AtomRegistry.js.map +1 -1
- package/dist/unstable/reactivity/AtomRpc.d.ts +8 -8
- package/dist/unstable/reactivity/AtomRpc.d.ts.map +1 -1
- package/dist/unstable/reactivity/AtomRpc.js +46 -20
- package/dist/unstable/reactivity/AtomRpc.js.map +1 -1
- package/dist/unstable/rpc/Rpc.d.ts +1 -1
- package/dist/unstable/rpc/Rpc.d.ts.map +1 -1
- package/dist/unstable/rpc/Rpc.js.map +1 -1
- package/dist/unstable/rpc/RpcMiddleware.d.ts +5 -5
- package/dist/unstable/rpc/RpcMiddleware.d.ts.map +1 -1
- package/dist/unstable/rpc/RpcMiddleware.js.map +1 -1
- package/dist/unstable/rpc/RpcServer.js +2 -2
- package/dist/unstable/rpc/RpcServer.js.map +1 -1
- package/dist/unstable/rpc/Utils.js +1 -1
- package/dist/unstable/rpc/Utils.js.map +1 -1
- package/dist/unstable/socket/SocketServer.d.ts +3 -3
- package/dist/unstable/sql/Migrator.d.ts +1 -1
- package/dist/unstable/sql/SqlResolver.js +2 -2
- package/dist/unstable/sql/SqlResolver.js.map +1 -1
- package/dist/unstable/workflow/Workflow.d.ts +1 -1
- package/package.json +1 -1
- package/src/Brand.ts +1 -1
- package/src/Data.ts +1 -2
- package/src/Effect.ts +300 -184
- package/src/Exit.ts +24 -12
- package/src/Fiber.ts +1 -0
- package/src/Function.ts +2 -10
- package/src/Newtype.ts +308 -0
- package/src/References.ts +6 -1
- package/src/RequestResolver.ts +20 -20
- package/src/Schedule.ts +142 -80
- package/src/Scheduler.ts +12 -0
- package/src/Schema.ts +4 -2
- package/src/SchemaAST.ts +1 -4
- package/src/Stdio.ts +8 -4
- package/src/Stream.ts +8 -4
- package/src/Types.ts +1 -23
- package/src/index.ts +72 -3
- package/src/internal/effect.ts +3 -0
- package/src/unstable/ai/LanguageModel.ts +16 -37
- package/src/unstable/ai/McpSchema.ts +14 -0
- package/src/unstable/ai/McpServer.ts +224 -53
- package/src/unstable/ai/Toolkit.ts +5 -14
- package/src/unstable/ai/internal/codec-transformer.ts +0 -7
- package/src/unstable/cli/Prompt.ts +31 -9
- package/src/unstable/http/Cookies.ts +84 -0
- package/src/unstable/http/HttpClient.ts +5 -6
- package/src/unstable/http/HttpClientRequest.ts +21 -17
- package/src/unstable/http/HttpEffect.ts +8 -0
- package/src/unstable/http/HttpServerRequest.ts +388 -1
- package/src/unstable/http/HttpServerResponse.ts +328 -1
- package/src/unstable/http/HttpStaticServer.ts +456 -0
- package/src/unstable/http/index.ts +5 -0
- package/src/unstable/httpapi/HttpApiGroup.ts +1 -0
- package/src/unstable/reactivity/Atom.ts +62 -35
- package/src/unstable/reactivity/AtomHttpApi.ts +45 -11
- package/src/unstable/reactivity/AtomRegistry.ts +30 -2
- package/src/unstable/reactivity/AtomRpc.ts +48 -17
- package/src/unstable/rpc/Rpc.ts +1 -3
- package/src/unstable/rpc/RpcMiddleware.ts +12 -6
- package/src/unstable/rpc/RpcServer.ts +2 -2
- package/src/unstable/rpc/Utils.ts +1 -1
- package/src/unstable/sql/SqlResolver.ts +2 -2
package/src/Exit.ts
CHANGED
|
@@ -857,10 +857,12 @@ export const map: {
|
|
|
857
857
|
* **Example** (Mapping over an error)
|
|
858
858
|
*
|
|
859
859
|
* ```ts
|
|
860
|
-
* import { Exit } from "effect"
|
|
860
|
+
* import { Data, Exit } from "effect"
|
|
861
|
+
*
|
|
862
|
+
* class ExitError extends Data.TaggedError("ExitError")<{ readonly input: string }> {}
|
|
861
863
|
*
|
|
862
864
|
* const exit = Exit.fail("bad input")
|
|
863
|
-
* const mapped = Exit.mapError(exit, (e) => new
|
|
865
|
+
* const mapped = Exit.mapError(exit, (e) => new ExitError({ input: e }))
|
|
864
866
|
* console.log(Exit.isFailure(mapped)) // true
|
|
865
867
|
* ```
|
|
866
868
|
*
|
|
@@ -884,10 +886,12 @@ export const mapError: {
|
|
|
884
886
|
* **Example** (Mapping over an error)
|
|
885
887
|
*
|
|
886
888
|
* ```ts
|
|
887
|
-
* import { Exit } from "effect"
|
|
889
|
+
* import { Data, Exit } from "effect"
|
|
890
|
+
*
|
|
891
|
+
* class ExitError extends Data.TaggedError("ExitError")<{ readonly input: string }> {}
|
|
888
892
|
*
|
|
889
893
|
* const exit = Exit.fail("bad input")
|
|
890
|
-
* const mapped = Exit.mapError(exit, (e) => new
|
|
894
|
+
* const mapped = Exit.mapError(exit, (e) => new ExitError({ input: e }))
|
|
891
895
|
* console.log(Exit.isFailure(mapped)) // true
|
|
892
896
|
* ```
|
|
893
897
|
*
|
|
@@ -911,10 +915,12 @@ export const mapError: {
|
|
|
911
915
|
* **Example** (Mapping over an error)
|
|
912
916
|
*
|
|
913
917
|
* ```ts
|
|
914
|
-
* import { Exit } from "effect"
|
|
918
|
+
* import { Data, Exit } from "effect"
|
|
919
|
+
*
|
|
920
|
+
* class ExitError extends Data.TaggedError("ExitError")<{ readonly input: string }> {}
|
|
915
921
|
*
|
|
916
922
|
* const exit = Exit.fail("bad input")
|
|
917
|
-
* const mapped = Exit.mapError(exit, (e) => new
|
|
923
|
+
* const mapped = Exit.mapError(exit, (e) => new ExitError({ input: e }))
|
|
918
924
|
* console.log(Exit.isFailure(mapped)) // true
|
|
919
925
|
* ```
|
|
920
926
|
*
|
|
@@ -941,12 +947,14 @@ export const mapError: {
|
|
|
941
947
|
* **Example** (Mapping both channels)
|
|
942
948
|
*
|
|
943
949
|
* ```ts
|
|
944
|
-
* import { Exit } from "effect"
|
|
950
|
+
* import { Data, Exit } from "effect"
|
|
951
|
+
*
|
|
952
|
+
* class ExitError extends Data.TaggedError("ExitError")<{ readonly input: string }> {}
|
|
945
953
|
*
|
|
946
954
|
* const exit = Exit.succeed(42)
|
|
947
955
|
* const mapped = Exit.mapBoth(exit, {
|
|
948
956
|
* onSuccess: (x) => String(x),
|
|
949
|
-
* onFailure: (e: string) => new
|
|
957
|
+
* onFailure: (e: string) => new ExitError({ input: e })
|
|
950
958
|
* })
|
|
951
959
|
* console.log(Exit.isSuccess(mapped) && mapped.value) // "42"
|
|
952
960
|
* ```
|
|
@@ -972,12 +980,14 @@ export const mapBoth: {
|
|
|
972
980
|
* **Example** (Mapping both channels)
|
|
973
981
|
*
|
|
974
982
|
* ```ts
|
|
975
|
-
* import { Exit } from "effect"
|
|
983
|
+
* import { Data, Exit } from "effect"
|
|
984
|
+
*
|
|
985
|
+
* class ExitError extends Data.TaggedError("ExitError")<{ readonly input: string }> {}
|
|
976
986
|
*
|
|
977
987
|
* const exit = Exit.succeed(42)
|
|
978
988
|
* const mapped = Exit.mapBoth(exit, {
|
|
979
989
|
* onSuccess: (x) => String(x),
|
|
980
|
-
* onFailure: (e: string) => new
|
|
990
|
+
* onFailure: (e: string) => new ExitError({ input: e })
|
|
981
991
|
* })
|
|
982
992
|
* console.log(Exit.isSuccess(mapped) && mapped.value) // "42"
|
|
983
993
|
* ```
|
|
@@ -1005,12 +1015,14 @@ export const mapBoth: {
|
|
|
1005
1015
|
* **Example** (Mapping both channels)
|
|
1006
1016
|
*
|
|
1007
1017
|
* ```ts
|
|
1008
|
-
* import { Exit } from "effect"
|
|
1018
|
+
* import { Data, Exit } from "effect"
|
|
1019
|
+
*
|
|
1020
|
+
* class ExitError extends Data.TaggedError("ExitError")<{ readonly input: string }> {}
|
|
1009
1021
|
*
|
|
1010
1022
|
* const exit = Exit.succeed(42)
|
|
1011
1023
|
* const mapped = Exit.mapBoth(exit, {
|
|
1012
1024
|
* onSuccess: (x) => String(x),
|
|
1013
|
-
* onFailure: (e: string) => new
|
|
1025
|
+
* onFailure: (e: string) => new ExitError({ input: e })
|
|
1014
1026
|
* })
|
|
1015
1027
|
* console.log(Exit.isSuccess(mapped) && mapped.value) // "42"
|
|
1016
1028
|
* ```
|
package/src/Fiber.ts
CHANGED
|
@@ -128,6 +128,7 @@ export interface Fiber<out A, out E = never> extends Pipeable {
|
|
|
128
128
|
readonly minimumLogLevel: LogLevel
|
|
129
129
|
readonly currentStackFrame?: StackFrame | undefined
|
|
130
130
|
readonly maxOpsBeforeYield: number
|
|
131
|
+
readonly currentPreventYield: boolean
|
|
131
132
|
readonly addObserver: (cb: (exit: Exit<A, E>) => void) => () => void
|
|
132
133
|
readonly interruptUnsafe: (
|
|
133
134
|
fiberId?: number | undefined,
|
package/src/Function.ts
CHANGED
|
@@ -402,18 +402,10 @@ export const satisfies = <A>() => <B extends A>(b: B) => b
|
|
|
402
402
|
/**
|
|
403
403
|
* Casts the result to the specified type.
|
|
404
404
|
*
|
|
405
|
-
* @example
|
|
406
|
-
* ```ts
|
|
407
|
-
* import { coerceUnsafe, identity } from "effect/Function"
|
|
408
|
-
* import * as assert from "node:assert"
|
|
409
|
-
*
|
|
410
|
-
* assert.deepStrictEqual(coerceUnsafe, identity)
|
|
411
|
-
* ```
|
|
412
|
-
*
|
|
413
405
|
* @category type utils
|
|
414
406
|
* @since 2.0.0
|
|
415
407
|
*/
|
|
416
|
-
export const
|
|
408
|
+
export const cast: <A, B>(a: A) => B = identity as any
|
|
417
409
|
|
|
418
410
|
/**
|
|
419
411
|
* Creates a constant value that never changes.
|
|
@@ -1392,7 +1384,7 @@ export function flow(
|
|
|
1392
1384
|
* @category utilities
|
|
1393
1385
|
* @since 2.0.0
|
|
1394
1386
|
*/
|
|
1395
|
-
export const hole: <T>() => T =
|
|
1387
|
+
export const hole: <T>() => T = cast(absurd)
|
|
1396
1388
|
|
|
1397
1389
|
/**
|
|
1398
1390
|
* The SK combinator, also known as the "S-K combinator" or "S-combinator", is a fundamental combinator in the
|
package/src/Newtype.ts
ADDED
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lightweight wrapper types that prevent accidental mixing of structurally
|
|
3
|
+
* identical values (e.g. `UserId` vs `OrderId`, both `string` at runtime).
|
|
4
|
+
*
|
|
5
|
+
* **Mental model**
|
|
6
|
+
*
|
|
7
|
+
* - **Newtype** — a compile-time wrapper around a **carrier** type (the
|
|
8
|
+
* underlying primitive or object). At runtime the value is unchanged; the
|
|
9
|
+
* tag exists only in the type system.
|
|
10
|
+
* - **Key** — a unique string literal that distinguishes one newtype from
|
|
11
|
+
* another (e.g. `"Label"`, `"UserId"`).
|
|
12
|
+
* - **Carrier** — the underlying type the newtype wraps (e.g. `string`,
|
|
13
|
+
* `number`).
|
|
14
|
+
* - **Iso** — a lossless two-way conversion between a newtype and its carrier,
|
|
15
|
+
* created with {@link makeIso}. Use `iso.set(carrier)` to wrap and
|
|
16
|
+
* `iso.get(newtype)` to unwrap.
|
|
17
|
+
*
|
|
18
|
+
* **Common tasks**
|
|
19
|
+
*
|
|
20
|
+
* - Define a newtype → declare an `interface` extending
|
|
21
|
+
* `Newtype.Newtype<Key, Carrier>`
|
|
22
|
+
* - Wrap / unwrap values → {@link makeIso} (returns an `Optic.Iso`)
|
|
23
|
+
* - Unwrap only → {@link value}
|
|
24
|
+
* - Lift an `Equivalence` → {@link makeEquivalence}
|
|
25
|
+
* - Lift an `Order` → {@link makeOrder}
|
|
26
|
+
* - Lift a `Combiner` → {@link makeCombiner}
|
|
27
|
+
* - Lift a `Reducer` → {@link makeReducer}
|
|
28
|
+
*
|
|
29
|
+
* **Gotchas**
|
|
30
|
+
*
|
|
31
|
+
* - Newtypes are **purely compile-time**. There is zero runtime overhead;
|
|
32
|
+
* `value` and `makeIso` use identity casts.
|
|
33
|
+
* - Two newtypes sharing the same key string will be assignable to each other.
|
|
34
|
+
* Choose unique key strings.
|
|
35
|
+
* - A newtype value is **not** assignable to its carrier type without
|
|
36
|
+
* explicitly unwrapping via {@link value} or an iso.
|
|
37
|
+
*
|
|
38
|
+
* **Quickstart**
|
|
39
|
+
*
|
|
40
|
+
* **Example** (defining and using a newtype)
|
|
41
|
+
*
|
|
42
|
+
* ```ts
|
|
43
|
+
* import { Newtype } from "effect"
|
|
44
|
+
*
|
|
45
|
+
* // 1. Define a newtype
|
|
46
|
+
* interface Label extends Newtype.Newtype<"Label", string> {}
|
|
47
|
+
*
|
|
48
|
+
* // 2. Create an iso for wrapping/unwrapping
|
|
49
|
+
* const labelIso = Newtype.makeIso<Label>()
|
|
50
|
+
*
|
|
51
|
+
* // 3. Wrap a raw string
|
|
52
|
+
* const myLabel: Label = labelIso.set("hello")
|
|
53
|
+
*
|
|
54
|
+
* // 4. Unwrap back to string
|
|
55
|
+
* const raw: string = labelIso.get(myLabel) // "hello"
|
|
56
|
+
* ```
|
|
57
|
+
*
|
|
58
|
+
* **See also**
|
|
59
|
+
*
|
|
60
|
+
* - {@link Newtype} (the tagged interface)
|
|
61
|
+
* - {@link makeIso} (wrap and unwrap)
|
|
62
|
+
* - {@link value} (unwrap only)
|
|
63
|
+
*
|
|
64
|
+
* @since 4.0.0
|
|
65
|
+
*/
|
|
66
|
+
import type * as Combiner from "./Combiner.ts"
|
|
67
|
+
import type * as Equivalence from "./Equivalence.ts"
|
|
68
|
+
import { cast } from "./Function.ts"
|
|
69
|
+
import * as Optic from "./Optic.ts"
|
|
70
|
+
import type * as Order from "./Order.ts"
|
|
71
|
+
import type * as Reducer from "./Reducer.ts"
|
|
72
|
+
|
|
73
|
+
const TypeId = "~effect/Newtype"
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* A tagged interface that wraps a carrier type under a unique key, preventing
|
|
77
|
+
* accidental interchange of structurally identical values.
|
|
78
|
+
*
|
|
79
|
+
* - Define your newtype as an `interface` extending
|
|
80
|
+
* `Newtype<"MyKey", CarrierType>`.
|
|
81
|
+
* - The tag is compile-time only; no runtime wrapper is allocated.
|
|
82
|
+
* - Use {@link makeIso} to create a two-way conversion, or {@link value} to
|
|
83
|
+
* unwrap.
|
|
84
|
+
*
|
|
85
|
+
* **Example** (defining a newtype)
|
|
86
|
+
*
|
|
87
|
+
* ```ts
|
|
88
|
+
* import { Newtype } from "effect"
|
|
89
|
+
*
|
|
90
|
+
* interface UserId extends Newtype.Newtype<"UserId", number> {}
|
|
91
|
+
* interface OrderId extends Newtype.Newtype<"OrderId", number> {}
|
|
92
|
+
*
|
|
93
|
+
* // UserId and OrderId are not assignable to each other
|
|
94
|
+
* // even though both wrap `number`.
|
|
95
|
+
* ```
|
|
96
|
+
*
|
|
97
|
+
* @see {@link makeIso} — create an iso to wrap and unwrap
|
|
98
|
+
* @see {@link value} — unwrap a newtype value
|
|
99
|
+
*
|
|
100
|
+
* @since 4.0.0
|
|
101
|
+
*/
|
|
102
|
+
export interface Newtype<in out Key extends string, out Carrier> {
|
|
103
|
+
readonly [TypeId]: {
|
|
104
|
+
readonly key: Key
|
|
105
|
+
readonly carrier: Carrier
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* @since 4.0.0
|
|
111
|
+
*/
|
|
112
|
+
export declare namespace Newtype {
|
|
113
|
+
/**
|
|
114
|
+
* A type that matches any `Newtype`, useful as a generic constraint:
|
|
115
|
+
* `<N extends Newtype.Any>`.
|
|
116
|
+
*
|
|
117
|
+
* @see {@link Newtype} — the base tagged interface
|
|
118
|
+
*
|
|
119
|
+
* @since 4.0.0
|
|
120
|
+
*/
|
|
121
|
+
export type Any = Newtype<any, unknown>
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Extracts the key literal type from a newtype.
|
|
125
|
+
*
|
|
126
|
+
* - Useful in generic code that needs to inspect or constrain the key.
|
|
127
|
+
*
|
|
128
|
+
* @since 4.0.0
|
|
129
|
+
*/
|
|
130
|
+
export type Key<N extends Any> = N extends Newtype<infer Key, unknown> ? Key : never
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Extracts the carrier (underlying) type from a newtype.
|
|
134
|
+
*
|
|
135
|
+
* - Useful when you need to refer to the wrapped type in generic utilities.
|
|
136
|
+
*
|
|
137
|
+
* @since 4.0.0
|
|
138
|
+
*/
|
|
139
|
+
export type Carrier<N extends Any> = N extends Newtype<infer _Key, infer Carrier> ? Carrier : never
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Unwraps a newtype value, returning the underlying carrier value.
|
|
144
|
+
*
|
|
145
|
+
* - Use when you only need to read the inner value and do not need to wrap new
|
|
146
|
+
* values.
|
|
147
|
+
* - For both wrapping and unwrapping, prefer {@link makeIso}.
|
|
148
|
+
* - Zero runtime cost: this is an identity cast.
|
|
149
|
+
*
|
|
150
|
+
* **Example** (unwrapping a newtype)
|
|
151
|
+
*
|
|
152
|
+
* ```ts
|
|
153
|
+
* import { Newtype } from "effect"
|
|
154
|
+
*
|
|
155
|
+
* interface Label extends Newtype.Newtype<"Label", string> {}
|
|
156
|
+
*
|
|
157
|
+
* const iso = Newtype.makeIso<Label>()
|
|
158
|
+
* const label = iso.set("hello")
|
|
159
|
+
*
|
|
160
|
+
* const raw: string = Newtype.value(label) // "hello"
|
|
161
|
+
* ```
|
|
162
|
+
*
|
|
163
|
+
* @see {@link makeIso} — two-way conversion (wrap and unwrap)
|
|
164
|
+
*
|
|
165
|
+
* @since 4.0.0
|
|
166
|
+
*/
|
|
167
|
+
export const value: <N extends Newtype.Any>(newtype: N) => Newtype.Carrier<N> = cast
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Creates an `Optic.Iso` for a newtype, providing both wrapping (`set`) and
|
|
171
|
+
* unwrapping (`get`).
|
|
172
|
+
*
|
|
173
|
+
* - Use this as the primary way to construct and deconstruct newtype values.
|
|
174
|
+
* - The returned iso composes with other optics via the standard `Optic` API.
|
|
175
|
+
* - Zero runtime cost: both directions are identity casts.
|
|
176
|
+
*
|
|
177
|
+
* **Example** (wrapping and unwrapping with an iso)
|
|
178
|
+
*
|
|
179
|
+
* ```ts
|
|
180
|
+
* import { Newtype } from "effect"
|
|
181
|
+
*
|
|
182
|
+
* interface Label extends Newtype.Newtype<"Label", string> {}
|
|
183
|
+
*
|
|
184
|
+
* const labelIso = Newtype.makeIso<Label>()
|
|
185
|
+
*
|
|
186
|
+
* const label: Label = labelIso.set("world")
|
|
187
|
+
* const str: string = labelIso.get(label) // "world"
|
|
188
|
+
* ```
|
|
189
|
+
*
|
|
190
|
+
* @see {@link value} — unwrap only
|
|
191
|
+
*
|
|
192
|
+
* @since 4.0.0
|
|
193
|
+
*/
|
|
194
|
+
export function makeIso<N extends Newtype.Any>(): Optic.Iso<N, Newtype.Carrier<N>> {
|
|
195
|
+
return Optic.makeIso(value, cast)
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Lifts an `Equivalence` for the carrier type into an `Equivalence` for the
|
|
200
|
+
* newtype.
|
|
201
|
+
*
|
|
202
|
+
* - Use when you need to compare two newtype values for equality.
|
|
203
|
+
* - The returned equivalence delegates to the provided carrier equivalence.
|
|
204
|
+
* - Zero runtime cost beyond the underlying equivalence check.
|
|
205
|
+
*
|
|
206
|
+
* **Example** (comparing newtypes)
|
|
207
|
+
*
|
|
208
|
+
* ```ts
|
|
209
|
+
* import { Newtype, Equivalence } from "effect"
|
|
210
|
+
*
|
|
211
|
+
* interface Label extends Newtype.Newtype<"Label", string> {}
|
|
212
|
+
*
|
|
213
|
+
* const eq = Newtype.makeEquivalence<Label>(Equivalence.String)
|
|
214
|
+
* const iso = Newtype.makeIso<Label>()
|
|
215
|
+
*
|
|
216
|
+
* eq(iso.set("a"), iso.set("a")) // true
|
|
217
|
+
* eq(iso.set("a"), iso.set("b")) // false
|
|
218
|
+
* ```
|
|
219
|
+
*
|
|
220
|
+
* @see {@link makeOrder} — lift an `Order` for the carrier
|
|
221
|
+
*
|
|
222
|
+
* @since 4.0.0
|
|
223
|
+
*/
|
|
224
|
+
export const makeEquivalence: <N extends Newtype.Any>(
|
|
225
|
+
equivalence: Equivalence.Equivalence<Newtype.Carrier<N>>
|
|
226
|
+
) => Equivalence.Equivalence<N> = cast
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Lifts an `Order` for the carrier type into an `Order` for the newtype.
|
|
230
|
+
*
|
|
231
|
+
* - Use when you need to sort or compare newtype values.
|
|
232
|
+
* - The returned order delegates to the provided carrier order.
|
|
233
|
+
*
|
|
234
|
+
* **Example** (ordering newtypes)
|
|
235
|
+
*
|
|
236
|
+
* ```ts
|
|
237
|
+
* import { Newtype, Order } from "effect"
|
|
238
|
+
*
|
|
239
|
+
* interface Score extends Newtype.Newtype<"Score", number> {}
|
|
240
|
+
*
|
|
241
|
+
* const ord = Newtype.makeOrder<Score>(Order.Number)
|
|
242
|
+
* const iso = Newtype.makeIso<Score>()
|
|
243
|
+
*
|
|
244
|
+
* ord(iso.set(1), iso.set(2)) // -1
|
|
245
|
+
* ```
|
|
246
|
+
*
|
|
247
|
+
* @see {@link makeEquivalence} — lift an `Equivalence` for the carrier
|
|
248
|
+
*
|
|
249
|
+
* @since 4.0.0
|
|
250
|
+
*/
|
|
251
|
+
export const makeOrder: <N extends Newtype.Any>(order: Order.Order<Newtype.Carrier<N>>) => Order.Order<N> = cast
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* Lifts a `Combiner` for the carrier type into a `Combiner` for the newtype.
|
|
255
|
+
*
|
|
256
|
+
* - Use when you need to combine (e.g. concatenate, add) newtype values.
|
|
257
|
+
* - The returned combiner delegates to the provided carrier combiner.
|
|
258
|
+
*
|
|
259
|
+
* **Example** (combining newtypes)
|
|
260
|
+
*
|
|
261
|
+
* ```ts
|
|
262
|
+
* import { Newtype, Combiner } from "effect"
|
|
263
|
+
*
|
|
264
|
+
* interface Amount extends Newtype.Newtype<"Amount", number> {}
|
|
265
|
+
*
|
|
266
|
+
* const sum = Combiner.make<number>((a, b) => a + b)
|
|
267
|
+
* const combiner = Newtype.makeCombiner<Amount>(sum)
|
|
268
|
+
* const iso = Newtype.makeIso<Amount>()
|
|
269
|
+
*
|
|
270
|
+
* const total = combiner.combine(iso.set(10), iso.set(20))
|
|
271
|
+
* Newtype.value(total) // 30
|
|
272
|
+
* ```
|
|
273
|
+
*
|
|
274
|
+
* @see {@link makeReducer} — lift a `Reducer` for the carrier
|
|
275
|
+
*
|
|
276
|
+
* @since 4.0.0
|
|
277
|
+
*/
|
|
278
|
+
export const makeCombiner: <N extends Newtype.Any>(
|
|
279
|
+
combiner: Combiner.Combiner<Newtype.Carrier<N>>
|
|
280
|
+
) => Combiner.Combiner<N> = cast
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* Lifts a `Reducer` for the carrier type into a `Reducer` for the newtype.
|
|
284
|
+
*
|
|
285
|
+
* - Use when you need to fold/reduce over a collection of newtype values.
|
|
286
|
+
* - The returned reducer delegates to the provided carrier reducer.
|
|
287
|
+
*
|
|
288
|
+
* **Example** (reducing newtypes)
|
|
289
|
+
*
|
|
290
|
+
* ```ts
|
|
291
|
+
* import { Newtype, Reducer } from "effect"
|
|
292
|
+
*
|
|
293
|
+
* interface Score extends Newtype.Newtype<"Score", number> {}
|
|
294
|
+
*
|
|
295
|
+
* const sum = Reducer.make<number>((a, b) => a + b, 0)
|
|
296
|
+
* const reducer = Newtype.makeReducer<Score>(sum)
|
|
297
|
+
* const iso = Newtype.makeIso<Score>()
|
|
298
|
+
*
|
|
299
|
+
* const total = reducer.combineAll([iso.set(1), iso.set(2), iso.set(3)])
|
|
300
|
+
* Newtype.value(total) // 6
|
|
301
|
+
* ```
|
|
302
|
+
*
|
|
303
|
+
* @see {@link makeCombiner} — lift a `Combiner` for the carrier
|
|
304
|
+
*
|
|
305
|
+
* @since 4.0.0
|
|
306
|
+
*/
|
|
307
|
+
export const makeReducer: <N extends Newtype.Any>(reducer: Reducer.Reducer<Newtype.Carrier<N>>) => Reducer.Reducer<N> =
|
|
308
|
+
cast
|
package/src/References.ts
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
import { constTrue, constUndefined } from "./Function.ts"
|
|
14
14
|
import type { LogLevel, Severity } from "./LogLevel.ts"
|
|
15
15
|
import type { ReadonlyRecord } from "./Record.ts"
|
|
16
|
-
import { MaxOpsBeforeYield } from "./Scheduler.ts"
|
|
16
|
+
import { MaxOpsBeforeYield, PreventSchedulerYield } from "./Scheduler.ts"
|
|
17
17
|
import * as ServiceMap from "./ServiceMap.ts"
|
|
18
18
|
import { CurrentTraceLevel, DisablePropagation, MinimumTraceLevel, type SpanLink, Tracer } from "./Tracer.ts"
|
|
19
19
|
|
|
@@ -38,6 +38,11 @@ export {
|
|
|
38
38
|
* @category references
|
|
39
39
|
*/
|
|
40
40
|
MinimumTraceLevel,
|
|
41
|
+
/**
|
|
42
|
+
* @since 4.0.0
|
|
43
|
+
* @category references
|
|
44
|
+
*/
|
|
45
|
+
PreventSchedulerYield,
|
|
41
46
|
/**
|
|
42
47
|
* @since 4.0.0
|
|
43
48
|
* @category references
|
package/src/RequestResolver.ts
CHANGED
|
@@ -181,7 +181,7 @@ const defaultKey = (_request: unknown): unknown => defaultKeyObject
|
|
|
181
181
|
* )
|
|
182
182
|
*
|
|
183
183
|
* // Use the resolver to handle requests
|
|
184
|
-
* const getUserEffect = Effect.request(GetUserRequest({ id: 123 }),
|
|
184
|
+
* const getUserEffect = Effect.request(GetUserRequest({ id: 123 }), UserResolver)
|
|
185
185
|
* ```
|
|
186
186
|
*
|
|
187
187
|
* @since 2.0.0
|
|
@@ -276,7 +276,7 @@ const hashGroupKey = <A, K>(get: (entry: Request.Entry<A>) => K) => {
|
|
|
276
276
|
* // Usage
|
|
277
277
|
* const getSquareEffect = Effect.request(
|
|
278
278
|
* GetSquareRequest({ value: 5 }),
|
|
279
|
-
*
|
|
279
|
+
* SquareResolver
|
|
280
280
|
* )
|
|
281
281
|
* // Will resolve to 25
|
|
282
282
|
* ```
|
|
@@ -319,7 +319,7 @@ export const fromFunction = <A extends Request.Any>(
|
|
|
319
319
|
*
|
|
320
320
|
* // Usage with multiple requests
|
|
321
321
|
* const effects = [1, 2, 3].map((value) =>
|
|
322
|
-
* Effect.request(GetDoubleRequest({ value }),
|
|
322
|
+
* Effect.request(GetDoubleRequest({ value }), DoubleResolver)
|
|
323
323
|
* )
|
|
324
324
|
* const batchedEffect = Effect.all(effects) // [2, 4, 6]
|
|
325
325
|
* ```
|
|
@@ -370,7 +370,7 @@ export const fromFunctionBatched = <A extends Request.Any>(
|
|
|
370
370
|
* // Usage
|
|
371
371
|
* const getUserEffect = Effect.request(
|
|
372
372
|
* GetUserFromAPIRequest({ id: 123 }),
|
|
373
|
-
*
|
|
373
|
+
* UserAPIResolver
|
|
374
374
|
* )
|
|
375
375
|
* ```
|
|
376
376
|
*
|
|
@@ -874,7 +874,7 @@ export const never: RequestResolver<never> = make(() => Effect.never)
|
|
|
874
874
|
* // When more than 5 requests are made, they'll be split into multiple batches
|
|
875
875
|
* const requests = Array.from(
|
|
876
876
|
* { length: 12 },
|
|
877
|
-
* (_, i) => Effect.request(GetDataRequest({ id: i }),
|
|
877
|
+
* (_, i) => Effect.request(GetDataRequest({ id: i }), limitedResolver)
|
|
878
878
|
* )
|
|
879
879
|
* ```
|
|
880
880
|
*
|
|
@@ -910,7 +910,7 @@ export const batchN: {
|
|
|
910
910
|
* // When more than 5 requests are made, they'll be split into multiple batches
|
|
911
911
|
* const requests = Array.from(
|
|
912
912
|
* { length: 12 },
|
|
913
|
-
* (_, i) => Effect.request(GetDataRequest({ id: i }),
|
|
913
|
+
* (_, i) => Effect.request(GetDataRequest({ id: i }), limitedResolver)
|
|
914
914
|
* )
|
|
915
915
|
* ```
|
|
916
916
|
*
|
|
@@ -946,7 +946,7 @@ export const batchN: {
|
|
|
946
946
|
* // When more than 5 requests are made, they'll be split into multiple batches
|
|
947
947
|
* const requests = Array.from(
|
|
948
948
|
* { length: 12 },
|
|
949
|
-
* (_, i) => Effect.request(GetDataRequest({ id: i }),
|
|
949
|
+
* (_, i) => Effect.request(GetDataRequest({ id: i }), limitedResolver)
|
|
950
950
|
* )
|
|
951
951
|
* ```
|
|
952
952
|
*
|
|
@@ -994,15 +994,15 @@ export const batchN: {
|
|
|
994
994
|
* const requests = [
|
|
995
995
|
* Effect.request(
|
|
996
996
|
* GetUserRequest({ userId: 1, department: "Engineering" }),
|
|
997
|
-
*
|
|
997
|
+
* groupedResolver
|
|
998
998
|
* ),
|
|
999
999
|
* Effect.request(
|
|
1000
1000
|
* GetUserRequest({ userId: 2, department: "Engineering" }),
|
|
1001
|
-
*
|
|
1001
|
+
* groupedResolver
|
|
1002
1002
|
* ),
|
|
1003
1003
|
* Effect.request(
|
|
1004
1004
|
* GetUserRequest({ userId: 3, department: "Marketing" }),
|
|
1005
|
-
*
|
|
1005
|
+
* groupedResolver
|
|
1006
1006
|
* )
|
|
1007
1007
|
* ]
|
|
1008
1008
|
* ```
|
|
@@ -1045,15 +1045,15 @@ export const grouped: {
|
|
|
1045
1045
|
* const requests = [
|
|
1046
1046
|
* Effect.request(
|
|
1047
1047
|
* GetUserRequest({ userId: 1, department: "Engineering" }),
|
|
1048
|
-
*
|
|
1048
|
+
* groupedResolver
|
|
1049
1049
|
* ),
|
|
1050
1050
|
* Effect.request(
|
|
1051
1051
|
* GetUserRequest({ userId: 2, department: "Engineering" }),
|
|
1052
|
-
*
|
|
1052
|
+
* groupedResolver
|
|
1053
1053
|
* ),
|
|
1054
1054
|
* Effect.request(
|
|
1055
1055
|
* GetUserRequest({ userId: 3, department: "Marketing" }),
|
|
1056
|
-
*
|
|
1056
|
+
* groupedResolver
|
|
1057
1057
|
* )
|
|
1058
1058
|
* ]
|
|
1059
1059
|
* ```
|
|
@@ -1096,15 +1096,15 @@ export const grouped: {
|
|
|
1096
1096
|
* const requests = [
|
|
1097
1097
|
* Effect.request(
|
|
1098
1098
|
* GetUserRequest({ userId: 1, department: "Engineering" }),
|
|
1099
|
-
*
|
|
1099
|
+
* groupedResolver
|
|
1100
1100
|
* ),
|
|
1101
1101
|
* Effect.request(
|
|
1102
1102
|
* GetUserRequest({ userId: 2, department: "Engineering" }),
|
|
1103
|
-
*
|
|
1103
|
+
* groupedResolver
|
|
1104
1104
|
* ),
|
|
1105
1105
|
* Effect.request(
|
|
1106
1106
|
* GetUserRequest({ userId: 3, department: "Marketing" }),
|
|
1107
|
-
*
|
|
1107
|
+
* groupedResolver
|
|
1108
1108
|
* )
|
|
1109
1109
|
* ]
|
|
1110
1110
|
* ```
|
|
@@ -1300,7 +1300,7 @@ export const race: {
|
|
|
1300
1300
|
* )
|
|
1301
1301
|
*
|
|
1302
1302
|
* // Spans will automatically include batch size and request links
|
|
1303
|
-
* const effect = Effect.request(GetDataRequest({ id: 123 }),
|
|
1303
|
+
* const effect = Effect.request(GetDataRequest({ id: 123 }), tracedResolver)
|
|
1304
1304
|
* ```
|
|
1305
1305
|
*
|
|
1306
1306
|
* @since 4.0.0
|
|
@@ -1342,7 +1342,7 @@ export const withSpan: {
|
|
|
1342
1342
|
* )
|
|
1343
1343
|
*
|
|
1344
1344
|
* // Spans will automatically include batch size and request links
|
|
1345
|
-
* const effect = Effect.request(GetDataRequest({ id: 123 }),
|
|
1345
|
+
* const effect = Effect.request(GetDataRequest({ id: 123 }), tracedResolver)
|
|
1346
1346
|
* ```
|
|
1347
1347
|
*
|
|
1348
1348
|
* @since 4.0.0
|
|
@@ -1387,7 +1387,7 @@ export const withSpan: {
|
|
|
1387
1387
|
* )
|
|
1388
1388
|
*
|
|
1389
1389
|
* // Spans will automatically include batch size and request links
|
|
1390
|
-
* const effect = Effect.request(GetDataRequest({ id: 123 }),
|
|
1390
|
+
* const effect = Effect.request(GetDataRequest({ id: 123 }), tracedResolver)
|
|
1391
1391
|
* ```
|
|
1392
1392
|
*
|
|
1393
1393
|
* @since 4.0.0
|
|
@@ -1509,7 +1509,7 @@ export const asCache: {
|
|
|
1509
1509
|
capacity: options.capacity,
|
|
1510
1510
|
timeToLive: options.timeToLive as any,
|
|
1511
1511
|
requireServicesAt: options.requireServicesAt ?? "lookup" as ServiceMode,
|
|
1512
|
-
lookup: (req: A) => internal.request(req,
|
|
1512
|
+
lookup: (req: A) => internal.request(req, self)
|
|
1513
1513
|
}) as any)
|
|
1514
1514
|
|
|
1515
1515
|
/**
|