posipaki 0.13.0 → 0.14.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/actor-types-B4Yn1k1C.d.ts +69 -0
- package/dist/actor-types-B4Yn1k1C.d.ts.map +1 -0
- package/dist/hooks-BdNEs0DD.d.ts +48 -0
- package/dist/hooks-BdNEs0DD.d.ts.map +1 -0
- package/dist/hooks.d.ts +2 -48
- package/dist/index.d.ts +5 -66
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -476
- package/dist/pipe.d.ts +1 -1
- package/dist/pipe.js +1 -1
- package/dist/pipe.js.map +1 -1
- package/dist/plugins/debug-logger.d.ts +1 -1
- package/dist/plugins/rbac.d.ts +1 -1
- package/dist/plugins/timeout-guard.d.ts +1 -1
- package/dist/{process-DSljemNS.d.ts → process-oAztLPCm.d.ts} +2 -2
- package/dist/process-oAztLPCm.d.ts.map +1 -0
- package/dist/remote/index.d.ts +127 -0
- package/dist/remote/index.d.ts.map +1 -0
- package/dist/remote/index.js +414 -0
- package/dist/remote/index.js.map +1 -0
- package/dist/src-CqzaKQBZ.js +489 -0
- package/dist/src-CqzaKQBZ.js.map +1 -0
- package/dist/supervisor.d.ts +2 -2
- package/dist/supervisor.js +1 -1
- package/dist/{types-DW-t7vov.d.ts → types-C6plZEPj.d.ts} +19 -17
- package/dist/types-C6plZEPj.d.ts.map +1 -0
- package/dist/{util-Cw64MseZ.js → util-DsfVKxTT.js} +2 -2
- package/dist/util-DsfVKxTT.js.map +1 -0
- package/dist/xfetch.d.ts +2 -2
- package/dist/xfetch.js +1 -1
- package/dist/xfetch.js.map +1 -1
- package/package.json +14 -10
- package/dist/hooks.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/process-DSljemNS.d.ts.map +0 -1
- package/dist/types-DW-t7vov.d.ts.map +0 -1
- package/dist/util-Cw64MseZ.js.map +0 -1
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { a as ProcessCtx, n as ExitMessage, p as AsyncProcess, r as Message, s as SenderInfo, t as AsyncProcessFn } from "./types-C6plZEPj.js";
|
|
2
|
+
import { f as PluginTransform, i as HookResult, n as ActorPlugin, t as ActorDecorated, u as OnStartHook } from "./hooks-BdNEs0DD.js";
|
|
3
|
+
|
|
4
|
+
//#region src/actor-types.d.ts
|
|
5
|
+
type ActorMessages<M extends Message> = {
|
|
6
|
+
__tag_messages: M;
|
|
7
|
+
};
|
|
8
|
+
interface MethodOptions {
|
|
9
|
+
[key: string]: Function;
|
|
10
|
+
}
|
|
11
|
+
type HandlerFn<InMsg extends Message> = (msg: InMsg, sender: SenderInfo) => void | Promise<void>;
|
|
12
|
+
type HandlerOptions<InMsg extends Message> = Omit<{ [K in InMsg["type"]]: HandlerFn<Extract<InMsg, {
|
|
13
|
+
type: K;
|
|
14
|
+
}>> }, "STOP">;
|
|
15
|
+
interface ActorDefinition<Args, ExposedState, InMsg extends Message, OutMsg extends Message, Handlers extends HandlerOptions<InMsg>> {
|
|
16
|
+
fn: AsyncProcessFn<Args, ExposedState, InMsg, OutMsg>;
|
|
17
|
+
config: ActorConfig<Args, any, ExposedState, InMsg, OutMsg, {}, Handlers>;
|
|
18
|
+
/** Preferred process name (from config.name). */
|
|
19
|
+
name?: string;
|
|
20
|
+
/** Raw plugin config (array or transform). Resolved at fork time. @internal */
|
|
21
|
+
pvtPluginsRaw?: ActorPlugin[] | PluginTransform;
|
|
22
|
+
/** Spawn this actor as a standalone process. */
|
|
23
|
+
spawn(args: Args): AsyncProcess<Args, ExposedState, InMsg, OutMsg>;
|
|
24
|
+
/** Spawn this actor as a child of the calling process. */
|
|
25
|
+
spawnAsChild(ctx: ProcessCtx<any, any, any, any>, args: Args, name?: string): AsyncProcess<Args, ExposedState, InMsg, OutMsg>;
|
|
26
|
+
}
|
|
27
|
+
interface ActorHooksConfig<Args, InternalState, ExposedState, InMsg extends Message, OutMsg extends Message, Methods extends MethodOptions, Handlers extends HandlerOptions<InMsg>> {
|
|
28
|
+
onStart?: OnStartHook<ExposedState>;
|
|
29
|
+
onMessage?: (this: ActorContext<Args, InternalState, InMsg, OutMsg, Methods, Handlers>, msg: InMsg, sender: SenderInfo) => HookResult | Promise<HookResult>;
|
|
30
|
+
onEmit?: (this: ActorContext<Args, InternalState, InMsg, OutMsg, Methods, Handlers>, msg: OutMsg) => void;
|
|
31
|
+
onChildExit?: (this: ActorContext<Args, InternalState, InMsg, OutMsg, Methods, Handlers>, name: string) => void | Promise<void>;
|
|
32
|
+
onStopRequested?: (this: ActorContext<Args, InternalState, InMsg, OutMsg, Methods, Handlers>) => void | Promise<void>;
|
|
33
|
+
onEnd?: (this: ActorContext<Args, InternalState, InMsg, OutMsg, Methods, Handlers>, reason: unknown) => void | Promise<void>;
|
|
34
|
+
onError?: (this: ActorContext<Args, InternalState, InMsg, OutMsg, Methods, Handlers>, err: unknown) => void;
|
|
35
|
+
}
|
|
36
|
+
interface ActorConfig<Args, InternalState, ExposedState, InMsg extends Message, OutMsg extends Message, Methods extends MethodOptions, Handlers extends HandlerOptions<InMsg>> {
|
|
37
|
+
initialState?: InternalState | ((this: void, args: Args, ctx: ActorContext<Args, InternalState, InMsg, OutMsg, Methods, Handlers>["ctx"]) => InternalState);
|
|
38
|
+
expose?: (internalState: InternalState) => ExposedState;
|
|
39
|
+
/** Preferred process name. Used by ctx.fork() when no explicit name is given. */
|
|
40
|
+
name?: string;
|
|
41
|
+
hooks?: ActorHooksConfig<Args, InternalState, ExposedState, InMsg, OutMsg, Methods, Handlers>;
|
|
42
|
+
/** Plugins installed at fork time. Array = replace, function = transform parent chain. */
|
|
43
|
+
plugins?: ActorPlugin[] | PluginTransform;
|
|
44
|
+
outMessages?: ActorMessages<OutMsg>;
|
|
45
|
+
inMessages?: ActorMessages<InMsg>;
|
|
46
|
+
setup?: (this: ActorContext<Args, InternalState, InMsg, OutMsg, Methods, Handlers>, args: Args) => InternalState | Promise<InternalState>;
|
|
47
|
+
afterStart?: (this: ActorContext<Args, InternalState, InMsg, OutMsg, Methods, Handlers>) => void | Promise<void>;
|
|
48
|
+
onStart?: (this: ActorContext<Args, InternalState, InMsg, OutMsg, Methods, Handlers>, args: Args) => void | Promise<void>;
|
|
49
|
+
onStopRequested?: (this: ActorContext<Args, InternalState, InMsg, OutMsg, Methods, Handlers>) => void | Promise<void>;
|
|
50
|
+
onEnd?: (this: ActorContext<Args, InternalState, InMsg, OutMsg, Methods, Handlers>, reason?: unknown) => void | Promise<void>;
|
|
51
|
+
handlers: Handlers & ThisType<ActorContext<Args, InternalState, InMsg, OutMsg, Methods, Handlers>>;
|
|
52
|
+
methods?: Methods & ThisType<ActorContext<Args, InternalState, InMsg, OutMsg, Methods, Handlers>>;
|
|
53
|
+
onUnhandled?: (this: ActorContext<Args, InternalState, InMsg, OutMsg, Methods, Handlers>, msg: InMsg, sender: SenderInfo) => void | Promise<void>;
|
|
54
|
+
onChildExit?: (this: ActorContext<Args, InternalState, InMsg, OutMsg, Methods, Handlers>, name: string, reason: ExitMessage) => void | Promise<void>;
|
|
55
|
+
}
|
|
56
|
+
type ActorContext<Args, InternalState, InMsg extends Message, OutMsg extends Message, Methods extends MethodOptions, Handlers extends HandlerOptions<InMsg>> = Methods & ActorDecorated & {
|
|
57
|
+
state: InternalState;
|
|
58
|
+
name: string;
|
|
59
|
+
id: symbol;
|
|
60
|
+
emit: (msg: OutMsg) => void;
|
|
61
|
+
agreeToStop: () => void;
|
|
62
|
+
exit: (reason?: unknown) => void;
|
|
63
|
+
$child: Record<string, AsyncProcess<unknown, unknown, Message, Message>>;
|
|
64
|
+
fork<A, S, IM extends Message, OM extends Message, H extends HandlerOptions<IM>>(fn: AsyncProcessFn<A, S, IM, OM> | ActorDefinition<A, S, IM, OM, H>, name?: string, args?: A): AsyncProcess<A, S, IM, OM>;
|
|
65
|
+
ctx: ProcessCtx<Args, InternalState, InMsg, OutMsg>;
|
|
66
|
+
};
|
|
67
|
+
//#endregion
|
|
68
|
+
export { HandlerFn as a, ActorMessages as i, ActorContext as n, HandlerOptions as o, ActorDefinition as r, MethodOptions as s, ActorConfig as t };
|
|
69
|
+
//# sourceMappingURL=actor-types-B4Yn1k1C.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"actor-types-B4Yn1k1C.d.ts","names":[],"sources":["../src/actor-types.ts"],"mappings":";;;;KAuBY,aAAA,WAAwB,OAAA;EAClC,cAAA,EAAgB,CAAC;AAAA;AAAA,UAEF,aAAA;EAAA,CACd,GAAA,WAAc,QAAQ;AAAA;AAAA,KAEb,SAAA,eAAwB,OAAA,KAClC,GAAA,EAAK,KAAA,EACL,MAAA,EAAQ,UAAA,YACE,OAAA;AAAA,KACA,cAAA,eAA6B,OAAA,IAAW,IAAA,SAE1C,KAAA,WAAgB,SAAA,CAAU,OAAA,CAAQ,KAAA;EAAS,IAAA,EAAM,CAAA;AAAA;AAAA,UAK1C,eAAA,mCAGD,OAAA,iBACC,OAAA,mBAEE,cAAA,CAAe,KAAA;EAEhC,EAAA,EAAI,cAAA,CAAe,IAAA,EAAM,YAAA,EAAc,KAAA,EAAO,MAAA;EAC9C,MAAA,EAAQ,WAAA,CAAY,IAAA,OAAW,YAAA,EAAc,KAAA,EAAO,MAAA,MAAY,QAAA;EAtBzC;EAwBvB,IAAA;EAtBmB;EAwBnB,aAAA,GAAgB,WAAA,KAAgB,eAAA;EAxBE;EA0BlC,KAAA,CAAM,IAAA,EAAM,IAAA,GAAO,YAAA,CAAa,IAAA,EAAM,YAAA,EAAc,KAAA,EAAO,MAAA;EAxBnD;EA0BR,YAAA,CACE,GAAA,EAAK,UAAA,sBACL,IAAA,EAAM,IAAA,EACN,IAAA,YACC,YAAA,CAAa,IAAA,EAAM,YAAA,EAAc,KAAA,EAAO,MAAA;AAAA;AAAA,UAG5B,gBAAA,kDAID,OAAA,iBACC,OAAA,kBACC,aAAA,mBAEC,cAAA,CAAe,KAAA;EAEhC,OAAA,GAAU,WAAA,CAAY,YAAA;EACtB,SAAA,IACE,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A;EAEZ,WAAA,IACE,IAAA,EAAM,YAAA,CAAa,IAAA,EAAM,aAAA,EAAe,KAAA,EAAO,MAAA,EAAQ,OAAA,EAAS,QAAA,GAChE,IAAA,UACA,MAAA,EAAQ,WAAA,YACE,OAAA;AAAA;AAAA,KAGF,YAAA,oCAGI,OAAA,iBACC,OAAA,kBACC,aAAA,mBAEC,cAAA,CAAe,KAAA,KAC9B,OAAA,GAAU,cAAA;EACZ,KAAA,EAAO,aAAA;EACP,IAAA;EACA,EAAA;EAEA,IAAA,GAAO,GAAA,EAAK,MAAA;EACZ,WAAA;EACA,IAAA,GAAO,MAAA;EAEP,MAAA,EAAQ,MAAA,SAAe,YAAA,mBAA+B,OAAA,EAAS,OAAA;EAE/D,IAAA,kBAGa,OAAA,aACA,OAAA,YACD,cAAA,CAAe,EAAA,GAEzB,EAAA,EAAI,cAAA,CAAe,CAAA,EAAG,CAAA,EAAG,EAAA,EAAI,EAAA,IAAM,eAAA,CAAgB,CAAA,EAAG,CAAA,EAAG,EAAA,EAAI,EAAA,EAAI,CAAA,GACjE,IAAA,WACA,IAAA,GAAO,CAAA,GACN,YAAA,CAAa,CAAA,EAAG,CAAA,EAAG,EAAA,EAAI,EAAA;EAE1B,GAAA,EAAK,UAAA,CAAW,IAAA,EAAM,aAAA,EAAe,KAAA,EAAO,MAAA;AAAA"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { a as ProcessCtx, r as Message, s as SenderInfo } from "./types-C6plZEPj.js";
|
|
2
|
+
|
|
3
|
+
//#region src/hooks.d.ts
|
|
4
|
+
/** Returned by onMessage hooks to prevent further dispatch. */
|
|
5
|
+
declare const STOP_SENTINEL: unique symbol;
|
|
6
|
+
/** Type-safe sentinel for short-circuiting onMessage hooks. */
|
|
7
|
+
declare const stopPropagation: () => typeof STOP_SENTINEL;
|
|
8
|
+
/** Return type of onMessage hooks: void (continue) or sentinel (stop). */
|
|
9
|
+
type HookResult = void | typeof STOP_SENTINEL;
|
|
10
|
+
type OnStartHook<State> = (state: State) => void | Promise<void>;
|
|
11
|
+
type OnMessageHook<InMsg extends Message> = (msg: InMsg, sender: SenderInfo) => HookResult | Promise<HookResult>;
|
|
12
|
+
type OnEmitHook<OutMsg extends Message> = (msg: OutMsg) => void;
|
|
13
|
+
type OnChildExitHook = (name: string) => void | Promise<void>;
|
|
14
|
+
type OnStopRequestedHook = () => void | Promise<void>;
|
|
15
|
+
type OnEndHook = (reason: unknown) => void | Promise<void>;
|
|
16
|
+
type OnErrorHook = (err: unknown) => void;
|
|
17
|
+
declare class HookRegistry<State, InMsg extends Message, OutMsg extends Message> {
|
|
18
|
+
onStart: Array<OnStartHook<State>>;
|
|
19
|
+
onMessage: Array<OnMessageHook<InMsg>>;
|
|
20
|
+
onEmit: Array<OnEmitHook<OutMsg>>;
|
|
21
|
+
onChildExit: Array<OnChildExitHook>;
|
|
22
|
+
onStopRequested: Array<OnStopRequestedHook>;
|
|
23
|
+
onEnd: Array<OnEndHook>;
|
|
24
|
+
onError: Array<OnErrorHook>;
|
|
25
|
+
}
|
|
26
|
+
/** A reusable unit of actor behaviour, installed at fork time. */
|
|
27
|
+
interface ActorPlugin<InMsg extends Message = Message, OutMsg extends Message = Message, State = unknown> {
|
|
28
|
+
name: string;
|
|
29
|
+
install(ctx: ProcessCtx<unknown, State, InMsg, OutMsg>): void | Promise<void>;
|
|
30
|
+
}
|
|
31
|
+
/** Transform parent plugins into child plugins. */
|
|
32
|
+
type PluginTransform = (parentPlugins: ActorPlugin[]) => ActorPlugin[];
|
|
33
|
+
/**
|
|
34
|
+
* Interface that plugins can augment via declaration merging.
|
|
35
|
+
* Plugins ship a .d.ts that adds properties to this interface,
|
|
36
|
+
* making them available on `this` in handlers and methods.
|
|
37
|
+
*
|
|
38
|
+
* Example (in a plugin's .d.ts):
|
|
39
|
+
* declare module 'posipaki' {
|
|
40
|
+
* interface ActorDecorated {
|
|
41
|
+
* log: Logger;
|
|
42
|
+
* }
|
|
43
|
+
* }
|
|
44
|
+
*/
|
|
45
|
+
interface ActorDecorated {}
|
|
46
|
+
//#endregion
|
|
47
|
+
export { OnChildExitHook as a, OnErrorHook as c, OnStopRequestedHook as d, PluginTransform as f, HookResult as i, OnMessageHook as l, stopPropagation as m, ActorPlugin as n, OnEmitHook as o, STOP_SENTINEL as p, HookRegistry as r, OnEndHook as s, ActorDecorated as t, OnStartHook as u };
|
|
48
|
+
//# sourceMappingURL=hooks-BdNEs0DD.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks-BdNEs0DD.d.ts","names":[],"sources":["../src/hooks.ts"],"mappings":";;;;cAWa,aAAA;AAAb;AAAA,cAGa,eAAA,eAA6B,aAA8B;;KAG5D,UAAA,iBAA2B,aAAa;AAAA,KAIxC,WAAA,WAAsB,KAAA,EAAO,KAAA,YAAiB,OAAO;AAAA,KACrD,aAAA,eAA4B,OAAA,KAAY,GAAA,EAAK,KAAA,EAAO,MAAA,EAAQ,UAAA,KAAe,UAAA,GAAa,OAAA,CAAQ,UAAA;AAAA,KAChG,UAAA,gBAA0B,OAAA,KAAY,GAAA,EAAK,MAAM;AAAA,KACjD,eAAA,IAAmB,IAAA,oBAAwB,OAAO;AAAA,KAClD,mBAAA,gBAAmC,OAAO;AAAA,KAC1C,SAAA,IAAa,MAAA,qBAA2B,OAAO;AAAA,KAC/C,WAAA,IAAe,GAAY;AAAA,cAI1B,YAAA,sBAAkC,OAAA,iBAAwB,OAAA;EACrE,OAAA,EAAS,KAAA,CAAM,WAAA,CAAY,KAAA;EAC3B,SAAA,EAAW,KAAA,CAAM,aAAA,CAAc,KAAA;EAC/B,MAAA,EAAQ,KAAA,CAAM,UAAA,CAAW,MAAA;EACzB,WAAA,EAAa,KAAA,CAAM,eAAA;EACnB,eAAA,EAAiB,KAAA,CAAM,mBAAA;EACvB,KAAA,EAAO,KAAA,CAAM,SAAA;EACb,OAAA,EAAS,KAAA,CAAM,WAAA;AAAA;;UAOA,WAAA,eACD,OAAA,GAAU,OAAA,iBACT,OAAA,GAAU,OAAA;EAGzB,IAAA;EACA,OAAA,CAAQ,GAAA,EAAK,UAAA,UAAoB,KAAA,EAAO,KAAA,EAAO,MAAA,WAAiB,OAAA;AAAA;AA7BlE;AAAA,KAiCY,eAAA,IAAmB,aAAA,EAAe,WAAA,OAAkB,WAAW;;;;;;;;;;;;;UAgB1D,cAAA"}
|
package/dist/hooks.d.ts
CHANGED
|
@@ -1,48 +1,2 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
|
|
3
|
-
//#region src/hooks.d.ts
|
|
4
|
-
/** Returned by onMessage hooks to prevent further dispatch. */
|
|
5
|
-
declare const STOP_SENTINEL: unique symbol;
|
|
6
|
-
/** Type-safe sentinel for short-circuiting onMessage hooks. */
|
|
7
|
-
declare const stopPropagation: () => typeof STOP_SENTINEL;
|
|
8
|
-
/** Return type of onMessage hooks: void (continue) or sentinel (stop). */
|
|
9
|
-
type HookResult = void | typeof STOP_SENTINEL;
|
|
10
|
-
type OnStartHook<State> = (state: State) => void | Promise<void>;
|
|
11
|
-
type OnMessageHook<InMsg extends Message> = (msg: InMsg, sender: SenderInfo) => HookResult | Promise<HookResult>;
|
|
12
|
-
type OnEmitHook<OutMsg extends Message> = (msg: OutMsg) => void;
|
|
13
|
-
type OnChildExitHook = (name: string) => void | Promise<void>;
|
|
14
|
-
type OnStopRequestedHook = () => void | Promise<void>;
|
|
15
|
-
type OnEndHook = (reason: unknown) => void | Promise<void>;
|
|
16
|
-
type OnErrorHook = (err: unknown) => void;
|
|
17
|
-
declare class HookRegistry<State, InMsg extends Message, OutMsg extends Message> {
|
|
18
|
-
onStart: Array<OnStartHook<State>>;
|
|
19
|
-
onMessage: Array<OnMessageHook<InMsg>>;
|
|
20
|
-
onEmit: Array<OnEmitHook<OutMsg>>;
|
|
21
|
-
onChildExit: Array<OnChildExitHook>;
|
|
22
|
-
onStopRequested: Array<OnStopRequestedHook>;
|
|
23
|
-
onEnd: Array<OnEndHook>;
|
|
24
|
-
onError: Array<OnErrorHook>;
|
|
25
|
-
}
|
|
26
|
-
/** A reusable unit of actor behaviour, installed at fork time. */
|
|
27
|
-
interface ActorPlugin<InMsg extends Message = Message, OutMsg extends Message = Message, State = unknown> {
|
|
28
|
-
name: string;
|
|
29
|
-
install(ctx: ProcessCtx<unknown, State, InMsg, OutMsg>): void | Promise<void>;
|
|
30
|
-
}
|
|
31
|
-
/** Transform parent plugins into child plugins. */
|
|
32
|
-
type PluginTransform = (parentPlugins: ActorPlugin[]) => ActorPlugin[];
|
|
33
|
-
/**
|
|
34
|
-
* Interface that plugins can augment via declaration merging.
|
|
35
|
-
* Plugins ship a .d.ts that adds properties to this interface,
|
|
36
|
-
* making them available on `this` in handlers and methods.
|
|
37
|
-
*
|
|
38
|
-
* Example (in a plugin's .d.ts):
|
|
39
|
-
* declare module 'posipaki' {
|
|
40
|
-
* interface ActorDecorated {
|
|
41
|
-
* log: Logger;
|
|
42
|
-
* }
|
|
43
|
-
* }
|
|
44
|
-
*/
|
|
45
|
-
interface ActorDecorated {}
|
|
46
|
-
//#endregion
|
|
47
|
-
export { ActorDecorated, ActorPlugin, HookRegistry, HookResult, OnChildExitHook, OnEmitHook, OnEndHook, OnErrorHook, OnMessageHook, OnStartHook, OnStopRequestedHook, PluginTransform, STOP_SENTINEL, stopPropagation };
|
|
48
|
-
//# sourceMappingURL=hooks.d.ts.map
|
|
1
|
+
import { a as OnChildExitHook, c as OnErrorHook, d as OnStopRequestedHook, f as PluginTransform, i as HookResult, l as OnMessageHook, m as stopPropagation, n as ActorPlugin, o as OnEmitHook, p as STOP_SENTINEL, r as HookRegistry, s as OnEndHook, t as ActorDecorated, u as OnStartHook } from "./hooks-BdNEs0DD.js";
|
|
2
|
+
export { ActorDecorated, ActorPlugin, HookRegistry, HookResult, OnChildExitHook, OnEmitHook, OnEndHook, OnErrorHook, OnMessageHook, OnStartHook, OnStopRequestedHook, PluginTransform, STOP_SENTINEL, stopPropagation };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,75 +1,14 @@
|
|
|
1
|
-
import { a as ProcessCtx, c as SenderOrigin, d as WithSender, f as WithoutSender, h as spawnAsync, i as PipeState, l as StopMessage, m as runDispatchAsync, n as ExitMessage, o as ProcessFn, p as AsyncProcess, r as Message, s as SenderInfo, t as AsyncProcessFn, u as SupervisorState } from "./types-
|
|
2
|
-
import {
|
|
3
|
-
import { n as spawn, r as runDispatch, t as Process } from "./process-
|
|
1
|
+
import { a as ProcessCtx, c as SenderOrigin, d as WithSender, f as WithoutSender, h as spawnAsync, i as PipeState, l as StopMessage, m as runDispatchAsync, n as ExitMessage, o as ProcessFn, p as AsyncProcess, r as Message, s as SenderInfo, t as AsyncProcessFn, u as SupervisorState } from "./types-C6plZEPj.js";
|
|
2
|
+
import { a as OnChildExitHook, c as OnErrorHook, d as OnStopRequestedHook, f as PluginTransform, i as HookResult, l as OnMessageHook, m as stopPropagation, n as ActorPlugin, o as OnEmitHook, r as HookRegistry, s as OnEndHook, t as ActorDecorated, u as OnStartHook } from "./hooks-BdNEs0DD.js";
|
|
3
|
+
import { n as spawn, r as runDispatch, t as Process } from "./process-oAztLPCm.js";
|
|
4
|
+
import { a as HandlerFn, i as ActorMessages, n as ActorContext, o as HandlerOptions, r as ActorDefinition, s as MethodOptions, t as ActorConfig } from "./actor-types-B4Yn1k1C.js";
|
|
4
5
|
|
|
5
6
|
//#region src/adapters.d.ts
|
|
6
7
|
declare function asyncify<A, S, IM extends Message, OM extends Message>(fn: ProcessFn<A, S, IM, OM>): AsyncProcessFn<A, S, IM, OM>;
|
|
7
8
|
//#endregion
|
|
8
|
-
//#region src/actor-types.d.ts
|
|
9
|
-
type ActorMessages<M extends Message> = {
|
|
10
|
-
__tag_messages: M;
|
|
11
|
-
};
|
|
12
|
-
interface MethodOptions {
|
|
13
|
-
[key: string]: Function;
|
|
14
|
-
}
|
|
15
|
-
type HandlerFn<InMsg extends Message> = (msg: InMsg, sender: SenderInfo) => void | Promise<void>;
|
|
16
|
-
type HandlerOptions<InMsg extends Message> = Omit<{ [K in InMsg["type"]]: HandlerFn<Extract<InMsg, {
|
|
17
|
-
type: K;
|
|
18
|
-
}>> }, "STOP">;
|
|
19
|
-
interface ActorDefinition<Args, ExposedState, InMsg extends Message, OutMsg extends Message, Handlers extends HandlerOptions<InMsg>> {
|
|
20
|
-
fn: AsyncProcessFn<Args, ExposedState, InMsg, OutMsg>;
|
|
21
|
-
config: ActorConfig<Args, any, ExposedState, InMsg, OutMsg, {}, Handlers>;
|
|
22
|
-
/** Preferred process name (from config.name). */
|
|
23
|
-
name?: string;
|
|
24
|
-
/** Raw plugin config (array or transform). Resolved at fork time. @internal */
|
|
25
|
-
_pluginsRaw?: ActorPlugin[] | PluginTransform;
|
|
26
|
-
/** Spawn this actor as a standalone process. */
|
|
27
|
-
spawn(args: Args): AsyncProcess<Args, ExposedState, InMsg, OutMsg>;
|
|
28
|
-
/** Spawn this actor as a child of the calling process. */
|
|
29
|
-
spawnAsChild(ctx: ProcessCtx<any, any, any, any>, args: Args, name?: string): AsyncProcess<Args, ExposedState, InMsg, OutMsg>;
|
|
30
|
-
}
|
|
31
|
-
interface ActorHooksConfig<Args, InternalState, ExposedState, InMsg extends Message, OutMsg extends Message, Methods extends MethodOptions, Handlers extends HandlerOptions<InMsg>> {
|
|
32
|
-
onStart?: OnStartHook<ExposedState>;
|
|
33
|
-
onMessage?: (this: ActorContext<Args, InternalState, InMsg, OutMsg, Methods, Handlers>, msg: InMsg, sender: SenderInfo) => HookResult | Promise<HookResult>;
|
|
34
|
-
onEmit?: (this: ActorContext<Args, InternalState, InMsg, OutMsg, Methods, Handlers>, msg: OutMsg) => void;
|
|
35
|
-
onChildExit?: (this: ActorContext<Args, InternalState, InMsg, OutMsg, Methods, Handlers>, name: string) => void | Promise<void>;
|
|
36
|
-
onStopRequested?: (this: ActorContext<Args, InternalState, InMsg, OutMsg, Methods, Handlers>) => void | Promise<void>;
|
|
37
|
-
onEnd?: (this: ActorContext<Args, InternalState, InMsg, OutMsg, Methods, Handlers>, reason: unknown) => void | Promise<void>;
|
|
38
|
-
onError?: (this: ActorContext<Args, InternalState, InMsg, OutMsg, Methods, Handlers>, err: unknown) => void;
|
|
39
|
-
}
|
|
40
|
-
interface ActorConfig<Args, InternalState, ExposedState, InMsg extends Message, OutMsg extends Message, Methods extends MethodOptions, Handlers extends HandlerOptions<InMsg>> {
|
|
41
|
-
initialState: InternalState | ((this: void, args: Args, ctx: ActorContext<Args, InternalState, InMsg, OutMsg, Methods, Handlers>["ctx"]) => InternalState);
|
|
42
|
-
expose?: (internalState: InternalState) => ExposedState;
|
|
43
|
-
/** Preferred process name. Used by ctx.fork() when no explicit name is given. */
|
|
44
|
-
name?: string;
|
|
45
|
-
hooks?: ActorHooksConfig<Args, InternalState, InMsg, OutMsg, Methods, Handlers>;
|
|
46
|
-
/** Plugins installed at fork time. Array = replace, function = transform parent chain. */
|
|
47
|
-
plugins?: ActorPlugin[] | PluginTransform;
|
|
48
|
-
outMessages?: ActorMessages<OutMsg>;
|
|
49
|
-
inMessages?: ActorMessages<InMsg>;
|
|
50
|
-
onStart?: (this: ActorContext<Args, InternalState, InMsg, OutMsg, Methods, Handlers>, args: Args) => void | Promise<void>;
|
|
51
|
-
onStopRequested?: (this: ActorContext<Args, InternalState, InMsg, OutMsg, Methods, Handlers>) => void | Promise<void>;
|
|
52
|
-
onEnd?: (this: ActorContext<Args, InternalState, InMsg, OutMsg, Methods, Handlers>, reason?: unknown) => void | Promise<void>;
|
|
53
|
-
handlers: Handlers & ThisType<ActorContext<Args, InternalState, InMsg, OutMsg, Methods, Handlers>>;
|
|
54
|
-
methods?: Methods & ThisType<ActorContext<Args, InternalState, InMsg, OutMsg, Methods, Handlers>>;
|
|
55
|
-
onUnhandled?: (this: ActorContext<Args, InternalState, InMsg, OutMsg, Methods, Handlers>, msg: InMsg, sender: SenderInfo) => void | Promise<void>;
|
|
56
|
-
onChildExit?: (this: ActorContext<Args, InternalState, InMsg, OutMsg, Methods, Handlers>, name: string, reason: ExitMessage) => void | Promise<void>;
|
|
57
|
-
}
|
|
58
|
-
type ActorContext<Args, InternalState, InMsg extends Message, OutMsg extends Message, Methods extends MethodOptions, Handlers extends HandlerOptions<InMsg>> = Methods & ActorDecorated & {
|
|
59
|
-
state: InternalState;
|
|
60
|
-
name: string;
|
|
61
|
-
id: symbol;
|
|
62
|
-
emit: (msg: OutMsg) => void;
|
|
63
|
-
agreeToStop: () => void;
|
|
64
|
-
exit: (reason?: unknown) => void;
|
|
65
|
-
$child: Record<string, AsyncProcess<unknown, unknown, Message, Message>>;
|
|
66
|
-
fork<A, S, IM extends Message, OM extends Message, H extends HandlerOptions<IM>>(fn: AsyncProcessFn<A, S, IM, OM> | ActorDefinition<A, S, IM, OM, H>, name?: string, args?: A): AsyncProcess<A, S, IM, OM>;
|
|
67
|
-
ctx: ProcessCtx<Args, InternalState, InMsg, OutMsg>;
|
|
68
|
-
};
|
|
69
|
-
//#endregion
|
|
70
9
|
//#region src/define-actor.d.ts
|
|
71
10
|
declare function defineMessages<OutMsg extends Message = Message>(): ActorMessages<OutMsg>;
|
|
72
11
|
declare function defineActor<Args, InternalState, ExposedState, InMsg extends Message, OutMsg extends Message, Methods extends MethodOptions, Handlers extends HandlerOptions<InMsg>>(config: ActorConfig<Args, InternalState, ExposedState, InMsg, OutMsg, Methods, Handlers>): ActorDefinition<Args, ExposedState, InMsg, OutMsg, Handlers>;
|
|
73
12
|
//#endregion
|
|
74
|
-
export { type ActorConfig, type ActorContext, type ActorDecorated
|
|
13
|
+
export { type ActorConfig, type ActorContext, type ActorDecorated, type ActorDefinition, type ActorPlugin, AsyncProcess, type AsyncProcessFn, type ExitMessage, type HandlerFn, type HandlerOptions, HookRegistry, type HookResult, type Message, type MethodOptions, type OnChildExitHook, type OnEmitHook, type OnEndHook, type OnErrorHook, type OnMessageHook, type OnStartHook, type OnStopRequestedHook, type PipeState, type PluginTransform, Process, type ProcessCtx, type ProcessFn, type SenderInfo, type SenderOrigin, type StopMessage, type SupervisorState, type WithSender, type WithoutSender, asyncify, defineActor, defineMessages, runDispatch, runDispatchAsync, spawn, spawnAsync, stopPropagation };
|
|
75
14
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/adapters.ts","../src/
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/adapters.ts","../src/define-actor.ts"],"mappings":";;;;;;iBAEgB,QAAA,kBAA0B,OAAA,aAAoB,OAAA,EAC5D,EAAA,EAAI,SAAA,CAAU,CAAA,EAAG,CAAA,EAAG,EAAA,EAAI,EAAA,IACvB,cAAA,CAAe,CAAA,EAAG,CAAA,EAAG,EAAA,EAAI,EAAA;;;iBC6BZ,cAAA,gBACC,OAAA,GAAU,OAAA,KACtB,aAAA,CAAc,MAAA;AAAA,iBAIH,WAAA,kDAIA,OAAA,iBACC,OAAA,kBACC,aAAA,mBACC,cAAA,CAAe,KAAA,GAEhC,MAAA,EAAQ,WAAA,CACN,IAAA,EACA,aAAA,EACA,YAAA,EACA,KAAA,EACA,MAAA,EACA,OAAA,EACA,QAAA,IAED,eAAA,CAAgB,IAAA,EAAM,YAAA,EAAc,KAAA,EAAO,MAAA,EAAQ,QAAA"}
|