@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.cjs23.js
CHANGED
|
@@ -1,10 +1,146 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
+
const isEqual = require("./index.cjs9.js");
|
|
6
|
+
const uniqueBy = require("./index.cjs29.js");
|
|
7
|
+
class Observer {
|
|
8
|
+
/**
|
|
9
|
+
* Creates a new instance of the `Observer` class.
|
|
10
|
+
* Sets up event bindings and initializes the callbacks for tracking changes in a collection.
|
|
11
|
+
* @param bindEvents - A function to bind external events to the observer. Must return a cleanup function to unbind those events.
|
|
12
|
+
*/
|
|
13
|
+
constructor(bindEvents) {
|
|
14
|
+
__publicField(this, "previousItems", []);
|
|
15
|
+
__publicField(this, "callbacks");
|
|
16
|
+
__publicField(this, "unbindEvents");
|
|
17
|
+
this.callbacks = {
|
|
18
|
+
added: [],
|
|
19
|
+
addedBefore: [],
|
|
20
|
+
changed: [],
|
|
21
|
+
changedField: [],
|
|
22
|
+
movedBefore: [],
|
|
23
|
+
removed: []
|
|
24
|
+
};
|
|
25
|
+
this.unbindEvents = bindEvents();
|
|
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
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Compares the previous state of items with the new state and triggers the appropriate callbacks
|
|
53
|
+
* for events such as added, removed, changed, or moved items.
|
|
54
|
+
* @param newItems - The new list of items to compare against the previous state.
|
|
55
|
+
*/
|
|
56
|
+
runChecks(newItems) {
|
|
57
|
+
const oldItemsMap = new Map(this.previousItems.map((item, index) => [
|
|
58
|
+
item.id,
|
|
59
|
+
{ item, index, beforeItem: this.previousItems[index + 1] || null }
|
|
60
|
+
]));
|
|
61
|
+
const newItemsMap = new Map(newItems.map((item, index) => [
|
|
62
|
+
item.id,
|
|
63
|
+
{ item, index, beforeItem: newItems[index + 1] || null }
|
|
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);
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
if (this.hasCallbacks(["added", "addedBefore"])) {
|
|
93
|
+
newItems.forEach((newItem, index) => {
|
|
94
|
+
const oldItem = oldItemsMap.get(newItem.id);
|
|
95
|
+
if (oldItem)
|
|
96
|
+
return;
|
|
97
|
+
this.call("added", newItem);
|
|
98
|
+
this.call("addedBefore", newItem, newItems[index + 1] || null);
|
|
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
|
|
110
|
+
}
|
|
111
|
+
}));
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Stops the observer by unbinding all events and cleaning up resources.
|
|
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
|
+
});
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Removes the specified callbacks for specific events, unregistering them from the observer.
|
|
136
|
+
* @param callbacks - An object containing the callbacks to be removed for various events.
|
|
137
|
+
*/
|
|
138
|
+
removeCallbacks(callbacks) {
|
|
139
|
+
Object.keys(callbacks).forEach((key) => {
|
|
140
|
+
const typedKey = key;
|
|
141
|
+
const index = this.callbacks[typedKey].findIndex(({ callback }) => callback === callbacks[typedKey]);
|
|
142
|
+
this.callbacks[typedKey].splice(index, 1);
|
|
143
|
+
});
|
|
144
|
+
}
|
|
9
145
|
}
|
|
10
|
-
module.exports =
|
|
146
|
+
module.exports = Observer;
|
package/dist/index.cjs24.js
CHANGED
|
@@ -1,27 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
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
|
+
function intersection(...arrays) {
|
|
3
|
+
if (arrays.length === 0)
|
|
4
|
+
return [];
|
|
5
|
+
return [...new Set(arrays.reduce((a, b) => a.filter((c) => b.includes(c))))];
|
|
26
6
|
}
|
|
27
|
-
module.exports =
|
|
7
|
+
module.exports = intersection;
|
package/dist/index.cjs25.js
CHANGED
|
@@ -1,146 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
this.callbacks = {
|
|
18
|
-
added: [],
|
|
19
|
-
addedBefore: [],
|
|
20
|
-
changed: [],
|
|
21
|
-
changedField: [],
|
|
22
|
-
movedBefore: [],
|
|
23
|
-
removed: []
|
|
24
|
-
};
|
|
25
|
-
this.unbindEvents = bindEvents();
|
|
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
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Compares the previous state of items with the new state and triggers the appropriate callbacks
|
|
53
|
-
* for events such as added, removed, changed, or moved items.
|
|
54
|
-
* @param newItems - The new list of items to compare against the previous state.
|
|
55
|
-
*/
|
|
56
|
-
runChecks(newItems) {
|
|
57
|
-
const oldItemsMap = new Map(this.previousItems.map((item, index) => [
|
|
58
|
-
item.id,
|
|
59
|
-
{ item, index, beforeItem: this.previousItems[index + 1] || null }
|
|
60
|
-
]));
|
|
61
|
-
const newItemsMap = new Map(newItems.map((item, index) => [
|
|
62
|
-
item.id,
|
|
63
|
-
{ item, index, beforeItem: newItems[index + 1] || null }
|
|
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);
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
if (this.hasCallbacks(["added", "addedBefore"])) {
|
|
93
|
-
newItems.forEach((newItem, index) => {
|
|
94
|
-
const oldItem = oldItemsMap.get(newItem.id);
|
|
95
|
-
if (oldItem)
|
|
96
|
-
return;
|
|
97
|
-
this.call("added", newItem);
|
|
98
|
-
this.call("addedBefore", newItem, newItems[index + 1] || null);
|
|
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
|
|
110
|
-
}
|
|
111
|
-
}));
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* Stops the observer by unbinding all events and cleaning up resources.
|
|
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
|
-
});
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* Removes the specified callbacks for specific events, unregistering them from the observer.
|
|
136
|
-
* @param callbacks - An object containing the callbacks to be removed for various events.
|
|
137
|
-
*/
|
|
138
|
-
removeCallbacks(callbacks) {
|
|
139
|
-
Object.keys(callbacks).forEach((key) => {
|
|
140
|
-
const typedKey = key;
|
|
141
|
-
const index = this.callbacks[typedKey].findIndex(({ callback }) => callback === callbacks[typedKey]);
|
|
142
|
-
this.callbacks[typedKey].splice(index, 1);
|
|
143
|
-
});
|
|
144
|
-
}
|
|
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;
|
|
145
17
|
}
|
|
146
|
-
module.exports =
|
|
18
|
+
module.exports = get;
|
package/dist/index.cjs26.js
CHANGED
|
@@ -1,7 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
const isFieldExpression = require("./index.cjs27.js");
|
|
3
|
+
const serializeValue = require("./index.cjs16.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;
|
|
23
|
+
}
|
|
24
|
+
return { include: null, exclude: null };
|
|
25
|
+
}
|
|
26
|
+
result.include = [serializeValue(fieldSelector)];
|
|
27
|
+
return result;
|
|
6
28
|
}
|
|
7
|
-
module.exports =
|
|
29
|
+
module.exports = getMatchingKeys;
|
package/dist/index.cjs27.js
CHANGED
|
@@ -1,18 +1,42 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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;
|
|
13
31
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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;
|
|
17
41
|
}
|
|
18
|
-
module.exports =
|
|
42
|
+
module.exports = isFieldExpression;
|
package/dist/index.cjs28.js
CHANGED
|
@@ -1,28 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
if (
|
|
7
|
-
|
|
8
|
-
if (
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
};
|
|
16
|
-
delete optimizedSelector[field].$in;
|
|
17
|
-
if (Object.keys(optimizedSelector[field]).length === 0) {
|
|
18
|
-
delete optimizedSelector[field];
|
|
19
|
-
}
|
|
20
|
-
return fieldSelector.$in.map(serializeValue);
|
|
2
|
+
function set(object, path, value, deleteIfUndefined = false) {
|
|
3
|
+
if (object == null)
|
|
4
|
+
return object;
|
|
5
|
+
const segments = path.split(/[.[\]]/g);
|
|
6
|
+
if (segments[0] === "")
|
|
7
|
+
segments.shift();
|
|
8
|
+
if (segments.at(-1) === "")
|
|
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 ? [] : {};
|
|
21
16
|
}
|
|
22
|
-
|
|
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;
|
|
23
24
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
return
|
|
25
|
+
};
|
|
26
|
+
apply(object);
|
|
27
|
+
return object;
|
|
27
28
|
}
|
|
28
|
-
module.exports =
|
|
29
|
+
module.exports = set;
|
package/dist/index.cjs29.js
CHANGED
|
@@ -1,42 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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 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
|
+
});
|
|
41
8
|
}
|
|
42
|
-
module.exports =
|
|
9
|
+
module.exports = uniqueBy;
|