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.
- package/README.md +31 -10
- package/docs/apig-utils.toml +69 -0
- package/docs/authentication/index.toml +15 -0
- package/docs/authentication/login.toml +14 -0
- package/docs/client-utils.toml +24 -0
- package/docs/command_needs/auth.toml +4 -0
- package/docs/command_needs/rc.toml +24 -0
- package/docs/commands/apig/disable.toml +4 -0
- package/docs/commands/apig/enable.toml +4 -0
- package/docs/commands/apig/status.toml +4 -0
- package/docs/commands/client/delete.toml +34 -0
- package/docs/commands/ds/export.toml +4 -0
- package/docs/commands/ds/import.toml +15 -0
- package/docs/commands/ds/status.toml +9 -0
- package/docs/commands/event/generate/index.toml +29 -0
- package/docs/commands/event/generate/integ.toml +4 -0
- package/docs/commands/functions/config.toml +11 -0
- package/docs/commands/functions/delete.toml +29 -0
- package/docs/commands/project/use.toml +9 -0
- package/docs/dc.toml +4 -0
- package/docs/deploy/features/apig.toml +4 -0
- package/docs/deploy/features/functions/index.toml +4 -0
- package/docs/event_generate/cache.toml +4 -0
- package/docs/event_generate/custom.toml +4 -0
- package/docs/event_generate/datastore.toml +4 -0
- package/docs/event_generate/filestore.toml +4 -0
- package/docs/event_generate/integration/cliq.toml +9 -0
- package/docs/execute-script.toml +19 -0
- package/docs/fn-utils/lib/common.toml +25 -0
- package/docs/fn-utils/lib/java.toml +34 -0
- package/docs/fn-utils/lib/node.toml +4 -0
- package/docs/init/index.toml +4 -0
- package/docs/internal/command.toml +4 -0
- package/docs/internal/config.toml +9 -0
- package/docs/internal/credential.toml +14 -0
- package/docs/option-filter.toml +45 -0
- package/docs/port-resolver.toml +9 -0
- package/docs/pull/index.toml +4 -0
- package/docs/serve/index.toml +4 -0
- package/docs/shell/index.toml +4 -0
- package/docs/util_modules/project.toml +9 -0
- package/lib/apig-utils.js +133 -43
- package/lib/archiver.js +4 -2
- package/lib/authentication/index.js +44 -9
- package/lib/authentication/login.js +51 -8
- package/lib/bin/catalyst.js +14 -7
- package/lib/client-utils.js +47 -14
- package/lib/client.js +1 -1
- package/lib/command_needs/auth.js +5 -3
- package/lib/command_needs/rc.js +35 -13
- package/lib/commands/apig/disable.js +8 -3
- package/lib/commands/apig/enable.js +8 -3
- package/lib/commands/apig/status.js +29 -9
- package/lib/commands/client/delete.js +65 -26
- package/lib/commands/client/setup.js +2 -2
- package/lib/commands/deploy.js +2 -2
- package/lib/commands/ds/export.js +16 -8
- package/lib/commands/ds/import.js +20 -14
- package/lib/commands/ds/status.js +22 -11
- package/lib/commands/event/generate/index.js +62 -12
- package/lib/commands/event/generate/integ.js +7 -3
- package/lib/commands/functions/add.js +2 -2
- package/lib/commands/functions/config.js +11 -3
- package/lib/commands/functions/delete.js +36 -13
- package/lib/commands/functions/setup.js +2 -2
- package/lib/commands/functions/shell.js +2 -2
- package/lib/commands/help.js +1 -1
- package/lib/commands/index.js +2 -3
- package/lib/commands/init.js +4 -4
- package/lib/commands/login.js +2 -2
- package/lib/commands/logout.js +2 -2
- package/lib/commands/project/list.js +2 -2
- package/lib/commands/project/reset.js +1 -1
- package/lib/commands/project/use.js +18 -2
- package/lib/commands/pull.js +5 -5
- package/lib/commands/run.js +2 -2
- package/lib/commands/serve.js +7 -6
- package/lib/commands/token/generate.js +2 -2
- package/lib/commands/token/list.js +2 -2
- package/lib/commands/token/revoke.js +2 -2
- package/lib/commands/whoami.js +1 -1
- package/lib/dc.js +11 -1
- package/lib/deploy/features/apig.js +33 -33
- package/lib/deploy/features/client.js +12 -19
- package/lib/deploy/features/functions/index.js +14 -4
- package/lib/deploy/features/index.js +1 -1
- package/lib/deploy/index.js +2 -9
- package/lib/endpoints/index.js +5 -2
- package/lib/endpoints/lib/apig.js +15 -5
- package/lib/endpoints/lib/applogic.js +12 -4
- package/lib/endpoints/lib/cache.js +9 -3
- package/lib/endpoints/lib/catalyst-details.js +37 -0
- package/lib/endpoints/lib/client.js +15 -5
- package/lib/endpoints/lib/datastore.js +6 -2
- package/lib/endpoints/lib/ds-bulk.js +15 -5
- package/lib/endpoints/lib/env.js +3 -1
- package/lib/endpoints/lib/event-bus.js +3 -1
- package/lib/endpoints/lib/filestore.js +6 -2
- package/lib/endpoints/lib/functions.js +12 -4
- package/lib/endpoints/lib/project.js +9 -3
- package/lib/endpoints/lib/queue.js +9 -3
- package/lib/endpoints/lib/sdk.js +3 -1
- package/lib/endpoints/lib/zcql.js +3 -1
- package/lib/error.js +18 -0
- package/lib/errorOut.js +10 -7
- package/lib/event_generate/cache.js +9 -1
- package/lib/event_generate/custom.js +6 -1
- package/lib/event_generate/datastore.js +12 -2
- package/lib/event_generate/filestore.js +9 -1
- package/lib/event_generate/integration/cliq.js +10 -2
- package/lib/execute-script.js +35 -6
- package/lib/express_middlewares/unknownReqProxy.js +18 -7
- package/lib/fn-utils/index.js +1 -1
- package/lib/fn-utils/lib/common.js +95 -17
- package/lib/fn-utils/lib/integ.js +4 -3
- package/lib/fn-utils/lib/java.js +49 -13
- package/lib/fn-utils/lib/node.js +15 -6
- package/lib/fn-watcher.js +67 -0
- package/lib/index.js +13 -12
- package/lib/init/dependencies/package-json.js +3 -1
- package/lib/init/features/functions/index.js +41 -29
- package/lib/init/features/functions/languages/java.js +5 -4
- package/lib/init/features/functions/languages/node.js +6 -5
- package/lib/init/features/index.js +8 -4
- package/lib/init/index.js +10 -3
- package/lib/internal/api.js +9 -9
- package/lib/internal/command.js +19 -14
- package/lib/internal/config.js +15 -15
- package/lib/internal/credential.js +33 -7
- package/lib/internal/rc.js +18 -10
- package/lib/migration/global/1.4.0.js +4 -2
- package/lib/migration/global/1.6.2.js +4 -2
- package/lib/migration/index.js +1 -1
- package/lib/option-filter.js +79 -22
- package/lib/optional-import.js +1 -1
- package/lib/plugin-loader.js +1 -1
- package/lib/port-resolver.js +23 -3
- package/lib/prompt.js +1 -1
- package/lib/pull/features/functions/index.js +7 -7
- package/lib/pull/features/index.js +1 -1
- package/lib/pull/index.js +10 -3
- package/lib/repl-server.js +9 -5
- package/lib/serve/features/index.js +11 -2
- package/lib/serve/index.js +19 -9
- package/lib/serve/server/index.js +137 -60
- package/lib/serve/server/lib/client.js +1 -1
- package/lib/serve/server/lib/master.js +16 -3
- package/lib/serve/server/lib/node.js +1 -1
- package/lib/shell/dependencies/http-functions.js +120 -90
- package/lib/shell/dependencies/invoker/integ/node.js +1 -1
- package/lib/shell/dependencies/local-function.js +86 -119
- package/lib/shell/index.js +10 -10
- package/lib/shell/prepare/index.js +1 -4
- package/lib/shell/prepare/languages/index.js +15 -4
- package/lib/track.js +4 -1
- package/lib/util_modules/config/index.js +1 -1
- package/lib/util_modules/config/lib/apig.js +3 -3
- package/lib/util_modules/config/lib/client.js +3 -3
- package/lib/util_modules/config/lib/functions.js +5 -5
- package/lib/util_modules/constants/index.js +22 -20
- package/lib/util_modules/constants/lib/regex.js +3 -2
- package/lib/util_modules/constants/lib/runtime.js +9 -0
- package/lib/util_modules/contextHelp.js +63 -123
- package/lib/util_modules/fs/index.js +1 -1
- package/lib/util_modules/fs/lib/async.js +19 -2
- package/lib/util_modules/fs/lib/sync.js +13 -1
- package/lib/util_modules/logger.js +12 -20
- package/lib/util_modules/option.js +1 -13
- package/lib/util_modules/project.js +75 -26
- package/lib/util_modules/shell.js +8 -2
- package/package.json +45 -45
- package/scripts/postInstall.js +31 -0
- package/lib/cjson.js +0 -20
- package/lib/log-error.js +0 -18
- package/lib/util_modules/big-json.js +0 -16
- package/lib/util_modules/constants/lib/stack.js +0 -6
- package/templates/init/functions/.DS_Store +0 -0
- package/templates/init/functions/node/.DS_Store +0 -0
- package/templates/init/functions/node/integ/.DS_Store +0 -0
|
@@ -8,6 +8,17 @@ 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 __rest = (this && this.__rest) || function (s, e) {
|
|
12
|
+
var t = {};
|
|
13
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
14
|
+
t[p] = s[p];
|
|
15
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
16
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
17
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
18
|
+
t[p[i]] = s[p[i]];
|
|
19
|
+
}
|
|
20
|
+
return t;
|
|
21
|
+
};
|
|
11
22
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
23
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
24
|
};
|
|
@@ -18,6 +29,7 @@ const fn_utils_1 = require("../../fn-utils");
|
|
|
18
29
|
const plugin_loader_1 = __importDefault(require("../../plugin-loader"));
|
|
19
30
|
const runtime_store_1 = __importDefault(require("../../runtime-store"));
|
|
20
31
|
const constants_1 = require("../../util_modules/constants");
|
|
32
|
+
const runtime_1 = __importDefault(require("../../util_modules/constants/lib/runtime"));
|
|
21
33
|
const fs_1 = require("../../util_modules/fs");
|
|
22
34
|
const js_1 = require("../../util_modules/js");
|
|
23
35
|
const logger_1 = require("../../util_modules/logger");
|
|
@@ -27,26 +39,26 @@ class Server {
|
|
|
27
39
|
constructor() {
|
|
28
40
|
this.targetDetailsArr = [];
|
|
29
41
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
42
|
+
_addBasicFnDetails() {
|
|
43
|
+
const fnTargets = runtime_store_1.default.get('context.functions.targets', []);
|
|
44
|
+
if (fnTargets.length === 0) {
|
|
45
|
+
logger_1.debug('No basic functions to add');
|
|
46
|
+
}
|
|
47
|
+
const httpPort = parseInt(runtime_store_1.default.get('context.port.http.' + constants_1.REMOTE_REF.functions.type[constants_1.FN_TYPE.basic]), 10);
|
|
48
|
+
const debugPort = parseInt(runtime_store_1.default.get('context.port.debug.' + constants_1.REMOTE_REF.functions.type[constants_1.FN_TYPE.basic], '-1'), 10);
|
|
49
|
+
if (!isNaN(httpPort)) {
|
|
50
|
+
fnTargets
|
|
51
|
+
.filter((t) => t.url !== undefined && t.type === constants_1.FN_TYPE.basic)
|
|
52
|
+
.map((t) => js_1.JS.omit(t, ['zip_stream', 'localFn']))
|
|
53
|
+
.forEach((t) => {
|
|
54
|
+
this.targetDetailsArr.push({
|
|
55
|
+
type: 'functions',
|
|
56
|
+
httpPort,
|
|
57
|
+
debugPort,
|
|
58
|
+
target: t
|
|
46
59
|
});
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
});
|
|
60
|
+
});
|
|
61
|
+
}
|
|
50
62
|
}
|
|
51
63
|
_spinUpJavaServer(details, masterPort) {
|
|
52
64
|
var _a, _b, _c, _d;
|
|
@@ -97,10 +109,11 @@ class Server {
|
|
|
97
109
|
var _a, _b, _c;
|
|
98
110
|
return __awaiter(this, void 0, void 0, function* () {
|
|
99
111
|
const label = `${details.type}[${(_a = details.target) === null || _a === void 0 ? void 0 : _a.name}]`;
|
|
112
|
+
const _d = details.target, { ['watcher']: _ } = _d, serialisableTarget = __rest(_d, ['watcher']);
|
|
100
113
|
const opts = [
|
|
101
114
|
path_1.join(__dirname, 'lib', details.type === 'client' ? 'client.js' : 'node.js'),
|
|
102
115
|
details.httpPort + '',
|
|
103
|
-
JSON.stringify(
|
|
116
|
+
JSON.stringify(serialisableTarget)
|
|
104
117
|
];
|
|
105
118
|
if (details.debugPort !== -1) {
|
|
106
119
|
logger_1.labeled(label, 'you can attach your debugger at port : ' + details.debugPort).MESSAGE();
|
|
@@ -141,43 +154,49 @@ class Server {
|
|
|
141
154
|
debugPort
|
|
142
155
|
});
|
|
143
156
|
}
|
|
157
|
+
startServer(details, masterPort) {
|
|
158
|
+
var _a;
|
|
159
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
160
|
+
if (details.target === undefined) {
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
let currentProcess;
|
|
164
|
+
if ((_a = details.target.stack) === null || _a === void 0 ? void 0 : _a.startsWith(runtime_1.default.language.java)) {
|
|
165
|
+
currentProcess = yield this._spinUpJavaServer(details, masterPort);
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
currentProcess = yield this._spinUpProcess(details, masterPort);
|
|
169
|
+
}
|
|
170
|
+
details.process = currentProcess;
|
|
171
|
+
const stdout = currentProcess.stdout;
|
|
172
|
+
if (stdout && typeof stdout.pipe === 'function') {
|
|
173
|
+
stdout.pipe(process.stdout);
|
|
174
|
+
}
|
|
175
|
+
const stderr = currentProcess.stderr;
|
|
176
|
+
if (stderr && typeof stderr.pipe === 'function') {
|
|
177
|
+
stderr.pipe(process.stderr);
|
|
178
|
+
}
|
|
179
|
+
return new Promise((res) => setTimeout(res, 100));
|
|
180
|
+
});
|
|
181
|
+
}
|
|
144
182
|
start() {
|
|
145
183
|
return __awaiter(this, void 0, void 0, function* () {
|
|
146
184
|
const masterPort = runtime_store_1.default.get(`context.port.http.master`, -1);
|
|
147
185
|
if (masterPort === -1) {
|
|
148
186
|
throw new error_1.default('master port cannot be undefined', { exit: 2 });
|
|
149
187
|
}
|
|
150
|
-
yield Promise.all(this.targetDetailsArr.map((details) => __awaiter(this, void 0, void 0, function* () {
|
|
151
|
-
|
|
152
|
-
return;
|
|
153
|
-
}
|
|
154
|
-
let currentProcess;
|
|
155
|
-
switch (details.target.stack) {
|
|
156
|
-
case constants_1.STACK.java8:
|
|
157
|
-
currentProcess = yield this._spinUpJavaServer(details, masterPort);
|
|
158
|
-
break;
|
|
159
|
-
default:
|
|
160
|
-
currentProcess = yield this._spinUpProcess(details, masterPort);
|
|
161
|
-
break;
|
|
162
|
-
}
|
|
163
|
-
Server.process = [...Server.process, currentProcess];
|
|
164
|
-
const stdout = currentProcess.stdout;
|
|
165
|
-
if (stdout && typeof stdout.pipe === 'function') {
|
|
166
|
-
stdout.pipe(process.stdout);
|
|
167
|
-
}
|
|
168
|
-
const stderr = currentProcess.stderr;
|
|
169
|
-
if (stderr && typeof stderr.pipe === 'function') {
|
|
170
|
-
stderr.pipe(process.stderr);
|
|
171
|
-
}
|
|
172
|
-
})));
|
|
173
|
-
const masterServer = yield this._spinUpMaster(masterPort);
|
|
188
|
+
yield Promise.all(this.targetDetailsArr.map((details) => __awaiter(this, void 0, void 0, function* () { return this.startServer(details, masterPort); })));
|
|
189
|
+
this._addBasicFnDetails();
|
|
174
190
|
if (this.targetDetailsArr.length === 0) {
|
|
175
|
-
throw new error_1.default('master server
|
|
191
|
+
throw new error_1.default('Trying to start master server before other server', {
|
|
192
|
+
exit: 2
|
|
193
|
+
});
|
|
176
194
|
}
|
|
177
|
-
|
|
195
|
+
const server = yield master_1.default(masterPort, this.targetDetailsArr);
|
|
196
|
+
this.masterServer = server;
|
|
178
197
|
return new Promise((res) => {
|
|
179
|
-
|
|
180
|
-
|
|
198
|
+
server.on('listening', () => {
|
|
199
|
+
this.targetDetailsArr.forEach((targetDetails) => { var _a; return (_a = targetDetails.process) === null || _a === void 0 ? void 0 : _a.emit('start'); });
|
|
181
200
|
res();
|
|
182
201
|
});
|
|
183
202
|
});
|
|
@@ -185,30 +204,88 @@ class Server {
|
|
|
185
204
|
}
|
|
186
205
|
wait() {
|
|
187
206
|
return __awaiter(this, void 0, void 0, function* () {
|
|
188
|
-
if (
|
|
189
|
-
logger_1.debug('
|
|
207
|
+
if (!this.masterServer) {
|
|
208
|
+
logger_1.debug('Master server is not started yet.');
|
|
190
209
|
throw new error_1.default('Server cannot be put to wait state.', { exit: 2 });
|
|
191
210
|
}
|
|
211
|
+
this.targetDetailsArr.forEach((targetdetails) => {
|
|
212
|
+
var _a, _b;
|
|
213
|
+
const target = targetdetails.target;
|
|
214
|
+
if (targetdetails.type === 'functions' || !target || !targetdetails.process) {
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
(_a = target.watcher) === null || _a === void 0 ? void 0 : _a.on('preparing', () => __awaiter(this, void 0, void 0, function* () {
|
|
218
|
+
yield this.kill(targetdetails.process);
|
|
219
|
+
}));
|
|
220
|
+
(_b = target.watcher) === null || _b === void 0 ? void 0 : _b.on('compiled', () => __awaiter(this, void 0, void 0, function* () {
|
|
221
|
+
yield this.restart(target);
|
|
222
|
+
logger_1.labeled(`server[${target.name}]`, 'ready!').MESSAGE();
|
|
223
|
+
setTimeout(() => {
|
|
224
|
+
var _a;
|
|
225
|
+
(_a = target.watcher) === null || _a === void 0 ? void 0 : _a.emit('next');
|
|
226
|
+
}, 1000);
|
|
227
|
+
}));
|
|
228
|
+
}, this);
|
|
192
229
|
return new Promise((res) => {
|
|
193
230
|
['SIGINT', 'SIGTERM'].forEach((sig) => process.on(sig, res));
|
|
194
231
|
});
|
|
195
232
|
});
|
|
196
233
|
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
234
|
+
kill(serverProcess) {
|
|
235
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
236
|
+
return new Promise((resolve) => {
|
|
237
|
+
if (serverProcess.pid === undefined) {
|
|
238
|
+
try {
|
|
239
|
+
serverProcess.close(() => resolve());
|
|
240
|
+
}
|
|
241
|
+
catch (e) {
|
|
242
|
+
serverProcess.emit('close');
|
|
243
|
+
}
|
|
202
244
|
}
|
|
203
|
-
|
|
204
|
-
serverProcess.
|
|
245
|
+
if (serverProcess.exitCode === null) {
|
|
246
|
+
serverProcess.kill('SIGINT');
|
|
205
247
|
}
|
|
248
|
+
resolve();
|
|
249
|
+
});
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
restart(target) {
|
|
253
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
254
|
+
const targetIdx = this.targetDetailsArr.findIndex((targetDetails) => { var _a; return target.source === ((_a = targetDetails.target) === null || _a === void 0 ? void 0 : _a.source); });
|
|
255
|
+
if (targetIdx === -1) {
|
|
256
|
+
throw new error_1.default('Unknown target given for restart.', { exit: 2 });
|
|
206
257
|
}
|
|
207
|
-
|
|
208
|
-
|
|
258
|
+
if (this.targetDetailsArr[targetIdx].type === 'functions') {
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
const targetProcess = this.targetDetailsArr[targetIdx].process;
|
|
262
|
+
if (!targetProcess) {
|
|
263
|
+
throw new error_1.default('Process is not defined for this target.', { exit: 2 });
|
|
264
|
+
}
|
|
265
|
+
yield this.kill(targetProcess);
|
|
266
|
+
yield this.startServer(this.targetDetailsArr[targetIdx], runtime_store_1.default.get(`context.port.http.master`, -1));
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
stop() {
|
|
270
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
271
|
+
yield Promise.all(this.targetDetailsArr.map((targetdetails) => __awaiter(this, void 0, void 0, function* () {
|
|
272
|
+
var _a;
|
|
273
|
+
const target = targetdetails.target;
|
|
274
|
+
if (!target) {
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
yield ((_a = target.watcher) === null || _a === void 0 ? void 0 : _a.close());
|
|
278
|
+
if (targetdetails.process) {
|
|
279
|
+
return this.kill(targetdetails.process);
|
|
280
|
+
}
|
|
281
|
+
})));
|
|
282
|
+
if (this.masterServer) {
|
|
283
|
+
const masterServer = this.masterServer;
|
|
284
|
+
return new Promise((res, rej) => {
|
|
285
|
+
masterServer.close((err) => (err ? rej(err) : res()));
|
|
286
|
+
});
|
|
209
287
|
}
|
|
210
288
|
});
|
|
211
289
|
}
|
|
212
290
|
}
|
|
213
|
-
Server.process = [];
|
|
214
291
|
exports.default = Server;
|
|
@@ -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
|
};
|
|
@@ -29,6 +29,7 @@ const constants_1 = require("../../../util_modules/constants");
|
|
|
29
29
|
const js_1 = require("../../../util_modules/js");
|
|
30
30
|
const logger_2 = require("../../../util_modules/logger");
|
|
31
31
|
const project_2 = require("../../../util_modules/project");
|
|
32
|
+
const option_1 = require("../../../util_modules/option");
|
|
32
33
|
const removeSecure = (str) => str.replace(/;\s?Secure/i, '').replace(/;\s?SameSite=None/i, '');
|
|
33
34
|
const redirectByAuth = (req, res, redirectUrl) => {
|
|
34
35
|
if (req.headers['x-zc-user-cred-token'] === undefined) {
|
|
@@ -90,9 +91,10 @@ function spinUpMaster(listenPort, otherServerDetails) {
|
|
|
90
91
|
key: project_2.getDomainKey(),
|
|
91
92
|
env_name: project_2.getEnvName()
|
|
92
93
|
};
|
|
93
|
-
const bindPort = parseInt(runtime_store_1.default.get('context.port.bind', '-1'), 10);
|
|
94
94
|
const rules = runtime_store_1.default.get('context.apig.local.config', -1);
|
|
95
|
+
const customProxyUrl = option_1.getOptionValue('proxy');
|
|
95
96
|
const app = express_1.default();
|
|
97
|
+
const connections = {};
|
|
96
98
|
let systemRoutes;
|
|
97
99
|
app.use(logger_1.default);
|
|
98
100
|
app.use(cookie_parser_1.default);
|
|
@@ -132,7 +134,8 @@ function spinUpMaster(listenPort, otherServerDetails) {
|
|
|
132
134
|
const appTarget = `http://127.0.0.1:${serverDetail.httpPort}/app/`;
|
|
133
135
|
app.use('/app', (req, res) => {
|
|
134
136
|
var _a;
|
|
135
|
-
if (req.url.startsWith('/local-redirect') &&
|
|
137
|
+
if (req.url.startsWith('/local-redirect') &&
|
|
138
|
+
((_a = serverDetail.target) === null || _a === void 0 ? void 0 : _a.login_redirect)) {
|
|
136
139
|
const isUrl = serverDetail.target.login_redirect.startsWith('/');
|
|
137
140
|
if (isUrl) {
|
|
138
141
|
res.redirect(serverDetail.target.login_redirect);
|
|
@@ -204,7 +207,7 @@ function spinUpMaster(listenPort, otherServerDetails) {
|
|
|
204
207
|
});
|
|
205
208
|
}
|
|
206
209
|
});
|
|
207
|
-
app.use('/', unknownReqProxy_1.default(proxy,
|
|
210
|
+
app.use('/', unknownReqProxy_1.default(proxy, customProxyUrl));
|
|
208
211
|
app.use(error_handler_1.default);
|
|
209
212
|
const expressServer = app.listen(listenPort).on('error', (err) => {
|
|
210
213
|
if (proxy) {
|
|
@@ -212,6 +215,16 @@ function spinUpMaster(listenPort, otherServerDetails) {
|
|
|
212
215
|
}
|
|
213
216
|
console.error(err);
|
|
214
217
|
});
|
|
218
|
+
expressServer.maxConnections = 100;
|
|
219
|
+
process.once('SIGINT', () => Object.keys(connections).forEach((sokcetId) => { var _a; return (_a = connections[sokcetId]) === null || _a === void 0 ? void 0 : _a.destroy(); }));
|
|
220
|
+
expressServer.on('connection', (socket) => {
|
|
221
|
+
const offset = Math.floor(Math.random() * 10);
|
|
222
|
+
const id = Date.now() + offset + '';
|
|
223
|
+
connections[id] = socket;
|
|
224
|
+
socket.on('close', () => {
|
|
225
|
+
delete connections[id];
|
|
226
|
+
});
|
|
227
|
+
});
|
|
215
228
|
expressServer.on('close', () => {
|
|
216
229
|
logger_2.info('Shutting down server');
|
|
217
230
|
proxy.close();
|
|
@@ -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
|
};
|
|
@@ -24,11 +24,15 @@ const project_1 = __importDefault(require("../../express_middlewares/project"));
|
|
|
24
24
|
const fn_utils_1 = require("../../fn-utils");
|
|
25
25
|
const runtime_store_1 = __importDefault(require("../../runtime-store"));
|
|
26
26
|
const constants_1 = require("../../util_modules/constants");
|
|
27
|
+
const runtime_1 = __importDefault(require("../../util_modules/constants/lib/runtime"));
|
|
27
28
|
const fs_1 = require("../../util_modules/fs");
|
|
28
29
|
const js_1 = require("../../util_modules/js");
|
|
29
30
|
const logger_2 = require("../../util_modules/logger");
|
|
30
31
|
const project_2 = require("../../util_modules/project");
|
|
31
32
|
const shell_1 = require("../../util_modules/shell");
|
|
33
|
+
const logUrl = (name, pthName, httpPort, masterPort) => {
|
|
34
|
+
logger_2.labeled(`functions(${name})`, 'URL => http://localhost:' + (masterPort === -1 ? httpPort : masterPort) + pthName).MESSAGE();
|
|
35
|
+
};
|
|
32
36
|
class HttpFunctions {
|
|
33
37
|
constructor(repl) {
|
|
34
38
|
this.repl = repl;
|
|
@@ -43,6 +47,7 @@ class HttpFunctions {
|
|
|
43
47
|
this.responseFile = path_1.join(runtime_store_1.default.get('cwd'), '.build', '.catalyst', 'user_res_body');
|
|
44
48
|
this.metaFile = path_1.join(runtime_store_1.default.get('cwd'), '.build', '.catalyst', 'user_meta.json');
|
|
45
49
|
this.runningSlaves = [];
|
|
50
|
+
this.targets = [];
|
|
46
51
|
this.q = new better_queue_1.default((opts, cb) => {
|
|
47
52
|
var _a, _b;
|
|
48
53
|
fs_1.SYNC.ensureFile(this.responseFile, true);
|
|
@@ -66,7 +71,7 @@ class HttpFunctions {
|
|
|
66
71
|
}
|
|
67
72
|
}).RAW();
|
|
68
73
|
(_a = slave.stdout) === null || _a === void 0 ? void 0 : _a.on('data', (data) => {
|
|
69
|
-
logger_2.info(data);
|
|
74
|
+
logger_2.info(Buffer.isBuffer(data) ? data.toString() : data);
|
|
70
75
|
});
|
|
71
76
|
(_b = slave.stderr) === null || _b === void 0 ? void 0 : _b.on('data', (data) => {
|
|
72
77
|
const errorStr = data.toString().trim();
|
|
@@ -105,6 +110,12 @@ class HttpFunctions {
|
|
|
105
110
|
return __awaiter(this, void 0, void 0, function* () {
|
|
106
111
|
const debugPort = parseInt(runtime_store_1.default.get('context.port.debug.' + constants_1.REMOTE_REF.functions.type[constants_1.FN_TYPE.basic], '-1'), 10);
|
|
107
112
|
const httpPort = parseInt(runtime_store_1.default.get('context.port.http.' + constants_1.REMOTE_REF.functions.type[constants_1.FN_TYPE.basic]), 10);
|
|
113
|
+
if (this.repl !== undefined) {
|
|
114
|
+
this.app.use((_req, _res, next) => {
|
|
115
|
+
shell_1.clearLine(process.stdout);
|
|
116
|
+
next();
|
|
117
|
+
});
|
|
118
|
+
}
|
|
108
119
|
this.app.use(logger_1.default);
|
|
109
120
|
this.app.use(cookie_parser_1.default);
|
|
110
121
|
this.app.use(authenticator_1.default);
|
|
@@ -116,83 +127,86 @@ class HttpFunctions {
|
|
|
116
127
|
env_name: project_2.getEnvName()
|
|
117
128
|
}));
|
|
118
129
|
const reqHandler = (fnTarget) => (request, response, next) => {
|
|
130
|
+
var _a, _b;
|
|
119
131
|
const urlParts = new url_1.URL(request.originalUrl, request.protocol + '://' + request.get('host')).searchParams;
|
|
120
132
|
const query = JSON.stringify(Object.fromEntries(urlParts.entries()));
|
|
121
133
|
const slaveOptions = [];
|
|
122
134
|
let slave = null;
|
|
123
135
|
if (fnTarget.type === undefined) {
|
|
124
|
-
throw new error_1.default('Function target type is not defined', {
|
|
136
|
+
throw new error_1.default('Function target type is not defined', {
|
|
137
|
+
exit: 2
|
|
138
|
+
});
|
|
125
139
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
});
|
|
192
|
-
break;
|
|
140
|
+
if ((_a = fnTarget.stack) === null || _a === void 0 ? void 0 : _a.startsWith(runtime_1.default.language.nodejs)) {
|
|
141
|
+
if (debugPort !== -1) {
|
|
142
|
+
slaveOptions.push('--inspect-brk=' + debugPort);
|
|
143
|
+
}
|
|
144
|
+
slaveOptions.push(this.nodeInvoker[fnTarget.type]);
|
|
145
|
+
slaveOptions.push(JSON.stringify(fnTarget));
|
|
146
|
+
slaveOptions.push(query);
|
|
147
|
+
slaveOptions.push(JSON.stringify({
|
|
148
|
+
'x-zc-projectid': request.headers['x-zc-projectid'],
|
|
149
|
+
'x-zc-project-domain': request.headers['x-zc-project-domain'],
|
|
150
|
+
'x-zc-project-key': request.headers['x-zc-project-key'],
|
|
151
|
+
'x-zc-environment': request.headers['x-zc-environment']
|
|
152
|
+
}));
|
|
153
|
+
slaveOptions.push(JSON.stringify({
|
|
154
|
+
'x-zc-user-cred-type': request.headers['x-zc-user-cred-type'],
|
|
155
|
+
'x-zc-user-cred-token': request.headers['x-zc-user-cred-token'],
|
|
156
|
+
'x-zc-admin-cred-type': request.headers['x-zc-admin-cred-type'],
|
|
157
|
+
'x-zc-admin-cred-token': request.headers['x-zc-admin-cred-token'],
|
|
158
|
+
'x-zc-cookie': request.headers['x-zc-cookie']
|
|
159
|
+
}));
|
|
160
|
+
slaveOptions.push(JSON.stringify(path_1.join(runtime_store_1.default.get('cwd'), '.build')));
|
|
161
|
+
slave = this.q.push({
|
|
162
|
+
command: 'node',
|
|
163
|
+
options: slaveOptions,
|
|
164
|
+
pth: fnTarget.source,
|
|
165
|
+
req: request,
|
|
166
|
+
id: fnTarget.name
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
else if ((_b = fnTarget.stack) === null || _b === void 0 ? void 0 : _b.startsWith(runtime_1.default.language.java)) {
|
|
170
|
+
const javaInvokerDir = path_1.parse(this.javaInvoker[fnTarget.type]).dir;
|
|
171
|
+
slaveOptions.push('-cp');
|
|
172
|
+
slaveOptions.push(javaInvokerDir +
|
|
173
|
+
fn_utils_1.fnUtils.java.classPathSep +
|
|
174
|
+
path_1.join(javaInvokerDir, 'lib', '*'));
|
|
175
|
+
if (debugPort !== -1) {
|
|
176
|
+
slaveOptions.push('-Xdebug');
|
|
177
|
+
slaveOptions.push('-Xrunjdwp:transport=dt_socket,address=' +
|
|
178
|
+
debugPort +
|
|
179
|
+
',server=y,suspend=y');
|
|
180
|
+
}
|
|
181
|
+
slaveOptions.push(path_1.basename(this.javaInvoker[fnTarget.type]));
|
|
182
|
+
slaveOptions.push(javaInvokerDir);
|
|
183
|
+
slaveOptions.push(JSON.stringify(fnTarget));
|
|
184
|
+
slaveOptions.push(query);
|
|
185
|
+
slaveOptions.push(JSON.stringify({
|
|
186
|
+
'x-zc-projectid': request.headers['x-zc-projectid'],
|
|
187
|
+
'x-zc-project-domain': request.headers['x-zc-project-domain'],
|
|
188
|
+
'x-zc-project-key': request.headers['x-zc-project-key'],
|
|
189
|
+
'x-zc-environment': request.headers['x-zc-environment']
|
|
190
|
+
}));
|
|
191
|
+
slaveOptions.push(JSON.stringify({
|
|
192
|
+
'x-zc-user-cred-type': request.headers['x-zc-user-cred-type'],
|
|
193
|
+
'x-zc-user-cred-token': request.headers['x-zc-user-cred-token'],
|
|
194
|
+
'x-zc-admin-cred-type': request.headers['x-zc-admin-cred-type'],
|
|
195
|
+
'x-zc-admin-cred-token': request.headers['x-zc-admin-cred-token'],
|
|
196
|
+
'x-zc-cookie': request.headers['x-zc-cookie']
|
|
197
|
+
}));
|
|
198
|
+
slave = this.q.push({
|
|
199
|
+
command: 'java',
|
|
200
|
+
options: slaveOptions,
|
|
201
|
+
pth: fnTarget.source,
|
|
202
|
+
req: request,
|
|
203
|
+
id: fnTarget.name
|
|
204
|
+
});
|
|
193
205
|
}
|
|
194
206
|
if (slave === null) {
|
|
195
|
-
throw new error_1.default('Slave is null event after pushing opts', {
|
|
207
|
+
throw new error_1.default('Slave is null event after pushing opts', {
|
|
208
|
+
exit: 2
|
|
209
|
+
});
|
|
196
210
|
}
|
|
197
211
|
slave
|
|
198
212
|
.on('finish', (result) => {
|
|
@@ -224,17 +238,19 @@ class HttpFunctions {
|
|
|
224
238
|
const fnTargets = runtime_store_1.default.get('context.functions.targets');
|
|
225
239
|
fnTargets
|
|
226
240
|
.filter((t) => t.url !== undefined && t.type === constants_1.FN_TYPE.basic)
|
|
227
|
-
.map((t) =>
|
|
241
|
+
.map((t) => {
|
|
242
|
+
this.targets.push(t);
|
|
243
|
+
return js_1.JS.omit(t, ['zip_stream', 'watcher', 'localFn']);
|
|
244
|
+
})
|
|
228
245
|
.forEach((t) => {
|
|
229
|
-
|
|
246
|
+
var _a;
|
|
247
|
+
if ((_a = t.stack) === null || _a === void 0 ? void 0 : _a.startsWith(runtime_1.default.language.java)) {
|
|
230
248
|
fn_utils_1.fnUtils.java.ensureJavaInvoker(this.javaInvoker[t.type], path_1.normalize(path_1.join(__dirname, './invoker', t.type, 'java', 'Java' + t.type + 'Invoker.java')));
|
|
231
249
|
}
|
|
232
250
|
const pthName = new url_1.URL(t.url).pathname;
|
|
233
251
|
if (pthName !== null) {
|
|
234
252
|
this.app.use(pthName, reqHandler(t));
|
|
235
|
-
|
|
236
|
-
(masterPort === -1 ? httpPort : masterPort) +
|
|
237
|
-
pthName).MESSAGE();
|
|
253
|
+
logUrl(t.name, pthName, httpPort, masterPort);
|
|
238
254
|
}
|
|
239
255
|
if (t.url_with_id !== undefined) {
|
|
240
256
|
const pathWithId = new url_1.URL(t.url_with_id).pathname;
|
|
@@ -245,6 +261,26 @@ class HttpFunctions {
|
|
|
245
261
|
});
|
|
246
262
|
return new Promise((res) => {
|
|
247
263
|
const server = this.app.listen(httpPort, () => {
|
|
264
|
+
this.targets.forEach((target) => {
|
|
265
|
+
var _a, _b;
|
|
266
|
+
(_a = target.watcher) === null || _a === void 0 ? void 0 : _a.on('preparing', () => {
|
|
267
|
+
if (this.repl && !this.repl.paused) {
|
|
268
|
+
this.repl.pause();
|
|
269
|
+
}
|
|
270
|
+
});
|
|
271
|
+
(_b = target.watcher) === null || _b === void 0 ? void 0 : _b.on('compiled', () => {
|
|
272
|
+
logger_2.labeled(`functions(${target.name})`, 'ready!').MESSAGE();
|
|
273
|
+
logUrl(target.name, new url_1.URL(target.url).pathname, httpPort, masterPort);
|
|
274
|
+
if (this.repl && this.repl.paused) {
|
|
275
|
+
this.repl.resume();
|
|
276
|
+
this.repl.showPrompt();
|
|
277
|
+
}
|
|
278
|
+
setTimeout(() => {
|
|
279
|
+
var _a;
|
|
280
|
+
(_a = target.watcher) === null || _a === void 0 ? void 0 : _a.emit('next');
|
|
281
|
+
}, 1000);
|
|
282
|
+
});
|
|
283
|
+
});
|
|
248
284
|
if (this.repl !== undefined) {
|
|
249
285
|
this.repl.showPrompt();
|
|
250
286
|
}
|
|
@@ -266,28 +302,22 @@ class HttpFunctions {
|
|
|
266
302
|
}
|
|
267
303
|
stop() {
|
|
268
304
|
return __awaiter(this, void 0, void 0, function* () {
|
|
269
|
-
return new Promise((
|
|
305
|
+
return new Promise((res) => {
|
|
270
306
|
this.runningSlaves.forEach((slave) => {
|
|
271
307
|
slave.kill('SIGINT');
|
|
272
308
|
});
|
|
273
|
-
this.q.destroy(() => {
|
|
309
|
+
this.q.destroy(() => __awaiter(this, void 0, void 0, function* () {
|
|
310
|
+
yield Promise.all(this.targets.map((target) => __awaiter(this, void 0, void 0, function* () { var _a; return (_a = target.watcher) === null || _a === void 0 ? void 0 : _a.close(); })));
|
|
274
311
|
if (HttpFunctions.server !== null) {
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
catch (e) {
|
|
280
|
-
HttpFunctions.server.emit('close');
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
else {
|
|
284
|
-
HttpFunctions.server.kill('SIGINT');
|
|
285
|
-
}
|
|
312
|
+
HttpFunctions.server.close((err) => {
|
|
313
|
+
logger_2.debug(err);
|
|
314
|
+
res();
|
|
315
|
+
});
|
|
286
316
|
}
|
|
287
317
|
else {
|
|
288
|
-
|
|
318
|
+
res();
|
|
289
319
|
}
|
|
290
|
-
});
|
|
320
|
+
}));
|
|
291
321
|
});
|
|
292
322
|
});
|
|
293
323
|
}
|
|
@@ -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
|
};
|