@livestore/utils 0.4.0 → 0.5.0-dev.0
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/.tsbuildinfo +1 -1
- package/dist/NoopTracer.d.ts +7 -8
- package/dist/NoopTracer.d.ts.map +1 -1
- package/dist/NoopTracer.js +3 -18
- package/dist/NoopTracer.js.map +1 -1
- package/dist/NoopTracer.test.d.ts +2 -0
- package/dist/NoopTracer.test.d.ts.map +1 -0
- package/dist/NoopTracer.test.js +17 -0
- package/dist/NoopTracer.test.js.map +1 -0
- package/dist/browser/Opfs/Opfs.d.ts +179 -29
- package/dist/browser/Opfs/Opfs.d.ts.map +1 -1
- package/dist/browser/Opfs/Opfs.js +132 -307
- package/dist/browser/Opfs/Opfs.js.map +1 -1
- package/dist/browser/Opfs/debug-utils.d.ts.map +1 -1
- package/dist/browser/Opfs/debug-utils.js +5 -4
- package/dist/browser/Opfs/debug-utils.js.map +1 -1
- package/dist/browser/Opfs/utils.d.ts +8 -8
- package/dist/browser/Opfs/utils.d.ts.map +1 -1
- package/dist/browser/Opfs/utils.js +35 -26
- package/dist/browser/Opfs/utils.js.map +1 -1
- package/dist/browser/QuotaExceededError.d.ts +10 -9
- package/dist/browser/QuotaExceededError.d.ts.map +1 -1
- package/dist/browser/WebChannelBrowser.d.ts.map +1 -1
- package/dist/browser/WebChannelBrowser.js +21 -10
- package/dist/browser/WebChannelBrowser.js.map +1 -1
- package/dist/browser/WebError.d.ts +54 -86
- package/dist/browser/WebError.d.ts.map +1 -1
- package/dist/browser/WebError.js +91 -84
- package/dist/browser/WebError.js.map +1 -1
- package/dist/browser/WebError.test.js +6 -6
- package/dist/browser/WebError.test.js.map +1 -1
- package/dist/browser/WebLock.d.ts.map +1 -1
- package/dist/browser/WebLock.js +13 -13
- package/dist/browser/WebLock.js.map +1 -1
- package/dist/effect/Debug.d.ts +4 -7
- package/dist/effect/Debug.d.ts.map +1 -1
- package/dist/effect/Debug.js +32 -36
- package/dist/effect/Debug.js.map +1 -1
- package/dist/effect/Effect.d.ts +31 -22
- package/dist/effect/Effect.d.ts.map +1 -1
- package/dist/effect/Effect.js +51 -47
- package/dist/effect/Effect.js.map +1 -1
- package/dist/effect/Effect.test.d.ts +2 -0
- package/dist/effect/Effect.test.d.ts.map +1 -0
- package/dist/effect/Effect.test.js +72 -0
- package/dist/effect/Effect.test.js.map +1 -0
- package/dist/effect/Error.d.ts +4 -6
- package/dist/effect/Error.d.ts.map +1 -1
- package/dist/effect/Logger.d.ts +0 -6
- package/dist/effect/Logger.d.ts.map +1 -1
- package/dist/effect/Logger.js +0 -32
- package/dist/effect/Logger.js.map +1 -1
- package/dist/effect/OtelTracer.d.ts +1 -1
- package/dist/effect/OtelTracer.d.ts.map +1 -1
- package/dist/effect/OtelTracer.js +2 -3
- package/dist/effect/OtelTracer.js.map +1 -1
- package/dist/effect/RpcClient.d.ts +7 -7
- package/dist/effect/RpcClient.d.ts.map +1 -1
- package/dist/effect/RpcClient.js +72 -52
- package/dist/effect/RpcClient.js.map +1 -1
- package/dist/effect/Schedule.d.ts +1 -1
- package/dist/effect/Schedule.d.ts.map +1 -1
- package/dist/effect/Schedule.js +2 -2
- package/dist/effect/Schedule.js.map +1 -1
- package/dist/effect/Schema/debug-diff.d.ts +1 -1
- package/dist/effect/Schema/debug-diff.d.ts.map +1 -1
- package/dist/effect/Schema/debug-diff.js +5 -7
- package/dist/effect/Schema/debug-diff.js.map +1 -1
- package/dist/effect/Schema/debug-diff.test.js +7 -4
- package/dist/effect/Schema/debug-diff.test.js.map +1 -1
- package/dist/effect/Schema/index.d.ts +28 -20
- package/dist/effect/Schema/index.d.ts.map +1 -1
- package/dist/effect/Schema/index.js +55 -28
- package/dist/effect/Schema/index.js.map +1 -1
- package/dist/effect/Stream.d.ts +13 -5
- package/dist/effect/Stream.d.ts.map +1 -1
- package/dist/effect/Stream.js +19 -12
- package/dist/effect/Stream.js.map +1 -1
- package/dist/effect/Stream.test.js +9 -9
- package/dist/effect/Stream.test.js.map +1 -1
- package/dist/effect/Subscribable.d.ts +9 -3
- package/dist/effect/Subscribable.d.ts.map +1 -1
- package/dist/effect/Subscribable.js +20 -35
- package/dist/effect/Subscribable.js.map +1 -1
- package/dist/effect/SubscriptionRef.d.ts +5 -6
- package/dist/effect/SubscriptionRef.d.ts.map +1 -1
- package/dist/effect/SubscriptionRef.js +2 -3
- package/dist/effect/SubscriptionRef.js.map +1 -1
- package/dist/effect/TaskTracing.d.ts +1 -1
- package/dist/effect/TaskTracing.d.ts.map +1 -1
- package/dist/effect/TaskTracing.js +12 -16
- package/dist/effect/TaskTracing.js.map +1 -1
- package/dist/effect/WebChannel/WebChannel.d.ts +7 -7
- package/dist/effect/WebChannel/WebChannel.d.ts.map +1 -1
- package/dist/effect/WebChannel/WebChannel.js +64 -43
- package/dist/effect/WebChannel/WebChannel.js.map +1 -1
- package/dist/effect/WebChannel/WebChannel.test.js +15 -15
- package/dist/effect/WebChannel/WebChannel.test.js.map +1 -1
- package/dist/effect/WebChannel/broadcastChannelWithAck.d.ts.map +1 -1
- package/dist/effect/WebChannel/broadcastChannelWithAck.js +16 -9
- package/dist/effect/WebChannel/broadcastChannelWithAck.js.map +1 -1
- package/dist/effect/WebChannel/common.d.ts +16 -17
- package/dist/effect/WebChannel/common.d.ts.map +1 -1
- package/dist/effect/WebChannel/common.js +6 -6
- package/dist/effect/WebChannel/common.js.map +1 -1
- package/dist/effect/WebSocket.d.ts +4 -6
- package/dist/effect/WebSocket.d.ts.map +1 -1
- package/dist/effect/WebSocket.js +4 -4
- package/dist/effect/WebSocket.js.map +1 -1
- package/dist/effect/WebSocket.test.js +2 -2
- package/dist/effect/WebSocket.test.js.map +1 -1
- package/dist/effect/mod.browser-build.test.d.ts +2 -0
- package/dist/effect/mod.browser-build.test.d.ts.map +1 -0
- package/dist/effect/mod.browser-build.test.js +18 -0
- package/dist/effect/mod.browser-build.test.js.map +1 -0
- package/dist/effect/mod.d.ts +13 -15
- package/dist/effect/mod.d.ts.map +1 -1
- package/dist/effect/mod.js +13 -18
- package/dist/effect/mod.js.map +1 -1
- package/dist/effect/spanEvent.d.ts.map +1 -1
- package/dist/effect/spanEvent.js +2 -2
- package/dist/effect/spanEvent.js.map +1 -1
- package/dist/effect/spanEvent.test.js +10 -13
- package/dist/effect/spanEvent.test.js.map +1 -1
- package/dist/fast-deep-equal.d.ts.map +1 -1
- package/dist/fast-deep-equal.js +1 -2
- package/dist/fast-deep-equal.js.map +1 -1
- package/dist/misc.js +2 -2
- package/dist/misc.js.map +1 -1
- package/dist/mod.d.ts +0 -35
- package/dist/mod.d.ts.map +1 -1
- package/dist/mod.js +0 -8
- package/dist/mod.js.map +1 -1
- package/dist/node/mod.d.ts +17 -11
- package/dist/node/mod.d.ts.map +1 -1
- package/dist/node/mod.js +23 -16
- package/dist/node/mod.js.map +1 -1
- package/dist/object/index.d.ts +0 -9
- package/dist/object/index.d.ts.map +1 -1
- package/dist/object/index.js +0 -9
- package/dist/object/index.js.map +1 -1
- package/dist/string.d.ts +0 -2
- package/dist/string.d.ts.map +1 -1
- package/dist/string.js +0 -2
- package/dist/string.js.map +1 -1
- package/package.json +18 -36
- package/src/NoopTracer.test.ts +20 -0
- package/src/NoopTracer.ts +18 -41
- package/src/browser/Opfs/Opfs.ts +304 -277
- package/src/browser/Opfs/debug-utils.ts +7 -6
- package/src/browser/Opfs/utils.ts +36 -26
- package/src/browser/QuotaExceededError.ts +13 -10
- package/src/browser/WebChannelBrowser.ts +25 -11
- package/src/browser/WebError.test.ts +6 -6
- package/src/browser/WebError.ts +107 -133
- package/src/browser/WebLock.ts +13 -14
- package/src/effect/Debug.ts +66 -59
- package/src/effect/Effect.test.ts +117 -0
- package/src/effect/Effect.ts +84 -71
- package/src/effect/Logger.ts +0 -48
- package/src/effect/OtelTracer.ts +2 -3
- package/src/effect/RpcClient.ts +80 -61
- package/src/effect/Schedule.ts +4 -5
- package/src/effect/Schema/debug-diff.test.ts +6 -6
- package/src/effect/Schema/debug-diff.ts +6 -8
- package/src/effect/Schema/index.ts +122 -61
- package/src/effect/Stream.test.ts +9 -9
- package/src/effect/Stream.ts +23 -16
- package/src/effect/Subscribable.ts +31 -42
- package/src/effect/SubscriptionRef.ts +8 -12
- package/src/effect/TaskTracing.ts +13 -16
- package/src/effect/WebChannel/WebChannel.test.ts +23 -23
- package/src/effect/WebChannel/WebChannel.ts +87 -55
- package/src/effect/WebChannel/broadcastChannelWithAck.ts +21 -11
- package/src/effect/WebChannel/common.ts +14 -15
- package/src/effect/WebSocket.test.ts +2 -2
- package/src/effect/WebSocket.ts +9 -6
- package/src/effect/mod.browser-build.test.ts +19 -0
- package/src/effect/mod.ts +35 -69
- package/src/effect/spanEvent.test.ts +10 -13
- package/src/effect/spanEvent.ts +5 -3
- package/src/fast-deep-equal.ts +1 -2
- package/src/misc.ts +2 -2
- package/src/mod.ts +0 -36
- package/src/node/mod.ts +26 -20
- package/src/object/index.ts +0 -24
- package/src/string.ts +0 -3
- package/dist/effect/BucketQueue.d.ts +0 -20
- package/dist/effect/BucketQueue.d.ts.map +0 -1
- package/dist/effect/BucketQueue.js +0 -34
- package/dist/effect/BucketQueue.js.map +0 -1
- package/dist/effect/Scheduler.d.ts +0 -4
- package/dist/effect/Scheduler.d.ts.map +0 -1
- package/dist/effect/Scheduler.js +0 -9
- package/dist/effect/Scheduler.js.map +0 -1
- package/dist/effect/ServiceContext.d.ts +0 -37
- package/dist/effect/ServiceContext.d.ts.map +0 -1
- package/dist/effect/ServiceContext.js +0 -55
- package/dist/effect/ServiceContext.js.map +0 -1
- package/dist/guards.d.ts +0 -20
- package/dist/guards.d.ts.map +0 -1
- package/dist/guards.js +0 -20
- package/dist/guards.js.map +0 -1
- package/dist/node/ChildProcessRunner/ChildProcessRunner.d.ts +0 -4
- package/dist/node/ChildProcessRunner/ChildProcessRunner.d.ts.map +0 -1
- package/dist/node/ChildProcessRunner/ChildProcessRunner.js +0 -128
- package/dist/node/ChildProcessRunner/ChildProcessRunner.js.map +0 -1
- package/dist/node/ChildProcessRunner/ChildProcessRunnerTest/ChildProcessRunner.test.d.ts +0 -10
- package/dist/node/ChildProcessRunner/ChildProcessRunnerTest/ChildProcessRunner.test.d.ts.map +0 -1
- package/dist/node/ChildProcessRunner/ChildProcessRunnerTest/ChildProcessRunner.test.js +0 -217
- package/dist/node/ChildProcessRunner/ChildProcessRunnerTest/ChildProcessRunner.test.js.map +0 -1
- package/dist/node/ChildProcessRunner/ChildProcessRunnerTest/schema.d.ts +0 -84
- package/dist/node/ChildProcessRunner/ChildProcessRunnerTest/schema.d.ts.map +0 -1
- package/dist/node/ChildProcessRunner/ChildProcessRunnerTest/schema.js +0 -68
- package/dist/node/ChildProcessRunner/ChildProcessRunnerTest/schema.js.map +0 -1
- package/dist/node/ChildProcessRunner/ChildProcessRunnerTest/serializedWorker.d.ts +0 -2
- package/dist/node/ChildProcessRunner/ChildProcessRunnerTest/serializedWorker.d.ts.map +0 -1
- package/dist/node/ChildProcessRunner/ChildProcessRunnerTest/serializedWorker.js +0 -52
- package/dist/node/ChildProcessRunner/ChildProcessRunnerTest/serializedWorker.js.map +0 -1
- package/dist/node/ChildProcessRunner/ChildProcessWorker.d.ts +0 -23
- package/dist/node/ChildProcessRunner/ChildProcessWorker.d.ts.map +0 -1
- package/dist/node/ChildProcessRunner/ChildProcessWorker.js +0 -138
- package/dist/node/ChildProcessRunner/ChildProcessWorker.js.map +0 -1
- package/dist/object/omit.d.ts +0 -3
- package/dist/object/omit.d.ts.map +0 -1
- package/dist/object/omit.js +0 -14
- package/dist/object/omit.js.map +0 -1
- package/dist/object/pick.d.ts +0 -14
- package/dist/object/pick.d.ts.map +0 -1
- package/dist/object/pick.js +0 -17
- package/dist/object/pick.js.map +0 -1
- package/dist/time.d.ts +0 -12
- package/dist/time.d.ts.map +0 -1
- package/dist/time.js +0 -22
- package/dist/time.js.map +0 -1
- package/src/effect/BucketQueue.ts +0 -49
- package/src/effect/Scheduler.ts +0 -13
- package/src/effect/ServiceContext.ts +0 -108
- package/src/guards.ts +0 -23
- package/src/node/ChildProcessRunner/ChildProcessRunner.ts +0 -148
- package/src/node/ChildProcessRunner/ChildProcessRunnerTest/ChildProcessRunner.test.ts +0 -311
- package/src/node/ChildProcessRunner/ChildProcessRunnerTest/schema.ts +0 -78
- package/src/node/ChildProcessRunner/ChildProcessRunnerTest/serializedWorker.ts +0 -65
- package/src/node/ChildProcessRunner/ChildProcessWorker.ts +0 -169
- package/src/object/omit.ts +0 -17
- package/src/object/pick.ts +0 -27
- package/src/time.ts +0 -25
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
// import * as Transferable from '@effect/platform/Transferable'
|
|
2
|
-
import * as Schema from 'effect/Schema';
|
|
3
|
-
export class User extends Schema.Class('User')({
|
|
4
|
-
id: Schema.Number,
|
|
5
|
-
name: Schema.String,
|
|
6
|
-
}) {
|
|
7
|
-
}
|
|
8
|
-
export class GetUserById extends Schema.TaggedRequest()('GetUserById', {
|
|
9
|
-
failure: Schema.Never,
|
|
10
|
-
success: User,
|
|
11
|
-
payload: {
|
|
12
|
-
id: Schema.Number,
|
|
13
|
-
},
|
|
14
|
-
}) {
|
|
15
|
-
}
|
|
16
|
-
export class Person extends Schema.Class('Person')({
|
|
17
|
-
id: Schema.Number,
|
|
18
|
-
name: Schema.String,
|
|
19
|
-
// data: Transferable.Uint8Array,
|
|
20
|
-
data: Schema.Uint8Array,
|
|
21
|
-
}) {
|
|
22
|
-
}
|
|
23
|
-
export class GetPersonById extends Schema.TaggedRequest()('GetPersonById', {
|
|
24
|
-
failure: Schema.Never,
|
|
25
|
-
success: Person,
|
|
26
|
-
payload: {
|
|
27
|
-
id: Schema.Number,
|
|
28
|
-
},
|
|
29
|
-
}) {
|
|
30
|
-
}
|
|
31
|
-
export class RunnerInterrupt extends Schema.TaggedRequest()('RunnerInterrupt', {
|
|
32
|
-
failure: Schema.Never,
|
|
33
|
-
success: Schema.Void,
|
|
34
|
-
payload: {},
|
|
35
|
-
}) {
|
|
36
|
-
}
|
|
37
|
-
export class StartStubbornWorker extends Schema.TaggedRequest()('StartStubbornWorker', {
|
|
38
|
-
failure: Schema.Never,
|
|
39
|
-
success: Schema.Struct({ pid: Schema.Number }),
|
|
40
|
-
payload: { blockDuration: Schema.Number },
|
|
41
|
-
}) {
|
|
42
|
-
}
|
|
43
|
-
export class InitialMessage extends Schema.TaggedRequest()('InitialMessage', {
|
|
44
|
-
failure: Schema.Never,
|
|
45
|
-
success: Schema.Void,
|
|
46
|
-
payload: {
|
|
47
|
-
name: Schema.String,
|
|
48
|
-
data: Schema.Uint8Array,
|
|
49
|
-
// data: Transferable.Uint8Array,
|
|
50
|
-
},
|
|
51
|
-
}) {
|
|
52
|
-
}
|
|
53
|
-
export class GetSpan extends Schema.TaggedRequest()('GetSpan', {
|
|
54
|
-
failure: Schema.Never,
|
|
55
|
-
success: Schema.Struct({
|
|
56
|
-
name: Schema.String,
|
|
57
|
-
traceId: Schema.String,
|
|
58
|
-
spanId: Schema.String,
|
|
59
|
-
parent: Schema.Option(Schema.Struct({
|
|
60
|
-
traceId: Schema.String,
|
|
61
|
-
spanId: Schema.String,
|
|
62
|
-
})),
|
|
63
|
-
}),
|
|
64
|
-
payload: {},
|
|
65
|
-
}) {
|
|
66
|
-
}
|
|
67
|
-
export const WorkerMessage = Schema.Union(GetUserById, GetPersonById, InitialMessage, GetSpan, RunnerInterrupt, StartStubbornWorker);
|
|
68
|
-
//# sourceMappingURL=schema.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../../src/node/ChildProcessRunner/ChildProcessRunnerTest/schema.ts"],"names":[],"mappings":"AAAA,gEAAgE;AAChE,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAEvC,MAAM,OAAO,IAAK,SAAQ,MAAM,CAAC,KAAK,CAAO,MAAM,CAAC,CAAC;IACnD,EAAE,EAAE,MAAM,CAAC,MAAM;IACjB,IAAI,EAAE,MAAM,CAAC,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E,MAAM,CAAC,KAAK;IACrB,OAAO,EAAE,MAAM,CAAC,IAAI;IACpB,OAAO,EAAE;QACP,IAAI,EAAE,MAAM,CAAC,MAAM;QACnB,IAAI,EAAE,MAAM,CAAC,UAAU;QACvB,iCAAiC;KAClC;CACF,CAAC;CAAG;AAEL,MAAM,OAAO,OAAQ,SAAQ,MAAM,CAAC,aAAa,EAAW,CAAC,SAAS,EAAE;IACtE,OAAO,EAAE,MAAM,CAAC,KAAK;IACrB,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC;QACrB,IAAI,EAAE,MAAM,CAAC,MAAM;QACnB,OAAO,EAAE,MAAM,CAAC,MAAM;QACtB,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,MAAM,EAAE,MAAM,CAAC,MAAM,CACnB,MAAM,CAAC,MAAM,CAAC;YACZ,OAAO,EAAE,MAAM,CAAC,MAAM;YACtB,MAAM,EAAE,MAAM,CAAC,MAAM;SACtB,CAAC,CACH;KACF,CAAC;IACF,OAAO,EAAE,EAAE;CACZ,CAAC;CAAG;AAEL,MAAM,CAAC,MAAM,aAAa,GAAG,MAAM,CAAC,KAAK,CACvC,WAAW,EACX,aAAa,EACb,cAAc,EACd,OAAO,EACP,eAAe,EACf,mBAAmB,CACpB,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"serializedWorker.d.ts","sourceRoot":"","sources":["../../../../src/node/ChildProcessRunner/ChildProcessRunnerTest/serializedWorker.ts"],"names":[],"mappings":""}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import * as Runner from '@effect/platform/WorkerRunner';
|
|
2
|
-
import { Context, Effect, Layer, Option, Stream } from 'effect';
|
|
3
|
-
// import { NodeRuntime, NodeWorkerRunner } from '@effect/platform-node'
|
|
4
|
-
import { PlatformNode } from "../../mod.js";
|
|
5
|
-
import * as ChildProcessRunner from "../ChildProcessRunner.js";
|
|
6
|
-
import { Person, User, WorkerMessage } from "./schema.js";
|
|
7
|
-
const Name = Context.GenericTag('Name');
|
|
8
|
-
const WorkerLive = Runner.layerSerialized(WorkerMessage, {
|
|
9
|
-
GetPersonById: (req) => {
|
|
10
|
-
return Stream.make(new Person({ id: req.id, name: 'test', data: new Uint8Array([1, 2, 3]) }), new Person({ id: req.id, name: 'ing', data: new Uint8Array([4, 5, 6]) }));
|
|
11
|
-
},
|
|
12
|
-
GetUserById: (req) => Effect.map(Name, (name) => new User({ id: req.id, name })),
|
|
13
|
-
// InitialMessage: (req) => Layer.succeed(Name, req.name),
|
|
14
|
-
InitialMessage: (req) => Effect.gen(function* () {
|
|
15
|
-
// yield* Effect.addFinalizer(() => Effect.log('closing worker scope'))
|
|
16
|
-
return Layer.succeed(Name, req.name);
|
|
17
|
-
}).pipe(Layer.unwrapScoped),
|
|
18
|
-
// InitialMessage: (req) =>
|
|
19
|
-
// Layer.scoped(
|
|
20
|
-
// Name,
|
|
21
|
-
// Effect.gen(function* () {
|
|
22
|
-
// yield* Effect.addFinalizer(() => Effect.log('closing worker scope'))
|
|
23
|
-
// return req.name
|
|
24
|
-
// }),
|
|
25
|
-
// ),
|
|
26
|
-
GetSpan: Effect.fn('GetSpan')(function* (_) {
|
|
27
|
-
const span = yield* Effect.currentSpan.pipe(Effect.orDie);
|
|
28
|
-
return {
|
|
29
|
-
traceId: span.traceId,
|
|
30
|
-
spanId: span.spanId,
|
|
31
|
-
name: span.name,
|
|
32
|
-
parent: Option.map(span.parent, (span) => ({
|
|
33
|
-
traceId: span.traceId,
|
|
34
|
-
spanId: span.spanId,
|
|
35
|
-
})),
|
|
36
|
-
};
|
|
37
|
-
}),
|
|
38
|
-
RunnerInterrupt: () => Effect.interrupt,
|
|
39
|
-
StartStubbornWorker: ({ blockDuration }) => Effect.gen(function* () {
|
|
40
|
-
// Start a blocking operation that won't respond to normal shutdown signals
|
|
41
|
-
const pid = process.pid;
|
|
42
|
-
yield* Effect.fork(Effect.gen(function* () {
|
|
43
|
-
// Block for the specified duration, ignoring shutdown attempts
|
|
44
|
-
yield* Effect.sleep(`${blockDuration} millis`);
|
|
45
|
-
yield* Effect.log('Stubborn worker finished blocking');
|
|
46
|
-
}).pipe(Effect.uninterruptible));
|
|
47
|
-
return { pid };
|
|
48
|
-
}),
|
|
49
|
-
}).pipe(Layer.provide(ChildProcessRunner.layer));
|
|
50
|
-
// }).pipe(Layer.provide(PlatformNode.NodeWorkerRunner.layer))
|
|
51
|
-
PlatformNode.NodeRuntime.runMain(Runner.launch(WorkerLive));
|
|
52
|
-
//# sourceMappingURL=serializedWorker.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"serializedWorker.js","sourceRoot":"","sources":["../../../../src/node/ChildProcessRunner/ChildProcessRunnerTest/serializedWorker.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,+BAA+B,CAAA;AACvD,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAE/D,wEAAwE;AACxE,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAC3C,OAAO,KAAK,kBAAkB,MAAM,0BAA0B,CAAA;AAC9D,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAKzD,MAAM,IAAI,GAAG,OAAO,CAAC,UAAU,CAAe,MAAM,CAAC,CAAA;AAErD,MAAM,UAAU,GAAG,MAAM,CAAC,eAAe,CAAC,aAAa,EAAE;IACvD,aAAa,EAAE,CAAC,GAAG,EAAE,EAAE;QACrB,OAAO,MAAM,CAAC,IAAI,CAChB,IAAI,MAAM,CAAC,EAAE,EAAE,EAAE,GAAG,CAAC,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EACzE,IAAI,MAAM,CAAC,EAAE,EAAE,EAAE,GAAG,CA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IACH,CAAC,CAAC;IACF,eAAe,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,SAAS;IACvC,mBAAmB,EAAE,CAAC,EAAE,aAAa,EAAE,EAAE,EAAE,CACzC,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;QAClB,2EAA2E;QAC3E,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAA;QACvB,KAAK,CAAC,CAAC,MAAM,CAAC,IAAI,CAChB,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;YAClB,+DAA+D;YAC/D,KAAK,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,aAAa,SAAS,CAAC,CAAA;YAC9C,KAAK,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,mCAAmC,CAAC,CAAA;QACxD,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC,CAChC,CAAA;QACD,OAAO,EAAE,GAAG,EAAE,CAAA;IAChB,CAAC,CAAC;CACL,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC,CAAA;AAChD,8DAA8D;AAE9D,YAAY,CAAC,WAAW,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAA"}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import type * as ChildProcess from 'node:child_process';
|
|
2
|
-
import * as Worker from '@effect/platform/Worker';
|
|
3
|
-
import * as Layer from 'effect/Layer';
|
|
4
|
-
export declare const layerWorker: Layer.Layer<Worker.PlatformWorker, never, never>;
|
|
5
|
-
export declare const layerManager: Layer.Layer<Worker.WorkerManager, never, never>;
|
|
6
|
-
/**
|
|
7
|
-
* @example
|
|
8
|
-
* ```ts
|
|
9
|
-
* import * as ChildProcess from 'node:child_process'
|
|
10
|
-
* import { Effect, Worker } from '@effect/platform/Worker'
|
|
11
|
-
* import { ChildProcessWorker } from '@livestore/utils/node'
|
|
12
|
-
*
|
|
13
|
-
* Worker.makePoolSerialized<WorkerMessage>({
|
|
14
|
-
* size: 1,
|
|
15
|
-
* initialMessage: () => new InitialMessage({ name: 'test', data: new Uint8Array([1, 2, 3]) }),
|
|
16
|
-
* }).pipe(
|
|
17
|
-
* Effect.provide(ChildProcessWorker.layer(() => ChildProcess.fork(new URL('worker.ts', import.meta.url)))),
|
|
18
|
-
* )
|
|
19
|
-
* ```
|
|
20
|
-
*
|
|
21
|
-
*/
|
|
22
|
-
export declare const layer: (spawn: (id: number) => ChildProcess.ChildProcess) => Layer.Layer<Worker.Spawner | Worker.WorkerManager, never, never>;
|
|
23
|
-
//# sourceMappingURL=ChildProcessWorker.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ChildProcessWorker.d.ts","sourceRoot":"","sources":["../../../src/node/ChildProcessRunner/ChildProcessWorker.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,YAAY,MAAM,oBAAoB,CAAA;AAEvD,OAAO,KAAK,MAAM,MAAM,yBAAyB,CAAA;AAKjD,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AA4IrC,eAAO,MAAM,WAAW,kDAA2D,CAAA;AAEnF,eAAO,MAAM,YAAY,iDAAkD,CAAA;AAE3E;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,KAAK,GAAI,OAAO,CAAC,EAAE,EAAE,MAAM,KAAK,YAAY,CAAC,YAAY,qEACf,CAAA"}
|
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
import * as Worker from '@effect/platform/Worker';
|
|
2
|
-
import { WorkerError } from '@effect/platform/WorkerError';
|
|
3
|
-
import * as Deferred from 'effect/Deferred';
|
|
4
|
-
import * as Effect from 'effect/Effect';
|
|
5
|
-
import * as Exit from 'effect/Exit';
|
|
6
|
-
import * as Layer from 'effect/Layer';
|
|
7
|
-
import * as Scope from 'effect/Scope';
|
|
8
|
-
// Track child processes for cleanup on process signals
|
|
9
|
-
const childProcesses = new Set();
|
|
10
|
-
// Force cleanup all tracked child processes
|
|
11
|
-
const forceCleanupChildren = (signal = 'SIGKILL') => {
|
|
12
|
-
for (const child of childProcesses) {
|
|
13
|
-
try {
|
|
14
|
-
if (child.killed === false) {
|
|
15
|
-
child.kill(signal);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
catch {
|
|
19
|
-
// Ignore errors during cleanup
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
childProcesses.clear();
|
|
23
|
-
};
|
|
24
|
-
// Install signal handlers once to clean up all child processes
|
|
25
|
-
let signalHandlersInstalled = false;
|
|
26
|
-
const installSignalHandlers = () => {
|
|
27
|
-
if (signalHandlersInstalled === true)
|
|
28
|
-
return;
|
|
29
|
-
signalHandlersInstalled = true;
|
|
30
|
-
// Use 'beforeExit' instead of signal handlers since tests may interfere with signals
|
|
31
|
-
process.on('beforeExit', () => {
|
|
32
|
-
forceCleanupChildren('SIGKILL');
|
|
33
|
-
});
|
|
34
|
-
// Also try to cleanup on uncaught exceptions
|
|
35
|
-
process.on('uncaughtException', () => {
|
|
36
|
-
forceCleanupChildren('SIGKILL');
|
|
37
|
-
});
|
|
38
|
-
// Install signal handlers but make them more robust
|
|
39
|
-
const sigintHandler = () => {
|
|
40
|
-
forceCleanupChildren('SIGINT');
|
|
41
|
-
};
|
|
42
|
-
const sigtermHandler = () => {
|
|
43
|
-
forceCleanupChildren('SIGTERM');
|
|
44
|
-
};
|
|
45
|
-
const exitHandler = () => {
|
|
46
|
-
forceCleanupChildren('SIGKILL');
|
|
47
|
-
};
|
|
48
|
-
// Add handlers that will persist even if tests remove/add other handlers
|
|
49
|
-
process.prependListener('SIGINT', sigintHandler);
|
|
50
|
-
process.prependListener('SIGTERM', sigtermHandler);
|
|
51
|
-
process.prependListener('exit', exitHandler);
|
|
52
|
-
};
|
|
53
|
-
const platformWorkerImpl = Worker.makePlatform()({
|
|
54
|
-
setup({ scope, worker: childProcess }) {
|
|
55
|
-
return Effect.flatMap(Deferred.make(), (exitDeferred) => {
|
|
56
|
-
// Install signal handlers for process-wide cleanup
|
|
57
|
-
installSignalHandlers();
|
|
58
|
-
// Track this child process for cleanup
|
|
59
|
-
childProcesses.add(childProcess);
|
|
60
|
-
childProcess.on('exit', () => {
|
|
61
|
-
// Remove from tracking when process exits
|
|
62
|
-
childProcesses.delete(childProcess);
|
|
63
|
-
Deferred.unsafeDone(exitDeferred, Exit.void);
|
|
64
|
-
});
|
|
65
|
-
childProcess.send(['setup-parent-death-detection', { parentPid: process.pid }]);
|
|
66
|
-
return Effect.as(Scope.addFinalizer(scope, Effect.suspend(() => {
|
|
67
|
-
// Try graceful shutdown first
|
|
68
|
-
try {
|
|
69
|
-
childProcess.send([1]);
|
|
70
|
-
}
|
|
71
|
-
catch {
|
|
72
|
-
// IPC channel might be closed, proceed to forceful termination
|
|
73
|
-
}
|
|
74
|
-
return Deferred.await(exitDeferred);
|
|
75
|
-
}).pipe(Effect.timeout(3000), // Reduced timeout for faster cleanup
|
|
76
|
-
Effect.interruptible, Effect.catchAllCause(() => Effect.sync(() => {
|
|
77
|
-
// Enhanced cleanup with escalating signals
|
|
78
|
-
if (childProcess.killed === false) {
|
|
79
|
-
try {
|
|
80
|
-
// First try SIGTERM
|
|
81
|
-
childProcess.kill('SIGTERM');
|
|
82
|
-
// If still running after a short delay, use SIGKILL
|
|
83
|
-
setTimeout(() => {
|
|
84
|
-
if (childProcess.killed === false) {
|
|
85
|
-
childProcess.kill('SIGKILL');
|
|
86
|
-
}
|
|
87
|
-
}, 1000);
|
|
88
|
-
}
|
|
89
|
-
catch {
|
|
90
|
-
// Process might already be dead
|
|
91
|
-
}
|
|
92
|
-
finally {
|
|
93
|
-
// Ensure it's removed from tracking
|
|
94
|
-
childProcesses.delete(childProcess);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
})))), {
|
|
98
|
-
postMessage: (message) => childProcess.send(message),
|
|
99
|
-
on: (event, handler) => childProcess.on(event, handler),
|
|
100
|
-
});
|
|
101
|
-
});
|
|
102
|
-
},
|
|
103
|
-
listen({ deferred, emit, port }) {
|
|
104
|
-
port.on('message', (message) => {
|
|
105
|
-
emit(message);
|
|
106
|
-
});
|
|
107
|
-
port.on('messageerror', (cause) => {
|
|
108
|
-
Deferred.unsafeDone(deferred, new WorkerError({ reason: 'decode', cause }));
|
|
109
|
-
});
|
|
110
|
-
port.on('error', (cause) => {
|
|
111
|
-
Deferred.unsafeDone(deferred, new WorkerError({ reason: 'unknown', cause }));
|
|
112
|
-
});
|
|
113
|
-
port.on('exit', (code) => {
|
|
114
|
-
Deferred.unsafeDone(deferred, new WorkerError({ reason: 'unknown', cause: new Error(`exited with code ${code}`) }));
|
|
115
|
-
});
|
|
116
|
-
return Effect.void;
|
|
117
|
-
},
|
|
118
|
-
});
|
|
119
|
-
export const layerWorker = Layer.succeed(Worker.PlatformWorker, platformWorkerImpl);
|
|
120
|
-
export const layerManager = Layer.provide(Worker.layerManager, layerWorker);
|
|
121
|
-
/**
|
|
122
|
-
* @example
|
|
123
|
-
* ```ts
|
|
124
|
-
* import * as ChildProcess from 'node:child_process'
|
|
125
|
-
* import { Effect, Worker } from '@effect/platform/Worker'
|
|
126
|
-
* import { ChildProcessWorker } from '@livestore/utils/node'
|
|
127
|
-
*
|
|
128
|
-
* Worker.makePoolSerialized<WorkerMessage>({
|
|
129
|
-
* size: 1,
|
|
130
|
-
* initialMessage: () => new InitialMessage({ name: 'test', data: new Uint8Array([1, 2, 3]) }),
|
|
131
|
-
* }).pipe(
|
|
132
|
-
* Effect.provide(ChildProcessWorker.layer(() => ChildProcess.fork(new URL('worker.ts', import.meta.url)))),
|
|
133
|
-
* )
|
|
134
|
-
* ```
|
|
135
|
-
*
|
|
136
|
-
*/
|
|
137
|
-
export const layer = (spawn) => Layer.merge(layerManager, Worker.layerSpawner(spawn));
|
|
138
|
-
//# sourceMappingURL=ChildProcessWorker.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ChildProcess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M,KAAK,GAAG,CAAC,KAAgD,EAAE,EAAE,CACxE,KAAK,CAAC,KAAK,CAAC,YAAY,EAAE,MAAM,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAA"}
|
package/dist/object/omit.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"omit.d.ts","sourceRoot":"","sources":["../../src/object/omit.ts"],"names":[],"mappings":"AAKA,uEAAuE;AACvE,eAAO,MAAM,IAAI,GAAI,GAAG,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,IAAI,SAAS,MAAM,GAAG,EAC1E,KAAK,GAAG,EACR,MAAM,IAAI,EAAE,KACX,IAAI,CAAC,GAAG,EAAE,IAAI,CAOhB,CAAA"}
|
package/dist/object/omit.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
// type ConvertUndefined<T> = OrUndefined<{ [K in keyof T as undefined extends T[K] ? K : never]-?: T[K] }>
|
|
2
|
-
// type OrUndefined<T> = { [K in keyof T]: T[K] | undefined }
|
|
3
|
-
// type PickRequired<T> = { [K in keyof T as undefined extends T[K] ? never : K]: T[K] }
|
|
4
|
-
// type ConvertPick<T> = ConvertUndefined<T> & PickRequired<T>
|
|
5
|
-
/** Returns a shallowly cloned object with the provided keys omitted */
|
|
6
|
-
export const omit = (obj, keys) => {
|
|
7
|
-
return Object.keys(obj).reduce((acc, key) => {
|
|
8
|
-
if (keys.includes(key) === false) {
|
|
9
|
-
acc[key] = obj[key];
|
|
10
|
-
}
|
|
11
|
-
return acc;
|
|
12
|
-
}, {});
|
|
13
|
-
};
|
|
14
|
-
//# sourceMappingURL=omit.js.map
|
package/dist/object/omit.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"omit.js","sourceRoot":"","sources":["../../src/object/omit.ts"],"names":[],"mappings":"AAAA,2GAA2G;AAC3G,6DAA6D;AAC7D,wFAAwF;AACxF,8DAA8D;AAE9D,uEAAuE;AACvE,MAAM,CAAC,MAAM,IAAI,GAAG,CAClB,GAAQ,EACR,IAAY,EACK,EAAE;IACnB,OAAO,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,GAAQ,EAAE,EAAE;QAC/C,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,KAAK,EAAE,CAAC;YACjC,GAAG,CAAC,GAAG,CAAC,GAAI,GAAW,CAAC,GAAG,CAAC,CAAA;QAC9B,CAAC;QACD,OAAO,GAAG,CAAA;IACZ,CAAC,EAAE,EAAS,CAAC,CAAA;AACf,CAAC,CAAA"}
|
package/dist/object/pick.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
type ConvertUndefined<T> = OrUndefined<{
|
|
2
|
-
[K in keyof T as undefined extends T[K] ? K : never]-?: T[K];
|
|
3
|
-
}>;
|
|
4
|
-
type OrUndefined<T> = {
|
|
5
|
-
[K in keyof T]: T[K] | undefined;
|
|
6
|
-
};
|
|
7
|
-
type PickRequired<T> = {
|
|
8
|
-
[K in keyof T as undefined extends T[K] ? never : K]: T[K];
|
|
9
|
-
};
|
|
10
|
-
type ConvertPick<T> = ConvertUndefined<T> & PickRequired<T>;
|
|
11
|
-
export declare const pick: <Obj, Keys extends keyof Obj>(obj: Obj, keys: Keys[]) => ConvertPick<{ [K in Keys]: Obj[K]; }>;
|
|
12
|
-
export declare const pickAllOrElse: <Obj, Keys extends keyof Obj, TElse>(obj: Obj, keys: Keys[], elseValue: TElse) => ConvertPick<{ [K in Keys]: NonNullable<Obj[K]>; }> | TElse;
|
|
13
|
-
export {};
|
|
14
|
-
//# sourceMappingURL=pick.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"pick.d.ts","sourceRoot":"","sources":["../../src/object/pick.ts"],"names":[],"mappings":"AAAA,KAAK,gBAAgB,CAAC,CAAC,IAAI,WAAW,CAAC;KAAG,CAAC,IAAI,MAAM,CAAC,IAAI,SAAS,SAAS,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAAE,CAAC,CAAA;AACxG,KAAK,WAAW,CAAC,CAAC,IAAI;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,SAAS;CAAE,CAAA;AAC1D,KAAK,YAAY,CAAC,CAAC,IAAI;KAAG,CAAC,IAAI,MAAM,CAAC,IAAI,SAAS,SAAS,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAAE,CAAA;AACrF,KAAK,WAAW,CAAC,CAAC,IAAI,gBAAgB,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAAA;AAE3D,eAAO,MAAM,IAAI,GAAI,GAAG,EAAE,IAAI,SAAS,MAAM,GAAG,EAAE,KAAK,GAAG,EAAE,MAAM,IAAI,EAAE,KAAG,WAAW,CAAC,GAAG,CAAC,IAAI,IAAI,GAAG,GAAG,CAAC,CAAC,CAAC,GAAE,CAK7G,CAAA;AAED,eAAO,MAAM,aAAa,GAAI,GAAG,EAAE,IAAI,SAAS,MAAM,GAAG,EAAE,KAAK,EAC9D,KAAK,GAAG,EACR,MAAM,IAAI,EAAE,EACZ,WAAW,KAAK,KACf,WAAW,CAAC,GAAG,CAAC,IAAI,IAAI,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAE,CAAC,GAAG,KAUtD,CAAA"}
|
package/dist/object/pick.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export const pick = (obj, keys) => {
|
|
2
|
-
return keys.reduce((acc, key) => {
|
|
3
|
-
acc[key] = obj[key];
|
|
4
|
-
return acc;
|
|
5
|
-
}, {});
|
|
6
|
-
};
|
|
7
|
-
export const pickAllOrElse = (obj, keys, elseValue) => {
|
|
8
|
-
const ret = {};
|
|
9
|
-
for (const key of keys) {
|
|
10
|
-
if (obj[key] === undefined) {
|
|
11
|
-
return elseValue;
|
|
12
|
-
}
|
|
13
|
-
ret[key] = obj[key];
|
|
14
|
-
}
|
|
15
|
-
return ret;
|
|
16
|
-
};
|
|
17
|
-
//# sourceMappingURL=pick.js.map
|
package/dist/object/pick.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"pick.js","sourceRoot":"","sources":["../../src/object/pick.ts"],"names":[],"mappings":"AAKA,MAAM,CAAC,MAAM,IAAI,GAAG,CAA8B,GAAQ,EAAE,IAAY,EAAwC,EAAE;IAChH,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;QAC9B,GAAG,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,GAAG,CAAC,CAAA;QACnB,OAAO,GAAG,CAAA;IACZ,CAAC,EAAE,EAAS,CAAC,CAAA;AACf,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,aAAa,GAAG,CAC3B,GAAQ,EACR,IAAY,EACZ,SAAgB,EAC2C,EAAE;IAC7D,MAAM,GAAG,GAAG,EAAS,CAAA;IACrB,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,IAAI,GAAG,CAAC,GAAG,CAAC,KAAK,SAAS,EAAE,CAAC;YAC3B,OAAO,SAAS,CAAA;QAClB,CAAC;QACD,GAAG,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,GAAG,CAAC,CAAA;IACrB,CAAC;IAED,OAAO,GAAG,CAAA;AACZ,CAAC,CAAA"}
|
package/dist/time.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export declare const minuteInMs: number;
|
|
2
|
-
export declare const time: {
|
|
3
|
-
ms: number;
|
|
4
|
-
sec: number;
|
|
5
|
-
min: number;
|
|
6
|
-
hour: number;
|
|
7
|
-
day: number;
|
|
8
|
-
week: number;
|
|
9
|
-
};
|
|
10
|
-
/** Returns a string of format `m:ss` / `mm:ss` / `h:mm:ss` / ... */
|
|
11
|
-
export declare const msAsTimeString: (ms: number) => string;
|
|
12
|
-
//# sourceMappingURL=time.d.ts.map
|
package/dist/time.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"time.d.ts","sourceRoot":"","sources":["../src/time.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,UAAU,QAAY,CAAA;AAEnC,eAAO,MAAM,IAAI;;;;;;;CAOhB,CAAA;AAED,oEAAoE;AACpE,eAAO,MAAM,cAAc,GAAI,IAAI,MAAM,WAYxC,CAAA"}
|
package/dist/time.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
export const minuteInMs = 1000 * 60;
|
|
2
|
-
export const time = {
|
|
3
|
-
ms: 1,
|
|
4
|
-
sec: 1000,
|
|
5
|
-
min: 60 * 1000,
|
|
6
|
-
hour: 60 * 60 * 1000,
|
|
7
|
-
day: 24 * 60 * 60 * 1000,
|
|
8
|
-
week: 7 * 24 * 60 * 60 * 1000,
|
|
9
|
-
};
|
|
10
|
-
/** Returns a string of format `m:ss` / `mm:ss` / `h:mm:ss` / ... */
|
|
11
|
-
export const msAsTimeString = (ms) => {
|
|
12
|
-
const seconds = Math.floor(ms / 1000);
|
|
13
|
-
const minutes = Math.floor(seconds / 60);
|
|
14
|
-
const hours = Math.floor(minutes / 60);
|
|
15
|
-
const remainingSeconds = (seconds % 60).toString().padStart(2, '0');
|
|
16
|
-
const remainingMinutes = hours > 0 ? (minutes % 60).toString().padStart(2, '0') : minutes % 60;
|
|
17
|
-
const timeString = [hours > 0 ? `${hours}:` : '', `${remainingMinutes}:`, remainingSeconds]
|
|
18
|
-
.filter((val) => val !== '')
|
|
19
|
-
.join('');
|
|
20
|
-
return timeString;
|
|
21
|
-
};
|
|
22
|
-
//# sourceMappingURL=time.js.map
|
package/dist/time.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version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AAC,GAAG,EAAE,EAAE,CAAC,GAAG,KAAK,EAAE,CAAC;SAC3B,IAAI,CAAC,EAAE,CAAC,CAAA;IAEX,OAAO,UAAU,CAAA;AACnB,CAAC,CAAA"}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { Array, Effect, STM, TRef } from 'effect'
|
|
2
|
-
|
|
3
|
-
export type BucketQueue<A> = TRef.TRef<A[]>
|
|
4
|
-
|
|
5
|
-
export const make = <A>(): STM.STM<BucketQueue<A>> => TRef.make<A[]>([])
|
|
6
|
-
|
|
7
|
-
export const offerAll = <A>(self: BucketQueue<A>, elements: ReadonlyArray<A>) =>
|
|
8
|
-
TRef.update(self, (bucket) => Array.appendAll(bucket, elements))
|
|
9
|
-
|
|
10
|
-
export const replace = <A>(self: BucketQueue<A>, elements: ReadonlyArray<A>) => TRef.set(self, elements as A[])
|
|
11
|
-
|
|
12
|
-
export const clear = <A>(self: BucketQueue<A>) => TRef.set(self, [])
|
|
13
|
-
|
|
14
|
-
export const takeBetween = <A>(
|
|
15
|
-
bucket: BucketQueue<A>,
|
|
16
|
-
min: number,
|
|
17
|
-
max: number,
|
|
18
|
-
): STM.STM<ReadonlyArray<A>> =>
|
|
19
|
-
STM.gen(function* () {
|
|
20
|
-
const bucketValue = yield* TRef.get(bucket)
|
|
21
|
-
if (bucketValue.length < min) {
|
|
22
|
-
return yield* STM.retry
|
|
23
|
-
} else {
|
|
24
|
-
const elements = bucketValue.splice(0, Math.min(max, bucketValue.length))
|
|
25
|
-
yield* TRef.set(bucket, bucketValue)
|
|
26
|
-
return elements
|
|
27
|
-
}
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
export const peekAll = <A>(bucket: BucketQueue<A>) => TRef.get(bucket)
|
|
31
|
-
|
|
32
|
-
/** Returns the elements up to the first element that matches the predicate, the rest is left in the queue
|
|
33
|
-
*
|
|
34
|
-
* @example
|
|
35
|
-
* ```ts
|
|
36
|
-
* const [elements, rest] = yield* BucketQueue.takeSplitWhere(bucket, (a) => a > 3)
|
|
37
|
-
* assert.deepStrictEqual(elements, [1, 2, 3])
|
|
38
|
-
* assert.deepStrictEqual(rest, [4, 5, 6])
|
|
39
|
-
* ```
|
|
40
|
-
*/
|
|
41
|
-
export const takeSplitWhere = <A>(bucket: BucketQueue<A>, predicate: (a: A) => boolean) =>
|
|
42
|
-
STM.gen(function* () {
|
|
43
|
-
const bucketValue = yield* TRef.get(bucket)
|
|
44
|
-
const [elements, rest] = Array.splitWhere(bucketValue, predicate)
|
|
45
|
-
yield* TRef.set(bucket, rest)
|
|
46
|
-
return elements
|
|
47
|
-
})
|
|
48
|
-
|
|
49
|
-
export const size = <A>(bucket: BucketQueue<A>) => TRef.get(bucket).pipe(Effect.map((_) => _.length))
|
package/src/effect/Scheduler.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export * from 'effect/Scheduler'
|
|
2
|
-
|
|
3
|
-
import { Scheduler } from 'effect'
|
|
4
|
-
|
|
5
|
-
// Based on https://github.com/astoilkov/main-thread-scheduling/blob/4b99c26ab96781bc35a331f5c225ad9c8a62cb95/src/utils/waitNextTask.ts#L25
|
|
6
|
-
export const messageChannel = (shouldYield: Scheduler.Scheduler['shouldYield'] = Scheduler.defaultShouldYield) =>
|
|
7
|
-
Scheduler.makeBatched((task) => {
|
|
8
|
-
const messageChannel = new MessageChannel()
|
|
9
|
-
|
|
10
|
-
messageChannel.port1.postMessage(undefined)
|
|
11
|
-
|
|
12
|
-
messageChannel.port2.onmessage = task
|
|
13
|
-
}, shouldYield)
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
import type { Runtime } from 'effect'
|
|
2
|
-
import { Cause, Effect, Exit, Fiber, Layer, pipe, Scope } from 'effect'
|
|
3
|
-
|
|
4
|
-
export interface MainLayer<Ctx> {
|
|
5
|
-
layer: Layer.Layer<Ctx>
|
|
6
|
-
close: Effect.Effect<void>
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export const unsafeMainLayer = <Ctx>(original: Layer.Layer<Ctx>): MainLayer<Ctx> => {
|
|
10
|
-
const scope = Effect.runSync(Scope.make())
|
|
11
|
-
const layer = pipe(
|
|
12
|
-
original,
|
|
13
|
-
Layer.memoize,
|
|
14
|
-
Effect.parallelFinalizers, // NOTE this runs the layer teardown in parallel
|
|
15
|
-
Effect.provideService(Scope.Scope, scope),
|
|
16
|
-
Effect.runSync,
|
|
17
|
-
)
|
|
18
|
-
return { layer, close: Scope.close(scope, Exit.void) }
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export const make = <TStaticData, Ctx>(
|
|
22
|
-
staticData: TStaticData,
|
|
23
|
-
runtime: Runtime.Runtime<Ctx>,
|
|
24
|
-
close: Effect.Effect<void> = Effect.dieMessage('close not implemented'),
|
|
25
|
-
): ServiceContext<Ctx, TStaticData> => {
|
|
26
|
-
return {
|
|
27
|
-
provide: (self) => self.pipe(Effect.provide(runtime)),
|
|
28
|
-
runWithErrorLog: <E, A>(self: Effect.Effect<A, E, Ctx>) => runWithErrorLog(self.pipe(Effect.provide(runtime))),
|
|
29
|
-
runSync: <E, A>(self: Effect.Effect<A, E, Ctx>) => Effect.runSync(self.pipe(Effect.provide(runtime))),
|
|
30
|
-
runPromiseWithErrorLog: <E, A>(self: Effect.Effect<A, E, Ctx>) =>
|
|
31
|
-
runPromiseWithErrorLog(self.pipe(Effect.provide(runtime))),
|
|
32
|
-
runPromiseExit: <E, A>(self: Effect.Effect<A, E, Ctx>) => Effect.runPromiseExit(self.pipe(Effect.provide(runtime))),
|
|
33
|
-
runPromise: <E, A>(self: Effect.Effect<A, E, Ctx>) => Effect.runPromise(self.pipe(Effect.provide(runtime))),
|
|
34
|
-
withRuntime: (fn) => fn(runtime),
|
|
35
|
-
close: close,
|
|
36
|
-
closePromise: () => Effect.runPromise(close),
|
|
37
|
-
staticData,
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export interface ServiceContext<Ctx, TStaticData> {
|
|
42
|
-
readonly provide: <E, A>(self: Effect.Effect<A, E, Ctx>) => Effect.Effect<A, E>
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Fire and Forget. Errors are logged however.
|
|
46
|
-
*/
|
|
47
|
-
readonly runWithErrorLog: <E, A>(self: Effect.Effect<A, E, Ctx>) => AbortCallback
|
|
48
|
-
|
|
49
|
-
readonly runSync: <E, A>(self: Effect.Effect<A, E, Ctx>) => A
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Fire and Forget. A promise that never fails nor returns any value.
|
|
53
|
-
* Errors are logged however.
|
|
54
|
-
*/
|
|
55
|
-
readonly runPromiseWithErrorLog: <E, A>(self: Effect.Effect<A, E, Ctx>) => Promise<A | undefined>
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* A Promise that never fails, the Resolved value is an Exit result that can be either Success or Failed
|
|
59
|
-
*/
|
|
60
|
-
readonly runPromiseExit: <E, A>(self: Effect.Effect<A, E, Ctx>) => Promise<Exit.Exit<A, E>>
|
|
61
|
-
readonly runPromise: <E, A>(self: Effect.Effect<A, E, Ctx>) => Promise<A>
|
|
62
|
-
|
|
63
|
-
readonly withRuntime: (fn: (runtime: Runtime.Runtime<Ctx>) => void) => void
|
|
64
|
-
|
|
65
|
-
/** Closes the ServiceContext and closing all its layers */
|
|
66
|
-
readonly close: Effect.Effect<void>
|
|
67
|
-
readonly closePromise: () => Promise<void>
|
|
68
|
-
readonly staticData: TStaticData
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export type AbortCallback = () => void
|
|
72
|
-
|
|
73
|
-
export const runWithErrorLog = <E, A>(self: Effect.Effect<A, E>) => {
|
|
74
|
-
const fiber = Effect.runFork(self)
|
|
75
|
-
fiber.addObserver((ex) => {
|
|
76
|
-
if (ex._tag === 'Failure' && Cause.isInterruptedOnly(ex.cause) === false) {
|
|
77
|
-
console.error(Cause.pretty(ex.cause))
|
|
78
|
-
}
|
|
79
|
-
})
|
|
80
|
-
return () => {
|
|
81
|
-
Effect.runFork(Fiber.interrupt(fiber))
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
export const runPromiseWithErrorLog = <E, A>(self: Effect.Effect<A, E>) =>
|
|
86
|
-
Effect.runPromiseExit(self).then((ex) => {
|
|
87
|
-
if (ex._tag === 'Failure') {
|
|
88
|
-
console.error(Cause.pretty(ex.cause))
|
|
89
|
-
return undefined
|
|
90
|
-
} else {
|
|
91
|
-
return ex.value
|
|
92
|
-
}
|
|
93
|
-
})
|
|
94
|
-
|
|
95
|
-
export const MissingContext = Effect.die('service context not provided, wrap your app in LiveServiceContext')
|
|
96
|
-
|
|
97
|
-
export const empty = <Ctx, TStaticData>(): ServiceContext<Ctx, TStaticData> => ({
|
|
98
|
-
provide: () => MissingContext,
|
|
99
|
-
runWithErrorLog: () => runWithErrorLog(MissingContext),
|
|
100
|
-
runSync: () => Effect.runSync(MissingContext),
|
|
101
|
-
runPromiseWithErrorLog: () => runPromiseWithErrorLog(MissingContext),
|
|
102
|
-
runPromiseExit: () => Effect.runPromiseExit(MissingContext),
|
|
103
|
-
runPromise: () => Effect.runPromise(MissingContext),
|
|
104
|
-
withRuntime: () => Effect.runSync(MissingContext),
|
|
105
|
-
close: Effect.dieMessage('Empty ServiceContext cannot be closed'),
|
|
106
|
-
closePromise: () => Promise.reject('Empty ServiceContext cannot be closed'),
|
|
107
|
-
staticData: {} as TStaticData,
|
|
108
|
-
})
|
package/src/guards.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/** Type guard that narrows `T | undefined` to `T`. Useful for filtering arrays. */
|
|
2
|
-
export const isNotUndefined = <T>(_: T | undefined): _ is T => _ !== undefined
|
|
3
|
-
|
|
4
|
-
/** Type guard that narrows `T | null` to `T`. */
|
|
5
|
-
export const isNotNull = <T>(_: T | null): _ is T => _ !== null
|
|
6
|
-
|
|
7
|
-
/** Type guard that checks if a value is `undefined`. */
|
|
8
|
-
export const isUndefined = <T>(_: T | undefined): _ is undefined => _ === undefined
|
|
9
|
-
|
|
10
|
-
/** Type guard that checks if a value is `null` or `undefined`. */
|
|
11
|
-
export const isNil = (val: any): val is null | undefined => val === null || val === undefined
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Type guard that narrows `T | undefined | null` to `T`.
|
|
15
|
-
* Commonly used to filter out nullish values from arrays.
|
|
16
|
-
*
|
|
17
|
-
* @example
|
|
18
|
-
* ```ts
|
|
19
|
-
* const values = [1, null, 2, undefined, 3]
|
|
20
|
-
* const nonNil = values.filter(isNotNil) // [1, 2, 3] (type: number[])
|
|
21
|
-
* ```
|
|
22
|
-
*/
|
|
23
|
-
export const isNotNil = <T>(val: T | undefined | null): val is T => val !== null && val !== undefined
|