@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,38 @@
1
+ export interface ICloudSDKError extends Error {
2
+ errCode: number;
3
+ errMsg: string;
4
+ }
5
+ export declare class CloudSDKError extends Error {
6
+ errCode: string;
7
+ errMsg: string;
8
+ requestID?: string;
9
+ constructor(options: IErrorConstructorOptions);
10
+ get message(): string;
11
+ set message(msg: string);
12
+ }
13
+ interface IErrorConstructorOptions {
14
+ errCode?: string;
15
+ errMsg: string;
16
+ }
17
+ export declare function isSDKError(error: any): error is CloudSDKError;
18
+ export interface IGenericError<T extends string, P = any> extends Error {
19
+ type: T;
20
+ payload: P;
21
+ generic: boolean;
22
+ }
23
+ export declare const isGenericError: <T extends string, P>(e: any) => e is IGenericError<T, P>;
24
+ export declare class TimeoutError extends Error implements IGenericError<'timeout', null> {
25
+ type: "timeout";
26
+ payload: any;
27
+ generic: boolean;
28
+ constructor(message: string);
29
+ }
30
+ export declare const isTimeoutError: (e: any) => e is TimeoutError;
31
+ export declare class CancelledError extends Error implements IGenericError<'cancelled', null> {
32
+ type: "cancelled";
33
+ payload: any;
34
+ generic: boolean;
35
+ constructor(message: string);
36
+ }
37
+ export declare const isCancelledError: (e: any) => e is CancelledError;
38
+ export {};
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.isCancelledError = exports.CancelledError = exports.isTimeoutError = exports.TimeoutError = exports.isGenericError = exports.isSDKError = exports.CloudSDKError = void 0;
19
+ var type_1 = require("./type");
20
+ var error_config_1 = require("../config/error.config");
21
+ var CloudSDKError = (function (_super) {
22
+ __extends(CloudSDKError, _super);
23
+ function CloudSDKError(options) {
24
+ var _this = _super.call(this, options.errMsg) || this;
25
+ _this.errCode = 'UNKNOWN_ERROR';
26
+ Object.defineProperties(_this, {
27
+ message: {
28
+ get: function () {
29
+ return ("errCode: ".concat(this.errCode, " ").concat(error_config_1.ERR_CODE[this.errCode] ||
30
+ '', " | errMsg: ") + this.errMsg);
31
+ },
32
+ set: function (msg) {
33
+ this.errMsg = msg;
34
+ }
35
+ }
36
+ });
37
+ _this.errCode = options.errCode || 'UNKNOWN_ERROR';
38
+ _this.errMsg = options.errMsg;
39
+ return _this;
40
+ }
41
+ Object.defineProperty(CloudSDKError.prototype, "message", {
42
+ get: function () {
43
+ return "errCode: ".concat(this.errCode, " | errMsg: ") + this.errMsg;
44
+ },
45
+ set: function (msg) {
46
+ this.errMsg = msg;
47
+ },
48
+ enumerable: false,
49
+ configurable: true
50
+ });
51
+ return CloudSDKError;
52
+ }(Error));
53
+ exports.CloudSDKError = CloudSDKError;
54
+ function isSDKError(error) {
55
+ return (error && error instanceof Error && (0, type_1.isString)(error.errMsg));
56
+ }
57
+ exports.isSDKError = isSDKError;
58
+ var isGenericError = function (e) { return e.generic; };
59
+ exports.isGenericError = isGenericError;
60
+ var TimeoutError = (function (_super) {
61
+ __extends(TimeoutError, _super);
62
+ function TimeoutError(message) {
63
+ var _this = _super.call(this, message) || this;
64
+ _this.type = 'timeout';
65
+ _this.payload = null;
66
+ _this.generic = true;
67
+ return _this;
68
+ }
69
+ return TimeoutError;
70
+ }(Error));
71
+ exports.TimeoutError = TimeoutError;
72
+ var isTimeoutError = function (e) {
73
+ return e.type === 'timeout';
74
+ };
75
+ exports.isTimeoutError = isTimeoutError;
76
+ var CancelledError = (function (_super) {
77
+ __extends(CancelledError, _super);
78
+ function CancelledError(message) {
79
+ var _this = _super.call(this, message) || this;
80
+ _this.type = 'cancelled';
81
+ _this.payload = null;
82
+ _this.generic = true;
83
+ return _this;
84
+ }
85
+ return CancelledError;
86
+ }(Error));
87
+ exports.CancelledError = CancelledError;
88
+ var isCancelledError = function (e) {
89
+ return e.type === 'cancelled';
90
+ };
91
+ exports.isCancelledError = isCancelledError;
File without changes
File without changes
@@ -0,0 +1,8 @@
1
+ declare class HiddenSymbol {
2
+ constructor(target: any);
3
+ }
4
+ export declare class InternalSymbol extends HiddenSymbol {
5
+ constructor(target: any, __mark__: any);
6
+ static for(target: any): InternalSymbol;
7
+ }
8
+ export default InternalSymbol;
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.InternalSymbol = void 0;
19
+ var _symbols = [];
20
+ var __internalMark__ = {};
21
+ var HiddenSymbol = (function () {
22
+ function HiddenSymbol(target) {
23
+ Object.defineProperties(this, {
24
+ target: {
25
+ enumerable: false,
26
+ writable: false,
27
+ configurable: false,
28
+ value: target,
29
+ },
30
+ });
31
+ }
32
+ return HiddenSymbol;
33
+ }());
34
+ var InternalSymbol = (function (_super) {
35
+ __extends(InternalSymbol, _super);
36
+ function InternalSymbol(target, __mark__) {
37
+ if (__mark__ !== __internalMark__) {
38
+ throw new TypeError('InternalSymbol cannot be constructed with new operator');
39
+ }
40
+ return _super.call(this, target) || this;
41
+ }
42
+ InternalSymbol.for = function (target) {
43
+ for (var i = 0, len = _symbols.length; i < len; i++) {
44
+ if (_symbols[i].target === target) {
45
+ return _symbols[i].instance;
46
+ }
47
+ }
48
+ var symbol = new InternalSymbol(target, __internalMark__);
49
+ _symbols.push({
50
+ target: target,
51
+ instance: symbol,
52
+ });
53
+ return symbol;
54
+ };
55
+ return InternalSymbol;
56
+ }(HiddenSymbol));
57
+ exports.InternalSymbol = InternalSymbol;
58
+ exports.default = InternalSymbol;
@@ -0,0 +1,13 @@
1
+ export declare const getType: (x: any) => string;
2
+ export declare const isObject: <T extends object>(x: any) => x is T;
3
+ export declare const isString: (x: any) => x is string;
4
+ export declare const isNumber: (x: any) => x is number;
5
+ export declare const isPromise: <T extends Promise<any> = Promise<any>>(x: any) => x is T;
6
+ type AnyFn = (...args: any[]) => any;
7
+ export declare const isFunction: <T extends AnyFn = AnyFn>(x: any) => x is T;
8
+ export declare const isArray: <T extends any[] = any[]>(x: any) => x is T;
9
+ export declare const isDate: (x: any) => x is Date;
10
+ export declare const isRegExp: (x: any) => x is RegExp;
11
+ export declare const isInternalObject: (x: any) => boolean;
12
+ export declare const isPlainObject: (obj: any) => obj is object;
13
+ export {};
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isPlainObject = exports.isInternalObject = exports.isRegExp = exports.isDate = exports.isArray = exports.isFunction = exports.isPromise = exports.isNumber = exports.isString = exports.isObject = exports.getType = void 0;
4
+ var symbol_1 = require("./symbol");
5
+ var getType = function (x) { return Object.prototype.toString.call(x).slice(8, -1).toLowerCase(); };
6
+ exports.getType = getType;
7
+ var isObject = function (x) { return (0, exports.getType)(x) === 'object'; };
8
+ exports.isObject = isObject;
9
+ var isString = function (x) { return (0, exports.getType)(x) === 'string'; };
10
+ exports.isString = isString;
11
+ var isNumber = function (x) { return (0, exports.getType)(x) === 'number'; };
12
+ exports.isNumber = isNumber;
13
+ var isPromise = function (x) { return (0, exports.getType)(x) === 'promise'; };
14
+ exports.isPromise = isPromise;
15
+ var isFunction = function (x) { return typeof x === 'function'; };
16
+ exports.isFunction = isFunction;
17
+ var isArray = function (x) { return Array.isArray(x); };
18
+ exports.isArray = isArray;
19
+ var isDate = function (x) { return (0, exports.getType)(x) === 'date'; };
20
+ exports.isDate = isDate;
21
+ var isRegExp = function (x) { return (0, exports.getType)(x) === 'regexp'; };
22
+ exports.isRegExp = isRegExp;
23
+ var isInternalObject = function (x) { return x && (x._internalType instanceof symbol_1.InternalSymbol); };
24
+ exports.isInternalObject = isInternalObject;
25
+ var isPlainObject = function (obj) {
26
+ if (typeof obj !== 'object' || obj === null)
27
+ return false;
28
+ var proto = obj;
29
+ while (Object.getPrototypeOf(proto) !== null) {
30
+ proto = Object.getPrototypeOf(proto);
31
+ }
32
+ return Object.getPrototypeOf(obj) === proto;
33
+ };
34
+ exports.isPlainObject = isPlainObject;
@@ -0,0 +1,4 @@
1
+ import { Db } from '../';
2
+ export declare const sleep: (ms?: number) => Promise<unknown>;
3
+ export declare const autoCount: (domain?: string) => number;
4
+ export declare function getWsInstance(db: Db): any;
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getWsInstance = exports.autoCount = exports.sleep = void 0;
4
+ var __1 = require("../");
5
+ var sleep = function (ms) {
6
+ if (ms === void 0) { ms = 0; }
7
+ return new Promise(function (r) { return setTimeout(r, ms); });
8
+ };
9
+ exports.sleep = sleep;
10
+ var counters = {};
11
+ var autoCount = function (domain) {
12
+ if (domain === void 0) { domain = 'any'; }
13
+ if (!counters[domain]) {
14
+ counters[domain] = 0;
15
+ }
16
+ return counters[domain]++;
17
+ };
18
+ exports.autoCount = autoCount;
19
+ var wsList = {};
20
+ function getWsInstance(db) {
21
+ if (!__1.Db.wsClientClass) {
22
+ throw new Error('to use realtime you must import realtime module first');
23
+ }
24
+ var env = db.config.env;
25
+ if (!wsList[env]) {
26
+ wsList[env] = new __1.Db.wsClientClass({
27
+ context: {
28
+ appConfig: {
29
+ docSizeLimit: 1000,
30
+ realtimePingInterval: 10000,
31
+ realtimePongWaitTimeout: 5000,
32
+ request: __1.Db.createRequest(db.config)
33
+ }
34
+ }
35
+ });
36
+ }
37
+ return wsList[env];
38
+ }
39
+ exports.getWsInstance = getWsInstance;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Validate = void 0;
4
+ var constant_1 = require("./constant");
5
+ var util_1 = require("./util");
6
+ var Validate = (function () {
7
+ function Validate() {
8
+ }
9
+ Validate.isGeopoint = function (point, degree) {
10
+ if (util_1.Util.whichType(degree) !== constant_1.FieldType.Number) {
11
+ throw new Error('Geo Point must be number type');
12
+ }
13
+ var degreeAbs = Math.abs(degree);
14
+ if (point === 'latitude' && degreeAbs > 90) {
15
+ throw new Error('latitude should be a number ranges from -90 to 90');
16
+ }
17
+ else if (point === 'longitude' && degreeAbs > 180) {
18
+ throw new Error('longitude should be a number ranges from -180 to 180');
19
+ }
20
+ return true;
21
+ };
22
+ Validate.isInteger = function (param, num) {
23
+ if (!Number.isInteger(num)) {
24
+ throw new Error(param + constant_1.ErrorCode.IntergerError);
25
+ }
26
+ return true;
27
+ };
28
+ Validate.isFieldOrder = function (direction) {
29
+ if (constant_1.OrderDirectionList.indexOf(direction) === -1) {
30
+ throw new Error(constant_1.ErrorCode.DirectionError);
31
+ }
32
+ return true;
33
+ };
34
+ Validate.isFieldPath = function (path) {
35
+ if (!/^[a-zA-Z0-9-_\.]/.test(path)) {
36
+ throw new Error();
37
+ }
38
+ return true;
39
+ };
40
+ Validate.isOperator = function (op) {
41
+ if (constant_1.WhereFilterOpList.indexOf(op) === -1) {
42
+ throw new Error(constant_1.ErrorCode.OpStrError);
43
+ }
44
+ return true;
45
+ };
46
+ Validate.isCollName = function (name) {
47
+ if (!/^[a-zA-Z0-9]([a-zA-Z0-9-_]){1,32}$/.test(name)) {
48
+ throw new Error(constant_1.ErrorCode.CollNameError);
49
+ }
50
+ return true;
51
+ };
52
+ Validate.isDocID = function (docId) {
53
+ if (!/^([a-fA-F0-9]){24}$/.test(docId)) {
54
+ throw new Error(constant_1.ErrorCode.DocIDError);
55
+ }
56
+ return true;
57
+ };
58
+ return Validate;
59
+ }());
60
+ exports.Validate = Validate;
@@ -0,0 +1,29 @@
1
+ export default class Aggregation {
2
+ _db: any;
3
+ _request: any;
4
+ _stages: any[];
5
+ _collectionName: string;
6
+ constructor(db?: any, collectionName?: any);
7
+ end(): Promise<any>;
8
+ unwrap(): any[];
9
+ done(): {
10
+ [x: number]: any;
11
+ }[];
12
+ _pipe(stage: any, param: any): this;
13
+ addFields(param: any): this;
14
+ bucket(param: any): this;
15
+ bucketAuto(param: any): this;
16
+ count(param: any): this;
17
+ geoNear(param: any): this;
18
+ group(param: any): this;
19
+ limit(param: any): this;
20
+ match(param: any): this;
21
+ project(param: any): this;
22
+ lookup(param: any): this;
23
+ replaceRoot(param: any): this;
24
+ sample(param: any): this;
25
+ skip(param: any): this;
26
+ sort(param: any): this;
27
+ sortByCount(param: any): this;
28
+ unwind(param: any): this;
29
+ }
@@ -0,0 +1,154 @@
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 { EJSON } from 'bson';
39
+ import { QuerySerializer } from './serializer/query';
40
+ import { Point } from './geo';
41
+ var Aggregation = (function () {
42
+ function Aggregation(db, collectionName) {
43
+ this._stages = [];
44
+ if (db && collectionName) {
45
+ this._db = db;
46
+ this._request = Db.createRequest(this._db.config);
47
+ this._collectionName = collectionName;
48
+ }
49
+ }
50
+ Aggregation.prototype.end = function () {
51
+ return __awaiter(this, void 0, void 0, function () {
52
+ var result;
53
+ return __generator(this, function (_a) {
54
+ switch (_a.label) {
55
+ case 0:
56
+ if (!this._collectionName || !this._db) {
57
+ throw new Error('Aggregation pipeline cannot send request');
58
+ }
59
+ return [4, this._request.send('database.aggregate', {
60
+ collectionName: this._collectionName,
61
+ stages: this._stages
62
+ })];
63
+ case 1:
64
+ result = _a.sent();
65
+ if (result && result.data && result.data.list) {
66
+ return [2, {
67
+ requestId: result.requestId,
68
+ data: JSON.parse(result.data.list).map(EJSON.parse)
69
+ }];
70
+ }
71
+ return [2, result];
72
+ }
73
+ });
74
+ });
75
+ };
76
+ Aggregation.prototype.unwrap = function () {
77
+ return this._stages;
78
+ };
79
+ Aggregation.prototype.done = function () {
80
+ return this._stages.map(function (_a) {
81
+ var _b;
82
+ var stageKey = _a.stageKey, stageValue = _a.stageValue;
83
+ return _b = {},
84
+ _b[stageKey] = JSON.parse(stageValue),
85
+ _b;
86
+ });
87
+ };
88
+ Aggregation.prototype._pipe = function (stage, param) {
89
+ this._stages.push({
90
+ stageKey: "$".concat(stage),
91
+ stageValue: JSON.stringify(param)
92
+ });
93
+ return this;
94
+ };
95
+ Aggregation.prototype.addFields = function (param) {
96
+ return this._pipe('addFields', param);
97
+ };
98
+ Aggregation.prototype.bucket = function (param) {
99
+ return this._pipe('bucket', param);
100
+ };
101
+ Aggregation.prototype.bucketAuto = function (param) {
102
+ return this._pipe('bucketAuto', param);
103
+ };
104
+ Aggregation.prototype.count = function (param) {
105
+ return this._pipe('count', param);
106
+ };
107
+ Aggregation.prototype.geoNear = function (param) {
108
+ if (param.query) {
109
+ param.query = QuerySerializer.encode(param.query);
110
+ }
111
+ if (param.distanceMultiplier && typeof (param.distanceMultiplier) === 'number') {
112
+ param.distanceMultiplier = param.distanceMultiplier;
113
+ }
114
+ if (param.near) {
115
+ param.near = new Point(param.near.longitude, param.near.latitude).toJSON();
116
+ }
117
+ return this._pipe('geoNear', param);
118
+ };
119
+ Aggregation.prototype.group = function (param) {
120
+ return this._pipe('group', param);
121
+ };
122
+ Aggregation.prototype.limit = function (param) {
123
+ return this._pipe('limit', param);
124
+ };
125
+ Aggregation.prototype.match = function (param) {
126
+ return this._pipe('match', QuerySerializer.encode(param));
127
+ };
128
+ Aggregation.prototype.project = function (param) {
129
+ return this._pipe('project', param);
130
+ };
131
+ Aggregation.prototype.lookup = function (param) {
132
+ return this._pipe('lookup', param);
133
+ };
134
+ Aggregation.prototype.replaceRoot = function (param) {
135
+ return this._pipe('replaceRoot', param);
136
+ };
137
+ Aggregation.prototype.sample = function (param) {
138
+ return this._pipe('sample', param);
139
+ };
140
+ Aggregation.prototype.skip = function (param) {
141
+ return this._pipe('skip', param);
142
+ };
143
+ Aggregation.prototype.sort = function (param) {
144
+ return this._pipe('sort', param);
145
+ };
146
+ Aggregation.prototype.sortByCount = function (param) {
147
+ return this._pipe('sortByCount', param);
148
+ };
149
+ Aggregation.prototype.unwind = function (param) {
150
+ return this._pipe('unwind', param);
151
+ };
152
+ return Aggregation;
153
+ }());
154
+ export default Aggregation;
@@ -0,0 +1,9 @@
1
+ import { DocumentReference } from './document';
2
+ import { Query } from './query';
3
+ import Aggregation from './aggregate';
4
+ export declare class CollectionReference extends Query {
5
+ get name(): string;
6
+ doc(docID?: string | number): DocumentReference;
7
+ add(data: Object | Object[], callback?: any): Promise<any>;
8
+ aggregate(): Aggregation;
9
+ }
@@ -0,0 +1,46 @@
1
+ var __extends = (this && this.__extends) || (function () {
2
+ var extendStatics = function (d, b) {
3
+ extendStatics = Object.setPrototypeOf ||
4
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
6
+ return extendStatics(d, b);
7
+ };
8
+ return function (d, b) {
9
+ if (typeof b !== "function" && b !== null)
10
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
11
+ extendStatics(d, b);
12
+ function __() { this.constructor = d; }
13
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
14
+ };
15
+ })();
16
+ import { DocumentReference } from './document';
17
+ import { Query } from './query';
18
+ import Aggregation from './aggregate';
19
+ var CollectionReference = (function (_super) {
20
+ __extends(CollectionReference, _super);
21
+ function CollectionReference(db, coll) {
22
+ return _super.call(this, db, coll) || this;
23
+ }
24
+ Object.defineProperty(CollectionReference.prototype, "name", {
25
+ get: function () {
26
+ return this._coll;
27
+ },
28
+ enumerable: false,
29
+ configurable: true
30
+ });
31
+ CollectionReference.prototype.doc = function (docID) {
32
+ if (typeof docID !== 'string' && typeof docID !== 'number') {
33
+ throw new Error('docId必须为字符串或数字');
34
+ }
35
+ return new DocumentReference(this._db, this._coll, docID);
36
+ };
37
+ CollectionReference.prototype.add = function (data, callback) {
38
+ var docRef = new DocumentReference(this._db, this._coll, undefined);
39
+ return docRef.create(data, callback);
40
+ };
41
+ CollectionReference.prototype.aggregate = function () {
42
+ return new Aggregation(this._db, this._coll);
43
+ };
44
+ return CollectionReference;
45
+ }(Query));
46
+ export { CollectionReference };