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

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 (83) 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/Collection/index.d.ts +40 -0
  6. package/dist/DataAdapter.d.ts +15 -2
  7. package/dist/WorkerDataAdapter.d.ts +25 -2
  8. package/dist/WorkerDataAdapterHost.d.ts +2 -0
  9. package/dist/index.cjs.js +15 -15
  10. package/dist/index.d.ts +2 -0
  11. package/dist/index.mjs +15 -15
  12. package/dist/index10.cjs.js +7 -19
  13. package/dist/index10.mjs +7 -19
  14. package/dist/index11.cjs.js +19 -41
  15. package/dist/index11.mjs +19 -41
  16. package/dist/index12.cjs.js +41 -18
  17. package/dist/index12.mjs +41 -18
  18. package/dist/index13.cjs.js +18 -41
  19. package/dist/index13.mjs +18 -41
  20. package/dist/index14.cjs.js +39 -80
  21. package/dist/index14.mjs +39 -80
  22. package/dist/index15.cjs.js +82 -11
  23. package/dist/index15.mjs +82 -11
  24. package/dist/index16.cjs.js +11 -132
  25. package/dist/index16.mjs +11 -132
  26. package/dist/index17.cjs.js +127 -38
  27. package/dist/index17.mjs +127 -38
  28. package/dist/index18.cjs.js +43 -11
  29. package/dist/index18.mjs +43 -11
  30. package/dist/index19.cjs.js +10 -18
  31. package/dist/index19.mjs +11 -19
  32. package/dist/index20.cjs.js +19 -33
  33. package/dist/index20.mjs +19 -33
  34. package/dist/index21.cjs.js +33 -31
  35. package/dist/index21.mjs +33 -31
  36. package/dist/index22.cjs.js +31 -21
  37. package/dist/index22.mjs +31 -21
  38. package/dist/index23.cjs.js +16 -14
  39. package/dist/index23.mjs +16 -14
  40. package/dist/index24.cjs.js +15 -338
  41. package/dist/index24.mjs +15 -338
  42. package/dist/index25.cjs.js +122 -554
  43. package/dist/index25.mjs +121 -554
  44. package/dist/index26.cjs.js +34 -7
  45. package/dist/index26.mjs +34 -7
  46. package/dist/index27.cjs.js +339 -7
  47. package/dist/index27.mjs +339 -7
  48. package/dist/index28.cjs.js +595 -83
  49. package/dist/index28.mjs +595 -82
  50. package/dist/index29.cjs.js +8 -422
  51. package/dist/index29.mjs +8 -422
  52. package/dist/index30.cjs.js +7 -68
  53. package/dist/index30.mjs +7 -68
  54. package/dist/index31.cjs.js +86 -28
  55. package/dist/index31.mjs +85 -28
  56. package/dist/index32.cjs.js +446 -278
  57. package/dist/index32.mjs +446 -278
  58. package/dist/index33.cjs.js +68 -17
  59. package/dist/index33.mjs +68 -17
  60. package/dist/index34.cjs.js +460 -304
  61. package/dist/index34.mjs +460 -304
  62. package/dist/index35.cjs.js +14 -532
  63. package/dist/index35.mjs +14 -532
  64. package/dist/index36.cjs.js +389 -0
  65. package/dist/index36.mjs +389 -0
  66. package/dist/index37.cjs.js +539 -0
  67. package/dist/index37.mjs +539 -0
  68. package/dist/index4.cjs.js +199 -140
  69. package/dist/index4.mjs +195 -140
  70. package/dist/index5.cjs.js +152 -253
  71. package/dist/index5.mjs +152 -253
  72. package/dist/index6.cjs.js +267 -89
  73. package/dist/index6.mjs +267 -89
  74. package/dist/index7.cjs.js +121 -29
  75. package/dist/index7.mjs +121 -29
  76. package/dist/index8.cjs.js +29 -8
  77. package/dist/index8.mjs +29 -8
  78. package/dist/index9.cjs.js +8 -7
  79. package/dist/index9.mjs +8 -7
  80. package/dist/utils/incrementalQueryUpdate.d.ts +60 -0
  81. package/dist/utils/projectItems.d.ts +12 -0
  82. package/dist/utils/queryDelta.d.ts +83 -0
  83. package/package.json +1 -1
