@arke-institute/sdk 0.1.0 → 0.1.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.
Files changed (53) hide show
  1. package/dist/{index.d.mts → client-dAk3E64p.d.cts} +1 -7
  2. package/dist/client-dAk3E64p.d.ts +183 -0
  3. package/dist/{index.mjs → collections/index.cjs} +34 -5
  4. package/dist/collections/index.cjs.map +1 -0
  5. package/dist/collections/index.d.cts +9 -0
  6. package/dist/collections/index.d.ts +9 -1
  7. package/dist/collections/index.js +5 -32
  8. package/dist/collections/index.js.map +1 -1
  9. package/dist/content/index.cjs +506 -0
  10. package/dist/content/index.cjs.map +1 -0
  11. package/dist/content/index.d.cts +403 -0
  12. package/dist/content/index.d.ts +403 -0
  13. package/dist/content/index.js +473 -0
  14. package/dist/content/index.js.map +1 -0
  15. package/dist/edit/index.cjs +1029 -0
  16. package/dist/edit/index.cjs.map +1 -0
  17. package/dist/edit/index.d.cts +78 -0
  18. package/dist/edit/index.d.ts +78 -0
  19. package/dist/edit/index.js +983 -0
  20. package/dist/edit/index.js.map +1 -0
  21. package/dist/errors-3L7IiHcr.d.cts +480 -0
  22. package/dist/errors-B82BMmRP.d.cts +343 -0
  23. package/dist/errors-B82BMmRP.d.ts +343 -0
  24. package/dist/errors-BTe8GKRQ.d.ts +480 -0
  25. package/dist/graph/index.cjs +433 -0
  26. package/dist/graph/index.cjs.map +1 -0
  27. package/dist/graph/index.d.cts +456 -0
  28. package/dist/graph/index.d.ts +456 -0
  29. package/dist/graph/index.js +402 -0
  30. package/dist/graph/index.js.map +1 -0
  31. package/dist/index.cjs +3761 -0
  32. package/dist/index.cjs.map +1 -0
  33. package/dist/index.d.cts +7 -0
  34. package/dist/index.d.ts +7 -189
  35. package/dist/index.js +3502 -30
  36. package/dist/index.js.map +1 -1
  37. package/dist/query/index.cjs +289 -0
  38. package/dist/query/index.cjs.map +1 -0
  39. package/dist/query/index.d.cts +541 -0
  40. package/dist/query/index.d.ts +541 -0
  41. package/dist/query/index.js +261 -0
  42. package/dist/query/index.js.map +1 -0
  43. package/dist/upload/index.cjs +1634 -0
  44. package/dist/upload/index.cjs.map +1 -0
  45. package/dist/upload/index.d.cts +150 -0
  46. package/dist/upload/index.d.ts +150 -0
  47. package/dist/upload/index.js +1597 -0
  48. package/dist/upload/index.js.map +1 -0
  49. package/package.json +43 -8
  50. package/dist/collections/index.d.mts +0 -1
  51. package/dist/collections/index.mjs +0 -204
  52. package/dist/collections/index.mjs.map +0 -1
  53. package/dist/index.mjs.map +0 -1
