@akanjs/language 3.2.0-rc.9 → 3.3.0-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/index.js CHANGED
@@ -109,6 +109,42 @@ ${at.file}` : null;
109
109
  return node.fields ? { ...node, fields: node.fields.map(({ digest: _field, ...field }) => field) } : node;
110
110
  }
111
111
  }
112
+ // pkgs/akanjs/common/facetBarrel.ts
113
+ var barrelFacetDirs = ["ui", "webkit", "srvkit", "common", "plugin"];
114
+ var sourceFilePattern = /\.(ts|tsx)$/;
115
+ var excludedFilePattern = /(^index\.tsx?$|\.d\.ts$|\.(test|spec)\.(ts|tsx)$|\.css$|\.scss$|\.sass$)/;
116
+ var pascalCasePattern = /^[A-Z][A-Za-z0-9]*$/;
117
+ var camelCasePattern = /^[a-z][A-Za-z0-9]*$/;
118
+ var letterRankOf = (char) => char.toLowerCase().charCodeAt(0) * 2 + (char === char.toLowerCase() ? 1 : 0);
119
+ var digitRunAt = (name, idx) => /^\d+/.exec(name.slice(idx))?.[0] ?? "";
120
+ var compareExportNames = (a, b) => {
121
+ for (let idx = 0;idx < a.length && idx < b.length; ) {
122
+ const [runA, runB] = [digitRunAt(a, idx), digitRunAt(b, idx)];
123
+ if (runA && runB && runA !== runB)
124
+ return runA.length - runB.length || (runA < runB ? -1 : 1);
125
+ if (runA && runB)
126
+ idx += runA.length;
127
+ else if (runA || runB)
128
+ return runA ? -1 : 1;
129
+ else if (a.charAt(idx) !== b.charAt(idx))
130
+ return letterRankOf(a.charAt(idx)) - letterRankOf(b.charAt(idx));
131
+ else
132
+ idx++;
133
+ }
134
+ return a.length - b.length;
135
+ };
136
+ var facetBarrelNamesOf = (facet, files, dirs) => {
137
+ const nameCasePattern = facet === "ui" ? pascalCasePattern : camelCasePattern;
138
+ return [
139
+ ...files.filter((file) => sourceFilePattern.test(file) && !excludedFilePattern.test(file)).map((file) => file.replace(sourceFilePattern, "")),
140
+ ...dirs.filter((dir) => !dir.startsWith("."))
141
+ ].filter((name) => nameCasePattern.test(name)).sort(compareExportNames);
142
+ };
143
+
144
+ // pkgs/@akanjs/language/escapeRegExp.ts
145
+ var regExpSpecials = /[\\^$.*+?()[\]{}|]/g;
146
+ var escapeRegExp = (text) => text.replace(regExpSpecials, (special) => `\\${special}`);
147
+
112
148
  // pkgs/@akanjs/language/guardFacts.ts
113
149
  var guardLabelOf = (guard, labels) => {
114
150
  const [, role = null, local = guard] = guard.match(/^([\w$]+) (.+)$/) ?? [];
@@ -116,6 +152,7 @@ var guardLabelOf = (guard, labels) => {
116
152
  return label === undefined ? guard : role ? `${role} ${label}` : label;
117
153
  };
118
154
  var maxLabelArgs = 32;
155
+ var maxLayers = 4;
119
156
  var guardRefReaderOf = (ts, ast, unwrap) => {
120
157
  const pathOf = (expression) => {
121
158
  if (ts.isIdentifier(expression))
@@ -125,10 +162,19 @@ var guardRefReaderOf = (ts, ast, unwrap) => {
125
162
  const head = pathOf(expression.expression);
126
163
  return head && `${head}.${expression.name.text}`;
127
164
  };
128
- const calleeOf = (call) => pathOf(unwrap(call.expression)) ?? "?";
165
+ const layersOf = (call) => {
166
+ const inner = unwrap(call.expression);
167
+ if (!ts.isCallExpression(inner))
168
+ return { root: call, layers: 0 };
169
+ const { root, layers } = layersOf(inner);
170
+ return { root, layers: layers + 1 };
171
+ };
172
+ const calleeOf = (call) => pathOf(unwrap(layersOf(call).root.expression)) ?? "?";
129
173
  const labelOf = (source, call) => {
130
174
  const args = call.arguments.map((arg) => arg.getText(source)).join(", ");
131
- return `${calleeOf(call)}(${args.length <= maxLabelArgs && !args.includes(`
175
+ const inner = unwrap(call.expression);
176
+ const head = ts.isCallExpression(inner) ? labelOf(source, inner) : pathOf(inner) ?? "?";
177
+ return `${head}(${args.length <= maxLabelArgs && !args.includes(`
132
178
  `) ? args : "…"})`;
133
179
  };
134
180
  const guardRefOf = (expression, made, member) => {
@@ -156,9 +202,9 @@ var guardRefReaderOf = (ts, ast, unwrap) => {
156
202
  const single = refOf(guards);
157
203
  return single ? [single] : [];
158
204
  };
159
- return { pathOf, labelOf, guardsIn };
205
+ return { pathOf, layersOf, labelOf, guardsIn };
160
206
  };
161
- var guardFactoryReaderOf = (ts, ast, { spanOf, extentOf, unwrap, docOf }, pathOf) => {
207
+ var guardFactoryReaderOf = (ts, ast, { spanOf, extentOf, unwrap, docOf }, pathOf, layersOf) => {
162
208
  const implementsGuard = (node, guardNames) => !!node.heritageClauses?.some((clause) => clause.token === ts.SyntaxKind.ImplementsKeyword && clause.types.some(({ expression }) => guardNames.has(ast.expressionName(expression) ?? "")));
163
209
  const scopeOf = (node) => {
164
210
  const scope = node.members.find((member) => ts.isPropertyDeclaration(member) && ast.nodeName(member.name) === "scope" && !!ts.getModifiers(member)?.some(({ kind }) => kind === ts.SyntaxKind.StaticKeyword))?.initializer;
@@ -180,7 +226,7 @@ var guardFactoryReaderOf = (ts, ast, { spanOf, extentOf, unwrap, docOf }, pathOf
180
226
  }
181
227
  return functions;
182
228
  };
183
- const returnedOf = (body, guardNames) => {
229
+ const returnedOf = (body, guardNames, depth = 0) => {
184
230
  const locals = new Map;
185
231
  const pending = [];
186
232
  const visit = (node) => {
@@ -201,6 +247,7 @@ var guardFactoryReaderOf = (ts, ast, { spanOf, extentOf, unwrap, docOf }, pathOf
201
247
  const calls = [];
202
248
  const seen = new Set;
203
249
  const passed = new Set;
250
+ const returned = [];
204
251
  for (let node = pending.pop();node; node = pending.pop()) {
205
252
  if (seen.has(node))
206
253
  continue;
@@ -208,6 +255,8 @@ var guardFactoryReaderOf = (ts, ast, { spanOf, extentOf, unwrap, docOf }, pathOf
208
255
  const value = ts.isExpression(node) ? unwrap(node) : node;
209
256
  if ((ts.isClassExpression(value) || ts.isClassDeclaration(value)) && implementsGuard(value, guardNames))
210
257
  guard ??= value;
258
+ else if ((ts.isArrowFunction(value) || ts.isFunctionExpression(value)) && !passed.has(node) && depth < maxLayers)
259
+ returned.push(value.body);
211
260
  else if (ts.isConditionalExpression(value))
212
261
  pending.push(value.whenTrue, value.whenFalse);
213
262
  else if (ts.isBinaryExpression(value))
@@ -217,15 +266,22 @@ var guardFactoryReaderOf = (ts, ast, { spanOf, extentOf, unwrap, docOf }, pathOf
217
266
  if (local)
218
267
  pending.push(local);
219
268
  } else if (ts.isCallExpression(value)) {
220
- const callee = pathOf(unwrap(value.expression));
221
- if (callee && !passed.has(node) && !calls.includes(callee))
222
- calls.push(callee);
223
- for (const arg of value.arguments)
224
- passed.add(arg);
225
- pending.push(...value.arguments);
269
+ const { root, layers } = layersOf(value);
270
+ const callee = pathOf(unwrap(root.expression));
271
+ if (callee && !passed.has(node) && !calls.some((call) => call.callee === callee))
272
+ calls.push({ callee, layers });
273
+ for (let call = value;ts.isCallExpression(call); call = unwrap(call.expression)) {
274
+ for (const arg of call.arguments)
275
+ passed.add(arg);
276
+ pending.push(...call.arguments);
277
+ }
226
278
  }
227
279
  }
228
- return { guard, calls };
280
+ const [inner] = returned;
281
+ if (guard || calls.length || !inner)
282
+ return { guard, calls, layers: 0 };
283
+ const nested = returnedOf(inner, guardNames, depth + 1);
284
+ return { ...nested, layers: nested.layers + 1 };
229
285
  };
230
286
  const guardFactoriesOf = (source, guardNames, isImported) => {
231
287
  const functions = functionsOf(source);
@@ -235,7 +291,7 @@ var guardFactoryReaderOf = (ts, ast, { spanOf, extentOf, unwrap, docOf }, pathOf
235
291
  for (let isGrowing = true;isGrowing; ) {
236
292
  isGrowing = false;
237
293
  for (const [name, { guard, calls }] of returned) {
238
- if (members.has(name) || !guard && !calls.some(isFactoryCall))
294
+ if (members.has(name) || !guard && !calls.some(({ callee }) => isFactoryCall(callee)))
239
295
  continue;
240
296
  members.add(name);
241
297
  isGrowing = true;
@@ -254,7 +310,8 @@ var guardFactoryReaderOf = (ts, ast, { spanOf, extentOf, unwrap, docOf }, pathOf
254
310
  scope: made.guard ? scopeOf(made.guard) : null,
255
311
  doc: docOf(source, found.statement),
256
312
  direct: !!made.guard,
257
- via: made.calls.filter(isFactoryCall)
313
+ via: made.calls.filter(({ callee }) => isFactoryCall(callee)),
314
+ layers: made.layers
258
315
  });
259
316
  }
260
317
  return factories;
@@ -263,8 +320,8 @@ var guardFactoryReaderOf = (ts, ast, { spanOf, extentOf, unwrap, docOf }, pathOf
263
320
  };
264
321
  var createGuardFactReader = (ts, ast, base) => {
265
322
  const { spanOf, extentOf, unwrap, docOf } = base;
266
- const { pathOf, labelOf, guardsIn } = guardRefReaderOf(ts, ast, unwrap);
267
- const { implementsGuard, scopeOf, guardFactoriesOf } = guardFactoryReaderOf(ts, ast, base, pathOf);
323
+ const { pathOf, layersOf, labelOf, guardsIn } = guardRefReaderOf(ts, ast, unwrap);
324
+ const { implementsGuard, scopeOf, guardFactoriesOf } = guardFactoryReaderOf(ts, ast, base, pathOf, layersOf);
268
325
  const guardsOf = (source, imports, madeInPlace) => {
269
326
  const guardNames = new Set([
270
327
  "Guard",
@@ -277,15 +334,16 @@ var createGuardFactReader = (ts, ast, base) => {
277
334
  const calls = [];
278
335
  const makeOf = (made, value, isInPlace = false) => {
279
336
  if (ts.isClassExpression(value) && implementsGuard(value, guardNames)) {
280
- guards.push({ ...made, scope: scopeOf(value), factory: null });
337
+ guards.push({ ...made, scope: scopeOf(value), factory: null, layers: 0 });
281
338
  return;
282
339
  }
283
- const callee = ts.isCallExpression(value) ? pathOf(unwrap(value.expression)) : null;
340
+ const { root, layers } = ts.isCallExpression(value) ? layersOf(value) : { root: null, layers: 0 };
341
+ const callee = root && pathOf(unwrap(root.expression));
284
342
  const factory = callee && factories.get(callee);
285
343
  if (factory)
286
- guards.push({ ...made, scope: factory.scope, factory: factory.name });
344
+ guards.push({ ...made, scope: factory.scope, factory: factory.name, layers });
287
345
  else if (callee && (isImported(callee) || isInPlace))
288
- calls.push({ ...made, callee, kind: "call", scope: null });
346
+ calls.push({ ...made, callee, kind: "call", scope: null, layers });
289
347
  };
290
348
  for (const statement of source.statements) {
291
349
  if (ts.isClassDeclaration(statement) && statement.name) {
@@ -299,9 +357,9 @@ var createGuardFactReader = (ts, ast, base) => {
299
357
  const base = statement.heritageClauses?.find(({ token }) => token === ts.SyntaxKind.ExtendsKeyword)?.types[0];
300
358
  const callee = base && pathOf(base.expression);
301
359
  if (implementsGuard(statement, guardNames))
302
- guards.push({ ...declared, factory: null });
360
+ guards.push({ ...declared, factory: null, layers: 0 });
303
361
  else if (callee)
304
- calls.push({ ...declared, callee, kind: "extends" });
362
+ calls.push({ ...declared, callee, kind: "extends", layers: 0 });
305
363
  }
306
364
  if (!ts.isVariableStatement(statement))
307
365
  continue;
@@ -338,10 +396,6 @@ var createGuardFactReader = (ts, ast, base) => {
338
396
  return { guardsIn, guardsOf };
339
397
  };
340
398
 
341
- // pkgs/@akanjs/language/escapeRegExp.ts
342
- var regExpSpecials = /[\\^$.*+?()[\]{}|]/g;
343
- var escapeRegExp = (text) => text.replace(regExpSpecials, (special) => `\\${special}`);
344
-
345
399
  // pkgs/@akanjs/language/moduleFacts.ts
346
400
  var testFilePattern = /\.(?:test|spec)\.tsx?$/;
347
401
  var moduleCallees = new Set([
@@ -368,7 +422,7 @@ var ownerOf = (relativePath) => {
368
422
  const [root, name] = relativePath.split("/");
369
423
  return (root === "apps" || root === "libs") && name ? `${root}/${name}` : null;
370
424
  };
371
- var createFactReader = (ts, ast) => {
425
+ var syntaxReaderOf = (ts, ast) => {
372
426
  const spanOf = (source, node) => {
373
427
  const start = node.getStart(source);
374
428
  const end = node.getEnd();
@@ -426,6 +480,74 @@ var createFactReader = (ts, ast) => {
426
480
  const node = keyName(property);
427
481
  return name && node ? [{ name, span: spanOf(source, node), extent: extentOf(source, property) }] : [];
428
482
  });
483
+ const verbReaderOf = (parameter) => {
484
+ const verbs = new Map;
485
+ if (parameter && ts.isObjectBindingPattern(parameter.name))
486
+ for (const element of parameter.name.elements) {
487
+ const verb = element.propertyName ?? element.name;
488
+ if (ts.isIdentifier(verb) && ts.isIdentifier(element.name))
489
+ verbs.set(element.name.text, verb.text);
490
+ }
491
+ const holder = parameter && ts.isIdentifier(parameter.name) ? parameter.name.text : null;
492
+ return (callee) => {
493
+ if (callee && ts.isIdentifier(callee))
494
+ return verbs.get(callee.text) ?? null;
495
+ if (callee && ts.isPropertyAccessExpression(callee) && ts.isIdentifier(callee.expression) && callee.expression.text === holder)
496
+ return callee.name.text;
497
+ return null;
498
+ };
499
+ };
500
+ return {
501
+ spanOf,
502
+ extentOf,
503
+ unwrap,
504
+ moduleRefOf,
505
+ returnedObject,
506
+ builderOf,
507
+ guardNameOf,
508
+ optionObjectOf,
509
+ chainOf,
510
+ keyName,
511
+ objectKeys,
512
+ verbReaderOf
513
+ };
514
+ };
515
+ var sourceReaderOf = (ts) => {
516
+ const importsOf = (statement) => {
517
+ const { importClause, moduleSpecifier } = statement;
518
+ if (!importClause || !ts.isStringLiteral(moduleSpecifier))
519
+ return [];
520
+ const from = moduleSpecifier.text;
521
+ const bindings = importClause.namedBindings;
522
+ return [
523
+ ...importClause.name ? [{ name: importClause.name.text, imported: "default", from }] : [],
524
+ ...bindings && ts.isNamespaceImport(bindings) ? [{ name: bindings.name.text, imported: "*", from }] : [],
525
+ ...bindings && ts.isNamedImports(bindings) ? bindings.elements.map((element) => ({
526
+ name: element.name.text,
527
+ imported: (element.propertyName ?? element.name).text,
528
+ from
529
+ })) : []
530
+ ];
531
+ };
532
+ const docOf = (source, node) => {
533
+ const { text } = source;
534
+ const ranges = ts.getLeadingCommentRanges(text, node.getFullStart()) ?? [];
535
+ const comments = [];
536
+ let end = node.getStart(source);
537
+ for (const range of [...ranges].reverse()) {
538
+ if ((text.slice(range.end, end).match(/\n/g)?.length ?? 0) > 1)
539
+ break;
540
+ comments.unshift(text.slice(range.pos, range.end));
541
+ end = range.pos;
542
+ }
543
+ const lines = comments.flatMap((comment) => comment.split(`
544
+ `)).map((line) => line.trim().replace(/^\/\*\*?|\*\/$/g, "").replace(/^(?:\/\/[?*!]?|\*)/, "").replace(/\{@link\s+([^}\s|]+)[^}]*\}/g, "$1").trim()).filter((line) => line && !/^(?:biome-ignore|eslint-|@ts-)/.test(line));
545
+ return lines.length ? lines.join(" ") : null;
546
+ };
547
+ const importsIn = (source) => source.statements.filter(ts.isImportDeclaration).flatMap(importsOf);
548
+ return { docOf, importsIn };
549
+ };
550
+ var signalKeyReaderOf = (ts, ast, { spanOf, extentOf, returnedObject, optionObjectOf, chainOf, verbReaderOf }, guardsIn) => {
429
551
  const sliceKeysOf = (source, builder, made, model) => (returnedObject(builder)?.properties ?? []).flatMap((property) => {
430
552
  if (!ts.isPropertyAssignment(property))
431
553
  return [];
@@ -444,23 +566,30 @@ var createFactReader = (ts, ast) => {
444
566
  }
445
567
  ];
446
568
  });
447
- const verbReaderOf = (parameter) => {
448
- const verbs = new Map;
449
- if (parameter && ts.isObjectBindingPattern(parameter.name))
450
- for (const element of parameter.name.elements) {
451
- const verb = element.propertyName ?? element.name;
452
- if (ts.isIdentifier(verb) && ts.isIdentifier(element.name))
453
- verbs.set(element.name.text, verb.text);
454
- }
455
- const holder = parameter && ts.isIdentifier(parameter.name) ? parameter.name.text : null;
456
- return (callee) => {
457
- if (callee && ts.isIdentifier(callee))
458
- return verbs.get(callee.text) ?? null;
459
- if (callee && ts.isPropertyAccessExpression(callee) && ts.isIdentifier(callee.expression) && callee.expression.text === holder)
460
- return callee.name.text;
461
- return null;
462
- };
569
+ const endpointKeysOf = (source, builder, made, model) => {
570
+ const verbOf = verbReaderOf(builder?.parameters[0]);
571
+ return (returnedObject(builder)?.properties ?? []).flatMap((property) => {
572
+ if (!ts.isPropertyAssignment(property))
573
+ return [];
574
+ const name = ast.nodeName(property.name);
575
+ if (!name)
576
+ return [];
577
+ const { root, methods } = chainOf(property.initializer);
578
+ return [
579
+ {
580
+ name,
581
+ span: spanOf(source, property.name),
582
+ extent: extentOf(source, property),
583
+ verb: root ? verbOf(root.expression) : null,
584
+ guards: root ? guardsIn(source, optionObjectOf(root), made, `${model}.${name}`) : [],
585
+ argCount: methods.filter((method) => argMethods.has(method)).length
586
+ }
587
+ ];
588
+ });
463
589
  };
590
+ return { sliceKeysOf, endpointKeysOf };
591
+ };
592
+ var jobKeyReaderOf = (ts, ast, { spanOf, extentOf, unwrap, returnedObject, chainOf, verbReaderOf }) => {
464
593
  const numberOf = (expression) => {
465
594
  const value = unwrap(expression);
466
595
  if (ts.isNumericLiteral(value))
@@ -533,6 +662,9 @@ var createFactReader = (ts, ast) => {
533
662
  ];
534
663
  });
535
664
  };
665
+ return { internalKeysOf };
666
+ };
667
+ var serviceReaderOf = (ts, ast, { spanOf, extentOf, returnedObject, guardNameOf, chainOf, verbReaderOf }) => {
536
668
  const plugsOf = (source, builder) => {
537
669
  const verbOf = verbReaderOf(builder?.parameters[0]);
538
670
  return (returnedObject(builder)?.properties ?? []).flatMap((property) => {
@@ -558,27 +690,17 @@ var createFactReader = (ts, ast) => {
558
690
  visit(source);
559
691
  return bindings;
560
692
  };
561
- const endpointKeysOf = (source, builder, made, model) => {
562
- const verbOf = verbReaderOf(builder?.parameters[0]);
563
- return (returnedObject(builder)?.properties ?? []).flatMap((property) => {
564
- if (!ts.isPropertyAssignment(property))
565
- return [];
566
- const name = ast.nodeName(property.name);
567
- if (!name)
568
- return [];
569
- const { root, methods } = chainOf(property.initializer);
570
- return [
571
- {
572
- name,
573
- span: spanOf(source, property.name),
574
- extent: extentOf(source, property),
575
- verb: root ? verbOf(root.expression) : null,
576
- guards: root ? guardsIn(source, optionObjectOf(root), made, `${model}.${name}`) : [],
577
- argCount: methods.filter((method) => argMethods.has(method)).length
578
- }
579
- ];
580
- });
581
- };
693
+ const methodsOf = (source, statement) => statement.members.flatMap((member) => {
694
+ if (!ts.isMethodDeclaration(member) || !member.body)
695
+ return [];
696
+ const name = ast.nodeName(member.name);
697
+ if (!name || ts.getModifiers(member)?.some(({ kind }) => kind === ts.SyntaxKind.StaticKeyword))
698
+ return [];
699
+ return [{ name, span: spanOf(source, member.name), extent: extentOf(source, member) }];
700
+ });
701
+ return { plugsOf, adaptorBindingsIn, methodsOf };
702
+ };
703
+ var constantReaderOf = (ts, ast, { spanOf, extentOf, unwrap, returnedObject, chainOf, keyName, objectKeys }) => {
582
704
  const filterQueriesOf = (source, builder) => {
583
705
  const query = returnedObject(builder)?.properties.find((property) => ts.isPropertyAssignment(property) && ast.nodeName(property.name) === "query")?.initializer;
584
706
  return query && ts.isObjectLiteralExpression(query) ? objectKeys(source, query) : [];
@@ -616,48 +738,18 @@ var createFactReader = (ts, ast) => {
616
738
  return [];
617
739
  return list.elements.flatMap((element) => ts.isStringLiteralLike(element) ? [element.text] : []);
618
740
  };
619
- const methodsOf = (source, statement) => statement.members.flatMap((member) => {
620
- if (!ts.isMethodDeclaration(member) || !member.body)
621
- return [];
622
- const name = ast.nodeName(member.name);
623
- if (!name || ts.getModifiers(member)?.some(({ kind }) => kind === ts.SyntaxKind.StaticKeyword))
624
- return [];
625
- return [{ name, span: spanOf(source, member.name), extent: extentOf(source, member) }];
626
- });
627
- const importsOf = (statement) => {
628
- const { importClause, moduleSpecifier } = statement;
629
- if (!importClause || !ts.isStringLiteral(moduleSpecifier))
630
- return [];
631
- const from = moduleSpecifier.text;
632
- const bindings = importClause.namedBindings;
633
- return [
634
- ...importClause.name ? [{ name: importClause.name.text, imported: "default", from }] : [],
635
- ...bindings && ts.isNamespaceImport(bindings) ? [{ name: bindings.name.text, imported: "*", from }] : [],
636
- ...bindings && ts.isNamedImports(bindings) ? bindings.elements.map((element) => ({
637
- name: element.name.text,
638
- imported: (element.propertyName ?? element.name).text,
639
- from
640
- })) : []
641
- ];
642
- };
643
- const docOf = (source, node) => {
644
- const { text } = source;
645
- const ranges = ts.getLeadingCommentRanges(text, node.getFullStart()) ?? [];
646
- const comments = [];
647
- let end = node.getStart(source);
648
- for (const range of [...ranges].reverse()) {
649
- if ((text.slice(range.end, end).match(/\n/g)?.length ?? 0) > 1)
650
- break;
651
- comments.unshift(text.slice(range.pos, range.end));
652
- end = range.pos;
653
- }
654
- const lines = comments.flatMap((comment) => comment.split(`
655
- `)).map((line) => line.trim().replace(/^\/\*\*?|\*\/$/g, "").replace(/^(?:\/\/[?*!]?|\*)/, "").replace(/\{@link\s+([^}\s|]+)[^}]*\}/g, "$1").trim()).filter((line) => line && !/^(?:biome-ignore|eslint-|@ts-)/.test(line));
656
- return lines.length ? lines.join(" ") : null;
657
- };
741
+ return { constantOf, enumValuesOf, filterQueriesOf };
742
+ };
743
+ var createFactReader = (ts, ast) => {
744
+ const syntax = syntaxReaderOf(ts, ast);
745
+ const { spanOf, extentOf, unwrap, moduleRefOf, returnedObject, builderOf, chainOf, objectKeys } = syntax;
746
+ const { docOf, importsIn } = sourceReaderOf(ts);
658
747
  const { guardsIn, guardsOf } = createGuardFactReader(ts, ast, { spanOf, extentOf, unwrap, docOf });
748
+ const { sliceKeysOf, endpointKeysOf } = signalKeyReaderOf(ts, ast, syntax, guardsIn);
749
+ const { internalKeysOf } = jobKeyReaderOf(ts, ast, syntax);
750
+ const { plugsOf, adaptorBindingsIn, methodsOf } = serviceReaderOf(ts, ast, syntax);
751
+ const { constantOf, enumValuesOf, filterQueriesOf } = constantReaderOf(ts, ast, syntax);
659
752
  const lowerFirst = (text) => text.charAt(0).toLowerCase() + text.slice(1);
660
- const importsIn = (source) => source.statements.filter(ts.isImportDeclaration).flatMap(importsOf);
661
753
  const read = (source, owner) => {
662
754
  const imports = importsIn(source);
663
755
  const madeInPlace = [];
@@ -755,7 +847,11 @@ var frameworkOwner = "akanjs";
755
847
  var frameworkPattern = /^akanjs(?:\/|$)/;
756
848
  var aliasPattern = /^@(apps|libs)\/([^/]+)/;
757
849
  var maxMapDepth = 4;
850
+ var identifierPattern = /^[\p{ID_Start}$_][\p{ID_Continue}$\u200c\u200d]*$/u;
758
851
  var starExportPattern = /export\s*\*\s*from\s*["']([^"']+)["']/g;
852
+ var facetEntryPattern = new RegExp(`^((?:apps|libs)/[^/]+/(${barrelFacetDirs.map(escapeRegExp).join("|")}))/([^/]+)(/)?`);
853
+ var exportingPatternOf = (name) => new RegExp(`export\\s*\\{(?:[^}]*?[\\s,])?${escapeRegExp(name)}(?![\\w$])`);
854
+ var exportMentioningPatternOf = (name) => new RegExp(`export(?![\\w$])[^;]*?(?<![\\w$])${escapeRegExp(name)}(?![\\w$])`);
759
855
  var declaringPatternOf = (name, isAnyBinding) => {
760
856
  const escaped = escapeRegExp(name);
761
857
  const braced = "\\{(?:[^}]*?[\\s,])?";
@@ -777,8 +873,12 @@ class GuardResolver {
777
873
  #reexports = new Map;
778
874
  #declarations = new Map;
779
875
  #starExports = new Map;
876
+ #moduleExports = new Map;
877
+ #fileStars = new Map;
878
+ #starReach = new Map;
780
879
  #ownerFiles = null;
781
880
  #modules = null;
881
+ #barrels = null;
782
882
  constructor(source, routes) {
783
883
  this.#source = source;
784
884
  this.#routes = routes;
@@ -802,21 +902,26 @@ ${name}`);
802
902
  made: [],
803
903
  isReal: fact.direct,
804
904
  scope: fact.scope,
905
+ layers: fact.layers,
805
906
  targets: []
806
907
  };
807
908
  factories.set(fact.name, [...factories.get(fact.name) ?? [], factory]);
808
909
  declaredFactories.push(factory);
809
910
  }
