@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,257 @@
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 { Db } from './index';
14
+ import { Util } from './util';
15
+ import { UpdateSerializer } from './serializer/update';
16
+ import { serialize } from './serializer/datatype';
17
+ import { UpdateCommand } from './commands/update';
18
+ import { QueryType } from './constant';
19
+ import { getWsInstance } from './utils/utils';
20
+ var DocumentReference = (function () {
21
+ function DocumentReference(db, coll, docID, projection) {
22
+ if (projection === void 0) { projection = {}; }
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({
27
+ _id: _this.id
28
+ }) }));
29
+ };
30
+ this._db = db;
31
+ this._coll = coll;
32
+ this.id = docID;
33
+ this.request = Db.createRequest(this._db.config);
34
+ this.projection = projection;
35
+ }
36
+ DocumentReference.prototype.create = function (data, callback) {
37
+ callback = callback || createPromiseCallback();
38
+ var isBatch = Array.isArray(data);
39
+ var params = {
40
+ collectionName: this._coll,
41
+ data: isBatch ? data.map(function (item) { return serialize(item); }) : serialize(data)
42
+ };
43
+ if (!isBatch && this.id) {
44
+ params['_id'] = this.id;
45
+ }
46
+ this.request
47
+ .send('database.addDocument', params)
48
+ .then(function (res) {
49
+ var _a;
50
+ if (res.code) {
51
+ callback(0, res);
52
+ }
53
+ else {
54
+ if (isBatch) {
55
+ callback(0, {
56
+ ids: ((_a = res.data) === null || _a === void 0 ? void 0 : _a.insertedIds) || [],
57
+ requestId: res.requestId
58
+ });
59
+ }
60
+ else {
61
+ callback(0, {
62
+ id: res.data._id,
63
+ requestId: res.requestId
64
+ });
65
+ }
66
+ }
67
+ })
68
+ .catch(function (err) {
69
+ callback(err);
70
+ });
71
+ return callback.promise;
72
+ };
73
+ DocumentReference.prototype.set = function (data, callback) {
74
+ callback = callback || createPromiseCallback();
75
+ if (!this.id) {
76
+ return Promise.resolve({
77
+ code: 'INVALID_PARAM',
78
+ message: 'docId不能为空'
79
+ });
80
+ }
81
+ if (!data || typeof data !== 'object') {
82
+ return Promise.resolve({
83
+ code: 'INVALID_PARAM',
84
+ message: '参数必需是非空对象'
85
+ });
86
+ }
87
+ if (data.hasOwnProperty('_id')) {
88
+ return Promise.resolve({
89
+ code: 'INVALID_PARAM',
90
+ message: '不能更新_id的值'
91
+ });
92
+ }
93
+ var hasOperator = false;
94
+ var checkMixed = function (objs) {
95
+ if (typeof objs === 'object') {
96
+ for (var key in objs) {
97
+ if (objs[key] instanceof UpdateCommand) {
98
+ hasOperator = true;
99
+ }
100
+ else if (typeof objs[key] === 'object') {
101
+ checkMixed(objs[key]);
102
+ }
103
+ }
104
+ }
105
+ };
106
+ checkMixed(data);
107
+ if (hasOperator) {
108
+ return Promise.resolve({
109
+ code: 'DATABASE_REQUEST_FAILED',
110
+ message: 'update operator complicit'
111
+ });
112
+ }
113
+ var merge = false;
114
+ var param = {
115
+ collectionName: this._coll,
116
+ queryType: QueryType.DOC,
117
+ data: serialize(data),
118
+ multi: false,
119
+ merge: merge,
120
+ upsert: true
121
+ };
122
+ if (this.id) {
123
+ param['query'] = { _id: this.id };
124
+ }
125
+ this.request
126
+ .send('database.updateDocument', param)
127
+ .then(function (res) {
128
+ if (res.code) {
129
+ callback(0, res);
130
+ }
131
+ else {
132
+ callback(0, {
133
+ updated: res.data.updated,
134
+ upsertedId: res.data.upserted_id,
135
+ requestId: res.requestId
136
+ });
137
+ }
138
+ })
139
+ .catch(function (err) {
140
+ callback(err);
141
+ });
142
+ return callback.promise;
143
+ };
144
+ DocumentReference.prototype.update = function (data, callback) {
145
+ callback = callback || createPromiseCallback();
146
+ if (!data || typeof data !== 'object') {
147
+ return Promise.resolve({
148
+ code: 'INVALID_PARAM',
149
+ message: '参数必需是非空对象'
150
+ });
151
+ }
152
+ if (data.hasOwnProperty('_id')) {
153
+ return Promise.resolve({
154
+ code: 'INVALID_PARAM',
155
+ message: '不能更新_id的值'
156
+ });
157
+ }
158
+ var query = { _id: this.id };
159
+ var merge = true;
160
+ var param = {
161
+ collectionName: this._coll,
162
+ data: UpdateSerializer.encode(data),
163
+ query: query,
164
+ queryType: QueryType.DOC,
165
+ multi: false,
166
+ merge: merge,
167
+ upsert: false
168
+ };
169
+ this.request
170
+ .send('database.updateDocument', param)
171
+ .then(function (res) {
172
+ if (res.code) {
173
+ callback(0, res);
174
+ }
175
+ else {
176
+ callback(0, {
177
+ updated: res.data.updated,
178
+ upsertedId: res.data.upserted_id,
179
+ requestId: res.requestId
180
+ });
181
+ }
182
+ })
183
+ .catch(function (err) {
184
+ callback(err);
185
+ });
186
+ return callback.promise;
187
+ };
188
+ DocumentReference.prototype.remove = function (callback) {
189
+ callback = callback || createPromiseCallback();
190
+ var query = { _id: this.id };
191
+ var param = {
192
+ collectionName: this._coll,
193
+ query: query,
194
+ queryType: QueryType.DOC,
195
+ multi: false
196
+ };
197
+ this.request
198
+ .send('database.deleteDocument', param)
199
+ .then(function (res) {
200
+ if (res.code) {
201
+ callback(0, res);
202
+ }
203
+ else {
204
+ callback(0, {
205
+ deleted: res.data.deleted,
206
+ requestId: res.requestId
207
+ });
208
+ }
209
+ })
210
+ .catch(function (err) {
211
+ callback(err);
212
+ });
213
+ return callback.promise;
214
+ };
215
+ DocumentReference.prototype.get = function (callback) {
216
+ callback = callback || createPromiseCallback();
217
+ var query = { _id: this.id };
218
+ var param = {
219
+ collectionName: this._coll,
220
+ query: query,
221
+ queryType: QueryType.DOC,
222
+ multi: false,
223
+ projection: this.projection
224
+ };
225
+ this.request
226
+ .send('database.queryDocument', param)
227
+ .then(function (res) {
228
+ if (res.code) {
229
+ callback(0, res);
230
+ }
231
+ else {
232
+ var documents = Util.formatResDocumentData(res.data.list);
233
+ callback(0, {
234
+ data: documents,
235
+ requestId: res.requestId
236
+ });
237
+ }
238
+ })
239
+ .catch(function (err) {
240
+ callback(err);
241
+ });
242
+ return callback.promise;
243
+ };
244
+ DocumentReference.prototype.field = function (projection) {
245
+ for (var k in projection) {
246
+ if (projection[k]) {
247
+ projection[k] = 1;
248
+ }
249
+ else {
250
+ projection[k] = 0;
251
+ }
252
+ }
253
+ return new DocumentReference(this._db, this._coll, this.id, projection);
254
+ };
255
+ return DocumentReference;
256
+ }());
257
+ export { DocumentReference };
@@ -0,0 +1,6 @@
1
+ export * from './point';
2
+ export * from './lineString';
3
+ export * from './polygon';
4
+ export * from './multiPoint';
5
+ export * from './multiLineString';
6
+ export * from './multiPolygon';
@@ -0,0 +1,6 @@
1
+ export * from './point';
2
+ export * from './lineString';
3
+ export * from './polygon';
4
+ export * from './multiPoint';
5
+ export * from './multiLineString';
6
+ export * from './multiPolygon';
@@ -0,0 +1,24 @@
1
+ export interface ISerializedPoint {
2
+ type: string;
3
+ coordinates: [number, number];
4
+ }
5
+ export interface ISerializedLineString {
6
+ type: string;
7
+ coordinates: [number, number][];
8
+ }
9
+ export interface ISerializedPolygon {
10
+ type: string;
11
+ coordinates: [number, number][][];
12
+ }
13
+ export interface ISerializedMultiPoint {
14
+ type: string;
15
+ coordinates: [number, number][];
16
+ }
17
+ export interface ISerializedMultiLineString {
18
+ type: string;
19
+ coordinates: [number, number][][];
20
+ }
21
+ export interface ISerializedMultiPolygon {
22
+ type: string;
23
+ coordinates: [number, number][][][];
24
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,19 @@
1
+ import { Point } from './point';
2
+ import { ISerializedLineString } from './interface';
3
+ export declare class LineString {
4
+ readonly points: Point[];
5
+ constructor(points: Point[]);
6
+ parse(key: any): {
7
+ [x: number]: {
8
+ type: string;
9
+ coordinates: number[][];
10
+ };
11
+ };
12
+ toJSON(): {
13
+ type: string;
14
+ coordinates: number[][];
15
+ };
16
+ static validate(lineString: ISerializedLineString): boolean;
17
+ static isClosed(lineString: LineString): boolean;
18
+ get _internalType(): import("../utils/symbol").InternalSymbol;
19
+ }
@@ -0,0 +1,83 @@
1
+ var __values = (this && this.__values) || function(o) {
2
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
3
+ if (m) return m.call(o);
4
+ if (o && typeof o.length === "number") return {
5
+ next: function () {
6
+ if (o && i >= o.length) o = void 0;
7
+ return { value: o && o[i++], done: !o };
8
+ }
9
+ };
10
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
11
+ };
12
+ import { SYMBOL_GEO_LINE_STRING } from '../helper/symbol';
13
+ import { Point } from './point';
14
+ import { isArray, isNumber } from '../utils/type';
15
+ var LineString = (function () {
16
+ function LineString(points) {
17
+ if (!isArray(points)) {
18
+ throw new TypeError("\"points\" must be of type Point[]. Received type ".concat(typeof points));
19
+ }
20
+ if (points.length < 2) {
21
+ throw new Error('"points" must contain 2 points at least');
22
+ }
23
+ points.forEach(function (point) {
24
+ if (!(point instanceof Point)) {
25
+ throw new TypeError("\"points\" must be of type Point[]. Received type ".concat(typeof point, "[]"));
26
+ }
27
+ });
28
+ this.points = points;
29
+ }
30
+ LineString.prototype.parse = function (key) {
31
+ var _a;
32
+ return _a = {},
33
+ _a[key] = {
34
+ type: 'LineString',
35
+ coordinates: this.points.map(function (point) { return point.toJSON().coordinates; })
36
+ },
37
+ _a;
38
+ };
39
+ LineString.prototype.toJSON = function () {
40
+ return {
41
+ type: 'LineString',
42
+ coordinates: this.points.map(function (point) { return point.toJSON().coordinates; })
43
+ };
44
+ };
45
+ LineString.validate = function (lineString) {
46
+ var e_1, _a;
47
+ if (lineString.type !== 'LineString' || !isArray(lineString.coordinates)) {
48
+ return false;
49
+ }
50
+ try {
51
+ for (var _b = __values(lineString.coordinates), _c = _b.next(); !_c.done; _c = _b.next()) {
52
+ var point = _c.value;
53
+ if (!isNumber(point[0]) || !isNumber(point[1])) {
54
+ return false;
55
+ }
56
+ }
57
+ }
58
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
59
+ finally {
60
+ try {
61
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
62
+ }
63
+ finally { if (e_1) throw e_1.error; }
64
+ }
65
+ return true;
66
+ };
67
+ LineString.isClosed = function (lineString) {
68
+ var firstPoint = lineString.points[0];
69
+ var lastPoint = lineString.points[lineString.points.length - 1];
70
+ if (firstPoint.latitude === lastPoint.latitude && firstPoint.longitude === lastPoint.longitude) {
71
+ return true;
72
+ }
73
+ };
74
+ Object.defineProperty(LineString.prototype, "_internalType", {
75
+ get: function () {
76
+ return SYMBOL_GEO_LINE_STRING;
77
+ },
78
+ enumerable: false,
79
+ configurable: true
80
+ });
81
+ return LineString;
82
+ }());
83
+ export { LineString };
@@ -0,0 +1,18 @@
1
+ import { LineString } from './lineString';
2
+ import { ISerializedMultiLineString } from './interface';
3
+ export declare class MultiLineString {
4
+ readonly lines: LineString[];
5
+ constructor(lines: LineString[]);
6
+ parse(key: any): {
7
+ [x: number]: {
8
+ type: string;
9
+ coordinates: number[][][];
10
+ };
11
+ };
12
+ toJSON(): {
13
+ type: string;
14
+ coordinates: number[][][];
15
+ };
16
+ static validate(multiLineString: ISerializedMultiLineString): boolean;
17
+ get _internalType(): import("../utils/symbol").InternalSymbol;
18
+ }
@@ -0,0 +1,92 @@
1
+ var __values = (this && this.__values) || function(o) {
2
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
3
+ if (m) return m.call(o);
4
+ if (o && typeof o.length === "number") return {
5
+ next: function () {
6
+ if (o && i >= o.length) o = void 0;
7
+ return { value: o && o[i++], done: !o };
8
+ }
9
+ };
10
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
11
+ };
12
+ import { SYMBOL_GEO_MULTI_LINE_STRING } from '../helper/symbol';
13
+ import { isArray, isNumber } from '../utils/type';
14
+ import { LineString } from './lineString';
15
+ var MultiLineString = (function () {
16
+ function MultiLineString(lines) {
17
+ if (!isArray(lines)) {
18
+ throw new TypeError("\"lines\" must be of type LineString[]. Received type ".concat(typeof lines));
19
+ }
20
+ if (lines.length === 0) {
21
+ throw new Error('Polygon must contain 1 linestring at least');
22
+ }
23
+ lines.forEach(function (line) {
24
+ if (!(line instanceof LineString)) {
25
+ throw new TypeError("\"lines\" must be of type LineString[]. Received type ".concat(typeof line, "[]"));
26
+ }
27
+ });
28
+ this.lines = lines;
29
+ }
30
+ MultiLineString.prototype.parse = function (key) {
31
+ var _a;
32
+ return _a = {},
33
+ _a[key] = {
34
+ type: 'MultiLineString',
35
+ coordinates: this.lines.map(function (line) {
36
+ return line.points.map(function (point) { return [point.longitude, point.latitude]; });
37
+ })
38
+ },
39
+ _a;
40
+ };
41
+ MultiLineString.prototype.toJSON = function () {
42
+ return {
43
+ type: 'MultiLineString',
44
+ coordinates: this.lines.map(function (line) {
45
+ return line.points.map(function (point) { return [point.longitude, point.latitude]; });
46
+ })
47
+ };
48
+ };
49
+ MultiLineString.validate = function (multiLineString) {
50
+ var e_1, _a, e_2, _b;
51
+ if (multiLineString.type !== 'MultiLineString' || !isArray(multiLineString.coordinates)) {
52
+ return false;
53
+ }
54
+ try {
55
+ for (var _c = __values(multiLineString.coordinates), _d = _c.next(); !_d.done; _d = _c.next()) {
56
+ var line = _d.value;
57
+ try {
58
+ for (var line_1 = (e_2 = void 0, __values(line)), line_1_1 = line_1.next(); !line_1_1.done; line_1_1 = line_1.next()) {
59
+ var point = line_1_1.value;
60
+ if (!isNumber(point[0]) || !isNumber(point[1])) {
61
+ return false;
62
+ }
63
+ }
64
+ }
65
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
66
+ finally {
67
+ try {
68
+ if (line_1_1 && !line_1_1.done && (_b = line_1.return)) _b.call(line_1);
69
+ }
70
+ finally { if (e_2) throw e_2.error; }
71
+ }
72
+ }
73
+ }
74
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
75
+ finally {
76
+ try {
77
+ if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
78
+ }
79
+ finally { if (e_1) throw e_1.error; }
80
+ }
81
+ return true;
82
+ };
83
+ Object.defineProperty(MultiLineString.prototype, "_internalType", {
84
+ get: function () {
85
+ return SYMBOL_GEO_MULTI_LINE_STRING;
86
+ },
87
+ enumerable: false,
88
+ configurable: true
89
+ });
90
+ return MultiLineString;
91
+ }());
92
+ export { MultiLineString };
@@ -0,0 +1,18 @@
1
+ import { Point } from './point';
2
+ import { ISerializedMultiPoint } from './interface';
3
+ export declare class MultiPoint {
4
+ readonly points: Point[];
5
+ constructor(points: Point[]);
6
+ parse(key: any): {
7
+ [x: number]: {
8
+ type: string;
9
+ coordinates: number[][];
10
+ };
11
+ };
12
+ toJSON(): {
13
+ type: string;
14
+ coordinates: number[][];
15
+ };
16
+ static validate(multiPoint: ISerializedMultiPoint): boolean;
17
+ get _internalType(): import("../utils/symbol").InternalSymbol;
18
+ }
@@ -0,0 +1,76 @@
1
+ var __values = (this && this.__values) || function(o) {
2
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
3
+ if (m) return m.call(o);
4
+ if (o && typeof o.length === "number") return {
5
+ next: function () {
6
+ if (o && i >= o.length) o = void 0;
7
+ return { value: o && o[i++], done: !o };
8
+ }
9
+ };
10
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
11
+ };
12
+ import { SYMBOL_GEO_MULTI_POINT } from '../helper/symbol';
13
+ import { Point } from './point';
14
+ import { isArray, isNumber } from '../utils/type';
15
+ var MultiPoint = (function () {
16
+ function MultiPoint(points) {
17
+ if (!isArray(points)) {
18
+ throw new TypeError("\"points\" must be of type Point[]. Received type ".concat(typeof points));
19
+ }
20
+ if (points.length === 0) {
21
+ throw new Error('"points" must contain 1 point at least');
22
+ }
23
+ points.forEach(function (point) {
24
+ if (!(point instanceof Point)) {
25
+ throw new TypeError("\"points\" must be of type Point[]. Received type ".concat(typeof point, "[]"));
26
+ }
27
+ });
28
+ this.points = points;
29
+ }
30
+ MultiPoint.prototype.parse = function (key) {
31
+ var _a;
32
+ return _a = {},
33
+ _a[key] = {
34
+ type: 'MultiPoint',
35
+ coordinates: this.points.map(function (point) { return point.toJSON().coordinates; })
36
+ },
37
+ _a;
38
+ };
39
+ MultiPoint.prototype.toJSON = function () {
40
+ return {
41
+ type: 'MultiPoint',
42
+ coordinates: this.points.map(function (point) { return point.toJSON().coordinates; })
43
+ };
44
+ };
45
+ MultiPoint.validate = function (multiPoint) {
46
+ var e_1, _a;
47
+ if (multiPoint.type !== 'MultiPoint' || !isArray(multiPoint.coordinates)) {
48
+ return false;
49
+ }
50
+ try {
51
+ for (var _b = __values(multiPoint.coordinates), _c = _b.next(); !_c.done; _c = _b.next()) {
52
+ var point = _c.value;
53
+ if (!isNumber(point[0]) || !isNumber(point[1])) {
54
+ return false;
55
+ }
56
+ }
57
+ }
58
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
59
+ finally {
60
+ try {
61
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
62
+ }
63
+ finally { if (e_1) throw e_1.error; }
64
+ }
65
+ return true;
66
+ };
67
+ Object.defineProperty(MultiPoint.prototype, "_internalType", {
68
+ get: function () {
69
+ return SYMBOL_GEO_MULTI_POINT;
70
+ },
71
+ enumerable: false,
72
+ configurable: true
73
+ });
74
+ return MultiPoint;
75
+ }());
76
+ export { MultiPoint };
@@ -0,0 +1,18 @@
1
+ import { Polygon } from './polygon';
2
+ import { ISerializedMultiPolygon } from './interface';
3
+ export declare class MultiPolygon {
4
+ readonly polygons: Polygon[];
5
+ constructor(polygons: Polygon[]);
6
+ parse(key: any): {
7
+ [x: number]: {
8
+ type: string;
9
+ coordinates: number[][][][];
10
+ };
11
+ };
12
+ toJSON(): {
13
+ type: string;
14
+ coordinates: number[][][][];
15
+ };
16
+ static validate(multiPolygon: ISerializedMultiPolygon): boolean;
17
+ get _internalType(): import("../utils/symbol").InternalSymbol;
18
+ }