@signaldb/core 1.7.0 → 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 -115
- 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 +16 -12
- package/dist/index.cjs18.js +24 -5
- package/dist/index.cjs2.js +27 -36
- package/dist/index.cjs20.js +102 -13
- package/dist/index.cjs21.js +124 -21
- package/dist/index.cjs22.js +5 -68
- package/dist/index.cjs23.js +22 -82
- 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 +242 -497
- package/dist/index.cjs30.js +42 -0
- package/dist/index.cjs31.js +9 -0
- package/dist/index.cjs4.js +3 -170
- package/dist/index.cjs5.js +3 -67
- 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 -115
- package/dist/index14.mjs +183 -66
- package/dist/index15.mjs +339 -8
- package/dist/index16.mjs +563 -20
- package/dist/index17.mjs +16 -12
- package/dist/index18.mjs +24 -5
- package/dist/index2.mjs +27 -36
- package/dist/index20.mjs +102 -13
- package/dist/index21.mjs +123 -21
- package/dist/index22.mjs +5 -67
- package/dist/index23.mjs +22 -81
- 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 +241 -497
- package/dist/index30.mjs +43 -0
- package/dist/index31.mjs +10 -0
- package/dist/index4.mjs +3 -170
- package/dist/index5.mjs +3 -66
- 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 +2 -2
- 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
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
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;
|
|
41
|
+
}
|
|
42
|
+
module.exports = isFieldExpression;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
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
|
+
});
|
|
8
|
+
}
|
|
9
|
+
module.exports = uniqueBy;
|
package/dist/index.cjs4.js
CHANGED
|
@@ -1,172 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
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;
|
|
33
|
-
}
|
|
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());
|
|
58
|
-
}
|
|
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);
|
|
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));
|
|
150
|
-
}
|
|
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;
|
|
167
|
-
}
|
|
168
|
-
const signal = this.ensureSignal(selector);
|
|
169
|
-
return signal.get() || isPushing;
|
|
170
|
-
}
|
|
2
|
+
function createStorageAdapter(definition) {
|
|
3
|
+
return definition;
|
|
171
4
|
}
|
|
172
|
-
module.exports =
|
|
5
|
+
module.exports = createStorageAdapter;
|
package/dist/index.cjs5.js
CHANGED
|
@@ -1,69 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
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
|
-
};
|
|
2
|
+
function createReactivityAdapter(definition) {
|
|
3
|
+
return definition;
|
|
35
4
|
}
|
|
36
|
-
|
|
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;
|
|
5
|
+
module.exports = createReactivityAdapter;
|
package/dist/index.cjs6.js
CHANGED
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
function
|
|
3
|
-
|
|
2
|
+
function isEqual(a, b) {
|
|
3
|
+
if (Object.is(a, b))
|
|
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;
|
|
4
28
|
}
|
|
5
|
-
module.exports =
|
|
29
|
+
module.exports = isEqual;
|
package/dist/index.cjs7.js
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
const mingo = require("mingo");
|
|
3
|
+
const deepClone = require("./index.cjs19.js");
|
|
4
|
+
function modify(item, modifier) {
|
|
5
|
+
const hasOperators = Object.keys(modifier).some((key) => key.startsWith("$"));
|
|
6
|
+
if (!hasOperators)
|
|
7
|
+
return modifier;
|
|
8
|
+
const clonedItem = deepClone.default(item);
|
|
9
|
+
mingo.update(clonedItem, modifier);
|
|
10
|
+
return clonedItem;
|
|
4
11
|
}
|
|
5
|
-
module.exports =
|
|
12
|
+
module.exports = modify;
|
package/dist/index.cjs8.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
function
|
|
3
|
-
return
|
|
2
|
+
function randomId() {
|
|
3
|
+
return Array.from({ length: 16 }, () => "abcdefghijklmnopqrstuvwxyz0123456789"[Math.floor(Math.random() * 36)]).join("");
|
|
4
4
|
}
|
|
5
|
-
module.exports =
|
|
5
|
+
module.exports = randomId;
|
package/dist/index.cjs9.js
CHANGED
|
@@ -1,5 +1,133 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
class EventEmitter {
|
|
3
|
+
_maxListeners = 100;
|
|
4
|
+
/**
|
|
5
|
+
* We store a set of the listeners for each event.
|
|
6
|
+
*/
|
|
7
|
+
_listenerStore = /* @__PURE__ */ new Map();
|
|
8
|
+
setMaxListeners(max) {
|
|
9
|
+
this._maxListeners = max;
|
|
10
|
+
return this;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Subscribe to an event with a listener function.
|
|
14
|
+
* @param eventName The event name (key of E).
|
|
15
|
+
* @param listener A function that receives the emitted arguments.
|
|
16
|
+
* @returns The emitter instance (for chaining).
|
|
17
|
+
*/
|
|
18
|
+
on(eventName, listener) {
|
|
19
|
+
let listenersSet = this._listenerStore.get(eventName);
|
|
20
|
+
if (!listenersSet) {
|
|
21
|
+
listenersSet = /* @__PURE__ */ new Set();
|
|
22
|
+
this._listenerStore.set(eventName, listenersSet);
|
|
23
|
+
}
|
|
24
|
+
listenersSet.add(listener);
|
|
25
|
+
if (listenersSet.size > this._maxListeners) {
|
|
26
|
+
console.warn(`Possible EventEmitter memory leak detected. ${listenersSet.size} ${String(eventName)} listeners added. Use emitter.setMaxListeners() to increase limit.`);
|
|
27
|
+
}
|
|
28
|
+
return this;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Subscribe to an event with a listener function.
|
|
32
|
+
* @param eventName The event name (key of E).
|
|
33
|
+
* @param listener A function that receives the emitted arguments.
|
|
34
|
+
* @returns The emitter instance (for chaining).
|
|
35
|
+
*/
|
|
36
|
+
addListener(eventName, listener) {
|
|
37
|
+
return this.on(eventName, listener);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Subscribe to an event, handling it only once. Automatically removes
|
|
41
|
+
* the listener after it fires the first time.
|
|
42
|
+
* @param eventName The event name (key of E).
|
|
43
|
+
* @param listener A function that receives the emitted arguments.
|
|
44
|
+
* @returns The emitter instance (for chaining).
|
|
45
|
+
*/
|
|
46
|
+
once(eventName, listener) {
|
|
47
|
+
const onceWrapper = ((...args) => {
|
|
48
|
+
listener(...args);
|
|
49
|
+
this.off(eventName, onceWrapper);
|
|
50
|
+
});
|
|
51
|
+
return this.on(eventName, onceWrapper);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Unsubscribe a previously subscribed listener.
|
|
55
|
+
* @param eventName The event name (key of E).
|
|
56
|
+
* @param listener The original function passed to `on` or `once`.
|
|
57
|
+
* @returns The emitter instance (for chaining).
|
|
58
|
+
*/
|
|
59
|
+
off(eventName, listener) {
|
|
60
|
+
const listenersSet = this._listenerStore.get(eventName);
|
|
61
|
+
if (!listenersSet)
|
|
62
|
+
return this;
|
|
63
|
+
listenersSet.delete(listener);
|
|
64
|
+
if (listenersSet.size === 0) {
|
|
65
|
+
this._listenerStore.delete(eventName);
|
|
66
|
+
}
|
|
67
|
+
return this;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Unsubscribe a previously subscribed listener.
|
|
71
|
+
* @param eventName The event name (key of E).
|
|
72
|
+
* @param listener The original function passed to `on` or `once`.
|
|
73
|
+
* @returns The emitter instance (for chaining).
|
|
74
|
+
*/
|
|
75
|
+
removeListener(eventName, listener) {
|
|
76
|
+
return this.off(eventName, listener);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Emit (dispatch) an event with a variable number of arguments.
|
|
80
|
+
* @param eventName The event name (key of E).
|
|
81
|
+
* @param args The arguments to pass to subscribed listeners.
|
|
82
|
+
*/
|
|
83
|
+
emit(eventName, ...args) {
|
|
84
|
+
this.listeners(eventName).forEach((listener) => {
|
|
85
|
+
listener(...args);
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Returns the array of listener functions currently registered for a given event.
|
|
90
|
+
* @param eventName The event name (key of E).
|
|
91
|
+
* @returns An array of listener functions.
|
|
92
|
+
*/
|
|
93
|
+
listeners(eventName) {
|
|
94
|
+
const listenersSet = this._listenerStore.get(eventName);
|
|
95
|
+
if (!listenersSet)
|
|
96
|
+
return [];
|
|
97
|
+
return [...listenersSet.values()];
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Returns the number of listeners for a given event.
|
|
101
|
+
* @param eventName The event name (key of E).
|
|
102
|
+
* @returns The number of listeners.
|
|
103
|
+
*/
|
|
104
|
+
listenerCount(eventName) {
|
|
105
|
+
const listenersSet = this._listenerStore.get(eventName);
|
|
106
|
+
return listenersSet ? listenersSet.size : 0;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Removes all listeners for a given event, or all events if none is specified.
|
|
110
|
+
* @param eventName Optional. If omitted, clears all events’ listeners.
|
|
111
|
+
* @returns The emitter instance (for chaining).
|
|
112
|
+
*/
|
|
113
|
+
removeAllListeners(eventName) {
|
|
114
|
+
if (eventName === void 0) {
|
|
115
|
+
for (const [eventName_, listenersSet] of this._listenerStore.entries()) {
|
|
116
|
+
for (const listener of listenersSet.values()) {
|
|
117
|
+
this.off(eventName_, listener);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
this._listenerStore.clear();
|
|
121
|
+
} else {
|
|
122
|
+
const listenersSet = this._listenerStore.get(eventName);
|
|
123
|
+
if (listenersSet) {
|
|
124
|
+
for (const listener of listenersSet.values()) {
|
|
125
|
+
this.off(eventName, listener);
|
|
126
|
+
}
|
|
127
|
+
this._listenerStore.delete(eventName);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return this;
|
|
131
|
+
}
|
|
4
132
|
}
|
|
5
|
-
module.exports =
|
|
133
|
+
module.exports = EventEmitter;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
export type { default as ReactivityAdapter } from './types/ReactivityAdapter';
|
|
2
|
-
export type { default as
|
|
3
|
-
export type { default as PersistenceAdapter, Changeset, LoadResponse, } from './types/PersistenceAdapter';
|
|
2
|
+
export type { default as StorageAdapter, Changeset, } from './types/StorageAdapter';
|
|
4
3
|
export type { default as Selector } from './types/Selector';
|
|
5
4
|
export type { default as Modifier } from './types/Modifier';
|
|
6
5
|
export type { BaseItem, ObserveCallbacks, CursorOptions, Transform, SortSpecifier, FieldSpecifier, FindOptions, CollectionOptions, } from './Collection';
|
|
7
6
|
export { default as Cursor } from './Collection/Cursor';
|
|
8
|
-
export { default as Collection
|
|
9
|
-
export { default as
|
|
10
|
-
export { default as combinePersistenceAdapters } from './persistence/combinePersistenceAdapters';
|
|
11
|
-
export { default as createIndexProvider } from './createIndexProvider';
|
|
12
|
-
export { default as createMemoryAdapter } from './createMemoryAdapter';
|
|
13
|
-
export { default as createPersistenceAdapter } from './persistence/createPersistenceAdapter';
|
|
7
|
+
export { default as Collection } from './Collection';
|
|
8
|
+
export { default as createStorageAdapter } from './createStorageAdapter';
|
|
14
9
|
export { default as createReactivityAdapter } from './createReactivityAdapter';
|
|
15
10
|
export { default as isEqual } from './utils/isEqual';
|
|
16
11
|
export { default as modify } from './utils/modify';
|
|
17
12
|
export { default as randomId } from './utils/randomId';
|
|
18
13
|
export { default as EventEmitter } from './utils/EventEmitter';
|
|
14
|
+
export { default as get } from './utils/get';
|
|
15
|
+
export { default as serializeValue } from './utils/serializeValue';
|
|
16
|
+
export { default as DefaultDataAdapter } from './DefaultDataAdapter';
|
|
17
|
+
export { default as AsyncDataAdapter } from './AsyncDataAdapter';
|
|
18
|
+
export { default as WorkerDataAdapter } from './WorkerDataAdapter';
|
|
19
|
+
export { default as WorkerDataAdapterHost } from './WorkerDataAdapterHost';
|
|
20
|
+
export { default as AutoFetchDataAdapter } from './AutoFetchDataAdapter';
|
package/dist/index.mjs
CHANGED
|
@@ -11,18 +11,22 @@ 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
13
|
import { default as default14 } from "./index14.mjs";
|
|
14
|
+
import { default as default15 } from "./index15.mjs";
|
|
15
|
+
import { default as default16 } from "./index16.mjs";
|
|
14
16
|
export {
|
|
15
|
-
|
|
17
|
+
default13 as AsyncDataAdapter,
|
|
18
|
+
default16 as AutoFetchDataAdapter,
|
|
16
19
|
default3 as Collection,
|
|
17
20
|
default2 as Cursor,
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
default14 as
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
21
|
+
default12 as DefaultDataAdapter,
|
|
22
|
+
default9 as EventEmitter,
|
|
23
|
+
default14 as WorkerDataAdapter,
|
|
24
|
+
default15 as WorkerDataAdapterHost,
|
|
25
|
+
default5 as createReactivityAdapter,
|
|
26
|
+
default4 as createStorageAdapter,
|
|
27
|
+
default10 as get,
|
|
28
|
+
default6 as isEqual,
|
|
29
|
+
default7 as modify,
|
|
30
|
+
default8 as randomId,
|
|
31
|
+
default11 as serializeValue
|
|
28
32
|
};
|
package/dist/index10.mjs
CHANGED
|
@@ -1,30 +1,19 @@
|
|
|
1
|
-
function
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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;
|
|
1
|
+
function get(value, path) {
|
|
2
|
+
const normalized = path.replaceAll(/\[(\w+)\]/g, ".$1");
|
|
3
|
+
if (normalized.includes("..") || normalized.startsWith(".") || normalized.endsWith(".")) {
|
|
4
|
+
return;
|
|
25
5
|
}
|
|
26
|
-
|
|
6
|
+
const segments = normalized.split(".");
|
|
7
|
+
let current = value;
|
|
8
|
+
for (const key of segments) {
|
|
9
|
+
if (current == null)
|
|
10
|
+
return;
|
|
11
|
+
current = current[key];
|
|
12
|
+
}
|
|
13
|
+
if (current === void 0)
|
|
14
|
+
return;
|
|
15
|
+
return current;
|
|
27
16
|
}
|
|
28
17
|
export {
|
|
29
|
-
|
|
18
|
+
get as default
|
|
30
19
|
};
|
package/dist/index11.mjs
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
function serializeValue(value) {
|
|
2
|
+
if (value == null)
|
|
3
|
+
return null;
|
|
4
|
+
if (typeof value === "string")
|
|
5
|
+
return value;
|
|
6
|
+
if (typeof value === "number")
|
|
7
|
+
return value.toString();
|
|
8
|
+
if (typeof value === "boolean")
|
|
9
|
+
return value.toString();
|
|
10
|
+
if (value instanceof Date)
|
|
11
|
+
return value.toISOString();
|
|
12
|
+
return JSON.stringify(value);
|
|
10
13
|
}
|
|
11
14
|
export {
|
|
12
|
-
|
|
15
|
+
serializeValue as default
|
|
13
16
|
};
|