@akanjs/language 3.2.0-rc.2 → 3.2.0-rc.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/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))
@@ -384,7 +513,7 @@ var createFactReader = (ts, ast) => {
384
513
  const [size, unit] = intervalUnits.find(([size]) => ms >= size && ms % size === 0) ?? [1, "ms"];
385
514
  return `${ms / size}${unit}`;
386
515
  };
387
- const modesOf = (option) => {
516
+ const modesOf = (option, type) => {
388
517
  const object = option && unwrap(option);
389
518
  if (!object || !ts.isObjectLiteralExpression(object))
390
519
  return [];
@@ -394,9 +523,9 @@ var createFactReader = (ts, ast) => {
394
523
  if (name === "enabled")
395
524
  return value.kind === ts.SyntaxKind.FalseKeyword ? ["disabled"] : [];
396
525
  if (name === "once")
397
- return value.kind === ts.SyntaxKind.TrueKeyword ? ["once"] : [];
526
+ return type === "initialize" && value.kind === ts.SyntaxKind.TrueKeyword ? ["once"] : [];
398
527
  if (name === "lock")
399
- return value.kind === ts.SyntaxKind.FalseKeyword ? ["unlocked"] : [];
528
+ return type === "interval" && value.kind === ts.SyntaxKind.FalseKeyword ? ["unlocked"] : [];
400
529
  if (name !== "serverMode" && name !== "operationMode")
401
530
  return [];
402
531
  const values = ts.isArrayLiteralExpression(value) ? [...value.elements] : [value];
@@ -414,7 +543,8 @@ var createFactReader = (ts, ast) => {
414
543
  const { root } = chainOf(property.initializer);
415
544
  const type = root ? verbOf(root.expression) : null;
416
545
  const [first, second] = root?.arguments ?? [];
417
- const schedule = type === "cron" && first ? ts.isStringLiteralLike(first) ? first.text : first.getText(source) : type === "interval" || type === "timeout" ? durationOf(first, source) : null;
546
+ const cron = type === "cron" && first ? unwrap(first) : null;
547
+ const schedule = cron ? ts.isStringLiteralLike(cron) ? cron.text : cron.getText(source) : type === "interval" || type === "timeout" ? durationOf(first, source) : null;
418
548
  const option = type === "initialize" || type === "destroy" ? first : second;
419
549
  return [
420
550
  {
@@ -423,11 +553,14 @@ var createFactReader = (ts, ast) => {
423
553
  extent: extentOf(source, property),
424
554
  type,
425
555
  schedule,
426
- modes: modesOf(option)
556
+ modes: modesOf(option, type)
427
557
  }
428
558
  ];
429
559
  });
430
560
  };
561
+ return { internalKeysOf };
562
+ };
563
+ var serviceReaderOf = (ts, ast, { spanOf, extentOf, returnedObject, guardNameOf, chainOf, verbReaderOf }) => {
431
564
  const plugsOf = (source, builder) => {
432
565
  const verbOf = verbReaderOf(builder?.parameters[0]);
433
566
  return (returnedObject(builder)?.properties ?? []).flatMap((property) => {
@@ -440,27 +573,30 @@ var createFactReader = (ts, ast) => {
440
573
  return name && targetName ? [{ name, span: spanOf(source, property.name), target: targetName }] : [];
441
574
  });
442
575
  };
443
- const endpointKeysOf = (source, builder, made, model) => {
444
- const verbOf = verbReaderOf(builder?.parameters[0]);
445
- return (returnedObject(builder)?.properties ?? []).flatMap((property) => {
446
- if (!ts.isPropertyAssignment(property))
447
- return [];
448
- const name = ast.nodeName(property.name);
449
- if (!name)
450
- return [];
451
- const { root, methods } = chainOf(property.initializer);
452
- return [
453
- {
454
- name,
455
- span: spanOf(source, property.name),
456
- extent: extentOf(source, property),
457
- verb: root ? verbOf(root.expression) : null,
458
- guards: root ? guardsIn(source, optionObjectOf(root), made, `${model}.${name}`) : [],
459
- argCount: methods.filter((method) => argMethods.has(method)).length
460
- }
461
- ];
462
- });
576
+ const adaptorBindingsIn = (source) => {
577
+ const bindings = [];
578
+ const visit = (node) => {
579
+ if (ts.isCallExpression(node) && ts.isPropertyAccessExpression(node.expression) && node.expression.name.text === "applyAdaptor") {
580
+ const [role, adaptor] = node.arguments.map(guardNameOf);
581
+ if (role && adaptor)
582
+ bindings.push({ role, adaptor, span: spanOf(source, node.expression.name) });
583
+ }
584
+ ts.forEachChild(node, visit);
585
+ };
586
+ visit(source);
587
+ return bindings;
463
588
  };
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 }) => {
464
600
  const filterQueriesOf = (source, builder) => {
465
601
  const query = returnedObject(builder)?.properties.find((property) => ts.isPropertyAssignment(property) && ast.nodeName(property.name) === "query")?.initializer;
466
602
  return query && ts.isObjectLiteralExpression(query) ? objectKeys(source, query) : [];
@@ -498,48 +634,18 @@ var createFactReader = (ts, ast) => {
498
634
  return [];
499
635
  return list.elements.flatMap((element) => ts.isStringLiteralLike(element) ? [element.text] : []);
500
636
  };
501
- const methodsOf = (source, statement) => statement.members.flatMap((member) => {
502
- if (!ts.isMethodDeclaration(member) || !member.body)
503
- return [];
504
- const name = ast.nodeName(member.name);
505
- if (!name || ts.getModifiers(member)?.some(({ kind }) => kind === ts.SyntaxKind.StaticKeyword))
506
- return [];
507
- return [{ name, span: spanOf(source, member.name), extent: extentOf(source, member) }];
508
- });
509
- const importsOf = (statement) => {
510
- const { importClause, moduleSpecifier } = statement;
511
- if (!importClause || !ts.isStringLiteral(moduleSpecifier))
512
- return [];
513
- const from = moduleSpecifier.text;
514
- const bindings = importClause.namedBindings;
515
- return [
516
- ...importClause.name ? [{ name: importClause.name.text, imported: "default", from }] : [],
517
- ...bindings && ts.isNamespaceImport(bindings) ? [{ name: bindings.name.text, imported: "*", from }] : [],
518
- ...bindings && ts.isNamedImports(bindings) ? bindings.elements.map((element) => ({
519
- name: element.name.text,
520
- imported: (element.propertyName ?? element.name).text,
521
- from
522
- })) : []
523
- ];
524
- };
525
- const docOf = (source, node) => {
526
- const { text } = source;
527
- const ranges = ts.getLeadingCommentRanges(text, node.getFullStart()) ?? [];
528
- const comments = [];
529
- let end = node.getStart(source);
530
- for (const range of [...ranges].reverse()) {
531
- if ((text.slice(range.end, end).match(/\n/g)?.length ?? 0) > 1)
532
- break;
533
- comments.unshift(text.slice(range.pos, range.end));
534
- end = range.pos;
535
- }
536
- const lines = comments.flatMap((comment) => comment.split(`
537
- `)).map((line) => line.trim().replace(/^\/\*\*?|\*\/$/g, "").replace(/^(?:\/\/[?*!]?|\*)/, "").replace(/\{@link\s+([^}\s|]+)[^}]*\}/g, "$1").trim()).filter((line) => line && !/^(?:biome-ignore|eslint-|@ts-)/.test(line));
538
- return lines.length ? lines.join(" ") : null;
539
- };
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);
540
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);
541
648
  const lowerFirst = (text) => text.charAt(0).toLowerCase() + text.slice(1);
