marcidb-client 0.6.1 → 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.
- package/bin/marci-generate-darwin-arm64 +0 -0
- package/bin/marci-generate-linux-x64 +0 -0
- package/bin/marci-generate-win32-x64.exe +0 -0
- package/bin/marci-migrate-darwin-arm64 +0 -0
- package/bin/marci-migrate-linux-x64 +0 -0
- package/bin/marci-migrate-win32-x64.exe +0 -0
- package/client/index.d.ts +2 -0
- package/client/index.js +5 -0
- package/package.json +1 -1
- package/runtime/index.d.ts +12 -1
- package/runtime/index.js +22 -0
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/client/index.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
// Re-export the generated client (default location: node_modules/.marcidb/client). A relative path is
|
|
2
|
+
// used deliberately: the bare specifier `.marcidb/client` is an INVALID ESM specifier on Node
|
|
3
|
+
// (ERR_INVALID_MODULE_SPECIFIER — it starts with "." but not "./"). A `../` relative path is valid on
|
|
4
|
+
// Node and Bun, and resolves the runtime-generated dir without needing it installed as a package.
|
|
5
|
+
export * from '../../.marcidb/client/index.js'
|
package/package.json
CHANGED
package/runtime/index.d.ts
CHANGED
|
@@ -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
|