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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (203) hide show
  1. package/CHANGELOG.md +398 -0
  2. package/ai/dist/index.esm.js +2 -3
  3. package/ai/dist/index.esm.js.map +1 -0
  4. package/ai/dist/index.js +2 -21
  5. package/ai/dist/index.js.map +1 -0
  6. package/apis/dist/index.d.ts +1 -0
  7. package/apis/dist/index.esm.js +2 -0
  8. package/apis/dist/index.esm.js.map +1 -0
  9. package/apis/dist/index.js +2 -0
  10. package/apis/dist/index.js.map +1 -0
  11. package/{analytics → apis}/package.json +1 -1
  12. package/app/dist/index.esm.js +2 -11
  13. package/app/dist/index.esm.js.map +1 -0
  14. package/app/dist/index.js +2 -18
  15. package/app/dist/index.js.map +1 -0
  16. package/app/dist/index.node.esm.js +3 -0
  17. package/app/dist/index.node.esm.js.LICENSE.txt +13 -0
  18. package/app/dist/index.node.esm.js.map +1 -0
  19. package/app/dist/index.node.js +3 -0
  20. package/app/dist/index.node.js.LICENSE.txt +13 -0
  21. package/app/dist/index.node.js.map +1 -0
  22. package/app/package.json +12 -1
  23. package/auth/dist/index.d.ts +2 -2
  24. package/auth/dist/index.esm.js +3 -4
  25. package/auth/dist/index.esm.js.LICENSE.txt +12 -0
  26. package/auth/dist/index.esm.js.map +1 -0
  27. package/auth/dist/index.js +3 -9
  28. package/auth/dist/index.js.LICENSE.txt +12 -0
  29. package/auth/dist/index.js.map +1 -0
  30. package/cloudrun/dist/index.esm.js +2 -3
  31. package/cloudrun/dist/index.esm.js.map +1 -0
  32. package/cloudrun/dist/index.js +2 -21
  33. package/cloudrun/dist/index.js.map +1 -0
  34. package/container/dist/index.d.ts +2 -2
  35. package/container/dist/index.esm.js +2 -4
  36. package/container/dist/index.esm.js.map +1 -0
  37. package/container/dist/index.js +2 -9
  38. package/container/dist/index.js.map +1 -0
  39. package/core.d.ts +4331 -0
  40. package/core.node.d.ts +294 -0
  41. package/database/dist/index.esm.js +2 -47
  42. package/database/dist/index.esm.js.map +1 -0
  43. package/database/dist/index.js +2 -53
  44. package/database/dist/index.js.map +1 -0
  45. package/database/package.json +34 -4
  46. package/dist/index.cjs.js +3 -37
  47. package/dist/index.cjs.js.LICENSE.txt +12 -0
  48. package/dist/index.cjs.js.map +1 -0
  49. package/dist/index.esm.js +3 -32
  50. package/dist/index.esm.js.LICENSE.txt +12 -0
  51. package/dist/index.esm.js.map +1 -0
  52. package/dist/index.node.cjs.js +3 -0
  53. package/dist/index.node.cjs.js.LICENSE.txt +26 -0
  54. package/dist/index.node.cjs.js.map +1 -0
  55. package/dist/index.node.esm.js +3 -0
  56. package/dist/index.node.esm.js.LICENSE.txt +26 -0
  57. package/dist/index.node.esm.js.map +1 -0
  58. package/functions/dist/index.d.ts +2 -2
  59. package/functions/dist/index.esm.js +2 -4
  60. package/functions/dist/index.esm.js.map +1 -0
  61. package/functions/dist/index.js +2 -9
  62. package/functions/dist/index.js.map +1 -0
  63. package/index.d.ts +7 -1785
  64. package/index.node.d.ts +13 -0
  65. package/miniprogram_dist/ai/index.d.ts +42 -0
  66. package/miniprogram_dist/ai/index.js +2 -0
  67. package/miniprogram_dist/apis/index.d.ts +5 -0
  68. package/miniprogram_dist/apis/index.js +1 -0
  69. package/miniprogram_dist/app/index.d.ts +67 -0
  70. package/miniprogram_dist/app/index.js +2 -0
  71. package/miniprogram_dist/auth/index.d.ts +269 -0
  72. package/miniprogram_dist/auth/index.js +2 -0
  73. package/miniprogram_dist/cloudrun/index.d.ts +4 -0
  74. package/miniprogram_dist/cloudrun/index.js +1 -0
  75. package/miniprogram_dist/container/index.d.ts +13 -0
  76. package/miniprogram_dist/container/index.js +1 -0
  77. package/miniprogram_dist/database/index.d.ts +3 -0
  78. package/miniprogram_dist/database/index.js +1 -0
  79. package/miniprogram_dist/functions/index.d.ts +2 -0
  80. package/miniprogram_dist/functions/index.js +1 -0
  81. package/miniprogram_dist/index.js +1 -1
  82. package/miniprogram_dist/model/index.d.ts +5 -0
  83. package/miniprogram_dist/model/index.js +1 -0
  84. package/miniprogram_dist/mysql/index.d.ts +3 -0
  85. package/miniprogram_dist/mysql/index.js +1 -0
  86. package/miniprogram_dist/oauth/index.d.ts +22 -0
  87. package/miniprogram_dist/oauth/index.js +2 -0
  88. package/miniprogram_dist/realtime/index.d.ts +2 -0
  89. package/miniprogram_dist/realtime/index.js +1 -0
  90. package/miniprogram_dist/storage/index.d.ts +13 -0
  91. package/miniprogram_dist/storage/index.js +1 -0
  92. package/model/dist/index.esm.js +2 -3
  93. package/model/dist/index.esm.js.map +1 -0
  94. package/model/dist/index.js +2 -21
  95. package/model/dist/index.js.map +1 -0
  96. package/mysql/dist/index.d.ts +1 -0
  97. package/mysql/dist/index.esm.js +2 -0
  98. package/mysql/dist/index.esm.js.map +1 -0
  99. package/mysql/dist/index.js +2 -0
  100. package/mysql/dist/index.js.map +1 -0
  101. package/mysql/package.json +6 -0
  102. package/oauth/dist/index.esm.js +3 -3
  103. package/oauth/dist/index.esm.js.LICENSE.txt +12 -0
  104. package/oauth/dist/index.esm.js.map +1 -0
  105. package/oauth/dist/index.js +3 -21
  106. package/oauth/dist/index.js.LICENSE.txt +12 -0
  107. package/oauth/dist/index.js.map +1 -0
  108. package/package.json +144 -18
  109. package/realtime/dist/index.d.ts +2 -2
  110. package/realtime/dist/index.esm.js +2 -4
  111. package/realtime/dist/index.esm.js.map +1 -0
  112. package/realtime/dist/index.js +2 -9
  113. package/realtime/dist/index.js.map +1 -0
  114. package/storage/dist/index.d.ts +2 -2
  115. package/storage/dist/index.esm.js +2 -4
  116. package/storage/dist/index.esm.js.map +1 -0
  117. package/storage/dist/index.js +2 -9
  118. package/storage/dist/index.js.map +1 -0
  119. package/types/analytics.d.ts +51 -0
  120. package/types/auth.d.ts +166 -0
  121. package/types/cache.d.ts +26 -0
  122. package/types/cloudrun.d.ts +9 -0
  123. package/types/component.d.ts +17 -0
  124. package/types/container.d.ts +93 -0
  125. package/types/database.d.ts +31 -0
  126. package/types/error.d.ts +40 -0
  127. package/types/events.d.ts +13 -0
  128. package/types/functions.d.ts +49 -0
  129. package/types/index.d.ts +269 -0
  130. package/types/package.json +47 -0
  131. package/types/realtime.d.ts +350 -0
  132. package/types/request.d.ts +30 -0
  133. package/types/result.d.ts +48 -0
  134. package/types/storage.d.ts +144 -0
  135. package/utilities/dist/cjs/adapters/index.d.ts +45 -0
  136. package/utilities/dist/cjs/adapters/index.js +68 -0
  137. package/utilities/dist/cjs/adapters/platforms/web.d.ts +20 -0
  138. package/utilities/dist/cjs/adapters/platforms/web.js +286 -0
  139. package/utilities/dist/cjs/constants/common.d.ts +6 -0
  140. package/utilities/dist/cjs/constants/common.js +24 -0
  141. package/utilities/dist/cjs/constants/errors.d.ts +8 -0
  142. package/utilities/dist/cjs/constants/errors.js +12 -0
  143. package/utilities/dist/cjs/constants/index.d.ts +3 -0
  144. package/utilities/dist/cjs/constants/index.js +21 -0
  145. package/utilities/dist/cjs/helpers/decorators.d.ts +11 -0
  146. package/utilities/dist/cjs/helpers/decorators.js +238 -0
  147. package/utilities/dist/cjs/helpers/index.d.ts +1 -0
  148. package/utilities/dist/cjs/helpers/index.js +18 -0
  149. package/utilities/dist/cjs/index.d.ts +13 -0
  150. package/utilities/dist/cjs/index.js +51 -0
  151. package/utilities/dist/cjs/libs/abortController.d.ts +9 -0
  152. package/utilities/dist/cjs/libs/abortController.js +25 -0
  153. package/utilities/dist/cjs/libs/cache.d.ts +17 -0
  154. package/utilities/dist/cjs/libs/cache.js +261 -0
  155. package/utilities/dist/cjs/libs/events.d.ts +27 -0
  156. package/utilities/dist/cjs/libs/events.js +108 -0
  157. package/utilities/dist/cjs/libs/langEvent.d.ts +3 -0
  158. package/utilities/dist/cjs/libs/langEvent.js +7 -0
  159. package/utilities/dist/cjs/libs/util.d.ts +49 -0
  160. package/utilities/dist/cjs/libs/util.js +282 -0
  161. package/utilities/dist/esm/adapters/index.d.ts +45 -0
  162. package/utilities/dist/esm/adapters/index.js +40 -0
  163. package/utilities/dist/esm/adapters/platforms/web.d.ts +20 -0
  164. package/utilities/dist/esm/adapters/platforms/web.js +282 -0
  165. package/utilities/dist/esm/constants/common.d.ts +6 -0
  166. package/utilities/dist/esm/constants/common.js +17 -0
  167. package/utilities/dist/esm/constants/errors.d.ts +8 -0
  168. package/utilities/dist/esm/constants/errors.js +9 -0
  169. package/utilities/dist/esm/constants/index.d.ts +3 -0
  170. package/utilities/dist/esm/constants/index.js +4 -0
  171. package/utilities/dist/esm/helpers/decorators.d.ts +11 -0
  172. package/utilities/dist/esm/helpers/decorators.js +234 -0
  173. package/utilities/dist/esm/helpers/index.d.ts +1 -0
  174. package/utilities/dist/esm/helpers/index.js +2 -0
  175. package/utilities/dist/esm/index.d.ts +13 -0
  176. package/utilities/dist/esm/index.js +14 -0
  177. package/utilities/dist/esm/libs/abortController.d.ts +9 -0
  178. package/utilities/dist/esm/libs/abortController.js +23 -0
  179. package/utilities/dist/esm/libs/cache.d.ts +17 -0
  180. package/utilities/dist/esm/libs/cache.js +258 -0
  181. package/utilities/dist/esm/libs/events.d.ts +27 -0
  182. package/utilities/dist/esm/libs/events.js +102 -0
  183. package/utilities/dist/esm/libs/langEvent.d.ts +3 -0
  184. package/utilities/dist/esm/libs/langEvent.js +4 -0
  185. package/utilities/dist/esm/libs/util.d.ts +49 -0
  186. package/utilities/dist/esm/libs/util.js +254 -0
  187. package/utilities/dist/miniprogram/index.js +1 -0
  188. package/utilities/package.json +26 -0
  189. package/analytics/dist/index.d.ts +0 -2
  190. package/analytics/dist/index.esm.js +0 -4
  191. package/analytics/dist/index.js +0 -9
  192. package/miniprogram_dist/ai.js +0 -2
  193. package/miniprogram_dist/analytics.js +0 -1
  194. package/miniprogram_dist/app.js +0 -2
  195. package/miniprogram_dist/auth.js +0 -2
  196. package/miniprogram_dist/cloudrun.js +0 -1
  197. package/miniprogram_dist/container.js +0 -1
  198. package/miniprogram_dist/database.js +0 -2
  199. package/miniprogram_dist/functions.js +0 -1
  200. package/miniprogram_dist/model.js +0 -1
  201. package/miniprogram_dist/oauth.js +0 -1
  202. package/miniprogram_dist/realtime.js +0 -1
  203. package/miniprogram_dist/storage.js +0 -1
