@akanjs/cli 3.1.2-rc.4 → 3.2.0-rc.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.
- package/.build-stamp +1 -1
- package/{CodeAgent-z34p8m91.js → CodeAgent-vmd9k4ak.js} +3 -3
- package/{CodeTui-nvd9fk3g.js → CodeTui-zka44v52.js} +1 -1
- package/README.ko.md +9 -0
- package/README.md +9 -0
- package/TunnelShare-k3ja4w9x.js +14 -0
- package/{agent.command-962mp3kg.js → agent.command-2f657613.js} +19 -17
- package/akanCode.js +6 -6
- package/{application.command-1nr0bqq1.js → application.command-q6skd3am.js} +36 -22
- package/{applicationBuildRunner-xy7hnfzq.js → applicationBuildRunner-sctcmkyx.js} +55 -16
- package/buildBatch.proc.js +7 -7
- package/{cloud.command-cj7b3m6y.js → cloud.command-7642pks6.js} +36 -19
- package/cloud.script-1sfseznn.js +30 -0
- package/{code.command-asq7xrr6.js → code.command-7s4ndq2k.js} +6 -6
- package/commandManifest.json +1 -1
- package/{context.command-fw4g2pw1.js → context.command-569z0rqf.js} +20 -19
- package/context.runner-ms8v1rxy.js +29 -0
- package/{devTui-evr3b35y.js → devTui-w38ch13a.js} +1 -1
- package/{guideline.command-43gfjsjv.js → guideline.command-gnv3e8p8.js} +2 -2
- package/guidelines/akanApi/akanApi.instruction.md +317 -0
- package/guidelines/conventions/rules/app.md +5 -5
- package/guidelines/conventions/rules/config.md +1 -1
- package/guidelines/conventions/rules/gates.md +10 -5
- package/incrementalBuilder.proc.js +69 -39
- package/{index-0tkj05cz.js → index-0fb3cpbt.js} +3 -3
- package/{index-6t7fkx73.js → index-1q1cjn8s.js} +21 -11
- package/{index-tenw3mah.js → index-23860fej.js} +16 -6
- package/{index-6zgt7zmx.js → index-48d5qsj3.js} +4 -4
- package/{index-z47rw9ez.js → index-5w9my9qe.js} +8 -8
- package/{index-qwe079ww.js → index-6wpaq392.js} +61 -15
- package/{index-kc871vpc.js → index-7xdpww43.js} +69 -12
- package/index-7y5yghjg.js +2969 -0
- package/{index-38patcx6.js → index-8g7tdsk4.js} +249 -696
- package/{index-90q0w90q.js → index-8kczhnmv.js} +1 -1
- package/{index-kdswbvys.js → index-8pb9yvp8.js} +63 -21
- package/{index-hmj94es2.js → index-8ts9774g.js} +4 -4
- package/{index-r0q2ka2b.js → index-93ewzmp6.js} +43 -14
- package/{index-y0y0pnx8.js → index-9tbgb4d8.js} +1 -1
- package/{index-jzpeny42.js → index-a8a9ede9.js} +7 -7
- package/index-abgh0jve.js +126 -0
- package/{index-t0hk1kxq.js → index-aj3ehkcx.js} +1 -1
- package/{index-demt944k.js → index-d4n1wmrz.js} +37 -4
- package/{index-sra1a5f8.js → index-drz9e84d.js} +22 -8
- package/{index-gfh90r3t.js → index-e3vmjtph.js} +2 -2
- package/{index-k64mhwbw.js → index-eajbmk10.js} +2 -1
- package/{index-g0yds382.js → index-ed6ea0qp.js} +1 -1
- package/{index-ap6ac70m.js → index-fjr4d6yd.js} +444 -368
- package/index-hqrkqxx2.js +176 -0
- package/{index-ampz4vgv.js → index-kpdv34rq.js} +4 -4
- package/{index-kc6ffq0s.js → index-ktb3wcqz.js} +73 -34
- package/{index-dcm66hss.js → index-mmym5xmb.js} +4 -2
- package/{index-8d9r465x.js → index-mqntfzv5.js} +2 -2
- package/{index-4am4dvmf.js → index-ny2k80mv.js} +15 -3
- package/index-p6hjwt2d.js +1668 -0
- package/{index-53h0053j.js → index-rc5fvqj2.js} +12 -14
- package/{index-jzz6ye8x.js → index-s2grpzef.js} +40 -8
- package/{index-38by07nw.js → index-sr5da35e.js} +32 -9
- package/{index-qev8p5wp.js → index-sy481q2x.js} +1 -1
- package/{index-ck64kxrn.js → index-thckcabc.js} +2 -2
- package/{index-2yan1ajk.js → index-v4p1zye8.js} +18 -9
- package/{index-wymcdsas.js → index-vkzfk7qt.js} +25 -23
- package/{index-r8t5sq7z.js → index-vr68mxj5.js} +68 -21
- package/{index-vkpqe29t.js → index-w639tvkd.js} +24 -125
- package/index-ygdbn9jn.js +122 -0
- package/{index-w60zxxye.js → index-zpv14wpy.js} +3 -3
- package/index.js +24 -23
- package/{library.command-zh29tjdd.js → library.command-1gp5qe3r.js} +3 -3
- package/{localRegistry.command-k9pn9ahj.js → localRegistry.command-x7jptkd3.js} +26 -17
- package/{module.command-dgpqs9fz.js → module.command-4xz9he6h.js} +6 -6
- package/{package.command-1je4hsca.js → package.command-s7qpnn1g.js} +12 -3
- package/package.json +2 -2
- package/{page.command-cgsasanh.js → page.command-fan34c49.js} +3 -3
- package/{pipeline.command-tb46sa8v.js → pipeline.command-ph4fnn9w.js} +2 -2
- package/{primitive.command-bzsy23x5.js → primitive.command-3fqh8emf.js} +7 -7
- package/{projectTypecheck-h8rgaczy.js → projectTypecheck-vkb40hjc.js} +1 -1
- package/{quality.command-120m9h6v.js → quality.command-ecj6exsh.js} +15 -10
- package/{repair.command-6m4wd0qv.js → repair.command-fe9jw719.js} +6 -6
- package/{scalar.command-3dn5hsc6.js → scalar.command-cnvfhk0n.js} +5 -5
- package/skills/akan-debug/SKILL.md +2 -1
- package/skills/akan-page/SKILL.md +16 -7
- package/skills/akan-service/SKILL.md +48 -19
- package/{subspace.command-s8nyfqbn.js → subspace.command-qw5ddd6y.js} +8 -8
- package/templates/app/lib/___appName__/__appName__.abstract.md.template +6 -0
- package/templates/app/page/_index.tsx +4 -284
- package/templates/app/page/_layout.tsx +1 -26
- package/templates/app/page/styles.css.template +58 -318
- package/templates/appSample/page/_index.tsx +281 -0
- package/templates/appSample/page/_layout.tsx +55 -0
- package/templates/appSample/page/styles.css.template +327 -0
- package/templates/libRoot/lib/___libName__/__libName__.abstract.md.template +6 -0
- package/templates/workspaceRoot/package.json.template +1 -12
- package/{tunnel.command-8mwrqkr3.js → tunnel.command-ggj38mqf.js} +7 -7
- package/{verify.command-2pspfy7k.js → verify.command-w9ttxkdz.js} +16 -14
- package/{workflow.command-7sy5vnsj.js → workflow.command-ss8devj0.js} +12 -12
- package/{workspace.command-x518tdv4.js → workspace.command-6z2rh8ze.js} +51 -39
- package/TunnelShare-jwbb50kz.js +0 -14
- package/cloud.script-8kr7qgfa.js +0 -27
- package/context.runner-p6m5cxk3.js +0 -28
- package/index-d894868w.js +0 -842
- package/index-re2kfscb.js +0 -1363
- /package/templates/{app → appSample}/page/_overrides.tsx +0 -0
- /package/templates/{app → appSample}/public/fonts/Pretendard-Black.woff2 +0 -0
- /package/templates/{app → appSample}/public/fonts/Pretendard-Bold.woff2 +0 -0
- /package/templates/{app → appSample}/public/fonts/Pretendard-ExtraBold.woff2 +0 -0
- /package/templates/{app → appSample}/public/fonts/Pretendard-ExtraLight.woff2 +0 -0
- /package/templates/{app → appSample}/public/fonts/Pretendard-Light.woff2 +0 -0
- /package/templates/{app → appSample}/public/fonts/Pretendard-Medium.woff2 +0 -0
- /package/templates/{app → appSample}/public/fonts/Pretendard-Regular.woff2 +0 -0
- /package/templates/{app → appSample}/public/fonts/Pretendard-SemiBold.woff2 +0 -0
- /package/templates/{app → appSample}/public/fonts/Pretendard-Thin.woff2 +0 -0
- /package/templates/{app → appSample}/public/jelly/cloud.webp +0 -0
- /package/templates/{app → appSample}/public/jelly/comet.webp +0 -0
- /package/templates/{app → appSample}/public/jelly/moon.webp +0 -0
- /package/templates/{app → appSample}/public/jelly/planet.webp +0 -0
- /package/templates/{app → appSample}/public/jelly/rocket.webp +0 -0
- /package/templates/{app → appSample}/public/jelly/star.webp +0 -0
- /package/templates/{app → appSample}/public/jelly/sugar.webp +0 -0
- /package/templates/{app → appSample}/public/logo.png +0 -0
- /package/templates/{app → appSample}/ui/Recipe/index.ts +0 -0
- /package/templates/{app → appSample}/ui/Recipe/jellyButton.ts +0 -0
package/index-re2kfscb.js
DELETED
|
@@ -1,1363 +0,0 @@
|
|
|
1
|
-
// @bun
|
|
2
|
-
// pkgs/@akanjs/language/akanGraphDiff.ts
|
|
3
|
-
var edgeKeyOf = ({ from, to, kind, label }) => `${from}
|
|
4
|
-
${to}
|
|
5
|
-
${kind}
|
|
6
|
-
${label ?? ""}`;
|
|
7
|
-
var shapeOf = ({ type, array, optional, declaredIn }) => `${type ?? ""}${array ? "[]" : ""}${optional ? "?" : ""} ${declaredIn}`;
|
|
8
|
-
var isEdited = (before, after) => before.digest !== undefined && after.digest !== undefined && before.digest !== after.digest;
|
|
9
|
-
var byId = (a, b) => a.id < b.id ? -1 : a.id > b.id ? 1 : 0;
|
|
10
|
-
|
|
11
|
-
class AkanGraphDiff {
|
|
12
|
-
static between(base, head) {
|
|
13
|
-
const baseNodes = new Map(base.nodes.map((node) => [node.id, node]));
|
|
14
|
-
const headNodes = new Map(head.nodes.map((node) => [node.id, node]));
|
|
15
|
-
const marked = new Map;
|
|
16
|
-
for (const node of head.nodes) {
|
|
17
|
-
const before = baseNodes.get(node.id);
|
|
18
|
-
const next = before ? AkanGraphDiff.#compare(before, node) : AkanGraphDiff.#mark(node, "added");
|
|
19
|
-
if (next)
|
|
20
|
-
marked.set(node.id, next);
|
|
21
|
-
}
|
|
22
|
-
for (const node of base.nodes)
|
|
23
|
-
if (!headNodes.has(node.id))
|
|
24
|
-
marked.set(node.id, AkanGraphDiff.#mark(node, "removed"));
|
|
25
|
-
const baseKeys = new Set(base.edges.map(edgeKeyOf));
|
|
26
|
-
const headKeys = new Set(head.edges.map(edgeKeyOf));
|
|
27
|
-
const edges = [
|
|
28
|
-
...head.edges.flatMap((edge) => !baseKeys.has(edgeKeyOf(edge)) ? [{ ...edge, change: "added" }] : marked.has(edge.from) || marked.has(edge.to) ? [edge] : []),
|
|
29
|
-
...base.edges.filter((edge) => !headKeys.has(edgeKeyOf(edge))).map((edge) => ({ ...edge, change: "removed" }))
|
|
30
|
-
];
|
|
31
|
-
const context = edges.flatMap((edge) => [edge.from, edge.to]).filter((id) => !marked.has(id)).flatMap((id) => {
|
|
32
|
-
const node = headNodes.get(id) ?? baseNodes.get(id);
|
|
33
|
-
return node ? [node] : [];
|
|
34
|
-
});
|
|
35
|
-
const nodes = [...new Map([...marked.values(), ...context].map((node) => [node.id, node])).values()].map(AkanGraphDiff.#withoutDigest).sort(byId);
|
|
36
|
-
const summary = { added: 0, removed: 0, changed: 0 };
|
|
37
|
-
for (const node of marked.values())
|
|
38
|
-
if (node.change)
|
|
39
|
-
summary[node.change] += 1;
|
|
40
|
-
return { version: 1, nodes, edges, summary };
|
|
41
|
-
}
|
|
42
|
-
static #mark(node, change) {
|
|
43
|
-
return node.fields ? { ...node, change, fields: node.fields.map((field) => ({ ...field, change })) } : { ...node, change };
|
|
44
|
-
}
|
|
45
|
-
static #compare(before, after) {
|
|
46
|
-
const fields = AkanGraphDiff.#fieldsBetween(before.fields, after.fields);
|
|
47
|
-
const isChanged = isEdited(before, after) || before.label !== after.label || before.detail.join(`
|
|
48
|
-
`) !== after.detail.join(`
|
|
49
|
-
`) || (before.values ?? []).join(`
|
|
50
|
-
`) !== (after.values ?? []).join(`
|
|
51
|
-
`) || !!fields?.some((field) => field.change);
|
|
52
|
-
if (!isChanged)
|
|
53
|
-
return null;
|
|
54
|
-
return fields ? { ...after, change: "changed", fields } : { ...after, change: "changed" };
|
|
55
|
-
}
|
|
56
|
-
static #fieldsBetween(before, after) {
|
|
57
|
-
if (!before && !after)
|
|
58
|
-
return;
|
|
59
|
-
const previous = new Map((before ?? []).map((field) => [field.name, field]));
|
|
60
|
-
const names = new Set((after ?? []).map((field) => field.name));
|
|
61
|
-
return [
|
|
62
|
-
...(after ?? []).map((field) => {
|
|
63
|
-
const old = previous.get(field.name);
|
|
64
|
-
if (!old)
|
|
65
|
-
return { ...field, change: "added" };
|
|
66
|
-
return shapeOf(old) === shapeOf(field) && !isEdited(old, field) ? field : { ...field, change: "changed" };
|
|
67
|
-
}),
|
|
68
|
-
...(before ?? []).filter((field) => !names.has(field.name)).map((field) => ({ ...field, change: "removed" }))
|
|
69
|
-
];
|
|
70
|
-
}
|
|
71
|
-
static #withoutDigest({ digest: _digest, ...node }) {
|
|
72
|
-
return node.fields ? { ...node, fields: node.fields.map(({ digest: _field, ...field }) => field) } : node;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
// pkgs/@akanjs/language/akanGraph.ts
|
|
76
|
-
var capitalize = (text) => text.charAt(0).toUpperCase() + text.slice(1);
|
|
77
|
-
var lowerFirst = (text) => text.charAt(0).toLowerCase() + text.slice(1);
|
|
78
|
-
var memberSourcePattern = /\.(signal|service|store)\.ts$/;
|
|
79
|
-
var skippedPattern = /(?:\.(?:constant|document|dictionary|test|spec)\.tsx?|\/lib\/(?:cnst|db|dict|sig|srv|st|useClient|useServer)\.ts|\/index\.tsx?|^(?:apps|libs)\/[^/]+\/(?:client|server)\.ts)$/;
|
|
80
|
-
var scalarPattern = /\/lib\/__scalar\/([^/]+)\/[^/]+\.constant\.ts$/;
|
|
81
|
-
var moduleDirPattern = /\/lib\/([^/]+)\//;
|
|
82
|
-
var typeKinds = new Set(["model", "scalar", "enum"]);
|
|
83
|
-
var clientRoots = new Set(["fetch", "st", "sig"]);
|
|
84
|
-
|
|
85
|
-
class GraphBuilder {
|
|
86
|
-
#source;
|
|
87
|
-
#nodes = new Map;
|
|
88
|
-
#edges = new Map;
|
|
89
|
-
#contexts = new Map;
|
|
90
|
-
#members = new Map;
|
|
91
|
-
constructor(source) {
|
|
92
|
-
this.#source = source;
|
|
93
|
-
}
|
|
94
|
-
build() {
|
|
95
|
-
const { facts } = this.#source;
|
|
96
|
-
const constantsByOwner = new Map;
|
|
97
|
-
for (const file of facts)
|
|
98
|
-
constantsByOwner.set(file.owner, [...constantsByOwner.get(file.owner) ?? [], ...file.constants]);
|
|
99
|
-
const scopeOf = (owner) => [
|
|
100
|
-
...constantsByOwner.get(owner) ?? [],
|
|
101
|
-
...[...constantsByOwner].filter(([key]) => key !== owner && key?.startsWith("libs/")).flatMap(([, list]) => list)
|
|
102
|
-
];
|
|
103
|
-
const typed = [];
|
|
104
|
-
for (const file of facts) {
|
|
105
|
-
const { owner } = file;
|
|
106
|
-
const scalar = this.#source.relative(file.fileName).match(scalarPattern)?.[1];
|
|
107
|
-
const scalarClass = scalar ? file.constants.find((constant) => constant.name === capitalize(scalar)) : undefined;
|
|
108
|
-
if (scalar && scalarClass) {
|
|
109
|
-
const id = this.#key("scalar", owner, scalar);
|
|
110
|
-
const node = this.#addNode(id, "scalar", owner, scalar, scalarClass.name, scalarClass.span);
|
|
111
|
-
node.fields = this.#fieldsOf(scalarClass, scopeOf(owner));
|
|
112
|
-
typed.push(node);
|
|
113
|
-
}
|
|
114
|
-
for (const item of file.enums) {
|
|
115
|
-
const id = this.#key("enum", owner, item.name);
|
|
116
|
-
this.#addNode(id, "enum", owner, this.#moduleDirOf(file.fileName), item.name, item.span).values = item.values;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
for (const file of facts) {
|
|
120
|
-
const { owner } = file;
|
|
121
|
-
for (const service of file.services) {
|
|
122
|
-
const refName = service.model;
|
|
123
|
-
if (!refName)
|
|
124
|
-
continue;
|
|
125
|
-
const modelId = this.#key("model", owner, refName);
|
|
126
|
-
const modelClass = constantsByOwner.get(owner)?.find((constant) => constant.name === capitalize(refName));
|
|
127
|
-
if (modelClass && !this.#nodes.has(modelId)) {
|
|
128
|
-
const node = this.#addNode(modelId, "model", owner, refName, modelClass.name, modelClass.span);
|
|
129
|
-
node.fields = this.#fieldsOf(modelClass, scopeOf(owner));
|
|
130
|
-
typed.push(node);
|
|
131
|
-
}
|
|
132
|
-
for (const method of service.methods)
|
|
133
|
-
this.#addMember("method", owner, refName, method, `${service.name}.${method.name}`, file.fileName);
|
|
134
|
-
}
|
|
135
|
-
for (const filter of file.filters) {
|
|
136
|
-
if (!filter.name.endsWith("Filter"))
|
|
137
|
-
continue;
|
|
138
|
-
const refName = lowerFirst(filter.name.slice(0, -"Filter".length));
|
|
139
|
-
this.#addNode(this.#key("query", owner, refName), "query", owner, refName, "", filter.span);
|
|
140
|
-
for (const query of filter.queries)
|
|
141
|
-
this.#digest(this.#addNode(this.#key("query", owner, refName, query.name), "query", owner, refName, query.name, query.span), this.#source.readText(file.fileName), query.extent);
|
|
142
|
-
}
|
|
143
|
-
for (const slice of file.slices) {
|
|
144
|
-
const refName = slice.model;
|
|
145
|
-
if (!refName)
|
|
146
|
-
continue;
|
|
147
|
-
const fallback = this.#addNode(this.#key("slice", owner, refName), "slice", owner, refName, "", slice.span, slice.guards);
|
|
148
|
-
for (const guard of slice.guards)
|
|
149
|
-
this.#guard(fallback, guard);
|
|
150
|
-
for (const key of slice.keys) {
|
|
151
|
-
const detail = [...key.guards, ...key.live ? ["live"] : []];
|
|
152
|
-
const node = this.#addMember("slice", owner, refName, key, `${refName}.${key.name}`, file.fileName, detail);
|
|
153
|
-
for (const guard of key.guards)
|
|
154
|
-
this.#guard(node, guard);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
for (const endpoint of file.endpoints) {
|
|
158
|
-
const refName = endpoint.model;
|
|
159
|
-
if (!refName)
|
|
160
|
-
continue;
|
|
161
|
-
for (const key of endpoint.keys) {
|
|
162
|
-
const detail = [...key.verb ? [key.verb] : [], ...key.guards];
|
|
163
|
-
const node = this.#addMember("endpoint", owner, refName, key, `${refName}.${key.name}`, file.fileName, detail);
|
|
164
|
-
for (const guard of key.guards)
|
|
165
|
-
this.#guard(node, guard);
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
for (const store of file.stores)
|
|
169
|
-
if (store.model)
|
|
170
|
-
for (const action of store.actions)
|
|
171
|
-
this.#addMember("action", owner, store.model, action, `${store.name}.${action.name}`, file.fileName);
|
|
172
|
-
}
|
|
173
|
-
const types = new Map;
|
|
174
|
-
for (const node of this.#nodes.values())
|
|
175
|
-
if (typeKinds.has(node.kind))
|
|
176
|
-
types.set(node.label, [...types.get(node.label) ?? [], node]);
|
|
177
|
-
for (const node of typed)
|
|
178
|
-
for (const field of node.fields ?? []) {
|
|
179
|
-
const candidates = (field.type ? types.get(field.type) ?? [] : []).filter((type) => this.#visible(type.owner, node.owner));
|
|
180
|
-
field.ref = (candidates.find((type) => type.owner === node.owner) ?? candidates[0])?.id ?? null;
|
|
181
|
-
if (field.ref)
|
|
182
|
-
this.#addEdge(node.id, field.ref, "field", `${field.name}${field.array ? "[]" : ""}`, field.at);
|
|
183
|
-
}
|
|
184
|
-
for (const [fileName, words] of this.#source.files)
|
|
185
|
-
this.#walk(fileName, words);
|
|
186
|
-
return {
|
|
187
|
-
version: 1,
|
|
188
|
-
nodes: [...this.#nodes.values()].sort((a, b) => a.id < b.id ? -1 : a.id > b.id ? 1 : 0),
|
|
189
|
-
edges: [...this.#edges.values()]
|
|
190
|
-
};
|
|
191
|
-
}
|
|
192
|
-
#key(kind, owner, scope, name = "") {
|
|
193
|
-
return `${kind}:${owner ?? ""}:${scope}${name ? `.${name}` : ""}`;
|
|
194
|
-
}
|
|
195
|
-
#location(span) {
|
|
196
|
-
return { file: this.#source.relative(span.fileName), line: span.line + 1, column: span.character + 1 };
|
|
197
|
-
}
|
|
198
|
-
#addNode(id, kind, owner, module, name, span, detail = [], label = (kind === "query" || kind === "slice") && module ? `${module}${name ? `.${name}` : " (default)"}` : name) {
|
|
199
|
-
const existing = this.#nodes.get(id);
|
|
200
|
-
if (existing)
|
|
201
|
-
return existing;
|
|
202
|
-
const node = {
|
|
203
|
-
id,
|
|
204
|
-
kind,
|
|
205
|
-
name,
|
|
206
|
-
label,
|
|
207
|
-
owner,
|
|
208
|
-
module,
|
|
209
|
-
detail,
|
|
210
|
-
at: span ? this.#location(span) : null
|
|
211
|
-
};
|
|
212
|
-
this.#nodes.set(id, node);
|
|
213
|
-
return node;
|
|
214
|
-
}
|
|
215
|
-
#addMember(kind, owner, refName, member, label, fileName, detail = []) {
|
|
216
|
-
const id = this.#key(kind, owner, refName, member.name);
|
|
217
|
-
const node = this.#addNode(id, kind, owner, refName, member.name, member.span, detail, label);
|
|
218
|
-
this.#digest(node, this.#source.readText(fileName), member.extent);
|
|
219
|
-
this.#contexts.set(fileName, [
|
|
220
|
-
...this.#contexts.get(fileName) ?? [],
|
|
221
|
-
{ id, kind, owner, module: refName, extent: member.extent }
|
|
222
|
-
]);
|
|
223
|
-
const byName = `${kind}:${member.name}`;
|
|
224
|
-
this.#members.set(byName, [...this.#members.get(byName) ?? [], node]);
|
|
225
|
-
return node;
|
|
226
|
-
}
|
|
227
|
-
#hashOf(text, { start, end }) {
|
|
228
|
-
if (!this.#source.digests || text === undefined)
|
|
229
|
-
return null;
|
|
230
|
-
let hash = 2166136261;
|
|
231
|
-
for (let idx = start;idx < end; idx++) {
|
|
232
|
-
const code = text.charCodeAt(idx);
|
|
233
|
-
if (code !== 13)
|
|
234
|
-
hash = Math.imul(hash ^ code, 16777619);
|
|
235
|
-
}
|
|
236
|
-
return (hash >>> 0).toString(16).padStart(8, "0");
|
|
237
|
-
}
|
|
238
|
-
#digest(node, text, extent) {
|
|
239
|
-
const digest = node.digest ? null : this.#hashOf(text, extent);
|
|
240
|
-
if (digest)
|
|
241
|
-
node.digest = digest;
|
|
242
|
-
}
|
|
243
|
-
#addEdge(from, to, kind, label, at) {
|
|
244
|
-
if (from === to)
|
|
245
|
-
return;
|
|
246
|
-
const key = `${from}
|
|
247
|
-
${to}
|
|
248
|
-
${kind}
|
|
249
|
-
${label ?? ""}`;
|
|
250
|
-
const existing = this.#edges.get(key);
|
|
251
|
-
if (existing)
|
|
252
|
-
existing.count += 1;
|
|
253
|
-
else
|
|
254
|
-
this.#edges.set(key, { from, to, kind, label, count: 1, at });
|
|
255
|
-
}
|
|
256
|
-
#guard(node, guard) {
|
|
257
|
-
const [role, name] = guard.includes(" ") ? guard.split(" ") : [null, guard];
|
|
258
|
-
if (!name || name === "?")
|
|
259
|
-
return;
|
|
260
|
-
const id = `guard:${name}`;
|
|
261
|
-
if (!this.#nodes.has(id))
|
|
262
|
-
this.#nodes.set(id, { id, kind: "guard", name, label: name, owner: null, module: null, detail: [], at: null });
|
|
263
|
-
this.#addEdge(node.id, id, "guard", role, node.at);
|
|
264
|
-
}
|
|
265
|
-
#moduleDirOf(fileName) {
|
|
266
|
-
const dir = this.#source.relative(fileName).match(moduleDirPattern)?.[1] ?? null;
|
|
267
|
-
return dir?.startsWith("_") && !dir.startsWith("__") ? dir.slice(1) : dir;
|
|
268
|
-
}
|
|
269
|
-
#fieldsOf(constant, scope) {
|
|
270
|
-
const fields = new Map;
|
|
271
|
-
const seen = new Set;
|
|
272
|
-
const visit = (current) => {
|
|
273
|
-
if (seen.has(current))
|
|
274
|
-
return;
|
|
275
|
-
seen.add(current);
|
|
276
|
-
for (const parent of current.parents) {
|
|
277
|
-
const parentClass = scope.find((other) => other.name === parent && other.span.fileName === current.span.fileName) ?? scope.find((other) => other.name === parent);
|
|
278
|
-
if (parentClass)
|
|
279
|
-
visit(parentClass);
|
|
280
|
-
}
|
|
281
|
-
for (const field of current.fields) {
|
|
282
|
-
if (fields.has(field.name))
|
|
283
|
-
continue;
|
|
284
|
-
const digest = this.#hashOf(this.#source.readText(field.span.fileName), field.extent);
|
|
285
|
-
fields.set(field.name, {
|
|
286
|
-
name: field.name,
|
|
287
|
-
type: field.type,
|
|
288
|
-
array: field.array,
|
|
289
|
-
optional: field.optional,
|
|
290
|
-
ref: null,
|
|
291
|
-
declaredIn: current.name,
|
|
292
|
-
at: this.#location(field.span),
|
|
293
|
-
...digest ? { digest } : {}
|
|
294
|
-
});
|
|
295
|
-
}
|
|
296
|
-
};
|
|
297
|
-
visit(constant);
|
|
298
|
-
return [...fields.values()];
|
|
299
|
-
}
|
|
300
|
-
#visible(target, from) {
|
|
301
|
-
return !from || !target || target === from || target.startsWith("libs/");
|
|
302
|
-
}
|
|
303
|
-
#targetNodeOf({ family, owner, refName, sourceKey }) {
|
|
304
|
-
const isDefault = /^[A-Z]/.test(sourceKey);
|
|
305
|
-
const id = family === "slice" || family === "query" ? this.#key(family, owner, refName, isDefault ? "" : sourceKey) : family === "model" || family === "formSetter" ? this.#key("model", owner, refName) : family === "endpoint" ? this.#key("endpoint", owner, refName, sourceKey) : null;
|
|
306
|
-
return id && this.#nodes.has(id) ? id : null;
|
|
307
|
-
}
|
|
308
|
-
#membersNamed(kind, name, owner, refName) {
|
|
309
|
-
const nodes = (this.#members.get(`${kind}:${name}`) ?? []).filter((node) => (!refName || node.module === refName) && this.#visible(node.owner, owner));
|
|
310
|
-
const own = nodes.filter((node) => node.owner === owner);
|
|
311
|
-
return (own.length ? own : nodes).map((node) => node.id);
|
|
312
|
-
}
|
|
313
|
-
#plainTargetsOf(chain, name, context, owner) {
|
|
314
|
-
const [head, second] = chain ?? [];
|
|
315
|
-
if (chain?.length === 1 && head === "fetch")
|
|
316
|
-
return this.#membersNamed("endpoint", name, owner);
|
|
317
|
-
if (chain?.length === 2 && head === "st" && second === "do")
|
|
318
|
-
return this.#membersNamed("action", name, owner);
|
|
319
|
-
if (chain?.length === 1 && head === "this" && (context.kind === "method" || context.kind === "action"))
|
|
320
|
-
return this.#membersNamed(context.kind, name, context.owner, context.module).filter((id) => id.startsWith(`${context.kind}:${context.owner ?? ""}:`));
|
|
321
|
-
if (chain?.length === 2 && head === "this" && second && /.Service$/.test(second))
|
|
322
|
-
return this.#membersNamed("method", name, owner, second.slice(0, -"Service".length));
|
|
323
|
-
return [];
|
|
324
|
-
}
|
|
325
|
-
#walk(fileName, words) {
|
|
326
|
-
const relative = this.#source.relative(fileName);
|
|
327
|
-
const contexts = this.#contexts.get(fileName);
|
|
328
|
-
const isComponentFile = !memberSourcePattern.test(fileName) && !skippedPattern.test(relative) && (words.includes(`
|
|
329
|
-
fetch
|
|
330
|
-
`) || words.includes(`
|
|
331
|
-
st
|
|
332
|
-
`));
|
|
333
|
-
if (!contexts && !isComponentFile)
|
|
334
|
-
return;
|
|
335
|
-
const text = this.#source.readText(fileName);
|
|
336
|
-
if (text === undefined)
|
|
337
|
-
return;
|
|
338
|
-
const { ts } = this.#source;
|
|
339
|
-
const owner = this.#source.ownerOf(fileName);
|
|
340
|
-
const source = this.#source.parse(fileName, text);
|
|
341
|
-
const visit = (node) => {
|
|
342
|
-
if (ts.isPropertyAccessExpression(node) && ts.isIdentifier(node.name)) {
|
|
343
|
-
const start = node.name.getStart(source);
|
|
344
|
-
const chain = this.#chainOf(node.expression);
|
|
345
|
-
const context = contexts ? contexts.find(({ extent }) => extent.start <= start && start < extent.end) : chain && clientRoots.has(chain[0]) ? this.#componentOf(source, node) : undefined;
|
|
346
|
-
if (context)
|
|
347
|
-
this.#link(fileName, source, node.name, chain, context, owner);
|
|
348
|
-
}
|
|
349
|
-
ts.forEachChild(node, visit);
|
|
350
|
-
};
|
|
351
|
-
visit(source);
|
|
352
|
-
}
|
|
353
|
-
#link(fileName, source, identifier, chain, context, owner) {
|
|
354
|
-
const resolved = this.#source.resolve(fileName, identifier).map((target) => this.#targetNodeOf(target)).filter((id) => id !== null);
|
|
355
|
-
const targets = resolved.length ? resolved : this.#plainTargetsOf(chain, identifier.text, context, owner);
|
|
356
|
-
if (!targets.length)
|
|
357
|
-
return;
|
|
358
|
-
if (context.pending && !this.#nodes.has(context.id)) {
|
|
359
|
-
this.#nodes.set(context.id, context.pending);
|
|
360
|
-
this.#digest(context.pending, source.text, context.extent);
|
|
361
|
-
}
|
|
362
|
-
const own = targets.filter((id) => this.#nodes.get(id)?.owner === owner);
|
|
363
|
-
const kind = context.kind === "component" ? "uses" : chain?.[0] === "fetch" ? "fetches" : "calls";
|
|
364
|
-
const position = source.getLineAndCharacterOfPosition(identifier.getStart(source));
|
|
365
|
-
const at = { file: this.#source.relative(fileName), line: position.line + 1, column: position.character + 1 };
|
|
366
|
-
for (const target of new Set(own.length ? own : targets))
|
|
367
|
-
this.#addEdge(context.id, target, kind, identifier.text, at);
|
|
368
|
-
}
|
|
369
|
-
#chainOf(expression) {
|
|
370
|
-
const { ts } = this.#source;
|
|
371
|
-
if (ts.isNonNullExpression(expression) || ts.isParenthesizedExpression(expression))
|
|
372
|
-
return this.#chainOf(expression.expression);
|
|
373
|
-
if (ts.isIdentifier(expression))
|
|
374
|
-
return [expression.text];
|
|
375
|
-
if (expression.kind === ts.SyntaxKind.ThisKeyword)
|
|
376
|
-
return ["this"];
|
|
377
|
-
if (!ts.isPropertyAccessExpression(expression))
|
|
378
|
-
return null;
|
|
379
|
-
const head = this.#chainOf(expression.expression);
|
|
380
|
-
return head ? [...head, expression.name.text] : null;
|
|
381
|
-
}
|
|
382
|
-
#componentOf(source, node) {
|
|
383
|
-
const { ts } = this.#source;
|
|
384
|
-
let top = node;
|
|
385
|
-
while (top.parent && !ts.isSourceFile(top.parent))
|
|
386
|
-
top = top.parent;
|
|
387
|
-
const declared = ts.isVariableStatement(top) ? top.declarationList.declarations[0]?.name : ts.isFunctionDeclaration(top) || ts.isClassDeclaration(top) ? top.name : undefined;
|
|
388
|
-
const isDefaultExport = ts.canHaveModifiers(top) && !!ts.getModifiers(top)?.some(({ kind }) => kind === ts.SyntaxKind.DefaultKeyword);
|
|
389
|
-
const name = declared && ts.isIdentifier(declared) && !isDefaultExport ? declared.text : "default";
|
|
390
|
-
const relative = this.#source.relative(source.fileName);
|
|
391
|
-
const owner = this.#source.ownerOf(source.fileName);
|
|
392
|
-
const id = `component:${relative}#${name}`;
|
|
393
|
-
const context = {
|
|
394
|
-
id,
|
|
395
|
-
kind: "component",
|
|
396
|
-
owner,
|
|
397
|
-
module: null,
|
|
398
|
-
extent: { start: top.getStart(source), end: top.getEnd() }
|
|
399
|
-
};
|
|
400
|
-
if (this.#nodes.has(id))
|
|
401
|
-
return context;
|
|
402
|
-
const pagePrefix = owner ? `${owner}/page/` : null;
|
|
403
|
-
const route = pagePrefix && relative.startsWith(pagePrefix) ? relative.slice(pagePrefix.length).replace(/\.tsx?$/, "") : null;
|
|
404
|
-
const base = relative.slice(relative.lastIndexOf("/") + 1).replace(/\.tsx?$/, "");
|
|
405
|
-
const label = route ? `${route}${name === "default" ? "" : `#${name}`}` : name === "default" ? base : `${base}.${name}`;
|
|
406
|
-
const position = source.getLineAndCharacterOfPosition((declared ?? top).getStart(source));
|
|
407
|
-
context.pending = {
|
|
408
|
-
id,
|
|
409
|
-
kind: "component",
|
|
410
|
-
name,
|
|
411
|
-
label,
|
|
412
|
-
owner,
|
|
413
|
-
module: this.#moduleDirOf(source.fileName),
|
|
414
|
-
detail: route ? ["page"] : [],
|
|
415
|
-
at: { file: relative, line: position.line + 1, column: position.character + 1 }
|
|
416
|
-
};
|
|
417
|
-
return context;
|
|
418
|
-
}
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
// pkgs/@akanjs/language/ast.ts
|
|
422
|
-
var createAst = (ts) => {
|
|
423
|
-
const sourceFileFor = (fileName, content, scriptKind = ts.ScriptKind.TS) => ts.createSourceFile(fileName, content, ts.ScriptTarget.Latest, true, scriptKind);
|
|
424
|
-
const nodeName = (node) => {
|
|
425
|
-
if (!node)
|
|
426
|
-
return null;
|
|
427
|
-
if (ts.isIdentifier(node) || ts.isStringLiteral(node) || ts.isNumericLiteral(node))
|
|
428
|
-
return node.text;
|
|
429
|
-
return null;
|
|
430
|
-
};
|
|
431
|
-
const propertyName = (node) => ts.isPropertyAssignment(node) || ts.isShorthandPropertyAssignment(node) || ts.isMethodDeclaration(node) ? nodeName(node.name) : null;
|
|
432
|
-
const expressionName = (expression) => {
|
|
433
|
-
if (ts.isIdentifier(expression))
|
|
434
|
-
return expression.text;
|
|
435
|
-
if (ts.isPropertyAccessExpression(expression))
|
|
436
|
-
return expression.name.text;
|
|
437
|
-
if (ts.isCallExpression(expression))
|
|
438
|
-
return expressionName(expression.expression);
|
|
439
|
-
if (ts.isAsExpression(expression))
|
|
440
|
-
return expressionName(expression.expression);
|
|
441
|
-
return null;
|
|
442
|
-
};
|
|
443
|
-
const callExpressionName = (node) => ts.isPropertyAccessExpression(node.expression) ? node.expression.name.text : expressionName(node.expression);
|
|
444
|
-
const firstObjectReturnedByArrow = (node) => {
|
|
445
|
-
if (!ts.isArrowFunction(node) && !ts.isFunctionExpression(node))
|
|
446
|
-
return null;
|
|
447
|
-
if (ts.isObjectLiteralExpression(node.body))
|
|
448
|
-
return node.body;
|
|
449
|
-
if (ts.isParenthesizedExpression(node.body) && ts.isObjectLiteralExpression(node.body.expression)) {
|
|
450
|
-
return node.body.expression;
|
|
451
|
-
}
|
|
452
|
-
if (!ts.isBlock(node.body))
|
|
453
|
-
return null;
|
|
454
|
-
for (const statement of node.body.statements) {
|
|
455
|
-
if (ts.isReturnStatement(statement) && statement.expression && ts.isObjectLiteralExpression(statement.expression)) {
|
|
456
|
-
return statement.expression;
|
|
457
|
-
}
|
|
458
|
-
}
|
|
459
|
-
return null;
|
|
460
|
-
};
|
|
461
|
-
const heritageCallNamed = (node, names) => {
|
|
462
|
-
const heritage = node.heritageClauses?.flatMap((clause) => [...clause.types]) ?? [];
|
|
463
|
-
for (const { expression } of heritage) {
|
|
464
|
-
if (!ts.isCallExpression(expression))
|
|
465
|
-
continue;
|
|
466
|
-
const callee = expressionName(expression.expression);
|
|
467
|
-
if (callee && names.has(callee))
|
|
468
|
-
return { callee, call: expression };
|
|
469
|
-
}
|
|
470
|
-
return null;
|
|
471
|
-
};
|
|
472
|
-
const viaNames = new Set(["via"]);
|
|
473
|
-
const heritageCall = (node) => heritageCallNamed(node, viaNames)?.call ?? null;
|
|
474
|
-
return {
|
|
475
|
-
sourceFileFor,
|
|
476
|
-
nodeName,
|
|
477
|
-
propertyName,
|
|
478
|
-
expressionName,
|
|
479
|
-
callExpressionName,
|
|
480
|
-
firstObjectReturnedByArrow,
|
|
481
|
-
heritageCallNamed,
|
|
482
|
-
heritageCall
|
|
483
|
-
};
|
|
484
|
-
};
|
|
485
|
-
|
|
486
|
-
// pkgs/@akanjs/language/moduleFacts.ts
|
|
487
|
-
var moduleCallees = new Set(["via", "from", "into", "serve", "slice", "endpoint", "store", "enumOf"]);
|
|
488
|
-
var argMethods = new Set(["param", "body", "search", "room", "msg"]);
|
|
489
|
-
var ownerOf = (relativePath) => {
|
|
490
|
-
const [root, name] = relativePath.split("/");
|
|
491
|
-
return (root === "apps" || root === "libs") && name ? `${root}/${name}` : null;
|
|
492
|
-
};
|
|
493
|
-
var createFactReader = (ts, ast) => {
|
|
494
|
-
const spanOf = (source, node) => {
|
|
495
|
-
const start = node.getStart(source);
|
|
496
|
-
const end = node.getEnd();
|
|
497
|
-
const head = source.getLineAndCharacterOfPosition(start);
|
|
498
|
-
const tail = source.getLineAndCharacterOfPosition(end);
|
|
499
|
-
return {
|
|
500
|
-
fileName: source.fileName,
|
|
501
|
-
start,
|
|
502
|
-
end,
|
|
503
|
-
line: head.line,
|
|
504
|
-
character: head.character,
|
|
505
|
-
endLine: tail.line,
|
|
506
|
-
endCharacter: tail.character
|
|
507
|
-
};
|
|
508
|
-
};
|
|
509
|
-
const extentOf = (source, node) => ({
|
|
510
|
-
start: node.getStart(source),
|
|
511
|
-
end: node.getEnd()
|
|
512
|
-
});
|
|
513
|
-
const unwrap = (expression) => {
|
|
514
|
-
let current = expression;
|
|
515
|
-
while (ts.isParenthesizedExpression(current) || ts.isAsExpression(current) || ts.isSatisfiesExpression(current))
|
|
516
|
-
current = current.expression;
|
|
517
|
-
return current;
|
|
518
|
-
};
|
|
519
|
-
const moduleRefOf = (expression, holder) => {
|
|
520
|
-
let current = expression && unwrap(expression);
|
|
521
|
-
while (current && ts.isCallExpression(current) && ts.isPropertyAccessExpression(current.expression))
|
|
522
|
-
current = current.expression.expression;
|
|
523
|
-
if (current && ts.isStringLiteral(current))
|
|
524
|
-
return current.text;
|
|
525
|
-
if (!current || !ts.isPropertyAccessExpression(current))
|
|
526
|
-
return null;
|
|
527
|
-
return ts.isIdentifier(current.expression) && current.expression.text === holder ? current.name.text : null;
|
|
528
|
-
};
|
|
529
|
-
const returnedObject = (builder) => builder ? ast.firstObjectReturnedByArrow(builder) : null;
|
|
530
|
-
const builderOf = (call) => [...call.arguments].reverse().find((arg) => ts.isArrowFunction(arg) || ts.isFunctionExpression(arg));
|
|
531
|
-
const guardsIn = (object) => {
|
|
532
|
-
const guards = object?.properties.find((property) => ts.isPropertyAssignment(property) && ast.nodeName(property.name) === "guards")?.initializer;
|
|
533
|
-
if (!guards)
|
|
534
|
-
return [];
|
|
535
|
-
if (ts.isArrayLiteralExpression(guards))
|
|
536
|
-
return guards.elements.map((element) => ast.expressionName(element)).filter((name) => name !== null);
|
|
537
|
-
if (ts.isObjectLiteralExpression(guards))
|
|
538
|
-
return guards.properties.filter(ts.isPropertyAssignment).map((property) => `${ast.nodeName(property.name)} ${ast.expressionName(property.initializer) ?? "?"}`);
|
|
539
|
-
const single = ast.expressionName(guards);
|
|
540
|
-
return single ? [single] : [];
|
|
541
|
-
};
|
|
542
|
-
const optionObjectOf = (call) => call.arguments.find((arg) => ts.isObjectLiteralExpression(arg) && arg.properties.some((property) => ast.propertyName(property) === "guards"));
|
|
543
|
-
const chainOf = (initializer) => {
|
|
544
|
-
let root = unwrap(initializer);
|
|
545
|
-
const methods = [];
|
|
546
|
-
while (ts.isCallExpression(root) && ts.isPropertyAccessExpression(root.expression) && ts.isCallExpression(unwrap(root.expression.expression))) {
|
|
547
|
-
methods.push(root.expression.name.text);
|
|
548
|
-
root = unwrap(root.expression.expression);
|
|
549
|
-
}
|
|
550
|
-
return { root: ts.isCallExpression(root) ? root : null, methods };
|
|
551
|
-
};
|
|
552
|
-
const keyName = (property) => ts.isPropertyAssignment(property) || ts.isMethodDeclaration(property) || ts.isShorthandPropertyAssignment(property) ? property.name : null;
|
|
553
|
-
const objectKeys = (source, object) => (object?.properties ?? []).flatMap((property) => {
|
|
554
|
-
const name = ast.propertyName(property);
|
|
555
|
-
const node = keyName(property);
|
|
556
|
-
return name && node ? [{ name, span: spanOf(source, node), extent: extentOf(source, property) }] : [];
|
|
557
|
-
});
|
|
558
|
-
const sliceKeysOf = (source, builder) => (returnedObject(builder)?.properties ?? []).flatMap((property) => {
|
|
559
|
-
if (!ts.isPropertyAssignment(property))
|
|
560
|
-
return [];
|
|
561
|
-
const name = ast.nodeName(property.name);
|
|
562
|
-
if (!name)
|
|
563
|
-
return [];
|
|
564
|
-
const { root, methods } = chainOf(property.initializer);
|
|
565
|
-
return [
|
|
566
|
-
{
|
|
567
|
-
name,
|
|
568
|
-
span: spanOf(source, property.name),
|
|
569
|
-
extent: extentOf(source, property),
|
|
570
|
-
guards: root ? guardsIn(optionObjectOf(root)) : [],
|
|
571
|
-
live: methods.includes("live"),
|
|
572
|
-
argCount: methods.filter((method) => argMethods.has(method)).length
|
|
573
|
-
}
|
|
574
|
-
];
|
|
575
|
-
});
|
|
576
|
-
const verbReaderOf = (parameter) => {
|
|
577
|
-
const verbs = new Map;
|
|
578
|
-
if (parameter && ts.isObjectBindingPattern(parameter.name))
|
|
579
|
-
for (const element of parameter.name.elements) {
|
|
580
|
-
const verb = element.propertyName ?? element.name;
|
|
581
|
-
if (ts.isIdentifier(verb) && ts.isIdentifier(element.name))
|
|
582
|
-
verbs.set(element.name.text, verb.text);
|
|
583
|
-
}
|
|
584
|
-
const holder = parameter && ts.isIdentifier(parameter.name) ? parameter.name.text : null;
|
|
585
|
-
return (callee) => {
|
|
586
|
-
if (callee && ts.isIdentifier(callee))
|
|
587
|
-
return verbs.get(callee.text) ?? null;
|
|
588
|
-
if (callee && ts.isPropertyAccessExpression(callee) && ts.isIdentifier(callee.expression) && callee.expression.text === holder)
|
|
589
|
-
return callee.name.text;
|
|
590
|
-
return null;
|
|
591
|
-
};
|
|
592
|
-
};
|
|
593
|
-
const endpointKeysOf = (source, builder) => {
|
|
594
|
-
const verbOf = verbReaderOf(builder?.parameters[0]);
|
|
595
|
-
return (returnedObject(builder)?.properties ?? []).flatMap((property) => {
|
|
596
|
-
if (!ts.isPropertyAssignment(property))
|
|
597
|
-
return [];
|
|
598
|
-
const name = ast.nodeName(property.name);
|
|
599
|
-
if (!name)
|
|
600
|
-
return [];
|
|
601
|
-
const { root, methods } = chainOf(property.initializer);
|
|
602
|
-
return [
|
|
603
|
-
{
|
|
604
|
-
name,
|
|
605
|
-
span: spanOf(source, property.name),
|
|
606
|
-
extent: extentOf(source, property),
|
|
607
|
-
verb: root ? verbOf(root.expression) : null,
|
|
608
|
-
guards: root ? guardsIn(optionObjectOf(root)) : [],
|
|
609
|
-
argCount: methods.filter((method) => argMethods.has(method)).length
|
|
610
|
-
}
|
|
611
|
-
];
|
|
612
|
-
});
|
|
613
|
-
};
|
|
614
|
-
const filterQueriesOf = (source, builder) => {
|
|
615
|
-
const query = returnedObject(builder)?.properties.find((property) => ts.isPropertyAssignment(property) && ast.nodeName(property.name) === "query")?.initializer;
|
|
616
|
-
return query && ts.isObjectLiteralExpression(query) ? objectKeys(source, query) : [];
|
|
617
|
-
};
|
|
618
|
-
const typeOf = (expression) => {
|
|
619
|
-
const value = expression && unwrap(expression);
|
|
620
|
-
if (value && ts.isArrayLiteralExpression(value))
|
|
621
|
-
return { type: typeOf(value.elements[0]).type, array: true };
|
|
622
|
-
return { type: value ? ast.expressionName(value) : null, array: false };
|
|
623
|
-
};
|
|
624
|
-
const fieldsOf = (source, object) => (object?.properties ?? []).flatMap((property) => {
|
|
625
|
-
const name = ast.propertyName(property);
|
|
626
|
-
const node = keyName(property);
|
|
627
|
-
if (!name || !node)
|
|
628
|
-
return [];
|
|
629
|
-
const { root, methods } = ts.isPropertyAssignment(property) ? chainOf(property.initializer) : { root: null, methods: [] };
|
|
630
|
-
return [
|
|
631
|
-
{
|
|
632
|
-
name,
|
|
633
|
-
span: spanOf(source, node),
|
|
634
|
-
extent: extentOf(source, property),
|
|
635
|
-
...typeOf(root?.arguments[0]),
|
|
636
|
-
optional: methods.includes("optional")
|
|
637
|
-
}
|
|
638
|
-
];
|
|
639
|
-
});
|
|
640
|
-
const constantOf = (source, name, call) => {
|
|
641
|
-
const parents = call.arguments.map(unwrap).filter((arg) => ts.isIdentifier(arg) || ts.isPropertyAccessExpression(arg)).map((arg) => ast.expressionName(arg)).filter((parent) => parent !== null);
|
|
642
|
-
const fields = call.arguments.flatMap((arg) => fieldsOf(source, ast.firstObjectReturnedByArrow(arg)));
|
|
643
|
-
return { ...name, parents, fields };
|
|
644
|
-
};
|
|
645
|
-
const enumValuesOf = (call) => {
|
|
646
|
-
const list = call.arguments[1] && unwrap(call.arguments[1]);
|
|
647
|
-
if (!list || !ts.isArrayLiteralExpression(list))
|
|
648
|
-
return [];
|
|
649
|
-
return list.elements.flatMap((element) => ts.isStringLiteralLike(element) ? [element.text] : []);
|
|
650
|
-
};
|
|
651
|
-
const methodsOf = (source, statement) => statement.members.flatMap((member) => {
|
|
652
|
-
if (!ts.isMethodDeclaration(member) || !member.body)
|
|
653
|
-
return [];
|
|
654
|
-
const name = ast.nodeName(member.name);
|
|
655
|
-
if (!name || ts.getModifiers(member)?.some(({ kind }) => kind === ts.SyntaxKind.StaticKeyword))
|
|
656
|
-
return [];
|
|
657
|
-
return [{ name, span: spanOf(source, member.name), extent: extentOf(source, member) }];
|
|
658
|
-
});
|
|
659
|
-
const lowerFirst = (text) => text.charAt(0).toLowerCase() + text.slice(1);
|
|
660
|
-
const read = (source, owner) => {
|
|
661
|
-
const facts = {
|
|
662
|
-
fileName: source.fileName,
|
|
663
|
-
owner,
|
|
664
|
-
constants: [],
|
|
665
|
-
enums: [],
|
|
666
|
-
filters: [],
|
|
667
|
-
models: [],
|
|
668
|
-
services: [],
|
|
669
|
-
slices: [],
|
|
670
|
-
endpoints: [],
|
|
671
|
-
stores: []
|
|
672
|
-
};
|
|
673
|
-
for (const statement of source.statements) {
|
|
674
|
-
if (!ts.isClassDeclaration(statement) || !statement.name)
|
|
675
|
-
continue;
|
|
676
|
-
const heritage = ast.heritageCallNamed(statement, moduleCallees);
|
|
677
|
-
if (!heritage)
|
|
678
|
-
continue;
|
|
679
|
-
const { callee, call } = heritage;
|
|
680
|
-
const name = { name: statement.name.text, span: spanOf(source, statement.name) };
|
|
681
|
-
const builder = builderOf(call);
|
|
682
|
-
if (callee === "via")
|
|
683
|
-
facts.constants.push(constantOf(source, name, call));
|
|
684
|
-
else if (callee === "enumOf")
|
|
685
|
-
facts.enums.push({ ...name, values: enumValuesOf(call) });
|
|
686
|
-
else if (callee === "from")
|
|
687
|
-
facts.filters.push({ ...name, queries: filterQueriesOf(source, builder) });
|
|
688
|
-
else if (callee === "into")
|
|
689
|
-
facts.models.push({ ...name, model: name.name.endsWith("Model") ? lowerFirst(name.name.slice(0, -5)) : null });
|
|
690
|
-
else if (callee === "serve")
|
|
691
|
-
facts.services.push({
|
|
692
|
-
...name,
|
|
693
|
-
model: moduleRefOf(call.arguments[0], "db"),
|
|
694
|
-
methods: methodsOf(source, statement)
|
|
695
|
-
});
|
|
696
|
-
else if (callee === "slice")
|
|
697
|
-
facts.slices.push({
|
|
698
|
-
...name,
|
|
699
|
-
model: moduleRefOf(call.arguments[0], "srv"),
|
|
700
|
-
guards: guardsIn(call.arguments.find(ts.isObjectLiteralExpression)),
|
|
701
|
-
keys: sliceKeysOf(source, builder)
|
|
702
|
-
});
|
|
703
|
-
else if (callee === "endpoint")
|
|
704
|
-
facts.endpoints.push({
|
|
705
|
-
...name,
|
|
706
|
-
model: moduleRefOf(call.arguments[0], "srv"),
|
|
707
|
-
keys: endpointKeysOf(source, builder)
|
|
708
|
-
});
|
|
709
|
-
else if (callee === "store")
|
|
710
|
-
facts.stores.push({
|
|
711
|
-
...name,
|
|
712
|
-
model: moduleRefOf(call.arguments[0], "sig"),
|
|
713
|
-
stateKeys: objectKeys(source, returnedObject(builder)),
|
|
714
|
-
actions: methodsOf(source, statement)
|
|
715
|
-
});
|
|
716
|
-
}
|
|
717
|
-
return facts;
|
|
718
|
-
};
|
|
719
|
-
return { read, spanOf, moduleRefOf, chainOf, unwrap };
|
|
720
|
-
};
|
|
721
|
-
|
|
722
|
-
// pkgs/@akanjs/language/nameTable.ts
|
|
723
|
-
import {
|
|
724
|
-
databaseStateNames,
|
|
725
|
-
endpointNames,
|
|
726
|
-
formSetterNames,
|
|
727
|
-
modelNames,
|
|
728
|
-
moduleNames,
|
|
729
|
-
queryNames,
|
|
730
|
-
sliceNames,
|
|
731
|
-
stateSetterName
|
|
732
|
-
} from "akanjs/common/akanNames.ts";
|
|
733
|
-
var capitalize2 = (text) => text.charAt(0).toUpperCase() + text.slice(1);
|
|
734
|
-
|
|
735
|
-
class NameTable {
|
|
736
|
-
#byName = new Map;
|
|
737
|
-
#byFile = new Map;
|
|
738
|
-
constructor(files) {
|
|
739
|
-
const all = [...files];
|
|
740
|
-
const constantsByOwner = new Map;
|
|
741
|
-
for (const facts of all) {
|
|
742
|
-
const constants = constantsByOwner.get(facts.owner) ?? [];
|
|
743
|
-
constants.push(...facts.constants);
|
|
744
|
-
constantsByOwner.set(facts.owner, constants);
|
|
745
|
-
}
|
|
746
|
-
const libConstants = [...constantsByOwner].filter(([owner]) => owner?.startsWith("libs/"));
|
|
747
|
-
const scope = (owner) => ({
|
|
748
|
-
own: constantsByOwner.get(owner) ?? [],
|
|
749
|
-
libs: libConstants.filter(([key]) => key !== owner).flatMap(([, constants]) => constants)
|
|
750
|
-
});
|
|
751
|
-
const scopes = new Map;
|
|
752
|
-
for (const group of NameTable.#groupsOf(all)) {
|
|
753
|
-
const constants = scopes.get(group.owner) ?? scope(group.owner);
|
|
754
|
-
scopes.set(group.owner, constants);
|
|
755
|
-
this.#addGroup(group, constants);
|
|
756
|
-
}
|
|
757
|
-
}
|
|
758
|
-
lookup(name) {
|
|
759
|
-
return this.#byName.get(name) ?? [];
|
|
760
|
-
}
|
|
761
|
-
entriesTargeting(fileName) {
|
|
762
|
-
return this.#byFile.get(fileName) ?? [];
|
|
763
|
-
}
|
|
764
|
-
static #groupsOf(files) {
|
|
765
|
-
const groups = new Map;
|
|
766
|
-
const groupOf = (owner, refName) => {
|
|
767
|
-
const key = `${owner ?? ""}:${refName}`;
|
|
768
|
-
const group = groups.get(key) ?? { owner, refName, constants: [], slices: [], facts: [] };
|
|
769
|
-
groups.set(key, group);
|
|
770
|
-
return group;
|
|
771
|
-
};
|
|
772
|
-
for (const facts of files) {
|
|
773
|
-
const refs = new Set;
|
|
774
|
-
for (const item of [...facts.services, ...facts.slices, ...facts.endpoints, ...facts.stores, ...facts.models])
|
|
775
|
-
if (item.model)
|
|
776
|
-
refs.add(item.model);
|
|
777
|
-
for (const filter of facts.filters)
|
|
778
|
-
if (filter.name.endsWith("Filter"))
|
|
779
|
-
refs.add(NameTable.#lowerFirst(filter.name.slice(0, -6)));
|
|
780
|
-
for (const constant of facts.constants)
|
|
781
|
-
refs.add(NameTable.#lowerFirst(constant.name));
|
|
782
|
-
for (const refName of refs)
|
|
783
|
-
groupOf(facts.owner, refName).facts.push(facts);
|
|
784
|
-
}
|
|
785
|
-
for (const group of groups.values()) {
|
|
786
|
-
group.constants = group.facts.flatMap((facts) => facts.constants);
|
|
787
|
-
group.slices = group.facts.flatMap((facts) => facts.slices.filter((slice) => slice.model === group.refName));
|
|
788
|
-
}
|
|
789
|
-
return [...groups.values()].filter((group) => group.facts.some((facts) => facts.services.some((item) => item.model === group.refName) || facts.slices.some((item) => item.model === group.refName) || facts.stores.some((item) => item.model === group.refName) || facts.models.some((item) => item.model === group.refName)));
|
|
790
|
-
}
|
|
791
|
-
static #lowerFirst(text) {
|
|
792
|
-
return text.charAt(0).toLowerCase() + text.slice(1);
|
|
793
|
-
}
|
|
794
|
-
#add(entry) {
|
|
795
|
-
if (entry.name === entry.sourceKey)
|
|
796
|
-
return;
|
|
797
|
-
const sameName = this.#byName.get(entry.name) ?? [];
|
|
798
|
-
if (sameName.some((other) => other.gate === entry.gate && other.span.fileName === entry.span.fileName && other.span.start === entry.span.start))
|
|
799
|
-
return;
|
|
800
|
-
sameName.push(entry);
|
|
801
|
-
this.#byName.set(entry.name, sameName);
|
|
802
|
-
const sameFile = this.#byFile.get(entry.span.fileName) ?? [];
|
|
803
|
-
sameFile.push(entry);
|
|
804
|
-
this.#byFile.set(entry.span.fileName, sameFile);
|
|
805
|
-
}
|
|
806
|
-
#addGroup(group, constants) {
|
|
807
|
-
const { owner, refName } = group;
|
|
808
|
-
const Model = capitalize2(refName);
|
|
809
|
-
const base = { owner, refName };
|
|
810
|
-
const modelClass = group.constants.find((constant) => constant.name === Model);
|
|
811
|
-
const facts = group.facts;
|
|
812
|
-
const names = moduleNames(refName);
|
|
813
|
-
const serviceClass = facts.flatMap((file) => file.services).find((item) => item.model === refName);
|
|
814
|
-
const sliceClass = group.slices[0];
|
|
815
|
-
const modelDoc = facts.flatMap((file) => file.models).find((item) => item.model === refName);
|
|
816
|
-
const filterClass = facts.flatMap((file) => file.filters).find((item) => item.name === names.FilterClass);
|
|
817
|
-
if (serviceClass) {
|
|
818
|
-
const target = { ...base, family: "module", sourceKey: serviceClass.name, span: serviceClass.span };
|
|
819
|
-
this.#add({ ...target, name: names.service, role: "service", gate: null, label: serviceClass.name, detail: [] });
|
|
820
|
-
this.#add({ ...target, name: refName, role: "srv", gate: "srv", label: serviceClass.name, detail: [] });
|
|
821
|
-
}
|
|
822
|
-
if (sliceClass)
|
|
823
|
-
this.#add({
|
|
824
|
-
...base,
|
|
825
|
-
family: "module",
|
|
826
|
-
sourceKey: sliceClass.name,
|
|
827
|
-
span: sliceClass.span,
|
|
828
|
-
name: refName,
|
|
829
|
-
role: "sig",
|
|
830
|
-
gate: "sig",
|
|
831
|
-
label: sliceClass.name,
|
|
832
|
-
detail: sliceClass.guards.length ? [`guards: ${sliceClass.guards.join(", ")}`] : []
|
|
833
|
-
});
|
|
834
|
-
if (modelDoc)
|
|
835
|
-
this.#add({
|
|
836
|
-
...base,
|
|
837
|
-
family: "module",
|
|
838
|
-
sourceKey: modelDoc.name,
|
|
839
|
-
span: modelDoc.span,
|
|
840
|
-
name: refName,
|
|
841
|
-
role: "db",
|
|
842
|
-
gate: "db",
|
|
843
|
-
label: modelDoc.name,
|
|
844
|
-
detail: []
|
|
845
|
-
});
|
|
846
|
-
const modelRoles = modelNames(refName);
|
|
847
|
-
const modelNameSet = new Set(Object.values(modelRoles));
|
|
848
|
-
if (modelClass) {
|
|
849
|
-
const target = { ...base, family: "model", sourceKey: modelClass.name, span: modelClass.span };
|
|
850
|
-
for (const [role, name] of Object.entries(modelRoles))
|
|
851
|
-
this.#add({
|
|
852
|
-
...target,
|
|
853
|
-
name,
|
|
854
|
-
role,
|
|
855
|
-
gate: role === "model" ? "state" : null,
|
|
856
|
-
label: `model ${Model}`,
|
|
857
|
-
detail: []
|
|
858
|
-
});
|
|
859
|
-
for (const [role, name] of Object.entries(databaseStateNames(refName)))
|
|
860
|
-
this.#add({
|
|
861
|
-
...target,
|
|
862
|
-
name: stateSetterName(name),
|
|
863
|
-
role: `set:${role}`,
|
|
864
|
-
gate: null,
|
|
865
|
-
label: `model ${Model}`,
|
|
866
|
-
detail: []
|
|
867
|
-
});
|
|
868
|
-
for (const field of NameTable.#fieldsOf(modelClass, constants)) {
|
|
869
|
-
const setters = formSetterNames(Model, field.name);
|
|
870
|
-
for (const role of [
|
|
871
|
-
"setFieldOnModel",
|
|
872
|
-
"addFieldOnModel",
|
|
873
|
-
"subFieldOnModel",
|
|
874
|
-
"addOrSubFieldOnModel",
|
|
875
|
-
"uploadFieldOnModel"
|
|
876
|
-
])
|
|
877
|
-
this.#add({
|
|
878
|
-
...base,
|
|
879
|
-
family: "formSetter",
|
|
880
|
-
sourceKey: field.name,
|
|
881
|
-
span: field.span,
|
|
882
|
-
name: setters[role],
|
|
883
|
-
role,
|
|
884
|
-
gate: null,
|
|
885
|
-
label: `field ${field.declaredIn}.${field.name}`,
|
|
886
|
-
detail: []
|
|
887
|
-
});
|
|
888
|
-
}
|
|
889
|
-
}
|
|
890
|
-
for (const slice of group.slices) {
|
|
891
|
-
const defaultTarget = {
|
|
892
|
-
...base,
|
|
893
|
-
family: "slice",
|
|
894
|
-
sourceKey: slice.name,
|
|
895
|
-
span: slice.span,
|
|
896
|
-
label: `slice ${refName} (default)`,
|
|
897
|
-
detail: slice.guards.length ? [`guards: ${slice.guards.join(", ")}`] : []
|
|
898
|
-
};
|
|
899
|
-
this.#addSliceNames(defaultTarget, refName, "", modelNameSet);
|
|
900
|
-
for (const key of slice.keys)
|
|
901
|
-
this.#addSliceNames({
|
|
902
|
-
...base,
|
|
903
|
-
family: "slice",
|
|
904
|
-
sourceKey: key.name,
|
|
905
|
-
span: key.span,
|
|
906
|
-
label: `slice ${key.name}`,
|
|
907
|
-
detail: [...key.guards.length ? [`guards: ${key.guards.join(", ")}`] : [], ...key.live ? ["live"] : []]
|
|
908
|
-
}, refName, key.name, modelNameSet, slice.name);
|
|
909
|
-
}
|
|
910
|
-
if (filterClass) {
|
|
911
|
-
const defaults = { ...base, family: "query", detail: [] };
|
|
912
|
-
for (const [role, name] of Object.entries(queryNames("any")))
|
|
913
|
-
this.#add({
|
|
914
|
-
...defaults,
|
|
915
|
-
sourceKey: filterClass.name,
|
|
916
|
-
span: filterClass.span,
|
|
917
|
-
name,
|
|
918
|
-
role,
|
|
919
|
-
gate: null,
|
|
920
|
-
label: `query any (default) of ${filterClass.name}`
|
|
921
|
-
});
|
|
922
|
-
for (const query of filterClass.queries)
|
|
923
|
-
for (const [role, name] of Object.entries(queryNames(query.name)))
|
|
924
|
-
this.#add({
|
|
925
|
-
...defaults,
|
|
926
|
-
sourceKey: query.name,
|
|
927
|
-
span: query.span,
|
|
928
|
-
name,
|
|
929
|
-
role,
|
|
930
|
-
gate: null,
|
|
931
|
-
label: `query ${query.name}`,
|
|
932
|
-
renamed: (key) => queryNames(key)[role],
|
|
933
|
-
dictionary: { section: "query", className: filterClass.name }
|
|
934
|
-
});
|
|
935
|
-
}
|
|
936
|
-
for (const store of facts.flatMap((file) => file.stores).filter((item) => item.model === refName))
|
|
937
|
-
for (const key of store.stateKeys)
|
|
938
|
-
this.#add({
|
|
939
|
-
...base,
|
|
940
|
-
family: "storeState",
|
|
941
|
-
sourceKey: key.name,
|
|
942
|
-
span: key.span,
|
|
943
|
-
name: stateSetterName(key.name),
|
|
944
|
-
role: "set",
|
|
945
|
-
gate: null,
|
|
946
|
-
label: `store state ${key.name}`,
|
|
947
|
-
detail: []
|
|
948
|
-
});
|
|
949
|
-
for (const endpoint of facts.flatMap((file) => file.endpoints).filter((item) => item.model === refName))
|
|
950
|
-
for (const key of endpoint.keys) {
|
|
951
|
-
const derived = endpointNames(key.name);
|
|
952
|
-
const name = key.verb === "pubsub" ? derived.subscribe : key.verb === "message" ? derived.listen : null;
|
|
953
|
-
if (!name)
|
|
954
|
-
continue;
|
|
955
|
-
this.#add({
|
|
956
|
-
...base,
|
|
957
|
-
family: "endpoint",
|
|
958
|
-
sourceKey: key.name,
|
|
959
|
-
span: key.span,
|
|
960
|
-
name,
|
|
961
|
-
role: key.verb === "pubsub" ? "subscribe" : "listen",
|
|
962
|
-
gate: null,
|
|
963
|
-
label: `${key.verb} ${key.name}`,
|
|
964
|
-
detail: key.guards.length ? [`guards: ${key.guards.join(", ")}`] : []
|
|
965
|
-
});
|
|
966
|
-
}
|
|
967
|
-
}
|
|
968
|
-
static #sliceRoles(refName, suffix) {
|
|
969
|
-
const names = sliceNames(refName, suffix);
|
|
970
|
-
return new Map([
|
|
971
|
-
["slice", names.slice],
|
|
972
|
-
...Object.entries(names.state),
|
|
973
|
-
...Object.entries(names.action),
|
|
974
|
-
...Object.entries(names.endpoint),
|
|
975
|
-
...Object.entries(names.state).map(([role, name]) => [`set:${role}`, stateSetterName(name)])
|
|
976
|
-
]);
|
|
977
|
-
}
|
|
978
|
-
#addSliceNames(target, refName, suffix, skip, className) {
|
|
979
|
-
for (const [role, name] of NameTable.#sliceRoles(refName, suffix)) {
|
|
980
|
-
if (!suffix && role !== "slice" && skip.has(name))
|
|
981
|
-
continue;
|
|
982
|
-
this.#add({
|
|
983
|
-
...target,
|
|
984
|
-
name,
|
|
985
|
-
role,
|
|
986
|
-
gate: role === "slice" ? "slice" : null,
|
|
987
|
-
...suffix && className ? {
|
|
988
|
-
renamed: (key) => NameTable.#sliceRoles(refName, key).get(role) ?? name,
|
|
989
|
-
dictionary: { section: "slice", className }
|
|
990
|
-
} : {}
|
|
991
|
-
});
|
|
992
|
-
}
|
|
993
|
-
}
|
|
994
|
-
static #fieldsOf(modelClass, { own, libs }) {
|
|
995
|
-
const classNamed = (name, near) => own.find((constant) => constant.name === name && constant.span.fileName === near.span.fileName) ?? own.find((constant) => constant.name === name) ?? libs.find((constant) => constant.name === name);
|
|
996
|
-
const fields = new Map;
|
|
997
|
-
const seen = new Set;
|
|
998
|
-
const visit = (constant) => {
|
|
999
|
-
if (seen.has(constant))
|
|
1000
|
-
return;
|
|
1001
|
-
seen.add(constant);
|
|
1002
|
-
for (const field of constant.fields)
|
|
1003
|
-
if (!fields.has(field.name))
|
|
1004
|
-
fields.set(field.name, { ...field, declaredIn: constant.name });
|
|
1005
|
-
for (const parent of constant.parents) {
|
|
1006
|
-
const parentClass = classNamed(parent, constant);
|
|
1007
|
-
if (parentClass)
|
|
1008
|
-
visit(parentClass);
|
|
1009
|
-
}
|
|
1010
|
-
};
|
|
1011
|
-
visit(modelClass);
|
|
1012
|
-
return [...fields.values()];
|
|
1013
|
-
}
|
|
1014
|
-
}
|
|
1015
|
-
|
|
1016
|
-
// pkgs/@akanjs/language/akanIndex.ts
|
|
1017
|
-
var sourcePattern = /\.(constant|document|service|signal|store)\.ts$/;
|
|
1018
|
-
var dictionaryPattern = /\.dictionary\.ts$/;
|
|
1019
|
-
var wordPattern = /[A-Za-z_$][\w$]*/g;
|
|
1020
|
-
var identifierPattern = /^[A-Za-z_$][\w$]*$/;
|
|
1021
|
-
var regExpSpecials = /[\\^$.*+?()[\]{}|]/g;
|
|
1022
|
-
var stateReceivers = new Set(["use", "sel", "get", "do"]);
|
|
1023
|
-
var lensFamilies = new Set(["slice", "query", "formSetter", "storeState", "endpoint"]);
|
|
1024
|
-
var modellessFamilies = new Set(["query", "storeState", "endpoint"]);
|
|
1025
|
-
var gateWords = { srv: "srv", sig: "sig", db: "db", slice: "slice" };
|
|
1026
|
-
var parseCacheSize = 64;
|
|
1027
|
-
var pathOf = (fileName) => fileName.replace(/\\/g, "/");
|
|
1028
|
-
var escapeRegExp = (text) => text.replace(regExpSpecials, (special) => `\\${special}`);
|
|
1029
|
-
var receiverGap = String.raw`(?:\s|\)|\/\*[\s\S]*?\*\/)*`;
|
|
1030
|
-
|
|
1031
|
-
class AkanIndex {
|
|
1032
|
-
#ts;
|
|
1033
|
-
#root;
|
|
1034
|
-
#ast;
|
|
1035
|
-
#reader;
|
|
1036
|
-
#facts = new Map;
|
|
1037
|
-
#fileWords = new Map;
|
|
1038
|
-
#parsed = new Map;
|
|
1039
|
-
#table = null;
|
|
1040
|
-
constructor({ ts, root }) {
|
|
1041
|
-
this.#ts = ts;
|
|
1042
|
-
this.#root = pathOf(root).replace(/\/$/, "");
|
|
1043
|
-
this.#ast = createAst(ts);
|
|
1044
|
-
this.#reader = createFactReader(ts, this.#ast);
|
|
1045
|
-
}
|
|
1046
|
-
static isSourcePath(fileName) {
|
|
1047
|
-
return sourcePattern.test(fileName);
|
|
1048
|
-
}
|
|
1049
|
-
get fileCount() {
|
|
1050
|
-
return this.#fileWords.size;
|
|
1051
|
-
}
|
|
1052
|
-
setFile(givenName, text) {
|
|
1053
|
-
const fileName = pathOf(givenName);
|
|
1054
|
-
this.#fileWords.set(fileName, `
|
|
1055
|
-
${[...new Set(text.match(wordPattern))].join(`
|
|
1056
|
-
`)}
|
|
1057
|
-
`);
|
|
1058
|
-
if (!AkanIndex.isSourcePath(fileName))
|
|
1059
|
-
return;
|
|
1060
|
-
const source = this.#parsed.get(fileName)?.text === text ? this.#parse(fileName, text) : this.#parseUncached(fileName, text);
|
|
1061
|
-
this.#facts.set(fileName, this.#reader.read(source, this.#ownerOf(fileName)));
|
|
1062
|
-
this.#table = null;
|
|
1063
|
-
}
|
|
1064
|
-
removeFile(givenName) {
|
|
1065
|
-
const fileName = pathOf(givenName);
|
|
1066
|
-
this.#fileWords.delete(fileName);
|
|
1067
|
-
this.#parsed.delete(fileName);
|
|
1068
|
-
if (this.#facts.delete(fileName))
|
|
1069
|
-
this.#table = null;
|
|
1070
|
-
}
|
|
1071
|
-
definitionAt(givenName, text, offset) {
|
|
1072
|
-
const fileName = pathOf(givenName);
|
|
1073
|
-
const site = this.#useAt(this.#parse(fileName, text), offset);
|
|
1074
|
-
return site ? this.#resolve(fileName, site) : [];
|
|
1075
|
-
}
|
|
1076
|
-
hoverAt(givenName, text, offset) {
|
|
1077
|
-
const fileName = pathOf(givenName);
|
|
1078
|
-
const site = this.#useAt(this.#parse(fileName, text), offset);
|
|
1079
|
-
if (!site)
|
|
1080
|
-
return null;
|
|
1081
|
-
const targets = this.#resolve(fileName, site);
|
|
1082
|
-
return targets.length ? { name: site.identifier.text, targets } : null;
|
|
1083
|
-
}
|
|
1084
|
-
sourceKeysOf(givenName) {
|
|
1085
|
-
const keys = new Map;
|
|
1086
|
-
for (const entry of this.#nameTable().entriesTargeting(pathOf(givenName))) {
|
|
1087
|
-
if (!lensFamilies.has(entry.family) || keys.has(entry.span.start))
|
|
1088
|
-
continue;
|
|
1089
|
-
keys.set(entry.span.start, AkanIndex.#sourceKeyOf(entry));
|
|
1090
|
-
}
|
|
1091
|
-
return [...keys.values()].sort((a, b) => a.span.start - b.span.start);
|
|
1092
|
-
}
|
|
1093
|
-
sourceKeyAt(givenName, offset) {
|
|
1094
|
-
const entries = this.#sourceEntriesAt(pathOf(givenName), offset);
|
|
1095
|
-
const entry = entries.find((candidate) => lensFamilies.has(candidate.family)) ?? entries.at(0);
|
|
1096
|
-
return entry ? AkanIndex.#sourceKeyOf(entry) : null;
|
|
1097
|
-
}
|
|
1098
|
-
referencesAt(givenName, offset, readText) {
|
|
1099
|
-
return this.#usesOf(this.#sourceEntriesAt(pathOf(givenName), offset), readText).map((use) => use.span);
|
|
1100
|
-
}
|
|
1101
|
-
graph(readText, { digests = false } = {}) {
|
|
1102
|
-
return new GraphBuilder({
|
|
1103
|
-
digests,
|
|
1104
|
-
ts: this.#ts,
|
|
1105
|
-
facts: [...this.#facts].sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([, facts]) => facts),
|
|
1106
|
-
files: [...this.#fileWords].sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0),
|
|
1107
|
-
readText,
|
|
1108
|
-
parse: (fileName, text) => this.#parse(fileName, text),
|
|
1109
|
-
resolve: (fileName, identifier) => {
|
|
1110
|
-
if (!this.#nameTable().lookup(identifier.text).length)
|
|
1111
|
-
return [];
|
|
1112
|
-
const site = this.#siteOf(identifier);
|
|
1113
|
-
return site ? this.#resolve(fileName, site) : [];
|
|
1114
|
-
},
|
|
1115
|
-
relative: (fileName) => this.#relative(fileName),
|
|
1116
|
-
ownerOf: (fileName) => this.#ownerOf(fileName)
|
|
1117
|
-
}).build();
|
|
1118
|
-
}
|
|
1119
|
-
renameTargetAt(givenName, offset) {
|
|
1120
|
-
const source = this.#sourceEntriesAt(pathOf(givenName), offset).find((entry) => entry.renamed);
|
|
1121
|
-
return source ? { family: source.family, sourceKey: source.sourceKey, span: source.span } : null;
|
|
1122
|
-
}
|
|
1123
|
-
renameAt(givenName, offset, newKey, readText) {
|
|
1124
|
-
const sources = this.#sourceEntriesAt(pathOf(givenName), offset).filter((entry) => entry.renamed);
|
|
1125
|
-
if (!sources.length || !identifierPattern.test(newKey))
|
|
1126
|
-
return null;
|
|
1127
|
-
return [
|
|
1128
|
-
{ span: sources[0].span, newText: newKey },
|
|
1129
|
-
...this.#usesOf(sources, readText).map(({ span, entry, shorthand }) => {
|
|
1130
|
-
const renamed = entry.renamed?.(newKey) ?? entry.name;
|
|
1131
|
-
return { span, newText: shorthand ? `${renamed}: ${entry.name}` : renamed };
|
|
1132
|
-
}),
|
|
1133
|
-
...this.#dictionaryKeysOf(sources[0], readText).map(({ span, quote }) => ({
|
|
1134
|
-
span,
|
|
1135
|
-
newText: `${quote}${newKey}${quote}`
|
|
1136
|
-
}))
|
|
1137
|
-
];
|
|
1138
|
-
}
|
|
1139
|
-
static #sourceKeyOf({ family, sourceKey, label, detail, span }) {
|
|
1140
|
-
return { family, sourceKey, label, detail, span };
|
|
1141
|
-
}
|
|
1142
|
-
#usesOf(sources, readText) {
|
|
1143
|
-
if (!sources.length)
|
|
1144
|
-
return [];
|
|
1145
|
-
const ts = this.#ts;
|
|
1146
|
-
const isSource = (target) => sources.some((source) => source.span.fileName === target.span.fileName && source.span.start === target.span.start);
|
|
1147
|
-
const refNames = new Set(sources.map((source) => source.refName));
|
|
1148
|
-
const byName = new Map(sources.map((source) => [source.name, source]));
|
|
1149
|
-
const naming = new RegExp(`\\n(?:${[...byName.keys()].map(escapeRegExp).join("|")})\\n`);
|
|
1150
|
-
const gateWordsOf = sources.map((source) => source.gate ? gateWords[source.gate] : undefined);
|
|
1151
|
-
const receiverPatterns = sources.map((source, at) => {
|
|
1152
|
-
const gateWord = gateWordsOf[at];
|
|
1153
|
-
return gateWord ? new RegExp(String.raw`(?<![\w$])${gateWord}${receiverGap}[?!]?\.${receiverGap}${escapeRegExp(source.name)}(?![\w$])`) : null;
|
|
1154
|
-
});
|
|
1155
|
-
const named = (words, at) => words.includes(`
|
|
1156
|
-
${sources[at].name}
|
|
1157
|
-
`) && (!gateWordsOf[at] || words.includes(`
|
|
1158
|
-
${gateWordsOf[at]}
|
|
1159
|
-
`));
|
|
1160
|
-
const candidates = [...this.#fileWords].filter(([, words]) => naming.test(words) && sources.some((_, at) => named(words, at)));
|
|
1161
|
-
const found = [];
|
|
1162
|
-
for (const [file, words] of candidates.sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0)) {
|
|
1163
|
-
const text = readText(file);
|
|
1164
|
-
if (text === undefined)
|
|
1165
|
-
continue;
|
|
1166
|
-
if (!sources.some((_, at) => named(words, at) && (receiverPatterns[at]?.test(text) ?? true)))
|
|
1167
|
-
continue;
|
|
1168
|
-
const source = this.#parse(file, text);
|
|
1169
|
-
const visit = (node) => {
|
|
1170
|
-
const entry = ts.isIdentifier(node) ? byName.get(node.text) : undefined;
|
|
1171
|
-
const site = entry && ts.isIdentifier(node) ? this.#siteOf(node) : null;
|
|
1172
|
-
const targets = site ? this.#resolve(file, site) : [];
|
|
1173
|
-
if (entry && site && targets.some(isSource) && targets.every((target) => refNames.has(target.refName))) {
|
|
1174
|
-
const parent = site.identifier.parent;
|
|
1175
|
-
const shorthand = ts.isBindingElement(parent) && !parent.propertyName;
|
|
1176
|
-
found.push({ span: this.#reader.spanOf(source, site.identifier), entry, shorthand });
|
|
1177
|
-
}
|
|
1178
|
-
ts.forEachChild(node, visit);
|
|
1179
|
-
};
|
|
1180
|
-
visit(source);
|
|
1181
|
-
}
|
|
1182
|
-
return found;
|
|
1183
|
-
}
|
|
1184
|
-
#dictionaryKeysOf(source, readText) {
|
|
1185
|
-
const { dictionary } = source;
|
|
1186
|
-
if (!dictionary)
|
|
1187
|
-
return [];
|
|
1188
|
-
const ts = this.#ts;
|
|
1189
|
-
const keys = [];
|
|
1190
|
-
const moduleDir = source.span.fileName.slice(0, source.span.fileName.lastIndexOf("/"));
|
|
1191
|
-
for (const [file, words] of this.#fileWords) {
|
|
1192
|
-
if (!dictionaryPattern.test(file) || this.#ownerOf(file) !== source.owner)
|
|
1193
|
-
continue;
|
|
1194
|
-
const sameModule = file.slice(0, file.lastIndexOf("/")) === moduleDir;
|
|
1195
|
-
if (!words.includes(`
|
|
1196
|
-
${dictionary.section}
|
|
1197
|
-
`))
|
|
1198
|
-
continue;
|
|
1199
|
-
if (!sameModule && !words.includes(`
|
|
1200
|
-
${dictionary.className}
|
|
1201
|
-
`))
|
|
1202
|
-
continue;
|
|
1203
|
-
const text = readText(file);
|
|
1204
|
-
if (text === undefined)
|
|
1205
|
-
continue;
|
|
1206
|
-
const parsed = this.#parse(file, text);
|
|
1207
|
-
const visit = (node) => {
|
|
1208
|
-
const typeArgument = ts.isCallExpression(node) ? node.typeArguments?.[0] : undefined;
|
|
1209
|
-
const builder = ts.isCallExpression(node) ? node.arguments.at(-1) : undefined;
|
|
1210
|
-
const typed = !!typeArgument && ts.isTypeReferenceNode(typeArgument) && ts.isIdentifier(typeArgument.typeName) && typeArgument.typeName.text === dictionary.className;
|
|
1211
|
-
const untyped = !typeArgument && sameModule;
|
|
1212
|
-
const object = ts.isCallExpression(node) && ts.isPropertyAccessExpression(node.expression) && node.expression.name.text === dictionary.section && (typed || untyped) && builder ? this.#ast.firstObjectReturnedByArrow(builder) : null;
|
|
1213
|
-
for (const property of object?.properties ?? [])
|
|
1214
|
-
if (ts.isPropertyAssignment(property) && this.#ast.nodeName(property.name) === source.sourceKey)
|
|
1215
|
-
keys.push({
|
|
1216
|
-
span: this.#reader.spanOf(parsed, property.name),
|
|
1217
|
-
quote: ts.isStringLiteral(property.name) ? parsed.text.charAt(property.name.getStart(parsed)) : ""
|
|
1218
|
-
});
|
|
1219
|
-
ts.forEachChild(node, visit);
|
|
1220
|
-
};
|
|
1221
|
-
visit(parsed);
|
|
1222
|
-
}
|
|
1223
|
-
return keys;
|
|
1224
|
-
}
|
|
1225
|
-
#sourceEntriesAt(fileName, offset) {
|
|
1226
|
-
return this.#nameTable().entriesTargeting(fileName).filter((entry) => entry.span.start <= offset && offset <= entry.span.end);
|
|
1227
|
-
}
|
|
1228
|
-
#nameTable() {
|
|
1229
|
-
this.#table ??= new NameTable(this.#facts.values());
|
|
1230
|
-
return this.#table;
|
|
1231
|
-
}
|
|
1232
|
-
#relative(fileName) {
|
|
1233
|
-
return fileName.startsWith(`${this.#root}/`) ? fileName.slice(this.#root.length + 1) : fileName;
|
|
1234
|
-
}
|
|
1235
|
-
#ownerOf(fileName) {
|
|
1236
|
-
return ownerOf(this.#relative(fileName));
|
|
1237
|
-
}
|
|
1238
|
-
#parseUncached(fileName, text) {
|
|
1239
|
-
const kind = fileName.endsWith(".tsx") ? this.#ts.ScriptKind.TSX : this.#ts.ScriptKind.TS;
|
|
1240
|
-
return this.#ast.sourceFileFor(fileName, text, kind);
|
|
1241
|
-
}
|
|
1242
|
-
#parse(fileName, text) {
|
|
1243
|
-
const cached = this.#parsed.get(fileName);
|
|
1244
|
-
if (cached?.text === text)
|
|
1245
|
-
return cached.source;
|
|
1246
|
-
const source = this.#parseUncached(fileName, text);
|
|
1247
|
-
this.#parsed.delete(fileName);
|
|
1248
|
-
this.#parsed.set(fileName, { text, source });
|
|
1249
|
-
if (this.#parsed.size > parseCacheSize) {
|
|
1250
|
-
const oldest = this.#parsed.keys().next().value;
|
|
1251
|
-
if (oldest !== undefined)
|
|
1252
|
-
this.#parsed.delete(oldest);
|
|
1253
|
-
}
|
|
1254
|
-
return source;
|
|
1255
|
-
}
|
|
1256
|
-
#useAt(source, offset) {
|
|
1257
|
-
const ts = this.#ts;
|
|
1258
|
-
let found = null;
|
|
1259
|
-
const visit = (node) => {
|
|
1260
|
-
if (offset < node.getStart(source) || offset > node.getEnd())
|
|
1261
|
-
return;
|
|
1262
|
-
if (ts.isIdentifier(node))
|
|
1263
|
-
found = node;
|
|
1264
|
-
ts.forEachChild(node, visit);
|
|
1265
|
-
};
|
|
1266
|
-
visit(source);
|
|
1267
|
-
return found ? this.#siteOf(found) : null;
|
|
1268
|
-
}
|
|
1269
|
-
#siteOf(identifier) {
|
|
1270
|
-
const ts = this.#ts;
|
|
1271
|
-
const parent = identifier.parent;
|
|
1272
|
-
let chain;
|
|
1273
|
-
if (ts.isPropertyAccessExpression(parent) && parent.name === identifier)
|
|
1274
|
-
chain = this.#chainOf(parent.expression);
|
|
1275
|
-
else if (ts.isBindingElement(parent) && !parent.dotDotDotToken && ts.isObjectBindingPattern(parent.parent) && (parent.propertyName === identifier || !parent.propertyName && parent.name === identifier))
|
|
1276
|
-
chain = null;
|
|
1277
|
-
else
|
|
1278
|
-
return null;
|
|
1279
|
-
const { model, inStore } = this.#classContextOf(identifier);
|
|
1280
|
-
return { identifier, chain, classModel: model, inStore };
|
|
1281
|
-
}
|
|
1282
|
-
#chainOf(expression) {
|
|
1283
|
-
const ts = this.#ts;
|
|
1284
|
-
if (ts.isNonNullExpression(expression) || ts.isParenthesizedExpression(expression))
|
|
1285
|
-
return this.#chainOf(expression.expression);
|
|
1286
|
-
if (ts.isIdentifier(expression))
|
|
1287
|
-
return [expression.text];
|
|
1288
|
-
if (expression.kind === ts.SyntaxKind.ThisKeyword)
|
|
1289
|
-
return ["this"];
|
|
1290
|
-
if (ts.isPropertyAccessExpression(expression))
|
|
1291
|
-
return [...this.#chainOf(expression.expression), expression.name.text];
|
|
1292
|
-
return ["?"];
|
|
1293
|
-
}
|
|
1294
|
-
#classContextOf(node) {
|
|
1295
|
-
const ts = this.#ts;
|
|
1296
|
-
let current = node.parent;
|
|
1297
|
-
while (current && !ts.isClassDeclaration(current) && !ts.isClassExpression(current))
|
|
1298
|
-
current = current.parent;
|
|
1299
|
-
if (!current)
|
|
1300
|
-
return { model: null, inStore: false };
|
|
1301
|
-
const className = current.name?.text;
|
|
1302
|
-
const heritage = current.heritageClauses?.flatMap((clause) => [...clause.types]) ?? [];
|
|
1303
|
-
for (const { expression } of heritage) {
|
|
1304
|
-
if (!ts.isCallExpression(expression))
|
|
1305
|
-
continue;
|
|
1306
|
-
const callee = this.#ast.expressionName(expression.expression);
|
|
1307
|
-
if (callee === "into" && className?.endsWith("Model"))
|
|
1308
|
-
return { model: className.charAt(0).toLowerCase() + className.slice(1, -5), inStore: false };
|
|
1309
|
-
const holder = callee === "serve" ? "db" : callee === "store" ? "sig" : callee === "slice" || callee === "endpoint" || callee === "internal" ? "srv" : null;
|
|
1310
|
-
if (!holder)
|
|
1311
|
-
continue;
|
|
1312
|
-
return { model: this.#reader.moduleRefOf(expression.arguments[0], holder), inStore: callee === "store" };
|
|
1313
|
-
}
|
|
1314
|
-
return { model: null, inStore: false };
|
|
1315
|
-
}
|
|
1316
|
-
#modelHintOf(site) {
|
|
1317
|
-
const { chain } = site;
|
|
1318
|
-
if (!chain)
|
|
1319
|
-
return null;
|
|
1320
|
-
if (chain.length === 1 && chain[0] === "this")
|
|
1321
|
-
return site.classModel;
|
|
1322
|
-
const holder = chain.at(-1)?.replace(/^#/, "");
|
|
1323
|
-
const suffix = holder?.match(/.(Service|Model)$/)?.[1];
|
|
1324
|
-
if (holder && suffix)
|
|
1325
|
-
return holder.slice(0, -suffix.length);
|
|
1326
|
-
if (chain.length === 2 && (chain[0] === "db" || chain[0] === "srv"))
|
|
1327
|
-
return chain[1];
|
|
1328
|
-
return null;
|
|
1329
|
-
}
|
|
1330
|
-
#passesGate(entry, site) {
|
|
1331
|
-
const { chain } = site;
|
|
1332
|
-
const last = chain?.at(-1);
|
|
1333
|
-
switch (entry.gate) {
|
|
1334
|
-
case "srv":
|
|
1335
|
-
case "sig":
|
|
1336
|
-
case "db":
|
|
1337
|
-
return chain?.length === 1 && last === entry.gate;
|
|
1338
|
-
case "slice":
|
|
1339
|
-
return last === "slice";
|
|
1340
|
-
case "state":
|
|
1341
|
-
return !!last && stateReceivers.has(last) || site.inStore && chain?.length === 1 && last === "this";
|
|
1342
|
-
default:
|
|
1343
|
-
return true;
|
|
1344
|
-
}
|
|
1345
|
-
}
|
|
1346
|
-
#resolve(fileName, site) {
|
|
1347
|
-
const owner = this.#ownerOf(fileName);
|
|
1348
|
-
const visible = this.#nameTable().lookup(site.identifier.text).filter((entry) => this.#passesGate(entry, site) && (!owner || !entry.owner || entry.owner === owner || entry.owner.startsWith("libs/")));
|
|
1349
|
-
const hint = this.#modelHintOf(site);
|
|
1350
|
-
const hinted = hint ? visible.filter((entry) => entry.refName === hint) : [];
|
|
1351
|
-
const chosen = hinted.length ? hinted : hint ? visible.filter((entry) => !modellessFamilies.has(entry.family)) : visible;
|
|
1352
|
-
return chosen.map(({ family, refName, owner: entryOwner, sourceKey, label, detail, span }) => ({
|
|
1353
|
-
family,
|
|
1354
|
-
refName,
|
|
1355
|
-
owner: entryOwner,
|
|
1356
|
-
sourceKey,
|
|
1357
|
-
label,
|
|
1358
|
-
detail,
|
|
1359
|
-
span
|
|
1360
|
-
})).sort((a, b) => Number(b.owner === owner) - Number(a.owner === owner));
|
|
1361
|
-
}
|
|
1362
|
-
}
|
|
1363
|
-
export { AkanGraphDiff, createAst, createFactReader, AkanIndex };
|