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.
Files changed (221) hide show
  1. package/README.md +1 -3
  2. package/dist/Array.js +1 -1
  3. package/dist/Array.js.map +1 -1
  4. package/dist/Graph.d.ts +1187 -196
  5. package/dist/Graph.d.ts.map +1 -1
  6. package/dist/Graph.js +1031 -283
  7. package/dist/Graph.js.map +1 -1
  8. package/dist/Iterable.d.ts.map +1 -1
  9. package/dist/Iterable.js +41 -1
  10. package/dist/Iterable.js.map +1 -1
  11. package/dist/LayerRef.d.ts +4 -6
  12. package/dist/LayerRef.d.ts.map +1 -1
  13. package/dist/LayerRef.js +4 -6
  14. package/dist/LayerRef.js.map +1 -1
  15. package/dist/Number.d.ts.map +1 -1
  16. package/dist/Number.js +28 -10
  17. package/dist/Number.js.map +1 -1
  18. package/dist/Schema.d.ts +22 -22
  19. package/dist/Schema.d.ts.map +1 -1
  20. package/dist/Schema.js +37 -34
  21. package/dist/Schema.js.map +1 -1
  22. package/dist/SchemaAST.d.ts.map +1 -1
  23. package/dist/SchemaAST.js +25 -10
  24. package/dist/SchemaAST.js.map +1 -1
  25. package/dist/SchemaError.d.ts +53 -0
  26. package/dist/SchemaError.d.ts.map +1 -0
  27. package/dist/SchemaError.js +61 -0
  28. package/dist/SchemaError.js.map +1 -0
  29. package/dist/SchemaGetter.d.ts.map +1 -1
  30. package/dist/SchemaGetter.js +17 -12
  31. package/dist/SchemaGetter.js.map +1 -1
  32. package/dist/SchemaRepresentation.d.ts.map +1 -1
  33. package/dist/SchemaRepresentation.js +186 -224
  34. package/dist/SchemaRepresentation.js.map +1 -1
  35. package/dist/index.d.ts +8 -0
  36. package/dist/index.d.ts.map +1 -1
  37. package/dist/index.js +8 -0
  38. package/dist/index.js.map +1 -1
  39. package/dist/internal/effect.js +35 -11
  40. package/dist/internal/effect.js.map +1 -1
  41. package/dist/internal/schema/equivalence.js +1 -2
  42. package/dist/internal/schema/equivalence.js.map +1 -1
  43. package/dist/internal/schema/representation.js +1 -3
  44. package/dist/internal/schema/representation.js.map +1 -1
  45. package/dist/internal/schema/schema.d.ts +0 -13
  46. package/dist/internal/schema/schema.d.ts.map +1 -1
  47. package/dist/internal/schema/schema.js +4 -29
  48. package/dist/internal/schema/schema.js.map +1 -1
  49. package/dist/unstable/ai/Tool.d.ts.map +1 -1
  50. package/dist/unstable/ai/Tool.js +11 -13
  51. package/dist/unstable/ai/Tool.js.map +1 -1
  52. package/dist/unstable/cli/CliConfig.d.ts +76 -0
  53. package/dist/unstable/cli/CliConfig.d.ts.map +1 -0
  54. package/dist/unstable/cli/CliConfig.js +63 -0
  55. package/dist/unstable/cli/CliConfig.js.map +1 -0
  56. package/dist/unstable/cli/CliError.d.ts +8 -16
  57. package/dist/unstable/cli/CliError.d.ts.map +1 -1
  58. package/dist/unstable/cli/CliError.js +11 -16
  59. package/dist/unstable/cli/CliError.js.map +1 -1
  60. package/dist/unstable/cli/Command.d.ts +40 -4
  61. package/dist/unstable/cli/Command.d.ts.map +1 -1
  62. package/dist/unstable/cli/Command.js +63 -6
  63. package/dist/unstable/cli/Command.js.map +1 -1
  64. package/dist/unstable/cli/GlobalFlag.d.ts +24 -5
  65. package/dist/unstable/cli/GlobalFlag.d.ts.map +1 -1
  66. package/dist/unstable/cli/GlobalFlag.js +26 -10
  67. package/dist/unstable/cli/GlobalFlag.js.map +1 -1
  68. package/dist/unstable/cli/Param.js +6 -2
  69. package/dist/unstable/cli/Param.js.map +1 -1
  70. package/dist/unstable/cli/index.d.ts +4 -0
  71. package/dist/unstable/cli/index.d.ts.map +1 -1
  72. package/dist/unstable/cli/index.js +4 -0
  73. package/dist/unstable/cli/index.js.map +1 -1
  74. package/dist/unstable/cli/internal/ansi.d.ts.map +1 -1
  75. package/dist/unstable/cli/internal/ansi.js +2 -0
  76. package/dist/unstable/cli/internal/ansi.js.map +1 -1
  77. package/dist/unstable/cli/internal/parser.js +11 -2
  78. package/dist/unstable/cli/internal/parser.js.map +1 -1
  79. package/dist/unstable/cli/internal/wizard.d.ts +13 -0
  80. package/dist/unstable/cli/internal/wizard.d.ts.map +1 -0
  81. package/dist/unstable/cli/internal/wizard.js +212 -0
  82. package/dist/unstable/cli/internal/wizard.js.map +1 -0
  83. package/dist/unstable/cluster/EntityProxyServer.d.ts +1 -1
  84. package/dist/unstable/cluster/EntityProxyServer.d.ts.map +1 -1
  85. package/dist/unstable/cluster/EntityProxyServer.js +2 -4
  86. package/dist/unstable/cluster/EntityProxyServer.js.map +1 -1
  87. package/dist/unstable/cluster/RunnerStorage.js +1 -1
  88. package/dist/unstable/cluster/RunnerStorage.js.map +1 -1
  89. package/dist/unstable/cluster/internal/entityManager.js +15 -12
  90. package/dist/unstable/cluster/internal/entityManager.js.map +1 -1
  91. package/dist/unstable/http/Multipart.d.ts.map +1 -1
  92. package/dist/unstable/http/Multipart.js +3 -1
  93. package/dist/unstable/http/Multipart.js.map +1 -1
  94. package/dist/unstable/httpapi/HttpApi.d.ts +36 -15
  95. package/dist/unstable/httpapi/HttpApi.d.ts.map +1 -1
  96. package/dist/unstable/httpapi/HttpApi.js +19 -20
  97. package/dist/unstable/httpapi/HttpApi.js.map +1 -1
  98. package/dist/unstable/httpapi/HttpApiBuilder.d.ts +51 -62
  99. package/dist/unstable/httpapi/HttpApiBuilder.d.ts.map +1 -1
  100. package/dist/unstable/httpapi/HttpApiBuilder.js +68 -58
  101. package/dist/unstable/httpapi/HttpApiBuilder.js.map +1 -1
  102. package/dist/unstable/httpapi/HttpApiClient.d.ts +53 -53
  103. package/dist/unstable/httpapi/HttpApiClient.d.ts.map +1 -1
  104. package/dist/unstable/httpapi/HttpApiClient.js +40 -30
  105. package/dist/unstable/httpapi/HttpApiClient.js.map +1 -1
  106. package/dist/unstable/httpapi/HttpApiEndpoint.d.ts +165 -164
  107. package/dist/unstable/httpapi/HttpApiEndpoint.d.ts.map +1 -1
  108. package/dist/unstable/httpapi/HttpApiEndpoint.js +31 -19
  109. package/dist/unstable/httpapi/HttpApiEndpoint.js.map +1 -1
  110. package/dist/unstable/httpapi/HttpApiError.d.ts +22 -0
  111. package/dist/unstable/httpapi/HttpApiError.d.ts.map +1 -1
  112. package/dist/unstable/httpapi/HttpApiError.js +31 -0
  113. package/dist/unstable/httpapi/HttpApiError.js.map +1 -1
  114. package/dist/unstable/httpapi/HttpApiGroup.d.ts +55 -30
  115. package/dist/unstable/httpapi/HttpApiGroup.d.ts.map +1 -1
  116. package/dist/unstable/httpapi/HttpApiGroup.js +22 -29
  117. package/dist/unstable/httpapi/HttpApiGroup.js.map +1 -1
  118. package/dist/unstable/httpapi/HttpApiMiddleware.d.ts +8 -8
  119. package/dist/unstable/httpapi/HttpApiMiddleware.d.ts.map +1 -1
  120. package/dist/unstable/httpapi/HttpApiMiddleware.js.map +1 -1
  121. package/dist/unstable/httpapi/HttpApiScalar.d.ts +2 -2
  122. package/dist/unstable/httpapi/HttpApiScalar.d.ts.map +1 -1
  123. package/dist/unstable/httpapi/HttpApiScalar.js +4 -3
  124. package/dist/unstable/httpapi/HttpApiScalar.js.map +1 -1
  125. package/dist/unstable/httpapi/HttpApiSchema.d.ts +8 -0
  126. package/dist/unstable/httpapi/HttpApiSchema.d.ts.map +1 -1
  127. package/dist/unstable/httpapi/HttpApiSchema.js.map +1 -1
  128. package/dist/unstable/httpapi/HttpApiSwagger.d.ts +1 -1
  129. package/dist/unstable/httpapi/HttpApiSwagger.d.ts.map +1 -1
  130. package/dist/unstable/httpapi/HttpApiSwagger.js.map +1 -1
  131. package/dist/unstable/httpapi/HttpApiTest.d.ts +4 -4
  132. package/dist/unstable/httpapi/HttpApiTest.d.ts.map +1 -1
  133. package/dist/unstable/httpapi/HttpApiTest.js +9 -8
  134. package/dist/unstable/httpapi/HttpApiTest.js.map +1 -1
  135. package/dist/unstable/httpapi/OpenApi.d.ts +1 -1
  136. package/dist/unstable/httpapi/OpenApi.d.ts.map +1 -1
  137. package/dist/unstable/httpapi/OpenApi.js +77 -37
  138. package/dist/unstable/httpapi/OpenApi.js.map +1 -1
  139. package/dist/unstable/httpapi/internal/html.js +6 -2
  140. package/dist/unstable/httpapi/internal/html.js.map +1 -1
  141. package/dist/unstable/httpapi/internal/mediaType.d.ts +2 -0
  142. package/dist/unstable/httpapi/internal/mediaType.d.ts.map +1 -0
  143. package/dist/unstable/httpapi/internal/mediaType.js +7 -0
  144. package/dist/unstable/httpapi/internal/mediaType.js.map +1 -0
  145. package/dist/unstable/persistence/PersistedQueue.d.ts.map +1 -1
  146. package/dist/unstable/persistence/PersistedQueue.js +16 -12
  147. package/dist/unstable/persistence/PersistedQueue.js.map +1 -1
  148. package/dist/unstable/persistence/Redis.d.ts.map +1 -1
  149. package/dist/unstable/persistence/Redis.js +5 -3
  150. package/dist/unstable/persistence/Redis.js.map +1 -1
  151. package/dist/unstable/reactivity/Atom.js +1 -1
  152. package/dist/unstable/reactivity/Atom.js.map +1 -1
  153. package/dist/unstable/reactivity/AtomHttpApi.d.ts +7 -7
  154. package/dist/unstable/reactivity/AtomHttpApi.d.ts.map +1 -1
  155. package/dist/unstable/reactivity/AtomHttpApi.js +3 -2
  156. package/dist/unstable/reactivity/AtomHttpApi.js.map +1 -1
  157. package/dist/unstable/rpc/RpcServer.d.ts +3 -1
  158. package/dist/unstable/rpc/RpcServer.d.ts.map +1 -1
  159. package/dist/unstable/rpc/RpcServer.js +6 -3
  160. package/dist/unstable/rpc/RpcServer.js.map +1 -1
  161. package/dist/unstable/sql/SqlClient.d.ts +1 -2
  162. package/dist/unstable/sql/SqlClient.d.ts.map +1 -1
  163. package/dist/unstable/sql/SqlClient.js.map +1 -1
  164. package/dist/unstable/workflow/DurableDeferred.js +1 -1
  165. package/dist/unstable/workflow/DurableDeferred.js.map +1 -1
  166. package/dist/unstable/workflow/WorkflowProxyServer.d.ts +1 -1
  167. package/dist/unstable/workflow/WorkflowProxyServer.d.ts.map +1 -1
  168. package/dist/unstable/workflow/WorkflowProxyServer.js +1 -2
  169. package/dist/unstable/workflow/WorkflowProxyServer.js.map +1 -1
  170. package/package.json +3 -3
  171. package/src/Array.ts +1 -1
  172. package/src/Graph.ts +2967 -457
  173. package/src/Iterable.ts +32 -2
  174. package/src/LayerRef.ts +4 -6
  175. package/src/Number.ts +29 -10
  176. package/src/Schema.ts +43 -35
  177. package/src/SchemaAST.ts +25 -13
  178. package/src/SchemaError.ts +64 -0
  179. package/src/SchemaGetter.ts +22 -16
  180. package/src/SchemaRepresentation.ts +165 -202
  181. package/src/index.ts +10 -0
  182. package/src/internal/effect.ts +48 -25
  183. package/src/internal/schema/equivalence.ts +1 -2
  184. package/src/internal/schema/representation.ts +4 -4
  185. package/src/internal/schema/schema.ts +4 -37
  186. package/src/unstable/ai/Tool.ts +13 -16
  187. package/src/unstable/cli/CliConfig.ts +85 -0
  188. package/src/unstable/cli/CliError.ts +27 -16
  189. package/src/unstable/cli/Command.ts +90 -14
  190. package/src/unstable/cli/GlobalFlag.ts +46 -29
  191. package/src/unstable/cli/Param.ts +15 -3
  192. package/src/unstable/cli/index.ts +5 -0
  193. package/src/unstable/cli/internal/ansi.ts +3 -0
  194. package/src/unstable/cli/internal/parser.ts +14 -2
  195. package/src/unstable/cli/internal/wizard.ts +283 -0
  196. package/src/unstable/cluster/EntityProxyServer.ts +15 -17
  197. package/src/unstable/cluster/RunnerStorage.ts +1 -1
  198. package/src/unstable/cluster/internal/entityManager.ts +48 -34
  199. package/src/unstable/http/Multipart.ts +3 -1
  200. package/src/unstable/httpapi/HttpApi.ts +72 -47
  201. package/src/unstable/httpapi/HttpApiBuilder.ts +320 -217
  202. package/src/unstable/httpapi/HttpApiClient.ts +196 -151
  203. package/src/unstable/httpapi/HttpApiEndpoint.ts +251 -447
  204. package/src/unstable/httpapi/HttpApiError.ts +33 -0
  205. package/src/unstable/httpapi/HttpApiGroup.ts +95 -74
  206. package/src/unstable/httpapi/HttpApiMiddleware.ts +10 -7
  207. package/src/unstable/httpapi/HttpApiScalar.ts +15 -12
  208. package/src/unstable/httpapi/HttpApiSchema.ts +8 -0
  209. package/src/unstable/httpapi/HttpApiSwagger.ts +2 -2
  210. package/src/unstable/httpapi/HttpApiTest.ts +15 -14
  211. package/src/unstable/httpapi/OpenApi.ts +74 -36
  212. package/src/unstable/httpapi/internal/html.ts +9 -2
  213. package/src/unstable/httpapi/internal/mediaType.ts +6 -0
  214. package/src/unstable/persistence/PersistedQueue.ts +16 -14
  215. package/src/unstable/persistence/Redis.ts +9 -4
  216. package/src/unstable/reactivity/Atom.ts +1 -1
  217. package/src/unstable/reactivity/AtomHttpApi.ts +164 -162
  218. package/src/unstable/rpc/RpcServer.ts +10 -4
  219. package/src/unstable/sql/SqlClient.ts +1 -2
  220. package/src/unstable/workflow/DurableDeferred.ts +1 -1
  221. 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.Any>
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
- GroupName extends HttpApiGroup.Name<Groups>,
52
- Name extends HttpApiEndpoint.Name<HttpApiGroup.Endpoints<Group>>,
53
- Group extends HttpApiGroup.Any = HttpApiGroup.WithName<Groups, GroupName>,
54
- Endpoint extends HttpApiEndpoint.Any = HttpApiEndpoint.WithName<
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
- Name
56
+ EndpointIdentifier
57
57
  >,
