@rotorsoft/act 0.33.3 → 0.34.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 +26 -2
  2. package/package.json +1 -1
  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,284 +0,0 @@
1
- import type { Actor, Message, Schema, Schemas, Snapshot, Target } from "./action.js";
2
- /**
3
- * @packageDocumentation
4
- * @module act/types
5
- * @category Types
6
- * Application error type constants and error classes for the Act Framework.
7
- *
8
- * - `ERR_VALIDATION`: Schema validation error
9
- * - `ERR_INVARIANT`: Invariant validation error
10
- * - `ERR_CONCURRENCY`: Optimistic concurrency validation error on commits
11
- */
12
- export declare const Errors: {
13
- readonly ValidationError: "ERR_VALIDATION";
14
- readonly InvariantError: "ERR_INVARIANT";
15
- readonly ConcurrencyError: "ERR_CONCURRENCY";
16
- readonly StreamClosedError: "ERR_STREAM_CLOSED";
17
- };
18
- /**
19
- * Thrown when an action or event payload fails Zod schema validation.
20
- *
21
- * This error indicates that data doesn't match the expected schema defined
22
- * for an action or event. The `details` property contains the Zod validation
23
- * error with specific information about what failed.
24
- *
25
- * @example Catching validation errors
26
- * ```typescript
27
- * import { ValidationError } from "@rotorsoft/act";
28
- *
29
- * try {
30
- * await app.do("createUser", target, {
31
- * email: "invalid-email", // Missing @ symbol
32
- * age: -5 // Negative age
33
- * });
34
- * } catch (error) {
35
- * if (error instanceof ValidationError) {
36
- * console.error("Validation failed for:", error.target);
37
- * console.error("Invalid payload:", error.payload);
38
- * console.error("Validation details:", error.details);
39
- * // details contains Zod error with field-level info
40
- * }
41
- * }
42
- * ```
43
- *
44
- * @example Logging validation details
45
- * ```typescript
46
- * try {
47
- * await app.do("updateProfile", target, payload);
48
- * } catch (error) {
49
- * if (error instanceof ValidationError) {
50
- * error.details.errors.forEach((err) => {
51
- * console.error(`Field ${err.path.join(".")}: ${err.message}`);
52
- * });
53
- * }
54
- * }
55
- * ```
56
- *
57
- * @see {@link https://zod.dev | Zod documentation} for validation details
58
- */
59
- export declare class ValidationError extends Error {
60
- /** The type of target being validated (e.g., "action", "event") */
61
- readonly target: string;
62
- /** The invalid payload that failed validation */
63
- readonly payload: any;
64
- /** Zod validation error details */
65
- readonly details: any;
66
- constructor(
67
- /** The type of target being validated (e.g., "action", "event") */
68
- target: string,
69
- /** The invalid payload that failed validation */
70
- payload: any,
71
- /** Zod validation error details */
72
- details: any);
73
- }
74
- /**
75
- * Thrown when a business rule (invariant) is violated during action execution.
76
- *
77
- * Invariants are conditions that must hold true for an action to succeed.
78
- * They're checked after loading the current state but before emitting events.
79
- * This error provides complete context about what action was attempted and
80
- * why it was rejected.
81
- *
82
- * @template TState - State schema type
83
- * @template TEvents - Event schemas type
84
- * @template TActions - Action schemas type
85
- * @template TKey - Action name
86
- * @template TActor - Actor type extending base Actor
87
- *
88
- * @example Catching invariant violations
89
- * ```typescript
90
- * import { InvariantError } from "@rotorsoft/act";
91
- *
92
- * try {
93
- * await app.do("withdraw",
94
- * { stream: "account-123", actor: { id: "user1", name: "Alice" } },
95
- * { amount: 1000 }
96
- * );
97
- * } catch (error) {
98
- * if (error instanceof InvariantError) {
99
- * console.error("Action:", error.action);
100
- * console.error("Reason:", error.description);
101
- * console.error("Current state:", error.snapshot.state);
102
- * console.error("Attempted payload:", error.payload);
103
- * }
104
- * }
105
- * ```
106
- *
107
- * @example User-friendly error messages
108
- * ```typescript
109
- * try {
110
- * await app.do("closeTicket", target, payload);
111
- * } catch (error) {
112
- * if (error instanceof InvariantError) {
113
- * // Present friendly message to user
114
- * if (error.description === "Ticket must be open") {
115
- * return { error: "This ticket is already closed" };
116
- * } else if (error.description === "Not authorized") {
117
- * return { error: "You don't have permission to close this ticket" };
118
- * }
119
- * }
120
- * }
121
- * ```
122
- *
123
- * @example Logging with context
124
- * ```typescript
125
- * try {
126
- * await app.do("transfer", target, { to: "account2", amount: 500 });
127
- * } catch (error) {
128
- * if (error instanceof InvariantError) {
129
- * logger.error({
130
- * action: error.action,
131
- * stream: error.target.stream,
132
- * actor: error.target.actor,
133
- * reason: error.description,
134
- * balance: error.snapshot.state.balance,
135
- * attempted: error.payload.amount
136
- * }, "Invariant violation");
137
- * }
138
- * }
139
- * ```
140
- *
141
- * @see {@link Invariant} for defining business rules
142
- */
143
- export declare class InvariantError<TState extends Schema, TEvents extends Schemas, TActions extends Schemas, TKey extends keyof TActions, TActor extends Actor = Actor> extends Error {
144
- /** The action that was attempted */
145
- readonly action: TKey;
146
- /** The action payload that was provided */
147
- readonly payload: Readonly<TActions[TKey]>;
148
- /** The target stream and actor context */
149
- readonly target: Target<TActor>;
150
- /** The current state snapshot when invariant was checked */
151
- readonly snapshot: Snapshot<TState, TEvents>;
152
- /** Human-readable description of why the invariant failed */
153
- readonly description: string;
154
- constructor(
155
- /** The action that was attempted */
156
- action: TKey,
157
- /** The action payload that was provided */
158
- payload: Readonly<TActions[TKey]>,
159
- /** The target stream and actor context */
160
- target: Target<TActor>,
161
- /** The current state snapshot when invariant was checked */
162
- snapshot: Snapshot<TState, TEvents>,
163
- /** Human-readable description of why the invariant failed */
164
- description: string);
165
- }
166
- /**
167
- * Thrown when optimistic concurrency control detects a conflict.
168
- *
169
- * This error occurs when trying to commit events to a stream that has been
170
- * modified by another process since it was last loaded. The version number
171
- * doesn't match expectations, indicating a concurrent modification.
172
- *
173
- * This is a normal occurrence in distributed systems and should be handled
174
- * by reloading the current state and retrying the action.
175
- *
176
- * @example Handling concurrency conflicts with retry
177
- * ```typescript
178
- * import { ConcurrencyError } from "@rotorsoft/act";
179
- *
180
- * async function transferWithRetry(from, to, amount, maxRetries = 3) {
181
- * for (let attempt = 0; attempt < maxRetries; attempt++) {
182
- * try {
183
- * await app.do("transfer",
184
- * { stream: from, actor: currentUser },
185
- * { to, amount }
186
- * );
187
- * return { success: true };
188
- * } catch (error) {
189
- * if (error instanceof ConcurrencyError) {
190
- * if (attempt < maxRetries - 1) {
191
- * console.log(`Concurrent modification detected, retrying... (${attempt + 1}/${maxRetries})`);
192
- * await sleep(100 * Math.pow(2, attempt)); // Exponential backoff
193
- * continue;
194
- * }
195
- * }
196
- * throw error;
197
- * }
198
- * }
199
- * return { success: false, reason: "Too many concurrent modifications" };
200
- * }
201
- * ```
202
- *
203
- * @example Logging concurrency conflicts
204
- * ```typescript
205
- * try {
206
- * await app.do("updateInventory", target, payload);
207
- * } catch (error) {
208
- * if (error instanceof ConcurrencyError) {
209
- * logger.warn({
210
- * stream: error.stream,
211
- * expectedVersion: error.expectedVersion,
212
- * actualVersion: error.lastVersion,
213
- * events: error.events.map(e => e.name)
214
- * }, "Concurrent modification detected");
215
- * }
216
- * }
217
- * ```
218
- *
219
- * @example User feedback for conflicts
220
- * ```typescript
221
- * try {
222
- * await app.do("editDocument", target, { content: newContent });
223
- * } catch (error) {
224
- * if (error instanceof ConcurrencyError) {
225
- * return {
226
- * error: "This document was modified by another user. Please refresh and try again.",
227
- * code: "CONCURRENT_MODIFICATION"
228
- * };
229
- * }
230
- * }
231
- * ```
232
- *
233
- * @see {@link Store.commit} for version checking details
234
- */
235
- export declare class ConcurrencyError extends Error {
236
- /** The stream that had the concurrent modification */
237
- readonly stream: string;
238
- /** The actual current version in the store */
239
- readonly lastVersion: number;
240
- /** The events that were being committed */
241
- readonly events: Message<Schemas, keyof Schemas>[];
242
- /** The version number that was expected */
243
- readonly expectedVersion: number;
244
- constructor(
245
- /** The stream that had the concurrent modification */
246
- stream: string,
247
- /** The actual current version in the store */
248
- lastVersion: number,
249
- /** The events that were being committed */
250
- events: Message<Schemas, keyof Schemas>[],
251
- /** The version number that was expected */
252
- expectedVersion: number);
253
- }
254
- /**
255
- * Thrown when attempting to write to a stream that has been closed
256
- * with a tombstone event.
257
- *
258
- * A tombstoned stream is permanently closed — no further actions can
259
- * be executed against it. The only way to reopen a tombstoned stream
260
- * is through `Act.close()` with a `restart` callback.
261
- *
262
- * @example
263
- * ```typescript
264
- * import { StreamClosedError } from "@rotorsoft/act";
265
- *
266
- * try {
267
- * await app.do("updateTicket", target, payload);
268
- * } catch (error) {
269
- * if (error instanceof StreamClosedError) {
270
- * console.error(`Stream ${error.stream} is closed`);
271
- * }
272
- * }
273
- * ```
274
- *
275
- * @see {@link Act.close} for closing streams
276
- */
277
- export declare class StreamClosedError extends Error {
278
- /** The stream that is closed */
279
- readonly stream: string;
280
- constructor(
281
- /** The stream that is closed */
282
- stream: string);
283
- }
284
- //# sourceMappingURL=errors.d.ts.map
@@ -1 +0,0 @@
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;;;;;CAKT,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,O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,EAAE,MAAM,OAAO,CAAC,EAAE;IACzD,2CAA2C;IAC3B,eAAe,EAAE,MAAM;CAe1C;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,qBAAa,iBAAkB,SAAQ,KAAK;IAExC,gCAAgC;aAChB,MAAM,EAAE,MAAM;;IAD9B,gCAAgC;IAChB,MAAM,EAAE,MAAM;CAKjC"}
@@ -1,39 +0,0 @@
1
- /**
2
- * @packageDocumentation
3
- * @module act/types
4
- * Barrel file for Act Framework core types.
5
- *
6
- * Re-exports all major type definitions for actions, errors, ports, reactions, registries, and schemas.
7
- * Also defines common environment and log level types/constants for configuration and logging.
8
- *
9
- * @remarks
10
- * Import from this module to access all core framework types in one place.
11
- */
12
- export type * from "./action.js";
13
- export * from "./errors.js";
14
- export type * from "./ports.js";
15
- export type * from "./reaction.js";
16
- export type * from "./registry.js";
17
- export * from "./schemas.js";
18
- /**
19
- * Supported runtime environments for the framework.
20
- * - `development`: Local development
21
- * - `test`: Automated testing
22
- * - `staging`: Pre-production
23
- * - `production`: Live/production
24
- */
25
- export declare const Environments: readonly ["development", "test", "staging", "production"];
26
- /**
27
- * Type representing a valid environment string.
28
- */
29
- export type Environment = (typeof Environments)[number];
30
- /**
31
- * Supported log levels for framework logging.
32
- * - `fatal`, `error`, `warn`, `info`, `debug`, `trace`
33
- */
34
- export declare const LogLevels: readonly ["fatal", "error", "warn", "info", "debug", "trace"];
35
- /**
36
- * Type representing a valid log level string.
37
- */
38
- export type LogLevel = (typeof LogLevels)[number];
39
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/types/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,mBAAmB,aAAa,CAAC;AACjC,cAAc,aAAa,CAAC;AAC5B,mBAAmB,YAAY,CAAC;AAChC,mBAAmB,eAAe,CAAC;AACnC,mBAAmB,eAAe,CAAC;AACnC,cAAc,cAAc,CAAC;AAE7B;;;;;;GAMG;AACH,eAAO,MAAM,YAAY,2DAKf,CAAC;AAEX;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,YAAY,CAAC,CAAC,MAAM,CAAC,CAAC;AAExD;;;GAGG;AACH,eAAO,MAAM,SAAS,+DAOZ,CAAC;AAEX;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG,CAAC,OAAO,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC"}