@semiont/graph 0.2.45 → 0.3.0

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
@@ -1,4 +1,4 @@
1
- import { components, ResourceUri, UpdateResourceInput, ResourceFilter, CreateAnnotationInternal, AnnotationUri, ResourceId, AnnotationCategory, AnnotationId, GraphConnection, GraphPath, EntityTypeStats, EnvironmentConfig, Logger } from '@semiont/core';
1
+ import { components, ResourceId, UpdateResourceInput, ResourceFilter, CreateAnnotationInternal, AnnotationId, AnnotationCategory, GraphConnection, GraphPath, EntityTypeStats, GraphServiceConfig, Logger } from '@semiont/core';
2
2
 
3
3
  type ResourceDescriptor$4 = components['schemas']['ResourceDescriptor'];
4
4
  type Annotation$4 = components['schemas']['Annotation'];
@@ -7,18 +7,18 @@ interface GraphDatabase {
7
7
  disconnect(): Promise<void>;
8
8
  isConnected(): boolean;
9
9
  createResource(resource: ResourceDescriptor$4): Promise<ResourceDescriptor$4>;
10
- getResource(id: ResourceUri): Promise<ResourceDescriptor$4 | null>;
11
- updateResource(id: ResourceUri, input: UpdateResourceInput): Promise<ResourceDescriptor$4>;
12
- deleteResource(id: ResourceUri): Promise<void>;
10
+ getResource(id: ResourceId): Promise<ResourceDescriptor$4 | null>;
11
+ updateResource(id: ResourceId, input: UpdateResourceInput): Promise<ResourceDescriptor$4>;
12
+ deleteResource(id: ResourceId): Promise<void>;
13
13
  listResources(filter: ResourceFilter): Promise<{
14
14
  resources: ResourceDescriptor$4[];
15
15
  total: number;
16
16
  }>;
17
17
  searchResources(query: string, limit?: number): Promise<ResourceDescriptor$4[]>;
18
18
  createAnnotation(input: CreateAnnotationInternal): Promise<Annotation$4>;
19
- getAnnotation(id: AnnotationUri): Promise<Annotation$4 | null>;
20
- updateAnnotation(id: AnnotationUri, updates: Partial<Annotation$4>): Promise<Annotation$4>;
21
- deleteAnnotation(id: AnnotationUri): Promise<void>;
19
+ getAnnotation(id: AnnotationId): Promise<Annotation$4 | null>;
20
+ updateAnnotation(id: AnnotationId, updates: Partial<Annotation$4>): Promise<Annotation$4>;
21
+ deleteAnnotation(id: AnnotationId): Promise<void>;
22
22
  listAnnotations(filter: {
23
23
  resourceId?: ResourceId;
24
24
  type?: AnnotationCategory;
@@ -31,7 +31,7 @@ interface GraphDatabase {
31
31
  getReferences(resourceId: ResourceId): Promise<Annotation$4[]>;
32
32
  getEntityReferences(resourceId: ResourceId, entityTypes?: string[]): Promise<Annotation$4[]>;
33
33
  getResourceAnnotations(resourceId: ResourceId): Promise<Annotation$4[]>;
34
- getResourceReferencedBy(resourceUri: ResourceUri, motivation?: string): Promise<Annotation$4[]>;
34
+ getResourceReferencedBy(resourceId: ResourceId, motivation?: string): Promise<Annotation$4[]>;
35
35
  getResourceConnections(resourceId: ResourceId): Promise<GraphConnection[]>;
36
36
  findPath(fromResourceId: ResourceId, toResourceId: ResourceId, maxDepth?: number): Promise<GraphPath[]>;
37
37
  getEntityTypeStats(): Promise<EntityTypeStats[]>;
@@ -73,8 +73,8 @@ interface GraphDatabaseConfig {
73
73
  janusStorageBackend?: 'cassandra' | 'hbase' | 'berkeleydb';
74
74
  janusIndexBackend?: 'elasticsearch' | 'solr' | 'lucene';
75
75
  }
76
- declare function createGraphDatabase(config: GraphDatabaseConfig, envConfig: EnvironmentConfig): GraphDatabase;
77
- declare function getGraphDatabase(envConfig: EnvironmentConfig): Promise<GraphDatabase>;
76
+ declare function createGraphDatabase(config: GraphDatabaseConfig): GraphDatabase;
77
+ declare function getGraphDatabase(graphConfig: GraphServiceConfig): Promise<GraphDatabase>;
78
78
  declare function closeGraphDatabase(): Promise<void>;
79
79
 
80
80
  type ResourceDescriptor$3 = components['schemas']['ResourceDescriptor'];
@@ -98,18 +98,18 @@ declare class Neo4jGraphDatabase implements GraphDatabase {
98
98
  private getSession;
99
99
  private ensureSchemaExists;
100
100
  createResource(resource: ResourceDescriptor$3): Promise<ResourceDescriptor$3>;
101
- getResource(id: ResourceUri): Promise<ResourceDescriptor$3 | null>;
102
- updateResource(id: ResourceUri, input: UpdateResourceInput): Promise<ResourceDescriptor$3>;
103
- deleteResource(id: ResourceUri): Promise<void>;
101
+ getResource(id: ResourceId): Promise<ResourceDescriptor$3 | null>;
102
+ updateResource(id: ResourceId, input: UpdateResourceInput): Promise<ResourceDescriptor$3>;
103
+ deleteResource(id: ResourceId): Promise<void>;
104
104
  listResources(filter: ResourceFilter): Promise<{
105
105
  resources: ResourceDescriptor$3[];
106
106
  total: number;
107
107
  }>;
108
108
  searchResources(query: string, limit?: number): Promise<ResourceDescriptor$3[]>;
109
109
  createAnnotation(input: CreateAnnotationInternal): Promise<Annotation$3>;
110
- getAnnotation(id: AnnotationUri): Promise<Annotation$3 | null>;
111
- updateAnnotation(id: AnnotationUri, updates: Partial<Annotation$3>): Promise<Annotation$3>;
112
- deleteAnnotation(id: AnnotationUri): Promise<void>;
110
+ getAnnotation(id: AnnotationId): Promise<Annotation$3 | null>;
111
+ updateAnnotation(id: AnnotationId, updates: Partial<Annotation$3>): Promise<Annotation$3>;
112
+ deleteAnnotation(id: AnnotationId): Promise<void>;
113
113
  listAnnotations(filter: {
114
114
  resourceId?: ResourceId;
115
115
  type?: AnnotationCategory;
@@ -122,7 +122,7 @@ declare class Neo4jGraphDatabase implements GraphDatabase {
122
122
  getReferences(resourceId: ResourceId): Promise<Annotation$3[]>;
123
123
  getEntityReferences(resourceId: ResourceId, entityTypes?: string[]): Promise<Annotation$3[]>;
124
124
  getResourceAnnotations(resourceId: ResourceId): Promise<Annotation$3[]>;
125
- getResourceReferencedBy(resourceUri: ResourceUri, motivation?: string): Promise<Annotation$3[]>;
125
+ getResourceReferencedBy(resourceId: ResourceId, motivation?: string): Promise<Annotation$3[]>;
126
126
  getResourceConnections(resourceId: ResourceId): Promise<GraphConnection[]>;
127
127
  findPath(fromResourceId: string, toResourceId: string, maxDepth?: number): Promise<GraphPath[]>;
128
128
  getEntityTypeStats(): Promise<EntityTypeStats[]>;
@@ -175,18 +175,18 @@ declare class NeptuneGraphDatabase implements GraphDatabase {
175
175
  disconnect(): Promise<void>;
176
176
  isConnected(): boolean;
177
177
  createResource(resource: ResourceDescriptor$2): Promise<ResourceDescriptor$2>;
178
- getResource(id: ResourceUri): Promise<ResourceDescriptor$2 | null>;
179
- updateResource(id: ResourceUri, input: UpdateResourceInput): Promise<ResourceDescriptor$2>;
180
- deleteResource(id: ResourceUri): Promise<void>;
178
+ getResource(id: ResourceId): Promise<ResourceDescriptor$2 | null>;
179
+ updateResource(id: ResourceId, input: UpdateResourceInput): Promise<ResourceDescriptor$2>;
180
+ deleteResource(id: ResourceId): Promise<void>;
181
181
  listResources(filter: ResourceFilter): Promise<{
182
182
  resources: ResourceDescriptor$2[];
183
183
  total: number;
184
184
  }>;
185
185
  searchResources(query: string, limit?: number): Promise<ResourceDescriptor$2[]>;
186
186
  createAnnotation(input: CreateAnnotationInternal): Promise<Annotation$2>;
187
- getAnnotation(id: AnnotationUri): Promise<Annotation$2 | null>;
188
- updateAnnotation(id: AnnotationUri, updates: Partial<Annotation$2>): Promise<Annotation$2>;
189
- deleteAnnotation(id: AnnotationUri): Promise<void>;
187
+ getAnnotation(id: AnnotationId): Promise<Annotation$2 | null>;
188
+ updateAnnotation(id: AnnotationId, updates: Partial<Annotation$2>): Promise<Annotation$2>;
189
+ deleteAnnotation(id: AnnotationId): Promise<void>;
190
190
  listAnnotations(filter: {
191
191
  resourceId?: ResourceId;
192
192
  type?: AnnotationCategory;
@@ -199,7 +199,7 @@ declare class NeptuneGraphDatabase implements GraphDatabase {
199
199
  getReferences(resourceId: ResourceId): Promise<Annotation$2[]>;
200
200
  getEntityReferences(resourceId: ResourceId, entityTypes?: string[]): Promise<Annotation$2[]>;
201
201
  getResourceAnnotations(resourceId: ResourceId): Promise<Annotation$2[]>;
202
- getResourceReferencedBy(resourceUri: ResourceUri, _motivation?: string): Promise<Annotation$2[]>;
202
+ getResourceReferencedBy(resourceId: ResourceId, _motivation?: string): Promise<Annotation$2[]>;
203
203
  getResourceConnections(resourceId: ResourceId): Promise<GraphConnection[]>;
204
204
  findPath(fromResourceId: string, toResourceId: string, maxDepth?: number): Promise<GraphPath[]>;
205
205
  getEntityTypeStats(): Promise<EntityTypeStats[]>;
@@ -232,7 +232,6 @@ type ResourceDescriptor$1 = components['schemas']['ResourceDescriptor'];
232
232
  type Annotation$1 = components['schemas']['Annotation'];
233
233
  declare class JanusGraphDatabase implements GraphDatabase {
234
234
  private graphConfig;
235
- private envConfig;
236
235
  private connected;
237
236
  private connection;
238
237
  private g;
@@ -244,7 +243,7 @@ declare class JanusGraphDatabase implements GraphDatabase {
244
243
  storageBackend?: 'cassandra' | 'hbase' | 'berkeleydb';
245
244
  indexBackend?: 'elasticsearch' | 'solr' | 'lucene';
246
245
  logger?: Logger;
247
- }, envConfig: EnvironmentConfig);
246
+ });
248
247
  connect(): Promise<void>;
249
248
  disconnect(): Promise<void>;
250
249
  isConnected(): boolean;
@@ -254,18 +253,18 @@ declare class JanusGraphDatabase implements GraphDatabase {
254
253
  private fetchAnnotationsWithEntityTypes;
255
254
  private vertexToAnnotation;
256
255
  createResource(resource: ResourceDescriptor$1): Promise<ResourceDescriptor$1>;
257
- getResource(id: ResourceUri): Promise<ResourceDescriptor$1 | null>;
258
- updateResource(id: ResourceUri, input: UpdateResourceInput): Promise<ResourceDescriptor$1>;
259
- deleteResource(id: ResourceUri): Promise<void>;
256
+ getResource(id: ResourceId): Promise<ResourceDescriptor$1 | null>;
257
+ updateResource(id: ResourceId, input: UpdateResourceInput): Promise<ResourceDescriptor$1>;
258
+ deleteResource(id: ResourceId): Promise<void>;
260
259
  listResources(filter: ResourceFilter): Promise<{
261
260
  resources: ResourceDescriptor$1[];
262
261
  total: number;
263
262
  }>;
264
263
  searchResources(query: string, limit?: number): Promise<ResourceDescriptor$1[]>;
265
264
  createAnnotation(input: CreateAnnotationInternal): Promise<Annotation$1>;
266
- getAnnotation(id: AnnotationUri): Promise<Annotation$1 | null>;
267
- updateAnnotation(id: AnnotationUri, updates: Partial<Annotation$1>): Promise<Annotation$1>;
268
- deleteAnnotation(id: AnnotationUri): Promise<void>;
265
+ getAnnotation(id: AnnotationId): Promise<Annotation$1 | null>;
266
+ updateAnnotation(id: AnnotationId, updates: Partial<Annotation$1>): Promise<Annotation$1>;
267
+ deleteAnnotation(id: AnnotationId): Promise<void>;
269
268
  listAnnotations(filter: {
270
269
  resourceId?: ResourceId;
271
270
  type?: AnnotationCategory;
@@ -278,7 +277,7 @@ declare class JanusGraphDatabase implements GraphDatabase {
278
277
  getReferences(resourceId: ResourceId): Promise<Annotation$1[]>;
279
278
  getEntityReferences(resourceId: ResourceId, entityTypes?: string[]): Promise<Annotation$1[]>;
280
279
  getResourceAnnotations(resourceId: ResourceId): Promise<Annotation$1[]>;
281
- getResourceReferencedBy(resourceUri: ResourceUri, _motivation?: string): Promise<Annotation$1[]>;
280
+ getResourceReferencedBy(resourceId: ResourceId, _motivation?: string): Promise<Annotation$1[]>;
282
281
  getResourceConnections(resourceId: ResourceId): Promise<GraphConnection[]>;
283
282
  findPath(_fromResourceId: string, _toResourceId: string, _maxDepth?: number): Promise<GraphPath[]>;
284
283
  getEntityTypeStats(): Promise<EntityTypeStats[]>;
@@ -312,18 +311,18 @@ declare class MemoryGraphDatabase implements GraphDatabase {
312
311
  disconnect(): Promise<void>;
313
312
  isConnected(): boolean;
314
313
  createResource(resource: ResourceDescriptor): Promise<ResourceDescriptor>;
315
- getResource(id: ResourceUri): Promise<ResourceDescriptor | null>;
316
- updateResource(id: ResourceUri, input: UpdateResourceInput): Promise<ResourceDescriptor>;
317
- deleteResource(id: ResourceUri): Promise<void>;
314
+ getResource(id: ResourceId): Promise<ResourceDescriptor | null>;
315
+ updateResource(id: ResourceId, input: UpdateResourceInput): Promise<ResourceDescriptor>;
316
+ deleteResource(id: ResourceId): Promise<void>;
318
317
  listResources(filter: ResourceFilter): Promise<{
319
318
  resources: ResourceDescriptor[];
320
319
  total: number;
321
320
  }>;
322
321
  searchResources(query: string, limit?: number): Promise<ResourceDescriptor[]>;
323
322
  createAnnotation(input: CreateAnnotationInternal): Promise<Annotation>;
324
- getAnnotation(id: AnnotationUri): Promise<Annotation | null>;
325
- updateAnnotation(id: AnnotationUri, updates: Partial<Annotation>): Promise<Annotation>;
326
- deleteAnnotation(id: AnnotationUri): Promise<void>;
323
+ getAnnotation(id: AnnotationId): Promise<Annotation | null>;
324
+ updateAnnotation(id: AnnotationId, updates: Partial<Annotation>): Promise<Annotation>;
325
+ deleteAnnotation(id: AnnotationId): Promise<void>;
327
326
  listAnnotations(filter: {
328
327
  resourceId?: ResourceId;
329
328
  type?: AnnotationCategory;
@@ -336,7 +335,7 @@ declare class MemoryGraphDatabase implements GraphDatabase {
336
335
  getReferences(resourceId: ResourceId): Promise<Annotation[]>;
337
336
  getEntityReferences(resourceId: ResourceId, entityTypes?: string[]): Promise<Annotation[]>;
338
337
  getResourceAnnotations(resourceId: ResourceId): Promise<Annotation[]>;
339
- getResourceReferencedBy(resourceUri: ResourceUri, _motivation?: string): Promise<Annotation[]>;
338
+ getResourceReferencedBy(resourceId: ResourceId, _motivation?: string): Promise<Annotation[]>;
340
339
  getResourceConnections(resourceId: ResourceId): Promise<GraphConnection[]>;
341
340
  findPath(fromResourceId: string, toResourceId: string, maxDepth?: number): Promise<GraphPath[]>;
342
341
  getEntityTypeStats(): Promise<EntityTypeStats[]>;
package/dist/index.js CHANGED
@@ -524,9 +524,9 @@ var NeptuneGraphDatabase = class {
524
524
  throw error;
525
525
  }
526
526
  }
527
- async getResourceReferencedBy(resourceUri3, _motivation) {
527
+ async getResourceReferencedBy(resourceId, _motivation) {
528
528
  try {
529
- const results = await this.g.V().hasLabel("Annotation").has("resolvedResourceId", resourceUri3).elementMap().toList();
529
+ const results = await this.g.V().hasLabel("Annotation").has("resolvedResourceId", resourceId).elementMap().toList();
530
530
  return await this.fetchAnnotationsWithEntityTypes(results);
531
531
  } catch (error) {
532
532
  this.logger?.error("Failed to get resource referenced by from Neptune", { error });
@@ -1383,16 +1383,16 @@ var Neo4jGraphDatabase = class {
1383
1383
  await session.close();
1384
1384
  }
1385
1385
  }
1386
- async getResourceReferencedBy(resourceUri3, motivation) {
1386
+ async getResourceReferencedBy(resourceId, motivation) {
1387
1387
  const session = this.getSession();
1388
1388
  try {
1389
- this.logger?.debug("Searching for annotations referencing resource", { resourceUri: resourceUri3, motivation });
1389
+ this.logger?.debug("Searching for annotations referencing resource", { resourceId, motivation });
1390
1390
  const motivationLabel = motivation ? `:${motivationToLabel(motivation)}` : "";
1391
- const cypher = `MATCH (a:Annotation${motivationLabel})-[:REFERENCES]->(d:Resource {id: $resourceUri})
1391
+ const cypher = `MATCH (a:Annotation${motivationLabel})-[:REFERENCES]->(d:Resource {id: $resourceId})
1392
1392
  OPTIONAL MATCH (a)-[:TAGGED_AS]->(et:EntityType)
1393
1393
  RETURN a, collect(et.name) as entityTypes
1394
1394
  ORDER BY a.created DESC`;
1395
- const result = await session.run(cypher, { resourceUri: resourceUri3 });
1395
+ const result = await session.run(cypher, { resourceId });
1396
1396
  this.logger?.debug("Found annotations", { count: result.records.length });
1397
1397
  return result.records.map(
1398
1398
  (record) => this.parseAnnotationNode(record.get("a"), record.get("entityTypes"))
@@ -1776,7 +1776,7 @@ var Neo4jGraphDatabase = class {
1776
1776
 
1777
1777
  // src/implementations/janusgraph.ts
1778
1778
  import gremlin2 from "gremlin";
1779
- import { resourceUri, annotationIdToURI } from "@semiont/core";
1779
+ import { resourceId as makeResourceId } from "@semiont/core";
1780
1780
  import {
1781
1781
  getBodySource as getBodySource3,
1782
1782
  getPrimaryRepresentation as getPrimaryRepresentation3,
@@ -1788,9 +1788,8 @@ import { v4 as uuidv43 } from "uuid";
1788
1788
  var traversal = gremlin2.process.AnonymousTraversalSource.traversal;
1789
1789
  var DriverRemoteConnection = gremlin2.driver.DriverRemoteConnection;
1790
1790
  var JanusGraphDatabase = class {
1791
- constructor(graphConfig, envConfig) {
1791
+ constructor(graphConfig) {
1792
1792
  this.graphConfig = graphConfig;
1793
- this.envConfig = envConfig;
1794
1793
  this.logger = graphConfig.logger;
1795
1794
  }
1796
1795
  connected = false;
@@ -2120,10 +2119,9 @@ var JanusGraphDatabase = class {
2120
2119
  return annotations;
2121
2120
  }
2122
2121
  async resolveReference(annotationId, source) {
2123
- const publicURL = this.envConfig.services.backend.publicURL;
2124
- const annotation = await this.getAnnotation(annotationIdToURI(annotationId, publicURL));
2122
+ const annotation = await this.getAnnotation(annotationId);
2125
2123
  if (!annotation) throw new Error("Annotation not found");
2126
- await this.updateAnnotation(annotationIdToURI(annotationId, publicURL), {
2124
+ await this.updateAnnotation(annotationId, {
2127
2125
  body: [
2128
2126
  {
2129
2127
  type: "SpecificResource",
@@ -2133,7 +2131,7 @@ var JanusGraphDatabase = class {
2133
2131
  ]
2134
2132
  });
2135
2133
  await this.g.V().has("Annotation", "id", annotationId).addE("REFERENCES").to(this.g.V().has("Resource", "id", source)).next();
2136
- const updatedAnnotation = await this.getAnnotation(annotationIdToURI(annotationId, publicURL));
2134
+ const updatedAnnotation = await this.getAnnotation(annotationId);
2137
2135
  if (!updatedAnnotation) {
2138
2136
  throw new Error("Annotation not found after update");
2139
2137
  }
@@ -2163,8 +2161,8 @@ var JanusGraphDatabase = class {
2163
2161
  const { annotations } = await this.listAnnotations({ resourceId });
2164
2162
  return annotations;
2165
2163
  }
2166
- async getResourceReferencedBy(resourceUri3, _motivation) {
2167
- const vertices = await this.g.V().hasLabel("Annotation").has("source", resourceUri3).toList();
2164
+ async getResourceReferencedBy(resourceId, _motivation) {
2165
+ const vertices = await this.g.V().hasLabel("Annotation").has("source", resourceId).toList();
2168
2166
  return await this.fetchAnnotationsWithEntityTypes(vertices);
2169
2167
  }
2170
2168
  async getResourceConnections(resourceId) {
@@ -2175,7 +2173,7 @@ var JanusGraphDatabase = class {
2175
2173
  for (const ref of refs) {
2176
2174
  const bodySource = getBodySource3(ref.body);
2177
2175
  if (bodySource) {
2178
- const targetDoc = await this.getResource(resourceUri(bodySource));
2176
+ const targetDoc = await this.getResource(makeResourceId(bodySource));
2179
2177
  if (targetDoc) {
2180
2178
  const existing = connections.find((c) => c.targetResource.id === targetDoc.id);
2181
2179
  if (existing) {
@@ -2327,7 +2325,7 @@ var JanusGraphDatabase = class {
2327
2325
  };
2328
2326
 
2329
2327
  // src/implementations/memorygraph.ts
2330
- import { resourceId as makeResourceId, uriToResourceId, resourceUri as resourceUri2 } from "@semiont/core";
2328
+ import { resourceId as makeResourceId2 } from "@semiont/core";
2331
2329
  import { v4 as uuidv44 } from "uuid";
2332
2330
  import {
2333
2331
  getBodySource as getBodySource4,
@@ -2364,30 +2362,22 @@ var MemoryGraphDatabase = class {
2364
2362
  return resource;
2365
2363
  }
2366
2364
  async getResource(id) {
2367
- try {
2368
- const resourceId = uriToResourceId(id);
2369
- return this.resources.get(resourceId) || null;
2370
- } catch {
2371
- return null;
2372
- }
2365
+ return this.resources.get(String(id)) || null;
2373
2366
  }
2374
2367
  async updateResource(id, input) {
2375
2368
  if (Object.keys(input).length !== 1 || input.archived === void 0) {
2376
2369
  throw new Error("Resources are immutable. Only archiving is allowed.");
2377
2370
  }
2378
- const resourceId = uriToResourceId(id);
2379
- const doc = resourceId ? this.resources.get(resourceId) : null;
2371
+ const doc = this.resources.get(String(id));
2380
2372
  if (!doc) throw new Error("Resource not found");
2381
2373
  doc.archived = input.archived;
2382
2374
  return doc;
2383
2375
  }
2384
2376
  async deleteResource(id) {
2385
- const resourceId = uriToResourceId(id);
2386
- if (resourceId) {
2387
- this.resources.delete(resourceId);
2388
- }
2377
+ this.resources.delete(String(id));
2378
+ const idStr = String(id);
2389
2379
  for (const [selId, sel] of this.annotations) {
2390
- if (getTargetSource3(sel.target) === id || getBodySource4(sel.body) === id) {
2380
+ if (getTargetSource3(sel.target) === idStr || getBodySource4(sel.body) === idStr) {
2391
2381
  this.annotations.delete(selId);
2392
2382
  }
2393
2383
  }
@@ -2457,11 +2447,7 @@ var MemoryGraphDatabase = class {
2457
2447
  let results = Array.from(this.annotations.values());
2458
2448
  if (filter.resourceId) {
2459
2449
  const resourceIdStr = String(filter.resourceId);
2460
- results = results.filter((a) => {
2461
- const targetSource = getTargetSource3(a.target);
2462
- const targetResourceId = targetSource ? uriToResourceId(targetSource) : null;
2463
- return targetResourceId === resourceIdStr;
2464
- });
2450
+ results = results.filter((a) => getTargetSource3(a.target) === resourceIdStr);
2465
2451
  }
2466
2452
  if (filter.type) {
2467
2453
  const motivation = filter.type === "highlight" ? "highlighting" : "linking";
@@ -2471,24 +2457,18 @@ var MemoryGraphDatabase = class {
2471
2457
  }
2472
2458
  async getHighlights(resourceId) {
2473
2459
  const resourceIdStr = String(resourceId);
2474
- const highlights = Array.from(this.annotations.values()).filter((sel) => {
2475
- const targetSource = getTargetSource3(sel.target);
2476
- const targetResourceId = targetSource ? uriToResourceId(targetSource) : null;
2477
- return targetResourceId === resourceIdStr && sel.motivation === "highlighting";
2478
- });
2460
+ const highlights = Array.from(this.annotations.values()).filter((sel) => getTargetSource3(sel.target) === resourceIdStr && sel.motivation === "highlighting");
2479
2461
  this.logger?.debug("Got highlights for resource", { resourceId, count: highlights.length });
2480
2462
  return highlights;
2481
2463
  }
2482
2464
  async resolveReference(annotationId, source) {
2483
2465
  const annotation = this.annotations.get(annotationId);
2484
2466
  if (!annotation) throw new Error("Annotation not found");
2485
- const sourceResource = this.resources.get(String(source));
2486
- if (!sourceResource) throw new Error("Source resource not found");
2487
2467
  const updated = {
2488
2468
  ...annotation,
2489
2469
  body: {
2490
2470
  type: "SpecificResource",
2491
- source: sourceResource["@id"],
2471
+ source: String(source),
2492
2472
  purpose: "linking"
2493
2473
  }
2494
2474
  };
@@ -2497,22 +2477,16 @@ var MemoryGraphDatabase = class {
2497
2477
  }
2498
2478
  async getReferences(resourceId) {
2499
2479
  const resourceIdStr = String(resourceId);
2500
- const references = Array.from(this.annotations.values()).filter((sel) => {
2501
- const targetSource = getTargetSource3(sel.target);
2502
- const targetResourceId = targetSource ? uriToResourceId(targetSource) : null;
2503
- return targetResourceId === resourceIdStr && sel.motivation === "linking";
2504
- });
2480
+ const references = Array.from(this.annotations.values()).filter((sel) => getTargetSource3(sel.target) === resourceIdStr && sel.motivation === "linking");
2505
2481
  this.logger?.debug("Got references for resource", { resourceId, count: references.length });
2506
2482
  return references;
2507
2483
  }
2508
2484
  async getEntityReferences(resourceId, entityTypes) {
2509
2485
  const resourceIdStr = String(resourceId);
2510
2486
  let refs = Array.from(this.annotations.values()).filter((sel) => {
2511
- const targetSource = getTargetSource3(sel.target);
2512
- const targetResourceId = targetSource ? uriToResourceId(targetSource) : null;
2487
+ if (getTargetSource3(sel.target) !== resourceIdStr) return false;
2513
2488
  const bodyEntityTypes = sel.body?.entityTypes;
2514
- const hasEntityTypes = Array.isArray(bodyEntityTypes) && bodyEntityTypes.length > 0;
2515
- return targetResourceId === resourceIdStr && hasEntityTypes;
2489
+ return Array.isArray(bodyEntityTypes) && bodyEntityTypes.length > 0;
2516
2490
  });
2517
2491
  if (entityTypes && entityTypes.length > 0) {
2518
2492
  refs = refs.filter((sel) => {
@@ -2524,62 +2498,48 @@ var MemoryGraphDatabase = class {
2524
2498
  }
2525
2499
  async getResourceAnnotations(resourceId) {
2526
2500
  const resourceIdStr = String(resourceId);
2527
- return Array.from(this.annotations.values()).filter((sel) => {
2528
- const targetSource = getTargetSource3(sel.target);
2529
- const targetResourceId = targetSource ? uriToResourceId(targetSource) : null;
2530
- return targetResourceId === resourceIdStr;
2531
- });
2501
+ return Array.from(this.annotations.values()).filter((sel) => getTargetSource3(sel.target) === resourceIdStr);
2532
2502
  }
2533
- async getResourceReferencedBy(resourceUri3, _motivation) {
2534
- return Array.from(this.annotations.values()).filter((sel) => getBodySource4(sel.body) === resourceUri3);
2503
+ async getResourceReferencedBy(resourceId, _motivation) {
2504
+ return Array.from(this.annotations.values()).filter((sel) => getBodySource4(sel.body) === String(resourceId));
2535
2505
  }
2536
2506
  async getResourceConnections(resourceId) {
2537
2507
  const connections = [];
2538
2508
  const refs = await this.getReferences(resourceId);
2509
+ const resourceIdStr = String(resourceId);
2539
2510
  for (const ref of refs) {
2540
2511
  const bodySource = getBodySource4(ref.body);
2541
2512
  if (bodySource) {
2542
- const targetDoc = await this.getResource(resourceUri2(bodySource));
2513
+ const targetDoc = await this.getResource(makeResourceId2(bodySource));
2543
2514
  if (targetDoc) {
2544
- const bodySourceId = uriToResourceId(bodySource);
2545
- if (bodySourceId) {
2546
- const reverseRefs = await this.getReferences(makeResourceId(bodySourceId));
2547
- const resourceIdStr = String(resourceId);
2548
- const bidirectional = reverseRefs.some((r) => {
2549
- const reverseBodySource = getBodySource4(r.body);
2550
- const reverseBodyResourceId = reverseBodySource ? uriToResourceId(reverseBodySource) : null;
2551
- return reverseBodyResourceId === resourceIdStr;
2552
- });
2553
- connections.push({
2554
- targetResource: targetDoc,
2555
- annotations: [ref],
2556
- bidirectional
2557
- });
2558
- }
2515
+ const reverseRefs = await this.getReferences(makeResourceId2(bodySource));
2516
+ const bidirectional = reverseRefs.some((r) => getBodySource4(r.body) === resourceIdStr);
2517
+ connections.push({
2518
+ targetResource: targetDoc,
2519
+ annotations: [ref],
2520
+ bidirectional
2521
+ });
2559
2522
  }
2560
2523
  }
2561
2524
  }
2562
2525
  return connections;
2563
2526
  }
2564
2527
  async findPath(fromResourceId, toResourceId, maxDepth = 5) {
2565
- const fromUuid = uriToResourceId(fromResourceId);
2566
- const toUuid = uriToResourceId(toResourceId);
2567
- if (!fromUuid || !toUuid) return [];
2568
2528
  const visited = /* @__PURE__ */ new Set();
2569
2529
  const queue = [];
2570
- const fromDoc = await this.getResource(resourceUri2(fromResourceId));
2530
+ const fromDoc = await this.getResource(makeResourceId2(fromResourceId));
2571
2531
  if (!fromDoc) return [];
2572
- queue.push({ docId: fromUuid, path: [fromDoc], sels: [] });
2573
- visited.add(fromUuid);
2532
+ queue.push({ docId: fromResourceId, path: [fromDoc], sels: [] });
2533
+ visited.add(fromResourceId);
2574
2534
  const paths = [];
2575
2535
  while (queue.length > 0 && paths.length < 10) {
2576
2536
  const { docId, path, sels } = queue.shift();
2577
2537
  if (path.length > maxDepth) continue;
2578
- if (docId === toUuid) {
2538
+ if (docId === toResourceId) {
2579
2539
  paths.push({ resources: path, annotations: sels });
2580
2540
  continue;
2581
2541
  }
2582
- const connections = await this.getResourceConnections(makeResourceId(docId));
2542
+ const connections = await this.getResourceConnections(makeResourceId2(docId));
2583
2543
  for (const conn of connections) {
2584
2544
  const targetId = getResourceId3(conn.targetResource);
2585
2545
  if (targetId && !visited.has(targetId)) {
@@ -2698,7 +2658,7 @@ var MemoryGraphDatabase = class {
2698
2658
 
2699
2659
  // src/factory.ts
2700
2660
  var graphDatabaseInstance = null;
2701
- function createGraphDatabase(config, envConfig) {
2661
+ function createGraphDatabase(config) {
2702
2662
  switch (config.type) {
2703
2663
  case "neptune": {
2704
2664
  const neptuneConfig = {};
@@ -2721,7 +2681,7 @@ function createGraphDatabase(config, envConfig) {
2721
2681
  if (config.janusPort !== void 0) janusConfig.port = config.janusPort;
2722
2682
  if (config.janusStorageBackend !== void 0) janusConfig.storageBackend = config.janusStorageBackend;
2723
2683
  if (config.janusIndexBackend !== void 0) janusConfig.indexBackend = config.janusIndexBackend;
2724
- return new JanusGraphDatabase(janusConfig, envConfig);
2684
+ return new JanusGraphDatabase(janusConfig);
2725
2685
  }
2726
2686
  case "memory":
2727
2687
  return new MemoryGraphDatabase({});
@@ -2739,9 +2699,8 @@ function evaluateEnvVar(value) {
2739
2699
  return envValue;
2740
2700
  });
2741
2701
  }
2742
- async function getGraphDatabase(envConfig) {
2702
+ async function getGraphDatabase(graphConfig) {
2743
2703
  if (!graphDatabaseInstance) {
2744
- const graphConfig = envConfig.services.graph;
2745
2704
  const config = {
2746
2705
  type: graphConfig.type
2747
2706
  };
@@ -2782,7 +2741,7 @@ async function getGraphDatabase(envConfig) {
2782
2741
  config.neo4jDatabase = evaluateEnvVar(graphConfig.database);
2783
2742
  }
2784
2743
  }
2785
- graphDatabaseInstance = createGraphDatabase(config, envConfig);
2744
+ graphDatabaseInstance = createGraphDatabase(config);
2786
2745
  await graphDatabaseInstance.connect();
2787
2746
  }
2788
2747
  if (!graphDatabaseInstance.isConnected()) {