@cloudbase/js-sdk 3.6.5-alpha.0 → 3.6.5

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 (251) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/README.md +20 -0
  3. package/ai/dist/index.esm.js +1 -1
  4. package/ai/dist/index.esm.js.map +1 -1
  5. package/ai/dist/index.js +1 -1
  6. package/ai/dist/index.js.map +1 -1
  7. package/apis/dist/index.esm.js +1 -1
  8. package/apis/dist/index.esm.js.map +1 -1
  9. package/apis/dist/index.js +1 -1
  10. package/apis/dist/index.js.map +1 -1
  11. package/app/dist/index.esm.js +1 -1
  12. package/app/dist/index.esm.js.map +1 -1
  13. package/app/dist/index.js +1 -1
  14. package/app/dist/index.js.map +1 -1
  15. package/app/dist/index.node.esm.js +1 -1
  16. package/app/dist/index.node.esm.js.map +1 -1
  17. package/app/dist/index.node.js +1 -1
  18. package/app/dist/index.node.js.map +1 -1
  19. package/auth/dist/index.esm.js +2 -1
  20. package/auth/dist/index.esm.js.LICENSE.txt +12 -0
  21. package/auth/dist/index.esm.js.map +1 -1
  22. package/auth/dist/index.js +2 -1
  23. package/auth/dist/index.js.LICENSE.txt +12 -0
  24. package/auth/dist/index.js.map +1 -1
  25. package/cloudrun/dist/index.esm.js +1 -1
  26. package/cloudrun/dist/index.esm.js.map +1 -1
  27. package/cloudrun/dist/index.js +1 -1
  28. package/cloudrun/dist/index.js.map +1 -1
  29. package/container/dist/index.esm.js +1 -1
  30. package/container/dist/index.esm.js.map +1 -1
  31. package/container/dist/index.js +1 -1
  32. package/container/dist/index.js.map +1 -1
  33. package/database/dist/commonjs/aggregate.d.ts +29 -0
  34. package/database/dist/commonjs/aggregate.js +156 -0
  35. package/database/dist/commonjs/collection.d.ts +9 -0
  36. package/database/dist/commonjs/collection.js +49 -0
  37. package/database/dist/commonjs/command.d.ts +175 -0
  38. package/database/dist/commonjs/command.js +299 -0
  39. package/database/dist/commonjs/commands/logic.d.ts +24 -0
  40. package/database/dist/commonjs/commands/logic.js +89 -0
  41. package/database/dist/commonjs/commands/query.d.ts +68 -0
  42. package/database/dist/commonjs/commands/query.js +160 -0
  43. package/database/dist/commonjs/commands/update.d.ts +29 -0
  44. package/database/dist/commonjs/commands/update.js +51 -0
  45. package/database/dist/commonjs/config/app.config.d.ts +6 -0
  46. package/database/dist/commonjs/config/app.config.js +7 -0
  47. package/database/dist/commonjs/config/error.config.d.ts +3 -0
  48. package/database/dist/commonjs/config/error.config.js +16 -0
  49. package/database/dist/commonjs/const/code.d.ts +30 -0
  50. package/database/dist/commonjs/const/code.js +33 -0
  51. package/database/dist/commonjs/constant.d.ts +51 -0
  52. package/database/dist/commonjs/constant.js +75 -0
  53. package/database/dist/commonjs/document.d.ts +11 -0
  54. package/database/dist/commonjs/document.js +260 -0
  55. package/database/dist/commonjs/geo/index.d.ts +6 -0
  56. package/database/dist/commonjs/geo/index.js +22 -0
  57. package/database/dist/commonjs/geo/interface.d.ts +24 -0
  58. package/database/dist/commonjs/geo/interface.js +2 -0
  59. package/database/dist/commonjs/geo/lineString.d.ts +19 -0
  60. package/database/dist/commonjs/geo/lineString.js +86 -0
  61. package/database/dist/commonjs/geo/multiLineString.d.ts +18 -0
  62. package/database/dist/commonjs/geo/multiLineString.js +95 -0
  63. package/database/dist/commonjs/geo/multiPoint.d.ts +18 -0
  64. package/database/dist/commonjs/geo/multiPoint.js +79 -0
  65. package/database/dist/commonjs/geo/multiPolygon.d.ts +18 -0
  66. package/database/dist/commonjs/geo/multiPolygon.js +122 -0
  67. package/database/dist/commonjs/geo/point.d.ts +19 -0
  68. package/database/dist/commonjs/geo/point.js +50 -0
  69. package/database/dist/commonjs/geo/polygon.d.ts +19 -0
  70. package/database/dist/commonjs/geo/polygon.js +109 -0
  71. package/database/dist/commonjs/helper/symbol.d.ts +14 -0
  72. package/database/dist/commonjs/helper/symbol.js +31 -0
  73. package/database/dist/commonjs/index.d.ts +40 -0
  74. package/database/dist/commonjs/index.js +61 -0
  75. package/database/dist/commonjs/lib/util.d.ts +1 -0
  76. package/database/dist/commonjs/lib/util.js +26 -0
  77. package/database/dist/commonjs/operator-map.d.ts +4 -0
  78. package/database/dist/commonjs/operator-map.js +24 -0
  79. package/database/dist/commonjs/query.d.ts +22 -0
  80. package/database/dist/commonjs/query.js +252 -0
  81. package/database/dist/commonjs/regexp/index.d.ts +14 -0
  82. package/database/dist/commonjs/regexp/index.js +33 -0
  83. package/database/dist/commonjs/serializer/common.d.ts +11 -0
  84. package/database/dist/commonjs/serializer/common.js +127 -0
  85. package/database/dist/commonjs/serializer/datatype.d.ts +7 -0
  86. package/database/dist/commonjs/serializer/datatype.js +132 -0
  87. package/database/dist/commonjs/serializer/query.d.ts +7 -0
  88. package/database/dist/commonjs/serializer/query.js +232 -0
  89. package/database/dist/commonjs/serializer/update.d.ts +15 -0
  90. package/database/dist/commonjs/serializer/update.js +142 -0
  91. package/database/dist/commonjs/serverDate/index.d.ts +13 -0
  92. package/database/dist/commonjs/serverDate/index.js +30 -0
  93. package/database/dist/commonjs/transaction/collection.d.ts +7 -0
  94. package/database/dist/commonjs/transaction/collection.js +49 -0
  95. package/database/dist/commonjs/transaction/document.d.ts +27 -0
  96. package/database/dist/commonjs/transaction/document.js +205 -0
  97. package/database/dist/commonjs/transaction/index.d.ts +30 -0
  98. package/database/dist/commonjs/transaction/index.js +215 -0
  99. package/database/dist/commonjs/transaction/query.d.ts +43 -0
  100. package/database/dist/commonjs/transaction/query.js +261 -0
  101. package/database/dist/commonjs/typings/index.d.ts +40 -0
  102. package/database/dist/commonjs/typings/index.js +2 -0
  103. package/database/dist/commonjs/typings/realtime.d.ts +219 -0
  104. package/database/dist/commonjs/typings/realtime.js +2 -0
  105. package/database/dist/commonjs/util.d.ts +9 -0
  106. package/database/dist/commonjs/util.js +145 -0
  107. package/database/dist/commonjs/utils/error.d.ts +38 -0
  108. package/database/dist/commonjs/utils/error.js +91 -0
  109. package/database/dist/commonjs/utils/msg.d.ts +0 -0
  110. package/database/dist/commonjs/utils/msg.js +0 -0
  111. package/database/dist/commonjs/utils/symbol.d.ts +8 -0
  112. package/database/dist/commonjs/utils/symbol.js +58 -0
  113. package/database/dist/commonjs/utils/type.d.ts +13 -0
  114. package/database/dist/commonjs/utils/type.js +34 -0
  115. package/database/dist/commonjs/utils/utils.d.ts +4 -0
  116. package/database/dist/commonjs/utils/utils.js +39 -0
  117. package/database/dist/commonjs/validate.d.ts +1 -0
  118. package/database/dist/commonjs/validate.js +60 -0
  119. package/database/dist/esm/aggregate.d.ts +29 -0
  120. package/database/dist/esm/aggregate.js +154 -0
  121. package/database/dist/esm/collection.d.ts +9 -0
  122. package/database/dist/esm/collection.js +46 -0
  123. package/database/dist/esm/command.d.ts +175 -0
  124. package/database/dist/esm/command.js +296 -0
  125. package/database/dist/esm/commands/logic.d.ts +24 -0
  126. package/database/dist/esm/commands/logic.js +84 -0
  127. package/database/dist/esm/commands/query.d.ts +68 -0
  128. package/database/dist/esm/commands/query.js +154 -0
  129. package/database/dist/esm/commands/update.d.ts +29 -0
  130. package/database/dist/esm/commands/update.js +46 -0
  131. package/database/dist/esm/config/app.config.d.ts +6 -0
  132. package/database/dist/esm/config/app.config.js +5 -0
  133. package/database/dist/esm/config/error.config.d.ts +3 -0
  134. package/database/dist/esm/config/error.config.js +13 -0
  135. package/database/dist/esm/const/code.d.ts +30 -0
  136. package/database/dist/esm/const/code.js +30 -0
  137. package/database/dist/esm/constant.d.ts +51 -0
  138. package/database/dist/esm/constant.js +65 -0
  139. package/database/dist/esm/document.d.ts +11 -0
  140. package/database/dist/esm/document.js +257 -0
  141. package/database/dist/esm/geo/index.d.ts +6 -0
  142. package/database/dist/esm/geo/index.js +6 -0
  143. package/database/dist/esm/geo/interface.d.ts +24 -0
  144. package/database/dist/esm/geo/interface.js +1 -0
  145. package/database/dist/esm/geo/lineString.d.ts +19 -0
  146. package/database/dist/esm/geo/lineString.js +83 -0
  147. package/database/dist/esm/geo/multiLineString.d.ts +18 -0
  148. package/database/dist/esm/geo/multiLineString.js +92 -0
  149. package/database/dist/esm/geo/multiPoint.d.ts +18 -0
  150. package/database/dist/esm/geo/multiPoint.js +76 -0
  151. package/database/dist/esm/geo/multiPolygon.d.ts +18 -0
  152. package/database/dist/esm/geo/multiPolygon.js +119 -0
  153. package/database/dist/esm/geo/point.d.ts +19 -0
  154. package/database/dist/esm/geo/point.js +47 -0
  155. package/database/dist/esm/geo/polygon.d.ts +19 -0
  156. package/database/dist/esm/geo/polygon.js +106 -0
  157. package/database/dist/esm/helper/symbol.d.ts +14 -0
  158. package/database/dist/esm/helper/symbol.js +14 -0
  159. package/database/dist/esm/index.d.ts +40 -0
  160. package/database/dist/esm/index.js +55 -0
  161. package/database/dist/esm/lib/util.d.ts +1 -0
  162. package/database/dist/esm/lib/util.js +22 -0
  163. package/database/dist/esm/operator-map.d.ts +4 -0
  164. package/database/dist/esm/operator-map.js +20 -0
  165. package/database/dist/esm/query.d.ts +22 -0
  166. package/database/dist/esm/query.js +249 -0
  167. package/database/dist/esm/regexp/index.d.ts +14 -0
  168. package/database/dist/esm/regexp/index.js +29 -0
  169. package/database/dist/esm/serializer/common.d.ts +11 -0
  170. package/database/dist/esm/serializer/common.js +118 -0
  171. package/database/dist/esm/serializer/datatype.d.ts +7 -0
  172. package/database/dist/esm/serializer/datatype.js +127 -0
  173. package/database/dist/esm/serializer/query.d.ts +7 -0
  174. package/database/dist/esm/serializer/query.js +229 -0
  175. package/database/dist/esm/serializer/update.d.ts +15 -0
  176. package/database/dist/esm/serializer/update.js +139 -0
  177. package/database/dist/esm/serverDate/index.d.ts +13 -0
  178. package/database/dist/esm/serverDate/index.js +26 -0
  179. package/database/dist/esm/transaction/collection.d.ts +7 -0
  180. package/database/dist/esm/transaction/collection.js +46 -0
  181. package/database/dist/esm/transaction/document.d.ts +27 -0
  182. package/database/dist/esm/transaction/document.js +202 -0
  183. package/database/dist/esm/transaction/index.d.ts +30 -0
  184. package/database/dist/esm/transaction/index.js +210 -0
  185. package/database/dist/esm/transaction/query.d.ts +43 -0
  186. package/database/dist/esm/transaction/query.js +258 -0
  187. package/database/dist/esm/typings/index.d.ts +40 -0
  188. package/database/dist/esm/typings/index.js +1 -0
  189. package/database/dist/esm/typings/realtime.d.ts +219 -0
  190. package/database/dist/esm/typings/realtime.js +1 -0
  191. package/database/dist/esm/util.d.ts +9 -0
  192. package/database/dist/esm/util.js +142 -0
  193. package/database/dist/esm/utils/error.d.ts +38 -0
  194. package/database/dist/esm/utils/error.js +84 -0
  195. package/database/dist/esm/utils/msg.d.ts +0 -0
  196. package/database/dist/esm/utils/msg.js +0 -0
  197. package/database/dist/esm/utils/symbol.d.ts +8 -0
  198. package/database/dist/esm/utils/symbol.js +55 -0
  199. package/database/dist/esm/utils/type.d.ts +13 -0
  200. package/database/dist/esm/utils/type.js +20 -0
  201. package/database/dist/esm/utils/utils.d.ts +4 -0
  202. package/database/dist/esm/utils/utils.js +33 -0
  203. package/database/dist/esm/validate.d.ts +1 -0
  204. package/database/dist/esm/validate.js +57 -0
  205. package/dist/index.cjs.js +2 -1
  206. package/dist/index.cjs.js.LICENSE.txt +12 -0
  207. package/dist/index.cjs.js.map +1 -1
  208. package/dist/index.esm.js +2 -1
  209. package/dist/index.esm.js.LICENSE.txt +12 -0
  210. package/dist/index.esm.js.map +1 -1
  211. package/dist/index.node.cjs.js +1 -1
  212. package/dist/index.node.cjs.js.LICENSE.txt +13 -0
  213. package/dist/index.node.cjs.js.map +1 -1
  214. package/dist/index.node.esm.js +1 -1
  215. package/dist/index.node.esm.js.LICENSE.txt +13 -0
  216. package/dist/index.node.esm.js.map +1 -1
  217. package/functions/dist/index.esm.js +1 -1
  218. package/functions/dist/index.esm.js.map +1 -1
  219. package/functions/dist/index.js +1 -1
  220. package/functions/dist/index.js.map +1 -1
  221. package/miniprogram_dist/index.js +1 -1
  222. package/model/dist/index.esm.js +1 -1
  223. package/model/dist/index.esm.js.map +1 -1
  224. package/model/dist/index.js +1 -1
  225. package/model/dist/index.js.map +1 -1
  226. package/mysql/dist/index.esm.js +1 -1
  227. package/mysql/dist/index.esm.js.map +1 -1
  228. package/mysql/dist/index.js +1 -1
  229. package/mysql/dist/index.js.map +1 -1
  230. package/oauth/dist/index.esm.js +2 -1
  231. package/oauth/dist/index.esm.js.LICENSE.txt +12 -0
  232. package/oauth/dist/index.esm.js.map +1 -1
  233. package/oauth/dist/index.js +2 -1
  234. package/oauth/dist/index.js.LICENSE.txt +12 -0
  235. package/oauth/dist/index.js.map +1 -1
  236. package/package.json +2 -17
  237. package/realtime/dist/index.esm.js +1 -1
  238. package/realtime/dist/index.esm.js.map +1 -1
  239. package/realtime/dist/index.js +1 -1
  240. package/realtime/dist/index.js.map +1 -1
  241. package/storage/dist/index.esm.js +1 -1
  242. package/storage/dist/index.esm.js.map +1 -1
  243. package/storage/dist/index.js +1 -1
  244. package/storage/dist/index.js.map +1 -1
  245. package/types/package.json +1 -2
  246. package/utilities/package.json +3 -9
  247. package/database/dist/index.d.ts +0 -3
  248. package/database/dist/index.esm.js +0 -2
  249. package/database/dist/index.esm.js.map +0 -1
  250. package/database/dist/index.js +0 -2
  251. package/database/dist/index.js.map +0 -1