542
- const importsIn = (source) => source.statements.filter(ts.isImportDeclaration).flatMap(importsOf);
543
649
  const read = (source, owner) => {
544
650
  const imports = importsIn(source);
545
651
  const madeInPlace = [];
@@ -560,6 +666,7 @@ var createFactReader = (ts, ast) => {
560
666
  endpoints: [],
561
667
  internals: [],
562
668
  adaptors: [],
669
+ adaptorBindings: source.text.includes("applyAdaptor") ? adaptorBindingsIn(source) : [],
563
670
  stores: []
564
671
  };
565
672
  for (const statement of source.statements) {
@@ -584,7 +691,8 @@ var createFactReader = (ts, ast) => {
584
691
  ...name,
585
692
  model: moduleRefOf(call.arguments[0], "db"),
586
693
  methods: methodsOf(source, statement),
587
- plugs: plugsOf(source, builder)
694
+ plugs: plugsOf(source, builder),
695
+ fields: objectKeys(source, returnedObject(builder)).map(({ name }) => name)
588
696
  });
589
697
  else if (callee === "slice") {
590
698
  const model = moduleRefOf(call.arguments[0], "srv");
@@ -635,7 +743,11 @@ var frameworkOwner = "akanjs";
635
743
  var frameworkPattern = /^akanjs(?:\/|$)/;
636
744
  var aliasPattern = /^@(apps|libs)\/([^/]+)/;
637
745
  var maxMapDepth = 4;
746
+ var identifierPattern = /^[\p{ID_Start}$_][\p{ID_Continue}$\u200c\u200d]*$/u;
638
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$])`);
639
751
  var declaringPatternOf = (name, isAnyBinding) => {
640
752
  const escaped = escapeRegExp(name);
641
753
  const braced = "\\{(?:[^}]*?[\\s,])?";
@@ -657,8 +769,12 @@ class GuardResolver {
657
769
  #reexports = new Map;
658
770
  #declarations = new Map;
659
771
  #starExports = new Map;
772
+ #moduleExports = new Map;
773
+ #fileStars = new Map;
774
+ #starReach = new Map;
660
775
  #ownerFiles = null;
661
776
  #modules = null;
777
+ #barrels = null;
662
778
  constructor(source, routes) {
663
779
  this.#source = source;
664
780
  this.#routes = routes;
@@ -682,21 +798,26 @@ ${name}`);
682
798
  made: [],
