@signaldb/sync 2.0.0-beta.7 → 2.0.0-beta.9
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/{sync/src/SyncManager.d.ts → SyncManager.d.ts} +3 -4
- package/dist/{sync/src/applyChanges.d.ts → applyChanges.d.ts} +2 -2
- package/dist/{sync/src/computeChanges.d.ts → computeChanges.d.ts} +1 -1
- package/dist/{sync/src/getSnapshot.d.ts → getSnapshot.d.ts} +2 -2
- package/dist/{sync/src/sync.d.ts → sync.d.ts} +2 -2
- package/dist/{sync/src/types.d.ts → types.d.ts} +1 -1
- package/package.json +2 -2
- package/dist/core/src/AsyncDataAdapter.d.ts +0 -64
- package/dist/core/src/AutoFetchDataAdapter.d.ts +0 -112
- package/dist/core/src/Collection/Cursor.d.ts +0 -113
- package/dist/core/src/Collection/Observer.d.ts +0 -64
- package/dist/core/src/Collection/index.d.ts +0 -294
- package/dist/core/src/Collection/types.d.ts +0 -28
- package/dist/core/src/DataAdapter.d.ts +0 -35
- package/dist/core/src/DefaultDataAdapter.d.ts +0 -35
- package/dist/core/src/WorkerDataAdapter.d.ts +0 -25
- package/dist/core/src/WorkerDataAdapterHost.d.ts +0 -62
- package/dist/core/src/createIndex.d.ts +0 -7
- package/dist/core/src/createIndexProvider.d.ts +0 -8
- package/dist/core/src/createReactivityAdapter.d.ts +0 -8
- package/dist/core/src/createStorageAdapter.d.ts +0 -9
- package/dist/core/src/getIndexInfo.d.ts +0 -39
- package/dist/core/src/index.d.ts +0 -22
- package/dist/core/src/types/Dependency.d.ts +0 -4
- package/dist/core/src/types/IndexProvider.d.ts +0 -26
- package/dist/core/src/types/Modifier.d.ts +0 -46
- package/dist/core/src/types/ReactivityAdapter.d.ts +0 -6
- package/dist/core/src/types/Selector.d.ts +0 -46
- package/dist/core/src/types/Signal.d.ts +0 -4
- package/dist/core/src/types/StorageAdapter.d.ts +0 -20
- package/dist/core/src/utils/EventEmitter.d.ts +0 -71
- package/dist/core/src/utils/batchOnNextTick.d.ts +0 -16
- package/dist/core/src/utils/compact.d.ts +0 -9
- package/dist/core/src/utils/createSignal.d.ts +0 -14
- package/dist/core/src/utils/deepClone.d.ts +0 -17
- package/dist/core/src/utils/get.d.ts +0 -9
- package/dist/core/src/utils/getMatchingKeys.d.ts +0 -19
- package/dist/core/src/utils/intersection.d.ts +0 -9
- package/dist/core/src/utils/isEqual.d.ts +0 -14
- package/dist/core/src/utils/isFieldExpression.d.ts +0 -11
- package/dist/core/src/utils/match.d.ts +0 -12
- package/dist/core/src/utils/modify.d.ts +0 -14
- package/dist/core/src/utils/project.d.ts +0 -15
- package/dist/core/src/utils/queryId.d.ts +0 -9
- package/dist/core/src/utils/randomId.d.ts +0 -7
- package/dist/core/src/utils/reactiveOrAsync.d.ts +0 -59
- package/dist/core/src/utils/serializeValue.d.ts +0 -12
- package/dist/core/src/utils/set.d.ts +0 -13
- package/dist/core/src/utils/sortItems.d.ts +0 -12
- package/dist/core/src/utils/uniqueBy.d.ts +0 -10
- /package/dist/{sync/src/index.d.ts → index.d.ts} +0 -0
- /package/dist/{sync/src/utils → utils}/PromiseQueue.d.ts +0 -0
- /package/dist/{sync/src/utils → utils}/debounce.d.ts +0 -0
|
@@ -1,294 +0,0 @@
|
|
|
1
|
-
import type ReactivityAdapter from '../types/ReactivityAdapter';
|
|
2
|
-
import EventEmitter from '../utils/EventEmitter';
|
|
3
|
-
import type Selector from '../types/Selector';
|
|
4
|
-
import type Modifier from '../types/Modifier';
|
|
5
|
-
import type DataAdapter from '../DataAdapter';
|
|
6
|
-
import type { QueryOptions } from '../DataAdapter';
|
|
7
|
-
import type StorageAdapter from '../types/StorageAdapter';
|
|
8
|
-
import Cursor from './Cursor';
|
|
9
|
-
import type { AsyncFindOptions, BaseItem, FindOptions, SyncFindOptions, Transform, TransformAll } from './types';
|
|
10
|
-
export type { AnyFindOptions, AsyncFindOptions, BaseItem, Transform, TransformAll, SortSpecifier, FieldSpecifier, FindOptions, SyncFindOptions, } from './types';
|
|
11
|
-
export type { CursorOptions } from './Cursor';
|
|
12
|
-
export type { ObserveCallbacks } from './Observer';
|
|
13
|
-
export { default as createIndex } from '../createIndex';
|
|
14
|
-
export interface CollectionOptions<T extends BaseItem<I>, I, E extends BaseItem = T, U = E> {
|
|
15
|
-
/**
|
|
16
|
-
* @deprecated Use new constructor parameters instead.
|
|
17
|
-
*/
|
|
18
|
-
name?: string;
|
|
19
|
-
/**
|
|
20
|
-
* @deprecated Use `DataAdapter` options instead.
|
|
21
|
-
*/
|
|
22
|
-
persistence?: StorageAdapter<T, I>;
|
|
23
|
-
primaryKeyGenerator?: (item: Omit<T, 'id'>) => I;
|
|
24
|
-
reactivity?: ReactivityAdapter;
|
|
25
|
-
transform?: Transform<E, U>;
|
|
26
|
-
transformAll?: TransformAll<T, E>;
|
|
27
|
-
indices?: string[];
|
|
28
|
-
enableDebugMode?: boolean;
|
|
29
|
-
fieldTracking?: boolean;
|
|
30
|
-
}
|
|
31
|
-
interface CollectionEvents<T extends BaseItem, E extends BaseItem = T, U = E> {
|
|
32
|
-
'added': (item: T) => void;
|
|
33
|
-
'changed': (item: T, modifier: Modifier<T>) => void;
|
|
34
|
-
'removed': (item: T) => void;
|
|
35
|
-
'observer.created': <O extends QueryOptions<T>>(selector?: Selector<T>, options?: O) => void;
|
|
36
|
-
'observer.disposed': <O extends QueryOptions<T>>(selector?: Selector<T>, options?: O) => void;
|
|
37
|
-
'getItems': (selector: Selector<T> | undefined) => void;
|
|
38
|
-
'find': <Async extends boolean, O extends FindOptions<T, Async>>(selector: Selector<T> | undefined, options: O | undefined, cursor: Cursor<E, U, Async>) => void;
|
|
39
|
-
'findOne': <O extends QueryOptions<T>>(selector: Selector<T>, options: O | undefined, item: U | undefined) => void;
|
|
40
|
-
'insert': (item: Omit<T, 'id'> & Partial<Pick<T, 'id'>>) => void;
|
|
41
|
-
'updateOne': (selector: Selector<T>, modifier: Modifier<T>) => void;
|
|
42
|
-
'updateMany': (selector: Selector<T>, modifier: Modifier<T>) => void;
|
|
43
|
-
'replaceOne': (selector: Selector<T>, item: Omit<T, 'id'> & Partial<Pick<T, 'id'>>) => void;
|
|
44
|
-
'removeOne': (selector: Selector<T>) => void;
|
|
45
|
-
'removeMany': (selector: Selector<T>) => void;
|
|
46
|
-
'validate': (item: T) => void;
|
|
47
|
-
'_debug.getItems': (callstack: string, selector: Selector<T> | undefined, measuredTime: number) => void;
|
|
48
|
-
'_debug.find': <Async extends boolean, O extends FindOptions<T, Async>>(callstack: string, selector: Selector<T> | undefined, options: O | undefined, cursor: Cursor<E, U, Async>) => void;
|
|
49
|
-
'_debug.findOne': <Async extends boolean, O extends FindOptions<T, Async>>(callstack: string, selector: Selector<T>, options: O | undefined, item: U | undefined) => void;
|
|
50
|
-
'_debug.insert': (callstack: string, item: Omit<T, 'id'> & Partial<Pick<T, 'id'>>) => void;
|
|
51
|
-
'_debug.updateOne': (callstack: string, selector: Selector<T>, modifier: Modifier<T>) => void;
|
|
52
|
-
'_debug.updateMany': (callstack: string, selector: Selector<T>, modifier: Modifier<T>) => void;
|
|
53
|
-
'_debug.replaceOne': (callstack: string, selector: Selector<T>, item: Omit<T, 'id'> & Partial<Pick<T, 'id'>>) => void;
|
|
54
|
-
'_debug.removeOne': (callstack: string, selector: Selector<T>) => void;
|
|
55
|
-
'_debug.removeMany': (callstack: string, selector: Selector<T>) => void;
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Represents a collection of data items with support for in-memory operations,
|
|
59
|
-
* persistence, reactivity, and event-based notifications. The collection provides
|
|
60
|
-
* CRUD operations, observer patterns, and batch operations.
|
|
61
|
-
* @template T - The type of the items stored in the collection.
|
|
62
|
-
* @template I - The type of the unique identifier for the items.
|
|
63
|
-
* @template U - The transformed item type after applying transformations (default is T).
|
|
64
|
-
*/
|
|
65
|
-
export default class Collection<T extends BaseItem<I> = BaseItem, I = any, E extends BaseItem = T, U = E> extends EventEmitter<CollectionEvents<T, E, U>> {
|
|
66
|
-
private static collections;
|
|
67
|
-
private static debugMode;
|
|
68
|
-
private static batchOperationInProgress;
|
|
69
|
-
private static fieldTracking;
|
|
70
|
-
private static onCreationCallbacks;
|
|
71
|
-
private static onDisposeCallbacks;
|
|
72
|
-
static getCollections(): Collection<any, any, any, any>[];
|
|
73
|
-
static onCreation(callback: (collection: Collection<any>) => void): void;
|
|
74
|
-
static onDispose(callback: (collection: Collection<any>) => void): void;
|
|
75
|
-
/**
|
|
76
|
-
* Enables debug mode for all collections.
|
|
77
|
-
*/
|
|
78
|
-
static enableDebugMode: () => void;
|
|
79
|
-
/**
|
|
80
|
-
* Enables field tracking for all collections.
|
|
81
|
-
* @param enable - A boolean indicating whether to enable field tracking.
|
|
82
|
-
*/
|
|
83
|
-
static setFieldTracking: (enable: boolean) => void;
|
|
84
|
-
/**
|
|
85
|
-
* Executes a batch operation, allowing multiple modifications to the collection
|
|
86
|
-
* while deferring index rebuilding until all operations in the batch are completed.
|
|
87
|
-
* This improves performance by avoiding repetitive index recalculations and
|
|
88
|
-
* provides atomicity for the batch of operations.
|
|
89
|
-
* Supports both synchronous and asynchronous callbacks.
|
|
90
|
-
* @param callback - The batch operation to execute.
|
|
91
|
-
* @returns A promise if the callback returns a promise, otherwise `void`.
|
|
92
|
-
*/
|
|
93
|
-
static batch<ReturnType>(callback: () => Promise<ReturnType>): Promise<void>;
|
|
94
|
-
static batch<ReturnType>(callback: () => ReturnType): void;
|
|
95
|
-
readonly name: string;
|
|
96
|
-
private backend;
|
|
97
|
-
private options;
|
|
98
|
-
private isPullingSignal;
|
|
99
|
-
private isPushingSignal;
|
|
100
|
-
private readySignal;
|
|
101
|
-
private debugMode;
|
|
102
|
-
private batchOperationInProgress;
|
|
103
|
-
private isDisposed;
|
|
104
|
-
private postBatchCallbacks;
|
|
105
|
-
private fieldTracking;
|
|
106
|
-
private queryListenersMap;
|
|
107
|
-
/**
|
|
108
|
-
* Initializes a new instance of the `Collection` class with optional configuration.
|
|
109
|
-
* Sets up memory, persistence, reactivity, and indices as specified in the options.
|
|
110
|
-
* @template T - The type of the items stored in the collection.
|
|
111
|
-
* @template I - The type of the unique identifier for the items.
|
|
112
|
-
* @template U - The transformed item type after applying transformations (default is T).
|
|
113
|
-
* @param name - The name of the collection.
|
|
114
|
-
* @param dataAdapter - The data adapter for creating the collection backend.
|
|
115
|
-
* @param options - Optional configuration for the collection.
|
|
116
|
-
* @param options.name - An optional name for the collection.
|
|
117
|
-
* @param options.memory - The in-memory adapter for storing items.
|
|
118
|
-
* @param options.reactivity - The reactivity adapter for observing changes in the collection.
|
|
119
|
-
* @param options.transform - A transformation function to apply to items when retrieving them.
|
|
120
|
-
* @param options.persistence - The persistence adapter for saving and loading items.
|
|
121
|
-
* @param options.indices - An array of index providers for optimized querying.
|
|
122
|
-
* @param options.enableDebugMode - A boolean to enable or disable debug mode.
|
|
123
|
-
* @param options.fieldTracking - A boolean to enable or disable field tracking by default.
|
|
124
|
-
* @param options.transformAll - A function that will be able to solve the n+1 problem
|
|
125
|
-
*/
|
|
126
|
-
constructor(options?: CollectionOptions<T, I, E, U>);
|
|
127
|
-
constructor(name: string, dataAdapter: DataAdapter, options?: CollectionOptions<T, I, E, U>);
|
|
128
|
-
isBatchOperationInProgress(): boolean;
|
|
129
|
-
/**
|
|
130
|
-
* Checks whether the collection is currently performing a pull operation
|
|
131
|
-
* ⚡️ this function is reactive!
|
|
132
|
-
* (loading data from the persistence adapter).
|
|
133
|
-
* @returns A boolean indicating if the collection is in the process of pulling data.
|
|
134
|
-
*/
|
|
135
|
-
isPulling(): boolean;
|
|
136
|
-
/**
|
|
137
|
-
* Checks whether the collection is currently performing a push operation
|
|
138
|
-
* ⚡️ this function is reactive!
|
|
139
|
-
* (saving data to the persistence adapter).
|
|
140
|
-
* @returns A boolean indicating if the collection is in the process of pushing data.
|
|
141
|
-
*/
|
|
142
|
-
isPushing(): boolean;
|
|
143
|
-
/**
|
|
144
|
-
* Checks whether the collection is currently performing either a pull or push operation,
|
|
145
|
-
* ⚡️ this function is reactive!
|
|
146
|
-
* indicating that it is loading or saving data.
|
|
147
|
-
* @returns A boolean indicating if the collection is in the process of loading or saving data.
|
|
148
|
-
*/
|
|
149
|
-
isLoading(): boolean;
|
|
150
|
-
/**
|
|
151
|
-
* Retrieves the current debug mode status of the collection.
|
|
152
|
-
* @returns A boolean indicating whether debug mode is enabled for the collection.
|
|
153
|
-
*/
|
|
154
|
-
getDebugMode(): boolean;
|
|
155
|
-
/**
|
|
156
|
-
* Enables or disables debug mode for the collection.
|
|
157
|
-
* When debug mode is enabled, additional debugging information and events are emitted.
|
|
158
|
-
* @param enable - A boolean indicating whether to enable (`true`) or disable (`false`) debug mode.
|
|
159
|
-
*/
|
|
160
|
-
setDebugMode(enable: boolean): void;
|
|
161
|
-
/**
|
|
162
|
-
* Enables or disables field tracking for the collection.
|
|
163
|
-
* @param enable - A boolean indicating whether to enable (`true`) or disable (`false`) field tracking.
|
|
164
|
-
*/
|
|
165
|
-
setFieldTracking(enable: boolean): void;
|
|
166
|
-
/**
|
|
167
|
-
* Resolves when the persistence adapter finished initializing
|
|
168
|
-
* and the collection is ready to be used.
|
|
169
|
-
* @returns A promise that resolves when the collection is ready.
|
|
170
|
-
* @example
|
|
171
|
-
* ```ts
|
|
172
|
-
* const collection = new Collection({
|
|
173
|
-
* persistence: // ...
|
|
174
|
-
* })
|
|
175
|
-
* await collection.isReady()
|
|
176
|
-
*
|
|
177
|
-
* collection.insert({ name: 'Item 1' })
|
|
178
|
-
*/
|
|
179
|
-
ready(): Promise<void>;
|
|
180
|
-
/**
|
|
181
|
-
* Checks if the collection is ready.
|
|
182
|
-
* ⚡️ this function is reactive!
|
|
183
|
-
* @returns A boolean indicating whether the collection is ready.
|
|
184
|
-
*/
|
|
185
|
-
isReady(): boolean;
|
|
186
|
-
private profile;
|
|
187
|
-
private executeInDebugMode;
|
|
188
|
-
private transform;
|
|
189
|
-
private transformAll;
|
|
190
|
-
private getItem;
|
|
191
|
-
private getItems;
|
|
192
|
-
private withPushState;
|
|
193
|
-
private queryListeners;
|
|
194
|
-
/**
|
|
195
|
-
* Disposes the collection, unregisters persistence adapters, clears memory, and
|
|
196
|
-
* cleans up all resources used by the collection.
|
|
197
|
-
* @returns A promise that resolves when the collection is disposed.
|
|
198
|
-
*/
|
|
199
|
-
dispose(): Promise<void>;
|
|
200
|
-
/**
|
|
201
|
-
* Finds multiple items in the collection based on a selector and optional options.
|
|
202
|
-
* Returns a cursor for reactive data queries.
|
|
203
|
-
* @param [selector] - The criteria to select items.
|
|
204
|
-
* @param [options] - Options for the find operation, such as limit and sort.
|
|
205
|
-
* @returns A cursor to fetch and observe the matching items.
|
|
206
|
-
*/
|
|
207
|
-
find(selector?: Selector<T>, options?: SyncFindOptions<T>): Cursor<E, U, false>;
|
|
208
|
-
find(selector: Selector<T> | undefined, options: AsyncFindOptions<T>): Cursor<E, U, true>;
|
|
209
|
-
find(selector?: Selector<T>, options?: FindOptions<T, boolean>): Cursor<E, U, boolean>;
|
|
210
|
-
/**
|
|
211
|
-
* Finds a single item in the collection based on a selector and optional options.
|
|
212
|
-
* ⚡️ this function is reactive!
|
|
213
|
-
* Returns the found item or undefined if no item matches.
|
|
214
|
-
* @param selector - The criteria to select the item.
|
|
215
|
-
* @param [options] - Options for the find operation, such as projection.
|
|
216
|
-
* @returns The found item or `undefined`.
|
|
217
|
-
*/
|
|
218
|
-
findOne(selector: Selector<T>, options?: Omit<SyncFindOptions<T>, 'limit'>): U | undefined;
|
|
219
|
-
findOne(selector: Selector<T>, options: Omit<AsyncFindOptions<T>, 'limit'>): Promise<U | undefined>;
|
|
220
|
-
findOne(selector: Selector<T>, options?: Omit<FindOptions<T, boolean>, 'limit'>): Promise<U | undefined> | U | undefined;
|
|
221
|
-
/**
|
|
222
|
-
* Performs a batch operation, deferring index rebuilds and allowing multiple
|
|
223
|
-
* modifications to be made atomically. Executes any post-batch callbacks afterwards.
|
|
224
|
-
* @param callback - The batch operation to execute.
|
|
225
|
-
* @returns A promise if the callback returns a promise, otherwise void.
|
|
226
|
-
*/
|
|
227
|
-
batch<ReturnType>(callback: () => Promise<ReturnType>): Promise<void>;
|
|
228
|
-
batch<ReturnType>(callback: () => ReturnType): void;
|
|
229
|
-
onPostBatch(callback: () => void): void;
|
|
230
|
-
/**
|
|
231
|
-
* Inserts a single item into the collection. Generates a unique ID if not provided.
|
|
232
|
-
* @param item - The item to insert.
|
|
233
|
-
* @returns The ID of the inserted item.
|
|
234
|
-
* @throws {Error} If the collection is disposed or the item has an invalid ID.
|
|
235
|
-
*/
|
|
236
|
-
insert(item: Omit<T, 'id'> & Partial<Pick<T, 'id'>>): Promise<I>;
|
|
237
|
-
/**
|
|
238
|
-
* Inserts multiple items into the collection. Generates unique IDs for items if not provided.
|
|
239
|
-
* @param items - The items to insert.
|
|
240
|
-
* @returns An array of IDs of the inserted items.
|
|
241
|
-
* @throws {Error} If the collection is disposed or the items are invalid.
|
|
242
|
-
*/
|
|
243
|
-
insertMany(items: Array<Omit<T, 'id'> & Partial<Pick<T, 'id'>>>): Promise<I[]>;
|
|
244
|
-
/**
|
|
245
|
-
* Updates a single item in the collection that matches the given selector.
|
|
246
|
-
* @param selector - The criteria to select the item to update.
|
|
247
|
-
* @param modifier - The modifications to apply to the item.
|
|
248
|
-
* @param [options] - Optional settings for the update operation.
|
|
249
|
-
* @param [options.upsert] - If `true`, creates a new item if no item matches the selector.
|
|
250
|
-
* @returns The number of items updated (0 or 1).
|
|
251
|
-
* @throws {Error} If the collection is disposed or invalid arguments are provided.
|
|
252
|
-
*/
|
|
253
|
-
updateOne(selector: Selector<T>, modifier: Modifier<T>, options?: {
|
|
254
|
-
upsert?: boolean;
|
|
255
|
-
}): Promise<number>;
|
|
256
|
-
/**
|
|
257
|
-
* Updates multiple items in the collection that match the given selector.
|
|
258
|
-
* @param selector - The criteria to select the items to update.
|
|
259
|
-
* @param modifier - The modifications to apply to the items.
|
|
260
|
-
* @param [options] - Optional settings for the update operation.
|
|
261
|
-
* @param [options.upsert] - If `true`, creates new items if no items match the selector.
|
|
262
|
-
* @returns The number of items updated.
|
|
263
|
-
* @throws {Error} If the collection is disposed or invalid arguments are provided.
|
|
264
|
-
*/
|
|
265
|
-
updateMany(selector: Selector<T>, modifier: Modifier<T>, options?: {
|
|
266
|
-
upsert?: boolean;
|
|
267
|
-
}): Promise<number>;
|
|
268
|
-
/**
|
|
269
|
-
* Replaces a single item in the collection that matches the given selector.
|
|
270
|
-
* @param selector - The criteria to select the item to replace.
|
|
271
|
-
* @param replacement - The item to replace the selected item with.
|
|
272
|
-
* @param [options] - Optional settings for the replace operation.
|
|
273
|
-
* @param [options.upsert] - If `true`, creates a new item if no item matches the selector.
|
|
274
|
-
* @returns The number of items replaced (0 or 1).
|
|
275
|
-
* @throws {Error} If the collection is disposed or invalid arguments are provided.
|
|
276
|
-
*/
|
|
277
|
-
replaceOne(selector: Selector<T>, replacement: Omit<T, 'id'> & Partial<Pick<T, 'id'>>, options?: {
|
|
278
|
-
upsert?: boolean;
|
|
279
|
-
}): Promise<number>;
|
|
280
|
-
/**
|
|
281
|
-
* Removes a single item from the collection that matches the given selector.
|
|
282
|
-
* @param selector - The criteria to select the item to remove.
|
|
283
|
-
* @returns The number of items removed (0 or 1).
|
|
284
|
-
* @throws {Error} If the collection is disposed or invalid arguments are provided.
|
|
285
|
-
*/
|
|
286
|
-
removeOne(selector: Selector<T>): Promise<number>;
|
|
287
|
-
/**
|
|
288
|
-
* Removes multiple items from the collection that match the given selector.
|
|
289
|
-
* @param selector - The criteria to select the items to remove.
|
|
290
|
-
* @returns The number of items removed.
|
|
291
|
-
* @throws {Error} If the collection is disposed or invalid arguments are provided.
|
|
292
|
-
*/
|
|
293
|
-
removeMany(selector: Selector<T>): Promise<number>;
|
|
294
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import type { QueryOptions } from '../DataAdapter';
|
|
2
|
-
import type ReactivityAdapter from '../types/ReactivityAdapter';
|
|
3
|
-
export type BaseItem<I = any> = {
|
|
4
|
-
id: I;
|
|
5
|
-
} & Record<string, any>;
|
|
6
|
-
export type Transform<T, U = T> = ((document: T) => U) | null | undefined;
|
|
7
|
-
export type TransformAll<T extends BaseItem, O extends BaseItem = T> = ((items: T[], fields: FieldSpecifier<O> | undefined) => O[]) | null | undefined;
|
|
8
|
-
export type SortSpecifier<T> = {
|
|
9
|
-
[P in keyof T]?: -1 | 1;
|
|
10
|
-
} & Record<string, -1 | 1>;
|
|
11
|
-
export type FieldSpecifier<T> = {
|
|
12
|
-
[P in keyof T]?: 0 | 1;
|
|
13
|
-
} & Record<string, 0 | 1>;
|
|
14
|
-
export interface FindOptions<T extends BaseItem, Async extends boolean> extends QueryOptions<T> {
|
|
15
|
-
/** pass `false` to disable reactivity */
|
|
16
|
-
reactive?: ReactivityAdapter | false;
|
|
17
|
-
/** pass `true` to enable automatic field-level reactitivy */
|
|
18
|
-
fieldTracking?: boolean;
|
|
19
|
-
/** pass `true` to execute the query asynchronously */
|
|
20
|
-
async?: Async;
|
|
21
|
-
}
|
|
22
|
-
export type AsyncFindOptions<T extends BaseItem> = Omit<FindOptions<T, true>, 'async'> & {
|
|
23
|
-
async: true;
|
|
24
|
-
};
|
|
25
|
-
export type SyncFindOptions<T extends BaseItem> = Omit<FindOptions<T, false>, 'async'> & {
|
|
26
|
-
async?: false;
|
|
27
|
-
};
|
|
28
|
-
export type AnyFindOptions<T extends BaseItem> = AsyncFindOptions<T> | SyncFindOptions<T>;
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import type { BaseItem, FieldSpecifier, SortSpecifier } from './Collection';
|
|
2
|
-
import type Collection from './Collection';
|
|
3
|
-
import type Modifier from './types/Modifier';
|
|
4
|
-
import type Selector from './types/Selector';
|
|
5
|
-
export interface QueryOptions<T extends BaseItem> {
|
|
6
|
-
/** Sort order (default: natural order) */
|
|
7
|
-
sort?: SortSpecifier<T> | undefined;
|
|
8
|
-
/** Number of results to skip at the beginning */
|
|
9
|
-
skip?: number | undefined;
|
|
10
|
-
/** Maximum number of results to return */
|
|
11
|
-
limit?: number | undefined;
|
|
12
|
-
/** Dictionary of fields to return or exclude. */
|
|
13
|
-
fields?: FieldSpecifier<T> | undefined;
|
|
14
|
-
}
|
|
15
|
-
export type StateChangeCallback = (state: 'active' | 'complete' | 'error') => void;
|
|
16
|
-
export interface CollectionBackend<T extends BaseItem<I>, I> {
|
|
17
|
-
insert(item: T): Promise<T>;
|
|
18
|
-
updateOne(selector: Selector<T>, modifier: Modifier<T>): Promise<T[]>;
|
|
19
|
-
updateMany(selector: Selector<T>, modifier: Modifier<T>): Promise<T[]>;
|
|
20
|
-
replaceOne(selector: Selector<T>, replacement: Omit<T, 'id'> & Partial<Pick<T, 'id'>>): Promise<T[]>;
|
|
21
|
-
removeOne(selector: Selector<T>): Promise<T[]>;
|
|
22
|
-
removeMany(selector: Selector<T>): Promise<T[]>;
|
|
23
|
-
registerQuery<O extends QueryOptions<T>>(selector: Selector<T>, options: O): void;
|
|
24
|
-
unregisterQuery<O extends QueryOptions<T>>(selector: Selector<T>, options: O): void;
|
|
25
|
-
getQueryState<O extends QueryOptions<T>>(selector: Selector<T>, options: O): 'active' | 'complete' | 'error';
|
|
26
|
-
getQueryError<O extends QueryOptions<T>>(selector: Selector<T>, options: O): Error | null;
|
|
27
|
-
getQueryResult<O extends QueryOptions<T>>(selector: Selector<T>, options: O): T[];
|
|
28
|
-
executeQuery<O extends QueryOptions<T>>(selector: Selector<T>, options: O): Promise<T[]>;
|
|
29
|
-
onQueryStateChange<O extends QueryOptions<T>>(selector: Selector<T>, options: O, callback: StateChangeCallback): () => void;
|
|
30
|
-
dispose(): Promise<void>;
|
|
31
|
-
isReady(): Promise<void>;
|
|
32
|
-
}
|
|
33
|
-
export default interface DataAdapter {
|
|
34
|
-
createCollectionBackend<T extends BaseItem<I>, I = any, E extends BaseItem = T, U = E>(collection: Collection<T, I, E, U>, indices: string[]): CollectionBackend<T, I>;
|
|
35
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import type { BaseItem } from './Collection';
|
|
2
|
-
import type Collection from './Collection';
|
|
3
|
-
import type DataAdapter from './DataAdapter';
|
|
4
|
-
import type { CollectionBackend } from './DataAdapter';
|
|
5
|
-
import type StorageAdapter from './types/StorageAdapter';
|
|
6
|
-
interface DefaultDataAdapterOptions {
|
|
7
|
-
storage?: (name: string) => StorageAdapter<any, any> | undefined;
|
|
8
|
-
onError?: (name: string, error: Error) => void;
|
|
9
|
-
}
|
|
10
|
-
export default class DefaultDataAdapter implements DataAdapter {
|
|
11
|
-
private items;
|
|
12
|
-
private options;
|
|
13
|
-
private storageAdapters;
|
|
14
|
-
private collections;
|
|
15
|
-
private indices;
|
|
16
|
-
private activeQueries;
|
|
17
|
-
private queryEmitters;
|
|
18
|
-
private queuedQueryUpdates;
|
|
19
|
-
private cachedQueryResults;
|
|
20
|
-
constructor(options?: DefaultDataAdapterOptions);
|
|
21
|
-
private ensureStorageAdapter;
|
|
22
|
-
private rebuildIndices;
|
|
23
|
-
private setupStorageAdapter;
|
|
24
|
-
private getIndexInfo;
|
|
25
|
-
private applyIndexDeltas;
|
|
26
|
-
private getItem;
|
|
27
|
-
private queryItems;
|
|
28
|
-
private executeQuery;
|
|
29
|
-
private flushQueuedQueryUpdates;
|
|
30
|
-
private executeAndCacheQuery;
|
|
31
|
-
private updateQueries;
|
|
32
|
-
createCollectionBackend<T extends BaseItem<I>, I = any, E extends BaseItem = T, U = E>(collection: Collection<T, I, E, U>, indices: string[]): CollectionBackend<T, I>;
|
|
33
|
-
fetchItemsFromStorage<T extends BaseItem<I>, I = any, E extends BaseItem = T, U = E>(collection?: Collection<T, I, E, U>): Promise<void>;
|
|
34
|
-
}
|
|
35
|
-
export {};
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import type { BaseItem } from './Collection';
|
|
2
|
-
import type Collection from './Collection';
|
|
3
|
-
import type DataAdapter from './DataAdapter';
|
|
4
|
-
import type { CollectionBackend } from './DataAdapter';
|
|
5
|
-
interface WorkerDataAdapterOptions {
|
|
6
|
-
id?: string;
|
|
7
|
-
log?: (message: string, ...args: any[]) => void;
|
|
8
|
-
}
|
|
9
|
-
export default class WorkerDataAdapter implements DataAdapter {
|
|
10
|
-
private worker;
|
|
11
|
-
private options;
|
|
12
|
-
private id;
|
|
13
|
-
private isDisposed;
|
|
14
|
-
private workerReady;
|
|
15
|
-
private log;
|
|
16
|
-
private collectionReady;
|
|
17
|
-
private batchExecutionHelpers;
|
|
18
|
-
private queries;
|
|
19
|
-
constructor(worker: Worker, options: WorkerDataAdapterOptions);
|
|
20
|
-
private exec;
|
|
21
|
-
private enqueueBatched;
|
|
22
|
-
private updateQuery;
|
|
23
|
-
createCollectionBackend<T extends BaseItem<I>, I = any, E extends BaseItem = T, U = E>(collection: Collection<T, I, E, U>, indices: string[]): CollectionBackend<T, I>;
|
|
24
|
-
}
|
|
25
|
-
export {};
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import type { BaseItem } from './Collection';
|
|
2
|
-
import type { QueryOptions } from './DataAdapter';
|
|
3
|
-
import type Modifier from './types/Modifier';
|
|
4
|
-
import type StorageAdapter from './types/StorageAdapter';
|
|
5
|
-
import type Selector from './types/Selector';
|
|
6
|
-
interface WorkerContext {
|
|
7
|
-
addEventListener: (type: 'message', listener: (event: MessageEvent) => any) => void;
|
|
8
|
-
postMessage: (message: any) => void;
|
|
9
|
-
}
|
|
10
|
-
interface WorkerDataAdapterHostOptions {
|
|
11
|
-
id?: string;
|
|
12
|
-
storage: (name: string) => StorageAdapter<any, any>;
|
|
13
|
-
onError?: (error: Error) => void;
|
|
14
|
-
log?: (message: string, ...args: any[]) => void;
|
|
15
|
-
}
|
|
16
|
-
type CollectionMethods<T extends BaseItem<I>, I = any> = {
|
|
17
|
-
registerCollection: (collectionName: string, indices: string[]) => Promise<void>;
|
|
18
|
-
unregisterCollection: (collectionName: string) => Promise<void>;
|
|
19
|
-
registerQuery: <O extends QueryOptions<T>>(collectionName: string, selector: Selector<T>, options?: O) => Promise<void>;
|
|
20
|
-
unregisterQuery: <O extends QueryOptions<T>>(collectionName: string, selector: Selector<T>, options?: O) => Promise<void>;
|
|
21
|
-
executeQuery: <O extends QueryOptions<T>>(collectionName: string, selector: Selector<T>, options?: O) => Promise<T[]>;
|
|
22
|
-
insert: (collectionName: string, items: [T][]) => Promise<(T | Error)[]>;
|
|
23
|
-
updateOne: (collectionName: string, args: [Selector<T>, Modifier<T>][]) => Promise<(T[] | Error)[]>;
|
|
24
|
-
updateMany: (collectionName: string, args: [Selector<T>, Modifier<T>][]) => Promise<(T[] | Error)[]>;
|
|
25
|
-
replaceOne: (collectionName: string, args: [Selector<T>, Omit<T, 'id'> & Partial<Pick<T, 'id'>>][]) => Promise<(T[] | Error)[]>;
|
|
26
|
-
removeOne: (collectionName: string, selectors: [Selector<T>][]) => Promise<(T[] | Error)[]>;
|
|
27
|
-
removeMany: (collectionName: string, selectors: [Selector<T>][]) => Promise<(T[] | Error)[]>;
|
|
28
|
-
isReady: (collectionName: string) => Promise<void>;
|
|
29
|
-
};
|
|
30
|
-
export default class WorkerDataAdapterHost<T extends BaseItem<I>, I = any> {
|
|
31
|
-
private workerContext;
|
|
32
|
-
private options;
|
|
33
|
-
private id;
|
|
34
|
-
private log;
|
|
35
|
-
private storageAdapters;
|
|
36
|
-
private storageAdapterReady;
|
|
37
|
-
private collectionIndices;
|
|
38
|
-
private queries;
|
|
39
|
-
private onError;
|
|
40
|
-
constructor(workerContext: WorkerContext, options: WorkerDataAdapterHostOptions);
|
|
41
|
-
private respond;
|
|
42
|
-
private handleMessage;
|
|
43
|
-
private getIndexInfo;
|
|
44
|
-
private queryItems;
|
|
45
|
-
private executeQuery;
|
|
46
|
-
private ensureQuery;
|
|
47
|
-
private emitQueryUpdate;
|
|
48
|
-
private ensureStorageAdapter;
|
|
49
|
-
private checkQueryUpdates;
|
|
50
|
-
protected registerCollection: CollectionMethods<T, I>['registerCollection'];
|
|
51
|
-
protected unregisterCollection: CollectionMethods<T, I>['unregisterCollection'];
|
|
52
|
-
protected registerQuery: CollectionMethods<T, I>['registerQuery'];
|
|
53
|
-
protected unregisterQuery: CollectionMethods<T, I>['unregisterQuery'];
|
|
54
|
-
protected insert: CollectionMethods<T, I>['insert'];
|
|
55
|
-
protected updateOne: CollectionMethods<T, I>['updateOne'];
|
|
56
|
-
protected updateMany: CollectionMethods<T, I>['updateMany'];
|
|
57
|
-
protected replaceOne: CollectionMethods<T, I>['replaceOne'];
|
|
58
|
-
protected removeOne: CollectionMethods<T, I>['removeOne'];
|
|
59
|
-
protected removeMany: CollectionMethods<T, I>['removeMany'];
|
|
60
|
-
protected isReady: CollectionMethods<T, I>['isReady'];
|
|
61
|
-
}
|
|
62
|
-
export {};
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { BaseItem } from './Collection/types';
|
|
2
|
-
/**
|
|
3
|
-
* creates an index for a specific field
|
|
4
|
-
* @param field name of the field
|
|
5
|
-
* @returns an index provider to pass to the `indices` option of the collection constructor
|
|
6
|
-
*/
|
|
7
|
-
export default function createIndex<T extends BaseItem<I> = BaseItem, I = any>(field: string): import("./types/IndexProvider").default<T, I>;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { BaseItem } from './Collection';
|
|
2
|
-
import type IndexProvider from './types/IndexProvider';
|
|
3
|
-
/**
|
|
4
|
-
* Creates an IndexProvider based on the given definition.
|
|
5
|
-
* @param definition - The definition of the IndexProvider.
|
|
6
|
-
* @returns The created IndexProvider.
|
|
7
|
-
*/
|
|
8
|
-
export default function createIndexProvider<T extends BaseItem<I> = BaseItem, I = any>(definition: IndexProvider<T, I>): IndexProvider<T, I>;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type Dependency from './types/Dependency';
|
|
2
|
-
import type ReactivityAdapter from './types/ReactivityAdapter';
|
|
3
|
-
/**
|
|
4
|
-
* Creates an ReactivityAdapter based on the given definition.
|
|
5
|
-
* @param definition - The definition of the ReactivityAdapter.
|
|
6
|
-
* @returns The created ReactivityAdapter.
|
|
7
|
-
*/
|
|
8
|
-
export default function createReactivityAdapter<T extends Dependency = Dependency>(definition: ReactivityAdapter<T>): ReactivityAdapter<T>;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type StorageAdapter from './types/StorageAdapter';
|
|
2
|
-
/**
|
|
3
|
-
* Creates an StorageAdapter based on the given definition.
|
|
4
|
-
* @param definition - The definition of the StorageAdapter.
|
|
5
|
-
* @returns The created StorageAdapter.
|
|
6
|
-
*/
|
|
7
|
-
export default function createStorageAdapter<T extends {
|
|
8
|
-
id: I;
|
|
9
|
-
} & Record<string, any>, I>(definition: StorageAdapter<T, I>): StorageAdapter<T, I>;
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import type { AsynchronousQueryFunction, SynchronousQueryFunction } from './types/IndexProvider';
|
|
2
|
-
import type { FlatSelector } from './types/Selector';
|
|
3
|
-
import type Selector from './types/Selector';
|
|
4
|
-
import type { BaseItem } from './Collection/types';
|
|
5
|
-
type IndexInfo<T extends BaseItem<I> = BaseItem, I = any> = {
|
|
6
|
-
matched: boolean;
|
|
7
|
-
ids: I[];
|
|
8
|
-
optimizedSelector: FlatSelector<T>;
|
|
9
|
-
};
|
|
10
|
-
/**
|
|
11
|
-
* Retrieves merged index information for a given flat selector by querying multiple
|
|
12
|
-
* index providers. Combines results from all index providers to determine matched ids
|
|
13
|
-
* and an optimized selector.
|
|
14
|
-
* @template T - The type of the items in the collection.
|
|
15
|
-
* @template I - The type of the unique identifier for the items.
|
|
16
|
-
* @param queryFunctions - An array of index providers to query.
|
|
17
|
-
* @param selector - The flat selector used to filter items.
|
|
18
|
-
* @returns An object containing:
|
|
19
|
-
* - `matched`: A boolean indicating if the selector matched any items.
|
|
20
|
-
* - `ids`: An array of matched item ids.
|
|
21
|
-
* - `optimizedSelector`: A flat selector optimized based on the index results.
|
|
22
|
-
*/
|
|
23
|
-
export declare function getMergedIndexInfo<T extends BaseItem<I> = BaseItem, I = any>(queryFunctions: (SynchronousQueryFunction<T, I> | AsynchronousQueryFunction<T, I>)[], selector: FlatSelector<T>): IndexInfo<T, I> | Promise<IndexInfo<T, I>>;
|
|
24
|
-
/**
|
|
25
|
-
* Retrieves index information for a given complex selector by querying multiple
|
|
26
|
-
* index providers. Handles nested `$and` and `$or` conditions in the selector and
|
|
27
|
-
* optimizes the selector to minimize processing overhead.
|
|
28
|
-
* @template T - The type of the items in the collection.
|
|
29
|
-
* @template I - The type of the unique identifier for the items.
|
|
30
|
-
* @param queryFunctions - An array of index providers to query.
|
|
31
|
-
* @param selector - The complex selector used to filter items.
|
|
32
|
-
* @returns An object containing:
|
|
33
|
-
* - `matched`: A boolean indicating if the selector matched any items.
|
|
34
|
-
* - `ids`: An array of matched item ids.
|
|
35
|
-
* - `optimizedSelector`: A selector optimized based on the index results, with unused
|
|
36
|
-
* conditions removed.
|
|
37
|
-
*/
|
|
38
|
-
export default function getIndexInfo<QueryFunction extends SynchronousQueryFunction<T, I> | AsynchronousQueryFunction<T, I>, T extends BaseItem<I> = BaseItem, I = any>(queryFunctions: QueryFunction[], selector: Selector<T>): QueryFunction extends AsynchronousQueryFunction<T, I> ? Promise<IndexInfo<T, I>> : IndexInfo<T, I>;
|
|
39
|
-
export {};
|
package/dist/core/src/index.d.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
export type { default as ReactivityAdapter } from './types/ReactivityAdapter';
|
|
2
|
-
export type { default as StorageAdapter, Changeset, } from './types/StorageAdapter';
|
|
3
|
-
export type { default as Selector } from './types/Selector';
|
|
4
|
-
export type { default as Modifier } from './types/Modifier';
|
|
5
|
-
export type { BaseItem, ObserveCallbacks, CursorOptions, Transform, TransformAll, SortSpecifier, FieldSpecifier, AnyFindOptions, AsyncFindOptions, FindOptions, SyncFindOptions, CollectionOptions, } from './Collection';
|
|
6
|
-
export type { default as DataAdapter } from './DataAdapter';
|
|
7
|
-
export { default as Cursor } from './Collection/Cursor';
|
|
8
|
-
export { default as Collection } from './Collection';
|
|
9
|
-
export { default as createStorageAdapter } from './createStorageAdapter';
|
|
10
|
-
export { default as createReactivityAdapter } from './createReactivityAdapter';
|
|
11
|
-
export { default as isEqual } from './utils/isEqual';
|
|
12
|
-
export { default as modify } from './utils/modify';
|
|
13
|
-
export { default as randomId } from './utils/randomId';
|
|
14
|
-
export { default as EventEmitter } from './utils/EventEmitter';
|
|
15
|
-
export { default as get } from './utils/get';
|
|
16
|
-
export { default as serializeValue } from './utils/serializeValue';
|
|
17
|
-
export { default as reactiveOrAsync, unwrap } from './utils/reactiveOrAsync';
|
|
18
|
-
export { default as DefaultDataAdapter } from './DefaultDataAdapter';
|
|
19
|
-
export { default as AsyncDataAdapter } from './AsyncDataAdapter';
|
|
20
|
-
export { default as WorkerDataAdapter } from './WorkerDataAdapter';
|
|
21
|
-
export { default as WorkerDataAdapterHost } from './WorkerDataAdapterHost';
|
|
22
|
-
export { default as AutoFetchDataAdapter } from './AutoFetchDataAdapter';
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import type { BaseItem } from '../Collection';
|
|
2
|
-
import type { FlatSelector } from './Selector';
|
|
3
|
-
export type IndexResult<IdType> = {
|
|
4
|
-
ids: IdType[];
|
|
5
|
-
fields: string[];
|
|
6
|
-
keepSelector?: boolean;
|
|
7
|
-
matched: true;
|
|
8
|
-
} | {
|
|
9
|
-
ids?: never;
|
|
10
|
-
fields?: never;
|
|
11
|
-
keepSelector?: never;
|
|
12
|
-
matched: false;
|
|
13
|
-
};
|
|
14
|
-
export type SynchronousQueryFunction<T extends BaseItem<I> = BaseItem, I = any> = (selector: FlatSelector<T>) => IndexResult<I>;
|
|
15
|
-
export type AsynchronousQueryFunction<T extends BaseItem<I> = BaseItem, I = any> = (selector: FlatSelector<T>) => Promise<IndexResult<I>>;
|
|
16
|
-
interface IndexProvider<T extends BaseItem<I> = BaseItem, I = any> {
|
|
17
|
-
query: SynchronousQueryFunction<T, I>;
|
|
18
|
-
rebuild(items: T[]): void;
|
|
19
|
-
insert(items: T[]): void;
|
|
20
|
-
remove(items: T[]): void;
|
|
21
|
-
update(pairs: {
|
|
22
|
-
oldItem: T;
|
|
23
|
-
newItem: T;
|
|
24
|
-
}[]): void;
|
|
25
|
-
}
|
|
26
|
-
export default IndexProvider;
|