@wxn0brp/db-core 0.12.0-alpha.0 → 0.12.0-alpha.1

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.
@@ -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 => Number(d[srcField]))
101
- .filter(n => !Number.isNaN(n));
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 => Number(d[srcField]))
107
- .filter(n => !Number.isNaN(n));
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 => Number(d[srcField]))
113
- .filter(n => !Number.isNaN(n));
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 => Number(d[srcField]))
121
- .filter(n => !Number.isNaN(n));
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);
@@ -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,
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const version = "0.12.0-alpha.0";
1
+ export const version = "0.12.0-alpha.1";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wxn0brp/db-core",
3
- "version": "0.12.0-alpha.0",
3
+ "version": "0.12.0-alpha.1",
4
4
  "types": "dist/index.d.ts",
5
5
  "main": "dist/index.js",
6
6
  "author": "wxn0brP",
@@ -13,7 +13,7 @@
13
13
  },
14
14
  "homepage": "https://github.com/wxn0brP/ValtheraDB",
15
15
  "dependencies": {
16
- "@wxn0brp/event-emitter": "0.0.5"
16
+ "@wxn0brp/event-emitter": "0.0.6"
17
17
  },
18
18
  "devDependencies": {
19
19
  "@types/bun": "*",