@signaldb/core 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.
- package/dist/.vite/manifest.json +128 -75
- package/dist/AsyncDataAdapter.d.ts +44 -7
- package/dist/AutoFetchDataAdapter.d.ts +5 -8
- package/dist/Collection/Cursor.d.ts +6 -5
- package/dist/Collection/Observer.d.ts +2 -0
- package/dist/Collection/index.d.ts +36 -25
- package/dist/Collection/types.d.ts +10 -2
- package/dist/DataAdapter.d.ts +18 -11
- package/dist/DefaultDataAdapter.d.ts +7 -6
- package/dist/WorkerDataAdapter.d.ts +7 -6
- package/dist/WorkerDataAdapterHost.d.ts +14 -11
- package/dist/createIndex.d.ts +2 -2
- package/dist/createIndexProvider.d.ts +2 -2
- package/dist/createReactivityAdapter.d.ts +2 -2
- package/dist/createStorageAdapter.d.ts +1 -1
- package/dist/getIndexInfo.d.ts +3 -4
- package/dist/index.cjs.js +33 -31
- package/dist/index.d.ts +3 -1
- package/dist/index.mjs +17 -32
- package/dist/index10.cjs.js +23 -0
- package/dist/index10.mjs +21 -17
- package/dist/index11.cjs.js +45 -0
- package/dist/index11.mjs +44 -15
- package/dist/index12.cjs.js +22 -0
- package/dist/index12.mjs +21 -339
- package/dist/index13.cjs.js +45 -0
- package/dist/index13.mjs +44 -407
- package/dist/index14.cjs.js +86 -0
- package/dist/index14.mjs +85 -190
- package/dist/index15.cjs.js +15 -0
- package/dist/index15.mjs +14 -341
- package/dist/index16.cjs.js +136 -0
- package/dist/index16.mjs +134 -569
- package/dist/index17.cjs.js +47 -0
- package/dist/index17.mjs +46 -150
- package/dist/index18.cjs.js +15 -0
- package/dist/index18.mjs +14 -26
- package/dist/index19.cjs.js +23 -0
- package/dist/index19.mjs +22 -42
- package/dist/index2.cjs.js +33 -0
- package/dist/index2.mjs +32 -254
- package/dist/index20.cjs.js +37 -0
- package/dist/index20.mjs +36 -104
- package/dist/index21.cjs.js +35 -0
- package/dist/index21.mjs +34 -128
- package/dist/index22.cjs.js +25 -0
- package/dist/index22.mjs +24 -7
- package/dist/index23.cjs.js +19 -0
- package/dist/index23.mjs +17 -26
- package/dist/index24.cjs.js +342 -0
- package/dist/index24.mjs +340 -6
- package/dist/index25.cjs.js +542 -0
- package/dist/index25.mjs +541 -10
- package/dist/index26.cjs.js +11 -0
- package/dist/index26.mjs +10 -29
- package/dist/index27.cjs.js +11 -0
- package/dist/index27.mjs +10 -5
- package/dist/index28.cjs.js +90 -0
- package/dist/index28.mjs +89 -8
- package/dist/index29.cjs.js +424 -0
- package/dist/index29.mjs +423 -29
- package/dist/index3.cjs.js +19 -0
- package/dist/index3.mjs +18 -537
- package/dist/index30.cjs.js +72 -0
- package/dist/index30.mjs +71 -42
- package/dist/index31.cjs.js +191 -0
- package/dist/index31.mjs +190 -9
- package/dist/index32.cjs.js +21 -0
- package/dist/index32.mjs +21 -0
- package/dist/index33.cjs.js +336 -0
- package/dist/index33.mjs +336 -0
- package/dist/index34.cjs.js +539 -0
- package/dist/index34.mjs +539 -0
- package/dist/index4.cjs.js +150 -0
- package/dist/index4.mjs +149 -5
- package/dist/index5.cjs.js +254 -0
- package/dist/index5.mjs +252 -4
- package/dist/index6.cjs.js +125 -0
- package/dist/index6.mjs +124 -29
- package/dist/index7.cjs.js +33 -0
- package/dist/index7.mjs +32 -12
- package/dist/index8.cjs.js +12 -0
- package/dist/index8.mjs +10 -4
- package/dist/index9.cjs.js +11 -0
- package/dist/index9.mjs +10 -133
- package/dist/types/IndexProvider.d.ts +2 -2
- package/dist/types/Modifier.d.ts +1 -1
- package/dist/types/ReactivityAdapter.d.ts +1 -1
- package/dist/utils/batchOnNextTick.d.ts +16 -0
- package/dist/utils/createSignal.d.ts +2 -2
- package/dist/utils/deepClone.d.ts +1 -1
- package/dist/utils/getMatchingKeys.d.ts +2 -2
- package/dist/utils/isFieldExpression.d.ts +1 -1
- package/dist/utils/match.d.ts +1 -1
- package/dist/utils/modify.d.ts +1 -1
- package/dist/utils/queryId.d.ts +2 -2
- package/dist/utils/reactiveOrAsync.d.ts +59 -0
- package/package.json +3 -3
- package/dist/index.cjs10.js +0 -18
- package/dist/index.cjs11.js +0 -15
- package/dist/index.cjs12.js +0 -339
- package/dist/index.cjs13.js +0 -407
- package/dist/index.cjs14.js +0 -190
- package/dist/index.cjs15.js +0 -341
- package/dist/index.cjs16.js +0 -570
- package/dist/index.cjs17.js +0 -150
- package/dist/index.cjs18.js +0 -26
- package/dist/index.cjs19.js +0 -43
- package/dist/index.cjs2.js +0 -255
- package/dist/index.cjs20.js +0 -104
- package/dist/index.cjs21.js +0 -129
- package/dist/index.cjs22.js +0 -7
- package/dist/index.cjs23.js +0 -27
- package/dist/index.cjs24.js +0 -7
- package/dist/index.cjs25.js +0 -10
- package/dist/index.cjs26.js +0 -29
- package/dist/index.cjs27.js +0 -5
- package/dist/index.cjs28.js +0 -7
- package/dist/index.cjs29.js +0 -29
- package/dist/index.cjs3.js +0 -538
- package/dist/index.cjs30.js +0 -42
- package/dist/index.cjs31.js +0 -9
- package/dist/index.cjs4.js +0 -5
- package/dist/index.cjs5.js +0 -5
- package/dist/index.cjs6.js +0 -29
- package/dist/index.cjs7.js +0 -12
- package/dist/index.cjs8.js +0 -5
- package/dist/index.cjs9.js +0 -133
|
@@ -1,17 +1,16 @@
|
|
|
1
|
-
import
|
|
2
|
-
import EventEmitter from '../utils/EventEmitter';
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
|
|
10
|
-
export type { BaseItem, Transform, SortSpecifier, FieldSpecifier, FindOptions } from './types';
|
|
1
|
+
import { default as ReactivityAdapter } from '../types/ReactivityAdapter';
|
|
2
|
+
import { default as EventEmitter } from '../utils/EventEmitter';
|
|
3
|
+
import { default as Selector } from '../types/Selector';
|
|
4
|
+
import { default as Modifier } from '../types/Modifier';
|
|
5
|
+
import { default as DataAdapter, QueryOptions } from '../DataAdapter';
|
|
6
|
+
import { default as StorageAdapter } from '../types/StorageAdapter';
|
|
7
|
+
import { default as Cursor } from './Cursor';
|
|
8
|
+
import { AsyncFindOptions, BaseItem, FindOptions, SyncFindOptions, Transform, TransformAll } from './types';
|
|
9
|
+
export type { AnyFindOptions, AsyncFindOptions, BaseItem, Transform, TransformAll, SortSpecifier, FieldSpecifier, FindOptions, SyncFindOptions, } from './types';
|
|
11
10
|
export type { CursorOptions } from './Cursor';
|
|
12
11
|
export type { ObserveCallbacks } from './Observer';
|
|
13
12
|
export { default as createIndex } from '../createIndex';
|
|
14
|
-
export interface CollectionOptions<T extends BaseItem<I>, I, U =
|
|
13
|
+
export interface CollectionOptions<T extends BaseItem<I>, I, E extends BaseItem = T, U = E> {
|
|
15
14
|
/**
|
|
16
15
|
* @deprecated Use new constructor parameters instead.
|
|
17
16
|
*/
|
|
@@ -22,19 +21,26 @@ export interface CollectionOptions<T extends BaseItem<I>, I, U = T> {
|
|
|
22
21
|
persistence?: StorageAdapter<T, I>;
|
|
23
22
|
primaryKeyGenerator?: (item: Omit<T, 'id'>) => I;
|
|
24
23
|
reactivity?: ReactivityAdapter;
|
|
25
|
-
transform?: Transform<
|
|
24
|
+
transform?: Transform<E, U>;
|
|
25
|
+
transformAll?: TransformAll<T, E>;
|
|
26
26
|
indices?: string[];
|
|
27
27
|
enableDebugMode?: boolean;
|
|
28
28
|
fieldTracking?: boolean;
|
|
29
29
|
}
|
|
30
|
-
interface CollectionEvents<T extends BaseItem, U =
|
|
30
|
+
interface CollectionEvents<T extends BaseItem, E extends BaseItem = T, U = E> {
|
|
31
31
|
'added': (item: T) => void;
|
|
32
32
|
'changed': (item: T, modifier: Modifier<T>) => void;
|
|
33
33
|
'removed': (item: T) => void;
|
|
34
34
|
'observer.created': <O extends QueryOptions<T>>(selector?: Selector<T>, options?: O) => void;
|
|
35
35
|
'observer.disposed': <O extends QueryOptions<T>>(selector?: Selector<T>, options?: O) => void;
|
|
36
|
+
/**
|
|
37
|
+
* A query backing at least one live cursor failed and will not deliver
|
|
38
|
+
* results. The cursor keeps returning its neutral empty value, so without
|
|
39
|
+
* listening here a consumer cannot distinguish failure from "no data".
|
|
40
|
+
*/
|
|
41
|
+
'query.error': <O extends QueryOptions<T>>(error: Error, selector?: Selector<T>, options?: O) => void;
|
|
36
42
|
'getItems': (selector: Selector<T> | undefined) => void;
|
|
37
|
-
'find': <O extends FindOptions<T, Async
|
|
43
|
+
'find': <Async extends boolean, O extends FindOptions<T, Async>>(selector: Selector<T> | undefined, options: O | undefined, cursor: Cursor<E, U, Async>) => void;
|
|
38
44
|
'findOne': <O extends QueryOptions<T>>(selector: Selector<T>, options: O | undefined, item: U | undefined) => void;
|
|
39
45
|
'insert': (item: Omit<T, 'id'> & Partial<Pick<T, 'id'>>) => void;
|
|
40
46
|
'updateOne': (selector: Selector<T>, modifier: Modifier<T>) => void;
|
|
@@ -44,8 +50,8 @@ interface CollectionEvents<T extends BaseItem, U = T> {
|
|
|
44
50
|
'removeMany': (selector: Selector<T>) => void;
|
|
45
51
|
'validate': (item: T) => void;
|
|
46
52
|
'_debug.getItems': (callstack: string, selector: Selector<T> | undefined, measuredTime: number) => void;
|
|
47
|
-
'_debug.find': <O extends FindOptions<T, Async
|
|
48
|
-
'_debug.findOne': <O extends FindOptions<T, Async
|
|
53
|
+
'_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;
|
|
54
|
+
'_debug.findOne': <Async extends boolean, O extends FindOptions<T, Async>>(callstack: string, selector: Selector<T>, options: O | undefined, item: U | undefined) => void;
|
|
49
55
|
'_debug.insert': (callstack: string, item: Omit<T, 'id'> & Partial<Pick<T, 'id'>>) => void;
|
|
50
56
|
'_debug.updateOne': (callstack: string, selector: Selector<T>, modifier: Modifier<T>) => void;
|
|
51
57
|
'_debug.updateMany': (callstack: string, selector: Selector<T>, modifier: Modifier<T>) => void;
|
|
@@ -61,14 +67,14 @@ interface CollectionEvents<T extends BaseItem, U = T> {
|
|
|
61
67
|
* @template I - The type of the unique identifier for the items.
|
|
62
68
|
* @template U - The transformed item type after applying transformations (default is T).
|
|
63
69
|
*/
|
|
64
|
-
export default class Collection<T extends BaseItem<I> = BaseItem, I = any, U =
|
|
70
|
+
export default class Collection<T extends BaseItem<I> = BaseItem, I = any, E extends BaseItem = T, U = E> extends EventEmitter<CollectionEvents<T, E, U>> {
|
|
65
71
|
private static collections;
|
|
66
72
|
private static debugMode;
|
|
67
73
|
private static batchOperationInProgress;
|
|
68
74
|
private static fieldTracking;
|
|
69
75
|
private static onCreationCallbacks;
|
|
70
76
|
private static onDisposeCallbacks;
|
|
71
|
-
static getCollections(): Collection<any, any, any>[];
|
|
77
|
+
static getCollections(): Collection<any, any, any, any>[];
|
|
72
78
|
static onCreation(callback: (collection: Collection<any>) => void): void;
|
|
73
79
|
static onDispose(callback: (collection: Collection<any>) => void): void;
|
|
74
80
|
/**
|
|
@@ -102,6 +108,7 @@ export default class Collection<T extends BaseItem<I> = BaseItem, I = any, U = T
|
|
|
102
108
|
private isDisposed;
|
|
103
109
|
private postBatchCallbacks;
|
|
104
110
|
private fieldTracking;
|
|
111
|
+
private queryListenersMap;
|
|
105
112
|
/**
|
|
106
113
|
* Initializes a new instance of the `Collection` class with optional configuration.
|
|
107
114
|
* Sets up memory, persistence, reactivity, and indices as specified in the options.
|
|
@@ -119,9 +126,10 @@ export default class Collection<T extends BaseItem<I> = BaseItem, I = any, U = T
|
|
|
119
126
|
* @param options.indices - An array of index providers for optimized querying.
|
|
120
127
|
* @param options.enableDebugMode - A boolean to enable or disable debug mode.
|
|
121
128
|
* @param options.fieldTracking - A boolean to enable or disable field tracking by default.
|
|
129
|
+
* @param options.transformAll - A function that will be able to solve the n+1 problem
|
|
122
130
|
*/
|
|
123
|
-
constructor(options?: CollectionOptions<T, I, U>);
|
|
124
|
-
constructor(name: string, dataAdapter: DataAdapter, options?: CollectionOptions<T, I, U>);
|
|
131
|
+
constructor(options?: CollectionOptions<T, I, E, U>);
|
|
132
|
+
constructor(name: string, dataAdapter: DataAdapter, options?: CollectionOptions<T, I, E, U>);
|
|
125
133
|
isBatchOperationInProgress(): boolean;
|
|
126
134
|
/**
|
|
127
135
|
* Checks whether the collection is currently performing a pull operation
|
|
@@ -183,9 +191,11 @@ export default class Collection<T extends BaseItem<I> = BaseItem, I = any, U = T
|
|
|
183
191
|
private profile;
|
|
184
192
|
private executeInDebugMode;
|
|
185
193
|
private transform;
|
|
194
|
+
private transformAll;
|
|
186
195
|
private getItem;
|
|
187
196
|
private getItems;
|
|
188
197
|
private withPushState;
|
|
198
|
+
private queryListeners;
|
|
189
199
|
/**
|
|
190
200
|
* Disposes the collection, unregisters persistence adapters, clears memory, and
|
|
191
201
|
* cleans up all resources used by the collection.
|
|
@@ -195,23 +205,24 @@ export default class Collection<T extends BaseItem<I> = BaseItem, I = any, U = T
|
|
|
195
205
|
/**
|
|
196
206
|
* Finds multiple items in the collection based on a selector and optional options.
|
|
197
207
|
* Returns a cursor for reactive data queries.
|
|
198
|
-
* @template O - The options type for the find operation.
|
|
199
208
|
* @param [selector] - The criteria to select items.
|
|
200
209
|
* @param [options] - Options for the find operation, such as limit and sort.
|
|
201
210
|
* @returns A cursor to fetch and observe the matching items.
|
|
202
211
|
*/
|
|
203
|
-
find
|
|
212
|
+
find(selector?: Selector<T>, options?: SyncFindOptions<T>): Cursor<E, U, false>;
|
|
213
|
+
find(selector: Selector<T> | undefined, options: AsyncFindOptions<T>): Cursor<E, U, true>;
|
|
214
|
+
find(selector?: Selector<T>, options?: FindOptions<T, boolean>): Cursor<E, U, boolean>;
|
|
204
215
|
/**
|
|
205
216
|
* Finds a single item in the collection based on a selector and optional options.
|
|
206
217
|
* ⚡️ this function is reactive!
|
|
207
218
|
* Returns the found item or undefined if no item matches.
|
|
208
|
-
* @template Async - Whether to perform the operation asynchronously.
|
|
209
|
-
* @template O - The options type for the find operation.
|
|
210
219
|
* @param selector - The criteria to select the item.
|
|
211
220
|
* @param [options] - Options for the find operation, such as projection.
|
|
212
221
|
* @returns The found item or `undefined`.
|
|
213
222
|
*/
|
|
214
|
-
findOne
|
|
223
|
+
findOne(selector: Selector<T>, options?: Omit<SyncFindOptions<T>, 'limit'>): U | undefined;
|
|
224
|
+
findOne(selector: Selector<T>, options: Omit<AsyncFindOptions<T>, 'limit'>): Promise<U | undefined>;
|
|
225
|
+
findOne(selector: Selector<T>, options?: Omit<FindOptions<T, boolean>, 'limit'>): Promise<U | undefined> | U | undefined;
|
|
215
226
|
/**
|
|
216
227
|
* Performs a batch operation, deferring index rebuilds and allowing multiple
|
|
217
228
|
* modifications to be made atomically. Executes any post-batch callbacks afterwards.
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import { QueryOptions } from '../DataAdapter';
|
|
2
|
+
import { default as ReactivityAdapter } from '../types/ReactivityAdapter';
|
|
3
3
|
export type BaseItem<I = any> = {
|
|
4
4
|
id: I;
|
|
5
5
|
} & Record<string, any>;
|
|
6
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;
|
|
7
8
|
export type SortSpecifier<T> = {
|
|
8
9
|
[P in keyof T]?: -1 | 1;
|
|
9
10
|
} & Record<string, -1 | 1>;
|
|
@@ -18,3 +19,10 @@ export interface FindOptions<T extends BaseItem, Async extends boolean> extends
|
|
|
18
19
|
/** pass `true` to execute the query asynchronously */
|
|
19
20
|
async?: Async;
|
|
20
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>;
|
package/dist/DataAdapter.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import type Selector from './types/Selector';
|
|
1
|
+
import { BaseItem, FieldSpecifier, SortSpecifier, default as Collection } from './Collection';
|
|
2
|
+
import { default as Modifier } from './types/Modifier';
|
|
3
|
+
import { default as Selector } from './types/Selector';
|
|
5
4
|
export interface QueryOptions<T extends BaseItem> {
|
|
6
5
|
/** Sort order (default: natural order) */
|
|
7
6
|
sort?: SortSpecifier<T> | undefined;
|
|
@@ -12,6 +11,7 @@ export interface QueryOptions<T extends BaseItem> {
|
|
|
12
11
|
/** Dictionary of fields to return or exclude. */
|
|
13
12
|
fields?: FieldSpecifier<T> | undefined;
|
|
14
13
|
}
|
|
14
|
+
export type StateChangeCallback = (state: 'active' | 'complete' | 'error') => void;
|
|
15
15
|
export interface CollectionBackend<T extends BaseItem<I>, I> {
|
|
16
16
|
insert(item: T): Promise<T>;
|
|
17
17
|
updateOne(selector: Selector<T>, modifier: Modifier<T>): Promise<T[]>;
|
|
@@ -19,15 +19,22 @@ export interface CollectionBackend<T extends BaseItem<I>, I> {
|
|
|
19
19
|
replaceOne(selector: Selector<T>, replacement: Omit<T, 'id'> & Partial<Pick<T, 'id'>>): Promise<T[]>;
|
|
20
20
|
removeOne(selector: Selector<T>): Promise<T[]>;
|
|
21
21
|
removeMany(selector: Selector<T>): Promise<T[]>;
|
|
22
|
-
registerQuery<O extends QueryOptions<T>>(selector: Selector<T>, options
|
|
23
|
-
unregisterQuery<O extends QueryOptions<T>>(selector: Selector<T>, options
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
22
|
+
registerQuery<O extends QueryOptions<T>>(selector: Selector<T>, options: O): void;
|
|
23
|
+
unregisterQuery<O extends QueryOptions<T>>(selector: Selector<T>, options: O): void;
|
|
24
|
+
/**
|
|
25
|
+
* Re-runs a query that is currently in the `'error'` state. Optional so
|
|
26
|
+
* existing custom adapters keep compiling — an adapter that never surfaces
|
|
27
|
+
* an error state has nothing to implement.
|
|
28
|
+
*/
|
|
29
|
+
retryQuery?<O extends QueryOptions<T>>(selector: Selector<T>, options: O): void;
|
|
30
|
+
getQueryState<O extends QueryOptions<T>>(selector: Selector<T>, options: O): 'active' | 'complete' | 'error';
|
|
31
|
+
getQueryError<O extends QueryOptions<T>>(selector: Selector<T>, options: O): Error | null;
|
|
32
|
+
getQueryResult<O extends QueryOptions<T>>(selector: Selector<T>, options: O): T[];
|
|
33
|
+
executeQuery<O extends QueryOptions<T>>(selector: Selector<T>, options: O): Promise<T[]>;
|
|
34
|
+
onQueryStateChange<O extends QueryOptions<T>>(selector: Selector<T>, options: O, callback: StateChangeCallback): () => void;
|
|
28
35
|
dispose(): Promise<void>;
|
|
29
36
|
isReady(): Promise<void>;
|
|
30
37
|
}
|
|
31
38
|
export default interface DataAdapter {
|
|
32
|
-
createCollectionBackend<T extends BaseItem<I>, I = any, U =
|
|
39
|
+
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
40
|
}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import type { CollectionBackend } from './DataAdapter';
|
|
5
|
-
import type StorageAdapter from './types/StorageAdapter';
|
|
1
|
+
import { BaseItem, default as Collection } from './Collection';
|
|
2
|
+
import { default as DataAdapter, CollectionBackend } from './DataAdapter';
|
|
3
|
+
import { default as StorageAdapter } from './types/StorageAdapter';
|
|
6
4
|
interface DefaultDataAdapterOptions {
|
|
7
5
|
storage?: (name: string) => StorageAdapter<any, any> | undefined;
|
|
8
6
|
onError?: (name: string, error: Error) => void;
|
|
@@ -11,6 +9,7 @@ export default class DefaultDataAdapter implements DataAdapter {
|
|
|
11
9
|
private items;
|
|
12
10
|
private options;
|
|
13
11
|
private storageAdapters;
|
|
12
|
+
private collections;
|
|
14
13
|
private indices;
|
|
15
14
|
private activeQueries;
|
|
16
15
|
private queryEmitters;
|
|
@@ -26,7 +25,9 @@ export default class DefaultDataAdapter implements DataAdapter {
|
|
|
26
25
|
private queryItems;
|
|
27
26
|
private executeQuery;
|
|
28
27
|
private flushQueuedQueryUpdates;
|
|
28
|
+
private executeAndCacheQuery;
|
|
29
29
|
private updateQueries;
|
|
30
|
-
createCollectionBackend<T extends BaseItem<I>, I = any, U =
|
|
30
|
+
createCollectionBackend<T extends BaseItem<I>, I = any, E extends BaseItem = T, U = E>(collection: Collection<T, I, E, U>, indices: string[]): CollectionBackend<T, I>;
|
|
31
|
+
fetchItemsFromStorage<T extends BaseItem<I>, I = any, E extends BaseItem = T, U = E>(collection?: Collection<T, I, E, U>): Promise<void>;
|
|
31
32
|
}
|
|
32
33
|
export {};
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import type DataAdapter from './DataAdapter';
|
|
4
|
-
import type { CollectionBackend } from './DataAdapter';
|
|
1
|
+
import { BaseItem, default as Collection } from './Collection';
|
|
2
|
+
import { default as DataAdapter, CollectionBackend } from './DataAdapter';
|
|
5
3
|
interface WorkerDataAdapterOptions {
|
|
6
4
|
id?: string;
|
|
5
|
+
log?: (message: string, ...args: any[]) => void;
|
|
7
6
|
}
|
|
8
7
|
export default class WorkerDataAdapter implements DataAdapter {
|
|
9
8
|
private worker;
|
|
@@ -11,12 +10,14 @@ export default class WorkerDataAdapter implements DataAdapter {
|
|
|
11
10
|
private id;
|
|
12
11
|
private isDisposed;
|
|
13
12
|
private workerReady;
|
|
13
|
+
private log;
|
|
14
14
|
private collectionReady;
|
|
15
|
+
private batchExecutionHelpers;
|
|
15
16
|
private queries;
|
|
16
17
|
constructor(worker: Worker, options: WorkerDataAdapterOptions);
|
|
17
18
|
private exec;
|
|
18
|
-
private
|
|
19
|
+
private enqueueBatched;
|
|
19
20
|
private updateQuery;
|
|
20
|
-
createCollectionBackend<T extends BaseItem<I>, I = any, U =
|
|
21
|
+
createCollectionBackend<T extends BaseItem<I>, I = any, E extends BaseItem = T, U = E>(collection: Collection<T, I, E, U>, indices: string[]): CollectionBackend<T, I>;
|
|
21
22
|
}
|
|
22
23
|
export {};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
1
|
+
import { BaseItem } from './Collection';
|
|
2
|
+
import { QueryOptions } from './DataAdapter';
|
|
3
|
+
import { default as Modifier } from './types/Modifier';
|
|
4
|
+
import { default as StorageAdapter } from './types/StorageAdapter';
|
|
5
|
+
import { default as Selector } from './types/Selector';
|
|
6
6
|
interface WorkerContext {
|
|
7
7
|
addEventListener: (type: 'message', listener: (event: MessageEvent) => any) => void;
|
|
8
8
|
postMessage: (message: any) => void;
|
|
@@ -11,24 +11,27 @@ interface WorkerDataAdapterHostOptions {
|
|
|
11
11
|
id?: string;
|
|
12
12
|
storage: (name: string) => StorageAdapter<any, any>;
|
|
13
13
|
onError?: (error: Error) => void;
|
|
14
|
+
log?: (message: string, ...args: any[]) => void;
|
|
14
15
|
}
|
|
15
16
|
type CollectionMethods<T extends BaseItem<I>, I = any> = {
|
|
16
17
|
registerCollection: (collectionName: string, indices: string[]) => Promise<void>;
|
|
17
18
|
unregisterCollection: (collectionName: string) => Promise<void>;
|
|
18
19
|
registerQuery: <O extends QueryOptions<T>>(collectionName: string, selector: Selector<T>, options?: O) => Promise<void>;
|
|
19
20
|
unregisterQuery: <O extends QueryOptions<T>>(collectionName: string, selector: Selector<T>, options?: O) => Promise<void>;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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)[]>;
|
|
26
28
|
isReady: (collectionName: string) => Promise<void>;
|
|
27
29
|
};
|
|
28
30
|
export default class WorkerDataAdapterHost<T extends BaseItem<I>, I = any> {
|
|
29
31
|
private workerContext;
|
|
30
32
|
private options;
|
|
31
33
|
private id;
|
|
34
|
+
private log;
|
|
32
35
|
private storageAdapters;
|
|
33
36
|
private storageAdapterReady;
|
|
34
37
|
private collectionIndices;
|
package/dist/createIndex.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { BaseItem } from './Collection/types';
|
|
2
2
|
/**
|
|
3
3
|
* creates an index for a specific field
|
|
4
4
|
* @param field name of the field
|
|
5
5
|
* @returns an index provider to pass to the `indices` option of the collection constructor
|
|
6
6
|
*/
|
|
7
|
-
export default function createIndex<T extends BaseItem<I> = BaseItem, I = any>(field: string): import(
|
|
7
|
+
export default function createIndex<T extends BaseItem<I> = BaseItem, I = any>(field: string): import('./types/IndexProvider').default<T, I>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import { BaseItem } from './Collection';
|
|
2
|
+
import { default as IndexProvider } from './types/IndexProvider';
|
|
3
3
|
/**
|
|
4
4
|
* Creates an IndexProvider based on the given definition.
|
|
5
5
|
* @param definition - The definition of the IndexProvider.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import { default as Dependency } from './types/Dependency';
|
|
2
|
+
import { default as ReactivityAdapter } from './types/ReactivityAdapter';
|
|
3
3
|
/**
|
|
4
4
|
* Creates an ReactivityAdapter based on the given definition.
|
|
5
5
|
* @param definition - The definition of the ReactivityAdapter.
|
package/dist/getIndexInfo.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import type { BaseItem } from './Collection/types';
|
|
1
|
+
import { AsynchronousQueryFunction, SynchronousQueryFunction } from './types/IndexProvider';
|
|
2
|
+
import { FlatSelector, default as Selector } from './types/Selector';
|
|
3
|
+
import { BaseItem } from './Collection/types';
|
|
5
4
|
type IndexInfo<T extends BaseItem<I> = BaseItem, I = any> = {
|
|
6
5
|
matched: boolean;
|
|
7
6
|
ids: I[];
|
package/dist/index.cjs.js
CHANGED
|
@@ -1,32 +1,34 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
exports.
|
|
20
|
-
exports.
|
|
21
|
-
exports.
|
|
22
|
-
exports.
|
|
23
|
-
exports.
|
|
24
|
-
exports.
|
|
25
|
-
exports.
|
|
26
|
-
exports.
|
|
27
|
-
exports.
|
|
28
|
-
exports.
|
|
29
|
-
exports.
|
|
30
|
-
exports.
|
|
31
|
-
exports.
|
|
32
|
-
exports.
|
|
2
|
+
const require_isEqual = require("./index2.cjs.js");
|
|
3
|
+
const require_Cursor = require("./index5.cjs.js");
|
|
4
|
+
const require_EventEmitter = require("./index6.cjs.js");
|
|
5
|
+
const require_randomId = require("./index8.cjs.js");
|
|
6
|
+
const require_get = require("./index10.cjs.js");
|
|
7
|
+
const require_serializeValue = require("./index12.cjs.js");
|
|
8
|
+
const require_modify = require("./index19.cjs.js");
|
|
9
|
+
const require_DefaultDataAdapter = require("./index24.cjs.js");
|
|
10
|
+
const require_index = require("./index25.cjs.js");
|
|
11
|
+
const require_createStorageAdapter = require("./index26.cjs.js");
|
|
12
|
+
const require_createReactivityAdapter = require("./index27.cjs.js");
|
|
13
|
+
const require_reactiveOrAsync = require("./index28.cjs.js");
|
|
14
|
+
const require_AsyncDataAdapter = require("./index29.cjs.js");
|
|
15
|
+
const require_WorkerDataAdapter = require("./index31.cjs.js");
|
|
16
|
+
const require_WorkerDataAdapterHost = require("./index33.cjs.js");
|
|
17
|
+
const require_AutoFetchDataAdapter = require("./index34.cjs.js");
|
|
18
|
+
exports.AsyncDataAdapter = require_AsyncDataAdapter.default;
|
|
19
|
+
exports.AutoFetchDataAdapter = require_AutoFetchDataAdapter.default;
|
|
20
|
+
exports.Collection = require_index.default;
|
|
21
|
+
exports.Cursor = require_Cursor.default;
|
|
22
|
+
exports.DefaultDataAdapter = require_DefaultDataAdapter.default;
|
|
23
|
+
exports.EventEmitter = require_EventEmitter.default;
|
|
24
|
+
exports.WorkerDataAdapter = require_WorkerDataAdapter.default;
|
|
25
|
+
exports.WorkerDataAdapterHost = require_WorkerDataAdapterHost.default;
|
|
26
|
+
exports.createReactivityAdapter = require_createReactivityAdapter.default;
|
|
27
|
+
exports.createStorageAdapter = require_createStorageAdapter.default;
|
|
28
|
+
exports.get = require_get.default;
|
|
29
|
+
exports.isEqual = require_isEqual.default;
|
|
30
|
+
exports.modify = require_modify.default;
|
|
31
|
+
exports.randomId = require_randomId.default;
|
|
32
|
+
exports.reactiveOrAsync = require_reactiveOrAsync.default;
|
|
33
|
+
exports.serializeValue = require_serializeValue.default;
|
|
34
|
+
exports.unwrap = require_reactiveOrAsync.unwrap;
|
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,8 @@ export type { default as ReactivityAdapter } from './types/ReactivityAdapter';
|
|
|
2
2
|
export type { default as StorageAdapter, Changeset, } from './types/StorageAdapter';
|
|
3
3
|
export type { default as Selector } from './types/Selector';
|
|
4
4
|
export type { default as Modifier } from './types/Modifier';
|
|
5
|
-
export type { BaseItem, ObserveCallbacks, CursorOptions, Transform, SortSpecifier, FieldSpecifier, FindOptions, CollectionOptions, } from './Collection';
|
|
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';
|
|
6
7
|
export { default as Cursor } from './Collection/Cursor';
|
|
7
8
|
export { default as Collection } from './Collection';
|
|
8
9
|
export { default as createStorageAdapter } from './createStorageAdapter';
|
|
@@ -13,6 +14,7 @@ export { default as randomId } from './utils/randomId';
|
|
|
13
14
|
export { default as EventEmitter } from './utils/EventEmitter';
|
|
14
15
|
export { default as get } from './utils/get';
|
|
15
16
|
export { default as serializeValue } from './utils/serializeValue';
|
|
17
|
+
export { default as reactiveOrAsync, unwrap } from './utils/reactiveOrAsync';
|
|
16
18
|
export { default as DefaultDataAdapter } from './DefaultDataAdapter';
|
|
17
19
|
export { default as AsyncDataAdapter } from './AsyncDataAdapter';
|
|
18
20
|
export { default as WorkerDataAdapter } from './WorkerDataAdapter';
|
package/dist/index.mjs
CHANGED
|
@@ -1,32 +1,17 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import {
|
|
13
|
-
import
|
|
14
|
-
import
|
|
15
|
-
import
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
default16 as AutoFetchDataAdapter,
|
|
19
|
-
default3 as Collection,
|
|
20
|
-
default2 as Cursor,
|
|
21
|
-
default12 as DefaultDataAdapter,
|
|
22
|
-
default9 as EventEmitter,
|
|
23
|
-
default14 as WorkerDataAdapter,
|
|
24
|
-
default15 as WorkerDataAdapterHost,
|
|
25
|
-
default5 as createReactivityAdapter,
|
|
26
|
-
default4 as createStorageAdapter,
|
|
27
|
-
default10 as get,
|
|
28
|
-
default6 as isEqual,
|
|
29
|
-
default7 as modify,
|
|
30
|
-
default8 as randomId,
|
|
31
|
-
default11 as serializeValue
|
|
32
|
-
};
|
|
1
|
+
import isEqual from "./index2.mjs";
|
|
2
|
+
import Cursor from "./index5.mjs";
|
|
3
|
+
import EventEmitter from "./index6.mjs";
|
|
4
|
+
import randomId from "./index8.mjs";
|
|
5
|
+
import get from "./index10.mjs";
|
|
6
|
+
import serializeValue from "./index12.mjs";
|
|
7
|
+
import modify from "./index19.mjs";
|
|
8
|
+
import DefaultDataAdapter from "./index24.mjs";
|
|
9
|
+
import Collection from "./index25.mjs";
|
|
10
|
+
import createStorageAdapter from "./index26.mjs";
|
|
11
|
+
import createReactivityAdapter from "./index27.mjs";
|
|
12
|
+
import reactiveOrAsync, { unwrap } from "./index28.mjs";
|
|
13
|
+
import AsyncDataAdapter from "./index29.mjs";
|
|
14
|
+
import WorkerDataAdapter from "./index31.mjs";
|
|
15
|
+
import WorkerDataAdapterHost from "./index33.mjs";
|
|
16
|
+
import AutoFetchDataAdapter from "./index34.mjs";
|
|
17
|
+
export { AsyncDataAdapter, AutoFetchDataAdapter, Collection, Cursor, DefaultDataAdapter, EventEmitter, WorkerDataAdapter, WorkerDataAdapterHost, createReactivityAdapter, createStorageAdapter, get, isEqual, modify, randomId, reactiveOrAsync, serializeValue, unwrap };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
//#region src/utils/get.ts
|
|
2
|
+
/**
|
|
3
|
+
* Retrieves the value at a specified path within an object.
|
|
4
|
+
* Supports dot and bracket notation for navigating nested properties.
|
|
5
|
+
* @template T - The type of the object to retrieve the value from.
|
|
6
|
+
* @param value - The object to navigate.
|
|
7
|
+
* @param path - The path (dot or bracket notation) to the desired value.
|
|
8
|
+
* @returns The value at the specified path, or `undefined` if the path does not exist.
|
|
9
|
+
*/
|
|
10
|
+
function get(value, path) {
|
|
11
|
+
const normalized = path.replaceAll(/\[(\w+)\]/g, ".$1");
|
|
12
|
+
if (normalized.includes("..") || normalized.startsWith(".") || normalized.endsWith(".")) return;
|
|
13
|
+
const segments = normalized.split(".");
|
|
14
|
+
let current = value;
|
|
15
|
+
for (const key of segments) {
|
|
16
|
+
if (current == null) return;
|
|
17
|
+
current = current[key];
|
|
18
|
+
}
|
|
19
|
+
if (current === void 0) return;
|
|
20
|
+
return current;
|
|
21
|
+
}
|
|
22
|
+
//#endregion
|
|
23
|
+
exports.default = get;
|
package/dist/index10.mjs
CHANGED
|
@@ -1,19 +1,23 @@
|
|
|
1
|
+
//#region src/utils/get.ts
|
|
2
|
+
/**
|
|
3
|
+
* Retrieves the value at a specified path within an object.
|
|
4
|
+
* Supports dot and bracket notation for navigating nested properties.
|
|
5
|
+
* @template T - The type of the object to retrieve the value from.
|
|
6
|
+
* @param value - The object to navigate.
|
|
7
|
+
* @param path - The path (dot or bracket notation) to the desired value.
|
|
8
|
+
* @returns The value at the specified path, or `undefined` if the path does not exist.
|
|
9
|
+
*/
|
|
1
10
|
function get(value, path) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
if (current === void 0)
|
|
14
|
-
return;
|
|
15
|
-
return current;
|
|
11
|
+
const normalized = path.replaceAll(/\[(\w+)\]/g, ".$1");
|
|
12
|
+
if (normalized.includes("..") || normalized.startsWith(".") || normalized.endsWith(".")) return;
|
|
13
|
+
const segments = normalized.split(".");
|
|
14
|
+
let current = value;
|
|
15
|
+
for (const key of segments) {
|
|
16
|
+
if (current == null) return;
|
|
17
|
+
current = current[key];
|
|
18
|
+
}
|
|
19
|
+
if (current === void 0) return;
|
|
20
|
+
return current;
|
|
16
21
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
};
|
|
22
|
+
//#endregion
|
|
23
|
+
export { get as default };
|