@cloudbase/js-sdk 2.26.1 → 2.26.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.
- package/CHANGELOG.md +3 -1
- package/dist/index.cjs.js +1 -1
- package/dist/index.esm.js +1 -1
- package/index.d.ts +1279 -132
- package/miniprogram_dist/ai.js +1 -1
- package/miniprogram_dist/analytics.js +1 -1
- package/miniprogram_dist/app.js +1 -1
- package/miniprogram_dist/auth.js +1 -1
- package/miniprogram_dist/cloudrun.js +1 -1
- package/miniprogram_dist/container.js +1 -1
- package/miniprogram_dist/functions.js +1 -1
- package/miniprogram_dist/index.js +1 -1
- package/miniprogram_dist/model.js +1 -1
- package/miniprogram_dist/oauth.js +1 -1
- package/miniprogram_dist/storage.js +1 -1
- package/package.json +15 -15
package/index.d.ts
CHANGED
|
@@ -78,11 +78,19 @@ declare namespace cloudbase {
|
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
interface ICloudbaseConfig {
|
|
81
|
+
/** 环境 ID,在腾讯云开发控制台 → 环境 → 环境总览中获取 */
|
|
81
82
|
env: string
|
|
83
|
+
/**
|
|
84
|
+
* 地域信息
|
|
85
|
+
* @example 'ap-shanghai'
|
|
86
|
+
*/
|
|
82
87
|
region?: string
|
|
88
|
+
/** 网络请求超时上限,单位 ms,默认 15000 */
|
|
83
89
|
timeout?: number
|
|
90
|
+
/** 本地登录态保留期限 */
|
|
84
91
|
persistence?: Persistence
|
|
85
92
|
oauthClient?: any
|
|
93
|
+
/** 是否开启调试模式 */
|
|
86
94
|
debug?: boolean
|
|
87
95
|
_fromApp?: ICloudbase
|
|
88
96
|
clientId?: string
|
|
@@ -95,7 +103,31 @@ declare namespace cloudbase {
|
|
|
95
103
|
}
|
|
96
104
|
accessKey?: string
|
|
97
105
|
endPointMode?: EndPointKey
|
|
98
|
-
lang?: LANGS
|
|
106
|
+
lang?: LANGS
|
|
107
|
+
/**
|
|
108
|
+
* 认证相关配置
|
|
109
|
+
* @example
|
|
110
|
+
* ```typescript
|
|
111
|
+
* cloudbase.init({
|
|
112
|
+
* env: 'your-env-id',
|
|
113
|
+
* auth: {
|
|
114
|
+
* detectSessionInUrl: true // 自动检测 URL 中的 OAuth 回调参数
|
|
115
|
+
* }
|
|
116
|
+
* })
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
119
|
+
auth?: {
|
|
120
|
+
/** 是否自动检测 URL 中的 OAuth 回调参数,默认 false */
|
|
121
|
+
detectSessionInUrl?: boolean
|
|
122
|
+
/** 密钥 ID(Node.js 端使用) */
|
|
123
|
+
secretId?: string
|
|
124
|
+
/** 密钥(Node.js 端使用) */
|
|
125
|
+
secretKey?: string
|
|
126
|
+
/** 临时会话 Token(Node.js 端使用) */
|
|
127
|
+
sessionToken?: string
|
|
128
|
+
/** 密钥类型 */
|
|
129
|
+
secretType?: 'SESSION_SECRET' | 'SECRET'
|
|
130
|
+
}
|
|
99
131
|
}
|
|
100
132
|
|
|
101
133
|
interface ICloudbaseExtension {
|
|
@@ -148,20 +180,49 @@ declare namespace cloudbase {
|
|
|
148
180
|
*
|
|
149
181
|
* @example
|
|
150
182
|
* ```javascript
|
|
183
|
+
* // 基本用法
|
|
151
184
|
* const app = cloudbase.init({
|
|
152
185
|
* env: 'your-envid',
|
|
153
186
|
* timeout: 15000
|
|
154
187
|
* });
|
|
188
|
+
*
|
|
189
|
+
* // 推荐:从环境变量读取环境 ID
|
|
190
|
+
* const app = cloudbase.init({
|
|
191
|
+
* env: process.env.CLOUDBASE_ENV || import.meta.env.VITE_CLOUDBASE_ENV || 'your-envid'
|
|
192
|
+
* });
|
|
193
|
+
*
|
|
194
|
+
* // 使用认证配置
|
|
195
|
+
* const app = cloudbase.init({
|
|
196
|
+
* env: 'your-envid',
|
|
197
|
+
* auth: {
|
|
198
|
+
* detectSessionInUrl: true // 自动检测 URL 中的 OAuth 回调参数
|
|
199
|
+
* }
|
|
200
|
+
* });
|
|
155
201
|
* ```
|
|
156
202
|
*
|
|
157
203
|
* @param config 初始化配置
|
|
158
|
-
* @param config.env 环境ID
|
|
204
|
+
* @param config.env 环境ID,在腾讯云开发控制台 → 环境 → 环境总览中获取
|
|
159
205
|
* @param config.timeout 【可选】网络请求超时上限,单位`ms`,默认值`15000`
|
|
206
|
+
* @param config.auth 【可选】认证相关配置
|
|
160
207
|
*
|
|
161
208
|
* @return {!cloudbase.app.App} 初始化成功的Cloudbase实例
|
|
162
209
|
*/
|
|
163
210
|
function init(config: ICloudbaseConfig): cloudbase.app.App
|
|
164
211
|
|
|
212
|
+
/**
|
|
213
|
+
* 检查 Cloudbase 实例是否已完成初始化
|
|
214
|
+
*
|
|
215
|
+
* @example
|
|
216
|
+
* ```javascript
|
|
217
|
+
* if (!cloudbase.isInitialized()) {
|
|
218
|
+
* cloudbase.init({ env: 'your-envid' });
|
|
219
|
+
* }
|
|
220
|
+
* ```
|
|
221
|
+
*
|
|
222
|
+
* @returns 是否已初始化
|
|
223
|
+
*/
|
|
224
|
+
function isInitialized(): boolean
|
|
225
|
+
|
|
165
226
|
function updateConfig(config: ICloudbaseUpgradedConfig): void
|
|
166
227
|
|
|
167
228
|
function updateLang(lang: LANGS): void
|
|
@@ -512,8 +573,7 @@ declare namespace cloudbase.app {
|
|
|
512
573
|
|
|
513
574
|
getFileInfo(
|
|
514
575
|
params: cloudbase.storage.ICloudbaseGetTempFileURLParams,
|
|
515
|
-
|
|
516
|
-
): Promise<cloudbase.storage.ICloudbaseGetTempFileURLResult>
|
|
576
|
+
): Promise<cloudbase.storage.ICloudbaseGetFileInfoResult>
|
|
517
577
|
/**
|
|
518
578
|
* 云存储-获取上传元信息
|
|
519
579
|
*
|
|
@@ -522,10 +582,21 @@ declare namespace cloudbase.app {
|
|
|
522
582
|
* @param callback
|
|
523
583
|
*/
|
|
524
584
|
getUploadMetadata(params: cloudbase.storage.ICloudbaseGetUploadMetadataParams, callback?: Function): Promise<any>
|
|
585
|
+
|
|
586
|
+
/**
|
|
587
|
+
* Supabase 风格的文件存储 API
|
|
588
|
+
*
|
|
589
|
+
* @example
|
|
590
|
+
* ```typescript
|
|
591
|
+
* const bucket = app.storage.from('my-bucket')
|
|
592
|
+
* const { data, error } = await bucket.upload('path/to/file.jpg', file)
|
|
593
|
+
* ```
|
|
594
|
+
*/
|
|
595
|
+
storage: cloudbase.storage.SupabaseFileAPILikeStorage
|
|
525
596
|
/**
|
|
526
597
|
* 获取数据库实例
|
|
527
598
|
*
|
|
528
|
-
* {@link https://docs.cloudbase.net/api-reference/webv3/database#%E8%8E%B7%E5%8F%96%E6%95%B0%E6%8D%AE%E5%BA%93%E5%AE%9E%E4%BE%8B}
|
|
599
|
+
* {@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}
|
|
529
600
|
*
|
|
530
601
|
* @example
|
|
531
602
|
* ```javascript
|
|
@@ -537,7 +608,7 @@ declare namespace cloudbase.app {
|
|
|
537
608
|
*
|
|
538
609
|
* @return 数据库实例
|
|
539
610
|
*/
|
|
540
|
-
database(dbConfig?:
|
|
611
|
+
database(dbConfig?: cloudbase.database.IDbConfig): cloudbase.database.App
|
|
541
612
|
/**
|
|
542
613
|
* 调用扩展能力插件功能
|
|
543
614
|
*
|
|
@@ -863,6 +934,7 @@ declare namespace cloudbase.auth {
|
|
|
863
934
|
setPassword(params: authModels.SetPasswordRequest): Promise<void>
|
|
864
935
|
/**
|
|
865
936
|
* 获取用户信息
|
|
937
|
+
* @deprecated 请使用 getCurrentUser 代替
|
|
866
938
|
*
|
|
867
939
|
* 文档 {@link https://docs.cloudbase.net/api-reference/webv2/authentication#authgetuserinfo}
|
|
868
940
|
*/
|
|
@@ -1307,6 +1379,296 @@ declare namespace cloudbase.auth {
|
|
|
1307
1379
|
* @param params
|
|
1308
1380
|
*/
|
|
1309
1381
|
signInWithPhoneAuth(params: { phoneCode: string }): Promise<SignInRes>
|
|
1382
|
+
|
|
1383
|
+
// ========== v1 兼容 API ==========
|
|
1384
|
+
|
|
1385
|
+
/**
|
|
1386
|
+
* v1 API: 获取用于微信登录的 WeixinAuthProvider
|
|
1387
|
+
*
|
|
1388
|
+
* @deprecated 建议使用 auth.signInWithOAuth({ provider: appid }) 替代。
|
|
1389
|
+
*
|
|
1390
|
+
* @example
|
|
1391
|
+
* ```javascript
|
|
1392
|
+
* const provider = auth.weixinAuthProvider({ appid: 'wx-appid', scope: 'snsapi_login' });
|
|
1393
|
+
* provider.signInWithRedirect();
|
|
1394
|
+
* ```
|
|
1395
|
+
*
|
|
1396
|
+
* @param options
|
|
1397
|
+
* @param options.appid 微信 AppID
|
|
1398
|
+
* @param options.scope 微信授权范围
|
|
1399
|
+
*/
|
|
1400
|
+
weixinAuthProvider(options: { appid: string; scope: string }): cloudbase.auth.WeixinAuthProvider
|
|
1401
|
+
|
|
1402
|
+
/**
|
|
1403
|
+
* v1 API: 获取用于自定义登录的 CustomAuthProvider
|
|
1404
|
+
*
|
|
1405
|
+
* @deprecated 建议使用 auth.signInWithCustomTicket(() => Promise.resolve(ticket)) 替代。
|
|
1406
|
+
*
|
|
1407
|
+
* @example
|
|
1408
|
+
* ```javascript
|
|
1409
|
+
* const provider = auth.customAuthProvider();
|
|
1410
|
+
* await provider.signIn(ticket);
|
|
1411
|
+
* ```
|
|
1412
|
+
*/
|
|
1413
|
+
customAuthProvider(): cloudbase.auth.CustomAuthProvider
|
|
1414
|
+
|
|
1415
|
+
/**
|
|
1416
|
+
* v1 API: 获取用于匿名登录的 AnonymousAuthProvider
|
|
1417
|
+
*
|
|
1418
|
+
* @deprecated 建议使用 auth.signInAnonymously({}) 替代。
|
|
1419
|
+
*
|
|
1420
|
+
* @example
|
|
1421
|
+
* ```javascript
|
|
1422
|
+
* const provider = auth.anonymousAuthProvider();
|
|
1423
|
+
* await provider.signIn();
|
|
1424
|
+
* ```
|
|
1425
|
+
*/
|
|
1426
|
+
anonymousAuthProvider(): cloudbase.auth.AnonymousAuthProvider
|
|
1427
|
+
|
|
1428
|
+
/**
|
|
1429
|
+
* v1 API: 使用邮箱和密码注册云开发账户
|
|
1430
|
+
*
|
|
1431
|
+
* @deprecated 建议使用 auth.signUp({ email, password }) 替代。
|
|
1432
|
+
*
|
|
1433
|
+
* @example
|
|
1434
|
+
* ```javascript
|
|
1435
|
+
* await auth.signUpWithEmailAndPassword('user@example.com', 'password123');
|
|
1436
|
+
* ```
|
|
1437
|
+
*
|
|
1438
|
+
* @param email 邮箱
|
|
1439
|
+
* @param password 密码
|
|
1440
|
+
*/
|
|
1441
|
+
signUpWithEmailAndPassword(email: string, password: string): Promise<SignUpRes>
|
|
1442
|
+
|
|
1443
|
+
/**
|
|
1444
|
+
* v1 API: 使用邮箱和密码登录云开发(支持两种调用方式)
|
|
1445
|
+
*
|
|
1446
|
+
* @deprecated 建议使用 auth.signInWithPassword({ email, password }) 替代。
|
|
1447
|
+
*
|
|
1448
|
+
* @example
|
|
1449
|
+
* ```javascript
|
|
1450
|
+
* // 方式一(v1 风格):
|
|
1451
|
+
* await auth.signInWithEmailAndPassword('user@example.com', 'password123');
|
|
1452
|
+
*
|
|
1453
|
+
* // 方式二(v3 风格):
|
|
1454
|
+
* const { data, error } = await auth.signInWithEmailAndPassword({
|
|
1455
|
+
* email: 'user@example.com',
|
|
1456
|
+
* password: 'password123'
|
|
1457
|
+
* });
|
|
1458
|
+
* ```
|
|
1459
|
+
*
|
|
1460
|
+
* @param emailOrParams - 邮箱字符串(v1)或包含 email 和 password 的对象(v3)
|
|
1461
|
+
* @param password - 密码(仅 v1 风格时使用)
|
|
1462
|
+
*/
|
|
1463
|
+
signInWithEmailAndPassword(emailOrParams: string | { email: string; password: string; is_encrypt?: boolean }, password?: string): Promise<SignInRes | ILoginState>
|
|
1464
|
+
|
|
1465
|
+
/**
|
|
1466
|
+
* v1 API: 发送重置密码的邮件
|
|
1467
|
+
*
|
|
1468
|
+
* @deprecated 建议使用 auth.resetPasswordForEmail(email) 替代。
|
|
1469
|
+
*
|
|
1470
|
+
* @example
|
|
1471
|
+
* ```javascript
|
|
1472
|
+
* await auth.sendPasswordResetEmail('user@example.com');
|
|
1473
|
+
* ```
|
|
1474
|
+
*
|
|
1475
|
+
* @param email 邮箱
|
|
1476
|
+
*/
|
|
1477
|
+
sendPasswordResetEmail(email: string): Promise<void>
|
|
1478
|
+
|
|
1479
|
+
/**
|
|
1480
|
+
* v1 API: 使用用户名和密码登录云开发
|
|
1481
|
+
*
|
|
1482
|
+
* @deprecated 建议使用 auth.signInWithPassword({ username, password }) 替代。
|
|
1483
|
+
*
|
|
1484
|
+
* @example
|
|
1485
|
+
* ```javascript
|
|
1486
|
+
* const loginState = await auth.signInWithUsernameAndPassword('username', 'password123');
|
|
1487
|
+
* ```
|
|
1488
|
+
*
|
|
1489
|
+
* @param username 用户名
|
|
1490
|
+
* @param password 密码
|
|
1491
|
+
*/
|
|
1492
|
+
signInWithUsernameAndPassword(username: string, password: string): Promise<ILoginState>
|
|
1493
|
+
|
|
1494
|
+
/**
|
|
1495
|
+
* v1 API: 发送手机验证码
|
|
1496
|
+
*
|
|
1497
|
+
* @deprecated 建议使用 auth.signInWithOtp({ phone }) 或 auth.getVerification({ phone_number }) 替代。
|
|
1498
|
+
*
|
|
1499
|
+
* @example
|
|
1500
|
+
* ```javascript
|
|
1501
|
+
* const success = await auth.sendPhoneCode('+8613800138000');
|
|
1502
|
+
* ```
|
|
1503
|
+
*
|
|
1504
|
+
* @param phoneNumber 手机号
|
|
1505
|
+
* @returns 是否发送成功
|
|
1506
|
+
*/
|
|
1507
|
+
sendPhoneCode(phoneNumber: string): Promise<boolean>
|
|
1508
|
+
|
|
1509
|
+
/**
|
|
1510
|
+
* v1 API: 手机号注册(支持短信验证码+密码方式)
|
|
1511
|
+
*
|
|
1512
|
+
* @deprecated 建议使用 auth.signUp({ phone_number, verification_code, password? }) 替代。
|
|
1513
|
+
*
|
|
1514
|
+
* @example
|
|
1515
|
+
* ```javascript
|
|
1516
|
+
* const loginState = await auth.signUpWithPhoneCode('+8613800138000', '123456', 'password');
|
|
1517
|
+
* ```
|
|
1518
|
+
*
|
|
1519
|
+
* @param phoneNumber 手机号
|
|
1520
|
+
* @param phoneCode 验证码
|
|
1521
|
+
* @param password 可选密码
|
|
1522
|
+
*/
|
|
1523
|
+
signUpWithPhoneCode(phoneNumber: string, phoneCode: string, password?: string): Promise<ILoginState>
|
|
1524
|
+
|
|
1525
|
+
/**
|
|
1526
|
+
* v1 API: 手机号登录(支持短信验证码 or 密码方式)
|
|
1527
|
+
*
|
|
1528
|
+
* @deprecated 密码方式建议使用 auth.signInWithPassword({ phone, password }) 替代;
|
|
1529
|
+
* 验证码方式建议使用 auth.signInWithOtp({ phone }) 替代。
|
|
1530
|
+
*
|
|
1531
|
+
* @example
|
|
1532
|
+
* ```javascript
|
|
1533
|
+
* // 验证码登录
|
|
1534
|
+
* const loginState = await auth.signInWithPhoneCodeOrPassword({
|
|
1535
|
+
* phoneNumber: '+8613800138000',
|
|
1536
|
+
* phoneCode: '123456'
|
|
1537
|
+
* });
|
|
1538
|
+
*
|
|
1539
|
+
* // 密码登录
|
|
1540
|
+
* const loginState = await auth.signInWithPhoneCodeOrPassword({
|
|
1541
|
+
* phoneNumber: '+8613800138000',
|
|
1542
|
+
* password: 'password123'
|
|
1543
|
+
* });
|
|
1544
|
+
* ```
|
|
1545
|
+
*
|
|
1546
|
+
* @param params
|
|
1547
|
+
*/
|
|
1548
|
+
signInWithPhoneCodeOrPassword(params: {
|
|
1549
|
+
phoneNumber: string
|
|
1550
|
+
phoneCode?: string
|
|
1551
|
+
password?: string
|
|
1552
|
+
}): Promise<ILoginState>
|
|
1553
|
+
|
|
1554
|
+
/**
|
|
1555
|
+
* v1 API: 手机号强制重置密码
|
|
1556
|
+
*
|
|
1557
|
+
* @deprecated 建议使用 auth.resetPasswordForEmail(phoneNumber) 替代。
|
|
1558
|
+
*
|
|
1559
|
+
* @example
|
|
1560
|
+
* ```javascript
|
|
1561
|
+
* const loginState = await auth.forceResetPwdByPhoneCode({
|
|
1562
|
+
* phoneNumber: '+8613800138000',
|
|
1563
|
+
* phoneCode: '123456',
|
|
1564
|
+
* password: 'newPassword'
|
|
1565
|
+
* });
|
|
1566
|
+
* ```
|
|
1567
|
+
*
|
|
1568
|
+
* @param params
|
|
1569
|
+
*/
|
|
1570
|
+
forceResetPwdByPhoneCode(params: {
|
|
1571
|
+
phoneNumber: string
|
|
1572
|
+
phoneCode: string
|
|
1573
|
+
password: string
|
|
1574
|
+
}): Promise<ILoginState>
|
|
1575
|
+
|
|
1576
|
+
/**
|
|
1577
|
+
* v1 API: 接收一个回调函数,在刷新短期访问令牌前调用,根据返回值决定是否刷新
|
|
1578
|
+
*
|
|
1579
|
+
* @deprecated 建议使用 auth.onAuthStateChange(callback) 监听 TOKEN_REFRESHED 事件替代。
|
|
1580
|
+
*
|
|
1581
|
+
* @param callback 回调函数,返回 true 则刷新,返回 false 则不刷新
|
|
1582
|
+
*/
|
|
1583
|
+
shouldRefreshAccessToken(callback: () => boolean): void
|
|
1584
|
+
|
|
1585
|
+
/**
|
|
1586
|
+
* v1 API: 接收一个回调函数,在登录状态过期时调用
|
|
1587
|
+
*
|
|
1588
|
+
* @deprecated 建议使用 auth.onAuthStateChange(callback) 替代,监听 SIGNED_OUT 事件。
|
|
1589
|
+
*
|
|
1590
|
+
* @param callback 登录态过期回调
|
|
1591
|
+
*/
|
|
1592
|
+
onLoginStateExpired(callback: Function): void
|
|
1593
|
+
|
|
1594
|
+
/**
|
|
1595
|
+
* v1 API: 接收一个回调函数,在短期访问令牌刷新后调用
|
|
1596
|
+
*
|
|
1597
|
+
* @deprecated 建议使用 auth.onAuthStateChange(callback) 替代,监听 TOKEN_REFRESHED 事件。
|
|
1598
|
+
*
|
|
1599
|
+
* @param callback 令牌刷新回调
|
|
1600
|
+
*/
|
|
1601
|
+
onAccessTokenRefreshed(callback: Function): void
|
|
1602
|
+
|
|
1603
|
+
/**
|
|
1604
|
+
* v1 API: 接收一个回调函数,在匿名登录状态被转换后调用
|
|
1605
|
+
*
|
|
1606
|
+
* @deprecated 建议使用 auth.onAuthStateChange(callback) 替代,监听 SIGNED_IN 事件。
|
|
1607
|
+
*
|
|
1608
|
+
* @param callback 匿名转正回调
|
|
1609
|
+
*/
|
|
1610
|
+
onAnonymousConverted(callback: Function): void
|
|
1611
|
+
|
|
1612
|
+
/**
|
|
1613
|
+
* v1 API: 接收一个回调函数,在登录类型发生变化后调用
|
|
1614
|
+
*
|
|
1615
|
+
* @deprecated 建议使用 auth.onAuthStateChange(callback) 替代,监听 SIGNED_IN / SIGNED_OUT 事件。
|
|
1616
|
+
*
|
|
1617
|
+
* @param callback 登录类型变化回调
|
|
1618
|
+
*/
|
|
1619
|
+
onLoginTypeChanged(callback: Function): void
|
|
1620
|
+
}
|
|
1621
|
+
|
|
1622
|
+
// ========== v1 兼容 Provider 类 ==========
|
|
1623
|
+
|
|
1624
|
+
/**
|
|
1625
|
+
* v1 微信登录 Provider
|
|
1626
|
+
*
|
|
1627
|
+
* @deprecated 建议使用 auth.signInWithOAuth({ provider }) 替代。
|
|
1628
|
+
*/
|
|
1629
|
+
interface WeixinAuthProvider {
|
|
1630
|
+
/**
|
|
1631
|
+
* 跳转微信授权页面进行登录
|
|
1632
|
+
* @deprecated 建议使用 auth.signInWithOAuth({ provider: 'providerId' }) 替代。
|
|
1633
|
+
*/
|
|
1634
|
+
signInWithRedirect(): void
|
|
1635
|
+
/**
|
|
1636
|
+
* 获取微信授权重定向结果
|
|
1637
|
+
* @deprecated 建议使用 auth.verifyOAuth({ code, state, provider }) 替代。
|
|
1638
|
+
*/
|
|
1639
|
+
getRedirectResult(options?: { createUser?: boolean; syncUserInfo?: boolean }): Promise<any>
|
|
1640
|
+
/**
|
|
1641
|
+
* 获取微信绑定重定向结果
|
|
1642
|
+
* @deprecated 建议使用 auth.linkIdentity({ provider: 'providerId' }) 替代。
|
|
1643
|
+
*/
|
|
1644
|
+
getLinkRedirectResult(options?: { withUnionId?: boolean }): Promise<void>
|
|
1645
|
+
}
|
|
1646
|
+
|
|
1647
|
+
/**
|
|
1648
|
+
* v1 自定义登录 Provider
|
|
1649
|
+
*
|
|
1650
|
+
* @deprecated 建议使用 auth.signInWithCustomTicket(() => Promise.resolve(ticket)) 替代。
|
|
1651
|
+
*/
|
|
1652
|
+
interface CustomAuthProvider {
|
|
1653
|
+
/**
|
|
1654
|
+
* 使用自定义登录凭据 ticket 登录云开发
|
|
1655
|
+
* @param ticket 自定义登录 ticket
|
|
1656
|
+
* @deprecated 建议使用 auth.signInWithCustomTicket(() => Promise.resolve(ticket)) 替代。
|
|
1657
|
+
*/
|
|
1658
|
+
signIn(ticket: string): Promise<void>
|
|
1659
|
+
}
|
|
1660
|
+
|
|
1661
|
+
/**
|
|
1662
|
+
* v1 匿名登录 Provider
|
|
1663
|
+
*
|
|
1664
|
+
* @deprecated 建议使用 auth.signInAnonymously({}) 替代。
|
|
1665
|
+
*/
|
|
1666
|
+
interface AnonymousAuthProvider {
|
|
1667
|
+
/**
|
|
1668
|
+
* 匿名登录云开发
|
|
1669
|
+
* @deprecated 建议使用 auth.signInAnonymously({}) 替代。
|
|
1670
|
+
*/
|
|
1671
|
+
signIn(): Promise<void>
|
|
1310
1672
|
}
|
|
1311
1673
|
}
|
|
1312
1674
|
/**
|
|
@@ -1427,68 +1789,427 @@ declare namespace cloudbase.storage {
|
|
|
1427
1789
|
}>
|
|
1428
1790
|
requestId?: string
|
|
1429
1791
|
}
|
|
1430
|
-
}
|
|
1431
1792
|
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1793
|
+
interface ICloudbaseGetFileInfoResultItem {
|
|
1794
|
+
code?: string
|
|
1795
|
+
message?: string
|
|
1796
|
+
fileID: string
|
|
1797
|
+
tempFileURL: string
|
|
1798
|
+
fileName?: string
|
|
1799
|
+
cloudId?: string
|
|
1800
|
+
contentType?: string
|
|
1801
|
+
mime?: string
|
|
1802
|
+
size?: number
|
|
1803
|
+
cacheControl?: string
|
|
1804
|
+
lastModified?: string
|
|
1805
|
+
etag?: string
|
|
1441
1806
|
}
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
* {@link https://docs.cloudbase.net/api-reference/webv3/database.html#shu-ju-ku-shi-shi-tui-song}
|
|
1447
|
-
*
|
|
1448
|
-
* @example
|
|
1449
|
-
* // 启动监听
|
|
1450
|
-
* const ref = db
|
|
1451
|
-
* .collection("collName")
|
|
1452
|
-
* .where({ test: _.gt(0) })
|
|
1453
|
-
* .watch({
|
|
1454
|
-
* onChange: (snapshot) => {
|
|
1455
|
-
* console.log("收到snapshot**********", snapshot);
|
|
1456
|
-
* },
|
|
1457
|
-
* onError: (error) => {
|
|
1458
|
-
* console.log("收到error**********", error);
|
|
1459
|
-
* }
|
|
1460
|
-
* });
|
|
1461
|
-
* // 关闭监听
|
|
1462
|
-
* ref.close();
|
|
1463
|
-
*/
|
|
1464
|
-
close: () => void
|
|
1807
|
+
|
|
1808
|
+
interface ICloudbaseGetFileInfoResult {
|
|
1809
|
+
fileList: ICloudbaseGetFileInfoResultItem[]
|
|
1810
|
+
requestId: string
|
|
1465
1811
|
}
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1812
|
+
|
|
1813
|
+
// ---- Supabase-like Storage Types ----
|
|
1814
|
+
|
|
1815
|
+
type FileBody =
|
|
1816
|
+
| ArrayBuffer
|
|
1817
|
+
| ArrayBufferView
|
|
1818
|
+
| Blob
|
|
1819
|
+
| Buffer
|
|
1820
|
+
| File
|
|
1821
|
+
| FormData
|
|
1822
|
+
| NodeJS.ReadableStream
|
|
1823
|
+
| ReadableStream<Uint8Array>
|
|
1824
|
+
| URLSearchParams
|
|
1825
|
+
| string
|
|
1826
|
+
|
|
1827
|
+
interface FileOptions {
|
|
1828
|
+
cacheControl?: string
|
|
1829
|
+
contentType?: string
|
|
1830
|
+
upsert?: boolean
|
|
1831
|
+
duplex?: string
|
|
1832
|
+
metadata?: Record<string, any>
|
|
1833
|
+
headers?: Record<string, string>
|
|
1473
1834
|
}
|
|
1474
1835
|
|
|
1475
|
-
interface
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
updatedFields?: any
|
|
1482
|
-
removedFields?: any
|
|
1836
|
+
interface TransformOptions {
|
|
1837
|
+
width?: number
|
|
1838
|
+
height?: number
|
|
1839
|
+
resize?: 'cover' | 'contain' | 'fill'
|
|
1840
|
+
quality?: number
|
|
1841
|
+
format?: 'origin'
|
|
1483
1842
|
}
|
|
1484
1843
|
|
|
1485
|
-
|
|
1844
|
+
interface FileObject {
|
|
1845
|
+
name: string
|
|
1846
|
+
bucket_id: string
|
|
1847
|
+
owner: string
|
|
1848
|
+
id: string
|
|
1849
|
+
updated_at: string
|
|
1850
|
+
created_at: string
|
|
1851
|
+
/** @deprecated */
|
|
1852
|
+
last_accessed_at: string
|
|
1853
|
+
metadata: Record<string, any>
|
|
1854
|
+
buckets: {
|
|
1855
|
+
id: string
|
|
1856
|
+
name: string
|
|
1857
|
+
owner: string
|
|
1858
|
+
public: boolean
|
|
1859
|
+
created_at: string
|
|
1860
|
+
updated_at: string
|
|
1861
|
+
}
|
|
1862
|
+
}
|
|
1486
1863
|
|
|
1487
|
-
interface
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1864
|
+
interface FileObjectV2 {
|
|
1865
|
+
id: string
|
|
1866
|
+
version: string
|
|
1867
|
+
name: string
|
|
1868
|
+
bucketId: string
|
|
1869
|
+
updatedAt: string
|
|
1870
|
+
createdAt: string
|
|
1871
|
+
/** @deprecated */
|
|
1872
|
+
lastAccessedAt: string
|
|
1873
|
+
size?: number
|
|
1874
|
+
cacheControl?: string
|
|
1875
|
+
contentType?: string
|
|
1876
|
+
etag?: string
|
|
1877
|
+
lastModified?: string
|
|
1878
|
+
metadata?: Record<string, any>
|
|
1879
|
+
}
|
|
1880
|
+
|
|
1881
|
+
class StorageError extends Error {
|
|
1882
|
+
name: 'StorageError'
|
|
1883
|
+
constructor(message: string)
|
|
1884
|
+
}
|
|
1885
|
+
|
|
1886
|
+
/**
|
|
1887
|
+
* Supabase 风格的文件存储 API
|
|
1888
|
+
*
|
|
1889
|
+
* 通过 `app.storage` 获取实例,提供类似 Supabase Storage 的操作接口。
|
|
1890
|
+
*
|
|
1891
|
+
* @example
|
|
1892
|
+
* ```typescript
|
|
1893
|
+
* const app = cloudbase.init({ env: 'your-envid' })
|
|
1894
|
+
* const bucket = app.storage.from('my-bucket')
|
|
1895
|
+
*
|
|
1896
|
+
* // 上传文件
|
|
1897
|
+
* const { data, error } = await bucket.upload('path/to/file.jpg', file)
|
|
1898
|
+
*
|
|
1899
|
+
* // 获取签名 URL
|
|
1900
|
+
* const { data } = await bucket.createSignedUrl('path/to/file.jpg', 3600)
|
|
1901
|
+
*
|
|
1902
|
+
* // 下载文件
|
|
1903
|
+
* const { data } = await bucket.download('path/to/file.jpg')
|
|
1904
|
+
* ```
|
|
1905
|
+
*/
|
|
1906
|
+
interface SupabaseFileAPILikeStorage {
|
|
1907
|
+
/**
|
|
1908
|
+
* 启用错误抛出模式,而非返回 `{ data: null, error }` 格式
|
|
1909
|
+
*/
|
|
1910
|
+
throwOnError(): this
|
|
1911
|
+
|
|
1912
|
+
/**
|
|
1913
|
+
* 选择存储桶
|
|
1914
|
+
*
|
|
1915
|
+
* @param bucket 存储桶名称
|
|
1916
|
+
* @returns 当前实例(链式调用)
|
|
1917
|
+
*
|
|
1918
|
+
* @example
|
|
1919
|
+
* ```typescript
|
|
1920
|
+
* const bucket = app.storage.from('my-bucket')
|
|
1921
|
+
* ```
|
|
1922
|
+
*/
|
|
1923
|
+
from(bucket?: string): this
|
|
1924
|
+
|
|
1925
|
+
/**
|
|
1926
|
+
* 上传文件
|
|
1927
|
+
*
|
|
1928
|
+
* @param path 文件路径
|
|
1929
|
+
* @param fileBody 文件内容
|
|
1930
|
+
* @param fileOptions 上传选项
|
|
1931
|
+
*/
|
|
1932
|
+
upload(
|
|
1933
|
+
path: string,
|
|
1934
|
+
fileBody: FileBody,
|
|
1935
|
+
fileOptions?: FileOptions,
|
|
1936
|
+
): Promise<
|
|
1937
|
+
| { data: { id: string; path: string; fullPath: string }; error: null }
|
|
1938
|
+
| { data: null; error: StorageError }
|
|
1939
|
+
>
|
|
1940
|
+
|
|
1941
|
+
/**
|
|
1942
|
+
* 上传文件到已签名的 URL
|
|
1943
|
+
*
|
|
1944
|
+
* @param path 文件路径
|
|
1945
|
+
* @param token 签名 Token
|
|
1946
|
+
* @param fileBody 文件内容
|
|
1947
|
+
* @param fileOptions 上传选项
|
|
1948
|
+
*/
|
|
1949
|
+
uploadToSignedUrl(
|
|
1950
|
+
path: string,
|
|
1951
|
+
token: string,
|
|
1952
|
+
fileBody: FileBody,
|
|
1953
|
+
fileOptions?: FileOptions,
|
|
1954
|
+
): Promise<
|
|
1955
|
+
| { data: { id: string; path: string; fullPath: string }; error: null }
|
|
1956
|
+
| { data: null; error: StorageError }
|
|
1957
|
+
>
|
|
1958
|
+
|
|
1959
|
+
/**
|
|
1960
|
+
* 创建用于上传的签名 URL
|
|
1961
|
+
*
|
|
1962
|
+
* @param path 文件路径
|
|
1963
|
+
*/
|
|
1964
|
+
createSignedUploadUrl(path: string): Promise<
|
|
1965
|
+
| {
|
|
1966
|
+
data: {
|
|
1967
|
+
signedUrl: string
|
|
1968
|
+
token: string
|
|
1969
|
+
path: string
|
|
1970
|
+
authorization?: string
|
|
1971
|
+
id?: string
|
|
1972
|
+
cosFileId?: string
|
|
1973
|
+
downloadUrl?: string
|
|
1974
|
+
}
|
|
1975
|
+
error: null
|
|
1976
|
+
}
|
|
1977
|
+
| { data: null; error: StorageError }
|
|
1978
|
+
>
|
|
1979
|
+
|
|
1980
|
+
/**
|
|
1981
|
+
* 更新(覆盖)文件
|
|
1982
|
+
*
|
|
1983
|
+
* @param path 文件路径
|
|
1984
|
+
* @param fileBody 文件内容
|
|
1985
|
+
* @param fileOptions 上传选项
|
|
1986
|
+
*/
|
|
1987
|
+
update(
|
|
1988
|
+
path: string,
|
|
1989
|
+
fileBody: FileBody,
|
|
1990
|
+
fileOptions?: FileOptions,
|
|
1991
|
+
): Promise<
|
|
1992
|
+
| { data: { id: string; path: string; fullPath: string }; error: null }
|
|
1993
|
+
| { data: null; error: StorageError }
|
|
1994
|
+
>
|
|
1995
|
+
|
|
1996
|
+
/**
|
|
1997
|
+
* 移动文件(复制后删除源文件)
|
|
1998
|
+
*
|
|
1999
|
+
* @param fromPath 源文件路径
|
|
2000
|
+
* @param toPath 目标文件路径
|
|
2001
|
+
*/
|
|
2002
|
+
move(
|
|
2003
|
+
fromPath: string,
|
|
2004
|
+
toPath: string,
|
|
2005
|
+
): Promise<
|
|
2006
|
+
| { data: { message: string }; error: null }
|
|
2007
|
+
| { data: null; error: StorageError }
|
|
2008
|
+
>
|
|
2009
|
+
|
|
2010
|
+
/**
|
|
2011
|
+
* 复制文件
|
|
2012
|
+
*
|
|
2013
|
+
* @param fromPath 源文件路径
|
|
2014
|
+
* @param toPath 目标文件路径
|
|
2015
|
+
*/
|
|
2016
|
+
copy(
|
|
2017
|
+
fromPath: string,
|
|
2018
|
+
toPath: string,
|
|
2019
|
+
): Promise<
|
|
2020
|
+
| { data: { path: string }; error: null }
|
|
2021
|
+
| { data: null; error: StorageError }
|
|
2022
|
+
>
|
|
2023
|
+
|
|
2024
|
+
/**
|
|
2025
|
+
* 创建签名下载 URL
|
|
2026
|
+
*
|
|
2027
|
+
* @param path 文件路径
|
|
2028
|
+
* @param expiresIn 有效期(秒)
|
|
2029
|
+
* @param options 可选配置
|
|
2030
|
+
*/
|
|
2031
|
+
createSignedUrl(
|
|
2032
|
+
path: string,
|
|
2033
|
+
expiresIn: number,
|
|
2034
|
+
options?: {
|
|
2035
|
+
download?: string | boolean
|
|
2036
|
+
transform?: TransformOptions
|
|
2037
|
+
},
|
|
2038
|
+
): Promise<
|
|
2039
|
+
| { data: { signedUrl: string }; error: null }
|
|
2040
|
+
| { data: null; error: StorageError }
|
|
2041
|
+
>
|
|
2042
|
+
|
|
2043
|
+
/**
|
|
2044
|
+
* 批量创建签名下载 URL
|
|
2045
|
+
*
|
|
2046
|
+
* @param paths 文件路径数组
|
|
2047
|
+
* @param expiresIn 有效期(秒)
|
|
2048
|
+
*/
|
|
2049
|
+
createSignedUrls(
|
|
2050
|
+
paths: string[],
|
|
2051
|
+
expiresIn: number,
|
|
2052
|
+
): Promise<
|
|
2053
|
+
| { data: Array<{ path: string; signedUrl: string; error: string | null }>; error: null }
|
|
2054
|
+
| { data: null; error: StorageError }
|
|
2055
|
+
>
|
|
2056
|
+
|
|
2057
|
+
/**
|
|
2058
|
+
* 下载文件,返回 Blob
|
|
2059
|
+
*
|
|
2060
|
+
* @param path 文件路径
|
|
2061
|
+
* @param options 图片转换选项
|
|
2062
|
+
*/
|
|
2063
|
+
download(
|
|
2064
|
+
path: string,
|
|
2065
|
+
options?: TransformOptions,
|
|
2066
|
+
): Promise<{ data: Blob; error: StorageError | null }>
|
|
2067
|
+
|
|
2068
|
+
/**
|
|
2069
|
+
* 获取文件详细信息
|
|
2070
|
+
*
|
|
2071
|
+
* @param pathOrFileId 相对路径或 CloudBase fileID
|
|
2072
|
+
*/
|
|
2073
|
+
info(pathOrFileId: string): Promise<
|
|
2074
|
+
| { data: FileObjectV2; error: null }
|
|
2075
|
+
| { data: null; error: StorageError }
|
|
2076
|
+
>
|
|
2077
|
+
|
|
2078
|
+
/**
|
|
2079
|
+
* 检查文件是否存在
|
|
2080
|
+
*
|
|
2081
|
+
* @param pathOrFileId 相对路径或 CloudBase fileID
|
|
2082
|
+
*/
|
|
2083
|
+
exists(pathOrFileId: string): Promise<
|
|
2084
|
+
| { data: boolean; error: null }
|
|
2085
|
+
| { data: null; error: StorageError }
|
|
2086
|
+
>
|
|
2087
|
+
|
|
2088
|
+
/**
|
|
2089
|
+
* 获取文件的公开 URL
|
|
2090
|
+
*
|
|
2091
|
+
* @param path 文件路径
|
|
2092
|
+
* @param options 可选配置
|
|
2093
|
+
*/
|
|
2094
|
+
getPublicUrl(
|
|
2095
|
+
path: string,
|
|
2096
|
+
options?: {
|
|
2097
|
+
download?: string | boolean
|
|
2098
|
+
transform?: TransformOptions
|
|
2099
|
+
},
|
|
2100
|
+
): Promise<
|
|
2101
|
+
| { data: { publicUrl: string } }
|
|
2102
|
+
| { data: null; error: StorageError }
|
|
2103
|
+
>
|
|
2104
|
+
|
|
2105
|
+
/**
|
|
2106
|
+
* 批量删除文件
|
|
2107
|
+
*
|
|
2108
|
+
* @param paths 文件路径数组
|
|
2109
|
+
*/
|
|
2110
|
+
remove(paths: string[]): Promise<
|
|
2111
|
+
| { data: FileObject[]; error: null }
|
|
2112
|
+
| { data: null; error: StorageError }
|
|
2113
|
+
>
|
|
2114
|
+
|
|
2115
|
+
// ---- 继承自 CloudbaseStorage 的方法 ----
|
|
2116
|
+
|
|
2117
|
+
uploadFile(
|
|
2118
|
+
params: ICloudbaseUploadFileParams,
|
|
2119
|
+
callback?: Function,
|
|
2120
|
+
): Promise<ICloudbaseUploadFileResult>
|
|
2121
|
+
|
|
2122
|
+
deleteFile(
|
|
2123
|
+
params: ICloudbaseDeleteFileParams,
|
|
2124
|
+
callback?: Function,
|
|
2125
|
+
): Promise<ICloudbaseDeleteFileResult>
|
|
2126
|
+
|
|
2127
|
+
getTempFileURL(
|
|
2128
|
+
params: ICloudbaseGetTempFileURLParams,
|
|
2129
|
+
callback?: Function,
|
|
2130
|
+
): Promise<ICloudbaseGetTempFileURLResult>
|
|
2131
|
+
|
|
2132
|
+
downloadFile(
|
|
2133
|
+
params: ICloudbaseDownloadFileParams,
|
|
2134
|
+
callback?: Function,
|
|
2135
|
+
): Promise<ICloudbaseDownloadFileResult>
|
|
2136
|
+
|
|
2137
|
+
getUploadMetadata(
|
|
2138
|
+
params: ICloudbaseGetUploadMetadataParams,
|
|
2139
|
+
callback?: Function,
|
|
2140
|
+
): Promise<ICloudbaseFileMetaDataRes>
|
|
2141
|
+
|
|
2142
|
+
copyFile(
|
|
2143
|
+
params: ICloudbaseCopyFileParams,
|
|
2144
|
+
callback?: Function,
|
|
2145
|
+
): Promise<ICloudbaseCopyFileResult>
|
|
2146
|
+
|
|
2147
|
+
getFileInfo(
|
|
2148
|
+
params: ICloudbaseGetTempFileURLParams,
|
|
2149
|
+
): Promise<ICloudbaseGetFileInfoResult>
|
|
2150
|
+
}
|
|
2151
|
+
}
|
|
2152
|
+
|
|
2153
|
+
declare namespace cloudbase.database {
|
|
2154
|
+
/**
|
|
2155
|
+
* realtime types
|
|
2156
|
+
*/
|
|
2157
|
+
interface IWatchOptions {
|
|
2158
|
+
// server realtime data init & change event
|
|
2159
|
+
onChange: (snapshot: ISnapshot) => void
|
|
2160
|
+
// error while connecting / listening
|
|
2161
|
+
onError: (error: any) => void
|
|
2162
|
+
}
|
|
2163
|
+
interface DBRealtimeListener {
|
|
2164
|
+
/**
|
|
2165
|
+
* 关闭实时推送
|
|
2166
|
+
*
|
|
2167
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database.html#shu-ju-ku-shi-shi-tui-song}
|
|
2168
|
+
*
|
|
2169
|
+
* @example
|
|
2170
|
+
* // 启动监听
|
|
2171
|
+
* const ref = db
|
|
2172
|
+
* .collection("collName")
|
|
2173
|
+
* .where({ test: _.gt(0) })
|
|
2174
|
+
* .watch({
|
|
2175
|
+
* onChange: (snapshot) => {
|
|
2176
|
+
* console.log("收到snapshot**********", snapshot);
|
|
2177
|
+
* },
|
|
2178
|
+
* onError: (error) => {
|
|
2179
|
+
* console.log("收到error**********", error);
|
|
2180
|
+
* }
|
|
2181
|
+
* });
|
|
2182
|
+
* // 关闭监听
|
|
2183
|
+
* ref.close();
|
|
2184
|
+
*/
|
|
2185
|
+
close: () => void
|
|
2186
|
+
}
|
|
2187
|
+
type DataType = 'init' | 'update' | 'add' | 'remove' | 'replace' | 'limit'
|
|
2188
|
+
type QueueType = 'init' | 'enqueue' | 'dequeue' | 'update'
|
|
2189
|
+
interface ISnapshot {
|
|
2190
|
+
id: number
|
|
2191
|
+
docChanges: ISingleDBEvent[]
|
|
2192
|
+
docs: Record<string, any>
|
|
2193
|
+
type?: SnapshotType
|
|
2194
|
+
}
|
|
2195
|
+
|
|
2196
|
+
interface ISingleDBEvent {
|
|
2197
|
+
id: number
|
|
2198
|
+
dataType: DataType
|
|
2199
|
+
queueType: QueueType
|
|
2200
|
+
docId: string
|
|
2201
|
+
doc: Record<string, any>
|
|
2202
|
+
updatedFields?: any
|
|
2203
|
+
removedFields?: any
|
|
2204
|
+
}
|
|
2205
|
+
|
|
2206
|
+
type SnapshotType = 'init'
|
|
2207
|
+
|
|
2208
|
+
interface IWatchable {
|
|
2209
|
+
/**
|
|
2210
|
+
* 开启实时推送
|
|
2211
|
+
*
|
|
2212
|
+
* {@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}
|
|
1492
2213
|
*
|
|
1493
2214
|
* @example
|
|
1494
2215
|
* const ref = db
|
|
@@ -1515,21 +2236,44 @@ declare namespace cloudbase.database {
|
|
|
1515
2236
|
*/
|
|
1516
2237
|
interface ICollection extends IQuery {
|
|
1517
2238
|
/**
|
|
1518
|
-
*
|
|
2239
|
+
* 向集合中添加一条新记录
|
|
2240
|
+
*
|
|
2241
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database#add}
|
|
2242
|
+
*
|
|
2243
|
+
* @example
|
|
2244
|
+
* const result = await db.collection('todos').add({
|
|
2245
|
+
* title: '学习 CloudBase',
|
|
2246
|
+
* completed: false
|
|
2247
|
+
* })
|
|
2248
|
+
* console.log('新增成功,文档 ID:', result.id)
|
|
1519
2249
|
*
|
|
1520
|
-
*
|
|
2250
|
+
* @param data 要新增的数据对象,支持嵌套对象、数组、地理位置等数据类型
|
|
1521
2251
|
*
|
|
1522
|
-
* @
|
|
2252
|
+
* @return Promise<AddRes> 包含新增文档的 id 和 requestId
|
|
1523
2253
|
*/
|
|
1524
|
-
add(data: Object): Promise<
|
|
2254
|
+
add(data: Object): Promise<AddRes>
|
|
1525
2255
|
/**
|
|
1526
2256
|
* 获取一条文档的引用
|
|
1527
2257
|
*
|
|
1528
|
-
* {@link https://docs.cloudbase.net/api-reference/webv3/database#record--document}
|
|
2258
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database#record--document}
|
|
1529
2259
|
*
|
|
1530
2260
|
* @param id 文档ID
|
|
1531
2261
|
*/
|
|
1532
|
-
doc(id: string): IDocument
|
|
2262
|
+
doc(id: string | number): IDocument
|
|
2263
|
+
/**
|
|
2264
|
+
* 获取聚合操作对象
|
|
2265
|
+
*
|
|
2266
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database#aggregate}
|
|
2267
|
+
*
|
|
2268
|
+
* @example
|
|
2269
|
+
* const result = await db.collection('todos')
|
|
2270
|
+
* .aggregate()
|
|
2271
|
+
* .group({ _id: '$priority', count: { $sum: 1 } })
|
|
2272
|
+
* .end()
|
|
2273
|
+
*
|
|
2274
|
+
* @return 聚合操作对象,可链式调用各种聚合阶段方法
|
|
2275
|
+
*/
|
|
2276
|
+
aggregate(): IAggregate
|
|
1533
2277
|
}
|
|
1534
2278
|
/**
|
|
1535
2279
|
* command types
|
|
@@ -1549,7 +2293,7 @@ declare namespace cloudbase.database {
|
|
|
1549
2293
|
/**
|
|
1550
2294
|
* 表示字段等于某个值
|
|
1551
2295
|
*
|
|
1552
|
-
* {@link https://docs.cloudbase.net/api-reference/webv3/database#eq}
|
|
2296
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database#eq}
|
|
1553
2297
|
*
|
|
1554
2298
|
* @example
|
|
1555
2299
|
* const _ = db.command;
|
|
@@ -1564,7 +2308,7 @@ declare namespace cloudbase.database {
|
|
|
1564
2308
|
/**
|
|
1565
2309
|
* 表示字段不等于某个值
|
|
1566
2310
|
*
|
|
1567
|
-
* {@link https://docs.cloudbase.net/api-reference/webv3/database#neq}
|
|
2311
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database#neq}
|
|
1568
2312
|
*
|
|
1569
2313
|
* @example
|
|
1570
2314
|
* const _ = db.command;
|
|
@@ -1579,7 +2323,7 @@ declare namespace cloudbase.database {
|
|
|
1579
2323
|
/**
|
|
1580
2324
|
* 字段大于指定值
|
|
1581
2325
|
*
|
|
1582
|
-
* {@link https://docs.cloudbase.net/api-reference/webv3/database#gt}
|
|
2326
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database#gt}
|
|
1583
2327
|
*
|
|
1584
2328
|
* @example
|
|
1585
2329
|
* const _ = db.command;
|
|
@@ -1594,7 +2338,7 @@ declare namespace cloudbase.database {
|
|
|
1594
2338
|
/**
|
|
1595
2339
|
* 字段大于或等于指定值
|
|
1596
2340
|
*
|
|
1597
|
-
* {@link https://docs.cloudbase.net/api-reference/webv3/database#neq}
|
|
2341
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database#neq}
|
|
1598
2342
|
*
|
|
1599
2343
|
* @example
|
|
1600
2344
|
* const _ = db.command;
|
|
@@ -1609,7 +2353,7 @@ declare namespace cloudbase.database {
|
|
|
1609
2353
|
/**
|
|
1610
2354
|
* 字段小于指定值
|
|
1611
2355
|
*
|
|
1612
|
-
* {@link https://docs.cloudbase.net/api-reference/webv3/database#lt}
|
|
2356
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database#lt}
|
|
1613
2357
|
*
|
|
1614
2358
|
* @example
|
|
1615
2359
|
* const _ = db.command;
|
|
@@ -1624,7 +2368,7 @@ declare namespace cloudbase.database {
|
|
|
1624
2368
|
/**
|
|
1625
2369
|
* 字段小于或等于指定值
|
|
1626
2370
|
*
|
|
1627
|
-
* {@link https://docs.cloudbase.net/api-reference/webv3/database#lte}
|
|
2371
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database#lte}
|
|
1628
2372
|
*
|
|
1629
2373
|
* @example
|
|
1630
2374
|
* const _ = db.command;
|
|
@@ -1639,7 +2383,7 @@ declare namespace cloudbase.database {
|
|
|
1639
2383
|
/**
|
|
1640
2384
|
* 字段值在给定的数组中
|
|
1641
2385
|
*
|
|
1642
|
-
* {@link https://docs.cloudbase.net/api-reference/webv3/database#in}
|
|
2386
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database#in}
|
|
1643
2387
|
*
|
|
1644
2388
|
* @example
|
|
1645
2389
|
* const _ = db.command;
|
|
@@ -1654,7 +2398,7 @@ declare namespace cloudbase.database {
|
|
|
1654
2398
|
/**
|
|
1655
2399
|
* 字段值不在给定的数组中
|
|
1656
2400
|
*
|
|
1657
|
-
* {@link https://docs.cloudbase.net/api-reference/webv3/database#nin}
|
|
2401
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database#nin}
|
|
1658
2402
|
*
|
|
1659
2403
|
* @example
|
|
1660
2404
|
* const _ = db.command;
|
|
@@ -1669,7 +2413,7 @@ declare namespace cloudbase.database {
|
|
|
1669
2413
|
/**
|
|
1670
2414
|
* 表示需同时满足指定的两个或以上的条件
|
|
1671
2415
|
*
|
|
1672
|
-
* {@link https://docs.cloudbase.net/api-reference/webv3/database#and}
|
|
2416
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database#and}
|
|
1673
2417
|
*
|
|
1674
2418
|
* @example
|
|
1675
2419
|
* const _ = db.command;
|
|
@@ -1684,7 +2428,7 @@ declare namespace cloudbase.database {
|
|
|
1684
2428
|
/**
|
|
1685
2429
|
* 表示需满足所有指定条件中的至少一个
|
|
1686
2430
|
*
|
|
1687
|
-
* {@link https://docs.cloudbase.net/api-reference/webv3/database#or}
|
|
2431
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database#or}
|
|
1688
2432
|
*
|
|
1689
2433
|
* @example
|
|
1690
2434
|
* const _ = db.command;
|
|
@@ -1699,7 +2443,7 @@ declare namespace cloudbase.database {
|
|
|
1699
2443
|
/**
|
|
1700
2444
|
* 用于设定字段等于指定值
|
|
1701
2445
|
*
|
|
1702
|
-
* {@link https://docs.cloudbase.net/api-reference/webv3/database#set}
|
|
2446
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database#set}
|
|
1703
2447
|
*
|
|
1704
2448
|
* @example
|
|
1705
2449
|
* const _ = db.command;
|
|
@@ -1720,7 +2464,7 @@ declare namespace cloudbase.database {
|
|
|
1720
2464
|
/**
|
|
1721
2465
|
* 用于指示字段自增某个值
|
|
1722
2466
|
*
|
|
1723
|
-
* {@link https://docs.cloudbase.net/api-reference/webv3/database#inc}
|
|
2467
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database#inc}
|
|
1724
2468
|
*
|
|
1725
2469
|
* @example
|
|
1726
2470
|
* const _ = db.command;
|
|
@@ -1739,7 +2483,7 @@ declare namespace cloudbase.database {
|
|
|
1739
2483
|
/**
|
|
1740
2484
|
* 用于指示字段自乘某个值
|
|
1741
2485
|
*
|
|
1742
|
-
* {@link https://docs.cloudbase.net/api-reference/webv3/database#mul}
|
|
2486
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database#mul}
|
|
1743
2487
|
*
|
|
1744
2488
|
* @example
|
|
1745
2489
|
* const _ = db.command;
|
|
@@ -1758,7 +2502,7 @@ declare namespace cloudbase.database {
|
|
|
1758
2502
|
/**
|
|
1759
2503
|
* 用于表示删除某个字段
|
|
1760
2504
|
*
|
|
1761
|
-
* {@link https://docs.cloudbase.net/api-reference/webv3/database#remove}
|
|
2505
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database#remove}
|
|
1762
2506
|
*
|
|
1763
2507
|
* @example
|
|
1764
2508
|
* const _ = db.command;
|
|
@@ -1773,7 +2517,7 @@ declare namespace cloudbase.database {
|
|
|
1773
2517
|
/**
|
|
1774
2518
|
* 向数组尾部追加元素
|
|
1775
2519
|
*
|
|
1776
|
-
* {@link https://docs.cloudbase.net/api-reference/webv3/database#push}
|
|
2520
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database#push}
|
|
1777
2521
|
*
|
|
1778
2522
|
* @example
|
|
1779
2523
|
* const _ = db.command;
|
|
@@ -1789,7 +2533,7 @@ declare namespace cloudbase.database {
|
|
|
1789
2533
|
/**
|
|
1790
2534
|
* 删除数组尾部元素
|
|
1791
2535
|
*
|
|
1792
|
-
* {@link https://docs.cloudbase.net/api-reference/webv3/database#pop}
|
|
2536
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database#pop}
|
|
1793
2537
|
*
|
|
1794
2538
|
* @example
|
|
1795
2539
|
* const _ = db.command;
|
|
@@ -1804,7 +2548,7 @@ declare namespace cloudbase.database {
|
|
|
1804
2548
|
/**
|
|
1805
2549
|
* 向数组头部添加元素
|
|
1806
2550
|
*
|
|
1807
|
-
* {@link https://docs.cloudbase.net/api-reference/webv3/database#unshift}
|
|
2551
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database#unshift}
|
|
1808
2552
|
*
|
|
1809
2553
|
* @example
|
|
1810
2554
|
* const _ = db.command;
|
|
@@ -1820,7 +2564,7 @@ declare namespace cloudbase.database {
|
|
|
1820
2564
|
/**
|
|
1821
2565
|
* 删除数组头部元素
|
|
1822
2566
|
*
|
|
1823
|
-
* {@link https://docs.cloudbase.net/api-reference/webv3/database#shift}
|
|
2567
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database#shift}
|
|
1824
2568
|
*
|
|
1825
2569
|
* @example
|
|
1826
2570
|
* const _ = db.command;
|
|
@@ -1832,10 +2576,148 @@ declare namespace cloudbase.database {
|
|
|
1832
2576
|
*
|
|
1833
2577
|
*/
|
|
1834
2578
|
shift(): any
|
|
2579
|
+
/**
|
|
2580
|
+
* 条件取反
|
|
2581
|
+
*
|
|
2582
|
+
* @example
|
|
2583
|
+
* const _ = db.command;
|
|
2584
|
+
* db.collection('users').where({
|
|
2585
|
+
* status: _.not(_.eq('deleted'))
|
|
2586
|
+
* })
|
|
2587
|
+
*
|
|
2588
|
+
* @param condition 查询条件
|
|
2589
|
+
*/
|
|
2590
|
+
not(condition: any): any
|
|
2591
|
+
/**
|
|
2592
|
+
* 都不满足指定的条件
|
|
2593
|
+
*
|
|
2594
|
+
* @example
|
|
2595
|
+
* const _ = db.command;
|
|
2596
|
+
* db.collection('users').where(
|
|
2597
|
+
* _.nor([{ status: 'banned' }, { status: 'deleted' }])
|
|
2598
|
+
* )
|
|
2599
|
+
*
|
|
2600
|
+
* @param conditions 条件数组
|
|
2601
|
+
*/
|
|
2602
|
+
nor(conditions: any[]): any
|
|
2603
|
+
/**
|
|
2604
|
+
* 判断字段是否存在
|
|
2605
|
+
*
|
|
2606
|
+
* @example
|
|
2607
|
+
* const _ = db.command;
|
|
2608
|
+
* db.collection('users').where({
|
|
2609
|
+
* avatar: _.exists(true)
|
|
2610
|
+
* })
|
|
2611
|
+
*
|
|
2612
|
+
* @param val true 表示字段存在,false 表示不存在
|
|
2613
|
+
*/
|
|
2614
|
+
exists(val: boolean): any
|
|
2615
|
+
/**
|
|
2616
|
+
* 取模运算
|
|
2617
|
+
*
|
|
2618
|
+
* @example
|
|
2619
|
+
* const _ = db.command;
|
|
2620
|
+
* db.collection('users').where({
|
|
2621
|
+
* age: _.mod([2, 0])
|
|
2622
|
+
* })
|
|
2623
|
+
*
|
|
2624
|
+
* @param val [除数, 余数]
|
|
2625
|
+
*/
|
|
2626
|
+
mod(val: [number, number]): any
|
|
2627
|
+
/**
|
|
2628
|
+
* 数组包含所有指定元素
|
|
2629
|
+
*
|
|
2630
|
+
* @example
|
|
2631
|
+
* const _ = db.command;
|
|
2632
|
+
* db.collection('articles').where({
|
|
2633
|
+
* tags: _.all(['javascript', 'nodejs'])
|
|
2634
|
+
* })
|
|
2635
|
+
*
|
|
2636
|
+
* @param list 必须包含的元素数组
|
|
2637
|
+
*/
|
|
2638
|
+
all(list: any[]): any
|
|
2639
|
+
/**
|
|
2640
|
+
* 数组元素匹配
|
|
2641
|
+
*
|
|
2642
|
+
* @example
|
|
2643
|
+
* const _ = db.command;
|
|
2644
|
+
* db.collection('orders').where({
|
|
2645
|
+
* items: _.elemMatch({ price: _.gt(100) })
|
|
2646
|
+
* })
|
|
2647
|
+
*
|
|
2648
|
+
* @param condition 匹配条件对象
|
|
2649
|
+
*/
|
|
2650
|
+
elemMatch(condition: Object): any
|
|
2651
|
+
/**
|
|
2652
|
+
* 数组长度匹配
|
|
2653
|
+
*
|
|
2654
|
+
* @example
|
|
2655
|
+
* const _ = db.command;
|
|
2656
|
+
* db.collection('articles').where({
|
|
2657
|
+
* tags: _.size(3)
|
|
2658
|
+
* })
|
|
2659
|
+
*
|
|
2660
|
+
* @param size 数组长度
|
|
2661
|
+
*/
|
|
2662
|
+
size(size: number): any
|
|
2663
|
+
/**
|
|
2664
|
+
* 取最小值更新
|
|
2665
|
+
*
|
|
2666
|
+
* @param val 比较值
|
|
2667
|
+
*/
|
|
2668
|
+
min(val: number): any
|
|
2669
|
+
/**
|
|
2670
|
+
* 取最大值更新
|
|
2671
|
+
*
|
|
2672
|
+
* @param val 比较值
|
|
2673
|
+
*/
|
|
2674
|
+
max(val: number): any
|
|
2675
|
+
/**
|
|
2676
|
+
* 重命名字段
|
|
2677
|
+
*
|
|
2678
|
+
* @param newFieldName 新字段名
|
|
2679
|
+
*/
|
|
2680
|
+
rename(newFieldName: string): any
|
|
2681
|
+
/**
|
|
2682
|
+
* 位运算
|
|
2683
|
+
*
|
|
2684
|
+
* @param options 位运算选项,如 { and: 5 }
|
|
2685
|
+
*/
|
|
2686
|
+
bit(options: Object): any
|
|
2687
|
+
/**
|
|
2688
|
+
* 删除数组中匹配的元素
|
|
2689
|
+
*
|
|
2690
|
+
* @example
|
|
2691
|
+
* const _ = db.command;
|
|
2692
|
+
* db.collection('articles').doc('id').update({
|
|
2693
|
+
* tags: _.pull('要删除的标签')
|
|
2694
|
+
* })
|
|
2695
|
+
*
|
|
2696
|
+
* @param val 要删除的元素或匹配条件
|
|
2697
|
+
*/
|
|
2698
|
+
pull(val: any): any
|
|
2699
|
+
/**
|
|
2700
|
+
* 删除数组中所有匹配的元素
|
|
2701
|
+
*
|
|
2702
|
+
* @param list 要删除的元素数组
|
|
2703
|
+
*/
|
|
2704
|
+
pullAll(list: any[]): any
|
|
2705
|
+
/**
|
|
2706
|
+
* 向数组添加不重复的元素
|
|
2707
|
+
*
|
|
2708
|
+
* @example
|
|
2709
|
+
* const _ = db.command;
|
|
2710
|
+
* db.collection('articles').doc('id').update({
|
|
2711
|
+
* tags: _.addToSet('唯一标签')
|
|
2712
|
+
* })
|
|
2713
|
+
*
|
|
2714
|
+
* @param val 要添加的元素
|
|
2715
|
+
*/
|
|
2716
|
+
addToSet(val: any): any
|
|
1835
2717
|
/**
|
|
1836
2718
|
* 按从近到远的顺序,找出字段值在给定点的附近的文档
|
|
1837
2719
|
*
|
|
1838
|
-
* {@link https://docs.cloudbase.net/api-reference/webv3/database#geonear}
|
|
2720
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database#geonear}
|
|
1839
2721
|
*
|
|
1840
2722
|
* @example
|
|
1841
2723
|
* const _ = db.command;
|
|
@@ -1856,7 +2738,7 @@ declare namespace cloudbase.database {
|
|
|
1856
2738
|
/**
|
|
1857
2739
|
* 找出字段值在指定 Polygon / MultiPolygon 内的文档,无排序
|
|
1858
2740
|
*
|
|
1859
|
-
* {@link https://docs.cloudbase.net/api-reference/webv3/database#geowithin}
|
|
2741
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database#geowithin}
|
|
1860
2742
|
*
|
|
1861
2743
|
* @example
|
|
1862
2744
|
* const _ = db.command;
|
|
@@ -1875,7 +2757,7 @@ declare namespace cloudbase.database {
|
|
|
1875
2757
|
/**
|
|
1876
2758
|
* 找出字段值和给定的地理位置图形相交的文档
|
|
1877
2759
|
*
|
|
1878
|
-
* {@link https://docs.cloudbase.net/api-reference/webv3/database#geointersects}
|
|
2760
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database#geointersects}
|
|
1879
2761
|
*
|
|
1880
2762
|
* @example
|
|
1881
2763
|
* const _ = db.command;
|
|
@@ -1895,9 +2777,9 @@ declare namespace cloudbase.database {
|
|
|
1895
2777
|
*/
|
|
1896
2778
|
interface IDocument extends IWatchable {
|
|
1897
2779
|
/**
|
|
1898
|
-
*
|
|
2780
|
+
* 设置文档数据,如果文档不存在则创建新文档
|
|
1899
2781
|
*
|
|
1900
|
-
* {@link https://docs.cloudbase.net/api-reference/webv3/database.html#update-set}
|
|
2782
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database.html#update-set}
|
|
1901
2783
|
*
|
|
1902
2784
|
* @example
|
|
1903
2785
|
* collection
|
|
@@ -1905,55 +2787,65 @@ declare namespace cloudbase.database {
|
|
|
1905
2787
|
* .set({name:'cloudbase'})
|
|
1906
2788
|
* .then(res=>{})
|
|
1907
2789
|
*
|
|
1908
|
-
* @param data
|
|
2790
|
+
* @param data 要设置的数据对象,将完全替换原有文档内容
|
|
1909
2791
|
*
|
|
1910
|
-
* @return Promise
|
|
2792
|
+
* @return Promise<SetRes> 包含 updated 或 upsertedId
|
|
1911
2793
|
*/
|
|
1912
2794
|
set(data: Object): Promise<SetRes>
|
|
1913
2795
|
/**
|
|
1914
|
-
*
|
|
2796
|
+
* 获取文档数据
|
|
1915
2797
|
*
|
|
1916
|
-
* {@link https://docs.cloudbase.net/api-reference/webv3/database#get}
|
|
2798
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database#get}
|
|
1917
2799
|
*
|
|
1918
2800
|
* @example
|
|
1919
2801
|
* collection
|
|
1920
2802
|
* .doc('docId')
|
|
1921
2803
|
* .get()
|
|
1922
|
-
* .then(res=>{})
|
|
2804
|
+
* .then(res=>{ console.log(res.data) })
|
|
1923
2805
|
*
|
|
1924
|
-
* @return Promise
|
|
2806
|
+
* @return Promise<GetRes> 包含 data 数组和 requestId
|
|
1925
2807
|
*/
|
|
1926
2808
|
get(): Promise<GetRes>
|
|
1927
2809
|
/**
|
|
1928
|
-
*
|
|
2810
|
+
* 更新文档数据,如果文档不存在则不做任何操作
|
|
1929
2811
|
*
|
|
1930
|
-
* {@link https://docs.cloudbase.net/api-reference/webv3/database#update--set}
|
|
2812
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database#update--set}
|
|
1931
2813
|
*
|
|
1932
2814
|
* @example
|
|
1933
2815
|
* collection
|
|
1934
2816
|
* .doc('docId')
|
|
1935
|
-
* .update({
|
|
1936
|
-
* .then(res=>{})
|
|
2817
|
+
* .update({completed: true})
|
|
2818
|
+
* .then(res=>{ console.log(res.updated) })
|
|
1937
2819
|
*
|
|
1938
|
-
* @param data
|
|
2820
|
+
* @param data 要更新的数据对象,支持操作符
|
|
1939
2821
|
*
|
|
1940
|
-
* @return Promise
|
|
2822
|
+
* @return Promise<UpdateRes> 包含 updated 字段
|
|
1941
2823
|
*/
|
|
1942
|
-
update(data: Object): Promise<
|
|
2824
|
+
update(data: Object): Promise<UpdateRes>
|
|
1943
2825
|
/**
|
|
1944
2826
|
* 删除一条文档
|
|
1945
2827
|
*
|
|
1946
|
-
* {@link https://docs.cloudbase.net/api-reference/webv3/database.html#remove-2}
|
|
2828
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database.html#remove-2}
|
|
1947
2829
|
*
|
|
1948
2830
|
* @example
|
|
1949
2831
|
* collection
|
|
1950
2832
|
* .doc('docId')
|
|
1951
2833
|
* .remove()
|
|
1952
|
-
* .then(res=>{})
|
|
2834
|
+
* .then(res=>{ console.log(res.deleted) })
|
|
1953
2835
|
*
|
|
1954
|
-
* @return Promise
|
|
2836
|
+
* @return Promise<RemoveRes> 包含 deleted 字段
|
|
2837
|
+
*/
|
|
2838
|
+
remove(): Promise<RemoveRes>
|
|
2839
|
+
/**
|
|
2840
|
+
* 指定要返回的字段
|
|
2841
|
+
*
|
|
2842
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database#field}
|
|
2843
|
+
*
|
|
2844
|
+
* @param projection 字段投影对象,true 表示返回,false 表示不返回
|
|
2845
|
+
*
|
|
2846
|
+
* @return 文档引用,可继续链式调用 get()
|
|
1955
2847
|
*/
|
|
1956
|
-
|
|
2848
|
+
field(projection: Object): IDocument
|
|
1957
2849
|
}
|
|
1958
2850
|
/**
|
|
1959
2851
|
* query types
|
|
@@ -1962,7 +2854,7 @@ declare namespace cloudbase.database {
|
|
|
1962
2854
|
code?: string
|
|
1963
2855
|
message?: string
|
|
1964
2856
|
updated?: number
|
|
1965
|
-
upsertedId?:
|
|
2857
|
+
upsertedId?: string
|
|
1966
2858
|
requestId: string
|
|
1967
2859
|
}
|
|
1968
2860
|
interface GetRes {
|
|
@@ -1975,11 +2867,181 @@ declare namespace cloudbase.database {
|
|
|
1975
2867
|
interface UpdateRes {
|
|
1976
2868
|
requestId: string
|
|
1977
2869
|
updated?: number
|
|
1978
|
-
|
|
2870
|
+
upsertedId?: string
|
|
2871
|
+
code?: string
|
|
2872
|
+
message?: string
|
|
2873
|
+
}
|
|
2874
|
+
|
|
2875
|
+
interface AddRes {
|
|
2876
|
+
id: string
|
|
2877
|
+
requestId: string
|
|
2878
|
+
code?: string
|
|
2879
|
+
message?: string
|
|
2880
|
+
}
|
|
2881
|
+
|
|
2882
|
+
interface CountRes {
|
|
2883
|
+
total: number
|
|
2884
|
+
requestId: string
|
|
2885
|
+
code?: string
|
|
2886
|
+
message?: string
|
|
2887
|
+
}
|
|
2888
|
+
|
|
2889
|
+
interface RemoveRes {
|
|
2890
|
+
deleted: number
|
|
2891
|
+
requestId: string
|
|
2892
|
+
code?: string
|
|
2893
|
+
message?: string
|
|
2894
|
+
}
|
|
2895
|
+
|
|
2896
|
+
interface CreateCollectionRes {
|
|
2897
|
+
data: string
|
|
2898
|
+
requestId: string
|
|
2899
|
+
code?: string
|
|
2900
|
+
message?: string
|
|
2901
|
+
}
|
|
2902
|
+
|
|
2903
|
+
interface IRunCommandsReq {
|
|
2904
|
+
/** 命令对象数组 */
|
|
2905
|
+
commands: Object[]
|
|
2906
|
+
/** 事务 ID(可选) */
|
|
2907
|
+
transactionId?: string
|
|
2908
|
+
}
|
|
2909
|
+
|
|
2910
|
+
interface IRunCommandsResult {
|
|
2911
|
+
requestId: string
|
|
2912
|
+
/** 命令执行结果数组 */
|
|
2913
|
+
list: Object[][]
|
|
1979
2914
|
code?: string
|
|
1980
2915
|
message?: string
|
|
1981
2916
|
}
|
|
1982
2917
|
|
|
2918
|
+
/**
|
|
2919
|
+
* 数据库配置
|
|
2920
|
+
*/
|
|
2921
|
+
interface IDbConfig {
|
|
2922
|
+
/** 实例 ID(可选),不填则使用默认实例 */
|
|
2923
|
+
instance?: string
|
|
2924
|
+
/** 数据库名称(可选),不填则使用默认数据库 */
|
|
2925
|
+
database?: string
|
|
2926
|
+
}
|
|
2927
|
+
|
|
2928
|
+
/**
|
|
2929
|
+
* 聚合操作对象
|
|
2930
|
+
*/
|
|
2931
|
+
interface IAggregate {
|
|
2932
|
+
/**
|
|
2933
|
+
* 添加新字段
|
|
2934
|
+
*/
|
|
2935
|
+
addFields(fieldObj: Object): IAggregate
|
|
2936
|
+
/**
|
|
2937
|
+
* 分桶
|
|
2938
|
+
*/
|
|
2939
|
+
bucket(bucketObj: Object): IAggregate
|
|
2940
|
+
/**
|
|
2941
|
+
* 自动分桶
|
|
2942
|
+
*/
|
|
2943
|
+
bucketAuto(bucketObj: Object): IAggregate
|
|
2944
|
+
/**
|
|
2945
|
+
* 计数
|
|
2946
|
+
*/
|
|
2947
|
+
count(fieldName: string): IAggregate
|
|
2948
|
+
/**
|
|
2949
|
+
* 地理位置附近查询
|
|
2950
|
+
*/
|
|
2951
|
+
geoNear(options: Object): IAggregate
|
|
2952
|
+
/**
|
|
2953
|
+
* 分组统计
|
|
2954
|
+
*
|
|
2955
|
+
* @example
|
|
2956
|
+
* db.collection('todos').aggregate()
|
|
2957
|
+
* .group({ _id: '$priority', count: { $sum: 1 } })
|
|
2958
|
+
* .end()
|
|
2959
|
+
*/
|
|
2960
|
+
group(groupObj: Object): IAggregate
|
|
2961
|
+
/**
|
|
2962
|
+
* 限制结果数量
|
|
2963
|
+
*/
|
|
2964
|
+
limit(limit: number): IAggregate
|
|
2965
|
+
/**
|
|
2966
|
+
* 联表查询
|
|
2967
|
+
*/
|
|
2968
|
+
lookup(lookupObj: Object): IAggregate
|
|
2969
|
+
/**
|
|
2970
|
+
* 条件筛选
|
|
2971
|
+
*/
|
|
2972
|
+
match(matchObj: Object): IAggregate
|
|
2973
|
+
/**
|
|
2974
|
+
* 字段投影
|
|
2975
|
+
*/
|
|
2976
|
+
project(projectObj: Object): IAggregate
|
|
2977
|
+
/**
|
|
2978
|
+
* 替换根文档
|
|
2979
|
+
*/
|
|
2980
|
+
replaceRoot(replaceObj: Object): IAggregate
|
|
2981
|
+
/**
|
|
2982
|
+
* 随机采样
|
|
2983
|
+
*/
|
|
2984
|
+
sample(sampleObj: Object): IAggregate
|
|
2985
|
+
/**
|
|
2986
|
+
* 跳过数量
|
|
2987
|
+
*/
|
|
2988
|
+
skip(skip: number): IAggregate
|
|
2989
|
+
/**
|
|
2990
|
+
* 排序
|
|
2991
|
+
*/
|
|
2992
|
+
sort(sortObj: Object): IAggregate
|
|
2993
|
+
/**
|
|
2994
|
+
* 按数量排序
|
|
2995
|
+
*/
|
|
2996
|
+
sortByCount(fieldName: string): IAggregate
|
|
2997
|
+
/**
|
|
2998
|
+
* 展开数组
|
|
2999
|
+
*/
|
|
3000
|
+
unwind(fieldPath: string | Object): IAggregate
|
|
3001
|
+
/**
|
|
3002
|
+
* 结束聚合管道,返回结果
|
|
3003
|
+
*/
|
|
3004
|
+
end(): Promise<GetRes>
|
|
3005
|
+
}
|
|
3006
|
+
|
|
3007
|
+
/**
|
|
3008
|
+
* 事务对象
|
|
3009
|
+
*/
|
|
3010
|
+
interface ITransaction {
|
|
3011
|
+
/**
|
|
3012
|
+
* 获取事务内的集合引用
|
|
3013
|
+
*/
|
|
3014
|
+
collection(name: string): ITransactionCollection
|
|
3015
|
+
/**
|
|
3016
|
+
* 提交事务
|
|
3017
|
+
*/
|
|
3018
|
+
commit(): Promise<void>
|
|
3019
|
+
/**
|
|
3020
|
+
* 回滚事务
|
|
3021
|
+
*
|
|
3022
|
+
* @param reason 回滚原因
|
|
3023
|
+
*/
|
|
3024
|
+
rollback(reason?: any): Promise<void>
|
|
3025
|
+
}
|
|
3026
|
+
|
|
3027
|
+
/**
|
|
3028
|
+
* 事务内的集合引用
|
|
3029
|
+
*/
|
|
3030
|
+
interface ITransactionCollection {
|
|
3031
|
+
doc(id: string): ITransactionDocument
|
|
3032
|
+
}
|
|
3033
|
+
|
|
3034
|
+
/**
|
|
3035
|
+
* 事务内的文档引用
|
|
3036
|
+
*/
|
|
3037
|
+
interface ITransactionDocument {
|
|
3038
|
+
get(): Promise<GetRes>
|
|
3039
|
+
create(data: Object): Promise<any>
|
|
3040
|
+
set(data: Object): Promise<SetRes>
|
|
3041
|
+
update(data: Object): Promise<UpdateRes>
|
|
3042
|
+
remove(): Promise<RemoveRes>
|
|
3043
|
+
}
|
|
3044
|
+
|
|
1983
3045
|
interface QueryOrder {
|
|
1984
3046
|
field?: string
|
|
1985
3047
|
direction?: 'asc' | 'desc'
|
|
@@ -1997,7 +3059,7 @@ declare namespace cloudbase.database {
|
|
|
1997
3059
|
/**
|
|
1998
3060
|
* 获取数据库查询结果
|
|
1999
3061
|
*
|
|
2000
|
-
* {@link https://docs.cloudbase.net/api-reference/webv3/database.html#get}
|
|
3062
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database.html#get}
|
|
2001
3063
|
*
|
|
2002
3064
|
* @example
|
|
2003
3065
|
* collection
|
|
@@ -2013,7 +3075,7 @@ declare namespace cloudbase.database {
|
|
|
2013
3075
|
/**
|
|
2014
3076
|
* 更新数据库文档
|
|
2015
3077
|
*
|
|
2016
|
-
* {@link https://docs.cloudbase.net/api-reference/webv3/database.html#update-set}
|
|
3078
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database.html#update-set}
|
|
2017
3079
|
*
|
|
2018
3080
|
* @example
|
|
2019
3081
|
* collection
|
|
@@ -2031,7 +3093,7 @@ declare namespace cloudbase.database {
|
|
|
2031
3093
|
/**
|
|
2032
3094
|
* 获取数据库查询结果的数目
|
|
2033
3095
|
*
|
|
2034
|
-
* {@link https://docs.cloudbase.net/api-reference/webv3/database#count}
|
|
3096
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database#count}
|
|
2035
3097
|
*
|
|
2036
3098
|
* @example
|
|
2037
3099
|
* collection
|
|
@@ -2041,13 +3103,13 @@ declare namespace cloudbase.database {
|
|
|
2041
3103
|
* .count()
|
|
2042
3104
|
* .then(res=>{})
|
|
2043
3105
|
*
|
|
2044
|
-
* @return Promise
|
|
3106
|
+
* @return Promise<CountRes> 包含 total 字段
|
|
2045
3107
|
*/
|
|
2046
|
-
count(): Promise<
|
|
3108
|
+
count(): Promise<CountRes>
|
|
2047
3109
|
/**
|
|
2048
3110
|
* 设置过滤条件
|
|
2049
3111
|
*
|
|
2050
|
-
* {@link https://docs.cloudbase.net/api-reference/webv3/database#where}
|
|
3112
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database#where}
|
|
2051
3113
|
*
|
|
2052
3114
|
* @example
|
|
2053
3115
|
* collection
|
|
@@ -2062,7 +3124,7 @@ declare namespace cloudbase.database {
|
|
|
2062
3124
|
/**
|
|
2063
3125
|
* 指定查询结果集数量上限
|
|
2064
3126
|
*
|
|
2065
|
-
* {@link https://docs.cloudbase.net/api-reference/webv3/database#limit}
|
|
3127
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database#limit}
|
|
2066
3128
|
*
|
|
2067
3129
|
* @example
|
|
2068
3130
|
* collection
|
|
@@ -2077,7 +3139,7 @@ declare namespace cloudbase.database {
|
|
|
2077
3139
|
/**
|
|
2078
3140
|
* 指定查询返回结果时从指定序列后的结果开始返回,常用于分页
|
|
2079
3141
|
*
|
|
2080
|
-
* {@link https://docs.cloudbase.net/api-reference/webv3/database#skip}
|
|
3142
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database#skip}
|
|
2081
3143
|
*
|
|
2082
3144
|
* @example
|
|
2083
3145
|
* collection
|
|
@@ -2092,7 +3154,7 @@ declare namespace cloudbase.database {
|
|
|
2092
3154
|
/**
|
|
2093
3155
|
* 指定查询排序条件
|
|
2094
3156
|
*
|
|
2095
|
-
* {@link https://docs.cloudbase.net/api-reference/webv3/database#orderby}
|
|
3157
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database#orderby}
|
|
2096
3158
|
*
|
|
2097
3159
|
* @example
|
|
2098
3160
|
* collection
|
|
@@ -2108,7 +3170,7 @@ declare namespace cloudbase.database {
|
|
|
2108
3170
|
/**
|
|
2109
3171
|
* 指定返回结果中文档需返回的字段
|
|
2110
3172
|
*
|
|
2111
|
-
* {@link https://docs.cloudbase.net/api-reference/webv3/database#field}
|
|
3173
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database#field}
|
|
2112
3174
|
*
|
|
2113
3175
|
* @example
|
|
2114
3176
|
* collection
|
|
@@ -2123,7 +3185,7 @@ declare namespace cloudbase.database {
|
|
|
2123
3185
|
/**
|
|
2124
3186
|
* 删除查询到的结果
|
|
2125
3187
|
*
|
|
2126
|
-
* {@link https://docs.cloudbase.net/api-reference/webv3/database#remove-1}
|
|
3188
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database#remove-1}
|
|
2127
3189
|
*
|
|
2128
3190
|
* @example
|
|
2129
3191
|
* collection
|
|
@@ -2132,9 +3194,9 @@ declare namespace cloudbase.database {
|
|
|
2132
3194
|
* })
|
|
2133
3195
|
* .remove()
|
|
2134
3196
|
*
|
|
2135
|
-
* @return Promise
|
|
3197
|
+
* @return Promise<RemoveRes> 包含 deleted 字段
|
|
2136
3198
|
*/
|
|
2137
|
-
remove(): Promise<
|
|
3199
|
+
remove(): Promise<RemoveRes>
|
|
2138
3200
|
}
|
|
2139
3201
|
/**
|
|
2140
3202
|
* geo types
|
|
@@ -2149,7 +3211,7 @@ declare namespace cloudbase.database {
|
|
|
2149
3211
|
/**
|
|
2150
3212
|
* 用于表示地理位置点
|
|
2151
3213
|
*
|
|
2152
|
-
* {@link https://docs.cloudbase.net/api-reference/webv3/database#point}
|
|
3214
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database#point}
|
|
2153
3215
|
*
|
|
2154
3216
|
* @example
|
|
2155
3217
|
* const point = new db.Geo.Point(lng,lat);
|
|
@@ -2165,7 +3227,7 @@ declare namespace cloudbase.database {
|
|
|
2165
3227
|
/**
|
|
2166
3228
|
* 用于表示地理路径,是由两个或者更多的 Point 组成的线段
|
|
2167
3229
|
*
|
|
2168
|
-
* {@link https://docs.cloudbase.net/api-reference/webv3/database#linestring}
|
|
3230
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database#linestring}
|
|
2169
3231
|
*
|
|
2170
3232
|
* @example
|
|
2171
3233
|
* const point = new db.Geo.LineString([pointA,pointB]);
|
|
@@ -2180,7 +3242,7 @@ declare namespace cloudbase.database {
|
|
|
2180
3242
|
/**
|
|
2181
3243
|
* 用于表示地理上的一个多边形
|
|
2182
3244
|
*
|
|
2183
|
-
* {@link https://docs.cloudbase.net/api-reference/webv3/database#polygon}
|
|
3245
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database#polygon}
|
|
2184
3246
|
*
|
|
2185
3247
|
* @example
|
|
2186
3248
|
* const point = new db.Geo.Polygon([lineStringA,lineStringB]);
|
|
@@ -2195,7 +3257,7 @@ declare namespace cloudbase.database {
|
|
|
2195
3257
|
/**
|
|
2196
3258
|
* 用于表示多个点 Point 的集合
|
|
2197
3259
|
*
|
|
2198
|
-
* {@link https://docs.cloudbase.net/api-reference/webv3/database#multipoint}
|
|
3260
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database#multipoint}
|
|
2199
3261
|
*
|
|
2200
3262
|
* @example
|
|
2201
3263
|
* const point = new db.Geo.MultiPoint([pointA,pointB]);
|
|
@@ -2210,7 +3272,7 @@ declare namespace cloudbase.database {
|
|
|
2210
3272
|
/**
|
|
2211
3273
|
* 用于表示多个地理路径 LineString 的集合
|
|
2212
3274
|
*
|
|
2213
|
-
* {@link https://docs.cloudbase.net/api-reference/webv3/database#multilinestring}
|
|
3275
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database#multilinestring}
|
|
2214
3276
|
*
|
|
2215
3277
|
* @example
|
|
2216
3278
|
* const point = new db.Geo.MultiLineString([lineA,lineB]);
|
|
@@ -2225,7 +3287,7 @@ declare namespace cloudbase.database {
|
|
|
2225
3287
|
/**
|
|
2226
3288
|
* 用于表示多个地理多边形 Polygon 的集合
|
|
2227
3289
|
*
|
|
2228
|
-
* {@link https://docs.cloudbase.net/api-reference/webv3/database#multipolygon}
|
|
3290
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database#multipolygon}
|
|
2229
3291
|
*
|
|
2230
3292
|
* @example
|
|
2231
3293
|
* const point = new db.Geo.MultiPolygon([polygonA,polygonB]);
|
|
@@ -2255,19 +3317,19 @@ declare namespace cloudbase.database {
|
|
|
2255
3317
|
/**
|
|
2256
3318
|
* 数据库指令
|
|
2257
3319
|
*
|
|
2258
|
-
* {@link https://docs.cloudbase.net/api-reference/webv3/database#%E6%9F%A5%E8%AF%A2%E6%8C%87%E4%BB%A4}
|
|
3320
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database#%E6%9F%A5%E8%AF%A2%E6%8C%87%E4%BB%A4}
|
|
2259
3321
|
*/
|
|
2260
3322
|
command: ICommand
|
|
2261
3323
|
/**
|
|
2262
3324
|
* 数据库Geo地理位置
|
|
2263
3325
|
*
|
|
2264
|
-
* {@link https://docs.cloudbase.net/api-reference/webv3/database.html#geo-shu-ju-lei-xing}
|
|
3326
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database.html#geo-shu-ju-lei-xing}
|
|
2265
3327
|
*/
|
|
2266
3328
|
Geo: IGeo
|
|
2267
3329
|
/**
|
|
2268
3330
|
* 根据正则表达式进行筛选
|
|
2269
3331
|
*
|
|
2270
|
-
* {@link https://docs.cloudbase.net/api-reference/webv3/database.html#regexp}
|
|
3332
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database.html#regexp}
|
|
2271
3333
|
*
|
|
2272
3334
|
* @example
|
|
2273
3335
|
* db.collection('articles').where({
|
|
@@ -2285,7 +3347,7 @@ declare namespace cloudbase.database {
|
|
|
2285
3347
|
/**
|
|
2286
3348
|
* 创建集合的引用
|
|
2287
3349
|
*
|
|
2288
|
-
* {@link https://docs.cloudbase.net/api-reference/webv3/database.html#collection}
|
|
3350
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database.html#collection}
|
|
2289
3351
|
*
|
|
2290
3352
|
* @example
|
|
2291
3353
|
* const coll = db.collection('demo');
|
|
@@ -2295,8 +3357,93 @@ declare namespace cloudbase.database {
|
|
|
2295
3357
|
* @return 集合的引用
|
|
2296
3358
|
*/
|
|
2297
3359
|
collection(name: string): ICollection
|
|
3360
|
+
/**
|
|
3361
|
+
* 创建集合
|
|
3362
|
+
*
|
|
3363
|
+
* **⚠️ 权限说明**:此方法通常需要管理员权限,客户端 SDK(Web/小程序)在默认安全规则下
|
|
3364
|
+
* 可能无权限调用此方法。如果调用失败,请通过以下方式创建集合:
|
|
3365
|
+
* 1. 登录[腾讯云开发控制台](https://console.cloud.tencent.com/tcb/database)手动创建
|
|
3366
|
+
* 2. 在云函数中使用管理端 SDK 创建
|
|
3367
|
+
* 3. 使用 CLI 工具创建:`tcb service:collection-create <collName>`
|
|
3368
|
+
*
|
|
3369
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database#createcollection}
|
|
3370
|
+
*
|
|
3371
|
+
* @example
|
|
3372
|
+
* ```javascript
|
|
3373
|
+
* // 管理端 SDK 或具有管理员权限时可用
|
|
3374
|
+
* const result = await db.createCollection('new-collection')
|
|
3375
|
+
* ```
|
|
3376
|
+
*
|
|
3377
|
+
* @param collName 集合名称
|
|
3378
|
+
*
|
|
3379
|
+
* @return Promise<CreateCollectionRes>
|
|
3380
|
+
*/
|
|
3381
|
+
createCollection(collName: string): Promise<CreateCollectionRes>
|
|
3382
|
+
/**
|
|
3383
|
+
* 构造服务端时间对象
|
|
3384
|
+
*
|
|
3385
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database#serverdate}
|
|
3386
|
+
*
|
|
3387
|
+
* @example
|
|
3388
|
+
* db.collection('todos').add({
|
|
3389
|
+
* createdAt: db.serverDate()
|
|
3390
|
+
* })
|
|
3391
|
+
*
|
|
3392
|
+
* @param options 可选配置,支持 offset(毫秒偏移量)
|
|
3393
|
+
*
|
|
3394
|
+
* @return 服务端时间对象
|
|
3395
|
+
*/
|
|
3396
|
+
serverDate(options?: { offset?: number }): any
|
|
3397
|
+
/**
|
|
3398
|
+
* 开启一个新事务
|
|
3399
|
+
*
|
|
3400
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database#starttransaction}
|
|
3401
|
+
*
|
|
3402
|
+
* @example
|
|
3403
|
+
* const transaction = await db.startTransaction()
|
|
3404
|
+
* // ... 事务操作
|
|
3405
|
+
* await transaction.commit()
|
|
3406
|
+
*
|
|
3407
|
+
* @return Promise<ITransaction> 事务对象
|
|
3408
|
+
*/
|
|
3409
|
+
startTransaction(): Promise<ITransaction>
|
|
3410
|
+
/**
|
|
3411
|
+
* 执行事务操作,自动处理提交和回滚
|
|
3412
|
+
*
|
|
3413
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database#runtransaction}
|
|
3414
|
+
*
|
|
3415
|
+
* @example
|
|
3416
|
+
* const result = await db.runTransaction(async (transaction) => {
|
|
3417
|
+
* const doc = await transaction.collection('accounts').doc('id').get()
|
|
3418
|
+
* await transaction.collection('accounts').doc('id').update({ balance: doc.data.balance - 100 })
|
|
3419
|
+
* return { success: true }
|
|
3420
|
+
* })
|
|
3421
|
+
*
|
|
3422
|
+
* @param callback 事务回调函数
|
|
3423
|
+
* @param times 事务冲突时的重试次数,默认为 3
|
|
3424
|
+
*
|
|
3425
|
+
* @return Promise<any> 事务回调函数的返回值
|
|
3426
|
+
*/
|
|
3427
|
+
runTransaction(callback: (transaction: ITransaction) => Promise<any>, times?: number): Promise<any>
|
|
3428
|
+
/**
|
|
3429
|
+
* 执行 MongoDB 原生命令
|
|
3430
|
+
*
|
|
3431
|
+
* {@link https://docs.cloudbase.net/api-reference/webv3-next/database#runcommands}
|
|
3432
|
+
*
|
|
3433
|
+
* @example
|
|
3434
|
+
* const result = await db.runCommands({
|
|
3435
|
+
* commands: [
|
|
3436
|
+
* { find: 'users', filter: { age: { $gte: 18 } }, limit: 10 }
|
|
3437
|
+
* ]
|
|
3438
|
+
* })
|
|
3439
|
+
*
|
|
3440
|
+
* @param params 命令参数,包含 commands 数组和可选的 transactionId
|
|
3441
|
+
*
|
|
3442
|
+
* @return Promise<IRunCommandsResult>
|
|
3443
|
+
*/
|
|
3444
|
+
runCommands(params: IRunCommandsReq): Promise<IRunCommandsResult>
|
|
2298
3445
|
}
|
|
2299
3446
|
}
|
|
2300
3447
|
|
|
2301
|
-
export
|
|
3448
|
+
export = cloudbase
|
|
2302
3449
|
export as namespace cloudbase
|