@signaldb/svelte 2.0.0-beta.2 → 2.0.0-beta.21
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/base/core/src/AsyncDataAdapter.d.ts +112 -0
- package/dist/base/core/src/AsyncDataAdapter.js +549 -0
- package/dist/base/core/src/AutoFetchDataAdapter.d.ts +112 -0
- package/dist/base/core/src/AutoFetchDataAdapter.js +612 -0
- package/dist/base/core/src/Collection/Cursor.d.ts +165 -0
- package/dist/base/core/src/Collection/Cursor.js +352 -0
- package/dist/base/core/src/Collection/Observer.d.ts +95 -0
- package/dist/base/core/src/Collection/Observer.js +227 -0
- package/dist/base/core/src/Collection/index.d.ts +341 -0
- package/dist/base/core/src/Collection/index.js +761 -0
- package/dist/base/core/src/Collection/types.d.ts +28 -0
- package/dist/base/core/src/Collection/types.js +2 -0
- package/dist/base/core/src/DataAdapter.d.ts +54 -0
- package/dist/base/core/src/DataAdapter.js +2 -0
- package/dist/base/core/src/DefaultDataAdapter.d.ts +35 -0
- package/dist/base/core/src/DefaultDataAdapter.js +408 -0
- package/dist/base/core/src/WorkerDataAdapter.d.ts +79 -0
- package/dist/base/core/src/WorkerDataAdapter.js +749 -0
- package/dist/base/core/src/WorkerDataAdapterHost.d.ts +64 -0
- package/dist/base/core/src/WorkerDataAdapterHost.js +430 -0
- package/dist/base/core/src/createIndex.d.ts +7 -0
- package/dist/base/core/src/createIndex.js +120 -0
- package/dist/base/core/src/createIndexProvider.d.ts +8 -0
- package/dist/base/core/src/createIndexProvider.js +11 -0
- package/dist/base/core/src/createReactivityAdapter.d.ts +8 -0
- package/dist/base/core/src/createReactivityAdapter.js +11 -0
- package/dist/base/core/src/createStorageAdapter.d.ts +9 -0
- package/dist/base/core/src/createStorageAdapter.js +11 -0
- package/dist/base/core/src/getIndexInfo.d.ts +39 -0
- package/dist/base/core/src/getIndexInfo.js +188 -0
- package/dist/base/core/src/index.d.ts +26 -0
- package/dist/base/core/src/index.js +39 -0
- package/dist/base/core/src/types/Dependency.d.ts +4 -0
- package/dist/base/core/src/types/Dependency.js +2 -0
- package/dist/base/core/src/types/IndexProvider.d.ts +26 -0
- package/dist/base/core/src/types/IndexProvider.js +2 -0
- package/dist/base/core/src/types/Modifier.d.ts +46 -0
- package/dist/base/core/src/types/Modifier.js +3 -0
- package/dist/base/core/src/types/ReactivityAdapter.d.ts +6 -0
- package/dist/base/core/src/types/ReactivityAdapter.js +2 -0
- package/dist/base/core/src/types/Selector.d.ts +46 -0
- package/dist/base/core/src/types/Selector.js +3 -0
- package/dist/base/core/src/types/Signal.d.ts +4 -0
- package/dist/base/core/src/types/Signal.js +2 -0
- package/dist/base/core/src/types/StorageAdapter.d.ts +28 -0
- package/dist/base/core/src/types/StorageAdapter.js +2 -0
- package/dist/base/core/src/utils/EventEmitter.d.ts +71 -0
- package/dist/base/core/src/utils/EventEmitter.js +144 -0
- package/dist/base/core/src/utils/applyQueryOptions.d.ts +15 -0
- package/dist/base/core/src/utils/applyQueryOptions.js +36 -0
- package/dist/base/core/src/utils/batchOnNextTick.d.ts +16 -0
- package/dist/base/core/src/utils/batchOnNextTick.js +72 -0
- package/dist/base/core/src/utils/compact.d.ts +9 -0
- package/dist/base/core/src/utils/compact.js +21 -0
- package/dist/base/core/src/utils/createSignal.d.ts +14 -0
- package/dist/base/core/src/utils/createSignal.js +38 -0
- package/dist/base/core/src/utils/deepClone.d.ts +17 -0
- package/dist/base/core/src/utils/deepClone.js +68 -0
- package/dist/base/core/src/utils/get.d.ts +9 -0
- package/dist/base/core/src/utils/get.js +27 -0
- package/dist/base/core/src/utils/getMatchingKeys.d.ts +19 -0
- package/dist/base/core/src/utils/getMatchingKeys.js +49 -0
- package/dist/base/core/src/utils/idIndexQuery.d.ts +20 -0
- package/dist/base/core/src/utils/idIndexQuery.js +49 -0
- package/dist/base/core/src/utils/incrementalQueryUpdate.d.ts +62 -0
- package/dist/base/core/src/utils/incrementalQueryUpdate.js +197 -0
- package/dist/base/core/src/utils/intersection.d.ts +9 -0
- package/dist/base/core/src/utils/intersection.js +16 -0
- package/dist/base/core/src/utils/isEqual.d.ts +14 -0
- package/dist/base/core/src/utils/isEqual.js +43 -0
- package/dist/base/core/src/utils/isFieldExpression.d.ts +11 -0
- package/dist/base/core/src/utils/isFieldExpression.js +52 -0
- package/dist/base/core/src/utils/match.d.ts +12 -0
- package/dist/base/core/src/utils/match.js +16 -0
- package/dist/base/core/src/utils/modify.d.ts +14 -0
- package/dist/base/core/src/utils/modify.js +29 -0
- package/dist/base/core/src/utils/project.d.ts +15 -0
- package/dist/base/core/src/utils/project.js +43 -0
- package/dist/base/core/src/utils/projectItems.d.ts +12 -0
- package/dist/base/core/src/utils/projectItems.js +25 -0
- package/dist/base/core/src/utils/queryDelta.d.ts +83 -0
- package/dist/base/core/src/utils/queryDelta.js +231 -0
- package/dist/base/core/src/utils/queryId.d.ts +9 -0
- package/dist/base/core/src/utils/queryId.js +61 -0
- package/dist/base/core/src/utils/randomId.d.ts +7 -0
- package/dist/base/core/src/utils/randomId.js +12 -0
- package/dist/base/core/src/utils/reactiveOrAsync.d.ts +59 -0
- package/dist/base/core/src/utils/reactiveOrAsync.js +93 -0
- package/dist/base/core/src/utils/serializeValue.d.ts +12 -0
- package/dist/base/core/src/utils/serializeValue.js +27 -0
- package/dist/base/core/src/utils/set.d.ts +13 -0
- package/dist/base/core/src/utils/set.js +43 -0
- package/dist/base/core/src/utils/sortItems.d.ts +12 -0
- package/dist/base/core/src/utils/sortItems.js +23 -0
- package/dist/base/core/src/utils/storageIndexQuery.d.ts +20 -0
- package/dist/base/core/src/utils/storageIndexQuery.js +75 -0
- package/dist/base/core/src/utils/uniqueBy.d.ts +10 -0
- package/dist/base/core/src/utils/uniqueBy.js +19 -0
- package/dist/index.cjs +38 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.mjs +38 -0
- package/dist/index.mjs.map +1 -0
- package/dist/reactivity-adapters/svelte/index.svelte.d.ts +10 -0
- package/dist/reactivity-adapters/svelte/index.svelte.js +36 -0
- package/package.json +3 -3
|
@@ -0,0 +1,9 @@
|
|
|
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>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = createStorageAdapter;
|
|
4
|
+
/**
|
|
5
|
+
* Creates an StorageAdapter based on the given definition.
|
|
6
|
+
* @param definition - The definition of the StorageAdapter.
|
|
7
|
+
* @returns The created StorageAdapter.
|
|
8
|
+
*/
|
|
9
|
+
function createStorageAdapter(definition) {
|
|
10
|
+
return definition;
|
|
11
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
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 {};
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getMergedIndexInfo = getMergedIndexInfo;
|
|
7
|
+
exports.default = getIndexInfo;
|
|
8
|
+
const intersection_1 = __importDefault(require("./utils/intersection"));
|
|
9
|
+
/**
|
|
10
|
+
* Retrieves merged index information for a given flat selector by querying multiple
|
|
11
|
+
* index providers. Combines results from all index providers to determine matched ids
|
|
12
|
+
* and an optimized selector.
|
|
13
|
+
* @template T - The type of the items in the collection.
|
|
14
|
+
* @template I - The type of the unique identifier for the items.
|
|
15
|
+
* @param queryFunctions - An array of index providers to query.
|
|
16
|
+
* @param selector - The flat selector used to filter items.
|
|
17
|
+
* @returns An object containing:
|
|
18
|
+
* - `matched`: A boolean indicating if the selector matched any items.
|
|
19
|
+
* - `ids`: An array of matched item ids.
|
|
20
|
+
* - `optimizedSelector`: A flat selector optimized based on the index results.
|
|
21
|
+
*/
|
|
22
|
+
function getMergedIndexInfo(queryFunctions, selector) {
|
|
23
|
+
return queryFunctions.reduce((memoOrPromise, queryFunction) => {
|
|
24
|
+
const resultOrPromise = queryFunction(selector);
|
|
25
|
+
const processResult = (memo, result) => {
|
|
26
|
+
if (!result.matched)
|
|
27
|
+
return memo;
|
|
28
|
+
const optimizedSelector = result.keepSelector
|
|
29
|
+
? memo.optimizedSelector
|
|
30
|
+
: Object.fromEntries(Object.entries(memo.optimizedSelector)
|
|
31
|
+
.filter(([key]) => !result.fields.includes(key)));
|
|
32
|
+
return {
|
|
33
|
+
matched: true,
|
|
34
|
+
ids: [...new Set(memo.matched
|
|
35
|
+
? (0, intersection_1.default)(memo.ids, result.ids)
|
|
36
|
+
: result.ids)],
|
|
37
|
+
optimizedSelector,
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
if (resultOrPromise instanceof Promise) {
|
|
41
|
+
return resultOrPromise.then(async (result) => {
|
|
42
|
+
const memo = memoOrPromise instanceof Promise ? await memoOrPromise : memoOrPromise;
|
|
43
|
+
return processResult(memo, result);
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
const memo = memoOrPromise;
|
|
47
|
+
if (memo instanceof Promise)
|
|
48
|
+
throw new Error('Mixing async and sync index providers is not supported');
|
|
49
|
+
return processResult(memo, resultOrPromise);
|
|
50
|
+
}, {
|
|
51
|
+
matched: false,
|
|
52
|
+
ids: [],
|
|
53
|
+
optimizedSelector: { ...selector },
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Optimizes a logic gate ($and/$or) of selectors by querying multiple index providers.
|
|
58
|
+
* @param queryFunctions - An array of index providers to query.
|
|
59
|
+
* @param logicGate - An array of selectors representing the logic gate.
|
|
60
|
+
* @param idsCallback - A callback function called with matched ids.
|
|
61
|
+
* @returns An array of optimized selectors or a promise that resolves to such an array.
|
|
62
|
+
*/
|
|
63
|
+
function optimizeLogicGate(queryFunctions, logicGate, idsCallback) {
|
|
64
|
+
return logicGate.reduce((memoOrPromise, sel) => {
|
|
65
|
+
const getSelector = (indexInfo) => {
|
|
66
|
+
const { matched: selMatched, ids: selIds, optimizedSelector, } = indexInfo;
|
|
67
|
+
if (selMatched) {
|
|
68
|
+
idsCallback(true, selIds);
|
|
69
|
+
if (Object.keys(optimizedSelector).length > 0) {
|
|
70
|
+
return optimizedSelector;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
idsCallback(false, []);
|
|
75
|
+
return sel;
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
const indexInfoOrPromise = getIndexInfo(queryFunctions, sel);
|
|
79
|
+
if (indexInfoOrPromise instanceof Promise) {
|
|
80
|
+
return indexInfoOrPromise.then(async (indexInfo) => {
|
|
81
|
+
const memo = memoOrPromise instanceof Promise ? await memoOrPromise : memoOrPromise;
|
|
82
|
+
const optimizedSelector = getSelector(indexInfo);
|
|
83
|
+
if (optimizedSelector)
|
|
84
|
+
memo.push(optimizedSelector);
|
|
85
|
+
return memo;
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
const memo = memoOrPromise;
|
|
89
|
+
if (memo instanceof Promise)
|
|
90
|
+
throw new Error('Mixing async and sync index providers is not supported');
|
|
91
|
+
const optimizedSelector = getSelector(indexInfoOrPromise);
|
|
92
|
+
if (optimizedSelector)
|
|
93
|
+
memo.push(optimizedSelector);
|
|
94
|
+
return memo;
|
|
95
|
+
}, []);
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Retrieves index information for a given complex selector by querying multiple
|
|
99
|
+
* index providers. Handles nested `$and` and `$or` conditions in the selector and
|
|
100
|
+
* optimizes the selector to minimize processing overhead.
|
|
101
|
+
* @template T - The type of the items in the collection.
|
|
102
|
+
* @template I - The type of the unique identifier for the items.
|
|
103
|
+
* @param queryFunctions - An array of index providers to query.
|
|
104
|
+
* @param selector - The complex selector used to filter items.
|
|
105
|
+
* @returns An object containing:
|
|
106
|
+
* - `matched`: A boolean indicating if the selector matched any items.
|
|
107
|
+
* - `ids`: An array of matched item ids.
|
|
108
|
+
* - `optimizedSelector`: A selector optimized based on the index results, with unused
|
|
109
|
+
* conditions removed.
|
|
110
|
+
*/
|
|
111
|
+
function getIndexInfo(queryFunctions, selector) {
|
|
112
|
+
if (selector == null || Object.keys(selector).length <= 0) {
|
|
113
|
+
return {
|
|
114
|
+
matched: false,
|
|
115
|
+
ids: [],
|
|
116
|
+
optimizedSelector: selector,
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
const { $and, $or, ...rest } = selector;
|
|
120
|
+
const flatInfoOrPromise = getMergedIndexInfo(queryFunctions, rest);
|
|
121
|
+
const processFlatInfo = (flatInfo) => {
|
|
122
|
+
let { matched, ids } = flatInfo;
|
|
123
|
+
const newSelector = flatInfo.optimizedSelector;
|
|
124
|
+
const $andNewOrPromise = Array.isArray($and)
|
|
125
|
+
? optimizeLogicGate(queryFunctions, $and, (match, selIds) => {
|
|
126
|
+
if (!match)
|
|
127
|
+
return;
|
|
128
|
+
ids = matched ? (0, intersection_1.default)(ids, selIds) : selIds;
|
|
129
|
+
matched = true;
|
|
130
|
+
})
|
|
131
|
+
: undefined;
|
|
132
|
+
const process$and = ($andNew) => {
|
|
133
|
+
if ($andNew && $andNew.length > 0)
|
|
134
|
+
newSelector.$and = $andNew;
|
|
135
|
+
let hasNonIndexField = false;
|
|
136
|
+
const matchedBefore = matched;
|
|
137
|
+
const idsBefore = ids;
|
|
138
|
+
// The branches of an $or union with each other, but the $or as a whole
|
|
139
|
+
// *intersects* with what the flat fields and $and already narrowed down
|
|
140
|
+
// to. Collecting the branches separately is what keeps those two apart —
|
|
141
|
+
// folding them into `ids` turns `{ a: 1, $or: [...] }` into a union and
|
|
142
|
+
// returns items matching neither half of the selector, with an empty
|
|
143
|
+
// optimized selector that leaves nothing to filter them out again.
|
|
144
|
+
let orIds = [];
|
|
145
|
+
let orMatched = false;
|
|
146
|
+
const process$or = ($orNew) => {
|
|
147
|
+
if (hasNonIndexField || ($orNew && $orNew.length > 0)) {
|
|
148
|
+
newSelector.$or = $or;
|
|
149
|
+
matched = matchedBefore;
|
|
150
|
+
ids = idsBefore;
|
|
151
|
+
}
|
|
152
|
+
else if (orMatched) {
|
|
153
|
+
ids = matchedBefore ? (0, intersection_1.default)(idsBefore, orIds) : orIds;
|
|
154
|
+
matched = true;
|
|
155
|
+
}
|
|
156
|
+
return {
|
|
157
|
+
matched,
|
|
158
|
+
ids: ids || [],
|
|
159
|
+
optimizedSelector: newSelector,
|
|
160
|
+
};
|
|
161
|
+
};
|
|
162
|
+
const $orNewOrPromise = Array.isArray($or)
|
|
163
|
+
? optimizeLogicGate(queryFunctions, $or, (match, selIds) => {
|
|
164
|
+
if (match) {
|
|
165
|
+
orIds = [...new Set([...orIds, ...selIds])];
|
|
166
|
+
orMatched = true;
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
hasNonIndexField = true;
|
|
170
|
+
}
|
|
171
|
+
})
|
|
172
|
+
: undefined;
|
|
173
|
+
if ($orNewOrPromise instanceof Promise) {
|
|
174
|
+
return $orNewOrPromise.then($orNew => process$or($orNew));
|
|
175
|
+
}
|
|
176
|
+
return process$or($orNewOrPromise);
|
|
177
|
+
};
|
|
178
|
+
if ($andNewOrPromise instanceof Promise) {
|
|
179
|
+
return $andNewOrPromise.then($andNew => process$and($andNew));
|
|
180
|
+
}
|
|
181
|
+
return process$and($andNewOrPromise);
|
|
182
|
+
};
|
|
183
|
+
if (flatInfoOrPromise instanceof Promise) {
|
|
184
|
+
return flatInfoOrPromise
|
|
185
|
+
.then(processFlatInfo);
|
|
186
|
+
}
|
|
187
|
+
return processFlatInfo(flatInfoOrPromise);
|
|
188
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
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, QueryStateAccessor, } from './Collection';
|
|
6
|
+
export type { default as DataAdapter } from './DataAdapter';
|
|
7
|
+
export type { CollectionBackend, QueryOptions, StateChangeCallback, } from './DataAdapter';
|
|
8
|
+
export type { QueryDelta } from './utils/queryDelta';
|
|
9
|
+
export { default as Cursor } from './Collection/Cursor';
|
|
10
|
+
export { default as Collection } from './Collection';
|
|
11
|
+
export { default as createStorageAdapter } from './createStorageAdapter';
|
|
12
|
+
export { default as createReactivityAdapter } from './createReactivityAdapter';
|
|
13
|
+
export { default as isEqual } from './utils/isEqual';
|
|
14
|
+
export { default as modify } from './utils/modify';
|
|
15
|
+
export { default as randomId } from './utils/randomId';
|
|
16
|
+
export { default as EventEmitter } from './utils/EventEmitter';
|
|
17
|
+
export { default as get } from './utils/get';
|
|
18
|
+
export { default as serializeValue } from './utils/serializeValue';
|
|
19
|
+
export { default as reactiveOrAsync, unwrap } from './utils/reactiveOrAsync';
|
|
20
|
+
export { default as DefaultDataAdapter } from './DefaultDataAdapter';
|
|
21
|
+
export { default as AsyncDataAdapter } from './AsyncDataAdapter';
|
|
22
|
+
export { default as WorkerDataAdapter } from './WorkerDataAdapter';
|
|
23
|
+
export { default as WorkerDataAdapterHost } from './WorkerDataAdapterHost';
|
|
24
|
+
export type { WorkerDataAdapterEndpoint } from './WorkerDataAdapter';
|
|
25
|
+
export type { WorkerDataAdapterHostEndpoint } from './WorkerDataAdapterHost';
|
|
26
|
+
export { default as AutoFetchDataAdapter } from './AutoFetchDataAdapter';
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.AutoFetchDataAdapter = exports.WorkerDataAdapterHost = exports.WorkerDataAdapter = exports.AsyncDataAdapter = exports.DefaultDataAdapter = exports.unwrap = exports.reactiveOrAsync = exports.serializeValue = exports.get = exports.EventEmitter = exports.randomId = exports.modify = exports.isEqual = exports.createReactivityAdapter = exports.createStorageAdapter = exports.Collection = exports.Cursor = void 0;
|
|
7
|
+
var Cursor_1 = require("./Collection/Cursor");
|
|
8
|
+
Object.defineProperty(exports, "Cursor", { enumerable: true, get: function () { return __importDefault(Cursor_1).default; } });
|
|
9
|
+
var Collection_1 = require("./Collection");
|
|
10
|
+
Object.defineProperty(exports, "Collection", { enumerable: true, get: function () { return __importDefault(Collection_1).default; } });
|
|
11
|
+
var createStorageAdapter_1 = require("./createStorageAdapter");
|
|
12
|
+
Object.defineProperty(exports, "createStorageAdapter", { enumerable: true, get: function () { return __importDefault(createStorageAdapter_1).default; } });
|
|
13
|
+
var createReactivityAdapter_1 = require("./createReactivityAdapter");
|
|
14
|
+
Object.defineProperty(exports, "createReactivityAdapter", { enumerable: true, get: function () { return __importDefault(createReactivityAdapter_1).default; } });
|
|
15
|
+
var isEqual_1 = require("./utils/isEqual");
|
|
16
|
+
Object.defineProperty(exports, "isEqual", { enumerable: true, get: function () { return __importDefault(isEqual_1).default; } });
|
|
17
|
+
var modify_1 = require("./utils/modify");
|
|
18
|
+
Object.defineProperty(exports, "modify", { enumerable: true, get: function () { return __importDefault(modify_1).default; } });
|
|
19
|
+
var randomId_1 = require("./utils/randomId");
|
|
20
|
+
Object.defineProperty(exports, "randomId", { enumerable: true, get: function () { return __importDefault(randomId_1).default; } });
|
|
21
|
+
var EventEmitter_1 = require("./utils/EventEmitter");
|
|
22
|
+
Object.defineProperty(exports, "EventEmitter", { enumerable: true, get: function () { return __importDefault(EventEmitter_1).default; } });
|
|
23
|
+
var get_1 = require("./utils/get");
|
|
24
|
+
Object.defineProperty(exports, "get", { enumerable: true, get: function () { return __importDefault(get_1).default; } });
|
|
25
|
+
var serializeValue_1 = require("./utils/serializeValue");
|
|
26
|
+
Object.defineProperty(exports, "serializeValue", { enumerable: true, get: function () { return __importDefault(serializeValue_1).default; } });
|
|
27
|
+
var reactiveOrAsync_1 = require("./utils/reactiveOrAsync");
|
|
28
|
+
Object.defineProperty(exports, "reactiveOrAsync", { enumerable: true, get: function () { return __importDefault(reactiveOrAsync_1).default; } });
|
|
29
|
+
Object.defineProperty(exports, "unwrap", { enumerable: true, get: function () { return reactiveOrAsync_1.unwrap; } });
|
|
30
|
+
var DefaultDataAdapter_1 = require("./DefaultDataAdapter");
|
|
31
|
+
Object.defineProperty(exports, "DefaultDataAdapter", { enumerable: true, get: function () { return __importDefault(DefaultDataAdapter_1).default; } });
|
|
32
|
+
var AsyncDataAdapter_1 = require("./AsyncDataAdapter");
|
|
33
|
+
Object.defineProperty(exports, "AsyncDataAdapter", { enumerable: true, get: function () { return __importDefault(AsyncDataAdapter_1).default; } });
|
|
34
|
+
var WorkerDataAdapter_1 = require("./WorkerDataAdapter");
|
|
35
|
+
Object.defineProperty(exports, "WorkerDataAdapter", { enumerable: true, get: function () { return __importDefault(WorkerDataAdapter_1).default; } });
|
|
36
|
+
var WorkerDataAdapterHost_1 = require("./WorkerDataAdapterHost");
|
|
37
|
+
Object.defineProperty(exports, "WorkerDataAdapterHost", { enumerable: true, get: function () { return __importDefault(WorkerDataAdapterHost_1).default; } });
|
|
38
|
+
var AutoFetchDataAdapter_1 = require("./AutoFetchDataAdapter");
|
|
39
|
+
Object.defineProperty(exports, "AutoFetchDataAdapter", { enumerable: true, get: function () { return __importDefault(AutoFetchDataAdapter_1).default; } });
|
|
@@ -0,0 +1,26 @@
|
|
|
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;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { DotNotation, GetType } from './Selector';
|
|
2
|
+
type Dictionary<T> = Record<string, T>;
|
|
3
|
+
type PartialMapTo<T, M> = Partial<Record<DotNotation<T>, M>> & Dictionary<M>;
|
|
4
|
+
type OnlyElementsOfArrays<T> = T extends any[] ? Partial<T[0]> : never;
|
|
5
|
+
type ElementsOf<T> = {
|
|
6
|
+
[P in DotNotation<T>]?: OnlyElementsOfArrays<GetType<T, P>>;
|
|
7
|
+
};
|
|
8
|
+
type PushModifier<T> = {
|
|
9
|
+
[P in DotNotation<T>]?: OnlyElementsOfArrays<GetType<T, P>> | {
|
|
10
|
+
$each?: GetType<T, P> | undefined;
|
|
11
|
+
$position?: number | undefined;
|
|
12
|
+
$slice?: number | undefined;
|
|
13
|
+
$sort?: 1 | -1 | Dictionary<number> | undefined;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
type ArraysOrEach<T> = {
|
|
17
|
+
[P in DotNotation<T>]?: OnlyElementsOfArrays<GetType<T, P>> | {
|
|
18
|
+
$each: GetType<T, P>;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
type CurrentDateModifier = {
|
|
22
|
+
$type: 'timestamp' | 'date';
|
|
23
|
+
} | true;
|
|
24
|
+
type Modifier<T extends Dictionary<any> = Dictionary<any>> = {
|
|
25
|
+
$currentDate?: (Partial<Record<DotNotation<T>, CurrentDateModifier>> & Dictionary<CurrentDateModifier>) | undefined;
|
|
26
|
+
$inc?: (PartialMapTo<T, number> & Dictionary<number>) | undefined;
|
|
27
|
+
$min?: (PartialMapTo<T, Date | number> & Dictionary<Date | number>) | undefined;
|
|
28
|
+
$max?: (PartialMapTo<T, Date | number> & Dictionary<Date | number>) | undefined;
|
|
29
|
+
$mul?: (PartialMapTo<T, number> & Dictionary<number>) | undefined;
|
|
30
|
+
$rename?: (PartialMapTo<T, string> & Dictionary<string>) | undefined;
|
|
31
|
+
$set?: ({
|
|
32
|
+
[P in DotNotation<T>]?: GetType<T, P>;
|
|
33
|
+
} & Dictionary<any>) | undefined;
|
|
34
|
+
$setOnInsert?: ({
|
|
35
|
+
[P in DotNotation<T>]?: GetType<T, P>;
|
|
36
|
+
} & Dictionary<any>) | undefined;
|
|
37
|
+
$unset?: (PartialMapTo<T, string | boolean | 1 | 0> & Dictionary<any>) | undefined;
|
|
38
|
+
$addToSet?: (ArraysOrEach<T> & Dictionary<any>) | undefined;
|
|
39
|
+
$push?: (PushModifier<T> & Dictionary<any>) | undefined;
|
|
40
|
+
$pull?: (ElementsOf<T> & Dictionary<any>) | undefined;
|
|
41
|
+
$pullAll?: ({
|
|
42
|
+
[P in DotNotation<T>]?: GetType<T, P>;
|
|
43
|
+
} & Dictionary<any>) | undefined;
|
|
44
|
+
$pop?: (PartialMapTo<T, 1 | -1> & Dictionary<1 | -1>) | undefined;
|
|
45
|
+
};
|
|
46
|
+
export default Modifier;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
export interface FieldExpression<T> {
|
|
2
|
+
$eq?: T;
|
|
3
|
+
$gt?: T;
|
|
4
|
+
$gte?: T;
|
|
5
|
+
$lt?: T;
|
|
6
|
+
$lte?: T;
|
|
7
|
+
$in?: T[] | undefined;
|
|
8
|
+
$nin?: T[];
|
|
9
|
+
$ne?: T;
|
|
10
|
+
$exists?: boolean;
|
|
11
|
+
$not?: FieldExpression<T>;
|
|
12
|
+
$expr?: FieldExpression<T>;
|
|
13
|
+
$jsonSchema?: any;
|
|
14
|
+
$mod?: number[];
|
|
15
|
+
$regex?: RegExp | string;
|
|
16
|
+
$options?: string;
|
|
17
|
+
$where?: string | ((this: T) => boolean);
|
|
18
|
+
$all?: T[];
|
|
19
|
+
$elemMatch?: T extends object ? Query<T> : FieldExpression<T>;
|
|
20
|
+
$size?: number;
|
|
21
|
+
$bitsAllClear?: any;
|
|
22
|
+
$bitsAllSet?: any;
|
|
23
|
+
$bitsAnyClear?: any;
|
|
24
|
+
$bitsAnySet?: any;
|
|
25
|
+
}
|
|
26
|
+
export type DotNotation<T> = {
|
|
27
|
+
[K in keyof T & string]: T[K] extends Array<infer U> ? `${K}` | `${K}.$` | `${K}.${DotNotation<U>}` : T[K] extends object ? `${K}` | `${K}.${DotNotation<T[K]>}` : `${K}`;
|
|
28
|
+
}[keyof T & string];
|
|
29
|
+
export type GetType<T, P extends string> = P extends `${infer H}.${infer R}` ? H extends keyof T ? T[H] extends Array<infer U> ? GetType<U, R> : GetType<T[H], R> : H extends '$' ? T extends Array<infer U> ? GetType<U, R> : never : never : P extends keyof T ? T[P] : never;
|
|
30
|
+
type FlatQuery<T> = {
|
|
31
|
+
[P in DotNotation<T>]?: FlatQueryValue<T, P>;
|
|
32
|
+
};
|
|
33
|
+
type FieldValue<U> = U extends string ? string | RegExp | FieldExpression<string> : U | FieldExpression<U>;
|
|
34
|
+
type FlatQueryValue<T, P extends string> = GetType<T, P> extends never ? never : GetType<T, P> extends Array<infer U> ? FieldValue<U> | FieldValue<U[]> : FieldValue<GetType<T, P>>;
|
|
35
|
+
type Query<T> = FlatQuery<T> & {
|
|
36
|
+
$or?: Query<T>[];
|
|
37
|
+
$and?: Query<T>[];
|
|
38
|
+
$nor?: Query<T>[];
|
|
39
|
+
};
|
|
40
|
+
export type FlatSelector<T extends Record<string, any>> = FlatQuery<T> & {
|
|
41
|
+
$or?: never;
|
|
42
|
+
$and?: never;
|
|
43
|
+
$nor?: never;
|
|
44
|
+
};
|
|
45
|
+
type Selector<T extends Record<string, any>> = Query<T>;
|
|
46
|
+
export default Selector;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export interface Changeset<T> {
|
|
2
|
+
added: T[];
|
|
3
|
+
modified: T[];
|
|
4
|
+
removed: T[];
|
|
5
|
+
}
|
|
6
|
+
export default interface StorageAdapter<T extends {
|
|
7
|
+
id: I;
|
|
8
|
+
} & Record<string, any>, I> {
|
|
9
|
+
setup(): Promise<void>;
|
|
10
|
+
teardown(): Promise<void>;
|
|
11
|
+
readAll(): Promise<T[]>;
|
|
12
|
+
readIds(positions: I[]): Promise<T[]>;
|
|
13
|
+
createIndex(field: string): Promise<void>;
|
|
14
|
+
dropIndex(field: string): Promise<void>;
|
|
15
|
+
/**
|
|
16
|
+
* The index, keyed by `serializeValue(value)` — not by the raw field value.
|
|
17
|
+
*
|
|
18
|
+
* SignalDB looks an index up with the serialized form, because that is what
|
|
19
|
+
* makes `3`, `'3'` and `new Date(...)` comparable as map keys at all. An
|
|
20
|
+
* adapter that stores its backend's own keys instead answers nothing for
|
|
21
|
+
* every non-string field, and everything for a `$ne` on one.
|
|
22
|
+
*/
|
|
23
|
+
readIndex(field: string): Promise<Map<string | null, Set<I>>>;
|
|
24
|
+
insert(items: T[]): Promise<void>;
|
|
25
|
+
replace(items: T[]): Promise<void>;
|
|
26
|
+
remove(items: T[]): Promise<void>;
|
|
27
|
+
removeAll(): Promise<void>;
|
|
28
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A strongly‑typed EventEmitter.
|
|
3
|
+
*/
|
|
4
|
+
export default class EventEmitter<Events extends Record<string | symbol, any>> {
|
|
5
|
+
private _maxListeners;
|
|
6
|
+
/**
|
|
7
|
+
* We store a set of the listeners for each event.
|
|
8
|
+
*/
|
|
9
|
+
private _listenerStore;
|
|
10
|
+
setMaxListeners(max: number): this;
|
|
11
|
+
/**
|
|
12
|
+
* Subscribe to an event with a listener function.
|
|
13
|
+
* @param eventName The event name (key of E).
|
|
14
|
+
* @param listener A function that receives the emitted arguments.
|
|
15
|
+
* @returns The emitter instance (for chaining).
|
|
16
|
+
*/
|
|
17
|
+
on<K extends keyof Events>(eventName: K, listener: Events[K]): this;
|
|
18
|
+
/**
|
|
19
|
+
* Subscribe to an event with a listener function.
|
|
20
|
+
* @param eventName The event name (key of E).
|
|
21
|
+
* @param listener A function that receives the emitted arguments.
|
|
22
|
+
* @returns The emitter instance (for chaining).
|
|
23
|
+
*/
|
|
24
|
+
addListener<K extends keyof Events>(eventName: K, listener: Events[K]): this;
|
|
25
|
+
/**
|
|
26
|
+
* Subscribe to an event, handling it only once. Automatically removes
|
|
27
|
+
* the listener after it fires the first time.
|
|
28
|
+
* @param eventName The event name (key of E).
|
|
29
|
+
* @param listener A function that receives the emitted arguments.
|
|
30
|
+
* @returns The emitter instance (for chaining).
|
|
31
|
+
*/
|
|
32
|
+
once<K extends keyof Events>(eventName: K, listener: Events[K]): this;
|
|
33
|
+
/**
|
|
34
|
+
* Unsubscribe a previously subscribed listener.
|
|
35
|
+
* @param eventName The event name (key of E).
|
|
36
|
+
* @param listener The original function passed to `on` or `once`.
|
|
37
|
+
* @returns The emitter instance (for chaining).
|
|
38
|
+
*/
|
|
39
|
+
off<K extends keyof Events>(eventName: K, listener: Events[K]): this;
|
|
40
|
+
/**
|
|
41
|
+
* Unsubscribe a previously subscribed listener.
|
|
42
|
+
* @param eventName The event name (key of E).
|
|
43
|
+
* @param listener The original function passed to `on` or `once`.
|
|
44
|
+
* @returns The emitter instance (for chaining).
|
|
45
|
+
*/
|
|
46
|
+
removeListener<K extends keyof Events>(eventName: K, listener: Events[K]): this;
|
|
47
|
+
/**
|
|
48
|
+
* Emit (dispatch) an event with a variable number of arguments.
|
|
49
|
+
* @param eventName The event name (key of E).
|
|
50
|
+
* @param args The arguments to pass to subscribed listeners.
|
|
51
|
+
*/
|
|
52
|
+
emit<K extends keyof Events>(eventName: K, ...args: Parameters<Events[K]>): void;
|
|
53
|
+
/**
|
|
54
|
+
* Returns the array of listener functions currently registered for a given event.
|
|
55
|
+
* @param eventName The event name (key of E).
|
|
56
|
+
* @returns An array of listener functions.
|
|
57
|
+
*/
|
|
58
|
+
listeners<K extends keyof Events>(eventName: K): Array<(...args: Parameters<Events[K]>) => void>;
|
|
59
|
+
/**
|
|
60
|
+
* Returns the number of listeners for a given event.
|
|
61
|
+
* @param eventName The event name (key of E).
|
|
62
|
+
* @returns The number of listeners.
|
|
63
|
+
*/
|
|
64
|
+
listenerCount<K extends keyof Events>(eventName: K): number;
|
|
65
|
+
/**
|
|
66
|
+
* Removes all listeners for a given event, or all events if none is specified.
|
|
67
|
+
* @param eventName Optional. If omitted, clears all events’ listeners.
|
|
68
|
+
* @returns The emitter instance (for chaining).
|
|
69
|
+
*/
|
|
70
|
+
removeAllListeners<K extends keyof Events>(eventName?: K): this;
|
|
71
|
+
}
|