810
911
  for (const factory of declaredFactories)
811
- factory.targets = factory.fact.via.map((callee) => this.#factoryAt(factories, callee, factory.site)).filter((target) => target !== undefined);
912
+ factory.targets = factory.fact.via.flatMap(({ callee, layers }) => {
913
+ const target = this.#factoryAt(factories, callee, factory.site);
914
+ return target ? [{ target, layers }] : [];
915
+ });
812
916
  for (let isGrowing = true;isGrowing; ) {
813
917
  isGrowing = false;
814
918
  for (const factory of declaredFactories) {
815
- const target = factory.targets.find((other) => other.isReal);
816
- if (factory.isReal || !target)
919
+ const via = factory.targets.find(({ target, layers }) => target.isReal && target.layers >= layers);
920
+ if (factory.isReal || !via)
817
921
  continue;
818
922
  factory.isReal = true;
819
- factory.scope ??= target.scope;
923
+ factory.layers = factory.fact.layers + via.target.layers - via.layers;
924
+ factory.scope ??= via.target.scope;
820
925
  isGrowing = true;
821
926
  }
822
927
  }
@@ -826,7 +931,7 @@ ${name}`);
826
931
  seen.add(factory);
827
932
  return [
828
933
  { fileName: factory.site.fileName, extent: factory.fact.extent },
829
- ...factory.targets.filter((target) => target.isReal).flatMap((target) => partsOf(target, seen))
934
+ ...factory.targets.filter(({ target }) => target.isReal).flatMap(({ target }) => partsOf(target, seen))
830
935
  ];
831
936
  };
832
937
  const declare = (file, made, scope, parts) => {
@@ -847,7 +952,7 @@ ${name}`, guard);
847
952
  const factory = made.factory ? factories.get(made.factory)?.find((other) => other.site.fileName === file.fileName) : undefined;
