@signaldb/core 1.0.0 → 1.2.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/README.md +2 -2
- package/dist/.vite/manifest.json +78 -64
- package/dist/Collection/index.d.ts +39 -16
- package/dist/Collection/types.d.ts +1 -1
- package/dist/devtools.d.ts +4 -0
- package/dist/index.cjs.js +19 -11
- package/dist/index.cjs10.js +27 -6
- package/dist/index.cjs11.js +6 -3
- package/dist/index.cjs12.js +3 -35
- package/dist/index.cjs13.js +141 -16
- package/dist/index.cjs14.js +38 -5
- package/dist/index.cjs15.js +2 -42
- package/dist/index.cjs16.js +5 -11
- package/dist/index.cjs17.js +40 -17
- package/dist/index.cjs18.js +11 -245
- package/dist/index.cjs19.js +16 -67
- package/dist/index.cjs2.js +104 -615
- package/dist/index.cjs20.js +251 -67
- package/dist/index.cjs21.js +68 -8
- package/dist/index.cjs22.js +83 -22
- package/dist/index.cjs23.js +8 -135
- package/dist/index.cjs24.js +25 -16
- package/dist/index.cjs25.js +144 -5
- package/dist/index.cjs26.js +5 -17
- package/dist/index.cjs27.js +15 -21
- package/dist/index.cjs28.js +21 -39
- package/dist/index.cjs29.js +40 -27
- package/dist/index.cjs3.js +669 -136
- package/dist/index.cjs30.js +27 -7
- package/dist/index.cjs31.js +9 -0
- package/dist/index.cjs4.js +166 -63
- package/dist/index.cjs5.js +66 -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 -28
- package/dist/index.d.ts +2 -0
- package/dist/index.mjs +20 -12
- package/dist/index10.mjs +27 -6
- package/dist/index11.mjs +6 -3
- package/dist/index12.mjs +3 -34
- package/dist/index13.mjs +141 -16
- package/dist/index14.mjs +37 -5
- package/dist/index15.mjs +2 -41
- package/dist/index16.mjs +5 -11
- package/dist/index17.mjs +39 -17
- package/dist/index18.mjs +11 -244
- package/dist/index19.mjs +16 -66
- package/dist/index2.mjs +80 -615
- package/dist/index20.mjs +251 -67
- package/dist/index21.mjs +67 -8
- package/dist/index22.mjs +82 -22
- package/dist/index23.mjs +8 -135
- package/dist/index24.mjs +25 -15
- package/dist/index25.mjs +144 -5
- package/dist/index26.mjs +5 -17
- package/dist/index27.mjs +15 -21
- package/dist/index28.mjs +21 -39
- package/dist/index29.mjs +40 -27
- package/dist/index3.mjs +669 -136
- package/dist/index30.mjs +27 -7
- package/dist/index31.mjs +10 -0
- package/dist/index4.mjs +166 -62
- package/dist/index5.mjs +65 -3
- package/dist/index6.mjs +2 -2
- package/dist/index7.mjs +2 -2
- package/dist/index8.mjs +2 -2
- package/dist/index9.mjs +3 -28
- package/dist/persistence/combinePersistenceAdapters.d.ts +7 -7
- package/dist/types/MemoryAdapter.d.ts +2 -2
- package/dist/utils/EventEmitter.d.ts +75 -0
- package/dist/utils/deepClone.d.ts +2 -2
- package/dist/utils/set.d.ts +2 -2
- package/dist/utils/uniqueBy.d.ts +2 -2
- package/package.json +1 -1
- package/dist/types/EventEmitter.d.ts +0 -25
package/dist/index.cjs24.js
CHANGED
|
@@ -1,18 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
2
|
+
const get = require("./index.cjs27.js");
|
|
3
|
+
const set = require("./index.cjs30.js");
|
|
4
|
+
function project(item, fields) {
|
|
5
|
+
const allFieldsDeactivated = Object.values(fields).every((value) => value === 0);
|
|
6
|
+
if (allFieldsDeactivated) {
|
|
7
|
+
const result2 = { ...item };
|
|
8
|
+
Object.keys(fields).forEach((key) => {
|
|
9
|
+
const fieldValue = get(item, key);
|
|
10
|
+
if (fieldValue === void 0)
|
|
11
|
+
return;
|
|
12
|
+
set(result2, key, void 0, true);
|
|
13
|
+
});
|
|
14
|
+
return result2;
|
|
15
|
+
}
|
|
16
|
+
const result = {};
|
|
17
|
+
Object.entries(fields).forEach(([key, value]) => {
|
|
18
|
+
const fieldValue = get(item, key);
|
|
19
|
+
if (fieldValue === void 0)
|
|
20
|
+
return;
|
|
21
|
+
if (fieldValue == null && value !== 1)
|
|
22
|
+
return;
|
|
23
|
+
set(result, key, value === 1 ? fieldValue : void 0);
|
|
24
|
+
});
|
|
25
|
+
return result;
|
|
13
26
|
}
|
|
14
|
-
|
|
15
|
-
var e = new Error(message);
|
|
16
|
-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
17
|
-
};
|
|
18
|
-
exports.__rest = __rest;
|
|
27
|
+
module.exports = project;
|
package/dist/index.cjs25.js
CHANGED
|
@@ -1,7 +1,146 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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.cjs10.js");
|
|
6
|
+
const uniqueBy = require("./index.cjs31.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
|
+
}
|
|
6
145
|
}
|
|
7
|
-
module.exports =
|
|
146
|
+
module.exports = Observer;
|
package/dist/index.cjs26.js
CHANGED
|
@@ -1,19 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
function
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
if (segments[segments.length - 1] === "")
|
|
7
|
-
segments.pop();
|
|
8
|
-
let current = value;
|
|
9
|
-
for (let i = 0; i < segments.length; i += 1) {
|
|
10
|
-
const key = segments[i];
|
|
11
|
-
if (current == null || key.trim() === "")
|
|
12
|
-
return void 0;
|
|
13
|
-
current = current[key];
|
|
14
|
-
}
|
|
15
|
-
if (current === void 0)
|
|
16
|
-
return void 0;
|
|
17
|
-
return current;
|
|
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))))];
|
|
18
6
|
}
|
|
19
|
-
module.exports =
|
|
7
|
+
module.exports = intersection;
|
package/dist/index.cjs27.js
CHANGED
|
@@ -1,24 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
if (Object.keys(optimizedSelector[field]).length === 0) {
|
|
14
|
-
delete optimizedSelector[field];
|
|
15
|
-
}
|
|
16
|
-
return selector[field].$in.map(serializeValue);
|
|
17
|
-
}
|
|
18
|
-
return null;
|
|
19
|
-
}
|
|
20
|
-
return [serializeValue(selector[field])];
|
|
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];
|
|
21
13
|
}
|
|
22
|
-
|
|
14
|
+
if (current === void 0)
|
|
15
|
+
return;
|
|
16
|
+
return current;
|
|
23
17
|
}
|
|
24
|
-
module.exports =
|
|
18
|
+
module.exports = get;
|
package/dist/index.cjs28.js
CHANGED
|
@@ -1,42 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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;
|
|
2
|
+
const isFieldExpression = require("./index.cjs29.js");
|
|
3
|
+
const serializeValue = require("./index.cjs18.js");
|
|
4
|
+
function getMatchingKeys(field, selector) {
|
|
5
|
+
if (selector[field] instanceof RegExp)
|
|
6
|
+
return null;
|
|
7
|
+
if (selector[field] != null) {
|
|
8
|
+
if (isFieldExpression(selector[field])) {
|
|
9
|
+
const is$in = isFieldExpression(selector[field]) && Array.isArray(selector[field].$in) && selector[field].$in.length > 0;
|
|
10
|
+
if (is$in) {
|
|
11
|
+
const optimizedSelector = { ...selector, [field]: { ...selector[field] } };
|
|
12
|
+
delete optimizedSelector[field].$in;
|
|
13
|
+
if (Object.keys(optimizedSelector[field]).length === 0) {
|
|
14
|
+
delete optimizedSelector[field];
|
|
15
|
+
}
|
|
16
|
+
return selector[field].$in.map(serializeValue);
|
|
17
|
+
}
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
return [serializeValue(selector[field])];
|
|
31
21
|
}
|
|
32
|
-
|
|
33
|
-
if (keys.length === 0) {
|
|
34
|
-
return false;
|
|
35
|
-
}
|
|
36
|
-
const hasInvalidKeys = keys.some((key) => !expressionKeys.includes(key));
|
|
37
|
-
if (hasInvalidKeys)
|
|
38
|
-
return false;
|
|
39
|
-
const hasValidKeys = keys.every((key) => expressionKeys.includes(key));
|
|
40
|
-
return hasValidKeys;
|
|
22
|
+
return null;
|
|
41
23
|
}
|
|
42
|
-
module.exports =
|
|
24
|
+
module.exports = getMatchingKeys;
|
package/dist/index.cjs29.js
CHANGED
|
@@ -1,29 +1,42 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
2
|
+
const expressionKeys = /* @__PURE__ */ new Set([
|
|
3
|
+
"$eq",
|
|
4
|
+
"$gt",
|
|
5
|
+
"$gte",
|
|
6
|
+
"$lt",
|
|
7
|
+
"$lte",
|
|
8
|
+
"$in",
|
|
9
|
+
"$nin",
|
|
10
|
+
"$ne",
|
|
11
|
+
"$exists",
|
|
12
|
+
"$not",
|
|
13
|
+
"$expr",
|
|
14
|
+
"$jsonSchema",
|
|
15
|
+
"$mod",
|
|
16
|
+
"$regex",
|
|
17
|
+
"$options",
|
|
18
|
+
"$text",
|
|
19
|
+
"$where",
|
|
20
|
+
"$all",
|
|
21
|
+
"$elemMatch",
|
|
22
|
+
"$size",
|
|
23
|
+
"$bitsAllClear",
|
|
24
|
+
"$bitsAllSet",
|
|
25
|
+
"$bitsAnyClear",
|
|
26
|
+
"$bitsAnySet"
|
|
27
|
+
]);
|
|
28
|
+
function isFieldExpression(expression) {
|
|
29
|
+
if (typeof expression !== "object" || expression == null) {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
const keys = Object.keys(expression);
|
|
33
|
+
if (keys.length === 0) {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
const hasInvalidKeys = keys.some((key) => !expressionKeys.has(key));
|
|
37
|
+
if (hasInvalidKeys)
|
|
38
|
+
return false;
|
|
39
|
+
const hasValidKeys = keys.every((key) => expressionKeys.has(key));
|
|
40
|
+
return hasValidKeys;
|
|
28
41
|
}
|
|
29
|
-
module.exports =
|
|
42
|
+
module.exports = isFieldExpression;
|