@cloudbase/database 1.4.3 → 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 (196) 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.d.ts +1 -0
  35. package/dist/commonjs/lib/util.js +26 -0
  36. package/dist/commonjs/operator-map.js +7 -6
  37. package/dist/commonjs/query.d.ts +8 -4
  38. package/dist/commonjs/query.js +308 -201
  39. package/dist/commonjs/regexp/index.d.ts +1 -1
  40. package/dist/commonjs/regexp/index.js +16 -9
  41. package/dist/commonjs/serializer/common.d.ts +2 -2
  42. package/dist/commonjs/serializer/common.js +59 -22
  43. package/dist/commonjs/serializer/datatype.d.ts +2 -2
  44. package/dist/commonjs/serializer/datatype.js +58 -21
  45. package/dist/commonjs/serializer/query.d.ts +1 -1
  46. package/dist/commonjs/serializer/query.js +137 -127
  47. package/dist/commonjs/serializer/update.d.ts +1 -1
  48. package/dist/commonjs/serializer/update.js +83 -78
  49. package/dist/commonjs/serverDate/index.d.ts +1 -1
  50. package/dist/commonjs/serverDate/index.js +16 -9
  51. package/dist/commonjs/transaction/collection.d.ts +7 -0
  52. package/dist/commonjs/transaction/collection.js +49 -0
  53. package/dist/commonjs/transaction/document.d.ts +27 -0
  54. package/dist/commonjs/transaction/document.js +205 -0
  55. package/dist/commonjs/transaction/index.js +196 -86
  56. package/dist/commonjs/transaction/query.d.ts +43 -0
  57. package/dist/commonjs/transaction/query.js +261 -0
  58. package/dist/commonjs/typings/index.d.ts +4 -4
  59. package/dist/commonjs/typings/realtime.d.ts +16 -16
  60. package/dist/commonjs/util.js +123 -92
  61. package/dist/commonjs/utils/error.d.ts +2 -1
  62. package/dist/commonjs/utils/error.js +74 -38
  63. package/dist/commonjs/utils/symbol.js +33 -14
  64. package/dist/commonjs/utils/type.d.ts +1 -1
  65. package/dist/commonjs/utils/type.js +25 -13
  66. package/dist/commonjs/utils/utils.d.ts +4 -1
  67. package/dist/commonjs/utils/utils.js +93 -22
  68. package/dist/commonjs/validate.js +79 -63
  69. package/dist/esm/ObjectId/index.d.ts +1 -1
  70. package/dist/esm/ObjectId/index.js +15 -8
  71. package/dist/esm/aggregate.js +118 -66
  72. package/dist/esm/collection.d.ts +3 -2
  73. package/dist/esm/collection.js +125 -52
  74. package/dist/esm/command.d.ts +5 -5
  75. package/dist/esm/command.js +175 -147
  76. package/dist/esm/commands/logic.js +30 -20
  77. package/dist/esm/commands/query.d.ts +1 -1
  78. package/dist/esm/commands/query.js +91 -71
  79. package/dist/esm/commands/update.js +8 -6
  80. package/dist/esm/config/error.config.js +1 -1
  81. package/dist/esm/const/code.js +1 -1
  82. package/dist/esm/constant.d.ts +7 -7
  83. package/dist/esm/constant.js +12 -11
  84. package/dist/esm/document.d.ts +10 -6
  85. package/dist/esm/document.js +297 -185
  86. package/dist/esm/geo/interface.js +1 -0
  87. package/dist/esm/geo/lineString.d.ts +1 -1
  88. package/dist/esm/geo/lineString.js +57 -28
  89. package/dist/esm/geo/multiLineString.d.ts +1 -1
  90. package/dist/esm/geo/multiLineString.js +66 -27
  91. package/dist/esm/geo/multiPoint.d.ts +1 -1
  92. package/dist/esm/geo/multiPoint.js +53 -24
  93. package/dist/esm/geo/multiPolygon.d.ts +1 -1
  94. package/dist/esm/geo/multiPolygon.js +91 -31
  95. package/dist/esm/geo/point.d.ts +1 -1
  96. package/dist/esm/geo/point.js +26 -19
  97. package/dist/esm/geo/polygon.d.ts +1 -1
  98. package/dist/esm/geo/polygon.js +73 -34
  99. package/dist/esm/helper/symbol.js +13 -13
  100. package/dist/esm/index.d.ts +8 -2
  101. package/dist/esm/index.js +62 -9
  102. package/dist/esm/lib/util.d.ts +1 -0
  103. package/dist/esm/lib/util.js +22 -0
  104. package/dist/esm/operator-map.js +4 -4
  105. package/dist/esm/query.d.ts +8 -4
  106. package/dist/esm/query.js +299 -192
  107. package/dist/esm/regexp/index.d.ts +1 -1
  108. package/dist/esm/regexp/index.js +15 -8
  109. package/dist/esm/serializer/common.d.ts +2 -2
  110. package/dist/esm/serializer/common.js +49 -13
  111. package/dist/esm/serializer/datatype.d.ts +2 -2
  112. package/dist/esm/serializer/datatype.js +44 -8
  113. package/dist/esm/serializer/query.d.ts +1 -1
  114. package/dist/esm/serializer/query.js +112 -102
  115. package/dist/esm/serializer/update.d.ts +1 -1
  116. package/dist/esm/serializer/update.js +69 -64
  117. package/dist/esm/serverDate/index.d.ts +1 -1
  118. package/dist/esm/serverDate/index.js +15 -8
  119. package/dist/esm/transaction/collection.d.ts +7 -0
  120. package/dist/esm/transaction/collection.js +46 -0
  121. package/dist/esm/transaction/document.d.ts +27 -0
  122. package/dist/esm/transaction/document.js +202 -0
  123. package/dist/esm/transaction/index.js +191 -81
  124. package/dist/esm/transaction/query.d.ts +43 -0
  125. package/dist/esm/transaction/query.js +258 -0
  126. package/dist/esm/typings/index.d.ts +4 -4
  127. package/dist/esm/typings/index.js +1 -0
  128. package/dist/esm/typings/realtime.d.ts +16 -16
  129. package/dist/esm/typings/realtime.js +1 -0
  130. package/dist/esm/util.js +121 -90
  131. package/dist/esm/utils/error.d.ts +2 -1
  132. package/dist/esm/utils/error.js +70 -35
  133. package/dist/esm/utils/symbol.js +33 -14
  134. package/dist/esm/utils/type.d.ts +1 -1
  135. package/dist/esm/utils/type.js +12 -12
  136. package/dist/esm/utils/utils.d.ts +4 -1
  137. package/dist/esm/utils/utils.js +78 -16
  138. package/dist/esm/validate.js +65 -49
  139. package/jest.config.js +14 -0
  140. package/package.json +14 -10
  141. package/src/aggregate.ts +1 -5
  142. package/src/collection.ts +15 -2
  143. package/src/document.ts +45 -34
  144. package/src/index.ts +51 -4
  145. package/src/query.ts +33 -29
  146. package/src/serializer/query.ts +18 -6
  147. package/src/transaction/index.ts +1 -1
  148. package/src/typings/index.ts +0 -4
  149. package/src/utils/utils.ts +46 -0
  150. package/src/validate.ts +3 -6
  151. package/tests/gateway-contract.test.ts +180 -0
  152. package/tests/index.test.ts +283 -0
  153. package/tests/transaction-query.test.ts +207 -0
  154. package/tsconfig.esm.json +4 -2
  155. package/tsconfig.json +16 -6
  156. package/tsconfig.test.json +15 -0
  157. package/dist/commonjs/realtime/error.d.ts +0 -7
  158. package/dist/commonjs/realtime/error.js +0 -11
  159. package/dist/commonjs/realtime/listener.d.ts +0 -14
  160. package/dist/commonjs/realtime/listener.js +0 -17
  161. package/dist/commonjs/realtime/message.d.ts +0 -3
  162. package/dist/commonjs/realtime/message.js +0 -10
  163. package/dist/commonjs/realtime/snapshot.d.ts +0 -16
  164. package/dist/commonjs/realtime/snapshot.js +0 -42
  165. package/dist/commonjs/realtime/virtual-websocket-client.d.ts +0 -63
  166. package/dist/commonjs/realtime/virtual-websocket-client.js +0 -736
  167. package/dist/commonjs/realtime/websocket-client.d.ts +0 -78
  168. package/dist/commonjs/realtime/websocket-client.js +0 -567
  169. package/dist/commonjs/realtime/ws-event.d.ts +0 -126
  170. package/dist/commonjs/realtime/ws-event.js +0 -139
  171. package/dist/commonjs/transaction.d.ts +0 -42
  172. package/dist/commonjs/transaction.js +0 -126
  173. package/dist/esm/realtime/error.d.ts +0 -7
  174. package/dist/esm/realtime/error.js +0 -8
  175. package/dist/esm/realtime/listener.d.ts +0 -14
  176. package/dist/esm/realtime/listener.js +0 -14
  177. package/dist/esm/realtime/message.d.ts +0 -3
  178. package/dist/esm/realtime/message.js +0 -6
  179. package/dist/esm/realtime/snapshot.d.ts +0 -16
  180. package/dist/esm/realtime/snapshot.js +0 -39
  181. package/dist/esm/realtime/virtual-websocket-client.d.ts +0 -63
  182. package/dist/esm/realtime/virtual-websocket-client.js +0 -733
  183. package/dist/esm/realtime/websocket-client.d.ts +0 -78
  184. package/dist/esm/realtime/websocket-client.js +0 -564
  185. package/dist/esm/realtime/ws-event.d.ts +0 -126
  186. package/dist/esm/realtime/ws-event.js +0 -137
  187. package/dist/esm/transaction.d.ts +0 -42
  188. package/dist/esm/transaction.js +0 -121
  189. package/src/realtime/error.ts +0 -19
  190. package/src/realtime/listener.ts +0 -35
  191. package/src/realtime/message.ts +0 -14
  192. package/src/realtime/snapshot.ts +0 -60
  193. package/src/realtime/virtual-websocket-client.ts +0 -1195
  194. package/src/realtime/websocket-client.ts +0 -995
  195. package/src/realtime/ws-event.ts +0 -163
  196. 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 };
@@ -0,0 +1 @@
1
+ export declare const createPromiseCallback: () => any;
@@ -0,0 +1,22 @@
1
+ export var createPromiseCallback = function () {
2
+ var cb = function () { };
3
+ if (!Promise) {
4
+ cb.promise = {};
5
+ var throwPromiseNotDefined = function () {
6
+ throw new Error('Your Node runtime does support ES6 Promises. ' +
7
+ 'Set "global.Promise" to your preferred implementation of promises.');
8
+ };
9
+ Object.defineProperty(cb.promise, 'then', { get: throwPromiseNotDefined });
10
+ Object.defineProperty(cb.promise, 'catch', { get: throwPromiseNotDefined });
11
+ return cb;
12
+ }
13
+ var promise = new Promise(function (resolve, reject) {
14
+ cb = function (err, data) {
15
+ if (err)
16
+ return reject(err);
17
+ return resolve(data);
18
+ };
19
+ });
20
+ cb.promise = promise;
21
+ return cb;
22
+ };
@@ -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
  }