@livestore/utils 0.4.0-dev.9 → 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 -0
- package/dist/NoopTracer.d.ts +7 -8
- package/dist/NoopTracer.d.ts.map +1 -1
- package/dist/NoopTracer.js +13 -15
- 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/binary.js +1 -1
- package/dist/binary.js.map +1 -1
- package/dist/browser/Opfs/Opfs.d.ts +201 -0
- package/dist/browser/Opfs/Opfs.d.ts.map +1 -0
- package/dist/browser/Opfs/Opfs.js +170 -0
- package/dist/browser/Opfs/Opfs.js.map +1 -0
- package/dist/browser/Opfs/debug-utils.d.ts +20 -0
- package/dist/browser/Opfs/debug-utils.d.ts.map +1 -0
- package/dist/browser/Opfs/debug-utils.js +95 -0
- package/dist/browser/Opfs/debug-utils.js.map +1 -0
- package/dist/browser/Opfs/mod.d.ts +4 -0
- package/dist/browser/Opfs/mod.d.ts.map +1 -0
- package/dist/browser/Opfs/mod.js +4 -0
- package/dist/browser/Opfs/mod.js.map +1 -0
- package/dist/browser/Opfs/utils.d.ts +71 -0
- package/dist/browser/Opfs/utils.d.ts.map +1 -0
- package/dist/browser/Opfs/utils.js +227 -0
- package/dist/browser/Opfs/utils.js.map +1 -0
- package/dist/browser/QuotaExceededError.d.ts +60 -0
- package/dist/browser/QuotaExceededError.d.ts.map +1 -0
- package/dist/browser/QuotaExceededError.js +2 -0
- package/dist/browser/QuotaExceededError.js.map +1 -0
- package/dist/browser/WebChannelBrowser.d.ts +22 -0
- package/dist/browser/WebChannelBrowser.d.ts.map +1 -0
- package/dist/browser/WebChannelBrowser.js +87 -0
- package/dist/browser/WebChannelBrowser.js.map +1 -0
- package/dist/browser/WebError.d.ts +389 -0
- package/dist/browser/WebError.d.ts.map +1 -0
- package/dist/browser/WebError.js +423 -0
- package/dist/browser/WebError.js.map +1 -0
- package/dist/browser/WebError.test.d.ts +2 -0
- package/dist/browser/WebError.test.d.ts.map +1 -0
- package/dist/browser/WebError.test.js +46 -0
- package/dist/browser/WebError.test.js.map +1 -0
- package/dist/browser/WebLock.d.ts.map +1 -0
- package/dist/{effect → browser}/WebLock.js +21 -21
- package/dist/browser/WebLock.js.map +1 -0
- package/dist/{browser.d.ts → browser/detect.d.ts} +1 -1
- package/dist/browser/detect.d.ts.map +1 -0
- package/dist/{browser.js → browser/detect.js} +7 -7
- package/dist/browser/detect.js.map +1 -0
- package/dist/browser/mod.d.ts +8 -0
- package/dist/browser/mod.d.ts.map +1 -0
- package/dist/browser/mod.js +8 -0
- package/dist/browser/mod.js.map +1 -0
- package/dist/cuid/cuid.browser.js +1 -1
- package/dist/cuid/cuid.browser.js.map +1 -1
- package/dist/cuid/cuid.node.js +1 -1
- package/dist/cuid/cuid.node.js.map +1 -1
- package/dist/effect/Debug.d.ts +38 -0
- package/dist/effect/Debug.d.ts.map +1 -0
- package/dist/effect/Debug.js +350 -0
- package/dist/effect/Debug.js.map +1 -0
- package/dist/effect/Effect.d.ts +91 -22
- package/dist/effect/Effect.d.ts.map +1 -1
- package/dist/effect/Effect.js +126 -38
- 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/Error.js +1 -1
- package/dist/effect/Error.js.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 +74 -54
- 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 +9 -10
- 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 -18
- 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 +12 -12
- 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 +11 -30
- package/dist/effect/WebChannel/WebChannel.d.ts.map +1 -1
- package/dist/effect/WebChannel/WebChannel.js +70 -125
- package/dist/effect/WebChannel/WebChannel.js.map +1 -1
- package/dist/effect/WebChannel/WebChannel.test.js +16 -16
- 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 +20 -13
- package/dist/effect/WebChannel/broadcastChannelWithAck.js.map +1 -1
- package/dist/effect/WebChannel/common.d.ts +17 -18
- package/dist/effect/WebChannel/common.d.ts.map +1 -1
- package/dist/effect/WebChannel/common.js +7 -7
- 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 +17 -17
- 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 +30 -0
- package/dist/effect/mod.d.ts.map +1 -0
- package/dist/effect/mod.js +30 -0
- package/dist/effect/mod.js.map +1 -0
- package/dist/effect/spanEvent.d.ts +12 -0
- package/dist/effect/spanEvent.d.ts.map +1 -0
- package/dist/effect/spanEvent.js +12 -0
- package/dist/effect/spanEvent.js.map +1 -0
- package/dist/effect/spanEvent.test.d.ts +2 -0
- package/dist/effect/spanEvent.test.d.ts.map +1 -0
- package/dist/effect/spanEvent.test.js +79 -0
- package/dist/effect/spanEvent.test.js.map +1 -0
- package/dist/env.d.ts.map +1 -1
- package/dist/env.js +1 -1
- package/dist/env.js.map +1 -1
- package/dist/fast-deep-equal.d.ts.map +1 -1
- package/dist/fast-deep-equal.js +9 -10
- package/dist/fast-deep-equal.js.map +1 -1
- package/dist/global.d.ts +3 -0
- package/dist/global.d.ts.map +1 -1
- package/dist/global.js.map +1 -1
- package/dist/misc.d.ts +9 -1
- package/dist/misc.d.ts.map +1 -1
- package/dist/misc.js +12 -4
- package/dist/misc.js.map +1 -1
- package/dist/mod.d.ts +177 -20
- package/dist/mod.d.ts.map +1 -1
- package/dist/mod.js +159 -22
- package/dist/mod.js.map +1 -1
- package/dist/node/mod.d.ts +45 -6
- package/dist/node/mod.d.ts.map +1 -1
- package/dist/node/mod.js +51 -9
- 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/object/stringify-object.js +2 -2
- package/dist/object/stringify-object.js.map +1 -1
- package/dist/object/stringify-object.test.js.map +1 -1
- package/dist/qr.d.ts +38 -0
- package/dist/qr.d.ts.map +1 -0
- package/dist/qr.js +109 -0
- package/dist/qr.js.map +1 -0
- package/dist/set.js +1 -1
- package/dist/set.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 +61 -55
- package/src/NoopTracer.test.ts +20 -0
- package/src/NoopTracer.ts +28 -37
- package/src/binary.ts +1 -1
- package/src/browser/Opfs/Opfs.ts +463 -0
- package/src/browser/Opfs/debug-utils.ts +154 -0
- package/src/browser/Opfs/mod.ts +3 -0
- package/src/browser/Opfs/utils.ts +297 -0
- package/src/browser/QuotaExceededError.ts +60 -0
- package/src/browser/WebChannelBrowser.ts +145 -0
- package/src/browser/WebError.test.ts +66 -0
- package/src/browser/WebError.ts +587 -0
- package/src/{effect → browser}/WebLock.ts +27 -28
- package/src/{browser.ts → browser/detect.ts} +6 -6
- package/src/browser/mod.ts +8 -0
- package/src/cuid/cuid.browser.ts +1 -1
- package/src/cuid/cuid.node.ts +1 -1
- package/src/effect/Debug.ts +477 -0
- package/src/effect/Effect.test.ts +117 -0
- package/src/effect/Effect.ts +174 -79
- package/src/effect/Error.ts +1 -1
- package/src/effect/Logger.ts +0 -48
- package/src/effect/OtelTracer.ts +2 -3
- package/src/effect/RpcClient.ts +85 -65
- package/src/effect/Schedule.ts +4 -5
- package/src/effect/Schema/debug-diff.test.ts +7 -7
- package/src/effect/Schema/debug-diff.ts +11 -12
- package/src/effect/Schema/index.ts +121 -57
- package/src/effect/Stream.test.ts +14 -13
- package/src/effect/Stream.ts +23 -16
- package/src/effect/Subscribable.ts +31 -42
- package/src/effect/SubscriptionRef.ts +9 -13
- package/src/effect/TaskTracing.ts +13 -16
- package/src/effect/WebChannel/WebChannel.test.ts +24 -24
- package/src/effect/WebChannel/WebChannel.ts +102 -192
- package/src/effect/WebChannel/broadcastChannelWithAck.ts +25 -15
- package/src/effect/WebChannel/common.ts +16 -17
- package/src/effect/WebSocket.test.ts +2 -2
- package/src/effect/WebSocket.ts +20 -16
- package/src/effect/mod.browser-build.test.ts +19 -0
- package/src/effect/{index.ts → mod.ts} +43 -69
- package/src/effect/spanEvent.test.ts +92 -0
- package/src/effect/spanEvent.ts +17 -0
- package/src/env.ts +2 -1
- package/src/fast-deep-equal.ts +9 -10
- package/src/global.ts +4 -2
- package/src/misc.ts +13 -5
- package/src/mod.ts +188 -32
- package/src/node/mod.ts +57 -12
- package/src/object/index.ts +0 -24
- package/src/object/stringify-object.test.ts +1 -0
- package/src/object/stringify-object.ts +2 -2
- package/src/qr.ts +125 -0
- package/src/set.ts +1 -1
- package/src/string.ts +0 -3
- package/dist/.tsbuildinfo.json +0 -1
- package/dist/browser.d.ts.map +0 -1
- package/dist/browser.js.map +0 -1
- 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/effect/WebLock.d.ts.map +0 -1
- package/dist/effect/WebLock.js.map +0 -1
- package/dist/effect/index.d.ts +0 -32
- package/dist/effect/index.d.ts.map +0 -1
- package/dist/effect/index.js +0 -35
- package/dist/effect/index.js.map +0 -1
- package/dist/guards.d.ts +0 -6
- package/dist/guards.d.ts.map +0 -1
- package/dist/guards.js +0 -6
- 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 -122
- package/dist/node/ChildProcessRunner/ChildProcessRunner.js.map +0 -1
- package/dist/node/ChildProcessRunner/ChildProcessRunnerTest/ChildProcessRunner.test.d.ts +0 -2
- package/dist/node/ChildProcessRunner/ChildProcessRunnerTest/ChildProcessRunner.test.d.ts.map +0 -1
- package/dist/node/ChildProcessRunner/ChildProcessRunnerTest/ChildProcessRunner.test.js +0 -218
- 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 -8
- package/src/node/ChildProcessRunner/ChildProcessRunner.ts +0 -135
- package/src/node/ChildProcessRunner/ChildProcessRunnerTest/ChildProcessRunner.test.ts +0 -302
- package/src/node/ChildProcessRunner/ChildProcessRunnerTest/schema.ts +0 -78
- package/src/node/ChildProcessRunner/ChildProcessRunnerTest/serializedWorker.ts +0 -66
- package/src/node/ChildProcessRunner/ChildProcessWorker.ts +0 -168
- package/src/object/omit.ts +0 -17
- package/src/object/pick.ts +0 -27
- package/src/time.ts +0 -25
- /package/dist/{effect → browser}/WebLock.d.ts +0 -0
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)) {
|
|
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,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;YACxB,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":3,"file":"time.js","sourceRoot":"","sources":["../src/time.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,UAAU,GAAG,IAAI,GAAG,EAAE,CAAA;AAEnC,MAAM,CAAC,MAAM,IAAI,GAAG;IAClB,EAAE,EAAE,CAAC;IACL,GAAG,EAAE,IAAI;IACT,GAAG,EAAE,EAAE,GAAG,IAAI;IACd,IAAI,EAAE,EAAE,GAAG,EAAE,GAAG,IAAI;IACpB,GAAG,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI;IACxB,IAAI,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI;CAC9B,CAAA;AAED,oEAAoE;AACpE,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,EAAU,EAAE,EAAE;IAC3C,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,GAAG,IAAI,CAAC,CAAA;IACrC,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,GAAG,EAAE,CAAC,CAAA;IACxC,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,GAAG,EAAE,CAAC,CAAA;IACtC,MAAM,gBAAgB,GAAG,CAAC,OAAO,GAAG,EAAE,CAAC,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAA;IACnE,MAAM,gBAAgB,GAAG,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,GAAG,EAAE,CAAC,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,GAAG,EAAE,CAAA;IAE9F,MAAM,UAAU,GAAG,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,GAAG,gBAAgB,GAAG,EAAE,GAAG,gBAAgB,EAAE,CAAC;SAC7F,MAAM,CAAC,CAAC,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>, never, never> =>
|
|
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) => Effect.provide(runtime)(self),
|
|
28
|
-
runWithErrorLog: <E, A>(self: Effect.Effect<A, E, Ctx>) => runWithErrorLog(Effect.provide(runtime)(self)),
|
|
29
|
-
runSync: <E, A>(self: Effect.Effect<A, E, Ctx>) => Effect.runSync(Effect.provide(runtime)(self)),
|
|
30
|
-
runPromiseWithErrorLog: <E, A>(self: Effect.Effect<A, E, Ctx>) =>
|
|
31
|
-
runPromiseWithErrorLog(Effect.provide(runtime)(self)),
|
|
32
|
-
runPromiseExit: <E, A>(self: Effect.Effect<A, E, Ctx>) => Effect.runPromiseExit(Effect.provide(runtime)(self)),
|
|
33
|
-
runPromise: <E, A>(self: Effect.Effect<A, E, Ctx>) => Effect.runPromise(Effect.provide(runtime)(self)),
|
|
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,8 +0,0 @@
|
|
|
1
|
-
export const isNotUndefined = <T>(_: T | undefined): _ is T => _ !== undefined
|
|
2
|
-
|
|
3
|
-
export const isNotNull = <T>(_: T | null): _ is T => _ !== null
|
|
4
|
-
export const isUndefined = <T>(_: T | undefined): _ is undefined => _ === undefined
|
|
5
|
-
|
|
6
|
-
export const isNil = (val: any): val is null | undefined => val === null || val === undefined
|
|
7
|
-
|
|
8
|
-
export const isNotNil = <T>(val: T | undefined | null): val is T => val !== null && val !== undefined
|
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
import process from 'node:process'
|
|
2
|
-
|
|
3
|
-
import { WorkerError } from '@effect/platform/WorkerError'
|
|
4
|
-
import type { CloseLatch } from '@effect/platform/WorkerRunner'
|
|
5
|
-
import * as Runner from '@effect/platform/WorkerRunner'
|
|
6
|
-
import * as Cause from 'effect/Cause'
|
|
7
|
-
import * as Context from 'effect/Context'
|
|
8
|
-
import * as Deferred from 'effect/Deferred'
|
|
9
|
-
import * as Effect from 'effect/Effect'
|
|
10
|
-
import * as Exit from 'effect/Exit'
|
|
11
|
-
import * as FiberSet from 'effect/FiberSet'
|
|
12
|
-
import * as Layer from 'effect/Layer'
|
|
13
|
-
import * as Runtime from 'effect/Runtime'
|
|
14
|
-
import * as Scope from 'effect/Scope'
|
|
15
|
-
|
|
16
|
-
// Parent death monitoring setup
|
|
17
|
-
let parentDeathDetectionEnabled = false
|
|
18
|
-
let parentDeathTimer: NodeJS.Timeout | null = null
|
|
19
|
-
|
|
20
|
-
const stopParentDeathMonitoring = () => {
|
|
21
|
-
parentDeathDetectionEnabled = false
|
|
22
|
-
if (parentDeathTimer) {
|
|
23
|
-
clearTimeout(parentDeathTimer)
|
|
24
|
-
parentDeathTimer = null
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const setupParentDeathMonitoring = (parentPid: number) => {
|
|
29
|
-
if (parentDeathDetectionEnabled) return
|
|
30
|
-
parentDeathDetectionEnabled = true
|
|
31
|
-
|
|
32
|
-
let consecutiveFailures = 0
|
|
33
|
-
const maxFailures = 3 // Require 3 consecutive failures before self-terminating
|
|
34
|
-
|
|
35
|
-
// Check if parent is still alive every 2 seconds (more conservative)
|
|
36
|
-
const checkParentAlive = () => {
|
|
37
|
-
if (!parentDeathDetectionEnabled) return
|
|
38
|
-
try {
|
|
39
|
-
// Send signal 0 to check if process exists (doesn't actually send signal)
|
|
40
|
-
process.kill(parentPid, 0)
|
|
41
|
-
// If we reach here, parent is still alive, reset failure counter and check again later
|
|
42
|
-
consecutiveFailures = 0
|
|
43
|
-
parentDeathTimer = setTimeout(checkParentAlive, 2000)
|
|
44
|
-
} catch {
|
|
45
|
-
consecutiveFailures++
|
|
46
|
-
console.warn(`[Worker ${process.pid}] Parent check failed (${consecutiveFailures}/${maxFailures})`)
|
|
47
|
-
|
|
48
|
-
if (consecutiveFailures >= maxFailures) {
|
|
49
|
-
// Parent process has been gone for multiple checks, self-terminate
|
|
50
|
-
console.error(`[Worker ${process.pid}] Parent process ${parentPid} confirmed dead, self-terminating`)
|
|
51
|
-
process.exit(0)
|
|
52
|
-
} else {
|
|
53
|
-
// Try again sooner on failure
|
|
54
|
-
parentDeathTimer = setTimeout(checkParentAlive, 1000)
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// Start monitoring after a longer initial delay to let things settle
|
|
60
|
-
parentDeathTimer = setTimeout(checkParentAlive, 5000)
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const platformRunnerImpl = Runner.PlatformRunner.of({
|
|
64
|
-
[Runner.PlatformRunnerTypeId]: Runner.PlatformRunnerTypeId,
|
|
65
|
-
start<I, O>(closeLatch: typeof CloseLatch.Service) {
|
|
66
|
-
return Effect.gen(function* () {
|
|
67
|
-
if (!process.send) {
|
|
68
|
-
return yield* new WorkerError({ reason: 'spawn', cause: new Error('not in a child process') })
|
|
69
|
-
}
|
|
70
|
-
const port = {
|
|
71
|
-
postMessage: (message: any) => process.send!(message),
|
|
72
|
-
on: (event: string, handler: (message: any) => void) => process.on(event, handler),
|
|
73
|
-
close: () => process.disconnect(),
|
|
74
|
-
}
|
|
75
|
-
const send = (_portId: number, message: O, _transfers?: ReadonlyArray<unknown>) =>
|
|
76
|
-
Effect.sync(() => port.postMessage([1, message] /*, transfers as any*/))
|
|
77
|
-
|
|
78
|
-
const run = Effect.fnUntraced(function* <A, E, R>(
|
|
79
|
-
// biome-ignore lint/suspicious/noConfusingVoidType: need to support void
|
|
80
|
-
handler: (portId: number, message: I) => Effect.Effect<A, E, R> | void,
|
|
81
|
-
) {
|
|
82
|
-
const runtime = (yield* Effect.interruptible(Effect.runtime<R | Scope.Scope>())).pipe(
|
|
83
|
-
Runtime.updateContext(Context.omit(Scope.Scope)),
|
|
84
|
-
) as Runtime.Runtime<R>
|
|
85
|
-
const fiberSet = yield* FiberSet.make<any, WorkerError | E>()
|
|
86
|
-
const runFork = Runtime.runFork(runtime)
|
|
87
|
-
const onExit = (exit: Exit.Exit<any, E>) => {
|
|
88
|
-
if (exit._tag === 'Failure' && !Cause.isInterruptedOnly(exit.cause)) {
|
|
89
|
-
// Deferred.unsafeDone(closeLatch, Exit.die(Cause.squash(exit.cause)))
|
|
90
|
-
Deferred.unsafeDone(closeLatch, Exit.die(exit.cause))
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
port.on('message', (message: Runner.BackingRunner.Message<I> | any) => {
|
|
94
|
-
// console.log('message', message)
|
|
95
|
-
|
|
96
|
-
// Handle parent death detection setup messages
|
|
97
|
-
if (Array.isArray(message) && message[0] === 'setup-parent-death-detection' && message[1]?.parentPid) {
|
|
98
|
-
const parentPid = message[1].parentPid
|
|
99
|
-
// console.log(`[Worker ${process.pid}] Setting up parent death detection for parent ${parentPid}`)
|
|
100
|
-
setupParentDeathMonitoring(parentPid)
|
|
101
|
-
return
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
// Handle normal Effect worker messages
|
|
105
|
-
if (Array.isArray(message) && typeof message[0] === 'number') {
|
|
106
|
-
if (message[0] === 0) {
|
|
107
|
-
const result = handler(0, message[1])
|
|
108
|
-
if (Effect.isEffect(result)) {
|
|
109
|
-
const fiber = runFork(result)
|
|
110
|
-
fiber.addObserver(onExit)
|
|
111
|
-
FiberSet.unsafeAdd(fiberSet, fiber)
|
|
112
|
-
}
|
|
113
|
-
} else {
|
|
114
|
-
// Graceful shutdown requested by parent: stop monitoring and close port
|
|
115
|
-
stopParentDeathMonitoring()
|
|
116
|
-
Deferred.unsafeDone(closeLatch, Exit.void)
|
|
117
|
-
port.close()
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
})
|
|
121
|
-
port.on('messageerror', (cause) => {
|
|
122
|
-
Deferred.unsafeDone(closeLatch, new WorkerError({ reason: 'decode', cause }))
|
|
123
|
-
})
|
|
124
|
-
port.on('error', (cause) => {
|
|
125
|
-
Deferred.unsafeDone(closeLatch, new WorkerError({ reason: 'unknown', cause }))
|
|
126
|
-
})
|
|
127
|
-
port.postMessage([0])
|
|
128
|
-
})
|
|
129
|
-
|
|
130
|
-
return { run, send }
|
|
131
|
-
})
|
|
132
|
-
},
|
|
133
|
-
})
|
|
134
|
-
|
|
135
|
-
export const layer = Layer.succeed(Runner.PlatformRunner, platformRunnerImpl)
|