@saptools/service-flow 0.1.39 → 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/CHANGELOG.md +14 -0
- package/README.md +4 -0
- package/TECHNICAL-NOTE.md +4 -0
- package/dist/{chunk-SAZ5OK7R.js → chunk-7L4QKKGN.js} +189 -86
- package/dist/chunk-7L4QKKGN.js.map +1 -0
- package/dist/cli.js +79 -9
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +10 -0
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/src/db/migrations.ts +14 -1
- package/src/db/repositories.ts +9 -2
- package/src/db/schema.ts +4 -2
- package/src/indexer/cds-extension-resolver.ts +65 -0
- package/src/indexer/workspace-indexer.ts +2 -0
- package/src/parsers/cds-parser.ts +43 -16
- package/src/parsers/outbound-call-parser.ts +142 -62
- package/src/types.ts +10 -0
- package/dist/chunk-SAZ5OK7R.js.map +0 -1
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
package/package.json
CHANGED
package/src/db/migrations.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Db } from './connection.js';
|
|
2
2
|
import { schemaSql } from './schema.js';
|
|
3
|
-
const CURRENT_SCHEMA_VERSION =
|
|
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' },
|
package/src/db/repositories.ts
CHANGED
|
@@ -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(
|
|
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) {
|
|
@@ -73,19 +73,40 @@ function collectAnnotations(text: string, index: number): { end: number; raw: st
|
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
function pathAnnotation(raw: string): string | undefined {
|
|
76
|
-
return /path\s*:\s*
|
|
76
|
+
return /path\s*:\s*(['"])(.*?)\1/s.exec(raw)?.[2];
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
-
function matchingBrace(
|
|
79
|
+
function matchingBrace(maskedText: string, open: number): number {
|
|
80
80
|
let depth = 0;
|
|
81
|
-
for (let i = open; i <
|
|
82
|
-
if (
|
|
83
|
-
if (
|
|
81
|
+
for (let i = open; i < maskedText.length; i += 1) {
|
|
82
|
+
if (maskedText[i] === '{') depth += 1;
|
|
83
|
+
if (maskedText[i] === '}') depth -= 1;
|
|
84
84
|
if (depth === 0) return i;
|
|
85
85
|
}
|
|
86
|
-
return
|
|
86
|
+
return maskedText.length - 1;
|
|
87
87
|
}
|
|
88
|
+
function annotationRawAt(original: string, masked: string, index: number): { end: number; raw: string } {
|
|
89
|
+
const collected = collectAnnotations(masked, index);
|
|
90
|
+
return { end: collected.end, raw: original.slice(index, collected.end) };
|
|
91
|
+
}
|
|
92
|
+
|
|
88
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
|
+
}
|
|
89
110
|
function operationsFromBody(text: string, maskedBody: string, bodyOffset: number, filePath: string): CdsOperationFact[] {
|
|
90
111
|
return [...maskedBody.matchAll(/\b(action|function|event)\s+(\w+)\s*(?:\(([^)]*)\))?\s*(?:returns\s+([^;{]+))?/g)].map((m) => ({
|
|
91
112
|
operationType: (m[1] as 'action' | 'function' | 'event') ?? 'action',
|
|
@@ -105,16 +126,19 @@ export async function parseCdsFile(repoPath: string, filePath: string): Promise<
|
|
|
105
126
|
const namespace = /namespace\s+([\w.]+)\s*;/.exec(masked)?.[1];
|
|
106
127
|
const services: CdsServiceFact[] = [];
|
|
107
128
|
const pendingAnnotations: Array<{ end: number; raw: string }> = [];
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
}
|
|
112
|
-
const serviceRegex = /\b(extend\s+)?service\s+([\w.]+)\b/g;
|
|
129
|
+
const usings = collectUsings(text);
|
|
130
|
+
for (const a of masked.matchAll(/@\s*\(/g)) pendingAnnotations.push(annotationRawAt(text, masked, a.index ?? 0));
|
|
131
|
+
const serviceRegex = /\b(?:(extend)\s+)?(?:(service)\s+)?([A-Za-z_]\w*(?:\.[A-Za-z_]\w*)*)\b/g;
|
|
113
132
|
let match: RegExpExecArray | null;
|
|
114
133
|
while ((match = serviceRegex.exec(masked))) {
|
|
115
|
-
const
|
|
134
|
+
const isExtend = match[1] === 'extend';
|
|
135
|
+
const hasServiceKeyword = match[2] === 'service';
|
|
136
|
+
if (!isExtend && !hasServiceKeyword) continue;
|
|
137
|
+
const afterName = annotationRawAt(text, masked, serviceRegex.lastIndex);
|
|
116
138
|
const open = masked.indexOf('{', afterName.end);
|
|
117
139
|
if (open === -1) continue;
|
|
140
|
+
const between = masked.slice(afterName.end, open).trim();
|
|
141
|
+
if (between.length > 0) continue;
|
|
118
142
|
const matchIndex = match.index;
|
|
119
143
|
const prefix = pendingAnnotations
|
|
120
144
|
.filter((a) => a.end <= matchIndex && matchIndex - a.end < 8)
|
|
@@ -123,25 +147,28 @@ export async function parseCdsFile(repoPath: string, filePath: string): Promise<
|
|
|
123
147
|
const annotations = `${prefix}${afterName.raw}`;
|
|
124
148
|
const end = matchingBrace(masked, open);
|
|
125
149
|
const body = masked.slice(open + 1, end);
|
|
126
|
-
const name = match[
|
|
150
|
+
const name = match[3] ?? 'UnknownService';
|
|
127
151
|
const serviceName = name.split('.').pop() ?? name;
|
|
152
|
+
const imported = isExtend ? usings.get(name) ?? usings.get(serviceName) : undefined;
|
|
128
153
|
const servicePath = ensureLeadingSlash(pathAnnotation(annotations) ?? serviceName);
|
|
129
154
|
services.push({
|
|
130
155
|
namespace,
|
|
131
156
|
serviceName,
|
|
132
157
|
qualifiedName: name.includes('.') ? name : namespace ? `${namespace}.${name}` : name,
|
|
133
158
|
servicePath,
|
|
134
|
-
isExtend
|
|
159
|
+
isExtend,
|
|
135
160
|
sourceFile: normalizePath(filePath),
|
|
136
161
|
sourceLine: lineOf(text, match.index),
|
|
137
|
-
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
|
|
138
164
|
});
|
|
139
165
|
serviceRegex.lastIndex = end + 1;
|
|
140
166
|
}
|
|
141
167
|
const baseOps = new Map(services.filter((s) => !s.isExtend).map((s) => [s.qualifiedName, s.operations]));
|
|
142
168
|
for (const service of services.filter((s) => s.isExtend && s.operations.length === 0)) {
|
|
169
|
+
if (service.extension?.moduleSpecifier) continue;
|
|
143
170
|
const inherited = baseOps.get(service.qualifiedName) ?? baseOps.get(service.serviceName);
|
|
144
|
-
if (inherited) service.operations = inherited.map((op) => ({ ...op,
|
|
171
|
+
if (inherited) service.operations = inherited.map((op) => ({ ...op, provenance: 'inherited' }));
|
|
145
172
|
}
|
|
146
173
|
return services;
|
|
147
174
|
}
|