ihsm 0.1.1 → 0.1.22
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/lib/cjs/index.d.ts +4 -1
- package/lib/cjs/index.js +13 -1
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/internal/console-instrumentation.d.ts +34 -0
- package/lib/cjs/internal/console-instrumentation.js +71 -0
- package/lib/cjs/internal/console-instrumentation.js.map +1 -0
- package/lib/cjs/internal/identity.d.ts +16 -0
- package/lib/cjs/internal/identity.js +170 -0
- package/lib/cjs/internal/identity.js.map +1 -0
- package/lib/cjs/internal/instrumentation.d.ts +47 -0
- package/lib/cjs/internal/instrumentation.js +201 -0
- package/lib/cjs/internal/instrumentation.js.map +1 -0
- package/lib/cjs/internal/runtime.d.ts +89 -6
- package/lib/cjs/internal/runtime.js +676 -52
- package/lib/cjs/internal/runtime.js.map +1 -1
- package/lib/cjs/internal/types.d.ts +174 -7
- package/lib/cjs/internal/types.js.map +1 -1
- package/lib/cjs/testing.d.ts +86 -1
- package/lib/cjs/testing.js +54 -0
- package/lib/cjs/testing.js.map +1 -1
- package/lib/cjs/types.d.ts +1 -1
- package/lib/esm/index.d.ts +4 -1
- package/lib/esm/index.js +3 -1
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/internal/console-instrumentation.d.ts +34 -0
- package/lib/esm/internal/console-instrumentation.js +68 -0
- package/lib/esm/internal/console-instrumentation.js.map +1 -0
- package/lib/esm/internal/identity.d.ts +16 -0
- package/lib/esm/internal/identity.js +159 -0
- package/lib/esm/internal/identity.js.map +1 -0
- package/lib/esm/internal/instrumentation.d.ts +47 -0
- package/lib/esm/internal/instrumentation.js +178 -0
- package/lib/esm/internal/instrumentation.js.map +1 -0
- package/lib/esm/internal/runtime.d.ts +89 -6
- package/lib/esm/internal/runtime.js +666 -51
- package/lib/esm/internal/runtime.js.map +1 -1
- package/lib/esm/internal/types.d.ts +174 -7
- package/lib/esm/internal/types.js.map +1 -1
- package/lib/esm/testing.d.ts +86 -1
- package/lib/esm/testing.js +53 -0
- package/lib/esm/testing.js.map +1 -1
- package/lib/esm/types.d.ts +1 -1
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** @internal Consolidated ihsm runtime (no pure types — see ./types.ts). */
|
|
2
|
-
import type { ActorConfig, ActorContextOf, ActorConfigOf, ActorOptions, ChildActor, ChildHsm, DispatchableMachine, EmbodimentKind, ErrorHost, ExternalActor, ExternalHsm, HandlerHsm, HsmWithTracing, InboundActor, InboundHsm, Instance, NotificationQueue, ParentActor, PlannedTransition, IPort, MachinePortInput, Properties, ProtocolIndex, RandomService, ReservedName, SelfNotifications, ServiceCallOptions, StateClass, StateEvents, Task, TopStateArg, TraceWriter, DispatchErrorCallback, Transition, TransitionResolver, TransitionHost, TransitionRoutineExecuteOptions, TransitionRoutinePlan, TransitionTracer, Disposable, EventObserver, TransitionTraceHost } from './types';
|
|
2
|
+
import type { ActorConfig, ActorContextOf, ActorConfigOf, ActorOptions, ChildActor, ChildHsm, DispatchableMachine, EmbodimentKind, ErrorHost, ExternalActor, ExternalHsm, HandlerHsm, HsmWithTracing, InboundActor, InboundHsm, Instance, NotificationQueue, ParentActor, PlannedTransition, IPort, MachinePortInput, Properties, ProtocolIndex, RandomService, ReservedName, SelfNotifications, ServiceCallOptions, StateClass, StateEvents, Task, TimerService, TopStateArg, TraceWriter, DispatchErrorCallback, Transition, TransitionResolver, TransitionHost, TransitionRoutineExecuteOptions, TransitionRoutinePlan, TransitionTracer, Disposable, EventObserver, TransitionTraceHost, ActorIdentity, ActorLogger, Instrumentation, OutboundCallBegin, TraceFrame } from './types';
|
|
3
3
|
export declare enum TraceLevel {
|
|
4
4
|
PRODUCTION = 0,
|
|
5
5
|
DEBUG = 1,
|
|
@@ -103,6 +103,8 @@ export declare class InitializationError<C extends ActorConfig = ActorConfig> ex
|
|
|
103
103
|
export declare class FatalErrorState extends TopState {
|
|
104
104
|
}
|
|
105
105
|
/** @internal */
|
|
106
|
+
export declare function lookupHandlerState<C extends ActorConfig>(hsm: HsmWithTracing<C>, eventName: PropertyKey): string | undefined;
|
|
107
|
+
/** @internal */
|
|
106
108
|
export declare function lookupEventHandler<C extends ActorConfig>(hsm: HsmWithTracing<C>, eventName: PropertyKey): ((...args: any[]) => unknown) | undefined;
|
|
107
109
|
export declare function InitialState<C extends ActorConfig>(TargetState: StateClass<C>): void;
|
|
108
110
|
export declare function registerStateNames(exports: Record<string, unknown>): void;
|
|
@@ -144,7 +146,15 @@ export declare function splitServiceArgs(args: readonly unknown[]): {
|
|
|
144
146
|
callArgs: unknown[];
|
|
145
147
|
timeoutMs: number | undefined;
|
|
146
148
|
};
|
|
147
|
-
|
|
149
|
+
/**
|
|
150
|
+
* Race a service-call promise against a `timeoutMs` deadline.
|
|
151
|
+
*
|
|
152
|
+
* The deadline is armed through `timer` — the actor's port timer service — so that under a
|
|
153
|
+
* {@link TestPort} virtual clock a call timeout is driven by `port.advance(...)` and stays
|
|
154
|
+
* fully deterministic. When no port timer is available the host timer is used (production
|
|
155
|
+
* `Port` already delegates to the host timer, so behaviour there is unchanged).
|
|
156
|
+
*/
|
|
157
|
+
export declare function serviceCallWithTimeout<T>(promise: Promise<T>, method: string, timeoutMs: number, timer?: TimerService): Promise<T>;
|
|
148
158
|
/** @internal */
|
|
149
159
|
export declare function createActorHandle(machine: DispatchableMachine, topState: object, index: ProtocolIndex, kind: EmbodimentKind): HandleOwn;
|
|
150
160
|
/** @internal */
|
|
@@ -154,6 +164,18 @@ export declare function createSelfNotifications(machine: DispatchableMachine, to
|
|
|
154
164
|
export declare class SelfCallDeadlockError extends Error {
|
|
155
165
|
constructor();
|
|
156
166
|
}
|
|
167
|
+
type DispatchToken = {
|
|
168
|
+
machine: DispatchableMachine;
|
|
169
|
+
actorUuid?: string;
|
|
170
|
+
macrostepId?: string;
|
|
171
|
+
stepSeq?: number;
|
|
172
|
+
};
|
|
173
|
+
interface InstrumentationHost {
|
|
174
|
+
onTaskBegin(task: Task): void;
|
|
175
|
+
onTaskEnd(task: Task, outcome: 'ok' | 'error'): void;
|
|
176
|
+
onQueuesDrained(): void;
|
|
177
|
+
onDispatchError(err: Error): void;
|
|
178
|
+
}
|
|
157
179
|
type AsyncLocalStorageCtor = new <T>() => {
|
|
158
180
|
run<R>(store: T, fn: () => R): R;
|
|
159
181
|
getStore(): T | undefined;
|
|
@@ -168,6 +190,15 @@ export declare const dispatchContext: {
|
|
|
168
190
|
resetInit: () => void;
|
|
169
191
|
markUnavailable: () => void;
|
|
170
192
|
};
|
|
193
|
+
/**
|
|
194
|
+
* Best-effort current runtime trace anchor (`actorUuid`, `macrostepId`, `stepSeq`) for user code.
|
|
195
|
+
* Returns `undefined` when called outside an active handler dispatch turn.
|
|
196
|
+
*/
|
|
197
|
+
export declare function currentTraceAnchor(): {
|
|
198
|
+
readonly actorUuid: string;
|
|
199
|
+
readonly macrostepId?: string;
|
|
200
|
+
readonly stepSeq?: number;
|
|
201
|
+
} | undefined;
|
|
171
202
|
/** Thrown when a generated transition table's graph hash does not match the scanned hierarchy. */
|
|
172
203
|
export declare class TransitionTableError extends Error {
|
|
173
204
|
constructor(message: string);
|
|
@@ -202,6 +233,9 @@ export declare class HsmObject<C extends ActorConfig> implements HsmWithTracing<
|
|
|
202
233
|
topStateName: string;
|
|
203
234
|
readonly ctxTypeName: string;
|
|
204
235
|
traceWriter: TraceWriter;
|
|
236
|
+
readonly actorUuid: string;
|
|
237
|
+
readonly actorName: string;
|
|
238
|
+
readonly actorPath: string;
|
|
205
239
|
/** @internal */
|
|
206
240
|
_instance: Instance<C>;
|
|
207
241
|
/** @internal */
|
|
@@ -216,10 +250,14 @@ export declare class HsmObject<C extends ActorConfig> implements HsmWithTracing<
|
|
|
216
250
|
dispatchErrorCallback: DispatchErrorCallback<C>;
|
|
217
251
|
private _traceLevel;
|
|
218
252
|
private _traceDomainStack;
|
|
219
|
-
|
|
253
|
+
protected _instrumentationHost?: InstrumentationHost;
|
|
254
|
+
private _drainWaiters;
|
|
255
|
+
constructor(TopState: StateClass<C>, instance: Instance<C>, traceWriter: TraceWriter, traceLevel: TraceLevel, dispatchErrorCallback: DispatchErrorCallback<C>, identity: ActorIdentity);
|
|
220
256
|
get ctx(): ActorContextOf<C>;
|
|
221
257
|
set ctx(ctx: ActorContextOf<C>);
|
|
222
258
|
get port(): unknown;
|
|
259
|
+
/** The bound port when it provides a timer service, so service-call timeouts honour a virtual clock. */
|
|
260
|
+
get callTimer(): TimerService | undefined;
|
|
223
261
|
get eventName(): string;
|
|
224
262
|
get eventPayload(): unknown[];
|
|
225
263
|
get currentStateName(): string;
|
|
@@ -232,7 +270,18 @@ export declare class HsmObject<C extends ActorConfig> implements HsmWithTracing<
|
|
|
232
270
|
unhandled(): never;
|
|
233
271
|
get traceLevel(): TraceLevel;
|
|
234
272
|
set traceLevel(traceLevel: TraceLevel);
|
|
273
|
+
/**
|
|
274
|
+
* Resolve when the actor next reaches stability (mailbox fully drained).
|
|
275
|
+
*
|
|
276
|
+
* The resolver fires at the queue-drain point — *after* {@link InstrumentationHost.onQueuesDrained}
|
|
277
|
+
* — so the closing `macrostep.end` and the macrostep-boundary reset are observable before `sync()`
|
|
278
|
+
* resolves, and a subsequent external stimulus deterministically starts its own macrostep. The
|
|
279
|
+
* pushed task is a no-op (internal) whose only purpose is to guarantee a drain cycle occurs.
|
|
280
|
+
*/
|
|
235
281
|
sync(): Promise<void>;
|
|
282
|
+
/** Invoke the user dispatch-error callback, first notifying instrumentation (pure observer). */
|
|
283
|
+
reportDispatchError(err: Error): void;
|
|
284
|
+
private flushDrainWaiters;
|
|
236
285
|
pushTask(t: Task): void;
|
|
237
286
|
pushHiPriorityTask(t: Task): void;
|
|
238
287
|
unshiftHiPriorityTask(t: Task): void;
|
|
@@ -247,26 +296,56 @@ export declare class HsmObject<C extends ActorConfig> implements HsmWithTracing<
|
|
|
247
296
|
_tracePopError(msg: string): void;
|
|
248
297
|
_traceWrite(msg: any): void;
|
|
249
298
|
get traceHeader(): string;
|
|
299
|
+
get traceFrames(): readonly TraceFrame[];
|
|
250
300
|
}
|
|
251
|
-
export declare class Machine<C extends ActorConfig> extends HsmObject<C> {
|
|
301
|
+
export declare class Machine<C extends ActorConfig> extends HsmObject<C> implements InstrumentationHost {
|
|
252
302
|
readonly transitionResolver: TransitionResolver<C>;
|
|
303
|
+
readonly identity: ActorIdentity;
|
|
304
|
+
readonly instrumentation?: Instrumentation<C>;
|
|
253
305
|
private _dispatchStrategy;
|
|
254
306
|
private readonly protocolIndex;
|
|
255
307
|
private readonly handlerFacade;
|
|
256
308
|
private readonly selfActor;
|
|
257
309
|
private readonly selfImmediate;
|
|
258
310
|
private readonly actorFacades;
|
|
311
|
+
private _macrostepCounter;
|
|
312
|
+
private _currentMacrostep?;
|
|
313
|
+
private _microstepFromState?;
|
|
314
|
+
private readonly _childSpawnCounters;
|
|
315
|
+
private _nextTraceCallId;
|
|
316
|
+
private _proxiedPort?;
|
|
259
317
|
constructor(topState: StateClass<C>, instance: {
|
|
260
318
|
ctx: ActorContextOf<C>;
|
|
261
319
|
hsm: HandlerHsm<C>;
|
|
262
320
|
portRef?: unknown;
|
|
263
|
-
}, protocolIndex: ProtocolIndex, traceWriter: TraceWriter, traceLevel: TraceLevel, dispatchErrorCallback: DispatchErrorCallback<C>, initialize: boolean, transitionResolver?: TransitionResolver<C>);
|
|
321
|
+
}, protocolIndex: ProtocolIndex, traceWriter: TraceWriter, traceLevel: TraceLevel, dispatchErrorCallback: DispatchErrorCallback<C>, initialize: boolean, identity: ActorIdentity, instrumentation: Instrumentation<C> | undefined, transitionResolver?: TransitionResolver<C>);
|
|
322
|
+
allocateChildSpawnIndex(childTopName: string): number;
|
|
323
|
+
needsDispatchContext(): boolean;
|
|
324
|
+
buildDispatchToken(): DispatchToken;
|
|
325
|
+
private readDispatchCause;
|
|
326
|
+
private nextTraceCallId;
|
|
327
|
+
private beginPortCall;
|
|
328
|
+
private endPortCall;
|
|
329
|
+
beginOutboundCall(service: string, targetUuid?: string): OutboundCallBegin | undefined;
|
|
330
|
+
endOutboundCall(begin: OutboundCallBegin | undefined, outcome: 'ok' | 'error', error?: Error): void;
|
|
331
|
+
private slotBucket;
|
|
332
|
+
onTaskBegin(task: Task): void;
|
|
333
|
+
onTaskEnd(task: Task, outcome: 'ok' | 'error'): void;
|
|
334
|
+
onDispatchError(err: Error): void;
|
|
335
|
+
onQueuesDrained(): void;
|
|
336
|
+
private resolveEnqueueCause;
|
|
337
|
+
private enqueueWithInstrumentation;
|
|
264
338
|
get traceLevel(): TraceLevel;
|
|
265
339
|
set traceLevel(traceLevel: TraceLevel);
|
|
266
340
|
dispatchService(name: string, args: unknown[]): Promise<unknown>;
|
|
267
341
|
dispatchNotification(name: string, args: unknown[], queue: NotificationQueue): void;
|
|
268
342
|
actorHsmFor(kind: EmbodimentKind): ExternalHsm<C> | InboundHsm<C> | ChildHsm<C>;
|
|
269
343
|
private scheduleNotification;
|
|
344
|
+
private enqueueTimerNotification;
|
|
345
|
+
private _actorLogger?;
|
|
346
|
+
/** Severity-typed handler logger surfaced as `this.hsm.log.*` (CORE-F, §4.10.1). */
|
|
347
|
+
get logger(): ActorLogger;
|
|
348
|
+
private emitUserLog;
|
|
270
349
|
/** @internal Binds deferred self-notifications to a port instance. */
|
|
271
350
|
bindPort(portRef: unknown): void;
|
|
272
351
|
private buildHandlerFacade;
|
|
@@ -281,8 +360,11 @@ export declare const defaultInitialize = true;
|
|
|
281
360
|
/** @internal */
|
|
282
361
|
export declare function defaultDispatchErrorCallback<C extends ActorConfig>(hsm: Properties<C>, err: Error): void;
|
|
283
362
|
type ActorHandleFor<C extends ActorConfig, K extends EmbodimentKind> = K extends 'root' ? ExternalActor<C> : K extends 'inbound' ? InboundActor<C> : ChildActor<C>;
|
|
363
|
+
type SpawnContext<C extends ActorConfig = ActorConfig> = {
|
|
364
|
+
readonly parentMachine?: Machine<C>;
|
|
365
|
+
};
|
|
284
366
|
/** @internal Spawn with embodiment kind — used by factories and `ihsm/testing`. */
|
|
285
|
-
export declare function spawnActor<C extends ActorConfig, K extends EmbodimentKind>(kind: K, topState: TopStateArg<C>, ctx: ActorContextOf<C>, port: MachinePortInput<C> | undefined, options: ActorOptions<C>): ActorHandleFor<C, K>;
|
|
367
|
+
export declare function spawnActor<C extends ActorConfig, K extends EmbodimentKind>(kind: K, topState: TopStateArg<C>, ctx: ActorContextOf<C>, port: MachinePortInput<C> | undefined, options: ActorOptions<C>, spawnContext?: SpawnContext<C>): ActorHandleFor<C, K>;
|
|
286
368
|
/** Production black-box — public protocol only (generated handle). */
|
|
287
369
|
export declare function makeActor<T extends TopStateArg<ActorConfig>>(topState: T, ctx: ActorContextOf<ActorConfigOf<T>>, port?: MachinePortInput<ActorConfigOf<T>>, options?: ActorOptions<ActorConfigOf<T>>): ExternalActor<ActorConfigOf<T>>;
|
|
288
370
|
export declare function asParentActor<T extends TopStateArg<ActorConfig>>(handler: TopState<ActorConfigOf<T>>): ParentActor<T>;
|
|
@@ -291,3 +373,4 @@ export declare function makeChildActor<ParentT extends TopStateArg<ActorConfig>,
|
|
|
291
373
|
readonly parent: ParentActor<ParentT>;
|
|
292
374
|
};
|
|
293
375
|
export { kHandlerMachine, kParentLink } from './types';
|
|
376
|
+
export { configureRunSeed, getRunSeed, getRunNamespace, actorNameFromTopState, mintActorIdentity, rootActorPath, childActorPath } from './identity';
|