@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
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
const require_intersection = require("./index15.cjs.js");
|
|
2
|
+
//#region src/getIndexInfo.ts
|
|
3
|
+
/**
|
|
4
|
+
* Retrieves merged index information for a given flat selector by querying multiple
|
|
5
|
+
* index providers. Combines results from all index providers to determine matched ids
|
|
6
|
+
* and an optimized selector.
|
|
7
|
+
* @template T - The type of the items in the collection.
|
|
8
|
+
* @template I - The type of the unique identifier for the items.
|
|
9
|
+
* @param queryFunctions - An array of index providers to query.
|
|
10
|
+
* @param selector - The flat selector used to filter items.
|
|
11
|
+
* @returns An object containing:
|
|
12
|
+
* - `matched`: A boolean indicating if the selector matched any items.
|
|
13
|
+
* - `ids`: An array of matched item ids.
|
|
14
|
+
* - `optimizedSelector`: A flat selector optimized based on the index results.
|
|
15
|
+
*/
|
|
16
|
+
function getMergedIndexInfo(queryFunctions, selector) {
|
|
17
|
+
return queryFunctions.reduce((memoOrPromise, queryFunction) => {
|
|
18
|
+
const resultOrPromise = queryFunction(selector);
|
|
19
|
+
const processResult = (memo, result) => {
|
|
20
|
+
if (!result.matched) return memo;
|
|
21
|
+
const optimizedSelector = result.keepSelector ? memo.optimizedSelector : Object.fromEntries(Object.entries(memo.optimizedSelector).filter(([key]) => !result.fields.includes(key)));
|
|
22
|
+
return {
|
|
23
|
+
matched: true,
|
|
24
|
+
ids: [...new Set(memo.matched ? require_intersection.default(memo.ids, result.ids) : result.ids)],
|
|
25
|
+
optimizedSelector
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
if (resultOrPromise instanceof Promise) return resultOrPromise.then(async (result) => {
|
|
29
|
+
return processResult(memoOrPromise instanceof Promise ? await memoOrPromise : memoOrPromise, result);
|
|
30
|
+
});
|
|
31
|
+
const memo = memoOrPromise;
|
|
32
|
+
if (memo instanceof Promise) throw new Error("Mixing async and sync index providers is not supported");
|
|
33
|
+
return processResult(memo, resultOrPromise);
|
|
34
|
+
}, {
|
|
35
|
+
matched: false,
|
|
36
|
+
ids: [],
|
|
37
|
+
optimizedSelector: { ...selector }
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Optimizes a logic gate ($and/$or) of selectors by querying multiple index providers.
|
|
42
|
+
* @param queryFunctions - An array of index providers to query.
|
|
43
|
+
* @param logicGate - An array of selectors representing the logic gate.
|
|
44
|
+
* @param idsCallback - A callback function called with matched ids.
|
|
45
|
+
* @returns An array of optimized selectors or a promise that resolves to such an array.
|
|
46
|
+
*/
|
|
47
|
+
function optimizeLogicGate(queryFunctions, logicGate, idsCallback) {
|
|
48
|
+
return logicGate.reduce((memoOrPromise, sel) => {
|
|
49
|
+
const getSelector = (indexInfo) => {
|
|
50
|
+
const { matched: selMatched, ids: selIds, optimizedSelector } = indexInfo;
|
|
51
|
+
if (selMatched) {
|
|
52
|
+
idsCallback(true, selIds);
|
|
53
|
+
if (Object.keys(optimizedSelector).length > 0) return optimizedSelector;
|
|
54
|
+
} else {
|
|
55
|
+
idsCallback(false, []);
|
|
56
|
+
return sel;
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
const indexInfoOrPromise = getIndexInfo(queryFunctions, sel);
|
|
60
|
+
if (indexInfoOrPromise instanceof Promise) return indexInfoOrPromise.then(async (indexInfo) => {
|
|
61
|
+
const memo = memoOrPromise instanceof Promise ? await memoOrPromise : memoOrPromise;
|
|
62
|
+
const optimizedSelector = getSelector(indexInfo);
|
|
63
|
+
if (optimizedSelector) memo.push(optimizedSelector);
|
|
64
|
+
return memo;
|
|
65
|
+
});
|
|
66
|
+
const memo = memoOrPromise;
|
|
67
|
+
if (memo instanceof Promise) throw new Error("Mixing async and sync index providers is not supported");
|
|
68
|
+
const optimizedSelector = getSelector(indexInfoOrPromise);
|
|
69
|
+
if (optimizedSelector) memo.push(optimizedSelector);
|
|
70
|
+
return memo;
|
|
71
|
+
}, []);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Retrieves index information for a given complex selector by querying multiple
|
|
75
|
+
* index providers. Handles nested `$and` and `$or` conditions in the selector and
|
|
76
|
+
* optimizes the selector to minimize processing overhead.
|
|
77
|
+
* @template T - The type of the items in the collection.
|
|
78
|
+
* @template I - The type of the unique identifier for the items.
|
|
79
|
+
* @param queryFunctions - An array of index providers to query.
|
|
80
|
+
* @param selector - The complex selector used to filter items.
|
|
81
|
+
* @returns An object containing:
|
|
82
|
+
* - `matched`: A boolean indicating if the selector matched any items.
|
|
83
|
+
* - `ids`: An array of matched item ids.
|
|
84
|
+
* - `optimizedSelector`: A selector optimized based on the index results, with unused
|
|
85
|
+
* conditions removed.
|
|
86
|
+
*/
|
|
87
|
+
function getIndexInfo(queryFunctions, selector) {
|
|
88
|
+
if (selector == null || Object.keys(selector).length <= 0) return {
|
|
89
|
+
matched: false,
|
|
90
|
+
ids: [],
|
|
91
|
+
optimizedSelector: selector
|
|
92
|
+
};
|
|
93
|
+
const { $and, $or, ...rest } = selector;
|
|
94
|
+
const flatInfoOrPromise = getMergedIndexInfo(queryFunctions, rest);
|
|
95
|
+
const processFlatInfo = (flatInfo) => {
|
|
96
|
+
let { matched, ids } = flatInfo;
|
|
97
|
+
const newSelector = flatInfo.optimizedSelector;
|
|
98
|
+
const $andNewOrPromise = Array.isArray($and) ? optimizeLogicGate(queryFunctions, $and, (match, selIds) => {
|
|
99
|
+
if (!match) return;
|
|
100
|
+
ids = matched ? require_intersection.default(ids, selIds) : selIds;
|
|
101
|
+
matched = true;
|
|
102
|
+
}) : void 0;
|
|
103
|
+
const process$and = ($andNew) => {
|
|
104
|
+
if ($andNew && $andNew.length > 0) newSelector.$and = $andNew;
|
|
105
|
+
let hasNonIndexField = false;
|
|
106
|
+
const matchedBefore = matched;
|
|
107
|
+
const idsBefore = ids;
|
|
108
|
+
const process$or = ($orNew) => {
|
|
109
|
+
if (hasNonIndexField || $orNew && $orNew.length > 0) {
|
|
110
|
+
newSelector.$or = $or;
|
|
111
|
+
matched = matchedBefore;
|
|
112
|
+
ids = idsBefore;
|
|
113
|
+
}
|
|
114
|
+
return {
|
|
115
|
+
matched,
|
|
116
|
+
ids: ids || [],
|
|
117
|
+
optimizedSelector: newSelector
|
|
118
|
+
};
|
|
119
|
+
};
|
|
120
|
+
const $orNewOrPromise = Array.isArray($or) ? optimizeLogicGate(queryFunctions, $or, (match, selIds) => {
|
|
121
|
+
if (match) {
|
|
122
|
+
ids = [...new Set([...ids, ...selIds])];
|
|
123
|
+
matched = true;
|
|
124
|
+
} else hasNonIndexField = true;
|
|
125
|
+
}) : void 0;
|
|
126
|
+
if ($orNewOrPromise instanceof Promise) return $orNewOrPromise.then(($orNew) => process$or($orNew));
|
|
127
|
+
return process$or($orNewOrPromise);
|
|
128
|
+
};
|
|
129
|
+
if ($andNewOrPromise instanceof Promise) return $andNewOrPromise.then(($andNew) => process$and($andNew));
|
|
130
|
+
return process$and($andNewOrPromise);
|
|
131
|
+
};
|
|
132
|
+
if (flatInfoOrPromise instanceof Promise) return flatInfoOrPromise.then(processFlatInfo);
|
|
133
|
+
return processFlatInfo(flatInfoOrPromise);
|
|
134
|
+
}
|
|
135
|
+
//#endregion
|
|
136
|
+
exports.default = getIndexInfo;
|