@saptools/service-flow 0.1.6 → 0.1.7
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 +10 -0
- package/README.md +19 -2
- package/TECHNICAL-NOTE.md +2 -2
- package/dist/{chunk-6C5HZ6IR.js → chunk-YFT57U54.js} +116 -124
- package/dist/chunk-YFT57U54.js.map +1 -0
- package/dist/cli.js +141 -144
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +8 -2
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-6C5HZ6IR.js.map +0 -1
package/dist/cli.js
CHANGED
|
@@ -10,12 +10,12 @@ import {
|
|
|
10
10
|
parsePackageJson,
|
|
11
11
|
parseServiceBindings,
|
|
12
12
|
trace
|
|
13
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-YFT57U54.js";
|
|
14
14
|
|
|
15
15
|
// src/cli.ts
|
|
16
16
|
import { Command } from "commander";
|
|
17
|
-
import
|
|
18
|
-
import
|
|
17
|
+
import path5 from "path";
|
|
18
|
+
import fs5 from "fs/promises";
|
|
19
19
|
import pc from "picocolors";
|
|
20
20
|
|
|
21
21
|
// src/config/defaults.ts
|
|
@@ -90,7 +90,7 @@ import path2 from "path";
|
|
|
90
90
|
// src/db/schema.ts
|
|
91
91
|
var schemaSql = `
|
|
92
92
|
CREATE TABLE IF NOT EXISTS workspaces (id INTEGER PRIMARY KEY, root_path TEXT UNIQUE NOT NULL, db_path TEXT NOT NULL, created_at TEXT NOT NULL, updated_at TEXT NOT NULL);
|
|
93
|
-
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, UNIQUE(workspace_id, absolute_path), FOREIGN KEY(workspace_id) REFERENCES workspaces(id) ON DELETE CASCADE);
|
|
93
|
+
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, UNIQUE(workspace_id, absolute_path), FOREIGN KEY(workspace_id) REFERENCES workspaces(id) ON DELETE CASCADE);
|
|
94
94
|
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);
|
|
95
95
|
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);
|
|
96
96
|
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);
|
|
@@ -98,11 +98,11 @@ CREATE TABLE IF NOT EXISTS cds_operations (id INTEGER PRIMARY KEY, service_id IN
|
|
|
98
98
|
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, FOREIGN KEY(repo_id) REFERENCES repositories(id) ON DELETE CASCADE, FOREIGN KEY(file_id) REFERENCES files(id) ON DELETE CASCADE);
|
|
99
99
|
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);
|
|
100
100
|
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);
|
|
101
|
-
CREATE TABLE IF NOT EXISTS handler_registrations (id INTEGER PRIMARY KEY, repo_id INTEGER NOT NULL, handler_class_id INTEGER, registration_file TEXT NOT NULL, registration_line INTEGER NOT NULL, registration_kind TEXT NOT NULL, confidence REAL NOT NULL, FOREIGN KEY(repo_id) REFERENCES repositories(id) ON DELETE CASCADE, FOREIGN KEY(handler_class_id) REFERENCES handler_classes(id) ON DELETE SET NULL);
|
|
101
|
+
CREATE TABLE IF NOT EXISTS handler_registrations (id INTEGER PRIMARY KEY, repo_id INTEGER NOT NULL, handler_class_id INTEGER, class_name TEXT, import_source TEXT, registration_file TEXT NOT NULL, registration_line INTEGER NOT NULL, registration_kind TEXT NOT NULL, confidence REAL NOT NULL, FOREIGN KEY(repo_id) REFERENCES repositories(id) ON DELETE CASCADE, FOREIGN KEY(handler_class_id) REFERENCES handler_classes(id) ON DELETE SET NULL);
|
|
102
102
|
CREATE TABLE IF NOT EXISTS service_bindings (id INTEGER PRIMARY KEY, repo_id INTEGER NOT NULL, symbol_id INTEGER, variable_name TEXT NOT NULL, alias TEXT, alias_expr TEXT, destination_expr TEXT, service_path_expr TEXT, is_dynamic INTEGER NOT NULL, placeholders_json TEXT NOT NULL, source_file TEXT NOT NULL, source_line INTEGER NOT NULL, helper_chain_json TEXT, FOREIGN KEY(repo_id) REFERENCES repositories(id) ON DELETE CASCADE, FOREIGN KEY(symbol_id) REFERENCES symbols(id) ON DELETE SET NULL);
|
|
103
103
|
CREATE TABLE IF NOT EXISTS outbound_calls (id INTEGER PRIMARY KEY, repo_id INTEGER NOT NULL, source_symbol_id INTEGER, call_type TEXT NOT NULL, service_binding_id INTEGER, method TEXT, operation_path_expr TEXT, query_entity TEXT, event_name_expr TEXT, payload_summary TEXT, source_file TEXT NOT NULL, source_line INTEGER NOT NULL, confidence REAL NOT NULL, unresolved_reason TEXT, FOREIGN KEY(repo_id) REFERENCES repositories(id) ON DELETE CASCADE, FOREIGN KEY(source_symbol_id) REFERENCES symbols(id) ON DELETE SET NULL, FOREIGN KEY(service_binding_id) REFERENCES service_bindings(id) ON DELETE SET NULL);
|
|
104
|
-
CREATE TABLE IF NOT EXISTS graph_edges (id INTEGER PRIMARY KEY, workspace_id INTEGER NOT NULL, edge_type TEXT NOT NULL, status TEXT NOT NULL DEFAULT 'unresolved', from_kind TEXT NOT NULL, from_id TEXT NOT NULL, to_kind TEXT NOT NULL, to_id TEXT NOT NULL, confidence REAL NOT NULL, evidence_json TEXT NOT NULL, is_dynamic INTEGER NOT NULL, unresolved_reason TEXT, FOREIGN KEY(workspace_id) REFERENCES workspaces(id) ON DELETE CASCADE);
|
|
105
|
-
CREATE TABLE IF NOT EXISTS index_runs (id INTEGER PRIMARY KEY, workspace_id INTEGER NOT NULL, started_at TEXT NOT NULL, finished_at TEXT, status TEXT NOT NULL, repo_count INTEGER NOT NULL, file_count INTEGER NOT NULL, diagnostic_count INTEGER NOT NULL, FOREIGN KEY(workspace_id) REFERENCES workspaces(id) ON DELETE CASCADE);
|
|
104
|
+
CREATE TABLE IF NOT EXISTS graph_edges (id INTEGER PRIMARY KEY, workspace_id INTEGER NOT NULL, edge_type TEXT NOT NULL, status TEXT NOT NULL DEFAULT 'unresolved', from_kind TEXT NOT NULL, from_id TEXT NOT NULL, to_kind TEXT NOT NULL, to_id TEXT NOT NULL, confidence REAL NOT NULL, evidence_json TEXT NOT NULL, is_dynamic INTEGER NOT NULL, unresolved_reason TEXT, generation INTEGER NOT NULL DEFAULT 0, FOREIGN KEY(workspace_id) REFERENCES workspaces(id) ON DELETE CASCADE);
|
|
105
|
+
CREATE TABLE IF NOT EXISTS index_runs (id INTEGER PRIMARY KEY, workspace_id INTEGER NOT NULL, started_at TEXT NOT NULL, finished_at TEXT, status TEXT NOT NULL, repo_count INTEGER NOT NULL, file_count INTEGER NOT NULL, diagnostic_count INTEGER NOT NULL, error_message TEXT, FOREIGN KEY(workspace_id) REFERENCES workspaces(id) ON DELETE CASCADE);
|
|
106
106
|
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);
|
|
107
107
|
CREATE INDEX IF NOT EXISTS idx_repo_name ON repositories(name);
|
|
108
108
|
CREATE INDEX IF NOT EXISTS idx_service_path ON cds_services(service_path);
|
|
@@ -112,7 +112,31 @@ CREATE VIRTUAL TABLE IF NOT EXISTS search_index USING fts5(kind, name, path, rep
|
|
|
112
112
|
`;
|
|
113
113
|
|
|
114
114
|
// src/db/migrations.ts
|
|
115
|
-
var CURRENT_SCHEMA_VERSION =
|
|
115
|
+
var CURRENT_SCHEMA_VERSION = 3;
|
|
116
|
+
var columns = {
|
|
117
|
+
service_bindings: [
|
|
118
|
+
{ name: "helper_chain_json", ddl: "ALTER TABLE service_bindings ADD COLUMN helper_chain_json TEXT" },
|
|
119
|
+
{ name: "alias_expr", ddl: "ALTER TABLE service_bindings ADD COLUMN alias_expr TEXT" }
|
|
120
|
+
],
|
|
121
|
+
repositories: [
|
|
122
|
+
{ name: "fingerprint", ddl: "ALTER TABLE repositories ADD COLUMN fingerprint TEXT" },
|
|
123
|
+
{ name: "fact_generation", ddl: "ALTER TABLE repositories ADD COLUMN fact_generation INTEGER NOT NULL DEFAULT 0" },
|
|
124
|
+
{ name: "graph_generation", ddl: "ALTER TABLE repositories ADD COLUMN graph_generation INTEGER NOT NULL DEFAULT 0" },
|
|
125
|
+
{ name: "graph_stale_reason", ddl: "ALTER TABLE repositories ADD COLUMN graph_stale_reason TEXT" },
|
|
126
|
+
{ name: "graph_stale_at", ddl: "ALTER TABLE repositories ADD COLUMN graph_stale_at TEXT" }
|
|
127
|
+
],
|
|
128
|
+
graph_edges: [
|
|
129
|
+
{ name: "status", ddl: "ALTER TABLE graph_edges ADD COLUMN status TEXT NOT NULL DEFAULT 'unresolved'" },
|
|
130
|
+
{ name: "generation", ddl: "ALTER TABLE graph_edges ADD COLUMN generation INTEGER NOT NULL DEFAULT 0" }
|
|
131
|
+
],
|
|
132
|
+
handler_registrations: [
|
|
133
|
+
{ name: "class_name", ddl: "ALTER TABLE handler_registrations ADD COLUMN class_name TEXT" },
|
|
134
|
+
{ name: "import_source", ddl: "ALTER TABLE handler_registrations ADD COLUMN import_source TEXT" }
|
|
135
|
+
],
|
|
136
|
+
index_runs: [
|
|
137
|
+
{ name: "error_message", ddl: "ALTER TABLE index_runs ADD COLUMN error_message TEXT" }
|
|
138
|
+
]
|
|
139
|
+
};
|
|
116
140
|
function hasColumn(db, table, column) {
|
|
117
141
|
return db.prepare(`PRAGMA table_info(${table})`).all().some((row) => row.name === column);
|
|
118
142
|
}
|
|
@@ -120,15 +144,27 @@ function userVersion(db) {
|
|
|
120
144
|
const row = db.pragma("user_version")[0];
|
|
121
145
|
return Number(row?.user_version ?? 0);
|
|
122
146
|
}
|
|
147
|
+
function addMissingColumns(db) {
|
|
148
|
+
for (const [table, tableColumns] of Object.entries(columns)) {
|
|
149
|
+
for (const column of tableColumns) {
|
|
150
|
+
if (!hasColumn(db, table, column.name)) db.prepare(column.ddl).run();
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
function normalizeLegacyStatus(db) {
|
|
155
|
+
db.prepare("UPDATE graph_edges SET status=CASE WHEN edge_type='REMOTE_CALL_RESOLVES_TO_OPERATION' THEN 'resolved' WHEN edge_type IN ('HANDLER_RUNS_DB_QUERY','HANDLER_CALLS_EXTERNAL_HTTP','HANDLER_EMITS_EVENT','EVENT_CONSUMED_BY_HANDLER') THEN 'terminal' WHEN edge_type='DYNAMIC_EDGE_CANDIDATE' THEN 'dynamic' WHEN status='ambiguous' THEN 'ambiguous' ELSE status END").run();
|
|
156
|
+
db.prepare("UPDATE repositories SET graph_stale_reason='schema_migration_requires_relink', graph_stale_at=COALESCE(graph_stale_at, datetime('now')) WHERE EXISTS (SELECT 1 FROM graph_edges WHERE graph_edges.workspace_id=repositories.workspace_id) AND graph_generation=0").run();
|
|
157
|
+
}
|
|
123
158
|
function migrate(db) {
|
|
124
159
|
db.transaction(() => {
|
|
160
|
+
const version = userVersion(db);
|
|
161
|
+
if (version > CURRENT_SCHEMA_VERSION) throw new Error(`Unsupported future service-flow schema version ${version}`);
|
|
125
162
|
db.exec(schemaSql);
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
if (
|
|
130
|
-
db.
|
|
131
|
-
db.pragma(`user_version = ${Math.max(userVersion(db), CURRENT_SCHEMA_VERSION)}`);
|
|
163
|
+
addMissingColumns(db);
|
|
164
|
+
normalizeLegacyStatus(db);
|
|
165
|
+
const violations = db.pragma("foreign_key_check");
|
|
166
|
+
if (violations.length > 0) throw new Error("SQLite foreign_key_check failed during migration");
|
|
167
|
+
db.pragma(`user_version = ${CURRENT_SCHEMA_VERSION}`);
|
|
132
168
|
});
|
|
133
169
|
}
|
|
134
170
|
|
|
@@ -144,7 +180,7 @@ function loadSqlite() {
|
|
|
144
180
|
return sqlite;
|
|
145
181
|
} catch (error) {
|
|
146
182
|
throw new Error(
|
|
147
|
-
"service-flow 0.1.
|
|
183
|
+
"service-flow 0.1.7 requires Node.js >=24 with node:sqlite DatabaseSync support. Upgrade Node.js or install a service-flow build with a compatible SQLite driver.",
|
|
148
184
|
{ cause: error }
|
|
149
185
|
);
|
|
150
186
|
}
|
|
@@ -360,17 +396,23 @@ function insertHandler(db, repoId, h) {
|
|
|
360
396
|
}
|
|
361
397
|
function insertRegistrations(db, repoId, rows) {
|
|
362
398
|
const stmt = db.prepare(
|
|
363
|
-
"INSERT INTO handler_registrations(repo_id,handler_class_id,registration_file,registration_line,registration_kind,confidence) VALUES(
|
|
399
|
+
"INSERT INTO handler_registrations(repo_id,handler_class_id,class_name,import_source,registration_file,registration_line,registration_kind,confidence) VALUES(?,?,?,?,?,?,?,?)"
|
|
364
400
|
);
|
|
365
|
-
for (const r of rows)
|
|
401
|
+
for (const r of rows) {
|
|
402
|
+
const handlerClass = r.className ? db.prepare(
|
|
403
|
+
"SELECT id FROM handler_classes WHERE repo_id=? AND class_name=? ORDER BY id"
|
|
404
|
+
).all(repoId, r.className) : [];
|
|
366
405
|
stmt.run(
|
|
367
406
|
repoId,
|
|
368
|
-
null,
|
|
407
|
+
handlerClass.length === 1 ? handlerClass[0]?.id : null,
|
|
408
|
+
r.className,
|
|
409
|
+
r.importSource,
|
|
369
410
|
r.registrationFile,
|
|
370
411
|
r.registrationLine,
|
|
371
412
|
r.registrationKind,
|
|
372
413
|
r.confidence
|
|
373
414
|
);
|
|
415
|
+
}
|
|
374
416
|
}
|
|
375
417
|
function insertBindings(db, repoId, rows) {
|
|
376
418
|
const stmt = db.prepare(
|
|
@@ -453,11 +495,12 @@ async function findFiles(root, suffix) {
|
|
|
453
495
|
return out;
|
|
454
496
|
}
|
|
455
497
|
|
|
456
|
-
// src/
|
|
457
|
-
|
|
458
|
-
|
|
498
|
+
// src/utils/diagnostics.ts
|
|
499
|
+
function errorMessage(error) {
|
|
500
|
+
return error instanceof Error ? error.message : String(error);
|
|
501
|
+
}
|
|
459
502
|
|
|
460
|
-
// src/indexer/
|
|
503
|
+
// src/indexer/repository-indexer.ts
|
|
461
504
|
import fs4 from "fs/promises";
|
|
462
505
|
import path4 from "path";
|
|
463
506
|
|
|
@@ -471,32 +514,10 @@ function sha256Text(text) {
|
|
|
471
514
|
return createHash("sha256").update(text).digest("hex");
|
|
472
515
|
}
|
|
473
516
|
|
|
474
|
-
// src/indexer/incremental-index.ts
|
|
475
|
-
async function recordFile(db, repoId, repoPath, relativeFile) {
|
|
476
|
-
const abs = path4.join(repoPath, relativeFile);
|
|
477
|
-
const stat = await fs4.stat(abs);
|
|
478
|
-
const hash = await sha256File(abs);
|
|
479
|
-
db.prepare(
|
|
480
|
-
"INSERT INTO files(repo_id,relative_path,extension,sha256,size_bytes,last_indexed_at) VALUES(?,?,?,?,?,?) ON CONFLICT(repo_id,relative_path) DO UPDATE SET sha256=excluded.sha256,size_bytes=excluded.size_bytes,last_indexed_at=excluded.last_indexed_at"
|
|
481
|
-
).run(
|
|
482
|
-
repoId,
|
|
483
|
-
normalizePath(relativeFile),
|
|
484
|
-
path4.extname(relativeFile),
|
|
485
|
-
hash,
|
|
486
|
-
stat.size,
|
|
487
|
-
(/* @__PURE__ */ new Date()).toISOString()
|
|
488
|
-
);
|
|
489
|
-
}
|
|
490
|
-
|
|
491
|
-
// src/utils/diagnostics.ts
|
|
492
|
-
function errorMessage(error) {
|
|
493
|
-
return error instanceof Error ? error.message : String(error);
|
|
494
|
-
}
|
|
495
|
-
|
|
496
517
|
// package.json
|
|
497
518
|
var package_default = {
|
|
498
519
|
name: "@saptools/service-flow",
|
|
499
|
-
version: "0.1.
|
|
520
|
+
version: "0.1.7",
|
|
500
521
|
description: "Trace SAP CAP service-to-service flows across multi-repository workspaces with runtime-aware graph resolution",
|
|
501
522
|
type: "module",
|
|
502
523
|
publishConfig: {
|
|
@@ -572,80 +593,59 @@ var ANALYZER_VERSION = package_default.version;
|
|
|
572
593
|
|
|
573
594
|
// src/indexer/repository-indexer.ts
|
|
574
595
|
async function indexRepository(db, repo, force) {
|
|
575
|
-
let diagnostics = 0;
|
|
576
|
-
let files = 0;
|
|
577
596
|
const sourceFiles = await findSourceFiles(repo.absolute_path);
|
|
578
|
-
const
|
|
579
|
-
const fingerprint = await repositoryFingerprint(repo.absolute_path, sourceFiles,
|
|
597
|
+
const packageFacts = await parsePackageJson(repo.absolute_path);
|
|
598
|
+
const fingerprint = await repositoryFingerprint(repo.absolute_path, sourceFiles, packageFacts);
|
|
580
599
|
if (!force && repo.fingerprint === fingerprint) return { fileCount: 0, diagnosticCount: 0, skipped: true };
|
|
581
|
-
const kind = await classifyRepository(repo.absolute_path,
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
await parseOutboundCalls(repo.absolute_path, file)
|
|
618
|
-
);
|
|
619
|
-
}
|
|
620
|
-
} catch (error) {
|
|
621
|
-
diagnostics += 1;
|
|
622
|
-
db.prepare(
|
|
623
|
-
"INSERT INTO diagnostics(repo_id,severity,code,message,source_file) VALUES(?,?,?,?,?)"
|
|
624
|
-
).run(repo.id, "warning", "parse_failed", errorMessage(error), file);
|
|
600
|
+
const kind = await classifyRepository(repo.absolute_path, packageFacts);
|
|
601
|
+
try {
|
|
602
|
+
const parsed = await parseAllSourceFacts(repo.absolute_path, sourceFiles);
|
|
603
|
+
db.transaction(() => {
|
|
604
|
+
db.prepare("UPDATE repositories SET package_name=?, package_version=?, dependencies_json=?, kind=?, index_status=? WHERE id=?").run(packageFacts.packageName, packageFacts.packageVersion, JSON.stringify(packageFacts.dependencies), kind, "indexing", repo.id);
|
|
605
|
+
clearRepoFacts(db, repo.id);
|
|
606
|
+
insertRequires(db, repo.id, packageFacts.cdsRequires);
|
|
607
|
+
const fileStmt = db.prepare("INSERT INTO files(repo_id,relative_path,extension,sha256,size_bytes,last_indexed_at) VALUES(?,?,?,?,?,?) ON CONFLICT(repo_id,relative_path) DO UPDATE SET sha256=excluded.sha256,size_bytes=excluded.size_bytes,last_indexed_at=excluded.last_indexed_at");
|
|
608
|
+
for (const file of parsed.fileRecords) fileStmt.run(repo.id, file.relativePath, file.extension, file.sha256, file.sizeBytes, (/* @__PURE__ */ new Date()).toISOString());
|
|
609
|
+
for (const s of parsed.services) insertService(db, repo.id, s);
|
|
610
|
+
for (const h of parsed.handlers) insertHandler(db, repo.id, h);
|
|
611
|
+
insertRegistrations(db, repo.id, parsed.registrations);
|
|
612
|
+
insertBindings(db, repo.id, parsed.bindings);
|
|
613
|
+
insertCalls(db, repo.id, parsed.calls);
|
|
614
|
+
db.prepare("UPDATE repositories SET last_indexed_at=?, index_status='indexed', error_count=0, fingerprint=?, fact_generation=COALESCE(fact_generation,0)+1, graph_stale_reason='facts_changed', graph_stale_at=? WHERE id=?").run((/* @__PURE__ */ new Date()).toISOString(), fingerprint, (/* @__PURE__ */ new Date()).toISOString(), repo.id);
|
|
615
|
+
});
|
|
616
|
+
return { fileCount: sourceFiles.length, diagnosticCount: 0, skipped: false };
|
|
617
|
+
} catch (error) {
|
|
618
|
+
const message = errorMessage(error);
|
|
619
|
+
db.prepare("UPDATE repositories SET index_status='failed', error_count=1 WHERE id=?").run(repo.id);
|
|
620
|
+
db.prepare("INSERT INTO diagnostics(repo_id,severity,code,message) VALUES(?,?,?,?)").run(repo.id, "error", "index_failed_snapshot_preserved", message);
|
|
621
|
+
return { fileCount: 0, diagnosticCount: 1, skipped: false };
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
async function parseAllSourceFacts(root, files) {
|
|
625
|
+
const facts = { services: [], handlers: [], registrations: [], bindings: [], calls: [], fileRecords: [] };
|
|
626
|
+
for (const file of files) {
|
|
627
|
+
const abs = path4.join(root, file);
|
|
628
|
+
const stat = await fs4.stat(abs);
|
|
629
|
+
facts.fileRecords.push({ relativePath: normalizePath(file), extension: path4.extname(file), sha256: await sha256File(abs), sizeBytes: stat.size });
|
|
630
|
+
if (file.endsWith(".cds")) facts.services.push(...await parseCdsFile(root, file));
|
|
631
|
+
if (/\.[jt]s$/.test(file)) {
|
|
632
|
+
facts.handlers.push(...await parseDecorators(root, file));
|
|
633
|
+
facts.registrations.push(...await parseHandlerRegistrations(root, file));
|
|
634
|
+
facts.bindings.push(...await parseServiceBindings(root, file));
|
|
635
|
+
facts.calls.push(...await parseOutboundCalls(root, file));
|
|
625
636
|
}
|
|
626
637
|
}
|
|
627
|
-
|
|
628
|
-
"UPDATE repositories SET last_indexed_at=?, index_status=?, error_count=?, fingerprint=? WHERE id=?"
|
|
629
|
-
).run(
|
|
630
|
-
(/* @__PURE__ */ new Date()).toISOString(),
|
|
631
|
-
diagnostics ? "partial" : "indexed",
|
|
632
|
-
diagnostics,
|
|
633
|
-
fingerprint,
|
|
634
|
-
repo.id
|
|
635
|
-
);
|
|
636
|
-
return { fileCount: files, diagnosticCount: diagnostics, skipped: false };
|
|
638
|
+
return facts;
|
|
637
639
|
}
|
|
638
640
|
async function findSourceFiles(root) {
|
|
639
641
|
const out = [];
|
|
640
642
|
async function walk(dir, prefix = "") {
|
|
641
|
-
const entries = await
|
|
643
|
+
const entries = await fs4.readdir(dir, { withFileTypes: true }).catch(() => []);
|
|
642
644
|
for (const e of entries) {
|
|
643
645
|
const rel = prefix ? `${prefix}/${e.name}` : e.name;
|
|
644
646
|
if (e.isDirectory()) {
|
|
645
|
-
if (!["node_modules", "dist", "gen", "coverage", ".git"].includes(e.name))
|
|
646
|
-
|
|
647
|
-
} else if (/\.(cds|ts|js)$/.test(e.name) && !isDefaultTestFile(rel))
|
|
648
|
-
out.push(rel);
|
|
647
|
+
if (!["node_modules", "dist", "gen", "coverage", ".git"].includes(e.name)) await walk(path4.join(dir, e.name), rel);
|
|
648
|
+
} else if (/\.(cds|ts|js)$/.test(e.name) && !isDefaultTestFile(rel)) out.push(rel);
|
|
649
649
|
}
|
|
650
650
|
}
|
|
651
651
|
await walk(root);
|
|
@@ -653,13 +653,11 @@ async function findSourceFiles(root) {
|
|
|
653
653
|
}
|
|
654
654
|
function isDefaultTestFile(relativeFile) {
|
|
655
655
|
const parts = relativeFile.split("/");
|
|
656
|
-
if (parts.some((part) => ["test", "tests", "__tests__"].includes(part)))
|
|
657
|
-
return true;
|
|
656
|
+
if (parts.some((part) => ["test", "tests", "__tests__"].includes(part))) return true;
|
|
658
657
|
return /\.(test|spec)\.[jt]s$/.test(parts.at(-1) ?? "");
|
|
659
658
|
}
|
|
660
|
-
async function repositoryFingerprint(root, files, facts
|
|
661
|
-
|
|
662
|
-
const packageJson = await fs5.readFile(path5.join(root, "package.json"), "utf8").catch(() => "");
|
|
659
|
+
async function repositoryFingerprint(root, files, facts) {
|
|
660
|
+
const packageJson = await fs4.readFile(path4.join(root, "package.json"), "utf8").catch(() => "");
|
|
663
661
|
const normalizedFacts = {
|
|
664
662
|
analyzerVersion: ANALYZER_VERSION,
|
|
665
663
|
packageName: facts.packageName,
|
|
@@ -672,7 +670,7 @@ async function repositoryFingerprint(root, files, facts, force) {
|
|
|
672
670
|
};
|
|
673
671
|
const entries = [`facts:${JSON.stringify(normalizedFacts)}`];
|
|
674
672
|
for (const file of files) {
|
|
675
|
-
const content = await
|
|
673
|
+
const content = await fs4.readFile(path4.join(root, file), "utf8");
|
|
676
674
|
entries.push(`${file}:${sha256Text(content)}`);
|
|
677
675
|
}
|
|
678
676
|
return sha256Text(entries.join("\n"));
|
|
@@ -682,30 +680,23 @@ async function repositoryFingerprint(root, files, facts, force) {
|
|
|
682
680
|
async function indexWorkspace(db, workspaceId, options) {
|
|
683
681
|
const started = (/* @__PURE__ */ new Date()).toISOString();
|
|
684
682
|
const repos = options.repo ? [repoByName(db, options.repo)].filter((r) => r !== void 0) : listRepositories(db);
|
|
685
|
-
const runId = Number(
|
|
686
|
-
db.prepare(
|
|
687
|
-
"INSERT INTO index_runs(workspace_id,started_at,status,repo_count,file_count,diagnostic_count) VALUES(?,?,?,?,?,?) RETURNING id"
|
|
688
|
-
).get(workspaceId, started, "running", repos.length, 0, 0)?.id
|
|
689
|
-
);
|
|
683
|
+
const runId = Number(db.prepare("INSERT INTO index_runs(workspace_id,started_at,status,repo_count,file_count,diagnostic_count) VALUES(?,?,?,?,?,?) RETURNING id").get(workspaceId, started, "running", repos.length, 0, 0)?.id);
|
|
690
684
|
let fileCount = 0;
|
|
691
685
|
let diagnosticCount = 0;
|
|
692
686
|
let skippedCount = 0;
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
687
|
+
try {
|
|
688
|
+
for (const repo of repos) {
|
|
689
|
+
const result = await indexRepository(db, repo, options.force);
|
|
690
|
+
fileCount += result.fileCount;
|
|
691
|
+
diagnosticCount += result.diagnosticCount;
|
|
692
|
+
skippedCount += result.skipped ? 1 : 0;
|
|
693
|
+
}
|
|
694
|
+
db.prepare("UPDATE index_runs SET finished_at=?, status=?, file_count=?, diagnostic_count=? WHERE id=?").run((/* @__PURE__ */ new Date()).toISOString(), diagnosticCount ? "failed" : "success", fileCount, diagnosticCount, runId);
|
|
695
|
+
return { repoCount: repos.length, indexedCount: repos.length - skippedCount, skippedCount, fileCount, diagnosticCount };
|
|
696
|
+
} catch (error) {
|
|
697
|
+
db.prepare("UPDATE index_runs SET finished_at=?, status='failed', file_count=?, diagnostic_count=?, error_message=? WHERE id=?").run((/* @__PURE__ */ new Date()).toISOString(), fileCount, diagnosticCount + 1, errorMessage(error), runId);
|
|
698
|
+
throw error;
|
|
698
699
|
}
|
|
699
|
-
db.prepare(
|
|
700
|
-
"UPDATE index_runs SET finished_at=?, status=?, file_count=?, diagnostic_count=? WHERE id=?"
|
|
701
|
-
).run(
|
|
702
|
-
(/* @__PURE__ */ new Date()).toISOString(),
|
|
703
|
-
diagnosticCount ? "partial" : "success",
|
|
704
|
-
fileCount,
|
|
705
|
-
diagnosticCount,
|
|
706
|
-
runId
|
|
707
|
-
);
|
|
708
|
-
return { repoCount: repos.length, indexedCount: repos.length - skippedCount, skippedCount, fileCount, diagnosticCount };
|
|
709
700
|
}
|
|
710
701
|
|
|
711
702
|
// src/trace/selectors.ts
|
|
@@ -841,7 +832,7 @@ function createProgram() {
|
|
|
841
832
|
(opts) => void withWorkspace(opts.workspace, (db, workspaceId) => {
|
|
842
833
|
const r = linkWorkspace(db, workspaceId);
|
|
843
834
|
process.stdout.write(
|
|
844
|
-
`Linked ${r.edgeCount} edges: ${r.resolvedCount} remote resolved, ${r.unresolvedCount} remote unresolved, ${r.ambiguousCount} ambiguous, ${r.dynamicCount} dynamic, ${r.terminalCount} terminal
|
|
835
|
+
`Linked ${r.edgeCount} edges: ${r.resolvedCount} remote resolved, ${r.unresolvedCount} remote unresolved, ${r.ambiguousCount} remote ambiguous, ${r.dynamicCount} dynamic, ${r.terminalCount} terminal, ${r.dependencyResolvedCount} dependency resolved, ${r.dependencyAmbiguousCount} dependency ambiguous, ${r.implementationResolvedCount} implementation resolved, ${r.implementationAmbiguousCount} implementation ambiguous
|
|
845
836
|
`
|
|
846
837
|
);
|
|
847
838
|
}).catch(fail)
|
|
@@ -991,7 +982,13 @@ function createProgram() {
|
|
|
991
982
|
WHERE NOT EXISTS (SELECT 1 FROM search_index)
|
|
992
983
|
UNION ALL
|
|
993
984
|
SELECT 'error','foreign_key_violation','SQLite foreign_key_check reported integrity failures',NULL,NULL
|
|
994
|
-
WHERE EXISTS (SELECT 1 FROM pragma_foreign_key_check)
|
|
985
|
+
WHERE EXISTS (SELECT 1 FROM pragma_foreign_key_check)
|
|
986
|
+
UNION ALL
|
|
987
|
+
SELECT 'warning','graph_stale','Graph is stale after repository fact changes; run service-flow link',NULL,NULL
|
|
988
|
+
WHERE EXISTS (SELECT 1 FROM repositories WHERE graph_stale_reason IS NOT NULL)
|
|
989
|
+
UNION ALL
|
|
990
|
+
SELECT 'warning','index_run_abandoned','An index run is still marked running',NULL,NULL
|
|
991
|
+
WHERE EXISTS (SELECT 1 FROM index_runs WHERE status='running')`
|
|
995
992
|
).all(Boolean(opts.strict), Boolean(opts.strict));
|
|
996
993
|
const allDiagnostics = [...diagnostics, ...health];
|
|
997
994
|
process.stdout.write(
|
|
@@ -1003,20 +1000,20 @@ function createProgram() {
|
|
|
1003
1000
|
program.command("clean").option("--workspace <path>").option("--db-only").action(
|
|
1004
1001
|
(opts) => void (async () => {
|
|
1005
1002
|
const config = await loadWorkspaceConfig(opts.workspace);
|
|
1006
|
-
const dbDir =
|
|
1007
|
-
const workspaceRoot =
|
|
1008
|
-
await
|
|
1003
|
+
const dbDir = path5.resolve(path5.dirname(config.dbPath));
|
|
1004
|
+
const workspaceRoot = path5.resolve(config.rootPath);
|
|
1005
|
+
await fs5.rm(config.dbPath, { force: true });
|
|
1009
1006
|
if (!opts.dbOnly) {
|
|
1010
|
-
const marker =
|
|
1007
|
+
const marker = path5.join(dbDir, ".service-flow-state");
|
|
1011
1008
|
const dangerous = /* @__PURE__ */ new Set([
|
|
1012
|
-
|
|
1009
|
+
path5.parse(dbDir).root,
|
|
1013
1010
|
"/tmp",
|
|
1014
|
-
process.env.HOME ?
|
|
1011
|
+
process.env.HOME ? path5.resolve(process.env.HOME) : "",
|
|
1015
1012
|
workspaceRoot
|
|
1016
1013
|
]);
|
|
1017
1014
|
let ownsState;
|
|
1018
1015
|
try {
|
|
1019
|
-
ownsState = (await
|
|
1016
|
+
ownsState = (await fs5.stat(marker)).isFile();
|
|
1020
1017
|
} catch {
|
|
1021
1018
|
ownsState = false;
|
|
1022
1019
|
}
|
|
@@ -1024,7 +1021,7 @@ function createProgram() {
|
|
|
1024
1021
|
throw new Error(
|
|
1025
1022
|
`Refusing to recursively delete unowned or dangerous state directory: ${dbDir}. Use --db-only to remove only the database file.`
|
|
1026
1023
|
);
|
|
1027
|
-
await
|
|
1024
|
+
await fs5.rm(dbDir, { recursive: true, force: true });
|
|
1028
1025
|
}
|
|
1029
1026
|
process.stdout.write("Cleaned service-flow state\n");
|
|
1030
1027
|
})().catch(fail)
|