@rotorsoft/act 0.12.1 → 0.13.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 +7 -7
- package/dist/.tsbuildinfo +1 -1
- package/dist/@types/act-builder.d.ts +30 -88
- package/dist/@types/act-builder.d.ts.map +1 -1
- package/dist/@types/act.d.ts +5 -5
- package/dist/@types/ports.d.ts +1 -1
- package/dist/@types/projection-builder.d.ts +2 -6
- package/dist/@types/projection-builder.d.ts.map +1 -1
- package/dist/@types/slice-builder.d.ts +13 -24
- package/dist/@types/slice-builder.d.ts.map +1 -1
- package/dist/@types/types/ports.d.ts +1 -1
- package/dist/@types/types/reaction.d.ts +2 -2
- package/dist/@types/types/reaction.d.ts.map +1 -1
- package/dist/index.cjs +83 -104
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +83 -102
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -5,14 +5,16 @@
|
|
|
5
5
|
* Fluent builder for composing event-sourced applications.
|
|
6
6
|
*/
|
|
7
7
|
import { Act } from "./act.js";
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
8
|
+
import type { Projection } from "./projection-builder.js";
|
|
9
|
+
import type { Slice } from "./slice-builder.js";
|
|
10
10
|
import type { 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
|
*
|
|
14
14
|
* Provides a chainable API for:
|
|
15
|
-
* - Registering states
|
|
15
|
+
* - Registering states via `.withState()`
|
|
16
|
+
* - Registering slices via `.withSlice()`
|
|
17
|
+
* - Registering projections via `.withProjection()`
|
|
16
18
|
* - Defining event reactions via `.on()` → `.do()` → `.to()` or `.void()`
|
|
17
19
|
* - Building the orchestrator via `.build()`
|
|
18
20
|
*
|
|
@@ -25,31 +27,35 @@ import type { Committed, Dispatcher, EventRegister, ReactionOptions, ReactionRes
|
|
|
25
27
|
*/
|
|
26
28
|
export type ActBuilder<S extends SchemaRegister<A>, E extends Schemas, A extends Schemas, M extends Record<string, Schema> = {}> = {
|
|
27
29
|
/**
|
|
28
|
-
* Registers a state definition
|
|
30
|
+
* Registers a state definition with the builder.
|
|
29
31
|
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
* State names, action names, and event names must be unique across the application
|
|
33
|
-
* (partial states with the same name are merged automatically).
|
|
32
|
+
* State names, action names, and event names must be unique across the
|
|
33
|
+
* application (partial states with the same name are merged automatically).
|
|
34
34
|
*
|
|
35
35
|
* @throws {Error} If duplicate action or event names are detected
|
|
36
|
-
*
|
|
37
|
-
* @example Register a state
|
|
38
|
-
* ```typescript
|
|
39
|
-
* const app = act().with(Counter).build();
|
|
40
|
-
* ```
|
|
41
|
-
*
|
|
42
|
-
* @example Register a slice
|
|
43
|
-
* ```typescript
|
|
44
|
-
* const CounterSlice = slice().with(Counter).on("Incremented").do(log).void().build();
|
|
45
|
-
* const app = act().with(CounterSlice).build();
|
|
46
|
-
* ```
|
|
47
36
|
*/
|
|
48
|
-
|
|
37
|
+
withState: <SX extends Schema, EX extends Schemas, AX extends Schemas, NX extends string = string>(state: State<SX, EX, AX, NX>) => ActBuilder<S & {
|
|
49
38
|
[K in keyof AX]: SX;
|
|
50
39
|
}, E & EX, A & AX, M & {
|
|
51
40
|
[K in NX]: SX;
|
|
52
|
-
}
|
|
41
|
+
}>;
|
|
42
|
+
/**
|
|
43
|
+
* Registers a slice with the builder.
|
|
44
|
+
*
|
|
45
|
+
* Merges all the slice's states and reactions into the application.
|
|
46
|
+
* State names, action names, and event names must be unique across the
|
|
47
|
+
* application (partial states with the same name are merged automatically).
|
|
48
|
+
*
|
|
49
|
+
* @throws {Error} If duplicate action or event names are detected
|
|
50
|
+
*/
|
|
51
|
+
withSlice: <SX extends SchemaRegister<AX>, EX extends Schemas, AX extends Schemas, MX extends Record<string, Schema>>(slice: Slice<SX, EX, AX, MX>) => ActBuilder<S & SX, E & EX, A & AX, M & MX>;
|
|
52
|
+
/**
|
|
53
|
+
* Registers a standalone projection with the builder.
|
|
54
|
+
*
|
|
55
|
+
* The projection's events must be a subset of events already registered
|
|
56
|
+
* via `.withState()` or `.withSlice()`.
|
|
57
|
+
*/
|
|
58
|
+
withProjection: <EX extends Schemas>(projection: [Exclude<keyof EX, keyof E>] extends [never] ? Projection<EX> : never) => ActBuilder<S, E, A, M>;
|
|
53
59
|
/**
|
|
54
60
|
* Begins defining a reaction to a specific event.
|
|
55
61
|
*
|
|
@@ -60,47 +66,10 @@ export type ActBuilder<S extends SchemaRegister<A>, E extends Schemas, A extends
|
|
|
60
66
|
* @template K - Event name (must be a registered event)
|
|
61
67
|
* @param event - The event name to react to
|
|
62
68
|
* @returns An object with `.do()` method to define the reaction handler
|
|
63
|
-
*
|
|
64
|
-
* @example
|
|
65
|
-
* ```typescript
|
|
66
|
-
* const app = act()
|
|
67
|
-
* .with(User)
|
|
68
|
-
* .on("UserCreated") // React to UserCreated events
|
|
69
|
-
* .do(async (event) => {
|
|
70
|
-
* await sendWelcomeEmail(event.data.email);
|
|
71
|
-
* })
|
|
72
|
-
* .void()
|
|
73
|
-
* .build();
|
|
74
|
-
* ```
|
|
75
69
|
*/
|
|
76
70
|
on: <K extends keyof E>(event: K) => {
|
|
77
|
-
/**
|
|
78
|
-
* Defines the reaction handler function for the event.
|
|
79
|
-
*
|
|
80
|
-
* The handler receives the committed event and can:
|
|
81
|
-
* - Perform side effects (send emails, call APIs, etc.)
|
|
82
|
-
* - Return an action tuple `[actionName, payload]` to trigger another action
|
|
83
|
-
* - Return `void` or `undefined` for side-effect-only reactions
|
|
84
|
-
*
|
|
85
|
-
* @param handler - The reaction handler function
|
|
86
|
-
* @param options - Optional reaction configuration
|
|
87
|
-
* @param options.blockOnError - Block this stream if handler fails (default: true)
|
|
88
|
-
* @param options.maxRetries - Maximum retry attempts on failure (default: 3)
|
|
89
|
-
* @returns The builder with `.to()` and `.void()` methods for routing configuration
|
|
90
|
-
*/
|
|
91
71
|
do: (handler: (event: Committed<E, K>, stream: string, app: Dispatcher<A>) => Promise<Snapshot<Schema, E> | void>, options?: Partial<ReactionOptions>) => ActBuilder<S, E, A, M> & {
|
|
92
|
-
/**
|
|
93
|
-
* Routes the reaction to a specific target stream.
|
|
94
|
-
*
|
|
95
|
-
* @param resolver - Target stream name (string) or resolver function
|
|
96
|
-
* @returns The builder for chaining
|
|
97
|
-
*/
|
|
98
72
|
to: (resolver: ReactionResolver<E, K> | string) => ActBuilder<S, E, A, M>;
|
|
99
|
-
/**
|
|
100
|
-
* Marks the reaction as void (side-effect only, no target stream).
|
|
101
|
-
*
|
|
102
|
-
* @returns The builder for chaining
|
|
103
|
-
*/
|
|
104
73
|
void: () => ActBuilder<S, E, A, M>;
|
|
105
74
|
};
|
|
106
75
|
};
|
|
@@ -121,51 +90,24 @@ export type ActBuilder<S extends SchemaRegister<A>, E extends Schemas, A extends
|
|
|
121
90
|
/**
|
|
122
91
|
* Creates a new Act orchestrator builder for composing event-sourced applications.
|
|
123
92
|
*
|
|
124
|
-
* The Act orchestrator is responsible for:
|
|
125
|
-
* - Managing state instances (aggregates)
|
|
126
|
-
* - Executing actions and committing events
|
|
127
|
-
* - Processing reactions (event handlers)
|
|
128
|
-
* - Coordinating event-driven workflows
|
|
129
|
-
*
|
|
130
|
-
* Use the fluent API to register states or slices with `.with()`, define event
|
|
131
|
-
* reactions with `.on()`, and build the orchestrator with `.build()`.
|
|
132
|
-
*
|
|
133
|
-
* @template S - State schema register type
|
|
134
|
-
* @template E - Event schemas type
|
|
135
|
-
* @template A - Action schemas type
|
|
136
|
-
* @returns An ActBuilder instance for fluent API configuration
|
|
137
|
-
*
|
|
138
93
|
* @example Basic application with single state
|
|
139
94
|
* ```typescript
|
|
140
|
-
* import { act, state } from "@rotorsoft/act";
|
|
141
|
-
* import { z } from "zod";
|
|
142
|
-
*
|
|
143
|
-
* const Counter = state({ Counter: z.object({ count: z.number() }) })
|
|
144
|
-
* .init(() => ({ count: 0 }))
|
|
145
|
-
* .emits({ Incremented: z.object({ amount: z.number() }) })
|
|
146
|
-
* .patch({ Incremented: (event, state) => ({ count: state.count + event.data.amount }) })
|
|
147
|
-
* .on({ increment: z.object({ by: z.number() }) })
|
|
148
|
-
* .emit((action) => ["Incremented", { amount: action.by }])
|
|
149
|
-
* .build();
|
|
150
|
-
*
|
|
151
95
|
* const app = act()
|
|
152
|
-
* .
|
|
96
|
+
* .withState(Counter)
|
|
153
97
|
* .build();
|
|
154
98
|
* ```
|
|
155
99
|
*
|
|
156
100
|
* @example Application with slices (vertical slice architecture)
|
|
157
101
|
* ```typescript
|
|
158
|
-
* import { act, slice, state } from "@rotorsoft/act";
|
|
159
|
-
*
|
|
160
102
|
* const CounterSlice = slice()
|
|
161
|
-
* .
|
|
103
|
+
* .withState(Counter)
|
|
162
104
|
* .on("Incremented")
|
|
163
105
|
* .do(async (event) => { console.log("incremented!"); })
|
|
164
106
|
* .void()
|
|
165
107
|
* .build();
|
|
166
108
|
*
|
|
167
109
|
* const app = act()
|
|
168
|
-
* .
|
|
110
|
+
* .withSlice(CounterSlice)
|
|
169
111
|
* .build();
|
|
170
112
|
* ```
|
|
171
113
|
*
|
|
@@ -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,
|
|
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,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AAC,SAAS,cAAc,CAAC,CAAC,CAAC,GAAG,EAAE,EAChC,CAAC,SAAS,OAAO,GAAG,EAAE,EACtB,CAAC,SAAS,OAAO,GAAG,EAAE,EACtB,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,EAAE,EAErC,MAAM,GAAE,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAa,EACrD,QAAQ,GAAE,QAAQ,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAGzB,EACD,kBAAkB,GAAE,UAAU,CAAC,GAAG,CAAC,EAAO,GACzC,UAAU,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CA6GxB"}
|
package/dist/@types/act.d.ts
CHANGED
|
@@ -132,8 +132,8 @@ export declare class Act<S extends SchemaRegister<A>, E extends Schemas, A exten
|
|
|
132
132
|
* @example Reaction triggering another action
|
|
133
133
|
* ```typescript
|
|
134
134
|
* const app = act()
|
|
135
|
-
* .
|
|
136
|
-
* .
|
|
135
|
+
* .withState(Order)
|
|
136
|
+
* .withState(Inventory)
|
|
137
137
|
* .on("OrderPlaced")
|
|
138
138
|
* .do(async (event, context) => {
|
|
139
139
|
* // This action is triggered by an event
|
|
@@ -165,7 +165,7 @@ export declare class Act<S extends SchemaRegister<A>, E extends Schemas, A exten
|
|
|
165
165
|
*
|
|
166
166
|
* Accepts either a State definition object or a state name string. When
|
|
167
167
|
* using a string, the merged state (from partial states registered via
|
|
168
|
-
* `.
|
|
168
|
+
* `.withState()`) is resolved by name.
|
|
169
169
|
*
|
|
170
170
|
* @template SX - State schema type
|
|
171
171
|
* @template EX - Event schemas type
|
|
@@ -389,8 +389,8 @@ export declare class Act<S extends SchemaRegister<A>, E extends Schemas, A exten
|
|
|
389
389
|
* @example Dynamic stream creation
|
|
390
390
|
* ```typescript
|
|
391
391
|
* const app = act()
|
|
392
|
-
* .
|
|
393
|
-
* .
|
|
392
|
+
* .withState(User)
|
|
393
|
+
* .withState(UserStats)
|
|
394
394
|
* .on("UserLoggedIn")
|
|
395
395
|
* .do(async (event) => ["incrementLoginCount", {}])
|
|
396
396
|
* .to((event) => ({
|
package/dist/@types/ports.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ import type { ZodType } from "zod";
|
|
|
12
12
|
import type { Committed, EventRegister, ReactionResolver, Schema, Schemas } from "./types/index.js";
|
|
13
13
|
/**
|
|
14
14
|
* A self-contained projection grouping read-model update handlers.
|
|
15
|
-
* Projections are composed into an Act orchestrator via `act().
|
|
15
|
+
* Projections are composed into an Act orchestrator via `act().withProjection(projection)`.
|
|
16
16
|
*
|
|
17
17
|
* @template E - Event schemas handled by this projection
|
|
18
18
|
*/
|
|
@@ -20,10 +20,6 @@ export type Projection<E extends Schemas> = {
|
|
|
20
20
|
readonly _tag: "Projection";
|
|
21
21
|
readonly events: EventRegister<E>;
|
|
22
22
|
};
|
|
23
|
-
/**
|
|
24
|
-
* Type guard for distinguishing Projection from State and Slice objects.
|
|
25
|
-
*/
|
|
26
|
-
export declare function isProjection(x: any): x is Projection<any>;
|
|
27
23
|
/** Helper: a single-key record mapping an event name to its Zod schema. */
|
|
28
24
|
type EventEntry<K extends string = string, D extends Schema = Schema> = {
|
|
29
25
|
[P in K]: ZodType<D>;
|
|
@@ -45,7 +41,7 @@ type DoResult<E extends Schemas, K extends string, D extends Schema> = Projectio
|
|
|
45
41
|
* Fluent builder interface for composing projections.
|
|
46
42
|
*
|
|
47
43
|
* Provides a chainable API for registering event handlers that update
|
|
48
|
-
* read models. Unlike slices, projections have no `.
|
|
44
|
+
* read models. Unlike slices, projections have no `.withState()` for states
|
|
49
45
|
* and handlers do not receive a `Dispatcher`.
|
|
50
46
|
*
|
|
51
47
|
* When a default target is provided via `projection("target")`, all
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"projection-builder.d.ts","sourceRoot":"","sources":["../../src/projection-builder.ts"],"names":[],"mappings":"A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
|
|
|
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
|
-
* `act().
|
|
6
|
+
* `act().withSlice(slice)`.
|
|
7
7
|
*
|
|
8
8
|
* @template S - Schema register for states
|
|
9
9
|
* @template E - Event schemas from this slice's states
|
|
@@ -20,17 +20,11 @@ export type Slice<S extends SchemaRegister<A>, E extends Schemas, A extends Sche
|
|
|
20
20
|
/** @internal phantom field for type-level state name tracking */
|
|
21
21
|
readonly _M?: M;
|
|
22
22
|
};
|
|
23
|
-
/**
|
|
24
|
-
* Type guard for distinguishing Slice from State objects.
|
|
25
|
-
*/
|
|
26
|
-
export declare function isSlice(x: any): x is Slice<any, any, any, any>;
|
|
27
23
|
/**
|
|
28
24
|
* Fluent builder interface for composing functional slices.
|
|
29
25
|
*
|
|
30
|
-
* Provides a chainable API for registering states and
|
|
31
|
-
* scoped to the slice's own events.
|
|
32
|
-
* handlers need via `.with()` — the `app` parameter in `.do()` handlers
|
|
33
|
-
* is typed with every action registered in the slice.
|
|
26
|
+
* Provides a chainable API for registering states and projections,
|
|
27
|
+
* and defining reactions scoped to the slice's own events.
|
|
34
28
|
*
|
|
35
29
|
* @template S - Schema register for states
|
|
36
30
|
* @template E - Event schemas
|
|
@@ -39,25 +33,24 @@ export declare function isSlice(x: any): x is Slice<any, any, any, any>;
|
|
|
39
33
|
*/
|
|
40
34
|
export type SliceBuilder<S extends SchemaRegister<A>, E extends Schemas, A extends Schemas, M extends Record<string, Schema> = {}> = {
|
|
41
35
|
/**
|
|
42
|
-
* Registers a
|
|
36
|
+
* Registers a state definition with the slice.
|
|
43
37
|
*
|
|
44
38
|
* Include every state whose actions your reaction handlers need to
|
|
45
39
|
* dispatch. Duplicate registrations (same state in multiple slices)
|
|
46
40
|
* are handled automatically at composition time.
|
|
47
41
|
*/
|
|
48
|
-
|
|
42
|
+
withState: <SX extends Schema, EX extends Schemas, AX extends Schemas, NX extends string = string>(state: State<SX, EX, AX, NX>) => SliceBuilder<S & {
|
|
49
43
|
[K in keyof AX]: SX;
|
|
50
44
|
}, E & EX, A & AX, M & {
|
|
51
45
|
[K in NX]: SX;
|
|
52
46
|
}>;
|
|
53
47
|
/**
|
|
54
|
-
* Embeds a built Projection within this slice
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
* and do not receive a Dispatcher.
|
|
48
|
+
* Embeds a built Projection within this slice. The projection's events
|
|
49
|
+
* must be a subset of events from states already registered via
|
|
50
|
+
* `.withState()`. Projection handlers preserve their `(event, stream)`
|
|
51
|
+
* signature and do not receive a Dispatcher.
|
|
59
52
|
*/
|
|
60
|
-
|
|
53
|
+
withProjection: <EP extends Schemas>(projection: [Exclude<keyof EP, keyof E>] extends [never] ? Projection<EP> : never) => SliceBuilder<S, E, A, M>;
|
|
61
54
|
/**
|
|
62
55
|
* Begins defining a reaction scoped to this slice's events.
|
|
63
56
|
*/
|
|
@@ -83,14 +76,10 @@ export type SliceBuilder<S extends SchemaRegister<A>, E extends Schemas, A exten
|
|
|
83
76
|
* reactions into self-contained feature modules. Reactions defined in a slice
|
|
84
77
|
* are type-scoped to events from that slice's states only.
|
|
85
78
|
*
|
|
86
|
-
* Include all states whose actions your handlers dispatch via `.with()`.
|
|
87
|
-
* When multiple slices share the same state, duplicates are merged
|
|
88
|
-
* automatically at `act().with(slice)` composition time.
|
|
89
|
-
*
|
|
90
79
|
* @example Single-state slice with typed dispatch
|
|
91
80
|
* ```typescript
|
|
92
81
|
* const CounterSlice = slice()
|
|
93
|
-
* .
|
|
82
|
+
* .withState(Counter)
|
|
94
83
|
* .on("Incremented")
|
|
95
84
|
* .do(async (event, _stream, app) => {
|
|
96
85
|
* await app.do("reset", target, {});
|
|
@@ -102,8 +91,8 @@ export type SliceBuilder<S extends SchemaRegister<A>, E extends Schemas, A exten
|
|
|
102
91
|
* @example Cross-state dispatch (include both states)
|
|
103
92
|
* ```typescript
|
|
104
93
|
* const CreationSlice = slice()
|
|
105
|
-
* .
|
|
106
|
-
* .
|
|
94
|
+
* .withState(TicketCreation)
|
|
95
|
+
* .withState(TicketOperations) // handler can dispatch AssignTicket
|
|
107
96
|
* .on("TicketOpened").do(async (event, _stream, app) => {
|
|
108
97
|
* await app.do("AssignTicket", target, payload, event);
|
|
109
98
|
* })
|
|
@@ -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;;;;;;;;;GASG;AACH,MAAM,MAAM,KAAK,CACf,CAAC,SAAS,cAAc,CAAC,CAAC,CAAC,EAC3B,CAAC,SAAS,OAAO,EACjB,CAAC,SAAS,OAAO,EAEjB,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,EAAE,IACnC;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,CAAC,CAAC,CAAC;IAClC,QAAQ,CAAC,WAAW,EAAE,aAAa,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC;IACrD,mEAAmE;IACnE,QAAQ,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;IAChB,iEAAiE;IACjE,QAAQ,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;CACjB,CAAC;AAEF
|
|
1
|
+
{"version":3,"file":"slice-builder.d.ts","sourceRo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AE,CAAC,CAAC,CAAC;SACtC,CAAC;KACH,CAAC;IACF;;OAEG;IACH,KAAK,EAAE,MAAM,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IAC/B;;OAEG;IACH,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC,CAAC,CAAC;CACnC,CAAC;AAIF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,wBAAgB,KAAK,CAEnB,CAAC,SAAS,cAAc,CAAC,CAAC,CAAC,GAAG,EAAE,EAChC,CAAC,SAAS,OAAO,GAAG,EAAE,EACtB,CAAC,SAAS,OAAO,GAAG,EAAE,EACtB,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,EAAE,EAErC,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,CAAC,CAA0B,EACjD,WAAW,GAAE,UAAU,CAAC,GAAG,CAAC,EAAO,GAClC,YAAY,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CA4E1B"}
|
|
@@ -107,8 +107,8 @@ export type ReactionOptions = {
|
|
|
107
107
|
* @property resolver - The reaction resolver.
|
|
108
108
|
* @property options - The reaction options.
|
|
109
109
|
*/
|
|
110
|
-
export type Reaction<E extends Schemas, K extends keyof E = keyof E> = {
|
|
111
|
-
readonly handler: ReactionHandler<E, K>;
|
|
110
|
+
export type Reaction<E extends Schemas, K extends keyof E = keyof E, A extends Schemas = Schemas> = {
|
|
111
|
+
readonly handler: ReactionHandler<E, K, A>;
|
|
112
112
|
readonly resolver: ReactionResolver<E, K>;
|
|
113
113
|
readonly options: ReactionOptions;
|
|
114
114
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reaction.d.ts","sourceRoot":"","sources":["../../../src/types/reaction.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EACV,SAAS,EACT,UAAU,EACV,MAAM,EACN,OAAO,EACP,QAAQ,EACT,MAAM,aAAa,CAAC;AAErB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,MAAM,MAAM,eAAe,CACzB,CAAC,SAAS,OAAO,EACjB,CAAC,SAAS,MAAM,CAAC,EACjB,CAAC,SAAS,OAAO,GAAG,OAAO,IACzB,CACF,KAAK,EAAE,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,EACtB,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,UAAU,CAAC,CAAC,CAAC,KACf,OAAO,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;AAEzC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,MAAM,MAAM,gBAAgB,CAAC,CAAC,SAAS,OAAO,EAAE,CAAC,SAAS,MAAM,CAAC,IAC7D;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,GACnC,CAAC,CACC,KAAK,EAAE,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,KACnB;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,CAAC,CAAC;AAE1D;;;;GAIG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B,QAAQ,CAAC,YAAY,EAAE,OAAO,CAAC;IAC/B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;CAC7B,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,MAAM,QAAQ,
|
|
1
|
+
{"version":3,"file":"reaction.d.ts","sourceRoot":"","sources":["../../../src/types/reaction.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAC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Q,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;CAC3B,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;CAC/B,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,MAAM,KAAK,CAAC,CAAC,SAAS,OAAO,IAAI;IACrC,QAAQ,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC;IAC3B,QAAQ,CAAC,MAAM,EAAE,KAAK,EAAE,CAAC;IACzB,QAAQ,CAAC,KAAK,EAAE,KAAK,EAAE,CAAC;IACxB,QAAQ,CAAC,OAAO,EAAE,KAAK,CAAC,KAAK,GAAG;QAAE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAC7D,CAAC"}
|
package/dist/index.cjs
CHANGED
|
@@ -53,8 +53,6 @@ __export(index_exports, {
|
|
|
53
53
|
dispose: () => dispose,
|
|
54
54
|
disposeAndExit: () => disposeAndExit,
|
|
55
55
|
extend: () => extend,
|
|
56
|
-
isProjection: () => isProjection,
|
|
57
|
-
isSlice: () => isSlice,
|
|
58
56
|
logger: () => logger,
|
|
59
57
|
patch: () => patch,
|
|
60
58
|
port: () => port,
|
|
@@ -843,8 +841,8 @@ var Act = class {
|
|
|
843
841
|
* @example Reaction triggering another action
|
|
844
842
|
* ```typescript
|
|
845
843
|
* const app = act()
|
|
846
|
-
* .
|
|
847
|
-
* .
|
|
844
|
+
* .withState(Order)
|
|
845
|
+
* .withState(Inventory)
|
|
848
846
|
* .on("OrderPlaced")
|
|
849
847
|
* .do(async (event, context) => {
|
|
850
848
|
* // This action is triggered by an event
|
|
@@ -1206,8 +1204,8 @@ var Act = class {
|
|
|
1206
1204
|
* @example Dynamic stream creation
|
|
1207
1205
|
* ```typescript
|
|
1208
1206
|
* const app = act()
|
|
1209
|
-
* .
|
|
1210
|
-
* .
|
|
1207
|
+
* .withState(User)
|
|
1208
|
+
* .withState(UserStats)
|
|
1211
1209
|
* .on("UserLoggedIn")
|
|
1212
1210
|
* .do(async (event) => ["incrementLoginCount", {}])
|
|
1213
1211
|
* .to((event) => ({
|
|
@@ -1448,10 +1446,84 @@ var _this_ = ({ stream }) => ({
|
|
|
1448
1446
|
});
|
|
1449
1447
|
var _void_ = () => void 0;
|
|
1450
1448
|
|
|
1451
|
-
// src/
|
|
1452
|
-
function
|
|
1453
|
-
|
|
1449
|
+
// src/act-builder.ts
|
|
1450
|
+
function act(states = /* @__PURE__ */ new Map(), registry = {
|
|
1451
|
+
actions: {},
|
|
1452
|
+
events: {}
|
|
1453
|
+
}, pendingProjections = []) {
|
|
1454
|
+
const builder = {
|
|
1455
|
+
withState: (state2) => {
|
|
1456
|
+
registerState(state2, states, registry.actions, registry.events);
|
|
1457
|
+
return act(
|
|
1458
|
+
states,
|
|
1459
|
+
registry,
|
|
1460
|
+
pendingProjections
|
|
1461
|
+
);
|
|
1462
|
+
},
|
|
1463
|
+
withSlice: (input) => {
|
|
1464
|
+
for (const s of input.states.values()) {
|
|
1465
|
+
registerState(s, states, registry.actions, registry.events);
|
|
1466
|
+
}
|
|
1467
|
+
for (const eventName of Object.keys(input.events)) {
|
|
1468
|
+
const sliceRegister = input.events[eventName];
|
|
1469
|
+
for (const [name, reaction] of sliceRegister.reactions) {
|
|
1470
|
+
registry.events[eventName].reactions.set(name, reaction);
|
|
1471
|
+
}
|
|
1472
|
+
}
|
|
1473
|
+
pendingProjections.push(...input.projections);
|
|
1474
|
+
return act(
|
|
1475
|
+
states,
|
|
1476
|
+
registry,
|
|
1477
|
+
pendingProjections
|
|
1478
|
+
);
|
|
1479
|
+
},
|
|
1480
|
+
withProjection: (proj) => {
|
|
1481
|
+
mergeProjection(proj, registry.events);
|
|
1482
|
+
return act(states, registry, pendingProjections);
|
|
1483
|
+
},
|
|
1484
|
+
on: (event) => ({
|
|
1485
|
+
do: (handler, options) => {
|
|
1486
|
+
const reaction = {
|
|
1487
|
+
handler,
|
|
1488
|
+
resolver: _this_,
|
|
1489
|
+
options: {
|
|
1490
|
+
blockOnError: options?.blockOnError ?? true,
|
|
1491
|
+
maxRetries: options?.maxRetries ?? 3
|
|
1492
|
+
}
|
|
1493
|
+
};
|
|
1494
|
+
const name = handler.name || `${String(event)}_${registry.events[event].reactions.size}`;
|
|
1495
|
+
registry.events[event].reactions.set(name, reaction);
|
|
1496
|
+
return {
|
|
1497
|
+
...builder,
|
|
1498
|
+
to(resolver) {
|
|
1499
|
+
registry.events[event].reactions.set(name, {
|
|
1500
|
+
...reaction,
|
|
1501
|
+
resolver: typeof resolver === "string" ? { target: resolver } : resolver
|
|
1502
|
+
});
|
|
1503
|
+
return builder;
|
|
1504
|
+
},
|
|
1505
|
+
void() {
|
|
1506
|
+
registry.events[event].reactions.set(name, {
|
|
1507
|
+
...reaction,
|
|
1508
|
+
resolver: _void_
|
|
1509
|
+
});
|
|
1510
|
+
return builder;
|
|
1511
|
+
}
|
|
1512
|
+
};
|
|
1513
|
+
}
|
|
1514
|
+
}),
|
|
1515
|
+
build: () => {
|
|
1516
|
+
for (const proj of pendingProjections) {
|
|
1517
|
+
mergeProjection(proj, registry.events);
|
|
1518
|
+
}
|
|
1519
|
+
return new Act(registry, states);
|
|
1520
|
+
},
|
|
1521
|
+
events: registry.events
|
|
1522
|
+
};
|
|
1523
|
+
return builder;
|
|
1454
1524
|
}
|
|
1525
|
+
|
|
1526
|
+
// src/projection-builder.ts
|
|
1455
1527
|
function projection(target, events = {}) {
|
|
1456
1528
|
const defaultResolver = target ? { target } : void 0;
|
|
1457
1529
|
const builder = {
|
|
@@ -1513,12 +1585,9 @@ function projection(target, events = {}) {
|
|
|
1513
1585
|
}
|
|
1514
1586
|
|
|
1515
1587
|
// src/slice-builder.ts
|
|
1516
|
-
function isSlice(x) {
|
|
1517
|
-
return x != null && x._tag === "Slice";
|
|
1518
|
-
}
|
|
1519
1588
|
function slice(states = /* @__PURE__ */ new Map(), actions = {}, events = {}, projections = []) {
|
|
1520
1589
|
const builder = {
|
|
1521
|
-
|
|
1590
|
+
withState: (state2) => {
|
|
1522
1591
|
registerState(state2, states, actions, events);
|
|
1523
1592
|
return slice(
|
|
1524
1593
|
states,
|
|
@@ -1527,7 +1596,7 @@ function slice(states = /* @__PURE__ */ new Map(), actions = {}, events = {}, pr
|
|
|
1527
1596
|
projections
|
|
1528
1597
|
);
|
|
1529
1598
|
},
|
|
1530
|
-
|
|
1599
|
+
withProjection: (proj) => {
|
|
1531
1600
|
projections.push(proj);
|
|
1532
1601
|
return slice(states, actions, events, projections);
|
|
1533
1602
|
},
|
|
@@ -1573,94 +1642,6 @@ function slice(states = /* @__PURE__ */ new Map(), actions = {}, events = {}, pr
|
|
|
1573
1642
|
return builder;
|
|
1574
1643
|
}
|
|
1575
1644
|
|
|
1576
|
-
// src/act-builder.ts
|
|
1577
|
-
function act(states = /* @__PURE__ */ new Map(), registry = {
|
|
1578
|
-
actions: {},
|
|
1579
|
-
events: {}
|
|
1580
|
-
}, pendingProjections = []) {
|
|
1581
|
-
const builder = {
|
|
1582
|
-
with: ((input) => {
|
|
1583
|
-
if (isProjection(input)) {
|
|
1584
|
-
mergeProjection(input, registry.events);
|
|
1585
|
-
return act(
|
|
1586
|
-
states,
|
|
1587
|
-
registry,
|
|
1588
|
-
pendingProjections
|
|
1589
|
-
);
|
|
1590
|
-
}
|
|
1591
|
-
if (isSlice(input)) {
|
|
1592
|
-
for (const s of input.states.values()) {
|
|
1593
|
-
registerState(s, states, registry.actions, registry.events);
|
|
1594
|
-
}
|
|
1595
|
-
for (const eventName of Object.keys(input.events)) {
|
|
1596
|
-
const sliceRegister = input.events[eventName];
|
|
1597
|
-
for (const [name, reaction] of sliceRegister.reactions) {
|
|
1598
|
-
registry.events[eventName].reactions.set(name, reaction);
|
|
1599
|
-
}
|
|
1600
|
-
}
|
|
1601
|
-
pendingProjections.push(...input.projections);
|
|
1602
|
-
return act(
|
|
1603
|
-
states,
|
|
1604
|
-
registry,
|
|
1605
|
-
pendingProjections
|
|
1606
|
-
);
|
|
1607
|
-
}
|
|
1608
|
-
registerState(input, states, registry.actions, registry.events);
|
|
1609
|
-
return act(
|
|
1610
|
-
states,
|
|
1611
|
-
registry,
|
|
1612
|
-
pendingProjections
|
|
1613
|
-
);
|
|
1614
|
-
}),
|
|
1615
|
-
/**
|
|
1616
|
-
* Adds a reaction to an event.
|
|
1617
|
-
*
|
|
1618
|
-
* @template K The type of event
|
|
1619
|
-
* @param event The event to add a reaction to
|
|
1620
|
-
* @returns The builder
|
|
1621
|
-
*/
|
|
1622
|
-
on: (event) => ({
|
|
1623
|
-
do: (handler, options) => {
|
|
1624
|
-
const reaction = {
|
|
1625
|
-
handler,
|
|
1626
|
-
resolver: _this_,
|
|
1627
|
-
options: {
|
|
1628
|
-
blockOnError: options?.blockOnError ?? true,
|
|
1629
|
-
maxRetries: options?.maxRetries ?? 3
|
|
1630
|
-
}
|
|
1631
|
-
};
|
|
1632
|
-
const name = handler.name || `${String(event)}_${registry.events[event].reactions.size}`;
|
|
1633
|
-
registry.events[event].reactions.set(name, reaction);
|
|
1634
|
-
return {
|
|
1635
|
-
...builder,
|
|
1636
|
-
to(resolver) {
|
|
1637
|
-
registry.events[event].reactions.set(name, {
|
|
1638
|
-
...reaction,
|
|
1639
|
-
resolver: typeof resolver === "string" ? { target: resolver } : resolver
|
|
1640
|
-
});
|
|
1641
|
-
return builder;
|
|
1642
|
-
},
|
|
1643
|
-
void() {
|
|
1644
|
-
registry.events[event].reactions.set(name, {
|
|
1645
|
-
...reaction,
|
|
1646
|
-
resolver: _void_
|
|
1647
|
-
});
|
|
1648
|
-
return builder;
|
|
1649
|
-
}
|
|
1650
|
-
};
|
|
1651
|
-
}
|
|
1652
|
-
}),
|
|
1653
|
-
build: () => {
|
|
1654
|
-
for (const proj of pendingProjections) {
|
|
1655
|
-
mergeProjection(proj, registry.events);
|
|
1656
|
-
}
|
|
1657
|
-
return new Act(registry, states);
|
|
1658
|
-
},
|
|
1659
|
-
events: registry.events
|
|
1660
|
-
};
|
|
1661
|
-
return builder;
|
|
1662
|
-
}
|
|
1663
|
-
|
|
1664
1645
|
// src/state-builder.ts
|
|
1665
1646
|
function state(entry) {
|
|
1666
1647
|
const keys = Object.keys(entry);
|
|
@@ -1749,8 +1730,6 @@ function action_builder(state2) {
|
|
|
1749
1730
|
dispose,
|
|
1750
1731
|
disposeAndExit,
|
|
1751
1732
|
extend,
|
|
1752
|
-
isProjection,
|
|
1753
|
-
isSlice,
|
|
1754
1733
|
logger,
|
|
1755
1734
|
patch,
|
|
1756
1735
|
port,
|