@cloudbase/js-sdk 4.0.0 → 4.0.1-alpha.1

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 (203) hide show
  1. package/CHANGELOG.md +398 -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.d.ts +1 -0
  7. package/apis/dist/index.esm.js +2 -0
  8. package/apis/dist/index.esm.js.map +1 -0
  9. package/apis/dist/index.js +2 -0
  10. package/apis/dist/index.js.map +1 -0
  11. package/{analytics → apis}/package.json +1 -1
  12. package/app/dist/index.esm.js +2 -11
  13. package/app/dist/index.esm.js.map +1 -0
  14. package/app/dist/index.js +2 -18
  15. package/app/dist/index.js.map +1 -0
  16. package/app/dist/index.node.esm.js +3 -0
  17. package/app/dist/index.node.esm.js.LICENSE.txt +13 -0
  18. package/app/dist/index.node.esm.js.map +1 -0
  19. package/app/dist/index.node.js +3 -0
  20. package/app/dist/index.node.js.LICENSE.txt +13 -0
  21. package/app/dist/index.node.js.map +1 -0
  22. package/app/package.json +12 -1
  23. package/auth/dist/index.d.ts +2 -2
  24. package/auth/dist/index.esm.js +3 -4
  25. package/auth/dist/index.esm.js.LICENSE.txt +12 -0
  26. package/auth/dist/index.esm.js.map +1 -0
  27. package/auth/dist/index.js +3 -9
  28. package/auth/dist/index.js.LICENSE.txt +12 -0
  29. package/auth/dist/index.js.map +1 -0
  30. package/cloudrun/dist/index.esm.js +2 -3
  31. package/cloudrun/dist/index.esm.js.map +1 -0
  32. package/cloudrun/dist/index.js +2 -21
  33. package/cloudrun/dist/index.js.map +1 -0
  34. package/container/dist/index.d.ts +2 -2
  35. package/container/dist/index.esm.js +2 -4
  36. package/container/dist/index.esm.js.map +1 -0
  37. package/container/dist/index.js +2 -9
  38. package/container/dist/index.js.map +1 -0
  39. package/core.d.ts +4331 -0
  40. package/core.node.d.ts +294 -0
  41. package/database/dist/index.esm.js +2 -47
  42. package/database/dist/index.esm.js.map +1 -0
  43. package/database/dist/index.js +2 -53
  44. package/database/dist/index.js.map +1 -0
  45. package/database/package.json +34 -4
  46. package/dist/index.cjs.js +3 -37
  47. package/dist/index.cjs.js.LICENSE.txt +12 -0
  48. package/dist/index.cjs.js.map +1 -0
  49. package/dist/index.esm.js +3 -32
  50. package/dist/index.esm.js.LICENSE.txt +12 -0
  51. package/dist/index.esm.js.map +1 -0
  52. package/dist/index.node.cjs.js +3 -0
  53. package/dist/index.node.cjs.js.LICENSE.txt +26 -0
  54. package/dist/index.node.cjs.js.map +1 -0
  55. package/dist/index.node.esm.js +3 -0
  56. package/dist/index.node.esm.js.LICENSE.txt +26 -0
  57. package/dist/index.node.esm.js.map +1 -0
  58. package/functions/dist/index.d.ts +2 -2
  59. package/functions/dist/index.esm.js +2 -4
  60. package/functions/dist/index.esm.js.map +1 -0
  61. package/functions/dist/index.js +2 -9
  62. package/functions/dist/index.js.map +1 -0
  63. package/index.d.ts +7 -1785
  64. package/index.node.d.ts +13 -0
  65. package/miniprogram_dist/ai/index.d.ts +42 -0
  66. package/miniprogram_dist/ai/index.js +2 -0
  67. package/miniprogram_dist/apis/index.d.ts +5 -0
  68. package/miniprogram_dist/apis/index.js +1 -0
  69. package/miniprogram_dist/app/index.d.ts +67 -0
  70. package/miniprogram_dist/app/index.js +2 -0
  71. package/miniprogram_dist/auth/index.d.ts +269 -0
  72. package/miniprogram_dist/auth/index.js +2 -0
  73. package/miniprogram_dist/cloudrun/index.d.ts +4 -0
  74. package/miniprogram_dist/cloudrun/index.js +1 -0
  75. package/miniprogram_dist/container/index.d.ts +13 -0
  76. package/miniprogram_dist/container/index.js +1 -0
  77. package/miniprogram_dist/database/index.d.ts +3 -0
  78. package/miniprogram_dist/database/index.js +1 -0
  79. package/miniprogram_dist/functions/index.d.ts +2 -0
  80. package/miniprogram_dist/functions/index.js +1 -0
  81. package/miniprogram_dist/index.js +1 -1
  82. package/miniprogram_dist/model/index.d.ts +5 -0
  83. package/miniprogram_dist/model/index.js +1 -0
  84. package/miniprogram_dist/mysql/index.d.ts +3 -0
  85. package/miniprogram_dist/mysql/index.js +1 -0
  86. package/miniprogram_dist/oauth/index.d.ts +22 -0
  87. package/miniprogram_dist/oauth/index.js +2 -0
  88. package/miniprogram_dist/realtime/index.d.ts +2 -0
  89. package/miniprogram_dist/realtime/index.js +1 -0
  90. package/miniprogram_dist/storage/index.d.ts +13 -0
  91. package/miniprogram_dist/storage/index.js +1 -0
  92. package/model/dist/index.esm.js +2 -3
  93. package/model/dist/index.esm.js.map +1 -0
  94. package/model/dist/index.js +2 -21
  95. package/model/dist/index.js.map +1 -0
  96. package/mysql/dist/index.d.ts +1 -0
  97. package/mysql/dist/index.esm.js +2 -0
  98. package/mysql/dist/index.esm.js.map +1 -0
  99. package/mysql/dist/index.js +2 -0
  100. package/mysql/dist/index.js.map +1 -0
  101. package/mysql/package.json +6 -0
  102. package/oauth/dist/index.esm.js +3 -3
  103. package/oauth/dist/index.esm.js.LICENSE.txt +12 -0
  104. package/oauth/dist/index.esm.js.map +1 -0
  105. package/oauth/dist/index.js +3 -21
  106. package/oauth/dist/index.js.LICENSE.txt +12 -0
  107. package/oauth/dist/index.js.map +1 -0
  108. package/package.json +144 -18
  109. package/realtime/dist/index.d.ts +2 -2
  110. package/realtime/dist/index.esm.js +2 -4
  111. package/realtime/dist/index.esm.js.map +1 -0
  112. package/realtime/dist/index.js +2 -9
  113. package/realtime/dist/index.js.map +1 -0
  114. package/storage/dist/index.d.ts +2 -2
  115. package/storage/dist/index.esm.js +2 -4
  116. package/storage/dist/index.esm.js.map +1 -0
  117. package/storage/dist/index.js +2 -9
  118. package/storage/dist/index.js.map +1 -0
  119. package/types/analytics.d.ts +51 -0
  120. package/types/auth.d.ts +166 -0
  121. package/types/cache.d.ts +26 -0
  122. package/types/cloudrun.d.ts +9 -0
  123. package/types/component.d.ts +17 -0
  124. package/types/container.d.ts +93 -0
  125. package/types/database.d.ts +31 -0
  126. package/types/error.d.ts +40 -0
  127. package/types/events.d.ts +13 -0
  128. package/types/functions.d.ts +49 -0
  129. package/types/index.d.ts +269 -0
  130. package/types/package.json +47 -0
  131. package/types/realtime.d.ts +350 -0
  132. package/types/request.d.ts +30 -0
  133. package/types/result.d.ts +48 -0
  134. package/types/storage.d.ts +144 -0
  135. package/utilities/dist/cjs/adapters/index.d.ts +45 -0
  136. package/utilities/dist/cjs/adapters/index.js +68 -0
  137. package/utilities/dist/cjs/adapters/platforms/web.d.ts +20 -0
  138. package/utilities/dist/cjs/adapters/platforms/web.js +286 -0
  139. package/utilities/dist/cjs/constants/common.d.ts +6 -0
  140. package/utilities/dist/cjs/constants/common.js +24 -0
  141. package/utilities/dist/cjs/constants/errors.d.ts +8 -0
  142. package/utilities/dist/cjs/constants/errors.js +12 -0
  143. package/utilities/dist/cjs/constants/index.d.ts +3 -0
  144. package/utilities/dist/cjs/constants/index.js +21 -0
  145. package/utilities/dist/cjs/helpers/decorators.d.ts +11 -0
  146. package/utilities/dist/cjs/helpers/decorators.js +238 -0
  147. package/utilities/dist/cjs/helpers/index.d.ts +1 -0
  148. package/utilities/dist/cjs/helpers/index.js +18 -0
  149. package/utilities/dist/cjs/index.d.ts +13 -0
  150. package/utilities/dist/cjs/index.js +51 -0
  151. package/utilities/dist/cjs/libs/abortController.d.ts +9 -0
  152. package/utilities/dist/cjs/libs/abortController.js +25 -0
  153. package/utilities/dist/cjs/libs/cache.d.ts +17 -0
  154. package/utilities/dist/cjs/libs/cache.js +261 -0
  155. package/utilities/dist/cjs/libs/events.d.ts +27 -0
  156. package/utilities/dist/cjs/libs/events.js +108 -0
  157. package/utilities/dist/cjs/libs/langEvent.d.ts +3 -0
  158. package/utilities/dist/cjs/libs/langEvent.js +7 -0
  159. package/utilities/dist/cjs/libs/util.d.ts +49 -0
  160. package/utilities/dist/cjs/libs/util.js +282 -0
  161. package/utilities/dist/esm/adapters/index.d.ts +45 -0
  162. package/utilities/dist/esm/adapters/index.js +40 -0
  163. package/utilities/dist/esm/adapters/platforms/web.d.ts +20 -0
  164. package/utilities/dist/esm/adapters/platforms/web.js +282 -0
  165. package/utilities/dist/esm/constants/common.d.ts +6 -0
  166. package/utilities/dist/esm/constants/common.js +17 -0
  167. package/utilities/dist/esm/constants/errors.d.ts +8 -0
  168. package/utilities/dist/esm/constants/errors.js +9 -0
  169. package/utilities/dist/esm/constants/index.d.ts +3 -0
  170. package/utilities/dist/esm/constants/index.js +4 -0
  171. package/utilities/dist/esm/helpers/decorators.d.ts +11 -0
  172. package/utilities/dist/esm/helpers/decorators.js +234 -0
  173. package/utilities/dist/esm/helpers/index.d.ts +1 -0
  174. package/utilities/dist/esm/helpers/index.js +2 -0
  175. package/utilities/dist/esm/index.d.ts +13 -0
  176. package/utilities/dist/esm/index.js +14 -0
  177. package/utilities/dist/esm/libs/abortController.d.ts +9 -0
  178. package/utilities/dist/esm/libs/abortController.js +23 -0
  179. package/utilities/dist/esm/libs/cache.d.ts +17 -0
  180. package/utilities/dist/esm/libs/cache.js +258 -0
  181. package/utilities/dist/esm/libs/events.d.ts +27 -0
  182. package/utilities/dist/esm/libs/events.js +102 -0
  183. package/utilities/dist/esm/libs/langEvent.d.ts +3 -0
  184. package/utilities/dist/esm/libs/langEvent.js +4 -0
  185. package/utilities/dist/esm/libs/util.d.ts +49 -0
  186. package/utilities/dist/esm/libs/util.js +254 -0
  187. package/utilities/dist/miniprogram/index.js +1 -0
  188. package/utilities/package.json +26 -0
  189. package/analytics/dist/index.d.ts +0 -2
  190. package/analytics/dist/index.esm.js +0 -4
  191. package/analytics/dist/index.js +0 -9
  192. package/miniprogram_dist/ai.js +0 -2
  193. package/miniprogram_dist/analytics.js +0 -1
  194. package/miniprogram_dist/app.js +0 -2
  195. package/miniprogram_dist/auth.js +0 -2
  196. package/miniprogram_dist/cloudrun.js +0 -1
  197. package/miniprogram_dist/container.js +0 -1
  198. package/miniprogram_dist/database.js +0 -2
  199. package/miniprogram_dist/functions.js +0 -1
  200. package/miniprogram_dist/model.js +0 -1
  201. package/miniprogram_dist/oauth.js +0 -1
  202. package/miniprogram_dist/realtime.js +0 -1
  203. package/miniprogram_dist/storage.js +0 -1
