effect 4.0.0-beta.64 → 4.0.0-beta.66
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/Cause.d.ts +4 -4
- package/dist/Cause.d.ts.map +1 -1
- package/dist/Config.d.ts +1 -2
- package/dist/Config.d.ts.map +1 -1
- package/dist/Config.js +7 -6
- package/dist/Config.js.map +1 -1
- package/dist/Context.d.ts +3 -4
- package/dist/Context.d.ts.map +1 -1
- package/dist/Context.js +10 -8
- package/dist/Context.js.map +1 -1
- package/dist/DateTime.d.ts +1 -1
- package/dist/DateTime.d.ts.map +1 -1
- package/dist/DateTime.js +2 -2
- package/dist/DateTime.js.map +1 -1
- package/dist/Effect.d.ts +337 -412
- package/dist/Effect.d.ts.map +1 -1
- package/dist/Effect.js +5 -32
- package/dist/Effect.js.map +1 -1
- package/dist/Effectable.d.ts +1 -1
- package/dist/Effectable.d.ts.map +1 -1
- package/dist/Effectable.js +1 -1
- package/dist/Effectable.js.map +1 -1
- package/dist/ExecutionPlan.d.ts +2 -3
- package/dist/ExecutionPlan.d.ts.map +1 -1
- package/dist/ExecutionPlan.js +1 -1
- package/dist/ExecutionPlan.js.map +1 -1
- package/dist/FiberHandle.d.ts +2 -2
- package/dist/FiberHandle.js +2 -2
- package/dist/FiberMap.d.ts +2 -2
- package/dist/FiberMap.js +2 -2
- package/dist/FiberSet.d.ts +1 -1
- package/dist/FiberSet.js +1 -1
- package/dist/Layer.js +1 -1
- package/dist/Layer.js.map +1 -1
- package/dist/LayerMap.d.ts.map +1 -1
- package/dist/LayerMap.js +3 -3
- package/dist/LayerMap.js.map +1 -1
- package/dist/ManagedRuntime.d.ts +1 -1
- package/dist/ManagedRuntime.js +1 -1
- package/dist/Option.d.ts +11 -7
- package/dist/Option.d.ts.map +1 -1
- package/dist/Option.js +74 -0
- package/dist/Option.js.map +1 -1
- package/dist/Result.d.ts +11 -3
- package/dist/Result.d.ts.map +1 -1
- package/dist/Result.js.map +1 -1
- package/dist/Schedule.js +1 -1
- package/dist/Schedule.js.map +1 -1
- package/dist/Schema.d.ts +12 -12
- package/dist/Schema.d.ts.map +1 -1
- package/dist/Schema.js +6 -4
- package/dist/Schema.js.map +1 -1
- package/dist/SchemaGetter.js +2 -2
- package/dist/SchemaGetter.js.map +1 -1
- package/dist/SchemaRepresentation.d.ts +2 -2
- package/dist/Stream.d.ts +3 -3
- package/dist/Stream.js +1 -1
- package/dist/TxRef.js +1 -1
- package/dist/TxRef.js.map +1 -1
- package/dist/internal/concurrency.js +2 -2
- package/dist/internal/concurrency.js.map +1 -1
- package/dist/internal/core.js +8 -20
- package/dist/internal/core.js.map +1 -1
- package/dist/internal/effect.js +20 -19
- package/dist/internal/effect.js.map +1 -1
- package/dist/internal/executionPlan.js +2 -2
- package/dist/internal/executionPlan.js.map +1 -1
- package/dist/internal/option.js +5 -8
- package/dist/internal/option.js.map +1 -1
- package/dist/internal/result.js +5 -8
- package/dist/internal/result.js.map +1 -1
- package/dist/unstable/ai/LanguageModel.d.ts +5 -5
- package/dist/unstable/ai/LanguageModel.d.ts.map +1 -1
- package/dist/unstable/ai/LanguageModel.js +1 -1
- package/dist/unstable/ai/LanguageModel.js.map +1 -1
- package/dist/unstable/ai/McpServer.js +2 -2
- package/dist/unstable/ai/McpServer.js.map +1 -1
- package/dist/unstable/ai/Model.d.ts +5 -1
- package/dist/unstable/ai/Model.d.ts.map +1 -1
- package/dist/unstable/ai/Model.js +4 -4
- package/dist/unstable/ai/Model.js.map +1 -1
- package/dist/unstable/ai/Toolkit.d.ts +1 -3
- package/dist/unstable/ai/Toolkit.d.ts.map +1 -1
- package/dist/unstable/ai/Toolkit.js +28 -31
- package/dist/unstable/ai/Toolkit.js.map +1 -1
- package/dist/unstable/cli/Command.d.ts +25 -5
- package/dist/unstable/cli/Command.d.ts.map +1 -1
- package/dist/unstable/cli/Command.js.map +1 -1
- package/dist/unstable/cli/GlobalFlag.d.ts +1 -1
- package/dist/unstable/cli/GlobalFlag.d.ts.map +1 -1
- package/dist/unstable/cli/Param.js +1 -1
- package/dist/unstable/cli/Param.js.map +1 -1
- package/dist/unstable/cli/Prompt.d.ts +1 -2
- package/dist/unstable/cli/Prompt.d.ts.map +1 -1
- package/dist/unstable/cli/Prompt.js +8 -10
- package/dist/unstable/cli/Prompt.js.map +1 -1
- package/dist/unstable/cli/internal/command.d.ts +2 -6
- package/dist/unstable/cli/internal/command.d.ts.map +1 -1
- package/dist/unstable/cli/internal/command.js +7 -9
- package/dist/unstable/cli/internal/command.js.map +1 -1
- package/dist/unstable/cluster/ClusterWorkflowEngine.js +1 -1
- package/dist/unstable/cluster/ClusterWorkflowEngine.js.map +1 -1
- package/dist/unstable/cluster/Entity.js +3 -3
- package/dist/unstable/cluster/Entity.js.map +1 -1
- package/dist/unstable/cluster/MessageStorage.js +1 -1
- package/dist/unstable/cluster/MessageStorage.js.map +1 -1
- package/dist/unstable/cluster/ShardingConfig.js +1 -1
- package/dist/unstable/cluster/ShardingConfig.js.map +1 -1
- package/dist/unstable/eventlog/EventLogMessage.d.ts +4 -4
- package/dist/unstable/eventlog/SqlEventLogServerUnencrypted.js +2 -1
- package/dist/unstable/eventlog/SqlEventLogServerUnencrypted.js.map +1 -1
- package/dist/unstable/http/HttpBody.js +2 -2
- package/dist/unstable/http/HttpBody.js.map +1 -1
- package/dist/unstable/http/HttpClient.js +1 -1
- package/dist/unstable/http/HttpClient.js.map +1 -1
- package/dist/unstable/http/HttpClientRequest.js +2 -2
- package/dist/unstable/http/HttpClientRequest.js.map +1 -1
- package/dist/unstable/http/HttpMiddleware.d.ts.map +1 -1
- package/dist/unstable/http/HttpMiddleware.js +18 -21
- package/dist/unstable/http/HttpMiddleware.js.map +1 -1
- package/dist/unstable/http/HttpPlatform.js +1 -1
- package/dist/unstable/http/HttpPlatform.js.map +1 -1
- package/dist/unstable/http/HttpRouter.d.ts.map +1 -1
- package/dist/unstable/http/HttpRouter.js +4 -4
- package/dist/unstable/http/HttpRouter.js.map +1 -1
- package/dist/unstable/http/HttpServer.js +1 -1
- package/dist/unstable/http/HttpServer.js.map +1 -1
- package/dist/unstable/http/HttpServerRequest.js +11 -11
- package/dist/unstable/http/HttpServerRequest.js.map +1 -1
- package/dist/unstable/http/HttpServerResponse.d.ts.map +1 -1
- package/dist/unstable/http/HttpServerResponse.js +5 -5
- package/dist/unstable/http/HttpServerResponse.js.map +1 -1
- package/dist/unstable/http/Multipart.js +1 -1
- package/dist/unstable/http/Multipart.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiBuilder.js +3 -3
- package/dist/unstable/httpapi/HttpApiBuilder.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiClient.js +1 -1
- package/dist/unstable/httpapi/HttpApiClient.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiMiddleware.d.ts +2 -0
- package/dist/unstable/httpapi/HttpApiMiddleware.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiMiddleware.js +2 -1
- package/dist/unstable/httpapi/HttpApiMiddleware.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiTest.d.ts +3 -1
- package/dist/unstable/httpapi/HttpApiTest.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiTest.js +2 -2
- package/dist/unstable/httpapi/HttpApiTest.js.map +1 -1
- package/dist/unstable/persistence/RateLimiter.js +1 -1
- package/dist/unstable/persistence/RateLimiter.js.map +1 -1
- package/dist/unstable/process/ChildProcess.d.ts +2 -45
- package/dist/unstable/process/ChildProcess.d.ts.map +1 -1
- package/dist/unstable/process/ChildProcess.js +51 -7
- package/dist/unstable/process/ChildProcess.js.map +1 -1
- package/dist/unstable/reactivity/Atom.d.ts.map +1 -1
- package/dist/unstable/reactivity/Atom.js +4 -4
- package/dist/unstable/reactivity/Atom.js.map +1 -1
- package/dist/unstable/rpc/RpcClient.js +1 -1
- package/dist/unstable/rpc/RpcClient.js.map +1 -1
- package/dist/unstable/rpc/RpcServer.d.ts.map +1 -1
- package/dist/unstable/rpc/RpcServer.js +1 -1
- package/dist/unstable/rpc/RpcServer.js.map +1 -1
- package/dist/unstable/rpc/RpcWorker.js +1 -1
- package/dist/unstable/rpc/RpcWorker.js.map +1 -1
- package/dist/unstable/socket/Socket.d.ts.map +1 -1
- package/dist/unstable/socket/Socket.js +1 -1
- package/dist/unstable/socket/Socket.js.map +1 -1
- package/dist/unstable/sql/Migrator.d.ts.map +1 -1
- package/dist/unstable/sql/Migrator.js +3 -2
- package/dist/unstable/sql/Migrator.js.map +1 -1
- package/dist/unstable/sql/SqlError.d.ts +23 -3
- package/dist/unstable/sql/SqlError.d.ts.map +1 -1
- package/dist/unstable/sql/SqlError.js +62 -2
- package/dist/unstable/sql/SqlError.js.map +1 -1
- package/dist/unstable/workflow/Activity.js +1 -1
- package/dist/unstable/workflow/Activity.js.map +1 -1
- package/dist/unstable/workflow/DurableQueue.d.ts +122 -0
- package/dist/unstable/workflow/DurableQueue.d.ts.map +1 -0
- package/dist/unstable/workflow/DurableQueue.js +182 -0
- package/dist/unstable/workflow/DurableQueue.js.map +1 -0
- package/dist/unstable/workflow/Workflow.js +1 -1
- package/dist/unstable/workflow/Workflow.js.map +1 -1
- package/dist/unstable/workflow/index.d.ts +4 -0
- package/dist/unstable/workflow/index.d.ts.map +1 -1
- package/dist/unstable/workflow/index.js +4 -0
- package/dist/unstable/workflow/index.js.map +1 -1
- package/package.json +1 -1
- package/src/Cause.ts +4 -4
- package/src/Config.ts +8 -8
- package/src/Context.ts +13 -14
- package/src/DateTime.ts +2 -2
- package/src/Effect.ts +340 -431
- package/src/Effectable.ts +2 -2
- package/src/ExecutionPlan.ts +3 -4
- package/src/FiberHandle.ts +2 -2
- package/src/FiberMap.ts +2 -2
- package/src/FiberSet.ts +1 -1
- package/src/Layer.ts +1 -1
- package/src/LayerMap.ts +3 -4
- package/src/ManagedRuntime.ts +1 -1
- package/src/Option.ts +14 -7
- package/src/Result.ts +14 -3
- package/src/Schedule.ts +1 -1
- package/src/Schema.ts +26 -24
- package/src/SchemaGetter.ts +3 -3
- package/src/Stream.ts +4 -4
- package/src/TxRef.ts +1 -1
- package/src/internal/concurrency.ts +2 -2
- package/src/internal/core.ts +12 -23
- package/src/internal/effect.ts +25 -29
- package/src/internal/executionPlan.ts +2 -2
- package/src/internal/option.ts +5 -8
- package/src/internal/result.ts +5 -8
- package/src/unstable/ai/LanguageModel.ts +12 -19
- package/src/unstable/ai/McpServer.ts +2 -2
- package/src/unstable/ai/Model.ts +15 -12
- package/src/unstable/ai/Toolkit.ts +30 -38
- package/src/unstable/cli/Command.ts +32 -13
- package/src/unstable/cli/GlobalFlag.ts +1 -1
- package/src/unstable/cli/Param.ts +1 -1
- package/src/unstable/cli/Prompt.ts +9 -13
- package/src/unstable/cli/internal/command.ts +12 -14
- package/src/unstable/cluster/ClusterWorkflowEngine.ts +1 -1
- package/src/unstable/cluster/Entity.ts +3 -3
- package/src/unstable/cluster/MessageStorage.ts +1 -1
- package/src/unstable/cluster/ShardingConfig.ts +1 -1
- package/src/unstable/eventlog/SqlEventLogServerUnencrypted.ts +4 -1
- package/src/unstable/http/HttpBody.ts +2 -2
- package/src/unstable/http/HttpClient.ts +1 -1
- package/src/unstable/http/HttpClientRequest.ts +2 -2
- package/src/unstable/http/HttpMiddleware.ts +4 -5
- package/src/unstable/http/HttpPlatform.ts +1 -1
- package/src/unstable/http/HttpRouter.ts +4 -5
- package/src/unstable/http/HttpServer.ts +1 -1
- package/src/unstable/http/HttpServerRequest.ts +11 -11
- package/src/unstable/http/HttpServerResponse.ts +5 -5
- package/src/unstable/http/Multipart.ts +1 -1
- package/src/unstable/httpapi/HttpApiBuilder.ts +4 -4
- package/src/unstable/httpapi/HttpApiClient.ts +1 -1
- package/src/unstable/httpapi/HttpApiMiddleware.ts +2 -1
- package/src/unstable/httpapi/HttpApiTest.ts +5 -2
- package/src/unstable/persistence/RateLimiter.ts +1 -1
- package/src/unstable/process/ChildProcess.ts +11 -14
- package/src/unstable/reactivity/Atom.ts +4 -4
- package/src/unstable/rpc/RpcClient.ts +1 -1
- package/src/unstable/rpc/RpcServer.ts +1 -2
- package/src/unstable/rpc/RpcWorker.ts +2 -2
- package/src/unstable/socket/Socket.ts +1 -1
- package/src/unstable/sql/Migrator.ts +5 -2
- package/src/unstable/sql/SqlError.ts +72 -1
- package/src/unstable/workflow/Activity.ts +1 -1
- package/src/unstable/workflow/DurableQueue.ts +343 -0
- package/src/unstable/workflow/Workflow.ts +1 -1
- package/src/unstable/workflow/index.ts +5 -0
|
@@ -376,7 +376,7 @@ export const file = (
|
|
|
376
376
|
}
|
|
377
377
|
): Effect.Effect<Stream, PlatformError.PlatformError, FileSystem.FileSystem> =>
|
|
378
378
|
Effect.flatMap(
|
|
379
|
-
FileSystem.FileSystem
|
|
379
|
+
FileSystem.FileSystem,
|
|
380
380
|
(fs) =>
|
|
381
381
|
Effect.map(fs.stat(path), (info) =>
|
|
382
382
|
stream(
|
|
@@ -401,7 +401,7 @@ export const fileFromInfo = (
|
|
|
401
401
|
}
|
|
402
402
|
): Effect.Effect<Stream, PlatformError.PlatformError, FileSystem.FileSystem> =>
|
|
403
403
|
Effect.map(
|
|
404
|
-
FileSystem.FileSystem
|
|
404
|
+
FileSystem.FileSystem,
|
|
405
405
|
(fs) =>
|
|
406
406
|
stream(
|
|
407
407
|
fs.stream(path, options),
|
|
@@ -119,7 +119,7 @@ export const HttpClient: Context.Service<HttpClient, HttpClient> = Context.Servi
|
|
|
119
119
|
|
|
120
120
|
const accessor = (method: keyof HttpClient) => (...args: Array<any>): Effect.Effect<any, any, any> =>
|
|
121
121
|
Effect.flatMap(
|
|
122
|
-
HttpClient
|
|
122
|
+
HttpClient,
|
|
123
123
|
(client) => (client as any)[method](...args)
|
|
124
124
|
)
|
|
125
125
|
|
|
@@ -1051,8 +1051,8 @@ export const toWeb = (self: HttpClientRequest, options?: {
|
|
|
1051
1051
|
readonly signal?: AbortSignal | undefined
|
|
1052
1052
|
}): Effect.Effect<Request, UrlParams.UrlParamsError> =>
|
|
1053
1053
|
Effect.contextWith((context) =>
|
|
1054
|
-
toWebResult(self, {
|
|
1054
|
+
Effect.fromResult(toWebResult(self, {
|
|
1055
1055
|
context: context,
|
|
1056
1056
|
signal: options?.signal
|
|
1057
|
-
})
|
|
1057
|
+
}))
|
|
1058
1058
|
)
|
|
@@ -105,9 +105,8 @@ export const SpanNameGenerator = Context.Reference<(request: HttpServerRequest)
|
|
|
105
105
|
*/
|
|
106
106
|
export const logger: <E, R>(
|
|
107
107
|
httpApp: Effect.Effect<HttpServerResponse, E, HttpServerRequest | R>
|
|
108
|
-
) => Effect.Effect<HttpServerResponse, E, HttpServerRequest | R> = make((httpApp) =>
|
|
109
|
-
|
|
110
|
-
return Effect.withFiber((fiber) => {
|
|
108
|
+
) => Effect.Effect<HttpServerResponse, E, HttpServerRequest | R> = make((httpApp) =>
|
|
109
|
+
Effect.withFiber((fiber) => {
|
|
111
110
|
const request = Context.getUnsafe(fiber.context, HttpServerRequest)
|
|
112
111
|
const path = stripSearchAndHash(request.url)
|
|
113
112
|
return Effect.withLogSpan(
|
|
@@ -134,10 +133,10 @@ export const logger: <E, R>(
|
|
|
134
133
|
exit
|
|
135
134
|
)
|
|
136
135
|
}),
|
|
137
|
-
|
|
136
|
+
"http.span"
|
|
138
137
|
)
|
|
139
138
|
})
|
|
140
|
-
|
|
139
|
+
)
|
|
141
140
|
|
|
142
141
|
/**
|
|
143
142
|
* @since 4.0.0
|
|
@@ -121,7 +121,7 @@ export const make: (impl: {
|
|
|
121
121
|
* @category layers
|
|
122
122
|
*/
|
|
123
123
|
export const layer = Layer.effect(HttpPlatform)(
|
|
124
|
-
Effect.flatMap(FileSystem.FileSystem
|
|
124
|
+
Effect.flatMap(FileSystem.FileSystem, (fs) =>
|
|
125
125
|
make({
|
|
126
126
|
fileResponse(path, status, statusText, headers, start, end, contentLength) {
|
|
127
127
|
return Response.stream(
|
|
@@ -148,7 +148,7 @@ export const make = Effect.gen(function*() {
|
|
|
148
148
|
Effect.succeed(handler) :
|
|
149
149
|
Effect.isEffect(handler)
|
|
150
150
|
? handler
|
|
151
|
-
: Effect.flatMap(HttpServerRequest.HttpServerRequest
|
|
151
|
+
: Effect.flatMap(HttpServerRequest.HttpServerRequest, handler),
|
|
152
152
|
uninterruptible: options?.uninterruptible ?? false,
|
|
153
153
|
prefix
|
|
154
154
|
})
|
|
@@ -240,7 +240,7 @@ export const params: Effect.Effect<
|
|
|
240
240
|
ReadonlyRecord<string, string | undefined>,
|
|
241
241
|
never,
|
|
242
242
|
RouteContext
|
|
243
|
-
> = Effect.map(RouteContext
|
|
243
|
+
> = Effect.map(RouteContext, (_) => _.params)
|
|
244
244
|
|
|
245
245
|
/**
|
|
246
246
|
* @since 4.0.0
|
|
@@ -385,8 +385,7 @@ export const schemaPathParams = <A, I extends Readonly<Record<string, string | u
|
|
|
385
385
|
*/
|
|
386
386
|
export const use = <A, E, R>(
|
|
387
387
|
f: (router: HttpRouter) => Effect.Effect<A, E, R>
|
|
388
|
-
): Layer.Layer<never, E, HttpRouter | Exclude<R, Scope.Scope>> =>
|
|
389
|
-
Layer.effectDiscard(Effect.flatMap(HttpRouter.asEffect(), f))
|
|
388
|
+
): Layer.Layer<never, E, HttpRouter | Exclude<R, Scope.Scope>> => Layer.effectDiscard(Effect.flatMap(HttpRouter, f))
|
|
390
389
|
|
|
391
390
|
/**
|
|
392
391
|
* Create a layer that adds a single route to the HTTP router.
|
|
@@ -559,7 +558,7 @@ export const route = <E = never, R = never>(
|
|
|
559
558
|
Effect.succeed(handler) :
|
|
560
559
|
Effect.isEffect(handler)
|
|
561
560
|
? handler
|
|
562
|
-
: Effect.flatMap(HttpServerRequest.HttpServerRequest
|
|
561
|
+
: Effect.flatMap(HttpServerRequest.HttpServerRequest, handler),
|
|
563
562
|
uninterruptible: options?.uninterruptible ?? false
|
|
564
563
|
})
|
|
565
564
|
|
|
@@ -201,7 +201,7 @@ export const addressFormattedWith = <A, E, R>(
|
|
|
201
201
|
f: (address: string) => Effect.Effect<A, E, R>
|
|
202
202
|
): Effect.Effect<A, E, HttpServer | R> =>
|
|
203
203
|
Effect.flatMap(
|
|
204
|
-
HttpServer
|
|
204
|
+
HttpServer,
|
|
205
205
|
(server) => f(formatAddress(server.address))
|
|
206
206
|
)
|
|
207
207
|
|
|
@@ -121,7 +121,7 @@ export const upgradeChannel = <IE = never>(): Channel.Channel<
|
|
|
121
121
|
unknown,
|
|
122
122
|
HttpServerRequest
|
|
123
123
|
> =>
|
|
124
|
-
HttpServerRequest.
|
|
124
|
+
HttpServerRequest.pipe(
|
|
125
125
|
Effect.flatMap((_) => _.upgrade),
|
|
126
126
|
Effect.map(Socket.toChannelWith<IE>()),
|
|
127
127
|
Channel.unwrap
|
|
@@ -136,7 +136,7 @@ export const schemaCookies = <A, I extends Readonly<Record<string, string | unde
|
|
|
136
136
|
options?: ParseOptions | undefined
|
|
137
137
|
): Effect.Effect<A, Schema.SchemaError, RD | HttpServerRequest> => {
|
|
138
138
|
const parse = Schema.decodeUnknownEffect(schema)
|
|
139
|
-
return Effect.flatMap(HttpServerRequest
|
|
139
|
+
return Effect.flatMap(HttpServerRequest, (req) => parse(req.cookies, options))
|
|
140
140
|
}
|
|
141
141
|
|
|
142
142
|
/**
|
|
@@ -148,7 +148,7 @@ export const schemaHeaders = <A, I extends Readonly<Record<string, string | unde
|
|
|
148
148
|
options?: ParseOptions | undefined
|
|
149
149
|
): Effect.Effect<A, Schema.SchemaError, HttpServerRequest | RD> => {
|
|
150
150
|
const parse = Schema.decodeUnknownEffect(schema)
|
|
151
|
-
return Effect.flatMap(HttpServerRequest
|
|
151
|
+
return Effect.flatMap(HttpServerRequest, (req) => parse(req.headers, options))
|
|
152
152
|
}
|
|
153
153
|
|
|
154
154
|
/**
|
|
@@ -165,7 +165,7 @@ export const schemaSearchParams = <
|
|
|
165
165
|
options?: ParseOptions | undefined
|
|
166
166
|
): Effect.Effect<A, Schema.SchemaError, ParsedSearchParams | RD> => {
|
|
167
167
|
const parse = Schema.decodeUnknownEffect(schema)
|
|
168
|
-
return Effect.flatMap(ParsedSearchParams
|
|
168
|
+
return Effect.flatMap(ParsedSearchParams, (params) => parse(params, options))
|
|
169
169
|
}
|
|
170
170
|
/**
|
|
171
171
|
* @since 4.0.0
|
|
@@ -176,7 +176,7 @@ export const schemaBodyJson = <A, I, RD, RE>(
|
|
|
176
176
|
options?: ParseOptions | undefined
|
|
177
177
|
): Effect.Effect<A, HttpServerError | Schema.SchemaError, HttpServerRequest | RD> => {
|
|
178
178
|
const parse = HttpIncomingMessage.schemaBodyJson(schema, options)
|
|
179
|
-
return Effect.flatMap(HttpServerRequest
|
|
179
|
+
return Effect.flatMap(HttpServerRequest, parse)
|
|
180
180
|
}
|
|
181
181
|
|
|
182
182
|
const isMultipart = (request: HttpServerRequest) =>
|
|
@@ -193,7 +193,7 @@ export const schemaBodyForm = <A, I extends Partial<Multipart.Persisted>, RD, RE
|
|
|
193
193
|
) => {
|
|
194
194
|
const parseMultipart = Multipart.schemaPersisted(schema)
|
|
195
195
|
const parseUrlParams = HttpIncomingMessage.schemaBodyUrlParams(schema as Schema.Codec<A, any, RD, RE>, options)
|
|
196
|
-
return Effect.flatMap(HttpServerRequest
|
|
196
|
+
return Effect.flatMap(HttpServerRequest, (request): Effect.Effect<
|
|
197
197
|
A,
|
|
198
198
|
Multipart.MultipartError | Schema.SchemaError | HttpServerError,
|
|
199
199
|
RD | HttpServerRequest | Scope.Scope | FileSystem.FileSystem | Path.Path
|
|
@@ -219,7 +219,7 @@ export const schemaBodyUrlParams = <
|
|
|
219
219
|
options?: ParseOptions | undefined
|
|
220
220
|
): Effect.Effect<A, HttpServerError | Schema.SchemaError, HttpServerRequest | RD> => {
|
|
221
221
|
const parse = HttpIncomingMessage.schemaBodyUrlParams(schema, options)
|
|
222
|
-
return Effect.flatMap(HttpServerRequest
|
|
222
|
+
return Effect.flatMap(HttpServerRequest, parse)
|
|
223
223
|
}
|
|
224
224
|
|
|
225
225
|
/**
|
|
@@ -235,7 +235,7 @@ export const schemaBodyMultipart = <A, I extends Partial<Multipart.Persisted>, R
|
|
|
235
235
|
HttpServerRequest | Scope.Scope | FileSystem.FileSystem | Path.Path | RD
|
|
236
236
|
> => {
|
|
237
237
|
const parse = Multipart.schemaPersisted(schema)
|
|
238
|
-
return HttpServerRequest.
|
|
238
|
+
return HttpServerRequest.pipe(
|
|
239
239
|
Effect.flatMap((_) => _.multipart),
|
|
240
240
|
Effect.flatMap((_) => parse(_, options))
|
|
241
241
|
)
|
|
@@ -256,7 +256,7 @@ export const schemaBodyFormJson = <A, I, RD, RE>(
|
|
|
256
256
|
Schema.decodeEffect
|
|
257
257
|
)
|
|
258
258
|
return Effect.flatMap(
|
|
259
|
-
HttpServerRequest
|
|
259
|
+
HttpServerRequest,
|
|
260
260
|
(request): Effect.Effect<
|
|
261
261
|
A,
|
|
262
262
|
Schema.SchemaError | HttpServerError,
|
|
@@ -933,8 +933,8 @@ export const toWeb = (self: HttpServerRequest, options?: {
|
|
|
933
933
|
readonly signal?: AbortSignal | undefined
|
|
934
934
|
}): Effect.Effect<Request, RequestError> =>
|
|
935
935
|
Effect.contextWith((context) =>
|
|
936
|
-
toWebResult(self, {
|
|
936
|
+
Effect.fromResult(toWebResult(self, {
|
|
937
937
|
context,
|
|
938
938
|
signal: options?.signal
|
|
939
|
-
})
|
|
939
|
+
}))
|
|
940
940
|
)
|
|
@@ -379,7 +379,7 @@ export const file = (
|
|
|
379
379
|
})
|
|
380
380
|
| undefined
|
|
381
381
|
): Effect.Effect<HttpServerResponse, PlatformError, HttpPlatform> =>
|
|
382
|
-
Effect.flatMap(HttpPlatformKey
|
|
382
|
+
Effect.flatMap(HttpPlatformKey, (platform) => platform.fileResponse(path, options))
|
|
383
383
|
|
|
384
384
|
/**
|
|
385
385
|
* @since 4.0.0
|
|
@@ -395,7 +395,7 @@ export const fileWeb = (
|
|
|
395
395
|
})
|
|
396
396
|
| undefined
|
|
397
397
|
): Effect.Effect<HttpServerResponse, never, HttpPlatform> =>
|
|
398
|
-
Effect.flatMap(HttpPlatformKey
|
|
398
|
+
Effect.flatMap(HttpPlatformKey, (platform) => platform.fileWebResponse(file, options))
|
|
399
399
|
|
|
400
400
|
/**
|
|
401
401
|
* @since 4.0.0
|
|
@@ -520,7 +520,7 @@ export const setCookie: {
|
|
|
520
520
|
options?: Cookies.Cookie["options"]
|
|
521
521
|
): Effect.Effect<HttpServerResponse, Cookies.CookiesError> =>
|
|
522
522
|
Effect.map(
|
|
523
|
-
Cookies.set(self.cookies, name, value, options)
|
|
523
|
+
Effect.fromResult(Cookies.set(self.cookies, name, value, options)),
|
|
524
524
|
(cookies) =>
|
|
525
525
|
makeResponse({
|
|
526
526
|
...self,
|
|
@@ -561,7 +561,7 @@ export const expireCookie: {
|
|
|
561
561
|
options?: Omit<NonNullable<Cookies.Cookie["options"]>, "expires" | "maxAge">
|
|
562
562
|
): Effect.Effect<HttpServerResponse, Cookies.CookiesError> =>
|
|
563
563
|
Effect.map(
|
|
564
|
-
Cookies.expireCookie(self.cookies, name, options)
|
|
564
|
+
Effect.fromResult(Cookies.expireCookie(self.cookies, name, options)),
|
|
565
565
|
(cookies) =>
|
|
566
566
|
makeResponse({
|
|
567
567
|
...self,
|
|
@@ -733,7 +733,7 @@ export const setCookies: {
|
|
|
733
733
|
]
|
|
734
734
|
>
|
|
735
735
|
): Effect.Effect<HttpServerResponse, Cookies.CookiesError> =>
|
|
736
|
-
Effect.map(Cookies.setAll(self.cookies, cookies)
|
|
736
|
+
Effect.map(Effect.fromResult(Cookies.setAll(self.cookies, cookies)), (cookies) =>
|
|
737
737
|
makeResponse({
|
|
738
738
|
...self,
|
|
739
739
|
cookies
|
|
@@ -455,7 +455,7 @@ class FileImpl extends PartBase implements File {
|
|
|
455
455
|
|
|
456
456
|
const defaultWriteFile = (path: string, file: File) =>
|
|
457
457
|
Effect.flatMap(
|
|
458
|
-
FileSystem.FileSystem
|
|
458
|
+
FileSystem.FileSystem,
|
|
459
459
|
(fs) =>
|
|
460
460
|
Effect.mapError(
|
|
461
461
|
Stream.run(file.content, fs.sink(path)),
|
|
@@ -364,7 +364,7 @@ export const securityDecode = <Security extends HttpApiSecurity.HttpApiSecurity>
|
|
|
364
364
|
switch (self._tag) {
|
|
365
365
|
case "Bearer": {
|
|
366
366
|
return Effect.map(
|
|
367
|
-
HttpServerRequest
|
|
367
|
+
HttpServerRequest,
|
|
368
368
|
(request) => Redacted.make((request.headers.authorization ?? "").slice(bearerLen)) as any
|
|
369
369
|
)
|
|
370
370
|
}
|
|
@@ -392,9 +392,9 @@ export const securityDecode = <Security extends HttpApiSecurity.HttpApiSecurity>
|
|
|
392
392
|
username: "",
|
|
393
393
|
password: Redacted.make("")
|
|
394
394
|
} as any
|
|
395
|
-
return HttpServerRequest.
|
|
395
|
+
return HttpServerRequest.pipe(
|
|
396
396
|
Effect.flatMap((request) =>
|
|
397
|
-
Encoding.decodeBase64String((request.headers.authorization ?? "").slice(basicLen))
|
|
397
|
+
Effect.fromResult(Encoding.decodeBase64String((request.headers.authorization ?? "").slice(basicLen)))
|
|
398
398
|
),
|
|
399
399
|
Effect.match({
|
|
400
400
|
onFailure: () => empty,
|
|
@@ -722,7 +722,7 @@ const makeSecurityMiddleware = (
|
|
|
722
722
|
}
|
|
723
723
|
return result.success
|
|
724
724
|
}
|
|
725
|
-
return yield* lastResult
|
|
725
|
+
return yield* Effect.fromResult(lastResult!)
|
|
726
726
|
})
|
|
727
727
|
|
|
728
728
|
securityMiddlewareCache.set(service, middleware)
|
|
@@ -386,7 +386,7 @@ export const make = <ApiId extends string, Groups extends HttpApiGroup.Any>(
|
|
|
386
386
|
never,
|
|
387
387
|
HttpClient.HttpClient | HttpApiGroup.MiddlewareClient<Groups>
|
|
388
388
|
> =>
|
|
389
|
-
Effect.flatMap(HttpClient.HttpClient
|
|
389
|
+
Effect.flatMap(HttpClient.HttpClient, (httpClient) =>
|
|
390
390
|
makeWith(api, {
|
|
391
391
|
...options,
|
|
392
392
|
httpClient: options?.transformClient ? options.transformClient(httpClient) : httpClient
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @since 4.0.0
|
|
3
3
|
*/
|
|
4
|
+
/** @effect-diagnostics floatingEffect:skip-file */
|
|
5
|
+
/** @effect-diagnostics classSelfMismatch:off */
|
|
4
6
|
import * as Context from "../../Context.ts"
|
|
5
7
|
import * as Effect from "../../Effect.ts"
|
|
6
8
|
import * as Layer from "../../Layer.ts"
|
|
@@ -280,7 +282,6 @@ export const Service = <
|
|
|
280
282
|
const creationError = new Err()
|
|
281
283
|
Err.stackTraceLimit = limit
|
|
282
284
|
|
|
283
|
-
/** @effect-diagnostics-next-line classSelfMismatch:off */
|
|
284
285
|
class Service extends Context.Service<Self, any>()(id) {}
|
|
285
286
|
const self = Service as any
|
|
286
287
|
Object.defineProperty(Service, "stack", {
|
|
@@ -31,7 +31,10 @@ export const groups = Effect.fnUntraced(function*<
|
|
|
31
31
|
SelectedGroups = HttpApiGroup.WithName<Groups, Names[number]>
|
|
32
32
|
>(
|
|
33
33
|
api: HttpApi.HttpApi<ApiId, Groups>,
|
|
34
|
-
groupNames: Names
|
|
34
|
+
groupNames: Names,
|
|
35
|
+
options?: {
|
|
36
|
+
readonly baseUrl?: string | URL | undefined
|
|
37
|
+
}
|
|
35
38
|
): Effect.fn.Return<
|
|
36
39
|
HttpApiClient.Client<Groups>,
|
|
37
40
|
never,
|
|
@@ -90,6 +93,6 @@ export const groups = Effect.fnUntraced(function*<
|
|
|
90
93
|
|
|
91
94
|
return yield* HttpApiClient.makeWith(api, {
|
|
92
95
|
httpClient,
|
|
93
|
-
baseUrl: "http://localhost:3000"
|
|
96
|
+
baseUrl: options?.baseUrl ?? "http://localhost:3000"
|
|
94
97
|
})
|
|
95
98
|
})
|
|
@@ -666,5 +666,5 @@ export const layerStoreRedisConfig = (
|
|
|
666
666
|
): Layer.Layer<RateLimiterStore, Config.ConfigError, Redis.Redis> =>
|
|
667
667
|
Layer.effect(
|
|
668
668
|
RateLimiterStore,
|
|
669
|
-
Effect.flatMap(Config.unwrap(options)
|
|
669
|
+
Effect.flatMap(Config.unwrap(options), makeStoreRedis)
|
|
670
670
|
)
|
|
@@ -40,11 +40,11 @@
|
|
|
40
40
|
*
|
|
41
41
|
* @since 4.0.0
|
|
42
42
|
*/
|
|
43
|
+
import * as Context from "../../Context.ts"
|
|
43
44
|
import type * as Duration from "../../Duration.ts"
|
|
44
45
|
import type * as Effect from "../../Effect.ts"
|
|
46
|
+
import * as Effectable from "../../Effectable.ts"
|
|
45
47
|
import { dual } from "../../Function.ts"
|
|
46
|
-
import { PipeInspectableProto, YieldableProto } from "../../internal/core.ts"
|
|
47
|
-
import type { Pipeable } from "../../Pipeable.ts"
|
|
48
48
|
import type * as PlatformError from "../../PlatformError.ts"
|
|
49
49
|
import * as Predicate from "../../Predicate.ts"
|
|
50
50
|
import type * as Scope from "../../Scope.ts"
|
|
@@ -74,9 +74,7 @@ export type Command =
|
|
|
74
74
|
* @category Models
|
|
75
75
|
*/
|
|
76
76
|
export interface StandardCommand extends
|
|
77
|
-
|
|
78
|
-
Effect.Yieldable<
|
|
79
|
-
StandardCommand,
|
|
77
|
+
Effect.Effect<
|
|
80
78
|
ChildProcessHandle,
|
|
81
79
|
PlatformError.PlatformError,
|
|
82
80
|
ChildProcessSpawner | Scope.Scope
|
|
@@ -96,9 +94,7 @@ export interface StandardCommand extends
|
|
|
96
94
|
* @category Models
|
|
97
95
|
*/
|
|
98
96
|
export interface PipedCommand extends
|
|
99
|
-
|
|
100
|
-
Effect.Yieldable<
|
|
101
|
-
PipedCommand,
|
|
97
|
+
Effect.Effect<
|
|
102
98
|
ChildProcessHandle,
|
|
103
99
|
PlatformError.PlatformError,
|
|
104
100
|
ChildProcessSpawner | Scope.Scope
|
|
@@ -510,12 +506,13 @@ export type TemplateExpression = TemplateExpressionItem | ReadonlyArray<Template
|
|
|
510
506
|
// =============================================================================
|
|
511
507
|
|
|
512
508
|
const Proto = {
|
|
513
|
-
...
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
}
|
|
509
|
+
...Effectable.Prototype<Command>({
|
|
510
|
+
label: "Command",
|
|
511
|
+
evaluate(fiber) {
|
|
512
|
+
return Context.getUnsafe(fiber.context, ChildProcessSpawner).spawn(this)
|
|
513
|
+
}
|
|
514
|
+
}),
|
|
515
|
+
[TypeId]: TypeId
|
|
519
516
|
}
|
|
520
517
|
|
|
521
518
|
/**
|
|
@@ -2316,7 +2316,7 @@ export const modify: {
|
|
|
2316
2316
|
} = dual(
|
|
2317
2317
|
2,
|
|
2318
2318
|
<R, W, A>(self: Writable<R, W>, f: (_: R) => [returnValue: A, nextValue: W]): Effect.Effect<A, never, AtomRegistry> =>
|
|
2319
|
-
Effect.map(AtomRegistry
|
|
2319
|
+
Effect.map(AtomRegistry, (_) => _.modify(self, f))
|
|
2320
2320
|
)
|
|
2321
2321
|
|
|
2322
2322
|
/**
|
|
@@ -2337,7 +2337,7 @@ export const set: {
|
|
|
2337
2337
|
} = dual(
|
|
2338
2338
|
2,
|
|
2339
2339
|
<R, W>(self: Writable<R, W>, value: W): Effect.Effect<void, never, AtomRegistry> =>
|
|
2340
|
-
Effect.map(AtomRegistry
|
|
2340
|
+
Effect.map(AtomRegistry, (_) => _.set(self, value))
|
|
2341
2341
|
)
|
|
2342
2342
|
|
|
2343
2343
|
/**
|
|
@@ -2358,7 +2358,7 @@ export const update: {
|
|
|
2358
2358
|
} = dual(
|
|
2359
2359
|
2,
|
|
2360
2360
|
<R, W>(self: Writable<R, W>, f: (_: R) => W): Effect.Effect<void, never, AtomRegistry> =>
|
|
2361
|
-
Effect.map(AtomRegistry
|
|
2361
|
+
Effect.map(AtomRegistry, (_) => _.update(self, f))
|
|
2362
2362
|
)
|
|
2363
2363
|
|
|
2364
2364
|
/**
|
|
@@ -2375,7 +2375,7 @@ export const getResult = <A, E>(
|
|
|
2375
2375
|
* @category Conversions
|
|
2376
2376
|
*/
|
|
2377
2377
|
export const refresh = <A>(self: Atom<A>): Effect.Effect<void, never, AtomRegistry> =>
|
|
2378
|
-
Effect.map(AtomRegistry
|
|
2378
|
+
Effect.map(AtomRegistry, (_) => _.refresh(self))
|
|
2379
2379
|
|
|
2380
2380
|
/**
|
|
2381
2381
|
* @since 4.0.0
|
|
@@ -916,7 +916,7 @@ export const layerProtocolHttp = (options: {
|
|
|
916
916
|
}): Layer.Layer<Protocol, never, RpcSerialization.RpcSerialization | HttpClient.HttpClient> =>
|
|
917
917
|
Layer.effect(Protocol)(
|
|
918
918
|
Effect.flatMap(
|
|
919
|
-
HttpClient.HttpClient
|
|
919
|
+
HttpClient.HttpClient,
|
|
920
920
|
(client) => {
|
|
921
921
|
client = HttpClient.mapRequest(client, HttpClientRequest.prependUrl(options.url))
|
|
922
922
|
return makeProtocolHttp(options.transformClient ? options.transformClient(client) : client)
|
|
@@ -961,6 +961,7 @@ export const makeProtocolWithHttpEffect: Effect.Effect<
|
|
|
961
961
|
const id = clientId++
|
|
962
962
|
const queue = yield* Queue.make<Uint8Array | FromServerEncoded, Cause.Done>()
|
|
963
963
|
const parser = serialization.makeUnsafe()
|
|
964
|
+
const requestIds: Array<RequestId> = []
|
|
964
965
|
|
|
965
966
|
const offer = (data: Uint8Array | string) =>
|
|
966
967
|
typeof data === "string" ? Queue.offer(queue, encoder.encode(data)) : Queue.offer(queue, data)
|
|
@@ -993,8 +994,6 @@ export const makeProtocolWithHttpEffect: Effect.Effect<
|
|
|
993
994
|
clients.set(id, client)
|
|
994
995
|
clientIds.add(id)
|
|
995
996
|
|
|
996
|
-
const requestIds: Array<RequestId> = []
|
|
997
|
-
|
|
998
997
|
// @effect-diagnostics-next-line tryCatchInEffectGen:off
|
|
999
998
|
try {
|
|
1000
999
|
const decoded = parser.decode(data) as ReadonlyArray<FromClientEncoded>
|
|
@@ -85,8 +85,8 @@ export const layerInitialMessage = <S extends Schema.Top, R2>(
|
|
|
85
85
|
export const initialMessage = <S extends Schema.Top>(
|
|
86
86
|
schema: S
|
|
87
87
|
): Effect.Effect<S["Type"], NoSuchElementError | Schema.SchemaError, Protocol | S["DecodingServices"]> =>
|
|
88
|
-
ProtocolTag.
|
|
88
|
+
ProtocolTag.pipe(
|
|
89
89
|
Effect.flatMap((protocol) => protocol.initialMessage),
|
|
90
|
-
Effect.flatMap(
|
|
90
|
+
Effect.flatMap(Effect.fromOption),
|
|
91
91
|
Effect.flatMap(Schema.decodeUnknownEffect(Schema.toCodecJson(schema)))
|
|
92
92
|
)
|
|
@@ -448,7 +448,7 @@ export const makeChannel = <IE = never>(): Channel.Channel<
|
|
|
448
448
|
IE,
|
|
449
449
|
unknown,
|
|
450
450
|
Socket
|
|
451
|
-
> => Channel.unwrap(Effect.map(Socket
|
|
451
|
+
> => Channel.unwrap(Effect.map(Socket, toChannelWith<IE>()))
|
|
452
452
|
|
|
453
453
|
/**
|
|
454
454
|
* @since 4.0.0
|
|
@@ -114,7 +114,7 @@ export const make = <RD = never>({
|
|
|
114
114
|
migration_id integer primary key,
|
|
115
115
|
created_at timestamp with time zone not null default now(),
|
|
116
116
|
name text not null
|
|
117
|
-
)
|
|
117
|
+
)`
|
|
118
118
|
),
|
|
119
119
|
orElse: () =>
|
|
120
120
|
sql`CREATE TABLE IF NOT EXISTS ${sql(table)} (
|
|
@@ -237,7 +237,7 @@ export const make = <RD = never>({
|
|
|
237
237
|
yield* pipe(
|
|
238
238
|
insertMigrations(required.map(([id, name]) => [id, name])),
|
|
239
239
|
Effect.mapError((error): MigrationError | SqlError =>
|
|
240
|
-
error
|
|
240
|
+
isConstraintConflict(error)
|
|
241
241
|
? new MigrationError({
|
|
242
242
|
kind: "Locked",
|
|
243
243
|
message: "Migrations already running"
|
|
@@ -297,6 +297,9 @@ export const make = <RD = never>({
|
|
|
297
297
|
|
|
298
298
|
const migrationOrder = Order.make<ResolvedMigration>(([a], [b]) => Order.Number(a, b))
|
|
299
299
|
|
|
300
|
+
const isConstraintConflict = (error: SqlError): boolean =>
|
|
301
|
+
error.reason._tag === "ConstraintError" || error.reason._tag === "UniqueViolation"
|
|
302
|
+
|
|
300
303
|
/**
|
|
301
304
|
* @since 4.0.0
|
|
302
305
|
* @category loaders
|
|
@@ -91,6 +91,31 @@ export class SqlSyntaxError extends Schema.TaggedErrorClass<SqlSyntaxError>("eff
|
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
+
const UniqueViolationFields = {
|
|
95
|
+
...ReasonFields,
|
|
96
|
+
constraint: Schema.String
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* @since 4.0.0
|
|
101
|
+
*/
|
|
102
|
+
export class UniqueViolation extends Schema.TaggedErrorClass<UniqueViolation>("effect/sql/SqlError/UniqueViolation")(
|
|
103
|
+
"UniqueViolation",
|
|
104
|
+
UniqueViolationFields
|
|
105
|
+
) {
|
|
106
|
+
/**
|
|
107
|
+
* @since 4.0.0
|
|
108
|
+
*/
|
|
109
|
+
readonly [ReasonTypeId] = ReasonTypeId
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* @since 4.0.0
|
|
113
|
+
*/
|
|
114
|
+
get isRetryable(): boolean {
|
|
115
|
+
return false
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
94
119
|
/**
|
|
95
120
|
* @since 4.0.0
|
|
96
121
|
*/
|
|
@@ -217,6 +242,7 @@ export type SqlErrorReason =
|
|
|
217
242
|
| AuthenticationError
|
|
218
243
|
| AuthorizationError
|
|
219
244
|
| SqlSyntaxError
|
|
245
|
+
| UniqueViolation
|
|
220
246
|
| ConstraintError
|
|
221
247
|
| DeadlockError
|
|
222
248
|
| SerializationError
|
|
@@ -232,6 +258,7 @@ export const SqlErrorReason: Schema.Union<[
|
|
|
232
258
|
typeof AuthenticationError,
|
|
233
259
|
typeof AuthorizationError,
|
|
234
260
|
typeof SqlSyntaxError,
|
|
261
|
+
typeof UniqueViolation,
|
|
235
262
|
typeof ConstraintError,
|
|
236
263
|
typeof DeadlockError,
|
|
237
264
|
typeof SerializationError,
|
|
@@ -243,6 +270,7 @@ export const SqlErrorReason: Schema.Union<[
|
|
|
243
270
|
AuthenticationError,
|
|
244
271
|
AuthorizationError,
|
|
245
272
|
SqlSyntaxError,
|
|
273
|
+
UniqueViolation,
|
|
246
274
|
ConstraintError,
|
|
247
275
|
DeadlockError,
|
|
248
276
|
SerializationError,
|
|
@@ -317,9 +345,48 @@ const sqliteNumericCodeFromCause = (cause: unknown): number | undefined => {
|
|
|
317
345
|
return typeof errno === "number" ? errno : undefined
|
|
318
346
|
}
|
|
319
347
|
|
|
348
|
+
const matchesSqliteNumericCode = (cause: unknown, expected: number): boolean => {
|
|
349
|
+
const code = sqliteCodeFromCause(cause)
|
|
350
|
+
if (code === expected) {
|
|
351
|
+
return true
|
|
352
|
+
}
|
|
353
|
+
if (!Predicate.hasProperty(cause, "errno")) {
|
|
354
|
+
return false
|
|
355
|
+
}
|
|
356
|
+
return cause.errno === expected
|
|
357
|
+
}
|
|
358
|
+
|
|
320
359
|
const matchesSqliteCode = (code: string, expected: string): boolean =>
|
|
321
360
|
code === expected || code.startsWith(expected + "_")
|
|
322
361
|
|
|
362
|
+
const UNKNOWN_CONSTRAINT = "unknown"
|
|
363
|
+
const SQLITE_CONSTRAINT_UNIQUE = "SQLITE_CONSTRAINT_UNIQUE"
|
|
364
|
+
const SQLITE_CONSTRAINT_UNIQUE_CODE = 2067
|
|
365
|
+
|
|
366
|
+
const normalizeConstraintIdentifier = (identifier: unknown): string => {
|
|
367
|
+
if (typeof identifier !== "string") {
|
|
368
|
+
return UNKNOWN_CONSTRAINT
|
|
369
|
+
}
|
|
370
|
+
const trimmed = identifier.trim()
|
|
371
|
+
return trimmed.length === 0 ? UNKNOWN_CONSTRAINT : trimmed
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
const sqliteUniqueConstraintFromCause = (cause: unknown): string => {
|
|
375
|
+
if (Predicate.hasProperty(cause, "constraint")) {
|
|
376
|
+
return normalizeConstraintIdentifier(cause.constraint)
|
|
377
|
+
}
|
|
378
|
+
if (!Predicate.hasProperty(cause, "message")) {
|
|
379
|
+
return UNKNOWN_CONSTRAINT
|
|
380
|
+
}
|
|
381
|
+
const message = cause.message
|
|
382
|
+
if (typeof message !== "string") {
|
|
383
|
+
return UNKNOWN_CONSTRAINT
|
|
384
|
+
}
|
|
385
|
+
const prefix = "UNIQUE constraint failed:"
|
|
386
|
+
const index = message.indexOf(prefix)
|
|
387
|
+
return index === -1 ? UNKNOWN_CONSTRAINT : normalizeConstraintIdentifier(message.slice(index + prefix.length))
|
|
388
|
+
}
|
|
389
|
+
|
|
323
390
|
/**
|
|
324
391
|
* @since 4.0.0
|
|
325
392
|
*/
|
|
@@ -333,6 +400,11 @@ export const classifySqliteError = (
|
|
|
333
400
|
operation
|
|
334
401
|
}
|
|
335
402
|
const code = sqliteCodeFromCause(cause)
|
|
403
|
+
const numericCode = sqliteNumericCodeFromCause(cause)
|
|
404
|
+
|
|
405
|
+
if (code === SQLITE_CONSTRAINT_UNIQUE || matchesSqliteNumericCode(cause, SQLITE_CONSTRAINT_UNIQUE_CODE)) {
|
|
406
|
+
return new UniqueViolation({ ...props, constraint: sqliteUniqueConstraintFromCause(cause) })
|
|
407
|
+
}
|
|
336
408
|
|
|
337
409
|
if (typeof code === "string") {
|
|
338
410
|
if (matchesSqliteCode(code, "SQLITE_AUTH")) {
|
|
@@ -352,7 +424,6 @@ export const classifySqliteError = (
|
|
|
352
424
|
}
|
|
353
425
|
}
|
|
354
426
|
|
|
355
|
-
const numericCode = sqliteNumericCodeFromCause(cause)
|
|
356
427
|
if (typeof numericCode === "number") {
|
|
357
428
|
const code = numericCode & 0xff
|
|
358
429
|
switch (code) {
|
|
@@ -256,7 +256,7 @@ export const raceAll = <const Activities extends NonEmptyReadonlyArray<Any>>(
|
|
|
256
256
|
error: Schema.Union(
|
|
257
257
|
activities.map((activity) => (activity as any).errorSchema)
|
|
258
258
|
),
|
|
259
|
-
effects: activities.map((activity) => (activity as any)
|
|
259
|
+
effects: activities.map((activity) => (activity as any)) as any
|
|
260
260
|
}) as any
|
|
261
261
|
|
|
262
262
|
// -----------------------------------------------------------------------------
|