@bzync/nextsql 0.0.1
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/LICENSE +21 -0
- package/README.md +36 -0
- package/client-encryption.js +705 -0
- package/nextsql.d.ts +353 -0
- package/nextsql.js +2238 -0
- package/package.json +43 -0
package/nextsql.d.ts
ADDED
|
@@ -0,0 +1,353 @@
|
|
|
1
|
+
// Public TypeScript surface for the official NextSQL Node.js driver.
|
|
2
|
+
//
|
|
3
|
+
// Self-contained COPY of drivers/js/types.d.ts. It must NOT import from ../js:
|
|
4
|
+
// the package tarball contains only the files in package.json "files", so a
|
|
5
|
+
// parent-directory import resolves to nothing for an installed consumer. The
|
|
6
|
+
// parity test in the driver test suite fails if this drifts from the canonical
|
|
7
|
+
// shared file.
|
|
8
|
+
|
|
9
|
+
export interface TLSOptions {
|
|
10
|
+
/** PEM or DER trust material. */
|
|
11
|
+
ca?: string | Uint8Array;
|
|
12
|
+
/** SNI and certificate hostname (may differ from the TCP host). */
|
|
13
|
+
servername?: string;
|
|
14
|
+
/** Explicitly disable verification. Remote production must not set this. */
|
|
15
|
+
rejectUnauthorized?: boolean;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** How a read observes replicated state. Values match the wire byte ordering. */
|
|
19
|
+
export declare const ReadConsistency: {
|
|
20
|
+
/** Every acknowledged write; leader only, behind a Raft read barrier. */
|
|
21
|
+
readonly Strong: 0;
|
|
22
|
+
/** Any member within maxStalenessMs of the leader. */
|
|
23
|
+
readonly Bounded: 1;
|
|
24
|
+
/** Local applied state, no freshness bound. */
|
|
25
|
+
readonly Stale: 2;
|
|
26
|
+
};
|
|
27
|
+
export type ReadConsistencyMode = 0 | 1 | 2;
|
|
28
|
+
|
|
29
|
+
/** The only supported way to open a connection. Do not put keys in URLs. */
|
|
30
|
+
export interface Config {
|
|
31
|
+
/** Single-node entry point. Required for connect(); optional when nodes is set. */
|
|
32
|
+
address?: string;
|
|
33
|
+
database?: string;
|
|
34
|
+
/** Reserved; must stay empty. Multi-realm hosting was removed — a
|
|
35
|
+
* deployment serves exactly one database, and a server rejects a Hello
|
|
36
|
+
* naming any other realm. The field remains only because the wire
|
|
37
|
+
* frame's trailing realm slot does. */
|
|
38
|
+
realm?: string;
|
|
39
|
+
user: string;
|
|
40
|
+
password?: string;
|
|
41
|
+
/** 32-byte client-held root when the server requires it. Never a URL query. */
|
|
42
|
+
key?: string | Uint8Array;
|
|
43
|
+
keyVersion?: number;
|
|
44
|
+
/** Client-only provider for ENCRYPTED CLIENT field keys. Never sent over NSQL. */
|
|
45
|
+
fieldKeys?: FieldKeyProvider;
|
|
46
|
+
tls?: TLSOptions;
|
|
47
|
+
/** Plaintext is allowed only on loopback. */
|
|
48
|
+
insecureNoTLS?: boolean;
|
|
49
|
+
/** Every cluster member address, for connectCluster routing. */
|
|
50
|
+
nodes?: string[];
|
|
51
|
+
/** Read-consistency mode applied to routed reads / the plain connection. */
|
|
52
|
+
readConsistency?: ReadConsistencyMode;
|
|
53
|
+
/** Bounded-read staleness window in milliseconds. 0 selects the server default. */
|
|
54
|
+
maxStalenessMs?: number;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export interface FieldKey {
|
|
58
|
+
/** Public NSCE1 key identifier (1..64 ASCII letters/digits/._-). */
|
|
59
|
+
id: string;
|
|
60
|
+
/** Exactly 32 bytes of AES-256 key material. */
|
|
61
|
+
material: Uint8Array;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export interface FieldKeyProvider {
|
|
65
|
+
currentFieldKey(database: string, table: string, column: string): FieldKey | Promise<FieldKey>;
|
|
66
|
+
fieldKey(database: string, table: string, column: string, keyID: string): FieldKey | Promise<FieldKey>;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export interface FieldTypeDescriptor {
|
|
70
|
+
kind: number;
|
|
71
|
+
precision: number;
|
|
72
|
+
scale: number;
|
|
73
|
+
vecElem: number;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export declare const FieldType: {
|
|
77
|
+
readonly UUID: FieldTypeDescriptor;
|
|
78
|
+
readonly String: FieldTypeDescriptor;
|
|
79
|
+
readonly Text: FieldTypeDescriptor;
|
|
80
|
+
readonly TimestampTZ: FieldTypeDescriptor;
|
|
81
|
+
readonly JSON: FieldTypeDescriptor;
|
|
82
|
+
readonly Bool: FieldTypeDescriptor;
|
|
83
|
+
Decimal(precision: number, scale: number): FieldTypeDescriptor;
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
export declare class MemoryFieldKeyring implements FieldKeyProvider {
|
|
87
|
+
constructor(current: FieldKey, ...overlap: FieldKey[]);
|
|
88
|
+
currentFieldKey(database: string, table: string, column: string): Promise<FieldKey>;
|
|
89
|
+
fieldKey(database: string, table: string, column: string, keyID: string): Promise<FieldKey>;
|
|
90
|
+
rotate(key: FieldKey): void;
|
|
91
|
+
revoke(keyID: string): void;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** Material-free summary of one FileFieldKeyring record. */
|
|
95
|
+
export interface FieldKeyInfo {
|
|
96
|
+
id: string;
|
|
97
|
+
/** Unix seconds. */
|
|
98
|
+
created: number;
|
|
99
|
+
current: boolean;
|
|
100
|
+
revoked: boolean;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Durable, atomic, file-backed FieldKeyProvider. Unlike MemoryFieldKeyring,
|
|
105
|
+
* rotation and revocation persist across process restarts in the versioned
|
|
106
|
+
* NSFK1 on-disk format (see docs/client-encryption.md). A revoked key's
|
|
107
|
+
* material is overwritten with zeros on disk and its id can never be reused.
|
|
108
|
+
* Production applications with an existing secret manager or KMS should
|
|
109
|
+
* still prefer implementing FieldKeyProvider directly against that system.
|
|
110
|
+
*/
|
|
111
|
+
export declare class FileFieldKeyring implements FieldKeyProvider {
|
|
112
|
+
private constructor();
|
|
113
|
+
static create(path: string, current: FieldKey): Promise<FileFieldKeyring>;
|
|
114
|
+
static open(path: string): Promise<FileFieldKeyring>;
|
|
115
|
+
readonly path: string;
|
|
116
|
+
currentFieldKey(database: string, table: string, column: string): Promise<FieldKey>;
|
|
117
|
+
fieldKey(database: string, table: string, column: string, keyID: string): Promise<FieldKey>;
|
|
118
|
+
rotate(key: FieldKey): Promise<void>;
|
|
119
|
+
revoke(keyID: string): Promise<void>;
|
|
120
|
+
/** Re-reads the keyring file; on error the in-memory keyring is unchanged. */
|
|
121
|
+
reload(): Promise<void>;
|
|
122
|
+
list(): FieldKeyInfo[];
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/** Key-free replication health snapshot for follower-read routing. */
|
|
126
|
+
export interface NodeStatus {
|
|
127
|
+
role: string;
|
|
128
|
+
hasLeader: boolean;
|
|
129
|
+
healthy: boolean;
|
|
130
|
+
appliedLSN: bigint;
|
|
131
|
+
lastContactMs: bigint;
|
|
132
|
+
applyBacklog: bigint;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export type Point = { lon: number; lat: number };
|
|
136
|
+
export type Box = { west: number; south: number; east: number; north: number };
|
|
137
|
+
export type LineString = { coords: number[] };
|
|
138
|
+
export type Polygon = { rings: number[][] };
|
|
139
|
+
export type VectorRef = { ref: true; dim: number };
|
|
140
|
+
export type SparseVector = { dim: number; indices: number[]; values: number[] };
|
|
141
|
+
|
|
142
|
+
export type Param =
|
|
143
|
+
| null
|
|
144
|
+
| undefined
|
|
145
|
+
| boolean
|
|
146
|
+
| number
|
|
147
|
+
| bigint
|
|
148
|
+
| string
|
|
149
|
+
| Date
|
|
150
|
+
| Uint8Array
|
|
151
|
+
| number[]
|
|
152
|
+
| Point
|
|
153
|
+
| Box
|
|
154
|
+
| { kind: 'uuid'; value: string }
|
|
155
|
+
| { kind: 'decimal'; value: string }
|
|
156
|
+
| Record<string, unknown>;
|
|
157
|
+
|
|
158
|
+
export type Value =
|
|
159
|
+
| null
|
|
160
|
+
| boolean
|
|
161
|
+
| string
|
|
162
|
+
| number
|
|
163
|
+
| Date
|
|
164
|
+
| number[]
|
|
165
|
+
| Point
|
|
166
|
+
| Box
|
|
167
|
+
| LineString
|
|
168
|
+
| Polygon
|
|
169
|
+
| VectorRef
|
|
170
|
+
| SparseVector
|
|
171
|
+
| Record<string, unknown>
|
|
172
|
+
| unknown[];
|
|
173
|
+
|
|
174
|
+
export interface Column {
|
|
175
|
+
name: string;
|
|
176
|
+
kind: number;
|
|
177
|
+
precision: number;
|
|
178
|
+
scale: number;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export interface ExecResult {
|
|
182
|
+
columns: string[];
|
|
183
|
+
rows: Value[][];
|
|
184
|
+
affected: number;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export interface Rows extends AsyncIterable<Value[]> {
|
|
188
|
+
columns: string[];
|
|
189
|
+
columnTypes: Column[];
|
|
190
|
+
affected: number;
|
|
191
|
+
next(): Promise<boolean>;
|
|
192
|
+
values(): Value[] | null;
|
|
193
|
+
close(): Promise<void>;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
export interface Stmt {
|
|
197
|
+
query(params?: Param[]): Promise<Rows>;
|
|
198
|
+
exec(params?: Param[]): Promise<ExecResult>;
|
|
199
|
+
close(): Promise<void>;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
export interface Conn {
|
|
203
|
+
query(sql: string, params?: Param[]): Promise<Rows>;
|
|
204
|
+
exec(sql: string, params?: Param[]): Promise<ExecResult>;
|
|
205
|
+
prepare(sql: string): Promise<Stmt>;
|
|
206
|
+
cancel(): Promise<void>;
|
|
207
|
+
close(): Promise<void>;
|
|
208
|
+
/** Set this connection's read-consistency mode for subsequent statements. */
|
|
209
|
+
setReadConsistency(mode: ReadConsistencyMode, maxStalenessMs?: number): Promise<void>;
|
|
210
|
+
/** This server node's key-free replication health. */
|
|
211
|
+
nodeStatus(): Promise<NodeStatus>;
|
|
212
|
+
/** Seal a logical value into an opaque NSCE1 STRING; null passes through. */
|
|
213
|
+
encryptField(table: string, column: string, type: FieldTypeDescriptor, value: unknown): Promise<string | null>;
|
|
214
|
+
/** Authenticate and decode an opaque NSCE1 STRING; null passes through. */
|
|
215
|
+
decryptField(table: string, column: string, type: FieldTypeDescriptor, ciphertext: string | null): Promise<unknown>;
|
|
216
|
+
encryptFieldDeterministic(table: string, column: string, type: FieldTypeDescriptor, value: unknown): Promise<string | null>;
|
|
217
|
+
decryptFieldDeterministic(table: string, column: string, type: FieldTypeDescriptor, ciphertext: string | null): Promise<unknown>;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/** Routing client over every node of a NextSQL HA cluster. */
|
|
221
|
+
export interface Cluster {
|
|
222
|
+
query(sql: string, params?: Param[]): Promise<Rows>;
|
|
223
|
+
exec(sql: string, params?: Param[]): Promise<ExecResult>;
|
|
224
|
+
/** Last observed status of every reachable node. */
|
|
225
|
+
nodes(): Promise<NodeStatus[]>;
|
|
226
|
+
close(): Promise<void>;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
export interface Hello {
|
|
230
|
+
version: number;
|
|
231
|
+
flags?: number;
|
|
232
|
+
secret?: bigint;
|
|
233
|
+
database?: string;
|
|
234
|
+
user?: string;
|
|
235
|
+
realm?: string;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
export interface HelloOK {
|
|
239
|
+
version: number;
|
|
240
|
+
authMethod: number;
|
|
241
|
+
secret: bigint;
|
|
242
|
+
/** Capability bits the server accepted from Hello.flags; 0 when none. */
|
|
243
|
+
flags: number;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
export interface DecodeValue {
|
|
247
|
+
value: Value;
|
|
248
|
+
next: number;
|
|
249
|
+
kind: number;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
export declare class NextSQLError extends Error {
|
|
253
|
+
readonly code: string;
|
|
254
|
+
/**
|
|
255
|
+
* Stable ERR_* name from docs/error-codes.md, present only on an error
|
|
256
|
+
* received over a connection that negotiated the public taxonomy and empty
|
|
257
|
+
* otherwise. `code` always carries the legacy class, so retry logic should
|
|
258
|
+
* keep reading that.
|
|
259
|
+
*/
|
|
260
|
+
readonly publicCode: string;
|
|
261
|
+
constructor(code: string, message?: string, publicCode?: string);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
export declare const Kind: {
|
|
265
|
+
readonly Invalid: 0;
|
|
266
|
+
readonly UUID: 1;
|
|
267
|
+
readonly String: 2;
|
|
268
|
+
readonly Text: 3;
|
|
269
|
+
readonly Decimal: 4;
|
|
270
|
+
readonly TimestampTZ: 5;
|
|
271
|
+
readonly JSON: 6;
|
|
272
|
+
readonly Vector: 7;
|
|
273
|
+
readonly Bool: 8;
|
|
274
|
+
readonly Null: 9;
|
|
275
|
+
readonly Point: 10;
|
|
276
|
+
readonly Box: 11;
|
|
277
|
+
readonly Line: 12;
|
|
278
|
+
readonly Polygon: 13;
|
|
279
|
+
readonly Blob: 14;
|
|
280
|
+
readonly Int8: 15;
|
|
281
|
+
readonly Int16: 16;
|
|
282
|
+
readonly Int32: 17;
|
|
283
|
+
readonly Int64: 18;
|
|
284
|
+
readonly Uint8: 19;
|
|
285
|
+
readonly Uint16: 20;
|
|
286
|
+
readonly Uint32: 21;
|
|
287
|
+
readonly Uint64: 22;
|
|
288
|
+
readonly Date: 23;
|
|
289
|
+
readonly Time: 24;
|
|
290
|
+
readonly Char: 25;
|
|
291
|
+
readonly Varchar: 26;
|
|
292
|
+
readonly Timestamp: 27;
|
|
293
|
+
readonly Float32: 28;
|
|
294
|
+
readonly Float64: 29;
|
|
295
|
+
readonly Enum: 30;
|
|
296
|
+
readonly Interval: 31;
|
|
297
|
+
readonly Struct: 32;
|
|
298
|
+
readonly Array: 33;
|
|
299
|
+
readonly Map: 34;
|
|
300
|
+
readonly Geometry: 35;
|
|
301
|
+
readonly Geography: 36;
|
|
302
|
+
};
|
|
303
|
+
|
|
304
|
+
export declare const Type: {
|
|
305
|
+
readonly Hello: 1;
|
|
306
|
+
readonly HelloOK: 2;
|
|
307
|
+
readonly Auth: 3;
|
|
308
|
+
readonly AuthOK: 4;
|
|
309
|
+
readonly Query: 5;
|
|
310
|
+
readonly Prepare: 6;
|
|
311
|
+
readonly PrepareOK: 7;
|
|
312
|
+
readonly Execute: 8;
|
|
313
|
+
readonly CloseStmt: 9;
|
|
314
|
+
readonly CloseOK: 10;
|
|
315
|
+
readonly FlowAck: 11;
|
|
316
|
+
readonly Cancel: 12;
|
|
317
|
+
readonly Terminate: 13;
|
|
318
|
+
readonly RowDesc: 14;
|
|
319
|
+
readonly DataBatch: 15;
|
|
320
|
+
readonly CommandComplete: 16;
|
|
321
|
+
readonly Error: 17;
|
|
322
|
+
readonly Ready: 18;
|
|
323
|
+
readonly Unlock: 19;
|
|
324
|
+
readonly UnlockOK: 20;
|
|
325
|
+
readonly IdempotentQuery: 21;
|
|
326
|
+
readonly SetReadConsistency: 22;
|
|
327
|
+
readonly NodeStatus: 23;
|
|
328
|
+
readonly NodeStatusResp: 24;
|
|
329
|
+
};
|
|
330
|
+
|
|
331
|
+
export declare function connect(cfg: Config): Promise<Conn>;
|
|
332
|
+
export declare function connectCluster(cfg: Config): Promise<Cluster>;
|
|
333
|
+
export declare function generateFieldKey(id: string): FieldKey;
|
|
334
|
+
export declare function inspectField(ciphertext: string): { keyID: string; type: FieldTypeDescriptor };
|
|
335
|
+
export declare function encryptField(provider: FieldKeyProvider, database: string, table: string, column: string, type: FieldTypeDescriptor, value: unknown): Promise<string | null>;
|
|
336
|
+
export declare function decryptField(provider: FieldKeyProvider, database: string, table: string, column: string, type: FieldTypeDescriptor, ciphertext: string | null): Promise<unknown>;
|
|
337
|
+
export declare function encryptFieldDeterministic(provider: FieldKeyProvider, database: string, table: string, column: string, type: FieldTypeDescriptor, value: unknown): Promise<string | null>;
|
|
338
|
+
export declare function decryptFieldDeterministic(provider: FieldKeyProvider, database: string, table: string, column: string, type: FieldTypeDescriptor, ciphertext: string | null): Promise<unknown>;
|
|
339
|
+
export declare function validateConfig(cfg: Config): void;
|
|
340
|
+
export declare function isLoopback(addr: string): boolean;
|
|
341
|
+
export declare function encodeParam(v: Param): Uint8Array;
|
|
342
|
+
export declare function struct(fields: Array<[string, unknown]>): { __struct: Array<[string, unknown]> };
|
|
343
|
+
export declare function decodeValue(buf: Uint8Array, off: number): DecodeValue;
|
|
344
|
+
/** Hello.flags bit requesting cancellation instead of a session. */
|
|
345
|
+
export declare const FlagCancel: number;
|
|
346
|
+
/** Hello.flags bit requesting the stable ERR_* error taxonomy. */
|
|
347
|
+
export declare const FlagPublicErrorCodes: number;
|
|
348
|
+
export declare function encodeHello(h: Hello): Uint8Array;
|
|
349
|
+
export declare function decodeHelloOK(b: Uint8Array): HelloOK;
|
|
350
|
+
export declare function encodeDecimalString(s: string): Uint8Array;
|
|
351
|
+
export declare function decodeDecimal(body: Uint8Array): string;
|
|
352
|
+
export declare function decodeNSJB(doc: Uint8Array): unknown;
|
|
353
|
+
export declare function formatUUID(raw: Uint8Array): string;
|