@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.
Files changed (3) hide show
  1. package/dist/agg.cjs +10 -13
  2. package/dist/agg.mjs +11 -14
  3. 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
- /** Simple accumulators that map directly to `{ $<fn>: '$field' }`. */
7
- const SIMPLE_ACCUMULATORS = {
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
- const simple = SIMPLE_ACCUMULATORS[expr.$fn];
18
- if (simple) return { [simple]: `$${expr.$field}` };
19
- if (expr.$fn === "count") {
20
- if (expr.$field === "*") return { $sum: 1 };
21
- return { $sum: { $cond: [
22
- { $ne: [`$${expr.$field}`, null] },
23
- 1,
24
- 0
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
- /** Simple accumulators that map directly to `{ $<fn>: '$field' }`. */
6
- const SIMPLE_ACCUMULATORS = {
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
- const simple = SIMPLE_ACCUMULATORS[expr.$fn];
17
- if (simple) return { [simple]: `$${expr.$field}` };
18
- if (expr.$fn === "count") {
19
- if (expr.$field === "*") return { $sum: 1 };
20
- return { $sum: { $cond: [
21
- { $ne: [`$${expr.$field}`, null] },
22
- 1,
23
- 0
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.133",
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.10",
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.10",
59
+ "@uniqu/core": "^0.1.11",
60
60
  "mongodb": "^6.17.0",
61
- "@atscript/db": "^0.1.133"
61
+ "@atscript/db": "^0.1.135"
62
62
  },
63
63
  "scripts": {
64
64
  "postinstall": "asc -f dts",