zcatalyst-cli 1.15.0-beta.5 → 1.15.0-beta.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.
Files changed (43) hide show
  1. package/docs/serve/server/index.toml +5 -0
  2. package/docs/serve/server/lib/appsail/index.toml +4 -0
  3. package/lib/archiver.js +8 -3
  4. package/lib/client-utils.js +5 -1
  5. package/lib/commands/iac/pack.js +9 -8
  6. package/lib/deploy/features/appsail/index.js +15 -5
  7. package/lib/deploy/features/client.js +1 -1
  8. package/lib/deploy/features/functions/index.js +7 -4
  9. package/lib/endpoints/lib/applogic.js +14 -2
  10. package/lib/endpoints/lib/appsail.js +11 -2
  11. package/lib/endpoints/lib/client.js +11 -2
  12. package/lib/endpoints/lib/functions.js +14 -2
  13. package/lib/express_middlewares/logger.js +6 -2
  14. package/lib/fn-utils/lib/common.js +78 -48
  15. package/lib/fn-utils/lib/java.js +10 -10
  16. package/lib/fn-utils/lib/python.js +1 -1
  17. package/lib/init/features/appsail/index.js +2 -2
  18. package/lib/internal/api.js +33 -8
  19. package/lib/option-filter.js +4 -4
  20. package/lib/port-resolver.js +24 -11
  21. package/lib/progress.js +3 -2
  22. package/lib/prompt/types/file-path.js +3 -1
  23. package/lib/serve/features/appsail.js +14 -3
  24. package/lib/serve/features/index.js +1 -1
  25. package/lib/serve/index.js +7 -2
  26. package/lib/serve/server/index.js +317 -123
  27. package/lib/serve/server/lib/appsail/index.js +28 -10
  28. package/lib/serve/server/lib/appsail/start.js +4 -15
  29. package/lib/serve/server/lib/master.js +10 -10
  30. package/lib/serve/server/lib/web_client/index.js +5 -5
  31. package/lib/shell/dependencies/http-functions.js +11 -15
  32. package/lib/shell/prepare/languages/java.js +9 -4
  33. package/lib/util_modules/constants/lib/default.js +4 -1
  34. package/lib/util_modules/constants/lib/scopes.js +1 -0
  35. package/lib/util_modules/fs/lib/async.js +11 -17
  36. package/lib/util_modules/fs/lib/sync.js +5 -1
  37. package/package.json +1 -1
  38. package/templates/init/functions/java/integ/convokraft/FallbackHandler.java +1 -0
  39. package/templates/init/functions/node/integ/convokraft/fallback.js +1 -0
  40. package/templates/init/functions/python/integ/convokraft/fallback_handler.py +2 -1
  41. package/templates/init/functions/node/.DS_Store +0 -0
  42. package/templates/init/functions/node/integ/.DS_Store +0 -0
  43. package/templates/init/functions/node/integ/convokraft/.DS_Store +0 -0
@@ -44,6 +44,8 @@ const constants_1 = require("../util_modules/constants");
44
44
  const js_1 = require("../util_modules/js");
45
45
  const logger_1 = require("../util_modules/logger");
46
46
  const project_1 = require("../util_modules/project");
