@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,13 +1,14 @@
1
1
  import { Point } from './geo/point';
2
2
  import { CollectionReference } from './collection';
3
3
  import { Command } from './command';
4
+ export type IDbConfig = ICloudBaseConfig;
4
5
  interface GeoTeyp {
5
6
  Point: typeof Point;
6
7
  }
7
8
  export { Query } from './query';
8
9
  export { CollectionReference } from './collection';
9
10
  export { DocumentReference } from './document';
10
- interface ICloudBaseConfig {
11
+ export interface ICloudBaseConfig {
11
12
  timeout?: number;
12
13
  isHttp?: boolean;
13
14
  secretId?: string;
@@ -37,16 +38,21 @@ export declare class Db {
37
38
  ObjectId: any;
38
39
  startTransaction: any;
39
40
  runTransaction: any;
41
+ logicCommand: any;
42
+ updateCommand: any;
43
+ queryCommand: any;
40
44
  config: ICloudBaseConfig;
41
45
  static ws: any;
42
46
  static reqClass: any;
43
47
  static wsClass: any;
48
+ static wsClientClass: any;
44
49
  static createSign: Function;
45
50
  static getAccessToken: Function;
46
51
  static dataVersion: string;
47
52
  static runtime: string;
48
53
  static appSecretInfo: any;
49
- constructor(config?: any);
54
+ static createRequest(config: ICloudBaseConfig): any;
55
+ constructor(config?: ICloudBaseConfig);
50
56
  collection(collName: string): CollectionReference;
51
57
  createCollection(collName: string): any;
52
58
  }
package/dist/esm/index.js CHANGED
@@ -1,15 +1,43 @@
1
+ var __read = (this && this.__read) || function (o, n) {
2
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
3
+ if (!m) return o;
4
+ var i = m.call(o), r, ar = [], e;
5
+ try {
6
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
7
+ }
8
+ catch (error) { e = { error: error }; }
9
+ finally {
10
+ try {
11
+ if (r && !r.done && (m = i["return"])) m.call(i);
12
+ }
13
+ finally { if (e) throw e.error; }
14
+ }
15
+ return ar;
16
+ };
17
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
18
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
19
+ if (ar || !(i in from)) {
20
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
21
+ ar[i] = from[i];
22
+ }
23
+ }
24
+ return to.concat(ar || Array.prototype.slice.call(from));
25
+ };
1
26
  import * as Geo from './geo/index';
2
27
  import { CollectionReference } from './collection';
3
28
  import { Command } from './command';
4
29
  import { ServerDateConstructor } from './serverDate/index';
5
30
  import { RegExpConstructor } from './regexp/index';
6
31
  import { startTransaction, runTransaction } from './transaction/index';
32
+ import { LogicCommand } from './commands/logic';
33
+ import { QueryCommand } from './commands/query';
34
+ import { UpdateCommand } from './commands/update';
7
35
  import { ObjectIdConstructor } from './ObjectId/index';
8
36
  export { Query } from './query';
9
37
  export { CollectionReference } from './collection';
10
38
  export { DocumentReference } from './document';
