@signaldb/core 2.0.0-beta.18 → 2.0.0-beta.19
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 +39 -17
- package/dist/index.cjs.js +9 -9
- package/dist/index.mjs +9 -9
- package/dist/index17.cjs.js +7 -2
- package/dist/index17.mjs +7 -2
- package/dist/index27.cjs.js +36 -337
- package/dist/index27.mjs +36 -337
- package/dist/index28.cjs.js +318 -573
- package/dist/index28.mjs +318 -573
- package/dist/index29.cjs.js +599 -8
- package/dist/index29.mjs +599 -8
- package/dist/index30.cjs.js +6 -6
- package/dist/index30.mjs +6 -6
- package/dist/index31.cjs.js +7 -86
- package/dist/index31.mjs +7 -85
- package/dist/index32.cjs.js +76 -465
- package/dist/index32.mjs +75 -465
- package/dist/index33.cjs.js +45 -64
- package/dist/index33.mjs +45 -64
- package/dist/index34.cjs.js +403 -530
- package/dist/index34.mjs +405 -532
- package/dist/index35.cjs.js +68 -17
- package/dist/index35.mjs +68 -17
- package/dist/index36.cjs.js +535 -344
- package/dist/index36.mjs +537 -346
- package/dist/index37.cjs.js +14 -532
- package/dist/index37.mjs +14 -532
- package/dist/index38.cjs.js +363 -0
- package/dist/index38.mjs +363 -0
- package/dist/index39.cjs.js +513 -0
- package/dist/index39.mjs +513 -0
- package/dist/types/StorageAdapter.d.ts +9 -1
- package/dist/utils/idIndexQuery.d.ts +20 -0
- package/dist/utils/storageIndexQuery.d.ts +20 -0
- package/package.json +1 -1
package/dist/index33.mjs
CHANGED
|
@@ -1,72 +1,53 @@
|
|
|
1
|
-
|
|
1
|
+
import getMatchingKeys from "./index14.mjs";
|
|
2
|
+
//#region src/utils/storageIndexQuery.ts
|
|
2
3
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* @returns An object with `enqueue` and `flush` methods.
|
|
6
|
-
* @example
|
|
7
|
-
* const batcher = batchOnNextTick<string>(async (key, items) => {
|
|
8
|
-
* // items is an array of { args, resolve, reject }
|
|
9
|
-
* // do something once with all args...
|
|
10
|
-
* })
|
|
4
|
+
* Builds the index provider a data adapter uses to narrow a selector down through
|
|
5
|
+
* a storage adapter's index.
|
|
11
6
|
*
|
|
12
|
-
*
|
|
7
|
+
* Every adapter that keeps its data in a `StorageAdapter` needs exactly this, and
|
|
8
|
+
* each of them used to carry its own copy — three transcriptions of one set of
|
|
9
|
+
* rules about null, `$exists`, inclusion and exclusion, which is how they drift
|
|
10
|
+
* apart without anyone noticing. The index is keyed by `serializeValue(value)`,
|
|
11
|
+
* which is what `getMatchingKeys` produces, so the two only agree while they stay
|
|
12
|
+
* in one place.
|
|
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 storage - The storage adapter holding the index.
|
|
16
|
+
* @param field - The indexed field this provider answers for.
|
|
17
|
+
* @returns A query function for `getIndexInfo`.
|
|
13
18
|
*/
|
|
14
|
-
function
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
};
|
|
31
|
-
queues.set(key, q);
|
|
32
|
-
}
|
|
33
|
-
q.items.push({
|
|
34
|
-
args,
|
|
35
|
-
resolve,
|
|
36
|
-
reject
|
|
37
|
-
});
|
|
38
|
-
if (q.timer == null) q.timer = setTimeout(() => {
|
|
39
|
-
q.timer = null;
|
|
40
|
-
q.flush();
|
|
41
|
-
}, 0);
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Flush the queue for the given key immediately.
|
|
46
|
-
* @param key key to flush
|
|
47
|
-
* @returns A promise that resolves when the flush is complete.
|
|
48
|
-
*/
|
|
49
|
-
async function flush(key) {
|
|
50
|
-
const q = queues.get(key);
|
|
51
|
-
if (!q || q.items.length === 0) return;
|
|
52
|
-
if (q.timer != null) {
|
|
53
|
-
clearTimeout(q.timer);
|
|
54
|
-
q.timer = null;
|
|
19
|
+
function storageIndexQuery(storage, field) {
|
|
20
|
+
return async (flatSelector) => {
|
|
21
|
+
if (!Object.hasOwnProperty.call(flatSelector, field)) return { matched: false };
|
|
22
|
+
const index = await storage.readIndex(field);
|
|
23
|
+
const fieldSelector = flatSelector[field];
|
|
24
|
+
const filtersForNull = fieldSelector == null || fieldSelector.$exists === false;
|
|
25
|
+
const keys = filtersForNull ? {
|
|
26
|
+
include: null,
|
|
27
|
+
exclude: [...index.keys()].filter((key) => key != null)
|
|
28
|
+
} : getMatchingKeys(field, flatSelector);
|
|
29
|
+
if (keys.include == null && keys.exclude == null) return { matched: false };
|
|
30
|
+
let includedIds = [];
|
|
31
|
+
if (keys.include == null) for (const set of index.values()) for (const id of set) includedIds.push(id);
|
|
32
|
+
else for (const key of keys.include) {
|
|
33
|
+
const idSet = index.get(key);
|
|
34
|
+
if (idSet) for (const id of idSet) includedIds.push(id);
|
|
55
35
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
for (const
|
|
59
|
-
const
|
|
60
|
-
|
|
36
|
+
if (keys.exclude != null) {
|
|
37
|
+
const excludedIds = /* @__PURE__ */ new Set();
|
|
38
|
+
for (const key of keys.exclude) {
|
|
39
|
+
const idSet = index.get(key);
|
|
40
|
+
if (idSet) for (const id of idSet) excludedIds.add(id);
|
|
61
41
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
42
|
+
includedIds = includedIds.filter((id) => !excludedIds.has(id));
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
matched: true,
|
|
46
|
+
ids: includedIds,
|
|
47
|
+
fields: [field],
|
|
48
|
+
keepSelector: filtersForNull
|
|
49
|
+
};
|
|
69
50
|
};
|
|
70
51
|
}
|
|
71
52
|
//#endregion
|
|
72
|
-
export {
|
|
53
|
+
export { storageIndexQuery as default };
|