@rivium/sync-node 0.1.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.
@@ -0,0 +1,337 @@
1
+ /**
2
+ * RiviumSync Node.js SDK
3
+ * Server-side SDK for RiviumSync Realtime Database
4
+ *
5
+ * Features:
6
+ * - Admin-level access (bypasses security rules by default)
7
+ * - Full CRUD operations on databases, collections, documents
8
+ * - Query support with filters, sorting, pagination
9
+ * - Batch operations for atomic writes
10
+ * - Realtime subscriptions via MQTT
11
+ * - Ideal for backend services, serverless functions, data migrations
12
+ *
13
+ * @packageDocumentation
14
+ */
15
+ declare enum RiviumSyncErrorCode {
16
+ CONNECTION_FAILED = 1000,
17
+ CONNECTION_TIMEOUT = 1001,
18
+ CONNECTION_LOST = 1002,
19
+ AUTHENTICATION_FAILED = 1004,
20
+ SUBSCRIPTION_FAILED = 1100,
21
+ DATA_FETCH_FAILED = 1200,
22
+ DATA_PARSE_ERROR = 1201,
23
+ DATA_WRITE_FAILED = 1202,
24
+ DATA_DELETE_FAILED = 1203,
25
+ DOCUMENT_NOT_FOUND = 1204,
26
+ INVALID_CONFIG = 1300,
27
+ MISSING_API_KEY = 1301,
28
+ MISSING_SERVER_URL = 1302,
29
+ MISSING_SERVER_SECRET = 1303,
30
+ NOT_INITIALIZED = 1500,
31
+ NOT_CONNECTED = 1501,
32
+ INVALID_QUERY = 1700,
33
+ QUERY_EXECUTION_FAILED = 1701,
34
+ BATCH_WRITE_FAILED = 1800,
35
+ UNKNOWN_ERROR = 9999
36
+ }
37
+ declare class RiviumSyncError extends Error {
38
+ readonly code: RiviumSyncErrorCode;
39
+ readonly details?: string;
40
+ constructor(code: RiviumSyncErrorCode, details?: string);
41
+ toJSON(): {
42
+ code: RiviumSyncErrorCode;
43
+ message: string;
44
+ details: string | undefined;
45
+ };
46
+ }
47
+ declare enum RiviumSyncLogLevel {
48
+ NONE = 0,
49
+ ERROR = 1,
50
+ WARNING = 2,
51
+ INFO = 3,
52
+ DEBUG = 4,
53
+ VERBOSE = 5
54
+ }
55
+ interface RiviumSyncAdminConfig {
56
+ /** Your Project API Key (rv_live_xxx or rv_test_xxx) - REQUIRED */
57
+ apiKey: string;
58
+ /** Server secret for server-side authentication (nl_srv_xxx) - REQUIRED for all server operations */
59
+ serverSecret: string;
60
+ /** Optional user identifier for Security Rules (used as auth.uid when acting on behalf of a user) */
61
+ userId?: string;
62
+ /** Enable realtime subscriptions (default: false for server-side) */
63
+ enableRealtime?: boolean;
64
+ /** Log level (default: ERROR) */
65
+ logLevel?: RiviumSyncLogLevel;
66
+ /** Request timeout in ms (default: 30000) */
67
+ timeout?: number;
68
+ }
69
+ interface SyncDocument<T = Record<string, unknown>> {
70
+ id: string;
71
+ data: T;
72
+ createdAt?: string;
73
+ updatedAt?: string;
74
+ version?: number;
75
+ }
76
+ type QueryOperator = '==' | '!=' | '<' | '<=' | '>' | '>=' | 'in' | 'not-in' | 'array-contains';
77
+ interface QueryFilter {
78
+ field: string;
79
+ operator: QueryOperator;
80
+ value: unknown;
81
+ }
82
+ interface QueryOptions {
83
+ filters?: QueryFilter[];
84
+ orderBy?: string;
85
+ orderDirection?: 'asc' | 'desc';
86
+ limit?: number;
87
+ offset?: number;
88
+ }
89
+ type DocumentListener<T = Record<string, unknown>> = (doc: SyncDocument<T> | null) => void;
90
+ type CollectionListener<T = Record<string, unknown>> = (docs: SyncDocument<T>[]) => void;
91
+ type Unsubscribe = () => void;
92
+ interface BatchOperation {
93
+ type: 'set' | 'update' | 'delete';
94
+ databaseId: string;
95
+ collectionId: string;
96
+ documentId: string;
97
+ data?: unknown;
98
+ }
99
+ declare class SyncCollection<T = Record<string, unknown>> {
100
+ private admin;
101
+ private databaseId;
102
+ private collectionId;
103
+ constructor(admin: RiviumSyncAdmin, databaseId: string, collectionId: string);
104
+ /**
105
+ * Get a document reference
106
+ */
107
+ doc(documentId: string): SyncDocumentRef<T>;
108
+ /**
109
+ * Create a new document with auto-generated ID
110
+ */
111
+ add(data: T): Promise<SyncDocument<T>>;
112
+ /**
113
+ * Get a single document by ID
114
+ */
115
+ get(documentId: string): Promise<SyncDocument<T> | null>;
116
+ /**
117
+ * Get all documents in collection
118
+ */
119
+ getAll(options?: QueryOptions): Promise<SyncDocument<T>[]>;
120
+ /**
121
+ * Listen to collection changes (requires enableRealtime: true)
122
+ */
123
+ onSnapshot(callback: CollectionListener<T>, options?: QueryOptions): Unsubscribe;
124
+ /**
125
+ * Start a query builder
126
+ */
127
+ query(): SyncQuery<T>;
128
+ /**
129
+ * Add a filter condition
130
+ */
131
+ where(field: string, operator: QueryOperator, value: unknown): SyncQuery<T>;
132
+ /**
133
+ * Order results
134
+ */
135
+ orderBy(field: string, direction?: 'asc' | 'desc'): SyncQuery<T>;
136
+ /**
137
+ * Limit results
138
+ */
139
+ limit(count: number): SyncQuery<T>;
140
+ }
141
+ declare class SyncDocumentRef<T = Record<string, unknown>> {
142
+ private admin;
143
+ private databaseId;
144
+ private collectionId;
145
+ private documentId;
146
+ constructor(admin: RiviumSyncAdmin, databaseId: string, collectionId: string, documentId: string);
147
+ get id(): string;
148
+ get path(): string;
149
+ /**
150
+ * Get document data
151
+ */
152
+ get(): Promise<SyncDocument<T> | null>;
153
+ /**
154
+ * Check if document exists
155
+ */
156
+ exists(): Promise<boolean>;
157
+ /**
158
+ * Set document data (overwrite)
159
+ */
160
+ set(data: T): Promise<void>;
161
+ /**
162
+ * Update document data (merge)
163
+ */
164
+ update(data: Partial<T>): Promise<void>;
165
+ /**
166
+ * Delete document
167
+ */
168
+ delete(): Promise<void>;
169
+ /**
170
+ * Listen to document changes (requires enableRealtime: true)
171
+ */
172
+ onSnapshot(callback: DocumentListener<T>): Unsubscribe;
173
+ }
174
+ declare class SyncQuery<T = Record<string, unknown>> {
175
+ private admin;
176
+ private databaseId;
177
+ private collectionId;
178
+ private options;
179
+ constructor(admin: RiviumSyncAdmin, databaseId: string, collectionId: string);
180
+ /**
181
+ * Add a filter condition
182
+ */
183
+ where(field: string, operator: QueryOperator, value: unknown): SyncQuery<T>;
184
+ /**
185
+ * Order results
186
+ */
187
+ orderBy(field: string, direction?: 'asc' | 'desc'): SyncQuery<T>;
188
+ /**
189
+ * Limit results
190
+ */
191
+ limit(count: number): SyncQuery<T>;
192
+ /**
193
+ * Skip results (for pagination)
194
+ */
195
+ offset(count: number): SyncQuery<T>;
196
+ /**
197
+ * Alias for offset - skip first N results
198
+ */
199
+ startAfter(count: number): SyncQuery<T>;
200
+ /**
201
+ * Execute query and get results
202
+ */
203
+ get(): Promise<SyncDocument<T>[]>;
204
+ /**
205
+ * Get first result only
206
+ */
207
+ getFirst(): Promise<SyncDocument<T> | null>;
208
+ /**
209
+ * Count matching documents
210
+ */
211
+ count(): Promise<number>;
212
+ /**
213
+ * Listen to query results (requires enableRealtime: true)
214
+ */
215
+ onSnapshot(callback: CollectionListener<T>): Unsubscribe;
216
+ }
217
+ declare class SyncDatabase {
218
+ private admin;
219
+ private databaseId;
220
+ constructor(admin: RiviumSyncAdmin, databaseId: string);
221
+ get id(): string;
222
+ /**
223
+ * Get a collection reference
224
+ */
225
+ collection<T = Record<string, unknown>>(collectionId: string): SyncCollection<T>;
226
+ }
227
+ declare class WriteBatch {
228
+ private admin;
229
+ private operations;
230
+ constructor(admin: RiviumSyncAdmin);
231
+ /**
232
+ * Add a set operation to the batch
233
+ */
234
+ set<T>(docRef: SyncDocumentRef<T>, data: T): WriteBatch;
235
+ /**
236
+ * Add an update operation to the batch
237
+ */
238
+ update<T>(docRef: SyncDocumentRef<T>, data: Partial<T>): WriteBatch;
239
+ /**
240
+ * Add a delete operation to the batch
241
+ */
242
+ delete<T>(docRef: SyncDocumentRef<T>): WriteBatch;
243
+ /**
244
+ * Commit all operations in the batch
245
+ */
246
+ commit(): Promise<void>;
247
+ /**
248
+ * Get the number of pending operations
249
+ */
250
+ get size(): number;
251
+ }
252
+ /**
253
+ * RiviumSync Admin SDK for Node.js
254
+ *
255
+ * @example
256
+ * ```typescript
257
+ * import { RiviumSyncAdmin } from '@rivium/sync-node';
258
+ *
259
+ * const riviumSync = new RiviumSyncAdmin({
260
+ * apiKey: process.env.RIVIUM_SYNC_API_KEY,
261
+ * serverSecret: process.env.RIVIUM_SYNC_SERVER_SECRET, // Required for server-side operations
262
+ * });
263
+ *
264
+ * // Get a database reference
265
+ * const db = riviumSync.database('my-database-id');
266
+ *
267
+ * // CRUD operations
268
+ * const users = db.collection('users');
269
+ *
270
+ * // Create
271
+ * const newUser = await users.add({ name: 'John', email: 'john@example.com' });
272
+ *
273
+ * // Read
274
+ * const user = await users.get('user-id');
275
+ *
276
+ * // Query
277
+ * const adults = await users.where('age', '>=', 18).orderBy('name').get();
278
+ *
279
+ * // Update
280
+ * await users.doc('user-id').update({ age: 31 });
281
+ *
282
+ * // Delete
283
+ * await users.doc('user-id').delete();
284
+ *
285
+ * // Batch operations
286
+ * const batch = riviumSync.batch();
287
+ * batch.set(users.doc('user1'), { name: 'User 1' });
288
+ * batch.update(users.doc('user2'), { status: 'active' });
289
+ * batch.delete(users.doc('user3'));
290
+ * await batch.commit();
291
+ * ```
292
+ */
293
+ declare class RiviumSyncAdmin {
294
+ private static readonly DEFAULT_BASE_URL;
295
+ private config;
296
+ private mqttClient;
297
+ private mqttConfig;
298
+ private logLevel;
299
+ private timeout;
300
+ private documentListeners;
301
+ private collectionListeners;
302
+ private cachedCollections;
303
+ constructor(config: RiviumSyncAdminConfig);
304
+ private log;
305
+ setLogLevel(level: RiviumSyncLogLevel): void;
306
+ private request;
307
+ /**
308
+ * Get a database reference
309
+ */
310
+ database(databaseId: string): SyncDatabase;
311
+ /**
312
+ * Create a new write batch
313
+ */
314
+ batch(): WriteBatch;
315
+ getDocument<T>(databaseId: string, collectionId: string, documentId: string): Promise<SyncDocument<T> | null>;
316
+ getDocuments<T>(databaseId: string, collectionId: string, options?: QueryOptions): Promise<SyncDocument<T>[]>;
317
+ addDocument<T>(databaseId: string, collectionId: string, data: T): Promise<SyncDocument<T>>;
318
+ setDocument<T>(databaseId: string, collectionId: string, documentId: string, data: T): Promise<void>;
319
+ updateDocument<T>(databaseId: string, collectionId: string, documentId: string, data: Partial<T>): Promise<void>;
320
+ deleteDocument(databaseId: string, collectionId: string, documentId: string): Promise<void>;
321
+ executeBatch(operations: BatchOperation[]): Promise<void>;
322
+ private initRealtime;
323
+ private connectMqtt;
324
+ listenDocument<T>(databaseId: string, collectionId: string, documentId: string, callback: DocumentListener<T>): Unsubscribe;
325
+ listenCollection<T>(databaseId: string, collectionId: string, callback: CollectionListener<T>, options?: QueryOptions): Unsubscribe;
326
+ private resubscribeAll;
327
+ private handleMqttMessage;
328
+ private applyFilters;
329
+ private applyOrdering;
330
+ private generateUUID;
331
+ /**
332
+ * Disconnect from realtime updates
333
+ */
334
+ disconnect(): void;
335
+ }
336
+
337
+ export { type CollectionListener, type DocumentListener, type QueryFilter, type QueryOperator, type QueryOptions, RiviumSyncAdmin, type RiviumSyncAdminConfig, RiviumSyncError, RiviumSyncErrorCode, RiviumSyncLogLevel, SyncCollection, SyncDatabase, type SyncDocument, SyncDocumentRef, SyncQuery, type Unsubscribe, WriteBatch, RiviumSyncAdmin as default };
@@ -0,0 +1,337 @@
1
+ /**
2
+ * RiviumSync Node.js SDK
3
+ * Server-side SDK for RiviumSync Realtime Database
4
+ *
5
+ * Features:
6
+ * - Admin-level access (bypasses security rules by default)
7
+ * - Full CRUD operations on databases, collections, documents
8
+ * - Query support with filters, sorting, pagination
9
+ * - Batch operations for atomic writes
10
+ * - Realtime subscriptions via MQTT
11
+ * - Ideal for backend services, serverless functions, data migrations
12
+ *
13
+ * @packageDocumentation
14
+ */
15
+ declare enum RiviumSyncErrorCode {
16
+ CONNECTION_FAILED = 1000,
17
+ CONNECTION_TIMEOUT = 1001,
18
+ CONNECTION_LOST = 1002,
19
+ AUTHENTICATION_FAILED = 1004,
20
+ SUBSCRIPTION_FAILED = 1100,
21
+ DATA_FETCH_FAILED = 1200,
22
+ DATA_PARSE_ERROR = 1201,
23
+ DATA_WRITE_FAILED = 1202,
24
+ DATA_DELETE_FAILED = 1203,
25
+ DOCUMENT_NOT_FOUND = 1204,
26
+ INVALID_CONFIG = 1300,
27
+ MISSING_API_KEY = 1301,
28
+ MISSING_SERVER_URL = 1302,
29
+ MISSING_SERVER_SECRET = 1303,
30
+ NOT_INITIALIZED = 1500,
31
+ NOT_CONNECTED = 1501,
32
+ INVALID_QUERY = 1700,
33
+ QUERY_EXECUTION_FAILED = 1701,
34
+ BATCH_WRITE_FAILED = 1800,
35
+ UNKNOWN_ERROR = 9999
36
+ }
37
+ declare class RiviumSyncError extends Error {
38
+ readonly code: RiviumSyncErrorCode;
39
+ readonly details?: string;
40
+ constructor(code: RiviumSyncErrorCode, details?: string);
41
+ toJSON(): {
42
+ code: RiviumSyncErrorCode;
43
+ message: string;
44
+ details: string | undefined;
45
+ };
46
+ }
47
+ declare enum RiviumSyncLogLevel {
48
+ NONE = 0,
49
+ ERROR = 1,
50
+ WARNING = 2,
51
+ INFO = 3,
52
+ DEBUG = 4,
53
+ VERBOSE = 5
54
+ }
55
+ interface RiviumSyncAdminConfig {
56
+ /** Your Project API Key (rv_live_xxx or rv_test_xxx) - REQUIRED */
57
+ apiKey: string;
58
+ /** Server secret for server-side authentication (nl_srv_xxx) - REQUIRED for all server operations */
59
+ serverSecret: string;
60
+ /** Optional user identifier for Security Rules (used as auth.uid when acting on behalf of a user) */
61
+ userId?: string;
62
+ /** Enable realtime subscriptions (default: false for server-side) */
63
+ enableRealtime?: boolean;
64
+ /** Log level (default: ERROR) */
65
+ logLevel?: RiviumSyncLogLevel;
66
+ /** Request timeout in ms (default: 30000) */
67
+ timeout?: number;
68
+ }
69
+ interface SyncDocument<T = Record<string, unknown>> {
70
+ id: string;
71
+ data: T;
72
+ createdAt?: string;
73
+ updatedAt?: string;
74
+ version?: number;
75
+ }
76
+ type QueryOperator = '==' | '!=' | '<' | '<=' | '>' | '>=' | 'in' | 'not-in' | 'array-contains';
77
+ interface QueryFilter {
78
+ field: string;
79
+ operator: QueryOperator;
80
+ value: unknown;
81
+ }
82
+ interface QueryOptions {
83
+ filters?: QueryFilter[];
84
+ orderBy?: string;
85
+ orderDirection?: 'asc' | 'desc';
86
+ limit?: number;
87
+ offset?: number;
88
+ }
89
+ type DocumentListener<T = Record<string, unknown>> = (doc: SyncDocument<T> | null) => void;
90
+ type CollectionListener<T = Record<string, unknown>> = (docs: SyncDocument<T>[]) => void;
91
+ type Unsubscribe = () => void;
92
+ interface BatchOperation {
93
+ type: 'set' | 'update' | 'delete';
94
+ databaseId: string;
95
+ collectionId: string;
96
+ documentId: string;
97
+ data?: unknown;
98
+ }
99
+ declare class SyncCollection<T = Record<string, unknown>> {
100
+ private admin;
101
+ private databaseId;
102
+ private collectionId;
103
+ constructor(admin: RiviumSyncAdmin, databaseId: string, collectionId: string);
104
+ /**
105
+ * Get a document reference
106
+ */
107
+ doc(documentId: string): SyncDocumentRef<T>;
108
+ /**
109
+ * Create a new document with auto-generated ID
110
+ */
111
+ add(data: T): Promise<SyncDocument<T>>;
112
+ /**
113
+ * Get a single document by ID
114
+ */
115
+ get(documentId: string): Promise<SyncDocument<T> | null>;
116
+ /**
117
+ * Get all documents in collection
118
+ */
119
+ getAll(options?: QueryOptions): Promise<SyncDocument<T>[]>;
120
+ /**
121
+ * Listen to collection changes (requires enableRealtime: true)
122
+ */
123
+ onSnapshot(callback: CollectionListener<T>, options?: QueryOptions): Unsubscribe;
124
+ /**
125
+ * Start a query builder
126
+ */
127
+ query(): SyncQuery<T>;
128
+ /**
129
+ * Add a filter condition
130
+ */
131
+ where(field: string, operator: QueryOperator, value: unknown): SyncQuery<T>;
132
+ /**
133
+ * Order results
134
+ */
135
+ orderBy(field: string, direction?: 'asc' | 'desc'): SyncQuery<T>;
136
+ /**
137
+ * Limit results
138
+ */
139
+ limit(count: number): SyncQuery<T>;
140
+ }
141
+ declare class SyncDocumentRef<T = Record<string, unknown>> {
142
+ private admin;
143
+ private databaseId;
144
+ private collectionId;
145
+ private documentId;
146
+ constructor(admin: RiviumSyncAdmin, databaseId: string, collectionId: string, documentId: string);
147
+ get id(): string;
148
+ get path(): string;
149
+ /**
150
+ * Get document data
151
+ */
152
+ get(): Promise<SyncDocument<T> | null>;
153
+ /**
154
+ * Check if document exists
155
+ */
156
+ exists(): Promise<boolean>;
157
+ /**
158
+ * Set document data (overwrite)
159
+ */
160
+ set(data: T): Promise<void>;
161
+ /**
162
+ * Update document data (merge)
163
+ */
164
+ update(data: Partial<T>): Promise<void>;
165
+ /**
166
+ * Delete document
167
+ */
168
+ delete(): Promise<void>;
169
+ /**
170
+ * Listen to document changes (requires enableRealtime: true)
171
+ */
172
+ onSnapshot(callback: DocumentListener<T>): Unsubscribe;
173
+ }
174
+ declare class SyncQuery<T = Record<string, unknown>> {
175
+ private admin;
176
+ private databaseId;
177
+ private collectionId;
178
+ private options;
179
+ constructor(admin: RiviumSyncAdmin, databaseId: string, collectionId: string);
180
+ /**
181
+ * Add a filter condition
182
+ */
183
+ where(field: string, operator: QueryOperator, value: unknown): SyncQuery<T>;
184
+ /**
185
+ * Order results
186
+ */
187
+ orderBy(field: string, direction?: 'asc' | 'desc'): SyncQuery<T>;
188
+ /**
189
+ * Limit results
190
+ */
191
+ limit(count: number): SyncQuery<T>;
192
+ /**
193
+ * Skip results (for pagination)
194
+ */
195
+ offset(count: number): SyncQuery<T>;
196
+ /**
197
+ * Alias for offset - skip first N results
198
+ */
199
+ startAfter(count: number): SyncQuery<T>;
200
+ /**
201
+ * Execute query and get results
202
+ */
203
+ get(): Promise<SyncDocument<T>[]>;
204
+ /**
205
+ * Get first result only
206
+ */
207
+ getFirst(): Promise<SyncDocument<T> | null>;
208
+ /**
209
+ * Count matching documents
210
+ */
211
+ count(): Promise<number>;
212
+ /**
213
+ * Listen to query results (requires enableRealtime: true)
214
+ */
215
+ onSnapshot(callback: CollectionListener<T>): Unsubscribe;
216
+ }
217
+ declare class SyncDatabase {
218
+ private admin;
219
+ private databaseId;
220
+ constructor(admin: RiviumSyncAdmin, databaseId: string);
221
+ get id(): string;
222
+ /**
223
+ * Get a collection reference
224
+ */
225
+ collection<T = Record<string, unknown>>(collectionId: string): SyncCollection<T>;
226
+ }
227
+ declare class WriteBatch {
228
+ private admin;
229
+ private operations;
230
+ constructor(admin: RiviumSyncAdmin);
231
+ /**
232
+ * Add a set operation to the batch
233
+ */
234
+ set<T>(docRef: SyncDocumentRef<T>, data: T): WriteBatch;
235
+ /**
236
+ * Add an update operation to the batch
237
+ */
238
+ update<T>(docRef: SyncDocumentRef<T>, data: Partial<T>): WriteBatch;
239
+ /**
240
+ * Add a delete operation to the batch
241
+ */
242
+ delete<T>(docRef: SyncDocumentRef<T>): WriteBatch;
243
+ /**
244
+ * Commit all operations in the batch
245
+ */
246
+ commit(): Promise<void>;
247
+ /**
248
+ * Get the number of pending operations
249
+ */
250
+ get size(): number;
251
+ }
252
+ /**
253
+ * RiviumSync Admin SDK for Node.js
254
+ *
255
+ * @example
256
+ * ```typescript
257
+ * import { RiviumSyncAdmin } from '@rivium/sync-node';
258
+ *
259
+ * const riviumSync = new RiviumSyncAdmin({
260
+ * apiKey: process.env.RIVIUM_SYNC_API_KEY,
261
+ * serverSecret: process.env.RIVIUM_SYNC_SERVER_SECRET, // Required for server-side operations
262
+ * });
263
+ *
264
+ * // Get a database reference
265
+ * const db = riviumSync.database('my-database-id');
266
+ *
267
+ * // CRUD operations
268
+ * const users = db.collection('users');
269
+ *
270
+ * // Create
271
+ * const newUser = await users.add({ name: 'John', email: 'john@example.com' });
272
+ *
273
+ * // Read
274
+ * const user = await users.get('user-id');
275
+ *
276
+ * // Query
277
+ * const adults = await users.where('age', '>=', 18).orderBy('name').get();
278
+ *
279
+ * // Update
280
+ * await users.doc('user-id').update({ age: 31 });
281
+ *
282
+ * // Delete
283
+ * await users.doc('user-id').delete();
284
+ *
285
+ * // Batch operations
286
+ * const batch = riviumSync.batch();
287
+ * batch.set(users.doc('user1'), { name: 'User 1' });
288
+ * batch.update(users.doc('user2'), { status: 'active' });
289
+ * batch.delete(users.doc('user3'));
290
+ * await batch.commit();
291
+ * ```
292
+ */
293
+ declare class RiviumSyncAdmin {
294
+ private static readonly DEFAULT_BASE_URL;
295
+ private config;
296
+ private mqttClient;
297
+ private mqttConfig;
298
+ private logLevel;
299
+ private timeout;
300
+ private documentListeners;
301
+ private collectionListeners;
302
+ private cachedCollections;
303
+ constructor(config: RiviumSyncAdminConfig);
304
+ private log;
305
+ setLogLevel(level: RiviumSyncLogLevel): void;
306
+ private request;
307
+ /**
308
+ * Get a database reference
309
+ */
310
+ database(databaseId: string): SyncDatabase;
311
+ /**
312
+ * Create a new write batch
313
+ */
314
+ batch(): WriteBatch;
315
+ getDocument<T>(databaseId: string, collectionId: string, documentId: string): Promise<SyncDocument<T> | null>;
316
+ getDocuments<T>(databaseId: string, collectionId: string, options?: QueryOptions): Promise<SyncDocument<T>[]>;
317
+ addDocument<T>(databaseId: string, collectionId: string, data: T): Promise<SyncDocument<T>>;
318
+ setDocument<T>(databaseId: string, collectionId: string, documentId: string, data: T): Promise<void>;
319
+ updateDocument<T>(databaseId: string, collectionId: string, documentId: string, data: Partial<T>): Promise<void>;
320
+ deleteDocument(databaseId: string, collectionId: string, documentId: string): Promise<void>;
321
+ executeBatch(operations: BatchOperation[]): Promise<void>;
322
+ private initRealtime;
323
+ private connectMqtt;
324
+ listenDocument<T>(databaseId: string, collectionId: string, documentId: string, callback: DocumentListener<T>): Unsubscribe;
325
+ listenCollection<T>(databaseId: string, collectionId: string, callback: CollectionListener<T>, options?: QueryOptions): Unsubscribe;
326
+ private resubscribeAll;
327
+ private handleMqttMessage;
328
+ private applyFilters;
329
+ private applyOrdering;
330
+ private generateUUID;
331
+ /**
332
+ * Disconnect from realtime updates
333
+ */
334
+ disconnect(): void;
335
+ }
336
+
337
+ export { type CollectionListener, type DocumentListener, type QueryFilter, type QueryOperator, type QueryOptions, RiviumSyncAdmin, type RiviumSyncAdminConfig, RiviumSyncError, RiviumSyncErrorCode, RiviumSyncLogLevel, SyncCollection, SyncDatabase, type SyncDocument, SyncDocumentRef, SyncQuery, type Unsubscribe, WriteBatch, RiviumSyncAdmin as default };