@signaldb/core 2.0.0-beta.13 → 2.0.0-beta.14

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.
Files changed (82) hide show
  1. package/dist/.vite/manifest.json +72 -46
  2. package/dist/AsyncDataAdapter.d.ts +11 -2
  3. package/dist/Collection/Cursor.d.ts +11 -1
  4. package/dist/Collection/Observer.d.ts +31 -0
  5. package/dist/DataAdapter.d.ts +15 -2
  6. package/dist/WorkerDataAdapter.d.ts +25 -2
  7. package/dist/WorkerDataAdapterHost.d.ts +2 -0
  8. package/dist/index.cjs.js +15 -15
  9. package/dist/index.d.ts +2 -0
  10. package/dist/index.mjs +15 -15
  11. package/dist/index10.cjs.js +7 -19
  12. package/dist/index10.mjs +7 -19
  13. package/dist/index11.cjs.js +19 -41
  14. package/dist/index11.mjs +19 -41
  15. package/dist/index12.cjs.js +41 -18
  16. package/dist/index12.mjs +41 -18
  17. package/dist/index13.cjs.js +18 -41
  18. package/dist/index13.mjs +18 -41
  19. package/dist/index14.cjs.js +39 -80
  20. package/dist/index14.mjs +39 -80
  21. package/dist/index15.cjs.js +82 -11
  22. package/dist/index15.mjs +82 -11
  23. package/dist/index16.cjs.js +11 -132
  24. package/dist/index16.mjs +11 -132
  25. package/dist/index17.cjs.js +127 -38
  26. package/dist/index17.mjs +127 -38
  27. package/dist/index18.cjs.js +43 -11
  28. package/dist/index18.mjs +43 -11
  29. package/dist/index19.cjs.js +10 -18
  30. package/dist/index19.mjs +11 -19
  31. package/dist/index20.cjs.js +19 -33
  32. package/dist/index20.mjs +19 -33
  33. package/dist/index21.cjs.js +33 -31
  34. package/dist/index21.mjs +33 -31
  35. package/dist/index22.cjs.js +31 -21
  36. package/dist/index22.mjs +31 -21
  37. package/dist/index23.cjs.js +16 -14
  38. package/dist/index23.mjs +16 -14
  39. package/dist/index24.cjs.js +15 -338
  40. package/dist/index24.mjs +15 -338
  41. package/dist/index25.cjs.js +122 -554
  42. package/dist/index25.mjs +121 -554
  43. package/dist/index26.cjs.js +34 -7
  44. package/dist/index26.mjs +34 -7
  45. package/dist/index27.cjs.js +339 -7
  46. package/dist/index27.mjs +339 -7
  47. package/dist/index28.cjs.js +550 -83
  48. package/dist/index28.mjs +550 -82
  49. package/dist/index29.cjs.js +8 -422
  50. package/dist/index29.mjs +8 -422
  51. package/dist/index30.cjs.js +7 -68
  52. package/dist/index30.mjs +7 -68
  53. package/dist/index31.cjs.js +86 -28
  54. package/dist/index31.mjs +85 -28
  55. package/dist/index32.cjs.js +446 -278
  56. package/dist/index32.mjs +446 -278
  57. package/dist/index33.cjs.js +68 -17
  58. package/dist/index33.mjs +68 -17
  59. package/dist/index34.cjs.js +460 -304
  60. package/dist/index34.mjs +460 -304
  61. package/dist/index35.cjs.js +14 -532
  62. package/dist/index35.mjs +14 -532
  63. package/dist/index36.cjs.js +389 -0
  64. package/dist/index36.mjs +389 -0
  65. package/dist/index37.cjs.js +539 -0
  66. package/dist/index37.mjs +539 -0
  67. package/dist/index4.cjs.js +199 -140
  68. package/dist/index4.mjs +195 -140
  69. package/dist/index5.cjs.js +152 -253
  70. package/dist/index5.mjs +152 -253
  71. package/dist/index6.cjs.js +267 -89
  72. package/dist/index6.mjs +267 -89
  73. package/dist/index7.cjs.js +121 -29
  74. package/dist/index7.mjs +121 -29
  75. package/dist/index8.cjs.js +29 -8
  76. package/dist/index8.mjs +29 -8
  77. package/dist/index9.cjs.js +8 -7
  78. package/dist/index9.mjs +8 -7
  79. package/dist/utils/incrementalQueryUpdate.d.ts +60 -0
  80. package/dist/utils/projectItems.d.ts +12 -0
  81. package/dist/utils/queryDelta.d.ts +83 -0
  82. package/package.json +1 -1
@@ -1,21 +1,72 @@
1
- //#region src/utils/compact.ts
1
+ //#region src/utils/batchOnNextTick.ts
2
2
  /**
3
- * Checks if a value is truthy.
4
- * @template T - The type of the value.
5
- * @param value - The value to check.
6
- * @returns A boolean indicating if the value is truthy.
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 truthy(value) {
9
- return !!value;
10
- }
11
- /**
12
- * Filters out falsy values (`false`, `''`, `0`, `null`, `undefined`) from an array.
13
- * @template T - The type of the elements in the array.
14
- * @param array - The array to filter.
15
- * @returns A new array containing only the truthy values from the input array.
16
- */
17
- function compact(array) {
18
- return array.filter(truthy);
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 = compact;
72
+ exports.default = batchOnNextTick;
package/dist/index33.mjs CHANGED
@@ -1,21 +1,72 @@
1
- //#region src/utils/compact.ts
1
+ //#region src/utils/batchOnNextTick.ts
2
2
  /**
3
- * Checks if a value is truthy.
4
- * @template T - The type of the value.
5
- * @param value - The value to check.
6
- * @returns A boolean indicating if the value is truthy.
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 truthy(value) {
9
- return !!value;
10
- }
11
- /**
12
- * Filters out falsy values (`false`, `''`, `0`, `null`, `undefined`) from an array.
13
- * @template T - The type of the elements in the array.
14
- * @param array - The array to filter.
15
- * @returns A new array containing only the truthy values from the input array.
16
- */
17
- function compact(array) {
18
- return array.filter(truthy);
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 { compact as default };
72
+ export { batchOnNextTick as default };