@cloudbase/database 1.4.3-alpha.0 → 1.5.0

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 (194) hide show
  1. package/dist/commonjs/ObjectId/index.d.ts +1 -1
  2. package/dist/commonjs/ObjectId/index.js +16 -9
  3. package/dist/commonjs/aggregate.js +126 -75
  4. package/dist/commonjs/collection.d.ts +3 -2
  5. package/dist/commonjs/collection.js +131 -58
  6. package/dist/commonjs/command.d.ts +5 -5
  7. package/dist/commonjs/command.js +181 -154
  8. package/dist/commonjs/commands/logic.js +30 -20
  9. package/dist/commonjs/commands/query.d.ts +1 -1
  10. package/dist/commonjs/commands/query.js +85 -65
  11. package/dist/commonjs/commands/update.js +9 -7
  12. package/dist/commonjs/config/error.config.js +1 -0
  13. package/dist/commonjs/const/code.js +1 -0
  14. package/dist/commonjs/constant.d.ts +7 -7
  15. package/dist/commonjs/constant.js +13 -11
  16. package/dist/commonjs/document.d.ts +10 -6
  17. package/dist/commonjs/document.js +305 -193
  18. package/dist/commonjs/geo/index.js +20 -9
  19. package/dist/commonjs/geo/lineString.d.ts +1 -1
  20. package/dist/commonjs/geo/lineString.js +62 -33
  21. package/dist/commonjs/geo/multiLineString.d.ts +1 -1
  22. package/dist/commonjs/geo/multiLineString.js +71 -32
  23. package/dist/commonjs/geo/multiPoint.d.ts +1 -1
  24. package/dist/commonjs/geo/multiPoint.js +58 -29
  25. package/dist/commonjs/geo/multiPolygon.d.ts +1 -1
  26. package/dist/commonjs/geo/multiPolygon.js +96 -36
  27. package/dist/commonjs/geo/point.d.ts +1 -1
  28. package/dist/commonjs/geo/point.js +30 -23
  29. package/dist/commonjs/geo/polygon.d.ts +1 -1
  30. package/dist/commonjs/geo/polygon.js +78 -39
  31. package/dist/commonjs/helper/symbol.js +17 -5
  32. package/dist/commonjs/index.d.ts +8 -2
  33. package/dist/commonjs/index.js +73 -20
  34. package/dist/commonjs/lib/util.js +4 -3
  35. package/dist/commonjs/operator-map.js +7 -6
  36. package/dist/commonjs/query.d.ts +8 -4
  37. package/dist/commonjs/query.js +308 -201
  38. package/dist/commonjs/regexp/index.d.ts +1 -1
  39. package/dist/commonjs/regexp/index.js +16 -9
  40. package/dist/commonjs/serializer/common.d.ts +2 -2
  41. package/dist/commonjs/serializer/common.js +59 -22
  42. package/dist/commonjs/serializer/datatype.d.ts +2 -2
  43. package/dist/commonjs/serializer/datatype.js +58 -21
  44. package/dist/commonjs/serializer/query.d.ts +1 -1
  45. package/dist/commonjs/serializer/query.js +137 -127
  46. package/dist/commonjs/serializer/update.d.ts +1 -1
  47. package/dist/commonjs/serializer/update.js +83 -78
  48. package/dist/commonjs/serverDate/index.d.ts +1 -1
  49. package/dist/commonjs/serverDate/index.js +16 -9
  50. package/dist/commonjs/transaction/collection.d.ts +1 -1
  51. package/dist/commonjs/transaction/collection.js +5 -2
  52. package/dist/commonjs/transaction/document.d.ts +1 -1
  53. package/dist/commonjs/transaction/document.js +5 -5
  54. package/dist/commonjs/transaction/index.js +196 -86
  55. package/dist/commonjs/transaction/query.d.ts +39 -1
  56. package/dist/commonjs/transaction/query.js +252 -1
  57. package/dist/commonjs/typings/index.d.ts +4 -4
  58. package/dist/commonjs/typings/realtime.d.ts +16 -16
  59. package/dist/commonjs/util.js +123 -92
  60. package/dist/commonjs/utils/error.d.ts +2 -1
  61. package/dist/commonjs/utils/error.js +74 -38
  62. package/dist/commonjs/utils/symbol.js +33 -14
  63. package/dist/commonjs/utils/type.d.ts +1 -1
  64. package/dist/commonjs/utils/type.js +25 -13
  65. package/dist/commonjs/utils/utils.d.ts +4 -1
  66. package/dist/commonjs/utils/utils.js +93 -22
  67. package/dist/commonjs/validate.js +79 -63
  68. package/dist/esm/ObjectId/index.d.ts +1 -1
  69. package/dist/esm/ObjectId/index.js +15 -8
  70. package/dist/esm/aggregate.js +118 -66
  71. package/dist/esm/collection.d.ts +3 -2
  72. package/dist/esm/collection.js +125 -52
  73. package/dist/esm/command.d.ts +5 -5
  74. package/dist/esm/command.js +175 -147
  75. package/dist/esm/commands/logic.js +30 -20
  76. package/dist/esm/commands/query.d.ts +1 -1
  77. package/dist/esm/commands/query.js +91 -71
  78. package/dist/esm/commands/update.js +8 -6
  79. package/dist/esm/config/error.config.js +1 -1
  80. package/dist/esm/const/code.js +1 -1
  81. package/dist/esm/constant.d.ts +7 -7
  82. package/dist/esm/constant.js +12 -11
  83. package/dist/esm/document.d.ts +10 -6
  84. package/dist/esm/document.js +297 -185
  85. package/dist/esm/geo/interface.js +1 -0
  86. package/dist/esm/geo/lineString.d.ts +1 -1
  87. package/dist/esm/geo/lineString.js +57 -28
  88. package/dist/esm/geo/multiLineString.d.ts +1 -1
  89. package/dist/esm/geo/multiLineString.js +66 -27
  90. package/dist/esm/geo/multiPoint.d.ts +1 -1
  91. package/dist/esm/geo/multiPoint.js +53 -24
  92. package/dist/esm/geo/multiPolygon.d.ts +1 -1
  93. package/dist/esm/geo/multiPolygon.js +91 -31
  94. package/dist/esm/geo/point.d.ts +1 -1
  95. package/dist/esm/geo/point.js +26 -19
  96. package/dist/esm/geo/polygon.d.ts +1 -1
  97. package/dist/esm/geo/polygon.js +73 -34
  98. package/dist/esm/helper/symbol.js +13 -13
  99. package/dist/esm/index.d.ts +8 -2
  100. package/dist/esm/index.js +62 -9
  101. package/dist/esm/lib/util.js +1 -2
  102. package/dist/esm/operator-map.js +4 -4
  103. package/dist/esm/query.d.ts +8 -4
  104. package/dist/esm/query.js +299 -192
  105. package/dist/esm/regexp/index.d.ts +1 -1
  106. package/dist/esm/regexp/index.js +15 -8
  107. package/dist/esm/serializer/common.d.ts +2 -2
  108. package/dist/esm/serializer/common.js +49 -13
  109. package/dist/esm/serializer/datatype.d.ts +2 -2
  110. package/dist/esm/serializer/datatype.js +44 -8
  111. package/dist/esm/serializer/query.d.ts +1 -1
  112. package/dist/esm/serializer/query.js +112 -102
  113. package/dist/esm/serializer/update.d.ts +1 -1
  114. package/dist/esm/serializer/update.js +69 -64
  115. package/dist/esm/serverDate/index.d.ts +1 -1
  116. package/dist/esm/serverDate/index.js +15 -8
  117. package/dist/esm/transaction/collection.d.ts +1 -1
  118. package/dist/esm/transaction/collection.js +4 -2
  119. package/dist/esm/transaction/document.d.ts +1 -1
  120. package/dist/esm/transaction/document.js +2 -3
  121. package/dist/esm/transaction/index.js +191 -81
  122. package/dist/esm/transaction/query.d.ts +39 -1
  123. package/dist/esm/transaction/query.js +251 -1
  124. package/dist/esm/typings/index.d.ts +4 -4
  125. package/dist/esm/typings/index.js +1 -0
  126. package/dist/esm/typings/realtime.d.ts +16 -16
  127. package/dist/esm/typings/realtime.js +1 -0
  128. package/dist/esm/util.js +121 -90
  129. package/dist/esm/utils/error.d.ts +2 -1
  130. package/dist/esm/utils/error.js +70 -35
  131. package/dist/esm/utils/symbol.js +33 -14
  132. package/dist/esm/utils/type.d.ts +1 -1
  133. package/dist/esm/utils/type.js +12 -12
  134. package/dist/esm/utils/utils.d.ts +4 -1
  135. package/dist/esm/utils/utils.js +78 -16
  136. package/dist/esm/validate.js +65 -49
  137. package/jest.config.js +14 -0
  138. package/package.json +14 -10
  139. package/src/aggregate.ts +1 -5
  140. package/src/collection.ts +15 -2
  141. package/src/document.ts +45 -34
  142. package/src/index.ts +51 -4
  143. package/src/query.ts +33 -29
  144. package/src/serializer/query.ts +18 -6
  145. package/src/transaction/index.ts +1 -1
  146. package/src/typings/index.ts +0 -4
  147. package/src/utils/utils.ts +46 -0
  148. package/src/validate.ts +3 -6
  149. package/tests/gateway-contract.test.ts +180 -0
  150. package/tests/index.test.ts +283 -0
  151. package/tests/transaction-query.test.ts +207 -0
  152. package/tsconfig.esm.json +4 -2
  153. package/tsconfig.json +16 -6
  154. package/tsconfig.test.json +15 -0
  155. package/dist/commonjs/realtime/error.d.ts +0 -7
  156. package/dist/commonjs/realtime/error.js +0 -11
  157. package/dist/commonjs/realtime/listener.d.ts +0 -14
  158. package/dist/commonjs/realtime/listener.js +0 -17
  159. package/dist/commonjs/realtime/message.d.ts +0 -3
  160. package/dist/commonjs/realtime/message.js +0 -10
  161. package/dist/commonjs/realtime/snapshot.d.ts +0 -16
  162. package/dist/commonjs/realtime/snapshot.js +0 -42
  163. package/dist/commonjs/realtime/virtual-websocket-client.d.ts +0 -63
  164. package/dist/commonjs/realtime/virtual-websocket-client.js +0 -736
  165. package/dist/commonjs/realtime/websocket-client.d.ts +0 -78
  166. package/dist/commonjs/realtime/websocket-client.js +0 -567
  167. package/dist/commonjs/realtime/ws-event.d.ts +0 -126
  168. package/dist/commonjs/realtime/ws-event.js +0 -139
  169. package/dist/commonjs/transaction.d.ts +0 -42
  170. package/dist/commonjs/transaction.js +0 -126
  171. package/dist/esm/realtime/error.d.ts +0 -7
  172. package/dist/esm/realtime/error.js +0 -8
  173. package/dist/esm/realtime/listener.d.ts +0 -14
  174. package/dist/esm/realtime/listener.js +0 -14
  175. package/dist/esm/realtime/message.d.ts +0 -3
  176. package/dist/esm/realtime/message.js +0 -6
  177. package/dist/esm/realtime/snapshot.d.ts +0 -16
  178. package/dist/esm/realtime/snapshot.js +0 -39
  179. package/dist/esm/realtime/virtual-websocket-client.d.ts +0 -63
  180. package/dist/esm/realtime/virtual-websocket-client.js +0 -733
  181. package/dist/esm/realtime/websocket-client.d.ts +0 -78
  182. package/dist/esm/realtime/websocket-client.js +0 -564
  183. package/dist/esm/realtime/ws-event.d.ts +0 -126
  184. package/dist/esm/realtime/ws-event.js +0 -137
  185. package/dist/esm/transaction.d.ts +0 -42
  186. package/dist/esm/transaction.js +0 -121
  187. package/src/realtime/error.ts +0 -19
  188. package/src/realtime/listener.ts +0 -35
  189. package/src/realtime/message.ts +0 -14
  190. package/src/realtime/snapshot.ts +0 -60
  191. package/src/realtime/virtual-websocket-client.ts +0 -1195
  192. package/src/realtime/websocket-client.ts +0 -995
  193. package/src/realtime/ws-event.ts +0 -163
  194. package/src/transaction.ts +0 -190
