@signaldb/core 1.5.4 → 1.7.0

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 (68) hide show
  1. package/dist/.vite/manifest.json +29 -28
  2. package/dist/Collection/createIndex.d.ts +1 -1
  3. package/dist/Collection/index.d.ts +1 -0
  4. package/dist/index.cjs.js +14 -12
  5. package/dist/index.cjs10.js +27 -10
  6. package/dist/index.cjs11.js +10 -3
  7. package/dist/index.cjs12.js +3 -136
  8. package/dist/index.cjs13.js +131 -61
  9. package/dist/index.cjs14.js +72 -5
  10. package/dist/index.cjs15.js +8 -41
  11. package/dist/index.cjs16.js +25 -11
  12. package/dist/index.cjs17.js +143 -23
  13. package/dist/index.cjs18.js +5 -262
  14. package/dist/index.cjs19.js +36 -63
  15. package/dist/index.cjs2.js +210 -732
  16. package/dist/index.cjs20.js +13 -85
  17. package/dist/index.cjs21.js +24 -8
  18. package/dist/index.cjs22.js +67 -24
  19. package/dist/index.cjs23.js +72 -131
  20. package/dist/index.cjs24.js +16 -5
  21. package/dist/index.cjs25.js +22 -11
  22. package/dist/index.cjs26.js +7 -27
  23. package/dist/index.cjs27.js +5 -40
  24. package/dist/index.cjs28.js +26 -26
  25. package/dist/index.cjs29.js +40 -7
  26. package/dist/index.cjs3.js +757 -136
  27. package/dist/index.cjs4.js +165 -62
  28. package/dist/index.cjs5.js +67 -3
  29. package/dist/index.cjs6.js +2 -2
  30. package/dist/index.cjs7.js +2 -2
  31. package/dist/index.cjs8.js +2 -2
  32. package/dist/index.cjs9.js +3 -27
  33. package/dist/index.d.ts +1 -0
  34. package/dist/index.mjs +14 -12
  35. package/dist/index10.mjs +27 -10
  36. package/dist/index11.mjs +10 -3
  37. package/dist/index12.mjs +3 -136
  38. package/dist/index13.mjs +131 -60
  39. package/dist/index14.mjs +71 -5
  40. package/dist/index15.mjs +8 -40
  41. package/dist/index16.mjs +25 -11
  42. package/dist/index17.mjs +143 -23
  43. package/dist/index18.mjs +5 -261
  44. package/dist/index19.mjs +36 -63
  45. package/dist/index2.mjs +210 -733
  46. package/dist/index20.mjs +13 -84
  47. package/dist/index21.mjs +24 -8
  48. package/dist/index22.mjs +66 -24
  49. package/dist/index23.mjs +71 -131
  50. package/dist/index24.mjs +16 -5
  51. package/dist/index25.mjs +22 -11
  52. package/dist/index26.mjs +7 -27
  53. package/dist/index27.mjs +5 -40
  54. package/dist/index28.mjs +26 -26
  55. package/dist/index29.mjs +40 -7
  56. package/dist/index3.mjs +757 -136
  57. package/dist/index4.mjs +165 -61
  58. package/dist/index5.mjs +66 -3
  59. package/dist/index6.mjs +2 -2
  60. package/dist/index7.mjs +2 -2
  61. package/dist/index8.mjs +2 -2
  62. package/dist/index9.mjs +3 -27
  63. package/dist/types/IndexProvider.d.ts +2 -0
  64. package/dist/types/Modifier.d.ts +17 -10
  65. package/dist/types/Selector.d.ts +1 -7
  66. package/dist/utils/getMatchingKeys.d.ts +2 -2
  67. package/dist/utils/serializeValue.d.ts +1 -1
  68. package/package.json +1 -1
