@signaldb/core 2.0.0-beta.4 → 2.0.0-beta.5
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 +27 -21
- package/dist/Collection/Observer.d.ts +2 -0
- package/dist/Collection/index.d.ts +11 -10
- package/dist/Collection/types.d.ts +7 -0
- package/dist/DefaultDataAdapter.d.ts +2 -0
- package/dist/index.cjs.js +8 -5
- package/dist/index.cjs12.js +41 -346
- package/dist/index.cjs13.js +308 -359
- package/dist/index.cjs14.js +387 -177
- package/dist/index.cjs15.js +182 -364
- package/dist/index.cjs16.js +287 -478
- package/dist/index.cjs17.js +563 -136
- package/dist/index.cjs18.js +154 -23
- package/dist/index.cjs19.js +23 -39
- package/dist/index.cjs2.js +1 -1
- package/dist/index.cjs20.js +39 -13
- package/dist/index.cjs21.js +14 -102
- package/dist/index.cjs22.js +93 -118
- package/dist/index.cjs23.js +127 -5
- package/dist/index.cjs24.js +5 -25
- package/dist/index.cjs25.js +24 -7
- package/dist/index.cjs26.js +8 -27
- package/dist/index.cjs27.js +25 -42
- package/dist/index.cjs28.js +44 -6
- package/dist/index.cjs29.js +6 -7
- package/dist/index.cjs3.js +9 -26
- package/dist/index.cjs30.js +5 -3
- package/dist/index.cjs31.js +40 -5
- package/dist/index.cjs33.js +3 -40
- package/dist/index.cjs34.js +9 -0
- package/dist/index.cjs7.js +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.mjs +10 -7
- package/dist/index12.mjs +40 -346
- package/dist/index13.mjs +308 -359
- package/dist/index14.mjs +387 -177
- package/dist/index15.mjs +182 -364
- package/dist/index16.mjs +287 -478
- package/dist/index17.mjs +563 -136
- package/dist/index18.mjs +154 -23
- package/dist/index19.mjs +23 -38
- package/dist/index2.mjs +1 -1
- package/dist/index20.mjs +38 -13
- package/dist/index21.mjs +14 -102
- package/dist/index22.mjs +93 -117
- package/dist/index23.mjs +126 -5
- package/dist/index24.mjs +5 -25
- package/dist/index25.mjs +24 -7
- package/dist/index26.mjs +8 -27
- package/dist/index27.mjs +25 -42
- package/dist/index28.mjs +44 -6
- package/dist/index29.mjs +6 -7
- package/dist/index3.mjs +9 -26
- package/dist/index30.mjs +5 -3
- package/dist/index31.mjs +40 -5
- package/dist/index33.mjs +3 -40
- package/dist/index34.mjs +10 -0
- package/dist/index7.mjs +1 -1
- package/dist/utils/reactiveOrAsync.d.ts +59 -0
- package/package.json +1 -1
package/dist/index.cjs23.js
CHANGED
|
@@ -1,7 +1,129 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
return
|
|
2
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
3
|
+
const intersection = require("./index.cjs30.js");
|
|
4
|
+
function getMergedIndexInfo(queryFunctions, selector) {
|
|
5
|
+
return queryFunctions.reduce((memoOrPromise, queryFunction) => {
|
|
6
|
+
const resultOrPromise = queryFunction(selector);
|
|
7
|
+
const processResult = (memo2, result) => {
|
|
8
|
+
if (!result.matched)
|
|
9
|
+
return memo2;
|
|
10
|
+
const optimizedSelector = result.keepSelector ? memo2.optimizedSelector : Object.fromEntries(Object.entries(memo2.optimizedSelector).filter(([key]) => !result.fields.includes(key)));
|
|
11
|
+
return {
|
|
12
|
+
matched: true,
|
|
13
|
+
ids: [...new Set(memo2.matched ? intersection(memo2.ids, result.ids) : result.ids)],
|
|
14
|
+
optimizedSelector
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
if (resultOrPromise instanceof Promise) {
|
|
18
|
+
return resultOrPromise.then(async (result) => {
|
|
19
|
+
const memo2 = memoOrPromise instanceof Promise ? await memoOrPromise : memoOrPromise;
|
|
20
|
+
return processResult(memo2, result);
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
const memo = memoOrPromise;
|
|
24
|
+
if (memo instanceof Promise)
|
|
25
|
+
throw new Error("Mixing async and sync index providers is not supported");
|
|
26
|
+
return processResult(memo, resultOrPromise);
|
|
27
|
+
}, {
|
|
28
|
+
matched: false,
|
|
29
|
+
ids: [],
|
|
30
|
+
optimizedSelector: { ...selector }
|
|
31
|
+
});
|
|
6
32
|
}
|
|
7
|
-
|
|
33
|
+
function optimizeLogicGate(queryFunctions, logicGate, idsCallback) {
|
|
34
|
+
return logicGate.reduce((memoOrPromise, sel) => {
|
|
35
|
+
const getSelector = (indexInfo) => {
|
|
36
|
+
const { matched: selMatched, ids: selIds, optimizedSelector: optimizedSelector2 } = indexInfo;
|
|
37
|
+
if (selMatched) {
|
|
38
|
+
idsCallback(true, selIds);
|
|
39
|
+
if (Object.keys(optimizedSelector2).length > 0) {
|
|
40
|
+
return optimizedSelector2;
|
|
41
|
+
}
|
|
42
|
+
} else {
|
|
43
|
+
idsCallback(false, []);
|
|
44
|
+
return sel;
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
const indexInfoOrPromise = getIndexInfo(queryFunctions, sel);
|
|
48
|
+
if (indexInfoOrPromise instanceof Promise) {
|
|
49
|
+
return indexInfoOrPromise.then(async (indexInfo) => {
|
|
50
|
+
const memo2 = memoOrPromise instanceof Promise ? await memoOrPromise : memoOrPromise;
|
|
51
|
+
const optimizedSelector2 = getSelector(indexInfo);
|
|
52
|
+
if (optimizedSelector2)
|
|
53
|
+
memo2.push(optimizedSelector2);
|
|
54
|
+
return memo2;
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
const memo = memoOrPromise;
|
|
58
|
+
if (memo instanceof Promise)
|
|
59
|
+
throw new Error("Mixing async and sync index providers is not supported");
|
|
60
|
+
const optimizedSelector = getSelector(indexInfoOrPromise);
|
|
61
|
+
if (optimizedSelector)
|
|
62
|
+
memo.push(optimizedSelector);
|
|
63
|
+
return memo;
|
|
64
|
+
}, []);
|
|
65
|
+
}
|
|
66
|
+
function getIndexInfo(queryFunctions, selector) {
|
|
67
|
+
if (selector == null || Object.keys(selector).length <= 0) {
|
|
68
|
+
return {
|
|
69
|
+
matched: false,
|
|
70
|
+
ids: [],
|
|
71
|
+
optimizedSelector: selector
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
const { $and, $or, ...rest } = selector;
|
|
75
|
+
const flatInfoOrPromise = getMergedIndexInfo(queryFunctions, rest);
|
|
76
|
+
const processFlatInfo = (flatInfo) => {
|
|
77
|
+
let { matched, ids } = flatInfo;
|
|
78
|
+
const newSelector = flatInfo.optimizedSelector;
|
|
79
|
+
const $andNewOrPromise = Array.isArray($and) ? optimizeLogicGate(queryFunctions, $and, (match, selIds) => {
|
|
80
|
+
if (!match)
|
|
81
|
+
return;
|
|
82
|
+
ids = matched ? intersection(ids, selIds) : selIds;
|
|
83
|
+
matched = true;
|
|
84
|
+
}) : void 0;
|
|
85
|
+
const process$and = ($andNew) => {
|
|
86
|
+
if ($andNew && $andNew.length > 0)
|
|
87
|
+
newSelector.$and = $andNew;
|
|
88
|
+
let hasNonIndexField = false;
|
|
89
|
+
const matchedBefore = matched;
|
|
90
|
+
const idsBefore = ids;
|
|
91
|
+
const process$or = ($orNew) => {
|
|
92
|
+
if ($orNew && $orNew.length > 0)
|
|
93
|
+
newSelector.$or = $orNew;
|
|
94
|
+
if (hasNonIndexField) {
|
|
95
|
+
newSelector.$or = $or;
|
|
96
|
+
matched = matchedBefore;
|
|
97
|
+
ids = idsBefore;
|
|
98
|
+
}
|
|
99
|
+
return {
|
|
100
|
+
matched,
|
|
101
|
+
ids: ids || [],
|
|
102
|
+
optimizedSelector: newSelector
|
|
103
|
+
};
|
|
104
|
+
};
|
|
105
|
+
const $orNewOrPromise = Array.isArray($or) ? optimizeLogicGate(queryFunctions, $or, (match, selIds) => {
|
|
106
|
+
if (match) {
|
|
107
|
+
ids = [.../* @__PURE__ */ new Set([...ids, ...selIds])];
|
|
108
|
+
matched = true;
|
|
109
|
+
} else {
|
|
110
|
+
hasNonIndexField = true;
|
|
111
|
+
}
|
|
112
|
+
}) : void 0;
|
|
113
|
+
if ($orNewOrPromise instanceof Promise) {
|
|
114
|
+
return $orNewOrPromise.then(($orNew) => process$or($orNew));
|
|
115
|
+
}
|
|
116
|
+
return process$or($orNewOrPromise);
|
|
117
|
+
};
|
|
118
|
+
if ($andNewOrPromise instanceof Promise) {
|
|
119
|
+
return $andNewOrPromise.then(($andNew) => process$and($andNew));
|
|
120
|
+
}
|
|
121
|
+
return process$and($andNewOrPromise);
|
|
122
|
+
};
|
|
123
|
+
if (flatInfoOrPromise instanceof Promise) {
|
|
124
|
+
return flatInfoOrPromise.then(processFlatInfo);
|
|
125
|
+
}
|
|
126
|
+
return processFlatInfo(flatInfoOrPromise);
|
|
127
|
+
}
|
|
128
|
+
exports.default = getIndexInfo;
|
|
129
|
+
exports.getMergedIndexInfo = getMergedIndexInfo;
|
package/dist/index.cjs24.js
CHANGED
|
@@ -1,27 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
if (allFieldsDeactivated) {
|
|
7
|
-
const result2 = { ...item };
|
|
8
|
-
Object.keys(fields).forEach((key) => {
|
|
9
|
-
const fieldValue = get(item, key);
|
|
10
|
-
if (fieldValue === void 0)
|
|
11
|
-
return;
|
|
12
|
-
set(result2, key, void 0, true);
|
|
13
|
-
});
|
|
14
|
-
return result2;
|
|
15
|
-
}
|
|
16
|
-
const result = {};
|
|
17
|
-
Object.entries(fields).forEach(([key, value]) => {
|
|
18
|
-
const fieldValue = get(item, key);
|
|
19
|
-
if (fieldValue === void 0)
|
|
20
|
-
return;
|
|
21
|
-
if (fieldValue == null && value !== 1)
|
|
22
|
-
return;
|
|
23
|
-
set(result, key, value === 1 ? fieldValue : void 0);
|
|
24
|
-
});
|
|
25
|
-
return result;
|
|
2
|
+
const mingo = require("mingo");
|
|
3
|
+
function match(item, selector) {
|
|
4
|
+
const query = new mingo.Query(selector);
|
|
5
|
+
return query.test(item);
|
|
26
6
|
}
|
|
27
|
-
module.exports =
|
|
7
|
+
module.exports = match;
|
package/dist/index.cjs25.js
CHANGED
|
@@ -1,10 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
const fastSort = require("fast-sort");
|
|
3
2
|
const get = require("./index.cjs10.js");
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
const set = require("./index.cjs32.js");
|
|
4
|
+
function project(item, fields) {
|
|
5
|
+
const allFieldsDeactivated = Object.values(fields).every((value) => value === 0);
|
|
6
|
+
if (allFieldsDeactivated) {
|
|
7
|
+
const result2 = { ...item };
|
|
8
|
+
Object.keys(fields).forEach((key) => {
|
|
9
|
+
const fieldValue = get(item, key);
|
|
10
|
+
if (fieldValue === void 0)
|
|
11
|
+
return;
|
|
12
|
+
set(result2, key, void 0, true);
|
|
13
|
+
});
|
|
14
|
+
return result2;
|
|
15
|
+
}
|
|
16
|
+
const result = {};
|
|
17
|
+
Object.entries(fields).forEach(([key, value]) => {
|
|
18
|
+
const fieldValue = get(item, key);
|
|
19
|
+
if (fieldValue === void 0)
|
|
20
|
+
return;
|
|
21
|
+
if (fieldValue == null && value !== 1)
|
|
22
|
+
return;
|
|
23
|
+
set(result, key, value === 1 ? fieldValue : void 0);
|
|
24
|
+
});
|
|
25
|
+
return result;
|
|
9
26
|
}
|
|
10
|
-
module.exports =
|
|
27
|
+
module.exports = project;
|
package/dist/index.cjs26.js
CHANGED
|
@@ -1,29 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
function
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
if (fieldSelector == null)
|
|
10
|
-
return result;
|
|
11
|
-
if (isFieldExpression(fieldSelector)) {
|
|
12
|
-
if (fieldSelector.$ne != null) {
|
|
13
|
-
result.exclude = [serializeValue(fieldSelector.$ne)];
|
|
14
|
-
return result;
|
|
15
|
-
}
|
|
16
|
-
if (Array.isArray(fieldSelector.$in) && fieldSelector.$in.length > 0) {
|
|
17
|
-
result.include = fieldSelector.$in.map(serializeValue);
|
|
18
|
-
return result;
|
|
19
|
-
}
|
|
20
|
-
if (Array.isArray(fieldSelector.$nin) && fieldSelector.$nin.length > 0) {
|
|
21
|
-
result.exclude = fieldSelector.$nin.map(serializeValue);
|
|
22
|
-
return result;
|
|
23
|
-
}
|
|
24
|
-
return { include: null, exclude: null };
|
|
25
|
-
}
|
|
26
|
-
result.include = [serializeValue(fieldSelector)];
|
|
27
|
-
return result;
|
|
2
|
+
const fastSort = require("fast-sort");
|
|
3
|
+
const get = require("./index.cjs10.js");
|
|
4
|
+
function sortItems(items, sortFields) {
|
|
5
|
+
return fastSort.sort(items).by(Object.entries(sortFields).map(([key, value]) => {
|
|
6
|
+
const order = value === 1 ? "asc" : "desc";
|
|
7
|
+
return { [order]: (i) => get(i, key) };
|
|
8
|
+
}));
|
|
28
9
|
}
|
|
29
|
-
module.exports =
|
|
10
|
+
module.exports = sortItems;
|
package/dist/index.cjs27.js
CHANGED
|
@@ -1,46 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
async function flush(key) {
|
|
25
|
-
const q = queues.get(key);
|
|
26
|
-
if (!q || q.items.length === 0)
|
|
27
|
-
return;
|
|
28
|
-
if (q.timer != null) {
|
|
29
|
-
clearTimeout(q.timer);
|
|
30
|
-
q.timer = null;
|
|
2
|
+
const isFieldExpression = require("./index.cjs31.js");
|
|
3
|
+
const serializeValue = require("./index.cjs11.js");
|
|
4
|
+
function getMatchingKeys(field, selector) {
|
|
5
|
+
const result = { include: null, exclude: null };
|
|
6
|
+
const fieldSelector = selector[field];
|
|
7
|
+
if (fieldSelector instanceof RegExp)
|
|
8
|
+
return result;
|
|
9
|
+
if (fieldSelector == null)
|
|
10
|
+
return result;
|
|
11
|
+
if (isFieldExpression(fieldSelector)) {
|
|
12
|
+
if (fieldSelector.$ne != null) {
|
|
13
|
+
result.exclude = [serializeValue(fieldSelector.$ne)];
|
|
14
|
+
return result;
|
|
15
|
+
}
|
|
16
|
+
if (Array.isArray(fieldSelector.$in) && fieldSelector.$in.length > 0) {
|
|
17
|
+
result.include = fieldSelector.$in.map(serializeValue);
|
|
18
|
+
return result;
|
|
19
|
+
}
|
|
20
|
+
if (Array.isArray(fieldSelector.$nin) && fieldSelector.$nin.length > 0) {
|
|
21
|
+
result.exclude = fieldSelector.$nin.map(serializeValue);
|
|
22
|
+
return result;
|
|
31
23
|
}
|
|
32
|
-
|
|
33
|
-
onFlush(key, items.map((i) => i.args)).then((results) => {
|
|
34
|
-
for (const [index, result] of results.entries()) {
|
|
35
|
-
const { resolve } = items[index];
|
|
36
|
-
resolve(result);
|
|
37
|
-
}
|
|
38
|
-
}).catch((error) => {
|
|
39
|
-
for (const { reject } of items) {
|
|
40
|
-
reject(error);
|
|
41
|
-
}
|
|
42
|
-
});
|
|
24
|
+
return { include: null, exclude: null };
|
|
43
25
|
}
|
|
44
|
-
|
|
26
|
+
result.include = [serializeValue(fieldSelector)];
|
|
27
|
+
return result;
|
|
45
28
|
}
|
|
46
|
-
module.exports =
|
|
29
|
+
module.exports = getMatchingKeys;
|
package/dist/index.cjs28.js
CHANGED
|
@@ -1,8 +1,46 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
function
|
|
3
|
-
|
|
2
|
+
function batchOnNextTick(onFlush) {
|
|
3
|
+
const queues = /* @__PURE__ */ new Map();
|
|
4
|
+
function enqueue(key, args) {
|
|
5
|
+
return new Promise((resolve, reject) => {
|
|
6
|
+
let q = queues.get(key);
|
|
7
|
+
if (!q) {
|
|
8
|
+
q = {
|
|
9
|
+
timer: null,
|
|
10
|
+
items: [],
|
|
11
|
+
flush: () => flush(key)
|
|
12
|
+
};
|
|
13
|
+
queues.set(key, q);
|
|
14
|
+
}
|
|
15
|
+
q.items.push({ args, resolve, reject });
|
|
16
|
+
if (q.timer == null) {
|
|
17
|
+
q.timer = setTimeout(() => {
|
|
18
|
+
q.timer = null;
|
|
19
|
+
void q.flush();
|
|
20
|
+
}, 0);
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
async function flush(key) {
|
|
25
|
+
const q = queues.get(key);
|
|
26
|
+
if (!q || q.items.length === 0)
|
|
27
|
+
return;
|
|
28
|
+
if (q.timer != null) {
|
|
29
|
+
clearTimeout(q.timer);
|
|
30
|
+
q.timer = null;
|
|
31
|
+
}
|
|
32
|
+
const items = q.items.splice(0);
|
|
33
|
+
onFlush(key, items.map((i) => i.args)).then((results) => {
|
|
34
|
+
for (const [index, result] of results.entries()) {
|
|
35
|
+
const { resolve } = items[index];
|
|
36
|
+
resolve(result);
|
|
37
|
+
}
|
|
38
|
+
}).catch((error) => {
|
|
39
|
+
for (const { reject } of items) {
|
|
40
|
+
reject(error);
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
return { enqueue, flush };
|
|
4
45
|
}
|
|
5
|
-
|
|
6
|
-
return array.filter(truthy);
|
|
7
|
-
}
|
|
8
|
-
module.exports = compact;
|
|
46
|
+
module.exports = batchOnNextTick;
|
package/dist/index.cjs29.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
function
|
|
3
|
-
|
|
4
|
-
return array.filter((element) => {
|
|
5
|
-
const value = typeof fn === "function" ? fn(element) : element[fn];
|
|
6
|
-
return !set.has(value) && set.add(value);
|
|
7
|
-
});
|
|
2
|
+
function truthy(value) {
|
|
3
|
+
return !!value;
|
|
8
4
|
}
|
|
9
|
-
|
|
5
|
+
function compact(array) {
|
|
6
|
+
return array.filter(truthy);
|
|
7
|
+
}
|
|
8
|
+
module.exports = compact;
|
package/dist/index.cjs3.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
3
3
|
const EventEmitter = require("./index.cjs9.js");
|
|
4
|
-
const createSignal = require("./index.
|
|
4
|
+
const createSignal = require("./index.cjs19.js");
|
|
5
5
|
const randomId = require("./index.cjs8.js");
|
|
6
|
-
const DefaultDataAdapter = require("./index.
|
|
6
|
+
const DefaultDataAdapter = require("./index.cjs13.js");
|
|
7
7
|
const modify = require("./index.cjs7.js");
|
|
8
|
-
const deepClone = require("./index.
|
|
9
|
-
const queryId = require("./index.
|
|
8
|
+
const deepClone = require("./index.cjs20.js");
|
|
9
|
+
const queryId = require("./index.cjs21.js");
|
|
10
10
|
const Cursor = require("./index.cjs2.js");
|
|
11
11
|
class Collection extends EventEmitter {
|
|
12
12
|
static collections = [];
|
|
@@ -246,14 +246,6 @@ class Collection extends EventEmitter {
|
|
|
246
246
|
Collection.collections = Collection.collections.filter((collection) => collection !== this);
|
|
247
247
|
Collection.onDisposeCallbacks.forEach((callback) => callback(this));
|
|
248
248
|
}
|
|
249
|
-
/**
|
|
250
|
-
* Finds multiple items in the collection based on a selector and optional options.
|
|
251
|
-
* Returns a cursor for reactive data queries.
|
|
252
|
-
* @template O - The options type for the find operation.
|
|
253
|
-
* @param [selector] - The criteria to select items.
|
|
254
|
-
* @param [options] - Options for the find operation, such as limit and sort.
|
|
255
|
-
* @returns A cursor to fetch and observe the matching items.
|
|
256
|
-
*/
|
|
257
249
|
find(selector = {}, options) {
|
|
258
250
|
if (this.isDisposed)
|
|
259
251
|
throw new Error("Collection is disposed");
|
|
@@ -283,7 +275,8 @@ class Collection extends EventEmitter {
|
|
|
283
275
|
requery();
|
|
284
276
|
};
|
|
285
277
|
const listeners = this.queryListeners({ selector, options });
|
|
286
|
-
|
|
278
|
+
const didRegister = listeners === 0;
|
|
279
|
+
if (didRegister)
|
|
287
280
|
this.backend.registerQuery(selector, options || {});
|
|
288
281
|
this.queryListeners({ selector, options }, listeners + 1);
|
|
289
282
|
const queryStateChangeCleanup = this.backend.onQueryStateChange(selector, options || {}, (state) => {
|
|
@@ -293,14 +286,14 @@ class Collection extends EventEmitter {
|
|
|
293
286
|
});
|
|
294
287
|
this.emit("observer.created", selector, options);
|
|
295
288
|
return () => {
|
|
296
|
-
|
|
289
|
+
queueMicrotask(() => {
|
|
297
290
|
const newListeners = Math.max(0, this.queryListeners({ selector, options }) - 1);
|
|
298
|
-
if (newListeners === 0)
|
|
291
|
+
if (newListeners === 0 && didRegister)
|
|
299
292
|
this.backend.unregisterQuery(selector, options || {});
|
|
300
293
|
this.queryListeners({ selector, options }, newListeners);
|
|
301
294
|
queryStateChangeCleanup();
|
|
302
295
|
this.emit("observer.disposed", selector, options);
|
|
303
|
-
}
|
|
296
|
+
});
|
|
304
297
|
};
|
|
305
298
|
}
|
|
306
299
|
});
|
|
@@ -308,16 +301,6 @@ class Collection extends EventEmitter {
|
|
|
308
301
|
this.executeInDebugMode((callstack) => this.emit("_debug.find", callstack, selector, options, cursor));
|
|
309
302
|
return cursor;
|
|
310
303
|
}
|
|
311
|
-
/**
|
|
312
|
-
* Finds a single item in the collection based on a selector and optional options.
|
|
313
|
-
* ⚡️ this function is reactive!
|
|
314
|
-
* Returns the found item or undefined if no item matches.
|
|
315
|
-
* @template Async - Whether to perform the operation asynchronously.
|
|
316
|
-
* @template O - The options type for the find operation.
|
|
317
|
-
* @param selector - The criteria to select the item.
|
|
318
|
-
* @param [options] - Options for the find operation, such as projection.
|
|
319
|
-
* @returns The found item or `undefined`.
|
|
320
|
-
*/
|
|
321
304
|
findOne(selector, options) {
|
|
322
305
|
if (this.isDisposed)
|
|
323
306
|
throw new Error("Collection is disposed");
|
package/dist/index.cjs30.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
function
|
|
3
|
-
|
|
2
|
+
function intersection(...arrays) {
|
|
3
|
+
if (arrays.length === 0)
|
|
4
|
+
return [];
|
|
5
|
+
return [...new Set(arrays.reduce((a, b) => a.filter((c) => b.includes(c))))];
|
|
4
6
|
}
|
|
5
|
-
module.exports =
|
|
7
|
+
module.exports = intersection;
|
package/dist/index.cjs31.js
CHANGED
|
@@ -1,7 +1,42 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
const expressionKeys = /* @__PURE__ */ 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
|
+
function isFieldExpression(expression) {
|
|
29
|
+
if (typeof expression !== "object" || expression == null) {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
const keys = Object.keys(expression);
|
|
33
|
+
if (keys.length === 0) {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
const hasInvalidKeys = keys.some((key) => !expressionKeys.has(key));
|
|
37
|
+
if (hasInvalidKeys)
|
|
38
|
+
return false;
|
|
39
|
+
const hasValidKeys = keys.every((key) => expressionKeys.has(key));
|
|
40
|
+
return hasValidKeys;
|
|
6
41
|
}
|
|
7
|
-
module.exports =
|
|
42
|
+
module.exports = isFieldExpression;
|
package/dist/index.cjs33.js
CHANGED
|
@@ -1,42 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
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
|
-
function isFieldExpression(expression) {
|
|
29
|
-
if (typeof expression !== "object" || expression == null) {
|
|
30
|
-
return false;
|
|
31
|
-
}
|
|
32
|
-
const keys = Object.keys(expression);
|
|
33
|
-
if (keys.length === 0) {
|
|
34
|
-
return false;
|
|
35
|
-
}
|
|
36
|
-
const hasInvalidKeys = keys.some((key) => !expressionKeys.has(key));
|
|
37
|
-
if (hasInvalidKeys)
|
|
38
|
-
return false;
|
|
39
|
-
const hasValidKeys = keys.every((key) => expressionKeys.has(key));
|
|
40
|
-
return hasValidKeys;
|
|
2
|
+
function createIndexProvider(definition) {
|
|
3
|
+
return definition;
|
|
41
4
|
}
|
|
42
|
-
module.exports =
|
|
5
|
+
module.exports = createIndexProvider;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
function uniqueBy(array, fn) {
|
|
3
|
+
const set = /* @__PURE__ */ new Set();
|
|
4
|
+
return array.filter((element) => {
|
|
5
|
+
const value = typeof fn === "function" ? fn(element) : element[fn];
|
|
6
|
+
return !set.has(value) && set.add(value);
|
|
7
|
+
});
|
|
8
|
+
}
|
|
9
|
+
module.exports = uniqueBy;
|
package/dist/index.cjs7.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
const mingo = require("mingo");
|
|
3
|
-
const deepClone = require("./index.
|
|
3
|
+
const deepClone = require("./index.cjs20.js");
|
|
4
4
|
function modify(item, modifier) {
|
|
5
5
|
const hasOperators = Object.keys(modifier).some((key) => key.startsWith("$"));
|
|
6
6
|
if (!hasOperators)
|
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, TransformAll, 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
|
@@ -8,25 +8,28 @@ import { default as default8 } from "./index8.mjs";
|
|
|
8
8
|
import { default as default9 } from "./index9.mjs";
|
|
9
9
|
import { default as default10 } from "./index10.mjs";
|
|
10
10
|
import { default as default11 } from "./index11.mjs";
|
|
11
|
-
import { default as default12 } from "./index12.mjs";
|
|
11
|
+
import { default as default12, unwrap } from "./index12.mjs";
|
|
12
12
|
import { default as default13 } from "./index13.mjs";
|
|
13
13
|
import { default as default14 } from "./index14.mjs";
|
|
14
14
|
import { default as default15 } from "./index15.mjs";
|
|
15
15
|
import { default as default16 } from "./index16.mjs";
|
|
16
|
+
import { default as default17 } from "./index17.mjs";
|
|
16
17
|
export {
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
default14 as AsyncDataAdapter,
|
|
19
|
+
default17 as AutoFetchDataAdapter,
|
|
19
20
|
default3 as Collection,
|
|
20
21
|
default2 as Cursor,
|
|
21
|
-
|
|
22
|
+
default13 as DefaultDataAdapter,
|
|
22
23
|
default9 as EventEmitter,
|
|
23
|
-
|
|
24
|
-
|
|
24
|
+
default15 as WorkerDataAdapter,
|
|
25
|
+
default16 as WorkerDataAdapterHost,
|
|
25
26
|
default5 as createReactivityAdapter,
|
|
26
27
|
default4 as createStorageAdapter,
|
|
27
28
|
default10 as get,
|
|
28
29
|
default6 as isEqual,
|
|
29
30
|
default7 as modify,
|
|
30
31
|
default8 as randomId,
|
|
31
|
-
|
|
32
|
+
default12 as reactiveOrAsync,
|
|
33
|
+
default11 as serializeValue,
|
|
34
|
+
unwrap
|
|
32
35
|
};
|