@rotorsoft/act 0.35.0 → 0.35.2
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 -0
- package/dist/@types/act.d.ts +672 -0
- package/dist/@types/act.d.ts.map +1 -0
- package/dist/@types/adapters/console-logger.d.ts +41 -0
- package/dist/@types/adapters/console-logger.d.ts.map +1 -0
- package/dist/@types/adapters/in-memory-cache.d.ts +34 -0
- package/dist/@types/adapters/in-memory-cache.d.ts.map +1 -0
- package/dist/@types/adapters/in-memory-store.d.ts +202 -0
- package/dist/@types/adapters/in-memory-store.d.ts.map +1 -0
- package/dist/@types/adapters/index.d.ts +4 -0
- package/dist/@types/adapters/index.d.ts.map +1 -0
- package/dist/@types/builders/act-builder.d.ts +160 -0
- package/dist/@types/builders/act-builder.d.ts.map +1 -0
- package/dist/@types/builders/index.d.ts +13 -0
- package/dist/@types/builders/index.d.ts.map +1 -0
- package/dist/@types/builders/projection-builder.d.ts +101 -0
- package/dist/@types/builders/projection-builder.d.ts.map +1 -0
- package/dist/@types/builders/slice-builder.d.ts +109 -0
- package/dist/@types/builders/slice-builder.d.ts.map +1 -0
- package/dist/@types/builders/state-builder.d.ts +424 -0
- package/dist/@types/builders/state-builder.d.ts.map +1 -0
- package/dist/@types/config.d.ts +119 -0
- package/dist/@types/config.d.ts.map +1 -0
- package/dist/@types/index.d.ts +14 -0
- package/dist/@types/index.d.ts.map +1 -0
- package/dist/@types/internal/build-classify.d.ts +44 -0
- package/dist/@types/internal/build-classify.d.ts.map +1 -0
- package/dist/@types/internal/close-cycle.d.ts +38 -0
- package/dist/@types/internal/close-cycle.d.ts.map +1 -0
- package/dist/@types/internal/correlate-cycle.d.ts +78 -0
- package/dist/@types/internal/correlate-cycle.d.ts.map +1 -0
- package/dist/@types/internal/drain-cycle.d.ts +113 -0
- package/dist/@types/internal/drain-cycle.d.ts.map +1 -0
- package/dist/@types/internal/drain-ratio.d.ts +26 -0
- package/dist/@types/internal/drain-ratio.d.ts.map +1 -0
- package/dist/@types/internal/drain.d.ts +41 -0
- package/dist/@types/internal/drain.d.ts.map +1 -0
- package/dist/@types/internal/event-sourcing.d.ts +96 -0
- package/dist/@types/internal/event-sourcing.d.ts.map +1 -0
- package/dist/@types/internal/index.d.ts +29 -0
- package/dist/@types/internal/index.d.ts.map +1 -0
- package/dist/@types/internal/merge.d.ts +31 -0
- package/dist/@types/internal/merge.d.ts.map +1 -0
- package/dist/@types/internal/reactions.d.ts +54 -0
- package/dist/@types/internal/reactions.d.ts.map +1 -0
- package/dist/@types/internal/settle.d.ts +60 -0
- package/dist/@types/internal/settle.d.ts.map +1 -0
- package/dist/@types/internal/tracing.d.ts +45 -0
- package/dist/@types/internal/tracing.d.ts.map +1 -0
- package/dist/@types/lru-map.d.ts +50 -0
- package/dist/@types/lru-map.d.ts.map +1 -0
- package/dist/@types/ports.d.ts +196 -0
- package/dist/@types/ports.d.ts.map +1 -0
- package/dist/@types/signals.d.ts +2 -0
- package/dist/@types/signals.d.ts.map +1 -0
- package/dist/@types/types/action.d.ts +444 -0
- package/dist/@types/types/action.d.ts.map +1 -0
- package/dist/@types/types/errors.d.ts +284 -0
- package/dist/@types/types/errors.d.ts.map +1 -0
- package/dist/@types/types/index.d.ts +39 -0
- package/dist/@types/types/index.d.ts.map +1 -0
- package/dist/@types/types/ports.d.ts +617 -0
- package/dist/@types/types/ports.d.ts.map +1 -0
- package/dist/@types/types/reaction.d.ts +314 -0
- package/dist/@types/types/reaction.d.ts.map +1 -0
- package/dist/@types/types/registry.d.ts +74 -0
- package/dist/@types/types/registry.d.ts.map +1 -0
- package/dist/@types/types/schemas.d.ts +117 -0
- package/dist/@types/types/schemas.d.ts.map +1 -0
- package/dist/@types/utils.d.ts +54 -0
- package/dist/@types/utils.d.ts.map +1 -0
- package/dist/chunk-AGWZY6YT.js +127 -0
- package/dist/chunk-AGWZY6YT.js.map +1 -0
- package/dist/index.cjs +3144 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.js +2975 -0
- package/dist/index.js.map +1 -0
- package/dist/types/index.cjs +166 -0
- package/dist/types/index.cjs.map +1 -0
- package/dist/types/index.js +33 -0
- package/dist/types/index.js.map +1 -0
- package/package.json +15 -5
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @packageDocumentation
|
|
3
|
+
* @module act/types
|
|
4
|
+
* @category Types
|
|
5
|
+
* Types for reactions, leases, and fetch results in the Act Framework.
|
|
6
|
+
*/
|
|
7
|
+
import type { Actor, Committed, IAct, Query, Schema, Schemas, Snapshot } from "./action.js";
|
|
8
|
+
/**
|
|
9
|
+
* Reaction handler function that processes committed events.
|
|
10
|
+
*
|
|
11
|
+
* Reaction handlers respond to events asynchronously. They can:
|
|
12
|
+
* - Perform side effects (send emails, call APIs, log, etc.)
|
|
13
|
+
* - Return an action tuple to trigger another action
|
|
14
|
+
* - Return `void` or `undefined` for side-effect-only reactions
|
|
15
|
+
*
|
|
16
|
+
* Handlers are called during drain cycles and support automatic retries
|
|
17
|
+
* with configurable error handling.
|
|
18
|
+
*
|
|
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
|
|
23
|
+
* @param event - The committed event that triggered this reaction
|
|
24
|
+
* @param stream - The target stream name for this reaction
|
|
25
|
+
* @returns Promise resolving to an action tuple or void
|
|
26
|
+
*
|
|
27
|
+
* @example Side effect only
|
|
28
|
+
* ```typescript
|
|
29
|
+
* const sendEmail: ReactionHandler<Events, "UserCreated"> = async (event) => {
|
|
30
|
+
* await emailService.send(event.data.email, "Welcome!");
|
|
31
|
+
* };
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* @example Triggering another action
|
|
35
|
+
* ```typescript
|
|
36
|
+
* const reduceInventory: ReactionHandler<Events, "OrderPlaced"> = async (event) => {
|
|
37
|
+
* return ["reduceStock", { amount: event.data.items.length }];
|
|
38
|
+
* };
|
|
39
|
+
* ```
|
|
40
|
+
*
|
|
41
|
+
* @see {@link Reaction} for complete reaction configuration
|
|
42
|
+
*/
|
|
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: IAct<TEvents, TActions, TActor>) => Promise<Snapshot<Schema, TEvents> | void>;
|
|
44
|
+
/**
|
|
45
|
+
* Resolver for determining which stream a reaction should target.
|
|
46
|
+
*
|
|
47
|
+
* Resolvers enable dynamic reaction routing based on event content. They can be:
|
|
48
|
+
* - **Static**: Always route to the same target stream
|
|
49
|
+
* - **Dynamic**: Determine target based on event data at runtime
|
|
50
|
+
*
|
|
51
|
+
* Resolvers can also specify source streams for optimization, allowing the drain
|
|
52
|
+
* process to efficiently fetch only relevant events. An optional `priority`
|
|
53
|
+
* biases the lagging-frontier `claim()` ordering — see {@link Resolved.priority}.
|
|
54
|
+
*
|
|
55
|
+
* @template TEvents - Event schemas
|
|
56
|
+
* @template TKey - Event name
|
|
57
|
+
* @param event - The committed event (for dynamic resolvers)
|
|
58
|
+
* @returns Target stream configuration or undefined to skip
|
|
59
|
+
*
|
|
60
|
+
* @example Static target
|
|
61
|
+
* ```typescript
|
|
62
|
+
* .on("UserCreated")
|
|
63
|
+
* .do(sendWelcomeEmail)
|
|
64
|
+
* .to("email-queue") // Static target
|
|
65
|
+
* ```
|
|
66
|
+
*
|
|
67
|
+
* @example Dynamic target per user
|
|
68
|
+
* ```typescript
|
|
69
|
+
* .on("UserLoggedIn")
|
|
70
|
+
* .do(incrementLoginCount)
|
|
71
|
+
* .to((event) => ({
|
|
72
|
+
* target: `stats-${event.stream}` // Dynamic per user
|
|
73
|
+
* }))
|
|
74
|
+
* ```
|
|
75
|
+
*
|
|
76
|
+
* @example With source optimization
|
|
77
|
+
* ```typescript
|
|
78
|
+
* .on("UserUpdated")
|
|
79
|
+
* .do(updateReadModel)
|
|
80
|
+
* .to(({ stream }) => ({
|
|
81
|
+
* source: stream, // Only fetch from this user's stream
|
|
82
|
+
* target: `cache-${stream}` // Update corresponding cache
|
|
83
|
+
* }))
|
|
84
|
+
* ```
|
|
85
|
+
*
|
|
86
|
+
* @example With priority (saturated worker scheduling)
|
|
87
|
+
* ```typescript
|
|
88
|
+
* .on("OrderConfirmed")
|
|
89
|
+
* .do(sendCriticalNotification)
|
|
90
|
+
* .to({ target: "notifications-out", priority: 10 })
|
|
91
|
+
* ```
|
|
92
|
+
*
|
|
93
|
+
* @see {@link Reaction} for complete reaction configuration
|
|
94
|
+
* @see {@link Resolved} for the resolved-target shape
|
|
95
|
+
*/
|
|
96
|
+
export type ReactionResolver<TEvents extends Schemas, TKey extends keyof TEvents> = Resolved | ((event: Committed<TEvents, TKey>) => Resolved | undefined);
|
|
97
|
+
/**
|
|
98
|
+
* Resolver output shape — what `.to(...)` returns for a static or dynamic
|
|
99
|
+
* resolver.
|
|
100
|
+
*
|
|
101
|
+
* @property target - Stream name that processes this reaction
|
|
102
|
+
* @property source - Optional source-stream filter for fetch optimization
|
|
103
|
+
* @property priority - Optional scheduling hint. The lagging-frontier
|
|
104
|
+
* `claim()` orders streams by `priority DESC, at ASC`, so a higher value
|
|
105
|
+
* makes the stream win lease slots ahead of equal-watermark peers under
|
|
106
|
+
* saturation. Default `0` — behavior identical to current dual-frontier.
|
|
107
|
+
* Only meaningful when `streamLimit` is binding (more candidate streams
|
|
108
|
+
* than the worker can claim per cycle); idle systems are unaffected.
|
|
109
|
+
* See `libs/act-pg/PERFORMANCE.md` for the benchmark that motivated this
|
|
110
|
+
* knob.
|
|
111
|
+
*/
|
|
112
|
+
export type Resolved = {
|
|
113
|
+
readonly target: string;
|
|
114
|
+
readonly source?: string;
|
|
115
|
+
readonly priority?: number;
|
|
116
|
+
};
|
|
117
|
+
/**
|
|
118
|
+
* Options for reaction processing.
|
|
119
|
+
* @property blockOnError - Whether to block on error.
|
|
120
|
+
* @property maxRetries - Maximum number of retries.
|
|
121
|
+
*/
|
|
122
|
+
export type ReactionOptions = {
|
|
123
|
+
readonly blockOnError: boolean;
|
|
124
|
+
readonly maxRetries: number;
|
|
125
|
+
};
|
|
126
|
+
/**
|
|
127
|
+
* Distributive mapped type that produces a proper discriminated union of
|
|
128
|
+
* committed events. Unlike `Committed<TEvents, keyof TEvents>` (where
|
|
129
|
+
* `name` and `data` are independent unions), each variant correlates
|
|
130
|
+
* `name` with its corresponding `data` — enabling `switch (event.name)`
|
|
131
|
+
* to narrow both fields correctly.
|
|
132
|
+
*
|
|
133
|
+
* @template TEvents - Event schemas
|
|
134
|
+
*
|
|
135
|
+
* @example Exhaustive switch
|
|
136
|
+
* ```typescript
|
|
137
|
+
* for (const event of events) {
|
|
138
|
+
* switch (event.name) {
|
|
139
|
+
* case "TicketOpened":
|
|
140
|
+
* event.data; // typed as TicketOpened's schema
|
|
141
|
+
* break;
|
|
142
|
+
* case "TicketClosed":
|
|
143
|
+
* event.data; // typed as TicketClosed's schema
|
|
144
|
+
* break;
|
|
145
|
+
* default:
|
|
146
|
+
* const _: never = event; // compile error if a case is missing
|
|
147
|
+
* }
|
|
148
|
+
* }
|
|
149
|
+
* ```
|
|
150
|
+
*/
|
|
151
|
+
export type BatchEvent<TEvents extends Schemas> = {
|
|
152
|
+
[K in keyof TEvents]: Committed<TEvents, K>;
|
|
153
|
+
}[keyof TEvents];
|
|
154
|
+
/**
|
|
155
|
+
* Batch handler for projections that processes multiple events in a single call.
|
|
156
|
+
*
|
|
157
|
+
* Receives the full ordered array of all event types declared on the projection,
|
|
158
|
+
* enabling bulk DB operations (batch INSERT/UPDATE) in a single transaction.
|
|
159
|
+
* The handler is always called when defined — even for a single event.
|
|
160
|
+
*
|
|
161
|
+
* @template TEvents - Event schemas (all events declared on the projection)
|
|
162
|
+
* @param events - Ordered array of committed events (discriminated union)
|
|
163
|
+
* @param stream - The target stream name
|
|
164
|
+
*
|
|
165
|
+
* @see {@link BatchEvent} for the discriminated union type
|
|
166
|
+
*/
|
|
167
|
+
export type BatchHandler<TEvents extends Schemas> = (events: ReadonlyArray<BatchEvent<TEvents>>, stream: string) => Promise<void>;
|
|
168
|
+
/**
|
|
169
|
+
* Defines a reaction to an event.
|
|
170
|
+
* @template TEvents - Event schemas.
|
|
171
|
+
* @template TKey - Event name.
|
|
172
|
+
* @template TActions - Action schemas.
|
|
173
|
+
* @template TActor - Actor type extending base Actor.
|
|
174
|
+
* @property handler - The reaction handler.
|
|
175
|
+
* @property resolver - The reaction resolver.
|
|
176
|
+
* @property options - The reaction options.
|
|
177
|
+
*/
|
|
178
|
+
export type Reaction<TEvents extends Schemas, TKey extends keyof TEvents = keyof TEvents, TActions extends Schemas = Schemas, TActor extends Actor = Actor> = {
|
|
179
|
+
readonly handler: ReactionHandler<TEvents, TKey, TActions, TActor>;
|
|
180
|
+
/**
|
|
181
|
+
* Mutable so the builder's `.do()` → `.to()` chain can patch the resolver
|
|
182
|
+
* in place (registered once with the default `_this_` resolver in `.do()`,
|
|
183
|
+
* overwritten in `.to()` if present). After build-time the field is
|
|
184
|
+
* effectively immutable; runtime consumers only read it.
|
|
185
|
+
*/
|
|
186
|
+
resolver: ReactionResolver<TEvents, TKey>;
|
|
187
|
+
readonly options: ReactionOptions;
|
|
188
|
+
};
|
|
189
|
+
/**
|
|
190
|
+
* Payload for a reaction.
|
|
191
|
+
* @template TEvents - Event schemas.
|
|
192
|
+
* @property handler - The reaction handler.
|
|
193
|
+
* @property resolver - The reaction resolver.
|
|
194
|
+
* @property options - The reaction options.
|
|
195
|
+
* @property event - The committed event triggering the reaction.
|
|
196
|
+
* @property source - The source stream.
|
|
197
|
+
*/
|
|
198
|
+
export type ReactionPayload<TEvents extends Schemas> = Reaction<TEvents> & {
|
|
199
|
+
readonly event: Committed<TEvents, keyof TEvents>;
|
|
200
|
+
readonly source?: string;
|
|
201
|
+
};
|
|
202
|
+
/**
|
|
203
|
+
* Result of fetching events from the store for processing.
|
|
204
|
+
* @template TEvents - Event schemas.
|
|
205
|
+
* @property stream - The stream name
|
|
206
|
+
* @property source - The source stream(s) (name or RegExp), or undefined when sourcing from all streams.
|
|
207
|
+
* @property at - The last event sequence number processed by the stream.
|
|
208
|
+
* @property lagging - Whether the stream is lagging behind.
|
|
209
|
+
* @property events - The list of next committed events to be processed by the stream.
|
|
210
|
+
*/
|
|
211
|
+
export type Fetch<TEvents extends Schemas> = Array<{
|
|
212
|
+
readonly stream: string;
|
|
213
|
+
readonly source?: string;
|
|
214
|
+
readonly at: number;
|
|
215
|
+
readonly lagging: boolean;
|
|
216
|
+
readonly events: Committed<TEvents, keyof TEvents>[];
|
|
217
|
+
}>;
|
|
218
|
+
/**
|
|
219
|
+
* Lease information for distributed stream processing.
|
|
220
|
+
*
|
|
221
|
+
* Leases prevent concurrent processing of the same stream by multiple workers.
|
|
222
|
+
* When a worker acquires a lease, it has exclusive rights to process events
|
|
223
|
+
* for that stream until the lease expires or is acknowledged.
|
|
224
|
+
*
|
|
225
|
+
* The drain process uses leases to:
|
|
226
|
+
* - Prevent race conditions in distributed setups
|
|
227
|
+
* - Track processing progress (watermark)
|
|
228
|
+
* - Manage retries on failures
|
|
229
|
+
* - Balance load between lagging and leading streams
|
|
230
|
+
*
|
|
231
|
+
* @property stream - The target stream name being processed
|
|
232
|
+
* @property source - Optional source stream for filtering
|
|
233
|
+
* @property at - Watermark: last successfully processed event ID
|
|
234
|
+
* @property by - Unique identifier of the lease holder (UUID)
|
|
235
|
+
* @property retry - Number of retry attempts (0 = first attempt)
|
|
236
|
+
* @property lagging - Whether this stream is behind (lagging frontier)
|
|
237
|
+
*
|
|
238
|
+
* @example
|
|
239
|
+
* ```typescript
|
|
240
|
+
* app.on("acked", (leases) => {
|
|
241
|
+
* leases.forEach(lease => {
|
|
242
|
+
* console.log(`Processed ${lease.stream} up to event ${lease.at}`);
|
|
243
|
+
* });
|
|
244
|
+
* });
|
|
245
|
+
*
|
|
246
|
+
* app.on("blocked", (blocked) => {
|
|
247
|
+
* blocked.forEach(({ stream, retry, error }) => {
|
|
248
|
+
* console.error(`Stream ${stream} blocked after ${retry} retries: ${error}`);
|
|
249
|
+
* });
|
|
250
|
+
* });
|
|
251
|
+
* ```
|
|
252
|
+
*
|
|
253
|
+
* @see {@link Drain} for drain cycle results
|
|
254
|
+
*/
|
|
255
|
+
export type Lease = {
|
|
256
|
+
readonly stream: string;
|
|
257
|
+
readonly source?: string;
|
|
258
|
+
readonly at: number;
|
|
259
|
+
readonly by: string;
|
|
260
|
+
readonly retry: number;
|
|
261
|
+
readonly lagging: boolean;
|
|
262
|
+
};
|
|
263
|
+
/**
|
|
264
|
+
* A {@link Lease} augmented with the failure reason that pushed it past
|
|
265
|
+
* its retry budget. Yielded by {@link Drain.blocked}, emitted on the
|
|
266
|
+
* `"blocked"` lifecycle event, and accepted by {@link Store.block}.
|
|
267
|
+
*/
|
|
268
|
+
export type BlockedLease = Lease & {
|
|
269
|
+
readonly error: string;
|
|
270
|
+
};
|
|
271
|
+
/**
|
|
272
|
+
* Options for draining events from the store.
|
|
273
|
+
* @property streamLimit - Maximum number of streams to fetch.
|
|
274
|
+
* @property eventLimit - Maximum number of events to fetch per stream.
|
|
275
|
+
* @property leaseMillis - Maximum lease duration (in milliseconds).
|
|
276
|
+
*/
|
|
277
|
+
export type DrainOptions = {
|
|
278
|
+
readonly streamLimit?: number;
|
|
279
|
+
readonly eventLimit?: number;
|
|
280
|
+
readonly leaseMillis?: number;
|
|
281
|
+
};
|
|
282
|
+
/**
|
|
283
|
+
* Drain results
|
|
284
|
+
* @property fetched - The fetched events.
|
|
285
|
+
* @property leased - The leased events.
|
|
286
|
+
* @property acked - The acked events.
|
|
287
|
+
* @property blocked - The blocked events (with error).
|
|
288
|
+
*/
|
|
289
|
+
export type Drain<TEvents extends Schemas> = {
|
|
290
|
+
readonly fetched: Fetch<TEvents>;
|
|
291
|
+
readonly leased: Lease[];
|
|
292
|
+
readonly acked: Lease[];
|
|
293
|
+
readonly blocked: BlockedLease[];
|
|
294
|
+
};
|
|
295
|
+
/**
|
|
296
|
+
* Options for the debounced settle cycle.
|
|
297
|
+
*
|
|
298
|
+
* Extends {@link DrainOptions} with parameters that control the debounce
|
|
299
|
+
* window, the correlation query, and the maximum number of correlate→drain
|
|
300
|
+
* passes.
|
|
301
|
+
*
|
|
302
|
+
* @property debounceMs - Debounce window in milliseconds (default: 10)
|
|
303
|
+
* @property correlate - Query filter for correlation scans (default: `{ after: -1, limit: 100 }`)
|
|
304
|
+
* @property maxPasses - Cap on correlate→drain loops (default: `Infinity`).
|
|
305
|
+
* Settle exits early as soon as a pass makes no progress (no new
|
|
306
|
+
* subscriptions, no acks, no blocks), so the cap only matters in
|
|
307
|
+
* pathological cases.
|
|
308
|
+
*/
|
|
309
|
+
export type SettleOptions = DrainOptions & {
|
|
310
|
+
readonly debounceMs?: number;
|
|
311
|
+
readonly correlate?: Query;
|
|
312
|
+
readonly maxPasses?: number;
|
|
313
|
+
};
|
|
314
|
+
//# sourceMappingURL=reaction.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
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,IAAI,EACJ,KAAK,EACL,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,IAAI,CAAC,OAAO,EAAE,QAAQ,EAAE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AK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;CAC3B,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,YAAY,GAAG,KAAK,GAAG;IAAE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAE9D;;;;;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,OAAO,SAAS,OAAO,IAAI;IAC3C,QAAQ,CAAC,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;IACjC,QAAQ,CAAC,MAAM,EAAE,KAAK,EAAE,CAAC;IACzB,QAAQ,CAAC,KAAK,EAAE,KAAK,EAAE,CAAC;IACxB,QAAQ,CAAC,OAAO,EAAE,YAAY,EAAE,CAAC;CAClC,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,MAAM,MAAM,aAAa,GAAG,YAAY,GAAG;IACzC,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,SAAS,CAAC,EAAE,KAAK,CAAC;IAC3B,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;CAC7B,CAAC"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { ZodType, z } from "zod";
|
|
2
|
+
import type { CommittedMeta, Schema, Schemas, State } from "./action.js";
|
|
3
|
+
import type { Reaction } from "./reaction.js";
|
|
4
|
+
/**
|
|
5
|
+
* @packageDocumentation
|
|
6
|
+
* @module act/types
|
|
7
|
+
* @category Types
|
|
8
|
+
* Types for event and action registries in the Act Framework.
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Per-event registration: the event's schema plus every reaction
|
|
12
|
+
* registered against it. Keyed by reaction name within the inner map so
|
|
13
|
+
* a single event can fan out to multiple handlers (one per slice or
|
|
14
|
+
* top-level `act().on(...)` call).
|
|
15
|
+
*
|
|
16
|
+
* @template TEvents - Event schemas in the domain
|
|
17
|
+
* @template TKey - Specific event name within `TEvents`
|
|
18
|
+
*/
|
|
19
|
+
export type ReactionsRegister<TEvents extends Schemas, TKey extends keyof TEvents> = {
|
|
20
|
+
schema: ZodType<TEvents[TKey]>;
|
|
21
|
+
reactions: Map<string, Reaction<TEvents, TKey>>;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Maps event names to their schema and registered reactions.
|
|
25
|
+
* @template TEvents - Event schemas.
|
|
26
|
+
*/
|
|
27
|
+
export type EventRegister<TEvents extends Schemas> = {
|
|
28
|
+
[TKey in keyof TEvents]: ReactionsRegister<TEvents, TKey>;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Type-level constraint: every key in the action map must point at a
|
|
32
|
+
* Zod schema. Used as a constraint on the registry's action half so
|
|
33
|
+
* downstream types can `infer` payloads safely.
|
|
34
|
+
*
|
|
35
|
+
* @template TSchemaReg - Schema register for actions
|
|
36
|
+
*/
|
|
37
|
+
export type SchemaRegister<TSchemaReg> = {
|
|
38
|
+
[TKey in keyof TSchemaReg]: Schema;
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Registry of all actions and events for a domain.
|
|
42
|
+
* @template TSchemaReg - State schemas.
|
|
43
|
+
* @template TEvents - Event schemas.
|
|
44
|
+
* @template TActions - Action schemas.
|
|
45
|
+
* @property actions - Map of action names to state definitions.
|
|
46
|
+
* @property events - Map of event names to event registration info.
|
|
47
|
+
*/
|
|
48
|
+
export type Registry<TSchemaReg extends SchemaRegister<TActions>, TEvents extends Schemas, TActions extends Schemas> = {
|
|
49
|
+
readonly actions: {
|
|
50
|
+
[TKey in keyof TActions]: State<TSchemaReg[TKey], TEvents, TActions>;
|
|
51
|
+
};
|
|
52
|
+
readonly events: EventRegister<TEvents>;
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Utility type to convert a registry entry to a committed event type.
|
|
56
|
+
* @template R - Registry map.
|
|
57
|
+
* @template K - Event name.
|
|
58
|
+
*/
|
|
59
|
+
export type AsCommitted<R, K extends keyof R> = R[K] extends {
|
|
60
|
+
schema: infer S;
|
|
61
|
+
} ? {
|
|
62
|
+
readonly name: K;
|
|
63
|
+
readonly data: z.infer<S>;
|
|
64
|
+
} & CommittedMeta : never;
|
|
65
|
+
/**
|
|
66
|
+
* Utility type to map commited events from zod schema maps.
|
|
67
|
+
* @template E - Event map.
|
|
68
|
+
* @template K - Event name.
|
|
69
|
+
*/
|
|
70
|
+
export type CommittedOf<E, K extends keyof E> = E[K] extends z.ZodType ? {
|
|
71
|
+
readonly name: K;
|
|
72
|
+
readonly data: z.infer<E[K]>;
|
|
73
|
+
} & CommittedMeta : never;
|
|
74
|
+
//# sourceMappingURL=registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../../src/types/registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACtC,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;;;;;;;;GAQG;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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C9B,GAAG,aAAa,GACjB,KAAK,CAAC"}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { type ZodObject, type ZodRawShape, z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* @packageDocumentation
|
|
4
|
+
* @module act/types
|
|
5
|
+
* @category Types
|
|
6
|
+
* Zod schemas and helpers for the Act Framework.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* An empty Zod schema (no properties).
|
|
10
|
+
*/
|
|
11
|
+
export declare const ZodEmpty: z.ZodRecord<z.ZodString, z.ZodNever>;
|
|
12
|
+
/**
|
|
13
|
+
* Zod schema for an actor (user, system, etc.).
|
|
14
|
+
*/
|
|
15
|
+
export declare const ActorSchema: z.ZodReadonly<ZodObject<{
|
|
16
|
+
id: z.ZodString;
|
|
17
|
+
name: z.ZodString;
|
|
18
|
+
}, z.core.$loose>>;
|
|
19
|
+
/**
|
|
20
|
+
* Zod schema for a target (stream and actor info).
|
|
21
|
+
*/
|
|
22
|
+
export declare const TargetSchema: z.ZodReadonly<ZodObject<{
|
|
23
|
+
stream: z.ZodString;
|
|
24
|
+
actor: z.ZodReadonly<ZodObject<{
|
|
25
|
+
id: z.ZodString;
|
|
26
|
+
name: z.ZodString;
|
|
27
|
+
}, z.core.$loose>>;
|
|
28
|
+
expectedVersion: z.ZodOptional<z.ZodNumber>;
|
|
29
|
+
}, z.core.$loose>>;
|
|
30
|
+
/**
|
|
31
|
+
* Zod schema for causation event metadata.
|
|
32
|
+
*/
|
|
33
|
+
export declare const CausationEventSchema: ZodObject<{
|
|
34
|
+
id: z.ZodNumber;
|
|
35
|
+
name: z.ZodString;
|
|
36
|
+
stream: z.ZodString;
|
|
37
|
+
}, z.core.$strip>;
|
|
38
|
+
/**
|
|
39
|
+
* Zod schema for event metadata (correlation and causation).
|
|
40
|
+
*/
|
|
41
|
+
export declare const EventMetaSchema: z.ZodReadonly<ZodObject<{
|
|
42
|
+
correlation: z.ZodString;
|
|
43
|
+
causation: ZodObject<{
|
|
44
|
+
action: z.ZodOptional<z.ZodIntersection<z.ZodReadonly<ZodObject<{
|
|
45
|
+
stream: z.ZodString;
|
|
46
|
+
actor: z.ZodReadonly<ZodObject<{
|
|
47
|
+
id: z.ZodString;
|
|
48
|
+
name: z.ZodString;
|
|
49
|
+
}, z.core.$loose>>;
|
|
50
|
+
expectedVersion: z.ZodOptional<z.ZodNumber>;
|
|
51
|
+
}, z.core.$loose>>, ZodObject<{
|
|
52
|
+
name: z.ZodString;
|
|
53
|
+
}, z.core.$strip>>>;
|
|
54
|
+
event: z.ZodOptional<ZodObject<{
|
|
55
|
+
id: z.ZodNumber;
|
|
56
|
+
name: z.ZodString;
|
|
57
|
+
stream: z.ZodString;
|
|
58
|
+
}, z.core.$strip>>;
|
|
59
|
+
}, z.core.$strip>;
|
|
60
|
+
}, z.core.$strip>>;
|
|
61
|
+
/**
|
|
62
|
+
* Zod schema for committed event metadata (id, stream, version, created, meta).
|
|
63
|
+
*/
|
|
64
|
+
export declare const CommittedMetaSchema: z.ZodReadonly<ZodObject<{
|
|
65
|
+
id: z.ZodNumber;
|
|
66
|
+
stream: z.ZodString;
|
|
67
|
+
version: z.ZodNumber;
|
|
68
|
+
created: z.ZodDate;
|
|
69
|
+
meta: z.ZodReadonly<ZodObject<{
|
|
70
|
+
correlation: z.ZodString;
|
|
71
|
+
causation: ZodObject<{
|
|
72
|
+
action: z.ZodOptional<z.ZodIntersection<z.ZodReadonly<ZodObject<{
|
|
73
|
+
stream: z.ZodString;
|
|
74
|
+
actor: z.ZodReadonly<ZodObject<{
|
|
75
|
+
id: z.ZodString;
|
|
76
|
+
name: z.ZodString;
|
|
77
|
+
}, z.core.$loose>>;
|
|
78
|
+
expectedVersion: z.ZodOptional<z.ZodNumber>;
|
|
79
|
+
}, z.core.$loose>>, ZodObject<{
|
|
80
|
+
name: z.ZodString;
|
|
81
|
+
}, z.core.$strip>>>;
|
|
82
|
+
event: z.ZodOptional<ZodObject<{
|
|
83
|
+
id: z.ZodNumber;
|
|
84
|
+
name: z.ZodString;
|
|
85
|
+
stream: z.ZodString;
|
|
86
|
+
}, z.core.$strip>>;
|
|
87
|
+
}, z.core.$strip>;
|
|
88
|
+
}, z.core.$strip>>;
|
|
89
|
+
}, z.core.$strip>>;
|
|
90
|
+
/**
|
|
91
|
+
* Type representing the full state schema for a domain.
|
|
92
|
+
* @property events - Map of event names to Zod schemas.
|
|
93
|
+
* @property actions - Map of action names to Zod schemas.
|
|
94
|
+
* @property state - Zod schema for the state object.
|
|
95
|
+
*/
|
|
96
|
+
export type StateSchema = Readonly<{
|
|
97
|
+
events: Record<string, ZodObject<ZodRawShape> | typeof ZodEmpty>;
|
|
98
|
+
actions: Record<string, ZodObject<ZodRawShape> | typeof ZodEmpty>;
|
|
99
|
+
state: ZodObject<ZodRawShape>;
|
|
100
|
+
}>;
|
|
101
|
+
/**
|
|
102
|
+
* Query options for event store queries.
|
|
103
|
+
*/
|
|
104
|
+
export declare const QuerySchema: z.ZodReadonly<ZodObject<{
|
|
105
|
+
stream: z.ZodOptional<z.ZodString>;
|
|
106
|
+
names: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
107
|
+
before: z.ZodOptional<z.ZodNumber>;
|
|
108
|
+
after: z.ZodOptional<z.ZodNumber>;
|
|
109
|
+
limit: z.ZodOptional<z.ZodNumber>;
|
|
110
|
+
created_before: z.ZodOptional<z.ZodDate>;
|
|
111
|
+
created_after: z.ZodOptional<z.ZodDate>;
|
|
112
|
+
backward: z.ZodOptional<z.ZodBoolean>;
|
|
113
|
+
correlation: z.ZodOptional<z.ZodString>;
|
|
114
|
+
with_snaps: z.ZodOptional<z.ZodBoolean>;
|
|
115
|
+
stream_exact: z.ZodOptional<z.ZodBoolean>;
|
|
116
|
+
}, z.core.$strip>>;
|
|
117
|
+
//# sourceMappingURL=schemas.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../../../src/types/schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,WAAW,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAE1D;;;;;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;;;;;;;;;;;;kBAcX,CAAC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { type ZodType } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* @module utils
|
|
4
|
+
* @category Utilities
|
|
5
|
+
*
|
|
6
|
+
* Small utilities used across the framework:
|
|
7
|
+
* - {@link validate} — parse a payload against a Zod schema, throwing
|
|
8
|
+
* {@link ValidationError} on failure.
|
|
9
|
+
* - {@link extend} — validate a source object and merge into defaults.
|
|
10
|
+
* - {@link sleep} — async delay (default duration from `config().sleepMs`).
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Parse `payload` against `schema`, returning the validated value or throwing
|
|
14
|
+
* a {@link ValidationError} with prettified Zod details. When `schema` is
|
|
15
|
+
* omitted, returns `payload` unchanged. The framework calls this for every
|
|
16
|
+
* `app.do()` action, every emitted event, and every state init.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* const UserSchema = z.object({ email: z.string().email() });
|
|
21
|
+
* const user = validate("User", { email: "alice@example.com" }, UserSchema);
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* @see {@link ValidationError}
|
|
25
|
+
*/
|
|
26
|
+
export declare const validate: <S>(target: string, payload: Readonly<S>, schema?: ZodType<S>) => Readonly<S>;
|
|
27
|
+
/**
|
|
28
|
+
* Validate `source` against `schema` and return a new object that merges
|
|
29
|
+
* `source` over the optional `target` defaults. Used by {@link config} for
|
|
30
|
+
* env-var-overrides-defaults patterns; safe to call elsewhere — it never
|
|
31
|
+
* mutates `target`.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```typescript
|
|
35
|
+
* const schema = z.object({ host: z.string(), port: z.number() });
|
|
36
|
+
* const cfg = extend({ port: 8080 }, schema, { host: "localhost", port: 80 });
|
|
37
|
+
* // → { host: "localhost", port: 8080 }
|
|
38
|
+
* ```
|
|
39
|
+
*
|
|
40
|
+
* @throws {@link ValidationError} if `source` fails the schema.
|
|
41
|
+
*/
|
|
42
|
+
export declare const extend: <S extends Record<string, unknown>, T extends Record<string, unknown>>(source: Readonly<S>, schema: ZodType<S>, target?: Readonly<T>) => Readonly<S & T>;
|
|
43
|
+
/**
|
|
44
|
+
* Pause for `ms` milliseconds (or `config().sleepMs` when omitted — `100ms`
|
|
45
|
+
* in dev, `0ms` in tests). Used by adapters to simulate async I/O.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```typescript
|
|
49
|
+
* await sleep(); // default delay from config
|
|
50
|
+
* await sleep(500); // explicit 500ms
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
export declare function sleep(ms?: number): Promise<unknown>;
|
|
54
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAA2B,KAAK,OAAO,EAAE,MAAM,KAAK,CAAC;AAI5D;;;;;;;;;GASG;AAEH;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,QAAQ,GAAI,CAAC,EACxB,QAAQ,MAAM,EACd,SAAS,QAAQ,CAAC,CAAC,CAAC,EACpB,SAAS,OAAO,CAAC,CAAC,CAAC,KAClB,QAAQ,CAAC,CAAC,CASZ,CAAC;AAEF;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,MAAM,GACjB,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACjC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAEjC,QAAQ,QAAQ,CAAC,CAAC,CAAC,EACnB,QAAQ,OAAO,CAAC,CAAC,CAAC,EAClB,SAAS,QAAQ,CAAC,CAAC,CAAC,KACnB,QAAQ,CAAC,CAAC,GAAG,CAAC,CAGhB,CAAC;AAEF;;;;;;;;;GASG;AACH,wBAAsB,KAAK,CAAC,EAAE,CAAC,EAAE,MAAM,oBAEtC"}
|