package/dist/index20.mjs CHANGED
@@ -1,37 +1,23 @@
1
- //#region src/utils/set.ts
1
+ import deepClone from "./index18.mjs";
2
+ import { update } from "mingo";
3
+ //#region src/utils/modify.ts
2
4
  /**
3
- * Sets a value at a specified path within an object. Creates nested structures
4
- * (arrays or objects) as needed to set the value at the correct location. Supports
5
- * deleting the key if the value is `undefined` and the `deleteIfUndefined` flag is set to `true`.
6
- * @template T - The type of the object to modify.
7
- * @template K - The type of the value to set.
8
- * @param object - The object to modify. The object is mutated directly.
9
- * @param path - The path (dot or bracket notation) where the value should be set.
10
- * @param value - The value to set at the specified path.
11
- * @param deleteIfUndefined - A boolean indicating whether to delete the key if the value is `undefined` (default: `false`).
12
- * @returns The modified object.
5
+ * Applies a modifier to an object and returns a new modified object.
6
+ * @template T - The type of the object to be modified.
7
+ * @param item - The object to be modified.
8
+ * @param modifier - The modifier to apply. This can be any transformation logic.
9
+ * @returns - Returns a new object with the modifications applied.
10
+ * @example
11
+ * const item = { a: 1, b: 2 }
12
+ * const modifier = { $set: { b: 3, c: 4 } }
13
+ * const result = modify(item, modifier)
14
+ * // result: { a: 1, b: 3, c: 4 }
13
15
  */
