@rotorsoft/act 0.33.3 → 0.35.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.
Files changed (83) hide show
  1. package/README.md +53 -2
  2. package/package.json +5 -2
  3. package/dist/.tsbuildinfo +0 -1
  4. package/dist/@types/act.d.ts +0 -598
  5. package/dist/@types/act.d.ts.map +0 -1
  6. package/dist/@types/adapters/console-logger.d.ts +0 -41
  7. package/dist/@types/adapters/console-logger.d.ts.map +0 -1
  8. package/dist/@types/adapters/in-memory-cache.d.ts +0 -34
  9. package/dist/@types/adapters/in-memory-cache.d.ts.map +0 -1
  10. package/dist/@types/adapters/in-memory-store.d.ts +0 -181
  11. package/dist/@types/adapters/in-memory-store.d.ts.map +0 -1
  12. package/dist/@types/adapters/index.d.ts +0 -4
  13. package/dist/@types/adapters/index.d.ts.map +0 -1
  14. package/dist/@types/builders/act-builder.d.ts +0 -160
  15. package/dist/@types/builders/act-builder.d.ts.map +0 -1
  16. package/dist/@types/builders/index.d.ts +0 -13
  17. package/dist/@types/builders/index.d.ts.map +0 -1
  18. package/dist/@types/builders/projection-builder.d.ts +0 -101
  19. package/dist/@types/builders/projection-builder.d.ts.map +0 -1
  20. package/dist/@types/builders/slice-builder.d.ts +0 -109
  21. package/dist/@types/builders/slice-builder.d.ts.map +0 -1
  22. package/dist/@types/builders/state-builder.d.ts +0 -424
  23. package/dist/@types/builders/state-builder.d.ts.map +0 -1
  24. package/dist/@types/config.d.ts +0 -119
  25. package/dist/@types/config.d.ts.map +0 -1
  26. package/dist/@types/index.d.ts +0 -14
  27. package/dist/@types/index.d.ts.map +0 -1
  28. package/dist/@types/internal/build-classify.d.ts +0 -44
  29. package/dist/@types/internal/build-classify.d.ts.map +0 -1
  30. package/dist/@types/internal/close-cycle.d.ts +0 -38
  31. package/dist/@types/internal/close-cycle.d.ts.map +0 -1
  32. package/dist/@types/internal/correlate-cycle.d.ts +0 -73
  33. package/dist/@types/internal/correlate-cycle.d.ts.map +0 -1
  34. package/dist/@types/internal/drain-cycle.d.ts +0 -113
  35. package/dist/@types/internal/drain-cycle.d.ts.map +0 -1
  36. package/dist/@types/internal/drain-ratio.d.ts +0 -26
  37. package/dist/@types/internal/drain-ratio.d.ts.map +0 -1
  38. package/dist/@types/internal/drain.d.ts +0 -41
  39. package/dist/@types/internal/drain.d.ts.map +0 -1
  40. package/dist/@types/internal/event-sourcing.d.ts +0 -96
  41. package/dist/@types/internal/event-sourcing.d.ts.map +0 -1
  42. package/dist/@types/internal/index.d.ts +0 -29
  43. package/dist/@types/internal/index.d.ts.map +0 -1
  44. package/dist/@types/internal/merge.d.ts +0 -31
  45. package/dist/@types/internal/merge.d.ts.map +0 -1
  46. package/dist/@types/internal/reactions.d.ts +0 -54
  47. package/dist/@types/internal/reactions.d.ts.map +0 -1
  48. package/dist/@types/internal/settle.d.ts +0 -60
  49. package/dist/@types/internal/settle.d.ts.map +0 -1
  50. package/dist/@types/internal/tracing.d.ts +0 -45
  51. package/dist/@types/internal/tracing.d.ts.map +0 -1
  52. package/dist/@types/lru-map.d.ts +0 -50
  53. package/dist/@types/lru-map.d.ts.map +0 -1
  54. package/dist/@types/ports.d.ts +0 -196
  55. package/dist/@types/ports.d.ts.map +0 -1
  56. package/dist/@types/signals.d.ts +0 -2
  57. package/dist/@types/signals.d.ts.map +0 -1
  58. package/dist/@types/types/action.d.ts +0 -444
  59. package/dist/@types/types/action.d.ts.map +0 -1
  60. package/dist/@types/types/errors.d.ts +0 -284
  61. package/dist/@types/types/errors.d.ts.map +0 -1
  62. package/dist/@types/types/index.d.ts +0 -39
  63. package/dist/@types/types/index.d.ts.map +0 -1
  64. package/dist/@types/types/ports.d.ts +0 -485
  65. package/dist/@types/types/ports.d.ts.map +0 -1
  66. package/dist/@types/types/reaction.d.ts +0 -291
  67. package/dist/@types/types/reaction.d.ts.map +0 -1
  68. package/dist/@types/types/registry.d.ts +0 -74
  69. package/dist/@types/types/registry.d.ts.map +0 -1
  70. package/dist/@types/types/schemas.d.ts +0 -117
  71. package/dist/@types/types/schemas.d.ts.map +0 -1
  72. package/dist/@types/utils.d.ts +0 -54
  73. package/dist/@types/utils.d.ts.map +0 -1
  74. package/dist/chunk-AGWZY6YT.js +0 -127
  75. package/dist/chunk-AGWZY6YT.js.map +0 -1
  76. package/dist/index.cjs +0 -2985
  77. package/dist/index.cjs.map +0 -1
  78. package/dist/index.js +0 -2816
  79. package/dist/index.js.map +0 -1
  80. package/dist/types/index.cjs +0 -166
  81. package/dist/types/index.cjs.map +0 -1
  82. package/dist/types/index.js +0 -33
  83. package/dist/types/index.js.map +0 -1
