get-db9 0.4.1 → 0.6.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.
@@ -1,429 +0,0 @@
1
- type FetchFn = typeof globalThis.fetch;
2
- type BodyInit = string | Blob | ArrayBuffer | FormData | URLSearchParams | ReadableStream<Uint8Array>;
3
- interface HttpClientOptions {
4
- baseUrl: string;
5
- fetch?: FetchFn;
6
- headers?: Record<string, string>;
7
- }
8
- interface HttpClient {
9
- get<T>(path: string, params?: Record<string, string | undefined>): Promise<T>;
10
- post<T>(path: string, body?: unknown): Promise<T>;
11
- put<T>(path: string, body?: unknown): Promise<T>;
12
- del<T>(path: string): Promise<T>;
13
- getRaw(path: string, params?: Record<string, string | undefined>): Promise<Response>;
14
- putRaw(path: string, body: BodyInit, headers?: Record<string, string>): Promise<Response>;
15
- }
16
-
17
- /** Credential fields stored in `~/.db9/credentials` (TOML). */
18
- interface Credentials {
19
- token: string;
20
- is_anonymous?: boolean;
21
- anonymous_id?: string;
22
- anonymous_secret?: string;
23
- }
24
- /** Async credential persistence abstraction. */
25
- interface CredentialStore {
26
- load(): Promise<Credentials | null>;
27
- save(credentials: Credentials): Promise<void>;
28
- clear(): Promise<void>;
29
- }
30
- declare class FileCredentialStore implements CredentialStore {
31
- private readonly customPath;
32
- /**
33
- * @param path — Override the credential file location.
34
- * Defaults to `~/.db9/credentials` (resolved lazily).
35
- */
36
- constructor(path?: string);
37
- /** Resolve the credential file path (lazy to avoid top-level `os` import). */
38
- private resolvePath;
39
- load(): Promise<Credentials | null>;
40
- save(credentials: Credentials): Promise<void>;
41
- clear(): Promise<void>;
42
- }
43
- declare class MemoryCredentialStore implements CredentialStore {
44
- private credentials;
45
- load(): Promise<Credentials | null>;
46
- save(credentials: Credentials): Promise<void>;
47
- clear(): Promise<void>;
48
- }
49
- /** Returns a FileCredentialStore with the default path (`~/.db9/credentials`). */
50
- declare function defaultCredentialStore(): CredentialStore;
51
-
52
- /** A file or directory entry from fs9 readdir/stat API */
53
- interface Fs9FileEntry {
54
- path: string;
55
- size: number;
56
- file_type: 'regular' | 'directory' | 'symlink';
57
- mode: number;
58
- uid: number;
59
- gid: number;
60
- atime: number;
61
- mtime: number;
62
- ctime: number;
63
- etag: string;
64
- symlink_target?: string;
65
- }
66
- /** Options for fs9 list operation */
67
- interface Fs9ListOptions {
68
- recursive?: boolean;
69
- }
70
-
71
- interface Endpoint {
72
- host: string;
73
- port: number;
74
- type: string;
75
- region?: string;
76
- priority: number;
77
- description?: string;
78
- enabled: boolean;
79
- }
80
- interface MessageResponse {
81
- message: string;
82
- }
83
- interface HealthResponse {
84
- status: string;
85
- pd_healthy: boolean;
86
- }
87
- interface ColumnInfo {
88
- name: string;
89
- type: string;
90
- }
91
- interface SqlResult {
92
- columns: ColumnInfo[];
93
- rows: unknown[][];
94
- row_count: number;
95
- command: string;
96
- error?: string;
97
- }
98
- interface CreateTenantRequest {
99
- admin_user?: string;
100
- admin_password?: string;
101
- }
102
- interface TenantConnectRequest {
103
- admin_user: string;
104
- admin_password: string;
105
- }
106
- interface TenantUpdateRequest {
107
- notes?: string;
108
- tags?: string[];
109
- }
110
- interface AdminCreateUserRequest {
111
- username: string;
112
- password?: string;
113
- superuser?: boolean;
114
- }
115
- interface SqlQueryRequest {
116
- sql: string;
117
- }
118
- interface ListTenantsParams {
119
- page?: number;
120
- size?: number;
121
- state?: string;
122
- q?: string;
123
- cursor?: string;
124
- tag?: string;
125
- }
126
- interface BatchCreateRequest {
127
- count: number;
128
- admin_user?: string;
129
- admin_password?: string;
130
- }
131
- interface BatchDeleteRequest {
132
- ids: string[];
133
- }
134
- interface BatchUpdateRequest {
135
- ids: string[];
136
- notes?: string;
137
- tags?: string[];
138
- }
139
- interface AuditLogParams {
140
- tenant_id?: string;
141
- operation_type?: string;
142
- resource_type?: string;
143
- success?: boolean;
144
- limit?: number;
145
- offset?: number;
146
- }
147
- interface TenantResponse {
148
- id: string;
149
- state: string;
150
- created_at?: string;
151
- created_by?: string;
152
- notes?: string;
153
- tags?: string[];
154
- updated_at?: string;
155
- state_reason?: string;
156
- endpoints?: Endpoint[];
157
- }
158
- interface TenantListResponse {
159
- items: TenantResponse[];
160
- total: number;
161
- page: number;
162
- size: number;
163
- next_cursor?: string;
164
- }
165
- interface CreateTenantResponse {
166
- id: string;
167
- admin_user: string;
168
- admin_password: string;
169
- connection_string: string;
170
- created_at: string;
171
- }
172
- interface TenantConnectResponse {
173
- session_id: string;
174
- expires_at: string;
175
- }
176
- interface BatchCreateResponse {
177
- created: CreateTenantResponse[];
178
- failed: BatchItemError[];
179
- total_requested: number;
180
- total_created: number;
181
- }
182
- interface BatchDeleteResponse {
183
- deleted: string[];
184
- failed: BatchItemError[];
185
- }
186
- interface BatchUpdateResponse {
187
- updated: string[];
188
- failed: BatchItemError[];
189
- }
190
- interface BatchItemError {
191
- id: string;
192
- error: string;
193
- }
194
- interface UserResponse {
195
- name: string;
196
- is_superuser: boolean;
197
- can_login: boolean;
198
- can_create_db: boolean;
199
- can_create_role: boolean;
200
- }
201
- interface UserCreateResponse {
202
- username: string;
203
- password: string;
204
- connection: string;
205
- }
206
- interface PasswordResetResponse {
207
- username: string;
208
- password: string;
209
- }
210
- interface SqlQueryResponse {
211
- success: boolean;
212
- result?: string;
213
- error?: string;
214
- }
215
- interface AuditLogResponse {
216
- id: string;
217
- timestamp: string;
218
- operation_type: string;
219
- resource_type: string;
220
- resource_name: string;
221
- tenant_id?: string;
222
- operator?: string;
223
- success: boolean;
224
- error_message?: string;
225
- extra_metadata?: unknown;
226
- }
227
- interface ObservabilitySummary {
228
- window_seconds: number;
229
- statement_count: number;
230
- txn_commit_count: number;
231
- error_count: number;
232
- qps: number;
233
- tps: number;
234
- latency_avg_ms: number;
235
- latency_p99_ms: number;
236
- active_connections: number;
237
- }
238
- interface QuerySample {
239
- query: string;
240
- sample_count: number;
241
- error_count: number;
242
- latency_avg_ms: number;
243
- latency_p99_ms: number;
244
- latency_max_ms: number;
245
- last_seen_ms_ago: number;
246
- }
247
- interface TenantObservabilityResponse {
248
- summary: ObservabilitySummary;
249
- samples: QuerySample[];
250
- }
251
- interface RegisterRequest {
252
- email: string;
253
- password: string;
254
- }
255
- interface LoginRequest {
256
- email: string;
257
- password: string;
258
- }
259
- interface CreateDatabaseRequest {
260
- name: string;
261
- region?: string;
262
- admin_password?: string;
263
- }
264
- interface SqlExecuteRequest {
265
- query?: string;
266
- file_content?: string;
267
- }
268
- interface DumpRequest {
269
- ddl_only?: boolean;
270
- }
271
- interface MigrationApplyRequest {
272
- name: string;
273
- sql: string;
274
- checksum: string;
275
- }
276
- interface BranchRequest {
277
- name: string;
278
- }
279
- interface ClaimRequest {
280
- email: string;
281
- password: string;
282
- }
283
- interface AnonymousRefreshRequest {
284
- anonymous_id: string;
285
- anonymous_secret: string;
286
- }
287
- interface CreateUserRequest {
288
- username: string;
289
- password: string;
290
- }
291
- interface CustomerResponse {
292
- id: string;
293
- email: string;
294
- created_at: string;
295
- status: string;
296
- }
297
- interface LoginResponse {
298
- token: string;
299
- expires_at: string;
300
- }
301
- interface AnonymousRegisterResponse {
302
- token: string;
303
- expires_at: string;
304
- is_anonymous: boolean;
305
- anonymous_id: string;
306
- anonymous_secret: string;
307
- }
308
- interface AnonymousRefreshResponse {
309
- token: string;
310
- expires_at: string;
311
- }
312
- interface AnonymousSecretResponse {
313
- anonymous_id: string;
314
- anonymous_secret: string;
315
- }
316
- interface ClaimResponse {
317
- id: string;
318
- email: string;
319
- claimed: boolean;
320
- }
321
- interface DatabaseResponse {
322
- id: string;
323
- name: string;
324
- state: string;
325
- region?: string;
326
- endpoints?: Endpoint[];
327
- admin_user?: string;
328
- admin_password?: string;
329
- created_at: string;
330
- connection_string?: string;
331
- }
332
- interface CustomerPasswordResetResponse {
333
- admin_user: string;
334
- admin_password: string;
335
- connection_string: string;
336
- }
337
- interface TokenResponse {
338
- id: string;
339
- name: string;
340
- created_at: string;
341
- expires_at?: string;
342
- }
343
- interface DumpResponse {
344
- sql: string;
345
- object_count: number;
346
- }
347
- interface SchemaResponse {
348
- tables: TableMetadata[];
349
- views: ViewMetadata[];
350
- }
351
- interface TableMetadata {
352
- name: string;
353
- schema: string;
354
- columns: ColumnMetadata[];
355
- }
356
- interface ColumnMetadata {
357
- name: string;
358
- type: string;
359
- nullable: boolean;
360
- default_value?: string;
361
- }
362
- interface ViewMetadata {
363
- name: string;
364
- schema: string;
365
- }
366
- interface MigrationApplyResponse {
367
- status: string;
368
- name: string;
369
- }
370
- interface MigrationMetadata {
371
- name: string;
372
- checksum: string;
373
- applied_at: string;
374
- sql_preview: string;
375
- }
376
- type TenantState = 'CREATING' | 'ACTIVE' | 'DISABLING' | 'DISABLED' | 'CREATE_FAILED';
377
-
378
- interface Db9ClientOptions {
379
- baseUrl?: string;
380
- token?: string;
381
- fetch?: FetchFn;
382
- credentialStore?: CredentialStore;
383
- }
384
- declare function createDb9Client(options?: Db9ClientOptions): {
385
- auth: {
386
- register: (req: RegisterRequest) => Promise<CustomerResponse>;
387
- login: (req: LoginRequest) => Promise<LoginResponse>;
388
- anonymousRegister: () => Promise<AnonymousRegisterResponse>;
389
- anonymousRefresh: (req: AnonymousRefreshRequest) => Promise<AnonymousRefreshResponse>;
390
- me: () => Promise<CustomerResponse>;
391
- getAnonymousSecret: () => Promise<AnonymousSecretResponse>;
392
- claim: (req: ClaimRequest) => Promise<ClaimResponse>;
393
- };
394
- tokens: {
395
- list: () => Promise<TokenResponse[]>;
396
- revoke: (tokenId: string) => Promise<MessageResponse>;
397
- };
398
- databases: {
399
- create: (req: CreateDatabaseRequest) => Promise<DatabaseResponse>;
400
- list: () => Promise<DatabaseResponse[]>;
401
- get: (databaseId: string) => Promise<DatabaseResponse>;
402
- delete: (databaseId: string) => Promise<MessageResponse>;
403
- resetPassword: (databaseId: string) => Promise<CustomerPasswordResetResponse>;
404
- observability: (databaseId: string) => Promise<TenantObservabilityResponse>;
405
- sql: (databaseId: string, query: string) => Promise<SqlResult>;
406
- sqlFile: (databaseId: string, fileContent: string) => Promise<SqlResult>;
407
- schema: (databaseId: string) => Promise<SchemaResponse>;
408
- dump: (databaseId: string, req?: DumpRequest) => Promise<DumpResponse>;
409
- applyMigration: (databaseId: string, req: MigrationApplyRequest) => Promise<MigrationApplyResponse>;
410
- listMigrations: (databaseId: string) => Promise<MigrationMetadata[]>;
411
- branch: (databaseId: string, req: BranchRequest) => Promise<DatabaseResponse>;
412
- users: {
413
- list: (databaseId: string) => Promise<UserResponse[]>;
414
- create: (databaseId: string, req: CreateUserRequest) => Promise<MessageResponse>;
415
- delete: (databaseId: string, username: string) => Promise<MessageResponse>;
416
- };
417
- };
418
- fs: {
419
- list: (dbId: string, path: string, options?: Fs9ListOptions) => Promise<Fs9FileEntry[]>;
420
- read: (dbId: string, path: string) => Promise<string>;
421
- write: (dbId: string, path: string, content: string) => Promise<void>;
422
- stat: (dbId: string, path: string) => Promise<Fs9FileEntry>;
423
- mkdir: (dbId: string, path: string) => Promise<void>;
424
- remove: (dbId: string, path: string) => Promise<void>;
425
- };
426
- };
427
- type Db9Client = ReturnType<typeof createDb9Client>;
428
-
429
- export { type SqlQueryResponse as $, type AdminCreateUserRequest as A, type BatchCreateRequest as B, type CredentialStore as C, type DatabaseResponse as D, type DumpRequest as E, type FetchFn as F, type DumpResponse as G, type Endpoint as H, FileCredentialStore as I, type HealthResponse as J, type HttpClient as K, type HttpClientOptions as L, type ListTenantsParams as M, type LoginRequest as N, type LoginResponse as O, MemoryCredentialStore as P, type MessageResponse as Q, type MigrationApplyRequest as R, type MigrationApplyResponse as S, type MigrationMetadata as T, type ObservabilitySummary as U, type PasswordResetResponse as V, type QuerySample as W, type RegisterRequest as X, type SchemaResponse as Y, type SqlExecuteRequest as Z, type SqlQueryRequest as _, type AnonymousRefreshRequest as a, type SqlResult as a0, type TableMetadata as a1, type TenantConnectRequest as a2, type TenantConnectResponse as a3, type TenantListResponse as a4, type TenantObservabilityResponse as a5, type TenantResponse as a6, type TenantState as a7, type TenantUpdateRequest as a8, type TokenResponse as a9, type UserCreateResponse as aa, type UserResponse as ab, type ViewMetadata as ac, createDb9Client as ad, defaultCredentialStore as ae, type AnonymousRefreshResponse as b, type AnonymousRegisterResponse as c, type AnonymousSecretResponse as d, type AuditLogParams as e, type AuditLogResponse as f, type BatchCreateResponse as g, type BatchDeleteRequest as h, type BatchDeleteResponse as i, type BatchItemError as j, type BatchUpdateRequest as k, type BatchUpdateResponse as l, type BranchRequest as m, type ClaimRequest as n, type ClaimResponse as o, type ColumnInfo as p, type ColumnMetadata as q, type CreateDatabaseRequest as r, type CreateTenantRequest as s, type CreateTenantResponse as t, type CreateUserRequest as u, type Credentials as v, type CustomerPasswordResetResponse as w, type CustomerResponse as x, type Db9Client as y, type Db9ClientOptions as z };