@signaldb/core 1.2.3 → 1.3.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 +28 -47
  2. package/dist/index.cjs.js +12 -18
  3. package/dist/index.cjs10.js +6 -27
  4. package/dist/index.cjs11.js +3 -6
  5. package/dist/index.cjs12.js +136 -3
  6. package/dist/index.cjs13.js +40 -134
  7. package/dist/index.cjs14.js +5 -38
  8. package/dist/index.cjs15.js +42 -2
  9. package/dist/index.cjs16.js +11 -5
  10. package/dist/index.cjs17.js +17 -40
  11. package/dist/index.cjs18.js +262 -11
  12. package/dist/index.cjs19.js +66 -16
  13. package/dist/index.cjs2.js +688 -96
  14. package/dist/index.cjs20.js +71 -247
  15. package/dist/index.cjs21.js +8 -68
  16. package/dist/index.cjs22.js +22 -83
  17. package/dist/index.cjs23.js +144 -8
  18. package/dist/index.cjs24.js +5 -25
  19. package/dist/index.cjs25.js +16 -144
  20. package/dist/index.cjs26.js +27 -5
  21. package/dist/index.cjs27.js +39 -15
  22. package/dist/index.cjs28.js +25 -24
  23. package/dist/index.cjs29.js +7 -40
  24. package/dist/index.cjs3.js +139 -664
  25. package/dist/index.cjs4.js +62 -166
  26. package/dist/index.cjs5.js +3 -67
  27. package/dist/index.cjs6.js +2 -2
  28. package/dist/index.cjs7.js +2 -2
  29. package/dist/index.cjs8.js +2 -2
  30. package/dist/index.cjs9.js +27 -3
  31. package/dist/index.d.ts +0 -1
  32. package/dist/index.mjs +12 -18
  33. package/dist/index10.mjs +6 -27
  34. package/dist/index11.mjs +3 -6
  35. package/dist/index12.mjs +136 -3
  36. package/dist/index13.mjs +39 -134
  37. package/dist/index14.mjs +5 -37
  38. package/dist/index15.mjs +41 -2
  39. package/dist/index16.mjs +11 -5
  40. package/dist/index17.mjs +17 -39
  41. package/dist/index18.mjs +261 -11
  42. package/dist/index19.mjs +65 -16
  43. package/dist/index2.mjs +688 -94
  44. package/dist/index20.mjs +71 -247
  45. package/dist/index21.mjs +8 -67
  46. package/dist/index22.mjs +22 -82
  47. package/dist/index23.mjs +144 -8
  48. package/dist/index24.mjs +5 -25
  49. package/dist/index25.mjs +16 -144
  50. package/dist/index26.mjs +27 -5
  51. package/dist/index27.mjs +39 -15
  52. package/dist/index28.mjs +25 -24
  53. package/dist/index29.mjs +7 -40
  54. package/dist/index3.mjs +139 -664
  55. package/dist/index4.mjs +61 -166
  56. package/dist/index5.mjs +3 -66
  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 +27 -3
  61. package/dist/types/Selector.d.ts +33 -35
  62. package/dist/utils/getMatchingKeys.d.ts +11 -6
  63. package/package.json +1 -1
  64. package/dist/devtools.d.ts +0 -4
  65. package/dist/index.cjs30.js +0 -29
  66. package/dist/index.cjs31.js +0 -9
  67. package/dist/index30.mjs +0 -30
  68. package/dist/index31.mjs +0 -10