package/core.node.d.ts ADDED
@@ -0,0 +1,294 @@
1
+ /// <reference path="./core.d.ts" />
2
+
3
+ /**
4
+ * Node.js 环境专属类型定义(ambient)。
5
+ *
6
+ * 通过声明合并(declaration merging)在共享的 `cloudbase` 命名空间之上追加
7
+ * 仅在 Node.js 运行时可用的接口、常量与方法。仅由 `index.node.d.ts` 引用,
8
+ * 因此这些定义不会出现在 Web/浏览器构建的类型中。
9
+ */
10
+ declare namespace cloudbase {
11
+ /**
12
+ * ICloudbaseConfig 的 Node.js 专属字段(通过声明合并追加)。
13
+ * 这些字段仅在 Node.js 入口(index.node.d.ts)可见,Web 构建不包含。
14
+ */
15
+ interface ICloudbaseConfig {
16
+ /** 密钥 ID(Node.js 端使用) */
17
+ secretId?: string
18
+ /** 密钥(Node.js 端使用) */
19
+ secretKey?: string
20
+ /** 临时会话 Token(Node.js 端使用) */
21
+ sessionToken?: string
22
+ /** 自定义登录密钥 */
23
+ credentials?: { private_key_id: string; private_key: string; env_id?: string; }
24
+ // @cloudbase/functions-framework 函数上下文,只要求部分字段,只在云函数或云托管中有效
25
+ context?: Readonly<{
26
+ eventID: string
27
+ extendedContext?: {
28
+ envId: string // 环境 ID
29
+ // uin: string // 请求的 UIN
30
+ source: string // 请求来源,如 wx
31
+ accessToken?: string // 调用请求时的 AccessToken
32
+ userId?: string // 请求的用户 ID
33
+ tmpSecret?: {
34
+ // 临时凭证
35
+ secretId: string // secretId
36
+ secretKey: string // secretKey
37
+ token: string // token
38
+ }
39
+ }
40
+ }>
41
+ }
42
+
43
+ /**
44
+ * ICloudbaseAuthConfig 的 Node.js 专属字段(通过声明合并追加)。
45
+ */
46
+ interface ICloudbaseAuthConfig {
47
+ /** 密钥 ID(Node.js 端使用) */
48
+ secretId?: string
49
+ /** 密钥(Node.js 端使用) */
50
+ secretKey?: string
51
+ /** 临时会话 Token(Node.js 端使用) */
52
+ sessionToken?: string
53
+ /** 密钥类型 */
54
+ secretType?: 'SESSION_SECRET' | 'SECRET'
55
+ }
56
+
57
+ /**
58
+ * 云函数入口 context 参数结构(仅 Node.js 环境)
59
+ */
60
+ interface IContextParam {
61
+ memory_limit_in_mb: number
62
+ time_limit_in_ms: number
63
+ request_id: string
64
+ /** 老架构环境变量字符串,分号分隔的 key=value */
65
+ environ?: string
66
+ /** 新架构环境变量 JSON 字符串 */
67
+ environment?: string
68
+ function_version: string
69
+ function_name: string
70
+ namespace: string
71
+ }
72
+
73
+ /**
74
+ * 云函数运行时完整环境变量类型汇总(仅 Node.js 环境)
75
+ * 包含 SCF、TCB、微信相关的所有环境变量
76
+ */
77
+ interface ICompleteCloudbaseContext {
78
+ _SCF_TCB_LOG?: string
79
+ LOGINTYPE?: string
80
+ QQ_APPID?: string
81
+ QQ_OPENID?: string
82
+ SCF_NAMESPACE: string
83
+ TCB_CONTEXT_CNFG?: string
84
+ TCB_CONTEXT_KEYS: string[]
85
+ TCB_CUSTOM_USER_ID?: string
86
+ TCB_ENV: string
87
+ TCB_HTTP_CONTEXT?: string
88
+ TCB_ISANONYMOUS_USER?: string
89
+ TCB_ROUTE_KEY?: string
90
+ TCB_SEQID: string
91
+ TCB_SESSIONTOKEN?: string
92
+ TCB_SOURCE_IP?: string
93
+ TCB_SOURCE?: string
94
+ TCB_TRACELOG?: string
95
+ TCB_UUID?: string
96
+ TENCENTCLOUD_RUNENV: string
97
+ TENCENTCLOUD_SECRETID: string
98
+ TENCENTCLOUD_SECRETKEY: string
99
+ TENCENTCLOUD_SESSIONTOKEN: string
100
+ CLOUDBASE_APIKEY: string
101
+ TRIGGER_SRC: string
102
+ WX_API_TOKEN?: string
103
+ WX_APPID?: string
104
+ WX_CLIENTIP?: string
105
+ WX_CLIENTIPV6?: string
106
+ WX_CLOUDBASE_ACCESSTOKEN?: string
107
+ WX_CONTEXT_KEYS: string[]
108
+ WX_OPENID?: string
109
+ WX_TRIGGER_API_TOKEN_V0?: string
110
+ WX_UNIONID?: string
111
+ }
112
+
113
+ /**
114
+ * 自定义登录 Ticket 创建选项(仅 Node.js 环境)
115
+ */
116
+ interface ICreateTicketOpts {
117
+ /** 刷新间隔(毫秒),默认 3600000(1小时) */
118
+ refresh?: number
119
+ /** 过期时间戳(毫秒),默认 7 天后 */
120
+ expire?: number
121
+ }
122
+
123
+ /**
124
+ * 当前请求用户信息(仅 Node.js 环境)
125
+ */
126
+ interface IGetUserInfoResult {
127
+ openId: string
128
+ appId: string
129
+ uid: string
130
+ customUserId: string
131
+ isAnonymous: boolean
132
+ }
133
+
134
+ /**
135
+ * getEndUserInfo 返回结果(仅 Node.js 环境)
136
+ */
137
+ interface IGetEndUserInfoResult {
138
+ userInfo?: {
139
+ openId: string
140
+ appId: string
141
+ uid: string
142
+ customUserId: string
143
+ isAnonymous: boolean
144
+ [key: string]: any
145
+ }
146
+ requestId?: string
147
+ code?: string
148
+ message?: string
149
+ }
150
+
151
+ /**
152
+ * 用户信息查询请求参数(仅 Node.js 环境)
153
+ */
154
+ interface IUserInfoQuery {
155
+ platform?: string
156
+ platformId?: string
157
+ uid?: string
158
+ }
159
+
160
+ /**
161
+ * 模板消息推送请求参数(仅 Node.js 环境)
162
+ */
163
+ interface ITemplateNotifyReq {
164
+ /** 通知策略 ID */
165
+ notifyId: string
166
+ /** 通知模板变量键值对 */
167
+ data?: Record<string, unknown>
168
+ /** 点击消息打开的页面地址 */
169
+ url?: string
170
+ }
171
+
172
+ /**
173
+ * Node 端 Auth Context 解析结果(仅 Node.js 环境)
174
+ */
175
+ interface INodeAuthContext {
176
+ uid?: string
177
+ loginType?: string
178
+ appId?: string
179
+ openId?: string
180
+ }
181
+
182
+ /**
183
+ * SDK 版本号(仅 Node.js 环境下挂载)
184
+ */
185
+ const version: string
186
+ /**
187
+ * 当前环境标记 Symbol(仅 Node.js 环境下挂载)
188
+ */
189
+ const SYMBOL_CURRENT_ENV: symbol
190
+ /**
191
+ * 默认环境标记 Symbol(仅 Node.js 环境下挂载)
192
+ */
193
+ const SYMBOL_DEFAULT_ENV: symbol
194
+ /**
195
+ * 解析并校验云函数入口的 Context 参数(仅 Node.js 环境)
196
+ *
197
+ * @param context 云函数入口传入的 context 对象
198
+ */
199
+ function parseContext(context: IContextParam): Record<string, any>
200
+ /**
201
+ * 获取当前云函数内的所有环境变量(仅 Node.js 环境)
202
+ * 统一从 process.env 和 context 两个来源合并取值
203
+ *
204
+ * @param context 可选,云函数入口的 context 参数
205
+ */
206
+ function getCloudbaseContext(context?: IContextParam): ICompleteCloudbaseContext
207
+ }
208
+
209
+ declare namespace cloudbase.app {
210
+ interface App {
211
+ /**
212
+ * 解析并缓存云函数入口的 Context 参数(仅 Node.js 环境)
213
+ *
214
+ * @param context 云函数入口传入的 context 对象
215
+ */
216
+ parseContext(context: cloudbase.IContextParam): Record<string, any>
217
+ /**
218
+ * 获取当前云函数内的所有环境变量(仅 Node.js 环境)
219
+ *
220
+ * @param context 可选,云函数入口的 context 参数
221
+ */
222
+ getCloudbaseContext(context?: cloudbase.IContextParam): cloudbase.ICompleteCloudbaseContext
223
+ /**
224
+ * 发送订阅消息 / 模板通知(仅 Node.js 环境)
225
+ *
226
+ * @param params 模板通知参数
227
+ * @param opts 可选,请求配置
228
+ */
229
+ sendTemplateNotification(
230
+ params: cloudbase.ITemplateNotifyReq,
231
+ opts?: { timeout?: number },
232
+ ): Promise<cloudbase.functions.ICallFunctionResponse>
233
+ /**
234
+ * 调用微信开放接口(仅 Node.js 环境)
235
+ */
236
+ callWxOpenApi(wxOpenApiOptions: any, opts?: cloudbase.ICustomReqOpts): Promise<any>
237
+ /**
238
+ * 调用微信支付接口(仅 Node.js 环境)
239
+ */
240
+ callWxPayApi(wxOpenApiOptions: any, opts?: cloudbase.ICustomReqOpts): Promise<any>
241
+ /**
242
+ * 调用微信云托管接口(仅 Node.js 环境)
243
+ */
244
+ wxCallContainerApi(wxOpenApiOptions: any, opts?: cloudbase.ICustomReqOpts): Promise<any>
245
+ /**
246
+ * 调用微信兼容开放接口(仅 Node.js 环境)
247
+ */
248
+ callCompatibleWxOpenApi(wxOpenApiOptions: any, opts?: cloudbase.ICustomReqOpts): Promise<any>
249
+ /**
250
+ * 获取文件访问权限(仅 Node.js 环境)
251
+ *
252
+ * @param params 文件列表参数
253
+ * @param opts 可选,请求配置
254
+ */
255
+ getFileAuthority(
256
+ params: { fileList: Array<{ type: string; path: string }> },
257
+ opts?: cloudbase.ICustomReqOpts,
258
+ ): Promise<any>
259
+ /**
260
+ * 调用已开放的 API(仅 Node.js 环境)
261
+ */
262
+ callApis(callApiOptions: any, opts?: cloudbase.ICustomReqOpts): Promise<any>
263
+ }
264
+ }
265
+
266
+ declare namespace cloudbase.auth {
267
+ interface App {
268
+ /**
269
+ * 获取终端用户信息(仅 Node.js 环境)
270
+ * 不传 uid 时返回当前请求用户信息,传 uid 时查询指定用户
271
+ */
272
+ getEndUserInfo(uid?: string): Promise<cloudbase.IGetEndUserInfoResult>
273
+ /**
274
+ * 创建自定义登录 Ticket(仅 Node.js 环境)
275
+ */
276
+ createTicket(uid: string, options?: cloudbase.ICreateTicketOpts): Promise<string>
277
+ /**
278
+ * 按条件查询用户信息(管理端接口,仅 Node.js 环境)
279
+ */
280
+ queryUserInfo(query: cloudbase.IUserInfoQuery): Promise<any>
281
+ /**
282
+ * 获取客户端 IP 地址(仅 Node.js 环境)
283
+ */
284
+ getClientIP(): string
285
+ /**
286
+ * 获取 Auth Context(从运行环境中解析,仅 Node.js 环境)
287
+ */
288
+ getAuthContext(context?: any): cloudbase.INodeAuthContext
289
+ /**
290
+ * 获取客户端凭证(仅 Node.js 环境)
291
+ */
292
+ getClientCredential(opts?: cloudbase.ICustomReqOpts): Promise<any>
293
+ }
294
+ }
@@ -1,47 +1,2 @@
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 { Db } from '@cloudbase/database';
13
- var COMPONENT_NAME = 'database';
14
- function database(dbConfig) {
15
- var _a = this.platform, adapter = _a.adapter, runtime = _a.runtime;
16
- Db.reqClass = this.request.constructor;
17
- Db.getAccessToken = this.authInstance ? this.authInstance.getAccessToken.bind(this.authInstance) : function () { return ''; };
18
- Db.runtime = runtime;
19
- if (this.wsClientClass) {
20
- Db.wsClass = adapter.wsClass;
21
- Db.wsClientClass = this.wsClientClass;
22
- }
23
- if (!Db.ws) {
24
- Db.ws = null;
25
- }
26
- return new Db(__assign(__assign(__assign({}, this.config), { _fromApp: this }), dbConfig));
27
- }
28
- var component = {
29
- name: COMPONENT_NAME,
30
- entity: {
31
- database: database,
32
- },
33
- };
34
- try {
35
- cloudbase.registerComponent(component);
36
- }
37
- catch (e) { }
38
- export function registerDatabase(app) {
39
- try {
40
- app.registerComponent(component);
41
- }
42
- catch (e) {
43
- console.warn(e);
44
- }
45
- }
46
-
47
- //# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImluZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7O0FBQUEsT0FBTyxFQUFFLEVBQUUsRUFBRSxNQUFNLHFCQUFxQixDQUFBO0FBT3hDLElBQU0sY0FBYyxHQUFHLFVBQVUsQ0FBQTtBQUVqQyxTQUFTLFFBQVEsQ0FBQyxRQUFpQjtJQUMzQixJQUFBLEtBQXVCLElBQUksQ0FBQyxRQUFRLEVBQWxDLE9BQU8sYUFBQSxFQUFFLE9BQU8sYUFBa0IsQ0FBQTtJQUUxQyxFQUFFLENBQUMsUUFBUSxHQUFHLElBQUksQ0FBQyxPQUFPLENBQUMsV0FBVyxDQUFBO0lBRXRDLEVBQUUsQ0FBQyxjQUFjLEdBQUcsSUFBSSxDQUFDLFlBQVksQ0FBQyxDQUFDLENBQUMsSUFBSSxDQUFDLFlBQVksQ0FBQyxjQUFjLENBQUMsSUFBSSxDQUFDLElBQUksQ0FBQyxZQUFZLENBQUMsQ0FBQyxDQUFDLENBQUMsY0FBTSxPQUFBLEVBQUUsRUFBRixDQUFFLENBQUE7SUFDM0csRUFBRSxDQUFDLE9BQU8sR0FBRyxPQUFPLENBQUE7SUFDcEIsSUFBSSxJQUFJLENBQUMsYUFBYSxFQUFFO1FBQ3RCLEVBQUUsQ0FBQyxPQUFPLEdBQUcsT0FBTyxDQUFDLE9BQU8sQ0FBQTtRQUM1QixFQUFFLENBQUMsYUFBYSxHQUFHLElBQUksQ0FBQyxhQUFhLENBQUE7S0FDdEM7SUFFRCxJQUFJLENBQUMsRUFBRSxDQUFDLEVBQUUsRUFBRTtRQUNWLEVBQUUsQ0FBQyxFQUFFLEdBQUcsSUFBSSxDQUFBO0tBQ2I7SUFFRCxPQUFPLElBQUksRUFBRSxnQ0FBTSxJQUFJLENBQUMsTUFBTSxLQUFFLFFBQVEsRUFBRSxJQUFJLEtBQUssUUFBUSxFQUFHLENBQUE7QUFDaEUsQ0FBQztBQUVELElBQU0sU0FBUyxHQUF3QjtJQUNyQyxJQUFJLEVBQUUsY0FBYztJQUNwQixNQUFNLEVBQUU7UUFDTixRQUFRLFVBQUE7S0FDVDtDQUNGLENBQUE7QUFDRCxJQUFJO0lBQ0YsU0FBUyxDQUFDLGlCQUFpQixDQUFDLFNBQVMsQ0FBQyxDQUFBO0NBQ3ZDO0FBQUMsT0FBTyxDQUFDLEVBQUUsR0FBRztBQUVmLE1BQU0sVUFBVSxnQkFBZ0IsQ0FBQyxHQUFvQztJQUNuRSxJQUFJO1FBQ0YsR0FBRyxDQUFDLGlCQUFpQixDQUFDLFNBQVMsQ0FBQyxDQUFBO0tBQ2pDO0lBQUMsT0FBTyxDQUFDLEVBQUU7UUFDVixPQUFPLENBQUMsSUFBSSxDQUFDLENBQUMsQ0FBQyxDQUFBO0tBQ2hCO0FBQ0gsQ0FBQyIsImZpbGUiOiJpbmRleC5lc20uanMiLCJzb3VyY2VzQ29udGVudCI6WyJpbXBvcnQgeyBEYiB9IGZyb20gJ0BjbG91ZGJhc2UvZGF0YWJhc2UnXG5pbXBvcnQgeyBJQ2xvdWRiYXNlIH0gZnJvbSAnQGNsb3VkYmFzZS90eXBlcydcbmltcG9ydCB7IElDbG91ZGJhc2VDb21wb25lbnQgfSBmcm9tICdAY2xvdWRiYXNlL3R5cGVzL2NvbXBvbmVudCdcbmltcG9ydCBjbG91ZGJhc2VOUyBmcm9tICcuLi8uLi9pbmRleCdcblxuZGVjbGFyZSBjb25zdCBjbG91ZGJhc2U6IElDbG91ZGJhc2VcblxuY29uc3QgQ09NUE9ORU5UX05BTUUgPSAnZGF0YWJhc2UnXG5cbmZ1bmN0aW9uIGRhdGFiYXNlKGRiQ29uZmlnPzogb2JqZWN0KSB7XG4gIGNvbnN0IHsgYWRhcHRlciwgcnVudGltZSB9ID0gdGhpcy5wbGF0Zm9ybVxuXG4gIERiLnJlcUNsYXNzID0gdGhpcy5yZXF1ZXN0LmNvbnN0cnVjdG9yXG4gIC8vIOacqueZu+W9leaDheWGteS4i+S8oOWFpeepuuWHveaVsFxuICBEYi5nZXRBY2Nlc3NUb2tlbiA9IHRoaXMuYXV0aEluc3RhbmNlID8gdGhpcy5hdXRoSW5zdGFuY2UuZ2V0QWNjZXNzVG9rZW4uYmluZCh0aGlzLmF1dGhJbnN0YW5jZSkgOiAoKSA9PiAnJ1xuICBEYi5ydW50aW1lID0gcnVudGltZVxuICBpZiAodGhpcy53c0NsaWVudENsYXNzKSB7XG4gICAgRGIud3NDbGFzcyA9IGFkYXB0ZXIud3NDbGFzc1xuICAgIERiLndzQ2xpZW50Q2xhc3MgPSB0aGlzLndzQ2xpZW50Q2xhc3NcbiAgfVxuXG4gIGlmICghRGIud3MpIHtcbiAgICBEYi53cyA9IG51bGxcbiAgfVxuXG4gIHJldHVybiBuZXcgRGIoeyAuLi50aGlzLmNvbmZpZywgX2Zyb21BcHA6IHRoaXMsIC4uLmRiQ29uZmlnIH0pXG59XG5cbmNvbnN0IGNvbXBvbmVudDogSUNsb3VkYmFzZUNvbXBvbmVudCA9IHtcbiAgbmFtZTogQ09NUE9ORU5UX05BTUUsXG4gIGVudGl0eToge1xuICAgIGRhdGFiYXNlLFxuICB9LFxufVxudHJ5IHtcbiAgY2xvdWRiYXNlLnJlZ2lzdGVyQ29tcG9uZW50KGNvbXBvbmVudClcbn0gY2F0Y2ggKGUpIHsgfVxuXG5leHBvcnQgZnVuY3Rpb24gcmVnaXN0ZXJEYXRhYmFzZShhcHA6IElDbG91ZGJhc2UgfCB0eXBlb2YgY2xvdWRiYXNlTlMpIHtcbiAgdHJ5IHtcbiAgICBhcHAucmVnaXN0ZXJDb21wb25lbnQoY29tcG9uZW50KVxuICB9IGNhdGNoIChlKSB7XG4gICAgY29uc29sZS53YXJuKGUpXG4gIH1cbn1cbiJdfQ==
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