@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
|
@@ -5,14 +5,11 @@ import * as Chunk from "effect/Chunk"
|
|
|
5
5
|
import * as Context from "effect/Context"
|
|
6
6
|
import * as Effect from "effect/Effect"
|
|
7
7
|
import * as Either from "effect/Either"
|
|
8
|
-
import * as ExecutionStrategy from "effect/ExecutionStrategy"
|
|
9
|
-
import * as Exit from "effect/Exit"
|
|
10
8
|
import * as Fiber from "effect/Fiber"
|
|
11
|
-
import {
|
|
9
|
+
import { pipe } from "effect/Function"
|
|
12
10
|
import * as Layer from "effect/Layer"
|
|
13
|
-
import * as
|
|
14
|
-
import * as
|
|
15
|
-
import * as Scope from "effect/Scope"
|
|
11
|
+
import * as Schedule from "effect/Schedule"
|
|
12
|
+
import type * as Scope from "effect/Scope"
|
|
16
13
|
import * as Stream from "effect/Stream"
|
|
17
14
|
import * as Transferable from "../Transferable.js"
|
|
18
15
|
import type * as Worker from "../Worker.js"
|
|
@@ -30,149 +27,119 @@ export const PlatformRunner = Context.GenericTag<WorkerRunner.PlatformRunner>(
|
|
|
30
27
|
)
|
|
31
28
|
|
|
32
29
|
/** @internal */
|
|
33
|
-
export const
|
|
30
|
+
export const run = <I, E, R, O>(
|
|
34
31
|
process: (request: I) => Stream.Stream<O, E, R> | Effect.Effect<O, E, R>,
|
|
35
32
|
options?: WorkerRunner.Runner.Options<I, O, E>
|
|
36
33
|
) =>
|
|
37
|
-
Effect.gen(function*(
|
|
38
|
-
const
|
|
39
|
-
const
|
|
40
|
-
const
|
|
41
|
-
Scope.close(scope, Exit.void),
|
|
42
|
-
Fiber.interruptFork(fiber)
|
|
43
|
-
)
|
|
44
|
-
const platform = yield* _(PlatformRunner)
|
|
45
|
-
const backing = yield* _(
|
|
46
|
-
platform.start<Worker.Worker.Request<I>, Worker.Worker.Response<E>>(shutdown),
|
|
47
|
-
Scope.extend(scope)
|
|
48
|
-
)
|
|
49
|
-
const fiberMap = new Map<number, Fiber.Fiber<void, unknown>>()
|
|
34
|
+
Effect.gen(function*() {
|
|
35
|
+
const platform = yield* PlatformRunner
|
|
36
|
+
const backing = yield* platform.start<Worker.Worker.Request<I>, Worker.Worker.Response<E>>()
|
|
37
|
+
const fiberMap = new Map<number, Fiber.Fiber<unknown, unknown>>()
|
|
50
38
|
|
|
51
|
-
yield*
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
return Effect.succeed(msg)
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
return Effect.map(options.decode!(req[2]), (data) => [msg[0], [req[0], req[1], data, req[3]]])
|
|
61
|
-
}) :
|
|
62
|
-
identity,
|
|
63
|
-
Effect.tap(([portId, req]) => {
|
|
64
|
-
const id = req[0]
|
|
65
|
-
if (req[1] === 1) {
|
|
66
|
-
const fiber = fiberMap.get(id)
|
|
67
|
-
if (!fiber) return Effect.void
|
|
68
|
-
return Fiber.interrupt(fiber)
|
|
69
|
-
}
|
|
39
|
+
return yield* backing.run((portId, [id, kind, data, span]): Effect.Effect<void, WorkerError, R> => {
|
|
40
|
+
if (kind === 1) {
|
|
41
|
+
const fiber = fiberMap.get(id)
|
|
42
|
+
if (!fiber) return Effect.void
|
|
43
|
+
return Fiber.interrupt(fiber)
|
|
44
|
+
}
|
|
70
45
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
? Effect.provideService(options.encodeOutput(req[2], data), Transferable.Collector, collector)
|
|
81
|
-
: Effect.succeed(data),
|
|
82
|
-
Effect.flatMap((payload) =>
|
|
83
|
-
backing.send(portId, [id, 0, [payload]], [
|
|
84
|
-
...transfers,
|
|
85
|
-
...collector.unsafeRead()
|
|
86
|
-
])
|
|
87
|
-
)
|
|
88
|
-
)
|
|
89
|
-
}) :
|
|
46
|
+
return Effect.withFiberRuntime<I, WorkerError>((fiber) => {
|
|
47
|
+
fiberMap.set(id, fiber)
|
|
48
|
+
return options?.decode ? options.decode(data) : Effect.succeed(data)
|
|
49
|
+
}).pipe(
|
|
50
|
+
Effect.flatMap((input) => {
|
|
51
|
+
const collector = Transferable.unsafeMakeCollector()
|
|
52
|
+
const stream = process(input)
|
|
53
|
+
let effect = Effect.isEffect(stream) ?
|
|
54
|
+
Effect.flatMap(stream, (out) =>
|
|
90
55
|
pipe(
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
Effect.forEach(data, (data) => {
|
|
104
|
-
if (options?.transfers) {
|
|
105
|
-
for (const option of options.transfers(data)) {
|
|
106
|
-
transfers.push(option)
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
return Effect.orDie(options.encodeOutput!(req[2], data))
|
|
110
|
-
}),
|
|
111
|
-
Effect.provideService(Transferable.Collector, collector),
|
|
112
|
-
Effect.flatMap((payload) => {
|
|
113
|
-
collector.unsafeRead().forEach((transfer) => transfers.push(transfer))
|
|
114
|
-
return backing.send(portId, [id, 0, payload], transfers)
|
|
115
|
-
})
|
|
116
|
-
)
|
|
117
|
-
}),
|
|
118
|
-
Stream.runDrain,
|
|
119
|
-
Effect.andThen(backing.send(portId, [id, 1]))
|
|
120
|
-
)
|
|
121
|
-
|
|
122
|
-
if (req[3]) {
|
|
123
|
-
const [traceId, spanId, sampled] = req[3]
|
|
124
|
-
effect = Effect.withParentSpan(effect, {
|
|
125
|
-
_tag: "ExternalSpan",
|
|
126
|
-
traceId,
|
|
127
|
-
spanId,
|
|
128
|
-
sampled,
|
|
129
|
-
context: Context.empty()
|
|
130
|
-
})
|
|
131
|
-
}
|
|
56
|
+
options?.encodeOutput
|
|
57
|
+
? Effect.provideService(options.encodeOutput(input, out), Transferable.Collector, collector)
|
|
58
|
+
: Effect.succeed(out),
|
|
59
|
+
Effect.flatMap((payload) => backing.send(portId, [id, 0, [payload]], collector.unsafeRead()))
|
|
60
|
+
)) :
|
|
61
|
+
pipe(
|
|
62
|
+
stream,
|
|
63
|
+
Stream.runForEachChunk((chunk) => {
|
|
64
|
+
if (options?.encodeOutput === undefined) {
|
|
65
|
+
const payload = Chunk.toReadonlyArray(chunk)
|
|
66
|
+
return backing.send(portId, [id, 0, payload])
|
|
67
|
+
}
|
|
132
68
|
|
|
133
|
-
return effect
|
|
134
|
-
}),
|
|
135
|
-
Effect.catchIf(isWorkerError, (error) =>
|
|
136
|
-
backing.send(portId, [id, 3, WorkerError.encodeCause(Cause.fail(error))])),
|
|
137
|
-
Effect.onExit((exit) => {
|
|
138
|
-
if (exit._tag === "Success") {
|
|
139
|
-
return Effect.void
|
|
140
|
-
}
|
|
141
|
-
return Either.match(Cause.failureOrCause(exit.cause), {
|
|
142
|
-
onLeft: (error) => {
|
|
143
|
-
const transfers = options?.transfers ? options.transfers(error) : []
|
|
144
69
|
collector.unsafeClear()
|
|
145
70
|
return pipe(
|
|
146
|
-
options
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
Transferable.Collector,
|
|
150
|
-
collector
|
|
151
|
-
)
|
|
152
|
-
: Effect.succeed(error),
|
|
153
|
-
Effect.flatMap((payload) =>
|
|
154
|
-
backing.send(portId, [id, 2, payload as any], [
|
|
155
|
-
...transfers,
|
|
156
|
-
...collector.unsafeRead()
|
|
157
|
-
])
|
|
158
|
-
),
|
|
159
|
-
Effect.catchAllCause((cause) =>
|
|
160
|
-
backing.send(portId, [id, 3, WorkerError.encodeCause(cause)])
|
|
161
|
-
)
|
|
71
|
+
Effect.forEach(chunk, (data) => options.encodeOutput!(input, data)),
|
|
72
|
+
Effect.provideService(Transferable.Collector, collector),
|
|
73
|
+
Effect.flatMap((payload) => backing.send(portId, [id, 0, payload], collector.unsafeRead()))
|
|
162
74
|
)
|
|
163
|
-
},
|
|
164
|
-
|
|
75
|
+
}),
|
|
76
|
+
Effect.andThen(backing.send(portId, [id, 1]))
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
if (span) {
|
|
80
|
+
effect = Effect.withParentSpan(effect, {
|
|
81
|
+
_tag: "ExternalSpan",
|
|
82
|
+
traceId: span[0],
|
|
83
|
+
spanId: span[1],
|
|
84
|
+
sampled: span[2],
|
|
85
|
+
context: Context.empty()
|
|
165
86
|
})
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
Effect.
|
|
169
|
-
|
|
170
|
-
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return Effect.uninterruptibleMask((restore) =>
|
|
90
|
+
restore(effect).pipe(
|
|
91
|
+
Effect.catchIf(
|
|
92
|
+
isWorkerError,
|
|
93
|
+
(error) => backing.send(portId, [id, 3, WorkerError.encodeCause(Cause.fail(error))])
|
|
94
|
+
),
|
|
95
|
+
Effect.catchAllCause((cause) =>
|
|
96
|
+
Either.match(Cause.failureOrCause(cause), {
|
|
97
|
+
onLeft: (error) => {
|
|
98
|
+
collector.unsafeClear()
|
|
99
|
+
return pipe(
|
|
100
|
+
options?.encodeError
|
|
101
|
+
? Effect.provideService(
|
|
102
|
+
options.encodeError(input, error),
|
|
103
|
+
Transferable.Collector,
|
|
104
|
+
collector
|
|
105
|
+
)
|
|
106
|
+
: Effect.succeed(error),
|
|
107
|
+
Effect.flatMap((payload) =>
|
|
108
|
+
backing.send(portId, [id, 2, payload as any], collector.unsafeRead())
|
|
109
|
+
),
|
|
110
|
+
Effect.catchAllCause((cause) => backing.send(portId, [id, 3, WorkerError.encodeCause(cause)]))
|
|
111
|
+
)
|
|
112
|
+
},
|
|
113
|
+
onRight: (cause) => backing.send(portId, [id, 3, WorkerError.encodeCause(cause)])
|
|
114
|
+
})
|
|
115
|
+
)
|
|
116
|
+
)
|
|
117
|
+
)
|
|
118
|
+
}),
|
|
119
|
+
Effect.ensuring(Effect.sync(() => fiberMap.delete(id)))
|
|
120
|
+
)
|
|
121
|
+
})
|
|
122
|
+
})
|
|
123
|
+
|
|
124
|
+
/** @internal */
|
|
125
|
+
export const make = <I, E, R, O>(
|
|
126
|
+
process: (request: I) => Stream.Stream<O, E, R> | Effect.Effect<O, E, R>,
|
|
127
|
+
options?: WorkerRunner.Runner.Options<I, O, E>
|
|
128
|
+
): Effect.Effect<void, WorkerError, WorkerRunner.PlatformRunner | R | Scope.Scope> =>
|
|
129
|
+
Effect.withFiberRuntime<void, never, WorkerRunner.PlatformRunner | R | Scope.Scope>((fiber) =>
|
|
130
|
+
run(process, options).pipe(
|
|
131
|
+
Effect.tapErrorCause(Effect.logDebug),
|
|
132
|
+
Effect.retry(Schedule.spaced(1000)),
|
|
133
|
+
Effect.annotateLogs({
|
|
134
|
+
package: "@effect/platform-node",
|
|
135
|
+
module: "WorkerRunner"
|
|
171
136
|
}),
|
|
172
|
-
Effect.
|
|
173
|
-
Effect.
|
|
137
|
+
Effect.ensuring(Fiber.interruptAsFork(fiber, fiber.id())),
|
|
138
|
+
Effect.interruptible,
|
|
139
|
+
Effect.forkScoped,
|
|
140
|
+
Effect.asVoid
|
|
174
141
|
)
|
|
175
|
-
|
|
142
|
+
)
|
|
176
143
|
|
|
177
144
|
/** @internal */
|
|
178
145
|
export const layer = <I, E, R, O>(
|
|
@@ -217,19 +184,19 @@ export const makeSerialized = <
|
|
|
217
184
|
decode(message) {
|
|
218
185
|
return Effect.mapError(
|
|
219
186
|
parseRequest(message),
|
|
220
|
-
(
|
|
187
|
+
(cause) => new WorkerError({ reason: "decode", cause })
|
|
221
188
|
)
|
|
222
189
|
},
|
|
223
190
|
encodeError(request, message) {
|
|
224
191
|
return Effect.mapError(
|
|
225
192
|
Serializable.serializeFailure(request as any, message),
|
|
226
|
-
(
|
|
193
|
+
(cause) => new WorkerError({ reason: "encode", cause })
|
|
227
194
|
)
|
|
228
195
|
},
|
|
229
196
|
encodeOutput(request, message) {
|
|
230
197
|
return Effect.catchAllCause(
|
|
231
198
|
Serializable.serializeSuccess(request as any, message),
|
|
232
|
-
(
|
|
199
|
+
(cause) => new WorkerError({ reason: "encode", cause })
|
|
233
200
|
)
|
|
234
201
|
}
|
|
235
202
|
}))
|