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