@akanjs/language 3.2.0-rc.9 → 3.2.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/server.js CHANGED
@@ -5,6 +5,42 @@ import { existsSync, readdirSync, readFileSync, realpathSync, statSync } from "n
5
5
  import path from "node:path";
6
6
  import { fileURLToPath, pathToFileURL } from "node:url";
7
7
 
8
+ // pkgs/akanjs/common/facetBarrel.ts
9
+ var barrelFacetDirs = ["ui", "webkit", "srvkit", "common", "plugin"];
10
+ var sourceFilePattern = /\.(ts|tsx)$/;
11
+ var excludedFilePattern = /(^index\.tsx?$|\.d\.ts$|\.(test|spec)\.(ts|tsx)$|\.css$|\.scss$|\.sass$)/;
12
+ var pascalCasePattern = /^[A-Z][A-Za-z0-9]*$/;
13
+ var camelCasePattern = /^[a-z][A-Za-z0-9]*$/;
14
+ var letterRankOf = (char) => char.toLowerCase().charCodeAt(0) * 2 + (char === char.toLowerCase() ? 1 : 0);
15
+ var digitRunAt = (name, idx) => /^\d+/.exec(name.slice(idx))?.[0] ?? "";
16
+ var compareExportNames = (a, b) => {
17
+ for (let idx = 0;idx < a.length && idx < b.length; ) {
18
+ const [runA, runB] = [digitRunAt(a, idx), digitRunAt(b, idx)];
19
+ if (runA && runB && runA !== runB)
20
+ return runA.length - runB.length || (runA < runB ? -1 : 1);
21
+ if (runA && runB)
22
+ idx += runA.length;
23
+ else if (runA || runB)
24
+ return runA ? -1 : 1;
25
+ else if (a.charAt(idx) !== b.charAt(idx))
26
+ return letterRankOf(a.charAt(idx)) - letterRankOf(b.charAt(idx));
27
+ else
28
+ idx++;
29
+ }
30
+ return a.length - b.length;
31
+ };
32
+ var facetBarrelNamesOf = (facet, files, dirs) => {
33
+ const nameCasePattern = facet === "ui" ? pascalCasePattern : camelCasePattern;
34
+ return [
35
+ ...files.filter((file) => sourceFilePattern.test(file) && !excludedFilePattern.test(file)).map((file) => file.replace(sourceFilePattern, "")),
36
+ ...dirs.filter((dir) => !dir.startsWith("."))
37
+ ].filter((name) => nameCasePattern.test(name)).sort(compareExportNames);
38
+ };
39
+
40
+ // pkgs/@akanjs/language/escapeRegExp.ts
41
+ var regExpSpecials = /[\\^$.*+?()[\]{}|]/g;
42
+ var escapeRegExp = (text) => text.replace(regExpSpecials, (special) => `\\${special}`);
43
+
8
44
  // pkgs/@akanjs/language/guardFacts.ts
