@akanjs/cli 3.2.0-rc.1 → 3.2.0-rc.3
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-vmd9k4ak.js → CodeAgent-e9c712an.js} +3 -3
- package/{CodeTui-zka44v52.js → CodeTui-wv9yf7eq.js} +1 -1
- package/TunnelShare-zkfkrw8w.js +14 -0
- package/{agent.command-2f657613.js → agent.command-9erafkcb.js} +17 -17
- package/akanCode.js +3 -3
- package/{application.command-q6skd3am.js → application.command-6515t682.js} +13 -13
- package/{applicationBuildRunner-sctcmkyx.js → applicationBuildRunner-bqbyeg84.js} +6 -6
- package/buildBatch.proc.js +6 -6
- package/{cloud.command-7642pks6.js → cloud.command-32esk0v1.js} +19 -19
- package/cloud.script-arsagnq6.js +30 -0
- package/{code.command-7s4ndq2k.js → code.command-xk7rwq2x.js} +6 -6
- package/{context.command-569z0rqf.js → context.command-jwenkkf0.js} +19 -19
- package/context.runner-mqpp67br.js +29 -0
- package/{devTui-w38ch13a.js → devTui-cd03z4mx.js} +1 -1
- package/{guideline.command-gnv3e8p8.js → guideline.command-w6yqpdec.js} +2 -2
- package/incrementalBuilder.proc.js +7 -7
- package/{index-48d5qsj3.js → index-0ba8nj4d.js} +4 -4
- package/{index-ed6ea0qp.js → index-20wvskt8.js} +1 -1
- package/{index-rc5fvqj2.js → index-2eym1yjb.js} +29 -27
- package/{index-5w9my9qe.js → index-2rqyrvcy.js} +8 -8
- package/{index-93ewzmp6.js → index-386canwe.js} +21 -14
- package/{index-w639tvkd.js → index-39jz41jb.js} +29 -8
- package/{index-vkzfk7qt.js → index-43acpsc7.js} +40 -30
- package/{index-mqntfzv5.js → index-54s6knqe.js} +7 -2
- package/{index-6wpaq392.js → index-6h775rv3.js} +4 -4
- package/{index-aj3ehkcx.js → index-7kmbqp0b.js} +1 -1
- package/{index-1q1cjn8s.js → index-84c2pgak.js} +93 -53
- package/{index-0fb3cpbt.js → index-8gm4yag8.js} +9 -7
- package/{index-sy481q2x.js → index-8jpc5fqv.js} +1 -1
- package/{index-7y5yghjg.js → index-9p260r4e.js} +1000 -409
- package/{index-d4n1wmrz.js → index-bak9f2br.js} +4 -4
- package/{index-8g7tdsk4.js → index-bdmgqzb5.js} +4 -4
- package/{index-abgh0jve.js → index-cmg5ngqa.js} +1 -1
- package/{index-vr68mxj5.js → index-ddk49ypz.js} +14 -10
- package/{index-zpv14wpy.js → index-djc5nxpy.js} +3 -3
- package/{index-s2grpzef.js → index-dpgywgeq.js} +3 -3
- package/{index-drz9e84d.js → index-e22zedc2.js} +2 -2
- package/{index-e3vmjtph.js → index-h0p6n4k1.js} +7 -2
- package/{index-9tbgb4d8.js → index-j1hjb477.js} +1 -1
- package/{index-kpdv34rq.js → index-j4hkbzj6.js} +10 -7
- package/{index-ktb3wcqz.js → index-kcpk2d20.js} +8 -8
- package/{index-thckcabc.js → index-ngpt3zz3.js} +18 -3
- package/{index-8kczhnmv.js → index-qrk06tfp.js} +1 -1
- package/{index-8ts9774g.js → index-s34v3y28.js} +9 -4
- package/{index-23860fej.js → index-sc0g6zbm.js} +2 -0
- package/{index-eajbmk10.js → index-v50xjbbe.js} +1 -1
- package/{index-7xdpww43.js → index-vbhx60x5.js} +323 -129
- package/{index-sr5da35e.js → index-wfmpxke3.js} +2 -2
- package/{index-mmym5xmb.js → index-wr9magsr.js} +5 -3
- package/index-x3x31df8.js +14 -0
- package/{index-8pb9yvp8.js → index-xrmrvafh.js} +54 -17
- package/{index-p6hjwt2d.js → index-y725zb1a.js} +1 -1
- package/{index-hqrkqxx2.js → index-ygrdw6jw.js} +1 -1
- package/{index-a8a9ede9.js → index-ytpmk3pb.js} +4 -4
- package/{index-v4p1zye8.js → index-zcdmnfrf.js} +7 -7
- package/{index-fjr4d6yd.js → index-zhkcab5a.js} +5 -5
- package/index.js +23 -23
- package/{library.command-1gp5qe3r.js → library.command-qs8beggh.js} +4 -4
- package/{localRegistry.command-x7jptkd3.js → localRegistry.command-hz4ged9n.js} +18 -18
- package/{module.command-4xz9he6h.js → module.command-z9js77m2.js} +7 -7
- package/{package.command-s7qpnn1g.js → package.command-zqenq8c0.js} +7 -7
- package/package.json +2 -2
- package/{page.command-fan34c49.js → page.command-t0nx1jat.js} +3 -3
- package/{pipeline.command-ph4fnn9w.js → pipeline.command-2yjeas7m.js} +2 -2
- package/{primitive.command-3fqh8emf.js → primitive.command-v5kypwy4.js} +7 -7
- package/{projectTypecheck-vkb40hjc.js → projectTypecheck-s9hhe5sa.js} +1 -1
- package/{quality.command-ecj6exsh.js → quality.command-q55j2htd.js} +6 -6
- package/{repair.command-fe9jw719.js → repair.command-7ssbbdq2.js} +6 -6
- package/{scalar.command-cnvfhk0n.js → scalar.command-p5jb7z57.js} +6 -6
- package/skills/akan-scaffold/SKILL.md +2 -1
- package/{subspace.command-qw5ddd6y.js → subspace.command-7wxy6ptj.js} +8 -8
- package/{tunnel.command-ggj38mqf.js → tunnel.command-22g11n0x.js} +7 -7
- package/{verify.command-w9ttxkdz.js → verify.command-m0wnndd7.js} +14 -14
- package/{workflow.command-ss8devj0.js → workflow.command-jx8dqs9n.js} +30 -15
- package/{workspace.command-6z2rh8ze.js → workspace.command-ca9kfyt3.js} +38 -34
- package/TunnelShare-k3ja4w9x.js +0 -14
- package/cloud.script-1sfseznn.js +0 -30
- package/context.runner-ms8v1rxy.js +0 -29
|
@@ -9,7 +9,8 @@ var isEdited = (before, after) => before.digest !== undefined && after.digest !=
|
|
|
9
9
|
var byId = (a, b) => a.id < b.id ? -1 : a.id > b.id ? 1 : 0;
|
|
10
10
|
|
|
11
11
|
class AkanGraphDiff {
|
|
12
|
-
static between(
|
|
12
|
+
static between(given, head) {
|
|
13
|
+
const base = AkanGraphDiff.#renamed(given, head);
|
|
13
14
|
const baseNodes = new Map(base.nodes.map((node) => [node.id, node]));
|
|
14
15
|
const headNodes = new Map(head.nodes.map((node) => [node.id, node]));
|
|
15
16
|
const marked = new Map;
|
|
@@ -28,6 +29,9 @@ class AkanGraphDiff {
|
|
|
28
29
|
...head.edges.flatMap((edge) => !baseKeys.has(edgeKeyOf(edge)) ? [{ ...edge, change: "added" }] : marked.has(edge.from) || marked.has(edge.to) ? [edge] : []),
|
|
29
30
|
...base.edges.filter((edge) => !headKeys.has(edgeKeyOf(edge))).map((edge) => ({ ...edge, change: "removed" }))
|
|
30
31
|
];
|
|
32
|
+
const shown = new Set([...marked.keys(), ...edges.flatMap((edge) => [edge.from, edge.to])]);
|
|
33
|
+
const listed = new Set(edges.map(edgeKeyOf));
|
|
34
|
+
edges.push(...head.edges.filter((edge) => edge.kind === "binds" && shown.has(edge.from) && !listed.has(edgeKeyOf(edge))));
|
|
31
35
|
const context = edges.flatMap((edge) => [edge.from, edge.to]).filter((id) => !marked.has(id)).flatMap((id) => {
|
|
32
36
|
const node = headNodes.get(id) ?? baseNodes.get(id);
|
|
33
37
|
return node ? [node] : [];
|
|
@@ -39,6 +43,40 @@ class AkanGraphDiff {
|
|
|
39
43
|
summary[node.change] += 1;
|
|
40
44
|
return { version: 1, nodes, edges, summary };
|
|
41
45
|
}
|
|
46
|
+
static #renamed(base, head) {
|
|
47
|
+
const baseIds = new Set(base.nodes.map((node) => node.id));
|
|
48
|
+
const headIds = new Set(head.nodes.map((node) => node.id));
|
|
49
|
+
const pairKeyOf = ({ kind, owner, name, at }) => at ? `${kind}
|
|
50
|
+
${owner ?? ""}
|
|
51
|
+
${name}
|
|
52
|
+
${at.file}` : null;
|
|
53
|
+
const shortIdOf = ({ kind, owner, name }) => `${kind}:${owner ?? ""}:${name}`;
|
|
54
|
+
const isFileKeyed = (node) => node.id !== shortIdOf(node) && node.id.startsWith(`${node.kind}:${node.owner ?? ""}:`) && node.id.endsWith(`#${node.name}`);
|
|
55
|
+
const fromBase = new Map(base.nodes.flatMap((node) => {
|
|
56
|
+
const key = headIds.has(node.id) ? null : pairKeyOf(node);
|
|
57
|
+
return key ? [[key, node]] : [];
|
|
58
|
+
}));
|
|
59
|
+
const renames = new Map;
|
|
60
|
+
for (const node of head.nodes) {
|
|
61
|
+
if (baseIds.has(node.id))
|
|
62
|
+
continue;
|
|
63
|
+
const key = pairKeyOf(node);
|
|
64
|
+
const before = key ? fromBase.get(key) : undefined;
|
|
65
|
+
if (!before)
|
|
66
|
+
continue;
|
|
67
|
+
const isPair = isFileKeyed(node) ? before.id === shortIdOf(node) : isFileKeyed(before) && node.id === shortIdOf(before);
|
|
68
|
+
if (isPair)
|
|
69
|
+
renames.set(before.id, node.id);
|
|
70
|
+
}
|
|
71
|
+
if (!renames.size)
|
|
72
|
+
return base;
|
|
73
|
+
const rename = (id) => renames.get(id) ?? id;
|
|
74
|
+
return {
|
|
75
|
+
...base,
|
|
76
|
+
nodes: base.nodes.map((node) => renames.has(node.id) ? { ...node, id: rename(node.id) } : node),
|
|
77
|
+
edges: base.edges.map((edge) => ({ ...edge, from: rename(edge.from), to: rename(edge.to) }))
|
|
78
|
+
};
|
|
79
|
+
}
|
|
42
80
|
static #mark(node, change) {
|
|
43
81
|
return node.fields ? { ...node, change, fields: node.fields.map((field) => ({ ...field, change })) } : { ...node, change };
|
|
44
82
|
}
|
|
@@ -72,6 +110,239 @@ class AkanGraphDiff {
|
|
|
72
110
|
return node.fields ? { ...node, fields: node.fields.map(({ digest: _field, ...field }) => field) } : node;
|
|
73
111
|
}
|
|
74
112
|
}
|
|
113
|
+
// pkgs/@akanjs/language/guardFacts.ts
|
|
114
|
+
var guardLabelOf = (guard, labels) => {
|
|
115
|
+
const [, role = null, local = guard] = guard.match(/^([\w$]+) (.+)$/) ?? [];
|
|
116
|
+
const label = labels[local];
|
|
117
|
+
return label === undefined ? guard : role ? `${role} ${label}` : label;
|
|
118
|
+
};
|
|
119
|
+
var maxLabelArgs = 32;
|
|
120
|
+
var guardRefReaderOf = (ts, ast, unwrap) => {
|
|
121
|
+
const pathOf = (expression) => {
|
|
122
|
+
if (ts.isIdentifier(expression))
|
|
123
|
+
return expression.text;
|
|
124
|
+
if (!ts.isPropertyAccessExpression(expression))
|
|
125
|
+
return null;
|
|
126
|
+
const head = pathOf(expression.expression);
|
|
127
|
+
return head && `${head}.${expression.name.text}`;
|
|
128
|
+
};
|
|
129
|
+
const calleeOf = (call) => pathOf(unwrap(call.expression)) ?? "?";
|
|
130
|
+
const labelOf = (source, call) => {
|
|
131
|
+
const args = call.arguments.map((arg) => arg.getText(source)).join(", ");
|
|
132
|
+
return `${calleeOf(call)}(${args.length <= maxLabelArgs && !args.includes(`
|
|
133
|
+
`) ? args : "\u2026"})`;
|
|
134
|
+
};
|
|
135
|
+
const guardRefOf = (expression, made, member) => {
|
|
136
|
+
const value = unwrap(expression);
|
|
137
|
+
if (!ts.isCallExpression(value))
|
|
138
|
+
return pathOf(value) ?? ast.expressionName(value);
|
|
139
|
+
const prefix = `${member}:${calleeOf(value)}@`;
|
|
140
|
+
const name = `${prefix}${made.filter((other) => other.name.startsWith(prefix)).length + 1}`;
|
|
141
|
+
made.push({ call: value, name });
|
|
142
|
+
return name;
|
|
143
|
+
};
|
|
144
|
+
const guardsIn = (source, object, made, member) => {
|
|
145
|
+
const guards = object?.properties.find((property) => ts.isPropertyAssignment(property) && ast.nodeName(property.name) === "guards")?.initializer;
|
|
146
|
+
if (!guards)
|
|
147
|
+
return [];
|
|
148
|
+
const refOf = (expression) => guardRefOf(expression, made, member);
|
|
149
|
+
if (ts.isArrayLiteralExpression(guards))
|
|
150
|
+
return guards.elements.map(refOf).filter((name) => name !== null);
|
|
151
|
+
if (ts.isObjectLiteralExpression(guards))
|
|
152
|
+
return guards.properties.filter(ts.isPropertyAssignment).flatMap((property) => {
|
|
153
|
+
const value = unwrap(property.initializer);
|
|
154
|
+
const names = ts.isArrayLiteralExpression(value) ? value.elements.map(refOf) : [refOf(value)];
|
|
155
|
+
return names.map((name) => `${ast.nodeName(property.name)} ${name ?? "?"}`);
|
|
156
|
+
});
|
|
157
|
+
const single = refOf(guards);
|
|
158
|
+
return single ? [single] : [];
|
|
159
|
+
};
|
|
160
|
+
return { pathOf, labelOf, guardsIn };
|
|
161
|
+
};
|
|
162
|
+
var guardFactoryReaderOf = (ts, ast, { spanOf, extentOf, unwrap, docOf }, pathOf) => {
|
|
163
|
+
const implementsGuard = (node, guardNames) => !!node.heritageClauses?.some((clause) => clause.token === ts.SyntaxKind.ImplementsKeyword && clause.types.some(({ expression }) => guardNames.has(ast.expressionName(expression) ?? "")));
|
|
164
|
+
const scopeOf = (node) => {
|
|
165
|
+
const scope = node.members.find((member) => ts.isPropertyDeclaration(member) && ast.nodeName(member.name) === "scope" && !!ts.getModifiers(member)?.some(({ kind }) => kind === ts.SyntaxKind.StaticKeyword))?.initializer;
|
|
166
|
+
const value = scope && unwrap(scope);
|
|
167
|
+
return value && ts.isStringLiteralLike(value) ? value.text : null;
|
|
168
|
+
};
|
|
169
|
+
const functionsOf = (source) => {
|
|
170
|
+
const functions = new Map;
|
|
171
|
+
for (const statement of source.statements) {
|
|
172
|
+
if (ts.isFunctionDeclaration(statement) && statement.name && statement.body)
|
|
173
|
+
functions.set(statement.name.text, { statement, name: statement.name, body: statement.body });
|
|
174
|
+
if (!ts.isVariableStatement(statement))
|
|
175
|
+
continue;
|
|
176
|
+
for (const declaration of statement.declarationList.declarations) {
|
|
177
|
+
const initializer = declaration.initializer && unwrap(declaration.initializer);
|
|
178
|
+
if (initializer && ts.isIdentifier(declaration.name) && (ts.isArrowFunction(initializer) || ts.isFunctionExpression(initializer)))
|
|
179
|
+
functions.set(declaration.name.text, { statement, name: declaration.name, body: initializer.body });
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
return functions;
|
|
183
|
+
};
|
|
184
|
+
const returnedOf = (body, guardNames) => {
|
|
185
|
+
const locals = new Map;
|
|
186
|
+
const pending = [];
|
|
187
|
+
const visit = (node) => {
|
|
188
|
+
if (ts.isClassDeclaration(node) && node.name)
|
|
189
|
+
locals.set(node.name.text, node);
|
|
190
|
+
if (ts.isVariableDeclaration(node) && ts.isIdentifier(node.name) && node.initializer)
|
|
191
|
+
locals.set(node.name.text, node.initializer);
|
|
192
|
+
if (ts.isReturnStatement(node) && node.expression)
|
|
193
|
+
pending.push(node.expression);
|
|
194
|
+
if (!ts.isFunctionLike(node) && !ts.isClassLike(node))
|
|
195
|
+
ts.forEachChild(node, visit);
|
|
196
|
+
};
|
|
197
|
+
if (ts.isBlock(body))
|
|
198
|
+
ts.forEachChild(body, visit);
|
|
199
|
+
else
|
|
200
|
+
pending.push(body);
|
|
201
|
+
let guard = null;
|
|
202
|
+
const calls = [];
|
|
203
|
+
const seen = new Set;
|
|
204
|
+
const passed = new Set;
|
|
205
|
+
for (let node = pending.pop();node; node = pending.pop()) {
|
|
206
|
+
if (seen.has(node))
|
|
207
|
+
continue;
|
|
208
|
+
seen.add(node);
|
|
209
|
+
const value = ts.isExpression(node) ? unwrap(node) : node;
|
|
210
|
+
if ((ts.isClassExpression(value) || ts.isClassDeclaration(value)) && implementsGuard(value, guardNames))
|
|
211
|
+
guard ??= value;
|
|
212
|
+
else if (ts.isConditionalExpression(value))
|
|
213
|
+
pending.push(value.whenTrue, value.whenFalse);
|
|
214
|
+
else if (ts.isBinaryExpression(value))
|
|
215
|
+
pending.push(value.left, value.right);
|
|
216
|
+
else if (ts.isIdentifier(value)) {
|
|
217
|
+
const local = locals.get(value.text);
|
|
218
|
+
if (local)
|
|
219
|
+
pending.push(local);
|
|
220
|
+
} else if (ts.isCallExpression(value)) {
|
|
221
|
+
const callee = pathOf(unwrap(value.expression));
|
|
222
|
+
if (callee && !passed.has(node) && !calls.includes(callee))
|
|
223
|
+
calls.push(callee);
|
|
224
|
+
for (const arg of value.arguments)
|
|
225
|
+
passed.add(arg);
|
|
226
|
+
pending.push(...value.arguments);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
return { guard, calls };
|
|
230
|
+
};
|
|
231
|
+
const guardFactoriesOf = (source, guardNames, isImported) => {
|
|
232
|
+
const functions = functionsOf(source);
|
|
233
|
+
const returned = new Map([...functions].map(([name, { body }]) => [name, returnedOf(body, guardNames)]));
|
|
234
|
+
const members = new Set;
|
|
235
|
+
const isFactoryCall = (callee) => members.has(callee) || !functions.has(callee) && isImported(callee);
|
|
236
|
+
for (let isGrowing = true;isGrowing; ) {
|
|
237
|
+
isGrowing = false;
|
|
238
|
+
for (const [name, { guard, calls }] of returned) {
|
|
239
|
+
if (members.has(name) || !guard && !calls.some(isFactoryCall))
|
|
240
|
+
continue;
|
|
241
|
+
members.add(name);
|
|
242
|
+
isGrowing = true;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
const factories = new Map;
|
|
246
|
+
for (const name of members) {
|
|
247
|
+
const found = functions.get(name);
|
|
248
|
+
const made = returned.get(name);
|
|
249
|
+
if (!found || !made)
|
|
250
|
+
continue;
|
|
251
|
+
factories.set(name, {
|
|
252
|
+
name,
|
|
253
|
+
span: spanOf(source, found.name),
|
|
254
|
+
extent: extentOf(source, found.statement),
|
|
255
|
+
scope: made.guard ? scopeOf(made.guard) : null,
|
|
256
|
+
doc: docOf(source, found.statement),
|
|
257
|
+
direct: !!made.guard,
|
|
258
|
+
via: made.calls.filter(isFactoryCall)
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
return factories;
|
|
262
|
+
};
|
|
263
|
+
return { implementsGuard, scopeOf, guardFactoriesOf };
|
|
264
|
+
};
|
|
265
|
+
var createGuardFactReader = (ts, ast, base) => {
|
|
266
|
+
const { spanOf, extentOf, unwrap, docOf } = base;
|
|
267
|
+
const { pathOf, labelOf, guardsIn } = guardRefReaderOf(ts, ast, unwrap);
|
|
268
|
+
const { implementsGuard, scopeOf, guardFactoriesOf } = guardFactoryReaderOf(ts, ast, base, pathOf);
|
|
269
|
+
const guardsOf = (source, imports, madeInPlace) => {
|
|
270
|
+
const guardNames = new Set([
|
|
271
|
+
"Guard",
|
|
272
|
+
...imports.filter(({ imported }) => imported === "Guard").map(({ name }) => name)
|
|
273
|
+
]);
|
|
274
|
+
const imported = new Set(imports.map(({ name }) => name));
|
|
275
|
+
const isImported = (callee) => imported.has(callee.split(".")[0] ?? callee);
|
|
276
|
+
const factories = guardFactoriesOf(source, guardNames, isImported);
|
|
277
|
+
const guards = [];
|
|
278
|
+
const calls = [];
|
|
279
|
+
const makeOf = (made, value, isInPlace = false) => {
|
|
280
|
+
if (ts.isClassExpression(value) && implementsGuard(value, guardNames)) {
|
|
281
|
+
guards.push({ ...made, scope: scopeOf(value), factory: null });
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
const callee = ts.isCallExpression(value) ? pathOf(unwrap(value.expression)) : null;
|
|
285
|
+
const factory = callee && factories.get(callee);
|
|
286
|
+
if (factory)
|
|
287
|
+
guards.push({ ...made, scope: factory.scope, factory: factory.name });
|
|
288
|
+
else if (callee && (isImported(callee) || isInPlace))
|
|
289
|
+
calls.push({ ...made, callee, kind: "call", scope: null });
|
|
290
|
+
};
|
|
291
|
+
for (const statement of source.statements) {
|
|
292
|
+
if (ts.isClassDeclaration(statement) && statement.name) {
|
|
293
|
+
const declared = {
|
|
294
|
+
name: statement.name.text,
|
|
295
|
+
span: spanOf(source, statement.name),
|
|
296
|
+
extent: extentOf(source, statement),
|
|
297
|
+
scope: scopeOf(statement),
|
|
298
|
+
doc: docOf(source, statement)
|
|
299
|
+
};
|
|
300
|
+
const base = statement.heritageClauses?.find(({ token }) => token === ts.SyntaxKind.ExtendsKeyword)?.types[0];
|
|
301
|
+
const callee = base && pathOf(base.expression);
|
|
302
|
+
if (implementsGuard(statement, guardNames))
|
|
303
|
+
guards.push({ ...declared, factory: null });
|
|
304
|
+
else if (callee)
|
|
305
|
+
calls.push({ ...declared, callee, kind: "extends" });
|
|
306
|
+
}
|
|
307
|
+
if (!ts.isVariableStatement(statement))
|
|
308
|
+
continue;
|
|
309
|
+
for (const declaration of statement.declarationList.declarations) {
|
|
310
|
+
const initializer = declaration.initializer && unwrap(declaration.initializer);
|
|
311
|
+
if (!initializer || !ts.isIdentifier(declaration.name))
|
|
312
|
+
continue;
|
|
313
|
+
const holder = declaration.name.text;
|
|
314
|
+
makeOf({
|
|
315
|
+
name: holder,
|
|
316
|
+
span: spanOf(source, declaration.name),
|
|
317
|
+
extent: extentOf(source, statement),
|
|
318
|
+
doc: docOf(source, statement)
|
|
319
|
+
}, initializer);
|
|
320
|
+
if (!ts.isObjectLiteralExpression(initializer))
|
|
321
|
+
continue;
|
|
322
|
+
for (const property of initializer.properties) {
|
|
323
|
+
const key = ts.isPropertyAssignment(property) ? ast.nodeName(property.name) : null;
|
|
324
|
+
if (key && ts.isPropertyAssignment(property))
|
|
325
|
+
makeOf({
|
|
326
|
+
name: `${holder}.${key}`,
|
|
327
|
+
span: spanOf(source, property.name),
|
|
328
|
+
extent: extentOf(source, property),
|
|
329
|
+
doc: docOf(source, property)
|
|
330
|
+
}, unwrap(property.initializer));
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
for (const { call, name } of madeInPlace)
|
|
335
|
+
makeOf({ name, span: spanOf(source, call), extent: extentOf(source, call), doc: null }, call, true);
|
|
336
|
+
const guardLabels = Object.fromEntries(madeInPlace.map(({ call, name }) => [name, labelOf(source, call)]));
|
|
337
|
+
return { guards, guardFactories: [...factories.values()], guardCalls: calls, guardLabels };
|
|
338
|
+
};
|
|
339
|
+
return { guardsIn, guardsOf };
|
|
340
|
+
};
|
|
341
|
+
|
|
342
|
+
// pkgs/@akanjs/language/escapeRegExp.ts
|
|
343
|
+
var regExpSpecials = /[\\^$.*+?()[\]{}|]/g;
|
|
344
|
+
var escapeRegExp = (text) => text.replace(regExpSpecials, (special) => `\\${special}`);
|
|
345
|
+
|
|
75
346
|
// pkgs/@akanjs/language/moduleFacts.ts
|
|
76
347
|
var testFilePattern = /\.(?:test|spec)\.tsx?$/;
|
|
77
348
|
var moduleCallees = new Set([
|
|
@@ -140,21 +411,6 @@ var createFactReader = (ts, ast) => {
|
|
|
140
411
|
const value = unwrap(expression);
|
|
141
412
|
return ts.isPropertyAccessExpression(value) && ts.isIdentifier(value.expression) ? `${value.expression.text}.${value.name.text}` : ast.expressionName(value);
|
|
142
413
|
};
|
|
143
|
-
const guardsIn = (object) => {
|
|
144
|
-
const guards = object?.properties.find((property) => ts.isPropertyAssignment(property) && ast.nodeName(property.name) === "guards")?.initializer;
|
|
145
|
-
if (!guards)
|
|
146
|
-
return [];
|
|
147
|
-
if (ts.isArrayLiteralExpression(guards))
|
|
148
|
-
return guards.elements.map(guardNameOf).filter((name) => name !== null);
|
|
149
|
-
if (ts.isObjectLiteralExpression(guards))
|
|
150
|
-
return guards.properties.filter(ts.isPropertyAssignment).flatMap((property) => {
|
|
151
|
-
const value = unwrap(property.initializer);
|
|
152
|
-
const names = ts.isArrayLiteralExpression(value) ? value.elements.map(guardNameOf) : [guardNameOf(value)];
|
|
153
|
-
return names.map((name) => `${ast.nodeName(property.name)} ${name ?? "?"}`);
|
|
154
|
-
});
|
|
155
|
-
const single = guardNameOf(guards);
|
|
156
|
-
return single ? [single] : [];
|
|
157
|
-
};
|
|
158
414
|
const optionObjectOf = (call) => call.arguments.find((arg) => ts.isObjectLiteralExpression(arg) && arg.properties.some((property) => ast.propertyName(property) === "guards"));
|
|
159
415
|
const chainOf = (initializer) => {
|
|
160
416
|
let root = unwrap(initializer);
|
|
@@ -171,7 +427,7 @@ var createFactReader = (ts, ast) => {
|
|
|
171
427
|
const node = keyName(property);
|
|
172
428
|
return name && node ? [{ name, span: spanOf(source, node), extent: extentOf(source, property) }] : [];
|
|
173
429
|
});
|
|
174
|
-
const sliceKeysOf = (source, builder) => (returnedObject(builder)?.properties ?? []).flatMap((property) => {
|
|
430
|
+
const sliceKeysOf = (source, builder, made, model) => (returnedObject(builder)?.properties ?? []).flatMap((property) => {
|
|
175
431
|
if (!ts.isPropertyAssignment(property))
|
|
176
432
|
return [];
|
|
177
433
|
const name = ast.nodeName(property.name);
|
|
@@ -183,7 +439,7 @@ var createFactReader = (ts, ast) => {
|
|
|
183
439
|
name,
|
|
184
440
|
span: spanOf(source, property.name),
|
|
185
441
|
extent: extentOf(source, property),
|
|
186
|
-
guards: root ? guardsIn(optionObjectOf(root)) : [],
|
|
442
|
+
guards: root ? guardsIn(source, optionObjectOf(root), made, `${model}.${name}`) : [],
|
|
187
443
|
live: methods.includes("live"),
|
|
188
444
|
argCount: methods.filter((method) => argMethods.has(method)).length
|
|
189
445
|
}
|
|
@@ -233,7 +489,7 @@ var createFactReader = (ts, ast) => {
|
|
|
233
489
|
const [size, unit] = intervalUnits.find(([size]) => ms >= size && ms % size === 0) ?? [1, "ms"];
|
|
234
490
|
return `${ms / size}${unit}`;
|
|
235
491
|
};
|
|
236
|
-
const modesOf = (option) => {
|
|
492
|
+
const modesOf = (option, type) => {
|
|
237
493
|
const object = option && unwrap(option);
|
|
238
494
|
if (!object || !ts.isObjectLiteralExpression(object))
|
|
239
495
|
return [];
|
|
@@ -243,9 +499,9 @@ var createFactReader = (ts, ast) => {
|
|
|
243
499
|
if (name === "enabled")
|
|
244
500
|
return value.kind === ts.SyntaxKind.FalseKeyword ? ["disabled"] : [];
|
|
245
501
|
if (name === "once")
|
|
246
|
-
return value.kind === ts.SyntaxKind.TrueKeyword ? ["once"] : [];
|
|
502
|
+
return type === "initialize" && value.kind === ts.SyntaxKind.TrueKeyword ? ["once"] : [];
|
|
247
503
|
if (name === "lock")
|
|
248
|
-
return value.kind === ts.SyntaxKind.FalseKeyword ? ["unlocked"] : [];
|
|
504
|
+
return type === "interval" && value.kind === ts.SyntaxKind.FalseKeyword ? ["unlocked"] : [];
|
|
249
505
|
if (name !== "serverMode" && name !== "operationMode")
|
|
250
506
|
return [];
|
|
251
507
|
const values = ts.isArrayLiteralExpression(value) ? [...value.elements] : [value];
|
|
@@ -263,7 +519,8 @@ var createFactReader = (ts, ast) => {
|
|
|
263
519
|
const { root } = chainOf(property.initializer);
|
|
264
520
|
const type = root ? verbOf(root.expression) : null;
|
|
265
521
|
const [first, second] = root?.arguments ?? [];
|
|
266
|
-
const
|
|
522
|
+
const cron = type === "cron" && first ? unwrap(first) : null;
|
|
523
|
+
const schedule = cron ? ts.isStringLiteralLike(cron) ? cron.text : cron.getText(source) : type === "interval" || type === "timeout" ? durationOf(first, source) : null;
|
|
267
524
|
const option = type === "initialize" || type === "destroy" ? first : second;
|
|
268
525
|
return [
|
|
269
526
|
{
|
|
@@ -272,7 +529,7 @@ var createFactReader = (ts, ast) => {
|
|
|
272
529
|
extent: extentOf(source, property),
|
|
273
530
|
type,
|
|
274
531
|
schedule,
|
|
275
|
-
modes: modesOf(option)
|
|
532
|
+
modes: modesOf(option, type)
|
|
276
533
|
}
|
|
277
534
|
];
|
|
278
535
|
});
|
|
@@ -289,7 +546,20 @@ var createFactReader = (ts, ast) => {
|
|
|
289
546
|
return name && targetName ? [{ name, span: spanOf(source, property.name), target: targetName }] : [];
|
|
290
547
|
});
|
|
291
548
|
};
|
|
292
|
-
const
|
|
549
|
+
const adaptorBindingsIn = (source) => {
|
|
550
|
+
const bindings = [];
|
|
551
|
+
const visit = (node) => {
|
|
552
|
+
if (ts.isCallExpression(node) && ts.isPropertyAccessExpression(node.expression) && node.expression.name.text === "applyAdaptor") {
|
|
553
|
+
const [role, adaptor] = node.arguments.map(guardNameOf);
|
|
554
|
+
if (role && adaptor)
|
|
555
|
+
bindings.push({ role, adaptor, span: spanOf(source, node.expression.name) });
|
|
556
|
+
}
|
|
557
|
+
ts.forEachChild(node, visit);
|
|
558
|
+
};
|
|
559
|
+
visit(source);
|
|
560
|
+
return bindings;
|
|
561
|
+
};
|
|
562
|
+
const endpointKeysOf = (source, builder, made, model) => {
|
|
293
563
|
const verbOf = verbReaderOf(builder?.parameters[0]);
|
|
294
564
|
return (returnedObject(builder)?.properties ?? []).flatMap((property) => {
|
|
295
565
|
if (!ts.isPropertyAssignment(property))
|
|
@@ -304,7 +574,7 @@ var createFactReader = (ts, ast) => {
|
|
|
304
574
|
span: spanOf(source, property.name),
|
|
305
575
|
extent: extentOf(source, property),
|
|
306
576
|
verb: root ? verbOf(root.expression) : null,
|
|
307
|
-
guards: root ? guardsIn(optionObjectOf(root)) : [],
|
|
577
|
+
guards: root ? guardsIn(source, optionObjectOf(root), made, `${model}.${name}`) : [],
|
|
308
578
|
argCount: methods.filter((method) => argMethods.has(method)).length
|
|
309
579
|
}
|
|
310
580
|
];
|
|
@@ -371,22 +641,6 @@ var createFactReader = (ts, ast) => {
|
|
|
371
641
|
})) : []
|
|
372
642
|
];
|
|
373
643
|
};
|
|
374
|
-
const implementsGuard = (node, guardNames) => !!node.heritageClauses?.some((clause) => clause.token === ts.SyntaxKind.ImplementsKeyword && clause.types.some(({ expression }) => guardNames.has(ast.expressionName(expression) ?? "")));
|
|
375
|
-
const guardClassIn = (node, guardNames) => {
|
|
376
|
-
if ((ts.isClassExpression(node) || ts.isClassDeclaration(node)) && implementsGuard(node, guardNames))
|
|
377
|
-
return node;
|
|
378
|
-
return ts.forEachChild(node, (child) => guardClassIn(child, guardNames)) ?? null;
|
|
379
|
-
};
|
|
380
|
-
const callsIn = (node, names) => {
|
|
381
|
-
if (ts.isCallExpression(node) && ts.isIdentifier(node.expression) && names.has(node.expression.text))
|
|
382
|
-
return node.expression.text;
|
|
383
|
-
return ts.forEachChild(node, (child) => callsIn(child, names)) ?? null;
|
|
384
|
-
};
|
|
385
|
-
const scopeOf = (node) => {
|
|
386
|
-
const scope = node.members.find((member) => ts.isPropertyDeclaration(member) && ast.nodeName(member.name) === "scope" && !!ts.getModifiers(member)?.some(({ kind }) => kind === ts.SyntaxKind.StaticKeyword))?.initializer;
|
|
387
|
-
const value = scope && unwrap(scope);
|
|
388
|
-
return value && ts.isStringLiteralLike(value) ? value.text : null;
|
|
389
|
-
};
|
|
390
644
|
const docOf = (source, node) => {
|
|
391
645
|
const { text } = source;
|
|
392
646
|
const ranges = ts.getLeadingCommentRanges(text, node.getFullStart()) ?? [];
|
|
@@ -402,108 +656,20 @@ var createFactReader = (ts, ast) => {
|
|
|
402
656
|
`)).map((line) => line.trim().replace(/^\/\*\*?|\*\/$/g, "").replace(/^(?:\/\/[?*!]?|\*)/, "").replace(/\{@link\s+([^}\s|]+)[^}]*\}/g, "$1").trim()).filter((line) => line && !/^(?:biome-ignore|eslint-|@ts-)/.test(line));
|
|
403
657
|
return lines.length ? lines.join(" ") : null;
|
|
404
658
|
};
|
|
405
|
-
const
|
|
406
|
-
const functions = new Map;
|
|
407
|
-
for (const statement of source.statements) {
|
|
408
|
-
if (ts.isFunctionDeclaration(statement) && statement.name && statement.body)
|
|
409
|
-
functions.set(statement.name.text, { statement, name: statement.name, body: statement.body });
|
|
410
|
-
if (!ts.isVariableStatement(statement))
|
|
411
|
-
continue;
|
|
412
|
-
for (const declaration of statement.declarationList.declarations) {
|
|
413
|
-
const initializer = declaration.initializer && unwrap(declaration.initializer);
|
|
414
|
-
if (initializer && ts.isIdentifier(declaration.name) && (ts.isArrowFunction(initializer) || ts.isFunctionExpression(initializer)))
|
|
415
|
-
functions.set(declaration.name.text, { statement, name: declaration.name, body: initializer.body });
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
return functions;
|
|
419
|
-
};
|
|
420
|
-
const guardFactoriesOf = (source, guardNames) => {
|
|
421
|
-
const functions = functionsOf(source);
|
|
422
|
-
const factories = new Map;
|
|
423
|
-
const factoryOf = (name, scope, via) => {
|
|
424
|
-
const found = functions.get(name);
|
|
425
|
-
if (!found)
|
|
426
|
-
return;
|
|
427
|
-
factories.set(name, {
|
|
428
|
-
name,
|
|
429
|
-
span: spanOf(source, found.name),
|
|
430
|
-
extent: extentOf(source, found.statement),
|
|
431
|
-
scope,
|
|
432
|
-
doc: docOf(source, found.statement),
|
|
433
|
-
via
|
|
434
|
-
});
|
|
435
|
-
};
|
|
436
|
-
for (const [name, { body }] of functions) {
|
|
437
|
-
const guard = guardClassIn(body, guardNames);
|
|
438
|
-
if (guard)
|
|
439
|
-
factoryOf(name, scopeOf(guard), null);
|
|
440
|
-
}
|
|
441
|
-
for (let isGrowing = true;isGrowing; ) {
|
|
442
|
-
isGrowing = false;
|
|
443
|
-
for (const [name, { body }] of functions) {
|
|
444
|
-
const called = factories.has(name) ? null : callsIn(body, new Set(factories.keys()));
|
|
445
|
-
if (!called)
|
|
446
|
-
continue;
|
|
447
|
-
factoryOf(name, factories.get(called)?.scope ?? null, called);
|
|
448
|
-
isGrowing = true;
|
|
449
|
-
}
|
|
450
|
-
}
|
|
451
|
-
return factories;
|
|
452
|
-
};
|
|
453
|
-
const guardsOf = (source, imports) => {
|
|
454
|
-
const guardNames = new Set([
|
|
455
|
-
"Guard",
|
|
456
|
-
...imports.filter(({ imported }) => imported === "Guard").map(({ name }) => name)
|
|
457
|
-
]);
|
|
458
|
-
const imported = new Set(imports.map(({ name }) => name));
|
|
459
|
-
const factories = guardFactoriesOf(source, guardNames);
|
|
460
|
-
const guards = [];
|
|
461
|
-
const calls = [];
|
|
462
|
-
for (const statement of source.statements) {
|
|
463
|
-
if (ts.isClassDeclaration(statement) && statement.name && implementsGuard(statement, guardNames))
|
|
464
|
-
guards.push({
|
|
465
|
-
name: statement.name.text,
|
|
466
|
-
span: spanOf(source, statement.name),
|
|
467
|
-
extent: extentOf(source, statement),
|
|
468
|
-
scope: scopeOf(statement),
|
|
469
|
-
doc: docOf(source, statement),
|
|
470
|
-
factory: null
|
|
471
|
-
});
|
|
472
|
-
if (!ts.isVariableStatement(statement))
|
|
473
|
-
continue;
|
|
474
|
-
for (const declaration of statement.declarationList.declarations) {
|
|
475
|
-
const initializer = declaration.initializer && unwrap(declaration.initializer);
|
|
476
|
-
if (!initializer || !ts.isIdentifier(declaration.name))
|
|
477
|
-
continue;
|
|
478
|
-
const made = {
|
|
479
|
-
name: declaration.name.text,
|
|
480
|
-
span: spanOf(source, declaration.name),
|
|
481
|
-
extent: extentOf(source, statement),
|
|
482
|
-
doc: docOf(source, statement)
|
|
483
|
-
};
|
|
484
|
-
if (ts.isClassExpression(initializer) && implementsGuard(initializer, guardNames))
|
|
485
|
-
guards.push({ ...made, scope: scopeOf(initializer), factory: null });
|
|
486
|
-
if (!ts.isCallExpression(initializer) || !ts.isIdentifier(initializer.expression))
|
|
487
|
-
continue;
|
|
488
|
-
const callee = initializer.expression.text;
|
|
489
|
-
const factory = factories.get(callee);
|
|
490
|
-
if (factory)
|
|
491
|
-
guards.push({ ...made, scope: factory.scope, factory: callee });
|
|
492
|
-
else if (imported.has(callee))
|
|
493
|
-
calls.push({ ...made, callee });
|
|
494
|
-
}
|
|
495
|
-
}
|
|
496
|
-
return { guards, guardFactories: [...factories.values()], guardCalls: calls };
|
|
497
|
-
};
|
|
659
|
+
const { guardsIn, guardsOf } = createGuardFactReader(ts, ast, { spanOf, extentOf, unwrap, docOf });
|
|
498
660
|
const lowerFirst = (text) => text.charAt(0).toLowerCase() + text.slice(1);
|
|
499
661
|
const importsIn = (source) => source.statements.filter(ts.isImportDeclaration).flatMap(importsOf);
|
|
500
662
|
const read = (source, owner) => {
|
|
501
663
|
const imports = importsIn(source);
|
|
664
|
+
const madeInPlace = [];
|
|
502
665
|
const facts = {
|
|
503
666
|
fileName: source.fileName,
|
|
504
667
|
owner,
|
|
505
668
|
imports,
|
|
506
|
-
|
|
669
|
+
guards: [],
|
|
670
|
+
guardFactories: [],
|
|
671
|
+
guardCalls: [],
|
|
672
|
+
guardLabels: {},
|
|
507
673
|
constants: [],
|
|
508
674
|
enums: [],
|
|
509
675
|
filters: [],
|
|
@@ -513,6 +679,7 @@ var createFactReader = (ts, ast) => {
|
|
|
513
679
|
endpoints: [],
|
|
514
680
|
internals: [],
|
|
515
681
|
adaptors: [],
|
|
682
|
+
adaptorBindings: source.text.includes("applyAdaptor") ? adaptorBindingsIn(source) : [],
|
|
516
683
|
stores: []
|
|
517
684
|
};
|
|
518
685
|
for (const statement of source.statements) {
|
|
@@ -537,16 +704,19 @@ var createFactReader = (ts, ast) => {
|
|
|
537
704
|
...name,
|
|
538
705
|
model: moduleRefOf(call.arguments[0], "db"),
|
|
539
706
|
methods: methodsOf(source, statement),
|
|
540
|
-
plugs: plugsOf(source, builder)
|
|
707
|
+
plugs: plugsOf(source, builder),
|
|
708
|
+
fields: objectKeys(source, returnedObject(builder)).map(({ name }) => name)
|
|
541
709
|
});
|
|
542
|
-
else if (callee === "slice")
|
|
710
|
+
else if (callee === "slice") {
|
|
711
|
+
const model = moduleRefOf(call.arguments[0], "srv");
|
|
712
|
+
const member = model ?? name.name;
|
|
543
713
|
facts.slices.push({
|
|
544
714
|
...name,
|
|
545
|
-
model
|
|
546
|
-
guards: guardsIn(call.arguments.find(ts.isObjectLiteralExpression)),
|
|
547
|
-
keys: sliceKeysOf(source, builder)
|
|
715
|
+
model,
|
|
716
|
+
guards: guardsIn(source, call.arguments.find(ts.isObjectLiteralExpression), madeInPlace, member),
|
|
717
|
+
keys: sliceKeysOf(source, builder, madeInPlace, member)
|
|
548
718
|
});
|
|
549
|
-
else if (callee === "internal")
|
|
719
|
+
} else if (callee === "internal")
|
|
550
720
|
facts.internals.push({
|
|
551
721
|
...name,
|
|
552
722
|
model: moduleRefOf(call.arguments[0], "srv"),
|
|
@@ -561,13 +731,14 @@ var createFactReader = (ts, ast) => {
|
|
|
561
731
|
plugs: plugsOf(source, builder),
|
|
562
732
|
doc: docOf(source, statement)
|
|
563
733
|
});
|
|
564
|
-
} else if (callee === "endpoint")
|
|
734
|
+
} else if (callee === "endpoint") {
|
|
735
|
+
const model = moduleRefOf(call.arguments[0], "srv");
|
|
565
736
|
facts.endpoints.push({
|
|
566
737
|
...name,
|
|
567
|
-
model
|
|
568
|
-
keys: endpointKeysOf(source, builder)
|
|
738
|
+
model,
|
|
739
|
+
keys: endpointKeysOf(source, builder, madeInPlace, model ?? name.name)
|
|
569
740
|
});
|
|
570
|
-
else if (callee === "store")
|
|
741
|
+
} else if (callee === "store")
|
|
571
742
|
facts.stores.push({
|
|
572
743
|
...name,
|
|
573
744
|
model: moduleRefOf(call.arguments[0], "sig"),
|
|
@@ -575,10 +746,439 @@ var createFactReader = (ts, ast) => {
|
|
|
575
746
|
actions: methodsOf(source, statement)
|
|
576
747
|
});
|
|
577
748
|
}
|
|
578
|
-
return facts;
|
|
579
|
-
};
|
|
580
|
-
return { read, spanOf, extentOf, docOf, importsIn, moduleRefOf, chainOf, unwrap };
|
|
581
|
-
};
|
|
749
|
+
return { ...facts, ...guardsOf(source, imports, madeInPlace) };
|
|
750
|
+
};
|
|
751
|
+
return { read, spanOf, extentOf, docOf, importsIn, moduleRefOf, chainOf, unwrap };
|
|
752
|
+
};
|
|
753
|
+
|
|
754
|
+
// pkgs/@akanjs/language/guardResolver.ts
|
|
755
|
+
var frameworkOwner = "akanjs";
|
|
756
|
+
var frameworkPattern = /^akanjs(?:\/|$)/;
|
|
757
|
+
var aliasPattern = /^@(apps|libs)\/([^/]+)/;
|
|
758
|
+
var maxMapDepth = 4;
|
|
759
|
+
var starExportPattern = /export\s*\*\s*from\s*["']([^"']+)["']/g;
|
|
760
|
+
var declaringPatternOf = (name, isAnyBinding) => {
|
|
761
|
+
const escaped = escapeRegExp(name);
|
|
762
|
+
const braced = "\\{(?:[^}]*?[\\s,])?";
|
|
763
|
+
const leads = [
|
|
764
|
+
"function\\s*\\*?\\s*",
|
|
765
|
+
"(?:const|let|var)\\s+",
|
|
766
|
+
`export\\s*${braced}`,
|
|
767
|
+
...isAnyBinding ? ["class\\s+", `(?:const|let|var)\\s*${braced}`] : []
|
|
768
|
+
];
|
|
769
|
+
return new RegExp(`(?:${leads.join("|")})${escaped}(?![\\w$])|,\\s*${escaped}\\s*(?::[^=;,]+)?=(?![=>])`);
|
|
770
|
+
};
|
|
771
|
+
|
|
772
|
+
class GuardResolver {
|
|
773
|
+
#source;
|
|
774
|
+
#routes;
|
|
775
|
+
#guards = new Map;
|
|
776
|
+
#madeInPlace = new Map;
|
|
777
|
+
#mapEntries = new Map;
|
|
778
|
+
#reexports = new Map;
|
|
779
|
+
#declarations = new Map;
|
|
780
|
+
#starExports = new Map;
|
|
781
|
+
#ownerFiles = null;
|
|
782
|
+
#modules = null;
|
|
783
|
+
constructor(source, routes) {
|
|
784
|
+
this.#source = source;
|
|
785
|
+
this.#routes = routes;
|
|
786
|
+
}
|
|
787
|
+
find(local, site) {
|
|
788
|
+
return this.#findGuard(local, site, 0);
|
|
789
|
+
}
|
|
790
|
+
madeInPlace(fileName, name) {
|
|
791
|
+
return this.#madeInPlace.get(`${fileName}
|
|
792
|
+
${name}`);
|
|
793
|
+
}
|
|
794
|
+
declare(facts) {
|
|
795
|
+
const factories = new Map;
|
|
796
|
+
const declaredFactories = [];
|
|
797
|
+
for (const file of facts)
|
|
798
|
+
for (const fact of file.guardFactories) {
|
|
799
|
+
const factory = {
|
|
800
|
+
fact,
|
|
801
|
+
owner: file.owner,
|
|
802
|
+
site: file,
|
|
803
|
+
made: [],
|
|
804
|
+
isReal: fact.direct,
|
|
805
|
+
scope: fact.scope,
|
|
806
|
+
targets: []
|
|
807
|
+
};
|
|
808
|
+
factories.set(fact.name, [...factories.get(fact.name) ?? [], factory]);
|
|
809
|
+
declaredFactories.push(factory);
|
|
810
|
+
}
|
|
811
|
+
for (const factory of declaredFactories)
|
|
812
|
+
factory.targets = factory.fact.via.map((callee) => this.#factoryAt(factories, callee, factory.site)).filter((target) => target !== undefined);
|
|
813
|
+
for (let isGrowing = true;isGrowing; ) {
|
|
814
|
+
isGrowing = false;
|
|
815
|
+
for (const factory of declaredFactories) {
|
|
816
|
+
const target = factory.targets.find((other) => other.isReal);
|
|
817
|
+
if (factory.isReal || !target)
|
|
818
|
+
continue;
|
|
819
|
+
factory.isReal = true;
|
|
820
|
+
factory.scope ??= target.scope;
|
|
821
|
+
isGrowing = true;
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
const partsOf = (factory, seen = new Set) => {
|
|
825
|
+
if (seen.has(factory))
|
|
826
|
+
return [];
|
|
827
|
+
seen.add(factory);
|
|
828
|
+
return [
|
|
829
|
+
{ fileName: factory.site.fileName, extent: factory.fact.extent },
|
|
830
|
+
...factory.targets.filter((target) => target.isReal).flatMap((target) => partsOf(target, seen))
|
|
831
|
+
];
|
|
832
|
+
};
|
|
833
|
+
const declare = (file, made, scope, parts) => {
|
|
834
|
+
const { name, span, extent, doc } = made;
|
|
835
|
+
const label = file.guardLabels[name];
|
|
836
|
+
const own = { fileName: file.fileName, extent };
|
|
837
|
+
const guard = { name, owner: file.owner, span, scope, doc, parts: [own, ...parts], file: null, label };
|
|
838
|
+
if (name.includes("@"))
|
|
839
|
+
this.#madeInPlace.set(`${file.fileName}
|
|
840
|
+
${name}`, guard);
|
|
841
|
+
else
|
|
842
|
+
this.#guards.set(name, [...this.#guards.get(name) ?? [], guard]);
|
|
843
|
+
return guard;
|
|
844
|
+
};
|
|
845
|
+
const extending = [];
|
|
846
|
+
for (const file of facts) {
|
|
847
|
+
for (const made of file.guards) {
|
|
848
|
+
const factory = made.factory ? factories.get(made.factory)?.find((other) => other.site.fileName === file.fileName) : undefined;
|
|
849
|
+
if (!made.factory)
|
|
850
|
+
declare(file, made, made.scope, []);
|
|
851
|
+
else if (factory?.isReal)
|
|
852
|
+
factory.made.push(declare(file, made, factory.scope, partsOf(factory)));
|
|
853
|
+
}
|
|
854
|
+
for (const made of file.guardCalls) {
|
|
855
|
+
if (made.kind === "extends") {
|
|
856
|
+
extending.push([file, made]);
|
|
857
|
+
continue;
|
|
858
|
+
}
|
|
859
|
+
const factory = this.#factoryAt(factories, made.callee, file);
|
|
860
|
+
if (factory?.isReal)
|
|
861
|
+
factory.made.push(declare(file, made, factory.scope, partsOf(factory)));
|
|
862
|
+
}
|
|
863
|
+
}
|
|
864
|
+
for (let isGrowing = true;isGrowing; ) {
|
|
865
|
+
isGrowing = false;
|
|
866
|
+
for (const [idx, entry] of extending.entries()) {
|
|
867
|
+
const [file, made] = entry;
|
|
868
|
+
const found = this.#findGuard(made.callee, file, 0, true);
|
|
869
|
+
if (!("guard" in found))
|
|
870
|
+
continue;
|
|
871
|
+
declare(file, made, made.scope ?? found.guard.scope, found.guard.parts);
|
|
872
|
+
extending.splice(idx, 1);
|
|
873
|
+
isGrowing = true;
|
|
874
|
+
break;
|
|
875
|
+
}
|
|
876
|
+
}
|
|
877
|
+
for (const { fact, made, isReal } of declaredFactories)
|
|
878
|
+
if (isReal && made.every((guard) => !guard.doc))
|
|
879
|
+
for (const guard of made)
|
|
880
|
+
guard.doc = fact.doc;
|
|
881
|
+
for (const list of this.#guards.values())
|
|
882
|
+
for (const guard of list)
|
|
883
|
+
if (list.some((other) => other !== guard && other.owner === guard.owner))
|
|
884
|
+
guard.file = this.inOwner(guard.span.fileName, guard.owner);
|
|
885
|
+
for (const guard of this.#madeInPlace.values())
|
|
886
|
+
guard.file = this.inOwner(guard.span.fileName, guard.owner);
|
|
887
|
+
return [...[...this.#guards.values()].flat(), ...this.#madeInPlace.values()];
|
|
888
|
+
}
|
|
889
|
+
#factoryAt(factories, callee, site, depth = 0) {
|
|
890
|
+
const [head = callee, member] = callee.split(".");
|
|
891
|
+
const imported = site.imports.find((item) => item.name === head);
|
|
892
|
+
if (!imported)
|
|
893
|
+
return member ? undefined : factories.get(callee)?.find((other) => other.site.fileName === site.fileName);
|
|
894
|
+
if (member && imported.imported !== "*")
|
|
895
|
+
return;
|
|
896
|
+
const from = this.ownerOfSpecifier(site.fileName, imported.from);
|
|
897
|
+
if (from === undefined || from === frameworkOwner)
|
|
898
|
+
return;
|
|
899
|
+
const name = member ?? (imported.imported === "default" || imported.imported === "*" ? head : imported.imported);
|
|
900
|
+
const candidates = factories.get(name) ?? [];
|
|
901
|
+
const near = this.pathOfSpecifier(site.fileName, imported.from);
|
|
902
|
+
const own = this.#nearest(candidates.filter((other) => other.owner === from), ({ site }) => site.fileName, near);
|
|
903
|
+
if (own)
|
|
904
|
+
return own;
|
|
905
|
+
const reexport = from && depth < maxMapDepth ? this.reexportOf(from, name, near) : null;
|
|
906
|
+
if (reexport)
|
|
907
|
+
return this.#factoryAt(factories, reexport.local, reexport.site, depth + 1);
|
|
908
|
+
return from && near ? this.#throughStar(candidates, from, name, near) : undefined;
|
|
909
|
+
}
|
|
910
|
+
#findGuard(local, site, depth, isBase = false) {
|
|
911
|
+
const segments = local.split(".");
|
|
912
|
+
const head = segments[0] ?? local;
|
|
913
|
+
const imported = site.imports.find((item) => item.name === head);
|
|
914
|
+
const from = imported ? this.ownerOfSpecifier(site.fileName, imported.from) : undefined;
|
|
915
|
+
if (imported && from === undefined)
|
|
916
|
+
return { external: true };
|
|
917
|
+
const near = imported ? this.pathOfSpecifier(site.fileName, imported.from) : this.#source.relative(site.fileName).replace(/\.tsx?$/, "");
|
|
918
|
+
const named = imported && imported.imported !== "default" && imported.imported !== "*" ? imported.imported : null;
|
|
919
|
+
const path = imported?.imported === "*" ? segments.slice(1) : [named ?? head, ...segments.slice(1)];
|
|
920
|
+
const holder = imported ? from ?? null : site.owner;
|
|
921
|
+
const [objectName, member] = path;
|
|
922
|
+
if (path.length === 2 && objectName && member && holder !== frameworkOwner && depth < maxMapDepth) {
|
|
923
|
+
const made = this.#nearest((this.#guards.get(`${objectName}.${member}`) ?? []).filter((guard) => guard.owner === holder), ({ span }) => span.fileName, near);
|
|
924
|
+
if (made)
|
|
925
|
+
return { guard: made };
|
|
926
|
+
for (const entry of this.#mapEntriesOf(objectName, member, imported ? null : site.fileName, holder)) {
|
|
927
|
+
const found = this.#findGuard(entry.name, entry.site, depth + 1, isBase);
|
|
928
|
+
if ("guard" in found)
|
|
929
|
+
return found;
|
|
930
|
+
}
|
|
931
|
+
}
|
|
932
|
+
const name = path[path.length - 1] ?? head;
|
|
933
|
+
if (from === frameworkOwner)
|
|
934
|
+
return { name, from };
|
|
935
|
+
const declared = this.#guards.get(name) ?? [];
|
|
936
|
+
const own = this.#nearest(declared.filter((other) => other.owner === (imported ? from : site.owner)), ({ span }) => span.fileName, near);
|
|
937
|
+
if (own)
|
|
938
|
+
return { guard: own };
|
|
939
|
+
if (!imported) {
|
|
940
|
+
const visible = isBase ? undefined : declared.find((other) => this.visible(other.owner, site.owner));
|
|
941
|
+
return visible ? { guard: visible } : { name, from };
|
|
942
|
+
}
|
|
943
|
+
const reexport = from && depth < maxMapDepth ? this.reexportOf(from, name, near) : null;
|
|
944
|
+
if (reexport)
|
|
945
|
+
return this.#findGuard(reexport.local, reexport.site, depth + 1, isBase);
|
|
946
|
+
const reached = from && near ? this.#throughStar(declared, from, name, near) : undefined;
|
|
947
|
+
return reached ? { guard: reached } : { name, from };
|
|
948
|
+
}
|
|
949
|
+
reexportOf(owner, name, near) {
|
|
950
|
+
const key = `${owner}
|
|
951
|
+
${name}
|
|
952
|
+
${near ?? ""}`;
|
|
953
|
+
const cached = this.#reexports.get(key);
|
|
954
|
+
if (cached !== undefined)
|
|
955
|
+
return cached;
|
|
956
|
+
let found = null;
|
|
957
|
+
const exporting = new RegExp(`export\\s*\\{(?:[^}]*?[\\s,])?${escapeRegExp(name)}(?![\\w$])`);
|
|
958
|
+
for (const fileName of this.#filesOf(owner, name, near)) {
|
|
959
|
+
const text = this.#source.readText(fileName);
|
|
960
|
+
if (text === undefined || !exporting.test(text))
|
|
961
|
+
continue;
|
|
962
|
+
const reexport = this.#reexportIn(this.#source.parse(fileName, text), name);
|
|
963
|
+
if (!reexport)
|
|
964
|
+
continue;
|
|
965
|
+
const site = { fileName, owner, imports: [] };
|
|
966
|
+
found = reexport.from ? {
|
|
967
|
+
local: reexport.name,
|
|
968
|
+
site: { ...site, imports: [{ ...reexport, imported: reexport.name, from: reexport.from }] }
|
|
969
|
+
} : { local: reexport.name, site };
|
|
970
|
+
break;
|
|
971
|
+
}
|
|
972
|
+
this.#reexports.set(key, found);
|
|
973
|
+
return found;
|
|
974
|
+
}
|
|
975
|
+
#reexportIn(source, name) {
|
|
976
|
+
const { ts, reader } = this.#source;
|
|
977
|
+
for (const statement of source.statements) {
|
|
978
|
+
if (!ts.isExportDeclaration(statement) || statement.isTypeOnly)
|
|
979
|
+
continue;
|
|
980
|
+
const { exportClause, moduleSpecifier } = statement;
|
|
981
|
+
if (!exportClause || !ts.isNamedExports(exportClause))
|
|
982
|
+
continue;
|
|
983
|
+
const element = exportClause.elements.find((item) => !item.isTypeOnly && item.name.text === name);
|
|
984
|
+
if (!element)
|
|
985
|
+
continue;
|
|
986
|
+
const original = (element.propertyName ?? element.name).text;
|
|
987
|
+
if (moduleSpecifier && ts.isStringLiteral(moduleSpecifier))
|
|
988
|
+
return { name: original, from: moduleSpecifier.text };
|
|
989
|
+
const imported = reader.importsIn(source).find((item) => item.name === original);
|
|
990
|
+
if (!imported)
|
|
991
|
+
return { name: original, from: null };
|
|
992
|
+
return imported.imported === "default" || imported.imported === "*" ? null : { name: imported.imported, from: imported.from };
|
|
993
|
+
}
|
|
994
|
+
return null;
|
|
995
|
+
}
|
|
996
|
+
#filesOf(owner, name, near) {
|
|
997
|
+
const isNear = (fileName) => {
|
|
998
|
+
const relative = this.#source.relative(fileName);
|
|
999
|
+
return !!near && (relative.startsWith(`${near}/`) || relative.replace(/\.tsx?$/, "") === near);
|
|
1000
|
+
};
|
|
1001
|
+
const candidates = this.filesIn(owner).filter(([, words]) => words.includes(`
|
|
1002
|
+
${name}
|
|
1003
|
+
`)).map(([fileName]) => fileName);
|
|
1004
|
+
return [...candidates.filter(isNear), ...candidates.filter((other) => !isNear(other))];
|
|
1005
|
+
}
|
|
1006
|
+
#mapEntriesOf(objectName, member, fileName, owner) {
|
|
1007
|
+
const key = `${objectName}
|
|
1008
|
+
${member}
|
|
1009
|
+
${fileName ?? ""}
|
|
1010
|
+
${owner ?? ""}`;
|
|
1011
|
+
const cached = this.#mapEntries.get(key);
|
|
1012
|
+
if (cached)
|
|
1013
|
+
return cached;
|
|
1014
|
+
const { ts, reader } = this.#source;
|
|
1015
|
+
const entries = [];
|
|
1016
|
+
const fileNames = [
|
|
1017
|
+
...fileName ? [fileName] : [],
|
|
1018
|
+
...(owner === null ? [] : this.filesIn(owner)).filter(([other, words]) => other !== fileName && words.includes(`
|
|
1019
|
+
${objectName}
|
|
1020
|
+
`) && words.includes(`
|
|
1021
|
+
${member}
|
|
1022
|
+
`)).map(([other]) => other)
|
|
1023
|
+
];
|
|
1024
|
+
for (const holder of fileNames) {
|
|
1025
|
+
const text = this.#source.readText(holder);
|
|
1026
|
+
if (text === undefined)
|
|
1027
|
+
continue;
|
|
1028
|
+
const source = this.#source.parse(holder, text);
|
|
1029
|
+
const site = { fileName: holder, owner: this.#source.ownerOf(holder), imports: reader.importsIn(source) };
|
|
1030
|
+
for (const statement of source.statements) {
|
|
1031
|
+
if (!ts.isVariableStatement(statement))
|
|
1032
|
+
continue;
|
|
1033
|
+
const map = statement.declarationList.declarations.find((declaration) => ts.isIdentifier(declaration.name) && declaration.name.text === objectName)?.initializer;
|
|
1034
|
+
const object = map && reader.unwrap(map);
|
|
1035
|
+
if (!object || !ts.isObjectLiteralExpression(object))
|
|
1036
|
+
continue;
|
|
1037
|
+
for (const property of object.properties) {
|
|
1038
|
+
if (ts.isShorthandPropertyAssignment(property) && property.name.text === member)
|
|
1039
|
+
entries.push({ name: member, site });
|
|
1040
|
+
if (!ts.isPropertyAssignment(property) || !(ts.isIdentifier(property.name) || ts.isStringLiteral(property.name)) || property.name.text !== member)
|
|
1041
|
+
continue;
|
|
1042
|
+
const value = reader.unwrap(property.initializer);
|
|
1043
|
+
if (ts.isIdentifier(value))
|
|
1044
|
+
entries.push({ name: value.text, site });
|
|
1045
|
+
else if (ts.isPropertyAccessExpression(value) && ts.isIdentifier(value.expression))
|
|
1046
|
+
entries.push({ name: `${value.expression.text}.${value.name.text}`, site });
|
|
1047
|
+
}
|
|
1048
|
+
}
|
|
1049
|
+
}
|
|
1050
|
+
this.#mapEntries.set(key, entries);
|
|
1051
|
+
return entries;
|
|
1052
|
+
}
|
|
1053
|
+
declarationOf(owner, name, near, depth = 0) {
|
|
1054
|
+
const key = `${owner}
|
|
1055
|
+
${name}
|
|
1056
|
+
${near ?? ""}`;
|
|
1057
|
+
const cached = this.#declarations.get(key);
|
|
1058
|
+
if (cached !== undefined)
|
|
1059
|
+
return cached;
|
|
1060
|
+
this.#declarations.set(key, null);
|
|
1061
|
+
const declaring = declaringPatternOf(name, false);
|
|
1062
|
+
let found = null;
|
|
1063
|
+
for (const fileName of this.#filesOf(owner, name, near)) {
|
|
1064
|
+
const text = this.#source.readText(fileName);
|
|
1065
|
+
if (text === undefined || !declaring.test(text))
|
|
1066
|
+
continue;
|
|
1067
|
+
const source = this.#source.parse(fileName, text);
|
|
1068
|
+
const declared = this.#routes.declarationIn(source, name);
|
|
1069
|
+
if (declared) {
|
|
1070
|
+
found = { source, ...declared, name };
|
|
1071
|
+
break;
|
|
1072
|
+
}
|
|
1073
|
+
const reexport = this.#reexportIn(source, name);
|
|
1074
|
+
if (!reexport)
|
|
1075
|
+
continue;
|
|
1076
|
+
if (!reexport.from) {
|
|
1077
|
+
const local = this.#routes.declarationIn(source, reexport.name);
|
|
1078
|
+
found = local ? { source, ...local, name: reexport.name } : null;
|
|
1079
|
+
break;
|
|
1080
|
+
}
|
|
1081
|
+
const next = this.ownerOfSpecifier(fileName, reexport.from);
|
|
1082
|
+
if (next && next !== frameworkOwner && depth < maxMapDepth)
|
|
1083
|
+
found = this.declarationOf(next, reexport.name, this.pathOfSpecifier(fileName, reexport.from), depth + 1);
|
|
1084
|
+
break;
|
|
1085
|
+
}
|
|
1086
|
+
this.#declarations.set(key, found);
|
|
1087
|
+
return found;
|
|
1088
|
+
}
|
|
1089
|
+
#throughStar(declared, owner, name, near) {
|
|
1090
|
+
if (!declared.length)
|
|
1091
|
+
return;
|
|
1092
|
+
const { owners, isOpaque } = this.#starExportsOf(owner, near);
|
|
1093
|
+
const reached = declared.filter((other) => other.owner !== null && owners.includes(other.owner));
|
|
1094
|
+
return reached.length === 1 && !isOpaque && !this.declares(owner, name) ? reached[0] : undefined;
|
|
1095
|
+
}
|
|
1096
|
+
#starExportsOf(owner, near) {
|
|
1097
|
+
const cached = this.#starExports.get(near);
|
|
1098
|
+
if (cached)
|
|
1099
|
+
return cached;
|
|
1100
|
+
const found = { owners: [], isOpaque: false };
|
|
1101
|
+
this.#starExports.set(near, found);
|
|
1102
|
+
const paths = [near];
|
|
1103
|
+
for (let idx = 0;idx < paths.length && !found.isOpaque; idx++)
|
|
1104
|
+
for (const fileName of this.#modulesAt(paths[idx] ?? "")) {
|
|
1105
|
+
for (const [, specifier = ""] of this.#source.readText(fileName)?.matchAll(starExportPattern) ?? []) {
|
|
1106
|
+
const target = this.ownerOfSpecifier(fileName, specifier);
|
|
1107
|
+
const path = this.pathOfSpecifier(fileName, specifier);
|
|
1108
|
+
if (target === undefined || target === frameworkOwner || path === null)
|
|
1109
|
+
found.isOpaque = true;
|
|
1110
|
+
else if (!paths.includes(path))
|
|
1111
|
+
paths.push(path);
|
|
1112
|
+
if (target && target !== frameworkOwner && target !== owner && !found.owners.includes(target))
|
|
1113
|
+
found.owners.push(target);
|
|
1114
|
+
}
|
|
1115
|
+
}
|
|
1116
|
+
return found;
|
|
1117
|
+
}
|
|
1118
|
+
#modulesAt(path) {
|
|
1119
|
+
if (!this.#modules) {
|
|
1120
|
+
this.#modules = new Map;
|
|
1121
|
+
for (const [fileName] of this.#source.files) {
|
|
1122
|
+
const module = this.#source.relative(fileName).replace(/\.tsx?$/, "");
|
|
1123
|
+
for (const key of module.endsWith("/index") ? [module, module.slice(0, -6)] : [module])
|
|
1124
|
+
this.#modules.set(key, [...this.#modules.get(key) ?? [], fileName]);
|
|
1125
|
+
}
|
|
1126
|
+
}
|
|
1127
|
+
return this.#modules.get(path) ?? [];
|
|
1128
|
+
}
|
|
1129
|
+
declares(owner, name) {
|
|
1130
|
+
const declaring = declaringPatternOf(name, true);
|
|
1131
|
+
return this.#filesOf(owner, name, null).some((fileName) => declaring.test(this.#source.readText(fileName) ?? ""));
|
|
1132
|
+
}
|
|
1133
|
+
filesIn(owner) {
|
|
1134
|
+
if (!this.#ownerFiles) {
|
|
1135
|
+
this.#ownerFiles = new Map;
|
|
1136
|
+
for (const entry of this.#source.files) {
|
|
1137
|
+
const fileOwner = testFilePattern.test(entry[0]) ? null : this.#source.ownerOf(entry[0]);
|
|
1138
|
+
const files = fileOwner === null ? null : this.#ownerFiles.get(fileOwner);
|
|
1139
|
+
if (files)
|
|
1140
|
+
files.push(entry);
|
|
1141
|
+
else if (fileOwner !== null)
|
|
1142
|
+
this.#ownerFiles.set(fileOwner, [entry]);
|
|
1143
|
+
}
|
|
1144
|
+
}
|
|
1145
|
+
return this.#ownerFiles.get(owner) ?? [];
|
|
1146
|
+
}
|
|
1147
|
+
#nearest(items, fileOf, near) {
|
|
1148
|
+
const isNear = (fileName) => {
|
|
1149
|
+
const relative = this.#source.relative(fileName);
|
|
1150
|
+
return !!near && (relative.startsWith(`${near}/`) || relative.replace(/\.tsx?$/, "") === near);
|
|
1151
|
+
};
|
|
1152
|
+
return items.find((item) => isNear(fileOf(item))) ?? items[0];
|
|
1153
|
+
}
|
|
1154
|
+
inOwner(fileName, owner) {
|
|
1155
|
+
const relative = this.#source.relative(fileName);
|
|
1156
|
+
return owner && relative.startsWith(`${owner}/`) ? relative.slice(owner.length + 1) : relative;
|
|
1157
|
+
}
|
|
1158
|
+
ownerOfSpecifier(fileName, specifier) {
|
|
1159
|
+
if (frameworkPattern.test(specifier))
|
|
1160
|
+
return frameworkOwner;
|
|
1161
|
+
const path = this.pathOfSpecifier(fileName, specifier);
|
|
1162
|
+
return path === null ? undefined : ownerOf(path) ?? undefined;
|
|
1163
|
+
}
|
|
1164
|
+
pathOfSpecifier(fileName, specifier) {
|
|
1165
|
+
const alias = specifier.match(aliasPattern);
|
|
1166
|
+
if (alias)
|
|
1167
|
+
return `${alias[1]}/${alias[2]}${specifier.slice(alias[0].length)}`;
|
|
1168
|
+
if (!specifier.startsWith("."))
|
|
1169
|
+
return null;
|
|
1170
|
+
const segments = this.#source.relative(fileName).split("/").slice(0, -1);
|
|
1171
|
+
for (const segment of specifier.split("/"))
|
|
1172
|
+
if (segment === "..")
|
|
1173
|
+
segments.pop();
|
|
1174
|
+
else if (segment !== ".")
|
|
1175
|
+
segments.push(segment);
|
|
1176
|
+
return segments.join("/");
|
|
1177
|
+
}
|
|
1178
|
+
visible(target, from) {
|
|
1179
|
+
return !from || !target || target === from || target.startsWith("libs/");
|
|
1180
|
+
}
|
|
1181
|
+
}
|
|
582
1182
|
|
|
583
1183
|
// pkgs/@akanjs/language/routeFacts.ts
|
|
584
1184
|
import { normalizeRoutePattern, tryParseRouteModuleKey } from "akanjs/common/routeConvention.ts";
|
|
@@ -634,24 +1234,23 @@ rootLayout
|
|
|
634
1234
|
}
|
|
635
1235
|
declarationIn(source, name) {
|
|
636
1236
|
const ts = this.#ts;
|
|
1237
|
+
const overloads = source.statements.filter((statement) => ts.isFunctionDeclaration(statement) && statement.name?.text === name);
|
|
1238
|
+
const [first] = overloads;
|
|
1239
|
+
const last = overloads.at(-1);
|
|
1240
|
+
if (first?.name && last)
|
|
1241
|
+
return { statement: first, declared: first.name, extent: { start: first.getStart(source), end: last.getEnd() } };
|
|
637
1242
|
for (const statement of source.statements) {
|
|
638
|
-
if (ts.isFunctionDeclaration(statement) && statement.name?.text === name)
|
|
639
|
-
return { statement, declared: statement.name, initializer: null };
|
|
640
1243
|
if (!ts.isVariableStatement(statement))
|
|
641
1244
|
continue;
|
|
642
1245
|
const declaration = statement.declarationList.declarations.find((item) => ts.isIdentifier(item.name) && item.name.text === name);
|
|
643
1246
|
if (declaration)
|
|
644
|
-
return { statement, declared: declaration.name,
|
|
1247
|
+
return { statement, declared: declaration.name, extent: this.#reader.extentOf(source, statement) };
|
|
645
1248
|
}
|
|
646
1249
|
return null;
|
|
647
1250
|
}
|
|
648
1251
|
#guardOf(source, exported) {
|
|
649
1252
|
const ts = this.#ts;
|
|
650
1253
|
let current = ts.isExportAssignment(exported) ? this.#reader.unwrap(exported.expression) : null;
|
|
651
|
-
if (current && ts.isIdentifier(current)) {
|
|
652
|
-
const initializer = this.declarationIn(source, current.text)?.initializer;
|
|
653
|
-
current = initializer ? this.#reader.unwrap(initializer) : null;
|
|
654
|
-
}
|
|
655
1254
|
while (current && ts.isCallExpression(current) && ts.isPropertyAccessExpression(current.expression)) {
|
|
656
1255
|
const { name, expression } = current.expression;
|
|
657
1256
|
const [stage] = current.arguments;
|
|
@@ -663,9 +1262,20 @@ rootLayout
|
|
|
663
1262
|
}
|
|
664
1263
|
#callsIn(source, stage) {
|
|
665
1264
|
const ts = this.#ts;
|
|
666
|
-
const
|
|
1265
|
+
const imports = this.#reader.importsIn(source).filter(({ from }) => RouteFactReader.#workspacePattern.test(from));
|
|
1266
|
+
const imported = new Set(imports.filter(({ imported }) => imported !== "*").map(({ name }) => name));
|
|
1267
|
+
const namespaces = new Set(imports.filter(({ imported }) => imported === "*").map(({ name }) => name));
|
|
667
1268
|
const calls = new Map;
|
|
668
|
-
const callOf = (
|
|
1269
|
+
const callOf = (callee, shadowed) => {
|
|
1270
|
+
if (ts.isPropertyAccessExpression(callee) && ts.isIdentifier(callee.expression) && namespaces.has(callee.expression.text) && !shadowed.has(callee.expression.text)) {
|
|
1271
|
+
const name = `${callee.expression.text}.${callee.name.text}`;
|
|
1272
|
+
if (!calls.has(name))
|
|
1273
|
+
calls.set(name, { name, local: null });
|
|
1274
|
+
return true;
|
|
1275
|
+
}
|
|
1276
|
+
if (!ts.isIdentifier(callee) || shadowed.has(callee.text))
|
|
1277
|
+
return false;
|
|
1278
|
+
const name = callee.text;
|
|
669
1279
|
if (calls.has(name))
|
|
670
1280
|
return true;
|
|
671
1281
|
const declared = this.declarationIn(source, name);
|
|
@@ -675,23 +1285,71 @@ rootLayout
|
|
|
675
1285
|
name,
|
|
676
1286
|
local: declared && {
|
|
677
1287
|
span: this.#reader.spanOf(source, declared.declared),
|
|
678
|
-
extent:
|
|
1288
|
+
extent: declared.extent,
|
|
679
1289
|
doc: this.#reader.docOf(source, declared.statement)
|
|
680
1290
|
}
|
|
681
1291
|
});
|
|
682
1292
|
return true;
|
|
683
1293
|
};
|
|
684
|
-
const visit = (node) => {
|
|
685
|
-
|
|
1294
|
+
const visit = (node, outer) => {
|
|
1295
|
+
const shadowed = this.#scopeOf(node, outer);
|
|
1296
|
+
if (ts.isCallExpression(node) && callOf(node.expression, shadowed))
|
|
686
1297
|
return;
|
|
687
|
-
ts.forEachChild(node, visit);
|
|
1298
|
+
ts.forEachChild(node, (child) => visit(child, shadowed));
|
|
688
1299
|
};
|
|
689
1300
|
if (ts.isIdentifier(stage))
|
|
690
|
-
callOf(stage
|
|
1301
|
+
callOf(stage, new Set);
|
|
691
1302
|
else
|
|
692
|
-
visit(stage);
|
|
1303
|
+
visit(stage, new Set);
|
|
693
1304
|
return [...calls.values()];
|
|
694
1305
|
}
|
|
1306
|
+
#scopeOf(node, outer) {
|
|
1307
|
+
const ts = this.#ts;
|
|
1308
|
+
const names = [];
|
|
1309
|
+
const bind = (name) => {
|
|
1310
|
+
if (ts.isIdentifier(name))
|
|
1311
|
+
names.push(name.text);
|
|
1312
|
+
else
|
|
1313
|
+
for (const element of name.elements)
|
|
1314
|
+
if (!ts.isOmittedExpression(element))
|
|
1315
|
+
bind(element.name);
|
|
1316
|
+
};
|
|
1317
|
+
const declare = (statement) => {
|
|
1318
|
+
if (ts.isVariableStatement(statement))
|
|
1319
|
+
for (const declaration of statement.declarationList.declarations)
|
|
1320
|
+
bind(declaration.name);
|
|
1321
|
+
else if ((ts.isFunctionDeclaration(statement) || ts.isClassDeclaration(statement)) && statement.name)
|
|
1322
|
+
names.push(statement.name.text);
|
|
1323
|
+
};
|
|
1324
|
+
const hoist = (child) => {
|
|
1325
|
+
if (ts.isFunctionLike(child) || ts.isClassLike(child))
|
|
1326
|
+
return;
|
|
1327
|
+
if (ts.isVariableDeclarationList(child) && !(child.flags & ts.NodeFlags.BlockScoped))
|
|
1328
|
+
for (const declaration of child.declarations)
|
|
1329
|
+
bind(declaration.name);
|
|
1330
|
+
ts.forEachChild(child, hoist);
|
|
1331
|
+
};
|
|
1332
|
+
if (ts.isFunctionLike(node)) {
|
|
1333
|
+
for (const parameter of node.parameters)
|
|
1334
|
+
bind(parameter.name);
|
|
1335
|
+
if (ts.isFunctionExpression(node) && node.name)
|
|
1336
|
+
names.push(node.name.text);
|
|
1337
|
+
if ("body" in node && node.body)
|
|
1338
|
+
ts.forEachChild(node.body, hoist);
|
|
1339
|
+
} else if (ts.isClassExpression(node) && node.name)
|
|
1340
|
+
names.push(node.name.text);
|
|
1341
|
+
else if (ts.isBlock(node))
|
|
1342
|
+
node.statements.forEach(declare);
|
|
1343
|
+
else if (ts.isCaseBlock(node))
|
|
1344
|
+
for (const clause of node.clauses)
|
|
1345
|
+
clause.statements.forEach(declare);
|
|
1346
|
+
else if (ts.isCatchClause(node) && node.variableDeclaration)
|
|
1347
|
+
bind(node.variableDeclaration.name);
|
|
1348
|
+
else if ((ts.isForStatement(node) || ts.isForInStatement(node) || ts.isForOfStatement(node)) && node.initializer && ts.isVariableDeclarationList(node.initializer))
|
|
1349
|
+
for (const declaration of node.initializer.declarations)
|
|
1350
|
+
bind(declaration.name);
|
|
1351
|
+
return names.length ? new Set([...outer, ...names]) : outer;
|
|
1352
|
+
}
|
|
695
1353
|
}
|
|
696
1354
|
|
|
697
1355
|
// pkgs/@akanjs/language/akanGraph.ts
|
|
@@ -707,10 +1365,6 @@ var builtinGuards = {
|
|
|
707
1365
|
Public: { scope: "account", doc: "Passes every caller, signed in or not." },
|
|
708
1366
|
None: { scope: "account", doc: "Refuses every caller." }
|
|
709
1367
|
};
|
|
710
|
-
var frameworkOwner = "akanjs";
|
|
711
|
-
var frameworkPattern = /^akanjs(?:\/|$)/;
|
|
712
|
-
var aliasPattern = /^@(apps|libs)\/([^/]+)/;
|
|
713
|
-
var maxMapDepth = 4;
|
|
714
1368
|
|
|
715
1369
|
class GraphBuilder {
|
|
716
1370
|
#source;
|
|
@@ -718,16 +1372,16 @@ class GraphBuilder {
|
|
|
718
1372
|
#edges = new Map;
|
|
719
1373
|
#contexts = new Map;
|
|
720
1374
|
#members = new Map;
|
|
721
|
-
#guards = new Map;
|
|
722
|
-
#mapEntries = new Map;
|
|
723
1375
|
#routeFiles = new Map;
|
|
724
|
-
#declarations = new Map;
|
|
725
1376
|
#routes;
|
|
1377
|
+
#resolver;
|
|
726
1378
|
#adaptors = new Map;
|
|
727
1379
|
#plugs = new Map;
|
|
1380
|
+
#serviceFields = new Set;
|
|
728
1381
|
constructor(source) {
|
|
729
1382
|
this.#source = source;
|
|
730
1383
|
this.#routes = new RouteFactReader(source.ts, source.reader, source.parse);
|
|
1384
|
+
this.#resolver = new GuardResolver(source, this.#routes);
|
|
731
1385
|
}
|
|
732
1386
|
build() {
|
|
733
1387
|
const { facts } = this.#source;
|
|
@@ -739,17 +1393,28 @@ class GraphBuilder {
|
|
|
739
1393
|
...[...constantsByOwner].filter(([key]) => key !== owner && key?.startsWith("libs/")).flatMap(([, list]) => list)
|
|
740
1394
|
];
|
|
741
1395
|
const typed = [];
|
|
1396
|
+
const adaptorCounts = new Map;
|
|
742
1397
|
for (const file of facts)
|
|
743
1398
|
for (const fact of file.adaptors) {
|
|
744
|
-
const
|
|
745
|
-
|
|
746
|
-
this.#adaptorNodeOf(declared);
|
|
1399
|
+
const key = this.#key("adaptor", file.owner, fact.name);
|
|
1400
|
+
adaptorCounts.set(key, (adaptorCounts.get(key) ?? 0) + 1);
|
|
747
1401
|
}
|
|
1402
|
+
const declaredAdaptors = facts.flatMap((file) => file.adaptors.map((fact) => {
|
|
1403
|
+
const key = this.#key("adaptor", file.owner, fact.name);
|
|
1404
|
+
const id = (adaptorCounts.get(key) ?? 0) > 1 ? this.#key("adaptor", file.owner, `${this.#resolver.inOwner(file.fileName, file.owner)}#${fact.name}`) : key;
|
|
1405
|
+
const declared = { fact, owner: file.owner, fileName: file.fileName, id };
|
|
1406
|
+
this.#adaptors.set(fact.name, [...this.#adaptors.get(fact.name) ?? [], declared]);
|
|
1407
|
+
this.#adaptorNodeOf(declared);
|
|
1408
|
+
return { declared, file };
|
|
1409
|
+
}));
|
|
1410
|
+
for (const { declared, file } of declaredAdaptors)
|
|
1411
|
+
for (const plug of declared.fact.plugs)
|
|
1412
|
+
this.#addEdge(declared.id, this.#adaptorIdOf(plug.target, file), "plugs", plug.name, this.#location(plug.span));
|
|
748
1413
|
for (const file of facts)
|
|
749
|
-
for (const
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
1414
|
+
for (const binding of file.adaptorBindings)
|
|
1415
|
+
this.#addEdge(this.#adaptorIdOf(binding.role, file), this.#adaptorIdOf(binding.adaptor, file), "binds", file.owner, this.#location(binding.span));
|
|
1416
|
+
for (const guard of this.#resolver.declare(facts))
|
|
1417
|
+
this.#guardNodeOf(guard);
|
|
753
1418
|
for (const file of facts) {
|
|
754
1419
|
const { owner } = file;
|
|
755
1420
|
const scalar = this.#source.relative(file.fileName).match(scalarPattern)?.[1];
|
|
@@ -780,10 +1445,18 @@ class GraphBuilder {
|
|
|
780
1445
|
}
|
|
781
1446
|
for (const method of service.methods)
|
|
782
1447
|
this.#addMember("method", owner, refName, method, `${service.name}.${method.name}`, file.fileName);
|
|
783
|
-
for (const plug of service.plugs)
|
|
784
|
-
|
|
1448
|
+
for (const plug of service.plugs) {
|
|
1449
|
+
const key = `${refName}
|
|
1450
|
+
${plug.name}`;
|
|
1451
|
+
this.#plugs.set(key, [
|
|
1452
|
+
...this.#plugs.get(key) ?? [],
|
|
1453
|
+
{ owner, target: this.#adaptorIdOf(plug.target, file) }
|
|
1454
|
+
]);
|
|
1455
|
+
}
|
|
1456
|
+
for (const field of service.fields)
|
|
1457
|
+
this.#serviceFields.add(`${owner ?? ""}
|
|
785
1458
|
${refName}
|
|
786
|
-
${
|
|
1459
|
+
${field}`);
|
|
787
1460
|
}
|
|
788
1461
|
for (const filter of file.filters) {
|
|
789
1462
|
if (!filter.name.endsWith("Filter"))
|
|
@@ -793,31 +1466,7 @@ ${plug.name}`, this.#adaptorIdOf(plug.target, file));
|
|
|
793
1466
|
for (const query of filter.queries)
|
|
794
1467
|
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);
|
|
795
1468
|
}
|
|
796
|
-
|
|
797
|
-
const refName = slice.model;
|
|
798
|
-
if (!refName)
|
|
799
|
-
continue;
|
|
800
|
-
const fallback = this.#addNode(this.#key("slice", owner, refName), "slice", owner, refName, "", slice.span, slice.guards);
|
|
801
|
-
for (const guard of slice.guards)
|
|
802
|
-
this.#guard(fallback, guard, file);
|
|
803
|
-
for (const key of slice.keys) {
|
|
804
|
-
const detail = [...key.guards, ...key.live ? ["live"] : []];
|
|
805
|
-
const node = this.#addMember("slice", owner, refName, key, `${refName}.${key.name}`, file.fileName, detail);
|
|
806
|
-
for (const guard of key.guards)
|
|
807
|
-
this.#guard(node, guard, file);
|
|
808
|
-
}
|
|
809
|
-
}
|
|
810
|
-
for (const endpoint of file.endpoints) {
|
|
811
|
-
const refName = endpoint.model;
|
|
812
|
-
if (!refName)
|
|
813
|
-
continue;
|
|
814
|
-
for (const key of endpoint.keys) {
|
|
815
|
-
const detail = [...key.verb ? [key.verb] : [], ...key.guards];
|
|
816
|
-
const node = this.#addMember("endpoint", owner, refName, key, `${refName}.${key.name}`, file.fileName, detail);
|
|
817
|
-
for (const guard of key.guards)
|
|
818
|
-
this.#guard(node, guard, file);
|
|
819
|
-
}
|
|
820
|
-
}
|
|
1469
|
+
this.#addGuarded(file);
|
|
821
1470
|
for (const internal of file.internals)
|
|
822
1471
|
for (const key of internal.keys)
|
|
823
1472
|
if (internal.model && key.type !== "resolveField")
|
|
@@ -833,7 +1482,7 @@ ${plug.name}`, this.#adaptorIdOf(plug.target, file));
|
|
|
833
1482
|
types.set(node.label, [...types.get(node.label) ?? [], node]);
|
|
834
1483
|
for (const node of typed)
|
|
835
1484
|
for (const field of node.fields ?? []) {
|
|
836
|
-
const candidates = (field.type ? types.get(field.type) ?? [] : []).filter((type) => this.#visible(type.owner, node.owner));
|
|
1485
|
+
const candidates = (field.type ? types.get(field.type) ?? [] : []).filter((type) => this.#resolver.visible(type.owner, node.owner));
|
|
837
1486
|
field.ref = (candidates.find((type) => type.owner === node.owner) ?? candidates[0])?.id ?? null;
|
|
838
1487
|
if (field.ref)
|
|
839
1488
|
this.#addEdge(node.id, field.ref, "field", `${field.name}${field.array ? "[]" : ""}`, field.at);
|
|
@@ -915,61 +1564,52 @@ ${label ?? ""}`;
|
|
|
915
1564
|
else
|
|
916
1565
|
this.#edges.set(key, { from, to, kind, label, count: 1, at });
|
|
917
1566
|
}
|
|
918
|
-
#
|
|
919
|
-
const
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
for (const
|
|
928
|
-
const
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
};
|
|
936
|
-
const madeBy = (factory, fileName, extent) => {
|
|
937
|
-
const parts = [{ fileName, extent }];
|
|
938
|
-
const seen = new Set;
|
|
939
|
-
for (let current = factory;current && !seen.has(current); current = sameFile(current, current.fact.via)) {
|
|
940
|
-
seen.add(current);
|
|
941
|
-
parts.push({ fileName: current.fileName, extent: current.fact.extent });
|
|
942
|
-
}
|
|
943
|
-
return parts;
|
|
944
|
-
};
|
|
945
|
-
for (const file of facts) {
|
|
946
|
-
const { owner, fileName } = file;
|
|
947
|
-
for (const { name, span, extent, scope, doc, factory: callee } of file.guards) {
|
|
948
|
-
const factory = callee ? factories.get(callee)?.find((other) => other.fileName === fileName) : undefined;
|
|
949
|
-
declare({ name, owner, span, scope, doc, parts: madeBy(factory, fileName, extent) }, factory);
|
|
1567
|
+
#addGuarded(file) {
|
|
1568
|
+
const { owner } = file;
|
|
1569
|
+
for (const slice of file.slices) {
|
|
1570
|
+
const refName = slice.model;
|
|
1571
|
+
if (!refName)
|
|
1572
|
+
continue;
|
|
1573
|
+
const fallback = this.#addNode(this.#key("slice", owner, refName), "slice", owner, refName, "", slice.span, slice.guards.map((guard) => guardLabelOf(guard, file.guardLabels)));
|
|
1574
|
+
for (const guard of slice.guards)
|
|
1575
|
+
this.#guard(fallback, guard, file);
|
|
1576
|
+
for (const key of slice.keys) {
|
|
1577
|
+
const detail = [
|
|
1578
|
+
...key.guards.map((guard) => guardLabelOf(guard, file.guardLabels)),
|
|
1579
|
+
...key.live ? ["live"] : []
|
|
1580
|
+
];
|
|
1581
|
+
const node = this.#addMember("slice", owner, refName, key, `${refName}.${key.name}`, file.fileName, detail);
|
|
1582
|
+
for (const guard of key.guards)
|
|
1583
|
+
this.#guard(node, guard, file);
|
|
950
1584
|
}
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
const
|
|
958
|
-
|
|
959
|
-
|
|
1585
|
+
}
|
|
1586
|
+
for (const endpoint of file.endpoints) {
|
|
1587
|
+
const refName = endpoint.model;
|
|
1588
|
+
if (!refName)
|
|
1589
|
+
continue;
|
|
1590
|
+
for (const key of endpoint.keys) {
|
|
1591
|
+
const detail = [
|
|
1592
|
+
...key.verb ? [key.verb] : [],
|
|
1593
|
+
...key.guards.map((guard) => guardLabelOf(guard, file.guardLabels))
|
|
1594
|
+
];
|
|
1595
|
+
const node = this.#addMember("endpoint", owner, refName, key, `${refName}.${key.name}`, file.fileName, detail);
|
|
1596
|
+
for (const guard of key.guards)
|
|
1597
|
+
this.#guard(node, guard, file);
|
|
960
1598
|
}
|
|
961
1599
|
}
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
1600
|
+
}
|
|
1601
|
+
#guard(node, guard, file) {
|
|
1602
|
+
const [, role = null, local = guard] = guard.match(/^([\w$]+) (.+)$/) ?? [];
|
|
1603
|
+
if (!local || local === "?")
|
|
1604
|
+
return;
|
|
1605
|
+
const id = local.includes("@") ? this.#madeInPlaceIdOf(local, file) : this.#guardIdOf(local, file);
|
|
1606
|
+
if (id)
|
|
1607
|
+
this.#addEdge(node.id, id, "guard", role, node.at);
|
|
970
1608
|
}
|
|
971
1609
|
#guardIdOf(local, site) {
|
|
972
|
-
const found = this.#
|
|
1610
|
+
const found = this.#resolver.find(local, site);
|
|
1611
|
+
if ("external" in found)
|
|
1612
|
+
return null;
|
|
973
1613
|
if ("guard" in found)
|
|
974
1614
|
return this.#guardNodeOf(found.guard);
|
|
975
1615
|
const { name, from } = found;
|
|
@@ -982,99 +1622,18 @@ ${label ?? ""}`;
|
|
|
982
1622
|
node.doc = builtin.doc;
|
|
983
1623
|
return node.id;
|
|
984
1624
|
}
|
|
985
|
-
#
|
|
986
|
-
const
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
const
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
}
|
|
998
|
-
const name = member ?? (imported && imported.imported !== "default" && imported.imported !== "*" ? imported.imported : head);
|
|
999
|
-
const declared = this.#guards.get(name) ?? [];
|
|
1000
|
-
const guard = from === undefined ? declared.find((other) => other.owner === site.owner) ?? declared.find((other) => this.#visible(other.owner, site.owner)) : declared.find((other) => other.owner === from) ?? (from === frameworkOwner ? undefined : this.#soleVisible(declared, from));
|
|
1001
|
-
return guard ? { guard } : { name, from };
|
|
1002
|
-
}
|
|
1003
|
-
#mapEntriesOf(objectName, member, fileName, owner) {
|
|
1004
|
-
const key = `${objectName}
|
|
1005
|
-
${member}
|
|
1006
|
-
${fileName ?? ""}
|
|
1007
|
-
${owner ?? ""}`;
|
|
1008
|
-
const cached = this.#mapEntries.get(key);
|
|
1009
|
-
if (cached)
|
|
1010
|
-
return cached;
|
|
1011
|
-
const { ts, reader } = this.#source;
|
|
1012
|
-
const entries = [];
|
|
1013
|
-
const fileNames = [
|
|
1014
|
-
...fileName ? [fileName] : [],
|
|
1015
|
-
...this.#source.files.filter(([other, words]) => other !== fileName && owner !== null && !testFilePattern.test(other) && words.includes(`
|
|
1016
|
-
${objectName}
|
|
1017
|
-
`) && words.includes(`
|
|
1018
|
-
${member}
|
|
1019
|
-
`) && this.#source.ownerOf(other) === owner).map(([other]) => other)
|
|
1020
|
-
];
|
|
1021
|
-
for (const holder of fileNames) {
|
|
1022
|
-
const text = this.#source.readText(holder);
|
|
1023
|
-
if (text === undefined)
|
|
1024
|
-
continue;
|
|
1025
|
-
const source = this.#source.parse(holder, text);
|
|
1026
|
-
const site = { fileName: holder, owner: this.#source.ownerOf(holder), imports: reader.importsIn(source) };
|
|
1027
|
-
for (const statement of source.statements) {
|
|
1028
|
-
if (!ts.isVariableStatement(statement))
|
|
1029
|
-
continue;
|
|
1030
|
-
const map = statement.declarationList.declarations.find((declaration) => ts.isIdentifier(declaration.name) && declaration.name.text === objectName)?.initializer;
|
|
1031
|
-
const object = map && reader.unwrap(map);
|
|
1032
|
-
if (!object || !ts.isObjectLiteralExpression(object))
|
|
1033
|
-
continue;
|
|
1034
|
-
for (const property of object.properties) {
|
|
1035
|
-
if (ts.isShorthandPropertyAssignment(property) && property.name.text === member)
|
|
1036
|
-
entries.push({ name: member, site });
|
|
1037
|
-
if (!ts.isPropertyAssignment(property) || !(ts.isIdentifier(property.name) || ts.isStringLiteral(property.name)) || property.name.text !== member)
|
|
1038
|
-
continue;
|
|
1039
|
-
const value = reader.unwrap(property.initializer);
|
|
1040
|
-
if (ts.isIdentifier(value))
|
|
1041
|
-
entries.push({ name: value.text, site });
|
|
1042
|
-
else if (ts.isPropertyAccessExpression(value) && ts.isIdentifier(value.expression))
|
|
1043
|
-
entries.push({ name: `${value.expression.text}.${value.name.text}`, site });
|
|
1044
|
-
}
|
|
1045
|
-
}
|
|
1046
|
-
}
|
|
1047
|
-
this.#mapEntries.set(key, entries);
|
|
1048
|
-
return entries;
|
|
1049
|
-
}
|
|
1050
|
-
#declarationOf(owner, name, near) {
|
|
1051
|
-
const key = `${owner}
|
|
1052
|
-
${name}
|
|
1053
|
-
${near ?? ""}`;
|
|
1054
|
-
const cached = this.#declarations.get(key);
|
|
1055
|
-
if (cached !== undefined)
|
|
1056
|
-
return cached;
|
|
1057
|
-
const isNear = (fileName) => {
|
|
1058
|
-
const relative = this.#source.relative(fileName);
|
|
1059
|
-
return !!near && (relative.startsWith(`${near}/`) || relative.replace(/\.tsx?$/, "") === near);
|
|
1060
|
-
};
|
|
1061
|
-
const candidates = this.#source.files.filter(([fileName, words]) => !testFilePattern.test(fileName) && words.includes(`
|
|
1062
|
-
${name}
|
|
1063
|
-
`) && this.#source.ownerOf(fileName) === owner).map(([fileName]) => fileName);
|
|
1064
|
-
let found = null;
|
|
1065
|
-
for (const fileName of [...candidates.filter(isNear), ...candidates.filter((other) => !isNear(other))]) {
|
|
1066
|
-
const text = this.#source.readText(fileName);
|
|
1067
|
-
if (text === undefined)
|
|
1068
|
-
continue;
|
|
1069
|
-
const source = this.#source.parse(fileName, text);
|
|
1070
|
-
const declared = this.#routes.declarationIn(source, name);
|
|
1071
|
-
if (!declared)
|
|
1072
|
-
continue;
|
|
1073
|
-
found = { source, statement: declared.statement, declared: declared.declared };
|
|
1074
|
-
break;
|
|
1075
|
-
}
|
|
1076
|
-
this.#declarations.set(key, found);
|
|
1077
|
-
return found;
|
|
1625
|
+
#madeInPlaceIdOf(name, file) {
|
|
1626
|
+
const made = this.#resolver.madeInPlace(file.fileName, name);
|
|
1627
|
+
if (made)
|
|
1628
|
+
return this.#guardNodeOf(made);
|
|
1629
|
+
const head = name.slice(name.indexOf(":") + 1, name.indexOf("@")).split(".")[0] ?? name;
|
|
1630
|
+
const imported = file.imports.find((item) => item.name === head);
|
|
1631
|
+
const from = imported ? this.#resolver.ownerOfSpecifier(file.fileName, imported.from) : file.owner;
|
|
1632
|
+
if (from === undefined || from === frameworkOwner)
|
|
1633
|
+
return null;
|
|
1634
|
+
const scope = `${this.#resolver.inOwner(file.fileName, file.owner)}#${name}`;
|
|
1635
|
+
const label = guardLabelOf(name, file.guardLabels);
|
|
1636
|
+
return this.#addNode(this.#key("guard", file.owner, scope), "guard", file.owner, null, name, null, [], label).id;
|
|
1078
1637
|
}
|
|
1079
1638
|
#addRoutes() {
|
|
1080
1639
|
const routes = [];
|
|
@@ -1127,22 +1686,23 @@ ${dir}`, node);
|
|
|
1127
1686
|
}
|
|
1128
1687
|
#routeGuardIdOf({ name: local, local: declared }, fact, text) {
|
|
1129
1688
|
if (declared) {
|
|
1130
|
-
const
|
|
1131
|
-
const id = this.#key("guard", fact.owner, `${file}#${local}`);
|
|
1689
|
+
const id = this.#key("guard", fact.owner, `${this.#resolver.inOwner(fact.fileName, fact.owner)}#${local}`);
|
|
1132
1690
|
return this.#routeGuardNodeOf(id, fact.owner, local, declared.span, declared.doc, text, declared.extent);
|
|
1133
1691
|
}
|
|
1134
|
-
const
|
|
1135
|
-
|
|
1692
|
+
const [head = local, member] = local.split(".");
|
|
1693
|
+
const imported = fact.imports.find((item) => item.name === head);
|
|
1694
|
+
if (!imported || member && imported.imported !== "*")
|
|
1136
1695
|
return null;
|
|
1137
|
-
const name = imported.imported !== "default" && imported.imported !== "*" ? imported.imported : local;
|
|
1138
|
-
const from = this.#ownerOfSpecifier(fact.fileName, imported.from);
|
|
1696
|
+
const name = member ?? (imported.imported !== "default" && imported.imported !== "*" ? imported.imported : local);
|
|
1697
|
+
const from = this.#resolver.ownerOfSpecifier(fact.fileName, imported.from);
|
|
1139
1698
|
if (!from || from === frameworkOwner)
|
|
1140
1699
|
return null;
|
|
1141
|
-
const found = this.#declarationOf(from, name, this.#pathOfSpecifier(fact.fileName, imported.from));
|
|
1700
|
+
const found = this.#resolver.declarationOf(from, name, this.#resolver.pathOfSpecifier(fact.fileName, imported.from));
|
|
1142
1701
|
if (!found)
|
|
1143
1702
|
return null;
|
|
1144
1703
|
const { reader } = this.#source;
|
|
1145
|
-
|
|
1704
|
+
const owner = this.#source.ownerOf(found.source.fileName) ?? from;
|
|
1705
|
+
return this.#routeGuardNodeOf(this.#key("guard", owner, `${this.#resolver.inOwner(found.source.fileName, owner)}#${found.name}`), owner, found.name, reader.spanOf(found.source, found.declared), reader.docOf(found.source, found.statement), found.source.text, found.extent);
|
|
1146
1706
|
}
|
|
1147
1707
|
#routeGuardNodeOf(id, owner, name, span, doc, text, extent) {
|
|
1148
1708
|
const isNew = !this.#nodes.has(id);
|
|
@@ -1155,18 +1715,70 @@ ${dir}`, node);
|
|
|
1155
1715
|
#adaptorIdOf(local, file) {
|
|
1156
1716
|
const [head, member] = local.split(".");
|
|
1157
1717
|
const imported = file.imports.find((item) => item.name === head);
|
|
1158
|
-
const from = imported ? this.#ownerOfSpecifier(file.fileName, imported.from) : undefined;
|
|
1159
1718
|
const name = member ?? (imported && imported.imported !== "default" && imported.imported !== "*" ? imported.imported : head);
|
|
1719
|
+
const path = imported ? this.#resolver.pathOfSpecifier(file.fileName, imported.from) : null;
|
|
1720
|
+
if (imported && path === null && !frameworkPattern.test(imported.from))
|
|
1721
|
+
return this.#packageAdaptorOf(name, imported.from);
|
|
1722
|
+
const from = imported ? this.#resolver.ownerOfSpecifier(file.fileName, imported.from) : undefined;
|
|
1160
1723
|
const declared = this.#adaptors.get(name) ?? [];
|
|
1161
|
-
const found = from === undefined ? declared
|
|
1724
|
+
const found = from === undefined ? this.#adaptorIn(declared, file.owner, path, file.fileName) ?? declared.find((adaptor) => this.#resolver.visible(adaptor.owner, file.owner)) : this.#adaptorIn(declared, from, path, file.fileName) ?? (from === frameworkOwner ? undefined : declared.find((adaptor) => this.#resolver.visible(adaptor.owner, from)));
|
|
1162
1725
|
if (found)
|
|
1163
|
-
return
|
|
1726
|
+
return found.id;
|
|
1727
|
+
const reexported = from && from !== frameworkOwner ? this.#packageShimOf(from, name, path) : null;
|
|
1728
|
+
if (reexported)
|
|
1729
|
+
return this.#packageAdaptorOf(reexported.name, reexported.from);
|
|
1164
1730
|
const owner = from === frameworkOwner ? null : imported ? from ?? null : file.owner;
|
|
1165
1731
|
const detail = from === frameworkOwner ? [frameworkOwner] : [];
|
|
1166
1732
|
return this.#addNode(this.#key("adaptor", owner, name), "adaptor", owner, null, name, null, detail).id;
|
|
1167
1733
|
}
|
|
1168
|
-
#
|
|
1169
|
-
const
|
|
1734
|
+
#adaptorIn(declared, owner, path, fileName) {
|
|
1735
|
+
const own = declared.filter((adaptor) => adaptor.owner === owner);
|
|
1736
|
+
if (own.length < 2)
|
|
1737
|
+
return own.at(0);
|
|
1738
|
+
const pathOf = (adaptor) => this.#source.relative(adaptor.fileName).replace(/\.tsx?$/, "");
|
|
1739
|
+
const named = path === null ? own.find((adaptor) => adaptor.fileName === fileName) : own.find((adaptor) => pathOf(adaptor) === path || pathOf(adaptor) === `${path}/index`) ?? own.find((adaptor) => pathOf(adaptor).startsWith(`${path}/`));
|
|
1740
|
+
return named ?? own.at(0);
|
|
1741
|
+
}
|
|
1742
|
+
#pluggedOf({ owner, module }, field) {
|
|
1743
|
+
const plugs = this.#plugs.get(`${module}
|
|
1744
|
+
${field}`) ?? [];
|
|
1745
|
+
const own = plugs.filter((plug) => plug.owner === owner);
|
|
1746
|
+
if (!own.length && this.#serviceFields.has(`${owner ?? ""}
|
|
1747
|
+
${module}
|
|
1748
|
+
${field}`))
|
|
1749
|
+
return [];
|
|
1750
|
+
const inherited = own.length ? own : plugs.filter((plug) => this.#resolver.visible(plug.owner, owner));
|
|
1751
|
+
return [...new Set(inherited.map(({ target }) => target))];
|
|
1752
|
+
}
|
|
1753
|
+
#packageAdaptorOf(name, specifier) {
|
|
1754
|
+
if (frameworkPattern.test(specifier))
|
|
1755
|
+
return this.#addNode(this.#key("adaptor", null, name), "adaptor", null, null, name, null, [frameworkOwner]).id;
|
|
1756
|
+
const pkg = specifier.split("/").slice(0, specifier.startsWith("@") ? 2 : 1).join("/");
|
|
1757
|
+
return this.#addNode(this.#key("adaptor", pkg, name), "adaptor", null, null, name, null, [pkg]).id;
|
|
1758
|
+
}
|
|
1759
|
+
#packageShimOf(owner, name, near) {
|
|
1760
|
+
const reexport = this.#resolver.reexportOf(owner, name, near);
|
|
1761
|
+
const [shim] = reexport?.site.imports ?? [];
|
|
1762
|
+
if (reexport && shim && this.#resolver.pathOfSpecifier(reexport.site.fileName, shim.from) === null)
|
|
1763
|
+
return { name: reexport.local === "default" ? name : reexport.local, from: shim.from };
|
|
1764
|
+
if (reexport || !near)
|
|
1765
|
+
return null;
|
|
1766
|
+
const packages = new Set;
|
|
1767
|
+
for (const [fileName, words] of this.#resolver.filesIn(owner)) {
|
|
1768
|
+
const relative = this.#source.relative(fileName);
|
|
1769
|
+
const isNear = relative.startsWith(`${near}/`) || relative.replace(/\.tsx?$/, "") === near;
|
|
1770
|
+
if (!isNear || !words.includes(`
|
|
1771
|
+
export
|
|
1772
|
+
`))
|
|
1773
|
+
continue;
|
|
1774
|
+
for (const [, specifier = ""] of this.#source.readText(fileName)?.matchAll(starExportPattern) ?? [])
|
|
1775
|
+
if (this.#resolver.pathOfSpecifier(fileName, specifier) === null)
|
|
1776
|
+
packages.add(specifier);
|
|
1777
|
+
}
|
|
1778
|
+
const [only] = packages;
|
|
1779
|
+
return packages.size === 1 && only && !this.#resolver.declares(owner, name) ? { name, from: only } : null;
|
|
1780
|
+
}
|
|
1781
|
+
#adaptorNodeOf({ fact, owner, fileName, id }) {
|
|
1170
1782
|
const detail = fact.refName ? [fact.refName] : [];
|
|
1171
1783
|
const node = this.#addNode(id, "adaptor", owner, null, fact.name, fact.span, detail);
|
|
1172
1784
|
if (fact.doc && !node.doc)
|
|
@@ -1174,38 +1786,22 @@ ${dir}`, node);
|
|
|
1174
1786
|
this.#digest(node, this.#source.readText(fileName), fact.extent);
|
|
1175
1787
|
return node.id;
|
|
1176
1788
|
}
|
|
1177
|
-
#guardNodeOf({ name, owner, span, scope, doc, parts }) {
|
|
1178
|
-
const
|
|
1789
|
+
#guardNodeOf({ name, owner, span, scope, doc, parts, file, label }) {
|
|
1790
|
+
const id = this.#key("guard", owner, file ? `${file}#${name}` : name);
|
|
1791
|
+
const node = this.#addNode(id, "guard", owner, null, name, span, scope ? [scope] : [], label ?? name);
|
|
1179
1792
|
if (doc && !node.doc)
|
|
1180
1793
|
node.doc = doc;
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1794
|
+
if (node.digest)
|
|
1795
|
+
return node.id;
|
|
1796
|
+
const digest = this.#hashOf(...parts.map(({ fileName, extent }) => [this.#source.readText(fileName), extent]));
|
|
1797
|
+
if (!digest)
|
|
1798
|
+
return node.id;
|
|
1799
|
+
node.digest = digest;
|
|
1800
|
+
const sources = [...new Set(parts.map(({ fileName }) => this.#source.relative(fileName)))].filter((source) => source !== node.at?.file);
|
|
1801
|
+
if (sources.length)
|
|
1802
|
+
node.sources = sources;
|
|
1187
1803
|
return node.id;
|
|
1188
1804
|
}
|
|
1189
|
-
#ownerOfSpecifier(fileName, specifier) {
|
|
1190
|
-
if (frameworkPattern.test(specifier))
|
|
1191
|
-
return frameworkOwner;
|
|
1192
|
-
const path = this.#pathOfSpecifier(fileName, specifier);
|
|
1193
|
-
return path === null ? undefined : ownerOf(path) ?? undefined;
|
|
1194
|
-
}
|
|
1195
|
-
#pathOfSpecifier(fileName, specifier) {
|
|
1196
|
-
const alias = specifier.match(aliasPattern);
|
|
1197
|
-
if (alias)
|
|
1198
|
-
return `${alias[1]}/${alias[2]}${specifier.slice(alias[0].length)}`;
|
|
1199
|
-
if (!specifier.startsWith("."))
|
|
1200
|
-
return null;
|
|
1201
|
-
const segments = this.#source.relative(fileName).split("/").slice(0, -1);
|
|
1202
|
-
for (const segment of specifier.split("/"))
|
|
1203
|
-
if (segment === "..")
|
|
1204
|
-
segments.pop();
|
|
1205
|
-
else if (segment !== ".")
|
|
1206
|
-
segments.push(segment);
|
|
1207
|
-
return segments.join("/");
|
|
1208
|
-
}
|
|
1209
1805
|
#moduleDirOf(fileName) {
|
|
1210
1806
|
const dir = this.#source.relative(fileName).match(moduleDirPattern)?.[1] ?? null;
|
|
1211
1807
|
return dir?.startsWith("_") && !dir.startsWith("__") ? dir.slice(1) : dir;
|
|
@@ -1241,20 +1837,13 @@ ${dir}`, node);
|
|
|
1241
1837
|
visit(constant);
|
|
1242
1838
|
return [...fields.values()];
|
|
1243
1839
|
}
|
|
1244
|
-
#visible(target, from) {
|
|
1245
|
-
return !from || !target || target === from || target.startsWith("libs/");
|
|
1246
|
-
}
|
|
1247
|
-
#soleVisible(declared, from) {
|
|
1248
|
-
const visible = declared.filter((other) => this.#visible(other.owner, from));
|
|
1249
|
-
return visible.length === 1 ? visible[0] : undefined;
|
|
1250
|
-
}
|
|
1251
1840
|
#targetNodeOf({ family, owner, refName, sourceKey }) {
|
|
1252
1841
|
const isDefault = /^[A-Z]/.test(sourceKey);
|
|
1253
1842
|
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;
|
|
1254
1843
|
return id && this.#nodes.has(id) ? id : null;
|
|
1255
1844
|
}
|
|
1256
1845
|
#membersNamed(kind, name, owner, refName) {
|
|
1257
|
-
const nodes = (this.#members.get(`${kind}:${name}`) ?? []).filter((node) => (!refName || node.module === refName) && this.#visible(node.owner, owner));
|
|
1846
|
+
const nodes = (this.#members.get(`${kind}:${name}`) ?? []).filter((node) => (!refName || node.module === refName) && this.#resolver.visible(node.owner, owner));
|
|
1258
1847
|
const own = nodes.filter((node) => node.owner === owner);
|
|
1259
1848
|
return (own.length ? own : nodes).map((node) => node.id);
|
|
1260
1849
|
}
|
|
@@ -1299,10 +1888,8 @@ st
|
|
|
1299
1888
|
visit(source);
|
|
1300
1889
|
}
|
|
1301
1890
|
#link(fileName, source, identifier, chain, context, owner) {
|
|
1302
|
-
const plugged = chain?.length === 2 && chain[0] === "this" && context.kind === "method" && this.#isServiceThis(identifier) ? this.#
|
|
1303
|
-
|
|
1304
|
-
${chain[1]}`) : undefined;
|
|
1305
|
-
const resolved = plugged ? [plugged] : this.#source.resolve(fileName, identifier).map((target) => this.#targetNodeOf(target)).filter((id) => id !== null);
|
|
1891
|
+
const plugged = chain?.length === 2 && chain[0] === "this" && context.kind === "method" && this.#isServiceThis(identifier) ? this.#pluggedOf(context, chain[1]) : [];
|
|
1892
|
+
const resolved = plugged.length ? plugged : this.#source.resolve(fileName, identifier).map((target) => this.#targetNodeOf(target)).filter((id) => id !== null);
|
|
1306
1893
|
const targets = resolved.length ? resolved : this.#plainTargetsOf(chain, identifier.text, context, owner);
|
|
1307
1894
|
if (!targets.length)
|
|
1308
1895
|
return;
|
|
@@ -1454,6 +2041,10 @@ import {
|
|
|
1454
2041
|
sliceNames,
|
|
1455
2042
|
stateSetterName
|
|
1456
2043
|
} from "akanjs/common/akanNames.ts";
|
|
2044
|
+
var guardDetailOf = (facts, guards) => {
|
|
2045
|
+
const labels = Object.assign({}, ...facts.map((file) => file.guardLabels));
|
|
2046
|
+
return guards.length ? [`guards: ${guards.map((guard) => guardLabelOf(guard, labels)).join(", ")}`] : [];
|
|
2047
|
+
};
|
|
1457
2048
|
var capitalize2 = (text) => text.charAt(0).toUpperCase() + text.slice(1);
|
|
1458
2049
|
|
|
1459
2050
|
class NameTable {
|
|
@@ -1553,7 +2144,7 @@ class NameTable {
|
|
|
1553
2144
|
role: "sig",
|
|
1554
2145
|
gate: "sig",
|
|
1555
2146
|
label: sliceClass.name,
|
|
1556
|
-
detail:
|
|
2147
|
+
detail: guardDetailOf(facts, sliceClass.guards)
|
|
1557
2148
|
});
|
|
1558
2149
|
if (modelDoc)
|
|
1559
2150
|
this.#add({
|
|
@@ -1618,7 +2209,7 @@ class NameTable {
|
|
|
1618
2209
|
sourceKey: slice.name,
|
|
1619
2210
|
span: slice.span,
|
|
1620
2211
|
label: `slice ${refName} (default)`,
|
|
1621
|
-
detail:
|
|
2212
|
+
detail: guardDetailOf(facts, slice.guards)
|
|
1622
2213
|
};
|
|
1623
2214
|
this.#addSliceNames(defaultTarget, refName, "", modelNameSet);
|
|
1624
2215
|
for (const key of slice.keys)
|
|
@@ -1628,7 +2219,7 @@ class NameTable {
|
|
|
1628
2219
|
sourceKey: key.name,
|
|
1629
2220
|
span: key.span,
|
|
1630
2221
|
label: `slice ${key.name}`,
|
|
1631
|
-
detail: [...
|
|
2222
|
+
detail: [...guardDetailOf(facts, key.guards), ...key.live ? ["live"] : []]
|
|
1632
2223
|
}, refName, key.name, modelNameSet, slice.name);
|
|
1633
2224
|
}
|
|
1634
2225
|
if (filterClass) {
|
|
@@ -1685,7 +2276,7 @@ class NameTable {
|
|
|
1685
2276
|
role: key.verb === "pubsub" ? "subscribe" : "listen",
|
|
1686
2277
|
gate: null,
|
|
1687
2278
|
label: `${key.verb} ${key.name}`,
|
|
1688
|
-
detail:
|
|
2279
|
+
detail: guardDetailOf(facts, key.guards)
|
|
1689
2280
|
});
|
|
1690
2281
|
}
|
|
1691
2282
|
}
|
|
@@ -1743,14 +2334,12 @@ var dictionaryPattern = /\.dictionary\.ts$/;
|
|
|
1743
2334
|
var srvkitPattern = /\/srvkit\//;
|
|
1744
2335
|
var wordPattern = /[A-Za-z_$][\w$]*/g;
|
|
1745
2336
|
var identifierPattern = /^[A-Za-z_$][\w$]*$/;
|
|
1746
|
-
var regExpSpecials = /[\\^$.*+?()[\]{}|]/g;
|
|
1747
2337
|
var stateReceivers = new Set(["use", "sel", "get", "do"]);
|
|
1748
2338
|
var lensFamilies = new Set(["slice", "query", "formSetter", "storeState", "endpoint"]);
|
|
1749
2339
|
var modellessFamilies = new Set(["query", "storeState", "endpoint"]);
|
|
1750
2340
|
var gateWords = { srv: "srv", sig: "sig", db: "db", slice: "slice" };
|
|
1751
2341
|
var parseCacheSize = 64;
|
|
1752
2342
|
var pathOf = (fileName) => fileName.replace(/\\/g, "/");
|
|
1753
|
-
var escapeRegExp = (text) => text.replace(regExpSpecials, (special) => `\\${special}`);
|
|
1754
2343
|
var receiverGap = String.raw`(?:\s|\)|\/\*[\s\S]*?\*\/)*`;
|
|
1755
2344
|
|
|
1756
2345
|
class AkanIndex {
|
|
@@ -1881,6 +2470,8 @@ canPass
|
|
|
1881
2470
|
adapt
|
|
1882
2471
|
`) || words.includes(`
|
|
1883
2472
|
dangerouslyAdapt
|
|
2473
|
+
`) || words.includes(`
|
|
2474
|
+
applyAdaptor
|
|
1884
2475
|
`);
|
|
1885
2476
|
}
|
|
1886
2477
|
static #sourceKeyOf({ family, sourceKey, label, detail, span }) {
|