package/dist/index20.mjs CHANGED
@@ -1,87 +1,16 @@
1
- var __defProp = Object.defineProperty;
2
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
- import Collection from "./index2.mjs";
5
- import combinePersistenceAdapters from "./index4.mjs";
6
- import createPersistenceAdapter from "./index7.mjs";
7
- import createSignal from "./index17.mjs";
8
- function createReplicationAdapter(options) {
9
- return createPersistenceAdapter({
10
- async register(onChange) {
11
- if (!options.registerRemoteChange)
12
- return;
13
- await options.registerRemoteChange(onChange);
14
- },
15
- load: () => options.pull(),
16
- save: (items, changes) => {
17
- if (!options.push)
18
- throw new Error("Pushing is not configured for this collection. Try to pass a `push` function to the collection options.");
19
- return options.push(changes, items);
20
- }
21
- });
22
- }
23
- class ReplicatedCollection extends Collection {
24
- /**
25
- * Creates a new instance of the `ReplicatedCollection` class.
26
- * Sets up the replication adapter, combining it with an optional persistence adapter, and
27
- * initializes signals for tracking remote pull and push operations.
28
- * @param options - The configuration options for the replicated collection.
29
- * @param options.pull - A function to fetch data from the remote source.
30
- * @param options.push - An optional function to send changes and items to the remote source.
31
- * @param options.registerRemoteChange - An optional function to register a listener for remote changes.
32
- * @param options.persistence - An optional persistence adapter to combine with replication.
33
- * @param options.reactivity - A reactivity adapter for observing changes in the collection.
34
- * @param options.transform - A transformation function to apply to items when retrieving them.
35
- * @param options.indices - An array of index providers for optimized querying.
36
- * @param options.enableDebugMode - A boolean to enable or disable debug mode.
37
- */
38
- constructor(options) {
39
- const replicationAdapter = createReplicationAdapter({
40
- registerRemoteChange: options.registerRemoteChange,
41
- pull: async () => {
42
- this.isPullingRemoteSignal.set(true);
43
- try {
44
- return await options.pull();
45
- } finally {
46
- this.isPullingRemoteSignal.set(false);
47
- }
48
- },
49
- push: options.push ? async (changes, items) => {
50
- if (!options.push)
51
- throw new Error("Pushing is not configured for this collection. Try to pass a `push` function to the collection options.");
52
- this.isPushingRemoteSignal.set(true);
53
- try {
54
- await options.push(changes, items);
55
- } finally {
56
- this.isPushingRemoteSignal.set(false);
57
- }
58
- } : void 0
59
- });
60
- const persistenceAdapter = (options == null ? void 0 : options.persistence) ? combinePersistenceAdapters(replicationAdapter, options.persistence) : replicationAdapter;
61
- super({
62
- ...options,
63
- persistence: persistenceAdapter
64
- });
65
- __publicField(this, "isPullingRemoteSignal");
66
- __publicField(this, "isPushingRemoteSignal");
67
- this.isPullingRemoteSignal = createSignal(options.reactivity, false);
68
- this.isPushingRemoteSignal = createSignal(options.reactivity, false);
69
- }
70
- /**
71
- * Checks whether the collection is currently performing any loading operation,
72
- * including pulling or pushing data from/to the remote source, or standard
73
- * persistence adapter operations.
74
- * ⚡️ this function is reactive!
75
- * @returns A boolean indicating if the collection is currently loading or synchronizing.
76
- */
77
- isLoading() {
78
- const isPullingRemote = this.isPullingRemoteSignal.get();
79
- const isPushingRemote = this.isPushingRemoteSignal.get();
80
- const isLoading = super.isLoading();
81
- return isPullingRemote || isPushingRemote || isLoading;
82
- }
1
+ function serializeValue(value) {
2
+ if (value == null)
3
+ return null;
4
+ if (typeof value === "string")
5
+ return value;
6
+ if (typeof value === "number")
7
+ return value.toString();
8
+ if (typeof value === "boolean")
9
+ return value.toString();
10
+ if (value instanceof Date)
11
+ return value.toISOString();
12
+ return JSON.stringify(value);
83
13
  }
84
14
  export {
85
- createReplicationAdapter,
86
- ReplicatedCollection as default
15
+ serializeValue as default
87
16
  };
package/dist/index21.mjs CHANGED
@@ -1,11 +1,27 @@
1
- import { sort } from "fast-sort";
2
- import get from "./index25.mjs";
3
- function sortItems(items, sortFields) {
4
- return sort(items).by(Object.entries(sortFields).map(([key, value]) => {
5
- const order = value === 1 ? "asc" : "desc";
6
- return { [order]: (i) => get(i, key) };
7
- }));
1
+ function createSignal(reactivityAdapter, initialValue, isEqual = Object.is) {
2
+ let value = initialValue;
3
+ const dependency = reactivityAdapter == null ? void 0 : reactivityAdapter.create();
4
+ const isInReactiveScope = () => {
5
+ if (!(reactivityAdapter == null ? void 0 : reactivityAdapter.isInScope))
6
+ return true;
7
+ return reactivityAdapter.isInScope();
8
+ };
9
+ const signal = {
10
+ get() {
11
+ if (dependency && isInReactiveScope())
12
+ dependency.depend();
13
+ return value;
14
+ },
15
+ set(newValue) {
16
+ if (isEqual(value, newValue))
17
+ return;
18
+ value = newValue;
19
+ if (dependency)
20
+ dependency.notify();
21
+ }
22
+ };
23
+ return signal;
8
24
  }
9
25
  export {
10
- sortItems as default
26
+ createSignal as default
11
27
  };
package/dist/index22.mjs CHANGED
@@ -1,28 +1,70 @@
1
- import get from "./index25.mjs";
2
- import set from "./index28.mjs";
3
- function project(item, fields) {
4
- const allFieldsDeactivated = Object.values(fields).every((value) => value === 0);
5
- if (allFieldsDeactivated) {
6
- const result2 = { ...item };
7
- Object.keys(fields).forEach((key) => {
8
- const fieldValue = get(item, key);
9
- if (fieldValue === void 0)
10
- return;
11
- set(result2, key, void 0, true);
12
- });
13
- return result2;
14
- }
15
- const result = {};
16
- Object.entries(fields).forEach(([key, value]) => {
17
- const fieldValue = get(item, key);
18
- if (fieldValue === void 0)
19
- return;
20
- if (fieldValue == null && value !== 1)
21
- return;
22
- set(result, key, value === 1 ? fieldValue : void 0);
1
+ import intersection from "./index27.mjs";
2
+ function getMergedIndexInfo(indexProviders, selector) {
3
+ return indexProviders.reduce((memo, indexProvider) => {
4
+ const info = indexProvider.query(selector);
5
+ if (!info.matched)
6
+ return memo;
7
+ const optimizedSelector = info.keepSelector ? memo.optimizedSelector : Object.fromEntries(Object.entries(memo.optimizedSelector).filter(([key]) => !info.fields.includes(key)));
8
+ return {
9
+ matched: true,
10
+ positions: [...new Set(memo.matched ? intersection(memo.positions, info.positions) : info.positions)],
11
+ optimizedSelector
12
+ };
13
+ }, {
14
+ matched: false,
15
+ positions: [],
16
+ optimizedSelector: { ...selector }
23
17
  });
24
- return result;
18
+ }
19
+ function getIndexInfo(indexProviders, selector) {
20
+ if (selector == null || Object.keys(selector).length <= 0) {
21
+ return { matched: false, positions: [], optimizedSelector: selector };
22
+ }
23
+ const { $and, $or, ...rest } = selector;
24
+ const flatInfo = getMergedIndexInfo(indexProviders, rest);
25
+ let { matched, positions } = flatInfo;
26
+ const newSelector = flatInfo.optimizedSelector;
27
+ if (Array.isArray($and)) {
28
+ const $andNew = [];
29
+ for (const sel of $and) {
30
+ const { matched: selMatched, positions: selPositions, optimizedSelector } = getIndexInfo(indexProviders, sel);
31
+ if (selMatched) {
32
+ positions = matched ? intersection(positions, selPositions) : selPositions;
33
+ matched = true;
34
+ if (Object.keys(optimizedSelector).length > 0) {
35
+ $andNew.push(optimizedSelector);
36
+ }
37
+ } else {
38
+ $andNew.push(sel);
39
+ }
40
+ }
41
+ if ($andNew.length > 0)
42
+ newSelector.$and = $andNew;
43
+ }
44
+ if (Array.isArray($or)) {
45
+ const $orNew = [];
46
+ for (const sel of $or) {
47
+ const { matched: selMatched, positions: selPositions, optimizedSelector } = getIndexInfo(indexProviders, sel);
48
+ if (selMatched) {
49
+ positions = [.../* @__PURE__ */ new Set([...positions, ...selPositions])];
50
+ matched = true;
51
+ if (Object.keys(optimizedSelector).length > 0) {
52
+ $orNew.push(optimizedSelector);
53
+ }
54
+ } else {
55
+ $orNew.push(sel);
56
+ }
57
+ }
58
+ if ($orNew.length > 0)
59
+ newSelector.$or = $orNew;
60
+ }
61
+ return {
62
+ matched,
63
+ positions: positions || [],
64
+ optimizedSelector: newSelector
65
+ };
25
66
  }
26
67
  export {
27
- project as default
68
+ getIndexInfo as default,
69
+ getMergedIndexInfo
28
70
  };
package/dist/index23.mjs CHANGED
@@ -1,147 +1,87 @@
1
1
  var __defProp = Object.defineProperty;
2
2
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
3
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
- import isEqual from "./index9.mjs";
5
- import uniqueBy from "./index29.mjs";
6
- class Observer {
7
- /**
8
- * Creates a new instance of the `Observer` class.
9
- * Sets up event bindings and initializes the callbacks for tracking changes in a collection.
10
- * @param bindEvents - A function to bind external events to the observer. Must return a cleanup function to unbind those events.
11
- */
12
- constructor(bindEvents) {
13
- __publicField(this, "previousItems", []);
14
- __publicField(this, "callbacks");
15
- __publicField(this, "unbindEvents");
16
- this.callbacks = {
17
- added: [],
18
- addedBefore: [],
19
- changed: [],
20
- changedField: [],
21
- movedBefore: [],
22
- removed: []
23
- };
24
- this.unbindEvents = bindEvents();
25
- }
26
- call(event, ...args) {
27
- this.callbacks[event].forEach(({ callback, options }) => {
28
- if (!options.skipInitial || !options.isInitial) {
29
- callback(...args);
30
- }
31
- });
32
- }
33
- hasCallbacks(events) {
34
- return events.some((event) => this.callbacks[event].length > 0);
35
- }
36
- /**
37
- * Determines if the observer has no active callbacks registered for any events.
38
- * @returns A boolean indicating whether the observer is empty (i.e., no callbacks are registered).
39
- */
40
- isEmpty() {
41
- return !this.hasCallbacks([
42
- "added",
43
- "addedBefore",
44
- "changed",
45
- "changedField",
46
- "movedBefore",
47
- "removed"
48
- ]);
49
- }
4
+ import Collection from "./index3.mjs";
5
+ import combinePersistenceAdapters from "./index5.mjs";
6
+ import createPersistenceAdapter from "./index8.mjs";
7
+ import createSignal from "./index21.mjs";
8
+ function createReplicationAdapter(options) {
9
+ return createPersistenceAdapter({
10
+ async register(onChange) {
11
+ if (!options.registerRemoteChange)
12
+ return;
13
+ await options.registerRemoteChange(onChange);
14
+ },
15
+ load: () => options.pull(),
16
+ save: (items, changes) => {
17
+ if (!options.push)
18
+ throw new Error("Pushing is not configured for this collection. Try to pass a `push` function to the collection options.");
19
+ return options.push(changes, items);
20
+ }
21
+ });
22
+ }
23
+ class ReplicatedCollection extends Collection {
50
24
  /**
51
- * Compares the previous state of items with the new state and triggers the appropriate callbacks
52
- * for events such as added, removed, changed, or moved items.
53
- * @param newItems - The new list of items to compare against the previous state.
25
+ * Creates a new instance of the `ReplicatedCollection` class.
26
+ * Sets up the replication adapter, combining it with an optional persistence adapter, and
27
+ * initializes signals for tracking remote pull and push operations.
28
+ * @param options - The configuration options for the replicated collection.
29
+ * @param options.pull - A function to fetch data from the remote source.
30
+ * @param options.push - An optional function to send changes and items to the remote source.
31
+ * @param options.registerRemoteChange - An optional function to register a listener for remote changes.
32
+ * @param options.persistence - An optional persistence adapter to combine with replication.
33
+ * @param options.reactivity - A reactivity adapter for observing changes in the collection.
34
+ * @param options.transform - A transformation function to apply to items when retrieving them.
35
+ * @param options.indices - An array of index providers for optimized querying.
36
+ * @param options.enableDebugMode - A boolean to enable or disable debug mode.
54
37
  */
55
- runChecks(newItems) {
56
- const oldItemsMap = new Map(this.previousItems.map((item, index) => [
57
- item.id,
58
- { item, index, beforeItem: this.previousItems[index + 1] || null }
59
- ]));
60
- const newItemsMap = new Map(newItems.map((item, index) => [
61
- item.id,
62
- { item, index, beforeItem: newItems[index + 1] || null }
63
- ]));
64
- if (this.hasCallbacks(["changed", "changedField", "movedBefore", "removed"])) {
65
- oldItemsMap.forEach(({ item: oldItem, index, beforeItem: oldBeforeItem }) => {
66
- var _a;
67
- const newItem = newItemsMap.get(oldItem.id);
68
- if (newItem) {
69
- if (this.hasCallbacks(["changed", "changedField"]) && !isEqual(newItem.item, oldItem)) {
70
- this.call("changed", newItem.item);
71
- if (this.hasCallbacks(["changedField"])) {
72
- const keys = uniqueBy([
73
- ...Object.keys(newItem.item),
74
- ...Object.keys(oldItem)
75
- ], (value) => value);
76
- keys.forEach((key) => {
77
- if (isEqual(newItem.item[key], oldItem[key]))
78
- return;
79
- this.call("changedField", newItem.item, key, oldItem[key], newItem.item[key]);
80
- });
81
- }
82
- }
83
- if (newItem.index !== index && ((_a = newItem.beforeItem) == null ? void 0 : _a.id) !== (oldBeforeItem == null ? void 0 : oldBeforeItem.id)) {
84
- this.call("movedBefore", newItem.item, newItem.beforeItem);
85
- }
86
- } else {
87
- this.call("removed", oldItem);
38
+ constructor(options) {
39
+ const replicationAdapter = createReplicationAdapter({
40
+ registerRemoteChange: options.registerRemoteChange,
41
+ pull: async () => {
42
+ this.isPullingRemoteSignal.set(true);
43
+ try {
44
+ return await options.pull();
45
+ } finally {
46
+ this.isPullingRemoteSignal.set(false);
88
47
  }
89
- });
90
- }
91
- if (this.hasCallbacks(["added", "addedBefore"])) {
92
- newItems.forEach((newItem, index) => {
93
- const oldItem = oldItemsMap.get(newItem.id);
94
- if (oldItem)
95
- return;
96
- this.call("added", newItem);
97
- this.call("addedBefore", newItem, newItems[index + 1] || null);
98
- });
99
- }
100
- this.previousItems = newItems;
101
- Object.keys(this.callbacks).forEach((key) => {
102
- const event = key;
103
- const callbacks = this.callbacks[event];
104
- this.callbacks[event] = callbacks.map((callback) => ({
105
- ...callback,
106
- options: {
107
- ...callback.options,
108
- isInitial: false
48
+ },
49
+ push: options.push ? async (changes, items) => {
50
+ if (!options.push)
51
+ throw new Error("Pushing is not configured for this collection. Try to pass a `push` function to the collection options.");
52
+ this.isPushingRemoteSignal.set(true);
53
+ try {
54
+ await options.push(changes, items);
55
+ } finally {
56
+ this.isPushingRemoteSignal.set(false);
109
57
  }
110
- }));
58
+ } : void 0
111
59
  });
112
- }
113
- /**
114
- * Stops the observer by unbinding all events and cleaning up resources.
115
- */
116
- stop() {
117
- this.unbindEvents();
118
- }
119
- /**
120
- * Registers callbacks for specific events to observe changes in the collection.
121
- * @param callbacks - An object containing the callbacks for various events (e.g., 'added', 'removed').
122
- * @param skipInitial - A boolean indicating whether to skip invoking the callbacks for the initial state of the collection.
123
- */
124
- addCallbacks(callbacks, skipInitial = false) {
125
- Object.keys(callbacks).forEach((key) => {
126
- const typedKey = key;
127
- this.callbacks[typedKey].push({
128
- callback: callbacks[typedKey],
129
- options: { skipInitial, isInitial: true }
130
- });
60
+ const persistenceAdapter = (options == null ? void 0 : options.persistence) ? combinePersistenceAdapters(replicationAdapter, options.persistence) : replicationAdapter;
61
+ super({
62
+ ...options,
63
+ persistence: persistenceAdapter
131
64
  });
65
+ __publicField(this, "isPullingRemoteSignal");
66
+ __publicField(this, "isPushingRemoteSignal");
67
+ this.isPullingRemoteSignal = createSignal(options.reactivity, false);
68
+ this.isPushingRemoteSignal = createSignal(options.reactivity, false);
132
69
  }
133
70
  /**
134
- * Removes the specified callbacks for specific events, unregistering them from the observer.
135
- * @param callbacks - An object containing the callbacks to be removed for various events.
71
+ * Checks whether the collection is currently performing any loading operation,
72
+ * including pulling or pushing data from/to the remote source, or standard
73
+ * persistence adapter operations.
74
+ * ⚡️ this function is reactive!
75
+ * @returns A boolean indicating if the collection is currently loading or synchronizing.
136
76
  */
137
- removeCallbacks(callbacks) {
138
- Object.keys(callbacks).forEach((key) => {
139
- const typedKey = key;
140
- const index = this.callbacks[typedKey].findIndex(({ callback }) => callback === callbacks[typedKey]);
141
- this.callbacks[typedKey].splice(index, 1);
142
- });
77
+ isLoading() {
78
+ const isPullingRemote = this.isPullingRemoteSignal.get();
79
+ const isPushingRemote = this.isPushingRemoteSignal.get();
80
+ const isLoading = super.isLoading();
81
+ return isPullingRemote || isPushingRemote || isLoading;
143
82
  }
144
83
  }
145
84
  export {
146
- Observer as default
85
+ createReplicationAdapter,
86
+ ReplicatedCollection as default
147
87
  };
package/dist/index24.mjs CHANGED
@@ -1,8 +1,19 @@
1
- function intersection(...arrays) {
2
- if (arrays.length === 0)
3
- return [];
4
- return [...new Set(arrays.reduce((a, b) => a.filter((c) => b.includes(c))))];
1
+ function get(value, path) {
2
+ const normalized = path.replaceAll(/\[(\w+)\]/g, ".$1");
3
+ if (normalized.includes("..") || normalized.startsWith(".") || normalized.endsWith(".")) {
4
+ return;
5
+ }
6
+ const segments = normalized.split(".");
7
+ let current = value;
8
+ for (const key of segments) {
9
+ if (current == null)
10
+ return;
11
+ current = current[key];
12
+ }
13
+ if (current === void 0)
14
+ return;
15
+ return current;
5
16
  }
6
17
  export {
7
- intersection as default
18
+ get as default
8
19
  };
package/dist/index25.mjs CHANGED
@@ -1,19 +1,30 @@
1
- function get(value, path) {
1
+ function set(object, path, value, deleteIfUndefined = false) {
2
+ if (object == null)
3
+ return object;
2
4
  const segments = path.split(/[.[\]]/g);
3
5
  if (segments[0] === "")
4
6
  segments.shift();
5
7
  if (segments.at(-1) === "")
6
8
  segments.pop();
7
- let current = value;
8
- for (const key of segments) {
9
- if (current == null || key.trim() === "")
10
- return;
11
- current = current[key];
12
- }
13
- if (current === void 0)
14
- return;
15
- return current;
9
+ const apply = (node) => {
10
+ if (segments.length > 1) {
11
+ const key = segments.shift();
12
+ const nextIsNumber = !Number.isNaN(Number.parseInt(segments[0], 10));
13
+ if (node[key] === void 0) {
14
+ node[key] = nextIsNumber ? [] : {};
15
+ }
16
+ apply(node[key]);
17
+ } else {
18
+ if (deleteIfUndefined && value === void 0) {
19
+ delete node[segments[0]];
20
+ return;
21
+ }
22
+ node[segments[0]] = value;
23
+ }
24
+ };
25
+ apply(object);
26
+ return object;
16
27
  }
17
28
  export {
18
- get as default
29
+ set as default
19
30
  };
package/dist/index26.mjs CHANGED
@@ -1,30 +1,10 @@
1
- import isFieldExpression from "./index27.mjs";
2
- import serializeValue from "./index16.mjs";
3
- function getMatchingKeys(field, selector) {
4
- const result = { include: null, exclude: null };
5
- const fieldSelector = selector[field];
6
- if (fieldSelector instanceof RegExp)
7
- return result;
8
- if (fieldSelector == null)
9
- return result;
10
- if (isFieldExpression(fieldSelector)) {
11
- if (fieldSelector.$ne != null) {
12
- result.exclude = [serializeValue(fieldSelector.$ne)];
13
- return result;
14
- }
15
- if (Array.isArray(fieldSelector.$in) && fieldSelector.$in.length > 0) {
16
- result.include = fieldSelector.$in.map(serializeValue);
17
- return result;
18
- }
19
- if (Array.isArray(fieldSelector.$nin) && fieldSelector.$nin.length > 0) {
20
- result.exclude = fieldSelector.$nin.map(serializeValue);
21
- return result;
22
- }
23
- return { include: null, exclude: null };
24
- }
25
- result.include = [serializeValue(fieldSelector)];
26
- return result;
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
+ });
27
7
  }
28
8
  export {
29
- getMatchingKeys as default
9
+ uniqueBy as default
30
10
  };
package/dist/index27.mjs CHANGED
@@ -1,43 +1,8 @@
1
- const expressionKeys = /* @__PURE__ */ new Set([
2
- "$eq",
3
- "$gt",
4
- "$gte",
5
- "$lt",
6
- "$lte",
7
- "$in",
8
- "$nin",
9
- "$ne",
10
- "$exists",
11
- "$not",
12
- "$expr",
13
- "$jsonSchema",
14
- "$mod",
15
- "$regex",
16
- "$options",
17
- "$text",
18
- "$where",
19
- "$all",
20
- "$elemMatch",
21
- "$size",
22
- "$bitsAllClear",
23
- "$bitsAllSet",
24
- "$bitsAnyClear",
25
- "$bitsAnySet"
26
- ]);
27
- function isFieldExpression(expression) {
28
- if (typeof expression !== "object" || expression == null) {
29
- return false;
30
- }
31
- const keys = Object.keys(expression);
32
- if (keys.length === 0) {
33
- return false;
34
- }
35
- const hasInvalidKeys = keys.some((key) => !expressionKeys.has(key));
36
- if (hasInvalidKeys)
37
- return false;
38
- const hasValidKeys = keys.every((key) => expressionKeys.has(key));
39
- return hasValidKeys;
1
+ function intersection(...arrays) {
2
+ if (arrays.length === 0)
3
+ return [];
4
+ return [...new Set(arrays.reduce((a, b) => a.filter((c) => b.includes(c))))];
40
5
  }
41
6
  export {
42
- isFieldExpression as default
7
+ intersection as default
43
8
  };