@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
package/dist/esm/query.js CHANGED
@@ -1,32 +1,68 @@
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
+ };
12
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
13
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
14
+ return new (P || (P = Promise))(function (resolve, reject) {
15
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
17
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
18
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
19
+ });
20
+ };
21
+ var __generator = (this && this.__generator) || function (thisArg, body) {
22
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
23
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
24
+ function verb(n) { return function (v) { return step([n, v]); }; }
25
+ function step(op) {
26
+ if (f) throw new TypeError("Generator is already executing.");
27
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
28
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
29
+ if (y = 0, t) op = [op[0] & 2, t.value];
30
+ switch (op[0]) {
31
+ case 0: case 1: t = op; break;
32
+ case 4: _.label++; return { value: op[1], done: false };
33
+ case 5: _.label++; y = op[1]; op = [0]; continue;
34
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
35
+ default:
36
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
37
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
38
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
39
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
40
+ if (t[2]) _.ops.pop();
41
+ _.trys.pop(); continue;
42
+ }
43
+ op = body.call(thisArg, _);
44
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
45
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
46
+ }
47
+ };
1
48
  import { QueryType } from './constant';
2
49
  import { Db } from './index';
3
50
  import { Validate } from './validate';
4
51
  import { Util } from './util';
5
52
  import { QuerySerializer } from './serializer/query';
6
53
  import { UpdateSerializer } from './serializer/update';
7
- import { RealtimeWebSocketClient } from './realtime/websocket-client';
8
54
  import { ErrorCode } from './constant';
9
- import { getReqOpts, stringifyByEJSON, processReturn } from './utils/utils';
55
+ import { getWsInstance, getReqOpts, stringifyByEJSON, processReturn, withCallback } from './utils/utils';
10
56
  import { ERRORS } from './const/code';
11
57
  import { EJSON } from 'bson';
