zcatalyst-cli 1.18.0-beta.1 → 1.18.0-beta.10

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 (88) hide show
  1. package/docs/command_needs/rc.toml +8 -8
  2. package/docs/commands/ds/import.toml +5 -5
  3. package/docs/commands/zest/generate/index.toml +4 -0
  4. package/docs/serve/server/lib/appsail/index.toml +22 -1
  5. package/lib/authentication/login.js +8 -4
  6. package/lib/code-deck.js +7 -7
  7. package/lib/command_needs/rc.js +7 -7
  8. package/lib/commands/appsail/add.js +2 -2
  9. package/lib/commands/client/setup.js +1 -1
  10. package/lib/commands/codelib/install.js +6 -2
  11. package/lib/commands/ds/import.js +37 -21
  12. package/lib/commands/event/generate/index.js +14 -2
  13. package/lib/commands/functions/add.js +1 -1
  14. package/lib/commands/functions/setup.js +1 -1
  15. package/lib/commands/iac/export.js +5 -1
  16. package/lib/commands/iac/import.js +4 -1
  17. package/lib/commands/index.js +1 -0
  18. package/lib/commands/init.js +8 -1
  19. package/lib/commands/zest/generate/index.js +304 -0
  20. package/lib/deploy/features/appsail/index.js +25 -10
  21. package/lib/endpoints/index.js +17 -3
  22. package/lib/endpoints/lib/ds-bulk.js +1 -0
  23. package/lib/endpoints/lib/stratus.js +63 -0
  24. package/lib/endpoints/lib/tunnel.js +18 -0
  25. package/lib/endpoints/lib/zest.js +124 -0
  26. package/lib/event_generate/stratus.js +52 -0
  27. package/lib/fn-utils/lib/common.js +6 -1
  28. package/lib/iac/status/deploy.js +1 -5
  29. package/lib/init/features/appsail/index.js +34 -27
  30. package/lib/init/features/project.js +6 -15
  31. package/lib/internal/api.js +14 -6
  32. package/lib/internal/command.js +1 -1
  33. package/lib/prompt/index.js +5 -2
  34. package/lib/prompt/types/file-path.js +1 -1
  35. package/lib/prompt/types/search-box.js +281 -0
  36. package/lib/serve/features/appsail.js +1 -1
  37. package/lib/serve/server/index.js +44 -14
  38. package/lib/serve/server/lib/appsail/index.js +73 -13
  39. package/lib/serve/server/lib/appsail/start.js +9 -1
  40. package/lib/serve/server/lib/java/aio_server/lib/catalyst-cli-java-runtime-1.0.0.jar +0 -0
  41. package/lib/serve/server/lib/java/aio_server/lib/{catalyst-function-sdk-1.0.0.jar → catalyst-function-sdk-1.1.0.jar} +0 -0
  42. package/lib/serve/server/lib/java/aio_server/lib/catalyst-java-runtime-1.0.0.jar +0 -0
  43. package/lib/serve/server/lib/java/index.js +1 -1
  44. package/lib/serve/server/lib/master/appsail.js +3 -3
  45. package/lib/serve/server/lib/master/unknown-req-proxy.js +5 -2
  46. package/lib/serve/server/lib/master/utils.js +27 -15
  47. package/lib/serve/server/lib/node/index.js +1 -1
  48. package/lib/serve/server/lib/node/server/package-lock.json +12 -0
  49. package/lib/serve/server/lib/python/index.js +1 -1
  50. package/lib/shell/dependencies/http-functions.js +1 -1
  51. package/lib/shell/dependencies/invoker/bio/java/lib/{catalyst-function-sdk-1.0.0.jar → catalyst-function-sdk-1.1.0.jar} +0 -0
  52. package/lib/shell/dependencies/invoker/cron/java/JavacronInvoker.java +1 -1
  53. package/lib/shell/dependencies/invoker/cron/java/lib/{catalyst-function-sdk-1.0.0.jar → catalyst-function-sdk-1.1.0.jar} +0 -0
  54. package/lib/shell/dependencies/invoker/event/java/lib/{catalyst-function-sdk-1.0.0.jar → catalyst-function-sdk-1.1.0.jar} +0 -0
  55. package/lib/shell/dependencies/invoker/integ/java/JavaintegInvoker.java +15 -0
  56. package/lib/shell/dependencies/invoker/integ/java/lib/catalyst-function-sdk-1.1.0.jar +0 -0
  57. package/lib/shell/dependencies/invoker/integ/node.mjs +13 -0
  58. package/lib/shell/dependencies/invoker/job/java/JavajobInvoker.java +15 -1
  59. package/lib/shell/dependencies/invoker/job/java/lib/catalyst-function-sdk-1.1.0.jar +0 -0
  60. package/lib/shell/dependencies/local-function.js +24 -23
  61. package/lib/shell/dependencies/tunnel-server.js +52 -23
  62. package/lib/shell/index.js +22 -28
  63. package/lib/util_modules/config/lib/appsail.js +10 -8
  64. package/lib/util_modules/constants/lib/dc-type.js +8 -0
  65. package/lib/util_modules/constants/lib/event-action.js +1 -0
  66. package/lib/util_modules/constants/lib/event-source.js +1 -0
  67. package/lib/util_modules/constants/lib/placeholders.js +2 -1
  68. package/lib/util_modules/constants/lib/scopes.js +14 -3
  69. package/lib/util_modules/constants/lib/urls.js +8 -0
  70. package/lib/util_modules/fs/lib/async.js +7 -2
  71. package/package.json +4 -2
  72. package/templates/init/client/react/react_js/template/src/index.js +3 -3
  73. package/templates/init/client/react/react_ts/template/src/index.tsx +3 -3
  74. package/templates/init/client/react/react_ts/template.json +3 -3
  75. package/templates/init/functions/java/job/sample.java +1 -1
  76. package/templates/init/functions/node/aio/sample.js +7 -0
  77. package/templates/init/functions/node/bio/sample.js +5 -0
  78. package/templates/init/functions/node/bio/types/basicio.d.ts +57 -0
  79. package/templates/init/functions/node/cron/sample.js +5 -0
  80. package/templates/init/functions/node/cron/types/cron.d.ts +64 -0
  81. package/templates/init/functions/node/event/sample.js +11 -8
  82. package/templates/init/functions/node/event/types/event.d.ts +82 -0
  83. package/templates/init/functions/node/job/sample.js +0 -1
  84. package/templates/init/functions/node/job/types/job.d.ts +0 -4
  85. package/templates/init/functions/python/job/sample.py +0 -1
  86. package/templates/init.txt +2 -1
  87. package/lib/shell/dependencies/invoker/integ/java/lib/catalyst-function-sdk-1.0.0.jar +0 -0
  88. package/lib/shell/dependencies/invoker/job/java/lib/catalyst-function-sdk-1.0.0.jar +0 -0
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const moment_1 = __importDefault(require("moment"));
7
+ const runtime_store_1 = __importDefault(require("../runtime-store"));
8
+ const constants_1 = require("../util_modules/constants");
9
+ const js_1 = require("../util_modules/js");
10
+ const project_1 = require("../util_modules/project");
11
+ function generateStratusEventJson(eventJson) {
12
+ const userDetails = {
13
+ email_id: runtime_store_1.default.get('user.Email'),
14
+ user_id: js_1.JS.randomNumber(15),
15
+ is_confirmed: getRandomBoolean(),
16
+ last_name: js_1.JS.randomString(5),
17
+ first_name: js_1.JS.randomString(10),
18
+ zuid: js_1.JS.randomNumber(10)
19
+ };
20
+ const time = (0, moment_1.default)().format('MMM DD, YYYY hh:mm A');
21
+ const data = {
22
+ bucket_details: {
23
+ bucket_name: 'sample-bucket',
24
+ project_details: {
25
+ id: (0, project_1.getProjectId)(),
26
+ project_name: (0, project_1.getProjectName)(),
27
+ project_type: 'Live'
28
+ },
29
+ created_by: userDetails,
30
+ created_time: time,
31
+ modified_by: userDetails,
32
+ modified_time: time,
33
+ bucket_meta: {
34
+ versioning: getRandomBoolean(),
35
+ caching: {
36
+ status: getRandomBoolean() ? 'Enabled' : 'Disabled'
37
+ },
38
+ encryption: getRandomBoolean(),
39
+ audit_consent: getRandomBoolean()
40
+ }
41
+ },
42
+ object_key: 'path1/path2/myfile.png'
43
+ };
44
+ eventJson = eventJson.replace(new RegExp(constants_1.PLACEHOLDER.event_data.rule_id, 'g'), 'NULL');
45
+ eventJson = eventJson.replace(new RegExp(constants_1.PLACEHOLDER.event_data.source_id, 'g'), 'NULL');
46
+ eventJson = eventJson.replace(new RegExp(constants_1.PLACEHOLDER.event_data.data, 'g'), JSON.stringify(data));
47
+ return eventJson;
48
+ }
49
+ exports.default = generateStratusEventJson;
50
+ function getRandomBoolean() {
51
+ return js_1.JS.random(0, 1) === 1;
52
+ }
@@ -341,7 +341,12 @@ function pack(target) {
341
341
  }
