serverless-offline 8.2.0 → 8.5.0
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 +157 -116
- package/dist/ServerlessOffline.js +98 -26
- package/dist/config/commandOptions.js +4 -0
- package/dist/config/constants.js +1 -1
- package/dist/config/defaultOptions.js +1 -0
- package/dist/events/http/Endpoint.js +27 -9
- package/dist/events/http/Http.js +3 -3
- package/dist/events/http/HttpServer.js +355 -82
- package/dist/events/http/authFunctionNameExtractor.js +14 -8
- package/dist/events/http/authJWTSettingsExtractor.js +14 -7
- package/dist/events/http/createAuthScheme.js +44 -9
- package/dist/events/http/createJWTAuthScheme.js +52 -13
- package/dist/events/http/lambda-events/LambdaIntegrationEvent.js +7 -6
- package/dist/events/http/lambda-events/LambdaProxyIntegrationEvent.js +38 -7
- package/dist/events/http/lambda-events/LambdaProxyIntegrationEventV2.js +37 -6
- package/dist/events/http/lambda-events/VelocityContext.js +4 -4
- package/dist/events/http/lambda-events/index.js +4 -4
- package/dist/events/http/lambda-events/renderVelocityTemplateObject.js +19 -7
- package/dist/events/schedule/Schedule.js +45 -10
- package/dist/events/websocket/HttpServer.js +24 -7
- package/dist/events/websocket/WebSocket.js +14 -6
- package/dist/events/websocket/WebSocketClients.js +127 -38
- package/dist/events/websocket/WebSocketServer.js +79 -11
- package/dist/events/websocket/http-routes/_catchAll/catchAllRoute.js +9 -2
- package/dist/events/websocket/http-routes/connections/ConnectionsController.js +1 -1
- package/dist/events/websocket/http-routes/connections/connectionsRoutes.js +28 -5
- package/dist/events/websocket/lambda-events/WebSocketConnectEvent.js +5 -5
- package/dist/events/websocket/lambda-events/WebSocketDisconnectEvent.js +1 -1
- package/dist/events/websocket/lambda-events/WebSocketEvent.js +3 -3
- package/dist/events/websocket/lambda-events/WebSocketRequestContext.js +4 -4
- package/dist/lambda/HttpServer.js +34 -10
- package/dist/lambda/Lambda.js +15 -7
- package/dist/lambda/LambdaContext.js +1 -1
- package/dist/lambda/LambdaFunction.js +40 -23
- package/dist/lambda/LambdaFunctionPool.js +9 -8
- package/dist/lambda/handler-runner/HandlerRunner.js +51 -16
- package/dist/lambda/handler-runner/child-process-runner/ChildProcessRunner.js +21 -8
- package/dist/lambda/handler-runner/child-process-runner/childProcessHelper.js +1 -10
- package/dist/lambda/handler-runner/docker-runner/DockerContainer.js +168 -69
- package/dist/lambda/handler-runner/docker-runner/DockerImage.js +21 -5
- package/dist/lambda/handler-runner/docker-runner/DockerRunner.js +4 -4
- package/dist/lambda/handler-runner/go-runner/GoRunner.js +211 -0
- package/dist/lambda/handler-runner/go-runner/index.js +15 -0
- package/dist/lambda/handler-runner/in-process-runner/InProcessRunner.js +16 -22
- package/dist/lambda/handler-runner/java-runner/JavaRunner.js +26 -14
- package/dist/lambda/handler-runner/python-runner/PythonRunner.js +20 -7
- package/dist/lambda/handler-runner/ruby-runner/RubyRunner.js +22 -24
- package/dist/lambda/handler-runner/worker-thread-runner/WorkerThreadRunner.js +2 -2
- package/dist/lambda/handler-runner/worker-thread-runner/workerThreadHelper.js +1 -11
- package/dist/lambda/routes/invocations/InvocationsController.js +30 -11
- package/dist/lambda/routes/invocations/invocationsRoute.js +4 -3
- package/dist/lambda/routes/invoke-async/InvokeAsyncController.js +2 -6
- package/dist/serverlessLog.js +1 -1
- package/dist/utils/checkGoVersion.js +27 -0
- package/dist/utils/getHttpApiCorsConfig.js +18 -5
- package/dist/utils/index.js +24 -16
- package/package.json +86 -37
|
@@ -11,9 +11,9 @@ var path = _interopRequireWildcard(require("path"));
|
|
|
11
11
|
|
|
12
12
|
var fs = _interopRequireWildcard(require("fs"));
|
|
13
13
|
|
|
14
|
-
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var
|
|
14
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
15
15
|
|
|
16
|
-
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
16
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
17
17
|
|
|
18
18
|
function _classPrivateFieldLooseBase(receiver, privateKey) { if (!Object.prototype.hasOwnProperty.call(receiver, privateKey)) { throw new TypeError("attempted to use private field on non-instance"); } return receiver; }
|
|
19
19
|
|
|
@@ -74,7 +74,7 @@ const clearModule = (fP, opts) => {
|
|
|
74
74
|
cleanup = false;
|
|
75
75
|
|
|
76
76
|
for (const fn of Object.keys(require.cache)) {
|
|
77
|
-
if (require.cache[fn].id !== '.' && require.cache[fn].parent && require.cache[fn].parent.id !== '.' && !require.cache[require.cache[fn].parent.id]) {
|
|
77
|
+
if (require.cache[fn] && require.cache[fn].id !== '.' && require.cache[fn].parent && require.cache[fn].parent.id !== '.' && !require.cache[require.cache[fn].parent.id]) {
|
|
78
78
|
delete require.cache[fn];
|
|
79
79
|
cleanup = true;
|
|
80
80
|
}
|
|
@@ -84,17 +84,17 @@ const clearModule = (fP, opts) => {
|
|
|
84
84
|
}
|
|
85
85
|
};
|
|
86
86
|
|
|
87
|
-
var _env = _classPrivateFieldLooseKey("env");
|
|
87
|
+
var _env = /*#__PURE__*/_classPrivateFieldLooseKey("env");
|
|
88
88
|
|
|
89
|
-
var _functionKey = _classPrivateFieldLooseKey("functionKey");
|
|
89
|
+
var _functionKey = /*#__PURE__*/_classPrivateFieldLooseKey("functionKey");
|
|
90
90
|
|
|
91
|
-
var _handlerName = _classPrivateFieldLooseKey("handlerName");
|
|
91
|
+
var _handlerName = /*#__PURE__*/_classPrivateFieldLooseKey("handlerName");
|
|
92
92
|
|
|
93
|
-
var _handlerPath = _classPrivateFieldLooseKey("handlerPath");
|
|
93
|
+
var _handlerPath = /*#__PURE__*/_classPrivateFieldLooseKey("handlerPath");
|
|
94
94
|
|
|
95
|
-
var _timeout = _classPrivateFieldLooseKey("timeout");
|
|
95
|
+
var _timeout = /*#__PURE__*/_classPrivateFieldLooseKey("timeout");
|
|
96
96
|
|
|
97
|
-
var _allowCache = _classPrivateFieldLooseKey("allowCache");
|
|
97
|
+
var _allowCache = /*#__PURE__*/_classPrivateFieldLooseKey("allowCache");
|
|
98
98
|
|
|
99
99
|
class InProcessRunner {
|
|
100
100
|
constructor(functionKey, handlerPath, handlerName, env, timeout, allowCache) {
|
|
@@ -163,8 +163,14 @@ class InProcessRunner {
|
|
|
163
163
|
let callback;
|
|
164
164
|
const callbackCalled = new Promise((resolve, reject) => {
|
|
165
165
|
callback = (err, data) => {
|
|
166
|
+
if (err === 'Unauthorized') {
|
|
167
|
+
resolve('Unauthorized');
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
|
|
166
171
|
if (err) {
|
|
167
172
|
reject(err);
|
|
173
|
+
return;
|
|
168
174
|
}
|
|
169
175
|
|
|
170
176
|
resolve(data);
|
|
@@ -191,9 +197,6 @@ class InProcessRunner {
|
|
|
191
197
|
try {
|
|
192
198
|
result = handler(event, lambdaContext, callback);
|
|
193
199
|
} catch (err) {
|
|
194
|
-
// this only executes when we have an exception caused by synchronous code
|
|
195
|
-
// TODO logging
|
|
196
|
-
console.log(err);
|
|
197
200
|
throw new Error(`Uncaught error in '${_classPrivateFieldLooseBase(this, _functionKey)[_functionKey]}' handler.`);
|
|
198
201
|
} // // not a Promise, which is not supported by aws
|
|
199
202
|
// if (result == null || typeof result.then !== 'function') {
|
|
@@ -207,16 +210,7 @@ class InProcessRunner {
|
|
|
207
210
|
callbacks.push(result);
|
|
208
211
|
}
|
|
209
212
|
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
try {
|
|
213
|
-
callbackResult = await Promise.race(callbacks);
|
|
214
|
-
} catch (err) {
|
|
215
|
-
// TODO logging
|
|
216
|
-
console.log(err);
|
|
217
|
-
throw err;
|
|
218
|
-
}
|
|
219
|
-
|
|
213
|
+
const callbackResult = await Promise.race(callbacks);
|
|
220
214
|
return callbackResult;
|
|
221
215
|
}
|
|
222
216
|
|
|
@@ -27,18 +27,18 @@ const {
|
|
|
27
27
|
has
|
|
28
28
|
} = Reflect;
|
|
29
29
|
|
|
30
|
-
var _env = _classPrivateFieldLooseKey("env");
|
|
30
|
+
var _env = /*#__PURE__*/_classPrivateFieldLooseKey("env");
|
|
31
31
|
|
|
32
|
-
var _functionName = _classPrivateFieldLooseKey("functionName");
|
|
32
|
+
var _functionName = /*#__PURE__*/_classPrivateFieldLooseKey("functionName");
|
|
33
33
|
|
|
34
|
-
var _handler = _classPrivateFieldLooseKey("handler");
|
|
34
|
+
var _handler = /*#__PURE__*/_classPrivateFieldLooseKey("handler");
|
|
35
35
|
|
|
36
|
-
var _deployPackage = _classPrivateFieldLooseKey("deployPackage");
|
|
36
|
+
var _deployPackage = /*#__PURE__*/_classPrivateFieldLooseKey("deployPackage");
|
|
37
37
|
|
|
38
|
-
var _allowCache = _classPrivateFieldLooseKey("allowCache");
|
|
38
|
+
var _allowCache = /*#__PURE__*/_classPrivateFieldLooseKey("allowCache");
|
|
39
39
|
|
|
40
40
|
class JavaRunner {
|
|
41
|
-
constructor(funOptions, env, allowCache) {
|
|
41
|
+
constructor(funOptions, env, allowCache, v3Utils) {
|
|
42
42
|
Object.defineProperty(this, _env, {
|
|
43
43
|
writable: true,
|
|
44
44
|
value: null
|
|
@@ -70,6 +70,13 @@ class JavaRunner {
|
|
|
70
70
|
_classPrivateFieldLooseBase(this, _handler)[_handler] = handler;
|
|
71
71
|
_classPrivateFieldLooseBase(this, _deployPackage)[_deployPackage] = functionPackage || servicePackage;
|
|
72
72
|
_classPrivateFieldLooseBase(this, _allowCache)[_allowCache] = allowCache;
|
|
73
|
+
|
|
74
|
+
if (v3Utils) {
|
|
75
|
+
this.log = v3Utils.log;
|
|
76
|
+
this.progress = v3Utils.progress;
|
|
77
|
+
this.writeText = v3Utils.writeText;
|
|
78
|
+
this.v3Utils = v3Utils;
|
|
79
|
+
}
|
|
73
80
|
} // no-op
|
|
74
81
|
// () => void
|
|
75
82
|
|
|
@@ -120,19 +127,24 @@ class JavaRunner {
|
|
|
120
127
|
const response = await (0, _nodeFetch.default)(`http://localhost:${port}/invoke`, httpOptions);
|
|
121
128
|
result = await response.text();
|
|
122
129
|
} catch (e) {
|
|
123
|
-
|
|
130
|
+
if (this.log) {
|
|
131
|
+
this.log.notice('Local java server not running. For faster local invocations, run "java-invoke-local --server" in your project directory');
|
|
132
|
+
} else {
|
|
133
|
+
console.log('Local java server not running. For faster local invocations, run "java-invoke-local --server" in your project directory');
|
|
134
|
+
} // Fallback invocation
|
|
135
|
+
|
|
124
136
|
|
|
125
137
|
const args = ['-c', _classPrivateFieldLooseBase(this, _handler)[_handler], '-a', _classPrivateFieldLooseBase(this, _deployPackage)[_deployPackage], '-f', _classPrivateFieldLooseBase(this, _functionName)[_functionName], '-d', input, '--json-output', '--serverless-offline'];
|
|
126
138
|
result = (0, _javaInvokeLocal.invokeJavaLocal)(args, _classPrivateFieldLooseBase(this, _env)[_env]);
|
|
127
|
-
console.log(result);
|
|
128
|
-
}
|
|
129
139
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
140
|
+
if (this.log) {
|
|
141
|
+
this.log.notice(result);
|
|
142
|
+
} else {
|
|
143
|
+
console.log(result);
|
|
144
|
+
}
|
|
135
145
|
}
|
|
146
|
+
|
|
147
|
+
return this._parsePayload(result);
|
|
136
148
|
}
|
|
137
149
|
|
|
138
150
|
}
|
|
@@ -34,18 +34,18 @@ const {
|
|
|
34
34
|
has
|
|
35
35
|
} = Reflect;
|
|
36
36
|
|
|
37
|
-
var _env = _classPrivateFieldLooseKey("env");
|
|
37
|
+
var _env = /*#__PURE__*/_classPrivateFieldLooseKey("env");
|
|
38
38
|
|
|
39
|
-
var _handlerName = _classPrivateFieldLooseKey("handlerName");
|
|
39
|
+
var _handlerName = /*#__PURE__*/_classPrivateFieldLooseKey("handlerName");
|
|
40
40
|
|
|
41
|
-
var _handlerPath = _classPrivateFieldLooseKey("handlerPath");
|
|
41
|
+
var _handlerPath = /*#__PURE__*/_classPrivateFieldLooseKey("handlerPath");
|
|
42
42
|
|
|
43
|
-
var _runtime = _classPrivateFieldLooseKey("runtime");
|
|
43
|
+
var _runtime = /*#__PURE__*/_classPrivateFieldLooseKey("runtime");
|
|
44
44
|
|
|
45
|
-
var _allowCache = _classPrivateFieldLooseKey("allowCache");
|
|
45
|
+
var _allowCache = /*#__PURE__*/_classPrivateFieldLooseKey("allowCache");
|
|
46
46
|
|
|
47
47
|
class PythonRunner {
|
|
48
|
-
constructor(funOptions, env, allowCache) {
|
|
48
|
+
constructor(funOptions, env, allowCache, v3Utils) {
|
|
49
49
|
Object.defineProperty(this, _env, {
|
|
50
50
|
writable: true,
|
|
51
51
|
value: null
|
|
@@ -77,6 +77,13 @@ class PythonRunner {
|
|
|
77
77
|
_classPrivateFieldLooseBase(this, _runtime)[_runtime] = (0, _os.platform)() === 'win32' ? 'python.exe' : runtime;
|
|
78
78
|
_classPrivateFieldLooseBase(this, _allowCache)[_allowCache] = allowCache;
|
|
79
79
|
|
|
80
|
+
if (v3Utils) {
|
|
81
|
+
this.log = v3Utils.log;
|
|
82
|
+
this.progress = v3Utils.progress;
|
|
83
|
+
this.writeText = v3Utils.writeText;
|
|
84
|
+
this.v3Utils = v3Utils;
|
|
85
|
+
}
|
|
86
|
+
|
|
80
87
|
if (process.env.VIRTUAL_ENV) {
|
|
81
88
|
const runtimeDir = (0, _os.platform)() === 'win32' ? 'Scripts' : 'bin';
|
|
82
89
|
process.env.PATH = [(0, _path.join)(process.env.VIRTUAL_ENV, runtimeDir), _path.delimiter, process.env.PATH].join('');
|
|
@@ -112,6 +119,8 @@ class PythonRunner {
|
|
|
112
119
|
|
|
113
120
|
if (json && typeof json === 'object' && has(json, '__offline_payload__')) {
|
|
114
121
|
payload = json.__offline_payload__; // everything else is print(), logging, ...
|
|
122
|
+
} else if (this.log) {
|
|
123
|
+
this.log.notice(item);
|
|
115
124
|
} else {
|
|
116
125
|
console.log(item);
|
|
117
126
|
}
|
|
@@ -134,7 +143,11 @@ class PythonRunner {
|
|
|
134
143
|
|
|
135
144
|
const onErr = data => {
|
|
136
145
|
// TODO
|
|
137
|
-
|
|
146
|
+
if (this.log) {
|
|
147
|
+
this.log.notice(data.toString());
|
|
148
|
+
} else {
|
|
149
|
+
console.log(data.toString());
|
|
150
|
+
}
|
|
138
151
|
};
|
|
139
152
|
|
|
140
153
|
const onLine = line => {
|
|
@@ -30,16 +30,16 @@ const {
|
|
|
30
30
|
has
|
|
31
31
|
} = Reflect;
|
|
32
32
|
|
|
33
|
-
var _env = _classPrivateFieldLooseKey("env");
|
|
33
|
+
var _env = /*#__PURE__*/_classPrivateFieldLooseKey("env");
|
|
34
34
|
|
|
35
|
-
var _handlerName = _classPrivateFieldLooseKey("handlerName");
|
|
35
|
+
var _handlerName = /*#__PURE__*/_classPrivateFieldLooseKey("handlerName");
|
|
36
36
|
|
|
37
|
-
var _handlerPath = _classPrivateFieldLooseKey("handlerPath");
|
|
37
|
+
var _handlerPath = /*#__PURE__*/_classPrivateFieldLooseKey("handlerPath");
|
|
38
38
|
|
|
39
|
-
var _allowCache = _classPrivateFieldLooseKey("allowCache");
|
|
39
|
+
var _allowCache = /*#__PURE__*/_classPrivateFieldLooseKey("allowCache");
|
|
40
40
|
|
|
41
41
|
class RubyRunner {
|
|
42
|
-
constructor(funOptions, env, allowCache) {
|
|
42
|
+
constructor(funOptions, env, allowCache, v3Utils) {
|
|
43
43
|
Object.defineProperty(this, _env, {
|
|
44
44
|
writable: true,
|
|
45
45
|
value: null
|
|
@@ -64,6 +64,13 @@ class RubyRunner {
|
|
|
64
64
|
_classPrivateFieldLooseBase(this, _handlerName)[_handlerName] = handlerName;
|
|
65
65
|
_classPrivateFieldLooseBase(this, _handlerPath)[_handlerPath] = handlerPath;
|
|
66
66
|
_classPrivateFieldLooseBase(this, _allowCache)[_allowCache] = allowCache;
|
|
67
|
+
|
|
68
|
+
if (v3Utils) {
|
|
69
|
+
this.log = v3Utils.log;
|
|
70
|
+
this.progress = v3Utils.progress;
|
|
71
|
+
this.writeText = v3Utils.writeText;
|
|
72
|
+
this.v3Utils = v3Utils;
|
|
73
|
+
}
|
|
67
74
|
} // no-op
|
|
68
75
|
// () => void
|
|
69
76
|
|
|
@@ -84,6 +91,8 @@ class RubyRunner {
|
|
|
84
91
|
|
|
85
92
|
if (json && typeof json === 'object' && has(json, '__offline_payload__')) {
|
|
86
93
|
payload = json.__offline_payload__;
|
|
94
|
+
} else if (this.log) {
|
|
95
|
+
this.log.notice(item);
|
|
87
96
|
} else {
|
|
88
97
|
console.log(item); // log non-JSON stdout to console (puts, p, logger.info, ...)
|
|
89
98
|
}
|
|
@@ -116,16 +125,7 @@ class RubyRunner {
|
|
|
116
125
|
input // shell: true,
|
|
117
126
|
|
|
118
127
|
});
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
try {
|
|
122
|
-
result = await ruby;
|
|
123
|
-
} catch (err) {
|
|
124
|
-
// TODO
|
|
125
|
-
console.log(err);
|
|
126
|
-
throw err;
|
|
127
|
-
}
|
|
128
|
-
|
|
128
|
+
const result = await ruby;
|
|
129
129
|
const {
|
|
130
130
|
stderr,
|
|
131
131
|
stdout
|
|
@@ -133,18 +133,16 @@ class RubyRunner {
|
|
|
133
133
|
|
|
134
134
|
if (stderr) {
|
|
135
135
|
// TODO
|
|
136
|
-
|
|
136
|
+
if (this.log) {
|
|
137
|
+
this.log.notice(stderr);
|
|
138
|
+
} else {
|
|
139
|
+
console.log(stderr);
|
|
140
|
+
}
|
|
141
|
+
|
|
137
142
|
return stderr;
|
|
138
143
|
}
|
|
139
144
|
|
|
140
|
-
|
|
141
|
-
return this._parsePayload(stdout);
|
|
142
|
-
} catch (err) {
|
|
143
|
-
// TODO
|
|
144
|
-
console.log('No JSON'); // TODO return or re-throw?
|
|
145
|
-
|
|
146
|
-
return err;
|
|
147
|
-
}
|
|
145
|
+
return this._parsePayload(stdout);
|
|
148
146
|
}
|
|
149
147
|
|
|
150
148
|
}
|
|
@@ -18,9 +18,9 @@ function _classPrivateFieldLooseKey(name) { return "__private_" + id++ + "_" + n
|
|
|
18
18
|
// eslint-disable-line import/no-unresolved
|
|
19
19
|
const workerThreadHelperPath = (0, _path.resolve)(__dirname, './workerThreadHelper.js');
|
|
20
20
|
|
|
21
|
-
var _workerThread = _classPrivateFieldLooseKey("workerThread");
|
|
21
|
+
var _workerThread = /*#__PURE__*/_classPrivateFieldLooseKey("workerThread");
|
|
22
22
|
|
|
23
|
-
var _allowCache = _classPrivateFieldLooseKey("allowCache");
|
|
23
|
+
var _allowCache = /*#__PURE__*/_classPrivateFieldLooseKey("allowCache");
|
|
24
24
|
|
|
25
25
|
class WorkerThreadRunner {
|
|
26
26
|
constructor(funOptions
|
|
@@ -23,17 +23,7 @@ _worker_threads.parentPort.on('message', async messageData => {
|
|
|
23
23
|
} = messageData; // TODO we could probably cache this in the module scope?
|
|
24
24
|
|
|
25
25
|
const inProcessRunner = new _index.default(functionKey, handlerPath, handlerName, process.env, timeout, allowCache);
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
try {
|
|
29
|
-
result = await inProcessRunner.run(event, context);
|
|
30
|
-
} catch (err) {
|
|
31
|
-
// this only executes when we have an exception caused by synchronous code
|
|
32
|
-
// TODO logging
|
|
33
|
-
console.log(err);
|
|
34
|
-
throw err;
|
|
35
|
-
} // TODO check serializeability (contains function, symbol etc)
|
|
36
|
-
|
|
26
|
+
const result = await inProcessRunner.run(event, context); // TODO check serializeability (contains function, symbol etc)
|
|
37
27
|
|
|
38
28
|
port.postMessage(result);
|
|
39
29
|
});
|
|
@@ -15,15 +15,22 @@ var id = 0;
|
|
|
15
15
|
|
|
16
16
|
function _classPrivateFieldLooseKey(name) { return "__private_" + id++ + "_" + name; }
|
|
17
17
|
|
|
18
|
-
var _lambda = _classPrivateFieldLooseKey("lambda");
|
|
18
|
+
var _lambda = /*#__PURE__*/_classPrivateFieldLooseKey("lambda");
|
|
19
19
|
|
|
20
20
|
class InvocationsController {
|
|
21
|
-
constructor(lambda) {
|
|
21
|
+
constructor(lambda, v3Utils) {
|
|
22
22
|
Object.defineProperty(this, _lambda, {
|
|
23
23
|
writable: true,
|
|
24
24
|
value: null
|
|
25
25
|
});
|
|
26
26
|
_classPrivateFieldLooseBase(this, _lambda)[_lambda] = lambda;
|
|
27
|
+
|
|
28
|
+
if (v3Utils) {
|
|
29
|
+
this.log = v3Utils.log;
|
|
30
|
+
this.progress = v3Utils.progress;
|
|
31
|
+
this.writeText = v3Utils.writeText;
|
|
32
|
+
this.v3Utils = v3Utils;
|
|
33
|
+
}
|
|
27
34
|
}
|
|
28
35
|
|
|
29
36
|
async invoke(functionName, invocationType, event, clientContext) {
|
|
@@ -31,9 +38,14 @@ class InvocationsController {
|
|
|
31
38
|
const functionNames = _classPrivateFieldLooseBase(this, _lambda)[_lambda].listFunctionNames();
|
|
32
39
|
|
|
33
40
|
if (functionNames.length === 0 || !functionNames.includes(functionName)) {
|
|
34
|
-
(
|
|
41
|
+
if (this.log) {
|
|
42
|
+
this.log.error(`Attempt to invoke function '${functionName}' failed. Function does not exists.`);
|
|
43
|
+
} else {
|
|
44
|
+
(0, _serverlessLog.default)(`Attempt to invoke function '${functionName}' failed. Function does not exists.`);
|
|
45
|
+
} // Conforms to the actual response from AWS Lambda when invoking a non-existent
|
|
35
46
|
// function. Details on the error are provided in the Payload.Message key
|
|
36
47
|
|
|
48
|
+
|
|
37
49
|
return {
|
|
38
50
|
FunctionError: 'ResourceNotFoundException',
|
|
39
51
|
Payload: {
|
|
@@ -51,11 +63,7 @@ class InvocationsController {
|
|
|
51
63
|
|
|
52
64
|
if (invocationType === 'Event') {
|
|
53
65
|
// don't await result!
|
|
54
|
-
lambdaFunction.runHandler()
|
|
55
|
-
// TODO handle error
|
|
56
|
-
console.log(err);
|
|
57
|
-
throw err;
|
|
58
|
-
});
|
|
66
|
+
lambdaFunction.runHandler();
|
|
59
67
|
return {
|
|
60
68
|
Payload: '',
|
|
61
69
|
StatusCode: 202
|
|
@@ -68,13 +76,18 @@ class InvocationsController {
|
|
|
68
76
|
try {
|
|
69
77
|
result = await lambdaFunction.runHandler();
|
|
70
78
|
} catch (err) {
|
|
71
|
-
(
|
|
72
|
-
|
|
79
|
+
if (this.log) {
|
|
80
|
+
this.log.error(`Unhandled Lambda Error during invoke of '${functionName}': ${err}`);
|
|
81
|
+
} else {
|
|
82
|
+
(0, _serverlessLog.default)(`Unhandled Lambda Error during invoke of '${functionName}'`);
|
|
83
|
+
console.log(err);
|
|
84
|
+
} // In most circumstances this is the correct error type/structure.
|
|
73
85
|
// The API returns a StreamingBody with status code of 200
|
|
74
86
|
// that eventually spits out the error and stack trace.
|
|
75
87
|
// When the request is synchronous, aws-sdk should buffer
|
|
76
88
|
// the whole error stream, however this has not been validated.
|
|
77
89
|
|
|
90
|
+
|
|
78
91
|
return {
|
|
79
92
|
Payload: {
|
|
80
93
|
errorType: 'Error',
|
|
@@ -107,7 +120,13 @@ class InvocationsController {
|
|
|
107
120
|
|
|
108
121
|
|
|
109
122
|
const errMsg = `invocationType: '${invocationType}' not supported by serverless-offline`;
|
|
110
|
-
|
|
123
|
+
|
|
124
|
+
if (this.log) {
|
|
125
|
+
this.log.error(errMsg);
|
|
126
|
+
} else {
|
|
127
|
+
console.log(errMsg);
|
|
128
|
+
}
|
|
129
|
+
|
|
111
130
|
return {
|
|
112
131
|
FunctionError: 'InvalidParameterValueException',
|
|
113
132
|
Payload: {
|
|
@@ -17,8 +17,8 @@ const {
|
|
|
17
17
|
parse
|
|
18
18
|
} = JSON; // https://docs.aws.amazon.com/lambda/latest/dg/API_Invoke.html
|
|
19
19
|
|
|
20
|
-
function invocationsRoute(lambda, options) {
|
|
21
|
-
const invocationsController = new _InvocationsController.default(lambda);
|
|
20
|
+
function invocationsRoute(lambda, options, v3Utils) {
|
|
21
|
+
const invocationsController = new _InvocationsController.default(lambda, v3Utils);
|
|
22
22
|
return {
|
|
23
23
|
async handler(request, h) {
|
|
24
24
|
const {
|
|
@@ -53,7 +53,8 @@ function invocationsRoute(lambda, options) {
|
|
|
53
53
|
let functionError = null;
|
|
54
54
|
|
|
55
55
|
if (invokeResults) {
|
|
56
|
-
|
|
56
|
+
const isPayloadDefined = typeof invokeResults.Payload !== 'undefined';
|
|
57
|
+
resultPayload = isPayloadDefined ? invokeResults.Payload : '';
|
|
57
58
|
statusCode = invokeResults.StatusCode || 200;
|
|
58
59
|
functionError = invokeResults.FunctionError || null;
|
|
59
60
|
}
|
|
@@ -11,7 +11,7 @@ var id = 0;
|
|
|
11
11
|
|
|
12
12
|
function _classPrivateFieldLooseKey(name) { return "__private_" + id++ + "_" + name; }
|
|
13
13
|
|
|
14
|
-
var _lambda = _classPrivateFieldLooseKey("lambda");
|
|
14
|
+
var _lambda = /*#__PURE__*/_classPrivateFieldLooseKey("lambda");
|
|
15
15
|
|
|
16
16
|
class InvokeAsyncController {
|
|
17
17
|
constructor(lambda) {
|
|
@@ -27,11 +27,7 @@ class InvokeAsyncController {
|
|
|
27
27
|
|
|
28
28
|
lambdaFunction.setEvent(event); // don't await result!
|
|
29
29
|
|
|
30
|
-
lambdaFunction.runHandler()
|
|
31
|
-
// TODO handle error
|
|
32
|
-
console.log(err);
|
|
33
|
-
throw err;
|
|
34
|
-
});
|
|
30
|
+
lambdaFunction.runHandler();
|
|
35
31
|
return {
|
|
36
32
|
StatusCode: 202
|
|
37
33
|
};
|
package/dist/serverlessLog.js
CHANGED
|
@@ -5,9 +5,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = serverlessLog;
|
|
7
7
|
exports.logLayers = logLayers;
|
|
8
|
-
exports.setLog = setLog;
|
|
9
8
|
exports.logRoutes = logRoutes;
|
|
10
9
|
exports.logWarning = logWarning;
|
|
10
|
+
exports.setLog = setLog;
|
|
11
11
|
|
|
12
12
|
var _boxen = _interopRequireDefault(require("boxen"));
|
|
13
13
|
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = checkGoVersion;
|
|
7
|
+
|
|
8
|
+
var _execa = _interopRequireDefault(require("execa"));
|
|
9
|
+
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
+
|
|
12
|
+
async function checkGoVersion() {
|
|
13
|
+
let goVersion;
|
|
14
|
+
|
|
15
|
+
try {
|
|
16
|
+
const {
|
|
17
|
+
stdout
|
|
18
|
+
} = await (0, _execa.default)('go', ['version']);
|
|
19
|
+
|
|
20
|
+
if (stdout.match(/go1.\d+/g)) {
|
|
21
|
+
goVersion = '1.x';
|
|
22
|
+
}
|
|
23
|
+
} catch (err) {// @ignore
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return goVersion;
|
|
27
|
+
}
|
|
@@ -11,7 +11,9 @@ var _serverlessLog = require("../serverlessLog.js");
|
|
|
11
11
|
|
|
12
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
13
|
|
|
14
|
-
function getHttpApiCorsConfig(httpApiCors
|
|
14
|
+
function getHttpApiCorsConfig(httpApiCors, {
|
|
15
|
+
log
|
|
16
|
+
}) {
|
|
15
17
|
if (httpApiCors === true) {
|
|
16
18
|
// default values that should be set by serverless
|
|
17
19
|
// https://www.serverless.com/framework/docs/providers/aws/events/http-api/
|
|
@@ -20,12 +22,23 @@ function getHttpApiCorsConfig(httpApiCors) {
|
|
|
20
22
|
allowedHeaders: ['Content-Type', 'X-Amz-Date', 'Authorization', 'X-Api-Key', 'X-Amz-Security-Token', 'X-Amz-User-Agent'],
|
|
21
23
|
allowedMethods: ['OPTIONS', 'GET', 'POST', 'PUT', 'DELETE', 'PATCH']
|
|
22
24
|
};
|
|
23
|
-
|
|
24
|
-
|
|
25
|
+
|
|
26
|
+
if (log) {
|
|
27
|
+
log.warning(c);
|
|
28
|
+
} else {
|
|
29
|
+
(0, _debugLog.default)(c);
|
|
30
|
+
(0, _serverlessLog.logWarning)(c);
|
|
31
|
+
}
|
|
32
|
+
|
|
25
33
|
return c;
|
|
26
34
|
}
|
|
27
35
|
|
|
28
|
-
|
|
29
|
-
|
|
36
|
+
if (log) {
|
|
37
|
+
log.warning(httpApiCors);
|
|
38
|
+
} else {
|
|
39
|
+
(0, _debugLog.default)(httpApiCors);
|
|
40
|
+
(0, _serverlessLog.logWarning)(httpApiCors);
|
|
41
|
+
}
|
|
42
|
+
|
|
30
43
|
return httpApiCors;
|
|
31
44
|
}
|
package/dist/utils/index.js
CHANGED
|
@@ -3,10 +3,18 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
Object.defineProperty(exports, "checkDockerDaemon", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _checkDockerDaemon.default;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "checkGoVersion", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _checkGoVersion.default;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
10
18
|
Object.defineProperty(exports, "createApiKey", {
|
|
11
19
|
enumerable: true,
|
|
12
20
|
get: function () {
|
|
@@ -19,6 +27,7 @@ Object.defineProperty(exports, "createUniqueId", {
|
|
|
19
27
|
return _createUniqueId.default;
|
|
20
28
|
}
|
|
21
29
|
});
|
|
30
|
+
exports.detectEncoding = detectEncoding;
|
|
22
31
|
Object.defineProperty(exports, "detectExecutable", {
|
|
23
32
|
enumerable: true,
|
|
24
33
|
get: function () {
|
|
@@ -31,18 +40,26 @@ Object.defineProperty(exports, "formatToClfTime", {
|
|
|
31
40
|
return _formatToClfTime.default;
|
|
32
41
|
}
|
|
33
42
|
});
|
|
43
|
+
Object.defineProperty(exports, "generateHapiPath", {
|
|
44
|
+
enumerable: true,
|
|
45
|
+
get: function () {
|
|
46
|
+
return _generateHapiPath.default;
|
|
47
|
+
}
|
|
48
|
+
});
|
|
34
49
|
Object.defineProperty(exports, "getHttpApiCorsConfig", {
|
|
35
50
|
enumerable: true,
|
|
36
51
|
get: function () {
|
|
37
52
|
return _getHttpApiCorsConfig.default;
|
|
38
53
|
}
|
|
39
54
|
});
|
|
55
|
+
exports.isPlainObject = isPlainObject;
|
|
40
56
|
Object.defineProperty(exports, "jsonPath", {
|
|
41
57
|
enumerable: true,
|
|
42
58
|
get: function () {
|
|
43
59
|
return _jsonPath.default;
|
|
44
60
|
}
|
|
45
61
|
});
|
|
62
|
+
exports.nullIfEmpty = nullIfEmpty;
|
|
46
63
|
Object.defineProperty(exports, "parseHeaders", {
|
|
47
64
|
enumerable: true,
|
|
48
65
|
get: function () {
|
|
@@ -79,18 +96,7 @@ Object.defineProperty(exports, "splitHandlerPathAndName", {
|
|
|
79
96
|
return _splitHandlerPathAndName.default;
|
|
80
97
|
}
|
|
81
98
|
});
|
|
82
|
-
|
|
83
|
-
enumerable: true,
|
|
84
|
-
get: function () {
|
|
85
|
-
return _checkDockerDaemon.default;
|
|
86
|
-
}
|
|
87
|
-
});
|
|
88
|
-
Object.defineProperty(exports, "generateHapiPath", {
|
|
89
|
-
enumerable: true,
|
|
90
|
-
get: function () {
|
|
91
|
-
return _generateHapiPath.default;
|
|
92
|
-
}
|
|
93
|
-
});
|
|
99
|
+
exports.toPlainOrEmptyObject = toPlainOrEmptyObject;
|
|
94
100
|
|
|
95
101
|
var _createApiKey = _interopRequireDefault(require("./createApiKey.js"));
|
|
96
102
|
|
|
@@ -118,6 +124,8 @@ var _splitHandlerPathAndName = _interopRequireDefault(require("./splitHandlerPat
|
|
|
118
124
|
|
|
119
125
|
var _checkDockerDaemon = _interopRequireDefault(require("./checkDockerDaemon.js"));
|
|
120
126
|
|
|
127
|
+
var _checkGoVersion = _interopRequireDefault(require("./checkGoVersion.js"));
|
|
128
|
+
|
|
121
129
|
var _generateHapiPath = _interopRequireDefault(require("./generateHapiPath.js"));
|
|
122
130
|
|
|
123
131
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|