@cloudbase/js-sdk 3.6.2 → 3.6.3

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 (74) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/ai/dist/index.esm.js +1 -1
  3. package/ai/dist/index.esm.js.map +1 -1
  4. package/ai/dist/index.js +1 -1
  5. package/ai/dist/index.js.map +1 -1
  6. package/app/dist/index.esm.js +1 -1
  7. package/app/dist/index.esm.js.map +1 -1
  8. package/app/dist/index.js +1 -1
  9. package/app/dist/index.js.map +1 -1
  10. package/app/dist/index.node.esm.js +1 -1
  11. package/app/dist/index.node.esm.js.map +1 -1
  12. package/app/dist/index.node.js +1 -1
  13. package/app/dist/index.node.js.map +1 -1
  14. package/auth/dist/index.esm.js +1 -1
  15. package/auth/dist/index.esm.js.map +1 -1
  16. package/auth/dist/index.js +1 -1
  17. package/auth/dist/index.js.map +1 -1
  18. package/core.d.ts +4331 -0
  19. package/core.node.d.ts +294 -0
  20. package/dist/index.cjs.js +1 -1
  21. package/dist/index.cjs.js.map +1 -1
  22. package/dist/index.esm.js +1 -1
  23. package/dist/index.esm.js.map +1 -1
  24. package/dist/index.node.cjs.js +1 -1
  25. package/dist/index.node.cjs.js.map +1 -1
  26. package/dist/index.node.esm.js +1 -1
  27. package/dist/index.node.esm.js.map +1 -1
  28. package/index.d.ts +5 -4268
  29. package/index.node.d.ts +13 -0
  30. package/miniprogram_dist/ai/index.d.ts +42 -0
  31. package/miniprogram_dist/ai/index.js +2 -0
  32. package/miniprogram_dist/apis/index.d.ts +5 -0
  33. package/miniprogram_dist/{apis.js → apis/index.js} +1 -1
  34. package/miniprogram_dist/app/index.d.ts +67 -0
  35. package/miniprogram_dist/app/index.js +2 -0
  36. package/miniprogram_dist/auth/index.d.ts +284 -0
  37. package/miniprogram_dist/auth/index.js +2 -0
  38. package/miniprogram_dist/cloudrun/index.d.ts +4 -0
  39. package/miniprogram_dist/cloudrun/index.js +1 -0
  40. package/miniprogram_dist/container/index.d.ts +13 -0
  41. package/miniprogram_dist/container/index.js +1 -0
  42. package/miniprogram_dist/database/index.d.ts +3 -0
  43. package/miniprogram_dist/functions/index.d.ts +2 -0
  44. package/miniprogram_dist/functions/index.js +1 -0
  45. package/miniprogram_dist/index.js +1 -1
  46. package/miniprogram_dist/model/index.d.ts +5 -0
  47. package/miniprogram_dist/model/index.js +1 -0
  48. package/miniprogram_dist/mysql/index.d.ts +3 -0
  49. package/miniprogram_dist/mysql/index.js +1 -0
  50. package/miniprogram_dist/oauth/index.d.ts +22 -0
  51. package/miniprogram_dist/oauth/index.js +2 -0
  52. package/miniprogram_dist/realtime/index.d.ts +2 -0
  53. package/miniprogram_dist/realtime/index.js +1 -0
  54. package/miniprogram_dist/storage/index.d.ts +13 -0
  55. package/miniprogram_dist/{storage.js → storage/index.js} +1 -1
  56. package/oauth/dist/index.esm.js +1 -1
  57. package/oauth/dist/index.esm.js.map +1 -1
  58. package/oauth/dist/index.js +1 -1
  59. package/oauth/dist/index.js.map +1 -1
  60. package/package.json +6 -2
  61. package/types/package.json +1 -1
  62. package/utilities/package.json +2 -2
  63. package/dist/index.d.ts +0 -9
  64. package/miniprogram_dist/ai.js +0 -2
  65. package/miniprogram_dist/app.js +0 -2
  66. package/miniprogram_dist/auth.js +0 -2
  67. package/miniprogram_dist/cloudrun.js +0 -1
  68. package/miniprogram_dist/container.js +0 -1
  69. package/miniprogram_dist/functions.js +0 -1
  70. package/miniprogram_dist/model.js +0 -1
  71. package/miniprogram_dist/mysql.js +0 -1
  72. package/miniprogram_dist/oauth.js +0 -2
  73. package/miniprogram_dist/realtime.js +0 -1
  74. /package/miniprogram_dist/{database.js → database/index.js} +0 -0
