@signaldb/core 2.0.0-beta.1 → 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 +122 -82
- package/dist/AsyncDataAdapter.d.ts +44 -7
- package/dist/AutoFetchDataAdapter.d.ts +5 -7
- package/dist/Collection/Cursor.d.ts +6 -5
- package/dist/Collection/Observer.d.ts +2 -0
- package/dist/Collection/index.d.ts +34 -25
- package/dist/Collection/types.d.ts +10 -2
- package/dist/DataAdapter.d.ts +12 -6
- package/dist/DefaultDataAdapter.d.ts +6 -6
- package/dist/WorkerDataAdapter.d.ts +3 -5
- package/dist/WorkerDataAdapterHost.d.ts +5 -5
- 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 +2 -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 -350
- package/dist/index13.cjs.js +45 -0
- package/dist/index13.mjs +44 -419
- package/dist/index14.cjs.js +86 -0
- package/dist/index14.mjs +85 -184
- package/dist/index15.cjs.js +15 -0
- package/dist/index15.mjs +14 -386
- package/dist/index16.cjs.js +136 -0
- package/dist/index16.mjs +133 -577
- 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 -257
- package/dist/index20.cjs.js +37 -0
- package/dist/index20.mjs +36 -7
- package/dist/index21.cjs.js +35 -0
- package/dist/index21.mjs +33 -103
- package/dist/index22.cjs.js +25 -0
- package/dist/index22.mjs +23 -127
- package/dist/index23.cjs.js +19 -0
- package/dist/index23.mjs +18 -7
- package/dist/index24.cjs.js +342 -0
- package/dist/index24.mjs +340 -26
- 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 -46
- package/dist/index28.cjs.js +90 -0
- package/dist/index28.mjs +87 -7
- package/dist/index29.cjs.js +424 -0
- package/dist/index29.mjs +423 -9
- package/dist/index3.cjs.js +19 -0
- package/dist/index3.mjs +18 -541
- package/dist/index30.cjs.js +72 -0
- package/dist/index30.mjs +71 -5
- package/dist/index31.cjs.js +191 -0
- package/dist/index31.mjs +190 -7
- package/dist/index32.cjs.js +21 -0
- package/dist/index32.mjs +20 -29
- package/dist/index33.cjs.js +336 -0
- package/dist/index33.mjs +335 -42
- 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/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 -350
- package/dist/index.cjs13.js +0 -419
- package/dist/index.cjs14.js +0 -184
- package/dist/index.cjs15.js +0 -386
- package/dist/index.cjs16.js +0 -579
- 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 -258
- package/dist/index.cjs20.js +0 -7
- package/dist/index.cjs21.js +0 -104
- package/dist/index.cjs22.js +0 -129
- package/dist/index.cjs23.js +0 -7
- package/dist/index.cjs24.js +0 -27
- package/dist/index.cjs25.js +0 -10
- package/dist/index.cjs26.js +0 -29
- package/dist/index.cjs27.js +0 -46
- package/dist/index.cjs28.js +0 -8
- package/dist/index.cjs29.js +0 -9
- package/dist/index.cjs3.js +0 -542
- package/dist/index.cjs30.js +0 -5
- package/dist/index.cjs31.js +0 -7
- package/dist/index.cjs32.js +0 -29
- package/dist/index.cjs33.js +0 -42
- 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
|
/**
|
|
@@ -120,9 +126,10 @@ export default class Collection<T extends BaseItem<I> = BaseItem, I = any, U = T
|
|
|
120
126
|
* @param options.indices - An array of index providers for optimized querying.
|
|
121
127
|
* @param options.enableDebugMode - A boolean to enable or disable debug mode.
|
|
122
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
|
|
123
130
|
*/
|
|
124
|
-
constructor(options?: CollectionOptions<T, I, U>);
|
|
125
|
-
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>);
|
|
126
133
|
isBatchOperationInProgress(): boolean;
|
|
127
134
|
/**
|
|
128
135
|
* Checks whether the collection is currently performing a pull operation
|
|
@@ -184,6 +191,7 @@ export default class Collection<T extends BaseItem<I> = BaseItem, I = any, U = T
|
|
|
184
191
|
private profile;
|
|
185
192
|
private executeInDebugMode;
|
|
186
193
|
private transform;
|
|
194
|
+
private transformAll;
|
|
187
195
|
private getItem;
|
|
188
196
|
private getItems;
|
|
189
197
|
private withPushState;
|
|
@@ -197,23 +205,24 @@ export default class Collection<T extends BaseItem<I> = BaseItem, I = any, U = T
|
|
|
197
205
|
/**
|
|
198
206
|
* Finds multiple items in the collection based on a selector and optional options.
|
|
199
207
|
* Returns a cursor for reactive data queries.
|
|
200
|
-
* @template O - The options type for the find operation.
|
|
201
208
|
* @param [selector] - The criteria to select items.
|
|
202
209
|
* @param [options] - Options for the find operation, such as limit and sort.
|
|
203
210
|
* @returns A cursor to fetch and observe the matching items.
|
|
204
211
|
*/
|
|
205
|
-
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>;
|
|
206
215
|
/**
|
|
207
216
|
* Finds a single item in the collection based on a selector and optional options.
|
|
208
217
|
* ⚡️ this function is reactive!
|
|
209
218
|
* Returns the found item or undefined if no item matches.
|
|
210
|
-
* @template Async - Whether to perform the operation asynchronously.
|
|
211
|
-
* @template O - The options type for the find operation.
|
|
212
219
|
* @param selector - The criteria to select the item.
|
|
213
220
|
* @param [options] - Options for the find operation, such as projection.
|
|
214
221
|
* @returns The found item or `undefined`.
|
|
215
222
|
*/
|
|
216
|
-
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;
|
|
217
226
|
/**
|
|
218
227
|
* Performs a batch operation, deferring index rebuilds and allowing multiple
|
|
219
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[]>;
|
|
@@ -21,14 +21,20 @@ export interface CollectionBackend<T extends BaseItem<I>, I> {
|
|
|
21
21
|
removeMany(selector: Selector<T>): Promise<T[]>;
|
|
22
22
|
registerQuery<O extends QueryOptions<T>>(selector: Selector<T>, options: O): void;
|
|
23
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;
|
|
24
30
|
getQueryState<O extends QueryOptions<T>>(selector: Selector<T>, options: O): 'active' | 'complete' | 'error';
|
|
25
31
|
getQueryError<O extends QueryOptions<T>>(selector: Selector<T>, options: O): Error | null;
|
|
26
32
|
getQueryResult<O extends QueryOptions<T>>(selector: Selector<T>, options: O): T[];
|
|
27
33
|
executeQuery<O extends QueryOptions<T>>(selector: Selector<T>, options: O): Promise<T[]>;
|
|
28
|
-
onQueryStateChange<O extends QueryOptions<T>>(selector: Selector<T>, options: O, callback:
|
|
34
|
+
onQueryStateChange<O extends QueryOptions<T>>(selector: Selector<T>, options: O, callback: StateChangeCallback): () => void;
|
|
29
35
|
dispose(): Promise<void>;
|
|
30
36
|
isReady(): Promise<void>;
|
|
31
37
|
}
|
|
32
38
|
export default interface DataAdapter {
|
|
33
|
-
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>;
|
|
34
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;
|
|
@@ -28,6 +27,7 @@ export default class DefaultDataAdapter implements DataAdapter {
|
|
|
28
27
|
private flushQueuedQueryUpdates;
|
|
29
28
|
private executeAndCacheQuery;
|
|
30
29
|
private updateQueries;
|
|
31
|
-
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>;
|
|
32
32
|
}
|
|
33
33
|
export {};
|
|
@@ -1,7 +1,5 @@
|
|
|
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;
|
|
7
5
|
log?: (message: string, ...args: any[]) => void;
|
|
@@ -20,6 +18,6 @@ export default class WorkerDataAdapter implements DataAdapter {
|
|
|
20
18
|
private exec;
|
|
21
19
|
private enqueueBatched;
|
|
22
20
|
private updateQuery;
|
|
23
|
-
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>;
|
|
24
22
|
}
|
|
25
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;
|
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,7 @@ 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
6
|
export type { default as DataAdapter } from './DataAdapter';
|
|
7
7
|
export { default as Cursor } from './Collection/Cursor';
|
|
8
8
|
export { default as Collection } from './Collection';
|
|
@@ -14,6 +14,7 @@ export { default as randomId } from './utils/randomId';
|
|
|
14
14
|
export { default as EventEmitter } from './utils/EventEmitter';
|
|
15
15
|
export { default as get } from './utils/get';
|
|
16
16
|
export { default as serializeValue } from './utils/serializeValue';
|
|
17
|
+
export { default as reactiveOrAsync, unwrap } from './utils/reactiveOrAsync';
|
|
17
18
|
export { default as DefaultDataAdapter } from './DefaultDataAdapter';
|
|
18
19
|
export { default as AsyncDataAdapter } from './AsyncDataAdapter';
|
|
19
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 };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
//#region src/utils/isFieldExpression.ts
|
|
2
|
+
var expressionKeys = new Set([
|
|
3
|
+
"$eq",
|
|
4
|
+
"$gt",
|
|
5
|
+
"$gte",
|
|
6
|
+
"$lt",
|
|
7
|
+
"$lte",
|
|
8
|
+
"$in",
|
|
9
|
+
"$nin",
|
|
10
|
+
"$ne",
|
|
11
|
+
"$exists",
|
|
12
|
+
"$not",
|
|
13
|
+
"$expr",
|
|
14
|
+
"$jsonSchema",
|
|
15
|
+
"$mod",
|
|
16
|
+
"$regex",
|
|
17
|
+
"$options",
|
|
18
|
+
"$text",
|
|
19
|
+
"$where",
|
|
20
|
+
"$all",
|
|
21
|
+
"$elemMatch",
|
|
22
|
+
"$size",
|
|
23
|
+
"$bitsAllClear",
|
|
24
|
+
"$bitsAllSet",
|
|
25
|
+
"$bitsAnyClear",
|
|
26
|
+
"$bitsAnySet"
|
|
27
|
+
]);
|
|
28
|
+
/**
|
|
29
|
+
* Determines whether a given object is a valid field expression.
|
|
30
|
+
* A field expression is an object containing query operators supported by MongoDB-style queries.
|
|
31
|
+
* @template T - The type of the field expression.
|
|
32
|
+
* @param expression - The object to test.
|
|
33
|
+
* @returns A boolean indicating whether the object is a valid field expression.
|
|
34
|
+
* - `true` if the object contains only recognized query operators.
|
|
35
|
+
* - `false` otherwise.
|
|
36
|
+
*/
|
|
37
|
+
function isFieldExpression(expression) {
|
|
38
|
+
if (typeof expression !== "object" || expression == null) return false;
|
|
39
|
+
const keys = Object.keys(expression);
|
|
40
|
+
if (keys.length === 0) return false;
|
|
41
|
+
if (keys.some((key) => !expressionKeys.has(key))) return false;
|
|
42
|
+
return keys.every((key) => expressionKeys.has(key));
|
|
43
|
+
}
|
|
44
|
+
//#endregion
|
|
45
|
+
exports.default = isFieldExpression;
|
package/dist/index11.mjs
CHANGED
|
@@ -1,16 +1,45 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
//#region src/utils/isFieldExpression.ts
|
|
2
|
+
var expressionKeys = new Set([
|
|
3
|
+
"$eq",
|
|
4
|
+
"$gt",
|
|
5
|
+
"$gte",
|
|
6
|
+
"$lt",
|
|
7
|
+
"$lte",
|
|
8
|
+
"$in",
|
|
9
|
+
"$nin",
|
|
10
|
+
"$ne",
|
|
11
|
+
"$exists",
|
|
12
|
+
"$not",
|
|
13
|
+
"$expr",
|
|
14
|
+
"$jsonSchema",
|
|
15
|
+
"$mod",
|
|
16
|
+
"$regex",
|
|
17
|
+
"$options",
|
|
18
|
+
"$text",
|
|
19
|
+
"$where",
|
|
20
|
+
"$all",
|
|
21
|
+
"$elemMatch",
|
|
22
|
+
"$size",
|
|
23
|
+
"$bitsAllClear",
|
|
24
|
+
"$bitsAllSet",
|
|
25
|
+
"$bitsAnyClear",
|
|
26
|
+
"$bitsAnySet"
|
|
27
|
+
]);
|
|
28
|
+
/**
|
|
29
|
+
* Determines whether a given object is a valid field expression.
|
|
30
|
+
* A field expression is an object containing query operators supported by MongoDB-style queries.
|
|
31
|
+
* @template T - The type of the field expression.
|
|
32
|
+
* @param expression - The object to test.
|
|
33
|
+
* @returns A boolean indicating whether the object is a valid field expression.
|
|
34
|
+
* - `true` if the object contains only recognized query operators.
|
|
35
|
+
* - `false` otherwise.
|
|
36
|
+
*/
|
|
37
|
+
function isFieldExpression(expression) {
|
|
38
|
+
if (typeof expression !== "object" || expression == null) return false;
|
|
39
|
+
const keys = Object.keys(expression);
|
|
40
|
+
if (keys.length === 0) return false;
|
|
41
|
+
if (keys.some((key) => !expressionKeys.has(key))) return false;
|
|
42
|
+
return keys.every((key) => expressionKeys.has(key));
|
|
13
43
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
};
|
|
44
|
+
//#endregion
|
|
45
|
+
export { isFieldExpression as default };
|