cgserver 8.9.13 → 8.9.15

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,3 +1,7 @@
1
+ 8.9.15
2
+ 1、暴露mongo的objectid
3
+ 8.9.14
4
+ 1、字节操作能力
1
5
  8.9.13
2
6
  1、protofilter 可扩展
3
7
  8.9.6
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GByteTool = void 0;
4
+ class ByteTool {
5
+ //构建一个视图,把字节数组写到缓存中,索引从0开始
6
+ getView(bytes) {
7
+ var view = new DataView(new ArrayBuffer(bytes.length));
8
+ for (var i = 0; i < bytes.length; i++) {
9
+ view.setUint8(i, bytes[i]);
10
+ }
11
+ return view;
12
+ }
13
+ //将字节数组转成有符号的8位整型
14
+ toInt8(bytes, offset = 0) {
15
+ return this.getView(bytes).getInt8(offset);
16
+ }
17
+ //将字节数组转成无符号的8位整型
18
+ toUint8(bytes, offset = 0) {
19
+ return this.getView(bytes).getUint8(offset);
20
+ }
21
+ //将字节数组转成有符号的16位整型
22
+ toInt16(bytes, offset = 0, littleEndian = false) {
23
+ return this.getView(bytes).getInt16(offset, littleEndian);
24
+ }
25
+ //将字节数组转成无符号的16位整型
26
+ toUint16(bytes, offset = 0, littleEndian = false) {
27
+ return this.getView(bytes).getUint16(offset, littleEndian);
28
+ }
29
+ //将字节数组转成有符号的32位整型
30
+ toInt32(bytes, offset = 0, littleEndian = false) {
31
+ return this.getView(bytes).getInt32(offset, littleEndian);
32
+ }
33
+ //将字节数组转成无符号的32位整型
34
+ toUint32(bytes, offset = 0, littleEndian = false) {
35
+ return this.getView(bytes).getUint32(offset, littleEndian);
36
+ }
37
+ //将字节数组转成32位浮点型
38
+ toFloat32(bytes, offset = 0, littleEndian = false) {
39
+ return this.getView(bytes).getFloat32(offset, littleEndian);
40
+ }
41
+ //将字节数组转成64位浮点型
42
+ toFloat64(bytes, offset = 0, littleEndian = false) {
43
+ return this.getView(bytes).getFloat64(offset, littleEndian);
44
+ }
45
+ //将数值写入到视图中,获得其字节数组
46
+ getUint8Array(len, setNum) {
47
+ var buffer = new ArrayBuffer(len); //指定字节长度
48
+ setNum(new DataView(buffer)); //根据不同的类型调用不同的函数来写入数值
49
+ return new Uint8Array(buffer); //创建一个字节数组,从缓存中拿取数据
50
+ }
51
+ //得到一个8位有符号整型的字节数组
52
+ getInt8Bytes(num) {
53
+ return this.getUint8Array(1, (view) => { view.setInt8(0, num); });
54
+ }
55
+ //得到一个8位无符号整型的字节数组
56
+ getUint8Bytes(num) {
57
+ return this.getUint8Array(1, (view) => { view.setUint8(0, num); });
58
+ }
59
+ //得到一个16位有符号整型的字节数组
60
+ getInt16Bytes(num, littleEndian = false) {
61
+ return this.getUint8Array(2, (view) => { view.setInt16(0, num, littleEndian); });
62
+ }
63
+ //得到一个16位无符号整型的字节数组
64
+ getUint16Bytes(num, littleEndian = false) {
65
+ return this.getUint8Array(2, (view) => { view.setUint16(0, num, littleEndian); });
66
+ }
67
+ //得到一个32位有符号整型的字节数组
68
+ getInt32Bytes(num, littleEndian = false) {
69
+ return this.getUint8Array(4, (view) => { view.setInt32(0, num, littleEndian); });
70
+ }
71
+ //得到一个32位无符号整型的字节数组
72
+ getUint32Bytes(num, littleEndian = false) {
73
+ return this.getUint8Array(4, (view) => { view.setUint32(0, num, littleEndian); });
74
+ }
75
+ //得到一个32位浮点型的字节数组
76
+ getFloat32Bytes(num, littleEndian = false) {
77
+ return this.getUint8Array(4, (view) => { view.setFloat32(0, num, littleEndian); });
78
+ }
79
+ //得到一个64位浮点型的字节数组
80
+ getFloat64Bytes(num, littleEndian = false) {
81
+ return this.getUint8Array(8, (view) => { view.setFloat64(0, num, littleEndian); });
82
+ }
83
+ }
84
+ exports.GByteTool = new ByteTool();
@@ -26,6 +26,9 @@ class MongoBaseService {
26
26
  let id = await MongoManager_1.GMongoMgr.getAutoIds(this._table);
27
27
  return id;
28
28
  }