683
799
  isReal: fact.direct,
684
800
  scope: fact.scope,
801
+ layers: fact.layers,
685
802
  targets: []
686
803
  };
687
804
  factories.set(fact.name, [...factories.get(fact.name) ?? [], factory]);
688
805
  declaredFactories.push(factory);
689
806
  }
690
807
  for (const factory of declaredFactories)
691
- 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
+ });
692
812
  for (let isGrowing = true;isGrowing; ) {
693
813
  isGrowing = false;
694
814
  for (const factory of declaredFactories) {
695
- const target = factory.targets.find((other) => other.isReal);
696
- if (factory.isReal || !target)
815
+ const via = factory.targets.find(({ target, layers }) => target.isReal && target.layers >= layers);
816
+ if (factory.isReal || !via)
697
817
  continue;
698
818
  factory.isReal = true;
699
- factory.scope ??= target.scope;
819
+ factory.layers = factory.fact.layers + via.target.layers - via.layers;
820
+ factory.scope ??= via.target.scope;
700
821
  isGrowing = true;
701
822
  }
702
823
  }
@@ -706,7 +827,7 @@ ${name}`);
706
827
  seen.add(factory);
707
828
  return [
708
829
  { fileName: factory.site.fileName, extent: factory.fact.extent },
709
- ...factory.targets.filter((target) => target.isReal).flatMap((target) => partsOf(target, seen))
830
+ ...factory.targets.filter(({ target }) => target.isReal).flatMap(({ target }) => partsOf(target, seen))
710
831
  ];
711
832
  };
712
833
  const declare = (file, made, scope, parts) => {
@@ -727,7 +848,7 @@ ${name}`, guard);
727
848
  const factory = made.factory ? factories.get(made.factory)?.find((other) => other.site.fileName === file.fileName) : undefined;
728
849
  if (!made.factory)
729
850
  declare(file, made, made.scope, []);
730
- else if (factory?.isReal)
851
+ else if (factory?.isReal && factory.layers === made.layers)
731
852
  factory.made.push(declare(file, made, factory.scope, partsOf(factory)));
732
853
  }
