@living-architecture/riviere-query 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/README.md +11 -0
  2. package/dist/RiviereQuery.d.ts +486 -0
  3. package/dist/RiviereQuery.d.ts.map +1 -0
  4. package/dist/RiviereQuery.js +553 -0
  5. package/dist/component-queries.d.ts +8 -0
  6. package/dist/component-queries.d.ts.map +1 -0
  7. package/dist/component-queries.js +24 -0
  8. package/dist/cross-domain-queries.d.ts +5 -0
  9. package/dist/cross-domain-queries.d.ts.map +1 -0
  10. package/dist/cross-domain-queries.js +92 -0
  11. package/dist/depth-queries.d.ts +4 -0
  12. package/dist/depth-queries.d.ts.map +1 -0
  13. package/dist/depth-queries.js +54 -0
  14. package/dist/domain-queries.d.ts +10 -0
  15. package/dist/domain-queries.d.ts.map +1 -0
  16. package/dist/domain-queries.js +101 -0
  17. package/dist/domain-types.d.ts +307 -0
  18. package/dist/domain-types.d.ts.map +1 -0
  19. package/dist/domain-types.js +111 -0
  20. package/dist/errors.d.ts +6 -0
  21. package/dist/errors.d.ts.map +1 -0
  22. package/dist/errors.js +10 -0
  23. package/dist/event-queries.d.ts +5 -0
  24. package/dist/event-queries.d.ts.map +1 -0
  25. package/dist/event-queries.js +32 -0
  26. package/dist/event-types.d.ts +88 -0
  27. package/dist/event-types.d.ts.map +1 -0
  28. package/dist/event-types.js +1 -0
  29. package/dist/external-system-queries.d.ts +13 -0
  30. package/dist/external-system-queries.d.ts.map +1 -0
  31. package/dist/external-system-queries.js +54 -0
  32. package/dist/flow-queries.d.ts +17 -0
  33. package/dist/flow-queries.d.ts.map +1 -0
  34. package/dist/flow-queries.js +127 -0
  35. package/dist/graph-diff.d.ts +4 -0
  36. package/dist/graph-diff.d.ts.map +1 -0
  37. package/dist/graph-diff.js +53 -0
  38. package/dist/graph-validation.d.ts +5 -0
  39. package/dist/graph-validation.d.ts.map +1 -0
  40. package/dist/graph-validation.js +72 -0
  41. package/dist/index.d.ts +5 -0
  42. package/dist/index.d.ts.map +1 -0
  43. package/dist/index.js +4 -0
  44. package/dist/riviere-graph-fixtures.d.ts +37 -0
  45. package/dist/riviere-graph-fixtures.d.ts.map +1 -0
  46. package/dist/riviere-graph-fixtures.js +73 -0
  47. package/dist/stats-queries.d.ts +4 -0
  48. package/dist/stats-queries.d.ts.map +1 -0
  49. package/dist/stats-queries.js +14 -0
  50. package/package.json +29 -0