848
953
  if (!made.factory)
849
954
  declare(file, made, made.scope, []);
850
- else if (factory?.isReal)
955
+ else if (factory?.isReal && factory.layers === made.layers)
851
956
  factory.made.push(declare(file, made, factory.scope, partsOf(factory)));
852
957
  }
853
958
  for (const made of file.guardCalls) {
@@ -856,7 +961,7 @@ ${name}`, guard);
856
961
  continue;
857
962
  }
858
963
  const factory = this.#factoryAt(factories, made.callee, file);
859
- if (factory?.isReal)
964
+ if (factory?.isReal && factory.layers === made.layers)
860
965
  factory.made.push(declare(file, made, factory.scope, partsOf(factory)));
861
966
  }
862
967
  }
@@ -901,7 +1006,7 @@ ${name}`, guard);
901
1006
  const own = this.#nearest(candidates.filter((other) => other.owner === from), ({ site }) => site.fileName, near);
902
1007
  if (own)
903
1008
  return own;
904
- const reexport = from && depth < maxMapDepth ? this.reexportOf(from, name, near) : null;
1009
+ const reexport = from && depth < maxMapDepth ? this.#reexportOf(from, name, near) : null;
905
1010
  if (reexport)
906
1011
  return this.#factoryAt(factories, reexport.local, reexport.site, depth + 1);
