@signaldb/core 1.5.3 → 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 +28 -27
- 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 -731
- 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 -27
- package/dist/index.cjs28.js +27 -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 -732
- 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 -27
- package/dist/index28.mjs +27 -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.cjs4.js
CHANGED
|
@@ -1,69 +1,172 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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 ReplicatedCollection = require("./index.cjs23.js");
|
|
6
|
+
const createSignal = require("./index.cjs21.js");
|
|
7
|
+
class AutoFetchCollection extends ReplicatedCollection.default {
|
|
8
|
+
/**
|
|
9
|
+
* @param options {Object} - Options for the collection.
|
|
10
|
+
* @param options.fetchQueryItems {Function} - A function that fetches items from the server. It takes the selector as an argument and returns a promise that resolves to an object with an `items` property.
|
|
11
|
+
* @param options.purgeDelay {Number} - The delay in milliseconds before purging an item from the cache.
|
|
12
|
+
*/
|
|
13
|
+
constructor(options) {
|
|
14
|
+
let triggerRemoteChange;
|
|
15
|
+
super({
|
|
16
|
+
...options,
|
|
17
|
+
pull: () => Promise.resolve({
|
|
18
|
+
items: [...this.itemsCache.values()].reduce((memo, items) => {
|
|
19
|
+
const newItems = [...memo];
|
|
20
|
+
items.forEach((item) => {
|
|
21
|
+
const index = newItems.findIndex((i) => i.id === item.id);
|
|
22
|
+
if (index === -1) {
|
|
23
|
+
newItems.push(item);
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
newItems[index] = this.mergeItems(newItems[index], item);
|
|
27
|
+
});
|
|
28
|
+
return newItems;
|
|
29
|
+
}, [])
|
|
30
|
+
}),
|
|
31
|
+
registerRemoteChange: async (onChange) => {
|
|
32
|
+
triggerRemoteChange = onChange;
|
|
15
33
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
34
|
+
});
|
|
35
|
+
__publicField(this, "activeObservers", /* @__PURE__ */ new Map());
|
|
36
|
+
__publicField(this, "observerTimeouts", /* @__PURE__ */ new Map());
|
|
37
|
+
__publicField(this, "purgeDelay");
|
|
38
|
+
__publicField(this, "idQueryCache", /* @__PURE__ */ new Map());
|
|
39
|
+
__publicField(this, "itemsCache", /* @__PURE__ */ new Map());
|
|
40
|
+
__publicField(this, "fetchQueryItems");
|
|
41
|
+
__publicField(this, "triggerReload", null);
|
|
42
|
+
__publicField(this, "reactivityAdapter", null);
|
|
43
|
+
__publicField(this, "loadingSignals", /* @__PURE__ */ new Map());
|
|
44
|
+
__publicField(this, "isFetchingSignal");
|
|
45
|
+
__publicField(this, "mergeItems");
|
|
46
|
+
this.mergeItems = options.mergeItems ?? ((itemA, itemB) => ({ ...itemA, ...itemB }));
|
|
47
|
+
this.purgeDelay = options.purgeDelay ?? 1e4;
|
|
48
|
+
this.isFetchingSignal = createSignal(options.reactivity, false);
|
|
49
|
+
if (!triggerRemoteChange)
|
|
50
|
+
throw new Error("No triggerRemoteChange method found. Looks like your persistence adapter was not registered");
|
|
51
|
+
this.triggerReload = triggerRemoteChange;
|
|
52
|
+
this.reactivityAdapter = options.reactivity ?? null;
|
|
53
|
+
this.fetchQueryItems = options.fetchQueryItems;
|
|
54
|
+
this.on("observer.created", (selector) => this.handleObserverCreation(selector ?? {}));
|
|
55
|
+
this.on("observer.disposed", (selector) => setTimeout(() => this.handleObserverDisposal(selector ?? {}), 100));
|
|
56
|
+
if (options.registerRemoteChange) {
|
|
57
|
+
void options.registerRemoteChange(() => this.forceRefetch());
|
|
32
58
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Registers a query manually that items should be fetched for it
|
|
62
|
+
* @param selector {Object} Selector of the query
|
|
63
|
+
*/
|
|
64
|
+
registerQuery(selector) {
|
|
65
|
+
this.handleObserverCreation(selector);
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Unregisters a query manually that items are not fetched anymore for it
|
|
69
|
+
* @param selector {Object} Selector of the query
|
|
70
|
+
*/
|
|
71
|
+
unregisterQuery(selector) {
|
|
72
|
+
this.handleObserverDisposal(selector);
|
|
73
|
+
}
|
|
74
|
+
getKeyForSelector(selector) {
|
|
75
|
+
return JSON.stringify(selector);
|
|
76
|
+
}
|
|
77
|
+
async forceRefetch() {
|
|
78
|
+
return Promise.all([...this.activeObservers.values()].map(({ selector }) => this.fetchSelector(selector))).then(() => {
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
fetchSelector(selector) {
|
|
82
|
+
this.isFetchingSignal.set(true);
|
|
83
|
+
return this.fetchQueryItems(selector).then((response) => {
|
|
84
|
+
if (!response.items)
|
|
85
|
+
throw new Error("AutoFetchCollection currently only works with a full item response");
|
|
86
|
+
this.itemsCache.set(this.getKeyForSelector(selector), response.items);
|
|
87
|
+
response.items.forEach((item) => {
|
|
88
|
+
const queries = this.idQueryCache.get(item.id) ?? [];
|
|
89
|
+
queries.push(selector);
|
|
90
|
+
this.idQueryCache.set(item.id, queries);
|
|
91
|
+
});
|
|
92
|
+
this.setLoading(selector, true);
|
|
93
|
+
this.once("persistence.received", () => {
|
|
94
|
+
this.setLoading(selector, false);
|
|
48
95
|
});
|
|
96
|
+
if (!this.triggerReload)
|
|
97
|
+
throw new Error("No triggerReload method found. Looks like your persistence adapter was not registered");
|
|
98
|
+
void this.triggerReload();
|
|
99
|
+
}).catch((error) => {
|
|
100
|
+
this.emit("persistence.error", error);
|
|
101
|
+
}).finally(() => {
|
|
102
|
+
this.isFetchingSignal.set(false);
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
handleObserverCreation(selector) {
|
|
106
|
+
var _a;
|
|
107
|
+
const activeObservers = ((_a = this.activeObservers.get(this.getKeyForSelector(selector))) == null ? void 0 : _a.count) ?? 0;
|
|
108
|
+
this.activeObservers.set(this.getKeyForSelector(selector), {
|
|
109
|
+
selector,
|
|
110
|
+
count: activeObservers + 1
|
|
111
|
+
});
|
|
112
|
+
const timeout = this.observerTimeouts.get(this.getKeyForSelector(selector));
|
|
113
|
+
if (timeout)
|
|
114
|
+
clearTimeout(timeout);
|
|
115
|
+
if (activeObservers === 0)
|
|
116
|
+
void this.fetchSelector(selector);
|
|
117
|
+
}
|
|
118
|
+
handleObserverDisposal(selector) {
|
|
119
|
+
var _a;
|
|
120
|
+
const currentObservers = ((_a = this.activeObservers.get(this.getKeyForSelector(selector))) == null ? void 0 : _a.count) ?? 0;
|
|
121
|
+
const activeObservers = currentObservers - 1;
|
|
122
|
+
if (activeObservers > 0) {
|
|
123
|
+
this.activeObservers.set(this.getKeyForSelector(selector), {
|
|
124
|
+
selector,
|
|
125
|
+
count: activeObservers
|
|
126
|
+
});
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
const timeout = this.observerTimeouts.get(this.getKeyForSelector(selector));
|
|
130
|
+
if (timeout)
|
|
131
|
+
clearTimeout(timeout);
|
|
132
|
+
const removeObserver = () => {
|
|
133
|
+
this.activeObservers.delete(this.getKeyForSelector(selector));
|
|
134
|
+
this.itemsCache.delete(this.getKeyForSelector(selector));
|
|
135
|
+
if (!this.triggerReload)
|
|
136
|
+
throw new Error("No triggerReload method found. Looks like your persistence adapter was not registered");
|
|
137
|
+
void this.triggerReload();
|
|
138
|
+
};
|
|
139
|
+
if (this.purgeDelay === 0) {
|
|
140
|
+
removeObserver();
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
this.observerTimeouts.set(this.getKeyForSelector(selector), setTimeout(removeObserver, this.purgeDelay));
|
|
144
|
+
}
|
|
145
|
+
ensureSignal(selector) {
|
|
146
|
+
if (!this.reactivityAdapter)
|
|
147
|
+
throw new Error("No reactivity adapter found");
|
|
148
|
+
if (!this.loadingSignals.has(this.getKeyForSelector(selector))) {
|
|
149
|
+
this.loadingSignals.set(this.getKeyForSelector(selector), createSignal(this.reactivityAdapter, false));
|
|
49
150
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
151
|
+
return this.loadingSignals.get(this.getKeyForSelector(selector));
|
|
152
|
+
}
|
|
153
|
+
setLoading(selector, value) {
|
|
154
|
+
const signal = this.ensureSignal(selector);
|
|
155
|
+
signal.set(value);
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Indicates wether a query is currently been loaded
|
|
159
|
+
* ⚡️ this function is reactive!
|
|
160
|
+
* @param selector {Object} Selector of the query
|
|
161
|
+
* @returns The loading state
|
|
162
|
+
*/
|
|
163
|
+
isLoading(selector) {
|
|
164
|
+
const isPushing = this.isPushing();
|
|
165
|
+
if (!selector) {
|
|
166
|
+
return this.isFetchingSignal.get() || isPushing;
|
|
65
167
|
}
|
|
66
|
-
|
|
168
|
+
const signal = this.ensureSignal(selector);
|
|
169
|
+
return signal.get() || isPushing;
|
|
170
|
+
}
|
|
67
171
|
}
|
|
68
|
-
exports
|
|
69
|
-
exports.default = combinePersistenceAdapters;
|
|
172
|
+
module.exports = AutoFetchCollection;
|
package/dist/index.cjs5.js
CHANGED
|
@@ -1,5 +1,69 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
3
|
+
const createPersistenceAdapter = require("./index.cjs8.js");
|
|
4
|
+
function createTemporaryFallbackExecutor(firstResolvingPromiseFunction, secondResolvingPromiseFunction, options) {
|
|
5
|
+
const cacheTimeout = options == null ? void 0 : options.cacheTimeout;
|
|
6
|
+
let isResolved = false;
|
|
7
|
+
let resolvedValue = null;
|
|
8
|
+
let timeout = null;
|
|
9
|
+
let secondaryPromise = null;
|
|
10
|
+
return (...args) => {
|
|
11
|
+
if (secondaryPromise == null) {
|
|
12
|
+
if (timeout) {
|
|
13
|
+
clearTimeout(timeout);
|
|
14
|
+
timeout = null;
|
|
15
|
+
}
|
|
16
|
+
secondaryPromise = secondResolvingPromiseFunction(...args).then((result) => {
|
|
17
|
+
{
|
|
18
|
+
timeout = setTimeout(() => {
|
|
19
|
+
isResolved = false;
|
|
20
|
+
resolvedValue = null;
|
|
21
|
+
secondaryPromise = null;
|
|
22
|
+
}, cacheTimeout);
|
|
23
|
+
}
|
|
24
|
+
isResolved = true;
|
|
25
|
+
resolvedValue = result;
|
|
26
|
+
if (options == null ? void 0 : options.onResolve)
|
|
27
|
+
options.onResolve(resolvedValue);
|
|
28
|
+
return result;
|
|
29
|
+
});
|
|
30
|
+
} else if (isResolved) {
|
|
31
|
+
return secondaryPromise;
|
|
32
|
+
}
|
|
33
|
+
return firstResolvingPromiseFunction(...args);
|
|
34
|
+
};
|
|
4
35
|
}
|
|
5
|
-
|
|
36
|
+
function combinePersistenceAdapters(slowAdapter, fastAdapter) {
|
|
37
|
+
let handleChange = null;
|
|
38
|
+
const readExecutor = createTemporaryFallbackExecutor(() => fastAdapter.load(), () => slowAdapter.load(), {
|
|
39
|
+
cacheTimeout: 100,
|
|
40
|
+
onResolve: (result) => {
|
|
41
|
+
var _a, _b, _c;
|
|
42
|
+
if (handleChange)
|
|
43
|
+
void handleChange();
|
|
44
|
+
void fastAdapter.save(result.items || [], {
|
|
45
|
+
added: ((_a = result.changes) == null ? void 0 : _a.added) || [],
|
|
46
|
+
modified: ((_b = result.changes) == null ? void 0 : _b.modified) || [],
|
|
47
|
+
removed: ((_c = result.changes) == null ? void 0 : _c.removed) || []
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
return createPersistenceAdapter({
|
|
52
|
+
async register(onChange) {
|
|
53
|
+
handleChange = onChange;
|
|
54
|
+
await Promise.all([slowAdapter.register(onChange), fastAdapter.register(onChange)]);
|
|
55
|
+
},
|
|
56
|
+
async load() {
|
|
57
|
+
const promise = readExecutor();
|
|
58
|
+
return promise;
|
|
59
|
+
},
|
|
60
|
+
async save(items, changes) {
|
|
61
|
+
await Promise.all([
|
|
62
|
+
fastAdapter.save(items, changes),
|
|
63
|
+
slowAdapter.save(items, changes)
|
|
64
|
+
]);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
exports.createTemporaryFallbackExecutor = createTemporaryFallbackExecutor;
|
|
69
|
+
exports.default = combinePersistenceAdapters;
|
package/dist/index.cjs6.js
CHANGED
package/dist/index.cjs7.js
CHANGED
package/dist/index.cjs8.js
CHANGED
package/dist/index.cjs9.js
CHANGED
|
@@ -1,29 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
function
|
|
3
|
-
|
|
4
|
-
return true;
|
|
5
|
-
if (a instanceof RegExp && b instanceof RegExp)
|
|
6
|
-
return a.toString() === b.toString();
|
|
7
|
-
if (a instanceof Date && b instanceof Date)
|
|
8
|
-
return a.getTime() === b.getTime();
|
|
9
|
-
if (typeof a !== "object")
|
|
10
|
-
return false;
|
|
11
|
-
if (typeof b !== "object")
|
|
12
|
-
return false;
|
|
13
|
-
if (a === null)
|
|
14
|
-
return false;
|
|
15
|
-
if (b === null)
|
|
16
|
-
return false;
|
|
17
|
-
const aKeys = Object.keys(a);
|
|
18
|
-
const bKeys = Object.keys(b);
|
|
19
|
-
if (aKeys.length !== bKeys.length)
|
|
20
|
-
return false;
|
|
21
|
-
for (const key of aKeys) {
|
|
22
|
-
if (!bKeys.includes(key))
|
|
23
|
-
return false;
|
|
24
|
-
if (!isEqual(a[key], b[key]))
|
|
25
|
-
return false;
|
|
26
|
-
}
|
|
27
|
-
return true;
|
|
2
|
+
function createReactivityAdapter(definition) {
|
|
3
|
+
return definition;
|
|
28
4
|
}
|
|
29
|
-
module.exports =
|
|
5
|
+
module.exports = createReactivityAdapter;
|
package/dist/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export type { default as PersistenceAdapter, Changeset, LoadResponse, } from './
|
|
|
4
4
|
export type { default as Selector } from './types/Selector';
|
|
5
5
|
export type { default as Modifier } from './types/Modifier';
|
|
6
6
|
export type { BaseItem, ObserveCallbacks, CursorOptions, Transform, SortSpecifier, FieldSpecifier, FindOptions, CollectionOptions, } from './Collection';
|
|
7
|
+
export { default as Cursor } from './Collection/Cursor';
|
|
7
8
|
export { default as Collection, createIndex } from './Collection';
|
|
8
9
|
export { default as AutoFetchCollection } from './AutoFetchCollection';
|
|
9
10
|
export { default as combinePersistenceAdapters } from './persistence/combinePersistenceAdapters';
|
package/dist/index.mjs
CHANGED
|
@@ -10,17 +10,19 @@ import { default as default10 } from "./index10.mjs";
|
|
|
10
10
|
import { default as default11 } from "./index11.mjs";
|
|
11
11
|
import { default as default12 } from "./index12.mjs";
|
|
12
12
|
import { default as default13 } from "./index13.mjs";
|
|
13
|
+
import { default as default14 } from "./index14.mjs";
|
|
13
14
|
export {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
default6 as
|
|
21
|
-
default7 as
|
|
22
|
-
default8 as
|
|
23
|
-
default9 as
|
|
24
|
-
default10 as
|
|
25
|
-
default11 as
|
|
15
|
+
default4 as AutoFetchCollection,
|
|
16
|
+
default3 as Collection,
|
|
17
|
+
default2 as Cursor,
|
|
18
|
+
default13 as EventEmitter,
|
|
19
|
+
default5 as combinePersistenceAdapters,
|
|
20
|
+
default14 as createIndex,
|
|
21
|
+
default6 as createIndexProvider,
|
|
22
|
+
default7 as createMemoryAdapter,
|
|
23
|
+
default8 as createPersistenceAdapter,
|
|
24
|
+
default9 as createReactivityAdapter,
|
|
25
|
+
default10 as isEqual,
|
|
26
|
+
default11 as modify,
|
|
27
|
+
default12 as randomId
|
|
26
28
|
};
|
package/dist/index10.mjs
CHANGED
|
@@ -1,13 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
function isEqual(a, b) {
|
|
2
|
+
if (Object.is(a, b))
|
|
3
|
+
return true;
|
|
4
|
+
if (a instanceof RegExp && b instanceof RegExp)
|
|
5
|
+
return a.toString() === b.toString();
|
|
6
|
+
if (a instanceof Date && b instanceof Date)
|
|
7
|
+
return a.getTime() === b.getTime();
|
|
8
|
+
if (typeof a !== "object")
|
|
9
|
+
return false;
|
|
10
|
+
if (typeof b !== "object")
|
|
11
|
+
return false;
|
|
12
|
+
if (a === null)
|
|
13
|
+
return false;
|
|
14
|
+
if (b === null)
|
|
15
|
+
return false;
|
|
16
|
+
const aKeys = Object.keys(a);
|
|
17
|
+
const bKeys = Object.keys(b);
|
|
18
|
+
if (aKeys.length !== bKeys.length)
|
|
19
|
+
return false;
|
|
20
|
+
for (const key of aKeys) {
|
|
21
|
+
if (!bKeys.includes(key))
|
|
22
|
+
return false;
|
|
23
|
+
if (!isEqual(a[key], b[key]))
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
return true;
|
|
10
27
|
}
|
|
11
28
|
export {
|
|
12
|
-
|
|
29
|
+
isEqual as default
|
|
13
30
|
};
|
package/dist/index11.mjs
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { update } from "mingo";
|
|
2
|
+
import deepClone from "./index19.mjs";
|
|
3
|
+
function modify(item, modifier) {
|
|
4
|
+
const hasOperators = Object.keys(modifier).some((key) => key.startsWith("$"));
|
|
5
|
+
if (!hasOperators)
|
|
6
|
+
return modifier;
|
|
7
|
+
const clonedItem = deepClone(item);
|
|
8
|
+
update(clonedItem, modifier);
|
|
9
|
+
return clonedItem;
|
|
3
10
|
}
|
|
4
11
|
export {
|
|
5
|
-
|
|
12
|
+
modify as default
|
|
6
13
|
};
|
package/dist/index12.mjs
CHANGED
|
@@ -1,139 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
|
-
class EventEmitter {
|
|
5
|
-
constructor() {
|
|
6
|
-
__publicField(this, "_maxListeners", 100);
|
|
7
|
-
/**
|
|
8
|
-
* We store a set of the listeners for each event.
|
|
9
|
-
*/
|
|
10
|
-
__publicField(this, "_listenerStore", /* @__PURE__ */ new Map());
|
|
11
|
-
}
|
|
12
|
-
setMaxListeners(max) {
|
|
13
|
-
this._maxListeners = max;
|
|
14
|
-
return this;
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Subscribe to an event with a listener function.
|
|
18
|
-
* @param eventName The event name (key of E).
|
|
19
|
-
* @param listener A function that receives the emitted arguments.
|
|
20
|
-
* @returns The emitter instance (for chaining).
|
|
21
|
-
*/
|
|
22
|
-
on(eventName, listener) {
|
|
23
|
-
let listenersSet = this._listenerStore.get(eventName);
|
|
24
|
-
if (!listenersSet) {
|
|
25
|
-
listenersSet = /* @__PURE__ */ new Set();
|
|
26
|
-
this._listenerStore.set(eventName, listenersSet);
|
|
27
|
-
}
|
|
28
|
-
listenersSet.add(listener);
|
|
29
|
-
if (listenersSet.size > this._maxListeners) {
|
|
30
|
-
console.warn(`Possible EventEmitter memory leak detected. ${listenersSet.size} ${String(eventName)} listeners added. Use emitter.setMaxListeners() to increase limit.`);
|
|
31
|
-
}
|
|
32
|
-
return this;
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Subscribe to an event with a listener function.
|
|
36
|
-
* @param eventName The event name (key of E).
|
|
37
|
-
* @param listener A function that receives the emitted arguments.
|
|
38
|
-
* @returns The emitter instance (for chaining).
|
|
39
|
-
*/
|
|
40
|
-
addListener(eventName, listener) {
|
|
41
|
-
return this.on(eventName, listener);
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Subscribe to an event, handling it only once. Automatically removes
|
|
45
|
-
* the listener after it fires the first time.
|
|
46
|
-
* @param eventName The event name (key of E).
|
|
47
|
-
* @param listener A function that receives the emitted arguments.
|
|
48
|
-
* @returns The emitter instance (for chaining).
|
|
49
|
-
*/
|
|
50
|
-
once(eventName, listener) {
|
|
51
|
-
const onceWrapper = (...args) => {
|
|
52
|
-
listener(...args);
|
|
53
|
-
this.off(eventName, onceWrapper);
|
|
54
|
-
};
|
|
55
|
-
return this.on(eventName, onceWrapper);
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Unsubscribe a previously subscribed listener.
|
|
59
|
-
* @param eventName The event name (key of E).
|
|
60
|
-
* @param listener The original function passed to `on` or `once`.
|
|
61
|
-
* @returns The emitter instance (for chaining).
|
|
62
|
-
*/
|
|
63
|
-
off(eventName, listener) {
|
|
64
|
-
const listenersSet = this._listenerStore.get(eventName);
|
|
65
|
-
if (!listenersSet)
|
|
66
|
-
return this;
|
|
67
|
-
listenersSet.delete(listener);
|
|
68
|
-
if (listenersSet.size === 0) {
|
|
69
|
-
this._listenerStore.delete(eventName);
|
|
70
|
-
}
|
|
71
|
-
return this;
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Unsubscribe a previously subscribed listener.
|
|
75
|
-
* @param eventName The event name (key of E).
|
|
76
|
-
* @param listener The original function passed to `on` or `once`.
|
|
77
|
-
* @returns The emitter instance (for chaining).
|
|
78
|
-
*/
|
|
79
|
-
removeListener(eventName, listener) {
|
|
80
|
-
return this.off(eventName, listener);
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* Emit (dispatch) an event with a variable number of arguments.
|
|
84
|
-
* @param eventName The event name (key of E).
|
|
85
|
-
* @param args The arguments to pass to subscribed listeners.
|
|
86
|
-
*/
|
|
87
|
-
emit(eventName, ...args) {
|
|
88
|
-
this.listeners(eventName).forEach((listener) => {
|
|
89
|
-
listener(...args);
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* Returns the array of listener functions currently registered for a given event.
|
|
94
|
-
* @param eventName The event name (key of E).
|
|
95
|
-
* @returns An array of listener functions.
|
|
96
|
-
*/
|
|
97
|
-
listeners(eventName) {
|
|
98
|
-
const listenersSet = this._listenerStore.get(eventName);
|
|
99
|
-
if (!listenersSet)
|
|
100
|
-
return [];
|
|
101
|
-
return [...listenersSet.values()];
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* Returns the number of listeners for a given event.
|
|
105
|
-
* @param eventName The event name (key of E).
|
|
106
|
-
* @returns The number of listeners.
|
|
107
|
-
*/
|
|
108
|
-
listenerCount(eventName) {
|
|
109
|
-
const listenersSet = this._listenerStore.get(eventName);
|
|
110
|
-
return listenersSet ? listenersSet.size : 0;
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* Removes all listeners for a given event, or all events if none is specified.
|
|
114
|
-
* @param eventName Optional. If omitted, clears all events’ listeners.
|
|
115
|
-
* @returns The emitter instance (for chaining).
|
|
116
|
-
*/
|
|
117
|
-
removeAllListeners(eventName) {
|
|
118
|
-
if (eventName === void 0) {
|
|
119
|
-
for (const [eventName_, listenersSet] of this._listenerStore.entries()) {
|
|
120
|
-
for (const listener of listenersSet.values()) {
|
|
121
|
-
this.off(eventName_, listener);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
this._listenerStore.clear();
|
|
125
|
-
} else {
|
|
126
|
-
const listenersSet = this._listenerStore.get(eventName);
|
|
127
|
-
if (listenersSet) {
|
|
128
|
-
for (const listener of listenersSet.values()) {
|
|
129
|
-
this.off(eventName, listener);
|
|
130
|
-
}
|
|
131
|
-
this._listenerStore.delete(eventName);
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
return this;
|
|
135
|
-
}
|
|
1
|
+
function randomId() {
|
|
2
|
+
return Math.floor(Math.random() * 1e17).toString(16);
|
|
136
3
|
}
|
|
137
4
|
export {
|
|
138
|
-
|
|
5
|
+
randomId as default
|
|
139
6
|
};
|