@rotorsoft/act 0.14.0 → 0.16.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/README.md +12 -1
- package/dist/.tsbuildinfo +1 -1
- package/dist/@types/act-builder.d.ts +60 -20
- package/dist/@types/act-builder.d.ts.map +1 -1
- package/dist/@types/act.d.ts +75 -57
- package/dist/@types/act.d.ts.map +1 -1
- package/dist/@types/event-sourcing.d.ts +12 -12
- package/dist/@types/event-sourcing.d.ts.map +1 -1
- package/dist/@types/merge.d.ts +1 -1
- package/dist/@types/merge.d.ts.map +1 -1
- package/dist/@types/projection-builder.d.ts +22 -22
- package/dist/@types/projection-builder.d.ts.map +1 -1
- package/dist/@types/slice-builder.d.ts +31 -27
- package/dist/@types/slice-builder.d.ts.map +1 -1
- package/dist/@types/state-builder.d.ts +35 -33
- package/dist/@types/state-builder.d.ts.map +1 -1
- package/dist/@types/types/action.d.ts +75 -66
- package/dist/@types/types/action.d.ts.map +1 -1
- package/dist/@types/types/errors.d.ts +15 -14
- package/dist/@types/types/errors.d.ts.map +1 -1
- package/dist/@types/types/reaction.d.ts +41 -22
- package/dist/@types/types/reaction.d.ts.map +1 -1
- package/dist/@types/types/registry.d.ts +15 -15
- package/dist/@types/types/registry.d.ts.map +1 -1
- package/dist/@types/types/schemas.d.ts +7 -7
- package/dist/@types/types/schemas.d.ts.map +1 -1
- package/dist/index.cjs +117 -48
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +117 -48
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
import { Act } from "./act.js";
|
|
8
8
|
import type { Projection } from "./projection-builder.js";
|
|
9
9
|
import type { Slice } from "./slice-builder.js";
|
|
10
|
-
import type { Committed, Dispatcher, EventRegister, ReactionOptions, ReactionResolver, Registry, Schema, SchemaRegister, Schemas, Snapshot, State } from "./types/index.js";
|
|
10
|
+
import type { Actor, Committed, Dispatcher, EventRegister, ReactionOptions, ReactionResolver, Registry, Schema, SchemaRegister, Schemas, Snapshot, State } from "./types/index.js";
|
|
11
11
|
/**
|
|
12
12
|
* Fluent builder interface for composing event-sourced applications.
|
|
13
13
|
*
|
|
@@ -15,17 +15,20 @@ import type { Committed, Dispatcher, EventRegister, ReactionOptions, ReactionRes
|
|
|
15
15
|
* - Registering states via `.withState()`
|
|
16
16
|
* - Registering slices via `.withSlice()`
|
|
17
17
|
* - Registering projections via `.withProjection()`
|
|
18
|
+
* - Locking a custom actor type via `.withActor<TActor>()`
|
|
18
19
|
* - Defining event reactions via `.on()` → `.do()` → `.to()` or `.void()`
|
|
19
20
|
* - Building the orchestrator via `.build()`
|
|
20
21
|
*
|
|
21
|
-
* @template
|
|
22
|
-
* @template
|
|
23
|
-
* @template
|
|
22
|
+
* @template TSchemaReg - Schema register for states (maps action names to state schemas)
|
|
23
|
+
* @template TEvents - Event schemas (maps event names to event data schemas)
|
|
24
|
+
* @template TActions - Action schemas (maps action names to action payload schemas)
|
|
25
|
+
* @template TStateMap - Map of state names to state schemas
|
|
26
|
+
* @template TActor - Actor type extending base Actor
|
|
24
27
|
*
|
|
25
28
|
* @see {@link act} for usage examples
|
|
26
29
|
* @see {@link Act} for the built orchestrator API
|
|
27
30
|
*/
|
|
28
|
-
export type ActBuilder<
|
|
31
|
+
export type ActBuilder<TSchemaReg extends SchemaRegister<TActions>, TEvents extends Schemas, TActions extends Schemas, TStateMap extends Record<string, Schema> = {}, TActor extends Actor = Actor> = {
|
|
29
32
|
/**
|
|
30
33
|
* Registers a state definition with the builder.
|
|
31
34
|
*
|
|
@@ -34,11 +37,11 @@ export type ActBuilder<S extends SchemaRegister<A>, E extends Schemas, A extends
|
|
|
34
37
|
*
|
|
35
38
|
* @throws {Error} If duplicate action or event names are detected
|
|
36
39
|
*/
|
|
37
|
-
withState: <
|
|
38
|
-
[K in keyof
|
|
39
|
-
},
|
|
40
|
-
[K in
|
|
41
|
-
}>;
|
|
40
|
+
withState: <TNewState extends Schema, TNewEvents extends Schemas, TNewActions extends Schemas, TNewName extends string = string>(state: State<TNewState, TNewEvents, TNewActions, TNewName>) => ActBuilder<TSchemaReg & {
|
|
41
|
+
[K in keyof TNewActions]: TNewState;
|
|
42
|
+
}, TEvents & TNewEvents, TActions & TNewActions, TStateMap & {
|
|
43
|
+
[K in TNewName]: TNewState;
|
|
44
|
+
}, TActor>;
|
|
42
45
|
/**
|
|
43
46
|
* Registers a slice with the builder.
|
|
44
47
|
*
|
|
@@ -48,14 +51,41 @@ export type ActBuilder<S extends SchemaRegister<A>, E extends Schemas, A extends
|
|
|
48
51
|
*
|
|
49
52
|
* @throws {Error} If duplicate action or event names are detected
|
|
50
53
|
*/
|
|
51
|
-
withSlice: <
|
|
54
|
+
withSlice: <TNewSchemaReg extends SchemaRegister<TNewActions>, TNewEvents extends Schemas, TNewActions extends Schemas, TNewMap extends Record<string, Schema>>(slice: Slice<TNewSchemaReg, TNewEvents, TNewActions, TNewMap>) => ActBuilder<TSchemaReg & TNewSchemaReg, TEvents & TNewEvents, TActions & TNewActions, TStateMap & TNewMap, TActor>;
|
|
52
55
|
/**
|
|
53
56
|
* Registers a standalone projection with the builder.
|
|
54
57
|
*
|
|
55
58
|
* The projection's events must be a subset of events already registered
|
|
56
59
|
* via `.withState()` or `.withSlice()`.
|
|
57
60
|
*/
|
|
58
|
-
withProjection: <
|
|
61
|
+
withProjection: <TNewEvents extends Schemas>(projection: [Exclude<keyof TNewEvents, keyof TEvents>] extends [never] ? Projection<TNewEvents> : never) => ActBuilder<TSchemaReg, TEvents, TActions, TStateMap, TActor>;
|
|
62
|
+
/**
|
|
63
|
+
* Locks a custom actor type for this application.
|
|
64
|
+
*
|
|
65
|
+
* This is a pure type-level method — it returns the same builder at
|
|
66
|
+
* runtime but narrows the `TActor` generic so that `app.do()` and
|
|
67
|
+
* reaction dispatchers require the richer actor shape.
|
|
68
|
+
*
|
|
69
|
+
* @template TNewActor - Custom actor type extending base Actor
|
|
70
|
+
* @returns The same builder with `TActor` locked to `TNewActor`
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```typescript
|
|
74
|
+
* type MyActor = { id: string; name: string; role: string; tenantId: string };
|
|
75
|
+
*
|
|
76
|
+
* const app = act()
|
|
77
|
+
* .withActor<MyActor>()
|
|
78
|
+
* .withState(Counter)
|
|
79
|
+
* .build();
|
|
80
|
+
*
|
|
81
|
+
* // Now app.do() requires MyActor in the target
|
|
82
|
+
* await app.do("increment", {
|
|
83
|
+
* stream: "counter-1",
|
|
84
|
+
* actor: { id: "1", name: "Alice", role: "admin", tenantId: "t1" }
|
|
85
|
+
* }, { by: 5 });
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
88
|
+
withActor: <TNewActor extends Actor>() => ActBuilder<TSchemaReg, TEvents, TActions, TStateMap, TNewActor>;
|
|
59
89
|
/**
|
|
60
90
|
* Begins defining a reaction to a specific event.
|
|
61
91
|
*
|
|
@@ -63,14 +93,14 @@ export type ActBuilder<S extends SchemaRegister<A>, E extends Schemas, A extends
|
|
|
63
93
|
* additional actions, update external systems, or perform side effects. Reactions
|
|
64
94
|
* are processed asynchronously during drain cycles.
|
|
65
95
|
*
|
|
66
|
-
* @template
|
|
96
|
+
* @template TKey - Event name (must be a registered event)
|
|
67
97
|
* @param event - The event name to react to
|
|
68
98
|
* @returns An object with `.do()` method to define the reaction handler
|
|
69
99
|
*/
|
|
70
|
-
on: <
|
|
71
|
-
do: (handler: (event: Committed<
|
|
72
|
-
to: (resolver: ReactionResolver<
|
|
73
|
-
void: () => ActBuilder<
|
|
100
|
+
on: <TKey extends keyof TEvents>(event: TKey) => {
|
|
101
|
+
do: (handler: (event: Committed<TEvents, TKey>, stream: string, app: Dispatcher<TActions, TActor>) => Promise<Snapshot<Schema, TEvents> | void>, options?: Partial<ReactionOptions>) => ActBuilder<TSchemaReg, TEvents, TActions, TStateMap, TActor> & {
|
|
102
|
+
to: (resolver: ReactionResolver<TEvents, TKey> | string) => ActBuilder<TSchemaReg, TEvents, TActions, TStateMap, TActor>;
|
|
103
|
+
void: () => ActBuilder<TSchemaReg, TEvents, TActions, TStateMap, TActor>;
|
|
74
104
|
};
|
|
75
105
|
};
|
|
76
106
|
/**
|
|
@@ -81,11 +111,11 @@ export type ActBuilder<S extends SchemaRegister<A>, E extends Schemas, A extends
|
|
|
81
111
|
*
|
|
82
112
|
* @see {@link Act} for available orchestrator methods
|
|
83
113
|
*/
|
|
84
|
-
build: (drainLimit?: number) => Act<
|
|
114
|
+
build: (drainLimit?: number) => Act<TSchemaReg, TEvents, TActions, TStateMap, TActor>;
|
|
85
115
|
/**
|
|
86
116
|
* The registered event schemas and their reaction maps.
|
|
87
117
|
*/
|
|
88
|
-
readonly events: EventRegister<
|
|
118
|
+
readonly events: EventRegister<TEvents>;
|
|
89
119
|
};
|
|
90
120
|
/**
|
|
91
121
|
* Creates a new Act orchestrator builder for composing event-sourced applications.
|
|
@@ -97,6 +127,16 @@ export type ActBuilder<S extends SchemaRegister<A>, E extends Schemas, A extends
|
|
|
97
127
|
* .build();
|
|
98
128
|
* ```
|
|
99
129
|
*
|
|
130
|
+
* @example Application with custom actor type
|
|
131
|
+
* ```typescript
|
|
132
|
+
* type MyActor = { id: string; name: string; role: string };
|
|
133
|
+
*
|
|
134
|
+
* const app = act()
|
|
135
|
+
* .withActor<MyActor>()
|
|
136
|
+
* .withState(Counter)
|
|
137
|
+
* .build();
|
|
138
|
+
* ```
|
|
139
|
+
*
|
|
100
140
|
* @example Application with slices (vertical slice architecture)
|
|
101
141
|
* ```typescript
|
|
102
142
|
* const CounterSlice = slice()
|
|
@@ -116,5 +156,5 @@ export type ActBuilder<S extends SchemaRegister<A>, E extends Schemas, A extends
|
|
|
116
156
|
* @see {@link state} for defining states
|
|
117
157
|
* @see {@link slice} for defining slices
|
|
118
158
|
*/
|
|
119
|
-
export declare function act<
|
|
159
|
+
export declare function act<TSchemaReg extends SchemaRegister<TActions> = {}, TEvents extends Schemas = {}, TActions extends Schemas = {}, TStateMap extends Record<string, Schema> = {}, TActor extends Actor = Actor>(states?: Map<string, State<any, any, any>>, registry?: Registry<TSchemaReg, TEvents, TActions>, pendingProjections?: Projection<any>[]): ActBuilder<TSchemaReg, TEvents, TActions, TStateMap, TActor>;
|
|
120
160
|
//# sourceMappingURL=act-builder.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"act-builder.d.ts","sourceRoot":"","sources":["../../src/act-builder.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAE/B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,KAAK,EACV,SAAS,EACT,UAAU,EACV,aAAa,EAGb,eAAe,EACf,gBAAgB,EAChB,QAAQ,EACR,MAAM,EACN,cAAc,EACd,OAAO,EACP,QAAQ,EACR,KAAK,EACN,MAAM,kBAAkB,CAAC;AAE1B
|
|
1
|
+
{"version":3,"file":"act-builder.d.ts","sourceRoot":"","sources":["../../src/act-builder.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAE/B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,KAAK,EACV,KAAK,EACL,SAAS,EACT,UAAU,EACV,aAAa,EAGb,eAAe,EACf,gBAAgB,EAChB,QAAQ,EACR,MAAM,EACN,cAAc,EACd,OAAO,EACP,QAAQ,EACR,KAAK,EACN,MAAM,kBAAkB,CAAC;AAE1B;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,MAAM,UAAU,CACpB,UAAU,SAAS,cAAc,CAAC,QAAQ,CAAC,EAC3C,OAAO,SAAS,OAAO,EACvB,Q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;;;;;;GAsCG;AACH,wBAAgB,GAAG,CAEjB,UAAU,SAAS,cAAc,CAAC,QAAQ,CAAC,GAAG,EAAE,EAChD,OAAO,SAAS,OAAO,GAAG,EAAE,EAC5B,QAAQ,SAAS,OAAO,GAAG,EAAE,EAC7B,SAAS,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,EAAE,EAC7C,MAAM,SAAS,KAAK,GAAG,KAAK,EAE5B,MAAM,GAAE,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAa,EACrD,QAAQ,GAAE,QAAQ,CAAC,UAAU,EAAE,OAAO,EAAE,QAAQ,CAG/C,EACD,kBAAkB,GAAE,UAAU,CAAC,GAAG,CAAC,EAAO,GACzC,UAAU,CAAC,UAAU,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,CAAC,CAgJ9D"}
|
package/dist/@types/act.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Committed, Drain, DrainOptions, Lease, Query, Registry, Schema, SchemaRegister, Schemas, Snapshot, State, Target } from "./types/index.js";
|
|
1
|
+
import type { Actor, Committed, Drain, DrainOptions, Lease, Query, Registry, Schema, SchemaRegister, Schemas, SettleOptions, Snapshot, State, Target } from "./types/index.js";
|
|
2
2
|
/**
|
|
3
3
|
* @category Orchestrator
|
|
4
4
|
* @see Store
|
|
@@ -19,17 +19,21 @@ import type { Committed, Drain, DrainOptions, Lease, Query, Registry, Schema, Sc
|
|
|
19
19
|
* - Register event listeners with `.on("committed", ...)` and `.on("acked", ...)` to react to lifecycle events.
|
|
20
20
|
* - Use `.query()` to analyze event streams for analytics or debugging.
|
|
21
21
|
*
|
|
22
|
-
* @template
|
|
23
|
-
* @template
|
|
24
|
-
* @template
|
|
22
|
+
* @template TSchemaReg SchemaRegister for state
|
|
23
|
+
* @template TEvents Schemas for events
|
|
24
|
+
* @template TActions Schemas for actions
|
|
25
|
+
* @template TStateMap Map of state names to state schemas
|
|
26
|
+
* @template TActor Actor type extending base Actor
|
|
25
27
|
*/
|
|
26
|
-
export declare class Act<
|
|
27
|
-
readonly registry: Registry<
|
|
28
|
+
export declare class Act<TSchemaReg extends SchemaRegister<TActions>, TEvents extends Schemas, TActions extends Schemas, TStateMap extends Record<string, Schema> = Record<string, never>, TActor extends Actor = Actor> {
|
|
29
|
+
readonly registry: Registry<TSchemaReg, TEvents, TActions>;
|
|
28
30
|
private readonly _states;
|
|
29
31
|
private _emitter;
|
|
30
32
|
private _drain_locked;
|
|
31
33
|
private _drain_lag2lead_ratio;
|
|
32
|
-
private
|
|
34
|
+
private _correlation_timer;
|
|
35
|
+
private _settle_timer;
|
|
36
|
+
private _settling;
|
|
33
37
|
/**
|
|
34
38
|
* Emit a lifecycle event (internal use, but can be used for custom listeners).
|
|
35
39
|
*
|
|
@@ -37,11 +41,12 @@ export declare class Act<S extends SchemaRegister<A>, E extends Schemas, A exten
|
|
|
37
41
|
* @param args The event payload
|
|
38
42
|
* @returns true if the event had listeners, false otherwise
|
|
39
43
|
*/
|
|
40
|
-
emit(event: "committed", args: Snapshot<
|
|
44
|
+
emit(event: "committed", args: Snapshot<TSchemaReg, TEvents>[]): boolean;
|
|
41
45
|
emit(event: "acked", args: Lease[]): boolean;
|
|
42
46
|
emit(event: "blocked", args: Array<Lease & {
|
|
43
47
|
error: string;
|
|
44
48
|
}>): boolean;
|
|
49
|
+
emit(event: "settled", args: Drain<TEvents>): boolean;
|
|
45
50
|
/**
|
|
46
51
|
* Register a listener for a lifecycle event ("committed", "acked", or "blocked").
|
|
47
52
|
*
|
|
@@ -49,11 +54,12 @@ export declare class Act<S extends SchemaRegister<A>, E extends Schemas, A exten
|
|
|
49
54
|
* @param listener The callback function
|
|
50
55
|
* @returns this (for chaining)
|
|
51
56
|
*/
|
|
52
|
-
on(event: "committed", listener: (args: Snapshot<
|
|
57
|
+
on(event: "committed", listener: (args: Snapshot<TSchemaReg, TEvents>[]) => void): this;
|
|
53
58
|
on(event: "acked", listener: (args: Lease[]) => void): this;
|
|
54
59
|
on(event: "blocked", listener: (args: Array<Lease & {
|
|
55
60
|
error: string;
|
|
56
61
|
}>) => void): this;
|
|
62
|
+
on(event: "settled", listener: (args: Drain<TEvents>) => void): this;
|
|
57
63
|
/**
|
|
58
64
|
* Remove a listener for a lifecycle event.
|
|
59
65
|
*
|
|
@@ -61,18 +67,19 @@ export declare class Act<S extends SchemaRegister<A>, E extends Schemas, A exten
|
|
|
61
67
|
* @param listener The callback function
|
|
62
68
|
* @returns this (for chaining)
|
|
63
69
|
*/
|
|
64
|
-
off(event: "committed", listener: (args: Snapshot<
|
|
70
|
+
off(event: "committed", listener: (args: Snapshot<TSchemaReg, TEvents>[]) => void): this;
|
|
65
71
|
off(event: "acked", listener: (args: Lease[]) => void): this;
|
|
66
72
|
off(event: "blocked", listener: (args: Array<Lease & {
|
|
67
73
|
error: string;
|
|
68
74
|
}>) => void): this;
|
|
75
|
+
off(event: "settled", listener: (args: Drain<TEvents>) => void): this;
|
|
69
76
|
/**
|
|
70
77
|
* Create a new Act orchestrator.
|
|
71
78
|
*
|
|
72
79
|
* @param registry The registry of state, event, and action schemas
|
|
73
80
|
* @param states Map of state names to their (potentially merged) state definitions
|
|
74
81
|
*/
|
|
75
|
-
constructor(registry: Registry<
|
|
82
|
+
constructor(registry: Registry<TSchemaReg, TEvents, TActions>, _states?: Map<string, State<any, any, any>>);
|
|
76
83
|
/**
|
|
77
84
|
* Executes an action on a state instance, committing resulting events.
|
|
78
85
|
*
|
|
@@ -84,7 +91,7 @@ export declare class Act<S extends SchemaRegister<A>, E extends Schemas, A exten
|
|
|
84
91
|
* 5. Applies events to create new state
|
|
85
92
|
* 6. Commits events to the store with optimistic concurrency control
|
|
86
93
|
*
|
|
87
|
-
* @template
|
|
94
|
+
* @template TKey - Action name from registered actions
|
|
88
95
|
* @param action - The name of the action to execute
|
|
89
96
|
* @param target - Target specification with stream ID and actor context
|
|
90
97
|
* @param payload - Action payload matching the action's schema
|
|
@@ -156,7 +163,7 @@ export declare class Act<S extends SchemaRegister<A>, E extends Schemas, A exten
|
|
|
156
163
|
* @see {@link Snapshot} for return value structure
|
|
157
164
|
* @see {@link ValidationError}, {@link InvariantError}, {@link ConcurrencyError}
|
|
158
165
|
*/
|
|
159
|
-
do<
|
|
166
|
+
do<TKey extends keyof TActions>(action: TKey, target: Target<TActor>, payload: Readonly<TActions[TKey]>, reactingTo?: Committed<TEvents, string & keyof TEvents>, skipValidation?: boolean): Promise<Snapshot<TSchemaReg[TKey], TEvents>[]>;
|
|
160
167
|
/**
|
|
161
168
|
* Loads the current state snapshot for a specific stream.
|
|
162
169
|
*
|
|
@@ -167,9 +174,9 @@ export declare class Act<S extends SchemaRegister<A>, E extends Schemas, A exten
|
|
|
167
174
|
* using a string, the merged state (from partial states registered via
|
|
168
175
|
* `.withState()`) is resolved by name.
|
|
169
176
|
*
|
|
170
|
-
* @template
|
|
171
|
-
* @template
|
|
172
|
-
* @template
|
|
177
|
+
* @template TNewState - State schema type
|
|
178
|
+
* @template TNewEvents - Event schemas type
|
|
179
|
+
* @template TNewActions - Action schemas type
|
|
173
180
|
* @param state - The state definition or state name to load
|
|
174
181
|
* @param stream - The stream ID (state instance identifier)
|
|
175
182
|
* @param callback - Optional callback invoked with the loaded snapshot
|
|
@@ -198,8 +205,8 @@ export declare class Act<S extends SchemaRegister<A>, E extends Schemas, A exten
|
|
|
198
205
|
*
|
|
199
206
|
* @see {@link Snapshot} for snapshot structure
|
|
200
207
|
*/
|
|
201
|
-
load<
|
|
202
|
-
load<
|
|
208
|
+
load<TNewState extends Schema, TNewEvents extends Schemas, TNewActions extends Schemas>(state: State<TNewState, TNewEvents, TNewActions>, stream: string, callback?: (snapshot: Snapshot<TNewState, TNewEvents>) => void): Promise<Snapshot<TNewState, TNewEvents>>;
|
|
209
|
+
load<TKey extends keyof TStateMap & string>(name: TKey, stream: string, callback?: (snapshot: Snapshot<TStateMap[TKey], TEvents>) => void): Promise<Snapshot<TStateMap[TKey], TEvents>>;
|
|
203
210
|
/**
|
|
204
211
|
* Queries the event store for events matching a filter.
|
|
205
212
|
*
|
|
@@ -251,9 +258,9 @@ export declare class Act<S extends SchemaRegister<A>, E extends Schemas, A exten
|
|
|
251
258
|
*
|
|
252
259
|
* @see {@link query_array} for loading events into memory
|
|
253
260
|
*/
|
|
254
|
-
query(query: Query, callback?: (event: Committed<
|
|
255
|
-
first?: Committed<
|
|
256
|
-
last?: Committed<
|
|
261
|
+
query(query: Query, callback?: (event: Committed<TEvents, keyof TEvents>) => void): Promise<{
|
|
262
|
+
first?: Committed<TEvents, keyof TEvents>;
|
|
263
|
+
last?: Committed<TEvents, keyof TEvents>;
|
|
257
264
|
count: number;
|
|
258
265
|
}>;
|
|
259
266
|
/**
|
|
@@ -282,7 +289,7 @@ export declare class Act<S extends SchemaRegister<A>, E extends Schemas, A exten
|
|
|
282
289
|
*
|
|
283
290
|
* @see {@link query} for large result sets
|
|
284
291
|
*/
|
|
285
|
-
query_array(query: Query): Promise<Committed<
|
|
292
|
+
query_array(query: Query): Promise<Committed<TEvents, keyof TEvents>[]>;
|
|
286
293
|
/**
|
|
287
294
|
* Handles leased reactions.
|
|
288
295
|
*
|
|
@@ -298,7 +305,7 @@ export declare class Act<S extends SchemaRegister<A>, E extends Schemas, A exten
|
|
|
298
305
|
/**
|
|
299
306
|
* Processes pending reactions by draining uncommitted events from the event store.
|
|
300
307
|
*
|
|
301
|
-
*
|
|
308
|
+
* Runs a single drain cycle:
|
|
302
309
|
* 1. Polls the store for streams with uncommitted events
|
|
303
310
|
* 2. Leases streams to prevent concurrent processing
|
|
304
311
|
* 3. Fetches events for each leased stream
|
|
@@ -308,7 +315,8 @@ export declare class Act<S extends SchemaRegister<A>, E extends Schemas, A exten
|
|
|
308
315
|
* Drain uses a dual-frontier strategy to balance processing of new streams (lagging)
|
|
309
316
|
* vs active streams (leading). The ratio adapts based on event pressure.
|
|
310
317
|
*
|
|
311
|
-
* Call
|
|
318
|
+
* Call `correlate()` before `drain()` to discover target streams. For a higher-level
|
|
319
|
+
* API that handles debouncing, correlation, and signaling automatically, use {@link settle}.
|
|
312
320
|
*
|
|
313
321
|
* @param options - Drain configuration options
|
|
314
322
|
* @param options.streamLimit - Maximum number of streams to process per cycle (default: 10)
|
|
@@ -316,50 +324,24 @@ export declare class Act<S extends SchemaRegister<A>, E extends Schemas, A exten
|
|
|
316
324
|
* @param options.leaseMillis - Lease duration in milliseconds (default: 10000)
|
|
317
325
|
* @returns Drain statistics with fetched, leased, acked, and blocked counts
|
|
318
326
|
*
|
|
319
|
-
* @example
|
|
327
|
+
* @example In tests and scripts
|
|
320
328
|
* ```typescript
|
|
321
|
-
* // Process reactions after each action
|
|
322
329
|
* await app.do("createUser", target, payload);
|
|
330
|
+
* await app.correlate();
|
|
323
331
|
* await app.drain();
|
|
324
332
|
* ```
|
|
325
333
|
*
|
|
326
|
-
* @example
|
|
327
|
-
* ```typescript
|
|
328
|
-
* setInterval(async () => {
|
|
329
|
-
* try {
|
|
330
|
-
* const result = await app.drain({
|
|
331
|
-
* streamLimit: 20,
|
|
332
|
-
* eventLimit: 50
|
|
333
|
-
* });
|
|
334
|
-
* if (result.acked.length) {
|
|
335
|
-
* console.log(`Processed ${result.acked.length} streams`);
|
|
336
|
-
* }
|
|
337
|
-
* } catch (error) {
|
|
338
|
-
* console.error("Drain error:", error);
|
|
339
|
-
* }
|
|
340
|
-
* }, 5000); // Every 5 seconds
|
|
341
|
-
* ```
|
|
342
|
-
*
|
|
343
|
-
* @example With lifecycle listeners
|
|
334
|
+
* @example In production, prefer settle()
|
|
344
335
|
* ```typescript
|
|
345
|
-
* app.
|
|
346
|
-
*
|
|
347
|
-
* });
|
|
348
|
-
*
|
|
349
|
-
* app.on("blocked", (blocked) => {
|
|
350
|
-
* console.error(`Blocked ${blocked.length} streams due to errors`);
|
|
351
|
-
* blocked.forEach(({ stream, error }) => {
|
|
352
|
-
* console.error(`Stream ${stream}: ${error}`);
|
|
353
|
-
* });
|
|
354
|
-
* });
|
|
355
|
-
*
|
|
356
|
-
* await app.drain();
|
|
336
|
+
* await app.do("CreateItem", target, input);
|
|
337
|
+
* app.settle(); // debounced correlate→drain, emits "settled"
|
|
357
338
|
* ```
|
|
358
339
|
*
|
|
340
|
+
* @see {@link settle} for debounced correlate→drain with lifecycle events
|
|
359
341
|
* @see {@link correlate} for dynamic stream discovery
|
|
360
342
|
* @see {@link start_correlations} for automatic correlation
|
|
361
343
|
*/
|
|
362
|
-
drain({ streamLimit, eventLimit, leaseMillis, }?: DrainOptions): Promise<Drain<
|
|
344
|
+
drain({ streamLimit, eventLimit, leaseMillis, }?: DrainOptions): Promise<Drain<TEvents>>;
|
|
363
345
|
/**
|
|
364
346
|
* Discovers and registers new streams dynamically based on reaction resolvers.
|
|
365
347
|
*
|
|
@@ -483,5 +465,41 @@ export declare class Act<S extends SchemaRegister<A>, E extends Schemas, A exten
|
|
|
483
465
|
* @see {@link start_correlations}
|
|
484
466
|
*/
|
|
485
467
|
stop_correlations(): void;
|
|
468
|
+
/**
|
|
469
|
+
* Cancels any pending or active settle cycle.
|
|
470
|
+
*
|
|
471
|
+
* @see {@link settle}
|
|
472
|
+
*/
|
|
473
|
+
stop_settling(): void;
|
|
474
|
+
/**
|
|
475
|
+
* Debounced, non-blocking correlate→drain cycle.
|
|
476
|
+
*
|
|
477
|
+
* Call this after `app.do()` to schedule a background drain. Multiple rapid
|
|
478
|
+
* calls within the debounce window are coalesced into a single cycle. Runs
|
|
479
|
+
* correlate→drain in a loop until the system reaches a consistent state,
|
|
480
|
+
* then emits the `"settled"` lifecycle event.
|
|
481
|
+
*
|
|
482
|
+
* @param options - Settle configuration options
|
|
483
|
+
* @param options.debounceMs - Debounce window in milliseconds (default: 10)
|
|
484
|
+
* @param options.correlate - Query filter for correlation scans (default: `{ after: -1, limit: 100 }`)
|
|
485
|
+
* @param options.maxPasses - Maximum correlate→drain loops (default: 5)
|
|
486
|
+
* @param options.streamLimit - Maximum streams per drain cycle (default: 10)
|
|
487
|
+
* @param options.eventLimit - Maximum events per stream (default: 10)
|
|
488
|
+
* @param options.leaseMillis - Lease duration in milliseconds (default: 10000)
|
|
489
|
+
*
|
|
490
|
+
* @example API mutations
|
|
491
|
+
* ```typescript
|
|
492
|
+
* await app.do("CreateItem", target, input);
|
|
493
|
+
* app.settle(); // non-blocking, returns immediately
|
|
494
|
+
*
|
|
495
|
+
* app.on("settled", (drain) => {
|
|
496
|
+
* // notify SSE clients, invalidate caches, etc.
|
|
497
|
+
* });
|
|
498
|
+
* ```
|
|
499
|
+
*
|
|
500
|
+
* @see {@link drain} for single synchronous drain cycles
|
|
501
|
+
* @see {@link correlate} for manual correlation
|
|
502
|
+
*/
|
|
503
|
+
settle(options?: SettleOptions): void;
|
|
486
504
|
}
|
|
487
505
|
//# sourceMappingURL=act.d.ts.map
|
package/dist/@types/act.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"act.d.ts","sourceRoot":"","sources":["../../src/act.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,SAAS,EACT,KAAK,EACL,YAAY,EACZ,KAAK,EACL,KAAK,EAEL,QAAQ,EACR,MAAM,EACN,cAAc,EACd,OAAO,EACP,QAAQ,EACR,KAAK,EACL,MAAM,EACP,MAAM,kBAAkB,CAAC;AAI1B
|
|
1
|
+
{"version":3,"file":"act.d.ts","sourceRoot":"","sources":["../../src/act.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,KAAK,EACL,SAAS,EACT,KAAK,EACL,YAAY,EACZ,KAAK,EACL,KAAK,EAEL,QAAQ,EACR,MAAM,EACN,cAAc,EACd,OAAO,EACP,aAAa,EACb,QAAQ,EACR,KAAK,EACL,MAAM,EACP,MAAM,kBAAkB,CAAC;AAI1B;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,qBAAa,GAAG,CACd,UAAU,SAAS,cAAc,CAAC,QAAQ,CAAC,EAC3C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;;;;OAyBG;IACG,WAAW,CACf,KAAK,EAAE,KAAK,GACX,OAAO,CAAC,SAAS,CAAC,OAAO,EAAE,MAAM,OAAO,CAAC,EAAE,CAAC;IAM/C;;;;;;;;;;OAUG;YACW,MAAM;IA4CpB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAsCG;IACG,KAAK,CAAC,EACV,WAAgB,EAChB,UAAe,EACf,WAAoB,GACrB,GAAE,YAAiB,GAAG,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAmH9C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA4CG;IACG,SAAS,CACb,KAAK,GAAE,KAAgC,GACtC,OAAO,CAAC;QAAE,MAAM,EAAE,KAAK,EAAE,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;IAwChD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAsDG;IACH,kBAAkB,CAChB,KAAK,GAAE,KAAU,EACjB,SAAS,SAAS,EAClB,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,KAAK,EAAE,KAAK,IAAI,GACnC,OAAO;IAkBV;;;;;;;;;;;;;;;;OAgBG;IACH,iBAAiB;IAOjB;;;;OAIG;IACH,aAAa;IAOb;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA4BG;IACH,MAAM,CAAC,OAAO,GAAE,aAAkB,GAAG,IAAI;CA8B1C"}
|
|
@@ -14,21 +14,21 @@ import type { Committed, Schema, Schemas, Snapshot, State, Target } from "./type
|
|
|
14
14
|
*
|
|
15
15
|
* Snapshots are used to optimize state reconstruction for aggregates with long event streams.
|
|
16
16
|
*
|
|
17
|
-
* @template
|
|
18
|
-
* @template
|
|
17
|
+
* @template TState The type of state
|
|
18
|
+
* @template TEvents The type of events
|
|
19
19
|
* @param snapshot The snapshot to save
|
|
20
20
|
* @returns Promise that resolves when the snapshot is saved
|
|
21
21
|
*
|
|
22
22
|
* @example
|
|
23
23
|
* await snap(snapshot);
|
|
24
24
|
*/
|
|
25
|
-
export declare function snap<
|
|
25
|
+
export declare function snap<TState extends Schema, TEvents extends Schemas>(snapshot: Snapshot<TState, TEvents>): Promise<void>;
|
|
26
26
|
/**
|
|
27
27
|
* Loads a snapshot of the state from the store by replaying events and applying patches.
|
|
28
28
|
*
|
|
29
|
-
* @template
|
|
30
|
-
* @template
|
|
31
|
-
* @template
|
|
29
|
+
* @template TState The type of state
|
|
30
|
+
* @template TEvents The type of events
|
|
31
|
+
* @template TActions The type of actions
|
|
32
32
|
* @param me The state machine definition
|
|
33
33
|
* @param stream The stream (instance) to load
|
|
34
34
|
* @param callback (Optional) Callback to receive the loaded snapshot as it is built
|
|
@@ -37,16 +37,16 @@ export declare function snap<S extends Schema, E extends Schemas>(snapshot: Snap
|
|
|
37
37
|
* @example
|
|
38
38
|
* const snapshot = await load(Counter, "counter1");
|
|
39
39
|
*/
|
|
40
|
-
export declare function load<
|
|
40
|
+
export declare function load<TState extends Schema, TEvents extends Schemas, TActions extends Schemas>(me: State<TState, TEvents, TActions>, stream: string, callback?: (snapshot: Snapshot<TState, TEvents>) => void): Promise<Snapshot<TState, TEvents>>;
|
|
41
41
|
/**
|
|
42
42
|
* Executes an action and emits an event to be committed by the store.
|
|
43
43
|
*
|
|
44
44
|
* This function validates the action, applies business invariants, emits events, and commits them to the event store.
|
|
45
45
|
*
|
|
46
|
-
* @template
|
|
47
|
-
* @template
|
|
48
|
-
* @template
|
|
49
|
-
* @template
|
|
46
|
+
* @template TState The type of state
|
|
47
|
+
* @template TEvents The type of events
|
|
48
|
+
* @template TActions The type of actionSchemas
|
|
49
|
+
* @template TKey The type of action to execute
|
|
50
50
|
* @param me The state machine definition
|
|
51
51
|
* @param action The action to execute
|
|
52
52
|
* @param target The target (stream, actor, etc.)
|
|
@@ -58,5 +58,5 @@ export declare function load<S extends Schema, E extends Schemas, A extends Sche
|
|
|
58
58
|
* @example
|
|
59
59
|
* const snapshot = await action(Counter, "increment", { stream: "counter1", actor }, { by: 1 });
|
|
60
60
|
*/
|
|
61
|
-
export declare function action<
|
|
61
|
+
export declare function action<TState extends Schema, TEvents extends Schemas, TActions extends Schemas, TKey extends keyof TActions>(me: State<TState, TEvents, TActions>, action: TKey, target: Target, payload: Readonly<TActions[TKey]>, reactingTo?: Committed<Schemas, keyof Schemas>, skipValidation?: boolean): Promise<Snapshot<TState, TEvents>[]>;
|
|
62
62
|
//# sourceMappingURL=event-sourcing.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event-sourcing.d.ts","sourceRoot":"","sources":["../../src/event-sourcing.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,OAAO,KAAK,EACV,SAAS,EAGT,MAAM,EACN,OAAO,EACP,QAAQ,EACR,KAAK,EACL,MAAM,EACP,MAAM,kBAAkB,CAAC;AAG1B;;;GAGG;AAEH;;;;;;;;;;;;GAYG;AACH,wBAAsB,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"event-sourcing.d.ts","sourceRoot":"","sources":["../../src/event-sourcing.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,OAAO,KAAK,EACV,SAAS,EAGT,MAAM,EACN,OAAO,EACP,QAAQ,EACR,KAAK,EACL,MAAM,EACP,MAAM,kBAAkB,CAAC;AAG1B;;;GAGG;AAEH;;;;;;;;;;;;GAYG;AACH,wBAAsB,IAAI,CAAC,MAAM,SAAS,MAAM,EAAE,OAAO,SAAS,OAAO,EACvE,QAAQ,EAAE,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC,GAClC,OAAO,CAAC,IAAI,CAAC,CAgBf;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAsB,IAAI,CACxB,MAAM,SAAS,MAAM,EACrB,OAAO,SAAS,OAAO,EACvB,QAAQ,SAAS,OAAO,EAExB,EAAE,EAAE,KAAK,CAAC,MAAM,EAAE,OAAO,EAAE,QAAQ,CAAC,EACpC,MAAM,EAAE,MAAM,EACd,QAAQ,CAAC,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,IAAI,GACvD,OAAO,CAAC,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAsBpC;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAsB,MAAM,CAC1B,MAAM,SAAS,MAAM,EACrB,OAAO,SAAS,OAAO,EACvB,QAAQ,SAAS,OAAO,EACxB,IAAI,SAAS,MAAM,QAAQ,EAE3B,EAAE,EAAE,KAAK,CAAC,MAAM,EAAE,OAAO,EAAE,QAAQ,CAAC,EACpC,MAAM,EAAE,IAAI,EACZ,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,EACjC,UAAU,CAAC,EAAE,SAAS,CAAC,OAAO,EAAE,MAAM,OAAO,CAAC,EAC9C,cAAc,UAAQ,GACrB,OAAO,CAAC,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC,CA6FtC"}
|
package/dist/@types/merge.d.ts
CHANGED
|
@@ -23,7 +23,7 @@ export declare function mergeSchemas(existing: ZodType, incoming: ZodType, state
|
|
|
23
23
|
* Merges two init functions by spreading both results together.
|
|
24
24
|
* Each partial only provides its own defaults.
|
|
25
25
|
*/
|
|
26
|
-
export declare function mergeInits<
|
|
26
|
+
export declare function mergeInits<TState extends Schema>(existing: () => Readonly<TState>, incoming: () => Readonly<TState>): () => Readonly<TState>;
|
|
27
27
|
/**
|
|
28
28
|
* Registers a state into a states map and action/event registries,
|
|
29
29
|
* merging with existing same-name states (partial state support).
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"merge.d.ts","sourceRoot":"","sources":["../../src/merge.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAa,KAAK,OAAO,EAAE,MAAM,KAAK,CAAC;AAC9C,OAAO,KAAK,EAAE,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