@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
|
@@ -1,24 +1,27 @@
|
|
|
1
1
|
import type { Projection } from "./projection-builder.js";
|
|
2
|
-
import type { Committed, Dispatcher, EventRegister, ReactionOptions, ReactionResolver, Schema, SchemaRegister, Schemas, Snapshot, State } from "./types/index.js";
|
|
2
|
+
import type { Actor, Committed, Dispatcher, EventRegister, ReactionOptions, ReactionResolver, Schema, SchemaRegister, Schemas, Snapshot, State } from "./types/index.js";
|
|
3
3
|
/**
|
|
4
4
|
* A self-contained functional slice grouping partial states with their
|
|
5
5
|
* scoped reactions. Slices are composed into an Act orchestrator via
|
|
6
6
|
* `act().withSlice(slice)`.
|
|
7
7
|
*
|
|
8
|
-
* @template
|
|
9
|
-
* @template
|
|
10
|
-
* @template
|
|
11
|
-
* @template
|
|
8
|
+
* @template TSchemaReg - Schema register for states
|
|
9
|
+
* @template TEvents - Event schemas from this slice's states
|
|
10
|
+
* @template TActions - Action schemas from this slice's states
|
|
11
|
+
* @template TStateMap - Map of state names to state schemas
|
|
12
|
+
* @template TActor - Actor type extending base Actor
|
|
12
13
|
*/
|
|
13
|
-
export type Slice<
|
|
14
|
+
export type Slice<TSchemaReg extends SchemaRegister<TActions>, TEvents extends Schemas, TActions extends Schemas, TStateMap extends Record<string, Schema> = {}, TActor extends Actor = Actor> = {
|
|
14
15
|
readonly _tag: "Slice";
|
|
15
16
|
readonly states: Map<string, State<any, any, any>>;
|
|
16
|
-
readonly events: EventRegister<
|
|
17
|
+
readonly events: EventRegister<TEvents>;
|
|
17
18
|
readonly projections: ReadonlyArray<Projection<any>>;
|
|
18
19
|
/** @internal phantom field for type-level state schema tracking */
|
|
19
|
-
readonly _S?:
|
|
20
|
+
readonly _S?: TSchemaReg;
|
|
20
21
|
/** @internal phantom field for type-level state name tracking */
|
|
21
|
-
readonly _M?:
|
|
22
|
+
readonly _M?: TStateMap;
|
|
23
|
+
/** @internal phantom field for type-level actor tracking */
|
|
24
|
+
readonly _TActor?: TActor;
|
|
22
25
|
};
|
|
23
26
|
/**
|
|
24
27
|
* Fluent builder interface for composing functional slices.
|
|
@@ -26,12 +29,13 @@ export type Slice<S extends SchemaRegister<A>, E extends Schemas, A extends Sche
|
|
|
26
29
|
* Provides a chainable API for registering states and projections,
|
|
27
30
|
* and defining reactions scoped to the slice's own events.
|
|
28
31
|
*
|
|
29
|
-
* @template
|
|
30
|
-
* @template
|
|
31
|
-
* @template
|
|
32
|
-
* @template
|
|
32
|
+
* @template TSchemaReg - Schema register for states
|
|
33
|
+
* @template TEvents - Event schemas
|
|
34
|
+
* @template TActions - Action schemas
|
|
35
|
+
* @template TStateMap - Map of state names to state schemas
|
|
36
|
+
* @template TActor - Actor type extending base Actor
|
|
33
37
|
*/
|
|
34
|
-
export type SliceBuilder<
|
|
38
|
+
export type SliceBuilder<TSchemaReg extends SchemaRegister<TActions>, TEvents extends Schemas, TActions extends Schemas, TStateMap extends Record<string, Schema> = {}, TActor extends Actor = Actor> = {
|
|
35
39
|
/**
|
|
36
40
|
* Registers a state definition with the slice.
|
|
37
41
|
*
|
|
@@ -39,35 +43,35 @@ export type SliceBuilder<S extends SchemaRegister<A>, E extends Schemas, A exten
|
|
|
39
43
|
* dispatch. Duplicate registrations (same state in multiple slices)
|
|
40
44
|
* are handled automatically at composition time.
|
|
41
45
|
*/
|
|
42
|
-
withState: <
|
|
43
|
-
[K in keyof
|
|
44
|
-
},
|
|
45
|
-
[K in
|
|
46
|
-
}>;
|
|
46
|
+
withState: <TNewState extends Schema, TNewEvents extends Schemas, TNewActions extends Schemas, TNewName extends string = string>(state: State<TNewState, TNewEvents, TNewActions, TNewName>) => SliceBuilder<TSchemaReg & {
|
|
47
|
+
[K in keyof TNewActions]: TNewState;
|
|
48
|
+
}, TEvents & TNewEvents, TActions & TNewActions, TStateMap & {
|
|
49
|
+
[K in TNewName]: TNewState;
|
|
50
|
+
}, TActor>;
|
|
47
51
|
/**
|
|
48
52
|
* Embeds a built Projection within this slice. The projection's events
|
|
49
53
|
* must be a subset of events from states already registered via
|
|
50
54
|
* `.withState()`. Projection handlers preserve their `(event, stream)`
|
|
51
55
|
* signature and do not receive a Dispatcher.
|
|
52
56
|
*/
|
|
53
|
-
withProjection: <
|
|
57
|
+
withProjection: <TNewEvents extends Schemas>(projection: [Exclude<keyof TNewEvents, keyof TEvents>] extends [never] ? Projection<TNewEvents> : never) => SliceBuilder<TSchemaReg, TEvents, TActions, TStateMap, TActor>;
|
|
54
58
|
/**
|
|
55
59
|
* Begins defining a reaction scoped to this slice's events.
|
|
56
60
|
*/
|
|
57
|
-
on: <
|
|
58
|
-
do: (handler: (event: Committed<
|
|
59
|
-
to: (resolver: ReactionResolver<
|
|
60
|
-
void: () => SliceBuilder<
|
|
61
|
+
on: <TKey extends keyof TEvents>(event: TKey) => {
|
|
62
|
+
do: (handler: (event: Committed<TEvents, TKey>, stream: string, app: Dispatcher<TActions, TActor>) => Promise<Snapshot<Schema, TEvents> | void>, options?: Partial<ReactionOptions>) => SliceBuilder<TSchemaReg, TEvents, TActions, TStateMap, TActor> & {
|
|
63
|
+
to: (resolver: ReactionResolver<TEvents, TKey> | string) => SliceBuilder<TSchemaReg, TEvents, TActions, TStateMap, TActor>;
|
|
64
|
+
void: () => SliceBuilder<TSchemaReg, TEvents, TActions, TStateMap, TActor>;
|
|
61
65
|
};
|
|
62
66
|
};
|
|
63
67
|
/**
|
|
64
68
|
* Builds and returns the Slice data structure.
|
|
65
69
|
*/
|
|
66
|
-
build: () => Slice<
|
|
70
|
+
build: () => Slice<TSchemaReg, TEvents, TActions, TStateMap, TActor>;
|
|
67
71
|
/**
|
|
68
72
|
* The registered event schemas and their reaction maps.
|
|
69
73
|
*/
|
|
70
|
-
readonly events: EventRegister<
|
|
74
|
+
readonly events: EventRegister<TEvents>;
|
|
71
75
|
};
|
|
72
76
|
/**
|
|
73
77
|
* Creates a new slice builder for composing partial states with scoped reactions.
|
|
@@ -102,5 +106,5 @@ export type SliceBuilder<S extends SchemaRegister<A>, E extends Schemas, A exten
|
|
|
102
106
|
* @see {@link SliceBuilder} for builder methods
|
|
103
107
|
* @see {@link Slice} for the output type
|
|
104
108
|
*/
|
|
105
|
-
export declare function slice<
|
|
109
|
+
export declare function slice<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>>, actions?: Record<string, any>, events?: EventRegister<TEvents>, projections?: Projection<any>[]): SliceBuilder<TSchemaReg, TEvents, TActions, TStateMap, TActor>;
|
|
106
110
|
//# sourceMappingURL=slice-builder.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"slice-builder.d.ts","sourceRoot":"","sources":["../../src/slice-builder.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,KAAK,EACV,SAAS,EACT,UAAU,EACV,aAAa,EAGb,eAAe,EACf,gBAAgB,EAChB,MAAM,EACN,cAAc,EACd,OAAO,EACP,QAAQ,EACR,KAAK,EACN,MAAM,kBAAkB,CAAC;AAE1B
|
|
1
|
+
{"version":3,"file":"slice-builder.d.ts","sourceRoot":"","sources":["../../src/slice-builder.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,KAAK,EACV,KAAK,EACL,SAAS,EACT,UAAU,EACV,aAAa,EAGb,eAAe,EACf,gBAAgB,EAChB,MAAM,EACN,cAAc,EACd,OAAO,EACP,QAAQ,EACR,KAAK,EACN,MAAM,kBAAkB,CAAC;AAE1B;;;;;;;;;;GAUG;AACH,MAAM,MAAM,KAAK,CACf,UAAU,SAAS,cAAc,CAAC,QAAQ,CAAC,EAC3C,OAAO,SAAS,OAAO,EACvB,QAAQ,SAAS,OAAO,EAExB,SAAS,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,EAAE,EAC7C,MAAM,SAAS,KAAK,GAAG,KAAK,IAC1B;IACF,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;IACnD,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC,OAAO,CAAC,CAAC;IACxC,QAAQ,CAAC,WAAW,EAAE,aAAa,CAAC,UAA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GAAG,KAAK,EAE5B,MAAM,GAAE,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAa,EACrD,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAM,EACjC,MAAM,GAAE,aAAa,CAAC,OAAO,CAAgC,EAC7D,WAAW,GAAE,UAAU,CAAC,GAAG,CAAC,EAAO,GAClC,YAAY,CAAC,UAAU,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,CAAC,CA0FhE"}
|
|
@@ -12,12 +12,13 @@ import { ActionHandler, Invariant, PatchHandlers, Schema, Schemas, Snapshot, Sta
|
|
|
12
12
|
* Provides a fluent API to configure the initial state, event types,
|
|
13
13
|
* and event handlers (reducers) before moving to action configuration.
|
|
14
14
|
*
|
|
15
|
-
* @template
|
|
15
|
+
* @template TState - State schema type
|
|
16
|
+
* @template TName - State name literal type
|
|
16
17
|
*
|
|
17
18
|
* @see {@link state} for usage examples
|
|
18
19
|
* @see {@link ActionBuilder} for action configuration
|
|
19
20
|
*/
|
|
20
|
-
export type StateBuilder<
|
|
21
|
+
export type StateBuilder<TState extends Schema, TName extends string = string> = {
|
|
21
22
|
/**
|
|
22
23
|
* Defines the initial state for new state instances.
|
|
23
24
|
*
|
|
@@ -37,14 +38,14 @@ export type StateBuilder<S extends Schema, N extends string = string> = {
|
|
|
37
38
|
* .init((data) => ({ ...data, createdAt: new Date() }))
|
|
38
39
|
* ```
|
|
39
40
|
*/
|
|
40
|
-
init: (init: () => Readonly<
|
|
41
|
+
init: (init: () => Readonly<TState>) => {
|
|
41
42
|
/**
|
|
42
43
|
* Declares the event types that this state can emit.
|
|
43
44
|
*
|
|
44
45
|
* Events represent facts that have happened - they should be named in past tense.
|
|
45
46
|
* Each event is defined with a Zod schema for type safety and runtime validation.
|
|
46
47
|
*
|
|
47
|
-
* @template
|
|
48
|
+
* @template TEvents - Event schemas type
|
|
48
49
|
* @param events - Object mapping event names to Zod schemas
|
|
49
50
|
* @returns An ActionBuilder (with optional `.patch()` to override specific reducers)
|
|
50
51
|
*
|
|
@@ -57,7 +58,7 @@ export type StateBuilder<S extends Schema, N extends string = string> = {
|
|
|
57
58
|
* })
|
|
58
59
|
* ```
|
|
59
60
|
*/
|
|
60
|
-
emits: <
|
|
61
|
+
emits: <TEvents extends Schemas>(events: ZodTypes<TEvents>) => ActionBuilder<TState, TEvents, {}, TName> & {
|
|
61
62
|
/**
|
|
62
63
|
* Overrides specific event reducers. Events without a custom patch
|
|
63
64
|
* default to passthrough: `({ data }) => data` (event data merges
|
|
@@ -78,17 +79,17 @@ export type StateBuilder<S extends Schema, N extends string = string> = {
|
|
|
78
79
|
* // TicketClosed and TicketResolved use passthrough
|
|
79
80
|
* ```
|
|
80
81
|
*/
|
|
81
|
-
patch: (patch: Partial<PatchHandlers<
|
|
82
|
+
patch: (patch: Partial<PatchHandlers<TState, TEvents>>) => ActionBuilder<TState, TEvents, {}, TName>;
|
|
82
83
|
};
|
|
83
84
|
};
|
|
84
85
|
};
|
|
85
86
|
/** Helper: a single-key record mapping a state name to its Zod schema. */
|
|
86
|
-
type StateEntry<
|
|
87
|
-
[P in
|
|
87
|
+
type StateEntry<TKey extends string = string, TState extends Schema = Schema> = {
|
|
88
|
+
[P in TKey]: ZodType<TState>;
|
|
88
89
|
};
|
|
89
90
|
/** Helper: a single-key record mapping an action name to its Zod schema. */
|
|
90
|
-
type ActionEntry<
|
|
91
|
-
[P in
|
|
91
|
+
type ActionEntry<TKey extends string = string, TNewActions extends Schema = Schema> = {
|
|
92
|
+
[P in TKey]: ZodType<TNewActions>;
|
|
92
93
|
};
|
|
93
94
|
/**
|
|
94
95
|
* Builder interface for defining actions (commands) on a state.
|
|
@@ -96,13 +97,14 @@ type ActionEntry<K extends string = string, AX extends Schema = Schema> = {
|
|
|
96
97
|
* Actions represent user/system intents to modify state. Each action is validated
|
|
97
98
|
* against a schema, can have business rule invariants, and must emit one or more events.
|
|
98
99
|
*
|
|
99
|
-
* @template
|
|
100
|
-
* @template
|
|
101
|
-
* @template
|
|
100
|
+
* @template TState - State schema type
|
|
101
|
+
* @template TEvents - Event schemas type
|
|
102
|
+
* @template TActions - Action schemas type
|
|
103
|
+
* @template TName - State name literal type
|
|
102
104
|
*
|
|
103
105
|
* @see {@link state} for complete usage examples
|
|
104
106
|
*/
|
|
105
|
-
export type ActionBuilder<
|
|
107
|
+
export type ActionBuilder<TState extends Schema, TEvents extends Schemas, TActions extends Schemas, TName extends string = string> = {
|
|
106
108
|
/**
|
|
107
109
|
* Defines an action (command) that can be executed on this state.
|
|
108
110
|
*
|
|
@@ -114,8 +116,8 @@ export type ActionBuilder<S extends Schema, E extends Schemas, A extends Schemas
|
|
|
114
116
|
* when the variable name matches the action name. The key becomes the
|
|
115
117
|
* action name, the value the Zod schema.
|
|
116
118
|
*
|
|
117
|
-
* @template
|
|
118
|
-
* @template
|
|
119
|
+
* @template TKey - Action name (string literal type)
|
|
120
|
+
* @template TNewActions - Action payload schema type
|
|
119
121
|
* @param entry - Single-key record `{ ActionName: schema }`
|
|
120
122
|
* @returns An object with `.given()` and `.emit()` for further configuration
|
|
121
123
|
*
|
|
@@ -142,7 +144,7 @@ export type ActionBuilder<S extends Schema, E extends Schemas, A extends Schemas
|
|
|
142
144
|
* .emit((action) => ["TicketOpened", { title: action.title }])
|
|
143
145
|
* ```
|
|
144
146
|
*/
|
|
145
|
-
on: <
|
|
147
|
+
on: <TKey extends string, TNewActions extends Schema>(entry: ActionEntry<TKey, TNewActions>) => {
|
|
146
148
|
/**
|
|
147
149
|
* Adds business rule invariants that must hold before the action can execute.
|
|
148
150
|
*
|
|
@@ -161,7 +163,7 @@ export type ActionBuilder<S extends Schema, E extends Schemas, A extends Schemas
|
|
|
161
163
|
* ])
|
|
162
164
|
* ```
|
|
163
165
|
*/
|
|
164
|
-
given: (rules: Invariant<
|
|
166
|
+
given: (rules: Invariant<TState>[]) => {
|
|
165
167
|
/**
|
|
166
168
|
* Defines the action handler that emits events.
|
|
167
169
|
*
|
|
@@ -188,11 +190,11 @@ export type ActionBuilder<S extends Schema, E extends Schemas, A extends Schemas
|
|
|
188
190
|
* .emit("TicketAssigned")
|
|
189
191
|
* ```
|
|
190
192
|
*/
|
|
191
|
-
emit: (handler: ActionHandler<
|
|
192
|
-
[P in
|
|
193
|
-
},
|
|
194
|
-
[P in
|
|
195
|
-
},
|
|
193
|
+
emit: (handler: ActionHandler<TState, TEvents, {
|
|
194
|
+
[P in TKey]: TNewActions;
|
|
195
|
+
}, TKey> | (keyof TEvents & string)) => ActionBuilder<TState, TEvents, TActions & {
|
|
196
|
+
[P in TKey]: TNewActions;
|
|
197
|
+
}, TName>;
|
|
196
198
|
};
|
|
197
199
|
/**
|
|
198
200
|
* Defines the action handler that emits events.
|
|
@@ -225,11 +227,11 @@ export type ActionBuilder<S extends Schema, E extends Schemas, A extends Schemas
|
|
|
225
227
|
* ])
|
|
226
228
|
* ```
|
|
227
229
|
*/
|
|
228
|
-
emit: (handler: ActionHandler<
|
|
229
|
-
[P in
|
|
230
|
-
},
|
|
231
|
-
[P in
|
|
232
|
-
},
|
|
230
|
+
emit: (handler: ActionHandler<TState, TEvents, {
|
|
231
|
+
[P in TKey]: TNewActions;
|
|
232
|
+
}, TKey> | (keyof TEvents & string)) => ActionBuilder<TState, TEvents, TActions & {
|
|
233
|
+
[P in TKey]: TNewActions;
|
|
234
|
+
}, TName>;
|
|
233
235
|
};
|
|
234
236
|
/**
|
|
235
237
|
* Defines a snapshotting strategy to optimize state reconstruction.
|
|
@@ -262,7 +264,7 @@ export type ActionBuilder<S extends Schema, E extends Schemas, A extends Schemas
|
|
|
262
264
|
* })
|
|
263
265
|
* ```
|
|
264
266
|
*/
|
|
265
|
-
snap: (snap: (snapshot: Snapshot<
|
|
267
|
+
snap: (snap: (snapshot: Snapshot<TState, TEvents>) => boolean) => ActionBuilder<TState, TEvents, TActions, TName>;
|
|
266
268
|
/**
|
|
267
269
|
* Finalizes and builds the state definition.
|
|
268
270
|
*
|
|
@@ -279,10 +281,10 @@ export type ActionBuilder<S extends Schema, E extends Schemas, A extends Schemas
|
|
|
279
281
|
* .patch({ Incremented: ({ data }, state) => ({ count: state.count + data.amount }) })
|
|
280
282
|
* .on({ increment: z.object({ by: z.number() }) })
|
|
281
283
|
* .emit((action) => ["Incremented", { amount: action.by }])
|
|
282
|
-
* .build(); // Returns State<
|
|
284
|
+
* .build(); // Returns State<TState, TEvents, TActions, TName>
|
|
283
285
|
* ```
|
|
284
286
|
*/
|
|
285
|
-
build: () => State<
|
|
287
|
+
build: () => State<TState, TEvents, TActions, TName>;
|
|
286
288
|
};
|
|
287
289
|
/**
|
|
288
290
|
* Creates a new state definition with event sourcing capabilities.
|
|
@@ -300,7 +302,7 @@ export type ActionBuilder<S extends Schema, E extends Schemas, A extends Schemas
|
|
|
300
302
|
* 5. Business rules (invariants) via `.given()`
|
|
301
303
|
* 6. Snapshotting strategy via `.snap()`
|
|
302
304
|
*
|
|
303
|
-
* @template
|
|
305
|
+
* @template TState - Zod schema type defining the shape of the state
|
|
304
306
|
* @param entry - Single-key record mapping state name to Zod schema (e.g., `{ Counter: z.object({ count: z.number() }) }`)
|
|
305
307
|
* @returns A StateBuilder instance for fluent API configuration
|
|
306
308
|
*
|
|
@@ -401,6 +403,6 @@ export type ActionBuilder<S extends Schema, E extends Schemas, A extends Schemas
|
|
|
401
403
|
* @see {@link https://rotorsoft.github.io/act-root/docs/intro | Getting Started Guide}
|
|
402
404
|
* @see {@link https://rotorsoft.github.io/act-root/docs/examples/calculator | Calculator Example}
|
|
403
405
|
*/
|
|
404
|
-
export declare function state<
|
|
406
|
+
export declare function state<TName extends string, TState extends Schema>(entry: StateEntry<TName, TState>): StateBuilder<TState, TName>;
|
|
405
407
|
export {};
|
|
406
408
|
//# sourceMappingURL=state-builder.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"state-builder.d.ts","sourceRoot":"","sources":["../../src/state-builder.ts"],"names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C,MAAM,OAAO,GAAG,MAAM,CAAC,KACzB,aAAa,CAChB,MAAM,EACN,OAAO,EACP,QAAQ,GAAG;aAAG,CAAC,IAAI,IAAI,GAAG,WAAW;SAAE,EACvC,KAAK,CACN,CAAC;KACH,CAAC;IACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA8BG;IACH,IAAI,EAAE,CACJ,IAAI,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,OAAO,KACnD,aAAa,CAAC,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC;IACrD;;;;;;;;;;;;;;;;;;OAkBG;IACH,KAAK,EAAE,MAAM,KAAK,CAAC,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC;CACtD,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoHG;AACH,wBAAgB,KAAK,CAAC,KAAK,SAAS,MAAM,EAAE,MAAM,SAAS,MAAM,EAC/D,KAAK,EAAE,UAAU,CAAC,KAAK,EAAE,MAAM,CAAC,GAC/B,YAAY,CAAC,MAAM,EAAE,KAAK,CAAC,CA8C7B"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z, ZodType } from "zod";
|
|
2
|
-
import { ActorSchema, CausationEventSchema, CommittedMetaSchema, EventMetaSchema, QuerySchema
|
|
2
|
+
import { ActorSchema, CausationEventSchema, CommittedMetaSchema, EventMetaSchema, QuerySchema } from "./schemas.js";
|
|
3
3
|
/**
|
|
4
4
|
* @packageDocumentation
|
|
5
5
|
* @module act/types
|
|
@@ -36,6 +36,8 @@ export type Actor = z.infer<typeof ActorSchema>;
|
|
|
36
36
|
* and who is performing it. The target combines the stream identifier
|
|
37
37
|
* with actor context for complete audit trail.
|
|
38
38
|
*
|
|
39
|
+
* @template TActor - Actor type extending base Actor (default: Actor)
|
|
40
|
+
*
|
|
39
41
|
* @example Basic target
|
|
40
42
|
* ```typescript
|
|
41
43
|
* const target: Target = {
|
|
@@ -55,7 +57,11 @@ export type Actor = z.infer<typeof ActorSchema>;
|
|
|
55
57
|
* }, userData);
|
|
56
58
|
* ```
|
|
57
59
|
*/
|
|
58
|
-
export type Target =
|
|
60
|
+
export type Target<TActor extends Actor = Actor> = {
|
|
61
|
+
readonly stream: string;
|
|
62
|
+
readonly actor: TActor;
|
|
63
|
+
readonly expectedVersion?: number;
|
|
64
|
+
};
|
|
59
65
|
/**
|
|
60
66
|
* Metadata describing the causation of an event.
|
|
61
67
|
*/
|
|
@@ -115,8 +121,8 @@ export type ZodTypes<T extends Schemas> = {
|
|
|
115
121
|
* Messages are the basic building blocks of the event log. Each message
|
|
116
122
|
* has a name (event type) and data (event payload).
|
|
117
123
|
*
|
|
118
|
-
* @template
|
|
119
|
-
* @template
|
|
124
|
+
* @template TEvents - Schemas map
|
|
125
|
+
* @template TKey - Event/action name
|
|
120
126
|
*
|
|
121
127
|
* @example
|
|
122
128
|
* ```typescript
|
|
@@ -126,11 +132,11 @@ export type ZodTypes<T extends Schemas> = {
|
|
|
126
132
|
* };
|
|
127
133
|
* ```
|
|
128
134
|
*/
|
|
129
|
-
export type Message<
|
|
135
|
+
export type Message<TEvents extends Schemas, TKey extends keyof TEvents> = {
|
|
130
136
|
/** The event or action name */
|
|
131
|
-
readonly name:
|
|
137
|
+
readonly name: TKey;
|
|
132
138
|
/** The event or action payload */
|
|
133
|
-
readonly data: Readonly<
|
|
139
|
+
readonly data: Readonly<TEvents[TKey]>;
|
|
134
140
|
};
|
|
135
141
|
/**
|
|
136
142
|
* A committed event with complete metadata.
|
|
@@ -139,8 +145,8 @@ export type Message<E extends Schemas, K extends keyof E> = {
|
|
|
139
145
|
* the event was created, including correlation and causation information for
|
|
140
146
|
* tracing event-driven workflows.
|
|
141
147
|
*
|
|
142
|
-
* @template
|
|
143
|
-
* @template
|
|
148
|
+
* @template TEvents - Schemas map
|
|
149
|
+
* @template TKey - Event name
|
|
144
150
|
*
|
|
145
151
|
* @example
|
|
146
152
|
* ```typescript
|
|
@@ -164,7 +170,7 @@ export type Message<E extends Schemas, K extends keyof E> = {
|
|
|
164
170
|
*
|
|
165
171
|
* @see {@link CommittedMeta} for metadata structure
|
|
166
172
|
*/
|
|
167
|
-
export type Committed<
|
|
173
|
+
export type Committed<TEvents extends Schemas, TKey extends keyof TEvents> = Message<TEvents, TKey> & CommittedMeta;
|
|
168
174
|
/**
|
|
169
175
|
* Snapshot of state at a specific point in time.
|
|
170
176
|
*
|
|
@@ -172,8 +178,8 @@ export type Committed<E extends Schemas, K extends keyof E> = Message<E, K> & Co
|
|
|
172
178
|
* metadata about how many events have been applied (patches) and how many
|
|
173
179
|
* snapshots have been taken for optimization.
|
|
174
180
|
*
|
|
175
|
-
* @template
|
|
176
|
-
* @template
|
|
181
|
+
* @template TState - State schema
|
|
182
|
+
* @template TEvents - Event schemas
|
|
177
183
|
*
|
|
178
184
|
* @example
|
|
179
185
|
* ```typescript
|
|
@@ -195,11 +201,11 @@ export type Committed<E extends Schemas, K extends keyof E> = Message<E, K> & Co
|
|
|
195
201
|
* })
|
|
196
202
|
* ```
|
|
197
203
|
*/
|
|
198
|
-
export type Snapshot<
|
|
204
|
+
export type Snapshot<TState extends Schema, TEvents extends Schemas> = {
|
|
199
205
|
/** Current state data */
|
|
200
|
-
readonly state:
|
|
206
|
+
readonly state: TState;
|
|
201
207
|
/** Event that created this snapshot (undefined for initial state) */
|
|
202
|
-
readonly event?: Committed<
|
|
208
|
+
readonly event?: Committed<TEvents, keyof TEvents>;
|
|
203
209
|
/** Number of patches applied since last snapshot */
|
|
204
210
|
readonly patches: number;
|
|
205
211
|
/** Number of snapshots taken for this stream */
|
|
@@ -207,91 +213,93 @@ export type Snapshot<S extends Schema, E extends Schemas> = {
|
|
|
207
213
|
};
|
|
208
214
|
/**
|
|
209
215
|
* An invariant is a condition that must always hold true for a state.
|
|
210
|
-
* @template
|
|
216
|
+
* @template TState - State schema.
|
|
217
|
+
* @template TActor - Actor type extending base Actor.
|
|
211
218
|
*/
|
|
212
|
-
export type Invariant<
|
|
219
|
+
export type Invariant<TState extends Schema, TActor extends Actor = Actor> = {
|
|
213
220
|
description: string;
|
|
214
|
-
valid: (state: Readonly<
|
|
221
|
+
valid: (state: Readonly<TState>, actor?: TActor) => boolean;
|
|
215
222
|
};
|
|
216
223
|
/**
|
|
217
224
|
* Represents an emitted event tuple from an action handler.
|
|
218
|
-
* @template
|
|
225
|
+
* @template TEvents - Event schemas.
|
|
219
226
|
*/
|
|
220
|
-
export type Emitted<
|
|
221
|
-
[
|
|
222
|
-
}[keyof
|
|
227
|
+
export type Emitted<TEvents extends Schemas> = {
|
|
228
|
+
[TKey in keyof TEvents]: readonly [TKey, Readonly<TEvents[TKey]>];
|
|
229
|
+
}[keyof TEvents];
|
|
223
230
|
/**
|
|
224
231
|
* Bundles the Zod types for state, events, and actions.
|
|
225
|
-
* @template
|
|
226
|
-
* @template
|
|
227
|
-
* @template
|
|
232
|
+
* @template TState - State schema.
|
|
233
|
+
* @template TEvents - Event schemas.
|
|
234
|
+
* @template TActions - Action schemas.
|
|
228
235
|
*/
|
|
229
|
-
export type StateSchemas<
|
|
230
|
-
readonly events: ZodTypes<
|
|
231
|
-
readonly actions: ZodTypes<
|
|
232
|
-
readonly state: ZodType<
|
|
236
|
+
export type StateSchemas<TState extends Schema, TEvents extends Schemas, TActions extends Schemas> = {
|
|
237
|
+
readonly events: ZodTypes<TEvents>;
|
|
238
|
+
readonly actions: ZodTypes<TActions>;
|
|
239
|
+
readonly state: ZodType<TState>;
|
|
233
240
|
};
|
|
234
241
|
/**
|
|
235
242
|
* Handles patching state in response to a committed event.
|
|
236
|
-
* @template
|
|
237
|
-
* @template
|
|
238
|
-
* @template
|
|
243
|
+
* @template TState - State schema.
|
|
244
|
+
* @template TEvents - Event schemas.
|
|
245
|
+
* @template TKey - Event name.
|
|
239
246
|
*/
|
|
240
|
-
export type PatchHandler<
|
|
247
|
+
export type PatchHandler<TState extends Schema, TEvents extends Schemas, TKey extends keyof TEvents> = (event: Committed<TEvents, TKey>, state: Readonly<TState>) => Readonly<Patch<TState>>;
|
|
241
248
|
/**
|
|
242
249
|
* Maps event names to their patch handlers.
|
|
243
|
-
* @template
|
|
244
|
-
* @template
|
|
250
|
+
* @template TState - State schema.
|
|
251
|
+
* @template TEvents - Event schemas.
|
|
245
252
|
*/
|
|
246
|
-
export type PatchHandlers<
|
|
247
|
-
[
|
|
253
|
+
export type PatchHandlers<TState extends Schema, TEvents extends Schemas> = {
|
|
254
|
+
[TKey in keyof TEvents]: PatchHandler<TState, TEvents, TKey>;
|
|
248
255
|
};
|
|
249
256
|
/**
|
|
250
257
|
* Handles an action, producing one or more emitted events.
|
|
251
|
-
* @template
|
|
252
|
-
* @template
|
|
253
|
-
* @template
|
|
254
|
-
* @template
|
|
258
|
+
* @template TState - State schema.
|
|
259
|
+
* @template TEvents - Event schemas.
|
|
260
|
+
* @template TActions - Action schemas.
|
|
261
|
+
* @template TKey - Action name.
|
|
255
262
|
*/
|
|
256
|
-
export type ActionHandler<
|
|
263
|
+
export type ActionHandler<TState extends Schema, TEvents extends Schemas, TActions extends Schemas, TKey extends keyof TActions> = (action: Readonly<TActions[TKey]>, snapshot: Readonly<Snapshot<TState, TEvents>>, target: Target) => Emitted<TEvents> | Emitted<TEvents>[] | undefined;
|
|
257
264
|
/**
|
|
258
265
|
* Maps action names to their handlers.
|
|
259
|
-
* @template
|
|
260
|
-
* @template
|
|
261
|
-
* @template
|
|
266
|
+
* @template TState - State schema.
|
|
267
|
+
* @template TEvents - Event schemas.
|
|
268
|
+
* @template TActions - Action schemas.
|
|
262
269
|
*/
|
|
263
|
-
export type ActionHandlers<
|
|
264
|
-
[
|
|
270
|
+
export type ActionHandlers<TState extends Schema, TEvents extends Schemas, TActions extends Schemas> = {
|
|
271
|
+
[TKey in keyof TActions]: ActionHandler<TState, TEvents, TActions, TKey>;
|
|
265
272
|
};
|
|
266
273
|
/**
|
|
267
274
|
* Maps action names to invariants that must hold after the action.
|
|
268
|
-
* @template
|
|
269
|
-
* @template
|
|
275
|
+
* @template TState - State schema.
|
|
276
|
+
* @template TActions - Action schemas.
|
|
270
277
|
*/
|
|
271
|
-
export type GivenHandlers<
|
|
272
|
-
[
|
|
278
|
+
export type GivenHandlers<TState extends Schema, TActions extends Schemas> = {
|
|
279
|
+
[TKey in keyof TActions]?: Invariant<TState>[];
|
|
273
280
|
};
|
|
274
281
|
/**
|
|
275
282
|
* The full state definition, including schemas, handlers, and optional invariants and snapshot logic.
|
|
276
|
-
* @template
|
|
277
|
-
* @template
|
|
278
|
-
* @template
|
|
283
|
+
* @template TState - State schema.
|
|
284
|
+
* @template TEvents - Event schemas.
|
|
285
|
+
* @template TActions - Action schemas.
|
|
286
|
+
* @template TName - State name literal.
|
|
279
287
|
*/
|
|
280
|
-
export type State<
|
|
281
|
-
name:
|
|
282
|
-
init: () => Readonly<
|
|
283
|
-
patch: PatchHandlers<
|
|
284
|
-
on: ActionHandlers<
|
|
285
|
-
given?: GivenHandlers<
|
|
286
|
-
snap?: (snapshot: Snapshot<
|
|
288
|
+
export type State<TState extends Schema, TEvents extends Schemas, TActions extends Schemas, TName extends string = string> = StateSchemas<TState, TEvents, TActions> & {
|
|
289
|
+
name: TName;
|
|
290
|
+
init: () => Readonly<TState>;
|
|
291
|
+
patch: PatchHandlers<TState, TEvents>;
|
|
292
|
+
on: ActionHandlers<TState, TEvents, TActions>;
|
|
293
|
+
given?: GivenHandlers<TState, TActions>;
|
|
294
|
+
snap?: (snapshot: Snapshot<TState, TEvents>) => boolean;
|
|
287
295
|
};
|
|
288
296
|
/**
|
|
289
297
|
* Extracts the raw action schemas from a State definition.
|
|
290
298
|
*
|
|
291
|
-
* Use this to recover the `
|
|
299
|
+
* Use this to recover the `TActions` type parameter from a built State object,
|
|
292
300
|
* enabling construction of typed dispatchers without circular imports.
|
|
293
301
|
*
|
|
294
|
-
* @template T - A State object (or any object with `readonly actions: ZodTypes<
|
|
302
|
+
* @template T - A State object (or any object with `readonly actions: ZodTypes<TActions>`)
|
|
295
303
|
*
|
|
296
304
|
* @example
|
|
297
305
|
* ```typescript
|
|
@@ -311,7 +319,8 @@ export type InferActions<T extends {
|
|
|
311
319
|
* Construct with {@link InferActions} to avoid circular imports between
|
|
312
320
|
* slice files and the bootstrap module.
|
|
313
321
|
*
|
|
314
|
-
* @template
|
|
322
|
+
* @template TActions - Action schemas (maps action names to payload types)
|
|
323
|
+
* @template TActor - Actor type extending base Actor
|
|
315
324
|
*
|
|
316
325
|
* @example
|
|
317
326
|
* ```typescript
|
|
@@ -327,7 +336,7 @@ export type InferActions<T extends {
|
|
|
327
336
|
* }
|
|
328
337
|
* ```
|
|
329
338
|
*/
|
|
330
|
-
export interface Dispatcher<
|
|
331
|
-
do<
|
|
339
|
+
export interface Dispatcher<TActions extends Schemas, TActor extends Actor = Actor> {
|
|
340
|
+
do<TKey extends keyof TActions & string>(action: TKey, target: Target<TActor>, payload: Readonly<TActions[TKey]>, reactingTo?: Committed<Schemas, string>, skipValidation?: boolean): Promise<Snapshot<any, any>[]>;
|
|
332
341
|
}
|
|
333
342
|
//# sourceMappingURL=action.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"action.d.ts","sourceRoot":"","sources":["../../../src/types/action.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AACjC,OAAO,EACL,WAAW,EACX,oBAAoB,EACpB,mBAAmB,EACnB,eAAe,EACf,WAAW,
|
|
1
|
+
{"version":3,"file":"action.d.ts","sourceRoot":"","sources":["../../../src/types/action.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AACjC,OAAO,EACL,WAAW,EACX,oBAA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