@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.cjs
CHANGED
|
@@ -80,6 +80,9 @@ class AkanGraphDiff {
|
|
|
80
80
|
...head.edges.flatMap((edge) => !baseKeys.has(edgeKeyOf(edge)) ? [{ ...edge, change: "added" }] : marked.has(edge.from) || marked.has(edge.to) ? [edge] : []),
|
|
81
81
|
...base.edges.filter((edge) => !headKeys.has(edgeKeyOf(edge))).map((edge) => ({ ...edge, change: "removed" }))
|
|
82
82
|
];
|
|
83
|
+
const shown = new Set([...marked.keys(), ...edges.flatMap((edge) => [edge.from, edge.to])]);
|
|
84
|
+
const listed = new Set(edges.map(edgeKeyOf));
|
|
85
|
+
edges.push(...head.edges.filter((edge) => edge.kind === "binds" && shown.has(edge.from) && !listed.has(edgeKeyOf(edge))));
|
|
83
86
|
const context = edges.flatMap((edge) => [edge.from, edge.to]).filter((id) => !marked.has(id)).flatMap((id) => {
|
|
84
87
|
const node = headNodes.get(id) ?? baseNodes.get(id);
|
|
85
88
|
return node ? [node] : [];
|
|
@@ -158,6 +161,42 @@ ${at.file}` : null;
|
|
|
158
161
|
return node.fields ? { ...node, fields: node.fields.map(({ digest: _field, ...field }) => field) } : node;
|
|
159
162
|
}
|
|
160
163
|
}
|
|
164
|
+
// pkgs/akanjs/common/facetBarrel.ts
|
|
165
|
+
var barrelFacetDirs = ["ui", "webkit", "srvkit", "common", "plugin"];
|
|
166
|
+
var sourceFilePattern = /\.(ts|tsx)$/;
|
|
167
|
+
var excludedFilePattern = /(^index\.tsx?$|\.d\.ts$|\.(test|spec)\.(ts|tsx)$|\.css$|\.scss$|\.sass$)/;
|
|
168
|
+
var pascalCasePattern = /^[A-Z][A-Za-z0-9]*$/;
|
|
169
|
+
var camelCasePattern = /^[a-z][A-Za-z0-9]*$/;
|
|
170
|
+
var letterRankOf = (char) => char.toLowerCase().charCodeAt(0) * 2 + (char === char.toLowerCase() ? 1 : 0);
|
|
171
|
+
var digitRunAt = (name, idx) => /^\d+/.exec(name.slice(idx))?.[0] ?? "";
|
|
172
|
+
var compareExportNames = (a, b) => {
|
|
173
|
+
for (let idx = 0;idx < a.length && idx < b.length; ) {
|
|
174
|
+
const [runA, runB] = [digitRunAt(a, idx), digitRunAt(b, idx)];
|
|
175
|
+
if (runA && runB && runA !== runB)
|
|
176
|
+
return runA.length - runB.length || (runA < runB ? -1 : 1);
|
|
177
|
+
if (runA && runB)
|
|
178
|
+
idx += runA.length;
|
|
179
|
+
else if (runA || runB)
|
|
180
|
+
return runA ? -1 : 1;
|
|
181
|
+
else if (a.charAt(idx) !== b.charAt(idx))
|
|
182
|
+
return letterRankOf(a.charAt(idx)) - letterRankOf(b.charAt(idx));
|
|
183
|
+
else
|
|
184
|
+
idx++;
|
|
185
|
+
}
|
|
186
|
+
return a.length - b.length;
|
|
187
|
+
};
|
|
188
|
+
var facetBarrelNamesOf = (facet, files, dirs) => {
|
|
189
|
+
const nameCasePattern = facet === "ui" ? pascalCasePattern : camelCasePattern;
|
|
190
|
+
return [
|
|
191
|
+
...files.filter((file) => sourceFilePattern.test(file) && !excludedFilePattern.test(file)).map((file) => file.replace(sourceFilePattern, "")),
|
|
192
|
+
...dirs.filter((dir) => !dir.startsWith("."))
|
|
193
|
+
].filter((name) => nameCasePattern.test(name)).sort(compareExportNames);
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
// pkgs/@akanjs/language/escapeRegExp.ts
|
|
197
|
+
var regExpSpecials = /[\\^$.*+?()[\]{}|]/g;
|
|
198
|
+
var escapeRegExp = (text) => text.replace(regExpSpecials, (special) => `\\${special}`);
|
|
199
|
+
|
|
161
200
|
// pkgs/@akanjs/language/guardFacts.ts
|
|
162
201
|
var guardLabelOf = (guard, labels) => {
|
|
163
202
|
const [, role = null, local = guard] = guard.match(/^([\w$]+) (.+)$/) ?? [];
|
|
@@ -165,6 +204,7 @@ var guardLabelOf = (guard, labels) => {
|
|
|
165
204
|
return label === undefined ? guard : role ? `${role} ${label}` : label;
|
|
166
205
|
};
|
|
167
206
|
var maxLabelArgs = 32;
|
|
207
|
+
var maxLayers = 4;
|
|
168
208
|
var guardRefReaderOf = (ts, ast, unwrap) => {
|
|
169
209
|
const pathOf = (expression) => {
|
|
170
210
|
if (ts.isIdentifier(expression))
|
|
@@ -174,10 +214,19 @@ var guardRefReaderOf = (ts, ast, unwrap) => {
|
|
|
174
214
|
const head = pathOf(expression.expression);
|
|
175
215
|
return head && `${head}.${expression.name.text}`;
|
|
176
216
|
};
|
|
177
|
-
const
|
|
217
|
+
const layersOf = (call) => {
|
|
218
|
+
const inner = unwrap(call.expression);
|
|
219
|
+
if (!ts.isCallExpression(inner))
|
|
220
|
+
return { root: call, layers: 0 };
|
|
221
|
+
const { root, layers } = layersOf(inner);
|
|
222
|
+
return { root, layers: layers + 1 };
|
|
223
|
+
};
|
|
224
|
+
const calleeOf = (call) => pathOf(unwrap(layersOf(call).root.expression)) ?? "?";
|
|
178
225
|
const labelOf = (source, call) => {
|
|
179
226
|
const args = call.arguments.map((arg) => arg.getText(source)).join(", ");
|
|
180
|
-
|
|
227
|
+
const inner = unwrap(call.expression);
|
|
228
|
+
const head = ts.isCallExpression(inner) ? labelOf(source, inner) : pathOf(inner) ?? "?";
|
|
229
|
+
return `${head}(${args.length <= maxLabelArgs && !args.includes(`
|
|
181
230
|
`) ? args : "…"})`;
|
|
182
231
|
};
|
|
183
232
|
const guardRefOf = (expression, made, member) => {
|
|
@@ -205,9 +254,9 @@ var guardRefReaderOf = (ts, ast, unwrap) => {
|
|
|
205
254
|
const single = refOf(guards);
|
|
206
255
|
return single ? [single] : [];
|
|
207
256
|
};
|
|
208
|
-
return { pathOf, labelOf, guardsIn };
|
|
257
|
+
return { pathOf, layersOf, labelOf, guardsIn };
|
|
209
258
|
};
|
|
210
|
-
var guardFactoryReaderOf = (ts, ast, { spanOf, extentOf, unwrap, docOf }, pathOf) => {
|
|
259
|
+
var guardFactoryReaderOf = (ts, ast, { spanOf, extentOf, unwrap, docOf }, pathOf, layersOf) => {
|
|
211
260
|
const implementsGuard = (node, guardNames) => !!node.heritageClauses?.some((clause) => clause.token === ts.SyntaxKind.ImplementsKeyword && clause.types.some(({ expression }) => guardNames.has(ast.expressionName(expression) ?? "")));
|
|
212
261
|
const scopeOf = (node) => {
|
|
213
262
|
const scope = node.members.find((member) => ts.isPropertyDeclaration(member) && ast.nodeName(member.name) === "scope" && !!ts.getModifiers(member)?.some(({ kind }) => kind === ts.SyntaxKind.StaticKeyword))?.initializer;
|
|
@@ -229,7 +278,7 @@ var guardFactoryReaderOf = (ts, ast, { spanOf, extentOf, unwrap, docOf }, pathOf
|
|
|
229
278
|
}
|
|
230
279
|
return functions;
|
|
231
280
|
};
|
|
232
|
-
const returnedOf = (body, guardNames) => {
|
|
281
|
+
const returnedOf = (body, guardNames, depth = 0) => {
|
|
233
282
|
const locals = new Map;
|
|
234
283
|
const pending = [];
|
|
235
284
|
const visit = (node) => {
|
|
@@ -250,6 +299,7 @@ var guardFactoryReaderOf = (ts, ast, { spanOf, extentOf, unwrap, docOf }, pathOf
|
|
|
250
299
|
const calls = [];
|
|
251
300
|
const seen = new Set;
|
|
252
301
|
const passed = new Set;
|
|
302
|
+
const returned = [];
|
|
253
303
|
for (let node = pending.pop();node; node = pending.pop()) {
|
|
254
304
|
if (seen.has(node))
|
|
255
305
|
continue;
|
|
@@ -257,6 +307,8 @@ var guardFactoryReaderOf = (ts, ast, { spanOf, extentOf, unwrap, docOf }, pathOf
|
|
|
257
307
|
const value = ts.isExpression(node) ? unwrap(node) : node;
|
|
258
308
|
if ((ts.isClassExpression(value) || ts.isClassDeclaration(value)) && implementsGuard(value, guardNames))
|
|
259
309
|
guard ??= value;
|
|
310
|
+
else if ((ts.isArrowFunction(value) || ts.isFunctionExpression(value)) && !passed.has(node) && depth < maxLayers)
|
|
311
|
+
returned.push(value.body);
|
|
260
312
|
else if (ts.isConditionalExpression(value))
|
|
261
313
|
pending.push(value.whenTrue, value.whenFalse);
|
|
262
314
|
else if (ts.isBinaryExpression(value))
|
|
@@ -266,15 +318,22 @@ var guardFactoryReaderOf = (ts, ast, { spanOf, extentOf, unwrap, docOf }, pathOf
|
|
|
266
318
|
if (local)
|
|
267
319
|
pending.push(local);
|
|
268
320
|
} else if (ts.isCallExpression(value)) {
|
|
269
|
-
const
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
321
|
+
const { root, layers } = layersOf(value);
|
|
322
|
+
const callee = pathOf(unwrap(root.expression));
|
|
323
|
+
if (callee && !passed.has(node) && !calls.some((call) => call.callee === callee))
|
|
324
|
+
calls.push({ callee, layers });
|
|
325
|
+
for (let call = value;ts.isCallExpression(call); call = unwrap(call.expression)) {
|
|
326
|
+
for (const arg of call.arguments)
|
|
327
|
+
passed.add(arg);
|
|
328
|
+
pending.push(...call.arguments);
|
|
329
|
+
}
|
|
275
330
|
}
|
|
276
331
|
}
|
|
277
|
-
|
|
332
|
+
const [inner] = returned;
|
|
333
|
+
if (guard || calls.length || !inner)
|
|
334
|
+
return { guard, calls, layers: 0 };
|
|
335
|
+
const nested = returnedOf(inner, guardNames, depth + 1);
|
|
336
|
+
return { ...nested, layers: nested.layers + 1 };
|
|
278
337
|
};
|
|
279
338
|
const guardFactoriesOf = (source, guardNames, isImported) => {
|
|
280
339
|
const functions = functionsOf(source);
|
|
@@ -284,7 +343,7 @@ var guardFactoryReaderOf = (ts, ast, { spanOf, extentOf, unwrap, docOf }, pathOf
|
|
|
284
343
|
for (let isGrowing = true;isGrowing; ) {
|
|
285
344
|
isGrowing = false;
|
|
286
345
|
for (const [name, { guard, calls }] of returned) {
|
|
287
|
-
if (members.has(name) || !guard && !calls.some(isFactoryCall))
|
|
346
|
+
if (members.has(name) || !guard && !calls.some(({ callee }) => isFactoryCall(callee)))
|
|
288
347
|
continue;
|
|
289
348
|
members.add(name);
|
|
290
349
|
isGrowing = true;
|
|
@@ -303,7 +362,8 @@ var guardFactoryReaderOf = (ts, ast, { spanOf, extentOf, unwrap, docOf }, pathOf
|
|
|
303
362
|
scope: made.guard ? scopeOf(made.guard) : null,
|
|
304
363
|
doc: docOf(source, found.statement),
|
|
305
364
|
direct: !!made.guard,
|
|
306
|
-
via: made.calls.filter(isFactoryCall)
|
|
365
|
+
via: made.calls.filter(({ callee }) => isFactoryCall(callee)),
|
|
366
|
+
layers: made.layers
|
|
307
367
|
});
|
|
308
368
|
}
|
|
309
369
|
return factories;
|
|
@@ -312,8 +372,8 @@ var guardFactoryReaderOf = (ts, ast, { spanOf, extentOf, unwrap, docOf }, pathOf
|
|
|
312
372
|
};
|
|
313
373
|
var createGuardFactReader = (ts, ast, base) => {
|
|
314
374
|
const { spanOf, extentOf, unwrap, docOf } = base;
|
|
315
|
-
const { pathOf, labelOf, guardsIn } = guardRefReaderOf(ts, ast, unwrap);
|
|
316
|
-
const { implementsGuard, scopeOf, guardFactoriesOf } = guardFactoryReaderOf(ts, ast, base, pathOf);
|
|
375
|
+
const { pathOf, layersOf, labelOf, guardsIn } = guardRefReaderOf(ts, ast, unwrap);
|
|
376
|
+
const { implementsGuard, scopeOf, guardFactoriesOf } = guardFactoryReaderOf(ts, ast, base, pathOf, layersOf);
|
|
317
377
|
const guardsOf = (source, imports, madeInPlace) => {
|
|
318
378
|
const guardNames = new Set([
|
|
319
379
|
"Guard",
|
|
@@ -326,15 +386,16 @@ var createGuardFactReader = (ts, ast, base) => {
|
|
|
326
386
|
const calls = [];
|
|
327
387
|
const makeOf = (made, value, isInPlace = false) => {
|
|
328
388
|
if (ts.isClassExpression(value) && implementsGuard(value, guardNames)) {
|
|
329
|
-
guards.push({ ...made, scope: scopeOf(value), factory: null });
|
|
389
|
+
guards.push({ ...made, scope: scopeOf(value), factory: null, layers: 0 });
|
|
330
390
|
return;
|
|
331
391
|
}
|
|
332
|
-
const
|
|
392
|
+
const { root, layers } = ts.isCallExpression(value) ? layersOf(value) : { root: null, layers: 0 };
|
|
393
|
+
const callee = root && pathOf(unwrap(root.expression));
|
|
333
394
|
const factory = callee && factories.get(callee);
|
|
334
395
|
if (factory)
|
|
335
|
-
guards.push({ ...made, scope: factory.scope, factory: factory.name });
|
|
396
|
+
guards.push({ ...made, scope: factory.scope, factory: factory.name, layers });
|
|
336
397
|
else if (callee && (isImported(callee) || isInPlace))
|
|
337
|
-
calls.push({ ...made, callee, kind: "call", scope: null });
|
|
398
|
+
calls.push({ ...made, callee, kind: "call", scope: null, layers });
|
|
338
399
|
};
|
|
339
400
|
for (const statement of source.statements) {
|
|
340
401
|
if (ts.isClassDeclaration(statement) && statement.name) {
|
|
@@ -348,9 +409,9 @@ var createGuardFactReader = (ts, ast, base) => {
|
|
|
348
409
|
const base = statement.heritageClauses?.find(({ token }) => token === ts.SyntaxKind.ExtendsKeyword)?.types[0];
|
|
349
410
|
const callee = base && pathOf(base.expression);
|
|
350
411
|
if (implementsGuard(statement, guardNames))
|
|
351
|
-
guards.push({ ...declared, factory: null });
|
|
412
|
+
guards.push({ ...declared, factory: null, layers: 0 });
|
|
352
413
|
else if (callee)
|
|
353
|
-
calls.push({ ...declared, callee, kind: "extends" });
|
|
414
|
+
calls.push({ ...declared, callee, kind: "extends", layers: 0 });
|
|
354
415
|
}
|
|
355
416
|
if (!ts.isVariableStatement(statement))
|
|
356
417
|
continue;
|
|
@@ -387,10 +448,6 @@ var createGuardFactReader = (ts, ast, base) => {
|
|
|
387
448
|
return { guardsIn, guardsOf };
|
|
388
449
|
};
|
|
389
450
|
|
|
390
|
-
// pkgs/@akanjs/language/escapeRegExp.ts
|
|
391
|
-
var regExpSpecials = /[\\^$.*+?()[\]{}|]/g;
|
|
392
|
-
var escapeRegExp = (text) => text.replace(regExpSpecials, (special) => `\\${special}`);
|
|
393
|
-
|
|
394
451
|
// pkgs/@akanjs/language/moduleFacts.ts
|
|
395
452
|
var testFilePattern = /\.(?:test|spec)\.tsx?$/;
|
|
396
453
|
var moduleCallees = new Set([
|
|
@@ -417,7 +474,7 @@ var ownerOf = (relativePath) => {
|
|
|
417
474
|
const [root, name] = relativePath.split("/");
|
|
418
475
|
return (root === "apps" || root === "libs") && name ? `${root}/${name}` : null;
|
|
419
476
|
};
|
|
420
|
-
var
|
|
477
|
+
var syntaxReaderOf = (ts, ast) => {
|
|
421
478
|
const spanOf = (source, node) => {
|
|
422
479
|
const start = node.getStart(source);
|
|
423
480
|
const end = node.getEnd();
|
|
@@ -475,6 +532,74 @@ var createFactReader = (ts, ast) => {
|
|
|
475
532
|
const node = keyName(property);
|
|
476
533
|
return name && node ? [{ name, span: spanOf(source, node), extent: extentOf(source, property) }] : [];
|
|
477
534
|
});
|
|
535
|
+
const verbReaderOf = (parameter) => {
|
|
536
|
+
const verbs = new Map;
|
|
537
|
+
if (parameter && ts.isObjectBindingPattern(parameter.name))
|
|
538
|
+
for (const element of parameter.name.elements) {
|
|
539
|
+
const verb = element.propertyName ?? element.name;
|
|
540
|
+
if (ts.isIdentifier(verb) && ts.isIdentifier(element.name))
|
|
541
|
+
verbs.set(element.name.text, verb.text);
|
|
542
|
+
}
|
|
543
|
+
const holder = parameter && ts.isIdentifier(parameter.name) ? parameter.name.text : null;
|
|
544
|
+
return (callee) => {
|
|
545
|
+
if (callee && ts.isIdentifier(callee))
|
|
546
|
+
return verbs.get(callee.text) ?? null;
|
|
547
|
+
if (callee && ts.isPropertyAccessExpression(callee) && ts.isIdentifier(callee.expression) && callee.expression.text === holder)
|
|
548
|
+
return callee.name.text;
|
|
549
|
+
return null;
|
|
550
|
+
};
|
|
551
|
+
};
|
|
552
|
+
return {
|
|
553
|
+
spanOf,
|
|
554
|
+
extentOf,
|
|
555
|
+
unwrap,
|
|
556
|
+
moduleRefOf,
|
|
557
|
+
returnedObject,
|
|
558
|
+
builderOf,
|
|
559
|
+
guardNameOf,
|
|
560
|
+
optionObjectOf,
|
|
561
|
+
chainOf,
|
|
562
|
+
keyName,
|
|
563
|
+
objectKeys,
|
|
564
|
+
verbReaderOf
|
|
565
|
+
};
|
|
566
|
+
};
|
|
567
|
+
var sourceReaderOf = (ts) => {
|
|
568
|
+
const importsOf = (statement) => {
|
|
569
|
+
const { importClause, moduleSpecifier } = statement;
|
|
570
|
+
if (!importClause || !ts.isStringLiteral(moduleSpecifier))
|
|
571
|
+
return [];
|
|
572
|
+
const from = moduleSpecifier.text;
|
|
573
|
+
const bindings = importClause.namedBindings;
|
|
574
|
+
return [
|
|
575
|
+
...importClause.name ? [{ name: importClause.name.text, imported: "default", from }] : [],
|
|
576
|
+
...bindings && ts.isNamespaceImport(bindings) ? [{ name: bindings.name.text, imported: "*", from }] : [],
|
|
577
|
+
...bindings && ts.isNamedImports(bindings) ? bindings.elements.map((element) => ({
|
|
578
|
+
name: element.name.text,
|
|
579
|
+
imported: (element.propertyName ?? element.name).text,
|
|
580
|
+
from
|
|
581
|
+
})) : []
|
|
582
|
+
];
|
|
583
|
+
};
|
|
584
|
+
const docOf = (source, node) => {
|
|
585
|
+
const { text } = source;
|
|
586
|
+
const ranges = ts.getLeadingCommentRanges(text, node.getFullStart()) ?? [];
|
|
587
|
+
const comments = [];
|
|
588
|
+
let end = node.getStart(source);
|
|
589
|
+
for (const range of [...ranges].reverse()) {
|
|
590
|
+
if ((text.slice(range.end, end).match(/\n/g)?.length ?? 0) > 1)
|
|
591
|
+
break;
|
|
592
|
+
comments.unshift(text.slice(range.pos, range.end));
|
|
593
|
+
end = range.pos;
|
|
594
|
+
}
|
|
595
|
+
const lines = comments.flatMap((comment) => comment.split(`
|
|
596
|
+
`)).map((line) => line.trim().replace(/^\/\*\*?|\*\/$/g, "").replace(/^(?:\/\/[?*!]?|\*)/, "").replace(/\{@link\s+([^}\s|]+)[^}]*\}/g, "$1").trim()).filter((line) => line && !/^(?:biome-ignore|eslint-|@ts-)/.test(line));
|
|
597
|
+
return lines.length ? lines.join(" ") : null;
|
|
598
|
+
};
|
|
599
|
+
const importsIn = (source) => source.statements.filter(ts.isImportDeclaration).flatMap(importsOf);
|
|
600
|
+
return { docOf, importsIn };
|
|
601
|
+
};
|
|
602
|
+
var signalKeyReaderOf = (ts, ast, { spanOf, extentOf, returnedObject, optionObjectOf, chainOf, verbReaderOf }, guardsIn) => {
|
|
478
603
|
const sliceKeysOf = (source, builder, made, model) => (returnedObject(builder)?.properties ?? []).flatMap((property) => {
|
|
479
604
|
if (!ts.isPropertyAssignment(property))
|
|
480
605
|
return [];
|
|
@@ -493,23 +618,30 @@ var createFactReader = (ts, ast) => {
|
|
|
493
618
|
}
|
|
494
619
|
];
|
|
495
620
|
});
|
|
496
|
-
const
|
|
497
|
-
const
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
621
|
+
const endpointKeysOf = (source, builder, made, model) => {
|
|
622
|
+
const verbOf = verbReaderOf(builder?.parameters[0]);
|
|
623
|
+
return (returnedObject(builder)?.properties ?? []).flatMap((property) => {
|
|
624
|
+
if (!ts.isPropertyAssignment(property))
|
|
625
|
+
return [];
|
|
626
|
+
const name = ast.nodeName(property.name);
|
|
627
|
+
if (!name)
|
|
628
|
+
return [];
|
|
629
|
+
const { root, methods } = chainOf(property.initializer);
|
|
630
|
+
return [
|
|
631
|
+
{
|
|
632
|
+
name,
|
|
633
|
+
span: spanOf(source, property.name),
|
|
634
|
+
extent: extentOf(source, property),
|
|
635
|
+
verb: root ? verbOf(root.expression) : null,
|
|
636
|
+
guards: root ? guardsIn(source, optionObjectOf(root), made, `${model}.${name}`) : [],
|
|
637
|
+
argCount: methods.filter((method) => argMethods.has(method)).length
|
|
638
|
+
}
|
|
639
|
+
];
|
|
640
|
+
});
|
|
512
641
|
};
|
|
642
|
+
return { sliceKeysOf, endpointKeysOf };
|
|
643
|
+
};
|
|
644
|
+
var jobKeyReaderOf = (ts, ast, { spanOf, extentOf, unwrap, returnedObject, chainOf, verbReaderOf }) => {
|
|
513
645
|
const numberOf = (expression) => {
|
|
514
646
|
const value = unwrap(expression);
|
|
515
647
|
if (ts.isNumericLiteral(value))
|
|
@@ -537,7 +669,7 @@ var createFactReader = (ts, ast) => {
|
|
|
537
669
|
const [size, unit] = intervalUnits.find(([size]) => ms >= size && ms % size === 0) ?? [1, "ms"];
|
|
538
670
|
return `${ms / size}${unit}`;
|
|
539
671
|
};
|
|
540
|
-
const modesOf = (option) => {
|
|
672
|
+
const modesOf = (option, type) => {
|
|
541
673
|
const object = option && unwrap(option);
|
|
542
674
|
if (!object || !ts.isObjectLiteralExpression(object))
|
|
543
675
|
return [];
|
|
@@ -547,9 +679,9 @@ var createFactReader = (ts, ast) => {
|
|
|
547
679
|
if (name === "enabled")
|
|
548
680
|
return value.kind === ts.SyntaxKind.FalseKeyword ? ["disabled"] : [];
|
|
549
681
|
if (name === "once")
|
|
550
|
-
return value.kind === ts.SyntaxKind.TrueKeyword ? ["once"] : [];
|
|
682
|
+
return type === "initialize" && value.kind === ts.SyntaxKind.TrueKeyword ? ["once"] : [];
|
|
551
683
|
if (name === "lock")
|
|
552
|
-
return value.kind === ts.SyntaxKind.FalseKeyword ? ["unlocked"] : [];
|
|
684
|
+
return type === "interval" && value.kind === ts.SyntaxKind.FalseKeyword ? ["unlocked"] : [];
|
|
553
685
|
if (name !== "serverMode" && name !== "operationMode")
|
|
554
686
|
return [];
|
|
555
687
|
const values = ts.isArrayLiteralExpression(value) ? [...value.elements] : [value];
|
|
@@ -567,7 +699,8 @@ var createFactReader = (ts, ast) => {
|
|
|
567
699
|
const { root } = chainOf(property.initializer);
|
|
568
700
|
const type = root ? verbOf(root.expression) : null;
|
|
569
701
|
const [first, second] = root?.arguments ?? [];
|
|
570
|
-
const
|
|
702
|
+
const cron = type === "cron" && first ? unwrap(first) : null;
|
|
703
|
+
const schedule = cron ? ts.isStringLiteralLike(cron) ? cron.text : cron.getText(source) : type === "interval" || type === "timeout" ? durationOf(first, source) : null;
|
|
571
704
|
const option = type === "initialize" || type === "destroy" ? first : second;
|
|
572
705
|
return [
|
|
573
706
|
{
|
|
@@ -576,11 +709,14 @@ var createFactReader = (ts, ast) => {
|
|
|
576
709
|
extent: extentOf(source, property),
|
|
577
710
|
type,
|
|
578
711
|
schedule,
|
|
579
|
-
modes: modesOf(option)
|
|
712
|
+
modes: modesOf(option, type)
|
|
580
713
|
}
|
|
581
714
|
];
|
|
582
715
|
});
|
|
583
716
|
};
|
|
717
|
+
return { internalKeysOf };
|
|
718
|
+
};
|
|
719
|
+
var serviceReaderOf = (ts, ast, { spanOf, extentOf, returnedObject, guardNameOf, chainOf, verbReaderOf }) => {
|
|
584
720
|
const plugsOf = (source, builder) => {
|
|
585
721
|
const verbOf = verbReaderOf(builder?.parameters[0]);
|
|
586
722
|
return (returnedObject(builder)?.properties ?? []).flatMap((property) => {
|
|
@@ -593,27 +729,30 @@ var createFactReader = (ts, ast) => {
|
|
|
593
729
|
return name && targetName ? [{ name, span: spanOf(source, property.name), target: targetName }] : [];
|
|
594
730
|
});
|
|
595
731
|
};
|
|
596
|
-
const
|
|
597
|
-
const
|
|
598
|
-
|
|
599
|
-
if (
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
span: spanOf(source, property.name),
|
|
609
|
-
extent: extentOf(source, property),
|
|
610
|
-
verb: root ? verbOf(root.expression) : null,
|
|
611
|
-
guards: root ? guardsIn(source, optionObjectOf(root), made, `${model}.${name}`) : [],
|
|
612
|
-
argCount: methods.filter((method) => argMethods.has(method)).length
|
|
613
|
-
}
|
|
614
|
-
];
|
|
615
|
-
});
|
|
732
|
+
const adaptorBindingsIn = (source) => {
|
|
733
|
+
const bindings = [];
|
|
734
|
+
const visit = (node) => {
|
|
735
|
+
if (ts.isCallExpression(node) && ts.isPropertyAccessExpression(node.expression) && node.expression.name.text === "applyAdaptor") {
|
|
736
|
+
const [role, adaptor] = node.arguments.map(guardNameOf);
|
|
737
|
+
if (role && adaptor)
|
|
738
|
+
bindings.push({ role, adaptor, span: spanOf(source, node.expression.name) });
|
|
739
|
+
}
|
|
740
|
+
ts.forEachChild(node, visit);
|
|
741
|
+
};
|
|
742
|
+
visit(source);
|
|
743
|
+
return bindings;
|
|
616
744
|
};
|
|
745
|
+
const methodsOf = (source, statement) => statement.members.flatMap((member) => {
|
|
746
|
+
if (!ts.isMethodDeclaration(member) || !member.body)
|
|
747
|
+
return [];
|
|
748
|
+
const name = ast.nodeName(member.name);
|
|
749
|
+
if (!name || ts.getModifiers(member)?.some(({ kind }) => kind === ts.SyntaxKind.StaticKeyword))
|
|
750
|
+
return [];
|
|
751
|
+
return [{ name, span: spanOf(source, member.name), extent: extentOf(source, member) }];
|
|
752
|
+
});
|
|
753
|
+
return { plugsOf, adaptorBindingsIn, methodsOf };
|
|
754
|
+
};
|
|
755
|
+
var constantReaderOf = (ts, ast, { spanOf, extentOf, unwrap, returnedObject, chainOf, keyName, objectKeys }) => {
|
|
617
756
|
const filterQueriesOf = (source, builder) => {
|
|
618
757
|
const query = returnedObject(builder)?.properties.find((property) => ts.isPropertyAssignment(property) && ast.nodeName(property.name) === "query")?.initializer;
|
|
619
758
|
return query && ts.isObjectLiteralExpression(query) ? objectKeys(source, query) : [];
|
|
@@ -651,48 +790,18 @@ var createFactReader = (ts, ast) => {
|
|
|
651
790
|
return [];
|
|
652
791
|
return list.elements.flatMap((element) => ts.isStringLiteralLike(element) ? [element.text] : []);
|
|
653
792
|
};
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
return [{ name, span: spanOf(source, member.name), extent: extentOf(source, member) }];
|
|
661
|
-
});
|
|
662
|
-
const importsOf = (statement) => {
|
|
663
|
-
const { importClause, moduleSpecifier } = statement;
|
|
664
|
-
if (!importClause || !ts.isStringLiteral(moduleSpecifier))
|
|
665
|
-
return [];
|
|
666
|
-
const from = moduleSpecifier.text;
|
|
667
|
-
const bindings = importClause.namedBindings;
|
|
668
|
-
return [
|
|
669
|
-
...importClause.name ? [{ name: importClause.name.text, imported: "default", from }] : [],
|
|
670
|
-
...bindings && ts.isNamespaceImport(bindings) ? [{ name: bindings.name.text, imported: "*", from }] : [],
|
|
671
|
-
...bindings && ts.isNamedImports(bindings) ? bindings.elements.map((element) => ({
|
|
672
|
-
name: element.name.text,
|
|
673
|
-
imported: (element.propertyName ?? element.name).text,
|
|
674
|
-
from
|
|
675
|
-
})) : []
|
|
676
|
-
];
|
|
677
|
-
};
|
|
678
|
-
const docOf = (source, node) => {
|
|
679
|
-
const { text } = source;
|
|
680
|
-
const ranges = ts.getLeadingCommentRanges(text, node.getFullStart()) ?? [];
|
|
681
|
-
const comments = [];
|
|
682
|
-
let end = node.getStart(source);
|
|
683
|
-
for (const range of [...ranges].reverse()) {
|
|
684
|
-
if ((text.slice(range.end, end).match(/\n/g)?.length ?? 0) > 1)
|
|
685
|
-
break;
|
|
686
|
-
comments.unshift(text.slice(range.pos, range.end));
|
|
687
|
-
end = range.pos;
|
|
688
|
-
}
|
|
689
|
-
const lines = comments.flatMap((comment) => comment.split(`
|
|
690
|
-
`)).map((line) => line.trim().replace(/^\/\*\*?|\*\/$/g, "").replace(/^(?:\/\/[?*!]?|\*)/, "").replace(/\{@link\s+([^}\s|]+)[^}]*\}/g, "$1").trim()).filter((line) => line && !/^(?:biome-ignore|eslint-|@ts-)/.test(line));
|
|
691
|
-
return lines.length ? lines.join(" ") : null;
|
|
692
|
-
};
|
|
793
|
+
return { constantOf, enumValuesOf, filterQueriesOf };
|
|
794
|
+
};
|
|
795
|
+
var createFactReader = (ts, ast) => {
|
|
796
|
+
const syntax = syntaxReaderOf(ts, ast);
|
|
797
|
+
const { spanOf, extentOf, unwrap, moduleRefOf, returnedObject, builderOf, chainOf, objectKeys } = syntax;
|
|
798
|
+
const { docOf, importsIn } = sourceReaderOf(ts);
|
|
693
799
|
const { guardsIn, guardsOf } = createGuardFactReader(ts, ast, { spanOf, extentOf, unwrap, docOf });
|
|
800
|
+
const { sliceKeysOf, endpointKeysOf } = signalKeyReaderOf(ts, ast, syntax, guardsIn);
|
|
801
|
+
const { internalKeysOf } = jobKeyReaderOf(ts, ast, syntax);
|
|
802
|
+
const { plugsOf, adaptorBindingsIn, methodsOf } = serviceReaderOf(ts, ast, syntax);
|
|
803
|
+
const { constantOf, enumValuesOf, filterQueriesOf } = constantReaderOf(ts, ast, syntax);
|
|
694
804
|
const lowerFirst = (text) => text.charAt(0).toLowerCase() + text.slice(1);
|
|
695
|
-
const importsIn = (source) => source.statements.filter(ts.isImportDeclaration).flatMap(importsOf);
|
|
696
805
|
const read = (source, owner) => {
|
|
697
806
|
const imports = importsIn(source);
|
|
698
807
|
const madeInPlace = [];
|
|
@@ -713,6 +822,7 @@ var createFactReader = (ts, ast) => {
|
|
|
713
822
|
endpoints: [],
|
|
714
823
|
internals: [],
|
|
715
824
|
adaptors: [],
|
|
825
|
+
adaptorBindings: source.text.includes("applyAdaptor") ? adaptorBindingsIn(source) : [],
|
|
716
826
|
stores: []
|
|
717
827
|
};
|
|
718
828
|
for (const statement of source.statements) {
|
|
@@ -737,7 +847,8 @@ var createFactReader = (ts, ast) => {
|
|
|
737
847
|
...name,
|
|
738
848
|
model: moduleRefOf(call.arguments[0], "db"),
|
|
739
849
|
methods: methodsOf(source, statement),
|
|
740
|
-
plugs: plugsOf(source, builder)
|
|
850
|
+
plugs: plugsOf(source, builder),
|
|
851
|
+
fields: objectKeys(source, returnedObject(builder)).map(({ name }) => name)
|
|
741
852
|
});
|
|
742
853
|
else if (callee === "slice") {
|
|
743
854
|
const model = moduleRefOf(call.arguments[0], "srv");
|
|
@@ -788,7 +899,11 @@ var frameworkOwner = "akanjs";
|
|
|
788
899
|
var frameworkPattern = /^akanjs(?:\/|$)/;
|
|
789
900
|
var aliasPattern = /^@(apps|libs)\/([^/]+)/;
|
|
790
901
|
var maxMapDepth = 4;
|
|
902
|
+
var identifierPattern = /^[\p{ID_Start}$_][\p{ID_Continue}$\u200c\u200d]*$/u;
|
|
791
903
|
var starExportPattern = /export\s*\*\s*from\s*["']([^"']+)["']/g;
|
|
904
|
+
var facetEntryPattern = new RegExp(`^((?:apps|libs)/[^/]+/(${barrelFacetDirs.map(escapeRegExp).join("|")}))/([^/]+)(/)?`);
|
|
905
|
+
var exportingPatternOf = (name) => new RegExp(`export\\s*\\{(?:[^}]*?[\\s,])?${escapeRegExp(name)}(?![\\w$])`);
|
|
906
|
+
var exportMentioningPatternOf = (name) => new RegExp(`export(?![\\w$])[^;]*?(?<![\\w$])${escapeRegExp(name)}(?![\\w$])`);
|
|
792
907
|
var declaringPatternOf = (name, isAnyBinding) => {
|
|
793
908
|
const escaped = escapeRegExp(name);
|
|
794
909
|
const braced = "\\{(?:[^}]*?[\\s,])?";
|
|
@@ -810,8 +925,12 @@ class GuardResolver {
|
|
|
810
925
|
#reexports = new Map;
|
|
811
926
|
#declarations = new Map;
|
|
812
927
|
#starExports = new Map;
|
|
928
|
+
#moduleExports = new Map;
|
|
929
|
+
#fileStars = new Map;
|
|
930
|
+
#starReach = new Map;
|
|
813
931
|
#ownerFiles = null;
|
|
814
932
|
#modules = null;
|
|
933
|
+
#barrels = null;
|
|
815
934
|
constructor(source, routes) {
|
|
816
935
|
this.#source = source;
|
|
817
936
|
this.#routes = routes;
|
|
@@ -835,21 +954,26 @@ ${name}`);
|
|
|
835
954
|
made: [],
|
|
836
955
|
isReal: fact.direct,
|
|
837
956
|
scope: fact.scope,
|
|
957
|
+
layers: fact.layers,
|
|
838
958
|
targets: []
|
|
839
959
|
};
|
|
840
960
|
factories.set(fact.name, [...factories.get(fact.name) ?? [], factory]);
|
|
841
961
|
declaredFactories.push(factory);
|
|
842
962
|
}
|
|
843
963
|
for (const factory of declaredFactories)
|
|
844
|
-
factory.targets = factory.fact.via.
|
|
964
|
+
factory.targets = factory.fact.via.flatMap(({ callee, layers }) => {
|
|
965
|
+
const target = this.#factoryAt(factories, callee, factory.site);
|
|
966
|
+
return target ? [{ target, layers }] : [];
|
|
967
|
+
});
|
|
845
968
|
for (let isGrowing = true;isGrowing; ) {
|
|
846
969
|
isGrowing = false;
|
|
847
970
|
for (const factory of declaredFactories) {
|
|
848
|
-
const
|
|
849
|
-
if (factory.isReal || !
|
|
971
|
+
const via = factory.targets.find(({ target, layers }) => target.isReal && target.layers >= layers);
|
|
972
|
+
if (factory.isReal || !via)
|
|
850
973
|
continue;
|
|
851
974
|
factory.isReal = true;
|
|
852
|
-
factory.
|
|
975
|
+
factory.layers = factory.fact.layers + via.target.layers - via.layers;
|
|
976
|
+
factory.scope ??= via.target.scope;
|
|
853
977
|
isGrowing = true;
|
|
854
978
|
}
|
|
855
979
|
}
|
|
@@ -859,7 +983,7 @@ ${name}`);
|
|
|
859
983
|
seen.add(factory);
|
|
860
984
|
return [
|
|
861
985
|
{ fileName: factory.site.fileName, extent: factory.fact.extent },
|
|
862
|
-
...factory.targets.filter((target) => target.isReal).flatMap((target) => partsOf(target, seen))
|
|
986
|
+
...factory.targets.filter(({ target }) => target.isReal).flatMap(({ target }) => partsOf(target, seen))
|
|
863
987
|
];
|
|
864
988
|
};
|
|
865
989
|
const declare = (file, made, scope, parts) => {
|
|
@@ -880,7 +1004,7 @@ ${name}`, guard);
|
|
|
880
1004
|
const factory = made.factory ? factories.get(made.factory)?.find((other) => other.site.fileName === file.fileName) : undefined;
|
|
881
1005
|
if (!made.factory)
|
|
882
1006
|
declare(file, made, made.scope, []);
|
|
883
|
-
else if (factory?.isReal)
|
|
1007
|
+
else if (factory?.isReal && factory.layers === made.layers)
|
|
884
1008
|
factory.made.push(declare(file, made, factory.scope, partsOf(factory)));
|
|
885
1009
|
}
|
|
886
1010
|
for (const made of file.guardCalls) {
|
|
@@ -889,7 +1013,7 @@ ${name}`, guard);
|
|
|
889
1013
|
continue;
|
|
890
1014
|
}
|
|
891
1015
|
const factory = this.#factoryAt(factories, made.callee, file);
|
|
892
|
-
if (factory?.isReal)
|
|
1016
|
+
if (factory?.isReal && factory.layers === made.layers)
|
|
893
1017
|
factory.made.push(declare(file, made, factory.scope, partsOf(factory)));
|
|
894
1018
|
}
|
|
895
1019
|
}
|
|
@@ -934,7 +1058,7 @@ ${name}`, guard);
|
|
|
934
1058
|
const own = this.#nearest(candidates.filter((other) => other.owner === from), ({ site }) => site.fileName, near);
|
|
935
1059
|
if (own)
|
|
936
1060
|
return own;
|
|
937
|
-
const reexport = from && depth < maxMapDepth ? this
|
|
1061
|
+
const reexport = from && depth < maxMapDepth ? this.#reexportOf(from, name, near) : null;
|
|
938
1062
|
if (reexport)
|
|
939
1063
|
return this.#factoryAt(factories, reexport.local, reexport.site, depth + 1);
|
|
940
1064
|
return from && near ? this.#throughStar(candidates, from, name, near) : undefined;
|
|
@@ -972,13 +1096,13 @@ ${name}`, guard);
|
|
|
972
1096
|
const visible = isBase ? undefined : declared.find((other) => this.visible(other.owner, site.owner));
|
|
973
1097
|
return visible ? { guard: visible } : { name, from };
|
|
974
1098
|
}
|
|
975
|
-
const reexport = from && depth < maxMapDepth ? this
|
|
1099
|
+
const reexport = from && depth < maxMapDepth ? this.#reexportOf(from, name, near) : null;
|
|
976
1100
|
if (reexport)
|
|
977
1101
|
return this.#findGuard(reexport.local, reexport.site, depth + 1, isBase);
|
|
978
1102
|
const reached = from && near ? this.#throughStar(declared, from, name, near) : undefined;
|
|
979
1103
|
return reached ? { guard: reached } : { name, from };
|
|
980
1104
|
}
|
|
981
|
-
reexportOf(owner, name, near) {
|
|
1105
|
+
#reexportOf(owner, name, near) {
|
|
982
1106
|
const key = `${owner}
|
|
983
1107
|
${name}
|
|
984
1108
|
${near ?? ""}`;
|
|
@@ -986,7 +1110,7 @@ ${near ?? ""}`;
|
|
|
986
1110
|
if (cached !== undefined)
|
|
987
1111
|
return cached;
|
|
988
1112
|
let found = null;
|
|
989
|
-
const exporting =
|
|
1113
|
+
const exporting = exportingPatternOf(name);
|
|
990
1114
|
for (const fileName of this.#filesOf(owner, name, near)) {
|
|
991
1115
|
const text = this.#source.readText(fileName);
|
|
992
1116
|
if (text === undefined || !exporting.test(text))
|
|
@@ -1004,7 +1128,7 @@ ${near ?? ""}`;
|
|
|
1004
1128
|
this.#reexports.set(key, found);
|
|
1005
1129
|
return found;
|
|
1006
1130
|
}
|
|
1007
|
-
#reexportIn(source, name) {
|
|
1131
|
+
#reexportIn(source, name, takesPackageDefault = false) {
|
|
1008
1132
|
const { ts, reader } = this.#source;
|
|
1009
1133
|
for (const statement of source.statements) {
|
|
1010
1134
|
if (!ts.isExportDeclaration(statement) || statement.isTypeOnly)
|
|
@@ -1021,7 +1145,9 @@ ${near ?? ""}`;
|
|
|
1021
1145
|
const imported = reader.importsIn(source).find((item) => item.name === original);
|
|
1022
1146
|
if (!imported)
|
|
1023
1147
|
return { name: original, from: null };
|
|
1024
|
-
|
|
1148
|
+
if (imported.imported === "default")
|
|
1149
|
+
return takesPackageDefault && this.pathOfSpecifier(source.fileName, imported.from) === null ? { name: "default", from: imported.from } : null;
|
|
1150
|
+
return imported.imported === "*" ? null : { name: imported.imported, from: imported.from };
|
|
1025
1151
|
}
|
|
1026
1152
|
return null;
|
|
1027
1153
|
}
|
|
@@ -1030,7 +1156,9 @@ ${near ?? ""}`;
|
|
|
1030
1156
|
const relative = this.#source.relative(fileName);
|
|
1031
1157
|
return !!near && (relative.startsWith(`${near}/`) || relative.replace(/\.tsx?$/, "") === near);
|
|
1032
1158
|
};
|
|
1033
|
-
|
|
1159
|
+
if (!identifierPattern.test(name))
|
|
1160
|
+
return [];
|
|
1161
|
+
const candidates = this.#filesIn(owner).filter(([, words]) => words.includes(`
|
|
1034
1162
|
${name}
|
|
1035
1163
|
`)).map(([fileName]) => fileName);
|
|
1036
1164
|
return [...candidates.filter(isNear), ...candidates.filter((other) => !isNear(other))];
|
|
@@ -1047,7 +1175,7 @@ ${owner ?? ""}`;
|
|
|
1047
1175
|
const entries = [];
|
|
1048
1176
|
const fileNames = [
|
|
1049
1177
|
...fileName ? [fileName] : [],
|
|
1050
|
-
...(owner === null ? [] : this
|
|
1178
|
+
...(owner === null ? [] : this.#filesIn(owner)).filter(([other, words]) => other !== fileName && words.includes(`
|
|
1051
1179
|
${objectName}
|
|
1052
1180
|
`) && words.includes(`
|
|
1053
1181
|
${member}
|
|
@@ -1121,30 +1249,120 @@ ${near ?? ""}`;
|
|
|
1121
1249
|
#throughStar(declared, owner, name, near) {
|
|
1122
1250
|
if (!declared.length)
|
|
1123
1251
|
return;
|
|
1124
|
-
const { owners, isOpaque } = this
|
|
1252
|
+
const { owners, isOpaque } = this.starExportsOf(owner, near);
|
|
1125
1253
|
const reached = declared.filter((other) => other.owner !== null && owners.includes(other.owner));
|
|
1126
1254
|
return reached.length === 1 && !isOpaque && !this.declares(owner, name) ? reached[0] : undefined;
|
|
1127
1255
|
}
|
|
1128
|
-
|
|
1129
|
-
const
|
|
1256
|
+
starExportsOf(owner, near) {
|
|
1257
|
+
const key = `${owner}
|
|
1258
|
+
${near}`;
|
|
1259
|
+
const cached = this.#starExports.get(key);
|
|
1130
1260
|
if (cached)
|
|
1131
1261
|
return cached;
|
|
1132
|
-
const found = { owners: [], isOpaque: false };
|
|
1133
|
-
this.#starExports.set(
|
|
1134
|
-
const
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1262
|
+
const found = { owners: [], packages: [], paths: [near], isOpaque: false };
|
|
1263
|
+
this.#starExports.set(key, found);
|
|
1264
|
+
const reach = (specifier, path, target) => {
|
|
1265
|
+
if (path === null && !found.packages.includes(specifier))
|
|
1266
|
+
found.packages.push(specifier);
|
|
1267
|
+
if (target === undefined || target === frameworkOwner || path === null)
|
|
1268
|
+
found.isOpaque = true;
|
|
1269
|
+
else if (!found.paths.includes(path))
|
|
1270
|
+
found.paths.push(path);
|
|
1271
|
+
if (target && target !== frameworkOwner && target !== owner && !found.owners.includes(target))
|
|
1272
|
+
found.owners.push(target);
|
|
1273
|
+
};
|
|
1274
|
+
for (let idx = 0;idx < found.paths.length; idx++) {
|
|
1275
|
+
const path = found.paths[idx] ?? "";
|
|
1276
|
+
for (const module2 of this.#barrelAt(path) ?? [])
|
|
1277
|
+
reach(module2, module2, ownerOf(module2) ?? undefined);
|
|
1278
|
+
for (const fileName of this.#modulesAt(path))
|
|
1279
|
+
for (const [, specifier = ""] of this.#source.readText(fileName)?.matchAll(starExportPattern) ?? [])
|
|
1280
|
+
reach(specifier, this.pathOfSpecifier(fileName, specifier), this.ownerOfSpecifier(fileName, specifier));
|
|
1281
|
+
}
|
|
1282
|
+
return found;
|
|
1283
|
+
}
|
|
1284
|
+
exportsAt(path, name) {
|
|
1285
|
+
const key = `${path}
|
|
1286
|
+
${name}`;
|
|
1287
|
+
const cached = this.#moduleExports.get(key);
|
|
1288
|
+
if (cached)
|
|
1289
|
+
return cached;
|
|
1290
|
+
const found = { named: null, stars: [], isLocal: false };
|
|
1291
|
+
const stars = new Set(this.#barrelAt(path));
|
|
1292
|
+
for (const fileName of this.#modulesAt(path)) {
|
|
1293
|
+
const text = this.#source.readText(fileName);
|
|
1294
|
+
if (text === undefined)
|
|
1295
|
+
continue;
|
|
1296
|
+
const named = text.includes(name) && identifierPattern.test(name) && exportingPatternOf(name).test(text) ? this.#reexportIn(this.#source.parse(fileName, text), name, true) : null;
|
|
1297
|
+
if (named) {
|
|
1298
|
+
found.named = { ...named, fileName };
|
|
1299
|
+
break;
|
|
1300
|
+
}
|
|
1301
|
+
if (text.includes(name) && exportMentioningPatternOf(name).test(text) && this.#exportsLocally(this.#source.parse(fileName, text), name)) {
|
|
1302
|
+
found.isLocal = true;
|
|
1303
|
+
break;
|
|
1304
|
+
}
|
|
1305
|
+
for (const target of this.#starsIn(fileName, text))
|
|
1306
|
+
stars.add(target);
|
|
1307
|
+
}
|
|
1308
|
+
if (!found.named && !found.isLocal)
|
|
1309
|
+
found.stars = [...stars];
|
|
1310
|
+
this.#moduleExports.set(key, found);
|
|
1311
|
+
return found;
|
|
1312
|
+
}
|
|
1313
|
+
#exportsLocally(source, name) {
|
|
1314
|
+
const { ts } = this.#source;
|
|
1315
|
+
const binds = (node) => ts.isIdentifier(node) ? node.text === name : node.elements.some((element) => !ts.isOmittedExpression(element) && binds(element.name));
|
|
1316
|
+
return source.statements.some((statement) => {
|
|
1317
|
+
if (ts.isExportDeclaration(statement)) {
|
|
1318
|
+
const { exportClause, isTypeOnly, moduleSpecifier } = statement;
|
|
1319
|
+
if (isTypeOnly || !exportClause)
|
|
1320
|
+
return false;
|
|
1321
|
+
if (ts.isNamespaceExport(exportClause))
|
|
1322
|
+
return exportClause.name.text === name;
|
|
1323
|
+
return !moduleSpecifier && ts.isNamedExports(exportClause) && exportClause.elements.some((element) => !element.isTypeOnly && element.name.text === name);
|
|
1324
|
+
}
|
|
1325
|
+
const modifiers = ts.canHaveModifiers(statement) ? ts.getModifiers(statement) ?? [] : [];
|
|
1326
|
+
if (!modifiers.some(({ kind }) => kind === ts.SyntaxKind.ExportKeyword) || modifiers.some(({ kind }) => kind === ts.SyntaxKind.DefaultKeyword))
|
|
1327
|
+
return false;
|
|
1328
|
+
if (ts.isVariableStatement(statement))
|
|
1329
|
+
return statement.declarationList.declarations.some((declaration) => binds(declaration.name));
|
|
1330
|
+
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;
|
|
1331
|
+
});
|
|
1332
|
+
}
|
|
1333
|
+
mentionsAlong(path, name) {
|
|
1334
|
+
return this.#starReachOf(path).some((text) => text.includes(name));
|
|
1335
|
+
}
|
|
1336
|
+
#starReachOf(path) {
|
|
1337
|
+
const cached = this.#starReach.get(path);
|
|
1338
|
+
if (cached)
|
|
1339
|
+
return cached;
|
|
1340
|
+
const paths = new Set([path]);
|
|
1341
|
+
const texts = [];
|
|
1342
|
+
for (const at of paths) {
|
|
1343
|
+
for (const next of this.#barrelAt(at) ?? [])
|
|
1344
|
+
paths.add(next);
|
|
1345
|
+
for (const fileName of this.#modulesAt(at)) {
|
|
1346
|
+
const text = this.#source.readText(fileName) ?? "";
|
|
1347
|
+
texts.push(text);
|
|
1348
|
+
for (const next of this.#starsIn(fileName, text))
|
|
1349
|
+
paths.add(next);
|
|
1147
1350
|
}
|
|
1351
|
+
}
|
|
1352
|
+
this.#starReach.set(path, texts);
|
|
1353
|
+
return texts;
|
|
1354
|
+
}
|
|
1355
|
+
#starsIn(fileName, text) {
|
|
1356
|
+
const cached = this.#fileStars.get(fileName);
|
|
1357
|
+
if (cached)
|
|
1358
|
+
return cached;
|
|
1359
|
+
const found = [];
|
|
1360
|
+
for (const [, specifier = ""] of text.matchAll(starExportPattern)) {
|
|
1361
|
+
const target = this.pathOfSpecifier(fileName, specifier);
|
|
1362
|
+
if (target !== null)
|
|
1363
|
+
found.push(target);
|
|
1364
|
+
}
|
|
1365
|
+
this.#fileStars.set(fileName, found);
|
|
1148
1366
|
return found;
|
|
1149
1367
|
}
|
|
1150
1368
|
#modulesAt(path) {
|
|
@@ -1158,11 +1376,33 @@ ${near ?? ""}`;
|
|
|
1158
1376
|
}
|
|
1159
1377
|
return this.#modules.get(path) ?? [];
|
|
1160
1378
|
}
|
|
1379
|
+
#barrelAt(path) {
|
|
1380
|
+
if (!this.#barrels) {
|
|
1381
|
+
const entries = new Map;
|
|
1382
|
+
for (const [fileName] of this.#source.files) {
|
|
1383
|
+
const [, folder, facet, entry, nested] = this.#source.relative(fileName).match(facetEntryPattern) ?? [];
|
|
1384
|
+
if (!folder || !facet || !entry)
|
|
1385
|
+
continue;
|
|
1386
|
+
const found = entries.get(folder) ?? { facet, files: new Set, dirs: new Set };
|
|
1387
|
+
(nested ? found.dirs : found.files).add(entry);
|
|
1388
|
+
entries.set(folder, found);
|
|
1389
|
+
}
|
|
1390
|
+
this.#barrels = new Map([...entries].map(([folder, { facet, files, dirs }]) => [
|
|
1391
|
+
folder,
|
|
1392
|
+
facetBarrelNamesOf(facet, [...files], [...dirs]).map((name) => `${folder}/${name}`)
|
|
1393
|
+
]));
|
|
1394
|
+
}
|
|
1395
|
+
return this.#modulesAt(path).length ? undefined : this.#barrels.get(path);
|
|
1396
|
+
}
|
|
1161
1397
|
declares(owner, name) {
|
|
1162
1398
|
const declaring = declaringPatternOf(name, true);
|
|
1163
1399
|
return this.#filesOf(owner, name, null).some((fileName) => declaring.test(this.#source.readText(fileName) ?? ""));
|
|
1164
1400
|
}
|
|
1165
|
-
|
|
1401
|
+
declaresAt(path, name) {
|
|
1402
|
+
const declaring = declaringPatternOf(name, true);
|
|
1403
|
+
return this.#modulesAt(path).some((fileName) => declaring.test(this.#source.readText(fileName) ?? ""));
|
|
1404
|
+
}
|
|
1405
|
+
#filesIn(owner) {
|
|
1166
1406
|
if (!this.#ownerFiles) {
|
|
1167
1407
|
this.#ownerFiles = new Map;
|
|
1168
1408
|
for (const entry of this.#source.files) {
|
|
@@ -1212,6 +1452,196 @@ ${near ?? ""}`;
|
|
|
1212
1452
|
}
|
|
1213
1453
|
}
|
|
1214
1454
|
|
|
1455
|
+
// pkgs/@akanjs/language/adaptorResolver.ts
|
|
1456
|
+
var packageOf = (specifier) => specifier.split("/").slice(0, specifier.startsWith("@") ? 2 : 1).join("/");
|
|
1457
|
+
var packageKeyOf = ({ name, from }) => `${packageOf(from)}
|
|
1458
|
+
${name}`;
|
|
1459
|
+
var exportedKeyOf = (item) => ("fact" in item) ? item.id : ("local" in item) ? `${item.local}
|
|
1460
|
+
` : packageKeyOf(item);
|
|
1461
|
+
var isPackageExport = (item) => ("from" in item);
|
|
1462
|
+
|
|
1463
|
+
class AdaptorResolver {
|
|
1464
|
+
#source;
|
|
1465
|
+
#resolver;
|
|
1466
|
+
#sink;
|
|
1467
|
+
#adaptors = new Map;
|
|
1468
|
+
#plugs = new Map;
|
|
1469
|
+
#serviceFields = new Set;
|
|
1470
|
+
#exported = new Map;
|
|
1471
|
+
constructor(source, resolver, sink) {
|
|
1472
|
+
this.#source = source;
|
|
1473
|
+
this.#resolver = resolver;
|
|
1474
|
+
this.#sink = sink;
|
|
1475
|
+
}
|
|
1476
|
+
declare(facts) {
|
|
1477
|
+
const counts = new Map;
|
|
1478
|
+
for (const file of facts)
|
|
1479
|
+
for (const fact of file.adaptors) {
|
|
1480
|
+
const key = this.#sink.key("adaptor", file.owner, fact.name);
|
|
1481
|
+
counts.set(key, (counts.get(key) ?? 0) + 1);
|
|
1482
|
+
}
|
|
1483
|
+
const declared = facts.flatMap((file) => file.adaptors.map((fact) => {
|
|
1484
|
+
const key = this.#sink.key("adaptor", file.owner, fact.name);
|
|
1485
|
+
const id = (counts.get(key) ?? 0) > 1 ? this.#sink.key("adaptor", file.owner, `${this.#resolver.inOwner(file.fileName, file.owner)}#${fact.name}`) : key;
|
|
1486
|
+
const adaptor = { fact, owner: file.owner, fileName: file.fileName, id };
|
|
1487
|
+
this.#adaptors.set(fact.name, [...this.#adaptors.get(fact.name) ?? [], adaptor]);
|
|
1488
|
+
this.#nodeOf(adaptor);
|
|
1489
|
+
return { adaptor, file };
|
|
1490
|
+
}));
|
|
1491
|
+
for (const { adaptor, file } of declared)
|
|
1492
|
+
for (const plug of adaptor.fact.plugs)
|
|
1493
|
+
this.#sink.addEdge(adaptor.id, this.#idOf(plug.target, file), "plugs", plug.name, this.#sink.location(plug.span));
|
|
1494
|
+
for (const file of facts)
|
|
1495
|
+
for (const binding of file.adaptorBindings)
|
|
1496
|
+
this.#sink.addEdge(this.#idOf(binding.role, file), this.#idOf(binding.adaptor, file), "binds", file.owner, this.#sink.location(binding.span));
|
|
1497
|
+
}
|
|
1498
|
+
addService(refName, service, file) {
|
|
1499
|
+
for (const plug of service.plugs) {
|
|
1500
|
+
const key = `${refName}
|
|
1501
|
+
${plug.name}`;
|
|
1502
|
+
this.#plugs.set(key, [
|
|
1503
|
+
...this.#plugs.get(key) ?? [],
|
|
1504
|
+
{ owner: file.owner, target: this.#idOf(plug.target, file) }
|
|
1505
|
+
]);
|
|
1506
|
+
}
|
|
1507
|
+
for (const field of service.fields)
|
|
1508
|
+
this.#serviceFields.add(`${file.owner ?? ""}
|
|
1509
|
+
${refName}
|
|
1510
|
+
${field}`);
|
|
1511
|
+
}
|
|
1512
|
+
pluggedOf(owner, module2, field) {
|
|
1513
|
+
const plugs = this.#plugs.get(`${module2}
|
|
1514
|
+
${field}`) ?? [];
|
|
1515
|
+
const own = plugs.filter((plug) => plug.owner === owner);
|
|
1516
|
+
if (!own.length && this.#serviceFields.has(`${owner ?? ""}
|
|
1517
|
+
${module2}
|
|
1518
|
+
${field}`))
|
|
1519
|
+
return [];
|
|
1520
|
+
const inherited = own.length ? own : plugs.filter((plug) => this.#resolver.visible(plug.owner, owner));
|
|
1521
|
+
return [...new Set(inherited.map(({ target }) => target))];
|
|
1522
|
+
}
|
|
1523
|
+
#idOf(local, file) {
|
|
1524
|
+
const [head, member] = local.split(".");
|
|
1525
|
+
const imported = file.imports.find((item) => item.name === head);
|
|
1526
|
+
const name = member ?? (imported && imported.imported !== "default" && imported.imported !== "*" ? imported.imported : head);
|
|
1527
|
+
const path = imported ? this.#resolver.pathOfSpecifier(file.fileName, imported.from) : null;
|
|
1528
|
+
if (imported && path === null && !frameworkPattern.test(imported.from))
|
|
1529
|
+
return this.#packageAdaptorOf(name, imported.from);
|
|
1530
|
+
const from = imported ? this.#resolver.ownerOfSpecifier(file.fileName, imported.from) : undefined;
|
|
1531
|
+
const declared = this.#adaptors.get(name) ?? [];
|
|
1532
|
+
const holder = from === undefined ? file.owner : from;
|
|
1533
|
+
const own = this.#adaptorIn(name, declared, holder, path, file.fileName);
|
|
1534
|
+
if (own && "from" in own)
|
|
1535
|
+
return this.#packageAdaptorOf(own.name, own.from);
|
|
1536
|
+
const found = own === undefined && from !== frameworkOwner ? declared.find((adaptor) => this.#resolver.visible(adaptor.owner, holder)) : own;
|
|
1537
|
+
if (found)
|
|
1538
|
+
return found.id;
|
|
1539
|
+
const reexported = own === undefined && from && from !== frameworkOwner ? this.#packageShimOf(from, name, path) : null;
|
|
1540
|
+
if (reexported)
|
|
1541
|
+
return this.#packageAdaptorOf(reexported.name, reexported.from);
|
|
1542
|
+
const owner = from === frameworkOwner ? null : imported ? from ?? null : file.owner;
|
|
1543
|
+
const detail = from === frameworkOwner ? [frameworkOwner] : [];
|
|
1544
|
+
return this.#sink.addNode(this.#sink.key("adaptor", owner, name), "adaptor", owner, name, null, detail).id;
|
|
1545
|
+
}
|
|
1546
|
+
#adaptorIn(name, declared, owner, path, fileName) {
|
|
1547
|
+
const own = declared.filter((adaptor) => adaptor.owner === owner);
|
|
1548
|
+
const [first] = own;
|
|
1549
|
+
if (path === null)
|
|
1550
|
+
return own.find((adaptor) => adaptor.fileName === fileName) ?? first;
|
|
1551
|
+
if (own.length === 1)
|
|
1552
|
+
return first;
|
|
1553
|
+
const exported = this.#exportedAt(name, path).filter((item) => first || !isPackageExport(item));
|
|
1554
|
+
const [only] = exported;
|
|
1555
|
+
if (only)
|
|
1556
|
+
return exported.length === 1 && !("local" in only) ? only : null;
|
|
1557
|
+
return first ? null : undefined;
|
|
1558
|
+
}
|
|
1559
|
+
#exportedAt(name, path) {
|
|
1560
|
+
const key = `${path}
|
|
1561
|
+
${name}`;
|
|
1562
|
+
const cached = this.#exported.get(key);
|
|
1563
|
+
if (cached)
|
|
1564
|
+
return cached;
|
|
1565
|
+
if (!this.#resolver.mentionsAlong(path, name)) {
|
|
1566
|
+
this.#exported.set(key, []);
|
|
1567
|
+
return [];
|
|
1568
|
+
}
|
|
1569
|
+
const reached = new Map;
|
|
1570
|
+
const seen = new Set;
|
|
1571
|
+
const pending = [[name, path]];
|
|
1572
|
+
for (let next = pending.pop();next; next = pending.pop()) {
|
|
1573
|
+
const [wanted, at] = next;
|
|
1574
|
+
if (seen.has(`${at}
|
|
1575
|
+
${wanted}`))
|
|
1576
|
+
continue;
|
|
1577
|
+
seen.add(`${at}
|
|
1578
|
+
${wanted}`);
|
|
1579
|
+
for (const item of this.#bindingAt(wanted, at, pending, name))
|
|
1580
|
+
reached.set(exportedKeyOf(item), item);
|
|
1581
|
+
}
|
|
1582
|
+
const found = [...reached.values()];
|
|
1583
|
+
this.#exported.set(key, found);
|
|
1584
|
+
return found;
|
|
1585
|
+
}
|
|
1586
|
+
#bindingAt(name, path, pending, plugged) {
|
|
1587
|
+
const here = this.#declaredAt(name, path);
|
|
1588
|
+
if (here.length)
|
|
1589
|
+
return here;
|
|
1590
|
+
const { named, stars, isLocal } = this.#resolver.exportsAt(path, name);
|
|
1591
|
+
if (isLocal)
|
|
1592
|
+
return [{ local: path }];
|
|
1593
|
+
if (named?.from === null) {
|
|
1594
|
+
const local = this.#declaredAt(named.name, path);
|
|
1595
|
+
return local.length ? local : [{ local: path }];
|
|
1596
|
+
}
|
|
1597
|
+
if (named) {
|
|
1598
|
+
const target = this.#resolver.pathOfSpecifier(named.fileName, named.from);
|
|
1599
|
+
if (target === null) {
|
|
1600
|
+
const exposed = named.name !== "default" ? named.name : name !== "default" ? name : plugged;
|
|
1601
|
+
return [{ name: exposed, from: named.from }];
|
|
1602
|
+
}
|
|
1603
|
+
pending.push([named.name, target]);
|
|
1604
|
+
return [];
|
|
1605
|
+
}
|
|
1606
|
+
for (const star of stars)
|
|
1607
|
+
pending.push([name, star]);
|
|
1608
|
+
return [];
|
|
1609
|
+
}
|
|
1610
|
+
#declaredAt(name, path) {
|
|
1611
|
+
return (this.#adaptors.get(name) ?? []).filter((adaptor) => {
|
|
1612
|
+
const module2 = this.#source.relative(adaptor.fileName).replace(/\.tsx?$/, "");
|
|
1613
|
+
return module2 === path || module2 === `${path}/index`;
|
|
1614
|
+
});
|
|
1615
|
+
}
|
|
1616
|
+
#packageAdaptorOf(name, specifier) {
|
|
1617
|
+
if (frameworkPattern.test(specifier))
|
|
1618
|
+
return this.#sink.addNode(this.#sink.key("adaptor", null, name), "adaptor", null, name, null, [frameworkOwner]).id;
|
|
1619
|
+
const pkg = packageOf(specifier);
|
|
1620
|
+
return this.#sink.addNode(this.#sink.key("adaptor", pkg, name), "adaptor", null, name, null, [pkg]).id;
|
|
1621
|
+
}
|
|
1622
|
+
#packageShimOf(owner, name, near) {
|
|
1623
|
+
if (!near)
|
|
1624
|
+
return null;
|
|
1625
|
+
const shims = this.#exportedAt(name, near).filter(isPackageExport);
|
|
1626
|
+
const [shim] = shims;
|
|
1627
|
+
if (shim)
|
|
1628
|
+
return shims.length === 1 ? shim : null;
|
|
1629
|
+
const { packages, paths } = this.#resolver.starExportsOf(owner, near);
|
|
1630
|
+
const [only] = packages;
|
|
1631
|
+
if (!only || new Set(packages.map(packageOf)).size !== 1)
|
|
1632
|
+
return null;
|
|
1633
|
+
return paths.some((path) => this.#resolver.declaresAt(path, name)) ? null : { name, from: only };
|
|
1634
|
+
}
|
|
1635
|
+
#nodeOf({ fact, owner, fileName, id }) {
|
|
1636
|
+
const detail = fact.refName ? [fact.refName] : [];
|
|
1637
|
+
const node = this.#sink.addNode(id, "adaptor", owner, fact.name, fact.span, detail);
|
|
1638
|
+
if (fact.doc && !node.doc)
|
|
1639
|
+
node.doc = fact.doc;
|
|
1640
|
+
this.#sink.digest(node, this.#source.readText(fileName), fact.extent);
|
|
1641
|
+
return node.id;
|
|
1642
|
+
}
|
|
1643
|
+
}
|
|
1644
|
+
|
|
1215
1645
|
// pkgs/akanjs/common/trimSlashes.ts
|
|
1216
1646
|
var trimTrailingSlashes = (value) => {
|
|
1217
1647
|
let end = value.length;
|
|
@@ -1235,6 +1665,7 @@ var PAGE_ROUTE_EXPORTS = new Set([
|
|
|
1235
1665
|
"guard"
|
|
1236
1666
|
]);
|
|
1237
1667
|
var LAYOUT_ROUTE_EXPORTS = new Set([...PAGE_ROUTE_EXPORTS, "NotFound", "Error"]);
|
|
1668
|
+
var GENERATED_ROOT_LAYOUT_EXPORTS = new Set(["McpAppRoot", "LevelBoundary"]);
|
|
1238
1669
|
var ROOT_LAYOUT_ROUTE_EXPORTS = new Set([
|
|
1239
1670
|
...LAYOUT_ROUTE_EXPORTS,
|
|
1240
1671
|
"fonts",
|
|
@@ -1244,7 +1675,7 @@ var ROOT_LAYOUT_ROUTE_EXPORTS = new Set([
|
|
|
1244
1675
|
"wsConnect",
|
|
1245
1676
|
"layoutStyle",
|
|
1246
1677
|
"viewport",
|
|
1247
|
-
|
|
1678
|
+
...GENERATED_ROOT_LAYOUT_EXPORTS
|
|
1248
1679
|
]);
|
|
1249
1680
|
var RESERVED_ROUTE_CONFIG_EXPORTS = new Set([...ROOT_LAYOUT_ROUTE_EXPORTS].filter((name) => name !== "default" && !/^[A-Z]/.test(name)));
|
|
1250
1681
|
function parseRouteModuleKey(key) {
|
|
@@ -1500,12 +1931,18 @@ class GraphBuilder {
|
|
|
1500
1931
|
#routeFiles = new Map;
|
|
1501
1932
|
#routes;
|
|
1502
1933
|
#resolver;
|
|
1503
|
-
#adaptors
|
|
1504
|
-
#plugs = new Map;
|
|
1934
|
+
#adaptors;
|
|
1505
1935
|
constructor(source) {
|
|
1506
1936
|
this.#source = source;
|
|
1507
1937
|
this.#routes = new RouteFactReader(source.ts, source.reader, source.parse);
|
|
1508
1938
|
this.#resolver = new GuardResolver(source, this.#routes);
|
|
1939
|
+
this.#adaptors = new AdaptorResolver(source, this.#resolver, {
|
|
1940
|
+
key: (kind, owner, scope) => this.#key(kind, owner, scope),
|
|
1941
|
+
addNode: (id, kind, owner, name, span, detail) => this.#addNode(id, kind, owner, null, name, span, detail),
|
|
1942
|
+
addEdge: (from, to, kind, label, at) => this.#addEdge(from, to, kind, label, at),
|
|
1943
|
+
digest: (node, text, extent) => this.#digest(node, text, extent),
|
|
1944
|
+
location: (span) => this.#location(span)
|
|
1945
|
+
});
|
|
1509
1946
|
}
|
|
1510
1947
|
build() {
|
|
1511
1948
|
const { facts } = this.#source;
|
|
@@ -1517,16 +1954,7 @@ class GraphBuilder {
|
|
|
1517
1954
|
...[...constantsByOwner].filter(([key]) => key !== owner && key?.startsWith("libs/")).flatMap(([, list]) => list)
|
|
1518
1955
|
];
|
|
1519
1956
|
const typed = [];
|
|
1520
|
-
|
|
1521
|
-
for (const fact of file.adaptors) {
|
|
1522
|
-
const declared = { fact, owner: file.owner, fileName: file.fileName };
|
|
1523
|
-
this.#adaptors.set(fact.name, [...this.#adaptors.get(fact.name) ?? [], declared]);
|
|
1524
|
-
this.#adaptorNodeOf(declared);
|
|
1525
|
-
}
|
|
1526
|
-
for (const file of facts)
|
|
1527
|
-
for (const fact of file.adaptors)
|
|
1528
|
-
for (const plug of fact.plugs)
|
|
1529
|
-
this.#addEdge(this.#key("adaptor", file.owner, fact.name), this.#adaptorIdOf(plug.target, file), "plugs", plug.name, this.#location(plug.span));
|
|
1957
|
+
this.#adaptors.declare(facts);
|
|
1530
1958
|
for (const guard of this.#resolver.declare(facts))
|
|
1531
1959
|
this.#guardNodeOf(guard);
|
|
1532
1960
|
for (const file of facts) {
|
|
@@ -1559,10 +1987,7 @@ class GraphBuilder {
|
|
|
1559
1987
|
}
|
|
1560
1988
|
for (const method of service.methods)
|
|
1561
1989
|
this.#addMember("method", owner, refName, method, `${service.name}.${method.name}`, file.fileName);
|
|
1562
|
-
|
|
1563
|
-
this.#plugs.set(`${owner ?? ""}
|
|
1564
|
-
${refName}
|
|
1565
|
-
${plug.name}`, this.#adaptorIdOf(plug.target, file));
|
|
1990
|
+
this.#adaptors.addService(refName, service, file);
|
|
1566
1991
|
}
|
|
1567
1992
|
for (const filter of file.filters) {
|
|
1568
1993
|
if (!filter.name.endsWith("Filter"))
|
|
@@ -1818,28 +2243,6 @@ ${dir}`, node);
|
|
|
1818
2243
|
this.#digest(node, text, extent);
|
|
1819
2244
|
return node.id;
|
|
1820
2245
|
}
|
|
1821
|
-
#adaptorIdOf(local, file) {
|
|
1822
|
-
const [head, member] = local.split(".");
|
|
1823
|
-
const imported = file.imports.find((item) => item.name === head);
|
|
1824
|
-
const from = imported ? this.#resolver.ownerOfSpecifier(file.fileName, imported.from) : undefined;
|
|
1825
|
-
const name = member ?? (imported && imported.imported !== "default" && imported.imported !== "*" ? imported.imported : head);
|
|
1826
|
-
const declared = this.#adaptors.get(name) ?? [];
|
|
1827
|
-
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)));
|
|
1828
|
-
if (found)
|
|
1829
|
-
return this.#adaptorNodeOf(found);
|
|
1830
|
-
const owner = from === frameworkOwner ? null : imported ? from ?? null : file.owner;
|
|
1831
|
-
const detail = from === frameworkOwner ? [frameworkOwner] : [];
|
|
1832
|
-
return this.#addNode(this.#key("adaptor", owner, name), "adaptor", owner, null, name, null, detail).id;
|
|
1833
|
-
}
|
|
1834
|
-
#adaptorNodeOf({ fact, owner, fileName }) {
|
|
1835
|
-
const id = this.#key("adaptor", owner, fact.name);
|
|
1836
|
-
const detail = fact.refName ? [fact.refName] : [];
|
|
1837
|
-
const node = this.#addNode(id, "adaptor", owner, null, fact.name, fact.span, detail);
|
|
1838
|
-
if (fact.doc && !node.doc)
|
|
1839
|
-
node.doc = fact.doc;
|
|
1840
|
-
this.#digest(node, this.#source.readText(fileName), fact.extent);
|
|
1841
|
-
return node.id;
|
|
1842
|
-
}
|
|
1843
2246
|
#guardNodeOf({ name, owner, span, scope, doc, parts, file, label }) {
|
|
1844
2247
|
const id = this.#key("guard", owner, file ? `${file}#${name}` : name);
|
|
1845
2248
|
const node = this.#addNode(id, "guard", owner, null, name, span, scope ? [scope] : [], label ?? name);
|
|
@@ -1942,10 +2345,8 @@ st
|
|
|
1942
2345
|
visit(source);
|
|
1943
2346
|
}
|
|
1944
2347
|
#link(fileName, source, identifier, chain, context, owner) {
|
|
1945
|
-
const plugged = chain?.length === 2 && chain[0] === "this" && context.kind === "method" && this.#isServiceThis(identifier) ? this.#
|
|
1946
|
-
|
|
1947
|
-
${chain[1]}`) : undefined;
|
|
1948
|
-
const resolved = plugged ? [plugged] : this.#source.resolve(fileName, identifier).map((target) => this.#targetNodeOf(target)).filter((id) => id !== null);
|
|
2348
|
+
const plugged = chain?.length === 2 && chain[0] === "this" && context.kind === "method" && this.#isServiceThis(identifier) ? this.#adaptors.pluggedOf(context.owner, context.module, chain[1]) : [];
|
|
2349
|
+
const resolved = plugged.length ? plugged : this.#source.resolve(fileName, identifier).map((target) => this.#targetNodeOf(target)).filter((id) => id !== null);
|
|
1949
2350
|
const targets = resolved.length ? resolved : this.#plainTargetsOf(chain, identifier.text, context, owner);
|
|
1950
2351
|
if (!targets.length)
|
|
1951
2352
|
return;
|
|
@@ -2543,7 +2944,7 @@ var sourcePattern = /\.(constant|document|service|signal|store)\.ts$/;
|
|
|
2543
2944
|
var dictionaryPattern = /\.dictionary\.ts$/;
|
|
2544
2945
|
var srvkitPattern = /\/srvkit\//;
|
|
2545
2946
|
var wordPattern = /[A-Za-z_$][\w$]*/g;
|
|
2546
|
-
var
|
|
2947
|
+
var identifierPattern2 = /^[A-Za-z_$][\w$]*$/;
|
|
2547
2948
|
var stateReceivers = new Set(["use", "sel", "get", "do"]);
|
|
2548
2949
|
var lensFamilies = new Set(["slice", "query", "formSetter", "storeState", "endpoint"]);
|
|
2549
2950
|
var modellessFamilies = new Set(["query", "storeState", "endpoint"]);
|
|
@@ -2652,7 +3053,7 @@ ${[...new Set(text.match(wordPattern))].join(`
|
|
|
2652
3053
|
}
|
|
2653
3054
|
renameAt(givenName, offset, newKey, readText) {
|
|
2654
3055
|
const sources = this.#sourceEntriesAt(pathOf(givenName), offset).filter((entry) => entry.renamed);
|
|
2655
|
-
if (!sources.length || !
|
|
3056
|
+
if (!sources.length || !identifierPattern2.test(newKey))
|
|
2656
3057
|
return null;
|
|
2657
3058
|
return [
|
|
2658
3059
|
{ span: sources[0].span, newText: newKey },
|
|
@@ -2680,6 +3081,8 @@ canPass
|
|
|
2680
3081
|
adapt
|
|
2681
3082
|
`) || words.includes(`
|
|
2682
3083
|
dangerouslyAdapt
|
|
3084
|
+
`) || words.includes(`
|
|
3085
|
+
applyAdaptor
|
|
2683
3086
|
`);
|
|
2684
3087
|
}
|
|
2685
3088
|
static #sourceKeyOf({ family, sourceKey, label, detail, span }) {
|
|
@@ -3360,6 +3763,11 @@ ${union.name}`)));
|
|
|
3360
3763
|
const field = this.#memberOf(this.#classOf(receiver), receiver.name.text);
|
|
3361
3764
|
return field && ts.isPropertyDeclaration(field) ? this.#namesIn(field.type) : new Set;
|
|
3362
3765
|
}
|
|
3766
|
+
if (ts.isCallExpression(receiver) && ts.isPropertyAccessExpression(receiver.expression) && receiver.expression.expression.kind === ts.SyntaxKind.ThisKeyword) {
|
|
3767
|
+
const field = this.#memberOf(this.#classOf(receiver), receiver.expression.name.text);
|
|
3768
|
+
const type = field && ts.isPropertyDeclaration(field) ? field.type : undefined;
|
|
3769
|
+
return type && ts.isFunctionTypeNode(type) ? this.#namesIn(type.type) : new Set;
|
|
3770
|
+
}
|
|
3363
3771
|
return this.#declaredTypeNames(receiver) ?? new Set;
|
|
3364
3772
|
}
|
|
3365
3773
|
#memberName(name) {
|