@ddd-ts/event-tree 0.0.0-eventviz.3 → 0.0.0-eventviz.4

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 (40) hide show
  1. package/dist/edge.d.ts +39 -0
  2. package/dist/edge.d.ts.map +1 -0
  3. package/dist/engine/defaults/_example.d.ts +2 -0
  4. package/dist/engine/defaults/_example.d.ts.map +1 -0
  5. package/dist/engine/defaults/_utils.d.ts +14 -0
  6. package/dist/engine/defaults/_utils.d.ts.map +1 -0
  7. package/dist/engine/defaults/_utils.mjs +106 -0
  8. package/dist/engine/defaults/command-handler.d.ts +2 -0
  9. package/dist/engine/defaults/command-handler.d.ts.map +1 -0
  10. package/dist/engine/defaults/command-handler.mjs +36 -0
  11. package/dist/engine/defaults/command.d.ts +2 -0
  12. package/dist/engine/defaults/command.d.ts.map +1 -0
  13. package/dist/engine/defaults/command.mjs +29 -0
  14. package/dist/engine/defaults/es-aggregate.d.ts +2 -0
  15. package/dist/engine/defaults/es-aggregate.d.ts.map +1 -0
  16. package/dist/engine/defaults/es-aggregate.mjs +82 -0
  17. package/dist/engine/defaults/event.d.ts +2 -0
  18. package/dist/engine/defaults/event.d.ts.map +1 -0
  19. package/dist/engine/defaults/event.mjs +49 -0
  20. package/dist/engine/defaults/index.d.ts +8 -0
  21. package/dist/engine/defaults/index.d.ts.map +1 -0
  22. package/dist/engine/defaults/index.mjs +9 -0
  23. package/dist/engine/defaults/projection.d.ts +2 -0
  24. package/dist/engine/defaults/projection.d.ts.map +1 -0
  25. package/dist/engine/defaults/projection.mjs +59 -0
  26. package/dist/engine/defaults/saga.d.ts +2 -0
  27. package/dist/engine/defaults/saga.d.ts.map +1 -0
  28. package/dist/engine/defaults/saga.mjs +77 -0
  29. package/dist/engine/defaults/scanner.d.ts +2 -0
  30. package/dist/engine/defaults/scanner.d.ts.map +1 -0
  31. package/dist/engine/defaults/scanner.mjs +29 -0
  32. package/dist/engine/engine.d.ts +21 -0
  33. package/dist/engine/engine.d.ts.map +1 -0
  34. package/dist/engine/engine.mjs +54 -0
  35. package/dist/index.mjs +3 -0
  36. package/dist/node.d.ts +37 -0
  37. package/dist/node.d.ts.map +1 -0
  38. package/dist/server/index.d.ts +4 -0
  39. package/dist/server/index.d.ts.map +1 -0
  40. package/package.json +2 -2
