@ddd-ts/event-tree 0.0.0-eventviz.10
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/dist/edge.d.ts +39 -0
- package/dist/edge.d.ts.map +1 -0
- package/dist/engine/defaults/_example.d.ts +2 -0
- package/dist/engine/defaults/_example.d.ts.map +1 -0
- package/dist/engine/defaults/_utils.d.ts +14 -0
- package/dist/engine/defaults/_utils.d.ts.map +1 -0
- package/dist/engine/defaults/_utils.mjs +105 -0
- package/dist/engine/defaults/command-handler.d.ts +2 -0
- package/dist/engine/defaults/command-handler.d.ts.map +1 -0
- package/dist/engine/defaults/command-handler.mjs +34 -0
- package/dist/engine/defaults/command.d.ts +2 -0
- package/dist/engine/defaults/command.d.ts.map +1 -0
- package/dist/engine/defaults/command.mjs +27 -0
- package/dist/engine/defaults/es-aggregate.d.ts +2 -0
- package/dist/engine/defaults/es-aggregate.d.ts.map +1 -0
- package/dist/engine/defaults/es-aggregate.mjs +80 -0
- package/dist/engine/defaults/event.d.ts +2 -0
- package/dist/engine/defaults/event.d.ts.map +1 -0
- package/dist/engine/defaults/event.mjs +47 -0
- package/dist/engine/defaults/index.d.ts +8 -0
- package/dist/engine/defaults/index.d.ts.map +1 -0
- package/dist/engine/defaults/index.mjs +8 -0
- package/dist/engine/defaults/projection.d.ts +2 -0
- package/dist/engine/defaults/projection.d.ts.map +1 -0
- package/dist/engine/defaults/projection.mjs +57 -0
- package/dist/engine/defaults/saga.d.ts +2 -0
- package/dist/engine/defaults/saga.d.ts.map +1 -0
- package/dist/engine/defaults/saga.mjs +75 -0
- package/dist/engine/defaults/scanner.d.ts +2 -0
- package/dist/engine/defaults/scanner.d.ts.map +1 -0
- package/dist/engine/defaults/scanner.mjs +27 -0
- package/dist/engine/engine.d.ts +21 -0
- package/dist/engine/engine.d.ts.map +1 -0
- package/dist/engine/engine.mjs +52 -0
- package/dist/index.mjs +2 -0
- package/dist/node.d.ts +37 -0
- package/dist/node.d.ts.map +1 -0
- package/dist/server/index.d.ts +4 -0
- package/dist/server/index.d.ts.map +1 -0
- package/package.json +30 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Aetherall
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
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 @@
|
|
|
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,105 @@
|
|
|
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
|
+
//#endregion
|
|
105
|
+
export { classMethods, identifierName, memberPath, methodEffects, methodName, reactorEvents, readStringLiteral, superGenericIdentifier, walkSubtree };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"command-handler.d.ts","sourceRoot":"","sources":["../../../src/engine/defaults/command-handler.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { engine } from "../engine.mjs";
|
|
2
|
+
import { identifierName, superGenericIdentifier, walkSubtree } from "./_utils.mjs";
|
|
3
|
+
//#region src/engine/defaults/command-handler.ts
|
|
4
|
+
engine.on((node, parent, ctx, file) => {
|
|
5
|
+
if (node.type !== "ClassDeclaration") return;
|
|
6
|
+
if (!node.id) return;
|
|
7
|
+
const sup = node.superClass;
|
|
8
|
+
if (sup?.type !== "Identifier" || sup.name !== "CommandHandler") return;
|
|
9
|
+
const command = superGenericIdentifier(node);
|
|
10
|
+
if (!command) return;
|
|
11
|
+
const seen = /* @__PURE__ */ new Set();
|
|
12
|
+
walkSubtree(node.body, (n) => {
|
|
13
|
+
if (n.type !== "NewExpression") return;
|
|
14
|
+
const event = identifierName(n.callee);
|
|
15
|
+
if (!event || seen.has(event)) return;
|
|
16
|
+
seen.add(event);
|
|
17
|
+
engine.saveEdge({
|
|
18
|
+
from: {
|
|
19
|
+
type: "command",
|
|
20
|
+
name: command
|
|
21
|
+
},
|
|
22
|
+
to: {
|
|
23
|
+
type: "event",
|
|
24
|
+
name: event
|
|
25
|
+
},
|
|
26
|
+
source: {
|
|
27
|
+
file,
|
|
28
|
+
start: n.start
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
//#endregion
|
|
34
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"command.d.ts","sourceRoot":"","sources":["../../../src/engine/defaults/command.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { engine } from "../engine.mjs";
|
|
2
|
+
//#region src/engine/defaults/command.ts
|
|
3
|
+
const COMMAND_BASES = new Set(["$Command", "Command"]);
|
|
4
|
+
engine.on((node, parent, ctx, file) => {
|
|
5
|
+
if (node.type !== "ClassDeclaration") return;
|
|
6
|
+
if (!node.id) return;
|
|
7
|
+
const sup = node.superClass;
|
|
8
|
+
if (!sup) return;
|
|
9
|
+
let base = null;
|
|
10
|
+
if (sup.type === "Identifier") {
|
|
11
|
+
if (COMMAND_BASES.has(sup.name)) base = sup.name;
|
|
12
|
+
} else if (sup.type === "CallExpression") {
|
|
13
|
+
if (sup.callee?.type === "Identifier" && COMMAND_BASES.has(sup.callee.name)) base = sup.callee.name;
|
|
14
|
+
}
|
|
15
|
+
if (!base) return;
|
|
16
|
+
engine.saveNode({
|
|
17
|
+
type: "command",
|
|
18
|
+
name: node.id.name,
|
|
19
|
+
meta: { base },
|
|
20
|
+
source: {
|
|
21
|
+
file,
|
|
22
|
+
start: node.start
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
//#endregion
|
|
27
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"es-aggregate.d.ts","sourceRoot":"","sources":["../../../src/engine/defaults/es-aggregate.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { engine } from "../engine.mjs";
|
|
2
|
+
import { classMethods, methodEffects, methodName, reactorEvents } from "./_utils.mjs";
|
|
3
|
+
//#region src/engine/defaults/es-aggregate.ts
|
|
4
|
+
const REACTOR_DECORATORS = new Set([
|
|
5
|
+
"EsAggregate.on",
|
|
6
|
+
"on",
|
|
7
|
+
"On"
|
|
8
|
+
]);
|
|
9
|
+
engine.on((node, parent, ctx, file) => {
|
|
10
|
+
if (node.type !== "ClassDeclaration") return;
|
|
11
|
+
if (!node.id) return;
|
|
12
|
+
const sup = node.superClass;
|
|
13
|
+
if (!sup) return;
|
|
14
|
+
if (sup.type === "Identifier") {
|
|
15
|
+
if (sup.name !== "EsAggregate") return;
|
|
16
|
+
} else if (sup.type === "CallExpression") {
|
|
17
|
+
if (sup.callee?.type !== "Identifier" || sup.callee.name !== "EsAggregate") return;
|
|
18
|
+
} else return;
|
|
19
|
+
const className = node.id.name;
|
|
20
|
+
for (const method of classMethods(node)) {
|
|
21
|
+
const name = methodName(method);
|
|
22
|
+
if (!name) continue;
|
|
23
|
+
const events = reactorEvents(method.decorators, REACTOR_DECORATORS);
|
|
24
|
+
if (!events.length) continue;
|
|
25
|
+
const handlerName = `${className}.${name}`;
|
|
26
|
+
engine.saveNode({
|
|
27
|
+
type: "aggregate",
|
|
28
|
+
name: handlerName,
|
|
29
|
+
source: {
|
|
30
|
+
file,
|
|
31
|
+
start: method.start
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
for (const event of events) engine.saveEdge({
|
|
35
|
+
from: {
|
|
36
|
+
type: "event",
|
|
37
|
+
name: event
|
|
38
|
+
},
|
|
39
|
+
to: {
|
|
40
|
+
type: "aggregate",
|
|
41
|
+
name: handlerName
|
|
42
|
+
},
|
|
43
|
+
source: {
|
|
44
|
+
file,
|
|
45
|
+
start: method.start
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
const effects = methodEffects(method);
|
|
49
|
+
for (const command of effects.sends) engine.saveEdge({
|
|
50
|
+
from: {
|
|
51
|
+
type: "aggregate",
|
|
52
|
+
name: handlerName
|
|
53
|
+
},
|
|
54
|
+
to: {
|
|
55
|
+
type: "command",
|
|
56
|
+
name: command
|
|
57
|
+
},
|
|
58
|
+
source: {
|
|
59
|
+
file,
|
|
60
|
+
start: method.start
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
for (const event of effects.emits) engine.saveEdge({
|
|
64
|
+
from: {
|
|
65
|
+
type: "aggregate",
|
|
66
|
+
name: handlerName
|
|
67
|
+
},
|
|
68
|
+
to: {
|
|
69
|
+
type: "event",
|
|
70
|
+
name: event
|
|
71
|
+
},
|
|
72
|
+
source: {
|
|
73
|
+
file,
|
|
74
|
+
start: method.start
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
//#endregion
|
|
80
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event.d.ts","sourceRoot":"","sources":["../../../src/engine/defaults/event.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { engine } from "../engine.mjs";
|
|
2
|
+
import { readStringLiteral } from "./_utils.mjs";
|
|
3
|
+
//#region src/engine/defaults/event.ts
|
|
4
|
+
const EVENT_BASES = new Set([
|
|
5
|
+
"EsEvent",
|
|
6
|
+
"OldEvent",
|
|
7
|
+
"Event"
|
|
8
|
+
]);
|
|
9
|
+
engine.on((node, parent, ctx, file) => {
|
|
10
|
+
if (node.type !== "ClassDeclaration") return;
|
|
11
|
+
if (!node.id) return;
|
|
12
|
+
const sup = node.superClass;
|
|
13
|
+
if (!sup) return;
|
|
14
|
+
if (sup.type === "Identifier") {
|
|
15
|
+
if (!EVENT_BASES.has(sup.name)) return;
|
|
16
|
+
engine.saveNode({
|
|
17
|
+
type: "event",
|
|
18
|
+
name: node.id.name,
|
|
19
|
+
meta: {
|
|
20
|
+
alias: node.id.name,
|
|
21
|
+
base: sup.name
|
|
22
|
+
},
|
|
23
|
+
source: {
|
|
24
|
+
file,
|
|
25
|
+
start: node.start
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
if (sup.type !== "CallExpression") return;
|
|
31
|
+
if (sup.callee?.type !== "Identifier") return;
|
|
32
|
+
if (!EVENT_BASES.has(sup.callee.name)) return;
|
|
33
|
+
engine.saveNode({
|
|
34
|
+
type: "event",
|
|
35
|
+
name: node.id.name,
|
|
36
|
+
meta: {
|
|
37
|
+
alias: readStringLiteral(sup.arguments?.[0]) ?? node.id.name,
|
|
38
|
+
base: sup.callee.name
|
|
39
|
+
},
|
|
40
|
+
source: {
|
|
41
|
+
file,
|
|
42
|
+
start: node.start
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
//#endregion
|
|
47
|
+
export {};
|
|
@@ -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 @@
|
|
|
1
|
+
{"version":3,"file":"projection.d.ts","sourceRoot":"","sources":["../../../src/engine/defaults/projection.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { engine } from "../engine.mjs";
|
|
2
|
+
import { classMethods, memberPath, methodName, reactorEvents, readStringLiteral } from "./_utils.mjs";
|
|
3
|
+
//#region src/engine/defaults/projection.ts
|
|
4
|
+
const REACTOR_DECORATORS = new Set([
|
|
5
|
+
"Projection.on",
|
|
6
|
+
"on",
|
|
7
|
+
"On"
|
|
8
|
+
]);
|
|
9
|
+
const PROJECTION_CALLEES = new Set(["Projection", "Projection.from"]);
|
|
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
|
+
let alias = null;
|
|
16
|
+
if (sup.type === "Identifier") {
|
|
17
|
+
if (sup.name !== "Projection") return;
|
|
18
|
+
} else if (sup.type === "CallExpression") {
|
|
19
|
+
const callee = memberPath(sup.callee);
|
|
20
|
+
if (!callee || !PROJECTION_CALLEES.has(callee)) return;
|
|
21
|
+
alias = readStringLiteral(sup.arguments?.[0]);
|
|
22
|
+
} else return;
|
|
23
|
+
const className = node.id.name;
|
|
24
|
+
const projectionAlias = alias ?? className;
|
|
25
|
+
for (const method of classMethods(node)) {
|
|
26
|
+
const name = methodName(method);
|
|
27
|
+
if (!name) continue;
|
|
28
|
+
const events = reactorEvents(method.decorators, REACTOR_DECORATORS);
|
|
29
|
+
if (!events.length) continue;
|
|
30
|
+
const handlerName = `${className}.${name}`;
|
|
31
|
+
engine.saveNode({
|
|
32
|
+
type: "projection",
|
|
33
|
+
name: handlerName,
|
|
34
|
+
meta: { alias: `${projectionAlias}.${name}` },
|
|
35
|
+
source: {
|
|
36
|
+
file,
|
|
37
|
+
start: method.start
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
for (const event of events) engine.saveEdge({
|
|
41
|
+
from: {
|
|
42
|
+
type: "event",
|
|
43
|
+
name: event
|
|
44
|
+
},
|
|
45
|
+
to: {
|
|
46
|
+
type: "projection",
|
|
47
|
+
name: handlerName
|
|
48
|
+
},
|
|
49
|
+
source: {
|
|
50
|
+
file,
|
|
51
|
+
start: method.start
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
//#endregion
|
|
57
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"saga.d.ts","sourceRoot":"","sources":["../../../src/engine/defaults/saga.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { engine } from "../engine.mjs";
|
|
2
|
+
import { classMethods, methodEffects, methodName, reactorEvents } from "./_utils.mjs";
|
|
3
|
+
//#region src/engine/defaults/saga.ts
|
|
4
|
+
const REACTOR_DECORATORS = new Set([
|
|
5
|
+
"Saga.on",
|
|
6
|
+
"on",
|
|
7
|
+
"On"
|
|
8
|
+
]);
|
|
9
|
+
engine.on((node, parent, ctx, file) => {
|
|
10
|
+
if (node.type !== "ClassDeclaration") return;
|
|
11
|
+
if (!node.id) return;
|
|
12
|
+
const sup = node.superClass;
|
|
13
|
+
if (sup?.type !== "Identifier" || sup.name !== "Saga") return;
|
|
14
|
+
const className = node.id.name;
|
|
15
|
+
for (const method of classMethods(node)) {
|
|
16
|
+
const name = methodName(method);
|
|
17
|
+
if (!name) continue;
|
|
18
|
+
const events = reactorEvents(method.decorators, REACTOR_DECORATORS);
|
|
19
|
+
if (!events.length) continue;
|
|
20
|
+
const handlerName = `${className}.${name}`;
|
|
21
|
+
engine.saveNode({
|
|
22
|
+
type: "saga",
|
|
23
|
+
name: handlerName,
|
|
24
|
+
source: {
|
|
25
|
+
file,
|
|
26
|
+
start: method.start
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
for (const event of events) engine.saveEdge({
|
|
30
|
+
from: {
|
|
31
|
+
type: "event",
|
|
32
|
+
name: event
|
|
33
|
+
},
|
|
34
|
+
to: {
|
|
35
|
+
type: "saga",
|
|
36
|
+
name: handlerName
|
|
37
|
+
},
|
|
38
|
+
source: {
|
|
39
|
+
file,
|
|
40
|
+
start: method.start
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
const effects = methodEffects(method);
|
|
44
|
+
for (const command of effects.sends) engine.saveEdge({
|
|
45
|
+
from: {
|
|
46
|
+
type: "saga",
|
|
47
|
+
name: handlerName
|
|
48
|
+
},
|
|
49
|
+
to: {
|
|
50
|
+
type: "command",
|
|
51
|
+
name: command
|
|
52
|
+
},
|
|
53
|
+
source: {
|
|
54
|
+
file,
|
|
55
|
+
start: method.start
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
for (const event of effects.emits) engine.saveEdge({
|
|
59
|
+
from: {
|
|
60
|
+
type: "saga",
|
|
61
|
+
name: handlerName
|
|
62
|
+
},
|
|
63
|
+
to: {
|
|
64
|
+
type: "event",
|
|
65
|
+
name: event
|
|
66
|
+
},
|
|
67
|
+
source: {
|
|
68
|
+
file,
|
|
69
|
+
start: method.start
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
//#endregion
|
|
75
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scanner.d.ts","sourceRoot":"","sources":["../../../src/engine/defaults/scanner.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { engine } from "../engine.mjs";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
//#region src/engine/defaults/scanner.ts
|
|
5
|
+
engine.scan(function* (root = process.cwd()) {
|
|
6
|
+
yield* fs.globSync("**/*.ts", {
|
|
7
|
+
cwd: root,
|
|
8
|
+
exclude: [
|
|
9
|
+
"**/node_modules/**",
|
|
10
|
+
"**/dist/**",
|
|
11
|
+
"**/build/**",
|
|
12
|
+
"**/.git/**",
|
|
13
|
+
"**/.turbo/**",
|
|
14
|
+
"**/coverage/**",
|
|
15
|
+
"**/.next/**",
|
|
16
|
+
"**/.cache/**",
|
|
17
|
+
"**/.vite/**",
|
|
18
|
+
"**/*.d.ts",
|
|
19
|
+
"**/*.spec.ts",
|
|
20
|
+
"**/*.test.ts",
|
|
21
|
+
"**/*.typecheck.spec.ts"
|
|
22
|
+
],
|
|
23
|
+
withFileTypes: false
|
|
24
|
+
}).map((p) => join(root, p));
|
|
25
|
+
});
|
|
26
|
+
//#endregion
|
|
27
|
+
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,CACf,GAAG,IAAI,EAAE,CAAC,GAAG,UAAU,CAAC,WAAW,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,KAChD,UAAU,CAAC,WAAW,CAAC,CAAC;AAE7B,qBAAa,MAAM;IACjB,OAAO,CAAC,UAAU,CAAmB;IAErC,EAAE,CAAC,MAAM,EAAE,SAAS;IAKpB,OAAO,CAAC,WAAW,CAIjB;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;CAoBjC;AAED,eAAO,MAAM,MAAM,QAAe,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import { parseAndWalk } from "oxc-walker";
|
|
3
|
+
//#region src/engine/engine.ts
|
|
4
|
+
var Engine = class {
|
|
5
|
+
astWalkers = [];
|
|
6
|
+
on(walker) {
|
|
7
|
+
this.astWalkers.push(walker);
|
|
8
|
+
return this;
|
|
9
|
+
}
|
|
10
|
+
fileScanner = function* () {
|
|
11
|
+
console.warn(`No file scanner configured for event-tree engine. Please call engine.scan() with a file scanner function.`);
|
|
12
|
+
};
|
|
13
|
+
scan(fileScanner) {
|
|
14
|
+
this.fileScanner = fileScanner;
|
|
15
|
+
return this;
|
|
16
|
+
}
|
|
17
|
+
edges = [];
|
|
18
|
+
saveEdge(edge) {
|
|
19
|
+
this.edges.push(edge);
|
|
20
|
+
}
|
|
21
|
+
getEdges() {
|
|
22
|
+
return this.edges;
|
|
23
|
+
}
|
|
24
|
+
nodes = [];
|
|
25
|
+
saveNode(node) {
|
|
26
|
+
this.nodes.push(node);
|
|
27
|
+
}
|
|
28
|
+
getNodes() {
|
|
29
|
+
return this.nodes;
|
|
30
|
+
}
|
|
31
|
+
reset() {
|
|
32
|
+
this.edges = [];
|
|
33
|
+
this.nodes = [];
|
|
34
|
+
}
|
|
35
|
+
run(root = process.cwd()) {
|
|
36
|
+
for (const file of this.fileScanner(root)) {
|
|
37
|
+
const code = fs.readFileSync(file, "utf8");
|
|
38
|
+
const walkers = this.astWalkers;
|
|
39
|
+
parseAndWalk(code, file, { enter: function(node, parent, ctx) {
|
|
40
|
+
for (const walker of walkers) try {
|
|
41
|
+
walker.call(this, node, parent, ctx, file);
|
|
42
|
+
} catch (error) {
|
|
43
|
+
console.error(`Error occurred while walking node in file ${file}:`, error);
|
|
44
|
+
}
|
|
45
|
+
} });
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
const engine = new Engine();
|
|
50
|
+
import("./defaults/index.mjs");
|
|
51
|
+
//#endregion
|
|
52
|
+
export { Engine, engine };
|
package/dist/index.mjs
ADDED
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 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ddd-ts/event-tree",
|
|
3
|
+
"version": "0.0.0-eventviz.10",
|
|
4
|
+
"types": "dist/server/index.d.ts",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"url": "git+https://github.com/ddd-ts/monorepo"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"dist"
|
|
11
|
+
],
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"oxc-parser": "^0.128.0",
|
|
14
|
+
"oxc-walker": "^1.0.0"
|
|
15
|
+
},
|
|
16
|
+
"devDependencies": {
|
|
17
|
+
"@ddd-ts/tools": "0.0.0-eventviz.10",
|
|
18
|
+
"@types/node": "^22.14.1"
|
|
19
|
+
},
|
|
20
|
+
"exports": {
|
|
21
|
+
".": "./dist/index.mjs",
|
|
22
|
+
"./package.json": "./package.json"
|
|
23
|
+
},
|
|
24
|
+
"publishConfig": {
|
|
25
|
+
"access": "public"
|
|
26
|
+
},
|
|
27
|
+
"scripts": {
|
|
28
|
+
"build": "tsdown --config node_modules/@ddd-ts/tools/tsdown.config.js -f esm src/server/index.ts"
|
|
29
|
+
}
|
|
30
|
+
}
|