get-db9 0.5.0 → 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.
@@ -54,24 +54,137 @@ declare class MemoryCredentialStore implements CredentialStore {
54
54
  /** Returns a FileCredentialStore with the default path (`~/.db9/credentials`). */
55
55
  declare function defaultCredentialStore(): CredentialStore;
56
56
 
57
- /** A file or directory entry from fs9 readdir/stat API */
58
- interface Fs9FileEntry {
57
+ /** File or directory metadata returned by `stat` and `readdir`. */
58
+ interface FileInfo {
59
59
  path: string;
60
+ type: 'file' | 'dir';
60
61
  size: number;
61
- file_type: 'regular' | 'directory' | 'symlink';
62
62
  mode: number;
63
- uid: number;
64
- gid: number;
65
- atime: number;
66
- mtime: number;
67
- ctime: number;
68
- etag: string;
69
- symlink_target?: string;
70
- }
71
- /** Options for fs9 list operation */
72
- interface Fs9ListOptions {
63
+ mtime: string;
64
+ }
65
+ /** Options for listing directory contents. */
66
+ interface FsListOptions {
67
+ recursive?: boolean;
68
+ }
69
+ /** Options for removing files/directories. */
70
+ interface FsRemoveOptions {
73
71
  recursive?: boolean;
74
72
  }
73
+ /** Base shape for all WS requests. */
74
+ interface FsWsRequest {
75
+ id: string;
76
+ op: string;
77
+ [key: string]: unknown;
78
+ }
79
+ /** Successful WS response. */
80
+ interface FsWsResponse {
81
+ id: string;
82
+ ok: boolean;
83
+ data?: unknown;
84
+ error?: FsWsError;
85
+ }
86
+ /** Error detail from a failed WS response. */
87
+ interface FsWsError {
88
+ code: string;
89
+ message: string;
90
+ }
91
+ /** Auth response data. */
92
+ interface FsAuthInfo {
93
+ user: string;
94
+ tenant: string;
95
+ keyspace: string;
96
+ }
97
+ /** Options for connecting to the fs9 WebSocket server. */
98
+ interface FsConnectOptions {
99
+ /** WebSocket URL (e.g. `wss://host:5480`). */
100
+ wsUrl: string;
101
+ /** Username in `{tenant_id}.{admin_user}` format. */
102
+ username: string;
103
+ /** Admin password. */
104
+ password: string;
105
+ }
106
+ /** @deprecated Use `FileInfo` instead. */
107
+ type Fs9FileEntry = FileInfo;
108
+ /** @deprecated Use `FsListOptions` instead. */
109
+ type Fs9ListOptions = FsListOptions;
110
+
111
+ /**
112
+ * WebSocket client for the fs9 filesystem protocol.
113
+ *
114
+ * Mirrors db9-cli/src/fssh/client.rs — each public method maps to a single
115
+ * request–response round-trip over a JSON text WebSocket.
116
+ *
117
+ * The client is environment-agnostic: pass any W3C-compatible WebSocket
118
+ * constructor (native `WebSocket` in browsers/Deno/Bun/Node 21+, or the
119
+ * `ws` npm package for Node 18–20).
120
+ */
121
+
122
+ /** Minimal W3C WebSocket interface we depend on. */
123
+ interface WebSocketLike {
124
+ readonly readyState: number;
125
+ send(data: string): void;
126
+ close(code?: number, reason?: string): void;
127
+ onopen: ((ev: unknown) => void) | null;
128
+ onclose: ((ev: unknown) => void) | null;
129
+ onerror: ((ev: unknown) => void) | null;
130
+ onmessage: ((ev: {
131
+ data: unknown;
132
+ }) => void) | null;
133
+ }
134
+ /** Constructor for a W3C-compatible WebSocket. */
135
+ type WebSocketConstructor = new (url: string) => WebSocketLike;
136
+ /** Error from an fs9 WebSocket operation. */
137
+ declare class FsError extends Error {
138
+ readonly code: string;
139
+ constructor(code: string, message: string);
140
+ }
141
+ /**
142
+ * Async WebSocket client for fs9 file operations.
143
+ *
144
+ * Usage:
145
+ * ```ts
146
+ * const client = await FsClient.connect('wss://host:5480', WebSocket);
147
+ * await client.authenticate('tenant.admin', 'password');
148
+ * const entries = await client.readdir('/');
149
+ * await client.close();
150
+ * ```
151
+ */
152
+ declare class FsClient {
153
+ private ws;
154
+ private pending;
155
+ private closed;
156
+ private constructor();
157
+ /**
158
+ * Connect to an fs9 WebSocket server.
159
+ *
160
+ * @param url WebSocket URL, e.g. `wss://host:5480`
161
+ * @param WS WebSocket constructor (native or from `ws` package)
162
+ */
163
+ static connect(url: string, WS: WebSocketConstructor): Promise<FsClient>;
164
+ /** Authenticate with the server. Must be called first after connect. */
165
+ authenticate(username: string, password: string): Promise<FsAuthInfo>;
166
+ /** Get file or directory metadata. */
167
+ stat(path: string): Promise<FileInfo>;
168
+ /** List directory contents. */
169
+ readdir(path: string): Promise<FileInfo[]>;
170
+ /** Create a directory. Always recursive (mkdir -p). */
171
+ mkdir(path: string, recursive?: boolean): Promise<void>;
172
+ /** Read an entire file, returning raw bytes. */
173
+ readFile(path: string): Promise<Uint8Array>;
174
+ /** Write (overwrite) a file. Returns bytes written. */
175
+ writeFile(path: string, data: Uint8Array | ArrayBuffer | string): Promise<number>;
176
+ /** Append to a file. Returns bytes written. */
177
+ appendFile(path: string, data: Uint8Array | ArrayBuffer | string): Promise<number>;
178
+ /** Remove a file (non-recursive) or directory (recursive). */
179
+ rm(path: string, recursive?: boolean): Promise<void>;
180
+ /** Rename (move) a file or directory. */
181
+ rename(oldPath: string, newPath: string): Promise<void>;
182
+ /** Gracefully close the WebSocket connection. */
183
+ close(): Promise<void>;
184
+ private sendAndRecv;
185
+ private expectOk;
186
+ private errorMessage;
187
+ }
75
188
 
76
189
  interface Endpoint {
77
190
  host: string;
@@ -396,6 +509,7 @@ interface MigrationMetadata {
396
509
  applied_at: string;
397
510
  sql_preview: string;
398
511
  }
512
+ /** @deprecated Fs9 events are not available in the WebSocket protocol. */
399
513
  interface Fs9EventEntry {
400
514
  id: string;
401
515
  type: string;
@@ -405,12 +519,35 @@ interface Fs9EventEntry {
405
519
  size?: number;
406
520
  metadata?: Record<string, unknown>;
407
521
  }
522
+ /** @deprecated Fs9 events are not available in the WebSocket protocol. */
408
523
  interface Fs9EventOptions {
409
524
  limit?: number;
410
525
  offset?: number;
411
526
  path?: string;
412
527
  type?: string;
413
528
  }
529
+ interface DeviceCodeResponse {
530
+ device_code: string;
531
+ user_code: string;
532
+ verification_uri: string;
533
+ expires_in: number;
534
+ interval: number;
535
+ }
536
+ interface DeviceTokenRequest {
537
+ device_code: string;
538
+ }
539
+ interface DeviceTokenResponse {
540
+ token: string;
541
+ expires_at: string;
542
+ }
543
+ interface DeviceTokenErrorResponse {
544
+ error: 'authorization_pending' | 'expired_token' | 'access_denied';
545
+ }
546
+ interface DeviceVerifyRequest {
547
+ user_code: string;
548
+ email: string;
549
+ password: string;
550
+ }
414
551
  type TenantState = 'CREATING' | 'ACTIVE' | 'DISABLING' | 'DISABLED' | 'CREATE_FAILED';
415
552
 
416
553
  interface Db9ClientOptions {
@@ -421,6 +558,10 @@ interface Db9ClientOptions {
421
558
  timeout?: number;
422
559
  maxRetries?: number;
423
560
  retryDelay?: number;
561
+ /** WebSocket constructor for fs operations (native WebSocket, or `ws` package for Node 18–20). */
562
+ WebSocket?: WebSocketConstructor;
563
+ /** WebSocket port for fs9 server (default: 5480). */
564
+ wsPort?: number;
424
565
  }
425
566
  declare function createDb9Client(options?: Db9ClientOptions): {
426
567
  auth: {
@@ -444,6 +585,7 @@ declare function createDb9Client(options?: Db9ClientOptions): {
444
585
  get: (databaseId: string) => Promise<DatabaseResponse>;
445
586
  delete: (databaseId: string) => Promise<MessageResponse>;
446
587
  resetPassword: (databaseId: string) => Promise<CustomerPasswordResetResponse>;
588
+ credentials: (databaseId: string) => Promise<CustomerPasswordResetResponse>;
447
589
  observability: (databaseId: string) => Promise<TenantObservabilityResponse>;
448
590
  sql: (databaseId: string, query: string) => Promise<SqlResult>;
449
591
  sqlFile: (databaseId: string, fileContent: string) => Promise<SqlResult>;
@@ -459,17 +601,43 @@ declare function createDb9Client(options?: Db9ClientOptions): {
459
601
  };
460
602
  };
461
603
  fs: {
462
- list: (dbId: string, path: string, options?: Fs9ListOptions) => Promise<Fs9FileEntry[]>;
604
+ /**
605
+ * Open a persistent WebSocket connection for multiple fs operations.
606
+ * Caller is responsible for calling `client.close()` when done.
607
+ */
608
+ connect: (dbId: string) => Promise<FsClient>;
609
+ /** List directory contents. */
610
+ list: (dbId: string, path: string) => Promise<FileInfo[]>;
611
+ /** Read a file as text (UTF-8). */
463
612
  read: (dbId: string, path: string) => Promise<string>;
464
- readBinary: (dbId: string, path: string) => Promise<ArrayBuffer>;
465
- write: (dbId: string, path: string, content: string | ArrayBuffer | Uint8Array | Blob) => Promise<void>;
466
- stat: (dbId: string, path: string) => Promise<Fs9FileEntry>;
613
+ /** Read a file as raw bytes. */
614
+ readBinary: (dbId: string, path: string) => Promise<Uint8Array>;
615
+ /** Write (overwrite) a file. Accepts string, ArrayBuffer, or Uint8Array. */
616
+ write: (dbId: string, path: string, content: string | ArrayBuffer | Uint8Array) => Promise<void>;
617
+ /** Append to a file. Returns bytes written. */
618
+ append: (dbId: string, path: string, content: string | ArrayBuffer | Uint8Array) => Promise<number>;
619
+ /** Get file or directory metadata. */
620
+ stat: (dbId: string, path: string) => Promise<FileInfo>;
621
+ /** Check if a file or directory exists. */
467
622
  exists: (dbId: string, path: string) => Promise<boolean>;
623
+ /** Create a directory (recursive by default). */
468
624
  mkdir: (dbId: string, path: string) => Promise<void>;
469
- remove: (dbId: string, path: string) => Promise<void>;
470
- events: (dbId: string, options?: Fs9EventOptions) => Promise<Fs9EventEntry[]>;
625
+ /** Remove a file or directory. */
626
+ remove: (dbId: string, path: string, opts?: {
627
+ recursive?: boolean;
628
+ }) => Promise<void>;
629
+ /** Rename (move) a file or directory. */
630
+ rename: (dbId: string, oldPath: string, newPath: string) => Promise<void>;
631
+ };
632
+ deviceAuth: {
633
+ /** Start device code flow. Returns codes for user to authorize. */
634
+ createDeviceCode: () => Promise<DeviceCodeResponse>;
635
+ /** Poll for device token after user authorizes. Returns token or error status. */
636
+ pollDeviceToken: (req: DeviceTokenRequest) => Promise<DeviceTokenResponse | DeviceTokenErrorResponse>;
637
+ /** Submit device verification with user credentials. */
638
+ verifyDevice: (req: DeviceVerifyRequest) => Promise<MessageResponse>;
471
639
  };
472
640
  };
473
641
  type Db9Client = ReturnType<typeof createDb9Client>;
474
642
 
475
- export { type RegisterRequest as $, type AdminCreateUserRequest as A, type BatchCreateRequest as B, type CredentialStore as C, type DatabaseResponse as D, type Db9Client as E, type FetchFn as F, type Db9ClientOptions as G, type DumpRequest as H, type DumpResponse as I, type Endpoint as J, FileCredentialStore as K, type Fs9EventEntry as L, type Fs9EventOptions as M, type HealthResponse as N, type HttpClient as O, type HttpClientOptions as P, type ListTenantsParams as Q, type LoginRequest as R, type LoginResponse as S, MemoryCredentialStore as T, type MessageResponse as U, type MigrationApplyRequest as V, type MigrationApplyResponse as W, type MigrationMetadata as X, type ObservabilitySummary as Y, type PasswordResetResponse as Z, type QuerySample as _, type AnonymousRefreshRequest as a, type SchemaResponse as a0, type SqlErrorDetail as a1, type SqlExecuteRequest as a2, type SqlQueryRequest as a3, type SqlQueryResponse as a4, type SqlResult as a5, type TableMetadata as a6, type TenantConnectRequest as a7, type TenantConnectResponse as a8, type TenantListResponse as a9, type TenantObservabilityResponse as aa, type TenantResponse as ab, type TenantState as ac, type TenantUpdateRequest as ad, type TokenResponse as ae, type UserCreateResponse as af, type UserResponse as ag, type ViewMetadata as ah, createDb9Client as ai, defaultCredentialStore as aj, 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 CreateTokenRequest as u, type CreateTokenResponse as v, type CreateUserRequest as w, type Credentials as x, type CustomerPasswordResetResponse as y, type CustomerResponse as z };
643
+ export { type FsWsError as $, type AdminCreateUserRequest as A, type BatchCreateRequest as B, type CredentialStore as C, type DatabaseResponse as D, type Db9Client as E, type FetchFn as F, type Db9ClientOptions as G, type DeviceCodeResponse as H, type DeviceTokenErrorResponse as I, type DeviceTokenRequest as J, type DeviceTokenResponse as K, type DeviceVerifyRequest as L, type DumpRequest as M, type DumpResponse as N, type Endpoint as O, FileCredentialStore as P, type FileInfo as Q, type Fs9EventEntry as R, type Fs9EventOptions as S, type Fs9FileEntry as T, type Fs9ListOptions as U, type FsAuthInfo as V, FsClient as W, type FsConnectOptions as X, FsError as Y, type FsListOptions as Z, type FsRemoveOptions as _, type AnonymousRefreshRequest as a, type FsWsRequest as a0, type FsWsResponse as a1, type HealthResponse as a2, type HttpClient as a3, type HttpClientOptions as a4, type ListTenantsParams as a5, type LoginRequest as a6, type LoginResponse as a7, MemoryCredentialStore as a8, type MessageResponse as a9, type WebSocketLike as aA, createDb9Client as aB, defaultCredentialStore as aC, type MigrationApplyRequest as aa, type MigrationApplyResponse as ab, type MigrationMetadata as ac, type ObservabilitySummary as ad, type PasswordResetResponse as ae, type QuerySample as af, type RegisterRequest as ag, type SchemaResponse as ah, type SqlErrorDetail as ai, type SqlExecuteRequest as aj, type SqlQueryRequest as ak, type SqlQueryResponse as al, type SqlResult as am, type TableMetadata as an, type TenantConnectRequest as ao, type TenantConnectResponse as ap, type TenantListResponse as aq, type TenantObservabilityResponse as ar, type TenantResponse as as, type TenantState as at, type TenantUpdateRequest as au, type TokenResponse as av, type UserCreateResponse as aw, type UserResponse as ax, type ViewMetadata as ay, type WebSocketConstructor as az, 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 CreateTokenRequest as u, type CreateTokenResponse as v, type CreateUserRequest as w, type Credentials as x, type CustomerPasswordResetResponse as y, type CustomerResponse as z };