@signaldb/core 1.7.1 → 2.0.0-beta.0
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 +125 -82
- package/dist/AsyncDataAdapter.d.ts +64 -0
- package/dist/AutoFetchDataAdapter.d.ts +113 -0
- package/dist/Collection/Cursor.d.ts +9 -9
- package/dist/Collection/Observer.d.ts +3 -2
- package/dist/Collection/index.d.ts +52 -46
- package/dist/Collection/types.d.ts +4 -9
- package/dist/DataAdapter.d.ts +33 -0
- package/dist/DefaultDataAdapter.d.ts +32 -0
- package/dist/WorkerDataAdapter.d.ts +22 -0
- package/dist/WorkerDataAdapterHost.d.ts +59 -0
- package/dist/createIndex.d.ts +7 -0
- package/dist/createStorageAdapter.d.ts +9 -0
- package/dist/{Collection/getIndexInfo.d.ts → getIndexInfo.d.ts} +17 -19
- package/dist/index.cjs.js +21 -17
- package/dist/index.cjs10.js +15 -26
- package/dist/index.cjs11.js +13 -10
- package/dist/index.cjs12.js +337 -3
- package/dist/index.cjs13.js +384 -110
- package/dist/index.cjs14.js +183 -67
- package/dist/index.cjs15.js +339 -8
- package/dist/index.cjs16.js +563 -20
- package/dist/index.cjs17.js +12 -4
- package/dist/index.cjs18.js +24 -5
- package/dist/index.cjs2.js +24 -30
- package/dist/index.cjs20.js +102 -13
- package/dist/index.cjs21.js +124 -21
- package/dist/index.cjs22.js +5 -77
- package/dist/index.cjs23.js +22 -79
- package/dist/index.cjs24.js +5 -16
- package/dist/index.cjs25.js +8 -27
- package/dist/index.cjs26.js +27 -7
- package/dist/index.cjs27.js +3 -5
- package/dist/index.cjs28.js +5 -27
- package/dist/index.cjs29.js +27 -40
- package/dist/index.cjs3.js +191 -441
- package/dist/index.cjs30.js +42 -0
- package/dist/index.cjs31.js +9 -0
- package/dist/index.cjs4.js +3 -165
- package/dist/index.cjs5.js +3 -66
- package/dist/index.cjs6.js +27 -3
- package/dist/index.cjs7.js +10 -3
- package/dist/index.cjs8.js +3 -3
- package/dist/index.cjs9.js +131 -3
- package/dist/index.d.ts +10 -8
- package/dist/index.mjs +15 -11
- package/dist/index10.mjs +15 -26
- package/dist/index11.mjs +13 -10
- package/dist/index12.mjs +337 -3
- package/dist/index13.mjs +384 -110
- package/dist/index14.mjs +183 -66
- package/dist/index15.mjs +339 -8
- package/dist/index16.mjs +563 -20
- package/dist/index17.mjs +12 -4
- package/dist/index18.mjs +24 -5
- package/dist/index2.mjs +24 -30
- package/dist/index20.mjs +102 -13
- package/dist/index21.mjs +123 -21
- package/dist/index22.mjs +5 -76
- package/dist/index23.mjs +22 -78
- package/dist/index24.mjs +5 -16
- package/dist/index25.mjs +8 -27
- package/dist/index26.mjs +27 -7
- package/dist/index27.mjs +3 -5
- package/dist/index28.mjs +5 -27
- package/dist/index29.mjs +27 -40
- package/dist/index3.mjs +191 -442
- package/dist/index30.mjs +43 -0
- package/dist/index31.mjs +10 -0
- package/dist/index4.mjs +3 -165
- package/dist/index5.mjs +3 -65
- package/dist/index6.mjs +27 -3
- package/dist/index7.mjs +10 -3
- package/dist/index8.mjs +3 -3
- package/dist/index9.mjs +131 -3
- package/dist/types/IndexProvider.d.ts +12 -7
- package/dist/types/StorageAdapter.d.ts +20 -0
- package/dist/utils/objectId.d.ts +8 -0
- package/dist/utils/queryId.d.ts +9 -0
- package/package.json +1 -1
- package/dist/AutoFetchCollection.d.ts +0 -60
- package/dist/Collection/createIndex.d.ts +0 -15
- package/dist/ReplicatedCollection.d.ts +0 -60
- package/dist/createMemoryAdapter.d.ts +0 -7
- package/dist/persistence/combinePersistenceAdapters.d.ts +0 -32
- package/dist/persistence/createPersistenceAdapter.d.ts +0 -9
- package/dist/types/MemoryAdapter.d.ts +0 -15
- package/dist/types/PersistenceAdapter.d.ts +0 -20
package/dist/index.cjs2.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
3
|
-
const sortItems = require("./index.cjs15.js");
|
|
4
|
-
const project = require("./index.cjs16.js");
|
|
5
3
|
const Observer = require("./index.cjs17.js");
|
|
6
4
|
function isInReactiveScope(reactivity) {
|
|
7
5
|
if (!reactivity)
|
|
@@ -12,7 +10,7 @@ function isInReactiveScope(reactivity) {
|
|
|
12
10
|
}
|
|
13
11
|
class Cursor {
|
|
14
12
|
observer;
|
|
15
|
-
|
|
13
|
+
getItems;
|
|
16
14
|
options;
|
|
17
15
|
onCleanupCallbacks = [];
|
|
18
16
|
/**
|
|
@@ -32,7 +30,7 @@ class Cursor {
|
|
|
32
30
|
* @param options.fieldTracking - A boolean to enable fine-grained field tracking for reactivity.
|
|
33
31
|
*/
|
|
34
32
|
constructor(getItems, options) {
|
|
35
|
-
this.
|
|
33
|
+
this.getItems = getItems;
|
|
36
34
|
this.options = options || {};
|
|
37
35
|
}
|
|
38
36
|
addGetters(item) {
|
|
@@ -63,22 +61,6 @@ class Cursor {
|
|
|
63
61
|
return item;
|
|
64
62
|
return this.options.transform(item);
|
|
65
63
|
}
|
|
66
|
-
getItems() {
|
|
67
|
-
const items = this.getFilteredItems();
|
|
68
|
-
const { sort, skip, limit } = this.options;
|
|
69
|
-
const sorted = sort ? sortItems(items, sort) : items;
|
|
70
|
-
const skipped = skip ? sorted.slice(skip) : sorted;
|
|
71
|
-
const limited = limit ? skipped.slice(0, limit) : skipped;
|
|
72
|
-
const idExcluded = this.options.fields && this.options.fields.id === 0;
|
|
73
|
-
return limited.map((item) => {
|
|
74
|
-
if (!this.options.fields)
|
|
75
|
-
return item;
|
|
76
|
-
return {
|
|
77
|
-
...idExcluded ? {} : { id: item.id },
|
|
78
|
-
...project(item, this.options.fields)
|
|
79
|
-
};
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
64
|
depend(changeEvents) {
|
|
83
65
|
if (!this.options.reactive)
|
|
84
66
|
return;
|
|
@@ -116,7 +98,7 @@ class Cursor {
|
|
|
116
98
|
if (!this.observer) {
|
|
117
99
|
const observer = new Observer(() => {
|
|
118
100
|
const requery = () => {
|
|
119
|
-
observer.runChecks(this.getItems
|
|
101
|
+
observer.runChecks(this.getItems);
|
|
120
102
|
};
|
|
121
103
|
const cleanup = this.options.bindEvents && this.options.bindEvents(requery);
|
|
122
104
|
return () => {
|
|
@@ -132,7 +114,7 @@ class Cursor {
|
|
|
132
114
|
observeRawChanges(callbacks, skipInitial = false) {
|
|
133
115
|
const observer = this.ensureObserver();
|
|
134
116
|
observer.addCallbacks(callbacks, skipInitial);
|
|
135
|
-
observer.runChecks(this.getItems
|
|
117
|
+
observer.runChecks(this.getItems);
|
|
136
118
|
return () => {
|
|
137
119
|
observer.removeCallbacks(callbacks);
|
|
138
120
|
if (!observer.isEmpty())
|
|
@@ -166,18 +148,27 @@ class Cursor {
|
|
|
166
148
|
* ⚡️ this function is reactive!
|
|
167
149
|
* @param callback - A function to execute for each item in the result set.
|
|
168
150
|
* @param callback.item - The transformed item.
|
|
151
|
+
* @returns A promise that resolves when all items have been processed, or void if not in async mode.
|
|
169
152
|
*/
|
|
170
153
|
forEach(callback) {
|
|
171
|
-
const items = this.getItems();
|
|
172
154
|
this.depend({
|
|
173
155
|
addedBefore: true,
|
|
174
156
|
removed: true,
|
|
175
157
|
movedBefore: true,
|
|
176
158
|
...this.options.fieldTracking ? {} : { changed: true }
|
|
177
159
|
});
|
|
178
|
-
items
|
|
179
|
-
|
|
180
|
-
|
|
160
|
+
const executeForEach = (items) => {
|
|
161
|
+
items.forEach((item) => {
|
|
162
|
+
callback(this.transform(item));
|
|
163
|
+
});
|
|
164
|
+
};
|
|
165
|
+
const result = this.getItems();
|
|
166
|
+
if (result instanceof Promise) {
|
|
167
|
+
return result.then(executeForEach);
|
|
168
|
+
} else {
|
|
169
|
+
executeForEach(result);
|
|
170
|
+
return void 0;
|
|
171
|
+
}
|
|
181
172
|
}
|
|
182
173
|
/**
|
|
183
174
|
* Creates a new array populated with the results of applying the provided callback
|
|
@@ -190,9 +181,12 @@ class Cursor {
|
|
|
190
181
|
*/
|
|
191
182
|
map(callback) {
|
|
192
183
|
const results = [];
|
|
193
|
-
this.forEach((item) => {
|
|
184
|
+
const maybePromise = this.forEach((item) => {
|
|
194
185
|
results.push(callback(item));
|
|
195
186
|
});
|
|
187
|
+
if (maybePromise instanceof Promise) {
|
|
188
|
+
return maybePromise.then(() => results);
|
|
189
|
+
}
|
|
196
190
|
return results;
|
|
197
191
|
}
|
|
198
192
|
/**
|
|
@@ -211,12 +205,12 @@ class Cursor {
|
|
|
211
205
|
* @returns The total number of items in the result set.
|
|
212
206
|
*/
|
|
213
207
|
count() {
|
|
214
|
-
const items = this.getItems();
|
|
215
208
|
this.depend({
|
|
216
209
|
added: true,
|
|
217
210
|
removed: true
|
|
218
211
|
});
|
|
219
|
-
|
|
212
|
+
const maybePromise = this.getItems();
|
|
213
|
+
return maybePromise instanceof Promise ? maybePromise.then((items) => items.length) : maybePromise.length;
|
|
220
214
|
}
|
|
221
215
|
/**
|
|
222
216
|
* Observes changes to the cursor's result set and triggers the specified callbacks
|
|
@@ -254,7 +248,7 @@ class Cursor {
|
|
|
254
248
|
requery() {
|
|
255
249
|
if (!this.observer)
|
|
256
250
|
return;
|
|
257
|
-
this.observer.runChecks(this.getItems
|
|
251
|
+
this.observer.runChecks(this.getItems);
|
|
258
252
|
}
|
|
259
253
|
}
|
|
260
254
|
exports.default = Cursor;
|
package/dist/index.cjs20.js
CHANGED
|
@@ -1,15 +1,104 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
2
|
+
const createIndexProvider = require("./index.cjs27.js");
|
|
3
|
+
const get = require("./index.cjs10.js");
|
|
4
|
+
const getMatchingKeys = require("./index.cjs26.js");
|
|
5
|
+
const serializeValue = require("./index.cjs11.js");
|
|
6
|
+
function createIndex(field) {
|
|
7
|
+
const index = /* @__PURE__ */ new Map();
|
|
8
|
+
const ensureSet = (key) => {
|
|
9
|
+
let set = index.get(key);
|
|
10
|
+
if (!set) {
|
|
11
|
+
set = /* @__PURE__ */ new Set();
|
|
12
|
+
index.set(key, set);
|
|
13
|
+
}
|
|
14
|
+
return set;
|
|
15
|
+
};
|
|
16
|
+
return createIndexProvider({
|
|
17
|
+
query(selector) {
|
|
18
|
+
if (!Object.hasOwnProperty.call(selector, field)) {
|
|
19
|
+
return { matched: false };
|
|
20
|
+
}
|
|
21
|
+
const fieldSelector = selector[field];
|
|
22
|
+
const filteresForNull = fieldSelector == null || fieldSelector.$exists === false;
|
|
23
|
+
const keys = filteresForNull ? { include: null, exclude: [...index.keys()].filter((key) => key != null) } : getMatchingKeys(field, selector);
|
|
24
|
+
if (keys.include == null && keys.exclude == null)
|
|
25
|
+
return { matched: false };
|
|
26
|
+
let includedIds = [];
|
|
27
|
+
if (keys.include == null) {
|
|
28
|
+
for (const set of index.values()) {
|
|
29
|
+
for (const pos of set) {
|
|
30
|
+
includedIds.push(pos);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
} else {
|
|
34
|
+
for (const key of keys.include) {
|
|
35
|
+
const posSet = index.get(key);
|
|
36
|
+
if (posSet) {
|
|
37
|
+
for (const pos of posSet) {
|
|
38
|
+
includedIds.push(pos);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
if (keys.exclude != null) {
|
|
44
|
+
const excludeIds = /* @__PURE__ */ new Set();
|
|
45
|
+
for (const key of keys.exclude) {
|
|
46
|
+
const posSet = index.get(key);
|
|
47
|
+
if (posSet) {
|
|
48
|
+
for (const pos of posSet) {
|
|
49
|
+
excludeIds.add(pos);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
includedIds = includedIds.filter((pos) => !excludeIds.has(pos));
|
|
54
|
+
}
|
|
55
|
+
return {
|
|
56
|
+
matched: true,
|
|
57
|
+
ids: includedIds,
|
|
58
|
+
fields: [field],
|
|
59
|
+
keepSelector: filteresForNull
|
|
60
|
+
};
|
|
61
|
+
},
|
|
62
|
+
rebuild(items) {
|
|
63
|
+
index.clear();
|
|
64
|
+
items.forEach((item) => {
|
|
65
|
+
const value = serializeValue(get(item, field));
|
|
66
|
+
ensureSet(value).add(item.id);
|
|
67
|
+
});
|
|
68
|
+
},
|
|
69
|
+
// NEW: delta methods
|
|
70
|
+
insert(items) {
|
|
71
|
+
for (const item of items) {
|
|
72
|
+
const value = serializeValue(get(item, field));
|
|
73
|
+
ensureSet(value).add(item.id);
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
remove(items) {
|
|
77
|
+
for (const item of items) {
|
|
78
|
+
const value = serializeValue(get(item, field));
|
|
79
|
+
const set = index.get(value);
|
|
80
|
+
if (!set)
|
|
81
|
+
continue;
|
|
82
|
+
set.delete(item.id);
|
|
83
|
+
if (set.size === 0)
|
|
84
|
+
index.delete(value);
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
update(pairs) {
|
|
88
|
+
for (const { oldItem, newItem } of pairs) {
|
|
89
|
+
const oldValue = serializeValue(get(oldItem, field));
|
|
90
|
+
const newValue = serializeValue(get(newItem, field));
|
|
91
|
+
if (oldValue === newValue)
|
|
92
|
+
continue;
|
|
93
|
+
const oldSet = index.get(oldValue);
|
|
94
|
+
if (oldSet) {
|
|
95
|
+
oldSet.delete(oldItem.id);
|
|
96
|
+
if (oldSet.size === 0)
|
|
97
|
+
index.delete(oldValue);
|
|
98
|
+
}
|
|
99
|
+
ensureSet(newValue).add(newItem.id);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
});
|
|
14
103
|
}
|
|
15
|
-
module.exports =
|
|
104
|
+
module.exports = createIndex;
|
package/dist/index.cjs21.js
CHANGED
|
@@ -1,26 +1,129 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
2
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
3
|
+
const intersection = require("./index.cjs28.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
|
+
});
|
|
32
|
+
}
|
|
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)
|
|
18
81
|
return;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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));
|
|
22
120
|
}
|
|
121
|
+
return process$and($andNewOrPromise);
|
|
23
122
|
};
|
|
24
|
-
|
|
123
|
+
if (flatInfoOrPromise instanceof Promise) {
|
|
124
|
+
return flatInfoOrPromise.then(processFlatInfo);
|
|
125
|
+
}
|
|
126
|
+
return processFlatInfo(flatInfoOrPromise);
|
|
25
127
|
}
|
|
26
|
-
|
|
128
|
+
exports.default = getIndexInfo;
|
|
129
|
+
exports.getMergedIndexInfo = getMergedIndexInfo;
|
package/dist/index.cjs22.js
CHANGED
|
@@ -1,79 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
return
|
|
6
|
-
const info = indexProvider.query(selector);
|
|
7
|
-
if (!info.matched)
|
|
8
|
-
return memo;
|
|
9
|
-
const optimizedSelector = info.keepSelector ? memo.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
|
-
});
|
|
2
|
+
const mingo = require("mingo");
|
|
3
|
+
function match(item, selector) {
|
|
4
|
+
const query = new mingo.Query(selector);
|
|
5
|
+
return query.test(item);
|
|
20
6
|
}
|
|
21
|
-
|
|
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
|
-
const matchedBefore = matched;
|
|
49
|
-
const positionsBefore = positions;
|
|
50
|
-
let hasNonIndexField = false;
|
|
51
|
-
for (const sel of $or) {
|
|
52
|
-
const { matched: selMatched, positions: selPositions, optimizedSelector } = getIndexInfo(indexProviders, sel);
|
|
53
|
-
if (selMatched) {
|
|
54
|
-
positions = [.../* @__PURE__ */ new Set([...positions, ...selPositions])];
|
|
55
|
-
matched = true;
|
|
56
|
-
if (Object.keys(optimizedSelector).length > 0) {
|
|
57
|
-
$orNew.push(optimizedSelector);
|
|
58
|
-
}
|
|
59
|
-
} else {
|
|
60
|
-
$orNew.push(sel);
|
|
61
|
-
hasNonIndexField = true;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
if ($orNew.length > 0)
|
|
65
|
-
newSelector.$or = $orNew;
|
|
66
|
-
if (hasNonIndexField) {
|
|
67
|
-
newSelector.$or = $or;
|
|
68
|
-
matched = matchedBefore;
|
|
69
|
-
positions = positionsBefore;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
return {
|
|
73
|
-
matched,
|
|
74
|
-
positions: positions || [],
|
|
75
|
-
optimizedSelector: newSelector
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
exports.default = getIndexInfo;
|
|
79
|
-
exports.getMergedIndexInfo = getMergedIndexInfo;
|
|
7
|
+
module.exports = match;
|
package/dist/index.cjs23.js
CHANGED
|
@@ -1,84 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
if (
|
|
2
|
+
const get = require("./index.cjs10.js");
|
|
3
|
+
const set = require("./index.cjs29.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
11
|
return;
|
|
12
|
-
|
|
13
|
-
},
|
|
14
|
-
load: () => options.pull(),
|
|
15
|
-
save: (items, changes) => {
|
|
16
|
-
if (!options.push)
|
|
17
|
-
throw new Error("Pushing is not configured for this collection. Try to pass a `push` function to the collection options.");
|
|
18
|
-
return options.push(changes, items);
|
|
19
|
-
}
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
class ReplicatedCollection extends index.default {
|
|
23
|
-
isPullingRemoteSignal;
|
|
24
|
-
isPushingRemoteSignal;
|
|
25
|
-
/**
|
|
26
|
-
* Creates a new instance of the `ReplicatedCollection` class.
|
|
27
|
-
* Sets up the replication adapter, combining it with an optional persistence adapter, and
|
|
28
|
-
* initializes signals for tracking remote pull and push operations.
|
|
29
|
-
* @param options - The configuration options for the replicated collection.
|
|
30
|
-
* @param options.pull - A function to fetch data from the remote source.
|
|
31
|
-
* @param options.push - An optional function to send changes and items to the remote source.
|
|
32
|
-
* @param options.registerRemoteChange - An optional function to register a listener for remote changes.
|
|
33
|
-
* @param options.persistence - An optional persistence adapter to combine with replication.
|
|
34
|
-
* @param options.reactivity - A reactivity adapter for observing changes in the collection.
|
|
35
|
-
* @param options.transform - A transformation function to apply to items when retrieving them.
|
|
36
|
-
* @param options.indices - An array of index providers for optimized querying.
|
|
37
|
-
* @param options.enableDebugMode - A boolean to enable or disable debug mode.
|
|
38
|
-
*/
|
|
39
|
-
constructor(options) {
|
|
40
|
-
const replicationAdapter = createReplicationAdapter({
|
|
41
|
-
registerRemoteChange: options.registerRemoteChange,
|
|
42
|
-
pull: async () => {
|
|
43
|
-
this.isPullingRemoteSignal.set(true);
|
|
44
|
-
try {
|
|
45
|
-
return await options.pull();
|
|
46
|
-
} finally {
|
|
47
|
-
this.isPullingRemoteSignal.set(false);
|
|
48
|
-
}
|
|
49
|
-
},
|
|
50
|
-
push: options.push ? async (changes, items) => {
|
|
51
|
-
if (!options.push)
|
|
52
|
-
throw new Error("Pushing is not configured for this collection. Try to pass a `push` function to the collection options.");
|
|
53
|
-
this.isPushingRemoteSignal.set(true);
|
|
54
|
-
try {
|
|
55
|
-
await options.push(changes, items);
|
|
56
|
-
} finally {
|
|
57
|
-
this.isPushingRemoteSignal.set(false);
|
|
58
|
-
}
|
|
59
|
-
} : void 0
|
|
60
|
-
});
|
|
61
|
-
const persistenceAdapter = options?.persistence ? combinePersistenceAdapters.default(replicationAdapter, options.persistence) : replicationAdapter;
|
|
62
|
-
super({
|
|
63
|
-
...options,
|
|
64
|
-
persistence: persistenceAdapter
|
|
12
|
+
set(result2, key, void 0, true);
|
|
65
13
|
});
|
|
66
|
-
|
|
67
|
-
this.isPushingRemoteSignal = createSignal(options.reactivity, false);
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Checks whether the collection is currently performing any loading operation,
|
|
71
|
-
* including pulling or pushing data from/to the remote source, or standard
|
|
72
|
-
* persistence adapter operations.
|
|
73
|
-
* ⚡️ this function is reactive!
|
|
74
|
-
* @returns A boolean indicating if the collection is currently loading or synchronizing.
|
|
75
|
-
*/
|
|
76
|
-
isLoading() {
|
|
77
|
-
const isPullingRemote = this.isPullingRemoteSignal.get();
|
|
78
|
-
const isPushingRemote = this.isPushingRemoteSignal.get();
|
|
79
|
-
const isLoading = super.isLoading();
|
|
80
|
-
return isPullingRemote || isPushingRemote || isLoading;
|
|
14
|
+
return result2;
|
|
81
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;
|
|
82
26
|
}
|
|
83
|
-
exports
|
|
84
|
-
exports.default = ReplicatedCollection;
|
|
27
|
+
module.exports = project;
|
package/dist/index.cjs24.js
CHANGED
|
@@ -1,18 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
function
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
7
|
-
const segments = normalized.split(".");
|
|
8
|
-
let current = value;
|
|
9
|
-
for (const key of segments) {
|
|
10
|
-
if (current == null)
|
|
11
|
-
return;
|
|
12
|
-
current = current[key];
|
|
13
|
-
}
|
|
14
|
-
if (current === void 0)
|
|
15
|
-
return;
|
|
16
|
-
return current;
|
|
2
|
+
function queryId(selector, options) {
|
|
3
|
+
const selectorId = JSON.stringify(selector);
|
|
4
|
+
const optionsId = options == null ? -1 : JSON.stringify(options);
|
|
5
|
+
return `${selectorId}:${optionsId}`;
|
|
17
6
|
}
|
|
18
|
-
module.exports =
|
|
7
|
+
module.exports = queryId;
|
package/dist/index.cjs25.js
CHANGED
|
@@ -1,29 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
segments.pop();
|
|
10
|
-
const apply = (node) => {
|
|
11
|
-
if (segments.length > 1) {
|
|
12
|
-
const key = segments.shift();
|
|
13
|
-
const nextIsNumber = !Number.isNaN(Number.parseInt(segments[0], 10));
|
|
14
|
-
if (node[key] === void 0) {
|
|
15
|
-
node[key] = nextIsNumber ? [] : {};
|
|
16
|
-
}
|
|
17
|
-
apply(node[key]);
|
|
18
|
-
} else {
|
|
19
|
-
if (deleteIfUndefined && value === void 0) {
|
|
20
|
-
delete node[segments[0]];
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
node[segments[0]] = value;
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
apply(object);
|
|
27
|
-
return object;
|
|
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;
|