733
854
  for (const made of file.guardCalls) {
@@ -736,7 +857,7 @@ ${name}`, guard);
736
857
  continue;
737
858
  }
738
859
  const factory = this.#factoryAt(factories, made.callee, file);
739
- if (factory?.isReal)
860
+ if (factory?.isReal && factory.layers === made.layers)
740
861
  factory.made.push(declare(file, made, factory.scope, partsOf(factory)));
741
862
  }
742
863
  }
@@ -781,7 +902,7 @@ ${name}`, guard);
781
902
  const own = this.#nearest(candidates.filter((other) => other.owner === from), ({ site }) => site.fileName, near);
782
903
  if (own)
783
904
  return own;
784
- const reexport = from && depth < maxMapDepth ? this.reexportOf(from, name, near) : null;
905
+ const reexport = from && depth < maxMapDepth ? this.#reexportOf(from, name, near) : null;
785
906
  if (reexport)
786
907
  return this.#factoryAt(factories, reexport.local, reexport.site, depth + 1);
787
908
  return from && near ? this.#throughStar(candidates, from, name, near) : undefined;
@@ -819,13 +940,13 @@ ${name}`, guard);
819
940
  const visible = isBase ? undefined : declared.find((other) => this.visible(other.owner, site.owner));
820
941
  return visible ? { guard: visible } : { name, from };
821
942
  }
822
- const reexport = from && depth < maxMapDepth ? this.reexportOf(from, name, near) : null;
943
+ const reexport = from && depth < maxMapDepth ? this.#reexportOf(from, name, near) : null;
823
944
  if (reexport)
824
945
  return this.#findGuard(reexport.local, reexport.site, depth + 1, isBase);
825
946
  const reached = from && near ? this.#throughStar(declared, from, name, near) : undefined;
826
947
  return reached ? { guard: reached } : { name, from };
827
948
  }
828
- reexportOf(owner, name, near) {
949
+ #reexportOf(owner, name, near) {
829
950
  const key = `${owner}
830
951
  ${name}
831
952
  ${near ?? ""}`;
@@ -833,7 +954,7 @@ ${near ?? ""}`;
833
954
  if (cached !== undefined)
834
955
  return cached;
835
956
  let found = null;
836
- const exporting = new RegExp(`export\\s*\\{(?:[^}]*?[\\s,])?${escapeRegExp(name)}(?![\\w$])`);
957
+ const exporting = exportingPatternOf(name);
837
958
  for (const fileName of this.#filesOf(owner, name, near)) {
838
959
  const text = this.#source.readText(fileName);
839
960
  if (text === undefined || !exporting.test(text))
@@ -851,7 +972,7 @@ ${near ?? ""}`;
851
972
  this.#reexports.set(key, found);
852
973
  return found;
853
974
  }
854
- #reexportIn(source, name) {
975
+ #reexportIn(source, name, takesPackageDefault = false) {
855
976
  const { ts, reader } = this.#source;
856
977
  for (const statement of source.statements) {
857
978
  if (!ts.isExportDeclaration(statement) || statement.isTypeOnly)
@@ -868,7 +989,9 @@ ${near ?? ""}`;
868
989
  const imported = reader.importsIn(source).find((item) => item.name === original);
869
990
  if (!imported)
870
991
  return { name: original, from: null };
871
- 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 };
872
995
  }
873
996
  return null;
874
997
  }
@@ -877,7 +1000,9 @@ ${near ?? ""}`;
877
1000
  const relative = this.#source.relative(fileName);
878
1001
  return !!near && (relative.startsWith(`${near}/`) || relative.replace(/\.tsx?$/, "") === near);
879
1002
  };
880
- 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(`
881
1006
  ${name}
882
1007
  `)).map(([fileName]) => fileName);
883
1008
  return [...candidates.filter(isNear), ...candidates.filter((other) => !isNear(other))];
@@ -894,7 +1019,7 @@ ${owner ?? ""}`;
894
1019
  const entries = [];