package/index.d.ts CHANGED
@@ -1,1789 +1,11 @@
1
- import { CloudbaseAdapter } from '@cloudbase/adapter-interface';
2
- import { ICloudbaseUpgradedConfig, ICloudbase, Persistence } from '@cloudbase/types';
3
- import { OrmClient, OrmRawQueryClient } from '@cloudbase/model';
4
- import { authModels } from '@cloudbase/oauth';
5
- import { AI } from '@cloudbase/ai';
1
+ /// <reference path="./core.d.ts" />
6
2
 
7
- type KV<T> = {
8
- [key: string]: T;
9
- };
10
-
11
- type ExcludeOf<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
12
-
13
- /**
14
- * module
15
- */
16
- declare namespace cloudbase {
17
-
18
- interface SimpleStorage {
19
- getItem: (key: string) => Promise<string | null>;
20
- removeItem: (key: string) => Promise<void>;
21
- setItem: (key: string, value: string) => Promise<void>;
22
- getItemSync: (key: string) => string | null;
23
- removeItemSync: (key: string) => void;
24
- setItemSync: (key: string, value: string) => void;
25
- }
26
-
27
- interface ICloudbaseConfig {
28
- env: string;
29
- region?: string;
30
- timeout?: number;
31
- persistence?: Persistence;
32
- oauthClient?: any
33
- debug?: boolean;
34
- _fromApp?: ICloudbase;
35
- clientId?: string
36
- oauthInstance?: any;
37
- }
38
-
39
- interface ICloudbaseExtension {
40
- name: string;
41
- invoke(opts: any, app: ICloudbase): Promise<any>;
42
- }
43
-
44
- interface Listeners {
45
- [key: string]: Function[];
46
- }
47
-
48
- interface ICloudbaseEvent {
49
- name: string;
50
- target: any;
51
- data: any;
52
- }
53
-
54
- interface ICloudbaseEventEmitter {
55
- on(name: string, listener: Function): this;
56
- off(name: string, listener: Function): this;
57
- fire(event: string | ICloudbaseEvent, data?: any): this;
58
- }
59
-
60
- interface ICloudbaseComponent {
61
- name: string;
62
- entity: any;
63
- namespace?: string;
64
- injectEvents?: {
65
- bus: ICloudbaseEventEmitter,
66
- events: string[];
67
- };
68
- IIFE?: boolean
69
- }
70
-
71
- interface ICloudbaseHook {
72
- entity: any;
73
- target: string;
74
- }
75
-
76
- type EndPointKey = 'CLOUD_API' | 'GATEWAY';
77
-
78
- interface ISetEndPointWithKey {
79
- key: EndPointKey;
80
- url?: string;
81
- protocol?: 'http' | 'https';
82
- }
83
-
84
- /**
85
- * 初始化Cloudbase
86
- *
87
- * @example
88
- * ```javascript
89
- * const app = cloudbase.init({
90
- * env: 'your-envid',
91
- * timeout: 15000
92
- * });
93
- * ```
94
- *
95
- * @param config 初始化配置
96
- * @param config.env 环境ID
97
- * @param config.timeout 【可选】网络请求超时上限,单位`ms`,默认值`15000`
98
- *
99
- * @return {!cloudbase.app.App} 初始化成功的Cloudbase实例
100
- */
101
- function init(config: ICloudbaseConfig): cloudbase.app.App;
102
-
103
- function updateConfig(config: ICloudbaseUpgradedConfig): void;
104
- /**
105
- * 使用适配器,使用方式参考 {@link https://docs.cloudbase.net/api-reference/webv3/adapter#%E7%AC%AC-1-%E6%AD%A5%E5%AE%89%E8%A3%85%E5%B9%B6%E5%BC%95%E5%85%A5%E9%80%82%E9%85%8D%E5%99%A8}
106
- *
107
- * @example
108
- * ```javascript
109
- * cloudbase.useAdapters(adapter); // 使用单个适配器
110
- * cloudbase.useAdapters([ // 使用多个适配器
111
- * adapterA,
112
- * adapterB
113
- * ]);
114
- * ```
115
- *
116
- * @param adapters 适配器对象,入参可以为单个适配器对象,也可以是多个适配器对象的数组
117
- * @param options 适配器参数,可以在genAdapter中获取到该参数
118
- */
119
- function useAdapters(adapters: CloudbaseAdapter | CloudbaseAdapter[], options?: any): void;
120
- /**
121
- * 注册扩展能力插件,使用方式参考 {@link https://docs.cloudbase.net/extension/abilities/image-examination.html#shi-yong-kuo-zhan}
122
- *
123
- * @example
124
- * ```javascript
125
- * cloudbase.registerExtension(ext);
126
- * ```
127
- *
128
- * @param ext 扩展能力插件对象
129
- */
130
- function registerExtension(ext: ICloudbaseExtension): void;
131
- /**
132
- * 【谨慎操作】注册SDK的版本
133
- *
134
- * @example
135
- * ```javascript
136
- * cloudbase.registerVersion('1.2.1');
137
- * ```
138
- *
139
- * @param version SDK版本
140
- */
141
- function registerVersion(version: string): void;
142
- /**
143
- * 【谨慎操作】注册SDK的名称
144
- *
145
- * @example
146
- * ```javascript
147
- * cloudbase.registerSdkName('cloudbase-js-sdk');
148
- * ```
149
- *
150
- * @param name SDK名称
151
- */
152
- function registerSdkName(name: string): void;
153
- /**
154
- * 【谨慎操作】修改SDK请求的云开发服务地址
155
- *
156
- * @example
157
- * ```javascript
158
- * cloudbase.registerEndPoint('url','https');
159
- * ```
160
- *
161
- * @param url 服务地址
162
- * @param protocol 【可选】强制使用某种协议,默认与主站协议一致
163
- */
164
- function registerEndPoint(url: string, protocol?: 'http' | 'https'): void;
165
- /**
166
- * 【谨慎操作】修改SDK请求的「云开发/网关」服务地址
167
- *
168
- * @example
169
- * ```javascript
170
- * cloudbase.registerEndPointWithKey({
171
- * key: "GATEWAY",
172
- * url: "",
173
- * protocol: ""
174
- * });
175
- * ```
176
- *
177
- */
178
- function registerEndPointWithKey(props: ISetEndPointWithKey): void;
179
- /**
180
- * 【谨慎操作】注册功能模块
181
- *
182
- * @example
183
- * ```javascript
184
- * cloudbase.registerComponent({});
185
- * ```
186
- *
187
- * @param component 功能模块对象
188
- */
189
- function registerComponent(component: ICloudbaseComponent): void;
190
- /**
191
- * 【谨慎操作】注册hook
192
- *
193
- * @example
194
- * ```javascript
195
- * cloudbase.registerHook({});
196
- * ```
197
- *
198
- * @param hook hook对象
199
- */
200
- function registerHook(hook: ICloudbaseHook): void;
201
-
202
- export interface models extends OrmClient, OrmRawQueryClient { }
203
- }
204
- /**
205
- * instance
206
- */
207
- declare namespace cloudbase.app {
208
- interface App {
209
- /**
210
- * 创建Auth对象
211
- *
212
- * {@link https://docs.cloudbase.net/api-reference/webv3/authentication#appauth}
213
- *
214
- * @example
215
- * ```javascript
216
- * const app = cloudbase.init({
217
- * env: 'your-envid'
218
- * });
219
- * const auth = app.auth({
220
- * persistence: 'local'
221
- * });
222
- * ```
223
- *
224
- * @param options Auth初始化配置
225
- * @param options.persistence 本地登录态保留期限
226
- *
227
- * @return {!cloudbase.auth.App} Auth实例
228
- */
229
- auth(options?: {
230
- persistence: cloudbase.auth.Persistence
231
- }): cloudbase.auth.App;
232
- /**
233
- * 调用云函数
234
- *
235
- * {@link https://docs.cloudbase.net/api-reference/webv3/functions#callfunction}
236
- *
237
- * @example
238
- * ```javascript
239
- * const app = cloudbase.init({
240
- * env: 'your-envid'
241
- * });
242
- * app.callFunction({
243
- * name: 'function-name'
244
- * data: {
245
- * a: 1,
246
- * b: 2
247
- * }
248
- * }).then(res=>{
249
- * console.log(res.result);
250
- * }});
251
- * ```
252
- *
253
- * @param options 被调用的云函数信息
254
- * @param options.name 云函数的名称
255
- * @param options.data 【可选】云函数的参数,默认为空
256
- * @param options.parse 【可选】设置为 `true` 时,当函数返回值为对象时,API 请求会返回解析对象,而不是 JSON 字符串,默认为`false`
257
- *
258
- * @return Promise-函数执行结果
259
- */
260
- callFunction(options: cloudbase.functions.ICallFunctionOptions, callback?: Function): Promise<cloudbase.functions.ICallFunctionResponse>;
261
- /**
262
- * 云存储-上传文件
263
- *
264
- * {@link https://docs.cloudbase.net/api-reference/webv3/storage#uploadfile}
265
- *
266
- * @example
267
- * ```javascript
268
- * const app = cloudbase.init({
269
- * env: 'your-envid'
270
- * });
271
- * app.uploadFile({
272
- * cloudPath: 'cloudPath',
273
- * filePath: 'filePath',
274
- * method: 'put',
275
- * headers: {
276
- * 'Content-MD5': 'xxxxxx'
277
- * }
278
- * onUploadProgress: function(event){}
279
- * });
280
- * ```
281
- *
282
- * @param params
283
- * @param params.cloudPath 文件上传到云端后的绝对路径,包含文件名
284
- * @param params.filePath 被上传的文件对象
285
- * @param params.method 上传方法,默认为 put
286
- * @param params.headers 自定义头部字段
287
- * @param params.onUploadProgress 【可选】上传进度回调函数
288
- *
289
- * @return Promise-上传结果
290
- */
291
- uploadFile(params: cloudbase.storage.ICloudbaseUploadFileParams, callback?: Function): Promise<cloudbase.storage.ICloudbaseUploadFileResult>;
292
- /**
293
- * 云存储-下载文件
294
- *
295
- * {@link https://docs.cloudbase.net/api-reference/webv3/storage#downloadfile}
296
- *
297
- * @example
298
- * ```javascript
299
- * const app = cloudbase.init({
300
- * env: 'your-envid'
301
- * });
302
- * app.downloadFile({
303
- * fileID: 'cloudPath'
304
- * });
305
- * ```
306
- *
307
- * @param params
308
- * @param params.fileID 要下载的文件的 `id`,在控制台云存储中查看
309
- *
310
- * @return Promise-下载结果
311
- */
312
- downloadFile(params: cloudbase.storage.ICloudbaseDownloadFileParams, callback?: Function): Promise<cloudbase.storage.ICloudbaseDownloadFileResult>;
313
- /**
314
- * 云存储-获取文件的下载链接
315
- *
316
- * {@link https://docs.cloudbase.net/api-reference/webv3/storage#gettempfileurl}
317
- *
318
- * @example
319
- * ```javascript
320
- * const app = cloudbase.init({
321
- * env: 'your-envid'
322
- * });
323
- * app.getTempFileURL({
324
- * fileList: [
325
- * '文件A的fileID',
326
- * {
327
- * fileID: '文件B的fileID',
328
- * maxAge: 600 // 文件B的链接有效期,单位`ms`
329
- * }
330
- * ]
331
- * });
332
- * ```
333
- *
334
- * @param params
335
- * @param params.fileList 要下载的文件数组,数组元素可以是`string`或`Object`,如果是`string`代表文件ID,如果是`Object`可配置以下信息
336
- * @param params.fileList[].fileID 要下载的文件ID
337
- * @param params.fileList[].maxAge 下载链接的有效期,单位`ms`
338
- *
339
- * @return Promise-文件下载链接
340
- */
341
- getTempFileURL(params: cloudbase.storage.ICloudbaseGetTempFileURLParams, callback?: Function): Promise<cloudbase.storage.ICloudbaseGetTempFileURLResult>;
342
- /**
343
- * 云存储-删除文件
344
- *
345
- * {@link https://docs.cloudbase.net/api-reference/webv3/storage#deletefile}
346
- *
347
- * @example
348
- * ```javascript
349
- * const app = cloudbase.init({
350
- * env: 'your-envid'
351
- * });
352
- * app.deleteFile({
353
- * fileList: [
354
- * '文件A的fileID',
355
- * '文件B的fileID'
356
- * ]
357
- * });
358
- * ```
359
- *
360
- * @param params
361
- * @param params.fileList 要删除的文件ID数组
362
- *
363
- * @return Promise-删除结果
364
- */
365
- deleteFile(params: cloudbase.storage.ICloudbaseDeleteFileParams, callback?: Function): Promise<cloudbase.storage.ICloudbaseDeleteFileResult>;
366
- /**
367
- * 云存储-获取上传元信息
368
- *
369
- *
370
- * @param params
371
- * @param callback
372
- */
373
- getUploadMetadata(params: cloudbase.storage.ICloudbaseGetUploadMetadataParams, callback?: Function): Promise<any>;
374
- /**
375
- * 获取数据库实例
376
- *
377
- * {@link https://docs.cloudbase.net/api-reference/webv3/database#%E8%8E%B7%E5%8F%96%E6%95%B0%E6%8D%AE%E5%BA%93%E5%AE%9E%E4%BE%8B}
378
- *
379
- * @example
380
- * ```javascript
381
- * const app = cloudbase.init({
382
- * env: 'your-envid'
383
- * });
384
- * const db = app.database();
385
- * ```
386
- *
387
- * @return 数据库实例
388
- */
389
- database(): cloudbase.database.App;
390
- /**
391
- * 调用扩展能力插件功能
392
- *
393
- * @example
394
- * ```javascript
395
- * const app = cloudbase.init({
396
- * env: 'your-envid'
397
- * });
398
- * // 调用前需要先注册
399
- * app.registerExtension(ext);
400
- *
401
- * app.invokeExtension('扩展能力插件名称',{
402
- * // ...扩展能力插件的入参
403
- * });
404
- * ```
405
- *
406
- * @param name 扩展能力插件的名称
407
- * @param opts 【可选】扩展能力插件的参数,根据插件具体需求而定
408
- *
409
- * @return Promise-扩展能力插件执行结果
410
- */
411
- invokeExtension(name: string, opts: any): Promise<any>;
412
-
413
- eventBus: any;
414
-
415
- /**
416
- * 调用 数据模型 SDK
417
- *
418
- * {@link https://docs.cloudbase.net/model/sdk-reference/model}
419
- * @example
420
- * ```javascript
421
- models.<model_name>.create() // 创建单条数据
422
- models.<model_name>.createMany() // 创建多条数据
423
- models.<model_name>.update() // 更新单条数据
424
- models.<model_name>.updateMany() // 更新多条数据
425
- models.<model_name>.delete() // 删除单条数据
426
- models.<model_name>.deleteMany() // 删除多条数据
427
- models.<model_name>.get() // 查询单条数据
428
- models.<model_name>.list() // 查询多条数据
429
- models.$runSQL() // 执行原生 SQL 语句
430
- * ```
431
- */
432
- models: OrmClient & OrmRawQueryClient;
433
-
434
- ai(): AI;
435
- }
436
- }
437
- /**
438
- * auth
439
- */
440
- declare namespace cloudbase.auth {
441
- type Persistence = 'local' | 'session' | 'none';
442
-
443
- interface IAccessTokenInfo {
444
- accessToken: string;
445
- env: string;
446
- }
447
-
448
- interface ILoginState {
449
- /**
450
- * 当前登录用户的信息
451
- */
452
- user: IUser;
453
- }
454
-
455
- interface ICredential {
456
- accessToken?: string;
457
- accessTokenExpire?: string;
458
- }
459
-
460
- interface IAuthProvider {
461
- signInWithRedirect: () => any;
462
- }
463
-
464
- /**
465
- * 用户信息
466
- */
467
- interface IUserInfo {
468
- uid?: string;
469
- loginType?: string;
470
- openid?: string;
471
- wxOpenId?: string;
472
- wxPublicId?: string;
473
- unionId?: string;
474
- qqMiniOpenId?: string;
475
- customUserId?: string;
476
- name?: string;
477
- gender?: string;
478
- email?: string;
479
- username?: string;
480
- hasPassword?: boolean;
481
- location?: {
482
- country?: string;
483
- province?: string;
484
- city?: string;
485
- };
486
- country?: string;
487
- province?: string;
488
- city?: string;
489
- }
490
-
491
- interface IUser extends IUserInfo {
492
- /**
493
- * 更新用户信息
494
- *
495
- * {@link https://docs.cloudbase.net/api-reference/webv3/authentication#userupdate}
496
- *
497
- * @example
498
- * ```javascript
499
- * const app = cloudbase.init({
500
- * env: "xxxx-yyy"
501
- * });
502
- * const auth = app.auth();
503
- * const user = auth.currentUser;
504
- * user.update({
505
- * nickName: '新昵称'
506
- * }).then(()=>{});
507
- * ```
508
- *
509
- * @param userinfo 用户信息
510
- *
511
- * @return Promise
512
- *
513
- */
514
- update(userinfo: IUserInfo): Promise<void>;
515
- /**
516
- * 刷新本地用户信息
517
- *
518
- * {@link https://docs.cloudbase.net/api-reference/webv3/authentication#userrefresh}
519
- *
520
- * @example
521
- * ```javascript
522
- * const app = cloudbase.init({
523
- * env: "xxxx-yyy"
524
- * });
525
- * const auth = app.auth();
526
- * const user = auth.currentUser;
527
- * user.refresh().then(()=>{});
528
- * ```
529
- *
530
- * @return Promise-刷新后的用户信息
531
- *
532
- */
533
- refresh(): Promise<IUserInfo>;
534
- /**
535
- * 同步获取本地用户信息
536
- */
537
- checkLocalInfo: () => void;
538
- /**
539
- * 异步获取本地用户信息
540
- */
541
- checkLocalInfoAsync: () => Promise<void>;
542
- linkWithTicket?: (ticket: string) => Promise<void>;
543
- linkWithRedirect?: (provider: IAuthProvider) => void;
544
- getLinkedUidList?: () => Promise<{ hasPrimaryUid: boolean, users: IUserInfo[] }>;
545
- setPrimaryUid?: (uid: string) => Promise<void>;
546
- unlink?: (loginType: 'CUSTOM' | 'WECHAT-OPEN' | 'WECHAT-PUBLIC' | 'WECHAT-UNION') => Promise<void>;
547
- }
548
-
549
- interface App {
550
- /**
551
- * 获取当前登录的用户信息-同步操作
552
- *
553
- * {@link https://docs.cloudbase.net/api-reference/webv3/authentication.html#auth-hasloginstate}
554
- *
555
- * @example
556
- * ```javascript
557
- * const app = cloudbase.init({
558
- * env: "xxxx-yyy"
559
- * });
560
- * const userInfo = app.auth().currentUser;
561
- * ```
562
- *
563
- * @return 用户信息,如果未登录返回`null`
564
- */
565
- currentUser: IUser | null;
566
- /**
567
- * 获取当前登录的用户信息-异步操作,文档 {@link https://docs.cloudbase.net/api-reference/webv3/authentication#authgetcurrentuser}
568
- *
569
- * @example
570
- * ```javascript
571
- * const app = cloudbase.init({
572
- * env: "xxxx-yyy"
573
- * });
574
- * app.auth().getCurrentUser().then(userInfo=>{
575
- * // ...
576
- * });
577
- * ```
578
- *
579
- * @return Promise-用户信息,如果未登录返回`null`
580
- */
581
- getCurrentUser(): Promise<IUser | null>
582
- /**
583
- * 绑定手机号码
584
- *
585
- * 文档 {@link https://docs.cloudbase.net/api-reference/webv3/authentication#authbindphonenumber}
586
- *
587
- * @param params
588
- */
589
- bindPhoneNumber(params: authModels.BindPhoneRequest): Promise<void>
590
- /**
591
- * 绑定邮箱
592
- *
593
- * 文档 {@link https://docs.cloudbase.net/api-reference/webv3/authentication#authbindemail}
594
- *
595
- * @param params
596
- */
597
- bindEmail(params: authModels.BindEmailRequest): Promise<void>
598
- /**
599
- * 解除三方绑定
600
- *
601
- * 文档 {@link https://docs.cloudbase.net/api-reference/webv3/authentication#authunbindprovider}
602
- *
603
- * @param params
604
- */
605
- unbindProvider(params: authModels.UnbindProviderRequest): Promise<void>
606
-
607
- /**
608
- * 验证码验证
609
- *
610
- * 文档 {@link https://docs.cloudbase.net/api-reference/webv3/authentication#authverify}
611
- *
612
- * @param params
613
- */
614
- verify(params: authModels.VerifyRequest): Promise<authModels.VerifyResponse>
615
- /**
616
- * 获取验证码
617
- *
618
- * 文档 {@link https://docs.cloudbase.net/api-reference/webv3/authentication#authgetverification}
619
- *
620
- * @param params
621
- */
622
- getVerification(params: authModels.GetVerificationRequest): Promise<authModels.GetVerificationResponse>
623
- /**
624
- * 匿名登录
625
- *
626
- *
627
- * 文档 {@link https://docs.cloudbase.net/api-reference/webv3/authentication#authsigninanonymously}
628
- *
629
- */
630
- signInAnonymously(data?: { provider_token?: string }): Promise<ILoginState>
631
- /**
632
- * 设置获取自定义登录 ticket 的函数
633
- *
634
- * 文档 {@link https://docs.cloudbase.net/api-reference/webv3/authentication#authsetcustomsignfunc}
635
- *
636
- *
637
- * @param getTickFn
638
- */
639
- setCustomSignFunc(getTickFn: authModels.GetCustomSignTicketFn): void
640
- /**
641
- * 使用自定义登录 ticket 登录
642
- *
643
- * 文档 {@link https://docs.cloudbase.net/api-reference/webv3/authentication#authsigninwithcustomticket}
644
- */
645
- signInWithCustomTicket(): Promise<ILoginState>
646
- /**
647
- * 用户登录,目前支持手机号,邮箱,用户名密码登录
648
- *
649
- * 文档 {@link https://docs.cloudbase.net/api-reference/webv3/authentication#authsignin}
650
- */
651
- signIn(params: authModels.SignInRequest): Promise<ILoginState>
652
- /**
653
- * 用户注册,目前支持手机号验证码注册,邮箱验证码注册
654
- *
655
- * 文档 {@link https://docs.cloudbase.net/api-reference/webv3/authentication#authsignup}
656
- */
657
- signUp(params: authModels.SignUpRequest): Promise<ILoginState>
658
- /**
659
- * 设置密码(已登录状态下,更新用户密码)
660
- *
661
- * 文档 {@link https://docs.cloudbase.net/api-reference/webv3/authentication#authsetpassword}
662
- *
663
- */
664
- setPassword(params: authModels.SetPasswordRequest): Promise<void>
665
- /**
666
- * 获取用户信息
667
- *
668
- * 文档 {@link https://docs.cloudbase.net/api-reference/webv3/authentication#authgetuserinfo}
669
- */
670
- getUserInfo(): Promise<IUserInfo>
671
- /**
672
- * 获取本地登录态-同步操作
673
- *
674
- * {@link https://docs.cloudbase.net/api-reference/webv3/authentication#authhasloginstate}
675
- *
676
- * @example
677
- * ```javascript
678
- * const app = cloudbase.init({
679
- * env: "xxxx-yyy"
680
- * });
681
- * const loginState = app.auth().hasLoginState();
682
- * ```
683
- *
684
- * @return 登录态信息,如果未登录返回`null`
685
- */
686
- hasLoginState(): ILoginState | null;
687
- /**
688
- * 获取本地登录态-异步操作
689
- *
690
- * {@link https://docs.cloudbase.net/api-reference/webv3/authentication.html#auth-getloginstate}
691
- *
692
- * @example
693
- * ```javascript
694
- * const app = cloudbase.init({
695
- * env: "xxxx-yyy"
696
- * });
697
- * app.auth().getLoginState().then(loginState=>{
698
- * // ...
699
- * });
700
- * ```
701
- *
702
- * @return Promise-登录态信息,如果未登录返回`null`
703
- */
704
- getLoginState(): Promise<ILoginState | null>;
705
- /**
706
- * @deprecated
707
- */
708
- getAuthHeader(): {}
709
- /**
710
- * 为已有账户绑定第三方账户
711
- *
712
- * 文档 {@link https://docs.cloudbase.net/api-reference/webv3/authentication#authbindwithprovider}
713
- */
714
- bindWithProvider(params: authModels.BindWithProviderRequest,): Promise<void>
715
- /**
716
- * 查询用户(自定义登录场景和匿名登录场景,不支持使用该接口查询用户信息)
717
- *
718
- * 文档 {@link https://docs.cloudbase.net/api-reference/webv3/authentication#authqueryuser}
719
- *
720
- */
721
- queryUser(queryObj: authModels.QueryUserProfileRequest): Promise<authModels.QueryUserProfileResponse>
722
- /**
723
- * 获取当前登录用户的访问凭证
724
- *
725
- * 文档 {@link https://docs.cloudbase.net/api-reference/webv3/authentication#authgetaccesstoken}
726
- */
727
- getAccessToken(): Promise<{ accessToken: string, env: string }>
728
- /**
729
- * 提供第三方平台登录 token
730
- *
731
- * 文档 {@link https://docs.cloudbase.net/api-reference/webv3/authentication#authgrantprovidertoken}
732
- */
733
- grantProviderToken(params: authModels.GrantProviderTokenRequest): Promise<authModels.GrantProviderTokenResponse>
734
- patchProviderToken(params: authModels.PatchProviderTokenRequest): Promise<authModels.PatchProviderTokenResponse>
735
- /**
736
- * 第三方平台登录
737
- *
738
- * 文档 {@link https://docs.cloudbase.net/api-reference/webv3/authentication#authsigninwithprovider}
739
- */
740
- signInWithProvider(params: authModels.SignInWithProviderRequest): Promise<ILoginState>
741
- grantToken(params: authModels.GrantTokenRequest): Promise<ILoginState>
742
- /**
743
- * 生成第三方平台授权 Uri (如微信二维码扫码授权网页)
744
- *
745
- * 文档 {@link https://docs.cloudbase.net/api-reference/webv3/authentication#authgenproviderredirecturi}
746
- */
747
- genProviderRedirectUri(params: authModels.GenProviderRedirectUriRequest): Promise<authModels.GenProviderRedirectUriResponse>
748
- /**
749
- * 重置密码(用户忘记密码无法登录时,可使用该接口强制设置密码)
750
- *
751
- * 文档 {@link https://docs.cloudbase.net/api-reference/webv3/authentication#authresetpassword}
752
- */
753
- resetPassword(params: authModels.ResetPasswordRequest): Promise<void>
754
- deviceAuthorize(params: authModels.DeviceAuthorizeRequest): Promise<authModels.DeviceAuthorizeResponse>
755
- /**
756
- * 通过 sudo 接口获取高级操作权限,如修改用户密码,修改手机号,邮箱等操作
757
- *
758
- * 文档 {@link https://docs.cloudbase.net/api-reference/webv3/authentication#authsudo}
759
- */
760
- sudo(params: authModels.SudoRequest): Promise<authModels.SudoResponse>
761
- /**
762
- * 删除用户
763
- *
764
- * 文档 {@link https://docs.cloudbase.net/api-reference/webv3/authentication#authdeleteme}
765
- */
766
- deleteMe(params: authModels.WithSudoRequest): Promise<authModels.UserProfile>
767
- /**
768
- * 获取第三方绑定列表
769
- *
770
- * 文档 {@link https://docs.cloudbase.net/api-reference/webv3/authentication#authgetproviders}
771
- */
772
- getProviders(): Promise<authModels.UserProfileProvider>
773
- /**
774
- * 用于查询用户是否为匿名登录状态
775
- *
776
- * 文档 {@link https://docs.cloudbase.net/api-reference/webv3/authentication#authloginscope}
777
- */
778
- loginScope(): Promise<string>
779
- loginGroups(): Promise<string[]>
780
- onLoginStateChanged(callback: Function)
781
- createLoginState(): Promise<ILoginState>
782
- /**
783
- * 退出登录,请注意,匿名登录不支持退出
784
- *
785
- * {@link https://docs.cloudbase.net/api-reference/webv3/authentication#authsignout}
786
- *
787
- * @example
788
- * ```javascript
789
- * const app = cloudbase.init({
790
- * env: "xxxx-yyy"
791
- * });
792
- * app.auth().signOut().then(()=>{});
793
- * ```
794
- *
795
- * @return Promise
796
- */
797
- signOut(): Promise<void>;
798
- /**
799
- * 检查用户名是否被绑定过
800
- *
801
- * {@link https://docs.cloudbase.net/api-reference/webv3/authentication.html#authisusernameregistered}
802
- *
803
- * @example
804
- * ```javascript
805
- * const app = cloudbase.init({
806
- * env: "xxxx-yyy"
807
- * });
808
- * const auth = app.auth();
809
- * const username = "your_awesome_username";
810
- * auth.isUsernameRegistered(username).then(registered=>{
811
- * // ...
812
- * });
813
- * ```
814
- *
815
- * @param username 用户名
816
- *
817
- * @return Promise-用户是否被绑定
818
- */
819
- isUsernameRegistered(username: string): Promise<boolean>;
820
- getMiniProgramQrCode(params: authModels.GetMiniProgramCodeRequest): Promise<authModels.GetMiniProgramCodeResponse>
821
- getMiniProgramQrCodeStatus(params: authModels.CheckMiniProgramCodeRequest): Promise<authModels.CheckMiniProgramCodeResponse>
822
- }
823
- }
824
- /**
825
- * functions
826
- */
827
- declare namespace cloudbase.functions {
828
- interface ICallFunctionOptions {
829
- name: string;
830
- data?: KV<any>;
831
- query?: KV<any>;
832
- search?: string;
833
- parse?: boolean;
834
- }
835
-
836
- interface ICallFunctionResponse {
837
- requestId: string;
838
- result: any;
839
- }
840
- }
841
3
  /**
842
- * storage
4
+ * Web / 浏览器(默认)环境类型入口。
5
+ *
6
+ * 仅聚合共享类型定义(core.d.ts),不包含任何 Node.js 专属定义。
7
+ * Node.js 环境请使用 `index.node.d.ts`(通过 package.json 的 exports.node.types 自动解析)。
843
8
  */
