@qingfu/core-env 0.2.9 → 0.2.10

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 (2) hide show
  1. package/lib/database.js +5 -2
  2. package/package.json +4 -4
package/lib/database.js CHANGED
@@ -70,8 +70,9 @@ function summaryPlugin( schema, options = {}) {
70
70
  function statisticsPlugin( schema, options = {}) {
71
71
  let { timeFields = [], valueFields = [], sizeFields = [], forbidFields = [] } = options;
72
72
  schema.statics.statistics = async function( query = {}, opts = {}) {
73
- let { group = null, first = null, format = '%Y-%m-%d', timezone = process.env.TZ } = opts;
73
+ let { unwind = null, group = null, first = null, format = '%Y-%m-%d', timezone = process.env.TZ } = opts;
74
74
  if ( _.isObject( group )) throw new Error( 422 );
75
+ if ( forbidFields.some( v => _.includes( unwind, v ))) throw new Error( 422 );
75
76
  if ( forbidFields.some( v => _.includes( group, v ))) throw new Error( 422 );
76
77
  if ( forbidFields.some( v => _.includes( first, v ))) throw new Error( 422 );
77
78
  if ( _.isString( group )) {
@@ -95,7 +96,9 @@ function statisticsPlugin( schema, options = {}) {
95
96
  let keys = first.split( /\s+/ ).map( v => _.trimStart( v, '$' ));
96
97
  keys.forEach( v => { $group[ v ] = { $first: '$' + v }; });
97
98
  }
98
- let results = await this.aggregate([{ $match: query }, { $group }]);
99
+ let actions = [{ $match: query }, { $group }];
100
+ if ( _.isString( unwind )) actions.splice( 1, 0, { $unwind: '$' + unwind })
101
+ let results = await this.aggregate( actions );
99
102
  return group && results || results.length && _.omit( results[ 0 ], '_id' ) || defaultRes;
100
103
  };
101
104
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qingfu/core-env",
3
- "version": "0.2.9",
3
+ "version": "0.2.10",
4
4
  "readmeFilename": "README.md",
5
5
  "dependencies": {
6
6
  "@koa/cors": "4.0.0",
@@ -12,7 +12,7 @@
12
12
  "dotenv-extended": "2.9.0",
13
13
  "glob": "8.1.0",
14
14
  "ioredis": "4.28.5",
15
- "jsonwebtoken": "9.0.0",
15
+ "jsonwebtoken": "9.0.1",
16
16
  "koa": "2.14.2",
17
17
  "koa-bodyparser": "4.4.1",
18
18
  "koa-favicon": "2.1.0",
@@ -22,7 +22,7 @@
22
22
  "koa-qs": "3.0.0",
23
23
  "lodash": "4.17.21",
24
24
  "moleculer": "0.14.29",
25
- "mongoose": "7.3.1",
25
+ "mongoose": "7.3.2",
26
26
  "mongoose-cast-aggregation": "0.3.1",
27
27
  "mongoose-geojson-schema": "2.2.4",
28
28
  "mongoose-lean-defaults": "2.2.1",
@@ -36,7 +36,7 @@
36
36
  "qr-image": "3.2.0",
37
37
  "superagent": "8.0.9",
38
38
  "wechat-encrypt": "1.1.1",
39
- "winston": "3.9.0",
39
+ "winston": "3.10.0",
40
40
  "winston-mongodb": "5.1.1",
41
41
  "xlsx": "0.18.5",
42
42
  "xml2js": "0.4.23"