@cloudbase/js-sdk 2.28.6 → 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,202 @@
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
+ };
48
+ import { EJSON } from 'bson';
49
+ import { ERRORS } from '../const/code';
50
+ import { UpdateSerializer } from '../serializer/update';
51
+ import { serialize } from '../serializer/datatype';
52
+ import { Util } from '../util';
53
+ var GET_DOC = 'database.getInTransaction';
54
+ var UPDATE_DOC = 'database.updateDocInTransaction';
55
+ var DELETE_DOC = 'database.deleteDocInTransaction';
56
+ var INSERT_DOC = 'database.insertDocInTransaction';
57
+ var DocumentReference = (function () {
58
+ function DocumentReference(transaction, coll, docID) {
59
+ this._coll = coll;
60
+ this.id = docID;
61
+ this._transaction = transaction;
62
+ this._request = this._transaction.getRequestMethod();
63
+ this._transactionId = this._transaction.getTransactionId();
64
+ }
65
+ DocumentReference.prototype.create = function (data) {
66
+ return __awaiter(this, void 0, void 0, function () {
67
+ var params, res, inserted, ok;
68
+ return __generator(this, function (_a) {
69
+ switch (_a.label) {
70
+ case 0:
71
+ params = {
72
+ collectionName: this._coll,
73
+ transactionId: this._transactionId,
74
+ data: EJSON.stringify(serialize(data), { relaxed: false })
75
+ };
76
+ if (this.id) {
77
+ params['_id'] = this.id;
78
+ }
79
+ return [4, this._request.send(INSERT_DOC, params)];
80
+ case 1:
81
+ res = _a.sent();
82
+ if (res.code) {
83
+ throw res;
84
+ }
85
+ inserted = EJSON.parse(res.inserted);
86
+ ok = EJSON.parse(res.ok);
87
+ if (ok == 1 && inserted == 1) {
88
+ return [2, __assign(__assign({}, res), { ok: ok, inserted: inserted })];
89
+ }
90
+ else {
91
+ throw new Error(ERRORS.INSERT_DOC_FAIL.message);
92
+ }
93
+ return [2];
94
+ }
95
+ });
96
+ });
97
+ };
98
+ DocumentReference.prototype.get = function () {
99
+ return __awaiter(this, void 0, void 0, function () {
100
+ var param, res;
101
+ return __generator(this, function (_a) {
102
+ switch (_a.label) {
103
+ case 0:
104
+ param = {
105
+ collectionName: this._coll,
106
+ transactionId: this._transactionId,
107
+ query: {
108
+ _id: { $eq: this.id }
109
+ }
110
+ };
111
+ return [4, this._request.send(GET_DOC, param)];
112
+ case 1:
113
+ res = _a.sent();
114
+ if (res.code)
115
+ throw res;
116
+ return [2, {
117
+ data: res.data !== 'null' ? Util.formatField(EJSON.parse(res.data)) : EJSON.parse(res.data),
118
+ requestId: res.requestId
119
+ }];
120
+ }
121
+ });
122
+ });
123
+ };
124
+ DocumentReference.prototype.set = function (data) {
125
+ return __awaiter(this, void 0, void 0, function () {
126
+ var param, res;
127
+ return __generator(this, function (_a) {
128
+ switch (_a.label) {
129
+ case 0:
130
+ param = {
131
+ collectionName: this._coll,
132
+ transactionId: this._transactionId,
133
+ query: {
134
+ _id: { $eq: this.id }
135
+ },
136
+ data: EJSON.stringify(serialize(data), { relaxed: false }),
137
+ upsert: true
138
+ };
139
+ return [4, this._request.send(UPDATE_DOC, param)];
140
+ case 1:
141
+ res = _a.sent();
142
+ if (res.code)
143
+ throw res;
144
+ return [2, __assign(__assign({}, res), { updated: EJSON.parse(res.updated), upserted: res.upserted
145
+ ? JSON.parse(res.upserted)
146
+ : null })];
147
+ }
148
+ });
149
+ });
150
+ };
151
+ DocumentReference.prototype.update = function (data) {
152
+ return __awaiter(this, void 0, void 0, function () {
153
+ var param, res;
154
+ return __generator(this, function (_a) {
155
+ switch (_a.label) {
156
+ case 0:
157
+ param = {
158
+ collectionName: this._coll,
159
+ transactionId: this._transactionId,
160
+ query: {
161
+ _id: { $eq: this.id }
162
+ },
163
+ data: EJSON.stringify(UpdateSerializer.encode(data), {
164
+ relaxed: false
165
+ })
166
+ };
167
+ return [4, this._request.send(UPDATE_DOC, param)];
168
+ case 1:
169
+ res = _a.sent();
170
+ if (res.code)
171
+ throw res;
172
+ return [2, __assign(__assign({}, res), { updated: EJSON.parse(res.updated) })];
173
+ }
174
+ });
175
+ });
176
+ };
177
+ DocumentReference.prototype.delete = function () {
178
+ return __awaiter(this, void 0, void 0, function () {
179
+ var param, res;
180
+ return __generator(this, function (_a) {
181
+ switch (_a.label) {
182
+ case 0:
183
+ param = {
184
+ collectionName: this._coll,
185
+ transactionId: this._transactionId,
186
+ query: {
187
+ _id: { $eq: this.id }
188
+ }
189
+ };
190
+ return [4, this._request.send(DELETE_DOC, param)];
191
+ case 1:
192
+ res = _a.sent();
193
+ if (res.code)
194
+ throw res;
195
+ return [2, __assign(__assign({}, res), { deleted: EJSON.parse(res.deleted) })];
196
+ }
197
+ });
198
+ });
199
+ };
200
+ return DocumentReference;
201
+ }());
202
+ export { DocumentReference };
@@ -0,0 +1,30 @@
1
+ import { Db } from '../index';
2
+ import { CollectionReference } from './collection';
3
+ interface TransactionAPI {
4
+ send(interfaceName: string, param?: any): any;
5
+ }
6
+ export declare class Transaction {
7
+ private _id;
8
+ private _db;
9
+ private _request;
10
+ aborted: boolean;
11
+ abortReason: any;
12
+ commited: boolean;
13
+ inited: boolean;
14
+ constructor(db: Db);
15
+ init(): Promise<void>;
16
+ collection(collName: string): CollectionReference;
17
+ getTransactionId(): string;
18
+ getRequestMethod(): TransactionAPI;
19
+ commit(): Promise<CommitResult>;
20
+ rollback(customRollbackRes: any): Promise<RollbackResult>;
21
+ }
22
+ export declare function startTransaction(): Promise<Transaction>;
23
+ export declare function runTransaction(callback: (transaction: Transaction) => void | Promise<any>, times?: number): Promise<any>;
24
+ interface CommitResult {
25
+ requestId: string;
26
+ }
27
+ interface RollbackResult {
28
+ requestId: string;
29
+ }
30
+ export {};
@@ -0,0 +1,210 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ var __generator = (this && this.__generator) || function (thisArg, body) {
11
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
12
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
+ function verb(n) { return function (v) { return step([n, v]); }; }
14
+ function step(op) {
15
+ if (f) throw new TypeError("Generator is already executing.");
16
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
17
+ 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;
18
+ if (y = 0, t) op = [op[0] & 2, t.value];
19
+ switch (op[0]) {
20
+ case 0: case 1: t = op; break;
21
+ case 4: _.label++; return { value: op[1], done: false };
22
+ case 5: _.label++; y = op[1]; op = [0]; continue;
23
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
+ default:
25
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
+ if (t[2]) _.ops.pop();
30
+ _.trys.pop(); continue;
31
+ }
32
+ op = body.call(thisArg, _);
33
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
+ }
36
+ };
37
+ import { Db } from '../index';
38
+ import { CollectionReference } from './collection';
39
+ import { ERRORS } from '../const/code';
40
+ var START = 'database.startTransaction';
41
+ var COMMIT = 'database.commitTransaction';
42
+ var ABORT = 'database.abortTransaction';
43
+ var Transaction = (function () {
44
+ function Transaction(db) {
45
+ this._db = db;
46
+ this._request = Db.createRequest(this._db.config);
47
+ this.aborted = false;
48
+ this.commited = false;
49
+ this.inited = false;
50
+ }
51
+ Transaction.prototype.init = function () {
52
+ return __awaiter(this, void 0, void 0, function () {
53
+ var res;
54
+ return __generator(this, function (_a) {
55
+ switch (_a.label) {
56
+ case 0: return [4, this._request.send(START)];
57
+ case 1:
58
+ res = _a.sent();
59
+ if (res.code) {
60
+ throw res;
61
+ }
62
+ this.inited = true;
63
+ this._id = res.transactionId;
64
+ return [2];
65
+ }
66
+ });
67
+ });
68
+ };
69
+ Transaction.prototype.collection = function (collName) {
70
+ if (!collName) {
71
+ throw new Error('Collection name is required');
72
+ }
73
+ return new CollectionReference(this, collName);
74
+ };
75
+ Transaction.prototype.getTransactionId = function () {
76
+ return this._id;
77
+ };
78
+ Transaction.prototype.getRequestMethod = function () {
79
+ return this._request;
80
+ };
81
+ Transaction.prototype.commit = function () {
82
+ return __awaiter(this, void 0, void 0, function () {
83
+ var param, res;
84
+ return __generator(this, function (_a) {
85
+ switch (_a.label) {
86
+ case 0:
87
+ param = {
88
+ transactionId: this._id
89
+ };
90
+ return [4, this._request.send(COMMIT, param)];
91
+ case 1:
92
+ res = _a.sent();
93
+ if (res.code)
94
+ throw res;
95
+ this.commited = true;
96
+ return [2, res];
97
+ }
98
+ });
99
+ });
100
+ };
101
+ Transaction.prototype.rollback = function (customRollbackRes) {
102
+ return __awaiter(this, void 0, void 0, function () {
103
+ var param, res;
104
+ return __generator(this, function (_a) {
105
+ switch (_a.label) {
106
+ case 0:
107
+ param = {
108
+ transactionId: this._id
109
+ };
110
+ return [4, this._request.send(ABORT, param)];
111
+ case 1:
112
+ res = _a.sent();
113
+ if (res.code)
114
+ throw res;
115
+ this.aborted = true;
116
+ this.abortReason = customRollbackRes;
117
+ return [2, res];
118
+ }
119
+ });
120
+ });
121
+ };
122
+ return Transaction;
123
+ }());
124
+ export { Transaction };
125
+ export function startTransaction() {
126
+ return __awaiter(this, void 0, void 0, function () {
127
+ var transaction;
128
+ return __generator(this, function (_a) {
129
+ switch (_a.label) {
130
+ case 0:
131
+ transaction = new Transaction(this);
132
+ return [4, transaction.init()];
133
+ case 1:
134
+ _a.sent();
135
+ return [2, transaction];
136
+ }
137
+ });
138
+ });
139
+ }
140
+ export function runTransaction(callback, times) {
141
+ if (times === void 0) { times = 3; }
142
+ return __awaiter(this, void 0, void 0, function () {
143
+ var transaction, callbackRes, error_1, throwWithRollback;
144
+ var _this = this;
145
+ return __generator(this, function (_a) {
146
+ switch (_a.label) {
147
+ case 0:
148
+ _a.trys.push([0, 4, , 10]);
149
+ transaction = new Transaction(this);
150
+ return [4, transaction.init()];
151
+ case 1:
152
+ _a.sent();
153
+ return [4, callback(transaction)];
154
+ case 2:
155
+ callbackRes = _a.sent();
156
+ if (transaction.aborted === true) {
157
+ throw transaction.abortReason;
158
+ }
159
+ return [4, transaction.commit()];
160
+ case 3:
161
+ _a.sent();
162
+ return [2, callbackRes];
163
+ case 4:
164
+ error_1 = _a.sent();
165
+ if (transaction.inited === false) {
166
+ throw error_1;
167
+ }
168
+ throwWithRollback = function (error) { return __awaiter(_this, void 0, void 0, function () {
169
+ var err_1;
170
+ return __generator(this, function (_a) {
171
+ switch (_a.label) {
172
+ case 0:
173
+ if (!(!transaction.aborted && !transaction.commited)) return [3, 5];
174
+ _a.label = 1;
175
+ case 1:
176
+ _a.trys.push([1, 3, , 4]);
177
+ return [4, transaction.rollback()];
178
+ case 2:
179
+ _a.sent();
180
+ return [3, 4];
181
+ case 3:
182
+ err_1 = _a.sent();
183
+ return [3, 4];
184
+ case 4: throw error;
185
+ case 5:
186
+ if (transaction.aborted === true) {
187
+ throw transaction.abortReason;
188
+ }
189
+ throw error;
190
+ }
191
+ });
192
+ }); };
193
+ if (!(times <= 0)) return [3, 6];
194
+ return [4, throwWithRollback(error_1)];
195
+ case 5:
196
+ _a.sent();
197
+ _a.label = 6;
198
+ case 6:
199
+ if (!(error_1 && error_1.code === ERRORS.DATABASE_TRANSACTION_CONFLICT.code)) return [3, 8];
200
+ return [4, runTransaction.bind(this)(callback, --times)];
201
+ case 7: return [2, _a.sent()];
202
+ case 8: return [4, throwWithRollback(error_1)];
203
+ case 9:
204
+ _a.sent();
205
+ return [3, 10];
206
+ case 10: return [2];
207
+ }
208
+ });
209
+ });
210
+ }
@@ -0,0 +1,43 @@
1
+ import { Transaction } from './index';
2
+ import { OrderByDirection } from '../constant';
3
+ interface QueryOrder {
4
+ field?: string;
5
+ direction?: 'asc' | 'desc';
6
+ }
7
+ interface QueryOption {
8
+ limit?: number;
9
+ offset?: number;
10
+ projection?: Object;
11
+ }
12
+ interface GetResult {
13
+ data: any[];
14
+ requestId: string;
15
+ total?: number;
16
+ limit?: number;
17
+ offset?: number;
18
+ }
19
+ interface UpdateResult {
20
+ requestId: string;
21
+ updated: number;
22
+ }
23
+ interface DeleteResult {
24
+ requestId: string;
25
+ deleted: number | string;
26
+ }
27
+ export declare class Query {
28
+ protected _transaction: Transaction;
29
+ constructor(transaction: Transaction, coll: string, fieldFilters?: Object, fieldOrders?: QueryOrder[], queryOptions?: QueryOption);
30
+ where(query: object): Query;
31
+ orderBy(fieldPath: string, directionStr: OrderByDirection): Query;
32
+ limit(limit: number): Query;
33
+ skip(offset: number): Query;
34
+ field(projection: any): Query;
35
+ get(): Promise<GetResult>;
36
+ count(): Promise<{
37
+ requestId: string;
38
+ total: number;
39
+ }>;
40
+ update(data: Object): Promise<UpdateResult>;
41
+ remove(): Promise<DeleteResult>;
42
+ }
43
+ export {};