9
45
  var guardLabelOf = (guard, labels) => {
10
46
  const [, role = null, local = guard] = guard.match(/^([\w$]+) (.+)$/) ?? [];
@@ -12,6 +48,7 @@ var guardLabelOf = (guard, labels) => {
12
48
  return label === undefined ? guard : role ? `${role} ${label}` : label;
13
49
  };
14
50
  var maxLabelArgs = 32;
51
+ var maxLayers = 4;
15
52
  var guardRefReaderOf = (ts, ast, unwrap) => {
16
53
  const pathOf = (expression) => {
17
54
  if (ts.isIdentifier(expression))
@@ -21,10 +58,19 @@ var guardRefReaderOf = (ts, ast, unwrap) => {
21
58
  const head = pathOf(expression.expression);
22
59
  return head && `${head}.${expression.name.text}`;
23
60
  };
24
- const calleeOf = (call) => pathOf(unwrap(call.expression)) ?? "?";
61
+ const layersOf = (call) => {
62
+ const inner = unwrap(call.expression);
63
+ if (!ts.isCallExpression(inner))
64
+ return { root: call, layers: 0 };
65
+ const { root, layers } = layersOf(inner);
66
+ return { root, layers: layers + 1 };
67
+ };
68
+ const calleeOf = (call) => pathOf(unwrap(layersOf(call).root.expression)) ?? "?";
25
69
  const labelOf = (source, call) => {
26
70
  const args = call.arguments.map((arg) => arg.getText(source)).join(", ");
27
- return `${calleeOf(call)}(${args.length <= maxLabelArgs && !args.includes(`
71
+ const inner = unwrap(call.expression);
72
+ const head = ts.isCallExpression(inner) ? labelOf(source, inner) : pathOf(inner) ?? "?";
73
+ return `${head}(${args.length <= maxLabelArgs && !args.includes(`
28
74
  `) ? args : "…"})`;
29
75
  };
30
76
  const guardRefOf = (expression, made, member) => {
@@ -52,9 +98,9 @@ var guardRefReaderOf = (ts, ast, unwrap) => {
52
98
  const single = refOf(guards);
53
99
  return single ? [single] : [];
54
100
  };
55
- return { pathOf, labelOf, guardsIn };
101
+ return { pathOf, layersOf, labelOf, guardsIn };
56
102
  };
57
- var guardFactoryReaderOf = (ts, ast, { spanOf, extentOf, unwrap, docOf }, pathOf) => {
103
+ var guardFactoryReaderOf = (ts, ast, { spanOf, extentOf, unwrap, docOf }, pathOf, layersOf) => {
58
104
  const implementsGuard = (node, guardNames) => !!node.heritageClauses?.some((clause) => clause.token === ts.SyntaxKind.ImplementsKeyword && clause.types.some(({ expression }) => guardNames.has(ast.expressionName(expression) ?? "")));
59
105
  const scopeOf = (node) => {
60
106
  const scope = node.members.find((member) => ts.isPropertyDeclaration(member) && ast.nodeName(member.name) === "scope" && !!ts.getModifiers(member)?.some(({ kind }) => kind === ts.SyntaxKind.StaticKeyword))?.initializer;
@@ -76,7 +122,7 @@ var guardFactoryReaderOf = (ts, ast, { spanOf, extentOf, unwrap, docOf }, pathOf
76
122
  }
77
123
  return functions;
78
124
  };
79
- const returnedOf = (body, guardNames) => {
125
+ const returnedOf = (body, guardNames, depth = 0) => {
80
126
  const locals = new Map;
81
127
  const pending = [];
82
128
  const visit = (node) => {
@@ -97,6 +143,7 @@ var guardFactoryReaderOf = (ts, ast, { spanOf, extentOf, unwrap, docOf }, pathOf
97
143
  const calls = [];
98
144
  const seen = new Set;
99
145
  const passed = new Set;
146
+ const returned = [];
100
147
  for (let node = pending.pop();node; node = pending.pop()) {
101
148
  if (seen.has(node))
102
149
  continue;
@@ -104,6 +151,8 @@ var guardFactoryReaderOf = (ts, ast, { spanOf, extentOf, unwrap, docOf }, pathOf
104
151
  const value = ts.isExpression(node) ? unwrap(node) : node;
105
152
  if ((ts.isClassExpression(value) || ts.isClassDeclaration(value)) && implementsGuard(value, guardNames))
106
153
  guard ??= value;
154
+ else if ((ts.isArrowFunction(value) || ts.isFunctionExpression(value)) && !passed.has(node) && depth < maxLayers)
155
+ returned.push(value.body);
107
156
  else if (ts.isConditionalExpression(value))
108
157
  pending.push(value.whenTrue, value.whenFalse);
109
158
  else if (ts.isBinaryExpression(value))
@@ -113,15 +162,22 @@ var guardFactoryReaderOf = (ts, ast, { spanOf, extentOf, unwrap, docOf }, pathOf
113
162
  if (local)
114
163
  pending.push(local);
115
164
  } else if (ts.isCallExpression(value)) {
116
- const callee = pathOf(unwrap(value.expression));
117
- if (callee && !passed.has(node) && !calls.includes(callee))
118
- calls.push(callee);
119
- for (const arg of value.arguments)
120
- passed.add(arg);
121
- pending.push(...value.arguments);
165
+ const { root, layers } = layersOf(value);
166
+ const callee = pathOf(unwrap(root.expression));
167
+ if (callee && !passed.has(node) && !calls.some((call) => call.callee === callee))
168
+ calls.push({ callee, layers });
169
+ for (let call = value;ts.isCallExpression(call); call = unwrap(call.expression)) {
170
+ for (const arg of call.arguments)
171
+ passed.add(arg);
172
+ pending.push(...call.arguments);
173
+ }
122
174
  }
123
175
  }
124
- return { guard, calls };
176
+ const [inner] = returned;
177
+ if (guard || calls.length || !inner)
178
+ return { guard, calls, layers: 0 };
179
+ const nested = returnedOf(inner, guardNames, depth + 1);
180
+ return { ...nested, layers: nested.layers + 1 };
125
181
  };
126
182
  const guardFactoriesOf = (source, guardNames, isImported) => {
127
183
  const functions = functionsOf(source);
@@ -131,7 +187,7 @@ var guardFactoryReaderOf = (ts, ast, { spanOf, extentOf, unwrap, docOf }, pathOf
131
187
  for (let isGrowing = true;isGrowing; ) {
132
188
  isGrowing = false;
133
189
  for (const [name, { guard, calls }] of returned) {
134
- if (members.has(name) || !guard && !calls.some(isFactoryCall))
190
+ if (members.has(name) || !guard && !calls.some(({ callee }) => isFactoryCall(callee)))
135
191
  continue;
136
192
  members.add(name);
137
193
  isGrowing = true;
@@ -150,7 +206,8 @@ var guardFactoryReaderOf = (ts, ast, { spanOf, extentOf, unwrap, docOf }, pathOf
150
206
  scope: made.guard ? scopeOf(made.guard) : null,
151
207
  doc: docOf(source, found.statement),
152
208
  direct: !!made.guard,
153
- via: made.calls.filter(isFactoryCall)
209
+ via: made.calls.filter(({ callee }) => isFactoryCall(callee)),
210
+ layers: made.layers
154
211
  });
155
212
  }
156
213
  return factories;
@@ -159,8 +216,8 @@ var guardFactoryReaderOf = (ts, ast, { spanOf, extentOf, unwrap, docOf }, pathOf
159
216
  };
160
217
  var createGuardFactReader = (ts, ast, base) => {
161
218
  const { spanOf, extentOf, unwrap, docOf } = base;
162
- const { pathOf, labelOf, guardsIn } = guardRefReaderOf(ts, ast, unwrap);
163
- const { implementsGuard, scopeOf, guardFactoriesOf } = guardFactoryReaderOf(ts, ast, base, pathOf);
219
+ const { pathOf, layersOf, labelOf, guardsIn } = guardRefReaderOf(ts, ast, unwrap);
220
+ const { implementsGuard, scopeOf, guardFactoriesOf } = guardFactoryReaderOf(ts, ast, base, pathOf, layersOf);
164
221
  const guardsOf = (source, imports, madeInPlace) => {
165
222
  const guardNames = new Set([
166
223
  "Guard",
@@ -173,15 +230,16 @@ var createGuardFactReader = (ts, ast, base) => {
173
230
  const calls = [];
174
231
  const makeOf = (made, value, isInPlace = false) => {
175
232
  if (ts.isClassExpression(value) && implementsGuard(value, guardNames)) {
176
- guards.push({ ...made, scope: scopeOf(value), factory: null });
233
+ guards.push({ ...made, scope: scopeOf(value), factory: null, layers: 0 });
177
234
  return;
178
235
  }
179
- const callee = ts.isCallExpression(value) ? pathOf(unwrap(value.expression)) : null;
236
+ const { root, layers } = ts.isCallExpression(value) ? layersOf(value) : { root: null, layers: 0 };
237
+ const callee = root && pathOf(unwrap(root.expression));
180
238
  const factory = callee && factories.get(callee);
181
239
  if (factory)
182
- guards.push({ ...made, scope: factory.scope, factory: factory.name });
240
+ guards.push({ ...made, scope: factory.scope, factory: factory.name, layers });
183
241
  else if (callee && (isImported(callee) || isInPlace))
184
- calls.push({ ...made, callee, kind: "call", scope: null });
242
+ calls.push({ ...made, callee, kind: "call", scope: null, layers });
185
243
  };
186
244
  for (const statement of source.statements) {
187
245
  if (ts.isClassDeclaration(statement) && statement.name) {
@@ -195,9 +253,9 @@ var createGuardFactReader = (ts, ast, base) => {
195
253
  const base = statement.heritageClauses?.find(({ token }) => token === ts.SyntaxKind.ExtendsKeyword)?.types[0];
196
254
  const callee = base && pathOf(base.expression);
197
255
  if (implementsGuard(statement, guardNames))
198
- guards.push({ ...declared, factory: null });
256
+ guards.push({ ...declared, factory: null, layers: 0 });
199
257
  else if (callee)
200
- calls.push({ ...declared, callee, kind: "extends" });
258
+ calls.push({ ...declared, callee, kind: "extends", layers: 0 });
201
259
  }
202
260
  if (!ts.isVariableStatement(statement))
203
261
  continue;
@@ -234,10 +292,6 @@ var createGuardFactReader = (ts, ast, base) => {
234
292
  return { guardsIn, guardsOf };
235
293
  };
236
294
 
237
- // pkgs/@akanjs/language/escapeRegExp.ts
238
- var regExpSpecials = /[\\^$.*+?()[\]{}|]/g;
239
- var escapeRegExp = (text) => text.replace(regExpSpecials, (special) => `\\${special}`);
240
-
241
295
  // pkgs/@akanjs/language/moduleFacts.ts
242
296
  var testFilePattern = /\.(?:test|spec)\.tsx?$/;
243
297
  var moduleCallees = new Set([
@@ -264,7 +318,7 @@ var ownerOf = (relativePath) => {
264
318
  const [root, name] = relativePath.split("/");
265
319
  return (root === "apps" || root === "libs") && name ? `${root}/${name}` : null;
266
320
  };
267
- var createFactReader = (ts, ast) => {
321
+ var syntaxReaderOf = (ts, ast) => {
268
322
  const spanOf = (source, node) => {
269
323
  const start = node.getStart(source);
270
324
  const end = node.getEnd();
@@ -322,6 +376,74 @@ var createFactReader = (ts, ast) => {
322
376
  const node = keyName(property);
323
377
  return name && node ? [{ name, span: spanOf(source, node), extent: extentOf(source, property) }] : [];
324
378
  });
379
+ const verbReaderOf = (parameter) => {
380
+ const verbs = new Map;
381
+ if (parameter && ts.isObjectBindingPattern(parameter.name))
382
+ for (const element of parameter.name.elements) {
383
+ const verb = element.propertyName ?? element.name;
384
+ if (ts.isIdentifier(verb) && ts.isIdentifier(element.name))
385
+ verbs.set(element.name.text, verb.text);
386
+ }
387
+ const holder = parameter && ts.isIdentifier(parameter.name) ? parameter.name.text : null;
388
+ return (callee) => {
389
+ if (callee && ts.isIdentifier(callee))
390
+ return verbs.get(callee.text) ?? null;
391
+ if (callee && ts.isPropertyAccessExpression(callee) && ts.isIdentifier(callee.expression) && callee.expression.text === holder)
392
+ return callee.name.text;
393
+ return null;
394
+ };
395
+ };
396
+ return {
397
+ spanOf,
398
+ extentOf,
399
+ unwrap,
400
+ moduleRefOf,
401
+ returnedObject,
402
+ builderOf,
403
+ guardNameOf,
404
+ optionObjectOf,
405
+ chainOf,
406
+ keyName,
407
+ objectKeys,
408
+ verbReaderOf
409
+ };
410
+ };
411
+ var sourceReaderOf = (ts) => {
412
+ const importsOf = (statement) => {
413
+ const { importClause, moduleSpecifier } = statement;
414
+ if (!importClause || !ts.isStringLiteral(moduleSpecifier))
415
+ return [];
416
+ const from = moduleSpecifier.text;
417
+ const bindings = importClause.namedBindings;
418
+ return [
419
+ ...importClause.name ? [{ name: importClause.name.text, imported: "default", from }] : [],
420
+ ...bindings && ts.isNamespaceImport(bindings) ? [{ name: bindings.name.text, imported: "*", from }] : [],
421
+ ...bindings && ts.isNamedImports(bindings) ? bindings.elements.map((element) => ({
422
+ name: element.name.text,
423
+ imported: (element.propertyName ?? element.name).text,
424
+ from
425
+ })) : []
426
+ ];
427
+ };
428
+ const docOf = (source, node) => {
429
+ const { text } = source;
430
+ const ranges = ts.getLeadingCommentRanges(text, node.getFullStart()) ?? [];
431
+ const comments = [];
432
+ let end = node.getStart(source);
433
+ for (const range of [...ranges].reverse()) {
434
+ if ((text.slice(range.end, end).match(/\n/g)?.length ?? 0) > 1)
435
+ break;
436
+ comments.unshift(text.slice(range.pos, range.end));
437
+ end = range.pos;
438
+ }
439
+ const lines = comments.flatMap((comment) => comment.split(`
440
+ `)).map((line) => line.trim().replace(/^\/\*\*?|\*\/$/g, "").replace(/^(?:\/\/[?*!]?|\*)/, "").replace(/\{@link\s+([^}\s|]+)[^}]*\}/g, "$1").trim()).filter((line) => line && !/^(?:biome-ignore|eslint-|@ts-)/.test(line));
441
+ return lines.length ? lines.join(" ") : null;
442
+ };
443
+ const importsIn = (source) => source.statements.filter(ts.isImportDeclaration).flatMap(importsOf);
444
+ return { docOf, importsIn };
445
+ };
446
+ var signalKeyReaderOf = (ts, ast, { spanOf, extentOf, returnedObject, optionObjectOf, chainOf, verbReaderOf }, guardsIn) => {
325
447
  const sliceKeysOf = (source, builder, made, model) => (returnedObject(builder)?.properties ?? []).flatMap((property) => {
326
448
  if (!ts.isPropertyAssignment(property))
327
449
  return [];
@@ -340,23 +462,30 @@ var createFactReader = (ts, ast) => {
340
462
  }
341
463
  ];
342
464
  });
343
- const verbReaderOf = (parameter) => {
344
- const verbs = new Map;
345
- if (parameter && ts.isObjectBindingPattern(parameter.name))
346
- for (const element of parameter.name.elements) {
347
- const verb = element.propertyName ?? element.name;
348
- if (ts.isIdentifier(verb) && ts.isIdentifier(element.name))
349
- verbs.set(element.name.text, verb.text);
350
- }
351
- const holder = parameter && ts.isIdentifier(parameter.name) ? parameter.name.text : null;
352
- return (callee) => {
353
- if (callee && ts.isIdentifier(callee))
354
- return verbs.get(callee.text) ?? null;
355
- if (callee && ts.isPropertyAccessExpression(callee) && ts.isIdentifier(callee.expression) && callee.expression.text === holder)
356
- return callee.name.text;
357
- return null;
358
- };
465
+ const endpointKeysOf = (source, builder, made, model) => {
466
+ const verbOf = verbReaderOf(builder?.parameters[0]);
467
+ return (returnedObject(builder)?.properties ?? []).flatMap((property) => {
468
+ if (!ts.isPropertyAssignment(property))
469
+ return [];
470
+ const name = ast.nodeName(property.name);
471
+ if (!name)
472
+ return [];
473
+ const { root, methods } = chainOf(property.initializer);
474
+ return [
475
+ {
476
+ name,
477
+ span: spanOf(source, property.name),
478
+ extent: extentOf(source, property),
479
+ verb: root ? verbOf(root.expression) : null,
480
+ guards: root ? guardsIn(source, optionObjectOf(root), made, `${model}.${name}`) : [],
481
+ argCount: methods.filter((method) => argMethods.has(method)).length
482
+ }
483
+ ];
484
+ });
359
485
  };
486
+ return { sliceKeysOf, endpointKeysOf };
487
+ };
488
+ var jobKeyReaderOf = (ts, ast, { spanOf, extentOf, unwrap, returnedObject, chainOf, verbReaderOf }) => {
360
489
  const numberOf = (expression) => {
361
490
  const value = unwrap(expression);
362
491
  if (ts.isNumericLiteral(value))
@@ -429,6 +558,9 @@ var createFactReader = (ts, ast) => {
429
558
  ];
430
559
  });
431
560
  };
561
+ return { internalKeysOf };
562
+ };
563
+ var serviceReaderOf = (ts, ast, { spanOf, extentOf, returnedObject, guardNameOf, chainOf, verbReaderOf }) => {
432
564
  const plugsOf = (source, builder) => {
433
565
  const verbOf = verbReaderOf(builder?.parameters[0]);
434
566
  return (returnedObject(builder)?.properties ?? []).flatMap((property) => {
@@ -454,27 +586,17 @@ var createFactReader = (ts, ast) => {
454
586
  visit(source);
455
587
  return bindings;
456
588
  };
457
- const endpointKeysOf = (source, builder, made, model) => {
458
- const verbOf = verbReaderOf(builder?.parameters[0]);
459
- return (returnedObject(builder)?.properties ?? []).flatMap((property) => {
460
- if (!ts.isPropertyAssignment(property))
461
- return [];
462
- const name = ast.nodeName(property.name);
463
- if (!name)
464
- return [];
465
- const { root, methods } = chainOf(property.initializer);
466
- return [
467
- {
468
- name,
469
- span: spanOf(source, property.name),
470
- extent: extentOf(source, property),
471
- verb: root ? verbOf(root.expression) : null,
472
- guards: root ? guardsIn(source, optionObjectOf(root), made, `${model}.${name}`) : [],
473
- argCount: methods.filter((method) => argMethods.has(method)).length
474
- }
475
- ];
476
- });
477
- };
589
+ const methodsOf = (source, statement) => statement.members.flatMap((member) => {
590
+ if (!ts.isMethodDeclaration(member) || !member.body)
591
+ return [];
592
+ const name = ast.nodeName(member.name);
593
+ if (!name || ts.getModifiers(member)?.some(({ kind }) => kind === ts.SyntaxKind.StaticKeyword))
594
+ return [];
595
+ return [{ name, span: spanOf(source, member.name), extent: extentOf(source, member) }];
596
+ });
597
+ return { plugsOf, adaptorBindingsIn, methodsOf };
598
+ };
599
+ var constantReaderOf = (ts, ast, { spanOf, extentOf, unwrap, returnedObject, chainOf, keyName, objectKeys }) => {
478
600
  const filterQueriesOf = (source, builder) => {
479
601
  const query = returnedObject(builder)?.properties.find((property) => ts.isPropertyAssignment(property) && ast.nodeName(property.name) === "query")?.initializer;
480
602
  return query && ts.isObjectLiteralExpression(query) ? objectKeys(source, query) : [];
@@ -512,48 +634,18 @@ var createFactReader = (ts, ast) => {
512
634
  return [];
513
635
  return list.elements.flatMap((element) => ts.isStringLiteralLike(element) ? [element.text] : []);
514
636
  };
515
- const methodsOf = (source, statement) => statement.members.flatMap((member) => {
516
- if (!ts.isMethodDeclaration(member) || !member.body)
517
- return [];
518
- const name = ast.nodeName(member.name);
519
- if (!name || ts.getModifiers(member)?.some(({ kind }) => kind === ts.SyntaxKind.StaticKeyword))
520
- return [];
521
- return [{ name, span: spanOf(source, member.name), extent: extentOf(source, member) }];
522
- });
523
- const importsOf = (statement) => {
524
- const { importClause, moduleSpecifier } = statement;
525
- if (!importClause || !ts.isStringLiteral(moduleSpecifier))
526
- return [];
527
- const from = moduleSpecifier.text;
528
- const bindings = importClause.namedBindings;
529
- return [
530
- ...importClause.name ? [{ name: importClause.name.text, imported: "default", from }] : [],
531
- ...bindings && ts.isNamespaceImport(bindings) ? [{ name: bindings.name.text, imported: "*", from }] : [],
532
- ...bindings && ts.isNamedImports(bindings) ? bindings.elements.map((element) => ({
533
- name: element.name.text,
534
- imported: (element.propertyName ?? element.name).text,
535
- from
536
- })) : []
537
- ];
538
- };
539
- const docOf = (source, node) => {
540
- const { text } = source;
541
- const ranges = ts.getLeadingCommentRanges(text, node.getFullStart()) ?? [];
542
- const comments = [];
543
- let end = node.getStart(source);
544
- for (const range of [...ranges].reverse()) {
545
- if ((text.slice(range.end, end).match(/\n/g)?.length ?? 0) > 1)
546
- break;
547
- comments.unshift(text.slice(range.pos, range.end));
548
- end = range.pos;
549
- }
550
- const lines = comments.flatMap((comment) => comment.split(`
551
- `)).map((line) => line.trim().replace(/^\/\*\*?|\*\/$/g, "").replace(/^(?:\/\/[?*!]?|\*)/, "").replace(/\{@link\s+([^}\s|]+)[^}]*\}/g, "$1").trim()).filter((line) => line && !/^(?:biome-ignore|eslint-|@ts-)/.test(line));
552
- return lines.length ? lines.join(" ") : null;
553
- };
637
+ return { constantOf, enumValuesOf, filterQueriesOf };
638
+ };
639
+ var createFactReader = (ts, ast) => {
640
+ const syntax = syntaxReaderOf(ts, ast);
641
+ const { spanOf, extentOf, unwrap, moduleRefOf, returnedObject, builderOf, chainOf, objectKeys } = syntax;
642
+ const { docOf, importsIn } = sourceReaderOf(ts);
554
643
  const { guardsIn, guardsOf } = createGuardFactReader(ts, ast, { spanOf, extentOf, unwrap, docOf });
644
+ const { sliceKeysOf, endpointKeysOf } = signalKeyReaderOf(ts, ast, syntax, guardsIn);
645
+ const { internalKeysOf } = jobKeyReaderOf(ts, ast, syntax);
646
+ const { plugsOf, adaptorBindingsIn, methodsOf } = serviceReaderOf(ts, ast, syntax);
647
+ const { constantOf, enumValuesOf, filterQueriesOf } = constantReaderOf(ts, ast, syntax);
555
648
  const lowerFirst = (text) => text.charAt(0).toLowerCase() + text.slice(1);
556
- const importsIn = (source) => source.statements.filter(ts.isImportDeclaration).flatMap(importsOf);
557
649
  const read = (source, owner) => {
558
650
  const imports = importsIn(source);
559
651
  const madeInPlace = [];
@@ -651,7 +743,11 @@ var frameworkOwner = "akanjs";
651
743
  var frameworkPattern = /^akanjs(?:\/|$)/;
652
744
  var aliasPattern = /^@(apps|libs)\/([^/]+)/;
653
745
  var maxMapDepth = 4;
746
+ var identifierPattern = /^[\p{ID_Start}$_][\p{ID_Continue}$\u200c\u200d]*$/u;
654
747
  var starExportPattern = /export\s*\*\s*from\s*["']([^"']+)["']/g;
748
+ var facetEntryPattern = new RegExp(`^((?:apps|libs)/[^/]+/(${barrelFacetDirs.map(escapeRegExp).join("|")}))/([^/]+)(/)?`);
749
+ var exportingPatternOf = (name) => new RegExp(`export\\s*\\{(?:[^}]*?[\\s,])?${escapeRegExp(name)}(?![\\w$])`);
750
+ var exportMentioningPatternOf = (name) => new RegExp(`export(?![\\w$])[^;]*?(?<![\\w$])${escapeRegExp(name)}(?![\\w$])`);
655
751
  var declaringPatternOf = (name, isAnyBinding) => {
656
752
  const escaped = escapeRegExp(name);
657
753
  const braced = "\\{(?:[^}]*?[\\s,])?";
@@ -673,8 +769,12 @@ class GuardResolver {
673
769
  #reexports = new Map;
674
770
  #declarations = new Map;
675
771
  #starExports = new Map;
772
+ #moduleExports = new Map;
773
+ #fileStars = new Map;
774
+ #starReach = new Map;
676
775
  #ownerFiles = null;
677
776
  #modules = null;
777
+ #barrels = null;
678
778
  constructor(source, routes) {
679
779
  this.#source = source;
680
780
  this.#routes = routes;
@@ -698,21 +798,26 @@ ${name}`);
698
798
  made: [],
699
799
  isReal: fact.direct,
700
800
  scope: fact.scope,
801
+ layers: fact.layers,
701
802
  targets: []
702
803
  };
703
804
  factories.set(fact.name, [...factories.get(fact.name) ?? [], factory]);
704
805
  declaredFactories.push(factory);
705
806
  }
706
807
  for (const factory of declaredFactories)
707
- factory.targets = factory.fact.via.map((callee) => this.#factoryAt(factories, callee, factory.site)).filter((target) => target !== undefined);
808
+ factory.targets = factory.fact.via.flatMap(({ callee, layers }) => {
809
+ const target = this.#factoryAt(factories, callee, factory.site);
810
+ return target ? [{ target, layers }] : [];
811
+ });
708
812
  for (let isGrowing = true;isGrowing; ) {
709
813
  isGrowing = false;
710
814
  for (const factory of declaredFactories) {
711
- const target = factory.targets.find((other) => other.isReal);
712
- if (factory.isReal || !target)
815
+ const via = factory.targets.find(({ target, layers }) => target.isReal && target.layers >= layers);
816
+ if (factory.isReal || !via)
713
817
  continue;
714
818
  factory.isReal = true;
715
- factory.scope ??= target.scope;
819
+ factory.layers = factory.fact.layers + via.target.layers - via.layers;
820
+ factory.scope ??= via.target.scope;
716
821
  isGrowing = true;
717
822
  }
718
823
  }
@@ -722,7 +827,7 @@ ${name}`);
722
827
  seen.add(factory);
723
828
  return [
724
829
  { fileName: factory.site.fileName, extent: factory.fact.extent },
725
- ...factory.targets.filter((target) => target.isReal).flatMap((target) => partsOf(target, seen))
830
+ ...factory.targets.filter(({ target }) => target.isReal).flatMap(({ target }) => partsOf(target, seen))
726
831
  ];
727
832
  };
728
833
  const declare = (file, made, scope, parts) => {
@@ -743,7 +848,7 @@ ${name}`, guard);
743
848
  const factory = made.factory ? factories.get(made.factory)?.find((other) => other.site.fileName === file.fileName) : undefined;
744
849
  if (!made.factory)
745
850
  declare(file, made, made.scope, []);
746
- else if (factory?.isReal)
851
+ else if (factory?.isReal && factory.layers === made.layers)
747
852
  factory.made.push(declare(file, made, factory.scope, partsOf(factory)));
748
853
  }
749
854
  for (const made of file.guardCalls) {
@@ -752,7 +857,7 @@ ${name}`, guard);
752
857
  continue;
753
858
  }
754
859
  const factory = this.#factoryAt(factories, made.callee, file);
755
- if (factory?.isReal)
860
+ if (factory?.isReal && factory.layers === made.layers)
756
861
  factory.made.push(declare(file, made, factory.scope, partsOf(factory)));
757
862
  }
758
863
  }
@@ -797,7 +902,7 @@ ${name}`, guard);
797
902
  const own = this.#nearest(candidates.filter((other) => other.owner === from), ({ site }) => site.fileName, near);
798
903
  if (own)
799
904
  return own;
800
- const reexport = from && depth < maxMapDepth ? this.reexportOf(from, name, near) : null;
905
+ const reexport = from && depth < maxMapDepth ? this.#reexportOf(from, name, near) : null;
801
906
  if (reexport)
802
907
  return this.#factoryAt(factories, reexport.local, reexport.site, depth + 1);
803
908
  return from && near ? this.#throughStar(candidates, from, name, near) : undefined;
@@ -835,13 +940,13 @@ ${name}`, guard);
835
940
  const visible = isBase ? undefined : declared.find((other) => this.visible(other.owner, site.owner));
836
941
  return visible ? { guard: visible } : { name, from };
837
942
  }
838
- const reexport = from && depth < maxMapDepth ? this.reexportOf(from, name, near) : null;
943
+ const reexport = from && depth < maxMapDepth ? this.#reexportOf(from, name, near) : null;
839
944
  if (reexport)
840
945
  return this.#findGuard(reexport.local, reexport.site, depth + 1, isBase);
841
946
  const reached = from && near ? this.#throughStar(declared, from, name, near) : undefined;
842
947
  return reached ? { guard: reached } : { name, from };
843
948
  }
844
- reexportOf(owner, name, near) {
949
+ #reexportOf(owner, name, near) {
845
950
  const key = `${owner}
846
951
  ${name}
847
952
  ${near ?? ""}`;
@@ -849,7 +954,7 @@ ${near ?? ""}`;
849
954
  if (cached !== undefined)
850
955
  return cached;
851
956
  let found = null;
852
- const exporting = new RegExp(`export\\s*\\{(?:[^}]*?[\\s,])?${escapeRegExp(name)}(?![\\w$])`);
957
+ const exporting = exportingPatternOf(name);
853
958
  for (const fileName of this.#filesOf(owner, name, near)) {
854
959
  const text = this.#source.readText(fileName);
855
960
  if (text === undefined || !exporting.test(text))
@@ -867,7 +972,7 @@ ${near ?? ""}`;
867
972
  this.#reexports.set(key, found);
868
973
  return found;
869
974
  }
870
- #reexportIn(source, name) {
975
+ #reexportIn(source, name, takesPackageDefault = false) {
871
976
  const { ts, reader } = this.#source;
872
977
  for (const statement of source.statements) {
873
978
  if (!ts.isExportDeclaration(statement) || statement.isTypeOnly)
@@ -884,7 +989,9 @@ ${near ?? ""}`;
884
989
  const imported = reader.importsIn(source).find((item) => item.name === original);
885
990
  if (!imported)
886
991
  return { name: original, from: null };
887
- return imported.imported === "default" || imported.imported === "*" ? null : { name: imported.imported, from: imported.from };
992
+ if (imported.imported === "default")
993
+ return takesPackageDefault && this.pathOfSpecifier(source.fileName, imported.from) === null ? { name: "default", from: imported.from } : null;
994
+ return imported.imported === "*" ? null : { name: imported.imported, from: imported.from };
888
995
  }
889
996
  return null;
890
997
  }
@@ -893,7 +1000,9 @@ ${near ?? ""}`;
893
1000
  const relative = this.#source.relative(fileName);
894
1001
  return !!near && (relative.startsWith(`${near}/`) || relative.replace(/\.tsx?$/, "") === near);
895
1002
  };
896
- const candidates = this.filesIn(owner).filter(([, words]) => words.includes(`
1003
+ if (!identifierPattern.test(name))
1004
+ return [];
1005
+ const candidates = this.#filesIn(owner).filter(([, words]) => words.includes(`
897
1006
  ${name}
898
1007
  `)).map(([fileName]) => fileName);
899
1008
  return [...candidates.filter(isNear), ...candidates.filter((other) => !isNear(other))];
@@ -910,7 +1019,7 @@ ${owner ?? ""}`;
910
1019
  const entries = [];
911
1020
  const fileNames = [
912
1021
  ...fileName ? [fileName] : [],
913
- ...(owner === null ? [] : this.filesIn(owner)).filter(([other, words]) => other !== fileName && words.includes(`
1022
+ ...(owner === null ? [] : this.#filesIn(owner)).filter(([other, words]) => other !== fileName && words.includes(`
914
1023
  ${objectName}
915
1024
  `) && words.includes(`
916
1025
  ${member}
@@ -984,30 +1093,120 @@ ${near ?? ""}`;
984
1093
  #throughStar(declared, owner, name, near) {
985
1094
  if (!declared.length)
986
1095
  return;
987
- const { owners, isOpaque } = this.#starExportsOf(owner, near);
1096
+ const { owners, isOpaque } = this.starExportsOf(owner, near);
988
1097
  const reached = declared.filter((other) => other.owner !== null && owners.includes(other.owner));
989
1098
  return reached.length === 1 && !isOpaque && !this.declares(owner, name) ? reached[0] : undefined;
990
1099
  }
991
- #starExportsOf(owner, near) {
992
- const cached = this.#starExports.get(near);
1100
+ starExportsOf(owner, near) {
1101
+ const key = `${owner}
1102
+ ${near}`;
1103
+ const cached = this.#starExports.get(key);
993
1104
  if (cached)
994
1105
  return cached;
995
- const found = { owners: [], isOpaque: false };
996
- this.#starExports.set(near, found);
997
- const paths = [near];
998
- for (let idx = 0;idx < paths.length && !found.isOpaque; idx++)
999
- for (const fileName of this.#modulesAt(paths[idx] ?? "")) {
1000
- for (const [, specifier = ""] of this.#source.readText(fileName)?.matchAll(starExportPattern) ?? []) {
1001
- const target = this.ownerOfSpecifier(fileName, specifier);
1002
- const path = this.pathOfSpecifier(fileName, specifier);
1003
- if (target === undefined || target === frameworkOwner || path === null)
1004
- found.isOpaque = true;
1005
- else if (!paths.includes(path))
1006
- paths.push(path);
1007
- if (target && target !== frameworkOwner && target !== owner && !found.owners.includes(target))
1008
- found.owners.push(target);
1009
- }
1106
+ const found = { owners: [], packages: [], paths: [near], isOpaque: false };
1107
+ this.#starExports.set(key, found);
1108
+ const reach = (specifier, path, target) => {
1109
+ if (path === null && !found.packages.includes(specifier))
1110
+ found.packages.push(specifier);
1111
+ if (target === undefined || target === frameworkOwner || path === null)
1112
+ found.isOpaque = true;
1113
+ else if (!found.paths.includes(path))
1114
+ found.paths.push(path);
1115
+ if (target && target !== frameworkOwner && target !== owner && !found.owners.includes(target))
1116
+ found.owners.push(target);
1117
+ };
1118
+ for (let idx = 0;idx < found.paths.length; idx++) {
1119
+ const path = found.paths[idx] ?? "";
1120
+ for (const module of this.#barrelAt(path) ?? [])
1121
+ reach(module, module, ownerOf(module) ?? undefined);
1122
+ for (const fileName of this.#modulesAt(path))
1123
+ for (const [, specifier = ""] of this.#source.readText(fileName)?.matchAll(starExportPattern) ?? [])
1124
+ reach(specifier, this.pathOfSpecifier(fileName, specifier), this.ownerOfSpecifier(fileName, specifier));
1125
+ }
1126
+ return found;
1127
+ }
1128
+ exportsAt(path, name) {
1129
+ const key = `${path}
1130
+ ${name}`;
1131
+ const cached = this.#moduleExports.get(key);
1132
+ if (cached)
1133
+ return cached;
1134
+ const found = { named: null, stars: [], isLocal: false };
1135
+ const stars = new Set(this.#barrelAt(path));
1136
+ for (const fileName of this.#modulesAt(path)) {
1137
+ const text = this.#source.readText(fileName);
1138
+ if (text === undefined)
1139
+ continue;
1140
+ const named = text.includes(name) && identifierPattern.test(name) && exportingPatternOf(name).test(text) ? this.#reexportIn(this.#source.parse(fileName, text), name, true) : null;
1141
+ if (named) {
1142
+ found.named = { ...named, fileName };
1143
+ break;
1144
+ }
1145
+ if (text.includes(name) && exportMentioningPatternOf(name).test(text) && this.#exportsLocally(this.#source.parse(fileName, text), name)) {
1146
+ found.isLocal = true;
1147
+ break;
1148
+ }
1149
+ for (const target of this.#starsIn(fileName, text))
1150
+ stars.add(target);
1151
+ }
1152
+ if (!found.named && !found.isLocal)
1153
+ found.stars = [...stars];
1154
+ this.#moduleExports.set(key, found);
1155
+ return found;
1156
+ }
1157
+ #exportsLocally(source, name) {
1158
+ const { ts } = this.#source;
1159
+ const binds = (node) => ts.isIdentifier(node) ? node.text === name : node.elements.some((element) => !ts.isOmittedExpression(element) && binds(element.name));
1160
+ return source.statements.some((statement) => {
1161
+ if (ts.isExportDeclaration(statement)) {
1162
+ const { exportClause, isTypeOnly, moduleSpecifier } = statement;
1163
+ if (isTypeOnly || !exportClause)
1164
+ return false;
1165
+ if (ts.isNamespaceExport(exportClause))
1166
+ return exportClause.name.text === name;
1167
+ return !moduleSpecifier && ts.isNamedExports(exportClause) && exportClause.elements.some((element) => !element.isTypeOnly && element.name.text === name);
1168
+ }
1169
+ const modifiers = ts.canHaveModifiers(statement) ? ts.getModifiers(statement) ?? [] : [];
1170
+ if (!modifiers.some(({ kind }) => kind === ts.SyntaxKind.ExportKeyword) || modifiers.some(({ kind }) => kind === ts.SyntaxKind.DefaultKeyword))
1171
+ return false;
1172
+ if (ts.isVariableStatement(statement))
1173
+ return statement.declarationList.declarations.some((declaration) => binds(declaration.name));
1174
+ 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;
1175
+ });
1176
+ }
1177
+ mentionsAlong(path, name) {
1178
+ return this.#starReachOf(path).some((text) => text.includes(name));
1179
+ }
1180
+ #starReachOf(path) {
1181
+ const cached = this.#starReach.get(path);
1182
+ if (cached)
1183
+ return cached;
1184
+ const paths = new Set([path]);
1185
+ const texts = [];
1186
+ for (const at of paths) {
1187
+ for (const next of this.#barrelAt(at) ?? [])
1188
+ paths.add(next);
1189
+ for (const fileName of this.#modulesAt(at)) {
1190
+ const text = this.#source.readText(fileName) ?? "";
1191
+ texts.push(text);
1192
+ for (const next of this.#starsIn(fileName, text))
1193
+ paths.add(next);
1010
1194
  }
1195
+ }
1196
+ this.#starReach.set(path, texts);
1197
+ return texts;
1198
+ }
1199
+ #starsIn(fileName, text) {
1200
+ const cached = this.#fileStars.get(fileName);
1201
+ if (cached)
1202
+ return cached;
1203
+ const found = [];
1204
+ for (const [, specifier = ""] of text.matchAll(starExportPattern)) {
1205
+ const target = this.pathOfSpecifier(fileName, specifier);
1206
+ if (target !== null)
1207
+ found.push(target);
1208
+ }
1209
+ this.#fileStars.set(fileName, found);
1011
1210
  return found;
1012
1211
  }
1013
1212
  #modulesAt(path) {
@@ -1021,11 +1220,33 @@ ${near ?? ""}`;
1021
1220
  }
1022
1221
  return this.#modules.get(path) ?? [];
1023
1222
  }
1223
+ #barrelAt(path) {
1224
+ if (!this.#barrels) {
1225
+ const entries = new Map;
1226
+ for (const [fileName] of this.#source.files) {
1227
+ const [, folder, facet, entry, nested] = this.#source.relative(fileName).match(facetEntryPattern) ?? [];
1228
+ if (!folder || !facet || !entry)
1229
+ continue;
1230
+ const found = entries.get(folder) ?? { facet, files: new Set, dirs: new Set };
1231
+ (nested ? found.dirs : found.files).add(entry);
1232
+ entries.set(folder, found);
1233
+ }
1234
+ this.#barrels = new Map([...entries].map(([folder, { facet, files, dirs }]) => [
1235
+ folder,
1236
+ facetBarrelNamesOf(facet, [...files], [...dirs]).map((name) => `${folder}/${name}`)
1237
+ ]));
1238
+ }
1239
+ return this.#modulesAt(path).length ? undefined : this.#barrels.get(path);
1240
+ }
1024
1241
  declares(owner, name) {
1025
1242
  const declaring = declaringPatternOf(name, true);
1026
1243
  return this.#filesOf(owner, name, null).some((fileName) => declaring.test(this.#source.readText(fileName) ?? ""));
1027
1244
  }
1028
- filesIn(owner) {
1245
+ declaresAt(path, name) {
1246
+ const declaring = declaringPatternOf(name, true);
1247
+ return this.#modulesAt(path).some((fileName) => declaring.test(this.#source.readText(fileName) ?? ""));
1248
+ }
1249
+ #filesIn(owner) {
1029
1250
  if (!this.#ownerFiles) {
1030
1251
  this.#ownerFiles = new Map;
1031
1252
  for (const entry of this.#source.files) {
@@ -1075,6 +1296,196 @@ ${near ?? ""}`;
1075
1296
  }
1076
1297
  }
1077
1298
 
1299
+ // pkgs/@akanjs/language/adaptorResolver.ts
1300
+ var packageOf = (specifier) => specifier.split("/").slice(0, specifier.startsWith("@") ? 2 : 1).join("/");
1301
+ var packageKeyOf = ({ name, from }) => `${packageOf(from)}
1302
+ ${name}`;
1303
+ var exportedKeyOf = (item) => ("fact" in item) ? item.id : ("local" in item) ? `${item.local}
1304
+ ` : packageKeyOf(item);
1305
+ var isPackageExport = (item) => ("from" in item);
1306
+
1307
+ class AdaptorResolver {
1308
+ #source;
1309
+ #resolver;
1310
+ #sink;
1311
+ #adaptors = new Map;
1312
+ #plugs = new Map;
1313
+ #serviceFields = new Set;
1314
+ #exported = new Map;
1315
+ constructor(source, resolver, sink) {
1316
+ this.#source = source;
1317
+ this.#resolver = resolver;
1318
+ this.#sink = sink;
1319
+ }
1320
+ declare(facts) {
1321
+ const counts = new Map;
1322
+ for (const file of facts)
1323
+ for (const fact of file.adaptors) {
1324
+ const key = this.#sink.key("adaptor", file.owner, fact.name);
1325
+ counts.set(key, (counts.get(key) ?? 0) + 1);
1326
+ }
1327
+ const declared = facts.flatMap((file) => file.adaptors.map((fact) => {
1328
+ const key = this.#sink.key("adaptor", file.owner, fact.name);
1329
+ const id = (counts.get(key) ?? 0) > 1 ? this.#sink.key("adaptor", file.owner, `${this.#resolver.inOwner(file.fileName, file.owner)}#${fact.name}`) : key;
1330
+ const adaptor = { fact, owner: file.owner, fileName: file.fileName, id };
1331
+ this.#adaptors.set(fact.name, [...this.#adaptors.get(fact.name) ?? [], adaptor]);
1332
+ this.#nodeOf(adaptor);
1333
+ return { adaptor, file };
1334
+ }));
1335
+ for (const { adaptor, file } of declared)
1336
+ for (const plug of adaptor.fact.plugs)
1337
+ this.#sink.addEdge(adaptor.id, this.#idOf(plug.target, file), "plugs", plug.name, this.#sink.location(plug.span));
1338
+ for (const file of facts)
1339
+ for (const binding of file.adaptorBindings)
1340
+ this.#sink.addEdge(this.#idOf(binding.role, file), this.#idOf(binding.adaptor, file), "binds", file.owner, this.#sink.location(binding.span));
1341
+ }
1342
+ addService(refName, service, file) {
1343
+ for (const plug of service.plugs) {
1344
+ const key = `${refName}
1345
+ ${plug.name}`;
1346
+ this.#plugs.set(key, [
1347
+ ...this.#plugs.get(key) ?? [],
1348
+ { owner: file.owner, target: this.#idOf(plug.target, file) }
1349
+ ]);
1350
+ }
1351
+ for (const field of service.fields)
1352
+ this.#serviceFields.add(`${file.owner ?? ""}
1353
+ ${refName}
1354
+ ${field}`);
1355
+ }
1356
+ pluggedOf(owner, module, field) {
1357
+ const plugs = this.#plugs.get(`${module}
1358
+ ${field}`) ?? [];
1359
+ const own = plugs.filter((plug) => plug.owner === owner);
1360
+ if (!own.length && this.#serviceFields.has(`${owner ?? ""}
1361
+ ${module}
1362
+ ${field}`))
1363
+ return [];
1364
+ const inherited = own.length ? own : plugs.filter((plug) => this.#resolver.visible(plug.owner, owner));
1365
+ return [...new Set(inherited.map(({ target }) => target))];
1366
+ }
1367
+ #idOf(local, file) {
1368
+ const [head, member] = local.split(".");
1369
+ const imported = file.imports.find((item) => item.name === head);
1370
+ const name = member ?? (imported && imported.imported !== "default" && imported.imported !== "*" ? imported.imported : head);
1371
+ const path = imported ? this.#resolver.pathOfSpecifier(file.fileName, imported.from) : null;
1372
+ if (imported && path === null && !frameworkPattern.test(imported.from))
1373
+ return this.#packageAdaptorOf(name, imported.from);
1374
+ const from = imported ? this.#resolver.ownerOfSpecifier(file.fileName, imported.from) : undefined;
1375
+ const declared = this.#adaptors.get(name) ?? [];
1376
+ const holder = from === undefined ? file.owner : from;
1377
+ const own = this.#adaptorIn(name, declared, holder, path, file.fileName);
1378
+ if (own && "from" in own)
1379
+ return this.#packageAdaptorOf(own.name, own.from);
1380
+ const shims = own === undefined && from && from !== frameworkOwner && path ? this.#exportedAt(name, path).filter(isPackageExport) : [];
1381
+ const [shim] = shims;
1382
+ if (shim && shims.length === 1)
1383
+ return this.#packageAdaptorOf(shim.name, shim.from);
1384
+ const found = own === undefined && !shim && from !== frameworkOwner ? declared.find((adaptor) => this.#resolver.visible(adaptor.owner, holder)) : own;
1385
+ if (found)
1386
+ return found.id;
1387
+ const starred = own === undefined && !shim && from && from !== frameworkOwner ? this.#starredPackageOf(from, name, path) : null;
1388
+ if (starred)
1389
+ return this.#packageAdaptorOf(starred.name, starred.from);
1390
+ const owner = from === frameworkOwner ? null : imported ? from ?? null : file.owner;
1391
+ const detail = from === frameworkOwner ? [frameworkOwner] : [];
1392
+ return this.#sink.addNode(this.#sink.key("adaptor", owner, name), "adaptor", owner, name, null, detail).id;
1393
+ }
1394
+ #adaptorIn(name, declared, owner, path, fileName) {
1395
+ const own = declared.filter((adaptor) => adaptor.owner === owner);
1396
+ const [first] = own;
1397
+ if (path === null)
1398
+ return own.find((adaptor) => adaptor.fileName === fileName) ?? first;
1399
+ if (own.length === 1)
1400
+ return first;
1401
+ const exported = this.#exportedAt(name, path).filter((item) => first || !isPackageExport(item));
1402
+ const [only] = exported;
1403
+ if (only)
1404
+ return exported.length === 1 && !("local" in only) ? only : null;
1405
+ return first ? null : undefined;
1406
+ }
1407
+ #exportedAt(name, path) {
1408
+ const key = `${path}
1409
+ ${name}`;
1410
+ const cached = this.#exported.get(key);
1411
+ if (cached)
1412
+ return cached;
1413
+ if (!this.#resolver.mentionsAlong(path, name)) {
1414
+ this.#exported.set(key, []);
1415
+ return [];
1416
+ }
1417
+ const reached = new Map;
1418
+ const seen = new Set;
1419
+ const pending = [[name, path]];
1420
+ for (let next = pending.pop();next; next = pending.pop()) {
1421
+ const [wanted, at] = next;
1422
+ if (seen.has(`${at}
1423
+ ${wanted}`))
1424
+ continue;
1425
+ seen.add(`${at}
1426
+ ${wanted}`);
1427
+ for (const item of this.#bindingAt(wanted, at, pending, name))
1428
+ reached.set(exportedKeyOf(item), item);
1429
+ }
1430
+ const found = [...reached.values()];
1431
+ this.#exported.set(key, found);
1432
+ return found;
1433
+ }
1434
+ #bindingAt(name, path, pending, plugged) {
1435
+ const here = this.#declaredAt(name, path);
1436
+ if (here.length)
1437
+ return here;
1438
+ const { named, stars, isLocal } = this.#resolver.exportsAt(path, name);
1439
+ if (isLocal)
1440
+ return [{ local: path }];
1441
+ if (named?.from === null) {
1442
+ const local = this.#declaredAt(named.name, path);
1443
+ return local.length ? local : [{ local: path }];
1444
+ }
1445
+ if (named) {
1446
+ const target = this.#resolver.pathOfSpecifier(named.fileName, named.from);
1447
+ if (target === null) {
1448
+ const exposed = named.name !== "default" ? named.name : name !== "default" ? name : plugged;
1449
+ return [{ name: exposed, from: named.from }];
1450
+ }
1451
+ pending.push([named.name, target]);
1452
+ return [];
1453
+ }
1454
+ for (const star of stars)
1455
+ pending.push([name, star]);
1456
+ return [];
1457
+ }
1458
+ #declaredAt(name, path) {
1459
+ return (this.#adaptors.get(name) ?? []).filter((adaptor) => {
1460
+ const module = this.#source.relative(adaptor.fileName).replace(/\.tsx?$/, "");
1461
+ return module === path || module === `${path}/index`;
1462
+ });
1463
+ }
1464
+ #packageAdaptorOf(name, specifier) {
1465
+ if (frameworkPattern.test(specifier))
1466
+ return this.#sink.addNode(this.#sink.key("adaptor", null, name), "adaptor", null, name, null, [frameworkOwner]).id;
1467
+ const pkg = packageOf(specifier);
1468
+ return this.#sink.addNode(this.#sink.key("adaptor", pkg, name), "adaptor", null, name, null, [pkg]).id;
1469
+ }
1470
+ #starredPackageOf(owner, name, near) {
1471
+ if (!near)
1472
+ return null;
1473
+ const { packages, paths } = this.#resolver.starExportsOf(owner, near);
1474
+ const [only] = packages;
1475
+ if (!only || new Set(packages.map(packageOf)).size !== 1)
1476
+ return null;
1477
+ return paths.some((path) => this.#resolver.declaresAt(path, name)) ? null : { name, from: only };
1478
+ }
1479
+ #nodeOf({ fact, owner, fileName, id }) {
1480
+ const detail = fact.refName ? [fact.refName] : [];
1481
+ const node = this.#sink.addNode(id, "adaptor", owner, fact.name, fact.span, detail);
1482
+ if (fact.doc && !node.doc)
1483
+ node.doc = fact.doc;
1484
+ this.#sink.digest(node, this.#source.readText(fileName), fact.extent);
1485
+ return node.id;
1486
+ }
1487
+ }
1488
+
1078
1489
  // pkgs/akanjs/common/trimSlashes.ts
1079
1490
  var trimTrailingSlashes = (value) => {
1080
1491
  let end = value.length;
@@ -1098,6 +1509,7 @@ var PAGE_ROUTE_EXPORTS = new Set([
1098
1509
  "guard"
1099
1510
  ]);
1100
1511
  var LAYOUT_ROUTE_EXPORTS = new Set([...PAGE_ROUTE_EXPORTS, "NotFound", "Error"]);
1512
+ var GENERATED_ROOT_LAYOUT_EXPORTS = new Set(["McpAppRoot", "LevelBoundary"]);
1101
1513
  var ROOT_LAYOUT_ROUTE_EXPORTS = new Set([
1102
1514
  ...LAYOUT_ROUTE_EXPORTS,
1103
1515
  "fonts",
@@ -1107,7 +1519,7 @@ var ROOT_LAYOUT_ROUTE_EXPORTS = new Set([
1107
1519
  "wsConnect",
1108
1520
  "layoutStyle",
1109
1521
  "viewport",
1110
- "McpAppRoot"
1522
+ ...GENERATED_ROOT_LAYOUT_EXPORTS
1111
1523
  ]);
1112
1524
  var RESERVED_ROUTE_CONFIG_EXPORTS = new Set([...ROOT_LAYOUT_ROUTE_EXPORTS].filter((name) => name !== "default" && !/^[A-Z]/.test(name)));
1113
1525
  function parseRouteModuleKey(key) {
@@ -1363,13 +1775,18 @@ class GraphBuilder {
1363
1775
  #routeFiles = new Map;
1364
1776
  #routes;
1365
1777
  #resolver;
1366
- #adaptors = new Map;
1367
- #plugs = new Map;
1368
- #serviceFields = new Set;
1778
+ #adaptors;
1369
1779
  constructor(source) {
1370
1780
  this.#source = source;
1371
1781
  this.#routes = new RouteFactReader(source.ts, source.reader, source.parse);
1372
1782
  this.#resolver = new GuardResolver(source, this.#routes);
1783
+ this.#adaptors = new AdaptorResolver(source, this.#resolver, {
1784
+ key: (kind, owner, scope) => this.#key(kind, owner, scope),
1785
+ addNode: (id, kind, owner, name, span, detail) => this.#addNode(id, kind, owner, null, name, span, detail),
1786
+ addEdge: (from, to, kind, label, at) => this.#addEdge(from, to, kind, label, at),
1787
+ digest: (node, text, extent) => this.#digest(node, text, extent),
1788
+ location: (span) => this.#location(span)
1789
+ });
1373
1790
  }
1374
1791
  build() {
1375
1792
  const { facts } = this.#source;
@@ -1381,26 +1798,7 @@ class GraphBuilder {
1381
1798
  ...[...constantsByOwner].filter(([key]) => key !== owner && key?.startsWith("libs/")).flatMap(([, list]) => list)
1382
1799
  ];
1383
1800
  const typed = [];
1384
- const adaptorCounts = new Map;
1385
- for (const file of facts)
1386
- for (const fact of file.adaptors) {
1387
- const key = this.#key("adaptor", file.owner, fact.name);
1388
- adaptorCounts.set(key, (adaptorCounts.get(key) ?? 0) + 1);
1389
- }
1390
- const declaredAdaptors = facts.flatMap((file) => file.adaptors.map((fact) => {
1391
- const key = this.#key("adaptor", file.owner, fact.name);
1392
- const id = (adaptorCounts.get(key) ?? 0) > 1 ? this.#key("adaptor", file.owner, `${this.#resolver.inOwner(file.fileName, file.owner)}#${fact.name}`) : key;
1393
- const declared = { fact, owner: file.owner, fileName: file.fileName, id };
1394
- this.#adaptors.set(fact.name, [...this.#adaptors.get(fact.name) ?? [], declared]);
1395
- this.#adaptorNodeOf(declared);
1396
- return { declared, file };
1397
- }));
1398
- for (const { declared, file } of declaredAdaptors)
1399
- for (const plug of declared.fact.plugs)
1400
- this.#addEdge(declared.id, this.#adaptorIdOf(plug.target, file), "plugs", plug.name, this.#location(plug.span));
1401
- for (const file of facts)
1402
- for (const binding of file.adaptorBindings)
1403
- this.#addEdge(this.#adaptorIdOf(binding.role, file), this.#adaptorIdOf(binding.adaptor, file), "binds", file.owner, this.#location(binding.span));
1801
+ this.#adaptors.declare(facts);
1404
1802
  for (const guard of this.#resolver.declare(facts))
1405
1803
  this.#guardNodeOf(guard);
1406
1804
  for (const file of facts) {
@@ -1433,18 +1831,7 @@ class GraphBuilder {
1433
1831
  }
1434
1832
  for (const method of service.methods)
1435
1833
  this.#addMember("method", owner, refName, method, `${service.name}.${method.name}`, file.fileName);
1436
- for (const plug of service.plugs) {
1437
- const key = `${refName}
1438
- ${plug.name}`;
1439
- this.#plugs.set(key, [
1440
- ...this.#plugs.get(key) ?? [],
1441
- { owner, target: this.#adaptorIdOf(plug.target, file) }
1442
- ]);
1443
- }
1444
- for (const field of service.fields)
1445
- this.#serviceFields.add(`${owner ?? ""}
1446
- ${refName}
1447
- ${field}`);
1834
+ this.#adaptors.addService(refName, service, file);
1448
1835
  }
1449
1836
  for (const filter of file.filters) {
1450
1837
  if (!filter.name.endsWith("Filter"))
@@ -1700,80 +2087,6 @@ ${dir}`, node);
1700
2087
  this.#digest(node, text, extent);
1701
2088
  return node.id;
1702
2089
  }
1703
- #adaptorIdOf(local, file) {
1704
- const [head, member] = local.split(".");
1705
- const imported = file.imports.find((item) => item.name === head);
1706
- const name = member ?? (imported && imported.imported !== "default" && imported.imported !== "*" ? imported.imported : head);
1707
- const path = imported ? this.#resolver.pathOfSpecifier(file.fileName, imported.from) : null;
1708
- if (imported && path === null && !frameworkPattern.test(imported.from))
1709
- return this.#packageAdaptorOf(name, imported.from);
1710
- const from = imported ? this.#resolver.ownerOfSpecifier(file.fileName, imported.from) : undefined;
1711
- const declared = this.#adaptors.get(name) ?? [];
1712
- 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)));
1713
- if (found)
1714
- return found.id;
1715
- const reexported = from && from !== frameworkOwner ? this.#packageShimOf(from, name, path) : null;
1716
- if (reexported)
1717
- return this.#packageAdaptorOf(reexported.name, reexported.from);
1718
- const owner = from === frameworkOwner ? null : imported ? from ?? null : file.owner;
1719
- const detail = from === frameworkOwner ? [frameworkOwner] : [];
1720
- return this.#addNode(this.#key("adaptor", owner, name), "adaptor", owner, null, name, null, detail).id;
1721
- }
1722
- #adaptorIn(declared, owner, path, fileName) {
1723
- const own = declared.filter((adaptor) => adaptor.owner === owner);
1724
- if (own.length < 2)
1725
- return own.at(0);
1726
- const pathOf = (adaptor) => this.#source.relative(adaptor.fileName).replace(/\.tsx?$/, "");
1727
- 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}/`));
1728
- return named ?? own.at(0);
1729
- }
1730
- #pluggedOf({ owner, module }, field) {
1731
- const plugs = this.#plugs.get(`${module}
1732
- ${field}`) ?? [];
1733
- const own = plugs.filter((plug) => plug.owner === owner);
1734
- if (!own.length && this.#serviceFields.has(`${owner ?? ""}
1735
- ${module}
1736
- ${field}`))
1737
- return [];
1738
- const inherited = own.length ? own : plugs.filter((plug) => this.#resolver.visible(plug.owner, owner));
1739
- return [...new Set(inherited.map(({ target }) => target))];
1740
- }
1741
- #packageAdaptorOf(name, specifier) {
1742
- if (frameworkPattern.test(specifier))
1743
- return this.#addNode(this.#key("adaptor", null, name), "adaptor", null, null, name, null, [frameworkOwner]).id;
1744
- const pkg = specifier.split("/").slice(0, specifier.startsWith("@") ? 2 : 1).join("/");
1745
- return this.#addNode(this.#key("adaptor", pkg, name), "adaptor", null, null, name, null, [pkg]).id;
1746
- }
1747
- #packageShimOf(owner, name, near) {
1748
- const reexport = this.#resolver.reexportOf(owner, name, near);
1749
- const [shim] = reexport?.site.imports ?? [];
1750
- if (reexport && shim && this.#resolver.pathOfSpecifier(reexport.site.fileName, shim.from) === null)
1751
- return { name: reexport.local === "default" ? name : reexport.local, from: shim.from };
1752
- if (reexport || !near)
1753
- return null;
1754
- const packages = new Set;
1755
- for (const [fileName, words] of this.#resolver.filesIn(owner)) {
1756
- const relative = this.#source.relative(fileName);
1757
- const isNear = relative.startsWith(`${near}/`) || relative.replace(/\.tsx?$/, "") === near;
1758
- if (!isNear || !words.includes(`
1759
- export
1760
- `))
1761
- continue;
1762
- for (const [, specifier = ""] of this.#source.readText(fileName)?.matchAll(starExportPattern) ?? [])
1763
- if (this.#resolver.pathOfSpecifier(fileName, specifier) === null)
1764
- packages.add(specifier);
1765
- }
1766
- const [only] = packages;
1767
- return packages.size === 1 && only && !this.#resolver.declares(owner, name) ? { name, from: only } : null;
1768
- }
1769
- #adaptorNodeOf({ fact, owner, fileName, id }) {
1770
- const detail = fact.refName ? [fact.refName] : [];
1771
- const node = this.#addNode(id, "adaptor", owner, null, fact.name, fact.span, detail);
1772
- if (fact.doc && !node.doc)
1773
- node.doc = fact.doc;
1774
- this.#digest(node, this.#source.readText(fileName), fact.extent);
1775
- return node.id;
1776
- }
1777
2090
  #guardNodeOf({ name, owner, span, scope, doc, parts, file, label }) {
1778
2091
  const id = this.#key("guard", owner, file ? `${file}#${name}` : name);
1779
2092
  const node = this.#addNode(id, "guard", owner, null, name, span, scope ? [scope] : [], label ?? name);
@@ -1876,7 +2189,7 @@ st
1876
2189
  visit(source);
1877
2190
  }
1878
2191
  #link(fileName, source, identifier, chain, context, owner) {
1879
- const plugged = chain?.length === 2 && chain[0] === "this" && context.kind === "method" && this.#isServiceThis(identifier) ? this.#pluggedOf(context, chain[1]) : [];
2192
+ const plugged = chain?.length === 2 && chain[0] === "this" && context.kind === "method" && this.#isServiceThis(identifier) ? this.#adaptors.pluggedOf(context.owner, context.module, chain[1]) : [];
1880
2193
  const resolved = plugged.length ? plugged : this.#source.resolve(fileName, identifier).map((target) => this.#targetNodeOf(target)).filter((id) => id !== null);
1881
2194
  const targets = resolved.length ? resolved : this.#plainTargetsOf(chain, identifier.text, context, owner);
1882
2195
  if (!targets.length)
@@ -2475,7 +2788,7 @@ var sourcePattern = /\.(constant|document|service|signal|store)\.ts$/;
2475
2788
  var dictionaryPattern = /\.dictionary\.ts$/;
2476
2789
  var srvkitPattern = /\/srvkit\//;
2477
2790
  var wordPattern = /[A-Za-z_$][\w$]*/g;
2478
- var identifierPattern = /^[A-Za-z_$][\w$]*$/;
2791
+ var identifierPattern2 = /^[A-Za-z_$][\w$]*$/;
2479
2792
  var stateReceivers = new Set(["use", "sel", "get", "do"]);
2480
2793
  var lensFamilies = new Set(["slice", "query", "formSetter", "storeState", "endpoint"]);
2481
2794
  var modellessFamilies = new Set(["query", "storeState", "endpoint"]);
@@ -2584,7 +2897,7 @@ ${[...new Set(text.match(wordPattern))].join(`
2584
2897
  }
2585
2898
  renameAt(givenName, offset, newKey, readText) {
2586
2899
  const sources = this.#sourceEntriesAt(pathOf(givenName), offset).filter((entry) => entry.renamed);
2587
- if (!sources.length || !identifierPattern.test(newKey))
2900
+ if (!sources.length || !identifierPattern2.test(newKey))
2588
2901
  return null;
2589
2902
  return [
2590
2903
  { span: sources[0].span, newText: newKey },