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