@arke-institute/sdk 0.1.1 → 0.1.3

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.
Files changed (41) hide show
  1. package/dist/content/index.cjs +591 -0
  2. package/dist/content/index.cjs.map +1 -0
  3. package/dist/content/index.d.cts +516 -0
  4. package/dist/content/index.d.ts +516 -0
  5. package/dist/content/index.js +558 -0
  6. package/dist/content/index.js.map +1 -0
  7. package/dist/edit/index.cjs +1503 -0
  8. package/dist/edit/index.cjs.map +1 -0
  9. package/dist/edit/index.d.cts +78 -0
  10. package/dist/edit/index.d.ts +78 -0
  11. package/dist/edit/index.js +1447 -0
  12. package/dist/edit/index.js.map +1 -0
  13. package/dist/{errors-BrNZWPE7.d.cts → errors-3L7IiHcr.d.cts} +3 -0
  14. package/dist/{errors-CCyp5KCg.d.ts → errors-BTe8GKRQ.d.ts} +3 -0
  15. package/dist/errors-CT7yzKkU.d.cts +874 -0
  16. package/dist/errors-CT7yzKkU.d.ts +874 -0
  17. package/dist/graph/index.cjs +427 -0
  18. package/dist/graph/index.cjs.map +1 -0
  19. package/dist/graph/index.d.cts +485 -0
  20. package/dist/graph/index.d.ts +485 -0
  21. package/dist/graph/index.js +396 -0
  22. package/dist/graph/index.js.map +1 -0
  23. package/dist/index.cjs +2726 -14
  24. package/dist/index.cjs.map +1 -1
  25. package/dist/index.d.cts +5 -1
  26. package/dist/index.d.ts +5 -1
  27. package/dist/index.js +2708 -14
  28. package/dist/index.js.map +1 -1
  29. package/dist/query/index.cjs +356 -0
  30. package/dist/query/index.cjs.map +1 -0
  31. package/dist/query/index.d.cts +636 -0
  32. package/dist/query/index.d.ts +636 -0
  33. package/dist/query/index.js +328 -0
  34. package/dist/query/index.js.map +1 -0
  35. package/dist/upload/index.cjs +3 -14
  36. package/dist/upload/index.cjs.map +1 -1
  37. package/dist/upload/index.d.cts +2 -2
  38. package/dist/upload/index.d.ts +2 -2
  39. package/dist/upload/index.js +3 -14
  40. package/dist/upload/index.js.map +1 -1
  41. package/package.json +26 -1
