@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.
- package/dist/.vite/manifest.json +28 -47
- package/dist/index.cjs.js +12 -18
- package/dist/index.cjs10.js +6 -27
- package/dist/index.cjs11.js +3 -6
- package/dist/index.cjs12.js +136 -3
- package/dist/index.cjs13.js +40 -134
- package/dist/index.cjs14.js +5 -38
- package/dist/index.cjs15.js +42 -2
- package/dist/index.cjs16.js +11 -5
- package/dist/index.cjs17.js +17 -40
- package/dist/index.cjs18.js +262 -11
- package/dist/index.cjs19.js +66 -16
- package/dist/index.cjs2.js +688 -96
- package/dist/index.cjs20.js +71 -247
- package/dist/index.cjs21.js +8 -68
- package/dist/index.cjs22.js +22 -83
- package/dist/index.cjs23.js +144 -8
- package/dist/index.cjs24.js +5 -25
- package/dist/index.cjs25.js +16 -144
- package/dist/index.cjs26.js +27 -5
- package/dist/index.cjs27.js +39 -15
- package/dist/index.cjs28.js +25 -24
- package/dist/index.cjs29.js +7 -40
- package/dist/index.cjs3.js +139 -664
- package/dist/index.cjs4.js +62 -166
- package/dist/index.cjs5.js +3 -67
- package/dist/index.cjs6.js +2 -2
- package/dist/index.cjs7.js +2 -2
- package/dist/index.cjs8.js +2 -2
- package/dist/index.cjs9.js +27 -3
- package/dist/index.d.ts +0 -1
- package/dist/index.mjs +12 -18
- package/dist/index10.mjs +6 -27
- package/dist/index11.mjs +3 -6
- package/dist/index12.mjs +136 -3
- package/dist/index13.mjs +39 -134
- package/dist/index14.mjs +5 -37
- package/dist/index15.mjs +41 -2
- package/dist/index16.mjs +11 -5
- package/dist/index17.mjs +17 -39
- package/dist/index18.mjs +261 -11
- package/dist/index19.mjs +65 -16
- package/dist/index2.mjs +688 -94
- package/dist/index20.mjs +71 -247
- package/dist/index21.mjs +8 -67
- package/dist/index22.mjs +22 -82
- package/dist/index23.mjs +144 -8
- package/dist/index24.mjs +5 -25
- package/dist/index25.mjs +16 -144
- package/dist/index26.mjs +27 -5
- package/dist/index27.mjs +39 -15
- package/dist/index28.mjs +25 -24
- package/dist/index29.mjs +7 -40
- package/dist/index3.mjs +139 -664
- package/dist/index4.mjs +61 -166
- package/dist/index5.mjs +3 -66
- package/dist/index6.mjs +2 -2
- package/dist/index7.mjs +2 -2
- package/dist/index8.mjs +2 -2
- package/dist/index9.mjs +27 -3
- package/dist/types/Selector.d.ts +33 -35
- package/dist/utils/getMatchingKeys.d.ts +11 -6
- package/package.json +1 -1
- package/dist/devtools.d.ts +0 -4
- package/dist/index.cjs30.js +0 -29
- package/dist/index.cjs31.js +0 -9
- package/dist/index30.mjs +0 -30
- package/dist/index31.mjs +0 -10
package/dist/index4.mjs
CHANGED
|
@@ -1,174 +1,69 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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
|
-
|
|
28
|
+
} else if (isResolved) {
|
|
29
|
+
return secondaryPromise;
|
|
128
30
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
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
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
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
|
-
|
|
169
|
-
return signal.get() || isPushing;
|
|
170
|
-
}
|
|
64
|
+
});
|
|
171
65
|
}
|
|
172
66
|
export {
|
|
173
|
-
|
|
67
|
+
createTemporaryFallbackExecutor,
|
|
68
|
+
combinePersistenceAdapters as default
|
|
174
69
|
};
|
package/dist/index5.mjs
CHANGED
|
@@ -1,69 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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
|
-
|
|
68
|
-
combinePersistenceAdapters as default
|
|
5
|
+
createIndexProvider as default
|
|
69
6
|
};
|
package/dist/index6.mjs
CHANGED
package/dist/index7.mjs
CHANGED
package/dist/index8.mjs
CHANGED
package/dist/index9.mjs
CHANGED
|
@@ -1,6 +1,30 @@
|
|
|
1
|
-
function
|
|
2
|
-
|
|
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
|
-
|
|
29
|
+
isEqual as default
|
|
6
30
|
};
|
package/dist/types/Selector.d.ts
CHANGED
|
@@ -1,54 +1,52 @@
|
|
|
1
1
|
export interface FieldExpression<T> {
|
|
2
|
-
$eq?: T
|
|
3
|
-
$gt?: T
|
|
4
|
-
$gte?: T
|
|
5
|
-
$lt?: T
|
|
6
|
-
$lte?: T
|
|
2
|
+
$eq?: T;
|
|
3
|
+
$gt?: T;
|
|
4
|
+
$gte?: T;
|
|
5
|
+
$lt?: T;
|
|
6
|
+
$lte?: T;
|
|
7
7
|
$in?: T[] | undefined;
|
|
8
|
-
$nin?: T[]
|
|
9
|
-
$ne?: T
|
|
10
|
-
$exists?: boolean
|
|
11
|
-
$not?: FieldExpression<T
|
|
12
|
-
$expr?: FieldExpression<T
|
|
8
|
+
$nin?: T[];
|
|
9
|
+
$ne?: T;
|
|
10
|
+
$exists?: boolean;
|
|
11
|
+
$not?: FieldExpression<T>;
|
|
12
|
+
$expr?: FieldExpression<T>;
|
|
13
13
|
$jsonSchema?: any;
|
|
14
|
-
$mod?: number[]
|
|
15
|
-
$regex?: RegExp | string
|
|
16
|
-
$options?: string
|
|
14
|
+
$mod?: number[];
|
|
15
|
+
$regex?: RegExp | string;
|
|
16
|
+
$options?: string;
|
|
17
17
|
$text?: {
|
|
18
18
|
$search: string;
|
|
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
|
|
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
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}[keyof T
|
|
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
|
|
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>[]
|
|
45
|
-
$and?: Query<T>[]
|
|
46
|
-
$nor?: Query<T>[]
|
|
42
|
+
$or?: Query<T>[];
|
|
43
|
+
$and?: Query<T>[];
|
|
44
|
+
$nor?: Query<T>[];
|
|
47
45
|
};
|
|
48
|
-
export type FlatSelector<T extends Record<string, any
|
|
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
|
|
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
|
|
12
|
-
*
|
|
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>):
|
|
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.
|
|
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"
|
package/dist/devtools.d.ts
DELETED
package/dist/index.cjs30.js
DELETED
|
@@ -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;
|
package/dist/index.cjs31.js
DELETED
|
@@ -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
|
-
};
|