895
1020
  const fileNames = [
896
1021
  ...fileName ? [fileName] : [],
897
- ...(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(`
898
1023
  ${objectName}
899
1024
  `) && words.includes(`
900
1025
  ${member}
@@ -968,30 +1093,120 @@ ${near ?? ""}`;
968
1093
  #throughStar(declared, owner, name, near) {
969
1094
  if (!declared.length)
970
1095
  return;
971
- const { owners, isOpaque } = this.#starExportsOf(owner, near);
1096
+ const { owners, isOpaque } = this.starExportsOf(owner, near);
972
1097
  const reached = declared.filter((other) => other.owner !== null && owners.includes(other.owner));
973
1098
  return reached.length === 1 && !isOpaque && !this.declares(owner, name) ? reached[0] : undefined;
974
1099
  }
975
- #starExportsOf(owner, near) {
976
- const cached = this.#starExports.get(near);
1100
+ starExportsOf(owner, near) {
1101
+ const key = `${owner}
1102
+ ${near}`;
1103
+ const cached = this.#starExports.get(key);
977
1104
  if (cached)
978
1105
  return cached;
979
- const found = { owners: [], isOpaque: false };
980
- this.#starExports.set(near, found);
981
- const paths = [near];
982
- for (let idx = 0;idx < paths.length && !found.isOpaque; idx++)
983
- for (const fileName of this.#modulesAt(paths[idx] ?? "")) {
984
- for (const [, specifier = ""] of this.#source.readText(fileName)?.matchAll(starExportPattern) ?? []) {
985
- const target = this.ownerOfSpecifier(fileName, specifier);
986
- const path = this.pathOfSpecifier(fileName, specifier);
987
- if (target === undefined || target === frameworkOwner || path === null)
988
- found.isOpaque = true;
989
- else if (!paths.includes(path))
990
- paths.push(path);
991
- if (target && target !== frameworkOwner && target !== owner && !found.owners.includes(target))
992
- found.owners.push(target);
993
- }
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);
994
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);
995
1210
  return found;
996
1211
  }
997
1212
  #modulesAt(path) {
@@ -1005,11 +1220,33 @@ ${near ?? ""}`;
1005
1220
  }
1006
1221
  return this.#modules.get(path) ?? [];
1007
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
+ }
1008
1241
  declares(owner, name) {
1009
1242
  const declaring = declaringPatternOf(name, true);
1010
1243
  return this.#filesOf(owner, name, null).some((fileName) => declaring.test(this.#source.readText(fileName) ?? ""));
1011
1244
  }
1012
- 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) {
1013
1250
  if (!this.#ownerFiles) {
1014
1251
  this.#ownerFiles = new Map;
1015
1252
  for (const entry of this.#source.files) {
@@ -1059,6 +1296,196 @@ ${near ?? ""}`;
1059
1296
  }
1060
1297
  }
