@signaldb/sync 2.0.0-beta.0 → 2.0.0-beta.10

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,7 +1,6 @@
1
- import type { BaseItem, StorageAdapter, ReactivityAdapter, Changeset } from '@signaldb/core';
2
- import { Collection } from '@signaldb/core';
3
- import PromiseQueue from './utils/PromiseQueue';
4
- import type { Change, LoadResponse, Snapshot, SyncOperation } from './types';
1
+ import { BaseItem, DataAdapter, ReactivityAdapter, Changeset, Collection } from '@signaldb/core';
2
+ import { default as PromiseQueue } from './utils/PromiseQueue';
3
+ import { Change, LoadResponse, Snapshot, SyncOperation } from './types';
5
4
  type SyncOptions<T extends Record<string, any>> = {
6
5
  name: string;
7
6
  } & T;
@@ -19,7 +18,7 @@ interface Options<CollectionOptions extends Record<string, any>, ItemType extend
19
18
  }) => Promise<void>;
20
19
  registerRemoteChange?: (collectionOptions: SyncOptions<CollectionOptions>, onChange: (data?: LoadResponse<ItemType>) => Promise<void>) => CleanupFunction | Promise<CleanupFunction>;
21
20
  id?: string;
22
- storageAdapter?: (id: string, registerErrorHandler: (handler: (error: Error) => void) => void) => StorageAdapter<any, any>;
21
+ dataAdapter?: DataAdapter;
23
22
  reactivity?: ReactivityAdapter;
24
23
  onError?: (collectionOptions: SyncOptions<CollectionOptions>, error: Error) => void;
25
24
  autostart?: boolean;
@@ -66,7 +65,7 @@ export default class SyncManager<CollectionOptions extends Record<string, any>,
66
65
  protected scheduledPushes: Set<string>;
67
66
  protected remoteChanges: Omit<Change, 'id' | 'time'>[];
68
67
  protected syncQueues: Map<string, PromiseQueue>;
69
- protected persistenceReady: Promise<void>;
68
+ protected collectionsReady: Promise<void>;
70
69
  protected isDisposed: boolean;
71
70
  protected instanceId: string;
72
71
  protected id: string;
@@ -84,10 +83,6 @@ export default class SyncManager<CollectionOptions extends Record<string, any>,
84
83
  * @param [options.debounceTime] The time in milliseconds to debounce push operations.
85
84
  */
86
85
  constructor(options: Options<CollectionOptions, ItemType, IdType>);
87
- protected createStorageAdapter(name: string): {
88
- adapter: StorageAdapter<any, any>;
89
- handler: (error: Error) => void;
90
- } | undefined;
91
86
  protected getSyncQueue(name: string): PromiseQueue;
92
87
  /**
93
88
  * Clears all internal data structures
@@ -97,14 +92,14 @@ export default class SyncManager<CollectionOptions extends Record<string, any>,
97
92
  * Gets a collection with it's options by name
98
93
  * @deprecated Use getCollectionProperties instead.
99
94
  * @param name Name of the collection
100
- * @throws Will throw an error if the name wasn't found
95
+ * @throws {Error} Will throw an error if the name wasn't found
101
96
  * @returns Tuple of collection and options
102
97
  */
103
- getCollection(name: string): (Collection<ItemType, IdType, any> | SyncOptions<CollectionOptions>)[];
98
+ getCollection(name: string): (Collection<ItemType, IdType, any, any> | SyncOptions<CollectionOptions>)[];
104
99
  /**
105
100
  * Gets collection options by name
106
101
  * @param name Name of the collection
107
- * @throws Will throw an error if the name wasn't found
102
+ * @throws {Error} Will throw an error if the name wasn't found
108
103
  * @returns An object of all properties of the collection
109
104
  */
110
105
  getCollectionProperties(name: string): {
@@ -120,7 +115,7 @@ export default class SyncManager<CollectionOptions extends Record<string, any>,
120
115
  * @param options Options for the collection. The object needs at least a `name` property.
121
116
  * @param options.name Unique name of the collection
122
117
  */
123
- addCollection(collection: Collection<ItemType, IdType, any>, options: SyncOptions<CollectionOptions>): void;
118
+ addCollection<CollectionItem extends ItemType = ItemType>(collection: Collection<CollectionItem, IdType, any>, options: SyncOptions<CollectionOptions>): void;
124
119
  protected flushScheduledPushes(): void;
125
120
  protected schedulePush(name: string): void;
126
121
  /**
@@ -154,9 +149,11 @@ export default class SyncManager<CollectionOptions extends Record<string, any>,
154
149
  /**
155
150
  * Checks if a collection is currently beeing synced
156
151
  * @param [name] Name of the collection. If not provided, it will check if any collection is currently beeing synced.
157
- * @returns True if the collection is currently beeing synced, false otherwise.
152
+ * @param [async] If true, it will check for active syncs in the database. This is useful if you have multiple instances of the application running.
153
+ * @returns True if the collection is currently beeing synced, false otherwise. If async is true, it will return a promise that resolves to true or false.
158
154
  */
159
- isSyncing(name?: string): boolean;
155
+ isSyncing(name: string | undefined, async: true): Promise<boolean>;
156
+ isSyncing(name?: string, async?: false): boolean;
160
157
  /**
161
158
  * Checks if the sync manager is ready to sync.
162
159
  * @returns A promise that resolves when the sync manager is ready to sync.
@@ -1,5 +1,5 @@
1
- import type { BaseItem } from '@signaldb/core';
2
- import type { Change } from './types';
1
+ import { BaseItem } from '@signaldb/core';
2
+ import { Change } from './types';
3
3
  /**
4
4
  * applies changes to a collection of items
5
5
  * @param items The items to apply the changes to
@@ -1,4 +1,4 @@
1
- import type { BaseItem } from '@signaldb/core';
1
+ import { BaseItem } from '@signaldb/core';
2
2
  /**
3
3
  * Computes the modified fields between two items recursively.
4
4
  * @param oldItem The old item
@@ -1,5 +1,5 @@
1
- import type { BaseItem } from '@signaldb/core';
2
- import type { LoadResponse } from './types';
1
+ import { BaseItem } from '@signaldb/core';
2
+ import { LoadResponse } from './types';
3
3
  /**
4
4
  * Gets the snapshot of items from the last snapshot and the changes.
5
5
  * @param lastSnapshot The last snapshot of items