package/dist/edge.d.ts ADDED
@@ -0,0 +1,39 @@
1
+ type EventRef = {
2
+ type: "event";
3
+ name: string;
4
+ };
5
+ type CommandRef = {
6
+ type: "command";
7
+ name: string;
8
+ };
9
+ type Reactor = {
10
+ type: "saga" | "aggregate" | "projection";
11
+ name: string;
12
+ };
13
+ type Sender = {
14
+ type: "saga" | "aggregate";
15
+ name: string;
16
+ };
17
+ type Source = {
18
+ file: string;
19
+ start: number;
20
+ };
21
+ export type Edge = {
22
+ from: EventRef;
23
+ to: Reactor;
24
+ source: Source;
25
+ } | {
26
+ from: Sender;
27
+ to: CommandRef;
28
+ source: Source;
29
+ } | {
30
+ from: Sender;
31
+ to: EventRef;
32
+ source: Source;
33
+ } | {
34
+ from: CommandRef;
35
+ to: EventRef;
36
+ source: Source;
37
+ };
38
+ export {};
39
+ //# sourceMappingURL=edge.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"edge.d.ts","sourceRoot":"","sources":["../src/edge.ts"],"names":[],"mappings":"AAAA,KAAK,QAAQ,GAAG;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAChD,KAAK,UAAU,GAAG;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AACpD,KAAK,OAAO,GAAG;IAAE,IAAI,EAAE,MAAM,GAAG,WAAW,GAAG,YAAY,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAC3E,KAAK,MAAM,GAAG;IAAE,IAAI,EAAE,MAAM,GAAG,WAAW,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAE3D,KAAK,MAAM,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAE9C,MAAM,MAAM,IAAI,GACZ;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,EAAE,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAC/C;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,UAAU,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAChD;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,QAAQ,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAC9C;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,EAAE,EAAE,QAAQ,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=_example.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_example.d.ts","sourceRoot":"","sources":["../../../src/engine/defaults/_example.ts"],"names":[],"mappings":""}
@@ -0,0 +1,14 @@
1
+ import type { Class, Decorator, MethodDefinition, Node } from "oxc-parser";
2
+ export declare function identifierName(node: Node | null | undefined): string | null;
3
+ export declare function memberPath(node: Node | null | undefined): string | null;
4
+ export declare function walkSubtree(node: Node | null | undefined, visit: (n: Node) => void): void;
5
+ export declare function readStringLiteral(node: Node | null | undefined): string | null;
6
+ export declare function superGenericIdentifier(node: Class): string | null;
7
+ export declare function reactorEvents(decorators: Decorator[] | undefined, allowedCallees: Set<string>): string[];
8
+ export declare function methodEffects(method: MethodDefinition): {
9
+ sends: string[];
10
+ emits: string[];
11
+ };
12
+ export declare function classMethods(node: Class): MethodDefinition[];
13
+ export declare function methodName(method: MethodDefinition): string | null;
14
+ //# sourceMappingURL=_utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_utils.d.ts","sourceRoot":"","sources":["../../../src/engine/defaults/_utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,KAAK,EACL,SAAS,EACT,gBAAgB,EAChB,IAAI,EACL,MAAM,YAAY,CAAC;AAEpB,wBAAgB,cAAc,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,GAAG,IAAI,CAM3E;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,GAAG,IAAI,CAQvE;AAOD,wBAAgB,WAAW,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,GAAG,SAAS,EAAE,KAAK,EAAE,CAAC,CAAC,EAAE,IAAI,KAAK,IAAI,QAYlF;AAED,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,GAAG,SAAS,iBAK9D;AAED,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,KAAK,iBAKjD;AAED,wBAAgB,aAAa,CAC3B,UAAU,EAAE,SAAS,EAAE,GAAG,SAAS,EACnC,cAAc,EAAE,GAAG,CAAC,MAAM,CAAC,YAc5B;AAKD,wBAAgB,aAAa,CAAC,MAAM,EAAE,gBAAgB;;;EAmCrD;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,KAAK,sBAQvC;AAED,wBAAgB,UAAU,CAAC,MAAM,EAAE,gBAAgB,iBAElD"}
@@ -0,0 +1,106 @@
1
+ //#region src/engine/defaults/_utils.ts
2
+ function identifierName(node) {
3
+ if (!node) return null;
4
+ if (node.type === "Identifier") return node.name;
5
+ if (node.type === "PrivateIdentifier") return node.name;
6
+ if (node.type === "MemberExpression") return identifierName(node.property);
7
+ return null;
8
+ }
9
+ function memberPath(node) {
10
+ if (!node) return null;
11
+ if (node.type === "Identifier") return node.name;
12
+ if (node.type !== "MemberExpression") return null;
13
+ const left = memberPath(node.object);
14
+ const right = identifierName(node.property);
15
+ if (left && right) return `${left}.${right}`;
16
+ return right ?? left;
17
+ }
18
+ function isNode(value) {
19
+ if (!value || typeof value !== "object") return false;
20
+ return typeof value.type === "string";
21
+ }
22
+ function walkSubtree(node, visit) {
23
+ if (!node) return;
24
+ visit(node);
25
+ for (const key of Object.keys(node)) {
26
+ if (key === "loc" || key === "range" || key === "parent") continue;
27
+ const child = node[key];
28
+ if (Array.isArray(child)) {
29
+ for (const c of child) if (isNode(c)) walkSubtree(c, visit);
30
+ } else if (isNode(child)) walkSubtree(child, visit);
31
+ }
32
+ }
33
+ function readStringLiteral(node) {
34
+ if (!node) return null;
35
+ if (node.type !== "Literal") return null;
36
+ if (typeof node.value !== "string") return null;
37
+ return node.value;
38
+ }
39
+ function superGenericIdentifier(node) {
40
+ const first = node.superTypeArguments?.params[0];
41
+ if (!first || first.type !== "TSTypeReference") return null;
42
+ if (first.typeName.type !== "Identifier") return null;
43
+ return first.typeName.name;
44
+ }
45
+ function reactorEvents(decorators, allowedCallees) {
46
+ if (!decorators) return [];
47
+ const events = [];
48
+ for (const d of decorators) {
49
+ if (d.expression.type !== "CallExpression") continue;
50
+ const callee = memberPath(d.expression.callee);
51
+ if (!callee || !allowedCallees.has(callee)) continue;
52
+ const a0 = d.expression.arguments[0];
53
+ if (a0?.type === "Identifier") events.push(a0.name);
54
+ }
55
+ return events;
56
+ }
57
+ const SEND_MEMBERS = new Set([
58
+ "execute",
59
+ "dispatch",
60
+ "send"
61
+ ]);
62
+ const EMIT_MEMBERS = new Set(["publish", "emit"]);
63
+ function methodEffects(method) {
64
+ const sends = /* @__PURE__ */ new Set();
65
+ const emits = /* @__PURE__ */ new Set();
66
+ const consumedNew = /* @__PURE__ */ new WeakSet();
67
+ walkSubtree(method.value.body, (n) => {
68
+ if (n.type !== "CallExpression") return;
69
+ const a0 = n.arguments[0];
70
+ let arg0New = null;
71
+ if (a0?.type === "NewExpression") arg0New = identifierName(a0.callee);
72
+ else if (a0?.type === "Identifier") arg0New = a0.name;
73
+ if (!arg0New) return;
74
+ if (n.callee.type !== "MemberExpression") return;
75
+ const member = identifierName(n.callee.property);
76
+ if (!member) return;
77
+ if (SEND_MEMBERS.has(member)) {
78
+ sends.add(arg0New);
79
+ if (a0?.type === "NewExpression") consumedNew.add(a0);
80
+ } else if (EMIT_MEMBERS.has(member)) {
81
+ emits.add(arg0New);
82
+ if (a0?.type === "NewExpression") consumedNew.add(a0);
83
+ }
84
+ });
85
+ walkSubtree(method.value.body, (n) => {
86
+ if (n.type !== "NewExpression") return;
87
+ if (consumedNew.has(n)) return;
88
+ const id = identifierName(n.callee);
89
+ if (id) emits.add(id);
90
+ });
91
+ return {
92
+ sends: [...sends],
93
+ emits: [...emits]
94
+ };
95
+ }
96
+ function classMethods(node) {
97
+ const out = [];
98
+ for (const member of node.body.body) if (member.type === "MethodDefinition" || member.type === "TSAbstractMethodDefinition") out.push(member);
99
+ return out;
100
+ }
101
+ function methodName(method) {
102
+ return identifierName(method.key);
103
+ }
104
+
105
+ //#endregion
106
+ export { classMethods, identifierName, memberPath, methodEffects, methodName, reactorEvents, readStringLiteral, superGenericIdentifier, walkSubtree };
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=command-handler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"command-handler.d.ts","sourceRoot":"","sources":["../../../src/engine/defaults/command-handler.ts"],"names":[],"mappings":""}
@@ -0,0 +1,36 @@
1
+ import { engine } from "../engine.mjs";
2
+ import { identifierName, superGenericIdentifier, walkSubtree } from "./_utils.mjs";
3
+
4
+ //#region src/engine/defaults/command-handler.ts
5
+ engine.on((node, parent, ctx, file) => {
6
+ if (node.type !== "ClassDeclaration") return;
7
+ if (!node.id) return;
8
+ const sup = node.superClass;
9
+ if (sup?.type !== "Identifier" || sup.name !== "CommandHandler") return;
10
+ const command = superGenericIdentifier(node);
11
+ if (!command) return;
12
+ const seen = /* @__PURE__ */ new Set();
13
+ walkSubtree(node.body, (n) => {
14
+ if (n.type !== "NewExpression") return;
15
+ const event = identifierName(n.callee);
16
+ if (!event || seen.has(event)) return;
17
+ seen.add(event);
18
+ engine.saveEdge({
19
+ from: {
20
+ type: "command",
21
+ name: command
22
+ },
23
+ to: {
24
+ type: "event",
25
+ name: event
26
+ },
27
+ source: {
28
+ file,
29
+ start: n.start
30
+ }
31
+ });
32
+ });
33
+ });
34
+
35
+ //#endregion
36
+ export { };
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=command.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"command.d.ts","sourceRoot":"","sources":["../../../src/engine/defaults/command.ts"],"names":[],"mappings":""}
@@ -0,0 +1,29 @@
1
+ import { engine } from "../engine.mjs";
2
+
3
+ //#region src/engine/defaults/command.ts
4
+ const COMMAND_BASES = new Set(["$Command", "Command"]);
5
+ engine.on((node, parent, ctx, file) => {
6
+ if (node.type !== "ClassDeclaration") return;
7
+ if (!node.id) return;
8
+ const sup = node.superClass;
9
+ if (!sup) return;
10
+ let base = null;
11
+ if (sup.type === "Identifier") {
12
+ if (COMMAND_BASES.has(sup.name)) base = sup.name;
13
+ } else if (sup.type === "CallExpression") {
14
+ if (sup.callee?.type === "Identifier" && COMMAND_BASES.has(sup.callee.name)) base = sup.callee.name;
15
+ }
16
+ if (!base) return;
17
+ engine.saveNode({
18
+ type: "command",
19
+ name: node.id.name,
20
+ meta: { base },
21
+ source: {
22
+ file,
23
+ start: node.start
24
+ }
25
+ });
26
+ });
27
+
28
+ //#endregion
29
+ export { };
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=es-aggregate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"es-aggregate.d.ts","sourceRoot":"","sources":["../../../src/engine/defaults/es-aggregate.ts"],"names":[],"mappings":""}
@@ -0,0 +1,82 @@
1
+ import { engine } from "../engine.mjs";
2
+ import { classMethods, methodEffects, methodName, reactorEvents } from "./_utils.mjs";
3
+
4
+ //#region src/engine/defaults/es-aggregate.ts
5
+ const REACTOR_DECORATORS = new Set([
6
+ "EsAggregate.on",
7
+ "on",
8
+ "On"
9
+ ]);
10
+ engine.on((node, parent, ctx, file) => {
11
+ if (node.type !== "ClassDeclaration") return;
12
+ if (!node.id) return;
13
+ const sup = node.superClass;
14
+ if (!sup) return;
15
+ if (sup.type === "Identifier") {
16
+ if (sup.name !== "EsAggregate") return;
17
+ } else if (sup.type === "CallExpression") {
18
+ if (sup.callee?.type !== "Identifier" || sup.callee.name !== "EsAggregate") return;
19
+ } else return;
20
+ const className = node.id.name;
21
+ for (const method of classMethods(node)) {
22
+ const name = methodName(method);
23
+ if (!name) continue;
24
+ const events = reactorEvents(method.decorators, REACTOR_DECORATORS);
25
+ if (!events.length) continue;
26
+ const handlerName = `${className}.${name}`;
27
+ engine.saveNode({
28
+ type: "aggregate",
29
+ name: handlerName,
30
+ source: {
31
+ file,
32
+ start: method.start
33
+ }
34
+ });
35
+ for (const event of events) engine.saveEdge({
36
+ from: {
37
+ type: "event",
38
+ name: event
39
+ },
40
+ to: {
41
+ type: "aggregate",
42
+ name: handlerName
43
+ },
44
+ source: {
45
+ file,
46
+ start: method.start
47
+ }
48
+ });
49
+ const effects = methodEffects(method);
50
+ for (const command of effects.sends) engine.saveEdge({
51
+ from: {
52
+ type: "aggregate",
53
+ name: handlerName
54
+ },
55
+ to: {
56
+ type: "command",
57
+ name: command
58
+ },
59
+ source: {
60
+ file,
61
+ start: method.start
62
+ }
63
+ });
64
+ for (const event of effects.emits) engine.saveEdge({
65
+ from: {
66
+ type: "aggregate",
67
+ name: handlerName
68
+ },
69
+ to: {
70
+ type: "event",
71
+ name: event
72
+ },
73
+ source: {
74
+ file,
75
+ start: method.start
76
+ }
77
+ });
78
+ }
79
+ });
80
+
81
+ //#endregion
82
+ export { };
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=event.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event.d.ts","sourceRoot":"","sources":["../../../src/engine/defaults/event.ts"],"names":[],"mappings":""}
@@ -0,0 +1,49 @@
1
+ import { engine } from "../engine.mjs";
2
+ import { readStringLiteral } from "./_utils.mjs";
3
+
4
+ //#region src/engine/defaults/event.ts
5
+ const EVENT_BASES = new Set([
6
+ "EsEvent",
7
+ "OldEvent",
8
+ "Event"
9
+ ]);
10
+ engine.on((node, parent, ctx, file) => {
11
+ if (node.type !== "ClassDeclaration") return;
12
+ if (!node.id) return;
13
+ const sup = node.superClass;
14
+ if (!sup) return;
15
+ if (sup.type === "Identifier") {
16
+ if (!EVENT_BASES.has(sup.name)) return;
17
+ engine.saveNode({
18
+ type: "event",
19
+ name: node.id.name,
20
+ meta: {
21
+ alias: node.id.name,
22
+ base: sup.name
23
+ },
24
+ source: {
25
+ file,
26
+ start: node.start
27
+ }
28
+ });
29
+ return;
30
+ }
31
+ if (sup.type !== "CallExpression") return;
32
+ if (sup.callee?.type !== "Identifier") return;
33
+ if (!EVENT_BASES.has(sup.callee.name)) return;
34
+ engine.saveNode({
35
+ type: "event",
36
+ name: node.id.name,
37
+ meta: {
38
+ alias: readStringLiteral(sup.arguments?.[0]) ?? node.id.name,
39
+ base: sup.callee.name
40
+ },
41
+ source: {
42
+ file,
43
+ start: node.start
44
+ }
45
+ });
46
+ });
47
+
48
+ //#endregion
49
+ export { };
@@ -0,0 +1,8 @@
1
+ import "./event";
2
+ import "./command";
3
+ import "./saga";
4
+ import "./es-aggregate";
5
+ import "./projection";
6
+ import "./command-handler";
7
+ import "./scanner";
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/engine/defaults/index.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,CAAC;AACjB,OAAO,WAAW,CAAC;AACnB,OAAO,QAAQ,CAAC;AAChB,OAAO,gBAAgB,CAAC;AACxB,OAAO,cAAc,CAAC;AACtB,OAAO,mBAAmB,CAAC;AAC3B,OAAO,WAAW,CAAC"}
@@ -0,0 +1,9 @@
1
+ import "./event.mjs";
2
+ import "./command.mjs";
3
+ import "./saga.mjs";
4
+ import "./es-aggregate.mjs";
5
+ import "./projection.mjs";
6
+ import "./command-handler.mjs";
7
+ import "./scanner.mjs";
8
+
9
+ export { };
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=projection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"projection.d.ts","sourceRoot":"","sources":["../../../src/engine/defaults/projection.ts"],"names":[],"mappings":""}
@@ -0,0 +1,59 @@
1
+ import { engine } from "../engine.mjs";
2
+ import { classMethods, memberPath, methodName, reactorEvents, readStringLiteral } from "./_utils.mjs";
3
+
4
+ //#region src/engine/defaults/projection.ts
5
+ const REACTOR_DECORATORS = new Set([
6
+ "Projection.on",
7
+ "on",
8
+ "On"
9
+ ]);
10
+ const PROJECTION_CALLEES = new Set(["Projection", "Projection.from"]);
11
+ engine.on((node, parent, ctx, file) => {
12
+ if (node.type !== "ClassDeclaration") return;
13
+ if (!node.id) return;
14
+ const sup = node.superClass;
15
+ if (!sup) return;
16
+ let alias = null;
17
+ if (sup.type === "Identifier") {
18
+ if (sup.name !== "Projection") return;
19
+ } else if (sup.type === "CallExpression") {
20
+ const callee = memberPath(sup.callee);
21
+ if (!callee || !PROJECTION_CALLEES.has(callee)) return;
22
+ alias = readStringLiteral(sup.arguments?.[0]);
23
+ } else return;
24
+ const className = node.id.name;
25
+ const projectionAlias = alias ?? className;
26
+ for (const method of classMethods(node)) {
27
+ const name = methodName(method);
28
+ if (!name) continue;
29
+ const events = reactorEvents(method.decorators, REACTOR_DECORATORS);
30
+ if (!events.length) continue;
31
+ const handlerName = `${className}.${name}`;
32
+ engine.saveNode({
33
+ type: "projection",
34
+ name: handlerName,
35
+ meta: { alias: `${projectionAlias}.${name}` },
36
+ source: {
37
+ file,
38
+ start: method.start
39
+ }
40
+ });
41
+ for (const event of events) engine.saveEdge({
42
+ from: {
43
+ type: "event",
44
+ name: event
45
+ },
46
+ to: {
47
+ type: "projection",
48
+ name: handlerName
49
+ },
50
+ source: {
51
+ file,
52
+ start: method.start
53
+ }
54
+ });
55
+ }
56
+ });
57
+
58
+ //#endregion
59
+ export { };
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=saga.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"saga.d.ts","sourceRoot":"","sources":["../../../src/engine/defaults/saga.ts"],"names":[],"mappings":""}
@@ -0,0 +1,77 @@
1
+ import { engine } from "../engine.mjs";
2
+ import { classMethods, methodEffects, methodName, reactorEvents } from "./_utils.mjs";
3
+
4
+ //#region src/engine/defaults/saga.ts
5
+ const REACTOR_DECORATORS = new Set([
6
+ "Saga.on",
7
+ "on",
8
+ "On"
9
+ ]);
10
+ engine.on((node, parent, ctx, file) => {
11
+ if (node.type !== "ClassDeclaration") return;
12
+ if (!node.id) return;
13
+ const sup = node.superClass;
14
+ if (sup?.type !== "Identifier" || sup.name !== "Saga") return;
15
+ const className = node.id.name;
16
+ for (const method of classMethods(node)) {
17
+ const name = methodName(method);
18
+ if (!name) continue;
19
+ const events = reactorEvents(method.decorators, REACTOR_DECORATORS);
20
+ if (!events.length) continue;
21
+ const handlerName = `${className}.${name}`;
22
+ engine.saveNode({
23
+ type: "saga",
24
+ name: handlerName,
25
+ source: {
26
+ file,
27
+ start: method.start
28
+ }
29
+ });
30
+ for (const event of events) engine.saveEdge({
31
+ from: {
32
+ type: "event",
33
+ name: event
34
+ },
35
+ to: {
36
+ type: "saga",
37
+ name: handlerName
38
+ },
39
+ source: {
40
+ file,
41
+ start: method.start
42
+ }
43
+ });
44
+ const effects = methodEffects(method);
45
+ for (const command of effects.sends) engine.saveEdge({
46
+ from: {
47
+ type: "saga",
48
+ name: handlerName
49
+ },
50
+ to: {
51
+ type: "command",
52
+ name: command
53
+ },
54
+ source: {
55
+ file,
56
+ start: method.start
57
+ }
58
+ });
59
+ for (const event of effects.emits) engine.saveEdge({
60
+ from: {
61
+ type: "saga",
62
+ name: handlerName
63
+ },
64
+ to: {
65
+ type: "event",
66
+ name: event
67
+ },
68
+ source: {
69
+ file,
70
+ start: method.start
71
+ }
72
+ });
73
+ }
74
+ });
75
+
76
+ //#endregion
77
+ export { };
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=scanner.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scanner.d.ts","sourceRoot":"","sources":["../../../src/engine/defaults/scanner.ts"],"names":[],"mappings":""}
@@ -0,0 +1,29 @@
1
+ import { engine } from "../engine.mjs";
2
+ import fs from "node:fs";
3
+ import { join } from "node:path";
4
+
5
+ //#region src/engine/defaults/scanner.ts
6
+ engine.scan(function* (root = process.cwd()) {
7
+ yield* fs.globSync("**/*.ts", {
8
+ cwd: root,
9
+ exclude: [
10
+ "**/node_modules/**",
11
+ "**/dist/**",
12
+ "**/build/**",
13
+ "**/.git/**",
14
+ "**/.turbo/**",
15
+ "**/coverage/**",
16
+ "**/.next/**",
17
+ "**/.cache/**",
18
+ "**/.vite/**",
19
+ "**/*.d.ts",
20
+ "**/*.spec.ts",
21
+ "**/*.test.ts",
22
+ "**/*.typecheck.spec.ts"
23
+ ],
24
+ withFileTypes: false
25
+ }).map((p) => join(root, p));
26
+ });
27
+
28
+ //#endregion
29
+ export { };
@@ -0,0 +1,21 @@
1
+ import { type WalkerEnter } from "oxc-walker";
2
+ import type { Node } from "../node";
3
+ import type { Edge } from "../edge";
4
+ type AstWalker = (...args: [...Parameters<WalkerEnter>, file: string]) => ReturnType<WalkerEnter>;
5
+ export declare class Engine {
6
+ private astWalkers;
7
+ on(walker: AstWalker): this;
8
+ private fileScanner;
9
+ scan(fileScanner: (root: string) => Iterable<string>): this;
10
+ private edges;
11
+ saveEdge(edge: Edge): void;
12
+ getEdges(): readonly Edge[];
13
+ private nodes;
14
+ saveNode(node: Node): void;
15
+ getNodes(): readonly Node[];
16
+ reset(): void;
17
+ run(root?: string): void;
18
+ }
19
+ export declare const engine: Engine;
20
+ export {};
21
+ //# sourceMappingURL=engine.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../../src/engine/engine.ts"],"names":[],"mappings":"AACA,OAAO,EAAgB,KAAK,WAAW,EAAE,MAAM,YAAY,CAAC;AAC5D,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAEpC,KAAK,SAAS,GAAG,CAAC,GAAG,IAAI,EAAE,CAAC,GAAG,UAAU,CAAC,WAAW,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,KAAK,UAAU,CAAC,WAAW,CAAC,CAAA;AAEjG,qBAAa,MAAM;IACjB,OAAO,CAAC,UAAU,CAAkB;IAEpC,EAAE,CAAC,MAAM,EAAE,SAAS;IAKpB,OAAO,CAAC,WAAW,CAEjB;IACF,IAAI,CAAC,WAAW,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,QAAQ,CAAC,MAAM,CAAC;IAKpD,OAAO,CAAC,KAAK,CAAc;IAC3B,QAAQ,CAAC,IAAI,EAAE,IAAI;IAGnB,QAAQ,IAAI,SAAS,IAAI,EAAE;IAI3B,OAAO,CAAC,KAAK,CAAc;IAC3B,QAAQ,CAAC,IAAI,EAAE,IAAI;IAGnB,QAAQ,IAAI,SAAS,IAAI,EAAE;IAI3B,KAAK;IAKL,GAAG,CAAC,IAAI,GAAE,MAAsB;CAiBjC;AAED,eAAO,MAAM,MAAM,QAAe,CAAC"}
@@ -0,0 +1,54 @@
1
+ import fs from "node:fs";
2
+ import { parseAndWalk } from "oxc-walker";
3
+
4
+ //#region src/engine/engine.ts
5
+ var Engine = class {
6
+ astWalkers = [];
7
+ on(walker) {
8
+ this.astWalkers.push(walker);
9
+ return this;
10
+ }
11
+ fileScanner = function* () {
12
+ console.warn(`No file scanner configured for event-tree engine. Please call engine.scan() with a file scanner function.`);
13
+ };
14
+ scan(fileScanner) {
15
+ this.fileScanner = fileScanner;
16
+ return this;
17
+ }
18
+ edges = [];
19
+ saveEdge(edge) {
20
+ this.edges.push(edge);
21
+ }
22
+ getEdges() {
23
+ return this.edges;
24
+ }
25
+ nodes = [];
26
+ saveNode(node) {
27
+ this.nodes.push(node);
28
+ }
29
+ getNodes() {
30
+ return this.nodes;
31
+ }
32
+ reset() {
33
+ this.edges = [];
34
+ this.nodes = [];
35
+ }
36
+ run(root = process.cwd()) {
37
+ for (const file of this.fileScanner(root)) {
38
+ const code = fs.readFileSync(file, "utf8");
39
+ const walkers = this.astWalkers;
40
+ parseAndWalk(code, file, { enter: function(node, parent, ctx) {
41
+ for (const walker of walkers) try {
42
+ walker.call(this, node, parent, ctx, file);
43
+ } catch (error) {
44
+ console.error(`Error occurred while walking node in file ${file}:`, error);
45
+ }
46
+ } });
47
+ }
48
+ }
49
+ };
50
+ const engine = new Engine();
51
+ await import("./defaults/index.mjs");
52
+
53
+ //#endregion
54
+ export { Engine, engine };
package/dist/index.mjs ADDED
@@ -0,0 +1,3 @@
1
+ import { Engine, engine } from "./engine/engine.mjs";
2
+
3
+ export { Engine, engine };
package/dist/node.d.ts ADDED
@@ -0,0 +1,37 @@
1
+ type Source = {
2
+ file: string;
3
+ start: number;
4
+ };
5
+ export type Node = {
6
+ type: "event";
7
+ name: string;
8
+ meta: {
9
+ alias: string;
10
+ base: string;
11
+ };
12
+ source: Source;
13
+ } | {
14
+ type: "command";
15
+ name: string;
16
+ meta: {
17
+ base: string;
18
+ };
19
+ source: Source;
20
+ } | {
21
+ type: "saga";
22
+ name: string;
23
+ source: Source;
24
+ } | {
25
+ type: "aggregate";
26
+ name: string;
27
+ source: Source;
28
+ } | {
29
+ type: "projection";
30
+ name: string;
31
+ meta: {
32
+ alias: string;
33
+ };
34
+ source: Source;
35
+ };
36
+ export {};
37
+ //# sourceMappingURL=node.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../src/node.ts"],"names":[],"mappings":"AAAA,KAAK,MAAM,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAE9C,MAAM,MAAM,IAAI,GACZ;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GACtF;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GACzE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAC9C;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GACnD;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC"}
@@ -0,0 +1,4 @@
1
+ export { engine, Engine } from "../engine/engine";
2
+ export type { Node } from "../node";
3
+ export type { Edge } from "../edge";
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAClD,YAAY,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AACpC,YAAY,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ddd-ts/event-tree",
3
- "version": "0.0.0-eventviz.3",
3
+ "version": "0.0.0-eventviz.4",
4
4
  "types": "dist/server/index.d.ts",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -14,7 +14,7 @@
14
14
  "oxc-walker": "^1.0.0"
15
15
  },
16
16
  "devDependencies": {
17
- "@ddd-ts/tools": "0.0.0-eventviz.3",
17
+ "@ddd-ts/tools": "0.0.0-eventviz.4",
18
18
  "@types/node": "^22.14.1"
19
19
  },
20
20
  "exports": {