@@ -0,0 +1,252 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.Query = void 0;
15
+ var util_1 = require("./lib/util");
16
+ var constant_1 = require("./constant");
17
+ var index_1 = require("./index");
18
+ var validate_1 = require("./validate");
19
+ var util_2 = require("./util");
20
+ var query_1 = require("./serializer/query");
21
+ var update_1 = require("./serializer/update");
22
+ var constant_2 = require("./constant");
23
+ var utils_1 = require("./utils/utils");
24
+ var Query = (function () {
25
+ function Query(db, coll, fieldFilters, fieldOrders, queryOptions) {
26
+ var _this = this;
27
+ this.watch = function (options) {
28
+ var ws = (0, utils_1.getWsInstance)(_this._db);
29
+ return ws.watch(__assign(__assign({}, options), { envId: _this._db.config.env, collectionName: _this._coll, query: JSON.stringify(_this._fieldFilters || {}), limit: _this._queryOptions.limit, orderBy: _this._fieldOrders
30
+ ? _this._fieldOrders.reduce(function (acc, cur) {
31
+ acc[cur.field] = cur.direction;
32
+ return acc;
33
+ }, {})
34
+ : undefined }));
35
+ };
36
+ this._db = db;
37
+ this._coll = coll;
38
+ this._fieldFilters = fieldFilters;
39
+ this._fieldOrders = fieldOrders || [];
40
+ this._queryOptions = queryOptions || {};
41
+ this._request = index_1.Db.createRequest(this._db.config);
42
+ }
43
+ Query.prototype.get = function (callback) {
44
+ callback = callback || (0, util_1.createPromiseCallback)();
45
+ var newOder = [];
46
+ if (this._fieldOrders) {
47
+ this._fieldOrders.forEach(function (order) {
48
+ newOder.push(order);
49
+ });
50
+ }
51
+ var param = {
52
+ collectionName: this._coll,
53
+ queryType: constant_1.QueryType.WHERE
54
+ };
55
+ if (this._fieldFilters) {
56
+ param.query = this._fieldFilters;
57
+ }
58
+ if (newOder.length > 0) {
59
+ param.order = newOder;
60
+ }
61
+ if (this._queryOptions.offset) {
62
+ param.offset = this._queryOptions.offset;
63
+ }
64
+ if (this._queryOptions.limit) {
65
+ param.limit = this._queryOptions.limit < 1000 ? this._queryOptions.limit : 1000;
66
+ }
67
+ else {
68
+ param.limit = 100;
69
+ }
70
+ if (this._queryOptions.projection) {
71
+ param.projection = this._queryOptions.projection;
72
+ }
73
+ this._request
74
+ .send('database.queryDocument', param)
75
+ .then(function (res) {
76
+ if (res.code) {
77
+ callback(0, res);
78
+ }
79
+ else {
80
+ var documents = util_2.Util.formatResDocumentData(res.data.list);
81
+ var result = {
82
+ data: documents,
83
+ requestId: res.requestId
84
+ };
85
+ if (res.total !== undefined)
86
+ result.total = res.total;
87
+ if (res.limit !== undefined)
88
+ result.limit = res.limit;
89
+ if (res.offset !== undefined)
90
+ result.offset = res.offset;
91
+ callback(0, result);
92
+ }
93
+ })
94
+ .catch(function (err) {
95
+ callback(err);
96
+ });
97
+ return callback.promise;
98
+ };
99
+ Query.prototype.count = function (callback) {
100
+ callback = callback || (0, util_1.createPromiseCallback)();
101
+ var param = {
102
+ collectionName: this._coll,
103
+ queryType: constant_1.QueryType.WHERE
104
+ };
105
+ if (this._fieldFilters) {
106
+ param.query = this._fieldFilters;
107
+ }
108
+ this._request
109
+ .send('database.countDocument', param)
110
+ .then(function (res) {
111
+ if (res.code) {
112
+ callback(0, res);
113
+ }
114
+ else {
115
+ callback(0, {
116
+ requestId: res.requestId,
117
+ total: res.data.total
118
+ });
119
+ }
120
+ })
121
+ .catch(function (e) {
122
+ callback(e);
123
+ });
124
+ return callback.promise;
125
+ };
126
+ Query.prototype.where = function (query) {
127
+ if (Object.prototype.toString.call(query).slice(8, -1) !== 'Object') {
128
+ throw Error(constant_2.ErrorCode.QueryParamTypeError);
129
+ }
130
+ var keys = Object.keys(query);
131
+ var checkFlag = keys.some(function (item) {
132
+ return query[item] !== undefined;
133
+ });
134
+ if (keys.length && !checkFlag) {
135
+ throw Error(constant_2.ErrorCode.QueryParamValueError);
136
+ }
137
+ return new Query(this._db, this._coll, query_1.QuerySerializer.encode(query), this._fieldOrders, this._queryOptions);
138
+ };
139
+ Query.prototype.orderBy = function (fieldPath, directionStr) {
140
+ validate_1.Validate.isFieldPath(fieldPath);
141
+ validate_1.Validate.isFieldOrder(directionStr);
142
+ var newOrder = {
143
+ field: fieldPath,
144
+ direction: directionStr
145
+ };
146
+ var combinedOrders = this._fieldOrders.concat(newOrder);
147
+ return new Query(this._db, this._coll, this._fieldFilters, combinedOrders, this._queryOptions);
148
+ };
149
+ Query.prototype.limit = function (limit) {
150
+ validate_1.Validate.isInteger('limit', limit);
151
+ var option = __assign({}, this._queryOptions);
152
+ option.limit = limit;
153
+ return new Query(this._db, this._coll, this._fieldFilters, this._fieldOrders, option);
154
+ };
155
+ Query.prototype.skip = function (offset) {
156
+ validate_1.Validate.isInteger('offset', offset);
157
+ var option = __assign({}, this._queryOptions);
158
+ option.offset = offset;
159
+ return new Query(this._db, this._coll, this._fieldFilters, this._fieldOrders, option);
160
+ };
161
+ Query.prototype.update = function (data, callback) {
162
+ callback = callback || (0, util_1.createPromiseCallback)();
163
+ if (!data || typeof data !== 'object') {
164
+ return Promise.resolve({
165
+ code: 'INVALID_PARAM',
166
+ message: '参数必需是非空对象'
167
+ });
168
+ }
169
+ if (data.hasOwnProperty('_id')) {
170
+ return Promise.resolve({
171
+ code: 'INVALID_PARAM',
172
+ message: '不能更新_id的值'
173
+ });
174
+ }
175
+ var param = {
176
+ collectionName: this._coll,
177
+ query: this._fieldFilters,
178
+ queryType: constant_1.QueryType.WHERE,
179
+ multi: true,
180
+ merge: true,
181
+ upsert: false,
182
+ data: update_1.UpdateSerializer.encode(data)
183
+ };
184
+ this._request
185
+ .send('database.updateDocument', param)
186
+ .then(function (res) {
187
+ if (res.code) {
188
+ callback(0, res);
189
+ }
190
+ else {
191
+ callback(0, {
192
+ requestId: res.requestId,
193
+ updated: res.data.updated,
194
+ upsertId: res.data.upsert_id
195
+ });
196
+ }
197
+ })
198
+ .catch(function (e) {
199
+ callback(e);
200
+ });
201
+ return callback.promise;
202
+ };
203
+ Query.prototype.field = function (projection) {
204
+ for (var k in projection) {
205
+ if (projection[k]) {
206
+ if (typeof projection[k] !== 'object') {
207
+ projection[k] = 1;
208
+ }
209
+ }
210
+ else {
211
+ projection[k] = 0;
212
+ }
213
+ }
214
+ var option = __assign({}, this._queryOptions);
215
+ option.projection = projection;
216
+ return new Query(this._db, this._coll, this._fieldFilters, this._fieldOrders, option);
217
+ };
218
+ Query.prototype.remove = function (callback) {
219
+ callback = callback || (0, util_1.createPromiseCallback)();
220
+ if (Object.keys(this._queryOptions).length > 0) {
221
+ console.warn('`offset`, `limit` and `projection` are not supported in remove() operation');
222
+ }
223
+ if (this._fieldOrders.length > 0) {
224
+ console.warn('`orderBy` is not supported in remove() operation');
225
+ }
226
+ var param = {
227
+ collectionName: this._coll,
228
+ query: query_1.QuerySerializer.encode(this._fieldFilters),
229
+ queryType: constant_1.QueryType.WHERE,
230
+ multi: true
231
+ };
232
+ this._request
233
+ .send('database.deleteDocument', param)
234
+ .then(function (res) {
235
+ if (res.code) {
236
+ callback(0, res);
237
+ }
238
+ else {
239
+ callback(0, {
240
+ requestId: res.requestId,
241
+ deleted: res.data.deleted
242
+ });
243
+ }
244
+ })
245
+ .catch(function (e) {
246
+ callback(e);
247
+ });
248
+ return callback.promise;
249
+ };
250
+ return Query;
251
+ }());
252
+ exports.Query = Query;
@@ -0,0 +1,14 @@
1
+ export declare class RegExp {
2
+ $regex: string;
3
+ $options: string;
4
+ constructor({ regexp, options }: {
5
+ regexp: any;
6
+ options: any;
7
+ });
8
+ parse(): {
9
+ $regex: string;
10
+ $options: string;
11
+ };
12
+ get _internalType(): import("../utils/symbol").InternalSymbol;
13
+ }
14
+ export declare function RegExpConstructor(param: any): RegExp;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RegExpConstructor = exports.RegExp = void 0;
4
+ var symbol_1 = require("../helper/symbol");
5
+ var RegExp = (function () {
6
+ function RegExp(_a) {
7
+ var regexp = _a.regexp, options = _a.options;
8
+ if (!regexp) {
9
+ throw new TypeError('regexp must be a string');
10
+ }
11
+ this.$regex = regexp;
12
+ this.$options = options;
13
+ }
14
+ RegExp.prototype.parse = function () {
15
+ return {
16
+ $regex: this.$regex,
17
+ $options: this.$options
18
+ };
19
+ };
20
+ Object.defineProperty(RegExp.prototype, "_internalType", {
21
+ get: function () {
22
+ return symbol_1.SYMBOL_REGEXP;
23
+ },
24
+ enumerable: false,
25
+ configurable: true
26
+ });
27
+ return RegExp;
28
+ }());
29
+ exports.RegExp = RegExp;
30
+ function RegExpConstructor(param) {
31
+ return new RegExp(param);
32
+ }
33
+ exports.RegExpConstructor = RegExpConstructor;
@@ -0,0 +1,11 @@
1
+ import { LogicCommand } from '../commands/logic';
2
+ export type IQueryCondition = Record<string, any> | LogicCommand;
3
+ export type AnyObject = {
4
+ [x: string]: any;
5
+ };
6
+ export declare function flattenQueryObject(query: Record<string, any>): Record<string, any>;
7
+ export declare function flattenObject(object: AnyObject): AnyObject;
8
+ export declare function mergeConditionAfterEncode(query: Record<string, any>, condition: Record<string, any>, key: string): void;
9
+ export declare function isConversionRequired(val: any): boolean;
10
+ export declare function encodeInternalDataType(val: any): IQueryCondition;
11
+ export declare function decodeInternalDataType(object: AnyObject): any;
@@ -0,0 +1,127 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __read = (this && this.__read) || function (o, n) {
14
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
15
+ if (!m) return o;
16
+ var i = m.call(o), r, ar = [], e;
17
+ try {
18
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
19
+ }
20
+ catch (error) { e = { error: error }; }
21
+ finally {
22
+ try {
23
+ if (r && !r.done && (m = i["return"])) m.call(i);
24
+ }
25
+ finally { if (e) throw e.error; }
26
+ }
27
+ return ar;
28
+ };
29
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
30
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
31
+ if (ar || !(i in from)) {
32
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
33
+ ar[i] = from[i];
34
+ }
35
+ }
36
+ return to.concat(ar || Array.prototype.slice.call(from));
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.decodeInternalDataType = exports.encodeInternalDataType = exports.isConversionRequired = exports.mergeConditionAfterEncode = exports.flattenObject = exports.flattenQueryObject = void 0;
40
+ var type_1 = require("../utils/type");
41
+ var datatype_1 = require("./datatype");
42
+ function flatten(query, shouldPreserverObject, parents, visited) {
43
+ var cloned = __assign({}, query);
44
+ for (var key in query) {
45
+ if (/^\$/.test(key))
46
+ continue;
47
+ var value = query[key];
48
+ if (!value)
49
+ continue;
50
+ if ((0, type_1.isObject)(value) && !shouldPreserverObject(value)) {
51
+ if (visited.indexOf(value) > -1) {
52
+ throw new Error('Cannot convert circular structure to JSON');
53
+ }
54
+ var newParents = __spreadArray(__spreadArray([], __read(parents), false), [
55
+ key,
56
+ ], false);
57
+ var newVisited = __spreadArray(__spreadArray([], __read(visited), false), [
58
+ value,
59
+ ], false);
60
+ var flattenedChild = flatten(value, shouldPreserverObject, newParents, newVisited);
61
+ cloned[key] = flattenedChild;
62
+ var hasKeyNotCombined = false;
63
+ for (var childKey in flattenedChild) {
64
+ if (!/^\$/.test(childKey)) {
65
+ cloned["".concat(key, ".").concat(childKey)] = flattenedChild[childKey];
66
+ delete cloned[key][childKey];
67
+ }
68
+ else {
69
+ hasKeyNotCombined = true;
70
+ }
71
+ }
72
+ if (!hasKeyNotCombined) {
73
+ delete cloned[key];
74
+ }
75
+ }
76
+ }
77
+ return cloned;
78
+ }
79
+ function flattenQueryObject(query) {
80
+ return flatten(query, isConversionRequired, [], [query]);
81
+ }
82
+ exports.flattenQueryObject = flattenQueryObject;
83
+ function flattenObject(object) {
84
+ return flatten(object, function (_) { return false; }, [], [object]);
85
+ }
86
+ exports.flattenObject = flattenObject;
87
+ function mergeConditionAfterEncode(query, condition, key) {
88
+ if (!condition[key]) {
89
+ delete query[key];
90
+ }
91
+ for (var conditionKey in condition) {
92
+ if (query[conditionKey]) {
93
+ if ((0, type_1.isArray)(query[conditionKey])) {
94
+ query[conditionKey].push(condition[conditionKey]);
95
+ }
96
+ else if ((0, type_1.isObject)(query[conditionKey])) {
97
+ if ((0, type_1.isObject)(condition[conditionKey])) {
98
+ Object.assign(query[conditionKey], condition[conditionKey]);
99
+ }
100
+ else {
101
+ console.warn("unmergable condition, query is object but condition is ".concat((0, type_1.getType)(condition), ", can only overwrite"), condition, key);
102
+ query[conditionKey] = condition[conditionKey];
103
+ }
104
+ }
105
+ else {
106
+ console.warn("to-merge query is of type ".concat((0, type_1.getType)(query), ", can only overwrite"), query, condition, key);
107
+ query[conditionKey] = condition[conditionKey];
108
+ }
109
+ }
110
+ else {
111
+ query[conditionKey] = condition[conditionKey];
112
+ }
113
+ }
114
+ }
115
+ exports.mergeConditionAfterEncode = mergeConditionAfterEncode;
116
+ function isConversionRequired(val) {
117
+ return (0, type_1.isInternalObject)(val) || (0, type_1.isDate)(val) || (0, type_1.isRegExp)(val);
118
+ }
119
+ exports.isConversionRequired = isConversionRequired;
120
+ function encodeInternalDataType(val) {
121
+ return (0, datatype_1.serialize)(val);
122
+ }
123
+ exports.encodeInternalDataType = encodeInternalDataType;
124
+ function decodeInternalDataType(object) {
125
+ return (0, datatype_1.deserialize)(object);
126
+ }
127
+ exports.decodeInternalDataType = decodeInternalDataType;
@@ -0,0 +1,7 @@
1
+ import { LogicCommand } from '../commands/logic';
2
+ export type IQueryCondition = Record<string, any> | LogicCommand;
3
+ export type AnyObject = {
4
+ [x: string]: any;
5
+ };
6
+ export declare function serialize(val: any): IQueryCondition;
7
+ export declare function deserialize(object: AnyObject): any;
@@ -0,0 +1,132 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __read = (this && this.__read) || function (o, n) {
14
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
15
+ if (!m) return o;
16
+ var i = m.call(o), r, ar = [], e;
17
+ try {
18
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
19
+ }
20
+ catch (error) { e = { error: error }; }
21
+ finally {
22
+ try {
23
+ if (r && !r.done && (m = i["return"])) m.call(i);
24
+ }
25
+ finally { if (e) throw e.error; }
26
+ }
27
+ return ar;
28
+ };
29
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
30
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
31
+ if (ar || !(i in from)) {
32
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
33
+ ar[i] = from[i];
34
+ }
35
+ }
36
+ return to.concat(ar || Array.prototype.slice.call(from));
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.deserialize = exports.serialize = void 0;
40
+ var symbol_1 = require("../helper/symbol");
41
+ var type_1 = require("../utils/type");
42
+ var index_1 = require("../geo/index");
43
+ var index_2 = require("../serverDate/index");
44
+ function serialize(val) {
45
+ return serializeHelper(val, [val]);
46
+ }
47
+ exports.serialize = serialize;
48
+ function serializeHelper(val, visited) {
49
+ if ((0, type_1.isInternalObject)(val)) {
50
+ switch (val._internalType) {
51
+ case symbol_1.SYMBOL_GEO_POINT: {
52
+ return val.toJSON();
53
+ }
54
+ case symbol_1.SYMBOL_SERVER_DATE: {
55
+ return val.parse();
56
+ }
57
+ case symbol_1.SYMBOL_REGEXP: {
58
+ return val.parse();
59
+ }
60
+ default: {
61
+ return val.toJSON ? val.toJSON() : val;
62
+ }
63
+ }
64
+ }
65
+ else if ((0, type_1.isDate)(val)) {
66
+ return {
67
+ $date: +val,
68
+ };
69
+ }
70
+ else if ((0, type_1.isRegExp)(val)) {
71
+ return {
72
+ $regex: val.source,
73
+ $options: val.flags,
74
+ };
75
+ }
76
+ else if ((0, type_1.isArray)(val)) {
77
+ return val.map(function (item) {
78
+ if (visited.indexOf(item) > -1) {
79
+ throw new Error('Cannot convert circular structure to JSON');
80
+ }
81
+ return serializeHelper(item, __spreadArray(__spreadArray([], __read(visited), false), [
82
+ item,
83
+ ], false));
84
+ });
85
+ }
86
+ else if ((0, type_1.isObject)(val)) {
87
+ var ret = __assign({}, val);
88
+ for (var key in ret) {
89
+ if (visited.indexOf(ret[key]) > -1) {
90
+ throw new Error('Cannot convert circular structure to JSON');
91
+ }
92
+ ret[key] = serializeHelper(ret[key], __spreadArray(__spreadArray([], __read(visited), false), [
93
+ ret[key],
94
+ ], false));
95
+ }
96
+ return ret;
97
+ }
98
+ else {
99
+ return val;
100
+ }
101
+ }
102
+ function deserialize(object) {
103
+ var ret = __assign({}, object);
104
+ for (var key in ret) {
105
+ switch (key) {
106
+ case '$date': {
107
+ switch ((0, type_1.getType)(ret[key])) {
108
+ case 'number': {
109
+ return new Date(ret[key]);
110
+ }
111
+ case 'object': {
112
+ return new index_2.ServerDate(ret[key]);
113
+ }
114
+ }
115
+ break;
116
+ }
117
+ case 'type': {
118
+ switch (ret.type) {
119
+ case 'Point': {
120
+ if ((0, type_1.isArray)(ret.coordinates) && (0, type_1.isNumber)(ret.coordinates[0]) && (0, type_1.isNumber)(ret.coordinates[1])) {
121
+ return new index_1.Point(ret.coordinates[0], ret.coordinates[1]);
122
+ }
123
+ break;
124
+ }
125
+ }
126
+ break;
127
+ }
128
+ }
129
+ }
130
+ return object;
131
+ }
132
+ exports.deserialize = deserialize;
@@ -0,0 +1,7 @@
1
+ import { QueryCommand } from '../commands/query';
2
+ import { LogicCommand } from '../commands/logic';
3
+ export type IQueryCondition = Record<string, any> | LogicCommand;
4
+ export declare class QuerySerializer {
5
+ constructor();
6
+ static encode(query: IQueryCondition | QueryCommand | LogicCommand): IQueryCondition;
7
+ }