posipaki 0.13.1 → 0.15.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/hooks-Czj67zNB.d.ts +127 -0
- package/dist/hooks-Czj67zNB.d.ts.map +1 -0
- package/dist/{hooks-uHIs8PJA.js → hooks-D5DhD9gu.js} +5 -2
- package/dist/hooks-D5DhD9gu.js.map +1 -0
- package/dist/hooks.d.ts +2 -48
- package/dist/hooks.js +1 -19
- package/dist/index.d.ts +4 -66
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1067
- package/dist/pipe.d.ts +1 -1
- package/dist/pipe.js.map +1 -1
- package/dist/plugins/debug-logger.d.ts +1 -1
- package/dist/plugins/debug-logger.js +6 -6
- package/dist/plugins/debug-logger.js.map +1 -1
- package/dist/plugins/rbac.d.ts +1 -1
- package/dist/plugins/rbac.js +4 -4
- package/dist/plugins/rbac.js.map +1 -1
- package/dist/plugins/timeout-guard.d.ts +1 -1
- package/dist/plugins/timeout-guard.js +4 -4
- package/dist/plugins/timeout-guard.js.map +1 -1
- package/dist/{process-C9zNB466.d.ts → process-Bf9HTr0m.d.ts} +2 -2
- package/dist/process-Bf9HTr0m.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-4KNZmXeS.js +505 -0
- package/dist/src-4KNZmXeS.js.map +1 -0
- package/dist/supervisor.d.ts +2 -2
- package/dist/{types-BeSkQz6f.d.ts → types-BLIFntvm.d.ts} +19 -23
- package/dist/types-BLIFntvm.d.ts.map +1 -0
- package/dist/util-DsfVKxTT.js.map +1 -1
- package/dist/xfetch.d.ts +2 -2
- package/package.json +6 -2
- package/dist/hooks-uHIs8PJA.js.map +0 -1
- package/dist/hooks.d.ts.map +0 -1
- package/dist/hooks.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/process-C9zNB466.d.ts.map +0 -1
- package/dist/types-BeSkQz6f.d.ts.map +0 -1
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { a as ProcessCtx, n as ExitMessage, p as AsyncProcess, r as Message, s as SenderInfo, t as AsyncProcessFn } from "./types-BLIFntvm.js";
|
|
2
|
+
|
|
3
|
+
//#region src/actor-types.d.ts
|
|
4
|
+
type ActorMessages<M extends Message> = {
|
|
5
|
+
__tag_messages: M;
|
|
6
|
+
};
|
|
7
|
+
interface MethodOptions {
|
|
8
|
+
[key: string]: Function;
|
|
9
|
+
}
|
|
10
|
+
type HandlerFn<InMsg extends Message> = (msg: InMsg, sender: SenderInfo) => void | Promise<void>;
|
|
11
|
+
type HandlerOptions<InMsg extends Message> = Omit<{ [K in InMsg["type"]]: HandlerFn<Extract<InMsg, {
|
|
12
|
+
type: K;
|
|
13
|
+
}>> }, "STOP">;
|
|
14
|
+
interface ActorDefinition<Args, ExposedState, InMsg extends Message, OutMsg extends Message, Handlers extends HandlerOptions<InMsg>, ReflectionMethods = {}> {
|
|
15
|
+
fn: AsyncProcessFn<Args, ExposedState, InMsg, OutMsg>;
|
|
16
|
+
config: ActorConfig<Args, any, ExposedState, InMsg, OutMsg, {}, Handlers>;
|
|
17
|
+
/** Preferred process name (from config.name). */
|
|
18
|
+
name?: string;
|
|
19
|
+
/** Raw plugin config (array or transform). Resolved at fork time. @internal */
|
|
20
|
+
pvtPluginsRaw?: ActorPlugin[] | PluginTransform;
|
|
21
|
+
/** Spawn this actor as a standalone process. */
|
|
22
|
+
spawn(args: Args): AsyncProcess<Args, ExposedState, InMsg, OutMsg, ReflectionMethods>;
|
|
23
|
+
/** Spawn this actor as a child of the calling process. */
|
|
24
|
+
spawnAsChild(ctx: ProcessCtx<any, any, any, any>, args: Args, name?: string): AsyncProcess<Args, ExposedState, InMsg, OutMsg, ReflectionMethods>;
|
|
25
|
+
}
|
|
26
|
+
interface ActorHooksConfig<Args, InternalState, ExposedState, InMsg extends Message, OutMsg extends Message, Methods extends MethodOptions, Handlers extends HandlerOptions<InMsg>> {
|
|
27
|
+
onStart?: OnStartHook<ExposedState>;
|
|
28
|
+
onMessage?: (this: ActorContext<Args, InternalState, InMsg, OutMsg, Methods, Handlers>, msg: InMsg, sender: SenderInfo) => HookResult | Promise<HookResult>;
|
|
29
|
+
onEmit?: (this: ActorContext<Args, InternalState, InMsg, OutMsg, Methods, Handlers>, msg: OutMsg) => void;
|
|
30
|
+
onChildExit?: (this: ActorContext<Args, InternalState, InMsg, OutMsg, Methods, Handlers>, name: string) => void | Promise<void>;
|
|
31
|
+
onStopRequested?: (this: ActorContext<Args, InternalState, InMsg, OutMsg, Methods, Handlers>) => void | Promise<void>;
|
|
32
|
+
onEnd?: (this: ActorContext<Args, InternalState, InMsg, OutMsg, Methods, Handlers>, reason: unknown) => void | Promise<void>;
|
|
33
|
+
onError?: (this: ActorContext<Args, InternalState, InMsg, OutMsg, Methods, Handlers>, err: unknown) => void;
|
|
34
|
+
}
|
|
35
|
+
interface ActorConfig<Args, InternalState, ExposedState, InMsg extends Message, OutMsg extends Message, Methods extends MethodOptions, Handlers extends HandlerOptions<InMsg>, ReflectionMethods = {}> {
|
|
36
|
+
initialState?: InternalState | ((this: void, args: Args, ctx: ActorContext<Args, InternalState, InMsg, OutMsg, Methods, Handlers>["ctx"]) => InternalState);
|
|
37
|
+
expose?: (internalState: InternalState) => ExposedState;
|
|
38
|
+
/** Preferred process name. Used by ctx.fork() when no explicit name is given. */
|
|
39
|
+
name?: string;
|
|
40
|
+
hooks?: ActorHooksConfig<Args, InternalState, ExposedState, InMsg, OutMsg, Methods, Handlers>;
|
|
41
|
+
/** Plugins installed at fork time. Array = replace, function = transform parent chain. */
|
|
42
|
+
plugins?: ActorPlugin[] | PluginTransform;
|
|
43
|
+
outMessages?: ActorMessages<OutMsg>;
|
|
44
|
+
inMessages?: ActorMessages<InMsg>;
|
|
45
|
+
setup?: (this: ActorContext<Args, InternalState, InMsg, OutMsg, Methods, Handlers>, args: Args) => InternalState | Promise<InternalState>;
|
|
46
|
+
afterStart?: (this: ActorContext<Args, InternalState, InMsg, OutMsg, Methods, Handlers>) => void | Promise<void>;
|
|
47
|
+
onStart?: (this: ActorContext<Args, InternalState, InMsg, OutMsg, Methods, Handlers>, args: Args) => void | Promise<void>;
|
|
48
|
+
onStopRequested?: (this: ActorContext<Args, InternalState, InMsg, OutMsg, Methods, Handlers>) => void | Promise<void>;
|
|
49
|
+
onEnd?: (this: ActorContext<Args, InternalState, InMsg, OutMsg, Methods, Handlers>, reason?: unknown) => void | Promise<void>;
|
|
50
|
+
handlers: Handlers & ThisType<ActorContext<Args, InternalState, InMsg, OutMsg, Methods, Handlers>>;
|
|
51
|
+
methods?: Methods & ThisType<ActorContext<Args, InternalState, InMsg, OutMsg, Methods, Handlers>>;
|
|
52
|
+
onUnhandled?: (this: ActorContext<Args, InternalState, InMsg, OutMsg, Methods, Handlers>, msg: InMsg, sender: SenderInfo) => void | Promise<void>;
|
|
53
|
+
onChildExit?: (this: ActorContext<Args, InternalState, InMsg, OutMsg, Methods, Handlers>, name: string, reason: ExitMessage) => void | Promise<void>;
|
|
54
|
+
$reflectionMethods?: ReflectionMethods & ThisType<ActorContext<Args, InternalState, InMsg, OutMsg, Methods, Handlers>>;
|
|
55
|
+
}
|
|
56
|
+
/** Returned by onMessage hooks to prevent further dispatch. */
|
|
57
|
+
declare const STOP_SENTINEL: unique symbol;
|
|
58
|
+
/** Type-safe sentinel for short-circuiting onMessage hooks. */
|
|
59
|
+
declare const stopPropagation: () => typeof STOP_SENTINEL;
|
|
60
|
+
/** Return type of onMessage hooks: void (continue) or sentinel (stop). */
|
|
61
|
+
type HookResult = void | typeof STOP_SENTINEL;
|
|
62
|
+
type OnStartHook<State> = (state: State) => void | Promise<void>;
|
|
63
|
+
type OnMessageHook<InMsg extends Message> = (msg: InMsg, sender: SenderInfo) => HookResult | Promise<HookResult>;
|
|
64
|
+
type OnEmitHook<OutMsg extends Message> = (msg: OutMsg) => void;
|
|
65
|
+
type OnChildExitHook = (name: string) => void | Promise<void>;
|
|
66
|
+
type OnStopRequestedHook = () => void | Promise<void>;
|
|
67
|
+
type OnEndHook = (reason: unknown) => void | Promise<void>;
|
|
68
|
+
type OnErrorHook = (err: unknown) => void;
|
|
69
|
+
/** A reusable unit of actor behaviour, installed at fork time. */
|
|
70
|
+
interface ActorPlugin<InMsg extends Message = Message, OutMsg extends Message = Message, State = unknown> {
|
|
71
|
+
name: string;
|
|
72
|
+
install(self: ActorContext<unknown, State, InMsg, OutMsg, MethodOptions, HandlerOptions<InMsg>>): void | Promise<void>;
|
|
73
|
+
}
|
|
74
|
+
/** Transform parent plugins into child plugins. */
|
|
75
|
+
type PluginTransform = (parentPlugins: ActorPlugin[]) => ActorPlugin[];
|
|
76
|
+
type ActorContext<Args, InternalState, InMsg extends Message, OutMsg extends Message, Methods extends MethodOptions, Handlers extends HandlerOptions<InMsg>> = Methods & ActorDecorated & {
|
|
77
|
+
state: InternalState;
|
|
78
|
+
name: string;
|
|
79
|
+
id: symbol;
|
|
80
|
+
emit: (msg: OutMsg) => void;
|
|
81
|
+
agreeToStop: () => void; /** Hook registration. */
|
|
82
|
+
hooks: {
|
|
83
|
+
onMessage: (h: OnMessageHook<InMsg>) => void;
|
|
84
|
+
onEmit: (h: OnEmitHook<OutMsg>) => void;
|
|
85
|
+
onChildExit: (h: OnChildExitHook) => void;
|
|
86
|
+
onStart: (h: OnStartHook<unknown>) => void;
|
|
87
|
+
onStopRequested: (h: OnStopRequestedHook) => void;
|
|
88
|
+
onError: (h: OnErrorHook) => void;
|
|
89
|
+
onEnd: (h: OnEndHook) => void;
|
|
90
|
+
}; /** Reflection method registration. Plugin name is automatically prefixed. */
|
|
91
|
+
reflection: {
|
|
92
|
+
register(name: string, method: (this: ActorContext<unknown, unknown, Message, Message, MethodOptions, HandlerOptions<Message>>) => unknown): void;
|
|
93
|
+
}; /** Property decoration. Throws if key conflicts with built-in. */
|
|
94
|
+
decorate: (key: string, value: unknown) => void;
|
|
95
|
+
exit: (reason?: unknown) => void;
|
|
96
|
+
$child: Record<string, AsyncProcess<unknown, unknown, Message, Message>>;
|
|
97
|
+
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>;
|
|
98
|
+
ctx: ProcessCtx<Args, InternalState, InMsg, OutMsg>;
|
|
99
|
+
};
|
|
100
|
+
//#endregion
|
|
101
|
+
//#region src/hooks.d.ts
|
|
102
|
+
/** Returned by onMessage hooks to prevent further dispatch. */
|
|
103
|
+
declare class HookRegistry<State, InMsg extends Message, OutMsg extends Message> {
|
|
104
|
+
onStart: Array<OnStartHook<State>>;
|
|
105
|
+
onMessage: Array<OnMessageHook<InMsg>>;
|
|
106
|
+
onEmit: Array<OnEmitHook<OutMsg>>;
|
|
107
|
+
onChildExit: Array<OnChildExitHook>;
|
|
108
|
+
onStopRequested: Array<OnStopRequestedHook>;
|
|
109
|
+
onEnd: Array<OnEndHook>;
|
|
110
|
+
onError: Array<OnErrorHook>;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Interface that plugins can augment via declaration merging.
|
|
114
|
+
* Plugins ship a .d.ts that adds properties to this interface,
|
|
115
|
+
* making them available on `this` in handlers and methods.
|
|
116
|
+
*
|
|
117
|
+
* Example (in a plugin's .d.ts):
|
|
118
|
+
* declare module 'posipaki' {
|
|
119
|
+
* interface ActorDecorated {
|
|
120
|
+
* log: Logger;
|
|
121
|
+
* }
|
|
122
|
+
* }
|
|
123
|
+
*/
|
|
124
|
+
interface ActorDecorated {}
|
|
125
|
+
//#endregion
|
|
126
|
+
export { OnStartHook as _, ActorDefinition as a, STOP_SENTINEL as b, HandlerFn as c, MethodOptions as d, OnChildExitHook as f, OnMessageHook as g, OnErrorHook as h, ActorContext as i, HandlerOptions as l, OnEndHook as m, HookRegistry as n, ActorMessages as o, OnEmitHook as p, ActorConfig as r, ActorPlugin as s, ActorDecorated as t, HookResult as u, OnStopRequestedHook as v, stopPropagation as x, PluginTransform as y };
|
|
127
|
+
//# sourceMappingURL=hooks-Czj67zNB.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks-Czj67zNB.d.ts","names":[],"sources":["../src/actor-types.ts","../src/hooks.ts"],"mappings":";;;KAiBY,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;EAGhC,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;EArBtD;EAuBV,IAAA;EAvBmB;EAyBnB,aAAA,GAAgB,WAAA,KAAgB,eAAA;EAxB3B;EA0BL,KAAA,CAAM,IAAA,EAAM,IAAA,GAAO,YAAA,CAAa,IAAA,EAAM,YAAA,EAAc,KAAA,EAAO,MAAA,EAAQ,iBAAA;EAxBzD;EA0BV,YAAA,CACE,GAAA,EAAK,UAAA,sBACL,IAAA,EAAM,IAAA,EACN,IAAA,YACC,YAAA,CAAa,IAAA,EAAM,YAAA,EAAc,KAAA,EAAO,MAAA,EAAQ,iBAAA;AAAA;AAAA,UAGpC,gBAAA,kDAID,OAAA,iBACC,OAAA,kBACC,aAAA,mBAEC,cAAA,CAAe,KAAA;EAEhC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,KAAA,CAAM,eAAA;EACnB,eAAA,EAAiB,KAAA,CAAM,mBAAA;EACvB,KAAA,EAAO,KAAA,CAAM,SAAA;EACb,OAAA,EAAS,KAAA,CAAM,WAAA;AAAA;;;ADfQ;AAEzB;;;;;;;;;UCkCiB,cAAA"}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
//#region src/
|
|
1
|
+
//#region src/actor-types.ts
|
|
2
2
|
/** Returned by onMessage hooks to prevent further dispatch. */
|
|
3
3
|
const STOP_SENTINEL = Symbol("posipaki.stopPropagation");
|
|
4
4
|
/** Type-safe sentinel for short-circuiting onMessage hooks. */
|
|
5
5
|
const stopPropagation = () => STOP_SENTINEL;
|
|
6
|
+
//#endregion
|
|
7
|
+
//#region src/hooks.ts
|
|
8
|
+
/** Returned by onMessage hooks to prevent further dispatch. */
|
|
6
9
|
var HookRegistry = class {
|
|
7
10
|
constructor() {
|
|
8
11
|
this.onStart = [];
|
|
@@ -17,4 +20,4 @@ var HookRegistry = class {
|
|
|
17
20
|
//#endregion
|
|
18
21
|
export { STOP_SENTINEL as n, stopPropagation as r, HookRegistry as t };
|
|
19
22
|
|
|
20
|
-
//# sourceMappingURL=hooks-
|
|
23
|
+
//# sourceMappingURL=hooks-D5DhD9gu.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks-D5DhD9gu.js","names":[],"sources":["../src/actor-types.ts","../src/hooks.ts"],"sourcesContent":["// ── defineActor types ────────────────────────────────────────────────────────\n//\n// Shared between define-actor.ts (implementation) and consumers that want\n// to reference the config/context/definition shapes without importing the\n// implementation module directly.\n\nimport type {\n SenderInfo,\n AsyncProcessFn,\n Message,\n ProcessCtx,\n ExitMessage,\n} from \"./types.js\";\nimport type { ActorDecorated } from \"./hooks.js\";\nimport type { AsyncProcess } from \"./process.async.js\";\n\n// Internal marker do not use\nexport type ActorMessages<M extends Message> = {\n __tag_messages: M;\n};\nexport interface MethodOptions {\n [key: string]: Function;\n}\nexport type HandlerFn<InMsg extends Message> = (\n msg: InMsg,\n sender: SenderInfo,\n) => void | Promise<void>;\nexport type HandlerOptions<InMsg extends Message> = Omit<\n {\n [K in InMsg[\"type\"]]: HandlerFn<Extract<InMsg, { type: K }>>;\n },\n \"STOP\"\n>;\n\nexport interface ActorDefinition<\n Args,\n ExposedState,\n InMsg extends Message,\n OutMsg extends Message,\n // eslint-disable-next-line no-unused-vars\n Handlers extends HandlerOptions<InMsg>,\n ReflectionMethods = {},\n> {\n fn: AsyncProcessFn<Args, ExposedState, InMsg, OutMsg>;\n config: ActorConfig<Args, any, ExposedState, InMsg, OutMsg, {}, Handlers>;\n /** Preferred process name (from config.name). */\n name?: string;\n /** Raw plugin config (array or transform). Resolved at fork time. @internal */\n pvtPluginsRaw?: ActorPlugin[] | PluginTransform;\n /** Spawn this actor as a standalone process. */\n spawn(args: Args): AsyncProcess<Args, ExposedState, InMsg, OutMsg, ReflectionMethods>;\n /** Spawn this actor as a child of the calling process. */\n spawnAsChild(\n ctx: ProcessCtx<any, any, any, any>,\n args: Args,\n name?: string,\n ): AsyncProcess<Args, ExposedState, InMsg, OutMsg, ReflectionMethods>;\n}\n\nexport interface ActorHooksConfig<\n Args,\n InternalState,\n ExposedState,\n InMsg extends Message,\n OutMsg extends Message,\n Methods extends MethodOptions,\n // eslint-disable-next-line no-unused-vars\n Handlers extends HandlerOptions<InMsg>,\n> {\n onStart?: OnStartHook<ExposedState>;\n onMessage?: (\n this: ActorContext<Args, InternalState, InMsg, OutMsg, Methods, Handlers>,\n msg: InMsg,\n sender: SenderInfo,\n ) => HookResult | Promise<HookResult>;\n onEmit?: (\n this: ActorContext<Args, InternalState, InMsg, OutMsg, Methods, Handlers>,\n msg: OutMsg,\n ) => void;\n onChildExit?: (\n this: ActorContext<Args, InternalState, InMsg, OutMsg, Methods, Handlers>,\n name: string,\n ) => void | Promise<void>;\n onStopRequested?: (\n this: ActorContext<Args, InternalState, InMsg, OutMsg, Methods, Handlers>,\n ) => void | Promise<void>;\n onEnd?: (\n this: ActorContext<Args, InternalState, InMsg, OutMsg, Methods, Handlers>,\n reason: unknown,\n ) => void | Promise<void>;\n onError?: (\n this: ActorContext<Args, InternalState, InMsg, OutMsg, Methods, Handlers>,\n err: unknown,\n ) => void;\n}\n\nexport interface ActorConfig<\n Args,\n InternalState,\n ExposedState,\n InMsg extends Message,\n OutMsg extends Message,\n Methods extends MethodOptions,\n // eslint-disable-next-line no-unused-vars\n Handlers extends HandlerOptions<InMsg>,\n ReflectionMethods = {},\n> {\n initialState?:\n | InternalState\n | ((\n this: void,\n args: Args,\n // initial state is called before the actor\n // context is created (not that it's really necessay)\n // so we can only pass the process context here.\n ctx: ActorContext<\n Args,\n InternalState,\n InMsg,\n OutMsg,\n Methods,\n Handlers\n >[\"ctx\"],\n ) => InternalState);\n expose?: (internalState: InternalState) => ExposedState;\n /** Preferred process name. Used by ctx.fork() when no explicit name is given. */\n name?: string;\n hooks?: ActorHooksConfig<Args, InternalState, ExposedState, InMsg, OutMsg, Methods, Handlers>;\n /** Plugins installed at fork time. Array = replace, function = transform parent chain. */\n plugins?: ActorPlugin[] | PluginTransform;\n outMessages?: ActorMessages<OutMsg>;\n inMessages?: ActorMessages<InMsg>;\n\n setup?: (\n this: ActorContext<Args, InternalState, InMsg, OutMsg, Methods, Handlers>,\n args: Args,\n ) => InternalState | Promise<InternalState>;\n\n afterStart?: (\n this: ActorContext<Args, InternalState, InMsg, OutMsg, Methods, Handlers>,\n ) => void | Promise<void>;\n\n onStart?: (\n this: ActorContext<Args, InternalState, InMsg, OutMsg, Methods, Handlers>,\n args: Args,\n ) => void | Promise<void>;\n\n onStopRequested?: (\n this: ActorContext<Args, InternalState, InMsg, OutMsg, Methods, Handlers>,\n ) => void | Promise<void>;\n\n onEnd?: (\n this: ActorContext<Args, InternalState, InMsg, OutMsg, Methods, Handlers>,\n reason?: unknown,\n ) => void | Promise<void>;\n\n handlers: Handlers &\n ThisType<\n ActorContext<Args, InternalState, InMsg, OutMsg, Methods, Handlers>\n >;\n\n methods?: Methods &\n ThisType<\n ActorContext<Args, InternalState, InMsg, OutMsg, Methods, Handlers>\n >;\n\n onUnhandled?: (\n this: ActorContext<Args, InternalState, InMsg, OutMsg, Methods, Handlers>,\n msg: InMsg,\n sender: SenderInfo,\n ) => void | Promise<void>;\n\n onChildExit?: (\n this: ActorContext<Args, InternalState, InMsg, OutMsg, Methods, Handlers>,\n name: string,\n reason: ExitMessage,\n ) => void | Promise<void>;\n\n $reflectionMethods?: ReflectionMethods &\n ThisType<ActorContext<Args, InternalState, InMsg, OutMsg, Methods, Handlers>>;\n}\n\n// ── stop propagation sentinel ────────────────────────────────────────────\n\n/** Returned by onMessage hooks to prevent further dispatch. */\nexport const STOP_SENTINEL = Symbol('posipaki.stopPropagation');\n\n/** Type-safe sentinel for short-circuiting onMessage hooks. */\nexport const stopPropagation = (): typeof STOP_SENTINEL => STOP_SENTINEL;\n\n// ── hook function types ──────────────────────────────────────────────────\n\n/** Return type of onMessage hooks: void (continue) or sentinel (stop). */\nexport type HookResult = void | typeof STOP_SENTINEL;\n\nexport type OnStartHook<State> = (state: State) => void | Promise<void>;\nexport type OnMessageHook<InMsg extends Message> = (msg: InMsg, sender: SenderInfo) => HookResult | Promise<HookResult>;\nexport type OnEmitHook<OutMsg extends Message> = (msg: OutMsg) => void;\nexport type OnChildExitHook = (name: string) => void | Promise<void>;\nexport type OnStopRequestedHook = () => void | Promise<void>;\nexport type OnEndHook = (reason: unknown) => void | Promise<void>;\nexport type OnErrorHook = (err: unknown) => void;\n\n// ── plugin types ─────────────────────────────────────────────────────────\n\n/** A reusable unit of actor behaviour, installed at fork time. */\nexport interface ActorPlugin<\n InMsg extends Message = Message,\n OutMsg extends Message = Message,\n State = unknown,\n> {\n name: string;\n install(self: ActorContext<unknown, State, InMsg, OutMsg, MethodOptions, HandlerOptions<InMsg>>): void | Promise<void>;\n}\n\n/** Transform parent plugins into child plugins. */\nexport type PluginTransform = (parentPlugins: ActorPlugin[]) => ActorPlugin[];\n\nexport type ActorContext<\n Args,\n InternalState,\n InMsg extends Message,\n OutMsg extends Message,\n Methods extends MethodOptions,\n // eslint-disable-next-line no-unused-vars\n Handlers extends HandlerOptions<InMsg>,\n> = Methods & ActorDecorated & {\n state: InternalState;\n name: string;\n id: symbol;\n\n emit: (msg: OutMsg) => void;\n agreeToStop: () => void;\n\n /** Hook registration. */\n hooks: {\n onMessage: (h: OnMessageHook<InMsg>) => void;\n onEmit: (h: OnEmitHook<OutMsg>) => void;\n onChildExit: (h: OnChildExitHook) => void;\n onStart: (h: OnStartHook<unknown>) => void;\n onStopRequested: (h: OnStopRequestedHook) => void;\n onError: (h: OnErrorHook) => void;\n onEnd: (h: OnEndHook) => void;\n };\n\n /** Reflection method registration. Plugin name is automatically prefixed. */\n reflection: {\n register(name: string, method: (this: ActorContext<unknown, unknown, Message, Message, MethodOptions, HandlerOptions<Message>>) => unknown): void;\n };\n\n /** Property decoration. Throws if key conflicts with built-in. */\n decorate: (key: string, value: unknown) => void;\n exit: (reason?: unknown) => void;\n\n $child: Record<string, AsyncProcess<unknown, unknown, Message, Message>>;\n\n fork<\n A,\n S,\n IM extends Message,\n OM extends Message,\n H extends HandlerOptions<IM>,\n >(\n fn: AsyncProcessFn<A, S, IM, OM> | ActorDefinition<A, S, IM, OM, H>,\n name?: string,\n args?: A,\n ): AsyncProcess<A, S, IM, OM>;\n\n ctx: ProcessCtx<Args, InternalState, InMsg, OutMsg>;\n};\n","// ── Lifecycle Hooks ──────────────────────────────────────────────────────\n//\n// Extends ProcessCtx and defineActor with observable lifecycle hooks.\n// Hooks are additive — multiple callbacks can register for the same hook\n// point, and they fire in registration order.\n\nimport type { Message } from './types.js';\nimport {\n STOP_SENTINEL,\n stopPropagation,\n} from './actor-types.js';\nimport type {\n HookResult,\n OnStartHook,\n OnMessageHook,\n OnEmitHook,\n OnChildExitHook,\n OnStopRequestedHook,\n OnEndHook,\n OnErrorHook,\n ActorPlugin,\n PluginTransform,\n} from './actor-types.js';\n\n// ── stop propagation sentinel ────────────────────────────────────────────\n\n/** Returned by onMessage hooks to prevent further dispatch. */\n// ── hook registry ────────────────────────────────────────────────────────\n\nexport class HookRegistry<State, InMsg extends Message, OutMsg extends Message> {\n onStart: Array<OnStartHook<State>> = [];\n onMessage: Array<OnMessageHook<InMsg>> = [];\n onEmit: Array<OnEmitHook<OutMsg>> = [];\n onChildExit: Array<OnChildExitHook> = [];\n onStopRequested: Array<OnStopRequestedHook> = [];\n onEnd: Array<OnEndHook> = [];\n onError: Array<OnErrorHook> = [];\n}\n\n// Re-exports from actor-types.ts (backward compatibility)\nexport { STOP_SENTINEL, stopPropagation };\nexport type { HookResult, OnStartHook, OnMessageHook, OnEmitHook, OnChildExitHook, OnStopRequestedHook, OnEndHook, OnErrorHook, ActorPlugin, PluginTransform };\n\n// ── type augmentation (Fastify-style) ────────────────────────────────────\n\n/**\n * Interface that plugins can augment via declaration merging.\n * Plugins ship a .d.ts that adds properties to this interface,\n * making them available on `this` in handlers and methods.\n *\n * Example (in a plugin's .d.ts):\n * declare module 'posipaki' {\n * interface ActorDecorated {\n * log: Logger;\n * }\n * }\n */\nexport interface ActorDecorated {}\n"],"mappings":";;AAyLA,MAAa,gBAAgB,OAAO,0BAA0B;;AAG9D,MAAa,wBAA8C;;;;AC/J3D,IAAa,eAAb,MAAgF;;iBACzC,CAAC;mBACG,CAAC;gBACN,CAAC;qBACC,CAAC;yBACO,CAAC;eACrB,CAAC;iBACG,CAAC;;AACjC"}
|
package/dist/hooks.d.ts
CHANGED
|
@@ -1,48 +1,2 @@
|
|
|
1
|
-
import {
|
|
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 { _ as OnStartHook, b as STOP_SENTINEL, f as OnChildExitHook, g as OnMessageHook, h as OnErrorHook, m as OnEndHook, n as HookRegistry, p as OnEmitHook, s as ActorPlugin, t as ActorDecorated, u as HookResult, v as OnStopRequestedHook, x as stopPropagation, y as PluginTransform } from "./hooks-Czj67zNB.js";
|
|
2
|
+
export { ActorDecorated, type ActorPlugin, HookRegistry, type HookResult, type OnChildExitHook, type OnEmitHook, type OnEndHook, type OnErrorHook, type OnMessageHook, type OnStartHook, type OnStopRequestedHook, type PluginTransform, STOP_SENTINEL, stopPropagation };
|
package/dist/hooks.js
CHANGED
|
@@ -1,20 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
/** Returned by onMessage hooks to prevent further dispatch. */
|
|
3
|
-
const STOP_SENTINEL = Symbol("posipaki.stopPropagation");
|
|
4
|
-
/** Type-safe sentinel for short-circuiting onMessage hooks. */
|
|
5
|
-
const stopPropagation = () => STOP_SENTINEL;
|
|
6
|
-
var HookRegistry = class {
|
|
7
|
-
constructor() {
|
|
8
|
-
this.onStart = [];
|
|
9
|
-
this.onMessage = [];
|
|
10
|
-
this.onEmit = [];
|
|
11
|
-
this.onChildExit = [];
|
|
12
|
-
this.onStopRequested = [];
|
|
13
|
-
this.onEnd = [];
|
|
14
|
-
this.onError = [];
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
//#endregion
|
|
1
|
+
import { n as STOP_SENTINEL, r as stopPropagation, t as HookRegistry } from "./hooks-D5DhD9gu.js";
|
|
18
2
|
export { HookRegistry, STOP_SENTINEL, stopPropagation };
|
|
19
|
-
|
|
20
|
-
//# sourceMappingURL=hooks.js.map
|
package/dist/index.d.ts
CHANGED
|
@@ -1,75 +1,13 @@
|
|
|
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-BLIFntvm.js";
|
|
2
|
+
import { _ as OnStartHook, a as ActorDefinition, c as HandlerFn, d as MethodOptions, f as OnChildExitHook, g as OnMessageHook, h as OnErrorHook, i as ActorContext, l as HandlerOptions, m as OnEndHook, n as HookRegistry, o as ActorMessages, p as OnEmitHook, r as ActorConfig, s as ActorPlugin, t as ActorDecorated, u as HookResult, v as OnStopRequestedHook, x as stopPropagation, y as PluginTransform } from "./hooks-Czj67zNB.js";
|
|
3
|
+
import { n as spawn, r as runDispatch, t as Process } from "./process-Bf9HTr0m.js";
|
|
4
4
|
|
|
5
5
|
//#region src/adapters.d.ts
|
|
6
6
|
declare function asyncify<A, S, IM extends Message, OM extends Message>(fn: ProcessFn<A, S, IM, OM>): AsyncProcessFn<A, S, IM, OM>;
|
|
7
7
|
//#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, ExposedState, 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
8
|
//#region src/define-actor.d.ts
|
|
71
9
|
declare function defineMessages<OutMsg extends Message = Message>(): ActorMessages<OutMsg>;
|
|
72
|
-
declare function defineActor<Args, InternalState, ExposedState, InMsg extends Message, OutMsg extends Message, Methods extends MethodOptions, Handlers extends HandlerOptions<InMsg
|
|
10
|
+
declare function defineActor<Args, InternalState, ExposedState, InMsg extends Message, OutMsg extends Message, Methods extends MethodOptions, Handlers extends HandlerOptions<InMsg>, ReflectionMethods = {}>(config: ActorConfig<Args, InternalState, ExposedState, InMsg, OutMsg, Methods, Handlers, ReflectionMethods>): ActorDefinition<Args, ExposedState, InMsg, OutMsg, Handlers, ReflectionMethods>;
|
|
73
11
|
//#endregion
|
|
74
12
|
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
13
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[
|
|
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,2BAGhC,MAAA,EAAQ,WAAA,CACN,IAAA,EACA,aAAA,EACA,YAAA,EACA,KAAA,EACA,MAAA,EACA,OAAA,EACA,QAAA,EACA,iBAAA,IAED,eAAA,CAAgB,IAAA,EAAM,YAAA,EAAc,KAAA,EAAO,MAAA,EAAQ,QAAA,EAAU,iBAAA"}
|