@signaldb/core 1.2.4 → 1.3.1
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 +28 -47
- package/dist/index.cjs.js +12 -18
- package/dist/index.cjs10.js +6 -27
- package/dist/index.cjs11.js +3 -6
- package/dist/index.cjs12.js +136 -3
- package/dist/index.cjs13.js +61 -131
- package/dist/index.cjs14.js +5 -38
- package/dist/index.cjs15.js +42 -2
- package/dist/index.cjs16.js +11 -5
- package/dist/index.cjs17.js +17 -40
- package/dist/index.cjs18.js +262 -11
- package/dist/index.cjs19.js +66 -16
- package/dist/index.cjs2.js +688 -96
- package/dist/index.cjs20.js +71 -247
- package/dist/index.cjs21.js +8 -68
- package/dist/index.cjs22.js +22 -83
- package/dist/index.cjs23.js +144 -8
- package/dist/index.cjs24.js +5 -25
- package/dist/index.cjs25.js +16 -144
- package/dist/index.cjs26.js +27 -5
- package/dist/index.cjs27.js +39 -15
- package/dist/index.cjs28.js +25 -24
- package/dist/index.cjs29.js +7 -40
- package/dist/index.cjs3.js +139 -664
- package/dist/index.cjs4.js +62 -166
- package/dist/index.cjs5.js +3 -67
- package/dist/index.cjs6.js +2 -2
- package/dist/index.cjs7.js +2 -2
- package/dist/index.cjs8.js +2 -2
- package/dist/index.cjs9.js +27 -3
- package/dist/index.d.ts +0 -1
- package/dist/index.mjs +12 -18
- package/dist/index10.mjs +6 -27
- package/dist/index11.mjs +3 -6
- package/dist/index12.mjs +136 -3
- package/dist/index13.mjs +60 -131
- package/dist/index14.mjs +5 -37
- package/dist/index15.mjs +41 -2
- package/dist/index16.mjs +11 -5
- package/dist/index17.mjs +17 -39
- package/dist/index18.mjs +261 -11
- package/dist/index19.mjs +65 -16
- package/dist/index2.mjs +688 -94
- package/dist/index20.mjs +71 -247
- package/dist/index21.mjs +8 -67
- package/dist/index22.mjs +22 -82
- package/dist/index23.mjs +144 -8
- package/dist/index24.mjs +5 -25
- package/dist/index25.mjs +16 -144
- package/dist/index26.mjs +27 -5
- package/dist/index27.mjs +39 -15
- package/dist/index28.mjs +25 -24
- package/dist/index29.mjs +7 -40
- package/dist/index3.mjs +139 -664
- package/dist/index4.mjs +61 -166
- package/dist/index5.mjs +3 -66
- package/dist/index6.mjs +2 -2
- package/dist/index7.mjs +2 -2
- package/dist/index8.mjs +2 -2
- package/dist/index9.mjs +27 -3
- package/dist/utils/getMatchingKeys.d.ts +11 -6
- package/package.json +1 -1
- package/dist/devtools.d.ts +0 -4
- package/dist/index.cjs30.js +0 -29
- package/dist/index.cjs31.js +0 -9
- package/dist/index30.mjs +0 -30
- package/dist/index31.mjs +0 -10
package/dist/index.cjs14.js
CHANGED
|
@@ -1,40 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
const serializeValue = require("./index.cjs18.js");
|
|
7
|
-
function createExternalIndex(field, index) {
|
|
8
|
-
return createIndexProvider({
|
|
9
|
-
query(selector) {
|
|
10
|
-
const keys = getMatchingKeys(field, selector);
|
|
11
|
-
if (keys == null)
|
|
12
|
-
return { matched: false };
|
|
13
|
-
const itemPositions = keys.reduce((memo, key) => [...memo, ...index.get(key) || []], []);
|
|
14
|
-
return {
|
|
15
|
-
matched: true,
|
|
16
|
-
positions: itemPositions,
|
|
17
|
-
fields: [field]
|
|
18
|
-
};
|
|
19
|
-
},
|
|
20
|
-
rebuild() {
|
|
21
|
-
}
|
|
22
|
-
});
|
|
2
|
+
const mingo = require("mingo");
|
|
3
|
+
function match(item, selector) {
|
|
4
|
+
const query = new mingo.Query(selector);
|
|
5
|
+
return query.test(item);
|
|
23
6
|
}
|
|
24
|
-
|
|
25
|
-
const index = /* @__PURE__ */ new Map();
|
|
26
|
-
return {
|
|
27
|
-
...createExternalIndex(field, index),
|
|
28
|
-
rebuild(items) {
|
|
29
|
-
index.clear();
|
|
30
|
-
items.forEach((item, i) => {
|
|
31
|
-
const value = serializeValue(get(item, field));
|
|
32
|
-
const current = index.get(value) || /* @__PURE__ */ new Set();
|
|
33
|
-
current.add(i);
|
|
34
|
-
index.set(value, current);
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
exports.createExternalIndex = createExternalIndex;
|
|
40
|
-
exports.default = createIndex;
|
|
7
|
+
module.exports = match;
|
package/dist/index.cjs15.js
CHANGED
|
@@ -1,3 +1,43 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
3
|
+
function clone(value) {
|
|
4
|
+
if (typeof value === "function")
|
|
5
|
+
throw new Error("Cloning functions is not supported");
|
|
6
|
+
if (value === null || typeof value !== "object")
|
|
7
|
+
return value;
|
|
8
|
+
if (value instanceof Date)
|
|
9
|
+
return new Date(value);
|
|
10
|
+
if (Array.isArray(value))
|
|
11
|
+
return value.map((item) => clone(item));
|
|
12
|
+
if (value instanceof Map) {
|
|
13
|
+
const result2 = /* @__PURE__ */ new Map();
|
|
14
|
+
value.forEach((currentValue, key) => {
|
|
15
|
+
result2.set(key, clone(currentValue));
|
|
16
|
+
});
|
|
17
|
+
return result2;
|
|
18
|
+
}
|
|
19
|
+
if (value instanceof Set) {
|
|
20
|
+
const result2 = /* @__PURE__ */ new Set();
|
|
21
|
+
value.forEach((currentValue) => {
|
|
22
|
+
result2.add(clone(currentValue));
|
|
23
|
+
});
|
|
24
|
+
return result2;
|
|
25
|
+
}
|
|
26
|
+
if (value instanceof RegExp)
|
|
27
|
+
return new RegExp(value);
|
|
28
|
+
const result = {};
|
|
29
|
+
for (const key in value) {
|
|
30
|
+
if (Object.hasOwnProperty.call(value, key)) {
|
|
31
|
+
result[key] = clone(value[key]);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return result;
|
|
35
|
+
}
|
|
36
|
+
function deepClone(object) {
|
|
37
|
+
if (typeof structuredClone === "function")
|
|
38
|
+
return structuredClone(object);
|
|
39
|
+
/* istanbul ignore next -- @preserve */
|
|
40
|
+
return clone(object);
|
|
41
|
+
}
|
|
42
|
+
exports.clone = clone;
|
|
43
|
+
exports.default = deepClone;
|
package/dist/index.cjs16.js
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
function serializeValue(value) {
|
|
3
|
+
if (typeof value === "string")
|
|
4
|
+
return value;
|
|
5
|
+
if (typeof value === "number")
|
|
6
|
+
return value.toString();
|
|
7
|
+
if (typeof value === "boolean")
|
|
8
|
+
return value.toString();
|
|
9
|
+
if (value instanceof Date)
|
|
10
|
+
return value.toISOString();
|
|
11
|
+
return JSON.stringify(value);
|
|
6
12
|
}
|
|
7
|
-
module.exports =
|
|
13
|
+
module.exports = serializeValue;
|
package/dist/index.cjs17.js
CHANGED
|
@@ -1,43 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
});
|
|
17
|
-
return result2;
|
|
18
|
-
}
|
|
19
|
-
if (value instanceof Set) {
|
|
20
|
-
const result2 = /* @__PURE__ */ new Set();
|
|
21
|
-
value.forEach((currentValue) => {
|
|
22
|
-
result2.add(clone(currentValue));
|
|
23
|
-
});
|
|
24
|
-
return result2;
|
|
25
|
-
}
|
|
26
|
-
if (value instanceof RegExp)
|
|
27
|
-
return new RegExp(value);
|
|
28
|
-
const result = {};
|
|
29
|
-
for (const key in value) {
|
|
30
|
-
if (Object.hasOwnProperty.call(value, key)) {
|
|
31
|
-
result[key] = clone(value[key]);
|
|
2
|
+
function createSignal(dependency, initialValue, isEqual = Object.is) {
|
|
3
|
+
let value = initialValue;
|
|
4
|
+
const signal = {
|
|
5
|
+
get() {
|
|
6
|
+
if (dependency)
|
|
7
|
+
dependency.depend();
|
|
8
|
+
return value;
|
|
9
|
+
},
|
|
10
|
+
set(newValue) {
|
|
11
|
+
if (isEqual(value, newValue))
|
|
12
|
+
return;
|
|
13
|
+
value = newValue;
|
|
14
|
+
if (dependency)
|
|
15
|
+
dependency.notify();
|
|
32
16
|
}
|
|
33
|
-
}
|
|
34
|
-
return
|
|
17
|
+
};
|
|
18
|
+
return signal;
|
|
35
19
|
}
|
|
36
|
-
|
|
37
|
-
if (typeof structuredClone === "function")
|
|
38
|
-
return structuredClone(object);
|
|
39
|
-
/* istanbul ignore next -- @preserve */
|
|
40
|
-
return clone(object);
|
|
41
|
-
}
|
|
42
|
-
exports.clone = clone;
|
|
43
|
-
exports.default = deepClone;
|
|
20
|
+
module.exports = createSignal;
|
package/dist/index.cjs18.js
CHANGED
|
@@ -1,13 +1,264 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
4
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
6
|
+
const sortItems = require("./index.cjs21.js");
|
|
7
|
+
const project = require("./index.cjs22.js");
|
|
8
|
+
const Observer = require("./index.cjs23.js");
|
|
9
|
+
function isInReactiveScope(reactivity) {
|
|
10
|
+
if (!reactivity)
|
|
11
|
+
return false;
|
|
12
|
+
if (!reactivity.isInScope)
|
|
13
|
+
return true;
|
|
14
|
+
return reactivity.isInScope();
|
|
12
15
|
}
|
|
13
|
-
|
|
16
|
+
class Cursor {
|
|
17
|
+
/**
|
|
18
|
+
* Creates a new instance of the `Cursor` class.
|
|
19
|
+
* Provides utilities for querying, observing, and transforming items from a collection.
|
|
20
|
+
* @template T - The type of the items in the collection.
|
|
21
|
+
* @template U - The transformed item type after applying transformations (default is T).
|
|
22
|
+
* @param getItems - A function that retrieves the filtered list of items.
|
|
23
|
+
* @param options - Optional configuration for the cursor.
|
|
24
|
+
* @param options.transform - A transformation function to apply to each item when retrieving them.
|
|
25
|
+
* @param options.bindEvents - A function to bind reactivity events for the cursor, which should return a cleanup function.
|
|
26
|
+
* @param options.fields - A projection object defining which fields of the item should be included or excluded.
|
|
27
|
+
* @param options.sort - A sort specifier to determine the order of the items.
|
|
28
|
+
* @param options.skip - The number of items to skip from the beginning of the result set.
|
|
29
|
+
* @param options.limit - The maximum number of items to return in the result set.
|
|
30
|
+
* @param options.reactive - A reactivity adapter to enable observing changes in the cursor's result set.
|
|
31
|
+
* @param options.fieldTracking - A boolean to enable fine-grained field tracking for reactivity.
|
|
32
|
+
*/
|
|
33
|
+
constructor(getItems, options) {
|
|
34
|
+
__publicField(this, "observer");
|
|
35
|
+
__publicField(this, "getFilteredItems");
|
|
36
|
+
__publicField(this, "options");
|
|
37
|
+
__publicField(this, "onCleanupCallbacks", []);
|
|
38
|
+
this.getFilteredItems = getItems;
|
|
39
|
+
this.options = options || {};
|
|
40
|
+
}
|
|
41
|
+
addGetters(item) {
|
|
42
|
+
if (!isInReactiveScope(this.options.reactive))
|
|
43
|
+
return item;
|
|
44
|
+
const depend = this.depend.bind(this);
|
|
45
|
+
return Object.entries(item).reduce((memo, [key, value]) => {
|
|
46
|
+
Object.defineProperty(memo, key, {
|
|
47
|
+
get() {
|
|
48
|
+
depend({
|
|
49
|
+
changedField: (notify) => (changedItem, changedFieldName) => {
|
|
50
|
+
if (changedFieldName !== key || changedItem.id !== item.id)
|
|
51
|
+
return;
|
|
52
|
+
notify();
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
return value;
|
|
56
|
+
},
|
|
57
|
+
enumerable: true,
|
|
58
|
+
configurable: true
|
|
59
|
+
});
|
|
60
|
+
return memo;
|
|
61
|
+
}, {});
|
|
62
|
+
}
|
|
63
|
+
transform(rawItem) {
|
|
64
|
+
const item = this.options.fieldTracking ? this.addGetters(rawItem) : rawItem;
|
|
65
|
+
if (!this.options.transform)
|
|
66
|
+
return item;
|
|
67
|
+
return this.options.transform(item);
|
|
68
|
+
}
|
|
69
|
+
getItems() {
|
|
70
|
+
const items = this.getFilteredItems();
|
|
71
|
+
const { sort, skip, limit } = this.options;
|
|
72
|
+
const sorted = sort ? sortItems(items, sort) : items;
|
|
73
|
+
const skipped = skip ? sorted.slice(skip) : sorted;
|
|
74
|
+
const limited = limit ? skipped.slice(0, limit) : skipped;
|
|
75
|
+
const idExcluded = this.options.fields && this.options.fields.id === 0;
|
|
76
|
+
return limited.map((item) => {
|
|
77
|
+
if (!this.options.fields)
|
|
78
|
+
return item;
|
|
79
|
+
return {
|
|
80
|
+
...idExcluded ? {} : { id: item.id },
|
|
81
|
+
...project(item, this.options.fields)
|
|
82
|
+
};
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
depend(changeEvents) {
|
|
86
|
+
if (!this.options.reactive)
|
|
87
|
+
return;
|
|
88
|
+
if (!isInReactiveScope(this.options.reactive))
|
|
89
|
+
return;
|
|
90
|
+
const signal = this.options.reactive.create();
|
|
91
|
+
signal.depend();
|
|
92
|
+
const notify = () => signal.notify();
|
|
93
|
+
function buildNotifier(event) {
|
|
94
|
+
const eventHandler = changeEvents[event];
|
|
95
|
+
return (...args) => {
|
|
96
|
+
if (eventHandler === true) {
|
|
97
|
+
notify();
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
if (typeof eventHandler !== "function")
|
|
101
|
+
return;
|
|
102
|
+
eventHandler(notify)(...args);
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
const stop = this.observeRawChanges({
|
|
106
|
+
added: buildNotifier("added"),
|
|
107
|
+
addedBefore: buildNotifier("addedBefore"),
|
|
108
|
+
changed: buildNotifier("changed"),
|
|
109
|
+
changedField: buildNotifier("changedField"),
|
|
110
|
+
movedBefore: buildNotifier("movedBefore"),
|
|
111
|
+
removed: buildNotifier("removed")
|
|
112
|
+
}, true);
|
|
113
|
+
if (this.options.reactive.onDispose) {
|
|
114
|
+
this.options.reactive.onDispose(() => stop(), signal);
|
|
115
|
+
}
|
|
116
|
+
this.onCleanup(stop);
|
|
117
|
+
}
|
|
118
|
+
ensureObserver() {
|
|
119
|
+
if (!this.observer) {
|
|
120
|
+
const observer = new Observer(() => {
|
|
121
|
+
const requery = () => {
|
|
122
|
+
observer.runChecks(this.getItems());
|
|
123
|
+
};
|
|
124
|
+
const cleanup = this.options.bindEvents && this.options.bindEvents(requery);
|
|
125
|
+
return () => {
|
|
126
|
+
if (cleanup)
|
|
127
|
+
cleanup();
|
|
128
|
+
};
|
|
129
|
+
});
|
|
130
|
+
this.onCleanup(() => observer.stop());
|
|
131
|
+
this.observer = observer;
|
|
132
|
+
}
|
|
133
|
+
return this.observer;
|
|
134
|
+
}
|
|
135
|
+
observeRawChanges(callbacks, skipInitial = false) {
|
|
136
|
+
const observer = this.ensureObserver();
|
|
137
|
+
observer.addCallbacks(callbacks, skipInitial);
|
|
138
|
+
observer.runChecks(this.getItems());
|
|
139
|
+
return () => {
|
|
140
|
+
observer.removeCallbacks(callbacks);
|
|
141
|
+
if (!observer.isEmpty())
|
|
142
|
+
return;
|
|
143
|
+
observer.stop();
|
|
144
|
+
this.observer = void 0;
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Cleans up all resources associated with the cursor, such as reactive bindings
|
|
149
|
+
* and event listeners. This method should be called when the cursor is no longer needed
|
|
150
|
+
* to prevent memory leaks.
|
|
151
|
+
*/
|
|
152
|
+
cleanup() {
|
|
153
|
+
this.onCleanupCallbacks.forEach((callback) => {
|
|
154
|
+
callback();
|
|
155
|
+
});
|
|
156
|
+
this.onCleanupCallbacks = [];
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Registers a cleanup callback to be executed when the `cleanup` method is called.
|
|
160
|
+
* Useful for managing resources and ensuring proper cleanup of bindings or listeners.
|
|
161
|
+
* @param callback - A function to be executed during cleanup.
|
|
162
|
+
*/
|
|
163
|
+
onCleanup(callback) {
|
|
164
|
+
this.onCleanupCallbacks.push(callback);
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Iterates over each item in the cursor's result set, applying the provided callback
|
|
168
|
+
* function to each transformed item.
|
|
169
|
+
* ⚡️ this function is reactive!
|
|
170
|
+
* @param callback - A function to execute for each item in the result set.
|
|
171
|
+
* @param callback.item - The transformed item.
|
|
172
|
+
*/
|
|
173
|
+
forEach(callback) {
|
|
174
|
+
const items = this.getItems();
|
|
175
|
+
this.depend({
|
|
176
|
+
addedBefore: true,
|
|
177
|
+
removed: true,
|
|
178
|
+
movedBefore: true,
|
|
179
|
+
...this.options.fieldTracking ? {} : { changed: true }
|
|
180
|
+
});
|
|
181
|
+
items.forEach((item) => {
|
|
182
|
+
callback(this.transform(item));
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Creates a new array populated with the results of applying the provided callback
|
|
187
|
+
* function to each transformed item in the cursor's result set.
|
|
188
|
+
* ⚡️ this function is reactive!
|
|
189
|
+
* @template V - The type of the items in the resulting array.
|
|
190
|
+
* @param callback - A function to execute for each item in the result set.
|
|
191
|
+
* @param callback.item - The transformed item.
|
|
192
|
+
* @returns An array of results after applying the callback to each item.
|
|
193
|
+
*/
|
|
194
|
+
map(callback) {
|
|
195
|
+
const results = [];
|
|
196
|
+
this.forEach((item) => {
|
|
197
|
+
results.push(callback(item));
|
|
198
|
+
});
|
|
199
|
+
return results;
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Fetches all transformed items from the cursor's result set as an array.
|
|
203
|
+
* Automatically applies filtering, sorting, and limiting as per the cursor's options.
|
|
204
|
+
* ⚡️ this function is reactive!
|
|
205
|
+
* @returns An array of transformed items in the result set.
|
|
206
|
+
*/
|
|
207
|
+
fetch() {
|
|
208
|
+
return this.map((item) => item);
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Counts the total number of items in the cursor's result set after applying
|
|
212
|
+
* filtering and other criteria.
|
|
213
|
+
* ⚡️ this function is reactive!
|
|
214
|
+
* @returns The total number of items in the result set.
|
|
215
|
+
*/
|
|
216
|
+
count() {
|
|
217
|
+
const items = this.getItems();
|
|
218
|
+
this.depend({
|
|
219
|
+
added: true,
|
|
220
|
+
removed: true
|
|
221
|
+
});
|
|
222
|
+
return items.length;
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Observes changes to the cursor's result set and triggers the specified callbacks
|
|
226
|
+
* when items are added, removed, or updated. Supports reactivity and transformation.
|
|
227
|
+
* @param callbacks - An object containing the callback functions to handle different change events.
|
|
228
|
+
* @param callbacks.added - Triggered when an item is added to the result set.
|
|
229
|
+
* @param callbacks.removed - Triggered when an item is removed from the result set.
|
|
230
|
+
* @param callbacks.changed - Triggered when an item in the result set is modified.
|
|
231
|
+
* @param callbacks.addedBefore - Triggered when an item is added before another item in the result set.
|
|
232
|
+
* @param callbacks.movedBefore - Triggered when an item is moved before another item in the result set.
|
|
233
|
+
* @param callbacks.changedField - Triggered when a specific field of an item changes.
|
|
234
|
+
* @param skipInitial - A boolean indicating whether to skip the initial notification of the current result set.
|
|
235
|
+
* @returns A function to stop observing changes.
|
|
236
|
+
*/
|
|
237
|
+
observeChanges(callbacks, skipInitial = false) {
|
|
238
|
+
return this.observeRawChanges(Object.entries(callbacks).reduce((memo, [callbackName, callback]) => {
|
|
239
|
+
if (!callback)
|
|
240
|
+
return memo;
|
|
241
|
+
return {
|
|
242
|
+
...memo,
|
|
243
|
+
[callbackName]: (item, before) => {
|
|
244
|
+
const transformedValue = this.transform(item);
|
|
245
|
+
const hasBeforeParameter = before !== void 0;
|
|
246
|
+
const transformedBeforeValue = hasBeforeParameter && before ? this.transform(before) : null;
|
|
247
|
+
return callback(transformedValue, ...hasBeforeParameter ? [transformedBeforeValue] : []);
|
|
248
|
+
}
|
|
249
|
+
};
|
|
250
|
+
}, {}), skipInitial);
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Forces the cursor to re-evaluate its result set by re-fetching items
|
|
254
|
+
* from the collection. This is useful when the underlying data or query
|
|
255
|
+
* criteria have changed, and you want to ensure the cursor reflects the latest state.
|
|
256
|
+
*/
|
|
257
|
+
requery() {
|
|
258
|
+
if (!this.observer)
|
|
259
|
+
return;
|
|
260
|
+
this.observer.runChecks(this.getItems());
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
exports.default = Cursor;
|
|
264
|
+
exports.isInReactiveScope = isInReactiveScope;
|
package/dist/index.cjs19.js
CHANGED
|
@@ -1,20 +1,70 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
return
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
2
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
3
|
+
const intersection = require("./index.cjs24.js");
|
|
4
|
+
function getMergedIndexInfo(indexProviders, selector) {
|
|
5
|
+
return indexProviders.reduce((memo, indexProvider) => {
|
|
6
|
+
const info = indexProvider.query(selector);
|
|
7
|
+
if (!info.matched)
|
|
8
|
+
return memo;
|
|
9
|
+
const optimizedSelector = Object.fromEntries(Object.entries(memo.optimizedSelector).filter(([key]) => !info.fields.includes(key)));
|
|
10
|
+
return {
|
|
11
|
+
matched: true,
|
|
12
|
+
positions: [...new Set(memo.matched ? intersection(memo.positions, info.positions) : info.positions)],
|
|
13
|
+
optimizedSelector
|
|
14
|
+
};
|
|
15
|
+
}, {
|
|
16
|
+
matched: false,
|
|
17
|
+
positions: [],
|
|
18
|
+
optimizedSelector: { ...selector }
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
function getIndexInfo(indexProviders, selector) {
|
|
22
|
+
if (selector == null || Object.keys(selector).length <= 0) {
|
|
23
|
+
return { matched: false, positions: [], optimizedSelector: selector };
|
|
24
|
+
}
|
|
25
|
+
const { $and, $or, ...rest } = selector;
|
|
26
|
+
const flatInfo = getMergedIndexInfo(indexProviders, rest);
|
|
27
|
+
let { matched, positions } = flatInfo;
|
|
28
|
+
const newSelector = flatInfo.optimizedSelector;
|
|
29
|
+
if (Array.isArray($and)) {
|
|
30
|
+
const $andNew = [];
|
|
31
|
+
for (const sel of $and) {
|
|
32
|
+
const { matched: selMatched, positions: selPositions, optimizedSelector } = getIndexInfo(indexProviders, sel);
|
|
33
|
+
if (selMatched) {
|
|
34
|
+
positions = matched ? intersection(positions, selPositions) : selPositions;
|
|
35
|
+
matched = true;
|
|
36
|
+
if (Object.keys(optimizedSelector).length > 0) {
|
|
37
|
+
$andNew.push(optimizedSelector);
|
|
38
|
+
}
|
|
39
|
+
} else {
|
|
40
|
+
$andNew.push(sel);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
if ($andNew.length > 0)
|
|
44
|
+
newSelector.$and = $andNew;
|
|
45
|
+
}
|
|
46
|
+
if (Array.isArray($or)) {
|
|
47
|
+
const $orNew = [];
|
|
48
|
+
for (const sel of $or) {
|
|
49
|
+
const { matched: selMatched, positions: selPositions, optimizedSelector } = getIndexInfo(indexProviders, sel);
|
|
50
|
+
if (selMatched) {
|
|
51
|
+
positions = [.../* @__PURE__ */ new Set([...positions, ...selPositions])];
|
|
52
|
+
matched = true;
|
|
53
|
+
if (Object.keys(optimizedSelector).length > 0) {
|
|
54
|
+
$orNew.push(optimizedSelector);
|
|
55
|
+
}
|
|
56
|
+
} else {
|
|
57
|
+
$orNew.push(sel);
|
|
58
|
+
}
|
|
16
59
|
}
|
|
60
|
+
if ($orNew.length > 0)
|
|
61
|
+
newSelector.$or = $orNew;
|
|
62
|
+
}
|
|
63
|
+
return {
|
|
64
|
+
matched,
|
|
65
|
+
positions: positions || [],
|
|
66
|
+
optimizedSelector: newSelector
|
|
17
67
|
};
|
|
18
|
-
return signal;
|
|
19
68
|
}
|
|
20
|
-
|
|
69
|
+
exports.default = getIndexInfo;
|
|
70
|
+
exports.getMergedIndexInfo = getMergedIndexInfo;
|