get-db9 0.2.0 → 0.4.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.
package/README.md CHANGED
@@ -29,14 +29,15 @@ const db = await instantDatabase({
29
29
  });
30
30
  ```
31
31
 
32
- ## Customer API
32
+ ## Db9 Client
33
33
 
34
- Full typed client for the Customer API (register, databases, SQL, migrations).
34
+ Full typed client for the API (register, databases, SQL, migrations).
35
35
 
36
36
  ```typescript
37
- import { createCustomerClient } from 'get-db9/customer';
37
+ import { createDb9Client } from 'get-db9/client';
38
38
 
39
- const client = createCustomerClient({ token: 'your-token' });
39
+ // No token needed. Automatically anonymous-registers and saves credentials.
40
+ const client = createDb9Client();
40
41
 
41
42
  // Create a database
42
43
  const db = await client.databases.create({ name: 'myapp' });
@@ -69,14 +70,24 @@ await client.databases.applyMigration(db.id, {
69
70
  | `seed` | `string` | — | SQL to run after creation |
70
71
  | `seedFile` | `string` | — | SQL file content to run |
71
72
 
72
- ### Customer client options
73
+ ### Db9 client options
73
74
 
74
75
  | Option | Type | Default | Description |
75
76
  |--------|------|---------|-------------|
76
77
  | `baseUrl` | `string` | Production URL | API endpoint |
77
- | `token` | `string` | — | Bearer token |
78
+ | `token` | `string` | — | Bearer token (optional) |
78
79
  | `fetch` | `FetchFn` | `globalThis.fetch` | Custom fetch |
79
- | `credentialStore` | `CredentialStore` | | Auto-load token |
80
+ | `credentialStore` | `CredentialStore` | `FileCredentialStore` | Load/save token |
81
+
82
+ ## Zero-config client
83
+
84
+ ```typescript
85
+ import { createDb9Client } from 'get-db9';
86
+
87
+ // No token needed! Auto-registers anonymously
88
+ const client = createDb9Client();
89
+ const db = await client.databases.create({ name: 'myapp' });
90
+ ```
80
91
 
81
92
  ## Error Handling
82
93
 
@@ -1,4 +1,5 @@
1
1
  type FetchFn = typeof globalThis.fetch;
2
+ type BodyInit = string | Blob | ArrayBuffer | FormData | URLSearchParams | ReadableStream<Uint8Array>;
2
3
  interface HttpClientOptions {
3
4
  baseUrl: string;
4
5
  fetch?: FetchFn;
@@ -9,6 +10,8 @@ interface HttpClient {
9
10
  post<T>(path: string, body?: unknown): Promise<T>;
10
11
  put<T>(path: string, body?: unknown): Promise<T>;
11
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>;
12
15
  }
13
16
 
14
17
  /** Credential fields stored in `~/.db9/credentials` (TOML). */
@@ -46,6 +49,28 @@ declare class MemoryCredentialStore implements CredentialStore {
46
49
  /** Returns a FileCredentialStore with the default path (`~/.db9/credentials`). */
47
50
  declare function defaultCredentialStore(): CredentialStore;
48
51
 
52
+ /** A file or directory entry from fs9 readdir API */
53
+ interface Fs9FileInfo {
54
+ path: string;
55
+ type: 'file' | 'dir';
56
+ size: number;
57
+ mode: number;
58
+ mtime: string;
59
+ }
60
+ /** Response from fs9 stat API */
61
+ interface Fs9StatResponse {
62
+ path: string;
63
+ is_dir: boolean;
64
+ is_file: boolean;
65
+ size: number;
66
+ mode: number;
67
+ mtime: number;
68
+ }
69
+ /** Options for fs9 list operation */
70
+ interface Fs9ListOptions {
71
+ recursive?: boolean;
72
+ }
73
+
49
74
  interface Endpoint {
50
75
  host: string;
51
76
  port: number;
@@ -353,13 +378,13 @@ interface MigrationMetadata {
353
378
  }
354
379
  type TenantState = 'CREATING' | 'ACTIVE' | 'DISABLING' | 'DISABLED' | 'CREATE_FAILED';
355
380
 
356
- interface CustomerClientOptions {
381
+ interface Db9ClientOptions {
357
382
  baseUrl?: string;
358
383
  token?: string;
359
384
  fetch?: FetchFn;
360
385
  credentialStore?: CredentialStore;
361
386
  }
362
- declare function createCustomerClient(options?: CustomerClientOptions): {
387
+ declare function createDb9Client(options?: Db9ClientOptions): {
363
388
  auth: {
364
389
  register: (req: RegisterRequest) => Promise<CustomerResponse>;
365
390
  login: (req: LoginRequest) => Promise<LoginResponse>;
@@ -393,7 +418,13 @@ declare function createCustomerClient(options?: CustomerClientOptions): {
393
418
  delete: (databaseId: string, username: string) => Promise<MessageResponse>;
394
419
  };
395
420
  };
421
+ fs: {
422
+ list: (dbId: string, path: string, options?: Fs9ListOptions) => Promise<Fs9FileInfo[]>;
423
+ read: (dbId: string, path: string) => Promise<string>;
424
+ write: (dbId: string, path: string, content: string) => Promise<void>;
425
+ stat: (dbId: string, path: string) => Promise<Fs9StatResponse>;
426
+ };
396
427
  };
397
- type CustomerClient = ReturnType<typeof createCustomerClient>;
428
+ type Db9Client = ReturnType<typeof createDb9Client>;
398
429
 
399
- 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, createCustomerClient 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 CustomerClient as w, type CustomerClientOptions as x, type CustomerPasswordResetResponse as y, type CustomerResponse as z };
430
+ 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 };
@@ -1,4 +1,5 @@
1
1
  type FetchFn = typeof globalThis.fetch;
2
+ type BodyInit = string | Blob | ArrayBuffer | FormData | URLSearchParams | ReadableStream<Uint8Array>;
2
3
  interface HttpClientOptions {
3
4
  baseUrl: string;
4
5
  fetch?: FetchFn;
@@ -9,6 +10,8 @@ interface HttpClient {
9
10
  post<T>(path: string, body?: unknown): Promise<T>;
10
11
  put<T>(path: string, body?: unknown): Promise<T>;
11
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>;
12
15
  }
13
16
 
14
17
  /** Credential fields stored in `~/.db9/credentials` (TOML). */
@@ -46,6 +49,28 @@ declare class MemoryCredentialStore implements CredentialStore {
46
49
  /** Returns a FileCredentialStore with the default path (`~/.db9/credentials`). */
47
50
  declare function defaultCredentialStore(): CredentialStore;
48
51
 
52
+ /** A file or directory entry from fs9 readdir API */
53
+ interface Fs9FileInfo {
54
+ path: string;
55
+ type: 'file' | 'dir';
56
+ size: number;
57
+ mode: number;
58
+ mtime: string;
59
+ }
60
+ /** Response from fs9 stat API */
61
+ interface Fs9StatResponse {
62
+ path: string;
63
+ is_dir: boolean;
64
+ is_file: boolean;
65
+ size: number;
66
+ mode: number;
67
+ mtime: number;
68
+ }
69
+ /** Options for fs9 list operation */
70
+ interface Fs9ListOptions {
71
+ recursive?: boolean;
72
+ }
73
+
49
74
  interface Endpoint {
50
75
  host: string;
51
76
  port: number;
@@ -353,13 +378,13 @@ interface MigrationMetadata {
353
378
  }
354
379
  type TenantState = 'CREATING' | 'ACTIVE' | 'DISABLING' | 'DISABLED' | 'CREATE_FAILED';
355
380
 
356
- interface CustomerClientOptions {
381
+ interface Db9ClientOptions {
357
382
  baseUrl?: string;
358
383
  token?: string;
359
384
  fetch?: FetchFn;
360
385
  credentialStore?: CredentialStore;
361
386
  }
362
- declare function createCustomerClient(options?: CustomerClientOptions): {
387
+ declare function createDb9Client(options?: Db9ClientOptions): {
363
388
  auth: {
364
389
  register: (req: RegisterRequest) => Promise<CustomerResponse>;
365
390
  login: (req: LoginRequest) => Promise<LoginResponse>;
@@ -393,7 +418,13 @@ declare function createCustomerClient(options?: CustomerClientOptions): {
393
418
  delete: (databaseId: string, username: string) => Promise<MessageResponse>;
394
419
  };
395
420
  };
421
+ fs: {
422
+ list: (dbId: string, path: string, options?: Fs9ListOptions) => Promise<Fs9FileInfo[]>;
423
+ read: (dbId: string, path: string) => Promise<string>;
424
+ write: (dbId: string, path: string, content: string) => Promise<void>;
425
+ stat: (dbId: string, path: string) => Promise<Fs9StatResponse>;
426
+ };
396
427
  };
397
- type CustomerClient = ReturnType<typeof createCustomerClient>;
428
+ type Db9Client = ReturnType<typeof createDb9Client>;
398
429
 
399
- 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, createCustomerClient 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 CustomerClient as w, type CustomerClientOptions as x, type CustomerPasswordResetResponse as y, type CustomerResponse as z };
430
+ 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 };
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
8
  var __export = (target, all) => {
7
9
  for (var name in all)
@@ -15,14 +17,22 @@ var __copyProps = (to, from, except, desc) => {
15
17
  }
16
18
  return to;
17
19
  };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
18
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
29
 
20
- // src/customer.ts
21
- var customer_exports = {};
22
- __export(customer_exports, {
23
- createCustomerClient: () => createCustomerClient
30
+ // src/client.ts
31
+ var client_exports = {};
32
+ __export(client_exports, {
33
+ createDb9Client: () => createDb9Client
24
34
  });
25
- module.exports = __toCommonJS(customer_exports);
35
+ module.exports = __toCommonJS(client_exports);
26
36
 
27
37
  // src/errors.ts
28
38
  var Db9Error = class _Db9Error extends Error {
@@ -106,36 +116,194 @@ function createHttpClient(options) {
106
116
  }
107
117
  return response.json();
108
118
  }
119
+ async function requestRaw(method, path, body, params, customHeaders) {
120
+ let url = `${baseUrl}${path}`;
121
+ if (params) {
122
+ const searchParams = new URLSearchParams();
123
+ for (const [key, value] of Object.entries(params)) {
124
+ if (value !== void 0) {
125
+ searchParams.set(key, value);
126
+ }
127
+ }
128
+ const qs = searchParams.toString();
129
+ if (qs) url += `?${qs}`;
130
+ }
131
+ const headers = {
132
+ ...options.headers,
133
+ ...customHeaders
134
+ };
135
+ const init = { method, headers };
136
+ if (body !== void 0) {
137
+ init.body = body;
138
+ }
139
+ const response = await fetchFn(url, init);
140
+ if (!response.ok) {
141
+ throw await Db9Error.fromResponse(response);
142
+ }
143
+ return response;
144
+ }
109
145
  return {
110
146
  get: (path, params) => request("GET", path, void 0, params),
111
147
  post: (path, body) => request("POST", path, body),
112
148
  put: (path, body) => request("PUT", path, body),
113
- del: (path) => request("DELETE", path)
149
+ del: (path) => request("DELETE", path),
150
+ getRaw: (path, params) => requestRaw("GET", path, void 0, params),
151
+ putRaw: (path, body, headers) => requestRaw("PUT", path, body, void 0, headers)
114
152
  };
115
153
  }
116
154
 
117
- // src/customer.ts
118
- function createCustomerClient(options = {}) {
155
+ // src/credentials.ts
156
+ var import_toml = require("@iarna/toml");
157
+ var FileCredentialStore = class {
158
+ customPath;
159
+ /**
160
+ * @param path — Override the credential file location.
161
+ * Defaults to `~/.db9/credentials` (resolved lazily).
162
+ */
163
+ constructor(path) {
164
+ this.customPath = path;
165
+ }
166
+ /** Resolve the credential file path (lazy to avoid top-level `os` import). */
167
+ async resolvePath() {
168
+ if (this.customPath) return this.customPath;
169
+ const os = await import("os");
170
+ const nodePath = await import("path");
171
+ return nodePath.join(os.homedir(), ".db9", "credentials");
172
+ }
173
+ async load() {
174
+ const fs = await import("fs/promises");
175
+ const filePath = await this.resolvePath();
176
+ let content;
177
+ try {
178
+ content = await fs.readFile(filePath, "utf-8");
179
+ } catch (err) {
180
+ if (err.code === "ENOENT") return null;
181
+ throw err;
182
+ }
183
+ const parsed = (0, import_toml.parse)(content);
184
+ const token = parsed["token"];
185
+ if (typeof token !== "string") return null;
186
+ const creds = { token };
187
+ if (typeof parsed["is_anonymous"] === "boolean") {
188
+ creds.is_anonymous = parsed["is_anonymous"];
189
+ }
190
+ if (typeof parsed["anonymous_id"] === "string") {
191
+ creds.anonymous_id = parsed["anonymous_id"];
192
+ }
193
+ if (typeof parsed["anonymous_secret"] === "string") {
194
+ creds.anonymous_secret = parsed["anonymous_secret"];
195
+ }
196
+ return creds;
197
+ }
198
+ async save(credentials) {
199
+ const fs = await import("fs/promises");
200
+ const nodePath = await import("path");
201
+ const filePath = await this.resolvePath();
202
+ const dir = nodePath.dirname(filePath);
203
+ await fs.mkdir(dir, { recursive: true, mode: 448 });
204
+ const data = {};
205
+ try {
206
+ const raw = await fs.readFile(filePath, "utf-8");
207
+ const parsed = (0, import_toml.parse)(raw);
208
+ for (const [k, v] of Object.entries(parsed)) {
209
+ if (typeof v === "string" || typeof v === "boolean" || typeof v === "number") {
210
+ data[k] = v;
211
+ }
212
+ }
213
+ } catch (err) {
214
+ if (err.code !== "ENOENT") throw err;
215
+ }
216
+ data["token"] = credentials.token;
217
+ if (credentials.is_anonymous !== void 0) {
218
+ data["is_anonymous"] = credentials.is_anonymous;
219
+ }
220
+ if (credentials.anonymous_id !== void 0) {
221
+ data["anonymous_id"] = credentials.anonymous_id;
222
+ }
223
+ if (credentials.anonymous_secret !== void 0) {
224
+ data["anonymous_secret"] = credentials.anonymous_secret;
225
+ }
226
+ const toml = (0, import_toml.stringify)(
227
+ data
228
+ );
229
+ await fs.writeFile(filePath, toml, { mode: 384 });
230
+ }
231
+ async clear() {
232
+ const fs = await import("fs/promises");
233
+ const filePath = await this.resolvePath();
234
+ try {
235
+ await fs.unlink(filePath);
236
+ } catch (err) {
237
+ if (err.code !== "ENOENT") throw err;
238
+ }
239
+ }
240
+ };
241
+ function defaultCredentialStore() {
242
+ return new FileCredentialStore();
243
+ }
244
+
245
+ // src/client.ts
246
+ function createDb9Client(options = {}) {
119
247
  const baseUrl = options.baseUrl ?? "https://db9.shared.aws.tidbcloud.com/api";
120
248
  let token = options.token;
121
249
  let tokenLoaded = !!token;
250
+ const store = options.credentialStore ?? defaultCredentialStore();
251
+ const fetchFn = options.fetch ?? globalThis.fetch;
122
252
  const publicClient = createHttpClient({
123
253
  baseUrl,
124
254
  fetch: options.fetch
125
255
  });
126
256
  async function getAuthClient() {
127
- if (!token && !tokenLoaded && options.credentialStore) {
128
- const creds = await options.credentialStore.load();
129
- if (creds) token = creds.token;
257
+ if (!token && !tokenLoaded) {
258
+ const creds = await store.load();
259
+ if (creds?.token) token = creds.token;
130
260
  tokenLoaded = true;
131
261
  }
132
- if (!token) throw new Error("No authentication token available");
262
+ if (!token) {
263
+ const reg = await publicClient.post(
264
+ "/customer/anonymous-register"
265
+ );
266
+ token = reg.token;
267
+ await store.save({
268
+ token: reg.token,
269
+ is_anonymous: reg.is_anonymous,
270
+ anonymous_id: reg.anonymous_id,
271
+ anonymous_secret: reg.anonymous_secret
272
+ });
273
+ }
133
274
  return createHttpClient({
134
275
  baseUrl,
135
276
  fetch: options.fetch,
136
277
  headers: { Authorization: `Bearer ${token}` }
137
278
  });
138
279
  }
280
+ function deriveFs9Url(dbId) {
281
+ const origin = baseUrl.replace(/\/api\/?$/, "");
282
+ return `${origin}/fs9/${dbId}`;
283
+ }
284
+ async function fsRequest(method, dbId, fsPath, body) {
285
+ if (!token && !tokenLoaded) {
286
+ await getAuthClient();
287
+ }
288
+ const fs9Url = deriveFs9Url(dbId);
289
+ const url = `${fs9Url}/api/v1${fsPath}`;
290
+ const headers = {};
291
+ if (token) {
292
+ headers["Authorization"] = `Bearer ${token}`;
293
+ }
294
+ if (body !== void 0) {
295
+ headers["Content-Type"] = "text/plain";
296
+ }
297
+ const init = { method, headers };
298
+ if (body !== void 0) {
299
+ init.body = body;
300
+ }
301
+ const response = await fetchFn(url, init);
302
+ if (!response.ok) {
303
+ throw await Db9Error.fromResponse(response);
304
+ }
305
+ return response;
306
+ }
139
307
  return {
140
308
  auth: {
141
309
  // Public endpoints (no token required)
@@ -281,11 +449,45 @@ function createCustomerClient(options = {}) {
281
449
  );
282
450
  }
283
451
  }
452
+ },
453
+ fs: {
454
+ list: async (dbId, path, options2) => {
455
+ const params = new URLSearchParams({ path });
456
+ if (options2?.recursive) params.set("recursive", "true");
457
+ const response = await fsRequest(
458
+ "GET",
459
+ dbId,
460
+ `/readdir?${params.toString()}`
461
+ );
462
+ return response.json();
463
+ },
464
+ read: async (dbId, path) => {
465
+ const params = new URLSearchParams({ path });
466
+ const response = await fsRequest(
467
+ "GET",
468
+ dbId,
469
+ `/download?${params.toString()}`
470
+ );
471
+ return response.text();
472
+ },
473
+ write: async (dbId, path, content) => {
474
+ const params = new URLSearchParams({ path });
475
+ await fsRequest("PUT", dbId, `/upload?${params.toString()}`, content);
476
+ },
477
+ stat: async (dbId, path) => {
478
+ const params = new URLSearchParams({ path });
479
+ const response = await fsRequest(
480
+ "GET",
481
+ dbId,
482
+ `/stat?${params.toString()}`
483
+ );
484
+ return response.json();
485
+ }
284
486
  }
285
487
  };
286
488
  }
287
489
  // Annotate the CommonJS export names for ESM import in node:
288
490
  0 && (module.exports = {
289
- createCustomerClient
491
+ createDb9Client
290
492
  });
291
- //# sourceMappingURL=customer.cjs.map
493
+ //# sourceMappingURL=client.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/client.ts","../src/errors.ts","../src/http.ts","../src/credentials.ts"],"sourcesContent":["import { createHttpClient, type FetchFn, type HttpClient } from './http';\nimport {\n defaultCredentialStore,\n type CredentialStore,\n} from './credentials';\nimport { Db9Error } from './errors';\nimport type { Fs9FileInfo, Fs9StatResponse, Fs9ListOptions } from './fs-types';\nimport type {\n RegisterRequest,\n CustomerResponse,\n LoginRequest,\n LoginResponse,\n AnonymousRegisterResponse,\n AnonymousRefreshRequest,\n AnonymousRefreshResponse,\n AnonymousSecretResponse,\n ClaimRequest,\n ClaimResponse,\n TokenResponse,\n MessageResponse,\n CreateDatabaseRequest,\n DatabaseResponse,\n CustomerPasswordResetResponse,\n TenantObservabilityResponse,\n SqlResult,\n SchemaResponse,\n DumpRequest,\n DumpResponse,\n MigrationApplyRequest,\n MigrationApplyResponse,\n MigrationMetadata,\n BranchRequest,\n UserResponse,\n CreateUserRequest,\n} from './types';\n\nexport interface Db9ClientOptions {\n baseUrl?: string;\n token?: string;\n fetch?: FetchFn;\n credentialStore?: CredentialStore;\n}\n\nexport function createDb9Client(options: Db9ClientOptions = {}) {\n const baseUrl =\n options.baseUrl ?? 'https://db9.shared.aws.tidbcloud.com/api';\n let token = options.token;\n let tokenLoaded = !!token;\n const store = options.credentialStore ?? defaultCredentialStore();\n const fetchFn = options.fetch ?? globalThis.fetch;\n\n // Public HTTP client — no Authorization header\n const publicClient = createHttpClient({\n baseUrl,\n fetch: options.fetch,\n });\n\n // Lazy-loading authenticated HTTP client\n async function getAuthClient(): Promise<HttpClient> {\n if (!token && !tokenLoaded) {\n const creds = await store.load();\n if (creds?.token) token = creds.token;\n tokenLoaded = true;\n }\n if (!token) {\n const reg = await publicClient.post<AnonymousRegisterResponse>(\n '/customer/anonymous-register'\n );\n token = reg.token;\n await store.save({\n token: reg.token,\n is_anonymous: reg.is_anonymous,\n anonymous_id: reg.anonymous_id,\n anonymous_secret: reg.anonymous_secret,\n });\n }\n return createHttpClient({\n baseUrl,\n fetch: options.fetch,\n headers: { Authorization: `Bearer ${token}` },\n });\n }\n\n // ── fs9 helpers ──────────────────────────────────────────────\n function deriveFs9Url(dbId: string): string {\n const origin = baseUrl.replace(/\\/api\\/?$/, '');\n return `${origin}/fs9/${dbId}`;\n }\n\n async function fsRequest(\n method: string,\n dbId: string,\n fsPath: string,\n body?: string\n ): Promise<Response> {\n // Ensure token is loaded (lazy auth pattern)\n if (!token && !tokenLoaded) {\n await getAuthClient();\n }\n\n const fs9Url = deriveFs9Url(dbId);\n const url = `${fs9Url}/api/v1${fsPath}`;\n\n const headers: Record<string, string> = {};\n if (token) {\n headers['Authorization'] = `Bearer ${token}`;\n }\n if (body !== undefined) {\n headers['Content-Type'] = 'text/plain';\n }\n\n const init: RequestInit = { method, headers };\n if (body !== undefined) {\n init.body = body;\n }\n\n const response = await fetchFn(url, init);\n if (!response.ok) {\n throw await Db9Error.fromResponse(response);\n }\n return response;\n }\n\n return {\n auth: {\n // Public endpoints (no token required)\n register: (req: RegisterRequest) =>\n publicClient.post<CustomerResponse>('/customer/register', req),\n\n login: (req: LoginRequest) =>\n publicClient.post<LoginResponse>('/customer/login', req),\n\n anonymousRegister: () =>\n publicClient.post<AnonymousRegisterResponse>(\n '/customer/anonymous-register'\n ),\n\n anonymousRefresh: (req: AnonymousRefreshRequest) =>\n publicClient.post<AnonymousRefreshResponse>(\n '/customer/anonymous-refresh',\n req\n ),\n\n // Authenticated endpoints\n me: async () => {\n const client = await getAuthClient();\n return client.get<CustomerResponse>('/customer/me');\n },\n\n getAnonymousSecret: async () => {\n const client = await getAuthClient();\n return client.get<AnonymousSecretResponse>(\n '/customer/anonymous-secret'\n );\n },\n\n claim: async (req: ClaimRequest) => {\n const client = await getAuthClient();\n return client.post<ClaimResponse>('/customer/claim', req);\n },\n },\n\n tokens: {\n list: async () => {\n const client = await getAuthClient();\n return client.get<TokenResponse[]>('/customer/tokens');\n },\n\n revoke: async (tokenId: string) => {\n const client = await getAuthClient();\n return client.del<MessageResponse>(`/customer/tokens/${tokenId}`);\n },\n },\n\n databases: {\n // ── CRUD ──────────────────────────────────────────────────\n create: async (req: CreateDatabaseRequest) => {\n const client = await getAuthClient();\n return client.post<DatabaseResponse>('/customer/databases', req);\n },\n\n list: async () => {\n const client = await getAuthClient();\n return client.get<DatabaseResponse[]>('/customer/databases');\n },\n\n get: async (databaseId: string) => {\n const client = await getAuthClient();\n return client.get<DatabaseResponse>(\n `/customer/databases/${databaseId}`\n );\n },\n\n delete: async (databaseId: string) => {\n const client = await getAuthClient();\n return client.del<MessageResponse>(\n `/customer/databases/${databaseId}`\n );\n },\n\n resetPassword: async (databaseId: string) => {\n const client = await getAuthClient();\n return client.post<CustomerPasswordResetResponse>(\n `/customer/databases/${databaseId}/reset-password`\n );\n },\n\n observability: async (databaseId: string) => {\n const client = await getAuthClient();\n return client.get<TenantObservabilityResponse>(\n `/customer/databases/${databaseId}/observability`\n );\n },\n\n // ── SQL Execution ─────────────────────────────────────────\n sql: async (databaseId: string, query: string) => {\n const client = await getAuthClient();\n return client.post<SqlResult>(\n `/customer/databases/${databaseId}/sql`,\n { query }\n );\n },\n\n sqlFile: async (databaseId: string, fileContent: string) => {\n const client = await getAuthClient();\n return client.post<SqlResult>(\n `/customer/databases/${databaseId}/sql`,\n { file_content: fileContent }\n );\n },\n\n // ── Schema & Dump ─────────────────────────────────────────\n schema: async (databaseId: string) => {\n const client = await getAuthClient();\n return client.get<SchemaResponse>(\n `/customer/databases/${databaseId}/schema`\n );\n },\n\n dump: async (databaseId: string, req?: DumpRequest) => {\n const client = await getAuthClient();\n return client.post<DumpResponse>(\n `/customer/databases/${databaseId}/dump`,\n req\n );\n },\n\n // ── Migrations ────────────────────────────────────────────\n applyMigration: async (\n databaseId: string,\n req: MigrationApplyRequest\n ) => {\n const client = await getAuthClient();\n return client.post<MigrationApplyResponse>(\n `/customer/databases/${databaseId}/migrations`,\n req\n );\n },\n\n listMigrations: async (databaseId: string) => {\n const client = await getAuthClient();\n return client.get<MigrationMetadata[]>(\n `/customer/databases/${databaseId}/migrations`\n );\n },\n\n // ── Branching ─────────────────────────────────────────────\n branch: async (databaseId: string, req: BranchRequest) => {\n const client = await getAuthClient();\n return client.post<DatabaseResponse>(\n `/customer/databases/${databaseId}/branch`,\n req\n );\n },\n\n // ── User Management ───────────────────────────────────────\n users: {\n list: async (databaseId: string) => {\n const client = await getAuthClient();\n return client.get<UserResponse[]>(\n `/customer/databases/${databaseId}/users`\n );\n },\n\n create: async (databaseId: string, req: CreateUserRequest) => {\n const client = await getAuthClient();\n return client.post<MessageResponse>(\n `/customer/databases/${databaseId}/users`,\n req\n );\n },\n\n delete: async (databaseId: string, username: string) => {\n const client = await getAuthClient();\n return client.del<MessageResponse>(\n `/customer/databases/${databaseId}/users/${username}`\n );\n },\n },\n },\n\n fs: {\n list: async (\n dbId: string,\n path: string,\n options?: Fs9ListOptions\n ): Promise<Fs9FileInfo[]> => {\n const params = new URLSearchParams({ path });\n if (options?.recursive) params.set('recursive', 'true');\n const response = await fsRequest(\n 'GET',\n dbId,\n `/readdir?${params.toString()}`\n );\n return response.json() as Promise<Fs9FileInfo[]>;\n },\n\n read: async (dbId: string, path: string): Promise<string> => {\n const params = new URLSearchParams({ path });\n const response = await fsRequest(\n 'GET',\n dbId,\n `/download?${params.toString()}`\n );\n return response.text();\n },\n\n write: async (\n dbId: string,\n path: string,\n content: string\n ): Promise<void> => {\n const params = new URLSearchParams({ path });\n await fsRequest('PUT', dbId, `/upload?${params.toString()}`, content);\n },\n\n stat: async (dbId: string, path: string): Promise<Fs9StatResponse> => {\n const params = new URLSearchParams({ path });\n const response = await fsRequest(\n 'GET',\n dbId,\n `/stat?${params.toString()}`\n );\n return response.json() as Promise<Fs9StatResponse>;\n },\n },\n };\n}\n\nexport type Db9Client = ReturnType<typeof createDb9Client>;\n","export class Db9Error extends Error {\n readonly statusCode: number;\n readonly response?: Response;\n\n constructor(message: string, statusCode: number, response?: Response) {\n super(message);\n this.name = 'Db9Error';\n this.statusCode = statusCode;\n this.response = response;\n }\n\n static async fromResponse(response: Response): Promise<Db9Error> {\n // Parse { \"message\": string } body — the ONLY error format from the API\n let message: string;\n try {\n const body = (await response.json()) as { message?: string };\n message = body.message || response.statusText;\n } catch {\n message = response.statusText;\n }\n\n // Return specific subclass based on status code\n switch (response.status) {\n case 401:\n return new Db9AuthError(message, response);\n case 404:\n return new Db9NotFoundError(message, response);\n case 409:\n return new Db9ConflictError(message, response);\n default:\n return new Db9Error(message, response.status, response);\n }\n }\n}\n\nexport class Db9AuthError extends Db9Error {\n constructor(message: string, response?: Response) {\n super(message, 401, response);\n this.name = 'Db9AuthError';\n }\n}\n\nexport class Db9NotFoundError extends Db9Error {\n constructor(message: string, response?: Response) {\n super(message, 404, response);\n this.name = 'Db9NotFoundError';\n }\n}\n\nexport class Db9ConflictError extends Db9Error {\n constructor(message: string, response?: Response) {\n super(message, 409, response);\n this.name = 'Db9ConflictError';\n }\n}\n","import { Db9Error } from './errors';\n\nexport type FetchFn = typeof globalThis.fetch;\n\n// BodyInit type for raw request bodies (string, Blob, ArrayBuffer, etc.)\nexport type BodyInit = string | Blob | ArrayBuffer | FormData | URLSearchParams | ReadableStream<Uint8Array>;\n\nexport interface HttpClientOptions {\n baseUrl: string;\n fetch?: FetchFn;\n headers?: Record<string, string>;\n}\n\nexport interface HttpClient {\n get<T>(path: string, params?: Record<string, string | undefined>): Promise<T>;\n post<T>(path: string, body?: unknown): Promise<T>;\n put<T>(path: string, body?: unknown): Promise<T>;\n del<T>(path: string): Promise<T>;\n getRaw(path: string, params?: Record<string, string | undefined>): Promise<Response>;\n putRaw(path: string, body: BodyInit, headers?: Record<string, string>): Promise<Response>;\n}\n\nexport function createHttpClient(options: HttpClientOptions): HttpClient {\n const fetchFn = options.fetch ?? globalThis.fetch;\n const baseUrl = options.baseUrl.replace(/\\/$/, ''); // strip trailing slash\n\n async function request<T>(\n method: string,\n path: string,\n body?: unknown,\n params?: Record<string, string | undefined>\n ): Promise<T> {\n let url = `${baseUrl}${path}`;\n\n // Append query params for GET requests\n if (params) {\n const searchParams = new URLSearchParams();\n for (const [key, value] of Object.entries(params)) {\n if (value !== undefined) {\n searchParams.set(key, value);\n }\n }\n const qs = searchParams.toString();\n if (qs) url += `?${qs}`;\n }\n\n const headers: Record<string, string> = {\n 'Content-Type': 'application/json',\n ...options.headers,\n };\n\n const init: RequestInit = { method, headers };\n if (body !== undefined) {\n init.body = JSON.stringify(body);\n }\n\n const response = await fetchFn(url, init);\n\n if (!response.ok) {\n throw await Db9Error.fromResponse(response);\n }\n\n // Handle 204 No Content\n if (response.status === 204) {\n return undefined as T;\n }\n\n return response.json() as Promise<T>;\n }\n\n async function requestRaw(\n method: string,\n path: string,\n body?: BodyInit,\n params?: Record<string, string | undefined>,\n customHeaders?: Record<string, string>\n ): Promise<Response> {\n let url = `${baseUrl}${path}`;\n\n // Append query params for GET requests\n if (params) {\n const searchParams = new URLSearchParams();\n for (const [key, value] of Object.entries(params)) {\n if (value !== undefined) {\n searchParams.set(key, value);\n }\n }\n const qs = searchParams.toString();\n if (qs) url += `?${qs}`;\n }\n\n const headers: Record<string, string> = {\n ...options.headers,\n ...customHeaders,\n };\n\n const init: RequestInit = { method, headers };\n if (body !== undefined) {\n init.body = body;\n }\n\n const response = await fetchFn(url, init);\n\n if (!response.ok) {\n throw await Db9Error.fromResponse(response);\n }\n\n return response;\n }\n\n return {\n get: <T>(path: string, params?: Record<string, string | undefined>) =>\n request<T>('GET', path, undefined, params),\n post: <T>(path: string, body?: unknown) => request<T>('POST', path, body),\n put: <T>(path: string, body?: unknown) => request<T>('PUT', path, body),\n del: <T>(path: string) => request<T>('DELETE', path),\n getRaw: (path: string, params?: Record<string, string | undefined>) =>\n requestRaw('GET', path, undefined, params),\n putRaw: (path: string, body: BodyInit, headers?: Record<string, string>) =>\n requestRaw('PUT', path, body, undefined, headers),\n };\n}\n","import { parse as parseToml, stringify as stringifyToml } from '@iarna/toml';\n\n// ---------------------------------------------------------------------------\n// Interfaces\n// ---------------------------------------------------------------------------\n\n/** Credential fields stored in `~/.db9/credentials` (TOML). */\nexport interface Credentials {\n token: string;\n is_anonymous?: boolean;\n anonymous_id?: string;\n anonymous_secret?: string;\n}\n\n/** Async credential persistence abstraction. */\nexport interface CredentialStore {\n load(): Promise<Credentials | null>;\n save(credentials: Credentials): Promise<void>;\n clear(): Promise<void>;\n}\n\n// ---------------------------------------------------------------------------\n// FileCredentialStore — TOML file at ~/.db9/credentials (matches db9 CLI)\n// ---------------------------------------------------------------------------\n\nexport class FileCredentialStore implements CredentialStore {\n private readonly customPath: string | undefined;\n\n /**\n * @param path — Override the credential file location.\n * Defaults to `~/.db9/credentials` (resolved lazily).\n */\n constructor(path?: string) {\n this.customPath = path;\n }\n\n /** Resolve the credential file path (lazy to avoid top-level `os` import). */\n private async resolvePath(): Promise<string> {\n if (this.customPath) return this.customPath;\n const os = await import('node:os');\n const nodePath = await import('node:path');\n return nodePath.join(os.homedir(), '.db9', 'credentials');\n }\n\n async load(): Promise<Credentials | null> {\n const fs = await import('node:fs/promises');\n const filePath = await this.resolvePath();\n\n let content: string;\n try {\n content = await fs.readFile(filePath, 'utf-8');\n } catch (err: unknown) {\n if ((err as NodeJS.ErrnoException).code === 'ENOENT') return null;\n throw err;\n }\n\n const parsed = parseToml(content);\n const token = parsed['token'];\n if (typeof token !== 'string') return null;\n\n const creds: Credentials = { token };\n if (typeof parsed['is_anonymous'] === 'boolean') {\n creds.is_anonymous = parsed['is_anonymous'];\n }\n if (typeof parsed['anonymous_id'] === 'string') {\n creds.anonymous_id = parsed['anonymous_id'];\n }\n if (typeof parsed['anonymous_secret'] === 'string') {\n creds.anonymous_secret = parsed['anonymous_secret'];\n }\n\n return creds;\n }\n\n async save(credentials: Credentials): Promise<void> {\n const fs = await import('node:fs/promises');\n const nodePath = await import('node:path');\n const filePath = await this.resolvePath();\n const dir = nodePath.dirname(filePath);\n\n // Ensure directory exists with 0o700 (matches CLI: ensure_config_dir)\n await fs.mkdir(dir, { recursive: true, mode: 0o700 });\n\n // Read → merge → write (preserves unknown fields as scalars)\n const data: Record<string, string | boolean | number> = {};\n try {\n const raw = await fs.readFile(filePath, 'utf-8');\n const parsed = parseToml(raw);\n for (const [k, v] of Object.entries(parsed)) {\n if (typeof v === 'string' || typeof v === 'boolean' || typeof v === 'number') {\n data[k] = v;\n }\n }\n } catch (err: unknown) {\n if ((err as NodeJS.ErrnoException).code !== 'ENOENT') throw err;\n }\n\n // Merge: always update token, only override optional fields when provided\n data['token'] = credentials.token;\n if (credentials.is_anonymous !== undefined) {\n data['is_anonymous'] = credentials.is_anonymous;\n }\n if (credentials.anonymous_id !== undefined) {\n data['anonymous_id'] = credentials.anonymous_id;\n }\n if (credentials.anonymous_secret !== undefined) {\n data['anonymous_secret'] = credentials.anonymous_secret;\n }\n\n // Serialize and write with 0o600 permissions (matches CLI: save_token)\n const toml = stringifyToml(\n data as Parameters<typeof stringifyToml>[0],\n );\n await fs.writeFile(filePath, toml, { mode: 0o600 });\n }\n\n async clear(): Promise<void> {\n const fs = await import('node:fs/promises');\n const filePath = await this.resolvePath();\n\n try {\n await fs.unlink(filePath);\n } catch (err: unknown) {\n if ((err as NodeJS.ErrnoException).code !== 'ENOENT') throw err;\n }\n }\n}\n\n// ---------------------------------------------------------------------------\n// MemoryCredentialStore — in-memory, no persistence\n// ---------------------------------------------------------------------------\n\nexport class MemoryCredentialStore implements CredentialStore {\n private credentials: Credentials | null = null;\n\n async load(): Promise<Credentials | null> {\n return this.credentials ? { ...this.credentials } : null;\n }\n\n async save(credentials: Credentials): Promise<void> {\n this.credentials = {\n token: credentials.token,\n is_anonymous: credentials.is_anonymous ?? this.credentials?.is_anonymous,\n anonymous_id: credentials.anonymous_id ?? this.credentials?.anonymous_id,\n anonymous_secret: credentials.anonymous_secret ?? this.credentials?.anonymous_secret,\n };\n }\n\n async clear(): Promise<void> {\n this.credentials = null;\n }\n}\n\n// ---------------------------------------------------------------------------\n// Factory\n// ---------------------------------------------------------------------------\n\n/** Returns a FileCredentialStore with the default path (`~/.db9/credentials`). */\nexport function defaultCredentialStore(): CredentialStore {\n return new FileCredentialStore();\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAO,IAAM,WAAN,MAAM,kBAAiB,MAAM;AAAA,EACzB;AAAA,EACA;AAAA,EAET,YAAY,SAAiB,YAAoB,UAAqB;AACpE,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,aAAa;AAClB,SAAK,WAAW;AAAA,EAClB;AAAA,EAEA,aAAa,aAAa,UAAuC;AAE/D,QAAI;AACJ,QAAI;AACF,YAAM,OAAQ,MAAM,SAAS,KAAK;AAClC,gBAAU,KAAK,WAAW,SAAS;AAAA,IACrC,QAAQ;AACN,gBAAU,SAAS;AAAA,IACrB;AAGA,YAAQ,SAAS,QAAQ;AAAA,MACvB,KAAK;AACH,eAAO,IAAI,aAAa,SAAS,QAAQ;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A,MAAM,OAAO,MAAc,SAAkC;AAC3D,cAAM,SAAS,IAAI,gBAAgB,EAAE,KAAK,CAAC;AAC3C,cAAM,WAAW,MAAM;AAAA,UACrB;AAAA,UACA;AAAA,UACA,aAAa,OAAO,SAAS,CAAC;AAAA,QAChC;AACA,eAAO,SAAS,KAAK;AAAA,MACvB;AAAA,MAEA,OAAO,OACL,MACA,MACA,YACkB;AAClB,cAAM,SAAS,IAAI,gBAAgB,EAAE,KAAK,CAAC;AAC3C,cAAM,UAAU,OAAO,MAAM,WAAW,OAAO,SAAS,CAAC,IAAI,OAAO;AAAA,MACtE;AAAA,MAEA,MAAM,OAAO,MAAc,SAA2C;AACpE,cAAM,SAAS,IAAI,gBAAgB,EAAE,KAAK,CAAC;AAC3C,cAAM,WAAW,MAAM;AAAA,UACrB;AAAA,UACA;AAAA,UACA,SAAS,OAAO,SAAS,CAAC;AAAA,QAC5B;AACA,eAAO,SAAS,KAAK;AAAA,MACvB;AAAA,IACF;AAAA,EACF;AACF;","names":["parseToml","stringifyToml","options"]}
@@ -0,0 +1 @@
1
+ export { y as Db9Client, z as Db9ClientOptions, ad as createDb9Client } from './client-fUeI7kwU.cjs';
@@ -0,0 +1 @@
1
+ export { y as Db9Client, z as Db9ClientOptions, ad as createDb9Client } from './client-fUeI7kwU.js';