47
+ const fs_1 = require("fs");
48
+ const throbber_1 = __importDefault(require("../throbber"));
47
49
  class API {
48
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)() } = {}) {
49
51
  this.requestOpts = {
@@ -63,7 +65,6 @@ class API {
63
65
  this.logOpts = log;
64
66
  this.maxRetryCount = maxRetry;
65
67
  this.retryCount = 0;
66
- this.progress = null;
67
68
  this.showWarning = showWarning;
68
69
  }
69
70
  _logReq() {
@@ -100,12 +101,21 @@ class API {
100
101
  }
101
102
  if (this.logOpts.progress !== undefined) {
102
103
  js_1.JS.set(this.logOpts, 'progress.total', resp.headers['content-length']);
103
- this.progress = new progress_1.default(this.logOpts.progress);
104
+ this.downloadProgress = new progress_1.default(this.logOpts.progress);
104
105
  }
105
106
  }
106
- _logProgress({ chunk, error } = {}) {
107
- if (this.progress !== null) {
108
- !chunk || error ? this.progress.error(error) : this.progress.tick(chunk.length);
107
+ _logUploadProgress({ chunk, error } = {}) {
108
+ if (this.uploadProgress) {
109
+ !chunk || error
110
+ ? this.uploadProgress.error(error)
111
+ : this.uploadProgress.tick(chunk.length);
112
+ }
113
+ }
114
+ _logDownloadProgress({ chunk, error } = {}) {
115
+ if (this.downloadProgress) {
116
+ !chunk || error
117
+ ? this.downloadProgress.error(error)
118
+ : this.downloadProgress.tick(chunk.length);
109
119
  }
110
120
  }
111
121
  _addAuthHeader() {
@@ -130,10 +140,10 @@ class API {
130
140
  (0, logger_1.debug)('Response Body : ' + JSON.stringify(resp.body) + '\n');
131
141
  if (!this.resolveOnHTTPError) {
132
142
  const errRes = (0, errorResponse_1.default)(resp, body);
133
- this._logProgress({ error: errRes });
143
+ this._logDownloadProgress({ error: errRes });
134
144
  throw errRes;
135
145
  }
136
- this._logProgress({ error: (0, errorResponse_1.default)(resp, body, true) });
146
+ this._logDownloadProgress({ error: (0, errorResponse_1.default)(resp, body, true) });
137
147
  }
138
148
  return {
139
149
  status: resp.statusCode,
@@ -164,7 +174,22 @@ class API {
164
174
  return new Promise((resolve, reject) => {
165
175
  const responseBuffer = [];
166
176
  let isJSONResponse = false;
177
+ const throbber = throbber_1.default.getInstance();
178
+ if (this.logOpts.uploadProgress !== undefined &&
179
+ this.logOpts.stream instanceof fs_1.ReadStream) {
180
+ const _stream = this.logOpts.stream;
181
+ this.uploadProgress = new progress_1.default(this.logOpts.uploadProgress);
182
+ _stream.on('data', (chunk) => {
183
+ this._logUploadProgress({ chunk });
184
+ });
185
+ }
186
+ if (this.logOpts.awaitingSpinner) {
187
+ this.logOpts.stream
188
+ ? this.logOpts.stream.on('end', () => throbber.add('response_await', { text: this.logOpts.awaitingSpinner }))
189
+ : throbber.add('response_await', { text: this.logOpts.awaitingSpinner });
190
+ }
167
191
  (0, request_1.default)(this.requestOpts, (err) => __awaiter(this, void 0, void 0, function* () {
192
+ this.logOpts.awaitingSpinner && throbber.remove('response_await');
168
193
  if (err) {
169
194
  switch (err.code) {
170
195
  case 'ETIMEDOUT':
@@ -205,7 +230,7 @@ class API {
205
230
  if (isJSONResponse) {
206
231
  responseBuffer.push(data);
207
232
  }
208
- this._logProgress({ chunk: data });
233
+ this._logDownloadProgress({ chunk: data });
209
234
  });
210
235
  });
211
236
  });
@@ -141,7 +141,7 @@ function validateTargets() {
141
141
  return [];
142
142
  }
143
143
  function validatePorts() {
144
- const customHttpPort = enrichOptsData('debug', (0, option_1.getOptionValue)('debug'), portTargets);
144
+ const customHttpPort = (0, option_1.getOptionValue)('http', undefined);
145
145
  const enrichedDebugOpts = enrichOptsData('debug', (0, option_1.getOptionValue)('debug'), portTargets);
146
146
  if (enrichedDebugOpts.some((opt) => {
147
147
  const noFilter = !opt.hasFilter;
@@ -185,11 +185,11 @@ function filterPorts() {
185
185
  ]
186
186
  });
187
187
  }
188
- else if (res.target.target === constants_1.REMOTE_REF.functions.type[constants_1.FN_TYPE.basic]) {
189
- runtime_store_1.default.set(`context.port.debug.${res.target}`, res.filter);
188
+ else if (res.target.target === constants_1.REMOTE_REF.functions.type.bio) {
189
+ runtime_store_1.default.set(`context.port.debug.${constants_1.REMOTE_REF.functions.type.bio}`, res.filter);
190
190
  }
191
191
  else {
192
- runtime_store_1.default.set(`context.port.debug.${res.target}.${res.filter}`, res.specific);
192
+ runtime_store_1.default.set(`context.port.debug.${res.target.target}.${res.filter}`, res.specific);
193
193
  }
194
194
  });
195
195
  }
@@ -8,9 +8,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
12
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
13
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
14
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
15
+ };
11
16
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
17
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
18
  };
19
+ var _a, _PortResolver_takenPorts, _PortResolver_isPortTaken;
14
20
  Object.defineProperty(exports, "__esModule", { value: true });
15
21
  const ansi_colors_1 = require("ansi-colors");
16
22
  const portfinder_1 = require("portfinder");
@@ -19,9 +25,6 @@ const runtime_store_1 = __importDefault(require("./runtime-store"));
19
25
  const constants_1 = require("./util_modules/constants");
20
26
  const logger_1 = require("./util_modules/logger");
21
27
  class PortResolver {
22
- static isPortTaken(port) {
23
- return PortResolver.takenPorts.includes(port);
24
- }
25
28
  static getFreePort(startPort, searchSpan, dupCheck) {
26
29
  return __awaiter(this, void 0, void 0, function* () {
27
30
  if (searchSpan < 0) {
@@ -31,20 +34,19 @@ class PortResolver {
31
34
  port: startPort,
32
35
  stopPort: startPort + searchSpan
33
36
  });
34
- if (PortResolver.isPortTaken(port)) {
37
+ if (__classPrivateFieldGet(PortResolver, _a, "m", _PortResolver_isPortTaken).call(PortResolver, port)) {
35
38
  if (dupCheck) {
36
39
  return PortResolver.getFreePort(port + 1, searchSpan - (port - startPort), dupCheck);
37
40
  }
38
41
  return port;
39
42
  }
40
- PortResolver.takenPorts.push(port);
43
+ __classPrivateFieldGet(PortResolver, _a, "f", _PortResolver_takenPorts).add(port);
41
44
  return port;
42
45
  });
43
46
  }
44
- static getPort(feature, type, name = '', duplicateCheck = true, pythonBio = false, searchSpan = 20, fallbackNeeded = true) {
47
+ static getPort(feature, type, { name = '', duplicateCheck = true, searchSpan = 20, fallbackNeeded = true, server } = {}) {
45
48
  return __awaiter(this, void 0, void 0, function* () {
46
49
  let port = parseInt(runtime_store_1.default.get(`context.port.${type}.${feature}.${name}`), 10);
47
- feature = pythonBio ? 'advancedio' : feature;
48
50
  port = isNaN(port) ? parseInt(runtime_store_1.default.get(`context.port.${type}.${feature}`), 10) : port;
49
51
  if (isNaN(port)) {
50
52
  if (type === 'debug' && feature === 'client') {
@@ -53,7 +55,15 @@ class PortResolver {
53
55
  if (!fallbackNeeded) {
54
56
  return -1;
55
57
  }
56
- port = constants_1.DEFAULT.serve_port[type][feature];
58
+ if (feature === 'appsail') {
59
+ if (!server || type !== 'http') {
60
+ throw new error_1.default('Invalid appsail details', { exit: 2 });
61
+ }
62
+ port = constants_1.DEFAULT.serve_port['http']['appsail'][server];
63
+ }
64
+ else {
65
+ port = constants_1.DEFAULT.serve_port[type][feature];
66
+ }
57
67
  }
58
68
  else {
59
69
  searchSpan = 0;
@@ -65,7 +75,7 @@ class PortResolver {
65
75
  }
66
76
  let finalPort = port;
67
77
  try {
68
- finalPort = yield PortResolver.getFreePort(port, searchSpan, duplicateCheck || pythonBio);
78
+ finalPort = yield PortResolver.getFreePort(port, searchSpan, duplicateCheck);
69
79
  }
70
80
  catch (e) {
71
81
  if (searchSpan === 0) {
@@ -86,7 +96,7 @@ class PortResolver {
86
96
  }
87
97
  const cerr = error_1.default.getErrorInstance(e, {
88
98
  message: `No ports from '${port}' to ${port + searchSpan} is free to use as a ${type} port.`,
89
- skipHelp: false,
99
+ skipHelp: server ? true : false,
90
100
  fileName: __filename
91
101
  });
92
102
  cerr.errorId = 'PORT-RESOLVER-2';
@@ -101,4 +111,7 @@ class PortResolver {
101
111
  }
102
112
  }
103
113
  exports.default = PortResolver;
104
- PortResolver.takenPorts = [];
114
+ _a = PortResolver, _PortResolver_isPortTaken = function _PortResolver_isPortTaken(port) {
115
+ return __classPrivateFieldGet(PortResolver, _a, "f", _PortResolver_takenPorts).has(port);
116
+ };
117
+ _PortResolver_takenPorts = { value: new Set() };
package/lib/progress.js CHANGED
@@ -7,7 +7,7 @@ const ansi_colors_1 = require("ansi-colors");
7
7
  const pretty_ms_1 = __importDefault(require("pretty-ms"));
8
8
  const throbber_1 = __importDefault(require("./throbber"));
9
9
  class Progress {
10
- constructor({ title = '', fillChar = '·', bgChar = ' ', startingChar = '[', endingChar = ']', total = 10, failure } = {}) {
10
+ constructor({ title = '', fillChar = '·', bgChar = ' ', startingChar = '[', endingChar = ']', total = 10, failure, progressType = 'download' } = {}) {
11
11
  this.title = title;
12
12
  this.fillChar = fillChar;
13
13
  this.bgChar = bgChar;
@@ -19,6 +19,7 @@ class Progress {
19
19
  this.currentProgress = 0;
20
20
  this.currentProgressFrame = '';
21
21
  this.failure = failure;
22
+ this.progressType = progressType;
22
23
  }
23
24
  get MAX_SCREEN_LENGTH() {
24
25
  return 35;
@@ -57,7 +58,7 @@ class Progress {
57
58
  if (this.throbber.hasActiveSpinners()) {
58
59
  const [totalSec] = process.hrtime(this.startTime);
59
60
  this.throbber.succeed(this.title, {
60
- text: `${this.title} downloaded in ${totalSec} seconds`
61
+ text: `${this.title} ${this.progressType}ed in ${totalSec} seconds`
61
62
  });
62
63
  }
63
64
  return;
@@ -23,7 +23,9 @@ function getPaths(rootPath, pattern, exclude, defaultItem) {
23
23
  filter: { exclude, excludeDir: false },
24
24
  includeDirPaths: true
25
25
  });
26
- const filteredNodes = fuzzy_1.default.filter(pattern || '', nodeList).map((e) => e.string);
26
+ const filteredNodes = fuzzy_1.default
27
+ .filter(pattern || '', nodeList, { extract: (node) => node.path })
28
+ .map((e) => e.string);
27
29
  if (!pattern && defaultItem) {
28
30
  filteredNodes.unshift(defaultItem);
29
31
  }
@@ -13,6 +13,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  const appsail_utils_1 = require("../../appsail-utils");
16
+ const error_1 = __importDefault(require("../../error"));
16
17
  const port_resolver_1 = __importDefault(require("../../port-resolver"));
17
18
  const runtime_store_1 = __importDefault(require("../../runtime-store"));
18
19
  const config_1 = require("../../util_modules/config");
@@ -26,12 +27,22 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
26
27
  }
27
28
  const validated = (0, appsail_utils_1.validateAppSail)(optionTargets);
28
29
  const filledTargets = yield Promise.all(validated.map((targ) => __awaiter(void 0, void 0, void 0, function* () {
29
- var _a;
30
+ var _a, _b;
30
31
  if (!targ.validity.valid) {
31
32
  return targ;
32
33
  }
33
- const port = yield port_resolver_1.default.getPort('appsail', 'http', (_a = targ.appSail) === null || _a === void 0 ? void 0 : _a.name);
34
- return Object.assign(Object.assign({}, targ), { port });
34
+ const proxyPort = yield port_resolver_1.default.getPort('appsail', 'http', {
35
+ name: ((_a = targ.appSail) === null || _a === void 0 ? void 0 : _a.name) + '_proxy',
36
+ searchSpan: 10,
37
+ server: 'master'
38
+ }).catch((err) => {
39
+ throw new error_1.default('No free ports between 3000 and 3010. AppSail needs the ports within this range to function properly', { original: err });
40
+ });
41
+ const appsailPort = yield port_resolver_1.default.getPort('appsail', 'http', {
42
+ name: ((_b = targ.appSail) === null || _b === void 0 ? void 0 : _b.name) + '_proxy',
43
+ server: 'service'
44
+ });
45
+ return Object.assign(Object.assign({}, targ), { port: { appsail: appsailPort, proxy: proxyPort } });
35
46
  })));
36
47
  runtime_store_1.default.set('context.appsail.targets', filledTargets);
37
48
  });
@@ -55,7 +55,7 @@ function client() {
55
55
  return;
56
56
  }
57
57
  const clientName = runtime_store_1.default.get('context.client.name');
58
- const finalPort = yield port_resolver_1.default.getPort('client', 'http', clientName);
58
+ const finalPort = yield port_resolver_1.default.getPort('client', 'http', { name: clientName });
59
59
  runtime_store_1.default.set('context.port.http.client.' + clientName, finalPort);
60
60
  });
61
61
  }
@@ -59,7 +59,7 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
59
59
  const buildFolder = (0, path_1.join)(projectRoot, constants_1.FOLDERNAME.build);
60
60
  if (yield fs_1.ASYNC.isPathExists(buildFolder)) {
61
61
  try {
62
- (0, logger_1.debug)('Build folder already exists, staring cleanup');
62
+ (0, logger_1.debug)('Build folder already exists, starting cleanup');
63
63
  yield fs_1.ASYNC.chmod((0, path_1.join)(buildFolder, constants_1.FOLDERNAME.functions), '755', {
64
64
  recursive: true
65
65
  });
@@ -75,7 +75,11 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
75
75
  }
76
76
  }
77
77
  try {
78
- const masterPort = yield port_resolver_1.default.getPort('master', 'http', 'master', false);
78
+ const masterPort = yield port_resolver_1.default.getPort('master', 'http', {
79
+ name: 'master',
80
+ duplicateCheck: false,
81
+ searchSpan: 10
82
+ });
79
83
  runtime_store_1.default.set('context.port.http.master', masterPort);
80
84
  yield Promise.all(serveTargets.map((target) => features[target]()));
81
85
  const rawTargets = runtime_store_1.default.get('context.functions.targets', []);
@@ -165,6 +169,7 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
165
169
  checkPath: false,
166
170
  recursive: true
167
171
  }).catch((err) => (0, logger_1.debug)('Error modifying the permissions: ', err)));
172
+ (0, logger_1.info)('Shutting down server');
168
173
  yield Promise.all([
169
174
  fs_1.ASYNC.deleteDir(buildFolder).catch(),
170
175
  advancedServer ? advancedServer.stop() : undefined,