@rotorsoft/act 0.19.1 → 0.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +44 -13
- package/dist/.tsbuildinfo +1 -1
- package/dist/@types/act.d.ts +2 -2
- package/dist/@types/act.d.ts.map +1 -1
- package/dist/@types/adapters/InMemoryCache.d.ts +29 -0
- package/dist/@types/adapters/InMemoryCache.d.ts.map +1 -0
- package/dist/@types/adapters/InMemoryStore.d.ts +15 -15
- package/dist/@types/adapters/InMemoryStore.d.ts.map +1 -1
- package/dist/@types/adapters/index.d.ts +3 -0
- package/dist/@types/adapters/index.d.ts.map +1 -0
- package/dist/@types/event-sourcing.d.ts +4 -0
- package/dist/@types/event-sourcing.d.ts.map +1 -1
- package/dist/@types/index.d.ts +1 -0
- package/dist/@types/index.d.ts.map +1 -1
- package/dist/@types/ports.d.ts +18 -2
- package/dist/@types/ports.d.ts.map +1 -1
- package/dist/@types/types/ports.d.ts +75 -48
- package/dist/@types/types/ports.d.ts.map +1 -1
- package/dist/@types/types/reaction.d.ts +0 -13
- package/dist/@types/types/reaction.d.ts.map +1 -1
- package/dist/index.cjs +200 -121
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +197 -121
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -100,24 +100,24 @@ export declare class InMemoryStore implements Store {
|
|
|
100
100
|
*/
|
|
101
101
|
commit<E extends Schemas>(stream: string, msgs: Message<E, keyof E>[], meta: EventMeta, expectedVersion?: number): Promise<Committed<E, keyof E>[]>;
|
|
102
102
|
/**
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
* @param
|
|
106
|
-
* @
|
|
103
|
+
* Atomically discovers and leases streams for processing.
|
|
104
|
+
* Fuses poll + lease into a single operation.
|
|
105
|
+
* @param lagging - Max streams from lagging frontier.
|
|
106
|
+
* @param leading - Max streams from leading frontier.
|
|
107
|
+
* @param by - Lease holder identifier.
|
|
108
|
+
* @param millis - Lease duration in milliseconds.
|
|
109
|
+
* @returns Granted leases.
|
|
107
110
|
*/
|
|
108
|
-
|
|
109
|
-
stream: string;
|
|
110
|
-
source: string | undefined;
|
|
111
|
-
at: number;
|
|
112
|
-
lagging: boolean;
|
|
113
|
-
}[]>;
|
|
111
|
+
claim(lagging: number, leading: number, by: string, millis: number): Promise<Lease[]>;
|
|
114
112
|
/**
|
|
115
|
-
*
|
|
116
|
-
* @param
|
|
117
|
-
* @
|
|
118
|
-
* @returns Granted leases.
|
|
113
|
+
* Registers streams for event processing.
|
|
114
|
+
* @param streams - Streams to register with optional source.
|
|
115
|
+
* @returns Number of newly registered streams.
|
|
119
116
|
*/
|
|
120
|
-
|
|
117
|
+
subscribe(streams: Array<{
|
|
118
|
+
stream: string;
|
|
119
|
+
source?: string;
|
|
120
|
+
}>): Promise<number>;
|
|
121
121
|
/**
|
|
122
122
|
* Acknowledge completion of processing for leased streams.
|
|
123
123
|
* @param leases - Leases to acknowledge, including last processed watermark and lease holder.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InMemoryStore.d.ts","sourceRoot":"","sources":["../../../src/adapters/InMemoryStore.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EACV,SAAS,EACT,SAAS,EACT,KAAK,EACL,OAAO,EACP,KAAK,EACL,OAAO,EACP,KAAK,EACN,MAAM,mBAAmB,CAAC;AAkG3B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+DG;AACH,qBAAa,aAAc,YAAW,KAAK;IAEzC,OAAO,CAAC,OAAO,CAA2C;IAE1D,OAAO,CAAC,QAAQ,CAA0C;IAE1D;;;OAGG;IACG,OAAO;IAKb;;;OAGG;IACG,IAAI;IAIV;;;OAGG;IACG,IAAI;IAMV,OAAO,CAAC,QAAQ;IAUhB;;;;;OAKG;IACG,KAAK,CAAC,CAAC,SAAS,OAAO,EAC3B,QAAQ,EAAE,CAAC,KAAK,E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M,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IAoCxE;;;;OAIG;IACG,SAAS,CAAC,OAAO,EAAE,KAAK,CAAC;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAYnE;;;OAGG;IACG,GAAG,CAAC,MAAM,EAAE,KAAK,EAAE;;;;;;;;IAOzB;;;;OAIG;IACG,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,KAAK,GAAG;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;;;;;;;;;CAMrD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/adapters/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC"}
|
|
@@ -26,6 +26,10 @@ export declare function snap<TState extends Schema, TEvents extends Schemas>(sna
|
|
|
26
26
|
/**
|
|
27
27
|
* Loads a snapshot of the state from the store by replaying events and applying patches.
|
|
28
28
|
*
|
|
29
|
+
* First checks the cache for a checkpoint, then queries the store for events
|
|
30
|
+
* committed after the cached position. On cache miss, replays from the store
|
|
31
|
+
* (using snapshots if available to avoid full replay).
|
|
32
|
+
*
|
|
29
33
|
* @template TState The type of state
|
|
30
34
|
* @template TEvents The type of events
|
|
31
35
|
* @template TActions The type of actions
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event-sourcing.d.ts","sourceRoot":"","sources":["../../src/event-sourcing.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH,OAAO,KAAK,EACV,SAAS,EAGT,MAAM,EACN,OAAO,EACP,QAAQ,EACR,KAAK,EACL,MAAM,EACP,MAAM,kBAAkB,CAAC;AAG1B;;;GAGG;AAEH;;;;;;;;;;;;GAYG;AAC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EACd,OAAO,EAAE,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,EACjC,UAAU,CAAC,EAAE,SAAS,CAAC,OAAO,EAAE,MAAM,OAAO,CAAC,EAC9C,cAAc,UAAQ,GACrB,OAAO,CAAC,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC,CAmHtC"}
|
package/dist/@types/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,CAAC;AAEtB;;;;GAIG;AACH,cAAc,kBAAkB,CAAC;AACjC,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,yBAAyB,CAAC;AACxC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,CAAC;AAEtB;;;;GAIG;AACH,cAAc,kBAAkB,CAAC;AACjC,cAAc,UAAU,CAAC;AACzB,cAAc,qBAAqB,CAAC;AACpC,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,yBAAyB,CAAC;AACxC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,YAAY,CAAC"}
|
package/dist/@types/ports.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Disposable, Disposer, Fetch, Lease, LogLevel, Schemas, Store } from "./types/index.js";
|
|
1
|
+
import type { Cache, Disposable, Disposer, Fetch, Lease, LogLevel, Schemas, Store } from "./types/index.js";
|
|
2
2
|
/**
|
|
3
3
|
* Port and adapter utilities for logging, store management, and resource disposal.
|
|
4
4
|
*
|
|
@@ -203,12 +203,28 @@ export declare const SNAP_EVENT = "__snapshot__";
|
|
|
203
203
|
* @see {@link PostgresStore} for production use
|
|
204
204
|
*/
|
|
205
205
|
export declare const store: (adapter?: Store | undefined) => Store;
|
|
206
|
+
/**
|
|
207
|
+
* Gets or injects the singleton cache.
|
|
208
|
+
*
|
|
209
|
+
* By default, Act uses an in-memory LRU cache. For distributed deployments,
|
|
210
|
+
* inject a Redis-backed cache before building your application.
|
|
211
|
+
*
|
|
212
|
+
* Cache unifies snapshotting — `snap()` writes to cache instead of the event store,
|
|
213
|
+
* and `load()` checks cache before querying the store for tail events.
|
|
214
|
+
*
|
|
215
|
+
* @param adapter - Optional cache implementation to inject
|
|
216
|
+
* @returns The singleton cache instance
|
|
217
|
+
*/
|
|
218
|
+
export declare const cache: (adapter?: Cache | undefined) => Cache;
|
|
206
219
|
/**
|
|
207
220
|
* Tracer builder for logging fetches, leases, etc.
|
|
208
221
|
*/
|
|
209
222
|
export declare function build_tracer(logLevel: LogLevel): {
|
|
210
223
|
fetched: <E extends Schemas>(fetched: Fetch<E>) => void;
|
|
211
|
-
correlated: (
|
|
224
|
+
correlated: (streams: Array<{
|
|
225
|
+
stream: string;
|
|
226
|
+
source?: string;
|
|
227
|
+
}>) => void;
|
|
212
228
|
leased: (leases: Lease[]) => void;
|
|
213
229
|
acked: (leases: Lease[]) => void;
|
|
214
230
|
blocked: (leases: Array<Lease & {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ports.d.ts","sourceRoot":"","sources":["../../src/ports.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ports.d.ts","sourceRoot":"","sources":["../../src/ports.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,KAAK,EACL,UAAU,EACV,QAAQ,EACR,KAAK,EACL,KAAK,EACL,QAAQ,EACR,OAAO,EACP,KAAK,EACN,MAAM,kBAAkB,CAAC;AAE1B;;;;;;;;;;G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AE,MAAM,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,KAAK,IAAI,CAAC;IAC1E,MAAM,EAAE,CAAC,MAAM,EAAE,KAAK,EAAE,KAAK,IAAI,CAAC;IAClC,KAAK,EAAE,CAAC,MAAM,EAAE,KAAK,EAAE,KAAK,IAAI,CAAC;IACjC,OAAO,EAAE,CAAC,MAAM,EAAE,KAAK,CAAC,KAAK,GAAG;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,KAAK,IAAI,CAAC;CAC7D,CAkDA"}
|
|
@@ -4,8 +4,34 @@
|
|
|
4
4
|
* @category Types
|
|
5
5
|
* Types and interfaces for event store ports and disposables in the Act Framework.
|
|
6
6
|
*/
|
|
7
|
-
import type { Committed, EventMeta, Message, Query, Schemas } from "./action.js";
|
|
8
|
-
import type { Lease
|
|
7
|
+
import type { Committed, EventMeta, Message, Query, Schema, Schemas } from "./action.js";
|
|
8
|
+
import type { Lease } from "./reaction.js";
|
|
9
|
+
/**
|
|
10
|
+
* A cached snapshot entry for a stream.
|
|
11
|
+
*
|
|
12
|
+
* @template TState - The state schema type
|
|
13
|
+
*/
|
|
14
|
+
export interface CacheEntry<TState extends Schema> {
|
|
15
|
+
readonly state: TState;
|
|
16
|
+
readonly version: number;
|
|
17
|
+
readonly event_id: number;
|
|
18
|
+
readonly patches: number;
|
|
19
|
+
readonly snaps: number;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Cache port for storing stream snapshots in-process.
|
|
23
|
+
*
|
|
24
|
+
* Implementations should provide fast key-value access with bounded memory.
|
|
25
|
+
* The async interface is forward-compatible with external caches (e.g., Redis).
|
|
26
|
+
*
|
|
27
|
+
* @template TState - The state schema type
|
|
28
|
+
*/
|
|
29
|
+
export interface Cache extends Disposable {
|
|
30
|
+
get<TState extends Schema>(stream: string): Promise<CacheEntry<TState> | undefined>;
|
|
31
|
+
set<TState extends Schema>(stream: string, entry: CacheEntry<TState>): Promise<void>;
|
|
32
|
+
invalidate(stream: string): Promise<void>;
|
|
33
|
+
clear(): Promise<void>;
|
|
34
|
+
}
|
|
9
35
|
/**
|
|
10
36
|
* A function that disposes of a resource asynchronously.
|
|
11
37
|
* @returns Promise that resolves when disposal is complete.
|
|
@@ -144,82 +170,83 @@ export interface Store extends Disposable {
|
|
|
144
170
|
*/
|
|
145
171
|
query: <E extends Schemas>(callback: (event: Committed<E, keyof E>) => void, query?: Query) => Promise<number>;
|
|
146
172
|
/**
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
* Returns streams that have uncommitted events, ordered by their watermark.
|
|
150
|
-
* Uses a dual-frontier approach:
|
|
151
|
-
* - **Lagging**: New or behind streams (ascending watermark)
|
|
152
|
-
* - **Leading**: Active streams (descending watermark)
|
|
173
|
+
* Acknowledges successful processing of leased streams.
|
|
153
174
|
*
|
|
154
|
-
*
|
|
175
|
+
* Updates the watermark to indicate events have been processed successfully.
|
|
176
|
+
* Releases the lease so other workers can process subsequent events.
|
|
155
177
|
*
|
|
156
|
-
* @param
|
|
157
|
-
* @
|
|
158
|
-
* @returns Array of poll results with stream, source, watermark, and lag status
|
|
178
|
+
* @param leases - Leases to acknowledge with updated watermarks
|
|
179
|
+
* @returns Acknowledged leases
|
|
159
180
|
*
|
|
160
181
|
* @example
|
|
161
182
|
* ```typescript
|
|
162
|
-
* const
|
|
163
|
-
*
|
|
164
|
-
*
|
|
165
|
-
* });
|
|
183
|
+
* const leased = await store().claim(5, 5, randomUUID(), 10000);
|
|
184
|
+
* // Process events up to ID 150
|
|
185
|
+
* await store().ack(leased.map(l => ({ ...l, at: 150 })));
|
|
166
186
|
* ```
|
|
167
187
|
*
|
|
168
|
-
* @see {@link
|
|
188
|
+
* @see {@link claim} for acquiring leases
|
|
169
189
|
*/
|
|
170
|
-
|
|
190
|
+
ack: (leases: Lease[]) => Promise<Lease[]>;
|
|
171
191
|
/**
|
|
172
|
-
*
|
|
192
|
+
* Atomically discovers and leases streams for reaction processing.
|
|
193
|
+
*
|
|
194
|
+
* Combines {@link poll} and {@link lease} into a single operation, eliminating
|
|
195
|
+
* the race condition where another worker can grab a stream between poll and lease.
|
|
173
196
|
*
|
|
174
|
-
*
|
|
175
|
-
*
|
|
176
|
-
*
|
|
177
|
-
* - Lease hasn't expired
|
|
178
|
-
* - Stream isn't blocked due to errors
|
|
197
|
+
* PostgresStore uses `FOR UPDATE SKIP LOCKED` for zero-contention competing
|
|
198
|
+
* consumer semantics — workers never block each other, each grabbing different
|
|
199
|
+
* streams atomically. InMemoryStore fuses its poll+lease logic equivalently.
|
|
179
200
|
*
|
|
180
|
-
*
|
|
201
|
+
* Used by `Act.drain()` as the primary stream acquisition method.
|
|
202
|
+
*
|
|
203
|
+
* @param lagging - Max streams from the lagging frontier (ascending watermark)
|
|
204
|
+
* @param leading - Max streams from the leading frontier (descending watermark)
|
|
205
|
+
* @param by - Unique lease holder identifier (UUID)
|
|
181
206
|
* @param millis - Lease duration in milliseconds
|
|
182
|
-
* @returns Array of successfully
|
|
207
|
+
* @returns Array of successfully leased streams with metadata
|
|
183
208
|
*
|
|
184
209
|
* @example
|
|
185
210
|
* ```typescript
|
|
186
|
-
* const
|
|
187
|
-
*
|
|
188
|
-
*
|
|
189
|
-
*
|
|
190
|
-
* if (granted.length > 0) {
|
|
191
|
-
* // Process events...
|
|
192
|
-
* await store().ack(granted);
|
|
193
|
-
* }
|
|
211
|
+
* const leased = await store().claim(5, 5, randomUUID(), 10000);
|
|
212
|
+
* leased.forEach(({ stream, at, lagging }) => {
|
|
213
|
+
* console.log(`Leased ${stream} at ${at} (lagging: ${lagging})`);
|
|
214
|
+
* });
|
|
194
215
|
* ```
|
|
195
216
|
*
|
|
196
|
-
* @see {@link
|
|
217
|
+
* @see {@link subscribe} for registering new streams (used by correlate)
|
|
197
218
|
* @see {@link ack} for acknowledging completion
|
|
219
|
+
* @see {@link block} for blocking failed streams
|
|
198
220
|
*/
|
|
199
|
-
|
|
221
|
+
claim: (lagging: number, leading: number, by: string, millis: number) => Promise<Lease[]>;
|
|
200
222
|
/**
|
|
201
|
-
*
|
|
223
|
+
* Registers streams for event processing.
|
|
202
224
|
*
|
|
203
|
-
*
|
|
204
|
-
*
|
|
225
|
+
* Upserts stream entries so they become visible to {@link claim}. Used by
|
|
226
|
+
* `correlate()` to register dynamically discovered reaction target streams.
|
|
205
227
|
*
|
|
206
|
-
* @param
|
|
207
|
-
* @returns
|
|
228
|
+
* @param streams - Streams to register with optional source hint
|
|
229
|
+
* @returns Number of newly registered streams (excludes already-known streams)
|
|
208
230
|
*
|
|
209
231
|
* @example
|
|
210
232
|
* ```typescript
|
|
211
|
-
* const
|
|
212
|
-
*
|
|
213
|
-
*
|
|
233
|
+
* const count = await store().subscribe([
|
|
234
|
+
* { stream: "stats-user-1", source: "user-1" },
|
|
235
|
+
* { stream: "stats-user-2", source: "user-2" },
|
|
236
|
+
* ]);
|
|
237
|
+
* console.log(`Registered ${count} new streams`);
|
|
214
238
|
* ```
|
|
215
239
|
*
|
|
216
|
-
* @see {@link
|
|
240
|
+
* @see {@link claim} for discovering and leasing registered streams
|
|
217
241
|
*/
|
|
218
|
-
|
|
242
|
+
subscribe: (streams: Array<{
|
|
243
|
+
stream: string;
|
|
244
|
+
source?: string;
|
|
245
|
+
}>) => Promise<number>;
|
|
219
246
|
/**
|
|
220
247
|
* Blocks streams after persistent processing failures.
|
|
221
248
|
*
|
|
222
|
-
* Blocked streams won't be returned by {@link
|
|
249
|
+
* Blocked streams won't be returned by {@link claim} until manually unblocked.
|
|
223
250
|
* This prevents poison messages from repeatedly failing and consuming resources.
|
|
224
251
|
*
|
|
225
252
|
* Streams are typically blocked when:
|
|
@@ -245,7 +272,7 @@ export interface Store extends Disposable {
|
|
|
245
272
|
* }
|
|
246
273
|
* ```
|
|
247
274
|
*
|
|
248
|
-
* @see {@link
|
|
275
|
+
* @see {@link claim} for lease management
|
|
249
276
|
*/
|
|
250
277
|
block: (leases: Array<Lease & {
|
|
251
278
|
error: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ports.d.ts","sourceRoot":"","sources":["../../../src/types/ports.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EACV,SAAS,EACT,SAAS,EACT,OAAO,EACP,KAAK,EACL,OAAO,EACR,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"ports.d.ts","sourceRoot":"","sources":["../../../src/types/ports.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EACV,SAAS,EACT,SAAS,EACT,OAAO,EACP,KAAK,EACL,MAAM,EACN,OAAO,EACR,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAE3C;;;;GAIG;AACH,MAAM,WAAW,UAAU,CAAC,MAAM,SAAS,MAAM;IAC/C,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACxB;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,KAAM,SAAQ,UAAU;IACvC,GAAG,CAAC,MAAM,SAAS,MAAM,EACvB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,UAAU,CAAC,MAAM,CAAC,GAAG,SAAS,CAAC,CAAC;IAC3C,GAAG,CAAC,MAAM,SAAS,MAAM,EACvB,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,UAAU,CAAC,MAAM,CAAC,GACxB,OAAO,CAAC,IAAI,CAAC,CAAC;IACjB,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1C,KAAK,IAAI,OAAO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,EACf,EAAE,EAAE,MAAM,EACV,MAAM,EAAE,MAAM,KACX,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC;IAEtB;;;;;;;;;;;;;;;;;;;OAmBG;IACH,SAAS,EAAE,CACT,OAAO,EAAE,KAAK,CAAC;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,KAChD,OAAO,CAAC,MAAM,CAAC,CAAC;IAErB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA8BG;IACH,KAAK,EAAE,CACL,MAAM,EAAE,KAAK,CAAC,KAAK,GAAG;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,KACrC,OAAO,CAAC,KAAK,CAAC,KAAK,GAAG;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC,CAAC;CAChD"}
|
|
@@ -128,19 +128,6 @@ export type ReactionPayload<TEvents extends Schemas> = Reaction<TEvents> & {
|
|
|
128
128
|
readonly event: Committed<TEvents, keyof TEvents>;
|
|
129
129
|
readonly source?: string;
|
|
130
130
|
};
|
|
131
|
-
/**
|
|
132
|
-
* Poll details for stream processing.
|
|
133
|
-
* @property stream - The target stream name.
|
|
134
|
-
* @property source - The source stream.
|
|
135
|
-
* @property at - The lease watermark.
|
|
136
|
-
* @property lagging - Whether the stream is lagging behind.
|
|
137
|
-
*/
|
|
138
|
-
export type Poll = {
|
|
139
|
-
readonly stream: string;
|
|
140
|
-
readonly source?: string;
|
|
141
|
-
readonly at: number;
|
|
142
|
-
readonly lagging: boolean;
|
|
143
|
-
};
|
|
144
131
|
/**
|
|
145
132
|
* Result of fetching events from the store for processing.
|
|
146
133
|
* @template TEvents - Event schemas.
|
|
@@ -1 +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,UA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