58
58
  const ResponseMode extends HttpApiEndpoint.ClientResponseMode = HttpApiEndpoint.ClientResponseMode
59
59
  >(
60
- group: GroupName,
61
- endpoint: Name,
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 _Name,
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
- GroupName extends HttpApiGroup.Name<Groups>,
92
- Name extends HttpApiEndpoint.Name<HttpApiGroup.Endpoints<Group>>,
93
- Group extends HttpApiGroup.Any = HttpApiGroup.WithName<Groups, GroupName>,
94
- Endpoint extends HttpApiEndpoint.Any = HttpApiEndpoint.WithName<
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
- Name
96
+ EndpointIdentifier
97
97
  >,
98
98
  const ResponseMode extends HttpApiEndpoint.ClientResponseMode = "decoded-only"
99
99
  >(
100
- group: GroupName,
101
- endpoint: Name,
100
+ group: GroupIdentifier,
101
+ endpoint: EndpointIdentifier,
102
102
  request: [Endpoint] extends [
103
103
  HttpApiEndpoint.HttpApiEndpoint<
104
- infer _Name,
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 _Name,
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 = <Self>() =>
170
- <const Id extends string, ApiId extends string, Groups extends HttpApiGroup.Any>(
171
- id: Id,
172
- options: {
173
- readonly api: HttpApi.HttpApi<ApiId, Groups>
174
- readonly httpClient:
175
- | Layer.Layer<
176
- | HttpApiGroup.ClientServices<Groups>
177
- | HttpClient.HttpClient
178
- >
179
- | ((get: Atom.AtomContext) => Layer.Layer<
180
- | HttpApiGroup.ClientServices<Groups>
181
- | HttpClient.HttpClient
182
- >)
183
- readonly transformClient?: ((client: HttpClient.HttpClient) => HttpClient.HttpClient) | undefined
184
- readonly transformResponse?:
185
- | ((effect: Effect.Effect<unknown, unknown, unknown>) => Effect.Effect<unknown, unknown, unknown>)
186
- | undefined
187
- readonly baseUrl?: URL | string | undefined
188
- readonly runtime?: Atom.RuntimeFactory | undefined
189
- }
190
- ): AtomHttpApiClient<Self, Id, Groups> => {
191
- const self: Mutable<AtomHttpApiClient<Self, Id, Groups>> = Context.Service<
192
- Self,
193
- HttpApiClient.Client<Groups, never, never>
194
- >()(id) as any
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
- const catchErrors = Effect.catch((e: unknown) =>
215
- Schema.isSchemaError(e) || HttpClientError.isHttpClientError(e) ? Effect.die(e) : Effect.fail(e)
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
- const mutationFamily = Atom.family(({ endpoint, group, responseMode }: MutationKey) => {
219
- const atom = self.runtime.fn<{
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
- if (responseMode === "decoded-only") {
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
- self.mutation = ((group: string, endpoint: string, options?: {
251
- readonly responseMode?: HttpApiEndpoint.ClientResponseMode | undefined
252
- }) =>
253
- mutationFamily({
254
- group,
255
- endpoint,
256
- responseMode: options?.responseMode ?? "decoded-only"
257
- })) as any
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
- const queryFamily = Atom.family((opts: QueryKey) => {
260
- let atom = self.runtime.atom(self.use((client_) => {
261
- const client = client_ as any
262
- return catchErrors(client[opts.group][opts.endpoint](opts) as Effect.Effect<
263
- any,
264
- HttpClientError.HttpClientError | SchemaError
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
- self.query = ((
288
- group: string,
289
- endpoint: string,
290
- request: {
291
- readonly params?: any
292
- readonly query?: any
293
- readonly payload?: any
294
- readonly headers?: any
295
- readonly responseMode?: HttpApiEndpoint.ClientResponseMode
296
- readonly reactivityKeys?: ReadonlyArray<unknown> | ReadonlyRecord<string, ReadonlyArray<unknown>> | undefined
297
- readonly timeToLive?: Duration.Input | undefined
298
- readonly serializationKey?: string | undefined
299
- }
300
- ) => {
301
- const key: QueryKey = {
302
- group,
303
- endpoint,
304
- params: request.params,
305
- query: request.query,
306
- payload: request.payload,
307
- headers: request.headers,
308
- responseMode: request.responseMode ?? "decoded-only",
309
- reactivityKeys: request.reactivityKeys,
310
- timeToLive: request.timeToLive
311
- ? Duration.fromInputUnsafe(request.timeToLive)
312
- : undefined,
313
- serializationKey: request.serializationKey
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
- return self as AtomHttpApiClient<Self, Id, Groups>
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>) => Effect.Effect<void>
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: number, message: FromClient<Rpcs>): Effect.Effect<void> =>
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 from @effect/experimental to create a reactive
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* Effect.flatten(exit.value) as Effect.Effect<any, any, any>
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.Any,
33
- Name extends HttpApiGroup.Name<Groups>,
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
- name: Name,
37
+ identifier: Identifier,
38
38
  workflows: Workflows
39
39
  ): Layer.Layer<
40
- HttpApiGroup.ApiGroup<ApiId, Name>,
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
- name,
47
- Effect.fnUntraced(function*(handlers_) {
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 as any,
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" as any,
63
+ workflow._tag + "Discard",
65
64
  ({ payload }: { payload: any }) =>
66
- workflow.execute(payload, { discard: true } as any).pipe(
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" as any,
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, never>
85
+ return handlers as HttpApiBuilder.Handlers<never>
87
86
  })
88
87
  )
89
88