@wavehouse/sdk 0.0.0-dev.0f8826c
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 +202 -0
- package/README.md +136 -0
- package/dist/index.cjs +1107 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +461 -0
- package/dist/index.d.ts +461 -0
- package/dist/index.js +1069 -0
- package/dist/index.js.map +1 -0
- package/package.json +63 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,461 @@
|
|
|
1
|
+
/** User-provided database schema mapping table names to row types. */
|
|
2
|
+
type Database = Record<string, Record<string, unknown>>;
|
|
3
|
+
/**
|
|
4
|
+
* Discriminated union for all async SDK operations. Never throws.
|
|
5
|
+
*
|
|
6
|
+
* Discriminated on `ok`: `if (result.ok)` narrows to the success arm (and tells
|
|
7
|
+
* the compiler `data` is present), while `error` is always available for
|
|
8
|
+
* debugging on failure. `data`/`error` remain populated as before.
|
|
9
|
+
*/
|
|
10
|
+
type Result<T> = {
|
|
11
|
+
ok: true;
|
|
12
|
+
data: T;
|
|
13
|
+
error: null;
|
|
14
|
+
hasMore?: boolean;
|
|
15
|
+
next?: () => Promise<Result<T>>;
|
|
16
|
+
} | {
|
|
17
|
+
ok: false;
|
|
18
|
+
data: null;
|
|
19
|
+
error: WaveHouseError;
|
|
20
|
+
hasMore?: false;
|
|
21
|
+
next?: undefined;
|
|
22
|
+
};
|
|
23
|
+
/** Structured error returned by all SDK operations. */
|
|
24
|
+
interface WaveHouseError {
|
|
25
|
+
status: number;
|
|
26
|
+
code: string;
|
|
27
|
+
message: string;
|
|
28
|
+
details?: unknown;
|
|
29
|
+
retryable: boolean;
|
|
30
|
+
}
|
|
31
|
+
/** SDK filter operators (translated to backend equivalents). */
|
|
32
|
+
type FilterOp = "=" | "!=" | ">" | ">=" | "<" | "<=" | "in" | "like" | "not_like";
|
|
33
|
+
type StreamStatus = "connecting" | "live" | "reconnecting" | "closed";
|
|
34
|
+
interface StreamEvent<T = Record<string, unknown>> {
|
|
35
|
+
table: string;
|
|
36
|
+
timestamp: string;
|
|
37
|
+
data: T;
|
|
38
|
+
}
|
|
39
|
+
interface StreamSubscriber<T = Record<string, unknown>> {
|
|
40
|
+
/** Called once with historical backfill data. */
|
|
41
|
+
initial?: (result: Result<T[]>) => void;
|
|
42
|
+
/** Called for each live event. */
|
|
43
|
+
next: (event: StreamEvent<T>) => void;
|
|
44
|
+
/** Called when stream connection status changes. */
|
|
45
|
+
status?: (state: StreamStatus) => void;
|
|
46
|
+
/** Called on stream errors. */
|
|
47
|
+
error?: (err: WaveHouseError) => void;
|
|
48
|
+
}
|
|
49
|
+
interface ClientConfig<_DB extends Database = Database> {
|
|
50
|
+
/** Base URL of the WaveHouse server (e.g. "http://localhost:8080"). */
|
|
51
|
+
baseURL: string;
|
|
52
|
+
/** Auth token provider. Omit for public/unauthenticated access. */
|
|
53
|
+
auth?: () => Promise<string> | string;
|
|
54
|
+
/** Additional client options. */
|
|
55
|
+
options?: ClientOptions;
|
|
56
|
+
}
|
|
57
|
+
interface ClientOptions {
|
|
58
|
+
/** Maximum retry attempts for failed requests. Default: 2. */
|
|
59
|
+
maxRetries?: number;
|
|
60
|
+
}
|
|
61
|
+
interface StructuredQuery {
|
|
62
|
+
columns?: string[];
|
|
63
|
+
aggregations?: Aggregation[];
|
|
64
|
+
filters?: QueryFilter[];
|
|
65
|
+
group_by?: string[];
|
|
66
|
+
order_by?: OrderClause[];
|
|
67
|
+
limit?: number;
|
|
68
|
+
time_range?: TimeRange;
|
|
69
|
+
}
|
|
70
|
+
interface Aggregation {
|
|
71
|
+
fn: string;
|
|
72
|
+
column: string;
|
|
73
|
+
alias: string;
|
|
74
|
+
}
|
|
75
|
+
interface QueryFilter {
|
|
76
|
+
column: string;
|
|
77
|
+
op: string;
|
|
78
|
+
value: unknown;
|
|
79
|
+
}
|
|
80
|
+
interface OrderClause {
|
|
81
|
+
column: string;
|
|
82
|
+
dir: "asc" | "desc";
|
|
83
|
+
}
|
|
84
|
+
interface TimeRange {
|
|
85
|
+
column: string;
|
|
86
|
+
since: string;
|
|
87
|
+
until?: string;
|
|
88
|
+
}
|
|
89
|
+
interface Column {
|
|
90
|
+
name: string;
|
|
91
|
+
type: string;
|
|
92
|
+
is_nullable: boolean;
|
|
93
|
+
has_default: boolean;
|
|
94
|
+
}
|
|
95
|
+
interface TableSchema {
|
|
96
|
+
name: string;
|
|
97
|
+
columns: Column[];
|
|
98
|
+
}
|
|
99
|
+
type Schemas = Record<string, TableSchema>;
|
|
100
|
+
interface InsertResult {
|
|
101
|
+
ok: boolean;
|
|
102
|
+
duplicate?: boolean;
|
|
103
|
+
}
|
|
104
|
+
interface DLQStats {
|
|
105
|
+
tables: Record<string, number>;
|
|
106
|
+
total: number;
|
|
107
|
+
}
|
|
108
|
+
interface Pipe {
|
|
109
|
+
name: string;
|
|
110
|
+
sql: string;
|
|
111
|
+
parameters?: ParamDef[];
|
|
112
|
+
description?: string;
|
|
113
|
+
allowed_roles?: string[];
|
|
114
|
+
}
|
|
115
|
+
interface ParamDef {
|
|
116
|
+
name: string;
|
|
117
|
+
type: string;
|
|
118
|
+
required?: boolean;
|
|
119
|
+
default?: unknown;
|
|
120
|
+
}
|
|
121
|
+
interface Policy {
|
|
122
|
+
default_role?: string;
|
|
123
|
+
tables: Record<string, TablePolicy>;
|
|
124
|
+
}
|
|
125
|
+
interface TablePolicy {
|
|
126
|
+
select?: Record<string, RolePermissions>;
|
|
127
|
+
insert?: Record<string, RolePermissions>;
|
|
128
|
+
}
|
|
129
|
+
interface RolePermissions {
|
|
130
|
+
allow_columns?: string[];
|
|
131
|
+
deny_columns?: string[];
|
|
132
|
+
filter?: Record<string, PolicyFilter>;
|
|
133
|
+
check?: Record<string, PolicyFilter>;
|
|
134
|
+
allowed_aggregations?: string[];
|
|
135
|
+
denied_aggregations?: string[];
|
|
136
|
+
max_rows?: number;
|
|
137
|
+
max_execution_time_ms?: number;
|
|
138
|
+
}
|
|
139
|
+
interface PolicyFilter {
|
|
140
|
+
_eq?: string;
|
|
141
|
+
_neq?: string;
|
|
142
|
+
_gt?: string;
|
|
143
|
+
_lt?: string;
|
|
144
|
+
_in?: string;
|
|
145
|
+
}
|
|
146
|
+
interface ValidationResult {
|
|
147
|
+
valid: boolean;
|
|
148
|
+
}
|
|
149
|
+
interface FetchOptions {
|
|
150
|
+
signal?: AbortSignal;
|
|
151
|
+
limit?: number;
|
|
152
|
+
}
|
|
153
|
+
interface StreamOptions {
|
|
154
|
+
since?: string;
|
|
155
|
+
signal?: AbortSignal;
|
|
156
|
+
}
|
|
157
|
+
/** @internal */
|
|
158
|
+
interface HttpContext {
|
|
159
|
+
baseURL: string;
|
|
160
|
+
auth?: () => Promise<string> | string;
|
|
161
|
+
options: {
|
|
162
|
+
maxRetries: number;
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/** @internal Transport abstraction for SSE backend. */
|
|
167
|
+
interface StreamTransport<T = Record<string, unknown>> {
|
|
168
|
+
connect(): void;
|
|
169
|
+
disconnect(): void;
|
|
170
|
+
onEvent: ((event: StreamEvent<T>) => void) | null;
|
|
171
|
+
onStatus: ((status: StreamStatus) => void) | null;
|
|
172
|
+
onError: ((error: WaveHouseError) => void) | null;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Controls a live event stream. NOT thenable.
|
|
176
|
+
* Use `.subscribe()` for callback-based consumption or `for await` for async iteration.
|
|
177
|
+
*/
|
|
178
|
+
declare class StreamController<T = Record<string, unknown>> {
|
|
179
|
+
private _transport;
|
|
180
|
+
private _subscribers;
|
|
181
|
+
private _status;
|
|
182
|
+
private _buffer;
|
|
183
|
+
private _waiters;
|
|
184
|
+
private _done;
|
|
185
|
+
constructor(transport: StreamTransport<T>);
|
|
186
|
+
/** Current connection status. */
|
|
187
|
+
get status(): StreamStatus;
|
|
188
|
+
/**
|
|
189
|
+
* Returns a promise that resolves when the stream status reaches `'live'`,
|
|
190
|
+
* rejects immediately if the stream is already `'closed'`, or rejects after
|
|
191
|
+
* `timeoutMs` milliseconds (default: 5 000) if it never connects.
|
|
192
|
+
*
|
|
193
|
+
* Safe to call before `.subscribe()` — does not trigger auto-close when
|
|
194
|
+
* the internal waiter is removed.
|
|
195
|
+
*
|
|
196
|
+
* `@example`
|
|
197
|
+
* const stream = client.from('events').stream();
|
|
198
|
+
* const unsub = stream.subscribe({ next: (e) => console.log(e) });
|
|
199
|
+
* await stream.connected(); // waits until the transport is live
|
|
200
|
+
* await client.from('events').insert({ ... });
|
|
201
|
+
*/
|
|
202
|
+
connected(timeoutMs?: number): Promise<void>;
|
|
203
|
+
/** Subscribe to stream events via callbacks. Returns an unsubscribe function. */
|
|
204
|
+
subscribe(subscriber: StreamSubscriber<T>): () => void;
|
|
205
|
+
/** Attach an AbortSignal — when aborted, the stream is closed. */
|
|
206
|
+
attachSignal(signal: AbortSignal): void;
|
|
207
|
+
/** Close the stream and release resources. */
|
|
208
|
+
close(): void;
|
|
209
|
+
/** Async iterator protocol — enables `for await (const event of stream)`. */
|
|
210
|
+
[Symbol.asyncIterator](): AsyncIterableIterator<StreamEvent<T>>;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
type CreateStreamFn$3 = (table: string, opts?: StreamOptions) => StreamController;
|
|
214
|
+
/** Namespace for Dead Letter Queue operations. */
|
|
215
|
+
declare class DLQNamespace {
|
|
216
|
+
private readonly _ctx;
|
|
217
|
+
private readonly _createStream;
|
|
218
|
+
constructor(ctx: HttpContext, createStream: CreateStreamFn$3);
|
|
219
|
+
/** Get DLQ statistics (message counts per table). */
|
|
220
|
+
list(opts?: {
|
|
221
|
+
signal?: AbortSignal;
|
|
222
|
+
}): Promise<Result<DLQStats>>;
|
|
223
|
+
/** Get DLQ stats filtered by table name. */
|
|
224
|
+
table(name: string, opts?: {
|
|
225
|
+
signal?: AbortSignal;
|
|
226
|
+
}): Promise<Result<DLQStats>>;
|
|
227
|
+
/** Subscribe to live DLQ events. */
|
|
228
|
+
stream(opts?: StreamOptions): StreamController;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
type CreateStreamFn$2<Row> = (table: string, opts?: StreamOptions) => StreamController<Row>;
|
|
232
|
+
/** Reference to a named query pipe — PromiseLike for convenient `await`. */
|
|
233
|
+
declare class PipeRef<Row = Record<string, unknown>> implements PromiseLike<Result<Row[]>> {
|
|
234
|
+
private readonly _ctx;
|
|
235
|
+
private readonly _name;
|
|
236
|
+
private readonly _params?;
|
|
237
|
+
private readonly _createStream;
|
|
238
|
+
constructor(ctx: HttpContext, name: string, params: Record<string, unknown> | undefined, createStream: CreateStreamFn$2<Row>);
|
|
239
|
+
/** Execute the pipe and return results. */
|
|
240
|
+
fetch(opts?: FetchOptions): Promise<Result<Row[]>>;
|
|
241
|
+
/** Subscribe to live events from the pipe's underlying query. */
|
|
242
|
+
stream(opts?: StreamOptions): StreamController<Row>;
|
|
243
|
+
then<TResult1 = Result<Row[]>, TResult2 = never>(onfulfilled?: ((value: Result<Row[]>) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;
|
|
244
|
+
}
|
|
245
|
+
/** Admin namespace for managing named query pipes. */
|
|
246
|
+
declare class PipesNamespace {
|
|
247
|
+
private readonly _ctx;
|
|
248
|
+
constructor(ctx: HttpContext);
|
|
249
|
+
/** List all registered pipes. */
|
|
250
|
+
list(opts?: {
|
|
251
|
+
signal?: AbortSignal;
|
|
252
|
+
}): Promise<Result<Pipe[]>>;
|
|
253
|
+
/** Get a single pipe definition by name. */
|
|
254
|
+
get(name: string, opts?: {
|
|
255
|
+
signal?: AbortSignal;
|
|
256
|
+
}): Promise<Result<Pipe>>;
|
|
257
|
+
/** Create or update a pipe. */
|
|
258
|
+
set(name: string, def: Omit<Pipe, "name">, opts?: {
|
|
259
|
+
signal?: AbortSignal;
|
|
260
|
+
}): Promise<Result<void>>;
|
|
261
|
+
/** Delete a pipe by name. */
|
|
262
|
+
delete(name: string, opts?: {
|
|
263
|
+
signal?: AbortSignal;
|
|
264
|
+
}): Promise<Result<void>>;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/** Namespace for access control policy management. Requires the admin role (the configured `admin_role`, `"admin"` by default). */
|
|
268
|
+
declare class PolicyNamespace {
|
|
269
|
+
private readonly _ctx;
|
|
270
|
+
constructor(ctx: HttpContext);
|
|
271
|
+
/** Get the current access control policy. */
|
|
272
|
+
get(opts?: {
|
|
273
|
+
signal?: AbortSignal;
|
|
274
|
+
}): Promise<Result<Policy>>;
|
|
275
|
+
/** Replace the entire access control policy. */
|
|
276
|
+
set(policy: Policy, opts?: {
|
|
277
|
+
signal?: AbortSignal;
|
|
278
|
+
}): Promise<Result<void>>;
|
|
279
|
+
/** Validate a policy without applying it (dry run). */
|
|
280
|
+
validate(policy: Policy, opts?: {
|
|
281
|
+
signal?: AbortSignal;
|
|
282
|
+
}): Promise<Result<ValidationResult>>;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/** Namespace for schema introspection. */
|
|
286
|
+
declare class SchemaNamespace {
|
|
287
|
+
private readonly _ctx;
|
|
288
|
+
constructor(ctx: HttpContext);
|
|
289
|
+
/** List all table schemas discovered from ClickHouse. */
|
|
290
|
+
list(opts?: {
|
|
291
|
+
signal?: AbortSignal;
|
|
292
|
+
}): Promise<Result<Schemas>>;
|
|
293
|
+
/** Force a schema refresh from ClickHouse system.columns. */
|
|
294
|
+
refresh(opts?: {
|
|
295
|
+
signal?: AbortSignal;
|
|
296
|
+
}): Promise<Result<void>>;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/** Namespace for the SDK's content-free server-online check. */
|
|
300
|
+
declare class SysNamespace {
|
|
301
|
+
private readonly _ctx;
|
|
302
|
+
constructor(ctx: HttpContext);
|
|
303
|
+
/**
|
|
304
|
+
* Liveness ping — resolves with no error when the server is reachable and
|
|
305
|
+
* past boot. Hits the public, content-free `/v1/health` route (200/503, no
|
|
306
|
+
* body), kept intentionally distinct from the `/livez` Kubernetes probe so
|
|
307
|
+
* it stays reachable even in deployments that filter probe paths at the
|
|
308
|
+
* reverse proxy. Use it to check a server is online before sending data, or
|
|
309
|
+
* to pick among servers in a distributed setup.
|
|
310
|
+
*/
|
|
311
|
+
health(opts?: {
|
|
312
|
+
signal?: AbortSignal;
|
|
313
|
+
}): Promise<Result<void>>;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* Stream-first live query orchestrator.
|
|
318
|
+
*
|
|
319
|
+
* 1. Opens a live stream immediately (buffers events).
|
|
320
|
+
* 2. Fetches historical data.
|
|
321
|
+
* 3. Calls `subscriber.initial(result)` with the historical snapshot.
|
|
322
|
+
* 4. Deduplicates buffered events against the fetch result.
|
|
323
|
+
* 5. Flushes remaining buffered events through `subscriber.next()`.
|
|
324
|
+
* 6. Resumes live: pipes stream events directly to `subscriber.next()`.
|
|
325
|
+
*/
|
|
326
|
+
declare class LiveQuery<T = Record<string, unknown>> {
|
|
327
|
+
private _stream;
|
|
328
|
+
private _subscriber;
|
|
329
|
+
private _buffer;
|
|
330
|
+
private _buffering;
|
|
331
|
+
private _unsubStream;
|
|
332
|
+
private _closed;
|
|
333
|
+
constructor(stream: StreamController<T>, fetchFn: () => Promise<Result<T[]>>, subscriber: StreamSubscriber<T>, _filters: QueryFilter[]);
|
|
334
|
+
private _runBackfill;
|
|
335
|
+
/** Close the live query and the underlying stream. */
|
|
336
|
+
close(): void;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
interface QueryState {
|
|
340
|
+
table: string;
|
|
341
|
+
columns: string[];
|
|
342
|
+
aggregations: Aggregation[];
|
|
343
|
+
filters: QueryFilter[];
|
|
344
|
+
groupBy: string[];
|
|
345
|
+
orderBy: OrderClause[];
|
|
346
|
+
limit?: number;
|
|
347
|
+
timeRange?: TimeRange;
|
|
348
|
+
cacheTTL?: number;
|
|
349
|
+
}
|
|
350
|
+
type CreateStreamFn$1<Row> = (table: string, opts?: StreamOptions) => StreamController<Row>;
|
|
351
|
+
/**
|
|
352
|
+
* Immutable, PromiseLike query builder.
|
|
353
|
+
* Every chain method returns a new instance. `await builder` auto-executes `.fetch()`.
|
|
354
|
+
*/
|
|
355
|
+
declare class QueryBuilder<Row = Record<string, unknown>> implements PromiseLike<Result<Row[]>> {
|
|
356
|
+
/** @internal */
|
|
357
|
+
private readonly _state;
|
|
358
|
+
/** @internal */
|
|
359
|
+
private readonly _ctx;
|
|
360
|
+
/** @internal */
|
|
361
|
+
private readonly _createStream;
|
|
362
|
+
constructor(ctx: HttpContext, state: QueryState, createStream: CreateStreamFn$1<Row>);
|
|
363
|
+
select(...columns: string[]): QueryBuilder<Row>;
|
|
364
|
+
where(column: string, op: FilterOp, value: unknown): QueryBuilder<Row>;
|
|
365
|
+
count(column?: string, alias?: string): QueryBuilder<Row>;
|
|
366
|
+
sum(column: string, alias?: string): QueryBuilder<Row>;
|
|
367
|
+
avg(column: string, alias?: string): QueryBuilder<Row>;
|
|
368
|
+
min(column: string, alias?: string): QueryBuilder<Row>;
|
|
369
|
+
max(column: string, alias?: string): QueryBuilder<Row>;
|
|
370
|
+
countDistinct(column: string, alias?: string): QueryBuilder<Row>;
|
|
371
|
+
aggregate(fn: string, column: string, alias: string): QueryBuilder<Row>;
|
|
372
|
+
groupBy(...columns: string[]): QueryBuilder<Row>;
|
|
373
|
+
orderBy(column: string, dir?: "asc" | "desc"): QueryBuilder<Row>;
|
|
374
|
+
limit(n: number): QueryBuilder<Row>;
|
|
375
|
+
timeRange(column: string, since: string, until?: string): QueryBuilder<Row>;
|
|
376
|
+
cacheTTL(seconds: number): QueryBuilder<Row>;
|
|
377
|
+
/** Default row limit when none is specified. Matches backend DefaultMaxRows. */
|
|
378
|
+
static readonly DEFAULT_LIMIT = 1000;
|
|
379
|
+
fetch(opts?: FetchOptions): Promise<Result<Row[]>>;
|
|
380
|
+
stream(opts?: StreamOptions): StreamController<Row>;
|
|
381
|
+
/**
|
|
382
|
+
* Start a live query: fetches historical data, then streams live updates.
|
|
383
|
+
*
|
|
384
|
+
* The subscriber's `initial()` is called once with the fetch result, then
|
|
385
|
+
* `next()` fires for each live event. Events that arrived during the fetch
|
|
386
|
+
* are deduplicated and flushed automatically.
|
|
387
|
+
*
|
|
388
|
+
* Returns a LiveQuery handle with a `.close()` method.
|
|
389
|
+
*/
|
|
390
|
+
liveQuery(subscriber: StreamSubscriber<Row>, opts?: StreamOptions): LiveQuery<Row>;
|
|
391
|
+
then<TResult1 = Result<Row[]>, TResult2 = never>(onfulfilled?: ((value: Result<Row[]>) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;
|
|
392
|
+
private _clone;
|
|
393
|
+
private _addAgg;
|
|
394
|
+
private _buildAST;
|
|
395
|
+
private _fetchNext;
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
type CreateStreamFn<Row> = (table: string, opts?: StreamOptions) => StreamController<Row>;
|
|
399
|
+
/**
|
|
400
|
+
* Reference to a table. NOT thenable — safe to pass around without triggering requests.
|
|
401
|
+
* Use `.fetch()`, `.select()`, `.insert()`, `.schema()`, or `.stream()` to act on it.
|
|
402
|
+
*/
|
|
403
|
+
declare class TableRef<Row = Record<string, unknown>> {
|
|
404
|
+
private readonly _ctx;
|
|
405
|
+
private readonly _table;
|
|
406
|
+
private readonly _createStream;
|
|
407
|
+
constructor(ctx: HttpContext, table: string, createStream: CreateStreamFn<Row>);
|
|
408
|
+
/** SELECT * shortcut — fetches rows with optional pagination. */
|
|
409
|
+
fetch(opts?: FetchOptions): Promise<Result<Row[]>>;
|
|
410
|
+
/** Start building a typed query. Returns an immutable, PromiseLike QueryBuilder. */
|
|
411
|
+
select(...columns: string[]): QueryBuilder<Row>;
|
|
412
|
+
/** Insert one or more rows into this table. */
|
|
413
|
+
insert(data: Partial<Row> | Partial<Row>[], opts?: {
|
|
414
|
+
signal?: AbortSignal;
|
|
415
|
+
}): Promise<Result<InsertResult>>;
|
|
416
|
+
/** Fetch the schema for this table. */
|
|
417
|
+
schema(opts?: {
|
|
418
|
+
signal?: AbortSignal;
|
|
419
|
+
}): Promise<Result<TableSchema>>;
|
|
420
|
+
/** Subscribe to live events for this table. */
|
|
421
|
+
stream(opts?: StreamOptions): StreamController<Row>;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
type TableName<DB> = DB extends Database ? Extract<keyof DB, string> : string;
|
|
425
|
+
type RowType<DB, T extends string> = DB extends Database ? T extends keyof DB ? DB[T] : Record<string, unknown> : Record<string, unknown>;
|
|
426
|
+
declare class WaveHouseClient<DB extends Database = Database> {
|
|
427
|
+
/** @internal */
|
|
428
|
+
readonly _ctx: HttpContext;
|
|
429
|
+
/** Schema introspection namespace. */
|
|
430
|
+
readonly schema: SchemaNamespace;
|
|
431
|
+
/** Access control policy namespace (admin). */
|
|
432
|
+
readonly policy: PolicyNamespace;
|
|
433
|
+
/** Dead Letter Queue namespace. */
|
|
434
|
+
readonly dlq: DLQNamespace;
|
|
435
|
+
/** System health/readiness namespace. */
|
|
436
|
+
readonly sys: SysNamespace;
|
|
437
|
+
/** Named query pipes admin namespace. */
|
|
438
|
+
readonly pipes: PipesNamespace;
|
|
439
|
+
constructor(config: ClientConfig<DB>);
|
|
440
|
+
/** Get a table reference for building queries, inserts, and streams. */
|
|
441
|
+
from<T extends TableName<DB>>(table: T): TableRef<RowType<DB, T>>;
|
|
442
|
+
/** Get a reference to a named query pipe. PromiseLike — `await` it to execute. */
|
|
443
|
+
pipe<Row = Record<string, unknown>>(name: string, params?: Record<string, unknown>): PipeRef<Row>;
|
|
444
|
+
/**
|
|
445
|
+
* Execute a raw SQL query against ClickHouse. Requires the admin role (the
|
|
446
|
+
* configured `admin_role`, `"admin"` by default; there is no separate
|
|
447
|
+
* `service` role). The endpoint proxies straight to ClickHouse's HTTP
|
|
448
|
+
* interface so any ClickHouse-accepted SQL works; positional `?` param
|
|
449
|
+
* binding is NOT supported — inline literals or use the structured query
|
|
450
|
+
* builder for safe binding. See sql.ts for details.
|
|
451
|
+
*/
|
|
452
|
+
sql<Row = Record<string, unknown>>(query: string, opts?: {
|
|
453
|
+
signal?: AbortSignal;
|
|
454
|
+
}): Promise<Result<Row[]>>;
|
|
455
|
+
/** @internal Create a stream for the given table. */
|
|
456
|
+
private _createStream;
|
|
457
|
+
}
|
|
458
|
+
/** Create a new WaveHouse client instance. */
|
|
459
|
+
declare function createClient<DB extends Database = Database>(config: ClientConfig<DB>): WaveHouseClient<DB>;
|
|
460
|
+
|
|
461
|
+
export { type Aggregation, type ClientConfig, type ClientOptions, type Column, DLQNamespace, type DLQStats, type Database, type FetchOptions, type FilterOp, type InsertResult, LiveQuery, type OrderClause, type ParamDef, type Pipe, PipeRef, PipesNamespace, type Policy, type PolicyFilter, PolicyNamespace, QueryBuilder, type QueryFilter, type Result, type RolePermissions, SchemaNamespace, type Schemas, StreamController, type StreamEvent, type StreamOptions, type StreamStatus, type StreamSubscriber, type StructuredQuery, SysNamespace, type TablePolicy, TableRef, type TableSchema, type TimeRange, type ValidationResult, WaveHouseClient, type WaveHouseError, createClient };
|