@spcsn/taro 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -0
- package/dist/index.js +147 -0
- package/dist/index.js.map +1 -0
- package/index.js +9 -0
- package/package.json +86 -0
- package/types/api/ad/index.d.ts +197 -0
- package/types/api/ai/face.d.ts +133 -0
- package/types/api/ai/inference.d.ts +129 -0
- package/types/api/ai/visionkit.d.ts +874 -0
- package/types/api/alipay/index.d.ts +69 -0
- package/types/api/base/crypto.d.ts +104 -0
- package/types/api/base/debug.d.ts +329 -0
- package/types/api/base/env.d.ts +19 -0
- package/types/api/base/index.d.ts +102 -0
- package/types/api/base/performance.d.ts +258 -0
- package/types/api/base/system.d.ts +742 -0
- package/types/api/base/update.d.ts +130 -0
- package/types/api/base/weapp/app-event.d.ts +265 -0
- package/types/api/base/weapp/life-cycle.d.ts +155 -0
- package/types/api/canvas/index.d.ts +2162 -0
- package/types/api/cloud/index.d.ts +2622 -0
- package/types/api/data-analysis/index.d.ts +122 -0
- package/types/api/device/accelerometer.d.ts +102 -0
- package/types/api/device/accessibility.d.ts +26 -0
- package/types/api/device/battery.d.ts +46 -0
- package/types/api/device/bluetooth-ble.d.ts +601 -0
- package/types/api/device/bluetooth-peripheral.d.ts +430 -0
- package/types/api/device/bluetooth.d.ts +463 -0
- package/types/api/device/calendar.d.ts +98 -0
- package/types/api/device/clipboard.d.ts +81 -0
- package/types/api/device/compass.d.ts +105 -0
- package/types/api/device/contact.d.ts +110 -0
- package/types/api/device/gyroscope.d.ts +85 -0
- package/types/api/device/iBeacon.d.ts +168 -0
- package/types/api/device/keyboard.d.ts +97 -0
- package/types/api/device/memory.d.ts +52 -0
- package/types/api/device/motion.d.ts +88 -0
- package/types/api/device/network.d.ts +172 -0
- package/types/api/device/nfc.d.ts +1238 -0
- package/types/api/device/phone.d.ts +30 -0
- package/types/api/device/scan.d.ts +111 -0
- package/types/api/device/screen.d.ts +217 -0
- package/types/api/device/sms.d.ts +26 -0
- package/types/api/device/vibrate.d.ts +51 -0
- package/types/api/device/wifi.d.ts +301 -0
- package/types/api/ext/index.d.ts +64 -0
- package/types/api/files/index.d.ts +1472 -0
- package/types/api/framework/index.d.ts +51 -0
- package/types/api/location/index.d.ts +517 -0
- package/types/api/media/audio.d.ts +1013 -0
- package/types/api/media/background-audio.d.ts +291 -0
- package/types/api/media/camera.d.ts +207 -0
- package/types/api/media/editor.d.ts +239 -0
- package/types/api/media/image.d.ts +469 -0
- package/types/api/media/live.d.ts +461 -0
- package/types/api/media/map.d.ts +638 -0
- package/types/api/media/media-recorder.d.ts +117 -0
- package/types/api/media/recorder.d.ts +317 -0
- package/types/api/media/video-decoder.d.ts +117 -0
- package/types/api/media/video-processing.d.ts +84 -0
- package/types/api/media/video.d.ts +527 -0
- package/types/api/media/voip.d.ts +393 -0
- package/types/api/navigate/index.d.ts +327 -0
- package/types/api/network/download.d.ts +173 -0
- package/types/api/network/mdns.d.ts +191 -0
- package/types/api/network/request.d.ts +480 -0
- package/types/api/network/tcp.d.ts +181 -0
- package/types/api/network/udp.d.ts +218 -0
- package/types/api/network/upload.d.ts +201 -0
- package/types/api/network/websocket.d.ts +383 -0
- package/types/api/open-api/account.d.ts +51 -0
- package/types/api/open-api/address.d.ts +68 -0
- package/types/api/open-api/authorize.d.ts +80 -0
- package/types/api/open-api/card.d.ts +110 -0
- package/types/api/open-api/channels.d.ts +225 -0
- package/types/api/open-api/customer-service.d.ts +45 -0
- package/types/api/open-api/device-voip.d.ts +103 -0
- package/types/api/open-api/facial.d.ts +98 -0
- package/types/api/open-api/favorites.d.ts +101 -0
- package/types/api/open-api/group.d.ts +59 -0
- package/types/api/open-api/invoice.d.ts +87 -0
- package/types/api/open-api/license-plate.d.ts +27 -0
- package/types/api/open-api/login.d.ts +115 -0
- package/types/api/open-api/my-miniprogram.d.ts +28 -0
- package/types/api/open-api/privacy.d.ts +107 -0
- package/types/api/open-api/redpackage.d.ts +24 -0
- package/types/api/open-api/settings.d.ts +174 -0
- package/types/api/open-api/soter.d.ts +184 -0
- package/types/api/open-api/sticker.d.ts +83 -0
- package/types/api/open-api/subscribe-message.d.ts +305 -0
- package/types/api/open-api/user-info.d.ts +182 -0
- package/types/api/open-api/werun.d.ts +101 -0
- package/types/api/payment/index.d.ts +119 -0
- package/types/api/qq/index.d.ts +354 -0
- package/types/api/route/index.d.ts +324 -0
- package/types/api/share/index.d.ts +354 -0
- package/types/api/skyline/index.d.ts +345 -0
- package/types/api/storage/background-fetch.d.ts +131 -0
- package/types/api/storage/cache-manager.d.ts +249 -0
- package/types/api/storage/index.d.ts +405 -0
- package/types/api/swan/bookshelf.d.ts +307 -0
- package/types/api/swan/download-package.d.ts +80 -0
- package/types/api/swan/index.d.ts +251 -0
- package/types/api/swan/pay.d.ts +139 -0
- package/types/api/taro.extend.d.ts +233 -0
- package/types/api/taro.hooks.d.ts +148 -0
- package/types/api/ui/animation.d.ts +427 -0
- package/types/api/ui/background.d.ts +69 -0
- package/types/api/ui/custom-component.d.ts +23 -0
- package/types/api/ui/fonts.d.ts +77 -0
- package/types/api/ui/interaction.d.ts +281 -0
- package/types/api/ui/menu.d.ts +29 -0
- package/types/api/ui/navigation-bar.d.ts +130 -0
- package/types/api/ui/pull-down-refresh.d.ts +50 -0
- package/types/api/ui/scroll.d.ts +114 -0
- package/types/api/ui/sticky.d.ts +32 -0
- package/types/api/ui/tab-bar.d.ts +196 -0
- package/types/api/ui/window.d.ts +71 -0
- package/types/api/worker/index.d.ts +83 -0
- package/types/api/wxml/index.d.ts +540 -0
- package/types/compile/compiler.d.ts +32 -0
- package/types/compile/config/h5.d.ts +134 -0
- package/types/compile/config/harmony.d.ts +118 -0
- package/types/compile/config/index.d.ts +8 -0
- package/types/compile/config/manifest.d.ts +155 -0
- package/types/compile/config/mini.d.ts +118 -0
- package/types/compile/config/plugin.d.ts +34 -0
- package/types/compile/config/project.d.ts +338 -0
- package/types/compile/config/rn.d.ts +85 -0
- package/types/compile/config/util.d.ts +179 -0
- package/types/compile/hooks.d.ts +13 -0
- package/types/compile/index.d.ts +11 -0
- package/types/compile/viteCompilerContext.d.ts +167 -0
- package/types/global.d.ts +428 -0
- package/types/index.d.ts +190 -0
- package/types/taro.api.d.ts +130 -0
- package/types/taro.component.d.ts +168 -0
- package/types/taro.config.d.ts +712 -0
- package/types/taro.lifecycle.d.ts +220 -0
- package/types/taro.runtime.d.ts +9 -0
|
@@ -0,0 +1,2622 @@
|
|
|
1
|
+
import Taro from "../../index"
|
|
2
|
+
|
|
3
|
+
declare module '../../index' {
|
|
4
|
+
namespace cloud {
|
|
5
|
+
/** 云函数通用返回 */
|
|
6
|
+
interface CallFunctionResult extends TaroGeneral.CallbackResult {
|
|
7
|
+
/** 云函数返回的结果 */
|
|
8
|
+
result: TaroGeneral.IAnyObject | string | undefined
|
|
9
|
+
/** 调用结果 */
|
|
10
|
+
errMsg: string
|
|
11
|
+
}
|
|
12
|
+
/** 云函数通用参数 */
|
|
13
|
+
interface IApiParam<T = any> {
|
|
14
|
+
/** 配置 */
|
|
15
|
+
config?: IConfig
|
|
16
|
+
/** 接口调用成功的回调函数 */
|
|
17
|
+
success?: (res: T) => void
|
|
18
|
+
/** 接口调用失败的回调函数 */
|
|
19
|
+
fail?: (err: TaroGeneral.CallbackResult) => void
|
|
20
|
+
/** 接口调用结束的回调函数(调用成功、失败都会执行) */
|
|
21
|
+
complete?: (val: T | TaroGeneral.CallbackResult) => void
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// type IApiFunction<T, P extends IApiParam<T>> = (param?: P) => Promise<T>
|
|
25
|
+
|
|
26
|
+
/** 初始化配置 */
|
|
27
|
+
interface IInitConfig {
|
|
28
|
+
/** 默认环境配置,传入字符串形式的环境 ID 可以指定所有服务的默认环境,传入对象可以分别指定各个服务的默认环境 */
|
|
29
|
+
env?:
|
|
30
|
+
| string
|
|
31
|
+
| {
|
|
32
|
+
/** 数据库 API 默认环境配置 */
|
|
33
|
+
database?: string
|
|
34
|
+
/** 存储 API 默认环境配置 */
|
|
35
|
+
functions?: string
|
|
36
|
+
/** 云函数 API 默认环境配置 */
|
|
37
|
+
storage?: string,
|
|
38
|
+
}
|
|
39
|
+
/** 是否在将用户访问记录到用户管理中,在控制台中可见 */
|
|
40
|
+
traceUser?: boolean
|
|
41
|
+
}
|
|
42
|
+
/** 配置 */
|
|
43
|
+
interface IConfig {
|
|
44
|
+
/** 使用的环境 ID,填写后忽略 init 指定的环境 */
|
|
45
|
+
env?: string
|
|
46
|
+
/** 是否在将用户访问记录到用户管理中,在控制台中可见 */
|
|
47
|
+
traceUser?: boolean
|
|
48
|
+
}
|
|
49
|
+
/** 云函数 API 通用参数 */
|
|
50
|
+
interface ICloudAPIParam<T = any> extends IApiParam<T> {
|
|
51
|
+
/** 配置 */
|
|
52
|
+
config?: IConfig
|
|
53
|
+
}
|
|
54
|
+
// interface IICloudAPI {
|
|
55
|
+
// init: (config?: cloud.IInitConfig) => void
|
|
56
|
+
// [api: string]: (...args: any[]) => any | cloud.IApiFunction<any, any>
|
|
57
|
+
// }
|
|
58
|
+
// interface ICloudService {
|
|
59
|
+
// name: string
|
|
60
|
+
|
|
61
|
+
// getAPIs: () => { [name: string]: cloud.IApiFunction<any, any> }
|
|
62
|
+
// }
|
|
63
|
+
// interface ICloudServices {
|
|
64
|
+
// [serviceName: string]: ICloudService
|
|
65
|
+
// }
|
|
66
|
+
// interface ICloudMetaData {
|
|
67
|
+
// session_id: string
|
|
68
|
+
// }
|
|
69
|
+
|
|
70
|
+
/** 调用云函数参数 */
|
|
71
|
+
interface CallFunctionParam extends ICloudAPIParam<CallFunctionResult> {
|
|
72
|
+
/** 云函数名 */
|
|
73
|
+
name: string
|
|
74
|
+
/** 传递给云函数的参数,在云函数中可通过 event 参数获取 */
|
|
75
|
+
data?: TaroGeneral.IAnyObject
|
|
76
|
+
slow?: boolean
|
|
77
|
+
/** 配置 */
|
|
78
|
+
config?: IConfig
|
|
79
|
+
/** 接口调用结束的回调函数(调用成功、失败都会执行) */
|
|
80
|
+
complete?: (res: CallFunctionResult | TaroGeneral.CallbackResult) => void
|
|
81
|
+
/** 接口调用失败的回调函数 */
|
|
82
|
+
fail?: (res: TaroGeneral.CallbackResult) => void
|
|
83
|
+
/** 接口调用成功的回调函数 */
|
|
84
|
+
success?: (res: CallFunctionResult) => void
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** 上传文件结果 */
|
|
88
|
+
interface UploadFileResult extends TaroGeneral.CallbackResult {
|
|
89
|
+
/** 文件 ID */
|
|
90
|
+
fileID: string
|
|
91
|
+
/** 服务器返回的 HTTP 状态码 */
|
|
92
|
+
statusCode: number
|
|
93
|
+
/** 调用结果 */
|
|
94
|
+
errMsg: string
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** 上传文件参数 */
|
|
98
|
+
interface UploadFileParam extends ICloudAPIParam<UploadFileResult> {
|
|
99
|
+
/** 云存储路径,命名限制见[文件名命名限制](https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/guide/storage/naming.html) */
|
|
100
|
+
cloudPath: string
|
|
101
|
+
/** 要上传文件资源的路径 */
|
|
102
|
+
filePath: string
|
|
103
|
+
header?: TaroGeneral.IAnyObject
|
|
104
|
+
/** 配置 */
|
|
105
|
+
config?: IConfig
|
|
106
|
+
/** 接口调用结束的回调函数(调用成功、失败都会执行) */
|
|
107
|
+
complete?: (res: UploadFileResult | TaroGeneral.CallbackResult) => void
|
|
108
|
+
/** 接口调用失败的回调函数 */
|
|
109
|
+
fail?: (res: TaroGeneral.CallbackResult) => void
|
|
110
|
+
/** 接口调用成功的回调函数 */
|
|
111
|
+
success?: (res: UploadFileResult) => void
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** 下载文件结果 */
|
|
115
|
+
interface DownloadFileResult extends TaroGeneral.CallbackResult {
|
|
116
|
+
/** 临时文件路径 */
|
|
117
|
+
tempFilePath: string
|
|
118
|
+
/** 服务器返回的 HTTP 状态码 */
|
|
119
|
+
statusCode: number
|
|
120
|
+
/** 调用结果 */
|
|
121
|
+
errMsg: string
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** 下载文件参数 */
|
|
125
|
+
interface DownloadFileParam extends ICloudAPIParam<DownloadFileResult> {
|
|
126
|
+
/** 云文件 ID */
|
|
127
|
+
fileID: string
|
|
128
|
+
cloudPath?: string
|
|
129
|
+
/** 配置 */
|
|
130
|
+
config?: IConfig
|
|
131
|
+
/** 接口调用结束的回调函数(调用成功、失败都会执行) */
|
|
132
|
+
complete?: (res: DownloadFileResult | TaroGeneral.CallbackResult) => void
|
|
133
|
+
/** 接口调用失败的回调函数 */
|
|
134
|
+
fail?: (res: TaroGeneral.CallbackResult) => void
|
|
135
|
+
/** 接口调用成功的回调函数 */
|
|
136
|
+
success?: (res: DownloadFileResult) => void
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/** 获取临时文件结果 */
|
|
140
|
+
interface GetTempFileURLResult extends TaroGeneral.CallbackResult {
|
|
141
|
+
/** 文件列表 */
|
|
142
|
+
fileList: GetTempFileURLResultItem[]
|
|
143
|
+
/** 调用结果 */
|
|
144
|
+
errMsg: string
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** 临时文件列表 */
|
|
148
|
+
interface GetTempFileURLResultItem extends TaroGeneral.CallbackResult {
|
|
149
|
+
/** 云文件 ID */
|
|
150
|
+
fileID: string
|
|
151
|
+
/** 临时文件路径 */
|
|
152
|
+
tempFileURL: string
|
|
153
|
+
maxAge: number
|
|
154
|
+
/** 状态码 */
|
|
155
|
+
status: number
|
|
156
|
+
/** 调用结果 */
|
|
157
|
+
errMsg: string
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/** 获取临时文件参数 */
|
|
161
|
+
interface GetTempFileURLParam extends ICloudAPIParam<GetTempFileURLResult> {
|
|
162
|
+
fileList: string[]
|
|
163
|
+
/** 配置 */
|
|
164
|
+
config?: IConfig
|
|
165
|
+
/** 接口调用结束的回调函数(调用成功、失败都会执行) */
|
|
166
|
+
complete?: (res: GetTempFileURLResult | TaroGeneral.CallbackResult) => void
|
|
167
|
+
/** 接口调用失败的回调函数 */
|
|
168
|
+
fail?: (res: TaroGeneral.CallbackResult) => void
|
|
169
|
+
/** 接口调用成功的回调函数 */
|
|
170
|
+
success?: (res: GetTempFileURLResult) => void
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/** 删除文件结果 */
|
|
174
|
+
interface DeleteFileResult extends TaroGeneral.CallbackResult {
|
|
175
|
+
/** 文件列表 */
|
|
176
|
+
fileList: DeleteFileResultItem[]
|
|
177
|
+
/** 调用结果 */
|
|
178
|
+
errMsg: string
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/** 删除文件列表 */
|
|
182
|
+
interface DeleteFileResultItem extends TaroGeneral.CallbackResult {
|
|
183
|
+
/** 云文件 ID */
|
|
184
|
+
fileID: string
|
|
185
|
+
/** 状态码 */
|
|
186
|
+
status: number
|
|
187
|
+
/** 调用结果 */
|
|
188
|
+
errMsg: string
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/** 删除文件参数 */
|
|
192
|
+
interface DeleteFileParam extends ICloudAPIParam<DeleteFileResult> {
|
|
193
|
+
/** 文件列表 */
|
|
194
|
+
fileList: string[]
|
|
195
|
+
/** 配置 */
|
|
196
|
+
config?: IConfig
|
|
197
|
+
/** 接口调用结束的回调函数(调用成功、失败都会执行) */
|
|
198
|
+
complete?: (res: DeleteFileResult | TaroGeneral.CallbackResult) => void
|
|
199
|
+
/** 接口调用失败的回调函数 */
|
|
200
|
+
fail?: (res: TaroGeneral.CallbackResult) => void
|
|
201
|
+
/** 接口调用成功的回调函数 */
|
|
202
|
+
success?: (res: DeleteFileResult) => void
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/** 新建云开发操作实例 */
|
|
206
|
+
interface IOptions {
|
|
207
|
+
/** 资源方 AppID, 不填则表示已登录的当前账号(如小程序中) */
|
|
208
|
+
resourceAppid?: string
|
|
209
|
+
/** 资源方云环境 ID */
|
|
210
|
+
resourceEnv: string
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/** 调用云托管参数 */
|
|
214
|
+
interface CallContainerParam < P extends string | TaroGeneral.IAnyObject | ArrayBuffer = any | any > {
|
|
215
|
+
config?:{
|
|
216
|
+
/** 微信云托管的环境ID, 如果在 Taro.cloud.init 中配置了env, 则可以不配置。 */
|
|
217
|
+
env: string,
|
|
218
|
+
}
|
|
219
|
+
/** 服务路径 */
|
|
220
|
+
path: string
|
|
221
|
+
/** HTTP请求方法,默认 GET */
|
|
222
|
+
method?: keyof request.Method
|
|
223
|
+
/** 请求数据 */
|
|
224
|
+
data?: P
|
|
225
|
+
/** 设置请求的 header,header 中不能设置 Referer。content-type 默认为 application/json */
|
|
226
|
+
header?: TaroGeneral.IAnyObject
|
|
227
|
+
/** 超时时间,单位为毫秒 */
|
|
228
|
+
timeout?: number
|
|
229
|
+
/** 返回的数据格式 */
|
|
230
|
+
dataType?: request.DataType
|
|
231
|
+
/** 响应的数据类型 */
|
|
232
|
+
responseType?: keyof {
|
|
233
|
+
text
|
|
234
|
+
arraybuffer
|
|
235
|
+
}
|
|
236
|
+
/** 接口调用结束的回调函数(调用成功、失败都会执行) */
|
|
237
|
+
complete?: (res: CallFunctionResult | TaroGeneral.CallbackResult) => void
|
|
238
|
+
/** 接口调用失败的回调函数 */
|
|
239
|
+
fail?: (res: TaroGeneral.CallbackResult) => void
|
|
240
|
+
/** 接口调用成功的回调函数 */
|
|
241
|
+
success?: (res: CallFunctionResult) => void
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/** 调用云托管返回值 */
|
|
245
|
+
interface CallContainerResult < R extends string | TaroGeneral.IAnyObject | ArrayBuffer = any | any > {
|
|
246
|
+
/** 开发者云托管服务返回的数据 */
|
|
247
|
+
data: R
|
|
248
|
+
/** 开发者云托管返回的 HTTP Response Header */
|
|
249
|
+
header: TaroGeneral.IAnyObject
|
|
250
|
+
/** 开发者云托管服务返回的 HTTP 状态码 */
|
|
251
|
+
statusCode: number
|
|
252
|
+
/** 开发者云托管返回的 cookies,格式为字符串数组,仅小程序端有此字段 */
|
|
253
|
+
cookies?: TaroGeneral.IAnyObject
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/** 云开发 SDK 实例
|
|
258
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/Cloud.html
|
|
259
|
+
*/
|
|
260
|
+
interface cloud {
|
|
261
|
+
/** 在调用云开发各 API 前,需先调用初始化方法 init 一次(全局只需一次,多次调用时只有第一次生效)
|
|
262
|
+
* @supported weapp
|
|
263
|
+
* @example
|
|
264
|
+
* ```tsx
|
|
265
|
+
* Taro.cloud.init({
|
|
266
|
+
* env: 'test-x1dzi'
|
|
267
|
+
* })
|
|
268
|
+
* ```
|
|
269
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/init/client.init.html
|
|
270
|
+
*/
|
|
271
|
+
init(config?: cloud.IInitConfig): void
|
|
272
|
+
|
|
273
|
+
/** 声明字符串为 CloudID(开放数据 ID),该接口传入一个字符串,返回一个 CloudID 特殊对象,将该对象传至云函数可以获取其对应的开放数据。
|
|
274
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/open/Cloud.CloudID.html
|
|
275
|
+
*/
|
|
276
|
+
CloudID(cloudID: string): void
|
|
277
|
+
|
|
278
|
+
/** 调用云函数
|
|
279
|
+
* @supported weapp
|
|
280
|
+
* @example
|
|
281
|
+
* 假设已有一个云函数 add,在小程序端发起对云函数 add 的调用:
|
|
282
|
+
*
|
|
283
|
+
* ```tsx
|
|
284
|
+
* Taro.cloud.callFunction({
|
|
285
|
+
* // 要调用的云函数名称
|
|
286
|
+
* name: 'add',
|
|
287
|
+
* // 传递给云函数的event参数
|
|
288
|
+
* data: {
|
|
289
|
+
* x: 1,
|
|
290
|
+
* y: 2,
|
|
291
|
+
* }
|
|
292
|
+
* }).then(res => {
|
|
293
|
+
* // output: res.result === 3
|
|
294
|
+
* }).catch(err => {
|
|
295
|
+
* // handle error
|
|
296
|
+
* })
|
|
297
|
+
* ```
|
|
298
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/functions/Cloud.callFunction.html
|
|
299
|
+
*/
|
|
300
|
+
callFunction(param: OQ<cloud.CallFunctionParam>): void
|
|
301
|
+
callFunction(param: RQ<cloud.CallFunctionParam>): Promise<cloud.CallFunctionResult>
|
|
302
|
+
|
|
303
|
+
/** 将本地资源上传至云存储空间,如果上传至同一路径则是覆盖写
|
|
304
|
+
* @supported weapp
|
|
305
|
+
* @example
|
|
306
|
+
* ```tsx
|
|
307
|
+
* Taro.cloud.uploadFile({
|
|
308
|
+
* cloudPath: 'example.png',
|
|
309
|
+
* filePath: '', // 文件路径
|
|
310
|
+
* success: res => {
|
|
311
|
+
* // get resource ID
|
|
312
|
+
* console.log(res.fileID)
|
|
313
|
+
* },
|
|
314
|
+
* fail: err => {
|
|
315
|
+
* // handle error
|
|
316
|
+
* }
|
|
317
|
+
* })
|
|
318
|
+
* ```
|
|
319
|
+
* @example
|
|
320
|
+
* ```tsx
|
|
321
|
+
* Taro.cloud.uploadFile({
|
|
322
|
+
* cloudPath: 'example.png',
|
|
323
|
+
* filePath: '', // 文件路径
|
|
324
|
+
* }).then(res => {
|
|
325
|
+
* // get resource ID
|
|
326
|
+
* console.log(res.fileID)
|
|
327
|
+
* }).catch(error => {
|
|
328
|
+
* // handle error
|
|
329
|
+
* })
|
|
330
|
+
* ```
|
|
331
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/storage/uploadFile/client.uploadFile.html
|
|
332
|
+
*/
|
|
333
|
+
uploadFile(param: OQ<cloud.UploadFileParam>): Taro.UploadTask
|
|
334
|
+
uploadFile(param: RQ<cloud.UploadFileParam>): Promise<cloud.UploadFileResult>
|
|
335
|
+
|
|
336
|
+
/** 从云存储空间下载文件
|
|
337
|
+
* @supported weapp
|
|
338
|
+
* @example
|
|
339
|
+
* ```tsx
|
|
340
|
+
* Taro.cloud.downloadFile({
|
|
341
|
+
* fileID: 'a7xzcb',
|
|
342
|
+
* success: res => {
|
|
343
|
+
* // get temp file path
|
|
344
|
+
* console.log(res.tempFilePath)
|
|
345
|
+
* },
|
|
346
|
+
* fail: err => {
|
|
347
|
+
* // handle error
|
|
348
|
+
* }
|
|
349
|
+
* })
|
|
350
|
+
* ```
|
|
351
|
+
* @example
|
|
352
|
+
* ```tsx
|
|
353
|
+
* Taro.cloud.downloadFile({
|
|
354
|
+
* fileID: 'a7xzcb'
|
|
355
|
+
* }).then(res => {
|
|
356
|
+
* // get temp file path
|
|
357
|
+
* console.log(res.tempFilePath)
|
|
358
|
+
* }).catch(error => {
|
|
359
|
+
* // handle error
|
|
360
|
+
* })
|
|
361
|
+
* ```
|
|
362
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/storage/downloadFile/client.downloadFile.html
|
|
363
|
+
*/
|
|
364
|
+
downloadFile(param: OQ<cloud.DownloadFileParam>): DownloadTask
|
|
365
|
+
downloadFile(param: RQ<cloud.DownloadFileParam>): Promise<cloud.DownloadFileResult>
|
|
366
|
+
|
|
367
|
+
/** 用云文件 ID 换取真实链接,公有读的文件获取的链接不会过期,私有的文件获取的链接十分钟有效期。一次最多取 50 个。
|
|
368
|
+
* @supported weapp
|
|
369
|
+
* @example
|
|
370
|
+
* ```tsx
|
|
371
|
+
* Taro.cloud.getTempFileURL({
|
|
372
|
+
* fileList: [{
|
|
373
|
+
* fileID: 'a7xzcb',
|
|
374
|
+
* maxAge: 60 * 60, // one hour
|
|
375
|
+
* }]
|
|
376
|
+
* }).then(res => {
|
|
377
|
+
* // get temp file URL
|
|
378
|
+
* console.log(res.fileList)
|
|
379
|
+
* }).catch(error => {
|
|
380
|
+
* // handle error
|
|
381
|
+
* })
|
|
382
|
+
* ```
|
|
383
|
+
* @example
|
|
384
|
+
* ```tsx
|
|
385
|
+
* Taro.cloud.getTempFileURL({
|
|
386
|
+
* fileList: ['cloud://xxx', 'cloud://yyy'],
|
|
387
|
+
* success: res => {
|
|
388
|
+
* // get temp file URL
|
|
389
|
+
* console.log(res.fileList)
|
|
390
|
+
* },
|
|
391
|
+
* fail: err => {
|
|
392
|
+
* // handle error
|
|
393
|
+
* }
|
|
394
|
+
* })
|
|
395
|
+
* ```
|
|
396
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/storage/Cloud.getTempFileURL.html
|
|
397
|
+
*/
|
|
398
|
+
getTempFileURL(param: OQ<cloud.GetTempFileURLParam>): void
|
|
399
|
+
getTempFileURL(param: RQ<cloud.GetTempFileURLParam>): Promise<cloud.GetTempFileURLResult>
|
|
400
|
+
|
|
401
|
+
/** 从云存储空间删除文件,一次最多 50 个
|
|
402
|
+
* @supported weapp
|
|
403
|
+
* @example
|
|
404
|
+
* ```tsx
|
|
405
|
+
* .cloud.deleteFile({
|
|
406
|
+
* fileList: ['a7xzcb']
|
|
407
|
+
* }).then(res => {
|
|
408
|
+
* // handle success
|
|
409
|
+
* console.log(res.fileList)
|
|
410
|
+
* }).catch(error => {
|
|
411
|
+
* // handle error
|
|
412
|
+
* })
|
|
413
|
+
* ```
|
|
414
|
+
* @example
|
|
415
|
+
* ```tsx
|
|
416
|
+
* Taro.cloud.deleteFile({
|
|
417
|
+
* fileList: ['a7xzcb'],
|
|
418
|
+
* success: res => {
|
|
419
|
+
* // handle success
|
|
420
|
+
* console.log(res.fileList)
|
|
421
|
+
* },
|
|
422
|
+
* fail: err => {
|
|
423
|
+
* // handle error
|
|
424
|
+
* },
|
|
425
|
+
* complete: res => {
|
|
426
|
+
* // ...
|
|
427
|
+
* }
|
|
428
|
+
* })
|
|
429
|
+
* ```
|
|
430
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/storage/Cloud.deleteFile.html
|
|
431
|
+
*/
|
|
432
|
+
deleteFile(param: OQ<cloud.DeleteFileParam>): void
|
|
433
|
+
deleteFile(param: RQ<cloud.DeleteFileParam>): Promise<cloud.DeleteFileResult>
|
|
434
|
+
|
|
435
|
+
/** 获取数据库实例
|
|
436
|
+
* @supported weapp
|
|
437
|
+
* @example
|
|
438
|
+
* 以下调用获取默认环境的数据库的引用:
|
|
439
|
+
*
|
|
440
|
+
* ```tsx
|
|
441
|
+
* const db = Taro.cloud.database()
|
|
442
|
+
* ```
|
|
443
|
+
* @example
|
|
444
|
+
* 假设有一个环境名为 test-123,用做测试环境,那么可以如下获取测试环境数据库:
|
|
445
|
+
*
|
|
446
|
+
* ```tsx
|
|
447
|
+
* const testDB = Taro.cloud.database({
|
|
448
|
+
* env: 'test-123'
|
|
449
|
+
* })
|
|
450
|
+
* ```
|
|
451
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/Cloud.database.html
|
|
452
|
+
*/
|
|
453
|
+
database(config?: cloud.IConfig): DB.Database
|
|
454
|
+
|
|
455
|
+
/** 声明新的云开发操作实例
|
|
456
|
+
* @supported weapp
|
|
457
|
+
* @example
|
|
458
|
+
* 声明新的操作实例
|
|
459
|
+
*
|
|
460
|
+
* ```tsx
|
|
461
|
+
* const c1 = new Taro.cloud.Cloud({
|
|
462
|
+
* resourceEnv: '我的某个环境ID',
|
|
463
|
+
* })
|
|
464
|
+
* ```
|
|
465
|
+
* @example
|
|
466
|
+
* 资源共享时跨账号访问资源
|
|
467
|
+
*
|
|
468
|
+
* ```tsx
|
|
469
|
+
* // 声明
|
|
470
|
+
* const c1 = new Taro.cloud.Cloud({
|
|
471
|
+
* resourceAppid: '资源方 AppID',
|
|
472
|
+
* resourceEnv: '我的某个环境ID',
|
|
473
|
+
* })
|
|
474
|
+
* // 等待初始化完成
|
|
475
|
+
* await c1.init()
|
|
476
|
+
*
|
|
477
|
+
* // 然后照常访问指定环境下的资源
|
|
478
|
+
* c1.callFunction({
|
|
479
|
+
* name: '',
|
|
480
|
+
* data: {},
|
|
481
|
+
* })
|
|
482
|
+
* ```
|
|
483
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/utils/Cloud.Cloud.html
|
|
484
|
+
*/
|
|
485
|
+
Cloud: new (options: cloud.IOptions) => Cloud
|
|
486
|
+
|
|
487
|
+
/** 调用云托管服务
|
|
488
|
+
* @supported weapp
|
|
489
|
+
* @example
|
|
490
|
+
* 假设已经初始化了一个叫c1的云开发实例,并发起云托管调用
|
|
491
|
+
*
|
|
492
|
+
* ``` tsx
|
|
493
|
+
* const r = await c1.callContainer({
|
|
494
|
+
* path: '/path/to/container', // 填入容器的访问路径
|
|
495
|
+
* method: 'POST',
|
|
496
|
+
* })
|
|
497
|
+
* ```
|
|
498
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/container/Cloud.callContainer.html
|
|
499
|
+
*/
|
|
500
|
+
callContainer < R = any, P = any >(params: cloud.CallContainerParam<P>): Promise<cloud.CallContainerResult<R>>
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
/** @ignore */
|
|
504
|
+
interface Cloud {
|
|
505
|
+
/** 在调用云开发各 API 前,需先调用初始化方法 init 一次(全局只需一次,多次调用时只有第一次生效)
|
|
506
|
+
* @supported weapp
|
|
507
|
+
* @example
|
|
508
|
+
* ```tsx
|
|
509
|
+
* Taro.cloud.init({
|
|
510
|
+
* env: 'test-x1dzi'
|
|
511
|
+
* })
|
|
512
|
+
* ```
|
|
513
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/init/client.init.html
|
|
514
|
+
*/
|
|
515
|
+
init(config?: cloud.IInitConfig): Promise<void>
|
|
516
|
+
|
|
517
|
+
/** 声明字符串为 CloudID(开放数据 ID),该接口传入一个字符串,返回一个 CloudID 特殊对象,将该对象传至云函数可以获取其对应的开放数据。
|
|
518
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/open/Cloud.CloudID.html
|
|
519
|
+
*/
|
|
520
|
+
CloudID(cloudID: string): void
|
|
521
|
+
|
|
522
|
+
/** 调用云函数
|
|
523
|
+
* @supported weapp
|
|
524
|
+
* @example
|
|
525
|
+
* 假设已有一个云函数 add,在小程序端发起对云函数 add 的调用:
|
|
526
|
+
*
|
|
527
|
+
* ```tsx
|
|
528
|
+
* Taro.cloud.callFunction({
|
|
529
|
+
* // 要调用的云函数名称
|
|
530
|
+
* name: 'add',
|
|
531
|
+
* // 传递给云函数的event参数
|
|
532
|
+
* data: {
|
|
533
|
+
* x: 1,
|
|
534
|
+
* y: 2,
|
|
535
|
+
* }
|
|
536
|
+
* }).then(res => {
|
|
537
|
+
* // output: res.result === 3
|
|
538
|
+
* }).catch(err => {
|
|
539
|
+
* // handle error
|
|
540
|
+
* })
|
|
541
|
+
* ```
|
|
542
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/functions/Cloud.callFunction.html
|
|
543
|
+
*/
|
|
544
|
+
callFunction(param: OQ<cloud.CallFunctionParam>): void
|
|
545
|
+
callFunction(param: RQ<cloud.CallFunctionParam>): Promise<cloud.CallFunctionResult>
|
|
546
|
+
|
|
547
|
+
/** 将本地资源上传至云存储空间,如果上传至同一路径则是覆盖写
|
|
548
|
+
* @supported weapp
|
|
549
|
+
* @example
|
|
550
|
+
* ```tsx
|
|
551
|
+
* Taro.cloud.uploadFile({
|
|
552
|
+
* cloudPath: 'example.png',
|
|
553
|
+
* filePath: '', // 文件路径
|
|
554
|
+
* success: res => {
|
|
555
|
+
* // get resource ID
|
|
556
|
+
* console.log(res.fileID)
|
|
557
|
+
* },
|
|
558
|
+
* fail: err => {
|
|
559
|
+
* // handle error
|
|
560
|
+
* }
|
|
561
|
+
* })
|
|
562
|
+
* ```
|
|
563
|
+
* @example
|
|
564
|
+
* ```tsx
|
|
565
|
+
* Taro.cloud.uploadFile({
|
|
566
|
+
* cloudPath: 'example.png',
|
|
567
|
+
* filePath: '', // 文件路径
|
|
568
|
+
* }).then(res => {
|
|
569
|
+
* // get resource ID
|
|
570
|
+
* console.log(res.fileID)
|
|
571
|
+
* }).catch(error => {
|
|
572
|
+
* // handle error
|
|
573
|
+
* })
|
|
574
|
+
* ```
|
|
575
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/storage/uploadFile/client.uploadFile.html
|
|
576
|
+
*/
|
|
577
|
+
uploadFile(param: OQ<cloud.UploadFileParam>): UploadTask
|
|
578
|
+
uploadFile(param: RQ<cloud.UploadFileParam>): Promise<cloud.UploadFileResult>
|
|
579
|
+
|
|
580
|
+
/** 从云存储空间下载文件
|
|
581
|
+
* @supported weapp
|
|
582
|
+
* @example
|
|
583
|
+
* ```tsx
|
|
584
|
+
* Taro.cloud.downloadFile({
|
|
585
|
+
* fileID: 'a7xzcb',
|
|
586
|
+
* success: res => {
|
|
587
|
+
* // get temp file path
|
|
588
|
+
* console.log(res.tempFilePath)
|
|
589
|
+
* },
|
|
590
|
+
* fail: err => {
|
|
591
|
+
* // handle error
|
|
592
|
+
* }
|
|
593
|
+
* })
|
|
594
|
+
* ```
|
|
595
|
+
* @example
|
|
596
|
+
* ```tsx
|
|
597
|
+
* Taro.cloud.downloadFile({
|
|
598
|
+
* fileID: 'a7xzcb'
|
|
599
|
+
* }).then(res => {
|
|
600
|
+
* // get temp file path
|
|
601
|
+
* console.log(res.tempFilePath)
|
|
602
|
+
* }).catch(error => {
|
|
603
|
+
* // handle error
|
|
604
|
+
* })
|
|
605
|
+
* ```
|
|
606
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/storage/downloadFile/client.downloadFile.html
|
|
607
|
+
*/
|
|
608
|
+
downloadFile(param: OQ<cloud.DownloadFileParam>): DownloadTask
|
|
609
|
+
downloadFile(param: RQ<cloud.DownloadFileParam>): Promise<cloud.DownloadFileResult>
|
|
610
|
+
|
|
611
|
+
/** 用云文件 ID 换取真实链接,公有读的文件获取的链接不会过期,私有的文件获取的链接十分钟有效期。一次最多取 50 个。
|
|
612
|
+
* @supported weapp
|
|
613
|
+
* @example
|
|
614
|
+
* ```tsx
|
|
615
|
+
* Taro.cloud.getTempFileURL({
|
|
616
|
+
* fileList: [{
|
|
617
|
+
* fileID: 'a7xzcb',
|
|
618
|
+
* maxAge: 60 * 60, // one hour
|
|
619
|
+
* }]
|
|
620
|
+
* }).then(res => {
|
|
621
|
+
* // get temp file URL
|
|
622
|
+
* console.log(res.fileList)
|
|
623
|
+
* }).catch(error => {
|
|
624
|
+
* // handle error
|
|
625
|
+
* })
|
|
626
|
+
* ```
|
|
627
|
+
* @example
|
|
628
|
+
* ```tsx
|
|
629
|
+
* Taro.cloud.getTempFileURL({
|
|
630
|
+
* fileList: ['cloud://xxx', 'cloud://yyy'],
|
|
631
|
+
* success: res => {
|
|
632
|
+
* // get temp file URL
|
|
633
|
+
* console.log(res.fileList)
|
|
634
|
+
* },
|
|
635
|
+
* fail: err => {
|
|
636
|
+
* // handle error
|
|
637
|
+
* }
|
|
638
|
+
* })
|
|
639
|
+
* ```
|
|
640
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/storage/Cloud.getTempFileURL.html
|
|
641
|
+
*/
|
|
642
|
+
getTempFileURL(param: OQ<cloud.GetTempFileURLParam>): void
|
|
643
|
+
getTempFileURL(param: RQ<cloud.GetTempFileURLParam>): Promise<cloud.GetTempFileURLResult>
|
|
644
|
+
|
|
645
|
+
/** 从云存储空间删除文件,一次最多 50 个
|
|
646
|
+
* @supported weapp
|
|
647
|
+
* @example
|
|
648
|
+
* ```tsx
|
|
649
|
+
* .cloud.deleteFile({
|
|
650
|
+
* fileList: ['a7xzcb']
|
|
651
|
+
* }).then(res => {
|
|
652
|
+
* // handle success
|
|
653
|
+
* console.log(res.fileList)
|
|
654
|
+
* }).catch(error => {
|
|
655
|
+
* // handle error
|
|
656
|
+
* })
|
|
657
|
+
* ```
|
|
658
|
+
* @example
|
|
659
|
+
* ```tsx
|
|
660
|
+
* Taro.cloud.deleteFile({
|
|
661
|
+
* fileList: ['a7xzcb'],
|
|
662
|
+
* success: res => {
|
|
663
|
+
* // handle success
|
|
664
|
+
* console.log(res.fileList)
|
|
665
|
+
* },
|
|
666
|
+
* fail: err => {
|
|
667
|
+
* // handle error
|
|
668
|
+
* },
|
|
669
|
+
* complete: res => {
|
|
670
|
+
* // ...
|
|
671
|
+
* }
|
|
672
|
+
* })
|
|
673
|
+
* ```
|
|
674
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/storage/Cloud.deleteFile.html
|
|
675
|
+
*/
|
|
676
|
+
deleteFile(param: OQ<cloud.DeleteFileParam>): void
|
|
677
|
+
deleteFile(param: RQ<cloud.DeleteFileParam>): Promise<cloud.DeleteFileResult>
|
|
678
|
+
|
|
679
|
+
/** 获取数据库实例
|
|
680
|
+
* @supported weapp
|
|
681
|
+
* @example
|
|
682
|
+
* 以下调用获取默认环境的数据库的引用:
|
|
683
|
+
*
|
|
684
|
+
* ```tsx
|
|
685
|
+
* const db = Taro.cloud.database()
|
|
686
|
+
* ```
|
|
687
|
+
* @example
|
|
688
|
+
* 假设有一个环境名为 test-123,用做测试环境,那么可以如下获取测试环境数据库:
|
|
689
|
+
*
|
|
690
|
+
* ```tsx
|
|
691
|
+
* const testDB = Taro.cloud.database({
|
|
692
|
+
* env: 'test-123'
|
|
693
|
+
* })
|
|
694
|
+
* ```
|
|
695
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/Cloud.database.html
|
|
696
|
+
*/
|
|
697
|
+
database(config?: cloud.IConfig): DB.Database
|
|
698
|
+
|
|
699
|
+
/** 调用云托管服务
|
|
700
|
+
* @supported weapp
|
|
701
|
+
* @example
|
|
702
|
+
* 假设已经初始化了一个叫c1的云开发实例,并发起云托管调用
|
|
703
|
+
*
|
|
704
|
+
* ``` tsx
|
|
705
|
+
* const r = await c1.callContainer({
|
|
706
|
+
* path: '/path/to/container', // 填入容器的访问路径
|
|
707
|
+
* method: 'POST',
|
|
708
|
+
* })
|
|
709
|
+
* ```
|
|
710
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/container/Cloud.callContainer.html
|
|
711
|
+
*/
|
|
712
|
+
callContainer < R = any, P = any >(params: cloud.CallContainerParam<P>): Promise<cloud.CallContainerResult<R>>
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
namespace DB {
|
|
716
|
+
/** 云开发 SDK 数据库实例
|
|
717
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/Database.html
|
|
718
|
+
*/
|
|
719
|
+
interface Database {
|
|
720
|
+
/** 数据库配置 */
|
|
721
|
+
readonly config: cloud.IConfig
|
|
722
|
+
/** 数据库操作符,通过 db.command 获取
|
|
723
|
+
* @supported weapp
|
|
724
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/Command.html
|
|
725
|
+
*/
|
|
726
|
+
readonly command: Command
|
|
727
|
+
/** 数据库地理位置结构集
|
|
728
|
+
* @supported weapp
|
|
729
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/Geo.html
|
|
730
|
+
*/
|
|
731
|
+
readonly Geo: IGeo
|
|
732
|
+
/** 构造一个服务端时间的引用。可用于查询条件、更新字段值或新增记录时的字段值。
|
|
733
|
+
* @supported weapp
|
|
734
|
+
* @example
|
|
735
|
+
* 新增记录时设置字段为服务端时间:
|
|
736
|
+
*
|
|
737
|
+
* ```tsx
|
|
738
|
+
* db.collection('todos').add({
|
|
739
|
+
* description: 'eat an apple',
|
|
740
|
+
* createTime: db.serverDate()
|
|
741
|
+
* })
|
|
742
|
+
* ```
|
|
743
|
+
* 更新字段为服务端时间往后一小时:
|
|
744
|
+
*
|
|
745
|
+
* ```tsx
|
|
746
|
+
* db.collection('todos').doc('my-todo-id').update({
|
|
747
|
+
* due: db.serverDate({
|
|
748
|
+
* offset: 60 * 60 * 1000
|
|
749
|
+
* })
|
|
750
|
+
* })
|
|
751
|
+
* ```
|
|
752
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/Database.serverDate.html
|
|
753
|
+
*/
|
|
754
|
+
serverDate(options?: Database.ServerDate.IOptions): Database.ServerDate
|
|
755
|
+
/** 构造正则表达式,仅需在普通 js 正则表达式无法满足的情况下使用
|
|
756
|
+
* @supported weapp
|
|
757
|
+
* @example
|
|
758
|
+
* ```tsx
|
|
759
|
+
* // 原生 JavaScript 对象
|
|
760
|
+
* db.collection('todos').where({
|
|
761
|
+
* description: /miniprogram/i
|
|
762
|
+
* })
|
|
763
|
+
*
|
|
764
|
+
* // 数据库正则对象
|
|
765
|
+
* db.collection('todos').where({
|
|
766
|
+
* description: db.RegExp({
|
|
767
|
+
* regexp: 'miniprogram',
|
|
768
|
+
* options: 'i',
|
|
769
|
+
* })
|
|
770
|
+
* })
|
|
771
|
+
*
|
|
772
|
+
* // 用 new 构造也是可以的
|
|
773
|
+
* db.collection('todos').where({
|
|
774
|
+
* description: new db.RegExp({
|
|
775
|
+
* regexp: 'miniprogram',
|
|
776
|
+
* options: 'i',
|
|
777
|
+
* })
|
|
778
|
+
* })
|
|
779
|
+
* ```
|
|
780
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/Database.RegExp.html
|
|
781
|
+
*/
|
|
782
|
+
RegExp(options: Database.IRegExp.IRegExpOptions): Database.IRegExp
|
|
783
|
+
/** 获取集合的引用。方法接受一个 `name` 参数,指定需引用的集合名称。
|
|
784
|
+
* @supported weapp
|
|
785
|
+
* @example
|
|
786
|
+
* ```tsx
|
|
787
|
+
* const db = Taro.cloud.database()
|
|
788
|
+
* const todosCollection = db.collection('todos')
|
|
789
|
+
* ```
|
|
790
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/Database.collection.html
|
|
791
|
+
*/
|
|
792
|
+
collection(collectionName: string): Collection
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
namespace Database {
|
|
796
|
+
/** 可用于查询条件、更新字段值或新增记录时的字段值。 */
|
|
797
|
+
interface ServerDate {
|
|
798
|
+
readonly options: ServerDate.IOptions
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
namespace ServerDate {
|
|
802
|
+
interface IOptions {
|
|
803
|
+
offset: number
|
|
804
|
+
}
|
|
805
|
+
}
|
|
806
|
+
|
|
807
|
+
/** 构造正则表达式 */
|
|
808
|
+
interface IRegExp {
|
|
809
|
+
readonly regexp: string
|
|
810
|
+
readonly options: string
|
|
811
|
+
}
|
|
812
|
+
|
|
813
|
+
namespace IRegExp {
|
|
814
|
+
interface IRegExpOptions {
|
|
815
|
+
regexp: string
|
|
816
|
+
options?: string
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
|
|
820
|
+
/** 内部符号 */
|
|
821
|
+
interface InternalSymbol {}
|
|
822
|
+
}
|
|
823
|
+
|
|
824
|
+
/** 数据库集合引用
|
|
825
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/Collection.html
|
|
826
|
+
*/
|
|
827
|
+
interface Collection extends Query {
|
|
828
|
+
/** 集合名称 */
|
|
829
|
+
readonly collectionName: string
|
|
830
|
+
/** 集合所在数据库引用 */
|
|
831
|
+
readonly database: Database
|
|
832
|
+
|
|
833
|
+
/** 获取集合中指定记录的引用。方法接受一个 `id` 参数,指定需引用的记录的 `_id`。
|
|
834
|
+
* @supported weapp
|
|
835
|
+
* @example
|
|
836
|
+
* ```tsx
|
|
837
|
+
* const myTodo = db.collection('todos').doc('my-todo-id')
|
|
838
|
+
* ```
|
|
839
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/collection/Collection.doc.html
|
|
840
|
+
*/
|
|
841
|
+
doc(
|
|
842
|
+
/** 记录 _id */
|
|
843
|
+
docId: string | number
|
|
844
|
+
): Document
|
|
845
|
+
|
|
846
|
+
/** 发起聚合操作,定义完聚合流水线阶段之后需调用 end 方法标志结束定义并实际发起聚合操作
|
|
847
|
+
* @supported weapp
|
|
848
|
+
* @example
|
|
849
|
+
* ```tsx
|
|
850
|
+
* const $ = db.command.aggregate
|
|
851
|
+
* db.collection('books').aggregate()
|
|
852
|
+
* .group({
|
|
853
|
+
* // 按 category 字段分组
|
|
854
|
+
* _id: '$category',
|
|
855
|
+
* // 让输出的每组记录有一个 avgSales 字段,其值是组内所有记录的 sales 字段的平均值
|
|
856
|
+
* avgSales: $.avg('$sales')
|
|
857
|
+
* })
|
|
858
|
+
* .end()
|
|
859
|
+
* .then(res => console.log(res))
|
|
860
|
+
* .catch(err => console.error(err))
|
|
861
|
+
* ```
|
|
862
|
+
* @example
|
|
863
|
+
* ```tsx
|
|
864
|
+
* const $ = db.command.aggregate
|
|
865
|
+
* db.collection('books').aggregate()
|
|
866
|
+
* .group({
|
|
867
|
+
* // 按 category 字段分组
|
|
868
|
+
* _id: '$category',
|
|
869
|
+
* // 让输出的每组记录有一个 avgSales 字段,其值是组内所有记录的 sales 字段的平均值
|
|
870
|
+
* avgSales: $.avg('$sales')
|
|
871
|
+
* })
|
|
872
|
+
* .end({
|
|
873
|
+
* success: function(res) {
|
|
874
|
+
* console.log(res)
|
|
875
|
+
* },
|
|
876
|
+
* fail: function(err) {
|
|
877
|
+
* console.error(err)
|
|
878
|
+
* }
|
|
879
|
+
* })
|
|
880
|
+
* ```
|
|
881
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/collection/Collection.aggregate.html
|
|
882
|
+
*/
|
|
883
|
+
aggregate(): Aggregate
|
|
884
|
+
|
|
885
|
+
/** 指定查询条件,返回带新查询条件的新的集合引用
|
|
886
|
+
* @supported weapp
|
|
887
|
+
* @example
|
|
888
|
+
* ```tsx
|
|
889
|
+
* const _ = db.command
|
|
890
|
+
* const result = await db.collection('todos').where({
|
|
891
|
+
* price: _.lt(100)
|
|
892
|
+
* }).get()
|
|
893
|
+
* ```
|
|
894
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/collection/Collection.where.html
|
|
895
|
+
*/
|
|
896
|
+
where(condition: Query.IQueryCondition): Collection
|
|
897
|
+
|
|
898
|
+
/** 指定查询结果集数量上限
|
|
899
|
+
* @supported weapp
|
|
900
|
+
* @example
|
|
901
|
+
* ```tsx
|
|
902
|
+
* db.collection('todos').limit(10)
|
|
903
|
+
* .get()
|
|
904
|
+
* .then(console.log)
|
|
905
|
+
* .catch(console.error)
|
|
906
|
+
* ```
|
|
907
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/collection/Collection.limit.html
|
|
908
|
+
*/
|
|
909
|
+
limit(value: number): Collection
|
|
910
|
+
|
|
911
|
+
/** 指定查询排序条件
|
|
912
|
+
* @supported weapp
|
|
913
|
+
* @example
|
|
914
|
+
* 按一个字段排序:按进度排升序取待办事项
|
|
915
|
+
*
|
|
916
|
+
* ```tsx
|
|
917
|
+
* db.collection('todos').orderBy('progress', 'asc')
|
|
918
|
+
* .get()
|
|
919
|
+
* .then(console.log)
|
|
920
|
+
* .catch(console.error)
|
|
921
|
+
* ```
|
|
922
|
+
*
|
|
923
|
+
* 按多个字段排序:先按 progress 排降序(progress 越大越靠前)、再按 description 排升序(字母序越前越靠前)取待办事项
|
|
924
|
+
*
|
|
925
|
+
* ```tsx
|
|
926
|
+
* db.collection('todos')
|
|
927
|
+
* .orderBy('progress', 'desc')
|
|
928
|
+
* .orderBy('description', 'asc')
|
|
929
|
+
* .get()
|
|
930
|
+
* .then(console.log)
|
|
931
|
+
* .catch(console.error)
|
|
932
|
+
* ```
|
|
933
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/collection/Collection.orderBy.html
|
|
934
|
+
*/
|
|
935
|
+
orderBy(fieldPath: string, string: 'asc' | 'desc'): Collection
|
|
936
|
+
|
|
937
|
+
/** 指定查询返回结果时从指定序列后的结果开始返回,常用于分页
|
|
938
|
+
* @supported weapp
|
|
939
|
+
* @example
|
|
940
|
+
* ```tsx
|
|
941
|
+
* db.collection('todos').skip(10)
|
|
942
|
+
* .get()
|
|
943
|
+
* .then(console.log)
|
|
944
|
+
* .catch(console.error)
|
|
945
|
+
* ```
|
|
946
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/collection/Collection.skip.html
|
|
947
|
+
*/
|
|
948
|
+
skip(offset: number): Collection
|
|
949
|
+
|
|
950
|
+
/** 指定返回结果中记录需返回的字段
|
|
951
|
+
*
|
|
952
|
+
* **说明**
|
|
953
|
+
*
|
|
954
|
+
* 方法接受一个必填对象用于指定需返回的字段,对象的各个 key 表示要返回或不要返回的字段,value 传入 true|false(或 1|-1)表示要返回还是不要返回。
|
|
955
|
+
* 如果指定的字段是数组字段,还可以用以下方法只返回数组的第一个元素:在该字段 key 后面拼接上 `.$` 成为 `字段.$` 的形式。
|
|
956
|
+
* 如果指定的字段是数组字段,还可以用 `db.command.project.slice` 方法返回数组的子数组:
|
|
957
|
+
* 方法既可以接收一个正数表示返回前 n 个元素,也可以接收一个负数表示返回后 n 个元素;还可以接收一个包含两个数字 `[ skip, limit ]` 的数组,如果 `skip` 是正数,表示跳过 `skip` 个元素后再返回接下来的 `limit` 个元素,如果 `skip` 是负数,表示从倒数第 `skip` 个元素开始,返回往后数的 `limit` 个元素
|
|
958
|
+
*
|
|
959
|
+
* - 返回数组的前 5 个元素:`{ tags: db.command.project.slice(5) }`
|
|
960
|
+
* - 返回数组的后 5 个元素:`{ tags: db.command.project.slice(-5) }`
|
|
961
|
+
* - 跳过前 5 个元素,返回接下来 10 个元素:`{ tags: db.command.project.slice(5, 10) }`
|
|
962
|
+
* - 从倒数第 5 个元素开始,返回接下来正方向数的 10 个元素:`{ tags: db.command.project.slice(-5, 10) }`
|
|
963
|
+
* @supported weapp
|
|
964
|
+
* @example
|
|
965
|
+
* 返回 description, done 和 progress 三个字段:
|
|
966
|
+
*
|
|
967
|
+
* ```tsx
|
|
968
|
+
* db.collection('todos').field({
|
|
969
|
+
* description: true,
|
|
970
|
+
* done: true,
|
|
971
|
+
* progress: true,
|
|
972
|
+
* // 只返回 tags 数组前 3 个元素
|
|
973
|
+
* tags: db.command.project.slice(3),
|
|
974
|
+
* })
|
|
975
|
+
* .get()
|
|
976
|
+
* .then(console.log)
|
|
977
|
+
* .catch(console.error)
|
|
978
|
+
* ```
|
|
979
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/collection/Collection.field.html
|
|
980
|
+
*/
|
|
981
|
+
field(object: TaroGeneral.IAnyObject): Collection
|
|
982
|
+
|
|
983
|
+
/** 获取集合数据,或获取根据查询条件筛选后的集合数据。
|
|
984
|
+
*
|
|
985
|
+
* **使用说明**
|
|
986
|
+
*
|
|
987
|
+
* 统计集合记录数或统计查询语句对应的结果记录数
|
|
988
|
+
*
|
|
989
|
+
* 小程序端与云函数端的表现会有如下差异:
|
|
990
|
+
*
|
|
991
|
+
* - 小程序端:如果没有指定 limit,则默认且最多取 20 条记录。
|
|
992
|
+
* - 云函数端:如果没有指定 limit,则默认且最多取 100 条记录。
|
|
993
|
+
*
|
|
994
|
+
* 如果没有指定 skip,则默认从第 0 条记录开始取,skip 常用于分页。
|
|
995
|
+
*
|
|
996
|
+
* 如果需要取集合中所有的数据,仅在数据量不大且在云函数中时
|
|
997
|
+
* @supported weapp
|
|
998
|
+
* @example
|
|
999
|
+
* ```tsx
|
|
1000
|
+
* const db = Taro.cloud.database()
|
|
1001
|
+
* db.collection('todos').where({
|
|
1002
|
+
* _openid: 'xxx' // 填入当前用户 openid
|
|
1003
|
+
* }).get().then(res => {
|
|
1004
|
+
* console.log(res.data)
|
|
1005
|
+
* })
|
|
1006
|
+
* ```
|
|
1007
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/collection/Collection.get.html
|
|
1008
|
+
*/
|
|
1009
|
+
get(): Promise<Query.IQueryResult>
|
|
1010
|
+
|
|
1011
|
+
/** 统计匹配查询条件的记录的条数
|
|
1012
|
+
* @supported weapp
|
|
1013
|
+
* @example
|
|
1014
|
+
* ```tsx
|
|
1015
|
+
* const db = Taro.cloud.database()
|
|
1016
|
+
* db.collection('todos').where({
|
|
1017
|
+
* _openid: 'xxx' // 填入当前用户 openid
|
|
1018
|
+
* }).count().then(res => {
|
|
1019
|
+
* console.log(res.total)
|
|
1020
|
+
* })
|
|
1021
|
+
* ```
|
|
1022
|
+
* @example
|
|
1023
|
+
* ```tsx
|
|
1024
|
+
* const db = Taro.cloud.database()
|
|
1025
|
+
* db.collection('todos').where({
|
|
1026
|
+
* _openid: 'xxx' // 填入当前用户 openid
|
|
1027
|
+
* }).count({
|
|
1028
|
+
* success: function(res) {
|
|
1029
|
+
* console.log(res.total)
|
|
1030
|
+
* },
|
|
1031
|
+
* fail: console.error
|
|
1032
|
+
* })
|
|
1033
|
+
* ```
|
|
1034
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/collection/Collection.count.html
|
|
1035
|
+
*/
|
|
1036
|
+
count(): Promise<Query.ICountResult>
|
|
1037
|
+
|
|
1038
|
+
/** 新增记录,如果传入的记录对象没有 _id 字段,则由后台自动生成 _id;若指定了 _id,则不能与已有记录冲突
|
|
1039
|
+
* @supported weapp
|
|
1040
|
+
* @example
|
|
1041
|
+
* ```tsx
|
|
1042
|
+
* db.collection('todos').add({
|
|
1043
|
+
* // data 字段表示需新增的 JSON 数据
|
|
1044
|
+
* data: {
|
|
1045
|
+
* description: "learn cloud database",
|
|
1046
|
+
* due: new Date("2018-09-01"),
|
|
1047
|
+
* tags: [
|
|
1048
|
+
* "cloud",
|
|
1049
|
+
* "database"
|
|
1050
|
+
* ],
|
|
1051
|
+
* location: new db.Geo.Point(113, 23),
|
|
1052
|
+
* done: false
|
|
1053
|
+
* }
|
|
1054
|
+
* })
|
|
1055
|
+
* .then(res => {
|
|
1056
|
+
* console.log(res)
|
|
1057
|
+
* })
|
|
1058
|
+
* .catch(console.error)
|
|
1059
|
+
* ```
|
|
1060
|
+
* @example
|
|
1061
|
+
* ```tsx
|
|
1062
|
+
* db.collection('todos').add({
|
|
1063
|
+
* // data 字段表示需新增的 JSON 数据
|
|
1064
|
+
* data: {
|
|
1065
|
+
* // _id: 'todo-identifiant-aleatoire', // 可选自定义 _id,在此处场景下用数据库自动分配的就可以了
|
|
1066
|
+
* description: "learn cloud database",
|
|
1067
|
+
* due: new Date("2018-09-01"),
|
|
1068
|
+
* tags: [
|
|
1069
|
+
* "cloud",
|
|
1070
|
+
* "database"
|
|
1071
|
+
* ],
|
|
1072
|
+
* // 为待办事项添加一个地理位置(113°E,23°N)
|
|
1073
|
+
* location: new db.Geo.Point(113, 23),
|
|
1074
|
+
* done: false
|
|
1075
|
+
* },
|
|
1076
|
+
* success: function(res) {
|
|
1077
|
+
* // res 是一个对象,其中有 _id 字段标记刚创建的记录的 id
|
|
1078
|
+
* console.log(res)
|
|
1079
|
+
* },
|
|
1080
|
+
* fail: console.error,
|
|
1081
|
+
* complete: cosnole.log
|
|
1082
|
+
* })
|
|
1083
|
+
* ```
|
|
1084
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/collection/Collection.add.html
|
|
1085
|
+
*/
|
|
1086
|
+
add(options: OQ<Document.IAddDocumentOptions>): void
|
|
1087
|
+
add(options: RQ<Document.IAddDocumentOptions>): Promise<Query.IAddResult>
|
|
1088
|
+
|
|
1089
|
+
/** 监听集合中符合查询条件的数据的更新事件。注意使用 watch 时,只有 where 语句会生效,orderBy、limit 等不生效。
|
|
1090
|
+
* @supported weapp
|
|
1091
|
+
* @example
|
|
1092
|
+
* 根据查询条件监听
|
|
1093
|
+
*
|
|
1094
|
+
* ```tsx
|
|
1095
|
+
* const db = Taro.cloud.database()
|
|
1096
|
+
* const watcher = db.collection('todos').where({
|
|
1097
|
+
* _openid: 'xxx' // 填入当前用户 openid
|
|
1098
|
+
* }).watch({
|
|
1099
|
+
* onChange: function(snapshot) {
|
|
1100
|
+
* console.log('snapshot', snapshot)
|
|
1101
|
+
* },
|
|
1102
|
+
* onError: function(err) {
|
|
1103
|
+
* console.error('the watch closed because of error', err)
|
|
1104
|
+
* }
|
|
1105
|
+
* })
|
|
1106
|
+
* ```
|
|
1107
|
+
* @example
|
|
1108
|
+
* 监听一个记录的变化
|
|
1109
|
+
*
|
|
1110
|
+
* ```tsx
|
|
1111
|
+
* const db = Taro.cloud.database()
|
|
1112
|
+
* const watcher = db.collection('todos').doc('x').watch({
|
|
1113
|
+
* onChange: function(snapshot) {
|
|
1114
|
+
* console.log('snapshot', snapshot)
|
|
1115
|
+
* },
|
|
1116
|
+
* onError: function(err) {
|
|
1117
|
+
* console.error('the watch closed because of error', err)
|
|
1118
|
+
* }
|
|
1119
|
+
* })
|
|
1120
|
+
* ```
|
|
1121
|
+
* @example
|
|
1122
|
+
* 关闭监听
|
|
1123
|
+
*
|
|
1124
|
+
* ```tsx
|
|
1125
|
+
* const db = Taro.cloud.database()
|
|
1126
|
+
* const watcher = db.collection('todos').where({
|
|
1127
|
+
* _openid: 'xxx' // 填入当前用户 openid
|
|
1128
|
+
* }).watch({
|
|
1129
|
+
* onChange: function(snapshot) {
|
|
1130
|
+
* console.log('snapshot', snapshot)
|
|
1131
|
+
* },
|
|
1132
|
+
* onError: function(err) {
|
|
1133
|
+
* console.error('the watch closed because of error', err)
|
|
1134
|
+
* }
|
|
1135
|
+
* })
|
|
1136
|
+
* // ...
|
|
1137
|
+
* // 关闭
|
|
1138
|
+
* await watcher.close()
|
|
1139
|
+
* ```
|
|
1140
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/collection/Collection.watch.html
|
|
1141
|
+
*/
|
|
1142
|
+
watch(options: Document.IWatchDocumentOptions): Document.IWatcher
|
|
1143
|
+
}
|
|
1144
|
+
|
|
1145
|
+
/** 数据库记录引用
|
|
1146
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/Document.html
|
|
1147
|
+
*/
|
|
1148
|
+
interface Document {
|
|
1149
|
+
/** 获取记录数据,或获取根据查询条件筛选后的记录数据
|
|
1150
|
+
* @supported weapp
|
|
1151
|
+
* @example
|
|
1152
|
+
* ```tsx
|
|
1153
|
+
* const db = Taro.cloud.database()
|
|
1154
|
+
* db.collection('todos').doc('<some-todo-id>').get().then(res => {
|
|
1155
|
+
* console.log(res.data)
|
|
1156
|
+
* })
|
|
1157
|
+
* ```
|
|
1158
|
+
* @example
|
|
1159
|
+
* ```tsx
|
|
1160
|
+
* const db = Taro.cloud.database()
|
|
1161
|
+
* db.collection('todos').doc('<some-todo-id>').get({
|
|
1162
|
+
* success: function(res) {
|
|
1163
|
+
* console.log(res.data)
|
|
1164
|
+
* },
|
|
1165
|
+
* fail: console.error
|
|
1166
|
+
* })
|
|
1167
|
+
* ```
|
|
1168
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/document/Document.get.html
|
|
1169
|
+
*/
|
|
1170
|
+
get(options: OQ<Document.IGetDocumentOptions>): void
|
|
1171
|
+
get(options: RQ<Document.IGetDocumentOptions>): Promise<Query.IQuerySingleResult>
|
|
1172
|
+
|
|
1173
|
+
/** 替换更新一条记
|
|
1174
|
+
* @supported weapp
|
|
1175
|
+
* @example
|
|
1176
|
+
* ```tsx
|
|
1177
|
+
* const _ = db.command
|
|
1178
|
+
* db.collection('todos').doc('todo-identifiant-aleatoire').set({
|
|
1179
|
+
* data: {
|
|
1180
|
+
* description: "learn cloud database",
|
|
1181
|
+
* due: new Date("2018-09-01"),
|
|
1182
|
+
* tags: [
|
|
1183
|
+
* "cloud",
|
|
1184
|
+
* "database"
|
|
1185
|
+
* ],
|
|
1186
|
+
* style: {
|
|
1187
|
+
* color: "skyblue"
|
|
1188
|
+
* },
|
|
1189
|
+
* // 位置(113°E,23°N)
|
|
1190
|
+
* location: new db.Geo.Point(113, 23),
|
|
1191
|
+
* done: false
|
|
1192
|
+
* }
|
|
1193
|
+
* }).then(res => {
|
|
1194
|
+
* console.log(res)
|
|
1195
|
+
* }).catch(err => {
|
|
1196
|
+
* console.error(err)
|
|
1197
|
+
* })
|
|
1198
|
+
* ```
|
|
1199
|
+
* @example
|
|
1200
|
+
* ```tsx
|
|
1201
|
+
* const _ = db.command
|
|
1202
|
+
* db.collection('todos').doc('todo-identifiant-aleatoire').set({
|
|
1203
|
+
* data: {
|
|
1204
|
+
* description: "learn cloud database",
|
|
1205
|
+
* due: new Date("2018-09-01"),
|
|
1206
|
+
* tags: [
|
|
1207
|
+
* "cloud",
|
|
1208
|
+
* "database"
|
|
1209
|
+
* ],
|
|
1210
|
+
* style: {
|
|
1211
|
+
* color: "skyblue"
|
|
1212
|
+
* },
|
|
1213
|
+
* // 位置(113°E,23°N)
|
|
1214
|
+
* location: new db.Geo.Point(113, 23),
|
|
1215
|
+
* done: false
|
|
1216
|
+
* },
|
|
1217
|
+
* success: function(res) {
|
|
1218
|
+
* console.log(res.data)
|
|
1219
|
+
* },
|
|
1220
|
+
* fail: console.error
|
|
1221
|
+
* })
|
|
1222
|
+
* ```
|
|
1223
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/document/Document.set.html
|
|
1224
|
+
*/
|
|
1225
|
+
set(options: OQ<Document.ISetSingleDocumentOptions>): void
|
|
1226
|
+
set(options: RQ<Document.ISetSingleDocumentOptions>): Promise<Query.ISetResult>
|
|
1227
|
+
|
|
1228
|
+
/** 更新一条记录
|
|
1229
|
+
* @supported weapp
|
|
1230
|
+
* @example
|
|
1231
|
+
* ```tsx
|
|
1232
|
+
* db.collection('todos').doc('todo-identifiant-aleatoire').update({
|
|
1233
|
+
* // data 传入需要局部更新的数据
|
|
1234
|
+
* data: {
|
|
1235
|
+
* // 表示将 done 字段置为 true
|
|
1236
|
+
* done: true
|
|
1237
|
+
* }
|
|
1238
|
+
* })
|
|
1239
|
+
* .then(console.log)
|
|
1240
|
+
* .catch(console.error)
|
|
1241
|
+
* ```
|
|
1242
|
+
* @example
|
|
1243
|
+
* db.collection('todos').doc('todo-identifiant-aleatoire').update({
|
|
1244
|
+
* // data 传入需要局部更新的数据
|
|
1245
|
+
* data: {
|
|
1246
|
+
* // 表示将 done 字段置为 true
|
|
1247
|
+
* done: true
|
|
1248
|
+
* },
|
|
1249
|
+
* success: console.log,
|
|
1250
|
+
* fail: console.error
|
|
1251
|
+
* })
|
|
1252
|
+
* ```
|
|
1253
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/document/Document.update.html
|
|
1254
|
+
*/
|
|
1255
|
+
update(options: OQ<Document.IUpdateSingleDocumentOptions>): void
|
|
1256
|
+
update(options: RQ<Document.IUpdateSingleDocumentOptions>): Promise<Query.IUpdateResult>
|
|
1257
|
+
|
|
1258
|
+
/** 删除一条记录
|
|
1259
|
+
* @supported weapp
|
|
1260
|
+
* @example
|
|
1261
|
+
* ```tsx
|
|
1262
|
+
* db.collection('todos').doc('todo-identifiant-aleatoire').remove()
|
|
1263
|
+
* .then(console.log)
|
|
1264
|
+
* .catch(console.error)
|
|
1265
|
+
* ```
|
|
1266
|
+
* @example
|
|
1267
|
+
* ```tsx
|
|
1268
|
+
* db.collection('todos').doc('todo-identifiant-aleatoire').remove({
|
|
1269
|
+
* success: console.log,
|
|
1270
|
+
* fail: console.error
|
|
1271
|
+
* })
|
|
1272
|
+
* ```
|
|
1273
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/document/Document.remove.html
|
|
1274
|
+
*/
|
|
1275
|
+
remove(options: OQ<Document.IRemoveSingleDocumentOptions>): void
|
|
1276
|
+
remove(options: RQ<Document.IRemoveSingleDocumentOptions>): Promise<Query.IRemoveResult>
|
|
1277
|
+
}
|
|
1278
|
+
|
|
1279
|
+
namespace Document {
|
|
1280
|
+
/** 记录 ID */
|
|
1281
|
+
type DocumentId = string | number
|
|
1282
|
+
|
|
1283
|
+
/** 记录结构 */
|
|
1284
|
+
interface IDocumentData {
|
|
1285
|
+
/** 新增的记录 _id */
|
|
1286
|
+
_id?: DocumentId
|
|
1287
|
+
[key: string]: any
|
|
1288
|
+
}
|
|
1289
|
+
|
|
1290
|
+
/** 数据库 API 通用参数 */
|
|
1291
|
+
type IDBAPIParam = cloud.IApiParam
|
|
1292
|
+
|
|
1293
|
+
/** 新增记录的定义 */
|
|
1294
|
+
interface IAddDocumentOptions extends IDBAPIParam {
|
|
1295
|
+
/** 新增记录的定义 */
|
|
1296
|
+
data: IDocumentData
|
|
1297
|
+
/** 配置 */
|
|
1298
|
+
config?: cloud.IConfig
|
|
1299
|
+
/** 接口调用结束的回调函数(调用成功、失败都会执行) */
|
|
1300
|
+
complete?: (res: TaroGeneral.CallbackResult) => void
|
|
1301
|
+
/** 接口调用失败的回调函数 */
|
|
1302
|
+
fail?: (res: TaroGeneral.CallbackResult) => void
|
|
1303
|
+
/** 接口调用成功的回调函数 */
|
|
1304
|
+
success?: (res: TaroGeneral.CallbackResult) => void
|
|
1305
|
+
}
|
|
1306
|
+
|
|
1307
|
+
/** 监听集合中符合查询条件的数据的更新事件 */
|
|
1308
|
+
interface IWatchDocumentOptions {
|
|
1309
|
+
/** 成功回调,回调传入的参数 snapshot 是变更快照 */
|
|
1310
|
+
onChange?: (res: TaroGeneral.CallbackResult) => void
|
|
1311
|
+
/** 失败回调 */
|
|
1312
|
+
onError?: (res: TaroGeneral.CallbackResult) => void
|
|
1313
|
+
}
|
|
1314
|
+
|
|
1315
|
+
/** 变更快照 */
|
|
1316
|
+
interface ISnapshot {
|
|
1317
|
+
/** 更新事件数组 */
|
|
1318
|
+
docChanges: ChangeEvent[]
|
|
1319
|
+
/** 数据快照,表示此更新事件发生后查询语句对应的查询结果 */
|
|
1320
|
+
docs: TaroGeneral.IAnyObject[]
|
|
1321
|
+
/** 快照类型,仅在第一次初始化数据时有值为 init */
|
|
1322
|
+
type: string
|
|
1323
|
+
/** 变更事件 id */
|
|
1324
|
+
id: number
|
|
1325
|
+
}
|
|
1326
|
+
|
|
1327
|
+
/** 更新事件 */
|
|
1328
|
+
interface ChangeEvent {
|
|
1329
|
+
/** 更新事件 id */
|
|
1330
|
+
id: number
|
|
1331
|
+
/** 列表更新类型,表示更新事件对监听列表的影响,枚举值 */
|
|
1332
|
+
queueType: keyof QueueType
|
|
1333
|
+
/** 数据更新类型,表示记录的具体更新类型,枚举值 */
|
|
1334
|
+
dataType: keyof DataType
|
|
1335
|
+
/** 更新的记录 id */
|
|
1336
|
+
docId: string
|
|
1337
|
+
/** 更新的完整记录 */
|
|
1338
|
+
doc: TaroGeneral.IAnyObject
|
|
1339
|
+
/** 所有更新的字段及字段更新后的值,`key` 为更新的字段路径,`value` 为字段更新后的值,仅在 `update` 操作时有此信息 */
|
|
1340
|
+
updatedFields: TaroGeneral.IAnyObject
|
|
1341
|
+
/** 所有被删除的字段,仅在 `update` 操作时有此信息 */
|
|
1342
|
+
removedFields: string[]
|
|
1343
|
+
}
|
|
1344
|
+
|
|
1345
|
+
/** 列表更新类型,表示更新事件对监听列表的影响,枚举值 */
|
|
1346
|
+
interface QueueType {
|
|
1347
|
+
/** 初始化列表 */
|
|
1348
|
+
init
|
|
1349
|
+
/** 列表中的记录内容有更新,但列表包含的记录不变 */
|
|
1350
|
+
update
|
|
1351
|
+
/** 记录进入列表 */
|
|
1352
|
+
enqueue
|
|
1353
|
+
/** 记录离开列表 */
|
|
1354
|
+
dequeue
|
|
1355
|
+
}
|
|
1356
|
+
|
|
1357
|
+
/** 数据更新类型,表示记录的具体更新类型,枚举值 */
|
|
1358
|
+
interface DataType {
|
|
1359
|
+
/** 初始化列表 */
|
|
1360
|
+
init
|
|
1361
|
+
/** 记录内容更新,对应 `update` 操作 */
|
|
1362
|
+
update
|
|
1363
|
+
/** 记录内容被替换,对应 `set` 操作 */
|
|
1364
|
+
replace
|
|
1365
|
+
/** 记录新增,对应 `add` 操作 */
|
|
1366
|
+
add
|
|
1367
|
+
/** 记录被删除,对应 `remove` 操作 */
|
|
1368
|
+
remove
|
|
1369
|
+
}
|
|
1370
|
+
|
|
1371
|
+
interface IWatcher {
|
|
1372
|
+
/** 关闭监听,无需参数,返回 Promise,会在关闭完成时 resolve */
|
|
1373
|
+
close(): Promise<any>
|
|
1374
|
+
}
|
|
1375
|
+
|
|
1376
|
+
/** 获取记录参数 */
|
|
1377
|
+
type IGetDocumentOptions = IDBAPIParam
|
|
1378
|
+
|
|
1379
|
+
/** 获取记录条数参数 */
|
|
1380
|
+
type ICountDocumentOptions = IDBAPIParam
|
|
1381
|
+
|
|
1382
|
+
/** 更新记录参数 */
|
|
1383
|
+
interface IUpdateDocumentOptions extends IDBAPIParam {
|
|
1384
|
+
data: IUpdateCondition
|
|
1385
|
+
/** 配置 */
|
|
1386
|
+
config?: cloud.IConfig
|
|
1387
|
+
/** 接口调用结束的回调函数(调用成功、失败都会执行) */
|
|
1388
|
+
complete?: (res: TaroGeneral.CallbackResult) => void
|
|
1389
|
+
/** 接口调用失败的回调函数 */
|
|
1390
|
+
fail?: (res: TaroGeneral.CallbackResult) => void
|
|
1391
|
+
/** 接口调用成功的回调函数 */
|
|
1392
|
+
success?: (res: TaroGeneral.CallbackResult) => void
|
|
1393
|
+
}
|
|
1394
|
+
|
|
1395
|
+
/** 更新单条记录参数 */
|
|
1396
|
+
interface IUpdateSingleDocumentOptions extends IDBAPIParam {
|
|
1397
|
+
/** 替换记录的定义 */
|
|
1398
|
+
data: IUpdateCondition
|
|
1399
|
+
/** 配置 */
|
|
1400
|
+
config?: cloud.IConfig
|
|
1401
|
+
/** 接口调用结束的回调函数(调用成功、失败都会执行) */
|
|
1402
|
+
complete?: (res: TaroGeneral.CallbackResult) => void
|
|
1403
|
+
/** 接口调用失败的回调函数 */
|
|
1404
|
+
fail?: (res: TaroGeneral.CallbackResult) => void
|
|
1405
|
+
/** 接口调用成功的回调函数 */
|
|
1406
|
+
success?: (res: TaroGeneral.CallbackResult) => void
|
|
1407
|
+
}
|
|
1408
|
+
|
|
1409
|
+
/** 替换记录参数 */
|
|
1410
|
+
interface ISetDocumentOptions extends IDBAPIParam {
|
|
1411
|
+
/** 替换记录的定义 */
|
|
1412
|
+
data: IUpdateCondition
|
|
1413
|
+
/** 配置 */
|
|
1414
|
+
config?: cloud.IConfig
|
|
1415
|
+
/** 接口调用结束的回调函数(调用成功、失败都会执行) */
|
|
1416
|
+
complete?: (res: TaroGeneral.CallbackResult) => void
|
|
1417
|
+
/** 接口调用失败的回调函数 */
|
|
1418
|
+
fail?: (res: TaroGeneral.CallbackResult) => void
|
|
1419
|
+
/** 接口调用成功的回调函数 */
|
|
1420
|
+
success?: (res: TaroGeneral.CallbackResult) => void
|
|
1421
|
+
}
|
|
1422
|
+
|
|
1423
|
+
/** 替换一条记录参数 */
|
|
1424
|
+
interface ISetSingleDocumentOptions extends IDBAPIParam {
|
|
1425
|
+
data: IUpdateCondition
|
|
1426
|
+
/** 配置 */
|
|
1427
|
+
config?: cloud.IConfig
|
|
1428
|
+
/** 接口调用结束的回调函数(调用成功、失败都会执行) */
|
|
1429
|
+
complete?: (res: TaroGeneral.CallbackResult) => void
|
|
1430
|
+
/** 接口调用失败的回调函数 */
|
|
1431
|
+
fail?: (res: TaroGeneral.CallbackResult) => void
|
|
1432
|
+
/** 接口调用成功的回调函数 */
|
|
1433
|
+
success?: (res: TaroGeneral.CallbackResult) => void
|
|
1434
|
+
}
|
|
1435
|
+
|
|
1436
|
+
/** 删除记录参数 */
|
|
1437
|
+
interface IRemoveDocumentOptions extends IDBAPIParam {
|
|
1438
|
+
query: Query.IQueryCondition
|
|
1439
|
+
/** 配置 */
|
|
1440
|
+
config?: cloud.IConfig
|
|
1441
|
+
/** 接口调用结束的回调函数(调用成功、失败都会执行) */
|
|
1442
|
+
complete?: (res: TaroGeneral.CallbackResult) => void
|
|
1443
|
+
/** 接口调用失败的回调函数 */
|
|
1444
|
+
fail?: (res: TaroGeneral.CallbackResult) => void
|
|
1445
|
+
/** 接口调用成功的回调函数 */
|
|
1446
|
+
success?: (res: TaroGeneral.CallbackResult) => void
|
|
1447
|
+
}
|
|
1448
|
+
|
|
1449
|
+
/** 删除一条记录参数 */
|
|
1450
|
+
type IRemoveSingleDocumentOptions = IDBAPIParam
|
|
1451
|
+
|
|
1452
|
+
/** 更新记录定义 */
|
|
1453
|
+
interface IUpdateCondition {
|
|
1454
|
+
[key: string]: any
|
|
1455
|
+
}
|
|
1456
|
+
}
|
|
1457
|
+
|
|
1458
|
+
/** 数据库 Query 引用
|
|
1459
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/Query.html
|
|
1460
|
+
*/
|
|
1461
|
+
interface Query {
|
|
1462
|
+
/** 指定查询条件,返回带新查询条件的新的集合引用
|
|
1463
|
+
* @supported weapp
|
|
1464
|
+
* @example
|
|
1465
|
+
* ```tsx
|
|
1466
|
+
* const _ = db.command
|
|
1467
|
+
* const result = await db.collection('todos').where({
|
|
1468
|
+
* price: _.lt(100)
|
|
1469
|
+
* }).get()
|
|
1470
|
+
* ```
|
|
1471
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/collection/Collection.where.html
|
|
1472
|
+
*/
|
|
1473
|
+
where(condition: Query.IQueryCondition): Query
|
|
1474
|
+
|
|
1475
|
+
/** 指定查询排序条件
|
|
1476
|
+
* @supported weapp
|
|
1477
|
+
* @example
|
|
1478
|
+
* 按一个字段排序:按进度排升序取待办事项
|
|
1479
|
+
*
|
|
1480
|
+
* ```tsx
|
|
1481
|
+
* db.collection('todos').orderBy('progress', 'asc')
|
|
1482
|
+
* .get()
|
|
1483
|
+
* .then(console.log)
|
|
1484
|
+
* .catch(console.error)
|
|
1485
|
+
* ```
|
|
1486
|
+
*
|
|
1487
|
+
* 按多个字段排序:先按 progress 排降序(progress 越大越靠前)、再按 description 排升序(字母序越前越靠前)取待办事项
|
|
1488
|
+
*
|
|
1489
|
+
* ```tsx
|
|
1490
|
+
* db.collection('todos')
|
|
1491
|
+
* .orderBy('progress', 'desc')
|
|
1492
|
+
* .orderBy('description', 'asc')
|
|
1493
|
+
* .get()
|
|
1494
|
+
* .then(console.log)
|
|
1495
|
+
* .catch(console.error)
|
|
1496
|
+
* ```
|
|
1497
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/collection/Collection.orderBy.html
|
|
1498
|
+
*/
|
|
1499
|
+
orderBy(fieldPath: string, order: string): Query
|
|
1500
|
+
|
|
1501
|
+
/** 指定查询结果集数量上限
|
|
1502
|
+
* @supported weapp
|
|
1503
|
+
* @example
|
|
1504
|
+
* ```tsx
|
|
1505
|
+
* db.collection('todos').limit(10)
|
|
1506
|
+
* .get()
|
|
1507
|
+
* .then(console.log)
|
|
1508
|
+
* .catch(console.error)
|
|
1509
|
+
* ```
|
|
1510
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/collection/Collection.limit.html
|
|
1511
|
+
*/
|
|
1512
|
+
limit(max: number): Query
|
|
1513
|
+
|
|
1514
|
+
/** 指定查询返回结果时从指定序列后的结果开始返回,常用于分页
|
|
1515
|
+
* @supported weapp
|
|
1516
|
+
* @example
|
|
1517
|
+
* ```tsx
|
|
1518
|
+
* db.collection('todos').skip(10)
|
|
1519
|
+
* .get()
|
|
1520
|
+
* .then(console.log)
|
|
1521
|
+
* .catch(console.error)
|
|
1522
|
+
* ```
|
|
1523
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/collection/Collection.skip.html
|
|
1524
|
+
*/
|
|
1525
|
+
skip(offset: number): Query
|
|
1526
|
+
|
|
1527
|
+
/** 指定返回结果中记录需返回的字段
|
|
1528
|
+
*
|
|
1529
|
+
* **说明**
|
|
1530
|
+
*
|
|
1531
|
+
* 方法接受一个必填对象用于指定需返回的字段,对象的各个 key 表示要返回或不要返回的字段,value 传入 true|false(或 1|-1)表示要返回还是不要返回。
|
|
1532
|
+
* 如果指定的字段是数组字段,还可以用以下方法只返回数组的第一个元素:在该字段 key 后面拼接上 `.$` 成为 `字段.$` 的形式。
|
|
1533
|
+
* 如果指定的字段是数组字段,还可以用 `db.command.project.slice` 方法返回数组的子数组:
|
|
1534
|
+
* 方法既可以接收一个正数表示返回前 n 个元素,也可以接收一个负数表示返回后 n 个元素;还可以接收一个包含两个数字 `[ skip, limit ]` 的数组,如果 `skip` 是正数,表示跳过 `skip` 个元素后再返回接下来的 `limit` 个元素,如果 `skip` 是负数,表示从倒数第 `skip` 个元素开始,返回往后数的 `limit` 个元素
|
|
1535
|
+
*
|
|
1536
|
+
* - 返回数组的前 5 个元素:`{ tags: db.command.project.slice(5) }`
|
|
1537
|
+
* - 返回数组的后 5 个元素:`{ tags: db.command.project.slice(-5) }`
|
|
1538
|
+
* - 跳过前 5 个元素,返回接下来 10 个元素:`{ tags: db.command.project.slice(5, 10) }`
|
|
1539
|
+
* - 从倒数第 5 个元素开始,返回接下来正方向数的 10 个元素:`{ tags: db.command.project.slice(-5, 10) }`
|
|
1540
|
+
* @supported weapp
|
|
1541
|
+
* @example
|
|
1542
|
+
* 返回 description, done 和 progress 三个字段:
|
|
1543
|
+
*
|
|
1544
|
+
* ```tsx
|
|
1545
|
+
* db.collection('todos').field({
|
|
1546
|
+
* description: true,
|
|
1547
|
+
* done: true,
|
|
1548
|
+
* progress: true,
|
|
1549
|
+
* // 只返回 tags 数组前 3 个元素
|
|
1550
|
+
* tags: db.command.project.slice(3),
|
|
1551
|
+
* })
|
|
1552
|
+
* .get()
|
|
1553
|
+
* .then(console.log)
|
|
1554
|
+
* .catch(console.error)
|
|
1555
|
+
* ```
|
|
1556
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/collection/Collection.field.html
|
|
1557
|
+
*/
|
|
1558
|
+
field(object: TaroGeneral.IAnyObject): Query
|
|
1559
|
+
|
|
1560
|
+
/** 获取集合数据,或获取根据查询条件筛选后的集合数据。
|
|
1561
|
+
*
|
|
1562
|
+
* **使用说明**
|
|
1563
|
+
*
|
|
1564
|
+
* 统计集合记录数或统计查询语句对应的结果记录数
|
|
1565
|
+
*
|
|
1566
|
+
* 小程序端与云函数端的表现会有如下差异:
|
|
1567
|
+
*
|
|
1568
|
+
* - 小程序端:如果没有指定 limit,则默认且最多取 20 条记录。
|
|
1569
|
+
* - 云函数端:如果没有指定 limit,则默认且最多取 100 条记录。
|
|
1570
|
+
*
|
|
1571
|
+
* 如果没有指定 skip,则默认从第 0 条记录开始取,skip 常用于分页。
|
|
1572
|
+
*
|
|
1573
|
+
* 如果需要取集合中所有的数据,仅在数据量不大且在云函数中时
|
|
1574
|
+
* @supported weapp
|
|
1575
|
+
* @example
|
|
1576
|
+
* ```tsx
|
|
1577
|
+
* const db = Taro.cloud.database()
|
|
1578
|
+
* db.collection('todos').where({
|
|
1579
|
+
* _openid: 'xxx' // 填入当前用户 openid
|
|
1580
|
+
* }).get().then(res => {
|
|
1581
|
+
* console.log(res.data)
|
|
1582
|
+
* })
|
|
1583
|
+
* ```
|
|
1584
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/collection/Collection.get.html
|
|
1585
|
+
*/
|
|
1586
|
+
get(options: OQ<Document.IGetDocumentOptions>): void
|
|
1587
|
+
get(options: RQ<Document.IGetDocumentOptions>): Promise<Query.IQueryResult>
|
|
1588
|
+
|
|
1589
|
+
/** 统计匹配查询条件的记录的条数
|
|
1590
|
+
* @supported weapp
|
|
1591
|
+
* @example
|
|
1592
|
+
* ```tsx
|
|
1593
|
+
* const db = Taro.cloud.database()
|
|
1594
|
+
* db.collection('todos').where({
|
|
1595
|
+
* _openid: 'xxx' // 填入当前用户 openid
|
|
1596
|
+
* }).count().then(res => {
|
|
1597
|
+
* console.log(res.total)
|
|
1598
|
+
* })
|
|
1599
|
+
* ```
|
|
1600
|
+
* @example
|
|
1601
|
+
* ```tsx
|
|
1602
|
+
* const db = Taro.cloud.database()
|
|
1603
|
+
* db.collection('todos').where({
|
|
1604
|
+
* _openid: 'xxx' // 填入当前用户 openid
|
|
1605
|
+
* }).count({
|
|
1606
|
+
* success: function(res) {
|
|
1607
|
+
* console.log(res.total)
|
|
1608
|
+
* },
|
|
1609
|
+
* fail: console.error
|
|
1610
|
+
* })
|
|
1611
|
+
* ```
|
|
1612
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/collection/Collection.count.html
|
|
1613
|
+
*/
|
|
1614
|
+
count(options: OQ<Document.ICountDocumentOptions>): void
|
|
1615
|
+
count(options: RQ<Document.ICountDocumentOptions>): Promise<Query.ICountResult>
|
|
1616
|
+
}
|
|
1617
|
+
|
|
1618
|
+
namespace Query {
|
|
1619
|
+
interface IQueryCondition {
|
|
1620
|
+
[key: string]: any
|
|
1621
|
+
}
|
|
1622
|
+
|
|
1623
|
+
type IStringQueryCondition = string
|
|
1624
|
+
|
|
1625
|
+
interface IQueryResult extends TaroGeneral.CallbackResult {
|
|
1626
|
+
/** 查询的结果数组,数据的每个元素是一个 Object,代表一条记录 */
|
|
1627
|
+
data: Document.IDocumentData[]
|
|
1628
|
+
/** 调用结果 */
|
|
1629
|
+
errMsg: string
|
|
1630
|
+
}
|
|
1631
|
+
|
|
1632
|
+
interface IQuerySingleResult extends TaroGeneral.CallbackResult {
|
|
1633
|
+
data: Document.IDocumentData
|
|
1634
|
+
/** 调用结果 */
|
|
1635
|
+
errMsg: string
|
|
1636
|
+
}
|
|
1637
|
+
|
|
1638
|
+
interface IAddResult extends TaroGeneral.CallbackResult {
|
|
1639
|
+
_id: Document.DocumentId
|
|
1640
|
+
/** 调用结果 */
|
|
1641
|
+
errMsg: string
|
|
1642
|
+
}
|
|
1643
|
+
|
|
1644
|
+
interface IUpdateResult extends TaroGeneral.CallbackResult {
|
|
1645
|
+
stats: {
|
|
1646
|
+
updated: number
|
|
1647
|
+
// created: number
|
|
1648
|
+
}
|
|
1649
|
+
/** 调用结果 */
|
|
1650
|
+
errMsg: string
|
|
1651
|
+
}
|
|
1652
|
+
|
|
1653
|
+
interface ISetResult extends TaroGeneral.CallbackResult {
|
|
1654
|
+
_id: Document.DocumentId
|
|
1655
|
+
stats: {
|
|
1656
|
+
updated: number
|
|
1657
|
+
created: number
|
|
1658
|
+
}
|
|
1659
|
+
/** 调用结果 */
|
|
1660
|
+
errMsg: string
|
|
1661
|
+
}
|
|
1662
|
+
|
|
1663
|
+
interface IRemoveResult extends TaroGeneral.CallbackResult {
|
|
1664
|
+
stats: {
|
|
1665
|
+
removed: number,
|
|
1666
|
+
}
|
|
1667
|
+
/** 调用结果 */
|
|
1668
|
+
errMsg: string
|
|
1669
|
+
}
|
|
1670
|
+
|
|
1671
|
+
interface ICountResult extends TaroGeneral.CallbackResult {
|
|
1672
|
+
/** 结果数量 */
|
|
1673
|
+
total: number
|
|
1674
|
+
/** 调用结果 */
|
|
1675
|
+
errMsg: string
|
|
1676
|
+
}
|
|
1677
|
+
}
|
|
1678
|
+
|
|
1679
|
+
/** 数据库操作符,通过 db.command 获取
|
|
1680
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/Command.html
|
|
1681
|
+
*/
|
|
1682
|
+
interface Command {
|
|
1683
|
+
/** 查询筛选条件,表示字段等于某个值。eq 指令接受一个字面量 (literal),可以是 number, boolean, string, object, array, Date。
|
|
1684
|
+
* @supported weapp
|
|
1685
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/command/Command.eq.html
|
|
1686
|
+
*/
|
|
1687
|
+
eq(val: any): Command.DatabaseQueryCommand
|
|
1688
|
+
/** 查询筛选条件,表示字段不等于某个值。eq 指令接受一个字面量 (literal),可以是 number, boolean, string, object, array, Date。
|
|
1689
|
+
* @supported weapp
|
|
1690
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/command/Command.neq.html
|
|
1691
|
+
*/
|
|
1692
|
+
neq(val: any): Command.DatabaseQueryCommand
|
|
1693
|
+
/** 查询筛选操作符,表示需大于指定值。可以传入 Date 对象用于进行日期比较。
|
|
1694
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/command/Command.gt.html
|
|
1695
|
+
*/
|
|
1696
|
+
gt(val: any): Command.DatabaseQueryCommand
|
|
1697
|
+
/** 查询筛选操作符,表示需大于或等于指定值。可以传入 Date 对象用于进行日期比较。
|
|
1698
|
+
* @supported weapp
|
|
1699
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/command/Command.gte.html
|
|
1700
|
+
*/
|
|
1701
|
+
gte(val: any): Command.DatabaseQueryCommand
|
|
1702
|
+
/** 查询筛选操作符,表示需小于指定值。可以传入 Date 对象用于进行日期比较。
|
|
1703
|
+
* @supported weapp
|
|
1704
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/command/Command.lt.html
|
|
1705
|
+
*/
|
|
1706
|
+
lt(val: any): Command.DatabaseQueryCommand
|
|
1707
|
+
/** 查询筛选操作符,表示需小于或等于指定值。可以传入 Date 对象用于进行日期比较。
|
|
1708
|
+
* @supported weapp
|
|
1709
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/command/Command.lte.html
|
|
1710
|
+
*/
|
|
1711
|
+
lte(val: any): Command.DatabaseQueryCommand
|
|
1712
|
+
/** 查询筛选操作符,表示要求值在给定的数组内。
|
|
1713
|
+
* @supported weapp
|
|
1714
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/command/Command.in.html
|
|
1715
|
+
*/
|
|
1716
|
+
in(val: any[]): Command.DatabaseQueryCommand
|
|
1717
|
+
/** 查询筛选操作符,表示要求值不在给定的数组内。
|
|
1718
|
+
* @supported weapp
|
|
1719
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/command/Command.nin.html
|
|
1720
|
+
*/
|
|
1721
|
+
nin(val: any[]): Command.DatabaseQueryCommand
|
|
1722
|
+
|
|
1723
|
+
/** 按从近到远的顺序,找出字段值在给定点的附近的记录。
|
|
1724
|
+
* @supported weapp
|
|
1725
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/command/Command.geoNear.html
|
|
1726
|
+
*/
|
|
1727
|
+
geoNear(options: Command.NearCommandOptions): Command.DatabaseQueryCommand
|
|
1728
|
+
/** 找出字段值在指定区域内的记录,无排序。指定的区域必须是多边形(Polygon)或多边形集合(MultiPolygon)。
|
|
1729
|
+
* @supported weapp
|
|
1730
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/command/Command.geoWithin.html
|
|
1731
|
+
*/
|
|
1732
|
+
geoWithin(options: Command.WithinCommandOptions): Command.DatabaseQueryCommand
|
|
1733
|
+
/** 找出给定的地理位置图形相交的记录
|
|
1734
|
+
* @supported weapp
|
|
1735
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/command/Command.geoIntersects.html
|
|
1736
|
+
*/
|
|
1737
|
+
geoIntersects(
|
|
1738
|
+
options: Command.IntersectsCommandOptions,
|
|
1739
|
+
): Command.DatabaseQueryCommand
|
|
1740
|
+
|
|
1741
|
+
/** 查询操作符,用于表示逻辑 "与" 的关系,表示需同时满足多个查询筛选条件
|
|
1742
|
+
* @supported weapp
|
|
1743
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/command/Command.and.html
|
|
1744
|
+
*/
|
|
1745
|
+
and(
|
|
1746
|
+
...expressions: Array<Command.DatabaseLogicCommand | Query.IQueryCondition>
|
|
1747
|
+
): Command.DatabaseLogicCommand
|
|
1748
|
+
/** 查询操作符,用于表示逻辑 "或" 的关系,表示需同时满足多个查询筛选条件。或指令有两种用法,一是可以进行字段值的 “或” 操作,二是也可以进行跨字段的 “或” 操作。
|
|
1749
|
+
* @supported weapp
|
|
1750
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/command/Command.or.html
|
|
1751
|
+
*/
|
|
1752
|
+
or(
|
|
1753
|
+
...expressions: Array<Command.DatabaseLogicCommand | Query.IQueryCondition>
|
|
1754
|
+
): Command.DatabaseLogicCommand
|
|
1755
|
+
|
|
1756
|
+
/** 查询操作符,用于表示逻辑 "与" 的关系,表示需同时满足多个查询筛选条件
|
|
1757
|
+
* @supported weapp
|
|
1758
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/command/Command.set.html
|
|
1759
|
+
*/
|
|
1760
|
+
set(val: any): Command.DatabaseUpdateCommand
|
|
1761
|
+
/** 更新操作符,用于表示删除某个字段。
|
|
1762
|
+
* @supported weapp
|
|
1763
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/command/Command.remove.html
|
|
1764
|
+
*/
|
|
1765
|
+
remove(): Command.DatabaseUpdateCommand
|
|
1766
|
+
/** 更新操作符,原子操作,用于指示字段自增
|
|
1767
|
+
* @supported weapp
|
|
1768
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/command/Command.inc.html
|
|
1769
|
+
*/
|
|
1770
|
+
inc(val: number): Command.DatabaseUpdateCommand
|
|
1771
|
+
/** 更新操作符,原子操作,用于指示字段自乘某个值
|
|
1772
|
+
* @supported weapp
|
|
1773
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/command/Command.mul.html
|
|
1774
|
+
*/
|
|
1775
|
+
mul(val: number): Command.DatabaseUpdateCommand
|
|
1776
|
+
|
|
1777
|
+
/** 数组更新操作符。对一个值为数组的字段,往数组添加一个或多个值。或字段原为空,则创建该字段并设数组为传入值。
|
|
1778
|
+
* @supported weapp
|
|
1779
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/command/Command.push.html
|
|
1780
|
+
*/
|
|
1781
|
+
push(...values: any[]): Command.DatabaseUpdateCommand
|
|
1782
|
+
/** 数组更新操作符,对一个值为数组的字段,将数组尾部元素删除
|
|
1783
|
+
* @supported weapp
|
|
1784
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/command/Command.pop.html
|
|
1785
|
+
*/
|
|
1786
|
+
pop(): Command.DatabaseUpdateCommand
|
|
1787
|
+
/** 数组更新操作符,对一个值为数组的字段,将数组头部元素删除。
|
|
1788
|
+
* @supported weapp
|
|
1789
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/command/Command.shift.html
|
|
1790
|
+
*/
|
|
1791
|
+
shift(): Command.DatabaseUpdateCommand
|
|
1792
|
+
/** 数组更新操作符,对一个值为数组的字段,往数组头部添加一个或多个值。或字段原为空,则创建该字段并设数组为传入值。
|
|
1793
|
+
* @supported weapp
|
|
1794
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/command/Command.unshift.html
|
|
1795
|
+
*/
|
|
1796
|
+
unshift(...values: any[]): Command.DatabaseUpdateCommand
|
|
1797
|
+
}
|
|
1798
|
+
|
|
1799
|
+
namespace Command {
|
|
1800
|
+
/** 数据库逻辑操作符 */
|
|
1801
|
+
interface DatabaseLogicCommand {
|
|
1802
|
+
/** 作用域名称 */
|
|
1803
|
+
fieldName: string | Database.InternalSymbol
|
|
1804
|
+
/** 操作符 */
|
|
1805
|
+
operator: keyof LOGIC_COMMANDS_LITERAL | string
|
|
1806
|
+
/** 操作数 */
|
|
1807
|
+
operands: any[]
|
|
1808
|
+
|
|
1809
|
+
/** 设置作用域名称 */
|
|
1810
|
+
_setFieldName: (fieldName: string) => DatabaseLogicCommand
|
|
1811
|
+
|
|
1812
|
+
/** 查询操作符,用于表示逻辑 "与" 的关系,表示需同时满足多个查询筛选条件
|
|
1813
|
+
* @supported weapp
|
|
1814
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/command/Command.and.html
|
|
1815
|
+
*/
|
|
1816
|
+
and(
|
|
1817
|
+
...expressions: Array<DatabaseLogicCommand | Query.IQueryCondition>
|
|
1818
|
+
): DatabaseLogicCommand
|
|
1819
|
+
/** 查询操作符,用于表示逻辑 "或" 的关系,表示需同时满足多个查询筛选条件。或指令有两种用法,一是可以进行字段值的 “或” 操作,二是也可以进行跨字段的 “或” 操作。
|
|
1820
|
+
* @supported weapp
|
|
1821
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/command/Command.or.html
|
|
1822
|
+
*/
|
|
1823
|
+
or(
|
|
1824
|
+
...expressions: Array<DatabaseLogicCommand | Query.IQueryCondition>
|
|
1825
|
+
): DatabaseLogicCommand
|
|
1826
|
+
}
|
|
1827
|
+
|
|
1828
|
+
/** 数据库查询操作符 */
|
|
1829
|
+
interface DatabaseQueryCommand extends DatabaseLogicCommand {
|
|
1830
|
+
/** 操作符 */
|
|
1831
|
+
operator: keyof QUERY_COMMANDS_LITERAL | string
|
|
1832
|
+
|
|
1833
|
+
/** 设置作用域名称 */
|
|
1834
|
+
_setFieldName: (fieldName: string) => DatabaseQueryCommand
|
|
1835
|
+
|
|
1836
|
+
/** 查询筛选条件,表示字段等于某个值。eq 指令接受一个字面量 (literal),可以是 number, boolean, string, object, array, Date。
|
|
1837
|
+
* @supported weapp
|
|
1838
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/command/Command.eq.html
|
|
1839
|
+
*/
|
|
1840
|
+
eq(val: any): DatabaseLogicCommand
|
|
1841
|
+
/** 查询筛选条件,表示字段不等于某个值。eq 指令接受一个字面量 (literal),可以是 number, boolean, string, object, array, Date。
|
|
1842
|
+
* @supported weapp
|
|
1843
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/command/Command.neq.html
|
|
1844
|
+
*/
|
|
1845
|
+
neq(val: any): DatabaseLogicCommand
|
|
1846
|
+
/** 查询筛选操作符,表示需大于指定值。可以传入 Date 对象用于进行日期比较。
|
|
1847
|
+
* @supported weapp
|
|
1848
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/command/Command.gt.html
|
|
1849
|
+
*/
|
|
1850
|
+
gt(val: any): DatabaseLogicCommand
|
|
1851
|
+
/** 查询筛选操作符,表示需大于或等于指定值。可以传入 Date 对象用于进行日期比较。
|
|
1852
|
+
* @supported weapp
|
|
1853
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/command/Command.gte.html
|
|
1854
|
+
*/
|
|
1855
|
+
gte(val: any): DatabaseLogicCommand
|
|
1856
|
+
/** 查询筛选操作符,表示需小于指定值。可以传入 Date 对象用于进行日期比较。
|
|
1857
|
+
* @supported weapp
|
|
1858
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/command/Command.lt.html
|
|
1859
|
+
*/
|
|
1860
|
+
lt(val: any): DatabaseLogicCommand
|
|
1861
|
+
/** 查询筛选操作符,表示需小于或等于指定值。可以传入 Date 对象用于进行日期比较。
|
|
1862
|
+
* @supported weapp
|
|
1863
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/command/Command.lte.html
|
|
1864
|
+
*/
|
|
1865
|
+
lte(val: any): DatabaseLogicCommand
|
|
1866
|
+
/** 查询筛选操作符,表示要求值在给定的数组内。
|
|
1867
|
+
* @supported weapp
|
|
1868
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/command/Command.in.html
|
|
1869
|
+
*/
|
|
1870
|
+
in(val: any[]): DatabaseLogicCommand
|
|
1871
|
+
/** 查询筛选操作符,表示要求值不在给定的数组内。
|
|
1872
|
+
* @supported weapp
|
|
1873
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/command/Command.nin.html
|
|
1874
|
+
*/
|
|
1875
|
+
nin(val: any[]): DatabaseLogicCommand
|
|
1876
|
+
|
|
1877
|
+
/** 按从近到远的顺序,找出字段值在给定点的附近的记录。
|
|
1878
|
+
* @supported weapp
|
|
1879
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/command/Command.geoNear.html
|
|
1880
|
+
*/
|
|
1881
|
+
geoNear(options: NearCommandOptions): DatabaseLogicCommand
|
|
1882
|
+
/** 找出字段值在指定区域内的记录,无排序。指定的区域必须是多边形(Polygon)或多边形集合(MultiPolygon)。
|
|
1883
|
+
* @supported weapp
|
|
1884
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/command/Command.geoWithin.html
|
|
1885
|
+
*/
|
|
1886
|
+
geoWithin(options: WithinCommandOptions): DatabaseLogicCommand
|
|
1887
|
+
/** 找出给定的地理位置图形相交的记录
|
|
1888
|
+
* @supported weapp
|
|
1889
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/command/Command.geoIntersects.html
|
|
1890
|
+
*/
|
|
1891
|
+
geoIntersects(
|
|
1892
|
+
options: IntersectsCommandOptions,
|
|
1893
|
+
): DatabaseLogicCommand
|
|
1894
|
+
}
|
|
1895
|
+
|
|
1896
|
+
/** 数据库更新操作符 */
|
|
1897
|
+
interface DatabaseUpdateCommand {
|
|
1898
|
+
/** 作用域名称 */
|
|
1899
|
+
fieldName: string | Database.InternalSymbol
|
|
1900
|
+
/** 操作符 */
|
|
1901
|
+
operator: keyof UPDATE_COMMANDS_LITERAL
|
|
1902
|
+
/** 操作数 */
|
|
1903
|
+
operands: any[]
|
|
1904
|
+
|
|
1905
|
+
/** 设置作用域名称 */
|
|
1906
|
+
_setFieldName: (fieldName: string) => DatabaseUpdateCommand
|
|
1907
|
+
}
|
|
1908
|
+
|
|
1909
|
+
/** 逻辑命令字面量 */
|
|
1910
|
+
interface LOGIC_COMMANDS_LITERAL {
|
|
1911
|
+
/** 与 */
|
|
1912
|
+
and: any
|
|
1913
|
+
/** 或 */
|
|
1914
|
+
or: any
|
|
1915
|
+
/** 非 */
|
|
1916
|
+
not: any
|
|
1917
|
+
/** 都不 */
|
|
1918
|
+
nor: any
|
|
1919
|
+
}
|
|
1920
|
+
|
|
1921
|
+
/** 查询命令字面量 */
|
|
1922
|
+
interface QUERY_COMMANDS_LITERAL {
|
|
1923
|
+
// normal
|
|
1924
|
+
/** 等于 */
|
|
1925
|
+
eq: any
|
|
1926
|
+
/** 不等于 */
|
|
1927
|
+
neq: any
|
|
1928
|
+
/** 大于 */
|
|
1929
|
+
gt: any
|
|
1930
|
+
/** 大于等于 */
|
|
1931
|
+
gte: any
|
|
1932
|
+
/** 小于 */
|
|
1933
|
+
lt: any
|
|
1934
|
+
/** 小于等于 */
|
|
1935
|
+
lte: any
|
|
1936
|
+
/** 范围内 */
|
|
1937
|
+
in: any
|
|
1938
|
+
/** 范围外 */
|
|
1939
|
+
nin: any
|
|
1940
|
+
|
|
1941
|
+
// geo
|
|
1942
|
+
/** 附近排序 */
|
|
1943
|
+
geoNear: any
|
|
1944
|
+
/** 指定区域内 */
|
|
1945
|
+
geoWithin: any
|
|
1946
|
+
/** 相交区域 */
|
|
1947
|
+
geoIntersects: any
|
|
1948
|
+
}
|
|
1949
|
+
|
|
1950
|
+
/** 更新命令字面量 */
|
|
1951
|
+
interface UPDATE_COMMANDS_LITERAL {
|
|
1952
|
+
/** 等于 */
|
|
1953
|
+
set: any
|
|
1954
|
+
/** 删除 */
|
|
1955
|
+
remove: any
|
|
1956
|
+
/** 自增 */
|
|
1957
|
+
inc: any
|
|
1958
|
+
/** 自乘 */
|
|
1959
|
+
mul: any
|
|
1960
|
+
/** 尾部添加 */
|
|
1961
|
+
push: any
|
|
1962
|
+
/** 尾部删除 */
|
|
1963
|
+
pop: any
|
|
1964
|
+
/** 头部删除 */
|
|
1965
|
+
shift: any
|
|
1966
|
+
/** 头部添加 */
|
|
1967
|
+
unshift: any
|
|
1968
|
+
}
|
|
1969
|
+
|
|
1970
|
+
/** 按从近到远的顺序,找出字段值在给定点的附近的记录参数 */
|
|
1971
|
+
interface NearCommandOptions {
|
|
1972
|
+
/** 地理位置点 (Point) */
|
|
1973
|
+
geometry: IGeo.GeoPoint
|
|
1974
|
+
/** 最大距离,单位为米 */
|
|
1975
|
+
maxDistance?: number
|
|
1976
|
+
/** 最小距离,单位为米 */
|
|
1977
|
+
minDistance?: number
|
|
1978
|
+
}
|
|
1979
|
+
|
|
1980
|
+
/** 找出字段值在指定区域内的记录,无排序参数 */
|
|
1981
|
+
interface WithinCommandOptions {
|
|
1982
|
+
/** 地理信息结构,Polygon,MultiPolygon,或 { centerSphere } */
|
|
1983
|
+
geometry: IGeo.GeoPolygon | IGeo.GeoMultiPolygon
|
|
1984
|
+
}
|
|
1985
|
+
|
|
1986
|
+
/** 找出给定的地理位置图形相交的记录 */
|
|
1987
|
+
interface IntersectsCommandOptions {
|
|
1988
|
+
/** 地理信息结构 */
|
|
1989
|
+
geometry:
|
|
1990
|
+
| IGeo.GeoPoint
|
|
1991
|
+
| IGeo.GeoMultiPoint
|
|
1992
|
+
| IGeo.GeoLineString
|
|
1993
|
+
| IGeo.GeoMultiLineString
|
|
1994
|
+
| IGeo.GeoPolygon
|
|
1995
|
+
| IGeo.GeoMultiPolygon
|
|
1996
|
+
}
|
|
1997
|
+
}
|
|
1998
|
+
|
|
1999
|
+
/** 数据库集合的聚合操作实例
|
|
2000
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/aggregate/Aggregate.html
|
|
2001
|
+
*/
|
|
2002
|
+
interface Aggregate {
|
|
2003
|
+
/** 聚合阶段。添加新字段到输出的记录。经过 addFields 聚合阶段,输出的所有记录中除了输入时带有的字段外,还将带有 addFields 指定的字段。
|
|
2004
|
+
* @supported weapp
|
|
2005
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/aggregate/Aggregate.addFields.html
|
|
2006
|
+
*/
|
|
2007
|
+
addFields(object: Object): Aggregate
|
|
2008
|
+
|
|
2009
|
+
/** 聚合阶段。将输入记录根据给定的条件和边界划分成不同的组,每组即一个 bucket。
|
|
2010
|
+
* @supported weapp
|
|
2011
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/aggregate/Aggregate.bucket.html
|
|
2012
|
+
*/
|
|
2013
|
+
bucket(object: Object): Aggregate
|
|
2014
|
+
|
|
2015
|
+
/** 聚合阶段。将输入记录根据给定的条件划分成不同的组,每组即一个 bucket。与 bucket 的其中一个不同之处在于无需指定 boundaries,bucketAuto 会自动尝试将记录尽可能平均的分散到每组中。
|
|
2016
|
+
* @supported weapp
|
|
2017
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/aggregate/Aggregate.bucketAuto.html
|
|
2018
|
+
*/
|
|
2019
|
+
bucketAuto(object: Object): Aggregate
|
|
2020
|
+
|
|
2021
|
+
/** 聚合阶段。计算上一聚合阶段输入到本阶段的记录数,输出一个记录,其中指定字段的值为记录数。
|
|
2022
|
+
* @supported weapp
|
|
2023
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/aggregate/Aggregate.count.html
|
|
2024
|
+
*/
|
|
2025
|
+
count(fieldName: string): Aggregate
|
|
2026
|
+
|
|
2027
|
+
/** 标志聚合操作定义完成,发起实际聚合操作
|
|
2028
|
+
* @supported weapp
|
|
2029
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/aggregate/Aggregate.end.html
|
|
2030
|
+
*/
|
|
2031
|
+
end(): Promise<Object>
|
|
2032
|
+
|
|
2033
|
+
/** 聚合阶段。将记录按照离给定点从近到远输出。
|
|
2034
|
+
* @supported weapp
|
|
2035
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/aggregate/Aggregate.geoNear.html
|
|
2036
|
+
*/
|
|
2037
|
+
geoNear(options: Object): Aggregate
|
|
2038
|
+
|
|
2039
|
+
/** 聚合阶段。将输入记录按给定表达式分组,输出时每个记录代表一个分组,每个记录的 _id 是区分不同组的 key。输出记录中也可以包括累计值,将输出字段设为累计值即会从该分组中计算累计值。
|
|
2040
|
+
* @supported weapp
|
|
2041
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/aggregate/Aggregate.group.html
|
|
2042
|
+
*/
|
|
2043
|
+
group(object: Object): Aggregate
|
|
2044
|
+
|
|
2045
|
+
/** 聚合阶段。限制输出到下一阶段的记录数。
|
|
2046
|
+
* @supported weapp
|
|
2047
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/aggregate/Aggregate.limit.html
|
|
2048
|
+
*/
|
|
2049
|
+
limit(value: number): Aggregate
|
|
2050
|
+
|
|
2051
|
+
/** 聚合阶段。聚合阶段。联表查询。与同个数据库下的一个指定的集合做 left outer join(左外连接)。对该阶段的每一个输入记录,lookup 会在该记录中增加一个数组字段,该数组是被联表中满足匹配条件的记录列表。lookup 会将连接后的结果输出给下个阶段。
|
|
2052
|
+
* @supported weapp
|
|
2053
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/aggregate/Aggregate.lookup.html
|
|
2054
|
+
*/
|
|
2055
|
+
lookup(object: Object): Aggregate
|
|
2056
|
+
|
|
2057
|
+
/** 聚合阶段。根据条件过滤文档,并且把符合条件的文档传递给下一个流水线阶段。
|
|
2058
|
+
* @supported weapp
|
|
2059
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/aggregate/Aggregate.match.html
|
|
2060
|
+
*/
|
|
2061
|
+
match(object: Object): Aggregate
|
|
2062
|
+
|
|
2063
|
+
/** 聚合阶段。把指定的字段传递给下一个流水线,指定的字段可以是某个已经存在的字段,也可以是计算出来的新字段。
|
|
2064
|
+
* @supported weapp
|
|
2065
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/aggregate/Aggregate.project.html
|
|
2066
|
+
*/
|
|
2067
|
+
project(object: Object): Aggregate
|
|
2068
|
+
|
|
2069
|
+
/** 聚合阶段。指定一个已有字段作为输出的根节点,也可以指定一个计算出的新字段作为根节点。
|
|
2070
|
+
* @supported weapp
|
|
2071
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/aggregate/Aggregate.replaceRoot.html
|
|
2072
|
+
*/
|
|
2073
|
+
replaceRoot(object: Object): Aggregate
|
|
2074
|
+
|
|
2075
|
+
/** 聚合阶段。随机从文档中选取指定数量的记录。
|
|
2076
|
+
* @supported weapp
|
|
2077
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/aggregate/Aggregate.sample.html
|
|
2078
|
+
*/
|
|
2079
|
+
sample(size: number): Aggregate
|
|
2080
|
+
|
|
2081
|
+
/** 聚合阶段。指定一个正整数,跳过对应数量的文档,输出剩下的文档。
|
|
2082
|
+
* @supported weapp
|
|
2083
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/aggregate/Aggregate.skip.html
|
|
2084
|
+
*/
|
|
2085
|
+
skip(value: number): Aggregate
|
|
2086
|
+
|
|
2087
|
+
/** 聚合阶段。根据指定的字段,对输入的文档进行排序。
|
|
2088
|
+
* @supported weapp
|
|
2089
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/aggregate/Aggregate.sort.html
|
|
2090
|
+
*/
|
|
2091
|
+
sort(object: Object): Aggregate
|
|
2092
|
+
|
|
2093
|
+
/** 聚合阶段。根据传入的表达式,将传入的集合进行分组(group)。然后计算不同组的数量,并且将这些组按照它们的数量进行排序,返回排序后的结果。
|
|
2094
|
+
* @supported weapp
|
|
2095
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/aggregate/Aggregate.sortByCount.html
|
|
2096
|
+
*/
|
|
2097
|
+
sortByCount(object: Object): Aggregate
|
|
2098
|
+
|
|
2099
|
+
/** 聚合阶段。使用指定的数组字段中的每个元素,对文档进行拆分。拆分后,文档会从一个变为一个或多个,分别对应数组的每个元素。
|
|
2100
|
+
* @supported weapp
|
|
2101
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/aggregate/Aggregate.unwind.html
|
|
2102
|
+
*/
|
|
2103
|
+
unwind(value: string|object): Aggregate
|
|
2104
|
+
}
|
|
2105
|
+
|
|
2106
|
+
/** 数据库地理位置结构集
|
|
2107
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/Geo.html
|
|
2108
|
+
*/
|
|
2109
|
+
interface IGeo {
|
|
2110
|
+
/** 构造一个地理位置 ”点“。方法接受两个必填参数,第一个是经度(longitude),第二个是纬度(latitude),务必注意顺序。
|
|
2111
|
+
*
|
|
2112
|
+
* 如存储地理位置信息的字段有被查询的需求,务必对字段建立地理位置索引
|
|
2113
|
+
* @supported weapp
|
|
2114
|
+
* @example
|
|
2115
|
+
* ```tsx
|
|
2116
|
+
* db.collection('todos').add({
|
|
2117
|
+
* data: {
|
|
2118
|
+
* description: 'eat an apple',
|
|
2119
|
+
* location: db.Geo.Point(113, 23)
|
|
2120
|
+
* }
|
|
2121
|
+
* }).then(console.log).catch(console.error)
|
|
2122
|
+
* ```
|
|
2123
|
+
* @example
|
|
2124
|
+
* 除了使用接口构造一个点外,也可以使用等价的 GeoJSON 的 点 (Point) 的 JSON 表示,其格式如下:
|
|
2125
|
+
*
|
|
2126
|
+
* ```json
|
|
2127
|
+
* {
|
|
2128
|
+
* "type": "Point",
|
|
2129
|
+
* "coordinates": [longitude, latitude] // 数字数组:[经度, 纬度]
|
|
2130
|
+
* }
|
|
2131
|
+
* ```
|
|
2132
|
+
*
|
|
2133
|
+
* ```tsx
|
|
2134
|
+
* db.collection('todos').add({
|
|
2135
|
+
* data: {
|
|
2136
|
+
* description: 'eat an apple',
|
|
2137
|
+
* location: {
|
|
2138
|
+
* type: 'Point',
|
|
2139
|
+
* coordinates: [113, 23]
|
|
2140
|
+
* }
|
|
2141
|
+
* }
|
|
2142
|
+
* }).then(console.log).catch(console.error)
|
|
2143
|
+
* ```
|
|
2144
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/geo/Geo.Point.html
|
|
2145
|
+
*/
|
|
2146
|
+
Point(longitude: number, latitide: number): IGeo.GeoPoint
|
|
2147
|
+
// Point(geojson: IGeo.JSONPoint): IGeo.GeoPoint
|
|
2148
|
+
|
|
2149
|
+
/** 构造一个地理位置的 ”线“。一个线由两个或更多的点有序连接组成。
|
|
2150
|
+
*
|
|
2151
|
+
* 如存储地理位置信息的字段有被查询的需求,务必对字段建立地理位置索引
|
|
2152
|
+
* @supported weapp
|
|
2153
|
+
* @example
|
|
2154
|
+
* ```tsx
|
|
2155
|
+
* db.collection('todos').add({
|
|
2156
|
+
* data: {
|
|
2157
|
+
* description: 'eat an apple',
|
|
2158
|
+
* location: db.Geo.LineString([
|
|
2159
|
+
* db.Geo.Point(113, 23),
|
|
2160
|
+
* db.Geo.Point(120, 50),
|
|
2161
|
+
* // ... 可选更多点
|
|
2162
|
+
* ])
|
|
2163
|
+
* }
|
|
2164
|
+
* }).then(console.log).catch(console.error)
|
|
2165
|
+
* ```
|
|
2166
|
+
* @example
|
|
2167
|
+
* 除了使用接口构造一条 LineString 外,也可以使用等价的 GeoJSON 的 线 (LineString) 的 JSON 表示,其格式如下:
|
|
2168
|
+
*
|
|
2169
|
+
* ```json
|
|
2170
|
+
* {
|
|
2171
|
+
* "type": "LineString",
|
|
2172
|
+
* "coordinates": [
|
|
2173
|
+
* [p1_lng, p1_lat],
|
|
2174
|
+
* [p2_lng, p2_lng]
|
|
2175
|
+
* // ... 可选更多点
|
|
2176
|
+
* ]
|
|
2177
|
+
* }
|
|
2178
|
+
* ```
|
|
2179
|
+
*
|
|
2180
|
+
* ```tsx
|
|
2181
|
+
* db.collection('todos').add({
|
|
2182
|
+
* data: {
|
|
2183
|
+
* description: 'eat an apple',
|
|
2184
|
+
* location: {
|
|
2185
|
+
* type: 'LineString',
|
|
2186
|
+
* coordinates: [
|
|
2187
|
+
* [113, 23],
|
|
2188
|
+
* [120, 50]
|
|
2189
|
+
* ]
|
|
2190
|
+
* }
|
|
2191
|
+
* }
|
|
2192
|
+
* }).then(console.log).catch(console.error)
|
|
2193
|
+
* ```
|
|
2194
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/geo/Geo.LineString.html
|
|
2195
|
+
*/
|
|
2196
|
+
LineString(points: IGeo.GeoPoint[] | IGeo.JSONMultiPoint): IGeo.GeoMultiPoint
|
|
2197
|
+
|
|
2198
|
+
/** 构造一个地理位置 ”多边形“
|
|
2199
|
+
*
|
|
2200
|
+
* 如存储地理位置信息的字段有被查询的需求,务必对字段建立地理位置索引
|
|
2201
|
+
*
|
|
2202
|
+
* **说明**
|
|
2203
|
+
*
|
|
2204
|
+
* 一个多边形由一个或多个线性环(Linear Ring)组成,一个线性环即一个闭合的线段。一个闭合线段至少由四个点组成,其中最后一个点和第一个点的坐标必须相同,以此表示环的起点和终点。如果一个多边形由多个线性环组成,则第一个线性环表示外环(外边界),接下来的所有线性环表示内环(即外环中的洞,不计在此多边形中的区域)。如果一个多边形只有一个线性环组成,则这个环就是外环。
|
|
2205
|
+
*
|
|
2206
|
+
* 多边形构造规则:
|
|
2207
|
+
*
|
|
2208
|
+
* 1. 第一个线性环必须是外环
|
|
2209
|
+
* 2. 外环不能自交
|
|
2210
|
+
* 3. 所有内环必须完全在外环内
|
|
2211
|
+
* 4. 各个内环间不能相交或重叠,也不能有共同的边
|
|
2212
|
+
* 5. 外环应为逆时针,内环应为顺时针
|
|
2213
|
+
* @supported weapp
|
|
2214
|
+
* @example
|
|
2215
|
+
* 单环多边形
|
|
2216
|
+
*
|
|
2217
|
+
* ```tsx
|
|
2218
|
+
* const { Polygon, LineString, Point } = db.Geo
|
|
2219
|
+
* db.collection('todos').add({
|
|
2220
|
+
* data: {
|
|
2221
|
+
* description: 'eat an apple',
|
|
2222
|
+
* location: Polygon([
|
|
2223
|
+
* LineString([
|
|
2224
|
+
* Point(0, 0),
|
|
2225
|
+
* Point(3, 2),
|
|
2226
|
+
* Point(2, 3),
|
|
2227
|
+
* Point(0, 0)
|
|
2228
|
+
* ])
|
|
2229
|
+
* ])
|
|
2230
|
+
* }
|
|
2231
|
+
* }).then(console.log).catch(console.error)
|
|
2232
|
+
* ```
|
|
2233
|
+
* @example
|
|
2234
|
+
* 含一个外环和一个内环的多边形
|
|
2235
|
+
*
|
|
2236
|
+
* ```tsx
|
|
2237
|
+
* const { Polygon, LineString, Point } = db.Geo
|
|
2238
|
+
* db.collection('todos').add({
|
|
2239
|
+
* data: {
|
|
2240
|
+
* description: 'eat an apple',
|
|
2241
|
+
* location: Polygon([
|
|
2242
|
+
* // 外环
|
|
2243
|
+
* LineString([ Point(0, 0), Point(30, 20), Point(20, 30), Point(0, 0) ]),
|
|
2244
|
+
* // 内环
|
|
2245
|
+
* LineString([ Point(10, 10), Point(16, 14), Point(14, 16), Point(10, 10) ])
|
|
2246
|
+
* ])
|
|
2247
|
+
* }
|
|
2248
|
+
* }).then(console.log).catch(console.error)
|
|
2249
|
+
* ```
|
|
2250
|
+
* @example
|
|
2251
|
+
* 除了使用接口构造一个 Polygon 外,也可以使用等价的 GeoJSON 的 多边形 (Polygon) 的 JSON 表示,其格式如下:
|
|
2252
|
+
*
|
|
2253
|
+
* ```json
|
|
2254
|
+
* {
|
|
2255
|
+
* "type": "Polygon",
|
|
2256
|
+
* "coordinates": [
|
|
2257
|
+
* [ [lng, lat], [lng, lat], [lng, lat], ..., [lng, lat] ], // 外环
|
|
2258
|
+
* [ [lng, lat], [lng, lat], [lng, lat], ..., [lng, lat] ], // 可选内环 1
|
|
2259
|
+
* ...
|
|
2260
|
+
* [ [lng, lat], [lng, lat], [lng, lat], ..., [lng, lat] ], // 可选内环 n
|
|
2261
|
+
* ]
|
|
2262
|
+
* }
|
|
2263
|
+
* ```
|
|
2264
|
+
*
|
|
2265
|
+
* ```tsx
|
|
2266
|
+
* db.collection('todos').add({
|
|
2267
|
+
* data: {
|
|
2268
|
+
* description: 'eat an apple',
|
|
2269
|
+
* location: {
|
|
2270
|
+
* type: 'Polygon',
|
|
2271
|
+
* coordinates: [
|
|
2272
|
+
* [ [0, 0], [30, 20], [20, 30], [0, 0] ],
|
|
2273
|
+
* [ [10, 10], [16, 14], [14, 16], [10, 10]]
|
|
2274
|
+
* ]
|
|
2275
|
+
* }
|
|
2276
|
+
* }
|
|
2277
|
+
* }).then(console.log).catch(console.error)
|
|
2278
|
+
* ```
|
|
2279
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/geo/Geo.Polygon.html
|
|
2280
|
+
*/
|
|
2281
|
+
Polygon(lineStrings: IGeo.GeoLineString[] | IGeo.JSONPolygon): IGeo.GeoPolygon
|
|
2282
|
+
|
|
2283
|
+
/** 构造一个地理位置的 ”点“ 的集合。一个点集合由一个或更多的点组成。
|
|
2284
|
+
*
|
|
2285
|
+
* 如存储地理位置信息的字段有被查询的需求,务必对字段建立地理位置索引
|
|
2286
|
+
* @supported weapp
|
|
2287
|
+
* @example
|
|
2288
|
+
* ```tsx
|
|
2289
|
+
* db.collection('todos').add({
|
|
2290
|
+
* data: {
|
|
2291
|
+
* description: 'eat an apple',
|
|
2292
|
+
* location: db.Geo.MultiPoint([
|
|
2293
|
+
* db.Geo.Point(113, 23),
|
|
2294
|
+
* db.Geo.Point(120, 50),
|
|
2295
|
+
* // ... 可选更多点
|
|
2296
|
+
* ])
|
|
2297
|
+
* }
|
|
2298
|
+
* }).then(console.log).catch(console.error)
|
|
2299
|
+
* ```
|
|
2300
|
+
* @example
|
|
2301
|
+
* 除了使用接口构造 MultiPoint 外,也可以使用等价的 GeoJSON 的 点集合 (MultiPoint) 的 JSON 表示,其格式如下:
|
|
2302
|
+
*
|
|
2303
|
+
* ```json
|
|
2304
|
+
* {
|
|
2305
|
+
* "type": "MultiPoint",
|
|
2306
|
+
* "coordinates": [
|
|
2307
|
+
* [p1_lng, p1_lat],
|
|
2308
|
+
* [p2_lng, p2_lng]
|
|
2309
|
+
* // ... 可选更多点
|
|
2310
|
+
* ]
|
|
2311
|
+
* }
|
|
2312
|
+
* ```
|
|
2313
|
+
*
|
|
2314
|
+
* ```tsx
|
|
2315
|
+
* db.collection('todos').add({
|
|
2316
|
+
* data: {
|
|
2317
|
+
* description: 'eat an apple',
|
|
2318
|
+
* location: {
|
|
2319
|
+
* type: 'MultiPoint',
|
|
2320
|
+
* coordinates: [
|
|
2321
|
+
* [113, 23],
|
|
2322
|
+
* [120, 50]
|
|
2323
|
+
* ]
|
|
2324
|
+
* }
|
|
2325
|
+
* }
|
|
2326
|
+
* }).then(console.log).catch(console.error)
|
|
2327
|
+
* ```
|
|
2328
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/geo/Geo.MultiPoint.html
|
|
2329
|
+
*/
|
|
2330
|
+
MultiPoint(polygons: IGeo.GeoPolygon[] | IGeo.JSONMultiPolygon): IGeo.GeoMultiPolygon
|
|
2331
|
+
|
|
2332
|
+
/** 构造一个地理位置 ”线“ 集合。一个线集合由多条线组成。
|
|
2333
|
+
*
|
|
2334
|
+
* 如存储地理位置信息的字段有被查询的需求,务必对字段建立地理位置索引
|
|
2335
|
+
* @supported weapp
|
|
2336
|
+
* @example
|
|
2337
|
+
* ```tsx
|
|
2338
|
+
* const { LineString, MultiLineString, Point } = db.Geo
|
|
2339
|
+
* db.collection('todos').add({
|
|
2340
|
+
* data: {
|
|
2341
|
+
* description: 'eat an apple',
|
|
2342
|
+
* location: MultiLineString([
|
|
2343
|
+
* LineString([ Point(0, 0), Point(30, 20), Point(20, 30), Point(0, 0) ]),
|
|
2344
|
+
* LineString([ Point(10, 10), Point(16, 14), Point(14, 16), Point(10, 10) ])
|
|
2345
|
+
* ])
|
|
2346
|
+
* }
|
|
2347
|
+
* }).then(console.log).catch(console.error)
|
|
2348
|
+
* ```
|
|
2349
|
+
* @example
|
|
2350
|
+
* 除了使用接口构造一个 MultiLineString 外,也可以使用等价的 GeoJSON 的 线集合 (MultiLineString) 的 JSON 表示,其格式如下:
|
|
2351
|
+
*
|
|
2352
|
+
* ```json
|
|
2353
|
+
* {
|
|
2354
|
+
* "type": "MultiLineString",
|
|
2355
|
+
* "coordinates": [
|
|
2356
|
+
* [ [lng, lat], [lng, lat], [lng, lat], ..., [lng, lat] ],
|
|
2357
|
+
* [ [lng, lat], [lng, lat], [lng, lat], ..., [lng, lat] ],
|
|
2358
|
+
* ...
|
|
2359
|
+
* [ [lng, lat], [lng, lat], [lng, lat], ..., [lng, lat] ]
|
|
2360
|
+
* ]
|
|
2361
|
+
* }
|
|
2362
|
+
* ```
|
|
2363
|
+
*
|
|
2364
|
+
* ```tsx
|
|
2365
|
+
* db.collection('todos').add({
|
|
2366
|
+
* data: {
|
|
2367
|
+
* description: 'eat an apple',
|
|
2368
|
+
* location: {
|
|
2369
|
+
* type: 'MultiLineString',
|
|
2370
|
+
* coordinates: [
|
|
2371
|
+
* [ [0, 0], [3, 3] ],
|
|
2372
|
+
* [ [5, 10], [20, 30] ]
|
|
2373
|
+
* ]
|
|
2374
|
+
* }
|
|
2375
|
+
* }
|
|
2376
|
+
* }).then(console.log).catch(console.error)
|
|
2377
|
+
* ```
|
|
2378
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/geo/Geo.MultiLineString.html
|
|
2379
|
+
*/
|
|
2380
|
+
MultiLineString(
|
|
2381
|
+
lineStrings: IGeo.GeoLineString[] | IGeo.JSONMultiLineString,
|
|
2382
|
+
): IGeo.GeoMultiLineString
|
|
2383
|
+
|
|
2384
|
+
/** 构造一个地理位置 ”多边形“ 集合。一个多边形集合由多个多边形组成。
|
|
2385
|
+
*
|
|
2386
|
+
* 如存储地理位置信息的字段有被查询的需求,务必对字段建立地理位置索引
|
|
2387
|
+
*
|
|
2388
|
+
* **说明**
|
|
2389
|
+
*
|
|
2390
|
+
* 一个多边形由一个或多个线性环(Linear Ring)组成,一个线性环即一个闭合的线段。一个闭合线段至少由四个点组成,其中最后一个点和第一个点的坐标必须相同,以此表示环的起点和终点。如果一个多边形由多个线性环组成,则第一个线性环表示外环(外边界),接下来的所有线性环表示内环(即外环中的洞,不计在此多边形中的区域)。如果一个多边形只有一个线性环组成,则这个环就是外环。
|
|
2391
|
+
*
|
|
2392
|
+
* 多边形构造规则:
|
|
2393
|
+
*
|
|
2394
|
+
* 1. 第一个线性环必须是外环
|
|
2395
|
+
* 2. 外环不能自交
|
|
2396
|
+
* 3. 所有内环必须完全在外环内
|
|
2397
|
+
* 4. 各个内环间不能相交或重叠,也不能有共同的边
|
|
2398
|
+
* 5. 外环应为逆时针,内环应为顺时针
|
|
2399
|
+
* @supported weapp
|
|
2400
|
+
* @example
|
|
2401
|
+
* ```tsx
|
|
2402
|
+
* const { MultiPolygon, Polygon, LineString, Point } = db.Geo
|
|
2403
|
+
* db.collection('todos').add({
|
|
2404
|
+
* data: {
|
|
2405
|
+
* description: 'eat an apple',
|
|
2406
|
+
* location: MultiPolygon([
|
|
2407
|
+
* Polygon([
|
|
2408
|
+
* LineString([ Point(50, 50), Point(60, 80), Point(80, 60), Point(50, 50) ]),
|
|
2409
|
+
* ]),
|
|
2410
|
+
* Polygon([
|
|
2411
|
+
* LineString([ Point(0, 0), Point(30, 20), Point(20, 30), Point(0, 0) ]),
|
|
2412
|
+
* LineString([ Point(10, 10), Point(16, 14), Point(14, 16), Point(10, 10) ])
|
|
2413
|
+
* ]),
|
|
2414
|
+
* ])
|
|
2415
|
+
* }
|
|
2416
|
+
* }).then(console.log).catch(console.error)
|
|
2417
|
+
* ```
|
|
2418
|
+
* @example
|
|
2419
|
+
* 除了使用接口构造一个 MultiPolygon 外,也可以使用等价的 GeoJSON 的 多边形 (MultiPolygon) 的 JSON 表示,其格式如下:
|
|
2420
|
+
*
|
|
2421
|
+
* ```json
|
|
2422
|
+
* {
|
|
2423
|
+
* "type": "MultiPolygon",
|
|
2424
|
+
* "coordinates": [
|
|
2425
|
+
* // polygon 1
|
|
2426
|
+
* [
|
|
2427
|
+
* [ [lng, lat], [lng, lat], [lng, lat], ..., [lng, lat] ],
|
|
2428
|
+
* [ [lng, lat], [lng, lat], [lng, lat], ..., [lng, lat] ],
|
|
2429
|
+
* ...
|
|
2430
|
+
* [ [lng, lat], [lng, lat], [lng, lat], ..., [lng, lat] ]
|
|
2431
|
+
* ],
|
|
2432
|
+
* ...
|
|
2433
|
+
* // polygon n
|
|
2434
|
+
* [
|
|
2435
|
+
* [ [lng, lat], [lng, lat], [lng, lat], ..., [lng, lat] ],
|
|
2436
|
+
* [ [lng, lat], [lng, lat], [lng, lat], ..., [lng, lat] ],
|
|
2437
|
+
* ...
|
|
2438
|
+
* [ [lng, lat], [lng, lat], [lng, lat], ..., [lng, lat] ]
|
|
2439
|
+
* ],
|
|
2440
|
+
* ]
|
|
2441
|
+
* }
|
|
2442
|
+
* ```
|
|
2443
|
+
*
|
|
2444
|
+
* ```tsx
|
|
2445
|
+
* db.collection('todos').add({
|
|
2446
|
+
* data: {
|
|
2447
|
+
* description: 'eat an apple',
|
|
2448
|
+
* location: {
|
|
2449
|
+
* type: 'MultiPolygon',
|
|
2450
|
+
* coordinates: [
|
|
2451
|
+
* [
|
|
2452
|
+
* [ [50, 50], [60, 80], [80, 60], [50, 50] ]
|
|
2453
|
+
* ],
|
|
2454
|
+
* [
|
|
2455
|
+
* [ [0, 0], [30, 20], [20, 30], [0, 0] ],
|
|
2456
|
+
* [ [10, 10], [16, 14], [14, 16], [10, 10]]
|
|
2457
|
+
* ]
|
|
2458
|
+
* ]
|
|
2459
|
+
* }
|
|
2460
|
+
* }
|
|
2461
|
+
* }).then(console.log).catch(console.error)
|
|
2462
|
+
* ```
|
|
2463
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/geo/Geo.MultiPolygon.html
|
|
2464
|
+
*/
|
|
2465
|
+
MultiPolygon(polygons: IGeo.GeoPolygon[] | IGeo.JSONMultiPolygon): IGeo.GeoMultiPolygon
|
|
2466
|
+
}
|
|
2467
|
+
|
|
2468
|
+
namespace IGeo {
|
|
2469
|
+
/** 地理位置 “点”
|
|
2470
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/geo/GeoPoint.html
|
|
2471
|
+
*/
|
|
2472
|
+
interface GeoPoint {
|
|
2473
|
+
/** 经度 */
|
|
2474
|
+
longitude: number
|
|
2475
|
+
/** 纬度 */
|
|
2476
|
+
latitude: number
|
|
2477
|
+
|
|
2478
|
+
/** 格式化为 JSON 结构 */
|
|
2479
|
+
toJSON(): object
|
|
2480
|
+
/** 格式化为字符串 */
|
|
2481
|
+
toString(): string
|
|
2482
|
+
}
|
|
2483
|
+
|
|
2484
|
+
/** 地理位置的 ”线“。一个线由两个或更多的点有序连接组成。
|
|
2485
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/geo/GeoLineString.html
|
|
2486
|
+
*/
|
|
2487
|
+
interface GeoLineString {
|
|
2488
|
+
/** 点集合 */
|
|
2489
|
+
points: GeoPoint[]
|
|
2490
|
+
|
|
2491
|
+
/** 格式化为 JSON 结构 */
|
|
2492
|
+
toJSON(): JSONLineString
|
|
2493
|
+
/** 格式化为字符串 */
|
|
2494
|
+
toString(): string
|
|
2495
|
+
}
|
|
2496
|
+
|
|
2497
|
+
/** 地理位置 ”多边形“
|
|
2498
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/geo/GeoPolygon.html
|
|
2499
|
+
*/
|
|
2500
|
+
interface GeoPolygon {
|
|
2501
|
+
/** 线集合 */
|
|
2502
|
+
lines: GeoLineString[]
|
|
2503
|
+
|
|
2504
|
+
/** 格式化为 JSON 结构 */
|
|
2505
|
+
toJSON(): JSONPolygon
|
|
2506
|
+
/** 格式化为字符串 */
|
|
2507
|
+
toString(): string
|
|
2508
|
+
}
|
|
2509
|
+
|
|
2510
|
+
/** 地理位置的 ”点“ 的集合。一个点集合由一个或更多的点组成。
|
|
2511
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/geo/GeoMultiPoint.html
|
|
2512
|
+
*/
|
|
2513
|
+
interface GeoMultiPoint {
|
|
2514
|
+
/** 点集合 */
|
|
2515
|
+
points: GeoPoint[]
|
|
2516
|
+
|
|
2517
|
+
/** 格式化为 JSON 结构 */
|
|
2518
|
+
toJSON(): JSONMultiPoint
|
|
2519
|
+
/** 格式化为字符串 */
|
|
2520
|
+
toString(): string
|
|
2521
|
+
}
|
|
2522
|
+
|
|
2523
|
+
/** 地理位置 ”线“ 集合。一个线集合由多条线组成。
|
|
2524
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/geo/GeoMultiLineString.html
|
|
2525
|
+
*/
|
|
2526
|
+
interface GeoMultiLineString {
|
|
2527
|
+
/** 线集合 */
|
|
2528
|
+
lines: GeoLineString[]
|
|
2529
|
+
|
|
2530
|
+
/** 格式化为 JSON 结构 */
|
|
2531
|
+
toJSON(): JSONMultiLineString
|
|
2532
|
+
/** 格式化为字符串 */
|
|
2533
|
+
toString(): string
|
|
2534
|
+
}
|
|
2535
|
+
|
|
2536
|
+
/** 地理位置 ”多边形“ 集合。一个多边形集合由多个多边形组成。
|
|
2537
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/geo/GeoMultiPolygon.html
|
|
2538
|
+
*/
|
|
2539
|
+
interface GeoMultiPolygon {
|
|
2540
|
+
/** 多边形集合 */
|
|
2541
|
+
polygons: GeoPolygon[]
|
|
2542
|
+
|
|
2543
|
+
/** 格式化为 JSON 结构 */
|
|
2544
|
+
toJSON(): JSONMultiPolygon
|
|
2545
|
+
/** 格式化为字符串 */
|
|
2546
|
+
toString(): string
|
|
2547
|
+
}
|
|
2548
|
+
|
|
2549
|
+
/** 地理位置 “点” 的 JSON 结构 */
|
|
2550
|
+
interface JSONPoint {
|
|
2551
|
+
/** 类型 */
|
|
2552
|
+
type: 'Point'
|
|
2553
|
+
/** 坐标 */
|
|
2554
|
+
coordinates: [number, number]
|
|
2555
|
+
}
|
|
2556
|
+
|
|
2557
|
+
/** 地理位置 ”线“ 的 JSON 结构 */
|
|
2558
|
+
interface JSONLineString {
|
|
2559
|
+
/** 类型 */
|
|
2560
|
+
type: 'LineString'
|
|
2561
|
+
/** 坐标 */
|
|
2562
|
+
coordinates: Array<[number, number]>
|
|
2563
|
+
}
|
|
2564
|
+
|
|
2565
|
+
/** 地理位置 ”多边形“ 的 JSON 结构 */
|
|
2566
|
+
interface JSONPolygon {
|
|
2567
|
+
/** 类型 */
|
|
2568
|
+
type: 'Polygon'
|
|
2569
|
+
/** 坐标 */
|
|
2570
|
+
coordinates: Array<Array<[number, number]>>
|
|
2571
|
+
}
|
|
2572
|
+
|
|
2573
|
+
/** 地理位置的 ”点“ 集合的 JSON 结构 */
|
|
2574
|
+
interface JSONMultiPoint {
|
|
2575
|
+
/** 类型 */
|
|
2576
|
+
type: 'MultiPoint'
|
|
2577
|
+
/** 坐标 */
|
|
2578
|
+
coordinates: Array<[number, number]>
|
|
2579
|
+
}
|
|
2580
|
+
|
|
2581
|
+
/** 地理位置 ”线“ 集合的 JSON 结构 */
|
|
2582
|
+
interface JSONMultiLineString {
|
|
2583
|
+
/** 类型 */
|
|
2584
|
+
type: 'MultiLineString'
|
|
2585
|
+
/** 坐标 */
|
|
2586
|
+
coordinates: Array<Array<[number, number]>>
|
|
2587
|
+
}
|
|
2588
|
+
|
|
2589
|
+
/** 地理位置 ”多边形“ 集合的 JSON 结构 */
|
|
2590
|
+
interface JSONMultiPolygon {
|
|
2591
|
+
/** 类型 */
|
|
2592
|
+
type: 'MultiPolygon'
|
|
2593
|
+
/** 坐标 */
|
|
2594
|
+
coordinates: Array<Array<Array<[number, number]>>>
|
|
2595
|
+
}
|
|
2596
|
+
}
|
|
2597
|
+
}
|
|
2598
|
+
|
|
2599
|
+
|
|
2600
|
+
interface TaroStatic {
|
|
2601
|
+
cloud: cloud & Cloud
|
|
2602
|
+
}
|
|
2603
|
+
}
|
|
2604
|
+
|
|
2605
|
+
type OQ<
|
|
2606
|
+
T extends Partial<
|
|
2607
|
+
Record<'complete' | 'success' | 'fail', (...args: any[]) => any>
|
|
2608
|
+
>
|
|
2609
|
+
> =
|
|
2610
|
+
| (RQ<T> & Required<Pick<T, 'success'>>)
|
|
2611
|
+
| (RQ<T> & Required<Pick<T, 'fail'>>)
|
|
2612
|
+
| (RQ<T> & Required<Pick<T, 'complete'>>)
|
|
2613
|
+
| (RQ<T> & Required<Pick<T, 'success' | 'fail'>>)
|
|
2614
|
+
| (RQ<T> & Required<Pick<T, 'success' | 'complete'>>)
|
|
2615
|
+
| (RQ<T> & Required<Pick<T, 'fail' | 'complete'>>)
|
|
2616
|
+
| (RQ<T> & Required<Pick<T, 'fail' | 'complete' | 'success'>>)
|
|
2617
|
+
|
|
2618
|
+
type RQ<
|
|
2619
|
+
T extends Partial<
|
|
2620
|
+
Record<'complete' | 'success' | 'fail', (...args: any[]) => any>
|
|
2621
|
+
>
|
|
2622
|
+
> = Pick<T, Exclude<keyof T, 'complete' | 'success' | 'fail'>>
|