@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,4 +1,4 @@
|
|
|
1
|
-
import type { Message, Schema, Schemas, Snapshot, Target } from "./action.js";
|
|
1
|
+
import type { Actor, Message, Schema, Schemas, Snapshot, Target } from "./action.js";
|
|
2
2
|
/**
|
|
3
3
|
* @packageDocumentation
|
|
4
4
|
* @module act/types
|
|
@@ -78,10 +78,11 @@ export declare class ValidationError extends Error {
|
|
|
78
78
|
* This error provides complete context about what action was attempted and
|
|
79
79
|
* why it was rejected.
|
|
80
80
|
*
|
|
81
|
-
* @template
|
|
82
|
-
* @template
|
|
83
|
-
* @template
|
|
84
|
-
* @template
|
|
81
|
+
* @template TState - State schema type
|
|
82
|
+
* @template TEvents - Event schemas type
|
|
83
|
+
* @template TActions - Action schemas type
|
|
84
|
+
* @template TKey - Action name
|
|
85
|
+
* @template TActor - Actor type extending base Actor
|
|
85
86
|
*
|
|
86
87
|
* @example Catching invariant violations
|
|
87
88
|
* ```typescript
|
|
@@ -138,26 +139,26 @@ export declare class ValidationError extends Error {
|
|
|
138
139
|
*
|
|
139
140
|
* @see {@link Invariant} for defining business rules
|
|
140
141
|
*/
|
|
141
|
-
export declare class InvariantError<
|
|
142
|
+
export declare class InvariantError<TState extends Schema, TEvents extends Schemas, TActions extends Schemas, TKey extends keyof TActions, TActor extends Actor = Actor> extends Error {
|
|
142
143
|
/** The action that was attempted */
|
|
143
|
-
readonly action:
|
|
144
|
+
readonly action: TKey;
|
|
144
145
|
/** The action payload that was provided */
|
|
145
|
-
readonly payload: Readonly<
|
|
146
|
+
readonly payload: Readonly<TActions[TKey]>;
|
|
146
147
|
/** The target stream and actor context */
|
|
147
|
-
readonly target: Target
|
|
148
|
+
readonly target: Target<TActor>;
|
|
148
149
|
/** The current state snapshot when invariant was checked */
|
|
149
|
-
readonly snapshot: Snapshot<
|
|
150
|
+
readonly snapshot: Snapshot<TState, TEvents>;
|
|
150
151
|
/** Human-readable description of why the invariant failed */
|
|
151
152
|
readonly description: string;
|
|
152
153
|
constructor(
|
|
153
154
|
/** The action that was attempted */
|
|
154
|
-
action:
|
|
155
|
+
action: TKey,
|
|
155
156
|
/** The action payload that was provided */
|
|
156
|
-
payload: Readonly<
|
|
157
|
+
payload: Readonly<TActions[TKey]>,
|
|
157
158
|
/** The target stream and actor context */
|
|
158
|
-
target: Target
|
|
159
|
+
target: Target<TActor>,
|
|
159
160
|
/** The current state snapshot when invariant was checked */
|
|
160
|
-
snapshot: Snapshot<
|
|
161
|
+
snapshot: Snapshot<TState, TEvents>,
|
|
161
162
|
/** Human-readable description of why the invariant failed */
|
|
162
163
|
description: string);
|
|
163
164
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../src/types/errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../src/types/errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,KAAK,EACL,OAAO,EACP,MAAM,EACN,OAAO,EACP,QAAQ,EACR,MAAM,EACP,MAAM,aAAa,CAAC;AAErB;;;;;;;;;GASG;AACH,eAAO,MAAM,MAAM;;;;CAIT,CAAC;AAEX;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,qBAAa,eAAgB,SAAQ,KAAK;IAEtC,mEAAmE;aACnD,MAAM,EAAE,MAAM;IAC9B,iDAAiD;aACjC,OAAO,EAAE,GAAG;IAC5B,mCAAmC;aACnB,OAAO,EAAE,GAAG;;IAL5B,mEAAmE;IACnD,MAAM,EAAE,MAAM;IAC9B,iDAAiD;IACjC,OAAO,EAAE,GAAG;IAC5B,mCAAmC;IACnB,OAAO,EAAE,GAAG;CAK/B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoEG;AACH,qBAAa,cAAc,CACzB,MAAM,SAAS,MAAM,EACrB,OAAO,SAAS,OAAO,EACvB,QAAQ,SAAS,OAAO,EACxB,IAAI,SAAS,MAAM,QAAQ,EAC3B,MAAM,SAAS,KAAK,GAAG,KAAK,CAC5B,SAAQ,KAAK;IAEX,oCAAoC;IACpC,QAAQ,CAAC,MAAM,EAAE,IAAI;IACrB,2CAA2C;IAC3C,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IAC1C,0CAA0C;IAC1C,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC;IAC/B,4DAA4D;IAC5D,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IAC5C,6DAA6D;IAC7D,QAAQ,CAAC,WAAW,EAAE,MAAM;;IAT5B,oCAAoC;IAC3B,MAAM,EAAE,IAAI;IACrB,2CAA2C;IAClC,OAAO,EAAE,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IAC1C,0CAA0C;IACjC,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC;IAC/B,4DAA4D;IACnD,QAAQ,EAAE,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IAC5C,6DAA6D;IACpD,WAAW,EAAE,MAAM;CAK/B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoEG;AACH,qBAAa,gBAAiB,SAAQ,KAAK;IAEvC,sDAAsD;aACtC,MAAM,EAAE,MAAM;IAC9B,8CAA8C;aAC9B,WAAW,EAAE,MAAM;IACnC,2CAA2C;aAC3B,MAAM,EAAE,OAAO,CAAC,OAAO,EAAE,MAAM,OAAO,CAAC,EAAE;IACzD,2CAA2C;aAC3B,eAAe,EAAE,MAAM;;IAPvC,sDAAsD;IACtC,MAAM,EAAE,MAAM;IAC9B,8CAA8C;IAC9B,WAAW,EAAE,MAAM;IACnC,2CAA2C;IAC3B,MAAM,EAAE,OAAO,CAAC,OAAO,EAAE,MAAM,OAAO,CAAC,EAAE;IACzD,2CAA2C;IAC3B,eAAe,EAAE,MAAM;CAW1C"}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @category Types
|
|
5
5
|
* Types for reactions, leases, and fetch results in the Act Framework.
|
|
6
6
|
*/
|
|
7
|
-
import type { Committed, Dispatcher, Schema, Schemas, Snapshot } from "./action.js";
|
|
7
|
+
import type { Actor, Committed, Dispatcher, Schema, Schemas, Snapshot } from "./action.js";
|
|
8
8
|
/**
|
|
9
9
|
* Reaction handler function that processes committed events.
|
|
10
10
|
*
|
|
@@ -16,9 +16,10 @@ import type { Committed, Dispatcher, Schema, Schemas, Snapshot } from "./action.
|
|
|
16
16
|
* Handlers are called during drain cycles and support automatic retries
|
|
17
17
|
* with configurable error handling.
|
|
18
18
|
*
|
|
19
|
-
* @template
|
|
20
|
-
* @template
|
|
21
|
-
* @template
|
|
19
|
+
* @template TEvents - Event schemas
|
|
20
|
+
* @template TKey - Event name
|
|
21
|
+
* @template TActions - Action schemas (defaults to Schemas for stored reactions)
|
|
22
|
+
* @template TActor - Actor type extending base Actor
|
|
22
23
|
* @param event - The committed event that triggered this reaction
|
|
23
24
|
* @param stream - The target stream name for this reaction
|
|
24
25
|
* @returns Promise resolving to an action tuple or void
|
|
@@ -39,7 +40,7 @@ import type { Committed, Dispatcher, Schema, Schemas, Snapshot } from "./action.
|
|
|
39
40
|
*
|
|
40
41
|
* @see {@link Reaction} for complete reaction configuration
|
|
41
42
|
*/
|
|
42
|
-
export type ReactionHandler<
|
|
43
|
+
export type ReactionHandler<TEvents extends Schemas, TKey extends keyof TEvents, TActions extends Schemas = Schemas, TActor extends Actor = Actor> = (event: Committed<TEvents, TKey>, stream: string, app: Dispatcher<TActions, TActor>) => Promise<Snapshot<Schema, TEvents> | void>;
|
|
43
44
|
/**
|
|
44
45
|
* Resolver for determining which stream a reaction should target.
|
|
45
46
|
*
|
|
@@ -50,8 +51,8 @@ export type ReactionHandler<E extends Schemas, K extends keyof E, A extends Sche
|
|
|
50
51
|
* Resolvers can also specify source streams for optimization, allowing the drain
|
|
51
52
|
* process to efficiently fetch only relevant events.
|
|
52
53
|
*
|
|
53
|
-
* @template
|
|
54
|
-
* @template
|
|
54
|
+
* @template TEvents - Event schemas
|
|
55
|
+
* @template TKey - Event name
|
|
55
56
|
* @param event - The committed event (for dynamic resolvers)
|
|
56
57
|
* @returns Target stream configuration or undefined to skip
|
|
57
58
|
*
|
|
@@ -83,10 +84,10 @@ export type ReactionHandler<E extends Schemas, K extends keyof E, A extends Sche
|
|
|
83
84
|
*
|
|
84
85
|
* @see {@link Reaction} for complete reaction configuration
|
|
85
86
|
*/
|
|
86
|
-
export type ReactionResolver<
|
|
87
|
+
export type ReactionResolver<TEvents extends Schemas, TKey extends keyof TEvents> = {
|
|
87
88
|
target: string;
|
|
88
89
|
source?: string;
|
|
89
|
-
} | ((event: Committed<
|
|
90
|
+
} | ((event: Committed<TEvents, TKey>) => {
|
|
90
91
|
target: string;
|
|
91
92
|
source?: string;
|
|
92
93
|
} | undefined);
|
|
@@ -101,28 +102,30 @@ export type ReactionOptions = {
|
|
|
101
102
|
};
|
|
102
103
|
/**
|
|
103
104
|
* Defines a reaction to an event.
|
|
104
|
-
* @template
|
|
105
|
-
* @template
|
|
105
|
+
* @template TEvents - Event schemas.
|
|
106
|
+
* @template TKey - Event name.
|
|
107
|
+
* @template TActions - Action schemas.
|
|
108
|
+
* @template TActor - Actor type extending base Actor.
|
|
106
109
|
* @property handler - The reaction handler.
|
|
107
110
|
* @property resolver - The reaction resolver.
|
|
108
111
|
* @property options - The reaction options.
|
|
109
112
|
*/
|
|
110
|
-
export type Reaction<
|
|
111
|
-
readonly handler: ReactionHandler<
|
|
112
|
-
readonly resolver: ReactionResolver<
|
|
113
|
+
export type Reaction<TEvents extends Schemas, TKey extends keyof TEvents = keyof TEvents, TActions extends Schemas = Schemas, TActor extends Actor = Actor> = {
|
|
114
|
+
readonly handler: ReactionHandler<TEvents, TKey, TActions, TActor>;
|
|
115
|
+
readonly resolver: ReactionResolver<TEvents, TKey>;
|
|
113
116
|
readonly options: ReactionOptions;
|
|
114
117
|
};
|
|
115
118
|
/**
|
|
116
119
|
* Payload for a reaction.
|
|
117
|
-
* @template
|
|
120
|
+
* @template TEvents - Event schemas.
|
|
118
121
|
* @property handler - The reaction handler.
|
|
119
122
|
* @property resolver - The reaction resolver.
|
|
120
123
|
* @property options - The reaction options.
|
|
121
124
|
* @property event - The committed event triggering the reaction.
|
|
122
125
|
* @property source - The source stream.
|
|
123
126
|
*/
|
|
124
|
-
export type ReactionPayload<
|
|
125
|
-
readonly event: Committed<
|
|
127
|
+
export type ReactionPayload<TEvents extends Schemas> = Reaction<TEvents> & {
|
|
128
|
+
readonly event: Committed<TEvents, keyof TEvents>;
|
|
126
129
|
readonly source?: string;
|
|
127
130
|
};
|
|
128
131
|
/**
|
|
@@ -140,19 +143,19 @@ export type Poll = {
|
|
|
140
143
|
};
|
|
141
144
|
/**
|
|
142
145
|
* Result of fetching events from the store for processing.
|
|
143
|
-
* @template
|
|
146
|
+
* @template TEvents - Event schemas.
|
|
144
147
|
* @property stream - The stream name
|
|
145
148
|
* @property source - The source stream(s) (name or RegExp), or undefined when sourcing from all streams.
|
|
146
149
|
* @property at - The last event sequence number processed by the stream.
|
|
147
150
|
* @property lagging - Whether the stream is lagging behind.
|
|
148
151
|
* @property events - The list of next committed events to be processed by the stream.
|
|
149
152
|
*/
|
|
150
|
-
export type Fetch<
|
|
153
|
+
export type Fetch<TEvents extends Schemas> = Array<{
|
|
151
154
|
readonly stream: string;
|
|
152
155
|
readonly source?: string;
|
|
153
156
|
readonly at: number;
|
|
154
157
|
readonly lagging: boolean;
|
|
155
|
-
readonly events: Committed<
|
|
158
|
+
readonly events: Committed<TEvents, keyof TEvents>[];
|
|
156
159
|
}>;
|
|
157
160
|
/**
|
|
158
161
|
* Lease information for distributed stream processing.
|
|
@@ -217,8 +220,8 @@ export type DrainOptions = {
|
|
|
217
220
|
* @property acked - The acked events.
|
|
218
221
|
* @property blocked - The blocked events (with error).
|
|
219
222
|
*/
|
|
220
|
-
export type Drain<
|
|
221
|
-
readonly fetched: Fetch<
|
|
223
|
+
export type Drain<TEvents extends Schemas> = {
|
|
224
|
+
readonly fetched: Fetch<TEvents>;
|
|
222
225
|
readonly leased: Lease[];
|
|
223
226
|
readonly acked: Lease[];
|
|
224
227
|
readonly blocked: Array<Lease & {
|
|
@@ -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
|
|
1
|
+
{"version":3,"file":"reaction.d.ts","sourceRoot":"","sources":["../../../src/types/reaction.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EACV,KAAK,EACL,SAAS,EACT,UAAU,EACV,MAAM,EACN,OAAO,EACP,QAAQ,EACT,MAAM,aAAa,CAAC;AAErB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,MAAM,MAAM,eAAe,CACzB,OAAO,SAAS,OAAO,EACvB,IAAI,SAAS,MAAM,OAAO,EAC1B,QAAQ,SAAS,OAAO,GAAG,OAAO,EAClC,MAAM,SAAS,KAAK,GAAG,KAAK,IAC1B,CACF,KAAK,EAAE,SAAS,CAAC,OAAO,EAAE,IAAI,CAAC,EAC/B,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,UAAU,CAAC,QAAQ,EAAE,MAAM,CAAC,KAC9B,OAAO,CAAC,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC,CAAC;AAE/C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,MAAM,MAAM,gBAAgB,CAC1B,OAAO,SAAS,OAAO,EACvB,IAAI,SAAS,MAAM,OAAO,IAExB;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,GACnC,CAAC,CACC,KAAK,EAAE,SAAS,CAAC,OAAO,EAAE,IAAI,CAAC,KAC5B;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,CAAC,CAAC;AAE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
|
|
13
|
-
export type ReactionsRegister<
|
|
14
|
-
schema: ZodType<
|
|
15
|
-
reactions: Map<string, Reaction<
|
|
13
|
+
export type ReactionsRegister<TEvents extends Schemas, TKey extends keyof TEvents> = {
|
|
14
|
+
schema: ZodType<TEvents[TKey]>;
|
|
15
|
+
reactions: Map<string, Reaction<TEvents, TKey>>;
|
|
16
16
|
};
|
|
17
17
|
/**
|
|
18
18
|
* Maps event names to their schema and registered reactions.
|
|
19
|
-
* @template
|
|
19
|
+
* @template TEvents - Event schemas.
|
|
20
20
|
*/
|
|
21
|
-
export type EventRegister<
|
|
22
|
-
[
|
|
21
|
+
export type EventRegister<TEvents extends Schemas> = {
|
|
22
|
+
[TKey in keyof TEvents]: ReactionsRegister<TEvents, TKey>;
|
|
23
23
|
};
|
|
24
24
|
/**
|
|
25
25
|
* Maps action names to their schema definitions.
|
|
26
|
-
* @template
|
|
26
|
+
* @template TSchemaReg - Schema register for actions.
|
|
27
27
|
*/
|
|
28
|
-
export type SchemaRegister<
|
|
29
|
-
[
|
|
28
|
+
export type SchemaRegister<TSchemaReg> = {
|
|
29
|
+
[TKey in keyof TSchemaReg]: Schema;
|
|
30
30
|
};
|
|
31
31
|
/**
|
|
32
32
|
* Registry of all actions and events for a domain.
|
|
33
|
-
* @template
|
|
34
|
-
* @template
|
|
35
|
-
* @template
|
|
33
|
+
* @template TSchemaReg - State schemas.
|
|
34
|
+
* @template TEvents - Event schemas.
|
|
35
|
+
* @template TActions - Action schemas.
|
|
36
36
|
* @property actions - Map of action names to state definitions.
|
|
37
37
|
* @property events - Map of event names to event registration info.
|
|
38
38
|
*/
|
|
39
|
-
export type Registry<
|
|
39
|
+
export type Registry<TSchemaReg extends SchemaRegister<TActions>, TEvents extends Schemas, TActions extends Schemas> = {
|
|
40
40
|
readonly actions: {
|
|
41
|
-
[
|
|
41
|
+
[TKey in keyof TActions]: State<TSchemaReg[TKey], TEvents, TActions>;
|
|
42
42
|
};
|
|
43
|
-
readonly events: EventRegister<
|
|
43
|
+
readonly events: EventRegister<TEvents>;
|
|
44
44
|
};
|
|
45
45
|
/**
|
|
46
46
|
* Utility type to convert a registry entry to a committed event type.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../../src/types/registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AACjC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACzE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAE9C;;;;;GAKG;AAEH;;GAEG;AACH,MAAM,MAAM,iBAAiB,
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../../src/types/registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AACjC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACzE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAE9C;;;;;GAKG;AAEH;;GAEG;AACH,MAAM,MAAM,iBAAiB,CAC3B,OAAO,SAAS,OAAO,EACvB,IAAI,SAAS,MAAM,OAAO,IACxB;IACF,MAAM,EAAE,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;IAC/B,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC;CACjD,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,aAAa,CAAC,OAAO,SAAS,OAAO,IAAI;KAClD,IAAI,IAAI,MAAM,OAAO,GAAG,iBAAiB,CAAC,OAAO,EAAE,IAAI,CAAC;CAC1D,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,cAAc,C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;
|
|
18
|
-
}, z.core.$
|
|
18
|
+
}, z.core.$loose>>;
|
|
19
19
|
/**
|
|
20
20
|
* Zod schema for a target (stream and actor info).
|
|
21
21
|
*/
|
|
@@ -24,9 +24,9 @@ export declare const TargetSchema: z.ZodReadonly<z.ZodObject<{
|
|
|
24
24
|
actor: z.ZodReadonly<z.ZodObject<{
|
|
25
25
|
id: z.ZodString;
|
|
26
26
|
name: z.ZodString;
|
|
27
|
-
}, z.core.$
|
|
27
|
+
}, z.core.$loose>>;
|
|
28
28
|
expectedVersion: z.ZodOptional<z.ZodNumber>;
|
|
29
|
-
}, z.core.$
|
|
29
|
+
}, z.core.$loose>>;
|
|
30
30
|
/**
|
|
31
31
|
* Zod schema for causation event metadata.
|
|
32
32
|
*/
|
|
@@ -46,9 +46,9 @@ export declare const EventMetaSchema: z.ZodReadonly<z.ZodObject<{
|
|
|
46
46
|
actor: z.ZodReadonly<z.ZodObject<{
|
|
47
47
|
id: z.ZodString;
|
|
48
48
|
name: z.ZodString;
|
|
49
|
-
}, z.core.$
|
|
49
|
+
}, z.core.$loose>>;
|
|
50
50
|
expectedVersion: z.ZodOptional<z.ZodNumber>;
|
|
51
|
-
}, z.core.$
|
|
51
|
+
}, z.core.$loose>>, z.ZodObject<{
|
|
52
52
|
name: z.ZodString;
|
|
53
53
|
}, z.core.$strip>>>;
|
|
54
54
|
event: z.ZodOptional<z.ZodObject<{
|
|
@@ -74,9 +74,9 @@ export declare const CommittedMetaSchema: z.ZodReadonly<z.ZodObject<{
|
|
|
74
74
|
actor: z.ZodReadonly<z.ZodObject<{
|
|
75
75
|
id: z.ZodString;
|
|
76
76
|
name: z.ZodString;
|
|
77
|
-
}, z.core.$
|
|
77
|
+
}, z.core.$loose>>;
|
|
78
78
|
expectedVersion: z.ZodOptional<z.ZodNumber>;
|
|
79
|
-
}, z.core.$
|
|
79
|
+
}, z.core.$loose>>, z.ZodObject<{
|
|
80
80
|
name: z.ZodString;
|
|
81
81
|
}, z.core.$strip>>>;
|
|
82
82
|
event: z.ZodOptional<z.ZodObject<{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../../../src/types/schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,KAAK,CAAC;AAEhD;;;;;GAKG;AAEH;;GAEG;AACH,eAAO,MAAM,QAAQ,sCAAkC,CAAC;AAExD;;GAEG;AACH,eAAO,MAAM,WAAW;;;
|
|
1
|
+
{"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../../../src/types/schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,KAAK,CAAC;AAEhD;;;;;GAKG;AAEH;;GAEG;AACH,eAAO,MAAM,QAAQ,sCAAkC,CAAC;AAExD;;GAEG;AACH,eAAO,MAAM,WAAW;;;kBAMX,CAAC;AAEd;;GAEG;AACH,eAAO,MAAM,YAAY;;;;;;;kBAOZ,CAAC;AAEd;;GAEG;AACH,eAAO,MAAM,oBAAoB;;;;iBAI/B,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;kBAQf,CAAC;AAEd;;GAEG;AACH,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;kBAQnB,CAAC;AAEd;;;;;GAKG;AACH,MAAM,MAAM,WAAW,GAAG,QAAQ,CAAC;IACjC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,WAAW,CAAC,GAAG,OAAO,QAAQ,CAAC,CAAC;IACjE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,WAAW,CAAC,GAAG,OAAO,QAAQ,CAAC,CAAC;IAClE,KAAK,EAAE,SAAS,CAAC,WAAW,CAAC,CAAC;CAC/B,CAAC,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,WAAW;;;;;;;;;;;kBAaX,CAAC"}
|
package/dist/index.cjs
CHANGED
|
@@ -122,12 +122,12 @@ var ZodEmpty = import_zod.z.record(import_zod.z.string(), import_zod.z.never());
|
|
|
122
122
|
var ActorSchema = import_zod.z.object({
|
|
123
123
|
id: import_zod.z.string(),
|
|
124
124
|
name: import_zod.z.string()
|
|
125
|
-
}).readonly();
|
|
125
|
+
}).loose().readonly();
|
|
126
126
|
var TargetSchema = import_zod.z.object({
|
|
127
127
|
stream: import_zod.z.string(),
|
|
128
128
|
actor: ActorSchema,
|
|
129
129
|
expectedVersion: import_zod.z.number().optional()
|
|
130
|
-
}).readonly();
|
|
130
|
+
}).loose().readonly();
|
|
131
131
|
var CausationEventSchema = import_zod.z.object({
|
|
132
132
|
id: import_zod.z.number(),
|
|
133
133
|
name: import_zod.z.string(),
|
|
@@ -793,7 +793,7 @@ var Act = class {
|
|
|
793
793
|
* 5. Applies events to create new state
|
|
794
794
|
* 6. Commits events to the store with optimistic concurrency control
|
|
795
795
|
*
|
|
796
|
-
* @template
|
|
796
|
+
* @template TKey - Action name from registered actions
|
|
797
797
|
* @param action - The name of the action to execute
|
|
798
798
|
* @param target - Target specification with stream ID and actor context
|
|
799
799
|
* @param payload - Action payload matching the action's schema
|
|
@@ -1479,7 +1479,18 @@ function act(states = /* @__PURE__ */ new Map(), registry = {
|
|
|
1479
1479
|
},
|
|
1480
1480
|
withProjection: (proj) => {
|
|
1481
1481
|
mergeProjection(proj, registry.events);
|
|
1482
|
-
return act(
|
|
1482
|
+
return act(
|
|
1483
|
+
states,
|
|
1484
|
+
registry,
|
|
1485
|
+
pendingProjections
|
|
1486
|
+
);
|
|
1487
|
+
},
|
|
1488
|
+
withActor: () => {
|
|
1489
|
+
return act(
|
|
1490
|
+
states,
|
|
1491
|
+
registry,
|
|
1492
|
+
pendingProjections
|
|
1493
|
+
);
|
|
1483
1494
|
},
|
|
1484
1495
|
on: (event) => ({
|
|
1485
1496
|
do: (handler, options) => {
|
|
@@ -1516,7 +1527,10 @@ function act(states = /* @__PURE__ */ new Map(), registry = {
|
|
|
1516
1527
|
for (const proj of pendingProjections) {
|
|
1517
1528
|
mergeProjection(proj, registry.events);
|
|
1518
1529
|
}
|
|
1519
|
-
return new Act(
|
|
1530
|
+
return new Act(
|
|
1531
|
+
registry,
|
|
1532
|
+
states
|
|
1533
|
+
);
|
|
1520
1534
|
},
|
|
1521
1535
|
events: registry.events
|
|
1522
1536
|
};
|
|
@@ -1598,7 +1612,12 @@ function slice(states = /* @__PURE__ */ new Map(), actions = {}, events = {}, pr
|
|
|
1598
1612
|
},
|
|
1599
1613
|
withProjection: (proj) => {
|
|
1600
1614
|
projections.push(proj);
|
|
1601
|
-
return slice(
|
|
1615
|
+
return slice(
|
|
1616
|
+
states,
|
|
1617
|
+
actions,
|
|
1618
|
+
events,
|
|
1619
|
+
projections
|
|
1620
|
+
);
|
|
1602
1621
|
},
|
|
1603
1622
|
on: (event) => ({
|
|
1604
1623
|
do: (handler, options) => {
|
|
@@ -1694,7 +1713,10 @@ function action_builder(state2) {
|
|
|
1694
1713
|
const schema = entry[action2];
|
|
1695
1714
|
if (action2 in state2.actions)
|
|
1696
1715
|
throw new Error(`Duplicate action "${action2}"`);
|
|
1697
|
-
const actions = {
|
|
1716
|
+
const actions = {
|
|
1717
|
+
...state2.actions,
|
|
1718
|
+
[action2]: schema
|
|
1719
|
+
};
|
|
1698
1720
|
const on = { ...state2.on };
|
|
1699
1721
|
const _given = { ...state2.given };
|
|
1700
1722
|
function given(rules) {
|
|
@@ -1718,7 +1740,10 @@ function action_builder(state2) {
|
|
|
1718
1740
|
return { given, emit };
|
|
1719
1741
|
},
|
|
1720
1742
|
snap(snap2) {
|
|
1721
|
-
return action_builder({
|
|
1743
|
+
return action_builder({
|
|
1744
|
+
...state2,
|
|
1745
|
+
snap: snap2
|
|
1746
|
+
});
|
|
1722
1747
|
},
|
|
1723
1748
|
build() {
|
|
1724
1749
|
return state2;
|