@thunderduck-io/client 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,260 @@
1
+ /** A value as it appears in a result cell. */
2
+ type Cell = null | boolean | number | string | Cell[] | {
3
+ [key: string]: Cell;
4
+ };
5
+ type Row = Cell[];
6
+ /**
7
+ * `queued`/`running` are in flight; `success`/`error`/`cancelled` are terminal.
8
+ * The union keeps a string arm because the API may add a status before this
9
+ * package is updated, and callers should not crash on it.
10
+ */
11
+ type ExecutionStatus = "queued" | "running" | "success" | "error" | "cancelled" | (string & {});
12
+ interface Execution {
13
+ /** Same value as `submit()` returned; the id `/executions/{id}` takes. */
14
+ id: string;
15
+ status: ExecutionStatus;
16
+ query: string;
17
+ errorMessage: string | null;
18
+ /** Where the result Parquet lives (S3 URI), when the run stored one. */
19
+ resultLocation: string | null;
20
+ resultRowCount: number | null;
21
+ startedAt: string | null;
22
+ finishedAt: string | null;
23
+ executionTimeMs: number | null;
24
+ queryTimeMs: number | null;
25
+ totalRuntimeMs: number | null;
26
+ peakMemoryBytes: number | null;
27
+ source: string | null;
28
+ /** The untouched response, for fields this package does not model yet. */
29
+ raw: Record<string, unknown>;
30
+ }
31
+ /** What `POST /queries` returns. */
32
+ interface QueryJob {
33
+ id: string;
34
+ /** `eks`, `ecs`, or `cache` (served from a prior result; no new run). */
35
+ backend: string;
36
+ namespace: string | null;
37
+ jobName: string | null;
38
+ raw: Record<string, unknown>;
39
+ }
40
+ interface ResultPage {
41
+ id: string;
42
+ columns: string[];
43
+ /** Parallel to `columns`; empty when the server did not send types. */
44
+ columnTypes: string[];
45
+ rows: Row[];
46
+ /** Rows in this page. */
47
+ rowCount: number;
48
+ /** Rows in the whole stored result. */
49
+ total: number;
50
+ limit: number;
51
+ offset: number;
52
+ }
53
+ /** One page produced by `iterate()`. */
54
+ interface ResultBatch {
55
+ columns: string[];
56
+ columnTypes: string[];
57
+ rows: Row[];
58
+ total: number;
59
+ offset: number;
60
+ }
61
+ /** A fully buffered query: `query()` walks every page for this. */
62
+ interface QueryResult extends ResultBatch {
63
+ id: string;
64
+ execution: Execution;
65
+ }
66
+ interface CatalogColumn {
67
+ name: string;
68
+ type: string;
69
+ /** Present only when someone annotated the column's meaning. */
70
+ semantics: Record<string, unknown> | null;
71
+ }
72
+ interface CatalogTable {
73
+ name: string;
74
+ kind: "table" | "view" | string;
75
+ columns: CatalogColumn[];
76
+ }
77
+ interface CatalogNamespace {
78
+ name: string;
79
+ tables: CatalogTable[];
80
+ }
81
+ interface CatalogTree {
82
+ name: string;
83
+ /** Integration type, e.g. `nessie_iceberg`, `postgresql`, `s3`. */
84
+ type: string | null;
85
+ /** Two-level catalogs (catalog.table) put tables here. */
86
+ tables: CatalogTable[] | null;
87
+ /** Three-level catalogs (catalog.schema.table) put namespaces here. */
88
+ namespaces: CatalogNamespace[] | null;
89
+ error: string | null;
90
+ }
91
+ interface CatalogSchema {
92
+ catalogs: CatalogTree[];
93
+ error: string | null;
94
+ }
95
+ interface DownloadUrl {
96
+ url: string;
97
+ /** Seconds until the presigned URL stops working. */
98
+ expiresIn: number;
99
+ }
100
+
101
+ interface ThunderduckOptions {
102
+ /**
103
+ * API token from the console (Settings → API tokens). Mutually exclusive
104
+ * with `getToken`.
105
+ */
106
+ token?: string;
107
+ /**
108
+ * Supplies the bearer for each request, for tokens that rotate or expire.
109
+ * Called with `true` after a 401 so it can force a refresh; returning the
110
+ * same rejected token simply produces the auth error.
111
+ */
112
+ getToken?: (forceRefresh?: boolean) => string | Promise<string>;
113
+ /** Origin of the API. Default `https://api.thunderduck.ai`. */
114
+ baseUrl?: string;
115
+ /** Injectable `fetch`, for tests and non-Node runtimes. */
116
+ fetch?: typeof fetch;
117
+ /** Poll cadence while a query runs. Default 1000 ms. */
118
+ pollIntervalMs?: number;
119
+ /** How long `awaitExecution()` waits before giving up. Default 300 s. */
120
+ timeoutMs?: number;
121
+ /** Per-HTTP-request ceiling. Default 30 s. */
122
+ requestTimeoutMs?: number;
123
+ /** Redirects followed, same-origin only. Default 3. */
124
+ maxRedirects?: number;
125
+ }
126
+ interface RequestOptions {
127
+ signal?: AbortSignal;
128
+ }
129
+ interface QueryOptions extends RequestOptions {
130
+ /** Overwrite the client's default poll cadence for this call. */
131
+ pollIntervalMs?: number;
132
+ /** Overwrite the client's default wait ceiling for this call. */
133
+ timeoutMs?: number;
134
+ /** Rows per request when walking the result. Default 1000. */
135
+ pageSize?: number;
136
+ /** Stop after this many rows. Default: the whole result. */
137
+ maxRows?: number;
138
+ /** Ask the API to skip a cached result. */
139
+ forceRefresh?: boolean;
140
+ }
141
+ /**
142
+ * Client for the Thunderduck REST API.
143
+ *
144
+ * ```ts
145
+ * const td = new Thunderduck({ token: process.env.THUNDERDUCK_TOKEN! });
146
+ * const { columns, rows } = await td.query("select * from nessie.orders limit 10");
147
+ * ```
148
+ */
149
+ declare class Thunderduck {
150
+ readonly baseUrl: string;
151
+ private readonly token?;
152
+ private readonly getToken?;
153
+ private readonly fetchImpl;
154
+ private readonly pollIntervalMs;
155
+ private readonly timeoutMs;
156
+ private readonly requestTimeoutMs;
157
+ private readonly maxRedirects;
158
+ constructor(options?: ThunderduckOptions);
159
+ /** Submit SQL and return its execution id, without waiting for it. */
160
+ submit(sql: string, options?: RequestOptions & {
161
+ forceRefresh?: boolean;
162
+ }): Promise<QueryJob>;
163
+ /** One execution by id. Throws when it does not exist. */
164
+ execution(id: string, options?: RequestOptions): Promise<Execution>;
165
+ /**
166
+ * Poll until the run is terminal. Returns only `success`; throws
167
+ * `ThunderduckQueryError` on `error`, `ThunderduckCancelledError` on
168
+ * `cancelled`, and `ThunderduckTimeoutError` when the deadline passes.
169
+ *
170
+ * A 404 while polling means "not visible yet" — the row is inserted at submit
171
+ * time, but a poll can still race it — so it keeps polling rather than
172
+ * failing.
173
+ */
174
+ awaitExecution(id: string, options?: QueryOptions): Promise<Execution>;
175
+ /** A fully buffered query: submit, wait, then walk every result page. */
176
+ query(sql: string, options?: QueryOptions): Promise<QueryResult>;
177
+ /**
178
+ * Submit, wait, then yield result pages — for results too large to buffer.
179
+ * A statement with no stored result (an INSERT, say) yields nothing.
180
+ */
181
+ iterate(sql: string, options?: QueryOptions): AsyncGenerator<ResultBatch>;
182
+ /** One page of an execution's stored result, or null when it stored none. */
183
+ resultPage(id: string, options?: RequestOptions & {
184
+ limit?: number;
185
+ offset?: number;
186
+ }): Promise<ResultPage | null>;
187
+ /**
188
+ * Best-effort cancel: an unknown or already-finished run is not an error.
189
+ * A rejected token still is — swallowing it would make a stop button look
190
+ * like it worked while hiding a dead credential.
191
+ */
192
+ cancel(id: string, options?: RequestOptions): Promise<void>;
193
+ /** Catalogs, namespaces, tables and columns this token may see. */
194
+ catalogSchema(options?: RequestOptions): Promise<CatalogSchema>;
195
+ /** Mint a short-lived presigned URL for the run's stored result. */
196
+ downloadUrl(id: string, options?: RequestOptions): Promise<DownloadUrl>;
197
+ /**
198
+ * The stored result, as the presigned GET response. Never sends the bearer:
199
+ * the URL is self-authenticating, and a client that attached our token to it
200
+ * would hand the token to whatever host the URL names.
201
+ */
202
+ download(id: string, options?: RequestOptions): Promise<Response>;
203
+ private batches;
204
+ private executionOrNull;
205
+ /**
206
+ * One logical request: token, redirects (same origin only), one retry after a
207
+ * 401 when a token provider can refresh.
208
+ */
209
+ private send;
210
+ private followRedirects;
211
+ private fetchText;
212
+ private currentToken;
213
+ private parse;
214
+ private detailOf;
215
+ /** Turn an unexpected status into the most specific error this client has. */
216
+ private fail;
217
+ }
218
+
219
+ /**
220
+ * Error hierarchy.
221
+ *
222
+ * Every error the client raises on purpose is a `ThunderduckError`, so callers
223
+ * can catch one type and still branch on `status`. Server-provided text is in
224
+ * `detail`; the transport's own error is in `cause`.
225
+ */
226
+ declare class ThunderduckError extends Error {
227
+ /** HTTP status, when the error came from a response. */
228
+ readonly status?: number;
229
+ /** The server's `detail` (or raw body) when there was one. */
230
+ readonly detail?: string;
231
+ constructor(message: string, options?: {
232
+ status?: number;
233
+ detail?: string;
234
+ cause?: unknown;
235
+ });
236
+ }
237
+ /** The token missing, expired, rejected or lacking access (HTTP 401/403). */
238
+ declare class ThunderduckAuthError extends ThunderduckError {
239
+ }
240
+ /**
241
+ * The identity authenticated but has no usable Thunderduck account (not signed
242
+ * in to the console yet, or suspended). Sending them to the console once fixes
243
+ * the first case; nothing the client can do fixes the second.
244
+ */
245
+ declare class ThunderduckNoAccessError extends ThunderduckError {
246
+ }
247
+ /** The run finished as `error` — `detail` is the engine's message. */
248
+ declare class ThunderduckQueryError extends ThunderduckError {
249
+ }
250
+ /** The run was cancelled before it finished. */
251
+ declare class ThunderduckCancelledError extends ThunderduckError {
252
+ }
253
+ /** Polling gave up before the run reached a terminal status. */
254
+ declare class ThunderduckTimeoutError extends ThunderduckError {
255
+ }
256
+ /** The run succeeded but its stored result has aged out (HTTP 409). Re-run. */
257
+ declare class ThunderduckResultExpiredError extends ThunderduckError {
258
+ }
259
+
260
+ export { type CatalogColumn, type CatalogNamespace, type CatalogSchema, type CatalogTable, type CatalogTree, type Cell, type DownloadUrl, type Execution, type ExecutionStatus, type QueryJob, type QueryOptions, type QueryResult, type RequestOptions, type ResultBatch, type ResultPage, type Row, Thunderduck, ThunderduckAuthError, ThunderduckCancelledError, ThunderduckError, ThunderduckNoAccessError, type ThunderduckOptions, ThunderduckQueryError, ThunderduckResultExpiredError, ThunderduckTimeoutError };
@@ -0,0 +1,260 @@
1
+ /** A value as it appears in a result cell. */
2
+ type Cell = null | boolean | number | string | Cell[] | {
3
+ [key: string]: Cell;
4
+ };
5
+ type Row = Cell[];
6
+ /**
7
+ * `queued`/`running` are in flight; `success`/`error`/`cancelled` are terminal.
8
+ * The union keeps a string arm because the API may add a status before this
9
+ * package is updated, and callers should not crash on it.
10
+ */
11
+ type ExecutionStatus = "queued" | "running" | "success" | "error" | "cancelled" | (string & {});
12
+ interface Execution {
13
+ /** Same value as `submit()` returned; the id `/executions/{id}` takes. */
14
+ id: string;
15
+ status: ExecutionStatus;
16
+ query: string;
17
+ errorMessage: string | null;
18
+ /** Where the result Parquet lives (S3 URI), when the run stored one. */
19
+ resultLocation: string | null;
20
+ resultRowCount: number | null;
21
+ startedAt: string | null;
22
+ finishedAt: string | null;
23
+ executionTimeMs: number | null;
24
+ queryTimeMs: number | null;
25
+ totalRuntimeMs: number | null;
26
+ peakMemoryBytes: number | null;
27
+ source: string | null;
28
+ /** The untouched response, for fields this package does not model yet. */
29
+ raw: Record<string, unknown>;
30
+ }
31
+ /** What `POST /queries` returns. */
32
+ interface QueryJob {
33
+ id: string;
34
+ /** `eks`, `ecs`, or `cache` (served from a prior result; no new run). */
35
+ backend: string;
36
+ namespace: string | null;
37
+ jobName: string | null;
38
+ raw: Record<string, unknown>;
39
+ }
40
+ interface ResultPage {
41
+ id: string;
42
+ columns: string[];
43
+ /** Parallel to `columns`; empty when the server did not send types. */
44
+ columnTypes: string[];
45
+ rows: Row[];
46
+ /** Rows in this page. */
47
+ rowCount: number;
48
+ /** Rows in the whole stored result. */
49
+ total: number;
50
+ limit: number;
51
+ offset: number;
52
+ }
53
+ /** One page produced by `iterate()`. */
54
+ interface ResultBatch {
55
+ columns: string[];
56
+ columnTypes: string[];
57
+ rows: Row[];
58
+ total: number;
59
+ offset: number;
60
+ }
61
+ /** A fully buffered query: `query()` walks every page for this. */
62
+ interface QueryResult extends ResultBatch {
63
+ id: string;
64
+ execution: Execution;
65
+ }
66
+ interface CatalogColumn {
67
+ name: string;
68
+ type: string;
69
+ /** Present only when someone annotated the column's meaning. */
70
+ semantics: Record<string, unknown> | null;
71
+ }
72
+ interface CatalogTable {
73
+ name: string;
74
+ kind: "table" | "view" | string;
75
+ columns: CatalogColumn[];
76
+ }
77
+ interface CatalogNamespace {
78
+ name: string;
79
+ tables: CatalogTable[];
80
+ }
81
+ interface CatalogTree {
82
+ name: string;
83
+ /** Integration type, e.g. `nessie_iceberg`, `postgresql`, `s3`. */
84
+ type: string | null;
85
+ /** Two-level catalogs (catalog.table) put tables here. */
86
+ tables: CatalogTable[] | null;
87
+ /** Three-level catalogs (catalog.schema.table) put namespaces here. */
88
+ namespaces: CatalogNamespace[] | null;
89
+ error: string | null;
90
+ }
91
+ interface CatalogSchema {
92
+ catalogs: CatalogTree[];
93
+ error: string | null;
94
+ }
95
+ interface DownloadUrl {
96
+ url: string;
97
+ /** Seconds until the presigned URL stops working. */
98
+ expiresIn: number;
99
+ }
100
+
101
+ interface ThunderduckOptions {
102
+ /**
103
+ * API token from the console (Settings → API tokens). Mutually exclusive
104
+ * with `getToken`.
105
+ */
106
+ token?: string;
107
+ /**
108
+ * Supplies the bearer for each request, for tokens that rotate or expire.
109
+ * Called with `true` after a 401 so it can force a refresh; returning the
110
+ * same rejected token simply produces the auth error.
111
+ */
112
+ getToken?: (forceRefresh?: boolean) => string | Promise<string>;
113
+ /** Origin of the API. Default `https://api.thunderduck.ai`. */
114
+ baseUrl?: string;
115
+ /** Injectable `fetch`, for tests and non-Node runtimes. */
116
+ fetch?: typeof fetch;
117
+ /** Poll cadence while a query runs. Default 1000 ms. */
118
+ pollIntervalMs?: number;
119
+ /** How long `awaitExecution()` waits before giving up. Default 300 s. */
120
+ timeoutMs?: number;
121
+ /** Per-HTTP-request ceiling. Default 30 s. */
122
+ requestTimeoutMs?: number;
123
+ /** Redirects followed, same-origin only. Default 3. */
124
+ maxRedirects?: number;
125
+ }
126
+ interface RequestOptions {
127
+ signal?: AbortSignal;
128
+ }
129
+ interface QueryOptions extends RequestOptions {
130
+ /** Overwrite the client's default poll cadence for this call. */
131
+ pollIntervalMs?: number;
132
+ /** Overwrite the client's default wait ceiling for this call. */
133
+ timeoutMs?: number;
134
+ /** Rows per request when walking the result. Default 1000. */
135
+ pageSize?: number;
136
+ /** Stop after this many rows. Default: the whole result. */
137
+ maxRows?: number;
138
+ /** Ask the API to skip a cached result. */
139
+ forceRefresh?: boolean;
140
+ }
141
+ /**
142
+ * Client for the Thunderduck REST API.
143
+ *
144
+ * ```ts
145
+ * const td = new Thunderduck({ token: process.env.THUNDERDUCK_TOKEN! });
146
+ * const { columns, rows } = await td.query("select * from nessie.orders limit 10");
147
+ * ```
148
+ */
149
+ declare class Thunderduck {
150
+ readonly baseUrl: string;
151
+ private readonly token?;
152
+ private readonly getToken?;
153
+ private readonly fetchImpl;
154
+ private readonly pollIntervalMs;
155
+ private readonly timeoutMs;
156
+ private readonly requestTimeoutMs;
157
+ private readonly maxRedirects;
158
+ constructor(options?: ThunderduckOptions);
159
+ /** Submit SQL and return its execution id, without waiting for it. */
160
+ submit(sql: string, options?: RequestOptions & {
161
+ forceRefresh?: boolean;
162
+ }): Promise<QueryJob>;
163
+ /** One execution by id. Throws when it does not exist. */
164
+ execution(id: string, options?: RequestOptions): Promise<Execution>;
165
+ /**
166
+ * Poll until the run is terminal. Returns only `success`; throws
167
+ * `ThunderduckQueryError` on `error`, `ThunderduckCancelledError` on
168
+ * `cancelled`, and `ThunderduckTimeoutError` when the deadline passes.
169
+ *
170
+ * A 404 while polling means "not visible yet" — the row is inserted at submit
171
+ * time, but a poll can still race it — so it keeps polling rather than
172
+ * failing.
173
+ */
174
+ awaitExecution(id: string, options?: QueryOptions): Promise<Execution>;
175
+ /** A fully buffered query: submit, wait, then walk every result page. */
176
+ query(sql: string, options?: QueryOptions): Promise<QueryResult>;
177
+ /**
178
+ * Submit, wait, then yield result pages — for results too large to buffer.
179
+ * A statement with no stored result (an INSERT, say) yields nothing.
180
+ */
181
+ iterate(sql: string, options?: QueryOptions): AsyncGenerator<ResultBatch>;
182
+ /** One page of an execution's stored result, or null when it stored none. */
183
+ resultPage(id: string, options?: RequestOptions & {
184
+ limit?: number;
185
+ offset?: number;
186
+ }): Promise<ResultPage | null>;
187
+ /**
188
+ * Best-effort cancel: an unknown or already-finished run is not an error.
189
+ * A rejected token still is — swallowing it would make a stop button look
190
+ * like it worked while hiding a dead credential.
191
+ */
192
+ cancel(id: string, options?: RequestOptions): Promise<void>;
193
+ /** Catalogs, namespaces, tables and columns this token may see. */
194
+ catalogSchema(options?: RequestOptions): Promise<CatalogSchema>;
195
+ /** Mint a short-lived presigned URL for the run's stored result. */
196
+ downloadUrl(id: string, options?: RequestOptions): Promise<DownloadUrl>;
197
+ /**
198
+ * The stored result, as the presigned GET response. Never sends the bearer:
199
+ * the URL is self-authenticating, and a client that attached our token to it
200
+ * would hand the token to whatever host the URL names.
201
+ */
202
+ download(id: string, options?: RequestOptions): Promise<Response>;
203
+ private batches;
204
+ private executionOrNull;
205
+ /**
206
+ * One logical request: token, redirects (same origin only), one retry after a
207
+ * 401 when a token provider can refresh.
208
+ */
209
+ private send;
210
+ private followRedirects;
211
+ private fetchText;
212
+ private currentToken;
213
+ private parse;
214
+ private detailOf;
215
+ /** Turn an unexpected status into the most specific error this client has. */
216
+ private fail;
217
+ }
218
+
219
+ /**
220
+ * Error hierarchy.
221
+ *
222
+ * Every error the client raises on purpose is a `ThunderduckError`, so callers
223
+ * can catch one type and still branch on `status`. Server-provided text is in
224
+ * `detail`; the transport's own error is in `cause`.
225
+ */
226
+ declare class ThunderduckError extends Error {
227
+ /** HTTP status, when the error came from a response. */
228
+ readonly status?: number;
229
+ /** The server's `detail` (or raw body) when there was one. */
230
+ readonly detail?: string;
231
+ constructor(message: string, options?: {
232
+ status?: number;
233
+ detail?: string;
234
+ cause?: unknown;
235
+ });
236
+ }
237
+ /** The token missing, expired, rejected or lacking access (HTTP 401/403). */
238
+ declare class ThunderduckAuthError extends ThunderduckError {
239
+ }
240
+ /**
241
+ * The identity authenticated but has no usable Thunderduck account (not signed
242
+ * in to the console yet, or suspended). Sending them to the console once fixes
243
+ * the first case; nothing the client can do fixes the second.
244
+ */
245
+ declare class ThunderduckNoAccessError extends ThunderduckError {
246
+ }
247
+ /** The run finished as `error` — `detail` is the engine's message. */
248
+ declare class ThunderduckQueryError extends ThunderduckError {
249
+ }
250
+ /** The run was cancelled before it finished. */
251
+ declare class ThunderduckCancelledError extends ThunderduckError {
252
+ }
253
+ /** Polling gave up before the run reached a terminal status. */
254
+ declare class ThunderduckTimeoutError extends ThunderduckError {
255
+ }
256
+ /** The run succeeded but its stored result has aged out (HTTP 409). Re-run. */
257
+ declare class ThunderduckResultExpiredError extends ThunderduckError {
258
+ }
259
+
260
+ export { type CatalogColumn, type CatalogNamespace, type CatalogSchema, type CatalogTable, type CatalogTree, type Cell, type DownloadUrl, type Execution, type ExecutionStatus, type QueryJob, type QueryOptions, type QueryResult, type RequestOptions, type ResultBatch, type ResultPage, type Row, Thunderduck, ThunderduckAuthError, ThunderduckCancelledError, ThunderduckError, ThunderduckNoAccessError, type ThunderduckOptions, ThunderduckQueryError, ThunderduckResultExpiredError, ThunderduckTimeoutError };