@akanjs/language 3.2.0-rc.9 → 3.2.1-rc.0
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 +21 -6
- package/index.cjs +569 -251
- package/index.js +569 -251
- package/package.json +1 -1
- package/server.js +564 -251
package/index.cjs
CHANGED
|
@@ -161,6 +161,42 @@ ${at.file}` : null;
|
|
|
161
161
|
return node.fields ? { ...node, fields: node.fields.map(({ digest: _field, ...field }) => field) } : node;
|
|
162
162
|
}
|
|
163
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
|
+
|
|
164
200
|
// pkgs/@akanjs/language/guardFacts.ts
|
|
165
201
|
var guardLabelOf = (guard, labels) => {
|
|
166
202
|
const [, role = null, local = guard] = guard.match(/^([\w$]+) (.+)$/) ?? [];
|
|
@@ -168,6 +204,7 @@ var guardLabelOf = (guard, labels) => {
|
|
|
168
204
|
return label === undefined ? guard : role ? `${role} ${label}` : label;
|
|
169
205
|
};
|
|
170
206
|
var maxLabelArgs = 32;
|
|
207
|
+
var maxLayers = 4;
|
|
171
208
|
var guardRefReaderOf = (ts, ast, unwrap) => {
|
|
172
209
|
const pathOf = (expression) => {
|
|
173
210
|
if (ts.isIdentifier(expression))
|
|
@@ -177,10 +214,19 @@ var guardRefReaderOf = (ts, ast, unwrap) => {
|
|
|
177
214
|
const head = pathOf(expression.expression);
|
|
178
215
|
return head && `${head}.${expression.name.text}`;
|
|
179
216
|
};
|
|
180
|
-
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)) ?? "?";
|
|
181
225
|
const labelOf = (source, call) => {
|
|
182
226
|
const args = call.arguments.map((arg) => arg.getText(source)).join(", ");
|
|
183
|
-
|
|
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(`
|
|
184
230
|
`) ? args : "…"})`;
|
|
185
231
|
};
|
|
186
232
|
const guardRefOf = (expression, made, member) => {
|
|
@@ -208,9 +254,9 @@ var guardRefReaderOf = (ts, ast, unwrap) => {
|
|
|
208
254
|
const single = refOf(guards);
|
|
209
255
|
return single ? [single] : [];
|
|
210
256
|
};
|
|
211
|
-
return { pathOf, labelOf, guardsIn };
|
|
257
|
+
return { pathOf, layersOf, labelOf, guardsIn };
|
|
212
258
|
};
|
|
213
|
-
var guardFactoryReaderOf = (ts, ast, { spanOf, extentOf, unwrap, docOf }, pathOf) => {
|
|
259
|
+
var guardFactoryReaderOf = (ts, ast, { spanOf, extentOf, unwrap, docOf }, pathOf, layersOf) => {
|
|
214
260
|
const implementsGuard = (node, guardNames) => !!node.heritageClauses?.some((clause) => clause.token === ts.SyntaxKind.ImplementsKeyword && clause.types.some(({ expression }) => guardNames.has(ast.expressionName(expression) ?? "")));
|
|
215
261
|
const scopeOf = (node) => {
|
|
216
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;
|
|
@@ -232,7 +278,7 @@ var guardFactoryReaderOf = (ts, ast, { spanOf, extentOf, unwrap, docOf }, pathOf
|
|
|
232
278
|
}
|
|
233
279
|
return functions;
|
|
234
280
|
};
|
|
235
|
-
const returnedOf = (body, guardNames) => {
|
|
281
|
+
const returnedOf = (body, guardNames, depth = 0) => {
|
|
236
282
|
const locals = new Map;
|
|
237
283
|
const pending = [];
|
|
238
284
|
const visit = (node) => {
|
|
@@ -253,6 +299,7 @@ var guardFactoryReaderOf = (ts, ast, { spanOf, extentOf, unwrap, docOf }, pathOf
|
|
|
253
299
|
const calls = [];
|
|
254
300
|
const seen = new Set;
|
|
255
301
|
const passed = new Set;
|
|
302
|
+
const returned = [];
|
|
256
303
|
for (let node = pending.pop();node; node = pending.pop()) {
|
|
257
304
|
if (seen.has(node))
|
|
258
305
|
continue;
|
|
@@ -260,6 +307,8 @@ var guardFactoryReaderOf = (ts, ast, { spanOf, extentOf, unwrap, docOf }, pathOf
|
|
|
260
307
|
const value = ts.isExpression(node) ? unwrap(node) : node;
|
|
261
308
|
if ((ts.isClassExpression(value) || ts.isClassDeclaration(value)) && implementsGuard(value, guardNames))
|
|
262
309
|
guard ??= value;
|
|
310
|
+
else if ((ts.isArrowFunction(value) || ts.isFunctionExpression(value)) && !passed.has(node) && depth < maxLayers)
|
|
311
|
+
returned.push(value.body);
|
|
263
312
|
else if (ts.isConditionalExpression(value))
|
|
264
313
|
pending.push(value.whenTrue, value.whenFalse);
|
|
265
314
|
else if (ts.isBinaryExpression(value))
|
|
@@ -269,15 +318,22 @@ var guardFactoryReaderOf = (ts, ast, { spanOf, extentOf, unwrap, docOf }, pathOf
|
|
|
269
318
|
if (local)
|
|
270
319
|
pending.push(local);
|
|
271
320
|
} else if (ts.isCallExpression(value)) {
|
|
272
|
-
const
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
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
|
+
}
|
|
278
330
|
}
|
|
279
331
|
}
|
|
280
|
-
|
|
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 };
|
|
281
337
|
};
|
|
282
338
|
const guardFactoriesOf = (source, guardNames, isImported) => {
|
|
283
339
|
const functions = functionsOf(source);
|
|
@@ -287,7 +343,7 @@ var guardFactoryReaderOf = (ts, ast, { spanOf, extentOf, unwrap, docOf }, pathOf
|
|
|
287
343
|
for (let isGrowing = true;isGrowing; ) {
|
|
288
344
|
isGrowing = false;
|
|
289
345
|
for (const [name, { guard, calls }] of returned) {
|
|
290
|
-
if (members.has(name) || !guard && !calls.some(isFactoryCall))
|
|
346
|
+
if (members.has(name) || !guard && !calls.some(({ callee }) => isFactoryCall(callee)))
|
|
291
347
|
continue;
|
|
292
348
|
members.add(name);
|
|
293
349
|
isGrowing = true;
|
|
@@ -306,7 +362,8 @@ var guardFactoryReaderOf = (ts, ast, { spanOf, extentOf, unwrap, docOf }, pathOf
|
|
|
306
362
|
scope: made.guard ? scopeOf(made.guard) : null,
|
|
307
363
|
doc: docOf(source, found.statement),
|
|
308
364
|
direct: !!made.guard,
|
|
309
|
-
via: made.calls.filter(isFactoryCall)
|
|
365
|
+
via: made.calls.filter(({ callee }) => isFactoryCall(callee)),
|
|
366
|
+
layers: made.layers
|
|
310
367
|
});
|
|
311
368
|
}
|
|
312
369
|
return factories;
|
|
@@ -315,8 +372,8 @@ var guardFactoryReaderOf = (ts, ast, { spanOf, extentOf, unwrap, docOf }, pathOf
|
|
|
315
372
|
};
|
|
316
373
|
var createGuardFactReader = (ts, ast, base) => {
|
|
317
374
|
const { spanOf, extentOf, unwrap, docOf } = base;
|
|
318
|
-
const { pathOf, labelOf, guardsIn } = guardRefReaderOf(ts, ast, unwrap);
|
|
319
|
-
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);
|
|
320
377
|
const guardsOf = (source, imports, madeInPlace) => {
|
|
321
378
|
const guardNames = new Set([
|
|
322
379
|
"Guard",
|
|
@@ -329,15 +386,16 @@ var createGuardFactReader = (ts, ast, base) => {
|
|
|
329
386
|
const calls = [];
|
|
330
387
|
const makeOf = (made, value, isInPlace = false) => {
|
|
331
388
|
if (ts.isClassExpression(value) && implementsGuard(value, guardNames)) {
|
|
332
|
-
guards.push({ ...made, scope: scopeOf(value), factory: null });
|
|
389
|
+
guards.push({ ...made, scope: scopeOf(value), factory: null, layers: 0 });
|
|
333
390
|
return;
|
|
334
391
|
}
|
|
335
|
-
const
|
|
392
|
+
const { root, layers } = ts.isCallExpression(value) ? layersOf(value) : { root: null, layers: 0 };
|
|
393
|
+
const callee = root && pathOf(unwrap(root.expression));
|
|
336
394
|
const factory = callee && factories.get(callee);
|
|
337
395
|
if (factory)
|
|
338
|
-
guards.push({ ...made, scope: factory.scope, factory: factory.name });
|
|
396
|
+
guards.push({ ...made, scope: factory.scope, factory: factory.name, layers });
|
|
339
397
|
else if (callee && (isImported(callee) || isInPlace))
|
|
340
|
-
calls.push({ ...made, callee, kind: "call", scope: null });
|
|
398
|
+
calls.push({ ...made, callee, kind: "call", scope: null, layers });
|
|
341
399
|
};
|
|
342
400
|
for (const statement of source.statements) {
|
|
343
401
|
if (ts.isClassDeclaration(statement) && statement.name) {
|
|
@@ -351,9 +409,9 @@ var createGuardFactReader = (ts, ast, base) => {
|
|
|
351
409
|
const base = statement.heritageClauses?.find(({ token }) => token === ts.SyntaxKind.ExtendsKeyword)?.types[0];
|
|
352
410
|
const callee = base && pathOf(base.expression);
|
|
353
411
|
if (implementsGuard(statement, guardNames))
|
|
354
|
-
guards.push({ ...declared, factory: null });
|
|
412
|
+
guards.push({ ...declared, factory: null, layers: 0 });
|
|
355
413
|
else if (callee)
|
|
356
|
-
calls.push({ ...declared, callee, kind: "extends" });
|
|
414
|
+
calls.push({ ...declared, callee, kind: "extends", layers: 0 });
|
|
357
415
|
}
|
|
358
416
|
if (!ts.isVariableStatement(statement))
|
|
359
417
|
continue;
|
|
@@ -390,10 +448,6 @@ var createGuardFactReader = (ts, ast, base) => {
|
|
|
390
448
|
return { guardsIn, guardsOf };
|
|
391
449
|
};
|
|
392
450
|
|
|
393
|
-
// pkgs/@akanjs/language/escapeRegExp.ts
|
|
394
|
-
var regExpSpecials = /[\\^$.*+?()[\]{}|]/g;
|
|
395
|
-
var escapeRegExp = (text) => text.replace(regExpSpecials, (special) => `\\${special}`);
|
|
396
|
-
|
|
397
451
|
// pkgs/@akanjs/language/moduleFacts.ts
|
|
398
452
|
var testFilePattern = /\.(?:test|spec)\.tsx?$/;
|
|
399
453
|
var moduleCallees = new Set([
|
|
@@ -420,7 +474,7 @@ var ownerOf = (relativePath) => {
|
|
|
420
474
|
const [root, name] = relativePath.split("/");
|
|
421
475
|
return (root === "apps" || root === "libs") && name ? `${root}/${name}` : null;
|
|
422
476
|
};
|
|
423
|
-
var
|
|
477
|
+
var syntaxReaderOf = (ts, ast) => {
|
|
424
478
|
const spanOf = (source, node) => {
|
|
425
479
|
const start = node.getStart(source);
|
|
426
480
|
const end = node.getEnd();
|
|
@@ -478,6 +532,74 @@ var createFactReader = (ts, ast) => {
|
|
|
478
532
|
const node = keyName(property);
|
|
479
533
|
return name && node ? [{ name, span: spanOf(source, node), extent: extentOf(source, property) }] : [];
|
|
480
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) => {
|
|
481
603
|
const sliceKeysOf = (source, builder, made, model) => (returnedObject(builder)?.properties ?? []).flatMap((property) => {
|
|
482
604
|
if (!ts.isPropertyAssignment(property))
|
|
483
605
|
return [];
|
|
@@ -496,23 +618,30 @@ var createFactReader = (ts, ast) => {
|
|
|
496
618
|
}
|
|
497
619
|
];
|
|
498
620
|
});
|
|
499
|
-
const
|
|
500
|
-
const
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
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
|
+
});
|
|
515
641
|
};
|
|
642
|
+
return { sliceKeysOf, endpointKeysOf };
|
|
643
|
+
};
|
|
644
|
+
var jobKeyReaderOf = (ts, ast, { spanOf, extentOf, unwrap, returnedObject, chainOf, verbReaderOf }) => {
|
|
516
645
|
const numberOf = (expression) => {
|
|
517
646
|
const value = unwrap(expression);
|
|
518
647
|
if (ts.isNumericLiteral(value))
|
|
@@ -585,6 +714,9 @@ var createFactReader = (ts, ast) => {
|
|
|
585
714
|
];
|
|
586
715
|
});
|
|
587
716
|
};
|
|
717
|
+
return { internalKeysOf };
|
|
718
|
+
};
|
|
719
|
+
var serviceReaderOf = (ts, ast, { spanOf, extentOf, returnedObject, guardNameOf, chainOf, verbReaderOf }) => {
|
|
588
720
|
const plugsOf = (source, builder) => {
|
|
589
721
|
const verbOf = verbReaderOf(builder?.parameters[0]);
|
|
590
722
|
return (returnedObject(builder)?.properties ?? []).flatMap((property) => {
|
|
@@ -610,27 +742,17 @@ var createFactReader = (ts, ast) => {
|
|
|
610
742
|
visit(source);
|
|
611
743
|
return bindings;
|
|
612
744
|
};
|
|
613
|
-
const
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
name,
|
|
625
|
-
span: spanOf(source, property.name),
|
|
626
|
-
extent: extentOf(source, property),
|
|
627
|
-
verb: root ? verbOf(root.expression) : null,
|
|
628
|
-
guards: root ? guardsIn(source, optionObjectOf(root), made, `${model}.${name}`) : [],
|
|
629
|
-
argCount: methods.filter((method) => argMethods.has(method)).length
|
|
630
|
-
}
|
|
631
|
-
];
|
|
632
|
-
});
|
|
633
|
-
};
|
|
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 }) => {
|
|
634
756
|
const filterQueriesOf = (source, builder) => {
|
|
635
757
|
const query = returnedObject(builder)?.properties.find((property) => ts.isPropertyAssignment(property) && ast.nodeName(property.name) === "query")?.initializer;
|
|
636
758
|
return query && ts.isObjectLiteralExpression(query) ? objectKeys(source, query) : [];
|
|
@@ -668,48 +790,18 @@ var createFactReader = (ts, ast) => {
|
|
|
668
790
|
return [];
|
|
669
791
|
return list.elements.flatMap((element) => ts.isStringLiteralLike(element) ? [element.text] : []);
|
|
670
792
|
};
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
return [{ name, span: spanOf(source, member.name), extent: extentOf(source, member) }];
|
|
678
|
-
});
|
|
679
|
-
const importsOf = (statement) => {
|
|
680
|
-
const { importClause, moduleSpecifier } = statement;
|
|
681
|
-
if (!importClause || !ts.isStringLiteral(moduleSpecifier))
|
|
682
|
-
return [];
|
|
683
|
-
const from = moduleSpecifier.text;
|
|
684
|
-
const bindings = importClause.namedBindings;
|
|
685
|
-
return [
|
|
686
|
-
...importClause.name ? [{ name: importClause.name.text, imported: "default", from }] : [],
|
|
687
|
-
...bindings && ts.isNamespaceImport(bindings) ? [{ name: bindings.name.text, imported: "*", from }] : [],
|
|
688
|
-
...bindings && ts.isNamedImports(bindings) ? bindings.elements.map((element) => ({
|
|
689
|
-
name: element.name.text,
|
|
690
|
-
imported: (element.propertyName ?? element.name).text,
|
|
691
|
-
from
|
|
692
|
-
})) : []
|
|
693
|
-
];
|
|
694
|
-
};
|
|
695
|
-
const docOf = (source, node) => {
|
|
696
|
-
const { text } = source;
|
|
697
|
-
const ranges = ts.getLeadingCommentRanges(text, node.getFullStart()) ?? [];
|
|
698
|
-
const comments = [];
|
|
699
|
-
let end = node.getStart(source);
|
|
700
|
-
for (const range of [...ranges].reverse()) {
|
|
701
|
-
if ((text.slice(range.end, end).match(/\n/g)?.length ?? 0) > 1)
|
|
702
|
-
break;
|
|
703
|
-
comments.unshift(text.slice(range.pos, range.end));
|
|
704
|
-
end = range.pos;
|
|
705
|
-
}
|
|
706
|
-
const lines = comments.flatMap((comment) => comment.split(`
|
|
707
|
-
`)).map((line) => line.trim().replace(/^\/\*\*?|\*\/$/g, "").replace(/^(?:\/\/[?*!]?|\*)/, "").replace(/\{@link\s+([^}\s|]+)[^}]*\}/g, "$1").trim()).filter((line) => line && !/^(?:biome-ignore|eslint-|@ts-)/.test(line));
|
|
708
|
-
return lines.length ? lines.join(" ") : null;
|
|
709
|
-
};
|
|
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);
|
|
710
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);
|
|
711
804
|
const lowerFirst = (text) => text.charAt(0).toLowerCase() + text.slice(1);
|
|
712
|
-
const importsIn = (source) => source.statements.filter(ts.isImportDeclaration).flatMap(importsOf);
|
|
713
805
|
const read = (source, owner) => {
|
|
714
806
|
const imports = importsIn(source);
|
|
715
807
|
const madeInPlace = [];
|
|
@@ -807,7 +899,11 @@ var frameworkOwner = "akanjs";
|
|
|
807
899
|
var frameworkPattern = /^akanjs(?:\/|$)/;
|
|
808
900
|
var aliasPattern = /^@(apps|libs)\/([^/]+)/;
|
|
809
901
|
var maxMapDepth = 4;
|
|
902
|
+
var identifierPattern = /^[\p{ID_Start}$_][\p{ID_Continue}$\u200c\u200d]*$/u;
|
|
810
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$])`);
|
|
811
907
|
var declaringPatternOf = (name, isAnyBinding) => {
|
|
812
908
|
const escaped = escapeRegExp(name);
|
|
813
909
|
const braced = "\\{(?:[^}]*?[\\s,])?";
|
|
@@ -829,8 +925,12 @@ class GuardResolver {
|
|
|
829
925
|
#reexports = new Map;
|
|
830
926
|
#declarations = new Map;
|
|
831
927
|
#starExports = new Map;
|
|
928
|
+
#moduleExports = new Map;
|
|
929
|
+
#fileStars = new Map;
|
|
930
|
+
#starReach = new Map;
|
|
832
931
|
#ownerFiles = null;
|
|
833
932
|
#modules = null;
|
|
933
|
+
#barrels = null;
|
|
834
934
|
constructor(source, routes) {
|
|
835
935
|
this.#source = source;
|
|
836
936
|
this.#routes = routes;
|
|
@@ -854,21 +954,26 @@ ${name}`);
|
|
|
854
954
|
made: [],
|
|
855
955
|
isReal: fact.direct,
|
|
856
956
|
scope: fact.scope,
|
|
957
|
+
layers: fact.layers,
|
|
857
958
|
targets: []
|
|
858
959
|
};
|
|
859
960
|
factories.set(fact.name, [...factories.get(fact.name) ?? [], factory]);
|
|
860
961
|
declaredFactories.push(factory);
|
|
861
962
|
}
|
|
862
963
|
for (const factory of declaredFactories)
|
|
863
|
-
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
|
+
});
|
|
864
968
|
for (let isGrowing = true;isGrowing; ) {
|
|
865
969
|
isGrowing = false;
|
|
866
970
|
for (const factory of declaredFactories) {
|
|
867
|
-
const
|
|
868
|
-
if (factory.isReal || !
|
|
971
|
+
const via = factory.targets.find(({ target, layers }) => target.isReal && target.layers >= layers);
|
|
972
|
+
if (factory.isReal || !via)
|
|
869
973
|
continue;
|
|
870
974
|
factory.isReal = true;
|
|
871
|
-
factory.
|
|
975
|
+
factory.layers = factory.fact.layers + via.target.layers - via.layers;
|
|
976
|
+
factory.scope ??= via.target.scope;
|
|
872
977
|
isGrowing = true;
|
|
873
978
|
}
|
|
874
979
|
}
|
|
@@ -878,7 +983,7 @@ ${name}`);
|
|
|
878
983
|
seen.add(factory);
|
|
879
984
|
return [
|
|
880
985
|
{ fileName: factory.site.fileName, extent: factory.fact.extent },
|
|
881
|
-
...factory.targets.filter((target) => target.isReal).flatMap((target) => partsOf(target, seen))
|
|
986
|
+
...factory.targets.filter(({ target }) => target.isReal).flatMap(({ target }) => partsOf(target, seen))
|
|
882
987
|
];
|
|
883
988
|
};
|
|
884
989
|
const declare = (file, made, scope, parts) => {
|
|
@@ -899,7 +1004,7 @@ ${name}`, guard);
|
|
|
899
1004
|
const factory = made.factory ? factories.get(made.factory)?.find((other) => other.site.fileName === file.fileName) : undefined;
|
|
900
1005
|
if (!made.factory)
|
|
901
1006
|
declare(file, made, made.scope, []);
|
|
902
|
-
else if (factory?.isReal)
|
|
1007
|
+
else if (factory?.isReal && factory.layers === made.layers)
|
|
903
1008
|
factory.made.push(declare(file, made, factory.scope, partsOf(factory)));
|
|
904
1009
|
}
|
|
905
1010
|
for (const made of file.guardCalls) {
|
|
@@ -908,7 +1013,7 @@ ${name}`, guard);
|
|
|
908
1013
|
continue;
|
|
909
1014
|
}
|
|
910
1015
|
const factory = this.#factoryAt(factories, made.callee, file);
|
|
911
|
-
if (factory?.isReal)
|
|
1016
|
+
if (factory?.isReal && factory.layers === made.layers)
|
|
912
1017
|
factory.made.push(declare(file, made, factory.scope, partsOf(factory)));
|
|
913
1018
|
}
|
|
914
1019
|
}
|
|
@@ -953,7 +1058,7 @@ ${name}`, guard);
|
|
|
953
1058
|
const own = this.#nearest(candidates.filter((other) => other.owner === from), ({ site }) => site.fileName, near);
|
|
954
1059
|
if (own)
|
|
955
1060
|
return own;
|
|
956
|
-
const reexport = from && depth < maxMapDepth ? this
|
|
1061
|
+
const reexport = from && depth < maxMapDepth ? this.#reexportOf(from, name, near) : null;
|
|
957
1062
|
if (reexport)
|
|
958
1063
|
return this.#factoryAt(factories, reexport.local, reexport.site, depth + 1);
|
|
959
1064
|
return from && near ? this.#throughStar(candidates, from, name, near) : undefined;
|
|
@@ -991,13 +1096,13 @@ ${name}`, guard);
|
|
|
991
1096
|
const visible = isBase ? undefined : declared.find((other) => this.visible(other.owner, site.owner));
|
|
992
1097
|
return visible ? { guard: visible } : { name, from };
|
|
993
1098
|
}
|
|
994
|
-
const reexport = from && depth < maxMapDepth ? this
|
|
1099
|
+
const reexport = from && depth < maxMapDepth ? this.#reexportOf(from, name, near) : null;
|
|
995
1100
|
if (reexport)
|
|
996
1101
|
return this.#findGuard(reexport.local, reexport.site, depth + 1, isBase);
|
|
997
1102
|
const reached = from && near ? this.#throughStar(declared, from, name, near) : undefined;
|
|
998
1103
|
return reached ? { guard: reached } : { name, from };
|
|
999
1104
|
}
|
|
1000
|
-
reexportOf(owner, name, near) {
|
|
1105
|
+
#reexportOf(owner, name, near) {
|
|
1001
1106
|
const key = `${owner}
|
|
1002
1107
|
${name}
|
|
1003
1108
|
${near ?? ""}`;
|
|
@@ -1005,7 +1110,7 @@ ${near ?? ""}`;
|
|
|
1005
1110
|
if (cached !== undefined)
|
|
1006
1111
|
return cached;
|
|
1007
1112
|
let found = null;
|
|
1008
|
-
const exporting =
|
|
1113
|
+
const exporting = exportingPatternOf(name);
|
|
1009
1114
|
for (const fileName of this.#filesOf(owner, name, near)) {
|
|
1010
1115
|
const text = this.#source.readText(fileName);
|
|
1011
1116
|
if (text === undefined || !exporting.test(text))
|
|
@@ -1023,7 +1128,7 @@ ${near ?? ""}`;
|
|
|
1023
1128
|
this.#reexports.set(key, found);
|
|
1024
1129
|
return found;
|
|
1025
1130
|
}
|
|
1026
|
-
#reexportIn(source, name) {
|
|
1131
|
+
#reexportIn(source, name, takesPackageDefault = false) {
|
|
1027
1132
|
const { ts, reader } = this.#source;
|
|
1028
1133
|
for (const statement of source.statements) {
|
|
1029
1134
|
if (!ts.isExportDeclaration(statement) || statement.isTypeOnly)
|
|
@@ -1040,7 +1145,9 @@ ${near ?? ""}`;
|
|
|
1040
1145
|
const imported = reader.importsIn(source).find((item) => item.name === original);
|
|
1041
1146
|
if (!imported)
|
|
1042
1147
|
return { name: original, from: null };
|
|
1043
|
-
|
|
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 };
|
|
1044
1151
|
}
|
|
1045
1152
|
return null;
|
|
1046
1153
|
}
|
|
@@ -1049,7 +1156,9 @@ ${near ?? ""}`;
|
|
|
1049
1156
|
const relative = this.#source.relative(fileName);
|
|
1050
1157
|
return !!near && (relative.startsWith(`${near}/`) || relative.replace(/\.tsx?$/, "") === near);
|
|
1051
1158
|
};
|
|
1052
|
-
|
|
1159
|
+
if (!identifierPattern.test(name))
|
|
1160
|
+
return [];
|
|
1161
|
+
const candidates = this.#filesIn(owner).filter(([, words]) => words.includes(`
|
|
1053
1162
|
${name}
|
|
1054
1163
|
`)).map(([fileName]) => fileName);
|
|
1055
1164
|
return [...candidates.filter(isNear), ...candidates.filter((other) => !isNear(other))];
|
|
@@ -1066,7 +1175,7 @@ ${owner ?? ""}`;
|
|
|
1066
1175
|
const entries = [];
|
|
1067
1176
|
const fileNames = [
|
|
1068
1177
|
...fileName ? [fileName] : [],
|
|
1069
|
-
...(owner === null ? [] : this
|
|
1178
|
+
...(owner === null ? [] : this.#filesIn(owner)).filter(([other, words]) => other !== fileName && words.includes(`
|
|
1070
1179
|
${objectName}
|
|
1071
1180
|
`) && words.includes(`
|
|
1072
1181
|
${member}
|
|
@@ -1140,30 +1249,120 @@ ${near ?? ""}`;
|
|
|
1140
1249
|
#throughStar(declared, owner, name, near) {
|
|
1141
1250
|
if (!declared.length)
|
|
1142
1251
|
return;
|
|
1143
|
-
const { owners, isOpaque } = this
|
|
1252
|
+
const { owners, isOpaque } = this.starExportsOf(owner, near);
|
|
1144
1253
|
const reached = declared.filter((other) => other.owner !== null && owners.includes(other.owner));
|
|
1145
1254
|
return reached.length === 1 && !isOpaque && !this.declares(owner, name) ? reached[0] : undefined;
|
|
1146
1255
|
}
|
|
1147
|
-
|
|
1148
|
-
const
|
|
1256
|
+
starExportsOf(owner, near) {
|
|
1257
|
+
const key = `${owner}
|
|
1258
|
+
${near}`;
|
|
1259
|
+
const cached = this.#starExports.get(key);
|
|
1149
1260
|
if (cached)
|
|
1150
1261
|
return cached;
|
|
1151
|
-
const found = { owners: [], isOpaque: false };
|
|
1152
|
-
this.#starExports.set(
|
|
1153
|
-
const
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
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);
|
|
1166
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);
|
|
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);
|
|
1167
1366
|
return found;
|
|
1168
1367
|
}
|
|
1169
1368
|
#modulesAt(path) {
|
|
@@ -1177,11 +1376,33 @@ ${near ?? ""}`;
|
|
|
1177
1376
|
}
|
|
1178
1377
|
return this.#modules.get(path) ?? [];
|
|
1179
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
|
+
}
|
|
1180
1397
|
declares(owner, name) {
|
|
1181
1398
|
const declaring = declaringPatternOf(name, true);
|
|
1182
1399
|
return this.#filesOf(owner, name, null).some((fileName) => declaring.test(this.#source.readText(fileName) ?? ""));
|
|
1183
1400
|
}
|
|
1184
|
-
|
|
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) {
|
|
1185
1406
|
if (!this.#ownerFiles) {
|
|
1186
1407
|
this.#ownerFiles = new Map;
|
|
1187
1408
|
for (const entry of this.#source.files) {
|
|
@@ -1231,6 +1452,196 @@ ${near ?? ""}`;
|
|
|
1231
1452
|
}
|
|
1232
1453
|
}
|
|
1233
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 shims = own === undefined && from && from !== frameworkOwner && path ? this.#exportedAt(name, path).filter(isPackageExport) : [];
|
|
1537
|
+
const [shim] = shims;
|
|
1538
|
+
if (shim && shims.length === 1)
|
|
1539
|
+
return this.#packageAdaptorOf(shim.name, shim.from);
|
|
1540
|
+
const found = own === undefined && !shim && from !== frameworkOwner ? declared.find((adaptor) => this.#resolver.visible(adaptor.owner, holder)) : own;
|
|
1541
|
+
if (found)
|
|
1542
|
+
return found.id;
|
|
1543
|
+
const starred = own === undefined && !shim && from && from !== frameworkOwner ? this.#starredPackageOf(from, name, path) : null;
|
|
1544
|
+
if (starred)
|
|
1545
|
+
return this.#packageAdaptorOf(starred.name, starred.from);
|
|
1546
|
+
const owner = from === frameworkOwner ? null : imported ? from ?? null : file.owner;
|
|
1547
|
+
const detail = from === frameworkOwner ? [frameworkOwner] : [];
|
|
1548
|
+
return this.#sink.addNode(this.#sink.key("adaptor", owner, name), "adaptor", owner, name, null, detail).id;
|
|
1549
|
+
}
|
|
1550
|
+
#adaptorIn(name, declared, owner, path, fileName) {
|
|
1551
|
+
const own = declared.filter((adaptor) => adaptor.owner === owner);
|
|
1552
|
+
const [first] = own;
|
|
1553
|
+
if (path === null)
|
|
1554
|
+
return own.find((adaptor) => adaptor.fileName === fileName) ?? first;
|
|
1555
|
+
if (own.length === 1)
|
|
1556
|
+
return first;
|
|
1557
|
+
const exported = this.#exportedAt(name, path).filter((item) => first || !isPackageExport(item));
|
|
1558
|
+
const [only] = exported;
|
|
1559
|
+
if (only)
|
|
1560
|
+
return exported.length === 1 && !("local" in only) ? only : null;
|
|
1561
|
+
return first ? null : undefined;
|
|
1562
|
+
}
|
|
1563
|
+
#exportedAt(name, path) {
|
|
1564
|
+
const key = `${path}
|
|
1565
|
+
${name}`;
|
|
1566
|
+
const cached = this.#exported.get(key);
|
|
1567
|
+
if (cached)
|
|
1568
|
+
return cached;
|
|
1569
|
+
if (!this.#resolver.mentionsAlong(path, name)) {
|
|
1570
|
+
this.#exported.set(key, []);
|
|
1571
|
+
return [];
|
|
1572
|
+
}
|
|
1573
|
+
const reached = new Map;
|
|
1574
|
+
const seen = new Set;
|
|
1575
|
+
const pending = [[name, path]];
|
|
1576
|
+
for (let next = pending.pop();next; next = pending.pop()) {
|
|
1577
|
+
const [wanted, at] = next;
|
|
1578
|
+
if (seen.has(`${at}
|
|
1579
|
+
${wanted}`))
|
|
1580
|
+
continue;
|
|
1581
|
+
seen.add(`${at}
|
|
1582
|
+
${wanted}`);
|
|
1583
|
+
for (const item of this.#bindingAt(wanted, at, pending, name))
|
|
1584
|
+
reached.set(exportedKeyOf(item), item);
|
|
1585
|
+
}
|
|
1586
|
+
const found = [...reached.values()];
|
|
1587
|
+
this.#exported.set(key, found);
|
|
1588
|
+
return found;
|
|
1589
|
+
}
|
|
1590
|
+
#bindingAt(name, path, pending, plugged) {
|
|
1591
|
+
const here = this.#declaredAt(name, path);
|
|
1592
|
+
if (here.length)
|
|
1593
|
+
return here;
|
|
1594
|
+
const { named, stars, isLocal } = this.#resolver.exportsAt(path, name);
|
|
1595
|
+
if (isLocal)
|
|
1596
|
+
return [{ local: path }];
|
|
1597
|
+
if (named?.from === null) {
|
|
1598
|
+
const local = this.#declaredAt(named.name, path);
|
|
1599
|
+
return local.length ? local : [{ local: path }];
|
|
1600
|
+
}
|
|
1601
|
+
if (named) {
|
|
1602
|
+
const target = this.#resolver.pathOfSpecifier(named.fileName, named.from);
|
|
1603
|
+
if (target === null) {
|
|
1604
|
+
const exposed = named.name !== "default" ? named.name : name !== "default" ? name : plugged;
|
|
1605
|
+
return [{ name: exposed, from: named.from }];
|
|
1606
|
+
}
|
|
1607
|
+
pending.push([named.name, target]);
|
|
1608
|
+
return [];
|
|
1609
|
+
}
|
|
1610
|
+
for (const star of stars)
|
|
1611
|
+
pending.push([name, star]);
|
|
1612
|
+
return [];
|
|
1613
|
+
}
|
|
1614
|
+
#declaredAt(name, path) {
|
|
1615
|
+
return (this.#adaptors.get(name) ?? []).filter((adaptor) => {
|
|
1616
|
+
const module2 = this.#source.relative(adaptor.fileName).replace(/\.tsx?$/, "");
|
|
1617
|
+
return module2 === path || module2 === `${path}/index`;
|
|
1618
|
+
});
|
|
1619
|
+
}
|
|
1620
|
+
#packageAdaptorOf(name, specifier) {
|
|
1621
|
+
if (frameworkPattern.test(specifier))
|
|
1622
|
+
return this.#sink.addNode(this.#sink.key("adaptor", null, name), "adaptor", null, name, null, [frameworkOwner]).id;
|
|
1623
|
+
const pkg = packageOf(specifier);
|
|
1624
|
+
return this.#sink.addNode(this.#sink.key("adaptor", pkg, name), "adaptor", null, name, null, [pkg]).id;
|
|
1625
|
+
}
|
|
1626
|
+
#starredPackageOf(owner, name, near) {
|
|
1627
|
+
if (!near)
|
|
1628
|
+
return 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
|
+
|
|
1234
1645
|
// pkgs/akanjs/common/trimSlashes.ts
|
|
1235
1646
|
var trimTrailingSlashes = (value) => {
|
|
1236
1647
|
let end = value.length;
|
|
@@ -1254,6 +1665,7 @@ var PAGE_ROUTE_EXPORTS = new Set([
|
|
|
1254
1665
|
"guard"
|
|
1255
1666
|
]);
|
|
1256
1667
|
var LAYOUT_ROUTE_EXPORTS = new Set([...PAGE_ROUTE_EXPORTS, "NotFound", "Error"]);
|
|
1668
|
+
var GENERATED_ROOT_LAYOUT_EXPORTS = new Set(["McpAppRoot", "LevelBoundary"]);
|
|
1257
1669
|
var ROOT_LAYOUT_ROUTE_EXPORTS = new Set([
|
|
1258
1670
|
...LAYOUT_ROUTE_EXPORTS,
|
|
1259
1671
|
"fonts",
|
|
@@ -1263,7 +1675,7 @@ var ROOT_LAYOUT_ROUTE_EXPORTS = new Set([
|
|
|
1263
1675
|
"wsConnect",
|
|
1264
1676
|
"layoutStyle",
|
|
1265
1677
|
"viewport",
|
|
1266
|
-
|
|
1678
|
+
...GENERATED_ROOT_LAYOUT_EXPORTS
|
|
1267
1679
|
]);
|
|
1268
1680
|
var RESERVED_ROUTE_CONFIG_EXPORTS = new Set([...ROOT_LAYOUT_ROUTE_EXPORTS].filter((name) => name !== "default" && !/^[A-Z]/.test(name)));
|
|
1269
1681
|
function parseRouteModuleKey(key) {
|
|
@@ -1519,13 +1931,18 @@ class GraphBuilder {
|
|
|
1519
1931
|
#routeFiles = new Map;
|
|
1520
1932
|
#routes;
|
|
1521
1933
|
#resolver;
|
|
1522
|
-
#adaptors
|
|
1523
|
-
#plugs = new Map;
|
|
1524
|
-
#serviceFields = new Set;
|
|
1934
|
+
#adaptors;
|
|
1525
1935
|
constructor(source) {
|
|
1526
1936
|
this.#source = source;
|
|
1527
1937
|
this.#routes = new RouteFactReader(source.ts, source.reader, source.parse);
|
|
1528
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
|
+
});
|
|
1529
1946
|
}
|
|
1530
1947
|
build() {
|
|
1531
1948
|
const { facts } = this.#source;
|
|
@@ -1537,26 +1954,7 @@ class GraphBuilder {
|
|
|
1537
1954
|
...[...constantsByOwner].filter(([key]) => key !== owner && key?.startsWith("libs/")).flatMap(([, list]) => list)
|
|
1538
1955
|
];
|
|
1539
1956
|
const typed = [];
|
|
1540
|
-
|
|
1541
|
-
for (const file of facts)
|
|
1542
|
-
for (const fact of file.adaptors) {
|
|
1543
|
-
const key = this.#key("adaptor", file.owner, fact.name);
|
|
1544
|
-
adaptorCounts.set(key, (adaptorCounts.get(key) ?? 0) + 1);
|
|
1545
|
-
}
|
|
1546
|
-
const declaredAdaptors = facts.flatMap((file) => file.adaptors.map((fact) => {
|
|
1547
|
-
const key = this.#key("adaptor", file.owner, fact.name);
|
|
1548
|
-
const id = (adaptorCounts.get(key) ?? 0) > 1 ? this.#key("adaptor", file.owner, `${this.#resolver.inOwner(file.fileName, file.owner)}#${fact.name}`) : key;
|
|
1549
|
-
const declared = { fact, owner: file.owner, fileName: file.fileName, id };
|
|
1550
|
-
this.#adaptors.set(fact.name, [...this.#adaptors.get(fact.name) ?? [], declared]);
|
|
1551
|
-
this.#adaptorNodeOf(declared);
|
|
1552
|
-
return { declared, file };
|
|
1553
|
-
}));
|
|
1554
|
-
for (const { declared, file } of declaredAdaptors)
|
|
1555
|
-
for (const plug of declared.fact.plugs)
|
|
1556
|
-
this.#addEdge(declared.id, this.#adaptorIdOf(plug.target, file), "plugs", plug.name, this.#location(plug.span));
|
|
1557
|
-
for (const file of facts)
|
|
1558
|
-
for (const binding of file.adaptorBindings)
|
|
1559
|
-
this.#addEdge(this.#adaptorIdOf(binding.role, file), this.#adaptorIdOf(binding.adaptor, file), "binds", file.owner, this.#location(binding.span));
|
|
1957
|
+
this.#adaptors.declare(facts);
|
|
1560
1958
|
for (const guard of this.#resolver.declare(facts))
|
|
1561
1959
|
this.#guardNodeOf(guard);
|
|
1562
1960
|
for (const file of facts) {
|
|
@@ -1589,18 +1987,7 @@ class GraphBuilder {
|
|
|
1589
1987
|
}
|
|
1590
1988
|
for (const method of service.methods)
|
|
1591
1989
|
this.#addMember("method", owner, refName, method, `${service.name}.${method.name}`, file.fileName);
|
|
1592
|
-
|
|
1593
|
-
const key = `${refName}
|
|
1594
|
-
${plug.name}`;
|
|
1595
|
-
this.#plugs.set(key, [
|
|
1596
|
-
...this.#plugs.get(key) ?? [],
|
|
1597
|
-
{ owner, target: this.#adaptorIdOf(plug.target, file) }
|
|
1598
|
-
]);
|
|
1599
|
-
}
|
|
1600
|
-
for (const field of service.fields)
|
|
1601
|
-
this.#serviceFields.add(`${owner ?? ""}
|
|
1602
|
-
${refName}
|
|
1603
|
-
${field}`);
|
|
1990
|
+
this.#adaptors.addService(refName, service, file);
|
|
1604
1991
|
}
|
|
1605
1992
|
for (const filter of file.filters) {
|
|
1606
1993
|
if (!filter.name.endsWith("Filter"))
|
|
@@ -1856,80 +2243,6 @@ ${dir}`, node);
|
|
|
1856
2243
|
this.#digest(node, text, extent);
|
|
1857
2244
|
return node.id;
|
|
1858
2245
|
}
|
|
1859
|
-
#adaptorIdOf(local, file) {
|
|
1860
|
-
const [head, member] = local.split(".");
|
|
1861
|
-
const imported = file.imports.find((item) => item.name === head);
|
|
1862
|
-
const name = member ?? (imported && imported.imported !== "default" && imported.imported !== "*" ? imported.imported : head);
|
|
1863
|
-
const path = imported ? this.#resolver.pathOfSpecifier(file.fileName, imported.from) : null;
|
|
1864
|
-
if (imported && path === null && !frameworkPattern.test(imported.from))
|
|
1865
|
-
return this.#packageAdaptorOf(name, imported.from);
|
|
1866
|
-
const from = imported ? this.#resolver.ownerOfSpecifier(file.fileName, imported.from) : undefined;
|
|
1867
|
-
const declared = this.#adaptors.get(name) ?? [];
|
|
1868
|
-
const found = from === undefined ? this.#adaptorIn(declared, file.owner, path, file.fileName) ?? declared.find((adaptor) => this.#resolver.visible(adaptor.owner, file.owner)) : this.#adaptorIn(declared, from, path, file.fileName) ?? (from === frameworkOwner ? undefined : declared.find((adaptor) => this.#resolver.visible(adaptor.owner, from)));
|
|
1869
|
-
if (found)
|
|
1870
|
-
return found.id;
|
|
1871
|
-
const reexported = from && from !== frameworkOwner ? this.#packageShimOf(from, name, path) : null;
|
|
1872
|
-
if (reexported)
|
|
1873
|
-
return this.#packageAdaptorOf(reexported.name, reexported.from);
|
|
1874
|
-
const owner = from === frameworkOwner ? null : imported ? from ?? null : file.owner;
|
|
1875
|
-
const detail = from === frameworkOwner ? [frameworkOwner] : [];
|
|
1876
|
-
return this.#addNode(this.#key("adaptor", owner, name), "adaptor", owner, null, name, null, detail).id;
|
|
1877
|
-
}
|
|
1878
|
-
#adaptorIn(declared, owner, path, fileName) {
|
|
1879
|
-
const own = declared.filter((adaptor) => adaptor.owner === owner);
|
|
1880
|
-
if (own.length < 2)
|
|
1881
|
-
return own.at(0);
|
|
1882
|
-
const pathOf = (adaptor) => this.#source.relative(adaptor.fileName).replace(/\.tsx?$/, "");
|
|
1883
|
-
const named = path === null ? own.find((adaptor) => adaptor.fileName === fileName) : own.find((adaptor) => pathOf(adaptor) === path || pathOf(adaptor) === `${path}/index`) ?? own.find((adaptor) => pathOf(adaptor).startsWith(`${path}/`));
|
|
1884
|
-
return named ?? own.at(0);
|
|
1885
|
-
}
|
|
1886
|
-
#pluggedOf({ owner, module: module2 }, field) {
|
|
1887
|
-
const plugs = this.#plugs.get(`${module2}
|
|
1888
|
-
${field}`) ?? [];
|
|
1889
|
-
const own = plugs.filter((plug) => plug.owner === owner);
|
|
1890
|
-
if (!own.length && this.#serviceFields.has(`${owner ?? ""}
|
|
1891
|
-
${module2}
|
|
1892
|
-
${field}`))
|
|
1893
|
-
return [];
|
|
1894
|
-
const inherited = own.length ? own : plugs.filter((plug) => this.#resolver.visible(plug.owner, owner));
|
|
1895
|
-
return [...new Set(inherited.map(({ target }) => target))];
|
|
1896
|
-
}
|
|
1897
|
-
#packageAdaptorOf(name, specifier) {
|
|
1898
|
-
if (frameworkPattern.test(specifier))
|
|
1899
|
-
return this.#addNode(this.#key("adaptor", null, name), "adaptor", null, null, name, null, [frameworkOwner]).id;
|
|
1900
|
-
const pkg = specifier.split("/").slice(0, specifier.startsWith("@") ? 2 : 1).join("/");
|
|
1901
|
-
return this.#addNode(this.#key("adaptor", pkg, name), "adaptor", null, null, name, null, [pkg]).id;
|
|
1902
|
-
}
|
|
1903
|
-
#packageShimOf(owner, name, near) {
|
|
1904
|
-
const reexport = this.#resolver.reexportOf(owner, name, near);
|
|
1905
|
-
const [shim] = reexport?.site.imports ?? [];
|
|
1906
|
-
if (reexport && shim && this.#resolver.pathOfSpecifier(reexport.site.fileName, shim.from) === null)
|
|
1907
|
-
return { name: reexport.local === "default" ? name : reexport.local, from: shim.from };
|
|
1908
|
-
if (reexport || !near)
|
|
1909
|
-
return null;
|
|
1910
|
-
const packages = new Set;
|
|
1911
|
-
for (const [fileName, words] of this.#resolver.filesIn(owner)) {
|
|
1912
|
-
const relative = this.#source.relative(fileName);
|
|
1913
|
-
const isNear = relative.startsWith(`${near}/`) || relative.replace(/\.tsx?$/, "") === near;
|
|
1914
|
-
if (!isNear || !words.includes(`
|
|
1915
|
-
export
|
|
1916
|
-
`))
|
|
1917
|
-
continue;
|
|
1918
|
-
for (const [, specifier = ""] of this.#source.readText(fileName)?.matchAll(starExportPattern) ?? [])
|
|
1919
|
-
if (this.#resolver.pathOfSpecifier(fileName, specifier) === null)
|
|
1920
|
-
packages.add(specifier);
|
|
1921
|
-
}
|
|
1922
|
-
const [only] = packages;
|
|
1923
|
-
return packages.size === 1 && only && !this.#resolver.declares(owner, name) ? { name, from: only } : null;
|
|
1924
|
-
}
|
|
1925
|
-
#adaptorNodeOf({ fact, owner, fileName, id }) {
|
|
1926
|
-
const detail = fact.refName ? [fact.refName] : [];
|
|
1927
|
-
const node = this.#addNode(id, "adaptor", owner, null, fact.name, fact.span, detail);
|
|
1928
|
-
if (fact.doc && !node.doc)
|
|
1929
|
-
node.doc = fact.doc;
|
|
1930
|
-
this.#digest(node, this.#source.readText(fileName), fact.extent);
|
|
1931
|
-
return node.id;
|
|
1932
|
-
}
|
|
1933
2246
|
#guardNodeOf({ name, owner, span, scope, doc, parts, file, label }) {
|
|
1934
2247
|
const id = this.#key("guard", owner, file ? `${file}#${name}` : name);
|
|
1935
2248
|
const node = this.#addNode(id, "guard", owner, null, name, span, scope ? [scope] : [], label ?? name);
|
|
@@ -2032,7 +2345,7 @@ st
|
|
|
2032
2345
|
visit(source);
|
|
2033
2346
|
}
|
|
2034
2347
|
#link(fileName, source, identifier, chain, context, owner) {
|
|
2035
|
-
const plugged = chain?.length === 2 && chain[0] === "this" && context.kind === "method" && this.#isServiceThis(identifier) ? this.#pluggedOf(context, chain[1]) : [];
|
|
2348
|
+
const plugged = chain?.length === 2 && chain[0] === "this" && context.kind === "method" && this.#isServiceThis(identifier) ? this.#adaptors.pluggedOf(context.owner, context.module, chain[1]) : [];
|
|
2036
2349
|
const resolved = plugged.length ? plugged : this.#source.resolve(fileName, identifier).map((target) => this.#targetNodeOf(target)).filter((id) => id !== null);
|
|
2037
2350
|
const targets = resolved.length ? resolved : this.#plainTargetsOf(chain, identifier.text, context, owner);
|
|
2038
2351
|
if (!targets.length)
|
|
@@ -2631,7 +2944,7 @@ var sourcePattern = /\.(constant|document|service|signal|store)\.ts$/;
|
|
|
2631
2944
|
var dictionaryPattern = /\.dictionary\.ts$/;
|
|
2632
2945
|
var srvkitPattern = /\/srvkit\//;
|
|
2633
2946
|
var wordPattern = /[A-Za-z_$][\w$]*/g;
|
|
2634
|
-
var
|
|
2947
|
+
var identifierPattern2 = /^[A-Za-z_$][\w$]*$/;
|
|
2635
2948
|
var stateReceivers = new Set(["use", "sel", "get", "do"]);
|
|
2636
2949
|
var lensFamilies = new Set(["slice", "query", "formSetter", "storeState", "endpoint"]);
|
|
2637
2950
|
var modellessFamilies = new Set(["query", "storeState", "endpoint"]);
|
|
@@ -2740,7 +3053,7 @@ ${[...new Set(text.match(wordPattern))].join(`
|
|
|
2740
3053
|
}
|
|
2741
3054
|
renameAt(givenName, offset, newKey, readText) {
|
|
2742
3055
|
const sources = this.#sourceEntriesAt(pathOf(givenName), offset).filter((entry) => entry.renamed);
|
|
2743
|
-
if (!sources.length || !
|
|
3056
|
+
if (!sources.length || !identifierPattern2.test(newKey))
|
|
2744
3057
|
return null;
|
|
2745
3058
|
return [
|
|
2746
3059
|
{ span: sources[0].span, newText: newKey },
|
|
@@ -3450,6 +3763,11 @@ ${union.name}`)));
|
|
|
3450
3763
|
const field = this.#memberOf(this.#classOf(receiver), receiver.name.text);
|
|
3451
3764
|
return field && ts.isPropertyDeclaration(field) ? this.#namesIn(field.type) : new Set;
|
|
3452
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
|
+
}
|
|
3453
3771
|
return this.#declaredTypeNames(receiver) ?? new Set;
|
|
3454
3772
|
}
|
|
3455
3773
|
#memberName(name) {
|