@semiont/graph 0.3.1 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -81,6 +81,7 @@ type ResourceDescriptor$3 = components['schemas']['ResourceDescriptor'];
81
81
  type Annotation$3 = components['schemas']['Annotation'];
82
82
  declare class Neo4jGraphDatabase implements GraphDatabase {
83
83
  private driver;
84
+ private neo4j;
84
85
  private connected;
85
86
  private logger?;
86
87
  private config;
package/dist/index.js CHANGED
@@ -211,17 +211,17 @@ var NeptuneGraphDatabase = class {
211
211
  await this.discoverNeptuneEndpoint();
212
212
  try {
213
213
  await loadDependencies();
214
- const traversal2 = gremlin.process.AnonymousTraversalSource.traversal;
215
- const DriverRemoteConnection2 = gremlin.driver.DriverRemoteConnection;
214
+ const traversal = gremlin.process.AnonymousTraversalSource.traversal;
215
+ const DriverRemoteConnection = gremlin.driver.DriverRemoteConnection;
216
216
  const connectionUrl = `wss://${this.neptuneEndpoint}:${this.neptunePort}/gremlin`;
217
217
  this.logger?.info("Connecting to Neptune", { connectionUrl });
218
- this.connection = new DriverRemoteConnection2(connectionUrl, {
218
+ this.connection = new DriverRemoteConnection(connectionUrl, {
219
219
  authenticator: null,
220
220
  // Neptune uses IAM authentication via task role
221
221
  rejectUnauthorized: true,
222
222
  traversalSource: "g"
223
223
  });
224
- this.g = traversal2().withRemote(this.connection);
224
+ this.g = traversal().withRemote(this.connection);
225
225
  const count = await this.g.V().limit(1).count().next();
226
226
  this.logger?.info("Connected to Neptune", { vertexCountTest: count.value });
227
227
  this.connected = true;
@@ -301,9 +301,9 @@ var NeptuneGraphDatabase = class {
301
301
  }
302
302
  async listResources(filter) {
303
303
  try {
304
- let traversal2 = this.g.V().hasLabel("Resource");
304
+ let traversal = this.g.V().hasLabel("Resource");
305
305
  if (filter.entityTypes && filter.entityTypes.length > 0) {
306
- traversal2 = traversal2.filter(
306
+ traversal = traversal.filter(
307
307
  process2.statics.or(
308
308
  ...filter.entityTypes.map(
309
309
  (type) => process2.statics.has("entityTypes", TextP.containing(`"${type}"`))
@@ -312,13 +312,13 @@ var NeptuneGraphDatabase = class {
312
312
  );
313
313
  }
314
314
  if (filter.search) {
315
- traversal2 = traversal2.has("name", TextP.containing(filter.search));
315
+ traversal = traversal.has("name", TextP.containing(filter.search));
316
316
  }
317
- const totalResult = await traversal2.clone().count().next();
317
+ const totalResult = await traversal.clone().count().next();
318
318
  const total = totalResult.value || 0;
319
319
  const offset = filter.offset || 0;
320
320
  const limit = filter.limit || 20;
321
- const results = await traversal2.order().by("created", order.desc).range(offset, offset + limit).elementMap().toList();
321
+ const results = await traversal.order().by("created", order.desc).range(offset, offset + limit).elementMap().toList();
322
322
  const resources = results.map(vertexToResource);
323
323
  return { resources, total };
324
324
  } catch (error) {
@@ -391,17 +391,17 @@ var NeptuneGraphDatabase = class {
391
391
  }
392
392
  async updateAnnotation(id, updates) {
393
393
  try {
394
- let traversal2 = this.g.V().hasLabel("Annotation").has("id", id);
394
+ let traversal = this.g.V().hasLabel("Annotation").has("id", id);
395
395
  if (updates.target !== void 0 && typeof updates.target !== "string") {
396
396
  if (updates.target.selector !== void 0) {
397
- traversal2 = traversal2.property("text", getExactText(updates.target.selector));
397
+ traversal = traversal.property("text", getExactText(updates.target.selector));
398
398
  }
399
399
  }
400
400
  if (updates.body !== void 0) {
401
401
  const bodySource = getBodySource(updates.body);
402
402
  const entityTypes2 = getEntityTypes({ body: updates.body });
403
403
  if (bodySource) {
404
- traversal2 = traversal2.property("source", bodySource);
404
+ traversal = traversal.property("source", bodySource);
405
405
  }
406
406
  if (entityTypes2.length >= 0) {
407
407
  await this.g.V().hasLabel("Annotation").has("id", id).outE("TAGGED_AS").drop().iterate();
@@ -415,12 +415,12 @@ var NeptuneGraphDatabase = class {
415
415
  }
416
416
  }
417
417
  if (updates.modified !== void 0) {
418
- traversal2 = traversal2.property("modified", updates.modified);
418
+ traversal = traversal.property("modified", updates.modified);
419
419
  }
420
420
  if (updates.generator !== void 0) {
421
- traversal2 = traversal2.property("generator", JSON.stringify(updates.generator));
421
+ traversal = traversal.property("generator", JSON.stringify(updates.generator));
422
422
  }
423
- const result = await traversal2.elementMap().next();
423
+ const result = await traversal.elementMap().next();
424
424
  if (!result.value) {
425
425
  throw new Error("Annotation not found");
426
426
  }
@@ -443,15 +443,15 @@ var NeptuneGraphDatabase = class {
443
443
  }
444
444
  async listAnnotations(filter) {
445
445
  try {
446
- let traversal2 = this.g.V().hasLabel("Annotation");
446
+ let traversal = this.g.V().hasLabel("Annotation");
447
447
  if (filter.resourceId) {
448
- traversal2 = traversal2.has("resourceId", filter.resourceId);
448
+ traversal = traversal.has("resourceId", filter.resourceId);
449
449
  }
450
450
  if (filter.type) {
451
451
  const w3cType = filter.type === "highlight" ? "TextualBody" : "SpecificResource";
452
- traversal2 = traversal2.has("type", w3cType);
452
+ traversal = traversal.has("type", w3cType);
453
453
  }
454
- const results = await traversal2.elementMap().toList();
454
+ const results = await traversal.elementMap().toList();
455
455
  const annotations = await this.fetchAnnotationsWithEntityTypes(results);
456
456
  return { annotations, total: annotations.length };
457
457
  } catch (error) {
@@ -472,8 +472,8 @@ var NeptuneGraphDatabase = class {
472
472
  try {
473
473
  const targetDocResult = await this.g.V().hasLabel("Resource").has("id", source).elementMap().next();
474
474
  const targetDoc = targetDocResult.value ? vertexToResource(targetDocResult.value) : null;
475
- const traversal2 = this.g.V().hasLabel("Annotation").has("id", annotationId).property("source", source).property("resolvedResourceName", targetDoc?.name).property("resolvedAt", (/* @__PURE__ */ new Date()).toISOString());
476
- const result = await traversal2.elementMap().next();
475
+ const traversal = this.g.V().hasLabel("Annotation").has("id", annotationId).property("source", source).property("resolvedResourceName", targetDoc?.name).property("resolvedAt", (/* @__PURE__ */ new Date()).toISOString());
476
+ const result = await traversal.elementMap().next();
477
477
  if (!result.value) {
478
478
  throw new Error("Annotation not found");
479
479
  }
@@ -498,9 +498,9 @@ var NeptuneGraphDatabase = class {
498
498
  }
499
499
  async getEntityReferences(resourceId, entityTypes) {
500
500
  try {
501
- let traversal2 = this.g.V().hasLabel("Annotation").has("resourceId", resourceId).has("resolvedResourceId").has("entityTypes");
501
+ let traversal = this.g.V().hasLabel("Annotation").has("resourceId", resourceId).has("resolvedResourceId").has("entityTypes");
502
502
  if (entityTypes && entityTypes.length > 0) {
503
- traversal2 = traversal2.filter(
503
+ traversal = traversal.filter(
504
504
  process2.statics.or(
505
505
  ...entityTypes.map(
506
506
  (type) => process2.statics.has("entityTypes", TextP.containing(`"${type}"`))
@@ -508,7 +508,7 @@ var NeptuneGraphDatabase = class {
508
508
  )
509
509
  );
510
510
  }
511
- const results = await traversal2.elementMap().toList();
511
+ const results = await traversal.elementMap().toList();
512
512
  return await this.fetchAnnotationsWithEntityTypes(results);
513
513
  } catch (error) {
514
514
  this.logger?.error("Failed to get entity references from Neptune", { error });
@@ -771,7 +771,6 @@ var NeptuneGraphDatabase = class {
771
771
  };
772
772
 
773
773
  // src/implementations/neo4j.ts
774
- import neo4j from "neo4j-driver";
775
774
  import { v4 as uuidv42 } from "uuid";
776
775
  import {
777
776
  getExactText as getExactText2,
@@ -786,6 +785,7 @@ function motivationToLabel(motivation) {
786
785
  }
787
786
  var Neo4jGraphDatabase = class {
788
787
  driver = null;
788
+ neo4j;
789
789
  connected = false;
790
790
  logger;
791
791
  config;
@@ -814,9 +814,10 @@ var Neo4jGraphDatabase = class {
814
814
  throw new Error("Neo4j database not configured! Pass database in config.");
815
815
  }
816
816
  this.logger?.info("Connecting to Neo4j", { uri });
817
- this.driver = neo4j.driver(
817
+ this.neo4j = await import("neo4j-driver");
818
+ this.driver = this.neo4j.driver(
818
819
  uri,
819
- neo4j.auth.basic(username, password),
820
+ this.neo4j.auth.basic(username, password),
820
821
  {
821
822
  maxConnectionPoolSize: 50,
822
823
  connectionAcquisitionTimeout: 6e4
@@ -1000,8 +1001,8 @@ var Neo4jGraphDatabase = class {
1000
1001
  params
1001
1002
  );
1002
1003
  const total = countResult.records[0].get("total").toNumber();
1003
- params.skip = neo4j.int(filter.offset || 0);
1004
- params.limit = neo4j.int(filter.limit || 20);
1004
+ params.skip = this.neo4j.int(filter.offset || 0);
1005
+ params.limit = this.neo4j.int(filter.limit || 20);
1005
1006
  const result = await session.run(
1006
1007
  `MATCH (d:Resource) ${whereClause}
1007
1008
  RETURN d
@@ -1024,7 +1025,7 @@ var Neo4jGraphDatabase = class {
1024
1025
  RETURN d
1025
1026
  ORDER BY d.updatedAt DESC
1026
1027
  LIMIT $limit`,
1027
- { query, limit: neo4j.int(limit) }
1028
+ { query, limit: this.neo4j.int(limit) }
1028
1029
  );
1029
1030
  return result.records.map((record) => this.parseResourceNode(record.get("d")));
1030
1031
  } finally {
@@ -1775,7 +1776,6 @@ var Neo4jGraphDatabase = class {
1775
1776
  };
1776
1777
 
1777
1778
  // src/implementations/janusgraph.ts
1778
- import gremlin2 from "gremlin";
1779
1779
  import { resourceId as makeResourceId } from "@semiont/core";
1780
1780
  import {
1781
1781
  getBodySource as getBodySource3,
@@ -1785,8 +1785,6 @@ import {
1785
1785
  } from "@semiont/api-client";
1786
1786
  import { getEntityTypes as getEntityTypes3 } from "@semiont/ontology";
1787
1787
  import { v4 as uuidv43 } from "uuid";
1788
- var traversal = gremlin2.process.AnonymousTraversalSource.traversal;
1789
- var DriverRemoteConnection = gremlin2.driver.DriverRemoteConnection;
1790
1788
  var JanusGraphDatabase = class {
1791
1789
  constructor(graphConfig) {
1792
1790
  this.graphConfig = graphConfig;
@@ -1808,6 +1806,9 @@ var JanusGraphDatabase = class {
1808
1806
  throw new Error("JanusGraph port is required: provide in config");
1809
1807
  }
1810
1808
  this.logger?.info("Connecting to JanusGraph", { host, port });
1809
+ const gremlin2 = await import("gremlin");
1810
+ const DriverRemoteConnection = gremlin2.driver.DriverRemoteConnection;
1811
+ const traversal = gremlin2.process.AnonymousTraversalSource.traversal;
1811
1812
  this.connection = new DriverRemoteConnection(
1812
1813
  `ws://${host}:${port}/gremlin`,
1813
1814
  {}
@@ -1976,7 +1977,8 @@ var JanusGraphDatabase = class {
1976
1977
  async listResources(filter) {
1977
1978
  let traversalQuery = this.g.V().hasLabel("Resource");
1978
1979
  if (filter.search) {
1979
- traversalQuery = traversalQuery.has("name", gremlin2.process.TextP.containing(filter.search));
1980
+ const { process: gremlinProcess } = await import("gremlin");
1981
+ traversalQuery = traversalQuery.has("name", gremlinProcess.TextP.containing(filter.search));
1980
1982
  }
1981
1983
  const docs = await traversalQuery.toList();
1982
1984
  let resources = docs.map((v) => this.vertexToResource(v));