effect 4.0.0-beta.97 → 4.0.0-beta.99
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 +1 -3
- package/dist/Array.js +1 -1
- package/dist/Array.js.map +1 -1
- package/dist/Graph.d.ts +1187 -196
- package/dist/Graph.d.ts.map +1 -1
- package/dist/Graph.js +1031 -283
- package/dist/Graph.js.map +1 -1
- package/dist/Iterable.d.ts.map +1 -1
- package/dist/Iterable.js +41 -1
- package/dist/Iterable.js.map +1 -1
- package/dist/LayerRef.d.ts +4 -6
- package/dist/LayerRef.d.ts.map +1 -1
- package/dist/LayerRef.js +4 -6
- package/dist/LayerRef.js.map +1 -1
- package/dist/Number.d.ts.map +1 -1
- package/dist/Number.js +28 -10
- package/dist/Number.js.map +1 -1
- package/dist/Schema.d.ts +22 -22
- package/dist/Schema.d.ts.map +1 -1
- package/dist/Schema.js +37 -34
- package/dist/Schema.js.map +1 -1
- package/dist/SchemaAST.d.ts.map +1 -1
- package/dist/SchemaAST.js +25 -10
- package/dist/SchemaAST.js.map +1 -1
- package/dist/SchemaError.d.ts +53 -0
- package/dist/SchemaError.d.ts.map +1 -0
- package/dist/SchemaError.js +61 -0
- package/dist/SchemaError.js.map +1 -0
- package/dist/SchemaGetter.d.ts.map +1 -1
- package/dist/SchemaGetter.js +17 -12
- package/dist/SchemaGetter.js.map +1 -1
- package/dist/SchemaRepresentation.d.ts.map +1 -1
- package/dist/SchemaRepresentation.js +186 -224
- package/dist/SchemaRepresentation.js.map +1 -1
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -1
- package/dist/internal/effect.js +35 -11
- package/dist/internal/effect.js.map +1 -1
- package/dist/internal/schema/equivalence.js +1 -2
- package/dist/internal/schema/equivalence.js.map +1 -1
- package/dist/internal/schema/representation.js +1 -3
- package/dist/internal/schema/representation.js.map +1 -1
- package/dist/internal/schema/schema.d.ts +0 -13
- package/dist/internal/schema/schema.d.ts.map +1 -1
- package/dist/internal/schema/schema.js +4 -29
- package/dist/internal/schema/schema.js.map +1 -1
- package/dist/unstable/ai/Tool.d.ts.map +1 -1
- package/dist/unstable/ai/Tool.js +11 -13
- package/dist/unstable/ai/Tool.js.map +1 -1
- package/dist/unstable/cli/CliConfig.d.ts +76 -0
- package/dist/unstable/cli/CliConfig.d.ts.map +1 -0
- package/dist/unstable/cli/CliConfig.js +63 -0
- package/dist/unstable/cli/CliConfig.js.map +1 -0
- package/dist/unstable/cli/CliError.d.ts +8 -16
- package/dist/unstable/cli/CliError.d.ts.map +1 -1
- package/dist/unstable/cli/CliError.js +11 -16
- package/dist/unstable/cli/CliError.js.map +1 -1
- package/dist/unstable/cli/Command.d.ts +40 -4
- package/dist/unstable/cli/Command.d.ts.map +1 -1
- package/dist/unstable/cli/Command.js +63 -6
- package/dist/unstable/cli/Command.js.map +1 -1
- package/dist/unstable/cli/GlobalFlag.d.ts +24 -5
- package/dist/unstable/cli/GlobalFlag.d.ts.map +1 -1
- package/dist/unstable/cli/GlobalFlag.js +26 -10
- package/dist/unstable/cli/GlobalFlag.js.map +1 -1
- package/dist/unstable/cli/Param.js +6 -2
- package/dist/unstable/cli/Param.js.map +1 -1
- package/dist/unstable/cli/index.d.ts +4 -0
- package/dist/unstable/cli/index.d.ts.map +1 -1
- package/dist/unstable/cli/index.js +4 -0
- package/dist/unstable/cli/index.js.map +1 -1
- package/dist/unstable/cli/internal/ansi.d.ts.map +1 -1
- package/dist/unstable/cli/internal/ansi.js +2 -0
- package/dist/unstable/cli/internal/ansi.js.map +1 -1
- package/dist/unstable/cli/internal/parser.js +11 -2
- package/dist/unstable/cli/internal/parser.js.map +1 -1
- package/dist/unstable/cli/internal/wizard.d.ts +13 -0
- package/dist/unstable/cli/internal/wizard.d.ts.map +1 -0
- package/dist/unstable/cli/internal/wizard.js +212 -0
- package/dist/unstable/cli/internal/wizard.js.map +1 -0
- package/dist/unstable/cluster/EntityProxyServer.d.ts +1 -1
- package/dist/unstable/cluster/EntityProxyServer.d.ts.map +1 -1
- package/dist/unstable/cluster/EntityProxyServer.js +2 -4
- package/dist/unstable/cluster/EntityProxyServer.js.map +1 -1
- package/dist/unstable/cluster/RunnerStorage.js +1 -1
- package/dist/unstable/cluster/RunnerStorage.js.map +1 -1
- package/dist/unstable/cluster/internal/entityManager.js +15 -12
- package/dist/unstable/cluster/internal/entityManager.js.map +1 -1
- package/dist/unstable/http/Multipart.d.ts.map +1 -1
- package/dist/unstable/http/Multipart.js +3 -1
- package/dist/unstable/http/Multipart.js.map +1 -1
- package/dist/unstable/httpapi/HttpApi.d.ts +36 -15
- package/dist/unstable/httpapi/HttpApi.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApi.js +19 -20
- package/dist/unstable/httpapi/HttpApi.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiBuilder.d.ts +51 -62
- package/dist/unstable/httpapi/HttpApiBuilder.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiBuilder.js +68 -58
- package/dist/unstable/httpapi/HttpApiBuilder.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiClient.d.ts +53 -53
- package/dist/unstable/httpapi/HttpApiClient.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiClient.js +40 -30
- package/dist/unstable/httpapi/HttpApiClient.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiEndpoint.d.ts +165 -164
- package/dist/unstable/httpapi/HttpApiEndpoint.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiEndpoint.js +31 -19
- package/dist/unstable/httpapi/HttpApiEndpoint.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiError.d.ts +22 -0
- package/dist/unstable/httpapi/HttpApiError.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiError.js +31 -0
- package/dist/unstable/httpapi/HttpApiError.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiGroup.d.ts +55 -30
- package/dist/unstable/httpapi/HttpApiGroup.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiGroup.js +22 -29
- package/dist/unstable/httpapi/HttpApiGroup.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiMiddleware.d.ts +8 -8
- package/dist/unstable/httpapi/HttpApiMiddleware.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiMiddleware.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiScalar.d.ts +2 -2
- package/dist/unstable/httpapi/HttpApiScalar.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiScalar.js +4 -3
- package/dist/unstable/httpapi/HttpApiScalar.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiSchema.d.ts +8 -0
- package/dist/unstable/httpapi/HttpApiSchema.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiSchema.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiSwagger.d.ts +1 -1
- package/dist/unstable/httpapi/HttpApiSwagger.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiSwagger.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiTest.d.ts +4 -4
- package/dist/unstable/httpapi/HttpApiTest.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiTest.js +9 -8
- package/dist/unstable/httpapi/HttpApiTest.js.map +1 -1
- package/dist/unstable/httpapi/OpenApi.d.ts +1 -1
- package/dist/unstable/httpapi/OpenApi.d.ts.map +1 -1
- package/dist/unstable/httpapi/OpenApi.js +77 -37
- package/dist/unstable/httpapi/OpenApi.js.map +1 -1
- package/dist/unstable/httpapi/internal/html.js +6 -2
- package/dist/unstable/httpapi/internal/html.js.map +1 -1
- package/dist/unstable/httpapi/internal/mediaType.d.ts +2 -0
- package/dist/unstable/httpapi/internal/mediaType.d.ts.map +1 -0
- package/dist/unstable/httpapi/internal/mediaType.js +7 -0
- package/dist/unstable/httpapi/internal/mediaType.js.map +1 -0
- package/dist/unstable/persistence/PersistedQueue.d.ts.map +1 -1
- package/dist/unstable/persistence/PersistedQueue.js +16 -12
- package/dist/unstable/persistence/PersistedQueue.js.map +1 -1
- package/dist/unstable/persistence/Redis.d.ts.map +1 -1
- package/dist/unstable/persistence/Redis.js +5 -3
- package/dist/unstable/persistence/Redis.js.map +1 -1
- package/dist/unstable/reactivity/Atom.js +1 -1
- package/dist/unstable/reactivity/Atom.js.map +1 -1
- package/dist/unstable/reactivity/AtomHttpApi.d.ts +7 -7
- package/dist/unstable/reactivity/AtomHttpApi.d.ts.map +1 -1
- package/dist/unstable/reactivity/AtomHttpApi.js +3 -2
- package/dist/unstable/reactivity/AtomHttpApi.js.map +1 -1
- package/dist/unstable/rpc/RpcServer.d.ts +3 -1
- package/dist/unstable/rpc/RpcServer.d.ts.map +1 -1
- package/dist/unstable/rpc/RpcServer.js +6 -3
- package/dist/unstable/rpc/RpcServer.js.map +1 -1
- package/dist/unstable/sql/SqlClient.d.ts +1 -2
- package/dist/unstable/sql/SqlClient.d.ts.map +1 -1
- package/dist/unstable/sql/SqlClient.js.map +1 -1
- package/dist/unstable/workflow/DurableDeferred.js +1 -1
- package/dist/unstable/workflow/DurableDeferred.js.map +1 -1
- package/dist/unstable/workflow/WorkflowProxyServer.d.ts +1 -1
- package/dist/unstable/workflow/WorkflowProxyServer.d.ts.map +1 -1
- package/dist/unstable/workflow/WorkflowProxyServer.js +1 -2
- package/dist/unstable/workflow/WorkflowProxyServer.js.map +1 -1
- package/package.json +3 -3
- package/src/Array.ts +1 -1
- package/src/Graph.ts +2967 -457
- package/src/Iterable.ts +32 -2
- package/src/LayerRef.ts +4 -6
- package/src/Number.ts +29 -10
- package/src/Schema.ts +43 -35
- package/src/SchemaAST.ts +25 -13
- package/src/SchemaError.ts +64 -0
- package/src/SchemaGetter.ts +22 -16
- package/src/SchemaRepresentation.ts +165 -202
- package/src/index.ts +10 -0
- package/src/internal/effect.ts +48 -25
- package/src/internal/schema/equivalence.ts +1 -2
- package/src/internal/schema/representation.ts +4 -4
- package/src/internal/schema/schema.ts +4 -37
- package/src/unstable/ai/Tool.ts +13 -16
- package/src/unstable/cli/CliConfig.ts +85 -0
- package/src/unstable/cli/CliError.ts +27 -16
- package/src/unstable/cli/Command.ts +90 -14
- package/src/unstable/cli/GlobalFlag.ts +46 -29
- package/src/unstable/cli/Param.ts +15 -3
- package/src/unstable/cli/index.ts +5 -0
- package/src/unstable/cli/internal/ansi.ts +3 -0
- package/src/unstable/cli/internal/parser.ts +14 -2
- package/src/unstable/cli/internal/wizard.ts +283 -0
- package/src/unstable/cluster/EntityProxyServer.ts +15 -17
- package/src/unstable/cluster/RunnerStorage.ts +1 -1
- package/src/unstable/cluster/internal/entityManager.ts +48 -34
- package/src/unstable/http/Multipart.ts +3 -1
- package/src/unstable/httpapi/HttpApi.ts +72 -47
- package/src/unstable/httpapi/HttpApiBuilder.ts +320 -217
- package/src/unstable/httpapi/HttpApiClient.ts +196 -151
- package/src/unstable/httpapi/HttpApiEndpoint.ts +251 -447
- package/src/unstable/httpapi/HttpApiError.ts +33 -0
- package/src/unstable/httpapi/HttpApiGroup.ts +95 -74
- package/src/unstable/httpapi/HttpApiMiddleware.ts +10 -7
- package/src/unstable/httpapi/HttpApiScalar.ts +15 -12
- package/src/unstable/httpapi/HttpApiSchema.ts +8 -0
- package/src/unstable/httpapi/HttpApiSwagger.ts +2 -2
- package/src/unstable/httpapi/HttpApiTest.ts +15 -14
- package/src/unstable/httpapi/OpenApi.ts +74 -36
- package/src/unstable/httpapi/internal/html.ts +9 -2
- package/src/unstable/httpapi/internal/mediaType.ts +6 -0
- package/src/unstable/persistence/PersistedQueue.ts +16 -14
- package/src/unstable/persistence/Redis.ts +9 -4
- package/src/unstable/reactivity/Atom.ts +1 -1
- package/src/unstable/reactivity/AtomHttpApi.ts +164 -162
- package/src/unstable/rpc/RpcServer.ts +10 -4
- package/src/unstable/sql/SqlClient.ts +1 -2
- package/src/unstable/workflow/DurableDeferred.ts +1 -1
- package/src/unstable/workflow/WorkflowProxyServer.ts +11 -12
|
@@ -40,7 +40,7 @@ import * as Reactivity from "./Reactivity.ts"
|
|
|
40
40
|
* @category models
|
|
41
41
|
* @since 4.0.0
|
|
42
42
|
*/
|
|
43
|
-
export interface AtomHttpApiClient<Self, Id extends string, Groups extends HttpApiGroup.
|
|
43
|
+
export interface AtomHttpApiClient<Self, Id extends string, Groups extends HttpApiGroup.Constraint>
|
|
44
44
|
extends Context.Service<Self, HttpApiClient.Client<Groups, never, never>>
|
|
45
45
|
{
|
|
46
46
|
new(_: never): Context.ServiceClass.Shape<Id, HttpApiClient.Client<Groups, never, never>>
|
|
@@ -48,23 +48,23 @@ export interface AtomHttpApiClient<Self, Id extends string, Groups extends HttpA
|
|
|
48
48
|
readonly runtime: Atom.AtomRuntime<Self>
|
|
49
49
|
|
|
50
50
|
readonly mutation: <
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
Group extends HttpApiGroup.
|
|
54
|
-
Endpoint extends HttpApiEndpoint.
|
|
51
|
+
GroupIdentifier extends HttpApiGroup.Identifier<Groups>,
|
|
52
|
+
EndpointIdentifier extends HttpApiEndpoint.Identifier<HttpApiGroup.Endpoints<Group>>,
|
|
53
|
+
Group extends HttpApiGroup.Constraint = HttpApiGroup.WithIdentifier<Groups, GroupIdentifier>,
|
|
54
|
+
Endpoint extends HttpApiEndpoint.Constraint = HttpApiEndpoint.WithIdentifier<
|
|
55
55
|
HttpApiGroup.Endpoints<Group>,
|
|
56
|
-
|
|
56
|
+
EndpointIdentifier
|
|
57
57
|
>,
|
|
58
58
|
const ResponseMode extends HttpApiEndpoint.ClientResponseMode = HttpApiEndpoint.ClientResponseMode
|
|
59
59
|
>(
|
|
60
|
-
group:
|
|
61
|
-
endpoint:
|
|
60
|
+
group: GroupIdentifier,
|
|
61
|
+
endpoint: EndpointIdentifier,
|
|
62
62
|
options?: {
|
|
63
63
|
readonly responseMode?: ResponseMode | undefined
|
|
64
64
|
}
|
|
65
65
|
) => [Endpoint] extends [
|
|
66
66
|
HttpApiEndpoint.HttpApiEndpoint<
|
|
67
|
-
infer
|
|
67
|
+
infer _Identifier,
|
|
68
68
|
infer _Method,
|
|
69
69
|
infer _Path,
|
|
70
70
|
infer _Params,
|
|
@@ -88,20 +88,20 @@ export interface AtomHttpApiClient<Self, Id extends string, Groups extends HttpA
|
|
|
88
88
|
: never
|
|
89
89
|
|
|
90
90
|
readonly query: <
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
Group extends HttpApiGroup.
|
|
94
|
-
Endpoint extends HttpApiEndpoint.
|
|
91
|
+
GroupIdentifier extends HttpApiGroup.Identifier<Groups>,
|
|
92
|
+
EndpointIdentifier extends HttpApiEndpoint.Identifier<HttpApiGroup.Endpoints<Group>>,
|
|
93
|
+
Group extends HttpApiGroup.Constraint = HttpApiGroup.WithIdentifier<Groups, GroupIdentifier>,
|
|
94
|
+
Endpoint extends HttpApiEndpoint.Constraint = HttpApiEndpoint.WithIdentifier<
|
|
95
95
|
HttpApiGroup.Endpoints<Group>,
|
|
96
|
-
|
|
96
|
+
EndpointIdentifier
|
|
97
97
|
>,
|
|
98
98
|
const ResponseMode extends HttpApiEndpoint.ClientResponseMode = "decoded-only"
|
|
99
99
|
>(
|
|
100
|
-
group:
|
|
101
|
-
endpoint:
|
|
100
|
+
group: GroupIdentifier,
|
|
101
|
+
endpoint: EndpointIdentifier,
|
|
102
102
|
request: [Endpoint] extends [
|
|
103
103
|
HttpApiEndpoint.HttpApiEndpoint<
|
|
104
|
-
infer
|
|
104
|
+
infer _Identifier,
|
|
105
105
|
infer _Method,
|
|
106
106
|
infer _Path,
|
|
107
107
|
infer _Params,
|
|
@@ -126,7 +126,7 @@ export interface AtomHttpApiClient<Self, Id extends string, Groups extends HttpA
|
|
|
126
126
|
: never
|
|
127
127
|
) => [Endpoint] extends [
|
|
128
128
|
HttpApiEndpoint.HttpApiEndpoint<
|
|
129
|
-
infer
|
|
129
|
+
infer _Identifier,
|
|
130
130
|
infer _Method,
|
|
131
131
|
infer _Path,
|
|
132
132
|
infer _Params,
|
|
@@ -166,157 +166,159 @@ declare global {
|
|
|
166
166
|
* @category constructors
|
|
167
167
|
* @since 4.0.0
|
|
168
168
|
*/
|
|
169
|
-
export const Service =
|
|
170
|
-
<
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
Self,
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
const layer = Layer.effect(
|
|
197
|
-
self,
|
|
198
|
-
HttpApiClient.make(options.api, options)
|
|
199
|
-
)
|
|
200
|
-
const runtimeFactory = options.runtime ?? Atom.runtime
|
|
201
|
-
self.runtime = runtimeFactory(
|
|
202
|
-
typeof options.httpClient === "function" ?
|
|
203
|
-
(get) =>
|
|
204
|
-
Layer.provide(
|
|
205
|
-
layer,
|
|
206
|
-
(options.httpClient as (get: Atom.AtomContext) => Layer.Layer<
|
|
207
|
-
| HttpApiGroup.ClientServices<Groups>
|
|
208
|
-
| HttpClient.HttpClient
|
|
209
|
-
>)(get)
|
|
210
|
-
) as Layer.Layer<Self> :
|
|
211
|
-
Layer.provide(layer, options.httpClient) as Layer.Layer<Self>
|
|
212
|
-
)
|
|
169
|
+
export const Service =
|
|
170
|
+
<Self>() =>
|
|
171
|
+
<const Id extends string, ApiId extends string, Groups extends HttpApiGroup.Constraint>(
|
|
172
|
+
id: Id,
|
|
173
|
+
options: {
|
|
174
|
+
readonly api: HttpApi.HttpApi<ApiId, Groups>
|
|
175
|
+
readonly httpClient:
|
|
176
|
+
| Layer.Layer<
|
|
177
|
+
| HttpApiGroup.ClientServices<Groups>
|
|
178
|
+
| HttpClient.HttpClient
|
|
179
|
+
>
|
|
180
|
+
| ((get: Atom.AtomContext) => Layer.Layer<
|
|
181
|
+
| HttpApiGroup.ClientServices<Groups>
|
|
182
|
+
| HttpClient.HttpClient
|
|
183
|
+
>)
|
|
184
|
+
readonly transformClient?: ((client: HttpClient.HttpClient) => HttpClient.HttpClient) | undefined
|
|
185
|
+
readonly transformResponse?:
|
|
186
|
+
| ((effect: Effect.Effect<unknown, unknown, unknown>) => Effect.Effect<unknown, unknown, unknown>)
|
|
187
|
+
| undefined
|
|
188
|
+
readonly baseUrl?: URL | string | undefined
|
|
189
|
+
readonly runtime?: Atom.RuntimeFactory | undefined
|
|
190
|
+
}
|
|
191
|
+
): AtomHttpApiClient<Self, Id, Groups> => {
|
|
192
|
+
const self: Mutable<AtomHttpApiClient<Self, Id, Groups>> = Context.Service<
|
|
193
|
+
Self,
|
|
194
|
+
HttpApiClient.Client<Groups, never, never>
|
|
195
|
+
>()(id) as any
|
|
213
196
|
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
197
|
+
const layer = Layer.effect(
|
|
198
|
+
self,
|
|
199
|
+
HttpApiClient.make(options.api, options)
|
|
200
|
+
)
|
|
201
|
+
const runtimeFactory = options.runtime ?? Atom.runtime
|
|
202
|
+
self.runtime = runtimeFactory(
|
|
203
|
+
typeof options.httpClient === "function" ?
|
|
204
|
+
(get) =>
|
|
205
|
+
Layer.provide(
|
|
206
|
+
layer,
|
|
207
|
+
(options.httpClient as (get: Atom.AtomContext) => Layer.Layer<
|
|
208
|
+
| HttpApiGroup.ClientServices<Groups>
|
|
209
|
+
| HttpClient.HttpClient
|
|
210
|
+
>)(get)
|
|
211
|
+
) as Layer.Layer<Self> :
|
|
212
|
+
Layer.provide(layer, options.httpClient) as Layer.Layer<Self>
|
|
213
|
+
)
|
|
217
214
|
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
params: any
|
|
221
|
-
query: any
|
|
222
|
-
headers: any
|
|
223
|
-
payload: any
|
|
224
|
-
reactivityKeys?: ReadonlyArray<unknown> | ReadonlyRecord<string, ReadonlyArray<unknown>> | undefined
|
|
225
|
-
}>()(
|
|
226
|
-
Effect.fnUntraced(function*(opts) {
|
|
227
|
-
const client = (yield* self) as any
|
|
228
|
-
const effect = catchErrors(client[group][endpoint]({
|
|
229
|
-
...opts,
|
|
230
|
-
responseMode
|
|
231
|
-
}) as Effect.Effect<any>)
|
|
232
|
-
return yield* opts.reactivityKeys
|
|
233
|
-
? Reactivity.mutation(effect, opts.reactivityKeys)
|
|
234
|
-
: effect
|
|
235
|
-
})
|
|
215
|
+
const catchErrors = Effect.catch((e: unknown) =>
|
|
216
|
+
Schema.isSchemaError(e) || HttpClientError.isHttpClientError(e) ? Effect.die(e) : Effect.fail(e)
|
|
236
217
|
)
|
|
237
|
-
|
|
238
|
-
const definition = options.api.groups[group]!.endpoints[endpoint]! as HttpApiEndpoint.AnyWithProps
|
|
239
|
-
return Atom.serializable(atom, {
|
|
240
|
-
key: `AtomHttpApi:mutation:${group}:${endpoint}`,
|
|
241
|
-
schema: AsyncResult.Schema({
|
|
242
|
-
success: Schema.Union(HttpApiEndpoint.getSuccessSchemas(definition)),
|
|
243
|
-
error: Schema.Union(HttpApiEndpoint.getErrorSchemas(definition))
|
|
244
|
-
}) as any
|
|
245
|
-
})
|
|
246
|
-
}
|
|
247
|
-
return atom
|
|
248
|
-
}) as any
|
|
218
|
+
const groups = options.api.groups as unknown as Record<string, HttpApiGroup.Top>
|
|
249
219
|
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
220
|
+
const mutationFamily = Atom.family(({ endpoint, group, responseMode }: MutationKey) => {
|
|
221
|
+
const atom = self.runtime.fn<{
|
|
222
|
+
params: any
|
|
223
|
+
query: any
|
|
224
|
+
headers: any
|
|
225
|
+
payload: any
|
|
226
|
+
reactivityKeys?: ReadonlyArray<unknown> | ReadonlyRecord<string, ReadonlyArray<unknown>> | undefined
|
|
227
|
+
}>()(
|
|
228
|
+
Effect.fnUntraced(function*(opts) {
|
|
229
|
+
const client = (yield* self) as any
|
|
230
|
+
const effect = catchErrors(client[group][endpoint]({
|
|
231
|
+
...opts,
|
|
232
|
+
responseMode
|
|
233
|
+
}) as Effect.Effect<any>)
|
|
234
|
+
return yield* opts.reactivityKeys
|
|
235
|
+
? Reactivity.mutation(effect, opts.reactivityKeys)
|
|
236
|
+
: effect
|
|
237
|
+
})
|
|
238
|
+
)
|
|
239
|
+
if (responseMode === "decoded-only") {
|
|
240
|
+
const definition = groups[group].endpoints[endpoint]
|
|
241
|
+
return Atom.serializable(atom, {
|
|
242
|
+
key: `AtomHttpApi:mutation:${group}:${endpoint}`,
|
|
243
|
+
schema: AsyncResult.Schema({
|
|
244
|
+
success: Schema.Union(HttpApiEndpoint.getSuccessSchemas(definition)),
|
|
245
|
+
error: Schema.Union(HttpApiEndpoint.getErrorSchemas(definition))
|
|
246
|
+
}) as any
|
|
247
|
+
})
|
|
248
|
+
}
|
|
249
|
+
return atom
|
|
250
|
+
}) as any
|
|
258
251
|
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
if (opts.responseMode === "decoded-only" && opts.serializationKey) {
|
|
268
|
-
const endpoint = options.api.groups[opts.group]!.endpoints[opts.endpoint]! as HttpApiEndpoint.AnyWithProps
|
|
269
|
-
atom = Atom.serializable(atom, {
|
|
270
|
-
key: `AtomHttpApi:${opts.group}:${opts.endpoint}:${opts.serializationKey}`,
|
|
271
|
-
schema: AsyncResult.Schema({
|
|
272
|
-
success: Schema.Union(HttpApiEndpoint.getSuccessSchemas(endpoint)),
|
|
273
|
-
error: Schema.Union(HttpApiEndpoint.getErrorSchemas(endpoint))
|
|
274
|
-
}) as any
|
|
275
|
-
})
|
|
276
|
-
}
|
|
277
|
-
if (opts.timeToLive) {
|
|
278
|
-
atom = Duration.isFinite(opts.timeToLive)
|
|
279
|
-
? Atom.setIdleTTL(atom, opts.timeToLive)
|
|
280
|
-
: Atom.keepAlive(atom)
|
|
281
|
-
}
|
|
282
|
-
return opts.reactivityKeys
|
|
283
|
-
? self.runtime.factory.withReactivity(opts.reactivityKeys)(atom)
|
|
284
|
-
: atom
|
|
285
|
-
})
|
|
252
|
+
self.mutation = ((group: string, endpoint: string, options?: {
|
|
253
|
+
readonly responseMode?: HttpApiEndpoint.ClientResponseMode | undefined
|
|
254
|
+
}) =>
|
|
255
|
+
mutationFamily({
|
|
256
|
+
group,
|
|
257
|
+
endpoint,
|
|
258
|
+
responseMode: options?.responseMode ?? "decoded-only"
|
|
259
|
+
})) as any
|
|
286
260
|
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
?
|
|
312
|
-
:
|
|
313
|
-
|
|
314
|
-
}
|
|
315
|
-
return queryFamily(key)
|
|
316
|
-
}) as any
|
|
261
|
+
const queryFamily = Atom.family((opts: QueryKey) => {
|
|
262
|
+
let atom = self.runtime.atom(self.use((client_) => {
|
|
263
|
+
const client = client_ as any
|
|
264
|
+
return catchErrors(client[opts.group][opts.endpoint](opts) as Effect.Effect<
|
|
265
|
+
any,
|
|
266
|
+
HttpClientError.HttpClientError | SchemaError
|
|
267
|
+
>)
|
|
268
|
+
}))
|
|
269
|
+
if (opts.responseMode === "decoded-only" && opts.serializationKey) {
|
|
270
|
+
const endpoint = groups[opts.group].endpoints[opts.endpoint]
|
|
271
|
+
atom = Atom.serializable(atom, {
|
|
272
|
+
key: `AtomHttpApi:${opts.group}:${opts.endpoint}:${opts.serializationKey}`,
|
|
273
|
+
schema: AsyncResult.Schema({
|
|
274
|
+
success: Schema.Union(HttpApiEndpoint.getSuccessSchemas(endpoint)),
|
|
275
|
+
error: Schema.Union(HttpApiEndpoint.getErrorSchemas(endpoint))
|
|
276
|
+
}) as any
|
|
277
|
+
})
|
|
278
|
+
}
|
|
279
|
+
if (opts.timeToLive) {
|
|
280
|
+
atom = Duration.isFinite(opts.timeToLive)
|
|
281
|
+
? Atom.setIdleTTL(atom, opts.timeToLive)
|
|
282
|
+
: Atom.keepAlive(atom)
|
|
283
|
+
}
|
|
284
|
+
return opts.reactivityKeys
|
|
285
|
+
? self.runtime.factory.withReactivity(opts.reactivityKeys)(atom)
|
|
286
|
+
: atom
|
|
287
|
+
})
|
|
317
288
|
|
|
318
|
-
|
|
319
|
-
|
|
289
|
+
self.query = ((
|
|
290
|
+
group: string,
|
|
291
|
+
endpoint: string,
|
|
292
|
+
request: {
|
|
293
|
+
readonly params?: any
|
|
294
|
+
readonly query?: any
|
|
295
|
+
readonly payload?: any
|
|
296
|
+
readonly headers?: any
|
|
297
|
+
readonly responseMode?: HttpApiEndpoint.ClientResponseMode
|
|
298
|
+
readonly reactivityKeys?: ReadonlyArray<unknown> | ReadonlyRecord<string, ReadonlyArray<unknown>> | undefined
|
|
299
|
+
readonly timeToLive?: Duration.Input | undefined
|
|
300
|
+
readonly serializationKey?: string | undefined
|
|
301
|
+
}
|
|
302
|
+
) => {
|
|
303
|
+
const key: QueryKey = {
|
|
304
|
+
group,
|
|
305
|
+
endpoint,
|
|
306
|
+
params: request.params,
|
|
307
|
+
query: request.query,
|
|
308
|
+
payload: request.payload,
|
|
309
|
+
headers: request.headers,
|
|
310
|
+
responseMode: request.responseMode ?? "decoded-only",
|
|
311
|
+
reactivityKeys: request.reactivityKeys,
|
|
312
|
+
timeToLive: request.timeToLive
|
|
313
|
+
? Duration.fromInputUnsafe(request.timeToLive)
|
|
314
|
+
: undefined,
|
|
315
|
+
serializationKey: request.serializationKey
|
|
316
|
+
}
|
|
317
|
+
return queryFamily(key)
|
|
318
|
+
}) as any
|
|
319
|
+
|
|
320
|
+
return self as AtomHttpApiClient<Self, Id, Groups>
|
|
321
|
+
}
|
|
320
322
|
|
|
321
323
|
interface MutationKey {
|
|
322
324
|
group: string
|
|
@@ -67,7 +67,9 @@ import { withRun } from "./Utils.ts"
|
|
|
67
67
|
* @since 4.0.0
|
|
68
68
|
*/
|
|
69
69
|
export interface RpcServer<A extends Rpc.Any> {
|
|
70
|
-
readonly write: (clientId: number, message: FromClient<A
|
|
70
|
+
readonly write: (clientId: number, message: FromClient<A>, options?: {
|
|
71
|
+
readonly onRequest?: (<A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>) | undefined
|
|
72
|
+
}) => Effect.Effect<void>
|
|
71
73
|
readonly disconnect: (clientId: number) => Effect.Effect<void>
|
|
72
74
|
}
|
|
73
75
|
|
|
@@ -164,7 +166,7 @@ export const makeNoSerialization: <Rpcs extends Rpc.Any>(
|
|
|
164
166
|
return Effect.void
|
|
165
167
|
})
|
|
166
168
|
|
|
167
|
-
const write = (clientId
|
|
169
|
+
const write: RpcServer<Rpcs>["write"] = (clientId, message, opts) =>
|
|
168
170
|
Effect.catchDefect(
|
|
169
171
|
Effect.withFiber((requestFiber) => {
|
|
170
172
|
if (isShutdown) return Effect.interrupt
|
|
@@ -184,7 +186,7 @@ export const makeNoSerialization: <Rpcs extends Rpc.Any>(
|
|
|
184
186
|
|
|
185
187
|
switch (message._tag) {
|
|
186
188
|
case "Request": {
|
|
187
|
-
return handleRequest(requestFiber, client, message)
|
|
189
|
+
return handleRequest(requestFiber, client, message, opts)
|
|
188
190
|
}
|
|
189
191
|
case "Ack": {
|
|
190
192
|
const latch = client.latches.get(message.requestId)
|
|
@@ -231,7 +233,8 @@ export const makeNoSerialization: <Rpcs extends Rpc.Any>(
|
|
|
231
233
|
const handleRequest = (
|
|
232
234
|
requestFiber: Fiber.Fiber<any, any>,
|
|
233
235
|
client: Client,
|
|
234
|
-
request: Request<Rpcs
|
|
236
|
+
request: Request<Rpcs>,
|
|
237
|
+
opts: Parameters<RpcServer<Rpcs>["write"]>[2]
|
|
235
238
|
): Effect.Effect<void> => {
|
|
236
239
|
if (client.fibers.has(request.id)) {
|
|
237
240
|
return Effect.interrupt
|
|
@@ -312,6 +315,9 @@ export const makeNoSerialization: <Rpcs extends Rpc.Any>(
|
|
|
312
315
|
}
|
|
313
316
|
return close ? Effect.ensuring(write, close) : write
|
|
314
317
|
})
|
|
318
|
+
if (opts?.onRequest) {
|
|
319
|
+
effect = opts.onRequest(effect)
|
|
320
|
+
}
|
|
315
321
|
if (enableTracing) {
|
|
316
322
|
const parentSpan = requestFiber.context.mapUnsafe.get(
|
|
317
323
|
Tracer.ParentSpan.key
|
|
@@ -62,8 +62,7 @@ export interface SqlClient extends Constructor {
|
|
|
62
62
|
readonly transactionService: Context.Service<TransactionConnection, TransactionConnection.Service>
|
|
63
63
|
|
|
64
64
|
/**
|
|
65
|
-
* Use the Reactivity service
|
|
66
|
-
* query.
|
|
65
|
+
* Use the Reactivity service to create a reactive query.
|
|
67
66
|
*/
|
|
68
67
|
readonly reactive: <A, E, R>(
|
|
69
68
|
keys: ReadonlyArray<unknown> | ReadonlyRecord<string, ReadonlyArray<unknown>>,
|
|
@@ -292,7 +292,7 @@ export const raceAll = <
|
|
|
292
292
|
const engine = yield* EngineTag
|
|
293
293
|
const exit = yield* engine.deferredResult(deferred)
|
|
294
294
|
if (Option.isSome(exit)) {
|
|
295
|
-
return yield*
|
|
295
|
+
return yield* exit.value
|
|
296
296
|
}
|
|
297
297
|
return yield* into(
|
|
298
298
|
Effect.raceAll(options.effects),
|
|
@@ -29,28 +29,27 @@ import type { WorkflowEngine } from "./WorkflowEngine.ts"
|
|
|
29
29
|
*/
|
|
30
30
|
export const layerHttpApi = <
|
|
31
31
|
ApiId extends string,
|
|
32
|
-
Groups extends HttpApiGroup.
|
|
33
|
-
|
|
32
|
+
Groups extends HttpApiGroup.Constraint,
|
|
33
|
+
Identifier extends HttpApiGroup.Identifier<Groups>,
|
|
34
34
|
const Workflows extends NonEmptyReadonlyArray<Workflow.Any>
|
|
35
35
|
>(
|
|
36
36
|
api: HttpApi.HttpApi<ApiId, Groups>,
|
|
37
|
-
|
|
37
|
+
identifier: Identifier,
|
|
38
38
|
workflows: Workflows
|
|
39
39
|
): Layer.Layer<
|
|
40
|
-
HttpApiGroup.
|
|
40
|
+
HttpApiGroup.Service<ApiId, Identifier>,
|
|
41
41
|
never,
|
|
42
42
|
WorkflowEngine | Workflow.RequirementsHandler<Workflows[number]>
|
|
43
43
|
> =>
|
|
44
44
|
HttpApiBuilder.group(
|
|
45
45
|
api,
|
|
46
|
-
|
|
47
|
-
Effect.fnUntraced(function*(
|
|
48
|
-
let handlers = handlers_ as any
|
|
46
|
+
identifier,
|
|
47
|
+
Effect.fnUntraced(function*(handlers: any) {
|
|
49
48
|
for (const workflow_ of workflows) {
|
|
50
49
|
const workflow = workflow_ as Workflow.AnyWithProps
|
|
51
50
|
handlers = handlers
|
|
52
51
|
.handle(
|
|
53
|
-
workflow._tag
|
|
52
|
+
workflow._tag,
|
|
54
53
|
({ payload }: { payload: any }) =>
|
|
55
54
|
workflow.execute(payload).pipe(
|
|
56
55
|
Effect.tapDefect(Effect.logError),
|
|
@@ -61,9 +60,9 @@ export const layerHttpApi = <
|
|
|
61
60
|
)
|
|
62
61
|
)
|
|
63
62
|
.handle(
|
|
64
|
-
workflow._tag + "Discard"
|
|
63
|
+
workflow._tag + "Discard",
|
|
65
64
|
({ payload }: { payload: any }) =>
|
|
66
|
-
workflow.execute(payload, { discard: true }
|
|
65
|
+
workflow.execute(payload, { discard: true }).pipe(
|
|
67
66
|
Effect.tapDefect(Effect.logError),
|
|
68
67
|
Effect.annotateLogs({
|
|
69
68
|
module: "WorkflowProxyServer",
|
|
@@ -72,7 +71,7 @@ export const layerHttpApi = <
|
|
|
72
71
|
)
|
|
73
72
|
)
|
|
74
73
|
.handle(
|
|
75
|
-
workflow._tag + "Resume"
|
|
74
|
+
workflow._tag + "Resume",
|
|
76
75
|
({ payload }: { payload: any }) =>
|
|
77
76
|
workflow.resume(payload.executionId).pipe(
|
|
78
77
|
Effect.tapDefect(Effect.logError),
|
|
@@ -83,7 +82,7 @@ export const layerHttpApi = <
|
|
|
83
82
|
)
|
|
84
83
|
)
|
|
85
84
|
}
|
|
86
|
-
return handlers as HttpApiBuilder.Handlers<never
|
|
85
|
+
return handlers as HttpApiBuilder.Handlers<never>
|
|
87
86
|
})
|
|
88
87
|
)
|
|
89
88
|
|