@atscript/db-mongo 0.1.133 → 0.1.135
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/agg.cjs +10 -13
- package/dist/agg.mjs +11 -14
- package/package.json +4 -4
package/dist/agg.cjs
CHANGED
|
@@ -3,8 +3,8 @@ const require_mongo_filter = require("./mongo-filter-Bf5rWV4P.cjs");
|
|
|
3
3
|
let _atscript_db_agg = require("@atscript/db/agg");
|
|
4
4
|
let _uniqu_core = require("@uniqu/core");
|
|
5
5
|
//#region src/agg.ts
|
|
6
|
-
/**
|
|
7
|
-
const
|
|
6
|
+
/** `$group` accumulator per value aggregate (`count` is built below). */
|
|
7
|
+
const ACCUMULATORS = {
|
|
8
8
|
sum: "$sum",
|
|
9
9
|
avg: "$avg",
|
|
10
10
|
min: "$min",
|
|
@@ -14,17 +14,14 @@ const SIMPLE_ACCUMULATORS = {
|
|
|
14
14
|
* Maps an AggregateExpr to a MongoDB $group accumulator expression.
|
|
15
15
|
*/
|
|
16
16
|
function toAccumulator(expr) {
|
|
17
|
-
|
|
18
|
-
if (
|
|
19
|
-
if (expr.$
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
] } };
|
|
26
|
-
}
|
|
27
|
-
throw new Error(`Unsupported aggregate function: ${expr.$fn}`);
|
|
17
|
+
(0, _atscript_db_agg.assertAggregateFn)(expr.$fn);
|
|
18
|
+
if (expr.$fn !== "count") return { [ACCUMULATORS[expr.$fn]]: `$${expr.$field}` };
|
|
19
|
+
if (expr.$field === "*") return { $sum: 1 };
|
|
20
|
+
return { $sum: { $cond: [
|
|
21
|
+
{ $ne: [`$${expr.$field}`, null] },
|
|
22
|
+
1,
|
|
23
|
+
0
|
|
24
|
+
] } };
|
|
28
25
|
}
|
|
29
26
|
const DAY_MS = 864e5;
|
|
30
27
|
const ISO_DATE = "%Y-%m-%d";
|
package/dist/agg.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { t as buildMongoFilter } from "./mongo-filter-CtyITmZM.mjs";
|
|
2
|
-
import { resolveAlias } from "@atscript/db/agg";
|
|
2
|
+
import { assertAggregateFn, resolveAlias } from "@atscript/db/agg";
|
|
3
3
|
import { BUCKET_MAX_INSTANT, BUCKET_MIN_INSTANT } from "@uniqu/core";
|
|
4
4
|
//#region src/agg.ts
|
|
5
|
-
/**
|
|
6
|
-
const
|
|
5
|
+
/** `$group` accumulator per value aggregate (`count` is built below). */
|
|
6
|
+
const ACCUMULATORS = {
|
|
7
7
|
sum: "$sum",
|
|
8
8
|
avg: "$avg",
|
|
9
9
|
min: "$min",
|
|
@@ -13,17 +13,14 @@ const SIMPLE_ACCUMULATORS = {
|
|
|
13
13
|
* Maps an AggregateExpr to a MongoDB $group accumulator expression.
|
|
14
14
|
*/
|
|
15
15
|
function toAccumulator(expr) {
|
|
16
|
-
|
|
17
|
-
if (
|
|
18
|
-
if (expr.$
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
] } };
|
|
25
|
-
}
|
|
26
|
-
throw new Error(`Unsupported aggregate function: ${expr.$fn}`);
|
|
16
|
+
assertAggregateFn(expr.$fn);
|
|
17
|
+
if (expr.$fn !== "count") return { [ACCUMULATORS[expr.$fn]]: `$${expr.$field}` };
|
|
18
|
+
if (expr.$field === "*") return { $sum: 1 };
|
|
19
|
+
return { $sum: { $cond: [
|
|
20
|
+
{ $ne: [`$${expr.$field}`, null] },
|
|
21
|
+
1,
|
|
22
|
+
0
|
|
23
|
+
] } };
|
|
27
24
|
}
|
|
28
25
|
const DAY_MS = 864e5;
|
|
29
26
|
const ISO_DATE = "%Y-%m-%d";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atscript/db-mongo",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.135",
|
|
4
4
|
"description": "Mongodb plugin for atscript.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"atscript",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"@atscript/core": "^0.1.92",
|
|
50
50
|
"@atscript/typescript": "^0.1.92",
|
|
51
|
-
"@uniqu/core": "^0.1.
|
|
51
|
+
"@uniqu/core": "^0.1.11",
|
|
52
52
|
"mongodb": "^6.17.0",
|
|
53
53
|
"mongodb-memory-server-core": "^10.0.0",
|
|
54
54
|
"unplugin-atscript": "^0.1.92"
|
|
@@ -56,9 +56,9 @@
|
|
|
56
56
|
"peerDependencies": {
|
|
57
57
|
"@atscript/core": "^0.1.92",
|
|
58
58
|
"@atscript/typescript": "^0.1.92",
|
|
59
|
-
"@uniqu/core": "^0.1.
|
|
59
|
+
"@uniqu/core": "^0.1.11",
|
|
60
60
|
"mongodb": "^6.17.0",
|
|
61
|
-
"@atscript/db": "^0.1.
|
|
61
|
+
"@atscript/db": "^0.1.135"
|
|
62
62
|
},
|
|
63
63
|
"scripts": {
|
|
64
64
|
"postinstall": "asc -f dts",
|