package/core.d.ts ADDED
@@ -0,0 +1,4331 @@
1
+ /**
2
+ * 共享类型定义(Web + Node.js 通用),以 ambient 形式声明。
3
+ *
4
+ * 说明:本文件不能出现顶层 `import` / `export` 语句,否则会变成模块而无法作为
5
+ * 全局 ambient 命名空间被 `index.d.ts` / `index.node.d.ts` 通过三斜线引用聚合。
6
+ * 因此所有外部依赖类型均以内联 `import('...')` 类型别名的形式声明在命名空间内部,
7
+ * 既避免污染全局作用域,又不会让本文件变成模块。
8
+ */
9
+ declare namespace cloudbase {
10
+ type KV<T> = {
11
+ [key: string]: T
12
+ }
13
+
14
+ type ExcludeOf<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>
15
+
16
+ type MethodType = 'request' | 'post' | 'get' | 'head' | 'patch' | 'delete' | 'put'
17
+
18
+ interface ICallApiOptions {
19
+ /** 请求的path */
20
+ path?: string
21
+ /** 请求方法 */
22
+ method?: MethodType
23
+ /** 请求头 */
24
+ headers?: KV<any>
25
+ /** 请求体,根据content-type可以是不同类型 */
26
+ body?: KV<any> | string
27
+ /** 可传token,如果没有传值,则默认用当前登录的token */
28
+ token?: string
29
+ }
30
+
31
+ interface ICloudbaseApis {
32
+ [apiName: string]: {
33
+ [method in MethodType]: (callApiOptions: ICallApiOptions, opts?: KV<any>) => Promise<ResponseObject['data']>
34
+ }
35
+ }
36
+
37
+ // ===== 外部依赖类型别名(内联 import 类型,避免顶层 import 使本文件成为模块)=====
38
+ type OrmClient = import('@cloudbase/model').OrmClient
39
+ type OrmRawQueryClient = import('@cloudbase/model').OrmRawQueryClient
40
+ type IMySqlClient = import('@cloudbase/mysql').IMySqlClient
41
+ type AI = import('@cloudbase/ai').AI
42
+ type CloudbaseAdapter = import('@cloudbase/adapter-interface').CloudbaseAdapter
43
+ type ResponseObject = import('@cloudbase/adapter-interface').ResponseObject
44
+ type ICloudbaseUpgradedConfig = import('@cloudbase/types').ICloudbaseUpgradedConfig
45
+ type ICloudbase = import('@cloudbase/types').ICloudbase
46
+ type Persistence = import('@cloudbase/types').Persistence
47
+ type LANGS = import('@cloudbase/types').LANGS
48
+ type ICustomReqOpts = import('@cloudbase/types/functions').ICustomReqOpts
49
+
50
+ // ===== @cloudbase/auth 相关类型别名 =====
51
+ type SignInRes = import('@cloudbase/auth').SignInRes
52
+ type GetUserRes = import('@cloudbase/auth').GetUserRes
53
+ type CommonRes = import('@cloudbase/auth').CommonRes
54
+ type SignInWithOtpRes = import('@cloudbase/auth').SignInWithOtpRes
55
+ type SignInOAuthRes = import('@cloudbase/auth').SignInOAuthRes
56
+ type GetClaimsRes = import('@cloudbase/auth').GetClaimsRes
57
+ type ResetPasswordForEmailRes = import('@cloudbase/auth').ResetPasswordForEmailRes
58
+ type GetUserIdentitiesRes = import('@cloudbase/auth').GetUserIdentitiesRes
59
+ type LinkIdentityRes = import('@cloudbase/auth').LinkIdentityRes
60
+ type ReauthenticateRes = import('@cloudbase/auth').ReauthenticateRes
61
+ type ResendRes = import('@cloudbase/auth').ResendRes
62
+ type UpdateUserWithVerificationRes = import('@cloudbase/auth').UpdateUserWithVerificationRes
63
+ type OnAuthStateChangeCallback = import('@cloudbase/auth').OnAuthStateChangeCallback
64
+ type SignInWithPasswordReq = import('@cloudbase/auth').SignInWithPasswordReq
65
+ type SignInWithIdTokenReq = import('@cloudbase/auth').SignInWithIdTokenReq
66
+ type SignInWithOAuthReq = import('@cloudbase/auth').SignInWithOAuthReq
67
+ type VerifyOAuthReq = import('@cloudbase/auth').VerifyOAuthReq
68
+ type VerifyOtpReq = import('@cloudbase/auth').VerifyOtpReq
69
+ type LinkIdentityReq = import('@cloudbase/auth').LinkIdentityReq
70
+ type UnlinkIdentityReq = import('@cloudbase/auth').UnlinkIdentityReq
71
+ type UpdateUserReq = import('@cloudbase/auth').UpdateUserReq
72
+ type SignInWithOtpReq = import('@cloudbase/auth').SignInWithOtpReq
73
+ type ResetPasswordForOldReq = import('@cloudbase/auth').ResetPasswordForOldReq
74
+ type ResendReq = import('@cloudbase/auth').ResendReq
75
+ type SetSessionReq = import('@cloudbase/auth').SetSessionReq
76
+ type DeleteMeReq = import('@cloudbase/auth').DeleteMeReq
77
+ type SignUpRes = import('@cloudbase/auth').SignUpRes
78
+
79
+ // ===== @cloudbase/oauth authModels 命名空间别名 =====
80
+ namespace authModels {
81
+ type BindPhoneRequest = import('@cloudbase/oauth').authModels.BindPhoneRequest
82
+ type BindEmailRequest = import('@cloudbase/oauth').authModels.BindEmailRequest
83
+ type UnbindProviderRequest = import('@cloudbase/oauth').authModels.UnbindProviderRequest
84
+ type VerifyRequest = import('@cloudbase/oauth').authModels.VerifyRequest
85
+ type VerifyResponse = import('@cloudbase/oauth').authModels.VerifyResponse
86
+ type GetVerificationRequest = import('@cloudbase/oauth').authModels.GetVerificationRequest
87
+ type GetVerificationResponse = import('@cloudbase/oauth').authModels.GetVerificationResponse
88
+ type GetCustomSignTicketFn = import('@cloudbase/oauth').authModels.GetCustomSignTicketFn
89
+ type SetPasswordRequest = import('@cloudbase/oauth').authModels.SetPasswordRequest
90
+ type ModifyUserBasicInfoRequest = import('@cloudbase/oauth').authModels.ModifyUserBasicInfoRequest
91
+ type BindWithProviderRequest = import('@cloudbase/oauth').authModels.BindWithProviderRequest
92
+ type QueryUserProfileRequest = import('@cloudbase/oauth').authModels.QueryUserProfileRequest
93
+ type QueryUserProfileResponse = import('@cloudbase/oauth').authModels.QueryUserProfileResponse
94
+ type GrantProviderTokenRequest = import('@cloudbase/oauth').authModels.GrantProviderTokenRequest
95
+ type GrantProviderTokenResponse = import('@cloudbase/oauth').authModels.GrantProviderTokenResponse
96
+ type PatchProviderTokenRequest = import('@cloudbase/oauth').authModels.PatchProviderTokenRequest
97
+ type PatchProviderTokenResponse = import('@cloudbase/oauth').authModels.PatchProviderTokenResponse
98
+ type SignInWithProviderRequest = import('@cloudbase/oauth').authModels.SignInWithProviderRequest
99
+ type GrantTokenRequest = import('@cloudbase/oauth').authModels.GrantTokenRequest
100
+ type GenProviderRedirectUriRequest = import('@cloudbase/oauth').authModels.GenProviderRedirectUriRequest
101
+ type GenProviderRedirectUriResponse = import('@cloudbase/oauth').authModels.GenProviderRedirectUriResponse
102
+ type ResetPasswordRequest = import('@cloudbase/oauth').authModels.ResetPasswordRequest
103
+ type DeviceAuthorizeRequest = import('@cloudbase/oauth').authModels.DeviceAuthorizeRequest
104
+ type DeviceAuthorizeResponse = import('@cloudbase/oauth').authModels.DeviceAuthorizeResponse
105
+ type SudoRequest = import('@cloudbase/oauth').authModels.SudoRequest
106
+ type SudoResponse = import('@cloudbase/oauth').authModels.SudoResponse
107
+ type WithSudoRequest = import('@cloudbase/oauth').authModels.WithSudoRequest
108
+ type UserProfile = import('@cloudbase/oauth').authModels.UserProfile
109
+ type UserProfileProvider = import('@cloudbase/oauth').authModels.UserProfileProvider
110
+ type Credentials = import('@cloudbase/oauth').authModels.Credentials
111
+ type ProviderSubType = import('@cloudbase/oauth').authModels.ProviderSubType
112
+ type ModifyPasswordWithoutLoginRequest = import('@cloudbase/oauth').authModels.ModifyPasswordWithoutLoginRequest
113
+ type GetUserBehaviorLog = import('@cloudbase/oauth').authModels.GetUserBehaviorLog
114
+ type GetUserBehaviorLogRes = import('@cloudbase/oauth').authModels.GetUserBehaviorLogRes
115
+ type GetMiniProgramQrCodeRequest = import('@cloudbase/oauth').authModels.GetMiniProgramQrCodeRequest
116
+ type GetMiniProgramQrCodeResponse = import('@cloudbase/oauth').authModels.GetMiniProgramQrCodeResponse
117
+ type GetMiniProgramQrCodeStatusRequest = import('@cloudbase/oauth').authModels.GetMiniProgramQrCodeStatusRequest
118
+ type GetMiniProgramQrCodeStatusResponse = import('@cloudbase/oauth').authModels.GetMiniProgramQrCodeStatusResponse
119
+ type ToDefaultLoginPage = import('@cloudbase/oauth').authModels.ToDefaultLoginPage
120
+ type SignoutRequest = import('@cloudbase/oauth').authModels.SignoutRequest
121
+ type SignoutResponse = import('@cloudbase/oauth').authModels.SignoutResponse
122
+ type SignInRequest = import('@cloudbase/oauth').authModels.SignInRequest
123
+ type SignUpRequest = import('@cloudbase/oauth').authModels.SignUpRequest
124
+ }
125
+ interface SimpleStorage {
126
+ getItem: (key: string) => Promise<string | null>
127
+ removeItem: (key: string) => Promise<void>
128
+ setItem: (key: string, value: string) => Promise<void>
129
+ getItemSync: (key: string) => string | null
130
+ removeItemSync: (key: string) => void
131
+ setItemSync: (key: string, value: string) => void
132
+ }
133
+
134
+ interface ICloudbaseConfig {
135
+ /** 是否国际站标记 */
136
+ intl?: boolean
137
+ /** 环境 ID,在腾讯云开发控制台 → 环境 → 环境总览中获取 */
138
+ env?: string
139
+ /**
140
+ * 地域信息
141
+ * @example 'ap-shanghai'
142
+ */
143
+ region?: string
144
+ /** 网络请求超时上限,单位 ms,默认 15000 */
145
+ timeout?: number
146
+ /** 本地登录态保留期限 */
147
+ persistence?: Persistence
148
+ oauthClient?: any
149
+ /** 是否开启调试模式 */
150
+ debug?: boolean
151
+ _fromApp?: ICloudbase
152
+ clientId?: string
153
+ oauthInstance?: any
154
+ wxCloud?: any
155
+ i18n?: {
156
+ t: (text: string) => string
157
+ LANG_HEADER_KEY: string
158
+ lang: LANGS
159
+ }
160
+ accessKey?: string
161
+ endPointMode?: EndPointKey
162
+ lang?: LANGS
163
+ /**
164
+ * 认证相关配置
165
+ * @example
166
+ * ```typescript
167
+ * cloudbase.init({
168
+ * env: 'your-env-id',
169
+ * auth: {
170
+ * detectSessionInUrl: true // 自动检测 URL 中的 OAuth 回调参数
171
+ * }
172
+ * })
173
+ * ```
174
+ */
175
+ auth?: ICloudbaseAuthConfig
176
+ }
177
+
178
+ /**
179
+ * 认证相关配置(Web 通用部分)。
180
+ * Node.js 专属字段(secretId / secretKey / sessionToken / secretType)
181
+ * 通过 core.node.d.ts 的声明合并追加,仅在 Node.js 入口可见。
182
+ */
183
+ interface ICloudbaseAuthConfig {
184
+ /** 是否自动检测 URL 中的 OAuth 回调参数,默认 false */
185
+ detectSessionInUrl?: boolean
186
+ }
187
+
188
+ interface ICloudbaseExtension {
189
+ name: string
190
+ invoke(opts: any, app: ICloudbase): Promise<any>
191
+ }
192
+
193
+ interface Listeners {
194
+ [key: string]: Function[]
195
+ }
196
+
197
+ interface ICloudbaseEvent {
198
+ name: string
199
+ target: any
200
+ data: any
201
+ }
202
+
203
+ interface ICloudbaseEventEmitter {
204
+ on(name: string, listener: Function): this
205
+ off(name: string, listener: Function): this
206
+ fire(event: string | ICloudbaseEvent, data?: any): this
207
+ }
208
+
209
+ interface ICloudbaseComponent {
210
+ name: string
211
+ entity: any
212
+ namespace?: string
213
+ injectEvents?: {
214
+ bus: ICloudbaseEventEmitter
215
+ events: string[]
216
+ }
217
+ IIFE?: boolean
218
+ }
219
+
220
+ interface ICloudbaseHook {
221
+ entity: any
222
+ target: string
223
+ }
224
+
225
+ type EndPointKey = 'CLOUD_API' | 'GATEWAY'
226
+
227
+ interface ISetEndPointWithKey {
228
+ key: EndPointKey
229
+ url?: string
230
+ protocol?: 'http' | 'https'
231
+ }
232
+
233
+ /**
234
+ * 初始化Cloudbase
235
+ *
236
+ * @example
237
+ * ```javascript
238
+ * // 基本用法
239
+ * const app = cloudbase.init({
240
+ * env: 'your-envid',
241
+ * timeout: 15000
242
+ * });
243
+ *
244
+ * // 推荐:从环境变量读取环境 ID
245
+ * const app = cloudbase.init({
246
+ * env: process.env.CLOUDBASE_ENV || import.meta.env.VITE_CLOUDBASE_ENV || 'your-envid'
247
+ * });
248
+ *
249
+ * // 使用认证配置
250
+ * const app = cloudbase.init({
251
+ * env: 'your-envid',
252
+ * auth: {
253
+ * detectSessionInUrl: true // 自动检测 URL 中的 OAuth 回调参数
254
+ * }
255
+ * });
256
+ * ```
257
+ *
258
+ * @param config 初始化配置
259
+ * @param config.env 环境ID,在腾讯云开发控制台 → 环境 → 环境总览中获取
260
+ * @param config.timeout 【可选】网络请求超时上限,单位`ms`,默认值`15000`
261
+ * @param config.auth 【可选】认证相关配置
262
+ *
263
+ * @return {!cloudbase.app.App} 初始化成功的Cloudbase实例
264
+ */
265
+ function init(config?: ICloudbaseConfig): cloudbase.app.App
266
+
267
+ /**
268
+ * 检查 Cloudbase 实例是否已完成初始化
269
+ *
270
+ * @example
271
+ * ```javascript
272
+ * if (!cloudbase.isInitialized()) {
273
+ * cloudbase.init({ env: 'your-envid' });
274
+ * }
275
+ * ```
276
+ *
277
+ * @returns 是否已初始化
278
+ */
279
+ function isInitialized(): boolean
280
+
281
+ function updateConfig(config: ICloudbaseUpgradedConfig): void
282
+
283
+ function updateLang(lang: LANGS): void
284
+ /**
285
+ * 使用适配器,使用方式参考 {@link https://docs.cloudbase.net/api-reference/webv3/adapter#%E7%AC%AC-1-%E6%AD%A5%E5%AE%89%E8%A3%85%E5%B9%B6%E5%BC%95%E5%85%A5%E9%80%82%E9%85%8D%E5%99%A8}
286
+ *
287
+ * @example
288
+ * ```javascript
289
+ * cloudbase.useAdapters(adapter); // 使用单个适配器
290
+ * cloudbase.useAdapters([ // 使用多个适配器
291
+ * adapterA,
292
+ * adapterB
293
+ * ]);
294
+ * ```
295
+ *
296
+ * @param adapters 适配器对象,入参可以为单个适配器对象,也可以是多个适配器对象的数组
297
+ * @param options 适配器参数,可以在genAdapter中获取到该参数
298
+ */
299
+ function useAdapters(adapters: CloudbaseAdapter | CloudbaseAdapter[], options?: any): void
300
+ /**
301
+ * 注册扩展能力插件,使用方式参考 {@link https://docs.cloudbase.net/extension/abilities/image-examination.html#shi-yong-kuo-zhan}
302
+ *
303
+ * @example
304
+ * ```javascript
305
+ * cloudbase.registerExtension(ext);
306
+ * ```
307
+ *
308
+ * @param ext 扩展能力插件对象
309
+ */
310
+ function registerExtension(ext: ICloudbaseExtension): void
311
+ /**
312
+ * 【谨慎操作】注册SDK的版本
313
+ *
314
+ * @example
315
+ * ```javascript
316
+ * cloudbase.registerVersion('1.2.1');
317
+ * ```
318
+ *
319
+ * @param version SDK版本
320
+ */
321
+ function registerVersion(version: string): void
322
+ /**
323
+ * 【谨慎操作】注册SDK的名称
324
+ *
325
+ * @example
326
+ * ```javascript
327
+ * cloudbase.registerSdkName('cloudbase-js-sdk');
328
+ * ```
329
+ *
330
+ * @param name SDK名称
331
+ */
332
+ function registerSdkName(name: string): void
333
+ /**
334
+ * 【谨慎操作】修改SDK请求的云开发服务地址
335
+ *
336
+ * @example
337
+ * ```javascript
338
+ * cloudbase.registerEndPoint('url','https');
339
+ * ```
340
+ *
341
+ * @param url 服务地址
342
+ * @param protocol 【可选】强制使用某种协议,默认与主站协议一致
343
+ */
344
+ function registerEndPoint(url: string, protocol?: 'http' | 'https'): void
345
+ /**
346
+ * 【谨慎操作】修改SDK请求的「云开发/网关」服务地址
347
+ *
348
+ * @example
349
+ * ```javascript
350
+ * cloudbase.registerEndPointWithKey({
351
+ * key: "GATEWAY",
352
+ * url: "",
353
+ * protocol: ""
354
+ * });
355
+ * ```
356
+ *
357
+ */
358
+ function registerEndPointWithKey(props: ISetEndPointWithKey): void
359
+ /**
360
+ * 一次性设置所有端点,只需传入 host 地址,自动拼接路径
361
+ * @param host - 主机地址,如 "43.144.98.4" 或 "//43.144.98.4"
362
+ * @param protocol - 协议,默认 "http"
363
+ */
364
+ function registerHost(host: string, protocol?: 'http' | 'https'): void
365
+ /**
366
+ * 【谨慎操作】注册功能模块
367
+ *
368
+ * @example
369
+ * ```javascript
370
+ * cloudbase.registerComponent({});
371
+ * ```
372
+ *
373
+ * @param component 功能模块对象
374
+ */
375
+ function registerComponent(component: ICloudbaseComponent): void
376
+ /**
377
+ * 【谨慎操作】注册hook
378
+ *
379
+ * @example
380
+ * ```javascript
381
+ * cloudbase.registerHook({});
382
+ * ```
383
+ *
384
+ * @param hook hook对象
385
+ */
386
+ function registerHook(hook: ICloudbaseHook): void
387
+
388
+ export interface models extends OrmClient, OrmRawQueryClient {}
389
+ }
390
+ /**
391
+ * instance
392
+ */
393
+ declare namespace cloudbase.app {
394
+ interface App {
395
+ /**
396
+ * 创建Auth对象
397
+ *
398
+ * {@link https://docs.cloudbase.net/api-reference/webv3/authentication#appauth}
399
+ *
400
+ * @example
401
+ * ```javascript
402
+ * const app = cloudbase.init({
403
+ * env: 'your-envid'
404
+ * });
405
+ * const auth = app.auth({
406
+ * persistence: 'local'
407
+ * });
408
+ * ```
409
+ *
410
+ * @param options Auth初始化配置
411
+ * @param options.persistence 本地登录态保留期限
412
+ *
413
+ * @return {!cloudbase.auth.App} Auth实例
414
+ */
415
+ auth: ((options?: { persistence: cloudbase.auth.Persistence }) => cloudbase.auth.App) & cloudbase.auth.App
416
+ /**
417
+ * 调用云函数
418
+ *
419
+ * {@link https://docs.cloudbase.net/api-reference/webv3/functions#callfunction}
420
+ *
421
+ * @example
422
+ * ```javascript
423
+ * const app = cloudbase.init({
424
+ * env: 'your-envid'
425
+ * });
426
+ * app.callFunction({
427
+ * name: 'function-name'
428
+ * data: {
429
+ * a: 1,
430
+ * b: 2
431
+ * }
432
+ * }).then(res=>{
433
+ * console.log(res.result);
434
+ * }});
435
+ * ```
436
+ *
437
+ * @param options 被调用的云函数信息
438
+ * @param options.name 云函数的名称
439
+ * @param options.data 【可选】云函数的参数,默认为空
440
+ * @param options.parse 【可选】设置为 `true` 时,当函数返回值为对象时,API 请求会返回解析对象,而不是 JSON 字符串,默认为`false`
441
+ *
442
+ * @return Promise-函数执行结果
443
+ */
444
+ callFunction(
445
+ options: cloudbase.functions.ICallFunctionOptions,
446
+ callback?: Function,
447
+ customReqOpts?: ICustomReqOpts,
448
+ ): Promise<cloudbase.functions.ICallFunctionResponse>
449
+ /**
450
+ * 调用云托管
451
+ *
452
+ * {@link https://docs.cloudbase.net/api-reference/webv3/cloudrun}
453
+ *
454
+ * @example
455
+ * ```javascript
456
+ * const app = cloudbase.init({
457
+ * env: 'your-envid'
458
+ * });
459
+ * app
460
+ * .callContainer({
461
+ * name: 'helloworld',
462
+ * method: 'POST',
463
+ * path: '/abc',
464
+ * header:{
465
+ * 'Content-Type': 'application/json; charset=utf-8'
466
+ * },
467
+ * data: {
468
+ * key1: 'test value 1',
469
+ * key2: 'test value 2'
470
+ * },
471
+ * })
472
+ * .then((res) => {
473
+ * console.log(res)
474
+ * });
475
+ * ```
476
+ *
477
+ * @param options 被调用的云托管信息
478
+ * @param options.name 云托管的名称
479
+ * @param options.data 【可选】云托管的参数,默认为空
480
+ *
481
+ * @return Promise-云托管执行结果
482
+ */
483
+ callContainer(
484
+ options: cloudbase.functions.ICallFunctionOptions,
485
+ customReqOpts?: ICustomReqOpts,
486
+ ): Promise<ResponseObject>
487
+ /**
488
+ * 云存储-上传文件
489
+ *
490
+ * {@link https://docs.cloudbase.net/api-reference/webv3/storage#uploadfile}
491
+ *
492
+ * @example
493
+ * ```javascript
494
+ * const app = cloudbase.init({
495
+ * env: 'your-envid'
496
+ * });
497
+ * app.uploadFile({
498
+ * cloudPath: 'cloudPath',
499
+ * filePath: 'filePath',
500
+ * method: 'put',
501
+ * headers: {
502
+ * 'Content-MD5': 'xxxxxx'
503
+ * }
504
+ * onUploadProgress: function(event){}
505
+ * });
506
+ * ```
507
+ *
508
+ * @param params
509
+ * @param params.cloudPath 文件上传到云端后的绝对路径,包含文件名
510
+ * @param params.filePath 被上传的文件对象
511
+ * @param params.method 上传方法,默认为 put
512
+ * @param params.headers 自定义头部字段
513
+ * @param params.onUploadProgress 【可选】上传进度回调函数
514
+ *
515
+ * @return Promise-上传结果
516
+ *
517
+ * @deprecated 传统云存储 API 已不推荐使用,请改用 `app.storage.from().upload()`。
518
+ */
519
+ uploadFile(
520
+ params: cloudbase.storage.ICloudbaseUploadFileParams,
521
+ callback?: Function,
522
+ ): Promise<cloudbase.storage.ICloudbaseUploadFileResult>
523
+ /**
524
+ * 云存储-下载文件
525
+ *
526
+ * {@link https://docs.cloudbase.net/api-reference/webv3/storage#downloadfile}
527
+ *
528
+ * @example
529
+ * ```javascript
530
+ * const app = cloudbase.init({
531
+ * env: 'your-envid'
532
+ * });
533
+ * app.downloadFile({
534
+ * fileID: 'cloudPath'
535
+ * });
536
+ * ```
537
+ *
538
+ * @param params
539
+ * @param params.fileID 要下载的文件的 `id`,在控制台云存储中查看
540
+ *
541
+ * @return Promise-下载结果
542
+ *
543
+ * @deprecated 传统云存储 API 已不推荐使用,请改用 `app.storage.from().download()`。
544
+ */
545
+ downloadFile(
546
+ params: cloudbase.storage.ICloudbaseDownloadFileParams,
547
+ callback?: Function,
548
+ ): Promise<cloudbase.storage.ICloudbaseDownloadFileResult>
549
+ /**
550
+ * 云存储-批量复制文件
551
+ *
552
+ *
553
+ * @example
554
+ * ```javascript
555
+ * const app = cloudbase.init({
556
+ * env: 'your-envid'
557
+ * });
558
+ * app.copyFile({
559
+ * fileList: [
560
+ * {
561
+ * srcPath: '源文件的绝对路径,包含文件名。例如 foo/bar.jpg、foo/bar/baz.jpg 等,不能包含除[0-9 , a-z , A-Z]、/、!、-、_、.、、*和中文以外的字符,使用 / 字符来实现类似传统文件系统的层级结构',
562
+ * dstPath: '目标文件的绝对路径,包含文件名。例如 foo/bar.jpg、foo/bar/baz.jpg 等,不能包含除[0-9 , a-z , A-Z]、/、!、-、_、.、、*和中文以外的字符,使用 / 字符来实现类似传统文件系统的层级结构',
563
+ * overwrite: '当目标文件已经存在时,是否允许覆盖已有文件,默认 true',
564
+ * removeOriginal: '复制文件后是否删除源文件,默认 false'
565
+ * }
566
+ * ]
567
+ * });
568
+ * ```
569
+ *
570
+ * @param params
571
+ * @param params.fileList 要复制的文件信息组成的数组
572
+ *
573
+ * @return Promise-复制结果
574
+ *
575
+ * @deprecated 传统云存储 API 已不推荐使用,请改用 `app.storage.from().copy()`。
576
+ */
577
+ copyFile(
578
+ params: cloudbase.storage.ICloudbaseCopyFileParams,
579
+ callback?: Function,
580
+ ): Promise<cloudbase.storage.ICloudbaseCopyFileResult>
581
+ /**
582
+ * 云存储-获取文件的下载链接
583
+ *
584
+ * {@link https://docs.cloudbase.net/api-reference/webv3/storage#gettempfileurl}
585
+ *
586
+ * @example
587
+ * ```javascript
588
+ * const app = cloudbase.init({
589
+ * env: 'your-envid'
590
+ * });
591
+ * app.getTempFileURL({
592
+ * fileList: [
593
+ * '文件A的fileID',
594
+ * {
595
+ * fileID: '文件B的fileID',
596
+ * maxAge: 600 // 文件B的链接有效期,单位`ms`
597
+ * }
598
+ * ]
599
+ * });
600
+ * ```
601
+ *
602
+ * @param params
603
+ * @param params.fileList 要下载的文件数组,数组元素可以是`string`或`Object`,如果是`string`代表文件ID,如果是`Object`可配置以下信息
604
+ * @param params.fileList[].fileID 要下载的文件ID
605
+ * @param params.fileList[].maxAge 下载链接的有效期,单位`ms`
606
+ *
607
+ * @return Promise-文件下载链接
608
+ *
609
+ * @deprecated 传统云存储 API 已不推荐使用,请改用 `app.storage.from().createSignedUrl()`。
610
+ */
611
+ getTempFileURL(
612
+ params: cloudbase.storage.ICloudbaseGetTempFileURLParams,
613
+ callback?: Function,
614
+ ): Promise<cloudbase.storage.ICloudbaseGetTempFileURLResult>
615
+ /**
616
+ * 云存储-删除文件
617
+ *
618
+ * {@link https://docs.cloudbase.net/api-reference/webv3/storage#deletefile}
619
+ *
620
+ * @example
621
+ * ```javascript
622
+ * const app = cloudbase.init({
623
+ * env: 'your-envid'
624
+ * });
625
+ * app.deleteFile({
626
+ * fileList: [
627
+ * '文件A的fileID',
628
+ * '文件B的fileID'
629
+ * ]
630
+ * });
631
+ * ```
632
+ *
633
+ * @param params
634
+ * @param params.fileList 要删除的文件ID数组
635
+ *
636
+ * @return Promise-删除结果
637
+ *
638
+ * @deprecated 传统云存储 API 已不推荐使用,请改用 `app.storage.from().remove()`。
639
+ */
640
+ deleteFile(
641
+ params: cloudbase.storage.ICloudbaseDeleteFileParams,
642
+ callback?: Function,
643
+ ): Promise<cloudbase.storage.ICloudbaseDeleteFileResult>
644
+
645
+ /**
646
+ * 云存储-获取文件信息
647
+ *
648
+ * @deprecated 传统云存储 API 已不推荐使用,请改用 `app.storage.from().info()`。
649
+ */
650
+ getFileInfo(
651
+ params: cloudbase.storage.ICloudbaseGetTempFileURLParams,
652
+ ): Promise<cloudbase.storage.ICloudbaseGetFileInfoResult>
653
+ /**
654
+ * 云存储-获取上传元信息
655
+ *
656
+ *
657
+ * @param params
658
+ * @param callback
659
+ *
660
+ * @deprecated 传统云存储 API 已不推荐使用,请改用 `app.storage.from().createSignedUploadUrl()`。
661
+ */
662
+ getUploadMetadata(params: cloudbase.storage.ICloudbaseGetUploadMetadataParams, callback?: Function): Promise<any>
663
+
664
+ /**
665
+ * Supabase 风格的文件存储 API
666
+ *
667
+ * @example
668
+ * ```typescript
669
+ * const bucket = app.storage.from('my-bucket')
670
+ * const { data, error } = await bucket.upload('path/to/file.jpg', file)
671
+ * ```
672
+ */
673
+ storage: cloudbase.storage.StorageClient
674
+ /**
675
+ * 获取数据库实例
676
+ *
677
+ * {@link https://docs.cloudbase.net/api-reference/webv3-next/database#%E8%8E%B7%E5%8F%96%E6%95%B0%E6%8D%AE%E5%BA%93%E5%AE%9E%E4%BE%8B}
678
+ *
679
+ * @example
680
+ * ```javascript
681
+ * const app = cloudbase.init({
682
+ * env: 'your-envid'
683
+ * });
684
+ * const db = app.database();
685
+ * ```
686
+ *
687
+ * @return 数据库实例
688
+ */
689
+ database(dbConfig?: { instance?: string; database?: string }): cloudbase.database.App
690
+ /**
691
+ * 调用扩展能力插件功能
692
+ *
693
+ * @example
694
+ * ```javascript
695
+ * const app = cloudbase.init({
696
+ * env: 'your-envid'
697
+ * });
698
+ * // 调用前需要先注册
699
+ * app.registerExtension(ext);
700
+ *
701
+ * app.invokeExtension('扩展能力插件名称',{
702
+ * // ...扩展能力插件的入参
703
+ * });
704
+ * ```
705
+ *
706
+ * @param name 扩展能力插件的名称
707
+ * @param opts 【可选】扩展能力插件的参数,根据插件具体需求而定
708
+ *
709
+ * @return Promise-扩展能力插件执行结果
710
+ */
711
+ invokeExtension(name: string, opts: any): Promise<any>
712
+
713
+ eventBus: any
714
+
715
+ /**
716
+ * 调用 数据模型 SDK
717
+ *
718
+ * {@link https://docs.cloudbase.net/model/sdk-reference/model}
719
+ * @example
720
+ * ```javascript
721
+ models.<model_name>.create() // 创建单条数据
722
+ models.<model_name>.createMany() // 创建多条数据
723
+ models.<model_name>.update() // 更新单条数据
724
+ models.<model_name>.updateMany() // 更新多条数据
725
+ models.<model_name>.delete() // 删除单条数据
726
+ models.<model_name>.deleteMany() // 删除多条数据
727
+ models.<model_name>.get() // 查询单条数据
728
+ models.<model_name>.list() // 查询多条数据
729
+ models.$runSQL() // 执行原生 SQL 语句
730
+ * ```
731
+ */
732
+ models: OrmClient & OrmRawQueryClient
733
+
734
+ /**
735
+ * MySQL 数据库
736
+ *
737
+ * @example
738
+ * ```javascript
739
+ * const app = cloudbase.init({
740
+ * env: "xxxx-yyy"
741
+ * });
742
+ *
743
+ * app.mysql().from('todos').select().then((res) => {
744
+ * console.log(res.data);
745
+ * });
746
+ * ```
747
+ */
748
+ mysql: IMySqlClient
749
+ rdb: IMySqlClient
750
+
751
+ ai(options?: { baseUrl?: string }): AI
752
+
753
+ apis: ICloudbaseApis
754
+
755
+ /**
756
+ * 一次性设置所有端点,只需传入 host 地址,自动拼接路径
757
+ * @param host - 主机地址,如 "43.144.98.4" 或 "//43.144.98.4"
758
+ * @param protocol - 协议,默认 "http"
759
+ */
760
+ registerHost(host: string, protocol?: 'http' | 'https'): void
761
+
762
+ /**
763
+ * 获取指定类型的端点信息
764
+ * @param key - 端点类型
765
+ */
766
+ getEndPointWithKey(key: cloudbase.EndPointKey): { BASE_URL: string; PROTOCOL: string }
767
+
768
+ /**
769
+ * 修改SDK请求的云开发服务地址
770
+ * @param url 服务地址
771
+ * @param protocol 【可选】强制使用某种协议,默认与主站协议一致
772
+ */
773
+ registerEndPoint(url: string, protocol?: 'http' | 'https'): void
774
+
775
+ /**
776
+ * 修改SDK请求的「云开发/网关」服务地址,通过 key 指定
777
+ */
778
+ registerEndPointWithKey(props: cloudbase.ISetEndPointWithKey): void
779
+
780
+ /**
781
+ * 解析验证码 URL 参数
782
+ */
783
+ parseCaptcha(url: string): any
784
+ }
785
+ }
786
+ /**
787
+ * auth
788
+ */
789
+ declare namespace cloudbase.auth {
790
+ type Persistence = 'local' | 'session' | 'none'
791
+
792
+ interface IAccessTokenInfo {
793
+ accessToken: string
794
+ env: string
795
+ }
796
+
797
+ interface ILoginState {
798
+ /**
799
+ * 当前登录用户的信息
800
+ */
801
+ user: IUser
802
+ }
803
+
804
+ interface ICredential {
805
+ accessToken?: string
806
+ accessTokenExpire?: string
807
+ }
808
+
809
+ interface IAuthProvider {
810
+ signInWithRedirect: () => any
811
+ }
812
+
813
+ /**
814
+ * 用户信息
815
+ */
816
+ interface IUserInfo {
817
+ uid?: string
818
+ loginType?: string
819
+ openid?: string
820
+ wxOpenId?: string
821
+ wxPublicId?: string
822
+ unionId?: string
823
+ qqMiniOpenId?: string
824
+ customUserId?: string
825
+ name?: string
826
+ displayName?: string
827
+ gender?: string
828
+ email?: string
829
+ username?: string
830
+ hasPassword?: boolean
831
+ location?: {
832
+ country?: string
833
+ province?: string
834
+ city?: string
835
+ }
836
+ country?: string
837
+ province?: string
838
+ city?: string
839
+ }
840
+
841
+ interface IUser extends IUserInfo {
842
+ /**
843
+ * 更新用户信息
844
+ *
845
+ * {@link https://docs.cloudbase.net/api-reference/webv3/authentication#userupdate}
846
+ *
847
+ * @example
848
+ * ```javascript
849
+ * const app = cloudbase.init({
850
+ * env: "xxxx-yyy"
851
+ * });
852
+ * const auth = app.auth();
853
+ * const user = auth.currentUser;
854
+ * user.update({
855
+ * nickName: '新昵称'
856
+ * }).then(()=>{});
857
+ * ```
858
+ *
859
+ * @param userinfo 用户信息
860
+ *
861
+ * @return Promise
862
+ *
863
+ */
864
+ update(userinfo: IUserInfo): Promise<void>
865
+ /**
866
+ * 刷新本地用户信息
867
+ *
868
+ * {@link https://docs.cloudbase.net/api-reference/webv3/authentication#userrefresh}
869
+ *
870
+ * @example
871
+ * ```javascript
872
+ * const app = cloudbase.init({
873
+ * env: "xxxx-yyy"
874
+ * });
875
+ * const auth = app.auth();
876
+ * const user = auth.currentUser;
877
+ * user.refresh().then(()=>{});
878
+ * ```
879
+ *
880
+ * @return Promise-刷新后的用户信息
881
+ *
882
+ */
883
+ refresh(): Promise<IUserInfo>
884
+ /**
885
+ * 同步获取本地用户信息
886
+ */
887
+ checkLocalInfo: () => void
888
+ /**
889
+ * 异步获取本地用户信息
890
+ */
891
+ checkLocalInfoAsync: () => Promise<void>
892
+ linkWithTicket?: (ticket: string) => Promise<void>
893
+ linkWithRedirect?: (provider: IAuthProvider) => void
894
+ getLinkedUidList?: () => Promise<{ hasPrimaryUid: boolean; users: IUserInfo[] }>
895
+ setPrimaryUid?: (uid: string) => Promise<void>
896
+ unlink?: (loginType: 'CUSTOM' | 'WECHAT-OPEN' | 'WECHAT-PUBLIC' | 'WECHAT-UNION') => Promise<void>
897
+ }
898
+
899
+ interface App {
900
+ /**
901
+ * 获取当前登录的用户信息-同步操作
902
+ *
903
+ * {@link https://docs.cloudbase.net/api-reference/webv2/authentication#authhasloginstate}
904
+ *
905
+ * @example
906
+ * ```javascript
907
+ * const app = cloudbase.init({
908
+ * env: "xxxx-yyy"
909
+ * });
910
+ * const userInfo = app.auth().currentUser;
911
+ * ```
912
+ *
913
+ * @return 用户信息,如果未登录返回`null`
914
+ */
915
+ currentUser: IUser | null
916
+ /**
917
+ * 获取当前登录的用户信息-异步操作,文档 {@link https://docs.cloudbase.net/api-reference/webv2/authentication#authgetcurrentuser}
918
+ *
919
+ * @example
920
+ * ```javascript
921
+ * const app = cloudbase.init({
922
+ * env: "xxxx-yyy"
923
+ * });
924
+ * app.auth().getCurrentUser().then(userInfo=>{
925
+ * // ...
926
+ * });
927
+ * ```
928
+ *
929
+ * @return Promise-用户信息,如果未登录返回`null`
930
+ */
931
+ getCurrentUser(): Promise<IUser | null>
932
+ /**
933
+ * 绑定手机号码
934
+ *
935
+ * 文档 {@link https://docs.cloudbase.net/api-reference/webv2/authentication#authbindphonenumber}
936
+ *
937
+ * @param params
938
+ */
939
+ bindPhoneNumber(params: authModels.BindPhoneRequest): Promise<void>
940
+ /**
941
+ * 绑定邮箱
942
+ *
943
+ * 文档 {@link https://docs.cloudbase.net/api-reference/webv2/authentication#authbindemail}
944
+ *
945
+ * @param params
946
+ */
947
+ bindEmail(params: authModels.BindEmailRequest): Promise<void>
948
+ /**
949
+ * 解除三方绑定
950
+ *
951
+ * 文档 {@link https://docs.cloudbase.net/api-reference/webv2/authentication#authunbindprovider}
952
+ *
953
+ * @param params
954
+ */
955
+ unbindProvider(params: authModels.UnbindProviderRequest): Promise<void>
956
+
957
+ /**
958
+ * 验证码验证
959
+ *
960
+ * 文档 {@link https://docs.cloudbase.net/api-reference/webv2/authentication#authverify}
961
+ *
962
+ * @param params
963
+ */
964
+ verify(params: authModels.VerifyRequest): Promise<authModels.VerifyResponse>
965
+ /**
966
+ * 获取验证码
967
+ *
968
+ * 文档 {@link https://docs.cloudbase.net/api-reference/webv2/authentication#authgetverification}
969
+ *
970
+ * @param params
971
+ * @param options
972
+ */
973
+ getVerification(
974
+ params: authModels.GetVerificationRequest,
975
+ options?: { withCaptcha: boolean },
976
+ ): Promise<authModels.GetVerificationResponse>
977
+ /**
978
+ * 匿名登录。无需用户注册即可使用应用功能,适合游客模式、临时体验等场景。
979
+ *
980
+ * **前置条件**:需要在云开发控制台(环境 → 登录授权 → 身份源列表)开启「匿名登录」。
981
+ *
982
+ * **重要**:匿名登录必须在使用 `watch()` 等实时数据库功能**之前**完成,
983
+ * 否则 WebSocket 连接会因缺少认证信息而失败。
984
+ *
985
+ * 文档 {@link https://docs.cloudbase.net/api-reference/webv2/authentication#authsigninanonymously}
986
+ *
987
+ * @example
988
+ * ```typescript
989
+ * import Cloudbase from '@cloudbase/js-sdk';
990
+ *
991
+ * const app = Cloudbase.init({
992
+ * env: 'your-env-id',
993
+ * region: 'ap-shanghai'
994
+ * });
995
+ * const auth = app.auth();
996
+ *
997
+ * // 匿名登录
998
+ * const { data, error } = await auth.signInAnonymously();
999
+ * if (error) {
1000
+ * console.error('匿名登录失败:', error.message);
1001
+ * return;
1002
+ * }
1003
+ * console.log('匿名登录成功, 用户ID:', data.user.id);
1004
+ * console.log('是否匿名用户:', data.user.is_anonymous); // true
1005
+ *
1006
+ * // 登录成功后,即可使用 watch() 等实时功能
1007
+ * const db = app.database();
1008
+ * const listener = db.collection('rooms').where({ status: 'active' }).watch({
1009
+ * onChange: (snapshot) => {
1010
+ * console.log('数据变化:', snapshot.docs);
1011
+ * },
1012
+ * onError: (err) => {
1013
+ * console.error('监听错误:', err);
1014
+ * }
1015
+ * });
1016
+ *
1017
+ * // 不再需要时关闭监听
1018
+ * listener.close();
1019
+ * ```
1020
+ *
1021
+ * @param data 可选参数
1022
+ * @param data.provider_token 提供令牌(通常不需要手动传入)
1023
+ * @returns 登录结果,包含 `data.user`(用户信息)和 `data.session`(会话信息),
1024
+ * 或 `error`(登录失败时的错误信息)
1025
+ */
1026
+ signInAnonymously(data?: { provider_token?: string }): Promise<SignInRes>
1027
+ /**
1028
+ * 小程序匿名登录
1029
+ *
1030
+ * @param params
1031
+ */
1032
+ signInAnonymouslyInWx(params?: { useWxCloud?: boolean }): Promise<ILoginState>
1033
+ /**
1034
+ * 小程序绑定OpenID
1035
+ *
1036
+ * 文档 {@link https://docs.cloudbase.net/api-reference/webv2/authentication#authbindopenid}
1037
+ *
1038
+ */
1039
+ bindOpenId(): Promise<void>
1040
+ /**
1041
+ * 小程序unionId静默登录
1042
+ *
1043
+ * 文档 {@link https://docs.cloudbase.net/api-reference/webv2/authentication#authsigninwithunionid}
1044
+ *
1045
+ */
1046
+ signInWithUnionId(): Promise<ILoginState>
1047
+ /**
1048
+ * 短信验证码登录
1049
+ *
1050
+ * 文档 {@link https://docs.cloudbase.net/api-reference/webv2/authentication#authsigninwithsms}
1051
+ *
1052
+ * @param params
1053
+ */
1054
+ signInWithSms(params: {
1055
+ verificationInfo?: { verification_id: string; is_user: boolean }
1056
+ verificationCode?: string
1057
+ phoneNum?: string
1058
+ bindInfo?: any
1059
+ }): Promise<ILoginState>
1060
+ /**
1061
+ * 邮箱验证码登录
1062
+ *
1063
+ * 文档 {@link https://docs.cloudbase.net/api-reference/webv2/authentication#authsigninwithemail}
1064
+ *
1065
+ * @param params
1066
+ */
1067
+ signInWithEmail(params: {
1068
+ verificationInfo?: { verification_id: string; is_user: boolean }
1069
+ verificationCode?: string
1070
+ email?: string
1071
+ bindInfo?: any
1072
+ }): Promise<ILoginState>
1073
+ /**
1074
+ * 设置获取自定义登录 ticket 的函数
1075
+ *
1076
+ * 文档 {@link https://docs.cloudbase.net/api-reference/webv2/authentication#authsetcustomsignfunc}
1077
+ *
1078
+ *
1079
+ * @param getTickFn
1080
+ */
1081
+ setCustomSignFunc(getTickFn: authModels.GetCustomSignTicketFn): void
1082
+ /**
1083
+ * 设置密码(已登录状态下,更新用户密码)
1084
+ *
1085
+ * 文档 {@link https://docs.cloudbase.net/api-reference/webv2/authentication#authsetpassword}
1086
+ *
1087
+ */
1088
+ setPassword(params: authModels.SetPasswordRequest): Promise<void>
1089
+ /**
1090
+ * 获取用户信息
1091
+ * @deprecated 请使用 getCurrentUser 代替
1092
+ *
1093
+ * 文档 {@link https://docs.cloudbase.net/api-reference/webv2/authentication#authgetuserinfo}
1094
+ */
1095
+ getUserInfo(): Promise<IUserInfo>
1096
+ /**
1097
+ * 获取微搭插件用户信息
1098
+ *
1099
+ */
1100
+ getWedaUserInfo(): Promise<any>
1101
+ /**
1102
+ * 更新用户基本信息
1103
+ *
1104
+ * 文档 {@link https://docs.cloudbase.net/api-reference/webv2/authentication#authupdateuserbasicinfo}
1105
+ *
1106
+ * @param params
1107
+ */
1108
+ updateUserBasicInfo(params: authModels.ModifyUserBasicInfoRequest): Promise<void>
1109
+ /**
1110
+ * 获取本地登录态-同步操作
1111
+ *
1112
+ * {@link https://docs.cloudbase.net/api-reference/webv2/authentication#authhasloginstate}
1113
+ *
1114
+ * @example
1115
+ * ```javascript
1116
+ * const app = cloudbase.init({
1117
+ * env: "xxxx-yyy"
1118
+ * });
1119
+ * const loginState = app.auth().hasLoginState();
1120
+ * ```
1121
+ *
1122
+ * @return 登录态信息,如果未登录返回`null`
1123
+ */
1124
+ hasLoginState(): ILoginState | null
1125
+ /**
1126
+ * 获取本地登录态-异步操作
1127
+ *
1128
+ * {@link https://docs.cloudbase.net/api-reference/webv2/authentication.html#auth-getloginstate}
1129
+ *
1130
+ * @example
1131
+ * ```javascript
1132
+ * const app = cloudbase.init({
1133
+ * env: "xxxx-yyy"
1134
+ * });
1135
+ * app.auth().getLoginState().then(loginState=>{
1136
+ * // ...
1137
+ * });
1138
+ * ```
1139
+ *
1140
+ * @return Promise-登录态信息,如果未登录返回`null`
1141
+ */
1142
+ getLoginState(): Promise<ILoginState | null>
1143
+ /**
1144
+ * @deprecated
1145
+ */
1146
+ getAuthHeader(): {}
1147
+ /**
1148
+ * 为已有账户绑定第三方账户
1149
+ *
1150
+ * 文档 {@link https://docs.cloudbase.net/api-reference/webv2/authentication#authbindwithprovider}
1151
+ */
1152
+ bindWithProvider(params: authModels.BindWithProviderRequest): Promise<void>
1153
+ /**
1154
+ * 查询用户(自定义登录场景和匿名登录场景,不支持使用该接口查询用户信息)
1155
+ *
1156
+ * 文档 {@link https://docs.cloudbase.net/api-reference/webv2/authentication#authqueryuser}
1157
+ *
1158
+ */
1159
+ queryUser(queryObj: authModels.QueryUserProfileRequest): Promise<authModels.QueryUserProfileResponse>
1160
+ /**
1161
+ * 获取当前登录用户的访问凭证
1162
+ *
1163
+ * 文档 {@link https://docs.cloudbase.net/api-reference/webv2/authentication#authgetaccesstoken}
1164
+ */
1165
+ getAccessToken(): Promise<{ accessToken: string; env: string }>
1166
+ /**
1167
+ * 提供第三方平台登录 token
1168
+ *
1169
+ * 文档 {@link https://docs.cloudbase.net/api-reference/webv2/authentication#authgrantprovidertoken}
1170
+ */
1171
+ grantProviderToken(params: authModels.GrantProviderTokenRequest): Promise<authModels.GrantProviderTokenResponse>
1172
+ patchProviderToken(params: authModels.PatchProviderTokenRequest): Promise<authModels.PatchProviderTokenResponse>
1173
+ /**
1174
+ * 第三方平台登录
1175
+ *
1176
+ * 文档 {@link https://docs.cloudbase.net/api-reference/webv2/authentication#authsigninwithprovider}
1177
+ */
1178
+ signInWithProvider(params: authModels.SignInWithProviderRequest): Promise<ILoginState>
1179
+ /**
1180
+ * 微信登录
1181
+ */
1182
+ signInWithWechat(params?: any): Promise<ILoginState>
1183
+ grantToken(params: authModels.GrantTokenRequest): Promise<ILoginState>
1184
+ /**
1185
+ * 生成第三方平台授权 Uri (如微信二维码扫码授权网页)
1186
+ *
1187
+ * 文档 {@link https://docs.cloudbase.net/api-reference/webv2/authentication#authgenproviderredirecturi}
1188
+ */
1189
+ genProviderRedirectUri(
1190
+ params: authModels.GenProviderRedirectUriRequest,
1191
+ ): Promise<authModels.GenProviderRedirectUriResponse>
1192
+ /**
1193
+ * 重置密码(用户忘记密码无法登录时,可使用该接口强制设置密码)
1194
+ *
1195
+ * 文档 {@link https://docs.cloudbase.net/api-reference/webv2/authentication#authresetpassword}
1196
+ */
1197
+ resetPassword(params: authModels.ResetPasswordRequest): Promise<void>
1198
+ deviceAuthorize(params: authModels.DeviceAuthorizeRequest): Promise<authModels.DeviceAuthorizeResponse>
1199
+ /**
1200
+ * 通过 sudo 接口获取高级操作权限,如修改用户密码,修改手机号,邮箱等操作
1201
+ *
1202
+ * 文档 {@link https://docs.cloudbase.net/api-reference/webv2/authentication#authsudo}
1203
+ */
1204
+ sudo(params: authModels.SudoRequest): Promise<authModels.SudoResponse>
1205
+ /**
1206
+ * 删除用户
1207
+ *
1208
+ * 文档 {@link https://docs.cloudbase.net/api-reference/webv2/authentication#authdeleteme}
1209
+ */
1210
+ deleteMe(params: authModels.WithSudoRequest): Promise<authModels.UserProfile>
1211
+ /**
1212
+ * 获取第三方绑定列表
1213
+ *
1214
+ * 文档 {@link https://docs.cloudbase.net/api-reference/webv2/authentication#authgetproviders}
1215
+ */
1216
+ getProviders(): Promise<authModels.UserProfileProvider>
1217
+ /**
1218
+ * 用于查询用户是否为匿名登录状态
1219
+ *
1220
+ * 文档 {@link https://docs.cloudbase.net/api-reference/webv2/authentication#authloginscope}
1221
+ */
1222
+ loginScope(): Promise<string>
1223
+ loginGroups(): Promise<string[]>
1224
+ onLoginStateChanged(callback: Function)
1225
+ createLoginState(
1226
+ params?: { version?: string; query?: any },
1227
+ options?: { asyncRefreshUser?: boolean; userInfo?: any },
1228
+ ): Promise<ILoginState>
1229
+ /**
1230
+ * 强制刷新token
1231
+ *
1232
+ * @param params
1233
+ */
1234
+ refreshTokenForce(params: { version?: string }): Promise<authModels.Credentials>
1235
+ /**
1236
+ * 获取身份信息
1237
+ *
1238
+ * 文档 {@link https://docs.cloudbase.net/api-reference/webv2/authentication#authgetcredentials}
1239
+ */
1240
+ getCredentials(): Promise<authModels.Credentials>
1241
+ /**
1242
+ * 写入身份信息
1243
+ *
1244
+ * @param credentials
1245
+ */
1246
+ setCredentials(credentials: authModels.Credentials): Promise<void>
1247
+ /**
1248
+ * 获取身份源类型
1249
+ *
1250
+ */
1251
+ getProviderSubType(): Promise<authModels.ProviderSubType>
1252
+ /**
1253
+ * 创建验证码数据
1254
+ *
1255
+ * @param params
1256
+ */
1257
+ createCaptchaData(params: { state: string; redirect_uri?: string }): Promise<any>
1258
+ /**
1259
+ * 验证验证码数据
1260
+ *
1261
+ * @param params
1262
+ */
1263
+ verifyCaptchaData(params: { token: string; key: string }): Promise<any>
1264
+ /**
1265
+ * 修改密码
1266
+ *
1267
+ * 文档 {@link https://docs.cloudbase.net/api-reference/webv2/authentication#authmodifypassword}
1268
+ *
1269
+ * @param params
1270
+ */
1271
+ modifyPassword(params: authModels.ModifyUserBasicInfoRequest): Promise<void>
1272
+ /**
1273
+ * 未登录状态修改密码
1274
+ *
1275
+ * 文档 {@link https://docs.cloudbase.net/api-reference/webv2/authentication#authmodifypasswordwithoutlogin}
1276
+ *
1277
+ * @param params
1278
+ */
1279
+ modifyPasswordWithoutLogin(params: authModels.ModifyPasswordWithoutLoginRequest): Promise<void>
1280
+ /**
1281
+ * 获取用户行为日志
1282
+ *
1283
+ * 文档 {@link https://docs.cloudbase.net/api-reference/webv2/authentication#authgetuserbehaviorlog}
1284
+ *
1285
+ * @param params
1286
+ */
1287
+ getUserBehaviorLog(params: authModels.GetUserBehaviorLog): Promise<authModels.GetUserBehaviorLogRes>
1288
+ /**
1289
+ * 检查用户名是否被绑定过
1290
+ *
1291
+ * {@link https://docs.cloudbase.net/api-reference/webv2/authentication.html#authisusernameregistered}
1292
+ *
1293
+ * @example
1294
+ * ```javascript
1295
+ * const app = cloudbase.init({
1296
+ * env: "xxxx-yyy"
1297
+ * });
1298
+ * const auth = app.auth();
1299
+ * const username = "your_awesome_username";
1300
+ * auth.isUsernameRegistered(username).then(registered=>{
1301
+ * // ...
1302
+ * });
1303
+ * ```
1304
+ *
1305
+ * @param username 用户名
1306
+ *
1307
+ * @return Promise-用户是否被绑定
1308
+ */
1309
+ isUsernameRegistered(username: string): Promise<boolean>
1310
+ getMiniProgramQrCode(
1311
+ params: authModels.GetMiniProgramQrCodeRequest,
1312
+ ): Promise<authModels.GetMiniProgramQrCodeResponse>
1313
+ getMiniProgramQrCodeStatus(
1314
+ params: authModels.GetMiniProgramQrCodeStatusRequest,
1315
+ ): Promise<authModels.GetMiniProgramQrCodeStatusResponse>
1316
+ /**
1317
+ * 跳转到默认登录页
1318
+ * 文档 {@link https://docs.cloudbase.net/api-reference/webv2/authentication#authtodefaultloginpage}
1319
+ * @param params
1320
+ */
1321
+ toDefaultLoginPage(params?: authModels.ToDefaultLoginPage): Promise<CommonRes>
1322
+
1323
+ /**
1324
+ * 退出登录
1325
+ *
1326
+ * {@link https://docs.cloudbase.net/api-reference/webv3/authentication#signout}
1327
+ *
1328
+ * @example
1329
+ * ```javascript
1330
+ * const app = cloudbase.init({
1331
+ * env: "xxxx-yyy"
1332
+ * });
1333
+ * app.auth.signOut().then(()=>{});
1334
+ * ```
1335
+ *
1336
+ * @return Promise
1337
+ */
1338
+ signOut(params?: authModels.SignoutRequest): Promise<void | authModels.SignoutResponse>
1339
+ /**
1340
+ * 使用自定义登录 ticket 登录
1341
+ *
1342
+ * 文档 {@link https://docs.cloudbase.net/api-reference/webv3/authentication#signinwithcustomticket}
1343
+ *
1344
+ * @param getTickFn
1345
+ */
1346
+ signInWithCustomTicket(getTickFn?: authModels.GetCustomSignTicketFn): Promise<ILoginState>
1347
+ /**
1348
+ * 用户登录,目前支持手机号,邮箱,用户名密码登录
1349
+ *
1350
+ * 文档 {@link https://docs.cloudbase.net/api-reference/webv3/authentication#signin}
1351
+ */
1352
+ signIn(params: authModels.SignInRequest): Promise<ILoginState>
1353
+ /**
1354
+ * 用户注册,目前支持手机号验证码注册,邮箱验证码注册
1355
+ *
1356
+ * 文档 {@link https://docs.cloudbase.net/api-reference/webv3/authentication#signup}
1357
+ */
1358
+ signUp(params: authModels.SignUpRequest): Promise<SignUpRes>
1359
+ /**
1360
+ * 监听认证状态变化
1361
+ *
1362
+ * 文档 {@link https://docs.cloudbase.net/api-reference/webv3/authentication#onauthstatechange}
1363
+ *
1364
+ * @param callback
1365
+ */
1366
+ onAuthStateChange(callback: OnAuthStateChangeCallback): {
1367
+ data: { subscription: { id: string; callback: Function; unsubscribe: () => void } }
1368
+ }
1369
+ /**
1370
+ * 使用用户名和密码登录
1371
+ *
1372
+ * 文档 {@link https://docs.cloudbase.net/api-reference/webv3/authentication#signinwithpassword}
1373
+ *
1374
+ * @param params
1375
+ */
1376
+ signInWithPassword(params: SignInWithPasswordReq): Promise<SignInRes>
1377
+ /**
1378
+ * 使用第三方平台 ID Token 登录
1379
+ *
1380
+ * 文档 {@link https://docs.cloudbase.net/api-reference/webv3/authentication#signinwithidtoken}
1381
+ *
1382
+ * @param params
1383
+ */
1384
+ signInWithIdToken(params: SignInWithIdTokenReq): Promise<SignInRes>
1385
+ /**
1386
+ * 使用一次性密码(OTP)登录,支持手机号和邮箱两种方式。
1387
+ *
1388
+ * **注意**:手机号验证码登录需要在初始化时设置 `region: 'ap-shanghai'`。
1389
+ *
1390
+ * 文档 {@link https://docs.cloudbase.net/api-reference/webv3/authentication#signinwithotp}
1391
+ *
1392
+ * @example
1393
+ * ```typescript
1394
+ * // 完整的手机号验证码登录流程
1395
+ * import Cloudbase from '@cloudbase/js-sdk';
1396
+ *
1397
+ * // 第一步:初始化(region 必须为 ap-shanghai)
1398
+ * const app = Cloudbase.init({
1399
+ * env: 'your-env-id',
1400
+ * region: 'ap-shanghai'
1401
+ * });
1402
+ * const auth = app.auth();
1403
+ *
1404
+ * // 第二步:发送验证码
1405
+ * const { data, error } = await auth.signInWithOtp({ phone: '+8613800138000' });
1406
+ * if (error) {
1407
+ * console.error('发送验证码失败:', error.message);
1408
+ * return;
1409
+ * }
1410
+ *
1411
+ * // 第三步:用户输入验证码后,调用 verifyOtp 完成登录
1412
+ * const { data: loginData, error: loginError } = await data.verifyOtp({
1413
+ * token: userInputCode // 用户输入的验证码
1414
+ * });
1415
+ * if (loginError) {
1416
+ * console.error('验证失败:', loginError.message);
1417
+ * return;
1418
+ * }
1419
+ * console.log('登录成功:', loginData.user);
1420
+ * ```
1421
+ *
1422
+ * @param params 登录参数,包含 email 或 phone(二选一)
1423
+ */
1424
+ signInWithOtp(params: SignInWithOtpReq): Promise<SignInWithOtpRes>
1425
+ /**
1426
+ * 校验第三方平台授权登录回调
1427
+ *
1428
+ * 文档 {@link https://docs.cloudbase.net/api-reference/webv3/authentication#verifyoauth}
1429
+ *
1430
+ * @param params
1431
+ */
1432
+ verifyOAuth(params?: VerifyOAuthReq): Promise<SignInRes>
1433
+ /**
1434
+ * 生成第三方平台授权 Uri
1435
+ *
1436
+ * 文档 {@link https://docs.cloudbase.net/api-reference/webv3/authentication#signinwithoauth}
1437
+ *
1438
+ * @param params
1439
+ */
1440
+ signInWithOAuth(params: SignInWithOAuthReq): Promise<SignInOAuthRes>
1441
+ /**
1442
+ * 获取当前访问令牌中的声明信息
1443
+ *
1444
+ * 文档 {@link https://docs.cloudbase.net/api-reference/webv3/authentication#getclaims}
1445
+ */
1446
+ getClaims(): Promise<GetClaimsRes>
1447
+ /**
1448
+ * 通过邮箱重置密码
1449
+ *
1450
+ * 文档 {@link https://docs.cloudbase.net/api-reference/webv3/authentication#resetpasswordforemail}
1451
+ *
1452
+ * @param emailOrPhone
1453
+ * @param options
1454
+ */
1455
+ resetPasswordForEmail(emailOrPhone: string, options?: { redirectTo?: string }): Promise<ResetPasswordForEmailRes>
1456
+ /**
1457
+ * 通过旧密码重置密码
1458
+ *
1459
+ * 文档 {@link https://docs.cloudbase.net/api-reference/webv3/authentication#resetpasswordforold}
1460
+ *
1461
+ * @param params
1462
+ */
1463
+ resetPasswordForOld(params: ResetPasswordForOldReq): Promise<SignInRes>
1464
+ /**
1465
+ * 验证一次性密码(OTP)
1466
+ *
1467
+ * 文档 {@link https://docs.cloudbase.net/api-reference/webv3/authentication#verifyotp}
1468
+ *
1469
+ * @param params
1470
+ */
1471
+ verifyOtp(params: VerifyOtpReq): Promise<SignInRes>
1472
+ /**
1473
+ * 获取当前会话
1474
+ *
1475
+ * 文档 {@link https://docs.cloudbase.net/api-reference/webv3/authentication#getsession}
1476
+ */
1477
+ getSession(): Promise<SignInRes>
1478
+ /**
1479
+ * 刷新会话
1480
+ *
1481
+ * 文档 {@link https://docs.cloudbase.net/api-reference/webv3/authentication#refreshsession}
1482
+ *
1483
+ * @param refresh_token
1484
+ */
1485
+ refreshSession(refresh_token?: string): Promise<SignInRes>
1486
+ /**
1487
+ * 获取当前用户详细信息
1488
+ *
1489
+ * 文档 {@link https://docs.cloudbase.net/api-reference/webv3/authentication#getuser}
1490
+ */
1491
+ getUser(): Promise<GetUserRes>
1492
+ /**
1493
+ * 刷新用户信息
1494
+ *
1495
+ * 文档 {@link https://docs.cloudbase.net/api-reference/webv3/authentication#refreshuser}
1496
+ */
1497
+ refreshUser(): Promise<CommonRes>
1498
+ /**
1499
+ * 更新用户信息
1500
+ *
1501
+ * 文档 {@link https://docs.cloudbase.net/api-reference/webv3/authentication#updateuser}
1502
+ *
1503
+ * @param params
1504
+ */
1505
+ updateUser(params: UpdateUserReq): Promise<GetUserRes | UpdateUserWithVerificationRes>
1506
+ /**
1507
+ * 获取已绑定的身份源
1508
+ *
1509
+ * 文档 {@link https://docs.cloudbase.net/api-reference/webv3/authentication#getuseridentities}
1510
+ */
1511
+ getUserIdentities(): Promise<GetUserIdentitiesRes>
1512
+ /**
1513
+ * 绑定身份源到当前用户
1514
+ *
1515
+ * 文档 {@link https://docs.cloudbase.net/api-reference/webv3/authentication#linkidentity}
1516
+ *
1517
+ * @param params
1518
+ */
1519
+ linkIdentity(params: LinkIdentityReq): Promise<LinkIdentityRes>
1520
+ /**
1521
+ * 解绑身份源
1522
+ *
1523
+ * 文档 {@link https://docs.cloudbase.net/api-reference/webv3/authentication#unlinkidentity}
1524
+ *
1525
+ * @param params
1526
+ */
1527
+ unlinkIdentity(params: UnlinkIdentityReq): Promise<CommonRes>
1528
+ /**
1529
+ * 重新认证
1530
+ *
1531
+ * 文档 {@link https://docs.cloudbase.net/api-reference/webv3/authentication#reauthenticate}
1532
+ */
1533
+ reauthenticate(): Promise<ReauthenticateRes>
1534
+ /**
1535
+ * 重新发送验证码
1536
+ *
1537
+ * 文档 {@link https://docs.cloudbase.net/api-reference/webv3/authentication#resend}
1538
+ *
1539
+ * @param params
1540
+ */
1541
+ resend(params: ResendReq): Promise<ResendRes>
1542
+ /**
1543
+ * 使用 access_token 和 refresh_token 设置会话
1544
+ *
1545
+ * 文档 {@link https://docs.cloudbase.net/api-reference/webv3/authentication#setsession}
1546
+ *
1547
+ * @param params
1548
+ */
1549
+ setSession(params: SetSessionReq): Promise<SignInRes>
1550
+ /**
1551
+ * 删除当前用户
1552
+ *
1553
+ * 文档 {@link https://docs.cloudbase.net/api-reference/webv3/authentication#deleteuser}
1554
+ *
1555
+ * @param params
1556
+ */
1557
+ deleteUser(params: DeleteMeReq): Promise<CommonRes>
1558
+ /**
1559
+ * 小程序 openId 静默登录
1560
+ *
1561
+ * 文档 {@link https://docs.cloudbase.net/api-reference/webv3/authentication#signinwithopenid}
1562
+ *
1563
+ * @param params
1564
+ */
1565
+ signInWithOpenId(params?: { useWxCloud?: boolean }): Promise<SignInRes>
1566
+ /**
1567
+ * 小程序手机号授权登录
1568
+ *
1569
+ * 文档 {@link https://docs.cloudbase.net/api-reference/webv3/authentication#signinwithphoneauth}
1570
+ *
1571
+ * @param params
1572
+ */
1573
+ signInWithPhoneAuth(params: { phoneCode: string }): Promise<SignInRes>
1574
+
1575
+ // ========== v1 兼容 API ==========
1576
+
1577
+ /**
1578
+ * v1 API: 获取用于微信登录的 WeixinAuthProvider
1579
+ *
1580
+ * @deprecated 建议使用 auth.signInWithOAuth({ provider: appid }) 替代。
1581
+ *
1582
+ * @example
1583
+ * ```javascript
1584
+ * const provider = auth.weixinAuthProvider({ appid: 'wx-appid', scope: 'snsapi_login' });
1585
+ * provider.signInWithRedirect();
1586
+ * ```
1587
+ *
1588
+ * @param options
1589
+ * @param options.appid 微信 AppID
1590
+ * @param options.scope 微信授权范围
1591
+ */
1592
+ weixinAuthProvider(options: { appid: string; scope: string }): cloudbase.auth.WeixinAuthProvider
1593
+
1594
+ /**
1595
+ * v1 API: 获取用于自定义登录的 CustomAuthProvider
1596
+ *
1597
+ * @deprecated 建议使用 auth.signInWithCustomTicket(() => Promise.resolve(ticket)) 替代。
1598
+ *
1599
+ * @example
1600
+ * ```javascript
1601
+ * const provider = auth.customAuthProvider();
1602
+ * await provider.signIn(ticket);
1603
+ * ```
1604
+ */
1605
+ customAuthProvider(): cloudbase.auth.CustomAuthProvider
1606
+
1607
+ /**
1608
+ * v1 API: 获取用于匿名登录的 AnonymousAuthProvider
1609
+ *
1610
+ * @deprecated 建议使用 auth.signInAnonymously({}) 替代。
1611
+ *
1612
+ * @example
1613
+ * ```javascript
1614
+ * const provider = auth.anonymousAuthProvider();
1615
+ * await provider.signIn();
1616
+ * ```
1617
+ */
1618
+ anonymousAuthProvider(): cloudbase.auth.AnonymousAuthProvider
1619
+
1620
+ /**
1621
+ * v1 API: 使用邮箱和密码注册云开发账户
1622
+ *
1623
+ * @deprecated 建议使用 auth.signUp({ email, password }) 替代。
1624
+ *
1625
+ * @example
1626
+ * ```javascript
1627
+ * await auth.signUpWithEmailAndPassword('user@example.com', 'password123');
1628
+ * ```
1629
+ *
1630
+ * @param email 邮箱
1631
+ * @param password 密码
1632
+ */
1633
+ signUpWithEmailAndPassword(email: string, password: string): Promise<SignUpRes>
1634
+
1635
+ /**
1636
+ * v1 API: 使用邮箱和密码登录云开发(支持两种调用方式)
1637
+ *
1638
+ * @deprecated 建议使用 auth.signInWithPassword({ email, password }) 替代。
1639
+ *
1640
+ * @example
1641
+ * ```javascript
1642
+ * // 方式一(v1 风格):
1643
+ * await auth.signInWithEmailAndPassword('user@example.com', 'password123');
1644
+ *
1645
+ * // 方式二(v3 风格):
1646
+ * const { data, error } = await auth.signInWithEmailAndPassword({
1647
+ * email: 'user@example.com',
1648
+ * password: 'password123'
1649
+ * });
1650
+ * ```
1651
+ *
1652
+ * @param emailOrParams - 邮箱字符串(v1)或包含 email 和 password 的对象(v3)
1653
+ * @param password - 密码(仅 v1 风格时使用)
1654
+ */
1655
+ signInWithEmailAndPassword(emailOrParams: string | { email: string; password: string; is_encrypt?: boolean }, password?: string): Promise<SignInRes | ILoginState>
1656
+
1657
+ /**
1658
+ * v1 API: 发送重置密码的邮件
1659
+ *
1660
+ * @deprecated 建议使用 auth.resetPasswordForEmail(email) 替代。
1661
+ *
1662
+ * @example
1663
+ * ```javascript
1664
+ * await auth.sendPasswordResetEmail('user@example.com');
1665
+ * ```
1666
+ *
1667
+ * @param email 邮箱
1668
+ */
1669
+ sendPasswordResetEmail(email: string): Promise<void>
1670
+
1671
+ /**
1672
+ * v1 API: 使用用户名和密码登录云开发
1673
+ *
1674
+ * @deprecated 建议使用 auth.signInWithPassword({ username, password }) 替代。
1675
+ *
1676
+ * @example
1677
+ * ```javascript
1678
+ * const loginState = await auth.signInWithUsernameAndPassword('username', 'password123');
1679
+ * ```
1680
+ *
1681
+ * @param username 用户名
1682
+ * @param password 密码
1683
+ */
1684
+ signInWithUsernameAndPassword(username: string, password: string): Promise<ILoginState>
1685
+
1686
+ /**
1687
+ * v1 API: 发送手机验证码
1688
+ *
1689
+ * @deprecated 此方法仅发送验证码并返回布尔值,不返回 verifyOtp 回调。
1690
+ * 推荐使用 v3 API `auth.signInWithOtp({ phone })` 替代,它会返回包含 `verifyOtp` 方法的对象,
1691
+ * 可直接完成"发送验证码 → 用户输入 → 验证并登录"的完整流程。
1692
+ *
1693
+ * **迁移示例**:
1694
+ * ```typescript
1695
+ * // ❌ 旧方式 (v1)
1696
+ * await auth.sendPhoneCode('+8613800138000');
1697
+ * // 需要单独调用其他 API 验证
1698
+ *
1699
+ * // ✅ 新方式 (v3) - 完整的手机号验证码登录流程
1700
+ * // 注意:初始化时必须设置 region: 'ap-shanghai'
1701
+ * const app = Cloudbase.init({ env: 'your-env-id', region: 'ap-shanghai' });
1702
+ * const auth = app.auth();
1703
+ * const { data, error } = await auth.signInWithOtp({ phone: '+8613800138000' });
1704
+ * if (error) throw error;
1705
+ * // 用户输入验证码后调用 verifyOtp
1706
+ * const { data: loginData, error: loginError } = await data.verifyOtp({ token: '123456' });
1707
+ * console.log('登录成功', loginData.user);
1708
+ * ```
1709
+ *
1710
+ * @param phoneNumber 手机号(需含国际区号,如 +86)
1711
+ * @returns 是否发送成功
1712
+ */
1713
+ sendPhoneCode(phoneNumber: string): Promise<boolean>
1714
+
1715
+ /**
1716
+ * v1 API: 手机号注册(支持短信验证码+密码方式)
1717
+ *
1718
+ * @deprecated 建议使用 auth.signUp({ phone_number, verification_code, password? }) 替代。
1719
+ *
1720
+ * @example
1721
+ * ```javascript
1722
+ * const loginState = await auth.signUpWithPhoneCode('+8613800138000', '123456', 'password');
1723
+ * ```
1724
+ *
1725
+ * @param phoneNumber 手机号
1726
+ * @param phoneCode 验证码
1727
+ * @param password 可选密码
1728
+ */
1729
+ signUpWithPhoneCode(phoneNumber: string, phoneCode: string, password?: string): Promise<ILoginState>
1730
+
1731
+ /**
1732
+ * v1 API: 手机号登录(支持短信验证码 or 密码方式)
1733
+ *
1734
+ * @deprecated 推荐使用 v3 API 替代:
1735
+ * - 密码登录:`auth.signInWithPassword({ phone, password })`
1736
+ * - 验证码登录:`auth.signInWithOtp({ phone })`
1737
+ *
1738
+ * **迁移示例**:
1739
+ * ```typescript
1740
+ * // ❌ 旧方式 (v1) - 验证码登录
1741
+ * const loginState = await auth.signInWithPhoneCodeOrPassword({
1742
+ * phoneNumber: '+8613800138000',
1743
+ * phoneCode: '123456'
1744
+ * });
1745
+ *
1746
+ * // ✅ 新方式 (v3) - 验证码登录
1747
+ * const { data, error } = await auth.signInWithOtp({ phone: '+8613800138000' });
1748
+ * if (error) throw error;
1749
+ * const { data: result } = await data.verifyOtp({ token: '123456' });
1750
+ *
1751
+ * // ✅ 新方式 (v3) - 密码登录
1752
+ * const { data, error } = await auth.signInWithPassword({
1753
+ * phone: '+8613800138000',
1754
+ * password: 'password123'
1755
+ * });
1756
+ * ```
1757
+ *
1758
+ * @param params
1759
+ */
1760
+ signInWithPhoneCodeOrPassword(params: {
1761
+ phoneNumber: string
1762
+ phoneCode?: string
1763
+ password?: string
1764
+ }): Promise<ILoginState>
1765
+
1766
+ /**
1767
+ * v1 API: 手机号强制重置密码
1768
+ *
1769
+ * @deprecated 建议使用 auth.resetPasswordForEmail(phoneNumber) 替代。
1770
+ *
1771
+ * @example
1772
+ * ```javascript
1773
+ * const loginState = await auth.forceResetPwdByPhoneCode({
1774
+ * phoneNumber: '+8613800138000',
1775
+ * phoneCode: '123456',
1776
+ * password: 'newPassword'
1777
+ * });
1778
+ * ```
1779
+ *
1780
+ * @param params
1781
+ */
1782
+ forceResetPwdByPhoneCode(params: {
1783
+ phoneNumber: string
1784
+ phoneCode: string
1785
+ password: string
1786
+ }): Promise<ILoginState>
1787
+
1788
+ /**
1789
+ * v1 API: 接收一个回调函数,在刷新短期访问令牌前调用,根据返回值决定是否刷新
1790
+ *
1791
+ * @deprecated 建议使用 auth.onAuthStateChange(callback) 监听 TOKEN_REFRESHED 事件替代。
1792
+ *
1793
+ * @param callback 回调函数,返回 true 则刷新,返回 false 则不刷新
1794
+ */
1795
+ shouldRefreshAccessToken(callback: () => boolean): void
1796
+
1797
+ /**
1798
+ * v1 API: 接收一个回调函数,在登录状态过期时调用
1799
+ *
1800
+ * @deprecated 建议使用 auth.onAuthStateChange(callback) 替代,监听 SIGNED_OUT 事件。
1801
+ *
1802
+ * @param callback 登录态过期回调
1803
+ */
1804
+ onLoginStateExpired(callback: Function): void
1805
+
1806
+ /**
1807
+ * v1 API: 接收一个回调函数,在短期访问令牌刷新后调用
1808
+ *
1809
+ * @deprecated 建议使用 auth.onAuthStateChange(callback) 替代,监听 TOKEN_REFRESHED 事件。
1810
+ *
1811
+ * @param callback 令牌刷新回调
1812
+ */
1813
+ onAccessTokenRefreshed(callback: Function): void
1814
+
1815
+ /**
1816
+ * v1 API: 接收一个回调函数,在匿名登录状态被转换后调用
1817
+ *
1818
+ * @deprecated 建议使用 auth.onAuthStateChange(callback) 替代,监听 SIGNED_IN 事件。
1819
+ *
1820
+ * @param callback 匿名转正回调
1821
+ */
1822
+ onAnonymousConverted(callback: Function): void
1823
+
1824
+ /**
1825
+ * v1 API: 接收一个回调函数,在登录类型发生变化后调用
1826
+ *
1827
+ * @deprecated 建议使用 auth.onAuthStateChange(callback) 替代,监听 SIGNED_IN / SIGNED_OUT 事件。
1828
+ *
1829
+ * @param callback 登录类型变化回调
1830
+ */
1831
+ onLoginTypeChanged(callback: Function): void
1832
+ }
1833
+
1834
+ // ========== v1 兼容 Provider 类 ==========
1835
+
1836
+ /**
1837
+ * v1 微信登录 Provider
1838
+ *
1839
+ * @deprecated 建议使用 auth.signInWithOAuth({ provider }) 替代。
1840
+ */
1841
+ interface WeixinAuthProvider {
1842
+ /**
1843
+ * 跳转微信授权页面进行登录
1844
+ * @deprecated 建议使用 auth.signInWithOAuth({ provider: 'providerId' }) 替代。
1845
+ */
1846
+ signInWithRedirect(): void
1847
+ /**
1848
+ * 获取微信授权重定向结果
1849
+ * @deprecated 建议使用 auth.verifyOAuth({ code, state, provider }) 替代。
1850
+ */
1851
+ getRedirectResult(options?: { createUser?: boolean; syncUserInfo?: boolean }): Promise<any>
1852
+ /**
1853
+ * 获取微信绑定重定向结果
1854
+ * @deprecated 建议使用 auth.linkIdentity({ provider: 'providerId' }) 替代。
1855
+ */
1856
+ getLinkRedirectResult(options?: { withUnionId?: boolean }): Promise<void>
1857
+ }
1858
+
1859
+ /**
1860
+ * v1 自定义登录 Provider
1861
+ *
1862
+ * @deprecated 建议使用 auth.signInWithCustomTicket(() => Promise.resolve(ticket)) 替代。
1863
+ */
1864
+ interface CustomAuthProvider {
1865
+ /**
1866
+ * 使用自定义登录凭据 ticket 登录云开发
1867
+ * @param ticket 自定义登录 ticket
1868
+ * @deprecated 建议使用 auth.signInWithCustomTicket(() => Promise.resolve(ticket)) 替代。
1869
+ */
1870
+ signIn(ticket: string): Promise<void>
1871
+ }
1872
+
1873
+ /**
1874
+ * v1 匿名登录 Provider
1875
+ *
1876
+ * @deprecated 建议使用 auth.signInAnonymously({}) 替代。
1877
+ */
1878
+ interface AnonymousAuthProvider {
1879
+ /**
1880
+ * 匿名登录云开发
1881
+ * @deprecated 建议使用 auth.signInAnonymously({}) 替代。
1882
+ */
1883
+ signIn(): Promise<void>
1884
+ }
1885
+ }
1886
+ /**
1887
+ * functions
1888
+ */
1889
+ declare namespace cloudbase.functions {
1890
+ interface ICallFunctionOptions {
1891
+ name: string
1892
+ data?: KV<any>
1893
+ query?: KV<any>
1894
+ search?: string
1895
+ parse?: boolean
1896
+ // Used for 云函数2.0 CallContainer
1897
+ type?: string
1898
+ method?: string
1899
+ path?: string
1900
+ header?: KV<any>
1901
+ }
1902
+
1903
+ interface ICallFunctionResponse {
1904
+ requestId: string
1905
+ result: any
1906
+ }
1907
+ }
1908
+ /**
1909
+ * storage
1910
+ */
1911
+ declare namespace cloudbase.storage {
1912
+ interface ICloudbaseUploadFileParams {
1913
+ cloudPath: string
1914
+ filePath?: string
1915
+ method?: 'post' | 'put'
1916
+ headers?: KV<string>
1917
+ onUploadProgress?: Function
1918
+ // 文件内容 Buffer 或 文件可读流, node端使用
1919
+ fileContent?: any
1920
+ customReqOpts?: ICustomReqOpts
1921
+ }
1922
+ interface ICloudbaseUploadFileResult {
1923
+ fileID: string
1924
+ requestId: string
1925
+ }
1926
+ interface ICloudbaseGetUploadMetadataParams {
1927
+ cloudPath: string
1928
+ customReqOpts?: ICustomReqOpts
1929
+ }
1930
+ interface ICloudbaseDeleteFileParams {
1931
+ fileList: string[]
1932
+ customReqOpts?: ICustomReqOpts
1933
+ }
1934
+ interface ICloudbaseDeleteFileResult {
1935
+ code?: string
1936
+ message?: string
1937
+ fileList?: {
1938
+ code?: string
1939
+ fileID: string
1940
+ }[]
1941
+ requestId?: string
1942
+ }
1943
+
1944
+ interface ICloudbaseFileInfo {
1945
+ fileID: string
1946
+ maxAge: number
1947
+ }
1948
+
1949
+ interface ICloudbaseGetTempFileURLParams {
1950
+ fileList: string[] | ICloudbaseFileInfo[]
1951
+ customReqOpts?: ICustomReqOpts
1952
+ }
1953
+
1954
+ interface ICloudbaseGetTempFileURLResult {
1955
+ code?: string
1956
+ message?: string
1957
+ fileList?: {
1958
+ code?: string
1959
+ message?: string
1960
+ fileID: string
1961
+ tempFileURL: string
1962
+ download_url?: string
1963
+ }[]
1964
+ requestId?: string
1965
+ }
1966
+ interface ICloudbaseDownloadFileParams {
1967
+ fileID: string
1968
+ tempFilePath?: string
1969
+ customReqOpts?: ICustomReqOpts
1970
+ }
1971
+ interface ICloudbaseDownloadFileResult {
1972
+ code?: string
1973
+ message?: string
1974
+ fileContent?: any
1975
+ requestId?: string
1976
+ }
1977
+ interface ICloudbaseFileMetaData {
1978
+ url: string
1979
+ token: string
1980
+ authorization: string
1981
+ fileId: string
1982
+ cosFileId: string
1983
+ download_url: string
1984
+ }
1985
+
1986
+ interface ICloudbaseFileMetaDataRes {
1987
+ data: ICloudbaseFileMetaData
1988
+ requestId: string
1989
+ }
1990
+
1991
+ interface ICloudbaseCopyFileParams {
1992
+ fileList: Array<{
1993
+ srcPath: string
1994
+ dstPath: string
1995
+ overwrite?: boolean
1996
+ removeOriginal?: boolean
1997
+ }>
1998
+ customReqOpts?: ICustomReqOpts
1999
+ }
2000
+
2001
+ interface ICloudbaseCopyFileResult {
2002
+ fileList: Array<{
2003
+ fileId?: string
2004
+ code?: string
2005
+ message?: string
2006
+ }>
2007
+ requestId?: string
2008
+ }
2009
+
2010
+ interface ICloudbaseGetFileInfoResultItem {
2011
+ code?: string
2012
+ message?: string
2013
+ fileID: string
2014
+ tempFileURL: string
2015
+ fileName?: string
2016
+ cloudId?: string
2017
+ contentType?: string
2018
+ mime?: string
2019
+ size?: number
2020
+ cacheControl?: string
2021
+ lastModified?: string
2022
+ etag?: string
2023
+ }
2024
+
2025
+ interface ICloudbaseGetFileInfoResult {
2026
+ fileList: ICloudbaseGetFileInfoResultItem[]
2027
+ requestId: string
2028
+ }
2029
+
2030
+ // ---- Supabase-like Storage Types ----
2031
+
2032
+ /** Node.js 风格可读流的最小兼容类型,避免依赖 `@types/node`。 */
2033
+ interface NodeReadableStreamLike {
2034
+ /** 将当前流管道输出到目标流。 */
2035
+ pipe(destination: any, options?: any): any
2036
+ }
2037
+
2038
+ /**
2039
+ * Node.js `Buffer` 的兼容类型。
2040
+ *
2041
+ * 在安装了 `@types/node` 的项目中解析为 `Buffer`,未安装时退化为 `never`,
2042
+ * 从而既能让 Node 端继续显式传入 `Buffer`,又不会让纯浏览器项目因缺少
2043
+ * `@types/node` 而报“找不到名称 Buffer”,避免对 `@types/node` 的硬依赖。
2044
+ */
2045
+ type MaybeNodeBuffer = typeof globalThis extends { Buffer: new (...args: any[]) => infer B } ? B : never
2046
+
2047
+ /**
2048
+ * 可上传的文件内容类型。
2049
+ *
2050
+ * @remarks
2051
+ * - Node.js `Buffer`:通过 `MaybeNodeBuffer` 兼容(装有 `@types/node` 时可直接传入);
2052
+ * 即便未装 `@types/node`,`Buffer` 仍可作为 `ArrayBufferView` / `Uint8Array` 传入。
2053
+ * - Node.js 可读流(如 `NodeJS.ReadableStream` / `fs.ReadStream`):可作为 `NodeReadableStreamLike` 传入。
2054
+ */
2055
+ type FileBody =
2056
+ | ArrayBuffer
2057
+ | ArrayBufferView
2058
+ | Blob
2059
+ | File
2060
+ | FormData
2061
+ | MaybeNodeBuffer
2062
+ | NodeReadableStreamLike
2063
+ | ReadableStream<Uint8Array>
2064
+ | URLSearchParams
2065
+ | string
2066
+
2067
+ /** 上传 / 覆盖对象选项。 */
2068
+ interface FileOptions {
2069
+ /** 缓存时间,单位为秒;会转换为 `Cache-Control: max-age=<seconds>`。 */
2070
+ cacheControl?: string
2071
+ /** 文件 MIME 类型;当 `fileBody` 不是 `Blob` / `File` / `FormData` 时建议显式指定。 */
2072
+ contentType?: string
2073
+ /** 是否允许覆盖同名对象。 */
2074
+ upsert?: boolean
2075
+ /** 透传给底层 `fetch` 的 duplex 配置,用于流式请求场景。 */
2076
+ duplex?: string
2077
+ /** 用户自定义元数据。 */
2078
+ metadata?: Record<string, any>
2079
+ /** 额外请求头。 */
2080
+ headers?: Record<string, string>
2081
+ }
2082
+
2083
+ /** 图片转换选项。 */
2084
+ interface TransformOptions {
2085
+ /** 图片宽度,单位为像素。 */
2086
+ width?: number
2087
+ /** 图片高度,单位为像素。 */
2088
+ height?: number
2089
+ /** 缩放模式:`cover` 保持比例裁剪填满;`contain` 保持比例完整适配;`fill` 拉伸填满。 */
2090
+ resize?: 'cover' | 'contain' | 'fill'
2091
+ /** 图片质量,通常取值 20 到 100,数值越大质量越高。 */
2092
+ quality?: number
2093
+ /** 输出格式;`origin` 表示保持原图格式。 */
2094
+ format?: 'origin'
2095
+ }
2096
+
2097
+ interface FileObject {
2098
+ name: string
2099
+ bucket_id: string
2100
+ owner: string
2101
+ id: string
2102
+ updated_at: string
2103
+ created_at: string
2104
+ /** @deprecated */
2105
+ last_accessed_at: string
2106
+ metadata: Record<string, any>
2107
+ buckets: {
2108
+ id: string
2109
+ name: string
2110
+ owner: string
2111
+ public: boolean
2112
+ created_at: string
2113
+ updated_at: string
2114
+ }
2115
+ }
2116
+
2117
+ interface FileObjectV2 {
2118
+ id: string
2119
+ version: string
2120
+ name: string
2121
+ bucketId: string
2122
+ updatedAt: string
2123
+ createdAt: string
2124
+ /** @deprecated */
2125
+ lastAccessedAt: string
2126
+ size?: number
2127
+ cacheControl?: string
2128
+ contentType?: string
2129
+ etag?: string
2130
+ lastModified?: string
2131
+ metadata?: Record<string, any>
2132
+ }
2133
+
2134
+ class StorageError extends Error {
2135
+ name: 'StorageError'
2136
+ constructor(message: string)
2137
+ }
2138
+
2139
+ /**
2140
+ * Supabase 风格的文件存储 API
2141
+ *
2142
+ * 通过 `app.storage` 获取实例,提供类似 Supabase Storage 的操作接口。
2143
+ *
2144
+ * @example
2145
+ * ```typescript
2146
+ * const app = cloudbase.init({ env: 'your-envid' })
2147
+ * const bucket = app.storage.from('my-bucket')
2148
+ *
2149
+ * // 上传文件
2150
+ * const { data, error } = await bucket.upload('path/to/file.jpg', file)
2151
+ *
2152
+ * // 获取签名 URL
2153
+ * const { data } = await bucket.createSignedUrl('path/to/file.jpg', 3600)
2154
+ *
2155
+ * // 下载文件
2156
+ * const { data } = await bucket.download('path/to/file.jpg')
2157
+ * ```
2158
+ */
2159
+ interface ClassicStorageFileApi {
2160
+ /**
2161
+ * 启用错误抛出模式,而非返回 `{ data: null, error }` 格式
2162
+ */
2163
+ throwOnError(): this
2164
+
2165
+ /**
2166
+ * 上传文件
2167
+ *
2168
+ * @param path 文件路径
2169
+ * @param fileBody 文件内容
2170
+ * @param fileOptions 上传选项
2171
+ */
2172
+ upload(
2173
+ path: string,
2174
+ fileBody: FileBody,
2175
+ fileOptions?: FileOptions,
2176
+ ): Promise<
2177
+ | { data: { id: string; path: string; fullPath: string }; error: null }
2178
+ | { data: null; error: StorageError }
2179
+ >
2180
+
2181
+ /**
2182
+ * 上传文件到已签名的 URL
2183
+ *
2184
+ * @param path 文件路径
2185
+ * @param token 签名 Token
2186
+ * @param fileBody 文件内容
2187
+ * @param fileOptions 上传选项
2188
+ */
2189
+ uploadToSignedUrl(
2190
+ path: string,
2191
+ token: string,
2192
+ fileBody: FileBody,
2193
+ fileOptions?: FileOptions,
2194
+ ): Promise<
2195
+ | { data: { id: string; path: string; fullPath: string }; error: null }
2196
+ | { data: null; error: StorageError }
2197
+ >
2198
+
2199
+ /**
2200
+ * 创建用于上传的签名 URL
2201
+ *
2202
+ * @param path 文件路径
2203
+ */
2204
+ createSignedUploadUrl(path: string): Promise<
2205
+ | {
2206
+ data: {
2207
+ signedUrl: string
2208
+ token: string
2209
+ path: string
2210
+ authorization?: string
2211
+ id?: string
2212
+ cosFileId?: string
2213
+ downloadUrl?: string
2214
+ }
2215
+ error: null
2216
+ }
2217
+ | { data: null; error: StorageError }
2218
+ >
2219
+
2220
+ /**
2221
+ * 更新(覆盖)文件
2222
+ *
2223
+ * @param path 文件路径
2224
+ * @param fileBody 文件内容
2225
+ * @param fileOptions 上传选项
2226
+ */
2227
+ update(
2228
+ path: string,
2229
+ fileBody: FileBody,
2230
+ fileOptions?: FileOptions,
2231
+ ): Promise<
2232
+ | { data: { id: string; path: string; fullPath: string }; error: null }
2233
+ | { data: null; error: StorageError }
2234
+ >
2235
+
2236
+ /**
2237
+ * 移动文件(复制后删除源文件)
2238
+ *
2239
+ * @param fromPath 源文件路径
2240
+ * @param toPath 目标文件路径
2241
+ */
2242
+ move(
2243
+ fromPath: string,
2244
+ toPath: string,
2245
+ ): Promise<
2246
+ | { data: { message: string }; error: null }
2247
+ | { data: null; error: StorageError }
2248
+ >
2249
+
2250
+ /**
2251
+ * 复制文件
2252
+ *
2253
+ * @param fromPath 源文件路径
2254
+ * @param toPath 目标文件路径
2255
+ */
2256
+ copy(
2257
+ fromPath: string,
2258
+ toPath: string,
2259
+ ): Promise<
2260
+ | { data: { path: string }; error: null }
2261
+ | { data: null; error: StorageError }
2262
+ >
2263
+
2264
+ /**
2265
+ * 创建签名下载 URL
2266
+ *
2267
+ * @param path 文件路径
2268
+ * @param expiresIn 有效期(秒)
2269
+ * @param options 可选配置
2270
+ */
2271
+ createSignedUrl(
2272
+ path: string,
2273
+ expiresIn: number,
2274
+ options?: {
2275
+ download?: string | boolean
2276
+ transform?: TransformOptions
2277
+ },
2278
+ ): Promise<
2279
+ | { data: { signedUrl: string }; error: null }
2280
+ | { data: null; error: StorageError }
2281
+ >
2282
+
2283
+ /**
2284
+ * 批量创建签名下载 URL
2285
+ *
2286
+ * @param paths 文件路径数组
2287
+ * @param expiresIn 有效期(秒)
2288
+ */
2289
+ createSignedUrls(
2290
+ paths: string[],
2291
+ expiresIn: number,
2292
+ ): Promise<
2293
+ | { data: Array<{ path: string; signedUrl: string; error: string | null }>; error: null }
2294
+ | { data: null; error: StorageError }
2295
+ >
2296
+
2297
+ /**
2298
+ * 下载文件,返回 Blob
2299
+ *
2300
+ * @param path 文件路径
2301
+ * @param options 图片转换选项
2302
+ */
2303
+ download(
2304
+ path: string,
2305
+ options?: TransformOptions,
2306
+ ): Promise<{ data: Blob; error: StorageError | null }>
2307
+
2308
+ /**
2309
+ * 获取文件详细信息
2310
+ *
2311
+ * @param pathOrFileId 相对路径或 CloudBase fileID
2312
+ */
2313
+ info(pathOrFileId: string): Promise<
2314
+ | { data: FileObjectV2; error: null }
2315
+ | { data: null; error: StorageError }
2316
+ >
2317
+
2318
+ /**
2319
+ * 检查文件是否存在
2320
+ *
2321
+ * @param pathOrFileId 相对路径或 CloudBase fileID
2322
+ */
2323
+ exists(pathOrFileId: string): Promise<
2324
+ | { data: boolean; error: null }
2325
+ | { data: null; error: StorageError }
2326
+ >
2327
+
2328
+ /**
2329
+ * 获取文件的公开 URL
2330
+ *
2331
+ * @param path 文件路径
2332
+ * @param options 可选配置
2333
+ */
2334
+ getPublicUrl(
2335
+ path: string,
2336
+ options?: {
2337
+ download?: string | boolean
2338
+ transform?: TransformOptions
2339
+ },
2340
+ ): Promise<
2341
+ | { data: { publicUrl: string } }
2342
+ | { data: null; error: StorageError }
2343
+ >
2344
+
2345
+ /**
2346
+ * 批量删除文件
2347
+ *
2348
+ * @param paths 文件路径数组
2349
+ */
2350
+ remove(paths: string[]): Promise<
2351
+ | { data: FileObject[]; error: null }
2352
+ | { data: null; error: StorageError }
2353
+ >
2354
+ }
2355
+
2356
+ /**
2357
+ * Bucket 管理 API,挂载在 `app.storage` 上。
2358
+ *
2359
+ * @remarks 权限由 `storage.buckets` 的 RLS Policy 决定。暂不提供
2360
+ * `emptyBucket()`、`headBucket()`、Bucket CORS、Bucket ACL 等 COS/S3 风格 Bucket 管理 API。
2361
+ */
2362
+ interface StorageBucketApi {
2363
+ /**
2364
+ * 启用错误抛出模式。开启后请求失败会抛异常;请求成功仍返回 `{ data, error: null }`。
2365
+ * 该设置会传递给 `from()` 返回的客户端。
2366
+ */
2367
+ throwOnError(): this
2368
+
2369
+ /**
2370
+ * 获取 Bucket 列表,支持偏移分页、排序和搜索。
2371
+ *
2372
+ * @param options 查询参数:`limit`、`offset`、`sortColumn`、`sortOrder`、`search`。
2373
+ */
2374
+ listBuckets(options?: ListBucketOptions): Promise<
2375
+ | { data: Bucket[]; error: null }
2376
+ | { data: null; error: StorageError }
2377
+ >
2378
+
2379
+ /**
2380
+ * 获取指定 Bucket 详情。
2381
+ *
2382
+ * @param bucketId Bucket ID。
2383
+ */
2384
+ getBucket(bucketId: string): Promise<
2385
+ | { data: Bucket; error: null }
2386
+ | { data: null; error: StorageError }
2387
+ >
2388
+
2389
+ /**
2390
+ * 创建 Bucket。
2391
+ *
2392
+ * @param bucketId Bucket ID,同时作为后端 `id` 与 `name` 传入。
2393
+ * @param options 创建参数:`public`、`fileSizeLimit`、`allowedMimeTypes`、`type`。
2394
+ * @remarks `public` 默认 `false`。
2395
+ */
2396
+ createBucket(bucketId: string, options?: CreateBucketOptions): Promise<
2397
+ | { data: { name: string }; error: null }
2398
+ | { data: null; error: StorageError }
2399
+ >
2400
+
2401
+ /**
2402
+ * 更新 Bucket 配置。
2403
+ *
2404
+ * @param bucketId Bucket ID。
2405
+ * @param options 更新参数:`public`、`fileSizeLimit`、`allowedMimeTypes`。不支持更新 `type`。
2406
+ */
2407
+ updateBucket(bucketId: string, options: UpdateBucketOptions): Promise<
2408
+ | { data: { message: string }; error: null }
2409
+ | { data: null; error: StorageError }
2410
+ >
2411
+
2412
+ /**
2413
+ * 删除空 Bucket。
2414
+ *
2415
+ * @param bucketId Bucket ID。
2416
+ * @remarks Bucket 非空时后端会返回错误。
2417
+ */
2418
+ deleteBucket(bucketId: string): Promise<
2419
+ | { data: { message: string }; error: null }
2420
+ | { data: null; error: StorageError }
2421
+ >
2422
+ }
2423
+
2424
+ /**
2425
+ * `app.storage` 命名空间(分流器)。继承 `StorageBucketApi` 的 Bucket 管理能力,并提供 `from()` 分流。
2426
+ *
2427
+ * `from()` 分流到两个**对等且独立**的客户端——`ClassicStorageFileApi`(传统环境)
2428
+ * 与 `StorageFileApi`(针对全新的 Neo 环境)。
2429
+ *
2430
+ * - `from()`:返回 `ClassicStorageFileApi`;
2431
+ * - `from(bucketId)`:返回 `StorageFileApi`。
2432
+ */
2433
+ interface StorageClient extends StorageBucketApi {
2434
+ /**
2435
+ * 进入对象操作客户端。
2436
+ *
2437
+ * - `from()`(不传 bucketId):返回传统环境对象操作客户端;
2438
+ * - `from(bucketId)`:返回 Neo 环境对象操作(`bucketId + objectName` 语义)客户端。
2439
+ *
2440
+ * @remarks 传入 `bucketId` 时返回的客户端仅 Neo 环境可用。
2441
+ *
2442
+ * @example
2443
+ * ```typescript
2444
+ * // 传统环境
2445
+ * const file = app.storage.from()
2446
+ * // Neo 环境
2447
+ * const avatars = app.storage.from('avatars')
2448
+ * ```
2449
+ */
2450
+ from(): ClassicStorageFileApi
2451
+ from<B extends string>(bucketId: B): StorageFileApi
2452
+ }
2453
+
2454
+ // ==================== Storage 类型 ====================
2455
+ // 以下类型通过 app.storage.from(bucketId) 与 Bucket 管理 API 暴露。
2456
+
2457
+ type BucketType = 'STANDARD'
2458
+
2459
+ /** Bucket 资源(对应 storage.buckets 表记录)。 */
2460
+ interface Bucket {
2461
+ /** Bucket ID。 */
2462
+ id: string
2463
+ /** Bucket 名称。 */
2464
+ name: string
2465
+ /** 创建者用户 ID;可能为空。 */
2466
+ owner_id?: string | null
2467
+ /** 是否为公开 Bucket。 */
2468
+ public: boolean
2469
+ /** Bucket 类型。 */
2470
+ type?: BucketType
2471
+ /** 文件大小限制,单位为字节;`null` 表示不限制。 */
2472
+ file_size_limit?: number | null
2473
+ /** 允许上传的 MIME 类型列表;`null` 表示不限制。 */
2474
+ allowed_mime_types?: string[] | null
2475
+ /** 创建时间,ISO 8601 日期时间字符串。 */
2476
+ created_at: string
2477
+ /** 更新时间,ISO 8601 日期时间字符串。 */
2478
+ updated_at: string
2479
+ }
2480
+
2481
+ interface ListBucketOptions {
2482
+ /** 返回数量限制。 */
2483
+ limit?: number
2484
+ /** 分页偏移量。 */
2485
+ offset?: number
2486
+ /** 排序字段。 */
2487
+ sortColumn?: 'id' | 'name' | 'created_at' | 'updated_at'
2488
+ /** 排序方向。 */
2489
+ sortOrder?: 'asc' | 'desc'
2490
+ /** 搜索关键词。 */
2491
+ search?: string
2492
+ }
2493
+
2494
+ interface CreateBucketOptions {
2495
+ /** 是否公开,默认 `false`。 */
2496
+ public?: boolean
2497
+ /** 文件大小限制;数字按字节处理,字符串支持如 `100MB`,`null` 表示不限制。 */
2498
+ fileSizeLimit?: number | string | null
2499
+ /** 允许上传的 MIME 类型列表,`null` 表示不限制。 */
2500
+ allowedMimeTypes?: string[] | null
2501
+ /** Bucket 类型,仅创建时可传。 */
2502
+ type?: BucketType
2503
+ }
2504
+
2505
+ interface UpdateBucketOptions {
2506
+ /** 是否公开。 */
2507
+ public?: boolean
2508
+ /** 文件大小限制;数字按字节处理,字符串支持如 `100MB`,`null` 表示不限制。 */
2509
+ fileSizeLimit?: number | string | null
2510
+ /** 允许上传的 MIME 类型列表,`null` 表示不限制。 */
2511
+ allowedMimeTypes?: string[] | null
2512
+ }
2513
+
2514
+ /** 上传选项。 */
2515
+ type UploadOptions = FileOptions
2516
+
2517
+ interface UploadResult {
2518
+ /** 对象 UUID(后端 `Id`)。 */
2519
+ id: string
2520
+ /** Bucket 内相对路径。 */
2521
+ path: string
2522
+ /** 对象完整路径 `bucketId/objectName`(后端 `Key`)。 */
2523
+ fullPath: string
2524
+ }
2525
+
2526
+ interface DownloadOptions {
2527
+ /** 触发浏览器下载,传字符串作为下载文件名。 */
2528
+ download?: string | boolean
2529
+ /** 缓存失效 nonce,追加到请求 URL 以绕过 CDN 缓存。 */
2530
+ cacheNonce?: string
2531
+ }
2532
+
2533
+ interface ListOptions {
2534
+ /** 返回数量限制。 */
2535
+ limit?: number
2536
+ /** 翻页游标,由上一页响应的 `nextCursor` 提供。 */
2537
+ cursor?: string
2538
+ /** 是否使用 `/` 作为分隔符区分文件夹。 */
2539
+ withDelimiter?: boolean
2540
+ /** 排序配置。 */
2541
+ sortBy?: {
2542
+ /** 排序字段。 */
2543
+ column?: 'name' | 'created_at' | 'updated_at'
2544
+ /** 排序方向。 */
2545
+ order?: 'asc' | 'desc'
2546
+ }
2547
+ }
2548
+
2549
+ interface ListObjectsEntry {
2550
+ /** 对象完整 key;文件夹条目可能为空。 */
2551
+ key?: string | null
2552
+ /** 对象名或文件夹名。 */
2553
+ name: string
2554
+ /** 对象 UUID;文件夹条目可能为空。 */
2555
+ id?: string | null
2556
+ /** 更新时间,ISO 8601 日期时间字符串。 */
2557
+ updated_at?: string | null
2558
+ /** 创建时间,ISO 8601 日期时间字符串。 */
2559
+ created_at?: string | null
2560
+ /** 最后访问时间,ISO 8601 日期时间字符串。 */
2561
+ last_accessed_at?: string | null
2562
+ /** 对象元数据。 */
2563
+ metadata?: Record<string, any> | null
2564
+ }
2565
+
2566
+ interface ListObjectsResponse {
2567
+ /** 当前前缀下的文件夹条目。 */
2568
+ folders: ListObjectsEntry[]
2569
+ /** 当前前缀下的对象条目。 */
2570
+ objects: ListObjectsEntry[]
2571
+ /** 是否还有下一页。 */
2572
+ hasNext: boolean
2573
+ /** 下一页游标。 */
2574
+ nextCursor?: string
2575
+ /** 下一页起始 key。 */
2576
+ nextCursorKey?: string
2577
+ }
2578
+
2579
+ interface ObjectInfo {
2580
+ /** 对象 UUID。 */
2581
+ id: string
2582
+ /** Bucket 内相对路径。 */
2583
+ name: string
2584
+ /** 对象版本标识;可能为空。 */
2585
+ version?: string | null
2586
+ /** 所属 Bucket ID。 */
2587
+ bucketId: string
2588
+ /** 文件大小,单位为字节;可能为空。 */
2589
+ size?: number | null
2590
+ /** 文件 MIME 类型;可能为空。 */
2591
+ contentType?: string | null
2592
+ /** 缓存控制信息;可能为空。 */
2593
+ cacheControl?: string | null
2594
+ /** 对象 ETag;可能为空。 */
2595
+ etag?: string | null
2596
+ /** 用户自定义元数据。 */
2597
+ metadata?: Record<string, any>
2598
+ /** 最后修改时间,ISO 8601 日期时间字符串。 */
2599
+ lastModified?: string | null
2600
+ /** 创建时间,ISO 8601 日期时间字符串。 */
2601
+ createdAt?: string | null
2602
+ }
2603
+
2604
+ interface FullObject {
2605
+ /** Bucket 内相对路径。 */
2606
+ name: string
2607
+ /** 所属 Bucket ID。 */
2608
+ bucket_id: string
2609
+ /** 创建者用户 ID;可能为空。 */
2610
+ owner_id?: string | null
2611
+ /** 对象版本标识;可能为空。 */
2612
+ version?: string | null
2613
+ /** 对象 UUID;可能为空。 */
2614
+ id?: string | null
2615
+ /** 更新时间,ISO 8601 日期时间字符串。 */
2616
+ updated_at?: string | null
2617
+ /** 创建时间,ISO 8601 日期时间字符串。 */
2618
+ created_at?: string | null
2619
+ /** 最后访问时间,ISO 8601 日期时间字符串。 */
2620
+ last_accessed_at?: string | null
2621
+ /** 系统或对象元数据。 */
2622
+ metadata?: Record<string, any>
2623
+ /** 用户自定义元数据。 */
2624
+ user_metadata?: Record<string, any>
2625
+ }
2626
+
2627
+ interface DestinationOptions {
2628
+ /** 目标 Bucket ID,默认与源相同。 */
2629
+ destinationBucket?: string
2630
+ /** 允许覆盖目标位置已有对象。 */
2631
+ upsert?: boolean
2632
+ /** 是否复制源对象元数据,默认 true。 */
2633
+ copyMetadata?: boolean
2634
+ /** `copyMetadata=false` 时合并到目标对象的用户元数据。 */
2635
+ metadata?: Record<string, any>
2636
+ }
2637
+
2638
+ interface SignedUrlOptions {
2639
+ /** 触发浏览器下载,传字符串作为下载文件名。 */
2640
+ download?: string | boolean
2641
+ /** 缓存失效 nonce,追加到请求 URL 以绕过 CDN 缓存。 */
2642
+ cacheNonce?: string
2643
+ }
2644
+
2645
+ /** 公开 URL 选项。 */
2646
+ interface PublicUrlOptions {
2647
+ /** 触发浏览器下载,传字符串作为下载文件名。 */
2648
+ download?: string | boolean
2649
+ /** 缓存失效 nonce,追加到请求 URL 以绕过 CDN 缓存。 */
2650
+ cacheNonce?: string
2651
+ }
2652
+
2653
+ /**
2654
+ * 请求级 fetch 控制参数(对齐 Supabase `FetchParameters`)。
2655
+ *
2656
+ * 纯客户端能力:`signal` 用于取消请求;`cache` 透传给底层 fetch 的缓存策略
2657
+ * (主要在浏览器 fetch 路径生效,XHR / 部分运行时会忽略)。
2658
+ */
2659
+ interface FetchParameters {
2660
+ /** 请求取消信号。 */
2661
+ signal?: AbortSignal
2662
+ /** 透传给底层 `fetch` 的缓存策略。 */
2663
+ cache?: 'default' | 'no-store' | 'reload' | 'no-cache' | 'force-cache' | 'only-if-cached'
2664
+ }
2665
+
2666
+ /**
2667
+ * 流式下载构建器(thenable)。`await` 后 resolve 为 `Result<ReadableStream>`。
2668
+ * 由 `DownloadBuilder.asStream()` 创建。
2669
+ */
2670
+ interface StreamDownloadBuilder extends PromiseLike<
2671
+ | { data: ReadableStream<Uint8Array>; error: null }
2672
+ | { data: null; error: StorageError }
2673
+ > {}
2674
+
2675
+ /**
2676
+ * 下载构建器(thenable)。默认 `await` 得 `Result<Blob>`;`.asStream()` 切换为流式终态。
2677
+ * 惰性执行:请求在 `await` / `.then()` 时才真正发出。
2678
+ */
2679
+ interface DownloadBuilder extends PromiseLike<
2680
+ | { data: Blob; error: null }
2681
+ | { data: null; error: StorageError }
2682
+ > {
2683
+ /** 切换为流式下载终态,返回 `StreamDownloadBuilder`。 */
2684
+ asStream(): StreamDownloadBuilder
2685
+ }
2686
+
2687
+ /**
2688
+ * 单 Bucket 对象操作客户端。通过 `app.storage.from(bucketId)` 获取。
2689
+ *
2690
+ * @remarks 所有 `objectName` 均为 Bucket 内相对路径。
2691
+ */
2692
+ interface StorageFileApi {
2693
+ /** 当前客户端绑定的 Bucket ID。 */
2694
+ readonly bucketId: string
2695
+
2696
+ /**
2697
+ * 启用错误抛出模式。开启后请求失败会抛异常;请求成功仍返回 `{ data, error: null }`。
2698
+ */
2699
+ throwOnError(): this
2700
+
2701
+ /**
2702
+ * 设置自定义请求头(链式)。
2703
+ *
2704
+ * @remarks 设置后对当前实例后续所有请求生效;每个 `from(bucketId)` 返回独立实例,互不影响。
2705
+ * 单次请求内部的功能性头(如上传的 `Content-Type` / `x-upsert`)优先级更高,会覆盖此处同名头。
2706
+ * name 为空或 name/value 含 CR/LF 时抛 `StorageError`。
2707
+ */
2708
+ setHeader(name: string, value: string): this
2709
+
2710
+ /**
2711
+ * 直接上传对象,默认不覆盖同名对象。
2712
+ *
2713
+ * 需要当前用户已登录,权限由 `storage.objects` 的 RLS `INSERT` / `UPDATE` 策略判定。
2714
+ *
2715
+ * 上传行为:
2716
+ * - `options.upsert` 默认 `false`:目标路径已有对象时,上传失败。
2717
+ * - `options.upsert` 设为 `true`:目标路径已有对象时,覆盖写入。
2718
+ * - 成功时返回 `{ id, path, fullPath }`。
2719
+ *
2720
+ * @param path Bucket 内相对路径。
2721
+ * @param fileBody 文件内容。
2722
+ * @param fileOptions 上传选项,如 `contentType`、`cacheControl`、`upsert`、`metadata`。
2723
+ * @see createSignedUploadUrl uploadToSignedUrl
2724
+ */
2725
+ upload(path: string, fileBody: FileBody, fileOptions?: UploadOptions): Promise<
2726
+ | { data: UploadResult; error: null }
2727
+ | { data: null; error: StorageError }
2728
+ >
2729
+
2730
+ /**
2731
+ * 覆盖更新对象。
2732
+ *
2733
+ * 与 `upload` 共享同一底层,区别:
2734
+ * - 使用 `PUT` 方法(语义为覆盖)。
2735
+ * - 目标路径不存在时也会创建(upsert 行为)。
2736
+ *
2737
+ * @param path Bucket 内相对路径。
2738
+ * @param fileBody 文件内容。
2739
+ * @param fileOptions 上传选项,如 `contentType`、`cacheControl`、`metadata`。
2740
+ */
2741
+ update(path: string, fileBody: FileBody, fileOptions?: UploadOptions): Promise<
2742
+ | { data: UploadResult; error: null }
2743
+ | { data: null; error: StorageError }
2744
+ >
2745
+
2746
+ /**
2747
+ * 下载对象。返回**下载构建器**(thenable),默认 `await` 得到 `Blob`。
2748
+ *
2749
+ * 需要登录态,权限由 `storage.objects` 的 RLS `SELECT` 策略判定。
2750
+ *
2751
+ * 两种终态:
2752
+ * - 默认:`await bucket.download(path)` → `{ data: Blob, error }`。
2753
+ * - 流式:`await bucket.download(path).asStream()` → `{ data: ReadableStream, error }`,
2754
+ * 适合 Node 大文件等不希望整体读入内存的场景。
2755
+ *
2756
+ * 两者统一走原生 `fetch` 的 `Response`:流式终态返回 `Response.body`,Blob 终态调 `Response.blob()`。
2757
+ *
2758
+ * 下载行为:
2759
+ * - 惰性执行:请求在 `await` / `.then()` 时才真正发出。
2760
+ * - 返回的 `Blob` 不会自动触发浏览器下载或渲染,需配合 `URL.createObjectURL` 手动处理。
2761
+ * - 支持 `parameters.signal`(AbortSignal)取消进行中的下载。
2762
+ *
2763
+ * @param path Bucket 内相对路径。
2764
+ * @param options 下载选项,支持 `download`(触发浏览器下载)、`cacheNonce`(绕过 CDN 缓存)。
2765
+ * @param parameters 请求控制参数,支持 `signal` / `cache`。
2766
+ * @returns `DownloadBuilder`:可 `await` 得 `Blob`,或 `.asStream()` 后得 `ReadableStream`。
2767
+ */
2768
+ download(path: string, options?: DownloadOptions, parameters?: FetchParameters): DownloadBuilder
2769
+
2770
+ /**
2771
+ * 获取对象列表(游标分页)。
2772
+ *
2773
+ * 采用**游标分页**,与 Supabase 的 `listV2` 对应。
2774
+ *
2775
+ * - 首次查询不传 `cursor`,后续用上一页的 `nextCursor` 继续翻页。
2776
+ * - 返回 `{ folders, objects, hasNext, nextCursor }`(区别于 Supabase `list` 的 offset 分页 `FileObject[]`)。
2777
+ * - `path` 不传时列出 Bucket 根目录。
2778
+ * - `options.withDelimiter` 为 `true` 时以 `/` 分隔文件夹和文件。
2779
+ *
2780
+ * @param path 路径前缀,不传表示 Bucket 根目录。
2781
+ * @param options 列表选项,支持 `limit`、`cursor`、`withDelimiter`、`sortBy`。
2782
+ * @param parameters 请求控制参数,支持 `signal` / `cache`。
2783
+ * @remarks 本方法对应 Supabase 的 `listV2`(游标分页),而非 `list`(offset 分页)。
2784
+ */
2785
+ list(path?: string, options?: ListOptions, parameters?: FetchParameters): Promise<
2786
+ | { data: ListObjectsResponse; error: null }
2787
+ | { data: null; error: StorageError }
2788
+ >
2789
+
2790
+ /**
2791
+ * 删除一个或多个对象。
2792
+ *
2793
+ * 权限由 `storage.objects` 的 RLS `DELETE` 策略判定。
2794
+ *
2795
+ * - 后端单次最多删除 100 个对象,超出时 SDK 自动分批发送。
2796
+ * - 返回所有被成功删除的对象信息(`FullObject[]`)。
2797
+ *
2798
+ * @param paths Bucket 内相对路径数组。
2799
+ */
2800
+ remove(paths: string[]): Promise<
2801
+ | { data: FullObject[]; error: null }
2802
+ | { data: null; error: StorageError }
2803
+ >
2804
+
2805
+ /**
2806
+ * 复制对象,支持跨 Bucket。
2807
+ *
2808
+ * 权限由 `storage.objects` 的 RLS 策略判定:读取源需要 `SELECT`,写入目标需要 `INSERT`。
2809
+ *
2810
+ * - `options.destinationBucket` 不传时在同一 Bucket 内复制。
2811
+ * - `options.upsert` 为 `true` 时,目标路径已有对象则覆盖。
2812
+ * - `options.copyMetadata` 设为 `false` 并传 `options.metadata` 时替换原 metadata。
2813
+ * - 返回目标对象的完整路径。
2814
+ *
2815
+ * @param fromPath 源对象 Bucket 内相对路径。
2816
+ * @param toPath 目标对象相对路径。
2817
+ * @param options 目标 Bucket、覆盖、元数据复制等选项。
2818
+ */
2819
+ copy(fromPath: string, toPath: string, options?: DestinationOptions): Promise<
2820
+ | { data: { path: string }; error: null }
2821
+ | { data: null; error: StorageError }
2822
+ >
2823
+
2824
+ /**
2825
+ * 移动对象,支持跨 Bucket;源对象会被删除。
2826
+ *
2827
+ * 语义为"复制到目标 → 删除源",非原地重命名。
2828
+ * 权限由 `storage.objects` 的 RLS 策略判定:读取源需要 `SELECT`,写入目标需要 `INSERT`,删除源需要 `DELETE`。
2829
+ *
2830
+ * - `options.destinationBucket` 不传时在同一 Bucket 内移动。
2831
+ *
2832
+ * @param fromPath 源对象 Bucket 内相对路径。
2833
+ * @param toPath 目标对象相对路径。
2834
+ * @param options 目标 Bucket 等选项。
2835
+ */
2836
+ move(fromPath: string, toPath: string, options?: DestinationOptions): Promise<
2837
+ | { data: { message: string }; error: null }
2838
+ | { data: null; error: StorageError }
2839
+ >
2840
+
2841
+ /**
2842
+ * 获取对象元信息。
2843
+ *
2844
+ * 返回对象在 `storage.objects` 表中的记录信息,包括 `bucketId`、`version`、`etag`、
2845
+ * `contentType`、`cacheControl`、`metadata`、`lastModified`、`createdAt` 等。
2846
+ *
2847
+ * @param path Bucket 内相对路径。
2848
+ */
2849
+ info(path: string): Promise<
2850
+ | { data: ObjectInfo; error: null }
2851
+ | { data: null; error: StorageError }
2852
+ >
2853
+
2854
+ /**
2855
+ * 判断对象是否存在。
2856
+ *
2857
+ * 底层调用 `info` 端点:
2858
+ * - HTTP 200 → 存在(返回 `true`)。
2859
+ * - HTTP 400 或 404 → 不存在(返回 `false`)。
2860
+ * - 其他异常 → 返回 `{ data: null, error }`。
2861
+ *
2862
+ * @param path Bucket 内相对路径。
2863
+ */
2864
+ exists(path: string): Promise<
2865
+ | { data: boolean; error: null }
2866
+ | { data: null; error: StorageError }
2867
+ >
2868
+
2869
+ /**
2870
+ * 生成单个对象的签名下载 URL。
2871
+ *
2872
+ * 需要登录态,权限由 `storage.objects` 的 RLS `SELECT` 策略判定。
2873
+ *
2874
+ * - `expiresIn` 以秒为单位,过期后 URL 不可用。
2875
+ * - 返回的 `fullSignedURL` 是服务端已拼接好的完整 URL,客户端可直接使用(无需再拼 HOST)。
2876
+ * - `options.download` 为 `true` 时追加 `?download`,浏览器访问时自动触发下载。
2877
+ *
2878
+ * @param path Bucket 内相对路径。
2879
+ * @param expiresIn 过期时间,单位为秒。
2880
+ * @param options 签名下载 URL 选项;当前仅支持 `download`,不支持图片 `transform`。
2881
+ */
2882
+ createSignedUrl(path: string, expiresIn: number, options?: SignedUrlOptions): Promise<
2883
+ | { data: { fullSignedURL: string }; error: null }
2884
+ | { data: null; error: StorageError }
2885
+ >
2886
+
2887
+ /**
2888
+ * 批量生成对象的签名下载 URL。
2889
+ *
2890
+ * 需要登录态,权限由 `storage.objects` 的 RLS `SELECT` 策略判定。
2891
+ *
2892
+ * - 后端单次最多 500 个,超出时 SDK 自动分批发送。
2893
+ * - 返回数组中每个元素包含 `path`、`fullSignedURL`(完整 URL,生成失败时为 `null`)、`error`。
2894
+ * - 部分路径生成失败不会影响其他路径。
2895
+ *
2896
+ * @param paths Bucket 内相对路径数组。
2897
+ * @param expiresIn 过期时间,单位为秒。
2898
+ * @param options 签名下载 URL 选项;当前仅支持 `download`,不支持图片 `transform`。
2899
+ */
2900
+ createSignedUrls(paths: string[], expiresIn: number, options?: SignedUrlOptions): Promise<
2901
+ | { data: Array<{ path: string; fullSignedURL: string | null; error: string | null }>; error: null }
2902
+ | { data: null; error: StorageError }
2903
+ >
2904
+
2905
+ /**
2906
+ * 两阶段上传(第一阶段):生成签名上传 URL,需登录态。
2907
+ *
2908
+ * 服务端基于调用者身份 + RLS 策略判断上传权限,生成临时签名 URL 和 token。
2909
+ * 适合的场景:服务端鉴定用户权限后,将 `token` 下发给不受信客户端(如浏览器前端),
2910
+ * 让客户端用 `uploadToSignedUrl` 直接上传文件,无需暴露登录凭证。
2911
+ *
2912
+ * - 返回的 `fullSignedURL` 是服务端已拼接好的完整上传 URL。
2913
+ * - 返回的 `token` 是临时凭证,与 `uploadToSignedUrl` 配合使用。
2914
+ * - `options.upsert` 为 `true` 时允许覆盖同名对象。
2915
+ *
2916
+ * @param path Bucket 内相对路径。
2917
+ * @param options 签名上传选项,`upsert=true` 时允许覆盖。
2918
+ * @see uploadToSignedUrl
2919
+ */
2920
+ createSignedUploadUrl(path: string, options?: { upsert?: boolean }): Promise<
2921
+ | { data: { fullSignedURL: string; token: string; path: string }; error: null }
2922
+ | { data: null; error: StorageError }
2923
+ >
2924
+
2925
+ /**
2926
+ * 两阶段上传(第二阶段):使用签名上传 token 上传对象,无需登录态。
2927
+ *
2928
+ * 配合 `createSignedUploadUrl` 完成两阶段上传:
2929
+ * 1. 服务端调用 `createSignedUploadUrl` 生成 token(需登录态)
2930
+ * 2. 客户端调用本方法,凭 token 上传文件(无需登录态)
2931
+ *
2932
+ * - 请求**不携带**登录态,仅凭 `token` 鉴权。
2933
+ * - `path` 和 `token` 必须与 `createSignedUploadUrl` 的返回值对应。
2934
+ *
2935
+ * @param path Bucket 内相对路径,需与 `createSignedUploadUrl` 的 `path` 一致。
2936
+ * @param token `createSignedUploadUrl()` 返回的 `token`。
2937
+ * @param fileBody 文件内容。
2938
+ * @param fileOptions 上传选项。
2939
+ * @see createSignedUploadUrl
2940
+ */
2941
+ uploadToSignedUrl(path: string, token: string, fileBody: FileBody, fileOptions?: UploadOptions): Promise<
2942
+ | { data: { path: string; fullPath: string }; error: null }
2943
+ | { data: null; error: StorageError }
2944
+ >
2945
+
2946
+ /**
2947
+ * 同步获取 public bucket 对象的公开访问 URL;不发请求、不返回 `error`。
2948
+ *
2949
+ * **同步方法**,不发起网络请求,不会抛异常。
2950
+ *
2951
+ * - URL 由客户端直接拼接 `{gateway}/v1/storages/object/public/{bucketId}/{path}` 得到。
2952
+ * - URL 是否可访问取决于 Bucket 的 `public` 属性。
2953
+ * - `options.download` 为 `true` 时追加 `?download`。
2954
+ *
2955
+ * @param path Bucket 内相对路径。
2956
+ * @param options 公开 URL 选项;当前仅支持 `download`,不支持图片 `transform`。
2957
+ */
2958
+ getPublicUrl(path: string, options?: PublicUrlOptions): { data: { publicUrl: string } }
2959
+ }
2960
+ }
2961
+
2962
+ declare namespace cloudbase.database {
2963
+ /**
2964
+ * realtime types
2965
+ */
2966
+ /**
2967
+ * watch() 监听选项
2968
+ */
2969
+ interface IWatchOptions {
2970
+ /**
2971
+ * 数据变化回调。首次建立连接时会触发 `type: 'init'` 的初始化快照,
2972
+ * 后续每次数据变化(增/删/改)都会触发此回调。
2973
+ *
2974
+ * @param snapshot 数据快照,包含当前完整文档列表 `docs` 和本次变化详情 `docChanges`
2975
+ */
2976
+ onChange: (snapshot: ISnapshot) => void
2977
+ /**
2978
+ * 错误回调。在连接失败、token 过期、权限不足等异常时触发。
2979
+ *
2980
+ * **常见错误场景**:
2981
+ * - 未登录或 token 过期:需先调用 `auth.signInAnonymously()` 等方法完成认证
2982
+ * - 权限不足:检查安全规则配置
2983
+ * - 网络中断:SDK 会自动尝试重连,重连失败后触发此回调
2984
+ *
2985
+ * @param error 错误信息
2986
+ */
2987
+ onError: (error: any) => void
2988
+ }
2989
+
2990
+ /**
2991
+ * 实时数据推送监听器。通过 `watch()` 方法返回,用于管理实时监听的生命周期。
2992
+ *
2993
+ * **重要**:在 React 组件卸载或不再需要监听时,务必调用 `close()` 释放资源,
2994
+ * 避免内存泄漏和不必要的网络连接。
2995
+ */
2996
+ interface DBRealtimeListener {
2997
+ /**
2998
+ * 关闭实时推送,释放 WebSocket 连接和相关资源。
2999
+ *
3000
+ * {@link https://docs.cloudbase.net/api-reference/webv3-next/database.html#shu-ju-ku-shi-shi-tui-song}
3001
+ *
3002
+ * @example
3003
+ * ```typescript
3004
+ * // 启动监听
3005
+ * const listener = db
3006
+ * .collection('messages')
3007
+ * .where({ roomId: 'room-1' })
3008
+ * .watch({
3009
+ * onChange: (snapshot) => {
3010
+ * console.log('数据更新:', snapshot.docs);
3011
+ * },
3012
+ * onError: (error) => {
3013
+ * console.error('监听异常:', error);
3014
+ * }
3015
+ * });
3016
+ *
3017
+ * // 不再需要时关闭监听
3018
+ * listener.close();
3019
+ *
3020
+ * // React 组件中的最佳实践
3021
+ * useEffect(() => {
3022
+ * const listener = db.collection('xxx').watch({ onChange, onError });
3023
+ * return () => listener.close(); // 组件卸载时自动清理
3024
+ * }, []);
3025
+ * ```
3026
+ */
3027
+ close: () => void
3028
+ }
3029
+
3030
+ /**
3031
+ * 数据变化类型
3032
+ * - `'init'`:初始化数据(首次连接时返回的完整数据)
3033
+ * - `'update'`:文档被更新
3034
+ * - `'add'`:新增文档
3035
+ * - `'remove'`:文档被删除
3036
+ * - `'replace'`:文档被替换(set 操作)
3037
+ * - `'limit'`:因 limit 限制导致的数据变化
3038
+ */
3039
+ type DataType = 'init' | 'update' | 'add' | 'remove' | 'replace' | 'limit'
3040
+
3041
+ /**
3042
+ * 队列操作类型
3043
+ * - `'init'`:初始化(对应 DataType 的 init)
3044
+ * - `'enqueue'`:文档进入监听结果集(新增或开始匹配查询条件)
3045
+ * - `'dequeue'`:文档离开监听结果集(删除或不再匹配查询条件)
3046
+ * - `'update'`:文档在结果集中被更新
3047
+ */
3048
+ type QueueType = 'init' | 'enqueue' | 'dequeue' | 'update'
3049
+
3050
+ /**
3051
+ * 数据快照,每次 watch 回调都会收到此对象。
3052
+ *
3053
+ * **使用方式**:
3054
+ * - 获取当前完整数据列表:使用 `snapshot.docs`(数组,包含所有匹配文档的最新状态)
3055
+ * - 获取本次变化详情:使用 `snapshot.docChanges`(数组,仅包含本次变化的文档信息)
3056
+ * - 判断是否为初始化数据:检查 `snapshot.type === 'init'`
3057
+ *
3058
+ * @example
3059
+ * ```typescript
3060
+ * onChange: (snapshot) => {
3061
+ * if (snapshot.type === 'init') {
3062
+ * // 首次连接,snapshot.docs 包含初始完整数据
3063
+ * console.log('初始数据:', snapshot.docs);
3064
+ * } else {
3065
+ * // 后续变化
3066
+ * snapshot.docChanges.forEach(change => {
3067
+ * switch (change.dataType) {
3068
+ * case 'add':
3069
+ * console.log('新增文档:', change.doc);
3070
+ * break;
3071
+ * case 'update':
3072
+ * console.log('更新文档:', change.docId, change.updatedFields);
3073
+ * break;
3074
+ * case 'remove':
3075
+ * console.log('删除文档:', change.docId);
3076
+ * break;
3077
+ * }
3078
+ * });
3079
+ * // snapshot.docs 始终是变化后的完整数据列表
3080
+ * console.log('当前全部数据:', snapshot.docs);
3081
+ * }
3082
+ * }
3083
+ * ```
3084
+ */
3085
+ interface ISnapshot {
3086
+ /** 快照序列号,单调递增 */
3087
+ id: number
3088
+ /** 本次变化的文档详情列表 */
3089
+ docChanges: ISingleDBEvent[]
3090
+ /** 当前完整的文档列表(变化后的最新状态) */
3091
+ docs: Record<string, any>[]
3092
+ /** 快照类型,`'init'` 表示初始化数据 */
3093
+ type?: SnapshotType
3094
+ }
3095
+
3096
+ /**
3097
+ * 单个文档变化事件
3098
+ */
3099
+ interface ISingleDBEvent {
3100
+ /** 事件序列号 */
3101
+ id: number
3102
+ /** 数据变化类型:init/add/update/remove/replace/limit */
3103
+ dataType: DataType
3104
+ /** 队列操作类型:init/enqueue/dequeue/update */
3105
+ queueType: QueueType
3106
+ /** 变化文档的 ID */
3107
+ docId: string
3108
+ /** 变化后的完整文档内容(remove 时为删除前的文档) */
3109
+ doc: Record<string, any>
3110
+ /** 被更新的字段及新值(仅 dataType 为 update 时存在) */
3111
+ updatedFields?: any
3112
+ /** 被删除的字段列表(仅 dataType 为 update 时存在) */
3113
+ removedFields?: any
3114
+ }
3115
+
3116
+ /** 快照类型。`'init'` 表示首次连接时返回的初始化数据 */
3117
+ type SnapshotType = 'init'
3118
+
3119
+ interface IWatchable {
3120
+ /**
3121
+ * 开启实时数据推送,监听集合或文档的数据变化。
3122
+ *
3123
+ * **前置条件**:使用 `watch()` 前必须先完成用户认证(如匿名登录),
3124
+ * 否则 WebSocket 连接会因缺少认证信息而失败。
3125
+ *
3126
+ * {@link https://docs.cloudbase.net/api-reference/webv3-next/database#%E6%95%B0%E6%8D%AE%E5%BA%93%E5%AE%9E%E6%97%B6%E6%8E%A8%E9%80%81}
3127
+ *
3128
+ * @example
3129
+ * ```typescript
3130
+ * // === 完整示例:匿名登录 + watch + React 集成 ===
3131
+ * import Cloudbase from '@cloudbase/js-sdk';
3132
+ * import { useEffect, useState } from 'react';
3133
+ *
3134
+ * const app = Cloudbase.init({ env: 'your-env-id', region: 'ap-shanghai' });
3135
+ *
3136
+ * function RoomList() {
3137
+ * const [rooms, setRooms] = useState<any[]>([]);
3138
+ * const [error, setError] = useState<string | null>(null);
3139
+ *
3140
+ * useEffect(() => {
3141
+ * let listener: cloudbase.database.DBRealtimeListener | null = null;
3142
+ *
3143
+ * async function setup() {
3144
+ * // 第一步:必须先完成认证
3145
+ * const auth = app.auth();
3146
+ * const { error: authError } = await auth.signInAnonymously();
3147
+ * if (authError) {
3148
+ * setError('登录失败: ' + authError.message);
3149
+ * return;
3150
+ * }
3151
+ *
3152
+ * // 第二步:认证成功后开启 watch
3153
+ * const db = app.database();
3154
+ * listener = db.collection('rooms')
3155
+ * .where({ status: 'active' })
3156
+ * .watch({
3157
+ * onChange: (snapshot) => {
3158
+ * // snapshot.docs 包含当前所有匹配文档
3159
+ * setRooms(snapshot.docs as any[]);
3160
+ * },
3161
+ * onError: (err) => {
3162
+ * console.error('watch 错误:', err);
3163
+ * setError('实时同步异常: ' + (err?.message || err));
3164
+ * }
3165
+ * });
3166
+ * }
3167
+ *
3168
+ * setup();
3169
+ *
3170
+ * // 第三步:组件卸载时清理监听
3171
+ * return () => {
3172
+ * if (listener) listener.close();
3173
+ * };
3174
+ * }, []);
3175
+ *
3176
+ * if (error) return <div>错误: {error}</div>;
3177
+ * return (
3178
+ * <ul>
3179
+ * {rooms.map(room => <li key={room._id}>{room.name}</li>)}
3180
+ * </ul>
3181
+ * );
3182
+ * }
3183
+ * ```
3184
+ *
3185
+ * @param options 监听选项
3186
+ * @param options.onChange 数据变化回调,接收 {@link ISnapshot} 快照对象
3187
+ * @param options.onError 错误回调,在连接异常、认证失败等情况下触发
3188
+ *
3189
+ * @returns {@link DBRealtimeListener} 监听器实例,调用 `close()` 可停止监听
3190
+ */
3191
+ watch(options: IWatchOptions): DBRealtimeListener
3192
+ }
3193
+ /**
3194
+ * collection types
3195
+ */
3196
+ interface ICollection extends IQuery {
3197
+ /**
3198
+ * 向集合中添加一条新记录
3199
+ *
3200
+ * {@link https://docs.cloudbase.net/api-reference/webv3-next/database#add}
3201
+ *
3202
+ * @example
3203
+ * const result = await db.collection('todos').add({
3204
+ * title: '学习 CloudBase',
3205
+ * completed: false
3206
+ * })
3207
+ * console.log('新增成功,文档 ID:', result.id)
3208
+ *
3209
+ * @param data 要新增的数据对象或数据对象数组,支持嵌套对象、数组、地理位置等数据类型
3210
+ *
3211
+ * @return Promise<AddRes> 包含新增文档的 id(单条)或 ids(批量)和 requestId
3212
+ */
3213
+ add(data: Object | Object[]): Promise<AddRes>
3214
+ /**
3215
+ * 获取一条文档的引用
3216
+ *
3217
+ * {@link https://docs.cloudbase.net/api-reference/webv3-next/database#record--document}
3218
+ *
3219
+ * @param id 文档ID
3220
+ */
3221
+ doc(id: string | number): IDocument
3222
+ /**
3223
+ * 获取聚合操作对象
3224
+ *
3225
+ * {@link https://docs.cloudbase.net/api-reference/webv3-next/database#aggregate}
3226
+ *
3227
+ * @example
3228
+ * const result = await db.collection('todos')
3229
+ * .aggregate()
3230
+ * .group({ _id: '$priority', count: { $sum: 1 } })
3231
+ * .end()
3232
+ *
3233
+ * @return 聚合操作对象,可链式调用各种聚合阶段方法
3234
+ */
3235
+ aggregate(): IAggregate
3236
+ }
3237
+ /**
3238
+ * command types
3239
+ */
3240
+ interface IGeoNearOptions {
3241
+ geometry: IGeo['Point'] // 点的地理位置
3242
+ maxDistance?: number // 选填,最大距离,米为单位
3243
+ minDistance?: number // 选填,最小距离,米为单位
3244
+ }
3245
+ interface IGeoWithinOptions {
3246
+ geometry: IPolygon | IMultiPolygon
3247
+ }
3248
+ interface IGeoIntersectsOptions {
3249
+ geometry: IPoint | ILineString | IMultiPoint | IMultiLineString | IPolygon | IMultiPolygon
3250
+ }
3251
+ interface ICommand {
3252
+ /**
3253
+ * 表示字段等于某个值
3254
+ *
3255
+ * {@link https://docs.cloudbase.net/api-reference/webv3-next/database#eq}
3256
+ *
3257
+ * @example
3258
+ * const _ = db.command;
3259
+ * db.collection("demo").where({
3260
+ * num: _.eq(10)
3261
+ * })
3262
+ *
3263
+ * @param val 接受一个字面量 (literal),可以是 `number`, `boolean`, `string`, `object`, `array`
3264
+ *
3265
+ */
3266
+ eq(val: number | string | boolean | Object | any[]): any
3267
+ /**
3268
+ * 表示字段不等于某个值
3269
+ *
3270
+ * {@link https://docs.cloudbase.net/api-reference/webv3-next/database#neq}
3271
+ *
3272
+ * @example
3273
+ * const _ = db.command;
3274
+ * db.collection("demo").where({
3275
+ * num: _.neq(10)
3276
+ * })
3277
+ *
3278
+ * @param val 接受一个字面量 (literal),可以是 `number`, `boolean`, `string`, `object`, `array`
3279
+ *
3280
+ */
3281
+ neq(val: number | string | boolean | Object | any[]): any
3282
+ /**
3283
+ * 字段大于指定值
3284
+ *
3285
+ * {@link https://docs.cloudbase.net/api-reference/webv3-next/database#gt}
3286
+ *
3287
+ * @example
3288
+ * const _ = db.command;
3289
+ * db.collection("demo").where({
3290
+ * num: _.gt(10)
3291
+ * })
3292
+ *
3293
+ * @param val 数字
3294
+ *
3295
+ */
3296
+ gt(val: number): any
3297
+ /**
3298
+ * 字段大于或等于指定值
3299
+ *
3300
+ * {@link https://docs.cloudbase.net/api-reference/webv3-next/database#neq}
3301
+ *
3302
+ * @example
3303
+ * const _ = db.command;
3304
+ * db.collection("demo").where({
3305
+ * num: _.gte(10)
3306
+ * })
3307
+ *
3308
+ * @param val 数字
3309
+ *
3310
+ */
3311
+ gte(val: number): any
3312
+ /**
3313
+ * 字段小于指定值
3314
+ *
3315
+ * {@link https://docs.cloudbase.net/api-reference/webv3-next/database#lt}
3316
+ *
3317
+ * @example
3318
+ * const _ = db.command;
3319
+ * db.collection("demo").where({
3320
+ * num: _.lt(10)
3321
+ * })
3322
+ *
3323
+ * @param val 数字
3324
+ *
3325
+ */
3326
+ lt(val: number): any
3327
+ /**
3328
+ * 字段小于或等于指定值
3329
+ *
3330
+ * {@link https://docs.cloudbase.net/api-reference/webv3-next/database#lte}
3331
+ *
3332
+ * @example
3333
+ * const _ = db.command;
3334
+ * db.collection("demo").where({
3335
+ * num: _.lte(10)
3336
+ * })
3337
+ *
3338
+ * @param val 数字
3339
+ *
3340
+ */
3341
+ lte(val: number): any
3342
+ /**
3343
+ * 字段值在给定的数组中
3344
+ *
3345
+ * {@link https://docs.cloudbase.net/api-reference/webv3-next/database#in}
3346
+ *
3347
+ * @example
3348
+ * const _ = db.command;
3349
+ * db.collection("demo").where({
3350
+ * num: _.in([1,2,3])
3351
+ * })
3352
+ *
3353
+ * @param list 数组
3354
+ *
3355
+ */
3356
+ in(list: any[]): any
3357
+ /**
3358
+ * 字段值不在给定的数组中
3359
+ *
3360
+ * {@link https://docs.cloudbase.net/api-reference/webv3-next/database#nin}
3361
+ *
3362
+ * @example
3363
+ * const _ = db.command;
3364
+ * db.collection("demo").where({
3365
+ * num: _.nin([1,2,3])
3366
+ * })
3367
+ *
3368
+ * @param list 数组
3369
+ *
3370
+ */
3371
+ nin(list: any[]): any
3372
+ /**
3373
+ * 表示需同时满足指定的两个或以上的条件
3374
+ *
3375
+ * {@link https://docs.cloudbase.net/api-reference/webv3-next/database#and}
3376
+ *
3377
+ * @example
3378
+ * const _ = db.command;
3379
+ * db.collection("demo").where({
3380
+ * num: _.and(_.gt(4), _.lt(32))
3381
+ * })
3382
+ *
3383
+ * @param args 多个条件
3384
+ *
3385
+ */
3386
+ and(...args: any[]): any
3387
+ /**
3388
+ * 表示需满足所有指定条件中的至少一个
3389
+ *
3390
+ * {@link https://docs.cloudbase.net/api-reference/webv3-next/database#or}
3391
+ *
3392
+ * @example
3393
+ * const _ = db.command;
3394
+ * db.collection("demo").where({
3395
+ * num: _.or(_.gt(4), _.lt(32))
3396
+ * })
3397
+ *
3398
+ * @param args 多个条件
3399
+ *
3400
+ */
3401
+ or(...args: any[]): any
3402
+ /**
3403
+ * 用于设定字段等于指定值
3404
+ *
3405
+ * {@link https://docs.cloudbase.net/api-reference/webv3-next/database#set}
3406
+ *
3407
+ * @example
3408
+ * const _ = db.command;
3409
+ * db.collection("demo")
3410
+ * .doc("doc-id")
3411
+ * .update({
3412
+ * data: {
3413
+ * style: _.set({
3414
+ * color: "red"
3415
+ * })
3416
+ * }
3417
+ * });
3418
+ *
3419
+ * @param val 被设定的属性对象
3420
+ *
3421
+ */
3422
+ set(val: any): any
3423
+ /**
3424
+ * 用于指示字段自增某个值
3425
+ *
3426
+ * {@link https://docs.cloudbase.net/api-reference/webv3-next/database#inc}
3427
+ *
3428
+ * @example
3429
+ * const _ = db.command;
3430
+ * db.collection("demo")
3431
+ * .doc("doc-id")
3432
+ * .update({
3433
+ * count: {
3434
+ * favorites: _.inc(1)
3435
+ * }
3436
+ * });
3437
+ *
3438
+ * @param val 自增的值
3439
+ *
3440
+ */
3441
+ inc(val: number): any
3442
+ /**
3443
+ * 用于指示字段自乘某个值
3444
+ *
3445
+ * {@link https://docs.cloudbase.net/api-reference/webv3-next/database#mul}
3446
+ *
3447
+ * @example
3448
+ * const _ = db.command;
3449
+ * db.collection("demo")
3450
+ * .doc("doc-id")
3451
+ * .update({
3452
+ * count: {
3453
+ * favorites: _.mul(21)
3454
+ * }
3455
+ * });
3456
+ *
3457
+ * @param val 自乘的值
3458
+ *
3459
+ */
3460
+ mul(val: number): any
3461
+ /**
3462
+ * 用于表示删除某个字段
3463
+ *
3464
+ * {@link https://docs.cloudbase.net/api-reference/webv3-next/database#remove}
3465
+ *
3466
+ * @example
3467
+ * const _ = db.command;
3468
+ * db.collection("demo")
3469
+ * .doc("doc-id")
3470
+ * .update({
3471
+ * rating: _.remove()
3472
+ * });
3473
+ *
3474
+ */
3475
+ remove(): any
3476
+ /**
3477
+ * 向数组尾部追加元素
3478
+ *
3479
+ * {@link https://docs.cloudbase.net/api-reference/webv3-next/database#push}
3480
+ *
3481
+ * @example
3482
+ * const _ = db.command;
3483
+ * db.collection("demo")
3484
+ * .doc("doc-id")
3485
+ * .update({
3486
+ * users: _.push(["aaa", "bbb"])
3487
+ * });
3488
+ *
3489
+ * @param val 支持传入单个元素或数组
3490
+ */
3491
+ push(val: any): any
3492
+ /**
3493
+ * 删除数组尾部元素
3494
+ *
3495
+ * {@link https://docs.cloudbase.net/api-reference/webv3-next/database#pop}
3496
+ *
3497
+ * @example
3498
+ * const _ = db.command;
3499
+ * db.collection("demo")
3500
+ * .doc("doc-id")
3501
+ * .update({
3502
+ * users: _.pop()
3503
+ * });
3504
+ *
3505
+ */
3506
+ pop(): any
3507
+ /**
3508
+ * 向数组头部添加元素
3509
+ *
3510
+ * {@link https://docs.cloudbase.net/api-reference/webv3-next/database#unshift}
3511
+ *
3512
+ * @example
3513
+ * const _ = db.command;
3514
+ * db.collection("demo")
3515
+ * .doc("doc-id")
3516
+ * .update({
3517
+ * users: _.unshift(["aaa", "bbb"])
3518
+ * });
3519
+ *
3520
+ * @param val 支持传入单个元素或数组
3521
+ */
3522
+ unshift(val: any): any
3523
+ /**
3524
+ * 删除数组头部元素
3525
+ *
3526
+ * {@link https://docs.cloudbase.net/api-reference/webv3-next/database#shift}
3527
+ *
3528
+ * @example
3529
+ * const _ = db.command;
3530
+ * db.collection("demo")
3531
+ * .doc("doc-id")
3532
+ * .update({
3533
+ * users: _.unshift()
3534
+ * });
3535
+ *
3536
+ */
3537
+ shift(): any
3538
+ /**
3539
+ * 条件取反
3540
+ *
3541
+ * @example
3542
+ * const _ = db.command;
3543
+ * db.collection('users').where({
3544
+ * status: _.not(_.eq('deleted'))
3545
+ * })
3546
+ *
3547
+ * @param condition 查询条件
3548
+ */
3549
+ not(condition: any): any
3550
+ /**
3551
+ * 都不满足指定的条件
3552
+ *
3553
+ * @example
3554
+ * const _ = db.command;
3555
+ * db.collection('users').where(
3556
+ * _.nor([{ status: 'banned' }, { status: 'deleted' }])
3557
+ * )
3558
+ *
3559
+ * @param conditions 条件数组
3560
+ */
3561
+ nor(conditions: any[]): any
3562
+ /**
3563
+ * 判断字段是否存在
3564
+ *
3565
+ * @example
3566
+ * const _ = db.command;
3567
+ * db.collection('users').where({
3568
+ * avatar: _.exists(true)
3569
+ * })
3570
+ *
3571
+ * @param val true 表示字段存在,false 表示不存在
3572
+ */
3573
+ exists(val: boolean): any
3574
+ /**
3575
+ * 取模运算
3576
+ *
3577
+ * @example
3578
+ * const _ = db.command;
3579
+ * db.collection('users').where({
3580
+ * age: _.mod([2, 0])
3581
+ * })
3582
+ *
3583
+ * @param val [除数, 余数]
3584
+ */
3585
+ mod(val: [number, number]): any
3586
+ /**
3587
+ * 数组包含所有指定元素
3588
+ *
3589
+ * @example
3590
+ * const _ = db.command;
3591
+ * db.collection('articles').where({
3592
+ * tags: _.all(['javascript', 'nodejs'])
3593
+ * })
3594
+ *
3595
+ * @param list 必须包含的元素数组
3596
+ */
3597
+ all(list: any[]): any
3598
+ /**
3599
+ * 数组元素匹配
3600
+ *
3601
+ * @example
3602
+ * const _ = db.command;
3603
+ * db.collection('orders').where({
3604
+ * items: _.elemMatch({ price: _.gt(100) })
3605
+ * })
3606
+ *
3607
+ * @param condition 匹配条件对象
3608
+ */
3609
+ elemMatch(condition: Object): any
3610
+ /**
3611
+ * 数组长度匹配
3612
+ *
3613
+ * @example
3614
+ * const _ = db.command;
3615
+ * db.collection('articles').where({
3616
+ * tags: _.size(3)
3617
+ * })
3618
+ *
3619
+ * @param size 数组长度
3620
+ */
3621
+ size(size: number): any
3622
+ /**
3623
+ * 取最小值更新
3624
+ *
3625
+ * @param val 比较值
3626
+ */
3627
+ min(val: number): any
3628
+ /**
3629
+ * 取最大值更新
3630
+ *
3631
+ * @param val 比较值
3632
+ */
3633
+ max(val: number): any
3634
+ /**
3635
+ * 重命名字段
3636
+ *
3637
+ * @param newFieldName 新字段名
3638
+ */
3639
+ rename(newFieldName: string): any
3640
+ /**
3641
+ * 位运算
3642
+ *
3643
+ * @param options 位运算选项,如 { and: 5 }
3644
+ */
3645
+ bit(options: Object): any
3646
+ /**
3647
+ * 删除数组中匹配的元素
3648
+ *
3649
+ * @example
3650
+ * const _ = db.command;
3651
+ * db.collection('articles').doc('id').update({
3652
+ * tags: _.pull('要删除的标签')
3653
+ * })
3654
+ *
3655
+ * @param val 要删除的元素或匹配条件
3656
+ */
3657
+ pull(val: any): any
3658
+ /**
3659
+ * 删除数组中所有匹配的元素
3660
+ *
3661
+ * @param list 要删除的元素数组
3662
+ */
3663
+ pullAll(list: any[]): any
3664
+ /**
3665
+ * 向数组添加不重复的元素
3666
+ *
3667
+ * @example
3668
+ * const _ = db.command;
3669
+ * db.collection('articles').doc('id').update({
3670
+ * tags: _.addToSet('唯一标签')
3671
+ * })
3672
+ *
3673
+ * @param val 要添加的元素
3674
+ */
3675
+ addToSet(val: any): any
3676
+ /**
3677
+ * 按从近到远的顺序,找出字段值在给定点的附近的文档
3678
+ *
3679
+ * {@link https://docs.cloudbase.net/api-reference/webv3-next/database#geonear}
3680
+ *
3681
+ * @example
3682
+ * const _ = db.command;
3683
+ * db.collection("demo").where({
3684
+ * location: _.geoNear({
3685
+ * geometry: new db.Geo.Point(lngA, latA),
3686
+ * maxDistance: 1000,
3687
+ * minDistance: 0
3688
+ * })
3689
+ * });
3690
+ *
3691
+ * @param options
3692
+ * @param options.geometry 点的地理位置
3693
+ * @param options.maxDistance 【可选】最大距离,米为单位
3694
+ * @param options.minDistance 【可选】最小距离,米为单位
3695
+ */
3696
+ geoNear(options: IGeoNearOptions): any
3697
+ /**
3698
+ * 找出字段值在指定 Polygon / MultiPolygon 内的文档,无排序
3699
+ *
3700
+ * {@link https://docs.cloudbase.net/api-reference/webv3-next/database#geowithin}
3701
+ *
3702
+ * @example
3703
+ * const _ = db.command;
3704
+ * db.collection("demo").where({
3705
+ * location: _.geoWithin({
3706
+ * geometry: new Polygon({
3707
+ * new LineString([...Points])
3708
+ * }),
3709
+ * })
3710
+ * });
3711
+ *
3712
+ * @param options
3713
+ * @param options.geometry 地理位置
3714
+ */
3715
+ geoWithin(options: IGeoWithinOptions): any
3716
+ /**
3717
+ * 找出字段值和给定的地理位置图形相交的文档
3718
+ *
3719
+ * {@link https://docs.cloudbase.net/api-reference/webv3-next/database#geointersects}
3720
+ *
3721
+ * @example
3722
+ * const _ = db.command;
3723
+ * db.collection("user").where({
3724
+ * location: _.geoNear({
3725
+ * geometry: new LineString([new Point(lngA, latA), new Point(lngB, latB)]);
3726
+ * })
3727
+ * });
3728
+ *
3729
+ * @param options
3730
+ * @param options.geometry 地理位置
3731
+ */
3732
+ geoIntersects(options: IGeoIntersectsOptions): any
3733
+ }
3734
+ /**
3735
+ * document types
3736
+ */
3737
+ interface IDocument extends IWatchable {
3738
+ /**
3739
+ * 设置文档数据,如果文档不存在则创建新文档
3740
+ *
3741
+ * {@link https://docs.cloudbase.net/api-reference/webv3-next/database.html#update-set}
3742
+ *
3743
+ * @example
3744
+ * collection
3745
+ * .doc('docId')
3746
+ * .set({name:'cloudbase'})
3747
+ * .then(res=>{})
3748
+ *
3749
+ * @param data 要设置的数据对象,将完全替换原有文档内容
3750
+ *
3751
+ * @return Promise<SetRes> 包含 updated 或 upsertedId
3752
+ */
3753
+ set(data: Object): Promise<SetRes>
3754
+ /**
3755
+ * 获取文档数据
3756
+ *
3757
+ * {@link https://docs.cloudbase.net/api-reference/webv3-next/database#get}
3758
+ *
3759
+ * @example
3760
+ * collection
3761
+ * .doc('docId')
3762
+ * .get()
3763
+ * .then(res=>{ console.log(res.data) })
3764
+ *
3765
+ * @return Promise<GetRes> 包含 data 数组和 requestId
3766
+ */
3767
+ get(): Promise<GetRes>
3768
+ /**
3769
+ * 更新文档数据,如果文档不存在则不做任何操作
3770
+ *
3771
+ * {@link https://docs.cloudbase.net/api-reference/webv3-next/database#update--set}
3772
+ *
3773
+ * @example
3774
+ * collection
3775
+ * .doc('docId')
3776
+ * .update({completed: true})
3777
+ * .then(res=>{ console.log(res.updated) })
3778
+ *
3779
+ * @param data 要更新的数据对象,支持操作符
3780
+ *
3781
+ * @return Promise<UpdateRes> 包含 updated 字段
3782
+ */
3783
+ update(data: Object): Promise<UpdateRes>
3784
+ /**
3785
+ * 删除一条文档
3786
+ *
3787
+ * {@link https://docs.cloudbase.net/api-reference/webv3-next/database.html#remove-2}
3788
+ *
3789
+ * @example
3790
+ * collection
3791
+ * .doc('docId')
3792
+ * .remove()
3793
+ * .then(res=>{ console.log(res.deleted) })
3794
+ *
3795
+ * @return Promise<RemoveRes> 包含 deleted 字段
3796
+ */
3797
+ remove(): Promise<RemoveRes>
3798
+ /**
3799
+ * 指定要返回的字段
3800
+ *
3801
+ * {@link https://docs.cloudbase.net/api-reference/webv3-next/database#field}
3802
+ *
3803
+ * @param projection 字段投影对象,true 表示返回,false 表示不返回
3804
+ *
3805
+ * @return 文档引用,可继续链式调用 get()
3806
+ */
3807
+ field(projection: Object): IDocument
3808
+ }
3809
+ /**
3810
+ * query types
3811
+ */
3812
+ interface SetRes {
3813
+ code?: string
3814
+ message?: string
3815
+ updated?: number
3816
+ upsertedId?: string
3817
+ requestId: string
3818
+ }
3819
+ interface GetRes {
3820
+ data: any[]
3821
+ requestId: string
3822
+ code?: string
3823
+ message?: string
3824
+ }
3825
+
3826
+ interface UpdateRes {
3827
+ requestId: string
3828
+ updated?: number
3829
+ upsertedId?: string
3830
+ code?: string
3831
+ message?: string
3832
+ }
3833
+
3834
+ interface AddRes {
3835
+ id?: string
3836
+ ids?: string[]
3837
+ insertedIds?: string[]
3838
+ requestId: string
3839
+ code?: string
3840
+ message?: string
3841
+ }
3842
+
3843
+ interface CountRes {
3844
+ total: number
3845
+ requestId: string
3846
+ code?: string
3847
+ message?: string
3848
+ }
3849
+
3850
+ interface RemoveRes {
3851
+ deleted: number
3852
+ requestId: string
3853
+ code?: string
3854
+ message?: string
3855
+ }
3856
+
3857
+ interface CreateCollectionRes {
3858
+ data: string
3859
+ requestId: string
3860
+ code?: string
3861
+ message?: string
3862
+ }
3863
+
3864
+ interface IRunCommandsReq {
3865
+ /** 命令对象数组 */
3866
+ commands: Object[]
3867
+ /** 事务 ID(可选) */
3868
+ transactionId?: string
3869
+ }
3870
+
3871
+ interface IRunCommandsResult {
3872
+ requestId: string
3873
+ /** 命令执行结果数组 */
3874
+ list: Object[][]
3875
+ code?: string
3876
+ message?: string
3877
+ }
3878
+
3879
+ /**
3880
+ * 数据库配置
3881
+ */
3882
+ interface IDbConfig {
3883
+ /** 实例 ID(可选),不填则使用默认实例 */
3884
+ instance?: string
3885
+ /** 数据库名称(可选),不填则使用默认数据库 */
3886
+ database?: string
3887
+ }
3888
+
3889
+ /**
3890
+ * 聚合操作对象
3891
+ */
3892
+ interface IAggregate {
3893
+ /**
3894
+ * 添加新字段
3895
+ */
3896
+ addFields(fieldObj: Object): IAggregate
3897
+ /**
3898
+ * 分桶
3899
+ */
3900
+ bucket(bucketObj: Object): IAggregate
3901
+ /**
3902
+ * 自动分桶
3903
+ */
3904
+ bucketAuto(bucketObj: Object): IAggregate
3905
+ /**
3906
+ * 计数
3907
+ */
3908
+ count(fieldName: string): IAggregate
3909
+ /**
3910
+ * 地理位置附近查询
3911
+ */
3912
+ geoNear(options: Object): IAggregate
3913
+ /**
3914
+ * 分组统计
3915
+ *
3916
+ * @example
3917
+ * db.collection('todos').aggregate()
3918
+ * .group({ _id: '$priority', count: { $sum: 1 } })
3919
+ * .end()
3920
+ */
3921
+ group(groupObj: Object): IAggregate
3922
+ /**
3923
+ * 限制结果数量
3924
+ */
3925
+ limit(limit: number): IAggregate
3926
+ /**
3927
+ * 联表查询
3928
+ */
3929
+ lookup(lookupObj: Object): IAggregate
3930
+ /**
3931
+ * 条件筛选
3932
+ */
3933
+ match(matchObj: Object): IAggregate
3934
+ /**
3935
+ * 字段投影
3936
+ */
3937
+ project(projectObj: Object): IAggregate
3938
+ /**
3939
+ * 替换根文档
3940
+ */
3941
+ replaceRoot(replaceObj: Object): IAggregate
3942
+ /**
3943
+ * 随机采样
3944
+ */
3945
+ sample(sampleObj: Object): IAggregate
3946
+ /**
3947
+ * 跳过数量
3948
+ */
3949
+ skip(skip: number): IAggregate
3950
+ /**
3951
+ * 排序
3952
+ */
3953
+ sort(sortObj: Object): IAggregate
3954
+ /**
3955
+ * 按数量排序
3956
+ */
3957
+ sortByCount(fieldName: string): IAggregate
3958
+ /**
3959
+ * 展开数组
3960
+ */
3961
+ unwind(fieldPath: string | Object): IAggregate
3962
+ /**
3963
+ * 结束聚合管道,返回结果
3964
+ */
3965
+ end(): Promise<GetRes>
3966
+ }
3967
+
3968
+ /**
3969
+ * 事务对象
3970
+ */
3971
+ interface ITransaction {
3972
+ /**
3973
+ * 获取事务内的集合引用
3974
+ */
3975
+ collection(name: string): ITransactionCollection
3976
+ /**
3977
+ * 提交事务
3978
+ */
3979
+ commit(): Promise<void>
3980
+ /**
3981
+ * 回滚事务
3982
+ *
3983
+ * @param reason 回滚原因
3984
+ */
3985
+ rollback(reason?: any): Promise<void>
3986
+ }
3987
+
3988
+ /**
3989
+ * 事务内的集合引用
3990
+ */
3991
+ interface ITransactionCollection {
3992
+ doc(id: string): ITransactionDocument
3993
+ }
3994
+
3995
+ /**
3996
+ * 事务内的文档引用
3997
+ */
3998
+ interface ITransactionDocument {
3999
+ get(): Promise<GetRes>
4000
+ create(data: Object): Promise<any>
4001
+ set(data: Object): Promise<SetRes>
4002
+ update(data: Object): Promise<UpdateRes>
4003
+ remove(): Promise<RemoveRes>
4004
+ }
4005
+
4006
+ interface QueryOrder {
4007
+ field?: string
4008
+ direction?: 'asc' | 'desc'
4009
+ }
4010
+
4011
+ interface QueryOption {
4012
+ // 查询数量
4013
+ limit?: number
4014
+ // 偏移量
4015
+ offset?: number
4016
+ // 指定显示或者不显示哪些字段
4017
+ projection?: Object
4018
+ }
4019
+ interface IQuery extends IWatchable {
4020
+ /**
4021
+ * 获取数据库查询结果
4022
+ *
4023
+ * {@link https://docs.cloudbase.net/api-reference/webv3-next/database.html#get}
4024
+ *
4025
+ * @example
4026
+ * collection
4027
+ * .where({
4028
+ * name: 'cloudbase'
4029
+ * })
4030
+ * .get()
4031
+ * .then(res=>{})
4032
+ *
4033
+ * @return Promise-查询结果
4034
+ */
4035
+ get(): Promise<GetRes>
4036
+ /**
4037
+ * 更新数据库文档
4038
+ *
4039
+ * {@link https://docs.cloudbase.net/api-reference/webv3-next/database.html#update-set}
4040
+ *
4041
+ * @example
4042
+ * collection
4043
+ * .where({
4044
+ * name: 'cloudbase'
4045
+ * })
4046
+ * .update({
4047
+ * name: 'newCloudbase'
4048
+ * })
4049
+ * .then(res=>{})
4050
+ *
4051
+ * @return Promise-查询结果
4052
+ */
4053
+ update(data: Object): Promise<UpdateRes>
4054
+ /**
4055
+ * 获取数据库查询结果的数目
4056
+ *
4057
+ * {@link https://docs.cloudbase.net/api-reference/webv3-next/database#count}
4058
+ *
4059
+ * @example
4060
+ * collection
4061
+ * .where({
4062
+ * name: 'cloudbase'
4063
+ * })
4064
+ * .count()
4065
+ * .then(res=>{})
4066
+ *
4067
+ * @return Promise<CountRes> 包含 total 字段
4068
+ */
4069
+ count(): Promise<CountRes>
4070
+ /**
4071
+ * 设置过滤条件
4072
+ *
4073
+ * {@link https://docs.cloudbase.net/api-reference/webv3-next/database#where}
4074
+ *
4075
+ * @example
4076
+ * collection
4077
+ * .where({
4078
+ * name: 'cloudbase'
4079
+ * })
4080
+ *
4081
+ * @param query 可接收对象作为参数,表示筛选出拥有和传入对象相同的 key-value 的文档
4082
+ *
4083
+ */
4084
+ where(query: Object): ExcludeOf<IQuery, 'where'>
4085
+ /**
4086
+ * 指定查询结果集数量上限
4087
+ *
4088
+ * {@link https://docs.cloudbase.net/api-reference/webv3-next/database#limit}
4089
+ *
4090
+ * @example
4091
+ * collection
4092
+ * .where({
4093
+ * name: 'cloudbase'
4094
+ * })
4095
+ * .limit(1)
4096
+ *
4097
+ * @param limit 查询结果数量上限
4098
+ */
4099
+ limit(limit: number): ExcludeOf<IQuery, 'where'>
4100
+ /**
4101
+ * 指定查询返回结果时从指定序列后的结果开始返回,常用于分页
4102
+ *
4103
+ * {@link https://docs.cloudbase.net/api-reference/webv3-next/database#skip}
4104
+ *
4105
+ * @example
4106
+ * collection
4107
+ * .where({
4108
+ * name: 'cloudbase'
4109
+ * })
4110
+ * .skip(4)
4111
+ *
4112
+ * @param offset 跳过的条目数量
4113
+ */
4114
+ skip(offset: number): ExcludeOf<IQuery, 'where'>
4115
+ /**
4116
+ * 指定查询排序条件
4117
+ *
4118
+ * {@link https://docs.cloudbase.net/api-reference/webv3-next/database#orderby}
4119
+ *
4120
+ * @example
4121
+ * collection
4122
+ * .where({
4123
+ * name: 'cloudbase'
4124
+ * })
4125
+ * .orderBy("name", "asc")
4126
+ *
4127
+ * @param field 排序的字段
4128
+ * @param orderType 排序的顺序,升序(asc) 或 降序(desc)
4129
+ */
4130
+ orderBy(field: string, orderType: 'desc' | 'asc'): ExcludeOf<IQuery, 'where'>
4131
+ /**
4132
+ * 指定返回结果中文档需返回的字段
4133
+ *
4134
+ * {@link https://docs.cloudbase.net/api-reference/webv3-next/database#field}
4135
+ *
4136
+ * @example
4137
+ * collection
4138
+ * .where({
4139
+ * name: 'cloudbase'
4140
+ * })
4141
+ * .field({ age: true })
4142
+ *
4143
+ * @param projection 要过滤的字段集合,不返回传 false,返回传 true
4144
+ */
4145
+ field(projection: Object): ExcludeOf<IQuery, 'where'>
4146
+ /**
4147
+ * 删除查询到的结果
4148
+ *
4149
+ * {@link https://docs.cloudbase.net/api-reference/webv3-next/database#remove-1}
4150
+ *
4151
+ * @example
4152
+ * collection
4153
+ * .where({
4154
+ * name: 'cloudbase'
4155
+ * })
4156
+ * .remove()
4157
+ *
4158
+ * @return Promise<RemoveRes> 包含 deleted 字段
4159
+ */
4160
+ remove(): Promise<RemoveRes>
4161
+ }
4162
+ /**
4163
+ * geo types
4164
+ */
4165
+ interface IPoint {}
4166
+ interface ILineString {}
4167
+ interface IPolygon {}
4168
+ interface IMultiPoint {}
4169
+ interface IMultiLineString {}
4170
+ interface IMultiPolygon {}
4171
+ interface IGeo {
4172
+ /**
4173
+ * 用于表示地理位置点
4174
+ *
4175
+ * {@link https://docs.cloudbase.net/api-reference/webv3-next/database#point}
4176
+ *
4177
+ * @example
4178
+ * const point = new db.Geo.Point(lng,lat);
4179
+ *
4180
+ * @param longitude 经度
4181
+ * @param latitude 纬度
4182
+ *
4183
+ * @return Point
4184
+ */
4185
+ Point: {
4186
+ new (longitude: number, latitude: number): IPoint
4187
+ }
4188
+ /**
4189
+ * 用于表示地理路径,是由两个或者更多的 Point 组成的线段
4190
+ *
4191
+ * {@link https://docs.cloudbase.net/api-reference/webv3-next/database#linestring}
4192
+ *
4193
+ * @example
4194
+ * const point = new db.Geo.LineString([pointA,pointB]);
4195
+ *
4196
+ * @param points Point数组
4197
+ *
4198
+ * @return LineString
4199
+ */
4200
+ LineString: {
4201
+ new (points: IPoint[]): ILineString
4202
+ }
4203
+ /**
4204
+ * 用于表示地理上的一个多边形
4205
+ *
4206
+ * {@link https://docs.cloudbase.net/api-reference/webv3-next/database#polygon}
4207
+ *
4208
+ * @example
4209
+ * const point = new db.Geo.Polygon([lineStringA,lineStringB]);
4210
+ *
4211
+ * @param lines LineString数组
4212
+ *
4213
+ * @return Polygon
4214
+ */
4215
+ Polygon: {
4216
+ new (lines: ILineString[]): IPolygon
4217
+ }
4218
+ /**
4219
+ * 用于表示多个点 Point 的集合
4220
+ *
4221
+ * {@link https://docs.cloudbase.net/api-reference/webv3-next/database#multipoint}
4222
+ *
4223
+ * @example
4224
+ * const point = new db.Geo.MultiPoint([pointA,pointB]);
4225
+ *
4226
+ * @param points Point数组
4227
+ *
4228
+ * @return MultiPoint
4229
+ */
4230
+ MultiPoint: {
4231
+ new (points: IPoint[]): IMultiPoint
4232
+ }
4233
+ /**
4234
+ * 用于表示多个地理路径 LineString 的集合
4235
+ *
4236
+ * {@link https://docs.cloudbase.net/api-reference/webv3-next/database#multilinestring}
4237
+ *
4238
+ * @example
4239
+ * const point = new db.Geo.MultiLineString([lineA,lineB]);
4240
+ *
4241
+ * @param lines LineString数组
4242
+ *
4243
+ * @return MultiLineString
4244
+ */
4245
+ MultiLineString: {
4246
+ new (lines: ILineString[]): IMultiLineString
4247
+ }
4248
+ /**
4249
+ * 用于表示多个地理多边形 Polygon 的集合
4250
+ *
4251
+ * {@link https://docs.cloudbase.net/api-reference/webv3-next/database#multipolygon}
4252
+ *
4253
+ * @example
4254
+ * const point = new db.Geo.MultiPolygon([polygonA,polygonB]);
4255
+ *
4256
+ * @param polygons Polygon数组
4257
+ *
4258
+ * @return MultiPolygon
4259
+ */
4260
+ MultiPolygon: {
4261
+ new (polygons: IPolygon[]): IMultiPolygon
4262
+ }
4263
+ }
4264
+ /**
4265
+ * regexp types
4266
+ */
4267
+ interface IRegExpOptions {
4268
+ regexp: string
4269
+ options?: string
4270
+ }
4271
+ interface IRegExp {
4272
+ (options: IRegExpOptions): any
4273
+ }
4274
+ /**
4275
+ * instance types
4276
+ */
4277
+ interface App {
4278
+ /**
4279
+ * 数据库指令
4280
+ *
4281
+ * {@link https://docs.cloudbase.net/api-reference/webv3-next/database#%E6%9F%A5%E8%AF%A2%E6%8C%87%E4%BB%A4}
4282
+ */
4283
+ command: ICommand
4284
+ /**
4285
+ * 数据库Geo地理位置
4286
+ *
4287
+ * {@link https://docs.cloudbase.net/api-reference/webv3-next/database.html#geo-shu-ju-lei-xing}
4288
+ */
4289
+ Geo: IGeo
4290
+ /**
4291
+ * 根据正则表达式进行筛选
4292
+ *
4293
+ * {@link https://docs.cloudbase.net/api-reference/webv3-next/database.html#regexp}
4294
+ *
4295
+ * @example
4296
+ * db.collection('articles').where({
4297
+ * version: new db.RegExp({
4298
+ * regexp: '^\\ds' // 正则表达式为 /^\ds/,转义后变成 '^\\ds'
4299
+ * options: 'i' // i表示忽略大小写
4300
+ * })
4301
+ * })
4302
+ *
4303
+ * @param options
4304
+ * @param options.regexp 正则表达式Pattern
4305
+ * @param options.options 正则表达式Flags
4306
+ */
4307
+ RegExp: IRegExp
4308
+ /**
4309
+ * 创建集合的引用
4310
+ *
4311
+ * {@link https://docs.cloudbase.net/api-reference/webv3-next/database.html#collection}
4312
+ *
4313
+ * @example
4314
+ * const coll = db.collection('demo');
4315
+ *
4316
+ * @param name 集合名称
4317
+ *
4318
+ * @return 集合的引用
4319
+ */
4320
+ collection(name: string): ICollection
4321
+
4322
+ runCommands(params: IRunCommandsReq): Promise<{
4323
+ statusCode: number
4324
+ requestId: string
4325
+ list?: Object[][]
4326
+ code?: string
4327
+ message?: string
4328
+ }>
4329
+ }
4330
+ }
4331
+