@@ -0,0 +1,485 @@
1
+ /**
2
+ * Graph package types for the Arke SDK
3
+ *
4
+ * Types for interacting with the GraphDB Gateway service.
5
+ *
6
+ * The GraphDB is an indexed mirror of entity data stored in IPFS. Entity IDs
7
+ * are consistent across both systems - the same ID works in ContentClient
8
+ * (IPFS source of truth) and GraphClient (indexed mirror).
9
+ *
10
+ * Key distinction:
11
+ * - IPFS stores only OUTBOUND relationships (in relationships.json)
12
+ * - GraphDB indexes BOTH inbound AND outbound relationships for fast bidirectional queries
13
+ */
14
+ /**
15
+ * Direction filter for relationship queries
16
+ *
17
+ * - 'outgoing': Relationships where this entity is the source
18
+ * - 'incoming': Relationships where this entity is the target (only available via GraphDB)
19
+ * - 'both': All relationships in both directions
20
+ */
21
+ type RelationshipDirection = 'outgoing' | 'incoming' | 'both';
22
+ /**
23
+ * Entity from the knowledge graph (as indexed in GraphDB)
24
+ */
25
+ interface GraphEntity {
26
+ /** Unique identifier (consistent with IPFS entity IDs) */
27
+ canonical_id: string;
28
+ /** Entity code (e.g., 'person_john', 'event_123') */
29
+ code: string;
30
+ /** Human-readable label */
31
+ label: string;
32
+ /** Entity type (e.g., 'person', 'event', 'date', 'organization') */
33
+ type: string;
34
+ /** Additional entity properties */
35
+ properties?: Record<string, unknown>;
36
+ /** PI that created this entity */
37
+ created_by_pi?: string;
38
+ /** All PIs that contributed to this entity */
39
+ source_pis?: string[];
40
+ }
41
+ /**
42
+ * Relationship between entities
43
+ */
44
+ interface Relationship {
45
+ /** Direction of the relationship relative to the queried entity */
46
+ direction: 'outgoing' | 'incoming';
47
+ /** Relationship type/predicate (e.g., 'affiliated_with', 'authored', 'located_at') */
48
+ predicate: string;
49
+ /** Canonical ID of the related entity */
50
+ target_id: string;
51
+ /** Code of the related entity */
52
+ target_code: string;
53
+ /** Label of the related entity */
54
+ target_label: string;
55
+ /** Type of the related entity */
56
+ target_type: string;
57
+ /** Additional relationship properties */
58
+ properties?: Record<string, unknown>;
59
+ /** PI that created this relationship */
60
+ source_pi?: string;
61
+ /** When the relationship was created */
62
+ created_at?: string;
63
+ }
64
+ /**
65
+ * Entity with its relationships
66
+ */
67
+ interface EntityWithRelationships extends GraphEntity {
68
+ /** All relationships for this entity */
69
+ relationships: Relationship[];
70
+ }
71
+ /**
72
+ * An edge in a path between entities
73
+ */
74
+ interface PathEdge {
75
+ /** Subject entity ID */
76
+ subject_id: string;
77
+ /** Subject entity label */
78
+ subject_label: string;
79
+ /** Subject entity type */
80
+ subject_type: string;
81
+ /** Relationship predicate */
82
+ predicate: string;
83
+ /** Object entity ID */
84
+ object_id: string;
85
+ /** Object entity label */
86
+ object_label: string;
87
+ /** Object entity type */
88
+ object_type: string;
89
+ /** PI that contributed this edge */
90
+ source_pi?: string;
91
+ }
92
+ /**
93
+ * A path between two entities
94
+ */
95
+ interface Path {
96
+ /** Starting entity ID */
97
+ source_id: string;
98
+ /** Ending entity ID */
99
+ target_id: string;
100
+ /** Number of hops in the path */
101
+ length: number;
102
+ /** Edges in the path */
103
+ edges: PathEdge[];
104
+ }
105
+ /**
106
+ * Options for finding paths between entities
107
+ */
108
+ interface PathOptions {
109
+ /** Maximum traversal depth (default: 3) */
110
+ max_depth?: number;
111
+ /** Direction of traversal */
112
+ direction?: 'outgoing' | 'incoming' | 'both';
113
+ /** Maximum number of paths to return */
114
+ limit?: number;
115
+ }
116
+ /**
117
+ * Options for finding reachable entities
118
+ */
119
+ interface ReachableOptions {
120
+ /** Maximum traversal depth */
121
+ max_depth?: number;
122
+ /** Direction of traversal */
123
+ direction?: 'outgoing' | 'incoming' | 'both';
124
+ /** Maximum entities to return */
125
+ limit?: number;
126
+ }
127
+ /**
128
+ * Options for listing entities from a PI
129
+ */
130
+ interface ListFromPiOptions {
131
+ /** Filter by entity type */
132
+ type?: string;
133
+ }
134
+ /**
135
+ * Response from entity query by code
136
+ */
137
+ interface EntityQueryResponse {
138
+ /** Whether entity was found */
139
+ found: boolean;
140
+ /** The entity (if found) */
141
+ entity?: GraphEntity;
142
+ /** Relationships (if found) */
143
+ relationships?: {
144
+ outgoing: Array<{
145
+ predicate: string;
146
+ target_id: string;
147
+ target_label: string;
148
+ target_type: string;
149
+ }>;
150
+ incoming: Array<{
151
+ predicate: string;
152
+ source_id: string;
153
+ source_label: string;
154
+ source_type: string;
155
+ }>;
156
+ };
157
+ }
158
+ /**
159
+ * Response from entities with relationships query
160
+ */
161
+ interface EntitiesWithRelationshipsResponse {
162
+ /** PI that was queried */
163
+ pi: string;
164
+ /** Entities with their relationships */
165
+ entities: EntityWithRelationships[];
166
+ /** Total count of entities */
167
+ total_count: number;
168
+ }
169
+ /**
170
+ * Response from path finding
171
+ */
172
+ interface PathsResponse {
173
+ /** Found paths */
174
+ paths: Path[];
175
+ /** Whether results were truncated */
176
+ truncated: boolean;
177
+ }
178
+ /**
179
+ * Lineage PI entry
180
+ */
181
+ interface LineagePiEntry {
182
+ /** PI ID */
183
+ id: string;
184
+ /** Number of hops from source */
185
+ hops: number;
186
+ /** When the PI was created */
187
+ created_at?: string;
188
+ }
189
+ /**
190
+ * Lineage result set (ancestors or descendants)
191
+ */
192
+ interface LineageResultSet {
193
+ /** List of PIs */
194
+ pis: LineagePiEntry[];
195
+ /** Total count */
196
+ count: number;
197
+ /** Whether results were truncated */
198
+ truncated: boolean;
199
+ }
200
+ /**
201
+ * Response from lineage query
202
+ */
203
+ interface LineageResponse {
204
+ /** Source PI */
205
+ sourcePi: string;
206
+ /** Ancestor PIs (if requested) */
207
+ ancestors?: LineageResultSet;
208
+ /** Descendant PIs (if requested) */
209
+ descendants?: LineageResultSet;
210
+ }
211
+
212
+ /**
213
+ * Configuration for GraphClient
214
+ */
215
+ interface GraphClientConfig {
216
+ /**
217
+ * Gateway base URL (e.g., https://gateway.arke.institute).
218
+ * The client will call /graphdb/* endpoints for GraphDB Gateway.
219
+ */
220
+ gatewayUrl: string;
221
+ /**
222
+ * Optional custom fetch implementation (useful for testing).
223
+ */
224
+ fetchImpl?: typeof fetch;
225
+ }
226
+ /**
227
+ * Client for querying entity relationships and graph traversal from the Arke knowledge graph.
228
+ *
229
+ * The GraphDB is an indexed mirror of entity data stored in IPFS. Use this client for:
230
+ * - **Bidirectional relationship queries** (IPFS only stores outbound relationships)
231
+ * - **Path finding** between entities
232
+ * - **Lineage queries** (PI ancestors/descendants)
233
+ * - **Code-based lookups** (indexed for fast search)
234
+ * - **Listing extracted entities** from a PI
235
+ *
236
+ * For entity CRUD operations, use ContentClient (source of truth in IPFS).
237
+ * For write operations, use EditClient.
238
+ *
239
+ * All endpoints are public and do not require authentication.
240
+ *
241
+ * @example
242
+ * ```typescript
243
+ * const graph = new GraphClient({
244
+ * gatewayUrl: 'https://gateway.arke.institute',
245
+ * });
246
+ *
247
+ * // Get BOTH inbound and outbound relationships (GraphDB indexed)
248
+ * const allRels = await graph.getRelationships('01K75HQQXNTDG7BBP7PS9AWYAN');
249
+ *
250
+ * // Get only inbound relationships ("who references this entity?")
251
+ * const incoming = await graph.getRelationships('01K75HQQXNTDG7BBP7PS9AWYAN', 'incoming');
252
+ *
253
+ * // Find paths between entities
254
+ * const paths = await graph.findPaths(['entity-1'], ['entity-2'], { max_depth: 4 });
255
+ *
256
+ * // Get PI lineage
257
+ * const lineage = await graph.getLineage('01K75HQQXNTDG7BBP7PS9AWYAN', 'ancestors');
258
+ * ```
259
+ */
260
+ declare class GraphClient {
261
+ private baseUrl;
262
+ private fetchImpl;
263
+ constructor(config: GraphClientConfig);
264
+ private buildUrl;
265
+ private request;
266
+ /**
267
+ * Query entities by code with optional type filter.
268
+ *
269
+ * @param code - Entity code to search for
270
+ * @param type - Optional entity type filter
271
+ * @returns Matching entities
272
+ *
273
+ * @example
274
+ * ```typescript
275
+ * // Find by code
276
+ * const entities = await graph.queryByCode('person_john');
277
+ *
278
+ * // With type filter
279
+ * const people = await graph.queryByCode('john', 'person');
280
+ * ```
281
+ */
282
+ queryByCode(code: string, type?: string): Promise<GraphEntity[]>;
283
+ /**
284
+ * Look up entities by code across all PIs.
285
+ *
286
+ * @param code - Entity code to search for
287
+ * @param type - Optional entity type filter
288
+ * @returns Matching entities
289
+ *
290
+ * @example
291
+ * ```typescript
292
+ * const entities = await graph.lookupByCode('alice_austen', 'person');
293
+ * ```
294
+ */
295
+ lookupByCode(code: string, type?: string): Promise<GraphEntity[]>;
296
+ /**
297
+ * List entities extracted from a specific PI or multiple PIs.
298
+ *
299
+ * This returns knowledge graph entities (persons, places, events, etc.)
300
+ * that were extracted from the given PI(s), not the PI entity itself.
301
+ *
302
+ * @param pi - Single PI or array of PIs
303
+ * @param options - Filter options
304
+ * @returns Extracted entities from the PI(s)
305
+ *
306
+ * @example
307
+ * ```typescript
308
+ * // From single PI
309
+ * const entities = await graph.listEntitiesFromPi('01K75HQQXNTDG7BBP7PS9AWYAN');
310
+ *
311
+ * // With type filter
312
+ * const people = await graph.listEntitiesFromPi('01K75HQQXNTDG7BBP7PS9AWYAN', { type: 'person' });
313
+ *
314
+ * // From multiple PIs
315
+ * const all = await graph.listEntitiesFromPi(['pi-1', 'pi-2']);
316
+ * ```
317
+ */
318
+ listEntitiesFromPi(pi: string | string[], options?: ListFromPiOptions): Promise<GraphEntity[]>;
319
+ /**
320
+ * Get entities with their relationships from a PI.
321
+ *
322
+ * This is an optimized query that returns entities along with all their
323
+ * relationship data in a single request.
324
+ *
325
+ * @param pi - Persistent Identifier
326
+ * @param type - Optional entity type filter
327
+ * @returns Entities with relationships
328
+ *
329
+ * @example
330
+ * ```typescript
331
+ * const entities = await graph.getEntitiesWithRelationships('01K75HQQXNTDG7BBP7PS9AWYAN');
332
+ * entities.forEach(e => {
333
+ * console.log(`${e.label} has ${e.relationships.length} relationships`);
334
+ * });
335
+ * ```
336
+ */
337
+ getEntitiesWithRelationships(pi: string, type?: string): Promise<EntityWithRelationships[]>;
338
+ /**
339
+ * Get the lineage (ancestors and/or descendants) of a PI.
340
+ *
341
+ * This traverses the PI hierarchy (parent_pi/children_pi relationships)
342
+ * which is indexed in GraphDB for fast lookups.
343
+ *
344
+ * @param pi - Source PI
345
+ * @param direction - 'ancestors', 'descendants', or 'both'
346
+ * @param maxHops - Maximum depth to traverse (default: 10)
347
+ * @returns Lineage data with PIs at each hop level
348
+ *
349
+ * @example
350
+ * ```typescript
351
+ * // Get ancestors (parent chain)
352
+ * const lineage = await graph.getLineage('01K75HQQXNTDG7BBP7PS9AWYAN', 'ancestors');
353
+ *
354
+ * // Get both directions
355
+ * const full = await graph.getLineage('01K75HQQXNTDG7BBP7PS9AWYAN', 'both');
356
+ * ```
357
+ */
358
+ getLineage(pi: string, direction?: 'ancestors' | 'descendants' | 'both', maxHops?: number): Promise<LineageResponse>;
359
+ /**
360
+ * Get relationships for an entity from the GraphDB index.
361
+ *
362
+ * **Important distinction from ContentClient.getRelationships():**
363
+ * - **ContentClient.getRelationships()**: Returns OUTBOUND relationships only
364
+ * (from the entity's relationships.json in IPFS - source of truth)
365
+ * - **GraphClient.getRelationships()**: Returns BOTH inbound AND outbound
366
+ * relationships (from the indexed GraphDB mirror)
367
+ *
368
+ * Use this method when you need to find "what references this entity" (inbound)
369
+ * or want a complete bidirectional view.
370
+ *
371
+ * @param id - Entity identifier (works for both PIs and KG entities)
372
+ * @param direction - Filter by direction: 'outgoing', 'incoming', or 'both' (default)
373
+ * @returns Array of relationships with direction indicator
374
+ *
375
+ * @example
376
+ * ```typescript
377
+ * // Get all relationships (both directions)
378
+ * const all = await graph.getRelationships('01K75HQQXNTDG7BBP7PS9AWYAN');
379
+ *
380
+ * // Get only inbound relationships ("who references this entity?")
381
+ * const incoming = await graph.getRelationships('01K75HQQXNTDG7BBP7PS9AWYAN', 'incoming');
382
+ *
383
+ * // Get only outbound relationships (similar to IPFS, but from index)
384
+ * const outgoing = await graph.getRelationships('01K75HQQXNTDG7BBP7PS9AWYAN', 'outgoing');
385
+ *
386
+ * // Process by direction
387
+ * const rels = await graph.getRelationships('entity-id');
388
+ * rels.forEach(r => {
389
+ * if (r.direction === 'incoming') {
390
+ * console.log(`${r.target_label} references this entity via ${r.predicate}`);
391
+ * } else {
392
+ * console.log(`This entity ${r.predicate} -> ${r.target_label}`);
393
+ * }
394
+ * });
395
+ * ```
396
+ */
397
+ getRelationships(id: string, direction?: RelationshipDirection): Promise<Relationship[]>;
398
+ /**
399
+ * Find shortest paths between sets of entities.
400
+ *
401
+ * @param sourceIds - Starting entity IDs
402
+ * @param targetIds - Target entity IDs
403
+ * @param options - Path finding options
404
+ * @returns Found paths
405
+ *
406
+ * @example
407
+ * ```typescript
408
+ * const paths = await graph.findPaths(
409
+ * ['entity-alice'],
410
+ * ['entity-bob'],
411
+ * { max_depth: 4, direction: 'both' }
412
+ * );
413
+ *
414
+ * paths.forEach(path => {
415
+ * console.log(`Path of length ${path.length}:`);
416
+ * path.edges.forEach(e => {
417
+ * console.log(` ${e.subject_label} -[${e.predicate}]-> ${e.object_label}`);
418
+ * });
419
+ * });
420
+ * ```
421
+ */
422
+ findPaths(sourceIds: string[], targetIds: string[], options?: PathOptions): Promise<Path[]>;
423
+ /**
424
+ * Find entities of a specific type reachable from starting entities.
425
+ *
426
+ * @param startIds - Starting entity IDs
427
+ * @param targetType - Type of entities to find
428
+ * @param options - Search options
429
+ * @returns Reachable entities of the specified type
430
+ *
431
+ * @example
432
+ * ```typescript
433
+ * // Find all people reachable from an event
434
+ * const people = await graph.findReachable(
435
+ * ['event-id'],
436
+ * 'person',
437
+ * { max_depth: 3 }
438
+ * );
439
+ * ```
440
+ */
441
+ findReachable(startIds: string[], targetType: string, options?: ReachableOptions): Promise<GraphEntity[]>;
442
+ /**
443
+ * Check the health of the graph service.
444
+ *
445
+ * @returns Health status
446
+ */
447
+ health(): Promise<{
448
+ status: string;
449
+ service: string;
450
+ version: string;
451
+ }>;
452
+ }
453
+
454
+ /**
455
+ * Graph package error classes for the Arke SDK
456
+ */
457
+ /**
458
+ * Base error class for graph operations
459
+ */
460
+ declare class GraphError extends Error {
461
+ code: string;
462
+ details?: unknown | undefined;
463
+ constructor(message: string, code?: string, details?: unknown | undefined);
464
+ }
465
+ /**
466
+ * Thrown when an entity is not found by canonical ID
467
+ */
468
+ declare class GraphEntityNotFoundError extends GraphError {
469
+ constructor(canonicalId: string);
470
+ }
471
+ /**
472
+ * Thrown when no paths are found between entities
473
+ */
474
+ declare class NoPathFoundError extends GraphError {
475
+ constructor(sourceIds: string[], targetIds: string[]);
476
+ }
477
+ /**
478
+ * Thrown when a network error occurs
479
+ */
480
+ declare class NetworkError extends GraphError {
481
+ statusCode?: number | undefined;
482
+ constructor(message: string, statusCode?: number | undefined);
483
+ }
484
+
485
+ export { type EntitiesWithRelationshipsResponse, type EntityQueryResponse, type EntityWithRelationships, GraphClient, type GraphClientConfig, type GraphEntity, GraphEntityNotFoundError, GraphError, type LineagePiEntry, type LineageResponse, type LineageResultSet, type ListFromPiOptions, NetworkError, NoPathFoundError, type Path, type PathEdge, type PathOptions, type PathsResponse, type ReachableOptions, type Relationship, type RelationshipDirection };