@effect/platform 0.58.27 → 0.59.1
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/cjs/Error.js +1 -25
- package/dist/cjs/Error.js.map +1 -1
- package/dist/cjs/HttpApp.js +4 -1
- package/dist/cjs/HttpApp.js.map +1 -1
- package/dist/cjs/HttpClientError.js +5 -6
- package/dist/cjs/HttpClientError.js.map +1 -1
- package/dist/cjs/HttpServerError.js +6 -5
- package/dist/cjs/HttpServerError.js.map +1 -1
- package/dist/cjs/HttpServerResponse.js.map +1 -1
- package/dist/cjs/Multipart.js.map +1 -1
- package/dist/cjs/Socket.js +11 -11
- package/dist/cjs/Socket.js.map +1 -1
- package/dist/cjs/Worker.js +10 -1
- package/dist/cjs/Worker.js.map +1 -1
- package/dist/cjs/WorkerError.js +13 -4
- package/dist/cjs/WorkerError.js.map +1 -1
- package/dist/cjs/WorkerRunner.js +6 -1
- package/dist/cjs/WorkerRunner.js.map +1 -1
- package/dist/cjs/internal/httpClient.js +7 -7
- package/dist/cjs/internal/httpClient.js.map +1 -1
- package/dist/cjs/internal/httpClientResponse.js +13 -13
- package/dist/cjs/internal/httpClientResponse.js.map +1 -1
- package/dist/cjs/internal/httpServerRequest.js +16 -16
- package/dist/cjs/internal/httpServerRequest.js.map +1 -1
- package/dist/cjs/internal/httpServerResponse.js +4 -3
- package/dist/cjs/internal/httpServerResponse.js.map +1 -1
- package/dist/cjs/internal/multipart.js +16 -16
- package/dist/cjs/internal/multipart.js.map +1 -1
- package/dist/cjs/internal/path.js +461 -11
- package/dist/cjs/internal/path.js.map +1 -1
- package/dist/cjs/internal/worker.js +126 -59
- package/dist/cjs/internal/worker.js.map +1 -1
- package/dist/cjs/internal/workerRunner.js +39 -65
- package/dist/cjs/internal/workerRunner.js.map +1 -1
- package/dist/dts/Error.d.ts +0 -10
- package/dist/dts/Error.d.ts.map +1 -1
- package/dist/dts/HttpApp.d.ts +1 -1
- package/dist/dts/HttpApp.d.ts.map +1 -1
- package/dist/dts/HttpClientError.d.ts +6 -8
- package/dist/dts/HttpClientError.d.ts.map +1 -1
- package/dist/dts/HttpServerError.d.ts +10 -13
- package/dist/dts/HttpServerError.d.ts.map +1 -1
- package/dist/dts/HttpServerResponse.d.ts +5 -1
- package/dist/dts/HttpServerResponse.d.ts.map +1 -1
- package/dist/dts/Multipart.d.ts +3 -2
- package/dist/dts/Multipart.d.ts.map +1 -1
- package/dist/dts/Socket.d.ts +2 -4
- package/dist/dts/Socket.d.ts.map +1 -1
- package/dist/dts/Worker.d.ts +27 -27
- package/dist/dts/Worker.d.ts.map +1 -1
- package/dist/dts/WorkerError.d.ts +2 -2
- package/dist/dts/WorkerError.d.ts.map +1 -1
- package/dist/dts/WorkerRunner.d.ts +8 -5
- package/dist/dts/WorkerRunner.d.ts.map +1 -1
- package/dist/esm/Error.js +0 -23
- package/dist/esm/Error.js.map +1 -1
- package/dist/esm/HttpApp.js +4 -1
- package/dist/esm/HttpApp.js.map +1 -1
- package/dist/esm/HttpClientError.js +5 -6
- package/dist/esm/HttpClientError.js.map +1 -1
- package/dist/esm/HttpServerError.js +7 -6
- package/dist/esm/HttpServerError.js.map +1 -1
- package/dist/esm/HttpServerResponse.js.map +1 -1
- package/dist/esm/Multipart.js.map +1 -1
- package/dist/esm/Socket.js +12 -12
- package/dist/esm/Socket.js.map +1 -1
- package/dist/esm/Worker.js +9 -0
- package/dist/esm/Worker.js.map +1 -1
- package/dist/esm/WorkerError.js +13 -4
- package/dist/esm/WorkerError.js.map +1 -1
- package/dist/esm/WorkerRunner.js +5 -0
- package/dist/esm/WorkerRunner.js.map +1 -1
- package/dist/esm/internal/httpClient.js +7 -7
- package/dist/esm/internal/httpClient.js.map +1 -1
- package/dist/esm/internal/httpClientResponse.js +13 -13
- package/dist/esm/internal/httpClientResponse.js.map +1 -1
- package/dist/esm/internal/httpServerRequest.js +16 -16
- package/dist/esm/internal/httpServerRequest.js.map +1 -1
- package/dist/esm/internal/httpServerResponse.js +4 -3
- package/dist/esm/internal/httpServerResponse.js.map +1 -1
- package/dist/esm/internal/multipart.js +17 -17
- package/dist/esm/internal/multipart.js.map +1 -1
- package/dist/esm/internal/path.js +461 -10
- package/dist/esm/internal/path.js.map +1 -1
- package/dist/esm/internal/worker.js +124 -57
- package/dist/esm/internal/worker.js.map +1 -1
- package/dist/esm/internal/workerRunner.js +38 -65
- package/dist/esm/internal/workerRunner.js.map +1 -1
- package/package.json +5 -6
- package/src/Error.ts +0 -38
- package/src/HttpApp.ts +2 -2
- package/src/HttpClientError.ts +13 -6
- package/src/HttpServerError.ts +17 -6
- package/src/HttpServerResponse.ts +8 -1
- package/src/Multipart.ts +3 -2
- package/src/Socket.ts +10 -9
- package/src/Worker.ts +32 -29
- package/src/WorkerError.ts +15 -8
- package/src/WorkerRunner.ts +15 -8
- package/src/internal/httpClient.ts +7 -7
- package/src/internal/httpClientResponse.ts +13 -13
- package/src/internal/httpServerRequest.ts +15 -15
- package/src/internal/httpServerResponse.ts +7 -3
- package/src/internal/multipart.ts +16 -15
- package/src/internal/path.ts +510 -14
- package/src/internal/worker.ts +193 -146
- package/src/internal/workerRunner.ts +106 -139
package/src/Error.ts
CHANGED
|
@@ -54,44 +54,6 @@ export const TypeIdError = <const TypeId extends symbol, const Tag extends strin
|
|
|
54
54
|
return Base as any
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
/**
|
|
58
|
-
* @since 1.0.0
|
|
59
|
-
* @category error
|
|
60
|
-
*/
|
|
61
|
-
export const RefailError = <const TypeId extends symbol, const Tag extends string>(
|
|
62
|
-
typeId: TypeId,
|
|
63
|
-
tag: Tag
|
|
64
|
-
): new<A extends Record<string, any>>(
|
|
65
|
-
args: Simplify<A & { readonly error: unknown }>
|
|
66
|
-
) =>
|
|
67
|
-
& Cause.YieldableError
|
|
68
|
-
& Record<TypeId, TypeId>
|
|
69
|
-
& { readonly _tag: Tag; readonly error: unknown }
|
|
70
|
-
& Readonly<A> =>
|
|
71
|
-
{
|
|
72
|
-
class Base extends Data.Error<{
|
|
73
|
-
readonly error: unknown
|
|
74
|
-
}> {
|
|
75
|
-
readonly _tag = tag
|
|
76
|
-
constructor(props: any) {
|
|
77
|
-
super(props)
|
|
78
|
-
if (Predicate.hasProperty(this.error, "stack")) {
|
|
79
|
-
;(this as any).stack = this.error.stack
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
get message() {
|
|
83
|
-
return Predicate.hasProperty(this.error, "message")
|
|
84
|
-
? this.error.message as string
|
|
85
|
-
: Predicate.hasProperty(this.error, "toJSON") && typeof this.error.toJSON === "function"
|
|
86
|
-
? JSON.stringify(this.error.toJSON())
|
|
87
|
-
: String(this.error)
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
;(Base.prototype as any)[typeId] = typeId
|
|
91
|
-
;(Base.prototype as any).name = tag
|
|
92
|
-
return Base as any
|
|
93
|
-
}
|
|
94
|
-
|
|
95
57
|
/**
|
|
96
58
|
* @since 1.0.0
|
|
97
59
|
*/
|
package/src/HttpApp.ts
CHANGED
|
@@ -138,12 +138,12 @@ export const withPreResponseHandler = dual<
|
|
|
138
138
|
*/
|
|
139
139
|
export const toWebHandlerRuntime = <R>(runtime: Runtime.Runtime<R>) => {
|
|
140
140
|
const run = Runtime.runFork(runtime)
|
|
141
|
-
return <E>(self: Default<E, R | Scope.Scope>, middleware
|
|
141
|
+
return <E>(self: Default<E, R | Scope.Scope>, middleware?: HttpMiddleware | undefined) =>
|
|
142
142
|
(request: Request): Promise<Response> =>
|
|
143
143
|
new Promise((resolve) => {
|
|
144
144
|
const fiber = run(Effect.provideService(
|
|
145
145
|
toHandled(self, (request, response) => {
|
|
146
|
-
resolve(ServerResponse.toWeb(response, request.method === "HEAD"))
|
|
146
|
+
resolve(ServerResponse.toWeb(response, { withoutBody: request.method === "HEAD", runtime }))
|
|
147
147
|
return Effect.void
|
|
148
148
|
}, middleware),
|
|
149
149
|
ServerRequest.HttpServerRequest,
|
package/src/HttpClientError.ts
CHANGED
|
@@ -28,17 +28,20 @@ export type HttpClientError = RequestError | ResponseError
|
|
|
28
28
|
* @since 1.0.0
|
|
29
29
|
* @category error
|
|
30
30
|
*/
|
|
31
|
-
export class RequestError extends Error.
|
|
31
|
+
export class RequestError extends Error.TypeIdError(TypeId, "RequestError")<{
|
|
32
32
|
readonly request: ClientRequest.HttpClientRequest
|
|
33
33
|
readonly reason: "Transport" | "Encode" | "InvalidUrl"
|
|
34
|
+
readonly cause?: unknown
|
|
35
|
+
readonly description?: string
|
|
34
36
|
}> {
|
|
35
37
|
get methodAndUrl() {
|
|
36
38
|
return `${this.request.method} ${this.request.url}`
|
|
37
39
|
}
|
|
38
40
|
|
|
39
41
|
get message() {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
+
return this.description ?
|
|
43
|
+
`${this.reason}: ${this.description} (${this.methodAndUrl})` :
|
|
44
|
+
`${this.reason} error (${this.methodAndUrl})`
|
|
42
45
|
}
|
|
43
46
|
}
|
|
44
47
|
|
|
@@ -46,17 +49,21 @@ export class RequestError extends Error.RefailError(TypeId, "RequestError")<{
|
|
|
46
49
|
* @since 1.0.0
|
|
47
50
|
* @category error
|
|
48
51
|
*/
|
|
49
|
-
export class ResponseError extends Error.
|
|
52
|
+
export class ResponseError extends Error.TypeIdError(TypeId, "ResponseError")<{
|
|
50
53
|
readonly request: ClientRequest.HttpClientRequest
|
|
51
54
|
readonly response: ClientResponse.HttpClientResponse
|
|
52
55
|
readonly reason: "StatusCode" | "Decode" | "EmptyBody"
|
|
56
|
+
readonly cause?: unknown
|
|
57
|
+
readonly description?: string
|
|
53
58
|
}> {
|
|
54
59
|
get methodAndUrl() {
|
|
55
60
|
return `${this.request.method} ${this.request.url}`
|
|
56
61
|
}
|
|
57
62
|
|
|
58
63
|
get message() {
|
|
59
|
-
const
|
|
60
|
-
return
|
|
64
|
+
const info = `${this.response.status} ${this.methodAndUrl}`
|
|
65
|
+
return this.description ?
|
|
66
|
+
`${this.reason}: ${this.description} (${info})` :
|
|
67
|
+
`${this.reason} error (${info})`
|
|
61
68
|
}
|
|
62
69
|
}
|
package/src/HttpServerError.ts
CHANGED
|
@@ -6,7 +6,7 @@ import type * as Effect from "effect/Effect"
|
|
|
6
6
|
import type * as Exit from "effect/Exit"
|
|
7
7
|
import type * as FiberId from "effect/FiberId"
|
|
8
8
|
import type * as Option from "effect/Option"
|
|
9
|
-
import {
|
|
9
|
+
import { TypeIdError } from "./Error.js"
|
|
10
10
|
import type * as ServerRequest from "./HttpServerRequest.js"
|
|
11
11
|
import * as Respondable from "./HttpServerRespondable.js"
|
|
12
12
|
import * as ServerResponse from "./HttpServerResponse.js"
|
|
@@ -34,9 +34,11 @@ export type HttpServerError = RequestError | ResponseError | RouteNotFound | Ser
|
|
|
34
34
|
* @since 1.0.0
|
|
35
35
|
* @category error
|
|
36
36
|
*/
|
|
37
|
-
export class RequestError extends
|
|
37
|
+
export class RequestError extends TypeIdError(TypeId, "RequestError")<{
|
|
38
38
|
readonly request: ServerRequest.HttpServerRequest
|
|
39
39
|
readonly reason: "Transport" | "Decode"
|
|
40
|
+
readonly cause?: unknown
|
|
41
|
+
readonly description?: string
|
|
40
42
|
}> implements Respondable.Respondable {
|
|
41
43
|
/**
|
|
42
44
|
* @since 1.0.0
|
|
@@ -50,7 +52,9 @@ export class RequestError extends RefailError(TypeId, "RequestError")<{
|
|
|
50
52
|
}
|
|
51
53
|
|
|
52
54
|
get message() {
|
|
53
|
-
return
|
|
55
|
+
return this.description ?
|
|
56
|
+
`${this.reason}: ${this.description} (${this.methodAndUrl})` :
|
|
57
|
+
`${this.reason} error (${this.methodAndUrl})`
|
|
54
58
|
}
|
|
55
59
|
}
|
|
56
60
|
|
|
@@ -86,10 +90,12 @@ export class RouteNotFound extends TypeIdError(TypeId, "RouteNotFound")<{
|
|
|
86
90
|
* @since 1.0.0
|
|
87
91
|
* @category error
|
|
88
92
|
*/
|
|
89
|
-
export class ResponseError extends
|
|
93
|
+
export class ResponseError extends TypeIdError(TypeId, "ResponseError")<{
|
|
90
94
|
readonly request: ServerRequest.HttpServerRequest
|
|
91
95
|
readonly response: ServerResponse.HttpServerResponse
|
|
92
96
|
readonly reason: "Decode"
|
|
97
|
+
readonly cause?: unknown
|
|
98
|
+
readonly description?: string
|
|
93
99
|
}> {
|
|
94
100
|
/**
|
|
95
101
|
* @since 1.0.0
|
|
@@ -103,7 +109,10 @@ export class ResponseError extends RefailError(TypeId, "ResponseError")<{
|
|
|
103
109
|
}
|
|
104
110
|
|
|
105
111
|
get message() {
|
|
106
|
-
|
|
112
|
+
const info = `${this.response.status} ${this.methodAndUrl}`
|
|
113
|
+
return this.description ?
|
|
114
|
+
`${this.description} (${info})` :
|
|
115
|
+
`${this.reason} error (${info})`
|
|
107
116
|
}
|
|
108
117
|
}
|
|
109
118
|
|
|
@@ -111,7 +120,9 @@ export class ResponseError extends RefailError(TypeId, "ResponseError")<{
|
|
|
111
120
|
* @since 1.0.0
|
|
112
121
|
* @category error
|
|
113
122
|
*/
|
|
114
|
-
export class ServeError extends
|
|
123
|
+
export class ServeError extends TypeIdError(TypeId, "ServeError")<{
|
|
124
|
+
readonly cause: unknown
|
|
125
|
+
}> {}
|
|
115
126
|
|
|
116
127
|
/**
|
|
117
128
|
* @since 1.0.0
|
|
@@ -5,6 +5,7 @@ import type { ParseOptions } from "@effect/schema/AST"
|
|
|
5
5
|
import type * as Schema from "@effect/schema/Schema"
|
|
6
6
|
import type * as Effect from "effect/Effect"
|
|
7
7
|
import type { Inspectable } from "effect/Inspectable"
|
|
8
|
+
import type * as Runtime from "effect/Runtime"
|
|
8
9
|
import type * as Stream from "effect/Stream"
|
|
9
10
|
import type { Cookie, Cookies, CookiesError } from "./Cookies.js"
|
|
10
11
|
import type * as PlatformError from "./Error.js"
|
|
@@ -353,4 +354,10 @@ export const setStatus: {
|
|
|
353
354
|
* @since 1.0.0
|
|
354
355
|
* @category conversions
|
|
355
356
|
*/
|
|
356
|
-
export const toWeb: (
|
|
357
|
+
export const toWeb: (
|
|
358
|
+
response: HttpServerResponse,
|
|
359
|
+
options?: {
|
|
360
|
+
readonly withoutBody?: boolean | undefined
|
|
361
|
+
readonly runtime?: Runtime.Runtime<never> | undefined
|
|
362
|
+
}
|
|
363
|
+
) => Response = internal.toWeb
|
package/src/Multipart.ts
CHANGED
|
@@ -137,7 +137,8 @@ export interface MultipartError extends YieldableError {
|
|
|
137
137
|
readonly [ErrorTypeId]: ErrorTypeId
|
|
138
138
|
readonly _tag: "MultipartError"
|
|
139
139
|
readonly reason: "FileTooLarge" | "FieldTooLarge" | "BodyTooLarge" | "TooManyParts" | "InternalError" | "Parse"
|
|
140
|
-
readonly
|
|
140
|
+
readonly message: string
|
|
141
|
+
readonly cause: unknown
|
|
141
142
|
}
|
|
142
143
|
|
|
143
144
|
/**
|
|
@@ -147,7 +148,7 @@ export interface MultipartError extends YieldableError {
|
|
|
147
148
|
export const MultipartError: new(
|
|
148
149
|
options: {
|
|
149
150
|
readonly reason: MultipartError["reason"]
|
|
150
|
-
readonly
|
|
151
|
+
readonly cause: unknown
|
|
151
152
|
}
|
|
152
153
|
) => MultipartError = internal.MultipartError
|
|
153
154
|
|
package/src/Socket.ts
CHANGED
|
@@ -18,7 +18,7 @@ import * as Predicate from "effect/Predicate"
|
|
|
18
18
|
import * as Queue from "effect/Queue"
|
|
19
19
|
import * as Scope from "effect/Scope"
|
|
20
20
|
import type * as AsyncProducer from "effect/SingleProducerAsyncInput"
|
|
21
|
-
import {
|
|
21
|
+
import { TypeIdError } from "./Error.js"
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
24
|
* @since 1.0.0
|
|
@@ -125,11 +125,12 @@ export type SocketError = SocketGenericError | SocketCloseError
|
|
|
125
125
|
* @since 1.0.0
|
|
126
126
|
* @category errors
|
|
127
127
|
*/
|
|
128
|
-
export class SocketGenericError extends
|
|
128
|
+
export class SocketGenericError extends TypeIdError(SocketErrorTypeId, "SocketError")<{
|
|
129
129
|
readonly reason: "Write" | "Read" | "Open" | "OpenTimeout"
|
|
130
|
+
readonly cause: unknown
|
|
130
131
|
}> {
|
|
131
132
|
get message() {
|
|
132
|
-
return
|
|
133
|
+
return `An error occurred during ${this.reason}`
|
|
133
134
|
}
|
|
134
135
|
}
|
|
135
136
|
|
|
@@ -383,10 +384,10 @@ export const fromWebSocket = <R>(
|
|
|
383
384
|
)
|
|
384
385
|
)
|
|
385
386
|
}
|
|
386
|
-
ws.onerror = (
|
|
387
|
+
ws.onerror = (cause) => {
|
|
387
388
|
Deferred.unsafeDone(
|
|
388
389
|
fiberSet.deferred,
|
|
389
|
-
Effect.fail(new SocketGenericError({ reason: open ? "Read" : "Open",
|
|
390
|
+
Effect.fail(new SocketGenericError({ reason: open ? "Read" : "Open", cause }))
|
|
390
391
|
)
|
|
391
392
|
}
|
|
392
393
|
|
|
@@ -407,7 +408,7 @@ export const fromWebSocket = <R>(
|
|
|
407
408
|
Effect.timeoutFail({
|
|
408
409
|
duration: options?.openTimeout ?? 10000,
|
|
409
410
|
onTimeout: () =>
|
|
410
|
-
new SocketGenericError({ reason: "OpenTimeout",
|
|
411
|
+
new SocketGenericError({ reason: "OpenTimeout", cause: "timeout waiting for \"open\"" })
|
|
411
412
|
}),
|
|
412
413
|
Effect.raceFirst(FiberSet.join(fiberSet))
|
|
413
414
|
)
|
|
@@ -430,7 +431,7 @@ export const fromWebSocket = <R>(
|
|
|
430
431
|
Effect.try({
|
|
431
432
|
try: () =>
|
|
432
433
|
ws.send(chunk),
|
|
433
|
-
catch: (
|
|
434
|
+
catch: (cause) => new SocketGenericError({ reason: "Write", cause })
|
|
434
435
|
})
|
|
435
436
|
),
|
|
436
437
|
Effect.forever,
|
|
@@ -585,7 +586,7 @@ export const fromTransformStream = <R>(acquire: Effect.Effect<InputTransformStre
|
|
|
585
586
|
writer.write(chunk)
|
|
586
587
|
}
|
|
587
588
|
},
|
|
588
|
-
catch: (
|
|
589
|
+
catch: (cause) => new SocketGenericError({ reason: "Write", cause })
|
|
589
590
|
})
|
|
590
591
|
}),
|
|
591
592
|
Effect.forever,
|
|
@@ -595,7 +596,7 @@ export const fromTransformStream = <R>(acquire: Effect.Effect<InputTransformStre
|
|
|
595
596
|
Effect.tap(({ fiberSet, reader }) =>
|
|
596
597
|
Effect.tryPromise({
|
|
597
598
|
try: () => reader.read(),
|
|
598
|
-
catch: (
|
|
599
|
+
catch: (cause) => new SocketGenericError({ reason: "Read", cause })
|
|
599
600
|
}).pipe(
|
|
600
601
|
Effect.tap((result) => {
|
|
601
602
|
if (result.done) {
|
package/src/Worker.ts
CHANGED
|
@@ -5,17 +5,14 @@ import type * as ParseResult from "@effect/schema/ParseResult"
|
|
|
5
5
|
import type * as Schema from "@effect/schema/Schema"
|
|
6
6
|
import type * as Serializable from "@effect/schema/Serializable"
|
|
7
7
|
import type * as Context from "effect/Context"
|
|
8
|
+
import type * as Deferred from "effect/Deferred"
|
|
8
9
|
import type * as Duration from "effect/Duration"
|
|
9
10
|
import type * as Effect from "effect/Effect"
|
|
10
|
-
import type * as Fiber from "effect/Fiber"
|
|
11
11
|
import type { LazyArg } from "effect/Function"
|
|
12
12
|
import type * as Layer from "effect/Layer"
|
|
13
|
-
import type * as Option from "effect/Option"
|
|
14
13
|
import type * as Pool from "effect/Pool"
|
|
15
|
-
import type * as Queue from "effect/Queue"
|
|
16
14
|
import type * as Scope from "effect/Scope"
|
|
17
15
|
import type * as Stream from "effect/Stream"
|
|
18
|
-
import type * as Tracer from "effect/Tracer"
|
|
19
16
|
import * as internal from "./internal/worker.js"
|
|
20
17
|
import type { WorkerError, WorkerErrorFrom } from "./WorkerError.js"
|
|
21
18
|
|
|
@@ -24,9 +21,10 @@ import type { WorkerError, WorkerErrorFrom } from "./WorkerError.js"
|
|
|
24
21
|
* @category models
|
|
25
22
|
*/
|
|
26
23
|
export interface BackingWorker<I, O> {
|
|
27
|
-
readonly fiber: Fiber.Fiber<never, WorkerError>
|
|
28
24
|
readonly send: (message: I, transfers?: ReadonlyArray<unknown>) => Effect.Effect<void, WorkerError>
|
|
29
|
-
readonly
|
|
25
|
+
readonly run: <A, E, R>(
|
|
26
|
+
handler: (_: BackingWorker.Message<O>) => Effect.Effect<A, E, R>
|
|
27
|
+
) => Effect.Effect<never, E | WorkerError, R>
|
|
30
28
|
}
|
|
31
29
|
|
|
32
30
|
/**
|
|
@@ -59,9 +57,28 @@ export type PlatformWorkerTypeId = typeof PlatformWorkerTypeId
|
|
|
59
57
|
*/
|
|
60
58
|
export interface PlatformWorker {
|
|
61
59
|
readonly [PlatformWorkerTypeId]: PlatformWorkerTypeId
|
|
62
|
-
readonly spawn: <I, O>(
|
|
60
|
+
readonly spawn: <I, O>(id: number) => Effect.Effect<BackingWorker<I, O>, WorkerError, Spawner>
|
|
63
61
|
}
|
|
64
62
|
|
|
63
|
+
/**
|
|
64
|
+
* @since 1.0.0
|
|
65
|
+
*/
|
|
66
|
+
export const makePlatform: <W>() => <
|
|
67
|
+
P extends { readonly postMessage: (message: any, transfers?: any | undefined) => void }
|
|
68
|
+
>(
|
|
69
|
+
options: {
|
|
70
|
+
readonly setup: (options: { readonly worker: W; readonly scope: Scope.Scope }) => Effect.Effect<P>
|
|
71
|
+
readonly listen: (
|
|
72
|
+
options: {
|
|
73
|
+
readonly port: P
|
|
74
|
+
readonly emit: (data: any) => void
|
|
75
|
+
readonly deferred: Deferred.Deferred<never, WorkerError>
|
|
76
|
+
readonly scope: Scope.Scope
|
|
77
|
+
}
|
|
78
|
+
) => Effect.Effect<void>
|
|
79
|
+
}
|
|
80
|
+
) => PlatformWorker = internal.makePlatform
|
|
81
|
+
|
|
65
82
|
/**
|
|
66
83
|
* @since 1.0.0
|
|
67
84
|
* @category tags
|
|
@@ -86,6 +103,12 @@ export interface Spawner {
|
|
|
86
103
|
readonly _: unique symbol
|
|
87
104
|
}
|
|
88
105
|
|
|
106
|
+
/**
|
|
107
|
+
* @since 1.0.0
|
|
108
|
+
* @category tags
|
|
109
|
+
*/
|
|
110
|
+
export const Spawner: Context.Tag<Spawner, SpawnerFn<unknown>> = internal.Spawner
|
|
111
|
+
|
|
89
112
|
/**
|
|
90
113
|
* @since 1.0.0
|
|
91
114
|
* @category models
|
|
@@ -105,8 +128,6 @@ export declare namespace Worker {
|
|
|
105
128
|
*/
|
|
106
129
|
export interface Options<I> {
|
|
107
130
|
readonly encode?: ((message: I) => Effect.Effect<unknown, WorkerError>) | undefined
|
|
108
|
-
readonly transfers?: ((message: I) => ReadonlyArray<unknown>) | undefined
|
|
109
|
-
readonly queue?: WorkerQueue<I> | undefined
|
|
110
131
|
readonly initialMessage?: LazyArg<I> | undefined
|
|
111
132
|
}
|
|
112
133
|
|
|
@@ -173,16 +194,6 @@ export declare namespace WorkerPool {
|
|
|
173
194
|
})
|
|
174
195
|
}
|
|
175
196
|
|
|
176
|
-
/**
|
|
177
|
-
* @category models
|
|
178
|
-
* @since 1.0.0
|
|
179
|
-
*/
|
|
180
|
-
export interface WorkerQueue<I> {
|
|
181
|
-
readonly offer: (id: number, item: I, span: Option.Option<Tracer.Span>) => Effect.Effect<void>
|
|
182
|
-
readonly take: Effect.Effect<readonly [id: number, item: I, span: Option.Option<Tracer.Span>]>
|
|
183
|
-
readonly shutdown: Effect.Effect<void>
|
|
184
|
-
}
|
|
185
|
-
|
|
186
197
|
/**
|
|
187
198
|
* @since 1.0.0
|
|
188
199
|
* @category type ids
|
|
@@ -268,20 +279,12 @@ export declare namespace SerializedWorker {
|
|
|
268
279
|
* @since 1.0.0
|
|
269
280
|
* @category models
|
|
270
281
|
*/
|
|
271
|
-
export type Options<I> = Extract<I, { readonly _tag: "InitialMessage" }> extends never ?
|
|
282
|
+
export type Options<I> = Extract<I, { readonly _tag: "InitialMessage" }> extends never ? {
|
|
272
283
|
readonly initialMessage?: LazyArg<I>
|
|
273
284
|
}
|
|
274
|
-
:
|
|
285
|
+
: {
|
|
275
286
|
readonly initialMessage: LazyArg<Extract<I, { readonly _tag: "InitialMessage" }>>
|
|
276
287
|
}
|
|
277
|
-
|
|
278
|
-
/**
|
|
279
|
-
* @since 1.0.0
|
|
280
|
-
* @category models
|
|
281
|
-
*/
|
|
282
|
-
export interface BaseOptions<I> {
|
|
283
|
-
readonly queue?: WorkerQueue<I> | undefined
|
|
284
|
-
}
|
|
285
288
|
}
|
|
286
289
|
|
|
287
290
|
/**
|
package/src/WorkerError.ts
CHANGED
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import * as Schema from "@effect/schema/Schema"
|
|
5
5
|
import type * as Cause from "effect/Cause"
|
|
6
|
-
import * as Inspectable from "effect/Inspectable"
|
|
7
6
|
import * as Predicate from "effect/Predicate"
|
|
8
7
|
import * as internal from "./internal/workerError.js"
|
|
9
8
|
|
|
@@ -31,7 +30,7 @@ export const isWorkerError = (u: unknown): u is WorkerError => Predicate.hasProp
|
|
|
31
30
|
*/
|
|
32
31
|
export class WorkerError extends Schema.TaggedError<WorkerError>()("WorkerError", {
|
|
33
32
|
reason: Schema.Literal("spawn", "decode", "send", "unknown", "encode"),
|
|
34
|
-
|
|
33
|
+
cause: Schema.CauseDefectUnknown
|
|
35
34
|
}) {
|
|
36
35
|
/**
|
|
37
36
|
* @since 1.0.0
|
|
@@ -61,11 +60,19 @@ export class WorkerError extends Schema.TaggedError<WorkerError>()("WorkerError"
|
|
|
61
60
|
/**
|
|
62
61
|
* @since 1.0.0
|
|
63
62
|
*/
|
|
64
|
-
get message() {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
63
|
+
get message(): string {
|
|
64
|
+
switch (this.reason) {
|
|
65
|
+
case "send":
|
|
66
|
+
return "An error occurred calling .postMessage"
|
|
67
|
+
case "spawn":
|
|
68
|
+
return "An error occurred while spawning a worker"
|
|
69
|
+
case "decode":
|
|
70
|
+
return "An error occurred during decoding"
|
|
71
|
+
case "encode":
|
|
72
|
+
return "An error occurred during encoding"
|
|
73
|
+
case "unknown":
|
|
74
|
+
return "An unexpected error occurred"
|
|
75
|
+
}
|
|
69
76
|
}
|
|
70
77
|
}
|
|
71
78
|
|
|
@@ -76,5 +83,5 @@ export class WorkerError extends Schema.TaggedError<WorkerError>()("WorkerError"
|
|
|
76
83
|
export interface WorkerErrorFrom {
|
|
77
84
|
readonly _tag: "WorkerError"
|
|
78
85
|
readonly reason: "spawn" | "decode" | "send" | "unknown" | "encode"
|
|
79
|
-
readonly
|
|
86
|
+
readonly cause: unknown
|
|
80
87
|
}
|
package/src/WorkerRunner.ts
CHANGED
|
@@ -6,7 +6,6 @@ import type * as Serializable from "@effect/schema/Serializable"
|
|
|
6
6
|
import type * as Context from "effect/Context"
|
|
7
7
|
import type * as Effect from "effect/Effect"
|
|
8
8
|
import type * as Layer from "effect/Layer"
|
|
9
|
-
import type * as Queue from "effect/Queue"
|
|
10
9
|
import type * as Scope from "effect/Scope"
|
|
11
10
|
import type * as Stream from "effect/Stream"
|
|
12
11
|
import * as internal from "./internal/workerRunner.js"
|
|
@@ -17,7 +16,9 @@ import type { WorkerError } from "./WorkerError.js"
|
|
|
17
16
|
* @category models
|
|
18
17
|
*/
|
|
19
18
|
export interface BackingRunner<I, O> {
|
|
20
|
-
readonly
|
|
19
|
+
readonly run: <A, E, R>(
|
|
20
|
+
handler: (portId: number, message: I) => Effect.Effect<A, E, R>
|
|
21
|
+
) => Effect.Effect<never, E | WorkerError, R>
|
|
21
22
|
readonly send: (
|
|
22
23
|
portId: number,
|
|
23
24
|
message: O,
|
|
@@ -55,9 +56,7 @@ export type PlatformRunnerTypeId = typeof PlatformRunnerTypeId
|
|
|
55
56
|
*/
|
|
56
57
|
export interface PlatformRunner {
|
|
57
58
|
readonly [PlatformRunnerTypeId]: PlatformRunnerTypeId
|
|
58
|
-
readonly start: <I, O>(
|
|
59
|
-
shutdown: Effect.Effect<void>
|
|
60
|
-
) => Effect.Effect<BackingRunner<I, O>, WorkerError, Scope.Scope>
|
|
59
|
+
readonly start: <I, O>() => Effect.Effect<BackingRunner<I, O>, WorkerError>
|
|
61
60
|
}
|
|
62
61
|
|
|
63
62
|
/**
|
|
@@ -87,18 +86,26 @@ export declare namespace Runner {
|
|
|
87
86
|
request: I,
|
|
88
87
|
error: E
|
|
89
88
|
) => Effect.Effect<unknown, WorkerError>
|
|
90
|
-
readonly transfers?: (message: O | E) => ReadonlyArray<unknown>
|
|
91
89
|
}
|
|
92
90
|
}
|
|
93
91
|
|
|
92
|
+
/**
|
|
93
|
+
* @since 1.0.0
|
|
94
|
+
* @category constructors
|
|
95
|
+
*/
|
|
96
|
+
export const run: <I, E, R, O>(
|
|
97
|
+
process: (request: I) => Stream.Stream<O, E, R> | Effect.Effect<O, E, R>,
|
|
98
|
+
options?: Runner.Options<I, O, E>
|
|
99
|
+
) => Effect.Effect<never, WorkerError, PlatformRunner | R> = internal.run
|
|
100
|
+
|
|
94
101
|
/**
|
|
95
102
|
* @since 1.0.0
|
|
96
103
|
* @category constructors
|
|
97
104
|
*/
|
|
98
105
|
export const make: <I, E, R, O>(
|
|
99
106
|
process: (request: I) => Stream.Stream<O, E, R> | Effect.Effect<O, E, R>,
|
|
100
|
-
options?: Runner.Options<I, O, E>
|
|
101
|
-
) => Effect.Effect<void, WorkerError,
|
|
107
|
+
options?: Runner.Options<I, O, E>
|
|
108
|
+
) => Effect.Effect<void, WorkerError, PlatformRunner | R | Scope.Scope> = internal.make
|
|
102
109
|
|
|
103
110
|
/**
|
|
104
111
|
* @since 1.0.0
|
|
@@ -128,7 +128,7 @@ export const makeDefault = (
|
|
|
128
128
|
const addAbort = Scope.addFinalizer(scope, Effect.sync(() => controller.abort()))
|
|
129
129
|
const urlResult = UrlParams.makeUrl(request.url, request.urlParams, request.hash)
|
|
130
130
|
if (urlResult._tag === "Left") {
|
|
131
|
-
return Effect.fail(new Error.RequestError({ request, reason: "InvalidUrl",
|
|
131
|
+
return Effect.fail(new Error.RequestError({ request, reason: "InvalidUrl", cause: urlResult.left }))
|
|
132
132
|
}
|
|
133
133
|
const url = urlResult.right
|
|
134
134
|
const tracerDisabled = !fiber.getFiberRef(FiberRef.currentTracerEnabled) ||
|
|
@@ -211,11 +211,11 @@ export const fetch: Client.HttpClient.Default = makeDefault((request, url, signa
|
|
|
211
211
|
duplex: request.body._tag === "Stream" ? "half" : undefined,
|
|
212
212
|
signal
|
|
213
213
|
} as any),
|
|
214
|
-
catch: (
|
|
214
|
+
catch: (cause) =>
|
|
215
215
|
new Error.RequestError({
|
|
216
216
|
request,
|
|
217
217
|
reason: "Transport",
|
|
218
|
-
|
|
218
|
+
cause
|
|
219
219
|
})
|
|
220
220
|
}),
|
|
221
221
|
(response) => internalResponse.fromWeb(request, response)
|
|
@@ -276,7 +276,7 @@ export const filterStatus = dual<
|
|
|
276
276
|
request,
|
|
277
277
|
response,
|
|
278
278
|
reason: "StatusCode",
|
|
279
|
-
|
|
279
|
+
description: "invalid status code"
|
|
280
280
|
})
|
|
281
281
|
)))
|
|
282
282
|
|
|
@@ -293,7 +293,7 @@ export const filterStatusOk = <E, R>(
|
|
|
293
293
|
request,
|
|
294
294
|
response,
|
|
295
295
|
reason: "StatusCode",
|
|
296
|
-
|
|
296
|
+
description: "non 2xx status code"
|
|
297
297
|
})
|
|
298
298
|
))
|
|
299
299
|
|
|
@@ -675,11 +675,11 @@ export const schemaFunction = dual<
|
|
|
675
675
|
Effect.flatMap(
|
|
676
676
|
Effect.tryMap(encode(a), {
|
|
677
677
|
try: (body) => new TextEncoder().encode(JSON.stringify(body)),
|
|
678
|
-
catch: (
|
|
678
|
+
catch: (cause) =>
|
|
679
679
|
new Error.RequestError({
|
|
680
680
|
request,
|
|
681
681
|
reason: "Encode",
|
|
682
|
-
|
|
682
|
+
cause
|
|
683
683
|
})
|
|
684
684
|
}),
|
|
685
685
|
(body) =>
|
|
@@ -67,19 +67,19 @@ class ClientResponseImpl extends Inspectable.Class implements ClientResponse.Htt
|
|
|
67
67
|
|
|
68
68
|
get stream(): Stream.Stream<Uint8Array, Error.ResponseError> {
|
|
69
69
|
return this.source.body
|
|
70
|
-
? Stream.fromReadableStream(() => this.source.body!, (
|
|
70
|
+
? Stream.fromReadableStream(() => this.source.body!, (cause) =>
|
|
71
71
|
new Error.ResponseError({
|
|
72
72
|
request: this.request,
|
|
73
73
|
response: this,
|
|
74
74
|
reason: "Decode",
|
|
75
|
-
|
|
75
|
+
cause
|
|
76
76
|
}))
|
|
77
77
|
: Stream.fail(
|
|
78
78
|
new Error.ResponseError({
|
|
79
79
|
request: this.request,
|
|
80
80
|
response: this,
|
|
81
81
|
reason: "EmptyBody",
|
|
82
|
-
|
|
82
|
+
description: "can not create stream from empty body"
|
|
83
83
|
})
|
|
84
84
|
)
|
|
85
85
|
}
|
|
@@ -87,12 +87,12 @@ class ClientResponseImpl extends Inspectable.Class implements ClientResponse.Htt
|
|
|
87
87
|
get json(): Effect.Effect<unknown, Error.ResponseError> {
|
|
88
88
|
return Effect.tryMap(this.text, {
|
|
89
89
|
try: (text) => text === "" ? null : JSON.parse(text) as unknown,
|
|
90
|
-
catch: (
|
|
90
|
+
catch: (cause) =>
|
|
91
91
|
new Error.ResponseError({
|
|
92
92
|
request: this.request,
|
|
93
93
|
response: this,
|
|
94
94
|
reason: "Decode",
|
|
95
|
-
|
|
95
|
+
cause
|
|
96
96
|
})
|
|
97
97
|
})
|
|
98
98
|
}
|
|
@@ -101,12 +101,12 @@ class ClientResponseImpl extends Inspectable.Class implements ClientResponse.Htt
|
|
|
101
101
|
get text(): Effect.Effect<string, Error.ResponseError> {
|
|
102
102
|
return this.textBody ??= Effect.tryPromise({
|
|
103
103
|
try: () => this.source.text(),
|
|
104
|
-
catch: (
|
|
104
|
+
catch: (cause) =>
|
|
105
105
|
new Error.ResponseError({
|
|
106
106
|
request: this.request,
|
|
107
107
|
response: this,
|
|
108
108
|
reason: "Decode",
|
|
109
|
-
|
|
109
|
+
cause
|
|
110
110
|
})
|
|
111
111
|
}).pipe(Effect.cached, Effect.runSync)
|
|
112
112
|
}
|
|
@@ -115,12 +115,12 @@ class ClientResponseImpl extends Inspectable.Class implements ClientResponse.Htt
|
|
|
115
115
|
return Effect.flatMap(this.text, (_) =>
|
|
116
116
|
Effect.try({
|
|
117
117
|
try: () => UrlParams.fromInput(new URLSearchParams(_)),
|
|
118
|
-
catch: (
|
|
118
|
+
catch: (cause) =>
|
|
119
119
|
new Error.ResponseError({
|
|
120
120
|
request: this.request,
|
|
121
121
|
response: this,
|
|
122
122
|
reason: "Decode",
|
|
123
|
-
|
|
123
|
+
cause
|
|
124
124
|
})
|
|
125
125
|
}))
|
|
126
126
|
}
|
|
@@ -129,12 +129,12 @@ class ClientResponseImpl extends Inspectable.Class implements ClientResponse.Htt
|
|
|
129
129
|
get formData(): Effect.Effect<FormData, Error.ResponseError> {
|
|
130
130
|
return this.formDataBody ??= Effect.tryPromise({
|
|
131
131
|
try: () => this.source.formData(),
|
|
132
|
-
catch: (
|
|
132
|
+
catch: (cause) =>
|
|
133
133
|
new Error.ResponseError({
|
|
134
134
|
request: this.request,
|
|
135
135
|
response: this,
|
|
136
136
|
reason: "Decode",
|
|
137
|
-
|
|
137
|
+
cause
|
|
138
138
|
})
|
|
139
139
|
}).pipe(Effect.cached, Effect.runSync)
|
|
140
140
|
}
|
|
@@ -143,12 +143,12 @@ class ClientResponseImpl extends Inspectable.Class implements ClientResponse.Htt
|
|
|
143
143
|
get arrayBuffer(): Effect.Effect<ArrayBuffer, Error.ResponseError> {
|
|
144
144
|
return this.arrayBufferBody ??= Effect.tryPromise({
|
|
145
145
|
try: () => this.source.arrayBuffer(),
|
|
146
|
-
catch: (
|
|
146
|
+
catch: (cause) =>
|
|
147
147
|
new Error.ResponseError({
|
|
148
148
|
request: this.request,
|
|
149
149
|
response: this,
|
|
150
150
|
reason: "Decode",
|
|
151
|
-
|
|
151
|
+
cause
|
|
152
152
|
})
|
|
153
153
|
}).pipe(Effect.cached, Effect.runSync)
|
|
154
154
|
}
|