12
- export class Query {
13
- constructor(db, coll, fieldFilters, apiOptions, transactionId) {
14
- this.watch = (options) => {
15
- if (!Db.ws) {
16
- Db.ws = new RealtimeWebSocketClient({
17
- context: {
18
- appConfig: {
19
- docSizeLimit: 1000,
20
- realtimePingInterval: 10000,
21
- realtimePongWaitTimeout: 5000,
22
- request: this._request
23
- }
24
- }
25
- });
26
- }
27
- const { limit, order } = this._apiOptions;
28
- return Db.ws.watch(Object.assign(Object.assign({}, options), { envId: this._db.config.env, collectionName: this._coll, query: JSON.stringify(this._fieldFilters), limit, orderBy: order
29
- ? order.reduce((acc, cur) => {
58
+ var Query = (function () {
59
+ function Query(db, coll, fieldFilters, apiOptions, transactionId) {
60
+ var _this = this;
61
+ this.watch = function (options) {
62
+ var ws = getWsInstance(_this._db);
63
+ var _a = _this._apiOptions, limit = _a.limit, order = _a.order;
64
+ return ws.watch(__assign(__assign({}, options), { envId: _this._db.config.env, collectionName: _this._coll, query: JSON.stringify(_this._fieldFilters), limit: limit, orderBy: order
65
+ ? order.reduce(function (acc, cur) {
30
66
  acc[cur.field] = cur.direction;
31
67
  return acc;
32
68
  }, {})
@@ -36,146 +72,189 @@ export class Query {
36
72
  this._coll = coll;
37
73
  this._fieldFilters = fieldFilters;
38
74
  this._apiOptions = apiOptions || {};
39
- this._request = new Db.reqClass(this._db.config);
75
+ this._request = Db.createRequest(this._db.config);
40
76
  this._transactionId = transactionId;
41
77
  }
42
- async get() {
43
- const order = this._apiOptions.order;
44
- let param = {
45
- collectionName: this._coll,
46
- queryType: QueryType.WHERE,
47
- transactionId: this._transactionId
48
- };
49
- if (this._fieldFilters) {
50
- param.query = this._fieldFilters;
51
- }
52
- if (order) {
53
- param.order = stringifyByEJSON(order);
54
- }
55
- const offset = this._apiOptions.offset;
56
- if (offset) {
57
- param.offset = offset;
58
- }
59
- const limit = this._apiOptions.limit;
60
- if (limit) {
61
- param.limit = limit < 1000 ? limit : 1000;
62
- }
63
- else {
64
- param.limit = 100;
65
- }
66
- const projection = this._apiOptions.projection;
67
- if (projection) {
68
- param.projection = stringifyByEJSON(projection);
69
- }
70
- const res = await this._request.send('database.getDocument', param, getReqOpts(this._apiOptions));
71
- if (res.code) {
72
- return res;
73
- }
74
- const list = res.data.list.map(item => EJSON.parse(item));
75
- const documents = Util.formatResDocumentData(list);
76
- const result = {
77
- data: documents,
78
- requestId: res.requestId
79
- };
80
- if (res.total)
81
- result.total = res.total;
82
- if (res.limit)
83
- result.limit = res.limit;
84
- if (res.offset)
85
- result.offset = res.offset;
86
- return result;
87
- }
88
- async count() {
89
- let param = {
90
- collectionName: this._coll,
91
- queryType: QueryType.WHERE
92
- };
93
- if (this._fieldFilters) {
94
- param.query = this._fieldFilters;
95
- }
96
- const res = await this._request.send('database.calculateDocument', param, getReqOpts(this._apiOptions));
97
- if (res.code) {
98
- return res;
99
- }
100
- return {
101
- requestId: res.requestId,
102
- total: res.data.total
103
- };
104
- }
105
- where(query) {
78
+ Query.prototype.get = function (callback) {
79
+ return withCallback(this._get(), callback);
80
+ };
81
+ Query.prototype._get = function () {
82
+ return __awaiter(this, void 0, void 0, function () {
83
+ var order, param, offset, limit, projection, res, list, documents, result;
84
+ return __generator(this, function (_a) {
85
+ switch (_a.label) {
86
+ case 0:
87
+ order = this._apiOptions.order;
88
+ param = {
89
+ collectionName: this._coll,
90
+ queryType: QueryType.WHERE,
91
+ transactionId: this._transactionId
92
+ };
93
+ if (this._fieldFilters) {
94
+ param.query = this._fieldFilters;
95
+ }
96
+ if (order) {
97
+ param.order = stringifyByEJSON(order);
98
+ }
99
+ offset = this._apiOptions.offset;
100
+ if (offset) {
101
+ param.offset = offset;
102
+ }
103
+ limit = this._apiOptions.limit;
104
+ if (limit) {
105
+ param.limit = limit < 1000 ? limit : 1000;
106
+ }
107
+ else {
108
+ param.limit = 100;
109
+ }
110
+ projection = this._apiOptions.projection;
111
+ if (projection) {
112
+ param.projection = stringifyByEJSON(projection);
113
+ }
114
+ return [4, this._request.send('database.getDocument', param, getReqOpts(this._apiOptions))];
115
+ case 1:
116
+ res = _a.sent();
117
+ if (res.code) {
118
+ return [2, res];
119
+ }
120
+ list = res.data.list.map(function (item) { return EJSON.parse(item); });
121
+ documents = Util.formatResDocumentData(list);
122
+ result = {
123
+ data: documents,
124
+ requestId: res.requestId
125
+ };
126
+ if (res.total)
127
+ result.total = res.total;
128
+ if (res.limit)
129
+ result.limit = res.limit;
130
+ if (res.offset)
131
+ result.offset = res.offset;
132
+ return [2, result];
133
+ }
134
+ });
135
+ });
136
+ };
137
+ Query.prototype.count = function (callback) {
138
+ return withCallback(this._count(), callback);
139
+ };
140
+ Query.prototype._count = function () {
141
+ return __awaiter(this, void 0, void 0, function () {
142
+ var param, res;
143
+ return __generator(this, function (_a) {
144
+ switch (_a.label) {
145
+ case 0:
146
+ param = {
147
+ collectionName: this._coll,
148
+ queryType: QueryType.WHERE
149
+ };
150
+ if (this._fieldFilters) {
151
+ param.query = this._fieldFilters;
152
+ }
153
+ return [4, this._request.send('database.calculateDocument', param, getReqOpts(this._apiOptions))];
154
+ case 1:
155
+ res = _a.sent();
156
+ if (res.code) {
157
+ return [2, res];
158
+ }
159
+ return [2, {
160
+ requestId: res.requestId,
161
+ total: res.data.total
162
+ }];
163
+ }
164
+ });
165
+ });
166
+ };
167
+ Query.prototype.where = function (query) {
106
168
  if (Object.prototype.toString.call(query).slice(8, -1) !== 'Object') {
107
169
  throw Error(ErrorCode.QueryParamTypeError);
108
170
  }
109
- const keys = Object.keys(query);
110
- const checkFlag = keys.some(item => {
171
+ var keys = Object.keys(query);
172
+ var checkFlag = keys.some(function (item) {
111
173
  return query[item] !== undefined;
112
174
  });
113
175
  if (keys.length && !checkFlag) {
114
176
  throw Error(ErrorCode.QueryParamValueError);
115
177
  }
116
178
  return new Query(this._db, this._coll, QuerySerializer.encodeEJSON(query, this._apiOptions.raw || false), this._apiOptions, this._transactionId);
117
- }
118
- options(apiOptions) {
179
+ };
180
+ Query.prototype.options = function (apiOptions) {
119
181
  Validate.isValidOptions(apiOptions);
120
182
  return new Query(this._db, this._coll, this._fieldFilters, apiOptions, this._transactionId);
121
- }
122
- orderBy(fieldPath, directionStr) {
183
+ };
184
+ Query.prototype.orderBy = function (fieldPath, directionStr) {
185
+ var _a;
123
186
  Validate.isFieldPath(fieldPath);
124
187
  Validate.isFieldOrder(directionStr);
125
- const newOrder = {
126
- [fieldPath]: directionStr === 'desc' ? -1 : 1
127
- };
128
- const order = this._apiOptions.order || {};
129
- const newApiOption = Object.assign({}, this._apiOptions, {
188
+ var newOrder = (_a = {},
189
+ _a[fieldPath] = directionStr === 'desc' ? -1 : 1,
190
+ _a);
191
+ var order = this._apiOptions.order || {};
192
+ var newApiOption = Object.assign({}, this._apiOptions, {
130
193
  order: Object.assign({}, order, newOrder)
131
194
  });
132
195
  return new Query(this._db, this._coll, this._fieldFilters, newApiOption, this._transactionId);
133
- }
134
- limit(limit) {
196
+ };
197
+ Query.prototype.limit = function (limit) {
135
198
  Validate.isInteger('limit', limit);
136
- let newApiOption = Object.assign({}, this._apiOptions);
199
+ var newApiOption = __assign({}, this._apiOptions);
137
200
  newApiOption.limit = limit;
138
201
  return new Query(this._db, this._coll, this._fieldFilters, newApiOption, this._transactionId);
139
- }
140
- skip(offset) {
202
+ };
203
+ Query.prototype.skip = function (offset) {
141
204
  Validate.isInteger('offset', offset);
142
- let newApiOption = Object.assign({}, this._apiOptions);
205
+ var newApiOption = __assign({}, this._apiOptions);
143
206
  newApiOption.offset = offset;
144
207
  return new Query(this._db, this._coll, this._fieldFilters, newApiOption, this._transactionId);
145
- }
146
- async update(data) {
147
- if (!data || typeof data !== 'object') {
148
- return processReturn(this._db.config.throwOnCode, Object.assign(Object.assign({}, ERRORS.INVALID_PARAM), { message: '参数必需是非空对象' }));
149
- }
150
- if (data.hasOwnProperty('_id')) {
151
- return processReturn(this._db.config.throwOnCode, Object.assign(Object.assign({}, ERRORS.INVALID_PARAM), { message: '不能更新_id的值' }));
152
- }
153
- let { multiple } = this._apiOptions;
154
- const multi = multiple === undefined ? true : multiple;
155
- let param = {
156
- collectionName: this._coll,
157
- queryType: QueryType.WHERE,
158
- multi,
159
- merge: true,
160
- upsert: false,
161
- data: UpdateSerializer.encodeEJSON(data, this._apiOptions.raw || false)
162
- };
163
- if (this._fieldFilters) {
164
- param.query = this._fieldFilters;
165
- }
166
- const res = await this._request.send('database.modifyDocument', param, getReqOpts(this._apiOptions));
167
- if (res.code) {
168
- return res;
169
- }
170
- return {
171
- requestId: res.requestId,
172
- updated: res.data.updated,
173
- upsertId: res.data.upsert_id
174
- };
175
- }
176
- field(projection) {
177
- let transformProjection = {};
178
- for (let k in projection) {
208
+ };
209
+ Query.prototype.update = function (data, callback) {
210
+ return withCallback(this._update(data), callback);
211
+ };
212
+ Query.prototype._update = function (data) {
213
+ return __awaiter(this, void 0, void 0, function () {
214
+ var multiple, multi, param, res;
215
+ return __generator(this, function (_a) {
216
+ switch (_a.label) {
217
+ case 0:
218
+ if (!data || typeof data !== 'object') {
219
+ return [2, processReturn(this._db.config.throwOnCode, __assign(__assign({}, ERRORS.INVALID_PARAM), { message: '参数必需是非空对象' }))];
220
+ }
221
+ if (data.hasOwnProperty('_id')) {
222
+ return [2, processReturn(this._db.config.throwOnCode, __assign(__assign({}, ERRORS.INVALID_PARAM), { message: '不能更新_id的值' }))];
223
+ }
224
+ multiple = this._apiOptions.multiple;
225
+ multi = multiple === undefined ? true : multiple;
226
+ param = {
227
+ collectionName: this._coll,
228
+ queryType: QueryType.WHERE,
229
+ multi: multi,
230
+ merge: true,
231
+ upsert: false,
232
+ data: UpdateSerializer.encodeEJSON(data, this._apiOptions.raw || false)
233
+ };
234
+ if (this._transactionId) {
235
+ param.transactionId = this._transactionId;
236
+ }
237
+ if (this._fieldFilters) {
238
+ param.query = this._fieldFilters;
239
+ }
240
+ return [4, this._request.send('database.modifyDocument', param, getReqOpts(this._apiOptions))];
241
+ case 1:
242
+ res = _a.sent();
243
+ if (res.code) {
244
+ return [2, res];
245
+ }
246
+ return [2, {
247
+ requestId: res.requestId,
248
+ updated: res.data.updated,
249
+ upsertId: res.data.upsert_id
250
+ }];
251
+ }
252
+ });
253
+ });
254
+ };
255
+ Query.prototype.field = function (projection) {
256
+ var transformProjection = {};
257
+ for (var k in projection) {
179
258
  if (typeof projection[k] === 'boolean') {
180
259
  transformProjection[k] = projection[k] === true ? 1 : 0;
181
260
  }
@@ -186,61 +265,89 @@ export class Query {
186
265
  transformProjection[k] = projection[k];
187
266
  }
188
267
  }
189
- let newApiOption = Object.assign({}, this._apiOptions);
268
+ var newApiOption = __assign({}, this._apiOptions);
190
269
  newApiOption.projection = transformProjection;
191
270
  return new Query(this._db, this._coll, this._fieldFilters, newApiOption, this._transactionId);
192
- }
193
- async remove() {
194
- const { offset, limit, projection, order } = this._apiOptions;
195
- if (offset !== undefined ||
196
- limit !== undefined ||
197
- projection !== undefined ||
198
- order !== undefined) {
199
- console.warn('`offset`, `limit`, `projection`, `orderBy` are not supported in remove() operation');
200
- }
201
- let { multiple } = this._apiOptions;
202
- const multi = multiple === undefined ? true : multiple;
203
- const param = {
204
- collectionName: this._coll,
205
- query: this._fieldFilters,
206
- queryType: QueryType.WHERE,
207
- multi
208
- };
209
- const res = await this._request.send('database.removeDocument', param, getReqOpts(this._apiOptions));
210
- if (res.code) {
211
- return res;
212
- }
213
- return {
214
- requestId: res.requestId,
215
- deleted: res.data.deleted
216
- };
217
- }
218
- async updateAndReturn(data) {
219
- if (!data || typeof data !== 'object') {
220
- return processReturn(this._db.config.throwOnCode, Object.assign(Object.assign({}, ERRORS.INVALID_PARAM), { message: '参数必需是非空对象' }));
221
- }
222
- if (data.hasOwnProperty('_id')) {
223
- return processReturn(this._db.config.throwOnCode, Object.assign(Object.assign({}, ERRORS.INVALID_PARAM), { message: '不能更新_id的值' }));
224
- }
225
- let param = {
226
- collectionName: this._coll,
227
- queryType: QueryType.WHERE,
228
- data: UpdateSerializer.encodeEJSON(data, false)
229
- };
230
- if (this._transactionId) {
231
- param.transactionId = this._transactionId;
232
- }
233
- if (this._fieldFilters) {
234
- param.query = this._fieldFilters;
235
- }
236
- const res = await this._request.send('database.modifyAndReturnDoc', param, getReqOpts(this._apiOptions));
237
- if (res.code) {
238
- return res;
239
- }
240
- return {
241
- requestId: res.requestId,
242
- updated: res.data.updated,
243
- doc: res.data.doc && EJSON.parse(res.data.doc)
244
- };
245
- }
246
- }
271
+ };
272
+ Query.prototype.remove = function (callback) {
273
+ return withCallback(this._remove(), callback);
274
+ };
275
+ Query.prototype._remove = function () {
276
+ return __awaiter(this, void 0, void 0, function () {
277
+ var _a, offset, limit, projection, order, multiple, multi, param, res;
278
+ return __generator(this, function (_b) {
279
+ switch (_b.label) {
280
+ case 0:
281
+ _a = this._apiOptions, offset = _a.offset, limit = _a.limit, projection = _a.projection, order = _a.order;
282
+ if (offset !== undefined ||
283
+ limit !== undefined ||
284
+ projection !== undefined ||
285
+ order !== undefined) {
286
+ console.warn('`offset`, `limit`, `projection`, `orderBy` are not supported in remove() operation');
287
+ }
288
+ multiple = this._apiOptions.multiple;
289
+ multi = multiple === undefined ? true : multiple;
290
+ param = {
291
+ collectionName: this._coll,
292
+ query: this._fieldFilters,
293
+ queryType: QueryType.WHERE,
294
+ multi: multi
295
+ };
296
+ if (this._transactionId) {
297
+ param.transactionId = this._transactionId;
298
+ }
299
+ return [4, this._request.send('database.removeDocument', param, getReqOpts(this._apiOptions))];
300
+ case 1:
301
+ res = _b.sent();
302
+ if (res.code) {
303
+ return [2, res];
304
+ }
305
+ return [2, {
306
+ requestId: res.requestId,
307
+ deleted: res.data.deleted
308
+ }];
309
+ }
310
+ });
311
+ });
312
+ };
313
+ Query.prototype.updateAndReturn = function (data) {
314
+ return __awaiter(this, void 0, void 0, function () {
315
+ var param, res;
316
+ return __generator(this, function (_a) {
317
+ switch (_a.label) {
318
+ case 0:
319
+ if (!data || typeof data !== 'object') {
320
+ return [2, processReturn(this._db.config.throwOnCode, __assign(__assign({}, ERRORS.INVALID_PARAM), { message: '参数必需是非空对象' }))];
321
+ }
322
+ if (data.hasOwnProperty('_id')) {
323
+ return [2, processReturn(this._db.config.throwOnCode, __assign(__assign({}, ERRORS.INVALID_PARAM), { message: '不能更新_id的值' }))];
324
+ }
325
+ param = {
326
+ collectionName: this._coll,
327
+ queryType: QueryType.WHERE,
328
+ data: UpdateSerializer.encodeEJSON(data, false)
329
+ };
330
+ if (this._transactionId) {
331
+ param.transactionId = this._transactionId;
332
+ }
333
+ if (this._fieldFilters) {
334
+ param.query = this._fieldFilters;
335
+ }
336
+ return [4, this._request.send('database.modifyAndReturnDoc', param, getReqOpts(this._apiOptions))];
337
+ case 1:
338
+ res = _a.sent();
339
+ if (res.code) {
340
+ return [2, res];
341
+ }
342
+ return [2, {
343
+ requestId: res.requestId,
344
+ updated: res.data.updated,
345
+ doc: res.data.doc && EJSON.parse(res.data.doc)
346
+ }];
347
+ }
348
+ });
349
+ });
350
+ };
351
+ return Query;
352
+ }());
353
+ export { Query };
@@ -13,6 +13,6 @@ export declare class RegExp {
13
13
  options: string;
14
14
  };
15
15
  };
16
- readonly _internalType: import("../utils/symbol").InternalSymbol;
16
+ get _internalType(): import("../utils/symbol").InternalSymbol;
17
17
  }
18
18
  export declare function RegExpConstructor(param: any): RegExp;
@@ -1,6 +1,7 @@
1
1
  import { SYMBOL_REGEXP } from '../helper/symbol';
2
- export class RegExp {
3
- constructor({ regexp, options }) {
2
+ var RegExp = (function () {
3
+ function RegExp(_a) {
4
+ var regexp = _a.regexp, options = _a.options;
4
5
  if (!regexp) {
5
6
  throw new TypeError('regexp must be a string');
6
7
  }
@@ -9,18 +10,24 @@ export class RegExp {
9
10
  options: options || ''
10
11
  };
11
12
  }
12
- parse() {
13
+ RegExp.prototype.parse = function () {
13
14
  return {
14
15
  $regularExpression: {
15
16
  pattern: this.$regularExpression.pattern,
16
17
  options: this.$regularExpression.options
17
18
  }
18
19
  };
19
- }
20
- get _internalType() {
21
- return SYMBOL_REGEXP;
22
- }
23
- }
20
+ };
21
+ Object.defineProperty(RegExp.prototype, "_internalType", {
22
+ get: function () {
23
+ return SYMBOL_REGEXP;
24
+ },
25
+ enumerable: false,
26
+ configurable: true
27
+ });
28
+ return RegExp;
29
+ }());
30
+ export { RegExp };
24
31
  export function RegExpConstructor(param) {
25
32
  return new RegExp(param);
26
33
  }
@@ -1,6 +1,6 @@
1
1
  import { LogicCommand } from '../commands/logic';
2
- export declare type IQueryCondition = Record<string, any> | LogicCommand;
3
- export declare type AnyObject = {
2
+ export type IQueryCondition = Record<string, any> | LogicCommand;
3
+ export type AnyObject = {
4
4
  [x: string]: any;
5
5
  };
6
6
  export declare function flattenQueryObject(query: Record<string, any>): Record<string, any>;