@cloudbase/manager-node 4.2.3 → 4.2.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.
Files changed (54) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/lib/constant.js +5 -1
  3. package/lib/env/index.js +10 -209
  4. package/lib/function/index.js +0 -3
  5. package/lib/storage/index.js +24 -10
  6. package/lib/utils/cloud-api-request.js +7 -0
  7. package/lib/utils/http-request.js +3 -3
  8. package/lib/utils/runenv.js +8 -0
  9. package/package.json +4 -3
  10. package/types/constant.d.ts +7 -0
  11. package/types/env/index.d.ts +0 -17
  12. package/types/function/types.d.ts +0 -2
  13. package/types/utils/runenv.d.ts +1 -0
  14. package/src/access/index.ts +0 -168
  15. package/src/access/types.ts +0 -55
  16. package/src/billing/index.ts +0 -43
  17. package/src/cam/index.ts +0 -106
  18. package/src/cloudBaseRun/index.ts +0 -40
  19. package/src/cloudBaseRun/types.ts +0 -24
  20. package/src/common/index.ts +0 -54
  21. package/src/constant.ts +0 -56
  22. package/src/context.ts +0 -18
  23. package/src/database/index.ts +0 -369
  24. package/src/debug.ts +0 -34
  25. package/src/env/index.ts +0 -614
  26. package/src/environment.ts +0 -156
  27. package/src/environmentManager.ts +0 -50
  28. package/src/error.ts +0 -27
  29. package/src/function/index.ts +0 -1378
  30. package/src/function/packer.ts +0 -164
  31. package/src/function/types.ts +0 -165
  32. package/src/hosting/index.ts +0 -698
  33. package/src/index.ts +0 -127
  34. package/src/interfaces/base.interface.ts +0 -8
  35. package/src/interfaces/billing.interface.ts +0 -21
  36. package/src/interfaces/cam.interface.ts +0 -28
  37. package/src/interfaces/flexdb.interface.ts +0 -104
  38. package/src/interfaces/function.interface.ts +0 -75
  39. package/src/interfaces/index.ts +0 -7
  40. package/src/interfaces/storage.interface.ts +0 -29
  41. package/src/interfaces/tcb.interface.ts +0 -642
  42. package/src/storage/index.ts +0 -1290
  43. package/src/third/index.ts +0 -24
  44. package/src/user/index.ts +0 -174
  45. package/src/user/types.ts +0 -21
  46. package/src/utils/auth.ts +0 -112
  47. package/src/utils/cloud-api-request.ts +0 -252
  48. package/src/utils/cloudbase-request.ts +0 -109
  49. package/src/utils/envLazy.ts +0 -15
  50. package/src/utils/fs.ts +0 -57
  51. package/src/utils/http-request.ts +0 -37
  52. package/src/utils/index.ts +0 -103
  53. package/src/utils/parallel.ts +0 -82
  54. package/src/utils/uuid.ts +0 -14
