@cloudbase/js-sdk 3.6.8 → 3.6.9-beta.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 (208) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/app/dist/index.esm.js +1 -1
  3. package/app/dist/index.esm.js.map +1 -1
  4. package/app/dist/index.js +1 -1
  5. package/app/dist/index.js.map +1 -1
  6. package/app/dist/index.node.esm.js +1 -1
  7. package/app/dist/index.node.esm.js.map +1 -1
  8. package/app/dist/index.node.js +1 -1
  9. package/app/dist/index.node.js.map +1 -1
  10. package/auth/dist/index.esm.js +1 -1
  11. package/auth/dist/index.esm.js.map +1 -1
  12. package/auth/dist/index.js +1 -1
  13. package/auth/dist/index.js.map +1 -1
  14. package/database/dist/index.d.ts +3 -0
  15. package/database/dist/index.esm.js +2 -0
  16. package/database/dist/index.esm.js.map +1 -0
  17. package/database/dist/index.js +2 -0
  18. package/database/dist/index.js.map +1 -0
  19. package/dist/index.cjs.js +1 -1
  20. package/dist/index.cjs.js.map +1 -1
  21. package/dist/index.esm.js +1 -1
  22. package/dist/index.esm.js.map +1 -1
  23. package/dist/index.node.cjs.js +1 -1
  24. package/dist/index.node.cjs.js.map +1 -1
  25. package/dist/index.node.esm.js +1 -1
  26. package/dist/index.node.esm.js.map +1 -1
  27. package/miniprogram_dist/auth/index.js +1 -1
  28. package/miniprogram_dist/index.js +1 -1
  29. package/miniprogram_dist/oauth/index.js +1 -1
  30. package/oauth/dist/index.esm.js +1 -1
  31. package/oauth/dist/index.esm.js.map +1 -1
  32. package/oauth/dist/index.js +1 -1
  33. package/oauth/dist/index.js.map +1 -1
  34. package/package.json +2 -2
  35. package/types/package.json +1 -1
  36. package/utilities/package.json +2 -2
  37. package/database/dist/commonjs/aggregate.d.ts +0 -29
  38. package/database/dist/commonjs/aggregate.js +0 -156
  39. package/database/dist/commonjs/collection.d.ts +0 -9
  40. package/database/dist/commonjs/collection.js +0 -49
  41. package/database/dist/commonjs/command.d.ts +0 -175
  42. package/database/dist/commonjs/command.js +0 -299
  43. package/database/dist/commonjs/commands/logic.d.ts +0 -24
  44. package/database/dist/commonjs/commands/logic.js +0 -89
  45. package/database/dist/commonjs/commands/query.d.ts +0 -68
  46. package/database/dist/commonjs/commands/query.js +0 -160
  47. package/database/dist/commonjs/commands/update.d.ts +0 -29
  48. package/database/dist/commonjs/commands/update.js +0 -51
  49. package/database/dist/commonjs/config/app.config.d.ts +0 -6
  50. package/database/dist/commonjs/config/app.config.js +0 -7
  51. package/database/dist/commonjs/config/error.config.d.ts +0 -3
  52. package/database/dist/commonjs/config/error.config.js +0 -16
  53. package/database/dist/commonjs/const/code.d.ts +0 -30
  54. package/database/dist/commonjs/const/code.js +0 -33
  55. package/database/dist/commonjs/constant.d.ts +0 -51
  56. package/database/dist/commonjs/constant.js +0 -75
  57. package/database/dist/commonjs/document.d.ts +0 -11
  58. package/database/dist/commonjs/document.js +0 -260
  59. package/database/dist/commonjs/geo/index.d.ts +0 -6
  60. package/database/dist/commonjs/geo/index.js +0 -22
  61. package/database/dist/commonjs/geo/interface.d.ts +0 -24
  62. package/database/dist/commonjs/geo/interface.js +0 -2
  63. package/database/dist/commonjs/geo/lineString.d.ts +0 -19
  64. package/database/dist/commonjs/geo/lineString.js +0 -86
  65. package/database/dist/commonjs/geo/multiLineString.d.ts +0 -18
  66. package/database/dist/commonjs/geo/multiLineString.js +0 -95
  67. package/database/dist/commonjs/geo/multiPoint.d.ts +0 -18
  68. package/database/dist/commonjs/geo/multiPoint.js +0 -79
  69. package/database/dist/commonjs/geo/multiPolygon.d.ts +0 -18
  70. package/database/dist/commonjs/geo/multiPolygon.js +0 -122
  71. package/database/dist/commonjs/geo/point.d.ts +0 -19
  72. package/database/dist/commonjs/geo/point.js +0 -50
  73. package/database/dist/commonjs/geo/polygon.d.ts +0 -19
  74. package/database/dist/commonjs/geo/polygon.js +0 -109
  75. package/database/dist/commonjs/helper/symbol.d.ts +0 -14
  76. package/database/dist/commonjs/helper/symbol.js +0 -31
  77. package/database/dist/commonjs/index.d.ts +0 -40
  78. package/database/dist/commonjs/index.js +0 -61
  79. package/database/dist/commonjs/lib/util.d.ts +0 -1
  80. package/database/dist/commonjs/lib/util.js +0 -26
  81. package/database/dist/commonjs/operator-map.d.ts +0 -4
  82. package/database/dist/commonjs/operator-map.js +0 -24
  83. package/database/dist/commonjs/query.d.ts +0 -22
  84. package/database/dist/commonjs/query.js +0 -252
  85. package/database/dist/commonjs/regexp/index.d.ts +0 -14
  86. package/database/dist/commonjs/regexp/index.js +0 -33
  87. package/database/dist/commonjs/serializer/common.d.ts +0 -11
  88. package/database/dist/commonjs/serializer/common.js +0 -127
  89. package/database/dist/commonjs/serializer/datatype.d.ts +0 -7
  90. package/database/dist/commonjs/serializer/datatype.js +0 -132
  91. package/database/dist/commonjs/serializer/query.d.ts +0 -7
  92. package/database/dist/commonjs/serializer/query.js +0 -232
  93. package/database/dist/commonjs/serializer/update.d.ts +0 -15
  94. package/database/dist/commonjs/serializer/update.js +0 -142
  95. package/database/dist/commonjs/serverDate/index.d.ts +0 -13
  96. package/database/dist/commonjs/serverDate/index.js +0 -30
  97. package/database/dist/commonjs/transaction/collection.d.ts +0 -7
  98. package/database/dist/commonjs/transaction/collection.js +0 -49
  99. package/database/dist/commonjs/transaction/document.d.ts +0 -27
  100. package/database/dist/commonjs/transaction/document.js +0 -205
  101. package/database/dist/commonjs/transaction/index.d.ts +0 -30
  102. package/database/dist/commonjs/transaction/index.js +0 -215
  103. package/database/dist/commonjs/transaction/query.d.ts +0 -43
  104. package/database/dist/commonjs/transaction/query.js +0 -261
  105. package/database/dist/commonjs/typings/index.d.ts +0 -40
  106. package/database/dist/commonjs/typings/index.js +0 -2
  107. package/database/dist/commonjs/typings/realtime.d.ts +0 -219
  108. package/database/dist/commonjs/typings/realtime.js +0 -2
  109. package/database/dist/commonjs/util.d.ts +0 -9
  110. package/database/dist/commonjs/util.js +0 -145
  111. package/database/dist/commonjs/utils/error.d.ts +0 -38
  112. package/database/dist/commonjs/utils/error.js +0 -91
  113. package/database/dist/commonjs/utils/msg.d.ts +0 -0
  114. package/database/dist/commonjs/utils/msg.js +0 -0
  115. package/database/dist/commonjs/utils/symbol.d.ts +0 -8
  116. package/database/dist/commonjs/utils/symbol.js +0 -58
  117. package/database/dist/commonjs/utils/type.d.ts +0 -13
  118. package/database/dist/commonjs/utils/type.js +0 -34
  119. package/database/dist/commonjs/utils/utils.d.ts +0 -4
  120. package/database/dist/commonjs/utils/utils.js +0 -39
  121. package/database/dist/commonjs/validate.d.ts +0 -1
  122. package/database/dist/commonjs/validate.js +0 -60
  123. package/database/dist/esm/aggregate.d.ts +0 -29
  124. package/database/dist/esm/aggregate.js +0 -154
  125. package/database/dist/esm/collection.d.ts +0 -9
  126. package/database/dist/esm/collection.js +0 -46
  127. package/database/dist/esm/command.d.ts +0 -175
  128. package/database/dist/esm/command.js +0 -296
  129. package/database/dist/esm/commands/logic.d.ts +0 -24
  130. package/database/dist/esm/commands/logic.js +0 -84
  131. package/database/dist/esm/commands/query.d.ts +0 -68
  132. package/database/dist/esm/commands/query.js +0 -154
  133. package/database/dist/esm/commands/update.d.ts +0 -29
  134. package/database/dist/esm/commands/update.js +0 -46
  135. package/database/dist/esm/config/app.config.d.ts +0 -6
  136. package/database/dist/esm/config/app.config.js +0 -5
  137. package/database/dist/esm/config/error.config.d.ts +0 -3
  138. package/database/dist/esm/config/error.config.js +0 -13
  139. package/database/dist/esm/const/code.d.ts +0 -30
  140. package/database/dist/esm/const/code.js +0 -30
  141. package/database/dist/esm/constant.d.ts +0 -51
  142. package/database/dist/esm/constant.js +0 -65
  143. package/database/dist/esm/document.d.ts +0 -11
  144. package/database/dist/esm/document.js +0 -257
  145. package/database/dist/esm/geo/index.d.ts +0 -6
  146. package/database/dist/esm/geo/index.js +0 -6
  147. package/database/dist/esm/geo/interface.d.ts +0 -24
  148. package/database/dist/esm/geo/interface.js +0 -1
  149. package/database/dist/esm/geo/lineString.d.ts +0 -19
  150. package/database/dist/esm/geo/lineString.js +0 -83
  151. package/database/dist/esm/geo/multiLineString.d.ts +0 -18
  152. package/database/dist/esm/geo/multiLineString.js +0 -92
  153. package/database/dist/esm/geo/multiPoint.d.ts +0 -18
  154. package/database/dist/esm/geo/multiPoint.js +0 -76
  155. package/database/dist/esm/geo/multiPolygon.d.ts +0 -18
  156. package/database/dist/esm/geo/multiPolygon.js +0 -119
  157. package/database/dist/esm/geo/point.d.ts +0 -19
  158. package/database/dist/esm/geo/point.js +0 -47
  159. package/database/dist/esm/geo/polygon.d.ts +0 -19
  160. package/database/dist/esm/geo/polygon.js +0 -106
  161. package/database/dist/esm/helper/symbol.d.ts +0 -14
  162. package/database/dist/esm/helper/symbol.js +0 -14
  163. package/database/dist/esm/index.d.ts +0 -40
  164. package/database/dist/esm/index.js +0 -55
  165. package/database/dist/esm/lib/util.d.ts +0 -1
  166. package/database/dist/esm/lib/util.js +0 -22
  167. package/database/dist/esm/operator-map.d.ts +0 -4
  168. package/database/dist/esm/operator-map.js +0 -20
  169. package/database/dist/esm/query.d.ts +0 -22
  170. package/database/dist/esm/query.js +0 -249
  171. package/database/dist/esm/regexp/index.d.ts +0 -14
  172. package/database/dist/esm/regexp/index.js +0 -29
  173. package/database/dist/esm/serializer/common.d.ts +0 -11
  174. package/database/dist/esm/serializer/common.js +0 -118
  175. package/database/dist/esm/serializer/datatype.d.ts +0 -7
  176. package/database/dist/esm/serializer/datatype.js +0 -127
  177. package/database/dist/esm/serializer/query.d.ts +0 -7
  178. package/database/dist/esm/serializer/query.js +0 -229
  179. package/database/dist/esm/serializer/update.d.ts +0 -15
  180. package/database/dist/esm/serializer/update.js +0 -139
  181. package/database/dist/esm/serverDate/index.d.ts +0 -13
  182. package/database/dist/esm/serverDate/index.js +0 -26
  183. package/database/dist/esm/transaction/collection.d.ts +0 -7
  184. package/database/dist/esm/transaction/collection.js +0 -46
  185. package/database/dist/esm/transaction/document.d.ts +0 -27
  186. package/database/dist/esm/transaction/document.js +0 -202
  187. package/database/dist/esm/transaction/index.d.ts +0 -30
  188. package/database/dist/esm/transaction/index.js +0 -210
  189. package/database/dist/esm/transaction/query.d.ts +0 -43
  190. package/database/dist/esm/transaction/query.js +0 -258
  191. package/database/dist/esm/typings/index.d.ts +0 -40
  192. package/database/dist/esm/typings/index.js +0 -1
  193. package/database/dist/esm/typings/realtime.d.ts +0 -219
  194. package/database/dist/esm/typings/realtime.js +0 -1
  195. package/database/dist/esm/util.d.ts +0 -9
  196. package/database/dist/esm/util.js +0 -142
  197. package/database/dist/esm/utils/error.d.ts +0 -38
  198. package/database/dist/esm/utils/error.js +0 -84
  199. package/database/dist/esm/utils/msg.d.ts +0 -0
  200. package/database/dist/esm/utils/msg.js +0 -0
  201. package/database/dist/esm/utils/symbol.d.ts +0 -8
  202. package/database/dist/esm/utils/symbol.js +0 -55
  203. package/database/dist/esm/utils/type.d.ts +0 -13
  204. package/database/dist/esm/utils/type.js +0 -20
  205. package/database/dist/esm/utils/utils.d.ts +0 -4
  206. package/database/dist/esm/utils/utils.js +0 -33
  207. package/database/dist/esm/validate.d.ts +0 -1
  208. package/database/dist/esm/validate.js +0 -57