1061
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 found = own === undefined && from !== frameworkOwner ? declared.find((adaptor) => this.#resolver.visible(adaptor.owner, holder)) : own;
1381
+ if (found)
1382
+ return found.id;
1383
+ const reexported = own === undefined && from && from !== frameworkOwner ? this.#packageShimOf(from, name, path) : null;
1384
+ if (reexported)
1385
+ return this.#packageAdaptorOf(reexported.name, reexported.from);
1386
+ const owner = from === frameworkOwner ? null : imported ? from ?? null : file.owner;
1387
+ const detail = from === frameworkOwner ? [frameworkOwner] : [];
1388
+ return this.#sink.addNode(this.#sink.key("adaptor", owner, name), "adaptor", owner, name, null, detail).id;
1389
+ }
1390
+ #adaptorIn(name, declared, owner, path, fileName) {
1391
+ const own = declared.filter((adaptor) => adaptor.owner === owner);
1392
+ const [first] = own;
1393
+ if (path === null)
1394
+ return own.find((adaptor) => adaptor.fileName === fileName) ?? first;
1395
+ if (own.length === 1)
1396
+ return first;
1397
+ const exported = this.#exportedAt(name, path).filter((item) => first || !isPackageExport(item));
1398
+ const [only] = exported;
1399
+ if (only)
1400
+ return exported.length === 1 && !("local" in only) ? only : null;
1401
+ return first ? null : undefined;
1402
+ }
1403
+ #exportedAt(name, path) {
1404
+ const key = `${path}
1405
+ ${name}`;
1406
+ const cached = this.#exported.get(key);
1407
+ if (cached)
1408
+ return cached;
1409
+ if (!this.#resolver.mentionsAlong(path, name)) {
1410
+ this.#exported.set(key, []);
1411
+ return [];
1412
+ }
1413
+ const reached = new Map;
1414
+ const seen = new Set;
1415
+ const pending = [[name, path]];
1416
+ for (let next = pending.pop();next; next = pending.pop()) {
1417
+ const [wanted, at] = next;
1418
+ if (seen.has(`${at}
1419
+ ${wanted}`))
1420
+ continue;
1421
+ seen.add(`${at}
1422
+ ${wanted}`);
1423
+ for (const item of this.#bindingAt(wanted, at, pending, name))
1424
+ reached.set(exportedKeyOf(item), item);
1425
+ }
1426
+ const found = [...reached.values()];
1427
+ this.#exported.set(key, found);
1428
+ return found;
1429
+ }
1430
+ #bindingAt(name, path, pending, plugged) {
1431
+ const here = this.#declaredAt(name, path);
1432
+ if (here.length)
1433
+ return here;
1434
+ const { named, stars, isLocal } = this.#resolver.exportsAt(path, name);
1435
+ if (isLocal)
1436
+ return [{ local: path }];
1437
+ if (named?.from === null) {
1438
+ const local = this.#declaredAt(named.name, path);
1439
+ return local.length ? local : [{ local: path }];
1440
+ }
1441
+ if (named) {
1442
+ const target = this.#resolver.pathOfSpecifier(named.fileName, named.from);
1443
+ if (target === null) {
1444
+ const exposed = named.name !== "default" ? named.name : name !== "default" ? name : plugged;
1445
+ return [{ name: exposed, from: named.from }];
1446
+ }
1447
+ pending.push([named.name, target]);
1448
+ return [];
1449
+ }
1450
+ for (const star of stars)
1451
+ pending.push([name, star]);
1452
+ return [];
1453
+ }
1454
+ #declaredAt(name, path) {
1455
+ return (this.#adaptors.get(name) ?? []).filter((adaptor) => {
1456
+ const module = this.#source.relative(adaptor.fileName).replace(/\.tsx?$/, "");
1457
+ return module === path || module === `${path}/index`;
1458
+ });
1459
+ }
1460
+ #packageAdaptorOf(name, specifier) {
1461
+ if (frameworkPattern.test(specifier))
1462
+ return this.#sink.addNode(this.#sink.key("adaptor", null, name), "adaptor", null, name, null, [frameworkOwner]).id;
1463
+ const pkg = packageOf(specifier);
1464
+ return this.#sink.addNode(this.#sink.key("adaptor", pkg, name), "adaptor", null, name, null, [pkg]).id;
1465
+ }
1466
+ #packageShimOf(owner, name, near) {
1467
+ if (!near)
1468
+ return null;
1469
+ const shims = this.#exportedAt(name, near).filter(isPackageExport);
1470
+ const [shim] = shims;
1471
+ if (shim)
1472
+ return shims.length === 1 ? shim : 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
+
1062
1489
  // pkgs/akanjs/common/trimSlashes.ts
