@effect/platform 0.44.7 → 0.45.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/Http/Client.js +11 -1
- package/dist/cjs/Http/Client.js.map +1 -1
- package/dist/cjs/Http/ClientResponse.js +60 -2
- package/dist/cjs/Http/ClientResponse.js.map +1 -1
- package/dist/cjs/Http/IncomingMessage.js +28 -1
- package/dist/cjs/Http/IncomingMessage.js.map +1 -1
- package/dist/cjs/WorkerError.js +41 -1
- package/dist/cjs/WorkerError.js.map +1 -1
- package/dist/cjs/internal/http/client.js +12 -7
- package/dist/cjs/internal/http/client.js.map +1 -1
- package/dist/cjs/internal/http/clientResponse.js +31 -1
- package/dist/cjs/internal/http/clientResponse.js.map +1 -1
- package/dist/cjs/internal/worker.js +9 -3
- package/dist/cjs/internal/worker.js.map +1 -1
- package/dist/cjs/internal/workerError.js +2 -37
- package/dist/cjs/internal/workerError.js.map +1 -1
- package/dist/cjs/internal/workerRunner.js +18 -9
- package/dist/cjs/internal/workerRunner.js.map +1 -1
- package/dist/dts/Http/Client.d.ts +18 -4
- package/dist/dts/Http/Client.d.ts.map +1 -1
- package/dist/dts/Http/ClientResponse.d.ts +66 -1
- package/dist/dts/Http/ClientResponse.d.ts.map +1 -1
- package/dist/dts/Http/IncomingMessage.d.ts +15 -0
- package/dist/dts/Http/IncomingMessage.d.ts.map +1 -1
- package/dist/dts/Worker.d.ts +2 -2
- package/dist/dts/Worker.d.ts.map +1 -1
- package/dist/dts/WorkerError.d.ts +43 -6
- package/dist/dts/WorkerError.d.ts.map +1 -1
- package/dist/esm/Http/Client.js +10 -0
- package/dist/esm/Http/Client.js.map +1 -1
- package/dist/esm/Http/ClientResponse.js +56 -1
- package/dist/esm/Http/ClientResponse.js.map +1 -1
- package/dist/esm/Http/IncomingMessage.js +24 -0
- package/dist/esm/Http/IncomingMessage.js.map +1 -1
- package/dist/esm/WorkerError.js +40 -1
- package/dist/esm/WorkerError.js.map +1 -1
- package/dist/esm/internal/http/client.js +11 -7
- package/dist/esm/internal/http/client.js.map +1 -1
- package/dist/esm/internal/http/clientResponse.js +22 -0
- package/dist/esm/internal/http/clientResponse.js.map +1 -1
- package/dist/esm/internal/worker.js +9 -3
- package/dist/esm/internal/worker.js.map +1 -1
- package/dist/esm/internal/workerError.js +1 -10
- package/dist/esm/internal/workerError.js.map +1 -1
- package/dist/esm/internal/workerRunner.js +18 -9
- package/dist/esm/internal/workerRunner.js.map +1 -1
- package/package.json +1 -1
- package/src/Http/Client.ts +37 -4
- package/src/Http/ClientResponse.ts +104 -1
- package/src/Http/IncomingMessage.ts +31 -0
- package/src/Worker.ts +2 -2
- package/src/WorkerError.ts +58 -11
- package/src/internal/http/client.ts +64 -39
- package/src/internal/http/clientResponse.ts +53 -0
- package/src/internal/worker.ts +6 -3
- package/src/internal/workerError.ts +1 -16
- package/src/internal/workerRunner.ts +14 -15
|
@@ -2,11 +2,12 @@ import type * as ParseResult from "@effect/schema/ParseResult"
|
|
|
2
2
|
import * as Schema from "@effect/schema/Schema"
|
|
3
3
|
import * as Context from "effect/Context"
|
|
4
4
|
import * as Effect from "effect/Effect"
|
|
5
|
-
import { dual } from "effect/Function"
|
|
5
|
+
import { dual, pipe } from "effect/Function"
|
|
6
6
|
import * as Layer from "effect/Layer"
|
|
7
7
|
import { pipeArguments } from "effect/Pipeable"
|
|
8
8
|
import type * as Predicate from "effect/Predicate"
|
|
9
9
|
import type * as Schedule from "effect/Schedule"
|
|
10
|
+
import type * as Scope from "effect/Scope"
|
|
10
11
|
import * as Stream from "effect/Stream"
|
|
11
12
|
import type * as Body from "../../Http/Body.js"
|
|
12
13
|
import type * as Client from "../../Http/Client.js"
|
|
@@ -68,7 +69,7 @@ const addB3Headers = (req: ClientRequest.ClientRequest) =>
|
|
|
68
69
|
export const makeDefault = (
|
|
69
70
|
f: (
|
|
70
71
|
request: ClientRequest.ClientRequest
|
|
71
|
-
) => Effect.Effect<ClientResponse.ClientResponse, Error.HttpClientError>
|
|
72
|
+
) => Effect.Effect<ClientResponse.ClientResponse, Error.HttpClientError, Scope.Scope>
|
|
72
73
|
): Client.Client.Default => make(Effect.flatMap(f), addB3Headers)
|
|
73
74
|
|
|
74
75
|
/** @internal */
|
|
@@ -91,25 +92,31 @@ export const fetch = (options?: RequestInit): Client.Client.Default =>
|
|
|
91
92
|
const fetch = fetch_._tag === "Some" ? fetch_.value : globalThis.fetch
|
|
92
93
|
const headers = new Headers(request.headers)
|
|
93
94
|
const send = (body: BodyInit | undefined) =>
|
|
94
|
-
|
|
95
|
-
Effect.
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
95
|
+
pipe(
|
|
96
|
+
Effect.acquireRelease(
|
|
97
|
+
Effect.sync(() => new AbortController()),
|
|
98
|
+
(controller) => Effect.sync(() => controller.abort())
|
|
99
|
+
),
|
|
100
|
+
Effect.flatMap((controller) =>
|
|
101
|
+
Effect.tryPromise({
|
|
102
|
+
try: () =>
|
|
103
|
+
fetch(url, {
|
|
104
|
+
...options,
|
|
105
|
+
method: request.method,
|
|
106
|
+
headers,
|
|
107
|
+
body,
|
|
108
|
+
duplex: request.body._tag === "Stream" ? "half" : undefined,
|
|
109
|
+
signal: controller.signal
|
|
110
|
+
} as any),
|
|
111
|
+
catch: (_) =>
|
|
112
|
+
internalError.requestError({
|
|
113
|
+
request,
|
|
114
|
+
reason: "Transport",
|
|
115
|
+
error: _
|
|
116
|
+
})
|
|
117
|
+
})
|
|
118
|
+
),
|
|
119
|
+
Effect.map((_) => internalResponse.fromWeb(request, _))
|
|
113
120
|
)
|
|
114
121
|
if (Method.hasBody(request.method)) {
|
|
115
122
|
return send(convertBody(request.body))
|
|
@@ -449,6 +456,22 @@ export const mapEffect = dual<
|
|
|
449
456
|
) => Client.Client<R | R2, E | E2, B>
|
|
450
457
|
>(2, (self, f) => transformResponse(self, Effect.flatMap(f)))
|
|
451
458
|
|
|
459
|
+
/** @internal */
|
|
460
|
+
export const scoped = <R, E, A>(
|
|
461
|
+
self: Client.Client<R, E, A>
|
|
462
|
+
): Client.Client<Exclude<R, Scope.Scope>, E, A> => transformResponse(self, Effect.scoped)
|
|
463
|
+
|
|
464
|
+
/** @internal */
|
|
465
|
+
export const mapEffectScoped = dual<
|
|
466
|
+
<A, R2, E2, B>(
|
|
467
|
+
f: (a: A) => Effect.Effect<B, E2, R2>
|
|
468
|
+
) => <R, E>(self: Client.Client<R, E, A>) => Client.Client<Exclude<R | R2, Scope.Scope>, E | E2, B>,
|
|
469
|
+
<R, E, A, R2, E2, B>(
|
|
470
|
+
self: Client.Client<R, E, A>,
|
|
471
|
+
f: (a: A) => Effect.Effect<B, E2, R2>
|
|
472
|
+
) => Client.Client<Exclude<R | R2, Scope.Scope>, E | E2, B>
|
|
473
|
+
>(2, (self, f) => scoped(mapEffect(self, f)))
|
|
474
|
+
|
|
452
475
|
/** @internal */
|
|
453
476
|
export const mapRequest = dual<
|
|
454
477
|
(
|
|
@@ -532,7 +555,7 @@ export const schemaFunction = dual<
|
|
|
532
555
|
request: ClientRequest.ClientRequest
|
|
533
556
|
) => (
|
|
534
557
|
a: SA
|
|
535
|
-
) => Effect.Effect<A, E | ParseResult.ParseError | Error.RequestError, SR | R
|
|
558
|
+
) => Effect.Effect<A, E | ParseResult.ParseError | Error.RequestError, Exclude<SR | R, Scope.Scope>>,
|
|
536
559
|
<R, E, A, SA, SI, SR>(
|
|
537
560
|
self: Client.Client<R, E, A>,
|
|
538
561
|
schema: Schema.Schema<SA, SI, SR>
|
|
@@ -540,27 +563,29 @@ export const schemaFunction = dual<
|
|
|
540
563
|
request: ClientRequest.ClientRequest
|
|
541
564
|
) => (
|
|
542
565
|
a: SA
|
|
543
|
-
) => Effect.Effect<A, E | ParseResult.ParseError | Error.RequestError, SR | R
|
|
566
|
+
) => Effect.Effect<A, E | ParseResult.ParseError | Error.RequestError, Exclude<SR | R, Scope.Scope>>
|
|
544
567
|
>(2, (self, schema) => {
|
|
545
568
|
const encode = Schema.encode(schema)
|
|
546
569
|
return (request) => (a) =>
|
|
547
|
-
Effect.
|
|
548
|
-
Effect.
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
570
|
+
Effect.scoped(
|
|
571
|
+
Effect.flatMap(
|
|
572
|
+
Effect.tryMap(encode(a), {
|
|
573
|
+
try: (body) => new TextEncoder().encode(JSON.stringify(body)),
|
|
574
|
+
catch: (error) =>
|
|
575
|
+
internalError.requestError({
|
|
576
|
+
request,
|
|
577
|
+
reason: "Encode",
|
|
578
|
+
error
|
|
579
|
+
})
|
|
580
|
+
}),
|
|
581
|
+
(body) =>
|
|
582
|
+
self(
|
|
583
|
+
internalRequest.setBody(
|
|
584
|
+
request,
|
|
585
|
+
internalBody.uint8Array(body, "application/json")
|
|
586
|
+
)
|
|
562
587
|
)
|
|
563
|
-
|
|
588
|
+
)
|
|
564
589
|
)
|
|
565
590
|
})
|
|
566
591
|
|
|
@@ -170,3 +170,56 @@ export const schemaNoBody = <
|
|
|
170
170
|
headers: self.headers
|
|
171
171
|
})
|
|
172
172
|
}
|
|
173
|
+
|
|
174
|
+
/** @internal */
|
|
175
|
+
export const arrayBuffer = <E, R>(effect: Effect.Effect<ClientResponse.ClientResponse, E, R>) =>
|
|
176
|
+
Effect.scoped(Effect.flatMap(effect, (_) => _.arrayBuffer))
|
|
177
|
+
|
|
178
|
+
/** @internal */
|
|
179
|
+
export const text = <E, R>(effect: Effect.Effect<ClientResponse.ClientResponse, E, R>) =>
|
|
180
|
+
Effect.scoped(Effect.flatMap(effect, (_) => _.text))
|
|
181
|
+
|
|
182
|
+
/** @internal */
|
|
183
|
+
export const json = <E, R>(effect: Effect.Effect<ClientResponse.ClientResponse, E, R>) =>
|
|
184
|
+
Effect.scoped(Effect.flatMap(effect, (_) => _.json))
|
|
185
|
+
|
|
186
|
+
/** @internal */
|
|
187
|
+
export const urlParamsBody = <E, R>(effect: Effect.Effect<ClientResponse.ClientResponse, E, R>) =>
|
|
188
|
+
Effect.scoped(Effect.flatMap(effect, (_) => _.urlParamsBody))
|
|
189
|
+
|
|
190
|
+
/** @internal */
|
|
191
|
+
export const formData = <E, R>(effect: Effect.Effect<ClientResponse.ClientResponse, E, R>) =>
|
|
192
|
+
Effect.scoped(Effect.flatMap(effect, (_) => _.formData))
|
|
193
|
+
|
|
194
|
+
/** @internal */
|
|
195
|
+
export const stream = <E, R>(effect: Effect.Effect<ClientResponse.ClientResponse, E, R>) =>
|
|
196
|
+
Stream.unwrapScoped(Effect.map(effect, (_) => _.stream))
|
|
197
|
+
|
|
198
|
+
/** @internal */
|
|
199
|
+
export const schemaJsonEffect = <
|
|
200
|
+
R,
|
|
201
|
+
I extends {
|
|
202
|
+
readonly status?: number | undefined
|
|
203
|
+
readonly headers?: Readonly<Record<string, string>> | undefined
|
|
204
|
+
readonly body?: unknown | undefined
|
|
205
|
+
},
|
|
206
|
+
A
|
|
207
|
+
>(schema: Schema.Schema<A, I, R>) => {
|
|
208
|
+
const decode = schemaJson(schema)
|
|
209
|
+
return <E, R2>(effect: Effect.Effect<ClientResponse.ClientResponse, E, R2>) =>
|
|
210
|
+
Effect.scoped(Effect.flatMap(effect, decode))
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/** @internal */
|
|
214
|
+
export const schemaNoBodyEffect = <
|
|
215
|
+
R,
|
|
216
|
+
I extends {
|
|
217
|
+
readonly status?: number | undefined
|
|
218
|
+
readonly headers?: Readonly<Record<string, string>> | undefined
|
|
219
|
+
},
|
|
220
|
+
A
|
|
221
|
+
>(schema: Schema.Schema<A, I, R>) => {
|
|
222
|
+
const decode = schemaNoBody(schema)
|
|
223
|
+
return <E, R2>(effect: Effect.Effect<ClientResponse.ClientResponse, E, R2>) =>
|
|
224
|
+
Effect.scoped(Effect.flatMap(effect, decode))
|
|
225
|
+
}
|
package/src/internal/worker.ts
CHANGED
|
@@ -176,7 +176,7 @@ export const makeManager = Effect.gen(function*(_) {
|
|
|
176
176
|
queue[0],
|
|
177
177
|
response[1] === 2
|
|
178
178
|
? Exit.fail(response[2])
|
|
179
|
-
: Exit.
|
|
179
|
+
: Exit.failCause(WorkerError.decodeCause(response[2]))
|
|
180
180
|
)
|
|
181
181
|
}
|
|
182
182
|
}
|
|
@@ -282,7 +282,7 @@ export const makeManager = Effect.gen(function*(_) {
|
|
|
282
282
|
yield* _(
|
|
283
283
|
Effect.sync(initialMessage),
|
|
284
284
|
Effect.flatMap(executeEffect),
|
|
285
|
-
Effect.mapError((error) => WorkerError("spawn", error))
|
|
285
|
+
Effect.mapError((error) => new WorkerError({ reason: "spawn", error }))
|
|
286
286
|
)
|
|
287
287
|
}
|
|
288
288
|
|
|
@@ -363,7 +363,10 @@ export const makeSerialized = <
|
|
|
363
363
|
manager.spawn({
|
|
364
364
|
...options as any,
|
|
365
365
|
encode(message) {
|
|
366
|
-
return Effect.mapError(
|
|
366
|
+
return Effect.mapError(
|
|
367
|
+
Serializable.serialize(message as any),
|
|
368
|
+
(error) => new WorkerError({ reason: "encode", error })
|
|
369
|
+
)
|
|
367
370
|
}
|
|
368
371
|
})
|
|
369
372
|
)
|
|
@@ -1,21 +1,6 @@
|
|
|
1
|
-
import * as Data from "effect/Data"
|
|
2
1
|
import type * as WorkerError_ from "../WorkerError.js"
|
|
3
2
|
|
|
4
3
|
/** @internal */
|
|
5
4
|
export const WorkerErrorTypeId: WorkerError_.WorkerErrorTypeId = Symbol.for(
|
|
6
|
-
"@effect
|
|
5
|
+
"@effect/platform/WorkerError"
|
|
7
6
|
) as WorkerError_.WorkerErrorTypeId
|
|
8
|
-
|
|
9
|
-
/** @internal */
|
|
10
|
-
export const WorkerError = (
|
|
11
|
-
reason: WorkerError_.WorkerError["reason"],
|
|
12
|
-
error: unknown,
|
|
13
|
-
stack?: string | undefined
|
|
14
|
-
): WorkerError_.WorkerError =>
|
|
15
|
-
Data.struct({
|
|
16
|
-
[WorkerErrorTypeId]: WorkerErrorTypeId,
|
|
17
|
-
_tag: "WorkerError",
|
|
18
|
-
reason,
|
|
19
|
-
error,
|
|
20
|
-
stack
|
|
21
|
-
})
|
|
@@ -16,7 +16,7 @@ import * as Scope from "effect/Scope"
|
|
|
16
16
|
import * as Stream from "effect/Stream"
|
|
17
17
|
import * as Transferable from "../Transferable.js"
|
|
18
18
|
import type * as Worker from "../Worker.js"
|
|
19
|
-
import
|
|
19
|
+
import { WorkerError } from "../WorkerError.js"
|
|
20
20
|
import type * as WorkerRunner from "../WorkerRunner.js"
|
|
21
21
|
|
|
22
22
|
/** @internal */
|
|
@@ -51,7 +51,7 @@ export const make = <I, R, E, O>(
|
|
|
51
51
|
yield* _(
|
|
52
52
|
Queue.take(backing.queue),
|
|
53
53
|
options?.decode ?
|
|
54
|
-
Effect.flatMap((req): Effect.Effect<Worker.Worker.Request<I>, WorkerError
|
|
54
|
+
Effect.flatMap((req): Effect.Effect<Worker.Worker.Request<I>, WorkerError> => {
|
|
55
55
|
if (req[1] === 1) {
|
|
56
56
|
return Effect.succeed(req)
|
|
57
57
|
}
|
|
@@ -86,10 +86,10 @@ export const make = <I, R, E, O>(
|
|
|
86
86
|
...collector.unsafeRead()
|
|
87
87
|
])
|
|
88
88
|
),
|
|
89
|
-
Effect.catchAllCause((cause) => backing.send([id, 3,
|
|
89
|
+
Effect.catchAllCause((cause) => backing.send([id, 3, WorkerError.encodeCause(cause)]))
|
|
90
90
|
)
|
|
91
91
|
},
|
|
92
|
-
onRight: (cause) => backing.send([id, 3,
|
|
92
|
+
onRight: (cause) => backing.send([id, 3, WorkerError.encodeCause(cause)])
|
|
93
93
|
}),
|
|
94
94
|
onSuccess: (data) => {
|
|
95
95
|
const transfers = options?.transfers ? options.transfers(data) : []
|
|
@@ -103,7 +103,7 @@ export const make = <I, R, E, O>(
|
|
|
103
103
|
...collector.unsafeRead()
|
|
104
104
|
])
|
|
105
105
|
),
|
|
106
|
-
Effect.catchAllCause((cause) => backing.send([id, 3,
|
|
106
|
+
Effect.catchAllCause((cause) => backing.send([id, 3, WorkerError.encodeCause(cause)]))
|
|
107
107
|
)
|
|
108
108
|
}
|
|
109
109
|
}) :
|
|
@@ -152,10 +152,10 @@ export const make = <I, R, E, O>(
|
|
|
152
152
|
...collector.unsafeRead()
|
|
153
153
|
])
|
|
154
154
|
),
|
|
155
|
-
Effect.catchAllCause((cause) => backing.send([id, 3,
|
|
155
|
+
Effect.catchAllCause((cause) => backing.send([id, 3, WorkerError.encodeCause(cause)]))
|
|
156
156
|
)
|
|
157
157
|
},
|
|
158
|
-
onRight: (cause) => backing.send([id, 3,
|
|
158
|
+
onRight: (cause) => backing.send([id, 3, WorkerError.encodeCause(cause)])
|
|
159
159
|
}),
|
|
160
160
|
onSuccess: () => backing.send([id, 1])
|
|
161
161
|
})
|
|
@@ -188,8 +188,7 @@ export const make = <I, R, E, O>(
|
|
|
188
188
|
export const layer = <I, R, E, O>(
|
|
189
189
|
process: (request: I) => Stream.Stream<O, E, R> | Effect.Effect<O, E, R>,
|
|
190
190
|
options?: WorkerRunner.Runner.Options<I, E, O>
|
|
191
|
-
): Layer.Layer<never, WorkerError
|
|
192
|
-
Layer.scopedDiscard(make(process, options))
|
|
191
|
+
): Layer.Layer<never, WorkerError, WorkerRunner.PlatformRunner | R> => Layer.scopedDiscard(make(process, options))
|
|
193
192
|
|
|
194
193
|
/** @internal */
|
|
195
194
|
export const makeSerialized = <
|
|
@@ -202,7 +201,7 @@ export const makeSerialized = <
|
|
|
202
201
|
handlers: Handlers
|
|
203
202
|
): Effect.Effect<
|
|
204
203
|
void,
|
|
205
|
-
WorkerError
|
|
204
|
+
WorkerError,
|
|
206
205
|
| R
|
|
207
206
|
| WorkerRunner.PlatformRunner
|
|
208
207
|
| Scope.Scope
|
|
@@ -228,19 +227,19 @@ export const makeSerialized = <
|
|
|
228
227
|
decode(message) {
|
|
229
228
|
return Effect.mapError(
|
|
230
229
|
parseRequest(message),
|
|
231
|
-
(error) => WorkerError
|
|
230
|
+
(error) => new WorkerError({ reason: "decode", error })
|
|
232
231
|
)
|
|
233
232
|
},
|
|
234
233
|
encodeError(request, message) {
|
|
235
234
|
return Effect.mapError(
|
|
236
235
|
Serializable.serializeFailure(request as any, message),
|
|
237
|
-
(error) => WorkerError
|
|
236
|
+
(error) => new WorkerError({ reason: "encode", error })
|
|
238
237
|
)
|
|
239
238
|
},
|
|
240
239
|
encodeOutput(request, message) {
|
|
241
|
-
return Effect.
|
|
240
|
+
return Effect.catchAllCause(
|
|
242
241
|
Serializable.serializeSuccess(request as any, message),
|
|
243
|
-
(error) => WorkerError
|
|
242
|
+
(error) => new WorkerError({ reason: "encode", error })
|
|
244
243
|
)
|
|
245
244
|
}
|
|
246
245
|
}))
|
|
@@ -257,7 +256,7 @@ export const layerSerialized = <
|
|
|
257
256
|
handlers: Handlers
|
|
258
257
|
): Layer.Layer<
|
|
259
258
|
never,
|
|
260
|
-
WorkerError
|
|
259
|
+
WorkerError,
|
|
261
260
|
| R
|
|
262
261
|
| WorkerRunner.PlatformRunner
|
|
263
262
|
| WorkerRunner.SerializedRunner.HandlersContext<Handlers>
|