@effect/platform 0.69.17 → 0.69.19
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/HttpApi.js +21 -18
- package/dist/cjs/HttpApi.js.map +1 -1
- package/dist/cjs/HttpApiBuilder.js +8 -10
- package/dist/cjs/HttpApiBuilder.js.map +1 -1
- package/dist/cjs/HttpApiEndpoint.js +2 -3
- package/dist/cjs/HttpApiEndpoint.js.map +1 -1
- package/dist/cjs/HttpApiGroup.js +12 -10
- package/dist/cjs/HttpApiGroup.js.map +1 -1
- package/dist/cjs/OpenApi.js +2 -3
- package/dist/cjs/OpenApi.js.map +1 -1
- package/dist/cjs/Socket.js +30 -37
- package/dist/cjs/Socket.js.map +1 -1
- package/dist/cjs/internal/worker.js +22 -34
- package/dist/cjs/internal/worker.js.map +1 -1
- package/dist/cjs/internal/workerRunner.js +1 -1
- package/dist/cjs/internal/workerRunner.js.map +1 -1
- package/dist/dts/HttpApi.d.ts +4 -5
- package/dist/dts/HttpApi.d.ts.map +1 -1
- package/dist/dts/HttpApiBuilder.d.ts.map +1 -1
- package/dist/dts/HttpApiEndpoint.d.ts +1 -2
- package/dist/dts/HttpApiEndpoint.d.ts.map +1 -1
- package/dist/dts/HttpApiGroup.d.ts +3 -4
- package/dist/dts/HttpApiGroup.d.ts.map +1 -1
- package/dist/dts/OpenApi.d.ts.map +1 -1
- package/dist/dts/Socket.d.ts.map +1 -1
- package/dist/dts/Worker.d.ts +1 -1
- package/dist/dts/Worker.d.ts.map +1 -1
- package/dist/esm/HttpApi.js +21 -18
- package/dist/esm/HttpApi.js.map +1 -1
- package/dist/esm/HttpApiBuilder.js +8 -10
- package/dist/esm/HttpApiBuilder.js.map +1 -1
- package/dist/esm/HttpApiEndpoint.js +2 -3
- package/dist/esm/HttpApiEndpoint.js.map +1 -1
- package/dist/esm/HttpApiGroup.js +12 -10
- package/dist/esm/HttpApiGroup.js.map +1 -1
- package/dist/esm/OpenApi.js +2 -3
- package/dist/esm/OpenApi.js.map +1 -1
- package/dist/esm/Socket.js +30 -37
- package/dist/esm/Socket.js.map +1 -1
- package/dist/esm/internal/worker.js +22 -34
- package/dist/esm/internal/worker.js.map +1 -1
- package/dist/esm/internal/workerRunner.js +1 -1
- package/dist/esm/internal/workerRunner.js.map +1 -1
- package/package.json +2 -2
- package/src/HttpApi.ts +24 -26
- package/src/HttpApiBuilder.ts +9 -11
- package/src/HttpApiEndpoint.ts +4 -5
- package/src/HttpApiGroup.ts +16 -14
- package/src/OpenApi.ts +2 -3
- package/src/Socket.ts +34 -48
- package/src/Worker.ts +1 -1
- package/src/internal/worker.ts +35 -41
- package/src/internal/workerRunner.ts +1 -1
package/src/Socket.ts
CHANGED
|
@@ -397,7 +397,7 @@ export const fromWebSocket = <RO>(
|
|
|
397
397
|
): Effect.Effect<Socket, never, Exclude<RO, Scope.Scope>> =>
|
|
398
398
|
Effect.gen(function*() {
|
|
399
399
|
const fiber = Option.getOrThrow(Fiber.getCurrentFiber())
|
|
400
|
-
const sendQueue = yield* Mailbox.make<Uint8Array | string
|
|
400
|
+
const sendQueue = yield* Mailbox.make<Uint8Array | string | CloseEvent>({
|
|
401
401
|
capacity: fiber.getFiberRef(currentSendQueueCapacity),
|
|
402
402
|
strategy: "dropping"
|
|
403
403
|
})
|
|
@@ -465,22 +465,25 @@ export const fromWebSocket = <RO>(
|
|
|
465
465
|
)
|
|
466
466
|
}
|
|
467
467
|
open = true
|
|
468
|
-
yield* sendQueue.
|
|
469
|
-
Effect.tap((
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
468
|
+
yield* sendQueue.take.pipe(
|
|
469
|
+
Effect.tap((chunk) => {
|
|
470
|
+
if (isCloseEvent(chunk)) {
|
|
471
|
+
ws.close(chunk.code, chunk.reason)
|
|
472
|
+
return Effect.fail(
|
|
473
|
+
new SocketCloseError({
|
|
474
|
+
reason: "Close",
|
|
475
|
+
code: chunk.code,
|
|
476
|
+
closeReason: chunk.reason
|
|
477
|
+
})
|
|
478
|
+
)
|
|
479
|
+
}
|
|
480
|
+
return Effect.try({
|
|
481
|
+
try: () => ws.send(chunk),
|
|
476
482
|
catch: (cause) => new SocketGenericError({ reason: "Write", cause })
|
|
477
483
|
})
|
|
478
|
-
),
|
|
479
|
-
Effect.forever,
|
|
480
|
-
Effect.catchIf(SocketCloseError.is, (error) => {
|
|
481
|
-
ws.close(error.code, error.closeReason)
|
|
482
|
-
return Effect.fail(error)
|
|
483
484
|
}),
|
|
485
|
+
Effect.forever,
|
|
486
|
+
Effect.catchTag("NoSuchElementException", () => Effect.void),
|
|
484
487
|
FiberSet.run(fiberSet)
|
|
485
488
|
)
|
|
486
489
|
return yield* FiberSet.join(fiberSet).pipe(
|
|
@@ -503,16 +506,7 @@ export const fromWebSocket = <RO>(
|
|
|
503
506
|
: handler(data)
|
|
504
507
|
)
|
|
505
508
|
|
|
506
|
-
const write = (chunk: Uint8Array | string | CloseEvent) =>
|
|
507
|
-
isCloseEvent(chunk)
|
|
508
|
-
? sendQueue.fail(
|
|
509
|
-
new SocketCloseError({
|
|
510
|
-
reason: "Close",
|
|
511
|
-
code: chunk.code,
|
|
512
|
-
closeReason: chunk.reason
|
|
513
|
-
})
|
|
514
|
-
)
|
|
515
|
-
: sendQueue.offer(chunk)
|
|
509
|
+
const write = (chunk: Uint8Array | string | CloseEvent) => sendQueue.offer(chunk)
|
|
516
510
|
const writer = Effect.succeed(write)
|
|
517
511
|
|
|
518
512
|
return Socket.of({
|
|
@@ -584,7 +578,7 @@ export const fromTransformStream = <R>(acquire: Effect.Effect<InputTransformStre
|
|
|
584
578
|
}): Effect.Effect<Socket, never, Exclude<R, Scope.Scope>> =>
|
|
585
579
|
Effect.gen(function*() {
|
|
586
580
|
const fiber = Option.getOrThrow(Fiber.getCurrentFiber())
|
|
587
|
-
const sendQueue = yield* Mailbox.make<Uint8Array | string
|
|
581
|
+
const sendQueue = yield* Mailbox.make<Uint8Array | string | CloseEvent>({
|
|
588
582
|
capacity: fiber.getFiberRef(currentSendQueueCapacity),
|
|
589
583
|
strategy: "dropping"
|
|
590
584
|
})
|
|
@@ -608,23 +602,24 @@ export const fromTransformStream = <R>(acquire: Effect.Effect<InputTransformStre
|
|
|
608
602
|
)
|
|
609
603
|
const fiberSet = yield* FiberSet.make<any, E | SocketError>()
|
|
610
604
|
const encoder = new TextEncoder()
|
|
611
|
-
yield* sendQueue.
|
|
612
|
-
Effect.
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
605
|
+
yield* sendQueue.take.pipe(
|
|
606
|
+
Effect.tap((chunk) => {
|
|
607
|
+
if (isCloseEvent(chunk)) {
|
|
608
|
+
return Effect.fail(
|
|
609
|
+
new SocketCloseError({
|
|
610
|
+
reason: "Close",
|
|
611
|
+
code: chunk.code,
|
|
612
|
+
closeReason: chunk.reason
|
|
613
|
+
})
|
|
614
|
+
)
|
|
615
|
+
}
|
|
616
|
+
return Effect.tryPromise({
|
|
617
|
+
try: () => writer.write(typeof chunk === "string" ? encoder.encode(chunk) : chunk),
|
|
623
618
|
catch: (cause) => new SocketGenericError({ reason: "Write", cause })
|
|
624
619
|
})
|
|
625
|
-
return done ? Effect.zipRight(write, Effect.interrupt) : write
|
|
626
620
|
}),
|
|
627
621
|
Effect.forever,
|
|
622
|
+
Effect.catchTag("NoSuchElementException", () => Effect.void),
|
|
628
623
|
Effect.ensuring(Effect.promise(() => writer.close())),
|
|
629
624
|
FiberSet.run(fiberSet)
|
|
630
625
|
)
|
|
@@ -663,16 +658,7 @@ export const fromTransformStream = <R>(acquire: Effect.Effect<InputTransformStre
|
|
|
663
658
|
: handler(data)
|
|
664
659
|
)
|
|
665
660
|
|
|
666
|
-
const write = (chunk: Uint8Array | string | CloseEvent) =>
|
|
667
|
-
isCloseEvent(chunk) ?
|
|
668
|
-
sendQueue.fail(
|
|
669
|
-
new SocketCloseError({
|
|
670
|
-
reason: "Close",
|
|
671
|
-
code: chunk.code,
|
|
672
|
-
closeReason: chunk.reason
|
|
673
|
-
})
|
|
674
|
-
) :
|
|
675
|
-
sendQueue.offer(chunk)
|
|
661
|
+
const write = (chunk: Uint8Array | string | CloseEvent) => sendQueue.offer(chunk)
|
|
676
662
|
const writer = Effect.acquireRelease(
|
|
677
663
|
Effect.succeed(write),
|
|
678
664
|
() => sendQueue.end
|
package/src/Worker.ts
CHANGED
|
@@ -66,7 +66,7 @@ export const makePlatform: <W>() => <
|
|
|
66
66
|
P extends { readonly postMessage: (message: any, transfers?: any | undefined) => void }
|
|
67
67
|
>(
|
|
68
68
|
options: {
|
|
69
|
-
readonly setup: (options: { readonly worker: W; readonly scope: Scope.Scope }) => Effect.Effect<P>
|
|
69
|
+
readonly setup: (options: { readonly worker: W; readonly scope: Scope.Scope }) => Effect.Effect<P, WorkerError>
|
|
70
70
|
readonly listen: (
|
|
71
71
|
options: {
|
|
72
72
|
readonly port: P
|
package/src/internal/worker.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Runtime } from "effect"
|
|
1
2
|
import * as Channel from "effect/Channel"
|
|
2
3
|
import * as Context from "effect/Context"
|
|
3
4
|
import * as Deferred from "effect/Deferred"
|
|
@@ -86,6 +87,7 @@ export const makeManager = Effect.gen(function*() {
|
|
|
86
87
|
? Deferred.failCause(mailbox, cause)
|
|
87
88
|
: mailbox.failCause(cause))
|
|
88
89
|
),
|
|
90
|
+
Effect.tapErrorCause(Effect.logWarning),
|
|
89
91
|
Effect.retry(Schedule.spaced(1000)),
|
|
90
92
|
Effect.annotateLogs({
|
|
91
93
|
package: "@effect/platform",
|
|
@@ -401,7 +403,7 @@ export const makePlatform = <W>() =>
|
|
|
401
403
|
readonly setup: (options: {
|
|
402
404
|
readonly worker: W
|
|
403
405
|
readonly scope: Scope.Scope
|
|
404
|
-
}) => Effect.Effect<P>
|
|
406
|
+
}) => Effect.Effect<P, WorkerError>
|
|
405
407
|
readonly listen: (options: {
|
|
406
408
|
readonly port: P
|
|
407
409
|
readonly emit: (data: any) => void
|
|
@@ -417,49 +419,41 @@ export const makePlatform = <W>() =>
|
|
|
417
419
|
let currentPort: P | undefined
|
|
418
420
|
const buffer: Array<[I, ReadonlyArray<unknown> | undefined]> = []
|
|
419
421
|
|
|
420
|
-
const run = <A, E, R>(
|
|
422
|
+
const run = <A, E, R>(
|
|
423
|
+
handler: (_: Worker.BackingWorker.Message<O>) => Effect.Effect<A, E, R>
|
|
424
|
+
): Effect.Effect<never, WorkerError | E, R> =>
|
|
421
425
|
Effect.uninterruptibleMask((restore) =>
|
|
422
|
-
|
|
423
|
-
Effect.
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
currentPort = undefined
|
|
431
|
-
})
|
|
432
|
-
)
|
|
433
|
-
}),
|
|
434
|
-
Effect.bind("fiberSet", ({ scope }) =>
|
|
435
|
-
FiberSet.make<any, WorkerError | E>().pipe(
|
|
436
|
-
Scope.extend(scope)
|
|
437
|
-
)),
|
|
438
|
-
Effect.bind("runFork", ({ fiberSet }) => FiberSet.runtime(fiberSet)<R>()),
|
|
439
|
-
Effect.tap(({ fiberSet, port, runFork, scope }) =>
|
|
440
|
-
options.listen({
|
|
441
|
-
port,
|
|
442
|
-
scope,
|
|
443
|
-
emit(data) {
|
|
444
|
-
runFork(handler(data))
|
|
445
|
-
},
|
|
446
|
-
deferred: fiberSet.deferred as any
|
|
426
|
+
Effect.gen(function*() {
|
|
427
|
+
const scope = yield* Effect.scope
|
|
428
|
+
const port = yield* options.setup({ worker: spawn(id), scope })
|
|
429
|
+
currentPort = port
|
|
430
|
+
yield* Scope.addFinalizer(
|
|
431
|
+
scope,
|
|
432
|
+
Effect.sync(() => {
|
|
433
|
+
currentPort = undefined
|
|
447
434
|
})
|
|
448
|
-
),
|
|
449
|
-
Effect.tap(({ port }) => {
|
|
450
|
-
if (buffer.length > 0) {
|
|
451
|
-
for (const [message, transfers] of buffer) {
|
|
452
|
-
port.postMessage([0, message], transfers as any)
|
|
453
|
-
}
|
|
454
|
-
buffer.length = 0
|
|
455
|
-
}
|
|
456
|
-
}),
|
|
457
|
-
Effect.flatMap(({ fiberSet, scope }) =>
|
|
458
|
-
(restore(FiberSet.join(fiberSet)) as Effect.Effect<never, WorkerError | E>).pipe(
|
|
459
|
-
Effect.ensuring(Scope.close(scope, Exit.void))
|
|
460
|
-
)
|
|
461
435
|
)
|
|
462
|
-
|
|
436
|
+
const runtime = (yield* Effect.runtime<R | Scope.Scope>()).pipe(
|
|
437
|
+
Runtime.updateContext(Context.omit(Scope.Scope))
|
|
438
|
+
) as Runtime.Runtime<R>
|
|
439
|
+
const fiberSet = yield* FiberSet.make<any, WorkerError | E>()
|
|
440
|
+
const runFork = Runtime.runFork(runtime)
|
|
441
|
+
yield* options.listen({
|
|
442
|
+
port,
|
|
443
|
+
scope,
|
|
444
|
+
emit(data) {
|
|
445
|
+
FiberSet.unsafeAdd(runFork(handler(data)))
|
|
446
|
+
},
|
|
447
|
+
deferred: fiberSet.deferred as any
|
|
448
|
+
})
|
|
449
|
+
if (buffer.length > 0) {
|
|
450
|
+
for (const [message, transfers] of buffer) {
|
|
451
|
+
port.postMessage([0, message], transfers as any)
|
|
452
|
+
}
|
|
453
|
+
buffer.length = 0
|
|
454
|
+
}
|
|
455
|
+
return (yield* restore(FiberSet.join(fiberSet))) as never
|
|
456
|
+
}).pipe(Effect.scoped)
|
|
463
457
|
)
|
|
464
458
|
|
|
465
459
|
const send = (message: I, transfers?: ReadonlyArray<unknown>) =>
|
|
@@ -127,7 +127,7 @@ export const make = <I, E, R, O>(
|
|
|
127
127
|
): Effect.Effect<void, WorkerError, WorkerRunner.PlatformRunner | R | Scope.Scope> =>
|
|
128
128
|
Effect.withFiberRuntime<void, never, WorkerRunner.PlatformRunner | R | Scope.Scope>((fiber) =>
|
|
129
129
|
run(process, options).pipe(
|
|
130
|
-
Effect.tapErrorCause(Effect.
|
|
130
|
+
Effect.tapErrorCause((cause) => Cause.isInterruptedOnly(cause) ? Effect.void : Effect.logWarning(cause)),
|
|
131
131
|
Effect.retry(Schedule.spaced(1000)),
|
|
132
132
|
Effect.annotateLogs({
|
|
133
133
|
package: "@effect/platform-node",
|