907
1012
  return from && near ? this.#throughStar(candidates, from, name, near) : undefined;
@@ -939,13 +1044,13 @@ ${name}`, guard);
939
1044
  const visible = isBase ? undefined : declared.find((other) => this.visible(other.owner, site.owner));
940
1045
  return visible ? { guard: visible } : { name, from };
941
1046
  }
942
- const reexport = from && depth < maxMapDepth ? this.reexportOf(from, name, near) : null;
1047
+ const reexport = from && depth < maxMapDepth ? this.#reexportOf(from, name, near) : null;
943
1048
  if (reexport)
944
1049
  return this.#findGuard(reexport.local, reexport.site, depth + 1, isBase);
945
1050
  const reached = from && near ? this.#throughStar(declared, from, name, near) : undefined;
946
1051
  return reached ? { guard: reached } : { name, from };
947
1052
  }
948
- reexportOf(owner, name, near) {
1053
+ #reexportOf(owner, name, near) {
949
1054
  const key = `${owner}
950
1055
  ${name}
951
1056
  ${near ?? ""}`;
@@ -953,7 +1058,7 @@ ${near ?? ""}`;
953
1058
  if (cached !== undefined)
954
1059
  return cached;
955
1060
  let found = null;
956
- const exporting = new RegExp(`export\\s*\\{(?:[^}]*?[\\s,])?${escapeRegExp(name)}(?![\\w$])`);
1061
+ const exporting = exportingPatternOf(name);
957
1062
  for (const fileName of this.#filesOf(owner, name, near)) {
958
1063
  const text = this.#source.readText(fileName);
959
1064
  if (text === undefined || !exporting.test(text))
@@ -971,7 +1076,7 @@ ${near ?? ""}`;
971
1076
  this.#reexports.set(key, found);
972
1077
  return found;
973
1078
  }
974
- #reexportIn(source, name) {
1079
+ #reexportIn(source, name, takesPackageDefault = false) {
975
1080
  const { ts, reader } = this.#source;
976
1081
  for (const statement of source.statements) {
977
1082
  if (!ts.isExportDeclaration(statement) || statement.isTypeOnly)
@@ -988,7 +1093,9 @@ ${near ?? ""}`;
988
1093
  const imported = reader.importsIn(source).find((item) => item.name === original);
989
1094
  if (!imported)
990
1095
  return { name: original, from: null };
991
- return imported.imported === "default" || imported.imported === "*" ? null : { name: imported.imported, from: imported.from };
1096
+ if (imported.imported === "default")
1097
+ return takesPackageDefault && this.pathOfSpecifier(source.fileName, imported.from) === null ? { name: "default", from: imported.from } : null;
1098
+ return imported.imported === "*" ? null : { name: imported.imported, from: imported.from };
992
1099
  }
