@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,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module adapters/console-logger
|
|
3
|
+
*
|
|
4
|
+
* High-performance console logger inspired by pino's design:
|
|
5
|
+
* - Numeric level comparison for O(1) gating
|
|
6
|
+
* - stdout.write() in production for raw JSON lines (no console overhead)
|
|
7
|
+
* - Colorized single-line output in development
|
|
8
|
+
* - No-op method replacement when level is above threshold
|
|
9
|
+
* - Child logger support with merged bindings
|
|
10
|
+
*/
|
|
11
|
+
import type { Logger } from "../types/index.js";
|
|
12
|
+
/**
|
|
13
|
+
* Default console logger for the Act framework.
|
|
14
|
+
*
|
|
15
|
+
* Production mode emits newline-delimited JSON (compatible with GCP, AWS
|
|
16
|
+
* CloudWatch, Datadog, and other structured log ingestion systems).
|
|
17
|
+
*
|
|
18
|
+
* Development mode emits colorized, human-readable output.
|
|
19
|
+
*/
|
|
20
|
+
export declare class ConsoleLogger implements Logger {
|
|
21
|
+
level: string;
|
|
22
|
+
private readonly _pretty;
|
|
23
|
+
readonly fatal: Logger["fatal"];
|
|
24
|
+
readonly error: Logger["error"];
|
|
25
|
+
readonly warn: Logger["warn"];
|
|
26
|
+
readonly info: Logger["info"];
|
|
27
|
+
readonly debug: Logger["debug"];
|
|
28
|
+
readonly trace: Logger["trace"];
|
|
29
|
+
constructor(options?: {
|
|
30
|
+
level?: string;
|
|
31
|
+
pretty?: boolean;
|
|
32
|
+
bindings?: Record<string, unknown>;
|
|
33
|
+
});
|
|
34
|
+
/** No-op — `console.log` has no resources to release. */
|
|
35
|
+
dispose(): Promise<void>;
|
|
36
|
+
/** @inheritDoc */
|
|
37
|
+
child(bindings: Record<string, unknown>): Logger;
|
|
38
|
+
private _jsonWrite;
|
|
39
|
+
private _prettyWrite;
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=console-logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"console-logger.d.ts","sourceRoot":"","sources":["../../../src/adapters/console-logger.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAwBhD;;;;;;;GAOG;AACH,qBAAa,aAAc,YAAW,MAAM;IAC1C,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAU;IAElC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;IAChC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;IAChC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;IAC9B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;IAC9B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;IAChC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;gBAG9B,OAAO,GAAE;QACP,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,MAAM,CAAC,EAAE,OAAO,CAAC;QACjB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KAC/B;IAwBR,yDAAyD;IACnD,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAE9B,kBAAkB;IAClB,KAAK,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM;IAQhD,OAAO,CAAC,UAAU;IAwClB,OAAO,CAAC,YAAY;CAmCrB"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { Cache, CacheEntry, Schema } from "../types/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* In-memory LRU cache for stream snapshots.
|
|
4
|
+
*
|
|
5
|
+
* Backed by an internal `LruMap` for O(1) get/set with LRU eviction.
|
|
6
|
+
* Configurable `maxSize` bounds memory usage.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* import { cache } from "@rotorsoft/act";
|
|
11
|
+
* import { InMemoryCache } from "@rotorsoft/act";
|
|
12
|
+
*
|
|
13
|
+
* cache(new InMemoryCache({ maxSize: 500 }));
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export declare class InMemoryCache implements Cache {
|
|
17
|
+
private readonly _entries;
|
|
18
|
+
constructor(options?: {
|
|
19
|
+
maxSize?: number;
|
|
20
|
+
});
|
|
21
|
+
/** @inheritDoc */
|
|
22
|
+
get<TState extends Schema>(stream: string): Promise<CacheEntry<TState> | undefined>;
|
|
23
|
+
/** @inheritDoc */
|
|
24
|
+
set<TState extends Schema>(stream: string, entry: CacheEntry<TState>): Promise<void>;
|
|
25
|
+
/** @inheritDoc */
|
|
26
|
+
invalidate(stream: string): Promise<void>;
|
|
27
|
+
/** @inheritDoc */
|
|
28
|
+
clear(): Promise<void>;
|
|
29
|
+
/** @inheritDoc */
|
|
30
|
+
dispose(): Promise<void>;
|
|
31
|
+
/** Current number of entries held by the LRU. */
|
|
32
|
+
get size(): number;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=in-memory-cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"in-memory-cache.d.ts","sourceRoot":"","sources":["../../../src/adapters/in-memory-cache.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAEnE;;;;;;;;;;;;;GAaG;AAEH,qBAAa,aAAc,YAAW,KAAK;IAIzC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAkC;gBAE/C,OAAO,CAAC,EAAE;QAAE,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE;IAI1C,kBAAkB;IACZ,GAAG,CAAC,MAAM,SAAS,MAAM,EAC7B,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,UAAU,CAAC,MAAM,CAAC,GAAG,SAAS,CAAC;IAI1C,kBAAkB;IACZ,GAAG,CAAC,MAAM,SAAS,MAAM,EAC7B,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,UAAU,CAAC,MAAM,CAAC,GACxB,OAAO,CAAC,IAAI,CAAC;IAIhB,kBAAkB;IACZ,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAI/C,kBAAkB;IACZ,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAI5B,kBAAkB;IACZ,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAI9B,iDAAiD;IACjD,IAAI,IAAI,IAAI,MAAM,CAEjB;CACF"}
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import type { BlockedLease, Committed, EventMeta, Lease, Message, PrioritizeFilter, Query, QueryStreams, QueryStreamsResult, Schema, Schemas, Store, StreamPosition } from "../types/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* In-memory event store implementation.
|
|
4
|
+
*
|
|
5
|
+
* This is the default store used by Act when no other store is injected.
|
|
6
|
+
* It stores all events in memory and is suitable for:
|
|
7
|
+
* - Development and prototyping
|
|
8
|
+
* - Unit and integration testing
|
|
9
|
+
* - Demonstrations and examples
|
|
10
|
+
*
|
|
11
|
+
* **Not suitable for production** - all data is lost when the process exits.
|
|
12
|
+
* Use {@link PostgresStore} for production deployments.
|
|
13
|
+
*
|
|
14
|
+
* The in-memory store provides:
|
|
15
|
+
* - Full {@link Store} interface implementation
|
|
16
|
+
* - Optimistic concurrency control
|
|
17
|
+
* - Stream leasing for distributed processing simulation
|
|
18
|
+
* - Snapshot support
|
|
19
|
+
* - Fast performance (no I/O overhead)
|
|
20
|
+
*
|
|
21
|
+
* **`Store.notify` is intentionally not implemented.** The notify hook is a
|
|
22
|
+
* cross-process wake-up signal — local commits already arm the drain via
|
|
23
|
+
* `do()`. An in-memory store is single-process by definition, so there is
|
|
24
|
+
* no remote writer to be notified of. The {@link Act} orchestrator
|
|
25
|
+
* detects the absence and falls back to the existing debounce/poll path.
|
|
26
|
+
*
|
|
27
|
+
* @example Using in tests
|
|
28
|
+
* ```typescript
|
|
29
|
+
* import { store } from "@rotorsoft/act";
|
|
30
|
+
*
|
|
31
|
+
* describe("Counter", () => {
|
|
32
|
+
* beforeEach(async () => {
|
|
33
|
+
* // Reset store between tests
|
|
34
|
+
* await store().seed();
|
|
35
|
+
* });
|
|
36
|
+
*
|
|
37
|
+
* it("increments", async () => {
|
|
38
|
+
* await app.do("increment", target, { by: 5 });
|
|
39
|
+
* const snapshot = await app.load(Counter, "counter-1");
|
|
40
|
+
* expect(snapshot.state.count).toBe(5);
|
|
41
|
+
* });
|
|
42
|
+
* });
|
|
43
|
+
* ```
|
|
44
|
+
*
|
|
45
|
+
* @example Explicit instantiation
|
|
46
|
+
* ```typescript
|
|
47
|
+
* import { InMemoryStore } from "@rotorsoft/act";
|
|
48
|
+
*
|
|
49
|
+
* const testStore = new InMemoryStore();
|
|
50
|
+
* await testStore.seed();
|
|
51
|
+
*
|
|
52
|
+
* // Use for specific test scenarios
|
|
53
|
+
* await testStore.commit("test-stream", events, meta);
|
|
54
|
+
* ```
|
|
55
|
+
*
|
|
56
|
+
* @example Querying events
|
|
57
|
+
* ```typescript
|
|
58
|
+
* const events: any[] = [];
|
|
59
|
+
* await store().query(
|
|
60
|
+
* (event) => events.push(event),
|
|
61
|
+
* { stream: "test-stream" }
|
|
62
|
+
* );
|
|
63
|
+
* console.log(`Found ${events.length} events`);
|
|
64
|
+
* ```
|
|
65
|
+
*
|
|
66
|
+
* @see {@link Store} for the interface definition
|
|
67
|
+
* @see {@link PostgresStore} for production use
|
|
68
|
+
* @see {@link store} for injecting stores
|
|
69
|
+
*
|
|
70
|
+
* @category Adapters
|
|
71
|
+
*/
|
|
72
|
+
export declare class InMemoryStore implements Store {
|
|
73
|
+
private _events;
|
|
74
|
+
private _streams;
|
|
75
|
+
private _streamVersions;
|
|
76
|
+
private _maxEventIdByStream;
|
|
77
|
+
private _maxNonSnapEventId;
|
|
78
|
+
private _resetIndexes;
|
|
79
|
+
/**
|
|
80
|
+
* Dispose of the store and clear all events.
|
|
81
|
+
* @returns Promise that resolves when disposal is complete.
|
|
82
|
+
*/
|
|
83
|
+
dispose(): Promise<void>;
|
|
84
|
+
/**
|
|
85
|
+
* Seed the store with initial data (no-op for in-memory).
|
|
86
|
+
* @returns Promise that resolves when seeding is complete.
|
|
87
|
+
*/
|
|
88
|
+
seed(): Promise<void>;
|
|
89
|
+
/**
|
|
90
|
+
* Drop all data from the store.
|
|
91
|
+
* @returns Promise that resolves when the store is cleared.
|
|
92
|
+
*/
|
|
93
|
+
drop(): Promise<void>;
|
|
94
|
+
private in_query;
|
|
95
|
+
/**
|
|
96
|
+
* Query events in the store, optionally filtered by query options.
|
|
97
|
+
* @param callback - Function to call for each event.
|
|
98
|
+
* @param query - Optional query options.
|
|
99
|
+
* @returns The number of events processed.
|
|
100
|
+
*/
|
|
101
|
+
query<E extends Schemas>(callback: (event: Committed<E, keyof E>) => void, query?: Query): Promise<number>;
|
|
102
|
+
/**
|
|
103
|
+
* Commit one or more events to a stream.
|
|
104
|
+
* @param stream - The stream name.
|
|
105
|
+
* @param msgs - The events/messages to commit.
|
|
106
|
+
* @param meta - Event metadata.
|
|
107
|
+
* @param expectedVersion - Optional optimistic concurrency check.
|
|
108
|
+
* @returns The committed events with metadata.
|
|
109
|
+
* @throws ConcurrencyError if expectedVersion does not match.
|
|
110
|
+
*/
|
|
111
|
+
commit<E extends Schemas>(stream: string, msgs: Message<E, keyof E>[], meta: EventMeta, expectedVersion?: number): Promise<Committed<E, keyof E>[]>;
|
|
112
|
+
/**
|
|
113
|
+
* Atomically discovers and leases streams for processing.
|
|
114
|
+
* Fuses poll + lease into a single operation.
|
|
115
|
+
* @param lagging - Max streams from lagging frontier.
|
|
116
|
+
* @param leading - Max streams from leading frontier.
|
|
117
|
+
* @param by - Lease holder identifier.
|
|
118
|
+
* @param millis - Lease duration in milliseconds.
|
|
119
|
+
* @returns Granted leases.
|
|
120
|
+
*/
|
|
121
|
+
claim(lagging: number, leading: number, by: string, millis: number): Promise<Lease[]>;
|
|
122
|
+
/**
|
|
123
|
+
* Registers streams for event processing. When the same stream is
|
|
124
|
+
* resubscribed with a different priority, the **maximum** wins — so
|
|
125
|
+
* the highest-priority registered reaction sets the scheduling lane.
|
|
126
|
+
* Use {@link prioritize} for operator runtime overrides.
|
|
127
|
+
*
|
|
128
|
+
* @param streams - Streams to register with optional source + priority.
|
|
129
|
+
* @returns subscribed count and current max watermark.
|
|
130
|
+
*/
|
|
131
|
+
subscribe(streams: Array<{
|
|
132
|
+
stream: string;
|
|
133
|
+
source?: string;
|
|
134
|
+
priority?: number;
|
|
135
|
+
}>): Promise<{
|
|
136
|
+
subscribed: number;
|
|
137
|
+
watermark: number;
|
|
138
|
+
}>;
|
|
139
|
+
/**
|
|
140
|
+
* Acknowledge completion of processing for leased streams.
|
|
141
|
+
* @param leases - Leases to acknowledge, including last processed watermark and lease holder.
|
|
142
|
+
*/
|
|
143
|
+
ack(leases: Lease[]): Promise<{
|
|
144
|
+
stream: string;
|
|
145
|
+
source: string | undefined;
|
|
146
|
+
at: number;
|
|
147
|
+
by: string;
|
|
148
|
+
retry: number;
|
|
149
|
+
lagging: boolean;
|
|
150
|
+
}[]>;
|
|
151
|
+
/**
|
|
152
|
+
* Block a stream for processing after failing to process and reaching max retries with blocking enabled.
|
|
153
|
+
* @param leases - Leases to block, including lease holder and last error message.
|
|
154
|
+
* @returns Blocked leases.
|
|
155
|
+
*/
|
|
156
|
+
block(leases: BlockedLease[]): Promise<{
|
|
157
|
+
stream: string;
|
|
158
|
+
source: string | undefined;
|
|
159
|
+
at: number;
|
|
160
|
+
by: string;
|
|
161
|
+
retry: number;
|
|
162
|
+
error: string;
|
|
163
|
+
lagging: boolean;
|
|
164
|
+
}[]>;
|
|
165
|
+
/**
|
|
166
|
+
* Reset watermarks for the given streams to -1, clearing retry, blocked,
|
|
167
|
+
* error, and lease state so they can be replayed from the beginning.
|
|
168
|
+
* @param streams - Stream names to reset.
|
|
169
|
+
* @returns Count of streams that were actually reset.
|
|
170
|
+
*/
|
|
171
|
+
reset(streams: string[]): Promise<number>;
|
|
172
|
+
/**
|
|
173
|
+
* Bulk-update priority of streams matching `filter`. Mirrors
|
|
174
|
+
* {@link query_streams}'s filter semantics — see {@link Store.prioritize}.
|
|
175
|
+
* Unlike {@link subscribe} (which keeps `max()` of registered
|
|
176
|
+
* priorities), this sets the priority outright — operator override
|
|
177
|
+
* for the build-time scheduling policy.
|
|
178
|
+
*
|
|
179
|
+
* @returns Count of streams whose priority changed.
|
|
180
|
+
*/
|
|
181
|
+
prioritize(filter: PrioritizeFilter, priority: number): Promise<number>;
|
|
182
|
+
/**
|
|
183
|
+
* Streams registered subscription positions to the callback, ordered by
|
|
184
|
+
* stream name. Returns the highest event id in the store and the count
|
|
185
|
+
* of positions emitted.
|
|
186
|
+
*/
|
|
187
|
+
query_streams(callback: (position: StreamPosition) => void, query?: QueryStreams): Promise<QueryStreamsResult>;
|
|
188
|
+
/**
|
|
189
|
+
* Atomically truncates streams and seeds each with a snapshot or tombstone.
|
|
190
|
+
* @param targets - Streams to truncate with optional snapshot state and meta.
|
|
191
|
+
* @returns Map keyed by stream name, each entry with `deleted` count and `committed` event.
|
|
192
|
+
*/
|
|
193
|
+
truncate(targets: Array<{
|
|
194
|
+
stream: string;
|
|
195
|
+
snapshot?: Schema;
|
|
196
|
+
meta?: EventMeta;
|
|
197
|
+
}>): Promise<Map<string, {
|
|
198
|
+
deleted: number;
|
|
199
|
+
committed: Committed<Schemas, keyof Schemas>;
|
|
200
|
+
}>>;
|
|
201
|
+
}
|
|
202
|
+
//# sourceMappingURL=in-memory-store.d.ts.map
|
|
@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A8DxE;;;;;;;;OAQG;IACG,SAAS,CACb,OAAO,EAAE,KAAK,CAAC;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;;;;IAoBxE;;;OAGG;IACG,GAAG,CAAC,MAAM,EAAE,KAAK,EAAE;;;;;;;;IAOzB;;;;OAIG;IACG,KAAK,CAAC,MAAM,EAAE,YAAY,EAAE;;;;;;;;;IAOlC;;;;;OAKG;IACG,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE;IAa7B;;;;;;;;OAQG;IACG,UAAU,CAAC,MAAM,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM;IAuC3D;;;;OAIG;IACG,aAAa,CACjB,QAAQ,EAAE,CAAC,QAAQ,EAAE,cAAc,KAAK,IAAI,EAC5C,KAAK,CAAC,EAAE,YAAY,GACnB,OAAO,CAAC,kBAAkB,CAAC;IAwD9B;;;;OAIG;IACG,QAAQ,CACZ,OAAO,EAAE,KAAK,CAAC;QACb,MAAM,EAAE,MAAM,CAAC;QACf,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,IAAI,CAAC,EAAE,SAAS,CAAC;KAClB,CAAC;iBAmBW,MAAM;mBAAa,SAAS,CAAC,OAAO,EAAE,MAAM,OAAO,CAAC;;CA6BpE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/adapters/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module act-builder
|
|
3
|
+
* @category Builders
|
|
4
|
+
*
|
|
5
|
+
* Fluent builder for composing event-sourced applications.
|
|
6
|
+
*/
|
|
7
|
+
import { Act, type ActOptions } from "../act.js";
|
|
8
|
+
import type { Actor, Committed, EventRegister, IAct, ReactionOptions, ReactionResolver, Schema, SchemaRegister, Schemas, Snapshot, State } from "../types/index.js";
|
|
9
|
+
import type { Projection } from "./projection-builder.js";
|
|
10
|
+
import type { Slice } from "./slice-builder.js";
|
|
11
|
+
/**
|
|
12
|
+
* Fluent builder interface for composing event-sourced applications.
|
|
13
|
+
*
|
|
14
|
+
* Provides a chainable API for:
|
|
15
|
+
* - Registering states via `.withState()`
|
|
16
|
+
* - Registering slices via `.withSlice()`
|
|
17
|
+
* - Registering projections via `.withProjection()`
|
|
18
|
+
* - Locking a custom actor type via `.withActor<TActor>()`
|
|
19
|
+
* - Defining event reactions via `.on()` → `.do()` → `.to()`
|
|
20
|
+
* - Building the orchestrator via `.build()`
|
|
21
|
+
*
|
|
22
|
+
* @template TSchemaReg - Schema register for states (maps action names to state schemas)
|
|
23
|
+
* @template TEvents - Event schemas (maps event names to event data schemas)
|
|
24
|
+
* @template TActions - Action schemas (maps action names to action payload schemas)
|
|
25
|
+
* @template TStateMap - Map of state names to state schemas
|
|
26
|
+
* @template TActor - Actor type extending base Actor
|
|
27
|
+
*
|
|
28
|
+
* @see {@link act} for usage examples
|
|
29
|
+
* @see {@link Act} for the built orchestrator API
|
|
30
|
+
*/
|
|
31
|
+
export type ActBuilder<TSchemaReg extends SchemaRegister<TActions>, TEvents extends Schemas, TActions extends Schemas, TStateMap extends Record<string, Schema> = {}, TActor extends Actor = Actor> = {
|
|
32
|
+
/**
|
|
33
|
+
* Registers a state definition with the builder.
|
|
34
|
+
*
|
|
35
|
+
* State names, action names, and event names must be unique across the
|
|
36
|
+
* application (partial states with the same name are merged automatically).
|
|
37
|
+
*
|
|
38
|
+
* @throws {Error} If duplicate action or event names are detected
|
|
39
|
+
*/
|
|
40
|
+
withState: <TNewState extends Schema, TNewEvents extends Schemas, TNewActions extends Schemas, TNewName extends string = string>(state: State<TNewState, TNewEvents, TNewActions, TNewName>) => ActBuilder<TSchemaReg & {
|
|
41
|
+
[K in keyof TNewActions]: TNewState;
|
|
42
|
+
}, TEvents & TNewEvents, TActions & TNewActions, TStateMap & {
|
|
43
|
+
[K in TNewName]: TNewState;
|
|
44
|
+
}, TActor>;
|
|
45
|
+
/**
|
|
46
|
+
* Registers a slice with the builder.
|
|
47
|
+
*
|
|
48
|
+
* Merges all the slice's states and reactions into the application.
|
|
49
|
+
* State names, action names, and event names must be unique across the
|
|
50
|
+
* application (partial states with the same name are merged automatically).
|
|
51
|
+
*
|
|
52
|
+
* @throws {Error} If duplicate action or event names are detected
|
|
53
|
+
*/
|
|
54
|
+
withSlice: <TNewSchemaReg extends SchemaRegister<TNewActions>, TNewEvents extends Schemas, TNewActions extends Schemas, TNewMap extends Record<string, Schema>>(slice: Slice<TNewSchemaReg, TNewEvents, TNewActions, TNewMap>) => ActBuilder<TSchemaReg & TNewSchemaReg, TEvents & TNewEvents, TActions & TNewActions, TStateMap & TNewMap, TActor>;
|
|
55
|
+
/**
|
|
56
|
+
* Registers a standalone projection with the builder.
|
|
57
|
+
*
|
|
58
|
+
* The projection's events must be a subset of events already registered
|
|
59
|
+
* via `.withState()` or `.withSlice()`.
|
|
60
|
+
*/
|
|
61
|
+
withProjection: <TNewEvents extends Schemas>(projection: [Exclude<keyof TNewEvents, keyof TEvents>] extends [never] ? Projection<TNewEvents> : never) => ActBuilder<TSchemaReg, TEvents, TActions, TStateMap, TActor>;
|
|
62
|
+
/**
|
|
63
|
+
* Locks a custom actor type for this application.
|
|
64
|
+
*
|
|
65
|
+
* This is a pure type-level method — it returns the same builder at
|
|
66
|
+
* runtime but narrows the `TActor` generic so that `app.do()` and
|
|
67
|
+
* reaction dispatchers require the richer actor shape.
|
|
68
|
+
*
|
|
69
|
+
* @template TNewActor - Custom actor type extending base Actor
|
|
70
|
+
* @returns The same builder with `TActor` locked to `TNewActor`
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```typescript
|
|
74
|
+
* type MyActor = { id: string; name: string; role: string; tenantId: string };
|
|
75
|
+
*
|
|
76
|
+
* const app = act()
|
|
77
|
+
* .withActor<MyActor>()
|
|
78
|
+
* .withState(Counter)
|
|
79
|
+
* .build();
|
|
80
|
+
*
|
|
81
|
+
* // Now app.do() requires MyActor in the target
|
|
82
|
+
* await app.do("increment", {
|
|
83
|
+
* stream: "counter-1",
|
|
84
|
+
* actor: { id: "1", name: "Alice", role: "admin", tenantId: "t1" }
|
|
85
|
+
* }, { by: 5 });
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
88
|
+
withActor: <TNewActor extends Actor>() => ActBuilder<TSchemaReg, TEvents, TActions, TStateMap, TNewActor>;
|
|
89
|
+
/**
|
|
90
|
+
* Begins defining a reaction to a specific event.
|
|
91
|
+
*
|
|
92
|
+
* Reactions are event handlers that respond to state changes. They can trigger
|
|
93
|
+
* additional actions, update external systems, or perform side effects. Reactions
|
|
94
|
+
* are processed asynchronously during drain cycles.
|
|
95
|
+
*
|
|
96
|
+
* @template TKey - Event name (must be a registered event)
|
|
97
|
+
* @param event - The event name to react to
|
|
98
|
+
* @returns An object with `.do()` method to define the reaction handler
|
|
99
|
+
*/
|
|
100
|
+
on: <TKey extends keyof TEvents>(event: TKey) => {
|
|
101
|
+
do: (handler: (event: Committed<TEvents, TKey>, stream: string, app: IAct<TEvents, TActions, TActor>) => Promise<Snapshot<Schema, TEvents> | void>, options?: Partial<ReactionOptions>) => ActBuilder<TSchemaReg, TEvents, TActions, TStateMap, TActor> & {
|
|
102
|
+
to: (resolver: ReactionResolver<TEvents, TKey> | string) => ActBuilder<TSchemaReg, TEvents, TActions, TStateMap, TActor>;
|
|
103
|
+
};
|
|
104
|
+
};
|
|
105
|
+
/**
|
|
106
|
+
* Builds and returns the Act orchestrator instance.
|
|
107
|
+
*
|
|
108
|
+
* @param options - Optional runtime overrides (see {@link ActOptions}).
|
|
109
|
+
* @returns The Act orchestrator instance
|
|
110
|
+
*
|
|
111
|
+
* @see {@link Act} for available orchestrator methods
|
|
112
|
+
*/
|
|
113
|
+
build: (options?: ActOptions) => Act<TSchemaReg, TEvents, TActions, TStateMap, TActor>;
|
|
114
|
+
/**
|
|
115
|
+
* The registered event schemas and their reaction maps.
|
|
116
|
+
*/
|
|
117
|
+
readonly events: EventRegister<TEvents>;
|
|
118
|
+
};
|
|
119
|
+
/**
|
|
120
|
+
* Creates a new Act orchestrator builder for composing event-sourced applications.
|
|
121
|
+
*
|
|
122
|
+
* @example Basic application with single state
|
|
123
|
+
* ```typescript
|
|
124
|
+
* const app = act()
|
|
125
|
+
* .withState(Counter)
|
|
126
|
+
* .build();
|
|
127
|
+
* ```
|
|
128
|
+
*
|
|
129
|
+
* @example Application with custom actor type
|
|
130
|
+
* ```typescript
|
|
131
|
+
* type MyActor = { id: string; name: string; role: string };
|
|
132
|
+
*
|
|
133
|
+
* const app = act()
|
|
134
|
+
* .withActor<MyActor>()
|
|
135
|
+
* .withState(Counter)
|
|
136
|
+
* .build();
|
|
137
|
+
* ```
|
|
138
|
+
*
|
|
139
|
+
* @example Application with slices (vertical slice architecture)
|
|
140
|
+
* ```typescript
|
|
141
|
+
* const CounterSlice = slice()
|
|
142
|
+
* .withState(Counter)
|
|
143
|
+
* .on("Incremented")
|
|
144
|
+
* .do(async (event) => { console.log("incremented!"); })
|
|
145
|
+
* .to("counter-target")
|
|
146
|
+
* .build();
|
|
147
|
+
*
|
|
148
|
+
* const app = act()
|
|
149
|
+
* .withSlice(CounterSlice)
|
|
150
|
+
* .build();
|
|
151
|
+
* ```
|
|
152
|
+
*
|
|
153
|
+
*
|
|
154
|
+
* @see {@link ActBuilder} for available builder methods
|
|
155
|
+
* @see {@link Act} for orchestrator API methods
|
|
156
|
+
* @see {@link state} for defining states
|
|
157
|
+
* @see {@link slice} for defining slices
|
|
158
|
+
*/
|
|
159
|
+
export declare function act<TSchemaReg extends SchemaRegister<TActions> = {}, TEvents extends Schemas = {}, TActions extends Schemas = {}, TStateMap extends Record<string, Schema> = {}, TActor extends Actor = Actor>(): ActBuilder<TSchemaReg, TEvents, TActions, TStateMap, TActor>;
|
|
160
|
+
//# sourceMappingURL=act-builder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"act-builder.d.ts","sourceRoot":"","sources":["../../../src/builders/act-builder.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,GAAG,EAAE,KAAK,UAAU,EAAE,MAAM,WAAW,CAAC;AAOjD,OAAO,KAAK,EACV,KAAK,EAEL,SAAS,EACT,aAAa,EACb,IAAI,EAEJ,eAAe,EACf,gBAAgB,EAEhB,MAAM,EACN,cAAc,EACd,OAAO,EACP,QAAQ,EACR,KAAK,EACN,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAoBhD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,MAAM,UAAU,CACpB,UAAU,SAAS,cAAc,CAAC,QAAQ,CAAC,EAC3C,OAAO,SAAS,OAAO,EACvB,QAAQ,SAAS,OAAO,EAExB,SAAS,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,EAAE,EAC7C,MAAM,SAAS,KAAK,GAAG,KAAK,IAC1B;IACF;;;;;;;OAOG;IACH,SAAS,EAAE,CACT,SAAS,SAAS,MAAM,EACxB,UAAU,SAAS,OAAO,EAC1B,WAAW,SAAS,OAAO,EAC3B,QAAQ,SAAS,MAAM,GAAG,MAAM,EAEhC,KAAK,EAAE,KAAK,CAAC,SAAS,EAAE,UAAU,EAAE,WAAW,EAAE,QAAQ,CAAC,KACvD,UAAU,CACb,UAAU,GAAG;SAAG,CAAC,IAAI,MAAM,WAAW,GAAG,SAAS;KAAE,EACpD,OAAO,GAAG,UAAU,EACpB,QAAQ,GAAG,WAA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CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC,EAC9C,OAAO,CAAC,EAAE,OAAO,CAAC,eAAe,CAAC,KAC/B,UAAU,CAAC,UAAU,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,CAAC,GAAG;YAClE,EAAE,EAAE,CACF,QAAQ,EAAE,gBAAgB,CAAC,OAAO,EAAE,IAAI,CAAC,GAAG,MAAM,KAC/C,UAAU,CAAC,UAAU,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC;SACnE,CAAC;KACH,CAAC;IACF;;;;;;;OAOG;IACH,KAAK,EAAE,CACL,OAAO,CAAC,EAAE,UAAU,KACjB,GAAG,CAAC,UAAU,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC;IAC3D;;OAEG;IACH,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC,OAAO,CAAC,CAAC;CACzC,CAAC;AAIF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,wBAAgB,GAAG,CAEjB,UAAU,SAAS,cAAc,CAAC,QAAQ,CAAC,GAAG,EAAE,EAChD,OAAO,SAAS,OAAO,GAAG,EAAE,EAC5B,QAAQ,SAAS,OAAO,GAAG,EAAE,EAC7B,SAAS,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,EAAE,EAC7C,MAAM,SAAS,KAAK,GAAG,KAAK,KACzB,UAAU,CAAC,UAAU,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,CAAC,CA4FhE"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module builders
|
|
3
|
+
* @category Builders
|
|
4
|
+
*
|
|
5
|
+
* Public-facing fluent builders for composing event-sourced applications:
|
|
6
|
+
* `state` (aggregates), `slice` (vertical-slice modules), `projection`
|
|
7
|
+
* (read-model updaters), and `act` (the orchestrator builder).
|
|
8
|
+
*/
|
|
9
|
+
export * from "./act-builder.js";
|
|
10
|
+
export * from "./projection-builder.js";
|
|
11
|
+
export * from "./slice-builder.js";
|
|
12
|
+
export * from "./state-builder.js";
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/builders/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,cAAc,kBAAkB,CAAC;AACjC,cAAc,yBAAyB,CAAC;AACxC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module projection-builder
|
|
3
|
+
* @category Builders
|
|
4
|
+
*
|
|
5
|
+
* Fluent builder for composing projection handlers — read-model updaters
|
|
6
|
+
* that react to events and update external state (databases, caches, etc.).
|
|
7
|
+
*
|
|
8
|
+
* Projections differ from slices: they don't contain states, don't dispatch
|
|
9
|
+
* actions, and are pure side-effect handlers routed to a named stream.
|
|
10
|
+
*/
|
|
11
|
+
import type { ZodType } from "zod";
|
|
12
|
+
import type { BatchHandler, Committed, EventRegister, ReactionResolver, Schema, Schemas } from "../types/index.js";
|
|
13
|
+
/**
|
|
14
|
+
* A self-contained projection grouping read-model update handlers.
|
|
15
|
+
* Projections are composed into an Act orchestrator via `act().withProjection(projection)`.
|
|
16
|
+
*
|
|
17
|
+
* @template TEvents - Event schemas handled by this projection
|
|
18
|
+
*/
|
|
19
|
+
export type Projection<TEvents extends Schemas> = {
|
|
20
|
+
readonly _tag: "Projection";
|
|
21
|
+
readonly events: EventRegister<TEvents>;
|
|
22
|
+
readonly target?: string;
|
|
23
|
+
readonly batchHandler?: BatchHandler<TEvents>;
|
|
24
|
+
};
|
|
25
|
+
/** Helper: a single-key record mapping an event name to its Zod schema. */
|
|
26
|
+
type EventEntry<TKey extends string = string, TData extends Schema = Schema> = {
|
|
27
|
+
[P in TKey]: ZodType<TData>;
|
|
28
|
+
};
|
|
29
|
+
/** Infer the handler-result type after registering one event. */
|
|
30
|
+
type DoResult<TEvents extends Schemas, TKey extends string, TData extends Schema, TTarget extends string | undefined = undefined> = ProjectionBuilder<TEvents & {
|
|
31
|
+
[P in TKey]: TData;
|
|
32
|
+
}, TTarget> & {
|
|
33
|
+
to: (resolver: ReactionResolver<TEvents & {
|
|
34
|
+
[P in TKey]: TData;
|
|
35
|
+
}, TKey> | string) => ProjectionBuilder<TEvents & {
|
|
36
|
+
[P in TKey]: TData;
|
|
37
|
+
}, TTarget>;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Fluent builder interface for composing projections.
|
|
41
|
+
*
|
|
42
|
+
* When a static target is provided via `projection("target")`, the builder
|
|
43
|
+
* exposes a `.batch()` method for registering a batch handler that processes
|
|
44
|
+
* all events in a single call.
|
|
45
|
+
*
|
|
46
|
+
* @template TEvents - Event schemas
|
|
47
|
+
* @template TTarget - Static target string or undefined
|
|
48
|
+
*/
|
|
49
|
+
export type ProjectionBuilder<TEvents extends Schemas, TTarget extends string | undefined = undefined> = {
|
|
50
|
+
/**
|
|
51
|
+
* Begins defining a projection handler for a specific event.
|
|
52
|
+
*
|
|
53
|
+
* Pass a `{ EventName: schema }` record — use shorthand `{ EventName }`
|
|
54
|
+
* when the variable name matches the event name. The key becomes the
|
|
55
|
+
* event name, the value the Zod schema.
|
|
56
|
+
*/
|
|
57
|
+
on: <TKey extends string, TData extends Schema>(entry: EventEntry<TKey, TData>) => {
|
|
58
|
+
do: (handler: (event: Committed<TEvents & {
|
|
59
|
+
[P in TKey]: TData;
|
|
60
|
+
}, TKey>, stream: string) => Promise<void>) => DoResult<TEvents, TKey, TData, TTarget>;
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Builds and returns the Projection data structure.
|
|
64
|
+
*/
|
|
65
|
+
build: () => Projection<TEvents>;
|
|
66
|
+
/**
|
|
67
|
+
* The registered event schemas and their reaction maps.
|
|
68
|
+
*/
|
|
69
|
+
readonly events: EventRegister<TEvents>;
|
|
70
|
+
} & (TTarget extends string ? {
|
|
71
|
+
/**
|
|
72
|
+
* Registers a batch handler that processes all events in a single call.
|
|
73
|
+
*
|
|
74
|
+
* Only available on projections with a static target (`projection("target")`).
|
|
75
|
+
* The handler receives a discriminated union of all declared events,
|
|
76
|
+
* enabling bulk DB operations in a single transaction.
|
|
77
|
+
*
|
|
78
|
+
* When defined, the batch handler is always called — even for a single event.
|
|
79
|
+
* Individual `.do()` handlers serve as fallback for projections without `.batch()`.
|
|
80
|
+
*/
|
|
81
|
+
batch: (handler: BatchHandler<TEvents>) => {
|
|
82
|
+
build: () => Projection<TEvents>;
|
|
83
|
+
};
|
|
84
|
+
} : {});
|
|
85
|
+
/**
|
|
86
|
+
* Creates a new projection builder with a static target stream.
|
|
87
|
+
*
|
|
88
|
+
* All handlers inherit the target resolver automatically. Enables `.batch()`
|
|
89
|
+
* for bulk event processing in a single transaction.
|
|
90
|
+
*
|
|
91
|
+
* @param target - Static target stream for all handlers
|
|
92
|
+
*/
|
|
93
|
+
export declare function projection<TEvents extends Schemas = {}>(target: string): ProjectionBuilder<TEvents, string>;
|
|
94
|
+
/**
|
|
95
|
+
* Creates a new projection builder without a default target.
|
|
96
|
+
*
|
|
97
|
+
* Use per-handler `.to()` to route events to different streams.
|
|
98
|
+
*/
|
|
99
|
+
export declare function projection<TEvents extends Schemas = {}>(target?: undefined): ProjectionBuilder<TEvents, undefined>;
|
|
100
|
+
export {};
|
|
101
|
+
//# sourceMappingURL=projection-builder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"projection-builder.d.ts","sourceRoot":"","sources":["../../../src/builders/projection-builder.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AAEnC,OAAO,KAAK,EACV,YAAY,EACZ,SAAS,EACT,aAA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