@saptools/service-flow 0.1.56 → 0.1.57
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/CHANGELOG.md +6 -0
- package/dist/{chunk-Y7H7ZU5B.js → chunk-DCOFNDKS.js} +78 -23
- package/dist/chunk-DCOFNDKS.js.map +1 -0
- package/dist/cli.js +14 -8
- package/dist/cli.js.map +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/src/db/repositories.ts +77 -22
- package/src/parsers/symbol-parser.ts +12 -6
- package/dist/chunk-Y7H7ZU5B.js.map +0 -1
package/dist/index.js
CHANGED
package/package.json
CHANGED
package/src/db/repositories.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { posix } from 'node:path';
|
|
1
2
|
import type { Db } from './connection.js';
|
|
2
3
|
import { projectBounded } from '../utils/000-bounded-projection.js';
|
|
3
4
|
import type {
|
|
@@ -390,34 +391,88 @@ export function insertSymbolCalls(db: Db, repoId: number, rows: SymbolCallFact[]
|
|
|
390
391
|
for (const r of rows) {
|
|
391
392
|
const caller = callerStmt.get(repoId, r.sourceFile, r.callerQualifiedName) as { id?: number } | undefined;
|
|
392
393
|
const target = resolveSymbolCallTarget(db, repoId, r);
|
|
393
|
-
insertStmt.run(repoId, caller?.id, target.id, r.calleeExpression, r.importSource, r.sourceFile, r.sourceLine, target.status, 0.8, JSON.stringify({ ...r.evidence, candidateStrategy: target.strategy, candidateCount: target.candidateCount }), target.reason);
|
|
394
|
+
insertStmt.run(repoId, caller?.id, target.id, r.calleeExpression, r.importSource, r.sourceFile, r.sourceLine, target.status, 0.8, JSON.stringify({ ...r.evidence, candidateStrategy: target.strategy, candidateCount: target.candidateCount, resolvedModulePath: target.resolvedModulePath }), target.reason);
|
|
394
395
|
}
|
|
395
396
|
}
|
|
397
|
+
interface SymbolTargetRow { id: number; kind?: string; sourceFile?: string | null; evidenceJson?: string | null }
|
|
398
|
+
interface SymbolCallResolution { id: number | null; status: 'resolved' | 'ambiguous' | 'unresolved'; reason: string | null; strategy: string; candidateCount: number; resolvedModulePath?: string }
|
|
399
|
+
const stripExt = (value: string): string => value.replace(/\.(ts|tsx|js|jsx|cds)$/, '');
|
|
400
|
+
function symbolTargetRows(rows: Array<Record<string, unknown>>): SymbolTargetRow[] {
|
|
401
|
+
return rows.flatMap((row) => typeof row.id === 'number' ? [{ id: row.id, kind: typeof row.kind === 'string' ? row.kind : undefined, sourceFile: nullableString(row.sourceFile), evidenceJson: nullableString(row.evidenceJson) }] : []);
|
|
402
|
+
}
|
|
403
|
+
function relativeModuleTargets(callerSourceFile: string, importSource: string): Set<string> {
|
|
404
|
+
const base = posix.dirname(callerSourceFile);
|
|
405
|
+
const joined = stripExt(posix.normalize(posix.join(base, importSource)));
|
|
406
|
+
return new Set([joined, `${joined}/index`]);
|
|
407
|
+
}
|
|
408
|
+
function moduleRows(rows: SymbolTargetRow[], r: SymbolCallFact): SymbolTargetRow[] {
|
|
409
|
+
if (!r.importSource) return [];
|
|
410
|
+
const targets = relativeModuleTargets(r.sourceFile, r.importSource);
|
|
411
|
+
return rows.filter((row) => typeof row.sourceFile === 'string' && targets.has(stripExt(row.sourceFile)));
|
|
412
|
+
}
|
|
413
|
+
function resolvedSymbol(row: SymbolTargetRow, strategy: string, candidateCount: number, moduleScoped = false): SymbolCallResolution {
|
|
414
|
+
return { id: row.id, status: 'resolved', reason: null, strategy, candidateCount, resolvedModulePath: moduleScoped && row.sourceFile ? stripExt(row.sourceFile) : undefined };
|
|
415
|
+
}
|
|
416
|
+
function exportedSymbolRows(db: Db, repoId: number, r: SymbolCallFact): SymbolTargetRow[] {
|
|
417
|
+
return symbolTargetRows(db.prepare('SELECT id,kind,source_file sourceFile,evidence_json evidenceJson FROM symbols WHERE repo_id=? AND source_file<>? AND exported=1 AND (exported_name=? OR name=? OR qualified_name=?) ORDER BY id').all(repoId, r.sourceFile, r.calleeLocalName, r.calleeLocalName, r.calleeLocalName));
|
|
418
|
+
}
|
|
396
419
|
function isRelativeImportedSymbolCall(r: SymbolCallFact): boolean {
|
|
397
420
|
return Boolean(r.importSource?.startsWith('.'));
|
|
398
421
|
}
|
|
399
|
-
function
|
|
400
|
-
const
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
if (
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
422
|
+
function sameFileResolution(db: Db, repoId: number, r: SymbolCallFact, relation: unknown): SymbolCallResolution | undefined {
|
|
423
|
+
const bareImport = relation === 'relative_import' && isRelativeImportedSymbolCall(r) && !String(r.calleeLocalName).includes('.');
|
|
424
|
+
if (bareImport || relation === 'relative_import_namespace_member' || relation === 'package_import') return undefined;
|
|
425
|
+
const rows = symbolTargetRows(db.prepare('SELECT id FROM symbols WHERE repo_id=? AND source_file=? AND (name=? OR qualified_name=?) ORDER BY id').all(repoId, r.sourceFile, r.calleeLocalName, r.calleeLocalName));
|
|
426
|
+
if (rows.length === 1 && rows[0]) return resolvedSymbol(rows[0], 'same_file_exact', 1);
|
|
427
|
+
return rows.length > 1 ? { id: null, status: 'ambiguous', reason: 'Multiple same-file symbol targets matched exactly', strategy: 'same_file_exact', candidateCount: rows.length } : undefined;
|
|
428
|
+
}
|
|
429
|
+
function classInstanceResolution(db: Db, repoId: number, r: SymbolCallFact, relation: unknown): SymbolCallResolution | undefined {
|
|
430
|
+
if (relation !== 'class_instance_method' || !isRelativeImportedSymbolCall(r)) return undefined;
|
|
431
|
+
const rows = symbolTargetRows(db.prepare('SELECT id FROM symbols WHERE repo_id=? AND source_file<>? AND qualified_name=? ORDER BY id').all(repoId, r.sourceFile, r.calleeLocalName));
|
|
432
|
+
if (rows.length === 1 && rows[0]) return resolvedSymbol(rows[0], 'relative_import_class_instance_method', 1);
|
|
433
|
+
return rows.length > 1 ? { id: null, status: 'ambiguous', reason: 'Multiple relative class instance method targets matched exactly', strategy: 'relative_import_class_instance_method', candidateCount: rows.length } : undefined;
|
|
434
|
+
}
|
|
435
|
+
function namespaceResolution(db: Db, repoId: number, r: SymbolCallFact, relation: unknown): SymbolCallResolution | undefined {
|
|
436
|
+
if (relation !== 'relative_import_namespace_member' || !isRelativeImportedSymbolCall(r)) return undefined;
|
|
437
|
+
const rows = moduleRows(exportedSymbolRows(db, repoId, r), r);
|
|
438
|
+
if (rows.length === 1 && rows[0]) return resolvedSymbol(rows[0], 'relative_import_namespace_member', 1, true);
|
|
439
|
+
if (rows.length > 1) return { id: null, status: 'ambiguous', reason: 'Multiple namespace member targets matched the imported module', strategy: 'relative_import_namespace_member', candidateCount: rows.length };
|
|
440
|
+
return { id: null, status: 'unresolved', reason: 'No namespace member target matched the imported module', strategy: 'relative_import_namespace_member', candidateCount: 0 };
|
|
441
|
+
}
|
|
442
|
+
function proxyResolution(rows: SymbolTargetRow[], r: SymbolCallFact, relation: unknown): SymbolCallResolution | undefined {
|
|
443
|
+
if (relation !== 'relative_import_proxy_member' || rows.length <= 1) return undefined;
|
|
444
|
+
const mapped = rows.filter((row) => String(row.evidenceJson ?? '').includes('exported_object_shorthand') || String(row.evidenceJson ?? '').includes('exported_object_literal'));
|
|
445
|
+
if (mapped.length > 0) {
|
|
446
|
+
const concrete = rows.find((row) => row.kind !== 'object_alias') ?? mapped[0];
|
|
447
|
+
return { id: concrete?.id ?? null, status: 'resolved', reason: null, strategy: 'proxy_member_exported_object_map', candidateCount: rows.length };
|
|
417
448
|
}
|
|
418
|
-
|
|
419
|
-
if (
|
|
420
|
-
return { id: null, status: '
|
|
449
|
+
const scoped = moduleRows(rows, r);
|
|
450
|
+
if (scoped.length === 1 && scoped[0]) return resolvedSymbol(scoped[0], 'relative_import_path_disambiguated', rows.length, true);
|
|
451
|
+
return { id: null, status: 'ambiguous', reason: 'Proxy member target requires explicit factory/module/type evidence; global member name is ambiguous', strategy: 'proxy_member_no_global_name_fallback', candidateCount: rows.length };
|
|
452
|
+
}
|
|
453
|
+
function exportedResolution(rows: SymbolTargetRow[], r: SymbolCallFact, relation: unknown): SymbolCallResolution | undefined {
|
|
454
|
+
if (rows.length === 1 && rows[0]) return resolvedSymbol(rows[0], relation === 'relative_import_proxy_member' ? 'proxy_member_unique_exported_candidate' : 'relative_import_exported_exact', 1, moduleRows(rows, r).length === 1);
|
|
455
|
+
if (rows.length <= 1) return undefined;
|
|
456
|
+
const scoped = isRelativeImportedSymbolCall(r) ? moduleRows(rows, r) : [];
|
|
457
|
+
if (scoped.length === 1 && scoped[0]) return resolvedSymbol(scoped[0], 'relative_import_path_disambiguated', rows.length, true);
|
|
458
|
+
return { id: null, status: 'ambiguous', reason: 'Multiple exported symbol targets matched exactly', strategy: 'exported_exact', candidateCount: rows.length };
|
|
459
|
+
}
|
|
460
|
+
function accessorResolution(db: Db, repoId: number, r: SymbolCallFact, relation: unknown): SymbolCallResolution | undefined {
|
|
461
|
+
if (relation !== 'relative_import' || !isRelativeImportedSymbolCall(r) || !/^[^.]+\.[^.]+$/.test(String(r.calleeLocalName))) return undefined;
|
|
462
|
+
const methodRows = symbolTargetRows(db.prepare("SELECT id,kind,source_file sourceFile FROM symbols WHERE repo_id=? AND source_file<>? AND kind='method' AND qualified_name=? ORDER BY id").all(repoId, r.sourceFile, r.calleeLocalName));
|
|
463
|
+
const scoped = moduleRows(methodRows, r);
|
|
464
|
+
if (scoped.length === 1 && scoped[0]) return resolvedSymbol(scoped[0], 'relative_import_static_accessor_instance_method', 1, true);
|
|
465
|
+
return scoped.length > 1 ? { id: null, status: 'ambiguous', reason: 'Multiple static-accessor instance method targets matched the imported module', strategy: 'relative_import_static_accessor_instance_method', candidateCount: scoped.length } : undefined;
|
|
466
|
+
}
|
|
467
|
+
function resolveSymbolCallTarget(db: Db, repoId: number, r: SymbolCallFact): SymbolCallResolution {
|
|
468
|
+
const relation = r.evidence.relation;
|
|
469
|
+
const early = sameFileResolution(db, repoId, r, relation) ?? classInstanceResolution(db, repoId, r, relation) ?? namespaceResolution(db, repoId, r, relation);
|
|
470
|
+
if (early) return early;
|
|
471
|
+
const rows = relation === 'package_import' ? [] : exportedSymbolRows(db, repoId, r);
|
|
472
|
+
const matched = proxyResolution(rows, r, relation) ?? exportedResolution(rows, r, relation) ?? accessorResolution(db, repoId, r, relation);
|
|
473
|
+
if (matched) return matched;
|
|
474
|
+
if (relation === 'package_import') return { id: null, status: 'unresolved', reason: 'Package import target resolution requires a post-publication workspace pass', strategy: 'package_import_unresolved', candidateCount: 0 };
|
|
475
|
+
return { id: null, status: 'unresolved', reason: 'No local symbol target matched exactly', strategy: relation === 'relative_import_proxy_member' ? 'proxy_member_no_global_name_fallback' : 'exact_symbol_match', candidateCount: 0 };
|
|
421
476
|
}
|
|
422
477
|
export function insertCalls(
|
|
423
478
|
db: Db,
|
|
@@ -184,6 +184,7 @@ export async function parseExecutableSymbols(
|
|
|
184
184
|
const symbols: ExecutableSymbolFact[] = [];
|
|
185
185
|
const calls: SymbolCallFact[] = [];
|
|
186
186
|
const imports = new Map<string, string>();
|
|
187
|
+
const namespaceImports = new Set<string>();
|
|
187
188
|
const exportNames = exportDeclarations(source);
|
|
188
189
|
const objectExports = new Set<string>();
|
|
189
190
|
const exportedClasses = new Set<string>();
|
|
@@ -214,7 +215,10 @@ export async function parseExecutableSymbols(
|
|
|
214
215
|
if (clause?.name) imports.set(clause.name.text, sourceText);
|
|
215
216
|
const named = clause?.namedBindings;
|
|
216
217
|
if (named && ts.isNamedImports(named)) for (const el of named.elements) imports.set(el.name.text, sourceText);
|
|
217
|
-
if (named && ts.isNamespaceImport(named))
|
|
218
|
+
if (named && ts.isNamespaceImport(named)) {
|
|
219
|
+
imports.set(named.name.text, sourceText);
|
|
220
|
+
namespaceImports.add(named.name.text);
|
|
221
|
+
}
|
|
218
222
|
}
|
|
219
223
|
if (ts.isVariableStatement(node)) {
|
|
220
224
|
for (const declaration of node.declarationList.declarations) {
|
|
@@ -330,7 +334,9 @@ export async function parseExecutableSymbols(
|
|
|
330
334
|
const instance = (callee.local ? classInstances.get(callee.local) : undefined) ?? (callee.receiver ? classInstances.get(callee.receiver) : undefined);
|
|
331
335
|
const importSource = instance?.importSource ?? proxy?.importSource ?? (callee.local ? imports.get(callee.local) : undefined) ?? (callee.member && callee.local ? imports.get(callee.local) : undefined);
|
|
332
336
|
const directThisMethod = callee.receiver === 'this';
|
|
333
|
-
const
|
|
337
|
+
const namespaceMember = Boolean(callee.member && callee.local && namespaceImports.has(callee.local));
|
|
338
|
+
const packageImport = Boolean(importSource && !isRelativeImport(importSource));
|
|
339
|
+
const targetName = instance && callee.member ? `${instance.className}.${callee.member}` : proxy && callee.member ? callee.member : directThisMethod ? callee.member : namespaceMember ? callee.member : packageImport ? (callee.member ?? callee.local) : callee.member && callee.local ? `${callee.local}.${callee.member}` : callee.local;
|
|
334
340
|
const className = caller.qualifiedName.includes('.') ? caller.qualifiedName.split('.')[0] : undefined;
|
|
335
341
|
const thisTarget = directThisMethod && className && callee.member ? `${className}.${callee.member}` : undefined;
|
|
336
342
|
const loggerLike = callee.receiver?.endsWith('.logger') || callee.local === 'logger' || (callee.expression.startsWith('this.logger.') && callee.member ? loggerMembers.has(callee.member) : false);
|
|
@@ -339,11 +345,11 @@ export async function parseExecutableSymbols(
|
|
|
339
345
|
const provenThisMethod = Boolean(thisTarget && localCallables.has(thisTarget));
|
|
340
346
|
const provenRelativeImport = Boolean(isRelativeImport(importSource) && targetName);
|
|
341
347
|
const provenClassInstance = Boolean(instance && callee.member && targetName);
|
|
342
|
-
const
|
|
343
|
-
const ignored = loggerLike || terminalMember ||
|
|
348
|
+
const provenPackageImport = Boolean(packageImport && targetName);
|
|
349
|
+
const ignored = loggerLike || terminalMember || ignoredFrameworkCall(callee);
|
|
344
350
|
const resolvedTarget = provenThisMethod ? thisTarget : targetName;
|
|
345
|
-
const keep = Boolean(resolvedTarget) && !ignored && (provenLocal || provenThisMethod || provenRelativeImport || provenClassInstance);
|
|
346
|
-
if (keep) calls.push({ callerQualifiedName: caller.qualifiedName, calleeExpression: callee.expression, calleeLocalName: resolvedTarget, receiverLocalName: callee.member ? (callee.local ?? callee.receiver) : undefined, importSource, sourceFile, sourceLine: line, evidence: { relation: instance ? 'class_instance_method' : proxy ? 'relative_import_proxy_member' : importSource ? 'relative_import' : provenThisMethod ? 'indexed_this_method' : 'indexed_local_symbol', caller: caller.qualifiedName, targetName: resolvedTarget, instanceVariable: instance ? (instance.propertyName ?? callee.local) : undefined, className: instance?.className, methodName: instance ? callee.member : undefined, classImportSource: instance?.importSource, callArguments: argumentEvidence(node.arguments, source), proxyVariableName: proxy?.variableName, factory: proxy?.factory, factoryExpression: proxy?.factory, factoryImportSource: proxy?.importSource, candidateStrategy: instance ? (instance.importSource ? 'relative_import_class_instance_method' : 'same_file_class_instance_method') : proxy ? 'proxy_member_exact_export_or_unique_member' : undefined } });
|
|
351
|
+
const keep = Boolean(resolvedTarget) && !ignored && (provenLocal || provenThisMethod || provenRelativeImport || provenClassInstance || provenPackageImport);
|
|
352
|
+
if (keep) calls.push({ callerQualifiedName: caller.qualifiedName, calleeExpression: callee.expression, calleeLocalName: resolvedTarget, receiverLocalName: callee.member ? (callee.local ?? callee.receiver) : undefined, importSource, sourceFile, sourceLine: line, evidence: { relation: instance ? 'class_instance_method' : proxy ? 'relative_import_proxy_member' : packageImport ? 'package_import' : namespaceMember ? 'relative_import_namespace_member' : importSource ? 'relative_import' : provenThisMethod ? 'indexed_this_method' : 'indexed_local_symbol', caller: caller.qualifiedName, targetName: resolvedTarget, instanceVariable: instance ? (instance.propertyName ?? callee.local) : undefined, className: instance?.className, methodName: instance ? callee.member : undefined, classImportSource: instance?.importSource, callArguments: argumentEvidence(node.arguments, source), proxyVariableName: proxy?.variableName, factory: proxy?.factory, factoryExpression: proxy?.factory, factoryImportSource: proxy?.importSource, candidateStrategy: instance ? (instance.importSource ? 'relative_import_class_instance_method' : 'same_file_class_instance_method') : proxy ? 'proxy_member_exact_export_or_unique_member' : undefined } });
|
|
347
353
|
}
|
|
348
354
|
}
|
|
349
355
|
ts.forEachChild(node, visitCalls);
|