@extrahorizon/exh-cli 1.5.0 → 1.5.1-dev-27-7bdff2e

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 (92) hide show
  1. package/CHANGELOG.md +56 -53
  2. package/README.md +0 -12
  3. package/build/commands/completion.d.ts +5 -5
  4. package/build/commands/completion.js +38 -38
  5. package/build/commands/data/schemas/delete.d.ts +10 -10
  6. package/build/commands/data/schemas/delete.js +29 -29
  7. package/build/commands/data/schemas/list.d.ts +8 -8
  8. package/build/commands/data/schemas/list.js +20 -20
  9. package/build/commands/data/schemas/sync/statusHelpers.d.ts +3 -3
  10. package/build/commands/data/schemas/sync/statusHelpers.js +49 -49
  11. package/build/commands/data/schemas/sync.d.ts +35 -35
  12. package/build/commands/data/schemas/sync.js +72 -72
  13. package/build/commands/data/schemas/util/listFilesInDir.d.ts +1 -1
  14. package/build/commands/data/schemas/util/listFilesInDir.js +25 -25
  15. package/build/commands/data/schemas/util/metaschema.json +455 -455
  16. package/build/commands/data/schemas/util/readJson.d.ts +1 -1
  17. package/build/commands/data/schemas/util/readJson.js +11 -11
  18. package/build/commands/data/schemas/util/schemaverify.d.ts +28 -28
  19. package/build/commands/data/schemas/util/schemaverify.js +202 -202
  20. package/build/commands/data/schemas/util/syncSchema.d.ts +20 -20
  21. package/build/commands/data/schemas/util/syncSchema.js +276 -276
  22. package/build/commands/data/schemas/util/tests/listFilesInDir.test.d.ts +1 -1
  23. package/build/commands/data/schemas/util/tests/listFilesInDir.test.js +40 -40
  24. package/build/commands/data/schemas/verify.d.ts +18 -18
  25. package/build/commands/data/schemas/verify.js +82 -82
  26. package/build/commands/data/schemas.d.ts +5 -5
  27. package/build/commands/data/schemas.js +10 -10
  28. package/build/commands/data.d.ts +5 -5
  29. package/build/commands/data.js +10 -10
  30. package/build/commands/dispatchers/sync.d.ts +21 -21
  31. package/build/commands/dispatchers/sync.js +24 -24
  32. package/build/commands/dispatchers.d.ts +5 -5
  33. package/build/commands/dispatchers.js +10 -10
  34. package/build/commands/login.d.ts +37 -37
  35. package/build/commands/login.js +59 -59
  36. package/build/commands/sync.d.ts +55 -55
  37. package/build/commands/sync.js +107 -107
  38. package/build/commands/tasks/createrepo.d.ts +22 -22
  39. package/build/commands/tasks/createrepo.js +70 -70
  40. package/build/commands/tasks/delete.d.ts +10 -10
  41. package/build/commands/tasks/delete.js +29 -29
  42. package/build/commands/tasks/list.d.ts +8 -8
  43. package/build/commands/tasks/list.js +27 -27
  44. package/build/commands/tasks/sync.d.ts +56 -56
  45. package/build/commands/tasks/sync.js +122 -122
  46. package/build/commands/tasks/taskConfig.d.ts +24 -24
  47. package/build/commands/tasks/taskConfig.js +169 -169
  48. package/build/commands/tasks/util.d.ts +1 -1
  49. package/build/commands/tasks/util.js +27 -27
  50. package/build/commands/tasks.d.ts +5 -5
  51. package/build/commands/tasks.js +10 -10
  52. package/build/commands/templates/delete.d.ts +19 -19
  53. package/build/commands/templates/delete.js +48 -48
  54. package/build/commands/templates/get.d.ts +19 -19
  55. package/build/commands/templates/get.js +37 -37
  56. package/build/commands/templates/list.d.ts +9 -9
  57. package/build/commands/templates/list.js +25 -25
  58. package/build/commands/templates/sync.d.ts +22 -22
  59. package/build/commands/templates/sync.js +65 -65
  60. package/build/commands/templates/util/buildTemplates.d.ts +2 -2
  61. package/build/commands/templates/util/buildTemplates.js +50 -50
  62. package/build/commands/templates/util/readTemplateFiles.d.ts +3 -3
  63. package/build/commands/templates/util/readTemplateFiles.js +52 -52
  64. package/build/commands/templates/util/templateService.d.ts +8 -8
  65. package/build/commands/templates/util/templateService.js +18 -18
  66. package/build/commands/templates/util/uploadTemplate.d.ts +2 -2
  67. package/build/commands/templates/util/uploadTemplate.js +20 -20
  68. package/build/commands/templates/util/utils.d.ts +4 -4
  69. package/build/commands/templates/util/utils.js +22 -22
  70. package/build/commands/templates.d.ts +5 -5
  71. package/build/commands/templates.js +10 -10
  72. package/build/constants.d.ts +13 -13
  73. package/build/constants.js +37 -37
  74. package/build/exh.d.ts +3 -3
  75. package/build/exh.js +65 -65
  76. package/build/helpers/error.d.ts +2 -2
  77. package/build/helpers/error.js +6 -6
  78. package/build/helpers/repoConfig.d.ts +2 -2
  79. package/build/helpers/repoConfig.js +60 -60
  80. package/build/helpers/util.d.ts +3 -3
  81. package/build/helpers/util.js +36 -36
  82. package/build/index.d.ts +2 -2
  83. package/build/index.js +33 -33
  84. package/build/repositories/dispatchers.d.ts +8 -8
  85. package/build/repositories/dispatchers.js +31 -31
  86. package/build/repositories/functions.d.ts +24 -24
  87. package/build/repositories/functions.js +28 -28
  88. package/build/repositories/schemas.d.ts +44 -44
  89. package/build/repositories/schemas.js +86 -86
  90. package/build/services/dispatchers.d.ts +3 -3
  91. package/build/services/dispatchers.js +132 -132
  92. package/package.json +53 -53
