@chinjinyu/mcp-knowledge-graph-plus 0.1.1
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/README.md +700 -0
- package/dist/application/services/FactService.d.ts +16 -0
- package/dist/application/services/FactService.d.ts.map +1 -0
- package/dist/application/services/FactService.js +50 -0
- package/dist/application/services/FactService.js.map +1 -0
- package/dist/application/services/KnowledgeGraphService.d.ts +33 -0
- package/dist/application/services/KnowledgeGraphService.d.ts.map +1 -0
- package/dist/application/services/KnowledgeGraphService.js +271 -0
- package/dist/application/services/KnowledgeGraphService.js.map +1 -0
- package/dist/application/services/LinkService.d.ts +17 -0
- package/dist/application/services/LinkService.d.ts.map +1 -0
- package/dist/application/services/LinkService.js +53 -0
- package/dist/application/services/LinkService.js.map +1 -0
- package/dist/application/services/NodeService.d.ts +31 -0
- package/dist/application/services/NodeService.d.ts.map +1 -0
- package/dist/application/services/NodeService.js +69 -0
- package/dist/application/services/NodeService.js.map +1 -0
- package/dist/core/config/index.d.ts +34 -0
- package/dist/core/config/index.d.ts.map +1 -0
- package/dist/core/config/index.js +60 -0
- package/dist/core/config/index.js.map +1 -0
- package/dist/core/errors/index.d.ts +70 -0
- package/dist/core/errors/index.d.ts.map +1 -0
- package/dist/core/errors/index.js +120 -0
- package/dist/core/errors/index.js.map +1 -0
- package/dist/core/types/index.d.ts +119 -0
- package/dist/core/types/index.d.ts.map +1 -0
- package/dist/core/types/index.js +5 -0
- package/dist/core/types/index.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +117 -0
- package/dist/index.js.map +1 -0
- package/dist/infrastructure/database/DatabaseManager.d.ts +13 -0
- package/dist/infrastructure/database/DatabaseManager.d.ts.map +1 -0
- package/dist/infrastructure/database/DatabaseManager.js +101 -0
- package/dist/infrastructure/database/DatabaseManager.js.map +1 -0
- package/dist/infrastructure/di/Container.d.ts +21 -0
- package/dist/infrastructure/di/Container.d.ts.map +1 -0
- package/dist/infrastructure/di/Container.js +45 -0
- package/dist/infrastructure/di/Container.js.map +1 -0
- package/dist/infrastructure/repositories/BaseRepository.d.ts +23 -0
- package/dist/infrastructure/repositories/BaseRepository.d.ts.map +1 -0
- package/dist/infrastructure/repositories/BaseRepository.js +84 -0
- package/dist/infrastructure/repositories/BaseRepository.js.map +1 -0
- package/dist/infrastructure/repositories/FactRepository.d.ts +28 -0
- package/dist/infrastructure/repositories/FactRepository.d.ts.map +1 -0
- package/dist/infrastructure/repositories/FactRepository.js +101 -0
- package/dist/infrastructure/repositories/FactRepository.js.map +1 -0
- package/dist/infrastructure/repositories/LinkRepository.d.ts +28 -0
- package/dist/infrastructure/repositories/LinkRepository.d.ts.map +1 -0
- package/dist/infrastructure/repositories/LinkRepository.js +107 -0
- package/dist/infrastructure/repositories/LinkRepository.js.map +1 -0
- package/dist/infrastructure/repositories/NodeRepository.d.ts +28 -0
- package/dist/infrastructure/repositories/NodeRepository.d.ts.map +1 -0
- package/dist/infrastructure/repositories/NodeRepository.js +143 -0
- package/dist/infrastructure/repositories/NodeRepository.js.map +1 -0
- package/dist/interfaces/mcp/commands/BaseCommand.d.ts +55 -0
- package/dist/interfaces/mcp/commands/BaseCommand.d.ts.map +1 -0
- package/dist/interfaces/mcp/commands/BaseCommand.js +42 -0
- package/dist/interfaces/mcp/commands/BaseCommand.js.map +1 -0
- package/dist/interfaces/mcp/commands/FactAddCommand.d.ts +42 -0
- package/dist/interfaces/mcp/commands/FactAddCommand.d.ts.map +1 -0
- package/dist/interfaces/mcp/commands/FactAddCommand.js +73 -0
- package/dist/interfaces/mcp/commands/FactAddCommand.js.map +1 -0
- package/dist/interfaces/mcp/commands/FactDelCommand.d.ts +42 -0
- package/dist/interfaces/mcp/commands/FactDelCommand.d.ts.map +1 -0
- package/dist/interfaces/mcp/commands/FactDelCommand.js +68 -0
- package/dist/interfaces/mcp/commands/FactDelCommand.js.map +1 -0
- package/dist/interfaces/mcp/commands/FactEditCommand.d.ts +43 -0
- package/dist/interfaces/mcp/commands/FactEditCommand.d.ts.map +1 -0
- package/dist/interfaces/mcp/commands/FactEditCommand.js +68 -0
- package/dist/interfaces/mcp/commands/FactEditCommand.js.map +1 -0
- package/dist/interfaces/mcp/commands/LinkAddCommand.d.ts +43 -0
- package/dist/interfaces/mcp/commands/LinkAddCommand.d.ts.map +1 -0
- package/dist/interfaces/mcp/commands/LinkAddCommand.js +63 -0
- package/dist/interfaces/mcp/commands/LinkAddCommand.js.map +1 -0
- package/dist/interfaces/mcp/commands/LinkDelCommand.d.ts +43 -0
- package/dist/interfaces/mcp/commands/LinkDelCommand.d.ts.map +1 -0
- package/dist/interfaces/mcp/commands/LinkDelCommand.js +65 -0
- package/dist/interfaces/mcp/commands/LinkDelCommand.js.map +1 -0
- package/dist/interfaces/mcp/commands/LinkEditCommand.d.ts +47 -0
- package/dist/interfaces/mcp/commands/LinkEditCommand.d.ts.map +1 -0
- package/dist/interfaces/mcp/commands/LinkEditCommand.js +75 -0
- package/dist/interfaces/mcp/commands/LinkEditCommand.js.map +1 -0
- package/dist/interfaces/mcp/commands/ListCommand.d.ts +33 -0
- package/dist/interfaces/mcp/commands/ListCommand.d.ts.map +1 -0
- package/dist/interfaces/mcp/commands/ListCommand.js +57 -0
- package/dist/interfaces/mcp/commands/ListCommand.js.map +1 -0
- package/dist/interfaces/mcp/commands/NodeAddCommand.d.ts +46 -0
- package/dist/interfaces/mcp/commands/NodeAddCommand.d.ts.map +1 -0
- package/dist/interfaces/mcp/commands/NodeAddCommand.js +67 -0
- package/dist/interfaces/mcp/commands/NodeAddCommand.js.map +1 -0
- package/dist/interfaces/mcp/commands/NodeDelCommand.d.ts +32 -0
- package/dist/interfaces/mcp/commands/NodeDelCommand.d.ts.map +1 -0
- package/dist/interfaces/mcp/commands/NodeDelCommand.js +63 -0
- package/dist/interfaces/mcp/commands/NodeDelCommand.js.map +1 -0
- package/dist/interfaces/mcp/commands/NodeEditCommand.d.ts +43 -0
- package/dist/interfaces/mcp/commands/NodeEditCommand.d.ts.map +1 -0
- package/dist/interfaces/mcp/commands/NodeEditCommand.js +63 -0
- package/dist/interfaces/mcp/commands/NodeEditCommand.js.map +1 -0
- package/dist/interfaces/mcp/commands/NodeGetCommand.d.ts +40 -0
- package/dist/interfaces/mcp/commands/NodeGetCommand.d.ts.map +1 -0
- package/dist/interfaces/mcp/commands/NodeGetCommand.js +72 -0
- package/dist/interfaces/mcp/commands/NodeGetCommand.js.map +1 -0
- package/dist/interfaces/mcp/commands/SearchCommand.d.ts +53 -0
- package/dist/interfaces/mcp/commands/SearchCommand.d.ts.map +1 -0
- package/dist/interfaces/mcp/commands/SearchCommand.js +91 -0
- package/dist/interfaces/mcp/commands/SearchCommand.js.map +1 -0
- package/package.json +10 -0
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fact Service
|
|
3
|
+
*/
|
|
4
|
+
export class FactService {
|
|
5
|
+
factRepo;
|
|
6
|
+
nodeRepo;
|
|
7
|
+
constructor(factRepo, nodeRepo) {
|
|
8
|
+
this.factRepo = factRepo;
|
|
9
|
+
this.nodeRepo = nodeRepo;
|
|
10
|
+
}
|
|
11
|
+
async createFacts(inputs) {
|
|
12
|
+
const factInputs = [];
|
|
13
|
+
for (const input of inputs) {
|
|
14
|
+
const node = await this.nodeRepo.findByName(input.nodeName);
|
|
15
|
+
if (node) {
|
|
16
|
+
for (const content of input.contents) {
|
|
17
|
+
factInputs.push({ nodeId: node.id, content });
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return this.factRepo.createMany(factInputs);
|
|
22
|
+
}
|
|
23
|
+
async deleteFactsByContent(nodeName, contents) {
|
|
24
|
+
const node = await this.nodeRepo.findByName(nodeName);
|
|
25
|
+
if (!node)
|
|
26
|
+
return 0;
|
|
27
|
+
return this.factRepo.deleteByNodeIdAndContent(node.id, contents);
|
|
28
|
+
}
|
|
29
|
+
async updateFactsByContent(updates) {
|
|
30
|
+
const updatedFacts = [];
|
|
31
|
+
for (const update of updates) {
|
|
32
|
+
const node = await this.nodeRepo.findByName(update.nodeName);
|
|
33
|
+
if (node) {
|
|
34
|
+
const facts = await this.factRepo.findByNodeId(node.id);
|
|
35
|
+
const existingFact = facts.find(f => f.content === update.oldContent);
|
|
36
|
+
if (existingFact) {
|
|
37
|
+
const updated = await this.factRepo.updateContent(existingFact.id, update.newContent);
|
|
38
|
+
if (updated)
|
|
39
|
+
updatedFacts.push(updated);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return updatedFacts;
|
|
44
|
+
}
|
|
45
|
+
async getNodeNameMap(entityIds) {
|
|
46
|
+
const nodes = await this.nodeRepo.findMany(entityIds);
|
|
47
|
+
return new Map(nodes.map(n => [n.id, n.name]));
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=FactService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FactService.js","sourceRoot":"","sources":["../../../src/application/services/FactService.ts"],"names":[],"mappings":"AAAA;;GAEG;AAMH,MAAM,OAAO,WAAW;IAEH;IACA;IAFnB,YACmB,QAAwB,EACxB,QAAwB;QADxB,aAAQ,GAAR,QAAQ,CAAgB;QACxB,aAAQ,GAAR,QAAQ,CAAgB;IACxC,CAAC;IAEJ,KAAK,CAAC,WAAW,CAAC,MAAkC;QAClD,MAAM,UAAU,GAA0C,EAAE,CAAC;QAC7D,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;YAC3B,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;YAC5D,IAAI,IAAI,EAAE,CAAC;gBACT,KAAK,MAAM,OAAO,IAAI,KAAK,CAAC,QAAQ,EAAE,CAAC;oBACrC,UAAU,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,EAAE,OAAO,EAAE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AC/C,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;QACtD,OAAO,IAAI,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACjD,CAAC;CACF"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Knowledge Graph Service
|
|
3
|
+
*/
|
|
4
|
+
import type { GraphOutput, PaginatedResult, SearchField, SearchLogic } from '../../core/types/index.js';
|
|
5
|
+
import type { NodeRepository } from '../../infrastructure/repositories/NodeRepository.js';
|
|
6
|
+
import type { LinkRepository } from '../../infrastructure/repositories/LinkRepository.js';
|
|
7
|
+
import type { FactRepository } from '../../infrastructure/repositories/FactRepository.js';
|
|
8
|
+
export declare class KnowledgeGraphService {
|
|
9
|
+
private readonly nodeRepo;
|
|
10
|
+
private readonly linkRepo;
|
|
11
|
+
private readonly factRepo;
|
|
12
|
+
constructor(nodeRepo: NodeRepository, linkRepo: LinkRepository, factRepo: FactRepository);
|
|
13
|
+
search(queries: readonly string[], logic?: SearchLogic, searchFields?: readonly SearchField[], pagination?: {
|
|
14
|
+
page: number;
|
|
15
|
+
pageSize: number;
|
|
16
|
+
}): Promise<PaginatedResult<GraphOutput>>;
|
|
17
|
+
private getNodesByIds;
|
|
18
|
+
getByNames(names: readonly string[], pagination?: {
|
|
19
|
+
page: number;
|
|
20
|
+
pageSize: number;
|
|
21
|
+
}): Promise<PaginatedResult<GraphOutput>>;
|
|
22
|
+
readAll(pagination?: {
|
|
23
|
+
page: number;
|
|
24
|
+
pageSize: number;
|
|
25
|
+
}): Promise<PaginatedResult<GraphOutput>>;
|
|
26
|
+
getStats(): Promise<{
|
|
27
|
+
nodeCount: number;
|
|
28
|
+
linkCount: number;
|
|
29
|
+
factCount: number;
|
|
30
|
+
}>;
|
|
31
|
+
private createPaginatedResult;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=KnowledgeGraphService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"KnowledgeGraphService.d.ts","sourceRoot":"","sources":["../../../src/application/services/KnowledgeGraphService.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAoB,WAAW,EAAE,eAAe,EAAkB,WAAW,EAAE,WAAW,EAAiB,MAAM,2BAA2B,CAAC;AACzJ,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qDAAqD,CAAC;AAC1F,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qDAAqD,CAAC;AAC1F,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qDAAqD,CAAC;AAE1F,qBAAa,qBAAqB;IAE9B,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACzB,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACzB,OAAO,CAAC,QAAQ,CAAC,QAAQ;gBAFR,QAAQ,EAAE,cAAc,EACxB,QAAQ,EAAE,cAAc,EACxB,QAAQ,EAAE,cAAc;IAGrC,MAAM,CACV,OAAO,EAAE,SAAS,MAAM,EAAE,EAC1B,KAAK,GAAE,WAAkB,EACzB,YAAY,CAAC,EAAE,SAAS,WAAW,EAAE,EACrC,UAAU,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,GAC9C,OAAO,CAAC,eAAe,CAAC,WAAW,CAAC,CAAC;YAsF1B,aAAa;IA4DrB,UAAU,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,EAAE,UAAU,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,eAAe,CAAC,WAAW,CAAC,CAAC;IAqD5H,OAAO,CAAC,UAAU,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,eAAe,CAAC,WAAW,CAAC,CAAC;IAuD/F,QAAQ,IAAI,OAAO,CAAC;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC;IAStF,OAAO,CAAC,qBAAqB;CA0B9B"}
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Knowledge Graph Service
|
|
3
|
+
*/
|
|
4
|
+
export class KnowledgeGraphService {
|
|
5
|
+
nodeRepo;
|
|
6
|
+
linkRepo;
|
|
7
|
+
factRepo;
|
|
8
|
+
constructor(nodeRepo, linkRepo, factRepo) {
|
|
9
|
+
this.nodeRepo = nodeRepo;
|
|
10
|
+
this.linkRepo = linkRepo;
|
|
11
|
+
this.factRepo = factRepo;
|
|
12
|
+
}
|
|
13
|
+
async search(queries, logic = 'or', searchFields, pagination) {
|
|
14
|
+
const fields = searchFields && searchFields.length > 0 ? searchFields : ['name', 'type', 'fact'];
|
|
15
|
+
if (queries.length === 0) {
|
|
16
|
+
return this.createPaginatedResult({ nodes: [], links: [] }, 0, pagination);
|
|
17
|
+
}
|
|
18
|
+
if (logic === 'and') {
|
|
19
|
+
// For AND logic, we need to find nodes that match ALL queries
|
|
20
|
+
// This is more complex because a node might match different queries in different facts
|
|
21
|
+
const nodeMatchCounts = new Map();
|
|
22
|
+
for (const query of queries) {
|
|
23
|
+
const pattern = `%${query.toLowerCase()}%`;
|
|
24
|
+
const conditions = [];
|
|
25
|
+
const params = [];
|
|
26
|
+
if (fields.includes('name')) {
|
|
27
|
+
conditions.push('LOWER(e.name) LIKE ?');
|
|
28
|
+
params.push(pattern);
|
|
29
|
+
}
|
|
30
|
+
if (fields.includes('type')) {
|
|
31
|
+
conditions.push('LOWER(e.entity_type) LIKE ?');
|
|
32
|
+
params.push(pattern);
|
|
33
|
+
}
|
|
34
|
+
if (fields.includes('fact')) {
|
|
35
|
+
conditions.push('LOWER(o.content) LIKE ?');
|
|
36
|
+
params.push(pattern);
|
|
37
|
+
}
|
|
38
|
+
if (fields.includes('link')) {
|
|
39
|
+
conditions.push('EXISTS (SELECT 1 FROM relations r WHERE (r.from_entity_id = e.id OR r.to_entity_id = e.id) AND LOWER(r.relation_type) LIKE ?)');
|
|
40
|
+
params.push(pattern);
|
|
41
|
+
}
|
|
42
|
+
if (conditions.length === 0)
|
|
43
|
+
continue;
|
|
44
|
+
const whereClause = conditions.join(' OR ');
|
|
45
|
+
const sql = `SELECT DISTINCT e.id FROM entities e LEFT JOIN observations o ON e.id = o.entity_id WHERE ${whereClause}`;
|
|
46
|
+
const rows = await this.nodeRepo['all'](sql, params);
|
|
47
|
+
for (const row of rows) {
|
|
48
|
+
nodeMatchCounts.set(row.id, (nodeMatchCounts.get(row.id) || 0) + 1);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
// Only keep nodes that matched all queries
|
|
52
|
+
const nodeIds = Array.from(nodeMatchCounts.entries())
|
|
53
|
+
.filter(([, count]) => count === queries.length)
|
|
54
|
+
.map(([id]) => id);
|
|
55
|
+
return this.getNodesByIds(nodeIds, pagination);
|
|
56
|
+
}
|
|
57
|
+
// OR logic (existing implementation)
|
|
58
|
+
const conditions = [];
|
|
59
|
+
const params = [];
|
|
60
|
+
for (const query of queries) {
|
|
61
|
+
const pattern = `%${query.toLowerCase()}%`;
|
|
62
|
+
const fieldConditions = [];
|
|
63
|
+
if (fields.includes('name')) {
|
|
64
|
+
fieldConditions.push('LOWER(e.name) LIKE ?');
|
|
65
|
+
params.push(pattern);
|
|
66
|
+
}
|
|
67
|
+
if (fields.includes('type')) {
|
|
68
|
+
fieldConditions.push('LOWER(e.entity_type) LIKE ?');
|
|
69
|
+
params.push(pattern);
|
|
70
|
+
}
|
|
71
|
+
if (fields.includes('fact')) {
|
|
72
|
+
fieldConditions.push('LOWER(o.content) LIKE ?');
|
|
73
|
+
params.push(pattern);
|
|
74
|
+
}
|
|
75
|
+
if (fields.includes('link')) {
|
|
76
|
+
fieldConditions.push('EXISTS (SELECT 1 FROM relations r WHERE (r.from_entity_id = e.id OR r.to_entity_id = e.id) AND LOWER(r.relation_type) LIKE ?)');
|
|
77
|
+
params.push(pattern);
|
|
78
|
+
}
|
|
79
|
+
if (fieldConditions.length > 0) {
|
|
80
|
+
conditions.push(`(${fieldConditions.join(' OR ')})`);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
if (conditions.length === 0) {
|
|
84
|
+
return this.createPaginatedResult({ nodes: [], links: [] }, 0, pagination);
|
|
85
|
+
}
|
|
86
|
+
const whereClause = `(${conditions.join(' OR ')})`;
|
|
87
|
+
// Get matching node IDs
|
|
88
|
+
const idSql = `SELECT DISTINCT e.id FROM entities e LEFT JOIN observations o ON e.id = o.entity_id WHERE ${whereClause}`;
|
|
89
|
+
const idRows = await this.nodeRepo['all'](idSql, params);
|
|
90
|
+
const nodeIds = idRows.map(r => r.id);
|
|
91
|
+
return this.getNodesByIds(nodeIds, pagination);
|
|
92
|
+
}
|
|
93
|
+
async getNodesByIds(nodeIds, pagination) {
|
|
94
|
+
const total = nodeIds.length;
|
|
95
|
+
// Apply pagination only if pagination is provided
|
|
96
|
+
let paginatedIds = nodeIds;
|
|
97
|
+
if (pagination) {
|
|
98
|
+
const page = pagination.page ?? 1;
|
|
99
|
+
const pageSize = pagination.pageSize ?? 10;
|
|
100
|
+
const offset = (page - 1) * pageSize;
|
|
101
|
+
paginatedIds = nodeIds.slice(offset, offset + pageSize);
|
|
102
|
+
}
|
|
103
|
+
if (paginatedIds.length === 0) {
|
|
104
|
+
return this.createPaginatedResult({ nodes: [], links: [] }, total, pagination);
|
|
105
|
+
}
|
|
106
|
+
// Get full data
|
|
107
|
+
const nodes = await this.nodeRepo.findMany(paginatedIds);
|
|
108
|
+
const links = await this.linkRepo.findByNodeIds(paginatedIds);
|
|
109
|
+
const facts = await this.factRepo.findByNodeIds(paginatedIds);
|
|
110
|
+
const nodesWithFacts = nodes.map(n => ({
|
|
111
|
+
id: n.id,
|
|
112
|
+
name: n.name,
|
|
113
|
+
type: n.type,
|
|
114
|
+
createdAt: n.createdAt,
|
|
115
|
+
updatedAt: n.updatedAt,
|
|
116
|
+
facts: facts.filter(f => f.nodeId === n.id),
|
|
117
|
+
}));
|
|
118
|
+
// Build node name map with current page nodes
|
|
119
|
+
const nodeMap = new Map(nodes.map(n => [n.id, n.name]));
|
|
120
|
+
// Find missing node IDs in links (nodes not in current page)
|
|
121
|
+
const missingIds = new Set();
|
|
122
|
+
for (const link of links) {
|
|
123
|
+
if (!nodeMap.has(link.fromNodeId))
|
|
124
|
+
missingIds.add(link.fromNodeId);
|
|
125
|
+
if (!nodeMap.has(link.toNodeId))
|
|
126
|
+
missingIds.add(link.toNodeId);
|
|
127
|
+
}
|
|
128
|
+
// Fetch missing node names to ensure link completeness
|
|
129
|
+
if (missingIds.size > 0) {
|
|
130
|
+
const missingNodes = await this.nodeRepo.findMany([...missingIds]);
|
|
131
|
+
for (const n of missingNodes) {
|
|
132
|
+
nodeMap.set(n.id, n.name);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
const linksWithNames = links.map(link => ({
|
|
136
|
+
from: nodeMap.get(link.fromNodeId) || '',
|
|
137
|
+
to: nodeMap.get(link.toNodeId) || '',
|
|
138
|
+
type: link.type,
|
|
139
|
+
}));
|
|
140
|
+
return this.createPaginatedResult({ nodes: nodesWithFacts, links: linksWithNames }, total, pagination);
|
|
141
|
+
}
|
|
142
|
+
async getByNames(names, pagination) {
|
|
143
|
+
const allNodes = await this.nodeRepo.findManyByNames(names);
|
|
144
|
+
const total = allNodes.length;
|
|
145
|
+
// Apply pagination if requested
|
|
146
|
+
let nodes = allNodes;
|
|
147
|
+
if (pagination) {
|
|
148
|
+
const page = pagination.page ?? 1;
|
|
149
|
+
const pageSize = pagination.pageSize ?? 10;
|
|
150
|
+
const offset = (page - 1) * pageSize;
|
|
151
|
+
nodes = allNodes.slice(offset, offset + pageSize);
|
|
152
|
+
}
|
|
153
|
+
const nodeIds = nodes.map(n => n.id);
|
|
154
|
+
const links = await this.linkRepo.findByNodeIds(nodeIds);
|
|
155
|
+
const facts = await this.factRepo.findByNodeIds(nodeIds);
|
|
156
|
+
const nodesWithFacts = nodes.map(n => ({
|
|
157
|
+
id: n.id,
|
|
158
|
+
name: n.name,
|
|
159
|
+
type: n.type,
|
|
160
|
+
createdAt: n.createdAt,
|
|
161
|
+
updatedAt: n.updatedAt,
|
|
162
|
+
facts: facts.filter(f => f.nodeId === n.id),
|
|
163
|
+
}));
|
|
164
|
+
// Build node name map with current page nodes
|
|
165
|
+
const nodeMap = new Map(nodes.map(n => [n.id, n.name]));
|
|
166
|
+
// Find missing node IDs in links (nodes not in current page)
|
|
167
|
+
const missingIds = new Set();
|
|
168
|
+
for (const link of links) {
|
|
169
|
+
if (!nodeMap.has(link.fromNodeId))
|
|
170
|
+
missingIds.add(link.fromNodeId);
|
|
171
|
+
if (!nodeMap.has(link.toNodeId))
|
|
172
|
+
missingIds.add(link.toNodeId);
|
|
173
|
+
}
|
|
174
|
+
// Fetch missing node names to ensure link completeness
|
|
175
|
+
if (missingIds.size > 0) {
|
|
176
|
+
const missingNodes = await this.nodeRepo.findMany([...missingIds]);
|
|
177
|
+
for (const n of missingNodes) {
|
|
178
|
+
nodeMap.set(n.id, n.name);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
const linksWithNames = links.map(l => ({
|
|
182
|
+
from: nodeMap.get(l.fromNodeId) || '',
|
|
183
|
+
to: nodeMap.get(l.toNodeId) || '',
|
|
184
|
+
type: l.type,
|
|
185
|
+
}));
|
|
186
|
+
return this.createPaginatedResult({ nodes: nodesWithFacts, links: linksWithNames }, total, pagination);
|
|
187
|
+
}
|
|
188
|
+
async readAll(pagination) {
|
|
189
|
+
let nodes;
|
|
190
|
+
let total;
|
|
191
|
+
if (pagination) {
|
|
192
|
+
const page = pagination.page ?? 1;
|
|
193
|
+
const pageSize = pagination.pageSize ?? 10;
|
|
194
|
+
const result = await this.nodeRepo.findAllWithPagination(page, pageSize);
|
|
195
|
+
nodes = result.nodes;
|
|
196
|
+
total = result.total;
|
|
197
|
+
}
|
|
198
|
+
else {
|
|
199
|
+
nodes = await this.nodeRepo.findAll();
|
|
200
|
+
total = nodes.length;
|
|
201
|
+
}
|
|
202
|
+
const nodeIds = nodes.map(n => n.id);
|
|
203
|
+
const links = await this.linkRepo.findByNodeIds(nodeIds);
|
|
204
|
+
const facts = await this.factRepo.findByNodeIds(nodeIds);
|
|
205
|
+
const nodesWithFacts = nodes.map(n => ({
|
|
206
|
+
id: n.id,
|
|
207
|
+
name: n.name,
|
|
208
|
+
type: n.type,
|
|
209
|
+
createdAt: n.createdAt,
|
|
210
|
+
updatedAt: n.updatedAt,
|
|
211
|
+
facts: facts.filter(f => f.nodeId === n.id),
|
|
212
|
+
}));
|
|
213
|
+
// Build node name map with current page nodes
|
|
214
|
+
const nodeMap = new Map(nodes.map(n => [n.id, n.name]));
|
|
215
|
+
// Find missing node IDs in links (nodes not in current page)
|
|
216
|
+
const missingIds = new Set();
|
|
217
|
+
for (const link of links) {
|
|
218
|
+
if (!nodeMap.has(link.fromNodeId))
|
|
219
|
+
missingIds.add(link.fromNodeId);
|
|
220
|
+
if (!nodeMap.has(link.toNodeId))
|
|
221
|
+
missingIds.add(link.toNodeId);
|
|
222
|
+
}
|
|
223
|
+
// Fetch missing node names to ensure link completeness
|
|
224
|
+
if (missingIds.size > 0) {
|
|
225
|
+
const missingNodes = await this.nodeRepo.findMany([...missingIds]);
|
|
226
|
+
for (const n of missingNodes) {
|
|
227
|
+
nodeMap.set(n.id, n.name);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
const linksWithNames = links.map(l => ({
|
|
231
|
+
from: nodeMap.get(l.fromNodeId) || '',
|
|
232
|
+
to: nodeMap.get(l.toNodeId) || '',
|
|
233
|
+
type: l.type,
|
|
234
|
+
}));
|
|
235
|
+
return this.createPaginatedResult({ nodes: nodesWithFacts, links: linksWithNames }, total, pagination);
|
|
236
|
+
}
|
|
237
|
+
async getStats() {
|
|
238
|
+
const [nodeCount, linkCount, factCount] = await Promise.all([
|
|
239
|
+
this.nodeRepo.count(),
|
|
240
|
+
this.linkRepo.count(),
|
|
241
|
+
this.factRepo.count(),
|
|
242
|
+
]);
|
|
243
|
+
return { nodeCount, linkCount, factCount };
|
|
244
|
+
}
|
|
245
|
+
createPaginatedResult(data, total, pagination) {
|
|
246
|
+
if (!pagination) {
|
|
247
|
+
// No pagination requested - return all data without pagination info
|
|
248
|
+
return {
|
|
249
|
+
data,
|
|
250
|
+
pagination: {
|
|
251
|
+
page: 1,
|
|
252
|
+
pageSize: total,
|
|
253
|
+
totalItems: total,
|
|
254
|
+
totalPages: 1,
|
|
255
|
+
hasNextPage: false,
|
|
256
|
+
hasPrevPage: false,
|
|
257
|
+
}
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
const page = pagination.page ?? 1;
|
|
261
|
+
const pageSize = pagination.pageSize ?? 10;
|
|
262
|
+
const totalPages = Math.ceil(total / pageSize);
|
|
263
|
+
const paginationInfo = {
|
|
264
|
+
page, pageSize, totalItems: total, totalPages,
|
|
265
|
+
hasNextPage: page < totalPages,
|
|
266
|
+
hasPrevPage: page > 1,
|
|
267
|
+
};
|
|
268
|
+
return { data, pagination: paginationInfo };
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
//# sourceMappingURL=KnowledgeGraphService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"KnowledgeGraphService.js","sourceRoot":"","sources":["../../../src/application/services/KnowledgeGraphService.ts"],"names":[],"mappings":"AAAA;;GAEG;AAOH,MAAM,OAAO,qBAAqB;IAEb;IACA;IACA;IAHnB,YACmB,QAAwB,EACxB,QAAwB,EACxB,QAAwB;QAFxB,aAAQ,GAAR,QAAQ,CAAgB;QACxB,aAAQ,GAAR,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7G,IAAI,CAAC,UAAU,EAAE,CAAC;YAChB,oEAAoE;YACpE,OAAO;gBACL,IAAI;gBACJ,UAAU,EAAE;oBACV,IAAI,EAAE,CAAC;oBACP,QAAQ,EAAE,KAAK;oBACf,UAAU,EAAE,KAAK;oBACjB,UAAU,EAAE,CAAC;oBACb,WAAW,EAAE,KAAK;oBAClB,WAAW,EAAE,KAAK;iBACnB;aACF,CAAC;QACJ,CAAC;QAED,MAAM,IAAI,GAAG,UAAU,CAAC,IAAI,IAAI,CAAC,CAAC;QAClC,MAAM,QAAQ,GAAG,UAAU,CAAC,QAAQ,IAAI,EAAE,CAAC;QAC3C,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK,GAAG,QAAQ,CAAC,CAAC;QAC/C,MAAM,cAAc,GAAmB;YACrC,IAAI,EAAE,QAAQ,EAAE,UAAU,EAAE,KAAK,EAAE,UAAU;YAC7C,WAAW,EAAE,IAAI,GAAG,UAAU;YAC9B,WAAW,EAAE,IAAI,GAAG,CAAC;SACtB,CAAC;QACF,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,cAAc,EAAE,CAAC;IAC9C,CAAC;CACF"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Link Service
|
|
3
|
+
*/
|
|
4
|
+
import type { Link, CreateLinkInput, UpdateLinkInput } from '../../core/types/index.js';
|
|
5
|
+
import type { LinkRepository } from '../../infrastructure/repositories/LinkRepository.js';
|
|
6
|
+
import type { NodeRepository } from '../../infrastructure/repositories/NodeRepository.js';
|
|
7
|
+
export declare class LinkService {
|
|
8
|
+
private readonly linkRepo;
|
|
9
|
+
private readonly nodeRepo;
|
|
10
|
+
constructor(linkRepo: LinkRepository, nodeRepo: NodeRepository);
|
|
11
|
+
createLinks(inputs: readonly CreateLinkInput[]): Promise<readonly Link[]>;
|
|
12
|
+
deleteLinksByNames(from: string, to: string, type: string): Promise<number>;
|
|
13
|
+
updateLinksByNames(updates: readonly UpdateLinkInput[]): Promise<readonly Link[]>;
|
|
14
|
+
getLinksByNodeIds(nodeIds: readonly number[]): Promise<readonly Link[]>;
|
|
15
|
+
getNodeNameMap(nodeIds: readonly number[]): Promise<Map<number, string>>;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=LinkService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LinkService.d.ts","sourceRoot":"","sources":["../../../src/application/services/LinkService.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,eAAe,EAAE,eAAe,EAAiB,MAAM,2BAA2B,CAAC;AACvG,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qDAAqD,CAAC;AAC1F,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qDAAqD,CAAC;AAE1F,qBAAa,WAAW;IAEpB,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACzB,OAAO,CAAC,QAAQ,CAAC,QAAQ;gBADR,QAAQ,EAAE,cAAc,EACxB,QAAQ,EAAE,cAAc;IAGrC,WAAW,CAAC,MAAM,EAAE,SAAS,eAAe,EAAE,GAAG,OAAO,CAAC,SAAS,IAAI,EAAE,CAAC;IAYzE,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAO3E,kBAAkB,CAAC,OAAO,EAAE,SAAS,eAAe,EAAE,GAAG,OAAO,CAAC,SAAS,IAAI,EAAE,CAAC;IAgBjF,iBAAiB,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO,CAAC,SAAS,IAAI,EAAE,CAAC;IAIvE,cAAc,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAI/E"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Link Service
|
|
3
|
+
*/
|
|
4
|
+
export class LinkService {
|
|
5
|
+
linkRepo;
|
|
6
|
+
nodeRepo;
|
|
7
|
+
constructor(linkRepo, nodeRepo) {
|
|
8
|
+
this.linkRepo = linkRepo;
|
|
9
|
+
this.nodeRepo = nodeRepo;
|
|
10
|
+
}
|
|
11
|
+
async createLinks(inputs) {
|
|
12
|
+
const linkData = [];
|
|
13
|
+
for (const input of inputs) {
|
|
14
|
+
const fromNode = await this.nodeRepo.findByName(input.from);
|
|
15
|
+
const toNode = await this.nodeRepo.findByName(input.to);
|
|
16
|
+
if (fromNode && toNode) {
|
|
17
|
+
linkData.push({ input, fromNodeId: fromNode.id, toNodeId: toNode.id });
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return this.linkRepo.createMany(linkData);
|
|
21
|
+
}
|
|
22
|
+
async deleteLinksByNames(from, to, type) {
|
|
23
|
+
const fromNode = await this.nodeRepo.findByName(from);
|
|
24
|
+
const toNode = await this.nodeRepo.findByName(to);
|
|
25
|
+
if (!fromNode || !toNode)
|
|
26
|
+
return 0;
|
|
27
|
+
return this.linkRepo.deleteByNodeIdsAndType(fromNode.id, toNode.id, type);
|
|
28
|
+
}
|
|
29
|
+
async updateLinksByNames(updates) {
|
|
30
|
+
const updatedLinks = [];
|
|
31
|
+
for (const update of updates) {
|
|
32
|
+
const fromNode = await this.nodeRepo.findByName(update.from);
|
|
33
|
+
const toNode = await this.nodeRepo.findByName(update.to);
|
|
34
|
+
if (fromNode && toNode) {
|
|
35
|
+
const existingLink = await this.linkRepo.findByNodeIdsAndType(fromNode.id, toNode.id, update.oldType);
|
|
36
|
+
if (existingLink) {
|
|
37
|
+
const updated = await this.linkRepo.updateType(existingLink.id, update.newType);
|
|
38
|
+
if (updated)
|
|
39
|
+
updatedLinks.push(updated);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return updatedLinks;
|
|
44
|
+
}
|
|
45
|
+
async getLinksByNodeIds(nodeIds) {
|
|
46
|
+
return this.linkRepo.findByNodeIds(nodeIds);
|
|
47
|
+
}
|
|
48
|
+
async getNodeNameMap(nodeIds) {
|
|
49
|
+
const nodes = await this.nodeRepo.findMany(nodeIds);
|
|
50
|
+
return new Map(nodes.map(n => [n.id, n.name]));
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=LinkService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LinkService.js","sourceRoot":"","sources":["../../../src/application/services/LinkService.ts"],"names":[],"mappings":"AAAA;;GAEG;AAMH,MAAM,OAAO,WAAW;IAEH;IACA;IAFnB,YACmB,QAAwB,EACxB,QAAwB;QADxB,aAAQ,GAAR,QAAQ,CAAgB;QACxB,aAAQ,GAAR,QAAQ,CAAgB;IACxC,CAAC;IAEJ,KAAK,CAAC,WAAW,CAAC,MAAkC;QAClD,MAAM,QAAQ,GAAuE,EAAE,CAAC;QACxF,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;YAC3B,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YAC5D,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;YACxD,IAAI,QAAQ,IAAI,MAAM,EAAE,CAAC;gBACvB,QAAQ,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,UAAU,EAAE,QAAQ,CAAC,EAAE,EAAE,QAAQ,EAAE,MAAM,CAAC,EAAE,EAAE,CAAC,CAAC;YACzE,CAAC;QACH,CAAC;QACD,OAAO,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;IAC5C,CAAC;IAED,KAAK,CAAC,kBAAkB,CAAC,IAAY,EAAE,EAAU,EAAE,IAAY;QAC7D,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,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CAAC,CAAC;IAC9C,CAAC;IAED,KAAK,CAAC,cAAc,CAAC,OAA0B;QAC7C,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;QACpD,OAAO,IAAI,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACjD,CAAC;CACF"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Node Service
|
|
3
|
+
*/
|
|
4
|
+
import type { Node, CreateNodeInput, UpdateNodeInput, Fact } from '../../core/types/index.js';
|
|
5
|
+
import type { NodeRepository } from '../../infrastructure/repositories/NodeRepository.js';
|
|
6
|
+
import type { FactRepository } from '../../infrastructure/repositories/FactRepository.js';
|
|
7
|
+
import type { LinkRepository } from '../../infrastructure/repositories/LinkRepository.js';
|
|
8
|
+
export declare class NodeService {
|
|
9
|
+
private readonly nodeRepo;
|
|
10
|
+
private readonly factRepo;
|
|
11
|
+
private readonly linkRepo;
|
|
12
|
+
constructor(nodeRepo: NodeRepository, factRepo: FactRepository, linkRepo: LinkRepository);
|
|
13
|
+
createNodes(inputs: readonly CreateNodeInput[]): Promise<{
|
|
14
|
+
nodes: readonly Node[];
|
|
15
|
+
createdFacts: readonly {
|
|
16
|
+
nodeName: string;
|
|
17
|
+
content: string;
|
|
18
|
+
}[];
|
|
19
|
+
}>;
|
|
20
|
+
updateNodesByName(updates: readonly UpdateNodeInput[]): Promise<readonly Node[]>;
|
|
21
|
+
deleteNodesByNames(names: readonly string[]): Promise<number>;
|
|
22
|
+
getNodesWithFacts(nodeIds: readonly number[]): Promise<readonly {
|
|
23
|
+
id: number;
|
|
24
|
+
name: string;
|
|
25
|
+
type: string;
|
|
26
|
+
facts: readonly Fact[];
|
|
27
|
+
}[]>;
|
|
28
|
+
findByName(name: string): Promise<Node | null>;
|
|
29
|
+
findByNames(names: readonly string[]): Promise<readonly Node[]>;
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=NodeService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NodeService.d.ts","sourceRoot":"","sources":["../../../src/application/services/NodeService.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,eAAe,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,2BAA2B,CAAC;AAC9F,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qDAAqD,CAAC;AAC1F,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qDAAqD,CAAC;AAC1F,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qDAAqD,CAAC;AAE1F,qBAAa,WAAW;IAEpB,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACzB,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACzB,OAAO,CAAC,QAAQ,CAAC,QAAQ;gBAFR,QAAQ,EAAE,cAAc,EACxB,QAAQ,EAAE,cAAc,EACxB,QAAQ,EAAE,cAAc;IAGrC,WAAW,CAAC,MAAM,EAAE,SAAS,eAAe,EAAE,GAAG,OAAO,CAAC;QAAE,KAAK,EAAE,SAAS,IAAI,EAAE,CAAC;QAAC,YAAY,EAAE,SAAS;YAAE,QAAQ,EAAE,MAAM,CAAC;YAAC,OAAO,EAAE,MAAM,CAAA;SAAE,EAAE,CAAA;KAAE,CAAC;IAsBpJ,iBAAiB,CAAC,OAAO,EAAE,SAAS,eAAe,EAAE,GAAG,OAAO,CAAC,SAAS,IAAI,EAAE,CAAC;IAShF,kBAAkB,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC;IAY7D,iBAAiB,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO,CAAC,SAAS;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,SAAS,IAAI,EAAE,CAAA;KAAE,EAAE,CAAC;IAYrI,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC;IAI9C,WAAW,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO,CAAC,SAAS,IAAI,EAAE,CAAC;CAGtE"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Node Service
|
|
3
|
+
*/
|
|
4
|
+
export class NodeService {
|
|
5
|
+
nodeRepo;
|
|
6
|
+
factRepo;
|
|
7
|
+
linkRepo;
|
|
8
|
+
constructor(nodeRepo, factRepo, linkRepo) {
|
|
9
|
+
this.nodeRepo = nodeRepo;
|
|
10
|
+
this.factRepo = factRepo;
|
|
11
|
+
this.linkRepo = linkRepo;
|
|
12
|
+
}
|
|
13
|
+
async createNodes(inputs) {
|
|
14
|
+
const nodes = await this.nodeRepo.createMany(inputs);
|
|
15
|
+
const createdFacts = [];
|
|
16
|
+
if (nodes.length > 0) {
|
|
17
|
+
const factInputs = [];
|
|
18
|
+
for (const input of inputs) {
|
|
19
|
+
const node = nodes.find(n => n.name === input.name);
|
|
20
|
+
if (node && input.facts) {
|
|
21
|
+
for (const content of input.facts) {
|
|
22
|
+
factInputs.push({ nodeId: node.id, content });
|
|
23
|
+
createdFacts.push({ nodeName: node.name, content });
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
if (factInputs.length > 0) {
|
|
28
|
+
await this.factRepo.createMany(factInputs);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return { nodes, createdFacts };
|
|
32
|
+
}
|
|
33
|
+
async updateNodesByName(updates) {
|
|
34
|
+
const updatedNodes = [];
|
|
35
|
+
for (const update of updates) {
|
|
36
|
+
const node = await this.nodeRepo.update(update);
|
|
37
|
+
if (node)
|
|
38
|
+
updatedNodes.push(node);
|
|
39
|
+
}
|
|
40
|
+
return updatedNodes;
|
|
41
|
+
}
|
|
42
|
+
async deleteNodesByNames(names) {
|
|
43
|
+
const nodes = await this.nodeRepo.findManyByNames(names);
|
|
44
|
+
// Cascade delete: delete facts and links first, then nodes
|
|
45
|
+
for (const node of nodes) {
|
|
46
|
+
await this.factRepo.deleteByNodeId(node.id);
|
|
47
|
+
await this.linkRepo.deleteByNodeId(node.id);
|
|
48
|
+
}
|
|
49
|
+
return this.nodeRepo.deleteByNames(names);
|
|
50
|
+
}
|
|
51
|
+
async getNodesWithFacts(nodeIds) {
|
|
52
|
+
const nodes = await this.nodeRepo.findMany(nodeIds);
|
|
53
|
+
const factsByNode = await this.factRepo.findByNodeIds(nodeIds);
|
|
54
|
+
const factsMap = new Map();
|
|
55
|
+
for (const fact of factsByNode) {
|
|
56
|
+
const existing = factsMap.get(fact.nodeId) || [];
|
|
57
|
+
existing.push(fact);
|
|
58
|
+
factsMap.set(fact.nodeId, existing);
|
|
59
|
+
}
|
|
60
|
+
return nodes.map(n => ({ id: n.id, name: n.name, type: n.type, facts: factsMap.get(n.id) || [] }));
|
|
61
|
+
}
|
|
62
|
+
async findByName(name) {
|
|
63
|
+
return this.nodeRepo.findByName(name);
|
|
64
|
+
}
|
|
65
|
+
async findByNames(names) {
|
|
66
|
+
return this.nodeRepo.findManyByNames(names);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=NodeService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NodeService.js","sourceRoot":"","sources":["../../../src/application/services/NodeService.ts"],"names":[],"mappings":"AAAA;;GAEG;AAOH,MAAM,OAAO,WAAW;IAEH;IACA;IACA;IAHnB,YACmB,QAAwB,EACxB,QAAwB,EACxB,QAAwB;QAFxB,aAAQ,GAAR,QAAQ,CAAgB;QACxB,aAAQ,GAAR,QAAQ,CAAgB;QACxB,aAAQ,GAAR,QAAQ,CA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AE,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC;IACrG,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,IAAY;QAC3B,OAAO,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;IACxC,CAAC;IAED,KAAK,CAAC,WAAW,CAAC,KAAwB;QACxC,OAAO,IAAI,CAAC,QAAQ,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC;IAC9C,CAAC;CACF"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration Management
|
|
3
|
+
*/
|
|
4
|
+
export declare const LogLevel: {
|
|
5
|
+
readonly DEBUG: "debug";
|
|
6
|
+
readonly INFO: "info";
|
|
7
|
+
readonly WARN: "warn";
|
|
8
|
+
readonly ERROR: "error";
|
|
9
|
+
readonly NONE: "none";
|
|
10
|
+
};
|
|
11
|
+
export type LogLevel = typeof LogLevel[keyof typeof LogLevel];
|
|
12
|
+
export declare const Environment: {
|
|
13
|
+
readonly DEVELOPMENT: "development";
|
|
14
|
+
readonly PRODUCTION: "production";
|
|
15
|
+
readonly TEST: "test";
|
|
16
|
+
};
|
|
17
|
+
export type Environment = typeof Environment[keyof typeof Environment];
|
|
18
|
+
export interface AppConfig {
|
|
19
|
+
readonly name: string;
|
|
20
|
+
readonly version: string;
|
|
21
|
+
readonly environment: Environment;
|
|
22
|
+
readonly dbPath: string;
|
|
23
|
+
readonly logLevel: LogLevel;
|
|
24
|
+
}
|
|
25
|
+
export declare function createConfig(dbPath: string, environment?: Environment): AppConfig;
|
|
26
|
+
export declare function getEnvironmentFromEnv(): Environment;
|
|
27
|
+
/**
|
|
28
|
+
* Parse command line arguments to get database path
|
|
29
|
+
* Supports both formats:
|
|
30
|
+
* - --db-path=/path/to/db.db
|
|
31
|
+
* - --db-path /path/to/db.db
|
|
32
|
+
*/
|
|
33
|
+
export declare function getDatabasePathFromEnv(defaultPath: string): string;
|
|
34
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/config/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,eAAO,MAAM,QAAQ;;;;;;CAMX,CAAC;AAEX,MAAM,MAAM,QAAQ,GAAG,OAAO,QAAQ,CAAC,MAAM,OAAO,QAAQ,CAAC,CAAC;AAE9D,eAAO,MAAM,WAAW;;;;CAId,CAAC;AAEX,MAAM,MAAM,WAAW,GAAG,OAAO,WAAW,CAAC,MAAM,OAAO,WAAW,CAAC,CAAC;AAEvE,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,WAAW,EAAE,WAAW,CAAC;IAClC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;CAC7B;AAED,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,WAAW,GAAE,WAAoC,GAAG,SAAS,CAQzG;AAED,wBAAgB,qBAAqB,IAAI,WAAW,CAOnD;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAyBlE"}
|