1063
1490
  var trimTrailingSlashes = (value) => {
1064
1491
  let end = value.length;
@@ -1082,6 +1509,7 @@ var PAGE_ROUTE_EXPORTS = new Set([
1082
1509
  "guard"
1083
1510
  ]);
1084
1511
  var LAYOUT_ROUTE_EXPORTS = new Set([...PAGE_ROUTE_EXPORTS, "NotFound", "Error"]);
1512
+ var GENERATED_ROOT_LAYOUT_EXPORTS = new Set(["McpAppRoot", "LevelBoundary"]);
1085
1513
  var ROOT_LAYOUT_ROUTE_EXPORTS = new Set([
1086
1514
  ...LAYOUT_ROUTE_EXPORTS,
1087
1515
  "fonts",
@@ -1091,7 +1519,7 @@ var ROOT_LAYOUT_ROUTE_EXPORTS = new Set([
1091
1519
  "wsConnect",
1092
1520
  "layoutStyle",
1093
1521
  "viewport",
1094
- "McpAppRoot"
1522
+ ...GENERATED_ROOT_LAYOUT_EXPORTS
1095
1523
  ]);
1096
1524
  var RESERVED_ROUTE_CONFIG_EXPORTS = new Set([...ROOT_LAYOUT_ROUTE_EXPORTS].filter((name) => name !== "default" && !/^[A-Z]/.test(name)));
1097
1525
  function parseRouteModuleKey(key) {
@@ -1347,12 +1775,18 @@ class GraphBuilder {
1347
1775
  #routeFiles = new Map;
1348
1776
  #routes;
1349
1777
  #resolver;
1350
- #adaptors = new Map;
1351
- #plugs = new Map;
1778
+ #adaptors;
1352
1779
  constructor(source) {
1353
1780
  this.#source = source;
1354
1781
  this.#routes = new RouteFactReader(source.ts, source.reader, source.parse);
1355
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
+ });
1356
1790
  }
1357
1791
  build() {
1358
1792
  const { facts } = this.#source;
@@ -1364,16 +1798,7 @@ class GraphBuilder {
1364
1798
  ...[...constantsByOwner].filter(([key]) => key !== owner && key?.startsWith("libs/")).flatMap(([, list]) => list)
1365
1799
  ];
1366
1800
  const typed = [];
1367
- for (const file of facts)
1368
- for (const fact of file.adaptors) {
1369
- const declared = { fact, owner: file.owner, fileName: file.fileName };
1370
- this.#adaptors.set(fact.name, [...this.#adaptors.get(fact.name) ?? [], declared]);
1371
- this.#adaptorNodeOf(declared);
1372
- }
1373
- for (const file of facts)
1374
- for (const fact of file.adaptors)
1375
- for (const plug of fact.plugs)
1376
- this.#addEdge(this.#key("adaptor", file.owner, fact.name), this.#adaptorIdOf(plug.target, file), "plugs", plug.name, this.#location(plug.span));
1801
+ this.#adaptors.declare(facts);
1377
1802
  for (const guard of this.#resolver.declare(facts))
1378
1803
  this.#guardNodeOf(guard);
1379
1804
  for (const file of facts) {
@@ -1406,10 +1831,7 @@ class GraphBuilder {
1406
1831
  }
1407
1832
  for (const method of service.methods)
1408
1833
  this.#addMember("method", owner, refName, method, `${service.name}.${method.name}`, file.fileName);
1409
- for (const plug of service.plugs)
1410
- this.#plugs.set(`${owner ?? ""}
1411
- ${refName}
1412
- ${plug.name}`, this.#adaptorIdOf(plug.target, file));
1834
+ this.#adaptors.addService(refName, service, file);
1413
1835
  }
1414
1836
  for (const filter of file.filters) {
1415
1837
  if (!filter.name.endsWith("Filter"))
@@ -1665,28 +2087,6 @@ ${dir}`, node);
1665
2087
  this.#digest(node, text, extent);
1666
2088
  return node.id;
1667
2089
  }
1668
- #adaptorIdOf(local, file) {
1669
- const [head, member] = local.split(".");
1670
- const imported = file.imports.find((item) => item.name === head);
1671
- const from = imported ? this.#resolver.ownerOfSpecifier(file.fileName, imported.from) : undefined;
1672
- const name = member ?? (imported && imported.imported !== "default" && imported.imported !== "*" ? imported.imported : head);
1673
- const declared = this.#adaptors.get(name) ?? [];
1674
- const found = from === undefined ? declared.find((adaptor) => adaptor.owner === file.owner) ?? declared.find((adaptor) => this.#resolver.visible(adaptor.owner, file.owner)) : declared.find((adaptor) => adaptor.owner === from) ?? (from === frameworkOwner ? undefined : declared.find((adaptor) => this.#resolver.visible(adaptor.owner, from)));
1675
- if (found)
1676
- return this.#adaptorNodeOf(found);
1677
- const owner = from === frameworkOwner ? null : imported ? from ?? null : file.owner;
1678
- const detail = from === frameworkOwner ? [frameworkOwner] : [];
1679
- return this.#addNode(this.#key("adaptor", owner, name), "adaptor", owner, null, name, null, detail).id;
1680
- }
1681
- #adaptorNodeOf({ fact, owner, fileName }) {
1682
- const id = this.#key("adaptor", owner, fact.name);
1683
- const detail = fact.refName ? [fact.refName] : [];
1684
- const node = this.#addNode(id, "adaptor", owner, null, fact.name, fact.span, detail);
1685
- if (fact.doc && !node.doc)
1686
- node.doc = fact.doc;
1687
- this.#digest(node, this.#source.readText(fileName), fact.extent);
1688
- return node.id;
1689
- }
1690
2090
  #guardNodeOf({ name, owner, span, scope, doc, parts, file, label }) {
1691
2091
  const id = this.#key("guard", owner, file ? `${file}#${name}` : name);
1692
2092
  const node = this.#addNode(id, "guard", owner, null, name, span, scope ? [scope] : [], label ?? name);
@@ -1789,10 +2189,8 @@ st
1789
2189
  visit(source);
1790
2190
  }
1791
2191
  #link(fileName, source, identifier, chain, context, owner) {
1792
- const plugged = chain?.length === 2 && chain[0] === "this" && context.kind === "method" && this.#isServiceThis(identifier) ? this.#plugs.get(`${context.owner ?? ""}
1793
- ${context.module}
1794
- ${chain[1]}`) : undefined;
1795
- const resolved = plugged ? [plugged] : this.#source.resolve(fileName, identifier).map((target) => this.#targetNodeOf(target)).filter((id) => id !== null);
2192
+ const plugged = chain?.length === 2 && chain[0] === "this" && context.kind === "method" && this.#isServiceThis(identifier) ? this.#adaptors.pluggedOf(context.owner, context.module, chain[1]) : [];
2193
+ const resolved = plugged.length ? plugged : this.#source.resolve(fileName, identifier).map((target) => this.#targetNodeOf(target)).filter((id) => id !== null);
1796
2194
  const targets = resolved.length ? resolved : this.#plainTargetsOf(chain, identifier.text, context, owner);
1797
2195
  if (!targets.length)
1798
2196
  return;
@@ -2390,7 +2788,7 @@ var sourcePattern = /\.(constant|document|service|signal|store)\.ts$/;
2390
2788
  var dictionaryPattern = /\.dictionary\.ts$/;
2391
2789
  var srvkitPattern = /\/srvkit\//;
2392
2790
  var wordPattern = /[A-Za-z_$][\w$]*/g;
2393
- var identifierPattern = /^[A-Za-z_$][\w$]*$/;
2791
+ var identifierPattern2 = /^[A-Za-z_$][\w$]*$/;
2394
2792
  var stateReceivers = new Set(["use", "sel", "get", "do"]);
2395
2793
  var lensFamilies = new Set(["slice", "query", "formSetter", "storeState", "endpoint"]);
2396
2794
  var modellessFamilies = new Set(["query", "storeState", "endpoint"]);
@@ -2499,7 +2897,7 @@ ${[...new Set(text.match(wordPattern))].join(`
2499
2897
  }
2500
2898
  renameAt(givenName, offset, newKey, readText) {
2501
2899
  const sources = this.#sourceEntriesAt(pathOf(givenName), offset).filter((entry) => entry.renamed);
2502
- if (!sources.length || !identifierPattern.test(newKey))
2900
+ if (!sources.length || !identifierPattern2.test(newKey))
2503
2901
  return null;
2504
2902
  return [
2505
2903
  { span: sources[0].span, newText: newKey },
@@ -2527,6 +2925,8 @@ canPass
2527
2925
  adapt
2528
2926
  `) || words.includes(`
2529
2927
  dangerouslyAdapt
2928
+ `) || words.includes(`
2929
+ applyAdaptor
2530
2930
  `);
2531
2931
  }
2532
2932
  static #sourceKeyOf({ family, sourceKey, label, detail, span }) {