@@ -1,49 +1,84 @@
1
+ var __extends = (this && this.__extends) || (function () {
2
+ var extendStatics = function (d, b) {
3
+ extendStatics = Object.setPrototypeOf ||
4
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
6
+ return extendStatics(d, b);
7
+ };
8
+ return function (d, b) {
9
+ if (typeof b !== "function" && b !== null)
10
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
11
+ extendStatics(d, b);
12
+ function __() { this.constructor = d; }
13
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
14
+ };
15
+ })();
1
16
  import { isString } from './type';
2
17
  import { ERR_CODE } from '../config/error.config';
3
- export class CloudSDKError extends Error {
4
- constructor(options) {
5
- super(options.errMsg);
6
- this.errCode = 'UNKNOWN_ERROR';
7
- Object.defineProperties(this, {
18
+ var CloudSDKError = (function (_super) {
19
+ __extends(CloudSDKError, _super);
20
+ function CloudSDKError(options) {
21
+ var _this = _super.call(this, options.errMsg) || this;
22
+ _this.errCode = 'UNKNOWN_ERROR';
23
+ Object.defineProperties(_this, {
8
24
  message: {
9
- get() {
10
- return (`errCode: ${this.errCode} ${ERR_CODE[this.errCode] ||
11
- ''} | errMsg: ` + this.errMsg);
25
+ get: function () {
26
+ return ("errCode: ".concat(this.errCode, " ").concat(ERR_CODE[this.errCode] ||
27
+ '', " | errMsg: ") + this.errMsg);
12
28
  },
13
- set(msg) {
29
+ set: function (msg) {
14
30
  this.errMsg = msg;
15
31
  }
16
32
  }
17
33
  });
18
- this.errCode = options.errCode || 'UNKNOWN_ERROR';
19
- this.errMsg = options.errMsg;
34
+ _this.errCode = options.errCode || 'UNKNOWN_ERROR';
35
+ _this.errMsg = options.errMsg;
36
+ return _this;
20
37
  }
21
- get message() {
22
- return `errCode: ${this.errCode} | errMsg: ` + this.errMsg;
23
- }
24
- set message(msg) {
25
- this.errMsg = msg;
26
- }
27
- }
38
+ Object.defineProperty(CloudSDKError.prototype, "message", {
39
+ get: function () {
40
+ return "errCode: ".concat(this.errCode, " | errMsg: ") + this.errMsg;
41
+ },
42
+ set: function (msg) {
43
+ this.errMsg = msg;
44
+ },
45
+ enumerable: false,
46
+ configurable: true
47
+ });
48
+ return CloudSDKError;
49
+ }(Error));
50
+ export { CloudSDKError };
28
51
  export function isSDKError(error) {
29
52
  return (error && error instanceof Error && isString(error.errMsg));
30
53
  }
31
- export const isGenericError = (e) => e.generic;
32
- export class TimeoutError extends Error {
33
- constructor(message) {
34
- super(message);
35
- this.type = 'timeout';
36
- this.payload = null;
37
- this.generic = true;
54
+ export var isGenericError = function (e) { return e.generic; };
55
+ var TimeoutError = (function (_super) {
56
+ __extends(TimeoutError, _super);
57
+ function TimeoutError(message) {
58
+ var _this = _super.call(this, message) || this;
59
+ _this.type = 'timeout';
60
+ _this.payload = null;
61
+ _this.generic = true;
62
+ return _this;
38
63
  }
39
- }
40
- export const isTimeoutError = (e) => e.type === 'timeout';
41
- export class CancelledError extends Error {
42
- constructor(message) {
43
- super(message);
44
- this.type = 'cancelled';
45
- this.payload = null;
46
- this.generic = true;
64
+ return TimeoutError;
65
+ }(Error));
66
+ export { TimeoutError };
67
+ export var isTimeoutError = function (e) {
68
+ return e.type === 'timeout';
69
+ };
70
+ var CancelledError = (function (_super) {
71
+ __extends(CancelledError, _super);
72
+ function CancelledError(message) {
73
+ var _this = _super.call(this, message) || this;
74
+ _this.type = 'cancelled';
75
+ _this.payload = null;
76
+ _this.generic = true;
77
+ return _this;
47
78
  }
48
- }
49
- export const isCancelledError = (e) => e.type === 'cancelled';
79
+ return CancelledError;
80
+ }(Error));
81
+ export { CancelledError };
82
+ export var isCancelledError = function (e) {
83
+ return e.type === 'cancelled';
84
+ };
@@ -1,7 +1,22 @@
1
- const _symbols = [];
2
- const __internalMark__ = {};
3
- class HiddenSymbol {
4
- constructor(target) {
1
+ var __extends = (this && this.__extends) || (function () {
2
+ var extendStatics = function (d, b) {
3
+ extendStatics = Object.setPrototypeOf ||
4
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
6
+ return extendStatics(d, b);
7
+ };
8
+ return function (d, b) {
9
+ if (typeof b !== "function" && b !== null)
10
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
11
+ extendStatics(d, b);
12
+ function __() { this.constructor = d; }
13
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
14
+ };
15
+ })();
16
+ var _symbols = [];
17
+ var __internalMark__ = {};
18
+ var HiddenSymbol = (function () {
19
+ function HiddenSymbol(target) {
5
20
  Object.defineProperties(this, {
6
21
  target: {
7
22
  enumerable: false,
@@ -11,26 +26,30 @@ class HiddenSymbol {
11
26
  },
12
27
  });
13
28
  }
14
- }
15
- export class InternalSymbol extends HiddenSymbol {
16
- constructor(target, __mark__) {
29
+ return HiddenSymbol;
30
+ }());
31
+ var InternalSymbol = (function (_super) {
32
+ __extends(InternalSymbol, _super);
33
+ function InternalSymbol(target, __mark__) {
17
34
  if (__mark__ !== __internalMark__) {
18
35
  throw new TypeError('InternalSymbol cannot be constructed with new operator');
19
36
  }
20
- super(target);
37
+ return _super.call(this, target) || this;
21
38
  }
22
- static for(target) {
23
- for (let i = 0, len = _symbols.length; i < len; i++) {
39
+ InternalSymbol.for = function (target) {
40
+ for (var i = 0, len = _symbols.length; i < len; i++) {
24
41
  if (_symbols[i].target === target) {
25
42
  return _symbols[i].instance;
26
43
  }
27
44
  }
28
- const symbol = new InternalSymbol(target, __internalMark__);
45
+ var symbol = new InternalSymbol(target, __internalMark__);
29
46
  _symbols.push({
30
- target,
47
+ target: target,
31
48
  instance: symbol,
32
49
  });
33
50
  return symbol;
34
- }
35
- }
51
+ };
52
+ return InternalSymbol;
53
+ }(HiddenSymbol));
54
+ export { InternalSymbol };
36
55
  export default InternalSymbol;
@@ -3,7 +3,7 @@ export declare const isObject: <T extends object>(x: any) => x is T;
3
3
  export declare const isString: (x: any) => x is string;
4
4
  export declare const isNumber: (x: any) => x is number;
5
5
  export declare const isPromise: <T extends Promise<any> = Promise<any>>(x: any) => x is T;
6
- declare type AnyFn = (...args: any[]) => any;
6
+ type AnyFn = (...args: any[]) => any;
7
7
  export declare const isFunction: <T extends AnyFn = AnyFn>(x: any) => x is T;
8
8
  export declare const isArray: <T extends any[] = any[]>(x: any) => x is T;
9
9
  export declare const isDate: (x: any) => x is Date;
@@ -1,18 +1,18 @@
1
1
  import { InternalSymbol } from './symbol';
2
- export const getType = (x) => Object.prototype.toString.call(x).slice(8, -1).toLowerCase();
3
- export const isObject = (x) => getType(x) === 'object';
4
- export const isString = (x) => getType(x) === 'string';
5
- export const isNumber = (x) => getType(x) === 'number';
6
- export const isPromise = (x) => getType(x) === 'promise';
7
- export const isFunction = (x) => typeof x === 'function';
8
- export const isArray = (x) => Array.isArray(x);
9
- export const isDate = (x) => getType(x) === 'date';
10
- export const isRegExp = (x) => getType(x) === 'regexp';
11
- export const isInternalObject = (x) => x && (x._internalType instanceof InternalSymbol);
12
- export const isPlainObject = (obj) => {
2
+ export var getType = function (x) { return Object.prototype.toString.call(x).slice(8, -1).toLowerCase(); };
3
+ export var isObject = function (x) { return getType(x) === 'object'; };
4
+ export var isString = function (x) { return getType(x) === 'string'; };
5
+ export var isNumber = function (x) { return getType(x) === 'number'; };
6
+ export var isPromise = function (x) { return getType(x) === 'promise'; };
7
+ export var isFunction = function (x) { return typeof x === 'function'; };
8
+ export var isArray = function (x) { return Array.isArray(x); };
9
+ export var isDate = function (x) { return getType(x) === 'date'; };
10
+ export var isRegExp = function (x) { return getType(x) === 'regexp'; };
11
+ export var isInternalObject = function (x) { return x && (x._internalType instanceof InternalSymbol); };
12
+ export var isPlainObject = function (obj) {
13
13
  if (typeof obj !== 'object' || obj === null)
14
14
  return false;
15
- let proto = obj;
15
+ var proto = obj;
16
16
  while (Object.getPrototypeOf(proto) !== null) {
17
17
  proto = Object.getPrototypeOf(proto);
18
18
  }
@@ -1,9 +1,12 @@
1
+ import { Db } from '../';
1
2
  import { QueryOption, UpdateOption } from '../query';
2
3
  export declare const sleep: (ms?: number) => Promise<unknown>;
4
+ export declare function withCallback<T>(promise: Promise<T>, callback?: any): Promise<T> | undefined;
3
5
  export declare const autoCount: (domain?: string) => number;
6
+ export declare function getWsInstance(db: Db): any;
4
7
  export declare const getReqOpts: (apiOptions: QueryOption | UpdateOption) => any;
5
8
  export declare const filterUndefined: (o: any) => any;
6
- export declare const stringifyByEJSON: (params: any) => any;
9
+ export declare const stringifyByEJSON: (params: any) => string;
7
10
  export declare const parseByEJSON: (params: any) => any;
8
11
  export declare class TcbError extends Error {
9
12
  readonly code: string;
@@ -1,14 +1,72 @@
1
+ var __extends = (this && this.__extends) || (function () {
2
+ var extendStatics = function (d, b) {
3
+ extendStatics = Object.setPrototypeOf ||
4
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
6
+ return extendStatics(d, b);
7
+ };
8
+ return function (d, b) {
9
+ if (typeof b !== "function" && b !== null)
10
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
11
+ extendStatics(d, b);
12
+ function __() { this.constructor = d; }
13
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
14
+ };
15
+ })();
16
+ var __assign = (this && this.__assign) || function () {
17
+ __assign = Object.assign || function(t) {
18
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
19
+ s = arguments[i];
20
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
21
+ t[p] = s[p];
22
+ }
23
+ return t;
24
+ };
25
+ return __assign.apply(this, arguments);
26
+ };
27
+ import { Db } from '../';
1
28
  import { EJSON } from 'bson';
2
29
  import { isObject } from './type';
3
- export const sleep = (ms = 0) => new Promise(r => setTimeout(r, ms));
4
- const counters = {};
5
- export const autoCount = (domain = 'any') => {
30
+ export var sleep = function (ms) {
31
+ if (ms === void 0) { ms = 0; }
32
+ return new Promise(function (r) { return setTimeout(r, ms); });
33
+ };
34
+ export function withCallback(promise, callback) {
35
+ if (typeof callback === 'function') {
36
+ promise.then(function (res) { return callback(0, res); }, function (err) { return callback(err); });
37
+ return undefined;
38
+ }
39
+ return promise;
40
+ }
41
+ var counters = {};
42
+ export var autoCount = function (domain) {
43
+ if (domain === void 0) { domain = 'any'; }
6
44
  if (!counters[domain]) {
7
45
  counters[domain] = 0;
8
46
  }
9
47
  return counters[domain]++;
10
48
  };
11
- export const getReqOpts = (apiOptions) => {
49
+ var wsList = {};
50
+ export function getWsInstance(db) {
51
+ if (!Db.wsClientClass) {
52
+ throw new Error('to use realtime you must import realtime module first');
53
+ }
54
+ var env = db.config.env;
55
+ if (!wsList[env]) {
56
+ wsList[env] = new Db.wsClientClass({
57
+ context: {
58
+ appConfig: {
59
+ docSizeLimit: 1000,
60
+ realtimePingInterval: 10000,
61
+ realtimePongWaitTimeout: 5000,
62
+ request: Db.createRequest(db.config)
63
+ }
64
+ }
65
+ });
66
+ }
67
+ return wsList[env];
68
+ }
69
+ export var getReqOpts = function (apiOptions) {
12
70
  if (apiOptions.timeout !== undefined) {
13
71
  return {
14
72
  timeout: apiOptions.timeout
@@ -16,11 +74,11 @@ export const getReqOpts = (apiOptions) => {
16
74
  }
17
75
  return {};
18
76
  };
19
- export const filterUndefined = o => {
77
+ export var filterUndefined = function (o) {
20
78
  if (!isObject(o)) {
21
79
  return o;
22
80
  }
23
- for (let key in o) {
81
+ for (var key in o) {
24
82
  if (o[key] === undefined) {
25
83
  delete o[key];
26
84
  }
@@ -30,26 +88,30 @@ export const filterUndefined = o => {
30
88
  }
31
89
  return o;
32
90
  };
33
- export const stringifyByEJSON = params => {
91
+ export var stringifyByEJSON = function (params) {
34
92
  params = filterUndefined(params);
35
93
  return EJSON.stringify(params, { relaxed: false });
36
94
  };
37
- export const parseByEJSON = params => {
95
+ export var parseByEJSON = function (params) {
38
96
  return EJSON.parse(params);
39
97
  };
40
- export class TcbError extends Error {
41
- constructor(error) {
42
- super(error.message);
43
- this.code = error.code;
44
- this.message = error.message;
98
+ var TcbError = (function (_super) {
99
+ __extends(TcbError, _super);
100
+ function TcbError(error) {
101
+ var _this = _super.call(this, error.message) || this;
102
+ _this.code = error.code;
103
+ _this.message = error.message;
104
+ return _this;
45
105
  }
46
- }
47
- export const E = (errObj) => {
106
+ return TcbError;
107
+ }(Error));
108
+ export { TcbError };
109
+ export var E = function (errObj) {
48
110
  return new TcbError(errObj);
49
111
  };
50
112
  export function processReturn(throwOnCode, res) {
51
113
  if (throwOnCode === false) {
52
114
  return res;
53
115
  }
54
- throw E(Object.assign({}, res));
116
+ throw E(__assign({}, res));
55
117
  }
@@ -1,16 +1,29 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
1
12
  import { ErrorCode, WhereFilterOpList, OrderDirectionList, FieldType } from './constant';
2
13
  import { Util } from './util';
3
14
  import { ERRORS } from './const/code';
4
15
  import { E } from './utils/utils';
5
16
  import { getType } from './utils/type';
6
17
  import { SYMBOL_GEO_POINT } from './helper/symbol';
7
- const validOptionsKeys = ['limit', 'offset', 'projection', 'order', 'multiple', 'timeout', 'raw'];
8
- export class Validate {
9
- static isGeopoint(point, degree) {
18
+ var validOptionsKeys = ['limit', 'offset', 'projection', 'order', 'multiple', 'timeout', 'raw'];
19
+ var Validate = (function () {
20
+ function Validate() {
21
+ }
22
+ Validate.isGeopoint = function (point, degree) {
10
23
  if (Util.whichType(degree) !== FieldType.Number) {
11
24
  throw new Error('Geo Point must be number type');
12
25
  }
13
- const degreeAbs = Math.abs(degree);
26
+ var degreeAbs = Math.abs(degree);
14
27
  if (point === 'latitude' && degreeAbs > 90) {
15
28
  throw new Error('latitude should be a number ranges from -90 to 90');
16
29
  }
@@ -18,92 +31,93 @@ export class Validate {
18
31
  throw new Error('longitude should be a number ranges from -180 to 180');
19
32
  }
20
33
  return true;
21
- }
22
- static isInteger(param, num) {
34
+ };
35
+ Validate.isInteger = function (param, num) {
23
36
  if (!Number.isInteger(num)) {
24
37
  throw new Error(param + ErrorCode.IntergerError);
25
38
  }
26
39
  return true;
27
- }
28
- static mustBeBoolean(param, bool) {
40
+ };
41
+ Validate.mustBeBoolean = function (param, bool) {
29
42
  if (typeof bool !== 'boolean') {
30
43
  throw new Error(param + ErrorCode.BooleanError);
31
44
  }
32
45
  return true;
33
- }
34
- static isProjection(param, value) {
46
+ };
47
+ Validate.isProjection = function (param, value) {
35
48
  if (getType(value) !== 'object') {
36
- throw E(Object.assign(Object.assign({}, ERRORS.INVALID_PARAM), { message: `${param} projection must be an object` }));
49
+ throw E(__assign(__assign({}, ERRORS.INVALID_PARAM), { message: "".concat(param, " projection must be an object") }));
37
50
  }
38
- for (const key in value) {
39
- const subValue = value[key];
51
+ for (var key in value) {
52
+ var subValue = value[key];
40
53
  if (getType(subValue) === 'number') {
41
54
  if (subValue !== 0 && subValue !== 1) {
42
- throw E(Object.assign(Object.assign({}, ERRORS.INVALID_PARAM), { message: `if the value in projection is of number, it must be 0 or 1` }));
55
+ throw E(__assign(__assign({}, ERRORS.INVALID_PARAM), { message: "if the value in projection is of number, it must be 0 or 1" }));
43
56
  }
44
57
  }
45
58
  else if (getType(subValue) === 'object') {
46
59
  }
47
60
  else {
48
- throw E(Object.assign(Object.assign({}, ERRORS.INVALID_PARAM), { message: 'invalid projection' }));
61
+ throw E(__assign(__assign({}, ERRORS.INVALID_PARAM), { message: 'invalid projection' }));
49
62
  }
50
63
  }
51
64
  return true;
52
- }
53
- static isOrder(param, value) {
65
+ };
66
+ Validate.isOrder = function (param, value) {
54
67
  if (getType(value) !== 'object') {
55
- throw E(Object.assign(Object.assign({}, ERRORS.INVALID_PARAM), { message: `${param} order must be an object` }));
68
+ throw E(__assign(__assign({}, ERRORS.INVALID_PARAM), { message: "".concat(param, " order must be an object") }));
56
69
  }
57
- for (let key in value) {
58
- const subValue = value[key];
70
+ for (var key in value) {
71
+ var subValue = value[key];
59
72
  if (subValue !== 1 && subValue !== -1) {
60
- throw E(Object.assign(Object.assign({}, ERRORS.INVALID_PARAM), { message: `order value must be 1 or -1` }));
73
+ throw E(__assign(__assign({}, ERRORS.INVALID_PARAM), { message: "order value must be 1 or -1" }));
61
74
  }
62
75
  }
63
76
  return true;
64
- }
65
- static isFieldOrder(direction) {
77
+ };
78
+ Validate.isFieldOrder = function (direction) {
66
79
  if (OrderDirectionList.indexOf(direction) === -1) {
67
80
  throw new Error(ErrorCode.DirectionError);
68
81
  }
69
82
  return true;
70
- }
71
- static isFieldPath(path) {
83
+ };
84
+ Validate.isFieldPath = function (path) {
72
85
  if (!/^[a-zA-Z0-9-_\.]/.test(path)) {
73
86
  throw new Error();
74
87
  }
75
88
  return true;
76
- }
77
- static isOperator(op) {
89
+ };
90
+ Validate.isOperator = function (op) {
78
91
  if (WhereFilterOpList.indexOf(op) === -1) {
79
92
  throw new Error(ErrorCode.OpStrError);
80
93
  }
81
94
  return true;
82
- }
83
- static isCollName(name) {
95
+ };
96
+ Validate.isCollName = function (name) {
84
97
  if (!/^[a-zA-Z0-9]([a-zA-Z0-9-_]){1,32}$/.test(name)) {
85
98
  throw new Error(ErrorCode.CollNameError);
86
99
  }
87
100
  return true;
88
- }
89
- static isDocID(docId) {
101
+ };
102
+ Validate.isDocID = function (docId) {
90
103
  if (!/^([a-fA-F0-9]){24}$/.test(docId)) {
91
104
  throw new Error(ErrorCode.DocIDError);
92
105
  }
93
106
  return true;
94
- }
95
- static isValidOptions(options = {}) {
107
+ };
108
+ Validate.isValidOptions = function (options) {
109
+ if (options === void 0) { options = {}; }
96
110
  if (getType(options) !== 'object') {
97
- throw E(Object.assign(Object.assign({}, ERRORS.INVALID_PARAM), { message: `options must be an object` }));
111
+ throw E(__assign(__assign({}, ERRORS.INVALID_PARAM), { message: "options must be an object" }));
98
112
  }
99
- const keys = Object.keys(options);
100
- for (const index in keys) {
113
+ var keys = Object.keys(options);
114
+ for (var index in keys) {
101
115
  if (validOptionsKeys.indexOf(keys[index]) < 0) {
102
- throw E(Object.assign(Object.assign({}, ERRORS.INVALID_PARAM), { message: `${keys[index]} is invalid options key` }));
116
+ throw E(__assign(__assign({}, ERRORS.INVALID_PARAM), { message: "".concat(keys[index], " is invalid options key") }));
103
117
  }
104
118
  }
105
- const { limit, offset, projection, order } = options;
106
- const { multiple } = options;
119
+ var _a = options, limit = _a.limit, offset = _a.offset, projection = _a.projection, order = _a.order;
120
+ var multiple = options.multiple;
107
121
  if (limit !== undefined) {
108
122
  Validate.isInteger('limit', limit);
109
123
  }
@@ -123,14 +137,14 @@ export class Validate {
123
137
  Validate.isInteger('timeout', options.timeout);
124
138
  }
125
139
  return true;
126
- }
127
- static isValidAggregation(stage) {
140
+ };
141
+ Validate.isValidAggregation = function (stage) {
128
142
  if (Object.keys(stage).length !== 1) {
129
- throw E(Object.assign(Object.assign({}, ERRORS.INVALID_PARAM), { message: `aggregation stage must have one key` }));
143
+ throw E(__assign(__assign({}, ERRORS.INVALID_PARAM), { message: "aggregation stage must have one key" }));
130
144
  }
131
145
  return true;
132
- }
133
- static isCentersPhere(param) {
146
+ };
147
+ Validate.isCentersPhere = function (param) {
134
148
  if (Array.isArray(param) && param.length === 2) {
135
149
  if (getType(param[0]) === 'object' &&
136
150
  param[0]._internalType === SYMBOL_GEO_POINT &&
@@ -138,8 +152,8 @@ export class Validate {
138
152
  return true;
139
153
  }
140
154
  if (Array.isArray(param[0]) && param[0].length === 2) {
141
- const longitude = param[0][0];
142
- const latitude = param[0][1];
155
+ var longitude = param[0][0];
156
+ var latitude = param[0][1];
143
157
  Validate.isGeopoint('longitude', longitude);
144
158
  Validate.isGeopoint('latitude', latitude);
145
159
  if (typeof param[1] === 'number') {
@@ -147,6 +161,8 @@ export class Validate {
147
161
  }
148
162
  }
149
163
  }
150
- throw new Error(`${ErrorCode.CentersPhereError}`);
151
- }
152
- }
164
+ throw new Error("".concat(ErrorCode.CentersPhereError));
165
+ };
166
+ return Validate;
167
+ }());
168
+ export { Validate };
package/jest.config.js ADDED
@@ -0,0 +1,14 @@
1
+ module.exports = {
2
+ preset: 'ts-jest',
3
+ testEnvironment: 'node',
4
+ testMatch: ['**/tests/**/*.ts'],
5
+ moduleFileExtensions: ['ts', 'js'],
6
+ transform: {
7
+ '^.+\\.ts$': ['ts-jest', {
8
+ tsconfig: 'tsconfig.test.json'
9
+ }]
10
+ },
11
+ transformIgnorePatterns: [
12
+ '/node_modules/(?!@types)/'
13
+ ]
14
+ };
package/package.json CHANGED
@@ -1,32 +1,36 @@
1
1
  {
2
2
  "name": "@cloudbase/database",
3
- "version": "1.4.3-alpha.0",
3
+ "version": "1.5.0",
4
4
  "description": "database for (node.)js sdk ",
5
5
  "main": "dist/commonjs/index.js",
6
6
  "module": "dist/esm/index.js",
7
+ "publishConfig": {
8
+ "tag": "next"
9
+ },
7
10
  "scripts": {
8
11
  "eslint": "eslint \"./**/*.ts\"",
9
12
  "eslint-fix": "eslint --fix \"./**/*.ts\"",
10
- "test": "echo \"Error: no test specified\" && exit 1",
13
+ "test": "jest",
11
14
  "build": "tsc -p tsconfig.json && tsc -p tsconfig.esm.json",
12
15
  "prepublishOnly": "npm run build"
13
16
  },
14
17
  "author": "",
15
18
  "license": "ISC",
16
19
  "devDependencies": {
20
+ "@types/jest": "26.0.24",
21
+ "@types/node": "14.14.31",
17
22
  "eslint": "^5.15.3",
18
23
  "eslint-config-prettier": "^4.1.0",
19
24
  "eslint-plugin-prettier": "^3.0.1",
20
25
  "eslint-plugin-typescript": "^0.14.0",
21
- "typescript": "^3.6.2",
22
- "typescript-eslint-parser": "^22.0.0",
23
- "@types/node": "^13.13.4"
26
+ "jest": "26.6.3",
27
+ "ts-jest": "26.5.6",
28
+ "typescript": "^4.1.0",
29
+ "typescript-eslint-parser": "^22.0.0"
24
30
  },
25
31
  "sideEffects": false,
26
32
  "dependencies": {
27
- "bson": "^4.0.3",
28
- "lodash.clonedeep": "4.5.0",
29
- "lodash.set": "4.3.2",
30
- "lodash.unset": "4.5.2"
31
- }
33
+ "bson": "^6.10.4"
34
+ },
35
+ "packageManager": "yarn@1.22.22"
32
36
  }