29
+ toObjectId(id) {
30
+ return MongoManager_1.GMongoMgr.toObjectId(id);
31
+ }
29
32
  /**
30
33
  * 没有id(非_id)的表不能使用该函数
31
34
  * @param id
@@ -133,7 +133,7 @@ class MongoManager {
133
133
  if (Core_1.core.isString(where._id) && where._id.length == 24) {
134
134
  let _id = where._id;
135
135
  try {
136
- where._id = new mongo.ObjectId(_id);
136
+ where._id = this.toObjectId(_id);
137
137
  }
138
138
  catch (e) {
139
139
  where._id = _id;
@@ -141,6 +141,9 @@ class MongoManager {
141
141
  }
142
142
  return where;
143
143
  }
144
+ toObjectId(id) {
145
+ return new mongo.ObjectId(id);
146
+ }
144
147
  /**
145
148
  * 获取单条消息
146
149
  * @param collection
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MongoCacheModel = exports.GMongoCacheSer = exports.MongoUserModel = exports.MysqlUserModel = exports.MongoUserService = exports.MysqlUserService = exports.MongoAccountService = exports.MysqlAccountService = exports.EAccountFrom = exports.EUserState = exports.ERoleGroup = exports.GLog = exports.GHttpTool = exports.GCacheTool = exports.RedisManager = exports.GRedisMgr = exports.SqlReturns = exports.SqlReturn = exports.SqlResult = exports.GMysqlMgr = exports.MysqlBaseService = exports.GMSSqlMgr = exports.GMongoMgr = exports.MongoManager = exports.MongoBaseModel = exports.MysqlBaseModel = exports.MongoBaseService = exports.EPropertyType = exports.Type = exports.Table = exports.Property = exports.PrimaryKey = exports.NotNull = exports.AutoIncrement = exports.Timer = exports.core = exports.GServerCfg = exports.IServerConfig = exports.FrameworkConfig = exports.Config = exports.FrameworkErrorCode = exports.GTriggerMgr = exports.Trigger = exports.Point = exports.Entity = exports.BehaviorAI = exports.AStar = exports.AiObject = exports.GDBCache = exports.GCgServer = void 0;
4
4
  exports.CgMq = exports.RpcConfig = exports.Rpc = exports.RpcBaseMsg = exports.EAccountState = exports.GEventTool = exports.GSyncQueueTool = exports.WebServerConfig = exports.Response = exports.Request = exports.RazorJs = exports.Engine = exports.GCtrMgr = exports.JsonCreatorValidate = exports.JsonAuthorityValidate = exports.JsonAdminValidate = exports.CreatorValidate = exports.AuthorityValidate = exports.AdminValidate = exports.MongoAccountModel = exports.MysqlAccountModel = exports.MongoBaseUserController = exports.MysqlBaseUserController = exports.BaseController = exports.IWebServer = exports.GWechatTool = exports.GWechatOATool = exports.GQQTool = exports.GQiniuTool = exports.GOpenSocial = exports.GEmailTool = exports.GAppleTool = exports.GSmsTool = exports.AlipayCallBack = exports.AlipayResult = exports.GAlipayTool = exports.BaseMsg = exports.IWebSocket = exports.ISocketServer = exports.IClientWebSocket = exports.IServerWebSocket = exports.JsonProtoFilter = exports.GoogleProtoFilter = exports.EProtoType = exports.GProtoFactory = exports.RedisConfig = exports.MysqlConfig = exports.MongoConfig = exports.MSSqlConfig = exports.DbConfig = void 0;
5
- exports.SyncCallServer2 = exports.SyncCallServer = exports.SyncCall2 = exports.SyncCall = exports.IRpcClientWebSocket = exports.IRpcServerWebSocket = exports.CgMqConfig = void 0;
5
+ exports.GByteTool = exports.SyncCallServer2 = exports.SyncCallServer = exports.SyncCall2 = exports.SyncCall = exports.IRpcClientWebSocket = exports.IRpcServerWebSocket = exports.CgMqConfig = void 0;
6
6
  var cgserver_1 = require("./cgserver");
7
7
  Object.defineProperty(exports, "GCgServer", { enumerable: true, get: function () { return cgserver_1.GCgServer; } });
8
8
  var DBCache_1 = require("./Database/Decorator/DBCache");
@@ -200,3 +200,5 @@ Object.defineProperty(exports, "SyncCall2", { enumerable: true, get: function ()
200
200
  var SyncCallServer_1 = require("./Decorator/SyncCallServer");
201
201
  Object.defineProperty(exports, "SyncCallServer", { enumerable: true, get: function () { return SyncCallServer_1.SyncCallServer; } });
202
202
  Object.defineProperty(exports, "SyncCallServer2", { enumerable: true, get: function () { return SyncCallServer_1.SyncCallServer2; } });
203
+ var ByteTool_1 = require("./Core/ByteTool");
204
+ Object.defineProperty(exports, "GByteTool", { enumerable: true, get: function () { return ByteTool_1.GByteTool; } });
@@ -0,0 +1,22 @@
1
+ declare class ByteTool {
2
+ getView(bytes: Uint8Array): DataView;
3
+ toInt8(bytes: Uint8Array, offset?: number): number;
4
+ toUint8(bytes: Uint8Array, offset?: number): number;
5
+ toInt16(bytes: Uint8Array, offset?: number, littleEndian?: boolean): number;
6
+ toUint16(bytes: Uint8Array, offset?: number, littleEndian?: boolean): number;
7
+ toInt32(bytes: Uint8Array, offset?: number, littleEndian?: boolean): number;
8
+ toUint32(bytes: Uint8Array, offset?: number, littleEndian?: boolean): number;
9
+ toFloat32(bytes: Uint8Array, offset?: number, littleEndian?: boolean): number;
10
+ toFloat64(bytes: Uint8Array, offset?: number, littleEndian?: boolean): number;
11
+ getUint8Array(len: number, setNum: (view: DataView) => void): Uint8Array;
12
+ getInt8Bytes(num: number): Uint8Array;
13
+ getUint8Bytes(num: number): Uint8Array;
14
+ getInt16Bytes(num: number, littleEndian?: boolean): Uint8Array;
15
+ getUint16Bytes(num: number, littleEndian?: boolean): Uint8Array;
16
+ getInt32Bytes(num: number, littleEndian?: boolean): Uint8Array;
17
+ getUint32Bytes(num: number, littleEndian?: boolean): Uint8Array;
18
+ getFloat32Bytes(num: number, littleEndian?: boolean): Uint8Array;
19
+ getFloat64Bytes(num: number, littleEndian?: boolean): Uint8Array;
20
+ }
21
+ export declare let GByteTool: ByteTool;
22
+ export {};
@@ -12,6 +12,7 @@ export declare class MongoBaseService<T> {
12
12
  new (): T;
13
13
  });
14
14
  getNextId(key?: string): Promise<number>;
15
+ toObjectId(id: string): mongo.BSON.ObjectId;
15
16
  /**
16
17
  * 没有id(非_id)的表不能使用该函数
17
18
  * @param id
@@ -7,7 +7,7 @@ export declare class MongoConfig {
7
7
  database: string;
8
8
  }
9
9
  export declare class MongoBaseModel {
10
- _id: any;
10
+ _id: mongo.ObjectId;
11
11
  }
12
12
  export declare class MrResult {
13
13
  /**
@@ -59,6 +59,7 @@ export declare class MongoManager {
59
59
  */
60
60
  getAutoIds(key: string): Promise<number>;
61
61
  protected _convertWhere(where?: any): any;
62
+ toObjectId(id: string): mongo.BSON.ObjectId;
62
63
  /**
63
64
  * 获取单条消息
64
65
  * @param collection
@@ -89,3 +89,4 @@ export { IRpcServerWebSocket } from './SocketServer/IRpcServerWebSocket';
89
89
  export { IRpcClientWebSocket } from './SocketServer/IRpcClientWebSocket';
90
90
  export { SyncCall, SyncCall2 } from './Decorator/SyncCall';
91
91
  export { SyncCallServer, SyncCallServer2 } from './Decorator/SyncCallServer';
92
+ export { GByteTool } from './Core/ByteTool';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cgserver",
3
- "version": "8.9.13",
3
+ "version": "8.9.15",
4
4
  "author": "trojan",
5
5
  "type": "commonjs",
6
6
  "description": "free for all.Websocket or Http",