993
1100
  return null;
994
1101
  }
@@ -997,7 +1104,9 @@ ${near ?? ""}`;
997
1104
  const relative = this.#source.relative(fileName);
998
1105
  return !!near && (relative.startsWith(`${near}/`) || relative.replace(/\.tsx?$/, "") === near);
999
1106
  };
1000
- const candidates = this.filesIn(owner).filter(([, words]) => words.includes(`
1107
+ if (!identifierPattern.test(name))
1108
+ return [];
1109
+ const candidates = this.#filesIn(owner).filter(([, words]) => words.includes(`
1001
1110
  ${name}
1002
1111
  `)).map(([fileName]) => fileName);
1003
1112
  return [...candidates.filter(isNear), ...candidates.filter((other) => !isNear(other))];
@@ -1014,7 +1123,7 @@ ${owner ?? ""}`;
1014
1123
  const entries = [];
1015
1124
  const fileNames = [
1016
1125
  ...fileName ? [fileName] : [],
1017
- ...(owner === null ? [] : this.filesIn(owner)).filter(([other, words]) => other !== fileName && words.includes(`
1126
+ ...(owner === null ? [] : this.#filesIn(owner)).filter(([other, words]) => other !== fileName && words.includes(`
1018
1127
  ${objectName}
1019
1128
  `) && words.includes(`
1020
1129
  ${member}
@@ -1088,30 +1197,120 @@ ${near ?? ""}`;
1088
1197
  #throughStar(declared, owner, name, near) {
1089
1198
  if (!declared.length)
1090
1199
  return;
1091
- const { owners, isOpaque } = this.#starExportsOf(owner, near);
1200
+ const { owners, isOpaque } = this.starExportsOf(owner, near);
1092
1201
  const reached = declared.filter((other) => other.owner !== null && owners.includes(other.owner));
1093
1202
  return reached.length === 1 && !isOpaque && !this.declares(owner, name) ? reached[0] : undefined;
1094
1203
  }
1095
- #starExportsOf(owner, near) {
1096
- const cached = this.#starExports.get(near);
1204
+ starExportsOf(owner, near) {
1205
+ const key = `${owner}
1206
+ ${near}`;
1207
+ const cached = this.#starExports.get(key);
1097
1208
  if (cached)
1098
1209
  return cached;
1099
- const found = { owners: [], isOpaque: false };
1100
- this.#starExports.set(near, found);
1101
- const paths = [near];
1102
- for (let idx = 0;idx < paths.length && !found.isOpaque; idx++)
1103
- for (const fileName of this.#modulesAt(paths[idx] ?? "")) {
1104
- for (const [, specifier = ""] of this.#source.readText(fileName)?.matchAll(starExportPattern) ?? []) {
1105
- const target = this.ownerOfSpecifier(fileName, specifier);
1106
- const path = this.pathOfSpecifier(fileName, specifier);
1107
- if (target === undefined || target === frameworkOwner || path === null)
1108
- found.isOpaque = true;
1109
- else if (!paths.includes(path))
1110
- paths.push(path);
1111
- if (target && target !== frameworkOwner && target !== owner && !found.owners.includes(target))
1112
- found.owners.push(target);
1113
- }
1210
+ const found = { owners: [], packages: [], paths: [near], isOpaque: false };
1211
+ this.#starExports.set(key, found);
1212
+ const reach = (specifier, path, target) => {
1213
+ if (path === null && !found.packages.includes(specifier))
1214
+ found.packages.push(specifier);
1215
+ if (target === undefined || target === frameworkOwner || path === null)
1216
+ found.isOpaque = true;
1217
+ else if (!found.paths.includes(path))
1218
+ found.paths.push(path);
1219
+ if (target && target !== frameworkOwner && target !== owner && !found.owners.includes(target))
1220
+ found.owners.push(target);
1221
+ };
1222
+ for (let idx = 0;idx < found.paths.length; idx++) {
1223
+ const path = found.paths[idx] ?? "";
1224
+ for (const module of this.#barrelAt(path) ?? [])
1225
+ reach(module, module, ownerOf(module) ?? undefined);
1226
+ for (const fileName of this.#modulesAt(path))
1227
+ for (const [, specifier = ""] of this.#source.readText(fileName)?.matchAll(starExportPattern) ?? [])
1228
+ reach(specifier, this.pathOfSpecifier(fileName, specifier), this.ownerOfSpecifier(fileName, specifier));
1229
+ }
1230
+ return found;
1231
+ }
1232
+ exportsAt(path, name) {
1233
+ const key = `${path}
1234
+ ${name}`;
1235
+ const cached = this.#moduleExports.get(key);
1236
+ if (cached)
1237
+ return cached;
1238
+ const found = { named: null, stars: [], isLocal: false };
1239
+ const stars = new Set(this.#barrelAt(path));
1240
+ for (const fileName of this.#modulesAt(path)) {
1241
+ const text = this.#source.readText(fileName);
1242
+ if (text === undefined)
1243
+ continue;
1244
+ const named = text.includes(name) && identifierPattern.test(name) && exportingPatternOf(name).test(text) ? this.#reexportIn(this.#source.parse(fileName, text), name, true) : null;
1245
+ if (named) {
1246
+ found.named = { ...named, fileName };
1247
+ break;
1248
+ }
1249
+ if (text.includes(name) && exportMentioningPatternOf(name).test(text) && this.#exportsLocally(this.#source.parse(fileName, text), name)) {
1250
+ found.isLocal = true;
1251
+ break;
1252
+ }
1253
+ for (const target of this.#starsIn(fileName, text))
1254
+ stars.add(target);
1255
+ }
1256
+ if (!found.named && !found.isLocal)
1257
+ found.stars = [...stars];
1258
+ this.#moduleExports.set(key, found);
1259
+ return found;
1260
+ }
1261
+ #exportsLocally(source, name) {
1262
+ const { ts } = this.#source;
1263
+ const binds = (node) => ts.isIdentifier(node) ? node.text === name : node.elements.some((element) => !ts.isOmittedExpression(element) && binds(element.name));
1264
+ return source.statements.some((statement) => {
1265
+ if (ts.isExportDeclaration(statement)) {
1266
+ const { exportClause, isTypeOnly, moduleSpecifier } = statement;
1267
+ if (isTypeOnly || !exportClause)
1268
+ return false;
1269
+ if (ts.isNamespaceExport(exportClause))
1270
+ return exportClause.name.text === name;
1271
+ return !moduleSpecifier && ts.isNamedExports(exportClause) && exportClause.elements.some((element) => !element.isTypeOnly && element.name.text === name);
1114
1272
  }
1273
+ const modifiers = ts.canHaveModifiers(statement) ? ts.getModifiers(statement) ?? [] : [];
1274
+ if (!modifiers.some(({ kind }) => kind === ts.SyntaxKind.ExportKeyword) || modifiers.some(({ kind }) => kind === ts.SyntaxKind.DefaultKeyword))
1275
+ return false;
1276
+ if (ts.isVariableStatement(statement))
1277
+ return statement.declarationList.declarations.some((declaration) => binds(declaration.name));
1278
+ return (ts.isClassDeclaration(statement) || ts.isFunctionDeclaration(statement) || ts.isEnumDeclaration(statement) || ts.isModuleDeclaration(statement) || ts.isImportEqualsDeclaration(statement)) && !!statement.name && ts.isIdentifier(statement.name) && statement.name.text === name;
1279
+ });
1280
+ }
1281
+ mentionsAlong(path, name) {
1282
+ return this.#starReachOf(path).some((text) => text.includes(name));
1283
+ }
1284
+ #starReachOf(path) {
1285
+ const cached = this.#starReach.get(path);
1286
+ if (cached)
1287
+ return cached;
1288
+ const paths = new Set([path]);
1289
+ const texts = [];
1290
+ for (const at of paths) {
1291
+ for (const next of this.#barrelAt(at) ?? [])
1292
+ paths.add(next);
1293
+ for (const fileName of this.#modulesAt(at)) {
1294
+ const text = this.#source.readText(fileName) ?? "";
1295
+ texts.push(text);
1296
+ for (const next of this.#starsIn(fileName, text))
1297
+ paths.add(next);
1298
+ }
1299
+ }
1300
+ this.#starReach.set(path, texts);
1301
+ return texts;
1302
+ }
1303
+ #starsIn(fileName, text) {
1304
+ const cached = this.#fileStars.get(fileName);
1305
+ if (cached)
1306
+ return cached;
1307
+ const found = [];
1308
+ for (const [, specifier = ""] of text.matchAll(starExportPattern)) {
1309
+ const target = this.pathOfSpecifier(fileName, specifier);
1310
+ if (target !== null)
1311
+ found.push(target);
1312
+ }
1313
+ this.#fileStars.set(fileName, found);
1115
1314
  return found;
1116
1315
  }
1117
1316
  #modulesAt(path) {
@@ -1125,11 +1324,33 @@ ${near ?? ""}`;
1125
1324
  }
1126
1325
  return this.#modules.get(path) ?? [];
1127
1326
  }
1327
+ #barrelAt(path) {
1328
+ if (!this.#barrels) {
1329
+ const entries = new Map;
1330
+ for (const [fileName] of this.#source.files) {
1331
+ const [, folder, facet, entry, nested] = this.#source.relative(fileName).match(facetEntryPattern) ?? [];
1332
+ if (!folder || !facet || !entry)
1333
+ continue;
1334
+ const found = entries.get(folder) ?? { facet, files: new Set, dirs: new Set };
1335
+ (nested ? found.dirs : found.files).add(entry);
1336
+ entries.set(folder, found);
1337
+ }
1338
+ this.#barrels = new Map([...entries].map(([folder, { facet, files, dirs }]) => [
1339
+ folder,
1340
+ facetBarrelNamesOf(facet, [...files], [...dirs]).map((name) => `${folder}/${name}`)
1341
+ ]));
1342
+ }
1343
+ return this.#modulesAt(path).length ? undefined : this.#barrels.get(path);
1344
+ }
1128
1345
  declares(owner, name) {
1129
1346
  const declaring = declaringPatternOf(name, true);
1130
1347
  return this.#filesOf(owner, name, null).some((fileName) => declaring.test(this.#source.readText(fileName) ?? ""));
1131
1348
  }
