@saptools/service-flow 0.1.40 → 0.1.41

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/dist/index.d.ts CHANGED
@@ -30,6 +30,14 @@ interface CdsServiceFact {
30
30
  sourceFile: string;
31
31
  sourceLine: number;
32
32
  operations: CdsOperationFact[];
33
+ extension?: CdsExtensionFact;
34
+ }
35
+ interface CdsExtensionFact {
36
+ localReference: string;
37
+ importedSymbol?: string;
38
+ localAlias?: string;
39
+ moduleSpecifier?: string;
40
+ importKind?: 'relative' | 'package' | 'none';
33
41
  }
34
42
  interface CdsOperationFact {
35
43
  operationType: 'action' | 'function' | 'event';
@@ -39,6 +47,8 @@ interface CdsOperationFact {
39
47
  returnType?: string;
40
48
  sourceFile: string;
41
49
  sourceLine: number;
50
+ provenance?: 'direct' | 'inherited';
51
+ baseOperationId?: number;
42
52
  }
43
53
  interface HandlerClassFact {
44
54
  className: string;
package/dist/index.js CHANGED
@@ -16,7 +16,7 @@ import {
16
16
  stripQuotes,
17
17
  substituteVariables,
18
18
  trace
19
- } from "./chunk-774PPGGK.js";
19
+ } from "./chunk-7L4QKKGN.js";
20
20
 
21
21
  // src/parsers/generated-constants-parser.ts
22
22
  import fs from "fs/promises";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@saptools/service-flow",
3
- "version": "0.1.40",
3
+ "version": "0.1.41",
4
4
  "description": "Trace SAP CAP service-to-service flows across multi-repository workspaces with runtime-aware graph resolution",
5
5
  "type": "module",
6
6
  "publishConfig": {
@@ -1,6 +1,6 @@
1
1
  import type { Db } from './connection.js';
2
2
  import { schemaSql } from './schema.js';
3
- const CURRENT_SCHEMA_VERSION = 8;
3
+ const CURRENT_SCHEMA_VERSION = 9;
4
4
  const columns: Record<string, Array<{ name: string; ddl: string }>> = {
5
5
  service_bindings: [
6
6
  { name: 'helper_chain_json', ddl: 'ALTER TABLE service_bindings ADD COLUMN helper_chain_json TEXT' },
@@ -29,6 +29,19 @@ const columns: Record<string, Array<{ name: string; ddl: string }>> = {
29
29
  { name: 'exported_name', ddl: 'ALTER TABLE symbols ADD COLUMN exported_name TEXT' },
30
30
  { name: 'evidence_json', ddl: 'ALTER TABLE symbols ADD COLUMN evidence_json TEXT' },
31
31
  ],
32
+ cds_services: [
33
+ { name: 'extension_local_ref', ddl: 'ALTER TABLE cds_services ADD COLUMN extension_local_ref TEXT' },
34
+ { name: 'extension_imported_symbol', ddl: 'ALTER TABLE cds_services ADD COLUMN extension_imported_symbol TEXT' },
35
+ { name: 'extension_local_alias', ddl: 'ALTER TABLE cds_services ADD COLUMN extension_local_alias TEXT' },
36
+ { name: 'extension_module_specifier', ddl: 'ALTER TABLE cds_services ADD COLUMN extension_module_specifier TEXT' },
37
+ { name: 'extension_import_kind', ddl: 'ALTER TABLE cds_services ADD COLUMN extension_import_kind TEXT' },
38
+ { name: 'extension_base_service_id', ddl: 'ALTER TABLE cds_services ADD COLUMN extension_base_service_id INTEGER' },
39
+ { name: 'extension_base_status', ddl: 'ALTER TABLE cds_services ADD COLUMN extension_base_status TEXT' },
40
+ ],
41
+ cds_operations: [
42
+ { name: 'provenance', ddl: "ALTER TABLE cds_operations ADD COLUMN provenance TEXT NOT NULL DEFAULT 'direct'" },
43
+ { name: 'base_operation_id', ddl: 'ALTER TABLE cds_operations ADD COLUMN base_operation_id INTEGER' },
44
+ ],
32
45
  outbound_calls: [
33
46
  { name: 'local_service_name', ddl: 'ALTER TABLE outbound_calls ADD COLUMN local_service_name TEXT' },
34
47
  { name: 'local_service_lookup', ddl: 'ALTER TABLE outbound_calls ADD COLUMN local_service_lookup TEXT' },
@@ -139,7 +139,7 @@ export function insertService(
139
139
  const id = Number(
140
140
  db
141
141
  .prepare(
142
- 'INSERT INTO cds_services(repo_id,namespace,service_name,qualified_name,service_path,is_extend,source_file,source_line) VALUES(?,?,?,?,?,?,?,?) RETURNING id',
142
+ 'INSERT INTO cds_services(repo_id,namespace,service_name,qualified_name,service_path,is_extend,source_file,source_line,extension_local_ref,extension_imported_symbol,extension_local_alias,extension_module_specifier,extension_import_kind) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?) RETURNING id',
143
143
  )
144
144
  .get(
145
145
  repoId,
@@ -150,10 +150,15 @@ export function insertService(
150
150
  s.isExtend ? 1 : 0,
151
151
  s.sourceFile,
152
152
  s.sourceLine,
153
+ s.extension?.localReference,
154
+ s.extension?.importedSymbol,
155
+ s.extension?.localAlias,
156
+ s.extension?.moduleSpecifier,
157
+ s.extension?.importKind,
153
158
  )?.id,
154
159
  );
155
160
  const stmt = db.prepare(
156
- 'INSERT INTO cds_operations(service_id,operation_type,operation_name,operation_path,params_json,return_type,source_file,source_line) VALUES(?,?,?,?,?,?,?,?)',
161
+ 'INSERT INTO cds_operations(service_id,operation_type,operation_name,operation_path,params_json,return_type,source_file,source_line,provenance,base_operation_id) VALUES(?,?,?,?,?,?,?,?,?,?)',
157
162
  );
158
163
  db.prepare(
159
164
  'INSERT INTO search_index(kind,name,path,repo) VALUES(?,?,?,?)',
@@ -168,6 +173,8 @@ export function insertService(
168
173
  o.returnType,
169
174
  o.sourceFile,
170
175
  o.sourceLine,
176
+ o.provenance ?? 'direct',
177
+ o.baseOperationId ?? null,
171
178
  );
172
179
  const search = db.prepare(
173
180
  'INSERT INTO search_index(kind,name,path,repo) VALUES(?,?,?,?)',
package/src/db/schema.ts CHANGED
@@ -3,8 +3,8 @@ CREATE TABLE IF NOT EXISTS workspaces (id INTEGER PRIMARY KEY, root_path TEXT UN
3
3
  CREATE TABLE IF NOT EXISTS repositories (id INTEGER PRIMARY KEY, workspace_id INTEGER NOT NULL, name TEXT NOT NULL, absolute_path TEXT NOT NULL, relative_path TEXT NOT NULL, package_name TEXT, package_version TEXT, dependencies_json TEXT DEFAULT '{}', kind TEXT NOT NULL, is_git_repo INTEGER NOT NULL, last_indexed_at TEXT, index_status TEXT DEFAULT 'pending', error_count INTEGER DEFAULT 0, fingerprint TEXT, fact_generation INTEGER NOT NULL DEFAULT 0, graph_generation INTEGER NOT NULL DEFAULT 0, graph_stale_reason TEXT, graph_stale_at TEXT, fact_analyzer_version TEXT, UNIQUE(workspace_id, absolute_path), FOREIGN KEY(workspace_id) REFERENCES workspaces(id) ON DELETE CASCADE);
4
4
  CREATE TABLE IF NOT EXISTS files (id INTEGER PRIMARY KEY, repo_id INTEGER NOT NULL, relative_path TEXT NOT NULL, extension TEXT NOT NULL, sha256 TEXT NOT NULL, size_bytes INTEGER NOT NULL, last_indexed_at TEXT NOT NULL, UNIQUE(repo_id, relative_path), FOREIGN KEY(repo_id) REFERENCES repositories(id) ON DELETE CASCADE);
5
5
  CREATE TABLE IF NOT EXISTS cds_requires (id INTEGER PRIMARY KEY, repo_id INTEGER NOT NULL, alias TEXT NOT NULL, kind TEXT, model TEXT, destination TEXT, service_path TEXT, request_timeout INTEGER, raw_json TEXT NOT NULL, FOREIGN KEY(repo_id) REFERENCES repositories(id) ON DELETE CASCADE);
6
- CREATE TABLE IF NOT EXISTS cds_services (id INTEGER PRIMARY KEY, repo_id INTEGER NOT NULL, namespace TEXT, service_name TEXT NOT NULL, qualified_name TEXT NOT NULL, service_path TEXT NOT NULL, is_extend INTEGER NOT NULL, source_file TEXT NOT NULL, source_line INTEGER NOT NULL, FOREIGN KEY(repo_id) REFERENCES repositories(id) ON DELETE CASCADE);
7
- CREATE TABLE IF NOT EXISTS cds_operations (id INTEGER PRIMARY KEY, service_id INTEGER NOT NULL, operation_type TEXT NOT NULL, operation_name TEXT NOT NULL, operation_path TEXT NOT NULL, params_json TEXT NOT NULL, return_type TEXT, source_file TEXT NOT NULL, source_line INTEGER NOT NULL, FOREIGN KEY(service_id) REFERENCES cds_services(id) ON DELETE CASCADE);
6
+ CREATE TABLE IF NOT EXISTS cds_services (id INTEGER PRIMARY KEY, repo_id INTEGER NOT NULL, namespace TEXT, service_name TEXT NOT NULL, qualified_name TEXT NOT NULL, service_path TEXT NOT NULL, is_extend INTEGER NOT NULL, source_file TEXT NOT NULL, source_line INTEGER NOT NULL, extension_local_ref TEXT, extension_imported_symbol TEXT, extension_local_alias TEXT, extension_module_specifier TEXT, extension_import_kind TEXT, extension_base_service_id INTEGER, extension_base_status TEXT, FOREIGN KEY(repo_id) REFERENCES repositories(id) ON DELETE CASCADE, FOREIGN KEY(extension_base_service_id) REFERENCES cds_services(id) ON DELETE SET NULL);
7
+ CREATE TABLE IF NOT EXISTS cds_operations (id INTEGER PRIMARY KEY, service_id INTEGER NOT NULL, operation_type TEXT NOT NULL, operation_name TEXT NOT NULL, operation_path TEXT NOT NULL, params_json TEXT NOT NULL, return_type TEXT, source_file TEXT NOT NULL, source_line INTEGER NOT NULL, provenance TEXT NOT NULL DEFAULT 'direct', base_operation_id INTEGER, FOREIGN KEY(service_id) REFERENCES cds_services(id) ON DELETE CASCADE, FOREIGN KEY(base_operation_id) REFERENCES cds_operations(id) ON DELETE SET NULL);
8
8
  CREATE TABLE IF NOT EXISTS symbols (id INTEGER PRIMARY KEY, repo_id INTEGER NOT NULL, file_id INTEGER, kind TEXT NOT NULL, name TEXT NOT NULL, qualified_name TEXT NOT NULL, exported INTEGER NOT NULL, start_line INTEGER NOT NULL, end_line INTEGER NOT NULL, start_offset INTEGER, end_offset INTEGER, source_file TEXT, exported_name TEXT, evidence_json TEXT, FOREIGN KEY(repo_id) REFERENCES repositories(id) ON DELETE CASCADE, FOREIGN KEY(file_id) REFERENCES files(id) ON DELETE CASCADE);
9
9
  CREATE TABLE IF NOT EXISTS handler_classes (id INTEGER PRIMARY KEY, repo_id INTEGER NOT NULL, symbol_id INTEGER, class_name TEXT NOT NULL, source_file TEXT NOT NULL, source_line INTEGER NOT NULL, FOREIGN KEY(repo_id) REFERENCES repositories(id) ON DELETE CASCADE, FOREIGN KEY(symbol_id) REFERENCES symbols(id) ON DELETE SET NULL);
10
10
  CREATE TABLE IF NOT EXISTS handler_methods (id INTEGER PRIMARY KEY, handler_class_id INTEGER NOT NULL, method_name TEXT NOT NULL, decorator_kind TEXT NOT NULL, decorator_value TEXT, decorator_raw_expression TEXT NOT NULL, source_file TEXT NOT NULL, source_line INTEGER NOT NULL, FOREIGN KEY(handler_class_id) REFERENCES handler_classes(id) ON DELETE CASCADE);
@@ -17,7 +17,9 @@ CREATE TABLE IF NOT EXISTS index_runs (id INTEGER PRIMARY KEY, workspace_id INTE
17
17
  CREATE TABLE IF NOT EXISTS diagnostics (id INTEGER PRIMARY KEY, repo_id INTEGER, file_id INTEGER, severity TEXT NOT NULL, code TEXT NOT NULL, message TEXT NOT NULL, source_file TEXT, source_line INTEGER, FOREIGN KEY(repo_id) REFERENCES repositories(id) ON DELETE CASCADE, FOREIGN KEY(file_id) REFERENCES files(id) ON DELETE SET NULL);
18
18
  CREATE INDEX IF NOT EXISTS idx_repo_name ON repositories(name);
19
19
  CREATE INDEX IF NOT EXISTS idx_service_path ON cds_services(service_path);
20
+ CREATE INDEX IF NOT EXISTS idx_extension_import ON cds_services(extension_module_specifier, extension_imported_symbol, is_extend);
20
21
  CREATE INDEX IF NOT EXISTS idx_operation_name ON cds_operations(operation_name, operation_path);
22
+ CREATE INDEX IF NOT EXISTS idx_operation_base ON cds_operations(base_operation_id);
21
23
  CREATE INDEX IF NOT EXISTS idx_calls_repo ON outbound_calls(repo_id, call_type);
22
24
  CREATE INDEX IF NOT EXISTS idx_symbol_calls_caller ON symbol_calls(repo_id, caller_symbol_id);
23
25
  CREATE VIRTUAL TABLE IF NOT EXISTS search_index USING fts5(kind, name, path, repo);
@@ -0,0 +1,65 @@
1
+ import type { Db } from '../db/connection.js';
2
+
3
+ interface ExtensionRow {
4
+ id: number;
5
+ repoId: number;
6
+ serviceName: string;
7
+ qualifiedName: string;
8
+ sourceFile: string;
9
+ moduleSpecifier?: string | null;
10
+ importedSymbol?: string | null;
11
+ importKind?: string | null;
12
+ }
13
+ interface BaseRow { id: number; repoId: number }
14
+
15
+ export function materializeCdsExtensionOperations(db: Db, workspaceId: number): void {
16
+ const extensions = db.prepare(`SELECT s.id,r.id repoId,s.service_name serviceName,s.qualified_name qualifiedName,s.source_file sourceFile,s.extension_module_specifier moduleSpecifier,s.extension_imported_symbol importedSymbol,s.extension_import_kind importKind
17
+ FROM cds_services s JOIN repositories r ON r.id=s.repo_id WHERE r.workspace_id=? AND s.is_extend=1`).all(workspaceId) as unknown as ExtensionRow[];
18
+ const insert = db.prepare(`INSERT INTO cds_operations(service_id,operation_type,operation_name,operation_path,params_json,return_type,source_file,source_line,provenance,base_operation_id)
19
+ SELECT ?,operation_type,operation_name,operation_path,params_json,return_type,source_file,source_line,'inherited',id FROM cds_operations WHERE service_id=? AND NOT EXISTS (SELECT 1 FROM cds_operations existing WHERE existing.service_id=? AND existing.operation_name=cds_operations.operation_name AND existing.operation_path=cds_operations.operation_path)`);
20
+ for (const extension of extensions) {
21
+ const bases = resolveBase(db, workspaceId, extension);
22
+ const status = bases.length === 1 ? 'resolved' : bases.length > 1 ? 'ambiguous' : 'unresolved';
23
+ db.prepare('UPDATE cds_services SET extension_base_status=?, extension_base_service_id=? WHERE id=?').run(status, bases[0]?.id ?? null, extension.id);
24
+ if (bases.length === 1) insert.run(extension.id, bases[0]?.id, extension.id);
25
+ }
26
+ }
27
+
28
+ function resolveBase(db: Db, workspaceId: number, extension: ExtensionRow): BaseRow[] {
29
+ const symbol = extension.importedSymbol ?? extension.serviceName;
30
+ if (extension.importKind === 'relative' && extension.moduleSpecifier) return relativeBase(db, extension, symbol);
31
+ if (extension.importKind === 'package' && extension.moduleSpecifier) return packageBase(db, workspaceId, extension.moduleSpecifier, symbol);
32
+ return sameRepoBase(db, extension, symbol);
33
+ }
34
+
35
+ function relativeBase(db: Db, extension: ExtensionRow, symbol: string): BaseRow[] {
36
+ const modulePath = normalizeModulePath(extension.sourceFile, extension.moduleSpecifier ?? '');
37
+ return db.prepare(`SELECT s.id,s.repo_id repoId FROM cds_services s WHERE s.repo_id=? AND s.is_extend=0 AND (s.qualified_name=? OR s.service_name=?) AND (s.source_file=? OR s.source_file=?) ORDER BY s.id`).all(extension.repoId, symbol, symbol, modulePath, `${modulePath}.cds`) as unknown as BaseRow[];
38
+ }
39
+
40
+ function packageBase(db: Db, workspaceId: number, specifier: string, symbol: string): BaseRow[] {
41
+ const packageName = packageNameFromSpecifier(specifier);
42
+ const moduleSuffix = specifier.slice(packageName.length).replace(/^\//, '');
43
+ return db.prepare(`SELECT s.id,s.repo_id repoId FROM cds_services s JOIN repositories r ON r.id=s.repo_id WHERE r.workspace_id=? AND s.is_extend=0 AND r.package_name=? AND (s.qualified_name=? OR s.service_name=?) AND (?='' OR s.source_file=? OR s.source_file=?) ORDER BY s.id`).all(workspaceId, packageName, symbol, symbol, moduleSuffix, moduleSuffix, `${moduleSuffix}.cds`) as unknown as BaseRow[];
44
+ }
45
+
46
+ function sameRepoBase(db: Db, extension: ExtensionRow, symbol: string): BaseRow[] {
47
+ return db.prepare('SELECT id,repo_id repoId FROM cds_services WHERE repo_id=? AND is_extend=0 AND (qualified_name=? OR service_name=?) ORDER BY id').all(extension.repoId, symbol, symbol) as unknown as BaseRow[];
48
+ }
49
+
50
+ function normalizeModulePath(sourceFile: string, specifier: string): string {
51
+ const base = sourceFile.split('/').slice(0, -1).join('/');
52
+ const parts = `${base}/${specifier}`.split('/');
53
+ const out: string[] = [];
54
+ for (const part of parts) {
55
+ if (!part || part === '.') continue;
56
+ if (part === '..') out.pop();
57
+ else out.push(part);
58
+ }
59
+ return out.join('/').replace(/\.cds$/, '');
60
+ }
61
+
62
+ function packageNameFromSpecifier(specifier: string): string {
63
+ const parts = specifier.split('/');
64
+ return specifier.startsWith('@') ? `${parts[0]}/${parts[1]}` : parts[0] ?? specifier;
65
+ }
@@ -2,6 +2,7 @@ import type { Db } from '../db/connection.js';
2
2
  import { listRepositories, repoByName } from '../db/repositories.js';
3
3
  import { errorMessage } from '../utils/diagnostics.js';
4
4
  import { indexRepository } from './repository-indexer.js';
5
+ import { materializeCdsExtensionOperations } from './cds-extension-resolver.js';
5
6
  export async function indexWorkspace(
6
7
  db: Db,
7
8
  workspaceId: number,
@@ -20,6 +21,7 @@ export async function indexWorkspace(
20
21
  diagnosticCount += result.diagnosticCount;
21
22
  skippedCount += result.skipped ? 1 : 0;
22
23
  }
24
+ materializeCdsExtensionOperations(db, workspaceId);
23
25
  db.prepare('UPDATE index_runs SET finished_at=?, status=?, file_count=?, diagnostic_count=? WHERE id=?').run(new Date().toISOString(), diagnosticCount ? 'failed' : 'success', fileCount, diagnosticCount, runId);
24
26
  return { repoCount: repos.length, indexedCount: repos.length - skippedCount, skippedCount, fileCount, diagnosticCount };
25
27
  } catch (error) {
@@ -90,6 +90,23 @@ function annotationRawAt(original: string, masked: string, index: number): { end
90
90
  return { end: collected.end, raw: original.slice(index, collected.end) };
91
91
  }
92
92
 
93
+
94
+ interface CdsUsing { importedSymbol: string; localAlias: string; moduleSpecifier: string; importKind: 'relative' | 'package' }
95
+ function collectUsings(masked: string): Map<string, CdsUsing> {
96
+ const imports = new Map<string, CdsUsing>();
97
+ for (const m of masked.matchAll(/\busing\s*\{([^}]*)\}\s*from\s*(['"])(.*?)\2\s*;/gs)) {
98
+ const moduleSpecifier = m[3] ?? '';
99
+ for (const part of (m[1] ?? '').split(',')) {
100
+ const text = part.trim();
101
+ if (!text) continue;
102
+ const alias = /^(\w+)\s+as\s+(\w+)$/.exec(text) ?? /^(\w+)\s*:\s*(\w+)$/.exec(text);
103
+ const importedSymbol = alias?.[1] ?? text;
104
+ const localAlias = alias?.[2] ?? importedSymbol;
105
+ imports.set(localAlias, { importedSymbol, localAlias, moduleSpecifier, importKind: moduleSpecifier.startsWith('.') ? 'relative' : 'package' });
106
+ }
107
+ }
108
+ return imports;
109
+ }
93
110
  function operationsFromBody(text: string, maskedBody: string, bodyOffset: number, filePath: string): CdsOperationFact[] {
94
111
  return [...maskedBody.matchAll(/\b(action|function|event)\s+(\w+)\s*(?:\(([^)]*)\))?\s*(?:returns\s+([^;{]+))?/g)].map((m) => ({
95
112
  operationType: (m[1] as 'action' | 'function' | 'event') ?? 'action',
@@ -109,6 +126,7 @@ export async function parseCdsFile(repoPath: string, filePath: string): Promise<
109
126
  const namespace = /namespace\s+([\w.]+)\s*;/.exec(masked)?.[1];
110
127
  const services: CdsServiceFact[] = [];
111
128
  const pendingAnnotations: Array<{ end: number; raw: string }> = [];
129
+ const usings = collectUsings(text);
112
130
  for (const a of masked.matchAll(/@\s*\(/g)) pendingAnnotations.push(annotationRawAt(text, masked, a.index ?? 0));
113
131
  const serviceRegex = /\b(?:(extend)\s+)?(?:(service)\s+)?([A-Za-z_]\w*(?:\.[A-Za-z_]\w*)*)\b/g;
114
132
  let match: RegExpExecArray | null;
@@ -131,6 +149,7 @@ export async function parseCdsFile(repoPath: string, filePath: string): Promise<
131
149
  const body = masked.slice(open + 1, end);
132
150
  const name = match[3] ?? 'UnknownService';
133
151
  const serviceName = name.split('.').pop() ?? name;
152
+ const imported = isExtend ? usings.get(name) ?? usings.get(serviceName) : undefined;
134
153
  const servicePath = ensureLeadingSlash(pathAnnotation(annotations) ?? serviceName);
135
154
  services.push({
136
155
  namespace,
@@ -140,14 +159,16 @@ export async function parseCdsFile(repoPath: string, filePath: string): Promise<
140
159
  isExtend,
141
160
  sourceFile: normalizePath(filePath),
142
161
  sourceLine: lineOf(text, match.index),
143
- operations: operationsFromBody(text, body, open + 1, filePath)
162
+ operations: operationsFromBody(text, body, open + 1, filePath),
163
+ extension: isExtend ? { localReference: name, importedSymbol: imported?.importedSymbol, localAlias: imported?.localAlias, moduleSpecifier: imported?.moduleSpecifier, importKind: imported?.importKind ?? 'none' } : undefined
144
164
  });
145
165
  serviceRegex.lastIndex = end + 1;
146
166
  }
147
167
  const baseOps = new Map(services.filter((s) => !s.isExtend).map((s) => [s.qualifiedName, s.operations]));
148
168
  for (const service of services.filter((s) => s.isExtend && s.operations.length === 0)) {
169
+ if (service.extension?.moduleSpecifier) continue;
149
170
  const inherited = baseOps.get(service.qualifiedName) ?? baseOps.get(service.serviceName);
150
- if (inherited) service.operations = inherited.map((op) => ({ ...op, sourceFile: service.sourceFile, sourceLine: service.sourceLine }));
171
+ if (inherited) service.operations = inherited.map((op) => ({ ...op, provenance: 'inherited' }));
151
172
  }
152
173
  return services;
153
174
  }
@@ -105,37 +105,40 @@ function placeholders(expr: ts.TemplateExpression): string[] {
105
105
  function isFunctionLikeScope(node: ts.Node): boolean {
106
106
  return ts.isFunctionLike(node) || ts.isSourceFile(node);
107
107
  }
108
- function containingScope(node: ts.Node): ts.Node {
109
- let current: ts.Node | undefined = node.parent;
110
- while (current && !isFunctionLikeScope(current)) current = current.parent;
111
- return current ?? node.getSourceFile();
112
- }
113
108
  function nodeContains(parent: ts.Node, child: ts.Node): boolean {
114
- return child.getStart(child.getSourceFile()) >= parent.getStart(parent.getSourceFile()) && child.getEnd() <= parent.getEnd();
115
- }
116
- function nestedFunctionContains(scope: ts.Node, candidate: ts.Node, use: ts.Node): boolean {
117
- let current = candidate.parent;
118
- while (current && current !== scope) {
119
- if (isFunctionLikeScope(current) && !nodeContains(current, use)) return true;
120
- current = current.parent;
109
+ const source = child.getSourceFile();
110
+ return child.getStart(source) >= parent.getStart(source) && child.getEnd() <= parent.getEnd();
111
+ }
112
+ function declarationScope(node: ts.VariableDeclaration | ts.ParameterDeclaration): ts.Node {
113
+ if (ts.isParameter(node)) return node.parent;
114
+ const list = node.parent;
115
+ const blockScoped = (list.flags & (ts.NodeFlags.Const | ts.NodeFlags.Let)) !== 0;
116
+ let current: ts.Node = list.parent;
117
+ if (!blockScoped) {
118
+ while (current.parent && !isFunctionLikeScope(current)) current = current.parent;
119
+ return current;
121
120
  }
122
- return false;
121
+ while (current.parent && !ts.isBlock(current) && !ts.isSourceFile(current) && !ts.isModuleBlock(current) && !ts.isCaseBlock(current) && !isFunctionLikeScope(current)) current = current.parent;
122
+ return current;
123
+ }
124
+ function isAccessibleDeclaration(declaration: ts.VariableDeclaration | ts.ParameterDeclaration, use: ts.Node): boolean {
125
+ const source = use.getSourceFile();
126
+ if (declaration.name.getStart(source) >= use.getStart(source)) return false;
127
+ const scope = declarationScope(declaration);
128
+ return ts.isSourceFile(scope) || nodeContains(scope, use);
123
129
  }
124
130
  function resolveBinding(identifier: ts.Identifier, use: ts.Node): BindingResolution {
125
- const scope = containingScope(use);
126
131
  const source = use.getSourceFile();
127
132
  let best: ts.VariableDeclaration | ts.ParameterDeclaration | undefined;
128
133
  const visit = (node: ts.Node): void => {
129
- if (node !== scope && isFunctionLikeScope(node)) return;
130
- if (node.getStart(source) >= identifier.getStart(source)) return;
131
- if (ts.isVariableDeclaration(node) && ts.isIdentifier(node.name) && node.name.text === identifier.text && !nestedFunctionContains(scope, node, use)) best = node;
132
- if (ts.isParameter(node) && ts.isIdentifier(node.name) && node.name.text === identifier.text && !nestedFunctionContains(scope, node, use)) best = node;
134
+ if (ts.isVariableDeclaration(node) && ts.isIdentifier(node.name) && node.name.text === identifier.text && isAccessibleDeclaration(node, use)) best = node;
135
+ if (ts.isParameter(node) && ts.isIdentifier(node.name) && node.name.text === identifier.text && isAccessibleDeclaration(node, use)) best = node;
133
136
  ts.forEachChild(node, visit);
134
137
  };
135
- visit(scope);
138
+ visit(source);
136
139
  if (!best) return { immutable: false, evidence: ['binding_not_found'] };
137
140
  const immutable = ts.isVariableDeclaration(best) && (best.parent.flags & ts.NodeFlags.Const) !== 0;
138
- return { declaration: best, initializer: ts.isVariableDeclaration(best) ? best.initializer : undefined, immutable, evidence: [immutable ? 'const_binding_before_use' : 'mutable_or_parameter_binding'] };
141
+ return { declaration: best, initializer: ts.isVariableDeclaration(best) ? best.initializer : undefined, immutable, evidence: [immutable ? 'lexical_const_binding_before_use' : 'lexical_mutable_or_parameter_binding'] };
139
142
  }
140
143
  function resolveExpression(expr: ts.Expression | undefined, use: ts.Node, policy: 'operation_path' | 'external' | 'literal', depth = 0, seen = new Set<ts.Node>()): ExpressionResolution {
141
144
  if (!expr) return { status: 'unknown', sourceKind: 'dynamic_expression', placeholderKeys: [], evidence: ['expression_missing'] };
@@ -177,7 +180,6 @@ function staticPathCandidates(identifier: ts.Identifier, call: ts.Node, method:
177
180
  const binding = resolveBinding(identifier, call);
178
181
  const declaration = binding.declaration;
179
182
  if (!declaration) return undefined;
180
- const scope = containingScope(call);
181
183
  const source = call.getSourceFile();
182
184
  const paths: string[] = [];
183
185
  let hasDynamicAssignments = false;
@@ -188,12 +190,15 @@ function staticPathCandidates(identifier: ts.Identifier, call: ts.Node, method:
188
190
  };
189
191
  if (ts.isVariableDeclaration(declaration)) addExpr(declaration.initializer, declaration);
190
192
  const visit = (node: ts.Node): void => {
191
- if (node !== scope && isFunctionLikeScope(node)) return;
193
+ if (node !== source && isFunctionLikeScope(node) && !nodeContains(node, call)) return;
192
194
  if (node.getStart(source) >= call.getStart(source)) return;
193
- if (ts.isBinaryExpression(node) && node.operatorToken.kind === ts.SyntaxKind.EqualsToken && ts.isIdentifier(node.left) && node.left.text === identifier.text) addExpr(node.right, node);
195
+ if (ts.isBinaryExpression(node) && node.operatorToken.kind === ts.SyntaxKind.EqualsToken && ts.isIdentifier(node.left)) {
196
+ const target = resolveBinding(node.left, node);
197
+ if (target.declaration === declaration) addExpr(node.right, node);
198
+ }
194
199
  ts.forEachChild(node, visit);
195
200
  };
196
- visit(scope);
201
+ visit(source);
197
202
  const candidatePaths = [...new Set(paths)];
198
203
  if (candidatePaths.length === 0) return undefined;
199
204
  const normalizedCandidateOperations = [...new Set(candidatePaths.map((candidate) => classifyODataPathIntent(candidate, method).topLevelOperationName).filter((value): value is string => Boolean(value)))];
@@ -467,7 +472,7 @@ function parseLocalServiceCalls(text: string, filePath: string): OutboundCallFac
467
472
  if (origin) aliases.set(node.name.text, { ...origin, chain: [...origin.chain, node.name.text] });
468
473
  }
469
474
  if (ts.isCallExpression(node)) {
470
- const parsed = serviceOperationCall(node.expression, aliases);
475
+ const parsed = serviceOperationCall(node, aliases);
471
476
  if (parsed && parsed.operation !== 'entities') calls.push({
472
477
  callType: 'local_service_call',
473
478
  operationPathExpr: `/${parsed.operation}`,
@@ -480,7 +485,8 @@ function parseLocalServiceCalls(text: string, filePath: string): OutboundCallFac
480
485
  confidence: 0.9,
481
486
  unresolvedReason: ['send', 'emit', 'publish', 'on'].includes(parsed.operation) ? 'transport_client_method' : undefined,
482
487
  evidence: parserEvidence(source, node, {
483
- classifier: 'local_cap_service_call',
488
+ classifier: parsed.classifier,
489
+ parserCallType: parsed.operation === 'send' ? 'transport_client_method' : parsed.classifier,
484
490
  localServiceLookup: parsed.lookup,
485
491
  localServiceName: parsed.service,
486
492
  operation: parsed.operation,
@@ -499,10 +505,17 @@ function serviceLookup(expr: ts.Expression, aliases: Map<string, { service: stri
499
505
  if (ts.isElementAccessExpression(expr) && expr.expression.getText() === 'cds.services' && ts.isStringLiteral(expr.argumentExpression)) return { service: expr.argumentExpression.text, lookup: expr.getText(), chain: [expr.getText()] };
500
506
  return undefined;
501
507
  }
502
- function serviceOperationCall(expr: ts.Expression, aliases: Map<string, { service: string; lookup: string; chain: string[] }>): { service: string; lookup: string; chain: string[]; operation: string } | undefined {
508
+ function serviceOperationCall(node: ts.CallExpression, aliases: Map<string, { service: string; lookup: string; chain: string[] }>): { service: string; lookup: string; chain: string[]; operation: string; classifier: string } | undefined {
509
+ const expr = node.expression;
503
510
  if (!ts.isPropertyAccessExpression(expr)) return undefined;
504
- const operation = expr.name.text;
505
511
  const origin = serviceLookup(expr.expression, aliases);
506
512
  if (!origin) return undefined;
507
- return { ...origin, operation };
513
+ if (expr.name.text === 'send') {
514
+ const first = literalText(node.arguments[0]);
515
+ const second = literalText(node.arguments[1]);
516
+ const method = first?.toUpperCase();
517
+ if (method && ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD'].includes(method) && second) return { ...origin, operation: second.replace(/^\//, ''), classifier: 'cap_service_send_method_path' };
518
+ if (first) return { ...origin, operation: first.replace(/^\//, ''), classifier: 'cap_service_send_local_dispatch' };
519
+ }
520
+ return { ...origin, operation: expr.name.text, classifier: 'local_cap_service_call' };
508
521
  }
package/src/types.ts CHANGED
@@ -70,6 +70,14 @@ export interface CdsServiceFact {
70
70
  sourceFile: string;
71
71
  sourceLine: number;
72
72
  operations: CdsOperationFact[];
73
+ extension?: CdsExtensionFact;
74
+ }
75
+ export interface CdsExtensionFact {
76
+ localReference: string;
77
+ importedSymbol?: string;
78
+ localAlias?: string;
79
+ moduleSpecifier?: string;
80
+ importKind?: 'relative' | 'package' | 'none';
73
81
  }
74
82
  export interface CdsOperationFact {
75
83
  operationType: 'action' | 'function' | 'event';
@@ -79,6 +87,8 @@ export interface CdsOperationFact {
79
87
  returnType?: string;
80
88
  sourceFile: string;
81
89
  sourceLine: number;
90
+ provenance?: 'direct' | 'inherited';
91
+ baseOperationId?: number;
82
92
  }
83
93
  export interface HandlerClassFact {
84
94
  className: string;