@@ -1,291 +0,0 @@
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.
53
- *
54
- * @template TEvents - Event schemas
55
- * @template TKey - Event name
56
- * @param event - The committed event (for dynamic resolvers)
57
- * @returns Target stream configuration or undefined to skip
58
- *
59
- * @example Static target
60
- * ```typescript
61
- * .on("UserCreated")
62
- * .do(sendWelcomeEmail)
63
- * .to("email-queue") // Static target
64
- * ```
65
- *
66
- * @example Dynamic target per user
67
- * ```typescript
68
- * .on("UserLoggedIn")
69
- * .do(incrementLoginCount)
70
- * .to((event) => ({
71
- * target: `stats-${event.stream}` // Dynamic per user
72
- * }))
73
- * ```
74
- *
75
- * @example With source optimization
76
- * ```typescript
77
- * .on("UserUpdated")
78
- * .do(updateReadModel)
79
- * .to(({ stream }) => ({
80
- * source: stream, // Only fetch from this user's stream
81
- * target: `cache-${stream}` // Update corresponding cache
82
- * }))
83
- * ```
84
- *
85
- * @see {@link Reaction} for complete reaction configuration
86
- */
87
- export type ReactionResolver<TEvents extends Schemas, TKey extends keyof TEvents> = {
88
- target: string;
89
- source?: string;
90
- } | ((event: Committed<TEvents, TKey>) => {
91
- target: string;
92
- source?: string;
93
- } | undefined);
94
- /**
95
- * Options for reaction processing.
96
- * @property blockOnError - Whether to block on error.
97
- * @property maxRetries - Maximum number of retries.
98
- */
99
- export type ReactionOptions = {
100
- readonly blockOnError: boolean;
101
- readonly maxRetries: number;
102
- };
103
- /**
104
- * Distributive mapped type that produces a proper discriminated union of
105
- * committed events. Unlike `Committed<TEvents, keyof TEvents>` (where
106
- * `name` and `data` are independent unions), each variant correlates
107
- * `name` with its corresponding `data` — enabling `switch (event.name)`
108
- * to narrow both fields correctly.
109
- *
110
- * @template TEvents - Event schemas
111
- *
112
- * @example Exhaustive switch
113
- * ```typescript
114
- * for (const event of events) {
115
- * switch (event.name) {
116
- * case "TicketOpened":
117
- * event.data; // typed as TicketOpened's schema
118
- * break;
119
- * case "TicketClosed":
120
- * event.data; // typed as TicketClosed's schema
121
- * break;
122
- * default:
123
- * const _: never = event; // compile error if a case is missing
124
- * }
125
- * }
126
- * ```
127
- */
128
- export type BatchEvent<TEvents extends Schemas> = {
129
- [K in keyof TEvents]: Committed<TEvents, K>;
130
- }[keyof TEvents];
131
- /**
132
- * Batch handler for projections that processes multiple events in a single call.
133
- *
134
- * Receives the full ordered array of all event types declared on the projection,
135
- * enabling bulk DB operations (batch INSERT/UPDATE) in a single transaction.
136
- * The handler is always called when defined — even for a single event.
137
- *
138
- * @template TEvents - Event schemas (all events declared on the projection)
139
- * @param events - Ordered array of committed events (discriminated union)
140
- * @param stream - The target stream name
141
- *
142
- * @see {@link BatchEvent} for the discriminated union type
143
- */
144
- export type BatchHandler<TEvents extends Schemas> = (events: ReadonlyArray<BatchEvent<TEvents>>, stream: string) => Promise<void>;
145
- /**
146
- * Defines a reaction to an event.
147
- * @template TEvents - Event schemas.
148
- * @template TKey - Event name.
149
- * @template TActions - Action schemas.
150
- * @template TActor - Actor type extending base Actor.
151
- * @property handler - The reaction handler.
152
- * @property resolver - The reaction resolver.
153
- * @property options - The reaction options.
154
- */
155
- export type Reaction<TEvents extends Schemas, TKey extends keyof TEvents = keyof TEvents, TActions extends Schemas = Schemas, TActor extends Actor = Actor> = {
156
- readonly handler: ReactionHandler<TEvents, TKey, TActions, TActor>;
157
- /**
158
- * Mutable so the builder's `.do()` → `.to()` chain can patch the resolver
159
- * in place (registered once with the default `_this_` resolver in `.do()`,
160
- * overwritten in `.to()` if present). After build-time the field is
161
- * effectively immutable; runtime consumers only read it.
162
- */
163
- resolver: ReactionResolver<TEvents, TKey>;
164
- readonly options: ReactionOptions;
165
- };
166
- /**
167
- * Payload for a reaction.
168
- * @template TEvents - Event schemas.
169
- * @property handler - The reaction handler.
170
- * @property resolver - The reaction resolver.
171
- * @property options - The reaction options.
172
- * @property event - The committed event triggering the reaction.
173
- * @property source - The source stream.
174
- */
175
- export type ReactionPayload<TEvents extends Schemas> = Reaction<TEvents> & {
176
- readonly event: Committed<TEvents, keyof TEvents>;
177
- readonly source?: string;
178
- };
179
- /**
180
- * Result of fetching events from the store for processing.
181
- * @template TEvents - Event schemas.
182
- * @property stream - The stream name
183
- * @property source - The source stream(s) (name or RegExp), or undefined when sourcing from all streams.
184
- * @property at - The last event sequence number processed by the stream.
185
- * @property lagging - Whether the stream is lagging behind.
186
- * @property events - The list of next committed events to be processed by the stream.
187
- */
188
- export type Fetch<TEvents extends Schemas> = Array<{
189
- readonly stream: string;
190
- readonly source?: string;
191
- readonly at: number;
192
- readonly lagging: boolean;
193
- readonly events: Committed<TEvents, keyof TEvents>[];
194
- }>;
195
- /**
196
- * Lease information for distributed stream processing.
197
- *
198
- * Leases prevent concurrent processing of the same stream by multiple workers.
199
- * When a worker acquires a lease, it has exclusive rights to process events
200
- * for that stream until the lease expires or is acknowledged.
201
- *
202
- * The drain process uses leases to:
203
- * - Prevent race conditions in distributed setups
204
- * - Track processing progress (watermark)
205
- * - Manage retries on failures
206
- * - Balance load between lagging and leading streams
207
- *
208
- * @property stream - The target stream name being processed
209
- * @property source - Optional source stream for filtering
210
- * @property at - Watermark: last successfully processed event ID
211
- * @property by - Unique identifier of the lease holder (UUID)
212
- * @property retry - Number of retry attempts (0 = first attempt)
213
- * @property lagging - Whether this stream is behind (lagging frontier)
214
- *
215
- * @example
216
- * ```typescript
217
- * app.on("acked", (leases) => {
218
- * leases.forEach(lease => {
219
- * console.log(`Processed ${lease.stream} up to event ${lease.at}`);
220
- * });
221
- * });
222
- *
223
- * app.on("blocked", (blocked) => {
224
- * blocked.forEach(({ stream, retry, error }) => {
225
- * console.error(`Stream ${stream} blocked after ${retry} retries: ${error}`);
226
- * });
227
- * });
228
- * ```
229
- *
230
- * @see {@link Drain} for drain cycle results
231
- */
232
- export type Lease = {
233
- readonly stream: string;
234
- readonly source?: string;
235
- readonly at: number;
236
- readonly by: string;
237
- readonly retry: number;
238
- readonly lagging: boolean;
239
- };
240
- /**
241
- * A {@link Lease} augmented with the failure reason that pushed it past
242
- * its retry budget. Yielded by {@link Drain.blocked}, emitted on the
243
- * `"blocked"` lifecycle event, and accepted by {@link Store.block}.
244
- */
245
- export type BlockedLease = Lease & {
246
- readonly error: string;
247
- };
248
- /**
249
- * Options for draining events from the store.
250
- * @property streamLimit - Maximum number of streams to fetch.
251
- * @property eventLimit - Maximum number of events to fetch per stream.
252
- * @property leaseMillis - Maximum lease duration (in milliseconds).
253
- */
254
- export type DrainOptions = {
255
- readonly streamLimit?: number;
256
- readonly eventLimit?: number;
257
- readonly leaseMillis?: number;
258
- };
259
- /**
260
- * Drain results
261
- * @property fetched - The fetched events.
262
- * @property leased - The leased events.
263
- * @property acked - The acked events.
264
- * @property blocked - The blocked events (with error).
265
- */
266
- export type Drain<TEvents extends Schemas> = {
267
- readonly fetched: Fetch<TEvents>;
268
- readonly leased: Lease[];
269
- readonly acked: Lease[];
270
- readonly blocked: BlockedLease[];
271
- };
272
- /**
273
- * Options for the debounced settle cycle.
274
- *
275
- * Extends {@link DrainOptions} with parameters that control the debounce
276
- * window, the correlation query, and the maximum number of correlate→drain
277
- * passes.
278
- *
279
- * @property debounceMs - Debounce window in milliseconds (default: 10)
280
- * @property correlate - Query filter for correlation scans (default: `{ after: -1, limit: 100 }`)
281
- * @property maxPasses - Cap on correlate→drain loops (default: `Infinity`).
282
- * Settle exits early as soon as a pass makes no progress (no new
283
- * subscriptions, no acks, no blocks), so the cap only matters in
284
- * pathological cases.
285
- */
286
- export type SettleOptions = DrainOptions & {
287
- readonly debounceMs?: number;
288
- readonly correlate?: Query;
289
- readonly maxPasses?: number;
290
- };
291
- //# sourceMappingURL=reaction.d.ts.map
@@ -1 +0,0 @@
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,MAAM,CAAC,KACjC,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;AAE1D;;;;GAIG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B,QAAQ,CAAC,YAAY,EAAE,OAAO,CAAC;IAC/B,QAAQ,CAAC,UAAU,E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AEF;;;;;;;;;;;;;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"}
@@ -1,74 +0,0 @@
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
@@ -1 +0,0 @@
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,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,aAAa,CAAC,OAAO,SAAS,OAAO,IAAI;KAClD,IAAI,IAAI,MAAM,OAAO,GAAG,iBAAiB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* @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
@@ -1 +0,0 @@
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"}
@@ -1,54 +0,0 @@
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
@@ -1 +0,0 @@
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"}
@@ -1,127 +0,0 @@
1
- // src/types/errors.ts
2
- var Errors = {
3
- ValidationError: "ERR_VALIDATION",
4
- InvariantError: "ERR_INVARIANT",
5
- ConcurrencyError: "ERR_CONCURRENCY",
6
- StreamClosedError: "ERR_STREAM_CLOSED"
7
- };
8
- var ValidationError = class extends Error {
9
- constructor(target, payload, details) {
10
- super(`Invalid ${target} payload`);
11
- this.target = target;
12
- this.payload = payload;
13
- this.details = details;
14
- this.name = Errors.ValidationError;
15
- }
16
- };
17
- var InvariantError = class extends Error {
18
- constructor(action, payload, target, snapshot, description) {
19
- super(`${action} failed invariant: ${description}`);
20
- this.action = action;
21
- this.payload = payload;
22
- this.target = target;
23
- this.snapshot = snapshot;
24
- this.description = description;
25
- this.name = Errors.InvariantError;
26
- }
27
- };
28
- var ConcurrencyError = class extends Error {
29
- constructor(stream, lastVersion, events, expectedVersion) {
30
- super(
31
- `Concurrency error committing "${events.map((e) => `${stream}.${e.name}`).join(
32
- ", "
33
- )}". Expected version ${expectedVersion} but found version ${lastVersion}.`
34
- );
35
- this.stream = stream;
36
- this.lastVersion = lastVersion;
37
- this.events = events;
38
- this.expectedVersion = expectedVersion;
39
- this.name = Errors.ConcurrencyError;
40
- }
41
- };
42
- var StreamClosedError = class extends Error {
43
- constructor(stream) {
44
- super(`Stream "${stream}" is closed (tombstoned)`);
45
- this.stream = stream;
46
- this.name = Errors.StreamClosedError;
47
- }
48
- };
49
-
50
- // src/types/schemas.ts
51
- import { z } from "zod";
52
- var ZodEmpty = z.record(z.string(), z.never());
53
- var ActorSchema = z.object({
54
- id: z.string(),
55
- name: z.string()
56
- }).loose().readonly();
57
- var TargetSchema = z.object({
58
- stream: z.string(),
59
- actor: ActorSchema,
60
- expectedVersion: z.number().optional()
61
- }).loose().readonly();
62
- var CausationEventSchema = z.object({
63
- id: z.number(),
64
- name: z.string(),
65
- stream: z.string()
66
- });
67
- var EventMetaSchema = z.object({
68
- correlation: z.string(),
69
- causation: z.object({
70
- action: TargetSchema.and(z.object({ name: z.string() })).optional(),
71
- event: CausationEventSchema.optional()
72
- })
73
- }).readonly();
74
- var CommittedMetaSchema = z.object({
75
- id: z.number(),
76
- stream: z.string(),
77
- version: z.number(),
78
- created: z.date(),
79
- meta: EventMetaSchema
80
- }).readonly();
81
- var QuerySchema = z.object({
82
- stream: z.string().optional(),
83
- names: z.string().array().optional(),
84
- before: z.number().optional(),
85
- after: z.number().optional(),
86
- limit: z.number().optional(),
87
- created_before: z.date().optional(),
88
- created_after: z.date().optional(),
89
- backward: z.boolean().optional(),
90
- correlation: z.string().optional(),
91
- with_snaps: z.boolean().optional(),
92
- stream_exact: z.boolean().optional()
93
- }).readonly();
94
-
95
- // src/types/index.ts
96
- var Environments = [
97
- "development",
98
- "test",
99
- "staging",
100
- "production"
101
- ];
102
- var LogLevels = [
103
- "fatal",
104
- "error",
105
- "warn",
106
- "info",
107
- "debug",
108
- "trace"
109
- ];
110
-
111
- export {
112
- Errors,
113
- ValidationError,
114
- InvariantError,
115
- ConcurrencyError,
116
- StreamClosedError,
117
- ZodEmpty,
118
- ActorSchema,
119
- TargetSchema,
120
- CausationEventSchema,
121
- EventMetaSchema,
122
- CommittedMetaSchema,
123
- QuerySchema,
124
- Environments,
125
- LogLevels
126
- };
127
- //# sourceMappingURL=chunk-AGWZY6YT.js.map