@cloudbase/js-sdk 3.3.14-beta.4 → 3.3.14-beta.5
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/ai/dist/index.d.ts +1 -0
- package/ai/dist/index.esm.js +3 -0
- package/ai/dist/index.js +21 -0
- package/ai/src/index.d.ts +1 -0
- package/ai/src/index.ts +1 -0
- package/analytics/dist/index.d.ts +2 -0
- package/analytics/dist/index.esm.js +4 -0
- package/analytics/dist/index.js +9 -0
- package/analytics/src/index.d.ts +2 -0
- package/analytics/src/index.ts +4 -0
- package/apis/dist/index.d.ts +1 -0
- package/apis/dist/index.esm.js +3 -0
- package/apis/dist/index.js +21 -0
- package/apis/src/index.d.ts +1 -0
- package/apis/src/index.ts +1 -0
- package/app/dist/index.d.ts +9 -0
- package/app/dist/index.esm.js +11 -0
- package/app/dist/index.js +18 -0
- package/app/src/index.d.ts +9 -0
- package/app/src/index.ts +17 -0
- package/auth/dist/index.d.ts +2 -0
- package/auth/dist/index.esm.js +8 -0
- package/auth/dist/index.js +13 -0
- package/auth/src/index.d.ts +2 -0
- package/auth/src/index.ts +8 -0
- package/cloudrun/dist/index.d.ts +1 -0
- package/cloudrun/dist/index.esm.js +3 -0
- package/cloudrun/dist/index.js +21 -0
- package/cloudrun/src/index.d.ts +1 -0
- package/cloudrun/src/index.ts +1 -0
- package/container/dist/index.d.ts +2 -0
- package/container/dist/index.esm.js +8 -0
- package/container/dist/index.js +13 -0
- package/container/src/index.d.ts +2 -0
- package/container/src/index.ts +8 -0
- package/database/dist/index.d.ts +3 -0
- package/database/dist/index.esm.js +503 -0
- package/database/dist/index.js +509 -0
- package/database/src/index.d.ts +3 -0
- package/database/src/index.ts +486 -0
- package/dist/index.cjs.js +1 -1
- package/dist/index.esm.js +35 -0
- package/functions/dist/index.d.ts +2 -0
- package/functions/dist/index.esm.js +8 -0
- package/functions/dist/index.js +13 -0
- package/functions/src/index.d.ts +2 -0
- package/functions/src/index.ts +8 -0
- package/miniprogram_dist/index.js +1 -1
- package/model/dist/index.d.ts +1 -0
- package/model/dist/index.esm.js +3 -0
- package/model/dist/index.js +21 -0
- package/model/src/index.d.ts +1 -0
- package/model/src/index.ts +1 -0
- package/mysql/dist/index.d.ts +1 -0
- package/mysql/dist/index.esm.js +3 -0
- package/mysql/dist/index.js +21 -0
- package/mysql/src/index.d.ts +1 -0
- package/mysql/src/index.ts +1 -0
- package/oauth/dist/index.d.ts +1 -0
- package/oauth/dist/index.esm.js +3 -0
- package/oauth/dist/index.js +21 -0
- package/oauth/src/index.d.ts +1 -0
- package/oauth/src/index.ts +1 -0
- package/package.json +19 -5
- package/realtime/dist/index.d.ts +2 -0
- package/realtime/dist/index.esm.js +8 -0
- package/realtime/dist/index.js +13 -0
- package/realtime/src/index.d.ts +2 -0
- package/realtime/src/index.ts +8 -0
- package/storage/dist/index.d.ts +2 -0
- package/storage/dist/index.esm.js +4 -0
- package/storage/dist/index.js +9 -0
- package/storage/src/index.d.ts +2 -0
- package/storage/src/index.js +5 -0
- package/storage/src/index.ts +4 -0
|
@@ -0,0 +1,486 @@
|
|
|
1
|
+
import { Db } from '@cloudbase/database'
|
|
2
|
+
import { ICloudbase } from '@cloudbase/types'
|
|
3
|
+
import { ICloudbaseComponent } from '@cloudbase/types/component'
|
|
4
|
+
import cloudbaseNS from '../../index'
|
|
5
|
+
import { EJSON } from 'bson'
|
|
6
|
+
|
|
7
|
+
declare const cloudbase: ICloudbase
|
|
8
|
+
declare type QueryType = 'WHERE' | 'DOC'
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* 数据库配置接口
|
|
12
|
+
*/
|
|
13
|
+
interface IDbConfig {
|
|
14
|
+
/** 实例 ID(可选,默认 '(default)') */
|
|
15
|
+
instance?: string
|
|
16
|
+
/** 数据库名称(可选,默认 '(default)') */
|
|
17
|
+
database?: string
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
interface IBaseReq extends IDbConfig {
|
|
21
|
+
collectionName: string
|
|
22
|
+
transactionId?: string
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
interface IDocumentsQueryReq extends IBaseReq {
|
|
26
|
+
query?: any
|
|
27
|
+
/** @deprecated 使用 query 替代 */
|
|
28
|
+
queryType?: QueryType
|
|
29
|
+
order?: string[]
|
|
30
|
+
offset?: number
|
|
31
|
+
limit?: number
|
|
32
|
+
projection?: Object
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
interface IDocumentsAddReq extends IBaseReq {
|
|
36
|
+
data: Object | Object[]
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
interface IDocumentsUpdateReq extends IBaseReq {
|
|
40
|
+
query: Object
|
|
41
|
+
data: Object
|
|
42
|
+
/** 是否批量更新(默认 false) */
|
|
43
|
+
multi?: boolean
|
|
44
|
+
/** 把所有更新数据转为带操作符的 */
|
|
45
|
+
merge?: boolean
|
|
46
|
+
/** 不存在时是否创建(默认 false) */
|
|
47
|
+
upsert?: boolean
|
|
48
|
+
/** 是否替换整个文档(默认 false,为 true 时替换整个文档而非合并更新) */
|
|
49
|
+
replaceMode?: boolean
|
|
50
|
+
/** @deprecated 使用 query 替代 */
|
|
51
|
+
queryType?: QueryType
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
interface IDocumentsRemoveReq extends IBaseReq {
|
|
55
|
+
query: Object
|
|
56
|
+
/** 是否批量删除(默认 false) */
|
|
57
|
+
multi?: boolean
|
|
58
|
+
/** @deprecated 使用 query 替代 */
|
|
59
|
+
queryType?: QueryType
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
interface IDocumentsCountReq extends IBaseReq {
|
|
63
|
+
query: Object
|
|
64
|
+
/** @deprecated 使用 query 替代 */
|
|
65
|
+
queryType?: QueryType
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
interface ICommonRes<T> {
|
|
69
|
+
data?: T & { code?: string }
|
|
70
|
+
requestId: string
|
|
71
|
+
code?: string
|
|
72
|
+
message?: string
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
interface IAddRes {
|
|
76
|
+
/** 单条插入时返回的文档 ID(批量插入时不返回) */
|
|
77
|
+
_id?: string
|
|
78
|
+
/** 批量插入时返回的文档 ID 列表 */
|
|
79
|
+
ids?: string[]
|
|
80
|
+
insertedIds: string[]
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
interface IRunCommandsReq {
|
|
84
|
+
transactionId?: string
|
|
85
|
+
/** 命令数组,方法会将其转为 MongoDB 原生命令(EJSON 对象格式) */
|
|
86
|
+
commands: Object[]
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const COMPONENT_NAME = 'database'
|
|
90
|
+
|
|
91
|
+
const gateWayFunc = {
|
|
92
|
+
/**
|
|
93
|
+
* 过滤响应,移除不必要的字段
|
|
94
|
+
*/
|
|
95
|
+
filterRes: function <T>(res: ICommonRes<T> & { header?: any; statusCode?: number }): ICommonRes<T> {
|
|
96
|
+
delete res.header
|
|
97
|
+
delete res.statusCode
|
|
98
|
+
return res
|
|
99
|
+
},
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* 展开响应数据到顶层(用于事务等场景)
|
|
103
|
+
*/
|
|
104
|
+
flattenResData: function <T>(res: ICommonRes<T>): any {
|
|
105
|
+
if (typeof res.data === 'object' && res.data !== null) {
|
|
106
|
+
const result = { ...res, ...res.data }
|
|
107
|
+
delete result.data
|
|
108
|
+
return result
|
|
109
|
+
}
|
|
110
|
+
return res
|
|
111
|
+
},
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* 安全解析 EJSON
|
|
115
|
+
*/
|
|
116
|
+
safeParseEJSON: function (data: any): any {
|
|
117
|
+
if (typeof data !== 'string') return data
|
|
118
|
+
try {
|
|
119
|
+
return EJSON.parse(data)
|
|
120
|
+
} catch {
|
|
121
|
+
return data
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* 构建 URL 查询参数
|
|
127
|
+
*/
|
|
128
|
+
buildQueryParams: function (params: Record<string, any>): string {
|
|
129
|
+
return Object.entries(params)
|
|
130
|
+
.filter(([_, value]) => value !== undefined && value !== null && value !== '')
|
|
131
|
+
.map(([key, value]) => {
|
|
132
|
+
const stringValue = typeof value === 'object' ? JSON.stringify(value) : String(value)
|
|
133
|
+
return `${encodeURIComponent(key)}=${encodeURIComponent(stringValue)}`
|
|
134
|
+
})
|
|
135
|
+
.join('&')
|
|
136
|
+
},
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* 获取 URL 前缀
|
|
140
|
+
*/
|
|
141
|
+
getUrlPrefix: function (data: IDbConfig): string {
|
|
142
|
+
const instance = data?.instance || '(default)'
|
|
143
|
+
const database = data?.database || '(default)'
|
|
144
|
+
return `/database/instances/${instance}/databases/${database}`
|
|
145
|
+
},
|
|
146
|
+
|
|
147
|
+
'database.queryDocument': async function (
|
|
148
|
+
data: IDocumentsQueryReq,
|
|
149
|
+
): Promise<ICommonRes<{ offset?: number; limit?: number; list: any[] }>> {
|
|
150
|
+
const isQueryDoc = !!data.query?._id
|
|
151
|
+
const queryParams = gateWayFunc.buildQueryParams({
|
|
152
|
+
projection: data.projection,
|
|
153
|
+
transactionId: data.transactionId,
|
|
154
|
+
...(isQueryDoc
|
|
155
|
+
? {}
|
|
156
|
+
: {
|
|
157
|
+
offset: data.offset ?? 0,
|
|
158
|
+
limit: data.limit ?? 100,
|
|
159
|
+
order: data.order,
|
|
160
|
+
query: data.query ? EJSON.stringify(data.query, { relaxed: false }) : undefined,
|
|
161
|
+
}),
|
|
162
|
+
})
|
|
163
|
+
|
|
164
|
+
let url = `${gateWayFunc.getUrlPrefix(data)}/collections/${data.collectionName}/documents?${queryParams}`
|
|
165
|
+
|
|
166
|
+
// 查询单个文档
|
|
167
|
+
if (isQueryDoc) {
|
|
168
|
+
url = `${gateWayFunc.getUrlPrefix(data)}/collections/${data.collectionName}/documents/${
|
|
169
|
+
data.query._id?.$eq || data.query._id
|
|
170
|
+
}?${queryParams}`
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
const res = await this.gateWay({
|
|
174
|
+
url,
|
|
175
|
+
method: 'GET',
|
|
176
|
+
})
|
|
177
|
+
|
|
178
|
+
// 尝试解析 EJSON 格式的数据
|
|
179
|
+
res.data = gateWayFunc.safeParseEJSON(JSON.stringify(res.data))
|
|
180
|
+
|
|
181
|
+
if (isQueryDoc && !res.code && !res.data?.code) {
|
|
182
|
+
return {
|
|
183
|
+
...res,
|
|
184
|
+
data: { list: [res.data] }
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
return gateWayFunc.filterRes(res)
|
|
189
|
+
},
|
|
190
|
+
|
|
191
|
+
'database.addDocument': async function (data: IDocumentsAddReq): Promise<ICommonRes<IAddRes>> {
|
|
192
|
+
let res = await this.gateWay({
|
|
193
|
+
url: `${gateWayFunc.getUrlPrefix(data)}/collections/${data.collectionName}/documents`,
|
|
194
|
+
method: 'POST',
|
|
195
|
+
data: {
|
|
196
|
+
data: Array.isArray(data.data) ? data.data : [data.data],
|
|
197
|
+
...(data.transactionId && { transactionId: data.transactionId }),
|
|
198
|
+
},
|
|
199
|
+
})
|
|
200
|
+
|
|
201
|
+
if (Array.isArray(data.data)) {
|
|
202
|
+
// 数组模式(批量插入),返回 ids 列表
|
|
203
|
+
res = {
|
|
204
|
+
...res,
|
|
205
|
+
data: {
|
|
206
|
+
ids: res.data?.insertedIds || [],
|
|
207
|
+
...res.data,
|
|
208
|
+
},
|
|
209
|
+
}
|
|
210
|
+
} else if (res.data?.insertedIds?.[0]) {
|
|
211
|
+
// 非数组模式(单条插入),将 _id 提升到顶层
|
|
212
|
+
res = {
|
|
213
|
+
...res,
|
|
214
|
+
data: {
|
|
215
|
+
_id: res.data.insertedIds[0],
|
|
216
|
+
...res.data,
|
|
217
|
+
},
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
return gateWayFunc.filterRes(res)
|
|
222
|
+
},
|
|
223
|
+
|
|
224
|
+
'database.updateDocument': async function (
|
|
225
|
+
data: IDocumentsUpdateReq,
|
|
226
|
+
): Promise<ICommonRes<{ matched: number; updated: number; upsert_id: string }>> {
|
|
227
|
+
const res = await this.gateWay({
|
|
228
|
+
url: `${gateWayFunc.getUrlPrefix(data)}/collections/${data.collectionName}/documents`,
|
|
229
|
+
method: 'PATCH',
|
|
230
|
+
data: {
|
|
231
|
+
query: data.query,
|
|
232
|
+
data: data.data,
|
|
233
|
+
multi: !!data.multi,
|
|
234
|
+
upsert: !!data.upsert,
|
|
235
|
+
replaceMode: !!data.replaceMode,
|
|
236
|
+
...(data.transactionId && { transactionId: data.transactionId }),
|
|
237
|
+
},
|
|
238
|
+
})
|
|
239
|
+
|
|
240
|
+
return gateWayFunc.filterRes(res)
|
|
241
|
+
},
|
|
242
|
+
|
|
243
|
+
'database.deleteDocument': async function (data: IDocumentsRemoveReq): Promise<ICommonRes<{ deleted: number }>> {
|
|
244
|
+
const res = await this.gateWay({
|
|
245
|
+
url: `${gateWayFunc.getUrlPrefix(data)}/collections/${data.collectionName}/documents/remove`,
|
|
246
|
+
method: 'POST',
|
|
247
|
+
data: {
|
|
248
|
+
query: data.query,
|
|
249
|
+
multi: !!data.multi,
|
|
250
|
+
...(data.transactionId && { transactionId: data.transactionId }),
|
|
251
|
+
},
|
|
252
|
+
})
|
|
253
|
+
|
|
254
|
+
return gateWayFunc.filterRes(res)
|
|
255
|
+
},
|
|
256
|
+
|
|
257
|
+
'database.countDocument': async function (data: IDocumentsCountReq): Promise<ICommonRes<{ total: number }>> {
|
|
258
|
+
const queryParams = gateWayFunc.buildQueryParams({
|
|
259
|
+
count: true,
|
|
260
|
+
query: data.query ? EJSON.stringify(data.query, { relaxed: false }) : undefined,
|
|
261
|
+
})
|
|
262
|
+
|
|
263
|
+
const res = await this.gateWay({
|
|
264
|
+
url: `${gateWayFunc.getUrlPrefix(data)}/collections/${data.collectionName}/documents?${queryParams}`,
|
|
265
|
+
method: 'GET',
|
|
266
|
+
})
|
|
267
|
+
|
|
268
|
+
return gateWayFunc.filterRes(res)
|
|
269
|
+
},
|
|
270
|
+
|
|
271
|
+
'database.addCollection': async function (data: { collectionName: string } & IDbConfig): Promise<ICommonRes<''>> {
|
|
272
|
+
const res = await this.gateWay({
|
|
273
|
+
url: `${gateWayFunc.getUrlPrefix(data)}/collections`,
|
|
274
|
+
method: 'POST',
|
|
275
|
+
data: { collectionName: data.collectionName },
|
|
276
|
+
})
|
|
277
|
+
|
|
278
|
+
return gateWayFunc.filterRes(res)
|
|
279
|
+
},
|
|
280
|
+
|
|
281
|
+
'database.aggregate': async function (
|
|
282
|
+
data: { collectionName: string; stages: { stageKey: string; stageValue: any }[] } & IDbConfig,
|
|
283
|
+
): Promise<ICommonRes<{ list: string }>> {
|
|
284
|
+
const pipeline = data.stages.map((stage) => {
|
|
285
|
+
try {
|
|
286
|
+
// stageValue 可能是字符串或对象,统一处理
|
|
287
|
+
const value = typeof stage.stageValue === 'string' ? JSON.parse(stage.stageValue) : stage.stageValue
|
|
288
|
+
return {
|
|
289
|
+
[stage.stageKey]: EJSON.serialize(value),
|
|
290
|
+
}
|
|
291
|
+
} catch {
|
|
292
|
+
return { [stage.stageKey]: stage.stageValue }
|
|
293
|
+
}
|
|
294
|
+
})
|
|
295
|
+
|
|
296
|
+
const res = await this.gateWay({
|
|
297
|
+
url: `${gateWayFunc.getUrlPrefix(data)}/collections/${data.collectionName}/documents/aggregations`,
|
|
298
|
+
method: 'POST',
|
|
299
|
+
data: { pipeline },
|
|
300
|
+
})
|
|
301
|
+
|
|
302
|
+
// 将结果列表转为字符串格式(兼容原有逻辑)
|
|
303
|
+
if (Array.isArray(res.data?.list)) {
|
|
304
|
+
res.data.list = JSON.stringify(res.data.list.map((item: any) => JSON.stringify(item)))
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
return gateWayFunc.filterRes(res)
|
|
308
|
+
},
|
|
309
|
+
|
|
310
|
+
'database.startTransaction': async function (data: IDbConfig) {
|
|
311
|
+
const res = await this.gateWay({
|
|
312
|
+
url: `${gateWayFunc.getUrlPrefix(data)}/transactions`,
|
|
313
|
+
method: 'POST',
|
|
314
|
+
})
|
|
315
|
+
|
|
316
|
+
return gateWayFunc.filterRes(gateWayFunc.flattenResData(res))
|
|
317
|
+
},
|
|
318
|
+
|
|
319
|
+
'database.commitTransaction': async function (data: { transactionId: string } & IDbConfig) {
|
|
320
|
+
const res = await this.gateWay({
|
|
321
|
+
url: `${gateWayFunc.getUrlPrefix(data)}/transactions/${data.transactionId}/commit`,
|
|
322
|
+
method: 'POST',
|
|
323
|
+
})
|
|
324
|
+
|
|
325
|
+
return gateWayFunc.filterRes(res)
|
|
326
|
+
},
|
|
327
|
+
|
|
328
|
+
'database.abortTransaction': async function (data: { transactionId: string } & IDbConfig) {
|
|
329
|
+
const res = await this.gateWay({
|
|
330
|
+
url: `${gateWayFunc.getUrlPrefix(data)}/transactions/${data.transactionId}/rollback`,
|
|
331
|
+
method: 'POST',
|
|
332
|
+
})
|
|
333
|
+
|
|
334
|
+
return gateWayFunc.filterRes(res)
|
|
335
|
+
},
|
|
336
|
+
|
|
337
|
+
'database.getInTransaction': async function (data: IDocumentsQueryReq) {
|
|
338
|
+
const res = await gateWayFunc['database.queryDocument'].call(this, data)
|
|
339
|
+
|
|
340
|
+
if (typeof res.data === 'object' && res.data !== null) {
|
|
341
|
+
if (res.data?.code) {
|
|
342
|
+
return gateWayFunc.flattenResData(res)
|
|
343
|
+
}
|
|
344
|
+
return { ...res, data: JSON.stringify(res.data) as any }
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
return res
|
|
348
|
+
},
|
|
349
|
+
|
|
350
|
+
'database.updateDocInTransaction': async function (data: IDocumentsUpdateReq) {
|
|
351
|
+
// 尝试解析 EJSON 格式的数据
|
|
352
|
+
data.data = gateWayFunc.safeParseEJSON(data.data)
|
|
353
|
+
|
|
354
|
+
const res = await gateWayFunc['database.updateDocument'].call(this, data)
|
|
355
|
+
return gateWayFunc.flattenResData(res)
|
|
356
|
+
},
|
|
357
|
+
|
|
358
|
+
'database.deleteDocInTransaction': async function (data: IDocumentsRemoveReq) {
|
|
359
|
+
const res = await gateWayFunc['database.deleteDocument'].call(this, data)
|
|
360
|
+
return gateWayFunc.flattenResData(res)
|
|
361
|
+
},
|
|
362
|
+
|
|
363
|
+
'database.insertDocInTransaction': async function (
|
|
364
|
+
data: IDocumentsAddReq,
|
|
365
|
+
): Promise<ICommonRes<IAddRes & { inserted?: number }>> {
|
|
366
|
+
// 尝试解析 EJSON 格式的数据
|
|
367
|
+
data.data = gateWayFunc.safeParseEJSON(data.data)
|
|
368
|
+
|
|
369
|
+
let res = await gateWayFunc['database.addDocument'].call(this, data)
|
|
370
|
+
|
|
371
|
+
if (typeof res.data === 'object' && res.data !== null) {
|
|
372
|
+
const hasId = !!res.data?._id
|
|
373
|
+
res = {
|
|
374
|
+
...res,
|
|
375
|
+
inserted: hasId ? 1 : 0,
|
|
376
|
+
ok: hasId ? 1 : 0,
|
|
377
|
+
...res.data,
|
|
378
|
+
} as any
|
|
379
|
+
} else {
|
|
380
|
+
res = { inserted: 0, ok: 0, ...res } as any
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
delete res.data
|
|
384
|
+
|
|
385
|
+
return res
|
|
386
|
+
},
|
|
387
|
+
|
|
388
|
+
'database.runCommands': async function (
|
|
389
|
+
data: IRunCommandsReq & IDbConfig,
|
|
390
|
+
): Promise<ICommonRes<{ list: Object[][] }>> {
|
|
391
|
+
let res = await this.gateWay({
|
|
392
|
+
url: `${gateWayFunc.getUrlPrefix(data)}/commands`,
|
|
393
|
+
method: 'POST',
|
|
394
|
+
data: {
|
|
395
|
+
commands: EJSON.serialize(data.commands),
|
|
396
|
+
...(data.transactionId && { transactionId: data.transactionId }),
|
|
397
|
+
},
|
|
398
|
+
})
|
|
399
|
+
|
|
400
|
+
if (typeof res.data === 'object' && res.data !== null) {
|
|
401
|
+
res = { ...res, ...res.data }
|
|
402
|
+
delete res.data
|
|
403
|
+
delete res.request_id
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
// 尝试将结果转换为普通对象
|
|
407
|
+
try {
|
|
408
|
+
res = EJSON.deserialize(res)
|
|
409
|
+
} catch {
|
|
410
|
+
// 忽略转换失败
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
return gateWayFunc.filterRes(res)
|
|
414
|
+
},
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
function database(dbConfig?: IDbConfig) {
|
|
418
|
+
const { adapter, runtime } = this.platform
|
|
419
|
+
|
|
420
|
+
class Req extends this.request.constructor {
|
|
421
|
+
constructor(config) {
|
|
422
|
+
super(config)
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
async send(action: string, data: any) {
|
|
426
|
+
let res = null
|
|
427
|
+
|
|
428
|
+
if (this.config.endPointMode === 'GATEWAY' && gateWayFunc[action]) {
|
|
429
|
+
res = await gateWayFunc[action].call(this, data)
|
|
430
|
+
} else {
|
|
431
|
+
res = await super.send(action, data)
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
return res
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
Db.reqClass = Req
|
|
439
|
+
// 未登录情况下传入空函数
|
|
440
|
+
Db.getAccessToken = this.authInstance ? this.authInstance.getAccessToken.bind(this.authInstance) : () => ''
|
|
441
|
+
Db.runtime = runtime
|
|
442
|
+
if (this.wsClientClass) {
|
|
443
|
+
Db.wsClass = adapter.wsClass
|
|
444
|
+
Db.wsClientClass = this.wsClientClass
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
if (!Db.ws) {
|
|
448
|
+
Db.ws = null
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
class NewDb extends Db {
|
|
452
|
+
constructor(config?: IDbConfig) {
|
|
453
|
+
super(config)
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
async runCommands(params: IRunCommandsReq): Promise<ICommonRes<{ list: Object[][] }>> {
|
|
457
|
+
let request = Db.createRequest(this.config)
|
|
458
|
+
|
|
459
|
+
return request.send('database.runCommands', params)
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
return new NewDb({ ...this.config, _fromApp: this, ...dbConfig })
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
const component: ICloudbaseComponent = {
|
|
467
|
+
name: COMPONENT_NAME,
|
|
468
|
+
entity: {
|
|
469
|
+
database,
|
|
470
|
+
},
|
|
471
|
+
}
|
|
472
|
+
try {
|
|
473
|
+
cloudbase.registerComponent(component)
|
|
474
|
+
} catch (e) {}
|
|
475
|
+
|
|
476
|
+
export function registerDatabase(app: ICloudbase | typeof cloudbaseNS) {
|
|
477
|
+
try {
|
|
478
|
+
app.registerComponent(component)
|
|
479
|
+
} catch (e) {
|
|
480
|
+
console.warn(e)
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
try {
|
|
485
|
+
;(window as any).registerDatabase = registerDatabase
|
|
486
|
+
} catch (e) {}
|
package/dist/index.cjs.js
CHANGED
|
@@ -14,7 +14,7 @@ var cloudrun_1 = require("@cloudbase/cloudrun");
|
|
|
14
14
|
var mysql_1 = require("@cloudbase/mysql");
|
|
15
15
|
var apis_1 = require("@cloudbase/apis");
|
|
16
16
|
var database_1 = require("./../database");
|
|
17
|
-
var version = "3.3.14-beta.
|
|
17
|
+
var version = "3.3.14-beta.4";
|
|
18
18
|
app_1.default.registerVersion(version);
|
|
19
19
|
try {
|
|
20
20
|
(0, auth_1.registerAuth)(app_1.default);
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import cloudbase from '@cloudbase/app';
|
|
2
|
+
import { registerAuth } from '@cloudbase/auth';
|
|
3
|
+
import { registerFunctions } from '@cloudbase/functions';
|
|
4
|
+
import { registerStorage } from '@cloudbase/storage';
|
|
5
|
+
import { registerRealtime } from '@cloudbase/realtime';
|
|
6
|
+
import { registerAnalytics } from '@cloudbase/analytics';
|
|
7
|
+
import { registerModel } from '@cloudbase/model';
|
|
8
|
+
import { registerAi } from '@cloudbase/ai';
|
|
9
|
+
import { registerCloudrun } from '@cloudbase/cloudrun';
|
|
10
|
+
import { registerMySQL } from '@cloudbase/mysql';
|
|
11
|
+
import { registerApis } from '@cloudbase/apis';
|
|
12
|
+
import { registerDatabase } from './../database';
|
|
13
|
+
var version = "3.3.14-beta.4";
|
|
14
|
+
cloudbase.registerVersion(version);
|
|
15
|
+
try {
|
|
16
|
+
registerAuth(cloudbase);
|
|
17
|
+
registerFunctions(cloudbase);
|
|
18
|
+
registerStorage(cloudbase);
|
|
19
|
+
registerDatabase(cloudbase);
|
|
20
|
+
registerRealtime(cloudbase);
|
|
21
|
+
registerAnalytics(cloudbase);
|
|
22
|
+
registerModel(cloudbase);
|
|
23
|
+
registerAi(cloudbase);
|
|
24
|
+
registerCloudrun(cloudbase);
|
|
25
|
+
registerMySQL(cloudbase);
|
|
26
|
+
registerApis(cloudbase);
|
|
27
|
+
}
|
|
28
|
+
catch (e) { }
|
|
29
|
+
try {
|
|
30
|
+
window.cloudbase = cloudbase;
|
|
31
|
+
}
|
|
32
|
+
catch (e) { }
|
|
33
|
+
export default cloudbase;
|
|
34
|
+
|
|
35
|
+
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL2luZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sU0FBUyxNQUFNLGdCQUFnQixDQUFBO0FBQ3RDLE9BQU8sRUFBRSxZQUFZLEVBQUUsTUFBTSxpQkFBaUIsQ0FBQTtBQUM5QyxPQUFPLEVBQUUsaUJBQWlCLEVBQUUsTUFBTSxzQkFBc0IsQ0FBQTtBQUN4RCxPQUFPLEVBQUUsZUFBZSxFQUFFLE1BQU0sb0JBQW9CLENBQUE7QUFDcEQsT0FBTyxFQUFFLGdCQUFnQixFQUFFLE1BQU0scUJBQXFCLENB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from '@cloudbase/functions';
|
|
2
|
+
export var registerFunctions = registerFunctionsOrigin;
|
|
3
|
+
try {
|
|
4
|
+
window.registerFunctions = registerFunctions;
|
|
5
|
+
}
|
|
6
|
+
catch (e) { }
|
|
7
|
+
|
|
8
|
+
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImluZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sRUFBRSxpQkFBaUIsSUFBSSx1QkFBdUIsRUFBRSxNQUFNLHNCQUFzQixDQUFDO0FBR3BGLE1BQU0sQ0FBQyxJQUFNLGlCQUFpQixHQUFHLHVCQUF1RCxDQUFDO0FBRXpGLElBQUk7SUFDRCxNQUFjLENBQUMsaUJBQWlCLEdBQUcsaUJBQWlCLENBQUE7Q0FDdEQ7QUFBQyxPQUFPLENBQUMsRUFBRSxHQUFFIiwiZmlsZSI6ImluZGV4LmVzbS5qcyIsInNvdXJjZXNDb250ZW50IjpbImltcG9ydCB7IHJlZ2lzdGVyRnVuY3Rpb25zIGFzIHJlZ2lzdGVyRnVuY3Rpb25zT3JpZ2luIH0gZnJvbSAnQGNsb3VkYmFzZS9mdW5jdGlvbnMnO1xuaW1wb3J0IGNsb3VkYmFzZSBmcm9tICcuLi8uLi9pbmRleCc7XG5cbmV4cG9ydCBjb25zdCByZWdpc3RlckZ1bmN0aW9ucyA9IHJlZ2lzdGVyRnVuY3Rpb25zT3JpZ2luIGFzIChhcHA6dHlwZW9mIGNsb3VkYmFzZSk9PnZvaWQ7XG5cbnRyeSB7XG4gICh3aW5kb3cgYXMgYW55KS5yZWdpc3RlckZ1bmN0aW9ucyA9IHJlZ2lzdGVyRnVuY3Rpb25zXG59IGNhdGNoIChlKSB7fSJdfQ==
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.registerFunctions = void 0;
|
|
4
|
+
var functions_1 = require("@cloudbase/functions");
|
|
5
|
+
exports.registerFunctions = functions_1.registerFunctions;
|
|
6
|
+
try {
|
|
7
|
+
window.registerFunctions = exports.registerFunctions;
|
|
8
|
+
}
|
|
9
|
+
catch (e) { }
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImluZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7OztBQUFBLGtEQUFvRjtBQUd2RSxRQUFBLGlCQUFpQixHQUFHLDZCQUF1RCxDQUFDO0FBRXpGLElBQUk7SUFDRCxNQUFjLENBQUMsaUJBQWlCLEdBQUcseUJBQWlCLENBQUE7Q0FDdEQ7QUFBQyxPQUFPLENBQUMsRUFBRSxHQUFFIiwiZmlsZSI6ImluZGV4LmpzIiwic291cmNlc0NvbnRlbnQiOlsiaW1wb3J0IHsgcmVnaXN0ZXJGdW5jdGlvbnMgYXMgcmVnaXN0ZXJGdW5jdGlvbnNPcmlnaW4gfSBmcm9tICdAY2xvdWRiYXNlL2Z1bmN0aW9ucyc7XG5pbXBvcnQgY2xvdWRiYXNlIGZyb20gJy4uLy4uL2luZGV4JztcblxuZXhwb3J0IGNvbnN0IHJlZ2lzdGVyRnVuY3Rpb25zID0gcmVnaXN0ZXJGdW5jdGlvbnNPcmlnaW4gYXMgKGFwcDp0eXBlb2YgY2xvdWRiYXNlKT0+dm9pZDtcblxudHJ5IHtcbiAgKHdpbmRvdyBhcyBhbnkpLnJlZ2lzdGVyRnVuY3Rpb25zID0gcmVnaXN0ZXJGdW5jdGlvbnNcbn0gY2F0Y2ggKGUpIHt9Il19
|
|
12
|
+
|
|
13
|
+
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImluZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7OztBQUFBLGtEQUFvRjtBQUd2RSxRQUFBLGlCQUFpQixHQUFHLDZCQUF1RCxDQUFDO0FBRXpGLElBQUk7SUFDRCxNQUFjLENBQUMsaUJBQWlCLEdBQUcseUJBQWlCLENBQUE7Q0FDdEQ7QUFBQyxPQUFPLENBQUMsRUFBRSxHQUFFIiwiZmlsZSI6ImluZGV4LmpzIiwic291cmNlc0NvbnRlbnQiOlsiaW1wb3J0IHsgcmVnaXN0ZXJGdW5jdGlvbnMgYXMgcmVnaXN0ZXJGdW5jdGlvbnNPcmlnaW4gfSBmcm9tICdAY2xvdWRiYXNlL2Z1bmN0aW9ucyc7XG5pbXBvcnQgY2xvdWRiYXNlIGZyb20gJy4uLy4uL2luZGV4JztcblxuZXhwb3J0IGNvbnN0IHJlZ2lzdGVyRnVuY3Rpb25zID0gcmVnaXN0ZXJGdW5jdGlvbnNPcmlnaW4gYXMgKGFwcDp0eXBlb2YgY2xvdWRiYXNlKT0+dm9pZDtcblxudHJ5IHtcbiAgKHdpbmRvdyBhcyBhbnkpLnJlZ2lzdGVyRnVuY3Rpb25zID0gcmVnaXN0ZXJGdW5jdGlvbnNcbn0gY2F0Y2ggKGUpIHt9Il19
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { registerFunctions as registerFunctionsOrigin } from '@cloudbase/functions';
|
|
2
|
+
import cloudbase from '../../index';
|
|
3
|
+
|
|
4
|
+
export const registerFunctions = registerFunctionsOrigin as (app:typeof cloudbase)=>void;
|
|
5
|
+
|
|
6
|
+
try {
|
|
7
|
+
(window as any).registerFunctions = registerFunctions
|
|
8
|
+
} catch (e) {}
|