@akanjs/cli 3.2.0-rc.2 → 3.2.0-rc.20
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/.build-stamp +2 -1
- package/CodeAgent-faqv7t4g.js +11 -0
- package/{CodeTui-zyc7zaq6.js → CodeTui-vqck9tet.js} +822 -666
- package/README.ko.md +26 -1
- package/README.md +26 -1
- package/TunnelShare-bwe3ddv7.js +18 -0
- package/agent.command-p75jvgrd.js +56 -0
- package/akanCode.js +12 -12
- package/appExecutor-020cyesq.js +11 -0
- package/{application.command-vb278qnq.js → application.command-ta2knqxm.js} +72 -34
- package/{applicationBuildRunner-bqbyeg84.js → applicationBuildRunner-gkh82j2b.js} +18 -13
- package/buildBatch.proc.js +26 -11
- package/{cloud.command-ca777ee2.js → cloud.command-v3jhfvm5.js} +31 -28
- package/cloud.script-be9s1432.js +35 -0
- package/{code.command-j08txqcd.js → code.command-mh7dh1st.js} +14 -9
- package/{context.command-2fa6egp9.js → context.command-1ycfjkdd.js} +28 -23
- package/context.runner-333jkz86.js +34 -0
- package/{dependencyScanner-78sq8m4q.js → dependencyScanner-ge10gb52.js} +2 -2
- package/{devTui-w38ch13a.js → devTui-rf374y2w.js} +1 -1
- package/{fileSys-zpvt5gtf.js → fileSys-q22646yc.js} +1 -1
- package/{guideline.command-w6yqpdec.js → guideline.command-w1grfwh7.js} +9 -4
- package/guidelines/agentRule/agentRule.instruction.md +17 -5
- package/guidelines/akanApi/akanApi.instruction.md +3 -1
- package/guidelines/conventions/core.md +23 -5
- package/guidelines/conventions/rules/app.md +4 -1
- package/guidelines/conventions/rules/page.md +5 -0
- package/guidelines/errorCodes/errorCodes.instruction.md +158 -0
- package/guidelines/fieldRule/fieldRule.instruction.md +2 -1
- package/guidelines/mcpRule/mcpRule.instruction.md +74 -2
- package/guidelines/pageRule/pageRule.instruction.md +11 -1
- package/guidelines/runtimeRule/runtimeRule.instruction.md +7 -2
- package/guidelines/transportRule/transportRule.instruction.md +8 -1
- package/incrementalBuilder.proc.js +574 -410
- package/{index-c5ymqb05.js → index-013n6z7m.js} +12 -12
- package/{index-w15mg3km.js → index-0dm25wvf.js} +1 -1
- package/{index-8nbx607g.js → index-0hj82f9w.js} +136 -48
- package/{index-ebwkh7bt.js → index-1c0mjc2b.js} +25 -7
- package/{index-6h775rv3.js → index-1jk52ffq.js} +53 -12
- package/{index-hj6w4ka1.js → index-1p81ecbz.js} +1 -1
- package/{index-ygrdw6jw.js → index-1pjwsh2g.js} +65 -8
- package/{index-cbcwxp5v.js → index-22g3jq43.js} +9 -7
- package/{index-466z5931.js → index-2d9nm03s.js} +580 -364
- package/{index-0fj9ra3q.js → index-2k6mve6a.js} +18 -11
- package/{index-qd7xn2bk.js → index-2ny1e95c.js} +2 -2
- package/{index-j7p0jgaq.js → index-52w4jb87.js} +6 -6
- package/{index-e22zedc2.js → index-5h888r6j.js} +3 -3
- package/{index-7kmbqp0b.js → index-6pxmcaq8.js} +1 -1
- package/{index-xa0289eg.js → index-6zb17wcm.js} +16 -9
- package/{index-qgazn58x.js → index-7a07tdap.js} +50 -38
- package/{index-m5sg5spm.js → index-7ehdht84.js} +565 -187
- package/{index-y725zb1a.js → index-7v7tvgt7.js} +196 -168
- package/{index-pq5rjkch.js → index-88s746ns.js} +7 -2
- package/{index-r0a604h4.js → index-99kjwyma.js} +1 -1
- package/{index-2mrn1mrg.js → index-9f3reh2y.js} +1 -1
- package/{index-386canwe.js → index-9rv2zt48.js} +186 -121
- package/{index-wr9magsr.js → index-9zswcze5.js} +3 -3
- package/{index-xq97me1h.js → index-a41vv4cy.js} +811 -697
- package/{index-yf9wc28h.js → index-bejy9zyc.js} +1 -1
- package/{index-bdmgqzb5.js → index-bket1068.js} +58 -29
- package/{index-bns3wcpc.js → index-by2tvsq6.js} +1 -1
- package/{index-1cb9apzn.js → index-czf94w8c.js} +2 -2
- package/{index-65b6ms4c.js → index-d3178asw.js} +15 -11
- package/index-dss3ds74.js +127 -0
- package/{index-annxfpgz.js → index-eyfty8kk.js} +9 -9
- package/{index-ny2k80mv.js → index-ffa52fwf.js} +1 -1
- package/{index-8jpc5fqv.js → index-g7jgd4xs.js} +2 -2
- package/{index-abfbf01s.js → index-gwsesvqc.js} +2 -2
- package/{index-kcpk2d20.js → index-h1w4wqgd.js} +1474 -1139
- package/{index-j1hjb477.js → index-hp2c7xc2.js} +1 -1
- package/index-j4yvgfhr.js +70 -0
- package/{index-84c2pgak.js → index-jx2jcw1r.js} +89 -78
- package/{index-j6eeh5d7.js → index-knpm8sdm.js} +5 -5
- package/{index-2gees180.js → index-mpp4aas6.js} +62 -33
- package/index-na8r4a27.js +30 -0
- package/{index-0mqga3h9.js → index-nmxszh6x.js} +525 -440
- package/{index-35j83zkd.js → index-p5zh7pmc.js} +2 -2
- package/{index-20wvskt8.js → index-pt0agdck.js} +1 -1
- package/{index-htxck0pn.js → index-q444k260.js} +15 -10
- package/{index-wfmpxke3.js → index-qssq2d41.js} +2775 -3677
- package/{index-23860fej.js → index-rwgqba9p.js} +24 -9
- package/{index-v50xjbbe.js → index-t4d0ckde.js} +1 -1
- package/index-va90m8nd.js +25 -0
- package/index-vjbne22r.js +80 -0
- package/{index-djc5nxpy.js → index-w23tf30e.js} +6 -6
- package/{index-mvwvxgtd.js → index-wa01phm9.js} +289 -210
- package/{index-h7hehkw6.js → index-xczjdng6.js} +3 -1
- package/{index-vbhx60x5.js → index-xwe7y0gf.js} +2140 -2165
- package/index-ze48c0vd.js +788 -0
- package/{index-dk4g0x0d.js → index-zttyg7tg.js} +27 -16
- package/{index-ygdbn9jn.js → index-zyb0ebm4.js} +1 -1
- package/index.js +29 -24
- package/libExecutor-tq994592.js +10 -0
- package/{library.command-8d03a0pq.js → library.command-x219mhcx.js} +9 -4
- package/{localRegistry.command-vyv5k6t0.js → localRegistry.command-4p17wa9t.js} +30 -24
- package/{module.command-vy3kg965.js → module.command-tjthnvvr.js} +17 -8
- package/{package.command-qjh13rs9.js → package.command-c6df2hxx.js} +13 -8
- package/package.json +2 -2
- package/{page.command-t0nx1jat.js → page.command-gf06paq2.js} +9 -4
- package/{pipeline.command-2yjeas7m.js → pipeline.command-y07dgj9b.js} +14 -8
- package/pkgExecutor-stde3yc3.js +10 -0
- package/{primitive.command-8vm49279.js → primitive.command-0enfygxn.js} +13 -8
- package/{projectTypecheck-s9hhe5sa.js → projectTypecheck-mk8wefvd.js} +2 -1
- package/{prompter-qrwx1p17.js → prompter-qyggfhqd.js} +2 -2
- package/{quality.command-v76fev72.js → quality.command-dkbdztad.js} +23 -16
- package/{recipeScanner-4b69ybe0.js → recipeScanner-rrx69awy.js} +1 -1
- package/{repair.command-fp4m3w03.js → repair.command-g5vd95ax.js} +13 -8
- package/{routeSourceValidator-4h947v7c.js → routeSourceValidator-8n6j1vn7.js} +4 -2
- package/{scalar.command-hxe6try8.js → scalar.command-7909pg0d.js} +11 -6
- package/skills/akan-debug/SKILL.md +10 -3
- package/skills/akan-err/SKILL.md +7 -0
- package/skills/akan-mcp/SKILL.md +10 -1
- package/skills/akan-scaffold/SKILL.md +2 -2
- package/skills/akan-transport/SKILL.md +2 -0
- package/skills/akan-validate/SKILL.md +1 -0
- package/{subspace.command-q42n1844.js → subspace.command-at4jt1fb.js} +29 -23
- package/templates/biomeForm.ts +1 -1
- package/templates/env/_env.server.type.ts +1 -1
- package/templates/facetIndex/index.ts +2 -37
- package/templates/lib/sig.ts +0 -4
- package/templates/lib/useClient.ts +1 -1
- package/templates/workspaceRoot/AGENTS.md.template +2 -1
- package/{tunnel.command-22g11n0x.js → tunnel.command-91h92dwr.js} +17 -12
- package/{typeChecker-s640r6c0.js → typeChecker-bfrd1n9n.js} +1 -1
- package/typecheck.proc.js +6 -3
- package/{verify.command-rx43bha1.js → verify.command-pzky05ts.js} +26 -20
- package/{workflow.command-yg0d8mmq.js → workflow.command-mqqe4n12.js} +37 -19
- package/{workspace.command-fcfztvn5.js → workspace.command-y4rznvhx.js} +64 -53
- package/CodeAgent-6cpjtj25.js +0 -11
- package/TunnelShare-zkfkrw8w.js +0 -14
- package/agent.command-kf1g3nh4.js +0 -51
- package/cloud.script-agpxzq6j.js +0 -30
- package/context.runner-ftv8373t.js +0 -29
|
@@ -29,6 +29,9 @@ class AkanGraphDiff {
|
|
|
29
29
|
...head.edges.flatMap((edge) => !baseKeys.has(edgeKeyOf(edge)) ? [{ ...edge, change: "added" }] : marked.has(edge.from) || marked.has(edge.to) ? [edge] : []),
|
|
30
30
|
...base.edges.filter((edge) => !headKeys.has(edgeKeyOf(edge))).map((edge) => ({ ...edge, change: "removed" }))
|
|
31
31
|
];
|
|
32
|
+
const shown = new Set([...marked.keys(), ...edges.flatMap((edge) => [edge.from, edge.to])]);
|
|
33
|
+
const listed = new Set(edges.map(edgeKeyOf));
|
|
34
|
+
edges.push(...head.edges.filter((edge) => edge.kind === "binds" && shown.has(edge.from) && !listed.has(edgeKeyOf(edge))));
|
|
32
35
|
const context = edges.flatMap((edge) => [edge.from, edge.to]).filter((id) => !marked.has(id)).flatMap((id) => {
|
|
33
36
|
const node = headNodes.get(id) ?? baseNodes.get(id);
|
|
34
37
|
return node ? [node] : [];
|
|
@@ -107,6 +110,13 @@ ${at.file}` : null;
|
|
|
107
110
|
return node.fields ? { ...node, fields: node.fields.map(({ digest: _field, ...field }) => field) } : node;
|
|
108
111
|
}
|
|
109
112
|
}
|
|
113
|
+
// pkgs/@akanjs/language/guardResolver.ts
|
|
114
|
+
import { barrelFacetDirs, facetBarrelNamesOf } from "akanjs/common/facetBarrel.ts";
|
|
115
|
+
|
|
116
|
+
// pkgs/@akanjs/language/escapeRegExp.ts
|
|
117
|
+
var regExpSpecials = /[\\^$.*+?()[\]{}|]/g;
|
|
118
|
+
var escapeRegExp = (text) => text.replace(regExpSpecials, (special) => `\\${special}`);
|
|
119
|
+
|
|
110
120
|
// pkgs/@akanjs/language/guardFacts.ts
|
|
111
121
|
var guardLabelOf = (guard, labels) => {
|
|
112
122
|
const [, role = null, local = guard] = guard.match(/^([\w$]+) (.+)$/) ?? [];
|
|
@@ -114,6 +124,7 @@ var guardLabelOf = (guard, labels) => {
|
|
|
114
124
|
return label === undefined ? guard : role ? `${role} ${label}` : label;
|
|
115
125
|
};
|
|
116
126
|
var maxLabelArgs = 32;
|
|
127
|
+
var maxLayers = 4;
|
|
117
128
|
var guardRefReaderOf = (ts, ast, unwrap) => {
|
|
118
129
|
const pathOf = (expression) => {
|
|
119
130
|
if (ts.isIdentifier(expression))
|
|
@@ -123,10 +134,19 @@ var guardRefReaderOf = (ts, ast, unwrap) => {
|
|
|
123
134
|
const head = pathOf(expression.expression);
|
|
124
135
|
return head && `${head}.${expression.name.text}`;
|
|
125
136
|
};
|
|
126
|
-
const
|
|
137
|
+
const layersOf = (call) => {
|
|
138
|
+
const inner = unwrap(call.expression);
|
|
139
|
+
if (!ts.isCallExpression(inner))
|
|
140
|
+
return { root: call, layers: 0 };
|
|
141
|
+
const { root, layers } = layersOf(inner);
|
|
142
|
+
return { root, layers: layers + 1 };
|
|
143
|
+
};
|
|
144
|
+
const calleeOf = (call) => pathOf(unwrap(layersOf(call).root.expression)) ?? "?";
|
|
127
145
|
const labelOf = (source, call) => {
|
|
128
146
|
const args = call.arguments.map((arg) => arg.getText(source)).join(", ");
|
|
129
|
-
|
|
147
|
+
const inner = unwrap(call.expression);
|
|
148
|
+
const head = ts.isCallExpression(inner) ? labelOf(source, inner) : pathOf(inner) ?? "?";
|
|
149
|
+
return `${head}(${args.length <= maxLabelArgs && !args.includes(`
|
|
130
150
|
`) ? args : "\u2026"})`;
|
|
131
151
|
};
|
|
132
152
|
const guardRefOf = (expression, made, member) => {
|
|
@@ -154,9 +174,9 @@ var guardRefReaderOf = (ts, ast, unwrap) => {
|
|
|
154
174
|
const single = refOf(guards);
|
|
155
175
|
return single ? [single] : [];
|
|
156
176
|
};
|
|
157
|
-
return { pathOf, labelOf, guardsIn };
|
|
177
|
+
return { pathOf, layersOf, labelOf, guardsIn };
|
|
158
178
|
};
|
|
159
|
-
var guardFactoryReaderOf = (ts, ast, { spanOf, extentOf, unwrap, docOf }, pathOf) => {
|
|
179
|
+
var guardFactoryReaderOf = (ts, ast, { spanOf, extentOf, unwrap, docOf }, pathOf, layersOf) => {
|
|
160
180
|
const implementsGuard = (node, guardNames) => !!node.heritageClauses?.some((clause) => clause.token === ts.SyntaxKind.ImplementsKeyword && clause.types.some(({ expression }) => guardNames.has(ast.expressionName(expression) ?? "")));
|
|
161
181
|
const scopeOf = (node) => {
|
|
162
182
|
const scope = node.members.find((member) => ts.isPropertyDeclaration(member) && ast.nodeName(member.name) === "scope" && !!ts.getModifiers(member)?.some(({ kind }) => kind === ts.SyntaxKind.StaticKeyword))?.initializer;
|
|
@@ -178,7 +198,7 @@ var guardFactoryReaderOf = (ts, ast, { spanOf, extentOf, unwrap, docOf }, pathOf
|
|
|
178
198
|
}
|
|
179
199
|
return functions;
|
|
180
200
|
};
|
|
181
|
-
const returnedOf = (body, guardNames) => {
|
|
201
|
+
const returnedOf = (body, guardNames, depth = 0) => {
|
|
182
202
|
const locals = new Map;
|
|
183
203
|
const pending = [];
|
|
184
204
|
const visit = (node) => {
|
|
@@ -199,6 +219,7 @@ var guardFactoryReaderOf = (ts, ast, { spanOf, extentOf, unwrap, docOf }, pathOf
|
|
|
199
219
|
const calls = [];
|
|
200
220
|
const seen = new Set;
|
|
201
221
|
const passed = new Set;
|
|
222
|
+
const returned = [];
|
|
202
223
|
for (let node = pending.pop();node; node = pending.pop()) {
|
|
203
224
|
if (seen.has(node))
|
|
204
225
|
continue;
|
|
@@ -206,6 +227,8 @@ var guardFactoryReaderOf = (ts, ast, { spanOf, extentOf, unwrap, docOf }, pathOf
|
|
|
206
227
|
const value = ts.isExpression(node) ? unwrap(node) : node;
|
|
207
228
|
if ((ts.isClassExpression(value) || ts.isClassDeclaration(value)) && implementsGuard(value, guardNames))
|
|
208
229
|
guard ??= value;
|
|
230
|
+
else if ((ts.isArrowFunction(value) || ts.isFunctionExpression(value)) && !passed.has(node) && depth < maxLayers)
|
|
231
|
+
returned.push(value.body);
|
|
209
232
|
else if (ts.isConditionalExpression(value))
|
|
210
233
|
pending.push(value.whenTrue, value.whenFalse);
|
|
211
234
|
else if (ts.isBinaryExpression(value))
|
|
@@ -215,15 +238,22 @@ var guardFactoryReaderOf = (ts, ast, { spanOf, extentOf, unwrap, docOf }, pathOf
|
|
|
215
238
|
if (local)
|
|
216
239
|
pending.push(local);
|
|
217
240
|
} else if (ts.isCallExpression(value)) {
|
|
218
|
-
const
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
241
|
+
const { root, layers } = layersOf(value);
|
|
242
|
+
const callee = pathOf(unwrap(root.expression));
|
|
243
|
+
if (callee && !passed.has(node) && !calls.some((call) => call.callee === callee))
|
|
244
|
+
calls.push({ callee, layers });
|
|
245
|
+
for (let call = value;ts.isCallExpression(call); call = unwrap(call.expression)) {
|
|
246
|
+
for (const arg of call.arguments)
|
|
247
|
+
passed.add(arg);
|
|
248
|
+
pending.push(...call.arguments);
|
|
249
|
+
}
|
|
224
250
|
}
|
|
225
251
|
}
|
|
226
|
-
|
|
252
|
+
const [inner] = returned;
|
|
253
|
+
if (guard || calls.length || !inner)
|
|
254
|
+
return { guard, calls, layers: 0 };
|
|
255
|
+
const nested = returnedOf(inner, guardNames, depth + 1);
|
|
256
|
+
return { ...nested, layers: nested.layers + 1 };
|
|
227
257
|
};
|
|
228
258
|
const guardFactoriesOf = (source, guardNames, isImported) => {
|
|
229
259
|
const functions = functionsOf(source);
|
|
@@ -233,7 +263,7 @@ var guardFactoryReaderOf = (ts, ast, { spanOf, extentOf, unwrap, docOf }, pathOf
|
|
|
233
263
|
for (let isGrowing = true;isGrowing; ) {
|
|
234
264
|
isGrowing = false;
|
|
235
265
|
for (const [name, { guard, calls }] of returned) {
|
|
236
|
-
if (members.has(name) || !guard && !calls.some(isFactoryCall))
|
|
266
|
+
if (members.has(name) || !guard && !calls.some(({ callee }) => isFactoryCall(callee)))
|
|
237
267
|
continue;
|
|
238
268
|
members.add(name);
|
|
239
269
|
isGrowing = true;
|
|
@@ -252,7 +282,8 @@ var guardFactoryReaderOf = (ts, ast, { spanOf, extentOf, unwrap, docOf }, pathOf
|
|
|
252
282
|
scope: made.guard ? scopeOf(made.guard) : null,
|
|
253
283
|
doc: docOf(source, found.statement),
|
|
254
284
|
direct: !!made.guard,
|
|
255
|
-
via: made.calls.filter(isFactoryCall)
|
|
285
|
+
via: made.calls.filter(({ callee }) => isFactoryCall(callee)),
|
|
286
|
+
layers: made.layers
|
|
256
287
|
});
|
|
257
288
|
}
|
|
258
289
|
return factories;
|
|
@@ -261,8 +292,8 @@ var guardFactoryReaderOf = (ts, ast, { spanOf, extentOf, unwrap, docOf }, pathOf
|
|
|
261
292
|
};
|
|
262
293
|
var createGuardFactReader = (ts, ast, base) => {
|
|
263
294
|
const { spanOf, extentOf, unwrap, docOf } = base;
|
|
264
|
-
const { pathOf, labelOf, guardsIn } = guardRefReaderOf(ts, ast, unwrap);
|
|
265
|
-
const { implementsGuard, scopeOf, guardFactoriesOf } = guardFactoryReaderOf(ts, ast, base, pathOf);
|
|
295
|
+
const { pathOf, layersOf, labelOf, guardsIn } = guardRefReaderOf(ts, ast, unwrap);
|
|
296
|
+
const { implementsGuard, scopeOf, guardFactoriesOf } = guardFactoryReaderOf(ts, ast, base, pathOf, layersOf);
|
|
266
297
|
const guardsOf = (source, imports, madeInPlace) => {
|
|
267
298
|
const guardNames = new Set([
|
|
268
299
|
"Guard",
|
|
@@ -275,15 +306,16 @@ var createGuardFactReader = (ts, ast, base) => {
|
|
|
275
306
|
const calls = [];
|
|
276
307
|
const makeOf = (made, value, isInPlace = false) => {
|
|
277
308
|
if (ts.isClassExpression(value) && implementsGuard(value, guardNames)) {
|
|
278
|
-
guards.push({ ...made, scope: scopeOf(value), factory: null });
|
|
309
|
+
guards.push({ ...made, scope: scopeOf(value), factory: null, layers: 0 });
|
|
279
310
|
return;
|
|
280
311
|
}
|
|
281
|
-
const
|
|
312
|
+
const { root, layers } = ts.isCallExpression(value) ? layersOf(value) : { root: null, layers: 0 };
|
|
313
|
+
const callee = root && pathOf(unwrap(root.expression));
|
|
282
314
|
const factory = callee && factories.get(callee);
|
|
283
315
|
if (factory)
|
|
284
|
-
guards.push({ ...made, scope: factory.scope, factory: factory.name });
|
|
316
|
+
guards.push({ ...made, scope: factory.scope, factory: factory.name, layers });
|
|
285
317
|
else if (callee && (isImported(callee) || isInPlace))
|
|
286
|
-
calls.push({ ...made, callee, kind: "call", scope: null });
|
|
318
|
+
calls.push({ ...made, callee, kind: "call", scope: null, layers });
|
|
287
319
|
};
|
|
288
320
|
for (const statement of source.statements) {
|
|
289
321
|
if (ts.isClassDeclaration(statement) && statement.name) {
|
|
@@ -297,9 +329,9 @@ var createGuardFactReader = (ts, ast, base) => {
|
|
|
297
329
|
const base = statement.heritageClauses?.find(({ token }) => token === ts.SyntaxKind.ExtendsKeyword)?.types[0];
|
|
298
330
|
const callee = base && pathOf(base.expression);
|
|
299
331
|
if (implementsGuard(statement, guardNames))
|
|
300
|
-
guards.push({ ...declared, factory: null });
|
|
332
|
+
guards.push({ ...declared, factory: null, layers: 0 });
|
|
301
333
|
else if (callee)
|
|
302
|
-
calls.push({ ...declared, callee, kind: "extends" });
|
|
334
|
+
calls.push({ ...declared, callee, kind: "extends", layers: 0 });
|
|
303
335
|
}
|
|
304
336
|
if (!ts.isVariableStatement(statement))
|
|
305
337
|
continue;
|
|
@@ -336,10 +368,6 @@ var createGuardFactReader = (ts, ast, base) => {
|
|
|
336
368
|
return { guardsIn, guardsOf };
|
|
337
369
|
};
|
|
338
370
|
|
|
339
|
-
// pkgs/@akanjs/language/escapeRegExp.ts
|
|
340
|
-
var regExpSpecials = /[\\^$.*+?()[\]{}|]/g;
|
|
341
|
-
var escapeRegExp = (text) => text.replace(regExpSpecials, (special) => `\\${special}`);
|
|
342
|
-
|
|
343
371
|
// pkgs/@akanjs/language/moduleFacts.ts
|
|
344
372
|
var testFilePattern = /\.(?:test|spec)\.tsx?$/;
|
|
345
373
|
var moduleCallees = new Set([
|
|
@@ -366,7 +394,7 @@ var ownerOf = (relativePath) => {
|
|
|
366
394
|
const [root, name] = relativePath.split("/");
|
|
367
395
|
return (root === "apps" || root === "libs") && name ? `${root}/${name}` : null;
|
|
368
396
|
};
|
|
369
|
-
var
|
|
397
|
+
var syntaxReaderOf = (ts, ast) => {
|
|
370
398
|
const spanOf = (source, node) => {
|
|
371
399
|
const start = node.getStart(source);
|
|
372
400
|
const end = node.getEnd();
|
|
@@ -424,6 +452,74 @@ var createFactReader = (ts, ast) => {
|
|
|
424
452
|
const node = keyName(property);
|
|
425
453
|
return name && node ? [{ name, span: spanOf(source, node), extent: extentOf(source, property) }] : [];
|
|
426
454
|
});
|
|
455
|
+
const verbReaderOf = (parameter) => {
|
|
456
|
+
const verbs = new Map;
|
|
457
|
+
if (parameter && ts.isObjectBindingPattern(parameter.name))
|
|
458
|
+
for (const element of parameter.name.elements) {
|
|
459
|
+
const verb = element.propertyName ?? element.name;
|
|
460
|
+
if (ts.isIdentifier(verb) && ts.isIdentifier(element.name))
|
|
461
|
+
verbs.set(element.name.text, verb.text);
|
|
462
|
+
}
|
|
463
|
+
const holder = parameter && ts.isIdentifier(parameter.name) ? parameter.name.text : null;
|
|
464
|
+
return (callee) => {
|
|
465
|
+
if (callee && ts.isIdentifier(callee))
|
|
466
|
+
return verbs.get(callee.text) ?? null;
|
|
467
|
+
if (callee && ts.isPropertyAccessExpression(callee) && ts.isIdentifier(callee.expression) && callee.expression.text === holder)
|
|
468
|
+
return callee.name.text;
|
|
469
|
+
return null;
|
|
470
|
+
};
|
|
471
|
+
};
|
|
472
|
+
return {
|
|
473
|
+
spanOf,
|
|
474
|
+
extentOf,
|
|
475
|
+
unwrap,
|
|
476
|
+
moduleRefOf,
|
|
477
|
+
returnedObject,
|
|
478
|
+
builderOf,
|
|
479
|
+
guardNameOf,
|
|
480
|
+
optionObjectOf,
|
|
481
|
+
chainOf,
|
|
482
|
+
keyName,
|
|
483
|
+
objectKeys,
|
|
484
|
+
verbReaderOf
|
|
485
|
+
};
|
|
486
|
+
};
|
|
487
|
+
var sourceReaderOf = (ts) => {
|
|
488
|
+
const importsOf = (statement) => {
|
|
489
|
+
const { importClause, moduleSpecifier } = statement;
|
|
490
|
+
if (!importClause || !ts.isStringLiteral(moduleSpecifier))
|
|
491
|
+
return [];
|
|
492
|
+
const from = moduleSpecifier.text;
|
|
493
|
+
const bindings = importClause.namedBindings;
|
|
494
|
+
return [
|
|
495
|
+
...importClause.name ? [{ name: importClause.name.text, imported: "default", from }] : [],
|
|
496
|
+
...bindings && ts.isNamespaceImport(bindings) ? [{ name: bindings.name.text, imported: "*", from }] : [],
|
|
497
|
+
...bindings && ts.isNamedImports(bindings) ? bindings.elements.map((element) => ({
|
|
498
|
+
name: element.name.text,
|
|
499
|
+
imported: (element.propertyName ?? element.name).text,
|
|
500
|
+
from
|
|
501
|
+
})) : []
|
|
502
|
+
];
|
|
503
|
+
};
|
|
504
|
+
const docOf = (source, node) => {
|
|
505
|
+
const { text } = source;
|
|
506
|
+
const ranges = ts.getLeadingCommentRanges(text, node.getFullStart()) ?? [];
|
|
507
|
+
const comments = [];
|
|
508
|
+
let end = node.getStart(source);
|
|
509
|
+
for (const range of [...ranges].reverse()) {
|
|
510
|
+
if ((text.slice(range.end, end).match(/\n/g)?.length ?? 0) > 1)
|
|
511
|
+
break;
|
|
512
|
+
comments.unshift(text.slice(range.pos, range.end));
|
|
513
|
+
end = range.pos;
|
|
514
|
+
}
|
|
515
|
+
const lines = comments.flatMap((comment) => comment.split(`
|
|
516
|
+
`)).map((line) => line.trim().replace(/^\/\*\*?|\*\/$/g, "").replace(/^(?:\/\/[?*!]?|\*)/, "").replace(/\{@link\s+([^}\s|]+)[^}]*\}/g, "$1").trim()).filter((line) => line && !/^(?:biome-ignore|eslint-|@ts-)/.test(line));
|
|
517
|
+
return lines.length ? lines.join(" ") : null;
|
|
518
|
+
};
|
|
519
|
+
const importsIn = (source) => source.statements.filter(ts.isImportDeclaration).flatMap(importsOf);
|
|
520
|
+
return { docOf, importsIn };
|
|
521
|
+
};
|
|
522
|
+
var signalKeyReaderOf = (ts, ast, { spanOf, extentOf, returnedObject, optionObjectOf, chainOf, verbReaderOf }, guardsIn) => {
|
|
427
523
|
const sliceKeysOf = (source, builder, made, model) => (returnedObject(builder)?.properties ?? []).flatMap((property) => {
|
|
428
524
|
if (!ts.isPropertyAssignment(property))
|
|
429
525
|
return [];
|
|
@@ -442,23 +538,30 @@ var createFactReader = (ts, ast) => {
|
|
|
442
538
|
}
|
|
443
539
|
];
|
|
444
540
|
});
|
|
445
|
-
const
|
|
446
|
-
const
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
541
|
+
const endpointKeysOf = (source, builder, made, model) => {
|
|
542
|
+
const verbOf = verbReaderOf(builder?.parameters[0]);
|
|
543
|
+
return (returnedObject(builder)?.properties ?? []).flatMap((property) => {
|
|
544
|
+
if (!ts.isPropertyAssignment(property))
|
|
545
|
+
return [];
|
|
546
|
+
const name = ast.nodeName(property.name);
|
|
547
|
+
if (!name)
|
|
548
|
+
return [];
|
|
549
|
+
const { root, methods } = chainOf(property.initializer);
|
|
550
|
+
return [
|
|
551
|
+
{
|
|
552
|
+
name,
|
|
553
|
+
span: spanOf(source, property.name),
|
|
554
|
+
extent: extentOf(source, property),
|
|
555
|
+
verb: root ? verbOf(root.expression) : null,
|
|
556
|
+
guards: root ? guardsIn(source, optionObjectOf(root), made, `${model}.${name}`) : [],
|
|
557
|
+
argCount: methods.filter((method) => argMethods.has(method)).length
|
|
558
|
+
}
|
|
559
|
+
];
|
|
560
|
+
});
|
|
461
561
|
};
|
|
562
|
+
return { sliceKeysOf, endpointKeysOf };
|
|
563
|
+
};
|
|
564
|
+
var jobKeyReaderOf = (ts, ast, { spanOf, extentOf, unwrap, returnedObject, chainOf, verbReaderOf }) => {
|
|
462
565
|
const numberOf = (expression) => {
|
|
463
566
|
const value = unwrap(expression);
|
|
464
567
|
if (ts.isNumericLiteral(value))
|
|
@@ -486,7 +589,7 @@ var createFactReader = (ts, ast) => {
|
|
|
486
589
|
const [size, unit] = intervalUnits.find(([size]) => ms >= size && ms % size === 0) ?? [1, "ms"];
|
|
487
590
|
return `${ms / size}${unit}`;
|
|
488
591
|
};
|
|
489
|
-
const modesOf = (option) => {
|
|
592
|
+
const modesOf = (option, type) => {
|
|
490
593
|
const object = option && unwrap(option);
|
|
491
594
|
if (!object || !ts.isObjectLiteralExpression(object))
|
|
492
595
|
return [];
|
|
@@ -496,9 +599,9 @@ var createFactReader = (ts, ast) => {
|
|
|
496
599
|
if (name === "enabled")
|
|
497
600
|
return value.kind === ts.SyntaxKind.FalseKeyword ? ["disabled"] : [];
|
|
498
601
|
if (name === "once")
|
|
499
|
-
return value.kind === ts.SyntaxKind.TrueKeyword ? ["once"] : [];
|
|
602
|
+
return type === "initialize" && value.kind === ts.SyntaxKind.TrueKeyword ? ["once"] : [];
|
|
500
603
|
if (name === "lock")
|
|
501
|
-
return value.kind === ts.SyntaxKind.FalseKeyword ? ["unlocked"] : [];
|
|
604
|
+
return type === "interval" && value.kind === ts.SyntaxKind.FalseKeyword ? ["unlocked"] : [];
|
|
502
605
|
if (name !== "serverMode" && name !== "operationMode")
|
|
503
606
|
return [];
|
|
504
607
|
const values = ts.isArrayLiteralExpression(value) ? [...value.elements] : [value];
|
|
@@ -516,7 +619,8 @@ var createFactReader = (ts, ast) => {
|
|
|
516
619
|
const { root } = chainOf(property.initializer);
|
|
517
620
|
const type = root ? verbOf(root.expression) : null;
|
|
518
621
|
const [first, second] = root?.arguments ?? [];
|
|
519
|
-
const
|
|
622
|
+
const cron = type === "cron" && first ? unwrap(first) : null;
|
|
623
|
+
const schedule = cron ? ts.isStringLiteralLike(cron) ? cron.text : cron.getText(source) : type === "interval" || type === "timeout" ? durationOf(first, source) : null;
|
|
520
624
|
const option = type === "initialize" || type === "destroy" ? first : second;
|
|
521
625
|
return [
|
|
522
626
|
{
|
|
@@ -525,11 +629,14 @@ var createFactReader = (ts, ast) => {
|
|
|
525
629
|
extent: extentOf(source, property),
|
|
526
630
|
type,
|
|
527
631
|
schedule,
|
|
528
|
-
modes: modesOf(option)
|
|
632
|
+
modes: modesOf(option, type)
|
|
529
633
|
}
|
|
530
634
|
];
|
|
531
635
|
});
|
|
532
636
|
};
|
|
637
|
+
return { internalKeysOf };
|
|
638
|
+
};
|
|
639
|
+
var serviceReaderOf = (ts, ast, { spanOf, extentOf, returnedObject, guardNameOf, chainOf, verbReaderOf }) => {
|
|
533
640
|
const plugsOf = (source, builder) => {
|
|
534
641
|
const verbOf = verbReaderOf(builder?.parameters[0]);
|
|
535
642
|
return (returnedObject(builder)?.properties ?? []).flatMap((property) => {
|
|
@@ -542,27 +649,30 @@ var createFactReader = (ts, ast) => {
|
|
|
542
649
|
return name && targetName ? [{ name, span: spanOf(source, property.name), target: targetName }] : [];
|
|
543
650
|
});
|
|
544
651
|
};
|
|
545
|
-
const
|
|
546
|
-
const
|
|
547
|
-
|
|
548
|
-
if (
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
span: spanOf(source, property.name),
|
|
558
|
-
extent: extentOf(source, property),
|
|
559
|
-
verb: root ? verbOf(root.expression) : null,
|
|
560
|
-
guards: root ? guardsIn(source, optionObjectOf(root), made, `${model}.${name}`) : [],
|
|
561
|
-
argCount: methods.filter((method) => argMethods.has(method)).length
|
|
562
|
-
}
|
|
563
|
-
];
|
|
564
|
-
});
|
|
652
|
+
const adaptorBindingsIn = (source) => {
|
|
653
|
+
const bindings = [];
|
|
654
|
+
const visit = (node) => {
|
|
655
|
+
if (ts.isCallExpression(node) && ts.isPropertyAccessExpression(node.expression) && node.expression.name.text === "applyAdaptor") {
|
|
656
|
+
const [role, adaptor] = node.arguments.map(guardNameOf);
|
|
657
|
+
if (role && adaptor)
|
|
658
|
+
bindings.push({ role, adaptor, span: spanOf(source, node.expression.name) });
|
|
659
|
+
}
|
|
660
|
+
ts.forEachChild(node, visit);
|
|
661
|
+
};
|
|
662
|
+
visit(source);
|
|
663
|
+
return bindings;
|
|
565
664
|
};
|
|
665
|
+
const methodsOf = (source, statement) => statement.members.flatMap((member) => {
|
|
666
|
+
if (!ts.isMethodDeclaration(member) || !member.body)
|
|
667
|
+
return [];
|
|
668
|
+
const name = ast.nodeName(member.name);
|
|
669
|
+
if (!name || ts.getModifiers(member)?.some(({ kind }) => kind === ts.SyntaxKind.StaticKeyword))
|
|
670
|
+
return [];
|
|
671
|
+
return [{ name, span: spanOf(source, member.name), extent: extentOf(source, member) }];
|
|
672
|
+
});
|
|
673
|
+
return { plugsOf, adaptorBindingsIn, methodsOf };
|
|
674
|
+
};
|
|
675
|
+
var constantReaderOf = (ts, ast, { spanOf, extentOf, unwrap, returnedObject, chainOf, keyName, objectKeys }) => {
|
|
566
676
|
const filterQueriesOf = (source, builder) => {
|
|
567
677
|
const query = returnedObject(builder)?.properties.find((property) => ts.isPropertyAssignment(property) && ast.nodeName(property.name) === "query")?.initializer;
|
|
568
678
|
return query && ts.isObjectLiteralExpression(query) ? objectKeys(source, query) : [];
|
|
@@ -600,48 +710,18 @@ var createFactReader = (ts, ast) => {
|
|
|
600
710
|
return [];
|
|
601
711
|
return list.elements.flatMap((element) => ts.isStringLiteralLike(element) ? [element.text] : []);
|
|
602
712
|
};
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
return [{ name, span: spanOf(source, member.name), extent: extentOf(source, member) }];
|
|
610
|
-
});
|
|
611
|
-
const importsOf = (statement) => {
|
|
612
|
-
const { importClause, moduleSpecifier } = statement;
|
|
613
|
-
if (!importClause || !ts.isStringLiteral(moduleSpecifier))
|
|
614
|
-
return [];
|
|
615
|
-
const from = moduleSpecifier.text;
|
|
616
|
-
const bindings = importClause.namedBindings;
|
|
617
|
-
return [
|
|
618
|
-
...importClause.name ? [{ name: importClause.name.text, imported: "default", from }] : [],
|
|
619
|
-
...bindings && ts.isNamespaceImport(bindings) ? [{ name: bindings.name.text, imported: "*", from }] : [],
|
|
620
|
-
...bindings && ts.isNamedImports(bindings) ? bindings.elements.map((element) => ({
|
|
621
|
-
name: element.name.text,
|
|
622
|
-
imported: (element.propertyName ?? element.name).text,
|
|
623
|
-
from
|
|
624
|
-
})) : []
|
|
625
|
-
];
|
|
626
|
-
};
|
|
627
|
-
const docOf = (source, node) => {
|
|
628
|
-
const { text } = source;
|
|
629
|
-
const ranges = ts.getLeadingCommentRanges(text, node.getFullStart()) ?? [];
|
|
630
|
-
const comments = [];
|
|
631
|
-
let end = node.getStart(source);
|
|
632
|
-
for (const range of [...ranges].reverse()) {
|
|
633
|
-
if ((text.slice(range.end, end).match(/\n/g)?.length ?? 0) > 1)
|
|
634
|
-
break;
|
|
635
|
-
comments.unshift(text.slice(range.pos, range.end));
|
|
636
|
-
end = range.pos;
|
|
637
|
-
}
|
|
638
|
-
const lines = comments.flatMap((comment) => comment.split(`
|
|
639
|
-
`)).map((line) => line.trim().replace(/^\/\*\*?|\*\/$/g, "").replace(/^(?:\/\/[?*!]?|\*)/, "").replace(/\{@link\s+([^}\s|]+)[^}]*\}/g, "$1").trim()).filter((line) => line && !/^(?:biome-ignore|eslint-|@ts-)/.test(line));
|
|
640
|
-
return lines.length ? lines.join(" ") : null;
|
|
641
|
-
};
|
|
713
|
+
return { constantOf, enumValuesOf, filterQueriesOf };
|
|
714
|
+
};
|
|
715
|
+
var createFactReader = (ts, ast) => {
|
|
716
|
+
const syntax = syntaxReaderOf(ts, ast);
|
|
717
|
+
const { spanOf, extentOf, unwrap, moduleRefOf, returnedObject, builderOf, chainOf, objectKeys } = syntax;
|
|
718
|
+
const { docOf, importsIn } = sourceReaderOf(ts);
|
|
642
719
|
const { guardsIn, guardsOf } = createGuardFactReader(ts, ast, { spanOf, extentOf, unwrap, docOf });
|
|
720
|
+
const { sliceKeysOf, endpointKeysOf } = signalKeyReaderOf(ts, ast, syntax, guardsIn);
|
|
721
|
+
const { internalKeysOf } = jobKeyReaderOf(ts, ast, syntax);
|
|
722
|
+
const { plugsOf, adaptorBindingsIn, methodsOf } = serviceReaderOf(ts, ast, syntax);
|
|
723
|
+
const { constantOf, enumValuesOf, filterQueriesOf } = constantReaderOf(ts, ast, syntax);
|
|
643
724
|
const lowerFirst = (text) => text.charAt(0).toLowerCase() + text.slice(1);
|
|
644
|
-
const importsIn = (source) => source.statements.filter(ts.isImportDeclaration).flatMap(importsOf);
|
|
645
725
|
const read = (source, owner) => {
|
|
646
726
|
const imports = importsIn(source);
|
|
647
727
|
const madeInPlace = [];
|
|
@@ -662,6 +742,7 @@ var createFactReader = (ts, ast) => {
|
|
|
662
742
|
endpoints: [],
|
|
663
743
|
internals: [],
|
|
664
744
|
adaptors: [],
|
|
745
|
+
adaptorBindings: source.text.includes("applyAdaptor") ? adaptorBindingsIn(source) : [],
|
|
665
746
|
stores: []
|
|
666
747
|
};
|
|
667
748
|
for (const statement of source.statements) {
|
|
@@ -686,7 +767,8 @@ var createFactReader = (ts, ast) => {
|
|
|
686
767
|
...name,
|
|
687
768
|
model: moduleRefOf(call.arguments[0], "db"),
|
|
688
769
|
methods: methodsOf(source, statement),
|
|
689
|
-
plugs: plugsOf(source, builder)
|
|
770
|
+
plugs: plugsOf(source, builder),
|
|
771
|
+
fields: objectKeys(source, returnedObject(builder)).map(({ name }) => name)
|
|
690
772
|
});
|
|
691
773
|
else if (callee === "slice") {
|
|
692
774
|
const model = moduleRefOf(call.arguments[0], "srv");
|
|
@@ -737,7 +819,11 @@ var frameworkOwner = "akanjs";
|
|
|
737
819
|
var frameworkPattern = /^akanjs(?:\/|$)/;
|
|
738
820
|
var aliasPattern = /^@(apps|libs)\/([^/]+)/;
|
|
739
821
|
var maxMapDepth = 4;
|
|
822
|
+
var identifierPattern = /^[\p{ID_Start}$_][\p{ID_Continue}$\u200c\u200d]*$/u;
|
|
740
823
|
var starExportPattern = /export\s*\*\s*from\s*["']([^"']+)["']/g;
|
|
824
|
+
var facetEntryPattern = new RegExp(`^((?:apps|libs)/[^/]+/(${barrelFacetDirs.map(escapeRegExp).join("|")}))/([^/]+)(/)?`);
|
|
825
|
+
var exportingPatternOf = (name) => new RegExp(`export\\s*\\{(?:[^}]*?[\\s,])?${escapeRegExp(name)}(?![\\w$])`);
|
|
826
|
+
var exportMentioningPatternOf = (name) => new RegExp(`export(?![\\w$])[^;]*?(?<![\\w$])${escapeRegExp(name)}(?![\\w$])`);
|
|
741
827
|
var declaringPatternOf = (name, isAnyBinding) => {
|
|
742
828
|
const escaped = escapeRegExp(name);
|
|
743
829
|
const braced = "\\{(?:[^}]*?[\\s,])?";
|
|
@@ -759,8 +845,12 @@ class GuardResolver {
|
|
|
759
845
|
#reexports = new Map;
|
|
760
846
|
#declarations = new Map;
|
|
761
847
|
#starExports = new Map;
|
|
848
|
+
#moduleExports = new Map;
|
|
849
|
+
#fileStars = new Map;
|
|
850
|
+
#starReach = new Map;
|
|
762
851
|
#ownerFiles = null;
|
|
763
852
|
#modules = null;
|
|
853
|
+
#barrels = null;
|
|
764
854
|
constructor(source, routes) {
|
|
765
855
|
this.#source = source;
|
|
766
856
|
this.#routes = routes;
|
|
@@ -784,21 +874,26 @@ ${name}`);
|
|
|
784
874
|
made: [],
|
|
785
875
|
isReal: fact.direct,
|
|
786
876
|
scope: fact.scope,
|
|
877
|
+
layers: fact.layers,
|
|
787
878
|
targets: []
|
|
788
879
|
};
|
|
789
880
|
factories.set(fact.name, [...factories.get(fact.name) ?? [], factory]);
|
|
790
881
|
declaredFactories.push(factory);
|
|
791
882
|
}
|
|
792
883
|
for (const factory of declaredFactories)
|
|
793
|
-
factory.targets = factory.fact.via.
|
|
884
|
+
factory.targets = factory.fact.via.flatMap(({ callee, layers }) => {
|
|
885
|
+
const target = this.#factoryAt(factories, callee, factory.site);
|
|
886
|
+
return target ? [{ target, layers }] : [];
|
|
887
|
+
});
|
|
794
888
|
for (let isGrowing = true;isGrowing; ) {
|
|
795
889
|
isGrowing = false;
|
|
796
890
|
for (const factory of declaredFactories) {
|
|
797
|
-
const
|
|
798
|
-
if (factory.isReal || !
|
|
891
|
+
const via = factory.targets.find(({ target, layers }) => target.isReal && target.layers >= layers);
|
|
892
|
+
if (factory.isReal || !via)
|
|
799
893
|
continue;
|
|
800
894
|
factory.isReal = true;
|
|
801
|
-
factory.
|
|
895
|
+
factory.layers = factory.fact.layers + via.target.layers - via.layers;
|
|
896
|
+
factory.scope ??= via.target.scope;
|
|
802
897
|
isGrowing = true;
|
|
803
898
|
}
|
|
804
899
|
}
|
|
@@ -808,7 +903,7 @@ ${name}`);
|
|
|
808
903
|
seen.add(factory);
|
|
809
904
|
return [
|
|
810
905
|
{ fileName: factory.site.fileName, extent: factory.fact.extent },
|
|
811
|
-
...factory.targets.filter((target) => target.isReal).flatMap((target) => partsOf(target, seen))
|
|
906
|
+
...factory.targets.filter(({ target }) => target.isReal).flatMap(({ target }) => partsOf(target, seen))
|
|
812
907
|
];
|
|
813
908
|
};
|
|
814
909
|
const declare = (file, made, scope, parts) => {
|
|
@@ -829,7 +924,7 @@ ${name}`, guard);
|
|
|
829
924
|
const factory = made.factory ? factories.get(made.factory)?.find((other) => other.site.fileName === file.fileName) : undefined;
|
|
830
925
|
if (!made.factory)
|
|
831
926
|
declare(file, made, made.scope, []);
|
|
832
|
-
else if (factory?.isReal)
|
|
927
|
+
else if (factory?.isReal && factory.layers === made.layers)
|
|
833
928
|
factory.made.push(declare(file, made, factory.scope, partsOf(factory)));
|
|
834
929
|
}
|
|
835
930
|
for (const made of file.guardCalls) {
|
|
@@ -838,7 +933,7 @@ ${name}`, guard);
|
|
|
838
933
|
continue;
|
|
839
934
|
}
|
|
840
935
|
const factory = this.#factoryAt(factories, made.callee, file);
|
|
841
|
-
if (factory?.isReal)
|
|
936
|
+
if (factory?.isReal && factory.layers === made.layers)
|
|
842
937
|
factory.made.push(declare(file, made, factory.scope, partsOf(factory)));
|
|
843
938
|
}
|
|
844
939
|
}
|
|
@@ -883,7 +978,7 @@ ${name}`, guard);
|
|
|
883
978
|
const own = this.#nearest(candidates.filter((other) => other.owner === from), ({ site }) => site.fileName, near);
|
|
884
979
|
if (own)
|
|
885
980
|
return own;
|
|
886
|
-
const reexport = from && depth < maxMapDepth ? this
|
|
981
|
+
const reexport = from && depth < maxMapDepth ? this.#reexportOf(from, name, near) : null;
|
|
887
982
|
if (reexport)
|
|
888
983
|
return this.#factoryAt(factories, reexport.local, reexport.site, depth + 1);
|
|
889
984
|
return from && near ? this.#throughStar(candidates, from, name, near) : undefined;
|
|
@@ -921,13 +1016,13 @@ ${name}`, guard);
|
|
|
921
1016
|
const visible = isBase ? undefined : declared.find((other) => this.visible(other.owner, site.owner));
|
|
922
1017
|
return visible ? { guard: visible } : { name, from };
|
|
923
1018
|
}
|
|
924
|
-
const reexport = from && depth < maxMapDepth ? this
|
|
1019
|
+
const reexport = from && depth < maxMapDepth ? this.#reexportOf(from, name, near) : null;
|
|
925
1020
|
if (reexport)
|
|
926
1021
|
return this.#findGuard(reexport.local, reexport.site, depth + 1, isBase);
|
|
927
1022
|
const reached = from && near ? this.#throughStar(declared, from, name, near) : undefined;
|
|
928
1023
|
return reached ? { guard: reached } : { name, from };
|
|
929
1024
|
}
|
|
930
|
-
reexportOf(owner, name, near) {
|
|
1025
|
+
#reexportOf(owner, name, near) {
|
|
931
1026
|
const key = `${owner}
|
|
932
1027
|
${name}
|
|
933
1028
|
${near ?? ""}`;
|
|
@@ -935,7 +1030,7 @@ ${near ?? ""}`;
|
|
|
935
1030
|
if (cached !== undefined)
|
|
936
1031
|
return cached;
|
|
937
1032
|
let found = null;
|
|
938
|
-
const exporting =
|
|
1033
|
+
const exporting = exportingPatternOf(name);
|
|
939
1034
|
for (const fileName of this.#filesOf(owner, name, near)) {
|
|
940
1035
|
const text = this.#source.readText(fileName);
|
|
941
1036
|
if (text === undefined || !exporting.test(text))
|
|
@@ -953,7 +1048,7 @@ ${near ?? ""}`;
|
|
|
953
1048
|
this.#reexports.set(key, found);
|
|
954
1049
|
return found;
|
|
955
1050
|
}
|
|
956
|
-
#reexportIn(source, name) {
|
|
1051
|
+
#reexportIn(source, name, takesPackageDefault = false) {
|
|
957
1052
|
const { ts, reader } = this.#source;
|
|
958
1053
|
for (const statement of source.statements) {
|
|
959
1054
|
if (!ts.isExportDeclaration(statement) || statement.isTypeOnly)
|
|
@@ -970,7 +1065,9 @@ ${near ?? ""}`;
|
|
|
970
1065
|
const imported = reader.importsIn(source).find((item) => item.name === original);
|
|
971
1066
|
if (!imported)
|
|
972
1067
|
return { name: original, from: null };
|
|
973
|
-
|
|
1068
|
+
if (imported.imported === "default")
|
|
1069
|
+
return takesPackageDefault && this.pathOfSpecifier(source.fileName, imported.from) === null ? { name: "default", from: imported.from } : null;
|
|
1070
|
+
return imported.imported === "*" ? null : { name: imported.imported, from: imported.from };
|
|
974
1071
|
}
|
|
975
1072
|
return null;
|
|
976
1073
|
}
|
|
@@ -979,7 +1076,9 @@ ${near ?? ""}`;
|
|
|
979
1076
|
const relative = this.#source.relative(fileName);
|
|
980
1077
|
return !!near && (relative.startsWith(`${near}/`) || relative.replace(/\.tsx?$/, "") === near);
|
|
981
1078
|
};
|
|
982
|
-
|
|
1079
|
+
if (!identifierPattern.test(name))
|
|
1080
|
+
return [];
|
|
1081
|
+
const candidates = this.#filesIn(owner).filter(([, words]) => words.includes(`
|
|
983
1082
|
${name}
|
|
984
1083
|
`)).map(([fileName]) => fileName);
|
|
985
1084
|
return [...candidates.filter(isNear), ...candidates.filter((other) => !isNear(other))];
|
|
@@ -996,7 +1095,7 @@ ${owner ?? ""}`;
|
|
|
996
1095
|
const entries = [];
|
|
997
1096
|
const fileNames = [
|
|
998
1097
|
...fileName ? [fileName] : [],
|
|
999
|
-
...(owner === null ? [] : this
|
|
1098
|
+
...(owner === null ? [] : this.#filesIn(owner)).filter(([other, words]) => other !== fileName && words.includes(`
|
|
1000
1099
|
${objectName}
|
|
1001
1100
|
`) && words.includes(`
|
|
1002
1101
|
${member}
|
|
@@ -1070,30 +1169,120 @@ ${near ?? ""}`;
|
|
|
1070
1169
|
#throughStar(declared, owner, name, near) {
|
|
1071
1170
|
if (!declared.length)
|
|
1072
1171
|
return;
|
|
1073
|
-
const { owners, isOpaque } = this
|
|
1172
|
+
const { owners, isOpaque } = this.starExportsOf(owner, near);
|
|
1074
1173
|
const reached = declared.filter((other) => other.owner !== null && owners.includes(other.owner));
|
|
1075
1174
|
return reached.length === 1 && !isOpaque && !this.declares(owner, name) ? reached[0] : undefined;
|
|
1076
1175
|
}
|
|
1077
|
-
|
|
1078
|
-
const
|
|
1176
|
+
starExportsOf(owner, near) {
|
|
1177
|
+
const key = `${owner}
|
|
1178
|
+
${near}`;
|
|
1179
|
+
const cached = this.#starExports.get(key);
|
|
1079
1180
|
if (cached)
|
|
1080
1181
|
return cached;
|
|
1081
|
-
const found = { owners: [], isOpaque: false };
|
|
1082
|
-
this.#starExports.set(
|
|
1083
|
-
const
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1182
|
+
const found = { owners: [], packages: [], paths: [near], isOpaque: false };
|
|
1183
|
+
this.#starExports.set(key, found);
|
|
1184
|
+
const reach = (specifier, path, target) => {
|
|
1185
|
+
if (path === null && !found.packages.includes(specifier))
|
|
1186
|
+
found.packages.push(specifier);
|
|
1187
|
+
if (target === undefined || target === frameworkOwner || path === null)
|
|
1188
|
+
found.isOpaque = true;
|
|
1189
|
+
else if (!found.paths.includes(path))
|
|
1190
|
+
found.paths.push(path);
|
|
1191
|
+
if (target && target !== frameworkOwner && target !== owner && !found.owners.includes(target))
|
|
1192
|
+
found.owners.push(target);
|
|
1193
|
+
};
|
|
1194
|
+
for (let idx = 0;idx < found.paths.length; idx++) {
|
|
1195
|
+
const path = found.paths[idx] ?? "";
|
|
1196
|
+
for (const module of this.#barrelAt(path) ?? [])
|
|
1197
|
+
reach(module, module, ownerOf(module) ?? undefined);
|
|
1198
|
+
for (const fileName of this.#modulesAt(path))
|
|
1199
|
+
for (const [, specifier = ""] of this.#source.readText(fileName)?.matchAll(starExportPattern) ?? [])
|
|
1200
|
+
reach(specifier, this.pathOfSpecifier(fileName, specifier), this.ownerOfSpecifier(fileName, specifier));
|
|
1201
|
+
}
|
|
1202
|
+
return found;
|
|
1203
|
+
}
|
|
1204
|
+
exportsAt(path, name) {
|
|
1205
|
+
const key = `${path}
|
|
1206
|
+
${name}`;
|
|
1207
|
+
const cached = this.#moduleExports.get(key);
|
|
1208
|
+
if (cached)
|
|
1209
|
+
return cached;
|
|
1210
|
+
const found = { named: null, stars: [], isLocal: false };
|
|
1211
|
+
const stars = new Set(this.#barrelAt(path));
|
|
1212
|
+
for (const fileName of this.#modulesAt(path)) {
|
|
1213
|
+
const text = this.#source.readText(fileName);
|
|
1214
|
+
if (text === undefined)
|
|
1215
|
+
continue;
|
|
1216
|
+
const named = text.includes(name) && identifierPattern.test(name) && exportingPatternOf(name).test(text) ? this.#reexportIn(this.#source.parse(fileName, text), name, true) : null;
|
|
1217
|
+
if (named) {
|
|
1218
|
+
found.named = { ...named, fileName };
|
|
1219
|
+
break;
|
|
1096
1220
|
}
|
|
1221
|
+
if (text.includes(name) && exportMentioningPatternOf(name).test(text) && this.#exportsLocally(this.#source.parse(fileName, text), name)) {
|
|
1222
|
+
found.isLocal = true;
|
|
1223
|
+
break;
|
|
1224
|
+
}
|
|
1225
|
+
for (const target of this.#starsIn(fileName, text))
|
|
1226
|
+
stars.add(target);
|
|
1227
|
+
}
|
|
1228
|
+
if (!found.named && !found.isLocal)
|
|
1229
|
+
found.stars = [...stars];
|
|
1230
|
+
this.#moduleExports.set(key, found);
|
|
1231
|
+
return found;
|
|
1232
|
+
}
|
|
1233
|
+
#exportsLocally(source, name) {
|
|
1234
|
+
const { ts } = this.#source;
|
|
1235
|
+
const binds = (node) => ts.isIdentifier(node) ? node.text === name : node.elements.some((element) => !ts.isOmittedExpression(element) && binds(element.name));
|
|
1236
|
+
return source.statements.some((statement) => {
|
|
1237
|
+
if (ts.isExportDeclaration(statement)) {
|
|
1238
|
+
const { exportClause, isTypeOnly, moduleSpecifier } = statement;
|
|
1239
|
+
if (isTypeOnly || !exportClause)
|
|
1240
|
+
return false;
|
|
1241
|
+
if (ts.isNamespaceExport(exportClause))
|
|
1242
|
+
return exportClause.name.text === name;
|
|
1243
|
+
return !moduleSpecifier && ts.isNamedExports(exportClause) && exportClause.elements.some((element) => !element.isTypeOnly && element.name.text === name);
|
|
1244
|
+
}
|
|
1245
|
+
const modifiers = ts.canHaveModifiers(statement) ? ts.getModifiers(statement) ?? [] : [];
|
|
1246
|
+
if (!modifiers.some(({ kind }) => kind === ts.SyntaxKind.ExportKeyword) || modifiers.some(({ kind }) => kind === ts.SyntaxKind.DefaultKeyword))
|
|
1247
|
+
return false;
|
|
1248
|
+
if (ts.isVariableStatement(statement))
|
|
1249
|
+
return statement.declarationList.declarations.some((declaration) => binds(declaration.name));
|
|
1250
|
+
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;
|
|
1251
|
+
});
|
|
1252
|
+
}
|
|
1253
|
+
mentionsAlong(path, name) {
|
|
1254
|
+
return this.#starReachOf(path).some((text) => text.includes(name));
|
|
1255
|
+
}
|
|
1256
|
+
#starReachOf(path) {
|
|
1257
|
+
const cached = this.#starReach.get(path);
|
|
1258
|
+
if (cached)
|
|
1259
|
+
return cached;
|
|
1260
|
+
const paths = new Set([path]);
|
|
1261
|
+
const texts = [];
|
|
1262
|
+
for (const at of paths) {
|
|
1263
|
+
for (const next of this.#barrelAt(at) ?? [])
|
|
1264
|
+
paths.add(next);
|
|
1265
|
+
for (const fileName of this.#modulesAt(at)) {
|
|
1266
|
+
const text = this.#source.readText(fileName) ?? "";
|
|
1267
|
+
texts.push(text);
|
|
1268
|
+
for (const next of this.#starsIn(fileName, text))
|
|
1269
|
+
paths.add(next);
|
|
1270
|
+
}
|
|
1271
|
+
}
|
|
1272
|
+
this.#starReach.set(path, texts);
|
|
1273
|
+
return texts;
|
|
1274
|
+
}
|
|
1275
|
+
#starsIn(fileName, text) {
|
|
1276
|
+
const cached = this.#fileStars.get(fileName);
|
|
1277
|
+
if (cached)
|
|
1278
|
+
return cached;
|
|
1279
|
+
const found = [];
|
|
1280
|
+
for (const [, specifier = ""] of text.matchAll(starExportPattern)) {
|
|
1281
|
+
const target = this.pathOfSpecifier(fileName, specifier);
|
|
1282
|
+
if (target !== null)
|
|
1283
|
+
found.push(target);
|
|
1284
|
+
}
|
|
1285
|
+
this.#fileStars.set(fileName, found);
|
|
1097
1286
|
return found;
|
|
1098
1287
|
}
|
|
1099
1288
|
#modulesAt(path) {
|
|
@@ -1107,11 +1296,33 @@ ${near ?? ""}`;
|
|
|
1107
1296
|
}
|
|
1108
1297
|
return this.#modules.get(path) ?? [];
|
|
1109
1298
|
}
|
|
1299
|
+
#barrelAt(path) {
|
|
1300
|
+
if (!this.#barrels) {
|
|
1301
|
+
const entries = new Map;
|
|
1302
|
+
for (const [fileName] of this.#source.files) {
|
|
1303
|
+
const [, folder, facet, entry, nested] = this.#source.relative(fileName).match(facetEntryPattern) ?? [];
|
|
1304
|
+
if (!folder || !facet || !entry)
|
|
1305
|
+
continue;
|
|
1306
|
+
const found = entries.get(folder) ?? { facet, files: new Set, dirs: new Set };
|
|
1307
|
+
(nested ? found.dirs : found.files).add(entry);
|
|
1308
|
+
entries.set(folder, found);
|
|
1309
|
+
}
|
|
1310
|
+
this.#barrels = new Map([...entries].map(([folder, { facet, files, dirs }]) => [
|
|
1311
|
+
folder,
|
|
1312
|
+
facetBarrelNamesOf(facet, [...files], [...dirs]).map((name) => `${folder}/${name}`)
|
|
1313
|
+
]));
|
|
1314
|
+
}
|
|
1315
|
+
return this.#modulesAt(path).length ? undefined : this.#barrels.get(path);
|
|
1316
|
+
}
|
|
1110
1317
|
declares(owner, name) {
|
|
1111
1318
|
const declaring = declaringPatternOf(name, true);
|
|
1112
1319
|
return this.#filesOf(owner, name, null).some((fileName) => declaring.test(this.#source.readText(fileName) ?? ""));
|
|
1113
1320
|
}
|
|
1114
|
-
|
|
1321
|
+
declaresAt(path, name) {
|
|
1322
|
+
const declaring = declaringPatternOf(name, true);
|
|
1323
|
+
return this.#modulesAt(path).some((fileName) => declaring.test(this.#source.readText(fileName) ?? ""));
|
|
1324
|
+
}
|
|
1325
|
+
#filesIn(owner) {
|
|
1115
1326
|
if (!this.#ownerFiles) {
|
|
1116
1327
|
this.#ownerFiles = new Map;
|
|
1117
1328
|
for (const entry of this.#source.files) {
|
|
@@ -1161,6 +1372,196 @@ ${near ?? ""}`;
|
|
|
1161
1372
|
}
|
|
1162
1373
|
}
|
|
1163
1374
|
|
|
1375
|
+
// pkgs/@akanjs/language/adaptorResolver.ts
|
|
1376
|
+
var packageOf = (specifier) => specifier.split("/").slice(0, specifier.startsWith("@") ? 2 : 1).join("/");
|
|
1377
|
+
var packageKeyOf = ({ name, from }) => `${packageOf(from)}
|
|
1378
|
+
${name}`;
|
|
1379
|
+
var exportedKeyOf = (item) => ("fact" in item) ? item.id : ("local" in item) ? `${item.local}
|
|
1380
|
+
` : packageKeyOf(item);
|
|
1381
|
+
var isPackageExport = (item) => ("from" in item);
|
|
1382
|
+
|
|
1383
|
+
class AdaptorResolver {
|
|
1384
|
+
#source;
|
|
1385
|
+
#resolver;
|
|
1386
|
+
#sink;
|
|
1387
|
+
#adaptors = new Map;
|
|
1388
|
+
#plugs = new Map;
|
|
1389
|
+
#serviceFields = new Set;
|
|
1390
|
+
#exported = new Map;
|
|
1391
|
+
constructor(source, resolver, sink) {
|
|
1392
|
+
this.#source = source;
|
|
1393
|
+
this.#resolver = resolver;
|
|
1394
|
+
this.#sink = sink;
|
|
1395
|
+
}
|
|
1396
|
+
declare(facts) {
|
|
1397
|
+
const counts = new Map;
|
|
1398
|
+
for (const file of facts)
|
|
1399
|
+
for (const fact of file.adaptors) {
|
|
1400
|
+
const key = this.#sink.key("adaptor", file.owner, fact.name);
|
|
1401
|
+
counts.set(key, (counts.get(key) ?? 0) + 1);
|
|
1402
|
+
}
|
|
1403
|
+
const declared = facts.flatMap((file) => file.adaptors.map((fact) => {
|
|
1404
|
+
const key = this.#sink.key("adaptor", file.owner, fact.name);
|
|
1405
|
+
const id = (counts.get(key) ?? 0) > 1 ? this.#sink.key("adaptor", file.owner, `${this.#resolver.inOwner(file.fileName, file.owner)}#${fact.name}`) : key;
|
|
1406
|
+
const adaptor = { fact, owner: file.owner, fileName: file.fileName, id };
|
|
1407
|
+
this.#adaptors.set(fact.name, [...this.#adaptors.get(fact.name) ?? [], adaptor]);
|
|
1408
|
+
this.#nodeOf(adaptor);
|
|
1409
|
+
return { adaptor, file };
|
|
1410
|
+
}));
|
|
1411
|
+
for (const { adaptor, file } of declared)
|
|
1412
|
+
for (const plug of adaptor.fact.plugs)
|
|
1413
|
+
this.#sink.addEdge(adaptor.id, this.#idOf(plug.target, file), "plugs", plug.name, this.#sink.location(plug.span));
|
|
1414
|
+
for (const file of facts)
|
|
1415
|
+
for (const binding of file.adaptorBindings)
|
|
1416
|
+
this.#sink.addEdge(this.#idOf(binding.role, file), this.#idOf(binding.adaptor, file), "binds", file.owner, this.#sink.location(binding.span));
|
|
1417
|
+
}
|
|
1418
|
+
addService(refName, service, file) {
|
|
1419
|
+
for (const plug of service.plugs) {
|
|
1420
|
+
const key = `${refName}
|
|
1421
|
+
${plug.name}`;
|
|
1422
|
+
this.#plugs.set(key, [
|
|
1423
|
+
...this.#plugs.get(key) ?? [],
|
|
1424
|
+
{ owner: file.owner, target: this.#idOf(plug.target, file) }
|
|
1425
|
+
]);
|
|
1426
|
+
}
|
|
1427
|
+
for (const field of service.fields)
|
|
1428
|
+
this.#serviceFields.add(`${file.owner ?? ""}
|
|
1429
|
+
${refName}
|
|
1430
|
+
${field}`);
|
|
1431
|
+
}
|
|
1432
|
+
pluggedOf(owner, module, field) {
|
|
1433
|
+
const plugs = this.#plugs.get(`${module}
|
|
1434
|
+
${field}`) ?? [];
|
|
1435
|
+
const own = plugs.filter((plug) => plug.owner === owner);
|
|
1436
|
+
if (!own.length && this.#serviceFields.has(`${owner ?? ""}
|
|
1437
|
+
${module}
|
|
1438
|
+
${field}`))
|
|
1439
|
+
return [];
|
|
1440
|
+
const inherited = own.length ? own : plugs.filter((plug) => this.#resolver.visible(plug.owner, owner));
|
|
1441
|
+
return [...new Set(inherited.map(({ target }) => target))];
|
|
1442
|
+
}
|
|
1443
|
+
#idOf(local, file) {
|
|
1444
|
+
const [head, member] = local.split(".");
|
|
1445
|
+
const imported = file.imports.find((item) => item.name === head);
|
|
1446
|
+
const name = member ?? (imported && imported.imported !== "default" && imported.imported !== "*" ? imported.imported : head);
|
|
1447
|
+
const path = imported ? this.#resolver.pathOfSpecifier(file.fileName, imported.from) : null;
|
|
1448
|
+
if (imported && path === null && !frameworkPattern.test(imported.from))
|
|
1449
|
+
return this.#packageAdaptorOf(name, imported.from);
|
|
1450
|
+
const from = imported ? this.#resolver.ownerOfSpecifier(file.fileName, imported.from) : undefined;
|
|
1451
|
+
const declared = this.#adaptors.get(name) ?? [];
|
|
1452
|
+
const holder = from === undefined ? file.owner : from;
|
|
1453
|
+
const own = this.#adaptorIn(name, declared, holder, path, file.fileName);
|
|
1454
|
+
if (own && "from" in own)
|
|
1455
|
+
return this.#packageAdaptorOf(own.name, own.from);
|
|
1456
|
+
const found = own === undefined && from !== frameworkOwner ? declared.find((adaptor) => this.#resolver.visible(adaptor.owner, holder)) : own;
|
|
1457
|
+
if (found)
|
|
1458
|
+
return found.id;
|
|
1459
|
+
const reexported = own === undefined && from && from !== frameworkOwner ? this.#packageShimOf(from, name, path) : null;
|
|
1460
|
+
if (reexported)
|
|
1461
|
+
return this.#packageAdaptorOf(reexported.name, reexported.from);
|
|
1462
|
+
const owner = from === frameworkOwner ? null : imported ? from ?? null : file.owner;
|
|
1463
|
+
const detail = from === frameworkOwner ? [frameworkOwner] : [];
|
|
1464
|
+
return this.#sink.addNode(this.#sink.key("adaptor", owner, name), "adaptor", owner, name, null, detail).id;
|
|
1465
|
+
}
|
|
1466
|
+
#adaptorIn(name, declared, owner, path, fileName) {
|
|
1467
|
+
const own = declared.filter((adaptor) => adaptor.owner === owner);
|
|
1468
|
+
const [first] = own;
|
|
1469
|
+
if (path === null)
|
|
1470
|
+
return own.find((adaptor) => adaptor.fileName === fileName) ?? first;
|
|
1471
|
+
if (own.length === 1)
|
|
1472
|
+
return first;
|
|
1473
|
+
const exported = this.#exportedAt(name, path).filter((item) => first || !isPackageExport(item));
|
|
1474
|
+
const [only] = exported;
|
|
1475
|
+
if (only)
|
|
1476
|
+
return exported.length === 1 && !("local" in only) ? only : null;
|
|
1477
|
+
return first ? null : undefined;
|
|
1478
|
+
}
|
|
1479
|
+
#exportedAt(name, path) {
|
|
1480
|
+
const key = `${path}
|
|
1481
|
+
${name}`;
|
|
1482
|
+
const cached = this.#exported.get(key);
|
|
1483
|
+
if (cached)
|
|
1484
|
+
return cached;
|
|
1485
|
+
if (!this.#resolver.mentionsAlong(path, name)) {
|
|
1486
|
+
this.#exported.set(key, []);
|
|
1487
|
+
return [];
|
|
1488
|
+
}
|
|
1489
|
+
const reached = new Map;
|
|
1490
|
+
const seen = new Set;
|
|
1491
|
+
const pending = [[name, path]];
|
|
1492
|
+
for (let next = pending.pop();next; next = pending.pop()) {
|
|
1493
|
+
const [wanted, at] = next;
|
|
1494
|
+
if (seen.has(`${at}
|
|
1495
|
+
${wanted}`))
|
|
1496
|
+
continue;
|
|
1497
|
+
seen.add(`${at}
|
|
1498
|
+
${wanted}`);
|
|
1499
|
+
for (const item of this.#bindingAt(wanted, at, pending, name))
|
|
1500
|
+
reached.set(exportedKeyOf(item), item);
|
|
1501
|
+
}
|
|
1502
|
+
const found = [...reached.values()];
|
|
1503
|
+
this.#exported.set(key, found);
|
|
1504
|
+
return found;
|
|
1505
|
+
}
|
|
1506
|
+
#bindingAt(name, path, pending, plugged) {
|
|
1507
|
+
const here = this.#declaredAt(name, path);
|
|
1508
|
+
if (here.length)
|
|
1509
|
+
return here;
|
|
1510
|
+
const { named, stars, isLocal } = this.#resolver.exportsAt(path, name);
|
|
1511
|
+
if (isLocal)
|
|
1512
|
+
return [{ local: path }];
|
|
1513
|
+
if (named?.from === null) {
|
|
1514
|
+
const local = this.#declaredAt(named.name, path);
|
|
1515
|
+
return local.length ? local : [{ local: path }];
|
|
1516
|
+
}
|
|
1517
|
+
if (named) {
|
|
1518
|
+
const target = this.#resolver.pathOfSpecifier(named.fileName, named.from);
|
|
1519
|
+
if (target === null) {
|
|
1520
|
+
const exposed = named.name !== "default" ? named.name : name !== "default" ? name : plugged;
|
|
1521
|
+
return [{ name: exposed, from: named.from }];
|
|
1522
|
+
}
|
|
1523
|
+
pending.push([named.name, target]);
|
|
1524
|
+
return [];
|
|
1525
|
+
}
|
|
1526
|
+
for (const star of stars)
|
|
1527
|
+
pending.push([name, star]);
|
|
1528
|
+
return [];
|
|
1529
|
+
}
|
|
1530
|
+
#declaredAt(name, path) {
|
|
1531
|
+
return (this.#adaptors.get(name) ?? []).filter((adaptor) => {
|
|
1532
|
+
const module = this.#source.relative(adaptor.fileName).replace(/\.tsx?$/, "");
|
|
1533
|
+
return module === path || module === `${path}/index`;
|
|
1534
|
+
});
|
|
1535
|
+
}
|
|
1536
|
+
#packageAdaptorOf(name, specifier) {
|
|
1537
|
+
if (frameworkPattern.test(specifier))
|
|
1538
|
+
return this.#sink.addNode(this.#sink.key("adaptor", null, name), "adaptor", null, name, null, [frameworkOwner]).id;
|
|
1539
|
+
const pkg = packageOf(specifier);
|
|
1540
|
+
return this.#sink.addNode(this.#sink.key("adaptor", pkg, name), "adaptor", null, name, null, [pkg]).id;
|
|
1541
|
+
}
|
|
1542
|
+
#packageShimOf(owner, name, near) {
|
|
1543
|
+
if (!near)
|
|
1544
|
+
return null;
|
|
1545
|
+
const shims = this.#exportedAt(name, near).filter(isPackageExport);
|
|
1546
|
+
const [shim] = shims;
|
|
1547
|
+
if (shim)
|
|
1548
|
+
return shims.length === 1 ? shim : null;
|
|
1549
|
+
const { packages, paths } = this.#resolver.starExportsOf(owner, near);
|
|
1550
|
+
const [only] = packages;
|
|
1551
|
+
if (!only || new Set(packages.map(packageOf)).size !== 1)
|
|
1552
|
+
return null;
|
|
1553
|
+
return paths.some((path) => this.#resolver.declaresAt(path, name)) ? null : { name, from: only };
|
|
1554
|
+
}
|
|
1555
|
+
#nodeOf({ fact, owner, fileName, id }) {
|
|
1556
|
+
const detail = fact.refName ? [fact.refName] : [];
|
|
1557
|
+
const node = this.#sink.addNode(id, "adaptor", owner, fact.name, fact.span, detail);
|
|
1558
|
+
if (fact.doc && !node.doc)
|
|
1559
|
+
node.doc = fact.doc;
|
|
1560
|
+
this.#sink.digest(node, this.#source.readText(fileName), fact.extent);
|
|
1561
|
+
return node.id;
|
|
1562
|
+
}
|
|
1563
|
+
}
|
|
1564
|
+
|
|
1164
1565
|
// pkgs/@akanjs/language/routeFacts.ts
|
|
1165
1566
|
import { normalizeRoutePattern, tryParseRouteModuleKey } from "akanjs/common/routeConvention.ts";
|
|
1166
1567
|
|
|
@@ -1356,12 +1757,18 @@ class GraphBuilder {
|
|
|
1356
1757
|
#routeFiles = new Map;
|
|
1357
1758
|
#routes;
|
|
1358
1759
|
#resolver;
|
|
1359
|
-
#adaptors
|
|
1360
|
-
#plugs = new Map;
|
|
1760
|
+
#adaptors;
|
|
1361
1761
|
constructor(source) {
|
|
1362
1762
|
this.#source = source;
|
|
1363
1763
|
this.#routes = new RouteFactReader(source.ts, source.reader, source.parse);
|
|
1364
1764
|
this.#resolver = new GuardResolver(source, this.#routes);
|
|
1765
|
+
this.#adaptors = new AdaptorResolver(source, this.#resolver, {
|
|
1766
|
+
key: (kind, owner, scope) => this.#key(kind, owner, scope),
|
|
1767
|
+
addNode: (id, kind, owner, name, span, detail) => this.#addNode(id, kind, owner, null, name, span, detail),
|
|
1768
|
+
addEdge: (from, to, kind, label, at) => this.#addEdge(from, to, kind, label, at),
|
|
1769
|
+
digest: (node, text, extent) => this.#digest(node, text, extent),
|
|
1770
|
+
location: (span) => this.#location(span)
|
|
1771
|
+
});
|
|
1365
1772
|
}
|
|
1366
1773
|
build() {
|
|
1367
1774
|
const { facts } = this.#source;
|
|
@@ -1373,16 +1780,7 @@ class GraphBuilder {
|
|
|
1373
1780
|
...[...constantsByOwner].filter(([key]) => key !== owner && key?.startsWith("libs/")).flatMap(([, list]) => list)
|
|
1374
1781
|
];
|
|
1375
1782
|
const typed = [];
|
|
1376
|
-
|
|
1377
|
-
for (const fact of file.adaptors) {
|
|
1378
|
-
const declared = { fact, owner: file.owner, fileName: file.fileName };
|
|
1379
|
-
this.#adaptors.set(fact.name, [...this.#adaptors.get(fact.name) ?? [], declared]);
|
|
1380
|
-
this.#adaptorNodeOf(declared);
|
|
1381
|
-
}
|
|
1382
|
-
for (const file of facts)
|
|
1383
|
-
for (const fact of file.adaptors)
|
|
1384
|
-
for (const plug of fact.plugs)
|
|
1385
|
-
this.#addEdge(this.#key("adaptor", file.owner, fact.name), this.#adaptorIdOf(plug.target, file), "plugs", plug.name, this.#location(plug.span));
|
|
1783
|
+
this.#adaptors.declare(facts);
|
|
1386
1784
|
for (const guard of this.#resolver.declare(facts))
|
|
1387
1785
|
this.#guardNodeOf(guard);
|
|
1388
1786
|
for (const file of facts) {
|
|
@@ -1415,10 +1813,7 @@ class GraphBuilder {
|
|
|
1415
1813
|
}
|
|
1416
1814
|
for (const method of service.methods)
|
|
1417
1815
|
this.#addMember("method", owner, refName, method, `${service.name}.${method.name}`, file.fileName);
|
|
1418
|
-
|
|
1419
|
-
this.#plugs.set(`${owner ?? ""}
|
|
1420
|
-
${refName}
|
|
1421
|
-
${plug.name}`, this.#adaptorIdOf(plug.target, file));
|
|
1816
|
+
this.#adaptors.addService(refName, service, file);
|
|
1422
1817
|
}
|
|
1423
1818
|
for (const filter of file.filters) {
|
|
1424
1819
|
if (!filter.name.endsWith("Filter"))
|
|
@@ -1674,28 +2069,6 @@ ${dir}`, node);
|
|
|
1674
2069
|
this.#digest(node, text, extent);
|
|
1675
2070
|
return node.id;
|
|
1676
2071
|
}
|
|
1677
|
-
#adaptorIdOf(local, file) {
|
|
1678
|
-
const [head, member] = local.split(".");
|
|
1679
|
-
const imported = file.imports.find((item) => item.name === head);
|
|
1680
|
-
const from = imported ? this.#resolver.ownerOfSpecifier(file.fileName, imported.from) : undefined;
|
|
1681
|
-
const name = member ?? (imported && imported.imported !== "default" && imported.imported !== "*" ? imported.imported : head);
|
|
1682
|
-
const declared = this.#adaptors.get(name) ?? [];
|
|
1683
|
-
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)));
|
|
1684
|
-
if (found)
|
|
1685
|
-
return this.#adaptorNodeOf(found);
|
|
1686
|
-
const owner = from === frameworkOwner ? null : imported ? from ?? null : file.owner;
|
|
1687
|
-
const detail = from === frameworkOwner ? [frameworkOwner] : [];
|
|
1688
|
-
return this.#addNode(this.#key("adaptor", owner, name), "adaptor", owner, null, name, null, detail).id;
|
|
1689
|
-
}
|
|
1690
|
-
#adaptorNodeOf({ fact, owner, fileName }) {
|
|
1691
|
-
const id = this.#key("adaptor", owner, fact.name);
|
|
1692
|
-
const detail = fact.refName ? [fact.refName] : [];
|
|
1693
|
-
const node = this.#addNode(id, "adaptor", owner, null, fact.name, fact.span, detail);
|
|
1694
|
-
if (fact.doc && !node.doc)
|
|
1695
|
-
node.doc = fact.doc;
|
|
1696
|
-
this.#digest(node, this.#source.readText(fileName), fact.extent);
|
|
1697
|
-
return node.id;
|
|
1698
|
-
}
|
|
1699
2072
|
#guardNodeOf({ name, owner, span, scope, doc, parts, file, label }) {
|
|
1700
2073
|
const id = this.#key("guard", owner, file ? `${file}#${name}` : name);
|
|
1701
2074
|
const node = this.#addNode(id, "guard", owner, null, name, span, scope ? [scope] : [], label ?? name);
|
|
@@ -1798,10 +2171,8 @@ st
|
|
|
1798
2171
|
visit(source);
|
|
1799
2172
|
}
|
|
1800
2173
|
#link(fileName, source, identifier, chain, context, owner) {
|
|
1801
|
-
const plugged = chain?.length === 2 && chain[0] === "this" && context.kind === "method" && this.#isServiceThis(identifier) ? this.#
|
|
1802
|
-
|
|
1803
|
-
${chain[1]}`) : undefined;
|
|
1804
|
-
const resolved = plugged ? [plugged] : this.#source.resolve(fileName, identifier).map((target) => this.#targetNodeOf(target)).filter((id) => id !== null);
|
|
2174
|
+
const plugged = chain?.length === 2 && chain[0] === "this" && context.kind === "method" && this.#isServiceThis(identifier) ? this.#adaptors.pluggedOf(context.owner, context.module, chain[1]) : [];
|
|
2175
|
+
const resolved = plugged.length ? plugged : this.#source.resolve(fileName, identifier).map((target) => this.#targetNodeOf(target)).filter((id) => id !== null);
|
|
1805
2176
|
const targets = resolved.length ? resolved : this.#plainTargetsOf(chain, identifier.text, context, owner);
|
|
1806
2177
|
if (!targets.length)
|
|
1807
2178
|
return;
|
|
@@ -2245,7 +2616,7 @@ var sourcePattern = /\.(constant|document|service|signal|store)\.ts$/;
|
|
|
2245
2616
|
var dictionaryPattern = /\.dictionary\.ts$/;
|
|
2246
2617
|
var srvkitPattern = /\/srvkit\//;
|
|
2247
2618
|
var wordPattern = /[A-Za-z_$][\w$]*/g;
|
|
2248
|
-
var
|
|
2619
|
+
var identifierPattern2 = /^[A-Za-z_$][\w$]*$/;
|
|
2249
2620
|
var stateReceivers = new Set(["use", "sel", "get", "do"]);
|
|
2250
2621
|
var lensFamilies = new Set(["slice", "query", "formSetter", "storeState", "endpoint"]);
|
|
2251
2622
|
var modellessFamilies = new Set(["query", "storeState", "endpoint"]);
|
|
@@ -2354,7 +2725,7 @@ ${[...new Set(text.match(wordPattern))].join(`
|
|
|
2354
2725
|
}
|
|
2355
2726
|
renameAt(givenName, offset, newKey, readText) {
|
|
2356
2727
|
const sources = this.#sourceEntriesAt(pathOf(givenName), offset).filter((entry) => entry.renamed);
|
|
2357
|
-
if (!sources.length || !
|
|
2728
|
+
if (!sources.length || !identifierPattern2.test(newKey))
|
|
2358
2729
|
return null;
|
|
2359
2730
|
return [
|
|
2360
2731
|
{ span: sources[0].span, newText: newKey },
|
|
@@ -2382,6 +2753,8 @@ canPass
|
|
|
2382
2753
|
adapt
|
|
2383
2754
|
`) || words.includes(`
|
|
2384
2755
|
dangerouslyAdapt
|
|
2756
|
+
`) || words.includes(`
|
|
2757
|
+
applyAdaptor
|
|
2385
2758
|
`);
|
|
2386
2759
|
}
|
|
2387
2760
|
static #sourceKeyOf({ family, sourceKey, label, detail, span }) {
|
|
@@ -3062,6 +3435,11 @@ ${union.name}`)));
|
|
|
3062
3435
|
const field = this.#memberOf(this.#classOf(receiver), receiver.name.text);
|
|
3063
3436
|
return field && ts.isPropertyDeclaration(field) ? this.#namesIn(field.type) : new Set;
|
|
3064
3437
|
}
|
|
3438
|
+
if (ts.isCallExpression(receiver) && ts.isPropertyAccessExpression(receiver.expression) && receiver.expression.expression.kind === ts.SyntaxKind.ThisKeyword) {
|
|
3439
|
+
const field = this.#memberOf(this.#classOf(receiver), receiver.expression.name.text);
|
|
3440
|
+
const type = field && ts.isPropertyDeclaration(field) ? field.type : undefined;
|
|
3441
|
+
return type && ts.isFunctionTypeNode(type) ? this.#namesIn(type.type) : new Set;
|
|
3442
|
+
}
|
|
3065
3443
|
return this.#declaredTypeNames(receiver) ?? new Set;
|
|
3066
3444
|
}
|
|
3067
3445
|
#memberName(name) {
|