hydrousdb 1.1.1 → 2.0.1
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 +528 -484
- package/dist/index.d.mts +689 -51
- package/dist/index.d.ts +689 -51
- package/dist/index.js +1114 -619
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1107 -617
- package/dist/index.mjs.map +1 -1
- package/package.json +15 -37
- package/dist/analytics/index.d.mts +0 -178
- package/dist/analytics/index.d.ts +0 -178
- package/dist/analytics/index.js +0 -221
- package/dist/analytics/index.js.map +0 -1
- package/dist/analytics/index.mjs +0 -219
- 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-DbiqdKlw.d.mts +0 -466
- package/dist/http-DbiqdKlw.d.ts +0 -466
- package/dist/records/index.d.mts +0 -124
- package/dist/records/index.d.ts +0 -124
- package/dist/records/index.js +0 -226
- package/dist/records/index.js.map +0 -1
- package/dist/records/index.mjs +0 -224
- package/dist/records/index.mjs.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,73 +1,711 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
interface HydrousConfig {
|
|
2
|
+
/** Your Hydrous project URL e.g. https://api.yourapp.hydrous.app */
|
|
3
|
+
url: string;
|
|
4
|
+
/** Your project API key */
|
|
5
|
+
apiKey: string;
|
|
6
|
+
/** Optional default request timeout in milliseconds (default: 30_000) */
|
|
7
|
+
timeout?: number;
|
|
8
|
+
}
|
|
9
|
+
interface HydrousResponse<T = unknown> {
|
|
10
|
+
data: T | null;
|
|
11
|
+
error: HydrousError | null;
|
|
12
|
+
}
|
|
13
|
+
interface HydrousError {
|
|
14
|
+
message: string;
|
|
15
|
+
code: string;
|
|
16
|
+
status?: number;
|
|
17
|
+
}
|
|
18
|
+
type FilterOperator = 'eq' | 'neq' | 'gt' | 'gte' | 'lt' | 'lte' | 'like' | 'ilike' | 'in' | 'nin' | 'is' | 'not';
|
|
19
|
+
interface Filter {
|
|
20
|
+
field: string;
|
|
21
|
+
operator: FilterOperator;
|
|
22
|
+
value: unknown;
|
|
23
|
+
}
|
|
24
|
+
interface QueryOptions {
|
|
25
|
+
where?: Filter | Filter[];
|
|
26
|
+
orderBy?: {
|
|
27
|
+
field: string;
|
|
28
|
+
direction?: 'asc' | 'desc';
|
|
29
|
+
};
|
|
30
|
+
limit?: number;
|
|
31
|
+
offset?: number;
|
|
32
|
+
select?: string[];
|
|
33
|
+
}
|
|
34
|
+
interface RecordResponse<T = Record<string, unknown>> {
|
|
35
|
+
data: T[];
|
|
36
|
+
count: number;
|
|
37
|
+
error: HydrousError | null;
|
|
38
|
+
}
|
|
39
|
+
interface SingleRecordResponse<T = Record<string, unknown>> {
|
|
40
|
+
data: T | null;
|
|
41
|
+
error: HydrousError | null;
|
|
42
|
+
}
|
|
43
|
+
interface AuthUser {
|
|
44
|
+
id: string;
|
|
45
|
+
email: string;
|
|
46
|
+
createdAt: string;
|
|
47
|
+
updatedAt: string;
|
|
48
|
+
metadata?: Record<string, unknown>;
|
|
49
|
+
}
|
|
50
|
+
interface AuthSession {
|
|
51
|
+
accessToken: string;
|
|
52
|
+
refreshToken: string;
|
|
53
|
+
expiresAt: number;
|
|
54
|
+
user: AuthUser;
|
|
55
|
+
}
|
|
56
|
+
interface SignUpOptions {
|
|
57
|
+
email: string;
|
|
58
|
+
password: string;
|
|
59
|
+
metadata?: Record<string, unknown>;
|
|
60
|
+
}
|
|
61
|
+
interface SignInOptions {
|
|
62
|
+
email: string;
|
|
63
|
+
password: string;
|
|
64
|
+
}
|
|
65
|
+
interface TrackEventOptions {
|
|
66
|
+
event: string;
|
|
67
|
+
properties?: Record<string, unknown>;
|
|
68
|
+
userId?: string;
|
|
69
|
+
sessionId?: string;
|
|
70
|
+
timestamp?: number;
|
|
71
|
+
}
|
|
72
|
+
interface AnalyticsQueryOptions {
|
|
73
|
+
event?: string;
|
|
74
|
+
from?: string;
|
|
75
|
+
to?: string;
|
|
76
|
+
limit?: number;
|
|
77
|
+
groupBy?: string;
|
|
78
|
+
}
|
|
79
|
+
interface AnalyticsEvent {
|
|
80
|
+
id: string;
|
|
81
|
+
event: string;
|
|
82
|
+
properties: Record<string, unknown>;
|
|
83
|
+
userId?: string;
|
|
84
|
+
sessionId?: string;
|
|
85
|
+
timestamp: number;
|
|
86
|
+
}
|
|
87
|
+
/** The bucket key (ssk_…) that authorizes access to a specific storage bucket */
|
|
88
|
+
type BucketKey = string;
|
|
89
|
+
type UploadStage = 'pending' | 'compressing' | 'uploading' | 'done' | 'error';
|
|
90
|
+
/** Fired for every progress tick during an upload */
|
|
91
|
+
interface UploadProgress {
|
|
92
|
+
/** 0-based index (always 0 for single uploads) */
|
|
93
|
+
index: number;
|
|
94
|
+
/** Total files in this operation */
|
|
95
|
+
total: number;
|
|
96
|
+
/** Destination path (relative to your bucket root) */
|
|
97
|
+
path: string;
|
|
98
|
+
/** Current lifecycle stage */
|
|
99
|
+
stage: UploadStage;
|
|
100
|
+
/** Bytes sent to the server so far */
|
|
101
|
+
bytesUploaded: number;
|
|
102
|
+
/** Total bytes to send */
|
|
103
|
+
totalBytes: number;
|
|
104
|
+
/** 0–100 integer */
|
|
105
|
+
percent: number;
|
|
106
|
+
/** Upload speed in bytes/second – null before the first tick */
|
|
107
|
+
bytesPerSecond: number | null;
|
|
108
|
+
/** Estimated seconds remaining – null until speed is known */
|
|
109
|
+
eta: number | null;
|
|
110
|
+
/** Set when stage === 'done' */
|
|
111
|
+
result?: UploadResult;
|
|
112
|
+
/** Set when stage === 'error' */
|
|
113
|
+
error?: string;
|
|
114
|
+
/** Set when stage === 'error' */
|
|
115
|
+
code?: string;
|
|
116
|
+
}
|
|
117
|
+
/** Per-file progress during a batch download */
|
|
118
|
+
interface DownloadProgress {
|
|
119
|
+
index: number;
|
|
120
|
+
total: number;
|
|
121
|
+
path: string;
|
|
122
|
+
status: 'pending' | 'success' | 'error';
|
|
123
|
+
size?: number;
|
|
124
|
+
mimeType?: string;
|
|
125
|
+
error?: string;
|
|
126
|
+
}
|
|
127
|
+
interface UploadResult {
|
|
128
|
+
path: string;
|
|
129
|
+
compressed: boolean;
|
|
130
|
+
originalSize: number;
|
|
131
|
+
storedSize: number;
|
|
132
|
+
spaceSaved: number;
|
|
133
|
+
mimeType: string;
|
|
134
|
+
}
|
|
135
|
+
interface FileMetadata {
|
|
136
|
+
path: string;
|
|
137
|
+
name: string;
|
|
138
|
+
size: number | null;
|
|
139
|
+
originalSize: number | null;
|
|
140
|
+
mimeType: string | null;
|
|
141
|
+
isCompressed: boolean;
|
|
142
|
+
md5Hash: string | null;
|
|
143
|
+
updatedAt: string | null;
|
|
144
|
+
createdAt: string | null;
|
|
145
|
+
}
|
|
146
|
+
interface StorageItem {
|
|
147
|
+
name: string;
|
|
148
|
+
path: string;
|
|
149
|
+
type: 'file' | 'folder';
|
|
150
|
+
size?: number | null;
|
|
151
|
+
storedSize?: number | null;
|
|
152
|
+
mimeType?: string | null;
|
|
153
|
+
isCompressed?: boolean;
|
|
154
|
+
updatedAt?: string | null;
|
|
155
|
+
createdAt?: string | null;
|
|
156
|
+
md5Hash?: string | null;
|
|
157
|
+
}
|
|
158
|
+
interface ListResult {
|
|
159
|
+
items: StorageItem[];
|
|
160
|
+
pagination: {
|
|
161
|
+
limit: number;
|
|
162
|
+
count: number;
|
|
163
|
+
hasNextPage: boolean;
|
|
164
|
+
nextCursor: string | null;
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
interface SignedUrlResult {
|
|
168
|
+
signedUrl: string;
|
|
169
|
+
expiresAt: string;
|
|
170
|
+
expiresIn: number;
|
|
171
|
+
path: string;
|
|
172
|
+
}
|
|
173
|
+
interface BatchUploadResult {
|
|
174
|
+
succeeded: UploadResult[];
|
|
175
|
+
failed: Array<{
|
|
176
|
+
path: string;
|
|
177
|
+
error: string;
|
|
178
|
+
code: string;
|
|
179
|
+
}>;
|
|
180
|
+
}
|
|
181
|
+
interface BatchDownloadFile {
|
|
182
|
+
path: string;
|
|
183
|
+
content: ArrayBuffer;
|
|
184
|
+
mimeType: string;
|
|
185
|
+
size: number;
|
|
186
|
+
}
|
|
187
|
+
interface StorageStats {
|
|
188
|
+
totalFiles: number;
|
|
189
|
+
totalSizeBytes: number;
|
|
190
|
+
totalOriginalSizeBytes: number;
|
|
191
|
+
spaceSavedBytes: number;
|
|
192
|
+
uploadsCount: number;
|
|
193
|
+
downloadsCount: number;
|
|
194
|
+
deletesCount: number;
|
|
195
|
+
creditsUsedUpload: number;
|
|
196
|
+
creditsUsedDownload: number;
|
|
197
|
+
creditsTotalUsed: number;
|
|
198
|
+
bytesDelivered: number;
|
|
199
|
+
compressionRatio: string;
|
|
200
|
+
}
|
|
201
|
+
interface UploadOptions {
|
|
202
|
+
/**
|
|
203
|
+
* Destination path within your bucket (e.g. "avatars/photo.jpg").
|
|
204
|
+
* Defaults to the file's original name.
|
|
205
|
+
*/
|
|
206
|
+
path?: string;
|
|
207
|
+
/**
|
|
208
|
+
* Replace the file if it already exists at the given path.
|
|
209
|
+
* @default false
|
|
210
|
+
*/
|
|
211
|
+
overwrite?: boolean;
|
|
212
|
+
/**
|
|
213
|
+
* Called on every progress tick while the file is being transferred.
|
|
214
|
+
* Use this to drive progress bars, speed indicators, and ETAs.
|
|
215
|
+
*/
|
|
216
|
+
onProgress?: (progress: UploadProgress) => void;
|
|
217
|
+
}
|
|
218
|
+
interface BatchUploadOptions {
|
|
219
|
+
/**
|
|
220
|
+
* Folder prefix to prepend to all file names (e.g. "uploads/2024/").
|
|
221
|
+
* Individual path overrides take precedence if provided.
|
|
222
|
+
*/
|
|
223
|
+
prefix?: string;
|
|
224
|
+
/**
|
|
225
|
+
* Per-file destination paths in the same order as the `files` array.
|
|
226
|
+
* If omitted, `prefix + file.name` is used.
|
|
227
|
+
*/
|
|
228
|
+
paths?: string[];
|
|
229
|
+
/** @default false */
|
|
230
|
+
overwrite?: boolean;
|
|
231
|
+
/** Max simultaneous uploads (1–10). @default 5 */
|
|
232
|
+
concurrency?: number;
|
|
233
|
+
/**
|
|
234
|
+
* Called on every progress tick for every file.
|
|
235
|
+
* The `index` field identifies which file the event belongs to.
|
|
236
|
+
*/
|
|
237
|
+
onProgress?: (progress: UploadProgress) => void;
|
|
238
|
+
}
|
|
239
|
+
interface BatchDownloadOptions {
|
|
240
|
+
/** Max simultaneous downloads (1–10). @default 5 */
|
|
241
|
+
concurrency?: number;
|
|
242
|
+
/**
|
|
243
|
+
* Called when each file's download status changes.
|
|
244
|
+
*/
|
|
245
|
+
onProgress?: (progress: DownloadProgress) => void;
|
|
246
|
+
/**
|
|
247
|
+
* When true, automatically triggers browser download for each file as
|
|
248
|
+
* it arrives. Only works in browser environments.
|
|
249
|
+
* @default false
|
|
250
|
+
*/
|
|
251
|
+
autoSave?: boolean;
|
|
252
|
+
}
|
|
253
|
+
interface ListOptions {
|
|
254
|
+
/** Folder prefix to list (e.g. "avatars/"). Empty string = root. */
|
|
255
|
+
prefix?: string;
|
|
256
|
+
/** Max items per page (1–100). @default 50 */
|
|
257
|
+
limit?: number;
|
|
258
|
+
/** Pagination cursor returned from the previous call. */
|
|
259
|
+
cursor?: string;
|
|
260
|
+
}
|
|
261
|
+
interface SignedUrlOptions {
|
|
262
|
+
/** How long the URL stays valid, in seconds. @default 3600 (1 hour) */
|
|
263
|
+
expiresIn?: number;
|
|
264
|
+
}
|
|
6
265
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
266
|
+
declare class AuthClient {
|
|
267
|
+
private readonly baseUrl;
|
|
268
|
+
private readonly headers;
|
|
269
|
+
private session;
|
|
270
|
+
constructor(config: HydrousConfig);
|
|
271
|
+
/**
|
|
272
|
+
* Create a new user account and return a session.
|
|
273
|
+
*
|
|
274
|
+
* @example
|
|
275
|
+
* const { data, error } = await hydrous.auth.signUp({
|
|
276
|
+
* email: 'user@example.com',
|
|
277
|
+
* password: 'supersecret',
|
|
278
|
+
* });
|
|
279
|
+
*/
|
|
280
|
+
signUp(options: SignUpOptions): Promise<HydrousResponse<AuthSession>>;
|
|
281
|
+
/**
|
|
282
|
+
* Sign in with email and password.
|
|
283
|
+
*
|
|
284
|
+
* @example
|
|
285
|
+
* const { data, error } = await hydrous.auth.signIn({
|
|
286
|
+
* email: 'user@example.com',
|
|
287
|
+
* password: 'supersecret',
|
|
288
|
+
* });
|
|
289
|
+
* if (data) console.log('Signed in as', data.user.email);
|
|
290
|
+
*/
|
|
291
|
+
signIn(options: SignInOptions): Promise<HydrousResponse<AuthSession>>;
|
|
292
|
+
/**
|
|
293
|
+
* Sign out the current user and invalidate their session.
|
|
294
|
+
*/
|
|
295
|
+
signOut(): Promise<HydrousResponse<void>>;
|
|
296
|
+
/** Return the currently authenticated user, or null if not signed in. */
|
|
297
|
+
getUser(): Promise<HydrousResponse<AuthUser>>;
|
|
298
|
+
/**
|
|
299
|
+
* Refresh the access token using the stored refresh token.
|
|
300
|
+
* Called automatically by the SDK when a 401 is received.
|
|
301
|
+
*/
|
|
302
|
+
refreshSession(): Promise<HydrousResponse<AuthSession>>;
|
|
303
|
+
/** Return the current in-memory session (may be null). */
|
|
304
|
+
getSession(): AuthSession | null;
|
|
305
|
+
private _sessionHeader;
|
|
20
306
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
307
|
+
|
|
308
|
+
declare class RecordsClient {
|
|
309
|
+
private readonly baseUrl;
|
|
310
|
+
private readonly headers;
|
|
311
|
+
constructor(config: HydrousConfig);
|
|
312
|
+
/**
|
|
313
|
+
* Query records from a collection.
|
|
314
|
+
*
|
|
315
|
+
* @param collection - Collection name (e.g. "users")
|
|
316
|
+
* @param options - Filters, ordering, pagination
|
|
317
|
+
*
|
|
318
|
+
* @example
|
|
319
|
+
* const { data, error } = await hydrous.records.select('users', {
|
|
320
|
+
* where: { field: 'role', operator: 'eq', value: 'admin' },
|
|
321
|
+
* orderBy: { field: 'createdAt', direction: 'desc' },
|
|
322
|
+
* limit: 20,
|
|
323
|
+
* });
|
|
324
|
+
*/
|
|
325
|
+
select<T = Record<string, unknown>>(collection: string, options?: QueryOptions): Promise<RecordResponse<T>>;
|
|
326
|
+
/**
|
|
327
|
+
* Fetch a single record by its ID.
|
|
328
|
+
*
|
|
329
|
+
* @example
|
|
330
|
+
* const { data, error } = await hydrous.records.get('users', 'user_abc123');
|
|
331
|
+
*/
|
|
332
|
+
get<T = Record<string, unknown>>(collection: string, id: string): Promise<SingleRecordResponse<T>>;
|
|
333
|
+
/**
|
|
334
|
+
* Insert one or more records into a collection.
|
|
335
|
+
*
|
|
336
|
+
* @param collection - Collection name
|
|
337
|
+
* @param payload - A single record object or an array of record objects
|
|
338
|
+
*
|
|
339
|
+
* @example
|
|
340
|
+
* // Single insert
|
|
341
|
+
* const { data, error } = await hydrous.records.insert('users', {
|
|
342
|
+
* name: 'Alice', email: 'alice@example.com'
|
|
343
|
+
* });
|
|
344
|
+
*
|
|
345
|
+
* // Bulk insert
|
|
346
|
+
* const { data, error } = await hydrous.records.insert('users', [
|
|
347
|
+
* { name: 'Alice' }, { name: 'Bob' }
|
|
348
|
+
* ]);
|
|
349
|
+
*/
|
|
350
|
+
insert<T = Record<string, unknown>>(collection: string, payload: Partial<T> | Partial<T>[]): Promise<RecordResponse<T>>;
|
|
351
|
+
/**
|
|
352
|
+
* Update a record by ID.
|
|
353
|
+
*
|
|
354
|
+
* @example
|
|
355
|
+
* const { data, error } = await hydrous.records.update('users', 'user_abc123', {
|
|
356
|
+
* name: 'Alice Smith'
|
|
357
|
+
* });
|
|
358
|
+
*/
|
|
359
|
+
update<T = Record<string, unknown>>(collection: string, id: string, payload: Partial<T>): Promise<SingleRecordResponse<T>>;
|
|
360
|
+
/**
|
|
361
|
+
* Delete a record by ID.
|
|
362
|
+
*
|
|
363
|
+
* @example
|
|
364
|
+
* const { error } = await hydrous.records.delete('users', 'user_abc123');
|
|
365
|
+
*/
|
|
366
|
+
delete(collection: string, id: string): Promise<SingleRecordResponse<void>>;
|
|
27
367
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
constructor(
|
|
368
|
+
|
|
369
|
+
declare class AnalyticsClient {
|
|
370
|
+
private readonly baseUrl;
|
|
371
|
+
private readonly headers;
|
|
372
|
+
constructor(config: HydrousConfig);
|
|
373
|
+
/**
|
|
374
|
+
* Track an analytics event.
|
|
375
|
+
*
|
|
376
|
+
* @example
|
|
377
|
+
* await hydrous.analytics.track({
|
|
378
|
+
* event: 'page_view',
|
|
379
|
+
* properties: { page: '/home', referrer: 'google.com' },
|
|
380
|
+
* userId: 'user_abc123',
|
|
381
|
+
* });
|
|
382
|
+
*/
|
|
383
|
+
track(options: TrackEventOptions): Promise<HydrousResponse<void>>;
|
|
384
|
+
/**
|
|
385
|
+
* Query recorded analytics events.
|
|
386
|
+
*
|
|
387
|
+
* @example
|
|
388
|
+
* const { data } = await hydrous.analytics.query({
|
|
389
|
+
* event: 'page_view',
|
|
390
|
+
* from: '2024-01-01',
|
|
391
|
+
* to: '2024-01-31',
|
|
392
|
+
* limit: 100,
|
|
393
|
+
* });
|
|
394
|
+
*/
|
|
395
|
+
query(options?: AnalyticsQueryOptions): Promise<RecordResponse<AnalyticsEvent>>;
|
|
396
|
+
/**
|
|
397
|
+
* Track multiple events in a single request (more efficient than
|
|
398
|
+
* calling `track` in a loop).
|
|
399
|
+
*
|
|
400
|
+
* @example
|
|
401
|
+
* await hydrous.analytics.trackBatch([
|
|
402
|
+
* { event: 'signup', userId: 'u1' },
|
|
403
|
+
* { event: 'onboarded', userId: 'u1' },
|
|
404
|
+
* ]);
|
|
405
|
+
*/
|
|
406
|
+
trackBatch(events: TrackEventOptions[]): Promise<HydrousResponse<void>>;
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
declare class StorageClient {
|
|
410
|
+
private readonly baseUrl;
|
|
411
|
+
constructor(config: HydrousConfig);
|
|
412
|
+
/**
|
|
413
|
+
* Upload a single file to a bucket.
|
|
414
|
+
*
|
|
415
|
+
* The bucket key **always comes first**.
|
|
416
|
+
* Supply an `onProgress` callback to receive live upload progress including
|
|
417
|
+
* bytes transferred, speed (bytes/sec), ETA, and lifecycle stage.
|
|
418
|
+
*
|
|
419
|
+
* ### Stages fired via `onProgress`
|
|
420
|
+
* | Stage | Meaning |
|
|
421
|
+
* |-------------|------------------------------------------|
|
|
422
|
+
* | `pending` | Queued, not yet started |
|
|
423
|
+
* | `compressing` | Server is compressing the file |
|
|
424
|
+
* | `uploading` | Bytes flowing to cloud storage |
|
|
425
|
+
* | `done` | Confirmed written to cloud storage |
|
|
426
|
+
* | `error` | Something went wrong |
|
|
427
|
+
*
|
|
428
|
+
* @param bucketKey Your storage bucket key (`ssk_…`)
|
|
429
|
+
* @param file A `File`, `Blob`, or `Buffer` (Node)
|
|
430
|
+
* @param options Path, overwrite flag, progress callback
|
|
431
|
+
*
|
|
432
|
+
* @example
|
|
433
|
+
* const { data, error } = await hydrous.storage.upload(
|
|
434
|
+
* 'ssk_my_bucket_key',
|
|
435
|
+
* file,
|
|
436
|
+
* {
|
|
437
|
+
* path: 'avatars/alice.jpg',
|
|
438
|
+
* overwrite: true,
|
|
439
|
+
* onProgress: (p) => {
|
|
440
|
+
* console.log(`${p.stage} — ${p.percent}% ${p.bytesPerSecond} B/s ETA ${p.eta}s`);
|
|
441
|
+
* },
|
|
442
|
+
* }
|
|
443
|
+
* );
|
|
444
|
+
*/
|
|
445
|
+
upload(bucketKey: BucketKey, file: File | Blob | Uint8Array | ArrayBuffer, options?: UploadOptions): Promise<HydrousResponse<UploadResult>>;
|
|
446
|
+
/**
|
|
447
|
+
* Upload raw text or JSON content directly — no `File` object needed.
|
|
448
|
+
* Great for saving generated content, config files, or JSON records.
|
|
449
|
+
*
|
|
450
|
+
* @param bucketKey Your storage bucket key (`ssk_…`)
|
|
451
|
+
* @param path Destination path (e.g. `"configs/settings.json"`)
|
|
452
|
+
* @param content String content to store
|
|
453
|
+
* @param options `mimeType`, `overwrite`, `onProgress`
|
|
454
|
+
*
|
|
455
|
+
* @example
|
|
456
|
+
* await hydrous.storage.uploadText(
|
|
457
|
+
* 'ssk_my_bucket_key',
|
|
458
|
+
* 'reports/summary.txt',
|
|
459
|
+
* 'Hello from Hydrous!',
|
|
460
|
+
* { mimeType: 'text/plain' }
|
|
461
|
+
* );
|
|
462
|
+
*/
|
|
463
|
+
uploadText(bucketKey: BucketKey, path: string, content: string, options?: {
|
|
464
|
+
mimeType?: string;
|
|
465
|
+
overwrite?: boolean;
|
|
466
|
+
onProgress?: UploadOptions['onProgress'];
|
|
467
|
+
}): Promise<HydrousResponse<UploadResult>>;
|
|
468
|
+
/**
|
|
469
|
+
* Upload multiple files in one request.
|
|
470
|
+
*
|
|
471
|
+
* `onProgress` fires for **every file individually** — the `index` field
|
|
472
|
+
* tells you which file the event belongs to (0-based, same order as `files`).
|
|
473
|
+
* All files receive a `pending` event upfront before any uploads start,
|
|
474
|
+
* so you can render all progress bars immediately.
|
|
475
|
+
*
|
|
476
|
+
* @param bucketKey Your storage bucket key (`ssk_…`)
|
|
477
|
+
* @param files Array of `File` objects (browser) or `{ name, data }` objects (Node)
|
|
478
|
+
* @param options Prefix, per-file paths, overwrite, concurrency, onProgress
|
|
479
|
+
*
|
|
480
|
+
* @example
|
|
481
|
+
* await hydrous.storage.batchUpload(
|
|
482
|
+
* 'ssk_my_bucket_key',
|
|
483
|
+
* fileArray,
|
|
484
|
+
* {
|
|
485
|
+
* prefix: 'uploads/2024/',
|
|
486
|
+
* onProgress: (p) => {
|
|
487
|
+
* console.log(`File ${p.index}: ${p.stage} ${p.percent}%`);
|
|
488
|
+
* },
|
|
489
|
+
* }
|
|
490
|
+
* );
|
|
491
|
+
*/
|
|
492
|
+
batchUpload(bucketKey: BucketKey, files: File[], options?: BatchUploadOptions): Promise<HydrousResponse<BatchUploadResult>>;
|
|
493
|
+
/**
|
|
494
|
+
* Download a single file and return its content as an `ArrayBuffer`.
|
|
495
|
+
*
|
|
496
|
+
* @param bucketKey Your storage bucket key (`ssk_…`)
|
|
497
|
+
* @param filePath Path of the file within your bucket
|
|
498
|
+
*
|
|
499
|
+
* @example
|
|
500
|
+
* const { data, error } = await hydrous.storage.download(
|
|
501
|
+
* 'ssk_my_bucket_key',
|
|
502
|
+
* 'avatars/alice.jpg'
|
|
503
|
+
* );
|
|
504
|
+
* if (data) {
|
|
505
|
+
* const blob = new Blob([data]);
|
|
506
|
+
* const url = URL.createObjectURL(blob);
|
|
507
|
+
* }
|
|
508
|
+
*/
|
|
509
|
+
download(bucketKey: BucketKey, filePath: string): Promise<HydrousResponse<ArrayBuffer>>;
|
|
510
|
+
/**
|
|
511
|
+
* Download multiple files in one request.
|
|
512
|
+
*
|
|
513
|
+
* When `autoSave: true` (browser only) each file is automatically saved
|
|
514
|
+
* to the user's Downloads folder as it arrives.
|
|
515
|
+
*
|
|
516
|
+
* @param bucketKey Your storage bucket key (`ssk_…`)
|
|
517
|
+
* @param filePaths Array of file paths within your bucket
|
|
518
|
+
* @param options Concurrency, onProgress, autoSave
|
|
519
|
+
*
|
|
520
|
+
* @example
|
|
521
|
+
* const { data } = await hydrous.storage.batchDownload(
|
|
522
|
+
* 'ssk_my_bucket_key',
|
|
523
|
+
* ['reports/jan.pdf', 'reports/feb.pdf'],
|
|
524
|
+
* {
|
|
525
|
+
* onProgress: (p) => console.log(p.path, p.status),
|
|
526
|
+
* autoSave: true, // triggers browser file-save dialog per file
|
|
527
|
+
* }
|
|
528
|
+
* );
|
|
529
|
+
*/
|
|
530
|
+
batchDownload(bucketKey: BucketKey, filePaths: string[], options?: BatchDownloadOptions): Promise<HydrousResponse<BatchDownloadFile[]>>;
|
|
531
|
+
/**
|
|
532
|
+
* List files and folders inside a bucket (or a folder within it).
|
|
533
|
+
*
|
|
534
|
+
* Results are paginated — use `pagination.nextCursor` to fetch the next page.
|
|
535
|
+
*
|
|
536
|
+
* @param bucketKey Your storage bucket key (`ssk_…`)
|
|
537
|
+
* @param options `prefix`, `limit`, `cursor`
|
|
538
|
+
*
|
|
539
|
+
* @example
|
|
540
|
+
* const { data } = await hydrous.storage.list('ssk_my_bucket_key', {
|
|
541
|
+
* prefix: 'avatars/',
|
|
542
|
+
* limit: 50,
|
|
543
|
+
* });
|
|
544
|
+
* for (const item of data.items) {
|
|
545
|
+
* console.log(item.type, item.path);
|
|
546
|
+
* }
|
|
547
|
+
*/
|
|
548
|
+
list(bucketKey: BucketKey, options?: ListOptions): Promise<HydrousResponse<ListResult>>;
|
|
549
|
+
/**
|
|
550
|
+
* Get metadata for a specific file (size, MIME type, compression info, etc.)
|
|
551
|
+
*
|
|
552
|
+
* @param bucketKey Your storage bucket key (`ssk_…`)
|
|
553
|
+
* @param filePath Path of the file within your bucket
|
|
554
|
+
*
|
|
555
|
+
* @example
|
|
556
|
+
* const { data } = await hydrous.storage.metadata(
|
|
557
|
+
* 'ssk_my_bucket_key',
|
|
558
|
+
* 'avatars/alice.jpg'
|
|
559
|
+
* );
|
|
560
|
+
* console.log(data.size, data.mimeType);
|
|
561
|
+
*/
|
|
562
|
+
metadata(bucketKey: BucketKey, filePath: string): Promise<HydrousResponse<FileMetadata>>;
|
|
563
|
+
/**
|
|
564
|
+
* Delete a single file.
|
|
565
|
+
*
|
|
566
|
+
* @param bucketKey Your storage bucket key (`ssk_…`)
|
|
567
|
+
* @param filePath Path of the file to delete
|
|
568
|
+
*
|
|
569
|
+
* @example
|
|
570
|
+
* await hydrous.storage.deleteFile('ssk_my_bucket_key', 'avatars/old.jpg');
|
|
571
|
+
*/
|
|
572
|
+
deleteFile(bucketKey: BucketKey, filePath: string): Promise<HydrousResponse<void>>;
|
|
573
|
+
/**
|
|
574
|
+
* Recursively delete a folder and all of its contents.
|
|
575
|
+
*
|
|
576
|
+
* @param bucketKey Your storage bucket key (`ssk_…`)
|
|
577
|
+
* @param folderPath Folder path to delete (e.g. `"old-uploads/"`)
|
|
578
|
+
*
|
|
579
|
+
* @example
|
|
580
|
+
* await hydrous.storage.deleteFolder('ssk_my_bucket_key', 'temp/');
|
|
581
|
+
*/
|
|
582
|
+
deleteFolder(bucketKey: BucketKey, folderPath: string): Promise<HydrousResponse<void>>;
|
|
583
|
+
/**
|
|
584
|
+
* Create an empty folder.
|
|
585
|
+
*
|
|
586
|
+
* @param bucketKey Your storage bucket key (`ssk_…`)
|
|
587
|
+
* @param folderPath Path for the new folder (e.g. `"avatars/2024/"`)
|
|
588
|
+
*
|
|
589
|
+
* @example
|
|
590
|
+
* await hydrous.storage.createFolder('ssk_my_bucket_key', 'avatars/2024/');
|
|
591
|
+
*/
|
|
592
|
+
createFolder(bucketKey: BucketKey, folderPath: string): Promise<HydrousResponse<void>>;
|
|
593
|
+
/**
|
|
594
|
+
* Move (rename) a file to a new path.
|
|
595
|
+
*
|
|
596
|
+
* @param bucketKey Your storage bucket key (`ssk_…`)
|
|
597
|
+
* @param fromPath Current path of the file
|
|
598
|
+
* @param toPath New path for the file
|
|
599
|
+
*
|
|
600
|
+
* @example
|
|
601
|
+
* await hydrous.storage.move(
|
|
602
|
+
* 'ssk_my_bucket_key',
|
|
603
|
+
* 'drafts/report.pdf',
|
|
604
|
+
* 'published/report.pdf'
|
|
605
|
+
* );
|
|
606
|
+
*/
|
|
607
|
+
move(bucketKey: BucketKey, fromPath: string, toPath: string): Promise<HydrousResponse<void>>;
|
|
608
|
+
/**
|
|
609
|
+
* Copy a file to a new path (original is kept).
|
|
610
|
+
*
|
|
611
|
+
* @param bucketKey Your storage bucket key (`ssk_…`)
|
|
612
|
+
* @param fromPath Source path
|
|
613
|
+
* @param toPath Destination path
|
|
614
|
+
*
|
|
615
|
+
* @example
|
|
616
|
+
* await hydrous.storage.copy(
|
|
617
|
+
* 'ssk_my_bucket_key',
|
|
618
|
+
* 'templates/invoice.pdf',
|
|
619
|
+
* 'invoices/invoice-001.pdf'
|
|
620
|
+
* );
|
|
621
|
+
*/
|
|
622
|
+
copy(bucketKey: BucketKey, fromPath: string, toPath: string): Promise<HydrousResponse<void>>;
|
|
623
|
+
/**
|
|
624
|
+
* Generate a time-limited public URL for a private file.
|
|
625
|
+
*
|
|
626
|
+
* @param bucketKey Your storage bucket key (`ssk_…`)
|
|
627
|
+
* @param filePath Path of the file
|
|
628
|
+
* @param options `expiresIn` seconds (default: 3600)
|
|
629
|
+
*
|
|
630
|
+
* @example
|
|
631
|
+
* const { data } = await hydrous.storage.signedUrl(
|
|
632
|
+
* 'ssk_my_bucket_key',
|
|
633
|
+
* 'private/contract.pdf',
|
|
634
|
+
* { expiresIn: 300 } // 5 minutes
|
|
635
|
+
* );
|
|
636
|
+
* console.log(data.signedUrl); // share this URL
|
|
637
|
+
*/
|
|
638
|
+
signedUrl(bucketKey: BucketKey, filePath: string, options?: SignedUrlOptions): Promise<HydrousResponse<SignedUrlResult>>;
|
|
639
|
+
/**
|
|
640
|
+
* Get usage and billing statistics for this bucket key.
|
|
641
|
+
*
|
|
642
|
+
* @param bucketKey Your storage bucket key (`ssk_…`)
|
|
643
|
+
*
|
|
644
|
+
* @example
|
|
645
|
+
* const { data } = await hydrous.storage.stats('ssk_my_bucket_key');
|
|
646
|
+
* console.log(`${data.totalFiles} files, ${data.totalSizeBytes} bytes stored`);
|
|
647
|
+
*/
|
|
648
|
+
stats(bucketKey: BucketKey): Promise<HydrousResponse<StorageStats>>;
|
|
33
649
|
}
|
|
34
650
|
|
|
35
651
|
/**
|
|
36
|
-
* The
|
|
652
|
+
* The root Hydrous client.
|
|
653
|
+
*
|
|
654
|
+
* Instantiate once and reuse throughout your app.
|
|
37
655
|
*
|
|
38
656
|
* @example
|
|
39
|
-
* import {
|
|
657
|
+
* import { HydrousClient } from 'hydrous';
|
|
40
658
|
*
|
|
41
|
-
* const
|
|
42
|
-
*
|
|
43
|
-
*
|
|
659
|
+
* const hydrous = new HydrousClient({
|
|
660
|
+
* url: 'https://api.myapp.hydrous.app',
|
|
661
|
+
* apiKey: 'hk_live_…',
|
|
44
662
|
* });
|
|
45
|
-
*
|
|
46
|
-
* // Records
|
|
47
|
-
* const { data } = await db.records.get('rec_abc123');
|
|
48
|
-
*
|
|
49
|
-
* // Auth
|
|
50
|
-
* const { data, session } = await db.auth.signIn({ email: 'a@b.com', password: '...' });
|
|
51
|
-
*
|
|
52
|
-
* // Analytics
|
|
53
|
-
* const { data } = await db.analytics.count();
|
|
54
663
|
*/
|
|
55
664
|
declare class HydrousClient {
|
|
56
|
-
/**
|
|
57
|
-
readonly records: RecordsClient;
|
|
58
|
-
/** User authentication and session management */
|
|
665
|
+
/** Authentication — sign up, sign in, sign out, session management */
|
|
59
666
|
readonly auth: AuthClient;
|
|
60
|
-
/**
|
|
667
|
+
/** Records — insert, select, update, delete structured data */
|
|
668
|
+
readonly records: RecordsClient;
|
|
669
|
+
/** Analytics — track events, query event history */
|
|
61
670
|
readonly analytics: AnalyticsClient;
|
|
62
|
-
|
|
671
|
+
/**
|
|
672
|
+
* Storage — upload, download, list, move, delete files.
|
|
673
|
+
*
|
|
674
|
+
* Every method takes a **bucket key** (`ssk_…`) as its **first argument**.
|
|
675
|
+
*/
|
|
676
|
+
readonly storage: StorageClient;
|
|
63
677
|
constructor(config: HydrousConfig);
|
|
64
678
|
}
|
|
679
|
+
|
|
680
|
+
/** Shorthand helper: creates a simple equality filter */
|
|
681
|
+
declare function eq(field: string, value: unknown): Filter;
|
|
682
|
+
/** Shorthand helper: creates a "not equal" filter */
|
|
683
|
+
declare function neq(field: string, value: unknown): Filter;
|
|
684
|
+
/** Shorthand helper: creates a "greater than" filter */
|
|
685
|
+
declare function gt(field: string, value: unknown): Filter;
|
|
686
|
+
/** Shorthand helper: creates a "less than" filter */
|
|
687
|
+
declare function lt(field: string, value: unknown): Filter;
|
|
688
|
+
/** Shorthand helper: creates an "in array" filter */
|
|
689
|
+
declare function inArray(field: string, value: unknown[]): Filter;
|
|
690
|
+
|
|
691
|
+
declare class HydrousSDKError extends Error {
|
|
692
|
+
readonly code: string;
|
|
693
|
+
readonly status: number | undefined;
|
|
694
|
+
constructor(message: string, code?: string, status?: number);
|
|
695
|
+
}
|
|
696
|
+
declare function isHydrousError(err: unknown): err is HydrousSDKError;
|
|
697
|
+
|
|
65
698
|
/**
|
|
66
|
-
* Create a
|
|
699
|
+
* Create and return a `HydrousClient` instance.
|
|
67
700
|
*
|
|
68
701
|
* @example
|
|
69
|
-
*
|
|
702
|
+
* import { createClient } from 'hydrous';
|
|
703
|
+
*
|
|
704
|
+
* const hydrous = createClient({
|
|
705
|
+
* url: 'https://api.myapp.hydrous.app',
|
|
706
|
+
* apiKey: 'hk_live_…',
|
|
707
|
+
* });
|
|
70
708
|
*/
|
|
71
709
|
declare function createClient(config: HydrousConfig): HydrousClient;
|
|
72
710
|
|
|
73
|
-
export { AnalyticsClient, AuthClient, HydrousClient, HydrousConfig, HydrousError,
|
|
711
|
+
export { AnalyticsClient, type AnalyticsEvent, type AnalyticsQueryOptions, AuthClient, type AuthSession, type AuthUser, type BatchDownloadFile, type BatchDownloadOptions, type BatchUploadOptions, type BatchUploadResult, type BucketKey, type DownloadProgress, type FileMetadata, type Filter, type FilterOperator, HydrousClient, type HydrousConfig, type HydrousError, type HydrousResponse, HydrousSDKError, type ListOptions, type ListResult, type QueryOptions, type RecordResponse, RecordsClient, type SignInOptions, type SignUpOptions, type SignedUrlOptions, type SignedUrlResult, type SingleRecordResponse, StorageClient, type StorageItem, type StorageStats, type TrackEventOptions, type UploadOptions, type UploadProgress, type UploadResult, type UploadStage, createClient, eq, gt, inArray, isHydrousError, lt, neq };
|