@signaldb/core 2.0.0-beta.2 → 2.0.0-beta.21

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 (145) hide show
  1. package/dist/.vite/manifest.json +183 -80
  2. package/dist/AsyncDataAdapter.d.ts +53 -7
  3. package/dist/AutoFetchDataAdapter.d.ts +4 -6
  4. package/dist/Collection/Cursor.d.ts +56 -4
  5. package/dist/Collection/Observer.d.ts +33 -0
  6. package/dist/Collection/index.d.ts +66 -19
  7. package/dist/Collection/types.d.ts +9 -2
  8. package/dist/DataAdapter.d.ts +24 -6
  9. package/dist/DefaultDataAdapter.d.ts +5 -5
  10. package/dist/WorkerDataAdapter.d.ts +57 -5
  11. package/dist/WorkerDataAdapterHost.d.ts +9 -7
  12. package/dist/createIndex.d.ts +2 -2
  13. package/dist/createIndexProvider.d.ts +2 -2
  14. package/dist/createReactivityAdapter.d.ts +2 -2
  15. package/dist/createStorageAdapter.d.ts +1 -1
  16. package/dist/getIndexInfo.d.ts +3 -4
  17. package/dist/index.cjs.js +33 -31
  18. package/dist/index.d.ts +6 -1
  19. package/dist/index.mjs +17 -32
  20. package/dist/index10.cjs.js +11 -0
  21. package/dist/index10.mjs +10 -18
  22. package/dist/index11.cjs.js +23 -0
  23. package/dist/index11.mjs +22 -15
  24. package/dist/index12.cjs.js +45 -0
  25. package/dist/index12.mjs +44 -353
  26. package/dist/index13.cjs.js +22 -0
  27. package/dist/index13.mjs +21 -419
  28. package/dist/index14.cjs.js +45 -0
  29. package/dist/index14.mjs +44 -206
  30. package/dist/index15.cjs.js +86 -0
  31. package/dist/index15.mjs +85 -388
  32. package/dist/index16.cjs.js +15 -0
  33. package/dist/index16.mjs +14 -579
  34. package/dist/index17.cjs.js +141 -0
  35. package/dist/index17.mjs +140 -152
  36. package/dist/index18.cjs.js +47 -0
  37. package/dist/index18.mjs +46 -26
  38. package/dist/index19.cjs.js +15 -0
  39. package/dist/index19.mjs +14 -41
  40. package/dist/index2.cjs.js +33 -0
  41. package/dist/index2.mjs +32 -258
  42. package/dist/index20.cjs.js +23 -0
  43. package/dist/index20.mjs +22 -16
  44. package/dist/index21.cjs.js +37 -0
  45. package/dist/index21.mjs +36 -104
  46. package/dist/index22.cjs.js +35 -0
  47. package/dist/index22.mjs +34 -128
  48. package/dist/index23.cjs.js +21 -0
  49. package/dist/index23.mjs +20 -7
  50. package/dist/index24.cjs.js +19 -0
  51. package/dist/index24.mjs +18 -27
  52. package/dist/index25.cjs.js +157 -0
  53. package/dist/index25.mjs +156 -11
  54. package/dist/index26.cjs.js +38 -0
  55. package/dist/index26.mjs +37 -29
  56. package/dist/index27.cjs.js +42 -0
  57. package/dist/index27.mjs +41 -46
  58. package/dist/index28.cjs.js +347 -0
  59. package/dist/index28.mjs +345 -7
  60. package/dist/index29.cjs.js +602 -0
  61. package/dist/index29.mjs +601 -7
  62. package/dist/index3.cjs.js +19 -0
  63. package/dist/index3.mjs +18 -556
  64. package/dist/index30.cjs.js +11 -0
  65. package/dist/index30.mjs +10 -42
  66. package/dist/index31.cjs.js +11 -0
  67. package/dist/index31.mjs +10 -29
  68. package/dist/index32.cjs.js +90 -0
  69. package/dist/index32.mjs +89 -10
  70. package/dist/index33.cjs.js +53 -0
  71. package/dist/index33.mjs +52 -5
  72. package/dist/index34.cjs.js +453 -0
  73. package/dist/index34.mjs +453 -0
  74. package/dist/index35.cjs.js +72 -0
  75. package/dist/index35.mjs +72 -0
  76. package/dist/index36.cjs.js +580 -0
  77. package/dist/index36.mjs +580 -0
  78. package/dist/index37.cjs.js +21 -0
  79. package/dist/index37.mjs +21 -0
  80. package/dist/index38.cjs.js +363 -0
  81. package/dist/index38.mjs +363 -0
  82. package/dist/index39.cjs.js +513 -0
  83. package/dist/index39.mjs +513 -0
  84. package/dist/index4.cjs.js +209 -0
  85. package/dist/index4.mjs +204 -5
  86. package/dist/index5.cjs.js +187 -0
  87. package/dist/index5.mjs +186 -5
  88. package/dist/index6.cjs.js +303 -0
  89. package/dist/index6.mjs +301 -28
  90. package/dist/index7.cjs.js +125 -0
  91. package/dist/index7.mjs +124 -12
  92. package/dist/index8.cjs.js +33 -0
  93. package/dist/index8.mjs +32 -5
  94. package/dist/index9.cjs.js +12 -0
  95. package/dist/index9.mjs +11 -133
  96. package/dist/types/IndexProvider.d.ts +2 -2
  97. package/dist/types/Modifier.d.ts +1 -1
  98. package/dist/types/ReactivityAdapter.d.ts +1 -1
  99. package/dist/types/StorageAdapter.d.ts +9 -1
  100. package/dist/utils/applyQueryOptions.d.ts +15 -0
  101. package/dist/utils/createSignal.d.ts +2 -2
  102. package/dist/utils/getMatchingKeys.d.ts +2 -2
  103. package/dist/utils/idIndexQuery.d.ts +20 -0
  104. package/dist/utils/incrementalQueryUpdate.d.ts +62 -0
  105. package/dist/utils/isFieldExpression.d.ts +1 -1
  106. package/dist/utils/match.d.ts +1 -1
  107. package/dist/utils/modify.d.ts +1 -1
  108. package/dist/utils/projectItems.d.ts +12 -0
  109. package/dist/utils/queryDelta.d.ts +83 -0
  110. package/dist/utils/queryId.d.ts +2 -2
  111. package/dist/utils/reactiveOrAsync.d.ts +59 -0
  112. package/dist/utils/storageIndexQuery.d.ts +20 -0
  113. package/package.json +1 -1
  114. package/dist/index.cjs10.js +0 -18
  115. package/dist/index.cjs11.js +0 -15
  116. package/dist/index.cjs12.js +0 -353
  117. package/dist/index.cjs13.js +0 -419
  118. package/dist/index.cjs14.js +0 -206
  119. package/dist/index.cjs15.js +0 -388
  120. package/dist/index.cjs16.js +0 -579
  121. package/dist/index.cjs17.js +0 -152
  122. package/dist/index.cjs18.js +0 -26
  123. package/dist/index.cjs19.js +0 -42
  124. package/dist/index.cjs2.js +0 -259
  125. package/dist/index.cjs20.js +0 -16
  126. package/dist/index.cjs21.js +0 -104
  127. package/dist/index.cjs22.js +0 -129
  128. package/dist/index.cjs23.js +0 -7
  129. package/dist/index.cjs24.js +0 -27
  130. package/dist/index.cjs25.js +0 -10
  131. package/dist/index.cjs26.js +0 -29
  132. package/dist/index.cjs27.js +0 -46
  133. package/dist/index.cjs28.js +0 -8
  134. package/dist/index.cjs29.js +0 -7
  135. package/dist/index.cjs3.js +0 -557
  136. package/dist/index.cjs30.js +0 -42
  137. package/dist/index.cjs31.js +0 -29
  138. package/dist/index.cjs32.js +0 -9
  139. package/dist/index.cjs33.js +0 -5
  140. package/dist/index.cjs4.js +0 -5
  141. package/dist/index.cjs5.js +0 -5
  142. package/dist/index.cjs6.js +0 -29
  143. package/dist/index.cjs7.js +0 -12
  144. package/dist/index.cjs8.js +0 -5
  145. package/dist/index.cjs9.js +0 -133
