@cloudbase/manager-node 5.2.0 → 5.4.0-beta.1

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/jest.config.js CHANGED
@@ -10,7 +10,10 @@ module.exports = {
10
10
  },
11
11
  transformIgnorePatterns: ['node_modules'],
12
12
  testEnvironment: 'node',
13
- forceExit: true,
13
+ testPathIgnorePatterns: [
14
+ // PG 集成测试 / smoke 测试需要 PostgreSQL 环境,流水线默认跳过
15
+ '/pg-storage-integration\\.test\\.ts$/'
16
+ ],
14
17
  // https://github.com/facebook/jest/issues/5164
15
18
  globalSetup: './test/global-setup-hook.ts',
16
19
  // globalTeardown: './test/global-teardown-hook.js',
@@ -0,0 +1,101 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.AiModelService = void 0;
10
+ const utils_1 = require("../utils");
11
+ class AiModelService {
12
+ constructor(environment) {
13
+ this.environment = environment;
14
+ this.tcbService = new utils_1.CloudService(environment.cloudBaseContext, 'tcb', '2018-06-08');
15
+ }
16
+ /**
17
+ * 创建 AI 模型配置分组
18
+ */
19
+ async createAIModel(options) {
20
+ const { EnvId } = this.environment.lazyEnvironmentConfig;
21
+ const { envId, groupName, baseUrl, models, remark, status, secret } = options;
22
+ if (!groupName || groupName.trim().length === 0) {
23
+ throw new Error('groupName is required');
24
+ }
25
+ if (groupName.toLowerCase().startsWith('cloudbase')) {
26
+ throw new Error('groupName cannot start with cloudbase');
27
+ }
28
+ if (status !== undefined && status !== 1 && status !== 2) {
29
+ throw new Error('status must be 1 or 2');
30
+ }
31
+ return this.tcbService.request('CreateAIModel', Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ EnvId: envId || EnvId, GroupName: groupName }, (baseUrl !== undefined ? { BaseUrl: baseUrl } : {})), (models !== undefined ? { Models: models } : {})), (remark !== undefined ? { Remark: remark } : {})), (status !== undefined ? { Status: status } : {})), (secret !== undefined ? { Secret: secret } : {})));
32
+ }
33
+ /**
34
+ * 更新 AI 模型配置分组
35
+ */
36
+ async updateAIModel(options) {
37
+ const { EnvId } = this.environment.lazyEnvironmentConfig;
38
+ const { envId, groupName, baseUrl, models, remark, status, secret } = options;
39
+ if (!groupName || groupName.trim().length === 0) {
40
+ throw new Error('groupName is required');
41
+ }
42
+ if (status !== undefined && status !== 1 && status !== 2) {
43
+ throw new Error('status must be 1 or 2');
44
+ }
45
+ return this.tcbService.request('UpdateAIModel', Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ EnvId: envId || EnvId, GroupName: groupName }, (baseUrl !== undefined ? { BaseUrl: baseUrl } : {})), (models !== undefined ? { Models: models } : {})), (remark !== undefined ? { Remark: remark } : {})), (status !== undefined ? { Status: status } : {})), (secret !== undefined ? { Secret: secret } : {})));
46
+ }
47
+ /**
48
+ * 删除 AI 模型配置分组,支持批量删除
49
+ */
50
+ async deleteAIModel(options) {
51
+ const { EnvId } = this.environment.lazyEnvironmentConfig;
52
+ const { envId, groupNames } = options;
53
+ if (!Array.isArray(groupNames) || groupNames.length === 0) {
54
+ throw new Error('groupNames is required');
55
+ }
56
+ const invalidGroupName = groupNames.find(item => typeof item !== 'string' || item.trim().length === 0);
57
+ if (invalidGroupName !== undefined) {
58
+ throw new Error('groupNames contains invalid item');
59
+ }
60
+ return this.tcbService.request('DeleteAIModel', {
61
+ EnvId: envId || EnvId,
62
+ GroupNames: groupNames
63
+ });
64
+ }
65
+ /**
66
+ * 查询指定云开发环境下已配置的 AI 模型分组列表
67
+ */
68
+ async describeAIModels(options = {}) {
69
+ const { EnvId } = this.environment.lazyEnvironmentConfig;
70
+ const { envId } = options;
71
+ return this.tcbService.request('DescribeAIModels', {
72
+ EnvId: envId || EnvId
73
+ });
74
+ }
75
+ /**
76
+ * 查询云开发平台支持的托管类型 AI 模型列表
77
+ */
78
+ async describeManagedAIModelList(options = {}) {
79
+ const { EnvId } = this.environment.lazyEnvironmentConfig;
80
+ const { envId } = options;
81
+ return this.tcbService.request('DescribeManagedAIModelList', {
82
+ EnvId: envId || EnvId
83
+ });
84
+ }
85
+ }
86
+ exports.AiModelService = AiModelService;
87
+ __decorate([
88
+ (0, utils_1.preLazy)()
89
+ ], AiModelService.prototype, "createAIModel", null);
90
+ __decorate([
91
+ (0, utils_1.preLazy)()
92
+ ], AiModelService.prototype, "updateAIModel", null);
93
+ __decorate([
94
+ (0, utils_1.preLazy)()
95
+ ], AiModelService.prototype, "deleteAIModel", null);
96
+ __decorate([
97
+ (0, utils_1.preLazy)()
98
+ ], AiModelService.prototype, "describeAIModels", null);
99
+ __decorate([
100
+ (0, utils_1.preLazy)()
101
+ ], AiModelService.prototype, "describeManagedAIModelList", null);
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -281,6 +281,39 @@ class DatabaseService {
281
281
  let { Tag } = this.getDatabaseConfig();
282
282
  return this.dbOpService.request('RunCommands', Object.assign({ MgoCommands: options.MgoCommands, Tag: options.Tag || Tag, EnvId: options.EnvId || this.envId }, (options.MongoConnector ? { MongoConnector: options.MongoConnector } : {})));
283
283
  }