1132
- filesIn(owner) {
1349
+ declaresAt(path, name) {
1350
+ const declaring = declaringPatternOf(name, true);
1351
+ return this.#modulesAt(path).some((fileName) => declaring.test(this.#source.readText(fileName) ?? ""));
1352
+ }
1353
+ #filesIn(owner) {
1133
1354
  if (!this.#ownerFiles) {
1134
1355
  this.#ownerFiles = new Map;
1135
1356
  for (const entry of this.#source.files) {
@@ -1179,6 +1400,196 @@ ${near ?? ""}`;
1179
1400
  }
1180
1401
  }
1181
1402
 
1403
+ // pkgs/@akanjs/language/adaptorResolver.ts
1404
+ var packageOf = (specifier) => specifier.split("/").slice(0, specifier.startsWith("@") ? 2 : 1).join("/");
1405
+ var packageKeyOf = ({ name, from }) => `${packageOf(from)}
1406
+ ${name}`;
1407
+ var exportedKeyOf = (item) => ("fact" in item) ? item.id : ("local" in item) ? `${item.local}
1408
+ ` : packageKeyOf(item);
1409
+ var isPackageExport = (item) => ("from" in item);
1410
+
1411
+ class AdaptorResolver {
1412
+ #source;
1413
+ #resolver;
1414
+ #sink;
1415
+ #adaptors = new Map;
1416
+ #plugs = new Map;
1417
+ #serviceFields = new Set;
1418
+ #exported = new Map;
1419
+ constructor(source, resolver, sink) {
1420
+ this.#source = source;
1421
+ this.#resolver = resolver;
1422
+ this.#sink = sink;
1423
+ }
1424
+ declare(facts) {
1425
+ const counts = new Map;
1426
+ for (const file of facts)
1427
+ for (const fact of file.adaptors) {
1428
+ const key = this.#sink.key("adaptor", file.owner, fact.name);
1429
+ counts.set(key, (counts.get(key) ?? 0) + 1);
1430
+ }
1431
+ const declared = facts.flatMap((file) => file.adaptors.map((fact) => {
1432
+ const key = this.#sink.key("adaptor", file.owner, fact.name);
1433
+ const id = (counts.get(key) ?? 0) > 1 ? this.#sink.key("adaptor", file.owner, `${this.#resolver.inOwner(file.fileName, file.owner)}#${fact.name}`) : key;
1434
+ const adaptor = { fact, owner: file.owner, fileName: file.fileName, id };
1435
+ this.#adaptors.set(fact.name, [...this.#adaptors.get(fact.name) ?? [], adaptor]);
1436
+ this.#nodeOf(adaptor);
1437
+ return { adaptor, file };
1438
+ }));
1439
+ for (const { adaptor, file } of declared)
1440
+ for (const plug of adaptor.fact.plugs)
1441
+ this.#sink.addEdge(adaptor.id, this.#idOf(plug.target, file), "plugs", plug.name, this.#sink.location(plug.span));
1442
+ for (const file of facts)
1443
+ for (const binding of file.adaptorBindings)
1444
+ this.#sink.addEdge(this.#idOf(binding.role, file), this.#idOf(binding.adaptor, file), "binds", file.owner, this.#sink.location(binding.span));
1445
+ }
1446
+ addService(refName, service, file) {
1447
+ for (const plug of service.plugs) {
1448
+ const key = `${refName}
1449
+ ${plug.name}`;
1450
+ this.#plugs.set(key, [
1451
+ ...this.#plugs.get(key) ?? [],
1452
+ { owner: file.owner, target: this.#idOf(plug.target, file) }
1453
+ ]);
1454
+ }
1455
+ for (const field of service.fields)
1456
+ this.#serviceFields.add(`${file.owner ?? ""}
1457
+ ${refName}
1458
+ ${field}`);
1459
+ }
1460
+ pluggedOf(owner, module, field) {
1461
+ const plugs = this.#plugs.get(`${module}
1462
+ ${field}`) ?? [];
1463
+ const own = plugs.filter((plug) => plug.owner === owner);
1464
+ if (!own.length && this.#serviceFields.has(`${owner ?? ""}
1465
+ ${module}
1466
+ ${field}`))
1467
+ return [];
1468
+ const inherited = own.length ? own : plugs.filter((plug) => this.#resolver.visible(plug.owner, owner));
1469
+ return [...new Set(inherited.map(({ target }) => target))];
1470
+ }
1471
+ #idOf(local, file) {
1472
+ const [head, member] = local.split(".");
1473
+ const imported = file.imports.find((item) => item.name === head);
1474
+ const name = member ?? (imported && imported.imported !== "default" && imported.imported !== "*" ? imported.imported : head);
1475
+ const path = imported ? this.#resolver.pathOfSpecifier(file.fileName, imported.from) : null;
1476
+ if (imported && path === null && !frameworkPattern.test(imported.from))
1477
+ return this.#packageAdaptorOf(name, imported.from);
1478
+ const from = imported ? this.#resolver.ownerOfSpecifier(file.fileName, imported.from) : undefined;
1479
+ const declared = this.#adaptors.get(name) ?? [];
1480
+ const holder = from === undefined ? file.owner : from;
1481
+ const own = this.#adaptorIn(name, declared, holder, path, file.fileName);
1482
+ if (own && "from" in own)
1483
+ return this.#packageAdaptorOf(own.name, own.from);
1484
+ const shims = own === undefined && from && from !== frameworkOwner && path ? this.#exportedAt(name, path).filter(isPackageExport) : [];
1485
+ const [shim] = shims;
1486
+ if (shim && shims.length === 1)
1487
+ return this.#packageAdaptorOf(shim.name, shim.from);
1488
+ const found = own === undefined && !shim && from !== frameworkOwner ? declared.find((adaptor) => this.#resolver.visible(adaptor.owner, holder)) : own;
1489
+ if (found)
1490
+ return found.id;
1491
+ const starred = own === undefined && !shim && from && from !== frameworkOwner ? this.#starredPackageOf(from, name, path) : null;
1492
+ if (starred)
1493
+ return this.#packageAdaptorOf(starred.name, starred.from);
1494
+ const owner = from === frameworkOwner ? null : imported ? from ?? null : file.owner;
1495
+ const detail = from === frameworkOwner ? [frameworkOwner] : [];
1496
+ return this.#sink.addNode(this.#sink.key("adaptor", owner, name), "adaptor", owner, name, null, detail).id;
1497
+ }
1498
+ #adaptorIn(name, declared, owner, path, fileName) {
1499
+ const own = declared.filter((adaptor) => adaptor.owner === owner);
1500
+ const [first] = own;
1501
+ if (path === null)
1502
+ return own.find((adaptor) => adaptor.fileName === fileName) ?? first;
1503
+ if (own.length === 1)
1504
+ return first;
1505
+ const exported = this.#exportedAt(name, path).filter((item) => first || !isPackageExport(item));
1506
+ const [only] = exported;
1507
+ if (only)
1508
+ return exported.length === 1 && !("local" in only) ? only : null;
1509
+ return first ? null : undefined;
1510
+ }
1511
+ #exportedAt(name, path) {
1512
+ const key = `${path}
1513
+ ${name}`;
1514
+ const cached = this.#exported.get(key);
1515
+ if (cached)
1516
+ return cached;
1517
+ if (!this.#resolver.mentionsAlong(path, name)) {
1518
+ this.#exported.set(key, []);
1519
+ return [];
1520
+ }
1521
+ const reached = new Map;
1522
+ const seen = new Set;
1523
+ const pending = [[name, path]];
1524
+ for (let next = pending.pop();next; next = pending.pop()) {
1525
+ const [wanted, at] = next;
1526
+ if (seen.has(`${at}
1527
+ ${wanted}`))
1528
+ continue;
1529
+ seen.add(`${at}
1530
+ ${wanted}`);
1531
+ for (const item of this.#bindingAt(wanted, at, pending, name))
1532
+ reached.set(exportedKeyOf(item), item);
1533
+ }
1534
+ const found = [...reached.values()];
1535
+ this.#exported.set(key, found);
1536
+ return found;
1537
+ }
1538
+ #bindingAt(name, path, pending, plugged) {
1539
+ const here = this.#declaredAt(name, path);
1540
+ if (here.length)
1541
+ return here;
1542
+ const { named, stars, isLocal } = this.#resolver.exportsAt(path, name);
1543
+ if (isLocal)
1544
+ return [{ local: path }];
1545
+ if (named?.from === null) {
1546
+ const local = this.#declaredAt(named.name, path);
1547
+ return local.length ? local : [{ local: path }];
1548
+ }
1549
+ if (named) {
1550
+ const target = this.#resolver.pathOfSpecifier(named.fileName, named.from);
1551
+ if (target === null) {
1552
+ const exposed = named.name !== "default" ? named.name : name !== "default" ? name : plugged;
1553
+ return [{ name: exposed, from: named.from }];
1554
+ }
1555
+ pending.push([named.name, target]);
1556
+ return [];
1557
+ }
1558
+ for (const star of stars)
1559
+ pending.push([name, star]);
1560
+ return [];
1561
+ }
1562
+ #declaredAt(name, path) {
1563
+ return (this.#adaptors.get(name) ?? []).filter((adaptor) => {
1564
+ const module = this.#source.relative(adaptor.fileName).replace(/\.tsx?$/, "");
1565
+ return module === path || module === `${path}/index`;
1566
+ });
1567
+ }
1568
+ #packageAdaptorOf(name, specifier) {
1569
+ if (frameworkPattern.test(specifier))
1570
+ return this.#sink.addNode(this.#sink.key("adaptor", null, name), "adaptor", null, name, null, [frameworkOwner]).id;
1571
+ const pkg = packageOf(specifier);
1572
+ return this.#sink.addNode(this.#sink.key("adaptor", pkg, name), "adaptor", null, name, null, [pkg]).id;
1573
+ }
1574
+ #starredPackageOf(owner, name, near) {
1575
+ if (!near)
1576
+ return null;
1577
+ const { packages, paths } = this.#resolver.starExportsOf(owner, near);
1578
+ const [only] = packages;
1579
+ if (!only || new Set(packages.map(packageOf)).size !== 1)
1580
+ return null;
1581
+ return paths.some((path) => this.#resolver.declaresAt(path, name)) ? null : { name, from: only };
1582
+ }
1583
+ #nodeOf({ fact, owner, fileName, id }) {
1584
+ const detail = fact.refName ? [fact.refName] : [];
1585
+ const node = this.#sink.addNode(id, "adaptor", owner, fact.name, fact.span, detail);
1586
+ if (fact.doc && !node.doc)
1587
+ node.doc = fact.doc;
1588
+ this.#sink.digest(node, this.#source.readText(fileName), fact.extent);
1589
+ return node.id;
1590
+ }
1591
+ }
1592
+
1182
1593
  // pkgs/akanjs/common/trimSlashes.ts
1183
1594
  var trimTrailingSlashes = (value) => {
1184
1595
  let end = value.length;
@@ -1202,6 +1613,7 @@ var PAGE_ROUTE_EXPORTS = new Set([
1202
1613
  "guard"
1203
1614
  ]);
1204
1615
  var LAYOUT_ROUTE_EXPORTS = new Set([...PAGE_ROUTE_EXPORTS, "NotFound", "Error"]);
1616
+ var GENERATED_ROOT_LAYOUT_EXPORTS = new Set(["McpAppRoot", "LevelBoundary"]);
1205
1617
  var ROOT_LAYOUT_ROUTE_EXPORTS = new Set([
1206
1618
  ...LAYOUT_ROUTE_EXPORTS,
1207
1619
  "fonts",
@@ -1211,7 +1623,7 @@ var ROOT_LAYOUT_ROUTE_EXPORTS = new Set([
1211
1623
  "wsConnect",
1212
1624
  "layoutStyle",
1213
1625
  "viewport",
1214
- "McpAppRoot"
1626
+ ...GENERATED_ROOT_LAYOUT_EXPORTS
1215
1627
  ]);
1216
1628
  var RESERVED_ROUTE_CONFIG_EXPORTS = new Set([...ROOT_LAYOUT_ROUTE_EXPORTS].filter((name) => name !== "default" && !/^[A-Z]/.test(name)));
1217
1629
  function parseRouteModuleKey(key) {
@@ -1467,13 +1879,18 @@ class GraphBuilder {
1467
1879
  #routeFiles = new Map;
1468
1880
  #routes;
1469
1881
  #resolver;
1470
- #adaptors = new Map;
1471
- #plugs = new Map;
1472
- #serviceFields = new Set;
1882
+ #adaptors;
1473
1883
  constructor(source) {
1474
1884
  this.#source = source;
1475
1885
  this.#routes = new RouteFactReader(source.ts, source.reader, source.parse);
1476
1886
  this.#resolver = new GuardResolver(source, this.#routes);
1887
+ this.#adaptors = new AdaptorResolver(source, this.#resolver, {
1888
+ key: (kind, owner, scope) => this.#key(kind, owner, scope),
1889
+ addNode: (id, kind, owner, name, span, detail) => this.#addNode(id, kind, owner, null, name, span, detail),
1890
+ addEdge: (from, to, kind, label, at) => this.#addEdge(from, to, kind, label, at),
1891
+ digest: (node, text, extent) => this.#digest(node, text, extent),
1892
+ location: (span) => this.#location(span)
1893
+ });
1477
1894
  }
1478
1895
  build() {
1479
1896
  const { facts } = this.#source;
@@ -1485,26 +1902,7 @@ class GraphBuilder {
1485
1902
  ...[...constantsByOwner].filter(([key]) => key !== owner && key?.startsWith("libs/")).flatMap(([, list]) => list)
1486
1903
  ];
1487
1904
  const typed = [];
1488
- const adaptorCounts = new Map;
1489
- for (const file of facts)
1490
- for (const fact of file.adaptors) {
1491
- const key = this.#key("adaptor", file.owner, fact.name);
1492
- adaptorCounts.set(key, (adaptorCounts.get(key) ?? 0) + 1);
1493
- }
1494
- const declaredAdaptors = facts.flatMap((file) => file.adaptors.map((fact) => {
1495
- const key = this.#key("adaptor", file.owner, fact.name);
1496
- const id = (adaptorCounts.get(key) ?? 0) > 1 ? this.#key("adaptor", file.owner, `${this.#resolver.inOwner(file.fileName, file.owner)}#${fact.name}`) : key;
1497
- const declared = { fact, owner: file.owner, fileName: file.fileName, id };
1498
- this.#adaptors.set(fact.name, [...this.#adaptors.get(fact.name) ?? [], declared]);
1499
- this.#adaptorNodeOf(declared);
1500
- return { declared, file };
1501
- }));
1502
- for (const { declared, file } of declaredAdaptors)
1503
- for (const plug of declared.fact.plugs)
1504
- this.#addEdge(declared.id, this.#adaptorIdOf(plug.target, file), "plugs", plug.name, this.#location(plug.span));
1505
- for (const file of facts)
1506
- for (const binding of file.adaptorBindings)
1507
- this.#addEdge(this.#adaptorIdOf(binding.role, file), this.#adaptorIdOf(binding.adaptor, file), "binds", file.owner, this.#location(binding.span));
1905
+ this.#adaptors.declare(facts);
1508
1906
  for (const guard of this.#resolver.declare(facts))
1509
1907
  this.#guardNodeOf(guard);
1510
1908
  for (const file of facts) {
@@ -1537,18 +1935,7 @@ class GraphBuilder {
1537
1935
  }
1538
1936
  for (const method of service.methods)
1539
1937
  this.#addMember("method", owner, refName, method, `${service.name}.${method.name}`, file.fileName);
1540
- for (const plug of service.plugs) {
1541
- const key = `${refName}
1542
- ${plug.name}`;
1543
- this.#plugs.set(key, [
1544
- ...this.#plugs.get(key) ?? [],
1545
- { owner, target: this.#adaptorIdOf(plug.target, file) }
1546
- ]);
1547
- }
1548
- for (const field of service.fields)
1549
- this.#serviceFields.add(`${owner ?? ""}
1550
- ${refName}
1551
- ${field}`);
1938
+ this.#adaptors.addService(refName, service, file);
1552
1939
  }
1553
1940
  for (const filter of file.filters) {
1554
1941
  if (!filter.name.endsWith("Filter"))
@@ -1804,80 +2191,6 @@ ${dir}`, node);
1804
2191
  this.#digest(node, text, extent);
