serverless-offline 8.7.0 → 8.8.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 +89 -93
- package/dist/ServerlessOffline.js +15 -8
- package/dist/config/supportedRuntimes.js +1 -1
- package/dist/debugLog.js +3 -1
- package/dist/events/{http/authValidateContext.js → authValidateContext.js} +8 -3
- package/dist/events/http/Endpoint.js +3 -1
- package/dist/events/http/HttpServer.js +27 -20
- package/dist/events/http/OfflineEndpoint.js +23 -25
- package/dist/events/http/createAuthScheme.js +1 -1
- package/dist/events/http/createJWTAuthScheme.js +6 -2
- package/dist/events/http/lambda-events/LambdaIntegrationEvent.js +4 -2
- package/dist/events/http/lambda-events/LambdaProxyIntegrationEvent.js +16 -14
- package/dist/events/http/lambda-events/LambdaProxyIntegrationEventV2.js +17 -13
- package/dist/events/http/lambda-events/VelocityContext.js +3 -1
- package/dist/events/http/lambda-events/renderVelocityTemplateObject.js +4 -1
- package/dist/events/schedule/Schedule.js +10 -9
- package/dist/events/websocket/HttpServer.js +3 -1
- package/dist/events/websocket/WebSocketClients.js +38 -11
- package/dist/events/websocket/WebSocketServer.js +5 -6
- package/dist/index.js +0 -4
- package/dist/lambda/HttpServer.js +3 -1
- package/dist/lambda/Lambda.js +5 -1
- package/dist/lambda/LambdaFunction.js +1 -2
- package/dist/lambda/handler-runner/HandlerRunner.js +1 -29
- package/dist/lambda/handler-runner/child-process-runner/ChildProcessRunner.js +1 -9
- package/dist/lambda/handler-runner/child-process-runner/childProcessHelper.js +15 -6
- package/dist/lambda/handler-runner/docker-runner/DockerContainer.js +2 -4
- package/dist/lambda/handler-runner/go-runner/GoRunner.js +34 -15
- package/dist/lambda/handler-runner/in-process-runner/InProcessRunner.js +24 -30
- package/dist/lambda/handler-runner/java-runner/JavaRunner.js +3 -1
- package/dist/lambda/handler-runner/python-runner/PythonRunner.js +15 -10
- package/dist/lambda/handler-runner/ruby-runner/RubyRunner.js +3 -4
- package/dist/lambda/handler-runner/worker-thread-runner/WorkerThreadRunner.js +0 -2
- package/dist/lambda/handler-runner/worker-thread-runner/workerThreadHelper.js +4 -3
- package/dist/utils/generateHapiPath.js +1 -1
- package/dist/utils/getHttpApiCorsConfig.js +4 -8
- package/dist/utils/index.js +11 -4
- package/dist/utils/lowerCaseKeys.js +14 -0
- package/dist/utils/resolveJoins.js +4 -2
- package/dist/utils/splitHandlerPathAndName.js +9 -13
- package/package.json +23 -26
- package/dist/checkEngine.js +0 -21
|
@@ -27,8 +27,6 @@ var _handlerName = /*#__PURE__*/_classPrivateFieldLooseKey("handlerName");
|
|
|
27
27
|
|
|
28
28
|
var _handlerPath = /*#__PURE__*/_classPrivateFieldLooseKey("handlerPath");
|
|
29
29
|
|
|
30
|
-
var _handlerModuleNesting = /*#__PURE__*/_classPrivateFieldLooseKey("handlerModuleNesting");
|
|
31
|
-
|
|
32
30
|
var _timeout = /*#__PURE__*/_classPrivateFieldLooseKey("timeout");
|
|
33
31
|
|
|
34
32
|
var _allowCache = /*#__PURE__*/_classPrivateFieldLooseKey("allowCache");
|
|
@@ -51,10 +49,6 @@ class ChildProcessRunner {
|
|
|
51
49
|
writable: true,
|
|
52
50
|
value: null
|
|
53
51
|
});
|
|
54
|
-
Object.defineProperty(this, _handlerModuleNesting, {
|
|
55
|
-
writable: true,
|
|
56
|
-
value: null
|
|
57
|
-
});
|
|
58
52
|
Object.defineProperty(this, _timeout, {
|
|
59
53
|
writable: true,
|
|
60
54
|
value: null
|
|
@@ -67,7 +61,6 @@ class ChildProcessRunner {
|
|
|
67
61
|
functionKey,
|
|
68
62
|
handlerName,
|
|
69
63
|
handlerPath,
|
|
70
|
-
handlerModuleNesting,
|
|
71
64
|
timeout
|
|
72
65
|
} = funOptions;
|
|
73
66
|
|
|
@@ -82,7 +75,6 @@ class ChildProcessRunner {
|
|
|
82
75
|
_classPrivateFieldLooseBase(this, _functionKey)[_functionKey] = functionKey;
|
|
83
76
|
_classPrivateFieldLooseBase(this, _handlerName)[_handlerName] = handlerName;
|
|
84
77
|
_classPrivateFieldLooseBase(this, _handlerPath)[_handlerPath] = handlerPath;
|
|
85
|
-
_classPrivateFieldLooseBase(this, _handlerModuleNesting)[_handlerModuleNesting] = handlerModuleNesting;
|
|
86
78
|
_classPrivateFieldLooseBase(this, _timeout)[_timeout] = timeout;
|
|
87
79
|
_classPrivateFieldLooseBase(this, _allowCache)[_allowCache] = allowCache;
|
|
88
80
|
} // no-op
|
|
@@ -92,7 +84,7 @@ class ChildProcessRunner {
|
|
|
92
84
|
cleanup() {}
|
|
93
85
|
|
|
94
86
|
async run(event, context) {
|
|
95
|
-
const childProcess = (0, _execa.node)(childProcessHelperPath, [_classPrivateFieldLooseBase(this, _functionKey)[_functionKey], _classPrivateFieldLooseBase(this, _handlerName)[_handlerName], _classPrivateFieldLooseBase(this, _handlerPath)[_handlerPath]
|
|
87
|
+
const childProcess = (0, _execa.node)(childProcessHelperPath, [_classPrivateFieldLooseBase(this, _functionKey)[_functionKey], _classPrivateFieldLooseBase(this, _handlerName)[_handlerName], _classPrivateFieldLooseBase(this, _handlerPath)[_handlerPath]], {
|
|
96
88
|
env: _classPrivateFieldLooseBase(this, _env)[_env],
|
|
97
89
|
stdio: 'inherit'
|
|
98
90
|
});
|
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _process = _interopRequireWildcard(require("process"));
|
|
4
|
+
|
|
3
5
|
var _index = _interopRequireDefault(require("../in-process-runner/index.js"));
|
|
4
6
|
|
|
5
7
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
6
8
|
|
|
9
|
+
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); }
|
|
10
|
+
|
|
11
|
+
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; }
|
|
12
|
+
|
|
7
13
|
// TODO handle this:
|
|
8
|
-
|
|
14
|
+
_process.default.on('uncaughtException', err => {
|
|
9
15
|
const {
|
|
10
16
|
constructor: {
|
|
11
17
|
name
|
|
@@ -13,7 +19,8 @@ process.on('uncaughtException', err => {
|
|
|
13
19
|
message,
|
|
14
20
|
stack
|
|
15
21
|
} = err;
|
|
16
|
-
|
|
22
|
+
|
|
23
|
+
_process.default.send({
|
|
17
24
|
// process.send() can't serialize an Error object, so we help it out a bit
|
|
18
25
|
error: {
|
|
19
26
|
constructor: {
|
|
@@ -24,8 +31,10 @@ process.on('uncaughtException', err => {
|
|
|
24
31
|
}
|
|
25
32
|
});
|
|
26
33
|
});
|
|
27
|
-
|
|
28
|
-
|
|
34
|
+
|
|
35
|
+
const [,, functionKey, handlerName, handlerPath] = _process.argv;
|
|
36
|
+
|
|
37
|
+
_process.default.on('message', async messageData => {
|
|
29
38
|
const {
|
|
30
39
|
context,
|
|
31
40
|
event,
|
|
@@ -33,8 +42,8 @@ process.on('message', async messageData => {
|
|
|
33
42
|
timeout
|
|
34
43
|
} = messageData; // TODO we could probably cache this in the module scope?
|
|
35
44
|
|
|
36
|
-
const inProcessRunner = new _index.default(functionKey, handlerPath, handlerName,
|
|
45
|
+
const inProcessRunner = new _index.default(functionKey, handlerPath, handlerName, _process.default.env, timeout, allowCache);
|
|
37
46
|
const result = await inProcessRunner.run(event, context); // TODO check serializeability (contains function, symbol etc)
|
|
38
47
|
|
|
39
|
-
|
|
48
|
+
_process.default.send(result);
|
|
40
49
|
});
|
|
@@ -43,9 +43,7 @@ const {
|
|
|
43
43
|
stringify
|
|
44
44
|
} = JSON;
|
|
45
45
|
const {
|
|
46
|
-
entries
|
|
47
|
-
} = Object;
|
|
48
|
-
const {
|
|
46
|
+
entries,
|
|
49
47
|
keys
|
|
50
48
|
} = Object;
|
|
51
49
|
|
|
@@ -505,7 +503,7 @@ class DockerContainer {
|
|
|
505
503
|
}
|
|
506
504
|
|
|
507
505
|
_getLayersSha256() {
|
|
508
|
-
return _crypto.default.createHash('sha256').update(
|
|
506
|
+
return _crypto.default.createHash('sha256').update(stringify(_classPrivateFieldLooseBase(this, _layers)[_layers])).digest('hex');
|
|
509
507
|
}
|
|
510
508
|
|
|
511
509
|
get isRunning() {
|
|
@@ -5,12 +5,14 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
|
-
var _os = require("os");
|
|
9
|
-
|
|
10
8
|
var _fs = require("fs");
|
|
11
9
|
|
|
10
|
+
var _os = require("os");
|
|
11
|
+
|
|
12
12
|
var _path = require("path");
|
|
13
13
|
|
|
14
|
+
var _process = _interopRequireWildcard(require("process"));
|
|
15
|
+
|
|
14
16
|
var _execa = _interopRequireWildcard(require("execa"));
|
|
15
17
|
|
|
16
18
|
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); }
|
|
@@ -33,9 +35,6 @@ const {
|
|
|
33
35
|
parse,
|
|
34
36
|
stringify
|
|
35
37
|
} = JSON;
|
|
36
|
-
const {
|
|
37
|
-
cwd
|
|
38
|
-
} = process;
|
|
39
38
|
const PAYLOAD_IDENTIFIER = 'offline_payload';
|
|
40
39
|
|
|
41
40
|
var _env = /*#__PURE__*/_classPrivateFieldLooseKey("env");
|
|
@@ -48,6 +47,8 @@ var _tmpFile = /*#__PURE__*/_classPrivateFieldLooseKey("tmpFile");
|
|
|
48
47
|
|
|
49
48
|
var _goEnv = /*#__PURE__*/_classPrivateFieldLooseKey("goEnv");
|
|
50
49
|
|
|
50
|
+
var _codeDir = /*#__PURE__*/_classPrivateFieldLooseKey("codeDir");
|
|
51
|
+
|
|
51
52
|
class GoRunner {
|
|
52
53
|
constructor(funOptions, env, v3Utils) {
|
|
53
54
|
Object.defineProperty(this, _env, {
|
|
@@ -70,21 +71,24 @@ class GoRunner {
|
|
|
70
71
|
writable: true,
|
|
71
72
|
value: null
|
|
72
73
|
});
|
|
74
|
+
Object.defineProperty(this, _codeDir, {
|
|
75
|
+
writable: true,
|
|
76
|
+
value: null
|
|
77
|
+
});
|
|
73
78
|
const {
|
|
74
|
-
handlerPath
|
|
79
|
+
handlerPath,
|
|
80
|
+
codeDir
|
|
75
81
|
} = funOptions;
|
|
76
82
|
_classPrivateFieldLooseBase(this, _env)[_env] = env;
|
|
77
83
|
_classPrivateFieldLooseBase(this, _handlerPath)[_handlerPath] = handlerPath;
|
|
84
|
+
_classPrivateFieldLooseBase(this, _codeDir)[_codeDir] = codeDir;
|
|
78
85
|
|
|
79
86
|
if (v3Utils) {
|
|
80
87
|
this.log = v3Utils.log;
|
|
81
88
|
this.progress = v3Utils.progress;
|
|
82
89
|
this.writeText = v3Utils.writeText;
|
|
83
90
|
this.v3Utils = v3Utils;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
(0, _execa.sync)('go', ['get', 'github.com/icarus-sullivan/mock-lambda@e065469']);
|
|
91
|
+
}
|
|
88
92
|
}
|
|
89
93
|
|
|
90
94
|
async cleanup() {
|
|
@@ -173,11 +177,20 @@ class GoRunner {
|
|
|
173
177
|
} // Remove our root, since we want to invoke go relatively
|
|
174
178
|
|
|
175
179
|
|
|
176
|
-
const cwdPath = `${_classPrivateFieldLooseBase(this, _tmpFile)[_tmpFile]}`.replace(`${cwd()}${_path.sep}`, '');
|
|
180
|
+
const cwdPath = `${_classPrivateFieldLooseBase(this, _tmpFile)[_tmpFile]}`.replace(`${(0, _process.cwd)()}${_path.sep}`, '');
|
|
181
|
+
|
|
182
|
+
try {
|
|
183
|
+
(0, _process.chdir)(cwdPath.substring(0, cwdPath.indexOf('main.go'))); // Make sure we have the mock-lambda runner
|
|
184
|
+
|
|
185
|
+
(0, _execa.sync)('go', ['get', 'github.com/icarus-sullivan/mock-lambda@e065469']);
|
|
186
|
+
(0, _execa.sync)('go', ['build']);
|
|
187
|
+
} catch (e) {// @ignore
|
|
188
|
+
}
|
|
189
|
+
|
|
177
190
|
const {
|
|
178
191
|
stdout,
|
|
179
192
|
stderr
|
|
180
|
-
} = await (0, _execa.default)(
|
|
193
|
+
} = await (0, _execa.default)(`./tmp`, {
|
|
181
194
|
stdio: 'pipe',
|
|
182
195
|
env: { ..._classPrivateFieldLooseBase(this, _env)[_env],
|
|
183
196
|
..._classPrivateFieldLooseBase(this, _goEnv)[_goEnv],
|
|
@@ -192,17 +205,23 @@ class GoRunner {
|
|
|
192
205
|
IS_LAMBDA_AUTHORIZER: event.type === 'REQUEST' || event.type === 'TOKEN',
|
|
193
206
|
IS_LAMBDA_REQUEST_AUTHORIZER: event.type === 'REQUEST',
|
|
194
207
|
IS_LAMBDA_TOKEN_AUTHORIZER: event.type === 'TOKEN',
|
|
195
|
-
PATH:
|
|
208
|
+
PATH: _process.default.env.PATH
|
|
196
209
|
},
|
|
197
210
|
encoding: 'utf-8'
|
|
198
|
-
});
|
|
199
|
-
|
|
211
|
+
});
|
|
200
212
|
await this.cleanup();
|
|
201
213
|
|
|
202
214
|
if (stderr) {
|
|
203
215
|
return stderr;
|
|
204
216
|
}
|
|
205
217
|
|
|
218
|
+
try {
|
|
219
|
+
// refresh go.mod
|
|
220
|
+
(0, _execa.sync)('go', ['mod', 'tidy']);
|
|
221
|
+
(0, _process.chdir)(_classPrivateFieldLooseBase(this, _codeDir)[_codeDir]);
|
|
222
|
+
} catch (e) {// @ignore
|
|
223
|
+
}
|
|
224
|
+
|
|
206
225
|
return this._parsePayload(stdout);
|
|
207
226
|
}
|
|
208
227
|
|
|
@@ -5,11 +5,15 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
|
+
var _fs = require("fs");
|
|
9
|
+
|
|
10
|
+
var _path = require("path");
|
|
11
|
+
|
|
8
12
|
var _perf_hooks = require("perf_hooks");
|
|
9
13
|
|
|
10
|
-
var
|
|
14
|
+
var _process = _interopRequireDefault(require("process"));
|
|
11
15
|
|
|
12
|
-
|
|
16
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
17
|
|
|
14
18
|
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
19
|
|
|
@@ -21,15 +25,20 @@ var id = 0;
|
|
|
21
25
|
|
|
22
26
|
function _classPrivateFieldLooseKey(name) { return "__private_" + id++ + "_" + name; }
|
|
23
27
|
|
|
28
|
+
const {
|
|
29
|
+
assign,
|
|
30
|
+
keys
|
|
31
|
+
} = Object;
|
|
32
|
+
|
|
24
33
|
const clearModule = (fP, opts) => {
|
|
25
34
|
const options = opts !== null && opts !== void 0 ? opts : {};
|
|
26
35
|
let filePath = fP;
|
|
27
36
|
|
|
28
37
|
if (!require.cache[filePath]) {
|
|
29
|
-
const
|
|
38
|
+
const dirName = (0, _path.dirname)(filePath);
|
|
30
39
|
|
|
31
|
-
for (const fn of
|
|
32
|
-
const fullPath =
|
|
40
|
+
for (const fn of (0, _fs.readdirSync)(dirName)) {
|
|
41
|
+
const fullPath = (0, _path.resolve)(dirName, fn);
|
|
33
42
|
|
|
34
43
|
if (fullPath.substr(0, filePath.length + 1) === `${filePath}.` && require.cache[fullPath]) {
|
|
35
44
|
filePath = fullPath;
|
|
@@ -73,7 +82,7 @@ const clearModule = (fP, opts) => {
|
|
|
73
82
|
do {
|
|
74
83
|
cleanup = false;
|
|
75
84
|
|
|
76
|
-
for (const fn of
|
|
85
|
+
for (const fn of keys(require.cache)) {
|
|
77
86
|
if (require.cache[fn] && require.cache[fn].id !== '.' && require.cache[fn].parent && require.cache[fn].parent.id !== '.' && !require.cache[require.cache[fn].parent.id] && !fn.match(/\/node_modules\//i) && !fn.match(/\.node$/i)) {
|
|
78
87
|
delete require.cache[fn];
|
|
79
88
|
cleanup = true;
|
|
@@ -92,14 +101,12 @@ var _handlerName = /*#__PURE__*/_classPrivateFieldLooseKey("handlerName");
|
|
|
92
101
|
|
|
93
102
|
var _handlerPath = /*#__PURE__*/_classPrivateFieldLooseKey("handlerPath");
|
|
94
103
|
|
|
95
|
-
var _handlerModuleNesting = /*#__PURE__*/_classPrivateFieldLooseKey("handlerModuleNesting");
|
|
96
|
-
|
|
97
104
|
var _timeout = /*#__PURE__*/_classPrivateFieldLooseKey("timeout");
|
|
98
105
|
|
|
99
106
|
var _allowCache = /*#__PURE__*/_classPrivateFieldLooseKey("allowCache");
|
|
100
107
|
|
|
101
108
|
class InProcessRunner {
|
|
102
|
-
constructor(functionKey, handlerPath, handlerName,
|
|
109
|
+
constructor(functionKey, handlerPath, handlerName, env, timeout, allowCache) {
|
|
103
110
|
Object.defineProperty(this, _env, {
|
|
104
111
|
writable: true,
|
|
105
112
|
value: null
|
|
@@ -116,10 +123,6 @@ class InProcessRunner {
|
|
|
116
123
|
writable: true,
|
|
117
124
|
value: null
|
|
118
125
|
});
|
|
119
|
-
Object.defineProperty(this, _handlerModuleNesting, {
|
|
120
|
-
writable: true,
|
|
121
|
-
value: null
|
|
122
|
-
});
|
|
123
126
|
Object.defineProperty(this, _timeout, {
|
|
124
127
|
writable: true,
|
|
125
128
|
value: null
|
|
@@ -132,7 +135,6 @@ class InProcessRunner {
|
|
|
132
135
|
_classPrivateFieldLooseBase(this, _functionKey)[_functionKey] = functionKey;
|
|
133
136
|
_classPrivateFieldLooseBase(this, _handlerName)[_handlerName] = handlerName;
|
|
134
137
|
_classPrivateFieldLooseBase(this, _handlerPath)[_handlerPath] = handlerPath;
|
|
135
|
-
_classPrivateFieldLooseBase(this, _handlerModuleNesting)[_handlerModuleNesting] = handlerModuleNesting;
|
|
136
138
|
_classPrivateFieldLooseBase(this, _timeout)[_timeout] = timeout;
|
|
137
139
|
_classPrivateFieldLooseBase(this, _allowCache)[_allowCache] = allowCache;
|
|
138
140
|
} // no-op
|
|
@@ -151,7 +153,7 @@ class InProcessRunner {
|
|
|
151
153
|
// e.g. process.env.foo = 1 should be coerced to '1' (string)
|
|
152
154
|
|
|
153
155
|
|
|
154
|
-
|
|
156
|
+
assign(_process.default.env, _classPrivateFieldLooseBase(this, _env)[_env]); // lazy load handler with first usage
|
|
155
157
|
|
|
156
158
|
if (!_classPrivateFieldLooseBase(this, _allowCache)[_allowCache]) {
|
|
157
159
|
clearModule(_classPrivateFieldLooseBase(this, _handlerPath)[_handlerPath], {
|
|
@@ -159,36 +161,28 @@ class InProcessRunner {
|
|
|
159
161
|
});
|
|
160
162
|
}
|
|
161
163
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
const handlerPathExport = await Promise.resolve(`${_classPrivateFieldLooseBase(this, _handlerPath)[_handlerPath]}`).then(s => _interopRequireWildcard(require(s))); // this supports handling of nested handler paths like <pathToFile>/<fileName>.object1.object2.object3.handler
|
|
166
|
-
// a use case for this, is when the handler is further down the export tree or in nested objects
|
|
167
|
-
// NOTE: this feature is supported in AWS Lambda
|
|
168
|
-
|
|
169
|
-
handler = _classPrivateFieldLooseBase(this, _handlerModuleNesting)[_handlerModuleNesting].reduce((obj, key) => obj[key], handlerPathExport);
|
|
170
|
-
} catch (error) {
|
|
171
|
-
throw new Error(`offline: one of the module nesting ${_classPrivateFieldLooseBase(this, _handlerModuleNesting)[_handlerModuleNesting]} for handler ${_classPrivateFieldLooseBase(this, _handlerName)[_handlerName]} is undefined or not exported`);
|
|
172
|
-
}
|
|
164
|
+
const {
|
|
165
|
+
[_classPrivateFieldLooseBase(this, _handlerName)[_handlerName]]: handler
|
|
166
|
+
} = await Promise.resolve(`${_classPrivateFieldLooseBase(this, _handlerPath)[_handlerPath]}`).then(s => _interopRequireWildcard(require(s)));
|
|
173
167
|
|
|
174
168
|
if (typeof handler !== 'function') {
|
|
175
169
|
throw new Error(`offline: handler '${_classPrivateFieldLooseBase(this, _handlerName)[_handlerName]}' in ${_classPrivateFieldLooseBase(this, _handlerPath)[_handlerPath]} is not a function`);
|
|
176
170
|
}
|
|
177
171
|
|
|
178
172
|
let callback;
|
|
179
|
-
const callbackCalled = new Promise((
|
|
173
|
+
const callbackCalled = new Promise((res, rej) => {
|
|
180
174
|
callback = (err, data) => {
|
|
181
175
|
if (err === 'Unauthorized') {
|
|
182
|
-
|
|
176
|
+
res('Unauthorized');
|
|
183
177
|
return;
|
|
184
178
|
}
|
|
185
179
|
|
|
186
180
|
if (err) {
|
|
187
|
-
|
|
181
|
+
rej(err);
|
|
188
182
|
return;
|
|
189
183
|
}
|
|
190
184
|
|
|
191
|
-
|
|
185
|
+
res(data);
|
|
192
186
|
};
|
|
193
187
|
});
|
|
194
188
|
|
|
@@ -7,6 +7,8 @@ exports.default = void 0;
|
|
|
7
7
|
|
|
8
8
|
var _os = require("os");
|
|
9
9
|
|
|
10
|
+
var _process = _interopRequireDefault(require("process"));
|
|
11
|
+
|
|
10
12
|
var _nodeFetch = _interopRequireDefault(require("node-fetch"));
|
|
11
13
|
|
|
12
14
|
var _javaInvokeLocal = require("java-invoke-local");
|
|
@@ -122,7 +124,7 @@ class JavaRunner {
|
|
|
122
124
|
method: 'POST',
|
|
123
125
|
body: data
|
|
124
126
|
};
|
|
125
|
-
const port =
|
|
127
|
+
const port = _process.default.env.JAVA_OFFLINE_SERVER || 8080;
|
|
126
128
|
const response = await (0, _nodeFetch.default)(`http://localhost:${port}/invoke`, httpOptions);
|
|
127
129
|
result = await response.text();
|
|
128
130
|
} catch (e) {
|
|
@@ -5,18 +5,22 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
|
+
var _child_process = require("child_process");
|
|
9
|
+
|
|
8
10
|
var _os = require("os");
|
|
9
11
|
|
|
10
12
|
var _path = require("path");
|
|
11
13
|
|
|
12
|
-
var
|
|
13
|
-
|
|
14
|
-
var _extend = _interopRequireDefault(require("extend"));
|
|
14
|
+
var _process = _interopRequireWildcard(require("process"));
|
|
15
15
|
|
|
16
16
|
var _readline = _interopRequireDefault(require("readline"));
|
|
17
17
|
|
|
18
18
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
19
|
|
|
20
|
+
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); }
|
|
21
|
+
|
|
22
|
+
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; }
|
|
23
|
+
|
|
20
24
|
function _classPrivateFieldLooseBase(receiver, privateKey) { if (!Object.prototype.hasOwnProperty.call(receiver, privateKey)) { throw new TypeError("attempted to use private field on non-instance"); } return receiver; }
|
|
21
25
|
|
|
22
26
|
var id = 0;
|
|
@@ -28,8 +32,8 @@ const {
|
|
|
28
32
|
stringify
|
|
29
33
|
} = JSON;
|
|
30
34
|
const {
|
|
31
|
-
|
|
32
|
-
} =
|
|
35
|
+
assign
|
|
36
|
+
} = Object;
|
|
33
37
|
const {
|
|
34
38
|
has
|
|
35
39
|
} = Reflect;
|
|
@@ -84,15 +88,15 @@ class PythonRunner {
|
|
|
84
88
|
this.v3Utils = v3Utils;
|
|
85
89
|
}
|
|
86
90
|
|
|
87
|
-
if (
|
|
91
|
+
if (_process.default.env.VIRTUAL_ENV) {
|
|
88
92
|
const runtimeDir = (0, _os.platform)() === 'win32' ? 'Scripts' : 'bin';
|
|
89
|
-
|
|
93
|
+
_process.default.env.PATH = [(0, _path.join)(_process.default.env.VIRTUAL_ENV, runtimeDir), _path.delimiter, _process.default.env.PATH].join('');
|
|
90
94
|
}
|
|
91
95
|
|
|
92
96
|
const [pythonExecutable] = _classPrivateFieldLooseBase(this, _runtime)[_runtime].split('.');
|
|
93
97
|
|
|
94
|
-
this.handlerProcess = (0, _child_process.spawn)(pythonExecutable, ['-u', (0, _path.resolve)(__dirname, 'invoke.py'), (0, _path.relative)(cwd(), _classPrivateFieldLooseBase(this, _handlerPath)[_handlerPath]), _classPrivateFieldLooseBase(this, _handlerName)[_handlerName]], {
|
|
95
|
-
env: (
|
|
98
|
+
this.handlerProcess = (0, _child_process.spawn)(pythonExecutable, ['-u', (0, _path.resolve)(__dirname, 'invoke.py'), (0, _path.relative)((0, _process.cwd)(), _classPrivateFieldLooseBase(this, _handlerPath)[_handlerPath]), _classPrivateFieldLooseBase(this, _handlerName)[_handlerName]], {
|
|
99
|
+
env: assign(_process.default.env, _classPrivateFieldLooseBase(this, _env)[_env]),
|
|
96
100
|
shell: true
|
|
97
101
|
});
|
|
98
102
|
this.handlerProcess.stdout.readline = _readline.default.createInterface({
|
|
@@ -168,7 +172,8 @@ class PythonRunner {
|
|
|
168
172
|
|
|
169
173
|
this.handlerProcess.stdout.readline.on('line', onLine);
|
|
170
174
|
this.handlerProcess.stderr.on('data', onErr);
|
|
171
|
-
|
|
175
|
+
|
|
176
|
+
_process.default.nextTick(() => {
|
|
172
177
|
this.handlerProcess.stdin.write(input);
|
|
173
178
|
this.handlerProcess.stdin.write('\n');
|
|
174
179
|
});
|
|
@@ -9,6 +9,8 @@ var _os = require("os");
|
|
|
9
9
|
|
|
10
10
|
var _path = require("path");
|
|
11
11
|
|
|
12
|
+
var _process = require("process");
|
|
13
|
+
|
|
12
14
|
var _execa = _interopRequireDefault(require("execa"));
|
|
13
15
|
|
|
14
16
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -23,9 +25,6 @@ const {
|
|
|
23
25
|
parse,
|
|
24
26
|
stringify
|
|
25
27
|
} = JSON;
|
|
26
|
-
const {
|
|
27
|
-
cwd
|
|
28
|
-
} = process;
|
|
29
28
|
const {
|
|
30
29
|
has
|
|
31
30
|
} = Reflect;
|
|
@@ -120,7 +119,7 @@ class RubyRunner {
|
|
|
120
119
|
allowCache: _classPrivateFieldLooseBase(this, _allowCache)[_allowCache]
|
|
121
120
|
}); // console.log(input)
|
|
122
121
|
|
|
123
|
-
const ruby = (0, _execa.default)(runtime, [(0, _path.resolve)(__dirname, 'invoke.rb'), (0, _path.relative)(cwd(), _classPrivateFieldLooseBase(this, _handlerPath)[_handlerPath]), _classPrivateFieldLooseBase(this, _handlerName)[_handlerName]], {
|
|
122
|
+
const ruby = (0, _execa.default)(runtime, [(0, _path.resolve)(__dirname, 'invoke.rb'), (0, _path.relative)((0, _process.cwd)(), _classPrivateFieldLooseBase(this, _handlerPath)[_handlerPath]), _classPrivateFieldLooseBase(this, _handlerName)[_handlerName]], {
|
|
124
123
|
env: _classPrivateFieldLooseBase(this, _env)[_env],
|
|
125
124
|
input // shell: true,
|
|
126
125
|
|
|
@@ -39,7 +39,6 @@ class WorkerThreadRunner {
|
|
|
39
39
|
functionKey,
|
|
40
40
|
handlerName,
|
|
41
41
|
handlerPath,
|
|
42
|
-
handlerModuleNesting,
|
|
43
42
|
timeout
|
|
44
43
|
} = funOptions;
|
|
45
44
|
_classPrivateFieldLooseBase(this, _allowCache)[_allowCache] = allowCache;
|
|
@@ -50,7 +49,6 @@ class WorkerThreadRunner {
|
|
|
50
49
|
functionKey,
|
|
51
50
|
handlerName,
|
|
52
51
|
handlerPath,
|
|
53
|
-
handlerModuleNesting,
|
|
54
52
|
timeout
|
|
55
53
|
}
|
|
56
54
|
});
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _process = require("process");
|
|
4
|
+
|
|
3
5
|
var _worker_threads = require("worker_threads");
|
|
4
6
|
|
|
5
7
|
var _index = _interopRequireDefault(require("../in-process-runner/index.js"));
|
|
@@ -10,8 +12,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
10
12
|
const {
|
|
11
13
|
functionKey,
|
|
12
14
|
handlerName,
|
|
13
|
-
handlerPath
|
|
14
|
-
handlerModuleNesting
|
|
15
|
+
handlerPath
|
|
15
16
|
} = _worker_threads.workerData;
|
|
16
17
|
|
|
17
18
|
_worker_threads.parentPort.on('message', async messageData => {
|
|
@@ -23,7 +24,7 @@ _worker_threads.parentPort.on('message', async messageData => {
|
|
|
23
24
|
allowCache
|
|
24
25
|
} = messageData; // TODO we could probably cache this in the module scope?
|
|
25
26
|
|
|
26
|
-
const inProcessRunner = new _index.default(functionKey, handlerPath, handlerName,
|
|
27
|
+
const inProcessRunner = new _index.default(functionKey, handlerPath, handlerName, _process.env, timeout, allowCache);
|
|
27
28
|
const result = await inProcessRunner.run(event, context); // TODO check serializeability (contains function, symbol etc)
|
|
28
29
|
|
|
29
30
|
port.postMessage(result);
|
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = generateHapiPath;
|
|
7
7
|
|
|
8
|
-
function generateHapiPath(path
|
|
8
|
+
function generateHapiPath(path, options, serverless) {
|
|
9
9
|
// path must start with '/'
|
|
10
10
|
let hapiPath = path.startsWith('/') ? path : `/${path}`;
|
|
11
11
|
|
|
@@ -7,8 +7,6 @@ exports.default = getHttpApiCorsConfig;
|
|
|
7
7
|
|
|
8
8
|
var _debugLog = _interopRequireDefault(require("../debugLog.js"));
|
|
9
9
|
|
|
10
|
-
var _serverlessLog = require("../serverlessLog.js");
|
|
11
|
-
|
|
12
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
11
|
|
|
14
12
|
function getHttpApiCorsConfig(httpApiCors, {
|
|
@@ -24,20 +22,18 @@ function getHttpApiCorsConfig(httpApiCors, {
|
|
|
24
22
|
};
|
|
25
23
|
|
|
26
24
|
if (log) {
|
|
27
|
-
log.
|
|
25
|
+
log.debug('Using CORS policy', c);
|
|
28
26
|
} else {
|
|
29
|
-
(0, _debugLog.default)(c);
|
|
30
|
-
(0, _serverlessLog.logWarning)(c);
|
|
27
|
+
(0, _debugLog.default)('Using CORS policy', c);
|
|
31
28
|
}
|
|
32
29
|
|
|
33
30
|
return c;
|
|
34
31
|
}
|
|
35
32
|
|
|
36
33
|
if (log) {
|
|
37
|
-
log.
|
|
34
|
+
log.debug('Using CORS policy', httpApiCors);
|
|
38
35
|
} else {
|
|
39
|
-
(0, _debugLog.default)(httpApiCors);
|
|
40
|
-
(0, _serverlessLog.logWarning)(httpApiCors);
|
|
36
|
+
(0, _debugLog.default)('Using CORS policy', httpApiCors);
|
|
41
37
|
}
|
|
42
38
|
|
|
43
39
|
return httpApiCors;
|
package/dist/utils/index.js
CHANGED
|
@@ -59,6 +59,12 @@ Object.defineProperty(exports, "jsonPath", {
|
|
|
59
59
|
return _jsonPath.default;
|
|
60
60
|
}
|
|
61
61
|
});
|
|
62
|
+
Object.defineProperty(exports, "lowerCaseKeys", {
|
|
63
|
+
enumerable: true,
|
|
64
|
+
get: function () {
|
|
65
|
+
return _lowerCaseKeys.default;
|
|
66
|
+
}
|
|
67
|
+
});
|
|
62
68
|
exports.nullIfEmpty = nullIfEmpty;
|
|
63
69
|
Object.defineProperty(exports, "parseHeaders", {
|
|
64
70
|
enumerable: true,
|
|
@@ -110,6 +116,8 @@ var _getHttpApiCorsConfig = _interopRequireDefault(require("./getHttpApiCorsConf
|
|
|
110
116
|
|
|
111
117
|
var _jsonPath = _interopRequireDefault(require("./jsonPath.js"));
|
|
112
118
|
|
|
119
|
+
var _lowerCaseKeys = _interopRequireDefault(require("./lowerCaseKeys.js"));
|
|
120
|
+
|
|
113
121
|
var _parseHeaders = _interopRequireDefault(require("./parseHeaders.js"));
|
|
114
122
|
|
|
115
123
|
var _parseMultiValueHeaders = _interopRequireDefault(require("./parseMultiValueHeaders.js"));
|
|
@@ -130,16 +138,15 @@ var _generateHapiPath = _interopRequireDefault(require("./generateHapiPath.js"))
|
|
|
130
138
|
|
|
131
139
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
132
140
|
|
|
141
|
+
// export { default as baseImage } from './baseImage.js'
|
|
133
142
|
const {
|
|
134
143
|
isArray
|
|
135
144
|
} = Array;
|
|
136
145
|
const {
|
|
137
146
|
keys
|
|
138
|
-
} = Object;
|
|
139
|
-
|
|
140
|
-
// export { default as baseImage } from './baseImage.js'
|
|
141
|
-
// Detect the toString encoding from the request headers content-type
|
|
147
|
+
} = Object; // Detect the toString encoding from the request headers content-type
|
|
142
148
|
// enhance if further content types need to be non utf8 encoded.
|
|
149
|
+
|
|
143
150
|
function detectEncoding(request) {
|
|
144
151
|
const contentType = request.headers['content-type'];
|
|
145
152
|
return typeof contentType === 'string' && contentType.includes('multipart/form-data') ? 'binary' : 'utf8';
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = parseHeaders;
|
|
7
|
+
const {
|
|
8
|
+
entries,
|
|
9
|
+
fromEntries
|
|
10
|
+
} = Object; // (obj: { [string]: string }): { [Lowercase<string>]: string }
|
|
11
|
+
|
|
12
|
+
function parseHeaders(obj) {
|
|
13
|
+
return fromEntries(entries(obj).map(([k, v]) => [k.toLowerCase(), v]));
|
|
14
|
+
}
|
|
@@ -4,15 +4,17 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = resolveJoins;
|
|
7
|
+
const {
|
|
8
|
+
keys
|
|
9
|
+
} = Object; // Used to resolve Fn::Join in environment variables
|
|
7
10
|
|
|
8
|
-
// Used to resolve Fn::Join in environment variables
|
|
9
11
|
function resolveJoins(environment) {
|
|
10
12
|
if (!environment) {
|
|
11
13
|
return undefined;
|
|
12
14
|
}
|
|
13
15
|
|
|
14
16
|
const newEnv = {};
|
|
15
|
-
|
|
17
|
+
keys(environment).forEach(key => {
|
|
16
18
|
const value = environment[key];
|
|
17
19
|
|
|
18
20
|
if (!value) {
|