@signaldb/core 1.5.4 → 1.6.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 +29 -28
- package/dist/Collection/createIndex.d.ts +1 -1
- package/dist/Collection/index.d.ts +1 -0
- package/dist/index.cjs.js +14 -12
- package/dist/index.cjs10.js +27 -10
- package/dist/index.cjs11.js +10 -3
- package/dist/index.cjs12.js +3 -136
- package/dist/index.cjs13.js +131 -61
- package/dist/index.cjs14.js +72 -5
- package/dist/index.cjs15.js +8 -41
- package/dist/index.cjs16.js +25 -11
- package/dist/index.cjs17.js +143 -23
- package/dist/index.cjs18.js +5 -262
- package/dist/index.cjs19.js +36 -63
- package/dist/index.cjs2.js +210 -732
- package/dist/index.cjs20.js +13 -85
- package/dist/index.cjs21.js +24 -8
- package/dist/index.cjs22.js +67 -24
- package/dist/index.cjs23.js +72 -131
- package/dist/index.cjs24.js +16 -5
- package/dist/index.cjs25.js +22 -11
- package/dist/index.cjs26.js +7 -27
- package/dist/index.cjs27.js +5 -40
- package/dist/index.cjs28.js +26 -26
- package/dist/index.cjs29.js +40 -7
- package/dist/index.cjs3.js +757 -136
- package/dist/index.cjs4.js +165 -62
- package/dist/index.cjs5.js +67 -3
- 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 +3 -27
- package/dist/index.d.ts +1 -0
- package/dist/index.mjs +14 -12
- package/dist/index10.mjs +27 -10
- package/dist/index11.mjs +10 -3
- package/dist/index12.mjs +3 -136
- package/dist/index13.mjs +131 -60
- package/dist/index14.mjs +71 -5
- package/dist/index15.mjs +8 -40
- package/dist/index16.mjs +25 -11
- package/dist/index17.mjs +143 -23
- package/dist/index18.mjs +5 -261
- package/dist/index19.mjs +36 -63
- package/dist/index2.mjs +210 -733
- package/dist/index20.mjs +13 -84
- package/dist/index21.mjs +24 -8
- package/dist/index22.mjs +66 -24
- package/dist/index23.mjs +71 -131
- package/dist/index24.mjs +16 -5
- package/dist/index25.mjs +22 -11
- package/dist/index26.mjs +7 -27
- package/dist/index27.mjs +5 -40
- package/dist/index28.mjs +26 -26
- package/dist/index29.mjs +40 -7
- package/dist/index3.mjs +757 -136
- package/dist/index4.mjs +165 -61
- package/dist/index5.mjs +66 -3
- package/dist/index6.mjs +2 -2
- package/dist/index7.mjs +2 -2
- package/dist/index8.mjs +2 -2
- package/dist/index9.mjs +3 -27
- package/dist/types/IndexProvider.d.ts +2 -0
- package/dist/utils/getMatchingKeys.d.ts +2 -2
- package/dist/utils/serializeValue.d.ts +1 -1
- package/package.json +1 -1
package/dist/index.cjs20.js
CHANGED
|
@@ -1,87 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
return;
|
|
15
|
-
await options.registerRemoteChange(onChange);
|
|
16
|
-
},
|
|
17
|
-
load: () => options.pull(),
|
|
18
|
-
save: (items, changes) => {
|
|
19
|
-
if (!options.push)
|
|
20
|
-
throw new Error("Pushing is not configured for this collection. Try to pass a `push` function to the collection options.");
|
|
21
|
-
return options.push(changes, items);
|
|
22
|
-
}
|
|
23
|
-
});
|
|
2
|
+
function serializeValue(value) {
|
|
3
|
+
if (value == null)
|
|
4
|
+
return null;
|
|
5
|
+
if (typeof value === "string")
|
|
6
|
+
return value;
|
|
7
|
+
if (typeof value === "number")
|
|
8
|
+
return value.toString();
|
|
9
|
+
if (typeof value === "boolean")
|
|
10
|
+
return value.toString();
|
|
11
|
+
if (value instanceof Date)
|
|
12
|
+
return value.toISOString();
|
|
13
|
+
return JSON.stringify(value);
|
|
24
14
|
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Creates a new instance of the `ReplicatedCollection` class.
|
|
28
|
-
* Sets up the replication adapter, combining it with an optional persistence adapter, and
|
|
29
|
-
* initializes signals for tracking remote pull and push operations.
|
|
30
|
-
* @param options - The configuration options for the replicated collection.
|
|
31
|
-
* @param options.pull - A function to fetch data from the remote source.
|
|
32
|
-
* @param options.push - An optional function to send changes and items to the remote source.
|
|
33
|
-
* @param options.registerRemoteChange - An optional function to register a listener for remote changes.
|
|
34
|
-
* @param options.persistence - An optional persistence adapter to combine with replication.
|
|
35
|
-
* @param options.reactivity - A reactivity adapter for observing changes in the collection.
|
|
36
|
-
* @param options.transform - A transformation function to apply to items when retrieving them.
|
|
37
|
-
* @param options.indices - An array of index providers for optimized querying.
|
|
38
|
-
* @param options.enableDebugMode - A boolean to enable or disable debug mode.
|
|
39
|
-
*/
|
|
40
|
-
constructor(options) {
|
|
41
|
-
const replicationAdapter = createReplicationAdapter({
|
|
42
|
-
registerRemoteChange: options.registerRemoteChange,
|
|
43
|
-
pull: async () => {
|
|
44
|
-
this.isPullingRemoteSignal.set(true);
|
|
45
|
-
try {
|
|
46
|
-
return await options.pull();
|
|
47
|
-
} finally {
|
|
48
|
-
this.isPullingRemoteSignal.set(false);
|
|
49
|
-
}
|
|
50
|
-
},
|
|
51
|
-
push: options.push ? async (changes, items) => {
|
|
52
|
-
if (!options.push)
|
|
53
|
-
throw new Error("Pushing is not configured for this collection. Try to pass a `push` function to the collection options.");
|
|
54
|
-
this.isPushingRemoteSignal.set(true);
|
|
55
|
-
try {
|
|
56
|
-
await options.push(changes, items);
|
|
57
|
-
} finally {
|
|
58
|
-
this.isPushingRemoteSignal.set(false);
|
|
59
|
-
}
|
|
60
|
-
} : void 0
|
|
61
|
-
});
|
|
62
|
-
const persistenceAdapter = (options == null ? void 0 : options.persistence) ? combinePersistenceAdapters.default(replicationAdapter, options.persistence) : replicationAdapter;
|
|
63
|
-
super({
|
|
64
|
-
...options,
|
|
65
|
-
persistence: persistenceAdapter
|
|
66
|
-
});
|
|
67
|
-
__publicField(this, "isPullingRemoteSignal");
|
|
68
|
-
__publicField(this, "isPushingRemoteSignal");
|
|
69
|
-
this.isPullingRemoteSignal = createSignal(options.reactivity, false);
|
|
70
|
-
this.isPushingRemoteSignal = createSignal(options.reactivity, false);
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* Checks whether the collection is currently performing any loading operation,
|
|
74
|
-
* including pulling or pushing data from/to the remote source, or standard
|
|
75
|
-
* persistence adapter operations.
|
|
76
|
-
* ⚡️ this function is reactive!
|
|
77
|
-
* @returns A boolean indicating if the collection is currently loading or synchronizing.
|
|
78
|
-
*/
|
|
79
|
-
isLoading() {
|
|
80
|
-
const isPullingRemote = this.isPullingRemoteSignal.get();
|
|
81
|
-
const isPushingRemote = this.isPushingRemoteSignal.get();
|
|
82
|
-
const isLoading = super.isLoading();
|
|
83
|
-
return isPullingRemote || isPushingRemote || isLoading;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
exports.createReplicationAdapter = createReplicationAdapter;
|
|
87
|
-
exports.default = ReplicatedCollection;
|
|
15
|
+
module.exports = serializeValue;
|
package/dist/index.cjs21.js
CHANGED
|
@@ -1,10 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
function createSignal(reactivityAdapter, initialValue, isEqual = Object.is) {
|
|
3
|
+
let value = initialValue;
|
|
4
|
+
const dependency = reactivityAdapter == null ? void 0 : reactivityAdapter.create();
|
|
5
|
+
const isInReactiveScope = () => {
|
|
6
|
+
if (!(reactivityAdapter == null ? void 0 : reactivityAdapter.isInScope))
|
|
7
|
+
return true;
|
|
8
|
+
return reactivityAdapter.isInScope();
|
|
9
|
+
};
|
|
10
|
+
const signal = {
|
|
11
|
+
get() {
|
|
12
|
+
if (dependency && isInReactiveScope())
|
|
13
|
+
dependency.depend();
|
|
14
|
+
return value;
|
|
15
|
+
},
|
|
16
|
+
set(newValue) {
|
|
17
|
+
if (isEqual(value, newValue))
|
|
18
|
+
return;
|
|
19
|
+
value = newValue;
|
|
20
|
+
if (dependency)
|
|
21
|
+
dependency.notify();
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
return signal;
|
|
9
25
|
}
|
|
10
|
-
module.exports =
|
|
26
|
+
module.exports = createSignal;
|
package/dist/index.cjs22.js
CHANGED
|
@@ -1,27 +1,70 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
const
|
|
4
|
-
function
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
if (fieldValue === void 0)
|
|
20
|
-
return;
|
|
21
|
-
if (fieldValue == null && value !== 1)
|
|
22
|
-
return;
|
|
23
|
-
set(result, key, value === 1 ? fieldValue : void 0);
|
|
2
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
3
|
+
const intersection = require("./index.cjs27.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 = 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 }
|
|
24
19
|
});
|
|
25
|
-
return result;
|
|
26
20
|
}
|
|
27
|
-
|
|
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
|
+
}
|
|
59
|
+
}
|
|
60
|
+
if ($orNew.length > 0)
|
|
61
|
+
newSelector.$or = $orNew;
|
|
62
|
+
}
|
|
63
|
+
return {
|
|
64
|
+
matched,
|
|
65
|
+
positions: positions || [],
|
|
66
|
+
optimizedSelector: newSelector
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
exports.default = getIndexInfo;
|
|
70
|
+
exports.getMergedIndexInfo = getMergedIndexInfo;
|
package/dist/index.cjs23.js
CHANGED
|
@@ -2,145 +2,86 @@
|
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
3
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
4
4
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
call(event, ...args) {
|
|
28
|
-
this.callbacks[event].forEach(({ callback, options }) => {
|
|
29
|
-
if (!options.skipInitial || !options.isInitial) {
|
|
30
|
-
callback(...args);
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
hasCallbacks(events) {
|
|
35
|
-
return events.some((event) => this.callbacks[event].length > 0);
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Determines if the observer has no active callbacks registered for any events.
|
|
39
|
-
* @returns A boolean indicating whether the observer is empty (i.e., no callbacks are registered).
|
|
40
|
-
*/
|
|
41
|
-
isEmpty() {
|
|
42
|
-
return !this.hasCallbacks([
|
|
43
|
-
"added",
|
|
44
|
-
"addedBefore",
|
|
45
|
-
"changed",
|
|
46
|
-
"changedField",
|
|
47
|
-
"movedBefore",
|
|
48
|
-
"removed"
|
|
49
|
-
]);
|
|
50
|
-
}
|
|
5
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
6
|
+
const index = require("./index.cjs3.js");
|
|
7
|
+
const combinePersistenceAdapters = require("./index.cjs5.js");
|
|
8
|
+
const createPersistenceAdapter = require("./index.cjs8.js");
|
|
9
|
+
const createSignal = require("./index.cjs21.js");
|
|
10
|
+
function createReplicationAdapter(options) {
|
|
11
|
+
return createPersistenceAdapter({
|
|
12
|
+
async register(onChange) {
|
|
13
|
+
if (!options.registerRemoteChange)
|
|
14
|
+
return;
|
|
15
|
+
await options.registerRemoteChange(onChange);
|
|
16
|
+
},
|
|
17
|
+
load: () => options.pull(),
|
|
18
|
+
save: (items, changes) => {
|
|
19
|
+
if (!options.push)
|
|
20
|
+
throw new Error("Pushing is not configured for this collection. Try to pass a `push` function to the collection options.");
|
|
21
|
+
return options.push(changes, items);
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
class ReplicatedCollection extends index.default {
|
|
51
26
|
/**
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
27
|
+
* Creates a new instance of the `ReplicatedCollection` class.
|
|
28
|
+
* Sets up the replication adapter, combining it with an optional persistence adapter, and
|
|
29
|
+
* initializes signals for tracking remote pull and push operations.
|
|
30
|
+
* @param options - The configuration options for the replicated collection.
|
|
31
|
+
* @param options.pull - A function to fetch data from the remote source.
|
|
32
|
+
* @param options.push - An optional function to send changes and items to the remote source.
|
|
33
|
+
* @param options.registerRemoteChange - An optional function to register a listener for remote changes.
|
|
34
|
+
* @param options.persistence - An optional persistence adapter to combine with replication.
|
|
35
|
+
* @param options.reactivity - A reactivity adapter for observing changes in the collection.
|
|
36
|
+
* @param options.transform - A transformation function to apply to items when retrieving them.
|
|
37
|
+
* @param options.indices - An array of index providers for optimized querying.
|
|
38
|
+
* @param options.enableDebugMode - A boolean to enable or disable debug mode.
|
|
55
39
|
*/
|
|
56
|
-
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
if (this.hasCallbacks(["changed", "changedField", "movedBefore", "removed"])) {
|
|
66
|
-
oldItemsMap.forEach(({ item: oldItem, index, beforeItem: oldBeforeItem }) => {
|
|
67
|
-
var _a;
|
|
68
|
-
const newItem = newItemsMap.get(oldItem.id);
|
|
69
|
-
if (newItem) {
|
|
70
|
-
if (this.hasCallbacks(["changed", "changedField"]) && !isEqual(newItem.item, oldItem)) {
|
|
71
|
-
this.call("changed", newItem.item);
|
|
72
|
-
if (this.hasCallbacks(["changedField"])) {
|
|
73
|
-
const keys = uniqueBy([
|
|
74
|
-
...Object.keys(newItem.item),
|
|
75
|
-
...Object.keys(oldItem)
|
|
76
|
-
], (value) => value);
|
|
77
|
-
keys.forEach((key) => {
|
|
78
|
-
if (isEqual(newItem.item[key], oldItem[key]))
|
|
79
|
-
return;
|
|
80
|
-
this.call("changedField", newItem.item, key, oldItem[key], newItem.item[key]);
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
if (newItem.index !== index && ((_a = newItem.beforeItem) == null ? void 0 : _a.id) !== (oldBeforeItem == null ? void 0 : oldBeforeItem.id)) {
|
|
85
|
-
this.call("movedBefore", newItem.item, newItem.beforeItem);
|
|
86
|
-
}
|
|
87
|
-
} else {
|
|
88
|
-
this.call("removed", oldItem);
|
|
40
|
+
constructor(options) {
|
|
41
|
+
const replicationAdapter = createReplicationAdapter({
|
|
42
|
+
registerRemoteChange: options.registerRemoteChange,
|
|
43
|
+
pull: async () => {
|
|
44
|
+
this.isPullingRemoteSignal.set(true);
|
|
45
|
+
try {
|
|
46
|
+
return await options.pull();
|
|
47
|
+
} finally {
|
|
48
|
+
this.isPullingRemoteSignal.set(false);
|
|
89
49
|
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
this.previousItems = newItems;
|
|
102
|
-
Object.keys(this.callbacks).forEach((key) => {
|
|
103
|
-
const event = key;
|
|
104
|
-
const callbacks = this.callbacks[event];
|
|
105
|
-
this.callbacks[event] = callbacks.map((callback) => ({
|
|
106
|
-
...callback,
|
|
107
|
-
options: {
|
|
108
|
-
...callback.options,
|
|
109
|
-
isInitial: false
|
|
50
|
+
},
|
|
51
|
+
push: options.push ? async (changes, items) => {
|
|
52
|
+
if (!options.push)
|
|
53
|
+
throw new Error("Pushing is not configured for this collection. Try to pass a `push` function to the collection options.");
|
|
54
|
+
this.isPushingRemoteSignal.set(true);
|
|
55
|
+
try {
|
|
56
|
+
await options.push(changes, items);
|
|
57
|
+
} finally {
|
|
58
|
+
this.isPushingRemoteSignal.set(false);
|
|
110
59
|
}
|
|
111
|
-
}
|
|
60
|
+
} : void 0
|
|
112
61
|
});
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
stop() {
|
|
118
|
-
this.unbindEvents();
|
|
119
|
-
}
|
|
120
|
-
/**
|
|
121
|
-
* Registers callbacks for specific events to observe changes in the collection.
|
|
122
|
-
* @param callbacks - An object containing the callbacks for various events (e.g., 'added', 'removed').
|
|
123
|
-
* @param skipInitial - A boolean indicating whether to skip invoking the callbacks for the initial state of the collection.
|
|
124
|
-
*/
|
|
125
|
-
addCallbacks(callbacks, skipInitial = false) {
|
|
126
|
-
Object.keys(callbacks).forEach((key) => {
|
|
127
|
-
const typedKey = key;
|
|
128
|
-
this.callbacks[typedKey].push({
|
|
129
|
-
callback: callbacks[typedKey],
|
|
130
|
-
options: { skipInitial, isInitial: true }
|
|
131
|
-
});
|
|
62
|
+
const persistenceAdapter = (options == null ? void 0 : options.persistence) ? combinePersistenceAdapters.default(replicationAdapter, options.persistence) : replicationAdapter;
|
|
63
|
+
super({
|
|
64
|
+
...options,
|
|
65
|
+
persistence: persistenceAdapter
|
|
132
66
|
});
|
|
67
|
+
__publicField(this, "isPullingRemoteSignal");
|
|
68
|
+
__publicField(this, "isPushingRemoteSignal");
|
|
69
|
+
this.isPullingRemoteSignal = createSignal(options.reactivity, false);
|
|
70
|
+
this.isPushingRemoteSignal = createSignal(options.reactivity, false);
|
|
133
71
|
}
|
|
134
72
|
/**
|
|
135
|
-
*
|
|
136
|
-
*
|
|
73
|
+
* Checks whether the collection is currently performing any loading operation,
|
|
74
|
+
* including pulling or pushing data from/to the remote source, or standard
|
|
75
|
+
* persistence adapter operations.
|
|
76
|
+
* ⚡️ this function is reactive!
|
|
77
|
+
* @returns A boolean indicating if the collection is currently loading or synchronizing.
|
|
137
78
|
*/
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
});
|
|
79
|
+
isLoading() {
|
|
80
|
+
const isPullingRemote = this.isPullingRemoteSignal.get();
|
|
81
|
+
const isPushingRemote = this.isPushingRemoteSignal.get();
|
|
82
|
+
const isLoading = super.isLoading();
|
|
83
|
+
return isPullingRemote || isPushingRemote || isLoading;
|
|
144
84
|
}
|
|
145
85
|
}
|
|
146
|
-
|
|
86
|
+
exports.createReplicationAdapter = createReplicationAdapter;
|
|
87
|
+
exports.default = ReplicatedCollection;
|
package/dist/index.cjs24.js
CHANGED
|
@@ -1,7 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
function
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
function get(value, path) {
|
|
3
|
+
const segments = path.split(/[.[\]]/g);
|
|
4
|
+
if (segments[0] === "")
|
|
5
|
+
segments.shift();
|
|
6
|
+
if (segments.at(-1) === "")
|
|
7
|
+
segments.pop();
|
|
8
|
+
let current = value;
|
|
9
|
+
for (const key of segments) {
|
|
10
|
+
if (current == null || key.trim() === "")
|
|
11
|
+
return;
|
|
12
|
+
current = current[key];
|
|
13
|
+
}
|
|
14
|
+
if (current === void 0)
|
|
15
|
+
return;
|
|
16
|
+
return current;
|
|
6
17
|
}
|
|
7
|
-
module.exports =
|
|
18
|
+
module.exports = get;
|
package/dist/index.cjs25.js
CHANGED
|
@@ -1,18 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
function
|
|
2
|
+
function set(object, path, value, deleteIfUndefined = false) {
|
|
3
|
+
if (object == null)
|
|
4
|
+
return object;
|
|
3
5
|
const segments = path.split(/[.[\]]/g);
|
|
4
6
|
if (segments[0] === "")
|
|
5
7
|
segments.shift();
|
|
6
8
|
if (segments.at(-1) === "")
|
|
7
9
|
segments.pop();
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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;
|
|
17
28
|
}
|
|
18
|
-
module.exports =
|
|
29
|
+
module.exports = set;
|
package/dist/index.cjs26.js
CHANGED
|
@@ -1,29 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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;
|
|
23
|
-
}
|
|
24
|
-
return { include: null, exclude: null };
|
|
25
|
-
}
|
|
26
|
-
result.include = [serializeValue(fieldSelector)];
|
|
27
|
-
return result;
|
|
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
|
+
});
|
|
28
8
|
}
|
|
29
|
-
module.exports =
|
|
9
|
+
module.exports = uniqueBy;
|
package/dist/index.cjs27.js
CHANGED
|
@@ -1,42 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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 intersection(...arrays) {
|
|
3
|
+
if (arrays.length === 0)
|
|
4
|
+
return [];
|
|
5
|
+
return [...new Set(arrays.reduce((a, b) => a.filter((c) => b.includes(c))))];
|
|
41
6
|
}
|
|
42
|
-
module.exports =
|
|
7
|
+
module.exports = intersection;
|
package/dist/index.cjs28.js
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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;
|
|
2
|
+
const isFieldExpression = require("./index.cjs29.js");
|
|
3
|
+
const serializeValue = require("./index.cjs20.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;
|
|
24
15
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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;
|
|
28
28
|
}
|
|
29
|
-
module.exports =
|
|
29
|
+
module.exports = getMatchingKeys;
|