1805
2192
  return node.id;
1806
2193
  }
1807
- #adaptorIdOf(local, file) {
1808
- const [head, member] = local.split(".");
1809
- const imported = file.imports.find((item) => item.name === head);
1810
- const name = member ?? (imported && imported.imported !== "default" && imported.imported !== "*" ? imported.imported : head);
1811
- const path = imported ? this.#resolver.pathOfSpecifier(file.fileName, imported.from) : null;
1812
- if (imported && path === null && !frameworkPattern.test(imported.from))
1813
- return this.#packageAdaptorOf(name, imported.from);
1814
- const from = imported ? this.#resolver.ownerOfSpecifier(file.fileName, imported.from) : undefined;
1815
- const declared = this.#adaptors.get(name) ?? [];
1816
- 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)));
1817
- if (found)
1818
- return found.id;
1819
- const reexported = from && from !== frameworkOwner ? this.#packageShimOf(from, name, path) : null;
1820
- if (reexported)
1821
- return this.#packageAdaptorOf(reexported.name, reexported.from);
1822
- const owner = from === frameworkOwner ? null : imported ? from ?? null : file.owner;
1823
- const detail = from === frameworkOwner ? [frameworkOwner] : [];
1824
- return this.#addNode(this.#key("adaptor", owner, name), "adaptor", owner, null, name, null, detail).id;
1825
- }
1826
- #adaptorIn(declared, owner, path, fileName) {
1827
- const own = declared.filter((adaptor) => adaptor.owner === owner);
1828
- if (own.length < 2)
1829
- return own.at(0);
1830
- const pathOf = (adaptor) => this.#source.relative(adaptor.fileName).replace(/\.tsx?$/, "");
1831
- 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}/`));
1832
- return named ?? own.at(0);
1833
- }
1834
- #pluggedOf({ owner, module }, field) {
1835
- const plugs = this.#plugs.get(`${module}
1836
- ${field}`) ?? [];
1837
- const own = plugs.filter((plug) => plug.owner === owner);
1838
- if (!own.length && this.#serviceFields.has(`${owner ?? ""}
1839
- ${module}
1840
- ${field}`))
1841
- return [];
1842
- const inherited = own.length ? own : plugs.filter((plug) => this.#resolver.visible(plug.owner, owner));
1843
- return [...new Set(inherited.map(({ target }) => target))];
1844
- }
1845
- #packageAdaptorOf(name, specifier) {
1846
- if (frameworkPattern.test(specifier))
1847
- return this.#addNode(this.#key("adaptor", null, name), "adaptor", null, null, name, null, [frameworkOwner]).id;
1848
- const pkg = specifier.split("/").slice(0, specifier.startsWith("@") ? 2 : 1).join("/");
1849
- return this.#addNode(this.#key("adaptor", pkg, name), "adaptor", null, null, name, null, [pkg]).id;
1850
- }
1851
- #packageShimOf(owner, name, near) {
1852
- const reexport = this.#resolver.reexportOf(owner, name, near);
1853
- const [shim] = reexport?.site.imports ?? [];
1854
- if (reexport && shim && this.#resolver.pathOfSpecifier(reexport.site.fileName, shim.from) === null)
1855
- return { name: reexport.local === "default" ? name : reexport.local, from: shim.from };
1856
- if (reexport || !near)
1857
- return null;
1858
- const packages = new Set;
1859
- for (const [fileName, words] of this.#resolver.filesIn(owner)) {
1860
- const relative = this.#source.relative(fileName);
1861
- const isNear = relative.startsWith(`${near}/`) || relative.replace(/\.tsx?$/, "") === near;
1862
- if (!isNear || !words.includes(`
1863
- export
1864
- `))
1865
- continue;
1866
- for (const [, specifier = ""] of this.#source.readText(fileName)?.matchAll(starExportPattern) ?? [])
1867
- if (this.#resolver.pathOfSpecifier(fileName, specifier) === null)
1868
- packages.add(specifier);
1869
- }
1870
- const [only] = packages;
1871
- return packages.size === 1 && only && !this.#resolver.declares(owner, name) ? { name, from: only } : null;
1872
- }
1873
- #adaptorNodeOf({ fact, owner, fileName, id }) {
1874
- const detail = fact.refName ? [fact.refName] : [];
1875
- const node = this.#addNode(id, "adaptor", owner, null, fact.name, fact.span, detail);
1876
- if (fact.doc && !node.doc)
1877
- node.doc = fact.doc;
1878
- this.#digest(node, this.#source.readText(fileName), fact.extent);
1879
- return node.id;
1880
- }
1881
2194
  #guardNodeOf({ name, owner, span, scope, doc, parts, file, label }) {
1882
2195
  const id = this.#key("guard", owner, file ? `${file}#${name}` : name);
