@rotorsoft/act 0.14.0 → 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/.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 +24 -22
- 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 +25 -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 +33 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +33 -8
- 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,QAAQ,SAAS,OA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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, Snapshot, State, Target } from "./types/index.js";
|
|
2
2
|
/**
|
|
3
3
|
* @category Orchestrator
|
|
4
4
|
* @see Store
|
|
@@ -19,12 +19,14 @@ 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;
|
|
@@ -37,7 +39,7 @@ export declare class Act<S extends SchemaRegister<A>, E extends Schemas, A exten
|
|
|
37
39
|
* @param args The event payload
|
|
38
40
|
* @returns true if the event had listeners, false otherwise
|
|
39
41
|
*/
|
|
40
|
-
emit(event: "committed", args: Snapshot<
|
|
42
|
+
emit(event: "committed", args: Snapshot<TSchemaReg, TEvents>[]): boolean;
|
|
41
43
|
emit(event: "acked", args: Lease[]): boolean;
|
|
42
44
|
emit(event: "blocked", args: Array<Lease & {
|
|
43
45
|
error: string;
|
|
@@ -49,7 +51,7 @@ export declare class Act<S extends SchemaRegister<A>, E extends Schemas, A exten
|
|
|
49
51
|
* @param listener The callback function
|
|
50
52
|
* @returns this (for chaining)
|
|
51
53
|
*/
|
|
52
|
-
on(event: "committed", listener: (args: Snapshot<
|
|
54
|
+
on(event: "committed", listener: (args: Snapshot<TSchemaReg, TEvents>[]) => void): this;
|
|
53
55
|
on(event: "acked", listener: (args: Lease[]) => void): this;
|
|
54
56
|
on(event: "blocked", listener: (args: Array<Lease & {
|
|
55
57
|
error: string;
|
|
@@ -61,7 +63,7 @@ export declare class Act<S extends SchemaRegister<A>, E extends Schemas, A exten
|
|
|
61
63
|
* @param listener The callback function
|
|
62
64
|
* @returns this (for chaining)
|
|
63
65
|
*/
|
|
64
|
-
off(event: "committed", listener: (args: Snapshot<
|
|
66
|
+
off(event: "committed", listener: (args: Snapshot<TSchemaReg, TEvents>[]) => void): this;
|
|
65
67
|
off(event: "acked", listener: (args: Lease[]) => void): this;
|
|
66
68
|
off(event: "blocked", listener: (args: Array<Lease & {
|
|
67
69
|
error: string;
|
|
@@ -72,7 +74,7 @@ export declare class Act<S extends SchemaRegister<A>, E extends Schemas, A exten
|
|
|
72
74
|
* @param registry The registry of state, event, and action schemas
|
|
73
75
|
* @param states Map of state names to their (potentially merged) state definitions
|
|
74
76
|
*/
|
|
75
|
-
constructor(registry: Registry<
|
|
77
|
+
constructor(registry: Registry<TSchemaReg, TEvents, TActions>, _states?: Map<string, State<any, any, any>>);
|
|
76
78
|
/**
|
|
77
79
|
* Executes an action on a state instance, committing resulting events.
|
|
78
80
|
*
|
|
@@ -84,7 +86,7 @@ export declare class Act<S extends SchemaRegister<A>, E extends Schemas, A exten
|
|
|
84
86
|
* 5. Applies events to create new state
|
|
85
87
|
* 6. Commits events to the store with optimistic concurrency control
|
|
86
88
|
*
|
|
87
|
-
* @template
|
|
89
|
+
* @template TKey - Action name from registered actions
|
|
88
90
|
* @param action - The name of the action to execute
|
|
89
91
|
* @param target - Target specification with stream ID and actor context
|
|
90
92
|
* @param payload - Action payload matching the action's schema
|
|
@@ -156,7 +158,7 @@ export declare class Act<S extends SchemaRegister<A>, E extends Schemas, A exten
|
|
|
156
158
|
* @see {@link Snapshot} for return value structure
|
|
157
159
|
* @see {@link ValidationError}, {@link InvariantError}, {@link ConcurrencyError}
|
|
158
160
|
*/
|
|
159
|
-
do<
|
|
161
|
+
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
162
|
/**
|
|
161
163
|
* Loads the current state snapshot for a specific stream.
|
|
162
164
|
*
|
|
@@ -167,9 +169,9 @@ export declare class Act<S extends SchemaRegister<A>, E extends Schemas, A exten
|
|
|
167
169
|
* using a string, the merged state (from partial states registered via
|
|
168
170
|
* `.withState()`) is resolved by name.
|
|
169
171
|
*
|
|
170
|
-
* @template
|
|
171
|
-
* @template
|
|
172
|
-
* @template
|
|
172
|
+
* @template TNewState - State schema type
|
|
173
|
+
* @template TNewEvents - Event schemas type
|
|
174
|
+
* @template TNewActions - Action schemas type
|
|
173
175
|
* @param state - The state definition or state name to load
|
|
174
176
|
* @param stream - The stream ID (state instance identifier)
|
|
175
177
|
* @param callback - Optional callback invoked with the loaded snapshot
|
|
@@ -198,8 +200,8 @@ export declare class Act<S extends SchemaRegister<A>, E extends Schemas, A exten
|
|
|
198
200
|
*
|
|
199
201
|
* @see {@link Snapshot} for snapshot structure
|
|
200
202
|
*/
|
|
201
|
-
load<
|
|
202
|
-
load<
|
|
203
|
+
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>>;
|
|
204
|
+
load<TKey extends keyof TStateMap & string>(name: TKey, stream: string, callback?: (snapshot: Snapshot<TStateMap[TKey], TEvents>) => void): Promise<Snapshot<TStateMap[TKey], TEvents>>;
|
|
203
205
|
/**
|
|
204
206
|
* Queries the event store for events matching a filter.
|
|
205
207
|
*
|
|
@@ -251,9 +253,9 @@ export declare class Act<S extends SchemaRegister<A>, E extends Schemas, A exten
|
|
|
251
253
|
*
|
|
252
254
|
* @see {@link query_array} for loading events into memory
|
|
253
255
|
*/
|
|
254
|
-
query(query: Query, callback?: (event: Committed<
|
|
255
|
-
first?: Committed<
|
|
256
|
-
last?: Committed<
|
|
256
|
+
query(query: Query, callback?: (event: Committed<TEvents, keyof TEvents>) => void): Promise<{
|
|
257
|
+
first?: Committed<TEvents, keyof TEvents>;
|
|
258
|
+
last?: Committed<TEvents, keyof TEvents>;
|
|
257
259
|
count: number;
|
|
258
260
|
}>;
|
|
259
261
|
/**
|
|
@@ -282,7 +284,7 @@ export declare class Act<S extends SchemaRegister<A>, E extends Schemas, A exten
|
|
|
282
284
|
*
|
|
283
285
|
* @see {@link query} for large result sets
|
|
284
286
|
*/
|
|
285
|
-
query_array(query: Query): Promise<Committed<
|
|
287
|
+
query_array(query: Query): Promise<Committed<TEvents, keyof TEvents>[]>;
|
|
286
288
|
/**
|
|
287
289
|
* Handles leased reactions.
|
|
288
290
|
*
|
|
@@ -359,7 +361,7 @@ export declare class Act<S extends SchemaRegister<A>, E extends Schemas, A exten
|
|
|
359
361
|
* @see {@link correlate} for dynamic stream discovery
|
|
360
362
|
* @see {@link start_correlations} for automatic correlation
|
|
361
363
|
*/
|
|
362
|
-
drain({ streamLimit, eventLimit, leaseMillis, }?: DrainOptions): Promise<Drain<
|
|
364
|
+
drain({ streamLimit, eventLimit, leaseMillis, }?: DrainOptions): Promise<Drain<TEvents>>;
|
|
363
365
|
/**
|
|
364
366
|
* Discovers and registers new streams dynamically based on reaction resolvers.
|
|
365
367
|
*
|
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,QAAQ,EACR,KAAK,EACL,MAAM,EACP,MAAM,kBAAkB,CAAC;AAI1B;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,qBAAa,GAAG,CACd,UAAU,SAAS,cAA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C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;CAMlB"}
|
|
@@ -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,KAA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AO,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,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAEtD;;;GAGG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,CAMrD;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAC1B,QAAQ,EAAE,OAAO,EACjB,QAAQ,EAAE,OAAO,EACjB,SAAS,EAAE,MAAM,GAChB,OAAO,CAkBT;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,
|
|
1
|
+
{"version":3,"file":"merge.d.ts","sourceRoot":"","sources":["../../src/merge.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAa,K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ema, Schemas } from
|
|
|
14
14
|
* A self-contained projection grouping read-model update handlers.
|
|
15
15
|
* Projections are composed into an Act orchestrator via `act().withProjection(projection)`.
|
|
16
16
|
*
|
|
17
|
-
* @template
|
|
17
|
+
* @template TEvents - Event schemas handled by this projection
|
|
18
18
|
*/
|
|
19
|
-
export type Projection<
|
|
19
|
+
export type Projection<TEvents extends Schemas> = {
|
|
20
20
|
readonly _tag: "Projection";
|
|
21
|
-
readonly events: EventRegister<
|
|
21
|
+
readonly events: EventRegister<TEvents>;
|
|
22
22
|
};
|
|
23
23
|
/** Helper: a single-key record mapping an event name to its Zod schema. */
|
|
24
|
-
type EventEntry<
|
|
25
|
-
[P in
|
|
24
|
+
type EventEntry<TKey extends string = string, TData extends Schema = Schema> = {
|
|
25
|
+
[P in TKey]: ZodType<TData>;
|
|
26
26
|
};
|
|
27
27
|
/** Infer the handler-result type after registering one event. */
|
|
28
|
-
type DoResult<
|
|
29
|
-
[P in
|
|
28
|
+
type DoResult<TEvents extends Schemas, TKey extends string, TData extends Schema> = ProjectionBuilder<TEvents & {
|
|
29
|
+
[P in TKey]: TData;
|
|
30
30
|
}> & {
|
|
31
|
-
to: (resolver: ReactionResolver<
|
|
32
|
-
[P in
|
|
33
|
-
},
|
|
34
|
-
[P in
|
|
31
|
+
to: (resolver: ReactionResolver<TEvents & {
|
|
32
|
+
[P in TKey]: TData;
|
|
33
|
+
}, TKey> | string) => ProjectionBuilder<TEvents & {
|
|
34
|
+
[P in TKey]: TData;
|
|
35
35
|
}>;
|
|
36
|
-
void: () => ProjectionBuilder<
|
|
37
|
-
[P in
|
|
36
|
+
void: () => ProjectionBuilder<TEvents & {
|
|
37
|
+
[P in TKey]: TData;
|
|
38
38
|
}>;
|
|
39
39
|
};
|
|
40
40
|
/**
|
|
@@ -48,9 +48,9 @@ type DoResult<E extends Schemas, K extends string, D extends Schema> = Projectio
|
|
|
48
48
|
* handlers inherit that resolver. Per-handler `.to()` or `.void()` can
|
|
49
49
|
* still override it.
|
|
50
50
|
*
|
|
51
|
-
* @template
|
|
51
|
+
* @template TEvents - Event schemas
|
|
52
52
|
*/
|
|
53
|
-
export type ProjectionBuilder<
|
|
53
|
+
export type ProjectionBuilder<TEvents extends Schemas> = {
|
|
54
54
|
/**
|
|
55
55
|
* Begins defining a projection handler for a specific event.
|
|
56
56
|
*
|
|
@@ -58,19 +58,19 @@ export type ProjectionBuilder<E extends Schemas> = {
|
|
|
58
58
|
* when the variable name matches the event name. The key becomes the
|
|
59
59
|
* event name, the value the Zod schema.
|
|
60
60
|
*/
|
|
61
|
-
on: <
|
|
62
|
-
do: (handler: (event: Committed<
|
|
63
|
-
[P in
|
|
64
|
-
},
|
|
61
|
+
on: <TKey extends string, TData extends Schema>(entry: EventEntry<TKey, TData>) => {
|
|
62
|
+
do: (handler: (event: Committed<TEvents & {
|
|
63
|
+
[P in TKey]: TData;
|
|
64
|
+
}, TKey>, stream: string) => Promise<void>) => DoResult<TEvents, TKey, TData>;
|
|
65
65
|
};
|
|
66
66
|
/**
|
|
67
67
|
* Builds and returns the Projection data structure.
|
|
68
68
|
*/
|
|
69
|
-
build: () => Projection<
|
|
69
|
+
build: () => Projection<TEvents>;
|
|
70
70
|
/**
|
|
71
71
|
* The registered event schemas and their reaction maps.
|
|
72
72
|
*/
|
|
73
|
-
readonly events: EventRegister<
|
|
73
|
+
readonly events: EventRegister<TEvents>;
|
|
74
74
|
};
|
|
75
75
|
/**
|
|
76
76
|
* Creates a new projection builder for composing read-model update handlers.
|
|
@@ -114,6 +114,6 @@ export type ProjectionBuilder<E extends Schemas> = {
|
|
|
114
114
|
* @see {@link ProjectionBuilder} for builder methods
|
|
115
115
|
* @see {@link Projection} for the output type
|
|
116
116
|
*/
|
|
117
|
-
export declare function projection<
|
|
117
|
+
export declare function projection<TEvents extends Schemas = {}>(target?: string, events?: EventRegister<TEvents>): ProjectionBuilder<TEvents>;
|
|
118
118
|
export {};
|
|
119
119
|
//# sourceMappingURL=projection-builder.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"projection-builder.d.ts","sourceRoot":"","sources":["../../src/projection-builder.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AAEnC,OAAO,KAAK,EACV,SAAS,EACT,aAAa,EAGb,gBAAgB,EAChB,MAAM,EACN,OAAO,EACR,MAAM,kBAAkB,CAAC;AAE1B;;;;;GAKG;AACH,MAAM,MAAM,UAAU,CAAC,
|
|
1
|
+
{"version":3,"file":"projection-builder.d.ts","sourceRoot":"","sources":["../../src/projection-builder.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AAEnC,OAAO,KAAK,EACV,SAAS,EACT,aAAa,EAGb,gBAAgB,EAChB,MAAM,EACN,OAAO,EACR,MAAM,kBAAkB,CAAC;AAE1B;;;;;GAKG;AACH,MAAM,MAAM,UAAU,CAAC,OAAO,SAAS,OAAO,IAAI;IAChD,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAC;IAC5B,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC,OAAO,CAAC,CAAC;CACzC,CAAC;AAEF,2EAA2E;AAC3E,KAAK,UAAU,CAAC,IAAI,SAAS,MAAM,GAAG,MAAM,EAAE,KAAK,SAAS,MAAM,GAAG,MAAM,IAAI;KAC5E,CAAC,IAAI,IAAI,GAAG,OAAO,CAAC,KAAK,CAAC;CAC5B,CAAC;AAEF,iEAAiE;AACjE,KAAK,QAAQ,CACX,OAAO,SAAS,OAAO,EACvB,IAAI,SAAS,MAAM,EACnB,KAAK,SAAS,MAAM,IAClB,iBAAiB,CAAC,OAAO,GAAG;KAAG,CAAC,IAAI,IAAI,GAAG,KAAK;CAAE,CAAC,GAAG;IACxD,EAAE,EAAE,CACF,QAAQ,EAAE,gBAAgB,CAAC,OAAO,GAAG;SAAG,CAAC,IAAI,IAAI,G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