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.
@@ -1,470 +0,0 @@
1
- type FilterOp = '==' | '!=' | '>' | '<' | '>=' | '<=' | 'contains';
2
- interface Filter {
3
- field: string;
4
- op: FilterOp;
5
- value: string | number | boolean;
6
- }
7
- interface PaginationMeta {
8
- nextCursor: string | null;
9
- hasMore: boolean;
10
- limit?: number;
11
- }
12
- interface ApiMeta extends PaginationMeta {
13
- bucketKey?: string;
14
- projectId?: string;
15
- retrievedAt?: number;
16
- filters?: Filter[];
17
- timeScope?: string;
18
- year?: string;
19
- sortOrder?: 'asc' | 'desc';
20
- }
21
- interface RequestOptions {
22
- /** Abort signal for cancellation */
23
- signal?: AbortSignal;
24
- /** Additional headers merged into every request */
25
- headers?: Record<string, string>;
26
- }
27
- interface HydrousConfig {
28
- /**
29
- * Your HydrousDB auth service key.
30
- * Used for all /auth routes (signUp, signIn, session management, etc.)
31
- */
32
- authKey: string;
33
- /**
34
- * Your HydrousDB security key.
35
- * Used as the credential for records and analytics routes.
36
- * The bucket is specified per-call via the bucketKey option on each method.
37
- */
38
- securityKey: string;
39
- /** Override the default base URL (advanced use) */
40
- baseUrl?: string;
41
- /** Request timeout in milliseconds (default: 30_000) */
42
- timeout?: number;
43
- /** Number of times to retry on network errors (default: 2) */
44
- retries?: number;
45
- }
46
- type RecordData = Record<string, unknown>;
47
- interface HydrousRecord {
48
- id: string;
49
- created_at?: number;
50
- updated_at?: number;
51
- [key: string]: unknown;
52
- }
53
- interface HistoryEntry {
54
- generation: string | null;
55
- savedAt: number | null;
56
- savedBy: string | null;
57
- sizeBytes: number | null;
58
- }
59
- interface GetRecordOptions {
60
- showHistory?: boolean;
61
- }
62
- interface GetRecordResponse {
63
- success: true;
64
- data: HydrousRecord;
65
- meta: {
66
- id: string;
67
- bucketKey: string;
68
- projectId: string;
69
- retrievedAt: number;
70
- historyCount?: number;
71
- };
72
- history?: HistoryEntry[];
73
- }
74
- interface GetSnapshotResponse {
75
- success: true;
76
- data: HydrousRecord;
77
- meta: {
78
- id: string;
79
- generation: string;
80
- historical: true;
81
- bucketKey: string;
82
- projectId: string;
83
- retrievedAt: number;
84
- };
85
- }
86
- interface QueryOptions {
87
- /** ISO date string or relative shorthand e.g. "7d", "30d" */
88
- timeScope?: string;
89
- /** Year restriction for monthly GCS walk e.g. "26" or "2026" */
90
- year?: string;
91
- filters?: Filter[];
92
- sortOrder?: 'asc' | 'desc';
93
- limit?: number;
94
- /** Opaque cursor from a previous response's meta.nextCursor */
95
- cursor?: string;
96
- /** Comma-separated field names to return */
97
- fields?: string;
98
- }
99
- interface QueryResponse<T extends RecordData = RecordData> {
100
- success: true;
101
- data: (T & HydrousRecord)[];
102
- meta: ApiMeta;
103
- }
104
- interface InsertRecordPayload {
105
- values: RecordData;
106
- /** Fields to index for querying */
107
- queryableFields?: string[];
108
- userEmail?: string;
109
- }
110
- interface InsertRecordResponse {
111
- success: true;
112
- data: HydrousRecord;
113
- meta: {
114
- id: string;
115
- bucketKey: string;
116
- projectId: string;
117
- };
118
- }
119
- interface UpdateRecordPayload {
120
- recordId: string;
121
- values: RecordData;
122
- userEmail?: string;
123
- reason?: string;
124
- track_record_history?: boolean;
125
- }
126
- interface UpdateRecordResponse {
127
- success: true;
128
- meta: {
129
- id: string;
130
- updatedAt: number;
131
- };
132
- }
133
- interface DeleteRecordResponse {
134
- success: true;
135
- meta: {
136
- id: string;
137
- deleted: true;
138
- deletedAt: number;
139
- deletedBy: string;
140
- bucketKey: string;
141
- projectId: string;
142
- };
143
- }
144
- interface RecordExistsInfo {
145
- exists: boolean;
146
- id: string;
147
- createdAt: string;
148
- updatedAt: string;
149
- sizeBytes: string;
150
- }
151
- interface BatchUpdateItem {
152
- recordId: string;
153
- values: RecordData;
154
- }
155
- interface BatchUpdatePayload {
156
- updates: BatchUpdateItem[];
157
- userEmail?: string;
158
- }
159
- interface BatchResult {
160
- successful: number;
161
- failed: number;
162
- errors?: Array<{
163
- recordId: string;
164
- error: string;
165
- }>;
166
- }
167
- interface BatchUpdateResponse {
168
- success: true;
169
- data: BatchResult;
170
- meta: {
171
- count: number;
172
- bucketKey: string;
173
- projectId: string;
174
- };
175
- }
176
- interface BatchDeletePayload {
177
- recordIds: string[];
178
- userEmail?: string;
179
- }
180
- interface BatchDeleteResponse {
181
- success: true;
182
- data: BatchResult;
183
- meta: {
184
- count: number;
185
- bucketKey: string;
186
- projectId: string;
187
- };
188
- }
189
- interface BatchInsertPayload {
190
- records: RecordData[];
191
- queryableFields?: string[];
192
- userEmail?: string;
193
- }
194
- interface BatchInsertResponse {
195
- success: boolean;
196
- data: HydrousRecord[];
197
- errors?: Array<{
198
- index: number;
199
- error: string;
200
- }>;
201
- meta: {
202
- totalProcessed: number;
203
- successful: number;
204
- failed: number;
205
- bucketKey: string;
206
- projectId: string;
207
- };
208
- }
209
- interface AuthUser {
210
- id: string;
211
- email: string;
212
- fullName?: string | null;
213
- role?: string;
214
- emailVerified?: boolean;
215
- accountStatus?: string;
216
- createdAt?: number;
217
- updatedAt?: number;
218
- lastLoginAt?: number | null;
219
- [key: string]: unknown;
220
- }
221
- interface SessionInfo {
222
- sessionId: string;
223
- refreshToken: string;
224
- expiresAt: number;
225
- }
226
- interface SignUpPayload {
227
- email: string;
228
- password: string;
229
- fullName?: string;
230
- [key: string]: unknown;
231
- }
232
- interface SignUpResponse {
233
- success: true;
234
- message: string;
235
- data: AuthUser;
236
- session: SessionInfo;
237
- meta: {
238
- userId: string;
239
- email: string;
240
- requiresVerification: boolean;
241
- requestId: string;
242
- };
243
- }
244
- interface SignInPayload {
245
- email: string;
246
- password: string;
247
- }
248
- interface SignInResponse {
249
- success: true;
250
- message: string;
251
- data: AuthUser;
252
- session: SessionInfo;
253
- meta: {
254
- userId: string;
255
- lastLogin: number | null;
256
- requestId: string;
257
- };
258
- }
259
- interface SignOutPayload {
260
- sessionId?: string;
261
- allDevices?: boolean;
262
- userId?: string;
263
- }
264
- interface ValidateSessionResponse {
265
- success: true;
266
- data: AuthUser;
267
- session: {
268
- sessionId: string;
269
- expiresAt: number;
270
- };
271
- requestId: string;
272
- }
273
- interface RefreshSessionResponse {
274
- success: true;
275
- data: AuthUser;
276
- session: SessionInfo;
277
- requestId: string;
278
- }
279
- interface GetUserResponse {
280
- success: true;
281
- data: AuthUser;
282
- meta: {
283
- userId: string;
284
- requestId: string;
285
- timestamp: number;
286
- };
287
- }
288
- interface ListUsersResponse {
289
- success: true;
290
- data: AuthUser[];
291
- meta: PaginationMeta & {
292
- requestId: string;
293
- };
294
- }
295
- interface UpdateUserPayload {
296
- userId: string;
297
- updates: Partial<AuthUser> & Record<string, unknown>;
298
- }
299
- interface UpdateUserResponse {
300
- success: true;
301
- message: string;
302
- data: AuthUser;
303
- meta: {
304
- userId: string;
305
- requestId: string;
306
- };
307
- }
308
- interface PasswordChangePayload {
309
- userId: string;
310
- oldPassword: string;
311
- newPassword: string;
312
- }
313
- interface PasswordResetRequestPayload {
314
- email: string;
315
- }
316
- interface PasswordResetConfirmPayload {
317
- resetToken: string;
318
- newPassword: string;
319
- }
320
- interface EmailVerifyRequestPayload {
321
- userId: string;
322
- }
323
- interface EmailVerifyConfirmPayload {
324
- verifyToken: string;
325
- }
326
- interface AccountLockPayload {
327
- userId: string;
328
- /** Duration in ms — defaults to 15 min */
329
- duration?: number;
330
- }
331
- interface AccountLockResponse {
332
- success: true;
333
- message: string;
334
- data: {
335
- lockedUntil: number;
336
- unlockTime: string;
337
- };
338
- meta: {
339
- userId: string;
340
- requestId: string;
341
- };
342
- }
343
- type AnalyticsQueryType = 'count' | 'distribution' | 'sum' | 'timeSeries' | 'fieldTimeSeries' | 'topN' | 'stats' | 'records' | 'multiMetric' | 'storageStats' | 'crossBucket';
344
- interface DateRange {
345
- startDate?: string;
346
- endDate?: string;
347
- year?: string;
348
- month?: string;
349
- day?: string;
350
- }
351
- interface MultiMetricItem {
352
- name: string;
353
- field: string;
354
- aggregation: 'sum' | 'avg' | 'min' | 'max' | 'count';
355
- }
356
- interface AnalyticsQuery {
357
- queryType: AnalyticsQueryType;
358
- dateRange?: DateRange;
359
- field?: string;
360
- groupBy?: string;
361
- labelField?: string;
362
- aggregation?: 'sum' | 'avg' | 'min' | 'max' | 'count';
363
- granularity?: 'hour' | 'day' | 'week' | 'month';
364
- filters?: Filter[];
365
- selectFields?: string[];
366
- limit?: number;
367
- offset?: number;
368
- orderBy?: string;
369
- order?: 'asc' | 'desc';
370
- n?: number;
371
- metrics?: MultiMetricItem[];
372
- bucketKeys?: string[];
373
- }
374
- interface CountResult {
375
- count: number;
376
- }
377
- interface DistributionItem {
378
- value: string;
379
- count: number;
380
- }
381
- interface SumResult {
382
- total: number;
383
- groups?: Array<{
384
- group: string;
385
- total: number;
386
- }>;
387
- }
388
- interface TimeSeriesPoint {
389
- date: string;
390
- count: number;
391
- }
392
- interface FieldTimeSeriesPoint {
393
- date: string;
394
- value: number;
395
- }
396
- interface TopNItem {
397
- label: string;
398
- value: string;
399
- count: number;
400
- }
401
- interface FieldStatsResult {
402
- min: number;
403
- max: number;
404
- avg: number;
405
- stddev: number;
406
- count: number;
407
- sum: number;
408
- p50: number;
409
- p90: number;
410
- p99: number;
411
- }
412
- interface FilteredRecordsResult {
413
- data: RecordData[];
414
- hasMore: boolean;
415
- offset: number;
416
- limit: number;
417
- }
418
- interface StorageStatsResult {
419
- totalRecords: number;
420
- totalBytes: number;
421
- avgBytes: number;
422
- minBytes: number;
423
- maxBytes: number;
424
- }
425
- interface AnalyticsResponse {
426
- success: true;
427
- data: unknown;
428
- meta?: Record<string, unknown>;
429
- }
430
- interface HydrousErrorBody {
431
- success: false;
432
- error: string;
433
- code?: string;
434
- details?: string[];
435
- requestId?: string;
436
- }
437
-
438
- interface HttpClientConfig {
439
- authKey: string;
440
- securityKey: string;
441
- baseUrl?: string;
442
- timeout?: number;
443
- retries?: number;
444
- }
445
- declare class HttpClient {
446
- readonly baseUrl: string;
447
- readonly authKey: string;
448
- readonly securityKey: string;
449
- private readonly timeout;
450
- private readonly retries;
451
- constructor(config: HttpClientConfig);
452
- request<T>(method: string, path: string, options?: {
453
- body?: unknown;
454
- params?: Record<string, string | number | boolean | undefined | null>;
455
- signal?: AbortSignal;
456
- headers?: Record<string, string>;
457
- /** Return raw Response instead of parsed JSON (used by HEAD) */
458
- raw?: boolean;
459
- }): Promise<T>;
460
- get<T>(path: string, params?: Record<string, string | number | boolean | undefined | null>, opts?: RequestOptions): Promise<T>;
461
- post<T>(path: string, body?: unknown, opts?: RequestOptions): Promise<T>;
462
- patch<T>(path: string, body?: unknown, opts?: RequestOptions): Promise<T>;
463
- delete<T>(path: string, params?: Record<string, string | number | boolean | undefined | null>, opts?: RequestOptions): Promise<T>;
464
- head(path: string, params?: Record<string, string | number | boolean | undefined | null>, opts?: RequestOptions): Promise<Response>;
465
- private buildUrl;
466
- private buildSignal;
467
- private executeWithRetry;
468
- }
469
-
470
- export { type SignUpResponse as $, type AccountLockPayload as A, type BatchDeletePayload as B, type CountResult as C, type DateRange as D, type EmailVerifyConfirmPayload as E, type FieldStatsResult as F, type GetRecordOptions as G, type HydrousErrorBody as H, type InsertRecordPayload as I, type InsertRecordResponse as J, type PasswordChangePayload as K, type ListUsersResponse as L, type MultiMetricItem as M, type PasswordResetConfirmPayload as N, type PasswordResetRequestPayload as O, type PaginationMeta as P, type QueryOptions as Q, type QueryResponse as R, type RecordData as S, type RecordExistsInfo as T, type RefreshSessionResponse as U, type RequestOptions as V, type SessionInfo as W, type SignInPayload as X, type SignInResponse as Y, type SignOutPayload as Z, type SignUpPayload as _, type HydrousConfig as a, type StorageStatsResult as a0, type SumResult as a1, type TimeSeriesPoint as a2, type TopNItem as a3, type UpdateRecordPayload as a4, type UpdateRecordResponse as a5, type UpdateUserPayload as a6, type UpdateUserResponse as a7, type ValidateSessionResponse as a8, HttpClient as a9, type AccountLockResponse as b, type AnalyticsQuery as c, type AnalyticsQueryType as d, type AnalyticsResponse as e, type ApiMeta as f, type AuthUser as g, type BatchDeleteResponse as h, type BatchInsertPayload as i, type BatchInsertResponse as j, type BatchResult as k, type BatchUpdateItem as l, type BatchUpdatePayload as m, type BatchUpdateResponse as n, type DeleteRecordResponse as o, type DistributionItem as p, type EmailVerifyRequestPayload as q, type FieldTimeSeriesPoint as r, type Filter as s, type FilterOp as t, type FilteredRecordsResult as u, type GetRecordResponse as v, type GetSnapshotResponse as w, type GetUserResponse as x, type HistoryEntry as y, type HydrousRecord as z };
@@ -1,137 +0,0 @@
1
- import { a9 as HttpClient, G as GetRecordOptions, V as RequestOptions, v as GetRecordResponse, w as GetSnapshotResponse, S as RecordData, Q as QueryOptions, R as QueryResponse, I as InsertRecordPayload, J as InsertRecordResponse, a4 as UpdateRecordPayload, a5 as UpdateRecordResponse, o as DeleteRecordResponse, T as RecordExistsInfo, m as BatchUpdatePayload, n as BatchUpdateResponse, B as BatchDeletePayload, h as BatchDeleteResponse, i as BatchInsertPayload, j as BatchInsertResponse, z as HydrousRecord } from '../http-DTukpdAU.mjs';
2
- export { s as Filter, t as FilterOp, y as HistoryEntry } from '../http-DTukpdAU.mjs';
3
-
4
- /** Options accepted by every records method that needs a bucket */
5
- interface BucketOptions {
6
- /**
7
- * The bucket to read from or write to.
8
- * Required on all records and analytics calls.
9
- *
10
- * @example
11
- * await db.records.insert({ values: { name: 'Alice' } }, { bucketKey: 'users' });
12
- */
13
- bucketKey: string;
14
- }
15
- declare class RecordsClient {
16
- private readonly http;
17
- constructor(http: HttpClient);
18
- /** Builds the base path for a given bucket: /api/:bucketKey/:securityKey */
19
- private path;
20
- /**
21
- * Fetch a single record by ID.
22
- *
23
- * @example
24
- * const { data } = await db.records.get('rec_abc123', { bucketKey: 'users' });
25
- * const { data, history } = await db.records.get('rec_abc123', { bucketKey: 'users', showHistory: true });
26
- */
27
- get(recordId: string, options: GetRecordOptions & BucketOptions & RequestOptions): Promise<GetRecordResponse>;
28
- /**
29
- * Fetch a specific historical version (generation) of a record.
30
- *
31
- * @example
32
- * const { data } = await db.records.getSnapshot('rec_abc123', '1700000000000000', { bucketKey: 'users' });
33
- */
34
- getSnapshot(recordId: string, generation: string, options: BucketOptions & RequestOptions): Promise<GetSnapshotResponse>;
35
- /**
36
- * Query a collection with optional filters, sorting, and pagination.
37
- *
38
- * @example
39
- * // Simple query
40
- * const { data, meta } = await db.records.query({ bucketKey: 'orders', limit: 50 });
41
- *
42
- * // Filtered query
43
- * const { data } = await db.records.query({
44
- * bucketKey: 'orders',
45
- * filters: [{ field: 'status', op: '==', value: 'active' }],
46
- * timeScope: '7d',
47
- * });
48
- *
49
- * // Paginated
50
- * let cursor: string | null = null;
51
- * do {
52
- * const result = await db.records.query({ bucketKey: 'orders', limit: 100, cursor: cursor ?? undefined });
53
- * cursor = result.meta.nextCursor;
54
- * } while (cursor);
55
- */
56
- query<T extends RecordData = RecordData>(options: QueryOptions & BucketOptions & RequestOptions): Promise<QueryResponse<T>>;
57
- /**
58
- * Insert a new record into the specified bucket.
59
- *
60
- * @example
61
- * const { data, meta } = await db.records.insert(
62
- * { values: { name: 'Alice', score: 99 }, queryableFields: ['name'] },
63
- * { bucketKey: 'users' }
64
- * );
65
- */
66
- insert(payload: InsertRecordPayload, options: BucketOptions & RequestOptions): Promise<InsertRecordResponse>;
67
- /**
68
- * Update an existing record.
69
- *
70
- * @example
71
- * await db.records.update(
72
- * { recordId: 'rec_abc123', values: { score: 100 }, track_record_history: true },
73
- * { bucketKey: 'users' }
74
- * );
75
- */
76
- update(payload: UpdateRecordPayload, options: BucketOptions & RequestOptions): Promise<UpdateRecordResponse>;
77
- /**
78
- * Delete a record permanently.
79
- *
80
- * @example
81
- * await db.records.delete('rec_abc123', { bucketKey: 'users' });
82
- */
83
- delete(recordId: string, options: BucketOptions & RequestOptions): Promise<DeleteRecordResponse>;
84
- /**
85
- * Check whether a record exists without fetching its full data.
86
- * Returns `null` if the record is not found.
87
- *
88
- * @example
89
- * const info = await db.records.exists('rec_abc123', { bucketKey: 'users' });
90
- * if (info?.exists) console.log('found at', info.updatedAt);
91
- */
92
- exists(recordId: string, options: BucketOptions & RequestOptions): Promise<RecordExistsInfo | null>;
93
- /**
94
- * Update up to 500 records in a single request.
95
- *
96
- * @example
97
- * await db.records.batchUpdate(
98
- * { updates: [{ recordId: 'rec_1', values: { status: 'archived' } }] },
99
- * { bucketKey: 'orders' }
100
- * );
101
- */
102
- batchUpdate(payload: BatchUpdatePayload, options: BucketOptions & RequestOptions): Promise<BatchUpdateResponse>;
103
- /**
104
- * Delete up to 500 records in a single request.
105
- *
106
- * @example
107
- * await db.records.batchDelete(
108
- * { recordIds: ['rec_1', 'rec_2'] },
109
- * { bucketKey: 'orders' }
110
- * );
111
- */
112
- batchDelete(payload: BatchDeletePayload, options: BucketOptions & RequestOptions): Promise<BatchDeleteResponse>;
113
- /**
114
- * Insert up to 500 records in a single request.
115
- * Returns HTTP 207 (multi-status) — check `meta.failed` for partial failures.
116
- *
117
- * @example
118
- * const result = await db.records.batchInsert(
119
- * { records: [{ name: 'Alice' }, { name: 'Bob' }], queryableFields: ['name'] },
120
- * { bucketKey: 'users' }
121
- * );
122
- */
123
- batchInsert(payload: BatchInsertPayload, options: BucketOptions & RequestOptions): Promise<BatchInsertResponse>;
124
- /**
125
- * Fetch ALL records matching a query, automatically following cursors.
126
- * Use with care on large collections — prefer `query()` with manual pagination.
127
- *
128
- * @example
129
- * const allRecords = await db.records.queryAll({
130
- * bucketKey: 'orders',
131
- * filters: [{ field: 'type', op: '==', value: 'invoice' }],
132
- * });
133
- */
134
- queryAll<T extends RecordData = RecordData>(options: Omit<QueryOptions, 'cursor'> & BucketOptions & RequestOptions): Promise<(T & HydrousRecord)[]>;
135
- }
136
-
137
- export { BatchDeletePayload, BatchDeleteResponse, BatchInsertPayload, BatchInsertResponse, BatchUpdatePayload, BatchUpdateResponse, type BucketOptions, DeleteRecordResponse, GetRecordOptions, GetRecordResponse, GetSnapshotResponse, HydrousRecord, InsertRecordPayload, InsertRecordResponse, QueryOptions, QueryResponse, RecordData, RecordExistsInfo, RecordsClient, UpdateRecordPayload, UpdateRecordResponse };