@qingfu/core-env 0.2.8 → 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.
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/lib/utils.js CHANGED
@@ -50,9 +50,10 @@ utils.json2xlsx = ( json, mapping, type ) => {
50
50
  };
51
51
 
52
52
  utils.xlsx2json = ( buffer, mapping ) => {
53
- let workbook = xlsx.read( buffer, { type: 'buffer', cellDates: true });
53
+ let type = _.isString( buffer ) ? 'string' : 'buffer';
54
+ let workbook = xlsx.read( buffer, { type, cellDates: true });
54
55
  let worksheet = workbook.Sheets[ workbook.SheetNames[ 0 ]];
55
- let date1904 = workbook.Workbook.WBProps.date1904;
56
+ let date1904 = _.get( workbook, 'Workbook.WBProps.date1904' );
56
57
  function fixImportedDate( date, date1904 ) {
57
58
  let basedate = new Date( 1899, 11, 30, 0, 0, 0 );
58
59
  let dnthresh = basedate.getTime() + ( new Date().getTimezoneOffset() - basedate.getTimezoneOffset() ) * 60000;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qingfu/core-env",
3
- "version": "0.2.8",
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"