@semiont/graph 0.2.34-build.91 → 0.2.34-build.93
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +11 -2
- package/dist/index.js +83 -92
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -145,6 +145,7 @@ var NeptuneGraphDatabase = class {
|
|
|
145
145
|
neptuneEndpoint;
|
|
146
146
|
neptunePort = 8182;
|
|
147
147
|
region;
|
|
148
|
+
logger;
|
|
148
149
|
g;
|
|
149
150
|
// Gremlin graph traversal source
|
|
150
151
|
connection;
|
|
@@ -164,6 +165,7 @@ var NeptuneGraphDatabase = class {
|
|
|
164
165
|
if (config.endpoint) this.neptuneEndpoint = config.endpoint;
|
|
165
166
|
this.neptunePort = config.port || 8182;
|
|
166
167
|
if (config.region) this.region = config.region;
|
|
168
|
+
this.logger = config.logger;
|
|
167
169
|
}
|
|
168
170
|
async discoverNeptuneEndpoint() {
|
|
169
171
|
if (this.neptuneEndpoint) {
|
|
@@ -199,9 +201,9 @@ var NeptuneGraphDatabase = class {
|
|
|
199
201
|
}
|
|
200
202
|
this.neptuneEndpoint = cluster.Endpoint;
|
|
201
203
|
this.neptunePort = cluster.Port || 8182;
|
|
202
|
-
|
|
204
|
+
this.logger?.info("Discovered Neptune endpoint", { endpoint: this.neptuneEndpoint, port: this.neptunePort });
|
|
203
205
|
} catch (error) {
|
|
204
|
-
|
|
206
|
+
this.logger?.error("Failed to discover Neptune endpoint", { error });
|
|
205
207
|
throw error;
|
|
206
208
|
}
|
|
207
209
|
}
|
|
@@ -212,7 +214,7 @@ var NeptuneGraphDatabase = class {
|
|
|
212
214
|
const traversal2 = gremlin.process.AnonymousTraversalSource.traversal;
|
|
213
215
|
const DriverRemoteConnection2 = gremlin.driver.DriverRemoteConnection;
|
|
214
216
|
const connectionUrl = `wss://${this.neptuneEndpoint}:${this.neptunePort}/gremlin`;
|
|
215
|
-
|
|
217
|
+
this.logger?.info("Connecting to Neptune", { connectionUrl });
|
|
216
218
|
this.connection = new DriverRemoteConnection2(connectionUrl, {
|
|
217
219
|
authenticator: null,
|
|
218
220
|
// Neptune uses IAM authentication via task role
|
|
@@ -221,10 +223,10 @@ var NeptuneGraphDatabase = class {
|
|
|
221
223
|
});
|
|
222
224
|
this.g = traversal2().withRemote(this.connection);
|
|
223
225
|
const count = await this.g.V().limit(1).count().next();
|
|
224
|
-
|
|
226
|
+
this.logger?.info("Connected to Neptune", { vertexCountTest: count.value });
|
|
225
227
|
this.connected = true;
|
|
226
228
|
} catch (error) {
|
|
227
|
-
|
|
229
|
+
this.logger?.error("Failed to connect to Neptune", { error });
|
|
228
230
|
throw error;
|
|
229
231
|
}
|
|
230
232
|
}
|
|
@@ -233,11 +235,11 @@ var NeptuneGraphDatabase = class {
|
|
|
233
235
|
try {
|
|
234
236
|
await this.connection.close();
|
|
235
237
|
} catch (error) {
|
|
236
|
-
|
|
238
|
+
this.logger?.error("Error closing Neptune connection", { error });
|
|
237
239
|
}
|
|
238
240
|
}
|
|
239
241
|
this.connected = false;
|
|
240
|
-
|
|
242
|
+
this.logger?.info("Disconnected from Neptune");
|
|
241
243
|
}
|
|
242
244
|
isConnected() {
|
|
243
245
|
return this.connected;
|
|
@@ -254,10 +256,10 @@ var NeptuneGraphDatabase = class {
|
|
|
254
256
|
vertex.property("sourceResourceId", resource.sourceResourceId);
|
|
255
257
|
}
|
|
256
258
|
await vertex.next();
|
|
257
|
-
|
|
259
|
+
this.logger?.info("Created resource vertex in Neptune", { id });
|
|
258
260
|
return resource;
|
|
259
261
|
} catch (error) {
|
|
260
|
-
|
|
262
|
+
this.logger?.error("Failed to create resource in Neptune", { error });
|
|
261
263
|
throw error;
|
|
262
264
|
}
|
|
263
265
|
}
|
|
@@ -269,7 +271,7 @@ var NeptuneGraphDatabase = class {
|
|
|
269
271
|
}
|
|
270
272
|
return vertexToResource(result.value);
|
|
271
273
|
} catch (error) {
|
|
272
|
-
|
|
274
|
+
this.logger?.error("Failed to get resource from Neptune", { error });
|
|
273
275
|
throw error;
|
|
274
276
|
}
|
|
275
277
|
}
|
|
@@ -284,16 +286,16 @@ var NeptuneGraphDatabase = class {
|
|
|
284
286
|
}
|
|
285
287
|
return vertexToResource(result.value);
|
|
286
288
|
} catch (error) {
|
|
287
|
-
|
|
289
|
+
this.logger?.error("Failed to update resource in Neptune", { error });
|
|
288
290
|
throw error;
|
|
289
291
|
}
|
|
290
292
|
}
|
|
291
293
|
async deleteResource(id) {
|
|
292
294
|
try {
|
|
293
295
|
await this.g.V().hasLabel("Resource").has("id", id).drop().iterate();
|
|
294
|
-
|
|
296
|
+
this.logger?.info("Deleted resource from Neptune", { id });
|
|
295
297
|
} catch (error) {
|
|
296
|
-
|
|
298
|
+
this.logger?.error("Failed to delete resource from Neptune", { error });
|
|
297
299
|
throw error;
|
|
298
300
|
}
|
|
299
301
|
}
|
|
@@ -320,7 +322,7 @@ var NeptuneGraphDatabase = class {
|
|
|
320
322
|
const resources = results.map(vertexToResource);
|
|
321
323
|
return { resources, total };
|
|
322
324
|
} catch (error) {
|
|
323
|
-
|
|
325
|
+
this.logger?.error("Failed to list resources from Neptune", { error });
|
|
324
326
|
throw error;
|
|
325
327
|
}
|
|
326
328
|
}
|
|
@@ -329,7 +331,7 @@ var NeptuneGraphDatabase = class {
|
|
|
329
331
|
const results = await this.g.V().hasLabel("Resource").has("name", TextP.containing(query)).order().by("created", order.desc).limit(limit).elementMap().toList();
|
|
330
332
|
return results.map(vertexToResource);
|
|
331
333
|
} catch (error) {
|
|
332
|
-
|
|
334
|
+
this.logger?.error("Failed to search resources in Neptune", { error });
|
|
333
335
|
throw error;
|
|
334
336
|
}
|
|
335
337
|
}
|
|
@@ -366,10 +368,10 @@ var NeptuneGraphDatabase = class {
|
|
|
366
368
|
).next();
|
|
367
369
|
await this.g.V(newVertex.value).addE("TAGGED_AS").to(this.g.V(etVertex.value)).next();
|
|
368
370
|
}
|
|
369
|
-
|
|
371
|
+
this.logger?.info("Created annotation vertex in Neptune", { id: annotation.id });
|
|
370
372
|
return annotation;
|
|
371
373
|
} catch (error) {
|
|
372
|
-
|
|
374
|
+
this.logger?.error("Failed to create annotation in Neptune", { error });
|
|
373
375
|
throw error;
|
|
374
376
|
}
|
|
375
377
|
}
|
|
@@ -383,7 +385,7 @@ var NeptuneGraphDatabase = class {
|
|
|
383
385
|
const entityTypes = entityTypesResult || [];
|
|
384
386
|
return vertexToAnnotation(result.value, entityTypes);
|
|
385
387
|
} catch (error) {
|
|
386
|
-
|
|
388
|
+
this.logger?.error("Failed to get annotation from Neptune", { error });
|
|
387
389
|
throw error;
|
|
388
390
|
}
|
|
389
391
|
}
|
|
@@ -426,16 +428,16 @@ var NeptuneGraphDatabase = class {
|
|
|
426
428
|
const entityTypes = entityTypesResult || [];
|
|
427
429
|
return vertexToAnnotation(result.value, entityTypes);
|
|
428
430
|
} catch (error) {
|
|
429
|
-
|
|
431
|
+
this.logger?.error("Failed to update annotation in Neptune", { error });
|
|
430
432
|
throw error;
|
|
431
433
|
}
|
|
432
434
|
}
|
|
433
435
|
async deleteAnnotation(id) {
|
|
434
436
|
try {
|
|
435
437
|
await this.g.V().hasLabel("Annotation").has("id", id).drop().iterate();
|
|
436
|
-
|
|
438
|
+
this.logger?.info("Deleted annotation from Neptune", { id });
|
|
437
439
|
} catch (error) {
|
|
438
|
-
|
|
440
|
+
this.logger?.error("Failed to delete annotation from Neptune", { error });
|
|
439
441
|
throw error;
|
|
440
442
|
}
|
|
441
443
|
}
|
|
@@ -453,7 +455,7 @@ var NeptuneGraphDatabase = class {
|
|
|
453
455
|
const annotations = await this.fetchAnnotationsWithEntityTypes(results);
|
|
454
456
|
return { annotations, total: annotations.length };
|
|
455
457
|
} catch (error) {
|
|
456
|
-
|
|
458
|
+
this.logger?.error("Failed to list annotations from Neptune", { error });
|
|
457
459
|
throw error;
|
|
458
460
|
}
|
|
459
461
|
}
|
|
@@ -462,7 +464,7 @@ var NeptuneGraphDatabase = class {
|
|
|
462
464
|
const results = await this.g.V().hasLabel("Annotation").has("resourceId", resourceId).hasNot("resolvedResourceId").elementMap().toList();
|
|
463
465
|
return await this.fetchAnnotationsWithEntityTypes(results);
|
|
464
466
|
} catch (error) {
|
|
465
|
-
|
|
467
|
+
this.logger?.error("Failed to get highlights from Neptune", { error });
|
|
466
468
|
throw error;
|
|
467
469
|
}
|
|
468
470
|
}
|
|
@@ -481,7 +483,7 @@ var NeptuneGraphDatabase = class {
|
|
|
481
483
|
const entityTypes = entityTypesResult || [];
|
|
482
484
|
return vertexToAnnotation(result.value, entityTypes);
|
|
483
485
|
} catch (error) {
|
|
484
|
-
|
|
486
|
+
this.logger?.error("Failed to resolve reference in Neptune", { error });
|
|
485
487
|
throw error;
|
|
486
488
|
}
|
|
487
489
|
}
|
|
@@ -490,7 +492,7 @@ var NeptuneGraphDatabase = class {
|
|
|
490
492
|
const results = await this.g.V().hasLabel("Annotation").has("resourceId", resourceId).has("resolvedResourceId").elementMap().toList();
|
|
491
493
|
return await this.fetchAnnotationsWithEntityTypes(results);
|
|
492
494
|
} catch (error) {
|
|
493
|
-
|
|
495
|
+
this.logger?.error("Failed to get references from Neptune", { error });
|
|
494
496
|
throw error;
|
|
495
497
|
}
|
|
496
498
|
}
|
|
@@ -509,7 +511,7 @@ var NeptuneGraphDatabase = class {
|
|
|
509
511
|
const results = await traversal2.elementMap().toList();
|
|
510
512
|
return await this.fetchAnnotationsWithEntityTypes(results);
|
|
511
513
|
} catch (error) {
|
|
512
|
-
|
|
514
|
+
this.logger?.error("Failed to get entity references from Neptune", { error });
|
|
513
515
|
throw error;
|
|
514
516
|
}
|
|
515
517
|
}
|
|
@@ -518,7 +520,7 @@ var NeptuneGraphDatabase = class {
|
|
|
518
520
|
const results = await this.g.V().hasLabel("Annotation").has("resourceId", resourceId).elementMap().toList();
|
|
519
521
|
return await this.fetchAnnotationsWithEntityTypes(results);
|
|
520
522
|
} catch (error) {
|
|
521
|
-
|
|
523
|
+
this.logger?.error("Failed to get resource annotations from Neptune", { error });
|
|
522
524
|
throw error;
|
|
523
525
|
}
|
|
524
526
|
}
|
|
@@ -527,7 +529,7 @@ var NeptuneGraphDatabase = class {
|
|
|
527
529
|
const results = await this.g.V().hasLabel("Annotation").has("resolvedResourceId", resourceUri3).elementMap().toList();
|
|
528
530
|
return await this.fetchAnnotationsWithEntityTypes(results);
|
|
529
531
|
} catch (error) {
|
|
530
|
-
|
|
532
|
+
this.logger?.error("Failed to get resource referenced by from Neptune", { error });
|
|
531
533
|
throw error;
|
|
532
534
|
}
|
|
533
535
|
}
|
|
@@ -573,7 +575,7 @@ var NeptuneGraphDatabase = class {
|
|
|
573
575
|
}
|
|
574
576
|
return Array.from(connectionsMap.values());
|
|
575
577
|
} catch (error) {
|
|
576
|
-
|
|
578
|
+
this.logger?.error("Failed to get resource connections from Neptune", { error });
|
|
577
579
|
throw error;
|
|
578
580
|
}
|
|
579
581
|
}
|
|
@@ -596,7 +598,7 @@ var NeptuneGraphDatabase = class {
|
|
|
596
598
|
}
|
|
597
599
|
return paths;
|
|
598
600
|
} catch (error) {
|
|
599
|
-
|
|
601
|
+
this.logger?.error("Failed to find paths in Neptune", { error });
|
|
600
602
|
throw error;
|
|
601
603
|
}
|
|
602
604
|
}
|
|
@@ -617,7 +619,7 @@ var NeptuneGraphDatabase = class {
|
|
|
617
619
|
}
|
|
618
620
|
return stats;
|
|
619
621
|
} catch (error) {
|
|
620
|
-
|
|
622
|
+
this.logger?.error("Failed to get entity type stats from Neptune", { error });
|
|
621
623
|
throw error;
|
|
622
624
|
}
|
|
623
625
|
}
|
|
@@ -650,7 +652,7 @@ var NeptuneGraphDatabase = class {
|
|
|
650
652
|
contentTypes
|
|
651
653
|
};
|
|
652
654
|
} catch (error) {
|
|
653
|
-
|
|
655
|
+
this.logger?.error("Failed to get stats from Neptune", { error });
|
|
654
656
|
throw error;
|
|
655
657
|
}
|
|
656
658
|
}
|
|
@@ -663,7 +665,7 @@ var NeptuneGraphDatabase = class {
|
|
|
663
665
|
}
|
|
664
666
|
return results;
|
|
665
667
|
} catch (error) {
|
|
666
|
-
|
|
668
|
+
this.logger?.error("Failed to create annotations in Neptune", { error });
|
|
667
669
|
throw error;
|
|
668
670
|
}
|
|
669
671
|
}
|
|
@@ -676,7 +678,7 @@ var NeptuneGraphDatabase = class {
|
|
|
676
678
|
}
|
|
677
679
|
return results;
|
|
678
680
|
} catch (error) {
|
|
679
|
-
|
|
681
|
+
this.logger?.error("Failed to resolve references in Neptune", { error });
|
|
680
682
|
throw error;
|
|
681
683
|
}
|
|
682
684
|
}
|
|
@@ -702,7 +704,7 @@ var NeptuneGraphDatabase = class {
|
|
|
702
704
|
__.addV("TagCollection").property("type", "entity-types")
|
|
703
705
|
).property(cardinality.set, "tags", tag).iterate();
|
|
704
706
|
} catch (error) {
|
|
705
|
-
|
|
707
|
+
this.logger?.error("Failed to add entity type", { error });
|
|
706
708
|
}
|
|
707
709
|
}
|
|
708
710
|
async addEntityTypes(tags) {
|
|
@@ -719,7 +721,7 @@ var NeptuneGraphDatabase = class {
|
|
|
719
721
|
await vertex.property(cardinality.set, "tags", tag).iterate();
|
|
720
722
|
}
|
|
721
723
|
} catch (error) {
|
|
722
|
-
|
|
724
|
+
this.logger?.error("Failed to add entity types", { error });
|
|
723
725
|
}
|
|
724
726
|
}
|
|
725
727
|
async initializeTagCollections() {
|
|
@@ -731,7 +733,7 @@ var NeptuneGraphDatabase = class {
|
|
|
731
733
|
}
|
|
732
734
|
}
|
|
733
735
|
} catch (error) {
|
|
734
|
-
|
|
736
|
+
this.logger?.debug("No existing tag collections found, will initialize with defaults");
|
|
735
737
|
}
|
|
736
738
|
if (this.entityTypesCollection === null) {
|
|
737
739
|
const { DEFAULT_ENTITY_TYPES } = await import("@semiont/ontology");
|
|
@@ -742,7 +744,7 @@ var NeptuneGraphDatabase = class {
|
|
|
742
744
|
await this.g.V(vertex.value.id).property(cardinality.set, "tags", tag).iterate();
|
|
743
745
|
}
|
|
744
746
|
} catch (error) {
|
|
745
|
-
|
|
747
|
+
this.logger?.error("Failed to initialize entity types", { error });
|
|
746
748
|
}
|
|
747
749
|
}
|
|
748
750
|
}
|
|
@@ -752,10 +754,10 @@ var NeptuneGraphDatabase = class {
|
|
|
752
754
|
async clearDatabase() {
|
|
753
755
|
try {
|
|
754
756
|
await this.g.V().drop().iterate();
|
|
755
|
-
|
|
757
|
+
this.logger?.info("Cleared all data from Neptune");
|
|
756
758
|
this.entityTypesCollection = null;
|
|
757
759
|
} catch (error) {
|
|
758
|
-
|
|
760
|
+
this.logger?.error("Failed to clear Neptune database", { error });
|
|
759
761
|
throw error;
|
|
760
762
|
}
|
|
761
763
|
}
|
|
@@ -778,11 +780,13 @@ function motivationToLabel(motivation) {
|
|
|
778
780
|
var Neo4jGraphDatabase = class {
|
|
779
781
|
driver = null;
|
|
780
782
|
connected = false;
|
|
783
|
+
logger;
|
|
781
784
|
config;
|
|
782
785
|
// Tag Collections - cached in memory for performance
|
|
783
786
|
entityTypesCollection = null;
|
|
784
787
|
constructor(config = {}) {
|
|
785
788
|
this.config = config;
|
|
789
|
+
this.logger = config.logger;
|
|
786
790
|
}
|
|
787
791
|
async connect() {
|
|
788
792
|
try {
|
|
@@ -802,7 +806,7 @@ var Neo4jGraphDatabase = class {
|
|
|
802
806
|
if (!database) {
|
|
803
807
|
throw new Error("Neo4j database not configured! Pass database in config.");
|
|
804
808
|
}
|
|
805
|
-
|
|
809
|
+
this.logger?.info("Connecting to Neo4j", { uri });
|
|
806
810
|
this.driver = neo4j.driver(
|
|
807
811
|
uri,
|
|
808
812
|
neo4j.auth.basic(username, password),
|
|
@@ -815,10 +819,10 @@ var Neo4jGraphDatabase = class {
|
|
|
815
819
|
await session.run("RETURN 1 as test");
|
|
816
820
|
await session.close();
|
|
817
821
|
await this.ensureSchemaExists();
|
|
818
|
-
|
|
822
|
+
this.logger?.info("Successfully connected to Neo4j");
|
|
819
823
|
this.connected = true;
|
|
820
824
|
} catch (error) {
|
|
821
|
-
|
|
825
|
+
this.logger?.error("Failed to connect to Neo4j", { error });
|
|
822
826
|
throw new Error(`Neo4j connection failed: ${error}`);
|
|
823
827
|
}
|
|
824
828
|
}
|
|
@@ -856,7 +860,7 @@ var Neo4jGraphDatabase = class {
|
|
|
856
860
|
await session.run(constraint);
|
|
857
861
|
} catch (error) {
|
|
858
862
|
if (!error.message?.includes("already exists")) {
|
|
859
|
-
|
|
863
|
+
this.logger?.warn("Schema creation warning", { message: error.message });
|
|
860
864
|
}
|
|
861
865
|
}
|
|
862
866
|
}
|
|
@@ -871,7 +875,7 @@ var Neo4jGraphDatabase = class {
|
|
|
871
875
|
await session.run(index);
|
|
872
876
|
} catch (error) {
|
|
873
877
|
if (!error.message?.includes("already exists")) {
|
|
874
|
-
|
|
878
|
+
this.logger?.warn("Index creation warning", { message: error.message });
|
|
875
879
|
}
|
|
876
880
|
}
|
|
877
881
|
}
|
|
@@ -915,7 +919,7 @@ var Neo4jGraphDatabase = class {
|
|
|
915
919
|
sourceResourceId: resource.sourceResourceId ?? null
|
|
916
920
|
}
|
|
917
921
|
);
|
|
918
|
-
|
|
922
|
+
this.logger?.info("Resource created/enriched", { id });
|
|
919
923
|
return this.parseResourceNode(result.records[0].get("d"));
|
|
920
924
|
} finally {
|
|
921
925
|
await session.close();
|
|
@@ -1107,7 +1111,7 @@ var Neo4jGraphDatabase = class {
|
|
|
1107
1111
|
}
|
|
1108
1112
|
}
|
|
1109
1113
|
async getAnnotation(id) {
|
|
1110
|
-
|
|
1114
|
+
this.logger?.debug("Getting annotation", { id });
|
|
1111
1115
|
const session = this.getSession();
|
|
1112
1116
|
try {
|
|
1113
1117
|
const result = await session.run(
|
|
@@ -1117,10 +1121,10 @@ var Neo4jGraphDatabase = class {
|
|
|
1117
1121
|
{ id }
|
|
1118
1122
|
);
|
|
1119
1123
|
if (result.records.length === 0) {
|
|
1120
|
-
|
|
1124
|
+
this.logger?.debug("Annotation not found", { id });
|
|
1121
1125
|
return null;
|
|
1122
1126
|
}
|
|
1123
|
-
|
|
1127
|
+
this.logger?.debug("Annotation found", { id });
|
|
1124
1128
|
return this.parseAnnotationNode(
|
|
1125
1129
|
result.records[0].get("a"),
|
|
1126
1130
|
result.records[0].get("entityTypes")
|
|
@@ -1159,7 +1163,7 @@ var Neo4jGraphDatabase = class {
|
|
|
1159
1163
|
}
|
|
1160
1164
|
if (updates.motivation) {
|
|
1161
1165
|
const newLabel = motivationToLabel(updates.motivation);
|
|
1162
|
-
|
|
1166
|
+
this.logger?.debug("Updating motivation label", { newLabel });
|
|
1163
1167
|
const allMotivations = [
|
|
1164
1168
|
"Assessing",
|
|
1165
1169
|
"Bookmarking",
|
|
@@ -1182,20 +1186,14 @@ var Neo4jGraphDatabase = class {
|
|
|
1182
1186
|
SET a:${newLabel}`,
|
|
1183
1187
|
{ id }
|
|
1184
1188
|
);
|
|
1185
|
-
|
|
1189
|
+
this.logger?.debug("Motivation label updated", { newLabel });
|
|
1186
1190
|
}
|
|
1187
1191
|
if (updates.body) {
|
|
1188
|
-
|
|
1189
|
-
console.log(`[Neo4j] updates.body:`, JSON.stringify(updates.body));
|
|
1192
|
+
this.logger?.debug("Body update for annotation", { id, body: updates.body });
|
|
1190
1193
|
const bodyArray = Array.isArray(updates.body) ? updates.body : [updates.body];
|
|
1191
|
-
console.log(`[Neo4j] bodyArray length: ${bodyArray.length}`);
|
|
1192
|
-
bodyArray.forEach((item, idx) => {
|
|
1193
|
-
console.log(`[Neo4j] Body item ${idx}:`, JSON.stringify(item));
|
|
1194
|
-
});
|
|
1195
1194
|
const specificResource = bodyArray.find((item) => item.type === "SpecificResource" && item.purpose === "linking");
|
|
1196
|
-
console.log(`[Neo4j] Found SpecificResource:`, specificResource ? JSON.stringify(specificResource) : "null");
|
|
1197
1195
|
if (specificResource && "source" in specificResource && specificResource.source) {
|
|
1198
|
-
|
|
1196
|
+
this.logger?.debug("Creating REFERENCES edge", { annotationId: id, targetResourceId: specificResource.source });
|
|
1199
1197
|
const refResult = await session.run(
|
|
1200
1198
|
`MATCH (a:Annotation {id: $annotationId})
|
|
1201
1199
|
MERGE (target:Resource {id: $targetResourceId})
|
|
@@ -1210,18 +1208,18 @@ var Neo4jGraphDatabase = class {
|
|
|
1210
1208
|
if (refResult.records.length > 0) {
|
|
1211
1209
|
const wasStub = refResult.records[0].get("wasStub");
|
|
1212
1210
|
if (wasStub) {
|
|
1213
|
-
|
|
1211
|
+
this.logger?.debug("REFERENCES edge created with stub node", { targetResourceId: specificResource.source });
|
|
1214
1212
|
} else {
|
|
1215
|
-
|
|
1213
|
+
this.logger?.debug("REFERENCES edge created to existing resource", { targetResourceId: specificResource.source });
|
|
1216
1214
|
}
|
|
1217
1215
|
} else {
|
|
1218
|
-
|
|
1216
|
+
this.logger?.warn("REFERENCES edge creation returned no records");
|
|
1219
1217
|
}
|
|
1220
1218
|
} else {
|
|
1221
|
-
|
|
1219
|
+
this.logger?.debug("No SpecificResource in body - stub reference not yet resolved");
|
|
1222
1220
|
}
|
|
1223
1221
|
} else {
|
|
1224
|
-
|
|
1222
|
+
this.logger?.debug("No body update for annotation", { id });
|
|
1225
1223
|
}
|
|
1226
1224
|
return this.parseAnnotationNode(
|
|
1227
1225
|
result.records[0].get("a"),
|
|
@@ -1381,15 +1379,14 @@ var Neo4jGraphDatabase = class {
|
|
|
1381
1379
|
async getResourceReferencedBy(resourceUri3, motivation) {
|
|
1382
1380
|
const session = this.getSession();
|
|
1383
1381
|
try {
|
|
1384
|
-
|
|
1385
|
-
console.log(`[Neo4j] getResourceReferencedBy: Searching for annotations${filterDesc} referencing ${resourceUri3}`);
|
|
1382
|
+
this.logger?.debug("Searching for annotations referencing resource", { resourceUri: resourceUri3, motivation });
|
|
1386
1383
|
const motivationLabel = motivation ? `:${motivationToLabel(motivation)}` : "";
|
|
1387
1384
|
const cypher = `MATCH (a:Annotation${motivationLabel})-[:REFERENCES]->(d:Resource {id: $resourceUri})
|
|
1388
1385
|
OPTIONAL MATCH (a)-[:TAGGED_AS]->(et:EntityType)
|
|
1389
1386
|
RETURN a, collect(et.name) as entityTypes
|
|
1390
1387
|
ORDER BY a.created DESC`;
|
|
1391
1388
|
const result = await session.run(cypher, { resourceUri: resourceUri3 });
|
|
1392
|
-
|
|
1389
|
+
this.logger?.debug("Found annotations", { count: result.records.length });
|
|
1393
1390
|
return result.records.map(
|
|
1394
1391
|
(record) => this.parseAnnotationNode(record.get("a"), record.get("entityTypes"))
|
|
1395
1392
|
);
|
|
@@ -1743,10 +1740,12 @@ var JanusGraphDatabase = class {
|
|
|
1743
1740
|
constructor(graphConfig, envConfig) {
|
|
1744
1741
|
this.graphConfig = graphConfig;
|
|
1745
1742
|
this.envConfig = envConfig;
|
|
1743
|
+
this.logger = graphConfig.logger;
|
|
1746
1744
|
}
|
|
1747
1745
|
connected = false;
|
|
1748
1746
|
connection = null;
|
|
1749
1747
|
g = null;
|
|
1748
|
+
logger;
|
|
1750
1749
|
// Tag Collections - cached in memory for performance
|
|
1751
1750
|
entityTypesCollection = null;
|
|
1752
1751
|
async connect() {
|
|
@@ -1758,7 +1757,7 @@ var JanusGraphDatabase = class {
|
|
|
1758
1757
|
if (!port) {
|
|
1759
1758
|
throw new Error("JanusGraph port is required: provide in config");
|
|
1760
1759
|
}
|
|
1761
|
-
|
|
1760
|
+
this.logger?.info("Connecting to JanusGraph", { host, port });
|
|
1762
1761
|
this.connection = new DriverRemoteConnection(
|
|
1763
1762
|
`ws://${host}:${port}/gremlin`,
|
|
1764
1763
|
{}
|
|
@@ -1766,7 +1765,7 @@ var JanusGraphDatabase = class {
|
|
|
1766
1765
|
this.g = traversal().withRemote(this.connection);
|
|
1767
1766
|
await this.g.V().limit(1).toList();
|
|
1768
1767
|
this.connected = true;
|
|
1769
|
-
|
|
1768
|
+
this.logger?.info("Successfully connected to JanusGraph");
|
|
1770
1769
|
await this.initializeSchema();
|
|
1771
1770
|
}
|
|
1772
1771
|
async disconnect() {
|
|
@@ -1779,7 +1778,7 @@ var JanusGraphDatabase = class {
|
|
|
1779
1778
|
return this.connected;
|
|
1780
1779
|
}
|
|
1781
1780
|
async initializeSchema() {
|
|
1782
|
-
|
|
1781
|
+
this.logger?.debug("Schema initialization would happen here in production");
|
|
1783
1782
|
}
|
|
1784
1783
|
// Helper function to convert vertex to Resource
|
|
1785
1784
|
vertexToResource(vertex) {
|
|
@@ -1899,7 +1898,7 @@ var JanusGraphDatabase = class {
|
|
|
1899
1898
|
vertex.property("sourceResourceId", resource.sourceResourceId);
|
|
1900
1899
|
}
|
|
1901
1900
|
await vertex.next();
|
|
1902
|
-
|
|
1901
|
+
this.logger?.info("Created resource vertex in JanusGraph", { id });
|
|
1903
1902
|
return resource;
|
|
1904
1903
|
}
|
|
1905
1904
|
async getResource(id) {
|
|
@@ -1922,7 +1921,7 @@ var JanusGraphDatabase = class {
|
|
|
1922
1921
|
}
|
|
1923
1922
|
async deleteResource(id) {
|
|
1924
1923
|
await this.g.V().has("Resource", "id", id).drop().next();
|
|
1925
|
-
|
|
1924
|
+
this.logger?.info("Deleted resource from JanusGraph", { id });
|
|
1926
1925
|
}
|
|
1927
1926
|
async listResources(filter) {
|
|
1928
1927
|
let traversalQuery = this.g.V().hasLabel("Resource");
|
|
@@ -1985,7 +1984,7 @@ var JanusGraphDatabase = class {
|
|
|
1985
1984
|
}
|
|
1986
1985
|
await this.g.V(annVertex.value).addE("TAGGED_AS").to(this.g.V(etVertex.value)).next();
|
|
1987
1986
|
}
|
|
1988
|
-
|
|
1987
|
+
this.logger?.info("Created annotation in JanusGraph", { id });
|
|
1989
1988
|
return annotation;
|
|
1990
1989
|
}
|
|
1991
1990
|
async getAnnotation(id) {
|
|
@@ -2044,7 +2043,7 @@ var JanusGraphDatabase = class {
|
|
|
2044
2043
|
}
|
|
2045
2044
|
async deleteAnnotation(id) {
|
|
2046
2045
|
await this.g.V().has("Annotation", "id", id).drop().next();
|
|
2047
|
-
|
|
2046
|
+
this.logger?.info("Deleted annotation from JanusGraph", { id });
|
|
2048
2047
|
}
|
|
2049
2048
|
async listAnnotations(filter) {
|
|
2050
2049
|
let traversalQuery = this.g.V().hasLabel("Annotation");
|
|
@@ -2119,7 +2118,7 @@ var JanusGraphDatabase = class {
|
|
|
2119
2118
|
}
|
|
2120
2119
|
async getResourceConnections(resourceId) {
|
|
2121
2120
|
const paths = await this.g.V().has("Resource", "id", resourceId).inE("BELONGS_TO").outV().outE("REFERENCES").inV().path().toList();
|
|
2122
|
-
|
|
2121
|
+
this.logger?.debug("Found paths", { count: paths.length });
|
|
2123
2122
|
const connections = [];
|
|
2124
2123
|
const refs = await this.getReferences(resourceId);
|
|
2125
2124
|
for (const ref of refs) {
|
|
@@ -2222,7 +2221,7 @@ var JanusGraphDatabase = class {
|
|
|
2222
2221
|
await this.g.addV("TagCollection").property("type", "entity-types").property("tags", JSON.stringify(Array.from(this.entityTypesCollection))).next();
|
|
2223
2222
|
}
|
|
2224
2223
|
} catch (error) {
|
|
2225
|
-
|
|
2224
|
+
this.logger?.error("Failed to add entity type", { error });
|
|
2226
2225
|
}
|
|
2227
2226
|
}
|
|
2228
2227
|
async addEntityTypes(tags) {
|
|
@@ -2238,7 +2237,7 @@ var JanusGraphDatabase = class {
|
|
|
2238
2237
|
await this.g.addV("TagCollection").property("type", "entity-types").property("tags", JSON.stringify(Array.from(this.entityTypesCollection))).next();
|
|
2239
2238
|
}
|
|
2240
2239
|
} catch (error) {
|
|
2241
|
-
|
|
2240
|
+
this.logger?.error("Failed to add entity types", { error });
|
|
2242
2241
|
}
|
|
2243
2242
|
}
|
|
2244
2243
|
async initializeTagCollections() {
|
|
@@ -2265,12 +2264,11 @@ var JanusGraphDatabase = class {
|
|
|
2265
2264
|
async clearDatabase() {
|
|
2266
2265
|
await this.g.V().drop().next();
|
|
2267
2266
|
this.entityTypesCollection = null;
|
|
2268
|
-
|
|
2267
|
+
this.logger?.info("Cleared JanusGraph database");
|
|
2269
2268
|
}
|
|
2270
2269
|
};
|
|
2271
2270
|
|
|
2272
2271
|
// src/implementations/memorygraph.ts
|
|
2273
|
-
import { getEntityTypes as getEntityTypes4 } from "@semiont/ontology";
|
|
2274
2272
|
import { resourceId as makeResourceId, uriToResourceId, resourceUri as resourceUri2 } from "@semiont/core";
|
|
2275
2273
|
import { v4 as uuidv44 } from "uuid";
|
|
2276
2274
|
import {
|
|
@@ -2282,14 +2280,15 @@ import {
|
|
|
2282
2280
|
} from "@semiont/api-client";
|
|
2283
2281
|
var MemoryGraphDatabase = class {
|
|
2284
2282
|
connected = false;
|
|
2283
|
+
logger;
|
|
2285
2284
|
// In-memory storage using Maps
|
|
2286
2285
|
resources = /* @__PURE__ */ new Map();
|
|
2287
2286
|
annotations = /* @__PURE__ */ new Map();
|
|
2288
2287
|
constructor(config = {}) {
|
|
2289
|
-
|
|
2288
|
+
this.logger = config.logger;
|
|
2290
2289
|
}
|
|
2291
2290
|
async connect() {
|
|
2292
|
-
|
|
2291
|
+
this.logger?.info("Using in-memory graph database");
|
|
2293
2292
|
this.connected = true;
|
|
2294
2293
|
}
|
|
2295
2294
|
async disconnect() {
|
|
@@ -2372,7 +2371,7 @@ var MemoryGraphDatabase = class {
|
|
|
2372
2371
|
created: (/* @__PURE__ */ new Date()).toISOString()
|
|
2373
2372
|
};
|
|
2374
2373
|
this.annotations.set(id, annotation);
|
|
2375
|
-
|
|
2374
|
+
this.logger?.debug("Created annotation", {
|
|
2376
2375
|
id,
|
|
2377
2376
|
motivation: annotation.motivation,
|
|
2378
2377
|
hasSource: !!getBodySource4(annotation.body),
|
|
@@ -2419,7 +2418,7 @@ var MemoryGraphDatabase = class {
|
|
|
2419
2418
|
const targetResourceId = targetSource ? uriToResourceId(targetSource) : null;
|
|
2420
2419
|
return targetResourceId === resourceIdStr && sel.motivation === "highlighting";
|
|
2421
2420
|
});
|
|
2422
|
-
|
|
2421
|
+
this.logger?.debug("Got highlights for resource", { resourceId, count: highlights.length });
|
|
2423
2422
|
return highlights;
|
|
2424
2423
|
}
|
|
2425
2424
|
async resolveReference(annotationId, source) {
|
|
@@ -2445,15 +2444,7 @@ var MemoryGraphDatabase = class {
|
|
|
2445
2444
|
const targetResourceId = targetSource ? uriToResourceId(targetSource) : null;
|
|
2446
2445
|
return targetResourceId === resourceIdStr && sel.motivation === "linking";
|
|
2447
2446
|
});
|
|
2448
|
-
|
|
2449
|
-
references.forEach((ref) => {
|
|
2450
|
-
console.log(" Reference:", {
|
|
2451
|
-
id: ref.id,
|
|
2452
|
-
source: getBodySource4(ref.body),
|
|
2453
|
-
entityTypes: getEntityTypes4(ref)
|
|
2454
|
-
// from body
|
|
2455
|
-
});
|
|
2456
|
-
});
|
|
2447
|
+
this.logger?.debug("Got references for resource", { resourceId, count: references.length });
|
|
2457
2448
|
return references;
|
|
2458
2449
|
}
|
|
2459
2450
|
async getEntityReferences(resourceId, entityTypes) {
|