@akanjs/language 3.2.0-rc.2 → 3.2.0-rc.21
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/adaptorResolver.d.ts +18 -0
- package/guardFacts.d.ts +8 -1
- package/guardResolver.d.ts +22 -5
- package/index.cjs +596 -188
- package/index.js +596 -188
- package/moduleFacts.d.ts +7 -0
- package/package.json +1 -1
- package/server.js +588 -188
package/index.js
CHANGED
|
@@ -28,6 +28,9 @@ class AkanGraphDiff {
|
|
|
28
28
|
...head.edges.flatMap((edge) => !baseKeys.has(edgeKeyOf(edge)) ? [{ ...edge, change: "added" }] : marked.has(edge.from) || marked.has(edge.to) ? [edge] : []),
|
|
29
29
|
...base.edges.filter((edge) => !headKeys.has(edgeKeyOf(edge))).map((edge) => ({ ...edge, change: "removed" }))
|
|
30
30
|
];
|
|
31
|
+
const shown = new Set([...marked.keys(), ...edges.flatMap((edge) => [edge.from, edge.to])]);
|
|
32
|
+
const listed = new Set(edges.map(edgeKeyOf));
|
|
33
|
+
edges.push(...head.edges.filter((edge) => edge.kind === "binds" && shown.has(edge.from) && !listed.has(edgeKeyOf(edge))));
|
|
31
34
|
const context = edges.flatMap((edge) => [edge.from, edge.to]).filter((id) => !marked.has(id)).flatMap((id) => {
|
|
32
35
|
const node = headNodes.get(id) ?? baseNodes.get(id);
|
|
33
36
|
return node ? [node] : [];
|
|
@@ -106,6 +109,42 @@ ${at.file}` : null;
|
|
|
106
109
|
return node.fields ? { ...node, fields: node.fields.map(({ digest: _field, ...field }) => field) } : node;
|
|
107
110
|
}
|
|
108
111
|
}
|
|
112
|
+
// pkgs/akanjs/common/facetBarrel.ts
|
|
113
|
+
var barrelFacetDirs = ["ui", "webkit", "srvkit", "common", "plugin"];
|
|
114
|
+
var sourceFilePattern = /\.(ts|tsx)$/;
|
|
115
|
+
var excludedFilePattern = /(^index\.tsx?$|\.d\.ts$|\.(test|spec)\.(ts|tsx)$|\.css$|\.scss$|\.sass$)/;
|
|
116
|
+
var pascalCasePattern = /^[A-Z][A-Za-z0-9]*$/;
|
|
117
|
+
var camelCasePattern = /^[a-z][A-Za-z0-9]*$/;
|
|
118
|
+
var letterRankOf = (char) => char.toLowerCase().charCodeAt(0) * 2 + (char === char.toLowerCase() ? 1 : 0);
|
|
119
|
+
var digitRunAt = (name, idx) => /^\d+/.exec(name.slice(idx))?.[0] ?? "";
|
|
120
|
+
var compareExportNames = (a, b) => {
|
|
121
|
+
for (let idx = 0;idx < a.length && idx < b.length; ) {
|
|
122
|
+
const [runA, runB] = [digitRunAt(a, idx), digitRunAt(b, idx)];
|
|
123
|
+
if (runA && runB && runA !== runB)
|
|
124
|
+
return runA.length - runB.length || (runA < runB ? -1 : 1);
|
|
125
|
+
if (runA && runB)
|
|
126
|
+
idx += runA.length;
|
|
127
|
+
else if (runA || runB)
|
|
128
|
+
return runA ? -1 : 1;
|
|
129
|
+
else if (a.charAt(idx) !== b.charAt(idx))
|
|
130
|
+
return letterRankOf(a.charAt(idx)) - letterRankOf(b.charAt(idx));
|
|
131
|
+
else
|
|
132
|
+
idx++;
|
|
133
|
+
}
|
|
134
|
+
return a.length - b.length;
|
|
135
|
+
};
|
|
136
|
+
var facetBarrelNamesOf = (facet, files, dirs) => {
|
|
137
|
+
const nameCasePattern = facet === "ui" ? pascalCasePattern : camelCasePattern;
|
|
138
|
+
return [
|
|
139
|
+
...files.filter((file) => sourceFilePattern.test(file) && !excludedFilePattern.test(file)).map((file) => file.replace(sourceFilePattern, "")),
|
|
140
|
+
...dirs.filter((dir) => !dir.startsWith("."))
|
|
141
|
+
].filter((name) => nameCasePattern.test(name)).sort(compareExportNames);
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
// pkgs/@akanjs/language/escapeRegExp.ts
|
|
145
|
+
var regExpSpecials = /[\\^$.*+?()[\]{}|]/g;
|
|
146
|
+
var escapeRegExp = (text) => text.replace(regExpSpecials, (special) => `\\${special}`);
|
|
147
|
+
|
|
109
148
|
// pkgs/@akanjs/language/guardFacts.ts
|
|
110
149
|
var guardLabelOf = (guard, labels) => {
|
|
111
150
|
const [, role = null, local = guard] = guard.match(/^([\w$]+) (.+)$/) ?? [];
|
|
@@ -113,6 +152,7 @@ var guardLabelOf = (guard, labels) => {
|
|
|
113
152
|
return label === undefined ? guard : role ? `${role} ${label}` : label;
|
|
114
153
|
};
|
|
115
154
|
var maxLabelArgs = 32;
|
|
155
|
+
var maxLayers = 4;
|
|
116
156
|
var guardRefReaderOf = (ts, ast, unwrap) => {
|
|
117
157
|
const pathOf = (expression) => {
|
|
118
158
|
if (ts.isIdentifier(expression))
|
|
@@ -122,10 +162,19 @@ var guardRefReaderOf = (ts, ast, unwrap) => {
|
|
|
122
162
|
const head = pathOf(expression.expression);
|
|
123
163
|
return head && `${head}.${expression.name.text}`;
|
|
124
164
|
};
|
|
125
|
-
const
|
|
165
|
+
const layersOf = (call) => {
|
|
166
|
+
const inner = unwrap(call.expression);
|
|
167
|
+
if (!ts.isCallExpression(inner))
|
|
168
|
+
return { root: call, layers: 0 };
|
|
169
|
+
const { root, layers } = layersOf(inner);
|
|
170
|
+
return { root, layers: layers + 1 };
|
|
171
|
+
};
|
|
172
|
+
const calleeOf = (call) => pathOf(unwrap(layersOf(call).root.expression)) ?? "?";
|
|
126
173
|
const labelOf = (source, call) => {
|
|
127
174
|
const args = call.arguments.map((arg) => arg.getText(source)).join(", ");
|
|
128
|
-
|
|
175
|
+
const inner = unwrap(call.expression);
|
|
176
|
+
const head = ts.isCallExpression(inner) ? labelOf(source, inner) : pathOf(inner) ?? "?";
|
|
177
|
+
return `${head}(${args.length <= maxLabelArgs && !args.includes(`
|
|
129
178
|
`) ? args : "…"})`;
|
|
130
179
|
};
|
|
131
180
|
const guardRefOf = (expression, made, member) => {
|
|
@@ -153,9 +202,9 @@ var guardRefReaderOf = (ts, ast, unwrap) => {
|
|
|
153
202
|
const single = refOf(guards);
|
|
154
203
|
return single ? [single] : [];
|
|
155
204
|
};
|
|
156
|
-
return { pathOf, labelOf, guardsIn };
|
|
205
|
+
return { pathOf, layersOf, labelOf, guardsIn };
|
|
157
206
|
};
|
|
158
|
-
var guardFactoryReaderOf = (ts, ast, { spanOf, extentOf, unwrap, docOf }, pathOf) => {
|
|
207
|
+
var guardFactoryReaderOf = (ts, ast, { spanOf, extentOf, unwrap, docOf }, pathOf, layersOf) => {
|
|
159
208
|
const implementsGuard = (node, guardNames) => !!node.heritageClauses?.some((clause) => clause.token === ts.SyntaxKind.ImplementsKeyword && clause.types.some(({ expression }) => guardNames.has(ast.expressionName(expression) ?? "")));
|
|
160
209
|
const scopeOf = (node) => {
|
|
161
210
|
const scope = node.members.find((member) => ts.isPropertyDeclaration(member) && ast.nodeName(member.name) === "scope" && !!ts.getModifiers(member)?.some(({ kind }) => kind === ts.SyntaxKind.StaticKeyword))?.initializer;
|
|
@@ -177,7 +226,7 @@ var guardFactoryReaderOf = (ts, ast, { spanOf, extentOf, unwrap, docOf }, pathOf
|
|
|
177
226
|
}
|
|
178
227
|
return functions;
|
|
179
228
|
};
|
|
180
|
-
const returnedOf = (body, guardNames) => {
|
|
229
|
+
const returnedOf = (body, guardNames, depth = 0) => {
|
|
181
230
|
const locals = new Map;
|
|
182
231
|
const pending = [];
|
|
183
232
|
const visit = (node) => {
|
|
@@ -198,6 +247,7 @@ var guardFactoryReaderOf = (ts, ast, { spanOf, extentOf, unwrap, docOf }, pathOf
|
|
|
198
247
|
const calls = [];
|
|
199
248
|
const seen = new Set;
|
|
200
249
|
const passed = new Set;
|
|
250
|
+
const returned = [];
|
|
201
251
|
for (let node = pending.pop();node; node = pending.pop()) {
|
|
202
252
|
if (seen.has(node))
|
|
203
253
|
continue;
|
|
@@ -205,6 +255,8 @@ var guardFactoryReaderOf = (ts, ast, { spanOf, extentOf, unwrap, docOf }, pathOf
|
|
|
205
255
|
const value = ts.isExpression(node) ? unwrap(node) : node;
|
|
206
256
|
if ((ts.isClassExpression(value) || ts.isClassDeclaration(value)) && implementsGuard(value, guardNames))
|
|
207
257
|
guard ??= value;
|
|
258
|
+
else if ((ts.isArrowFunction(value) || ts.isFunctionExpression(value)) && !passed.has(node) && depth < maxLayers)
|
|
259
|
+
returned.push(value.body);
|
|
208
260
|
else if (ts.isConditionalExpression(value))
|
|
209
261
|
pending.push(value.whenTrue, value.whenFalse);
|
|
210
262
|
else if (ts.isBinaryExpression(value))
|
|
@@ -214,15 +266,22 @@ var guardFactoryReaderOf = (ts, ast, { spanOf, extentOf, unwrap, docOf }, pathOf
|
|
|
214
266
|
if (local)
|
|
215
267
|
pending.push(local);
|
|
216
268
|
} else if (ts.isCallExpression(value)) {
|
|
217
|
-
const
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
269
|
+
const { root, layers } = layersOf(value);
|
|
270
|
+
const callee = pathOf(unwrap(root.expression));
|
|
271
|
+
if (callee && !passed.has(node) && !calls.some((call) => call.callee === callee))
|
|
272
|
+
calls.push({ callee, layers });
|
|
273
|
+
for (let call = value;ts.isCallExpression(call); call = unwrap(call.expression)) {
|
|
274
|
+
for (const arg of call.arguments)
|
|
275
|
+
passed.add(arg);
|
|
276
|
+
pending.push(...call.arguments);
|
|
277
|
+
}
|
|
223
278
|
}
|
|
224
279
|
}
|
|
225
|
-
|
|
280
|
+
const [inner] = returned;
|
|
281
|
+
if (guard || calls.length || !inner)
|
|
282
|
+
return { guard, calls, layers: 0 };
|
|
283
|
+
const nested = returnedOf(inner, guardNames, depth + 1);
|
|
284
|
+
return { ...nested, layers: nested.layers + 1 };
|
|
226
285
|
};
|
|
227
286
|
const guardFactoriesOf = (source, guardNames, isImported) => {
|
|
228
287
|
const functions = functionsOf(source);
|
|
@@ -232,7 +291,7 @@ var guardFactoryReaderOf = (ts, ast, { spanOf, extentOf, unwrap, docOf }, pathOf
|
|
|
232
291
|
for (let isGrowing = true;isGrowing; ) {
|
|
233
292
|
isGrowing = false;
|
|
234
293
|
for (const [name, { guard, calls }] of returned) {
|
|
235
|
-
if (members.has(name) || !guard && !calls.some(isFactoryCall))
|
|
294
|
+
if (members.has(name) || !guard && !calls.some(({ callee }) => isFactoryCall(callee)))
|
|
236
295
|
continue;
|
|
237
296
|
members.add(name);
|
|
238
297
|
isGrowing = true;
|
|
@@ -251,7 +310,8 @@ var guardFactoryReaderOf = (ts, ast, { spanOf, extentOf, unwrap, docOf }, pathOf
|
|
|
251
310
|
scope: made.guard ? scopeOf(made.guard) : null,
|
|
252
311
|
doc: docOf(source, found.statement),
|
|
253
312
|
direct: !!made.guard,
|
|
254
|
-
via: made.calls.filter(isFactoryCall)
|
|
313
|
+
via: made.calls.filter(({ callee }) => isFactoryCall(callee)),
|
|
314
|
+
layers: made.layers
|
|
255
315
|
});
|
|
256
316
|
}
|
|
257
317
|
return factories;
|
|
@@ -260,8 +320,8 @@ var guardFactoryReaderOf = (ts, ast, { spanOf, extentOf, unwrap, docOf }, pathOf
|
|
|
260
320
|
};
|
|
261
321
|
var createGuardFactReader = (ts, ast, base) => {
|
|
262
322
|
const { spanOf, extentOf, unwrap, docOf } = base;
|
|
263
|
-
const { pathOf, labelOf, guardsIn } = guardRefReaderOf(ts, ast, unwrap);
|
|
264
|
-
const { implementsGuard, scopeOf, guardFactoriesOf } = guardFactoryReaderOf(ts, ast, base, pathOf);
|
|
323
|
+
const { pathOf, layersOf, labelOf, guardsIn } = guardRefReaderOf(ts, ast, unwrap);
|
|
324
|
+
const { implementsGuard, scopeOf, guardFactoriesOf } = guardFactoryReaderOf(ts, ast, base, pathOf, layersOf);
|
|
265
325
|
const guardsOf = (source, imports, madeInPlace) => {
|
|
266
326
|
const guardNames = new Set([
|
|
267
327
|
"Guard",
|
|
@@ -274,15 +334,16 @@ var createGuardFactReader = (ts, ast, base) => {
|
|
|
274
334
|
const calls = [];
|
|
275
335
|
const makeOf = (made, value, isInPlace = false) => {
|
|
276
336
|
if (ts.isClassExpression(value) && implementsGuard(value, guardNames)) {
|
|
277
|
-
guards.push({ ...made, scope: scopeOf(value), factory: null });
|
|
337
|
+
guards.push({ ...made, scope: scopeOf(value), factory: null, layers: 0 });
|
|
278
338
|
return;
|
|
279
339
|
}
|
|
280
|
-
const
|
|
340
|
+
const { root, layers } = ts.isCallExpression(value) ? layersOf(value) : { root: null, layers: 0 };
|
|
341
|
+
const callee = root && pathOf(unwrap(root.expression));
|
|
281
342
|
const factory = callee && factories.get(callee);
|
|
282
343
|
if (factory)
|
|
283
|
-
guards.push({ ...made, scope: factory.scope, factory: factory.name });
|
|
344
|
+
guards.push({ ...made, scope: factory.scope, factory: factory.name, layers });
|
|
284
345
|
else if (callee && (isImported(callee) || isInPlace))
|
|
285
|
-
calls.push({ ...made, callee, kind: "call", scope: null });
|
|
346
|
+
calls.push({ ...made, callee, kind: "call", scope: null, layers });
|
|
286
347
|
};
|
|
287
348
|
for (const statement of source.statements) {
|
|
288
349
|
if (ts.isClassDeclaration(statement) && statement.name) {
|
|
@@ -296,9 +357,9 @@ var createGuardFactReader = (ts, ast, base) => {
|
|
|
296
357
|
const base = statement.heritageClauses?.find(({ token }) => token === ts.SyntaxKind.ExtendsKeyword)?.types[0];
|
|
297
358
|
const callee = base && pathOf(base.expression);
|
|
298
359
|
if (implementsGuard(statement, guardNames))
|
|
299
|
-
guards.push({ ...declared, factory: null });
|
|
360
|
+
guards.push({ ...declared, factory: null, layers: 0 });
|
|
300
361
|
else if (callee)
|
|
301
|
-
calls.push({ ...declared, callee, kind: "extends" });
|
|
362
|
+
calls.push({ ...declared, callee, kind: "extends", layers: 0 });
|
|
302
363
|
}
|
|
303
364
|
if (!ts.isVariableStatement(statement))
|
|
304
365
|
continue;
|
|
@@ -335,10 +396,6 @@ var createGuardFactReader = (ts, ast, base) => {
|
|
|
335
396
|
return { guardsIn, guardsOf };
|
|
336
397
|
};
|
|
337
398
|
|
|
338
|
-
// pkgs/@akanjs/language/escapeRegExp.ts
|
|
339
|
-
var regExpSpecials = /[\\^$.*+?()[\]{}|]/g;
|
|
340
|
-
var escapeRegExp = (text) => text.replace(regExpSpecials, (special) => `\\${special}`);
|
|
341
|
-
|
|
342
399
|
// pkgs/@akanjs/language/moduleFacts.ts
|
|
343
400
|
var testFilePattern = /\.(?:test|spec)\.tsx?$/;
|
|
344
401
|
var moduleCallees = new Set([
|
|
@@ -365,7 +422,7 @@ var ownerOf = (relativePath) => {
|
|
|
365
422
|
const [root, name] = relativePath.split("/");
|
|
366
423
|
return (root === "apps" || root === "libs") && name ? `${root}/${name}` : null;
|
|
367
424
|
};
|
|
368
|
-
var
|
|
425
|
+
var syntaxReaderOf = (ts, ast) => {
|
|
369
426
|
const spanOf = (source, node) => {
|
|
370
427
|
const start = node.getStart(source);
|
|
371
428
|
const end = node.getEnd();
|
|
@@ -423,6 +480,74 @@ var createFactReader = (ts, ast) => {
|
|
|
423
480
|
const node = keyName(property);
|
|
424
481
|
return name && node ? [{ name, span: spanOf(source, node), extent: extentOf(source, property) }] : [];
|
|
425
482
|
});
|
|
483
|
+
const verbReaderOf = (parameter) => {
|
|
484
|
+
const verbs = new Map;
|
|
485
|
+
if (parameter && ts.isObjectBindingPattern(parameter.name))
|
|
486
|
+
for (const element of parameter.name.elements) {
|
|
487
|
+
const verb = element.propertyName ?? element.name;
|
|
488
|
+
if (ts.isIdentifier(verb) && ts.isIdentifier(element.name))
|
|
489
|
+
verbs.set(element.name.text, verb.text);
|
|
490
|
+
}
|
|
491
|
+
const holder = parameter && ts.isIdentifier(parameter.name) ? parameter.name.text : null;
|
|
492
|
+
return (callee) => {
|
|
493
|
+
if (callee && ts.isIdentifier(callee))
|
|
494
|
+
return verbs.get(callee.text) ?? null;
|
|
495
|
+
if (callee && ts.isPropertyAccessExpression(callee) && ts.isIdentifier(callee.expression) && callee.expression.text === holder)
|
|
496
|
+
return callee.name.text;
|
|
497
|
+
return null;
|
|
498
|
+
};
|
|
499
|
+
};
|
|
500
|
+
return {
|
|
501
|
+
spanOf,
|
|
502
|
+
extentOf,
|
|
503
|
+
unwrap,
|
|
504
|
+
moduleRefOf,
|
|
505
|
+
returnedObject,
|
|
506
|
+
builderOf,
|
|
507
|
+
guardNameOf,
|
|
508
|
+
optionObjectOf,
|
|
509
|
+
chainOf,
|
|
510
|
+
keyName,
|
|
511
|
+
objectKeys,
|
|
512
|
+
verbReaderOf
|
|
513
|
+
};
|
|
514
|
+
};
|
|
515
|
+
var sourceReaderOf = (ts) => {
|
|
516
|
+
const importsOf = (statement) => {
|
|
517
|
+
const { importClause, moduleSpecifier } = statement;
|
|
518
|
+
if (!importClause || !ts.isStringLiteral(moduleSpecifier))
|
|
519
|
+
return [];
|
|
520
|
+
const from = moduleSpecifier.text;
|
|
521
|
+
const bindings = importClause.namedBindings;
|
|
522
|
+
return [
|
|
523
|
+
...importClause.name ? [{ name: importClause.name.text, imported: "default", from }] : [],
|
|
524
|
+
...bindings && ts.isNamespaceImport(bindings) ? [{ name: bindings.name.text, imported: "*", from }] : [],
|
|
525
|
+
...bindings && ts.isNamedImports(bindings) ? bindings.elements.map((element) => ({
|
|
526
|
+
name: element.name.text,
|
|
527
|
+
imported: (element.propertyName ?? element.name).text,
|
|
528
|
+
from
|
|
529
|
+
})) : []
|
|
530
|
+
];
|
|
531
|
+
};
|
|
532
|
+
const docOf = (source, node) => {
|
|
533
|
+
const { text } = source;
|
|
534
|
+
const ranges = ts.getLeadingCommentRanges(text, node.getFullStart()) ?? [];
|
|
535
|
+
const comments = [];
|
|
536
|
+
let end = node.getStart(source);
|
|
537
|
+
for (const range of [...ranges].reverse()) {
|
|
538
|
+
if ((text.slice(range.end, end).match(/\n/g)?.length ?? 0) > 1)
|
|
539
|
+
break;
|
|
540
|
+
comments.unshift(text.slice(range.pos, range.end));
|
|
541
|
+
end = range.pos;
|
|
542
|
+
}
|
|
543
|
+
const lines = comments.flatMap((comment) => comment.split(`
|
|
544
|
+
`)).map((line) => line.trim().replace(/^\/\*\*?|\*\/$/g, "").replace(/^(?:\/\/[?*!]?|\*)/, "").replace(/\{@link\s+([^}\s|]+)[^}]*\}/g, "$1").trim()).filter((line) => line && !/^(?:biome-ignore|eslint-|@ts-)/.test(line));
|
|
545
|
+
return lines.length ? lines.join(" ") : null;
|
|
546
|
+
};
|
|
547
|
+
const importsIn = (source) => source.statements.filter(ts.isImportDeclaration).flatMap(importsOf);
|
|
548
|
+
return { docOf, importsIn };
|
|
549
|
+
};
|
|
550
|
+
var signalKeyReaderOf = (ts, ast, { spanOf, extentOf, returnedObject, optionObjectOf, chainOf, verbReaderOf }, guardsIn) => {
|
|
426
551
|
const sliceKeysOf = (source, builder, made, model) => (returnedObject(builder)?.properties ?? []).flatMap((property) => {
|
|
427
552
|
if (!ts.isPropertyAssignment(property))
|
|
428
553
|
return [];
|
|
@@ -441,23 +566,30 @@ var createFactReader = (ts, ast) => {
|
|
|
441
566
|
}
|
|
442
567
|
];
|
|
443
568
|
});
|
|
444
|
-
const
|
|
445
|
-
const
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
569
|
+
const endpointKeysOf = (source, builder, made, model) => {
|
|
570
|
+
const verbOf = verbReaderOf(builder?.parameters[0]);
|
|
571
|
+
return (returnedObject(builder)?.properties ?? []).flatMap((property) => {
|
|
572
|
+
if (!ts.isPropertyAssignment(property))
|
|
573
|
+
return [];
|
|
574
|
+
const name = ast.nodeName(property.name);
|
|
575
|
+
if (!name)
|
|
576
|
+
return [];
|
|
577
|
+
const { root, methods } = chainOf(property.initializer);
|
|
578
|
+
return [
|
|
579
|
+
{
|
|
580
|
+
name,
|
|
581
|
+
span: spanOf(source, property.name),
|
|
582
|
+
extent: extentOf(source, property),
|
|
583
|
+
verb: root ? verbOf(root.expression) : null,
|
|
584
|
+
guards: root ? guardsIn(source, optionObjectOf(root), made, `${model}.${name}`) : [],
|
|
585
|
+
argCount: methods.filter((method) => argMethods.has(method)).length
|
|
586
|
+
}
|
|
587
|
+
];
|
|
588
|
+
});
|
|
460
589
|
};
|
|
590
|
+
return { sliceKeysOf, endpointKeysOf };
|
|
591
|
+
};
|
|
592
|
+
var jobKeyReaderOf = (ts, ast, { spanOf, extentOf, unwrap, returnedObject, chainOf, verbReaderOf }) => {
|
|
461
593
|
const numberOf = (expression) => {
|
|
462
594
|
const value = unwrap(expression);
|
|
463
595
|
if (ts.isNumericLiteral(value))
|
|
@@ -485,7 +617,7 @@ var createFactReader = (ts, ast) => {
|
|
|
485
617
|
const [size, unit] = intervalUnits.find(([size]) => ms >= size && ms % size === 0) ?? [1, "ms"];
|
|
486
618
|
return `${ms / size}${unit}`;
|
|
487
619
|
};
|
|
488
|
-
const modesOf = (option) => {
|
|
620
|
+
const modesOf = (option, type) => {
|
|
489
621
|
const object = option && unwrap(option);
|
|
490
622
|
if (!object || !ts.isObjectLiteralExpression(object))
|
|
491
623
|
return [];
|
|
@@ -495,9 +627,9 @@ var createFactReader = (ts, ast) => {
|
|
|
495
627
|
if (name === "enabled")
|
|
496
628
|
return value.kind === ts.SyntaxKind.FalseKeyword ? ["disabled"] : [];
|
|
497
629
|
if (name === "once")
|
|
498
|
-
return value.kind === ts.SyntaxKind.TrueKeyword ? ["once"] : [];
|
|
630
|
+
return type === "initialize" && value.kind === ts.SyntaxKind.TrueKeyword ? ["once"] : [];
|
|
499
631
|
if (name === "lock")
|
|
500
|
-
return value.kind === ts.SyntaxKind.FalseKeyword ? ["unlocked"] : [];
|
|
632
|
+
return type === "interval" && value.kind === ts.SyntaxKind.FalseKeyword ? ["unlocked"] : [];
|
|
501
633
|
if (name !== "serverMode" && name !== "operationMode")
|
|
502
634
|
return [];
|
|
503
635
|
const values = ts.isArrayLiteralExpression(value) ? [...value.elements] : [value];
|
|
@@ -515,7 +647,8 @@ var createFactReader = (ts, ast) => {
|
|
|
515
647
|
const { root } = chainOf(property.initializer);
|
|
516
648
|
const type = root ? verbOf(root.expression) : null;
|
|
517
649
|
const [first, second] = root?.arguments ?? [];
|
|
518
|
-
const
|
|
650
|
+
const cron = type === "cron" && first ? unwrap(first) : null;
|
|
651
|
+
const schedule = cron ? ts.isStringLiteralLike(cron) ? cron.text : cron.getText(source) : type === "interval" || type === "timeout" ? durationOf(first, source) : null;
|
|
519
652
|
const option = type === "initialize" || type === "destroy" ? first : second;
|
|
520
653
|
return [
|
|
521
654
|
{
|
|
@@ -524,11 +657,14 @@ var createFactReader = (ts, ast) => {
|
|
|
524
657
|
extent: extentOf(source, property),
|
|
525
658
|
type,
|
|
526
659
|
schedule,
|
|
527
|
-
modes: modesOf(option)
|
|
660
|
+
modes: modesOf(option, type)
|
|
528
661
|
}
|
|
529
662
|
];
|
|
530
663
|
});
|
|
531
664
|
};
|
|
665
|
+
return { internalKeysOf };
|
|
666
|
+
};
|
|
667
|
+
var serviceReaderOf = (ts, ast, { spanOf, extentOf, returnedObject, guardNameOf, chainOf, verbReaderOf }) => {
|
|
532
668
|
const plugsOf = (source, builder) => {
|
|
533
669
|
const verbOf = verbReaderOf(builder?.parameters[0]);
|
|
534
670
|
return (returnedObject(builder)?.properties ?? []).flatMap((property) => {
|
|
@@ -541,27 +677,30 @@ var createFactReader = (ts, ast) => {
|
|
|
541
677
|
return name && targetName ? [{ name, span: spanOf(source, property.name), target: targetName }] : [];
|
|
542
678
|
});
|
|
543
679
|
};
|
|
544
|
-
const
|
|
545
|
-
const
|
|
546
|
-
|
|
547
|
-
if (
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
span: spanOf(source, property.name),
|
|
557
|
-
extent: extentOf(source, property),
|
|
558
|
-
verb: root ? verbOf(root.expression) : null,
|
|
559
|
-
guards: root ? guardsIn(source, optionObjectOf(root), made, `${model}.${name}`) : [],
|
|
560
|
-
argCount: methods.filter((method) => argMethods.has(method)).length
|
|
561
|
-
}
|
|
562
|
-
];
|
|
563
|
-
});
|
|
680
|
+
const adaptorBindingsIn = (source) => {
|
|
681
|
+
const bindings = [];
|
|
682
|
+
const visit = (node) => {
|
|
683
|
+
if (ts.isCallExpression(node) && ts.isPropertyAccessExpression(node.expression) && node.expression.name.text === "applyAdaptor") {
|
|
684
|
+
const [role, adaptor] = node.arguments.map(guardNameOf);
|
|
685
|
+
if (role && adaptor)
|
|
686
|
+
bindings.push({ role, adaptor, span: spanOf(source, node.expression.name) });
|
|
687
|
+
}
|
|
688
|
+
ts.forEachChild(node, visit);
|
|
689
|
+
};
|
|
690
|
+
visit(source);
|
|
691
|
+
return bindings;
|
|
564
692
|
};
|
|
693
|
+
const methodsOf = (source, statement) => statement.members.flatMap((member) => {
|
|
694
|
+
if (!ts.isMethodDeclaration(member) || !member.body)
|
|
695
|
+
return [];
|
|
696
|
+
const name = ast.nodeName(member.name);
|
|
697
|
+
if (!name || ts.getModifiers(member)?.some(({ kind }) => kind === ts.SyntaxKind.StaticKeyword))
|
|
698
|
+
return [];
|
|
699
|
+
return [{ name, span: spanOf(source, member.name), extent: extentOf(source, member) }];
|
|
700
|
+
});
|
|
701
|
+
return { plugsOf, adaptorBindingsIn, methodsOf };
|
|
702
|
+
};
|
|
703
|
+
var constantReaderOf = (ts, ast, { spanOf, extentOf, unwrap, returnedObject, chainOf, keyName, objectKeys }) => {
|
|
565
704
|
const filterQueriesOf = (source, builder) => {
|
|
566
705
|
const query = returnedObject(builder)?.properties.find((property) => ts.isPropertyAssignment(property) && ast.nodeName(property.name) === "query")?.initializer;
|
|
567
706
|
return query && ts.isObjectLiteralExpression(query) ? objectKeys(source, query) : [];
|
|
@@ -599,48 +738,18 @@ var createFactReader = (ts, ast) => {
|
|
|
599
738
|
return [];
|
|
600
739
|
return list.elements.flatMap((element) => ts.isStringLiteralLike(element) ? [element.text] : []);
|
|
601
740
|
};
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
return [{ name, span: spanOf(source, member.name), extent: extentOf(source, member) }];
|
|
609
|
-
});
|
|
610
|
-
const importsOf = (statement) => {
|
|
611
|
-
const { importClause, moduleSpecifier } = statement;
|
|
612
|
-
if (!importClause || !ts.isStringLiteral(moduleSpecifier))
|
|
613
|
-
return [];
|
|
614
|
-
const from = moduleSpecifier.text;
|
|
615
|
-
const bindings = importClause.namedBindings;
|
|
616
|
-
return [
|
|
617
|
-
...importClause.name ? [{ name: importClause.name.text, imported: "default", from }] : [],
|
|
618
|
-
...bindings && ts.isNamespaceImport(bindings) ? [{ name: bindings.name.text, imported: "*", from }] : [],
|
|
619
|
-
...bindings && ts.isNamedImports(bindings) ? bindings.elements.map((element) => ({
|
|
620
|
-
name: element.name.text,
|
|
621
|
-
imported: (element.propertyName ?? element.name).text,
|
|
622
|
-
from
|
|
623
|
-
})) : []
|
|
624
|
-
];
|
|
625
|
-
};
|
|
626
|
-
const docOf = (source, node) => {
|
|
627
|
-
const { text } = source;
|
|
628
|
-
const ranges = ts.getLeadingCommentRanges(text, node.getFullStart()) ?? [];
|
|
629
|
-
const comments = [];
|
|
630
|
-
let end = node.getStart(source);
|
|
631
|
-
for (const range of [...ranges].reverse()) {
|
|
632
|
-
if ((text.slice(range.end, end).match(/\n/g)?.length ?? 0) > 1)
|
|
633
|
-
break;
|
|
634
|
-
comments.unshift(text.slice(range.pos, range.end));
|
|
635
|
-
end = range.pos;
|
|
636
|
-
}
|
|
637
|
-
const lines = comments.flatMap((comment) => comment.split(`
|
|
638
|
-
`)).map((line) => line.trim().replace(/^\/\*\*?|\*\/$/g, "").replace(/^(?:\/\/[?*!]?|\*)/, "").replace(/\{@link\s+([^}\s|]+)[^}]*\}/g, "$1").trim()).filter((line) => line && !/^(?:biome-ignore|eslint-|@ts-)/.test(line));
|
|
639
|
-
return lines.length ? lines.join(" ") : null;
|
|
640
|
-
};
|
|
741
|
+
return { constantOf, enumValuesOf, filterQueriesOf };
|
|
742
|
+
};
|
|
743
|
+
var createFactReader = (ts, ast) => {
|
|
744
|
+
const syntax = syntaxReaderOf(ts, ast);
|
|
745
|
+
const { spanOf, extentOf, unwrap, moduleRefOf, returnedObject, builderOf, chainOf, objectKeys } = syntax;
|
|
746
|
+
const { docOf, importsIn } = sourceReaderOf(ts);
|
|
641
747
|
const { guardsIn, guardsOf } = createGuardFactReader(ts, ast, { spanOf, extentOf, unwrap, docOf });
|
|
748
|
+
const { sliceKeysOf, endpointKeysOf } = signalKeyReaderOf(ts, ast, syntax, guardsIn);
|
|
749
|
+
const { internalKeysOf } = jobKeyReaderOf(ts, ast, syntax);
|
|
750
|
+
const { plugsOf, adaptorBindingsIn, methodsOf } = serviceReaderOf(ts, ast, syntax);
|
|
751
|
+
const { constantOf, enumValuesOf, filterQueriesOf } = constantReaderOf(ts, ast, syntax);
|
|
642
752
|
const lowerFirst = (text) => text.charAt(0).toLowerCase() + text.slice(1);
|
|
643
|
-
const importsIn = (source) => source.statements.filter(ts.isImportDeclaration).flatMap(importsOf);
|
|
644
753
|
const read = (source, owner) => {
|
|
645
754
|
const imports = importsIn(source);
|
|
646
755
|
const madeInPlace = [];
|
|
@@ -661,6 +770,7 @@ var createFactReader = (ts, ast) => {
|
|
|
661
770
|
endpoints: [],
|
|
662
771
|
internals: [],
|
|
663
772
|
adaptors: [],
|
|
773
|
+
adaptorBindings: source.text.includes("applyAdaptor") ? adaptorBindingsIn(source) : [],
|
|
664
774
|
stores: []
|
|
665
775
|
};
|
|
666
776
|
for (const statement of source.statements) {
|
|
@@ -685,7 +795,8 @@ var createFactReader = (ts, ast) => {
|
|
|
685
795
|
...name,
|
|
686
796
|
model: moduleRefOf(call.arguments[0], "db"),
|
|
687
797
|
methods: methodsOf(source, statement),
|
|
688
|
-
plugs: plugsOf(source, builder)
|
|
798
|
+
plugs: plugsOf(source, builder),
|
|
799
|
+
fields: objectKeys(source, returnedObject(builder)).map(({ name }) => name)
|
|
689
800
|
});
|
|
690
801
|
else if (callee === "slice") {
|
|
691
802
|
const model = moduleRefOf(call.arguments[0], "srv");
|
|
@@ -736,7 +847,11 @@ var frameworkOwner = "akanjs";
|
|
|
736
847
|
var frameworkPattern = /^akanjs(?:\/|$)/;
|
|
737
848
|
var aliasPattern = /^@(apps|libs)\/([^/]+)/;
|
|
738
849
|
var maxMapDepth = 4;
|
|
850
|
+
var identifierPattern = /^[\p{ID_Start}$_][\p{ID_Continue}$\u200c\u200d]*$/u;
|
|
739
851
|
var starExportPattern = /export\s*\*\s*from\s*["']([^"']+)["']/g;
|
|
852
|
+
var facetEntryPattern = new RegExp(`^((?:apps|libs)/[^/]+/(${barrelFacetDirs.map(escapeRegExp).join("|")}))/([^/]+)(/)?`);
|
|
853
|
+
var exportingPatternOf = (name) => new RegExp(`export\\s*\\{(?:[^}]*?[\\s,])?${escapeRegExp(name)}(?![\\w$])`);
|
|
854
|
+
var exportMentioningPatternOf = (name) => new RegExp(`export(?![\\w$])[^;]*?(?<![\\w$])${escapeRegExp(name)}(?![\\w$])`);
|
|
740
855
|
var declaringPatternOf = (name, isAnyBinding) => {
|
|
741
856
|
const escaped = escapeRegExp(name);
|
|
742
857
|
const braced = "\\{(?:[^}]*?[\\s,])?";
|
|
@@ -758,8 +873,12 @@ class GuardResolver {
|
|
|
758
873
|
#reexports = new Map;
|
|
759
874
|
#declarations = new Map;
|
|
760
875
|
#starExports = new Map;
|
|
876
|
+
#moduleExports = new Map;
|
|
877
|
+
#fileStars = new Map;
|
|
878
|
+
#starReach = new Map;
|
|
761
879
|
#ownerFiles = null;
|
|
762
880
|
#modules = null;
|
|
881
|
+
#barrels = null;
|
|
763
882
|
constructor(source, routes) {
|
|
764
883
|
this.#source = source;
|
|
765
884
|
this.#routes = routes;
|
|
@@ -783,21 +902,26 @@ ${name}`);
|
|
|
783
902
|
made: [],
|
|
784
903
|
isReal: fact.direct,
|
|
785
904
|
scope: fact.scope,
|
|
905
|
+
layers: fact.layers,
|
|
786
906
|
targets: []
|
|
787
907
|
};
|
|
788
908
|
factories.set(fact.name, [...factories.get(fact.name) ?? [], factory]);
|
|
789
909
|
declaredFactories.push(factory);
|
|
790
910
|
}
|
|
791
911
|
for (const factory of declaredFactories)
|
|
792
|
-
factory.targets = factory.fact.via.
|
|
912
|
+
factory.targets = factory.fact.via.flatMap(({ callee, layers }) => {
|
|
913
|
+
const target = this.#factoryAt(factories, callee, factory.site);
|
|
914
|
+
return target ? [{ target, layers }] : [];
|
|
915
|
+
});
|
|
793
916
|
for (let isGrowing = true;isGrowing; ) {
|
|
794
917
|
isGrowing = false;
|
|
795
918
|
for (const factory of declaredFactories) {
|
|
796
|
-
const
|
|
797
|
-
if (factory.isReal || !
|
|
919
|
+
const via = factory.targets.find(({ target, layers }) => target.isReal && target.layers >= layers);
|
|
920
|
+
if (factory.isReal || !via)
|
|
798
921
|
continue;
|
|
799
922
|
factory.isReal = true;
|
|
800
|
-
factory.
|
|
923
|
+
factory.layers = factory.fact.layers + via.target.layers - via.layers;
|
|
924
|
+
factory.scope ??= via.target.scope;
|
|
801
925
|
isGrowing = true;
|
|
802
926
|
}
|
|
803
927
|
}
|
|
@@ -807,7 +931,7 @@ ${name}`);
|
|
|
807
931
|
seen.add(factory);
|
|
808
932
|
return [
|
|
809
933
|
{ fileName: factory.site.fileName, extent: factory.fact.extent },
|
|
810
|
-
...factory.targets.filter((target) => target.isReal).flatMap((target) => partsOf(target, seen))
|
|
934
|
+
...factory.targets.filter(({ target }) => target.isReal).flatMap(({ target }) => partsOf(target, seen))
|
|
811
935
|
];
|
|
812
936
|
};
|
|
813
937
|
const declare = (file, made, scope, parts) => {
|
|
@@ -828,7 +952,7 @@ ${name}`, guard);
|
|
|
828
952
|
const factory = made.factory ? factories.get(made.factory)?.find((other) => other.site.fileName === file.fileName) : undefined;
|
|
829
953
|
if (!made.factory)
|
|
830
954
|
declare(file, made, made.scope, []);
|
|
831
|
-
else if (factory?.isReal)
|
|
955
|
+
else if (factory?.isReal && factory.layers === made.layers)
|
|
832
956
|
factory.made.push(declare(file, made, factory.scope, partsOf(factory)));
|
|
833
957
|
}
|
|
834
958
|
for (const made of file.guardCalls) {
|
|
@@ -837,7 +961,7 @@ ${name}`, guard);
|
|
|
837
961
|
continue;
|
|
838
962
|
}
|
|
839
963
|
const factory = this.#factoryAt(factories, made.callee, file);
|
|
840
|
-
if (factory?.isReal)
|
|
964
|
+
if (factory?.isReal && factory.layers === made.layers)
|
|
841
965
|
factory.made.push(declare(file, made, factory.scope, partsOf(factory)));
|
|
842
966
|
}
|
|
843
967
|
}
|
|
@@ -882,7 +1006,7 @@ ${name}`, guard);
|
|
|
882
1006
|
const own = this.#nearest(candidates.filter((other) => other.owner === from), ({ site }) => site.fileName, near);
|
|
883
1007
|
if (own)
|
|
884
1008
|
return own;
|
|
885
|
-
const reexport = from && depth < maxMapDepth ? this
|
|
1009
|
+
const reexport = from && depth < maxMapDepth ? this.#reexportOf(from, name, near) : null;
|
|
886
1010
|
if (reexport)
|
|
887
1011
|
return this.#factoryAt(factories, reexport.local, reexport.site, depth + 1);
|
|
888
1012
|
return from && near ? this.#throughStar(candidates, from, name, near) : undefined;
|
|
@@ -920,13 +1044,13 @@ ${name}`, guard);
|
|
|
920
1044
|
const visible = isBase ? undefined : declared.find((other) => this.visible(other.owner, site.owner));
|
|
921
1045
|
return visible ? { guard: visible } : { name, from };
|
|
922
1046
|
}
|
|
923
|
-
const reexport = from && depth < maxMapDepth ? this
|
|
1047
|
+
const reexport = from && depth < maxMapDepth ? this.#reexportOf(from, name, near) : null;
|
|
924
1048
|
if (reexport)
|
|
925
1049
|
return this.#findGuard(reexport.local, reexport.site, depth + 1, isBase);
|
|
926
1050
|
const reached = from && near ? this.#throughStar(declared, from, name, near) : undefined;
|
|
927
1051
|
return reached ? { guard: reached } : { name, from };
|
|
928
1052
|
}
|
|
929
|
-
reexportOf(owner, name, near) {
|
|
1053
|
+
#reexportOf(owner, name, near) {
|
|
930
1054
|
const key = `${owner}
|
|
931
1055
|
${name}
|
|
932
1056
|
${near ?? ""}`;
|
|
@@ -934,7 +1058,7 @@ ${near ?? ""}`;
|
|
|
934
1058
|
if (cached !== undefined)
|
|
935
1059
|
return cached;
|
|
936
1060
|
let found = null;
|
|
937
|
-
const exporting =
|
|
1061
|
+
const exporting = exportingPatternOf(name);
|
|
938
1062
|
for (const fileName of this.#filesOf(owner, name, near)) {
|
|
939
1063
|
const text = this.#source.readText(fileName);
|
|
940
1064
|
if (text === undefined || !exporting.test(text))
|
|
@@ -952,7 +1076,7 @@ ${near ?? ""}`;
|
|
|
952
1076
|
this.#reexports.set(key, found);
|
|
953
1077
|
return found;
|
|
954
1078
|
}
|
|
955
|
-
#reexportIn(source, name) {
|
|
1079
|
+
#reexportIn(source, name, takesPackageDefault = false) {
|
|
956
1080
|
const { ts, reader } = this.#source;
|
|
957
1081
|
for (const statement of source.statements) {
|
|
958
1082
|
if (!ts.isExportDeclaration(statement) || statement.isTypeOnly)
|
|
@@ -969,7 +1093,9 @@ ${near ?? ""}`;
|
|
|
969
1093
|
const imported = reader.importsIn(source).find((item) => item.name === original);
|
|
970
1094
|
if (!imported)
|
|
971
1095
|
return { name: original, from: null };
|
|
972
|
-
|
|
1096
|
+
if (imported.imported === "default")
|
|
1097
|
+
return takesPackageDefault && this.pathOfSpecifier(source.fileName, imported.from) === null ? { name: "default", from: imported.from } : null;
|
|
1098
|
+
return imported.imported === "*" ? null : { name: imported.imported, from: imported.from };
|
|
973
1099
|
}
|
|
974
1100
|
return null;
|
|
975
1101
|
}
|
|
@@ -978,7 +1104,9 @@ ${near ?? ""}`;
|
|
|
978
1104
|
const relative = this.#source.relative(fileName);
|
|
979
1105
|
return !!near && (relative.startsWith(`${near}/`) || relative.replace(/\.tsx?$/, "") === near);
|
|
980
1106
|
};
|
|
981
|
-
|
|
1107
|
+
if (!identifierPattern.test(name))
|
|
1108
|
+
return [];
|
|
1109
|
+
const candidates = this.#filesIn(owner).filter(([, words]) => words.includes(`
|
|
982
1110
|
${name}
|
|
983
1111
|
`)).map(([fileName]) => fileName);
|
|
984
1112
|
return [...candidates.filter(isNear), ...candidates.filter((other) => !isNear(other))];
|
|
@@ -995,7 +1123,7 @@ ${owner ?? ""}`;
|
|
|
995
1123
|
const entries = [];
|
|
996
1124
|
const fileNames = [
|
|
997
1125
|
...fileName ? [fileName] : [],
|
|
998
|
-
...(owner === null ? [] : this
|
|
1126
|
+
...(owner === null ? [] : this.#filesIn(owner)).filter(([other, words]) => other !== fileName && words.includes(`
|
|
999
1127
|
${objectName}
|
|
1000
1128
|
`) && words.includes(`
|
|
1001
1129
|
${member}
|
|
@@ -1069,30 +1197,120 @@ ${near ?? ""}`;
|
|
|
1069
1197
|
#throughStar(declared, owner, name, near) {
|
|
1070
1198
|
if (!declared.length)
|
|
1071
1199
|
return;
|
|
1072
|
-
const { owners, isOpaque } = this
|
|
1200
|
+
const { owners, isOpaque } = this.starExportsOf(owner, near);
|
|
1073
1201
|
const reached = declared.filter((other) => other.owner !== null && owners.includes(other.owner));
|
|
1074
1202
|
return reached.length === 1 && !isOpaque && !this.declares(owner, name) ? reached[0] : undefined;
|
|
1075
1203
|
}
|
|
1076
|
-
|
|
1077
|
-
const
|
|
1204
|
+
starExportsOf(owner, near) {
|
|
1205
|
+
const key = `${owner}
|
|
1206
|
+
${near}`;
|
|
1207
|
+
const cached = this.#starExports.get(key);
|
|
1078
1208
|
if (cached)
|
|
1079
1209
|
return cached;
|
|
1080
|
-
const found = { owners: [], isOpaque: false };
|
|
1081
|
-
this.#starExports.set(
|
|
1082
|
-
const
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1210
|
+
const found = { owners: [], packages: [], paths: [near], isOpaque: false };
|
|
1211
|
+
this.#starExports.set(key, found);
|
|
1212
|
+
const reach = (specifier, path, target) => {
|
|
1213
|
+
if (path === null && !found.packages.includes(specifier))
|
|
1214
|
+
found.packages.push(specifier);
|
|
1215
|
+
if (target === undefined || target === frameworkOwner || path === null)
|
|
1216
|
+
found.isOpaque = true;
|
|
1217
|
+
else if (!found.paths.includes(path))
|
|
1218
|
+
found.paths.push(path);
|
|
1219
|
+
if (target && target !== frameworkOwner && target !== owner && !found.owners.includes(target))
|
|
1220
|
+
found.owners.push(target);
|
|
1221
|
+
};
|
|
1222
|
+
for (let idx = 0;idx < found.paths.length; idx++) {
|
|
1223
|
+
const path = found.paths[idx] ?? "";
|
|
1224
|
+
for (const module of this.#barrelAt(path) ?? [])
|
|
1225
|
+
reach(module, module, ownerOf(module) ?? undefined);
|
|
1226
|
+
for (const fileName of this.#modulesAt(path))
|
|
1227
|
+
for (const [, specifier = ""] of this.#source.readText(fileName)?.matchAll(starExportPattern) ?? [])
|
|
1228
|
+
reach(specifier, this.pathOfSpecifier(fileName, specifier), this.ownerOfSpecifier(fileName, specifier));
|
|
1229
|
+
}
|
|
1230
|
+
return found;
|
|
1231
|
+
}
|
|
1232
|
+
exportsAt(path, name) {
|
|
1233
|
+
const key = `${path}
|
|
1234
|
+
${name}`;
|
|
1235
|
+
const cached = this.#moduleExports.get(key);
|
|
1236
|
+
if (cached)
|
|
1237
|
+
return cached;
|
|
1238
|
+
const found = { named: null, stars: [], isLocal: false };
|
|
1239
|
+
const stars = new Set(this.#barrelAt(path));
|
|
1240
|
+
for (const fileName of this.#modulesAt(path)) {
|
|
1241
|
+
const text = this.#source.readText(fileName);
|
|
1242
|
+
if (text === undefined)
|
|
1243
|
+
continue;
|
|
1244
|
+
const named = text.includes(name) && identifierPattern.test(name) && exportingPatternOf(name).test(text) ? this.#reexportIn(this.#source.parse(fileName, text), name, true) : null;
|
|
1245
|
+
if (named) {
|
|
1246
|
+
found.named = { ...named, fileName };
|
|
1247
|
+
break;
|
|
1248
|
+
}
|
|
1249
|
+
if (text.includes(name) && exportMentioningPatternOf(name).test(text) && this.#exportsLocally(this.#source.parse(fileName, text), name)) {
|
|
1250
|
+
found.isLocal = true;
|
|
1251
|
+
break;
|
|
1252
|
+
}
|
|
1253
|
+
for (const target of this.#starsIn(fileName, text))
|
|
1254
|
+
stars.add(target);
|
|
1255
|
+
}
|
|
1256
|
+
if (!found.named && !found.isLocal)
|
|
1257
|
+
found.stars = [...stars];
|
|
1258
|
+
this.#moduleExports.set(key, found);
|
|
1259
|
+
return found;
|
|
1260
|
+
}
|
|
1261
|
+
#exportsLocally(source, name) {
|
|
1262
|
+
const { ts } = this.#source;
|
|
1263
|
+
const binds = (node) => ts.isIdentifier(node) ? node.text === name : node.elements.some((element) => !ts.isOmittedExpression(element) && binds(element.name));
|
|
1264
|
+
return source.statements.some((statement) => {
|
|
1265
|
+
if (ts.isExportDeclaration(statement)) {
|
|
1266
|
+
const { exportClause, isTypeOnly, moduleSpecifier } = statement;
|
|
1267
|
+
if (isTypeOnly || !exportClause)
|
|
1268
|
+
return false;
|
|
1269
|
+
if (ts.isNamespaceExport(exportClause))
|
|
1270
|
+
return exportClause.name.text === name;
|
|
1271
|
+
return !moduleSpecifier && ts.isNamedExports(exportClause) && exportClause.elements.some((element) => !element.isTypeOnly && element.name.text === name);
|
|
1272
|
+
}
|
|
1273
|
+
const modifiers = ts.canHaveModifiers(statement) ? ts.getModifiers(statement) ?? [] : [];
|
|
1274
|
+
if (!modifiers.some(({ kind }) => kind === ts.SyntaxKind.ExportKeyword) || modifiers.some(({ kind }) => kind === ts.SyntaxKind.DefaultKeyword))
|
|
1275
|
+
return false;
|
|
1276
|
+
if (ts.isVariableStatement(statement))
|
|
1277
|
+
return statement.declarationList.declarations.some((declaration) => binds(declaration.name));
|
|
1278
|
+
return (ts.isClassDeclaration(statement) || ts.isFunctionDeclaration(statement) || ts.isEnumDeclaration(statement) || ts.isModuleDeclaration(statement) || ts.isImportEqualsDeclaration(statement)) && !!statement.name && ts.isIdentifier(statement.name) && statement.name.text === name;
|
|
1279
|
+
});
|
|
1280
|
+
}
|
|
1281
|
+
mentionsAlong(path, name) {
|
|
1282
|
+
return this.#starReachOf(path).some((text) => text.includes(name));
|
|
1283
|
+
}
|
|
1284
|
+
#starReachOf(path) {
|
|
1285
|
+
const cached = this.#starReach.get(path);
|
|
1286
|
+
if (cached)
|
|
1287
|
+
return cached;
|
|
1288
|
+
const paths = new Set([path]);
|
|
1289
|
+
const texts = [];
|
|
1290
|
+
for (const at of paths) {
|
|
1291
|
+
for (const next of this.#barrelAt(at) ?? [])
|
|
1292
|
+
paths.add(next);
|
|
1293
|
+
for (const fileName of this.#modulesAt(at)) {
|
|
1294
|
+
const text = this.#source.readText(fileName) ?? "";
|
|
1295
|
+
texts.push(text);
|
|
1296
|
+
for (const next of this.#starsIn(fileName, text))
|
|
1297
|
+
paths.add(next);
|
|
1095
1298
|
}
|
|
1299
|
+
}
|
|
1300
|
+
this.#starReach.set(path, texts);
|
|
1301
|
+
return texts;
|
|
1302
|
+
}
|
|
1303
|
+
#starsIn(fileName, text) {
|
|
1304
|
+
const cached = this.#fileStars.get(fileName);
|
|
1305
|
+
if (cached)
|
|
1306
|
+
return cached;
|
|
1307
|
+
const found = [];
|
|
1308
|
+
for (const [, specifier = ""] of text.matchAll(starExportPattern)) {
|
|
1309
|
+
const target = this.pathOfSpecifier(fileName, specifier);
|
|
1310
|
+
if (target !== null)
|
|
1311
|
+
found.push(target);
|
|
1312
|
+
}
|
|
1313
|
+
this.#fileStars.set(fileName, found);
|
|
1096
1314
|
return found;
|
|
1097
1315
|
}
|
|
1098
1316
|
#modulesAt(path) {
|
|
@@ -1106,11 +1324,33 @@ ${near ?? ""}`;
|
|
|
1106
1324
|
}
|
|
1107
1325
|
return this.#modules.get(path) ?? [];
|
|
1108
1326
|
}
|
|
1327
|
+
#barrelAt(path) {
|
|
1328
|
+
if (!this.#barrels) {
|
|
1329
|
+
const entries = new Map;
|
|
1330
|
+
for (const [fileName] of this.#source.files) {
|
|
1331
|
+
const [, folder, facet, entry, nested] = this.#source.relative(fileName).match(facetEntryPattern) ?? [];
|
|
1332
|
+
if (!folder || !facet || !entry)
|
|
1333
|
+
continue;
|
|
1334
|
+
const found = entries.get(folder) ?? { facet, files: new Set, dirs: new Set };
|
|
1335
|
+
(nested ? found.dirs : found.files).add(entry);
|
|
1336
|
+
entries.set(folder, found);
|
|
1337
|
+
}
|
|
1338
|
+
this.#barrels = new Map([...entries].map(([folder, { facet, files, dirs }]) => [
|
|
1339
|
+
folder,
|
|
1340
|
+
facetBarrelNamesOf(facet, [...files], [...dirs]).map((name) => `${folder}/${name}`)
|
|
1341
|
+
]));
|
|
1342
|
+
}
|
|
1343
|
+
return this.#modulesAt(path).length ? undefined : this.#barrels.get(path);
|
|
1344
|
+
}
|
|
1109
1345
|
declares(owner, name) {
|
|
1110
1346
|
const declaring = declaringPatternOf(name, true);
|
|
1111
1347
|
return this.#filesOf(owner, name, null).some((fileName) => declaring.test(this.#source.readText(fileName) ?? ""));
|
|
1112
1348
|
}
|
|
1113
|
-
|
|
1349
|
+
declaresAt(path, name) {
|
|
1350
|
+
const declaring = declaringPatternOf(name, true);
|
|
1351
|
+
return this.#modulesAt(path).some((fileName) => declaring.test(this.#source.readText(fileName) ?? ""));
|
|
1352
|
+
}
|
|
1353
|
+
#filesIn(owner) {
|
|
1114
1354
|
if (!this.#ownerFiles) {
|
|
1115
1355
|
this.#ownerFiles = new Map;
|
|
1116
1356
|
for (const entry of this.#source.files) {
|
|
@@ -1160,6 +1400,196 @@ ${near ?? ""}`;
|
|
|
1160
1400
|
}
|
|
1161
1401
|
}
|
|
1162
1402
|
|
|
1403
|
+
// pkgs/@akanjs/language/adaptorResolver.ts
|
|
1404
|
+
var packageOf = (specifier) => specifier.split("/").slice(0, specifier.startsWith("@") ? 2 : 1).join("/");
|
|
1405
|
+
var packageKeyOf = ({ name, from }) => `${packageOf(from)}
|
|
1406
|
+
${name}`;
|
|
1407
|
+
var exportedKeyOf = (item) => ("fact" in item) ? item.id : ("local" in item) ? `${item.local}
|
|
1408
|
+
` : packageKeyOf(item);
|
|
1409
|
+
var isPackageExport = (item) => ("from" in item);
|
|
1410
|
+
|
|
1411
|
+
class AdaptorResolver {
|
|
1412
|
+
#source;
|
|
1413
|
+
#resolver;
|
|
1414
|
+
#sink;
|
|
1415
|
+
#adaptors = new Map;
|
|
1416
|
+
#plugs = new Map;
|
|
1417
|
+
#serviceFields = new Set;
|
|
1418
|
+
#exported = new Map;
|
|
1419
|
+
constructor(source, resolver, sink) {
|
|
1420
|
+
this.#source = source;
|
|
1421
|
+
this.#resolver = resolver;
|
|
1422
|
+
this.#sink = sink;
|
|
1423
|
+
}
|
|
1424
|
+
declare(facts) {
|
|
1425
|
+
const counts = new Map;
|
|
1426
|
+
for (const file of facts)
|
|
1427
|
+
for (const fact of file.adaptors) {
|
|
1428
|
+
const key = this.#sink.key("adaptor", file.owner, fact.name);
|
|
1429
|
+
counts.set(key, (counts.get(key) ?? 0) + 1);
|
|
1430
|
+
}
|
|
1431
|
+
const declared = facts.flatMap((file) => file.adaptors.map((fact) => {
|
|
1432
|
+
const key = this.#sink.key("adaptor", file.owner, fact.name);
|
|
1433
|
+
const id = (counts.get(key) ?? 0) > 1 ? this.#sink.key("adaptor", file.owner, `${this.#resolver.inOwner(file.fileName, file.owner)}#${fact.name}`) : key;
|
|
1434
|
+
const adaptor = { fact, owner: file.owner, fileName: file.fileName, id };
|
|
1435
|
+
this.#adaptors.set(fact.name, [...this.#adaptors.get(fact.name) ?? [], adaptor]);
|
|
1436
|
+
this.#nodeOf(adaptor);
|
|
1437
|
+
return { adaptor, file };
|
|
1438
|
+
}));
|
|
1439
|
+
for (const { adaptor, file } of declared)
|
|
1440
|
+
for (const plug of adaptor.fact.plugs)
|
|
1441
|
+
this.#sink.addEdge(adaptor.id, this.#idOf(plug.target, file), "plugs", plug.name, this.#sink.location(plug.span));
|
|
1442
|
+
for (const file of facts)
|
|
1443
|
+
for (const binding of file.adaptorBindings)
|
|
1444
|
+
this.#sink.addEdge(this.#idOf(binding.role, file), this.#idOf(binding.adaptor, file), "binds", file.owner, this.#sink.location(binding.span));
|
|
1445
|
+
}
|
|
1446
|
+
addService(refName, service, file) {
|
|
1447
|
+
for (const plug of service.plugs) {
|
|
1448
|
+
const key = `${refName}
|
|
1449
|
+
${plug.name}`;
|
|
1450
|
+
this.#plugs.set(key, [
|
|
1451
|
+
...this.#plugs.get(key) ?? [],
|
|
1452
|
+
{ owner: file.owner, target: this.#idOf(plug.target, file) }
|
|
1453
|
+
]);
|
|
1454
|
+
}
|
|
1455
|
+
for (const field of service.fields)
|
|
1456
|
+
this.#serviceFields.add(`${file.owner ?? ""}
|
|
1457
|
+
${refName}
|
|
1458
|
+
${field}`);
|
|
1459
|
+
}
|
|
1460
|
+
pluggedOf(owner, module, field) {
|
|
1461
|
+
const plugs = this.#plugs.get(`${module}
|
|
1462
|
+
${field}`) ?? [];
|
|
1463
|
+
const own = plugs.filter((plug) => plug.owner === owner);
|
|
1464
|
+
if (!own.length && this.#serviceFields.has(`${owner ?? ""}
|
|
1465
|
+
${module}
|
|
1466
|
+
${field}`))
|
|
1467
|
+
return [];
|
|
1468
|
+
const inherited = own.length ? own : plugs.filter((plug) => this.#resolver.visible(plug.owner, owner));
|
|
1469
|
+
return [...new Set(inherited.map(({ target }) => target))];
|
|
1470
|
+
}
|
|
1471
|
+
#idOf(local, file) {
|
|
1472
|
+
const [head, member] = local.split(".");
|
|
1473
|
+
const imported = file.imports.find((item) => item.name === head);
|
|
1474
|
+
const name = member ?? (imported && imported.imported !== "default" && imported.imported !== "*" ? imported.imported : head);
|
|
1475
|
+
const path = imported ? this.#resolver.pathOfSpecifier(file.fileName, imported.from) : null;
|
|
1476
|
+
if (imported && path === null && !frameworkPattern.test(imported.from))
|
|
1477
|
+
return this.#packageAdaptorOf(name, imported.from);
|
|
1478
|
+
const from = imported ? this.#resolver.ownerOfSpecifier(file.fileName, imported.from) : undefined;
|
|
1479
|
+
const declared = this.#adaptors.get(name) ?? [];
|
|
1480
|
+
const holder = from === undefined ? file.owner : from;
|
|
1481
|
+
const own = this.#adaptorIn(name, declared, holder, path, file.fileName);
|
|
1482
|
+
if (own && "from" in own)
|
|
1483
|
+
return this.#packageAdaptorOf(own.name, own.from);
|
|
1484
|
+
const found = own === undefined && from !== frameworkOwner ? declared.find((adaptor) => this.#resolver.visible(adaptor.owner, holder)) : own;
|
|
1485
|
+
if (found)
|
|
1486
|
+
return found.id;
|
|
1487
|
+
const reexported = own === undefined && from && from !== frameworkOwner ? this.#packageShimOf(from, name, path) : null;
|
|
1488
|
+
if (reexported)
|
|
1489
|
+
return this.#packageAdaptorOf(reexported.name, reexported.from);
|
|
1490
|
+
const owner = from === frameworkOwner ? null : imported ? from ?? null : file.owner;
|
|
1491
|
+
const detail = from === frameworkOwner ? [frameworkOwner] : [];
|
|
1492
|
+
return this.#sink.addNode(this.#sink.key("adaptor", owner, name), "adaptor", owner, name, null, detail).id;
|
|
1493
|
+
}
|
|
1494
|
+
#adaptorIn(name, declared, owner, path, fileName) {
|
|
1495
|
+
const own = declared.filter((adaptor) => adaptor.owner === owner);
|
|
1496
|
+
const [first] = own;
|
|
1497
|
+
if (path === null)
|
|
1498
|
+
return own.find((adaptor) => adaptor.fileName === fileName) ?? first;
|
|
1499
|
+
if (own.length === 1)
|
|
1500
|
+
return first;
|
|
1501
|
+
const exported = this.#exportedAt(name, path).filter((item) => first || !isPackageExport(item));
|
|
1502
|
+
const [only] = exported;
|
|
1503
|
+
if (only)
|
|
1504
|
+
return exported.length === 1 && !("local" in only) ? only : null;
|
|
1505
|
+
return first ? null : undefined;
|
|
1506
|
+
}
|
|
1507
|
+
#exportedAt(name, path) {
|
|
1508
|
+
const key = `${path}
|
|
1509
|
+
${name}`;
|
|
1510
|
+
const cached = this.#exported.get(key);
|
|
1511
|
+
if (cached)
|
|
1512
|
+
return cached;
|
|
1513
|
+
if (!this.#resolver.mentionsAlong(path, name)) {
|
|
1514
|
+
this.#exported.set(key, []);
|
|
1515
|
+
return [];
|
|
1516
|
+
}
|
|
1517
|
+
const reached = new Map;
|
|
1518
|
+
const seen = new Set;
|
|
1519
|
+
const pending = [[name, path]];
|
|
1520
|
+
for (let next = pending.pop();next; next = pending.pop()) {
|
|
1521
|
+
const [wanted, at] = next;
|
|
1522
|
+
if (seen.has(`${at}
|
|
1523
|
+
${wanted}`))
|
|
1524
|
+
continue;
|
|
1525
|
+
seen.add(`${at}
|
|
1526
|
+
${wanted}`);
|
|
1527
|
+
for (const item of this.#bindingAt(wanted, at, pending, name))
|
|
1528
|
+
reached.set(exportedKeyOf(item), item);
|
|
1529
|
+
}
|
|
1530
|
+
const found = [...reached.values()];
|
|
1531
|
+
this.#exported.set(key, found);
|
|
1532
|
+
return found;
|
|
1533
|
+
}
|
|
1534
|
+
#bindingAt(name, path, pending, plugged) {
|
|
1535
|
+
const here = this.#declaredAt(name, path);
|
|
1536
|
+
if (here.length)
|
|
1537
|
+
return here;
|
|
1538
|
+
const { named, stars, isLocal } = this.#resolver.exportsAt(path, name);
|
|
1539
|
+
if (isLocal)
|
|
1540
|
+
return [{ local: path }];
|
|
1541
|
+
if (named?.from === null) {
|
|
1542
|
+
const local = this.#declaredAt(named.name, path);
|
|
1543
|
+
return local.length ? local : [{ local: path }];
|
|
1544
|
+
}
|
|
1545
|
+
if (named) {
|
|
1546
|
+
const target = this.#resolver.pathOfSpecifier(named.fileName, named.from);
|
|
1547
|
+
if (target === null) {
|
|
1548
|
+
const exposed = named.name !== "default" ? named.name : name !== "default" ? name : plugged;
|
|
1549
|
+
return [{ name: exposed, from: named.from }];
|
|
1550
|
+
}
|
|
1551
|
+
pending.push([named.name, target]);
|
|
1552
|
+
return [];
|
|
1553
|
+
}
|
|
1554
|
+
for (const star of stars)
|
|
1555
|
+
pending.push([name, star]);
|
|
1556
|
+
return [];
|
|
1557
|
+
}
|
|
1558
|
+
#declaredAt(name, path) {
|
|
1559
|
+
return (this.#adaptors.get(name) ?? []).filter((adaptor) => {
|
|
1560
|
+
const module = this.#source.relative(adaptor.fileName).replace(/\.tsx?$/, "");
|
|
1561
|
+
return module === path || module === `${path}/index`;
|
|
1562
|
+
});
|
|
1563
|
+
}
|
|
1564
|
+
#packageAdaptorOf(name, specifier) {
|
|
1565
|
+
if (frameworkPattern.test(specifier))
|
|
1566
|
+
return this.#sink.addNode(this.#sink.key("adaptor", null, name), "adaptor", null, name, null, [frameworkOwner]).id;
|
|
1567
|
+
const pkg = packageOf(specifier);
|
|
1568
|
+
return this.#sink.addNode(this.#sink.key("adaptor", pkg, name), "adaptor", null, name, null, [pkg]).id;
|
|
1569
|
+
}
|
|
1570
|
+
#packageShimOf(owner, name, near) {
|
|
1571
|
+
if (!near)
|
|
1572
|
+
return null;
|
|
1573
|
+
const shims = this.#exportedAt(name, near).filter(isPackageExport);
|
|
1574
|
+
const [shim] = shims;
|
|
1575
|
+
if (shim)
|
|
1576
|
+
return shims.length === 1 ? shim : null;
|
|
1577
|
+
const { packages, paths } = this.#resolver.starExportsOf(owner, near);
|
|
1578
|
+
const [only] = packages;
|
|
1579
|
+
if (!only || new Set(packages.map(packageOf)).size !== 1)
|
|
1580
|
+
return null;
|
|
1581
|
+
return paths.some((path) => this.#resolver.declaresAt(path, name)) ? null : { name, from: only };
|
|
1582
|
+
}
|
|
1583
|
+
#nodeOf({ fact, owner, fileName, id }) {
|
|
1584
|
+
const detail = fact.refName ? [fact.refName] : [];
|
|
1585
|
+
const node = this.#sink.addNode(id, "adaptor", owner, fact.name, fact.span, detail);
|
|
1586
|
+
if (fact.doc && !node.doc)
|
|
1587
|
+
node.doc = fact.doc;
|
|
1588
|
+
this.#sink.digest(node, this.#source.readText(fileName), fact.extent);
|
|
1589
|
+
return node.id;
|
|
1590
|
+
}
|
|
1591
|
+
}
|
|
1592
|
+
|
|
1163
1593
|
// pkgs/akanjs/common/trimSlashes.ts
|
|
1164
1594
|
var trimTrailingSlashes = (value) => {
|
|
1165
1595
|
let end = value.length;
|
|
@@ -1183,6 +1613,7 @@ var PAGE_ROUTE_EXPORTS = new Set([
|
|
|
1183
1613
|
"guard"
|
|
1184
1614
|
]);
|
|
1185
1615
|
var LAYOUT_ROUTE_EXPORTS = new Set([...PAGE_ROUTE_EXPORTS, "NotFound", "Error"]);
|
|
1616
|
+
var GENERATED_ROOT_LAYOUT_EXPORTS = new Set(["McpAppRoot", "LevelBoundary"]);
|
|
1186
1617
|
var ROOT_LAYOUT_ROUTE_EXPORTS = new Set([
|
|
1187
1618
|
...LAYOUT_ROUTE_EXPORTS,
|
|
1188
1619
|
"fonts",
|
|
@@ -1192,7 +1623,7 @@ var ROOT_LAYOUT_ROUTE_EXPORTS = new Set([
|
|
|
1192
1623
|
"wsConnect",
|
|
1193
1624
|
"layoutStyle",
|
|
1194
1625
|
"viewport",
|
|
1195
|
-
|
|
1626
|
+
...GENERATED_ROOT_LAYOUT_EXPORTS
|
|
1196
1627
|
]);
|
|
1197
1628
|
var RESERVED_ROUTE_CONFIG_EXPORTS = new Set([...ROOT_LAYOUT_ROUTE_EXPORTS].filter((name) => name !== "default" && !/^[A-Z]/.test(name)));
|
|
1198
1629
|
function parseRouteModuleKey(key) {
|
|
@@ -1448,12 +1879,18 @@ class GraphBuilder {
|
|
|
1448
1879
|
#routeFiles = new Map;
|
|
1449
1880
|
#routes;
|
|
1450
1881
|
#resolver;
|
|
1451
|
-
#adaptors
|
|
1452
|
-
#plugs = new Map;
|
|
1882
|
+
#adaptors;
|
|
1453
1883
|
constructor(source) {
|
|
1454
1884
|
this.#source = source;
|
|
1455
1885
|
this.#routes = new RouteFactReader(source.ts, source.reader, source.parse);
|
|
1456
1886
|
this.#resolver = new GuardResolver(source, this.#routes);
|
|
1887
|
+
this.#adaptors = new AdaptorResolver(source, this.#resolver, {
|
|
1888
|
+
key: (kind, owner, scope) => this.#key(kind, owner, scope),
|
|
1889
|
+
addNode: (id, kind, owner, name, span, detail) => this.#addNode(id, kind, owner, null, name, span, detail),
|
|
1890
|
+
addEdge: (from, to, kind, label, at) => this.#addEdge(from, to, kind, label, at),
|
|
1891
|
+
digest: (node, text, extent) => this.#digest(node, text, extent),
|
|
1892
|
+
location: (span) => this.#location(span)
|
|
1893
|
+
});
|
|
1457
1894
|
}
|
|
1458
1895
|
build() {
|
|
1459
1896
|
const { facts } = this.#source;
|
|
@@ -1465,16 +1902,7 @@ class GraphBuilder {
|
|
|
1465
1902
|
...[...constantsByOwner].filter(([key]) => key !== owner && key?.startsWith("libs/")).flatMap(([, list]) => list)
|
|
1466
1903
|
];
|
|
1467
1904
|
const typed = [];
|
|
1468
|
-
|
|
1469
|
-
for (const fact of file.adaptors) {
|
|
1470
|
-
const declared = { fact, owner: file.owner, fileName: file.fileName };
|
|
1471
|
-
this.#adaptors.set(fact.name, [...this.#adaptors.get(fact.name) ?? [], declared]);
|
|
1472
|
-
this.#adaptorNodeOf(declared);
|
|
1473
|
-
}
|
|
1474
|
-
for (const file of facts)
|
|
1475
|
-
for (const fact of file.adaptors)
|
|
1476
|
-
for (const plug of fact.plugs)
|
|
1477
|
-
this.#addEdge(this.#key("adaptor", file.owner, fact.name), this.#adaptorIdOf(plug.target, file), "plugs", plug.name, this.#location(plug.span));
|
|
1905
|
+
this.#adaptors.declare(facts);
|
|
1478
1906
|
for (const guard of this.#resolver.declare(facts))
|
|
1479
1907
|
this.#guardNodeOf(guard);
|
|
1480
1908
|
for (const file of facts) {
|
|
@@ -1507,10 +1935,7 @@ class GraphBuilder {
|
|
|
1507
1935
|
}
|
|
1508
1936
|
for (const method of service.methods)
|
|
1509
1937
|
this.#addMember("method", owner, refName, method, `${service.name}.${method.name}`, file.fileName);
|
|
1510
|
-
|
|
1511
|
-
this.#plugs.set(`${owner ?? ""}
|
|
1512
|
-
${refName}
|
|
1513
|
-
${plug.name}`, this.#adaptorIdOf(plug.target, file));
|
|
1938
|
+
this.#adaptors.addService(refName, service, file);
|
|
1514
1939
|
}
|
|
1515
1940
|
for (const filter of file.filters) {
|
|
1516
1941
|
if (!filter.name.endsWith("Filter"))
|
|
@@ -1766,28 +2191,6 @@ ${dir}`, node);
|
|
|
1766
2191
|
this.#digest(node, text, extent);
|
|
1767
2192
|
return node.id;
|
|
1768
2193
|
}
|
|
1769
|
-
#adaptorIdOf(local, file) {
|
|
1770
|
-
const [head, member] = local.split(".");
|
|
1771
|
-
const imported = file.imports.find((item) => item.name === head);
|
|
1772
|
-
const from = imported ? this.#resolver.ownerOfSpecifier(file.fileName, imported.from) : undefined;
|
|
1773
|
-
const name = member ?? (imported && imported.imported !== "default" && imported.imported !== "*" ? imported.imported : head);
|
|
1774
|
-
const declared = this.#adaptors.get(name) ?? [];
|
|
1775
|
-
const found = from === undefined ? declared.find((adaptor) => adaptor.owner === file.owner) ?? declared.find((adaptor) => this.#resolver.visible(adaptor.owner, file.owner)) : declared.find((adaptor) => adaptor.owner === from) ?? (from === frameworkOwner ? undefined : declared.find((adaptor) => this.#resolver.visible(adaptor.owner, from)));
|
|
1776
|
-
if (found)
|
|
1777
|
-
return this.#adaptorNodeOf(found);
|
|
1778
|
-
const owner = from === frameworkOwner ? null : imported ? from ?? null : file.owner;
|
|
1779
|
-
const detail = from === frameworkOwner ? [frameworkOwner] : [];
|
|
1780
|
-
return this.#addNode(this.#key("adaptor", owner, name), "adaptor", owner, null, name, null, detail).id;
|
|
1781
|
-
}
|
|
1782
|
-
#adaptorNodeOf({ fact, owner, fileName }) {
|
|
1783
|
-
const id = this.#key("adaptor", owner, fact.name);
|
|
1784
|
-
const detail = fact.refName ? [fact.refName] : [];
|
|
1785
|
-
const node = this.#addNode(id, "adaptor", owner, null, fact.name, fact.span, detail);
|
|
1786
|
-
if (fact.doc && !node.doc)
|
|
1787
|
-
node.doc = fact.doc;
|
|
1788
|
-
this.#digest(node, this.#source.readText(fileName), fact.extent);
|
|
1789
|
-
return node.id;
|
|
1790
|
-
}
|
|
1791
2194
|
#guardNodeOf({ name, owner, span, scope, doc, parts, file, label }) {
|
|
1792
2195
|
const id = this.#key("guard", owner, file ? `${file}#${name}` : name);
|
|
1793
2196
|
const node = this.#addNode(id, "guard", owner, null, name, span, scope ? [scope] : [], label ?? name);
|
|
@@ -1890,10 +2293,8 @@ st
|
|
|
1890
2293
|
visit(source);
|
|
1891
2294
|
}
|
|
1892
2295
|
#link(fileName, source, identifier, chain, context, owner) {
|
|
1893
|
-
const plugged = chain?.length === 2 && chain[0] === "this" && context.kind === "method" && this.#isServiceThis(identifier) ? this.#
|
|
1894
|
-
|
|
1895
|
-
${chain[1]}`) : undefined;
|
|
1896
|
-
const resolved = plugged ? [plugged] : this.#source.resolve(fileName, identifier).map((target) => this.#targetNodeOf(target)).filter((id) => id !== null);
|
|
2296
|
+
const plugged = chain?.length === 2 && chain[0] === "this" && context.kind === "method" && this.#isServiceThis(identifier) ? this.#adaptors.pluggedOf(context.owner, context.module, chain[1]) : [];
|
|
2297
|
+
const resolved = plugged.length ? plugged : this.#source.resolve(fileName, identifier).map((target) => this.#targetNodeOf(target)).filter((id) => id !== null);
|
|
1897
2298
|
const targets = resolved.length ? resolved : this.#plainTargetsOf(chain, identifier.text, context, owner);
|
|
1898
2299
|
if (!targets.length)
|
|
1899
2300
|
return;
|
|
@@ -2491,7 +2892,7 @@ var sourcePattern = /\.(constant|document|service|signal|store)\.ts$/;
|
|
|
2491
2892
|
var dictionaryPattern = /\.dictionary\.ts$/;
|
|
2492
2893
|
var srvkitPattern = /\/srvkit\//;
|
|
2493
2894
|
var wordPattern = /[A-Za-z_$][\w$]*/g;
|
|
2494
|
-
var
|
|
2895
|
+
var identifierPattern2 = /^[A-Za-z_$][\w$]*$/;
|
|
2495
2896
|
var stateReceivers = new Set(["use", "sel", "get", "do"]);
|
|
2496
2897
|
var lensFamilies = new Set(["slice", "query", "formSetter", "storeState", "endpoint"]);
|
|
2497
2898
|
var modellessFamilies = new Set(["query", "storeState", "endpoint"]);
|
|
@@ -2600,7 +3001,7 @@ ${[...new Set(text.match(wordPattern))].join(`
|
|
|
2600
3001
|
}
|
|
2601
3002
|
renameAt(givenName, offset, newKey, readText) {
|
|
2602
3003
|
const sources = this.#sourceEntriesAt(pathOf(givenName), offset).filter((entry) => entry.renamed);
|
|
2603
|
-
if (!sources.length || !
|
|
3004
|
+
if (!sources.length || !identifierPattern2.test(newKey))
|
|
2604
3005
|
return null;
|
|
2605
3006
|
return [
|
|
2606
3007
|
{ span: sources[0].span, newText: newKey },
|
|
@@ -2628,6 +3029,8 @@ canPass
|
|
|
2628
3029
|
adapt
|
|
2629
3030
|
`) || words.includes(`
|
|
2630
3031
|
dangerouslyAdapt
|
|
3032
|
+
`) || words.includes(`
|
|
3033
|
+
applyAdaptor
|
|
2631
3034
|
`);
|
|
2632
3035
|
}
|
|
2633
3036
|
static #sourceKeyOf({ family, sourceKey, label, detail, span }) {
|
|
@@ -3308,6 +3711,11 @@ ${union.name}`)));
|
|
|
3308
3711
|
const field = this.#memberOf(this.#classOf(receiver), receiver.name.text);
|
|
3309
3712
|
return field && ts.isPropertyDeclaration(field) ? this.#namesIn(field.type) : new Set;
|
|
3310
3713
|
}
|
|
3714
|
+
if (ts.isCallExpression(receiver) && ts.isPropertyAccessExpression(receiver.expression) && receiver.expression.expression.kind === ts.SyntaxKind.ThisKeyword) {
|
|
3715
|
+
const field = this.#memberOf(this.#classOf(receiver), receiver.expression.name.text);
|
|
3716
|
+
const type = field && ts.isPropertyDeclaration(field) ? field.type : undefined;
|
|
3717
|
+
return type && ts.isFunctionTypeNode(type) ? this.#namesIn(type.type) : new Set;
|
|
3718
|
+
}
|
|
3311
3719
|
return this.#declaredTypeNames(receiver) ?? new Set;
|
|
3312
3720
|
}
|
|
3313
3721
|
#memberName(name) {
|