zcatalyst-cli 1.7.1 → 1.9.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.
Files changed (179) hide show
  1. package/README.md +31 -10
  2. package/docs/apig-utils.toml +69 -0
  3. package/docs/authentication/index.toml +15 -0
  4. package/docs/authentication/login.toml +14 -0
  5. package/docs/client-utils.toml +24 -0
  6. package/docs/command_needs/auth.toml +4 -0
  7. package/docs/command_needs/rc.toml +24 -0
  8. package/docs/commands/apig/disable.toml +4 -0
  9. package/docs/commands/apig/enable.toml +4 -0
  10. package/docs/commands/apig/status.toml +4 -0
  11. package/docs/commands/client/delete.toml +34 -0
  12. package/docs/commands/ds/export.toml +4 -0
  13. package/docs/commands/ds/import.toml +15 -0
  14. package/docs/commands/ds/status.toml +9 -0
  15. package/docs/commands/event/generate/index.toml +29 -0
  16. package/docs/commands/event/generate/integ.toml +4 -0
  17. package/docs/commands/functions/config.toml +11 -0
  18. package/docs/commands/functions/delete.toml +29 -0
  19. package/docs/commands/project/use.toml +9 -0
  20. package/docs/dc.toml +4 -0
  21. package/docs/deploy/features/apig.toml +4 -0
  22. package/docs/deploy/features/functions/index.toml +4 -0
  23. package/docs/event_generate/cache.toml +4 -0
  24. package/docs/event_generate/custom.toml +4 -0
  25. package/docs/event_generate/datastore.toml +4 -0
  26. package/docs/event_generate/filestore.toml +4 -0
  27. package/docs/event_generate/integration/cliq.toml +9 -0
  28. package/docs/execute-script.toml +19 -0
  29. package/docs/fn-utils/lib/common.toml +25 -0
  30. package/docs/fn-utils/lib/java.toml +34 -0
  31. package/docs/fn-utils/lib/node.toml +4 -0
  32. package/docs/init/index.toml +4 -0
  33. package/docs/internal/command.toml +4 -0
  34. package/docs/internal/config.toml +9 -0
  35. package/docs/internal/credential.toml +14 -0
  36. package/docs/option-filter.toml +45 -0
  37. package/docs/port-resolver.toml +9 -0
  38. package/docs/pull/index.toml +4 -0
  39. package/docs/serve/index.toml +4 -0
  40. package/docs/shell/index.toml +4 -0
  41. package/docs/util_modules/project.toml +9 -0
  42. package/lib/apig-utils.js +133 -43
  43. package/lib/archiver.js +4 -2
  44. package/lib/authentication/index.js +44 -9
  45. package/lib/authentication/login.js +51 -8
  46. package/lib/bin/catalyst.js +14 -7
  47. package/lib/client-utils.js +47 -14
  48. package/lib/client.js +1 -1
  49. package/lib/command_needs/auth.js +5 -3
  50. package/lib/command_needs/rc.js +35 -13
  51. package/lib/commands/apig/disable.js +8 -3
  52. package/lib/commands/apig/enable.js +8 -3
  53. package/lib/commands/apig/status.js +29 -9
  54. package/lib/commands/client/delete.js +65 -26
  55. package/lib/commands/client/setup.js +2 -2
  56. package/lib/commands/deploy.js +2 -2
  57. package/lib/commands/ds/export.js +16 -8
  58. package/lib/commands/ds/import.js +20 -14
  59. package/lib/commands/ds/status.js +22 -11
  60. package/lib/commands/event/generate/index.js +62 -12
  61. package/lib/commands/event/generate/integ.js +7 -3
  62. package/lib/commands/functions/add.js +2 -2
  63. package/lib/commands/functions/config.js +11 -3
  64. package/lib/commands/functions/delete.js +36 -13
  65. package/lib/commands/functions/setup.js +2 -2
  66. package/lib/commands/functions/shell.js +2 -2
  67. package/lib/commands/help.js +1 -1
  68. package/lib/commands/index.js +2 -3
  69. package/lib/commands/init.js +4 -4
  70. package/lib/commands/login.js +2 -2
  71. package/lib/commands/logout.js +2 -2
  72. package/lib/commands/project/list.js +2 -2
  73. package/lib/commands/project/reset.js +1 -1
  74. package/lib/commands/project/use.js +18 -2
  75. package/lib/commands/pull.js +5 -5
  76. package/lib/commands/run.js +2 -2
  77. package/lib/commands/serve.js +7 -6
  78. package/lib/commands/token/generate.js +2 -2
  79. package/lib/commands/token/list.js +2 -2
  80. package/lib/commands/token/revoke.js +2 -2
  81. package/lib/commands/whoami.js +1 -1
  82. package/lib/dc.js +11 -1
  83. package/lib/deploy/features/apig.js +33 -33
  84. package/lib/deploy/features/client.js +12 -19
  85. package/lib/deploy/features/functions/index.js +14 -4
  86. package/lib/deploy/features/index.js +1 -1
  87. package/lib/deploy/index.js +2 -9
  88. package/lib/endpoints/index.js +5 -2
  89. package/lib/endpoints/lib/apig.js +15 -5
  90. package/lib/endpoints/lib/applogic.js +12 -4
  91. package/lib/endpoints/lib/cache.js +9 -3
  92. package/lib/endpoints/lib/catalyst-details.js +37 -0
  93. package/lib/endpoints/lib/client.js +15 -5
  94. package/lib/endpoints/lib/datastore.js +6 -2
  95. package/lib/endpoints/lib/ds-bulk.js +15 -5
  96. package/lib/endpoints/lib/env.js +3 -1
  97. package/lib/endpoints/lib/event-bus.js +3 -1
  98. package/lib/endpoints/lib/filestore.js +6 -2
  99. package/lib/endpoints/lib/functions.js +12 -4
  100. package/lib/endpoints/lib/project.js +9 -3
  101. package/lib/endpoints/lib/queue.js +9 -3
  102. package/lib/endpoints/lib/sdk.js +3 -1
  103. package/lib/endpoints/lib/zcql.js +3 -1
  104. package/lib/error.js +18 -0
  105. package/lib/errorOut.js +10 -7
  106. package/lib/event_generate/cache.js +9 -1
  107. package/lib/event_generate/custom.js +6 -1
  108. package/lib/event_generate/datastore.js +12 -2
  109. package/lib/event_generate/filestore.js +9 -1
  110. package/lib/event_generate/integration/cliq.js +10 -2
  111. package/lib/execute-script.js +35 -6
  112. package/lib/express_middlewares/unknownReqProxy.js +18 -7
  113. package/lib/fn-utils/index.js +1 -1
  114. package/lib/fn-utils/lib/common.js +95 -17
  115. package/lib/fn-utils/lib/integ.js +4 -3
  116. package/lib/fn-utils/lib/java.js +49 -13
  117. package/lib/fn-utils/lib/node.js +15 -6
  118. package/lib/fn-watcher.js +67 -0
  119. package/lib/index.js +13 -12
  120. package/lib/init/dependencies/package-json.js +3 -1
  121. package/lib/init/features/functions/index.js +41 -29
  122. package/lib/init/features/functions/languages/java.js +5 -4
  123. package/lib/init/features/functions/languages/node.js +6 -5
  124. package/lib/init/features/index.js +8 -4
  125. package/lib/init/index.js +10 -3
  126. package/lib/internal/api.js +9 -9
  127. package/lib/internal/command.js +19 -14
  128. package/lib/internal/config.js +15 -15
  129. package/lib/internal/credential.js +33 -7
  130. package/lib/internal/rc.js +18 -10
  131. package/lib/migration/global/1.4.0.js +4 -2
  132. package/lib/migration/global/1.6.2.js +4 -2
  133. package/lib/migration/index.js +1 -1
  134. package/lib/option-filter.js +79 -22
  135. package/lib/optional-import.js +1 -1
  136. package/lib/plugin-loader.js +1 -1
  137. package/lib/port-resolver.js +23 -3
  138. package/lib/prompt.js +1 -1
  139. package/lib/pull/features/functions/index.js +7 -7
  140. package/lib/pull/features/index.js +1 -1
  141. package/lib/pull/index.js +10 -3
  142. package/lib/repl-server.js +9 -5
  143. package/lib/serve/features/index.js +11 -2
  144. package/lib/serve/index.js +19 -9
  145. package/lib/serve/server/index.js +137 -60
  146. package/lib/serve/server/lib/client.js +1 -1
  147. package/lib/serve/server/lib/master.js +16 -3
  148. package/lib/serve/server/lib/node.js +1 -1
  149. package/lib/shell/dependencies/http-functions.js +120 -90
  150. package/lib/shell/dependencies/invoker/integ/node.js +1 -1
  151. package/lib/shell/dependencies/local-function.js +86 -119
  152. package/lib/shell/index.js +10 -10
  153. package/lib/shell/prepare/index.js +1 -4
  154. package/lib/shell/prepare/languages/index.js +15 -4
  155. package/lib/track.js +4 -1
  156. package/lib/util_modules/config/index.js +1 -1
  157. package/lib/util_modules/config/lib/apig.js +3 -3
  158. package/lib/util_modules/config/lib/client.js +3 -3
  159. package/lib/util_modules/config/lib/functions.js +5 -5
  160. package/lib/util_modules/constants/index.js +22 -20
  161. package/lib/util_modules/constants/lib/regex.js +3 -2
  162. package/lib/util_modules/constants/lib/runtime.js +9 -0
  163. package/lib/util_modules/contextHelp.js +63 -123
  164. package/lib/util_modules/fs/index.js +1 -1
  165. package/lib/util_modules/fs/lib/async.js +19 -2
  166. package/lib/util_modules/fs/lib/sync.js +13 -1
  167. package/lib/util_modules/logger.js +12 -20
  168. package/lib/util_modules/option.js +1 -13
  169. package/lib/util_modules/project.js +75 -26
  170. package/lib/util_modules/shell.js +8 -2
  171. package/package.json +45 -45
  172. package/scripts/postInstall.js +31 -0
  173. package/lib/cjson.js +0 -20
  174. package/lib/log-error.js +0 -18
  175. package/lib/util_modules/big-json.js +0 -16
  176. package/lib/util_modules/constants/lib/stack.js +0 -6
  177. package/templates/init/functions/.DS_Store +0 -0
  178. package/templates/init/functions/node/.DS_Store +0 -0
  179. package/templates/init/functions/node/integ/.DS_Store +0 -0