package/dist/index4.mjs CHANGED
@@ -1,174 +1,69 @@
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 ReplicatedCollection from "./index22.mjs";
5
- import createSignal from "./index19.mjs";
6
- class AutoFetchCollection extends ReplicatedCollection {
7
- /**
8
- * @param options {Object} - Options for the collection.
9
- * @param options.fetchQueryItems {Function} - A function that fetches items from the server. It takes the selector as an argument and returns a promise that resolves to an object with an `items` property.
10
- * @param options.purgeDelay {Number} - The delay in milliseconds before purging an item from the cache.
11
- */
12
- constructor(options) {
13
- var _a;
14
- let triggerRemoteChange;
15
- super({
16
- ...options,
17
- pull: () => Promise.resolve({
18
- items: [...this.itemsCache.values()].reduce((memo, items) => {
19
- const newItems = [...memo];
20
- items.forEach((item) => {
21
- const index = newItems.findIndex((i) => i.id === item.id);
22
- if (index === -1) {
23
- newItems.push(item);
24
- return;
25
- }
26
- newItems[index] = this.mergeItems(newItems[index], item);
27
- });
28
- return newItems;
29
- }, [])
30
- }),
31
- registerRemoteChange: async (onChange) => {
32
- triggerRemoteChange = onChange;
1
+ import createPersistenceAdapter from "./index7.mjs";
2
+ function createTemporaryFallbackExecutor(firstResolvingPromiseFunction, secondResolvingPromiseFunction, options) {
3
+ const cacheTimeout = options == null ? void 0 : options.cacheTimeout;
4
+ let isResolved = false;
5
+ let resolvedValue = null;
6
+ let timeout = null;
7
+ let secondaryPromise = null;
8
+ return (...args) => {
9
+ if (secondaryPromise == null) {
10
+ if (timeout) {
11
+ clearTimeout(timeout);
12
+ timeout = null;
33
13
  }
34
- });
35
- __publicField(this, "activeObservers", /* @__PURE__ */ new Map());
36
- __publicField(this, "observerTimeouts", /* @__PURE__ */ new Map());
37
- __publicField(this, "purgeDelay");
38
- __publicField(this, "idQueryCache", /* @__PURE__ */ new Map());
39
- __publicField(this, "itemsCache", /* @__PURE__ */ new Map());
40
- __publicField(this, "fetchQueryItems");
41
- __publicField(this, "triggerReload", null);
42
- __publicField(this, "reactivityAdapter", null);
43
- __publicField(this, "loadingSignals", /* @__PURE__ */ new Map());
44
- __publicField(this, "isFetchingSignal");
45
- __publicField(this, "mergeItems");
46
- this.mergeItems = options.mergeItems ?? ((itemA, itemB) => ({ ...itemA, ...itemB }));
47
- this.purgeDelay = options.purgeDelay ?? 1e4;
48
- this.isFetchingSignal = createSignal((_a = options.reactivity) == null ? void 0 : _a.create(), false);
49
- if (!triggerRemoteChange)
50
- throw new Error("No triggerRemoteChange method found. Looks like your persistence adapter was not registered");
51
- this.triggerReload = triggerRemoteChange;
52
- this.reactivityAdapter = options.reactivity ?? null;
53
- this.fetchQueryItems = options.fetchQueryItems;
54
- this.on("observer.created", (selector) => this.handleObserverCreation(selector ?? {}));
55
- this.on("observer.disposed", (selector) => setTimeout(() => this.handleObserverDisposal(selector ?? {}), 100));
56
- if (options.registerRemoteChange) {
57
- void options.registerRemoteChange(() => this.forceRefetch());
58
- }
59
- }
60
- /**
61
- * Registers a query manually that items should be fetched for it
62
- * @param selector {Object} Selector of the query
63
- */
64
- registerQuery(selector) {
65
- this.handleObserverCreation(selector);
66
- }
67
- /**
68
- * Unregisters a query manually that items are not fetched anymore for it
69
- * @param selector {Object} Selector of the query
70
- */
71
- unregisterQuery(selector) {
72
- this.handleObserverDisposal(selector);
73
- }
74
- getKeyForSelector(selector) {
75
- return JSON.stringify(selector);
76
- }
77
- async forceRefetch() {
78
- return Promise.all([...this.activeObservers.values()].map(({ selector }) => this.fetchSelector(selector))).then(() => {
79
- });
80
- }
81
- fetchSelector(selector) {
82
- this.isFetchingSignal.set(true);
83
- return this.fetchQueryItems(selector).then((response) => {
84
- if (!response.items)
85
- throw new Error("AutoFetchCollection currently only works with a full item response");
86
- this.itemsCache.set(this.getKeyForSelector(selector), response.items);
87
- response.items.forEach((item) => {
88
- const queries = this.idQueryCache.get(item.id) ?? [];
89
- queries.push(selector);
90
- this.idQueryCache.set(item.id, queries);
91
- });
92
- this.setLoading(selector, true);
93
- this.once("persistence.received", () => {
94
- this.setLoading(selector, false);
95
- });
96
- if (!this.triggerReload)
97
- throw new Error("No triggerReload method found. Looks like your persistence adapter was not registered");
98
- void this.triggerReload();
99
- }).catch((error) => {
100
- this.emit("persistence.error", error);
101
- }).finally(() => {
102
- this.isFetchingSignal.set(false);
103
- });
104
- }
105
- handleObserverCreation(selector) {
106
- var _a;
107
- const activeObservers = ((_a = this.activeObservers.get(this.getKeyForSelector(selector))) == null ? void 0 : _a.count) ?? 0;
108
- this.activeObservers.set(this.getKeyForSelector(selector), {
109
- selector,
110
- count: activeObservers + 1
111
- });
112
- const timeout = this.observerTimeouts.get(this.getKeyForSelector(selector));
113
- if (timeout)
114
- clearTimeout(timeout);
115
- if (activeObservers === 0)
116
- void this.fetchSelector(selector);
117
- }
118
- handleObserverDisposal(selector) {
119
- var _a;
120
- const currentObservers = ((_a = this.activeObservers.get(this.getKeyForSelector(selector))) == null ? void 0 : _a.count) ?? 0;
121
- const activeObservers = currentObservers - 1;
122
- if (activeObservers > 0) {
123
- this.activeObservers.set(this.getKeyForSelector(selector), {
124
- selector,
125
- count: activeObservers
14
+ secondaryPromise = secondResolvingPromiseFunction(...args).then((result) => {
15
+ {
16
+ timeout = setTimeout(() => {
17
+ isResolved = false;
18
+ resolvedValue = null;
19
+ secondaryPromise = null;
20
+ }, cacheTimeout);
21
+ }
22
+ isResolved = true;
23
+ resolvedValue = result;
24
+ if (options == null ? void 0 : options.onResolve)
25
+ options.onResolve(resolvedValue);
26
+ return result;
126
27
  });
127
- return;
28
+ } else if (isResolved) {
29
+ return secondaryPromise;
128
30
  }
129
- const timeout = this.observerTimeouts.get(this.getKeyForSelector(selector));
130
- if (timeout)
131
- clearTimeout(timeout);
132
- const removeObserver = () => {
133
- this.activeObservers.delete(this.getKeyForSelector(selector));
134
- this.itemsCache.delete(this.getKeyForSelector(selector));
135
- if (!this.triggerReload)
136
- throw new Error("No triggerReload method found. Looks like your persistence adapter was not registered");
137
- void this.triggerReload();
138
- };
139
- if (this.purgeDelay === 0) {
140
- removeObserver();
141
- return;
142
- }
143
- this.observerTimeouts.set(this.getKeyForSelector(selector), setTimeout(removeObserver, this.purgeDelay));
144
- }
145
- ensureSignal(selector) {
146
- if (!this.reactivityAdapter)
147
- throw new Error("No reactivity adapter found");
148
- if (!this.loadingSignals.has(this.getKeyForSelector(selector))) {
149
- this.loadingSignals.set(this.getKeyForSelector(selector), createSignal(this.reactivityAdapter.create(), false));
31
+ return firstResolvingPromiseFunction(...args);
32
+ };
33
+ }
34
+ function combinePersistenceAdapters(slowAdapter, fastAdapter) {
35
+ let handleChange = null;
36
+ const readExecutor = createTemporaryFallbackExecutor(() => fastAdapter.load(), () => slowAdapter.load(), {
37
+ cacheTimeout: 100,
38
+ onResolve: (result) => {
39
+ var _a, _b, _c;
40
+ if (handleChange)
41
+ void handleChange();
42
+ void fastAdapter.save(result.items || [], {
43
+ added: ((_a = result.changes) == null ? void 0 : _a.added) || [],
44
+ modified: ((_b = result.changes) == null ? void 0 : _b.modified) || [],
45
+ removed: ((_c = result.changes) == null ? void 0 : _c.removed) || []
46
+ });
150
47
  }
151
- return this.loadingSignals.get(this.getKeyForSelector(selector));
152
- }
153
- setLoading(selector, value) {
154
- const signal = this.ensureSignal(selector);
155
- signal.set(value);
156
- }
157
- /**
158
- * Indicates wether a query is currently been loaded
159
- * ⚡️ this function is reactive!
160
- * @param selector {Object} Selector of the query
161
- * @returns The loading state
162
- */
163
- isLoading(selector) {
164
- const isPushing = this.isPushing();
165
- if (!selector) {
166
- return this.isFetchingSignal.get() || isPushing;
48
+ });
49
+ return createPersistenceAdapter({
50
+ async register(onChange) {
51
+ handleChange = onChange;
52
+ await Promise.all([slowAdapter.register(onChange), fastAdapter.register(onChange)]);
53
+ },
54
+ async load() {
55
+ const promise = readExecutor();
56
+ return promise;
57
+ },
58
+ async save(items, changes) {
59
+ await Promise.all([
60
+ fastAdapter.save(items, changes),
61
+ slowAdapter.save(items, changes)
62
+ ]);
167
63
  }
168
- const signal = this.ensureSignal(selector);
169
- return signal.get() || isPushing;
170
- }
64
+ });
171
65
  }
172
66
  export {
173
- AutoFetchCollection as default
67
+ createTemporaryFallbackExecutor,
68
+ combinePersistenceAdapters as default
174
69
  };
package/dist/index5.mjs CHANGED
@@ -1,69 +1,6 @@
1
- import createPersistenceAdapter from "./index8.mjs";
2
- function createTemporaryFallbackExecutor(firstResolvingPromiseFunction, secondResolvingPromiseFunction, options) {
3
- const cacheTimeout = options == null ? void 0 : options.cacheTimeout;
4
- let isResolved = false;
5
- let resolvedValue = null;
6
- let timeout = null;
7
- let secondaryPromise = null;
8
- return (...args) => {
9
- if (secondaryPromise == null) {
10
- if (timeout) {
11
- clearTimeout(timeout);
12
- timeout = null;
13
- }
14
- secondaryPromise = secondResolvingPromiseFunction(...args).then((result) => {
15
- {
16
- timeout = setTimeout(() => {
17
- isResolved = false;
18
- resolvedValue = null;
19
- secondaryPromise = null;
20
- }, cacheTimeout);
21
- }
22
- isResolved = true;
23
- resolvedValue = result;
24
- if (options == null ? void 0 : options.onResolve)
25
- options.onResolve(resolvedValue);
26
- return result;
27
- });
28
- } else if (isResolved) {
29
- return secondaryPromise;
30
- }
31
- return firstResolvingPromiseFunction(...args);
32
- };
33
- }
34
- function combinePersistenceAdapters(slowAdapter, fastAdapter) {
35
- let handleChange = null;
36
- const readExecutor = createTemporaryFallbackExecutor(() => fastAdapter.load(), () => slowAdapter.load(), {
37
- cacheTimeout: 100,
38
- onResolve: (result) => {
39
- var _a, _b, _c;
40
- if (handleChange)
41
- void handleChange();
42
- void fastAdapter.save(result.items || [], {
43
- added: ((_a = result.changes) == null ? void 0 : _a.added) || [],
44
- modified: ((_b = result.changes) == null ? void 0 : _b.modified) || [],
45
- removed: ((_c = result.changes) == null ? void 0 : _c.removed) || []
46
- });
47
- }
48
- });
49
- return createPersistenceAdapter({
50
- async register(onChange) {
51
- handleChange = onChange;
52
- await Promise.all([slowAdapter.register(onChange), fastAdapter.register(onChange)]);
53
- },
54
- async load() {
55
- const promise = readExecutor();
56
- return promise;
57
- },
58
- async save(items, changes) {
59
- await Promise.all([
60
- fastAdapter.save(items, changes),
61
- slowAdapter.save(items, changes)
62
- ]);
63
- }
64
- });
1
+ function createIndexProvider(definition) {
2
+ return definition;
65
3
  }
66
4
  export {
67
- createTemporaryFallbackExecutor,
68
- combinePersistenceAdapters as default
5
+ createIndexProvider as default
69
6
  };
package/dist/index6.mjs CHANGED
@@ -1,6 +1,6 @@
1
- function createIndexProvider(definition) {
1
+ function createMemoryAdapter(definition) {
2
2
  return definition;
3
3
  }
4
4
  export {
5
- createIndexProvider as default
5
+ createMemoryAdapter as default
6
6
  };
package/dist/index7.mjs CHANGED
@@ -1,6 +1,6 @@
1
- function createMemoryAdapter(definition) {
1
+ function createPersistenceAdapter(definition) {
2
2
  return definition;
3
3
  }
4
4
  export {
5
- createMemoryAdapter as default
5
+ createPersistenceAdapter as default
6
6
  };
package/dist/index8.mjs CHANGED
@@ -1,6 +1,6 @@
1
- function createPersistenceAdapter(definition) {
1
+ function createReactivityAdapter(definition) {
2
2
  return definition;
3
3
  }
4
4
  export {
5
- createPersistenceAdapter as default
5
+ createReactivityAdapter as default
6
6
  };
package/dist/index9.mjs CHANGED
@@ -1,6 +1,30 @@
1
- function createReactivityAdapter(definition) {
2
- return definition;
1
+ function isEqual(a, b) {
2
+ if (Object.is(a, b))
3
+ return true;
4
+ if (a instanceof RegExp && b instanceof RegExp)
5
+ return a.toString() === b.toString();
6
+ if (a instanceof Date && b instanceof Date)
7
+ return a.getTime() === b.getTime();
8
+ if (typeof a !== "object")
9
+ return false;
10
+ if (typeof b !== "object")
11
+ return false;
12
+ if (a === null)
13
+ return false;
14
+ if (b === null)
15
+ return false;
16
+ const aKeys = Object.keys(a);
17
+ const bKeys = Object.keys(b);
18
+ if (aKeys.length !== bKeys.length)
19
+ return false;
20
+ for (const key of aKeys) {
21
+ if (!bKeys.includes(key))
22
+ return false;
23
+ if (!isEqual(a[key], b[key]))
24
+ return false;
25
+ }
26
+ return true;
3
27
  }
4
28
  export {
5
- createReactivityAdapter as default
29
+ isEqual as default
6
30
  };
@@ -1,54 +1,52 @@
1
1
  export interface FieldExpression<T> {
2
- $eq?: T | undefined;
3
- $gt?: T | undefined;
4
- $gte?: T | undefined;
5
- $lt?: T | undefined;
6
- $lte?: T | undefined;
2
+ $eq?: T;
3
+ $gt?: T;
4
+ $gte?: T;
5
+ $lt?: T;
6
+ $lte?: T;
7
7
  $in?: T[] | undefined;
8
- $nin?: T[] | undefined;
9
- $ne?: T | undefined;
10
- $exists?: boolean | undefined;
11
- $not?: FieldExpression<T> | undefined;
12
- $expr?: FieldExpression<T> | undefined;
8
+ $nin?: T[];
9
+ $ne?: T;
10
+ $exists?: boolean;
11
+ $not?: FieldExpression<T>;
12
+ $expr?: FieldExpression<T>;
13
13
  $jsonSchema?: any;
14
- $mod?: number[] | undefined;
15
- $regex?: RegExp | string | undefined;
16
- $options?: string | undefined;
14
+ $mod?: number[];
15
+ $regex?: RegExp | string;
16
+ $options?: string;
17
17
  $text?: {
18
18
  $search: string;
19
- $language?: string | undefined;
20
- $caseSensitive?: boolean | undefined;
21
- $diacriticSensitive?: boolean | undefined;
22
- } | undefined;
23
- $where?: string | ((item: T) => boolean) | undefined;
24
- $all?: T[] | undefined;
25
- $elemMatch?: T extends object ? Query<T> : FieldExpression<T> | undefined;
26
- $size?: number | undefined;
19
+ $language?: string;
20
+ $caseSensitive?: boolean;
21
+ $diacriticSensitive?: boolean;
22
+ };
23
+ $where?: string | ((item: T) => boolean);
24
+ $all?: T[];
25
+ $elemMatch?: T extends object ? Query<T> : FieldExpression<T>;
26
+ $size?: number;
27
27
  $bitsAllClear?: any;
28
28
  $bitsAllSet?: any;
29
29
  $bitsAnyClear?: any;
30
30
  $bitsAnySet?: any;
31
31
  }
32
- type IsObject<T> = T extends object ? (T extends Array<any> ? false : true) : false;
33
- type DotNotationKeys<T> = {
34
- [K in keyof T & (string | number)]: T[K] extends Array<infer U> ? `${K}` | `${K}.$` | `${K}.${DotNotationKeys<U>}` : IsObject<T[K]> extends true ? `${K}` | `${K}.${DotNotationKeys<T[K]>}` : `${K}`;
35
- }[keyof T & (string | number)];
36
- type Split<S extends string, Delimiter extends string> = S extends `${infer Head}${Delimiter}${infer Tail}` ? [Head, ...Split<Tail, Delimiter>] : [S];
37
- type GetTypeByParts<T, Parts extends readonly string[]> = Parts extends [infer Head, ...infer Tail] ? Head extends keyof T ? GetTypeByParts<T[Head], Extract<Tail, string[]>> : Head extends '$' ? T extends Array<infer U> ? GetTypeByParts<U, Extract<Tail, string[]>> : never : never : T;
38
- type Get<T, Path extends string> = GetTypeByParts<T, Split<Path, '.'>>;
39
- type Flatten<T> = T extends any[] ? T[0] : T;
32
+ type DotNotation<T> = {
33
+ [K in keyof T & string]: T[K] extends Array<infer U> ? `${K}` | `${K}.$` | `${K}.${DotNotation<U>}` : T[K] extends object ? `${K}` | `${K}.${DotNotation<T[K]>}` : `${K}`;
34
+ }[keyof T & string];
35
+ type GetType<T, P extends string> = P extends `${infer H}.${infer R}` ? H extends keyof T ? T[H] extends Array<infer U> ? GetType<U, R> : GetType<T[H], R> : H extends '$' ? T extends Array<infer U> ? GetType<U, R> : never : never : P extends keyof T ? T[P] : never;
40
36
  type FlatQuery<T> = {
41
- [P in DotNotationKeys<T>]?: Flatten<Get<T, P>> | RegExp | FieldExpression<Flatten<Get<T, P>>>;
37
+ [P in DotNotation<T>]?: FlatQueryValue<T, P>;
42
38
  };
39
+ type FieldValue<U> = U extends string ? string | RegExp | FieldExpression<string> : U | FieldExpression<U>;
40
+ type FlatQueryValue<T, P extends string> = GetType<T, P> extends never ? never : GetType<T, P> extends Array<infer U> ? FieldValue<U> | FieldValue<U[]> : FieldValue<GetType<T, P>>;
43
41
  type Query<T> = FlatQuery<T> & {
44
- $or?: Query<T>[] | undefined;
45
- $and?: Query<T>[] | undefined;
46
- $nor?: Query<T>[] | undefined;
42
+ $or?: Query<T>[];
43
+ $and?: Query<T>[];
44
+ $nor?: Query<T>[];
47
45
  };
48
- export type FlatSelector<T extends Record<string, any> = Record<string, any>> = FlatQuery<T> & {
46
+ export type FlatSelector<T extends Record<string, any>> = FlatQuery<T> & {
49
47
  $or?: never;
50
48
  $and?: never;
51
49
  $nor?: never;
52
50
  };
53
- type Selector<T extends Record<string, any> = Record<string, any>> = Query<T>;
51
+ type Selector<T extends Record<string, any>> = Query<T>;
54
52
  export default Selector;
@@ -1,14 +1,19 @@
1
1
  import type { BaseItem } from '../Collection/types';
2
2
  import type { FlatSelector } from '../types/Selector';
3
+ type KeyResult = {
4
+ include: string[] | null;
5
+ exclude: string[] | null;
6
+ };
3
7
  /**
4
- * Extracts the matching keys for a given field in a selector.
5
- * Supports serialized values and `$in` field expressions for optimization.
6
- * Returns `null` if the field cannot be optimized.
8
+ * Extracts the matching and excluded keys for a given field in a selector.
9
+ * Supports serialized values and `$in`/`$nin` field expressions for optimization.
10
+ * Returns `null` for include/exclude if the field cannot be optimized.
7
11
  * @template T - The type of the items in the selector.
8
12
  * @template I - The type of the unique identifier for the items.
9
13
  * @param field - The name of the field to extract matching keys for.
10
14
  * @param selector - The selector object containing query criteria.
11
- * @returns An array of serialized matching keys for the field, or `null` if the field
12
- * cannot be optimized (e.g., if it's a `RegExp` or non-optimizable field expression).
15
+ * @returns An object containing arrays of serialized included and excluded keys,
16
+ * or `null` if the field cannot be optimized.
13
17
  */
14
- export default function getMatchingKeys<T extends BaseItem<I> = BaseItem, I = any>(field: string, selector: FlatSelector<T>): string[] | null;
18
+ export default function getMatchingKeys<T extends BaseItem<I> = BaseItem, I = any>(field: string, selector: FlatSelector<T>): KeyResult;
19
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@signaldb/core",
3
- "version": "1.2.3",
3
+ "version": "1.3.0",
4
4
  "description": "SignalDB is a client-side database that provides a simple MongoDB-like interface to the data with first-class typescript support to achieve an optimistic UI. Data persistence can be achieved by using storage providers that store the data through a JSON interface to places such as localStorage.",
5
5
  "scripts": {
6
6
  "build": "rimraf dist && vite build"
@@ -1,4 +0,0 @@
1
- /**
2
- * Loads the devtools in production mode and logs a warning if in production.
3
- */
4
- export default function loadDeveloperTools(): void;
@@ -1,29 +0,0 @@
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;
28
- }
29
- module.exports = set;
@@ -1,9 +0,0 @@
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
- });
8
- }
9
- module.exports = uniqueBy;
package/dist/index30.mjs DELETED
@@ -1,30 +0,0 @@
1
- function set(object, path, value, deleteIfUndefined = false) {
2
- if (object == null)
3
- return object;
4
- const segments = path.split(/[.[\]]/g);
5
- if (segments[0] === "")
6
- segments.shift();
7
- if (segments.at(-1) === "")
8
- segments.pop();
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;
27
- }
28
- export {
29
- set as default
30
- };
package/dist/index31.mjs DELETED
@@ -1,10 +0,0 @@
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
- };