cgserver 12.2.4 → 12.2.6

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/README.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # 版本更新日志
2
2
 
3
+ ## v12.2.6
4
+ - mongo 新增 findOneAndUpdate 接口到处
5
+
6
+ ## v12.2.5
7
+ - Core 统一hash接口
8
+
3
9
  ## v12.2.4
4
10
  - mongo 添加了mongo的执行日志
5
11
 
@@ -369,29 +369,17 @@ class core {
369
369
  newStr += last;
370
370
  return newStr;
371
371
  }
372
- static md5(str, inputEncoding = null, encoding = "hex") {
373
- let _md5 = crypto.createHash('md5');
372
+ static hash(algorithm, str, inputEncoding = null, encoding = "hex") {
373
+ let _hash = crypto.createHash(algorithm);
374
374
  let hash = null;
375
375
  if (inputEncoding) {
376
- hash = _md5.update(str, inputEncoding);
376
+ hash = _hash.update(str, inputEncoding);
377
377
  }
378
378
  else {
379
- hash = _md5.update(str);
379
+ hash = _hash.update(str);
380
380
  }
381
- let md5_str = hash.digest(encoding);
382
- return md5_str;
383
- }
384
- static sha1(str, inputEncoding = null, encoding = "hex") {
385
- let _sha1 = crypto.createHash('sha1');
386
- let hash = null;
387
- if (inputEncoding) {
388
- hash = _sha1.update(str, inputEncoding);
389
- }
390
- else {
391
- hash = _sha1.update(str);
392
- }
393
- let sha1_str = hash.digest(encoding);
394
- return sha1_str;
381
+ let hash_str = hash.digest(encoding);
382
+ return hash_str;
395
383
  }
396
384
  static getLocalIP = function () {
397
385
  let iptable = {};
@@ -54,6 +54,10 @@ class MongoBaseService {
54
54
  let rs = await this.mongoDb.findOne(this._table, where, property);
55
55
  return rs.one;
56
56
  }
57
+ async findOneAndUpdate(where = null, update, options) {
58
+ let rs = await this.mongoDb.findOneAndUpdate(this._table, where, update, options);
59
+ return rs;
60
+ }
57
61
  async countDocuments(where = null, options) {
58
62
  let rs = await this.mongoDb.countDocuments(this._table, where);
59
63
  return rs.count;
@@ -698,6 +698,20 @@ class MongoExt {
698
698
  this._mongocfg.debug && Log_1.gLog.info({ key: "bulkWrite", dt, arguments });
699
699
  return bwr;
700
700
  }
701
+ async findOneAndUpdate(collection, filter, update, options) {
702
+ let now = Date.now();
703
+ let dt = 0;
704
+ if (!this._mongoDb) {
705
+ dt = Date.now() - now;
706
+ this._mongocfg.debug && Log_1.gLog.info({ key: "findOneAndUpdate", dt, arguments });
707
+ return;
708
+ }
709
+ let col = this._mongoDb.collection(collection);
710
+ let rs = await col.findOneAndUpdate(filter, update, options);
711
+ dt = Date.now() - now;
712
+ this._mongocfg.debug && Log_1.gLog.info({ key: "findOneAndUpdate", dt, arguments });
713
+ return rs;
714
+ }
701
715
  }
702
716
  exports.MongoExt = MongoExt;
703
717
  exports.gMongoMgr = new MongoManager();
@@ -42,8 +42,7 @@ export declare class core {
42
42
  * @param str
43
43
  */
44
44
  static fuzzy(str: string): string;
45
- static md5(str: string, inputEncoding?: crypto.Encoding, encoding?: crypto.BinaryToTextEncoding): string;
46
- static sha1(str: string, inputEncoding?: crypto.Encoding, encoding?: crypto.BinaryToTextEncoding): string;
45
+ static hash(algorithm: string, str: string, inputEncoding?: crypto.Encoding, encoding?: crypto.BinaryToTextEncoding): string;
47
46
  static getLocalIP: () => any;
48
47
  static getIP: () => Promise<string>;
49
48
  /**
@@ -27,6 +27,9 @@ export declare class MongoBaseService<T extends MongoBaseModel> {
27
27
  }, property?: {
28
28
  [key: string]: any;
29
29
  }): Promise<T>;
30
+ findOneAndUpdate(where: {
31
+ [key: string]: any;
32
+ }, update: any, options?: mongo.FindOneAndUpdateOptions): Promise<T>;
30
33
  countDocuments(where?: {
31
34
  [key: string]: any;
32
35
  }, options?: mongo.CountDocumentsOptions): Promise<number>;
@@ -205,5 +205,6 @@ export declare class MongoExt {
205
205
  */
206
206
  quickTransaction(cb: Function, options?: mongo.TransactionOptions): Promise<false | any>;
207
207
  bulkWrite(collection: string, operations: mongo.AnyBulkWriteOperation<mongo.BSON.Document>[], options?: mongo.BulkWriteOptions): Promise<mongo.BulkWriteResult>;
208
+ findOneAndUpdate(collection: string, filter: any, update: any, options?: mongo.FindOneAndUpdateOptions): Promise<any>;
208
209
  }
209
210
  export declare let gMongoMgr: MongoManager;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cgserver",
3
- "version": "12.2.4",
3
+ "version": "12.2.6",
4
4
  "author": "trojan",
5
5
  "type": "commonjs",
6
6
  "description": "free for all.Websocket or Http",