@@ -18,72 +18,46 @@ const fn_utils_1 = require("../../fn-utils");
18
18
  const credential_1 = __importDefault(require("../../internal/credential"));
19
19
  const runtime_store_1 = __importDefault(require("../../runtime-store"));
20
20
  const constants_1 = require("../../util_modules/constants");
21
+ const runtime_1 = __importDefault(require("../../util_modules/constants/lib/runtime"));
21
22
  const fs_1 = require("../../util_modules/fs");
22
23
  const js_1 = require("../../util_modules/js");
23
24
  const logger_1 = require("../../util_modules/logger");
24
25
  const project_1 = require("../../util_modules/project");
25
26
  const shell_1 = require("../../util_modules/shell");
26
- const languages_1 = require("../prepare/languages");
27
- function prepareTarget(target) {
28
- return __awaiter(this, void 0, void 0, function* () {
29
- switch (target.stack) {
30
- case constants_1.STACK.java8:
31
- return languages_1.java([target]);
32
- case constants_1.STACK.node10:
33
- return languages_1.node([target]);
34
- default:
35
- throw new error_1.default('Unknown stack received', { exit: 2 });
36
- }
37
- });
38
- }
39
27
  class LocalFunction {
40
28
  constructor(repl, target) {
29
+ var _a, _b, _c;
41
30
  if (target.type === undefined || !Object.values(constants_1.FN_TYPE).includes(target.type)) {
42
31
  throw new error_1.default('target type is not defined', { exit: 2 });
43
32
  }
44
33
  this.repl = repl;
34
+ this.watcher = target.watcher;
45
35
  this.target = js_1.JS.omit(target, ['zip_stream', 'watcher']);
46
36
  this.slave = null;
47
37
  this.nodeInvoker = path_1.normalize(path_1.join(__dirname, './invoker', target.type, 'node.js'));
48
38
  this.javaInvoker = path_1.join(runtime_store_1.default.get('cwd'), '.build', '.catalyst', 'Java' + target.type + 'Invoker');
49
- if (target.stack === constants_1.STACK.java8) {
39
+ if ((_a = target.stack) === null || _a === void 0 ? void 0 : _a.startsWith(runtime_1.default.language.java)) {
50
40
  fn_utils_1.fnUtils.java.ensureJavaInvoker(this.javaInvoker, path_1.normalize(path_1.join(__dirname, './invoker', target.type, 'java', 'Java' + target.type + 'Invoker.java')));
51
41
  }
52
42
  this.responseFile = path_1.join(runtime_store_1.default.get('cwd'), '.build', '.catalyst', 'user_res_body');
53
43
  this.metaFile = path_1.join(runtime_store_1.default.get('cwd'), '.build', '.catalyst', 'user_meta.json');
54
44
  this.call = this._call.bind(this);
55
- if (target.watcher) {
56
- this.watcher = target.watcher;
57
- target.watcher.on('all', (eventName, pth) => __awaiter(this, void 0, void 0, function* () {
45
+ (_b = this.watcher) === null || _b === void 0 ? void 0 : _b.on('preparing', () => {
46
+ if (!this.repl.paused) {
58
47
  this.repl.pause();
59
- shell_1.clearLine(process.stdout);
60
- logger_1.info(`\n${eventName} of ${pth} in ${target.name} detected. Preparing your function, please wait...`);
61
- const finalTargets = yield prepareTarget(target);
62
- if (finalTargets === undefined || finalTargets.length === 0) {
63
- logger_1.warning('target [' +
64
- target.name +
65
- '] is not a valid one reason : ' +
66
- target.failure_reason);
67
- logger_1.info('Waiting for correction..');
68
- if (this.exitTimer) {
69
- this.exitTimer.refresh();
70
- }
71
- else {
72
- this.exitTimer = setTimeout(() => {
73
- logger_1.info('\n(To exit, press ^C)');
74
- }, 2000);
75
- }
76
- }
77
- else {
78
- logger_1.labeled(`functions(${target.name})`, 'ready!').MESSAGE();
79
- if (this.exitTimer) {
80
- clearTimeout(this.exitTimer);
81
- }
82
- this.repl.resume();
83
- this.repl.showPrompt();
84
- }
85
- }));
86
- }
48
+ }
49
+ });
50
+ (_c = this.watcher) === null || _c === void 0 ? void 0 : _c.on('compiled', () => {
51
+ logger_1.labeled(`functions(${target.name})`, 'ready!').MESSAGE();
52
+ if (this.repl.paused) {
53
+ repl.resume();
54
+ repl.showPrompt();
55
+ }
56
+ setTimeout(() => {
57
+ var _a;
58
+ (_a = this.watcher) === null || _a === void 0 ? void 0 : _a.emit('next');
59
+ }, 1000);
60
+ });
87
61
  }
88
62
  _call(rawData = {}) {
89
63
  let data;
@@ -107,90 +81,86 @@ class LocalFunction {
107
81
  return new error_1.default('Event bus details missing');
108
82
  }
109
83
  return (() => __awaiter(this, void 0, void 0, function* () {
110
- var _a, _b;
84
+ var _a, _b, _c, _d;
111
85
  const accessToken = yield credential_1.default.getAccessToken();
112
86
  const slaveOptions = [];
113
87
  const debugPort = runtime_store_1.default.get('context.port.debug.' + constants_1.REMOTE_REF.functions.type[constants_1.FN_TYPE.basic], null);
114
88
  yield fs_1.ASYNC.ensureFile(this.responseFile, true);
115
89
  yield fs_1.ASYNC.ensureFile(this.metaFile, true);
116
- switch (this.target.stack) {
117
- case constants_1.STACK.node10:
118
- if (debugPort !== null) {
119
- slaveOptions.push('--inspect-brk=' + debugPort);
90
+ if ((_a = this.target.stack) === null || _a === void 0 ? void 0 : _a.startsWith(runtime_1.default.language.nodejs)) {
91
+ if (debugPort !== null) {
92
+ slaveOptions.push('--inspect-brk=' + debugPort);
93
+ }
94
+ slaveOptions.push(this.nodeInvoker);
95
+ slaveOptions.push(JSON.stringify(this.target));
96
+ slaveOptions.push(data);
97
+ slaveOptions.push(JSON.stringify({
98
+ 'x-zc-projectid': project_1.getProjectId(),
99
+ 'x-zc-project-domain': project_1.getDomainPrefix() + '.' + constants_1.ORIGIN.app.replace('https://', ''),
100
+ 'x-zc-project-key': project_1.getDomainKey(),
101
+ 'x-zc-environment': project_1.getEnvName()
102
+ }));
103
+ slaveOptions.push(JSON.stringify({
104
+ 'x-zc-user-cred-type': 'token',
105
+ 'x-zc-user-cred-token': accessToken,
106
+ 'x-zc-admin-cred-type': 'token',
107
+ 'x-zc-admin-cred-token': accessToken
108
+ }));
109
+ slaveOptions.push(JSON.stringify(path_1.join(runtime_store_1.default.get('cwd'), '.build')));
110
+ this.slave = shell_1.spawn('node', slaveOptions, {
111
+ cwd: this.target.source,
112
+ stdio: 'pipe',
113
+ env: {
114
+ X_ZOHO_CATALYST_IS_LOCAL: 'true',
115
+ X_ZOHO_CATALYST_ACCOUNTS_URL: constants_1.ORIGIN.auth,
116
+ X_ZOHO_CATALYST_CONSOLE_URL: constants_1.ORIGIN.admin
120
117
  }
121
- slaveOptions.push(this.nodeInvoker);
122
- slaveOptions.push(JSON.stringify(this.target));
123
- slaveOptions.push(data);
124
- slaveOptions.push(JSON.stringify({
125
- 'x-zc-projectid': project_1.getProjectId(),
126
- 'x-zc-project-domain': project_1.getDomainPrefix() + '.' + constants_1.ORIGIN.app.replace('https://', ''),
127
- 'x-zc-project-key': project_1.getDomainKey(),
128
- 'x-zc-environment': project_1.getEnvName()
129
- }));
130
- slaveOptions.push(JSON.stringify({
131
- 'x-zc-user-cred-type': 'token',
132
- 'x-zc-user-cred-token': accessToken,
133
- 'x-zc-admin-cred-type': 'token',
134
- 'x-zc-admin-cred-token': accessToken
135
- }));
136
- slaveOptions.push(JSON.stringify(path_1.join(runtime_store_1.default.get('cwd'), '.build')));
137
- this.slave = shell_1.spawn('node', slaveOptions, {
138
- cwd: this.target.source,
139
- stdio: 'pipe',
140
- env: {
141
- X_ZOHO_CATALYST_IS_LOCAL: 'true',
142
- X_ZOHO_CATALYST_ACCOUNTS_URL: constants_1.ORIGIN.auth,
143
- X_ZOHO_CATALYST_CONSOLE_URL: constants_1.ORIGIN.admin
144
- }
145
- }).RAW();
146
- break;
147
- case constants_1.STACK.java8:
148
- const javaInvokerDir = path_1.parse(this.javaInvoker).dir;
149
- slaveOptions.push('-cp');
150
- slaveOptions.push(javaInvokerDir +
151
- fn_utils_1.fnUtils.java.classPathSep +
152
- path_1.join(javaInvokerDir, 'lib', '*'));
153
- if (debugPort !== null) {
154
- slaveOptions.push('-Xdebug');
155
- slaveOptions.push('-Xrunjdwp:transport=dt_socket,address=' +
156
- debugPort +
157
- ',server=y,suspend=y');
118
+ }).RAW();
119
+ }
120
+ else if ((_b = this.target.stack) === null || _b === void 0 ? void 0 : _b.startsWith(runtime_1.default.language.java)) {
121
+ const javaInvokerDir = path_1.parse(this.javaInvoker).dir;
122
+ slaveOptions.push('-cp');
123
+ slaveOptions.push(javaInvokerDir + fn_utils_1.fnUtils.java.classPathSep + path_1.join(javaInvokerDir, 'lib', '*'));
124
+ if (debugPort !== null) {
125
+ slaveOptions.push('-Xdebug');
126
+ slaveOptions.push('-Xrunjdwp:transport=dt_socket,address=' + debugPort + ',server=y,suspend=y');
127
+ }
128
+ slaveOptions.push(path_1.basename(this.javaInvoker));
129
+ slaveOptions.push(javaInvokerDir);
130
+ slaveOptions.push(JSON.stringify(this.target));
131
+ slaveOptions.push(data);
132
+ slaveOptions.push(JSON.stringify({
133
+ 'x-zc-projectid': project_1.getProjectId(),
134
+ 'x-zc-project-domain': project_1.getDomainPrefix() + '.' + constants_1.ORIGIN.app.replace('https://', ''),
135
+ 'x-zc-project-key': project_1.getDomainKey(),
136
+ 'x-zc-environment': project_1.getEnvName()
137
+ }));
138
+ slaveOptions.push(JSON.stringify({
139
+ 'x-zc-user-cred-type': 'token',
140
+ 'x-zc-user-cred-token': accessToken,
141
+ 'x-zc-admin-cred-type': 'token',
142
+ 'x-zc-admin-cred-token': accessToken
143
+ }));
144
+ this.slave = shell_1.spawn('java', slaveOptions, {
145
+ cwd: this.target.source,
146
+ stdio: 'pipe',
147
+ env: {
148
+ X_ZOHO_CATALYST_IS_LOCAL: 'true',
149
+ X_ZOHO_CATALYST_ACCOUNTS_URL: constants_1.ORIGIN.auth,
150
+ X_ZOHO_CATALYST_CONSOLE_URL: constants_1.ORIGIN.admin
158
151
  }
159
- slaveOptions.push(path_1.basename(this.javaInvoker));
160
- slaveOptions.push(javaInvokerDir);
161
- slaveOptions.push(JSON.stringify(this.target));
162
- slaveOptions.push(data);
163
- slaveOptions.push(JSON.stringify({
164
- 'x-zc-projectid': project_1.getProjectId(),
165
- 'x-zc-project-domain': project_1.getDomainPrefix() + '.' + constants_1.ORIGIN.app.replace('https://', ''),
166
- 'x-zc-project-key': project_1.getDomainKey(),
167
- 'x-zc-environment': project_1.getEnvName()
168
- }));
169
- slaveOptions.push(JSON.stringify({
170
- 'x-zc-user-cred-type': 'token',
171
- 'x-zc-user-cred-token': accessToken,
172
- 'x-zc-admin-cred-type': 'token',
173
- 'x-zc-admin-cred-token': accessToken
174
- }));
175
- this.slave = shell_1.spawn('java', slaveOptions, {
176
- cwd: this.target.source,
177
- stdio: 'pipe',
178
- env: {
179
- X_ZOHO_CATALYST_IS_LOCAL: 'true',
180
- X_ZOHO_CATALYST_ACCOUNTS_URL: constants_1.ORIGIN.auth,
181
- X_ZOHO_CATALYST_CONSOLE_URL: constants_1.ORIGIN.admin
182
- }
183
- }).RAW();
184
- break;
152
+ }).RAW();
185
153
  }
186
154
  if (this.slave === null) {
187
- throw new error_1.default('Slave listening started before initialising', { exit: 2 });
155
+ throw new error_1.default('Slave listening started before initialising', {
156
+ exit: 2
157
+ });
188
158
  }
189
- (_a = this.slave.stdout) === null || _a === void 0 ? void 0 : _a.on('data', (message) => {
159
+ (_c = this.slave.stdout) === null || _c === void 0 ? void 0 : _c.on('data', (message) => {
190
160
  shell_1.clearLine(process.stdout);
191
161
  logger_1.info(message.toString());
192
162
  });
193
- (_b = this.slave.stderr) === null || _b === void 0 ? void 0 : _b.on('data', (message) => {
163
+ (_d = this.slave.stderr) === null || _d === void 0 ? void 0 : _d.on('data', (message) => {
194
164
  const errorStr = js_1.JS.trim(message.toString());
195
165
  shell_1.clearLine(process.stdout);
196
166
  logger_1.info(errorStr);
@@ -238,9 +208,6 @@ class LocalFunction {
238
208
  if (this.slave) {
239
209
  this.slave.kill('SIGINT');
240
210
  }
241
- if (this.exitTimer) {
242
- clearTimeout(this.exitTimer);
243
- }
244
211
  if (this.watcher) {
245
212
  this.watcher.close().then(res).catch(res);
246
213
  }
@@ -12,7 +12,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- const chokidar_1 = require("chokidar");
16
15
  const path_1 = require("path");
17
16
  const util_1 = require("util");
18
17
  const repl_server_1 = __importDefault(require("../repl-server"));
@@ -27,6 +26,7 @@ const option_1 = require("../util_modules/option");
27
26
  const http_functions_1 = __importDefault(require("./dependencies/http-functions"));
28
27
  const local_function_1 = __importDefault(require("./dependencies/local-function"));
29
28
  const prepare_1 = __importDefault(require("./prepare"));
29
+ const fn_watcher_1 = __importDefault(require("../fn-watcher"));
30
30
  exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
31
31
  const replServer = new repl_server_1.default({
32
32
  prompt: 'functions > ',
@@ -56,21 +56,21 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
56
56
  return target.valid;
57
57
  });
58
58
  if (targets.length === 0) {
59
- throw new error_1.default('No functions are ready for serving', { exit: 1 });
59
+ throw new error_1.default('No functions are ready for serving', {
60
+ exit: 0,
61
+ errorId: 'SHELL-IDX-1'
62
+ });
60
63
  }
61
64
  replServer.start();
62
- targets.forEach((target) => {
63
- if (option_1.getOptionValue('watch', false)) {
64
- target.watcher = chokidar_1.watch(target.source, {
65
- ignored: /(^|[\/\\])\../,
66
- cwd: target.source,
67
- ignoreInitial: true
68
- });
65
+ const watchOpt = option_1.getOptionValue('watch', false);
66
+ yield Promise.all(targets.map((target) => __awaiter(void 0, void 0, void 0, function* () {
67
+ if (watchOpt) {
68
+ yield fn_watcher_1.default(target);
69
69
  }
70
70
  const localFn = new local_function_1.default(replServer, target);
71
71
  replServer.setContext(target.name, localFn.call);
72
72
  target.localFn = localFn;
73
- });
73
+ })));
74
74
  if (runtime_store_1.default.get('context.port.http.' + constants_1.REMOTE_REF.functions.type[constants_1.FN_TYPE.basic], false)) {
75
75
  yield httpServer.start();
76
76
  }
@@ -32,10 +32,7 @@ exports.default = (fnTypes) => __awaiter(void 0, void 0, void 0, function* () {
32
32
  return target;
33
33
  });
34
34
  runtime_store_1.default.set('context.functions.targets', refinedTargets);
35
- yield Promise.all([
36
- languages_1.node(refinedTargets.filter((target) => target.stack === constants_1.STACK.node10 && target.valid)),
37
- languages_1.java(refinedTargets.filter((target) => target.stack === constants_1.STACK.java8 && target.valid))
38
- ]);
35
+ yield languages_1.prepareFunctions(refinedTargets);
39
36
  yield common_1.resolveAllFnPorts(refinedTargets);
40
37
  return refinedTargets;
41
38
  });
@@ -14,7 +14,7 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
14
14
  var __importStar = (this && this.__importStar) || function (mod) {
15
15
  if (mod && mod.__esModule) return mod;
16
16
  var result = {};
17
- if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
18
  __setModuleDefault(result, mod);
19
19
  return result;
20
20
  };
@@ -27,17 +27,28 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
27
27
  step((generator = generator.apply(thisArg, _arguments || [])).next());
28
28
  });
29
29
  };
30
+ var __importDefault = (this && this.__importDefault) || function (mod) {
31
+ return (mod && mod.__esModule) ? mod : { "default": mod };
32
+ };
30
33
  Object.defineProperty(exports, "__esModule", { value: true });
31
- exports.java = exports.node = void 0;
34
+ exports.prepareFunctions = void 0;
35
+ const runtime_1 = __importDefault(require("../../../util_modules/constants/lib/runtime"));
32
36
  function node(targets) {
33
37
  return __awaiter(this, void 0, void 0, function* () {
34
38
  return (yield Promise.resolve().then(() => __importStar(require('./node')))).default(targets);
35
39
  });
36
40
  }
37
- exports.node = node;
38
41
  function java(targets) {
39
42
  return __awaiter(this, void 0, void 0, function* () {
40
43
  return (yield Promise.resolve().then(() => __importStar(require('./java')))).default(targets);
41
44
  });
42
45
  }
43
- exports.java = java;
46
+ function prepareFunctions(targets) {
47
+ return __awaiter(this, void 0, void 0, function* () {
48
+ return Promise.all([
49
+ node(targets.filter((target) => { var _a; return ((_a = target.stack) === null || _a === void 0 ? void 0 : _a.startsWith(runtime_1.default.language.nodejs)) && target.valid; })),
50
+ java(targets.filter((target) => { var _a; return ((_a = target.stack) === null || _a === void 0 ? void 0 : _a.startsWith(runtime_1.default.language.java)) && target.valid; }))
51
+ ]);
52
+ });
53
+ }
54
+ exports.prepareFunctions = prepareFunctions;
package/lib/track.js CHANGED
@@ -32,6 +32,10 @@ exports.default = (event, message, duration) => __awaiter(void 0, void 0, void 0
32
32
  config_store_1.default.get('usage', false) &&
33
33
  httpLog !== undefined) {
34
34
  const httpLogger = yield endpoints_1.logAPI();
35
+ if (httpLogger === undefined) {
36
+ logger_1.debug('Unable to initialise the log API');
37
+ return;
38
+ }
35
39
  winston_1.logger.remove(httpLog);
36
40
  const rl = readline_1.createInterface({
37
41
  input: fs_1.SYNC.getReadStream(path_1.join(httpLog.dirname, httpLog.filename)),
@@ -51,5 +55,4 @@ exports.default = (event, message, duration) => __awaiter(void 0, void 0, void 0
51
55
  catch (err) {
52
56
  logger_1.debug('Unable to send debug log to server: ' + err.message);
53
57
  }
54
- return Promise.resolve();
55
58
  });
@@ -14,7 +14,7 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
14
14
  var __importStar = (this && this.__importStar) || function (mod) {
15
15
  if (mod && mod.__esModule) return mod;
16
16
  var result = {};
17
- if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
18
  __setModuleDefault(result, mod);
19
19
  return result;
20
20
  };
@@ -11,7 +11,7 @@ function raw(throwError = false) {
11
11
  const config = runtime_store_1.default.get('config', null);
12
12
  if (config === null) {
13
13
  if (throwError) {
14
- throw new error_1.default(constants_1.FILENAME.config + ' file is required', { exit: 1 });
14
+ throw new error_1.default(constants_1.FILENAME.config + ' file is required', { exit: 2 });
15
15
  }
16
16
  return;
17
17
  }
@@ -32,13 +32,13 @@ function script(name, fallback) {
32
32
  const apigConfig = raw();
33
33
  const rawScripts = apigConfig && (apigConfig === null || apigConfig === void 0 ? void 0 : apigConfig.scripts);
34
34
  if (rawScripts === undefined && fallback === undefined) {
35
- throw new error_1.default('Scripts not found', { exit: 1 });
35
+ throw new error_1.default('Scripts not found', { exit: 2 });
36
36
  }
37
37
  if (name === undefined) {
38
38
  return rawScripts || fallback;
39
39
  }
40
40
  if (rawScripts && rawScripts[name] === undefined && fallback === undefined) {
41
- throw new error_1.default('Scripts not found', { exit: 1 });
41
+ throw new error_1.default('Scripts not found', { exit: 2 });
42
42
  }
43
43
  return (rawScripts && rawScripts[name]) || fallback;
44
44
  }
@@ -14,7 +14,7 @@ function raw(throwError = false) {
14
14
  const config = runtime_store_1.default.get('config', null);
15
15
  if (config === null) {
16
16
  if (throwError) {
17
- throw new error_1.default(constants_1.FILENAME.config + ' file is required', { exit: 1 });
17
+ throw new error_1.default(constants_1.FILENAME.config + ' file is required', { exit: 2 });
18
18
  }
19
19
  return;
20
20
  }
@@ -75,13 +75,13 @@ function script(name, fallback) {
75
75
  const clientConfig = raw();
76
76
  const rawScripts = clientConfig && (clientConfig === null || clientConfig === void 0 ? void 0 : clientConfig.scripts);
77
77
  if (rawScripts === undefined && fallback === undefined) {
78
- throw new error_1.default('Scripts not found', { exit: 1 });
78
+ throw new error_1.default('Scripts not found', { exit: 2 });
79
79
  }
80
80
  if (name === undefined) {
81
81
  return rawScripts || fallback;
82
82
  }
83
83
  if (rawScripts && rawScripts[name] === undefined && fallback === undefined) {
84
- throw new error_1.default('Scripts not found', { exit: 1 });
84
+ throw new error_1.default('Scripts not found', { exit: 2 });
85
85
  }
86
86
  return (rawScripts && rawScripts[name]) || fallback;
87
87
  }
@@ -36,7 +36,7 @@ function raw(throwError = false) {
36
36
  const config = runtime_store_1.default.get('config', null);
37
37
  if (config === null) {
38
38
  if (throwError) {
39
- throw new error_1.default(constants_1.FILENAME.config + ' file is required', { exit: 1 });
39
+ throw new error_1.default(constants_1.FILENAME.config + ' file is required', { exit: 2 });
40
40
  }
41
41
  return;
42
42
  }
@@ -85,7 +85,7 @@ function targets(fallback) {
85
85
  const rawTargetArr = getRawTargets();
86
86
  if (rawTargetArr === null) {
87
87
  if (fallback === undefined) {
88
- throw new error_1.default('Function targets array is empty.', { exit: 1 });
88
+ throw new error_1.default('Function targets array is empty.', { exit: 2 });
89
89
  }
90
90
  return fallback;
91
91
  }
@@ -96,7 +96,7 @@ function targets(fallback) {
96
96
  if (typeof targetVal.source === 'string') {
97
97
  return targetVal.source;
98
98
  }
99
- throw new error_1.default('Function target array is corrupted.', { exit: 1 });
99
+ throw new error_1.default('Function target array is corrupted.', { exit: 2 });
100
100
  });
101
101
  }
102
102
  exports.targets = targets;
@@ -114,13 +114,13 @@ function script(name, fallback, sourcePath) {
114
114
  rawScripts = functionConfig && (functionConfig === null || functionConfig === void 0 ? void 0 : functionConfig.scripts);
115
115
  }
116
116
  if (rawScripts === undefined && fallback === undefined) {
117
- throw new error_1.default('Scripts not found', { exit: 1 });
117
+ throw new error_1.default('Scripts not found', { exit: 2 });
118
118
  }
119
119
  if (name === undefined) {
120
120
  return rawScripts || fallback;
121
121
  }
122
122
  if (rawScripts && rawScripts[name] === undefined && fallback === undefined) {
123
- throw new error_1.default('Scripts not found', { exit: 1 });
123
+ throw new error_1.default('Scripts not found', { exit: 2 });
124
124
  }
125
125
  return (rawScripts && rawScripts[name]) || fallback;
126
126
  }
@@ -1,40 +1,42 @@
1
1
  'use strict';
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.ORIGIN = exports.TEMPLATE = exports.SCOPE = exports.REMOTE_REF = exports.REGEX = exports.REFERENCE = exports.PLACEHOLDER = exports.INTEG = exports.FOLDERNAME = exports.FN_TYPE = exports.DC_TYPE = exports.FILENAME = exports.EVENT_SOURCE = exports.EVENT_REF = exports.DEFAULT = exports.CLIQ = exports.AUTH = exports.APIG_RULES = void 0;
3
7
  var apig_rules_1 = require("./lib/apig-rules");
4
- Object.defineProperty(exports, "APIG_RULES", { enumerable: true, get: function () { return apig_rules_1.default; } });
8
+ Object.defineProperty(exports, "APIG_RULES", { enumerable: true, get: function () { return __importDefault(apig_rules_1).default; } });
5
9
  var auth_1 = require("./lib/auth");
6
- Object.defineProperty(exports, "AUTH", { enumerable: true, get: function () { return auth_1.default; } });
10
+ Object.defineProperty(exports, "AUTH", { enumerable: true, get: function () { return __importDefault(auth_1).default; } });
7
11
  var cliq_handlers_1 = require("./lib/cliq-handlers");
8
- Object.defineProperty(exports, "CLIQ", { enumerable: true, get: function () { return cliq_handlers_1.default; } });
12
+ Object.defineProperty(exports, "CLIQ", { enumerable: true, get: function () { return __importDefault(cliq_handlers_1).default; } });
9
13
  var default_1 = require("./lib/default");
10
- Object.defineProperty(exports, "DEFAULT", { enumerable: true, get: function () { return default_1.default; } });
14
+ Object.defineProperty(exports, "DEFAULT", { enumerable: true, get: function () { return __importDefault(default_1).default; } });
11
15
  var event_action_1 = require("./lib/event-action");
12
- Object.defineProperty(exports, "EVENT_REF", { enumerable: true, get: function () { return event_action_1.default; } });
16
+ Object.defineProperty(exports, "EVENT_REF", { enumerable: true, get: function () { return __importDefault(event_action_1).default; } });
13
17
  var event_source_1 = require("./lib/event-source");
14
- Object.defineProperty(exports, "EVENT_SOURCE", { enumerable: true, get: function () { return event_source_1.default; } });
18
+ Object.defineProperty(exports, "EVENT_SOURCE", { enumerable: true, get: function () { return __importDefault(event_source_1).default; } });
15
19
  var file_names_1 = require("./lib/file-names");
16
- Object.defineProperty(exports, "FILENAME", { enumerable: true, get: function () { return file_names_1.default; } });
20
+ Object.defineProperty(exports, "FILENAME", { enumerable: true, get: function () { return __importDefault(file_names_1).default; } });
17
21
  var dc_type_1 = require("./lib/dc-type");
18
- Object.defineProperty(exports, "DC_TYPE", { enumerable: true, get: function () { return dc_type_1.default; } });
22
+ Object.defineProperty(exports, "DC_TYPE", { enumerable: true, get: function () { return __importDefault(dc_type_1).default; } });
19
23
  var fn_type_1 = require("./lib/fn-type");
20
- Object.defineProperty(exports, "FN_TYPE", { enumerable: true, get: function () { return fn_type_1.default; } });
24
+ Object.defineProperty(exports, "FN_TYPE", { enumerable: true, get: function () { return __importDefault(fn_type_1).default; } });
21
25
  var folder_names_1 = require("./lib/folder-names");
22
- Object.defineProperty(exports, "FOLDERNAME", { enumerable: true, get: function () { return folder_names_1.default; } });
26
+ Object.defineProperty(exports, "FOLDERNAME", { enumerable: true, get: function () { return __importDefault(folder_names_1).default; } });
23
27
  var integ_1 = require("./lib/integ");
24
- Object.defineProperty(exports, "INTEG", { enumerable: true, get: function () { return integ_1.default; } });
28
+ Object.defineProperty(exports, "INTEG", { enumerable: true, get: function () { return __importDefault(integ_1).default; } });
25
29
  var placeholders_1 = require("./lib/placeholders");
26
- Object.defineProperty(exports, "PLACEHOLDER", { enumerable: true, get: function () { return placeholders_1.default; } });
30
+ Object.defineProperty(exports, "PLACEHOLDER", { enumerable: true, get: function () { return __importDefault(placeholders_1).default; } });
27
31
  var ref_mapping_1 = require("./lib/ref-mapping");
28
- Object.defineProperty(exports, "REFERENCE", { enumerable: true, get: function () { return ref_mapping_1.default; } });
32
+ Object.defineProperty(exports, "REFERENCE", { enumerable: true, get: function () { return __importDefault(ref_mapping_1).default; } });
29
33
  var regex_1 = require("./lib/regex");
30
- Object.defineProperty(exports, "REGEX", { enumerable: true, get: function () { return regex_1.default; } });
34
+ Object.defineProperty(exports, "REGEX", { enumerable: true, get: function () { return __importDefault(regex_1).default; } });
31
35
  var remote_mapping_1 = require("./lib/remote-mapping");
32
- Object.defineProperty(exports, "REMOTE_REF", { enumerable: true, get: function () { return remote_mapping_1.default; } });
36
+ Object.defineProperty(exports, "REMOTE_REF", { enumerable: true, get: function () { return __importDefault(remote_mapping_1).default; } });
33
37
  var scopes_1 = require("./lib/scopes");
34
- Object.defineProperty(exports, "SCOPE", { enumerable: true, get: function () { return scopes_1.default; } });
35
- var stack_1 = require("./lib/stack");
36
- Object.defineProperty(exports, "STACK", { enumerable: true, get: function () { return stack_1.default; } });
38
+ Object.defineProperty(exports, "SCOPE", { enumerable: true, get: function () { return __importDefault(scopes_1).default; } });
37
39
  var template_1 = require("./lib/template");
38
- Object.defineProperty(exports, "TEMPLATE", { enumerable: true, get: function () { return template_1.default; } });
40
+ Object.defineProperty(exports, "TEMPLATE", { enumerable: true, get: function () { return __importDefault(template_1).default; } });
39
41
  var urls_1 = require("./lib/urls");
40
- Object.defineProperty(exports, "ORIGIN", { enumerable: true, get: function () { return urls_1.default; } });
42
+ Object.defineProperty(exports, "ORIGIN", { enumerable: true, get: function () { return __importDefault(urls_1).default; } });
@@ -1,5 +1,6 @@
1
1
  'use strict';
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ const functionName = /(?!^\d+$)^(\w|-)+$/g;
3
4
  exports.default = Object.freeze({
4
5
  project: {
5
6
  name: /^[a-zA-Z0-9][a-zA-Z0-9-]*$/g
@@ -9,9 +10,9 @@ exports.default = Object.freeze({
9
10
  },
10
11
  functions: {
11
12
  package: {
12
- name: /^(?:@[a-z0-9-~][a-z0-9-._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/g,
13
+ name: functionName,
13
14
  version: /(\d+)\.(\d+)\.(\d+)/g
14
15
  }
15
16
  },
16
- folder_name: /^((?![<>:"'\\/|?*]).)*$/g
17
+ folder_name: functionName
17
18
  });
@@ -0,0 +1,9 @@
1
+ 'use strict';
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const RUNTIME = Object.freeze({
4
+ language: {
5
+ nodejs: 'node',
6
+ java: 'java'
7
+ }
8
+ });
9
+ exports.default = RUNTIME;