@qingfu/core-env 0.1.17 → 0.1.20

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/broker.js CHANGED
@@ -1,6 +1,6 @@
1
1
  if ( process.env.BROKER_URI ) {
2
2
 
3
- const { ServiceBroker, Errors } = require( 'moleculer' );
3
+ const { ServiceBroker, Errors: { MoleculerError }} = require( 'moleculer' );
4
4
  const defaultTCP = { maxPacketSize: 20 * 1024 * 1024 };
5
5
  const namespaces = process.env.BROKER_NS.split( /,?\s+/ ).filter( Boolean );
6
6
  const transporters = process.env.BROKER_URI.split( /,?\s+/ ).filter( Boolean );
@@ -38,8 +38,10 @@ if ( process.env.BROKER_URI ) {
38
38
  nonce: ctx.meta.nonce,
39
39
  timestamp: ctx.meta.timestamp
40
40
  });
41
- if ( !nonce ) throw new Errors.MoleculerError(
42
- 'nonce or timestamp conflict', 409 );
41
+ if ( !nonce ) throw Object.assign(
42
+ new MoleculerError( 'NONCE_CONFLICT', 409 ),
43
+ { expose: true }
44
+ );
43
45
  }
44
46
  return await next( ctx );
45
47
  };
package/lib/helper.js CHANGED
@@ -57,7 +57,14 @@ helper.parseLike = ( ...fields ) => {
57
57
  let parse = data => {
58
58
  let regex = { $regex: data.like, $options: 'i' };
59
59
  let $or = fields.map( field => ({[ field ]: regex }));
60
- return Object.assign( data.like ? { $or } : {}, _.omit( data, 'like' ));
60
+ if ( !data.like ) {
61
+ return _.omit( data, 'like' );
62
+ } else if ( data.$or ) {
63
+ data.$or.forEach( v => Object.assign( v, { $or }));
64
+ return _.omit( data, 'like' );
65
+ } else {
66
+ return { $or, ..._.omit( data, 'like' )};
67
+ }
61
68
  };
62
69
  return async ( ctx, next ) => {
63
70
  if ( _.has( ctx.query, 'like' )) ctx.query = parse( ctx.query );
package/lib/utils.js CHANGED
@@ -1,10 +1,12 @@
1
- const _ = require( 'lodash' );
2
- const crypto = require( 'crypto' );
3
- const xml2js = require( 'xml2js' );
4
- const xlsx = require( 'xlsx' );
5
- const pinyin = require( 'pinyin' );
6
- const qrcode = require( 'qr-image' );
7
- const utils = global.utils = module.exports = {};
1
+ const fs = require( 'fs' );
2
+ const _ = require( 'lodash' );
3
+ const crypto = require( 'crypto' );
4
+ const xml2js = require( 'xml2js' );
5
+ const xlsx = require( 'xlsx' );
6
+ const pinyin = require( 'pinyin' );
7
+ const qrcode = require( 'qr-image' );
8
+ const request = require( 'superagent' );
9
+ const utils = global.utils = module.exports = {};
8
10
 
9
11
  utils.xml2json = async xml => {
10
12
  let options = { explicitRoot: false, explicitArray: false };
@@ -222,3 +224,18 @@ utils.identityValidate = identity => {
222
224
  if ( parity[ sum % 11 ] != identity[ 17 ]) return false;
223
225
  else return true;
224
226
  };
227
+
228
+ utils.fetchBig = async ({ url, dest, retry = 0 }) => {
229
+ try {
230
+ return await new Promise(( resolve, reject ) => {
231
+ let writeStream = fs.createWriteStream( dest );
232
+ let readStream = request.get( url );
233
+ readStream.pipe( writeStream );
234
+ readStream.on( 'error', reject );
235
+ writeStream.on( 'finish', resolve );
236
+ });
237
+ } catch ( err ) {
238
+ if ( !retry-- ) throw err;
239
+ return utils.fetchBig({ url, dest, retry });
240
+ }
241
+ };
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@qingfu/core-env",
3
- "version": "0.1.17",
3
+ "version": "0.1.20",
4
4
  "readmeFilename": "README.md",
5
5
  "dependencies": {
6
6
  "@koa/cors": "3.1.0",
7
7
  "@koa/router": "10.1.1",
8
- "bull": "4.5.4",
8
+ "bull": "4.6.2",
9
9
  "busboy": "0.3.1",
10
10
  "cookie": "0.4.2",
11
11
  "dotenv-extended": "2.9.0",
@@ -21,7 +21,7 @@
21
21
  "koa-qs": "3.0.0",
22
22
  "lodash": "4.17.21",
23
23
  "moleculer": "0.14.19",
24
- "mongoose": "6.2.1",
24
+ "mongoose": "6.2.4",
25
25
  "mongoose-cast-aggregation": "0.2.1",
26
26
  "mongoose-geojson-schema": "2.1.7",
27
27
  "mongoose-lean-defaults": "2.1.0",
@@ -29,7 +29,7 @@
29
29
  "mongoose-lean-virtuals": "0.9.0",
30
30
  "ms": "2.1.3",
31
31
  "notepack.io": "2.3.0",
32
- "pinyin": "2.10.2",
32
+ "pinyin": "2.11.0",
33
33
  "primus": "8.0.5",
34
34
  "primus-rooms": "3.4.1",
35
35
  "qr-image": "3.2.0",