11
- export class Db {
12
- constructor(config) {
39
+ var Db = (function () {
40
+ function Db(config) {
13
41
  this.config = config;
14
42
  this.Geo = Geo;
15
43
  this.serverDate = ServerDateConstructor;
@@ -18,18 +46,43 @@ export class Db {
18
46
  this.ObjectId = ObjectIdConstructor;
19
47
  this.startTransaction = startTransaction;
20
48
  this.runTransaction = runTransaction;
49
+ this.logicCommand = LogicCommand;
50
+ this.updateCommand = UpdateCommand;
51
+ this.queryCommand = QueryCommand;
21
52
  }
22
- collection(collName) {
53
+ Db.createRequest = function (config) {
54
+ var request = new Db.reqClass(config);
55
+ var originalSend = request.send;
56
+ request.send = function (action, data) {
57
+ var args = [];
58
+ for (var _i = 2; _i < arguments.length; _i++) {
59
+ args[_i - 2] = arguments[_i];
60
+ }
61
+ if (data) {
62
+ if (config.instance) {
63
+ data.instance = config.instance;
64
+ }
65
+ if (config.database) {
66
+ data.database = config.database;
67
+ }
68
+ }
69
+ return originalSend.call.apply(originalSend, __spreadArray([this, action, data], __read(args), false));
70
+ };
71
+ return request;
72
+ };
73
+ Db.prototype.collection = function (collName) {
23
74
  if (!collName) {
24
75
  throw new Error('Collection name is required');
25
76
  }
26
77
  return new CollectionReference(this, collName);
27
- }
28
- createCollection(collName) {
29
- let request = new Db.reqClass(this.config);
30
- const params = {
78
+ };
79
+ Db.prototype.createCollection = function (collName) {
80
+ var request = Db.createRequest(this.config);
81
+ var params = {
31
82
  collectionName: collName
32
83
  };
33
84
  return request.send('database.addCollection', params);
34
- }
35
- }
85
+ };
86
+ return Db;
87
+ }());
88
+ export { Db };
@@ -1,7 +1,6 @@
1
1
  export var createPromiseCallback = function () {
2
- var cb;
2
+ var cb = function () { };
3
3
  if (!Promise) {
4
- cb = function () { };
5
4
  cb.promise = {};
6
5
  var throwPromiseNotDefined = function () {
7
6
  throw new Error('Your Node runtime does support ES6 Promises. ' +
@@ -1,14 +1,14 @@
1
1
  import { QUERY_COMMANDS_LITERAL } from './commands/query';
2
2
  import { LOGIC_COMMANDS_LITERAL } from './commands/logic';
3
3
  import { UPDATE_COMMANDS_LITERAL } from './commands/update';
4
- export const OperatorMap = {};
5
- for (const key in QUERY_COMMANDS_LITERAL) {
4
+ export var OperatorMap = {};
5
+ for (var key in QUERY_COMMANDS_LITERAL) {
6
6
  OperatorMap[key] = '$' + key;
7
7
  }
8
- for (const key in LOGIC_COMMANDS_LITERAL) {
8
+ for (var key in LOGIC_COMMANDS_LITERAL) {
9
9
  OperatorMap[key] = '$' + key;
10
10
  }
11
- for (const key in UPDATE_COMMANDS_LITERAL) {
11
+ for (var key in UPDATE_COMMANDS_LITERAL) {
12
12
  OperatorMap[key] = '$' + key;
13
13
  }
14
14
  OperatorMap[QUERY_COMMANDS_LITERAL.NEQ] = '$ne';
@@ -22,16 +22,20 @@ export interface UpdateOption extends BaseOption {
22
22
  }
23
23
  export declare class Query {
24
24
  protected _transactionId: string;
25
- get(): Promise<GetRes>;
26
- count(): Promise<any>;
25
+ get(callback?: any): Promise<GetRes>;
26
+ private _get;
27
+ count(callback?: any): Promise<any>;
28
+ private _count;
27
29
  where(query: object): Query;
28
30
  options(apiOptions: QueryOption | UpdateOption): Query;
29
31
  orderBy(fieldPath: string, directionStr: OrderByDirection): Query;
30
32
  limit(limit: number): Query;
31
33
  skip(offset: number): Query;
32
- update(data: Object): Promise<any>;
34
+ update(data: Object, callback?: any): Promise<any>;
35
+ private _update;
33
36
  field(projection: any): Query;
34
- remove(): Promise<any>;
37
+ remove(callback?: any): Promise<any>;
38
+ private _remove;
35
39
  updateAndReturn(data: Object): Promise<any>;
36
40
  watch: (options: IWatchOptions) => DBRealtimeListener;
37
41
  }