@aouda/client 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 +151 -0
- package/dist/cli/index.cjs +5906 -0
- package/dist/cli/index.cjs.map +1 -0
- package/dist/cli/index.d.cts +52 -0
- package/dist/cli/index.d.ts +52 -0
- package/dist/cli/index.js +5875 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/client-DXT2ZAeO.d.cts +3356 -0
- package/dist/client-DXT2ZAeO.d.ts +3356 -0
- package/dist/index.cjs +5535 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +196 -0
- package/dist/index.d.ts +196 -0
- package/dist/index.js +5460 -0
- package/dist/index.js.map +1 -0
- package/package.json +52 -0
|
@@ -0,0 +1,3356 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Auth type definitions for @aouda/client.
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Authentication credentials for server/database-admin access.
|
|
6
|
+
* Routes auth requests to `/api/auth/…`.
|
|
7
|
+
*
|
|
8
|
+
* Use `apiKey` (server API key, `mk_srv_` prefix) or a pre-obtained `token` for
|
|
9
|
+
* machine/service access. Mutually exclusive: provide either `apiKey` or `token`.
|
|
10
|
+
*/
|
|
11
|
+
interface ServerAuthOptions {
|
|
12
|
+
/** Pre-obtained JWT access token. Mutually exclusive with apiKey. */
|
|
13
|
+
token?: string;
|
|
14
|
+
/** Refresh token for proactive/reactive refresh. Requires token. */
|
|
15
|
+
refreshToken?: string;
|
|
16
|
+
/** Server API key (e.g. `mk_srv_…`). Sent as Bearer on every request.
|
|
17
|
+
* Mutually exclusive with token. */
|
|
18
|
+
apiKey?: string;
|
|
19
|
+
/** User JWT to forward as X-User-Token header on outgoing requests.
|
|
20
|
+
* Only effective when `apiKey` is a service-level key (prefix `mk_svc_` or `mk_srv_`).
|
|
21
|
+
* Allows backends to execute requests on behalf of a specific user with PLS enforcement. */
|
|
22
|
+
userToken?: string;
|
|
23
|
+
/** How early before expiry (ms) to proactively refresh. Default: 120_000 (2 min). */
|
|
24
|
+
refreshThresholdMs?: number;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Authentication credentials for application-user access.
|
|
28
|
+
* Routes auth requests to `/api/databases/{db}/auth/…`.
|
|
29
|
+
*
|
|
30
|
+
* Two-layer auth model:
|
|
31
|
+
* - Layer 1 (connection): use `apiKey` (anon or service_role key from database creation).
|
|
32
|
+
* - Layer 2 (identity): call `client.auth.signIn(email, password)` after connecting.
|
|
33
|
+
*
|
|
34
|
+
* For backends using service keys, set `userToken` to forward a user JWT as X-User-Token,
|
|
35
|
+
* enabling PLS enforcement on behalf of that user.
|
|
36
|
+
*
|
|
37
|
+
* Mutually exclusive: provide either token, or apiKey — not both.
|
|
38
|
+
*/
|
|
39
|
+
interface AppAuthOptions {
|
|
40
|
+
/** Pre-obtained JWT access token. Mutually exclusive with apiKey. */
|
|
41
|
+
token?: string;
|
|
42
|
+
/** Refresh token for proactive/reactive refresh. Requires token. */
|
|
43
|
+
refreshToken?: string;
|
|
44
|
+
/** API key for connection-level auth (anon or service_role key). Sent as Bearer on every
|
|
45
|
+
* request. After `client.auth.signIn()`, the user JWT replaces it as the bearer token.
|
|
46
|
+
* Mutually exclusive with token. */
|
|
47
|
+
apiKey?: string;
|
|
48
|
+
/** User JWT to forward as X-User-Token header on outgoing requests.
|
|
49
|
+
* Only effective when `apiKey` is a service-level key (prefix `mk_svc_` or `mk_srv_`).
|
|
50
|
+
* Allows backends to execute requests on behalf of a specific user with PLS enforcement. */
|
|
51
|
+
userToken?: string;
|
|
52
|
+
/** Explicit auth database name. Discovered from X-Auth-Database header if not set, defaults to "_auth". */
|
|
53
|
+
authDatabase?: string;
|
|
54
|
+
/** How early before expiry (ms) to proactively refresh. Default: 120_000 (2 min). */
|
|
55
|
+
refreshThresholdMs?: number;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Auth response from sign-in, sign-up, or refresh endpoints.
|
|
59
|
+
*/
|
|
60
|
+
interface AuthResult {
|
|
61
|
+
user: AuthUserInfo;
|
|
62
|
+
accessToken: string;
|
|
63
|
+
refreshToken: string;
|
|
64
|
+
expiresIn: number;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Minimal user info returned in auth responses.
|
|
68
|
+
*/
|
|
69
|
+
interface AuthUserInfo {
|
|
70
|
+
id: string;
|
|
71
|
+
email: string;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Full user profile returned by the /me endpoint.
|
|
75
|
+
*/
|
|
76
|
+
interface UserProfile {
|
|
77
|
+
id: string;
|
|
78
|
+
email: string;
|
|
79
|
+
roles: string[];
|
|
80
|
+
createdAt: string;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Allowed table authorization modes for ADRA-enabled table metadata.
|
|
84
|
+
*/
|
|
85
|
+
type AuthorizationMode = "jwt-claim" | "auth-db-pls" | "auth-db-rls";
|
|
86
|
+
/**
|
|
87
|
+
* Request payload for creating a partition grant.
|
|
88
|
+
*/
|
|
89
|
+
interface CreatePartitionGrantRequest {
|
|
90
|
+
dimension: string;
|
|
91
|
+
partitionKey: string;
|
|
92
|
+
accessLevel?: string;
|
|
93
|
+
grantedBy?: string;
|
|
94
|
+
validFrom?: string;
|
|
95
|
+
validTo?: string;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Partition grant DTO returned by admin endpoints.
|
|
99
|
+
*/
|
|
100
|
+
interface PartitionGrant {
|
|
101
|
+
id: string;
|
|
102
|
+
userId: string;
|
|
103
|
+
dimension: string;
|
|
104
|
+
partitionKey: string;
|
|
105
|
+
accessLevel: string;
|
|
106
|
+
grantedBy?: string;
|
|
107
|
+
validFrom?: string;
|
|
108
|
+
validTo?: string;
|
|
109
|
+
createdAt: string;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Response payload for listing partition grants.
|
|
113
|
+
*/
|
|
114
|
+
interface PartitionGrantsListResponse {
|
|
115
|
+
grants: PartitionGrant[];
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Input rule when updating an RLS resolver.
|
|
119
|
+
*/
|
|
120
|
+
interface RlsResolverRuleInput {
|
|
121
|
+
ruleOrder: number;
|
|
122
|
+
columnName?: string;
|
|
123
|
+
operator?: string;
|
|
124
|
+
valueSource?: string;
|
|
125
|
+
valueConfig?: string;
|
|
126
|
+
combinator?: string;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Request payload for creating an RLS resolver.
|
|
130
|
+
*/
|
|
131
|
+
interface CreateRlsResolverRequest {
|
|
132
|
+
name: string;
|
|
133
|
+
description?: string;
|
|
134
|
+
targetTable: string;
|
|
135
|
+
resolverType: string;
|
|
136
|
+
createdBy?: string;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Request payload for patching an existing RLS resolver.
|
|
140
|
+
*/
|
|
141
|
+
interface UpdateRlsResolverRequest {
|
|
142
|
+
description?: string;
|
|
143
|
+
rules?: RlsResolverRuleInput[];
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* RLS resolver rule DTO returned by admin endpoints.
|
|
147
|
+
*/
|
|
148
|
+
interface RlsResolverRule {
|
|
149
|
+
id: string;
|
|
150
|
+
resolverId: string;
|
|
151
|
+
ruleOrder: number;
|
|
152
|
+
columnName: string;
|
|
153
|
+
operator: string;
|
|
154
|
+
valueSource: string;
|
|
155
|
+
valueConfig: string;
|
|
156
|
+
combinator?: string;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* RLS resolver DTO returned by admin endpoints.
|
|
160
|
+
*/
|
|
161
|
+
interface RlsResolver {
|
|
162
|
+
id: string;
|
|
163
|
+
name: string;
|
|
164
|
+
description?: string;
|
|
165
|
+
targetTable: string;
|
|
166
|
+
resolverType: string;
|
|
167
|
+
createdBy?: string;
|
|
168
|
+
createdAt: string;
|
|
169
|
+
updatedAt: string;
|
|
170
|
+
rules: RlsResolverRule[];
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Response payload for listing RLS resolvers.
|
|
174
|
+
*/
|
|
175
|
+
interface RlsResolversListResponse {
|
|
176
|
+
resolvers: RlsResolver[];
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* @aouda/client type definitions.
|
|
181
|
+
*/
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Retry policy with exponential backoff and jitter.
|
|
185
|
+
* Transient failures (connection, timeout, 5xx) are retried up to maxRetries times.
|
|
186
|
+
*/
|
|
187
|
+
interface RetryPolicy {
|
|
188
|
+
/** Maximum number of retry attempts (default: 3). Setting to 0 disables retries. */
|
|
189
|
+
maxRetries?: number;
|
|
190
|
+
/** Initial delay before first retry in ms (default: 100). */
|
|
191
|
+
initialDelayMs?: number;
|
|
192
|
+
/**
|
|
193
|
+
* Base delay between retries in milliseconds.
|
|
194
|
+
* @deprecated Use initialDelayMs instead. If both are present, initialDelayMs takes precedence.
|
|
195
|
+
*/
|
|
196
|
+
baseDelayMs?: number;
|
|
197
|
+
/** Maximum delay between retries in ms (default: 30_000). */
|
|
198
|
+
maxDelayMs?: number;
|
|
199
|
+
/** Backoff multiplier (default: 2). */
|
|
200
|
+
multiplier?: number;
|
|
201
|
+
/** Jitter factor 0–1 to randomize delays (default: 0.1). */
|
|
202
|
+
jitterFactor?: number;
|
|
203
|
+
}
|
|
204
|
+
/** Retry policy presets (None, Default, Aggressive). */
|
|
205
|
+
declare namespace RetryPolicy {
|
|
206
|
+
/** No retries. */
|
|
207
|
+
const None: RetryPolicy;
|
|
208
|
+
/** Default: 3 retries, 100ms initial delay, 30s max. */
|
|
209
|
+
const Default: RetryPolicy;
|
|
210
|
+
/** Aggressive: 5 retries, 60s max delay. */
|
|
211
|
+
const Aggressive: RetryPolicy;
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Circuit breaker policy. After failureThreshold failures within failureWindowMs,
|
|
215
|
+
* the circuit opens and requests fail fast until openDurationMs has passed (then half-open).
|
|
216
|
+
*/
|
|
217
|
+
interface CircuitBreakerPolicy {
|
|
218
|
+
/** Number of failures before opening the circuit (default: 5). */
|
|
219
|
+
failureThreshold?: number;
|
|
220
|
+
/** Time window for counting failures in ms (default: 30_000). */
|
|
221
|
+
failureWindowMs?: number;
|
|
222
|
+
/** Time to wait before allowing test requests (half-open) in ms (default: 30_000). */
|
|
223
|
+
openDurationMs?: number;
|
|
224
|
+
/** Successes needed in half-open to close the circuit (default: 2). */
|
|
225
|
+
successThreshold?: number;
|
|
226
|
+
}
|
|
227
|
+
/** Circuit breaker policy presets (Disabled, Default, Sensitive). */
|
|
228
|
+
declare namespace CircuitBreakerPolicy {
|
|
229
|
+
/** Circuit breaker disabled (never opens). */
|
|
230
|
+
const Disabled: CircuitBreakerPolicy;
|
|
231
|
+
/** Default: 5 failures in 30s window, 30s open duration. */
|
|
232
|
+
const Default: CircuitBreakerPolicy;
|
|
233
|
+
/** Sensitive: 3 failures in 15s window. */
|
|
234
|
+
const Sensitive: CircuitBreakerPolicy;
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Configuration options for AoudaClient.
|
|
238
|
+
*/
|
|
239
|
+
interface AoudaClientOptions {
|
|
240
|
+
/**
|
|
241
|
+
* The base URL of the Aouda server.
|
|
242
|
+
* Required. Must be a valid URL (e.g., "http://localhost:8080").
|
|
243
|
+
*/
|
|
244
|
+
serverUrl: string;
|
|
245
|
+
/**
|
|
246
|
+
* Database name to scope all data and schema operations.
|
|
247
|
+
* Required. Must be a non-empty string (no default).
|
|
248
|
+
*/
|
|
249
|
+
database: string;
|
|
250
|
+
/**
|
|
251
|
+
* Request timeout in milliseconds.
|
|
252
|
+
* @default 30000
|
|
253
|
+
*/
|
|
254
|
+
timeout?: number;
|
|
255
|
+
/**
|
|
256
|
+
* Optional retry policy configuration.
|
|
257
|
+
* When omitted, no retries are performed (equivalent to RetryPolicy.None).
|
|
258
|
+
*/
|
|
259
|
+
retryPolicy?: RetryPolicy;
|
|
260
|
+
/**
|
|
261
|
+
* Optional circuit breaker policy.
|
|
262
|
+
* When omitted, circuit breaker is disabled (equivalent to CircuitBreakerPolicy.Disabled).
|
|
263
|
+
*/
|
|
264
|
+
circuitBreakerPolicy?: CircuitBreakerPolicy;
|
|
265
|
+
/**
|
|
266
|
+
* Server/database-admin auth credentials. Routes to `/api/auth/…`.
|
|
267
|
+
* Mutually exclusive with `appAuth`.
|
|
268
|
+
* When set, the client automatically handles token lifecycle:
|
|
269
|
+
* proactive refresh, and 401 retry.
|
|
270
|
+
*/
|
|
271
|
+
serverAuth?: ServerAuthOptions;
|
|
272
|
+
/**
|
|
273
|
+
* Application-user auth credentials. Routes to `/api/databases/{db}/auth/…`.
|
|
274
|
+
* Mutually exclusive with `serverAuth`.
|
|
275
|
+
* When set, the client automatically handles token lifecycle:
|
|
276
|
+
* proactive refresh, and 401 retry.
|
|
277
|
+
* Use `apiKey` for connection (Layer 1); call `client.auth.signIn()` for user identity (Layer 2).
|
|
278
|
+
*/
|
|
279
|
+
appAuth?: AppAuthOptions;
|
|
280
|
+
/**
|
|
281
|
+
* Streaming transport options.
|
|
282
|
+
*/
|
|
283
|
+
streaming?: {
|
|
284
|
+
/**
|
|
285
|
+
* Enables permessage-deflate compression for WebSocket transport in Node.js.
|
|
286
|
+
* Browser-native WebSocket compression remains browser-managed.
|
|
287
|
+
* @default true
|
|
288
|
+
*/
|
|
289
|
+
enableCompression?: boolean;
|
|
290
|
+
/**
|
|
291
|
+
* Streaming WebSocket wire mode.
|
|
292
|
+
* - "json": text frames (default)
|
|
293
|
+
* - "msgpack": binary MessagePack frames after auth negotiation
|
|
294
|
+
* @default "json"
|
|
295
|
+
*/
|
|
296
|
+
wireMode?: "json" | "msgpack";
|
|
297
|
+
/**
|
|
298
|
+
* Enables HTTP long-poll fallback when WebSocket transport cannot connect.
|
|
299
|
+
* @default true
|
|
300
|
+
*/
|
|
301
|
+
enableLongPollFallback?: boolean;
|
|
302
|
+
/**
|
|
303
|
+
* Long-poll wait timeout in milliseconds for fallback transport.
|
|
304
|
+
* @default 25000
|
|
305
|
+
*/
|
|
306
|
+
longPollWaitMs?: number;
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
/**
|
|
310
|
+
* Health status response from the Aouda server.
|
|
311
|
+
* Matches the wire protocol response from GET /health.
|
|
312
|
+
*/
|
|
313
|
+
interface HealthStatus {
|
|
314
|
+
/**
|
|
315
|
+
* Status string from the server (e.g., "healthy").
|
|
316
|
+
*/
|
|
317
|
+
status: string;
|
|
318
|
+
/**
|
|
319
|
+
* Whether the server is healthy.
|
|
320
|
+
* Derived: true if status equals "healthy" (case-insensitive).
|
|
321
|
+
*/
|
|
322
|
+
isHealthy: boolean;
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* Schema type contract for the generic Aouda client.
|
|
326
|
+
*
|
|
327
|
+
* Use as the type parameter for `createAoudaClient<S>(options)` so that
|
|
328
|
+
* `table(name)` accepts only table names from the schema and returns
|
|
329
|
+
* queries typed with the corresponding row interface.
|
|
330
|
+
*
|
|
331
|
+
* Shape (aligned with server TypeScript generator and B.8 CLI output):
|
|
332
|
+
* - `tables`: record mapping table names (string keys) to row types (object types).
|
|
333
|
+
*
|
|
334
|
+
* @example
|
|
335
|
+
* ```typescript
|
|
336
|
+
* interface Order { id: number; status: string; }
|
|
337
|
+
* interface Schema { tables: { orders: Order; }; }
|
|
338
|
+
* const client = createAoudaClient<Schema>({ serverUrl: "..." });
|
|
339
|
+
* client.table('orders'); // OK, returns TableQuery<Order>
|
|
340
|
+
* client.table('other'); // type error
|
|
341
|
+
* ```
|
|
342
|
+
*/
|
|
343
|
+
interface SchemaLike {
|
|
344
|
+
/** Maps table names to their row types. */
|
|
345
|
+
tables: Record<string, Record<string, unknown>>;
|
|
346
|
+
}
|
|
347
|
+
/**
|
|
348
|
+
* Default schema when no generic is provided: any string table name,
|
|
349
|
+
* rows typed as `Record<string, unknown>`.
|
|
350
|
+
*/
|
|
351
|
+
interface DefaultSchema extends SchemaLike {
|
|
352
|
+
tables: Record<string, Record<string, unknown>>;
|
|
353
|
+
}
|
|
354
|
+
/**
|
|
355
|
+
* Extracts the union of table names from a schema type.
|
|
356
|
+
* Use for variables or parameters that must be a valid table name for schema `S`.
|
|
357
|
+
*
|
|
358
|
+
* @example
|
|
359
|
+
* ```typescript
|
|
360
|
+
* type TableName = TableNameFromSchema<Schema>; // 'orders' | 'authors' | ...
|
|
361
|
+
* const name: TableName = 'orders';
|
|
362
|
+
* ```
|
|
363
|
+
*/
|
|
364
|
+
type TableNameFromSchema<S extends SchemaLike> = keyof S["tables"] & string;
|
|
365
|
+
/**
|
|
366
|
+
* Full request configuration for HttpTransport.request().
|
|
367
|
+
*/
|
|
368
|
+
interface RequestConfig {
|
|
369
|
+
method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
|
|
370
|
+
path: string;
|
|
371
|
+
body?: unknown;
|
|
372
|
+
headers?: Record<string, string>;
|
|
373
|
+
/** Override default timeout for this request. */
|
|
374
|
+
timeout?: number;
|
|
375
|
+
/** External abort signal (e.g. client disconnect). */
|
|
376
|
+
signal?: AbortSignal;
|
|
377
|
+
/** If true, return the raw response text instead of parsing JSON. */
|
|
378
|
+
rawText?: boolean;
|
|
379
|
+
/**
|
|
380
|
+
* If response status is in this list, return parsed JSON instead of throwing.
|
|
381
|
+
* Used e.g. for GET /ready which returns 503 with a body when not ready.
|
|
382
|
+
*/
|
|
383
|
+
allowStatuses?: number[];
|
|
384
|
+
/**
|
|
385
|
+
* If set, send this raw string as the request body instead of JSON-serializing `body`.
|
|
386
|
+
* Used for NDJSON streaming (bulk-load :append).
|
|
387
|
+
*/
|
|
388
|
+
rawBodyStr?: string;
|
|
389
|
+
}
|
|
390
|
+
/**
|
|
391
|
+
* Options for convenience methods (get, post, put, patch, delete).
|
|
392
|
+
*/
|
|
393
|
+
interface RequestOptions {
|
|
394
|
+
headers?: Record<string, string>;
|
|
395
|
+
timeout?: number;
|
|
396
|
+
signal?: AbortSignal;
|
|
397
|
+
/** Sent as X-Request-Id header when provided. */
|
|
398
|
+
requestId?: string;
|
|
399
|
+
}
|
|
400
|
+
/**
|
|
401
|
+
* User-facing comparison operator for where clauses.
|
|
402
|
+
* Mapped to wire protocol operators (eq, ne, gt, etc.) internally.
|
|
403
|
+
*/
|
|
404
|
+
type WhereOperator = "=" | "!=" | ">" | "<" | ">=" | "<=" | "in" | "notIn" | "like" | "isNull" | "isNotNull" | "between";
|
|
405
|
+
/**
|
|
406
|
+
* User-facing sort direction.
|
|
407
|
+
* Mapped to wire protocol `descending` boolean internally.
|
|
408
|
+
*/
|
|
409
|
+
type SortDirection = "asc" | "desc";
|
|
410
|
+
/**
|
|
411
|
+
* Statistics about query execution.
|
|
412
|
+
* Returned by the server with every query response.
|
|
413
|
+
*/
|
|
414
|
+
interface QueryStats {
|
|
415
|
+
/** Number of rows scanned during query execution. */
|
|
416
|
+
rowsScanned: number;
|
|
417
|
+
/** Number of rows returned in the result. */
|
|
418
|
+
rowsReturned: number;
|
|
419
|
+
/** Number of segments accessed during query execution. */
|
|
420
|
+
segmentsAccessed: number;
|
|
421
|
+
/** Query execution time in milliseconds. */
|
|
422
|
+
executionMs: number;
|
|
423
|
+
}
|
|
424
|
+
/**
|
|
425
|
+
* Result of a query execution.
|
|
426
|
+
* Contains the rows and execution statistics.
|
|
427
|
+
*/
|
|
428
|
+
interface QueryResult<T = Record<string, unknown>> {
|
|
429
|
+
/** Array of result rows. */
|
|
430
|
+
rows: T[];
|
|
431
|
+
/** Query execution statistics. */
|
|
432
|
+
stats: QueryStats;
|
|
433
|
+
}
|
|
434
|
+
/**
|
|
435
|
+
* Wire protocol comparison operators.
|
|
436
|
+
* @internal
|
|
437
|
+
*/
|
|
438
|
+
type WireOperator = "eq" | "ne" | "gt" | "gte" | "lt" | "lte" | "in" | "nin" | "like";
|
|
439
|
+
/**
|
|
440
|
+
* A single predicate in a where clause.
|
|
441
|
+
* @internal
|
|
442
|
+
*/
|
|
443
|
+
interface WherePredicate {
|
|
444
|
+
column: string;
|
|
445
|
+
op: WireOperator;
|
|
446
|
+
value: unknown;
|
|
447
|
+
}
|
|
448
|
+
/**
|
|
449
|
+
* Where clause structure for the wire protocol.
|
|
450
|
+
* Semantics: `(∧ and) ∧ (∨ or) ∧ (∧ groups[i])` — see server `QueryTranslator`.
|
|
451
|
+
* Prefer `TableQuery.whereGroup` / `WhereGroupBuilder` in the TS client instead of hand-building `groups`.
|
|
452
|
+
* @internal
|
|
453
|
+
*/
|
|
454
|
+
interface WhereClause {
|
|
455
|
+
and?: WherePredicate[];
|
|
456
|
+
or?: WherePredicate[];
|
|
457
|
+
/** Nested sub-clauses AND-combined with top-level `and` / `or` (wire: `groups`). */
|
|
458
|
+
groups?: WhereClause[];
|
|
459
|
+
}
|
|
460
|
+
/**
|
|
461
|
+
* Order by clause for the wire protocol.
|
|
462
|
+
* @internal
|
|
463
|
+
*/
|
|
464
|
+
interface OrderByClause {
|
|
465
|
+
column: string;
|
|
466
|
+
descending?: boolean;
|
|
467
|
+
}
|
|
468
|
+
/**
|
|
469
|
+
* Supported join types in query requests.
|
|
470
|
+
* @internal
|
|
471
|
+
*/
|
|
472
|
+
type JoinType = "inner" | "left" | "right" | "full" | "cross";
|
|
473
|
+
/**
|
|
474
|
+
* Join clause for the wire protocol query request.
|
|
475
|
+
* Supports both single-column and multi-column equality joins, plus cross join.
|
|
476
|
+
* @internal
|
|
477
|
+
*/
|
|
478
|
+
interface JoinClause {
|
|
479
|
+
table: string;
|
|
480
|
+
type?: JoinType;
|
|
481
|
+
leftColumn?: string;
|
|
482
|
+
rightColumn?: string;
|
|
483
|
+
leftColumns?: string[];
|
|
484
|
+
rightColumns?: string[];
|
|
485
|
+
}
|
|
486
|
+
/**
|
|
487
|
+
* Supported aggregate functions in query requests.
|
|
488
|
+
* @internal
|
|
489
|
+
*/
|
|
490
|
+
type AggregateFunction = "sum" | "min" | "max";
|
|
491
|
+
/**
|
|
492
|
+
* Aggregate operation specification for query requests.
|
|
493
|
+
* @internal
|
|
494
|
+
*/
|
|
495
|
+
interface AggregateOperation {
|
|
496
|
+
op: AggregateFunction;
|
|
497
|
+
column: string;
|
|
498
|
+
}
|
|
499
|
+
/**
|
|
500
|
+
* Columnar response from the server (default format).
|
|
501
|
+
*/
|
|
502
|
+
interface ColumnarResponse {
|
|
503
|
+
columns: string[];
|
|
504
|
+
types: string[];
|
|
505
|
+
data: unknown[][];
|
|
506
|
+
rowCount: number;
|
|
507
|
+
stats: QueryStats;
|
|
508
|
+
}
|
|
509
|
+
/**
|
|
510
|
+
* Summary of a table returned by list().
|
|
511
|
+
*/
|
|
512
|
+
interface TableSummary {
|
|
513
|
+
/** Table name. */
|
|
514
|
+
name: string;
|
|
515
|
+
/** Number of columns in the table. */
|
|
516
|
+
columnCount: number;
|
|
517
|
+
/** Total row count across all segments. */
|
|
518
|
+
rowCount: number;
|
|
519
|
+
/** ISO 8601 timestamp when table was created (empty for legacy tables). */
|
|
520
|
+
createdAt: string;
|
|
521
|
+
/** ISO 8601 timestamp when table/data was last modified (empty for legacy tables). */
|
|
522
|
+
lastModifiedAt: string;
|
|
523
|
+
/** Approximate size in bytes across all segments. */
|
|
524
|
+
sizeBytes: number;
|
|
525
|
+
/** Storage policy (optional metadata). */
|
|
526
|
+
policy?: TablePolicy;
|
|
527
|
+
}
|
|
528
|
+
/**
|
|
529
|
+
* Detailed schema of a table returned by get().
|
|
530
|
+
*/
|
|
531
|
+
interface TableSchema {
|
|
532
|
+
/** Table name. */
|
|
533
|
+
name: string;
|
|
534
|
+
/** Column definitions. */
|
|
535
|
+
columns: ColumnSchema[];
|
|
536
|
+
/** Storage policy (optional metadata). */
|
|
537
|
+
policy?: TablePolicy;
|
|
538
|
+
/** Whether partition-level security is enabled. */
|
|
539
|
+
partitionLevelSecurity?: boolean;
|
|
540
|
+
/** Table authorization mode (ADRA). */
|
|
541
|
+
authMode?: AuthorizationMode;
|
|
542
|
+
/** Permission dimension for auth-db-pls mode. */
|
|
543
|
+
permissionDimension?: string;
|
|
544
|
+
/** Resolver name for auth-db-rls mode. */
|
|
545
|
+
rlsResolverName?: string;
|
|
546
|
+
}
|
|
547
|
+
/**
|
|
548
|
+
* Schema definition for a single column.
|
|
549
|
+
*/
|
|
550
|
+
interface ColumnSchema {
|
|
551
|
+
/** Column name. */
|
|
552
|
+
name: string;
|
|
553
|
+
/** Aouda data type (e.g., 'Int64', 'String', 'Double'). */
|
|
554
|
+
type: string;
|
|
555
|
+
/** Whether the column allows null values. */
|
|
556
|
+
isNullable: boolean;
|
|
557
|
+
/** Whether column has server-assigned auto-increment values. */
|
|
558
|
+
isAutoIncrement?: boolean;
|
|
559
|
+
/** Position in composite primary key (null if not PK). */
|
|
560
|
+
primaryKeyOrder?: number;
|
|
561
|
+
/** Position in composite partition key. */
|
|
562
|
+
partitionKeyOrder?: number;
|
|
563
|
+
/** Position in cluster columns for storage ordering. */
|
|
564
|
+
clusterOrder?: number;
|
|
565
|
+
/** Reference to another table's column (for relationship navigation). */
|
|
566
|
+
reference?: ReferenceInfo;
|
|
567
|
+
}
|
|
568
|
+
/**
|
|
569
|
+
* Storage policy for a table.
|
|
570
|
+
*/
|
|
571
|
+
interface TablePolicy {
|
|
572
|
+
/** Storage temperature setting. */
|
|
573
|
+
storageTemperature?: string;
|
|
574
|
+
/** Residency configuration. */
|
|
575
|
+
residency?: ResidencyConfig;
|
|
576
|
+
}
|
|
577
|
+
/**
|
|
578
|
+
* Residency configuration within a table policy.
|
|
579
|
+
*/
|
|
580
|
+
interface ResidencyConfig {
|
|
581
|
+
/** Data durability setting. */
|
|
582
|
+
dataDurability?: string;
|
|
583
|
+
/** Whether all data is pinned in memory. */
|
|
584
|
+
pinAllInMemory?: boolean;
|
|
585
|
+
}
|
|
586
|
+
/**
|
|
587
|
+
* Reference information for a column pointing to another table.
|
|
588
|
+
*/
|
|
589
|
+
interface ReferenceInfo {
|
|
590
|
+
/** Name of the table this column references. */
|
|
591
|
+
targetTable: string;
|
|
592
|
+
/** Name of the column in the target table. */
|
|
593
|
+
targetColumn: string;
|
|
594
|
+
/** Whether this reference was explicitly declared or inferred from naming conventions. */
|
|
595
|
+
source: "declared" | "inferred";
|
|
596
|
+
}
|
|
597
|
+
/**
|
|
598
|
+
* Enhanced schema response from schema() method.
|
|
599
|
+
*/
|
|
600
|
+
interface TableSchemaResponse {
|
|
601
|
+
/** Table name. */
|
|
602
|
+
name: string;
|
|
603
|
+
/** Column definitions with full metadata. */
|
|
604
|
+
columns: ColumnSchema[];
|
|
605
|
+
/** Column names forming the primary key, in order. */
|
|
606
|
+
primaryKey: string[];
|
|
607
|
+
/** Column names forming the partition key, in order. */
|
|
608
|
+
partitionKey: string[];
|
|
609
|
+
/** Column names for cluster ordering, in order. */
|
|
610
|
+
clusterColumns: string[];
|
|
611
|
+
/** Secondary indexes (placeholder for future). */
|
|
612
|
+
indexes: IndexInfo[];
|
|
613
|
+
/** Relationships to other tables (both declared and inferred). */
|
|
614
|
+
relationships?: RelationshipInfo[];
|
|
615
|
+
/** Whether partition-level security is enabled. */
|
|
616
|
+
partitionLevelSecurity?: boolean;
|
|
617
|
+
/** Table authorization mode (ADRA). */
|
|
618
|
+
authMode?: AuthorizationMode;
|
|
619
|
+
/** Permission dimension for auth-db-pls mode. */
|
|
620
|
+
permissionDimension?: string;
|
|
621
|
+
/** Resolver name for auth-db-rls mode. */
|
|
622
|
+
rlsResolverName?: string;
|
|
623
|
+
}
|
|
624
|
+
/**
|
|
625
|
+
* Index information (placeholder for future index management).
|
|
626
|
+
*/
|
|
627
|
+
interface IndexInfo {
|
|
628
|
+
/** Index name. */
|
|
629
|
+
name: string;
|
|
630
|
+
/** Indexed column names. */
|
|
631
|
+
columns: string[];
|
|
632
|
+
/** Whether index enforces uniqueness. */
|
|
633
|
+
isUnique: boolean;
|
|
634
|
+
}
|
|
635
|
+
/**
|
|
636
|
+
* Relationship between tables for ERD visualization.
|
|
637
|
+
*/
|
|
638
|
+
interface RelationshipInfo {
|
|
639
|
+
/** Source column of the relationship. */
|
|
640
|
+
from: RelationshipEndpoint;
|
|
641
|
+
/** Target table and column. */
|
|
642
|
+
to: RelationshipEndpoint;
|
|
643
|
+
/** Whether this relationship was declared or inferred. */
|
|
644
|
+
source: "declared" | "inferred";
|
|
645
|
+
/** Cardinality of the relationship. */
|
|
646
|
+
cardinality: "many-to-one" | "one-to-one" | "one-to-many";
|
|
647
|
+
}
|
|
648
|
+
/**
|
|
649
|
+
* Endpoint of a relationship (from or to side).
|
|
650
|
+
*/
|
|
651
|
+
interface RelationshipEndpoint {
|
|
652
|
+
/** Table name (required for "to" side, optional for "from" side in single-table context). */
|
|
653
|
+
table?: string;
|
|
654
|
+
/** Column name. */
|
|
655
|
+
column: string;
|
|
656
|
+
}
|
|
657
|
+
/**
|
|
658
|
+
* Response for relationships() — all tables with relationships for ERD.
|
|
659
|
+
*/
|
|
660
|
+
interface SchemaRelationshipsResponse {
|
|
661
|
+
/** All tables with column summaries. */
|
|
662
|
+
tables: TableSummaryForErd[];
|
|
663
|
+
/** All relationships (declared and inferred) across all tables. */
|
|
664
|
+
relationships: RelationshipInfo[];
|
|
665
|
+
}
|
|
666
|
+
/**
|
|
667
|
+
* Simplified table summary for ERD visualization.
|
|
668
|
+
*/
|
|
669
|
+
interface TableSummaryForErd {
|
|
670
|
+
/** Table name. */
|
|
671
|
+
name: string;
|
|
672
|
+
/** Column summaries. */
|
|
673
|
+
columns: ColumnSummaryForErd[];
|
|
674
|
+
}
|
|
675
|
+
/**
|
|
676
|
+
* Simplified column summary for ERD visualization.
|
|
677
|
+
*/
|
|
678
|
+
interface ColumnSummaryForErd {
|
|
679
|
+
/** Column name. */
|
|
680
|
+
name: string;
|
|
681
|
+
/** Data type. */
|
|
682
|
+
type: string;
|
|
683
|
+
/** Whether this column is part of the primary key. */
|
|
684
|
+
isPrimaryKey?: boolean;
|
|
685
|
+
/** Whether this column references another table. */
|
|
686
|
+
isReference?: boolean;
|
|
687
|
+
}
|
|
688
|
+
/**
|
|
689
|
+
* Options for TypeScript type generation.
|
|
690
|
+
*/
|
|
691
|
+
interface TypeGenerationOptions {
|
|
692
|
+
/** Include JSDoc comments in output (default: true). */
|
|
693
|
+
comments?: boolean;
|
|
694
|
+
/** Include Schema interface and TableName type (default: true). */
|
|
695
|
+
schema?: boolean;
|
|
696
|
+
/** Optional namespace wrapper for the generated types. */
|
|
697
|
+
namespace?: string;
|
|
698
|
+
}
|
|
699
|
+
/**
|
|
700
|
+
* Result of an insert operation.
|
|
701
|
+
*/
|
|
702
|
+
interface InsertResult {
|
|
703
|
+
/** Number of rows successfully inserted. */
|
|
704
|
+
rowsInserted: number;
|
|
705
|
+
/** Server-side execution time in milliseconds. */
|
|
706
|
+
executionMs: number;
|
|
707
|
+
/** Generated values for auto-increment columns. Keys are row indices (as strings). */
|
|
708
|
+
generatedValues?: Record<string, Record<string, unknown>>;
|
|
709
|
+
}
|
|
710
|
+
/**
|
|
711
|
+
* Result of an update or delete operation.
|
|
712
|
+
*/
|
|
713
|
+
interface MutationResult {
|
|
714
|
+
/** Number of rows affected by the operation. */
|
|
715
|
+
rowsAffected: number;
|
|
716
|
+
/** Server-side execution time in milliseconds. */
|
|
717
|
+
executionMs: number;
|
|
718
|
+
/** True when a limited delete can continue with additional matching rows. */
|
|
719
|
+
hasMore?: boolean;
|
|
720
|
+
/**
|
|
721
|
+
* Rows returned by a RETURNING clause. Present only when `returning` was specified.
|
|
722
|
+
* For UPDATE: post-update values. For DELETE: pre-delete values.
|
|
723
|
+
*/
|
|
724
|
+
rows?: Record<string, unknown>[];
|
|
725
|
+
/**
|
|
726
|
+
* True when the RETURNING row count exceeded the server maximum (10 000)
|
|
727
|
+
* and the result was truncated to the first 10 000 rows.
|
|
728
|
+
*/
|
|
729
|
+
rowsTruncated?: boolean;
|
|
730
|
+
}
|
|
731
|
+
/**
|
|
732
|
+
* Per-operation result for batch mutations.
|
|
733
|
+
*/
|
|
734
|
+
interface BatchMutationOperationResult {
|
|
735
|
+
/** Operation index in request order. */
|
|
736
|
+
index: number;
|
|
737
|
+
/** Operation kind. */
|
|
738
|
+
operationType: "update" | "delete";
|
|
739
|
+
/** Rows affected by this operation. */
|
|
740
|
+
rowsAffected: number;
|
|
741
|
+
/** For limited deletes, true means additional rows still match. */
|
|
742
|
+
hasMore?: boolean;
|
|
743
|
+
}
|
|
744
|
+
/**
|
|
745
|
+
* Result of a batch mutation execution.
|
|
746
|
+
*/
|
|
747
|
+
interface BatchMutationResult {
|
|
748
|
+
/** Per-operation results in request order. */
|
|
749
|
+
operationResults: BatchMutationOperationResult[];
|
|
750
|
+
/** Aggregate rows affected across all operations. */
|
|
751
|
+
totalRowsAffected: number;
|
|
752
|
+
/** Server-side execution time in milliseconds. */
|
|
753
|
+
executionMs: number;
|
|
754
|
+
}
|
|
755
|
+
/**
|
|
756
|
+
* Literal (constant) value node.
|
|
757
|
+
* @internal
|
|
758
|
+
*/
|
|
759
|
+
interface LiteralScalarExpr {
|
|
760
|
+
type: "literal";
|
|
761
|
+
value: unknown;
|
|
762
|
+
}
|
|
763
|
+
/**
|
|
764
|
+
* Column reference node — reads another column in the same row.
|
|
765
|
+
* @internal
|
|
766
|
+
*/
|
|
767
|
+
interface ColRefScalarExpr {
|
|
768
|
+
type: "colRef";
|
|
769
|
+
col: string;
|
|
770
|
+
}
|
|
771
|
+
/**
|
|
772
|
+
* Binary arithmetic node. op must be "+", "-", "*", or "/".
|
|
773
|
+
* @internal
|
|
774
|
+
*/
|
|
775
|
+
interface ArithmeticScalarExpr {
|
|
776
|
+
type: "arithmetic";
|
|
777
|
+
op: "+" | "-" | "*" | "/";
|
|
778
|
+
left: ScalarExprNode;
|
|
779
|
+
right: ScalarExprNode;
|
|
780
|
+
}
|
|
781
|
+
/**
|
|
782
|
+
* Coalesce node — returns the first non-null argument.
|
|
783
|
+
* @internal
|
|
784
|
+
*/
|
|
785
|
+
interface CoalesceScalarExpr {
|
|
786
|
+
type: "coalesce";
|
|
787
|
+
args: ScalarExprNode[];
|
|
788
|
+
}
|
|
789
|
+
/**
|
|
790
|
+
* Conditional (CASE WHEN) node. when is a WhereClause evaluated per row.
|
|
791
|
+
* @internal
|
|
792
|
+
*/
|
|
793
|
+
interface ConditionalScalarExpr {
|
|
794
|
+
type: "conditional";
|
|
795
|
+
when: WhereClause;
|
|
796
|
+
then: ScalarExprNode;
|
|
797
|
+
else: ScalarExprNode;
|
|
798
|
+
}
|
|
799
|
+
/**
|
|
800
|
+
* Discriminated union for scalar expression nodes in expression-based SET values.
|
|
801
|
+
* Named ScalarExprNode (not SetExprNode) to allow reuse for future SELECT projections.
|
|
802
|
+
* @internal
|
|
803
|
+
*/
|
|
804
|
+
type ScalarExprNode = LiteralScalarExpr | ColRefScalarExpr | ArithmeticScalarExpr | CoalesceScalarExpr | ConditionalScalarExpr;
|
|
805
|
+
/**
|
|
806
|
+
* A single server-side computed column definition for SELECT projections.
|
|
807
|
+
* Plain JSON object; the polymorphism lives in ScalarExprNode.
|
|
808
|
+
* @internal
|
|
809
|
+
*/
|
|
810
|
+
interface ComputedColumnDef {
|
|
811
|
+
/** Output column alias. Must be unique and must not collide with physical column names in the select list. */
|
|
812
|
+
alias: string;
|
|
813
|
+
/** Expression tree evaluated per row to produce the column value. */
|
|
814
|
+
expr: ScalarExprNode;
|
|
815
|
+
}
|
|
816
|
+
/**
|
|
817
|
+
* Request body for PATCH /api/tables/{name}/rows (update).
|
|
818
|
+
* @internal
|
|
819
|
+
*/
|
|
820
|
+
/**
|
|
821
|
+
* Options for `update()` on a query builder.
|
|
822
|
+
*/
|
|
823
|
+
interface UpdateOptions {
|
|
824
|
+
/**
|
|
825
|
+
* Columns to include in the RETURNING clause.
|
|
826
|
+
* Use `["*"]` to return all columns.
|
|
827
|
+
* Returned rows reflect post-update values.
|
|
828
|
+
*/
|
|
829
|
+
returning?: string[];
|
|
830
|
+
}
|
|
831
|
+
/**
|
|
832
|
+
* Options for `delete()` on a query builder.
|
|
833
|
+
*/
|
|
834
|
+
interface DeleteOptions {
|
|
835
|
+
/**
|
|
836
|
+
* Columns to include in the RETURNING clause.
|
|
837
|
+
* Use `["*"]` to return all columns.
|
|
838
|
+
* Returned rows reflect pre-delete values.
|
|
839
|
+
*/
|
|
840
|
+
returning?: string[];
|
|
841
|
+
}
|
|
842
|
+
/** Valid Aouda column types per wire protocol Data Types. */
|
|
843
|
+
declare const AOUDA_DATA_TYPES: readonly ["Bool", "Byte", "Int16", "Int32", "Int64", "UInt16", "UInt32", "UInt64", "Float32", "Double", "Decimal", "String", "Timestamp", "Date", "Guid"];
|
|
844
|
+
type AoudaDataType = (typeof AOUDA_DATA_TYPES)[number];
|
|
845
|
+
/** Partition function applied to partition key columns at insert time. */
|
|
846
|
+
type PartitionFunction = "None" | "TruncateToDay" | "TruncateToHour" | "TruncateToMinute" | "TruncateToWeek" | "TruncateToMonth" | "TruncateToYear";
|
|
847
|
+
/**
|
|
848
|
+
* Column definition when creating a table (POST /api/databases/{db}/tables).
|
|
849
|
+
*/
|
|
850
|
+
interface CreateColumnRequest {
|
|
851
|
+
name: string;
|
|
852
|
+
type: string;
|
|
853
|
+
/** Whether the column allows null values. */
|
|
854
|
+
isNullable?: boolean;
|
|
855
|
+
primaryKeyOrder?: number;
|
|
856
|
+
partitionKeyOrder?: number;
|
|
857
|
+
clusterOrder?: number;
|
|
858
|
+
partitionFunction?: PartitionFunction;
|
|
859
|
+
reference?: {
|
|
860
|
+
targetTable: string;
|
|
861
|
+
targetColumn: string;
|
|
862
|
+
};
|
|
863
|
+
isAutoIncrement?: boolean;
|
|
864
|
+
}
|
|
865
|
+
/**
|
|
866
|
+
* Request body for creating a table. Must include database (required by server in multi-db).
|
|
867
|
+
*/
|
|
868
|
+
interface CreateTableRequest {
|
|
869
|
+
database: string;
|
|
870
|
+
name: string;
|
|
871
|
+
columns: CreateColumnRequest[];
|
|
872
|
+
policy?: {
|
|
873
|
+
storageTemperature?: string;
|
|
874
|
+
};
|
|
875
|
+
authMode?: AuthorizationMode;
|
|
876
|
+
permissionDimension?: string;
|
|
877
|
+
rlsResolverName?: string;
|
|
878
|
+
}
|
|
879
|
+
/**
|
|
880
|
+
* Request body for renaming a table (PATCH /api/databases/{db}/tables/{name}).
|
|
881
|
+
*/
|
|
882
|
+
interface RenameTableRequest {
|
|
883
|
+
database: string;
|
|
884
|
+
newName: string;
|
|
885
|
+
}
|
|
886
|
+
/**
|
|
887
|
+
* Request body for adding a column (POST /api/databases/{db}/tables/{name}/columns).
|
|
888
|
+
*/
|
|
889
|
+
interface AddColumnRequest {
|
|
890
|
+
database: string;
|
|
891
|
+
name: string;
|
|
892
|
+
type: string;
|
|
893
|
+
}
|
|
894
|
+
/**
|
|
895
|
+
* Request body for renaming a column (PATCH /api/databases/{db}/tables/{name}/columns/{columnName}).
|
|
896
|
+
*/
|
|
897
|
+
interface RenameColumnRequest {
|
|
898
|
+
database: string;
|
|
899
|
+
newName: string;
|
|
900
|
+
}
|
|
901
|
+
/**
|
|
902
|
+
* Request body for updating a table's storage policy (PUT /api/databases/{db}/tables/{name}/policy).
|
|
903
|
+
* When calling client.tables.updatePolicy(name, body), the client injects database from the scoped client.
|
|
904
|
+
* storageTemperature: "Auto" | "HotOnly" | "ColdPreferred".
|
|
905
|
+
*/
|
|
906
|
+
interface UpdateTablePolicyRequest {
|
|
907
|
+
storageTemperature: string;
|
|
908
|
+
}
|
|
909
|
+
/**
|
|
910
|
+
* Database options in server response (camelCase).
|
|
911
|
+
*/
|
|
912
|
+
interface DatabaseOptionsInfo {
|
|
913
|
+
maxMemoryBytes?: number | null;
|
|
914
|
+
defaultTemperature: string;
|
|
915
|
+
enableWal: boolean;
|
|
916
|
+
replicationMode: string;
|
|
917
|
+
}
|
|
918
|
+
/**
|
|
919
|
+
* Database info returned by list/create/get (camelCase, matches server JSON).
|
|
920
|
+
*/
|
|
921
|
+
interface DatabaseInfo {
|
|
922
|
+
name: string;
|
|
923
|
+
state: string;
|
|
924
|
+
createdAt: string;
|
|
925
|
+
options: DatabaseOptionsInfo;
|
|
926
|
+
}
|
|
927
|
+
/**
|
|
928
|
+
* Options when creating a database (camelCase, matches server request).
|
|
929
|
+
*/
|
|
930
|
+
interface CreateDatabaseOptions {
|
|
931
|
+
enableWal?: boolean;
|
|
932
|
+
replicationMode?: string;
|
|
933
|
+
maxMemoryBytes?: number | null;
|
|
934
|
+
defaultTemperature?: string | null;
|
|
935
|
+
}
|
|
936
|
+
interface BulkLoadOptions {
|
|
937
|
+
embeddingModelVersion?: string;
|
|
938
|
+
maxRowsPerSegment?: number;
|
|
939
|
+
conflictPolicy?: "block" | "failFast";
|
|
940
|
+
pkUniquenessOverride?: "strict" | "recent" | "bestEffort";
|
|
941
|
+
/** Replication policy. See ADR 0030. */
|
|
942
|
+
replicationMode?: "logShipSegments" | "skipReplication" | "markForSnapshot";
|
|
943
|
+
/** Two-key safety for "skipReplication" on multi-node clusters. */
|
|
944
|
+
forceSingleNodeReplicationBypass?: boolean;
|
|
945
|
+
/** Post-load materialized-query behavior. */
|
|
946
|
+
postLoadMqBehavior?: "auto" | "skip";
|
|
947
|
+
/** Write-concern barrier at commit. Default "acknowledged". */
|
|
948
|
+
writeConcern?: "acknowledged" | "majority" | "all";
|
|
949
|
+
/** Max wait for the write-concern barrier in milliseconds. Default 300000 (5 min). */
|
|
950
|
+
writeConcernTimeoutMs?: number;
|
|
951
|
+
/** Max rows per :append call. Default 50000. Server caps take precedence if lower. */
|
|
952
|
+
appendBatchSize?: number;
|
|
953
|
+
/** If true, wait for deferred work before resolving. Default false. */
|
|
954
|
+
waitForDeferredWork?: boolean;
|
|
955
|
+
/** Idempotency key. Strongly recommended for production; enables resume from durable cursor. */
|
|
956
|
+
idempotencyKey?: string;
|
|
957
|
+
/** Progress callback invoked after each :append and once during :commit. */
|
|
958
|
+
onProgress?: (progress: BulkLoadProgress) => void;
|
|
959
|
+
/** AbortSignal for cancellation. Issues :abort on the server before throwing. */
|
|
960
|
+
signal?: AbortSignal;
|
|
961
|
+
}
|
|
962
|
+
interface BulkLoadProgress {
|
|
963
|
+
ivfAssignmentsCompleted: number;
|
|
964
|
+
ivfAssignmentsTotal: number;
|
|
965
|
+
raBitQEncodingsCompleted: number;
|
|
966
|
+
raBitQEncodingsTotal: number;
|
|
967
|
+
cscMirrorsCompleted: number;
|
|
968
|
+
cscMirrorsTotal: number;
|
|
969
|
+
pkIndexRebuildCompleted: number;
|
|
970
|
+
pkIndexRebuildTotal: number;
|
|
971
|
+
replicas: BulkLoadReplicaProgress[];
|
|
972
|
+
}
|
|
973
|
+
interface BulkLoadReplicaProgress {
|
|
974
|
+
serverId: string;
|
|
975
|
+
segmentsFetched: number;
|
|
976
|
+
segmentsTotal: number;
|
|
977
|
+
lagSeconds: number;
|
|
978
|
+
}
|
|
979
|
+
interface BulkLoadJobHandle {
|
|
980
|
+
readonly jobId: string;
|
|
981
|
+
readonly tables: readonly string[];
|
|
982
|
+
readonly rowsLoaded: number;
|
|
983
|
+
readonly perTableRowCounts: Readonly<Record<string, number>>;
|
|
984
|
+
readonly rowsDurablyCommitted: number;
|
|
985
|
+
readonly segmentsCreated: number;
|
|
986
|
+
readonly committedAtUtc: string;
|
|
987
|
+
readonly walPosition: number;
|
|
988
|
+
readonly writeConcernSatisfied: "acknowledged" | "majority" | "all";
|
|
989
|
+
readonly writeConcernTimedOut: boolean;
|
|
990
|
+
/** True if this load was resumed from a server-restart-recovered job. */
|
|
991
|
+
readonly wasResumed: boolean;
|
|
992
|
+
/** Resolves when deferred work is done. Polls the server with exponential backoff. */
|
|
993
|
+
readonly deferredWorkCompletion: Promise<BulkLoadProgress>;
|
|
994
|
+
/** One-off progress snapshot. */
|
|
995
|
+
getProgress(): Promise<BulkLoadProgress>;
|
|
996
|
+
}
|
|
997
|
+
interface BulkLoadStatusResponse {
|
|
998
|
+
jobId: string;
|
|
999
|
+
tables: string[];
|
|
1000
|
+
state: "acquired" | "appending" | "committing" | "deferred" | "completed" | "failed" | "aborted" | string;
|
|
1001
|
+
rowsAppendedToBuffer: number;
|
|
1002
|
+
rowsDurablyCommitted: number;
|
|
1003
|
+
segmentsSealed: number;
|
|
1004
|
+
startedAtUtc: string;
|
|
1005
|
+
lastUpdatedUtc: string;
|
|
1006
|
+
progress?: BulkLoadProgressDto;
|
|
1007
|
+
replicas: BulkLoadReplicaProgressDto[];
|
|
1008
|
+
error?: string;
|
|
1009
|
+
errorCode?: string;
|
|
1010
|
+
mqRebuildStatus?: "pending" | "inProgress" | "completed" | "skipped" | "failed" | string;
|
|
1011
|
+
}
|
|
1012
|
+
/** Response for GET /api/databases/{db}/bulk-load:list. */
|
|
1013
|
+
interface BulkLoadListResponse {
|
|
1014
|
+
database: string;
|
|
1015
|
+
jobs: BulkLoadStatusResponse[];
|
|
1016
|
+
snapshotUtc: string;
|
|
1017
|
+
}
|
|
1018
|
+
/** Request body for POST /api/databases/{db}/bulk-load:force-abort. */
|
|
1019
|
+
interface BulkLoadForceAbortRequest {
|
|
1020
|
+
database: string;
|
|
1021
|
+
jobId: string;
|
|
1022
|
+
/** Operator-supplied reason recorded in the WAL frame. Required. */
|
|
1023
|
+
reason: string;
|
|
1024
|
+
}
|
|
1025
|
+
/** Response for POST /api/databases/{db}/bulk-load:force-abort. */
|
|
1026
|
+
interface BulkLoadForceAbortResponse {
|
|
1027
|
+
jobId: string;
|
|
1028
|
+
aborted: boolean;
|
|
1029
|
+
}
|
|
1030
|
+
/** @internal */
|
|
1031
|
+
interface BulkLoadProgressDto {
|
|
1032
|
+
ivfAssignmentsCompleted: number;
|
|
1033
|
+
ivfAssignmentsTotal: number;
|
|
1034
|
+
raBitQEncodingsCompleted: number;
|
|
1035
|
+
raBitQEncodingsTotal: number;
|
|
1036
|
+
cscMirrorsCompleted: number;
|
|
1037
|
+
cscMirrorsTotal: number;
|
|
1038
|
+
pkIndexRebuildCompleted: number;
|
|
1039
|
+
pkIndexRebuildTotal: number;
|
|
1040
|
+
}
|
|
1041
|
+
interface BulkLoadReplicaProgressDto {
|
|
1042
|
+
serverId: string;
|
|
1043
|
+
segmentsFetched: number;
|
|
1044
|
+
segmentsTotal: number;
|
|
1045
|
+
lagSeconds: number;
|
|
1046
|
+
}
|
|
1047
|
+
|
|
1048
|
+
/**
|
|
1049
|
+
* HTTP transport layer for @aouda/client.
|
|
1050
|
+
* Internal use only — not exported from the package.
|
|
1051
|
+
*/
|
|
1052
|
+
|
|
1053
|
+
/**
|
|
1054
|
+
* Transport interface used by the client for all server calls.
|
|
1055
|
+
* Implemented by HttpTransport and ResilientTransport (wrapper).
|
|
1056
|
+
*/
|
|
1057
|
+
interface Transport {
|
|
1058
|
+
request<T>(config: RequestConfig): Promise<T>;
|
|
1059
|
+
requestRaw(config: RequestConfig): Promise<Response>;
|
|
1060
|
+
get<T>(path: string, options?: RequestOptions): Promise<T>;
|
|
1061
|
+
post<T>(path: string, body: unknown, options?: RequestOptions): Promise<T>;
|
|
1062
|
+
put<T>(path: string, body: unknown, options?: RequestOptions): Promise<T>;
|
|
1063
|
+
patch<T>(path: string, body: unknown, options?: RequestOptions): Promise<T>;
|
|
1064
|
+
delete<T>(path: string, body?: unknown, options?: RequestOptions): Promise<T>;
|
|
1065
|
+
getText(path: string, options?: RequestOptions): Promise<string>;
|
|
1066
|
+
/**
|
|
1067
|
+
* POST a raw string body (e.g. NDJSON) without JSON serialization.
|
|
1068
|
+
* The caller sets Content-Type via options.headers.
|
|
1069
|
+
*/
|
|
1070
|
+
postRaw<T>(path: string, rawBody: string, contentType: string, options?: RequestOptions): Promise<T>;
|
|
1071
|
+
/** List all bulk-load sessions for a database (admin). */
|
|
1072
|
+
bulkLoadList(db: string): Promise<BulkLoadListResponse>;
|
|
1073
|
+
/** Force-abort a stuck bulk-load job by emitting a BulkLoadAborted WAL frame (admin). */
|
|
1074
|
+
bulkLoadForceAbort(db: string, jobId: string, reason: string): Promise<BulkLoadForceAbortResponse>;
|
|
1075
|
+
abort(): void;
|
|
1076
|
+
reset(): void;
|
|
1077
|
+
}
|
|
1078
|
+
|
|
1079
|
+
/**
|
|
1080
|
+
* Response types for admin API (server info, memory, metrics, health).
|
|
1081
|
+
* Aligned with Aouda server JSON (camelCase).
|
|
1082
|
+
*/
|
|
1083
|
+
/** Service information from GET /. */
|
|
1084
|
+
interface ServiceInfo {
|
|
1085
|
+
service: string;
|
|
1086
|
+
version: string;
|
|
1087
|
+
status: string;
|
|
1088
|
+
tables: number;
|
|
1089
|
+
databases: number;
|
|
1090
|
+
}
|
|
1091
|
+
/** Per-database memory in server memory response. */
|
|
1092
|
+
interface DatabaseMemoryUsage {
|
|
1093
|
+
databaseName: string;
|
|
1094
|
+
totalBytes: number;
|
|
1095
|
+
budgetBytes: number | null;
|
|
1096
|
+
hotSegmentBytes: number;
|
|
1097
|
+
pageCacheBytes: number;
|
|
1098
|
+
bloomFilterBytes: number;
|
|
1099
|
+
tableCount: number;
|
|
1100
|
+
pressure: string;
|
|
1101
|
+
perTableBytes: Record<string, number>;
|
|
1102
|
+
}
|
|
1103
|
+
/** Server-wide memory usage from GET /api/server/memory. */
|
|
1104
|
+
interface ServerMemoryResponse {
|
|
1105
|
+
serverTotalBytes: number;
|
|
1106
|
+
serverMaxBytes: number;
|
|
1107
|
+
sharedPoolBytes: number;
|
|
1108
|
+
sharedPoolUsedBytes: number;
|
|
1109
|
+
databaseCount: number;
|
|
1110
|
+
perDatabaseUsage: Record<string, DatabaseMemoryUsage>;
|
|
1111
|
+
timestamp: string;
|
|
1112
|
+
}
|
|
1113
|
+
/** Per-database metrics DTO in server metrics response. */
|
|
1114
|
+
interface DatabaseMetricsDto {
|
|
1115
|
+
totalBytes: number;
|
|
1116
|
+
budgetBytes: number | null;
|
|
1117
|
+
hotSegmentBytes: number;
|
|
1118
|
+
bloomFilterBytes: number;
|
|
1119
|
+
pressure: string;
|
|
1120
|
+
tableCount: number;
|
|
1121
|
+
queryCount: number;
|
|
1122
|
+
queryMs: number;
|
|
1123
|
+
rowsReturned: number;
|
|
1124
|
+
insertCount: number;
|
|
1125
|
+
rowsInserted: number;
|
|
1126
|
+
insertMs: number;
|
|
1127
|
+
perTableBytes: Record<string, number>;
|
|
1128
|
+
}
|
|
1129
|
+
/** Server-wide per-database metrics from GET /api/server/metrics. */
|
|
1130
|
+
interface ServerMetricsResponse {
|
|
1131
|
+
databases: Record<string, DatabaseMetricsDto>;
|
|
1132
|
+
}
|
|
1133
|
+
/** Single database metrics from GET /api/server/databases/{db}/metrics. */
|
|
1134
|
+
interface SingleDatabaseMetricsResponse {
|
|
1135
|
+
databaseName: string;
|
|
1136
|
+
totalBytes: number;
|
|
1137
|
+
budgetBytes: number | null;
|
|
1138
|
+
hotSegmentBytes: number;
|
|
1139
|
+
bloomFilterBytes: number;
|
|
1140
|
+
pressure: string;
|
|
1141
|
+
tableCount: number;
|
|
1142
|
+
engineAccessible: boolean;
|
|
1143
|
+
queryCount: number;
|
|
1144
|
+
queryMs: number;
|
|
1145
|
+
rowsReturned: number;
|
|
1146
|
+
insertCount: number;
|
|
1147
|
+
rowsInserted: number;
|
|
1148
|
+
insertMs: number;
|
|
1149
|
+
perTableBytes: Record<string, number>;
|
|
1150
|
+
}
|
|
1151
|
+
/** Readiness probe response from GET /ready. */
|
|
1152
|
+
interface ReadinessResponse {
|
|
1153
|
+
ready: boolean;
|
|
1154
|
+
reason: string | null;
|
|
1155
|
+
}
|
|
1156
|
+
/** Component entry in detailed health response. */
|
|
1157
|
+
interface ComponentHealthEntry {
|
|
1158
|
+
status: string;
|
|
1159
|
+
isCritical: boolean;
|
|
1160
|
+
reason?: string | null;
|
|
1161
|
+
details?: Record<string, unknown> | null;
|
|
1162
|
+
}
|
|
1163
|
+
/** Detailed health from GET /health/detailed. */
|
|
1164
|
+
interface DetailedHealthResponse {
|
|
1165
|
+
status: string;
|
|
1166
|
+
timestamp: string;
|
|
1167
|
+
serverRole: string;
|
|
1168
|
+
checkDurationMs: number;
|
|
1169
|
+
components: Record<string, ComponentHealthEntry>;
|
|
1170
|
+
}
|
|
1171
|
+
|
|
1172
|
+
/**
|
|
1173
|
+
* Server admin API: info, memory, metrics.
|
|
1174
|
+
* Access via client.admin.server.
|
|
1175
|
+
*/
|
|
1176
|
+
|
|
1177
|
+
declare class ServerAdminApi {
|
|
1178
|
+
private readonly transport;
|
|
1179
|
+
constructor(transport: Transport);
|
|
1180
|
+
/**
|
|
1181
|
+
* Service information (name, version, status, table/database counts).
|
|
1182
|
+
* GET /
|
|
1183
|
+
*/
|
|
1184
|
+
info(): Promise<ServiceInfo>;
|
|
1185
|
+
/**
|
|
1186
|
+
* Server-wide memory usage with per-database breakdown.
|
|
1187
|
+
* GET /api/server/memory
|
|
1188
|
+
*/
|
|
1189
|
+
memory(): Promise<ServerMemoryResponse>;
|
|
1190
|
+
/**
|
|
1191
|
+
* Per-database metrics summary for all databases.
|
|
1192
|
+
* GET /api/server/metrics
|
|
1193
|
+
*/
|
|
1194
|
+
metrics(): Promise<ServerMetricsResponse>;
|
|
1195
|
+
/**
|
|
1196
|
+
* Combined metrics for a single database.
|
|
1197
|
+
* GET /api/server/databases/{db}/metrics
|
|
1198
|
+
*
|
|
1199
|
+
* @param databaseName - Database name.
|
|
1200
|
+
*/
|
|
1201
|
+
databaseMetrics(databaseName: string): Promise<SingleDatabaseMetricsResponse>;
|
|
1202
|
+
}
|
|
1203
|
+
|
|
1204
|
+
/**
|
|
1205
|
+
* Health admin API: check, ready, detailed.
|
|
1206
|
+
* Access via client.admin.health.
|
|
1207
|
+
*/
|
|
1208
|
+
|
|
1209
|
+
declare class HealthAdminApi {
|
|
1210
|
+
private readonly transport;
|
|
1211
|
+
constructor(transport: Transport);
|
|
1212
|
+
/**
|
|
1213
|
+
* Basic liveness probe. Same as client.health().
|
|
1214
|
+
* GET /health
|
|
1215
|
+
*/
|
|
1216
|
+
check(): Promise<HealthStatus>;
|
|
1217
|
+
/**
|
|
1218
|
+
* Readiness probe. Returns 200 when ready; on 503 returns parsed body (ready: false, reason).
|
|
1219
|
+
* GET /ready
|
|
1220
|
+
*/
|
|
1221
|
+
ready(): Promise<ReadinessResponse>;
|
|
1222
|
+
/**
|
|
1223
|
+
* Detailed component-level health. Returns 200 when healthy/degraded, 503 when unhealthy (body still returned).
|
|
1224
|
+
* GET /health/detailed
|
|
1225
|
+
*/
|
|
1226
|
+
detailed(): Promise<DetailedHealthResponse>;
|
|
1227
|
+
}
|
|
1228
|
+
|
|
1229
|
+
/**
|
|
1230
|
+
* Response types for admin metrics API.
|
|
1231
|
+
* Aligned with Aouda server JSON (camelCase) from MetricsSnapshot, MetricsSummary, MetricsHistory, SubsystemModels.
|
|
1232
|
+
*/
|
|
1233
|
+
/** Latency percentiles for response time metrics. */
|
|
1234
|
+
interface LatencyPercentiles {
|
|
1235
|
+
p50: number;
|
|
1236
|
+
p95: number;
|
|
1237
|
+
p99: number;
|
|
1238
|
+
}
|
|
1239
|
+
/** Query execution metrics. */
|
|
1240
|
+
interface QueryMetrics {
|
|
1241
|
+
total: number;
|
|
1242
|
+
active: number;
|
|
1243
|
+
totalMs: number;
|
|
1244
|
+
durationMs: LatencyPercentiles;
|
|
1245
|
+
rowsScanned: number;
|
|
1246
|
+
rowsReturned: number;
|
|
1247
|
+
hotAggregateOps: number;
|
|
1248
|
+
coldAggregateOps: number;
|
|
1249
|
+
hotScanRows: number;
|
|
1250
|
+
coldScanRows: number;
|
|
1251
|
+
parallelScans: number;
|
|
1252
|
+
vectorizedOps: number;
|
|
1253
|
+
fusedAggregateOps: number;
|
|
1254
|
+
}
|
|
1255
|
+
/** Page cache statistics. */
|
|
1256
|
+
interface PageCacheMetrics {
|
|
1257
|
+
bytes: number;
|
|
1258
|
+
entries: number;
|
|
1259
|
+
hits: number;
|
|
1260
|
+
misses: number;
|
|
1261
|
+
hitRatio: number;
|
|
1262
|
+
evictions: number;
|
|
1263
|
+
}
|
|
1264
|
+
/** Storage metrics for hot/cold segments. */
|
|
1265
|
+
interface StorageMetrics {
|
|
1266
|
+
hotSegments: number;
|
|
1267
|
+
coldSegments: number;
|
|
1268
|
+
hotBytes: number;
|
|
1269
|
+
coldBytes: number;
|
|
1270
|
+
demotions: number;
|
|
1271
|
+
promotions: number;
|
|
1272
|
+
pageCache: PageCacheMetrics;
|
|
1273
|
+
}
|
|
1274
|
+
/** Replication state metrics. */
|
|
1275
|
+
interface ReplicationMetrics {
|
|
1276
|
+
role: string;
|
|
1277
|
+
walPosition: number;
|
|
1278
|
+
lagBytes: number;
|
|
1279
|
+
lagSeconds: number;
|
|
1280
|
+
connectedPeers: number;
|
|
1281
|
+
canAcceptWrites: boolean;
|
|
1282
|
+
perDatabaseLag?: Record<string, number>;
|
|
1283
|
+
}
|
|
1284
|
+
/** Backup operation metrics. */
|
|
1285
|
+
interface BackupMetrics {
|
|
1286
|
+
operationsStarted: number;
|
|
1287
|
+
operationsCompleted: number;
|
|
1288
|
+
operationsFailed: number;
|
|
1289
|
+
blobsUploaded: number;
|
|
1290
|
+
bytesUploaded: number;
|
|
1291
|
+
restoreOperationsCompleted: number;
|
|
1292
|
+
}
|
|
1293
|
+
/** Partition operation metrics. */
|
|
1294
|
+
interface PartitioningMetrics {
|
|
1295
|
+
promotions: number;
|
|
1296
|
+
dedicatedPartitions: number;
|
|
1297
|
+
autoModePartitions: number;
|
|
1298
|
+
crossPartitionQueries: number;
|
|
1299
|
+
}
|
|
1300
|
+
/** Time-series/delta segment metrics. */
|
|
1301
|
+
interface TimeSeriesMetrics {
|
|
1302
|
+
deltaSegmentsCreated: number;
|
|
1303
|
+
lateArrivalsRouted: number;
|
|
1304
|
+
manifestsRead: number;
|
|
1305
|
+
segmentSummaryCount: number;
|
|
1306
|
+
}
|
|
1307
|
+
/** Materialized query metrics. */
|
|
1308
|
+
interface MaterializedQueryMetrics {
|
|
1309
|
+
active: number;
|
|
1310
|
+
lagMs: number;
|
|
1311
|
+
queueDepth: number;
|
|
1312
|
+
routes: number;
|
|
1313
|
+
}
|
|
1314
|
+
/** Bloom filter metrics. */
|
|
1315
|
+
interface BloomFilterMetrics {
|
|
1316
|
+
lookups: number;
|
|
1317
|
+
hits: number;
|
|
1318
|
+
misses: number;
|
|
1319
|
+
pagesPruned: number;
|
|
1320
|
+
adaptiveBytes: number;
|
|
1321
|
+
}
|
|
1322
|
+
/** Mini-transaction metrics. */
|
|
1323
|
+
interface TransactionMetrics {
|
|
1324
|
+
beginCount: number;
|
|
1325
|
+
commitCount: number;
|
|
1326
|
+
abortCount: number;
|
|
1327
|
+
rowsCommitted: number;
|
|
1328
|
+
activeCount: number;
|
|
1329
|
+
}
|
|
1330
|
+
/** Per-database memory metrics (memory subsystem). */
|
|
1331
|
+
interface DatabaseMemoryMetrics {
|
|
1332
|
+
totalBytes: number;
|
|
1333
|
+
budgetBytes: number | null;
|
|
1334
|
+
hotBytes: number;
|
|
1335
|
+
bloomBytes: number;
|
|
1336
|
+
tableCount: number;
|
|
1337
|
+
pressure: string;
|
|
1338
|
+
}
|
|
1339
|
+
/** Memory budget metrics. */
|
|
1340
|
+
interface MemoryMetrics {
|
|
1341
|
+
totalBudgetBytes: number;
|
|
1342
|
+
hotBytes: number;
|
|
1343
|
+
cacheBytes: number;
|
|
1344
|
+
evictions: number;
|
|
1345
|
+
perDatabase?: Record<string, DatabaseMemoryMetrics>;
|
|
1346
|
+
}
|
|
1347
|
+
/** I/O operation metrics. */
|
|
1348
|
+
interface IoMetrics {
|
|
1349
|
+
totalMs: number;
|
|
1350
|
+
pageReadCount: number;
|
|
1351
|
+
pageReadBytes: number;
|
|
1352
|
+
pageReadMs: number;
|
|
1353
|
+
decodeCount: number;
|
|
1354
|
+
decodeMs: number;
|
|
1355
|
+
}
|
|
1356
|
+
/** SIMD intrinsics metrics. */
|
|
1357
|
+
interface SimdMetrics {
|
|
1358
|
+
avx2Ops: number;
|
|
1359
|
+
sse2Ops: number;
|
|
1360
|
+
advSimdOps: number;
|
|
1361
|
+
scalarFallbacks: number;
|
|
1362
|
+
intrinsicsAvailable: number;
|
|
1363
|
+
}
|
|
1364
|
+
/** Per-database metrics in full snapshot (memory + operations). */
|
|
1365
|
+
interface PerDatabaseMetrics {
|
|
1366
|
+
totalBytes: number;
|
|
1367
|
+
budgetBytes: number | null;
|
|
1368
|
+
hotSegmentBytes: number;
|
|
1369
|
+
bloomFilterBytes: number;
|
|
1370
|
+
pressure: string;
|
|
1371
|
+
tableCount: number;
|
|
1372
|
+
queryCount: number;
|
|
1373
|
+
queryMs: number;
|
|
1374
|
+
rowsReturned: number;
|
|
1375
|
+
insertCount: number;
|
|
1376
|
+
rowsInserted: number;
|
|
1377
|
+
insertMs: number;
|
|
1378
|
+
perTableBytes?: Record<string, number>;
|
|
1379
|
+
}
|
|
1380
|
+
/** Full metrics snapshot from GET /api/admin/metrics. */
|
|
1381
|
+
interface MetricsSnapshot {
|
|
1382
|
+
timestamp: string;
|
|
1383
|
+
uptimeSeconds: number;
|
|
1384
|
+
query: QueryMetrics;
|
|
1385
|
+
storage: StorageMetrics;
|
|
1386
|
+
replication: ReplicationMetrics;
|
|
1387
|
+
backup: BackupMetrics;
|
|
1388
|
+
partitioning: PartitioningMetrics;
|
|
1389
|
+
timeSeries: TimeSeriesMetrics;
|
|
1390
|
+
materializedQueries: MaterializedQueryMetrics;
|
|
1391
|
+
bloomFilters: BloomFilterMetrics;
|
|
1392
|
+
transactions: TransactionMetrics;
|
|
1393
|
+
memory: MemoryMetrics;
|
|
1394
|
+
io: IoMetrics;
|
|
1395
|
+
simd: SimdMetrics;
|
|
1396
|
+
databases?: Record<string, PerDatabaseMetrics>;
|
|
1397
|
+
}
|
|
1398
|
+
/** Lightweight metrics summary from GET /api/admin/metrics/summary. */
|
|
1399
|
+
interface MetricsSummary {
|
|
1400
|
+
timestamp: string;
|
|
1401
|
+
status: string;
|
|
1402
|
+
queriesPerSecond: number;
|
|
1403
|
+
hotMemoryPercent: number;
|
|
1404
|
+
replicationLagMs: number;
|
|
1405
|
+
cacheHitRatio: number;
|
|
1406
|
+
lastBackupHoursAgo: number;
|
|
1407
|
+
activeConnections: number;
|
|
1408
|
+
activeMaterializedQueries: number;
|
|
1409
|
+
databaseCount: number;
|
|
1410
|
+
}
|
|
1411
|
+
/** Historical metrics from GET /api/admin/metrics/history. */
|
|
1412
|
+
interface MetricsHistory {
|
|
1413
|
+
timestamps: string[];
|
|
1414
|
+
queriesPerSecond: number[];
|
|
1415
|
+
hotMemoryBytes: number[];
|
|
1416
|
+
replicationLagMs: number[];
|
|
1417
|
+
cacheHitRatio: number[];
|
|
1418
|
+
rowsScanned: number[];
|
|
1419
|
+
}
|
|
1420
|
+
/** Options for metrics history request. */
|
|
1421
|
+
interface MetricsHistoryOptions {
|
|
1422
|
+
/** Minutes of history (1–1440; server clamps). Default 60. */
|
|
1423
|
+
minutes?: number;
|
|
1424
|
+
/** Sampling interval in seconds (1–3600; server clamps). Default 60. */
|
|
1425
|
+
interval?: number;
|
|
1426
|
+
}
|
|
1427
|
+
|
|
1428
|
+
/**
|
|
1429
|
+
* Admin metrics API: snapshot, summary, subsystem, history.
|
|
1430
|
+
* Access via client.admin.metrics.
|
|
1431
|
+
*/
|
|
1432
|
+
|
|
1433
|
+
declare class MetricsAdminApi {
|
|
1434
|
+
private readonly transport;
|
|
1435
|
+
constructor(transport: Transport);
|
|
1436
|
+
/**
|
|
1437
|
+
* Full metrics snapshot with all subsystems.
|
|
1438
|
+
* GET /api/admin/metrics
|
|
1439
|
+
*/
|
|
1440
|
+
snapshot(): Promise<MetricsSnapshot>;
|
|
1441
|
+
/**
|
|
1442
|
+
* Lightweight metrics summary for dashboard cards.
|
|
1443
|
+
* GET /api/admin/metrics/summary
|
|
1444
|
+
*/
|
|
1445
|
+
summary(): Promise<MetricsSummary>;
|
|
1446
|
+
/**
|
|
1447
|
+
* Metrics for a specific subsystem (query, storage, replication, etc.).
|
|
1448
|
+
* GET /api/admin/metrics/{subsystem}
|
|
1449
|
+
* Returns 404 for unknown subsystem name.
|
|
1450
|
+
*
|
|
1451
|
+
* @param name - Subsystem name (e.g. query, storage, replication, memory, io).
|
|
1452
|
+
*/
|
|
1453
|
+
subsystem(name: string): Promise<Record<string, unknown>>;
|
|
1454
|
+
/**
|
|
1455
|
+
* Historical metrics for sparkline charts.
|
|
1456
|
+
* GET /api/admin/metrics/history?minutes=&interval=
|
|
1457
|
+
* Server clamps minutes to 1–1440, interval to 1–3600.
|
|
1458
|
+
*
|
|
1459
|
+
* @param options - Optional minutes (default 60) and interval in seconds (default 60).
|
|
1460
|
+
*/
|
|
1461
|
+
history(options?: MetricsHistoryOptions): Promise<MetricsHistory>;
|
|
1462
|
+
}
|
|
1463
|
+
|
|
1464
|
+
/**
|
|
1465
|
+
* Response types for admin replication API.
|
|
1466
|
+
* Aligned with Aouda server JSON (camelCase) from ReplicationModels.
|
|
1467
|
+
*/
|
|
1468
|
+
/** Per-database lag entry for GET /admin/replication/status. */
|
|
1469
|
+
interface PerDatabaseLagEntry {
|
|
1470
|
+
walPosition: number;
|
|
1471
|
+
primaryPosition: number;
|
|
1472
|
+
lagBytes: number;
|
|
1473
|
+
}
|
|
1474
|
+
/** Replication status response from GET /admin/replication/status. */
|
|
1475
|
+
interface ReplicationStatusResponse {
|
|
1476
|
+
role: string;
|
|
1477
|
+
currentPrimary: string | null;
|
|
1478
|
+
walPosition: number;
|
|
1479
|
+
lagBytes: number;
|
|
1480
|
+
fencingToken: number;
|
|
1481
|
+
canAcceptWrites: boolean;
|
|
1482
|
+
perDatabaseLag: Record<string, PerDatabaseLagEntry>;
|
|
1483
|
+
}
|
|
1484
|
+
/** Per-database status for a topology member. */
|
|
1485
|
+
interface PerDatabaseStatusEntry {
|
|
1486
|
+
walPosition: number;
|
|
1487
|
+
lagBytes: number;
|
|
1488
|
+
}
|
|
1489
|
+
/** Per-database table subscription info for a connected secondary. */
|
|
1490
|
+
interface SubscriptionInfo {
|
|
1491
|
+
database: string;
|
|
1492
|
+
filterMode: string;
|
|
1493
|
+
tableNames: string[];
|
|
1494
|
+
}
|
|
1495
|
+
/** Information about a replica set member. */
|
|
1496
|
+
interface MemberInfo {
|
|
1497
|
+
address: string;
|
|
1498
|
+
role: string;
|
|
1499
|
+
isSelf: boolean;
|
|
1500
|
+
temperatureProfile: string | null;
|
|
1501
|
+
isHidden: boolean;
|
|
1502
|
+
isReadCandidate: boolean;
|
|
1503
|
+
perDatabaseStatus: Record<string, PerDatabaseStatusEntry>;
|
|
1504
|
+
subscriptions?: SubscriptionInfo[] | null;
|
|
1505
|
+
}
|
|
1506
|
+
/** Topology response from GET /admin/replication/topology. */
|
|
1507
|
+
interface TopologyResponse {
|
|
1508
|
+
replicaSetName: string | null;
|
|
1509
|
+
members: MemberInfo[];
|
|
1510
|
+
readCandidates: string[];
|
|
1511
|
+
primary: string | null;
|
|
1512
|
+
}
|
|
1513
|
+
/** Per-table replication coverage entry. */
|
|
1514
|
+
interface TableCoverageEntry {
|
|
1515
|
+
replicationEnabled: boolean;
|
|
1516
|
+
subscriberCount: number;
|
|
1517
|
+
subscribers: string[];
|
|
1518
|
+
warning: string | null;
|
|
1519
|
+
}
|
|
1520
|
+
/** Per-database coverage info. */
|
|
1521
|
+
interface DatabaseCoverageEntry {
|
|
1522
|
+
tables: Record<string, TableCoverageEntry>;
|
|
1523
|
+
}
|
|
1524
|
+
/** Replication coverage response from GET /admin/replication/coverage. */
|
|
1525
|
+
interface CoverageResponse {
|
|
1526
|
+
databases: Record<string, DatabaseCoverageEntry>;
|
|
1527
|
+
}
|
|
1528
|
+
|
|
1529
|
+
/**
|
|
1530
|
+
* Admin replication API: status, topology, coverage.
|
|
1531
|
+
* Access via client.admin.replication.
|
|
1532
|
+
*/
|
|
1533
|
+
|
|
1534
|
+
declare class ReplicationAdminApi {
|
|
1535
|
+
private readonly transport;
|
|
1536
|
+
constructor(transport: Transport);
|
|
1537
|
+
/**
|
|
1538
|
+
* Current replication status (role, lag, fencing token, per-database lag).
|
|
1539
|
+
* GET /admin/replication/status
|
|
1540
|
+
*/
|
|
1541
|
+
status(): Promise<ReplicationStatusResponse>;
|
|
1542
|
+
/**
|
|
1543
|
+
* Replica set topology (members, read candidates, primary).
|
|
1544
|
+
* GET /admin/replication/topology
|
|
1545
|
+
*/
|
|
1546
|
+
topology(): Promise<TopologyResponse>;
|
|
1547
|
+
/**
|
|
1548
|
+
* Per-table replication coverage across all databases.
|
|
1549
|
+
* GET /admin/replication/coverage
|
|
1550
|
+
*/
|
|
1551
|
+
coverage(): Promise<CoverageResponse>;
|
|
1552
|
+
}
|
|
1553
|
+
|
|
1554
|
+
/**
|
|
1555
|
+
* Admin cluster lifecycle response/request types.
|
|
1556
|
+
* Mirrors Aouda server JSON payloads under /admin/cluster/*.
|
|
1557
|
+
*/
|
|
1558
|
+
type ClusterNodeRole = "secondary" | "witness";
|
|
1559
|
+
interface JoinClusterRequest {
|
|
1560
|
+
replicaSetName: string;
|
|
1561
|
+
primaryAddress: string;
|
|
1562
|
+
thisNodeAddress: string;
|
|
1563
|
+
role?: ClusterNodeRole;
|
|
1564
|
+
}
|
|
1565
|
+
interface JoinClusterResponse {
|
|
1566
|
+
message: string;
|
|
1567
|
+
replicaSetName: string;
|
|
1568
|
+
}
|
|
1569
|
+
interface LeaveClusterResponse {
|
|
1570
|
+
message: string;
|
|
1571
|
+
}
|
|
1572
|
+
interface PromoteClusterResponse {
|
|
1573
|
+
message: string;
|
|
1574
|
+
}
|
|
1575
|
+
interface FailoverClusterResponse {
|
|
1576
|
+
message: string;
|
|
1577
|
+
}
|
|
1578
|
+
interface DrainClusterResponse {
|
|
1579
|
+
nodeAddress: string;
|
|
1580
|
+
isDraining: boolean;
|
|
1581
|
+
}
|
|
1582
|
+
interface ClusterMemberEntry {
|
|
1583
|
+
address: string;
|
|
1584
|
+
isDraining: boolean;
|
|
1585
|
+
}
|
|
1586
|
+
interface ClusterThisNodeEntry {
|
|
1587
|
+
address?: string | null;
|
|
1588
|
+
priority: number;
|
|
1589
|
+
arbiter: boolean;
|
|
1590
|
+
}
|
|
1591
|
+
interface ClusterConfigResponse {
|
|
1592
|
+
mode: string;
|
|
1593
|
+
replicaSetName?: string | null;
|
|
1594
|
+
members?: ClusterMemberEntry[] | null;
|
|
1595
|
+
thisNode?: ClusterThisNodeEntry | null;
|
|
1596
|
+
heartbeatIntervalMs: number;
|
|
1597
|
+
electionTimeoutMs: number;
|
|
1598
|
+
}
|
|
1599
|
+
interface ClusterConfigPatchRequest {
|
|
1600
|
+
heartbeatIntervalMs?: number;
|
|
1601
|
+
electionTimeoutMs?: number;
|
|
1602
|
+
}
|
|
1603
|
+
|
|
1604
|
+
/**
|
|
1605
|
+
* Admin cluster lifecycle API.
|
|
1606
|
+
* Access via client.admin.cluster.
|
|
1607
|
+
*/
|
|
1608
|
+
|
|
1609
|
+
declare class ClusterAdminApi {
|
|
1610
|
+
private readonly transport;
|
|
1611
|
+
constructor(transport: Transport);
|
|
1612
|
+
/**
|
|
1613
|
+
* Join this node to an existing replica set.
|
|
1614
|
+
* POST /admin/cluster/join
|
|
1615
|
+
*/
|
|
1616
|
+
join(request: JoinClusterRequest): Promise<JoinClusterResponse>;
|
|
1617
|
+
/**
|
|
1618
|
+
* Leave the current cluster and return to standalone mode.
|
|
1619
|
+
* DELETE /admin/cluster/leave
|
|
1620
|
+
*/
|
|
1621
|
+
leave(): Promise<LeaveClusterResponse>;
|
|
1622
|
+
/**
|
|
1623
|
+
* Trigger election to promote this node.
|
|
1624
|
+
* POST /admin/cluster/promote
|
|
1625
|
+
*/
|
|
1626
|
+
promote(): Promise<PromoteClusterResponse>;
|
|
1627
|
+
/**
|
|
1628
|
+
* Trigger failover by stepping down current primary.
|
|
1629
|
+
* POST /admin/cluster/failover
|
|
1630
|
+
*/
|
|
1631
|
+
failover(): Promise<FailoverClusterResponse>;
|
|
1632
|
+
/**
|
|
1633
|
+
* Mark a member as draining.
|
|
1634
|
+
* POST /admin/cluster/drain/{nodeAddress}
|
|
1635
|
+
*/
|
|
1636
|
+
drain(nodeAddress: string): Promise<DrainClusterResponse>;
|
|
1637
|
+
/**
|
|
1638
|
+
* Fetch current cluster config.
|
|
1639
|
+
* GET /admin/cluster/config
|
|
1640
|
+
*/
|
|
1641
|
+
getConfig(): Promise<ClusterConfigResponse>;
|
|
1642
|
+
/**
|
|
1643
|
+
* Patch mutable cluster config fields.
|
|
1644
|
+
* PATCH /admin/cluster/config
|
|
1645
|
+
*/
|
|
1646
|
+
patchConfig(patch: ClusterConfigPatchRequest): Promise<ClusterConfigResponse>;
|
|
1647
|
+
}
|
|
1648
|
+
|
|
1649
|
+
/**
|
|
1650
|
+
* Admin backup response/request types.
|
|
1651
|
+
* Mirrors Aouda server JSON payloads under /admin/backup/*.
|
|
1652
|
+
*/
|
|
1653
|
+
interface TriggerBackupRequest {
|
|
1654
|
+
destination?: string | null;
|
|
1655
|
+
incremental?: boolean;
|
|
1656
|
+
baseBackupId?: string | null;
|
|
1657
|
+
}
|
|
1658
|
+
interface TriggerBackupResponse {
|
|
1659
|
+
backupId: string;
|
|
1660
|
+
createdUtc: string;
|
|
1661
|
+
basedOn?: string | null;
|
|
1662
|
+
totalBytes: number;
|
|
1663
|
+
newBytes: number;
|
|
1664
|
+
fileCount: number;
|
|
1665
|
+
newFileCount: number;
|
|
1666
|
+
blobsUploaded: number;
|
|
1667
|
+
blobsSkipped: number;
|
|
1668
|
+
durationSeconds: number;
|
|
1669
|
+
}
|
|
1670
|
+
interface BackupSummary {
|
|
1671
|
+
backupId: string;
|
|
1672
|
+
createdUtc: string;
|
|
1673
|
+
basedOn?: string | null;
|
|
1674
|
+
totalBytes: number;
|
|
1675
|
+
newBytes: number;
|
|
1676
|
+
fileCount: number;
|
|
1677
|
+
newFileCount: number;
|
|
1678
|
+
}
|
|
1679
|
+
interface ListBackupsResponse {
|
|
1680
|
+
backups: BackupSummary[];
|
|
1681
|
+
warning?: string | null;
|
|
1682
|
+
}
|
|
1683
|
+
interface RestoreBackupResponse {
|
|
1684
|
+
backupId: string;
|
|
1685
|
+
restoredUtc: string;
|
|
1686
|
+
filesRestored: number;
|
|
1687
|
+
bytesDownloaded: number;
|
|
1688
|
+
integrityVerified: boolean;
|
|
1689
|
+
durationSeconds: number;
|
|
1690
|
+
}
|
|
1691
|
+
interface BackupSchedule {
|
|
1692
|
+
cronExpression?: string | null;
|
|
1693
|
+
destination?: string | null;
|
|
1694
|
+
incremental: boolean;
|
|
1695
|
+
}
|
|
1696
|
+
|
|
1697
|
+
/**
|
|
1698
|
+
* Admin backup API.
|
|
1699
|
+
* Access via client.admin.backup.
|
|
1700
|
+
*/
|
|
1701
|
+
|
|
1702
|
+
declare class BackupAdminApi {
|
|
1703
|
+
private readonly transport;
|
|
1704
|
+
constructor(transport: Transport);
|
|
1705
|
+
/**
|
|
1706
|
+
* Trigger an immediate backup.
|
|
1707
|
+
* POST /admin/backup/trigger
|
|
1708
|
+
*/
|
|
1709
|
+
trigger(request?: TriggerBackupRequest): Promise<TriggerBackupResponse>;
|
|
1710
|
+
/**
|
|
1711
|
+
* List available backups.
|
|
1712
|
+
* GET /admin/backup/list
|
|
1713
|
+
*/
|
|
1714
|
+
list(): Promise<ListBackupsResponse>;
|
|
1715
|
+
/**
|
|
1716
|
+
* Restore a backup by id.
|
|
1717
|
+
* POST /admin/backup/restore/{id}
|
|
1718
|
+
*/
|
|
1719
|
+
restore(backupId: string): Promise<RestoreBackupResponse>;
|
|
1720
|
+
/**
|
|
1721
|
+
* Get backup schedule.
|
|
1722
|
+
* GET /admin/backup/schedule
|
|
1723
|
+
*/
|
|
1724
|
+
getSchedule(): Promise<BackupSchedule>;
|
|
1725
|
+
/**
|
|
1726
|
+
* Set backup schedule.
|
|
1727
|
+
* PUT /admin/backup/schedule
|
|
1728
|
+
*/
|
|
1729
|
+
setSchedule(schedule: BackupSchedule): Promise<BackupSchedule>;
|
|
1730
|
+
}
|
|
1731
|
+
|
|
1732
|
+
/**
|
|
1733
|
+
* Admin runtime configuration response/request types.
|
|
1734
|
+
* Mirrors Aouda server JSON payloads under /admin/config*.
|
|
1735
|
+
*/
|
|
1736
|
+
interface AdminMemoryConfig {
|
|
1737
|
+
maxTotalRamBytes: number;
|
|
1738
|
+
maxHotBytes: number;
|
|
1739
|
+
maxPageCacheBytes: number;
|
|
1740
|
+
}
|
|
1741
|
+
interface AdminBackupConfig {
|
|
1742
|
+
cronExpression?: string | null;
|
|
1743
|
+
destination?: string | null;
|
|
1744
|
+
incremental: boolean;
|
|
1745
|
+
}
|
|
1746
|
+
interface AdminLoggingConfig {
|
|
1747
|
+
level: string;
|
|
1748
|
+
}
|
|
1749
|
+
interface AdminConfigResponse {
|
|
1750
|
+
memory: AdminMemoryConfig;
|
|
1751
|
+
backup: AdminBackupConfig;
|
|
1752
|
+
logging: AdminLoggingConfig;
|
|
1753
|
+
}
|
|
1754
|
+
interface AdminConfigSchemaResponse {
|
|
1755
|
+
mutableFields: string[];
|
|
1756
|
+
immutableFields: string[];
|
|
1757
|
+
}
|
|
1758
|
+
interface AdminMemoryPatch {
|
|
1759
|
+
maxTotalRamBytes?: number;
|
|
1760
|
+
maxHotBytes?: number;
|
|
1761
|
+
maxPageCacheBytes?: number;
|
|
1762
|
+
}
|
|
1763
|
+
interface AdminBackupPatch {
|
|
1764
|
+
cronExpression?: string | null;
|
|
1765
|
+
destination?: string | null;
|
|
1766
|
+
incremental?: boolean;
|
|
1767
|
+
}
|
|
1768
|
+
interface AdminLoggingPatch {
|
|
1769
|
+
level?: string;
|
|
1770
|
+
}
|
|
1771
|
+
interface AdminConfigPatchRequest {
|
|
1772
|
+
memory?: AdminMemoryPatch;
|
|
1773
|
+
backup?: AdminBackupPatch;
|
|
1774
|
+
logging?: AdminLoggingPatch;
|
|
1775
|
+
}
|
|
1776
|
+
|
|
1777
|
+
/**
|
|
1778
|
+
* Admin runtime config API.
|
|
1779
|
+
* Access via client.admin.config.
|
|
1780
|
+
*/
|
|
1781
|
+
|
|
1782
|
+
declare class ConfigAdminApi {
|
|
1783
|
+
private readonly transport;
|
|
1784
|
+
constructor(transport: Transport);
|
|
1785
|
+
/**
|
|
1786
|
+
* Get current runtime config.
|
|
1787
|
+
* GET /admin/config
|
|
1788
|
+
*/
|
|
1789
|
+
get(): Promise<AdminConfigResponse>;
|
|
1790
|
+
/**
|
|
1791
|
+
* Patch mutable runtime config values.
|
|
1792
|
+
* PATCH /admin/config
|
|
1793
|
+
*/
|
|
1794
|
+
patch(patch: AdminConfigPatchRequest): Promise<AdminConfigResponse>;
|
|
1795
|
+
/**
|
|
1796
|
+
* Get mutable and immutable config fields.
|
|
1797
|
+
* GET /admin/config/schema
|
|
1798
|
+
*/
|
|
1799
|
+
schema(): Promise<AdminConfigSchemaResponse>;
|
|
1800
|
+
}
|
|
1801
|
+
|
|
1802
|
+
/**
|
|
1803
|
+
* Admin node info/log response/request types.
|
|
1804
|
+
* Mirrors Aouda server JSON payloads under /admin/node*.
|
|
1805
|
+
*/
|
|
1806
|
+
interface NodeInfoResponse {
|
|
1807
|
+
nodeId: string;
|
|
1808
|
+
address?: string | null;
|
|
1809
|
+
role: string;
|
|
1810
|
+
version: string;
|
|
1811
|
+
uptimeSeconds: number;
|
|
1812
|
+
processId: number;
|
|
1813
|
+
machineName: string;
|
|
1814
|
+
osDescription: string;
|
|
1815
|
+
processorCount: number;
|
|
1816
|
+
workingSetBytes: number;
|
|
1817
|
+
gcHeapBytes: number;
|
|
1818
|
+
}
|
|
1819
|
+
type NodeLogLevel = "Trace" | "Debug" | "Information" | "Warning" | "Error" | "Critical";
|
|
1820
|
+
interface NodeLogEntry {
|
|
1821
|
+
timestampUtc: string;
|
|
1822
|
+
level: NodeLogLevel;
|
|
1823
|
+
category: string;
|
|
1824
|
+
message: string;
|
|
1825
|
+
}
|
|
1826
|
+
interface NodeLogsResponse {
|
|
1827
|
+
entries: NodeLogEntry[];
|
|
1828
|
+
}
|
|
1829
|
+
interface NodeLogsQuery extends RequestOptions {
|
|
1830
|
+
level?: NodeLogLevel;
|
|
1831
|
+
contains?: string;
|
|
1832
|
+
limit?: number;
|
|
1833
|
+
}
|
|
1834
|
+
interface NodeLogStreamOptions extends RequestOptions {
|
|
1835
|
+
level?: NodeLogLevel;
|
|
1836
|
+
contains?: string;
|
|
1837
|
+
}
|
|
1838
|
+
|
|
1839
|
+
/**
|
|
1840
|
+
* Admin node info and logs API.
|
|
1841
|
+
* Access via client.admin.node.
|
|
1842
|
+
*/
|
|
1843
|
+
|
|
1844
|
+
declare class NodeAdminApi {
|
|
1845
|
+
private readonly transport;
|
|
1846
|
+
constructor(transport: Transport);
|
|
1847
|
+
/**
|
|
1848
|
+
* Get node identity and resource snapshot.
|
|
1849
|
+
* GET /admin/node
|
|
1850
|
+
*/
|
|
1851
|
+
get(): Promise<NodeInfoResponse>;
|
|
1852
|
+
/**
|
|
1853
|
+
* Query recent buffered logs.
|
|
1854
|
+
* GET /admin/node/logs
|
|
1855
|
+
*/
|
|
1856
|
+
logs(options?: NodeLogsQuery): Promise<NodeLogsResponse>;
|
|
1857
|
+
/**
|
|
1858
|
+
* Stream node logs as SSE events.
|
|
1859
|
+
* GET /admin/node/logs/stream
|
|
1860
|
+
*/
|
|
1861
|
+
streamLogs(options?: NodeLogStreamOptions): AsyncIterable<NodeLogEntry>;
|
|
1862
|
+
private buildLogsPath;
|
|
1863
|
+
}
|
|
1864
|
+
|
|
1865
|
+
/**
|
|
1866
|
+
* Admin API: server info, memory, metrics, health, replication.
|
|
1867
|
+
* Access via client.admin.
|
|
1868
|
+
*/
|
|
1869
|
+
|
|
1870
|
+
/** Aggregated admin API exposed as client.admin. */
|
|
1871
|
+
declare class AdminApi {
|
|
1872
|
+
readonly server: ServerAdminApi;
|
|
1873
|
+
readonly health: HealthAdminApi;
|
|
1874
|
+
readonly metrics: MetricsAdminApi;
|
|
1875
|
+
readonly replication: ReplicationAdminApi;
|
|
1876
|
+
readonly cluster: ClusterAdminApi;
|
|
1877
|
+
readonly backup: BackupAdminApi;
|
|
1878
|
+
readonly config: ConfigAdminApi;
|
|
1879
|
+
readonly node: NodeAdminApi;
|
|
1880
|
+
constructor(transport: Transport);
|
|
1881
|
+
}
|
|
1882
|
+
|
|
1883
|
+
/**
|
|
1884
|
+
* AuthHandler — manages the client's authentication state:
|
|
1885
|
+
* token storage, proactive refresh, and a promise-coalescing single-refresh gate.
|
|
1886
|
+
*
|
|
1887
|
+
* Two-layer auth model: clients connect via API key (Layer 1); user sign-in is performed
|
|
1888
|
+
* explicitly via AuthClient.signIn() (Layer 2). There is no auto-authentication on first request.
|
|
1889
|
+
*
|
|
1890
|
+
* All auth endpoint calls use direct globalThis.fetch to avoid
|
|
1891
|
+
* circular refresh through the transport pipeline.
|
|
1892
|
+
*
|
|
1893
|
+
* @internal
|
|
1894
|
+
*/
|
|
1895
|
+
|
|
1896
|
+
/**
|
|
1897
|
+
* Flat credential config passed to AuthHandler.
|
|
1898
|
+
* Decoupled from ServerAuthOptions/AppAuthOptions so the handler is auth-system-agnostic.
|
|
1899
|
+
* @internal
|
|
1900
|
+
*/
|
|
1901
|
+
interface AuthConfig {
|
|
1902
|
+
/** Resolved auth endpoint base path: "/api/auth" or "/api/databases/{db}/auth". */
|
|
1903
|
+
basePath: string;
|
|
1904
|
+
apiKey?: string;
|
|
1905
|
+
token?: string;
|
|
1906
|
+
refreshToken?: string;
|
|
1907
|
+
userToken?: string;
|
|
1908
|
+
/** Explicit auth database name (app auth only). */
|
|
1909
|
+
authDatabase?: string;
|
|
1910
|
+
/** How early before expiry (ms) to proactively refresh. Default: 120_000 (2 min). */
|
|
1911
|
+
refreshThresholdMs?: number;
|
|
1912
|
+
}
|
|
1913
|
+
declare class AuthHandler {
|
|
1914
|
+
private _accessToken;
|
|
1915
|
+
private _refreshToken;
|
|
1916
|
+
private _tokenExpiry;
|
|
1917
|
+
private _authenticated;
|
|
1918
|
+
private _refreshPromise;
|
|
1919
|
+
private readonly _serverUrl;
|
|
1920
|
+
private readonly _timeout;
|
|
1921
|
+
private readonly _refreshThresholdMs;
|
|
1922
|
+
private readonly _apiKeyMode;
|
|
1923
|
+
private readonly _isServiceKeyMode;
|
|
1924
|
+
private readonly _userToken;
|
|
1925
|
+
/** Base path for auth endpoints: either "/api/auth" (server) or "/api/databases/{db}/auth" (app). */
|
|
1926
|
+
private readonly _authBasePath;
|
|
1927
|
+
private _authDatabase;
|
|
1928
|
+
private readonly _authDatabaseExplicit;
|
|
1929
|
+
constructor(config: AuthConfig, serverUrl: string, timeout: number);
|
|
1930
|
+
/** True when configured with apiKey and no refresh-capable user session exists. */
|
|
1931
|
+
get isApiKeyMode(): boolean;
|
|
1932
|
+
/**
|
|
1933
|
+
* The user JWT to forward as X-User-Token on outgoing requests.
|
|
1934
|
+
* Non-null only when the primary credential is a service-level key
|
|
1935
|
+
* (prefix `mk_svc_` or `mk_srv_`) and `userToken` was set in the auth config.
|
|
1936
|
+
*/
|
|
1937
|
+
get userToken(): string | null;
|
|
1938
|
+
/** The resolved auth database name (explicit, discovered, or default "_auth"). */
|
|
1939
|
+
get authDatabase(): string;
|
|
1940
|
+
/**
|
|
1941
|
+
* Updates the auth database from an X-Auth-Database response header.
|
|
1942
|
+
* Only updates if the database was not explicitly configured at construction.
|
|
1943
|
+
*/
|
|
1944
|
+
setDiscoveredAuthDatabase(name: string): void;
|
|
1945
|
+
/** Whether initial authentication has completed. */
|
|
1946
|
+
get isAuthenticated(): boolean;
|
|
1947
|
+
/** Internal server URL used for direct auth endpoint calls. */
|
|
1948
|
+
get serverUrl(): string;
|
|
1949
|
+
/** Internal auth base path (e.g. /api/auth or /api/databases/{db}/auth). */
|
|
1950
|
+
get authBasePath(): string;
|
|
1951
|
+
/** Internal request timeout used for direct auth endpoint calls. */
|
|
1952
|
+
get timeoutMs(): number;
|
|
1953
|
+
/** Current access token (null if not yet authenticated). */
|
|
1954
|
+
get currentAccessToken(): string | null;
|
|
1955
|
+
/** Current refresh token (null if not set). */
|
|
1956
|
+
get currentRefreshToken(): string | null;
|
|
1957
|
+
/**
|
|
1958
|
+
* No-op in the two-layer auth model.
|
|
1959
|
+
* App-mode clients connect via ApiKey (set at construction).
|
|
1960
|
+
* User sign-in is done explicitly via AuthClient.signIn() / signUp().
|
|
1961
|
+
*/
|
|
1962
|
+
ensureAuthenticated(): Promise<void>;
|
|
1963
|
+
/**
|
|
1964
|
+
* Returns the current access token. If the token is within the refresh threshold
|
|
1965
|
+
* of expiry, proactively refreshes first. In API key mode, returns the API key with no refresh.
|
|
1966
|
+
*/
|
|
1967
|
+
getAccessToken(): Promise<string | null>;
|
|
1968
|
+
/**
|
|
1969
|
+
* Attempts to refresh the access token using the stored refresh token.
|
|
1970
|
+
* Uses promise coalescing: if a refresh is already in flight, all callers
|
|
1971
|
+
* await the same Promise. The first caller initiates the refresh; subsequent
|
|
1972
|
+
* callers get the same result.
|
|
1973
|
+
*
|
|
1974
|
+
* @returns true if refresh succeeded, false if it failed.
|
|
1975
|
+
*/
|
|
1976
|
+
tryRefresh(): Promise<boolean>;
|
|
1977
|
+
/**
|
|
1978
|
+
* Stores tokens from an auth response (sign-in, sign-up, or refresh).
|
|
1979
|
+
*/
|
|
1980
|
+
handleSignInResult(result: AuthResult): void;
|
|
1981
|
+
/**
|
|
1982
|
+
* Clears all stored tokens (called on sign-out).
|
|
1983
|
+
*/
|
|
1984
|
+
clearTokens(): void;
|
|
1985
|
+
callSignInEndpoint(email: string, password: string): Promise<AuthResult | null>;
|
|
1986
|
+
callSignUpEndpoint(email: string, password: string): Promise<AuthResult | null>;
|
|
1987
|
+
callSignOutEndpoint(): Promise<void>;
|
|
1988
|
+
callRefreshEndpoint(): Promise<AuthResult>;
|
|
1989
|
+
callMeEndpoint(): Promise<UserProfile>;
|
|
1990
|
+
callChangePasswordEndpoint(currentPassword: string, newPassword: string): Promise<void>;
|
|
1991
|
+
private shouldProactivelyRefresh;
|
|
1992
|
+
private _doRefresh;
|
|
1993
|
+
private _fetchJson;
|
|
1994
|
+
private _tryReadErrorBody;
|
|
1995
|
+
}
|
|
1996
|
+
|
|
1997
|
+
/**
|
|
1998
|
+
* AuthClient — public auth API exposed as `client.auth`.
|
|
1999
|
+
* Makes direct fetch calls through AuthHandler (not through the transport
|
|
2000
|
+
* pipeline) to avoid circular refresh.
|
|
2001
|
+
*/
|
|
2002
|
+
|
|
2003
|
+
/**
|
|
2004
|
+
* Public auth API for application-level auth operations.
|
|
2005
|
+
* Access via `client.auth`.
|
|
2006
|
+
*/
|
|
2007
|
+
declare class AuthClient {
|
|
2008
|
+
private readonly _authHandler;
|
|
2009
|
+
constructor(authHandler: AuthHandler);
|
|
2010
|
+
/**
|
|
2011
|
+
* Creates a new user account and returns auth tokens.
|
|
2012
|
+
* Updates the client's stored tokens so subsequent requests use the new identity.
|
|
2013
|
+
*/
|
|
2014
|
+
signUp(email: string, password: string): Promise<AuthResult>;
|
|
2015
|
+
/**
|
|
2016
|
+
* Authenticates with credentials and returns auth tokens.
|
|
2017
|
+
* Updates the client's stored tokens so subsequent requests use the new identity.
|
|
2018
|
+
*/
|
|
2019
|
+
signIn(email: string, password: string): Promise<AuthResult>;
|
|
2020
|
+
/**
|
|
2021
|
+
* Signs out the current user, revokes session, and clears stored tokens.
|
|
2022
|
+
*/
|
|
2023
|
+
signOut(): Promise<void>;
|
|
2024
|
+
/**
|
|
2025
|
+
* Refreshes the access token using the stored refresh token.
|
|
2026
|
+
* Updates the client's stored tokens.
|
|
2027
|
+
*/
|
|
2028
|
+
refresh(): Promise<AuthResult>;
|
|
2029
|
+
/**
|
|
2030
|
+
* Returns the current user's profile.
|
|
2031
|
+
*/
|
|
2032
|
+
me(): Promise<UserProfile>;
|
|
2033
|
+
/**
|
|
2034
|
+
* Changes the current user's password.
|
|
2035
|
+
*/
|
|
2036
|
+
changePassword(currentPassword: string, newPassword: string): Promise<void>;
|
|
2037
|
+
/**
|
|
2038
|
+
* Creates a partition grant for a user.
|
|
2039
|
+
*/
|
|
2040
|
+
createPartitionGrant(userId: string, request: CreatePartitionGrantRequest): Promise<PartitionGrant>;
|
|
2041
|
+
/**
|
|
2042
|
+
* Lists partition grants for a user with optional dimension filtering.
|
|
2043
|
+
*/
|
|
2044
|
+
listPartitionGrants(userId: string, options?: {
|
|
2045
|
+
dimension?: string;
|
|
2046
|
+
}): Promise<PartitionGrant[]>;
|
|
2047
|
+
/**
|
|
2048
|
+
* Deletes a partition grant for a user.
|
|
2049
|
+
*/
|
|
2050
|
+
deletePartitionGrant(userId: string, grantId: string): Promise<void>;
|
|
2051
|
+
/**
|
|
2052
|
+
* Creates an RLS resolver.
|
|
2053
|
+
*/
|
|
2054
|
+
createRlsResolver(request: CreateRlsResolverRequest): Promise<RlsResolver>;
|
|
2055
|
+
/**
|
|
2056
|
+
* Lists RLS resolvers with optional target table filtering.
|
|
2057
|
+
*/
|
|
2058
|
+
listRlsResolvers(options?: {
|
|
2059
|
+
targetTable?: string;
|
|
2060
|
+
}): Promise<RlsResolver[]>;
|
|
2061
|
+
/**
|
|
2062
|
+
* Gets a single RLS resolver.
|
|
2063
|
+
*/
|
|
2064
|
+
getRlsResolver(resolverId: string): Promise<RlsResolver>;
|
|
2065
|
+
/**
|
|
2066
|
+
* Updates an existing RLS resolver.
|
|
2067
|
+
*/
|
|
2068
|
+
updateRlsResolver(resolverId: string, request: UpdateRlsResolverRequest): Promise<RlsResolver>;
|
|
2069
|
+
/**
|
|
2070
|
+
* Deletes an RLS resolver.
|
|
2071
|
+
*/
|
|
2072
|
+
deleteRlsResolver(resolverId: string): Promise<void>;
|
|
2073
|
+
private validateNonEmptyString;
|
|
2074
|
+
private authRequest;
|
|
2075
|
+
private tryReadAuthError;
|
|
2076
|
+
}
|
|
2077
|
+
|
|
2078
|
+
/**
|
|
2079
|
+
* Wire protocol message types for Aouda real-time streaming (ADR 0020 §4).
|
|
2080
|
+
* No imports — pure type definitions.
|
|
2081
|
+
*/
|
|
2082
|
+
type StreamingWireMode = "json" | "msgpack";
|
|
2083
|
+
interface AuthMessage {
|
|
2084
|
+
type: "auth";
|
|
2085
|
+
token: string | null;
|
|
2086
|
+
database: string;
|
|
2087
|
+
wire_mode?: StreamingWireMode;
|
|
2088
|
+
}
|
|
2089
|
+
interface SubscribeMessage {
|
|
2090
|
+
type: "subscribe";
|
|
2091
|
+
id: string;
|
|
2092
|
+
target: string;
|
|
2093
|
+
filter?: Record<string, unknown>;
|
|
2094
|
+
resume_from?: number;
|
|
2095
|
+
}
|
|
2096
|
+
interface UnsubscribeMessage {
|
|
2097
|
+
type: "unsubscribe";
|
|
2098
|
+
id: string;
|
|
2099
|
+
}
|
|
2100
|
+
interface StreamOpenMessage {
|
|
2101
|
+
type: "stream_open";
|
|
2102
|
+
id: string;
|
|
2103
|
+
table: string;
|
|
2104
|
+
mode: "insert" | "upsert";
|
|
2105
|
+
}
|
|
2106
|
+
interface StreamRowsMessage {
|
|
2107
|
+
type: "stream_rows";
|
|
2108
|
+
id: string;
|
|
2109
|
+
seq: number;
|
|
2110
|
+
rows: unknown[];
|
|
2111
|
+
}
|
|
2112
|
+
interface StreamCloseMessage {
|
|
2113
|
+
type: "stream_close";
|
|
2114
|
+
id: string;
|
|
2115
|
+
}
|
|
2116
|
+
interface PingMessage {
|
|
2117
|
+
type: "ping";
|
|
2118
|
+
}
|
|
2119
|
+
type ClientMessage = AuthMessage | SubscribeMessage | UnsubscribeMessage | StreamOpenMessage | StreamRowsMessage | StreamCloseMessage | PingMessage;
|
|
2120
|
+
interface AuthOkMessage {
|
|
2121
|
+
type: "auth_ok";
|
|
2122
|
+
user_id?: string;
|
|
2123
|
+
expires_at?: string;
|
|
2124
|
+
wire_mode?: StreamingWireMode;
|
|
2125
|
+
}
|
|
2126
|
+
interface AuthErrorMessage {
|
|
2127
|
+
type: "auth_error";
|
|
2128
|
+
code: string;
|
|
2129
|
+
message: string;
|
|
2130
|
+
}
|
|
2131
|
+
interface SnapshotMessage {
|
|
2132
|
+
type: "snapshot";
|
|
2133
|
+
id: string;
|
|
2134
|
+
rows: unknown[];
|
|
2135
|
+
version: number;
|
|
2136
|
+
}
|
|
2137
|
+
interface ChangeMessage {
|
|
2138
|
+
type: "change";
|
|
2139
|
+
id: string;
|
|
2140
|
+
op: "insert" | "update" | "delete";
|
|
2141
|
+
row?: unknown;
|
|
2142
|
+
prev?: unknown;
|
|
2143
|
+
key?: unknown;
|
|
2144
|
+
version: number;
|
|
2145
|
+
}
|
|
2146
|
+
interface StreamAckMessage {
|
|
2147
|
+
type: "stream_ack";
|
|
2148
|
+
id: string;
|
|
2149
|
+
through: number;
|
|
2150
|
+
}
|
|
2151
|
+
interface StreamReadyMessage {
|
|
2152
|
+
type: "stream_ready";
|
|
2153
|
+
id: string;
|
|
2154
|
+
}
|
|
2155
|
+
interface StreamClosedMessage {
|
|
2156
|
+
type: "stream_closed";
|
|
2157
|
+
id: string;
|
|
2158
|
+
}
|
|
2159
|
+
interface HeartbeatMessage {
|
|
2160
|
+
type: "heartbeat";
|
|
2161
|
+
version: number;
|
|
2162
|
+
}
|
|
2163
|
+
interface ServerErrorMessage {
|
|
2164
|
+
type: "error";
|
|
2165
|
+
id?: string;
|
|
2166
|
+
code: string;
|
|
2167
|
+
message: string;
|
|
2168
|
+
}
|
|
2169
|
+
interface PongMessage {
|
|
2170
|
+
type: "pong";
|
|
2171
|
+
}
|
|
2172
|
+
type ServerMessage = AuthOkMessage | AuthErrorMessage | SnapshotMessage | ChangeMessage | StreamAckMessage | StreamReadyMessage | StreamClosedMessage | HeartbeatMessage | ServerErrorMessage | PongMessage;
|
|
2173
|
+
|
|
2174
|
+
type StreamingMessageHandler = (message: ServerMessage) => void;
|
|
2175
|
+
interface StreamingTransport {
|
|
2176
|
+
readonly lastVersion: number;
|
|
2177
|
+
connect(): Promise<void>;
|
|
2178
|
+
send(message: ClientMessage): Promise<void>;
|
|
2179
|
+
registerHandler(id: string, handler: StreamingMessageHandler): void;
|
|
2180
|
+
unregisterHandler(id: string): void;
|
|
2181
|
+
registerReconnectHandler(id: string, handler: () => void): void;
|
|
2182
|
+
unregisterReconnectHandler(id: string): void;
|
|
2183
|
+
dispose(): Promise<void>;
|
|
2184
|
+
}
|
|
2185
|
+
|
|
2186
|
+
interface SubscriptionSnapshotEvent<T = Record<string, unknown>> {
|
|
2187
|
+
type: "snapshot";
|
|
2188
|
+
rows: T[];
|
|
2189
|
+
version: number;
|
|
2190
|
+
}
|
|
2191
|
+
interface SubscriptionChangeEvent<T = Record<string, unknown>> {
|
|
2192
|
+
type: "change";
|
|
2193
|
+
op: "insert" | "update" | "delete";
|
|
2194
|
+
row?: T;
|
|
2195
|
+
prev?: T;
|
|
2196
|
+
key?: unknown;
|
|
2197
|
+
version: number;
|
|
2198
|
+
}
|
|
2199
|
+
type SubscriptionEvent<T = Record<string, unknown>> = SubscriptionSnapshotEvent<T> | SubscriptionChangeEvent<T>;
|
|
2200
|
+
interface SubscribeOptions<T = Record<string, unknown>> {
|
|
2201
|
+
onSnapshot?: (rows: T[], version: number) => void;
|
|
2202
|
+
onChange?: (event: SubscriptionChangeEvent<T>) => void;
|
|
2203
|
+
onError?: (error: Error) => void;
|
|
2204
|
+
filter?: Record<string, unknown>;
|
|
2205
|
+
}
|
|
2206
|
+
interface Subscription<T = Record<string, unknown>> extends AsyncIterable<SubscriptionEvent<T>> {
|
|
2207
|
+
readonly id: string;
|
|
2208
|
+
readonly lastVersion: number;
|
|
2209
|
+
unsubscribe(): Promise<void>;
|
|
2210
|
+
}
|
|
2211
|
+
|
|
2212
|
+
interface OpenWriteStreamOptions {
|
|
2213
|
+
mode?: "insert" | "upsert";
|
|
2214
|
+
}
|
|
2215
|
+
interface WriteStream<T = Record<string, unknown>> {
|
|
2216
|
+
readonly id: string;
|
|
2217
|
+
readonly lastAcknowledgedSeq: number;
|
|
2218
|
+
write(row: Partial<T> | Partial<T>[]): Promise<void>;
|
|
2219
|
+
close(): Promise<void>;
|
|
2220
|
+
}
|
|
2221
|
+
|
|
2222
|
+
/**
|
|
2223
|
+
* Query builder for @aouda/client.
|
|
2224
|
+
* Provides a fluent API for constructing and executing queries.
|
|
2225
|
+
*/
|
|
2226
|
+
|
|
2227
|
+
/**
|
|
2228
|
+
* Mutable builder for a nested {@link WhereClause} used with {@link TableQuery.whereGroup}.
|
|
2229
|
+
* - `where()` — ANDs predicates inside this group.
|
|
2230
|
+
* - `orWhere()` — adds to this group’s `or` list (disjunction).
|
|
2231
|
+
* - `subgroup()` — nests another clause under wire `groups`.
|
|
2232
|
+
*/
|
|
2233
|
+
declare class WhereGroupBuilder {
|
|
2234
|
+
private andPredicates;
|
|
2235
|
+
private orPredicates;
|
|
2236
|
+
private subgroups;
|
|
2237
|
+
where(column: string, operator: "isNull" | "isNotNull"): this;
|
|
2238
|
+
where(column: string, operator: Exclude<WhereOperator, "isNull" | "isNotNull">, value: unknown): this;
|
|
2239
|
+
/**
|
|
2240
|
+
* Adds a predicate to the inner `or` list (disjunction within this group).
|
|
2241
|
+
*/
|
|
2242
|
+
orWhere(column: string, operator: "isNull" | "isNotNull"): this;
|
|
2243
|
+
orWhere(column: string, operator: Exclude<WhereOperator, "isNull" | "isNotNull">, value: unknown): this;
|
|
2244
|
+
/**
|
|
2245
|
+
* Nests a further {@link WhereClause} under `groups`.
|
|
2246
|
+
*/
|
|
2247
|
+
subgroup(fn: (inner: WhereGroupBuilder) => void): this;
|
|
2248
|
+
build(): WhereClause;
|
|
2249
|
+
}
|
|
2250
|
+
/**
|
|
2251
|
+
* One batch mutation operation for {@link TableQuery.batch}.
|
|
2252
|
+
*/
|
|
2253
|
+
type BatchOperationInput<T = Record<string, unknown>> = {
|
|
2254
|
+
where: (query: TableQuery<T>) => TableQuery<T>;
|
|
2255
|
+
update: Partial<T>;
|
|
2256
|
+
delete?: false;
|
|
2257
|
+
} | {
|
|
2258
|
+
where: (query: TableQuery<T>) => TableQuery<T>;
|
|
2259
|
+
delete: true;
|
|
2260
|
+
limit?: number;
|
|
2261
|
+
orderBy?: OrderByClause[];
|
|
2262
|
+
update?: never;
|
|
2263
|
+
};
|
|
2264
|
+
/**
|
|
2265
|
+
* Internal state for the query builder.
|
|
2266
|
+
* This is passed between immutable instances.
|
|
2267
|
+
*/
|
|
2268
|
+
interface QueryBuilderState {
|
|
2269
|
+
predicates: WherePredicate[];
|
|
2270
|
+
/** Root-level `groups` entries (each merged with top-level `and`). */
|
|
2271
|
+
groupClauses: WhereClause[];
|
|
2272
|
+
orderByClauses: OrderByClause[];
|
|
2273
|
+
joinClauses: JoinClause[];
|
|
2274
|
+
aggregateOperations: AggregateOperation[];
|
|
2275
|
+
groupByColumns: string[] | null;
|
|
2276
|
+
selectColumns: string[] | null;
|
|
2277
|
+
limitValue: number | null;
|
|
2278
|
+
offsetValue: number | null;
|
|
2279
|
+
crossPartitionAccess: boolean;
|
|
2280
|
+
/** Server-side computed column projections (S7). */
|
|
2281
|
+
selectExprs: ComputedColumnDef[] | null;
|
|
2282
|
+
}
|
|
2283
|
+
/**
|
|
2284
|
+
* Coerces a raw columnar value using the server-declared column type name.
|
|
2285
|
+
*
|
|
2286
|
+
* The server sends typed columnar data (e.g. Timestamp as Int64 ticks, Guid as string) alongside
|
|
2287
|
+
* a `types[]` array. This function is the TypeScript equivalent of the C# `CoerceValue` in
|
|
2288
|
+
* `ClientColumnarResult` — it is the single place that applies type-aware conversions so that
|
|
2289
|
+
* callers receive properly typed values without needing to know about wire-format details.
|
|
2290
|
+
*
|
|
2291
|
+
* Timestamp: .NET ticks (100-ns intervals since 0001-01-01 UTC) → ISO 8601 string.
|
|
2292
|
+
* Guid: already a string — passed through unchanged.
|
|
2293
|
+
* All other types: passed through unchanged.
|
|
2294
|
+
*/
|
|
2295
|
+
declare function coerceColumnarValue(value: unknown, typeName: string): unknown;
|
|
2296
|
+
/**
|
|
2297
|
+
* Fluent query builder for Aouda tables.
|
|
2298
|
+
*
|
|
2299
|
+
* The builder is immutable — each method returns a new instance
|
|
2300
|
+
* with the updated state, allowing query branching.
|
|
2301
|
+
*
|
|
2302
|
+
* @example
|
|
2303
|
+
* ```typescript
|
|
2304
|
+
* const results = await client.table('orders')
|
|
2305
|
+
* .where('status', '=', 'active')
|
|
2306
|
+
* .where('price', '>', 100)
|
|
2307
|
+
* .orderBy('price', 'desc')
|
|
2308
|
+
* .thenBy('createdAt')
|
|
2309
|
+
* .limit(50)
|
|
2310
|
+
* .select('id', 'status', 'price')
|
|
2311
|
+
* .execute();
|
|
2312
|
+
* ```
|
|
2313
|
+
*
|
|
2314
|
+
* Nested boolean filters (e.g. OR under an AND) use {@link TableQuery.whereGroup} and
|
|
2315
|
+
* {@link WhereGroupBuilder}; those become the wire `groups` array on {@link WhereClause}.
|
|
2316
|
+
*
|
|
2317
|
+
* @typeParam T - The type of rows returned by the query.
|
|
2318
|
+
*/
|
|
2319
|
+
declare class TableQuery<T = Record<string, unknown>> {
|
|
2320
|
+
private readonly transport;
|
|
2321
|
+
private readonly tableName;
|
|
2322
|
+
private readonly database;
|
|
2323
|
+
private readonly state;
|
|
2324
|
+
private readonly getWebSocketTransport;
|
|
2325
|
+
/**
|
|
2326
|
+
* Creates a new TableQuery instance.
|
|
2327
|
+
*
|
|
2328
|
+
* @param transport - The HTTP transport for making requests.
|
|
2329
|
+
* @param tableName - The name of the table to query.
|
|
2330
|
+
* @param database - The database name for path and request body.
|
|
2331
|
+
* @param state - Optional initial state (used for immutable chaining).
|
|
2332
|
+
* @internal Use `client.table()` to create queries.
|
|
2333
|
+
*/
|
|
2334
|
+
constructor(transport: Transport, tableName: string, database: string, state?: QueryBuilderState, getWebSocketTransport?: () => StreamingTransport);
|
|
2335
|
+
/**
|
|
2336
|
+
* Adds a filter predicate to the query.
|
|
2337
|
+
* Multiple `where()` calls are combined with AND.
|
|
2338
|
+
*
|
|
2339
|
+
* When T is a specific row type, only keys of T are accepted as column names.
|
|
2340
|
+
*
|
|
2341
|
+
* @param column - The column name to filter on.
|
|
2342
|
+
* @param operator - The comparison operator.
|
|
2343
|
+
* @param value - The value to compare against.
|
|
2344
|
+
* @returns A new TableQuery with the filter added.
|
|
2345
|
+
*
|
|
2346
|
+
* @example
|
|
2347
|
+
* ```typescript
|
|
2348
|
+
* query.where('status', '=', 'active')
|
|
2349
|
+
* .where('price', '>', 100)
|
|
2350
|
+
* ```
|
|
2351
|
+
*/
|
|
2352
|
+
where(column: keyof T & string, operator: "isNull" | "isNotNull"): TableQuery<T>;
|
|
2353
|
+
where(column: keyof T & string, operator: Exclude<WhereOperator, "isNull" | "isNotNull">, value: unknown): TableQuery<T>;
|
|
2354
|
+
/**
|
|
2355
|
+
* AND-combines a nested where subtree with any prior `where()` predicates.
|
|
2356
|
+
* Serializes as the `groups` property on the request body (see {@link WhereClause.groups}).
|
|
2357
|
+
*
|
|
2358
|
+
* @param fn - Configures a {@link WhereGroupBuilder}; must not leave the group empty.
|
|
2359
|
+
*/
|
|
2360
|
+
whereGroup(fn: (g: WhereGroupBuilder) => void): TableQuery<T>;
|
|
2361
|
+
/**
|
|
2362
|
+
* Sets the primary sort column for the query.
|
|
2363
|
+
* Calling `orderBy()` again replaces any previous ordering.
|
|
2364
|
+
*
|
|
2365
|
+
* When T is a specific row type, only keys of T are accepted as column names.
|
|
2366
|
+
*
|
|
2367
|
+
* @param column - The column name to sort by.
|
|
2368
|
+
* @param direction - The sort direction ('asc' or 'desc'). Defaults to 'asc'.
|
|
2369
|
+
* @returns A new TableQuery with the ordering set.
|
|
2370
|
+
*
|
|
2371
|
+
* @example
|
|
2372
|
+
* ```typescript
|
|
2373
|
+
* query.orderBy('price', 'desc')
|
|
2374
|
+
* ```
|
|
2375
|
+
*/
|
|
2376
|
+
orderBy(column: keyof T & string, direction?: SortDirection): TableQuery<T>;
|
|
2377
|
+
/**
|
|
2378
|
+
* Sets the primary sort column to descending order.
|
|
2379
|
+
* Convenience alias for `orderBy(column, 'desc')`.
|
|
2380
|
+
*
|
|
2381
|
+
* @param column - The column name to sort by descending.
|
|
2382
|
+
* @returns A new TableQuery with descending ordering set.
|
|
2383
|
+
*
|
|
2384
|
+
* @example
|
|
2385
|
+
* ```typescript
|
|
2386
|
+
* query.orderByDescending('price')
|
|
2387
|
+
* ```
|
|
2388
|
+
*/
|
|
2389
|
+
orderByDescending(column: keyof T & string): TableQuery<T>;
|
|
2390
|
+
/**
|
|
2391
|
+
* Adds a secondary sort column to the query.
|
|
2392
|
+
* Must be called after `orderBy()`.
|
|
2393
|
+
*
|
|
2394
|
+
* When T is a specific row type, only keys of T are accepted as column names.
|
|
2395
|
+
*
|
|
2396
|
+
* @param column - The column name to sort by.
|
|
2397
|
+
* @param direction - The sort direction ('asc' or 'desc'). Defaults to 'asc'.
|
|
2398
|
+
* @returns A new TableQuery with the secondary sort added.
|
|
2399
|
+
* @throws Error if `orderBy()` has not been called first.
|
|
2400
|
+
*
|
|
2401
|
+
* @example
|
|
2402
|
+
* ```typescript
|
|
2403
|
+
* query.orderBy('status')
|
|
2404
|
+
* .thenBy('price', 'desc')
|
|
2405
|
+
* .thenBy('createdAt')
|
|
2406
|
+
* ```
|
|
2407
|
+
*/
|
|
2408
|
+
thenBy(column: keyof T & string, direction?: SortDirection): TableQuery<T>;
|
|
2409
|
+
/**
|
|
2410
|
+
* Sets the maximum number of rows to return.
|
|
2411
|
+
*
|
|
2412
|
+
* @param count - The maximum number of rows.
|
|
2413
|
+
* @returns A new TableQuery with the limit set.
|
|
2414
|
+
*
|
|
2415
|
+
* @example
|
|
2416
|
+
* ```typescript
|
|
2417
|
+
* query.limit(50)
|
|
2418
|
+
* ```
|
|
2419
|
+
*/
|
|
2420
|
+
limit(count: number): TableQuery<T>;
|
|
2421
|
+
/**
|
|
2422
|
+
* Sets the number of rows to skip.
|
|
2423
|
+
*
|
|
2424
|
+
* @param count - The number of rows to skip.
|
|
2425
|
+
* @returns A new TableQuery with the offset set.
|
|
2426
|
+
*
|
|
2427
|
+
* @example
|
|
2428
|
+
* ```typescript
|
|
2429
|
+
* query.offset(100).limit(50) // Page 3 of 50-row pages
|
|
2430
|
+
* ```
|
|
2431
|
+
*/
|
|
2432
|
+
offset(count: number): TableQuery<T>;
|
|
2433
|
+
/**
|
|
2434
|
+
* Requests cross-partition access for this query.
|
|
2435
|
+
*
|
|
2436
|
+
* Sets `crossPartitionAccess: true` on the wire request. Use for admin or
|
|
2437
|
+
* authorized analytics queries that scan multiple partitions without a
|
|
2438
|
+
* partition-key filter. Server-side PLS and role checks still apply.
|
|
2439
|
+
*
|
|
2440
|
+
* @returns A new TableQuery with cross-partition access enabled.
|
|
2441
|
+
*/
|
|
2442
|
+
withCrossPartitionAccess(): TableQuery<T>;
|
|
2443
|
+
/**
|
|
2444
|
+
* Restricts the columns returned in the result.
|
|
2445
|
+
* If not called, all columns are returned.
|
|
2446
|
+
*
|
|
2447
|
+
* When T is a specific row type, only keys of T are accepted as column names.
|
|
2448
|
+
*
|
|
2449
|
+
* @param columns - The column names to return.
|
|
2450
|
+
* @returns A new TableQuery with column selection set.
|
|
2451
|
+
*
|
|
2452
|
+
* @example
|
|
2453
|
+
* ```typescript
|
|
2454
|
+
* query.select('id', 'name', 'price')
|
|
2455
|
+
* ```
|
|
2456
|
+
*/
|
|
2457
|
+
select(...columns: (keyof T & string)[]): TableQuery<T>;
|
|
2458
|
+
/**
|
|
2459
|
+
* Adds server-side computed columns to the query result.
|
|
2460
|
+
*
|
|
2461
|
+
* Each entry specifies an output alias and a {@link ScalarExprNode} expression tree
|
|
2462
|
+
* evaluated per row on the server. Computed columns are appended after any physical-column
|
|
2463
|
+
* `select()` projection.
|
|
2464
|
+
*
|
|
2465
|
+
* @param projections - One or more `{ alias, expr }` pairs.
|
|
2466
|
+
* @returns A new TableQuery with computed columns set.
|
|
2467
|
+
*
|
|
2468
|
+
* @example
|
|
2469
|
+
* ```typescript
|
|
2470
|
+
* query.selectExpr(
|
|
2471
|
+
* { alias: 'discounted', expr: { $mul: [{ $col: 'price' }, { $lit: 0.9 }] } }
|
|
2472
|
+
* )
|
|
2473
|
+
* ```
|
|
2474
|
+
*/
|
|
2475
|
+
selectExpr(...projections: ComputedColumnDef[]): TableQuery<T>;
|
|
2476
|
+
/**
|
|
2477
|
+
* Adds an INNER JOIN clause.
|
|
2478
|
+
*/
|
|
2479
|
+
join(rightTable: string, leftColumn: string, rightColumn: string): TableQuery<Record<string, unknown>>;
|
|
2480
|
+
join(rightTable: string, leftColumns: string[], rightColumns: string[]): TableQuery<Record<string, unknown>>;
|
|
2481
|
+
/**
|
|
2482
|
+
* Adds a LEFT JOIN clause.
|
|
2483
|
+
*/
|
|
2484
|
+
leftJoin(rightTable: string, leftColumn: string, rightColumn: string): TableQuery<Record<string, unknown>>;
|
|
2485
|
+
leftJoin(rightTable: string, leftColumns: string[], rightColumns: string[]): TableQuery<Record<string, unknown>>;
|
|
2486
|
+
/**
|
|
2487
|
+
* Adds a RIGHT JOIN clause.
|
|
2488
|
+
*/
|
|
2489
|
+
rightJoin(rightTable: string, leftColumn: string, rightColumn: string): TableQuery<Record<string, unknown>>;
|
|
2490
|
+
rightJoin(rightTable: string, leftColumns: string[], rightColumns: string[]): TableQuery<Record<string, unknown>>;
|
|
2491
|
+
/**
|
|
2492
|
+
* Adds a FULL JOIN clause.
|
|
2493
|
+
*/
|
|
2494
|
+
fullJoin(rightTable: string, leftColumn: string, rightColumn: string): TableQuery<Record<string, unknown>>;
|
|
2495
|
+
fullJoin(rightTable: string, leftColumns: string[], rightColumns: string[]): TableQuery<Record<string, unknown>>;
|
|
2496
|
+
/**
|
|
2497
|
+
* Adds a CROSS JOIN clause.
|
|
2498
|
+
*/
|
|
2499
|
+
crossJoin(rightTable: string): TableQuery<Record<string, unknown>>;
|
|
2500
|
+
/**
|
|
2501
|
+
* Adds a SUM aggregate operation for the specified column.
|
|
2502
|
+
*/
|
|
2503
|
+
sum(column: keyof T & string): TableQuery<T>;
|
|
2504
|
+
/**
|
|
2505
|
+
* Adds a MIN aggregate operation for the specified column.
|
|
2506
|
+
*/
|
|
2507
|
+
min(column: keyof T & string): TableQuery<T>;
|
|
2508
|
+
/**
|
|
2509
|
+
* Adds a MAX aggregate operation for the specified column.
|
|
2510
|
+
*/
|
|
2511
|
+
max(column: keyof T & string): TableQuery<T>;
|
|
2512
|
+
/**
|
|
2513
|
+
* Sets grouping columns for aggregate queries.
|
|
2514
|
+
*/
|
|
2515
|
+
groupBy(...columns: (keyof T & string)[]): TableQuery<T>;
|
|
2516
|
+
/**
|
|
2517
|
+
* Validates grouped aggregate configuration and returns the same query.
|
|
2518
|
+
*/
|
|
2519
|
+
groupAggregate(): TableQuery<T>;
|
|
2520
|
+
/**
|
|
2521
|
+
* Subscribes to table changes over the shared WebSocket transport.
|
|
2522
|
+
* Supports callback handlers and async-iterator consumption.
|
|
2523
|
+
*/
|
|
2524
|
+
subscribe(options?: SubscribeOptions<T>): Subscription<T>;
|
|
2525
|
+
/**
|
|
2526
|
+
* Opens a high-throughput write stream for insert/upsert operations.
|
|
2527
|
+
*/
|
|
2528
|
+
openWriteStream(options?: OpenWriteStreamOptions): Promise<WriteStream<T>>;
|
|
2529
|
+
/**
|
|
2530
|
+
* Builds the query request body for the wire protocol.
|
|
2531
|
+
* @returns The query request object.
|
|
2532
|
+
* @internal
|
|
2533
|
+
*/
|
|
2534
|
+
private buildRequest;
|
|
2535
|
+
private buildWhereClause;
|
|
2536
|
+
private addJoinClause;
|
|
2537
|
+
private addAggregate;
|
|
2538
|
+
private requireWebSocketTransport;
|
|
2539
|
+
/**
|
|
2540
|
+
* Executes the query and returns the results.
|
|
2541
|
+
*
|
|
2542
|
+
* Sends a POST request to `/api/query` with the built query
|
|
2543
|
+
* and converts the columnar response to row objects.
|
|
2544
|
+
*
|
|
2545
|
+
* @returns The query result with rows and statistics.
|
|
2546
|
+
*
|
|
2547
|
+
* @example
|
|
2548
|
+
* ```typescript
|
|
2549
|
+
* const result = await client.table('orders')
|
|
2550
|
+
* .where('status', '=', 'active')
|
|
2551
|
+
* .execute();
|
|
2552
|
+
*
|
|
2553
|
+
* console.log(result.rows);
|
|
2554
|
+
* console.log(result.stats.executionMs);
|
|
2555
|
+
* ```
|
|
2556
|
+
*/
|
|
2557
|
+
execute(): Promise<QueryResult<T>>;
|
|
2558
|
+
/**
|
|
2559
|
+
* Executes the query and returns the raw columnar JSON payload (no row-object conversion).
|
|
2560
|
+
*/
|
|
2561
|
+
toColumnar(): Promise<ColumnarResponse>;
|
|
2562
|
+
/**
|
|
2563
|
+
* Executes a count query and returns the number of matching rows.
|
|
2564
|
+
*
|
|
2565
|
+
* This is a convenience method that executes the query with
|
|
2566
|
+
* limit 0 and returns the rowCount from statistics.
|
|
2567
|
+
*
|
|
2568
|
+
* @returns The number of rows matching the query.
|
|
2569
|
+
*
|
|
2570
|
+
* @example
|
|
2571
|
+
* ```typescript
|
|
2572
|
+
* const count = await client.table('orders')
|
|
2573
|
+
* .where('status', '=', 'active')
|
|
2574
|
+
* .count();
|
|
2575
|
+
* ```
|
|
2576
|
+
*/
|
|
2577
|
+
count(): Promise<number>;
|
|
2578
|
+
/**
|
|
2579
|
+
* Inserts a single row into the table.
|
|
2580
|
+
*
|
|
2581
|
+
* This is a terminal operation — it executes immediately and returns
|
|
2582
|
+
* a Promise. It does not use query builder state (where, orderBy, etc.).
|
|
2583
|
+
*
|
|
2584
|
+
* @param row - The row data to insert. Keys are column names.
|
|
2585
|
+
* @returns The insert result with row count, execution time, and optional generated values.
|
|
2586
|
+
* @throws Error if `row` is null or undefined.
|
|
2587
|
+
*
|
|
2588
|
+
* @example
|
|
2589
|
+
* ```typescript
|
|
2590
|
+
* const result = await client.table('orders')
|
|
2591
|
+
* .insert({ status: 'pending', price: 100 });
|
|
2592
|
+
*
|
|
2593
|
+
* console.log(result.rowsInserted); // 1
|
|
2594
|
+
* console.log(result.generatedValues); // { "0": { id: 42 } }
|
|
2595
|
+
* ```
|
|
2596
|
+
*/
|
|
2597
|
+
insert(row: Partial<T>): Promise<InsertResult>;
|
|
2598
|
+
/**
|
|
2599
|
+
* Inserts multiple rows into the table in a single request.
|
|
2600
|
+
*
|
|
2601
|
+
* This is a terminal operation — it executes immediately and returns
|
|
2602
|
+
* a Promise. It does not use query builder state (where, orderBy, etc.).
|
|
2603
|
+
*
|
|
2604
|
+
* @param rows - Array of row objects to insert. Must contain at least one row.
|
|
2605
|
+
* @returns The insert result with total row count, execution time, and optional generated values.
|
|
2606
|
+
* @throws Error if `rows` is empty.
|
|
2607
|
+
*
|
|
2608
|
+
* @example
|
|
2609
|
+
* ```typescript
|
|
2610
|
+
* const result = await client.table('orders')
|
|
2611
|
+
* .insertMany([
|
|
2612
|
+
* { status: 'pending', price: 100 },
|
|
2613
|
+
* { status: 'shipped', price: 200 },
|
|
2614
|
+
* ]);
|
|
2615
|
+
*
|
|
2616
|
+
* console.log(result.rowsInserted); // 2
|
|
2617
|
+
* ```
|
|
2618
|
+
*/
|
|
2619
|
+
insertMany(rows: Partial<T>[]): Promise<InsertResult>;
|
|
2620
|
+
/**
|
|
2621
|
+
* Updates rows matching the current where predicates.
|
|
2622
|
+
*
|
|
2623
|
+
* This is a terminal operation — it executes immediately and returns
|
|
2624
|
+
* a Promise. Requires at least one `where()` predicate to prevent
|
|
2625
|
+
* accidental bulk updates.
|
|
2626
|
+
*
|
|
2627
|
+
* @param values - The column values to set. Keys are column names.
|
|
2628
|
+
* @returns The mutation result with rows affected and execution time.
|
|
2629
|
+
* @throws Error if no `where()` predicates have been set.
|
|
2630
|
+
* @throws Error if `values` is null, undefined, or empty.
|
|
2631
|
+
*
|
|
2632
|
+
* @example
|
|
2633
|
+
* ```typescript
|
|
2634
|
+
* const result = await client.table('orders')
|
|
2635
|
+
* .where('id', '=', 1)
|
|
2636
|
+
* .update({ status: 'shipped' });
|
|
2637
|
+
*
|
|
2638
|
+
* console.log(result.rowsAffected); // 1
|
|
2639
|
+
* ```
|
|
2640
|
+
*/
|
|
2641
|
+
update(values: Partial<T>, options?: UpdateOptions): Promise<MutationResult>;
|
|
2642
|
+
/**
|
|
2643
|
+
* Deletes rows matching the current where predicates.
|
|
2644
|
+
*
|
|
2645
|
+
* This is a terminal operation — it executes immediately and returns
|
|
2646
|
+
* a Promise. Requires at least one `where()` predicate to prevent
|
|
2647
|
+
* accidental bulk deletes.
|
|
2648
|
+
*
|
|
2649
|
+
* @returns The mutation result with rows affected and execution time.
|
|
2650
|
+
* @throws Error if no `where()` predicates have been set.
|
|
2651
|
+
*
|
|
2652
|
+
* @example
|
|
2653
|
+
* ```typescript
|
|
2654
|
+
* const result = await client.table('orders')
|
|
2655
|
+
* .where('id', '=', 1)
|
|
2656
|
+
* .delete();
|
|
2657
|
+
*
|
|
2658
|
+
* console.log(result.rowsAffected); // 1
|
|
2659
|
+
* ```
|
|
2660
|
+
*/
|
|
2661
|
+
delete(options?: DeleteOptions): Promise<MutationResult>;
|
|
2662
|
+
/**
|
|
2663
|
+
* Truncates the table (removes all rows) while preserving schema.
|
|
2664
|
+
*
|
|
2665
|
+
* This is a terminal operation and does not require where() predicates.
|
|
2666
|
+
*/
|
|
2667
|
+
truncate(): Promise<MutationResult>;
|
|
2668
|
+
/**
|
|
2669
|
+
* Executes multiple update/delete mutations against the same table in one request.
|
|
2670
|
+
*
|
|
2671
|
+
* Each operation must provide its own `where` query builder callback.
|
|
2672
|
+
*/
|
|
2673
|
+
batch(operations: BatchOperationInput<T>[]): Promise<BatchMutationResult>;
|
|
2674
|
+
/**
|
|
2675
|
+
* Bulk-load rows into this table.
|
|
2676
|
+
*
|
|
2677
|
+
* Executes the full `:begin` → `:append × N` → `:commit` sequence,
|
|
2678
|
+
* handling batching and resume-on-reconnect automatically.
|
|
2679
|
+
*
|
|
2680
|
+
* @param rows - Synchronous or asynchronous iterable of row objects.
|
|
2681
|
+
* @param options - Optional bulk-load tuning options.
|
|
2682
|
+
* @returns A handle describing the committed job.
|
|
2683
|
+
*
|
|
2684
|
+
* @example
|
|
2685
|
+
* ```typescript
|
|
2686
|
+
* const handle = await client.table('products').bulkLoad(rows);
|
|
2687
|
+
* console.log(`Loaded ${handle.rowsLoaded} rows`);
|
|
2688
|
+
* ```
|
|
2689
|
+
*/
|
|
2690
|
+
bulkLoad(rows: Iterable<T> | AsyncIterable<T>, options?: BulkLoadOptions): Promise<BulkLoadJobHandle>;
|
|
2691
|
+
}
|
|
2692
|
+
|
|
2693
|
+
/**
|
|
2694
|
+
* Table operations API for @aouda/client.
|
|
2695
|
+
* Provides table listing, schema introspection, and type generation.
|
|
2696
|
+
*/
|
|
2697
|
+
|
|
2698
|
+
/**
|
|
2699
|
+
* API for table listing and metadata operations.
|
|
2700
|
+
* Access via `client.tables`.
|
|
2701
|
+
*/
|
|
2702
|
+
declare class TablesApi {
|
|
2703
|
+
private readonly transport;
|
|
2704
|
+
private readonly database;
|
|
2705
|
+
constructor(transport: Transport, database: string);
|
|
2706
|
+
/**
|
|
2707
|
+
* Lists all tables in the database with statistics.
|
|
2708
|
+
* @returns Array of table summaries (includes rowCount, sizeBytes, timestamps).
|
|
2709
|
+
*/
|
|
2710
|
+
list(): Promise<TableSummary[]>;
|
|
2711
|
+
/**
|
|
2712
|
+
* Gets detailed schema for a specific table.
|
|
2713
|
+
* @param name - The table name.
|
|
2714
|
+
* @returns Table schema with columns.
|
|
2715
|
+
* @throws AoudaNotFoundError if table does not exist.
|
|
2716
|
+
* @throws Error if table name is empty or whitespace-only.
|
|
2717
|
+
*/
|
|
2718
|
+
get(name: string): Promise<TableSchema>;
|
|
2719
|
+
/**
|
|
2720
|
+
* Gets enhanced schema introspection with key arrays and relationships.
|
|
2721
|
+
* Optimized for schema exploration tools like Aouda Studio.
|
|
2722
|
+
* @param name - The table name.
|
|
2723
|
+
* @returns Enhanced schema with primaryKey, partitionKey, clusterColumns, relationships.
|
|
2724
|
+
* @throws AoudaNotFoundError if table does not exist.
|
|
2725
|
+
* @throws Error if table name is empty or whitespace-only.
|
|
2726
|
+
*/
|
|
2727
|
+
schema(name: string): Promise<TableSchemaResponse>;
|
|
2728
|
+
/**
|
|
2729
|
+
* Gets all tables and relationships for ERD visualization.
|
|
2730
|
+
* Returns both declared and inferred relationships.
|
|
2731
|
+
* @returns All tables with column summaries and relationship graph.
|
|
2732
|
+
*/
|
|
2733
|
+
relationships(): Promise<SchemaRelationshipsResponse>;
|
|
2734
|
+
/**
|
|
2735
|
+
* Generates TypeScript interfaces for all tables.
|
|
2736
|
+
* @param options - Generation options (comments, schema wrapper, namespace).
|
|
2737
|
+
* @returns TypeScript code as a string.
|
|
2738
|
+
*/
|
|
2739
|
+
generateTypes(options?: TypeGenerationOptions): Promise<string>;
|
|
2740
|
+
/**
|
|
2741
|
+
* Creates a new table.
|
|
2742
|
+
* @param body - Request body (database, name, columns, optional policy). database must match the client's database.
|
|
2743
|
+
* @returns 201 response body (table detail).
|
|
2744
|
+
* @throws AoudaApiError for TABLE_EXISTS, WRITE_NOT_ALLOWED, INVALID_REQUEST, etc.
|
|
2745
|
+
*/
|
|
2746
|
+
createTable(body: CreateTableRequest): Promise<TableSchema | undefined>;
|
|
2747
|
+
/**
|
|
2748
|
+
* Renames a table.
|
|
2749
|
+
* @param name - Current table name.
|
|
2750
|
+
* @param body - Request body (database, newName).
|
|
2751
|
+
* @returns 200 response body (table detail).
|
|
2752
|
+
* @throws AoudaNotFoundError if table does not exist; AoudaApiError for WRITE_NOT_ALLOWED, etc.
|
|
2753
|
+
*/
|
|
2754
|
+
renameTable(name: string, body: RenameTableRequest): Promise<TableSchema | undefined>;
|
|
2755
|
+
/**
|
|
2756
|
+
* Deletes a table.
|
|
2757
|
+
* @param name - Table name.
|
|
2758
|
+
* @throws AoudaNotFoundError if table does not exist; AoudaApiError for WRITE_NOT_ALLOWED, etc.
|
|
2759
|
+
*/
|
|
2760
|
+
deleteTable(name: string): Promise<void>;
|
|
2761
|
+
/**
|
|
2762
|
+
* Adds a column to a table.
|
|
2763
|
+
* @param tableName - Table name.
|
|
2764
|
+
* @param body - Request body (database, name, type).
|
|
2765
|
+
* @returns 201 response body (column detail).
|
|
2766
|
+
* @throws AoudaNotFoundError if table does not exist; AoudaApiError for COLUMN_EXISTS, WRITE_NOT_ALLOWED, etc.
|
|
2767
|
+
*/
|
|
2768
|
+
addColumn(tableName: string, body: AddColumnRequest): Promise<ColumnSchema | undefined>;
|
|
2769
|
+
/**
|
|
2770
|
+
* Renames a column.
|
|
2771
|
+
* @param tableName - Table name.
|
|
2772
|
+
* @param columnName - Current column name.
|
|
2773
|
+
* @param body - Request body (database, newName).
|
|
2774
|
+
* @returns 200 response body (column detail).
|
|
2775
|
+
* @throws AoudaNotFoundError if table or column does not exist; AoudaApiError for WRITE_NOT_ALLOWED, etc.
|
|
2776
|
+
*/
|
|
2777
|
+
renameColumn(tableName: string, columnName: string, body: RenameColumnRequest): Promise<ColumnSchema | undefined>;
|
|
2778
|
+
/**
|
|
2779
|
+
* Drops a column from a table.
|
|
2780
|
+
* @param tableName - Table name.
|
|
2781
|
+
* @param columnName - Column name.
|
|
2782
|
+
* @throws AoudaNotFoundError if table or column does not exist; AoudaApiError for WRITE_NOT_ALLOWED, etc.
|
|
2783
|
+
*/
|
|
2784
|
+
dropColumn(tableName: string, columnName: string): Promise<void>;
|
|
2785
|
+
/**
|
|
2786
|
+
* Updates a table's storage policy (temperature).
|
|
2787
|
+
* @param name - Table name.
|
|
2788
|
+
* @param body - Request body with storageTemperature ("Auto" | "HotOnly" | "ColdPreferred").
|
|
2789
|
+
* @returns Updated policy (storageTemperature, optional residency).
|
|
2790
|
+
* @throws AoudaNotFoundError if table does not exist; AoudaApiError for WRITE_NOT_ALLOWED, INVALID_REQUEST, etc.
|
|
2791
|
+
*/
|
|
2792
|
+
updatePolicy(name: string, body: UpdateTablePolicyRequest): Promise<TablePolicy>;
|
|
2793
|
+
}
|
|
2794
|
+
|
|
2795
|
+
/**
|
|
2796
|
+
* Databases API for @aouda/client.
|
|
2797
|
+
* Server-level operations: list and create databases.
|
|
2798
|
+
*/
|
|
2799
|
+
|
|
2800
|
+
/**
|
|
2801
|
+
* API for listing and creating databases.
|
|
2802
|
+
* Access via `client.databases`.
|
|
2803
|
+
* Uses server-level paths (GET/POST /api/databases) with no database in path.
|
|
2804
|
+
*/
|
|
2805
|
+
declare class DatabasesApi {
|
|
2806
|
+
private readonly transport;
|
|
2807
|
+
constructor(transport: Transport);
|
|
2808
|
+
/**
|
|
2809
|
+
* Lists all databases on the server.
|
|
2810
|
+
* GET /api/databases
|
|
2811
|
+
*
|
|
2812
|
+
* @returns Array of database info (name, state, createdAt, options).
|
|
2813
|
+
*/
|
|
2814
|
+
list(): Promise<DatabaseInfo[]>;
|
|
2815
|
+
/**
|
|
2816
|
+
* Creates a new database.
|
|
2817
|
+
* POST /api/databases
|
|
2818
|
+
*
|
|
2819
|
+
* @param name - Database name.
|
|
2820
|
+
* @param options - Optional settings (enableWal, replicationMode, maxMemoryBytes, defaultTemperature).
|
|
2821
|
+
* @returns The created database info.
|
|
2822
|
+
*/
|
|
2823
|
+
create(name: string, options?: CreateDatabaseOptions): Promise<DatabaseInfo>;
|
|
2824
|
+
/**
|
|
2825
|
+
* Gets information for a single database.
|
|
2826
|
+
* GET /api/databases/{db}
|
|
2827
|
+
*
|
|
2828
|
+
* @param databaseName - Database name.
|
|
2829
|
+
* @returns Database info.
|
|
2830
|
+
*/
|
|
2831
|
+
get(databaseName: string): Promise<DatabaseInfo>;
|
|
2832
|
+
/**
|
|
2833
|
+
* Drops a database.
|
|
2834
|
+
* DELETE /api/databases/{db}
|
|
2835
|
+
*
|
|
2836
|
+
* @param databaseName - Database name.
|
|
2837
|
+
*/
|
|
2838
|
+
drop(databaseName: string): Promise<void>;
|
|
2839
|
+
}
|
|
2840
|
+
|
|
2841
|
+
/**
|
|
2842
|
+
* Schema management API: diff, apply, export, history.
|
|
2843
|
+
* Uses server endpoints under /api/databases/{db}/schema.
|
|
2844
|
+
*/
|
|
2845
|
+
|
|
2846
|
+
/** Server diff result (matches SchemaDiffResult). */
|
|
2847
|
+
interface SchemaDiffResult {
|
|
2848
|
+
changes: SchemaChange[];
|
|
2849
|
+
summary: DiffSummary;
|
|
2850
|
+
warnings?: SchemaChangeWarning[];
|
|
2851
|
+
}
|
|
2852
|
+
interface SchemaChange {
|
|
2853
|
+
type: string;
|
|
2854
|
+
tableName?: string | null;
|
|
2855
|
+
columnName?: string | null;
|
|
2856
|
+
isDestructive: boolean;
|
|
2857
|
+
details: string;
|
|
2858
|
+
before?: unknown;
|
|
2859
|
+
after?: unknown;
|
|
2860
|
+
}
|
|
2861
|
+
interface DiffSummary {
|
|
2862
|
+
totalChanges: number;
|
|
2863
|
+
safeChanges: number;
|
|
2864
|
+
destructiveChanges: number;
|
|
2865
|
+
tablesCreated: number;
|
|
2866
|
+
tablesDropped: number;
|
|
2867
|
+
columnsAdded: number;
|
|
2868
|
+
columnsDropped: number;
|
|
2869
|
+
policiesUpdated: number;
|
|
2870
|
+
durabilitiesUpdated: number;
|
|
2871
|
+
settingsUpdated: number;
|
|
2872
|
+
}
|
|
2873
|
+
interface SchemaChangeWarning {
|
|
2874
|
+
code?: string;
|
|
2875
|
+
message?: string;
|
|
2876
|
+
}
|
|
2877
|
+
/** Server apply response (SchemaApplyResponse). */
|
|
2878
|
+
interface SchemaApplyResponse {
|
|
2879
|
+
result: SchemaApplyResult;
|
|
2880
|
+
historyId?: number | null;
|
|
2881
|
+
}
|
|
2882
|
+
interface SchemaApplyResult {
|
|
2883
|
+
entries: ApplyResultEntry[];
|
|
2884
|
+
summary: ApplyResultSummary;
|
|
2885
|
+
}
|
|
2886
|
+
interface ApplyResultEntry {
|
|
2887
|
+
changeType: string;
|
|
2888
|
+
tableName?: string | null;
|
|
2889
|
+
columnName?: string | null;
|
|
2890
|
+
status: string;
|
|
2891
|
+
reason?: string | null;
|
|
2892
|
+
}
|
|
2893
|
+
interface ApplyResultSummary {
|
|
2894
|
+
totalChanges: number;
|
|
2895
|
+
applied: number;
|
|
2896
|
+
skipped: number;
|
|
2897
|
+
failed: number;
|
|
2898
|
+
planned: number;
|
|
2899
|
+
}
|
|
2900
|
+
/** Migration history entry (MigrationHistoryEntry). */
|
|
2901
|
+
interface MigrationHistoryEntry {
|
|
2902
|
+
id: number;
|
|
2903
|
+
timestamp: string;
|
|
2904
|
+
source: string;
|
|
2905
|
+
schemaHash: string;
|
|
2906
|
+
changes: MigrationChangeEntry[];
|
|
2907
|
+
appliedBy?: string | null;
|
|
2908
|
+
}
|
|
2909
|
+
interface MigrationChangeEntry {
|
|
2910
|
+
changeType?: string;
|
|
2911
|
+
tableName?: string | null;
|
|
2912
|
+
columnName?: string | null;
|
|
2913
|
+
status?: string;
|
|
2914
|
+
}
|
|
2915
|
+
/** Per-table counts from `POST .../schema/seed`. */
|
|
2916
|
+
interface SeedTableApplyResult {
|
|
2917
|
+
insertedCount: number;
|
|
2918
|
+
skippedCount: number;
|
|
2919
|
+
}
|
|
2920
|
+
/** Root response from seed apply. */
|
|
2921
|
+
interface SeedApplyResult {
|
|
2922
|
+
tables: Record<string, SeedTableApplyResult>;
|
|
2923
|
+
}
|
|
2924
|
+
/**
|
|
2925
|
+
* Schema API for Aouda (diff, apply, export, history).
|
|
2926
|
+
*/
|
|
2927
|
+
declare class SchemaApi {
|
|
2928
|
+
private readonly transport;
|
|
2929
|
+
private readonly database;
|
|
2930
|
+
constructor(transport: Transport, database: string);
|
|
2931
|
+
private get prefix();
|
|
2932
|
+
/**
|
|
2933
|
+
* Compute diff between desired schema and current database.
|
|
2934
|
+
* @param desired - Schema document (merged from file + overlay).
|
|
2935
|
+
* @param format - "json" (default) or "markdown".
|
|
2936
|
+
*/
|
|
2937
|
+
diff(desired: Record<string, unknown>, format?: "json" | "markdown"): Promise<SchemaDiffResult | string>;
|
|
2938
|
+
/**
|
|
2939
|
+
* Apply desired schema to the database.
|
|
2940
|
+
*/
|
|
2941
|
+
apply(desired: Record<string, unknown>, options?: {
|
|
2942
|
+
allowDestructive?: boolean;
|
|
2943
|
+
dryRun?: boolean;
|
|
2944
|
+
}): Promise<SchemaApplyResponse>;
|
|
2945
|
+
/**
|
|
2946
|
+
* Export current database schema as JSON (aouda.schema.json format).
|
|
2947
|
+
*/
|
|
2948
|
+
export(): Promise<Record<string, unknown>>;
|
|
2949
|
+
/**
|
|
2950
|
+
* Get paginated migration history (newest first).
|
|
2951
|
+
*/
|
|
2952
|
+
history(limit?: number, offset?: number): Promise<MigrationHistoryEntry[]>;
|
|
2953
|
+
/**
|
|
2954
|
+
* Apply seed data (idempotent inserts). Body is a aouda seed document (`{ tables: { ... } }`).
|
|
2955
|
+
*/
|
|
2956
|
+
seed(document: Record<string, unknown>): Promise<SeedApplyResult>;
|
|
2957
|
+
}
|
|
2958
|
+
|
|
2959
|
+
/**
|
|
2960
|
+
* Branches API: list, create, get, delete, diff, merge.
|
|
2961
|
+
* Uses server endpoints under /api/databases/{db}/branches.
|
|
2962
|
+
*/
|
|
2963
|
+
|
|
2964
|
+
/** Branch metadata (and optional diff from parent). Matches server BranchInfo. */
|
|
2965
|
+
interface BranchInfo {
|
|
2966
|
+
name: string;
|
|
2967
|
+
from: string;
|
|
2968
|
+
createdAt: string;
|
|
2969
|
+
diff?: SchemaDiffResult | null;
|
|
2970
|
+
}
|
|
2971
|
+
/** Request body for creating a branch. */
|
|
2972
|
+
interface CreateBranchRequest {
|
|
2973
|
+
name: string;
|
|
2974
|
+
parentBranch?: string;
|
|
2975
|
+
/** Server uses "from" for parent branch name. */
|
|
2976
|
+
from?: string;
|
|
2977
|
+
}
|
|
2978
|
+
/** Options for merge (dry-run vs execute). */
|
|
2979
|
+
interface MergeBranchOptions {
|
|
2980
|
+
dryRun?: boolean;
|
|
2981
|
+
/** Server uses "execute" in body. */
|
|
2982
|
+
execute?: boolean;
|
|
2983
|
+
allowDestructive?: boolean;
|
|
2984
|
+
force?: boolean;
|
|
2985
|
+
}
|
|
2986
|
+
/** Merge conflict (branch change vs parent change). */
|
|
2987
|
+
interface MergeConflict {
|
|
2988
|
+
branchChange: SchemaChange;
|
|
2989
|
+
parentChange: SchemaChange;
|
|
2990
|
+
description: string;
|
|
2991
|
+
}
|
|
2992
|
+
/** Merge plan result (dry-run). */
|
|
2993
|
+
interface MergeResult {
|
|
2994
|
+
mergePlan: SchemaDiffResult;
|
|
2995
|
+
conflicts: MergeConflict[];
|
|
2996
|
+
hasConflicts: boolean;
|
|
2997
|
+
parentDiverged: boolean;
|
|
2998
|
+
branchName: string;
|
|
2999
|
+
baseSnapshotMissing?: boolean;
|
|
3000
|
+
}
|
|
3001
|
+
/** Result of executing a merge. */
|
|
3002
|
+
interface MergeExecutionResult {
|
|
3003
|
+
mergeResult: MergeResult;
|
|
3004
|
+
applyResult?: SchemaApplyResult | null;
|
|
3005
|
+
historyId?: number | null;
|
|
3006
|
+
executed: boolean;
|
|
3007
|
+
}
|
|
3008
|
+
/**
|
|
3009
|
+
* Branches API for Aouda (database-scoped).
|
|
3010
|
+
*/
|
|
3011
|
+
declare class BranchesApi {
|
|
3012
|
+
private readonly transport;
|
|
3013
|
+
private readonly database;
|
|
3014
|
+
constructor(transport: Transport, database: string);
|
|
3015
|
+
private get prefix();
|
|
3016
|
+
/** List all branches (excluding implicit main). */
|
|
3017
|
+
list(): Promise<BranchInfo[]>;
|
|
3018
|
+
/** Create a branch. Parent defaults to main. */
|
|
3019
|
+
create(body: CreateBranchRequest): Promise<BranchInfo>;
|
|
3020
|
+
/** Get branch details (includes diff from parent when available). */
|
|
3021
|
+
get(name: string): Promise<BranchInfo>;
|
|
3022
|
+
/** Get schema diff of branch vs parent. */
|
|
3023
|
+
diff(name: string): Promise<SchemaDiffResult>;
|
|
3024
|
+
/**
|
|
3025
|
+
* Merge branch to parent (main). Use dryRun: true to get plan, then execute without dryRun to apply.
|
|
3026
|
+
* Returns MergeResult when dryRun (or no options); returns MergeExecutionResult when execute: true.
|
|
3027
|
+
*/
|
|
3028
|
+
merge(name: string, options?: MergeBranchOptions): Promise<MergeResult | MergeExecutionResult>;
|
|
3029
|
+
/** Delete a branch. */
|
|
3030
|
+
delete(name: string): Promise<void>;
|
|
3031
|
+
}
|
|
3032
|
+
|
|
3033
|
+
/**
|
|
3034
|
+
* Materialized query HTTP API (`/api/databases/{db}/materialized-queries`).
|
|
3035
|
+
*/
|
|
3036
|
+
|
|
3037
|
+
/** Matches server `MaterializedQueryType` enum (numeric). */
|
|
3038
|
+
declare const MaterializedQueryType: {
|
|
3039
|
+
readonly LatestPerKey: 1;
|
|
3040
|
+
readonly FirstPerKey: 2;
|
|
3041
|
+
readonly Aggregate: 3;
|
|
3042
|
+
readonly Filter: 4;
|
|
3043
|
+
readonly TopNPerGroup: 5;
|
|
3044
|
+
};
|
|
3045
|
+
type MaterializedQueryTypeNumber = (typeof MaterializedQueryType)[keyof typeof MaterializedQueryType];
|
|
3046
|
+
/** Matches server `MaterializedQueryState` enum (numeric). */
|
|
3047
|
+
declare const MaterializedQueryState: {
|
|
3048
|
+
readonly Building: 0;
|
|
3049
|
+
readonly Ready: 1;
|
|
3050
|
+
readonly Rebuilding: 2;
|
|
3051
|
+
readonly Error: 3;
|
|
3052
|
+
};
|
|
3053
|
+
type MaterializedQueryStateNumber = (typeof MaterializedQueryState)[keyof typeof MaterializedQueryState];
|
|
3054
|
+
/** Status DTO returned by list/get (camelCase JSON from ASP.NET). */
|
|
3055
|
+
interface MaterializedQueryStatus {
|
|
3056
|
+
name: string;
|
|
3057
|
+
sourceTable: string;
|
|
3058
|
+
type: number;
|
|
3059
|
+
state: number;
|
|
3060
|
+
rowCount: number;
|
|
3061
|
+
createdUtc: string;
|
|
3062
|
+
lastUpdatedUtc?: string | null;
|
|
3063
|
+
currentLag?: string | null;
|
|
3064
|
+
rebuildProgress?: number | null;
|
|
3065
|
+
errorMessage?: string | null;
|
|
3066
|
+
}
|
|
3067
|
+
/**
|
|
3068
|
+
* Create payload: `configJson` is the type-specific config string (FilterConfig, LatestPerKeyConfig, …).
|
|
3069
|
+
* You may pass `config` as an object instead; it is JSON-stringified for the wire body.
|
|
3070
|
+
*/
|
|
3071
|
+
interface MaterializedQueryDefinition {
|
|
3072
|
+
version?: number;
|
|
3073
|
+
name: string;
|
|
3074
|
+
sourceTable: string;
|
|
3075
|
+
type: MaterializedQueryTypeNumber;
|
|
3076
|
+
/** Serialized JSON text for the pattern config. */
|
|
3077
|
+
configJson?: string;
|
|
3078
|
+
/** If set (and `configJson` omitted), serialized with `JSON.stringify`. */
|
|
3079
|
+
config?: unknown;
|
|
3080
|
+
storage?: {
|
|
3081
|
+
storageTemperature?: string;
|
|
3082
|
+
};
|
|
3083
|
+
updateMode?: number;
|
|
3084
|
+
}
|
|
3085
|
+
interface MaterializedQueryExecuteResult {
|
|
3086
|
+
rows: Record<string, unknown>[];
|
|
3087
|
+
stats?: {
|
|
3088
|
+
rowsScanned: number;
|
|
3089
|
+
rowsReturned: number;
|
|
3090
|
+
executionMs: number;
|
|
3091
|
+
};
|
|
3092
|
+
}
|
|
3093
|
+
/** Placeholder for future filter/limit on materialized query execution. */
|
|
3094
|
+
type MaterializedQueryExecuteOptions = Record<string, never>;
|
|
3095
|
+
interface MaterializedQueryRefreshOptions {
|
|
3096
|
+
await?: boolean;
|
|
3097
|
+
}
|
|
3098
|
+
/**
|
|
3099
|
+
* Materialized query operations for a single database.
|
|
3100
|
+
*/
|
|
3101
|
+
declare class MaterializedQueriesApi {
|
|
3102
|
+
private readonly transport;
|
|
3103
|
+
private readonly database;
|
|
3104
|
+
constructor(transport: Transport, database: string);
|
|
3105
|
+
private get prefix();
|
|
3106
|
+
list(): Promise<MaterializedQueryStatus[]>;
|
|
3107
|
+
/**
|
|
3108
|
+
* Create a materialized query. Server returns 204 with an empty body on success.
|
|
3109
|
+
*/
|
|
3110
|
+
create(spec: MaterializedQueryDefinition): Promise<void>;
|
|
3111
|
+
drop(name: string): Promise<void>;
|
|
3112
|
+
status(name: string): Promise<MaterializedQueryStatus>;
|
|
3113
|
+
refresh(name: string, options?: MaterializedQueryRefreshOptions): Promise<void>;
|
|
3114
|
+
/**
|
|
3115
|
+
* Read rows from a Ready materialized query. Optional `options` reserved for future use.
|
|
3116
|
+
*/
|
|
3117
|
+
query(name: string, _options?: MaterializedQueryExecuteOptions): Promise<MaterializedQueryExecuteResult>;
|
|
3118
|
+
}
|
|
3119
|
+
|
|
3120
|
+
/**
|
|
3121
|
+
* @aouda/client — AoudaClient implementation.
|
|
3122
|
+
*/
|
|
3123
|
+
|
|
3124
|
+
/**
|
|
3125
|
+
* Official TypeScript client for Aouda.
|
|
3126
|
+
*
|
|
3127
|
+
* When a schema type `S` is supplied (e.g. from the Type Generation CLI),
|
|
3128
|
+
* use `AoudaClient<S>` or `createAoudaClient<S>(options)` for table and
|
|
3129
|
+
* column name autocomplete and inferred result row types.
|
|
3130
|
+
*
|
|
3131
|
+
* Basic usage:
|
|
3132
|
+
* ```typescript
|
|
3133
|
+
* const client = new AoudaClient({ serverUrl: "http://localhost:8080", database: "mydb" });
|
|
3134
|
+
* await client.connect();
|
|
3135
|
+
* const health = await client.health();
|
|
3136
|
+
* console.log(health.isHealthy);
|
|
3137
|
+
* await client.disconnect();
|
|
3138
|
+
* ```
|
|
3139
|
+
*
|
|
3140
|
+
* @typeParam S - Schema type with `tables` mapping table names to row types. Defaults to untyped (any table name, Record<string, unknown> rows).
|
|
3141
|
+
*/
|
|
3142
|
+
declare class AoudaClient<S extends SchemaLike = DefaultSchema> {
|
|
3143
|
+
private readonly transport;
|
|
3144
|
+
private readonly baseUrl;
|
|
3145
|
+
private readonly timeout;
|
|
3146
|
+
private readonly database;
|
|
3147
|
+
private connected;
|
|
3148
|
+
private readonly _tables;
|
|
3149
|
+
private readonly _databases;
|
|
3150
|
+
private readonly _schema;
|
|
3151
|
+
private readonly _branches;
|
|
3152
|
+
private readonly _admin;
|
|
3153
|
+
private readonly _materializedQueries;
|
|
3154
|
+
private readonly _auth;
|
|
3155
|
+
private readonly _authHandler;
|
|
3156
|
+
private readonly _streamingEnableCompression;
|
|
3157
|
+
private readonly _streamingWireMode;
|
|
3158
|
+
private readonly _streamingEnableLongPollFallback;
|
|
3159
|
+
private readonly _streamingLongPollWaitMs;
|
|
3160
|
+
private _wsTransport;
|
|
3161
|
+
/**
|
|
3162
|
+
* Creates a new AoudaClient instance.
|
|
3163
|
+
*
|
|
3164
|
+
* @param options - Client configuration options.
|
|
3165
|
+
* @throws Error if serverUrl or database is empty or invalid.
|
|
3166
|
+
*/
|
|
3167
|
+
constructor(options: AoudaClientOptions);
|
|
3168
|
+
/**
|
|
3169
|
+
* Connects to the Aouda server.
|
|
3170
|
+
*
|
|
3171
|
+
* This method validates the configuration and optionally verifies
|
|
3172
|
+
* connectivity by calling the health endpoint. For HTTP clients,
|
|
3173
|
+
* no persistent connection is maintained; this method ensures
|
|
3174
|
+
* the client is in a valid state and the server is reachable.
|
|
3175
|
+
*
|
|
3176
|
+
* @throws AoudaConnectionError if the server is unreachable.
|
|
3177
|
+
* @throws AoudaTimeoutError if the health check times out.
|
|
3178
|
+
*/
|
|
3179
|
+
connect(): Promise<void>;
|
|
3180
|
+
/**
|
|
3181
|
+
* Disconnects from the Aouda server.
|
|
3182
|
+
*
|
|
3183
|
+
* This method releases any resources held by the client.
|
|
3184
|
+
* For HTTP clients, this aborts any pending requests and
|
|
3185
|
+
* resets internal state. This method is idempotent and
|
|
3186
|
+
* safe to call multiple times.
|
|
3187
|
+
*/
|
|
3188
|
+
disconnect(): Promise<void>;
|
|
3189
|
+
/**
|
|
3190
|
+
* Checks the health of the Aouda server.
|
|
3191
|
+
*
|
|
3192
|
+
* Performs a GET request to the /health endpoint and returns
|
|
3193
|
+
* the health status. The request respects the configured timeout
|
|
3194
|
+
* and will be aborted if disconnect() is called.
|
|
3195
|
+
*
|
|
3196
|
+
* @returns The health status of the server.
|
|
3197
|
+
* @throws AoudaConnectionError if the server is unreachable or client is disconnected.
|
|
3198
|
+
* @throws AoudaTimeoutError if the request times out.
|
|
3199
|
+
* @throws AoudaResponseError if the server returns a non-2xx status.
|
|
3200
|
+
*/
|
|
3201
|
+
health(): Promise<HealthStatus>;
|
|
3202
|
+
/**
|
|
3203
|
+
* Creates a query builder for the specified table.
|
|
3204
|
+
*
|
|
3205
|
+
* This is the primary entry point for querying data from Aouda.
|
|
3206
|
+
* Returns a fluent query builder that can be chained with
|
|
3207
|
+
* `where()`, `orderBy()`, `limit()`, etc.
|
|
3208
|
+
*
|
|
3209
|
+
* When the client is typed with a schema (e.g. createAoudaClient<Schema>(options)),
|
|
3210
|
+
* `name` is constrained to keys of `S['tables']` and the returned query is typed
|
|
3211
|
+
* with the corresponding row type.
|
|
3212
|
+
*
|
|
3213
|
+
* @param name - The name of the table to query.
|
|
3214
|
+
* @returns A new TableQuery instance for building the query.
|
|
3215
|
+
* @throws Error if the table name is empty or whitespace-only.
|
|
3216
|
+
*
|
|
3217
|
+
* @example
|
|
3218
|
+
* ```typescript
|
|
3219
|
+
* const results = await client.table('orders')
|
|
3220
|
+
* .where('status', '=', 'active')
|
|
3221
|
+
* .orderBy('price', 'desc')
|
|
3222
|
+
* .limit(50)
|
|
3223
|
+
* .execute();
|
|
3224
|
+
* ```
|
|
3225
|
+
*/
|
|
3226
|
+
table<N extends keyof S["tables"]>(name: N): TableQuery<S["tables"][N]>;
|
|
3227
|
+
/**
|
|
3228
|
+
* Access table listing and schema operations.
|
|
3229
|
+
* @returns The tables API.
|
|
3230
|
+
*/
|
|
3231
|
+
get tables(): TablesApi;
|
|
3232
|
+
/**
|
|
3233
|
+
* Access server-level database operations (list, create, get, drop).
|
|
3234
|
+
* @returns The databases API.
|
|
3235
|
+
*/
|
|
3236
|
+
get databases(): DatabasesApi;
|
|
3237
|
+
/**
|
|
3238
|
+
* Access schema management operations (diff, apply, export, history).
|
|
3239
|
+
* @returns The schema API.
|
|
3240
|
+
*/
|
|
3241
|
+
get schema(): SchemaApi;
|
|
3242
|
+
/**
|
|
3243
|
+
* Access branch operations (list, create, get, diff, merge, delete).
|
|
3244
|
+
* @returns The branches API.
|
|
3245
|
+
*/
|
|
3246
|
+
get branches(): BranchesApi;
|
|
3247
|
+
/**
|
|
3248
|
+
* Access admin operations (server info, memory, metrics, health).
|
|
3249
|
+
* @returns The admin API.
|
|
3250
|
+
*/
|
|
3251
|
+
get admin(): AdminApi;
|
|
3252
|
+
/**
|
|
3253
|
+
* Materialized query lifecycle (list, create, drop, status, query).
|
|
3254
|
+
*/
|
|
3255
|
+
get materializedQueries(): MaterializedQueriesApi;
|
|
3256
|
+
/**
|
|
3257
|
+
* Access auth operations (signUp, signIn, signOut, refresh, me, changePassword).
|
|
3258
|
+
* @returns The auth API.
|
|
3259
|
+
* @throws Error if auth is not configured on this client.
|
|
3260
|
+
*/
|
|
3261
|
+
get auth(): AuthClient;
|
|
3262
|
+
/**
|
|
3263
|
+
* Returns whether the client is currently connected.
|
|
3264
|
+
*/
|
|
3265
|
+
get isConnected(): boolean;
|
|
3266
|
+
/**
|
|
3267
|
+
* Returns the configured server URL (normalized).
|
|
3268
|
+
*/
|
|
3269
|
+
get serverUrl(): string;
|
|
3270
|
+
/**
|
|
3271
|
+
* Returns the configured timeout in milliseconds.
|
|
3272
|
+
*/
|
|
3273
|
+
get timeoutMs(): number;
|
|
3274
|
+
/**
|
|
3275
|
+
* Returns the configured database name.
|
|
3276
|
+
*/
|
|
3277
|
+
get databaseName(): string;
|
|
3278
|
+
/**
|
|
3279
|
+
* Resets the circuit breaker to closed state.
|
|
3280
|
+
* Call after manual recovery or when the server is known to be healthy again.
|
|
3281
|
+
*/
|
|
3282
|
+
resetCircuitBreaker(): void;
|
|
3283
|
+
/**
|
|
3284
|
+
* Bulk-load rows into a single table.
|
|
3285
|
+
*
|
|
3286
|
+
* Executes the full `:begin` → `:append × N` → `:commit` sequence, handling
|
|
3287
|
+
* batching and resume-on-reconnect automatically.
|
|
3288
|
+
*
|
|
3289
|
+
* @param tableName - Target table.
|
|
3290
|
+
* @param rows - Synchronous or asynchronous iterable of row objects.
|
|
3291
|
+
* @param options - Optional bulk-load tuning options.
|
|
3292
|
+
* @returns A handle describing the committed job and providing deferred-work polling.
|
|
3293
|
+
*
|
|
3294
|
+
* @example
|
|
3295
|
+
* ```typescript
|
|
3296
|
+
* const handle = await client.bulkLoad('products', rows, { writeConcern: 'majority' });
|
|
3297
|
+
* console.log(`Loaded ${handle.rowsLoaded} rows, job ${handle.jobId}`);
|
|
3298
|
+
* ```
|
|
3299
|
+
*/
|
|
3300
|
+
bulkLoad<T extends Record<string, unknown>>(tableName: string, rows: Iterable<T> | AsyncIterable<T>, options?: BulkLoadOptions): Promise<BulkLoadJobHandle>;
|
|
3301
|
+
/**
|
|
3302
|
+
* Bulk-load rows into multiple tables atomically.
|
|
3303
|
+
*
|
|
3304
|
+
* Each row must include a `_table` discriminator field that matches one of
|
|
3305
|
+
* the supplied table names.
|
|
3306
|
+
*
|
|
3307
|
+
* @param tables - Target table names.
|
|
3308
|
+
* @param rows - Synchronous or asynchronous iterable of row objects.
|
|
3309
|
+
* @param options - Optional bulk-load tuning options.
|
|
3310
|
+
* @returns A handle describing the committed job.
|
|
3311
|
+
*/
|
|
3312
|
+
bulkLoadMultiTable<T extends Record<string, unknown>>(tables: readonly string[], rows: Iterable<T> | AsyncIterable<T>, options?: BulkLoadOptions): Promise<BulkLoadJobHandle>;
|
|
3313
|
+
/**
|
|
3314
|
+
* List all bulk-load sessions registered for a database.
|
|
3315
|
+
* Admin use: returns both active and recently-completed jobs from the in-memory registry.
|
|
3316
|
+
*/
|
|
3317
|
+
bulkLoadList(db: string): Promise<BulkLoadListResponse>;
|
|
3318
|
+
/**
|
|
3319
|
+
* Force-abort a stuck bulk-load job by emitting a BulkLoadAborted WAL frame.
|
|
3320
|
+
* Requires BulkLoad + write permission. Use only when the job is in a terminal-wait
|
|
3321
|
+
* state past its bulkLoadResumeWindow.
|
|
3322
|
+
*/
|
|
3323
|
+
bulkLoadForceAbort(db: string, jobId: string, reason: string): Promise<BulkLoadForceAbortResponse>;
|
|
3324
|
+
/**
|
|
3325
|
+
* Returns the shared WebSocketTransport for this client, creating it lazily
|
|
3326
|
+
* on the first call. Used internally by streaming operations (S13+).
|
|
3327
|
+
*
|
|
3328
|
+
* @internal
|
|
3329
|
+
*/
|
|
3330
|
+
_getOrCreateWebSocketTransport(): StreamingTransport;
|
|
3331
|
+
}
|
|
3332
|
+
/**
|
|
3333
|
+
* Factory function to create a new AoudaClient instance.
|
|
3334
|
+
*
|
|
3335
|
+
* When a schema type `S` is provided, the returned client's `table()` method
|
|
3336
|
+
* accepts only table names from `S['tables']` and returns typed TableQuery.
|
|
3337
|
+
* Without a type argument, behavior is unchanged (any string table name,
|
|
3338
|
+
* rows as Record<string, unknown>).
|
|
3339
|
+
*
|
|
3340
|
+
* @param options - Client configuration options.
|
|
3341
|
+
* @returns A new AoudaClient instance.
|
|
3342
|
+
*
|
|
3343
|
+
* @example
|
|
3344
|
+
* ```typescript
|
|
3345
|
+
* const client = createAoudaClient({ serverUrl: "http://localhost:8080", database: "mydb" });
|
|
3346
|
+
* ```
|
|
3347
|
+
*
|
|
3348
|
+
* @example
|
|
3349
|
+
* ```typescript
|
|
3350
|
+
* const client = createAoudaClient<Schema>({ serverUrl: "http://localhost:8080", database: "mydb" });
|
|
3351
|
+
* const q = client.table('orders'); // TableQuery<Order>
|
|
3352
|
+
* ```
|
|
3353
|
+
*/
|
|
3354
|
+
declare function createAoudaClient<S extends SchemaLike = DefaultSchema>(options: AoudaClientOptions): AoudaClient<S>;
|
|
3355
|
+
|
|
3356
|
+
export { type BulkLoadForceAbortRequest as $, AoudaClient as A, type BulkLoadOptions as B, type CoverageResponse as C, type DetailedHealthResponse as D, type AoudaDataType as E, type FailoverClusterResponse as F, type AppAuthOptions as G, type HealthStatus as H, AuthClient as I, type JoinClusterRequest as J, type AuthResult as K, type ListBackupsResponse as L, type AuthUserInfo as M, type NodeInfoResponse as N, type AuthorizationMode as O, type PromoteClusterResponse as P, BackupAdminApi as Q, type ReplicationStatusResponse as R, type SchemaLike as S, type Transport as T, type BackupMetrics as U, type BackupSummary as V, type BatchMutationResult as W, type BatchOperationInput as X, type BloomFilterMetrics as Y, type BranchInfo as Z, BranchesApi as _, type BulkLoadJobHandle as a, type NodeLogsQuery as a$, type BulkLoadForceAbortResponse as a0, type BulkLoadListResponse as a1, type BulkLoadProgress as a2, type BulkLoadReplicaProgress as a3, type BulkLoadReplicaProgressDto as a4, type BulkLoadStatusResponse as a5, CircuitBreakerPolicy as a6, ClusterAdminApi as a7, type ClusterMemberEntry as a8, type ClusterThisNodeEntry as a9, MaterializedQueriesApi as aA, type MaterializedQueryDefinition as aB, type MaterializedQueryExecuteOptions as aC, type MaterializedQueryExecuteResult as aD, type MaterializedQueryMetrics as aE, type MaterializedQueryRefreshOptions as aF, MaterializedQueryState as aG, type MaterializedQueryStateNumber as aH, type MaterializedQueryStatus as aI, MaterializedQueryType as aJ, type MaterializedQueryTypeNumber as aK, type MemberInfo as aL, type MemoryMetrics as aM, type MergeBranchOptions as aN, type MergeConflict as aO, type MergeExecutionResult as aP, type MergeResult as aQ, MetricsAdminApi as aR, type MetricsHistory as aS, type MetricsHistoryOptions as aT, type MetricsSnapshot as aU, type MetricsSummary as aV, type MutationResult as aW, NodeAdminApi as aX, type NodeLogEntry as aY, type NodeLogLevel as aZ, type NodeLogStreamOptions as a_, type ColumnSchema as aa, type ColumnSummaryForErd as ab, type ColumnarResponse as ac, type ComponentHealthEntry as ad, type ComputedColumnDef as ae, ConfigAdminApi as af, type CreateBranchRequest as ag, type CreateColumnRequest as ah, type CreateDatabaseOptions as ai, type CreatePartitionGrantRequest as aj, type CreateRlsResolverRequest as ak, type CreateTableRequest as al, type DatabaseCoverageEntry as am, type DatabaseInfo as an, type DatabaseMemoryMetrics as ao, type DatabaseMemoryUsage as ap, type DatabaseMetricsDto as aq, type DatabaseOptionsInfo as ar, DatabasesApi as as, type DeleteOptions as at, type DiffSummary as au, HealthAdminApi as av, type IndexInfo as aw, type InsertResult as ax, type IoMetrics as ay, type LatencyPercentiles as az, type TopologyResponse as b, type WriteStream as b$, type NodeLogsResponse as b0, type OpenWriteStreamOptions as b1, type PageCacheMetrics as b2, type PartitionGrant as b3, type PartitionGrantsListResponse as b4, type PartitioningMetrics as b5, type PerDatabaseLagEntry as b6, type PerDatabaseMetrics as b7, type PerDatabaseStatusEntry as b8, type QueryMetrics as b9, type SingleDatabaseMetricsResponse as bA, type SortDirection as bB, type StorageMetrics as bC, type SubscribeOptions as bD, type Subscription as bE, type SubscriptionChangeEvent as bF, type SubscriptionEvent as bG, type SubscriptionInfo as bH, type SubscriptionSnapshotEvent as bI, type TableCoverageEntry as bJ, type TableNameFromSchema as bK, type TablePolicy as bL, TableQuery as bM, type TableSchema as bN, type TableSchemaResponse as bO, type TableSummary as bP, type TableSummaryForErd as bQ, TablesApi as bR, type TimeSeriesMetrics as bS, type TransactionMetrics as bT, type TypeGenerationOptions as bU, type UpdateOptions as bV, type UpdateRlsResolverRequest as bW, type UpdateTablePolicyRequest as bX, type UserProfile as bY, WhereGroupBuilder as bZ, type WhereOperator as b_, type QueryResult as ba, type QueryStats as bb, type ReferenceInfo as bc, type RelationshipEndpoint as bd, type RelationshipInfo as be, type RenameColumnRequest as bf, type RenameTableRequest as bg, ReplicationAdminApi as bh, type ReplicationMetrics as bi, type ResidencyConfig as bj, RetryPolicy as bk, type RlsResolver as bl, type RlsResolverRule as bm, type RlsResolverRuleInput as bn, type RlsResolversListResponse as bo, type SchemaChange as bp, type SchemaDiffResult as bq, type SchemaRelationshipsResponse as br, type SeedApplyResult as bs, type SeedTableApplyResult as bt, ServerAdminApi as bu, type ServerAuthOptions as bv, type ServerMemoryResponse as bw, type ServerMetricsResponse as bx, type ServiceInfo as by, type SimdMetrics as bz, type ReadinessResponse as c, coerceColumnarValue as c0, createAoudaClient as c1, type TriggerBackupRequest as d, type TriggerBackupResponse as e, type RestoreBackupResponse as f, type BackupSchedule as g, type JoinClusterResponse as h, type LeaveClusterResponse as i, type DrainClusterResponse as j, type ClusterConfigResponse as k, type ClusterConfigPatchRequest as l, type DefaultSchema as m, AOUDA_DATA_TYPES as n, type AddColumnRequest as o, AdminApi as p, type AdminBackupConfig as q, type AdminBackupPatch as r, type AdminConfigPatchRequest as s, type AdminConfigResponse as t, type AdminConfigSchemaResponse as u, type AdminLoggingConfig as v, type AdminLoggingPatch as w, type AdminMemoryConfig as x, type AdminMemoryPatch as y, type AoudaClientOptions as z };
|