@signaldb/core 2.0.0-beta.21 → 2.0.0-beta.22
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 +3 -3
- package/dist/.vite/manifest.json +61 -59
- package/dist/AsyncDataAdapter.d.ts +15 -2
- package/dist/AutoFetchDataAdapter.d.ts +13 -2
- package/dist/Collection/Observer.d.ts +1 -1
- package/dist/Collection/index.d.ts +11 -12
- package/dist/DataAdapter.d.ts +19 -3
- package/dist/WorkerDataAdapterHost.d.ts +19 -6
- package/dist/index.cjs.js +4 -4
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs +4 -4
- package/dist/index12.cjs.js +1 -1
- package/dist/index12.mjs +1 -1
- package/dist/index15.cjs.js +6 -2
- package/dist/index15.mjs +6 -2
- package/dist/index17.cjs.js +4 -2
- package/dist/index17.mjs +4 -3
- package/dist/index18.cjs.js +1 -0
- package/dist/index18.mjs +1 -1
- package/dist/index28.cjs.js +15 -5
- package/dist/index28.mjs +15 -5
- package/dist/index29.cjs.js +29 -16
- package/dist/index29.mjs +29 -16
- package/dist/index33.cjs.js +17 -49
- package/dist/index33.mjs +17 -49
- package/dist/index34.cjs.js +45 -445
- package/dist/index34.mjs +45 -445
- package/dist/index35.cjs.js +132 -65
- package/dist/index35.mjs +132 -65
- package/dist/index36.cjs.js +385 -531
- package/dist/index36.mjs +386 -533
- package/dist/index37.cjs.js +68 -17
- package/dist/index37.mjs +68 -17
- package/dist/index38.cjs.js +536 -319
- package/dist/index38.mjs +538 -321
- package/dist/index39.cjs.js +301 -466
- package/dist/index39.mjs +301 -466
- package/dist/index40.cjs.js +484 -0
- package/dist/index40.mjs +484 -0
- package/dist/index5.cjs.js +3 -3
- package/dist/index5.mjs +3 -3
- package/dist/index6.cjs.js +1 -0
- package/dist/index6.mjs +1 -1
- package/dist/types/StorageAdapter.d.ts +80 -0
- package/dist/utils/executeStorageQuery.d.ts +28 -0
- package/package.json +1 -1
package/dist/index37.cjs.js
CHANGED
|
@@ -1,21 +1,72 @@
|
|
|
1
|
-
//#region src/utils/
|
|
1
|
+
//#region src/utils/batchOnNextTick.ts
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
* @
|
|
5
|
-
* @
|
|
6
|
-
* @
|
|
3
|
+
* Groups multiple calls by key and flushes them on the next tick (macrotask).
|
|
4
|
+
* @param onFlush - Function that will be called with the key and all queued items when flushing.
|
|
5
|
+
* @returns An object with `enqueue` and `flush` methods.
|
|
6
|
+
* @example
|
|
7
|
+
* const batcher = batchOnNextTick<string>(async (key, items) => {
|
|
8
|
+
* // items is an array of { args, resolve, reject }
|
|
9
|
+
* // do something once with all args...
|
|
10
|
+
* })
|
|
11
|
+
*
|
|
12
|
+
* batcher.enqueue("my-key", [arg1, arg2])
|
|
7
13
|
*/
|
|
8
|
-
function
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
*
|
|
13
|
-
* @
|
|
14
|
-
* @
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
function batchOnNextTick(onFlush) {
|
|
15
|
+
const queues = /* @__PURE__ */ new Map();
|
|
16
|
+
/**
|
|
17
|
+
* Enqueue a call with the given key and arguments.
|
|
18
|
+
* @param key key to group calls
|
|
19
|
+
* @param args arguments for the call
|
|
20
|
+
* @returns A promise that resolves or rejects when the call is flushed.
|
|
21
|
+
*/
|
|
22
|
+
function enqueue(key, args) {
|
|
23
|
+
return new Promise((resolve, reject) => {
|
|
24
|
+
let q = queues.get(key);
|
|
25
|
+
if (!q) {
|
|
26
|
+
q = {
|
|
27
|
+
timer: null,
|
|
28
|
+
items: [],
|
|
29
|
+
flush: () => flush(key)
|
|
30
|
+
};
|
|
31
|
+
queues.set(key, q);
|
|
32
|
+
}
|
|
33
|
+
q.items.push({
|
|
34
|
+
args,
|
|
35
|
+
resolve,
|
|
36
|
+
reject
|
|
37
|
+
});
|
|
38
|
+
if (q.timer == null) q.timer = setTimeout(() => {
|
|
39
|
+
q.timer = null;
|
|
40
|
+
q.flush();
|
|
41
|
+
}, 0);
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Flush the queue for the given key immediately.
|
|
46
|
+
* @param key key to flush
|
|
47
|
+
* @returns A promise that resolves when the flush is complete.
|
|
48
|
+
*/
|
|
49
|
+
async function flush(key) {
|
|
50
|
+
const q = queues.get(key);
|
|
51
|
+
if (!q || q.items.length === 0) return;
|
|
52
|
+
if (q.timer != null) {
|
|
53
|
+
clearTimeout(q.timer);
|
|
54
|
+
q.timer = null;
|
|
55
|
+
}
|
|
56
|
+
const items = q.items.splice(0);
|
|
57
|
+
onFlush(key, items.map((i) => i.args)).then((results) => {
|
|
58
|
+
for (const [index, result] of results.entries()) {
|
|
59
|
+
const { resolve } = items[index];
|
|
60
|
+
resolve(result);
|
|
61
|
+
}
|
|
62
|
+
}).catch((error) => {
|
|
63
|
+
for (const { reject } of items) reject(error);
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
return {
|
|
67
|
+
enqueue,
|
|
68
|
+
flush
|
|
69
|
+
};
|
|
19
70
|
}
|
|
20
71
|
//#endregion
|
|
21
|
-
exports.default =
|
|
72
|
+
exports.default = batchOnNextTick;
|
package/dist/index37.mjs
CHANGED
|
@@ -1,21 +1,72 @@
|
|
|
1
|
-
//#region src/utils/
|
|
1
|
+
//#region src/utils/batchOnNextTick.ts
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
* @
|
|
5
|
-
* @
|
|
6
|
-
* @
|
|
3
|
+
* Groups multiple calls by key and flushes them on the next tick (macrotask).
|
|
4
|
+
* @param onFlush - Function that will be called with the key and all queued items when flushing.
|
|
5
|
+
* @returns An object with `enqueue` and `flush` methods.
|
|
6
|
+
* @example
|
|
7
|
+
* const batcher = batchOnNextTick<string>(async (key, items) => {
|
|
8
|
+
* // items is an array of { args, resolve, reject }
|
|
9
|
+
* // do something once with all args...
|
|
10
|
+
* })
|
|
11
|
+
*
|
|
12
|
+
* batcher.enqueue("my-key", [arg1, arg2])
|
|
7
13
|
*/
|
|
8
|
-
function
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
*
|
|
13
|
-
* @
|
|
14
|
-
* @
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
function batchOnNextTick(onFlush) {
|
|
15
|
+
const queues = /* @__PURE__ */ new Map();
|
|
16
|
+
/**
|
|
17
|
+
* Enqueue a call with the given key and arguments.
|
|
18
|
+
* @param key key to group calls
|
|
19
|
+
* @param args arguments for the call
|
|
20
|
+
* @returns A promise that resolves or rejects when the call is flushed.
|
|
21
|
+
*/
|
|
22
|
+
function enqueue(key, args) {
|
|
23
|
+
return new Promise((resolve, reject) => {
|
|
24
|
+
let q = queues.get(key);
|
|
25
|
+
if (!q) {
|
|
26
|
+
q = {
|
|
27
|
+
timer: null,
|
|
28
|
+
items: [],
|
|
29
|
+
flush: () => flush(key)
|
|
30
|
+
};
|
|
31
|
+
queues.set(key, q);
|
|
32
|
+
}
|
|
33
|
+
q.items.push({
|
|
34
|
+
args,
|
|
35
|
+
resolve,
|
|
36
|
+
reject
|
|
37
|
+
});
|
|
38
|
+
if (q.timer == null) q.timer = setTimeout(() => {
|
|
39
|
+
q.timer = null;
|
|
40
|
+
q.flush();
|
|
41
|
+
}, 0);
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Flush the queue for the given key immediately.
|
|
46
|
+
* @param key key to flush
|
|
47
|
+
* @returns A promise that resolves when the flush is complete.
|
|
48
|
+
*/
|
|
49
|
+
async function flush(key) {
|
|
50
|
+
const q = queues.get(key);
|
|
51
|
+
if (!q || q.items.length === 0) return;
|
|
52
|
+
if (q.timer != null) {
|
|
53
|
+
clearTimeout(q.timer);
|
|
54
|
+
q.timer = null;
|
|
55
|
+
}
|
|
56
|
+
const items = q.items.splice(0);
|
|
57
|
+
onFlush(key, items.map((i) => i.args)).then((results) => {
|
|
58
|
+
for (const [index, result] of results.entries()) {
|
|
59
|
+
const { resolve } = items[index];
|
|
60
|
+
resolve(result);
|
|
61
|
+
}
|
|
62
|
+
}).catch((error) => {
|
|
63
|
+
for (const { reject } of items) reject(error);
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
return {
|
|
67
|
+
enqueue,
|
|
68
|
+
flush
|
|
69
|
+
};
|
|
19
70
|
}
|
|
20
71
|
//#endregion
|
|
21
|
-
export {
|
|
72
|
+
export { batchOnNextTick as default };
|