@signaldb/core 1.7.1 → 2.0.0-beta.1

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 (93) hide show
  1. package/dist/.vite/manifest.json +138 -82
  2. package/dist/AsyncDataAdapter.d.ts +64 -0
  3. package/dist/AutoFetchDataAdapter.d.ts +112 -0
  4. package/dist/Collection/Cursor.d.ts +9 -9
  5. package/dist/Collection/Observer.d.ts +3 -2
  6. package/dist/Collection/index.d.ts +54 -46
  7. package/dist/Collection/types.d.ts +4 -9
  8. package/dist/DataAdapter.d.ts +34 -0
  9. package/dist/DefaultDataAdapter.d.ts +33 -0
  10. package/dist/WorkerDataAdapter.d.ts +25 -0
  11. package/dist/WorkerDataAdapterHost.d.ts +62 -0
  12. package/dist/createIndex.d.ts +7 -0
  13. package/dist/createStorageAdapter.d.ts +9 -0
  14. package/dist/{Collection/getIndexInfo.d.ts → getIndexInfo.d.ts} +17 -19
  15. package/dist/index.cjs.js +21 -17
  16. package/dist/index.cjs10.js +15 -26
  17. package/dist/index.cjs11.js +13 -10
  18. package/dist/index.cjs12.js +348 -3
  19. package/dist/index.cjs13.js +396 -110
  20. package/dist/index.cjs14.js +178 -68
  21. package/dist/index.cjs15.js +384 -8
  22. package/dist/index.cjs16.js +572 -20
  23. package/dist/index.cjs17.js +12 -4
  24. package/dist/index.cjs18.js +24 -5
  25. package/dist/index.cjs2.js +29 -32
  26. package/dist/index.cjs20.js +5 -13
  27. package/dist/index.cjs21.js +99 -21
  28. package/dist/index.cjs22.js +108 -58
  29. package/dist/index.cjs23.js +5 -82
  30. package/dist/index.cjs24.js +23 -14
  31. package/dist/index.cjs25.js +8 -27
  32. package/dist/index.cjs26.js +27 -7
  33. package/dist/index.cjs27.js +44 -5
  34. package/dist/index.cjs28.js +6 -27
  35. package/dist/index.cjs29.js +7 -40
  36. package/dist/index.cjs3.js +198 -444
  37. package/dist/index.cjs30.js +5 -0
  38. package/dist/index.cjs31.js +7 -0
  39. package/dist/index.cjs32.js +29 -0
  40. package/dist/index.cjs33.js +42 -0
  41. package/dist/index.cjs4.js +3 -165
  42. package/dist/index.cjs5.js +3 -66
  43. package/dist/index.cjs6.js +27 -3
  44. package/dist/index.cjs7.js +10 -3
  45. package/dist/index.cjs8.js +3 -3
  46. package/dist/index.cjs9.js +131 -3
  47. package/dist/index.d.ts +11 -8
  48. package/dist/index.mjs +15 -11
  49. package/dist/index10.mjs +15 -26
  50. package/dist/index11.mjs +13 -10
  51. package/dist/index12.mjs +348 -3
  52. package/dist/index13.mjs +396 -110
  53. package/dist/index14.mjs +178 -67
  54. package/dist/index15.mjs +384 -8
  55. package/dist/index16.mjs +572 -20
  56. package/dist/index17.mjs +12 -4
  57. package/dist/index18.mjs +24 -5
  58. package/dist/index2.mjs +29 -32
  59. package/dist/index20.mjs +5 -13
  60. package/dist/index21.mjs +99 -21
  61. package/dist/index22.mjs +108 -58
  62. package/dist/index23.mjs +5 -81
  63. package/dist/index24.mjs +23 -14
  64. package/dist/index25.mjs +8 -27
  65. package/dist/index26.mjs +27 -7
  66. package/dist/index27.mjs +44 -5
  67. package/dist/index28.mjs +6 -27
  68. package/dist/index29.mjs +7 -40
  69. package/dist/index3.mjs +198 -445
  70. package/dist/index30.mjs +6 -0
  71. package/dist/index31.mjs +8 -0
  72. package/dist/index32.mjs +30 -0
  73. package/dist/index33.mjs +43 -0
  74. package/dist/index4.mjs +3 -165
  75. package/dist/index5.mjs +3 -65
  76. package/dist/index6.mjs +27 -3
  77. package/dist/index7.mjs +10 -3
  78. package/dist/index8.mjs +3 -3
  79. package/dist/index9.mjs +131 -3
  80. package/dist/types/IndexProvider.d.ts +12 -7
  81. package/dist/types/StorageAdapter.d.ts +20 -0
  82. package/dist/utils/batchOnNextTick.d.ts +16 -0
  83. package/dist/utils/objectId.d.ts +8 -0
  84. package/dist/utils/queryId.d.ts +9 -0
  85. package/package.json +1 -1
  86. package/dist/AutoFetchCollection.d.ts +0 -60
  87. package/dist/Collection/createIndex.d.ts +0 -15
  88. package/dist/ReplicatedCollection.d.ts +0 -60
  89. package/dist/createMemoryAdapter.d.ts +0 -7
  90. package/dist/persistence/combinePersistenceAdapters.d.ts +0 -32
  91. package/dist/persistence/createPersistenceAdapter.d.ts +0 -9
  92. package/dist/types/MemoryAdapter.d.ts +0 -15
  93. package/dist/types/PersistenceAdapter.d.ts +0 -20
