@olivia-db/client 0.0.0-stage → 0.1.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.
@@ -0,0 +1,200 @@
1
+ /**
2
+ * Client for OliviaDB's network API (spec/oliviadb-api.openapi.json): agent memory and layer-1
3
+ * reads over HTTPS. Uses the platform's fetch (Node 18+, Deno, Bun, browsers, edge).
4
+ *
5
+ * const oliviadb = new OliviaDbClient({ baseUrl: "https://oliviadb.example:8443", token });
6
+ * await oliviadb.remember({ thread: "t1", text: "Ann works at Acme.", step_id: "s1",
7
+ * facts: [{ entity: "Ann", attr: "employer", value: "Acme" }] });
8
+ * const pack = await oliviadb.recall({ query: "Where does Ann work?", budget: 500 });
9
+ *
10
+ * Arguments and results are those of the MCP tools of the same name; failures throw
11
+ * OliviaDbError (an RFC 9457 problem document), retried when the server says retryable.
12
+ */
13
+ export type Json = Record<string, unknown>;
14
+ /**
15
+ * A transaction time, fact id or cursor. The server sends values above 2^53 - 1 as decimal
16
+ * strings (a JavaScript number would round them); pass them back as received, as a
17
+ * string or a bigint (sent as a string), never through Number().
18
+ */
19
+ export type U64 = number | string | bigint;
20
+ /** A U64 from a result as a bigint (exact). */
21
+ export declare function u64(v: U64): bigint;
22
+ export interface Fact {
23
+ entity: string;
24
+ attr: string;
25
+ value: string;
26
+ valid_from?: number;
27
+ }
28
+ export interface RememberArgs {
29
+ thread: string;
30
+ text: string;
31
+ step_id?: string;
32
+ entities?: string[];
33
+ facts?: Fact[];
34
+ durability?: "durable" | "session";
35
+ visibility?: "private" | "tenant";
36
+ }
37
+ export interface RecallArgs {
38
+ query: string;
39
+ budget?: number;
40
+ thread?: string;
41
+ valid_at?: U64;
42
+ known_at?: U64;
43
+ min_ts?: U64;
44
+ already?: string[];
45
+ }
46
+ export interface RecallItem {
47
+ ref: string;
48
+ kind: string;
49
+ tokens: number;
50
+ }
51
+ export interface RecallResult {
52
+ text: string;
53
+ pack: string;
54
+ tokens: number;
55
+ prefix_hash?: string;
56
+ items: RecallItem[];
57
+ }
58
+ export interface StateItem {
59
+ namespace: string[];
60
+ key: string;
61
+ value: unknown;
62
+ version: number;
63
+ created_ms: number;
64
+ updated_ms: number;
65
+ expires_ms?: number;
66
+ visibility: "private" | "tenant";
67
+ score?: number;
68
+ }
69
+ export interface WatchEvent {
70
+ id: string;
71
+ data: Json;
72
+ }
73
+ export interface ClientOptions {
74
+ /** The server, or every node of a high-availability pair: a refused connection or a
75
+ * retryable 503 moves the client to the node the answer names (`oliviadb-primary`), else
76
+ * to the next one. */
77
+ baseUrl: string | string[];
78
+ /** OAuth access token for this server. */
79
+ token?: string;
80
+ /** API key (development, Mem0-style clients). */
81
+ apiKey?: string;
82
+ retries?: number;
83
+ traceparent?: string;
84
+ fetch?: typeof fetch;
85
+ }
86
+ export declare class OliviaDbError extends Error {
87
+ readonly status: number;
88
+ readonly type: string;
89
+ readonly detail: string;
90
+ readonly retryable: boolean;
91
+ readonly problem: Json;
92
+ constructor(status: number, problem: Json);
93
+ }
94
+ export declare class OliviaDbClient {
95
+ private readonly bases;
96
+ private cur;
97
+ private readonly auth;
98
+ private readonly retries;
99
+ private readonly traceparent?;
100
+ private readonly f;
101
+ constructor(o: ClientOptions);
102
+ private headers;
103
+ private get base();
104
+ private next;
105
+ private send;
106
+ private json;
107
+ remember(a: RememberArgs): Promise<Json>;
108
+ recall(a: RecallArgs): Promise<RecallResult>;
109
+ expand(pack: string, ref: string): Promise<Json>;
110
+ feedback(a: {
111
+ pack: string;
112
+ used_refs?: string[];
113
+ answer?: string;
114
+ outcome?: "success" | "failure" | "unknown";
115
+ }): Promise<Json>;
116
+ assertFact(a: {
117
+ entity: string;
118
+ attr: string;
119
+ value: string;
120
+ evidence?: string;
121
+ expected_version?: U64;
122
+ }): Promise<Json>;
123
+ retract(fact_id: U64, reason?: string): Promise<Json>;
124
+ consolidate(cool_after_days?: number): Promise<Json>;
125
+ exportSubject(entity: string): Promise<Json>;
126
+ /** First call: {input_required, request_state}; after the confirmation, call again with request_state. */
127
+ eraseSubject(entity: string, request_state?: string): Promise<Json>;
128
+ path(p: string): Promise<Json>;
129
+ catalog(): Promise<Json>;
130
+ dataRecall(query: string, budget?: number, collection?: string): Promise<Json>;
131
+ statePut(a: {
132
+ namespace: string[];
133
+ key: string;
134
+ value: unknown;
135
+ ttl_ms?: number;
136
+ expected_version?: number;
137
+ index?: string[] | false;
138
+ vector?: number[];
139
+ visibility?: "private" | "tenant";
140
+ }): Promise<{
141
+ version: number;
142
+ }>;
143
+ /** Change one document atomically (an optimistic transaction on the server): inc, set, remove, merge. */
144
+ stateUpdate(a: {
145
+ namespace: string[];
146
+ key: string;
147
+ ops: Array<{
148
+ op: "inc" | "set" | "remove" | "merge";
149
+ path?: string;
150
+ by?: number;
151
+ value?: unknown;
152
+ }>;
153
+ create?: boolean;
154
+ visibility?: "private" | "tenant";
155
+ }): Promise<{
156
+ value: unknown;
157
+ version: number;
158
+ attempts: number;
159
+ pessimistic: boolean;
160
+ }>;
161
+ stateAppend(a: {
162
+ namespace: string[];
163
+ value: unknown;
164
+ ttl_ms?: number;
165
+ }): Promise<{
166
+ key: string;
167
+ version: number;
168
+ }>;
169
+ stateGet(namespace: string[], key: string): Promise<StateItem | null>;
170
+ stateDelete(namespace: string[], key?: string, prefix?: boolean): Promise<number>;
171
+ stateList(namespace: string[], o?: {
172
+ after?: string;
173
+ limit?: number;
174
+ reverse?: boolean;
175
+ }): Promise<StateItem[]>;
176
+ stateNamespaces(o?: {
177
+ prefix?: string[];
178
+ suffix?: string[];
179
+ max_depth?: number;
180
+ limit?: number;
181
+ offset?: number;
182
+ }): Promise<string[][]>;
183
+ stateSearch(namespace_prefix: string[], o?: {
184
+ query?: string;
185
+ vector?: number[];
186
+ filter?: Json;
187
+ limit?: number;
188
+ offset?: number;
189
+ }): Promise<StateItem[]>;
190
+ watch(w: {
191
+ entities?: string[];
192
+ paths?: string[];
193
+ }): Promise<string>;
194
+ watchRead(id: string): Promise<Json>;
195
+ /** Server-sent events of a watch; stop with the signal or by breaking the loop. */
196
+ events(id: string, o?: {
197
+ lastEventId?: string;
198
+ signal?: AbortSignal;
199
+ }): AsyncGenerator<WatchEvent>;
200
+ }
package/dist/index.js ADDED
@@ -0,0 +1,239 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ /**
3
+ * Client for OliviaDB's network API (spec/oliviadb-api.openapi.json): agent memory and layer-1
4
+ * reads over HTTPS. Uses the platform's fetch (Node 18+, Deno, Bun, browsers, edge).
5
+ *
6
+ * const oliviadb = new OliviaDbClient({ baseUrl: "https://oliviadb.example:8443", token });
7
+ * await oliviadb.remember({ thread: "t1", text: "Ann works at Acme.", step_id: "s1",
8
+ * facts: [{ entity: "Ann", attr: "employer", value: "Acme" }] });
9
+ * const pack = await oliviadb.recall({ query: "Where does Ann work?", budget: 500 });
10
+ *
11
+ * Arguments and results are those of the MCP tools of the same name; failures throw
12
+ * OliviaDbError (an RFC 9457 problem document), retried when the server says retryable.
13
+ */
14
+ /** A U64 from a result as a bigint (exact). */
15
+ export function u64(v) {
16
+ return typeof v === "bigint" ? v : BigInt(v);
17
+ }
18
+ export class OliviaDbError extends Error {
19
+ status;
20
+ type;
21
+ detail;
22
+ retryable;
23
+ problem;
24
+ constructor(status, problem) {
25
+ const text = (v) => (typeof v === "string" ? v : "");
26
+ super(`${status} ${text(problem.type)}: ${text(problem.detail)}`);
27
+ this.status = status;
28
+ this.problem = problem;
29
+ this.type = text(problem.type);
30
+ this.detail = text(problem.detail);
31
+ this.retryable = problem.retryable === true;
32
+ }
33
+ }
34
+ function clean(o) {
35
+ return Object.fromEntries(Object.entries(o).filter(([, v]) => v !== undefined));
36
+ }
37
+ export class OliviaDbClient {
38
+ bases;
39
+ cur = 0;
40
+ auth;
41
+ retries;
42
+ traceparent;
43
+ f;
44
+ constructor(o) {
45
+ if ((o.token === undefined) === (o.apiKey === undefined))
46
+ throw new Error("give either token or apiKey");
47
+ this.bases = (Array.isArray(o.baseUrl) ? o.baseUrl : [o.baseUrl]).map((u) => u.replace(/\/+$/, ""));
48
+ if (this.bases.length === 0)
49
+ throw new Error("no base URL");
50
+ this.auth = o.token !== undefined ? `Bearer ${o.token}` : `Token ${o.apiKey}`;
51
+ this.retries = o.retries ?? 3;
52
+ this.traceparent = o.traceparent;
53
+ this.f = o.fetch ?? fetch;
54
+ }
55
+ headers(extra) {
56
+ const h = { authorization: this.auth, accept: "application/json", ...extra };
57
+ if (this.traceparent)
58
+ h.traceparent = this.traceparent;
59
+ return h;
60
+ }
61
+ get base() {
62
+ return this.bases[this.cur];
63
+ }
64
+ next(primary) {
65
+ const p = primary?.replace(/\/+$/, "");
66
+ const i = p ? this.bases.indexOf(p) : -1;
67
+ this.cur = i >= 0 ? i : (this.cur + 1) % this.bases.length;
68
+ }
69
+ async send(method, path, body, extra) {
70
+ const n = this.bases.length;
71
+ // With several nodes every one gets its turn before the retries run out.
72
+ const budget = this.retries * n;
73
+ for (let attempt = 0;;) {
74
+ const h = this.headers(body ? { "content-type": "application/json", ...extra } : extra);
75
+ let r;
76
+ try {
77
+ r = await this.f(this.base + path, {
78
+ method,
79
+ headers: h,
80
+ body: body
81
+ ? JSON.stringify(clean(body), (_k, v) => (typeof v === "bigint" ? v.toString() : v))
82
+ : undefined,
83
+ });
84
+ }
85
+ catch (err) {
86
+ // A node that is down: the next one (only when there is another).
87
+ if (n === 1 || attempt >= budget)
88
+ throw err;
89
+ attempt++;
90
+ this.next(null);
91
+ if (attempt % n === 0)
92
+ await new Promise((res) => setTimeout(res, 200 * attempt));
93
+ continue;
94
+ }
95
+ if (r.ok)
96
+ return r;
97
+ const text = await r.text();
98
+ let p;
99
+ try {
100
+ p = JSON.parse(text);
101
+ }
102
+ catch {
103
+ p = { type: "about:blank", detail: text, retryable: false };
104
+ }
105
+ const e = new OliviaDbError(r.status, p);
106
+ if (e.retryable && attempt < budget) {
107
+ attempt++;
108
+ this.next(r.headers.get("oliviadb-primary"));
109
+ // A move to another node is tried at once; the same node after its Retry-After.
110
+ if (n === 1 || attempt % n === 0) {
111
+ await new Promise((res) => setTimeout(res, 1000 * Number(r.headers.get("retry-after") ?? 1) * Math.max(1, Math.floor(attempt / n))));
112
+ }
113
+ continue;
114
+ }
115
+ throw e;
116
+ }
117
+ }
118
+ async json(method, path, body, extra) {
119
+ const r = await this.send(method, path, body, extra);
120
+ const t = await r.text();
121
+ return (t ? JSON.parse(t) : {});
122
+ }
123
+ remember(a) {
124
+ return this.json("POST", "/v1/memory/remember", a);
125
+ }
126
+ recall(a) {
127
+ return this.json("POST", "/v1/memory/recall", a);
128
+ }
129
+ expand(pack, ref) {
130
+ return this.json("POST", "/v1/memory/expand", { pack, ref });
131
+ }
132
+ feedback(a) {
133
+ return this.json("POST", "/v1/memory/feedback", a);
134
+ }
135
+ assertFact(a) {
136
+ return this.json("POST", "/v1/memory/facts", a);
137
+ }
138
+ retract(fact_id, reason) {
139
+ return this.json("POST", "/v1/memory/facts/retract", { fact_id, reason });
140
+ }
141
+ consolidate(cool_after_days) {
142
+ return this.json("POST", "/v1/memory/consolidate", { cool_after_days });
143
+ }
144
+ exportSubject(entity) {
145
+ return this.json("POST", "/v1/admin/subjects/export", { entity });
146
+ }
147
+ /** First call: {input_required, request_state}; after the confirmation, call again with request_state. */
148
+ eraseSubject(entity, request_state) {
149
+ return this.json("POST", "/v1/admin/subjects/erase", { entity, request_state });
150
+ }
151
+ path(p) {
152
+ return this.json("GET", `/v1/path?p=${encodeURIComponent(p)}`);
153
+ }
154
+ catalog() {
155
+ return this.json("GET", "/v1/data/catalog");
156
+ }
157
+ dataRecall(query, budget = 1000, collection) {
158
+ return this.json("POST", "/v1/data/recall", { query, budget, collection });
159
+ }
160
+ // ---- agent state (namespaced documents) ----
161
+ statePut(a) {
162
+ return this.json("POST", "/v1/state/put", a);
163
+ }
164
+ /** Change one document atomically (an optimistic transaction on the server): inc, set, remove, merge. */
165
+ stateUpdate(a) {
166
+ return this.json("POST", "/v1/state/update", a);
167
+ }
168
+ stateAppend(a) {
169
+ return this.json("POST", "/v1/state/append", a);
170
+ }
171
+ async stateGet(namespace, key) {
172
+ try {
173
+ return await this.json("POST", "/v1/state/get", { namespace, key });
174
+ }
175
+ catch (e) {
176
+ if (e instanceof OliviaDbError && e.status === 404)
177
+ return null;
178
+ throw e;
179
+ }
180
+ }
181
+ async stateDelete(namespace, key, prefix = false) {
182
+ return (await this.json("POST", "/v1/state/delete", { namespace, key, prefix: prefix || undefined })).deleted;
183
+ }
184
+ async stateList(namespace, o = {}) {
185
+ return (await this.json("POST", "/v1/state/list", { namespace, ...o })).items;
186
+ }
187
+ async stateNamespaces(o = {}) {
188
+ return (await this.json("POST", "/v1/state/namespaces", o)).namespaces;
189
+ }
190
+ async stateSearch(namespace_prefix, o = {}) {
191
+ return (await this.json("POST", "/v1/state/search", { namespace_prefix, ...o })).items;
192
+ }
193
+ async watch(w) {
194
+ return (await this.json("POST", "/v1/watches", w)).id;
195
+ }
196
+ watchRead(id) {
197
+ return this.json("GET", `/v1/watches/${encodeURIComponent(id)}`);
198
+ }
199
+ /** Server-sent events of a watch; stop with the signal or by breaking the loop. */
200
+ async *events(id, o = {}) {
201
+ const extra = { accept: "text/event-stream" };
202
+ if (o.lastEventId !== undefined)
203
+ extra["last-event-id"] = o.lastEventId;
204
+ const r = await this.f(this.base + `/v1/watches/${encodeURIComponent(id)}/events`, {
205
+ headers: this.headers(extra),
206
+ signal: o.signal,
207
+ });
208
+ if (!r.ok || !r.body)
209
+ throw new OliviaDbError(r.status, (await r.json().catch(() => ({}))));
210
+ const reader = r.body.pipeThrough(new TextDecoderStream()).getReader();
211
+ let buf = "";
212
+ try {
213
+ for (;;) {
214
+ const { value, done } = await reader.read();
215
+ if (done)
216
+ return;
217
+ buf += value;
218
+ let i;
219
+ while ((i = buf.indexOf("\n\n")) >= 0) {
220
+ const block = buf.slice(0, i);
221
+ buf = buf.slice(i + 2);
222
+ let eid = "";
223
+ const data = [];
224
+ for (const line of block.split("\n")) {
225
+ if (line.startsWith("id:"))
226
+ eid = line.slice(3).trim();
227
+ else if (line.startsWith("data:"))
228
+ data.push(line.slice(5).trim());
229
+ }
230
+ if (data.length)
231
+ yield { id: eid, data: JSON.parse(data.join("\n")) };
232
+ }
233
+ }
234
+ }
235
+ finally {
236
+ await reader.cancel().catch(() => { });
237
+ }
238
+ }
239
+ }
@@ -0,0 +1,216 @@
1
+ import * as tls from "node:tls";
2
+ import { type Json } from "./index.ts";
3
+ /** A frame the server sent that this client cannot read (a protocol error). */
4
+ export declare class NativeProtocolError extends Error {
5
+ }
6
+ /** A logical type of a field or key part (`schema.md` 4.1). */
7
+ export type Type = {
8
+ kind: "string" | "date" | "timestamp" | "bool" | "float64" | "text" | "ref";
9
+ } | {
10
+ kind: "bytes";
11
+ length: number;
12
+ } | {
13
+ kind: "int";
14
+ signed: boolean;
15
+ } | {
16
+ kind: "decimal";
17
+ scale: number;
18
+ } | {
19
+ kind: "enum";
20
+ members: Array<[string, string]>;
21
+ };
22
+ export declare function parseType(t: string): Type;
23
+ /** A field of a descriptor: where it lies in a node's data and whether the caller sees it. */
24
+ export interface Field {
25
+ number: number;
26
+ name: string;
27
+ type: Type;
28
+ /** In the tail (`offset` is then the index among the tail fields). */
29
+ tail: boolean;
30
+ offset: number;
31
+ length: number;
32
+ scale: number;
33
+ /** 0 hidden, 1 shown, 2 masked (spec section 5). */
34
+ shown: number;
35
+ /** A variant case's discriminator and values, when the field belongs to one. */
36
+ caseOf?: {
37
+ disc: number;
38
+ values: string[];
39
+ };
40
+ }
41
+ export interface KeyPart {
42
+ name: string;
43
+ type: Type;
44
+ descending: boolean;
45
+ }
46
+ /** A type descriptor (spec section 5). */
47
+ export declare class Desc {
48
+ readonly strs: Array<[number, number]>;
49
+ readonly layout: string;
50
+ readonly typePath: string;
51
+ readonly bucket: number;
52
+ readonly ordinal: boolean;
53
+ readonly key: KeyPart[];
54
+ readonly fixed: number;
55
+ readonly fields: Field[];
56
+ readonly defaults: Array<[Field, Uint8Array]>;
57
+ readonly children: Map<number, string>;
58
+ constructor(layout: string, typePath: string, bucket: number, ordinal: boolean, key: KeyPart[], fixed: number, fields: Field[], defaults: Array<[Field, Uint8Array]>, children: Map<number, string>);
59
+ /** The node type's name (the last segment of its type path). */
60
+ get typeName(): string;
61
+ /** The aggregate's name. */
62
+ get aggregate(): string;
63
+ /** A field by name, to read it from nodes of this descriptor. */
64
+ field(name: string): Field | undefined;
65
+ }
66
+ type Descs = ReadonlyMap<number, Desc>;
67
+ /** A decimal's text with `scale` digits after the point. */
68
+ export declare function decimalText(unscaled: bigint, scale: number): string;
69
+ /** `YYYY-MM-DD` of days since 1970-01-01. */
70
+ export declare function dateText(days: number): string;
71
+ /** `YYYY-MM-DDTHH:MM:SS.ffffffZ` of microseconds since the epoch. */
72
+ export declare function timestampText(us: bigint): string;
73
+ /** A key part's value. */
74
+ export type KeyValue = bigint | number | boolean | Uint8Array | string;
75
+ /** One node of a result: its bytes are views into the frame it came in. */
76
+ export declare class Node {
77
+ readonly desc: Desc;
78
+ readonly depth: number;
79
+ /** The node's own key component, as stored (`path-keys.md`). */
80
+ readonly key: Uint8Array;
81
+ /** The value as received: layout bytes, with the fixed strings trimmed (`trim`). */
82
+ private readonly data;
83
+ /** Per fixed string: layout offset, n, offset in data, trimmed length. */
84
+ private readonly trim;
85
+ private readonly masks;
86
+ /** The granted child listings (a tree read), by type name. */
87
+ readonly lists: string[] | undefined;
88
+ /** LOOKUP: the indexed node's path. */
89
+ readonly hit: string | undefined;
90
+ /** SEARCH: the parent path and the score. */
91
+ readonly parent: string | undefined;
92
+ readonly score: number | undefined;
93
+ constructor(desc: Desc, depth: number, key: Uint8Array, data: Uint8Array, trim: Array<[number, number, number, number]>, masks: Array<[number, string]>, lists: string[] | undefined, hit: string | undefined, parent: string | undefined, score: number | undefined);
94
+ private span;
95
+ private wireAt;
96
+ private tails;
97
+ private present;
98
+ private bytesOf;
99
+ /** A string, text, enum member or reference field (fixed strings without their padding);
100
+ * a masked field's masked text. Undefined: hidden, or not in this node's variant case. */
101
+ str(f: Field): string | undefined;
102
+ /** An integer field. */
103
+ int(f: Field): bigint | undefined;
104
+ /** A decimal field: the unscaled value and the scale. */
105
+ decimal(f: Field): {
106
+ unscaled: bigint;
107
+ scale: number;
108
+ } | undefined;
109
+ /** A timestamp field: microseconds since 1970-01-01T00:00:00Z. */
110
+ timestamp(f: Field): bigint | undefined;
111
+ /** A date field: days since 1970-01-01. */
112
+ date(f: Field): number | undefined;
113
+ /** A field's value as the HTTP API's JSON shows it. */
114
+ json(f: Field): unknown;
115
+ /** The node's key parts, decoded from its component (`path-keys.md`, format 2). */
116
+ keyParts(): KeyValue[];
117
+ /** The ordinal of a twin, as hexadecimal (`~` in paths). */
118
+ ordinal(): string | undefined;
119
+ /** The node's level as a path segment (`key,key~ordinal`, percent-encoded). */
120
+ segment(): string;
121
+ private keyJson;
122
+ /** The node as the HTTP API's JSON shows it, under `parent` (a path, "" for a root). */
123
+ toJson(parent: string, defaults: boolean): Json;
124
+ }
125
+ /** An entry of a LOOKUP answer: a node, or a record whose root the profile does not show. */
126
+ export type Entry = {
127
+ node: Node;
128
+ } | {
129
+ path: string;
130
+ hitPath: string;
131
+ };
132
+ /** Where a value's trimmed fixed strings are (spec section 6.3). */
133
+ export declare function trimmed(desc: Desc, data: Uint8Array): Array<[number, number, number, number]>;
134
+ /** A read's answer: its frames as received, nodes read from them on demand. */
135
+ export declare class Rows {
136
+ frames: Array<[Uint8Array, Descs]>;
137
+ version: bigint | undefined;
138
+ /** A listing page's `after` for the next page. */
139
+ next: string | undefined;
140
+ /** The path of the depth-0 nodes' parent. */
141
+ base: string;
142
+ appliedThrough: {
143
+ through: bigint;
144
+ caughtUp: boolean;
145
+ } | undefined;
146
+ tokens: bigint | undefined;
147
+ /** Every entry (node, or LOOKUP's path-only entry) in order. */
148
+ entries(): Generator<Entry>;
149
+ /** The nodes, in order (pre-order for a tree). */
150
+ nodes(): Node[];
151
+ /** The answer as the HTTP API's JSON for a GET of a node (`listing` false) or a listing. */
152
+ toJson(listing: boolean): Json;
153
+ }
154
+ /** TLS settings of `NativeClient.connectTls`, besides the options of `node:tls`. */
155
+ export interface TlsOptions extends tls.ConnectionOptions {
156
+ /** Trust the certificates of this PEM file instead of the platform's roots. */
157
+ caFile?: string;
158
+ /** The name to verify in the server's certificate, when it is not the host connected to. */
159
+ serverName?: string;
160
+ }
161
+ /** A native-protocol connection. Concurrent requests share it, each on its own stream. */
162
+ export declare class NativeClient {
163
+ private streams;
164
+ private nextStream;
165
+ private descs;
166
+ private buf;
167
+ private closedWhy;
168
+ private handshake;
169
+ private readonly sock;
170
+ private constructor();
171
+ /** Connects over plain TCP (the server serves plain text on loopback only, unless configured
172
+ * otherwise) and authenticates with `scheme` (`token` or `bearer`) and the credential the
173
+ * HTTP Authorization header would carry. */
174
+ static connectTcp(host: string, port: number, scheme: string, credential: string): Promise<NativeClient>;
175
+ /** Connects over TLS (spec `native-protocol.md` section 1): TLS from the first byte, ALPN
176
+ * `oliviadb/1` offered and required, the certificate chain verified against the platform's
177
+ * roots (`tls.getCACertificates("system")`, Node 22.15 and later; earlier Node versions use
178
+ * Node's own roots) or `options.caFile` / `options.ca`, and the server name
179
+ * (`options.serverName`, else `host`) verified against the certificate. Other `options` are
180
+ * passed to `node:tls`. */
181
+ static connectTls(host: string, port: number, scheme: string, credential: string, options?: TlsOptions): Promise<NativeClient>;
182
+ /** Connects over a Unix socket. */
183
+ static connectUnix(path: string, scheme: string, credential: string): Promise<NativeClient>;
184
+ private static start;
185
+ private onData;
186
+ /** Frames to their streams, descriptors kept in arrival order. */
187
+ private dispatch;
188
+ private onClose;
189
+ private send;
190
+ private rows;
191
+ /** `GET /v1/aggregates/{path}` (a node, `tree=true` with `each`, or a listing page). */
192
+ get(path: string, params?: Record<string, string>): Promise<Rows>;
193
+ /** `GET /v1/lookup/{index}`. */
194
+ lookup(index: string, params?: Record<string, string>): Promise<Rows>;
195
+ /** `POST /v1/search/{aggregate}` with the HTTP body. */
196
+ search(aggregate: string, body: Json): Promise<Rows>;
197
+ private json;
198
+ /** `POST /v1/txn`: the HTTP route's status and answer. */
199
+ txn(body: Json): Promise<[number, Json]>;
200
+ /** `POST`, `PATCH` or `DELETE /v1/aggregates/{path}`: the status and the JSON answer. */
201
+ write(method: string, path: string, body: Json): Promise<[number, Json]>;
202
+ /** The change stream of native aggregates under `paths`, from a position (`start`, `now` or
203
+ * a record's): its records as they come, until the iteration stops (the stream is then
204
+ * cancelled). */
205
+ changes(paths: string[], from: string): AsyncGenerator<Change>;
206
+ close(): void;
207
+ }
208
+ /** One change record. */
209
+ export declare class Change {
210
+ private readonly body;
211
+ private readonly descs;
212
+ constructor(body: Uint8Array, descs: Descs);
213
+ /** The record as the HTTP change stream's JSON object. */
214
+ toJson(): Json;
215
+ }
216
+ export {};