effect-app 4.0.0-beta.20 → 4.0.0-beta.201
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/CHANGELOG.md +888 -0
- package/dist/Array.d.ts +1 -1
- package/dist/Chunk.d.ts +1 -1
- package/dist/Chunk.d.ts.map +1 -1
- package/dist/Config/SecretURL.d.ts +1 -1
- package/dist/Config/SecretURL.d.ts.map +1 -1
- package/dist/Config/SecretURL.js +2 -2
- package/dist/Config/internal/configSecretURL.d.ts +1 -1
- package/dist/Config/internal/configSecretURL.d.ts.map +1 -1
- package/dist/Config.d.ts +7 -0
- package/dist/Config.d.ts.map +1 -0
- package/dist/Config.js +6 -0
- package/dist/ConfigProvider.d.ts +39 -0
- package/dist/ConfigProvider.d.ts.map +1 -0
- package/dist/ConfigProvider.js +42 -0
- package/dist/Context.d.ts +40 -0
- package/dist/Context.d.ts.map +1 -0
- package/dist/Context.js +67 -0
- package/dist/Effect.d.ts +9 -10
- package/dist/Effect.d.ts.map +1 -1
- package/dist/Effect.js +3 -6
- package/dist/Function.d.ts +1 -1
- package/dist/Function.d.ts.map +1 -1
- package/dist/Inputify.type.d.ts +1 -1
- package/dist/Layer.d.ts +7 -6
- package/dist/Layer.d.ts.map +1 -1
- package/dist/Layer.js +1 -1
- package/dist/NonEmptySet.d.ts +1 -1
- package/dist/NonEmptySet.d.ts.map +1 -1
- package/dist/Option.d.ts +1 -1
- package/dist/Option.d.ts.map +1 -1
- package/dist/Pure.d.ts +5 -5
- package/dist/Pure.d.ts.map +1 -1
- package/dist/Pure.js +13 -13
- package/dist/Schema/Class.d.ts +66 -20
- package/dist/Schema/Class.d.ts.map +1 -1
- package/dist/Schema/Class.js +189 -22
- package/dist/Schema/FastCheck.d.ts +1 -1
- package/dist/Schema/FastCheck.d.ts.map +1 -1
- package/dist/Schema/Methods.d.ts +1 -1
- package/dist/Schema/SchemaParser.d.ts +5 -0
- package/dist/Schema/SchemaParser.d.ts.map +1 -0
- package/dist/Schema/SchemaParser.js +6 -0
- package/dist/Schema/SpecialJsonSchema.d.ts +33 -0
- package/dist/Schema/SpecialJsonSchema.d.ts.map +1 -0
- package/dist/Schema/SpecialJsonSchema.js +122 -0
- package/dist/Schema/SpecialOpenApi.d.ts +32 -0
- package/dist/Schema/SpecialOpenApi.d.ts.map +1 -0
- package/dist/Schema/SpecialOpenApi.js +123 -0
- package/dist/Schema/brand.d.ts +7 -2
- package/dist/Schema/brand.d.ts.map +1 -1
- package/dist/Schema/brand.js +1 -1
- package/dist/Schema/email.d.ts +1 -1
- package/dist/Schema/email.d.ts.map +1 -1
- package/dist/Schema/email.js +7 -4
- package/dist/Schema/ext.d.ts +117 -45
- package/dist/Schema/ext.d.ts.map +1 -1
- package/dist/Schema/ext.js +131 -42
- package/dist/Schema/moreStrings.d.ts +111 -11
- package/dist/Schema/moreStrings.d.ts.map +1 -1
- package/dist/Schema/moreStrings.js +14 -15
- package/dist/Schema/numbers.d.ts +127 -15
- package/dist/Schema/numbers.d.ts.map +1 -1
- package/dist/Schema/numbers.js +10 -12
- package/dist/Schema/phoneNumber.d.ts +1 -1
- package/dist/Schema/phoneNumber.d.ts.map +1 -1
- package/dist/Schema/phoneNumber.js +6 -3
- package/dist/Schema/schema.d.ts +1 -1
- package/dist/Schema/strings.d.ts +37 -5
- package/dist/Schema/strings.d.ts.map +1 -1
- package/dist/Schema/strings.js +1 -5
- package/dist/Schema.d.ts +154 -56
- package/dist/Schema.d.ts.map +1 -1
- package/dist/Schema.js +131 -64
- package/dist/Set.d.ts +1 -1
- package/dist/Set.d.ts.map +1 -1
- package/dist/TypeTest.d.ts +1 -1
- package/dist/Types.d.ts +1 -1
- package/dist/Widen.type.d.ts +1 -1
- package/dist/_ext/Array.d.ts +1 -1
- package/dist/_ext/Array.d.ts.map +1 -1
- package/dist/_ext/date.d.ts +1 -1
- package/dist/_ext/misc.d.ts +1 -1
- package/dist/_ext/ord.ext.d.ts +1 -1
- package/dist/_ext/ord.ext.d.ts.map +1 -1
- package/dist/builtin.d.ts +1 -1
- package/dist/builtin.d.ts.map +1 -1
- package/dist/client/InvalidationKeys.d.ts +29 -0
- package/dist/client/InvalidationKeys.d.ts.map +1 -0
- package/dist/client/InvalidationKeys.js +33 -0
- package/dist/client/apiClientFactory.d.ts +18 -32
- package/dist/client/apiClientFactory.d.ts.map +1 -1
- package/dist/client/apiClientFactory.js +95 -32
- package/dist/client/clientFor.d.ts +61 -17
- package/dist/client/clientFor.d.ts.map +1 -1
- package/dist/client/clientFor.js +9 -1
- package/dist/client/errors.d.ts +49 -25
- package/dist/client/errors.d.ts.map +1 -1
- package/dist/client/errors.js +43 -17
- package/dist/client/makeClient.d.ts +468 -32
- package/dist/client/makeClient.d.ts.map +1 -1
- package/dist/client/makeClient.js +62 -23
- package/dist/client.d.ts +2 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +2 -1
- package/dist/faker.d.ts +1 -1
- package/dist/faker.d.ts.map +1 -1
- package/dist/http/Request.d.ts +2 -2
- package/dist/http/Request.d.ts.map +1 -1
- package/dist/http/Request.js +5 -5
- package/dist/http/internal/lib.d.ts +1 -1
- package/dist/http.d.ts +1 -1
- package/dist/ids.d.ts +3 -3
- package/dist/ids.d.ts.map +1 -1
- package/dist/ids.js +3 -2
- package/dist/index.d.ts +5 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -8
- package/dist/logger.d.ts +1 -1
- package/dist/middleware.d.ts +14 -8
- package/dist/middleware.d.ts.map +1 -1
- package/dist/middleware.js +14 -8
- package/dist/rpc/Invalidation.d.ts +402 -0
- package/dist/rpc/Invalidation.d.ts.map +1 -0
- package/dist/rpc/Invalidation.js +150 -0
- package/dist/rpc/MiddlewareMaker.d.ts +5 -4
- package/dist/rpc/MiddlewareMaker.d.ts.map +1 -1
- package/dist/rpc/MiddlewareMaker.js +57 -37
- package/dist/rpc/RpcContextMap.d.ts +3 -3
- package/dist/rpc/RpcContextMap.d.ts.map +1 -1
- package/dist/rpc/RpcContextMap.js +4 -4
- package/dist/rpc/RpcMiddleware.d.ts +5 -4
- package/dist/rpc/RpcMiddleware.d.ts.map +1 -1
- package/dist/rpc/RpcMiddleware.js +1 -1
- package/dist/rpc.d.ts +2 -2
- package/dist/rpc.d.ts.map +1 -1
- package/dist/rpc.js +2 -2
- package/dist/transform.d.ts +1 -1
- package/dist/transform.d.ts.map +1 -1
- package/dist/transform.js +3 -3
- package/dist/utils/effectify.d.ts +1 -1
- package/dist/utils/extend.d.ts +1 -1
- package/dist/utils/extend.d.ts.map +1 -1
- package/dist/utils/gen.d.ts +2 -2
- package/dist/utils/gen.d.ts.map +1 -1
- package/dist/utils/logLevel.d.ts +2 -2
- package/dist/utils/logLevel.d.ts.map +1 -1
- package/dist/utils/logger.d.ts +3 -3
- package/dist/utils/logger.d.ts.map +1 -1
- package/dist/utils/logger.js +3 -3
- package/dist/utils.d.ts +31 -11
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +13 -7
- package/dist/validation/validators.d.ts +1 -1
- package/dist/validation/validators.d.ts.map +1 -1
- package/dist/validation.d.ts +1 -1
- package/dist/validation.d.ts.map +1 -1
- package/package.json +46 -24
- package/src/Config/SecretURL.ts +2 -1
- package/src/Config.ts +14 -0
- package/src/ConfigProvider.ts +48 -0
- package/src/{ServiceMap.ts → Context.ts} +52 -59
- package/src/Effect.ts +12 -14
- package/src/Layer.ts +6 -5
- package/src/Pure.ts +17 -18
- package/src/Schema/Class.ts +268 -62
- package/src/Schema/SchemaParser.ts +12 -0
- package/src/Schema/SpecialJsonSchema.ts +137 -0
- package/src/Schema/SpecialOpenApi.ts +130 -0
- package/src/Schema/brand.ts +9 -1
- package/src/Schema/email.ts +7 -2
- package/src/Schema/ext.ts +204 -72
- package/src/Schema/moreStrings.ts +22 -20
- package/src/Schema/numbers.ts +14 -16
- package/src/Schema/phoneNumber.ts +5 -1
- package/src/Schema/strings.ts +4 -8
- package/src/Schema.ts +332 -105
- package/src/client/InvalidationKeys.ts +50 -0
- package/src/client/apiClientFactory.ts +220 -129
- package/src/client/clientFor.ts +97 -29
- package/src/client/errors.ts +52 -26
- package/src/client/makeClient.ts +538 -68
- package/src/client.ts +1 -0
- package/src/http/Request.ts +7 -4
- package/src/ids.ts +2 -1
- package/src/index.ts +5 -10
- package/src/middleware.ts +13 -9
- package/src/rpc/Invalidation.ts +226 -0
- package/src/rpc/MiddlewareMaker.ts +65 -60
- package/src/rpc/README.md +2 -2
- package/src/rpc/RpcContextMap.ts +6 -5
- package/src/rpc/RpcMiddleware.ts +5 -4
- package/src/rpc.ts +1 -1
- package/src/transform.ts +2 -2
- package/src/utils/gen.ts +1 -1
- package/src/utils/logger.ts +2 -2
- package/src/utils.ts +51 -15
- package/test/dist/rpc.test.d.ts.map +1 -1
- package/test/dist/secretURL.test.d.ts.map +1 -0
- package/test/dist/special.test.d.ts.map +1 -0
- package/test/dist/stream-error.types.d.ts +2 -0
- package/test/dist/stream-error.types.d.ts.map +1 -0
- package/test/dist/stream-error.types.js +27 -0
- package/test/rpc.test.ts +41 -6
- package/test/schema.test.ts +591 -17
- package/test/secretURL.test.ts +157 -0
- package/test/special.test.ts +1023 -0
- package/test/utils.test.ts +6 -6
- package/tsconfig.base.json +3 -4
- package/tsconfig.json +0 -1
- package/tsconfig.json.bak +2 -2
- package/tsconfig.src.json +29 -29
- package/tsconfig.test.json +2 -2
- package/dist/Operations.d.ts +0 -87
- package/dist/Operations.d.ts.map +0 -1
- package/dist/Operations.js +0 -29
- package/dist/ServiceMap.d.ts +0 -44
- package/dist/ServiceMap.d.ts.map +0 -1
- package/dist/ServiceMap.js +0 -91
- package/eslint.config.mjs +0 -26
- package/src/Operations.ts +0 -55
package/src/Config.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type Config, make } from "effect/Config"
|
|
2
|
+
import { dual } from "effect/Function"
|
|
3
|
+
|
|
4
|
+
import * as ConfigProvider from "./ConfigProvider.js"
|
|
5
|
+
|
|
6
|
+
export const nested: {
|
|
7
|
+
(name: string): <A>(self: Config<A>) => Config<A>
|
|
8
|
+
<A>(self: Config<A>, name: string): Config<A>
|
|
9
|
+
} = dual(
|
|
10
|
+
2,
|
|
11
|
+
<A>(self: Config<A>, name: string): Config<A> => make((provider) => self.parse(ConfigProvider.nested(provider, name)))
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
export * from "effect/Config"
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { type ConfigProvider, make, type Path } from "effect/ConfigProvider"
|
|
2
|
+
import { dual } from "effect/Function"
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Scopes a provider so that all lookups are prefixed with the given path
|
|
6
|
+
* segments.
|
|
7
|
+
*
|
|
8
|
+
* When to use:
|
|
9
|
+
* - Namespacing config under a prefix like `"app"` or `"database"`.
|
|
10
|
+
* - Reusing the same provider shape for multiple sub-configs.
|
|
11
|
+
*
|
|
12
|
+
* Accepts a single string or a full `Path` array. The prefix is prepended
|
|
13
|
+
* *after* any `mapInput` transformation runs, so ordering matters when
|
|
14
|
+
* composing with {@link mapInput} or {@link constantCase}.
|
|
15
|
+
*
|
|
16
|
+
* Supports both data-last and data-first calling conventions.
|
|
17
|
+
*
|
|
18
|
+
* **Example** (Nesting under a prefix)
|
|
19
|
+
*
|
|
20
|
+
* ```ts
|
|
21
|
+
* import { ConfigProvider } from "effect"
|
|
22
|
+
*
|
|
23
|
+
* const provider = ConfigProvider.fromEnv({
|
|
24
|
+
* env: { APP_HOST: "localhost", APP_PORT: "3000" }
|
|
25
|
+
* })
|
|
26
|
+
*
|
|
27
|
+
* // Lookups for ["HOST"] now resolve to ["APP", "HOST"]
|
|
28
|
+
* const scoped = ConfigProvider.nested(provider, "APP")
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* @see {@link mapInput} – for arbitrary path transformations
|
|
32
|
+
*
|
|
33
|
+
* @category Combinators
|
|
34
|
+
* @since 4.0.0
|
|
35
|
+
*/
|
|
36
|
+
export const nested: {
|
|
37
|
+
(prefix: string | Path): (self: ConfigProvider) => ConfigProvider
|
|
38
|
+
(self: ConfigProvider, prefix: string | Path): ConfigProvider
|
|
39
|
+
} = dual(
|
|
40
|
+
2,
|
|
41
|
+
(self: ConfigProvider, prefix: string | Path): ConfigProvider => {
|
|
42
|
+
let path: Path = typeof prefix === "string" ? [prefix] : prefix
|
|
43
|
+
if (self.mapInput) path = self.mapInput(path)
|
|
44
|
+
return make(self.get, self.mapInput, self.prefix ? [...self.prefix, ...path] : path)
|
|
45
|
+
}
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
export * from "effect/ConfigProvider"
|
|
@@ -1,21 +1,17 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
-
|
|
3
|
-
* We're doing the long way around here with assignTag, TagBase & TagBaseTagged,
|
|
4
|
-
* because there's a typescript compiler issue where it will complain about Equal.symbol, and Hash.symbol not being accessible.
|
|
5
|
-
* https://github.com/microsoft/TypeScript/issues/52644
|
|
6
|
-
*/
|
|
2
|
+
/* eslint-disable import/namespace */
|
|
7
3
|
|
|
8
4
|
import { type Effect, Layer, type Scope, type Types } from "effect"
|
|
9
|
-
import * as
|
|
5
|
+
import * as CTX from "effect/Context"
|
|
10
6
|
import { type Yieldable } from "./Effect.js"
|
|
11
7
|
|
|
12
|
-
export * from "effect/
|
|
8
|
+
export * from "effect/Context"
|
|
13
9
|
|
|
14
10
|
export interface Opaque<Self extends object, in out Shape extends object>
|
|
15
|
-
extends
|
|
11
|
+
extends CTX.Key<Self, Self>, Yieldable<Opaque<Self, Shape>, Self, never, Self>
|
|
16
12
|
{
|
|
17
13
|
of(this: void, self: Shape): Self
|
|
18
|
-
|
|
14
|
+
context(self: Shape): CTX.Context<Self>
|
|
19
15
|
// a version that leverages the Shape -> Self conversion
|
|
20
16
|
toLayer: <E, R>(
|
|
21
17
|
eff: Effect.Effect<Shape, E, R>
|
|
@@ -25,11 +21,11 @@ export interface Opaque<Self extends object, in out Shape extends object>
|
|
|
25
21
|
}
|
|
26
22
|
|
|
27
23
|
// export interface OpaqueMake<Self extends object, in out Shape extends object, E, R>
|
|
28
|
-
// extends
|
|
24
|
+
// extends CTX.Service<Self, Self>
|
|
29
25
|
// {
|
|
30
26
|
// // temp while sorting out https://github.com/Effect-TS/effect-smol/pull/1534
|
|
31
27
|
// of(self: Shape): Self
|
|
32
|
-
//
|
|
28
|
+
// contextMap2(self: Shape): CTX.Context<Self>
|
|
33
29
|
// // a version that leverages the Shape -> Self conversion
|
|
34
30
|
// toLayer: {
|
|
35
31
|
// <E, R>(
|
|
@@ -44,7 +40,7 @@ export function assignTag<Identifier extends object, Shape extends object = Iden
|
|
|
44
40
|
creationError?: Error
|
|
45
41
|
) {
|
|
46
42
|
return <S extends object>(cls: S): S & Opaque<Identifier, Shape> => {
|
|
47
|
-
const tag =
|
|
43
|
+
const tag = CTX.Service<Identifier, Shape>(key)
|
|
48
44
|
let fields = tag
|
|
49
45
|
if (Reflect.ownKeys(cls).includes("key")) {
|
|
50
46
|
const { key, ...rest } = tag
|
|
@@ -67,54 +63,51 @@ export function assignTag<Identifier extends object, Shape extends object = Iden
|
|
|
67
63
|
}
|
|
68
64
|
}
|
|
69
65
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
: Effect.Effect<Type[k], never, Self>
|
|
81
|
-
}
|
|
82
|
-
: {}
|
|
66
|
+
/** Accessor for a service method that returns a plain value. Wraps via `useSync`. */
|
|
67
|
+
export const accessFn = <
|
|
68
|
+
Self extends object,
|
|
69
|
+
Shape extends Record<PropertyKey, any>,
|
|
70
|
+
K extends keyof Shape
|
|
71
|
+
>(
|
|
72
|
+
Tag: Opaque<Self, Shape>,
|
|
73
|
+
key: K
|
|
74
|
+
): Shape[K] extends (...args: [...infer Args]) => infer A ? (...args: Readonly<Args>) => Effect.Effect<A, never, Self>
|
|
75
|
+
: never => ((...args: Array<any>) => Tag.useSync((s: any) => s[key](...args))) as any
|
|
83
76
|
|
|
84
|
-
/**
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
77
|
+
/** Accessor for a service method that returns an Effect. Delegates via `use`. */
|
|
78
|
+
export const accessEffectFn = <
|
|
79
|
+
Self extends object,
|
|
80
|
+
Shape extends Record<PropertyKey, any>,
|
|
81
|
+
K extends keyof Shape
|
|
82
|
+
>(
|
|
83
|
+
Tag: Opaque<Self, Shape>,
|
|
84
|
+
key: K
|
|
85
|
+
): Shape[K] extends (...args: [...infer Args]) => Effect.Effect<infer A, infer E, infer R>
|
|
86
|
+
? (...args: Readonly<Args>) => Effect.Effect<A, E, Self | R>
|
|
87
|
+
: never => ((...args: Array<any>) => Tag.use((s: any) => s[key](...args))) as any
|
|
88
|
+
|
|
89
|
+
/** Accessor for a service property (constant). Wraps via `useSync`. */
|
|
90
|
+
export const accessCn = <
|
|
91
|
+
Self extends object,
|
|
92
|
+
Shape extends Record<PropertyKey, any>,
|
|
93
|
+
K extends keyof Shape
|
|
94
|
+
>(
|
|
95
|
+
Tag: Opaque<Self, Shape>,
|
|
96
|
+
key: K
|
|
97
|
+
): Effect.Effect<Shape[K], never, Self> => Tag.useSync((s) => s[key])
|
|
98
|
+
|
|
99
|
+
/** Accessor for a service property that is an Effect. Delegates via `use`. */
|
|
100
|
+
export const accessEffectCn = <
|
|
101
|
+
Self extends object,
|
|
102
|
+
Shape extends Record<PropertyKey, any>,
|
|
103
|
+
K extends keyof Shape
|
|
104
|
+
>(
|
|
105
|
+
Tag: Opaque<Self, Shape>,
|
|
106
|
+
key: K
|
|
107
|
+
): Shape[K] extends Effect.Effect<infer A, infer E, infer R> ? Effect.Effect<A, E, Self | R>
|
|
108
|
+
: never => Tag.use((s: any) => s[key]) as any
|
|
116
109
|
|
|
117
|
-
export const TypeId = "~
|
|
110
|
+
export const TypeId = "~Context.Opaque"
|
|
118
111
|
|
|
119
112
|
// export function Opaque<const Key extends string>(key: Key) {
|
|
120
113
|
// return <Identifier extends object, Shape extends object>() => {
|
|
@@ -179,7 +172,7 @@ export const Opaque: {
|
|
|
179
172
|
>
|
|
180
173
|
& { readonly make: Make }
|
|
181
174
|
} = () => (id: string, options: any) => {
|
|
182
|
-
const svc =
|
|
175
|
+
const svc = CTX.Service()(id, options) as any
|
|
183
176
|
return Object.assign(svc, {
|
|
184
177
|
toLayer: (eff: Effect.Effect<any, any, any>) => {
|
|
185
178
|
return Layer.effect(svc, eff)
|
package/src/Effect.ts
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
/* eslint-disable prefer-destructuring */
|
|
3
3
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
4
4
|
|
|
5
|
-
import { Effect, Option, Ref
|
|
5
|
+
import { Effect, Option, Ref } from "effect"
|
|
6
6
|
import * as Def from "effect/Deferred"
|
|
7
|
-
import * as Fiber from "effect/Fiber"
|
|
8
7
|
import type { Scope } from "effect/Scope"
|
|
9
8
|
import type { Semaphore } from "effect/Semaphore"
|
|
9
|
+
import type * as Context from "./Context.js"
|
|
10
10
|
import { curry } from "./Function.js"
|
|
11
11
|
import { typedKeysOf } from "./utils.js"
|
|
12
12
|
|
|
@@ -111,15 +111,11 @@ export function modifyWithPermitWithEffect<A>(ref: Ref.Ref<A>, semaphore: Semaph
|
|
|
111
111
|
)
|
|
112
112
|
}
|
|
113
113
|
|
|
114
|
-
export function joinAll<E, A>(fibers: Iterable<Fiber.Fiber<A, E>>): Effect.Effect<readonly A[], E> {
|
|
115
|
-
return Fiber.joinAll(fibers) as any
|
|
116
|
-
}
|
|
117
|
-
|
|
118
114
|
type ServiceA<T> = T extends Effect.Effect<infer S, any, any> ? S
|
|
119
|
-
: T extends
|
|
115
|
+
: T extends Context.Service<any, infer S> ? S
|
|
120
116
|
: never
|
|
121
117
|
type ServiceR<T> = T extends Effect.Effect<any, any, infer R> ? R
|
|
122
|
-
: T extends
|
|
118
|
+
: T extends Context.Service<infer I, any> ? I
|
|
123
119
|
: never
|
|
124
120
|
type ServiceE<T> = T extends Effect.Effect<any, infer E, any> ? E : never
|
|
125
121
|
// type Values<T> = T extends { [s: string]: infer S } ? ServiceA<S> : never
|
|
@@ -140,28 +136,30 @@ type ValuesE<T> = T extends { [s: string]: infer S } ? ServiceE<S> : never
|
|
|
140
136
|
* const b = a({ str: "" }) // valid, but shouldn't be!
|
|
141
137
|
* ```
|
|
142
138
|
*/
|
|
139
|
+
// eslint-disable-next-line import/namespace
|
|
143
140
|
export interface EffectUnunified<R, E, A> extends Effect.Effect<R, E, A> {}
|
|
144
141
|
|
|
145
142
|
export type LowerFirst<S extends PropertyKey> = S extends `${infer First}${infer Rest}` ? `${Lowercase<First>}${Rest}`
|
|
146
143
|
: S
|
|
147
|
-
export type LowerServices<T extends Record<string,
|
|
144
|
+
export type LowerServices<T extends Record<string, Context.Service<any, any> | Effect.Effect<any, any, any>>> = {
|
|
148
145
|
[key in keyof T as LowerFirst<key>]: ServiceA<T[key]>
|
|
149
146
|
}
|
|
150
147
|
|
|
151
|
-
export function allLower<T extends Record<string,
|
|
148
|
+
export function allLower<T extends Record<string, Context.Service<any, any> | Effect.Effect<any, any, any>>>(
|
|
152
149
|
services: T
|
|
153
150
|
) {
|
|
154
151
|
return Effect.all(
|
|
155
152
|
typedKeysOf(services).reduce((prev, cur) => {
|
|
156
|
-
const svc = services[cur]
|
|
157
|
-
prev[((cur as string)[0]!.toLowerCase() + (cur as string).slice(1)) as unknown as LowerFirst<typeof cur>] =
|
|
153
|
+
const svc = services[cur]!
|
|
154
|
+
prev[((cur as string)[0]!.toLowerCase() + (cur as string).slice(1)) as unknown as LowerFirst<typeof cur>] =
|
|
155
|
+
"asEffect" in svc ? svc.asEffect() : svc
|
|
158
156
|
return prev
|
|
159
157
|
}, {} as any),
|
|
160
158
|
{ concurrency: "inherit" }
|
|
161
159
|
) as any as Effect.Effect<LowerServices<T>, ValuesE<T>, ValuesR<T>>
|
|
162
160
|
}
|
|
163
161
|
|
|
164
|
-
export function allLowerWith<T extends Record<string,
|
|
162
|
+
export function allLowerWith<T extends Record<string, Context.Service<any, any> | Effect.Effect<any, any, any>>, A>(
|
|
165
163
|
services: T,
|
|
166
164
|
fn: (services: LowerServices<T>) => A
|
|
167
165
|
) {
|
|
@@ -169,7 +167,7 @@ export function allLowerWith<T extends Record<string, ServiceMap.Service<any, an
|
|
|
169
167
|
}
|
|
170
168
|
|
|
171
169
|
export function allLowerWithEffect<
|
|
172
|
-
T extends Record<string,
|
|
170
|
+
T extends Record<string, Context.Service<any, any> | Effect.Effect<any, any, any>>,
|
|
173
171
|
R,
|
|
174
172
|
E,
|
|
175
173
|
A
|
package/src/Layer.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { type Array, Effect, Layer, type Scope, type
|
|
1
|
+
import { type Array, Effect, Layer, type Scope, type Types } from "effect"
|
|
2
2
|
import { type Yieldable } from "effect/Effect"
|
|
3
3
|
import { dual } from "effect/Function"
|
|
4
|
+
import type * as Context from "./Context.js"
|
|
4
5
|
import { type EffectGenUtils } from "./utils/gen.js"
|
|
5
6
|
|
|
6
7
|
export * from "effect/Layer"
|
|
@@ -11,13 +12,13 @@ type MakeEff<S, E, R> = {
|
|
|
11
12
|
readonly make: Effect.Effect<S, E, R>
|
|
12
13
|
}
|
|
13
14
|
type MakeGen<S, E = never, R = never> = {
|
|
14
|
-
readonly make: () => Generator<Yieldable<any, any, E, R>, S
|
|
15
|
+
readonly make: () => Generator<Yieldable<any, any, E, R>, S>
|
|
15
16
|
}
|
|
16
17
|
type MakeGenNo<S> = {
|
|
17
18
|
readonly make: () => Generator<unknown, S>
|
|
18
19
|
}
|
|
19
20
|
type MakeErr<Opts> = Opts extends { make: () => any } ? EffectGenUtils.Error<Opts["make"]> : never
|
|
20
|
-
type MakeContext<Opts> = Opts extends { make: () => any } ? EffectGenUtils.
|
|
21
|
+
type MakeContext<Opts> = Opts extends { make: () => any } ? EffectGenUtils.Context<Opts["make"]> : never
|
|
21
22
|
|
|
22
23
|
type DependenciesOpt = { dependencies?: Array.NonEmptyReadonlyArray<Layer.Any> }
|
|
23
24
|
type Dependencies = { dependencies: Array.NonEmptyReadonlyArray<Layer.Any> }
|
|
@@ -41,12 +42,12 @@ type PackedOrUnpackedLayer<I, Opts> = Opts extends Dependencies ? PackedLayers<I
|
|
|
41
42
|
|
|
42
43
|
export const make: {
|
|
43
44
|
<I, S>(
|
|
44
|
-
tag:
|
|
45
|
+
tag: Context.Service<I, S>
|
|
45
46
|
): <Opts extends Make<Types.NoInfer<S>, any, any>>(
|
|
46
47
|
options: Opts
|
|
47
48
|
) => PackedOrUnpackedLayer<I, Opts>
|
|
48
49
|
<I, S, Opts extends Make<Types.NoInfer<S>, any, any>>(
|
|
49
|
-
tag:
|
|
50
|
+
tag: Context.Service<I, S>,
|
|
50
51
|
options: Opts
|
|
51
52
|
): PackedOrUnpackedLayer<I, Opts>
|
|
52
53
|
} = dual(2, (tag, options) => {
|
package/src/Pure.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
2
|
import { Chunk, Effect, Layer, Result } from "effect"
|
|
3
|
+
import * as Context from "./Context.js"
|
|
3
4
|
import { tuple } from "./Function.js"
|
|
4
|
-
import * as ServiceMap from "./ServiceMap.js"
|
|
5
5
|
|
|
6
6
|
const S1 = Symbol()
|
|
7
7
|
const S2 = Symbol()
|
|
@@ -86,9 +86,9 @@ export function GMU<W, S, S2, GA, MR, ME>(modify: (i: GA) => Pure<W, S, S2, MR,
|
|
|
86
86
|
) => GMU_(get, modify, update)
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
-
const tagg =
|
|
89
|
+
const tagg = Context.Service<{ env: PureEnv<never, unknown, never> }>("PureEnv")
|
|
90
90
|
function castTag<W, S, S2>() {
|
|
91
|
-
return tagg as any as
|
|
91
|
+
return tagg as any as Context.Service<PureEnvEnv<W, S, S2>, PureEnvEnv<W, S, S2>>
|
|
92
92
|
}
|
|
93
93
|
|
|
94
94
|
export const ServiceTag = Symbol()
|
|
@@ -100,9 +100,9 @@ export abstract class PhantomTypeParameter<Identifier extends keyof any, Instant
|
|
|
100
100
|
}
|
|
101
101
|
}
|
|
102
102
|
|
|
103
|
-
export type ServiceShape<T extends
|
|
103
|
+
export type ServiceShape<T extends Context.ServiceClass.Shape<any, any>> = Omit<
|
|
104
104
|
T,
|
|
105
|
-
keyof
|
|
105
|
+
keyof Context.ServiceClass.Shape<any, any>
|
|
106
106
|
>
|
|
107
107
|
|
|
108
108
|
export abstract class ServiceTagged<ServiceKey> extends PhantomTypeParameter<string, ServiceKey> {}
|
|
@@ -117,11 +117,11 @@ export interface PureEnvEnv<W, S, S2> extends ServiceTagged<typeof PureEnvEnv> {
|
|
|
117
117
|
}
|
|
118
118
|
|
|
119
119
|
export function get<S>(): Pure<never, S, S, never, never, S> {
|
|
120
|
-
return (castTag<never, S, S>()
|
|
120
|
+
return (castTag<never, S, S>()).useSync((_) => _.env.state)
|
|
121
121
|
}
|
|
122
122
|
|
|
123
123
|
export function set<S>(s: S): Pure<never, S, S, never, never, void> {
|
|
124
|
-
return (castTag<never, S, S>()
|
|
124
|
+
return (castTag<never, S, S>()).useSync((_) => {
|
|
125
125
|
_.env.state = s
|
|
126
126
|
})
|
|
127
127
|
}
|
|
@@ -129,13 +129,13 @@ export function set<S>(s: S): Pure<never, S, S, never, never, void> {
|
|
|
129
129
|
export type PureLogT<W> = Pure<W, unknown, never, never, never, void>
|
|
130
130
|
|
|
131
131
|
export function log<W>(w: W): PureLogT<W> {
|
|
132
|
-
return (castTag<W, unknown, never>()
|
|
132
|
+
return (castTag<W, unknown, never>()).useSync((_) => {
|
|
133
133
|
_.env.log = Chunk.append(_.env.log, w)
|
|
134
134
|
})
|
|
135
135
|
}
|
|
136
136
|
|
|
137
137
|
export function logMany<W>(w: Iterable<W>): PureLogT<W> {
|
|
138
|
-
return (castTag<W, unknown, never>()
|
|
138
|
+
return (castTag<W, unknown, never>()).useSync((_) => {
|
|
139
139
|
_.env.log = Chunk.appendAll(_.env.log, Chunk.fromIterable(w))
|
|
140
140
|
})
|
|
141
141
|
}
|
|
@@ -150,17 +150,16 @@ export function runAll<R, E, A, W3, S1, S3, S4 extends S1>(
|
|
|
150
150
|
> {
|
|
151
151
|
const a = Effect
|
|
152
152
|
.flatMap(self, (x) =>
|
|
153
|
-
(castTag<W3, S1, S3>()
|
|
154
|
-
.
|
|
155
|
-
({ env: _ }
|
|
153
|
+
(castTag<W3, S1, S3>())
|
|
154
|
+
.useSync(
|
|
155
|
+
({ env: _ }) => ({ log: _.log, state: _.state })
|
|
156
156
|
)
|
|
157
157
|
.pipe(
|
|
158
|
-
Effect.flatMap((_: any) => Effect.succeed(_)),
|
|
159
158
|
Effect.map(
|
|
160
|
-
({ log, state }
|
|
159
|
+
({ log, state }) => tuple(log, Result.succeed(tuple(state, x)))
|
|
161
160
|
)
|
|
162
161
|
))
|
|
163
|
-
.pipe(Effect.catch((err: any) =>
|
|
162
|
+
.pipe(Effect.catch((err: any) => tagg.useSync((env) => tuple(env.env.log, Result.fail(err)))))
|
|
164
163
|
return Effect.provide(a, Layer.succeed(tagg, { env: makePureEnv<W3, S3, S4>(s) as any }) as any) as any
|
|
165
164
|
}
|
|
166
165
|
|
|
@@ -198,11 +197,11 @@ export function runA<R, E, A, W3, S1, S3, S4 extends S1>(
|
|
|
198
197
|
export function modify<S2, A, S3>(
|
|
199
198
|
mod: (s: S2) => readonly [S3, A]
|
|
200
199
|
): Effect.Effect<A, never, { env: PureEnv<never, S2, S3> }> {
|
|
201
|
-
return (castTag<never, S3, S2>()
|
|
200
|
+
return (castTag<never, S3, S2>()).useSync((_) => {
|
|
202
201
|
const [s, a] = mod(_.env.state)
|
|
203
202
|
_.env.state = s as any
|
|
204
203
|
return a
|
|
205
|
-
})
|
|
204
|
+
}) as any
|
|
206
205
|
}
|
|
207
206
|
|
|
208
207
|
export function modifyM<W, R, E, A, S2, S3>(
|
|
@@ -210,7 +209,7 @@ export function modifyM<W, R, E, A, S2, S3>(
|
|
|
210
209
|
): Effect.Effect<A, E, FixEnv<R, W, S2, S3>> {
|
|
211
210
|
// return serviceWithEffect(_ => Ref.modifyM_(_.state, mod))
|
|
212
211
|
return Effect.flatMap(
|
|
213
|
-
(castTag<W, S3, S2>()
|
|
212
|
+
(castTag<W, S3, S2>()).useSync((_) => _),
|
|
214
213
|
(_: any) =>
|
|
215
214
|
Effect.map(mod(_.env.state), ([s, a]: any) => {
|
|
216
215
|
_.env.state = s
|