@cloudbase/cli 2.3.5 → 2.3.7

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.
@@ -63,7 +63,8 @@ let AttachFileLayer = class AttachFileLayer extends common_1.Command {
63
63
  }
64
64
  let layers = yield (0, function_1.listLayers)({
65
65
  offset: 0,
66
- limit: 200
66
+ limit: 200,
67
+ searchSrc: `TCB_${envId}`
67
68
  });
68
69
  loading.stop();
69
70
  layers = layers.map((item) => ({
@@ -31,6 +31,7 @@ const function_1 = require("../../../function");
31
31
  const utils_1 = require("../../../utils");
32
32
  const decorators_1 = require("../../../decorators");
33
33
  const common_2 = require("./common");
34
+ const toolbox_1 = require("@cloudbase/toolbox");
34
35
  let CreateFileLayer = class CreateFileLayer extends common_1.Command {
35
36
  get options() {
36
37
  return Object.assign(Object.assign({}, (0, common_2.layerCommonOptions)('create <alias>')), { deprecateCmd: 'functions:layer:create <alias>', options: [
@@ -49,11 +50,19 @@ let CreateFileLayer = class CreateFileLayer extends common_1.Command {
49
50
  const alias = params === null || params === void 0 ? void 0 : params[0];
50
51
  const { file } = options;
51
52
  const layerName = `${alias}_${envId}`;
53
+ const layers = yield (0, function_1.listLayers)({
54
+ offset: 0,
55
+ limit: 200
56
+ });
57
+ if (layers.find(({ LayerName }) => LayerName === layerName)) {
58
+ throw new toolbox_1.CloudBaseError(`层名称 ${layerName} 已被您的当前环境或其他环境占用,请换用别的名称`);
59
+ }
52
60
  const filePath = path_1.default.resolve(file);
53
61
  const runtimes = ['Nodejs12.16', 'Nodejs8.9', 'Php7', 'Java8'];
54
62
  const loading = (0, utils_1.loadingFactory)();
55
63
  loading.start('文件层创建中...');
56
64
  yield (0, function_1.createLayer)({
65
+ envId,
57
66
  layerName,
58
67
  runtimes,
59
68
  contentPath: filePath
@@ -42,14 +42,12 @@ let DeleteFileLayer = class DeleteFileLayer extends common_1.Command {
42
42
  return __awaiter(this, void 0, void 0, function* () {
43
43
  const loading = (0, utils_1.loadingFactory)();
44
44
  loading.start('数据加载中...');
45
- let layers = yield (0, function_1.listLayers)({
45
+ const layers = yield (0, function_1.listLayers)({
46
46
  offset: 0,
47
- limit: 200
47
+ limit: 200,
48
+ searchSrc: `TCB_${envId}`
48
49
  });
49
50
  loading.stop();
50
- layers = layers
51
- .filter((item) => item.LayerName.includes(`_${envId}`))
52
- .map((item) => item.LayerName);
53
51
  if (!layers.length) {
54
52
  throw new error_1.CloudBaseError('当前环境没有可用的文件层,请先创建文件层!');
55
53
  }
@@ -57,7 +55,7 @@ let DeleteFileLayer = class DeleteFileLayer extends common_1.Command {
57
55
  type: 'select',
58
56
  name: 'layer',
59
57
  message: '选择文件层名称',
60
- choices: layers
58
+ choices: layers.map((item) => item.LayerName)
61
59
  });
62
60
  let versions = yield (0, function_1.listLayerVersions)({
63
61
  name: layer
@@ -52,14 +52,12 @@ let DownloadFileLayer = class DownloadFileLayer extends common_1.Command {
52
52
  const { dest } = options;
53
53
  const loading = (0, utils_1.loadingFactory)();
54
54
  loading.start('数据加载中...');
55
- let layers = yield (0, function_1.listLayers)({
55
+ const layers = yield (0, function_1.listLayers)({
56
56
  offset: 0,
57
- limit: 200
57
+ limit: 200,
58
+ searchSrc: `TCB_${envId}`
58
59
  });
59
60
  loading.stop();
60
- layers = layers
61
- .filter((item) => item.LayerName.includes(`_${envId}`))
62
- .map((item) => item.LayerName);
63
61
  if (!layers.length) {
64
62
  throw new error_1.CloudBaseError('当前环境没有可用的文件层,请先创建文件层!');
65
63
  }
@@ -67,7 +65,7 @@ let DownloadFileLayer = class DownloadFileLayer extends common_1.Command {
67
65
  type: 'select',
68
66
  name: 'layer',
69
67
  message: '选择文件层名称',
70
- choices: layers
68
+ choices: layers.map((item) => item.LayerName)
71
69
  });
72
70
  let versions = yield (0, function_1.listLayerVersions)({
73
71
  name: layer
@@ -71,9 +71,9 @@ let ListFileLayer = class ListFileLayer extends common_1.Command {
71
71
  else if (envId) {
72
72
  data = yield (0, function_1.listLayers)({
73
73
  offset: 0,
74
- limit: 200
74
+ limit: 200,
75
+ searchSrc: `TCB_${envId}`
75
76
  });
76
- data = data.filter((item) => item.LayerName.includes(`_${envId}`));
77
77
  }
78
78
  else {
79
79
  data = yield (0, function_1.listLayers)({
@@ -20,10 +20,10 @@ const utils_1 = require("../../utils");
20
20
  const scfService = new utils_1.CloudApiService('scf');
21
21
  function createLayer(options) {
22
22
  return __awaiter(this, void 0, void 0, function* () {
23
- const { contentPath = '', layerName, base64Content = '', runtimes = [] } = options;
23
+ const { envId, contentPath = '', layerName, base64Content = '', runtimes = [] } = options;
24
24
  (0, utils_1.checkFullAccess)(contentPath);
25
25
  const validRuntime = ['Nodejs8.9', 'Php7', 'Java8', 'Nodejs12.16'];
26
- if (runtimes.some(item => validRuntime.indexOf(item) === -1)) {
26
+ if (runtimes.some((item) => validRuntime.indexOf(item) === -1)) {
27
27
  throw new toolbox_1.CloudBaseError(`Invalid runtime value. Now only support: ${validRuntime.join(', ')}`);
28
28
  }
29
29
  let base64;
@@ -52,6 +52,7 @@ function createLayer(options) {
52
52
  return scfService.request('PublishLayerVersion', {
53
53
  LayerName: layerName,
54
54
  CompatibleRuntimes: runtimes,
55
+ Src: `TCB_${envId}`,
55
56
  Content: {
56
57
  ZipFile: base64
57
58
  }
@@ -14,10 +14,11 @@ const utils_1 = require("../../utils");
14
14
  const scfService = new utils_1.CloudApiService('scf');
15
15
  function listLayers(options) {
16
16
  return __awaiter(this, void 0, void 0, function* () {
17
- const { offset, limit } = options;
17
+ const { offset, limit, searchSrc } = options;
18
18
  const res = yield scfService.request('ListLayers', {
19
19
  Offset: offset,
20
- Limit: limit
20
+ Limit: limit,
21
+ SearchSrc: searchSrc
21
22
  });
22
23
  return (res === null || res === void 0 ? void 0 : res.Layers) || [];
23
24
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudbase/cli",
3
- "version": "2.3.5",
3
+ "version": "2.3.7",
4
4
  "description": "cli tool for cloudbase",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -1,4 +1,5 @@
1
1
  export interface IFunctionLayerOptions {
2
+ envId: string;
2
3
  contentPath?: string;
3
4
  base64Content?: string;
4
5
  layerName: string;
@@ -1,6 +1,7 @@
1
1
  export interface ILayerListOptions {
2
2
  offset: number;
3
3
  limit: number;
4
+ searchSrc?: string;
4
5
  }
5
6
  export interface IVersionListOptions {
6
7
  name: string;