@@ -0,0 +1,3 @@
1
+ import { ICloudbase } from '@cloudbase/types';
2
+ import cloudbaseNS from '../../index';
3
+ export declare function registerDatabase(app: ICloudbase | typeof cloudbaseNS): void;
@@ -0,0 +1,2 @@
1
+ import*as t from"bson";var e={d:(t,n)=>{for(var r in n)e.o(n,r)&&!e.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:n[r]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},n={};e.d(n,{I:()=>Se});var r,o,i={};e.r(i),e.d(i,{LineString:()=>W,MultiLineString:()=>Y,MultiPoint:()=>B,MultiPolygon:()=>X,Point:()=>ot,Polygon:()=>H}),function(t){t.DocIDError="文档ID不合法",t.CollNameError="集合名称不合法",t.OpStrError="操作符不合法",t.DirectionError="排序字符不合法",t.IntergerError="must be integer",t.QueryParamTypeError="查询参数必须为对象",t.QueryParamValueError="查询参数对象值不能均为undefined"}(o||(o={}));var a,u,c="Object",s="GeoPoint",l="GeoLineString",f="GeoPolygon",d="GeoMultiPoint",p="GeoMultiLineString",h="GeoMultiPolygon",y="Date",m="ServerDate",v=["desc","asc"],w=["<","<=","==",">=",">"];!function(t){t.lt="<",t.gt=">",t.lte="<=",t.gte=">=",t.eq="=="}(a||(a={})),(r={})[a.eq]="$eq",r[a.lt]="$lt",r[a.lte]="$lte",r[a.gt]="$gt",r[a.gte]="$gte",function(t){t.WHERE="WHERE",t.DOC="DOC"}(u||(u={}));var b,g=(b=function(t,e){return b=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},b(t,e)},function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function n(){this.constructor=t}b(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}),_=[],O={},E=function(t){function e(e,n){if(n!==O)throw new TypeError("InternalSymbol cannot be constructed with new operator");return t.call(this,e)||this}return g(e,t),e.for=function(t){for(var n=0,r=_.length;n<r;n++)if(_[n].target===t)return _[n].instance;var o=new e(t,O);return _.push({target:t,instance:o}),o},e}(function(t){Object.defineProperties(this,{target:{enumerable:!1,writable:!1,configurable:!1,value:t}})});const N=E;var S=N.for("UNSET_FIELD_NAME"),I=N.for("UPDATE_COMMAND"),T=N.for("QUERY_COMMAND"),P=N.for("LOGIC_COMMAND"),q=N.for("GEO_POINT"),A=N.for("SYMBOL_GEO_LINE_STRING"),x=N.for("SYMBOL_GEO_POLYGON"),j=N.for("SYMBOL_GEO_MULTI_POINT"),D=N.for("SYMBOL_GEO_MULTI_LINE_STRING"),C=N.for("SYMBOL_GEO_MULTI_POLYGON"),R=N.for("SERVER_DATE"),L=N.for("REGEXP"),M=function(t){return Object.prototype.toString.call(t).slice(8,-1).toLowerCase()},$=function(t){return"object"===M(t)},F=function(t){return"number"===M(t)},k=function(t){return Array.isArray(t)},J=function(t){return"date"===M(t)},U=function(t){return"regexp"===M(t)},G=function(t){return t&&t._internalType instanceof E},W=function(){function t(t){if(!k(t))throw new TypeError('"points" must be of type Point[]. Received type '.concat(typeof t));if(t.length<2)throw new Error('"points" must contain 2 points at least');t.forEach(function(t){if(!(t instanceof ot))throw new TypeError('"points" must be of type Point[]. Received type '.concat(typeof t,"[]"))}),this.points=t}return t.prototype.parse=function(t){var e;return(e={})[t]={type:"LineString",coordinates:this.points.map(function(t){return t.toJSON().coordinates})},e},t.prototype.toJSON=function(){return{type:"LineString",coordinates:this.points.map(function(t){return t.toJSON().coordinates})}},t.validate=function(t){var e,n;if("LineString"!==t.type||!k(t.coordinates))return!1;try{for(var r=function(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],r=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}(t.coordinates),o=r.next();!o.done;o=r.next()){var i=o.value;if(!F(i[0])||!F(i[1]))return!1}}catch(t){e={error:t}}finally{try{o&&!o.done&&(n=r.return)&&n.call(r)}finally{if(e)throw e.error}}return!0},t.isClosed=function(t){var e=t.points[0],n=t.points[t.points.length-1];if(e.latitude===n.latitude&&e.longitude===n.longitude)return!0},Object.defineProperty(t.prototype,"_internalType",{get:function(){return A},enumerable:!1,configurable:!0}),t}(),Q=function(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],r=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")},H=function(){function t(t){if(!k(t))throw new TypeError('"lines" must be of type LineString[]. Received type '.concat(typeof t));if(0===t.length)throw new Error("Polygon must contain 1 linestring at least");t.forEach(function(t){if(!(t instanceof W))throw new TypeError('"lines" must be of type LineString[]. Received type '.concat(typeof t,"[]"));if(!W.isClosed(t))throw new Error("LineString ".concat(t.points.map(function(t){return t.toReadableString()})," is not a closed cycle"))}),this.lines=t}return t.prototype.parse=function(t){var e;return(e={})[t]={type:"Polygon",coordinates:this.lines.map(function(t){return t.points.map(function(t){return[t.longitude,t.latitude]})})},e},t.prototype.toJSON=function(){return{type:"Polygon",coordinates:this.lines.map(function(t){return t.points.map(function(t){return[t.longitude,t.latitude]})})}},t.validate=function(t){var e,n,r,o;if("Polygon"!==t.type||!k(t.coordinates))return!1;try{for(var i=Q(t.coordinates),a=i.next();!a.done;a=i.next()){var u=a.value;if(!this.isCloseLineString(u))return!1;try{for(var c=(r=void 0,Q(u)),s=c.next();!s.done;s=c.next()){var l=s.value;if(!F(l[0])||!F(l[1]))return!1}}catch(t){r={error:t}}finally{try{s&&!s.done&&(o=c.return)&&o.call(c)}finally{if(r)throw r.error}}}}catch(t){e={error:t}}finally{try{a&&!a.done&&(n=i.return)&&n.call(i)}finally{if(e)throw e.error}}return!0},t.isCloseLineString=function(t){var e=t[0],n=t[t.length-1];return e[0]===n[0]&&e[1]===n[1]},Object.defineProperty(t.prototype,"_internalType",{get:function(){return C},enumerable:!1,configurable:!0}),t}(),B=function(){function t(t){if(!k(t))throw new TypeError('"points" must be of type Point[]. Received type '.concat(typeof t));if(0===t.length)throw new Error('"points" must contain 1 point at least');t.forEach(function(t){if(!(t instanceof ot))throw new TypeError('"points" must be of type Point[]. Received type '.concat(typeof t,"[]"))}),this.points=t}return t.prototype.parse=function(t){var e;return(e={})[t]={type:"MultiPoint",coordinates:this.points.map(function(t){return t.toJSON().coordinates})},e},t.prototype.toJSON=function(){return{type:"MultiPoint",coordinates:this.points.map(function(t){return t.toJSON().coordinates})}},t.validate=function(t){var e,n;if("MultiPoint"!==t.type||!k(t.coordinates))return!1;try{for(var r=function(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],r=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}(t.coordinates),o=r.next();!o.done;o=r.next()){var i=o.value;if(!F(i[0])||!F(i[1]))return!1}}catch(t){e={error:t}}finally{try{o&&!o.done&&(n=r.return)&&n.call(r)}finally{if(e)throw e.error}}return!0},Object.defineProperty(t.prototype,"_internalType",{get:function(){return j},enumerable:!1,configurable:!0}),t}(),V=function(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],r=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")},Y=function(){function t(t){if(!k(t))throw new TypeError('"lines" must be of type LineString[]. Received type '.concat(typeof t));if(0===t.length)throw new Error("Polygon must contain 1 linestring at least");t.forEach(function(t){if(!(t instanceof W))throw new TypeError('"lines" must be of type LineString[]. Received type '.concat(typeof t,"[]"))}),this.lines=t}return t.prototype.parse=function(t){var e;return(e={})[t]={type:"MultiLineString",coordinates:this.lines.map(function(t){return t.points.map(function(t){return[t.longitude,t.latitude]})})},e},t.prototype.toJSON=function(){return{type:"MultiLineString",coordinates:this.lines.map(function(t){return t.points.map(function(t){return[t.longitude,t.latitude]})})}},t.validate=function(t){var e,n,r,o;if("MultiLineString"!==t.type||!k(t.coordinates))return!1;try{for(var i=V(t.coordinates),a=i.next();!a.done;a=i.next()){var u=a.value;try{for(var c=(r=void 0,V(u)),s=c.next();!s.done;s=c.next()){var l=s.value;if(!F(l[0])||!F(l[1]))return!1}}catch(t){r={error:t}}finally{try{s&&!s.done&&(o=c.return)&&o.call(c)}finally{if(r)throw r.error}}}}catch(t){e={error:t}}finally{try{a&&!a.done&&(n=i.return)&&n.call(i)}finally{if(e)throw e.error}}return!0},Object.defineProperty(t.prototype,"_internalType",{get:function(){return D},enumerable:!1,configurable:!0}),t}(),z=function(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],r=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")},X=function(){function t(t){var e,n;if(!k(t))throw new TypeError('"polygons" must be of type Polygon[]. Received type '.concat(typeof t));if(0===t.length)throw new Error("MultiPolygon must contain 1 polygon at least");try{for(var r=z(t),o=r.next();!o.done;o=r.next()){var i=o.value;if(!(i instanceof H))throw new TypeError('"polygon" must be of type Polygon[]. Received type '.concat(typeof i,"[]"))}}catch(t){e={error:t}}finally{try{o&&!o.done&&(n=r.return)&&n.call(r)}finally{if(e)throw e.error}}this.polygons=t}return t.prototype.parse=function(t){var e;return(e={})[t]={type:"MultiPolygon",coordinates:this.polygons.map(function(t){return t.lines.map(function(t){return t.points.map(function(t){return[t.longitude,t.latitude]})})})},e},t.prototype.toJSON=function(){return{type:"MultiPolygon",coordinates:this.polygons.map(function(t){return t.lines.map(function(t){return t.points.map(function(t){return[t.longitude,t.latitude]})})})}},t.validate=function(t){var e,n,r,o,i,a;if("MultiPolygon"!==t.type||!k(t.coordinates))return!1;try{for(var u=z(t.coordinates),c=u.next();!c.done;c=u.next()){var s=c.value;try{for(var l=(r=void 0,z(s)),f=l.next();!f.done;f=l.next()){var d=f.value;try{for(var p=(i=void 0,z(d)),h=p.next();!h.done;h=p.next()){var y=h.value;if(!F(y[0])||!F(y[1]))return!1}}catch(t){i={error:t}}finally{try{h&&!h.done&&(a=p.return)&&a.call(p)}finally{if(i)throw i.error}}}}catch(t){r={error:t}}finally{try{f&&!f.done&&(o=l.return)&&o.call(l)}finally{if(r)throw r.error}}}}catch(t){e={error:t}}finally{try{c&&!c.done&&(n=u.return)&&n.call(u)}finally{if(e)throw e.error}}return!0},Object.defineProperty(t.prototype,"_internalType",{get:function(){return x},enumerable:!1,configurable:!0}),t}(),Z=function(){function t(t){var e=(void 0===t?{}:t).offset,n=void 0===e?0:e;this.offset=n}return Object.defineProperty(t.prototype,"_internalType",{get:function(){return R},enumerable:!1,configurable:!0}),t.prototype.parse=function(){return{$date:{offset:this.offset}}},t}();function K(t){return new Z(t)}var tt,et=function(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,o,i=n.call(t),a=[];try{for(;(void 0===e||e-- >0)&&!(r=i.next()).done;)a.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return a},nt=function(){function t(){}return t.formatResDocumentData=function(e){return e.map(function(e){return t.formatField(e)})},t.formatField=function(e){var n=Object.keys(e),r={};return Array.isArray(e)&&(r=[]),n.forEach(function(n){var o,i=e[n];switch(t.whichType(i)){case s:o=new ot(i.coordinates[0],i.coordinates[1]);break;case l:o=new W(i.coordinates.map(function(t){return new ot(t[0],t[1])}));break;case f:o=new H(i.coordinates.map(function(t){return new W(t.map(function(t){var e=et(t,2),n=e[0],r=e[1];return new ot(n,r)}))}));break;case d:o=new B(i.coordinates.map(function(t){return new ot(t[0],t[1])}));break;case p:o=new Y(i.coordinates.map(function(t){return new W(t.map(function(t){var e=et(t,2),n=e[0],r=e[1];return new ot(n,r)}))}));break;case h:o=new X(i.coordinates.map(function(t){return new H(t.map(function(t){return new W(t.map(function(t){var e=et(t,2),n=e[0],r=e[1];return new ot(n,r)}))}))}));break;case y:o=new Date(1e3*i.$timestamp);break;case c:case"Array":o=t.formatField(i);break;case m:o=new Date(i.$date);break;default:o=i}Array.isArray(r)?r.push(o):r[n]=o}),r},t.whichType=function(t){var e=Object.prototype.toString.call(t).slice(8,-1);if(e===y)return"BsonDate";if(e===c){if(t instanceof ot)return s;if(t instanceof Date)return y;if(t instanceof Z)return m;t.$timestamp?e=y:t.$date?e=m:ot.validate(t)?e=s:W.validate(t)?e=l:H.validate(t)?e=f:B.validate(t)?e=d:Y.validate(t)?e=p:X.validate(t)&&(e=h)}return e},t.generateDocId=function(){for(var t="",e=0;e<24;e++)t+="ABCDEFabcdef0123456789".charAt(Math.floor(22*Math.random()));return t},t}(),rt=function(){function t(){}return t.isGeopoint=function(t,e){if("Number"!==nt.whichType(e))throw new Error("Geo Point must be number type");var n=Math.abs(e);if("latitude"===t&&n>90)throw new Error("latitude should be a number ranges from -90 to 90");if("longitude"===t&&n>180)throw new Error("longitude should be a number ranges from -180 to 180");return!0},t.isInteger=function(t,e){if(!Number.isInteger(e))throw new Error(t+o.IntergerError);return!0},t.isFieldOrder=function(t){if(-1===v.indexOf(t))throw new Error(o.DirectionError);return!0},t.isFieldPath=function(t){if(!/^[a-zA-Z0-9-_\.]/.test(t))throw new Error;return!0},t.isOperator=function(t){if(-1===w.indexOf(t))throw new Error(o.OpStrError);return!0},t.isCollName=function(t){if(!/^[a-zA-Z0-9]([a-zA-Z0-9-_]){1,32}$/.test(t))throw new Error(o.CollNameError);return!0},t.isDocID=function(t){if(!/^([a-fA-F0-9]){24}$/.test(t))throw new Error(o.DocIDError);return!0},t}(),ot=function(){function t(t,e){rt.isGeopoint("longitude",t),rt.isGeopoint("latitude",e),this.longitude=t,this.latitude=e}return t.prototype.parse=function(t){var e;return(e={})[t]={type:"Point",coordinates:[this.longitude,this.latitude]},e},t.prototype.toJSON=function(){return{type:"Point",coordinates:[this.longitude,this.latitude]}},t.prototype.toReadableString=function(){return"[".concat(this.longitude,",").concat(this.latitude,"]")},t.validate=function(t){return"Point"===t.type&&k(t.coordinates)&&rt.isGeopoint("longitude",t.coordinates[0])&&rt.isGeopoint("latitude",t.coordinates[1])},Object.defineProperty(t.prototype,"_internalType",{get:function(){return q},enumerable:!1,configurable:!0}),t}(),it=function(){var t=function(){};if(!Promise){t.promise={};var e=function(){throw new Error('Your Node runtime does support ES6 Promises. Set "global.Promise" to your preferred implementation of promises.')};return Object.defineProperty(t.promise,"then",{get:e}),Object.defineProperty(t.promise,"catch",{get:e}),t}var n=new Promise(function(e,n){t=function(t,r){return t?n(t):e(r)}});return t.promise=n,t};!function(t){t.SET="set",t.REMOVE="remove",t.INC="inc",t.MUL="mul",t.PUSH="push",t.PULL="pull",t.PULL_ALL="pullAll",t.POP="pop",t.SHIFT="shift",t.UNSHIFT="unshift",t.ADD_TO_SET="addToSet",t.BIT="bit",t.RENAME="rename",t.MAX="max",t.MIN="min"}(tt||(tt={}));var at,ut=function(){function t(t,e,n){this._internalType=I,Object.defineProperties(this,{_internalType:{enumerable:!1,configurable:!1}}),this.operator=t,this.operands=e,this.fieldName=n||S}return t.prototype._setFieldName=function(e){return new t(this.operator,this.operands,e)},t}();function ct(t){return t&&t instanceof ut&&t._internalType===I}!function(t){t.AND="and",t.OR="or",t.NOT="not",t.NOR="nor"}(at||(at={}));var st=function(){function t(t,e,n){if(this._internalType=P,Object.defineProperties(this,{_internalType:{enumerable:!1,configurable:!1}}),this.operator=t,this.operands=e,this.fieldName=n||S,this.fieldName!==S)if(Array.isArray(e)){e=e.slice(),this.operands=e;for(var r=0,o=e.length;r<o;r++)(lt(i=e[r])||ht(i))&&(e[r]=i._setFieldName(this.fieldName))}else{var i;(lt(i=e)||ht(i))&&(e=i._setFieldName(this.fieldName))}}return t.prototype._setFieldName=function(e){var n=this.operands.map(function(n){return n instanceof t?n._setFieldName(e):n});return new t(this.operator,n,e)},t.prototype.and=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];var r=Array.isArray(arguments[0])?arguments[0]:Array.from(arguments);return r.unshift(this),new t(at.AND,r,this.fieldName)},t.prototype.or=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];var r=Array.isArray(arguments[0])?arguments[0]:Array.from(arguments);return r.unshift(this),new t(at.OR,r,this.fieldName)},t}();function lt(t){return t&&t instanceof st&&t._internalType===P}var ft,dt=function(){var t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},t(e,n)};return function(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}();!function(t){t.EQ="eq",t.NEQ="neq",t.GT="gt",t.GTE="gte",t.LT="lt",t.LTE="lte",t.IN="in",t.NIN="nin",t.ALL="all",t.ELEM_MATCH="elemMatch",t.EXISTS="exists",t.SIZE="size",t.MOD="mod",t.GEO_NEAR="geoNear",t.GEO_WITHIN="geoWithin",t.GEO_INTERSECTS="geoIntersects"}(ft||(ft={}));var pt=function(t){function e(e,n,r){var o=t.call(this,e,n,r)||this;return o.operator=e,o._internalType=T,o}return dt(e,t),e.prototype.toJSON=function(){var t,e;switch(this.operator){case ft.IN:case ft.NIN:return(t={})["$"+this.operator]=this.operands,t;default:return(e={})["$"+this.operator]=this.operands[0],e}},e.prototype._setFieldName=function(t){return new e(this.operator,this.operands,t)},e.prototype.eq=function(t){var n=new e(ft.EQ,[t],this.fieldName);return this.and(n)},e.prototype.neq=function(t){var n=new e(ft.NEQ,[t],this.fieldName);return this.and(n)},e.prototype.gt=function(t){var n=new e(ft.GT,[t],this.fieldName);return this.and(n)},e.prototype.gte=function(t){var n=new e(ft.GTE,[t],this.fieldName);return this.and(n)},e.prototype.lt=function(t){var n=new e(ft.LT,[t],this.fieldName);return this.and(n)},e.prototype.lte=function(t){var n=new e(ft.LTE,[t],this.fieldName);return this.and(n)},e.prototype.in=function(t){var n=new e(ft.IN,t,this.fieldName);return this.and(n)},e.prototype.nin=function(t){var n=new e(ft.NIN,t,this.fieldName);return this.and(n)},e.prototype.geoNear=function(t){if(!(t.geometry instanceof ot))throw new TypeError('"geometry" must be of type Point. Received type '.concat(typeof t.geometry));if(void 0!==t.maxDistance&&!F(t.maxDistance))throw new TypeError('"maxDistance" must be of type Number. Received type '.concat(typeof t.maxDistance));if(void 0!==t.minDistance&&!F(t.minDistance))throw new TypeError('"minDistance" must be of type Number. Received type '.concat(typeof t.minDistance));var n=new e(ft.GEO_NEAR,[t],this.fieldName);return this.and(n)},e.prototype.geoWithin=function(t){if(!(t.geometry instanceof X||t.geometry instanceof H))throw new TypeError('"geometry" must be of type Polygon or MultiPolygon. Received type '.concat(typeof t.geometry));var n=new e(ft.GEO_WITHIN,[t],this.fieldName);return this.and(n)},e.prototype.geoIntersects=function(t){if(!(t.geometry instanceof ot||t.geometry instanceof W||t.geometry instanceof H||t.geometry instanceof B||t.geometry instanceof Y||t.geometry instanceof X))throw new TypeError('"geometry" must be of type Point, LineString, Polygon, MultiPoint, MultiLineString or MultiPolygon. Received type '.concat(typeof t.geometry));var n=new e(ft.GEO_INTERSECTS,[t],this.fieldName);return this.and(n)},e}(st);function ht(t){return t&&t instanceof pt&&t._internalType===T}function yt(t){return ht(t)}var mt={};for(var vt in ft)mt[vt]="$"+vt;for(var vt in at)mt[vt]="$"+vt;for(var vt in tt)mt[vt]="$"+vt;function wt(t){return mt[t]||"$"+t}mt[ft.NEQ]="$ne",mt[tt.REMOVE]="$unset",mt[tt.SHIFT]="$pop",mt[tt.UNSHIFT]="$push";var bt=function(){return bt=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},bt.apply(this,arguments)},gt=function(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,o,i=n.call(t),a=[];try{for(;(void 0===e||e-- >0)&&!(r=i.next()).done;)a.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return a},_t=function(t,e,n){if(n||2===arguments.length)for(var r,o=0,i=e.length;o<i;o++)!r&&o in e||(r||(r=Array.prototype.slice.call(e,0,o)),r[o]=e[o]);return t.concat(r||Array.prototype.slice.call(e))};function Ot(t){return Et(t,[t])}function Et(t,e){if(!G(t)){if(J(t))return{$date:+t};if(U(t))return{$regex:t.source,$options:t.flags};if(k(t))return t.map(function(t){if(e.indexOf(t)>-1)throw new Error("Cannot convert circular structure to JSON");return Et(t,_t(_t([],gt(e),!1),[t],!1))});if($(t)){var n=bt({},t);for(var r in n){if(e.indexOf(n[r])>-1)throw new Error("Cannot convert circular structure to JSON");n[r]=Et(n[r],_t(_t([],gt(e),!1),[n[r]],!1))}return n}return t}switch(t._internalType){case q:return t.toJSON();case R:case L:return t.parse();default:return t.toJSON?t.toJSON():t}}var Nt=function(){return Nt=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},Nt.apply(this,arguments)},St=function(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,o,i=n.call(t),a=[];try{for(;(void 0===e||e-- >0)&&!(r=i.next()).done;)a.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return a},It=function(t,e,n){if(n||2===arguments.length)for(var r,o=0,i=e.length;o<i;o++)!r&&o in e||(r||(r=Array.prototype.slice.call(e,0,o)),r[o]=e[o]);return t.concat(r||Array.prototype.slice.call(e))};function Tt(t,e,n,r){var o=Nt({},t);for(var i in t)if(!/^\$/.test(i)){var a=t[i];if(a&&$(a)&&!e(a)){if(r.indexOf(a)>-1)throw new Error("Cannot convert circular structure to JSON");var u=Tt(a,e,It(It([],St(n),!1),[i],!1),It(It([],St(r),!1),[a],!1));o[i]=u;var c=!1;for(var s in u)/^\$/.test(s)?c=!0:(o["".concat(i,".").concat(s)]=u[s],delete o[i][s]);c||delete o[i]}}return o}function Pt(t){return Tt(t,At,[],[t])}function qt(t,e,n){for(var r in e[n]||delete t[n],e)t[r]?k(t[r])?t[r].push(e[r]):$(t[r])?$(e[r])?Object.assign(t[r],e[r]):(console.warn("unmergable condition, query is object but condition is ".concat(M(e),", can only overwrite"),e,n),t[r]=e[r]):(console.warn("to-merge query is of type ".concat(M(t),", can only overwrite"),t,e,n),t[r]=e[r]):t[r]=e[r]}function At(t){return G(t)||J(t)||U(t)}function xt(t){return Ot(t)}var jt=function(){function t(){}return t.encode=function(e){return(new t).encodeUpdate(e)},t.prototype.encodeUpdate=function(t){return ct(t)?this.encodeUpdateCommand(t):"object"===M(t)?this.encodeUpdateObject(t):t},t.prototype.encodeUpdateCommand=function(t){if(t.fieldName===S)throw new Error("Cannot encode a comparison command with unset field name");switch(t.operator){case tt.PUSH:case tt.PULL:case tt.PULL_ALL:case tt.POP:case tt.SHIFT:case tt.UNSHIFT:case tt.ADD_TO_SET:return this.encodeArrayUpdateCommand(t);default:return this.encodeFieldUpdateCommand(t)}},t.prototype.encodeFieldUpdateCommand=function(t){var e,n,r,o,i=wt(t.operator);return t.operator===tt.REMOVE?((e={})[i]=((n={})[t.fieldName]="",n),e):((r={})[i]=((o={})[t.fieldName]=t.operands[0],o),r)},t.prototype.encodeArrayUpdateCommand=function(t){var e,n,r,o,i,a,u,c,s,l,f=wt(t.operator);switch(t.operator){case tt.PUSH:var d=void 0;return d=k(t.operands)?{$each:t.operands.map(xt)}:t.operands,(e={})[f]=((n={})[t.fieldName]=d,n),e;case tt.UNSHIFT:return d={$each:t.operands.map(xt),$position:0},(r={})[f]=((o={})[t.fieldName]=d,o),r;case tt.POP:return(i={})[f]=((a={})[t.fieldName]=1,a),i;case tt.SHIFT:return(u={})[f]=((c={})[t.fieldName]=-1,c),u;default:return(s={})[f]=((l={})[t.fieldName]=xt(t.operands),l),s}},t.prototype.encodeUpdateObject=function(t){var e=Pt(t);for(var n in e)if(!/^\$/.test(n)){var r=e[n];if(ct(r))e[n]=r._setFieldName(n),qt(e,this.encodeUpdateCommand(e[n]),n);else{e[n]=r=xt(r);var o=new ut(tt.SET,[r],n);qt(e,this.encodeUpdateCommand(o),n)}}return e},t}(),Dt={};function Ct(t){if(!we.wsClientClass)throw new Error("to use realtime you must import realtime module first");var e=t.config.env;return Dt[e]||(Dt[e]=new we.wsClientClass({context:{appConfig:{docSizeLimit:1e3,realtimePingInterval:1e4,realtimePongWaitTimeout:5e3,request:we.createRequest(t.config)}}})),Dt[e]}var Rt=function(){return Rt=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},Rt.apply(this,arguments)},Lt=function(){function t(t,e,n,r){void 0===r&&(r={});var o=this;this.watch=function(t){return Ct(o._db).watch(Rt(Rt({},t),{envId:o._db.config.env,collectionName:o._coll,query:JSON.stringify({_id:o.id})}))},this._db=t,this._coll=e,this.id=n,this.request=we.createRequest(this._db.config),this.projection=r}return t.prototype.create=function(t,e){e=e||it();var n=Array.isArray(t),r={collectionName:this._coll,data:n?t.map(function(t){return Ot(t)}):Ot(t)};return!n&&this.id&&(r._id=this.id),this.request.send("database.addDocument",r).then(function(t){var r;t.code?e(0,t):e(0,n?{ids:(null===(r=t.data)||void 0===r?void 0:r.insertedIds)||[],requestId:t.requestId}:{id:t.data._id,requestId:t.requestId})}).catch(function(t){e(t)}),e.promise},t.prototype.set=function(t,e){if(e=e||it(),!this.id)return Promise.resolve({code:"INVALID_PARAM",message:"docId不能为空"});if(!t||"object"!=typeof t)return Promise.resolve({code:"INVALID_PARAM",message:"参数必需是非空对象"});if(t.hasOwnProperty("_id"))return Promise.resolve({code:"INVALID_PARAM",message:"不能更新_id的值"});var n=!1,r=function(t){if("object"==typeof t)for(var e in t)t[e]instanceof ut?n=!0:"object"==typeof t[e]&&r(t[e])};if(r(t),n)return Promise.resolve({code:"DATABASE_REQUEST_FAILED",message:"update operator complicit"});var o={collectionName:this._coll,queryType:u.DOC,data:Ot(t),multi:!1,merge:!1,upsert:!0};return this.id&&(o.query={_id:this.id}),this.request.send("database.updateDocument",o).then(function(t){t.code?e(0,t):e(0,{updated:t.data.updated,upsertedId:t.data.upserted_id,requestId:t.requestId})}).catch(function(t){e(t)}),e.promise},t.prototype.update=function(t,e){if(e=e||it(),!t||"object"!=typeof t)return Promise.resolve({code:"INVALID_PARAM",message:"参数必需是非空对象"});if(t.hasOwnProperty("_id"))return Promise.resolve({code:"INVALID_PARAM",message:"不能更新_id的值"});var n={_id:this.id},r={collectionName:this._coll,data:jt.encode(t),query:n,queryType:u.DOC,multi:!1,merge:!0,upsert:!1};return this.request.send("database.updateDocument",r).then(function(t){t.code?e(0,t):e(0,{updated:t.data.updated,upsertedId:t.data.upserted_id,requestId:t.requestId})}).catch(function(t){e(t)}),e.promise},t.prototype.remove=function(t){t=t||it();var e={_id:this.id},n={collectionName:this._coll,query:e,queryType:u.DOC,multi:!1};return this.request.send("database.deleteDocument",n).then(function(e){e.code?t(0,e):t(0,{deleted:e.data.deleted,requestId:e.requestId})}).catch(function(e){t(e)}),t.promise},t.prototype.get=function(t){t=t||it();var e={_id:this.id},n={collectionName:this._coll,query:e,queryType:u.DOC,multi:!1,projection:this.projection};return this.request.send("database.queryDocument",n).then(function(e){if(e.code)t(0,e);else{var n=nt.formatResDocumentData(e.data.list);t(0,{data:n,requestId:e.requestId})}}).catch(function(e){t(e)}),t.promise},t.prototype.field=function(e){for(var n in e)e[n]?e[n]=1:e[n]=0;return new t(this._db,this._coll,this.id,e)},t}(),Mt=function(){function t(){}return t.encode=function(t){return(new $t).encodeQuery(t)},t}(),$t=function(){function t(){}return t.prototype.encodeQuery=function(t,e){var n;return At(t)?lt(t)?this.encodeLogicCommand(t):ht(t)?this.encodeQueryCommand(t):((n={})[e]=this.encodeQueryObject(t),n):$(t)?this.encodeQueryObject(t):t},t.prototype.encodeRegExp=function(t){return{$regex:t.source,$options:t.flags}},t.prototype.encodeLogicCommand=function(t){var e,n,r,o,i,a,u,c=this;switch(t.operator){case at.NOR:case at.AND:case at.OR:var s=wt(t.operator),l=t.operands.map(function(e){return c.encodeQuery(e,t.fieldName)});return(e={})[s]=l,e;case at.NOT:s=wt(t.operator);var f=t.operands[0];return U(f)?((n={})[t.fieldName]=((r={})[s]=this.encodeRegExp(f),r),n):(l=this.encodeQuery(f)[t.fieldName],(o={})[t.fieldName]=((i={})[s]=l,i),o);default:if(s=wt(t.operator),1===t.operands.length){var d=this.encodeQuery(t.operands[0]);return(a={})[s]=d,a}return l=t.operands.map(this.encodeQuery.bind(this)),(u={})[s]=l,u}},t.prototype.encodeQueryCommand=function(t){return yt(t),this.encodeComparisonCommand(t)},t.prototype.encodeComparisonCommand=function(t){var e,n,r,o,i,a,u,c,s;if(t.fieldName===S)throw new Error("Cannot encode a comparison command with unset field name");var l=wt(t.operator);switch(t.operator){case ft.EQ:case ft.NEQ:case ft.LT:case ft.LTE:case ft.GT:case ft.GTE:case ft.ELEM_MATCH:case ft.EXISTS:case ft.SIZE:case ft.MOD:return(e={})[t.fieldName]=((n={})[l]=xt(t.operands[0]),n),e;case ft.IN:case ft.NIN:case ft.ALL:return(r={})[t.fieldName]=((o={})[l]=xt(t.operands),o),r;case ft.GEO_NEAR:var f=t.operands[0];return(i={})[t.fieldName]={$nearSphere:{$geometry:f.geometry.toJSON(),$maxDistance:f.maxDistance,$minDistance:f.minDistance}},i;case ft.GEO_WITHIN:return f=t.operands[0],(a={})[t.fieldName]={$geoWithin:{$geometry:f.geometry.toJSON()}},a;case ft.GEO_INTERSECTS:return f=t.operands[0],(u={})[t.fieldName]={$geoIntersects:{$geometry:f.geometry.toJSON()}},u;default:return(c={})[t.fieldName]=((s={})[l]=xt(t.operands[0]),s),c}},t.prototype.encodeQueryObject=function(t){var e=Pt(t);for(var n in e){var r=e[n];if(lt(r)){e[n]=r._setFieldName(n);var o=this.encodeLogicCommand(e[n]);this.mergeConditionAfterEncode(e,o,n)}else yt(r)?(e[n]=r._setFieldName(n),o=this.encodeComparisonCommand(e[n]),this.mergeConditionAfterEncode(e,o,n)):At(r)&&(e[n]=xt(r))}return e},t.prototype.mergeConditionAfterEncode=function(t,e,n){for(var r in e[n]||delete t[n],e)t[r]?k(t[r])?t[r]=t[r].concat(e[r]):$(t[r])?$(e[r])?Object.assign(t,e):(console.warn("unmergable condition, query is object but condition is ".concat(M(e),", can only overwrite"),e,n),t[r]=e[r]):(console.warn("to-merge query is of type ".concat(M(t),", can only overwrite"),t,e,n),t[r]=e[r]):t[r]=e[r]},t}(),Ft=function(){return Ft=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},Ft.apply(this,arguments)},kt=function(){function t(t,e,n,r,o){var i=this;this.watch=function(t){return Ct(i._db).watch(Ft(Ft({},t),{envId:i._db.config.env,collectionName:i._coll,query:JSON.stringify(i._fieldFilters||{}),limit:i._queryOptions.limit,orderBy:i._fieldOrders?i._fieldOrders.reduce(function(t,e){return t[e.field]=e.direction,t},{}):void 0}))},this._db=t,this._coll=e,this._fieldFilters=n,this._fieldOrders=r||[],this._queryOptions=o||{},this._request=we.createRequest(this._db.config)}return t.prototype.get=function(t){t=t||it();var e=[];this._fieldOrders&&this._fieldOrders.forEach(function(t){e.push(t)});var n={collectionName:this._coll,queryType:u.WHERE};return this._fieldFilters&&(n.query=this._fieldFilters),e.length>0&&(n.order=e),this._queryOptions.offset&&(n.offset=this._queryOptions.offset),this._queryOptions.limit?n.limit=this._queryOptions.limit<1e3?this._queryOptions.limit:1e3:n.limit=100,this._queryOptions.projection&&(n.projection=this._queryOptions.projection),this._request.send("database.queryDocument",n).then(function(e){if(e.code)t(0,e);else{var n={data:nt.formatResDocumentData(e.data.list),requestId:e.requestId};void 0!==e.total&&(n.total=e.total),void 0!==e.limit&&(n.limit=e.limit),void 0!==e.offset&&(n.offset=e.offset),t(0,n)}}).catch(function(e){t(e)}),t.promise},t.prototype.count=function(t){t=t||it();var e={collectionName:this._coll,queryType:u.WHERE};return this._fieldFilters&&(e.query=this._fieldFilters),this._request.send("database.countDocument",e).then(function(e){e.code?t(0,e):t(0,{requestId:e.requestId,total:e.data.total})}).catch(function(e){t(e)}),t.promise},t.prototype.where=function(e){if("Object"!==Object.prototype.toString.call(e).slice(8,-1))throw Error(o.QueryParamTypeError);var n=Object.keys(e),r=n.some(function(t){return void 0!==e[t]});if(n.length&&!r)throw Error(o.QueryParamValueError);return new t(this._db,this._coll,Mt.encode(e),this._fieldOrders,this._queryOptions)},t.prototype.orderBy=function(e,n){rt.isFieldPath(e),rt.isFieldOrder(n);var r={field:e,direction:n},o=this._fieldOrders.concat(r);return new t(this._db,this._coll,this._fieldFilters,o,this._queryOptions)},t.prototype.limit=function(e){rt.isInteger("limit",e);var n=Ft({},this._queryOptions);return n.limit=e,new t(this._db,this._coll,this._fieldFilters,this._fieldOrders,n)},t.prototype.skip=function(e){rt.isInteger("offset",e);var n=Ft({},this._queryOptions);return n.offset=e,new t(this._db,this._coll,this._fieldFilters,this._fieldOrders,n)},t.prototype.update=function(t,e){if(e=e||it(),!t||"object"!=typeof t)return Promise.resolve({code:"INVALID_PARAM",message:"参数必需是非空对象"});if(t.hasOwnProperty("_id"))return Promise.resolve({code:"INVALID_PARAM",message:"不能更新_id的值"});var n={collectionName:this._coll,query:this._fieldFilters,queryType:u.WHERE,multi:!0,merge:!0,upsert:!1,data:jt.encode(t)};return this._request.send("database.updateDocument",n).then(function(t){t.code?e(0,t):e(0,{requestId:t.requestId,updated:t.data.updated,upsertId:t.data.upsert_id})}).catch(function(t){e(t)}),e.promise},t.prototype.field=function(e){for(var n in e)e[n]?"object"!=typeof e[n]&&(e[n]=1):e[n]=0;var r=Ft({},this._queryOptions);return r.projection=e,new t(this._db,this._coll,this._fieldFilters,this._fieldOrders,r)},t.prototype.remove=function(t){t=t||it(),Object.keys(this._queryOptions).length>0&&console.warn("`offset`, `limit` and `projection` are not supported in remove() operation"),this._fieldOrders.length>0&&console.warn("`orderBy` is not supported in remove() operation");var e={collectionName:this._coll,query:Mt.encode(this._fieldFilters),queryType:u.WHERE,multi:!0};return this._request.send("database.deleteDocument",e).then(function(e){e.code?t(0,e):t(0,{requestId:e.requestId,deleted:e.data.deleted})}).catch(function(e){t(e)}),t.promise},t}();const Jt=(Ut={EJSON:()=>t.EJSON},Gt={},e.d(Gt,Ut),Gt);var Ut,Gt,Wt=function(){function t(t,e){this._stages=[],t&&e&&(this._db=t,this._request=we.createRequest(this._db.config),this._collectionName=e)}return t.prototype.end=function(){return t=this,e=void 0,r=function(){var t;return function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(u){return function(c){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,u[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,u[1])).done)return o;switch(r=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,r=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){a=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){a.label=u[1];break}if(6===u[0]&&a.label<o[1]){a.label=o[1],o=u;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(u);break}o[2]&&a.ops.pop(),a.trys.pop();continue}u=e.call(t,a)}catch(t){u=[6,t],r=0}finally{n=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,c])}}}(this,function(e){switch(e.label){case 0:if(!this._collectionName||!this._db)throw new Error("Aggregation pipeline cannot send request");return[4,this._request.send("database.aggregate",{collectionName:this._collectionName,stages:this._stages})];case 1:return(t=e.sent())&&t.data&&t.data.list?[2,{requestId:t.requestId,data:JSON.parse(t.data.list).map(Jt.EJSON.parse)}]:[2,t]}})},new((n=void 0)||(n=Promise))(function(o,i){function a(t){try{c(r.next(t))}catch(t){i(t)}}function u(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(a,u)}c((r=r.apply(t,e||[])).next())});var t,e,n,r},t.prototype.unwrap=function(){return this._stages},t.prototype.done=function(){return this._stages.map(function(t){var e,n=t.stageKey,r=t.stageValue;return(e={})[n]=JSON.parse(r),e})},t.prototype._pipe=function(t,e){return this._stages.push({stageKey:"$".concat(t),stageValue:JSON.stringify(e)}),this},t.prototype.addFields=function(t){return this._pipe("addFields",t)},t.prototype.bucket=function(t){return this._pipe("bucket",t)},t.prototype.bucketAuto=function(t){return this._pipe("bucketAuto",t)},t.prototype.count=function(t){return this._pipe("count",t)},t.prototype.geoNear=function(t){return t.query&&(t.query=Mt.encode(t.query)),t.distanceMultiplier&&"number"==typeof t.distanceMultiplier&&(t.distanceMultiplier=t.distanceMultiplier),t.near&&(t.near=new ot(t.near.longitude,t.near.latitude).toJSON()),this._pipe("geoNear",t)},t.prototype.group=function(t){return this._pipe("group",t)},t.prototype.limit=function(t){return this._pipe("limit",t)},t.prototype.match=function(t){return this._pipe("match",Mt.encode(t))},t.prototype.project=function(t){return this._pipe("project",t)},t.prototype.lookup=function(t){return this._pipe("lookup",t)},t.prototype.replaceRoot=function(t){return this._pipe("replaceRoot",t)},t.prototype.sample=function(t){return this._pipe("sample",t)},t.prototype.skip=function(t){return this._pipe("skip",t)},t.prototype.sort=function(t){return this._pipe("sort",t)},t.prototype.sortByCount=function(t){return this._pipe("sortByCount",t)},t.prototype.unwind=function(t){return this._pipe("unwind",t)},t}();const Qt=Wt;var Ht=function(){var t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},t(e,n)};return function(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),Bt=function(t){function e(e,n){return t.call(this,e,n)||this}return Ht(e,t),Object.defineProperty(e.prototype,"name",{get:function(){return this._coll},enumerable:!1,configurable:!0}),e.prototype.doc=function(t){if("string"!=typeof t&&"number"!=typeof t)throw new Error("docId必须为字符串或数字");return new Lt(this._db,this._coll,t)},e.prototype.add=function(t,e){return new Lt(this._db,this._coll,void 0).create(t,e)},e.prototype.aggregate=function(){return new Qt(this._db,this._coll)},e}(kt),Vt={eq:function(t){return new pt(ft.EQ,[t])},neq:function(t){return new pt(ft.NEQ,[t])},lt:function(t){return new pt(ft.LT,[t])},lte:function(t){return new pt(ft.LTE,[t])},gt:function(t){return new pt(ft.GT,[t])},gte:function(t){return new pt(ft.GTE,[t])},in:function(t){return new pt(ft.IN,t)},nin:function(t){return new pt(ft.NIN,t)},all:function(t){return new pt(ft.ALL,t)},elemMatch:function(t){return new pt(ft.ELEM_MATCH,[t])},exists:function(t){return new pt(ft.EXISTS,[t])},size:function(t){return new pt(ft.SIZE,[t])},mod:function(t){return new pt(ft.MOD,[t])},geoNear:function(t){return new pt(ft.GEO_NEAR,[t])},geoWithin:function(t){return new pt(ft.GEO_WITHIN,[t])},geoIntersects:function(t){return new pt(ft.GEO_INTERSECTS,[t])},and:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=k(arguments[0])?arguments[0]:Array.from(arguments);return new st(at.AND,n)},nor:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=k(arguments[0])?arguments[0]:Array.from(arguments);return new st(at.NOR,n)},or:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=k(arguments[0])?arguments[0]:Array.from(arguments);return new st(at.OR,n)},not:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=k(arguments[0])?arguments[0]:Array.from(arguments);return new st(at.NOT,n)},set:function(t){return new ut(tt.SET,[t])},remove:function(){return new ut(tt.REMOVE,[])},inc:function(t){return new ut(tt.INC,[t])},mul:function(t){return new ut(tt.MUL,[t])},push:function(){for(var t,e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];if($(e[0])&&e[0].hasOwnProperty("each")){var r=e[0];t={$each:r.each,$position:r.position,$sort:r.sort,$slice:r.slice}}else t=k(e[0])?e[0]:Array.from(e);return new ut(tt.PUSH,t)},pull:function(t){return new ut(tt.PULL,t)},pullAll:function(t){return new ut(tt.PULL_ALL,t)},pop:function(){return new ut(tt.POP,[])},shift:function(){return new ut(tt.SHIFT,[])},unshift:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=k(arguments[0])?arguments[0]:Array.from(arguments);return new ut(tt.UNSHIFT,n)},addToSet:function(t){return new ut(tt.ADD_TO_SET,t)},rename:function(t){return new ut(tt.RENAME,[t])},bit:function(t){return new ut(tt.BIT,[t])},max:function(t){return new ut(tt.MAX,[t])},min:function(t){return new ut(tt.MIN,[t])},expr:function(t){return{$expr:t}},jsonSchema:function(t){return{$jsonSchema:t}},text:function(t){return function(t){return"string"===M(t)}(t)?{$search:t.search}:{$search:t.search,$language:t.language,$caseSensitive:t.caseSensitive,$diacriticSensitive:t.diacriticSensitive}},aggregate:{pipeline:function(){return new Qt},abs:function(t){return new Yt("abs",t)},add:function(t){return new Yt("add",t)},ceil:function(t){return new Yt("ceil",t)},divide:function(t){return new Yt("divide",t)},exp:function(t){return new Yt("exp",t)},floor:function(t){return new Yt("floor",t)},ln:function(t){return new Yt("ln",t)},log:function(t){return new Yt("log",t)},log10:function(t){return new Yt("log10",t)},mod:function(t){return new Yt("mod",t)},multiply:function(t){return new Yt("multiply",t)},pow:function(t){return new Yt("pow",t)},sqrt:function(t){return new Yt("sqrt",t)},subtract:function(t){return new Yt("subtract",t)},trunc:function(t){return new Yt("trunc",t)},arrayElemAt:function(t){return new Yt("arrayElemAt",t)},arrayToObject:function(t){return new Yt("arrayToObject",t)},concatArrays:function(t){return new Yt("concatArrays",t)},filter:function(t){return new Yt("filter",t)},in:function(t){return new Yt("in",t)},indexOfArray:function(t){return new Yt("indexOfArray",t)},isArray:function(t){return new Yt("isArray",t)},map:function(t){return new Yt("map",t)},range:function(t){return new Yt("range",t)},reduce:function(t){return new Yt("reduce",t)},reverseArray:function(t){return new Yt("reverseArray",t)},size:function(t){return new Yt("size",t)},slice:function(t){return new Yt("slice",t)},zip:function(t){return new Yt("zip",t)},and:function(t){return new Yt("and",t)},not:function(t){return new Yt("not",t)},or:function(t){return new Yt("or",t)},cmp:function(t){return new Yt("cmp",t)},eq:function(t){return new Yt("eq",t)},gt:function(t){return new Yt("gt",t)},gte:function(t){return new Yt("gte",t)},lt:function(t){return new Yt("lt",t)},lte:function(t){return new Yt("lte",t)},neq:function(t){return new Yt("ne",t)},cond:function(t){return new Yt("cond",t)},ifNull:function(t){return new Yt("ifNull",t)},switch:function(t){return new Yt("switch",t)},dateFromParts:function(t){return new Yt("dateFromParts",t)},dateFromString:function(t){return new Yt("dateFromString",t)},dayOfMonth:function(t){return new Yt("dayOfMonth",t)},dayOfWeek:function(t){return new Yt("dayOfWeek",t)},dayOfYear:function(t){return new Yt("dayOfYear",t)},isoDayOfWeek:function(t){return new Yt("isoDayOfWeek",t)},isoWeek:function(t){return new Yt("isoWeek",t)},isoWeekYear:function(t){return new Yt("isoWeekYear",t)},millisecond:function(t){return new Yt("millisecond",t)},minute:function(t){return new Yt("minute",t)},month:function(t){return new Yt("month",t)},second:function(t){return new Yt("second",t)},hour:function(t){return new Yt("hour",t)},week:function(t){return new Yt("week",t)},year:function(t){return new Yt("year",t)},literal:function(t){return new Yt("literal",t)},mergeObjects:function(t){return new Yt("mergeObjects",t)},objectToArray:function(t){return new Yt("objectToArray",t)},allElementsTrue:function(t){return new Yt("allElementsTrue",t)},anyElementTrue:function(t){return new Yt("anyElementTrue",t)},setDifference:function(t){return new Yt("setDifference",t)},setEquals:function(t){return new Yt("setEquals",t)},setIntersection:function(t){return new Yt("setIntersection",t)},setIsSubset:function(t){return new Yt("setIsSubset",t)},setUnion:function(t){return new Yt("setUnion",t)},concat:function(t){return new Yt("concat",t)},dateToString:function(t){return new Yt("dateToString",t)},indexOfBytes:function(t){return new Yt("indexOfBytes",t)},indexOfCP:function(t){return new Yt("indexOfCP",t)},split:function(t){return new Yt("split",t)},strLenBytes:function(t){return new Yt("strLenBytes",t)},strLenCP:function(t){return new Yt("strLenCP",t)},strcasecmp:function(t){return new Yt("strcasecmp",t)},substr:function(t){return new Yt("substr",t)},substrBytes:function(t){return new Yt("substrBytes",t)},substrCP:function(t){return new Yt("substrCP",t)},toLower:function(t){return new Yt("toLower",t)},toUpper:function(t){return new Yt("toUpper",t)},meta:function(t){return new Yt("meta",t)},addToSet:function(t){return new Yt("addToSet",t)},avg:function(t){return new Yt("avg",t)},first:function(t){return new Yt("first",t)},last:function(t){return new Yt("last",t)},max:function(t){return new Yt("max",t)},min:function(t){return new Yt("min",t)},push:function(t){return new Yt("push",t)},stdDevPop:function(t){return new Yt("stdDevPop",t)},stdDevSamp:function(t){return new Yt("stdDevSamp",t)},sum:function(t){return new Yt("sum",t)},let:function(t){return new Yt("let",t)}},project:{slice:function(t){return new zt("slice",t)},elemMatch:function(t){return new zt("elemMatch",t)}}},Yt=function(t,e){this["$"+t]=e},zt=function(t,e){this["$"+t]=e},Xt=function(){function t(t){var e=t.regexp,n=t.options;if(!e)throw new TypeError("regexp must be a string");this.$regex=e,this.$options=n}return t.prototype.parse=function(){return{$regex:this.$regex,$options:this.$options}},Object.defineProperty(t.prototype,"_internalType",{get:function(){return L},enumerable:!1,configurable:!0}),t}();function Zt(t){return new Xt(t)}var Kt="insert document failed",te="DATABASE_TRANSACTION_CONFLICT",ee=function(){return ee=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},ee.apply(this,arguments)},ne=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function a(t){try{c(r.next(t))}catch(t){i(t)}}function u(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(a,u)}c((r=r.apply(t,e||[])).next())})},re=function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(u){return function(c){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,u[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,u[1])).done)return o;switch(r=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,r=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){a=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){a.label=u[1];break}if(6===u[0]&&a.label<o[1]){a.label=o[1],o=u;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(u);break}o[2]&&a.ops.pop(),a.trys.pop();continue}u=e.call(t,a)}catch(t){u=[6,t],r=0}finally{n=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,c])}}},oe="database.updateDocInTransaction",ie=function(){function t(t,e,n){this._coll=e,this.id=n,this._transaction=t,this._request=this._transaction.getRequestMethod(),this._transactionId=this._transaction.getTransactionId()}return t.prototype.create=function(t){return ne(this,void 0,void 0,function(){var e,n,r,o;return re(this,function(i){switch(i.label){case 0:return e={collectionName:this._coll,transactionId:this._transactionId,data:Jt.EJSON.stringify(Ot(t),{relaxed:!1})},this.id&&(e._id=this.id),[4,this._request.send("database.insertDocInTransaction",e)];case 1:if((n=i.sent()).code)throw n;if(r=Jt.EJSON.parse(n.inserted),1==(o=Jt.EJSON.parse(n.ok))&&1==r)return[2,ee(ee({},n),{ok:o,inserted:r})];throw new Error(Kt)}})})},t.prototype.get=function(){return ne(this,void 0,void 0,function(){var t,e;return re(this,function(n){switch(n.label){case 0:return t={collectionName:this._coll,transactionId:this._transactionId,query:{_id:{$eq:this.id}}},[4,this._request.send("database.getInTransaction",t)];case 1:if((e=n.sent()).code)throw e;return[2,{data:"null"!==e.data?nt.formatField(Jt.EJSON.parse(e.data)):Jt.EJSON.parse(e.data),requestId:e.requestId}]}})})},t.prototype.set=function(t){return ne(this,void 0,void 0,function(){var e,n;return re(this,function(r){switch(r.label){case 0:return e={collectionName:this._coll,transactionId:this._transactionId,query:{_id:{$eq:this.id}},data:Jt.EJSON.stringify(Ot(t),{relaxed:!1}),upsert:!0},[4,this._request.send(oe,e)];case 1:if((n=r.sent()).code)throw n;return[2,ee(ee({},n),{updated:Jt.EJSON.parse(n.updated),upserted:n.upserted?JSON.parse(n.upserted):null})]}})})},t.prototype.update=function(t){return ne(this,void 0,void 0,function(){var e,n;return re(this,function(r){switch(r.label){case 0:return e={collectionName:this._coll,transactionId:this._transactionId,query:{_id:{$eq:this.id}},data:Jt.EJSON.stringify(jt.encode(t),{relaxed:!1})},[4,this._request.send(oe,e)];case 1:if((n=r.sent()).code)throw n;return[2,ee(ee({},n),{updated:Jt.EJSON.parse(n.updated)})]}})})},t.prototype.delete=function(){return ne(this,void 0,void 0,function(){var t,e;return re(this,function(n){switch(n.label){case 0:return t={collectionName:this._coll,transactionId:this._transactionId,query:{_id:{$eq:this.id}}},[4,this._request.send("database.deleteDocInTransaction",t)];case 1:if((e=n.sent()).code)throw e;return[2,ee(ee({},e),{deleted:Jt.EJSON.parse(e.deleted)})]}})})},t}(),ae=function(){return ae=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},ae.apply(this,arguments)},ue=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function a(t){try{c(r.next(t))}catch(t){i(t)}}function u(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(a,u)}c((r=r.apply(t,e||[])).next())})},ce=function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(u){return function(c){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,u[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,u[1])).done)return o;switch(r=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,r=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){a=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){a.label=u[1];break}if(6===u[0]&&a.label<o[1]){a.label=o[1],o=u;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(u);break}o[2]&&a.ops.pop(),a.trys.pop();continue}u=e.call(t,a)}catch(t){u=[6,t],r=0}finally{n=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,c])}}},se="database.getInTransaction",le=function(){function t(t,e,n,r,o){this._coll=e,this._transaction=t,this._fieldFilters=n,this._fieldOrders=r||[],this._queryOptions=o||{},this._request=this._transaction.getRequestMethod(),this._transactionId=this._transaction.getTransactionId()}return t.prototype.where=function(e){if("Object"!==Object.prototype.toString.call(e).slice(8,-1))throw Error(o.QueryParamTypeError);var n=Object.keys(e),r=n.some(function(t){return void 0!==e[t]});if(n.length&&!r)throw Error(o.QueryParamValueError);return new t(this._transaction,this._coll,Mt.encode(e),this._fieldOrders,this._queryOptions)},t.prototype.orderBy=function(e,n){rt.isFieldPath(e),rt.isFieldOrder(n);var r={field:e,direction:n},o=this._fieldOrders.concat(r);return new t(this._transaction,this._coll,this._fieldFilters,o,this._queryOptions)},t.prototype.limit=function(e){rt.isInteger("limit",e);var n=ae({},this._queryOptions);return n.limit=e,new t(this._transaction,this._coll,this._fieldFilters,this._fieldOrders,n)},t.prototype.skip=function(e){rt.isInteger("offset",e);var n=ae({},this._queryOptions);return n.offset=e,new t(this._transaction,this._coll,this._fieldFilters,this._fieldOrders,n)},t.prototype.field=function(e){for(var n in e)e[n]?"object"!=typeof e[n]&&(e[n]=1):e[n]=0;var r=ae({},this._queryOptions);return r.projection=e,new t(this._transaction,this._coll,this._fieldFilters,this._fieldOrders,r)},t.prototype.get=function(){return ue(this,void 0,void 0,function(){var t,e,n,r,o,i;return ce(this,function(a){switch(a.label){case 0:return t=[],this._fieldOrders&&this._fieldOrders.forEach(function(e){t.push(e)}),e={collectionName:this._coll,transactionId:this._transactionId},this._fieldFilters&&(e.query=this._fieldFilters),t.length>0&&(e.order=t),this._queryOptions.offset&&(e.offset=this._queryOptions.offset),this._queryOptions.limit?e.limit=this._queryOptions.limit<1e3?this._queryOptions.limit:1e3:e.limit=100,this._queryOptions.projection&&(e.projection=this._queryOptions.projection),[4,this._request.send(se,e)];case 1:if((n=a.sent()).code)throw n;return r="null"!==n.data?Jt.EJSON.parse(n.data):null,o=r?Array.isArray(r)?nt.formatResDocumentData(r):[nt.formatField(r)]:[],i={data:o,requestId:n.requestId},void 0!==n.total&&(i.total=n.total),void 0!==n.limit&&(i.limit=n.limit),void 0!==n.offset&&(i.offset=n.offset),[2,i]}})})},t.prototype.count=function(){return ue(this,void 0,void 0,function(){var t,e,n,r;return ce(this,function(o){switch(o.label){case 0:return t={collectionName:this._coll,transactionId:this._transactionId},this._fieldFilters&&(t.query=this._fieldFilters),[4,this._request.send(se,t)];case 1:if((e=o.sent()).code)throw e;return n="null"!==e.data?Jt.EJSON.parse(e.data):null,r=Array.isArray(n)?n.length:n?1:0,[2,{requestId:e.requestId,total:void 0!==e.total?e.total:r}]}})})},t.prototype.update=function(t){return ue(this,void 0,void 0,function(){var e,n;return ce(this,function(r){switch(r.label){case 0:if(!t||"object"!=typeof t)throw new Error("参数必需是非空对象");if(t.hasOwnProperty("_id"))throw new Error("不能更新_id的值");return e={collectionName:this._coll,transactionId:this._transactionId,query:this._fieldFilters,data:Jt.EJSON.stringify(jt.encode(t),{relaxed:!1})},[4,this._request.send("database.updateDocInTransaction",e)];case 1:if((n=r.sent()).code)throw n;return[2,ae(ae({},n),{updated:Jt.EJSON.parse(n.updated)})]}})})},t.prototype.remove=function(){return ue(this,void 0,void 0,function(){var t,e;return ce(this,function(n){switch(n.label){case 0:return Object.keys(this._queryOptions).length>0&&console.warn("`offset`, `limit` and `projection` are not supported in remove() operation"),this._fieldOrders.length>0&&console.warn("`orderBy` is not supported in remove() operation"),t={collectionName:this._coll,transactionId:this._transactionId,query:this._fieldFilters},[4,this._request.send("database.deleteDocInTransaction",t)];case 1:if((e=n.sent()).code)throw e;return[2,ae(ae({},e),{deleted:Jt.EJSON.parse(e.deleted)})]}})})},t}(),fe=function(){var t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},t(e,n)};return function(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),de=function(t){function e(e,n){return t.call(this,e,n)||this}return fe(e,t),Object.defineProperty(e.prototype,"name",{get:function(){return this._coll},enumerable:!1,configurable:!0}),e.prototype.doc=function(t){if("string"!=typeof t&&"number"!=typeof t)throw new Error("docId必须为字符串或数字");return new ie(this._transaction,this._coll,t)},e.prototype.add=function(t){var e;return void 0!==t._id&&(e=t._id),new ie(this._transaction,this._coll,e).create(t)},e}(le),pe=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function a(t){try{c(r.next(t))}catch(t){i(t)}}function u(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(a,u)}c((r=r.apply(t,e||[])).next())})},he=function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(u){return function(c){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,u[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,u[1])).done)return o;switch(r=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,r=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){a=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){a.label=u[1];break}if(6===u[0]&&a.label<o[1]){a.label=o[1],o=u;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(u);break}o[2]&&a.ops.pop(),a.trys.pop();continue}u=e.call(t,a)}catch(t){u=[6,t],r=0}finally{n=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,c])}}},ye=function(){function t(t){this._db=t,this._request=we.createRequest(this._db.config),this.aborted=!1,this.commited=!1,this.inited=!1}return t.prototype.init=function(){return pe(this,void 0,void 0,function(){var t;return he(this,function(e){switch(e.label){case 0:return[4,this._request.send("database.startTransaction")];case 1:if((t=e.sent()).code)throw t;return this.inited=!0,this._id=t.transactionId,[2]}})})},t.prototype.collection=function(t){if(!t)throw new Error("Collection name is required");return new de(this,t)},t.prototype.getTransactionId=function(){return this._id},t.prototype.getRequestMethod=function(){return this._request},t.prototype.commit=function(){return pe(this,void 0,void 0,function(){var t,e;return he(this,function(n){switch(n.label){case 0:return t={transactionId:this._id},[4,this._request.send("database.commitTransaction",t)];case 1:if((e=n.sent()).code)throw e;return this.commited=!0,[2,e]}})})},t.prototype.rollback=function(t){return pe(this,void 0,void 0,function(){var e,n;return he(this,function(r){switch(r.label){case 0:return e={transactionId:this._id},[4,this._request.send("database.abortTransaction",e)];case 1:if((n=r.sent()).code)throw n;return this.aborted=!0,this.abortReason=t,[2,n]}})})},t}();function me(){return pe(this,void 0,void 0,function(){var t;return he(this,function(e){switch(e.label){case 0:return[4,(t=new ye(this)).init()];case 1:return e.sent(),[2,t]}})})}function ve(t,e){return void 0===e&&(e=3),pe(this,void 0,void 0,function(){var n,r,o,i,a=this;return he(this,function(u){switch(u.label){case 0:return u.trys.push([0,4,,10]),[4,(n=new ye(this)).init()];case 1:return u.sent(),[4,t(n)];case 2:if(r=u.sent(),!0===n.aborted)throw n.abortReason;return[4,n.commit()];case 3:return u.sent(),[2,r];case 4:if(o=u.sent(),!1===n.inited)throw o;return i=function(t){return pe(a,void 0,void 0,function(){return he(this,function(e){switch(e.label){case 0:if(n.aborted||n.commited)return[3,5];e.label=1;case 1:return e.trys.push([1,3,,4]),[4,n.rollback()];case 2:case 3:return e.sent(),[3,4];case 4:throw t;case 5:if(!0===n.aborted)throw n.abortReason;throw t}})})},e<=0?[4,i(o)]:[3,6];case 5:u.sent(),u.label=6;case 6:return o&&o.code===te?[4,ve.bind(this)(t,--e)]:[3,8];case 7:return[2,u.sent()];case 8:return[4,i(o)];case 9:return u.sent(),[3,10];case 10:return[2]}})})}var we=function(){function t(t){this.config=t,this.Geo=i,this.serverDate=K,this.command=Vt,this.RegExp=Zt,this.startTransaction=me,this.runTransaction=ve,this.logicCommand=st,this.updateCommand=ut,this.queryCommand=pt}return t.createRequest=function(e){var n=new t.reqClass(e),r=n.send;return n.send=function(t,n){return e.instance&&(n.instance=e.instance),e.database&&(n.database=e.database),r.call(this,t,n)},n},t.prototype.collection=function(t){if(!t)throw new Error("Collection name is required");return new Bt(this,t)},t.prototype.createCollection=function(e){var n={collectionName:e};return t.createRequest(this.config).send("database.addCollection",n)},t}(),be=function(){var t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},t(e,n)};return function(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),ge=function(){return ge=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},ge.apply(this,arguments)},_e=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function a(t){try{c(r.next(t))}catch(t){i(t)}}function u(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(a,u)}c((r=r.apply(t,e||[])).next())})},Oe=function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(u){return function(c){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,u[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,u[1])).done)return o;switch(r=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,r=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){a=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){a.label=u[1];break}if(6===u[0]&&a.label<o[1]){a.label=o[1],o=u;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(u);break}o[2]&&a.ops.pop(),a.trys.pop();continue}u=e.call(t,a)}catch(t){u=[6,t],r=0}finally{n=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,c])}}},Ee={filterRes:function(t){return delete t.header,delete t.statusCode,t},flattenResData:function(t){if("object"==typeof t.data&&null!==t.data){var e=ge(ge({},t),t.data);return delete e.data,e}return t},safeParseEJSON:function(t){if("string"!=typeof t)return t;try{return Jt.EJSON.parse(t)}catch(e){return t}},buildQueryParams:function(t){return Object.entries(t).filter(function(t){t[0];var e=t[1];return null!=e&&""!==e}).map(function(t){var e=t[0],n=t[1],r="object"==typeof n?JSON.stringify(n):String(n);return"".concat(encodeURIComponent(e),"=").concat(encodeURIComponent(r))}).join("&")},getUrlPrefix:function(t){var e=(null==t?void 0:t.instance)||"(default)",n=(null==t?void 0:t.database)||"(default)";return"/database/instances/".concat(e,"/databases/").concat(n)},"database.queryDocument":function(t){var e,n,r,o,i,a,u,c;return _e(this,void 0,Promise,function(){var s,l,f,d;return Oe(this,function(p){switch(p.label){case 0:return s=!!(null===(n=null===(e=t.query)||void 0===e?void 0:e._id)||void 0===n?void 0:n.$eq),l=Ee.buildQueryParams(ge({projection:t.projection,transactionId:t.transactionId},s?{}:{offset:null!==(r=t.offset)&&void 0!==r?r:0,limit:null!==(o=t.limit)&&void 0!==o?o:100,order:t.order,query:t.query?Jt.EJSON.stringify(t.query,{relaxed:!1}):void 0})),f="".concat(Ee.getUrlPrefix(t),"/collections/").concat(t.collectionName,"/documents?").concat(l),s&&(f="".concat(Ee.getUrlPrefix(t),"/collections/").concat(t.collectionName,"/documents/").concat((null===(i=t.query._id)||void 0===i?void 0:i.$eq)||t.query._id,"?").concat(l)),[4,this.gateWay({url:f,method:"GET"})];case 1:return(d=p.sent()).data=Ee.safeParseEJSON(JSON.stringify(d.data)),!s||d.code||(null===(a=d.data)||void 0===a?void 0:a.code)?(d.code||(null===(u=d.data)||void 0===u?void 0:u.code)?d=ge(ge({},d),{code:d.code||(null===(c=d.data)||void 0===c?void 0:c.code),data:ge(ge({},d.data),{list:[]})}):Array.isArray(d.data)?d=ge(ge({},d),{data:{list:d.data}}):d.data&&!Array.isArray(d.data.list)&&(d=ge(ge({},d),{data:ge(ge({},d.data),{list:[]})})),[2,Ee.filterRes(d)]):[2,ge(ge({},d),{data:{list:[d.data]}})]}})})},"database.addDocument":function(t){var e,n,r;return _e(this,void 0,Promise,function(){var o;return Oe(this,function(i){switch(i.label){case 0:return[4,this.gateWay({url:"".concat(Ee.getUrlPrefix(t),"/collections/").concat(t.collectionName,"/documents"),method:"POST",data:ge({data:Array.isArray(t.data)?t.data:[t.data]},t.transactionId&&{transactionId:t.transactionId})})];case 1:return o=i.sent(),Array.isArray(t.data)?o=ge(ge({},o),{data:ge({ids:(null===(e=o.data)||void 0===e?void 0:e.insertedIds)||[]},o.data)}):(null===(r=null===(n=o.data)||void 0===n?void 0:n.insertedIds)||void 0===r?void 0:r[0])&&(o=ge(ge({},o),{data:ge({_id:o.data.insertedIds[0]},o.data)})),[2,Ee.filterRes(o)]}})})},"database.updateDocument":function(t){return _e(this,void 0,Promise,function(){var e;return Oe(this,function(n){switch(n.label){case 0:return[4,this.gateWay({url:"".concat(Ee.getUrlPrefix(t),"/collections/").concat(t.collectionName,"/documents"),method:"PATCH",data:ge({query:t.query,data:t.data,multi:!!t.multi,upsert:!!t.upsert,replaceMode:!!t.replaceMode},t.transactionId&&{transactionId:t.transactionId})})];case 1:return e=n.sent(),[2,Ee.filterRes(e)]}})})},"database.deleteDocument":function(t){return _e(this,void 0,Promise,function(){var e;return Oe(this,function(n){switch(n.label){case 0:return[4,this.gateWay({url:"".concat(Ee.getUrlPrefix(t),"/collections/").concat(t.collectionName,"/documents/remove"),method:"POST",data:ge({query:t.query,multi:!!t.multi},t.transactionId&&{transactionId:t.transactionId})})];case 1:return e=n.sent(),[2,Ee.filterRes(e)]}})})},"database.countDocument":function(t){return _e(this,void 0,Promise,function(){var e,n;return Oe(this,function(r){switch(r.label){case 0:return e=Ee.buildQueryParams({count:!0,query:t.query?Jt.EJSON.stringify(t.query,{relaxed:!1}):void 0}),[4,this.gateWay({url:"".concat(Ee.getUrlPrefix(t),"/collections/").concat(t.collectionName,"/documents?").concat(e),method:"GET"})];case 1:return n=r.sent(),[2,Ee.filterRes(n)]}})})},"database.addCollection":function(t){return _e(this,void 0,Promise,function(){var e;return Oe(this,function(n){switch(n.label){case 0:return[4,this.gateWay({url:"".concat(Ee.getUrlPrefix(t),"/collections"),method:"POST",data:{collectionName:t.collectionName}})];case 1:return e=n.sent(),[2,Ee.filterRes(e)]}})})},"database.aggregate":function(t){var e;return _e(this,void 0,Promise,function(){var n,r;return Oe(this,function(o){switch(o.label){case 0:return n=t.stages.map(function(t){var e,n;try{var r="string"==typeof t.stageValue?JSON.parse(t.stageValue):t.stageValue;return(e={})[t.stageKey]=Jt.EJSON.serialize(r),e}catch(e){return(n={})[t.stageKey]=t.stageValue,n}}),[4,this.gateWay({url:"".concat(Ee.getUrlPrefix(t),"/collections/").concat(t.collectionName,"/documents/aggregations"),method:"POST",data:{pipeline:n}})];case 1:return r=o.sent(),Array.isArray(null===(e=r.data)||void 0===e?void 0:e.list)&&(r.data.list=JSON.stringify(r.data.list.map(function(t){return JSON.stringify(t)}))),[2,Ee.filterRes(r)]}})})},"database.startTransaction":function(t){return _e(this,void 0,void 0,function(){var e;return Oe(this,function(n){switch(n.label){case 0:return[4,this.gateWay({url:"".concat(Ee.getUrlPrefix(t),"/transactions"),method:"POST"})];case 1:return e=n.sent(),[2,Ee.filterRes(Ee.flattenResData(e))]}})})},"database.commitTransaction":function(t){return _e(this,void 0,void 0,function(){var e;return Oe(this,function(n){switch(n.label){case 0:return[4,this.gateWay({url:"".concat(Ee.getUrlPrefix(t),"/transactions/").concat(t.transactionId,"/commit"),method:"POST"})];case 1:return e=n.sent(),[2,Ee.filterRes(e)]}})})},"database.abortTransaction":function(t){return _e(this,void 0,void 0,function(){var e;return Oe(this,function(n){switch(n.label){case 0:return[4,this.gateWay({url:"".concat(Ee.getUrlPrefix(t),"/transactions/").concat(t.transactionId,"/rollback"),method:"POST"})];case 1:return e=n.sent(),[2,Ee.filterRes(e)]}})})},"database.getInTransaction":function(t){var e;return _e(this,void 0,void 0,function(){var n;return Oe(this,function(r){switch(r.label){case 0:return[4,Ee["database.queryDocument"].call(this,t)];case 1:return"object"==typeof(n=r.sent()).data&&null!==n.data?(null===(e=n.data)||void 0===e?void 0:e.code)?[2,Ee.flattenResData(n)]:[2,ge(ge({},n),{data:JSON.stringify(n.data)})]:[2,n]}})})},"database.updateDocInTransaction":function(t){return _e(this,void 0,void 0,function(){var e;return Oe(this,function(n){switch(n.label){case 0:return t.data=Ee.safeParseEJSON(t.data),[4,Ee["database.updateDocument"].call(this,t)];case 1:return e=n.sent(),[2,Ee.flattenResData(e)]}})})},"database.deleteDocInTransaction":function(t){return _e(this,void 0,void 0,function(){var e;return Oe(this,function(n){switch(n.label){case 0:return[4,Ee["database.deleteDocument"].call(this,t)];case 1:return e=n.sent(),[2,Ee.flattenResData(e)]}})})},"database.insertDocInTransaction":function(t){var e;return _e(this,void 0,Promise,function(){var n,r;return Oe(this,function(o){switch(o.label){case 0:return t.data=Ee.safeParseEJSON(t.data),[4,Ee["database.addDocument"].call(this,t)];case 1:return"object"==typeof(n=o.sent()).data&&null!==n.data?(r=!!(null===(e=n.data)||void 0===e?void 0:e._id),n=ge(ge(ge({},n),{inserted:r?1:0,ok:r?1:0}),n.data)):n=ge({inserted:0,ok:0},n),delete n.data,[2,n]}})})},"database.runCommands":function(t){return _e(this,void 0,Promise,function(){var e;return Oe(this,function(n){switch(n.label){case 0:return[4,this.gateWay({url:"".concat(Ee.getUrlPrefix(t),"/commands"),method:"POST",data:ge({commands:Jt.EJSON.serialize(t.commands)},t.transactionId&&{transactionId:t.transactionId})})];case 1:"object"==typeof(e=n.sent()).data&&null!==e.data&&(delete(e=ge(ge({},e),e.data)).data,delete e.request_id);try{e=Jt.EJSON.deserialize(e)}catch(t){}return[2,Ee.filterRes(e)]}})})}},Ne={name:"database",entity:{database:function(t){var e=this.platform,n=e.adapter,r=e.runtime,o=function(t){function e(e){return t.call(this,e)||this}return be(e,t),e.prototype.send=function(e,n){return _e(this,void 0,void 0,function(){var r;return Oe(this,function(o){switch(o.label){case 0:return r=null,"GATEWAY"===this.config.endPointMode&&Ee[e]?[4,Ee[e].call(this,n)]:[3,2];case 1:return r=o.sent(),[3,4];case 2:return[4,t.prototype.send.call(this,e,n)];case 3:r=o.sent(),o.label=4;case 4:return[2,r]}})})},e}(this.request.constructor);return we.reqClass=o,we.getAccessToken=this.authInstance?this.authInstance.getAccessToken.bind(this.authInstance):function(){return""},we.runtime=r,this.wsClientClass&&(we.wsClass=n.wsClass,we.wsClientClass=this.wsClientClass),we.ws||(we.ws=null),new(function(t){function e(e){return t.call(this,e)||this}return be(e,t),e.prototype.runCommands=function(t){return _e(this,void 0,Promise,function(){return Oe(this,function(e){return[2,we.createRequest(this.config).send("database.runCommands",t)]})})},e}(we))(ge(ge(ge({},this.config),{_fromApp:this}),t))}}};try{cloudbase.registerComponent(Ne)}catch(t){}function Se(t){try{t.registerComponent(Ne)}catch(t){console.warn(t)}}try{window.registerDatabase=Se}catch(t){}var Ie=n.I;export{Ie as registerDatabase};
2
+ //# sourceMappingURL=index.esm.js.map