hydrousdb 2.0.0 → 2.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +1048 -540
- package/dist/index.d.mts +526 -51
- package/dist/index.d.ts +526 -51
- package/dist/index.js +924 -644
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +914 -642
- package/dist/index.mjs.map +1 -1
- package/package.json +17 -51
- package/dist/analytics/index.d.mts +0 -185
- package/dist/analytics/index.d.ts +0 -185
- package/dist/analytics/index.js +0 -184
- package/dist/analytics/index.js.map +0 -1
- package/dist/analytics/index.mjs +0 -182
- package/dist/analytics/index.mjs.map +0 -1
- package/dist/auth/index.d.mts +0 -180
- package/dist/auth/index.d.ts +0 -180
- package/dist/auth/index.js +0 -220
- package/dist/auth/index.js.map +0 -1
- package/dist/auth/index.mjs +0 -218
- package/dist/auth/index.mjs.map +0 -1
- package/dist/http-DTukpdAU.d.mts +0 -470
- package/dist/http-DTukpdAU.d.ts +0 -470
- package/dist/records/index.d.mts +0 -137
- package/dist/records/index.d.ts +0 -137
- package/dist/records/index.js +0 -228
- package/dist/records/index.js.map +0 -1
- package/dist/records/index.mjs +0 -226
- package/dist/records/index.mjs.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,79 +1,554 @@
|
|
|
1
|
-
import { RecordsClient } from './records/index.js';
|
|
2
|
-
export { BucketOptions } from './records/index.js';
|
|
3
|
-
import { AuthClient } from './auth/index.js';
|
|
4
|
-
import { AnalyticsClient } from './analytics/index.js';
|
|
5
|
-
import { H as HydrousErrorBody, a as HydrousConfig } from './http-DTukpdAU.js';
|
|
6
|
-
export { A as AccountLockPayload, b as AccountLockResponse, c as AnalyticsQuery, d as AnalyticsQueryType, e as AnalyticsResponse, f as ApiMeta, g as AuthUser, B as BatchDeletePayload, h as BatchDeleteResponse, i as BatchInsertPayload, j as BatchInsertResponse, k as BatchResult, l as BatchUpdateItem, m as BatchUpdatePayload, n as BatchUpdateResponse, C as CountResult, D as DateRange, o as DeleteRecordResponse, p as DistributionItem, E as EmailVerifyConfirmPayload, q as EmailVerifyRequestPayload, F as FieldStatsResult, r as FieldTimeSeriesPoint, s as Filter, t as FilterOp, u as FilteredRecordsResult, G as GetRecordOptions, v as GetRecordResponse, w as GetSnapshotResponse, x as GetUserResponse, y as HistoryEntry, z as HydrousRecord, I as InsertRecordPayload, J as InsertRecordResponse, L as ListUsersResponse, M as MultiMetricItem, P as PaginationMeta, K as PasswordChangePayload, N as PasswordResetConfirmPayload, O as PasswordResetRequestPayload, Q as QueryOptions, R as QueryResponse, S as RecordData, T as RecordExistsInfo, U as RefreshSessionResponse, V as RequestOptions, W as SessionInfo, X as SignInPayload, Y as SignInResponse, Z as SignOutPayload, _ as SignUpPayload, $ as SignUpResponse, a0 as StorageStatsResult, a1 as SumResult, a2 as TimeSeriesPoint, a3 as TopNItem, a4 as UpdateRecordPayload, a5 as UpdateRecordResponse, a6 as UpdateUserPayload, a7 as UpdateUserResponse, a8 as ValidateSessionResponse } from './http-DTukpdAU.js';
|
|
7
|
-
|
|
8
1
|
/**
|
|
9
|
-
*
|
|
2
|
+
* Named storage keys.
|
|
3
|
+
* Create as many as you need in the HydrousDB dashboard and give each one a
|
|
4
|
+
* meaningful name — you'll reference it by name when calling storage methods.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* {
|
|
8
|
+
* main: 'ssk_main_…',
|
|
9
|
+
* avatars: 'ssk_avatars_…',
|
|
10
|
+
* documents: 'ssk_docs_…',
|
|
11
|
+
* }
|
|
10
12
|
*/
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
13
|
+
type StorageKeys = Record<string, string>;
|
|
14
|
+
interface HydrousConfig {
|
|
15
|
+
/** Your HydrousDB project base URL */
|
|
16
|
+
url: string;
|
|
17
|
+
/** Auth service key — used for all auth.* operations */
|
|
18
|
+
authKey: string;
|
|
19
|
+
/** Bucket security key — used for records.* and analytics.* operations */
|
|
20
|
+
bucketSecurityKey: string;
|
|
21
|
+
/**
|
|
22
|
+
* Storage keys object. Each property name is a label you choose; each
|
|
23
|
+
* value is a storage key (ssk_…) from your dashboard.
|
|
24
|
+
* You can have as many as you need.
|
|
25
|
+
*/
|
|
26
|
+
storageKeys: StorageKeys;
|
|
27
|
+
/** Optional global request timeout in milliseconds (default: 30 000) */
|
|
28
|
+
timeout?: number;
|
|
21
29
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
30
|
+
interface HydrousResponse<T = unknown> {
|
|
31
|
+
data: T | null;
|
|
32
|
+
error: HydrousError | null;
|
|
33
|
+
}
|
|
34
|
+
interface HydrousError {
|
|
35
|
+
message: string;
|
|
36
|
+
code: string;
|
|
37
|
+
status?: number;
|
|
38
|
+
}
|
|
39
|
+
type FilterOperator = 'eq' | 'neq' | 'gt' | 'gte' | 'lt' | 'lte' | 'like' | 'ilike' | 'in' | 'nin' | 'is' | 'not';
|
|
40
|
+
interface Filter {
|
|
41
|
+
field: string;
|
|
42
|
+
operator: FilterOperator;
|
|
43
|
+
value: unknown;
|
|
44
|
+
}
|
|
45
|
+
interface QueryOptions {
|
|
46
|
+
where?: Filter | Filter[];
|
|
47
|
+
orderBy?: {
|
|
48
|
+
field: string;
|
|
49
|
+
direction?: 'asc' | 'desc';
|
|
50
|
+
};
|
|
51
|
+
limit?: number;
|
|
52
|
+
offset?: number;
|
|
53
|
+
select?: string[];
|
|
54
|
+
}
|
|
55
|
+
interface RecordResponse<T = Record<string, unknown>> {
|
|
56
|
+
data: T[];
|
|
57
|
+
count: number;
|
|
58
|
+
error: HydrousError | null;
|
|
59
|
+
}
|
|
60
|
+
interface SingleRecordResponse<T = Record<string, unknown>> {
|
|
61
|
+
data: T | null;
|
|
62
|
+
error: HydrousError | null;
|
|
63
|
+
}
|
|
64
|
+
interface AuthUser {
|
|
65
|
+
id: string;
|
|
66
|
+
email: string;
|
|
67
|
+
createdAt: string;
|
|
68
|
+
updatedAt: string;
|
|
69
|
+
metadata?: Record<string, unknown>;
|
|
70
|
+
}
|
|
71
|
+
interface AuthSession {
|
|
72
|
+
accessToken: string;
|
|
73
|
+
refreshToken: string;
|
|
74
|
+
expiresAt: number;
|
|
75
|
+
user: AuthUser;
|
|
76
|
+
}
|
|
77
|
+
interface SignUpOptions {
|
|
78
|
+
email: string;
|
|
79
|
+
password: string;
|
|
80
|
+
metadata?: Record<string, unknown>;
|
|
81
|
+
}
|
|
82
|
+
interface SignInOptions {
|
|
83
|
+
email: string;
|
|
84
|
+
password: string;
|
|
85
|
+
}
|
|
86
|
+
interface TrackEventOptions {
|
|
87
|
+
event: string;
|
|
88
|
+
properties?: Record<string, unknown>;
|
|
89
|
+
userId?: string;
|
|
90
|
+
sessionId?: string;
|
|
91
|
+
timestamp?: number;
|
|
92
|
+
}
|
|
93
|
+
interface AnalyticsQueryOptions {
|
|
94
|
+
event?: string;
|
|
95
|
+
from?: string;
|
|
96
|
+
to?: string;
|
|
97
|
+
limit?: number;
|
|
98
|
+
groupBy?: string;
|
|
99
|
+
}
|
|
100
|
+
interface AnalyticsEvent {
|
|
101
|
+
id: string;
|
|
102
|
+
event: string;
|
|
103
|
+
properties: Record<string, unknown>;
|
|
104
|
+
userId?: string;
|
|
105
|
+
sessionId?: string;
|
|
106
|
+
timestamp: number;
|
|
28
107
|
}
|
|
108
|
+
type UploadStage = 'pending' | 'compressing' | 'uploading' | 'done' | 'error';
|
|
109
|
+
interface UploadProgress {
|
|
110
|
+
/** 0-based file index (always 0 for single uploads) */
|
|
111
|
+
index: number;
|
|
112
|
+
/** Total files in the operation */
|
|
113
|
+
total: number;
|
|
114
|
+
/** Destination path in the bucket */
|
|
115
|
+
path: string;
|
|
116
|
+
/** Current lifecycle stage */
|
|
117
|
+
stage: UploadStage;
|
|
118
|
+
bytesUploaded: number;
|
|
119
|
+
totalBytes: number;
|
|
120
|
+
/** 0 – 100 */
|
|
121
|
+
percent: number;
|
|
122
|
+
/** Upload speed in bytes/sec; null until the first tick */
|
|
123
|
+
bytesPerSecond: number | null;
|
|
124
|
+
/** Estimated seconds remaining; null until speed is known */
|
|
125
|
+
eta: number | null;
|
|
126
|
+
result?: UploadResult;
|
|
127
|
+
error?: string;
|
|
128
|
+
code?: string;
|
|
129
|
+
}
|
|
130
|
+
interface DownloadProgress {
|
|
131
|
+
index: number;
|
|
132
|
+
total: number;
|
|
133
|
+
path: string;
|
|
134
|
+
status: 'pending' | 'success' | 'error';
|
|
135
|
+
size?: number;
|
|
136
|
+
mimeType?: string;
|
|
137
|
+
error?: string;
|
|
138
|
+
}
|
|
139
|
+
interface UploadResult {
|
|
140
|
+
path: string;
|
|
141
|
+
compressed: boolean;
|
|
142
|
+
originalSize: number;
|
|
143
|
+
storedSize: number;
|
|
144
|
+
spaceSaved: number;
|
|
145
|
+
mimeType: string;
|
|
146
|
+
}
|
|
147
|
+
interface FileMetadata {
|
|
148
|
+
path: string;
|
|
149
|
+
name: string;
|
|
150
|
+
size: number | null;
|
|
151
|
+
originalSize: number | null;
|
|
152
|
+
mimeType: string | null;
|
|
153
|
+
isCompressed: boolean;
|
|
154
|
+
md5Hash: string | null;
|
|
155
|
+
updatedAt: string | null;
|
|
156
|
+
createdAt: string | null;
|
|
157
|
+
}
|
|
158
|
+
interface StorageItem {
|
|
159
|
+
name: string;
|
|
160
|
+
path: string;
|
|
161
|
+
type: 'file' | 'folder';
|
|
162
|
+
size?: number | null;
|
|
163
|
+
storedSize?: number | null;
|
|
164
|
+
mimeType?: string | null;
|
|
165
|
+
isCompressed?: boolean;
|
|
166
|
+
updatedAt?: string | null;
|
|
167
|
+
createdAt?: string | null;
|
|
168
|
+
md5Hash?: string | null;
|
|
169
|
+
}
|
|
170
|
+
interface ListResult {
|
|
171
|
+
items: StorageItem[];
|
|
172
|
+
pagination: {
|
|
173
|
+
limit: number;
|
|
174
|
+
count: number;
|
|
175
|
+
hasNextPage: boolean;
|
|
176
|
+
nextCursor: string | null;
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
interface SignedUrlResult {
|
|
180
|
+
signedUrl: string;
|
|
181
|
+
expiresAt: string;
|
|
182
|
+
expiresIn: number;
|
|
183
|
+
path: string;
|
|
184
|
+
}
|
|
185
|
+
interface BatchUploadResult {
|
|
186
|
+
succeeded: UploadResult[];
|
|
187
|
+
failed: Array<{
|
|
188
|
+
path: string;
|
|
189
|
+
error: string;
|
|
190
|
+
code: string;
|
|
191
|
+
}>;
|
|
192
|
+
}
|
|
193
|
+
interface BatchDownloadFile {
|
|
194
|
+
path: string;
|
|
195
|
+
content: ArrayBuffer;
|
|
196
|
+
mimeType: string;
|
|
197
|
+
size: number;
|
|
198
|
+
}
|
|
199
|
+
interface StorageStats {
|
|
200
|
+
totalFiles: number;
|
|
201
|
+
totalSizeBytes: number;
|
|
202
|
+
totalOriginalSizeBytes: number;
|
|
203
|
+
spaceSavedBytes: number;
|
|
204
|
+
uploadsCount: number;
|
|
205
|
+
downloadsCount: number;
|
|
206
|
+
deletesCount: number;
|
|
207
|
+
creditsUsedUpload: number;
|
|
208
|
+
creditsUsedDownload: number;
|
|
209
|
+
creditsTotalUsed: number;
|
|
210
|
+
bytesDelivered: number;
|
|
211
|
+
compressionRatio: string;
|
|
212
|
+
}
|
|
213
|
+
interface UploadOptions {
|
|
214
|
+
/** Destination path in the bucket (defaults to the file's original name) */
|
|
215
|
+
path?: string;
|
|
216
|
+
/** Replace the file if it already exists (default: false) */
|
|
217
|
+
overwrite?: boolean;
|
|
218
|
+
/**
|
|
219
|
+
* Called on every progress tick.
|
|
220
|
+
* Use this to drive progress bars, speed displays, and ETAs.
|
|
221
|
+
*/
|
|
222
|
+
onProgress?: (progress: UploadProgress) => void;
|
|
223
|
+
}
|
|
224
|
+
interface BatchUploadOptions {
|
|
225
|
+
/** Folder prefix prepended to every filename */
|
|
226
|
+
prefix?: string;
|
|
227
|
+
/** Per-file paths (same order as the `files` array; takes priority over prefix) */
|
|
228
|
+
paths?: string[];
|
|
229
|
+
overwrite?: boolean;
|
|
230
|
+
/** Max simultaneous server-side uploads (1–10, default 5) */
|
|
231
|
+
concurrency?: number;
|
|
232
|
+
/** Called for every progress tick on every file */
|
|
233
|
+
onProgress?: (progress: UploadProgress) => void;
|
|
234
|
+
}
|
|
235
|
+
interface BatchDownloadOptions {
|
|
236
|
+
concurrency?: number;
|
|
237
|
+
onProgress?: (progress: DownloadProgress) => void;
|
|
238
|
+
/**
|
|
239
|
+
* Browser only — automatically triggers a Save dialog for each file as it
|
|
240
|
+
* arrives (default: false)
|
|
241
|
+
*/
|
|
242
|
+
autoSave?: boolean;
|
|
243
|
+
}
|
|
244
|
+
interface ListOptions {
|
|
245
|
+
/** Folder prefix to list (empty = bucket root) */
|
|
246
|
+
prefix?: string;
|
|
247
|
+
limit?: number;
|
|
248
|
+
cursor?: string;
|
|
249
|
+
}
|
|
250
|
+
interface SignedUrlOptions {
|
|
251
|
+
/** How long the URL stays valid in seconds (default: 3600) */
|
|
252
|
+
expiresIn?: number;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
declare class AuthClient {
|
|
256
|
+
private readonly baseUrl;
|
|
257
|
+
private readonly headers;
|
|
258
|
+
private session;
|
|
259
|
+
constructor(config: HydrousConfig);
|
|
260
|
+
/** Create a new user account */
|
|
261
|
+
signUp(options: SignUpOptions): Promise<HydrousResponse<AuthSession>>;
|
|
262
|
+
/** Sign in with email and password */
|
|
263
|
+
signIn(options: SignInOptions): Promise<HydrousResponse<AuthSession>>;
|
|
264
|
+
/** Sign out and invalidate the current session */
|
|
265
|
+
signOut(): Promise<HydrousResponse<void>>;
|
|
266
|
+
/** Get the currently authenticated user */
|
|
267
|
+
getUser(): Promise<HydrousResponse<AuthUser>>;
|
|
268
|
+
/** Refresh the access token using the stored refresh token */
|
|
269
|
+
refreshSession(): Promise<HydrousResponse<AuthSession>>;
|
|
270
|
+
/** Return the current in-memory session (may be null) */
|
|
271
|
+
getSession(): AuthSession | null;
|
|
272
|
+
private _sessionHeader;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
declare class RecordsClient {
|
|
276
|
+
private readonly baseUrl;
|
|
277
|
+
private readonly headers;
|
|
278
|
+
constructor(config: HydrousConfig);
|
|
279
|
+
/** Query records from a collection */
|
|
280
|
+
select<T = Record<string, unknown>>(collection: string, options?: QueryOptions): Promise<RecordResponse<T>>;
|
|
281
|
+
/** Fetch a single record by ID */
|
|
282
|
+
get<T = Record<string, unknown>>(collection: string, id: string): Promise<SingleRecordResponse<T>>;
|
|
283
|
+
/** Insert one or more records */
|
|
284
|
+
insert<T = Record<string, unknown>>(collection: string, payload: Partial<T> | Partial<T>[]): Promise<RecordResponse<T>>;
|
|
285
|
+
/** Update a record by ID */
|
|
286
|
+
update<T = Record<string, unknown>>(collection: string, id: string, payload: Partial<T>): Promise<SingleRecordResponse<T>>;
|
|
287
|
+
/** Delete a record by ID */
|
|
288
|
+
delete(collection: string, id: string): Promise<SingleRecordResponse<void>>;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
declare class AnalyticsClient {
|
|
292
|
+
private readonly baseUrl;
|
|
293
|
+
private readonly headers;
|
|
294
|
+
constructor(config: HydrousConfig);
|
|
295
|
+
/** Track a single analytics event */
|
|
296
|
+
track(options: TrackEventOptions): Promise<HydrousResponse<void>>;
|
|
297
|
+
/** Track many events in one request */
|
|
298
|
+
trackBatch(events: TrackEventOptions[]): Promise<HydrousResponse<void>>;
|
|
299
|
+
/** Query recorded analytics events */
|
|
300
|
+
query(options?: AnalyticsQueryOptions): Promise<RecordResponse<AnalyticsEvent>>;
|
|
301
|
+
}
|
|
302
|
+
|
|
29
303
|
/**
|
|
30
|
-
*
|
|
304
|
+
* A storage client that is already bound to a specific storage key.
|
|
305
|
+
* You get one of these by calling `db.storage('keyName')`.
|
|
306
|
+
*
|
|
307
|
+
* None of the methods on this class require you to pass a bucket key —
|
|
308
|
+
* it's already baked in.
|
|
31
309
|
*/
|
|
32
|
-
declare class
|
|
33
|
-
|
|
310
|
+
declare class ScopedStorageClient {
|
|
311
|
+
private readonly base;
|
|
312
|
+
private readonly key;
|
|
313
|
+
readonly keyName: string;
|
|
314
|
+
constructor(baseUrl: string, keyName: string, bucketKey: string);
|
|
315
|
+
/**
|
|
316
|
+
* Upload a single file.
|
|
317
|
+
*
|
|
318
|
+
* Supply `onProgress` to receive live upload ticks including bytes
|
|
319
|
+
* transferred, speed (bytes/sec), ETA, and lifecycle stage.
|
|
320
|
+
*
|
|
321
|
+
* **Stage sequence:**
|
|
322
|
+
* `pending → compressing → uploading → done | error`
|
|
323
|
+
*
|
|
324
|
+
* In browsers the progress is tracked at the network level via XHR, so
|
|
325
|
+
* `percent` reflects actual bytes leaving the device. `done` only fires
|
|
326
|
+
* after the server confirms the write to cloud storage, so 100% is real.
|
|
327
|
+
*
|
|
328
|
+
* @example
|
|
329
|
+
* const { data, error } = await db.storage('avatars').upload(file, {
|
|
330
|
+
* path: 'users/alice.jpg',
|
|
331
|
+
* overwrite: true,
|
|
332
|
+
* onProgress: (p) => {
|
|
333
|
+
* setProgress(p.percent); // e.g. drive a <progress> bar
|
|
334
|
+
* setSpeed(`${p.bytesPerSecond} B/s`);
|
|
335
|
+
* setEta(`${p.eta}s remaining`);
|
|
336
|
+
* },
|
|
337
|
+
* });
|
|
338
|
+
*/
|
|
339
|
+
upload(file: File | Blob | Uint8Array | ArrayBuffer, options?: UploadOptions): Promise<HydrousResponse<UploadResult>>;
|
|
340
|
+
/**
|
|
341
|
+
* Upload raw text or JSON content directly — no File object needed.
|
|
342
|
+
*
|
|
343
|
+
* @example
|
|
344
|
+
* // Save a JSON config
|
|
345
|
+
* await db.storage('configs').uploadText(
|
|
346
|
+
* 'settings/app.json',
|
|
347
|
+
* JSON.stringify({ theme: 'dark' }),
|
|
348
|
+
* { mimeType: 'application/json' }
|
|
349
|
+
* );
|
|
350
|
+
*/
|
|
351
|
+
uploadText(path: string, content: string, options?: {
|
|
352
|
+
mimeType?: string;
|
|
353
|
+
overwrite?: boolean;
|
|
354
|
+
onProgress?: UploadOptions['onProgress'];
|
|
355
|
+
}): Promise<HydrousResponse<UploadResult>>;
|
|
356
|
+
/**
|
|
357
|
+
* Upload multiple files in one request.
|
|
358
|
+
*
|
|
359
|
+
* `onProgress` fires per file — use `p.index` to identify which file.
|
|
360
|
+
* All files receive a `pending` event upfront so you can render progress
|
|
361
|
+
* bars immediately before any data is sent.
|
|
362
|
+
*
|
|
363
|
+
* @example
|
|
364
|
+
* await db.storage('documents').batchUpload(files, {
|
|
365
|
+
* prefix: 'reports/2024/',
|
|
366
|
+
* onProgress: (p) => updateBar(p.index, p.percent),
|
|
367
|
+
* });
|
|
368
|
+
*/
|
|
369
|
+
batchUpload(files: File[], options?: BatchUploadOptions): Promise<HydrousResponse<BatchUploadResult>>;
|
|
370
|
+
/**
|
|
371
|
+
* Download a single file and return its content as an `ArrayBuffer`.
|
|
372
|
+
*
|
|
373
|
+
* @example
|
|
374
|
+
* const { data } = await db.storage('avatars').download('users/alice.jpg');
|
|
375
|
+
* const blob = new Blob([data!]);
|
|
376
|
+
* img.src = URL.createObjectURL(blob);
|
|
377
|
+
*/
|
|
378
|
+
download(filePath: string): Promise<HydrousResponse<ArrayBuffer>>;
|
|
379
|
+
/**
|
|
380
|
+
* Download multiple files in one request.
|
|
381
|
+
*
|
|
382
|
+
* Set `autoSave: true` (browser only) to trigger a Save dialog per file.
|
|
383
|
+
*
|
|
384
|
+
* @example
|
|
385
|
+
* const { data } = await db.storage('reports').batchDownload(
|
|
386
|
+
* ['jan.pdf', 'feb.pdf'],
|
|
387
|
+
* { autoSave: true, onProgress: (p) => console.log(p.path, p.status) }
|
|
388
|
+
* );
|
|
389
|
+
*/
|
|
390
|
+
batchDownload(filePaths: string[], options?: BatchDownloadOptions): Promise<HydrousResponse<BatchDownloadFile[]>>;
|
|
391
|
+
/**
|
|
392
|
+
* List files and folders (paginated).
|
|
393
|
+
*
|
|
394
|
+
* @example
|
|
395
|
+
* const { data } = await db.storage('avatars').list({ prefix: 'users/' });
|
|
396
|
+
* for (const item of data!.items) {
|
|
397
|
+
* console.log(item.type, item.path, item.size);
|
|
398
|
+
* }
|
|
399
|
+
*/
|
|
400
|
+
list(options?: ListOptions): Promise<HydrousResponse<ListResult>>;
|
|
401
|
+
/**
|
|
402
|
+
* Get metadata for a file (size, MIME type, compression, etc.)
|
|
403
|
+
*
|
|
404
|
+
* @example
|
|
405
|
+
* const { data: meta } = await db.storage('docs').metadata('report.pdf');
|
|
406
|
+
* console.log(meta!.size, meta!.mimeType, meta!.isCompressed);
|
|
407
|
+
*/
|
|
408
|
+
metadata(filePath: string): Promise<HydrousResponse<FileMetadata>>;
|
|
409
|
+
/** Delete a single file */
|
|
410
|
+
deleteFile(filePath: string): Promise<HydrousResponse<void>>;
|
|
411
|
+
/** Recursively delete a folder and all its contents */
|
|
412
|
+
deleteFolder(folderPath: string): Promise<HydrousResponse<void>>;
|
|
413
|
+
/** Create an empty folder */
|
|
414
|
+
createFolder(folderPath: string): Promise<HydrousResponse<void>>;
|
|
415
|
+
/** Move (rename) a file */
|
|
416
|
+
move(fromPath: string, toPath: string): Promise<HydrousResponse<void>>;
|
|
417
|
+
/** Copy a file (original is kept) */
|
|
418
|
+
copy(fromPath: string, toPath: string): Promise<HydrousResponse<void>>;
|
|
419
|
+
/**
|
|
420
|
+
* Generate a time-limited public URL for a private file.
|
|
421
|
+
*
|
|
422
|
+
* @example
|
|
423
|
+
* const { data } = await db.storage('contracts').signedUrl('nda.pdf', { expiresIn: 300 });
|
|
424
|
+
* console.log(data!.signedUrl); // share this
|
|
425
|
+
*/
|
|
426
|
+
signedUrl(filePath: string, options?: SignedUrlOptions): Promise<HydrousResponse<SignedUrlResult>>;
|
|
427
|
+
/**
|
|
428
|
+
* Get usage and billing stats for this storage key.
|
|
429
|
+
*
|
|
430
|
+
* @example
|
|
431
|
+
* const { data } = await db.storage('main').stats();
|
|
432
|
+
* console.log(data!.totalFiles, data!.totalSizeBytes);
|
|
433
|
+
*/
|
|
434
|
+
stats(): Promise<HydrousResponse<StorageStats>>;
|
|
34
435
|
}
|
|
35
436
|
|
|
437
|
+
interface CallableStorage {
|
|
438
|
+
/** Get a scoped storage client by key name */
|
|
439
|
+
(keyName: string): ScopedStorageClient;
|
|
440
|
+
/** Same as calling db.storage(keyName) — more explicit */
|
|
441
|
+
use(keyName: string): ScopedStorageClient;
|
|
442
|
+
/** Return names of all configured storage keys */
|
|
443
|
+
keyNames(): string[];
|
|
444
|
+
}
|
|
36
445
|
/**
|
|
37
|
-
* The
|
|
446
|
+
* The HydrousDB root client.
|
|
38
447
|
*
|
|
39
|
-
*
|
|
40
|
-
* Every records and analytics call then takes a `bucketKey` option
|
|
41
|
-
* so a single client instance can work across multiple buckets.
|
|
448
|
+
* Create once and reuse across your app:
|
|
42
449
|
*
|
|
43
|
-
*
|
|
450
|
+
* ```ts
|
|
44
451
|
* import { createClient } from 'hydrousdb';
|
|
45
452
|
*
|
|
46
453
|
* const db = createClient({
|
|
47
|
-
*
|
|
48
|
-
*
|
|
454
|
+
* url: 'https://api.myapp.hydrous.app',
|
|
455
|
+
* authKey: 'hk_auth_…',
|
|
456
|
+
* bucketSecurityKey: 'hk_bucket_…',
|
|
457
|
+
* storageKeys: {
|
|
458
|
+
* main: 'ssk_main_…',
|
|
459
|
+
* avatars: 'ssk_avatars_…',
|
|
460
|
+
* documents: 'ssk_docs_…',
|
|
461
|
+
* },
|
|
49
462
|
* });
|
|
50
|
-
*
|
|
51
|
-
* // Records — pass bucketKey on every call
|
|
52
|
-
* const { data } = await db.records.get('rec_abc123', { bucketKey: 'users' });
|
|
53
|
-
* await db.records.insert({ values: { name: 'Alice' } }, { bucketKey: 'users' });
|
|
54
|
-
*
|
|
55
|
-
* // Auth — no bucketKey needed
|
|
56
|
-
* const { data, session } = await db.auth.signIn({ email: 'a@b.com', password: '...' });
|
|
57
|
-
*
|
|
58
|
-
* // Analytics — pass bucketKey on every call
|
|
59
|
-
* const { data } = await db.analytics.count({ bucketKey: 'orders' });
|
|
463
|
+
* ```
|
|
60
464
|
*/
|
|
61
465
|
declare class HydrousClient {
|
|
62
|
-
/**
|
|
63
|
-
readonly records: RecordsClient;
|
|
64
|
-
/** User authentication and session management */
|
|
466
|
+
/** Auth — sign up, sign in, sign out, session management */
|
|
65
467
|
readonly auth: AuthClient;
|
|
66
|
-
/**
|
|
468
|
+
/** Records — insert, select, update, delete structured data */
|
|
469
|
+
readonly records: RecordsClient;
|
|
470
|
+
/** Analytics — track events and query history */
|
|
67
471
|
readonly analytics: AnalyticsClient;
|
|
68
|
-
|
|
472
|
+
/**
|
|
473
|
+
* Storage — call with the name of the key you want.
|
|
474
|
+
*
|
|
475
|
+
* ```ts
|
|
476
|
+
* db.storage('avatars').upload(file, { path: 'user.jpg' })
|
|
477
|
+
* db.storage('documents').list({ prefix: 'invoices/' })
|
|
478
|
+
* db.storage('main').stats()
|
|
479
|
+
* ```
|
|
480
|
+
*/
|
|
481
|
+
readonly storage: CallableStorage;
|
|
482
|
+
constructor(config: HydrousConfig);
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
/**
|
|
486
|
+
* StorageManager is the object exposed as `db.storage`.
|
|
487
|
+
*
|
|
488
|
+
* Call `.use(keyName)` — or use the shorthand `db.storage('keyName')` which
|
|
489
|
+
* the main HydrousClient wires up as a Proxy — to get a scoped storage client
|
|
490
|
+
* bound to that key.
|
|
491
|
+
*
|
|
492
|
+
* ```ts
|
|
493
|
+
* db.storage('main').upload(file)
|
|
494
|
+
* db.storage('avatars').list()
|
|
495
|
+
* db.storage('documents').download('report.pdf')
|
|
496
|
+
* ```
|
|
497
|
+
*/
|
|
498
|
+
declare class StorageManager {
|
|
499
|
+
private readonly baseUrl;
|
|
500
|
+
private readonly _keys;
|
|
501
|
+
private readonly cache;
|
|
69
502
|
constructor(config: HydrousConfig);
|
|
503
|
+
/**
|
|
504
|
+
* Get a storage client scoped to a named key.
|
|
505
|
+
*
|
|
506
|
+
* @param keyName - Must match a property you declared in `storageKeys`
|
|
507
|
+
*
|
|
508
|
+
* @example
|
|
509
|
+
* const avatarStore = db.storage('avatars');
|
|
510
|
+
* const documentStore = db.storage('documents');
|
|
511
|
+
*
|
|
512
|
+
* await avatarStore.upload(file, { path: 'users/alice.jpg' });
|
|
513
|
+
* const list = await documentStore.list({ prefix: 'invoices/' });
|
|
514
|
+
*/
|
|
515
|
+
use(keyName: string): ScopedStorageClient;
|
|
516
|
+
/** Return the names of all configured storage keys */
|
|
517
|
+
keyNames(): string[];
|
|
70
518
|
}
|
|
519
|
+
|
|
520
|
+
declare const eq: (field: string, value: unknown) => Filter;
|
|
521
|
+
declare const neq: (field: string, value: unknown) => Filter;
|
|
522
|
+
declare const gt: (field: string, value: unknown) => Filter;
|
|
523
|
+
declare const lt: (field: string, value: unknown) => Filter;
|
|
524
|
+
declare const gte: (field: string, value: unknown) => Filter;
|
|
525
|
+
declare const lte: (field: string, value: unknown) => Filter;
|
|
526
|
+
declare const inArray: (field: string, value: unknown[]) => Filter;
|
|
527
|
+
|
|
528
|
+
declare class HydrousDBError extends Error {
|
|
529
|
+
readonly code: string;
|
|
530
|
+
readonly status: number | undefined;
|
|
531
|
+
constructor(message: string, code?: string, status?: number);
|
|
532
|
+
}
|
|
533
|
+
declare function isHydrousError(err: unknown): err is HydrousDBError;
|
|
534
|
+
|
|
71
535
|
/**
|
|
72
536
|
* Create a HydrousDB client.
|
|
73
537
|
*
|
|
74
538
|
* @example
|
|
75
|
-
*
|
|
539
|
+
* import { createClient } from 'hydrousdb';
|
|
540
|
+
*
|
|
541
|
+
* const db = createClient({
|
|
542
|
+
* url: 'https://api.myapp.hydrous.app',
|
|
543
|
+
* authKey: 'hk_auth_…',
|
|
544
|
+
* bucketSecurityKey: 'hk_bucket_…',
|
|
545
|
+
* storageKeys: {
|
|
546
|
+
* main: 'ssk_main_…',
|
|
547
|
+
* avatars: 'ssk_avatars_…',
|
|
548
|
+
* documents: 'ssk_docs_…',
|
|
549
|
+
* },
|
|
550
|
+
* });
|
|
76
551
|
*/
|
|
77
552
|
declare function createClient(config: HydrousConfig): HydrousClient;
|
|
78
553
|
|
|
79
|
-
export { AnalyticsClient, AuthClient, HydrousClient, HydrousConfig, HydrousError,
|
|
554
|
+
export { AnalyticsClient, type AnalyticsEvent, type AnalyticsQueryOptions, AuthClient, type AuthSession, type AuthUser, type BatchDownloadFile, type BatchDownloadOptions, type BatchUploadOptions, type BatchUploadResult, type CallableStorage, type DownloadProgress, type FileMetadata, type Filter, type FilterOperator, HydrousClient, type HydrousConfig, HydrousDBError, type HydrousError, type HydrousResponse, type ListOptions, type ListResult, type QueryOptions, type RecordResponse, RecordsClient, ScopedStorageClient, type SignInOptions, type SignUpOptions, type SignedUrlOptions, type SignedUrlResult, type SingleRecordResponse, type StorageItem, type StorageKeys, StorageManager, type StorageStats, type TrackEventOptions, type UploadOptions, type UploadProgress, type UploadResult, type UploadStage, createClient, eq, gt, gte, inArray, isHydrousError, lt, lte, neq };
|