posipaki 0.26.0 → 0.27.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{hooks-rduh9LzW.d.ts → hooks-DL2s94eM.d.ts} +5 -5
- package/dist/hooks-DL2s94eM.d.ts.map +1 -0
- package/dist/hooks.d.ts +1 -1
- package/dist/index.d.ts +13 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/pipe.d.ts +1 -2
- package/dist/pipe.d.ts.map +1 -1
- package/dist/pipe.js +12 -10
- package/dist/pipe.js.map +1 -1
- package/dist/plugins/debug-logger.d.ts +2 -3
- package/dist/plugins/debug-logger.d.ts.map +1 -1
- package/dist/plugins/tree-introspection.d.ts +2 -3
- package/dist/plugins/tree-introspection.d.ts.map +1 -1
- package/dist/plugins/tree-introspection.js.map +1 -1
- package/dist/process-B5ZijF-E.d.ts +14 -0
- package/dist/process-B5ZijF-E.d.ts.map +1 -0
- package/dist/remote/index.d.ts +6 -4
- package/dist/remote/index.d.ts.map +1 -1
- package/dist/remote/index.js +79 -37
- package/dist/remote/index.js.map +1 -1
- package/dist/{src-tbH9wapj.js → src-BLzdjrVl.js} +6 -3
- package/dist/{src-tbH9wapj.js.map → src-BLzdjrVl.js.map} +1 -1
- package/dist/supervisor.d.ts +3 -8
- package/dist/supervisor.d.ts.map +1 -1
- package/dist/supervisor.js +2 -4
- package/dist/supervisor.js.map +1 -1
- package/dist/testing/index.d.ts +11 -9
- package/dist/testing/index.d.ts.map +1 -1
- package/dist/testing/index.js +39 -27
- package/dist/testing/index.js.map +1 -1
- package/dist/{types-RfSUSvKp.d.ts → types-B_bUAR9r.d.ts} +1 -3
- package/dist/types-B_bUAR9r.d.ts.map +1 -0
- package/dist/{util-FmOqPdg-.js → util-Brtfgv68.js} +6 -3
- package/dist/util-Brtfgv68.js.map +1 -0
- package/dist/xfetch.d.ts +3 -13
- package/dist/xfetch.d.ts.map +1 -1
- package/dist/xfetch.js +19 -14
- package/dist/xfetch.js.map +1 -1
- package/package.json +4 -12
- package/dist/hooks-rduh9LzW.d.ts.map +0 -1
- package/dist/process-BGFeAuma.d.ts +0 -33
- package/dist/process-BGFeAuma.d.ts.map +0 -1
- package/dist/types-RfSUSvKp.d.ts.map +0 -1
- package/dist/util-FmOqPdg-.js.map +0 -1
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { a as ProcessCtx, m as AsyncProcess, n as ExitMessage, p as AnyProcess, r as Message, s as SenderInfo, t as AsyncProcessFn } from "./types-
|
|
2
|
-
|
|
1
|
+
import { a as ProcessCtx, m as AsyncProcess, n as ExitMessage, p as AnyProcess, r as Message, s as SenderInfo, t as AsyncProcessFn } from "./types-B_bUAR9r.js";
|
|
3
2
|
//#region src/actor-types.d.ts
|
|
4
3
|
type ActorMessages<M extends Message> = {
|
|
5
4
|
__tag_messages: M;
|
|
@@ -10,7 +9,7 @@ interface MethodOptions {
|
|
|
10
9
|
type HandlerFn<InMsg extends Message> = (msg: InMsg, sender: SenderInfo) => void | Promise<void>;
|
|
11
10
|
type HandlerOptions<InMsg extends Message> = Omit<{ [K in InMsg["type"]]: HandlerFn<Extract<InMsg, {
|
|
12
11
|
type: K;
|
|
13
|
-
}
|
|
12
|
+
}>>; }, "STOP">;
|
|
14
13
|
interface ReflectionOptions {}
|
|
15
14
|
type Paired<Priv, Pub> = {
|
|
16
15
|
public: Pub;
|
|
@@ -42,7 +41,8 @@ interface ActorDefinition<Args, InternalState, InMsg extends Message, OutMsg ext
|
|
|
42
41
|
outMessages: ActorMessages<OutMsg> | undefined;
|
|
43
42
|
}
|
|
44
43
|
type ActorConfig<Args, InternalState, InMsg extends Message, OutMsg extends Message, Methods extends MethodOptions, Handlers extends HandlerOptions<InMsg>, ReflectionMethods extends ReflectionOptions> = ThisType<ActorContext<Args, InternalState, InMsg, OutMsg, Methods, Handlers, ReflectionMethods & ActorReflection>> & {
|
|
45
|
-
/** Preferred process name. Used by ctx.fork() when no explicit name is given. */
|
|
44
|
+
/** Preferred process name. Used by ctx.fork() when no explicit name is given. */
|
|
45
|
+
name?: string;
|
|
46
46
|
plugins?: ActorPlugin[] | PluginTransform;
|
|
47
47
|
/** Non-overridable plugins added at spawn time (spawn/fork opts).
|
|
48
48
|
* Set by the framework during assembly, not by user config. @internal */
|
|
@@ -160,4 +160,4 @@ type Hook<T, I extends unknown[], O> = (this: T, ...args: I) => O;
|
|
|
160
160
|
declare function callHook<T, I extends unknown[], O>(fn: Hook<T, I, O> | undefined, eh: ((e: unknown) => unknown) | undefined, thisArg: T, ...args: I): Promise<O | undefined>;
|
|
161
161
|
//#endregion
|
|
162
162
|
export { ReflectionOptions as _, chainHook as a, stopPropagation as b, ActorContext as c, ActorPlugin as d, HandlerFn as f, PluginTransform as g, MethodOptions as h, callHook as i, ActorDefinition as l, HookResult as m, ActorReflection as n, mergeConfigs as o, HandlerOptions as p, Hook as r, ActorConfig as s, ActorDecorated as t, ActorMessages as u, STOP_SENTINEL as v, SpawnedFrom as y };
|
|
163
|
-
//# sourceMappingURL=hooks-
|
|
163
|
+
//# sourceMappingURL=hooks-DL2s94eM.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks-DL2s94eM.d.ts","names":[],"sources":["../src/actor-types.ts","../src/hooks.ts"],"mappings":"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"}
|
package/dist/hooks.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as chainHook, b as stopPropagation, d as ActorPlugin, g as PluginTransform, i as callHook, m as HookResult, n as ActorReflection, o as mergeConfigs, r as Hook, t as ActorDecorated, v as STOP_SENTINEL } from "./hooks-
|
|
1
|
+
import { a as chainHook, b as stopPropagation, d as ActorPlugin, g as PluginTransform, i as callHook, m as HookResult, n as ActorReflection, o as mergeConfigs, r as Hook, t as ActorDecorated, v as STOP_SENTINEL } from "./hooks-DL2s94eM.js";
|
|
2
2
|
export { ActorDecorated, type ActorPlugin, ActorReflection, Hook, type HookResult, type PluginTransform, STOP_SENTINEL, callHook, chainHook, mergeConfigs, stopPropagation };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,16 @@
|
|
|
1
|
-
import { a as ProcessCtx, c as SenderOrigin, d as WithSender, f as WithoutSender, g as spawnAsync, h as runDispatchAsync, i as PipeState, l as StopMessage, m as AsyncProcess, n as ExitMessage, o as ProcessFn, p as AnyProcess, r as Message, s as SenderInfo, t as AsyncProcessFn, u as SupervisorState } from "./types-
|
|
2
|
-
import { _ as ReflectionOptions, a as chainHook, b as stopPropagation, c as ActorContext, d as ActorPlugin, f as HandlerFn, g as PluginTransform, h as MethodOptions, i as callHook, l as ActorDefinition, m as HookResult, n as ActorReflection, o as mergeConfigs, p as HandlerOptions, s as ActorConfig, t as ActorDecorated, u as ActorMessages, y as SpawnedFrom } from "./hooks-
|
|
3
|
-
import { n as spawn,
|
|
4
|
-
|
|
1
|
+
import { a as ProcessCtx, c as SenderOrigin, d as WithSender, f as WithoutSender, g as spawnAsync, h as runDispatchAsync, i as PipeState, l as StopMessage, m as AsyncProcess, n as ExitMessage, o as ProcessFn, p as AnyProcess, r as Message, s as SenderInfo, t as AsyncProcessFn, u as SupervisorState } from "./types-B_bUAR9r.js";
|
|
2
|
+
import { _ as ReflectionOptions, a as chainHook, b as stopPropagation, c as ActorContext, d as ActorPlugin, f as HandlerFn, g as PluginTransform, h as MethodOptions, i as callHook, l as ActorDefinition, m as HookResult, n as ActorReflection, o as mergeConfigs, p as HandlerOptions, s as ActorConfig, t as ActorDecorated, u as ActorMessages, y as SpawnedFrom } from "./hooks-DL2s94eM.js";
|
|
3
|
+
import { n as spawn, t as Process } from "./process-B5ZijF-E.js";
|
|
4
|
+
//#region src/util.d.ts
|
|
5
|
+
type ReducerClosure<M> = (msg: M) => void;
|
|
6
|
+
type ReadyFn = () => boolean;
|
|
7
|
+
/**
|
|
8
|
+
* Generator helper that loops, yielding `null` and feeding incoming
|
|
9
|
+
* messages to `fn` until `readyFn()` returns true. Used inside
|
|
10
|
+
* process generators to build the main message loop.
|
|
11
|
+
*/
|
|
12
|
+
declare function runDispatch<M>(name: string, fn: ReducerClosure<M>, readyFn?: ReadyFn, debugLevel?: boolean): Generator<null, void, M>;
|
|
13
|
+
//#endregion
|
|
5
14
|
//#region src/adapters.d.ts
|
|
6
15
|
declare function asyncify<A, S, IM extends Message, OM extends Message>(fn: ProcessFn<A, S, IM, OM>): AsyncProcessFn<A, S, IM, OM>;
|
|
7
16
|
//#endregion
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/adapters.ts","../src/define-actor.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/util.ts","../src/adapters.ts","../src/define-actor.ts"],"mappings":";;;;KAOK,eAAe,MAAM,KAAK;KAC1B;;;;;;iBASK,YAAY,GACpB,cACA,IAAI,eAAe,IACnB,UAAS,SACT,uBACC,sBAAsB;;;iBCpBT,SAAS,GAAG,GAAG,WAAW,SAAS,WAAW,SAC5D,IAAI,UAAU,GAAG,GAAG,IAAI,MACvB,eAAe,GAAG,GAAG,IAAI;;;iBCmCZ,eACd,eAAe,UAAU,YACtB,cAAc;iBA4DH,YACd,MACA,eACA,cAAc,SACd,eAAe,SACf,gBAAgB,eAChB,iBAAiB,eAAe,QAChC,0BAA0B,mBAE1B,QAAQ,YACN,MACA,eACA,OACA,QACA,SACA,UACA,qBAED,gBAAgB,MAAM,eAAe,OAAO,QAAQ"}
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as runDispatch } from "./util-
|
|
2
|
-
import { a as AsyncProcess, c as asyncify, i as spawn, n as defineMessages, o as runDispatchAsync, r as Process, s as spawnAsync, t as defineActor } from "./src-
|
|
1
|
+
import { i as runDispatch } from "./util-Brtfgv68.js";
|
|
2
|
+
import { a as AsyncProcess, c as asyncify, i as spawn, n as defineMessages, o as runDispatchAsync, r as Process, s as spawnAsync, t as defineActor } from "./src-BLzdjrVl.js";
|
|
3
3
|
import { a as stopPropagation, n as chainHook, r as mergeConfigs, t as callHook } from "./hooks-V-PEPJHv.js";
|
|
4
4
|
export { AsyncProcess, Process, asyncify, callHook, chainHook, defineActor, defineMessages, mergeConfigs, runDispatch, runDispatchAsync, spawn, spawnAsync, stopPropagation };
|
package/dist/pipe.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { n as ExitMessage, o as ProcessFn, r as Message } from "./types-
|
|
2
|
-
|
|
1
|
+
import { n as ExitMessage, o as ProcessFn, r as Message } from "./types-B_bUAR9r.js";
|
|
3
2
|
//#region src/pipe.d.ts
|
|
4
3
|
/**
|
|
5
4
|
* State yielded by the pipe process. `params` starts as a copy of the
|
package/dist/pipe.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pipe.d.ts","names":[],"sources":["../src/pipe.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"pipe.d.ts","names":[],"sources":["../src/pipe.ts"],"mappings":";;;;;;;UAWiB,UAAU,QAAQ;EACjC,QAAQ;EACR,QAAQ;EACR;;;;;;;iBAQO,KAAK,QAAQ,QACpB,KAAK;EAAqB;GAAkB,SAAS,aACpD,UACD,QACA,UAAU,QAAQ,SAClB,SACA,UAAU"}
|
package/dist/pipe.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as runDispatch } from "./util-
|
|
1
|
+
import { i as runDispatch } from "./util-Brtfgv68.js";
|
|
2
2
|
//#region src/pipe.ts
|
|
3
3
|
/**
|
|
4
4
|
* Chain process functions so each runs after the previous one exits.
|
|
@@ -31,15 +31,17 @@ function pipe(fns) {
|
|
|
31
31
|
state.running = false;
|
|
32
32
|
return;
|
|
33
33
|
}
|
|
34
|
-
if (msg.type === "EXIT" && _sender.fromId === task.id)
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
34
|
+
if (msg.type === "EXIT" && _sender.fromId === task.id) {
|
|
35
|
+
if (hasNext()) {
|
|
36
|
+
state.params = {
|
|
37
|
+
...state.params,
|
|
38
|
+
...task.state?.result
|
|
39
|
+
};
|
|
40
|
+
spawnNext();
|
|
41
|
+
} else {
|
|
42
|
+
state.running = false;
|
|
43
|
+
state.result = task.state?.result;
|
|
44
|
+
}
|
|
43
45
|
}
|
|
44
46
|
}, () => !state.running, true);
|
|
45
47
|
};
|
package/dist/pipe.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pipe.js","names":[],"sources":["../src/pipe.ts"],"sourcesContent":["import { runDispatch } from \"./util.js\";\nimport type { ExitMessage } from \"./util.js\";\nimport type { ProcessFn, ProcessCtx } from \"./process.js\";\nimport type { AsyncProcess } from \"./process.async.js\";\nimport type { Message, WithSender } from \"./types.js\";\n\n/**\n * State yielded by the pipe process. `params` starts as a copy of the\n * initial args and is updated after each child exits by merging the\n * child's `state.result` into it.\n */\nexport interface PipeState<Params, Result> {\n params: Params | null;\n result: Result | null;\n running: boolean;\n}\n\n/**\n * Chain process functions so each runs after the previous one exits.\n * The `.state.result` of each completed child is spread into the params\n * of the next.\n */\nfunction pipe<Params, Result>(\n fns: ProcessFn<unknown, { result: object }, Message, Message>[],\n): ProcessFn<\n Params,\n PipeState<Params, Result>,\n Message,\n Message | ExitMessage\n> {\n return function* (\n ctx: ProcessCtx<\n Params,\n PipeState<Params, Result>,\n Message,\n Message | ExitMessage\n >,\n params: Params,\n ) {\n const state: PipeState<Params, Result> = {\n params: { ...params },\n result: null,\n running: false,\n };\n yield state;\n\n const queue = [...fns];\n let task: AsyncProcess<unknown, { result: object }, Message, Message, {}>;\n\n function spawnNext(): void {\n const fn = queue.shift()!;\n task = ctx.forkSync(\n fn,\n `${ctx.pname} [${fn.name || \"<anonymous>\"}]`,\n )(state.params as Params);\n }\n\n function hasNext(): boolean {\n return queue.length > 0;\n }\n\n spawnNext();\n state.running = hasNext();\n\n yield* runDispatch<WithSender<Message | ExitMessage>>(\n ctx.pname,\n (maybe) => {\n const [msg, _sender] = maybe;\n\n if (msg.type === \"STOP\") {\n state.params = null;\n state.running = false;\n return;\n }\n\n if (msg.type === \"EXIT\" && _sender.fromId === task.id) {\n if (hasNext()) {\n state.params = {\n ...state.params!,\n ...task.state?.result,\n } as Params;\n spawnNext();\n } else {\n state.running = false;\n state.result = task.state?.result as Result;\n }\n }\n },\n () => !state.running,\n true,\n );\n };\n}\n\nexport { pipe };\n"],"mappings":";;;;;;;AAsBA,SAAS,KACP,KAMA;CACA,OAAO,WACL,KAMA,QACA;EACA,MAAM,QAAmC;GACvC,QAAQ,EAAE,GAAG,OAAO;GACpB,QAAQ;GACR,SAAS;EACX;EACA,MAAM;EAEN,MAAM,QAAQ,CAAC,GAAG,GAAG;EACrB,IAAI;EAEJ,SAAS,YAAkB;GACzB,MAAM,KAAK,MAAM,MAAM;GACvB,OAAO,IAAI,SACT,IACA,GAAG,IAAI,MAAM,IAAI,GAAG,QAAQ,cAAc,EAC5C,
|
|
1
|
+
{"version":3,"file":"pipe.js","names":[],"sources":["../src/pipe.ts"],"sourcesContent":["import { runDispatch } from \"./util.js\";\nimport type { ExitMessage } from \"./util.js\";\nimport type { ProcessFn, ProcessCtx } from \"./process.js\";\nimport type { AsyncProcess } from \"./process.async.js\";\nimport type { Message, WithSender } from \"./types.js\";\n\n/**\n * State yielded by the pipe process. `params` starts as a copy of the\n * initial args and is updated after each child exits by merging the\n * child's `state.result` into it.\n */\nexport interface PipeState<Params, Result> {\n params: Params | null;\n result: Result | null;\n running: boolean;\n}\n\n/**\n * Chain process functions so each runs after the previous one exits.\n * The `.state.result` of each completed child is spread into the params\n * of the next.\n */\nfunction pipe<Params, Result>(\n fns: ProcessFn<unknown, { result: object }, Message, Message>[],\n): ProcessFn<\n Params,\n PipeState<Params, Result>,\n Message,\n Message | ExitMessage\n> {\n return function* (\n ctx: ProcessCtx<\n Params,\n PipeState<Params, Result>,\n Message,\n Message | ExitMessage\n >,\n params: Params,\n ) {\n const state: PipeState<Params, Result> = {\n params: { ...params },\n result: null,\n running: false,\n };\n yield state;\n\n const queue = [...fns];\n let task: AsyncProcess<unknown, { result: object }, Message, Message, {}>;\n\n function spawnNext(): void {\n const fn = queue.shift()!;\n task = ctx.forkSync(\n fn,\n `${ctx.pname} [${fn.name || \"<anonymous>\"}]`,\n )(state.params as Params);\n }\n\n function hasNext(): boolean {\n return queue.length > 0;\n }\n\n spawnNext();\n state.running = hasNext();\n\n yield* runDispatch<WithSender<Message | ExitMessage>>(\n ctx.pname,\n (maybe) => {\n const [msg, _sender] = maybe;\n\n if (msg.type === \"STOP\") {\n state.params = null;\n state.running = false;\n return;\n }\n\n if (msg.type === \"EXIT\" && _sender.fromId === task.id) {\n if (hasNext()) {\n state.params = {\n ...state.params!,\n ...task.state?.result,\n } as Params;\n spawnNext();\n } else {\n state.running = false;\n state.result = task.state?.result as Result;\n }\n }\n },\n () => !state.running,\n true,\n );\n };\n}\n\nexport { pipe };\n"],"mappings":";;;;;;;AAsBA,SAAS,KACP,KAMA;CACA,OAAO,WACL,KAMA,QACA;EACA,MAAM,QAAmC;GACvC,QAAQ,EAAE,GAAG,OAAO;GACpB,QAAQ;GACR,SAAS;EACX;EACA,MAAM;EAEN,MAAM,QAAQ,CAAC,GAAG,GAAG;EACrB,IAAI;EAEJ,SAAS,YAAkB;GACzB,MAAM,KAAK,MAAM,MAAM;GACvB,OAAO,IAAI,SACT,IACA,GAAG,IAAI,MAAM,IAAI,GAAG,QAAQ,cAAc,EAC5C,CAAC,CAAC,MAAM,MAAgB;EAC1B;EAEA,SAAS,UAAmB;GAC1B,OAAO,MAAM,SAAS;EACxB;EAEA,UAAU;EACV,MAAM,UAAU,QAAQ;EAExB,OAAO,YACL,IAAI,QACH,UAAU;GACT,MAAM,CAAC,KAAK,WAAW;GAEvB,IAAI,IAAI,SAAS,QAAQ;IACvB,MAAM,SAAS;IACf,MAAM,UAAU;IAChB;GACF;GAEA,IAAI,IAAI,SAAS,UAAU,QAAQ,WAAW,KAAK,IAAI;IACrD,IAAI,QAAQ,GAAG;KACb,MAAM,SAAS;MACb,GAAG,MAAM;MACT,GAAG,KAAK,OAAO;KACjB;KACA,UAAU;IACZ,OAAO;KACL,MAAM,UAAU;KAChB,MAAM,SAAS,KAAK,OAAO;IAC7B;GACF;EACF,SACM,CAAC,MAAM,SACb,IACF;CACF;AACF"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { r as Message } from "../types-
|
|
2
|
-
import { d as ActorPlugin } from "../hooks-
|
|
3
|
-
|
|
1
|
+
import { r as Message } from "../types-B_bUAR9r.js";
|
|
2
|
+
import { d as ActorPlugin } from "../hooks-DL2s94eM.js";
|
|
4
3
|
//#region src/plugins/debug-logger.d.ts
|
|
5
4
|
declare module "../index" {
|
|
6
5
|
interface ActorDecorated {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"debug-logger.d.ts","names":[],"sources":["../../src/plugins/debug-logger.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"debug-logger.d.ts","names":[],"sources":["../../src/plugins/debug-logger.ts"],"mappings":";;;;YAKY;IACR,KAAK;;;UAIQ;GACd,oBAAoB;;UAEN;GACd,SAAS;;UAEK;GACd,eAAe;;UAGD;EACf,OAAO;EACP,MAAM;EACN,MAAM;EACN,OAAO;EACP,KAAK;EACL,WAAW;;KAED,iBAAiB,iBAAiB;;;;;;KAOlC,aAAa,KAAK,YAAY;UAEzB;;EAEf;EACA,UAAU;;;EAGV,YAAY;;;;;;;iBAYE,iBAAiB,KAAK,UAAU;;;;;;;;iBAoChC,YAAY,OAAO,kBAAkB"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { p as AnyProcess } from "../types-
|
|
2
|
-
import { d as ActorPlugin } from "../hooks-
|
|
3
|
-
|
|
1
|
+
import { p as AnyProcess } from "../types-B_bUAR9r.js";
|
|
2
|
+
import { d as ActorPlugin } from "../hooks-DL2s94eM.js";
|
|
4
3
|
//#region src/plugins/tree-introspection.d.ts
|
|
5
4
|
declare module "../index" {
|
|
6
5
|
interface ActorReflection {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tree-introspection.d.ts","names":[],"sources":["../../src/plugins/tree-introspection.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"tree-introspection.d.ts","names":[],"sources":["../../src/plugins/tree-introspection.ts"],"mappings":";;;;YAMY;IACR,mBAAmB;IACnB,oBAAoB;IACpB,gBAAgB;IAChB,gBAAgB;;;UAIV;EACR,oBAAoB,oBAAoB;EACxC;EACA,iBAAiB,kBAAkB;EACnC;;UAGe;EACf;EACA;EACA,UAAU;EACV;;iBAac,WAAW"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tree-introspection.js","names":[],"sources":["../../src/plugins/tree-introspection.ts"],"sourcesContent":["import { mergeConfigs } from \"../hooks.js\";\nimport type { ActorPlugin, ActorReflection as AR } from \"../hooks.js\";\nimport { AnyProcessCtx } from \"../types.js\";\nimport type { AnyProcess } from \"../process.async.js\";\n\ndeclare module \"../index\" {\n interface ActorReflection {\n \"inspect.getTree\": TreeReflectionMethods[\"inspect.getTree\"];\n \"inspect.getState\": TreeReflectionMethods[\"inspect.getState\"];\n \"inspect.find\": TreeReflectionMethods[\"inspect.find\"];\n \"inspect.exit\": TreeReflectionMethods[\"inspect.exit\"];\n }\n}\n\ninterface TreeReflectionMethods {\n \"inspect.getTree\": (prefix?: string) => TreeNode;\n \"inspect.getState\": () => unknown;\n \"inspect.find\": (pname: string) => AnyProcess | null;\n \"inspect.exit\": () => void;\n}\n\nexport interface TreeNode {\n pname: string;\n parentName: string | null;\n children: TreeNode[];\n status: \"running\" | \"no introspection\";\n}\n\n/** Depth-first search for a live process by its full `pname`. */\nfunction findProcess(procs: Iterable<AnyProcess>, pname: string): AnyProcess | null {\n for (const proc of procs) {\n if (proc.pname === pname) return proc;\n const found = findProcess(proc.children, pname);\n if (found) return found;\n }\n return null;\n}\n\nexport function inspect(): ActorPlugin {\n return async function inspectPlugin(config) {\n return mergeConfigs(config, {\n $reflectionMethods: {\n ...config.$reflectionMethods,\n \"inspect.getTree\": function (prefix?: string) {\n const children: TreeNode[] = [];\n for (const child of this.ctx.children) {\n const cr = child.$reflection as AR;\n if (typeof cr[\"inspect.getTree\"] === \"function\") {\n const sub = cr[\"inspect.getTree\"](prefix) as TreeNode;\n if (!prefix || sub.pname.startsWith(prefix)) children.push(sub);\n } else {\n const n = child.pname;\n if (!prefix || n.startsWith(prefix))\n children.push({\n pname: n,\n parentName: this.name,\n children: [],\n status: \"no introspection\",\n });\n }\n }\n const selfCtx = this.ctx as AnyProcessCtx;\n return {\n pname: selfCtx.pname,\n parentName: selfCtx.parentName,\n children,\n status: \"running\" as const,\n } satisfies TreeNode;\n },\n \"inspect.getState\": function () {\n const state = this.state as unknown;\n return state;\n },\n \"inspect.find\": function (pname: string) {\n const selfCtx = this.ctx as AnyProcessCtx;\n return findProcess(selfCtx.children, pname);\n },\n \"inspect.exit\": function () {\n this.exit(\"inspector\");\n },\n },\n });\n };\n}\n"],"mappings":";;;AA6BA,SAAS,YAAY,OAA6B,OAAkC;CAClF,KAAK,MAAM,QAAQ,OAAO;EACxB,IAAI,KAAK,UAAU,OAAO,OAAO;EACjC,MAAM,QAAQ,YAAY,KAAK,UAAU,KAAK;EAC9C,IAAI,OAAO,OAAO;CACpB;CACA,OAAO;AACT;AAEA,SAAgB,UAAuB;CACrC,OAAO,eAAe,cAAc,QAAQ;EAC1C,OAAO,aAAa,QAAQ,EAC1B,oBAAoB;GAClB,GAAG,OAAO;GACV,mBAAmB,SAAU,QAAiB;IAC5C,MAAM,WAAuB,CAAC;IAC9B,KAAK,MAAM,SAAS,KAAK,IAAI,UAAU;KACrC,MAAM,KAAK,MAAM;KACjB,IAAI,OAAO,GAAG,uBAAuB,YAAY;MAC/C,MAAM,MAAM,GAAG,
|
|
1
|
+
{"version":3,"file":"tree-introspection.js","names":[],"sources":["../../src/plugins/tree-introspection.ts"],"sourcesContent":["import { mergeConfigs } from \"../hooks.js\";\nimport type { ActorPlugin, ActorReflection as AR } from \"../hooks.js\";\nimport { AnyProcessCtx } from \"../types.js\";\nimport type { AnyProcess } from \"../process.async.js\";\n\ndeclare module \"../index\" {\n interface ActorReflection {\n \"inspect.getTree\": TreeReflectionMethods[\"inspect.getTree\"];\n \"inspect.getState\": TreeReflectionMethods[\"inspect.getState\"];\n \"inspect.find\": TreeReflectionMethods[\"inspect.find\"];\n \"inspect.exit\": TreeReflectionMethods[\"inspect.exit\"];\n }\n}\n\ninterface TreeReflectionMethods {\n \"inspect.getTree\": (prefix?: string) => TreeNode;\n \"inspect.getState\": () => unknown;\n \"inspect.find\": (pname: string) => AnyProcess | null;\n \"inspect.exit\": () => void;\n}\n\nexport interface TreeNode {\n pname: string;\n parentName: string | null;\n children: TreeNode[];\n status: \"running\" | \"no introspection\";\n}\n\n/** Depth-first search for a live process by its full `pname`. */\nfunction findProcess(procs: Iterable<AnyProcess>, pname: string): AnyProcess | null {\n for (const proc of procs) {\n if (proc.pname === pname) return proc;\n const found = findProcess(proc.children, pname);\n if (found) return found;\n }\n return null;\n}\n\nexport function inspect(): ActorPlugin {\n return async function inspectPlugin(config) {\n return mergeConfigs(config, {\n $reflectionMethods: {\n ...config.$reflectionMethods,\n \"inspect.getTree\": function (prefix?: string) {\n const children: TreeNode[] = [];\n for (const child of this.ctx.children) {\n const cr = child.$reflection as AR;\n if (typeof cr[\"inspect.getTree\"] === \"function\") {\n const sub = cr[\"inspect.getTree\"](prefix) as TreeNode;\n if (!prefix || sub.pname.startsWith(prefix)) children.push(sub);\n } else {\n const n = child.pname;\n if (!prefix || n.startsWith(prefix))\n children.push({\n pname: n,\n parentName: this.name,\n children: [],\n status: \"no introspection\",\n });\n }\n }\n const selfCtx = this.ctx as AnyProcessCtx;\n return {\n pname: selfCtx.pname,\n parentName: selfCtx.parentName,\n children,\n status: \"running\" as const,\n } satisfies TreeNode;\n },\n \"inspect.getState\": function () {\n const state = this.state as unknown;\n return state;\n },\n \"inspect.find\": function (pname: string) {\n const selfCtx = this.ctx as AnyProcessCtx;\n return findProcess(selfCtx.children, pname);\n },\n \"inspect.exit\": function () {\n this.exit(\"inspector\");\n },\n },\n });\n };\n}\n"],"mappings":";;;AA6BA,SAAS,YAAY,OAA6B,OAAkC;CAClF,KAAK,MAAM,QAAQ,OAAO;EACxB,IAAI,KAAK,UAAU,OAAO,OAAO;EACjC,MAAM,QAAQ,YAAY,KAAK,UAAU,KAAK;EAC9C,IAAI,OAAO,OAAO;CACpB;CACA,OAAO;AACT;AAEA,SAAgB,UAAuB;CACrC,OAAO,eAAe,cAAc,QAAQ;EAC1C,OAAO,aAAa,QAAQ,EAC1B,oBAAoB;GAClB,GAAG,OAAO;GACV,mBAAmB,SAAU,QAAiB;IAC5C,MAAM,WAAuB,CAAC;IAC9B,KAAK,MAAM,SAAS,KAAK,IAAI,UAAU;KACrC,MAAM,KAAK,MAAM;KACjB,IAAI,OAAO,GAAG,uBAAuB,YAAY;MAC/C,MAAM,MAAM,GAAG,kBAAkB,CAAC,MAAM;MACxC,IAAI,CAAC,UAAU,IAAI,MAAM,WAAW,MAAM,GAAG,SAAS,KAAK,GAAG;KAChE,OAAO;MACL,MAAM,IAAI,MAAM;MAChB,IAAI,CAAC,UAAU,EAAE,WAAW,MAAM,GAChC,SAAS,KAAK;OACZ,OAAO;OACP,YAAY,KAAK;OACjB,UAAU,CAAC;OACX,QAAQ;MACV,CAAC;KACL;IACF;IACA,MAAM,UAAU,KAAK;IACrB,OAAO;KACL,OAAO,QAAQ;KACf,YAAY,QAAQ;KACpB;KACA,QAAQ;IACV;GACF;GACA,oBAAoB,WAAY;IAE9B,OADc,KAAK;GAErB;GACA,gBAAgB,SAAU,OAAe;IACvC,MAAM,UAAU,KAAK;IACrB,OAAO,YAAY,QAAQ,UAAU,KAAK;GAC5C;GACA,gBAAgB,WAAY;IAC1B,KAAK,KAAK,WAAW;GACvB;EACF,EACF,CAAC;CACH;AACF"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { m as AsyncProcess, n as ExitMessage, o as ProcessFn, r as Message, s as SenderInfo } from "./types-B_bUAR9r.js";
|
|
2
|
+
//#region src/process.d.ts
|
|
3
|
+
/** @deprecated Use {@link spawnAsync} instead. */
|
|
4
|
+
declare function spawn<A, S, IM extends Message = Message, OM extends Message = ExitMessage>(fn: ProcessFn<A, S, IM, OM>, pname: string, tp?: (m: OM, from: SenderInfo) => void): (a: A) => Process<A, S, IM, OM>;
|
|
5
|
+
/** @deprecated Use {@link AsyncProcess} instead. Sync processes are
|
|
6
|
+
* wrapped via asyncify internally; spawnAsync handles both. */
|
|
7
|
+
declare class Process<A, S, IM extends Message, OM extends Message> extends AsyncProcess<A, S, IM, OM, {}> {
|
|
8
|
+
constructor(fn: ProcessFn<A, S, IM, OM>, pname: string, tp?: (m: OM, from: SenderInfo) => void);
|
|
9
|
+
start(a: A): this;
|
|
10
|
+
tick(): Promise<void>;
|
|
11
|
+
}
|
|
12
|
+
//#endregion
|
|
13
|
+
export { spawn as n, Process as t };
|
|
14
|
+
//# sourceMappingURL=process-B5ZijF-E.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"process-B5ZijF-E.d.ts","names":[],"sources":["../src/process.ts"],"mappings":";;;iBAQgB,MACd,GACA,GACA,WAAW,UAAU,SACrB,WAAW,UAAU,aAErB,IAAI,UAAU,GAAG,GAAG,IAAI,KACxB,eACA,MAAM,GAAG,IAAI,MAAM,uBACjB,GAAG,MAAM,QAAQ,GAAG,GAAG,IAAI;;;cAMzB,QACJ,GACA,GACA,WAAW,SACX,WAAW,iBACH,aAAa,GAAG,GAAG,IAAI;EAC/B,YACE,IAAI,UAAU,GAAG,GAAG,IAAI,KACxB,eACA,MAAM,GAAG,IAAI,MAAM;EAKrB,MAAM,GAAG;EAIT,QAAQ"}
|
package/dist/remote/index.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { r as Message, t as AsyncProcessFn } from "../types-
|
|
2
|
-
import { _ as ReflectionOptions, h as MethodOptions, l as ActorDefinition, p as HandlerOptions } from "../hooks-
|
|
1
|
+
import { r as Message, t as AsyncProcessFn } from "../types-B_bUAR9r.js";
|
|
2
|
+
import { _ as ReflectionOptions, h as MethodOptions, l as ActorDefinition, p as HandlerOptions } from "../hooks-DL2s94eM.js";
|
|
3
3
|
import { FileHandle } from "node:fs/promises";
|
|
4
|
-
|
|
5
4
|
//#region src/remote/child.d.ts
|
|
6
5
|
declare function makeSender(fromName: string, parentName: string | null, parentId: symbol | null): {
|
|
7
6
|
fromName: string;
|
|
@@ -33,7 +32,7 @@ declare const bunConnector: (scriptPath: string) => Connector;
|
|
|
33
32
|
/** Spawn via `node <script>`. */
|
|
34
33
|
declare const nodeConnector: (scriptPath: string) => Connector;
|
|
35
34
|
/**
|
|
36
|
-
* Auto-detect: prefers `bun run` if
|
|
35
|
+
* Auto-detect: prefers `bun run` if bun is
|
|
37
36
|
* the current runtime, otherwise falls back to `node`.
|
|
38
37
|
*/
|
|
39
38
|
declare function defaultConnector(scriptPath: string): Connector;
|
|
@@ -57,8 +56,10 @@ declare class FifoUtf8NlineTransport {
|
|
|
57
56
|
private writeFd;
|
|
58
57
|
private rl;
|
|
59
58
|
private rs;
|
|
59
|
+
private ws;
|
|
60
60
|
private pvtOnMessage;
|
|
61
61
|
private closed;
|
|
62
|
+
private closingPromise;
|
|
62
63
|
private pvtError;
|
|
63
64
|
private pvtWriter;
|
|
64
65
|
private constructor();
|
|
@@ -94,6 +95,7 @@ declare class FifoUtf8NlineTransport {
|
|
|
94
95
|
get lastError(): Error | null;
|
|
95
96
|
send(line: string): Promise<void>;
|
|
96
97
|
close(): Promise<void>;
|
|
98
|
+
private pvtClose;
|
|
97
99
|
}
|
|
98
100
|
//#endregion
|
|
99
101
|
//#region src/remote/protocol.d.ts
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/remote/child.ts","../../src/remote/host.ts","../../src/remote/define.ts","../../src/remote/fifo.ts","../../src/remote/protocol.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/remote/child.ts","../../src/remote/host.ts","../../src/remote/define.ts","../../src/remote/fifo.ts","../../src/remote/protocol.ts"],"mappings":";;;;iBAQgB,WACd,kBACA,2BACA;EACG;EAAkB;;iBASD,SAAS,MAAM,OAAO,cAAc,SAAS,eAAe,SAChF,IAAI,eAAe,MAAM,OAAO,OAAO,UACtC;;;UCNc,oBAAoB,OAAO;EAC1C;EACA,MAAM;EACN;;UAGe,YACf,iBACA,cAAc,UAAU,SACxB,eAAe,UAAU;WAEhB,OAAO;EAChB,SAAS;EACT,KAAK,KAAK;EACV,QAAQ;IAAU;IAAqB,OAAO;;EAC9C,UAAU,UAAU,KAAK;;;KAIf,UACV,iBACA,cAAc,UAAU,SACxB,eAAe,UAAU,YACtB,MAAM,wBAAwB,QAAQ,YAAY,OAAO,OAAO;iBAI/C,YACpB,iBACA,cAAc,UAAU,SACxB,eAAe,UAAU,SACzB,OAAO,yBACP,MAAM,oBAAoB,QAAQ,QAAQ,YAAY,OAAO,OAAO;;cA0HzD,eAAY,uBAZ+D;;cAe3E,gBAAa,uBAf8D;;;;;iBAqBxE,iBAAiB,qBAAqB;cASzC,yBAAgB;;;UCzKZ;EACf;EACA,YAAY;;UAGG,kBACf,MACA,OACA,cAAc,SACd,eAAe,SACf,0BAA0B;EAE1B,OAAO,gBAAgB,MAAM,OAAO,OAAO,QAAQ;EACnD,iBAAiB;EACjB;;iBASc,kBACd,MACA,OACA,cAAc,SACd,eAAe,SACf,gBAAgB,eAChB,iBAAiB,eAAe,QAChC,mBAAmB,mBAEnB,OAAO,gBAAgB,MAAM,OAAO,OAAO,QAAQ,aACnD,aACA,OAAM,qBACL,kBAAkB,MAAM,OAAO,OAAO,QAAQ;;;cC9CpC;UACH;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UAED;iBA8Cc;iBAKA;SAKd,QAAQ,QAAQ,YAAY,SAAS,aAAa;UAMjD;;;;;;;;;SAYD,aACL,kBACA;IACG,WAAW,QAAQ;;;;;;;;;;;SAqBX,QAAQ,kBAAkB,oBAAoB,QAAQ;MAU/D;EAKJ,UAAU,UAAU;EASpB,mBAAmB;MAMf;MAIA,aAAa;EAIX,KAAK,eAAe;EAQpB,SAAS;UAMD;;;;cCrKH;iBAEG,OAAO,aAAa;iBAIpB,OAAO,eAAe;iBAMtB,QAAQ,KAAK,0BAA0B;EAAS;;iBAGhD,OAAO,KAAK,0BAA0B;EAAS,OAAO;;iBAGtD,QAAQ,KAAK,0BAA0B;EAAS,QAAQ;;iBAGxD,MAAM,KAAK,0BAA0B;EAAS;IAAQ;IAAc;IAAkB;;;iBAGtF,OAAO,KAAK,0BAA0B;EAAS;IAAS;IAAc"}
|
package/dist/remote/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { s as spawnAsync, t as defineActor } from "../src-
|
|
1
|
+
import { s as spawnAsync, t as defineActor } from "../src-BLzdjrVl.js";
|
|
2
2
|
import { a as stopPropagation } from "../hooks-V-PEPJHv.js";
|
|
3
3
|
import { open, unlink } from "node:fs/promises";
|
|
4
|
-
import { createReadStream } from "node:fs";
|
|
4
|
+
import { createReadStream, createWriteStream } from "node:fs";
|
|
5
5
|
import * as readline from "node:readline";
|
|
6
6
|
import { execSync, spawn } from "node:child_process";
|
|
7
7
|
import { createHash, randomUUID } from "node:crypto";
|
|
@@ -28,26 +28,35 @@ var FifoUtf8NlineTransport = class FifoUtf8NlineTransport {
|
|
|
28
28
|
if (this.pvtOnMessage && !this.closed) this.pvtOnMessage(line);
|
|
29
29
|
});
|
|
30
30
|
this.rl.on("close", () => {
|
|
31
|
-
this.
|
|
31
|
+
this.close();
|
|
32
32
|
});
|
|
33
33
|
this.rs.on("error", (err) => {
|
|
34
34
|
this.pvtError = err;
|
|
35
|
-
|
|
36
|
-
});
|
|
37
|
-
this.rl.on("error", (err) => {
|
|
38
|
-
this.pvtError = err;
|
|
39
|
-
if (!this.closed) this.closed = true;
|
|
35
|
+
this.close();
|
|
40
36
|
});
|
|
41
37
|
} else {
|
|
42
38
|
this.rs = null;
|
|
43
39
|
this.rl = null;
|
|
44
40
|
}
|
|
41
|
+
if (this.writeFd) {
|
|
42
|
+
this.ws = createWriteStream("", {
|
|
43
|
+
fd: this.writeFd.fd,
|
|
44
|
+
encoding: "utf-8",
|
|
45
|
+
autoclose: false
|
|
46
|
+
});
|
|
47
|
+
this.ws.on("error", (err) => {
|
|
48
|
+
this.pvtError = err;
|
|
49
|
+
this.close();
|
|
50
|
+
});
|
|
51
|
+
} else this.ws = null;
|
|
45
52
|
}
|
|
46
53
|
static async openReader(path) {
|
|
47
|
-
|
|
54
|
+
const readFd = await open(path, "r");
|
|
55
|
+
return new FifoUtf8NlineTransport({ readFd });
|
|
48
56
|
}
|
|
49
57
|
static async openWriter(path) {
|
|
50
|
-
|
|
58
|
+
const writeFd = await open(path, "w");
|
|
59
|
+
return new FifoUtf8NlineTransport({ writeFd });
|
|
51
60
|
}
|
|
52
61
|
static fromFds(readFd, writeFd) {
|
|
53
62
|
return new FifoUtf8NlineTransport({
|
|
@@ -115,19 +124,45 @@ var FifoUtf8NlineTransport = class FifoUtf8NlineTransport {
|
|
|
115
124
|
if (this.closed) throw new Error("FifoUtf8NlineTransport: closed");
|
|
116
125
|
if (this.writeFd === null) throw new Error("FifoUtf8NlineTransport: not a writer");
|
|
117
126
|
if (!line.endsWith("\n")) line += "\n";
|
|
118
|
-
await this.
|
|
127
|
+
await this.ws.write(line);
|
|
119
128
|
}
|
|
120
129
|
async close() {
|
|
121
|
-
|
|
130
|
+
this.closingPromise = this.closingPromise || this.pvtClose();
|
|
131
|
+
await this.closingPromise;
|
|
122
132
|
this.closed = true;
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
133
|
+
}
|
|
134
|
+
async pvtClose() {
|
|
135
|
+
await Promise.resolve();
|
|
136
|
+
if (this.rl) {
|
|
137
|
+
this.rl.close();
|
|
138
|
+
this.rl = null;
|
|
139
|
+
}
|
|
140
|
+
if (this.rs) {
|
|
141
|
+
this.rs.destroy();
|
|
142
|
+
this.rs = null;
|
|
143
|
+
}
|
|
144
|
+
if (this.ws) {
|
|
145
|
+
await new Promise(async (resolve) => {
|
|
146
|
+
try {
|
|
147
|
+
await this.ws.end("", resolve);
|
|
148
|
+
} catch {
|
|
149
|
+
resolve();
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
this.ws = null;
|
|
153
|
+
}
|
|
154
|
+
if (this.readFd) {
|
|
155
|
+
try {
|
|
156
|
+
await this.readFd.close();
|
|
157
|
+
} catch {}
|
|
158
|
+
this.readFd = null;
|
|
159
|
+
}
|
|
160
|
+
if (this.writeFd) {
|
|
161
|
+
try {
|
|
162
|
+
await this.writeFd.close();
|
|
163
|
+
} catch {}
|
|
164
|
+
this.writeFd = null;
|
|
165
|
+
}
|
|
131
166
|
if (this.pvtWriter) await this.pvtWriter.close();
|
|
132
167
|
}
|
|
133
168
|
};
|
|
@@ -192,18 +227,28 @@ async function runChild(fn) {
|
|
|
192
227
|
ctx.parentId = parentId;
|
|
193
228
|
return yield* fn(ctx, args);
|
|
194
229
|
};
|
|
195
|
-
const proc = spawnAsync(wrappedFn, "remote"
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
230
|
+
const proc = spawnAsync(wrappedFn, "remote")(initArgs);
|
|
231
|
+
proc.subscribe("message", async (msg, sender) => {
|
|
232
|
+
try {
|
|
233
|
+
const encodedMsg = encode("$msg", {
|
|
234
|
+
fromName: sender.fromName,
|
|
235
|
+
body: msg
|
|
236
|
+
});
|
|
237
|
+
await transport.send(encodedMsg);
|
|
238
|
+
} catch (e) {
|
|
239
|
+
console.error("Error sending out the message");
|
|
240
|
+
}
|
|
241
|
+
});
|
|
242
|
+
proc.subscribe("state", async () => {
|
|
243
|
+
try {
|
|
244
|
+
const encodedState = encode("$state", proc.state);
|
|
245
|
+
await transport.send(encodedState);
|
|
246
|
+
} catch (e) {
|
|
247
|
+
console.error("Error sending out the message", e);
|
|
248
|
+
}
|
|
249
|
+
});
|
|
202
250
|
await proc.ready();
|
|
203
251
|
await transport.send(encode("$state", proc.state));
|
|
204
|
-
proc.subscribe(() => {
|
|
205
|
-
transport.send(encode("$state", proc.state)).catch(() => {});
|
|
206
|
-
});
|
|
207
252
|
transport.onMessage((line) => {
|
|
208
253
|
const msg = decode(line);
|
|
209
254
|
if (isMsg(msg)) {
|
|
@@ -219,7 +264,7 @@ async function runChild(fn) {
|
|
|
219
264
|
code,
|
|
220
265
|
state: proc.state
|
|
221
266
|
}));
|
|
222
|
-
transport.close();
|
|
267
|
+
await transport.close();
|
|
223
268
|
process.exit(code);
|
|
224
269
|
};
|
|
225
270
|
proc.wait().then(() => shutdown(0), (err) => {
|
|
@@ -316,7 +361,6 @@ async function spawnRemote(opts) {
|
|
|
316
361
|
send(msg) {
|
|
317
362
|
const from = opts.parentName ?? "host";
|
|
318
363
|
transport.send(encode("$msg", {
|
|
319
|
-
type: msg.type,
|
|
320
364
|
fromName: from,
|
|
321
365
|
body: msg
|
|
322
366
|
}));
|
|
@@ -345,17 +389,15 @@ function scriptConnector(runner, runnerArgs) {
|
|
|
345
389
|
};
|
|
346
390
|
}
|
|
347
391
|
/** Spawn via `bun run <script>`. */
|
|
348
|
-
const bunConnector = scriptConnector("bun", [
|
|
392
|
+
const bunConnector = scriptConnector("bun", []);
|
|
349
393
|
/** Spawn via `node <script>`. */
|
|
350
394
|
const nodeConnector = scriptConnector("node", []);
|
|
351
395
|
/**
|
|
352
|
-
* Auto-detect: prefers `bun run` if
|
|
396
|
+
* Auto-detect: prefers `bun run` if bun is
|
|
353
397
|
* the current runtime, otherwise falls back to `node`.
|
|
354
398
|
*/
|
|
355
399
|
function defaultConnector(scriptPath) {
|
|
356
|
-
|
|
357
|
-
const isTs = scriptPath.endsWith(".ts");
|
|
358
|
-
if (isBun && isTs) return bunConnector(scriptPath);
|
|
400
|
+
if (typeof globalThis.Bun !== "undefined") return bunConnector(scriptPath);
|
|
359
401
|
return nodeConnector(scriptPath);
|
|
360
402
|
}
|
|
361
403
|
const commandConnector = spawnRemote;
|