@seed-hypermedia/client 0.0.94 → 0.0.96
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/{chunk-HQP7SFVC.mjs → chunk-5YWGB4XU.mjs} +54 -2
- package/dist/{chunk-HAHROSQH.mjs → chunk-6JS7R6XP.mjs} +1 -1
- package/dist/{chunk-JSNDXUPG.mjs → chunk-FFH7G6KW.mjs} +2 -1
- package/dist/{chunk-BBJCA2PR.mjs → chunk-OHN5ILTT.mjs} +1 -1
- package/dist/client.d.ts +16 -0
- package/dist/client.mjs +1 -1
- package/dist/index.mjs +2 -2
- package/dist/resource-read.mjs +2 -2
- package/dist/schema-engine.mjs +1 -1
- package/dist/schema-resolve.mjs +2 -2
- package/dist/schema-subtypes.mjs +2 -2
- package/dist/signed-blob.mjs +1 -1
- package/package.json +1 -1
|
@@ -19,6 +19,9 @@ import {
|
|
|
19
19
|
|
|
20
20
|
// src/client.ts
|
|
21
21
|
import { encode as cborEncode } from "@ipld/dag-cbor";
|
|
22
|
+
import { blake2b } from "@noble/hashes/blake2.js";
|
|
23
|
+
import { CID } from "multiformats/cid";
|
|
24
|
+
import * as Digest from "multiformats/hashes/digest";
|
|
22
25
|
import { deserialize } from "superjson";
|
|
23
26
|
var PRIMITIVE_VALUE_KEY = "__value";
|
|
24
27
|
function serializeQueryString(data, _schema) {
|
|
@@ -62,6 +65,8 @@ function deserializeQueryString(queryString, schema) {
|
|
|
62
65
|
}
|
|
63
66
|
return schema.parse(result);
|
|
64
67
|
}
|
|
68
|
+
var DAG_CBOR_CODEC = 113;
|
|
69
|
+
var BLAKE2B_256_CODE = 45600;
|
|
65
70
|
var QUERY_PARAM_SERIALIZERS = {
|
|
66
71
|
Account: (input) => ({
|
|
67
72
|
id: input
|
|
@@ -175,8 +180,53 @@ function createSeedClient(baseUrl, options) {
|
|
|
175
180
|
const deserialized = rawJson && typeof rawJson === "object" && !Array.isArray(rawJson) && "json" in rawJson ? deserialize(rawJson) : rawJson;
|
|
176
181
|
return requestSchema.shape.output.parse(deserialized);
|
|
177
182
|
}
|
|
178
|
-
function
|
|
179
|
-
return
|
|
183
|
+
function daemonBlobCid(data) {
|
|
184
|
+
return CID.createV1(DAG_CBOR_CODEC, Digest.create(BLAKE2B_256_CODE, blake2b(data, { dkLen: 32 }))).toString();
|
|
185
|
+
}
|
|
186
|
+
async function putBlob(blob, options2) {
|
|
187
|
+
const url = `${normalizedBaseUrl}/ipfs/${blob.cid}`;
|
|
188
|
+
const defaultHeaders = await getDefaultHeaders();
|
|
189
|
+
let response;
|
|
190
|
+
try {
|
|
191
|
+
response = await fetchFn(url, {
|
|
192
|
+
method: "POST",
|
|
193
|
+
headers: { "Content-Type": "application/octet-stream", ...defaultHeaders },
|
|
194
|
+
body: new Uint8Array(blob.data),
|
|
195
|
+
signal: options2 == null ? void 0 : options2.signal
|
|
196
|
+
});
|
|
197
|
+
} catch (err) {
|
|
198
|
+
if (isAbortError(err)) throw err;
|
|
199
|
+
throw new SeedNetworkError(
|
|
200
|
+
`Network error storing blob ${blob.cid}: ${err instanceof Error ? err.message : String(err)}`,
|
|
201
|
+
{ cause: err }
|
|
202
|
+
);
|
|
203
|
+
}
|
|
204
|
+
if (!response.ok) {
|
|
205
|
+
let errorBody;
|
|
206
|
+
try {
|
|
207
|
+
errorBody = await response.text();
|
|
208
|
+
} catch {
|
|
209
|
+
}
|
|
210
|
+
throw new SeedClientError(
|
|
211
|
+
formatHTTPErrorMessage(`PutBlob ${blob.cid}`, response.status, response.statusText, errorBody),
|
|
212
|
+
response.status,
|
|
213
|
+
errorBody
|
|
214
|
+
);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
async function publish(input) {
|
|
218
|
+
try {
|
|
219
|
+
return await request("PublishBlobs", input);
|
|
220
|
+
} catch (err) {
|
|
221
|
+
if (!(err instanceof SeedClientError && err.status === 413)) throw err;
|
|
222
|
+
const cids = [];
|
|
223
|
+
for (const blob of input.blobs) {
|
|
224
|
+
const cid = blob.cid || daemonBlobCid(blob.data);
|
|
225
|
+
await putBlob({ cid, data: blob.data });
|
|
226
|
+
cids.push(cid);
|
|
227
|
+
}
|
|
228
|
+
return { cids };
|
|
229
|
+
}
|
|
180
230
|
}
|
|
181
231
|
async function publishDocument(input, signer) {
|
|
182
232
|
if (!input.genesis && !input.baseVersion && !input.path) {
|
|
@@ -265,6 +315,8 @@ function createSeedClient(baseUrl, options) {
|
|
|
265
315
|
request,
|
|
266
316
|
publish,
|
|
267
317
|
publishBlobs: publish,
|
|
318
|
+
putBlob,
|
|
319
|
+
daemonBlobCid,
|
|
268
320
|
publishDocument
|
|
269
321
|
};
|
|
270
322
|
}
|
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
|
|
7
7
|
// src/schema-engine.ts
|
|
8
8
|
var LIBRARY_AUTHORITY = "hyper.media";
|
|
9
|
+
var LEGACY_LIBRARY_AUTHORITIES = /* @__PURE__ */ new Set(["seed.hyper.media", "example.com"]);
|
|
9
10
|
var KINDS = ["null", "boolean", "integer", "float", "string", "bytes", "list", "map", "struct", "link"];
|
|
10
11
|
var LIBRARY_CORE = new Set(
|
|
11
12
|
[
|
|
@@ -34,7 +35,7 @@ function refToName(ref) {
|
|
|
34
35
|
const m = /^hm:\/\/([^/]+)\/(.+)$/.exec(ref);
|
|
35
36
|
if (!m) return ref.replace(/\.schema\.json$|\.json$/, "");
|
|
36
37
|
const [, auth = "", name = ""] = m;
|
|
37
|
-
return auth === LIBRARY_AUTHORITY ? name : ref;
|
|
38
|
+
return auth === LIBRARY_AUTHORITY || LEGACY_LIBRARY_AUTHORITIES.has(auth) ? name : ref;
|
|
38
39
|
}
|
|
39
40
|
function nameToUrl(name) {
|
|
40
41
|
return `hm://${LIBRARY_AUTHORITY}/${name}`;
|
package/dist/client.d.ts
CHANGED
|
@@ -39,8 +39,24 @@ export type SeedClient = {
|
|
|
39
39
|
}>['input'], options?: SeedClientRequestOptions): Promise<Extract<HMRequest, {
|
|
40
40
|
key: K;
|
|
41
41
|
}>['output']>;
|
|
42
|
+
/**
|
|
43
|
+
* Store blobs. Goes through the site's `PublishBlobs` API; when the site refuses the request
|
|
44
|
+
* body as too large (413 — a site may cap its API bodies at a few KB) and every blob names its
|
|
45
|
+
* CID, the blobs are stored one per request through `putBlob` instead, and the result is the same.
|
|
46
|
+
*/
|
|
42
47
|
publish(input: PublishBlobsRequest['input']): Promise<PublishBlobsRequest['output']>;
|
|
43
48
|
publishBlobs(input: PublishBlobsRequest['input']): Promise<PublishBlobsRequest['output']>;
|
|
49
|
+
/**
|
|
50
|
+
* Store one blob through the daemon's raw blob endpoint, `POST /ipfs/<cid>`, which every Seed
|
|
51
|
+
* site routes to its daemon with a file-sized body limit. The daemon recomputes the hash and
|
|
52
|
+
* refuses bytes that do not match the CID; a stored blob is indexed like one from `PublishBlobs`.
|
|
53
|
+
*/
|
|
54
|
+
putBlob(blob: {
|
|
55
|
+
cid: string;
|
|
56
|
+
data: Uint8Array;
|
|
57
|
+
}, options?: SeedClientRequestOptions): Promise<void>;
|
|
58
|
+
/** The CID the daemon assigns a DAG-CBOR blob published without one (blake2b-256). */
|
|
59
|
+
daemonBlobCid(data: Uint8Array): string;
|
|
44
60
|
publishDocument(input: PublishDocumentInput, signer: AnySigner): Promise<PublishDocumentResult>;
|
|
45
61
|
baseUrl: string;
|
|
46
62
|
};
|
package/dist/client.mjs
CHANGED
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
resolveIdWithClient
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-6JS7R6XP.mjs";
|
|
4
4
|
import {
|
|
5
5
|
annotationContains,
|
|
6
6
|
hmBlockToEditorBlock,
|
|
@@ -49,7 +49,7 @@ import {
|
|
|
49
49
|
} from "./chunk-X3636TQF.mjs";
|
|
50
50
|
import {
|
|
51
51
|
createSeedClient
|
|
52
|
-
} from "./chunk-
|
|
52
|
+
} from "./chunk-5YWGB4XU.mjs";
|
|
53
53
|
import {
|
|
54
54
|
SeedClientError,
|
|
55
55
|
SeedNetworkError,
|
package/dist/resource-read.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
resolveIdWithClient
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-6JS7R6XP.mjs";
|
|
4
4
|
import "./chunk-X3636TQF.mjs";
|
|
5
|
-
import "./chunk-
|
|
5
|
+
import "./chunk-5YWGB4XU.mjs";
|
|
6
6
|
import "./chunk-CBELM7KX.mjs";
|
|
7
7
|
import "./chunk-O5MHN2EO.mjs";
|
|
8
8
|
import "./chunk-PJ2RFT5A.mjs";
|
package/dist/schema-engine.mjs
CHANGED
package/dist/schema-resolve.mjs
CHANGED
|
@@ -17,8 +17,8 @@ import {
|
|
|
17
17
|
resolveSchemaRef,
|
|
18
18
|
schemaDefinitionCid,
|
|
19
19
|
withoutSchemaLink
|
|
20
|
-
} from "./chunk-
|
|
21
|
-
import "./chunk-
|
|
20
|
+
} from "./chunk-OHN5ILTT.mjs";
|
|
21
|
+
import "./chunk-FFH7G6KW.mjs";
|
|
22
22
|
import "./chunk-ZWKMAGDU.mjs";
|
|
23
23
|
import "./chunk-VWSAFDOL.mjs";
|
|
24
24
|
import "./chunk-3NYKSLJ4.mjs";
|
package/dist/schema-subtypes.mjs
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
classifyRef
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-OHN5ILTT.mjs";
|
|
4
4
|
import {
|
|
5
5
|
kindOf,
|
|
6
6
|
nameForCid,
|
|
7
7
|
nameToUrl,
|
|
8
8
|
schemaCid
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-FFH7G6KW.mjs";
|
|
10
10
|
import {
|
|
11
11
|
HM_SCHEMAS
|
|
12
12
|
} from "./chunk-ZWKMAGDU.mjs";
|
package/dist/signed-blob.mjs
CHANGED