@@ -0,0 +1,54 @@
1
+ import { parseComponentId } from './domain-types';
2
+ export function queryNodeDepths(graph) {
3
+ const depths = new Map();
4
+ const entryPoints = findEntryPointIds(graph);
5
+ if (entryPoints.length === 0) {
6
+ return depths;
7
+ }
8
+ const outgoingEdges = buildOutgoingEdges(graph);
9
+ const queue = entryPoints.map((id) => ({ id, depth: 0 }));
10
+ processQueue(queue, depths, outgoingEdges);
11
+ return depths;
12
+ }
13
+ function processQueue(queue, depths, outgoingEdges) {
14
+ const current = queue.shift();
15
+ if (current === undefined)
16
+ return;
17
+ const existingDepth = depths.get(current.id);
18
+ const shouldProcess = existingDepth === undefined || existingDepth > current.depth;
19
+ if (shouldProcess) {
20
+ depths.set(current.id, current.depth);
21
+ enqueueChildren(outgoingEdges, current, queue);
22
+ }
23
+ processQueue(queue, depths, outgoingEdges);
24
+ }
25
+ function enqueueChildren(outgoingEdges, current, queue) {
26
+ const edges = outgoingEdges.get(current.id);
27
+ if (edges) {
28
+ for (const targetId of edges) {
29
+ queue.push({ id: targetId, depth: current.depth + 1 });
30
+ }
31
+ }
32
+ }
33
+ function findEntryPointIds(graph) {
34
+ const targets = new Set(graph.links.map((link) => link.target));
35
+ const entryPointTypes = new Set(['UI', 'API', 'EventHandler', 'Custom']);
36
+ return graph.components
37
+ .filter((c) => entryPointTypes.has(c.type) && !targets.has(c.id))
38
+ .map((c) => parseComponentId(c.id));
39
+ }
40
+ function buildOutgoingEdges(graph) {
41
+ const edges = new Map();
42
+ for (const link of graph.links) {
43
+ const sourceId = parseComponentId(link.source);
44
+ const targetId = parseComponentId(link.target);
45
+ const existing = edges.get(sourceId);
46
+ if (existing) {
47
+ existing.push(targetId);
48
+ }
49
+ else {
50
+ edges.set(sourceId, [targetId]);
51
+ }
52
+ }
53
+ return edges;
54
+ }
@@ -0,0 +1,10 @@
1
+ import type { RiviereGraph, DomainOpComponent } from '@living-architecture/riviere-schema';
2
+ import type { Entity, EntityTransition } from './event-types';
3
+ import type { State, Domain } from './domain-types';
4
+ export declare function queryDomains(graph: RiviereGraph): Domain[];
5
+ export declare function operationsForEntity(graph: RiviereGraph, entityName: string): DomainOpComponent[];
6
+ export declare function queryEntities(graph: RiviereGraph, domainName?: string): Entity[];
7
+ export declare function businessRulesForEntity(graph: RiviereGraph, entityName: string): string[];
8
+ export declare function transitionsForEntity(graph: RiviereGraph, entityName: string): EntityTransition[];
9
+ export declare function statesForEntity(graph: RiviereGraph, entityName: string): State[];
10
+ //# sourceMappingURL=domain-queries.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"domain-queries.d.ts","sourceRoot":"","sources":["../src/domain-queries.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,qCAAqC,CAAA;AAC1F,OAAO,KAAK,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAA;AAC7D,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,EAAmB,MAAM,gBAAgB,CAAA;AAIpE,wBAAgB,YAAY,CAAC,KAAK,EAAE,YAAY,GAAG,MAAM,EAAE,CAU1D;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,GAAG,iBAAiB,EAAE,CAEhG;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,YAAY,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAchF;AAED,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,EAAE,CAQxF;AAED,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,GAAG,gBAAgB,EAAE,CAUhG;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,GAAG,KAAK,EAAE,CAWhF"}
@@ -0,0 +1,101 @@
1
+ import { parseEntityName, parseDomainName, parseState, parseOperationName } from './domain-types';
2
+ import { componentsInDomain } from './component-queries';
3
+ export function queryDomains(graph) {
4
+ return Object.entries(graph.metadata.domains).map(([name, metadata]) => {
5
+ const dc = componentsInDomain(graph, name);
6
+ const count = (type) => dc.filter((c) => c.type === type).length;
7
+ const componentCounts = {
8
+ UI: count('UI'), API: count('API'), UseCase: count('UseCase'), DomainOp: count('DomainOp'),
9
+ Event: count('Event'), EventHandler: count('EventHandler'), Custom: count('Custom'), total: dc.length,
10
+ };
11
+ return { name, description: metadata.description, systemType: metadata.systemType, componentCounts };
12
+ });
13
+ }
14
+ export function operationsForEntity(graph, entityName) {
15
+ return graph.components.filter((c) => c.type === 'DomainOp' && c.entity === entityName);
16
+ }
17
+ export function queryEntities(graph, domainName) {
18
+ const domainOps = graph.components.filter((c) => c.type === 'DomainOp' && c.entity !== undefined);
19
+ const filtered = domainName ? domainOps.filter((op) => op.domain === domainName) : domainOps;
20
+ const entityMap = new Map();
21
+ for (const op of filtered) {
22
+ const key = `${op.domain}:${op.entity}`;
23
+ const existing = entityMap.get(key);
24
+ if (existing) {
25
+ entityMap.set(key, { ...existing, operations: [...existing.operations, op] });
26
+ }
27
+ else {
28
+ entityMap.set(key, { name: parseEntityName(op.entity), domain: parseDomainName(op.domain), operations: [op] });
29
+ }
30
+ }
31
+ return Array.from(entityMap.values());
32
+ }
33
+ export function businessRulesForEntity(graph, entityName) {
34
+ const operations = operationsForEntity(graph, entityName);
35
+ const allRules = [];
36
+ for (const op of operations) {
37
+ if (op.businessRules === undefined)
38
+ continue;
39
+ allRules.push(...op.businessRules);
40
+ }
41
+ return [...new Set(allRules)];
42
+ }
43
+ export function transitionsForEntity(graph, entityName) {
44
+ const operations = operationsForEntity(graph, entityName);
45
+ const transitions = [];
46
+ for (const op of operations) {
47
+ if (op.stateChanges === undefined)
48
+ continue;
49
+ for (const sc of op.stateChanges) {
50
+ transitions.push({ from: parseState(sc.from), to: parseState(sc.to), triggeredBy: parseOperationName(op.operationName) });
51
+ }
52
+ }
53
+ return transitions;
54
+ }
55
+ export function statesForEntity(graph, entityName) {
56
+ const operations = operationsForEntity(graph, entityName);
57
+ const states = new Set();
58
+ for (const op of operations) {
59
+ if (op.stateChanges === undefined)
60
+ continue;
61
+ for (const sc of op.stateChanges) {
62
+ if (sc.from !== '*')
63
+ states.add(sc.from);
64
+ states.add(sc.to);
65
+ }
66
+ }
67
+ return orderStatesByTransitions(states, operations);
68
+ }
69
+ function orderStatesByTransitions(states, operations) {
70
+ const fromStates = new Set();
71
+ const toStates = new Set();
72
+ const transitionMap = new Map();
73
+ for (const op of operations) {
74
+ if (op.stateChanges === undefined)
75
+ continue;
76
+ for (const t of op.stateChanges) {
77
+ if (t.from !== '*') {
78
+ fromStates.add(t.from);
79
+ transitionMap.set(t.from, t.to);
80
+ }
81
+ toStates.add(t.to);
82
+ }
83
+ }
84
+ const ordered = [];
85
+ const visited = new Set();
86
+ const follow = (s) => {
87
+ if (visited.has(s))
88
+ return;
89
+ visited.add(s);
90
+ ordered.push(parseState(s));
91
+ const next = transitionMap.get(s);
92
+ if (next)
93
+ follow(next);
94
+ };
95
+ [...fromStates].filter((s) => !toStates.has(s)).forEach(follow);
96
+ states.forEach((s) => {
97
+ if (!visited.has(s))
98
+ ordered.push(parseState(s));
99
+ });
100
+ return ordered;
101
+ }
@@ -0,0 +1,307 @@
1
+ import type { Component, Link, ExternalLink } from '@living-architecture/riviere-schema';
2
+ import { z } from 'zod';
3
+ /** @internal */
4
+ declare const componentIdSchema: z.core.$ZodBranded<z.ZodString, "ComponentId">;
5
+ /** @internal */
6
+ declare const linkIdSchema: z.core.$ZodBranded<z.ZodString, "LinkId">;
7
+ /** @internal */
8
+ declare const entityNameSchema: z.core.$ZodBranded<z.ZodString, "EntityName">;
9
+ /** @internal */
10
+ declare const domainNameSchema: z.core.$ZodBranded<z.ZodString, "DomainName">;
11
+ /** @internal */
12
+ declare const stateSchema: z.core.$ZodBranded<z.ZodString, "State">;
13
+ /** @internal */
14
+ declare const operationNameSchema: z.core.$ZodBranded<z.ZodString, "OperationName">;
15
+ /** @internal */
16
+ declare const eventIdSchema: z.core.$ZodBranded<z.ZodString, "EventId">;
17
+ /** @internal */
18
+ declare const eventNameSchema: z.core.$ZodBranded<z.ZodString, "EventName">;
19
+ /** @internal */
20
+ declare const handlerIdSchema: z.core.$ZodBranded<z.ZodString, "HandlerId">;
21
+ /** @internal */
22
+ declare const handlerNameSchema: z.core.$ZodBranded<z.ZodString, "HandlerName">;
23
+ /** Branded type for component identifiers. */
24
+ export type ComponentId = z.infer<typeof componentIdSchema>;
25
+ /** Branded type for link identifiers. */
26
+ export type LinkId = z.infer<typeof linkIdSchema>;
27
+ /** Branded type for entity names. */
28
+ export type EntityName = z.infer<typeof entityNameSchema>;
29
+ /** Branded type for domain names. */
30
+ export type DomainName = z.infer<typeof domainNameSchema>;
31
+ /** Branded type for state names in entity state machines. */
32
+ export type State = z.infer<typeof stateSchema>;
33
+ /** Branded type for operation names. */
34
+ export type OperationName = z.infer<typeof operationNameSchema>;
35
+ /** Branded type for event identifiers. */
36
+ export type EventId = z.infer<typeof eventIdSchema>;
37
+ /** Branded type for event names. */
38
+ export type EventName = z.infer<typeof eventNameSchema>;
39
+ /** Branded type for event handler identifiers. */
40
+ export type HandlerId = z.infer<typeof handlerIdSchema>;
41
+ /** Branded type for event handler names. */
42
+ export type HandlerName = z.infer<typeof handlerNameSchema>;
43
+ /** Error codes for graph validation failures. */
44
+ export type ValidationErrorCode = 'INVALID_LINK_SOURCE' | 'INVALID_LINK_TARGET' | 'INVALID_TYPE';
45
+ /**
46
+ * A validation error found in the graph.
47
+ */
48
+ export interface ValidationError {
49
+ /** JSON path to the error location. */
50
+ path: string;
51
+ /** Human-readable error description. */
52
+ message: string;
53
+ /** Machine-readable error code. */
54
+ code: ValidationErrorCode;
55
+ }
56
+ /**
57
+ * Result of graph validation.
58
+ */
59
+ export interface ValidationResult {
60
+ /** Whether the graph passed validation. */
61
+ valid: boolean;
62
+ /** List of validation errors (empty if valid). */
63
+ errors: ValidationError[];
64
+ }
65
+ /**
66
+ * Component counts by type within a domain.
67
+ */
68
+ export interface ComponentCounts {
69
+ /** Number of UI components. */
70
+ UI: number;
71
+ /** Number of API components. */
72
+ API: number;
73
+ /** Number of UseCase components. */
74
+ UseCase: number;
75
+ /** Number of DomainOp components. */
76
+ DomainOp: number;
77
+ /** Number of Event components. */
78
+ Event: number;
79
+ /** Number of EventHandler components. */
80
+ EventHandler: number;
81
+ /** Number of Custom components. */
82
+ Custom: number;
83
+ /** Total number of components. */
84
+ total: number;
85
+ }
86
+ /**
87
+ * Domain information with metadata and component counts.
88
+ */
89
+ export interface Domain {
90
+ /** Domain name. */
91
+ name: string;
92
+ /** Domain description from graph metadata. */
93
+ description: string;
94
+ /** System type classification. */
95
+ systemType: 'domain' | 'bff' | 'ui' | 'other';
96
+ /** Counts of components by type. */
97
+ componentCounts: ComponentCounts;
98
+ }
99
+ /**
100
+ * A component that was modified between graph versions.
101
+ */
102
+ export interface ComponentModification {
103
+ /** The component ID. */
104
+ id: ComponentId;
105
+ /** The component state before modification. */
106
+ before: Component;
107
+ /** The component state after modification. */
108
+ after: Component;
109
+ /** List of field names that changed. */
110
+ changedFields: string[];
111
+ }
112
+ /**
113
+ * Summary statistics of differences between graphs.
114
+ */
115
+ export interface DiffStats {
116
+ /** Number of components added. */
117
+ componentsAdded: number;
118
+ /** Number of components removed. */
119
+ componentsRemoved: number;
120
+ /** Number of components modified. */
121
+ componentsModified: number;
122
+ /** Number of links added. */
123
+ linksAdded: number;
124
+ /** Number of links removed. */
125
+ linksRemoved: number;
126
+ }
127
+ /**
128
+ * Complete diff between two graph versions.
129
+ */
130
+ export interface GraphDiff {
131
+ /** Component changes. */
132
+ components: {
133
+ /** Components present in new graph but not old. */
134
+ added: Component[];
135
+ /** Components present in old graph but not new. */
136
+ removed: Component[];
137
+ /** Components present in both with different values. */
138
+ modified: ComponentModification[];
139
+ };
140
+ /** Link changes. */
141
+ links: {
142
+ /** Links present in new graph but not old. */
143
+ added: Link[];
144
+ /** Links present in old graph but not new. */
145
+ removed: Link[];
146
+ };
147
+ /** Summary statistics. */
148
+ stats: DiffStats;
149
+ }
150
+ /** Type of link between components. */
151
+ export type LinkType = 'sync' | 'async';
152
+ /**
153
+ * A step in an execution flow.
154
+ */
155
+ export interface FlowStep {
156
+ /** The component at this step. */
157
+ component: Component;
158
+ /** Type of link leading to this step (undefined for entry point). */
159
+ linkType: LinkType | undefined;
160
+ /** Depth from entry point (0 = entry point). */
161
+ depth: number;
162
+ /** External links from this component to external systems. */
163
+ externalLinks: ExternalLink[];
164
+ }
165
+ /**
166
+ * An execution flow from entry point through the graph.
167
+ */
168
+ export interface Flow {
169
+ /** The entry point component. */
170
+ entryPoint: Component;
171
+ /** Steps in the flow including entry point. */
172
+ steps: FlowStep[];
173
+ }
174
+ /**
175
+ * Result of searchWithFlow containing matches and their flow context.
176
+ */
177
+ export interface SearchWithFlowResult {
178
+ /** IDs of components that matched the search. */
179
+ matchingIds: ComponentId[];
180
+ /** IDs of all components visible in the matching flows. */
181
+ visibleIds: ComponentId[];
182
+ }
183
+ /**
184
+ * A link that crosses domain boundaries.
185
+ */
186
+ export interface CrossDomainLink {
187
+ /** The target domain name. */
188
+ targetDomain: DomainName;
189
+ /** Type of the cross-domain link. */
190
+ linkType: LinkType | undefined;
191
+ }
192
+ /**
193
+ * Summary of connections between domains.
194
+ */
195
+ export interface DomainConnection {
196
+ /** The connected domain name. */
197
+ targetDomain: DomainName;
198
+ /** Direction relative to the queried domain. */
199
+ direction: 'outgoing' | 'incoming';
200
+ /** Number of API-based connections. */
201
+ apiCount: number;
202
+ /** Number of event-based connections. */
203
+ eventCount: number;
204
+ }
205
+ /**
206
+ * Aggregate statistics about a graph.
207
+ */
208
+ export interface GraphStats {
209
+ /** Total number of components. */
210
+ componentCount: number;
211
+ /** Total number of links. */
212
+ linkCount: number;
213
+ /** Number of domains. */
214
+ domainCount: number;
215
+ /** Number of API components. */
216
+ apiCount: number;
217
+ /** Number of unique entities. */
218
+ entityCount: number;
219
+ /** Number of Event components. */
220
+ eventCount: number;
221
+ }
222
+ /**
223
+ * An external domain that components connect to.
224
+ *
225
+ * External domains are any systems not represented in the graph—third-party
226
+ * services (Stripe, Twilio) or internal domains outside the current scope.
227
+ */
228
+ export interface ExternalDomain {
229
+ /** Name of the external domain (e.g., "Stripe", "Twilio"). */
230
+ name: string;
231
+ /** Domains that have connections to this external domain. */
232
+ sourceDomains: DomainName[];
233
+ /** Total number of connections to this external domain. */
234
+ connectionCount: number;
235
+ }
236
+ /**
237
+ * Parses a string as a ComponentId.
238
+ *
239
+ * @param id - The string to parse
240
+ * @returns A branded ComponentId
241
+ */
242
+ export declare function parseComponentId(id: string): ComponentId;
243
+ /**
244
+ * Parses a string as a LinkId.
245
+ *
246
+ * @param id - The string to parse
247
+ * @returns A branded LinkId
248
+ */
249
+ export declare function parseLinkId(id: string): LinkId;
250
+ /**
251
+ * Parses a string as an EntityName.
252
+ *
253
+ * @param value - The string to parse
254
+ * @returns A branded EntityName
255
+ */
256
+ export declare function parseEntityName(value: string): EntityName;
257
+ /**
258
+ * Parses a string as a DomainName.
259
+ *
260
+ * @param value - The string to parse
261
+ * @returns A branded DomainName
262
+ */
263
+ export declare function parseDomainName(value: string): DomainName;
264
+ /**
265
+ * Parses a string as a State.
266
+ *
267
+ * @param value - The string to parse
268
+ * @returns A branded State
269
+ */
270
+ export declare function parseState(value: string): State;
271
+ /**
272
+ * Parses a string as an OperationName.
273
+ *
274
+ * @param value - The string to parse
275
+ * @returns A branded OperationName
276
+ */
277
+ export declare function parseOperationName(value: string): OperationName;
278
+ /**
279
+ * Parses a string as an EventId.
280
+ *
281
+ * @param value - The string to parse
282
+ * @returns A branded EventId
283
+ */
284
+ export declare function parseEventId(value: string): EventId;
285
+ /**
286
+ * Parses a string as an EventName.
287
+ *
288
+ * @param value - The string to parse
289
+ * @returns A branded EventName
290
+ */
291
+ export declare function parseEventName(value: string): EventName;
292
+ /**
293
+ * Parses a string as a HandlerId.
294
+ *
295
+ * @param value - The string to parse
296
+ * @returns A branded HandlerId
297
+ */
298
+ export declare function parseHandlerId(value: string): HandlerId;
299
+ /**
300
+ * Parses a string as a HandlerName.
301
+ *
302
+ * @param value - The string to parse
303
+ * @returns A branded HandlerName
304
+ */
305
+ export declare function parseHandlerName(value: string): HandlerName;
306
+ export {};
307
+ //# sourceMappingURL=domain-types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"domain-types.d.ts","sourceRoot":"","sources":["../src/domain-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,YAAY,EAAE,MAAM,qCAAqC,CAAA;AACxF,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,gBAAgB;AAChB,QAAA,MAAM,iBAAiB,gDAAoC,CAAA;AAC3D,gBAAgB;AAChB,QAAA,MAAM,YAAY,2CAA+B,CAAA;AACjD,gBAAgB;AAChB,QAAA,MAAM,gBAAgB,+CAAmC,CAAA;AACzD,gBAAgB;AAChB,QAAA,MAAM,gBAAgB,+CAAmC,CAAA;AACzD,gBAAgB;AAChB,QAAA,MAAM,WAAW,0CAA8B,CAAA;AAC/C,gBAAgB;AAChB,QAAA,MAAM,mBAAmB,kDAAsC,CAAA;AAC/D,gBAAgB;AAChB,QAAA,MAAM,aAAa,4CAAgC,CAAA;AACnD,gBAAgB;AAChB,QAAA,MAAM,eAAe,8CAAkC,CAAA;AACvD,gBAAgB;AAChB,QAAA,MAAM,eAAe,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B,CAAC,KAAK,EAAE,MAAM,GAAG,aAAa,CAE/D;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAEnD;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,CAEvD;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,CAEvD;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,WAAW,CAE3D"}
@@ -0,0 +1,111 @@
1
+ import { z } from 'zod';
2
+ /** @internal */
3
+ const componentIdSchema = z.string().brand();
4
+ /** @internal */
5
+ const linkIdSchema = z.string().brand();
6
+ /** @internal */
7
+ const entityNameSchema = z.string().brand();
8
+ /** @internal */
9
+ const domainNameSchema = z.string().brand();
10
+ /** @internal */
11
+ const stateSchema = z.string().brand();
12
+ /** @internal */
13
+ const operationNameSchema = z.string().brand();
14
+ /** @internal */
15
+ const eventIdSchema = z.string().brand();
16
+ /** @internal */
17
+ const eventNameSchema = z.string().brand();
18
+ /** @internal */
19
+ const handlerIdSchema = z.string().brand();
20
+ /** @internal */
21
+ const handlerNameSchema = z.string().brand();
22
+ /**
23
+ * Parses a string as a ComponentId.
24
+ *
25
+ * @param id - The string to parse
26
+ * @returns A branded ComponentId
27
+ */
28
+ export function parseComponentId(id) {
29
+ return componentIdSchema.parse(id);
30
+ }
31
+ /**
32
+ * Parses a string as a LinkId.
33
+ *
34
+ * @param id - The string to parse
35
+ * @returns A branded LinkId
36
+ */
37
+ export function parseLinkId(id) {
38
+ return linkIdSchema.parse(id);
39
+ }
40
+ /**
41
+ * Parses a string as an EntityName.
42
+ *
43
+ * @param value - The string to parse
44
+ * @returns A branded EntityName
45
+ */
46
+ export function parseEntityName(value) {
47
+ return entityNameSchema.parse(value);
48
+ }
49
+ /**
50
+ * Parses a string as a DomainName.
51
+ *
52
+ * @param value - The string to parse
53
+ * @returns A branded DomainName
54
+ */
55
+ export function parseDomainName(value) {
56
+ return domainNameSchema.parse(value);
57
+ }
58
+ /**
59
+ * Parses a string as a State.
60
+ *
61
+ * @param value - The string to parse
62
+ * @returns A branded State
63
+ */
64
+ export function parseState(value) {
65
+ return stateSchema.parse(value);
66
+ }
67
+ /**
68
+ * Parses a string as an OperationName.
69
+ *
70
+ * @param value - The string to parse
71
+ * @returns A branded OperationName
72
+ */
73
+ export function parseOperationName(value) {
74
+ return operationNameSchema.parse(value);
75
+ }
76
+ /**
77
+ * Parses a string as an EventId.
78
+ *
79
+ * @param value - The string to parse
80
+ * @returns A branded EventId
81
+ */
82
+ export function parseEventId(value) {
83
+ return eventIdSchema.parse(value);
84
+ }
85
+ /**
86
+ * Parses a string as an EventName.
87
+ *
88
+ * @param value - The string to parse
89
+ * @returns A branded EventName
90
+ */
91
+ export function parseEventName(value) {
92
+ return eventNameSchema.parse(value);
93
+ }
94
+ /**
95
+ * Parses a string as a HandlerId.
96
+ *
97
+ * @param value - The string to parse
98
+ * @returns A branded HandlerId
99
+ */
100
+ export function parseHandlerId(value) {
101
+ return handlerIdSchema.parse(value);
102
+ }
103
+ /**
104
+ * Parses a string as a HandlerName.
105
+ *
106
+ * @param value - The string to parse
107
+ * @returns A branded HandlerName
108
+ */
109
+ export function parseHandlerName(value) {
110
+ return handlerNameSchema.parse(value);
111
+ }
@@ -0,0 +1,6 @@
1
+ export declare class ComponentNotFoundError extends Error {
2
+ readonly componentId: string;
3
+ readonly suggestions: string[];
4
+ constructor(componentId: string, suggestions?: string[]);
5
+ }
6
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,sBAAuB,SAAQ,KAAK;IAC/C,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAA;IAC5B,QAAQ,CAAC,WAAW,EAAE,MAAM,EAAE,CAAA;gBAElB,WAAW,EAAE,MAAM,EAAE,WAAW,GAAE,MAAM,EAAO;CAM5D"}
package/dist/errors.js ADDED
@@ -0,0 +1,10 @@
1
+ export class ComponentNotFoundError extends Error {
2
+ componentId;
3
+ suggestions;
4
+ constructor(componentId, suggestions = []) {
5
+ super(`Component '${componentId}' not found`);
6
+ this.name = 'ComponentNotFoundError';
7
+ this.componentId = componentId;
8
+ this.suggestions = suggestions;
9
+ }
10
+ }
@@ -0,0 +1,5 @@
1
+ import type { RiviereGraph } from '@living-architecture/riviere-schema';
2
+ import type { PublishedEvent, EventHandlerInfo } from './event-types';
3
+ export declare function queryPublishedEvents(graph: RiviereGraph, domainName?: string): PublishedEvent[];
4
+ export declare function queryEventHandlers(graph: RiviereGraph, eventName?: string): EventHandlerInfo[];
5
+ //# sourceMappingURL=event-queries.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event-queries.d.ts","sourceRoot":"","sources":["../src/event-queries.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAyC,MAAM,qCAAqC,CAAA;AAC9G,OAAO,KAAK,EAAE,cAAc,EAAmB,gBAAgB,EAAwC,MAAM,eAAe,CAAA;AAG5H,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,YAAY,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,cAAc,EAAE,CAU/F;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,YAAY,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,gBAAgB,EAAE,CAK9F"}
@@ -0,0 +1,32 @@
1
+ import { parseDomainName, parseEventId, parseEventName, parseHandlerId, parseHandlerName } from './domain-types';
2
+ export function queryPublishedEvents(graph, domainName) {
3
+ const eventComponents = graph.components.filter((c) => c.type === 'Event');
4
+ const filtered = domainName ? eventComponents.filter((e) => e.domain === domainName) : eventComponents;
5
+ const handlers = graph.components.filter((c) => c.type === 'EventHandler');
6
+ return filtered.map((event) => {
7
+ const subscribers = handlers.filter((h) => h.subscribedEvents.includes(event.eventName))
8
+ .map((h) => ({ handlerId: parseHandlerId(h.id), handlerName: parseHandlerName(h.name), domain: parseDomainName(h.domain) }));
9
+ return { id: parseEventId(event.id), eventName: parseEventName(event.eventName), domain: parseDomainName(event.domain), handlers: subscribers };
10
+ });
11
+ }
12
+ export function queryEventHandlers(graph, eventName) {
13
+ const eventByName = buildEventNameMap(graph);
14
+ const handlers = findEventHandlerComponents(graph);
15
+ const filtered = eventName ? handlers.filter((h) => h.subscribedEvents.includes(eventName)) : handlers;
16
+ return filtered.map((h) => buildEventHandlerInfo(h, eventByName));
17
+ }
18
+ function buildEventNameMap(graph) {
19
+ return new Map(graph.components.filter((c) => c.type === 'Event').map((e) => [e.eventName, e]));
20
+ }
21
+ function findEventHandlerComponents(graph) {
22
+ return graph.components.filter((c) => c.type === 'EventHandler');
23
+ }
24
+ function buildEventHandlerInfo(handler, eventByName) {
25
+ const subscribedEventsWithDomain = handler.subscribedEvents.map((name) => {
26
+ const event = eventByName.get(name);
27
+ if (event)
28
+ return { eventName: parseEventName(name), sourceDomain: parseDomainName(event.domain), sourceKnown: true };
29
+ return { eventName: parseEventName(name), sourceKnown: false };
30
+ });
31
+ return { id: parseHandlerId(handler.id), handlerName: parseHandlerName(handler.name), domain: parseDomainName(handler.domain), subscribedEvents: handler.subscribedEvents.map(parseEventName), subscribedEventsWithDomain };
32
+ }