@wxn0brp/db-core 0.12.0-alpha.0 → 0.12.0-alpha.2
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/db/valthera.d.ts
CHANGED
|
@@ -81,7 +81,7 @@ export declare class ValtheraClass implements ValtheraCompatible {
|
|
|
81
81
|
*/
|
|
82
82
|
toggleOne<T = Data>(query: VQueryT.ToggleOne<T>): Promise<VQueryT.ToggleOneResult<T>>;
|
|
83
83
|
/**
|
|
84
|
-
* Removes a database collection from the
|
|
84
|
+
* Removes a database collection from the database.
|
|
85
85
|
*/
|
|
86
86
|
removeCollection(collection: string): Promise<boolean>;
|
|
87
87
|
}
|
package/dist/db/valthera.js
CHANGED
|
@@ -196,9 +196,10 @@ export class ValtheraClass {
|
|
|
196
196
|
return this.execute("toggleOne", query);
|
|
197
197
|
}
|
|
198
198
|
/**
|
|
199
|
-
* Removes a database collection from the
|
|
199
|
+
* Removes a database collection from the database.
|
|
200
200
|
*/
|
|
201
201
|
removeCollection(collection) {
|
|
202
|
+
this._collections.delete(collection);
|
|
202
203
|
return this.execute("removeCollection", collection);
|
|
203
204
|
}
|
|
204
205
|
}
|
package/dist/utils/action.js
CHANGED
|
@@ -57,6 +57,8 @@ export async function findUtil(query, fileCpuOrData, files, fileCpuOpts) {
|
|
|
57
57
|
}
|
|
58
58
|
if (!needsAllData)
|
|
59
59
|
return datas;
|
|
60
|
+
if (datas.length === 0)
|
|
61
|
+
return [];
|
|
60
62
|
const hasAggregations = min || max || avg || sum || groupBy || count;
|
|
61
63
|
if (hasAggregations) {
|
|
62
64
|
const groups = new Map();
|
|
@@ -97,28 +99,28 @@ export async function findUtil(query, fileCpuOrData, files, fileCpuOpts) {
|
|
|
97
99
|
}
|
|
98
100
|
for (const [outKey, srcField] of Object.entries(min ?? {})) {
|
|
99
101
|
const nums = groupItems
|
|
100
|
-
.map(d =>
|
|
101
|
-
.filter(
|
|
102
|
+
.map(d => d[srcField])
|
|
103
|
+
.filter((v) => typeof v === "number");
|
|
102
104
|
result[outKey] = nums.length ? Math.min(...nums) : null;
|
|
103
105
|
}
|
|
104
106
|
for (const [outKey, srcField] of Object.entries(max ?? {})) {
|
|
105
107
|
const nums = groupItems
|
|
106
|
-
.map(d =>
|
|
107
|
-
.filter(
|
|
108
|
+
.map(d => d[srcField])
|
|
109
|
+
.filter((v) => typeof v === "number");
|
|
108
110
|
result[outKey] = nums.length ? Math.max(...nums) : null;
|
|
109
111
|
}
|
|
110
112
|
for (const [outKey, srcField] of Object.entries(avg ?? {})) {
|
|
111
113
|
const nums = groupItems
|
|
112
|
-
.map(d =>
|
|
113
|
-
.filter(
|
|
114
|
+
.map(d => d[srcField])
|
|
115
|
+
.filter((v) => typeof v === "number");
|
|
114
116
|
result[outKey] = nums.length
|
|
115
117
|
? nums.reduce((a, b) => a + b, 0) / nums.length
|
|
116
118
|
: null;
|
|
117
119
|
}
|
|
118
120
|
for (const [outKey, srcField] of Object.entries(sum ?? {})) {
|
|
119
121
|
const nums = groupItems
|
|
120
|
-
.map(d =>
|
|
121
|
-
.filter(
|
|
122
|
+
.map(d => d[srcField])
|
|
123
|
+
.filter((v) => typeof v === "number");
|
|
122
124
|
result[outKey] = nums.length ? nums.reduce((a, b) => a + b, 0) : null;
|
|
123
125
|
}
|
|
124
126
|
aggregated.push(result);
|
package/dist/utils/compare.js
CHANGED
|
@@ -10,7 +10,7 @@ export function compareSafe(a, b) {
|
|
|
10
10
|
const typeA = typeof a;
|
|
11
11
|
const typeB = typeof b;
|
|
12
12
|
if (typeA === "string" && typeB === "string") {
|
|
13
|
-
return a.localeCompare(b);
|
|
13
|
+
return Math.sign(a.localeCompare(b));
|
|
14
14
|
}
|
|
15
15
|
if ((typeA === "number" || a instanceof Date) &&
|
|
16
16
|
(typeB === "number" || b instanceof Date)) {
|
|
@@ -42,10 +42,10 @@ export function hasFieldsAdvanced(obj, fields) {
|
|
|
42
42
|
function mainCheck(obj, fields) {
|
|
43
43
|
return _for(fields, obj, {
|
|
44
44
|
ne: (data, value) => data !== value,
|
|
45
|
-
gt: (data, value) => data > value,
|
|
46
|
-
lt: (data, value) => data < value,
|
|
47
|
-
gte: (data, value) => data >= value,
|
|
48
|
-
lte: (data, value) => data <= value,
|
|
45
|
+
gt: (data, value) => typeof data === typeof value && data > value,
|
|
46
|
+
lt: (data, value) => typeof data === typeof value && data < value,
|
|
47
|
+
gte: (data, value) => typeof data === typeof value && data >= value,
|
|
48
|
+
lte: (data, value) => typeof data === typeof value && data <= value,
|
|
49
49
|
in: (data, value) => value.includes(data),
|
|
50
50
|
nin: (data, value) => !value.includes(data),
|
|
51
51
|
type: (data, value) => typeof data === value,
|
|
@@ -67,7 +67,13 @@ function mainUpdate(obj, fields) {
|
|
|
67
67
|
return item.filter(i => !updater.includes(i));
|
|
68
68
|
},
|
|
69
69
|
merge: (item, updater) => {
|
|
70
|
-
if (
|
|
70
|
+
if (Array.isArray(item) && Array.isArray(updater)) {
|
|
71
|
+
return [...item, ...updater];
|
|
72
|
+
}
|
|
73
|
+
if (typeof item === "object" &&
|
|
74
|
+
typeof updater === "object" &&
|
|
75
|
+
!Array.isArray(item) &&
|
|
76
|
+
!Array.isArray(updater)) {
|
|
71
77
|
Object.assign(item, updater);
|
|
72
78
|
return item;
|
|
73
79
|
}
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = "0.12.0-alpha.
|
|
1
|
+
export const version = "0.12.0-alpha.2";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wxn0brp/db-core",
|
|
3
|
-
"version": "0.12.0-alpha.
|
|
3
|
+
"version": "0.12.0-alpha.2",
|
|
4
4
|
"types": "dist/index.d.ts",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"author": "wxn0brP",
|
|
@@ -13,11 +13,12 @@
|
|
|
13
13
|
},
|
|
14
14
|
"homepage": "https://github.com/wxn0brP/ValtheraDB",
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@wxn0brp/event-emitter": "0.0.
|
|
16
|
+
"@wxn0brp/event-emitter": "0.0.6"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
19
|
"@types/bun": "*",
|
|
20
20
|
"@types/node": "*",
|
|
21
|
+
"fast-check": "^4",
|
|
21
22
|
"tsc-alias": "^1",
|
|
22
23
|
"typescript": "^7"
|
|
23
24
|
},
|