@@ -1,9 +1,29 @@
1
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
- });
2
+ const isFieldExpression = require("./index.cjs33.js");
3
+ const serializeValue = require("./index.cjs11.js");
4
+ function getMatchingKeys(field, selector) {
5
+ const result = { include: null, exclude: null };
6
+ const fieldSelector = selector[field];
7
+ if (fieldSelector instanceof RegExp)
8
+ return result;
9
+ if (fieldSelector == null)
10
+ return result;
11
+ if (isFieldExpression(fieldSelector)) {
12
+ if (fieldSelector.$ne != null) {
13
+ result.exclude = [serializeValue(fieldSelector.$ne)];
14
+ return result;
15
+ }
16
+ if (Array.isArray(fieldSelector.$in) && fieldSelector.$in.length > 0) {
17
+ result.include = fieldSelector.$in.map(serializeValue);
18
+ return result;
19
+ }
20
+ if (Array.isArray(fieldSelector.$nin) && fieldSelector.$nin.length > 0) {
21
+ result.exclude = fieldSelector.$nin.map(serializeValue);
22
+ return result;
23
+ }
24
+ return { include: null, exclude: null };
25
+ }
26
+ result.include = [serializeValue(fieldSelector)];
27
+ return result;
8
28
  }
9
- module.exports = uniqueBy;
29
+ module.exports = getMatchingKeys;
@@ -1,7 +1,46 @@
1
1
  "use strict";
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))))];
2
+ function batchOnNextTick(onFlush) {
3
+ const queues = /* @__PURE__ */ new Map();
4
+ function enqueue(key, args) {
5
+ return new Promise((resolve, reject) => {
6
+ let q = queues.get(key);
7
+ if (!q) {
8
+ q = {
9
+ timer: null,
10
+ items: [],
11
+ flush: () => flush(key)
12
+ };
13
+ queues.set(key, q);
14
+ }
15
+ q.items.push({ args, resolve, reject });
16
+ if (q.timer == null) {
17
+ q.timer = setTimeout(() => {
18
+ q.timer = null;
19
+ void q.flush();
20
+ }, 0);
21
+ }
22
+ });
23
+ }
24
+ async function flush(key) {
25
+ const q = queues.get(key);
26
+ if (!q || q.items.length === 0)
27
+ return;
28
+ if (q.timer != null) {
29
+ clearTimeout(q.timer);
30
+ q.timer = null;
31
+ }
32
+ const items = q.items.splice(0);
33
+ onFlush(key, items.map((i) => i.args)).then((results) => {
34
+ for (const [index, result] of results.entries()) {
35
+ const { resolve } = items[index];
36
+ resolve(result);
37
+ }
38
+ }).catch((error) => {
39
+ for (const { reject } of items) {
40
+ reject(error);
41
+ }
42
+ });
43
+ }
44
+ return { enqueue, flush };
6
45
  }
7
- module.exports = intersection;
46
+ module.exports = batchOnNextTick;
@@ -1,29 +1,8 @@
1
1
  "use strict";
2
- const isFieldExpression = require("./index.cjs29.js");
3
- const serializeValue = require("./index.cjs20.js");
4
- function getMatchingKeys(field, selector) {
5
- const result = { include: null, exclude: null };
6
- const fieldSelector = selector[field];
7
- if (fieldSelector instanceof RegExp)
8
- return result;
9
- if (fieldSelector == null)
10
- return result;
11
- if (isFieldExpression(fieldSelector)) {
12
- if (fieldSelector.$ne != null) {
13
- result.exclude = [serializeValue(fieldSelector.$ne)];
14
- return result;
15
- }
16
- if (Array.isArray(fieldSelector.$in) && fieldSelector.$in.length > 0) {
17
- result.include = fieldSelector.$in.map(serializeValue);
18
- return result;
19
- }
20
- if (Array.isArray(fieldSelector.$nin) && fieldSelector.$nin.length > 0) {
21
- result.exclude = fieldSelector.$nin.map(serializeValue);
22
- return result;
23
- }
24
- return { include: null, exclude: null };
25
- }
26
- result.include = [serializeValue(fieldSelector)];
27
- return result;
2
+ function truthy(value) {
3
+ return !!value;
28
4
  }
29
- module.exports = getMatchingKeys;
5
+ function compact(array) {
6
+ return array.filter(truthy);
7
+ }
8
+ module.exports = compact;
@@ -1,42 +1,9 @@
1
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;
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
+ });
41
8
  }
42
- module.exports = isFieldExpression;
9
+ module.exports = uniqueBy;