edmaxlabs-core 1.3.6 → 1.4.7

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/dist/index.d.cts CHANGED
@@ -99,36 +99,6 @@ declare class DocumentSnapshot {
99
99
  toMap(): Record<string, any>;
100
100
  }
101
101
 
102
- declare class ArraySnapshot {
103
- id?: string;
104
- data: Record<string, any>;
105
- dt: Timestamp;
106
- private constructor();
107
- static fromMap(map: Record<string, any>): ArraySnapshot;
108
- toMap(): Record<string, any>;
109
- }
110
-
111
- declare class Array {
112
- private app;
113
- readonly collection: string;
114
- readonly key: string;
115
- readonly docID: string;
116
- private persistence;
117
- private syncEngine;
118
- private localStore;
119
- constructor(app: EdmaxLabs, collection: string, key: string, id: string);
120
- /**
121
- * Get current array elements (offline-first: prefers local cache)
122
- */
123
- show(): Promise<ArraySnapshot[]>;
124
- private refreshFromRemote;
125
- push(data: any, id?: string): Promise<ArraySnapshot | null>;
126
- update(position: number, data: any, id?: string): Promise<ArraySnapshot | null>;
127
- insert(position: number, data: any, id?: string): Promise<ArraySnapshot | null>;
128
- get(position: number): Promise<ArraySnapshot | null>;
129
- remove(position: number): Promise<ArraySnapshot | null>;
130
- }
131
-
132
102
  declare class DocumentRef {
133
103
  private app;
134
104
  readonly collection: string;
@@ -138,23 +108,20 @@ declare class DocumentRef {
138
108
  private localStore;
139
109
  constructor(app: EdmaxLabs, collection: string, id: string);
140
110
  get(): Promise<DocumentSnapshot | null>;
141
- private refreshFromRemote;
142
111
  set(data: Record<string, any>): Promise<DocumentSnapshot | null>;
143
112
  update(data: Record<string, any>): Promise<DocumentSnapshot | null>;
144
113
  delete(): Promise<boolean>;
145
- array(key: string): Array;
146
114
  onSnapshot(callback: (snapshot: DocumentSnapshot | null, change: string) => void): () => void;
147
115
  }
148
116
 
149
- type ChangeType = "init" | "local_create" | "local_update" | "local_delete" | "remote_create" | "remote_update" | "remote_delete" | "sync" | "error";
150
- type DocListener = (snapshot: DocumentSnapshot | null, change: ChangeType) => void;
117
+ type DocListener = (snapshot: DocumentSnapshot | null, change: string) => void;
151
118
  /**
152
119
  * For collection listeners we pass:
153
120
  * - snapshots: all current documents in the collection
154
121
  * - change: what triggered this emission
155
122
  * - changedDocId?: which specific document changed (useful for granular updates)
156
123
  */
157
- type CollectionListener = (snapshots: DocumentSnapshot[], change: ChangeType, changedDocId?: string) => void;
124
+ type CollectionListener = (snapshots: DocumentSnapshot[], change: string, changedDocId?: string) => void;
158
125
  declare class LocalStore {
159
126
  private documentListeners;
160
127
  private collectionListeners;
@@ -164,13 +131,19 @@ declare class LocalStore {
164
131
  /**
165
132
  * Notify all listeners for a specific document
166
133
  */
167
- emitDocument(collection: string, id: string, snapshot: DocumentSnapshot | null, change: ChangeType): void;
134
+ emitDocument(collection: string, id: string, snapshot: DocumentSnapshot | null, change: string): void;
168
135
  /**
169
136
  * Notify all listeners for a collection.
170
137
  * This is the most important fix — collection listeners now receive the full list.
171
138
  */
172
139
  emitCollection(collection: string, snapshots: DocumentSnapshot[], // ← Changed from single snapshot
173
- change: ChangeType, changedDocId?: string): void;
140
+ change: string, changedDocId?: string): void;
141
+ /**
142
+ * OPTIMIZED: Notify collection listeners that something changed, without fetching full collection.
143
+ * Listeners can call getCollectionSnapshots() themselves if they need the full list.
144
+ * This avoids expensive collection queries after every single mutation.
145
+ */
146
+ notifyCollectionChanged(collection: string, changedDocId: string, change: string): void;
174
147
  /**
175
148
  * Clear all listeners (useful for testing or when persistence is disabled)
176
149
  */
@@ -182,6 +155,14 @@ declare class LocalStore {
182
155
  documents: number;
183
156
  collections: number;
184
157
  };
158
+ /**
159
+ * Remove all listeners for a specific collection (useful for cleanup)
160
+ */
161
+ removeCollectionListeners(collection: string): void;
162
+ /**
163
+ * Remove all listeners for a specific document (useful for cleanup)
164
+ */
165
+ removeDocumentListeners(collection: string, id: string): void;
185
166
  }
186
167
 
187
168
  type FilterExpression = {
@@ -193,9 +174,13 @@ declare class Query {
193
174
  private app;
194
175
  private collection;
195
176
  private filter;
177
+ private localStore;
196
178
  constructor(app: EdmaxLabs, collection: string);
197
179
  where(expression: FilterExpression): Query;
198
180
  private buildFilter;
181
+ private matchesFilter;
182
+ private filterDocuments;
183
+ private getLocalFilteredSnapshots;
199
184
  get(): Promise<DocumentSnapshot[]>;
200
185
  private refreshFromRemote;
201
186
  update(data: Record<string, any>): Promise<any>;
@@ -222,6 +207,7 @@ declare class Batch {
222
207
  private ops;
223
208
  constructor(app: EdmaxLabs);
224
209
  set(docRef: DocumentRef, data: any): Batch;
210
+ create(docRef: DocumentRef, data: any): Batch;
225
211
  update(docRef: DocumentRef, data: any): Batch;
226
212
  delete(docRef: DocumentRef): Batch;
227
213
  commit(): Promise<any>;
@@ -277,7 +263,6 @@ declare class Realtime {
277
263
  * Low-level document subscription (used by RealtimeBridge)
278
264
  */
279
265
  subscribeToDocumentRaw(collection: string, id: string, callback: (payload: any, change: string) => void): () => void;
280
- private normalizePayload;
281
266
  private registerSubscription;
282
267
  private resubscribeAll;
283
268
  private cleanupSubscription;
@@ -307,7 +292,7 @@ interface LocalDoc {
307
292
  revision?: string | number;
308
293
  }
309
294
 
310
- type MutationType = "create" | "update" | "delete" | "array_push" | "array_update" | "array_insert" | "array_remove";
295
+ type MutationType = "insert" | "update" | "delete" | "array_push" | "array_update" | "array_insert" | "array_remove";
311
296
  type MutationStatus = "pending" | "syncing" | "failed";
312
297
  interface MutationRecord {
313
298
  mutationId: string;
@@ -325,7 +310,8 @@ interface MutationRecord {
325
310
 
326
311
  declare class Persistence {
327
312
  private dbPromise;
328
- constructor();
313
+ private appName;
314
+ constructor(appName?: string);
329
315
  private docKey;
330
316
  private now;
331
317
  private getDb;
@@ -339,6 +325,8 @@ declare class Persistence {
339
325
  markDeleted(collection: string, id: string, pending?: number): Promise<LocalDoc>;
340
326
  enqueueMutation(mutation: Omit<MutationRecord, "updatedAt" | "createdAt" | "retryCount" | "status">): Promise<MutationRecord>;
341
327
  getPendingMutations(): Promise<MutationRecord[]>;
328
+ getMutation(mutationId: string): Promise<MutationRecord | null>;
329
+ resetMutation(mutationId: string): Promise<MutationRecord | null>;
342
330
  setMutationStatus(mutationId: string, status: MutationRecord["status"], error?: string): Promise<MutationRecord | null>;
343
331
  removeMutation(mutationId: string): Promise<void>;
344
332
  replaceDocId(collection: string, oldId: string, newId: string): Promise<LocalDoc | null>;
@@ -392,6 +380,25 @@ declare class SyncEngine {
392
380
  private syncDelete;
393
381
  private scheduleRetry;
394
382
  forceSync(): Promise<void>;
383
+ /**
384
+ * Get all failed mutations for error handling/UI
385
+ * Returns mutations that exceeded MAX_RETRIES
386
+ */
387
+ getFailedMutations(): Promise<any[]>;
388
+ /**
389
+ * Retry a specific failed mutation by resetting its retry count
390
+ * Useful for user-initiated recovery after fixing network/server issues
391
+ */
392
+ retryMutation(mutationId: string): Promise<boolean>;
393
+ /**
394
+ * Retry all failed mutations at once
395
+ */
396
+ retryAllFailed(): Promise<number>;
397
+ /**
398
+ * Remove a mutation entirely (user acknowledges the failure and wants to discard it)
399
+ * Be careful: this means the operation will never sync to the server
400
+ */
401
+ removeMutation(mutationId: string): Promise<boolean>;
395
402
  dispose(): void;
396
403
  }
397
404
 
@@ -424,6 +431,7 @@ declare class Storage {
424
431
  interface EdmaxLabsConfig {
425
432
  token: string;
426
433
  project: string;
434
+ app_name?: string;
427
435
  persistence?: boolean;
428
436
  default_bucket?: string;
429
437
  }
@@ -448,6 +456,15 @@ declare class EdmaxLabs {
448
456
  get getFunctions(): Functions;
449
457
  get getStorage(): Storage;
450
458
  get getAuthentication(): Authentication;
459
+ /** Check if offline features are enabled */
460
+ get isOfflineEnabled(): boolean;
461
+ /** Get current storage usage (approximate) */
462
+ getStorageUsage(): Promise<{
463
+ used: number;
464
+ available: number;
465
+ } | null>;
466
+ /** Clear all cached data (nuclear option) */
467
+ clearCache(): Promise<void>;
451
468
  /** New clean offline namespace - highly recommended */
452
469
  offline(): {
453
470
  readonly persistence: Persistence | null;
@@ -455,7 +472,25 @@ declare class EdmaxLabs {
455
472
  readonly syncEngine: SyncEngine | null;
456
473
  readonly realtimeBridge: RealtimeBridge | null;
457
474
  readonly enabled: boolean;
475
+ readonly clearListeners: () => void | undefined;
476
+ readonly getListenerCount: () => {
477
+ documents: number;
478
+ collections: number;
479
+ };
458
480
  };
481
+ /**
482
+ * Manually trigger sync of pending mutations
483
+ * Useful for progressive sync or after network restoration
484
+ */
485
+ sync(): Promise<void>;
486
+ /**
487
+ * Get mutations that failed to sync (for error UI)
488
+ */
489
+ getFailedMutations(): Promise<any[]>;
490
+ /**
491
+ * Retry all failed mutations
492
+ */
493
+ retrySync(): Promise<number>;
459
494
  getConfig(): EdmaxLabsConfig;
460
495
  getBaseUrl(): string;
461
496
  getSocketUrl(): string;
@@ -464,4 +499,13 @@ declare class EdmaxLabs {
464
499
  dispose(): void;
465
500
  }
466
501
 
502
+ declare class ArraySnapshot {
503
+ id?: string;
504
+ data: Record<string, any>;
505
+ dt: Timestamp;
506
+ private constructor();
507
+ static fromMap(map: Record<string, any>): ArraySnapshot;
508
+ toMap(): Record<string, any>;
509
+ }
510
+
467
511
  export { ArraySnapshot, Authentication, Credentials, DisplayInfo, DocumentSnapshot, EdmaxLabsConfig, StorageSnapshot, Timestamp, EdmaxLabs as default };
package/dist/index.d.ts CHANGED
@@ -99,36 +99,6 @@ declare class DocumentSnapshot {
99
99
  toMap(): Record<string, any>;
100
100
  }
101
101
 
102
- declare class ArraySnapshot {
103
- id?: string;
104
- data: Record<string, any>;
105
- dt: Timestamp;
106
- private constructor();
107
- static fromMap(map: Record<string, any>): ArraySnapshot;
108
- toMap(): Record<string, any>;
109
- }
110
-
111
- declare class Array {
112
- private app;
113
- readonly collection: string;
114
- readonly key: string;
115
- readonly docID: string;
116
- private persistence;
117
- private syncEngine;
118
- private localStore;
119
- constructor(app: EdmaxLabs, collection: string, key: string, id: string);
120
- /**
121
- * Get current array elements (offline-first: prefers local cache)
122
- */
123
- show(): Promise<ArraySnapshot[]>;
124
- private refreshFromRemote;
125
- push(data: any, id?: string): Promise<ArraySnapshot | null>;
126
- update(position: number, data: any, id?: string): Promise<ArraySnapshot | null>;
127
- insert(position: number, data: any, id?: string): Promise<ArraySnapshot | null>;
128
- get(position: number): Promise<ArraySnapshot | null>;
129
- remove(position: number): Promise<ArraySnapshot | null>;
130
- }
131
-
132
102
  declare class DocumentRef {
133
103
  private app;
134
104
  readonly collection: string;
@@ -138,23 +108,20 @@ declare class DocumentRef {
138
108
  private localStore;
139
109
  constructor(app: EdmaxLabs, collection: string, id: string);
140
110
  get(): Promise<DocumentSnapshot | null>;
141
- private refreshFromRemote;
142
111
  set(data: Record<string, any>): Promise<DocumentSnapshot | null>;
143
112
  update(data: Record<string, any>): Promise<DocumentSnapshot | null>;
144
113
  delete(): Promise<boolean>;
145
- array(key: string): Array;
146
114
  onSnapshot(callback: (snapshot: DocumentSnapshot | null, change: string) => void): () => void;
147
115
  }
148
116
 
149
- type ChangeType = "init" | "local_create" | "local_update" | "local_delete" | "remote_create" | "remote_update" | "remote_delete" | "sync" | "error";
150
- type DocListener = (snapshot: DocumentSnapshot | null, change: ChangeType) => void;
117
+ type DocListener = (snapshot: DocumentSnapshot | null, change: string) => void;
151
118
  /**
152
119
  * For collection listeners we pass:
153
120
  * - snapshots: all current documents in the collection
154
121
  * - change: what triggered this emission
155
122
  * - changedDocId?: which specific document changed (useful for granular updates)
156
123
  */
157
- type CollectionListener = (snapshots: DocumentSnapshot[], change: ChangeType, changedDocId?: string) => void;
124
+ type CollectionListener = (snapshots: DocumentSnapshot[], change: string, changedDocId?: string) => void;
158
125
  declare class LocalStore {
159
126
  private documentListeners;
160
127
  private collectionListeners;
@@ -164,13 +131,19 @@ declare class LocalStore {
164
131
  /**
165
132
  * Notify all listeners for a specific document
166
133
  */
167
- emitDocument(collection: string, id: string, snapshot: DocumentSnapshot | null, change: ChangeType): void;
134
+ emitDocument(collection: string, id: string, snapshot: DocumentSnapshot | null, change: string): void;
168
135
  /**
169
136
  * Notify all listeners for a collection.
170
137
  * This is the most important fix — collection listeners now receive the full list.
171
138
  */
172
139
  emitCollection(collection: string, snapshots: DocumentSnapshot[], // ← Changed from single snapshot
173
- change: ChangeType, changedDocId?: string): void;
140
+ change: string, changedDocId?: string): void;
141
+ /**
142
+ * OPTIMIZED: Notify collection listeners that something changed, without fetching full collection.
143
+ * Listeners can call getCollectionSnapshots() themselves if they need the full list.
144
+ * This avoids expensive collection queries after every single mutation.
145
+ */
146
+ notifyCollectionChanged(collection: string, changedDocId: string, change: string): void;
174
147
  /**
175
148
  * Clear all listeners (useful for testing or when persistence is disabled)
176
149
  */
@@ -182,6 +155,14 @@ declare class LocalStore {
182
155
  documents: number;
183
156
  collections: number;
184
157
  };
158
+ /**
159
+ * Remove all listeners for a specific collection (useful for cleanup)
160
+ */
161
+ removeCollectionListeners(collection: string): void;
162
+ /**
163
+ * Remove all listeners for a specific document (useful for cleanup)
164
+ */
165
+ removeDocumentListeners(collection: string, id: string): void;
185
166
  }
186
167
 
187
168
  type FilterExpression = {
@@ -193,9 +174,13 @@ declare class Query {
193
174
  private app;
194
175
  private collection;
195
176
  private filter;
177
+ private localStore;
196
178
  constructor(app: EdmaxLabs, collection: string);
197
179
  where(expression: FilterExpression): Query;
198
180
  private buildFilter;
181
+ private matchesFilter;
182
+ private filterDocuments;
183
+ private getLocalFilteredSnapshots;
199
184
  get(): Promise<DocumentSnapshot[]>;
200
185
  private refreshFromRemote;
201
186
  update(data: Record<string, any>): Promise<any>;
@@ -222,6 +207,7 @@ declare class Batch {
222
207
  private ops;
223
208
  constructor(app: EdmaxLabs);
224
209
  set(docRef: DocumentRef, data: any): Batch;
210
+ create(docRef: DocumentRef, data: any): Batch;
225
211
  update(docRef: DocumentRef, data: any): Batch;
226
212
  delete(docRef: DocumentRef): Batch;
227
213
  commit(): Promise<any>;
@@ -277,7 +263,6 @@ declare class Realtime {
277
263
  * Low-level document subscription (used by RealtimeBridge)
278
264
  */
279
265
  subscribeToDocumentRaw(collection: string, id: string, callback: (payload: any, change: string) => void): () => void;
280
- private normalizePayload;
281
266
  private registerSubscription;
282
267
  private resubscribeAll;
283
268
  private cleanupSubscription;
@@ -307,7 +292,7 @@ interface LocalDoc {
307
292
  revision?: string | number;
308
293
  }
309
294
 
310
- type MutationType = "create" | "update" | "delete" | "array_push" | "array_update" | "array_insert" | "array_remove";
295
+ type MutationType = "insert" | "update" | "delete" | "array_push" | "array_update" | "array_insert" | "array_remove";
311
296
  type MutationStatus = "pending" | "syncing" | "failed";
312
297
  interface MutationRecord {
313
298
  mutationId: string;
@@ -325,7 +310,8 @@ interface MutationRecord {
325
310
 
326
311
  declare class Persistence {
327
312
  private dbPromise;
328
- constructor();
313
+ private appName;
314
+ constructor(appName?: string);
329
315
  private docKey;
330
316
  private now;
331
317
  private getDb;
@@ -339,6 +325,8 @@ declare class Persistence {
339
325
  markDeleted(collection: string, id: string, pending?: number): Promise<LocalDoc>;
340
326
  enqueueMutation(mutation: Omit<MutationRecord, "updatedAt" | "createdAt" | "retryCount" | "status">): Promise<MutationRecord>;
341
327
  getPendingMutations(): Promise<MutationRecord[]>;
328
+ getMutation(mutationId: string): Promise<MutationRecord | null>;
329
+ resetMutation(mutationId: string): Promise<MutationRecord | null>;
342
330
  setMutationStatus(mutationId: string, status: MutationRecord["status"], error?: string): Promise<MutationRecord | null>;
343
331
  removeMutation(mutationId: string): Promise<void>;
344
332
  replaceDocId(collection: string, oldId: string, newId: string): Promise<LocalDoc | null>;
@@ -392,6 +380,25 @@ declare class SyncEngine {
392
380
  private syncDelete;
393
381
  private scheduleRetry;
394
382
  forceSync(): Promise<void>;
383
+ /**
384
+ * Get all failed mutations for error handling/UI
385
+ * Returns mutations that exceeded MAX_RETRIES
386
+ */
387
+ getFailedMutations(): Promise<any[]>;
388
+ /**
389
+ * Retry a specific failed mutation by resetting its retry count
390
+ * Useful for user-initiated recovery after fixing network/server issues
391
+ */
392
+ retryMutation(mutationId: string): Promise<boolean>;
393
+ /**
394
+ * Retry all failed mutations at once
395
+ */
396
+ retryAllFailed(): Promise<number>;
397
+ /**
398
+ * Remove a mutation entirely (user acknowledges the failure and wants to discard it)
399
+ * Be careful: this means the operation will never sync to the server
400
+ */
401
+ removeMutation(mutationId: string): Promise<boolean>;
395
402
  dispose(): void;
396
403
  }
397
404
 
@@ -424,6 +431,7 @@ declare class Storage {
424
431
  interface EdmaxLabsConfig {
425
432
  token: string;
426
433
  project: string;
434
+ app_name?: string;
427
435
  persistence?: boolean;
428
436
  default_bucket?: string;
429
437
  }
@@ -448,6 +456,15 @@ declare class EdmaxLabs {
448
456
  get getFunctions(): Functions;
449
457
  get getStorage(): Storage;
450
458
  get getAuthentication(): Authentication;
459
+ /** Check if offline features are enabled */
460
+ get isOfflineEnabled(): boolean;
461
+ /** Get current storage usage (approximate) */
462
+ getStorageUsage(): Promise<{
463
+ used: number;
464
+ available: number;
465
+ } | null>;
466
+ /** Clear all cached data (nuclear option) */
467
+ clearCache(): Promise<void>;
451
468
  /** New clean offline namespace - highly recommended */
452
469
  offline(): {
453
470
  readonly persistence: Persistence | null;
@@ -455,7 +472,25 @@ declare class EdmaxLabs {
455
472
  readonly syncEngine: SyncEngine | null;
456
473
  readonly realtimeBridge: RealtimeBridge | null;
457
474
  readonly enabled: boolean;
475
+ readonly clearListeners: () => void | undefined;
476
+ readonly getListenerCount: () => {
477
+ documents: number;
478
+ collections: number;
479
+ };
458
480
  };
481
+ /**
482
+ * Manually trigger sync of pending mutations
483
+ * Useful for progressive sync or after network restoration
484
+ */
485
+ sync(): Promise<void>;
486
+ /**
487
+ * Get mutations that failed to sync (for error UI)
488
+ */
489
+ getFailedMutations(): Promise<any[]>;
490
+ /**
491
+ * Retry all failed mutations
492
+ */
493
+ retrySync(): Promise<number>;
459
494
  getConfig(): EdmaxLabsConfig;
460
495
  getBaseUrl(): string;
461
496
  getSocketUrl(): string;
@@ -464,4 +499,13 @@ declare class EdmaxLabs {
464
499
  dispose(): void;
465
500
  }
466
501
 
502
+ declare class ArraySnapshot {
503
+ id?: string;
504
+ data: Record<string, any>;
505
+ dt: Timestamp;
506
+ private constructor();
507
+ static fromMap(map: Record<string, any>): ArraySnapshot;
508
+ toMap(): Record<string, any>;
509
+ }
510
+
467
511
  export { ArraySnapshot, Authentication, Credentials, DisplayInfo, DocumentSnapshot, EdmaxLabsConfig, StorageSnapshot, Timestamp, EdmaxLabs as default };