@arke-institute/sdk 0.1.1 → 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.
- package/dist/content/index.cjs +506 -0
- package/dist/content/index.cjs.map +1 -0
- package/dist/content/index.d.cts +403 -0
- package/dist/content/index.d.ts +403 -0
- package/dist/content/index.js +473 -0
- package/dist/content/index.js.map +1 -0
- package/dist/edit/index.cjs +1029 -0
- package/dist/edit/index.cjs.map +1 -0
- package/dist/edit/index.d.cts +78 -0
- package/dist/edit/index.d.ts +78 -0
- package/dist/edit/index.js +983 -0
- package/dist/edit/index.js.map +1 -0
- package/dist/{errors-BrNZWPE7.d.cts → errors-3L7IiHcr.d.cts} +3 -0
- package/dist/errors-B82BMmRP.d.cts +343 -0
- package/dist/errors-B82BMmRP.d.ts +343 -0
- package/dist/{errors-CCyp5KCg.d.ts → errors-BTe8GKRQ.d.ts} +3 -0
- package/dist/graph/index.cjs +433 -0
- package/dist/graph/index.cjs.map +1 -0
- package/dist/graph/index.d.cts +456 -0
- package/dist/graph/index.d.ts +456 -0
- package/dist/graph/index.js +402 -0
- package/dist/graph/index.js.map +1 -0
- package/dist/index.cjs +2126 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.js +2108 -14
- package/dist/index.js.map +1 -1
- package/dist/query/index.cjs +289 -0
- package/dist/query/index.cjs.map +1 -0
- package/dist/query/index.d.cts +541 -0
- package/dist/query/index.d.ts +541 -0
- package/dist/query/index.js +261 -0
- package/dist/query/index.js.map +1 -0
- package/dist/upload/index.cjs +3 -14
- package/dist/upload/index.cjs.map +1 -1
- package/dist/upload/index.d.cts +2 -2
- package/dist/upload/index.d.ts +2 -2
- package/dist/upload/index.js +3 -14
- package/dist/upload/index.js.map +1 -1
- package/package.json +26 -1
|
@@ -0,0 +1,506 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/content/index.ts
|
|
21
|
+
var content_exports = {};
|
|
22
|
+
__export(content_exports, {
|
|
23
|
+
ComponentNotFoundError: () => ComponentNotFoundError,
|
|
24
|
+
ContentClient: () => ContentClient,
|
|
25
|
+
ContentError: () => ContentError,
|
|
26
|
+
ContentNotFoundError: () => ContentNotFoundError,
|
|
27
|
+
EntityNotFoundError: () => EntityNotFoundError,
|
|
28
|
+
NetworkError: () => NetworkError,
|
|
29
|
+
VersionNotFoundError: () => VersionNotFoundError
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(content_exports);
|
|
32
|
+
|
|
33
|
+
// src/content/errors.ts
|
|
34
|
+
var ContentError = class extends Error {
|
|
35
|
+
constructor(message, code = "CONTENT_ERROR", details) {
|
|
36
|
+
super(message);
|
|
37
|
+
this.code = code;
|
|
38
|
+
this.details = details;
|
|
39
|
+
this.name = "ContentError";
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
var EntityNotFoundError = class extends ContentError {
|
|
43
|
+
constructor(pi) {
|
|
44
|
+
super(`Entity not found: ${pi}`, "ENTITY_NOT_FOUND", { pi });
|
|
45
|
+
this.name = "EntityNotFoundError";
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
var ContentNotFoundError = class extends ContentError {
|
|
49
|
+
constructor(cid) {
|
|
50
|
+
super(`Content not found: ${cid}`, "CONTENT_NOT_FOUND", { cid });
|
|
51
|
+
this.name = "ContentNotFoundError";
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
var ComponentNotFoundError = class extends ContentError {
|
|
55
|
+
constructor(pi, componentName) {
|
|
56
|
+
super(
|
|
57
|
+
`Component '${componentName}' not found on entity ${pi}`,
|
|
58
|
+
"COMPONENT_NOT_FOUND",
|
|
59
|
+
{ pi, componentName }
|
|
60
|
+
);
|
|
61
|
+
this.name = "ComponentNotFoundError";
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
var VersionNotFoundError = class extends ContentError {
|
|
65
|
+
constructor(pi, selector) {
|
|
66
|
+
super(
|
|
67
|
+
`Version not found: ${selector} for entity ${pi}`,
|
|
68
|
+
"VERSION_NOT_FOUND",
|
|
69
|
+
{ pi, selector }
|
|
70
|
+
);
|
|
71
|
+
this.name = "VersionNotFoundError";
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
var NetworkError = class extends ContentError {
|
|
75
|
+
constructor(message, statusCode) {
|
|
76
|
+
super(message, "NETWORK_ERROR", { statusCode });
|
|
77
|
+
this.statusCode = statusCode;
|
|
78
|
+
this.name = "NetworkError";
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
// src/content/client.ts
|
|
83
|
+
var ContentClient = class {
|
|
84
|
+
constructor(config) {
|
|
85
|
+
this.baseUrl = config.gatewayUrl.replace(/\/$/, "");
|
|
86
|
+
this.fetchImpl = config.fetchImpl ?? fetch;
|
|
87
|
+
}
|
|
88
|
+
// ---------------------------------------------------------------------------
|
|
89
|
+
// Request helpers
|
|
90
|
+
// ---------------------------------------------------------------------------
|
|
91
|
+
buildUrl(path, query) {
|
|
92
|
+
const url = new URL(`${this.baseUrl}${path}`);
|
|
93
|
+
if (query) {
|
|
94
|
+
Object.entries(query).forEach(([key, value]) => {
|
|
95
|
+
if (value !== void 0 && value !== null) {
|
|
96
|
+
url.searchParams.set(key, String(value));
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
return url.toString();
|
|
101
|
+
}
|
|
102
|
+
async request(path, options = {}) {
|
|
103
|
+
const url = this.buildUrl(path, options.query);
|
|
104
|
+
const headers = new Headers({ "Content-Type": "application/json" });
|
|
105
|
+
if (options.headers) {
|
|
106
|
+
Object.entries(options.headers).forEach(([k, v]) => {
|
|
107
|
+
if (v !== void 0) headers.set(k, v);
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
let response;
|
|
111
|
+
try {
|
|
112
|
+
response = await this.fetchImpl(url, { ...options, headers });
|
|
113
|
+
} catch (err) {
|
|
114
|
+
throw new NetworkError(
|
|
115
|
+
err instanceof Error ? err.message : "Network request failed"
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
if (response.ok) {
|
|
119
|
+
const contentType = response.headers.get("content-type") || "";
|
|
120
|
+
if (contentType.includes("application/json")) {
|
|
121
|
+
return await response.json();
|
|
122
|
+
}
|
|
123
|
+
return await response.text();
|
|
124
|
+
}
|
|
125
|
+
let body;
|
|
126
|
+
const text = await response.text();
|
|
127
|
+
try {
|
|
128
|
+
body = JSON.parse(text);
|
|
129
|
+
} catch {
|
|
130
|
+
body = text;
|
|
131
|
+
}
|
|
132
|
+
if (response.status === 404) {
|
|
133
|
+
const errorCode = body?.error;
|
|
134
|
+
if (errorCode === "NOT_FOUND" || errorCode === "ENTITY_NOT_FOUND") {
|
|
135
|
+
throw new ContentError(
|
|
136
|
+
body?.message || "Not found",
|
|
137
|
+
"NOT_FOUND",
|
|
138
|
+
body
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
const message = body?.error && typeof body.error === "string" ? body.error : body?.message && typeof body.message === "string" ? body.message : `Request failed with status ${response.status}`;
|
|
143
|
+
throw new ContentError(message, "HTTP_ERROR", {
|
|
144
|
+
status: response.status,
|
|
145
|
+
body
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
// ---------------------------------------------------------------------------
|
|
149
|
+
// Entity Operations
|
|
150
|
+
// ---------------------------------------------------------------------------
|
|
151
|
+
/**
|
|
152
|
+
* Get an entity by its Persistent Identifier (PI).
|
|
153
|
+
*
|
|
154
|
+
* @param pi - Persistent Identifier (ULID or test PI with II prefix)
|
|
155
|
+
* @returns Full entity manifest
|
|
156
|
+
* @throws EntityNotFoundError if the entity doesn't exist
|
|
157
|
+
*
|
|
158
|
+
* @example
|
|
159
|
+
* ```typescript
|
|
160
|
+
* const entity = await content.get('01K75HQQXNTDG7BBP7PS9AWYAN');
|
|
161
|
+
* console.log('Version:', entity.ver);
|
|
162
|
+
* console.log('Components:', Object.keys(entity.components));
|
|
163
|
+
* ```
|
|
164
|
+
*/
|
|
165
|
+
async get(pi) {
|
|
166
|
+
try {
|
|
167
|
+
return await this.request(`/api/entities/${encodeURIComponent(pi)}`);
|
|
168
|
+
} catch (err) {
|
|
169
|
+
if (err instanceof ContentError && err.code === "NOT_FOUND") {
|
|
170
|
+
throw new EntityNotFoundError(pi);
|
|
171
|
+
}
|
|
172
|
+
throw err;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* List entities with pagination.
|
|
177
|
+
*
|
|
178
|
+
* @param options - Pagination and metadata options
|
|
179
|
+
* @returns Paginated list of entity summaries
|
|
180
|
+
*
|
|
181
|
+
* @example
|
|
182
|
+
* ```typescript
|
|
183
|
+
* // Get first page
|
|
184
|
+
* const page1 = await content.list({ limit: 20, include_metadata: true });
|
|
185
|
+
*
|
|
186
|
+
* // Get next page
|
|
187
|
+
* if (page1.next_cursor) {
|
|
188
|
+
* const page2 = await content.list({ cursor: page1.next_cursor });
|
|
189
|
+
* }
|
|
190
|
+
* ```
|
|
191
|
+
*/
|
|
192
|
+
async list(options = {}) {
|
|
193
|
+
return this.request("/api/entities", {
|
|
194
|
+
query: {
|
|
195
|
+
limit: options.limit,
|
|
196
|
+
cursor: options.cursor,
|
|
197
|
+
include_metadata: options.include_metadata
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Get version history for an entity.
|
|
203
|
+
*
|
|
204
|
+
* @param pi - Persistent Identifier
|
|
205
|
+
* @param options - Pagination options
|
|
206
|
+
* @returns Version history (newest first)
|
|
207
|
+
*
|
|
208
|
+
* @example
|
|
209
|
+
* ```typescript
|
|
210
|
+
* const history = await content.versions('01K75HQQXNTDG7BBP7PS9AWYAN');
|
|
211
|
+
* console.log('Total versions:', history.items.length);
|
|
212
|
+
* history.items.forEach(v => {
|
|
213
|
+
* console.log(`v${v.ver}: ${v.ts} - ${v.note || 'no note'}`);
|
|
214
|
+
* });
|
|
215
|
+
* ```
|
|
216
|
+
*/
|
|
217
|
+
async versions(pi, options = {}) {
|
|
218
|
+
try {
|
|
219
|
+
return await this.request(
|
|
220
|
+
`/api/entities/${encodeURIComponent(pi)}/versions`,
|
|
221
|
+
{
|
|
222
|
+
query: {
|
|
223
|
+
limit: options.limit,
|
|
224
|
+
cursor: options.cursor
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
);
|
|
228
|
+
} catch (err) {
|
|
229
|
+
if (err instanceof ContentError && err.code === "NOT_FOUND") {
|
|
230
|
+
throw new EntityNotFoundError(pi);
|
|
231
|
+
}
|
|
232
|
+
throw err;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Get a specific version of an entity.
|
|
237
|
+
*
|
|
238
|
+
* @param pi - Persistent Identifier
|
|
239
|
+
* @param selector - Version selector: 'ver:N' for version number or 'cid:...' for CID
|
|
240
|
+
* @returns Entity manifest for the specified version
|
|
241
|
+
*
|
|
242
|
+
* @example
|
|
243
|
+
* ```typescript
|
|
244
|
+
* // Get version 2
|
|
245
|
+
* const v2 = await content.getVersion('01K75HQQXNTDG7BBP7PS9AWYAN', 'ver:2');
|
|
246
|
+
*
|
|
247
|
+
* // Get by CID
|
|
248
|
+
* const vByCid = await content.getVersion('01K75HQQXNTDG7BBP7PS9AWYAN', 'cid:bafybeih...');
|
|
249
|
+
* ```
|
|
250
|
+
*/
|
|
251
|
+
async getVersion(pi, selector) {
|
|
252
|
+
try {
|
|
253
|
+
return await this.request(
|
|
254
|
+
`/api/entities/${encodeURIComponent(pi)}/versions/${encodeURIComponent(selector)}`
|
|
255
|
+
);
|
|
256
|
+
} catch (err) {
|
|
257
|
+
if (err instanceof ContentError && err.code === "NOT_FOUND") {
|
|
258
|
+
throw new EntityNotFoundError(pi);
|
|
259
|
+
}
|
|
260
|
+
throw err;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Resolve a PI to its tip CID (fast lookup without fetching manifest).
|
|
265
|
+
*
|
|
266
|
+
* @param pi - Persistent Identifier
|
|
267
|
+
* @returns PI and tip CID
|
|
268
|
+
*
|
|
269
|
+
* @example
|
|
270
|
+
* ```typescript
|
|
271
|
+
* const { tip } = await content.resolve('01K75HQQXNTDG7BBP7PS9AWYAN');
|
|
272
|
+
* console.log('Latest manifest CID:', tip);
|
|
273
|
+
* ```
|
|
274
|
+
*/
|
|
275
|
+
async resolve(pi) {
|
|
276
|
+
try {
|
|
277
|
+
return await this.request(`/api/resolve/${encodeURIComponent(pi)}`);
|
|
278
|
+
} catch (err) {
|
|
279
|
+
if (err instanceof ContentError && err.code === "NOT_FOUND") {
|
|
280
|
+
throw new EntityNotFoundError(pi);
|
|
281
|
+
}
|
|
282
|
+
throw err;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Get the list of child PIs for an entity (fast, returns only PIs).
|
|
287
|
+
*
|
|
288
|
+
* @param pi - Persistent Identifier of parent entity
|
|
289
|
+
* @returns Array of child PIs
|
|
290
|
+
*
|
|
291
|
+
* @example
|
|
292
|
+
* ```typescript
|
|
293
|
+
* const childPis = await content.children('01K75HQQXNTDG7BBP7PS9AWYAN');
|
|
294
|
+
* console.log('Children:', childPis);
|
|
295
|
+
* ```
|
|
296
|
+
*/
|
|
297
|
+
async children(pi) {
|
|
298
|
+
const entity = await this.get(pi);
|
|
299
|
+
return entity.children_pi || [];
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* Get all child entities for a parent (fetches full entity for each child).
|
|
303
|
+
*
|
|
304
|
+
* @param pi - Persistent Identifier of parent entity
|
|
305
|
+
* @returns Array of child entities
|
|
306
|
+
*
|
|
307
|
+
* @example
|
|
308
|
+
* ```typescript
|
|
309
|
+
* const childEntities = await content.childrenEntities('01K75HQQXNTDG7BBP7PS9AWYAN');
|
|
310
|
+
* childEntities.forEach(child => {
|
|
311
|
+
* console.log(`${child.pi}: v${child.ver}`);
|
|
312
|
+
* });
|
|
313
|
+
* ```
|
|
314
|
+
*/
|
|
315
|
+
async childrenEntities(pi) {
|
|
316
|
+
const childPis = await this.children(pi);
|
|
317
|
+
if (childPis.length === 0) {
|
|
318
|
+
return [];
|
|
319
|
+
}
|
|
320
|
+
const results = await Promise.allSettled(
|
|
321
|
+
childPis.map((childPi) => this.get(childPi))
|
|
322
|
+
);
|
|
323
|
+
return results.filter((r) => r.status === "fulfilled").map((r) => r.value);
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* Get the Arke origin block (root of the archive tree).
|
|
327
|
+
*
|
|
328
|
+
* @returns Arke origin entity
|
|
329
|
+
*
|
|
330
|
+
* @example
|
|
331
|
+
* ```typescript
|
|
332
|
+
* const origin = await content.arke();
|
|
333
|
+
* console.log('Arke origin:', origin.pi);
|
|
334
|
+
* ```
|
|
335
|
+
*/
|
|
336
|
+
async arke() {
|
|
337
|
+
return this.request("/api/arke");
|
|
338
|
+
}
|
|
339
|
+
// ---------------------------------------------------------------------------
|
|
340
|
+
// Content Download
|
|
341
|
+
// ---------------------------------------------------------------------------
|
|
342
|
+
/**
|
|
343
|
+
* Download content by CID.
|
|
344
|
+
*
|
|
345
|
+
* Returns Blob in browser environments, Buffer in Node.js.
|
|
346
|
+
*
|
|
347
|
+
* @param cid - Content Identifier
|
|
348
|
+
* @returns Content as Blob (browser) or Buffer (Node)
|
|
349
|
+
* @throws ContentNotFoundError if the content doesn't exist
|
|
350
|
+
*
|
|
351
|
+
* @example
|
|
352
|
+
* ```typescript
|
|
353
|
+
* const content = await client.download('bafybeih...');
|
|
354
|
+
*
|
|
355
|
+
* // In browser
|
|
356
|
+
* const url = URL.createObjectURL(content as Blob);
|
|
357
|
+
*
|
|
358
|
+
* // In Node.js
|
|
359
|
+
* fs.writeFileSync('output.bin', content as Buffer);
|
|
360
|
+
* ```
|
|
361
|
+
*/
|
|
362
|
+
async download(cid) {
|
|
363
|
+
const url = this.buildUrl(`/api/cat/${encodeURIComponent(cid)}`);
|
|
364
|
+
let response;
|
|
365
|
+
try {
|
|
366
|
+
response = await this.fetchImpl(url);
|
|
367
|
+
} catch (err) {
|
|
368
|
+
throw new NetworkError(
|
|
369
|
+
err instanceof Error ? err.message : "Network request failed"
|
|
370
|
+
);
|
|
371
|
+
}
|
|
372
|
+
if (!response.ok) {
|
|
373
|
+
if (response.status === 404) {
|
|
374
|
+
throw new ContentNotFoundError(cid);
|
|
375
|
+
}
|
|
376
|
+
throw new ContentError(
|
|
377
|
+
`Failed to download content: ${response.status}`,
|
|
378
|
+
"DOWNLOAD_ERROR",
|
|
379
|
+
{ status: response.status }
|
|
380
|
+
);
|
|
381
|
+
}
|
|
382
|
+
if (typeof window !== "undefined") {
|
|
383
|
+
return response.blob();
|
|
384
|
+
} else {
|
|
385
|
+
const arrayBuffer = await response.arrayBuffer();
|
|
386
|
+
return Buffer.from(arrayBuffer);
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
/**
|
|
390
|
+
* Get a direct URL for content by CID.
|
|
391
|
+
*
|
|
392
|
+
* This is useful for embedding in img tags or for direct downloads.
|
|
393
|
+
*
|
|
394
|
+
* @param cid - Content Identifier
|
|
395
|
+
* @returns URL string
|
|
396
|
+
*
|
|
397
|
+
* @example
|
|
398
|
+
* ```typescript
|
|
399
|
+
* const url = content.getUrl('bafybeih...');
|
|
400
|
+
* // Use in img tag: <img src={url} />
|
|
401
|
+
* ```
|
|
402
|
+
*/
|
|
403
|
+
getUrl(cid) {
|
|
404
|
+
return `${this.baseUrl}/api/cat/${encodeURIComponent(cid)}`;
|
|
405
|
+
}
|
|
406
|
+
/**
|
|
407
|
+
* Stream content by CID.
|
|
408
|
+
*
|
|
409
|
+
* @param cid - Content Identifier
|
|
410
|
+
* @returns ReadableStream of the content
|
|
411
|
+
* @throws ContentNotFoundError if the content doesn't exist
|
|
412
|
+
*
|
|
413
|
+
* @example
|
|
414
|
+
* ```typescript
|
|
415
|
+
* const stream = await content.stream('bafybeih...');
|
|
416
|
+
* const reader = stream.getReader();
|
|
417
|
+
* while (true) {
|
|
418
|
+
* const { done, value } = await reader.read();
|
|
419
|
+
* if (done) break;
|
|
420
|
+
* // Process chunk
|
|
421
|
+
* }
|
|
422
|
+
* ```
|
|
423
|
+
*/
|
|
424
|
+
async stream(cid) {
|
|
425
|
+
const url = this.buildUrl(`/api/cat/${encodeURIComponent(cid)}`);
|
|
426
|
+
let response;
|
|
427
|
+
try {
|
|
428
|
+
response = await this.fetchImpl(url);
|
|
429
|
+
} catch (err) {
|
|
430
|
+
throw new NetworkError(
|
|
431
|
+
err instanceof Error ? err.message : "Network request failed"
|
|
432
|
+
);
|
|
433
|
+
}
|
|
434
|
+
if (!response.ok) {
|
|
435
|
+
if (response.status === 404) {
|
|
436
|
+
throw new ContentNotFoundError(cid);
|
|
437
|
+
}
|
|
438
|
+
throw new ContentError(
|
|
439
|
+
`Failed to stream content: ${response.status}`,
|
|
440
|
+
"STREAM_ERROR",
|
|
441
|
+
{ status: response.status }
|
|
442
|
+
);
|
|
443
|
+
}
|
|
444
|
+
if (!response.body) {
|
|
445
|
+
throw new ContentError("Response body is not available", "STREAM_ERROR");
|
|
446
|
+
}
|
|
447
|
+
return response.body;
|
|
448
|
+
}
|
|
449
|
+
// ---------------------------------------------------------------------------
|
|
450
|
+
// Component Helpers
|
|
451
|
+
// ---------------------------------------------------------------------------
|
|
452
|
+
/**
|
|
453
|
+
* Download a component from an entity.
|
|
454
|
+
*
|
|
455
|
+
* @param entity - Entity containing the component
|
|
456
|
+
* @param componentName - Name of the component (e.g., 'pinax', 'description', 'source')
|
|
457
|
+
* @returns Component content as Blob (browser) or Buffer (Node)
|
|
458
|
+
* @throws ComponentNotFoundError if the component doesn't exist
|
|
459
|
+
*
|
|
460
|
+
* @example
|
|
461
|
+
* ```typescript
|
|
462
|
+
* const entity = await content.get('01K75HQQXNTDG7BBP7PS9AWYAN');
|
|
463
|
+
* const pinax = await content.getComponent(entity, 'pinax');
|
|
464
|
+
* ```
|
|
465
|
+
*/
|
|
466
|
+
async getComponent(entity, componentName) {
|
|
467
|
+
const cid = entity.components[componentName];
|
|
468
|
+
if (!cid) {
|
|
469
|
+
throw new ComponentNotFoundError(entity.pi, componentName);
|
|
470
|
+
}
|
|
471
|
+
return this.download(cid);
|
|
472
|
+
}
|
|
473
|
+
/**
|
|
474
|
+
* Get the URL for a component from an entity.
|
|
475
|
+
*
|
|
476
|
+
* @param entity - Entity containing the component
|
|
477
|
+
* @param componentName - Name of the component
|
|
478
|
+
* @returns URL string
|
|
479
|
+
* @throws ComponentNotFoundError if the component doesn't exist
|
|
480
|
+
*
|
|
481
|
+
* @example
|
|
482
|
+
* ```typescript
|
|
483
|
+
* const entity = await content.get('01K75HQQXNTDG7BBP7PS9AWYAN');
|
|
484
|
+
* const imageUrl = content.getComponentUrl(entity, 'source');
|
|
485
|
+
* // Use in img tag: <img src={imageUrl} />
|
|
486
|
+
* ```
|
|
487
|
+
*/
|
|
488
|
+
getComponentUrl(entity, componentName) {
|
|
489
|
+
const cid = entity.components[componentName];
|
|
490
|
+
if (!cid) {
|
|
491
|
+
throw new ComponentNotFoundError(entity.pi, componentName);
|
|
492
|
+
}
|
|
493
|
+
return this.getUrl(cid);
|
|
494
|
+
}
|
|
495
|
+
};
|
|
496
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
497
|
+
0 && (module.exports = {
|
|
498
|
+
ComponentNotFoundError,
|
|
499
|
+
ContentClient,
|
|
500
|
+
ContentError,
|
|
501
|
+
ContentNotFoundError,
|
|
502
|
+
EntityNotFoundError,
|
|
503
|
+
NetworkError,
|
|
504
|
+
VersionNotFoundError
|
|
505
|
+
});
|
|
506
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/content/index.ts","../../src/content/errors.ts","../../src/content/client.ts"],"sourcesContent":["/**\n * Content package for the Arke SDK\n *\n * Provides read-only access to entities and content from the IPFS Wrapper service.\n *\n * @example\n * ```typescript\n * import { ContentClient } from '@arke-institute/sdk/content';\n *\n * const content = new ContentClient({\n * gatewayUrl: 'https://gateway.arke.institute',\n * });\n *\n * // Get an entity\n * const entity = await content.get('01K75HQQXNTDG7BBP7PS9AWYAN');\n *\n * // List entities\n * const { entities, next_cursor } = await content.list({ limit: 20 });\n *\n * // Download content\n * const blob = await content.download(entity.components.source);\n * ```\n */\n\nexport { ContentClient, type ContentClientConfig } from './client.js';\nexport * from './types.js';\nexport * from './errors.js';\n","/**\n * Content package error classes for the Arke SDK\n */\n\n/**\n * Base error class for content operations\n */\nexport class ContentError extends Error {\n constructor(\n message: string,\n public code: string = 'CONTENT_ERROR',\n public details?: unknown\n ) {\n super(message);\n this.name = 'ContentError';\n }\n}\n\n/**\n * Thrown when an entity is not found by PI\n */\nexport class EntityNotFoundError extends ContentError {\n constructor(pi: string) {\n super(`Entity not found: ${pi}`, 'ENTITY_NOT_FOUND', { pi });\n this.name = 'EntityNotFoundError';\n }\n}\n\n/**\n * Thrown when content is not found by CID\n */\nexport class ContentNotFoundError extends ContentError {\n constructor(cid: string) {\n super(`Content not found: ${cid}`, 'CONTENT_NOT_FOUND', { cid });\n this.name = 'ContentNotFoundError';\n }\n}\n\n/**\n * Thrown when a component is not found on an entity\n */\nexport class ComponentNotFoundError extends ContentError {\n constructor(pi: string, componentName: string) {\n super(\n `Component '${componentName}' not found on entity ${pi}`,\n 'COMPONENT_NOT_FOUND',\n { pi, componentName }\n );\n this.name = 'ComponentNotFoundError';\n }\n}\n\n/**\n * Thrown when a version is not found\n */\nexport class VersionNotFoundError extends ContentError {\n constructor(pi: string, selector: string) {\n super(\n `Version not found: ${selector} for entity ${pi}`,\n 'VERSION_NOT_FOUND',\n { pi, selector }\n );\n this.name = 'VersionNotFoundError';\n }\n}\n\n/**\n * Thrown when a network error occurs\n */\nexport class NetworkError extends ContentError {\n constructor(message: string, public statusCode?: number) {\n super(message, 'NETWORK_ERROR', { statusCode });\n this.name = 'NetworkError';\n }\n}\n","import {\n ContentError,\n EntityNotFoundError,\n ContentNotFoundError,\n ComponentNotFoundError,\n NetworkError,\n} from './errors.js';\nimport type {\n Entity,\n EntityVersion,\n ListOptions,\n ListResponse,\n VersionsOptions,\n VersionsResponse,\n ResolveResponse,\n} from './types.js';\n\n/**\n * Configuration for ContentClient\n */\nexport interface ContentClientConfig {\n /**\n * Gateway base URL (e.g., https://gateway.arke.institute).\n * The client will call /api/* endpoints for IPFS Wrapper.\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 accessing entities and content from the Arke archive.\n *\n * All endpoints are public and do not require authentication.\n *\n * @example\n * ```typescript\n * const content = new ContentClient({\n * gatewayUrl: 'https://gateway.arke.institute',\n * });\n *\n * // Get an entity\n * const entity = await content.get('01K75HQQXNTDG7BBP7PS9AWYAN');\n *\n * // Download content by CID\n * const blob = await content.download('bafybeihkoviema7g3gxyt6la7vd5ho32jywf7b4c4z3qtwcabpjqxwsumu');\n *\n * // Get component content\n * const pinax = await content.getComponent(entity, 'pinax');\n * ```\n */\nexport class ContentClient {\n private baseUrl: string;\n private fetchImpl: typeof fetch;\n\n constructor(config: ContentClientConfig) {\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 const errorCode = (body as JsonBody)?.error;\n if (errorCode === 'NOT_FOUND' || errorCode === 'ENTITY_NOT_FOUND') {\n throw new ContentError(\n (body as JsonBody)?.message as string || 'Not found',\n 'NOT_FOUND',\n body\n );\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 ContentError(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 Persistent Identifier (PI).\n *\n * @param pi - Persistent Identifier (ULID or test PI with II prefix)\n * @returns Full entity manifest\n * @throws EntityNotFoundError if the entity doesn't exist\n *\n * @example\n * ```typescript\n * const entity = await content.get('01K75HQQXNTDG7BBP7PS9AWYAN');\n * console.log('Version:', entity.ver);\n * console.log('Components:', Object.keys(entity.components));\n * ```\n */\n async get(pi: string): Promise<Entity> {\n try {\n return await this.request<Entity>(`/api/entities/${encodeURIComponent(pi)}`);\n } catch (err) {\n if (err instanceof ContentError && err.code === 'NOT_FOUND') {\n throw new EntityNotFoundError(pi);\n }\n throw err;\n }\n }\n\n /**\n * List entities with pagination.\n *\n * @param options - Pagination and metadata options\n * @returns Paginated list of entity summaries\n *\n * @example\n * ```typescript\n * // Get first page\n * const page1 = await content.list({ limit: 20, include_metadata: true });\n *\n * // Get next page\n * if (page1.next_cursor) {\n * const page2 = await content.list({ cursor: page1.next_cursor });\n * }\n * ```\n */\n async list(options: ListOptions = {}): Promise<ListResponse> {\n return this.request<ListResponse>('/api/entities', {\n query: {\n limit: options.limit,\n cursor: options.cursor,\n include_metadata: options.include_metadata,\n },\n });\n }\n\n /**\n * Get version history for an entity.\n *\n * @param pi - Persistent Identifier\n * @param options - Pagination options\n * @returns Version history (newest first)\n *\n * @example\n * ```typescript\n * const history = await content.versions('01K75HQQXNTDG7BBP7PS9AWYAN');\n * console.log('Total versions:', history.items.length);\n * history.items.forEach(v => {\n * console.log(`v${v.ver}: ${v.ts} - ${v.note || 'no note'}`);\n * });\n * ```\n */\n async versions(pi: string, options: VersionsOptions = {}): Promise<VersionsResponse> {\n try {\n return await this.request<VersionsResponse>(\n `/api/entities/${encodeURIComponent(pi)}/versions`,\n {\n query: {\n limit: options.limit,\n cursor: options.cursor,\n },\n }\n );\n } catch (err) {\n if (err instanceof ContentError && err.code === 'NOT_FOUND') {\n throw new EntityNotFoundError(pi);\n }\n throw err;\n }\n }\n\n /**\n * Get a specific version of an entity.\n *\n * @param pi - Persistent Identifier\n * @param selector - Version selector: 'ver:N' for version number or 'cid:...' for CID\n * @returns Entity manifest for the specified version\n *\n * @example\n * ```typescript\n * // Get version 2\n * const v2 = await content.getVersion('01K75HQQXNTDG7BBP7PS9AWYAN', 'ver:2');\n *\n * // Get by CID\n * const vByCid = await content.getVersion('01K75HQQXNTDG7BBP7PS9AWYAN', 'cid:bafybeih...');\n * ```\n */\n async getVersion(pi: string, selector: string): Promise<Entity> {\n try {\n return await this.request<Entity>(\n `/api/entities/${encodeURIComponent(pi)}/versions/${encodeURIComponent(selector)}`\n );\n } catch (err) {\n if (err instanceof ContentError && err.code === 'NOT_FOUND') {\n throw new EntityNotFoundError(pi);\n }\n throw err;\n }\n }\n\n /**\n * Resolve a PI to its tip CID (fast lookup without fetching manifest).\n *\n * @param pi - Persistent Identifier\n * @returns PI and tip CID\n *\n * @example\n * ```typescript\n * const { tip } = await content.resolve('01K75HQQXNTDG7BBP7PS9AWYAN');\n * console.log('Latest manifest CID:', tip);\n * ```\n */\n async resolve(pi: string): Promise<ResolveResponse> {\n try {\n return await this.request<ResolveResponse>(`/api/resolve/${encodeURIComponent(pi)}`);\n } catch (err) {\n if (err instanceof ContentError && err.code === 'NOT_FOUND') {\n throw new EntityNotFoundError(pi);\n }\n throw err;\n }\n }\n\n /**\n * Get the list of child PIs for an entity (fast, returns only PIs).\n *\n * @param pi - Persistent Identifier of parent entity\n * @returns Array of child PIs\n *\n * @example\n * ```typescript\n * const childPis = await content.children('01K75HQQXNTDG7BBP7PS9AWYAN');\n * console.log('Children:', childPis);\n * ```\n */\n async children(pi: string): Promise<string[]> {\n const entity = await this.get(pi);\n return entity.children_pi || [];\n }\n\n /**\n * Get all child entities for a parent (fetches full entity for each child).\n *\n * @param pi - Persistent Identifier of parent entity\n * @returns Array of child entities\n *\n * @example\n * ```typescript\n * const childEntities = await content.childrenEntities('01K75HQQXNTDG7BBP7PS9AWYAN');\n * childEntities.forEach(child => {\n * console.log(`${child.pi}: v${child.ver}`);\n * });\n * ```\n */\n async childrenEntities(pi: string): Promise<Entity[]> {\n const childPis = await this.children(pi);\n if (childPis.length === 0) {\n return [];\n }\n\n // Fetch all children in parallel\n const results = await Promise.allSettled(\n childPis.map(childPi => this.get(childPi))\n );\n\n // Return only successful fetches\n return results\n .filter((r): r is PromiseFulfilledResult<Entity> => r.status === 'fulfilled')\n .map(r => r.value);\n }\n\n /**\n * Get the Arke origin block (root of the archive tree).\n *\n * @returns Arke origin entity\n *\n * @example\n * ```typescript\n * const origin = await content.arke();\n * console.log('Arke origin:', origin.pi);\n * ```\n */\n async arke(): Promise<Entity> {\n return this.request<Entity>('/api/arke');\n }\n\n // ---------------------------------------------------------------------------\n // Content Download\n // ---------------------------------------------------------------------------\n\n /**\n * Download content by CID.\n *\n * Returns Blob in browser environments, Buffer in Node.js.\n *\n * @param cid - Content Identifier\n * @returns Content as Blob (browser) or Buffer (Node)\n * @throws ContentNotFoundError if the content doesn't exist\n *\n * @example\n * ```typescript\n * const content = await client.download('bafybeih...');\n *\n * // In browser\n * const url = URL.createObjectURL(content as Blob);\n *\n * // In Node.js\n * fs.writeFileSync('output.bin', content as Buffer);\n * ```\n */\n async download(cid: string): Promise<Blob | Buffer> {\n const url = this.buildUrl(`/api/cat/${encodeURIComponent(cid)}`);\n\n let response: Response;\n try {\n response = await this.fetchImpl(url);\n } catch (err) {\n throw new NetworkError(\n err instanceof Error ? err.message : 'Network request failed'\n );\n }\n\n if (!response.ok) {\n if (response.status === 404) {\n throw new ContentNotFoundError(cid);\n }\n throw new ContentError(\n `Failed to download content: ${response.status}`,\n 'DOWNLOAD_ERROR',\n { status: response.status }\n );\n }\n\n // Platform-aware response handling\n if (typeof window !== 'undefined') {\n // Browser environment\n return response.blob();\n } else {\n // Node.js environment\n const arrayBuffer = await response.arrayBuffer();\n return Buffer.from(arrayBuffer);\n }\n }\n\n /**\n * Get a direct URL for content by CID.\n *\n * This is useful for embedding in img tags or for direct downloads.\n *\n * @param cid - Content Identifier\n * @returns URL string\n *\n * @example\n * ```typescript\n * const url = content.getUrl('bafybeih...');\n * // Use in img tag: <img src={url} />\n * ```\n */\n getUrl(cid: string): string {\n return `${this.baseUrl}/api/cat/${encodeURIComponent(cid)}`;\n }\n\n /**\n * Stream content by CID.\n *\n * @param cid - Content Identifier\n * @returns ReadableStream of the content\n * @throws ContentNotFoundError if the content doesn't exist\n *\n * @example\n * ```typescript\n * const stream = await content.stream('bafybeih...');\n * const reader = stream.getReader();\n * while (true) {\n * const { done, value } = await reader.read();\n * if (done) break;\n * // Process chunk\n * }\n * ```\n */\n async stream(cid: string): Promise<ReadableStream<Uint8Array>> {\n const url = this.buildUrl(`/api/cat/${encodeURIComponent(cid)}`);\n\n let response: Response;\n try {\n response = await this.fetchImpl(url);\n } catch (err) {\n throw new NetworkError(\n err instanceof Error ? err.message : 'Network request failed'\n );\n }\n\n if (!response.ok) {\n if (response.status === 404) {\n throw new ContentNotFoundError(cid);\n }\n throw new ContentError(\n `Failed to stream content: ${response.status}`,\n 'STREAM_ERROR',\n { status: response.status }\n );\n }\n\n if (!response.body) {\n throw new ContentError('Response body is not available', 'STREAM_ERROR');\n }\n\n return response.body;\n }\n\n // ---------------------------------------------------------------------------\n // Component Helpers\n // ---------------------------------------------------------------------------\n\n /**\n * Download a component from an entity.\n *\n * @param entity - Entity containing the component\n * @param componentName - Name of the component (e.g., 'pinax', 'description', 'source')\n * @returns Component content as Blob (browser) or Buffer (Node)\n * @throws ComponentNotFoundError if the component doesn't exist\n *\n * @example\n * ```typescript\n * const entity = await content.get('01K75HQQXNTDG7BBP7PS9AWYAN');\n * const pinax = await content.getComponent(entity, 'pinax');\n * ```\n */\n async getComponent(entity: Entity, componentName: string): Promise<Blob | Buffer> {\n const cid = entity.components[componentName];\n if (!cid) {\n throw new ComponentNotFoundError(entity.pi, componentName);\n }\n return this.download(cid);\n }\n\n /**\n * Get the URL for a component from an entity.\n *\n * @param entity - Entity containing the component\n * @param componentName - Name of the component\n * @returns URL string\n * @throws ComponentNotFoundError if the component doesn't exist\n *\n * @example\n * ```typescript\n * const entity = await content.get('01K75HQQXNTDG7BBP7PS9AWYAN');\n * const imageUrl = content.getComponentUrl(entity, 'source');\n * // Use in img tag: <img src={imageUrl} />\n * ```\n */\n getComponentUrl(entity: Entity, componentName: string): string {\n const cid = entity.components[componentName];\n if (!cid) {\n throw new ComponentNotFoundError(entity.pi, componentName);\n }\n return this.getUrl(cid);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACOO,IAAM,eAAN,cAA2B,MAAM;AAAA,EACtC,YACE,SACO,OAAe,iBACf,SACP;AACA,UAAM,OAAO;AAHN;AACA;AAGP,SAAK,OAAO;AAAA,EACd;AACF;AAKO,IAAM,sBAAN,cAAkC,aAAa;AAAA,EACpD,YAAY,IAAY;AACtB,UAAM,qBAAqB,EAAE,IAAI,oBAAoB,EAAE,GAAG,CAAC;AAC3D,SAAK,OAAO;AAAA,EACd;AACF;AAKO,IAAM,uBAAN,cAAmC,aAAa;AAAA,EACrD,YAAY,KAAa;AACvB,UAAM,sBAAsB,GAAG,IAAI,qBAAqB,EAAE,IAAI,CAAC;AAC/D,SAAK,OAAO;AAAA,EACd;AACF;AAKO,IAAM,yBAAN,cAAqC,aAAa;AAAA,EACvD,YAAY,IAAY,eAAuB;AAC7C;AAAA,MACE,cAAc,aAAa,yBAAyB,EAAE;AAAA,MACtD;AAAA,MACA,EAAE,IAAI,cAAc;AAAA,IACtB;AACA,SAAK,OAAO;AAAA,EACd;AACF;AAKO,IAAM,uBAAN,cAAmC,aAAa;AAAA,EACrD,YAAY,IAAY,UAAkB;AACxC;A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