@graphrefly/graphrefly 0.1.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/LICENSE +21 -0
- package/README.md +234 -0
- package/dist/chunk-5X3LAO3B.js +1571 -0
- package/dist/chunk-5X3LAO3B.js.map +1 -0
- package/dist/chunk-6W5SGIGB.js +1793 -0
- package/dist/chunk-6W5SGIGB.js.map +1 -0
- package/dist/chunk-CP6MNKAA.js +97 -0
- package/dist/chunk-CP6MNKAA.js.map +1 -0
- package/dist/chunk-HP7OKEOE.js +107 -0
- package/dist/chunk-HP7OKEOE.js.map +1 -0
- package/dist/chunk-KWXPDASV.js +781 -0
- package/dist/chunk-KWXPDASV.js.map +1 -0
- package/dist/chunk-O3PI7W45.js +68 -0
- package/dist/chunk-O3PI7W45.js.map +1 -0
- package/dist/chunk-QW7H3ICI.js +1372 -0
- package/dist/chunk-QW7H3ICI.js.map +1 -0
- package/dist/chunk-VPS7L64N.js +4785 -0
- package/dist/chunk-VPS7L64N.js.map +1 -0
- package/dist/chunk-Z4Y4FMQN.js +1097 -0
- package/dist/chunk-Z4Y4FMQN.js.map +1 -0
- package/dist/compat/nestjs/index.cjs +4883 -0
- package/dist/compat/nestjs/index.cjs.map +1 -0
- package/dist/compat/nestjs/index.d.cts +7 -0
- package/dist/compat/nestjs/index.d.ts +7 -0
- package/dist/compat/nestjs/index.js +84 -0
- package/dist/compat/nestjs/index.js.map +1 -0
- package/dist/core/index.cjs +1632 -0
- package/dist/core/index.cjs.map +1 -0
- package/dist/core/index.d.cts +2 -0
- package/dist/core/index.d.ts +2 -0
- package/dist/core/index.js +90 -0
- package/dist/core/index.js.map +1 -0
- package/dist/extra/index.cjs +6885 -0
- package/dist/extra/index.cjs.map +1 -0
- package/dist/extra/index.d.cts +5 -0
- package/dist/extra/index.d.ts +5 -0
- package/dist/extra/index.js +290 -0
- package/dist/extra/index.js.map +1 -0
- package/dist/graph/index.cjs +3225 -0
- package/dist/graph/index.cjs.map +1 -0
- package/dist/graph/index.d.cts +3 -0
- package/dist/graph/index.d.ts +3 -0
- package/dist/graph/index.js +25 -0
- package/dist/graph/index.js.map +1 -0
- package/dist/graph-CL_ZDAj9.d.cts +605 -0
- package/dist/graph-D18qmsNm.d.ts +605 -0
- package/dist/index-B6SsZs2h.d.cts +3463 -0
- package/dist/index-B7eOdgEx.d.ts +449 -0
- package/dist/index-BHUvlQ3v.d.ts +3463 -0
- package/dist/index-BtK55IE2.d.ts +231 -0
- package/dist/index-BvhgZRHK.d.cts +231 -0
- package/dist/index-Bvy_6CaN.d.ts +452 -0
- package/dist/index-C3BMRmmp.d.cts +449 -0
- package/dist/index-C5mqLhMX.d.cts +452 -0
- package/dist/index-CP_QvbWu.d.ts +940 -0
- package/dist/index-D_geH2Bm.d.cts +940 -0
- package/dist/index.cjs +14843 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1517 -0
- package/dist/index.d.ts +1517 -0
- package/dist/index.js +3649 -0
- package/dist/index.js.map +1 -0
- package/dist/meta-BsF6Sag9.d.cts +607 -0
- package/dist/meta-BsF6Sag9.d.ts +607 -0
- package/dist/patterns/reactive-layout/index.cjs +4143 -0
- package/dist/patterns/reactive-layout/index.cjs.map +1 -0
- package/dist/patterns/reactive-layout/index.d.cts +3 -0
- package/dist/patterns/reactive-layout/index.d.ts +3 -0
- package/dist/patterns/reactive-layout/index.js +38 -0
- package/dist/patterns/reactive-layout/index.js.map +1 -0
- package/dist/reactive-log-BfvfNWQh.d.cts +137 -0
- package/dist/reactive-log-ohLmTXoZ.d.ts +137 -0
- package/package.json +256 -0
|
@@ -0,0 +1,940 @@
|
|
|
1
|
+
import { R as ReactiveLogSnapshot, o as observeGraph$, c as observeNode$, t as toMessages$, d as toObservable } from './reactive-log-BfvfNWQh.cjs';
|
|
2
|
+
import { OnModuleInit, OnModuleDestroy, ExecutionContext, CanActivate, DynamicModule } from '@nestjs/common';
|
|
3
|
+
import { ModuleRef } from '@nestjs/core';
|
|
4
|
+
import { G as Graph, a as GraphOptions, q as GraphPersistSnapshot } from './graph-CL_ZDAj9.cjs';
|
|
5
|
+
import { A as Actor, N as Node } from './meta-BsF6Sag9.cjs';
|
|
6
|
+
|
|
7
|
+
/** Class constructor key for decorator registries and Nest `ModuleRef.get()`. */
|
|
8
|
+
type DecoratorHostConstructor = abstract new (...args: unknown[]) => unknown;
|
|
9
|
+
/**
|
|
10
|
+
* TC39 Stage 3 class method decorator first argument (the method itself).
|
|
11
|
+
* Narrower than `Function` for Biome `noBannedTypes`.
|
|
12
|
+
*/
|
|
13
|
+
type DecoratorBoundMethod = (...args: unknown[]) => unknown;
|
|
14
|
+
interface OnGraphEventMeta {
|
|
15
|
+
nodeName: string;
|
|
16
|
+
methodKey: string | symbol;
|
|
17
|
+
}
|
|
18
|
+
interface GraphIntervalMeta {
|
|
19
|
+
ms: number;
|
|
20
|
+
methodKey: string | symbol;
|
|
21
|
+
}
|
|
22
|
+
interface GraphCronMeta {
|
|
23
|
+
expr: string;
|
|
24
|
+
methodKey: string | symbol;
|
|
25
|
+
}
|
|
26
|
+
/** Registry: constructor → event handler metadata. */
|
|
27
|
+
declare const EVENT_HANDLERS: Map<DecoratorHostConstructor, OnGraphEventMeta[]>;
|
|
28
|
+
/** Registry: constructor → interval metadata. */
|
|
29
|
+
declare const INTERVAL_HANDLERS: Map<DecoratorHostConstructor, GraphIntervalMeta[]>;
|
|
30
|
+
/** Registry: constructor → cron metadata. */
|
|
31
|
+
declare const CRON_HANDLERS: Map<DecoratorHostConstructor, GraphCronMeta[]>;
|
|
32
|
+
interface CommandHandlerMeta {
|
|
33
|
+
cqrsName: string;
|
|
34
|
+
commandName: string;
|
|
35
|
+
methodKey: string | symbol;
|
|
36
|
+
}
|
|
37
|
+
interface EventHandlerMeta {
|
|
38
|
+
cqrsName: string;
|
|
39
|
+
eventName: string;
|
|
40
|
+
methodKey: string | symbol;
|
|
41
|
+
}
|
|
42
|
+
interface QueryHandlerMeta {
|
|
43
|
+
cqrsName: string;
|
|
44
|
+
projectionName: string;
|
|
45
|
+
methodKey: string | symbol;
|
|
46
|
+
}
|
|
47
|
+
interface SagaHandlerMeta {
|
|
48
|
+
cqrsName: string;
|
|
49
|
+
eventNames: readonly string[];
|
|
50
|
+
sagaName: string;
|
|
51
|
+
methodKey: string | symbol;
|
|
52
|
+
}
|
|
53
|
+
/** Registry: constructor → command handler metadata. */
|
|
54
|
+
declare const COMMAND_HANDLERS: Map<DecoratorHostConstructor, CommandHandlerMeta[]>;
|
|
55
|
+
/** Registry: constructor → event handler metadata. */
|
|
56
|
+
declare const CQRS_EVENT_HANDLERS: Map<DecoratorHostConstructor, EventHandlerMeta[]>;
|
|
57
|
+
/** Registry: constructor → query handler metadata. */
|
|
58
|
+
declare const QUERY_HANDLERS: Map<DecoratorHostConstructor, QueryHandlerMeta[]>;
|
|
59
|
+
/** Registry: constructor → saga handler metadata. */
|
|
60
|
+
declare const SAGA_HANDLERS: Map<DecoratorHostConstructor, SagaHandlerMeta[]>;
|
|
61
|
+
/**
|
|
62
|
+
* Inject a `Graph` instance into a NestJS service or controller.
|
|
63
|
+
*
|
|
64
|
+
* - No argument → injects the root graph (from `forRoot()`).
|
|
65
|
+
* - With `name` → injects the named feature graph (from `forFeature({ name })`).
|
|
66
|
+
* - With `"request"` → injects the request-scoped graph (requires `requestScope: true`).
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```ts
|
|
70
|
+
* @Injectable()
|
|
71
|
+
* export class PaymentService {
|
|
72
|
+
* constructor(
|
|
73
|
+
* @InjectGraph() private root: Graph,
|
|
74
|
+
* @InjectGraph("payments") private payments: Graph,
|
|
75
|
+
* ) {}
|
|
76
|
+
* }
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
declare function InjectGraph(name?: string): ParameterDecorator & PropertyDecorator;
|
|
80
|
+
/**
|
|
81
|
+
* Inject a `CqrsGraph` instance into a NestJS service or controller.
|
|
82
|
+
*
|
|
83
|
+
* Typed alternative to `@InjectGraph(name)` — returns `CqrsGraph` instead of `Graph`,
|
|
84
|
+
* giving access to `.command()`, `.dispatch()`, `.event()`, `.projection()`, `.saga()`.
|
|
85
|
+
*
|
|
86
|
+
* @param name - The CQRS graph name (from `forCqrs({ name })`).
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```ts
|
|
90
|
+
* @Injectable()
|
|
91
|
+
* export class OrderService {
|
|
92
|
+
* constructor(@InjectCqrsGraph("orders") private orders: CqrsGraph) {
|
|
93
|
+
* orders.dispatch("placeOrder", { id: "1" }); // fully typed
|
|
94
|
+
* }
|
|
95
|
+
* }
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
98
|
+
declare function InjectCqrsGraph(name: string): ParameterDecorator & PropertyDecorator;
|
|
99
|
+
/**
|
|
100
|
+
* Inject a `Node` from the graph by its qualified path.
|
|
101
|
+
*
|
|
102
|
+
* The path must be declared in the `nodes` array of `forRoot()` or `forFeature()`.
|
|
103
|
+
* The module registers a factory provider that resolves the node from the root graph
|
|
104
|
+
* at injection time.
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* ```ts
|
|
108
|
+
* GraphReflyModule.forRoot({ nodes: ["payment::validate"] })
|
|
109
|
+
*
|
|
110
|
+
* @Injectable()
|
|
111
|
+
* export class PaymentService {
|
|
112
|
+
* constructor(@InjectNode("payment::validate") private validate: Node<boolean>) {}
|
|
113
|
+
* }
|
|
114
|
+
* ```
|
|
115
|
+
*/
|
|
116
|
+
declare function InjectNode(path: string): ParameterDecorator & PropertyDecorator;
|
|
117
|
+
/**
|
|
118
|
+
* Subscribe a method to a graph node's DATA emissions — replaces `@OnEvent()`.
|
|
119
|
+
*
|
|
120
|
+
* The method is called with the value payload on each `DATA` message from the
|
|
121
|
+
* named node. Routes through `graph.observe()` so actor guards are respected.
|
|
122
|
+
* Subscription is created on module init and disposed on destroy.
|
|
123
|
+
*
|
|
124
|
+
* For full protocol access (DIRTY, COMPLETE, ERROR, custom types), use
|
|
125
|
+
* `graph.observe()` directly instead of this decorator.
|
|
126
|
+
*
|
|
127
|
+
* @param nodeName - Qualified node path (e.g. `"orders::placed"`).
|
|
128
|
+
*
|
|
129
|
+
* @example
|
|
130
|
+
* ```ts
|
|
131
|
+
* @Injectable()
|
|
132
|
+
* export class OrderService {
|
|
133
|
+
* @OnGraphEvent("orders::placed")
|
|
134
|
+
* handleOrder(value: Order) { ... }
|
|
135
|
+
* }
|
|
136
|
+
* ```
|
|
137
|
+
*/
|
|
138
|
+
declare function OnGraphEvent(nodeName: string): (value: DecoratorBoundMethod, context: ClassMethodDecoratorContext) => void;
|
|
139
|
+
/**
|
|
140
|
+
* Run a method on a fixed interval — replaces `@Interval()` from `@nestjs/schedule`.
|
|
141
|
+
*
|
|
142
|
+
* Backed by a `fromTimer` node added to the root graph as `__schedule__.<className>.<methodName>`.
|
|
143
|
+
* Visible in `graph.describe()`, pausable via `graph.signal(name, [[PAUSE]])`.
|
|
144
|
+
*
|
|
145
|
+
* @param ms - Interval in milliseconds.
|
|
146
|
+
*
|
|
147
|
+
* @example
|
|
148
|
+
* ```ts
|
|
149
|
+
* @Injectable()
|
|
150
|
+
* export class CleanupService {
|
|
151
|
+
* @GraphInterval(5000)
|
|
152
|
+
* pruneStale() { ... }
|
|
153
|
+
* }
|
|
154
|
+
* ```
|
|
155
|
+
*/
|
|
156
|
+
declare function GraphInterval(ms: number): (value: DecoratorBoundMethod, context: ClassMethodDecoratorContext) => void;
|
|
157
|
+
/**
|
|
158
|
+
* Run a method on a cron schedule — replaces `@Cron()` from `@nestjs/schedule`.
|
|
159
|
+
*
|
|
160
|
+
* Backed by a `fromCron` node added to the root graph as `__schedule__.<className>.<methodName>`.
|
|
161
|
+
* Visible in `graph.describe()`, pausable via PAUSE/RESUME signals.
|
|
162
|
+
*
|
|
163
|
+
* @param expr - 5-field cron expression (`min hour dom month dow`).
|
|
164
|
+
*
|
|
165
|
+
* @example
|
|
166
|
+
* ```ts
|
|
167
|
+
* @Injectable()
|
|
168
|
+
* export class ReportService {
|
|
169
|
+
* @GraphCron("0 9 * * 1")
|
|
170
|
+
* weeklyReport() { ... }
|
|
171
|
+
* }
|
|
172
|
+
* ```
|
|
173
|
+
*/
|
|
174
|
+
declare function GraphCron(expr: string): (value: DecoratorBoundMethod, context: ClassMethodDecoratorContext) => void;
|
|
175
|
+
/**
|
|
176
|
+
* Register a method as a CQRS command handler — replaces `@CommandHandler()` from `@nestjs/cqrs`.
|
|
177
|
+
*
|
|
178
|
+
* The method receives `(payload, { emit })` — same signature as `CqrsGraph.command()` handlers.
|
|
179
|
+
* Wired reactively via the explorer on module init.
|
|
180
|
+
*
|
|
181
|
+
* @param cqrsName - Name of the CQRS graph (from `forCqrs({ name })`).
|
|
182
|
+
* @param commandName - Command to handle.
|
|
183
|
+
*
|
|
184
|
+
* @example
|
|
185
|
+
* ```ts
|
|
186
|
+
* @Injectable()
|
|
187
|
+
* export class OrderService {
|
|
188
|
+
* @CommandHandler("orders", "placeOrder")
|
|
189
|
+
* handlePlace(payload: PlaceOrderDto, { emit }: CommandActions) {
|
|
190
|
+
* emit("orderPlaced", { orderId: payload.id, amount: payload.amount });
|
|
191
|
+
* }
|
|
192
|
+
* }
|
|
193
|
+
* ```
|
|
194
|
+
*/
|
|
195
|
+
declare function CommandHandler$1(cqrsName: string, commandName: string): (value: DecoratorBoundMethod, context: ClassMethodDecoratorContext) => void;
|
|
196
|
+
/**
|
|
197
|
+
* Subscribe a method to CQRS event stream DATA — replaces `@EventsHandler()` from `@nestjs/cqrs`.
|
|
198
|
+
*
|
|
199
|
+
* The method receives each `CqrsEvent` envelope as events arrive. Subscription is reactive
|
|
200
|
+
* via `graph.observe()` — actor guards are respected.
|
|
201
|
+
*
|
|
202
|
+
* @param cqrsName - Name of the CQRS graph.
|
|
203
|
+
* @param eventName - Event stream to subscribe to.
|
|
204
|
+
*
|
|
205
|
+
* @example
|
|
206
|
+
* ```ts
|
|
207
|
+
* @Injectable()
|
|
208
|
+
* export class NotificationService {
|
|
209
|
+
* @EventHandler("orders", "orderPlaced")
|
|
210
|
+
* onOrderPlaced(event: CqrsEvent<{ orderId: string }>) {
|
|
211
|
+
* console.log("Order placed:", event.payload.orderId);
|
|
212
|
+
* }
|
|
213
|
+
* }
|
|
214
|
+
* ```
|
|
215
|
+
*/
|
|
216
|
+
declare function EventHandler(cqrsName: string, eventName: string): (value: DecoratorBoundMethod, context: ClassMethodDecoratorContext) => void;
|
|
217
|
+
/**
|
|
218
|
+
* Subscribe a method to CQRS projection changes — replaces `@QueryHandler()` from `@nestjs/cqrs`.
|
|
219
|
+
*
|
|
220
|
+
* The method is called reactively whenever the projection's value changes (DATA emission).
|
|
221
|
+
* This is push-based, not request-response — the projection recomputes on upstream events.
|
|
222
|
+
*
|
|
223
|
+
* @param cqrsName - Name of the CQRS graph.
|
|
224
|
+
* @param projectionName - Projection to observe.
|
|
225
|
+
*
|
|
226
|
+
* @example
|
|
227
|
+
* ```ts
|
|
228
|
+
* @Injectable()
|
|
229
|
+
* export class DashboardService {
|
|
230
|
+
* @QueryHandler("orders", "orderCount")
|
|
231
|
+
* onCountChanged(count: number) {
|
|
232
|
+
* this.broadcast({ type: "orderCount", value: count });
|
|
233
|
+
* }
|
|
234
|
+
* }
|
|
235
|
+
* ```
|
|
236
|
+
*/
|
|
237
|
+
declare function QueryHandler(cqrsName: string, projectionName: string): (value: DecoratorBoundMethod, context: ClassMethodDecoratorContext) => void;
|
|
238
|
+
/**
|
|
239
|
+
* Register a method as a CQRS saga — replaces RxJS saga streams from `@nestjs/cqrs`.
|
|
240
|
+
*
|
|
241
|
+
* The method receives each new `CqrsEvent` from the specified event streams. Backed by
|
|
242
|
+
* `CqrsGraph.saga()` — tracks last-processed entry, only delivers new events.
|
|
243
|
+
*
|
|
244
|
+
* @param cqrsName - Name of the CQRS graph.
|
|
245
|
+
* @param sagaName - Name for this saga node in the graph.
|
|
246
|
+
* @param eventNames - Event streams to react to.
|
|
247
|
+
*
|
|
248
|
+
* @example
|
|
249
|
+
* ```ts
|
|
250
|
+
* @Injectable()
|
|
251
|
+
* export class FulfillmentService {
|
|
252
|
+
* @SagaHandler("orders", "fulfillment", ["orderPlaced", "paymentConfirmed"])
|
|
253
|
+
* onOrderFlow(event: CqrsEvent) {
|
|
254
|
+
* if (event.type === "paymentConfirmed") this.shipOrder(event.payload);
|
|
255
|
+
* }
|
|
256
|
+
* }
|
|
257
|
+
* ```
|
|
258
|
+
*/
|
|
259
|
+
declare function SagaHandler$1(cqrsName: string, sagaName: string, eventNames: readonly string[]): (value: DecoratorBoundMethod, context: ClassMethodDecoratorContext) => void;
|
|
260
|
+
|
|
261
|
+
declare class GraphReflyEventExplorer implements OnModuleInit, OnModuleDestroy {
|
|
262
|
+
private readonly graph;
|
|
263
|
+
private readonly moduleRef;
|
|
264
|
+
private readonly disposers;
|
|
265
|
+
private readonly scheduleNodeNames;
|
|
266
|
+
constructor(graph: Graph, moduleRef: ModuleRef);
|
|
267
|
+
onModuleInit(): void;
|
|
268
|
+
onModuleDestroy(): void;
|
|
269
|
+
private wireEvents;
|
|
270
|
+
private wireEventHandler;
|
|
271
|
+
private wireIntervals;
|
|
272
|
+
private wireIntervalHandler;
|
|
273
|
+
private wireCrons;
|
|
274
|
+
private wireCronHandler;
|
|
275
|
+
private wireCqrsCommands;
|
|
276
|
+
private wireCqrsCommand;
|
|
277
|
+
private wireCqrsEvents;
|
|
278
|
+
private wireCqrsEventHandler;
|
|
279
|
+
private wireCqrsQueries;
|
|
280
|
+
private wireCqrsQuery;
|
|
281
|
+
private wireCqrsSagas;
|
|
282
|
+
private wireCqrsSaga;
|
|
283
|
+
private observeNode;
|
|
284
|
+
private observeNodeOn;
|
|
285
|
+
private resolveCqrsGraph;
|
|
286
|
+
private resolveInstance;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* Client-to-server commands for the WebSocket observe protocol.
|
|
291
|
+
*/
|
|
292
|
+
type ObserveWsCommand = {
|
|
293
|
+
type: "subscribe";
|
|
294
|
+
path: string;
|
|
295
|
+
} | {
|
|
296
|
+
type: "unsubscribe";
|
|
297
|
+
path: string;
|
|
298
|
+
} | {
|
|
299
|
+
type: "ack";
|
|
300
|
+
path: string;
|
|
301
|
+
count?: number;
|
|
302
|
+
};
|
|
303
|
+
/**
|
|
304
|
+
* Server-to-client messages for the WebSocket observe protocol.
|
|
305
|
+
*/
|
|
306
|
+
type ObserveWsMessage<T = unknown> = {
|
|
307
|
+
type: "data";
|
|
308
|
+
path: string;
|
|
309
|
+
value: T;
|
|
310
|
+
} | {
|
|
311
|
+
type: "error";
|
|
312
|
+
path: string;
|
|
313
|
+
error: string;
|
|
314
|
+
} | {
|
|
315
|
+
type: "complete";
|
|
316
|
+
path: string;
|
|
317
|
+
} | {
|
|
318
|
+
type: "subscribed";
|
|
319
|
+
path: string;
|
|
320
|
+
} | {
|
|
321
|
+
type: "unsubscribed";
|
|
322
|
+
path: string;
|
|
323
|
+
} | {
|
|
324
|
+
type: "err";
|
|
325
|
+
message: string;
|
|
326
|
+
};
|
|
327
|
+
type ObserveSSEOptions = {
|
|
328
|
+
actor?: Actor;
|
|
329
|
+
serialize?: (value: unknown) => string;
|
|
330
|
+
keepAliveMs?: number;
|
|
331
|
+
signal?: AbortSignal;
|
|
332
|
+
/** Pending DATA count at which PAUSE is sent upstream. Enables backpressure when set. */
|
|
333
|
+
highWaterMark?: number;
|
|
334
|
+
/** Pending DATA count at which RESUME is sent upstream. Defaults to `Math.floor(highWaterMark / 2)`. */
|
|
335
|
+
lowWaterMark?: number;
|
|
336
|
+
};
|
|
337
|
+
/**
|
|
338
|
+
* Creates an SSE `ReadableStream` that streams DATA values from a graph node.
|
|
339
|
+
*
|
|
340
|
+
* Routes through `graph.observe(path, { actor })` so node guards are respected.
|
|
341
|
+
* The stream emits `event: data` for DATA, `event: error` for ERROR, and
|
|
342
|
+
* `event: complete` for COMPLETE (then closes). TEARDOWN also closes the stream.
|
|
343
|
+
*
|
|
344
|
+
* @param graph - The graph to observe.
|
|
345
|
+
* @param path - Qualified node path to observe.
|
|
346
|
+
* @param opts - Actor context, serialization, keep-alive.
|
|
347
|
+
* @returns A `ReadableStream<Uint8Array>` suitable for NestJS SSE endpoints.
|
|
348
|
+
*
|
|
349
|
+
* @example
|
|
350
|
+
* ```ts
|
|
351
|
+
* @Sse("events/:path")
|
|
352
|
+
* streamEvents(@Param("path") path: string, @Req() req: Request) {
|
|
353
|
+
* return observeSSE(this.graph, path, { actor: getActor(req) });
|
|
354
|
+
* }
|
|
355
|
+
* ```
|
|
356
|
+
*/
|
|
357
|
+
declare function observeSSE(graph: Graph, path: string, opts?: ObserveSSEOptions): ReadableStream<Uint8Array>;
|
|
358
|
+
type ObserveSubscriptionOptions<T = unknown> = {
|
|
359
|
+
actor?: Actor;
|
|
360
|
+
/**
|
|
361
|
+
* Optional value filter. Only matching DATA values are enqueued.
|
|
362
|
+
*
|
|
363
|
+
* **Note:** `filter` and `highWaterMark` are semantically decoupled — the
|
|
364
|
+
* watermark counts items that pass the filter, not total upstream work.
|
|
365
|
+
* If the filter rejects most items, backpressure may never engage despite
|
|
366
|
+
* high upstream throughput. For upstream-level resource protection, place a
|
|
367
|
+
* filtering derived node in the graph before the observe point instead.
|
|
368
|
+
*/
|
|
369
|
+
filter?: (value: T) => boolean;
|
|
370
|
+
/** Pending DATA count at which PAUSE is sent upstream. Enables backpressure when set. */
|
|
371
|
+
highWaterMark?: number;
|
|
372
|
+
/** Pending DATA count at which RESUME is sent upstream. Defaults to `Math.floor(highWaterMark / 2)`. */
|
|
373
|
+
lowWaterMark?: number;
|
|
374
|
+
};
|
|
375
|
+
/**
|
|
376
|
+
* Creates an `AsyncIterableIterator` that yields DATA values from a graph node.
|
|
377
|
+
*
|
|
378
|
+
* Designed for GraphQL subscription resolvers (Apollo, Mercurius, etc.).
|
|
379
|
+
* Routes through `graph.observe(path, { actor })` for guard-scoped access.
|
|
380
|
+
*
|
|
381
|
+
* The iterator completes on COMPLETE/TEARDOWN and throws on ERROR.
|
|
382
|
+
*
|
|
383
|
+
* @param graph - The graph to observe.
|
|
384
|
+
* @param path - Qualified node path to observe.
|
|
385
|
+
* @param opts - Actor context, optional value filter.
|
|
386
|
+
* @returns An async iterable that yields DATA payloads.
|
|
387
|
+
*
|
|
388
|
+
* @example
|
|
389
|
+
* ```ts
|
|
390
|
+
* // Apollo-style resolver
|
|
391
|
+
* Subscription: {
|
|
392
|
+
* orderStatus: {
|
|
393
|
+
* subscribe: (_parent, args, ctx) =>
|
|
394
|
+
* observeSubscription(ctx.graph, `orders::${args.id}::status`, {
|
|
395
|
+
* actor: ctx.actor,
|
|
396
|
+
* }),
|
|
397
|
+
* },
|
|
398
|
+
* }
|
|
399
|
+
* ```
|
|
400
|
+
*/
|
|
401
|
+
declare function observeSubscription<T = unknown>(graph: Graph, path: string, opts?: ObserveSubscriptionOptions<T>): AsyncIterableIterator<T>;
|
|
402
|
+
type ObserveGatewayOptions = {
|
|
403
|
+
extractActor?: (client: unknown) => Actor | undefined;
|
|
404
|
+
parse?: (data: string) => ObserveWsCommand;
|
|
405
|
+
/** Pending DATA count per subscription at which PAUSE is sent upstream. Enables backpressure when set. */
|
|
406
|
+
highWaterMark?: number;
|
|
407
|
+
/** Pending DATA count per subscription at which RESUME is sent upstream. Defaults to `Math.floor(highWaterMark / 2)`. */
|
|
408
|
+
lowWaterMark?: number;
|
|
409
|
+
};
|
|
410
|
+
/**
|
|
411
|
+
* Manages per-client WebSocket subscriptions to graph nodes via `observe()`.
|
|
412
|
+
*
|
|
413
|
+
* Not a NestJS decorator or base class — a standalone helper that can be
|
|
414
|
+
* wired into any WebSocket gateway. Each client can subscribe/unsubscribe
|
|
415
|
+
* to individual node paths. Actor-scoped observation respects node guards.
|
|
416
|
+
*
|
|
417
|
+
* @example
|
|
418
|
+
* ```ts
|
|
419
|
+
* @WebSocketGateway()
|
|
420
|
+
* export class GraphGateway {
|
|
421
|
+
* private gw = new ObserveGateway(this.graph);
|
|
422
|
+
*
|
|
423
|
+
* constructor(@InjectGraph() private graph: Graph) {}
|
|
424
|
+
*
|
|
425
|
+
* handleConnection(client: WebSocket) {
|
|
426
|
+
* this.gw.handleConnection(client);
|
|
427
|
+
* }
|
|
428
|
+
*
|
|
429
|
+
* handleDisconnect(client: WebSocket) {
|
|
430
|
+
* this.gw.handleDisconnect(client);
|
|
431
|
+
* }
|
|
432
|
+
*
|
|
433
|
+
* @SubscribeMessage("observe")
|
|
434
|
+
* onObserve(client: WebSocket, data: unknown) {
|
|
435
|
+
* this.gw.handleMessage(client, data);
|
|
436
|
+
* }
|
|
437
|
+
* }
|
|
438
|
+
* ```
|
|
439
|
+
*/
|
|
440
|
+
declare class ObserveGateway {
|
|
441
|
+
private readonly graph;
|
|
442
|
+
private readonly clients;
|
|
443
|
+
private readonly extractActor;
|
|
444
|
+
private readonly parse;
|
|
445
|
+
private readonly highWaterMark;
|
|
446
|
+
private readonly lowWaterMark;
|
|
447
|
+
constructor(graph: Graph, opts?: ObserveGatewayOptions);
|
|
448
|
+
/**
|
|
449
|
+
* Register a new client. Call from `handleConnection`.
|
|
450
|
+
*/
|
|
451
|
+
handleConnection(client: unknown): void;
|
|
452
|
+
/**
|
|
453
|
+
* Unregister a client and dispose all its subscriptions. Call from `handleDisconnect`.
|
|
454
|
+
*/
|
|
455
|
+
handleDisconnect(client: unknown): void;
|
|
456
|
+
/**
|
|
457
|
+
* Handle an incoming client message (subscribe/unsubscribe/ack command).
|
|
458
|
+
*
|
|
459
|
+
* @param client - The WebSocket client reference.
|
|
460
|
+
* @param raw - Raw message data (string or parsed object).
|
|
461
|
+
* @param send - Function to send a message back to the client.
|
|
462
|
+
* Defaults to `client.send(JSON.stringify(msg))`.
|
|
463
|
+
*/
|
|
464
|
+
handleMessage(client: unknown, raw: unknown, send?: (msg: ObserveWsMessage) => void): void;
|
|
465
|
+
/**
|
|
466
|
+
* Number of active subscriptions for a client. Useful for tests.
|
|
467
|
+
*/
|
|
468
|
+
subscriptionCount(client: unknown): number;
|
|
469
|
+
/**
|
|
470
|
+
* Dispose all clients and subscriptions.
|
|
471
|
+
*/
|
|
472
|
+
destroy(): void;
|
|
473
|
+
private subscribe;
|
|
474
|
+
private unsubscribe;
|
|
475
|
+
private ack;
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
/**
|
|
479
|
+
* Property name under which the extracted {@link Actor} is stored on the
|
|
480
|
+
* request object. Downstream code (controllers, gateways) reads
|
|
481
|
+
* `req[ACTOR_KEY]` to pass actor context to graph operations.
|
|
482
|
+
*/
|
|
483
|
+
declare const ACTOR_KEY: "graphReflyActor";
|
|
484
|
+
/**
|
|
485
|
+
* Extracts a GraphReFly {@link Actor} from a NestJS {@link ExecutionContext}.
|
|
486
|
+
*
|
|
487
|
+
* Return `undefined` to fall back to {@link DEFAULT_ACTOR}.
|
|
488
|
+
*/
|
|
489
|
+
type ActorExtractor = (context: ExecutionContext) => Actor | undefined;
|
|
490
|
+
/**
|
|
491
|
+
* Creates an {@link ActorExtractor} that reads a JWT payload from `req.user`
|
|
492
|
+
* (the standard Passport.js location) and maps it to a GraphReFly {@link Actor}.
|
|
493
|
+
*
|
|
494
|
+
* @param mapping - Optional transform from the JWT payload to an Actor.
|
|
495
|
+
* When omitted, the payload is used directly (must have `type` and `id`).
|
|
496
|
+
*
|
|
497
|
+
* @example
|
|
498
|
+
* ```ts
|
|
499
|
+
* // Default: req.user is already { type, id, ... }
|
|
500
|
+
* GraphReflyGuard(fromJwtPayload())
|
|
501
|
+
*
|
|
502
|
+
* // Custom mapping from your JWT claims
|
|
503
|
+
* GraphReflyGuard(fromJwtPayload((payload) => ({
|
|
504
|
+
* type: payload.role === "admin" ? "human" : "llm",
|
|
505
|
+
* id: payload.sub,
|
|
506
|
+
* org: payload.org_id,
|
|
507
|
+
* })))
|
|
508
|
+
* ```
|
|
509
|
+
*/
|
|
510
|
+
declare function fromJwtPayload(mapping?: (payload: unknown) => Actor): ActorExtractor;
|
|
511
|
+
/**
|
|
512
|
+
* Creates an {@link ActorExtractor} that reads an Actor from a request header.
|
|
513
|
+
*
|
|
514
|
+
* The header value is parsed as JSON. Useful for service-to-service calls
|
|
515
|
+
* where the caller embeds actor context in a custom header.
|
|
516
|
+
*
|
|
517
|
+
* @param headerName - HTTP header name (case-insensitive). Default: `"x-graphrefly-actor"`.
|
|
518
|
+
*
|
|
519
|
+
* @example
|
|
520
|
+
* ```ts
|
|
521
|
+
* GraphReflyGuard(fromHeader("x-actor"))
|
|
522
|
+
* ```
|
|
523
|
+
*/
|
|
524
|
+
declare function fromHeader(headerName?: string): ActorExtractor;
|
|
525
|
+
/**
|
|
526
|
+
* Reads the extracted {@link Actor} from a request object (set by {@link GraphReflyGuardImpl}).
|
|
527
|
+
*
|
|
528
|
+
* Returns {@link DEFAULT_ACTOR} if no actor was attached.
|
|
529
|
+
*
|
|
530
|
+
* @example
|
|
531
|
+
* ```ts
|
|
532
|
+
* @Get("status")
|
|
533
|
+
* getStatus(@Req() req: Request) {
|
|
534
|
+
* const actor = getActor(req);
|
|
535
|
+
* return this.graph.describe({ actor });
|
|
536
|
+
* }
|
|
537
|
+
* ```
|
|
538
|
+
*/
|
|
539
|
+
declare function getActor(req: unknown): Actor;
|
|
540
|
+
/**
|
|
541
|
+
* NestJS guard that extracts a GraphReFly {@link Actor} from the execution
|
|
542
|
+
* context and attaches it to the request as `req.graphReflyActor`.
|
|
543
|
+
*
|
|
544
|
+
* This guard always returns `true` (allows the request through). Access
|
|
545
|
+
* control is handled by GraphReFly node guards (`policy()`), not by this
|
|
546
|
+
* NestJS guard. The purpose is purely to **bridge** authentication context.
|
|
547
|
+
*
|
|
548
|
+
* @example
|
|
549
|
+
* ```ts
|
|
550
|
+
* // Global guard — every request gets an Actor
|
|
551
|
+
* app.useGlobalGuards(new GraphReflyGuardImpl(fromJwtPayload()));
|
|
552
|
+
*
|
|
553
|
+
* // Controller-scoped
|
|
554
|
+
* @UseGuards(GraphReflyGuard(fromJwtPayload()))
|
|
555
|
+
* @Controller("api")
|
|
556
|
+
* export class ApiController { ... }
|
|
557
|
+
* ```
|
|
558
|
+
*/
|
|
559
|
+
declare class GraphReflyGuardImpl implements CanActivate {
|
|
560
|
+
private readonly extractor;
|
|
561
|
+
constructor(extractor: ActorExtractor);
|
|
562
|
+
canActivate(context: ExecutionContext): boolean;
|
|
563
|
+
}
|
|
564
|
+
/**
|
|
565
|
+
* Factory that creates a {@link GraphReflyGuardImpl} instance. Use with
|
|
566
|
+
* NestJS `@UseGuards()` or `app.useGlobalGuards()`.
|
|
567
|
+
*
|
|
568
|
+
* @param extractor - How to extract an Actor from the request context.
|
|
569
|
+
* Defaults to {@link fromJwtPayload} (reads `req.user`).
|
|
570
|
+
*
|
|
571
|
+
* @example
|
|
572
|
+
* ```ts
|
|
573
|
+
* import { GraphReflyGuard, fromJwtPayload } from "@graphrefly/graphrefly-ts/compat/nestjs";
|
|
574
|
+
*
|
|
575
|
+
* @UseGuards(GraphReflyGuard())
|
|
576
|
+
* @Controller("graph")
|
|
577
|
+
* export class GraphController { ... }
|
|
578
|
+
* ```
|
|
579
|
+
*/
|
|
580
|
+
declare function GraphReflyGuard(extractor?: ActorExtractor): GraphReflyGuardImpl;
|
|
581
|
+
|
|
582
|
+
/**
|
|
583
|
+
* CQRS patterns (roadmap §4.5).
|
|
584
|
+
*
|
|
585
|
+
* Composition layer over reactiveLog (3.2), pipeline/sagas (4.1), event bus (4.2),
|
|
586
|
+
* projections (4.3). Guards (1.5) enforce command/query boundary.
|
|
587
|
+
*
|
|
588
|
+
* - `cqrs(name, opts?)` → `CqrsGraph` — top-level factory
|
|
589
|
+
* - `CqrsGraph.command(name, handler)` — write-only node; guard rejects `observe`
|
|
590
|
+
* - `CqrsGraph.event(name)` — backed by `reactiveLog`; append-only
|
|
591
|
+
* - `CqrsGraph.projection(name, events, reducer, initial)` — read-only derived; guard rejects `write`
|
|
592
|
+
* - `CqrsGraph.saga(name, events, handler)` — event-driven side effects
|
|
593
|
+
*/
|
|
594
|
+
|
|
595
|
+
/**
|
|
596
|
+
* Immutable envelope for events emitted by command handlers.
|
|
597
|
+
*
|
|
598
|
+
* `seq` is a per-graph monotonic counter that provides stable ordering when
|
|
599
|
+
* multiple events share the same `timestampNs` (same wall-clock tick).
|
|
600
|
+
*/
|
|
601
|
+
type CqrsEvent<T = unknown> = {
|
|
602
|
+
type: string;
|
|
603
|
+
payload: T;
|
|
604
|
+
/** Wall-clock nanoseconds (via `wallClockNs()`). */
|
|
605
|
+
timestampNs: number;
|
|
606
|
+
/** Monotonic sequence within this CqrsGraph instance. */
|
|
607
|
+
seq: number;
|
|
608
|
+
/** V0 identity of the event log node at append time (§6.0b). */
|
|
609
|
+
v0?: {
|
|
610
|
+
id: string;
|
|
611
|
+
version: number;
|
|
612
|
+
};
|
|
613
|
+
};
|
|
614
|
+
/**
|
|
615
|
+
* Opaque replay cursor returned by `loadEvents`. Pass it back to
|
|
616
|
+
* `loadEvents` to resume from the last position.
|
|
617
|
+
*/
|
|
618
|
+
type EventStoreCursor = {
|
|
619
|
+
readonly __brand?: "EventStoreCursor";
|
|
620
|
+
[key: string]: unknown;
|
|
621
|
+
};
|
|
622
|
+
/**
|
|
623
|
+
* Result of `loadEvents` — events plus an opaque cursor for resumption.
|
|
624
|
+
*/
|
|
625
|
+
type LoadEventsResult = {
|
|
626
|
+
events: CqrsEvent[];
|
|
627
|
+
cursor: EventStoreCursor | undefined;
|
|
628
|
+
};
|
|
629
|
+
/**
|
|
630
|
+
* Pluggable persistence for CQRS events.
|
|
631
|
+
*
|
|
632
|
+
* **`persist`:** Must be synchronous. Called from the dispatch path inside
|
|
633
|
+
* `batch()`. Adapters that need async I/O should buffer internally and
|
|
634
|
+
* expose a `flush()` method for explicit drain.
|
|
635
|
+
*/
|
|
636
|
+
interface EventStoreAdapter {
|
|
637
|
+
persist(event: CqrsEvent): void;
|
|
638
|
+
/**
|
|
639
|
+
* Load persisted events. When `cursor` is provided, returns only events
|
|
640
|
+
* after that position. The returned `cursor` should be passed to the next
|
|
641
|
+
* `loadEvents` call for incremental replay.
|
|
642
|
+
*/
|
|
643
|
+
loadEvents(eventType: string, cursor?: EventStoreCursor): LoadEventsResult | Promise<LoadEventsResult>;
|
|
644
|
+
/** Optional explicit flush for adapters with async I/O. */
|
|
645
|
+
flush?(): Promise<void>;
|
|
646
|
+
}
|
|
647
|
+
declare class MemoryEventStore implements EventStoreAdapter {
|
|
648
|
+
private readonly _store;
|
|
649
|
+
persist(event: CqrsEvent): void;
|
|
650
|
+
loadEvents(eventType: string, cursor?: EventStoreCursor): LoadEventsResult;
|
|
651
|
+
clear(): void;
|
|
652
|
+
}
|
|
653
|
+
type CommandActions = {
|
|
654
|
+
/** Append an event to a named event log (bypasses event guard). */
|
|
655
|
+
emit: (eventName: string, payload: unknown) => void;
|
|
656
|
+
};
|
|
657
|
+
/**
|
|
658
|
+
* Command handler receives the dispatch payload and actions to emit events.
|
|
659
|
+
*
|
|
660
|
+
* **Purity:** Handlers should not mutate the payload. Event emission via
|
|
661
|
+
* `actions.emit()` is the only sanctioned side effect.
|
|
662
|
+
*/
|
|
663
|
+
type CommandHandler<T = unknown> = (payload: T, actions: CommandActions) => void;
|
|
664
|
+
/**
|
|
665
|
+
* Projection reducer folds events into a read model.
|
|
666
|
+
*
|
|
667
|
+
* **Purity contract:** Reducers MUST be pure — return a new state value
|
|
668
|
+
* without mutating `state` or any event. The `state` parameter is the
|
|
669
|
+
* original `initial` value on every invocation (full event-sourcing replay),
|
|
670
|
+
* so mutation would corrupt future recomputations.
|
|
671
|
+
*/
|
|
672
|
+
type ProjectionReducer<TState = unknown, TEvent = unknown> = (state: TState, events: readonly CqrsEvent<TEvent>[]) => TState;
|
|
673
|
+
type SagaHandler<T = unknown> = (event: CqrsEvent<T>) => void;
|
|
674
|
+
type CqrsOptions = {
|
|
675
|
+
graph?: GraphOptions;
|
|
676
|
+
};
|
|
677
|
+
declare class CqrsGraph extends Graph {
|
|
678
|
+
private readonly _eventLogs;
|
|
679
|
+
private readonly _commandHandlers;
|
|
680
|
+
private readonly _projections;
|
|
681
|
+
private readonly _sagas;
|
|
682
|
+
private readonly _keepaliveDisposers;
|
|
683
|
+
private _eventStore;
|
|
684
|
+
private _seq;
|
|
685
|
+
constructor(name: string, opts?: CqrsOptions);
|
|
686
|
+
destroy(): void;
|
|
687
|
+
/**
|
|
688
|
+
* Register a named event stream backed by `reactiveLog`.
|
|
689
|
+
* Guard denies external `write` — only commands append internally.
|
|
690
|
+
*/
|
|
691
|
+
event(name: string): Node<ReactiveLogSnapshot<CqrsEvent>>;
|
|
692
|
+
/** Internal: append to an event log, auto-registering if needed. */
|
|
693
|
+
private _appendEvent;
|
|
694
|
+
/**
|
|
695
|
+
* Register a command with its handler. Guard denies `observe` (write-only).
|
|
696
|
+
* Use `dispatch(name, payload)` to execute.
|
|
697
|
+
*
|
|
698
|
+
* The command node carries dynamic `meta.error` — a reactive companion
|
|
699
|
+
* that holds the last handler error (or `null` on success).
|
|
700
|
+
*/
|
|
701
|
+
command<T = unknown>(name: string, handler: CommandHandler<T>): Node<T>;
|
|
702
|
+
/**
|
|
703
|
+
* Execute a registered command. Wraps the entire dispatch in `batch()` so
|
|
704
|
+
* the command node DATA and all emitted events settle atomically.
|
|
705
|
+
*
|
|
706
|
+
* If the handler throws, `meta.error` on the command node is set to the
|
|
707
|
+
* error and the exception is re-thrown.
|
|
708
|
+
*/
|
|
709
|
+
dispatch<T = unknown>(commandName: string, payload: T): void;
|
|
710
|
+
/**
|
|
711
|
+
* Register a read-only projection derived from event streams.
|
|
712
|
+
* Guard denies `write` — value is computed from events only.
|
|
713
|
+
*
|
|
714
|
+
* **Purity contract:** The `reducer` must be a pure function — it receives
|
|
715
|
+
* the original `initial` on every invocation (full event-sourcing replay).
|
|
716
|
+
* Never mutate `initial`; always return a new value.
|
|
717
|
+
*/
|
|
718
|
+
projection<TState>(name: string, eventNames: readonly string[], reducer: ProjectionReducer<TState>, initial: TState): Node<TState>;
|
|
719
|
+
/**
|
|
720
|
+
* Register an event-driven side effect. Runs handler for each **new** event
|
|
721
|
+
* from the specified streams (tracks last-processed entry count per stream).
|
|
722
|
+
*
|
|
723
|
+
* The saga node carries dynamic `meta.error` — a reactive companion that
|
|
724
|
+
* holds the last handler error (or `null` on success). Handler errors do
|
|
725
|
+
* not propagate out of the saga run (the event cursor still advances so
|
|
726
|
+
* the same entry is not delivered twice).
|
|
727
|
+
*/
|
|
728
|
+
saga<T = unknown>(name: string, eventNames: readonly string[], handler: SagaHandler<T>): Node<unknown>;
|
|
729
|
+
useEventStore(adapter: EventStoreAdapter): void;
|
|
730
|
+
/**
|
|
731
|
+
* Replay persisted events through a reducer to rebuild a read model.
|
|
732
|
+
* Requires an event store adapter wired via `useEventStore()`.
|
|
733
|
+
*/
|
|
734
|
+
rebuildProjection<TState>(eventNames: readonly string[], reducer: ProjectionReducer<TState>, initial: TState): Promise<TState>;
|
|
735
|
+
}
|
|
736
|
+
/**
|
|
737
|
+
* Create a CQRS graph container.
|
|
738
|
+
*
|
|
739
|
+
* @example
|
|
740
|
+
* ```ts
|
|
741
|
+
* const app = cqrs("orders");
|
|
742
|
+
* app.event("orderPlaced");
|
|
743
|
+
* app.command("placeOrder", (payload, { emit }) => {
|
|
744
|
+
* emit("orderPlaced", { orderId: payload.id, amount: payload.amount });
|
|
745
|
+
* });
|
|
746
|
+
* app.projection("orderCount", ["orderPlaced"], (_s, events) => events.length, 0);
|
|
747
|
+
* app.dispatch("placeOrder", { id: "1", amount: 100 });
|
|
748
|
+
* ```
|
|
749
|
+
*/
|
|
750
|
+
declare function cqrs(name: string, opts?: CqrsOptions): CqrsGraph;
|
|
751
|
+
|
|
752
|
+
type cqrs$1_CommandActions = CommandActions;
|
|
753
|
+
type cqrs$1_CommandHandler<T = unknown> = CommandHandler<T>;
|
|
754
|
+
type cqrs$1_CqrsEvent<T = unknown> = CqrsEvent<T>;
|
|
755
|
+
type cqrs$1_CqrsGraph = CqrsGraph;
|
|
756
|
+
declare const cqrs$1_CqrsGraph: typeof CqrsGraph;
|
|
757
|
+
type cqrs$1_CqrsOptions = CqrsOptions;
|
|
758
|
+
type cqrs$1_EventStoreAdapter = EventStoreAdapter;
|
|
759
|
+
type cqrs$1_EventStoreCursor = EventStoreCursor;
|
|
760
|
+
type cqrs$1_LoadEventsResult = LoadEventsResult;
|
|
761
|
+
type cqrs$1_MemoryEventStore = MemoryEventStore;
|
|
762
|
+
declare const cqrs$1_MemoryEventStore: typeof MemoryEventStore;
|
|
763
|
+
type cqrs$1_ProjectionReducer<TState = unknown, TEvent = unknown> = ProjectionReducer<TState, TEvent>;
|
|
764
|
+
type cqrs$1_SagaHandler<T = unknown> = SagaHandler<T>;
|
|
765
|
+
declare const cqrs$1_cqrs: typeof cqrs;
|
|
766
|
+
declare namespace cqrs$1 {
|
|
767
|
+
export { type cqrs$1_CommandActions as CommandActions, type cqrs$1_CommandHandler as CommandHandler, type cqrs$1_CqrsEvent as CqrsEvent, cqrs$1_CqrsGraph as CqrsGraph, type cqrs$1_CqrsOptions as CqrsOptions, type cqrs$1_EventStoreAdapter as EventStoreAdapter, type cqrs$1_EventStoreCursor as EventStoreCursor, type cqrs$1_LoadEventsResult as LoadEventsResult, cqrs$1_MemoryEventStore as MemoryEventStore, type cqrs$1_ProjectionReducer as ProjectionReducer, type cqrs$1_SagaHandler as SagaHandler, cqrs$1_cqrs as cqrs };
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
interface GraphReflyRootOptions {
|
|
771
|
+
/** Root graph name (default: `"root"`). */
|
|
772
|
+
name?: string;
|
|
773
|
+
/** Snapshot to hydrate via `graph.restore()` after build. */
|
|
774
|
+
snapshot?: GraphPersistSnapshot;
|
|
775
|
+
/** Build callback — registers nodes/mounts on the graph. */
|
|
776
|
+
build?: (graph: Graph) => void;
|
|
777
|
+
/** Qualified node paths to expose as injectable providers. */
|
|
778
|
+
nodes?: readonly string[];
|
|
779
|
+
/** Enable a request-scoped graph (injectable via `@InjectGraph("request")`). */
|
|
780
|
+
requestScope?: boolean;
|
|
781
|
+
}
|
|
782
|
+
interface GraphReflyCqrsOptions {
|
|
783
|
+
/** Feature name — becomes the mount name in the root graph. */
|
|
784
|
+
name: string;
|
|
785
|
+
/** CQRS graph options (forwarded to `cqrs()` factory). */
|
|
786
|
+
cqrs?: CqrsOptions;
|
|
787
|
+
/** Build callback — registers commands, events, projections, sagas on the CqrsGraph. */
|
|
788
|
+
build?: (graph: CqrsGraph) => void;
|
|
789
|
+
/** Event store adapter for persistence (wired via `useEventStore()`). */
|
|
790
|
+
eventStore?: EventStoreAdapter;
|
|
791
|
+
/**
|
|
792
|
+
* Node paths (local to this feature) to expose as injectable providers.
|
|
793
|
+
* Tokens are auto-qualified as `featureName::path`.
|
|
794
|
+
*/
|
|
795
|
+
nodes?: readonly string[];
|
|
796
|
+
}
|
|
797
|
+
interface GraphReflyFeatureOptions {
|
|
798
|
+
/** Feature name — becomes the mount name in the root graph. */
|
|
799
|
+
name: string;
|
|
800
|
+
/** Build callback — registers nodes/mounts on the feature graph. */
|
|
801
|
+
build?: (graph: Graph) => void;
|
|
802
|
+
/** Snapshot to hydrate after build. */
|
|
803
|
+
snapshot?: GraphPersistSnapshot;
|
|
804
|
+
/**
|
|
805
|
+
* Node paths (local to this feature) to expose as injectable providers.
|
|
806
|
+
* Tokens are auto-qualified as `featureName::path` to avoid collisions.
|
|
807
|
+
*/
|
|
808
|
+
nodes?: readonly string[];
|
|
809
|
+
}
|
|
810
|
+
declare class GraphReflyModule {
|
|
811
|
+
/**
|
|
812
|
+
* Register the root `Graph` singleton in the NestJS DI container.
|
|
813
|
+
*
|
|
814
|
+
* The root graph is `@Global()` — injectable everywhere without importing
|
|
815
|
+
* the module again. Use `@InjectGraph()` to inject it.
|
|
816
|
+
*
|
|
817
|
+
* Lifecycle:
|
|
818
|
+
* - **init:** Graph created in factory. If `build` is provided, it runs
|
|
819
|
+
* first (registers nodes/mounts). If `snapshot` is provided, values
|
|
820
|
+
* are restored via `graph.restore()`.
|
|
821
|
+
* - **destroy:** Calls `graph.destroy()` — sends `[[TEARDOWN]]` to all
|
|
822
|
+
* nodes, including mounted feature subgraphs (cascading teardown).
|
|
823
|
+
*/
|
|
824
|
+
static forRoot(opts?: GraphReflyRootOptions): DynamicModule;
|
|
825
|
+
/**
|
|
826
|
+
* Register a feature subgraph that auto-mounts into the root graph.
|
|
827
|
+
*
|
|
828
|
+
* The feature graph is created in the factory, built/restored, then
|
|
829
|
+
* mounted into root via `root.mount(name, featureGraph)`. On app
|
|
830
|
+
* shutdown, root's `graph.destroy()` cascades TEARDOWN through all
|
|
831
|
+
* mounted subgraphs (no explicit remove needed).
|
|
832
|
+
*
|
|
833
|
+
* Node tokens are auto-qualified as `featureName::path` to prevent
|
|
834
|
+
* collisions between features declaring nodes with the same local name.
|
|
835
|
+
*
|
|
836
|
+
* Injectable via `@InjectGraph(name)`.
|
|
837
|
+
*/
|
|
838
|
+
static forFeature(opts: GraphReflyFeatureOptions): DynamicModule;
|
|
839
|
+
/**
|
|
840
|
+
* Register a CQRS subgraph that auto-mounts into the root graph.
|
|
841
|
+
*
|
|
842
|
+
* Creates a `CqrsGraph` via the `cqrs()` factory (roadmap §4.5), mounts it
|
|
843
|
+
* into the root graph, and exposes it for DI via `@InjectGraph(name)`.
|
|
844
|
+
*
|
|
845
|
+
* CQRS decorators (`@CommandHandler`, `@EventHandler`, `@QueryHandler`,
|
|
846
|
+
* `@SagaHandler`) are discovered by the explorer and wired to this graph
|
|
847
|
+
* on module init.
|
|
848
|
+
*
|
|
849
|
+
* @example
|
|
850
|
+
* ```ts
|
|
851
|
+
* GraphReflyModule.forCqrs({
|
|
852
|
+
* name: "orders",
|
|
853
|
+
* build: (g) => {
|
|
854
|
+
* g.event("orderPlaced");
|
|
855
|
+
* g.projection("orderCount", ["orderPlaced"], (_s, evts) => evts.length, 0);
|
|
856
|
+
* },
|
|
857
|
+
* })
|
|
858
|
+
* ```
|
|
859
|
+
*/
|
|
860
|
+
static forCqrs(opts: GraphReflyCqrsOptions): DynamicModule;
|
|
861
|
+
}
|
|
862
|
+
|
|
863
|
+
/** Injection token for the root `Graph` singleton created by `forRoot()`. */
|
|
864
|
+
declare const GRAPHREFLY_ROOT_GRAPH: unique symbol;
|
|
865
|
+
/** Injection token for the request-scoped `Graph` created by request scope config. */
|
|
866
|
+
declare const GRAPHREFLY_REQUEST_GRAPH: unique symbol;
|
|
867
|
+
/**
|
|
868
|
+
* Get the injection token for a named feature graph.
|
|
869
|
+
*
|
|
870
|
+
* Feature graphs registered via `GraphReflyModule.forFeature({ name })` are
|
|
871
|
+
* injectable using this token (or via the `@InjectGraph(name)` decorator).
|
|
872
|
+
*/
|
|
873
|
+
declare function getGraphToken(name: string): symbol;
|
|
874
|
+
/**
|
|
875
|
+
* Get the injection token for a node at a qualified path.
|
|
876
|
+
*
|
|
877
|
+
* Nodes declared in `forRoot({ nodes })` or `forFeature({ nodes })` are
|
|
878
|
+
* injectable using this token (or via the `@InjectNode(path)` decorator).
|
|
879
|
+
*/
|
|
880
|
+
declare function getNodeToken(path: string): symbol;
|
|
881
|
+
|
|
882
|
+
declare const index_ACTOR_KEY: typeof ACTOR_KEY;
|
|
883
|
+
type index_ActorExtractor = ActorExtractor;
|
|
884
|
+
declare const index_COMMAND_HANDLERS: typeof COMMAND_HANDLERS;
|
|
885
|
+
declare const index_CQRS_EVENT_HANDLERS: typeof CQRS_EVENT_HANDLERS;
|
|
886
|
+
declare const index_CRON_HANDLERS: typeof CRON_HANDLERS;
|
|
887
|
+
type index_CommandHandlerMeta = CommandHandlerMeta;
|
|
888
|
+
declare const index_EVENT_HANDLERS: typeof EVENT_HANDLERS;
|
|
889
|
+
declare const index_EventHandler: typeof EventHandler;
|
|
890
|
+
type index_EventHandlerMeta = EventHandlerMeta;
|
|
891
|
+
declare const index_GRAPHREFLY_REQUEST_GRAPH: typeof GRAPHREFLY_REQUEST_GRAPH;
|
|
892
|
+
declare const index_GRAPHREFLY_ROOT_GRAPH: typeof GRAPHREFLY_ROOT_GRAPH;
|
|
893
|
+
declare const index_GraphCron: typeof GraphCron;
|
|
894
|
+
type index_GraphCronMeta = GraphCronMeta;
|
|
895
|
+
declare const index_GraphInterval: typeof GraphInterval;
|
|
896
|
+
type index_GraphIntervalMeta = GraphIntervalMeta;
|
|
897
|
+
type index_GraphReflyCqrsOptions = GraphReflyCqrsOptions;
|
|
898
|
+
type index_GraphReflyEventExplorer = GraphReflyEventExplorer;
|
|
899
|
+
declare const index_GraphReflyEventExplorer: typeof GraphReflyEventExplorer;
|
|
900
|
+
type index_GraphReflyFeatureOptions = GraphReflyFeatureOptions;
|
|
901
|
+
declare const index_GraphReflyGuard: typeof GraphReflyGuard;
|
|
902
|
+
type index_GraphReflyGuardImpl = GraphReflyGuardImpl;
|
|
903
|
+
declare const index_GraphReflyGuardImpl: typeof GraphReflyGuardImpl;
|
|
904
|
+
type index_GraphReflyModule = GraphReflyModule;
|
|
905
|
+
declare const index_GraphReflyModule: typeof GraphReflyModule;
|
|
906
|
+
type index_GraphReflyRootOptions = GraphReflyRootOptions;
|
|
907
|
+
declare const index_INTERVAL_HANDLERS: typeof INTERVAL_HANDLERS;
|
|
908
|
+
declare const index_InjectCqrsGraph: typeof InjectCqrsGraph;
|
|
909
|
+
declare const index_InjectGraph: typeof InjectGraph;
|
|
910
|
+
declare const index_InjectNode: typeof InjectNode;
|
|
911
|
+
type index_ObserveGateway = ObserveGateway;
|
|
912
|
+
declare const index_ObserveGateway: typeof ObserveGateway;
|
|
913
|
+
type index_ObserveGatewayOptions = ObserveGatewayOptions;
|
|
914
|
+
type index_ObserveSSEOptions = ObserveSSEOptions;
|
|
915
|
+
type index_ObserveSubscriptionOptions<T = unknown> = ObserveSubscriptionOptions<T>;
|
|
916
|
+
type index_ObserveWsCommand = ObserveWsCommand;
|
|
917
|
+
type index_ObserveWsMessage<T = unknown> = ObserveWsMessage<T>;
|
|
918
|
+
declare const index_OnGraphEvent: typeof OnGraphEvent;
|
|
919
|
+
type index_OnGraphEventMeta = OnGraphEventMeta;
|
|
920
|
+
declare const index_QUERY_HANDLERS: typeof QUERY_HANDLERS;
|
|
921
|
+
declare const index_QueryHandler: typeof QueryHandler;
|
|
922
|
+
type index_QueryHandlerMeta = QueryHandlerMeta;
|
|
923
|
+
declare const index_SAGA_HANDLERS: typeof SAGA_HANDLERS;
|
|
924
|
+
type index_SagaHandlerMeta = SagaHandlerMeta;
|
|
925
|
+
declare const index_fromHeader: typeof fromHeader;
|
|
926
|
+
declare const index_fromJwtPayload: typeof fromJwtPayload;
|
|
927
|
+
declare const index_getActor: typeof getActor;
|
|
928
|
+
declare const index_getGraphToken: typeof getGraphToken;
|
|
929
|
+
declare const index_getNodeToken: typeof getNodeToken;
|
|
930
|
+
declare const index_observeGraph$: typeof observeGraph$;
|
|
931
|
+
declare const index_observeNode$: typeof observeNode$;
|
|
932
|
+
declare const index_observeSSE: typeof observeSSE;
|
|
933
|
+
declare const index_observeSubscription: typeof observeSubscription;
|
|
934
|
+
declare const index_toMessages$: typeof toMessages$;
|
|
935
|
+
declare const index_toObservable: typeof toObservable;
|
|
936
|
+
declare namespace index {
|
|
937
|
+
export { index_ACTOR_KEY as ACTOR_KEY, type index_ActorExtractor as ActorExtractor, index_COMMAND_HANDLERS as COMMAND_HANDLERS, index_CQRS_EVENT_HANDLERS as CQRS_EVENT_HANDLERS, index_CRON_HANDLERS as CRON_HANDLERS, CommandHandler$1 as CommandHandler, type index_CommandHandlerMeta as CommandHandlerMeta, index_EVENT_HANDLERS as EVENT_HANDLERS, index_EventHandler as EventHandler, type index_EventHandlerMeta as EventHandlerMeta, index_GRAPHREFLY_REQUEST_GRAPH as GRAPHREFLY_REQUEST_GRAPH, index_GRAPHREFLY_ROOT_GRAPH as GRAPHREFLY_ROOT_GRAPH, index_GraphCron as GraphCron, type index_GraphCronMeta as GraphCronMeta, index_GraphInterval as GraphInterval, type index_GraphIntervalMeta as GraphIntervalMeta, type index_GraphReflyCqrsOptions as GraphReflyCqrsOptions, index_GraphReflyEventExplorer as GraphReflyEventExplorer, type index_GraphReflyFeatureOptions as GraphReflyFeatureOptions, index_GraphReflyGuard as GraphReflyGuard, index_GraphReflyGuardImpl as GraphReflyGuardImpl, index_GraphReflyModule as GraphReflyModule, type index_GraphReflyRootOptions as GraphReflyRootOptions, index_INTERVAL_HANDLERS as INTERVAL_HANDLERS, index_InjectCqrsGraph as InjectCqrsGraph, index_InjectGraph as InjectGraph, index_InjectNode as InjectNode, index_ObserveGateway as ObserveGateway, type index_ObserveGatewayOptions as ObserveGatewayOptions, type index_ObserveSSEOptions as ObserveSSEOptions, type index_ObserveSubscriptionOptions as ObserveSubscriptionOptions, type index_ObserveWsCommand as ObserveWsCommand, type index_ObserveWsMessage as ObserveWsMessage, index_OnGraphEvent as OnGraphEvent, type index_OnGraphEventMeta as OnGraphEventMeta, index_QUERY_HANDLERS as QUERY_HANDLERS, index_QueryHandler as QueryHandler, type index_QueryHandlerMeta as QueryHandlerMeta, index_SAGA_HANDLERS as SAGA_HANDLERS, SagaHandler$1 as SagaHandler, type index_SagaHandlerMeta as SagaHandlerMeta, index_fromHeader as fromHeader, index_fromJwtPayload as fromJwtPayload, index_getActor as getActor, index_getGraphToken as getGraphToken, index_getNodeToken as getNodeToken, index_observeGraph$ as observeGraph$, index_observeNode$ as observeNode$, index_observeSSE as observeSSE, index_observeSubscription as observeSubscription, index_toMessages$ as toMessages$, index_toObservable as toObservable };
|
|
938
|
+
}
|
|
939
|
+
|
|
940
|
+
export { ACTOR_KEY as A, type ObserveSubscriptionOptions as B, COMMAND_HANDLERS as C, type ObserveWsCommand as D, EVENT_HANDLERS as E, type ObserveWsMessage as F, GRAPHREFLY_REQUEST_GRAPH as G, OnGraphEvent as H, INTERVAL_HANDLERS as I, type OnGraphEventMeta as J, QueryHandler as K, type QueryHandlerMeta as L, SagaHandler$1 as M, type SagaHandlerMeta as N, ObserveGateway as O, fromHeader as P, QUERY_HANDLERS as Q, fromJwtPayload as R, SAGA_HANDLERS as S, getActor as T, getGraphToken as U, getNodeToken as V, observeSSE as W, observeSubscription as X, type ActorExtractor as a, CQRS_EVENT_HANDLERS as b, cqrs$1 as c, CRON_HANDLERS as d, CommandHandler$1 as e, type CommandHandlerMeta as f, EventHandler as g, type EventHandlerMeta as h, index as i, GRAPHREFLY_ROOT_GRAPH as j, GraphCron as k, type GraphCronMeta as l, GraphInterval as m, type GraphIntervalMeta as n, type GraphReflyCqrsOptions as o, GraphReflyEventExplorer as p, type GraphReflyFeatureOptions as q, GraphReflyGuard as r, GraphReflyGuardImpl as s, GraphReflyModule as t, type GraphReflyRootOptions as u, InjectCqrsGraph as v, InjectGraph as w, InjectNode as x, type ObserveGatewayOptions as y, type ObserveSSEOptions as z };
|