14
- function set(object, path, value, deleteIfUndefined = false) {
15
- if (object == null) return object;
16
- const segments = path.split(/[.[\]]/g);
17
- if (segments[0] === "") segments.shift();
18
- if (segments.at(-1) === "") segments.pop();
19
- const apply = (node) => {
20
- if (segments.length > 1) {
21
- const key = segments.shift();
22
- const nextIsNumber = !Number.isNaN(Number.parseInt(segments[0], 10));
23
- if (node[key] === void 0) node[key] = nextIsNumber ? [] : {};
24
- apply(node[key]);
25
- } else {
26
- if (deleteIfUndefined && value === void 0) {
27
- delete node[segments[0]];
28
- return;
29
- }
30
- node[segments[0]] = value;
31
- }
32
- };
33
- apply(object);
34
- return object;
16
+ function modify(item, modifier) {
17
+ if (!Object.keys(modifier).some((key) => key.startsWith("$"))) return modifier;
18
+ const clonedItem = deepClone(item);
19
+ update(clonedItem, modifier);
20
+ return clonedItem;
35
21
  }
36
22
  //#endregion
37
- export { set as default };
23
+ export { modify as default };
@@ -1,35 +1,37 @@
1
- const require_get = require("./index10.cjs.js");
2
- const require_set = require("./index20.cjs.js");
3
- //#region src/utils/project.ts
1
+ //#region src/utils/set.ts
4
2
  /**
5
- * Projects the fields of an object based on a specified fields configuration.
6
- * Supports inclusion (`1`) and exclusion (`0`) of specific fields. Creates a new object
7
- * with the desired fields included or excluded, based on the configuration.
8
- * @template T - The type of the object being projected.
9
- * @param item - The original object to project fields from.
10
- * @param fields - An object defining the fields to include (`1`) or exclude (`0`).
11
- * - Keys are the field names, and values are either `1` (include) or `0` (exclude).
12
- * @returns A new object with the specified fields included or excluded.
13
- * - If all fields are set to `0`, the excluded fields are removed from the result.
14
- * - If fields are set to `1`, only the included fields are retained.
3
+ * Sets a value at a specified path within an object. Creates nested structures
4
+ * (arrays or objects) as needed to set the value at the correct location. Supports
5
+ * deleting the key if the value is `undefined` and the `deleteIfUndefined` flag is set to `true`.
6
+ * @template T - The type of the object to modify.
7
+ * @template K - The type of the value to set.
8
+ * @param object - The object to modify. The object is mutated directly.
9
+ * @param path - The path (dot or bracket notation) where the value should be set.
10
+ * @param value - The value to set at the specified path.
11
+ * @param deleteIfUndefined - A boolean indicating whether to delete the key if the value is `undefined` (default: `false`).
12
+ * @returns The modified object.
15
13
  */
16
- function project(item, fields) {
17
- if (Object.values(fields).every((value) => value === 0)) {
18
- const result = { ...item };
19
- Object.keys(fields).forEach((key) => {
20
- if (require_get.default(item, key) === void 0) return;
21
- require_set.default(result, key, void 0, true);
22
- });
23
- return result;
24
- }
25
- const result = {};
26
- Object.entries(fields).forEach(([key, value]) => {
27
- const fieldValue = require_get.default(item, key);
28
- if (fieldValue === void 0) return;
29
- if (fieldValue == null && value !== 1) return;
30
- require_set.default(result, key, value === 1 ? fieldValue : void 0);
31
- });
32
- return result;
14
+ function set(object, path, value, deleteIfUndefined = false) {
15
+ if (object == null) return object;
16
+ const segments = path.split(/[.[\]]/g);
17
+ if (segments[0] === "") segments.shift();
18
+ if (segments.at(-1) === "") segments.pop();
19
+ const apply = (node) => {
20
+ if (segments.length > 1) {
21
+ const key = segments.shift();
22
+ const nextIsNumber = !Number.isNaN(Number.parseInt(segments[0], 10));
23
+ if (node[key] === void 0) node[key] = nextIsNumber ? [] : {};
24
+ apply(node[key]);
25
+ } else {
26
+ if (deleteIfUndefined && value === void 0) {
27
+ delete node[segments[0]];
28
+ return;
29
+ }
30
+ node[segments[0]] = value;
31
+ }
32
+ };
33
+ apply(object);
34
+ return object;
33
35
  }
34
36
  //#endregion
35
- exports.default = project;
37
+ exports.default = set;
package/dist/index21.mjs CHANGED
@@ -1,35 +1,37 @@
1
- import get from "./index10.mjs";
2
- import set from "./index20.mjs";
3
- //#region src/utils/project.ts
1
+ //#region src/utils/set.ts
4
2
  /**
5
- * Projects the fields of an object based on a specified fields configuration.
6
- * Supports inclusion (`1`) and exclusion (`0`) of specific fields. Creates a new object
7
- * with the desired fields included or excluded, based on the configuration.
8
- * @template T - The type of the object being projected.
9
- * @param item - The original object to project fields from.
10
- * @param fields - An object defining the fields to include (`1`) or exclude (`0`).
11
- * - Keys are the field names, and values are either `1` (include) or `0` (exclude).
12
- * @returns A new object with the specified fields included or excluded.
13
- * - If all fields are set to `0`, the excluded fields are removed from the result.
14
- * - If fields are set to `1`, only the included fields are retained.
3
+ * Sets a value at a specified path within an object. Creates nested structures
4
+ * (arrays or objects) as needed to set the value at the correct location. Supports
5
+ * deleting the key if the value is `undefined` and the `deleteIfUndefined` flag is set to `true`.
6
+ * @template T - The type of the object to modify.
7
+ * @template K - The type of the value to set.
8
+ * @param object - The object to modify. The object is mutated directly.
9
+ * @param path - The path (dot or bracket notation) where the value should be set.
10
+ * @param value - The value to set at the specified path.
11
+ * @param deleteIfUndefined - A boolean indicating whether to delete the key if the value is `undefined` (default: `false`).
12
+ * @returns The modified object.
15
13
  */
16
- function project(item, fields) {
17
- if (Object.values(fields).every((value) => value === 0)) {
18
- const result = { ...item };
19
- Object.keys(fields).forEach((key) => {
20
- if (get(item, key) === void 0) return;
21
- set(result, key, void 0, true);
22
- });
23
- return result;
24
- }
25
- const result = {};
26
- Object.entries(fields).forEach(([key, value]) => {
27
- const fieldValue = get(item, key);
28
- if (fieldValue === void 0) return;
29
- if (fieldValue == null && value !== 1) return;
30
- set(result, key, value === 1 ? fieldValue : void 0);
31
- });
32
- return result;
14
+ function set(object, path, value, deleteIfUndefined = false) {
15
+ if (object == null) return object;
16
+ const segments = path.split(/[.[\]]/g);
17
+ if (segments[0] === "") segments.shift();
18
+ if (segments.at(-1) === "") segments.pop();
19
+ const apply = (node) => {
20
+ if (segments.length > 1) {
21
+ const key = segments.shift();
22
+ const nextIsNumber = !Number.isNaN(Number.parseInt(segments[0], 10));
23
+ if (node[key] === void 0) node[key] = nextIsNumber ? [] : {};
24
+ apply(node[key]);
25
+ } else {
26
+ if (deleteIfUndefined && value === void 0) {
27
+ delete node[segments[0]];
28
+ return;
29
+ }
30
+ node[segments[0]] = value;
31
+ }
32
+ };
33
+ apply(object);
34
+ return object;
33
35
  }
34
36
  //#endregion
35
- export { project as default };
37
+ export { set as default };
@@ -1,25 +1,35 @@
1
- //#region src/utils/queryId.ts
1
+ const require_get = require("./index11.cjs.js");
2
+ const require_set = require("./index21.cjs.js");
3
+ //#region src/utils/project.ts
2
4
  /**
3
- * Returns true when `options` is effectively "empty" for the purpose of queryId generation.
4
- * Treats `undefined`/`null` as empty, and only considers plain objects with zero own enumerable keys as empty.
5
- * Arrays and non-object values are not considered empty.
6
- * @param options - Query options to test.
7
- * @returns `true` if `options` is `null`/`undefined` or a plain object with no own keys; otherwise `false`.
5
+ * Projects the fields of an object based on a specified fields configuration.
6
+ * Supports inclusion (`1`) and exclusion (`0`) of specific fields. Creates a new object
7
+ * with the desired fields included or excluded, based on the configuration.
8
+ * @template T - The type of the object being projected.
9
+ * @param item - The original object to project fields from.
10
+ * @param fields - An object defining the fields to include (`1`) or exclude (`0`).
11
+ * - Keys are the field names, and values are either `1` (include) or `0` (exclude).
12
+ * @returns A new object with the specified fields included or excluded.
13
+ * - If all fields are set to `0`, the excluded fields are removed from the result.
14
+ * - If fields are set to `1`, only the included fields are retained.
8
15
  */
9
- function isEmptyOptions(options) {
10
- if (options == null) return true;
11
- if (typeof options !== "object") return false;
12
- if (Array.isArray(options)) return false;
13
- return Object.keys(options).length === 0;
14
- }
15
- /**
16
- * Generates a unique identifier for a query based on its selector and options.
17
- * @param selector - The selector object.
18
- * @param options - The query options object (optional).
19
- * @returns A unique identifier string for the query.
20
- */
21
- function queryId(selector, options) {
22
- return `${JSON.stringify(selector)}:${isEmptyOptions(options) ? -1 : JSON.stringify(options)}`;
16
+ function project(item, fields) {
17
+ if (Object.values(fields).every((value) => value === 0)) {
18
+ const result = { ...item };
19
+ Object.keys(fields).forEach((key) => {
20
+ if (require_get.default(item, key) === void 0) return;
21
+ require_set.default(result, key, void 0, true);
22
+ });
23
+ return result;
24
+ }
25
+ const result = {};
26
+ Object.entries(fields).forEach(([key, value]) => {
27
+ const fieldValue = require_get.default(item, key);
28
+ if (fieldValue === void 0) return;
29
+ if (fieldValue == null && value !== 1) return;
30
+ require_set.default(result, key, value === 1 ? fieldValue : void 0);
31
+ });
32
+ return result;
23
33
  }
24
34
  //#endregion
25
- exports.default = queryId;
35
+ exports.default = project;
package/dist/index22.mjs CHANGED
@@ -1,25 +1,35 @@
1
- //#region src/utils/queryId.ts
1
+ import get from "./index11.mjs";
2
+ import set from "./index21.mjs";
3
+ //#region src/utils/project.ts
2
4
  /**
3
- * Returns true when `options` is effectively "empty" for the purpose of queryId generation.
4
- * Treats `undefined`/`null` as empty, and only considers plain objects with zero own enumerable keys as empty.
5
- * Arrays and non-object values are not considered empty.
6
- * @param options - Query options to test.
7
- * @returns `true` if `options` is `null`/`undefined` or a plain object with no own keys; otherwise `false`.
5
+ * Projects the fields of an object based on a specified fields configuration.
6
+ * Supports inclusion (`1`) and exclusion (`0`) of specific fields. Creates a new object
7
+ * with the desired fields included or excluded, based on the configuration.
8
+ * @template T - The type of the object being projected.
9
+ * @param item - The original object to project fields from.
10
+ * @param fields - An object defining the fields to include (`1`) or exclude (`0`).
11
+ * - Keys are the field names, and values are either `1` (include) or `0` (exclude).
12
+ * @returns A new object with the specified fields included or excluded.
13
+ * - If all fields are set to `0`, the excluded fields are removed from the result.
14
+ * - If fields are set to `1`, only the included fields are retained.
8
15
  */
9
- function isEmptyOptions(options) {
10
- if (options == null) return true;
11
- if (typeof options !== "object") return false;
12
- if (Array.isArray(options)) return false;
13
- return Object.keys(options).length === 0;
14
- }
15
- /**
16
- * Generates a unique identifier for a query based on its selector and options.
17
- * @param selector - The selector object.
18
- * @param options - The query options object (optional).
19
- * @returns A unique identifier string for the query.
20
- */
21
- function queryId(selector, options) {
22
- return `${JSON.stringify(selector)}:${isEmptyOptions(options) ? -1 : JSON.stringify(options)}`;
16
+ function project(item, fields) {
17
+ if (Object.values(fields).every((value) => value === 0)) {
18
+ const result = { ...item };
19
+ Object.keys(fields).forEach((key) => {
20
+ if (get(item, key) === void 0) return;
21
+ set(result, key, void 0, true);
22
+ });
23
+ return result;
24
+ }
25
+ const result = {};
26
+ Object.entries(fields).forEach(([key, value]) => {
27
+ const fieldValue = get(item, key);
28
+ if (fieldValue === void 0) return;
29
+ if (fieldValue == null && value !== 1) return;
30
+ set(result, key, value === 1 ? fieldValue : void 0);
31
+ });
32
+ return result;
23
33
  }
24
34
  //#endregion
25
- export { queryId as default };
35
+ export { project as default };
@@ -1,19 +1,21 @@
1
- const require_get = require("./index10.cjs.js");
2
- let fast_sort = require("fast-sort");
3
- //#region src/utils/sortItems.ts
1
+ const require_project = require("./index22.cjs.js");
2
+ //#region src/utils/projectItems.ts
4
3
  /**
5
- * Sorts an array of items based on multiple fields and their specified sort order.
6
- * Uses the `fast-sort` library for efficient sorting.
7
- * @template T - The type of the items in the array.
8
- * @param items - The array of items to be sorted.
9
- * @param sortFields - An object defining the sort order for each field.
10
- * - Keys are the field names, and values are either `1` (ascending) or `-1` (descending).
11
- * @returns A new array of items sorted based on the specified fields and their order.
4
+ * Applies a query's field projection to a list of items, keeping the primary key unless the
5
+ * projection excludes it outright. Returns the items untouched when there is no projection, so a
6
+ * caller does not have to check for one first.
7
+ * @template T - The type of the items.
8
+ * @param items - The items to project.
9
+ * @param fields - The projection, or `undefined` for none.
10
+ * @returns The projected items.
12
11
  */
13
- function sortItems(items, sortFields) {
14
- return (0, fast_sort.sort)(items).by(Object.entries(sortFields).map(([key, value]) => {
15
- return { [value === 1 ? "asc" : "desc"]: (i) => require_get.default(i, key) };
12
+ function projectItems(items, fields) {
13
+ if (!fields) return items;
14
+ const idExcluded = fields.id === 0;
15
+ return items.map((item) => ({
16
+ ...idExcluded ? {} : { id: item.id },
17
+ ...require_project.default(item, fields)
16
18
  }));
17
19
  }
18
20
  //#endregion
19
- exports.default = sortItems;
21
+ exports.default = projectItems;
package/dist/index23.mjs CHANGED
@@ -1,19 +1,21 @@
1
- import get from "./index10.mjs";
2
- import { sort } from "fast-sort";
3
- //#region src/utils/sortItems.ts
1
+ import project from "./index22.mjs";
2
+ //#region src/utils/projectItems.ts
4
3
  /**
5
- * Sorts an array of items based on multiple fields and their specified sort order.
6
- * Uses the `fast-sort` library for efficient sorting.
7
- * @template T - The type of the items in the array.
8
- * @param items - The array of items to be sorted.
9
- * @param sortFields - An object defining the sort order for each field.
10
- * - Keys are the field names, and values are either `1` (ascending) or `-1` (descending).
11
- * @returns A new array of items sorted based on the specified fields and their order.
4
+ * Applies a query's field projection to a list of items, keeping the primary key unless the
5
+ * projection excludes it outright. Returns the items untouched when there is no projection, so a
6
+ * caller does not have to check for one first.
7
+ * @template T - The type of the items.
8
+ * @param items - The items to project.
9
+ * @param fields - The projection, or `undefined` for none.
10
+ * @returns The projected items.
12
11
  */
13
- function sortItems(items, sortFields) {
14
- return sort(items).by(Object.entries(sortFields).map(([key, value]) => {
15
- return { [value === 1 ? "asc" : "desc"]: (i) => get(i, key) };
12
+ function projectItems(items, fields) {
13
+ if (!fields) return items;
14
+ const idExcluded = fields.id === 0;
15
+ return items.map((item) => ({
16
+ ...idExcluded ? {} : { id: item.id },
17
+ ...project(item, fields)
16
18
  }));
17
19
  }
18
20
  //#endregion
19
- export { sortItems as default };
21
+ export { projectItems as default };