284
+ /**
285
+ * 在 PostgreSQL 数据库上执行 SQL 语句
286
+ *
287
+ * @param options 执行参数
288
+ * @param options.Sql 要执行的 SQL 语句
289
+ * @param options.Role 指定 role 执行 SQL(可选)
290
+ * @param options.EnvId 环境 ID(可选,不传则自动使用当前环境 ID)
291
+ * @returns 执行结果,包含影响行数、字段列表、数据行及执行耗时
292
+ *
293
+ * @example
294
+ * // 创建表
295
+ * const res = await database.executePGSql({
296
+ * Sql: 'CREATE TABLE users (id SERIAL PRIMARY KEY, name TEXT NOT NULL)'
297
+ * })
298
+ *
299
+ * @example
300
+ * // 查询数据
301
+ * const res = await database.executePGSql({
302
+ * Sql: "SELECT * FROM users WHERE id = 1"
303
+ * })
304
+ * console.log(res.Columns) // ['id', 'name']
305
+ * console.log(res.Rows) // ['["1","Alice"]']
306
+ */
307
+ async executePGSql(options) {
308
+ const params = {
309
+ EnvId: options.EnvId || this.envId,
310
+ Sql: options.Sql
311
+ };
312
+ if (options.Role) {
313
+ params.Role = options.Role;
314
+ }
315
+ return this.dbOpService.request('ExecutePGSql', params);
316
+ }
284
317
  }
285
318
  exports.DatabaseService = DatabaseService;
286
319
  DatabaseService.tcbServiceVersion = {
@@ -321,3 +354,6 @@ __decorate([
321
354
  __decorate([
322
355
  preLazy()
323
356
  ], DatabaseService.prototype, "runCommands", null);
357
+ __decorate([
358
+ preLazy()
359
+ ], DatabaseService.prototype, "executePGSql", null);
@@ -21,6 +21,7 @@ const mysql_1 = require("./mysql");
21
21
  const cloudApp_1 = require("./cloudApp");
22
22
  const permission_1 = require("./permission");
23
23
  const sandbox_1 = require("./sandbox");
24
+ const aiModel_1 = require("./aiModel");
24
25
  class Environment {
25
26
  constructor(context, envId) {
26
27
  this.inited = false;
@@ -45,6 +46,7 @@ class Environment {
45
46
  this.permissionService = new permission_1.PermissionService(this);
46
47
  this.cloudAppService = new cloudApp_1.CloudAppService(this);
47
48
  this.sandboxService = new sandbox_1.SandboxService(this);
49
+ this.aiModelService = new aiModel_1.AiModelService(this);
48
50
  }
49
51
  async lazyInit() {
50
52
  if (!this.inited) {
@@ -116,6 +118,9 @@ class Environment {
116
118
  getSandboxService() {
117
119
  return this.sandboxService;
118
120
  }
121
+ getAiModelService() {
122
+ return this.aiModelService;
123
+ }
119
124
  getCommonService(serviceType = 'tcb', serviceVersion) {
120
125
  return new common_1.CommonService(this, serviceType, serviceVersion);
121
126
  }
package/lib/index.js CHANGED
@@ -119,6 +119,9 @@ class CloudBase {
119
119
  get sandbox() {
120
120
  return this.currentEnvironment().getSandboxService();
121
121
  }
122
+ get aiModel() {
123
+ return this.currentEnvironment().getAiModelService();
124
+ }
122
125
  get docs() {
123
126
  if (!this.docsService) {
124
127
  this.docsService = new docs_1.DocsService();