342
342
  exports.pack = pack;
343
343
  function generateUrlForTarget(target) {
344
- const urlDefault = 'https://' + (0, project_1.getDomainPrefix)() + '.' + constants_1.ORIGIN.app.replace('https://', '');
344
+ const domainPrefix = (0, project_1.getDomainPrefix)(false);
345
+ if (!domainPrefix) {
346
+ (0, logger_1.warning)('Failed to retrieve the domain name, so the function URL generation was skipped.');
347
+ return;
348
+ }
349
+ const urlDefault = 'https://' + domainPrefix + '.' + constants_1.ORIGIN.app.replace('https://', '');
345
350
  switch (target.type) {
346
351
  case constants_1.FN_TYPE.basic:
347
352
  case constants_1.FN_TYPE.browserLogic:
@@ -19,7 +19,6 @@ const error_1 = __importDefault(require("../../error"));
19
19
  const throbber_1 = __importDefault(require("../../throbber"));
20
20
  const logger_1 = require("../../util_modules/logger");
21
21
  const util_1 = require("./util");
22
- const env_1 = require("../../util_modules/env");
23
22
  const ansi_colors_1 = require("ansi-colors");
24
23
  const code_deck_1 = require("../../code-deck");
25
24
  exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
@@ -76,10 +75,7 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
76
75
  timerAPI.on('error', (e) => {
77
76
  (0, logger_1.debug)('Error encountered : ', e);
78
77
  });
79
- timerAPI.on('end', (_error, data) => {
80
- if (data === true && !(0, env_1.isPrimaryShell)() && process.send) {
81
- process.send('success');
82
- }
78
+ timerAPI.on('end', () => {
83
79
  throbber.stopAll();
84
80
  });
85
81
  process.env.PARENT_COMMAND === 'codedeck' &&
@@ -141,21 +141,8 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
141
141
  })
142
142
  }))).source