@@ -0,0 +1,90 @@
1
+ //#region src/utils/reactiveOrAsync.ts
2
+ /**
3
+ * A generator helper that makes TypeScript infer the “synchronous value type” for maybe-async expressions.
4
+ *
5
+ * Usage:
6
+ * const doc = yield* unwrap(Collection.findOne(...))
7
+ * const list = yield* unwrap(Collection.find(...).fetch())
8
+ *
9
+ * Runtime note:
10
+ * This does not “unwrap” Promises by itself. It yields the value/Promise to the runner and returns the
11
+ * value that the runner feeds back via `.next(...)`.
12
+ * @param value The value (or Promise of a value) to yield to the runner.
13
+ * @returns A generator that yields `value` and resolves to the runner-supplied unwrapped `T`.
14
+ */
15
+ function unwrap(value) {
16
+ return (function* () {
17
+ return yield value;
18
+ })();
19
+ }
20
+ /**
21
+ * Internal: checks for thenables (Promise-like).
22
+ * @param value The value to test.
23
+ * @returns `true` if `value` looks like a Promise/thenable.
24
+ */
25
+ function isThenable(value) {
26
+ return typeof value === "object" && value !== null && typeof value.then === "function";
27
+ }
28
+ /**
29
+ * Internal runner: executes a generator either synchronously (reactive) or asynchronously (imperative).
30
+ *
31
+ * - In sync mode, yielding a Promise is a programming error and throws.
32
+ * - In async mode, yielded Promises are awaited.
33
+ * @param thisArgument The `this` value to bind when invoking `gen`.
34
+ * @param mode Execution mode options.
35
+ * @param gen The generator workflow to run.
36
+ * @returns The workflow result (a plain value in sync mode, or a Promise in async mode).
37
+ */
38
+ function runReactiveOrAsync(thisArgument, mode, gen) {
39
+ const a = !!mode?.async;
40
+ const it = gen.call(thisArgument, a);
41
+ if (!a) {
42
+ let step = it.next();
43
+ while (!step.done) {
44
+ const y = step.value;
45
+ if (isThenable(y)) throw new Error("Promise yielded in sync flow");
46
+ step = it.next(y);
47
+ }
48
+ return step.value;
49
+ }
50
+ return (async function() {
51
+ let step = it.next();
52
+ while (!step.done) {
53
+ const y = step.value;
54
+ const v = isThenable(y) ? await y : y;
55
+ step = it.next(v);
56
+ }
57
+ return step.value;
58
+ })();
59
+ }
60
+ /**
61
+ * Factory that turns a generator workflow into a callable method that can run in sync (reactive) or async mode.
62
+ *
63
+ * Call style:
64
+ * fn(a, b) -> sync/reactive return
65
+ * await fn(a, b, { async: true }) -> async return
66
+ * @param gen Generator workflow. Receives `(a)` which indicates async mode and should `yield`/`yield* unwrap(...)`
67
+ * any values that may be Promises.
68
+ * @returns A callable method with overloads plus a `.generator` property for composition.
69
+ */
70
+ function reactiveOrAsync(gen) {
71
+ /**
72
+ * The generated method wrapper.
73
+ * @param allArguments Method arguments, optionally ending with a `ModeOptions` object.
74
+ * @returns The workflow result (sync) or a Promise of the result (async).
75
+ */
76
+ function method(...allArguments) {
77
+ const last = allArguments.length > 0 ? allArguments.at(-1) : void 0;
78
+ const hasMode = typeof last === "object" && last !== null && "async" in last;
79
+ const mode = hasMode ? last : void 0;
80
+ const parameters = hasMode ? allArguments.slice(0, -1) : allArguments;
81
+ return runReactiveOrAsync(this, mode, function* (a) {
82
+ return yield* gen.call(this, a, ...parameters);
83
+ });
84
+ }
85
+ method.generator = gen;
86
+ return method;
87
+ }
88
+ //#endregion
89
+ exports.default = reactiveOrAsync;
90
+ exports.unwrap = unwrap;
package/dist/index32.mjs CHANGED
@@ -1,10 +1,89 @@
1
- function uniqueBy(array, fn) {
2
- const set = /* @__PURE__ */ new Set();
3
- return array.filter((element) => {
4
- const value = typeof fn === "function" ? fn(element) : element[fn];
5
- return !set.has(value) && set.add(value);
6
- });
7
- }
8
- export {
9
- uniqueBy as default
10
- };
1
+ //#region src/utils/reactiveOrAsync.ts
2
+ /**
3
+ * A generator helper that makes TypeScript infer the “synchronous value type” for maybe-async expressions.
4
+ *
5
+ * Usage:
6
+ * const doc = yield* unwrap(Collection.findOne(...))
7
+ * const list = yield* unwrap(Collection.find(...).fetch())
8
+ *
9
+ * Runtime note:
10
+ * This does not “unwrap” Promises by itself. It yields the value/Promise to the runner and returns the
11
+ * value that the runner feeds back via `.next(...)`.
12
+ * @param value The value (or Promise of a value) to yield to the runner.
13
+ * @returns A generator that yields `value` and resolves to the runner-supplied unwrapped `T`.
14
+ */
15
+ function unwrap(value) {
16
+ return (function* () {
17
+ return yield value;
18
+ })();
19
+ }
20
+ /**
21
+ * Internal: checks for thenables (Promise-like).
22
+ * @param value The value to test.
23
+ * @returns `true` if `value` looks like a Promise/thenable.
24
+ */
25
+ function isThenable(value) {
26
+ return typeof value === "object" && value !== null && typeof value.then === "function";
27
+ }
28
+ /**
29
+ * Internal runner: executes a generator either synchronously (reactive) or asynchronously (imperative).
30
+ *
31
+ * - In sync mode, yielding a Promise is a programming error and throws.
32
+ * - In async mode, yielded Promises are awaited.
33
+ * @param thisArgument The `this` value to bind when invoking `gen`.
34
+ * @param mode Execution mode options.
35
+ * @param gen The generator workflow to run.
36
+ * @returns The workflow result (a plain value in sync mode, or a Promise in async mode).
37
+ */
38
+ function runReactiveOrAsync(thisArgument, mode, gen) {
39
+ const a = !!mode?.async;
40
+ const it = gen.call(thisArgument, a);
41
+ if (!a) {
42
+ let step = it.next();
43
+ while (!step.done) {
44
+ const y = step.value;
45
+ if (isThenable(y)) throw new Error("Promise yielded in sync flow");
46
+ step = it.next(y);
47
+ }
48
+ return step.value;
49
+ }
50
+ return (async function() {
51
+ let step = it.next();
52
+ while (!step.done) {
53
+ const y = step.value;
54
+ const v = isThenable(y) ? await y : y;
55
+ step = it.next(v);
56
+ }
57
+ return step.value;
58
+ })();
59
+ }
60
+ /**
61
+ * Factory that turns a generator workflow into a callable method that can run in sync (reactive) or async mode.
62
+ *
63
+ * Call style:
64
+ * fn(a, b) -> sync/reactive return
65
+ * await fn(a, b, { async: true }) -> async return
66
+ * @param gen Generator workflow. Receives `(a)` which indicates async mode and should `yield`/`yield* unwrap(...)`
67
+ * any values that may be Promises.
68
+ * @returns A callable method with overloads plus a `.generator` property for composition.
69
+ */
70
+ function reactiveOrAsync(gen) {
71
+ /**
72
+ * The generated method wrapper.
73
+ * @param allArguments Method arguments, optionally ending with a `ModeOptions` object.
74
+ * @returns The workflow result (sync) or a Promise of the result (async).
75
+ */
76
+ function method(...allArguments) {
77
+ const last = allArguments.length > 0 ? allArguments.at(-1) : void 0;
78
+ const hasMode = typeof last === "object" && last !== null && "async" in last;
79
+ const mode = hasMode ? last : void 0;
80
+ const parameters = hasMode ? allArguments.slice(0, -1) : allArguments;
81
+ return runReactiveOrAsync(this, mode, function* (a) {
82
+ return yield* gen.call(this, a, ...parameters);
83
+ });
84
+ }
85
+ method.generator = gen;
86
+ return method;
87
+ }
88
+ //#endregion
89
+ export { reactiveOrAsync as default, unwrap };
@@ -0,0 +1,53 @@
1
+ const require_getMatchingKeys = require("./index14.cjs.js");
2
+ //#region src/utils/storageIndexQuery.ts
3
+ /**
4
+ * Builds the index provider a data adapter uses to narrow a selector down through
5
+ * a storage adapter's index.
6
+ *
7
+ * Every adapter that keeps its data in a `StorageAdapter` needs exactly this, and
8
+ * each of them used to carry its own copy — three transcriptions of one set of
9
+ * rules about null, `$exists`, inclusion and exclusion, which is how they drift
10
+ * apart without anyone noticing. The index is keyed by `serializeValue(value)`,
11
+ * which is what `getMatchingKeys` produces, so the two only agree while they stay
12
+ * in one place.
13
+ * @template T - The type of the items in the collection.
14
+ * @template I - The type of the unique identifier for the items.
15
+ * @param storage - The storage adapter holding the index.
16
+ * @param field - The indexed field this provider answers for.
17
+ * @returns A query function for `getIndexInfo`.
18
+ */
19
+ function storageIndexQuery(storage, field) {
20
+ return async (flatSelector) => {
21
+ if (!Object.hasOwnProperty.call(flatSelector, field)) return { matched: false };
22
+ const index = await storage.readIndex(field);
23
+ const fieldSelector = flatSelector[field];
24
+ const filtersForNull = fieldSelector == null || fieldSelector.$exists === false;
25
+ const keys = filtersForNull ? {
26
+ include: null,
27
+ exclude: [...index.keys()].filter((key) => key != null)
28
+ } : require_getMatchingKeys.default(field, flatSelector);
29
+ if (keys.include == null && keys.exclude == null) return { matched: false };
30
+ let includedIds = [];
31
+ if (keys.include == null) for (const set of index.values()) for (const id of set) includedIds.push(id);
32
+ else for (const key of keys.include) {
33
+ const idSet = index.get(key);
34
+ if (idSet) for (const id of idSet) includedIds.push(id);
35
+ }
36
+ if (keys.exclude != null) {
37
+ const excludedIds = /* @__PURE__ */ new Set();
38
+ for (const key of keys.exclude) {
39
+ const idSet = index.get(key);
40
+ if (idSet) for (const id of idSet) excludedIds.add(id);
41
+ }
42
+ includedIds = includedIds.filter((id) => !excludedIds.has(id));
43
+ }
44
+ return {
45
+ matched: true,
46
+ ids: includedIds,
47
+ fields: [field],
48
+ keepSelector: filtersForNull
49
+ };
50
+ };
51
+ }
52
+ //#endregion
53
+ exports.default = storageIndexQuery;
package/dist/index33.mjs CHANGED
@@ -1,6 +1,53 @@
1
- function createIndexProvider(definition) {
2
- return definition;
1
+ import getMatchingKeys from "./index14.mjs";
2
+ //#region src/utils/storageIndexQuery.ts
3
+ /**
4
+ * Builds the index provider a data adapter uses to narrow a selector down through
5
+ * a storage adapter's index.
6
+ *
7
+ * Every adapter that keeps its data in a `StorageAdapter` needs exactly this, and
8
+ * each of them used to carry its own copy — three transcriptions of one set of
9
+ * rules about null, `$exists`, inclusion and exclusion, which is how they drift
10
+ * apart without anyone noticing. The index is keyed by `serializeValue(value)`,
11
+ * which is what `getMatchingKeys` produces, so the two only agree while they stay
12
+ * in one place.
13
+ * @template T - The type of the items in the collection.
14
+ * @template I - The type of the unique identifier for the items.
15
+ * @param storage - The storage adapter holding the index.
16
+ * @param field - The indexed field this provider answers for.
17
+ * @returns A query function for `getIndexInfo`.
18
+ */
19
+ function storageIndexQuery(storage, field) {
20
+ return async (flatSelector) => {
21
+ if (!Object.hasOwnProperty.call(flatSelector, field)) return { matched: false };
22
+ const index = await storage.readIndex(field);
23
+ const fieldSelector = flatSelector[field];
24
+ const filtersForNull = fieldSelector == null || fieldSelector.$exists === false;
25
+ const keys = filtersForNull ? {
26
+ include: null,
27
+ exclude: [...index.keys()].filter((key) => key != null)
28
+ } : getMatchingKeys(field, flatSelector);
29
+ if (keys.include == null && keys.exclude == null) return { matched: false };
30
+ let includedIds = [];
31
+ if (keys.include == null) for (const set of index.values()) for (const id of set) includedIds.push(id);
32
+ else for (const key of keys.include) {
33
+ const idSet = index.get(key);
34
+ if (idSet) for (const id of idSet) includedIds.push(id);
35
+ }
36
+ if (keys.exclude != null) {
37
+ const excludedIds = /* @__PURE__ */ new Set();
38
+ for (const key of keys.exclude) {
39
+ const idSet = index.get(key);
40
+ if (idSet) for (const id of idSet) excludedIds.add(id);
41
+ }
42
+ includedIds = includedIds.filter((id) => !excludedIds.has(id));
43
+ }
44
+ return {
45
+ matched: true,
46
+ ids: includedIds,
47
+ fields: [field],
48
+ keepSelector: filtersForNull
49
+ };
50
+ };
3
51
  }
4
- export {
5
- createIndexProvider as default
6
- };
52
+ //#endregion
53
+ export { storageIndexQuery as default };