@polymathbase/polybase-client 0.8.2 → 0.8.3
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/README.md +17 -1
- package/dist/client.d.ts +18 -0
- package/dist/client.js +16 -2
- package/package.json +6 -1
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@ or a hosted service. Requires Node.js 24 or newer and a separately installed
|
|
|
6
6
|
Polybase console; version 0.8.2 is the release qualification target.
|
|
7
7
|
|
|
8
8
|
```sh
|
|
9
|
-
npm install @polymathbase/polybase-client@0.8.
|
|
9
|
+
npm install @polymathbase/polybase-client@0.8.3
|
|
10
10
|
```
|
|
11
11
|
|
|
12
12
|
Start `polybase-console /path/to/database 7340`, then:
|
|
@@ -47,9 +47,25 @@ the next page. On restart call `resume(savedToken)` and explicitly continue from
|
|
|
47
47
|
the last applied token. Delivery can repeat, tokens can expire, and the client
|
|
48
48
|
does not silently take a new snapshot. Streaming uses polling on consumer demand.
|
|
49
49
|
|
|
50
|
+
`search({kind: 'json', key_prefix: hex('tasks/'), path: ['status'], value: 'open'})`
|
|
51
|
+
and `search({kind: 'text', key_prefix: hex('notes/'), text: 'quick fox'})` call
|
|
52
|
+
`/api/search`: bounded current-head scalar equality or Unicode whole-word search,
|
|
53
|
+
without a subscription. This differs from `searchIndex`, which calls
|
|
54
|
+
`/api/index-search` for one named equality index, and from paginated typed queries.
|
|
55
|
+
|
|
56
|
+
`createIndex(name, prefix, path)` encodes its prefix as a JSON byte array because
|
|
57
|
+
the server's `index-create` route requires that format. Other key and
|
|
58
|
+
`key_prefix` wire fields use lowercase hex. The client handles this conversion.
|
|
59
|
+
|
|
60
|
+
Non-JSON HTTP errors retain their status in `ApiError.status` and response text
|
|
61
|
+
in `ApiError.body` (invalid UTF-8 is replaced). JSON error bodies stay parsed;
|
|
62
|
+
successful responses still require valid JSON.
|
|
63
|
+
|
|
50
64
|
The client supports explicit IPv4 loopback HTTP origins only, a 128 KiB request
|
|
51
65
|
bound, an 8 MiB response bound and a five-second request timeout. Keep the console
|
|
52
66
|
on loopback. Query optimizer estimates describe work units, not measured latency.
|
|
53
67
|
|
|
54
68
|
See the [Polybase documentation](https://base.polymathlabs.xyz/docs) for server
|
|
55
69
|
installation, limits and protocol guarantees. Client terms are in `LICENSE`.
|
|
70
|
+
The public [client source](https://github.com/ihabshea/polybase-downloads/tree/main/clients/typescript)
|
|
71
|
+
and release tags allow comparison with the registry archive; the engine is private.
|
package/dist/client.d.ts
CHANGED
|
@@ -37,6 +37,22 @@ export interface Row {
|
|
|
37
37
|
key: string;
|
|
38
38
|
value: string;
|
|
39
39
|
}
|
|
40
|
+
/** A bounded current-head search, separate from named indexes and query pages. */
|
|
41
|
+
export type SearchQuery = {
|
|
42
|
+
kind: "json";
|
|
43
|
+
key_prefix: string;
|
|
44
|
+
path: string[];
|
|
45
|
+
value: Scalar;
|
|
46
|
+
} | {
|
|
47
|
+
kind: "text";
|
|
48
|
+
key_prefix: string;
|
|
49
|
+
text: string;
|
|
50
|
+
};
|
|
51
|
+
export interface SearchResult {
|
|
52
|
+
position: string;
|
|
53
|
+
indexed: boolean;
|
|
54
|
+
rows: Row[];
|
|
55
|
+
}
|
|
40
56
|
export interface OptimizerAlternative {
|
|
41
57
|
strategy: "scan" | "index_lookup" | "index_intersection" | "index_union";
|
|
42
58
|
index_names: string[];
|
|
@@ -172,6 +188,7 @@ export declare class Client {
|
|
|
172
188
|
}>;
|
|
173
189
|
backup(directory: string): Promise<unknown>;
|
|
174
190
|
verifyBackup(directory: string): Promise<unknown>;
|
|
191
|
+
/** The index-create route requires prefix bytes as a JSON array, not hex. */
|
|
175
192
|
createIndex(name: string, prefix: Uint8Array | string, path: string[]): Promise<unknown>;
|
|
176
193
|
indexes(): Promise<unknown>;
|
|
177
194
|
searchIndex(name: string, value: Scalar): Promise<{
|
|
@@ -180,6 +197,7 @@ export declare class Client {
|
|
|
180
197
|
rows: Row[];
|
|
181
198
|
}>;
|
|
182
199
|
dropIndex(name: string): Promise<unknown>;
|
|
200
|
+
search(query: SearchQuery): Promise<SearchResult>;
|
|
183
201
|
compactionAdvice(retainCommits: bigint): Promise<unknown>;
|
|
184
202
|
/** Yield one complete page at a time. Persist rows and token before requesting another.
|
|
185
203
|
* A cancellation after a write is not an abort. No transport retry or implicit resnapshot. */
|
package/dist/client.js
CHANGED
|
@@ -34,8 +34,11 @@ export class Client {
|
|
|
34
34
|
throw new Error("request exceeds 128 KiB");
|
|
35
35
|
const response = await fetch(`${this.base}/api/${route}`, { method: "POST", headers: { "Content-Type": "application/json", Origin: this.base }, body: payload, signal: signal ? AbortSignal.any([signal, AbortSignal.timeout(5000)]) : AbortSignal.timeout(5000), redirect: "error" });
|
|
36
36
|
const reader = response.body?.getReader();
|
|
37
|
-
if (!reader)
|
|
37
|
+
if (!reader) {
|
|
38
|
+
if (!response.ok)
|
|
39
|
+
throw new ApiError(response.status, "");
|
|
38
40
|
throw new Error("missing response body");
|
|
41
|
+
}
|
|
39
42
|
const chunks = [];
|
|
40
43
|
let size = 0;
|
|
41
44
|
try {
|
|
@@ -59,7 +62,16 @@ export class Client {
|
|
|
59
62
|
all.set(chunk, offset);
|
|
60
63
|
offset += chunk.length;
|
|
61
64
|
}
|
|
62
|
-
const
|
|
65
|
+
const text = new TextDecoder("utf-8", { fatal: response.ok }).decode(all);
|
|
66
|
+
let result;
|
|
67
|
+
try {
|
|
68
|
+
result = JSON.parse(text);
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
if (response.ok)
|
|
72
|
+
throw error;
|
|
73
|
+
result = text;
|
|
74
|
+
}
|
|
63
75
|
if (!response.ok)
|
|
64
76
|
throw new ApiError(response.status, result);
|
|
65
77
|
return result;
|
|
@@ -74,10 +86,12 @@ export class Client {
|
|
|
74
86
|
snapshotAt(position) { return this.call("snapshot-at", { position: position.toString() }); }
|
|
75
87
|
backup(directory) { return this.call("backup", { directory }); }
|
|
76
88
|
verifyBackup(directory) { return this.call("verify-backup", { directory }); }
|
|
89
|
+
/** The index-create route requires prefix bytes as a JSON array, not hex. */
|
|
77
90
|
createIndex(name, prefix, path) { return this.call("index-create", { name, prefix: Array.from(typeof prefix === "string" ? new TextEncoder().encode(prefix) : prefix), path }); }
|
|
78
91
|
indexes() { return this.call("index-list", {}); }
|
|
79
92
|
searchIndex(name, value) { return this.call("index-search", { name, value }); }
|
|
80
93
|
dropIndex(name) { return this.call("index-drop", { name }); }
|
|
94
|
+
search(query) { return this.call("search", query); }
|
|
81
95
|
compactionAdvice(retainCommits) { return this.call("compaction-advice", { retain_commits: retainCommits.toString() }); }
|
|
82
96
|
/** Yield one complete page at a time. Persist rows and token before requesting another.
|
|
83
97
|
* A cancellation after a write is not an abort. No transport retry or implicit resnapshot. */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@polymathbase/polybase-client",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.3",
|
|
4
4
|
"description": "Typed loopback HTTP client for the local Polybase database",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -16,6 +16,11 @@
|
|
|
16
16
|
"sideEffects": false,
|
|
17
17
|
"author": "ihabshea",
|
|
18
18
|
"homepage": "https://base.polymathlabs.xyz/docs",
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/ihabshea/polybase-downloads.git",
|
|
22
|
+
"directory": "clients/typescript"
|
|
23
|
+
},
|
|
19
24
|
"keywords": ["polybase", "database", "client", "local"],
|
|
20
25
|
"publishConfig": {"access": "public", "registry": "https://registry.npmjs.org/"},
|
|
21
26
|
"engines": {"node": ">=24"},
|