@@ -0,0 +1,402 @@
1
+ // src/graph/errors.ts
2
+ var GraphError = class extends Error {
3
+ constructor(message, code = "GRAPH_ERROR", details) {
4
+ super(message);
5
+ this.code = code;
6
+ this.details = details;
7
+ this.name = "GraphError";
8
+ }
9
+ };
10
+ var GraphEntityNotFoundError = class extends GraphError {
11
+ constructor(canonicalId) {
12
+ super(`Graph entity not found: ${canonicalId}`, "ENTITY_NOT_FOUND", { canonicalId });
13
+ this.name = "GraphEntityNotFoundError";
14
+ }
15
+ };
16
+ var NoPathFoundError = class extends GraphError {
17
+ constructor(sourceIds, targetIds) {
18
+ super(
19
+ `No path found between sources and targets`,
20
+ "NO_PATH_FOUND",
21
+ { sourceIds, targetIds }
22
+ );
23
+ this.name = "NoPathFoundError";
24
+ }
25
+ };
26
+ var NetworkError = class extends GraphError {
27
+ constructor(message, statusCode) {
28
+ super(message, "NETWORK_ERROR", { statusCode });
29
+ this.statusCode = statusCode;
30
+ this.name = "NetworkError";
31
+ }
32
+ };
33
+
34
+ // src/graph/client.ts
35
+ var GraphClient = class {
36
+ constructor(config) {
37
+ this.baseUrl = config.gatewayUrl.replace(/\/$/, "");
38
+ this.fetchImpl = config.fetchImpl ?? fetch;
39
+ }
40
+ // ---------------------------------------------------------------------------
41
+ // Request helpers
42
+ // ---------------------------------------------------------------------------
43
+ buildUrl(path, query) {
44
+ const url = new URL(`${this.baseUrl}${path}`);
45
+ if (query) {
46
+ Object.entries(query).forEach(([key, value]) => {
47
+ if (value !== void 0 && value !== null) {
48
+ url.searchParams.set(key, String(value));
49
+ }
50
+ });
51
+ }
52
+ return url.toString();
53
+ }
54
+ async request(path, options = {}) {
55
+ const url = this.buildUrl(path, options.query);
56
+ const headers = new Headers({ "Content-Type": "application/json" });
57
+ if (options.headers) {
58
+ Object.entries(options.headers).forEach(([k, v]) => {
59
+ if (v !== void 0) headers.set(k, v);
60
+ });
61
+ }
62
+ let response;
63
+ try {
64
+ response = await this.fetchImpl(url, { ...options, headers });
65
+ } catch (err) {
66
+ throw new NetworkError(
67
+ err instanceof Error ? err.message : "Network request failed"
68
+ );
69
+ }
70
+ if (response.ok) {
71
+ const contentType = response.headers.get("content-type") || "";
72
+ if (contentType.includes("application/json")) {
73
+ return await response.json();
74
+ }
75
+ return await response.text();
76
+ }
77
+ let body;
78
+ const text = await response.text();
79
+ try {
80
+ body = JSON.parse(text);
81
+ } catch {
82
+ body = text;
83
+ }
84
+ if (response.status === 404) {
85
+ throw new GraphError(
86
+ body?.message || "Not found",
87
+ "NOT_FOUND",
88
+ body
89
+ );
90
+ }
91
+ const message = body?.error && typeof body.error === "string" ? body.error : body?.message && typeof body.message === "string" ? body.message : `Request failed with status ${response.status}`;
92
+ throw new GraphError(message, "HTTP_ERROR", {
93
+ status: response.status,
94
+ body
95
+ });
96
+ }
97
+ // ---------------------------------------------------------------------------
98
+ // Entity Operations
99
+ // ---------------------------------------------------------------------------
100
+ /**
101
+ * Get an entity by its canonical ID.
102
+ *
103
+ * @param canonicalId - Entity UUID
104
+ * @returns Entity data
105
+ * @throws GraphEntityNotFoundError if the entity doesn't exist
106
+ *
107
+ * @example
108
+ * ```typescript
109
+ * const entity = await graph.getEntity('uuid-123');
110
+ * console.log('Entity:', entity.label, entity.type);
111
+ * ```
112
+ */
113
+ async getEntity(canonicalId) {
114
+ const response = await this.request(
115
+ `/graphdb/entity/${encodeURIComponent(canonicalId)}`
116
+ );
117
+ if (!response.found || !response.entity) {
118
+ throw new GraphEntityNotFoundError(canonicalId);
119
+ }
120
+ return response.entity;
121
+ }
122
+ /**
123
+ * Check if an entity exists by its canonical ID.
124
+ *
125
+ * @param canonicalId - Entity UUID
126
+ * @returns True if entity exists
127
+ *
128
+ * @example
129
+ * ```typescript
130
+ * if (await graph.entityExists('uuid-123')) {
131
+ * console.log('Entity exists');
132
+ * }
133
+ * ```
134
+ */
135
+ async entityExists(canonicalId) {
136
+ const response = await this.request(
137
+ `/graphdb/entity/exists/${encodeURIComponent(canonicalId)}`
138
+ );
139
+ return response.exists;
140
+ }
141
+ /**
142
+ * Query entities by code with optional type filter.
143
+ *
144
+ * @param code - Entity code to search for
145
+ * @param type - Optional entity type filter
146
+ * @returns Matching entities
147
+ *
148
+ * @example
149
+ * ```typescript
150
+ * // Find by code
151
+ * const entities = await graph.queryByCode('person_john');
152
+ *
153
+ * // With type filter
154
+ * const people = await graph.queryByCode('john', 'person');
155
+ * ```
156
+ */
157
+ async queryByCode(code, type) {
158
+ const response = await this.request(
159
+ "/graphdb/entity/query",
160
+ {
161
+ method: "POST",
162
+ body: JSON.stringify({ code, type })
163
+ }
164
+ );
165
+ if (!response.found || !response.entity) {
166
+ return [];
167
+ }
168
+ return [response.entity];
169
+ }
170
+ /**
171
+ * Look up entities by code across all PIs.
172
+ *
173
+ * @param code - Entity code to search for
174
+ * @param type - Optional entity type filter
175
+ * @returns Matching entities
176
+ *
177
+ * @example
178
+ * ```typescript
179
+ * const entities = await graph.lookupByCode('alice_austen', 'person');
180
+ * ```
181
+ */
182
+ async lookupByCode(code, type) {
183
+ const response = await this.request(
184
+ "/graphdb/entities/lookup-by-code",
185
+ {
186
+ method: "POST",
187
+ body: JSON.stringify({ code, type })
188
+ }
189
+ );
190
+ return response.entities || [];
191
+ }
192
+ // ---------------------------------------------------------------------------
193
+ // PI-based Operations
194
+ // ---------------------------------------------------------------------------
195
+ /**
196
+ * List entities from a specific PI or multiple PIs.
197
+ *
198
+ * @param pi - Single PI or array of PIs
199
+ * @param options - Filter options
200
+ * @returns Entities from the PI(s)
201
+ *
202
+ * @example
203
+ * ```typescript
204
+ * // From single PI
205
+ * const entities = await graph.listEntitiesFromPi('01K75HQQXNTDG7BBP7PS9AWYAN');
206
+ *
207
+ * // With type filter
208
+ * const people = await graph.listEntitiesFromPi('01K75HQQXNTDG7BBP7PS9AWYAN', { type: 'person' });
209
+ *
210
+ * // From multiple PIs
211
+ * const all = await graph.listEntitiesFromPi(['pi-1', 'pi-2']);
212
+ * ```
213
+ */
214
+ async listEntitiesFromPi(pi, options = {}) {
215
+ const pis = Array.isArray(pi) ? pi : [pi];
216
+ const response = await this.request(
217
+ "/graphdb/entities/list",
218
+ {
219
+ method: "POST",
220
+ body: JSON.stringify({
221
+ pis,
222
+ type: options.type
223
+ })
224
+ }
225
+ );
226
+ return response.entities || [];
227
+ }
228
+ /**
229
+ * Get entities with their relationships from a PI.
230
+ *
231
+ * This is an optimized query that returns entities along with all their
232
+ * relationship data in a single request.
233
+ *
234
+ * @param pi - Persistent Identifier
235
+ * @param type - Optional entity type filter
236
+ * @returns Entities with relationships
237
+ *
238
+ * @example
239
+ * ```typescript
240
+ * const entities = await graph.getEntitiesWithRelationships('01K75HQQXNTDG7BBP7PS9AWYAN');
241
+ * entities.forEach(e => {
242
+ * console.log(`${e.label} has ${e.relationships.length} relationships`);
243
+ * });
244
+ * ```
245
+ */
246
+ async getEntitiesWithRelationships(pi, type) {
247
+ const response = await this.request(
248
+ "/graphdb/pi/entities-with-relationships",
249
+ {
250
+ method: "POST",
251
+ body: JSON.stringify({ pi, type })
252
+ }
253
+ );
254
+ return response.entities || [];
255
+ }
256
+ /**
257
+ * Get the lineage (ancestors and/or descendants) of a PI.
258
+ *
259
+ * @param pi - Source PI
260
+ * @param direction - 'ancestors', 'descendants', or 'both'
261
+ * @returns Lineage data
262
+ *
263
+ * @example
264
+ * ```typescript
265
+ * // Get ancestors
266
+ * const lineage = await graph.getLineage('01K75HQQXNTDG7BBP7PS9AWYAN', 'ancestors');
267
+ *
268
+ * // Get both directions
269
+ * const full = await graph.getLineage('01K75HQQXNTDG7BBP7PS9AWYAN', 'both');
270
+ * ```
271
+ */
272
+ async getLineage(pi, direction = "both", maxHops = 10) {
273
+ return this.request("/graphdb/pi/lineage", {
274
+ method: "POST",
275
+ body: JSON.stringify({ sourcePi: pi, direction, maxHops })
276
+ });
277
+ }
278
+ // ---------------------------------------------------------------------------
279
+ // Relationship Operations
280
+ // ---------------------------------------------------------------------------
281
+ /**
282
+ * Get all relationships for an entity.
283
+ *
284
+ * @param canonicalId - Entity UUID
285
+ * @returns Array of relationships
286
+ *
287
+ * @example
288
+ * ```typescript
289
+ * const relationships = await graph.getRelationships('uuid-123');
290
+ * relationships.forEach(r => {
291
+ * console.log(`${r.direction}: ${r.predicate} -> ${r.target_label}`);
292
+ * });
293
+ * ```
294
+ */
295
+ async getRelationships(canonicalId) {
296
+ const response = await this.request(`/graphdb/relationships/${encodeURIComponent(canonicalId)}`);
297
+ if (!response.found || !response.relationships) {
298
+ return [];
299
+ }
300
+ return response.relationships.map((rel) => ({
301
+ direction: rel.direction,
302
+ predicate: rel.predicate,
303
+ target_id: rel.target_id,
304
+ target_code: rel.target_code || "",
305
+ target_label: rel.target_label,
306
+ target_type: rel.target_type,
307
+ properties: rel.properties,
308
+ source_pi: rel.source_pi,
309
+ created_at: rel.created_at
310
+ }));
311
+ }
312
+ // ---------------------------------------------------------------------------
313
+ // Path Finding
314
+ // ---------------------------------------------------------------------------
315
+ /**
316
+ * Find shortest paths between sets of entities.
317
+ *
318
+ * @param sourceIds - Starting entity IDs
319
+ * @param targetIds - Target entity IDs
320
+ * @param options - Path finding options
321
+ * @returns Found paths
322
+ *
323
+ * @example
324
+ * ```typescript
325
+ * const paths = await graph.findPaths(
326
+ * ['uuid-alice'],
327
+ * ['uuid-bob'],
328
+ * { max_depth: 4, direction: 'both' }
329
+ * );
330
+ *
331
+ * paths.forEach(path => {
332
+ * console.log(`Path of length ${path.length}:`);
333
+ * path.edges.forEach(e => {
334
+ * console.log(` ${e.subject_label} -[${e.predicate}]-> ${e.object_label}`);
335
+ * });
336
+ * });
337
+ * ```
338
+ */
339
+ async findPaths(sourceIds, targetIds, options = {}) {
340
+ const response = await this.request("/graphdb/paths/between", {
341
+ method: "POST",
342
+ body: JSON.stringify({
343
+ source_ids: sourceIds,
344
+ target_ids: targetIds,
345
+ max_depth: options.max_depth,
346
+ direction: options.direction,
347
+ limit: options.limit
348
+ })
349
+ });
350
+ return response.paths || [];
351
+ }
352
+ /**
353
+ * Find entities of a specific type reachable from starting entities.
354
+ *
355
+ * @param startIds - Starting entity IDs
356
+ * @param targetType - Type of entities to find
357
+ * @param options - Search options
358
+ * @returns Reachable entities of the specified type
359
+ *
360
+ * @example
361
+ * ```typescript
362
+ * // Find all people reachable from an event
363
+ * const people = await graph.findReachable(
364
+ * ['uuid-event'],
365
+ * 'person',
366
+ * { max_depth: 3 }
367
+ * );
368
+ * ```
369
+ */
370
+ async findReachable(startIds, targetType, options = {}) {
371
+ const response = await this.request(
372
+ "/graphdb/paths/reachable",
373
+ {
374
+ method: "POST",
375
+ body: JSON.stringify({
376
+ start_ids: startIds,
377
+ target_type: targetType,
378
+ max_depth: options.max_depth,
379
+ direction: options.direction,
380
+ limit: options.limit
381
+ })
382
+ }
383
+ );
384
+ return response.entities || [];
385
+ }
386
+ /**
387
+ * Check the health of the graph service.
388
+ *
389
+ * @returns Health status
390
+ */
391
+ async health() {
392
+ return this.request("/graphdb/health", { method: "GET" });
393
+ }
394
+ };
395
+ export {
396
+ GraphClient,
397
+ GraphEntityNotFoundError,
398
+ GraphError,
399
+ NetworkError,
400
+ NoPathFoundError
401
+ };
402
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/graph/errors.ts","../../src/graph/client.ts"],"sourcesContent":["/**\n * Graph package error classes for the Arke SDK\n */\n\n/**\n * Base error class for graph operations\n */\nexport class GraphError extends Error {\n constructor(\n message: string,\n public code: string = 'GRAPH_ERROR',\n public details?: unknown\n ) {\n super(message);\n this.name = 'GraphError';\n }\n}\n\n/**\n * Thrown when an entity is not found by canonical ID\n */\nexport class GraphEntityNotFoundError extends GraphError {\n constructor(canonicalId: string) {\n super(`Graph entity not found: ${canonicalId}`, 'ENTITY_NOT_FOUND', { canonicalId });\n this.name = 'GraphEntityNotFoundError';\n }\n}\n\n/**\n * Thrown when no paths are found between entities\n */\nexport class NoPathFoundError extends GraphError {\n constructor(sourceIds: string[], targetIds: string[]) {\n super(\n `No path found between sources and targets`,\n 'NO_PATH_FOUND',\n { sourceIds, targetIds }\n );\n this.name = 'NoPathFoundError';\n }\n}\n\n/**\n * Thrown when a network error occurs\n */\nexport class NetworkError extends GraphError {\n constructor(message: string, public statusCode?: number) {\n super(message, 'NETWORK_ERROR', { statusCode });\n this.name = 'NetworkError';\n }\n}\n","import {\n GraphError,\n GraphEntityNotFoundError,\n NetworkError,\n} from './errors.js';\nimport type {\n GraphEntity,\n EntityWithRelationships,\n Relationship,\n Path,\n PathOptions,\n ReachableOptions,\n ListFromPiOptions,\n EntityQueryResponse,\n EntitiesWithRelationshipsResponse,\n PathsResponse,\n LineageResponse,\n} from './types.js';\n\n/**\n * Configuration for GraphClient\n */\nexport interface GraphClientConfig {\n /**\n * Gateway base URL (e.g., https://gateway.arke.institute).\n * The client will call /graphdb/* endpoints for GraphDB Gateway.\n */\n gatewayUrl: string;\n /**\n * Optional custom fetch implementation (useful for testing).\n */\n fetchImpl?: typeof fetch;\n}\n\ntype JsonBody = Record<string, unknown>;\n\n/**\n * Client for querying entity relationships from the Arke knowledge graph.\n *\n * All endpoints are public and do not require authentication.\n *\n * @example\n * ```typescript\n * const graph = new GraphClient({\n * gatewayUrl: 'https://gateway.arke.institute',\n * });\n *\n * // Get entity by ID\n * const entity = await graph.getEntity('uuid-123');\n *\n * // Find entities by code\n * const results = await graph.queryByCode('person_john');\n *\n * // Get entities with relationships from a PI\n * const entities = await graph.getEntitiesWithRelationships('01K75HQQXNTDG7BBP7PS9AWYAN');\n *\n * // Find paths between entities\n * const paths = await graph.findPaths(['uuid-1'], ['uuid-2'], { max_depth: 4 });\n * ```\n */\nexport class GraphClient {\n private baseUrl: string;\n private fetchImpl: typeof fetch;\n\n constructor(config: GraphClientConfig) {\n this.baseUrl = config.gatewayUrl.replace(/\\/$/, '');\n this.fetchImpl = config.fetchImpl ?? fetch;\n }\n\n // ---------------------------------------------------------------------------\n // Request helpers\n // ---------------------------------------------------------------------------\n\n private buildUrl(path: string, query?: Record<string, string | number | boolean | undefined>) {\n const url = new URL(`${this.baseUrl}${path}`);\n if (query) {\n Object.entries(query).forEach(([key, value]) => {\n if (value !== undefined && value !== null) {\n url.searchParams.set(key, String(value));\n }\n });\n }\n return url.toString();\n }\n\n private async request<T>(\n path: string,\n options: RequestInit & {\n query?: Record<string, string | number | boolean | undefined>;\n } = {}\n ): Promise<T> {\n const url = this.buildUrl(path, options.query);\n const headers = new Headers({ 'Content-Type': 'application/json' });\n if (options.headers) {\n Object.entries(options.headers).forEach(([k, v]) => {\n if (v !== undefined) headers.set(k, v as string);\n });\n }\n\n let response: Response;\n try {\n response = await this.fetchImpl(url, { ...options, headers });\n } catch (err) {\n throw new NetworkError(\n err instanceof Error ? err.message : 'Network request failed'\n );\n }\n\n if (response.ok) {\n const contentType = response.headers.get('content-type') || '';\n if (contentType.includes('application/json')) {\n return (await response.json()) as T;\n }\n return (await response.text()) as unknown as T;\n }\n\n let body: unknown;\n const text = await response.text();\n try {\n body = JSON.parse(text);\n } catch {\n body = text;\n }\n\n // Handle 404 specifically\n if (response.status === 404) {\n throw new GraphError(\n (body as JsonBody)?.message as string || 'Not found',\n 'NOT_FOUND',\n body\n );\n }\n\n const message =\n (body as JsonBody)?.error && typeof (body as JsonBody).error === 'string'\n ? ((body as JsonBody).error as string)\n : (body as JsonBody)?.message && typeof (body as JsonBody).message === 'string'\n ? ((body as JsonBody).message as string)\n : `Request failed with status ${response.status}`;\n\n throw new GraphError(message, 'HTTP_ERROR', {\n status: response.status,\n body,\n });\n }\n\n // ---------------------------------------------------------------------------\n // Entity Operations\n // ---------------------------------------------------------------------------\n\n /**\n * Get an entity by its canonical ID.\n *\n * @param canonicalId - Entity UUID\n * @returns Entity data\n * @throws GraphEntityNotFoundError if the entity doesn't exist\n *\n * @example\n * ```typescript\n * const entity = await graph.getEntity('uuid-123');\n * console.log('Entity:', entity.label, entity.type);\n * ```\n */\n async getEntity(canonicalId: string): Promise<GraphEntity> {\n const response = await this.request<{ found: boolean; entity?: GraphEntity }>(\n `/graphdb/entity/${encodeURIComponent(canonicalId)}`\n );\n\n if (!response.found || !response.entity) {\n throw new GraphEntityNotFoundError(canonicalId);\n }\n\n return response.entity;\n }\n\n /**\n * Check if an entity exists by its canonical ID.\n *\n * @param canonicalId - Entity UUID\n * @returns True if entity exists\n *\n * @example\n * ```typescript\n * if (await graph.entityExists('uuid-123')) {\n * console.log('Entity exists');\n * }\n * ```\n */\n async entityExists(canonicalId: string): Promise<boolean> {\n const response = await this.request<{ exists: boolean }>(\n `/graphdb/entity/exists/${encodeURIComponent(canonicalId)}`\n );\n return response.exists;\n }\n\n /**\n * Query entities by code with optional type filter.\n *\n * @param code - Entity code to search for\n * @param type - Optional entity type filter\n * @returns Matching entities\n *\n * @example\n * ```typescript\n * // Find by code\n * const entities = await graph.queryByCode('person_john');\n *\n * // With type filter\n * const people = await graph.queryByCode('john', 'person');\n * ```\n */\n async queryByCode(code: string, type?: string): Promise<GraphEntity[]> {\n const response = await this.request<EntityQueryResponse>(\n '/graphdb/entity/query',\n {\n method: 'POST',\n body: JSON.stringify({ code, type }),\n }\n );\n\n if (!response.found || !response.entity) {\n return [];\n }\n\n return [response.entity];\n }\n\n /**\n * Look up entities by code across all PIs.\n *\n * @param code - Entity code to search for\n * @param type - Optional entity type filter\n * @returns Matching entities\n *\n * @example\n * ```typescript\n * const entities = await graph.lookupByCode('alice_austen', 'person');\n * ```\n */\n async lookupByCode(code: string, type?: string): Promise<GraphEntity[]> {\n const response = await this.request<{ entities: GraphEntity[] }>(\n '/graphdb/entities/lookup-by-code',\n {\n method: 'POST',\n body: JSON.stringify({ code, type }),\n }\n );\n return response.entities || [];\n }\n\n // ---------------------------------------------------------------------------\n // PI-based Operations\n // ---------------------------------------------------------------------------\n\n /**\n * List entities from a specific PI or multiple PIs.\n *\n * @param pi - Single PI or array of PIs\n * @param options - Filter options\n * @returns Entities from the PI(s)\n *\n * @example\n * ```typescript\n * // From single PI\n * const entities = await graph.listEntitiesFromPi('01K75HQQXNTDG7BBP7PS9AWYAN');\n *\n * // With type filter\n * const people = await graph.listEntitiesFromPi('01K75HQQXNTDG7BBP7PS9AWYAN', { type: 'person' });\n *\n * // From multiple PIs\n * const all = await graph.listEntitiesFromPi(['pi-1', 'pi-2']);\n * ```\n */\n async listEntitiesFromPi(\n pi: string | string[],\n options: ListFromPiOptions = {}\n ): Promise<GraphEntity[]> {\n const pis = Array.isArray(pi) ? pi : [pi];\n const response = await this.request<{ entities: GraphEntity[] }>(\n '/graphdb/entities/list',\n {\n method: 'POST',\n body: JSON.stringify({\n pis,\n type: options.type,\n }),\n }\n );\n return response.entities || [];\n }\n\n /**\n * Get entities with their relationships from a PI.\n *\n * This is an optimized query that returns entities along with all their\n * relationship data in a single request.\n *\n * @param pi - Persistent Identifier\n * @param type - Optional entity type filter\n * @returns Entities with relationships\n *\n * @example\n * ```typescript\n * const entities = await graph.getEntitiesWithRelationships('01K75HQQXNTDG7BBP7PS9AWYAN');\n * entities.forEach(e => {\n * console.log(`${e.label} has ${e.relationships.length} relationships`);\n * });\n * ```\n */\n async getEntitiesWithRelationships(\n pi: string,\n type?: string\n ): Promise<EntityWithRelationships[]> {\n const response = await this.request<EntitiesWithRelationshipsResponse>(\n '/graphdb/pi/entities-with-relationships',\n {\n method: 'POST',\n body: JSON.stringify({ pi, type }),\n }\n );\n return response.entities || [];\n }\n\n /**\n * Get the lineage (ancestors and/or descendants) of a PI.\n *\n * @param pi - Source PI\n * @param direction - 'ancestors', 'descendants', or 'both'\n * @returns Lineage data\n *\n * @example\n * ```typescript\n * // Get ancestors\n * const lineage = await graph.getLineage('01K75HQQXNTDG7BBP7PS9AWYAN', 'ancestors');\n *\n * // Get both directions\n * const full = await graph.getLineage('01K75HQQXNTDG7BBP7PS9AWYAN', 'both');\n * ```\n */\n async getLineage(\n pi: string,\n direction: 'ancestors' | 'descendants' | 'both' = 'both',\n maxHops: number = 10\n ): Promise<LineageResponse> {\n return this.request<LineageResponse>('/graphdb/pi/lineage', {\n method: 'POST',\n body: JSON.stringify({ sourcePi: pi, direction, maxHops }),\n });\n }\n\n // ---------------------------------------------------------------------------\n // Relationship Operations\n // ---------------------------------------------------------------------------\n\n /**\n * Get all relationships for an entity.\n *\n * @param canonicalId - Entity UUID\n * @returns Array of relationships\n *\n * @example\n * ```typescript\n * const relationships = await graph.getRelationships('uuid-123');\n * relationships.forEach(r => {\n * console.log(`${r.direction}: ${r.predicate} -> ${r.target_label}`);\n * });\n * ```\n */\n async getRelationships(canonicalId: string): Promise<Relationship[]> {\n const response = await this.request<{\n found: boolean;\n canonical_id?: string;\n relationships?: Array<{\n direction: 'outgoing' | 'incoming';\n predicate: string;\n target_id: string;\n target_code?: string;\n target_label: string;\n target_type: string;\n properties?: Record<string, unknown>;\n source_pi?: string;\n created_at?: string;\n }>;\n }>(`/graphdb/relationships/${encodeURIComponent(canonicalId)}`);\n\n if (!response.found || !response.relationships) {\n return [];\n }\n\n return response.relationships.map(rel => ({\n direction: rel.direction,\n predicate: rel.predicate,\n target_id: rel.target_id,\n target_code: rel.target_code || '',\n target_label: rel.target_label,\n target_type: rel.target_type,\n properties: rel.properties,\n source_pi: rel.source_pi,\n created_at: rel.created_at,\n }));\n }\n\n // ---------------------------------------------------------------------------\n // Path Finding\n // ---------------------------------------------------------------------------\n\n /**\n * Find shortest paths between sets of entities.\n *\n * @param sourceIds - Starting entity IDs\n * @param targetIds - Target entity IDs\n * @param options - Path finding options\n * @returns Found paths\n *\n * @example\n * ```typescript\n * const paths = await graph.findPaths(\n * ['uuid-alice'],\n * ['uuid-bob'],\n * { max_depth: 4, direction: 'both' }\n * );\n *\n * paths.forEach(path => {\n * console.log(`Path of length ${path.length}:`);\n * path.edges.forEach(e => {\n * console.log(` ${e.subject_label} -[${e.predicate}]-> ${e.object_label}`);\n * });\n * });\n * ```\n */\n async findPaths(\n sourceIds: string[],\n targetIds: string[],\n options: PathOptions = {}\n ): Promise<Path[]> {\n const response = await this.request<PathsResponse>('/graphdb/paths/between', {\n method: 'POST',\n body: JSON.stringify({\n source_ids: sourceIds,\n target_ids: targetIds,\n max_depth: options.max_depth,\n direction: options.direction,\n limit: options.limit,\n }),\n });\n return response.paths || [];\n }\n\n /**\n * Find entities of a specific type reachable from starting entities.\n *\n * @param startIds - Starting entity IDs\n * @param targetType - Type of entities to find\n * @param options - Search options\n * @returns Reachable entities of the specified type\n *\n * @example\n * ```typescript\n * // Find all people reachable from an event\n * const people = await graph.findReachable(\n * ['uuid-event'],\n * 'person',\n * { max_depth: 3 }\n * );\n * ```\n */\n async findReachable(\n startIds: string[],\n targetType: string,\n options: ReachableOptions = {}\n ): Promise<GraphEntity[]> {\n const response = await this.request<{ entities: GraphEntity[] }>(\n '/graphdb/paths/reachable',\n {\n method: 'POST',\n body: JSON.stringify({\n start_ids: startIds,\n target_type: targetType,\n max_depth: options.max_depth,\n direction: options.direction,\n limit: options.limit,\n }),\n }\n );\n return response.entities || [];\n }\n\n /**\n * Check the health of the graph service.\n *\n * @returns Health status\n */\n async health(): Promise<{ status: string; service: string; version: string }> {\n return this.request('/graphdb/health', { method: 'GET' });\n }\n}\n"],"mappings":";AAOO,IAAM,aAAN,cAAyB,MAAM;AAAA,EACpC,YACE,SACO,OAAe,eACf,SACP;AACA,UAAM,OAAO;AAHN;AACA;AAGP,SAAK,OAAO;AAAA,EACd;AACF;AAKO,IAAM,2BAAN,cAAuC,WAAW;AAAA,EACvD,YAAY,aAAqB;AAC/B,UAAM,2BAA2B,WAAW,I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