@@ -1,27 +1,27 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.handler = exports.builder = exports.desc = exports.command = void 0;
4
- const util_1 = require("../../helpers/util");
5
- exports.command = 'list';
6
- exports.desc = 'List all tasks';
7
- const builder = (yargs) => (0, util_1.epilogue)(yargs);
8
- exports.builder = builder;
9
- const handler = async function list({ sdk, isTTY }) {
10
- let functionResponse;
11
- try {
12
- functionResponse = await sdk.raw.get('/tasks/v1/functions');
13
- }
14
- catch (err) {
15
- console.log(err);
16
- return;
17
- }
18
- if (functionResponse.data.data.length !== 0) {
19
- if (isTTY) {
20
- console.table(functionResponse.data.data.map((c) => ({ Name: c.name, Description: c.Description || '<none>', 'Last updated': c.updateTimestamp.toISOString() })));
21
- }
22
- else {
23
- functionResponse.data.data.forEach((f) => (console.log(f.name)));
24
- }
25
- }
26
- };
27
- exports.handler = handler;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.handler = exports.builder = exports.desc = exports.command = void 0;
4
+ const util_1 = require("../../helpers/util");
5
+ exports.command = 'list';
6
+ exports.desc = 'List all tasks';
7
+ const builder = (yargs) => (0, util_1.epilogue)(yargs);
8
+ exports.builder = builder;
9
+ const handler = async function list({ sdk, isTTY }) {
10
+ let functionResponse;
11
+ try {
12
+ functionResponse = await sdk.raw.get('/tasks/v1/functions');
13
+ }
14
+ catch (err) {
15
+ console.log(err);
16
+ return;
17
+ }
18
+ if (functionResponse.data.data.length !== 0) {
19
+ if (isTTY) {
20
+ console.table(functionResponse.data.data.map((c) => ({ Name: c.name, Description: c.Description || '<none>', 'Last updated': c.updateTimestamp.toISOString() })));
21
+ }
22
+ else {
23
+ functionResponse.data.data.forEach((f) => (console.log(f.name)));
24
+ }
25
+ }
26
+ };
27
+ exports.handler = handler;
@@ -1,56 +1,56 @@
1
- /// <reference types="yargs" />
2
- export declare const command = "sync";
3
- export declare const desc = "Sync a task. Will create the task first if it doesn't exist yet";
4
- export declare const builder: (yargs: any) => import("yargs").Argv<import("yargs").Omit<{}, "description" | "code" | "name" | "path" | "env" | "entryPoint" | "runtime" | "timeLimit" | "memoryLimit" | "executionPermission"> & import("yargs").InferredOptionTypes<{
5
- path: {
6
- demandOption: false;
7
- describe: string;
8
- type: "string";
9
- };
10
- name: {
11
- demandOption: false;
12
- describe: string;
13
- type: "string";
14
- };
15
- code: {
16
- demandOption: false;
17
- describe: string;
18
- type: "string";
19
- };
20
- entryPoint: {
21
- demandOption: false;
22
- describe: string;
23
- type: "string";
24
- };
25
- runtime: {
26
- demandOption: false;
27
- describe: string;
28
- choices: string[];
29
- type: "string";
30
- };
31
- description: {
32
- describe: string;
33
- type: "string";
34
- default: string;
35
- };
36
- timeLimit: {
37
- describe: string;
38
- type: "number";
39
- };
40
- memoryLimit: {
41
- describe: string;
42
- type: "number";
43
- };
44
- env: {
45
- describe: string;
46
- type: "string";
47
- default: any[];
48
- };
49
- executionPermission: {
50
- type: "string";
51
- };
52
- }>>;
53
- export declare const handler: ({ sdk, ...cmdLineParams }: {
54
- [x: string]: any;
55
- sdk: any;
56
- }) => Promise<void>;
1
+ /// <reference types="yargs" />
2
+ export declare const command = "sync";
3
+ export declare const desc = "Sync a task. Will create the task first if it doesn't exist yet";
4
+ export declare const builder: (yargs: any) => import("yargs").Argv<import("yargs").Omit<{}, "description" | "code" | "name" | "path" | "env" | "entryPoint" | "runtime" | "timeLimit" | "memoryLimit" | "executionPermission"> & import("yargs").InferredOptionTypes<{
5
+ path: {
6
+ demandOption: false;
7
+ describe: string;
8
+ type: "string";
9
+ };
10
+ name: {
11
+ demandOption: false;
12
+ describe: string;
13
+ type: "string";
14
+ };
15
+ code: {
16
+ demandOption: false;
17
+ describe: string;
18
+ type: "string";
19
+ };
20
+ entryPoint: {
21
+ demandOption: false;
22
+ describe: string;
23
+ type: "string";
24
+ };
25
+ runtime: {
26
+ demandOption: false;
27
+ describe: string;
28
+ choices: string[];
29
+ type: "string";
30
+ };
31
+ description: {
32
+ describe: string;
33
+ type: "string";
34
+ default: string;
35
+ };
36
+ timeLimit: {
37
+ describe: string;
38
+ type: "number";
39
+ };
40
+ memoryLimit: {
41
+ describe: string;
42
+ type: "number";
43
+ };
44
+ env: {
45
+ describe: string;
46
+ type: "string";
47
+ default: any[];
48
+ };
49
+ executionPermission: {
50
+ type: "string";
51
+ };
52
+ }>>;
53
+ export declare const handler: ({ sdk, ...cmdLineParams }: {
54
+ [x: string]: any;
55
+ sdk: any;
56
+ }) => Promise<void>;
@@ -1,122 +1,122 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.handler = exports.builder = exports.desc = exports.command = void 0;
4
- const fs = require("fs/promises");
5
- const chalk = require("chalk");
6
- const constants_1 = require("../../constants");
7
- const util_1 = require("../../helpers/util");
8
- const functionRepository = require("../../repositories/functions");
9
- const taskConfig_1 = require("./taskConfig");
10
- const util_2 = require("./util");
11
- exports.command = 'sync';
12
- exports.desc = 'Sync a task. Will create the task first if it doesn\'t exist yet';
13
- const builder = (yargs) => (0, util_1.epilogue)(yargs).options({
14
- path: {
15
- demandOption: false,
16
- describe: `Path of the configuration json file containing task parameters. If a directory is given instead, all sub-directories will be searched for a task-config.json file & synced.
17
- If this option is not used, each parameter (name, code, entryPoint, runtime, ...) will need to be supplied separately`,
18
- type: 'string',
19
- },
20
- name: {
21
- demandOption: false,
22
- describe: 'Name of the task',
23
- type: 'string',
24
- },
25
- code: {
26
- demandOption: false,
27
- describe: 'The path to a directory containing the built task. exh-cli will compress the directory and upload it',
28
- type: 'string',
29
- },
30
- entryPoint: {
31
- demandOption: false,
32
- describe: "The code function that should be invoked. For example 'index.handler' for Nodejs",
33
- type: 'string',
34
- },
35
- runtime: {
36
- demandOption: false,
37
- describe: 'Runtime to use for the task',
38
- choices: constants_1.runtimeChoices,
39
- type: 'string',
40
- },
41
- description: {
42
- describe: 'A description for this task',
43
- type: 'string',
44
- default: '',
45
- },
46
- timeLimit: {
47
- describe: 'The execution time limit for this task (in seconds). Min: 3 max: 900',
48
- type: 'number',
49
- },
50
- memoryLimit: {
51
- describe: 'The allocated memory for this task (in MB). Min: 128 max: 10240',
52
- type: 'number',
53
- },
54
- env: {
55
- describe: 'Environment Variables set for this task. This option can be used multiple times.',
56
- type: 'string',
57
- default: [],
58
- },
59
- executionPermission: {
60
- type: 'string',
61
- },
62
- })
63
- .check(async ({ path, entryPoint, runtime, name, code, executionPermission }) => {
64
- if (!path && (!name || !code || !runtime || !entryPoint)) {
65
- throw new Error('Need to specify either a task config file or all parameters separately');
66
- }
67
- (0, taskConfig_1.assertExecutionPermission)(executionPermission);
68
- return true;
69
- });
70
- exports.builder = builder;
71
- const handler = async ({ sdk, ...cmdLineParams }) => {
72
- for await (const config of (0, taskConfig_1.getValidatedConfigIterator)(cmdLineParams)) {
73
- console.log('Syncing task', config.name, '...');
74
- await syncSingleTask(sdk, config);
75
- }
76
- };
77
- exports.handler = handler;
78
- async function syncSingleTask(sdk, config) {
79
- const uploadFilePath = await (0, util_2.zipFileFromDirectory)(config.path);
80
- const file = await fs.readFile(uploadFilePath);
81
- const allFunctions = await functionRepository.find(sdk);
82
- const myFunction = allFunctions.find((f) => f.name === config.name);
83
- const request = {
84
- name: config.name,
85
- description: config.description || 'none',
86
- entryPoint: config.entryPoint,
87
- code: file.toString('base64'),
88
- runtime: config.runtime,
89
- };
90
- if (config.executionPermission) {
91
- request.executionOptions = { permissionMode: config.executionPermission };
92
- }
93
- if (config.timeLimit) {
94
- request.timeLimit = config.timeLimit;
95
- }
96
- if (config.memoryLimit) {
97
- request.memoryLimit = config.memoryLimit;
98
- }
99
- if (config.environment) {
100
- request.environmentVariables =
101
- Object.entries(config.environment).reduce((prev, curr) => ({ ...prev, [curr[0]]: { value: curr[1] } }), {});
102
- }
103
- if (config.retryPolicy) {
104
- request.retryPolicy = config.retryPolicy;
105
- }
106
- if (myFunction === undefined) {
107
- await functionRepository.create(sdk, request);
108
- console.log(chalk.green('Successfully created task', config.name));
109
- }
110
- else {
111
- const existingFunction = await functionRepository.findByName(sdk, myFunction.name);
112
- if (request.runtime === existingFunction.runtime) {
113
- delete request.runtime;
114
- }
115
- const updateResponse = await functionRepository.update(sdk, request);
116
- if (!updateResponse?.affectedRecords) {
117
- throw new Error(`Failed to update task ${request.name}`);
118
- }
119
- console.log(chalk.green('Successfully updated task', config.name));
120
- }
121
- await fs.unlink(uploadFilePath);
122
- }
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.handler = exports.builder = exports.desc = exports.command = void 0;
4
+ const fs = require("fs/promises");
5
+ const chalk = require("chalk");
6
+ const constants_1 = require("../../constants");
7
+ const util_1 = require("../../helpers/util");
8
+ const functionRepository = require("../../repositories/functions");
9
+ const taskConfig_1 = require("./taskConfig");
10
+ const util_2 = require("./util");
11
+ exports.command = 'sync';
12
+ exports.desc = 'Sync a task. Will create the task first if it doesn\'t exist yet';
13
+ const builder = (yargs) => (0, util_1.epilogue)(yargs).options({
14
+ path: {
15
+ demandOption: false,
16
+ describe: `Path of the configuration json file containing task parameters. If a directory is given instead, all sub-directories will be searched for a task-config.json file & synced.
17
+ If this option is not used, each parameter (name, code, entryPoint, runtime, ...) will need to be supplied separately`,
18
+ type: 'string',
19
+ },
20
+ name: {
21
+ demandOption: false,
22
+ describe: 'Name of the task',
23
+ type: 'string',
24
+ },
25
+ code: {
26
+ demandOption: false,
27
+ describe: 'The path to a directory containing the built task. exh-cli will compress the directory and upload it',
28
+ type: 'string',
29
+ },
30
+ entryPoint: {
31
+ demandOption: false,
32
+ describe: "The code function that should be invoked. For example 'index.handler' for Nodejs",
33
+ type: 'string',
34
+ },
35
+ runtime: {
36
+ demandOption: false,
37
+ describe: 'Runtime to use for the task',
38
+ choices: constants_1.runtimeChoices,
39
+ type: 'string',
40
+ },
41
+ description: {
42
+ describe: 'A description for this task',
43
+ type: 'string',
44
+ default: '',
45
+ },
46
+ timeLimit: {
47
+ describe: 'The execution time limit for this task (in seconds). Min: 3 max: 900',
48
+ type: 'number',
49
+ },
50
+ memoryLimit: {
51
+ describe: 'The allocated memory for this task (in MB). Min: 128 max: 10240',
52
+ type: 'number',
53
+ },
54
+ env: {
55
+ describe: 'Environment Variables set for this task. This option can be used multiple times.',
56
+ type: 'string',
57
+ default: [],
58
+ },
59
+ executionPermission: {
60
+ type: 'string',
61
+ },
62
+ })
63
+ .check(async ({ path, entryPoint, runtime, name, code, executionPermission }) => {
64
+ if (!path && (!name || !code || !runtime || !entryPoint)) {
65
+ throw new Error('Need to specify either a task config file or all parameters separately');
66
+ }
67
+ (0, taskConfig_1.assertExecutionPermission)(executionPermission);
68
+ return true;
69
+ });
70
+ exports.builder = builder;
71
+ const handler = async ({ sdk, ...cmdLineParams }) => {
72
+ for await (const config of (0, taskConfig_1.getValidatedConfigIterator)(cmdLineParams)) {
73
+ console.log('Syncing task', config.name, '...');
74
+ await syncSingleTask(sdk, config);
75
+ }
76
+ };
77
+ exports.handler = handler;
78
+ async function syncSingleTask(sdk, config) {
79
+ const uploadFilePath = await (0, util_2.zipFileFromDirectory)(config.path);
80
+ const file = await fs.readFile(uploadFilePath);
81
+ const allFunctions = await functionRepository.find(sdk);
82
+ const myFunction = allFunctions.find((f) => f.name === config.name);
83
+ const request = {
84
+ name: config.name,
85
+ description: config.description || 'none',
86
+ entryPoint: config.entryPoint,
87
+ code: file.toString('base64'),
88
+ runtime: config.runtime,
89
+ };
90
+ if (config.executionPermission) {
91
+ request.executionOptions = { permissionMode: config.executionPermission };
92
+ }
93
+ if (config.timeLimit) {
94
+ request.timeLimit = config.timeLimit;
95
+ }
96
+ if (config.memoryLimit) {
97
+ request.memoryLimit = config.memoryLimit;
98
+ }
99
+ if (config.environment) {
100
+ request.environmentVariables =
101
+ Object.entries(config.environment).reduce((prev, curr) => ({ ...prev, [curr[0]]: { value: curr[1] } }), {});
102
+ }
103
+ if (config.retryPolicy) {
104
+ request.retryPolicy = config.retryPolicy;
105
+ }
106
+ if (myFunction === undefined) {
107
+ await functionRepository.create(sdk, request);
108
+ console.log(chalk.green('Successfully created task', config.name));
109
+ }
110
+ else {
111
+ const existingFunction = await functionRepository.findByName(sdk, myFunction.name);
112
+ if (request.runtime === existingFunction.runtime) {
113
+ delete request.runtime;
114
+ }
115
+ const updateResponse = await functionRepository.update(sdk, request);
116
+ if (!updateResponse?.affectedRecords) {
117
+ throw new Error(`Failed to update task ${request.name}`);
118
+ }
119
+ console.log(chalk.green('Successfully updated task', config.name));
120
+ }
121
+ await fs.unlink(uploadFilePath);
122
+ }
@@ -1,24 +1,24 @@
1
- export declare enum permissionModes {
2
- permissionRequired = "permissionRequired",
3
- allUsers = "allUsers",
4
- public = "public"
5
- }
6
- export interface TaskConfig {
7
- name?: string;
8
- path?: string;
9
- entryPoint?: string;
10
- runtime?: string;
11
- description?: string;
12
- timeLimit?: number;
13
- memoryLimit?: number;
14
- environment?: Record<string, string>;
15
- executionPermission?: permissionModes;
16
- retryPolicy?: {
17
- enabled: boolean;
18
- errorsToRetry: string[];
19
- };
20
- }
21
- export declare function assertExecutionPermission(mode: string): asserts mode is permissionModes | undefined;
22
- export declare function validateConfig(config: TaskConfig): Promise<boolean>;
23
- export declare function loadSingleConfigFile(path: string): Promise<TaskConfig>;
24
- export declare function getValidatedConfigIterator({ path, name, code, entryPoint, runtime, description, timeLimit, memoryLimit, executionPermission, env }: any): AsyncGenerator<TaskConfig>;
1
+ export declare enum permissionModes {
2
+ permissionRequired = "permissionRequired",
3
+ allUsers = "allUsers",
4
+ public = "public"
5
+ }
6
+ export interface TaskConfig {
7
+ name?: string;
8
+ path?: string;
9
+ entryPoint?: string;
10
+ runtime?: string;
11
+ description?: string;
12
+ timeLimit?: number;
13
+ memoryLimit?: number;
14
+ environment?: Record<string, string>;
15
+ executionPermission?: permissionModes;
16
+ retryPolicy?: {
17
+ enabled: boolean;
18
+ errorsToRetry: string[];
19
+ };
20
+ }
21
+ export declare function assertExecutionPermission(mode: string): asserts mode is permissionModes | undefined;
22
+ export declare function validateConfig(config: TaskConfig): Promise<boolean>;
23
+ export declare function loadSingleConfigFile(path: string): Promise<TaskConfig>;
24
+ export declare function getValidatedConfigIterator({ path, name, code, entryPoint, runtime, description, timeLimit, memoryLimit, executionPermission, env }: any): AsyncGenerator<TaskConfig>;