marcidb-client 0.6.2 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "marcidb-client",
3
3
  "type": "module",
4
- "version": "0.6.2",
4
+ "version": "0.7.0",
5
5
  "license": "MIT",
6
6
  "author": {
7
7
  "name": "den59k"
@@ -1,4 +1,15 @@
1
1
  declare function request(method: string, url: string, body?: any): Promise<any>;
2
+ /**
3
+ * A binary-eligible read over HTTP. Advertises `Accept: <binary>, json` plus the client's schema
4
+ * fingerprint (`X-Marci-Schema`) and inspects the *response* content-type:
5
+ * - binary (`application/x-marcidb-rows`) → the raw result buffer as a `Uint8Array`
6
+ * - anything else (JSON) → `{ json }` with the already-parsed result (the server declined binary —
7
+ * schema/shape mismatch — so it sent the normal JSON body; no second round-trip needed).
8
+ * A single request handles both outcomes; `run()` in the generated client branches on the return shape.
9
+ */
10
+ declare function requestBinary(url: string, body: any, schemaHash: string): Promise<Uint8Array | {
11
+ json: any;
12
+ }>;
2
13
  type FieldDesc = {
3
14
  n: string;
4
15
  k: "key" | "body" | "one" | "many";
@@ -15,4 +26,4 @@ declare function createDecoderRegistry(MODELS: Record<string, FieldDesc[]>): {
15
26
  decodeBuffer(decoder: (reader: any) => any, bytes: Uint8Array, many: boolean): any;
16
27
  };
17
28
  declare function encodeId(id: any): string;
18
- export { request, encodeId, createDecoderRegistry };
29
+ export { requestBinary, request, encodeId, createDecoderRegistry };
package/runtime/index.js CHANGED
@@ -11,6 +11,27 @@ async function request(method, url, body) {
11
11
  }
12
12
  return res.json();
13
13
  }
14
+ var BINARY_MEDIA_TYPE = "application/x-marcidb-rows";
15
+ async function requestBinary(url, body, schemaHash) {
16
+ const res = await fetch(url, {
17
+ method: "POST",
18
+ headers: {
19
+ "Content-Type": "application/json",
20
+ Accept: `${BINARY_MEDIA_TYPE}, application/json`,
21
+ "X-Marci-Schema": schemaHash
22
+ },
23
+ body: JSON.stringify(body ?? {})
24
+ });
25
+ if (!res.ok) {
26
+ const text = await res.text();
27
+ throw new Error(`MarciDB [${res.status}]: ${text}`);
28
+ }
29
+ const contentType = res.headers.get("content-type") ?? "";
30
+ if (contentType.includes(BINARY_MEDIA_TYPE)) {
31
+ return new Uint8Array(await res.arrayBuffer());
32
+ }
33
+ return { json: await res.json() };
34
+ }
14
35
  var BINARY_VERSION = 1;
15
36
  var AGG_KEYS = ["$count", "$sum", "$avg", "$min", "$max"];
16
37
 
@@ -204,6 +225,7 @@ function encodeId(id) {
204
225
  return String(id);
205
226
  }
206
227
  export {
228
+ requestBinary,
207
229
  request,
208
230
  encodeId,
209
231
  createDecoderRegistry