@@ -1,369 +0,0 @@
1
- import path from 'path'
2
- import {
3
- IServiceVersion,
4
- IExistsRes,
5
- CreateIndex,
6
- DropIndex,
7
- IndexInfo,
8
- TableInfo,
9
- Pager,
10
- IResponseInfo,
11
- CollectionDispension
12
- } from '../interfaces/'
13
- import { CloudBaseError } from '../error'
14
- import { Environment } from '../environment'
15
- import { CloudService } from '../utils'
16
-
17
- interface IDatabaseConfig {
18
- Tag: string
19
- }
20
-
21
- interface IIndexiesInfo {
22
- CreateIndexes?: Array<CreateIndex>
23
- DropIndexes?: Array<DropIndex>
24
- }
25
-
26
- interface ITableInfo extends IResponseInfo {
27
- Indexes?: Array<IndexInfo>
28
- IndexNum?: number
29
- }
30
-
31
- interface IMgoQueryInfo {
32
- MgoLimit?: number
33
- MgoOffset?: number
34
- }
35
-
36
- interface ICollectionInfo extends IResponseInfo {
37
- Collections: Array<TableInfo>
38
- Pager: Pager
39
- }
40
-
41
- interface ICollectionExistInfo extends IResponseInfo {
42
- IsCreated: boolean
43
- ExistsResult: IExistsRes
44
- }
45
-
46
- interface IDistributionInfo extends IResponseInfo {
47
- Collections: CollectionDispension
48
- Count: number
49
- Total: number
50
- }
51
-
52
- interface IDatabaseMigrateQueryInfo extends IResponseInfo {
53
- Status: string
54
- RecordSuccess: number
55
- RecordFail: number
56
- ErrorMsg: string
57
- FileUrl: string
58
- }
59
-
60
- interface IDatabaseImportAndExportInfo extends IResponseInfo {
61
- JobId: number
62
- }
63
-
64
- function preLazy() {
65
- return function (target: any, propertyKey: string, descriptor: PropertyDescriptor) {
66
- let oldFunc = descriptor.value
67
- descriptor.value = async function () {
68
- // 检查当前环境对象上是否已加载好环境信息
69
- const currentEnvironment = this.environment
70
-
71
- if (!currentEnvironment.inited) {
72
- await currentEnvironment.lazyInit()
73
- }
74
- let result = await oldFunc.apply(this, arguments)
75
- return result
76
- }
77
- }
78
- }
79
-
80
- export class DatabaseService {
81
- static tcbServiceVersion: IServiceVersion = {
82
- service: 'tcb',
83
- version: '2018-06-08'
84
- }
85
-
86
- static flexdbServiceVersion: IServiceVersion = {
87
- service: 'flexdb',
88
- version: '2018-11-27'
89
- }
90
-
91
- private environment: Environment
92
- private envId: string
93
- private dbOpService: CloudService
94
- private collOpService: CloudService
95
- private DEFAULT_MGO_OFFSET = 0
96
- private DEFAULT_MGO_LIMIT = 100
97
-
98
- constructor(environment: Environment) {
99
- this.environment = environment
100
- this.envId = environment.getEnvId()
101
-
102
- this.dbOpService = new CloudService(
103
- environment.cloudBaseContext,
104
- DatabaseService.tcbServiceVersion.service,
105
- DatabaseService.tcbServiceVersion.version
106
- )
107
-
108
- this.collOpService = new CloudService(
109
- environment.cloudBaseContext,
110
- DatabaseService.flexdbServiceVersion.service,
111
- DatabaseService.flexdbServiceVersion.version
112
- )
113
- }
114
-
115
- public getCurrEnvironment(): Environment {
116
- return this.environment
117
- }
118
-
119
- public getDatabaseConfig(): IDatabaseConfig {
120
- const currEnv = this.environment
121
- const { Databases } = currEnv.lazyEnvironmentConfig
122
- return {
123
- Tag: Databases[0].InstanceId
124
- }
125
- }
126
-
127
- public async checkCollectionExists(collectionName: string): Promise<IExistsRes> {
128
- try {
129
- const result = await this.describeCollection(collectionName)
130
-
131
- return {
132
- RequestId: result.RequestId,
133
- Exists: true
134
- }
135
- } catch (e) {
136
- return {
137
- RequestId: e.requestId,
138
- Msg: e.message,
139
- Exists: false
140
- }
141
- }
142
- }
143
-
144
- @preLazy()
145
- public async createCollection(collectionName: string): Promise<any> {
146
- let { Tag } = this.getDatabaseConfig()
147
-
148
- const res = await this.collOpService.request('CreateTable', {
149
- Tag,
150
- TableName: collectionName
151
- })
152
- return res
153
- }
154
-
155
- @preLazy()
156
- public async deleteCollection(collectionName: string): Promise<any> {
157
- // 先检查当前集合是否存在
158
- const existRes = await this.checkCollectionExists(collectionName)
159
- if (existRes.Exists) {
160
- let { Tag } = this.getDatabaseConfig()
161
-
162
- const res = await this.collOpService.request('DeleteTable', {
163
- Tag,
164
- TableName: collectionName
165
- })
166
- return res
167
- } else {
168
- return existRes
169
- }
170
- }
171
-
172
- @preLazy()
173
- public async updateCollection(
174
- collectionName: string,
175
- indexiesInfo: IIndexiesInfo
176
- ): Promise<any> {
177
- let { Tag } = this.getDatabaseConfig()
178
-
179
- const res = await this.collOpService.request('UpdateTable', {
180
- Tag,
181
- TableName: collectionName,
182
- ...indexiesInfo
183
- })
184
- return res
185
- }
186
-
187
- @preLazy()
188
- public async describeCollection(collectionName: string): Promise<ITableInfo> {
189
- let { Tag } = this.getDatabaseConfig()
190
-
191
- return this.collOpService.request<ITableInfo>('DescribeTable', {
192
- Tag,
193
- TableName: collectionName
194
- })
195
- }
196
-
197
- // 获取
198
- @preLazy()
199
- public async listCollections(
200
- options: IMgoQueryInfo = {
201
- MgoLimit: this.DEFAULT_MGO_LIMIT,
202
- MgoOffset: this.DEFAULT_MGO_OFFSET
203
- }
204
- ): Promise<ICollectionInfo> {
205
- let { Tag } = this.getDatabaseConfig()
206
-
207
- if (options.MgoLimit === undefined) {
208
- options.MgoLimit = this.DEFAULT_MGO_LIMIT
209
- }
210
-
211
- if (options.MgoOffset === undefined) {
212
- options.MgoOffset = this.DEFAULT_MGO_OFFSET
213
- }
214
-
215
- const res = await this.collOpService.request<{
216
- RequestId: string
217
- Pager: Pager
218
- Tables?: TableInfo[]
219
- Collections: TableInfo[]
220
- }>('ListTables', {
221
- Tag,
222
- ...options
223
- })
224
-
225
- if (res.Tables === null) {
226
- // 无集合
227
- res.Collections = []
228
- } else {
229
- // 云 API 返回转换为与TCB一致
230
- res.Collections = res.Tables.map(item => {
231
- item.CollectionName = item.TableName
232
- delete item.TableName
233
- return item
234
- })
235
- }
236
-
237
- delete res.Tables
238
- return res
239
- }
240
-
241
- public async createCollectionIfNotExists(
242
- collectionName: string
243
- ): Promise<ICollectionExistInfo> {
244
- const existRes = await this.checkCollectionExists(collectionName)
245
- let res
246
- if (!existRes.Exists) {
247
- res = await this.createCollection(collectionName)
248
- return {
249
- RequestId: res.RequestId,
250
- IsCreated: true,
251
- ExistsResult: existRes
252
- }
253
- } else {
254
- return {
255
- RequestId: '',
256
- IsCreated: false,
257
- ExistsResult: existRes
258
- }
259
- }
260
- }
261
-
262
- // 检查集合中是否存在某索引
263
- public async checkIndexExists(collectionName: string, indexName: string): Promise<IExistsRes> {
264
- const result = await this.describeCollection(collectionName)
265
- let exists = result.Indexes.some(item => {
266
- return item.Name === indexName
267
- })
268
-
269
- return {
270
- RequestId: result.RequestId,
271
- Exists: exists
272
- }
273
- }
274
-
275
- // 查询DB的数据存储分布
276
- public async distribution(): Promise<IDistributionInfo> {
277
- const res: any = await this.dbOpService.request('DescribeDbDistribution', {
278
- EnvId: this.envId
279
- })
280
-
281
- return res
282
- }
283
-
284
- // 查询DB 迁移进度
285
- public async migrateStatus(jobId: number): Promise<IDatabaseMigrateQueryInfo> {
286
- const res: IDatabaseMigrateQueryInfo = await this.dbOpService.request(
287
- 'DatabaseMigrateQueryInfo',
288
- {
289
- EnvId: this.envId,
290
- JobId: jobId
291
- }
292
- )
293
-
294
- return res
295
- }
296
-
297
- // 数据库导入数据
298
- public async import(
299
- collectionName: string,
300
- file: any,
301
- options: any
302
- ): Promise<IDatabaseImportAndExportInfo> {
303
- let filePath
304
- let fileType
305
- if (file['FilePath']) {
306
- let temp = 'tmp/db-imports/'
307
- if (options['ObjectKeyPrefix']) {
308
- temp = options['ObjectKeyPrefix']
309
- delete options['ObjectKeyPrefix']
310
- }
311
- filePath = path.join(temp, path.basename(file['FilePath']))
312
-
313
- // 调用cos接口 上传文件 todo
314
- await this.environment.getStorageService().uploadFile({
315
- localPath: file['FilePath'],
316
- cloudPath: filePath
317
- })
318
-
319
- fileType = path.extname(filePath).substring(1)
320
- } else if (file['ObjectKey']) {
321
- delete options['ObjectKeyPrefix']
322
- filePath = file['ObjectKey']
323
- fileType = path.extname(filePath).substring(1)
324
- } else {
325
- throw new CloudBaseError('Miss file.filePath or file.objectKey')
326
- }
327
-
328
- if (file['FileType']) {
329
- fileType = file['FileType']
330
- }
331
-
332
- return this.dbOpService.request('DatabaseMigrateImport', {
333
- CollectionName: collectionName,
334
- FilePath: filePath,
335
- FileType: fileType,
336
- EnvId: this.envId,
337
- ...options
338
- })
339
- }
340
-
341
- // 数据库导出数据
342
- public async export(
343
- collectionName: string,
344
- file: any,
345
- options: any
346
- ): Promise<IDatabaseImportAndExportInfo> {
347
- let filePath
348
- let fileType
349
-
350
- if (file['ObjectKey']) {
351
- filePath = file['ObjectKey']
352
- fileType = path.extname(filePath).substring(1)
353
- } else {
354
- throw new CloudBaseError('Miss file.filePath or file.objectKey')
355
- }
356
-
357
- if (file['FileType']) {
358
- fileType = file['FileType']
359
- }
360
-
361
- return this.dbOpService.request('DatabaseMigrateExport', {
362
- CollectionName: collectionName,
363
- FilePath: filePath,
364
- FileType: fileType,
365
- EnvId: this.envId,
366
- ...options
367
- })
368
- }
369
- }
package/src/debug.ts DELETED
@@ -1,34 +0,0 @@
1
- import CloudBase from './index'
2
- // import { cloudBaseConfig } from '../test/config'
3
-
4
- // const app = new CloudBase(cloudBaseConfig)
5
- const app = new CloudBase({})
6
-
7
- async function test() {
8
- // const hosting = await app.hosting.getInfo()
9
- // const { Bucket, Regoin } = hosting[0]
10
- // const res = await app.storage.uploadFilesCustom({
11
- // files: [
12
- // {
13
- // localPath: 'test/storage/test_data/data.txt',
14
- // cloudPath: 'test/storage/test_data/data.txt'
15
- // },
16
- // {
17
- // localPath: 'test/storage/test_data/download.txt',
18
- // cloudPath: 'test/storage/test_data/download.txt'
19
- // }
20
- // ],
21
- // region: Regoin,
22
- // bucket: Bucket
23
- // })
24
-
25
- const res = await app.hosting.uploadFiles({
26
- localPath: '/Users/wuyiqing/Desktop/cloudbase-demo/functions/node-sdk',
27
- cloudPath: '',
28
- onProgress: console.log
29
- })
30
-
31
- console.log(res)
32
- }
33
-
34
- test().catch(console.log)