844
- declare namespace cloudbase.storage {
845
- interface ICloudbaseUploadFileParams {
846
- cloudPath: string;
847
- filePath: string;
848
- method?: 'post' | 'put';
849
- headers?: KV<string>;
850
- onUploadProgress?: Function;
851
- }
852
- interface ICloudbaseUploadFileResult {
853
- fileID: string;
854
- requestId: string;
855
- }
856
- interface ICloudbaseGetUploadMetadataParams {
857
- cloudPath: string;
858
- }
859
- interface ICloudbaseDeleteFileParams {
860
- fileList: string[];
861
- }
862
- interface ICloudbaseDeleteFileResult {
863
- code?: string;
864
- message?: string;
865
- fileList?: {
866
- code?: string;
867
- fileID: string;
868
- }[];
869
- requestId?: string;
870
- }
871
-
872
- interface ICloudbaseFileInfo {
873
- fileID: string;
874
- maxAge: number;
875
- }
876
-
877
- interface ICloudbaseGetTempFileURLParams {
878
- fileList: string[] | ICloudbaseFileInfo[];
879
- }
880
-
881
- interface ICloudbaseGetTempFileURLResult {
882
- code?: string;
883
- message?: string;
884
- fileList?: {
885
- code?: string;
886
- message?: string;
887
- fileID: string;
888
- tempFileURL: string;
889
- download_url?: string;
890
- }[];
891
- requestId?: string;
892
- }
893
- interface ICloudbaseDownloadFileParams {
894
- fileID: string;
895
- tempFilePath?: string;
896
- }
897
- interface ICloudbaseDownloadFileResult {
898
- code?: string;
899
- message?: string;
900
- fileContent?: any;
901
- requestId?: string;
902
- }
903
- interface ICloudbaseFileMetaData {
904
- url: string;
905
- token: string;
906
- authorization: string;
907
- fileId: string;
908
- cosFileId: string;
909
- download_url: string
910
- }
911
-
912
- interface ICloudbaseFileMetaDataRes {
913
- data: ICloudbaseFileMetaData;
914
- requestId: string;
915
- }
916
- }
917
-
918
- declare namespace cloudbase.database {
919
- /**
920
- * realtime types
921
- */
922
- interface IWatchOptions {
923
- // server realtime data init & change event
924
- onChange: (snapshot: ISnapshot) => void
925
- // error while connecting / listening
926
- onError: (error: any) => void
927
- }
928
- interface DBRealtimeListener {
929
- /**
930
- * 关闭实时推送
931
- *
932
- * {@link https://docs.cloudbase.net/api-reference/webv3/database.html#shu-ju-ku-shi-shi-tui-song}
933
- *
934
- * @example
935
- * // 启动监听
936
- * const ref = db
937
- * .collection("collName")
938
- * .where({ test: _.gt(0) })
939
- * .watch({
940
- * onChange: (snapshot) => {
941
- * console.log("收到snapshot**********", snapshot);
942
- * },
943
- * onError: (error) => {
944
- * console.log("收到error**********", error);
945
- * }
946
- * });
947
- * // 关闭监听
948
- * ref.close();
949
- */
950
- close: () => void
951
- }
952
- type DataType = 'init' | 'update' | 'add' | 'remove' | 'replace' | 'limit';
953
- type QueueType = 'init' | 'enqueue' | 'dequeue' | 'update';
954
- interface ISnapshot {
955
- id: number
956
- docChanges: ISingleDBEvent[]
957
- docs: Record<string, any>
958
- type?: SnapshotType
959
- }
960
-
961
- interface ISingleDBEvent {
962
- id: number
963
- dataType: DataType
964
- queueType: QueueType
965
- docId: string
966
- doc: Record<string, any>
967
- updatedFields?: any
968
- removedFields?: any
969
- }
970
-
971
- type SnapshotType = 'init';
972
-
973
- interface IWatchable {
974
- /**
975
- * 开启实时推送
976
- *
977
- * {@link https://docs.cloudbase.net/api-reference/webv3/database#%E6%95%B0%E6%8D%AE%E5%BA%93%E5%AE%9E%E6%97%B6%E6%8E%A8%E9%80%81}
978
- *
979
- * @example
980
- * const ref = db
981
- * .collection("collName")
982
- * .where({ test: _.gt(0) })
983
- * .watch({
984
- * onChange: (snapshot) => {
985
- * console.log("收到snapshot**********", snapshot);
986
- * },
987
- * onError: (error) => {
988
- * console.log("收到error**********", error);
989
- * }
990
- * });
991
- * @param options
992
- * @param options.onChange 监听数据变化的回调函数
993
- * @param options.onError 监听出现错误的回调函数
994
- *
995
- * @return 实时推送进程实例
996
- */
997
- watch(options: IWatchOptions): DBRealtimeListener;
998
- }
999
- /**
1000
- * collection types
1001
- */
1002
- interface ICollection extends IQuery {
1003
- /**
1004
- * 插入一条文档
1005
- *
1006
- * {@link https://docs.cloudbase.net/api-reference/webv3/database#add}
1007
- *
1008
- * @param data 文档数据
1009
- */
1010
- add(data: Object): Promise<Pick<SetRes, 'code' | 'message'>>;
1011
- /**
1012
- * 获取一条文档的引用
1013
- *
1014
- * {@link https://docs.cloudbase.net/api-reference/webv3/database#record--document}
1015
- *
1016
- * @param id 文档ID
1017
- */
1018
- doc(id: string): IDocument;
1019
- }
1020
- /**
1021
- * command types
1022
- */
1023
- interface IGeoNearOptions {
1024
- geometry: IGeo['Point'] // 点的地理位置
1025
- maxDistance?: number // 选填,最大距离,米为单位
1026
- minDistance?: number // 选填,最小距离,米为单位
1027
- }
1028
- interface IGeoWithinOptions {
1029
- geometry: IPolygon | IMultiPolygon
1030
- }
1031
- interface IGeoIntersectsOptions {
1032
- geometry: IPoint | ILineString | IMultiPoint | IMultiLineString | IPolygon | IMultiPolygon;
1033
- }
1034
- interface ICommand {
1035
- /**
1036
- * 表示字段等于某个值
1037
- *
1038
- * {@link https://docs.cloudbase.net/api-reference/webv3/database#eq}
1039
- *
1040
- * @example
1041
- * const _ = db.command;
1042
- * db.collection("demo").where({
1043
- * num: _.eq(10)
1044
- * })
1045
- *
1046
- * @param val 接受一个字面量 (literal),可以是 `number`, `boolean`, `string`, `object`, `array`
1047
- *
1048
- */
1049
- eq(val: number | string | boolean | Object | any[]): any;
1050
- /**
1051
- * 表示字段不等于某个值
1052
- *
1053
- * {@link https://docs.cloudbase.net/api-reference/webv3/database#neq}
1054
- *
1055
- * @example
1056
- * const _ = db.command;
1057
- * db.collection("demo").where({
1058
- * num: _.neq(10)
1059
- * })
1060
- *
1061
- * @param val 接受一个字面量 (literal),可以是 `number`, `boolean`, `string`, `object`, `array`
1062
- *
1063
- */
1064
- neq(val: number | string | boolean | Object | any[]): any;
1065
- /**
1066
- * 字段大于指定值
1067
- *
1068
- * {@link https://docs.cloudbase.net/api-reference/webv3/database#gt}
1069
- *
1070
- * @example
1071
- * const _ = db.command;
1072
- * db.collection("demo").where({
1073
- * num: _.gt(10)
1074
- * })
1075
- *
1076
- * @param val 数字
1077
- *
1078
- */
1079
- gt(val: number): any;
1080
- /**
1081
- * 字段大于或等于指定值
1082
- *
1083
- * {@link https://docs.cloudbase.net/api-reference/webv3/database#neq}
1084
- *
1085
- * @example
1086
- * const _ = db.command;
1087
- * db.collection("demo").where({
1088
- * num: _.gte(10)
1089
- * })
1090
- *
1091
- * @param val 数字
1092
- *
1093
- */
1094
- gte(val: number): any;
1095
- /**
1096
- * 字段小于指定值
1097
- *
1098
- * {@link https://docs.cloudbase.net/api-reference/webv3/database#lt}
1099
- *
1100
- * @example
1101
- * const _ = db.command;
1102
- * db.collection("demo").where({
1103
- * num: _.lt(10)
1104
- * })
1105
- *
1106
- * @param val 数字
1107
- *
1108
- */
1109
- lt(val: number): any;
1110
- /**
1111
- * 字段小于或等于指定值
1112
- *
1113
- * {@link https://docs.cloudbase.net/api-reference/webv3/database#lte}
1114
- *
1115
- * @example
1116
- * const _ = db.command;
1117
- * db.collection("demo").where({
1118
- * num: _.lte(10)
1119
- * })
1120
- *
1121
- * @param val 数字
1122
- *
1123
- */
1124
- lte(val: number): any;
1125
- /**
1126
- * 字段值在给定的数组中
1127
- *
1128
- * {@link https://docs.cloudbase.net/api-reference/webv3/database#in}
1129
- *
1130
- * @example
1131
- * const _ = db.command;
1132
- * db.collection("demo").where({
1133
- * num: _.in([1,2,3])
1134
- * })
1135
- *
1136
- * @param list 数组
1137
- *
1138
- */
1139
- in(list: any[]): any;
1140
- /**
1141
- * 字段值不在给定的数组中
1142
- *
1143
- * {@link https://docs.cloudbase.net/api-reference/webv3/database#nin}
1144
- *
1145
- * @example
1146
- * const _ = db.command;
1147
- * db.collection("demo").where({
1148
- * num: _.nin([1,2,3])
1149
- * })
1150
- *
1151
- * @param list 数组
1152
- *
1153
- */
1154
- nin(list: any[]): any;
1155
- /**
1156
- * 表示需同时满足指定的两个或以上的条件
1157
- *
1158
- * {@link https://docs.cloudbase.net/api-reference/webv3/database#and}
1159
- *
1160
- * @example
1161
- * const _ = db.command;
1162
- * db.collection("demo").where({
1163
- * num: _.and(_.gt(4), _.lt(32))
1164
- * })
1165
- *
1166
- * @param args 多个条件
1167
- *
1168
- */
1169
- and(...args: any[]): any;
1170
- /**
1171
- * 表示需满足所有指定条件中的至少一个
1172
- *
1173
- * {@link https://docs.cloudbase.net/api-reference/webv3/database#or}
1174
- *
1175
- * @example
1176
- * const _ = db.command;
1177
- * db.collection("demo").where({
1178
- * num: _.or(_.gt(4), _.lt(32))
1179
- * })
1180
- *
1181
- * @param args 多个条件
1182
- *
1183
- */
1184
- or(...args: any[]): any;
1185
- /**
1186
- * 用于设定字段等于指定值
1187
- *
1188
- * {@link https://docs.cloudbase.net/api-reference/webv3/database#set}
1189
- *
1190
- * @example
1191
- * const _ = db.command;
1192
- * db.collection("demo")
1193
- * .doc("doc-id")
1194
- * .update({
1195
- * data: {
1196
- * style: _.set({
1197
- * color: "red"
1198
- * })
1199
- * }
1200
- * });
1201
- *
1202
- * @param val 被设定的属性对象
1203
- *
1204
- */
1205
- set(val: any): any;
1206
- /**
1207
- * 用于指示字段自增某个值
1208
- *
1209
- * {@link https://docs.cloudbase.net/api-reference/webv3/database#inc}
1210
- *
1211
- * @example
1212
- * const _ = db.command;
1213
- * db.collection("demo")
1214
- * .doc("doc-id")
1215
- * .update({
1216
- * count: {
1217
- * favorites: _.inc(1)
1218
- * }
1219
- * });
1220
- *
1221
- * @param val 自增的值
1222
- *
1223
- */
1224
- inc(val: number): any;
1225
- /**
1226
- * 用于指示字段自乘某个值
1227
- *
1228
- * {@link https://docs.cloudbase.net/api-reference/webv3/database#mul}
1229
- *
1230
- * @example
1231
- * const _ = db.command;
1232
- * db.collection("demo")
1233
- * .doc("doc-id")
1234
- * .update({
1235
- * count: {
1236
- * favorites: _.mul(21)
1237
- * }
1238
- * });
1239
- *
1240
- * @param val 自乘的值
1241
- *
1242
- */
1243
- mul(val: number): any;
1244
- /**
1245
- * 用于表示删除某个字段
1246
- *
1247
- * {@link https://docs.cloudbase.net/api-reference/webv3/database#remove}
1248
- *
1249
- * @example
1250
- * const _ = db.command;
1251
- * db.collection("demo")
1252
- * .doc("doc-id")
1253
- * .update({
1254
- * rating: _.remove()
1255
- * });
1256
- *
1257
- */
1258
- remove(): any;
1259
- /**
1260
- * 向数组尾部追加元素
1261
- *
1262
- * {@link https://docs.cloudbase.net/api-reference/webv3/database#push}
1263
- *
1264
- * @example
1265
- * const _ = db.command;
1266
- * db.collection("demo")
1267
- * .doc("doc-id")
1268
- * .update({
1269
- * users: _.push(["aaa", "bbb"])
1270
- * });
1271
- *
1272
- * @param val 支持传入单个元素或数组
1273
- */
1274
- push(val: any): any;
1275
- /**
1276
- * 删除数组尾部元素
1277
- *
1278
- * {@link https://docs.cloudbase.net/api-reference/webv3/database#pop}
1279
- *
1280
- * @example
1281
- * const _ = db.command;
1282
- * db.collection("demo")
1283
- * .doc("doc-id")
1284
- * .update({
1285
- * users: _.pop()
1286
- * });
1287
- *
1288
- */
1289
- pop(): any;
1290
- /**
1291
- * 向数组头部添加元素
1292
- *
1293
- * {@link https://docs.cloudbase.net/api-reference/webv3/database#unshift}
1294
- *
1295
- * @example
1296
- * const _ = db.command;
1297
- * db.collection("demo")
1298
- * .doc("doc-id")
1299
- * .update({
1300
- * users: _.unshift(["aaa", "bbb"])
1301
- * });
1302
- *
1303
- * @param val 支持传入单个元素或数组
1304
- */
1305
- unshift(val: any): any;
1306
- /**
1307
- * 删除数组头部元素
1308
- *
1309
- * {@link https://docs.cloudbase.net/api-reference/webv3/database#shift}
1310
- *
1311
- * @example
1312
- * const _ = db.command;
1313
- * db.collection("demo")
1314
- * .doc("doc-id")
1315
- * .update({
1316
- * users: _.unshift()
1317
- * });
1318
- *
1319
- */
1320
- shift(): any;
1321
- /**
1322
- * 按从近到远的顺序,找出字段值在给定点的附近的文档
1323
- *
1324
- * {@link https://docs.cloudbase.net/api-reference/webv3/database#geonear}
1325
- *
1326
- * @example
1327
- * const _ = db.command;
1328
- * db.collection("demo").where({
1329
- * location: _.geoNear({
1330
- * geometry: new db.Geo.Point(lngA, latA),
1331
- * maxDistance: 1000,
1332
- * minDistance: 0
1333
- * })
1334
- * });
1335
- *
1336
- * @param options
1337
- * @param options.geometry 点的地理位置
1338
- * @param options.maxDistance 【可选】最大距离,米为单位
1339
- * @param options.minDistance 【可选】最小距离,米为单位
1340
- */
1341
- geoNear(options: IGeoNearOptions): any;
1342
- /**
1343
- * 找出字段值在指定 Polygon / MultiPolygon 内的文档,无排序
1344
- *
1345
- * {@link https://docs.cloudbase.net/api-reference/webv3/database#geowithin}
1346
- *
1347
- * @example
1348
- * const _ = db.command;
1349
- * db.collection("demo").where({
1350
- * location: _.geoWithin({
1351
- * geometry: new Polygon({
1352
- * new LineString([...Points])
1353
- * }),
1354
- * })
1355
- * });
1356
- *
1357
- * @param options
1358
- * @param options.geometry 地理位置
1359
- */
1360
- geoWithin(options: IGeoWithinOptions): any;
1361
- /**
1362
- * 找出字段值和给定的地理位置图形相交的文档
1363
- *
1364
- * {@link https://docs.cloudbase.net/api-reference/webv3/database#geointersects}
1365
- *
1366
- * @example
1367
- * const _ = db.command;
1368
- * db.collection("user").where({
1369
- * location: _.geoNear({
1370
- * geometry: new LineString([new Point(lngA, latA), new Point(lngB, latB)]);
1371
- * })
1372
- * });
1373
- *
1374
- * @param options
1375
- * @param options.geometry 地理位置
1376
- */
1377
- geoIntersects(options: IGeoIntersectsOptions): any;
1378
- }
1379
- /**
1380
- * document types
1381
- */
1382
- interface IDocument extends IWatchable {
1383
- /**
1384
- * 更新文档,如果要更新的文档不存在时新增一个文档
1385
- *
1386
- * {@link https://docs.cloudbase.net/api-reference/webv3/database.html#update-set}
1387
- *
1388
- * @example
1389
- * collection
1390
- * .doc('docId')
1391
- * .set({name:'cloudbase'})
1392
- * .then(res=>{})
1393
- *
1394
- * @param data 文档数据
1395
- *
1396
- * @return Promise
1397
- */
1398
- set(data: Object): Promise<SetRes>;
1399
- /**
1400
- * 获取查询结果
1401
- *
1402
- * {@link https://docs.cloudbase.net/api-reference/webv3/database#get}
1403
- *
1404
- * @example
1405
- * collection
1406
- * .doc('docId')
1407
- * .get()
1408
- * .then(res=>{})
1409
- *
1410
- * @return Promise-查询结果
1411
- */
1412
- get(): Promise<GetRes>;
1413
- /**
1414
- * 更新文档,如果要更新的文档不存在什么也不会做
1415
- *
1416
- * {@link https://docs.cloudbase.net/api-reference/webv3/database#update--set}
1417
- *
1418
- * @example
1419
- * collection
1420
- * .doc('docId')
1421
- * .update({name:'cloudbase'})
1422
- * .then(res=>{})
1423
- *
1424
- * @param data 文档数据
1425
- *
1426
- * @return Promise
1427
- */
1428
- update(data: Object): Promise<SetRes>;
1429
- /**
1430
- * 删除一条文档
1431
- *
1432
- * {@link https://docs.cloudbase.net/api-reference/webv3/database.html#remove-2}
1433
- *
1434
- * @example
1435
- * collection
1436
- * .doc('docId')
1437
- * .remove()
1438
- * .then(res=>{})
1439
- *
1440
- * @return Promise
1441
- */
1442
- remove(): Promise<any>;
1443
- }
1444
- /**
1445
- * query types
1446
- */
1447
- interface SetRes {
1448
- code?: string;
1449
- message?: string;
1450
- updated?: number;
1451
- upsertedId?: number;
1452
- requestId: string;
1453
- }
1454
- interface GetRes {
1455
- data: any[];
1456
- requestId: string;
1457
- code?: string;
1458
- message?: string;
1459
- }
1460
-
1461
- interface UpdateRes {
1462
- requestId: string
1463
- updated?: number
1464
- upsertId?: string
1465
- code?: string;
1466
- message?: string;
1467
- }
1468
-
1469
- interface QueryOrder {
1470
- field?: string
1471
- direction?: 'asc' | 'desc'
1472
- }
1473
-
1474
- interface QueryOption {
1475
- // 查询数量
1476
- limit?: number
1477
- // 偏移量
1478
- offset?: number
1479
- // 指定显示或者不显示哪些字段
1480
- projection?: Object
1481
- }
1482
- interface IQuery extends IWatchable {
1483
- /**
1484
- * 获取数据库查询结果
1485
- *
1486
- * {@link https://docs.cloudbase.net/api-reference/webv3/database.html#get}
1487
- *
1488
- * @example
1489
- * collection
1490
- * .where({
1491
- * name: 'cloudbase'
1492
- * })
1493
- * .get()
1494
- * .then(res=>{})
1495
- *
1496
- * @return Promise-查询结果
1497
- */
1498
- get(): Promise<GetRes>;
1499
- /**
1500
- * 更新数据库文档
1501
- *
1502
- * {@link https://docs.cloudbase.net/api-reference/webv3/database.html#update-set}
1503
- *
1504
- * @example
1505
- * collection
1506
- * .where({
1507
- * name: 'cloudbase'
1508
- * })
1509
- * .update({
1510
- * name: 'newCloudbase'
1511
- * })
1512
- * .then(res=>{})
1513
- *
1514
- * @return Promise-查询结果
1515
- */
1516
- update(data: Object): Promise<UpdateRes>
1517
- /**
1518
- * 获取数据库查询结果的数目
1519
- *
1520
- * {@link https://docs.cloudbase.net/api-reference/webv3/database#count}
1521
- *
1522
- * @example
1523
- * collection
1524
- * .where({
1525
- * name: 'cloudbase'
1526
- * })
1527
- * .count()
1528
- * .then(res=>{})
1529
- *
1530
- * @return Promise-查询结果
1531
- */
1532
- count(): Promise<any>;
1533
- /**
1534
- * 设置过滤条件
1535
- *
1536
- * {@link https://docs.cloudbase.net/api-reference/webv3/database#where}
1537
- *
1538
- * @example
1539
- * collection
1540
- * .where({
1541
- * name: 'cloudbase'
1542
- * })
1543
- *
1544
- * @param query 可接收对象作为参数,表示筛选出拥有和传入对象相同的 key-value 的文档
1545
- *
1546
- */
1547
- where(query: Object): ExcludeOf<IQuery, 'where'>;
1548
- /**
1549
- * 指定查询结果集数量上限
1550
- *
1551
- * {@link https://docs.cloudbase.net/api-reference/webv3/database#limit}
1552
- *
1553
- * @example
1554
- * collection
1555
- * .where({
1556
- * name: 'cloudbase'
1557
- * })
1558
- * .limit(1)
1559
- *
1560
- * @param limit 查询结果数量上限
1561
- */
1562
- limit(limit: number): ExcludeOf<IQuery, 'where'>;
1563
- /**
1564
- * 指定查询返回结果时从指定序列后的结果开始返回,常用于分页
1565
- *
1566
- * {@link https://docs.cloudbase.net/api-reference/webv3/database#skip}
1567
- *
1568
- * @example
1569
- * collection
1570
- * .where({
1571
- * name: 'cloudbase'
1572
- * })
1573
- * .skip(4)
1574
- *
1575
- * @param offset 跳过的条目数量
1576
- */
1577
- skip(offset: number): ExcludeOf<IQuery, 'where'>;
1578
- /**
1579
- * 指定查询排序条件
1580
- *
1581
- * {@link https://docs.cloudbase.net/api-reference/webv3/database#orderby}
1582
- *
1583
- * @example
1584
- * collection
1585
- * .where({
1586
- * name: 'cloudbase'
1587
- * })
1588
- * .orderBy("name", "asc")
1589
- *
1590
- * @param field 排序的字段
1591
- * @param orderType 排序的顺序,升序(asc) 或 降序(desc)
1592
- */
1593
- orderBy(field: string, orderType: 'desc' | 'asc'): ExcludeOf<IQuery, 'where'>;
1594
- /**
1595
- * 指定返回结果中文档需返回的字段
1596
- *
1597
- * {@link https://docs.cloudbase.net/api-reference/webv3/database#field}
1598
- *
1599
- * @example
1600
- * collection
1601
- * .where({
1602
- * name: 'cloudbase'
1603
- * })
1604
- * .field({ age: true })
1605
- *
1606
- * @param projection 要过滤的字段集合,不返回传 false,返回传 true
1607
- */
1608
- field(projection: Object): ExcludeOf<IQuery, 'where'>;
1609
- /**
1610
- * 删除查询到的结果
1611
- *
1612
- * {@link https://docs.cloudbase.net/api-reference/webv3/database#remove-1}
1613
- *
1614
- * @example
1615
- * collection
1616
- * .where({
1617
- * name: 'cloudbase'
1618
- * })
1619
- * .remove()
1620
- *
1621
- * @return Promise
1622
- */
1623
- remove(): Promise<any>;
1624
- }
1625
- /**
1626
- * geo types
1627
- */
1628
- interface IPoint { }
1629
- interface ILineString { }
1630
- interface IPolygon { }
1631
- interface IMultiPoint { }
1632
- interface IMultiLineString { }
1633
- interface IMultiPolygon { }
1634
- interface IGeo {
1635
- /**
1636
- * 用于表示地理位置点
1637
- *
1638
- * {@link https://docs.cloudbase.net/api-reference/webv3/database#point}
1639
- *
1640
- * @example
1641
- * const point = new db.Geo.Point(lng,lat);
1642
- *
1643
- * @param longitude 经度
1644
- * @param latitude 纬度
1645
- *
1646
- * @return Point
1647
- */
1648
- Point: {
1649
- new(longitude: number, latitude: number): IPoint;
1650
- };
1651
- /**
1652
- * 用于表示地理路径,是由两个或者更多的 Point 组成的线段
1653
- *
1654
- * {@link https://docs.cloudbase.net/api-reference/webv3/database#linestring}
1655
- *
1656
- * @example
1657
- * const point = new db.Geo.LineString([pointA,pointB]);
1658
- *
1659
- * @param points Point数组
1660
- *
1661
- * @return LineString
1662
- */
1663
- LineString: {
1664
- new(points: IPoint[]): ILineString;
1665
- }
1666
- /**
1667
- * 用于表示地理上的一个多边形
1668
- *
1669
- * {@link https://docs.cloudbase.net/api-reference/webv3/database#polygon}
1670
- *
1671
- * @example
1672
- * const point = new db.Geo.Polygon([lineStringA,lineStringB]);
1673
- *
1674
- * @param lines LineString数组
1675
- *
1676
- * @return Polygon
1677
- */
1678
- Polygon: {
1679
- new(lines: ILineString[]): IPolygon;
1680
- }
1681
- /**
1682
- * 用于表示多个点 Point 的集合
1683
- *
1684
- * {@link https://docs.cloudbase.net/api-reference/webv3/database#multipoint}
1685
- *
1686
- * @example
1687
- * const point = new db.Geo.MultiPoint([pointA,pointB]);
1688
- *
1689
- * @param points Point数组
1690
- *
1691
- * @return MultiPoint
1692
- */
1693
- MultiPoint: {
1694
- new(points: IPoint[]): IMultiPoint;
1695
- }
1696
- /**
1697
- * 用于表示多个地理路径 LineString 的集合
1698
- *
1699
- * {@link https://docs.cloudbase.net/api-reference/webv3/database#multilinestring}
1700
- *
1701
- * @example
1702
- * const point = new db.Geo.MultiLineString([lineA,lineB]);
1703
- *
1704
- * @param lines LineString数组
1705
- *
1706
- * @return MultiLineString
1707
- */
1708
- MultiLineString: {
1709
- new(lines: ILineString[]): IMultiLineString;
1710
- }
1711
- /**
1712
- * 用于表示多个地理多边形 Polygon 的集合
1713
- *
1714
- * {@link https://docs.cloudbase.net/api-reference/webv3/database#multipolygon}
1715
- *
1716
- * @example
1717
- * const point = new db.Geo.MultiPolygon([polygonA,polygonB]);
1718
- *
1719
- * @param polygons Polygon数组
1720
- *
1721
- * @return MultiPolygon
1722
- */
1723
- MultiPolygon: {
1724
- new(polygons: IPolygon[]): IMultiPolygon;
1725
- }
1726
- }
1727
- /**
1728
- * regexp types
1729
- */
1730
- interface IRegExpOptions {
1731
- regexp: string;
1732
- options?: string;
1733
- }
1734
- interface IRegExp {
1735
- (options: IRegExpOptions): any;
1736
- }
1737
- /**
1738
- * instance types
1739
- */
1740
- interface App {
1741
- /**
1742
- * 数据库指令
1743
- *
1744
- * {@link https://docs.cloudbase.net/api-reference/webv3/database#%E6%9F%A5%E8%AF%A2%E6%8C%87%E4%BB%A4}
1745
- */
1746
- command: ICommand;
1747
- /**
1748
- * 数据库Geo地理位置
1749
- *
1750
- * {@link https://docs.cloudbase.net/api-reference/webv3/database.html#geo-shu-ju-lei-xing}
1751
- */
1752
- Geo: IGeo;
1753
- /**
1754
- * 根据正则表达式进行筛选
1755
- *
1756
- * {@link https://docs.cloudbase.net/api-reference/webv3/database.html#regexp}
1757
- *
1758
- * @example
1759
- * db.collection('articles').where({
1760
- * version: new db.RegExp({
1761
- * regexp: '^\\ds' // 正则表达式为 /^\ds/,转义后变成 '^\\ds'
1762
- * options: 'i' // i表示忽略大小写
1763
- * })
1764
- * })
1765
- *
1766
- * @param options
1767
- * @param options.regexp 正则表达式Pattern
1768
- * @param options.options 正则表达式Flags
1769
- */
1770
- RegExp: IRegExp;
1771
- /**
1772
- * 创建集合的引用
1773
- *
1774
- * {@link https://docs.cloudbase.net/api-reference/webv3/database.html#collection}
1775
- *
1776
- * @example
1777
- * const coll = db.collection('demo');
1778
- *
1779
- * @param name 集合名称
1780
- *
1781
- * @return 集合的引用
1782
- */
1783
- collection(name: string): ICollection;
1784
- }
1785
- }
1786
-
1787
9
 
1788
- export default cloudbase;
1789
- export as namespace cloudbase;
10
+ export = cloudbase
11
+ export as namespace cloudbase