1883
2196
  const node = this.#addNode(id, "guard", owner, null, name, span, scope ? [scope] : [], label ?? name);
@@ -1980,7 +2293,7 @@ st
1980
2293
  visit(source);
1981
2294
  }
1982
2295
  #link(fileName, source, identifier, chain, context, owner) {
1983
- const plugged = chain?.length === 2 && chain[0] === "this" && context.kind === "method" && this.#isServiceThis(identifier) ? this.#pluggedOf(context, chain[1]) : [];
2296
+ const plugged = chain?.length === 2 && chain[0] === "this" && context.kind === "method" && this.#isServiceThis(identifier) ? this.#adaptors.pluggedOf(context.owner, context.module, chain[1]) : [];
1984
2297
  const resolved = plugged.length ? plugged : this.#source.resolve(fileName, identifier).map((target) => this.#targetNodeOf(target)).filter((id) => id !== null);
1985
2298
  const targets = resolved.length ? resolved : this.#plainTargetsOf(chain, identifier.text, context, owner);
1986
2299
  if (!targets.length)
@@ -2579,7 +2892,7 @@ var sourcePattern = /\.(constant|document|service|signal|store)\.ts$/;
2579
2892
  var dictionaryPattern = /\.dictionary\.ts$/;
2580
2893
  var srvkitPattern = /\/srvkit\//;
2581
2894
  var wordPattern = /[A-Za-z_$][\w$]*/g;
2582
- var identifierPattern = /^[A-Za-z_$][\w$]*$/;
2895
+ var identifierPattern2 = /^[A-Za-z_$][\w$]*$/;
2583
2896
  var stateReceivers = new Set(["use", "sel", "get", "do"]);
2584
2897
  var lensFamilies = new Set(["slice", "query", "formSetter", "storeState", "endpoint"]);
2585
2898
  var modellessFamilies = new Set(["query", "storeState", "endpoint"]);
@@ -2688,7 +3001,7 @@ ${[...new Set(text.match(wordPattern))].join(`
2688
3001
  }
2689
3002
  renameAt(givenName, offset, newKey, readText) {
2690
3003
  const sources = this.#sourceEntriesAt(pathOf(givenName), offset).filter((entry) => entry.renamed);
2691
- if (!sources.length || !identifierPattern.test(newKey))
3004
+ if (!sources.length || !identifierPattern2.test(newKey))
2692
3005
  return null;
2693
3006
  return [
2694
3007
  { span: sources[0].span, newText: newKey },
@@ -3398,6 +3711,11 @@ ${union.name}`)));
3398
3711
  const field = this.#memberOf(this.#classOf(receiver), receiver.name.text);
3399
3712
  return field && ts.isPropertyDeclaration(field) ? this.#namesIn(field.type) : new Set;
3400
3713
  }
3714
+ if (ts.isCallExpression(receiver) && ts.isPropertyAccessExpression(receiver.expression) && receiver.expression.expression.kind === ts.SyntaxKind.ThisKeyword) {
3715
+ const field = this.#memberOf(this.#classOf(receiver), receiver.expression.name.text);
3716
+ const type = field && ts.isPropertyDeclaration(field) ? field.type : undefined;
3717
+ return type && ts.isFunctionTypeNode(type) ? this.#namesIn(type.type) : new Set;
3718
+ }
3401
3719
  return this.#declaredTypeNames(receiver) ?? new Set;
3402
3720
  }
3403
3721
  #memberName(name) {