143
143
  };
144
- const appConfigPth = (0, path_1.join)(_appSailConfig.source, constants_1.FILENAME.app_config);
145
- const isAppConfig = yield fs_1.ASYNC.fileExists(appConfigPth);
146
144
  const existingSails = config_1.appSailConfig.raw() || [];
147
- yield prompt_1.default.register('file-path');
148
- const appSail = yield prompt_1.default.ask(prompt_1.default.question('buildPath', 'Please provide the build path of your AppSail service: ', {
149
- type: 'file-path',
150
- validate: (pth) => __awaiter(void 0, void 0, void 0, function* () {
151
- const buildPath = (0, path_1.resolve)(runtime_store_1.default.get('cwd'), pth.value);
152
- if ((yield fs_1.ASYNC.dirExists(buildPath)) || (yield fs_1.ASYNC.fileExists(buildPath))) {
153
- return true;
154
- }
155
- return 'Path does not exists';
156
- }),
157
- when: !_appSailConfig.build
158
- }), prompt_1.default.question('name', 'Please provide the name for your AppSail: ', {
145
+ const appName = yield prompt_1.default.ask(prompt_1.default.question('name', 'Please provide the name for your AppSail: ', {
159
146
  type: 'input',
160
147
  default: 'AppSail',
161
148
  validate: (name) => {
@@ -172,20 +159,45 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
172
159
  : true;
173
160
  }
174
161
  }));
175
- const appSailStack = _appSailConfig.stack ||
176
- (yield (0, common_1.getRuntimePromptAnswer)('Please choose a stack for your AppSail: '));
177
162
  const payload = {
178
- source: _appSailConfig.source,
179
- name: appSail.name
163
+ source: (0, path_1.relative)((0, project_1.getProjectRoot)(), _appSailConfig.source) || '.',
164
+ name: appName.name
180
165
  };
166
+ const appConfigPth = (0, path_1.join)(_appSailConfig.source, constants_1.FILENAME.app_config);
167
+ const isAppConfig = yield fs_1.ASYNC.fileExists(appConfigPth);
168
+ if (isAppConfig) {
169
+ (0, logger_1.info)();
170
+ (0, logger_1.warning)(`The ${(0, ansi_colors_1.bold)(constants_1.FILENAME.app_config)} file is already present in the appsail directory`);
171
+ }
172
+ const overWrite = yield prompt_1.default.ask(prompt_1.default.question('appConfig', 'Do you wish to overwrite the ' + constants_1.FILENAME.app_config, {
173
+ type: 'confirm',
174
+ default: false,
175
+ when: isAppConfig
176
+ }));
177
+ const activeWrite = overWrite.appConfig !== false;
178
+ if (!activeWrite) {
179
+ runtime_store_1.default.set('payload.appsail.targets', [payload]);
180
+ return;
181
+ }
182
+ const buildPath = yield prompt_1.default.ask(prompt_1.default.question('path', 'Please provide the build path of your AppSail service: ', {
183
+ type: 'input',
184
+ rootPath: _appSailConfig.source,
185
+ when: !_appSailConfig.build && activeWrite
186
+ }));
187
+ const appSailStack = _appSailConfig.stack ||
188
+ (yield (0, common_1.getRuntimePromptAnswer)('Please choose a stack for your AppSail: '));
181
189
  const appConfig = {
182
190
  command: _appSailConfig.command ||
183
- 'echo Please specify the start-up command in the app-config.json file under the key command',
184
- build_path: _appSailConfig.build || './' + (0, path_1.relative)(_appSailConfig.source, appSail.buildPath),
191
+ 'echo Please specify the start-up command in the app-config.json file under the key command for AppSail $X_ZC_RESOURCE_NAME',
192
+ build_path: _appSailConfig.build ||
193
+ ((0, path_1.isAbsolute)(buildPath.path)
194
+ ? (0, path_1.relative)(_appSailConfig.source, buildPath.path) || '.'
195
+ : buildPath.path),
185
196
  stack: appSailStack.runtime,
186
197
  env_variables: {},
187
198
  memory: _appSailConfig.memory || 256,
188
- scripts: _appSailConfig.scripts || {}
199
+ scripts: _appSailConfig.scripts || {},
200
+ raw: {}
189
201
  };
190
202
  if (appSailStack.lang === 'java') {
191
203
  const platform = yield prompt_1.default.ask(prompt_1.default.question('value', 'Please choose a platform for your AppSail: ', {
@@ -208,10 +220,5 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
208
220
  }
209
221
  }
210
222
  runtime_store_1.default.set('payload.appsail.targets', [payload]);
211
- if (isAppConfig) {
212
- (0, logger_1.message)((0, ansi_colors_1.bold)(`app-config.json`) + ` file already exist in ${(0, ansi_colors_1.underline)(_appSailConfig.source)}`);
213
- }
214
- else {
215
- yield fs_1.ASYNC.writeJSONFile(appConfigPth, appConfig);
216
- }
223
+ activeWrite && (yield fs_1.ASYNC.writeJSONFile(appConfigPth, appConfig));
217
224
  });
@@ -34,26 +34,16 @@ const client_utils_1 = require("../../client-utils");
34
34
  exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
35
35
  var _a, _b;
36
36
  const orgAPI = yield (0, endpoints_1.orgAPI)();
37
- const projectAPIWithoutOrg = yield (0, endpoints_1.projectAPI)();
38
37
  const defaultRCProjectName = (0, project_1.getDefaultProjectName)(null);
39
38
  const defaultRCProjectId = (0, project_1.getDefaultProjectId)(null);
40
39
  if (defaultRCProjectName !== null &&
41
40
  defaultRCProjectId !== null &&
42
41
  !(0, option_1.getOptionValue)('force', false)) {
43
- (0, logger_1.message)(constants_1.FILENAME.rc + ' already has ' + (0, ansi_colors_1.bold)(defaultRCProjectName) + ' as a default project.');
44
- try {
45
- yield projectAPIWithoutOrg.getProject(defaultRCProjectId);
46
- throw new error_1.default('Skipping project setup, since project directory contains a default project. To overwrite use --force option');
47
- }
48
- catch (err) {
49
- if (js_1.JS.get(err, 'context.response.statusCode') !== 404) {
50
- throw err;
51
- }
52
- (0, logger_1.warning)('cleaning up ' +
53
- constants_1.FILENAME.rc +
54
- ' since the current default project for this folder is not found in remote');
55
- yield (0, project_1.removeProject)(defaultRCProjectId + '');
56
- }
42
+ (0, logger_1.message)(constants_1.FILENAME.rc +
43
+ ' already has ' +
44
+ (0, ansi_colors_1.bold)(defaultRCProjectName) +
45
+ ' as a default project. To overwrite use --force option');
46
+ throw new error_1.default('Skipping project setup, since project directory contains a default project. To overwrite use --force option', { skipHelp: true, exit: 0 });
57
47
  }
58
48
  const orgList = yield orgAPI.getAllOrgs();
59
49
  if (orgList.length === 0) {
@@ -71,6 +61,7 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
71
61
  when: orgChoice.length > 1
72
62
  }));
73
63
  const selectedOrg = orgAns.org || orgList[0];
64
+ runtime_store_1.default.set('project.env.id', selectedOrg.id);
74
65
  (0, logger_1.message)('Setting up a new default project for this folder\n');
75
66
  const projectAPI = yield (0, endpoints_1.projectAPI)({ auth: true, org: selectedOrg.id });
76
67
  const allProjects = (yield projectAPI.getAllProjects());
@@ -47,11 +47,11 @@ const project_1 = require("../util_modules/project");
47
47
  const fs_1 = require("fs");
48
48
  const throbber_1 = __importDefault(require("../throbber"));
49
49
  class API {
50
- constructor({ authNeeded = true, resolveOnError = false, maxRetry = 3, env = constants_1.DEFAULT.env_name, log = {}, headers = {}, isExternal = false, origin = constants_1.ORIGIN.admin, showWarning = true, envId = (0, project_1.getEnvId)() } = {}) {
50
+ constructor({ authNeeded = true, resolveOnError = false, maxRetry = 3, env = constants_1.DEFAULT.env_name, log = {}, headers = {}, isExternal = false, origin = constants_1.ORIGIN.admin, json = true, showWarning = true, envId = (0, project_1.getEnvId)(), printError = true } = {}) {
51
51
  this.requestOpts = {
52
52
  url: origin,
53
53
  method: 'GET',
54
- json: true,
54
+ json,
55
55
  headers
56
56
  };
57
57
  const projectSecretKey = process.env.CATALYST_PROJECT_SECRET_KEY;
@@ -73,6 +73,7 @@ class API {
73
73
  this.maxRetryCount = maxRetry;
74
74
  this.retryCount = 0;
75
75
  this.showWarning = showWarning;
76
+ this.printError = printError;
76
77
  }
77
78
  _logReq() {
78
79
  let qs = this.requestOpts.qs
@@ -113,7 +114,9 @@ class API {
113
114
  (0, logger_1.debug)('TOTAL TIME TAKEN : ' + Number(resp.timings.end.toFixed(3)) + ' ms\n');
114
115
  (0, logger_1.debug)('REQUEST PHASES : ' + resp.timingPhases);
115
116
  }
116
- if (this.logOpts.progress !== undefined) {
117
+ if (resp.statusCode >= 200 &&
118
+ resp.statusCode < 300 &&
119
+ this.logOpts.progress !== undefined) {
117
120
  js_1.JS.set(this.logOpts, 'progress.total', resp.headers['content-length']);
118
121
  this.downloadProgress = new progress_1.default(this.logOpts.progress);
119
122
  }
@@ -153,11 +156,11 @@ class API {
153
156
  if (resp.statusCode >= 400 && !this.logOpts.skipRespBody) {
154
157
  (0, logger_1.debug)('Response Body : ' + JSON.stringify(resp.body) + '\n');
155
158
  if (!this.resolveOnHTTPError) {
156
- const errRes = (0, errorResponse_1.default)(resp, body);
159
+ const errRes = (0, errorResponse_1.default)(resp, body, !this.printError);
157
160
  this._logDownloadProgress({ error: errRes });
158
161
  throw errRes;
159
162
  }
160
- this._logDownloadProgress({ error: (0, errorResponse_1.default)(resp, body, true) });
163
+ this._logDownloadProgress({ error: (0, errorResponse_1.default)(resp, body, !this.printError) });
161
164
  }
162
165
  return {
163
166
  status: resp.statusCode,
@@ -188,6 +191,7 @@ class API {
188
191
  return new Promise((resolve, reject) => {
189
192
  const responseBuffer = [];
190
193
  let isJSONResponse = false;
194
+ let isErrorPage = false;
191
195
  const throbber = throbber_1.default.getInstance();
192
196
  if (this.logOpts.uploadProgress !== undefined &&
193
197
  this.logOpts.stream instanceof fs_1.ReadStream) {
@@ -230,6 +234,7 @@ class API {
230
234
  }))
231
235
  .on('response', (resp) => {
232
236
  isJSONResponse = js_1.JS.includes(resp.headers['content-type'], 'json');
237
+ isErrorPage = !(resp.statusCode >= 200 && resp.statusCode < 300);
233
238
  this._logResp(resp);
234
239
  })
235
240
  .on('complete', (resp, body) => __awaiter(this, void 0, void 0, function* () {
@@ -244,7 +249,9 @@ class API {
244
249
  if (isJSONResponse) {
245
250
  responseBuffer.push(data);
246
251
  }
247
- this._logDownloadProgress({ chunk: data });
252
+ if (!isErrorPage) {
253
+ this._logDownloadProgress({ chunk: data });
254
+ }
248
255
  });
249
256
  });
250
257
  });
@@ -252,6 +259,7 @@ class API {
252
259
  fire(method, path, options) {
253
260
  return __awaiter(this, void 0, void 0, function* () {
254
261
  this.resolveOnHTTPError = js_1.JS.get(options, 'resolveOnError', this.resolveOnHTTPError);
262
+ this.printError = (options === null || options === void 0 ? void 0 : options.printError) || this.printError;
255
263
  this.maxRetryCount = js_1.JS.get(options, 'maxRetry', this.maxRetryCount);
256
264
  this.authNeeded = js_1.JS.get(options, 'authNeeded', this.authNeeded);
257
265
  this.logOpts = js_1.JS.get(options, 'log', this.logOpts);
@@ -237,5 +237,5 @@ class Command {
237
237
  });
238
238
  }
239
239
  }
240
- Command.globalOpts = ['project', 'token', 'dc', 'org'];
240
+ Command.globalOpts = ['project', 'token', 'dc', 'org', 'verbose'];
241
241
  exports.default = Command;
@@ -63,11 +63,14 @@ exports.default = {
63
63
  const filePathExt = yield Promise.resolve().then(() => __importStar(require('./types/file-path')));
64
64
  inquirer_1.default.registerPrompt('file-path', filePathExt.default);
65
65
  break;
66
- case 'tree': {
66
+ case 'tree':
67
67
  const treeExt = yield Promise.resolve().then(() => __importStar(require('./types/tree')));
68
68
  inquirer_1.default.registerPrompt('tree', treeExt.default);
69
69
  break;
70
- }
70
+ case 'search-box':
71
+ const searchExt = yield Promise.resolve().then(() => __importStar(require('./types/search-box')));
72
+ inquirer_1.default.registerPrompt('search-box', searchExt.default);
73
+ break;
71
74
  default:
72
75
  throw new error_1.default('No such type registered', { exit: 2 });
73
76
  }
@@ -36,7 +36,7 @@ class InquirerFilePath extends inquirer_autocomplete_prompt_1.default {
36
36
  constructor(question, rl, answers) {
37
37
  const { rootPath = '.', exclude = [] } = question;
38
38
  const questionBase = Object.assign({
39
- emptyText: 'No valid file inside current directory!. Try giving the entire path and press ' +
39
+ emptyText: 'No valid file path inside current directory!. Try giving the entire path and press ' +
40
40
  (0, ansi_colors_1.cyan)('<return> ') +
41
41
  'key'
42
42
  }, question, {
@@ -0,0 +1,281 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const chalk_1 = __importDefault(require("chalk"));
7
+ const cli_cursor_1 = __importDefault(require("cli-cursor"));
8
+ const figures_1 = __importDefault(require("figures"));
9
+ const choices_1 = __importDefault(require("inquirer/lib/objects/choices"));
10
+ const base_1 = __importDefault(require("inquirer/lib/prompts/base"));
11
+ const events_1 = __importDefault(require("inquirer/lib/utils/events"));
12
+ const paginator_1 = __importDefault(require("inquirer/lib/utils/paginator"));
13
+ const operators_1 = require("rxjs/operators");
14
+ class SearchBox extends base_1.default {
15
+ constructor(questions, rl, answers) {
16
+ super(questions, rl, answers);
17
+ this.pointer = 0;
18
+ if (this.opt.highlight == null) {
19
+ this.opt.highlight = false;
20
+ }
21
+ if (typeof this.opt.searchable == null) {
22
+ this.opt.searchable = false;
23
+ }
24
+ if (typeof this.opt.default == null) {
25
+ this.opt.default = undefined;
26
+ }
27
+ if (this.opt.source == null) {
28
+ this.throwParamError('source');
29
+ }
30
+ if (this.opt.notFoundMsg === undefined) {
31
+ this.opt.notFoundMsg = 'No results...';
32
+ }
33
+ if (this.opt.searchMsg === undefined) {
34
+ this.opt.searchMsg = 'Searching...';
35
+ }
36
+ this.pointer = 0;
37
+ this.firstSourceLoading = true;
38
+ this.choices = new choices_1.default([], answers);
39
+ this.checkedChoices = [];
40
+ this.value = [];
41
+ this.lastQuery = undefined;
42
+ this.searching = false;
43
+ this.lastSourcePromise = undefined;
44
+ this.default = this.opt.default;
45
+ this.opt.default = undefined;
46
+ this.selection = [];
47
+ this.done = undefined;
48
+ this.paginator = new paginator_1.default(this.screen);
49
+ }
50
+ _run(callback) {
51
+ this.done = callback;
52
+ this.executeSource().then(() => {
53
+ const events = (0, events_1.default)(this.rl);
54
+ const validation = this.handleSubmitEvents(events.line.pipe((0, operators_1.map)(this.getCurrentValue.bind(this))));
55
+ validation.success.forEach(this.onEnd.bind(this));
56
+ validation.error.forEach(this.onError.bind(this));
57
+ events.normalizedUpKey
58
+ .pipe((0, operators_1.takeUntil)(validation.success))
59
+ .forEach(this.onUpKey.bind(this));
60
+ events.normalizedDownKey
61
+ .pipe((0, operators_1.takeUntil)(validation.success))
62
+ .forEach(this.onDownKey.bind(this));
63
+ events.spaceKey.pipe((0, operators_1.takeUntil)(validation.success)).forEach(this.onSpaceKey.bind(this));
64
+ if (this.opt.searchable === false) {
65
+ events.numberKey
66
+ .pipe((0, operators_1.takeUntil)(validation.success))
67
+ .forEach(this.onNumberKey.bind(this));
68
+ events.aKey.pipe((0, operators_1.takeUntil)(validation.success)).forEach(this.onAllKey.bind(this));
69
+ events.iKey
70
+ .pipe((0, operators_1.takeUntil)(validation.success))
71
+ .forEach(this.onInverseKey.bind(this));
72
+ }
73
+ else {
74
+ events.keypress
75
+ .pipe((0, operators_1.takeUntil)(validation.success))
76
+ .forEach(this.onKeypress.bind(this));
77
+ }
78
+ if (this.rl.line) {
79
+ this.onKeypress();
80
+ }
81
+ cli_cursor_1.default.hide();
82
+ this.render();
83
+ });
84
+ return this;
85
+ }
86
+ getValue(choice) {
87
+ if (choice.type === 'separator') {
88
+ return undefined;
89
+ }
90
+ return choice.value;
91
+ }
92
+ executeSource() {
93
+ let sourcePromise;
94
+ this.rl.line = this.rl.line.trim();
95
+ if (this.rl.line === this.lastQuery) {
96
+ return Promise.resolve(undefined);
97
+ }
98
+ if (this.opt.searchable) {
99
+ sourcePromise = this.opt.source(this.answers, this.rl.line);
100
+ }
101
+ else {
102
+ sourcePromise = this.opt.source(this.answers, undefined);
103
+ }
104
+ this.lastQuery = this.rl.line;
105
+ this.lastSourcePromise = sourcePromise;
106
+ this.searching = true;
107
+ sourcePromise.then((choices) => {
108
+ if (this.lastSourcePromise !== sourcePromise) {
109
+ return;
110
+ }
111
+ this.searching = false;
112
+ this.choices = new choices_1.default(choices, this.answers);
113
+ this.choices.forEach((choice) => {
114
+ var _a;
115
+ if (this.value.some((eachValue) => this.getValue(choice) === eachValue)) {
116
+ this.toggleChoice(choice, true);
117
+ }
118
+ else {
119
+ this.toggleChoice(choice, false);
120
+ }
121
+ if (this.default !== null) {
122
+ if ((_a = this.default) === null || _a === void 0 ? void 0 : _a.some((defaultValue) => this.getValue(choice) === defaultValue)) {
123
+ this.toggleChoice(choice, true);
124
+ }
125
+ }
126
+ });
127
+ this.pointer = 0;
128
+ this.render();
129
+ this.default = undefined;
130
+ this.firstSourceLoading = false;
131
+ });
132
+ return sourcePromise;
133
+ }
134
+ render(error) {
135
+ let message = this.getQuestion();
136
+ let bottomContent = '';
137
+ if (this.status === 'answered') {
138
+ message += chalk_1.default.cyan(this.selection.join(', '));
139
+ return this.screen.render(message, bottomContent);
140
+ }
141
+ if (this.firstSourceLoading) {
142
+ if (this.opt.searchable) {
143
+ message += `(Press ${chalk_1.default.cyan.bold('<space>')} to select, or type anything to filter the list)`;
144
+ }
145
+ else {
146
+ message += `(Press ${chalk_1.default.cyan.bold('<space>')} to select, ${chalk_1.default.cyan.bold('<a>')} to toggle all, ${chalk_1.default.cyan.bold('<i>')} to invert selection)`;
147
+ }
148
+ }
149
+ if (this.opt.searchable) {
150
+ message += this.rl.line;
151
+ }
152
+ if (this.searching) {
153
+ message += `\n ${chalk_1.default.cyan(this.opt.searchMsg)}`;
154
+ }
155
+ else if (!this.choices.length) {
156
+ message += `\n ${chalk_1.default.yellow(this.opt.notFoundMsg)}`;
157
+ }
158
+ else {
159
+ const choicesStr = this.renderChoices(this.choices, this.pointer);
160
+ const choice = this.choices.getChoice(this.pointer);
161
+ const indexPosition = this.choices.indexOf(choice);
162
+ message += `\n${this.paginator.paginate(choicesStr, indexPosition, this.opt.pageSize)}`;
163
+ }
164
+ if (error) {
165
+ bottomContent = chalk_1.default.red('>> ') + error;
166
+ }
167
+ return this.screen.render(message, bottomContent);
168
+ }
169
+ onEnd(state) {
170
+ var _a;
171
+ this.status = 'answered';
172
+ this.render();
173
+ this.screen.done();
174
+ cli_cursor_1.default.show();
175
+ (_a = this.done) === null || _a === void 0 ? void 0 : _a.call(this, 'value' in state ? state.value : undefined);
176
+ }
177
+ onError(state) {
178
+ if (state.isValid) {
179
+ this.render();
180
+ }
181
+ }
182
+ getCurrentValue() {
183
+ this.selection = this.checkedChoices.map((checkedChoice) => checkedChoice.short);
184
+ const values = this.checkedChoices.map((checkedChoice) => checkedChoice.value);
185
+ return values;
186
+ }
187
+ onUpKey() {
188
+ const len = this.choices.realLength;
189
+ this.pointer = this.pointer > 0 ? this.pointer - 1 : len - 1;
190
+ this.render();
191
+ }
192
+ onDownKey() {
193
+ const len = this.choices.realLength;
194
+ this.pointer = this.pointer < len - 1 ? this.pointer + 1 : 0;
195
+ this.render();
196
+ }
197
+ onNumberKey(input) {
198
+ if (input <= this.choices.realLength) {
199
+ this.pointer = input - 1;
200
+ this.toggleChoice(this.choices.getChoice(this.pointer));
201
+ }
202
+ this.render();
203
+ }
204
+ onSpaceKey() {
205
+ if (this.choices.getChoice(this.pointer) == null) {
206
+ return;
207
+ }
208
+ this.toggleChoice(this.choices.getChoice(this.pointer));
209
+ this.render();
210
+ }
211
+ onAllKey() {
212
+ const shouldBeChecked = Boolean(this.choices.find((choice) => {
213
+ return choice.type !== 'separator' && !choice.checked;
214
+ }));
215
+ this.choices.forEach((choice) => {
216
+ if (choice.type !== 'separator') {
217
+ choice.checked = shouldBeChecked;
218
+ }
219
+ return choice;
220
+ });
221
+ this.render();
222
+ }
223
+ onInverseKey() {
224
+ this.choices.forEach((choice) => {
225
+ if (choice.type !== 'separator') {
226
+ choice.checked = !choice.checked;
227
+ }
228
+ });
229
+ this.render();
230
+ }
231
+ onKeypress() {
232
+ this.executeSource();
233
+ this.render();
234
+ }
235
+ toggleChoice(choice, nextChecked) {
236
+ var _a;
237
+ if (choice.type === 'separator') {
238
+ return;
239
+ }
240
+ const checked = nextChecked == null ? !((_a = choice.checked) !== null && _a !== void 0 ? _a : false) : nextChecked;
241
+ this.value = this.value.filter((eachValue) => eachValue !== choice.value);
242
+ this.checkedChoices = this.checkedChoices.filter((checkedChoice) => checkedChoice.value !== choice.value);
243
+ choice.checked = false;
244
+ if (checked === true) {
245
+ this.value.push(choice.value);
246
+ this.checkedChoices.push(choice);
247
+ choice.checked = true;
248
+ }
249
+ }
250
+ static getCheckboxFigure(checked = false) {
251
+ return checked ? chalk_1.default.green(figures_1.default.radioOn) : figures_1.default.radioOff;
252
+ }
253
+ renderChoices(choices, pointer) {
254
+ const output = [];
255
+ let separatorOffset = 0;
256
+ choices.forEach((choice, index) => {
257
+ if (choice.type === 'separator') {
258
+ separatorOffset += 1;
259
+ output.push(` ${choice}\n`);
260
+ return;
261
+ }
262
+ if (choice.disabled) {
263
+ separatorOffset += 1;
264
+ output.push(` - ${choice.name} (${typeof choice.disabled === 'string' ? choice.disabled : 'Disabled'})\n`);
265
+ return;
266
+ }
267
+ if (index - separatorOffset === pointer) {
268
+ output.push(chalk_1.default.cyan(figures_1.default.pointer));
269
+ output.push(SearchBox.getCheckboxFigure(choice.checked));
270
+ output.push(' ');
271
+ output.push(this.opt.highlight ? chalk_1.default.gray(choice.name) : choice.name);
272
+ }
273
+ else {
274
+ output.push(` ${SearchBox.getCheckboxFigure(choice.checked)} ${choice.name}`);
275
+ }
276
+ output.push('\n');
277
+ });
278
+ return output.join('').replace(/\n$/, '');
279
+ }
280
+ }
281
+ exports.default = SearchBox;
@@ -41,7 +41,7 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
41
41
  name: targ.name + '_proxy',
42
42
  server: 'service'
43
43
  });
44
- return Object.assign(Object.assign({}, targ), { port: { appsail: appsailPort, proxy: proxyPort } });
44
+ return Object.assign(Object.assign({}, targ), { port: { appsail: appsailPort, proxy: proxyPort }, trigger: { kill: false } });
45
45
  })));
46
46
  runtime_store_1.default.set('context.appsail.targets', filledTargets);
47
47
  });