serverless-offline 8.8.1 → 9.0.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 +3 -3
- package/package.json +33 -57
- package/src/ServerlessOffline.js +412 -0
- package/src/config/commandOptions.js +155 -0
- package/src/config/constants.js +22 -0
- package/{dist → src}/config/defaultOptions.js +8 -17
- package/src/config/index.js +4 -0
- package/src/config/supportedRuntimes.js +47 -0
- package/src/events/authCanExecuteResource.js +35 -0
- package/src/events/authFunctionNameExtractor.js +75 -0
- package/src/events/authMatchPolicyResource.js +71 -0
- package/src/events/authValidateContext.js +51 -0
- package/src/events/http/Endpoint.js +135 -0
- package/src/events/http/Http.js +50 -0
- package/src/events/http/HttpEventDefinition.js +20 -0
- package/src/events/http/HttpServer.js +1277 -0
- package/src/events/http/OfflineEndpoint.js +33 -0
- package/src/events/http/authJWTSettingsExtractor.js +70 -0
- package/src/events/http/createAuthScheme.js +176 -0
- package/src/events/http/createJWTAuthScheme.js +106 -0
- package/src/events/http/index.js +1 -0
- package/src/events/http/javaHelpers.js +102 -0
- package/src/events/http/lambda-events/LambdaIntegrationEvent.js +57 -0
- package/src/events/http/lambda-events/LambdaProxyIntegrationEvent.js +233 -0
- package/src/events/http/lambda-events/LambdaProxyIntegrationEventV2.js +190 -0
- package/src/events/http/lambda-events/VelocityContext.js +147 -0
- package/src/events/http/lambda-events/index.js +4 -0
- package/src/events/http/lambda-events/renderVelocityTemplateObject.js +93 -0
- package/{dist → src}/events/http/parseResources.js +73 -78
- package/src/events/http/payloadSchemaValidator.js +13 -0
- package/{dist → src}/events/http/templates/offline-default.req.vm +0 -0
- package/{dist → src}/events/http/templates/offline-default.res.vm +0 -0
- package/src/events/schedule/Schedule.js +131 -0
- package/src/events/schedule/ScheduleEvent.js +18 -0
- package/src/events/schedule/ScheduleEventDefinition.js +21 -0
- package/src/events/schedule/index.js +1 -0
- package/src/events/websocket/HttpServer.js +69 -0
- package/src/events/websocket/WebSocket.js +52 -0
- package/src/events/websocket/WebSocketClients.js +462 -0
- package/src/events/websocket/WebSocketEventDefinition.js +18 -0
- package/src/events/websocket/WebSocketServer.js +73 -0
- package/src/events/websocket/http-routes/_catchAll/catchAllRoute.js +16 -0
- package/src/events/websocket/http-routes/_catchAll/index.js +1 -0
- package/src/events/websocket/http-routes/connections/ConnectionsController.js +28 -0
- package/src/events/websocket/http-routes/connections/connectionsRoutes.js +70 -0
- package/src/events/websocket/http-routes/connections/index.js +1 -0
- package/src/events/websocket/http-routes/index.js +2 -0
- package/src/events/websocket/index.js +1 -0
- package/src/events/websocket/lambda-events/WebSocketAuthorizerEvent.js +65 -0
- package/src/events/websocket/lambda-events/WebSocketConnectEvent.js +68 -0
- package/src/events/websocket/lambda-events/WebSocketDisconnectEvent.js +31 -0
- package/src/events/websocket/lambda-events/WebSocketEvent.js +29 -0
- package/src/events/websocket/lambda-events/WebSocketRequestContext.js +67 -0
- package/src/events/websocket/lambda-events/index.js +4 -0
- package/src/index.js +12 -0
- package/src/lambda/HttpServer.js +108 -0
- package/src/lambda/Lambda.js +68 -0
- package/src/lambda/LambdaContext.js +33 -0
- package/src/lambda/LambdaFunction.js +308 -0
- package/src/lambda/LambdaFunctionPool.js +109 -0
- package/src/lambda/__tests__/LambdaContext.test.js +30 -0
- package/src/lambda/__tests__/LambdaFunction.test.js +196 -0
- package/src/lambda/__tests__/fixtures/Lambda/LambdaFunctionThatReturnsJSONObject.fixture.js +47 -0
- package/src/lambda/__tests__/fixtures/Lambda/LambdaFunctionThatReturnsNativeString.fixture.js +46 -0
- package/src/lambda/__tests__/fixtures/Lambda/package.json +3 -0
- package/src/lambda/__tests__/fixtures/lambdaFunction.fixture.js +145 -0
- package/src/lambda/__tests__/fixtures/package.json +3 -0
- package/src/lambda/__tests__/routes/invocations/InvocationsController.test.js +42 -0
- package/src/lambda/handler-runner/HandlerRunner.js +136 -0
- package/src/lambda/handler-runner/child-process-runner/ChildProcessRunner.js +72 -0
- package/src/lambda/handler-runner/child-process-runner/childProcessHelper.js +42 -0
- package/src/lambda/handler-runner/child-process-runner/index.js +1 -0
- package/src/lambda/handler-runner/docker-runner/DockerContainer.js +417 -0
- package/src/lambda/handler-runner/docker-runner/DockerImage.js +35 -0
- package/src/lambda/handler-runner/docker-runner/DockerRunner.js +63 -0
- package/src/lambda/handler-runner/docker-runner/index.js +1 -0
- package/src/lambda/handler-runner/go-runner/GoRunner.js +166 -0
- package/src/lambda/handler-runner/go-runner/index.js +1 -0
- package/src/lambda/handler-runner/in-process-runner/InProcessRunner.js +125 -0
- package/src/lambda/handler-runner/in-process-runner/index.js +1 -0
- package/src/lambda/handler-runner/index.js +1 -0
- package/src/lambda/handler-runner/java-runner/JavaRunner.js +114 -0
- package/src/lambda/handler-runner/java-runner/index.js +1 -0
- package/src/lambda/handler-runner/python-runner/PythonRunner.js +138 -0
- package/src/lambda/handler-runner/python-runner/index.js +1 -0
- package/{dist → src}/lambda/handler-runner/python-runner/invoke.py +0 -0
- package/src/lambda/handler-runner/ruby-runner/RubyRunner.js +107 -0
- package/src/lambda/handler-runner/ruby-runner/index.js +1 -0
- package/{dist → src}/lambda/handler-runner/ruby-runner/invoke.rb +0 -0
- package/src/lambda/handler-runner/worker-thread-runner/WorkerThreadRunner.js +70 -0
- package/src/lambda/handler-runner/worker-thread-runner/index.js +1 -0
- package/src/lambda/handler-runner/worker-thread-runner/workerThreadHelper.js +29 -0
- package/src/lambda/index.js +1 -0
- package/src/lambda/routes/index.js +2 -0
- package/src/lambda/routes/invocations/InvocationsController.js +102 -0
- package/src/lambda/routes/invocations/index.js +1 -0
- package/src/lambda/routes/invocations/invocationsRoute.js +77 -0
- package/src/lambda/routes/invoke-async/InvokeAsyncController.js +20 -0
- package/src/lambda/routes/invoke-async/index.js +1 -0
- package/src/lambda/routes/invoke-async/invokeAsyncRoute.js +33 -0
- package/src/utils/__tests__/createUniqueId.test.js +18 -0
- package/src/utils/__tests__/formatToClfTime.test.js +14 -0
- package/src/utils/__tests__/generateHapiPath.test.js +46 -0
- package/src/utils/__tests__/lowerCaseKeys.test.js +30 -0
- package/src/utils/__tests__/parseHeaders.test.js +13 -0
- package/src/utils/__tests__/parseMultiValueHeaders.test.js +24 -0
- package/src/utils/__tests__/parseMultiValueQueryStringParameters.test.js +159 -0
- package/src/utils/__tests__/parseQueryStringParameters.test.js +15 -0
- package/src/utils/__tests__/splitHandlerPathAndName.test.js +54 -0
- package/src/utils/__tests__/unflatten.test.js +32 -0
- package/src/utils/checkDockerDaemon.js +19 -0
- package/src/utils/checkGoVersion.js +16 -0
- package/src/utils/createApiKey.js +5 -0
- package/src/utils/createUniqueId.js +5 -0
- package/src/utils/detectExecutable.js +11 -0
- package/{dist → src}/utils/formatToClfTime.js +6 -14
- package/src/utils/generateHapiPath.js +26 -0
- package/src/utils/getHttpApiCorsConfig.js +28 -0
- package/src/utils/index.js +42 -0
- package/src/utils/jsonPath.js +13 -0
- package/src/utils/logRoutes.js +64 -0
- package/src/utils/lowerCaseKeys.js +6 -0
- package/src/utils/parseHeaders.js +14 -0
- package/src/utils/parseMultiValueHeaders.js +27 -0
- package/src/utils/parseMultiValueQueryStringParameters.js +31 -0
- package/src/utils/parseQueryStringParameters.js +15 -0
- package/src/utils/resolveJoins.js +29 -0
- package/src/utils/splitHandlerPathAndName.js +31 -0
- package/src/utils/unflatten.js +11 -0
- package/CHANGELOG.md +0 -78
- package/dist/ServerlessOffline.js +0 -508
- package/dist/config/commandOptions.js +0 -149
- package/dist/config/constants.js +0 -30
- package/dist/config/index.js +0 -55
- package/dist/config/supportedRuntimes.js +0 -40
- package/dist/debugLog.js +0 -12
- package/dist/events/authCanExecuteResource.js +0 -35
- package/dist/events/authFunctionNameExtractor.js +0 -87
- package/dist/events/authMatchPolicyResource.js +0 -62
- package/dist/events/authValidateContext.js +0 -53
- package/dist/events/http/Endpoint.js +0 -173
- package/dist/events/http/Http.js +0 -77
- package/dist/events/http/HttpEventDefinition.js +0 -36
- package/dist/events/http/HttpServer.js +0 -1370
- package/dist/events/http/OfflineEndpoint.js +0 -38
- package/dist/events/http/authJWTSettingsExtractor.js +0 -76
- package/dist/events/http/createAuthScheme.js +0 -184
- package/dist/events/http/createJWTAuthScheme.js +0 -159
- package/dist/events/http/index.js +0 -15
- package/dist/events/http/javaHelpers.js +0 -99
- package/dist/events/http/lambda-events/LambdaIntegrationEvent.js +0 -87
- package/dist/events/http/lambda-events/LambdaProxyIntegrationEvent.js +0 -246
- package/dist/events/http/lambda-events/LambdaProxyIntegrationEventV2.js +0 -225
- package/dist/events/http/lambda-events/VelocityContext.js +0 -170
- package/dist/events/http/lambda-events/index.js +0 -39
- package/dist/events/http/lambda-events/renderVelocityTemplateObject.js +0 -111
- package/dist/events/http/payloadSchemaValidator.js +0 -13
- package/dist/events/schedule/Schedule.js +0 -183
- package/dist/events/schedule/ScheduleEvent.js +0 -27
- package/dist/events/schedule/ScheduleEventDefinition.js +0 -36
- package/dist/events/schedule/index.js +0 -15
- package/dist/events/websocket/HttpServer.js +0 -114
- package/dist/events/websocket/WebSocket.js +0 -78
- package/dist/events/websocket/WebSocketClients.js +0 -577
- package/dist/events/websocket/WebSocketEventDefinition.js +0 -32
- package/dist/events/websocket/WebSocketServer.js +0 -139
- package/dist/events/websocket/http-routes/_catchAll/catchAllRoute.js +0 -33
- package/dist/events/websocket/http-routes/_catchAll/index.js +0 -15
- package/dist/events/websocket/http-routes/connections/ConnectionsController.js +0 -45
- package/dist/events/websocket/http-routes/connections/connectionsRoutes.js +0 -95
- package/dist/events/websocket/http-routes/connections/index.js +0 -15
- package/dist/events/websocket/http-routes/index.js +0 -23
- package/dist/events/websocket/index.js +0 -15
- package/dist/events/websocket/lambda-events/WebSocketAuthorizerEvent.js +0 -99
- package/dist/events/websocket/lambda-events/WebSocketConnectEvent.js +0 -101
- package/dist/events/websocket/lambda-events/WebSocketDisconnectEvent.js +0 -47
- package/dist/events/websocket/lambda-events/WebSocketEvent.js +0 -54
- package/dist/events/websocket/lambda-events/WebSocketRequestContext.js +0 -98
- package/dist/events/websocket/lambda-events/index.js +0 -39
- package/dist/index.js +0 -15
- package/dist/lambda/HttpServer.js +0 -124
- package/dist/lambda/Lambda.js +0 -117
- package/dist/lambda/LambdaContext.js +0 -53
- package/dist/lambda/LambdaFunction.js +0 -390
- package/dist/lambda/LambdaFunctionPool.js +0 -127
- package/dist/lambda/handler-runner/HandlerRunner.js +0 -195
- package/dist/lambda/handler-runner/child-process-runner/ChildProcessRunner.js +0 -124
- package/dist/lambda/handler-runner/child-process-runner/childProcessHelper.js +0 -49
- package/dist/lambda/handler-runner/child-process-runner/index.js +0 -15
- package/dist/lambda/handler-runner/docker-runner/DockerContainer.js +0 -515
- package/dist/lambda/handler-runner/docker-runner/DockerImage.js +0 -67
- package/dist/lambda/handler-runner/docker-runner/DockerRunner.js +0 -74
- package/dist/lambda/handler-runner/docker-runner/index.js +0 -15
- package/dist/lambda/handler-runner/go-runner/GoRunner.js +0 -230
- package/dist/lambda/handler-runner/go-runner/index.js +0 -15
- package/dist/lambda/handler-runner/in-process-runner/InProcessRunner.js +0 -228
- package/dist/lambda/handler-runner/in-process-runner/index.js +0 -15
- package/dist/lambda/handler-runner/index.js +0 -15
- package/dist/lambda/handler-runner/java-runner/JavaRunner.js +0 -153
- package/dist/lambda/handler-runner/java-runner/index.js +0 -15
- package/dist/lambda/handler-runner/python-runner/PythonRunner.js +0 -185
- package/dist/lambda/handler-runner/python-runner/index.js +0 -15
- package/dist/lambda/handler-runner/ruby-runner/RubyRunner.js +0 -147
- package/dist/lambda/handler-runner/ruby-runner/index.js +0 -15
- package/dist/lambda/handler-runner/worker-thread-runner/WorkerThreadRunner.js +0 -92
- package/dist/lambda/handler-runner/worker-thread-runner/index.js +0 -15
- package/dist/lambda/handler-runner/worker-thread-runner/workerThreadHelper.js +0 -31
- package/dist/lambda/index.js +0 -15
- package/dist/lambda/routes/index.js +0 -23
- package/dist/lambda/routes/invocations/InvocationsController.js +0 -142
- package/dist/lambda/routes/invocations/index.js +0 -15
- package/dist/lambda/routes/invocations/invocationsRoute.js +0 -90
- package/dist/lambda/routes/invoke-async/InvokeAsyncController.js +0 -38
- package/dist/lambda/routes/invoke-async/index.js +0 -15
- package/dist/lambda/routes/invoke-async/invokeAsyncRoute.js +0 -43
- package/dist/main.js +0 -11
- package/dist/serverlessLog.js +0 -91
- package/dist/utils/checkDockerDaemon.js +0 -27
- package/dist/utils/checkGoVersion.js +0 -27
- package/dist/utils/createApiKey.js +0 -12
- package/dist/utils/createUniqueId.js +0 -14
- package/dist/utils/detectExecutable.js +0 -21
- package/dist/utils/generateHapiPath.js +0 -28
- package/dist/utils/getHttpApiCorsConfig.js +0 -40
- package/dist/utils/index.js +0 -165
- package/dist/utils/jsonPath.js +0 -21
- package/dist/utils/lowerCaseKeys.js +0 -14
- package/dist/utils/parseHeaders.js +0 -23
- package/dist/utils/parseMultiValueHeaders.js +0 -36
- package/dist/utils/parseMultiValueQueryStringParameters.js +0 -40
- package/dist/utils/parseQueryStringParameters.js +0 -26
- package/dist/utils/resolveJoins.js +0 -36
- package/dist/utils/satisfiesVersionRange.js +0 -20
- package/dist/utils/splitHandlerPathAndName.js +0 -37
- package/dist/utils/unflatten.js +0 -18
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = renderVelocityTemplateObject;
|
|
7
|
-
|
|
8
|
-
var _velocityjs = require("velocityjs");
|
|
9
|
-
|
|
10
|
-
var _javaHelpers = _interopRequireDefault(require("../javaHelpers.js"));
|
|
11
|
-
|
|
12
|
-
var _debugLog = _interopRequireDefault(require("../../../debugLog.js"));
|
|
13
|
-
|
|
14
|
-
var _index = require("../../../utils/index.js");
|
|
15
|
-
|
|
16
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
|
-
|
|
18
|
-
const {
|
|
19
|
-
parse
|
|
20
|
-
} = JSON;
|
|
21
|
-
const {
|
|
22
|
-
entries
|
|
23
|
-
} = Object;
|
|
24
|
-
|
|
25
|
-
function tryToParseJSON(string) {
|
|
26
|
-
let parsed;
|
|
27
|
-
|
|
28
|
-
try {
|
|
29
|
-
parsed = parse(string);
|
|
30
|
-
} catch (err) {// nothing! Some things are not meant to be parsed.
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
return parsed || string;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function renderVelocityString(velocityString, context, v3Utils) {
|
|
37
|
-
const log = v3Utils && v3Utils.log; // runs in a "polluted" (extended) String.prototype replacement scope
|
|
38
|
-
|
|
39
|
-
const renderResult = (0, _javaHelpers.default)(() => // This line can throw, but this function does not handle errors
|
|
40
|
-
// Quick args explanation:
|
|
41
|
-
// { escape: false } --> otherwise would escape &, < and > chars with html (&, < and >)
|
|
42
|
-
// render(context, null, true) --> null: no custom macros; true: silent mode, just like APIG
|
|
43
|
-
new _velocityjs.Compile((0, _velocityjs.parse)(velocityString), {
|
|
44
|
-
escape: false
|
|
45
|
-
}).render(context, null, true));
|
|
46
|
-
|
|
47
|
-
if (log) {
|
|
48
|
-
log.debug('Velocity rendered:', renderResult || 'undefined');
|
|
49
|
-
} else {
|
|
50
|
-
(0, _debugLog.default)('Velocity rendered:', renderResult || 'undefined');
|
|
51
|
-
} // Haaaa Velocity... this language sure loves strings a lot
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
switch (renderResult) {
|
|
55
|
-
case 'undefined':
|
|
56
|
-
return undefined;
|
|
57
|
-
// But we don't, we want JavaScript types
|
|
58
|
-
|
|
59
|
-
case 'null':
|
|
60
|
-
return null;
|
|
61
|
-
|
|
62
|
-
case 'true':
|
|
63
|
-
return true;
|
|
64
|
-
|
|
65
|
-
case 'false':
|
|
66
|
-
return false;
|
|
67
|
-
|
|
68
|
-
default:
|
|
69
|
-
return tryToParseJSON(renderResult);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
/*
|
|
73
|
-
Deeply traverses a Serverless-style JSON (Velocity) template
|
|
74
|
-
When it finds a string, assumes it's Velocity language and renders it.
|
|
75
|
-
*/
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
function renderVelocityTemplateObject(templateObject, context, v3Utils) {
|
|
79
|
-
const result = {};
|
|
80
|
-
const log = v3Utils && v3Utils.log;
|
|
81
|
-
let toProcess = templateObject; // In some projects, the template object is a string, let us see if it's JSON
|
|
82
|
-
|
|
83
|
-
if (typeof toProcess === 'string') {
|
|
84
|
-
toProcess = tryToParseJSON(toProcess);
|
|
85
|
-
} // Let's check again
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
if ((0, _index.isPlainObject)(toProcess)) {
|
|
89
|
-
entries(toProcess).forEach(([key, value]) => {
|
|
90
|
-
if (log) {
|
|
91
|
-
log.debug('Processing key:', key, '- value:', value);
|
|
92
|
-
} else {
|
|
93
|
-
(0, _debugLog.default)('Processing key:', key, '- value:', value);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
if (typeof value === 'string') {
|
|
97
|
-
result[key] = renderVelocityString(value, context, v3Utils); // Go deeper
|
|
98
|
-
} else if ((0, _index.isPlainObject)(value)) {
|
|
99
|
-
result[key] = renderVelocityTemplateObject(value, context); // This should never happen: value should either be a string or a plain object
|
|
100
|
-
} else {
|
|
101
|
-
result[key] = value;
|
|
102
|
-
}
|
|
103
|
-
}); // Still a string? Maybe it's some complex Velocity stuff
|
|
104
|
-
} else if (typeof toProcess === 'string') {
|
|
105
|
-
// If the plugin threw here then you should consider reviewing your template or posting an issue.
|
|
106
|
-
const alternativeResult = tryToParseJSON(renderVelocityString(toProcess, context, v3Utils));
|
|
107
|
-
return (0, _index.isPlainObject)(alternativeResult) ? alternativeResult : result;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
return result;
|
|
111
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const {
|
|
4
|
-
validate: validateJsonSchema
|
|
5
|
-
} = require('jsonschema');
|
|
6
|
-
|
|
7
|
-
exports.validate = function validate(model, body) {
|
|
8
|
-
const result = validateJsonSchema(body, model);
|
|
9
|
-
|
|
10
|
-
if (result.errors.length > 0) {
|
|
11
|
-
throw new Error(`Request body validation failed: ${result.errors.map(e => e.message).join(', ')}`);
|
|
12
|
-
}
|
|
13
|
-
};
|
|
@@ -1,183 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _nodeSchedule = _interopRequireDefault(require("node-schedule"));
|
|
9
|
-
|
|
10
|
-
var _ScheduleEvent = _interopRequireDefault(require("./ScheduleEvent.js"));
|
|
11
|
-
|
|
12
|
-
var _ScheduleEventDefinition = _interopRequireDefault(require("./ScheduleEventDefinition.js"));
|
|
13
|
-
|
|
14
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
-
|
|
16
|
-
function _classPrivateFieldLooseBase(receiver, privateKey) { if (!Object.prototype.hasOwnProperty.call(receiver, privateKey)) { throw new TypeError("attempted to use private field on non-instance"); } return receiver; }
|
|
17
|
-
|
|
18
|
-
var id = 0;
|
|
19
|
-
|
|
20
|
-
function _classPrivateFieldLooseKey(name) { return "__private_" + id++ + "_" + name; }
|
|
21
|
-
|
|
22
|
-
const CRON_LENGTH_WITH_YEAR = 6;
|
|
23
|
-
const {
|
|
24
|
-
stringify
|
|
25
|
-
} = JSON;
|
|
26
|
-
|
|
27
|
-
var _lambda = /*#__PURE__*/_classPrivateFieldLooseKey("lambda");
|
|
28
|
-
|
|
29
|
-
var _region = /*#__PURE__*/_classPrivateFieldLooseKey("region");
|
|
30
|
-
|
|
31
|
-
class Schedule {
|
|
32
|
-
constructor(lambda, region, v3Utils) {
|
|
33
|
-
Object.defineProperty(this, _lambda, {
|
|
34
|
-
writable: true,
|
|
35
|
-
value: null
|
|
36
|
-
});
|
|
37
|
-
Object.defineProperty(this, _region, {
|
|
38
|
-
writable: true,
|
|
39
|
-
value: null
|
|
40
|
-
});
|
|
41
|
-
_classPrivateFieldLooseBase(this, _lambda)[_lambda] = lambda;
|
|
42
|
-
_classPrivateFieldLooseBase(this, _region)[_region] = region;
|
|
43
|
-
|
|
44
|
-
if (v3Utils) {
|
|
45
|
-
this.log = v3Utils.log;
|
|
46
|
-
this.progress = v3Utils.progress;
|
|
47
|
-
this.writeText = v3Utils.writeText;
|
|
48
|
-
this.v3Utils = v3Utils;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
_scheduleEvent(functionKey, scheduleEvent) {
|
|
53
|
-
const {
|
|
54
|
-
enabled,
|
|
55
|
-
input,
|
|
56
|
-
rate
|
|
57
|
-
} = scheduleEvent;
|
|
58
|
-
|
|
59
|
-
if (!enabled) {
|
|
60
|
-
if (this.log) {
|
|
61
|
-
this.log.notice(`Scheduling [${functionKey}] cron: disabled`);
|
|
62
|
-
} else {
|
|
63
|
-
console.log(`Scheduling [${functionKey}] cron: disabled`);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
return;
|
|
67
|
-
} // Convert string rate to array to support Serverless v2.57.0 and lower.
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
let rates = rate;
|
|
71
|
-
|
|
72
|
-
if (typeof rate === 'string') {
|
|
73
|
-
rates = [rate];
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
rates.forEach(entry => {
|
|
77
|
-
const cron = this._convertExpressionToCron(entry);
|
|
78
|
-
|
|
79
|
-
if (this.log) {
|
|
80
|
-
this.log.notice(`Scheduling [${functionKey}] cron: [${cron}] input: ${stringify(input)}`);
|
|
81
|
-
} else {
|
|
82
|
-
console.log(`Scheduling [${functionKey}] cron: [${cron}] input: ${stringify(input)}`);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
_nodeSchedule.default.scheduleJob(cron, async () => {
|
|
86
|
-
try {
|
|
87
|
-
const lambdaFunction = _classPrivateFieldLooseBase(this, _lambda)[_lambda].get(functionKey);
|
|
88
|
-
|
|
89
|
-
const event = input !== null && input !== void 0 ? input : new _ScheduleEvent.default(_classPrivateFieldLooseBase(this, _region)[_region]);
|
|
90
|
-
lambdaFunction.setEvent(event);
|
|
91
|
-
/* const result = */
|
|
92
|
-
|
|
93
|
-
await lambdaFunction.runHandler();
|
|
94
|
-
|
|
95
|
-
if (this.log) {
|
|
96
|
-
this.log.notice(`Successfully invoked scheduled function: [${functionKey}]`);
|
|
97
|
-
} else {
|
|
98
|
-
console.log(`Successfully invoked scheduled function: [${functionKey}]`);
|
|
99
|
-
}
|
|
100
|
-
} catch (err) {
|
|
101
|
-
if (this.log) {
|
|
102
|
-
this.log.error(`Failed to execute scheduled function: [${functionKey}] Error: ${err}`);
|
|
103
|
-
} else {
|
|
104
|
-
console.log(`Failed to execute scheduled function: [${functionKey}] Error: ${err}`);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
_convertCronSyntax(cronString) {
|
|
112
|
-
if (cronString.split(' ').length < CRON_LENGTH_WITH_YEAR) {
|
|
113
|
-
return cronString;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
return cronString.replace(/\s\S+$/, '');
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
_convertRateToCron(rate) {
|
|
120
|
-
const [number, unit] = rate.split(' ');
|
|
121
|
-
|
|
122
|
-
switch (unit) {
|
|
123
|
-
case 'minute':
|
|
124
|
-
case 'minutes':
|
|
125
|
-
return `*/${number} * * * *`;
|
|
126
|
-
|
|
127
|
-
case 'hour':
|
|
128
|
-
case 'hours':
|
|
129
|
-
return `0 */${number} * * *`;
|
|
130
|
-
|
|
131
|
-
case 'day':
|
|
132
|
-
case 'days':
|
|
133
|
-
return `0 0 */${number} * *`;
|
|
134
|
-
|
|
135
|
-
default:
|
|
136
|
-
if (this.log) {
|
|
137
|
-
this.log.error(`scheduler: Invalid rate syntax '${rate}', will not schedule`);
|
|
138
|
-
} else {
|
|
139
|
-
console.log(`scheduler: Invalid rate syntax '${rate}', will not schedule`);
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
return null;
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
_convertExpressionToCron(scheduleEvent) {
|
|
147
|
-
const params = scheduleEvent.replace('rate(', '').replace('cron(', '').replace(')', '');
|
|
148
|
-
|
|
149
|
-
if (scheduleEvent.startsWith('cron(')) {
|
|
150
|
-
return this._convertCronSyntax(params);
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
if (scheduleEvent.startsWith('rate(')) {
|
|
154
|
-
return this._convertRateToCron(params);
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
if (this.log) {
|
|
158
|
-
this.log.error('scheduler: invalid, schedule syntax');
|
|
159
|
-
} else {
|
|
160
|
-
console.log('scheduler: invalid, schedule syntax');
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
return undefined;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
_create(functionKey, rawScheduleEventDefinition) {
|
|
167
|
-
const scheduleEvent = new _ScheduleEventDefinition.default(rawScheduleEventDefinition);
|
|
168
|
-
|
|
169
|
-
this._scheduleEvent(functionKey, scheduleEvent);
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
create(events) {
|
|
173
|
-
events.forEach(({
|
|
174
|
-
functionKey,
|
|
175
|
-
schedule
|
|
176
|
-
}) => {
|
|
177
|
-
this._create(functionKey, schedule);
|
|
178
|
-
});
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
exports.default = Schedule;
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _index = require("../../utils/index.js");
|
|
9
|
-
|
|
10
|
-
class ScheduleEvent {
|
|
11
|
-
constructor(region) {
|
|
12
|
-
// format of aws displaying the time, e.g.: 2020-02-09T14:13:57Z
|
|
13
|
-
const time = new Date().toISOString().replace(/\.(.*)(?=Z)/g, '');
|
|
14
|
-
this.account = (0, _index.createUniqueId)();
|
|
15
|
-
this.detail = {};
|
|
16
|
-
this['detail-type'] = 'Scheduled Event';
|
|
17
|
-
this.id = (0, _index.createUniqueId)();
|
|
18
|
-
this.region = region;
|
|
19
|
-
this.resources = [];
|
|
20
|
-
this.source = 'aws.events';
|
|
21
|
-
this.time = time;
|
|
22
|
-
this.version = '0';
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
exports.default = ScheduleEvent;
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
const {
|
|
8
|
-
assign
|
|
9
|
-
} = Object;
|
|
10
|
-
|
|
11
|
-
class ScheduleEventDefinition {
|
|
12
|
-
constructor(rawHttpEventDefinition) {
|
|
13
|
-
let enabled;
|
|
14
|
-
let rate;
|
|
15
|
-
let rest;
|
|
16
|
-
|
|
17
|
-
if (typeof rawHttpEventDefinition === 'string') {
|
|
18
|
-
rate = rawHttpEventDefinition;
|
|
19
|
-
} else {
|
|
20
|
-
;
|
|
21
|
-
({
|
|
22
|
-
rate,
|
|
23
|
-
enabled,
|
|
24
|
-
...rest
|
|
25
|
-
} = rawHttpEventDefinition);
|
|
26
|
-
} // enabled: true (default)
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
this.enabled = enabled == null ? true : enabled;
|
|
30
|
-
this.rate = rate;
|
|
31
|
-
assign(this, rest);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
exports.default = ScheduleEventDefinition;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
Object.defineProperty(exports, "default", {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: function () {
|
|
9
|
-
return _Schedule.default;
|
|
10
|
-
}
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
var _Schedule = _interopRequireDefault(require("./Schedule.js"));
|
|
14
|
-
|
|
15
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _process = require("process");
|
|
9
|
-
|
|
10
|
-
var _hapi = require("@hapi/hapi");
|
|
11
|
-
|
|
12
|
-
var _index = require("./http-routes/index.js");
|
|
13
|
-
|
|
14
|
-
var _serverlessLog = _interopRequireDefault(require("../../serverlessLog.js"));
|
|
15
|
-
|
|
16
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
|
-
|
|
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
|
-
|
|
20
|
-
var id = 0;
|
|
21
|
-
|
|
22
|
-
function _classPrivateFieldLooseKey(name) { return "__private_" + id++ + "_" + name; }
|
|
23
|
-
|
|
24
|
-
var _options = /*#__PURE__*/_classPrivateFieldLooseKey("options");
|
|
25
|
-
|
|
26
|
-
var _server = /*#__PURE__*/_classPrivateFieldLooseKey("server");
|
|
27
|
-
|
|
28
|
-
var _webSocketClients = /*#__PURE__*/_classPrivateFieldLooseKey("webSocketClients");
|
|
29
|
-
|
|
30
|
-
class HttpServer {
|
|
31
|
-
constructor(options, webSocketClients, v3Utils) {
|
|
32
|
-
Object.defineProperty(this, _options, {
|
|
33
|
-
writable: true,
|
|
34
|
-
value: null
|
|
35
|
-
});
|
|
36
|
-
Object.defineProperty(this, _server, {
|
|
37
|
-
writable: true,
|
|
38
|
-
value: null
|
|
39
|
-
});
|
|
40
|
-
Object.defineProperty(this, _webSocketClients, {
|
|
41
|
-
writable: true,
|
|
42
|
-
value: null
|
|
43
|
-
});
|
|
44
|
-
_classPrivateFieldLooseBase(this, _options)[_options] = options;
|
|
45
|
-
_classPrivateFieldLooseBase(this, _webSocketClients)[_webSocketClients] = webSocketClients;
|
|
46
|
-
|
|
47
|
-
if (v3Utils) {
|
|
48
|
-
this.log = v3Utils.log;
|
|
49
|
-
this.progress = v3Utils.progress;
|
|
50
|
-
this.writeText = v3Utils.writeText;
|
|
51
|
-
this.v3Utils = v3Utils;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const {
|
|
55
|
-
host,
|
|
56
|
-
websocketPort
|
|
57
|
-
} = options;
|
|
58
|
-
const serverOptions = {
|
|
59
|
-
host,
|
|
60
|
-
port: websocketPort,
|
|
61
|
-
router: {
|
|
62
|
-
// allows for paths with trailing slashes to be the same as without
|
|
63
|
-
// e.g. : /my-path is the same as /my-path/
|
|
64
|
-
stripTrailingSlash: true
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
_classPrivateFieldLooseBase(this, _server)[_server] = new _hapi.Server(serverOptions);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
async start() {
|
|
71
|
-
// add routes
|
|
72
|
-
const routes = [...(0, _index.connectionsRoutes)(_classPrivateFieldLooseBase(this, _webSocketClients)[_webSocketClients], this.v3Utils), (0, _index.catchAllRoute)(this.v3Utils)];
|
|
73
|
-
|
|
74
|
-
_classPrivateFieldLooseBase(this, _server)[_server].route(routes);
|
|
75
|
-
|
|
76
|
-
const {
|
|
77
|
-
host,
|
|
78
|
-
httpsProtocol,
|
|
79
|
-
websocketPort
|
|
80
|
-
} = _classPrivateFieldLooseBase(this, _options)[_options];
|
|
81
|
-
|
|
82
|
-
try {
|
|
83
|
-
await _classPrivateFieldLooseBase(this, _server)[_server].start();
|
|
84
|
-
} catch (err) {
|
|
85
|
-
if (this.log) {
|
|
86
|
-
this.log.error(`Unexpected error while starting serverless-offline websocket server on port ${websocketPort}:`, err);
|
|
87
|
-
} else {
|
|
88
|
-
console.error(`Unexpected error while starting serverless-offline websocket server on port ${websocketPort}:`, err);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
(0, _process.exit)(1);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
if (this.log) {
|
|
95
|
-
this.log.notice(`Offline [http for websocket] listening on http${httpsProtocol ? 's' : ''}://${host}:${websocketPort}`);
|
|
96
|
-
} else {
|
|
97
|
-
(0, _serverlessLog.default)(`Offline [http for websocket] listening on http${httpsProtocol ? 's' : ''}://${host}:${websocketPort}`);
|
|
98
|
-
}
|
|
99
|
-
} // stops the server
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
stop(timeout) {
|
|
103
|
-
return _classPrivateFieldLooseBase(this, _server)[_server].stop({
|
|
104
|
-
timeout
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
get server() {
|
|
109
|
-
return _classPrivateFieldLooseBase(this, _server)[_server].listener;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
exports.default = HttpServer;
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _HttpServer = _interopRequireDefault(require("./HttpServer.js"));
|
|
9
|
-
|
|
10
|
-
var _WebSocketEventDefinition = _interopRequireDefault(require("./WebSocketEventDefinition.js"));
|
|
11
|
-
|
|
12
|
-
var _WebSocketClients = _interopRequireDefault(require("./WebSocketClients.js"));
|
|
13
|
-
|
|
14
|
-
var _WebSocketServer = _interopRequireDefault(require("./WebSocketServer.js"));
|
|
15
|
-
|
|
16
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
|
-
|
|
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
|
-
|
|
20
|
-
var id = 0;
|
|
21
|
-
|
|
22
|
-
function _classPrivateFieldLooseKey(name) { return "__private_" + id++ + "_" + name; }
|
|
23
|
-
|
|
24
|
-
var _httpServer = /*#__PURE__*/_classPrivateFieldLooseKey("httpServer");
|
|
25
|
-
|
|
26
|
-
var _webSocketServer = /*#__PURE__*/_classPrivateFieldLooseKey("webSocketServer");
|
|
27
|
-
|
|
28
|
-
class WebSocket {
|
|
29
|
-
constructor(serverless, options, lambda, v3Utils) {
|
|
30
|
-
Object.defineProperty(this, _httpServer, {
|
|
31
|
-
writable: true,
|
|
32
|
-
value: null
|
|
33
|
-
});
|
|
34
|
-
Object.defineProperty(this, _webSocketServer, {
|
|
35
|
-
writable: true,
|
|
36
|
-
value: null
|
|
37
|
-
});
|
|
38
|
-
const webSocketClients = new _WebSocketClients.default(serverless, options, lambda, v3Utils);
|
|
39
|
-
|
|
40
|
-
if (v3Utils) {
|
|
41
|
-
this.log = v3Utils.log;
|
|
42
|
-
this.progress = v3Utils.progress;
|
|
43
|
-
this.writeText = v3Utils.writeText;
|
|
44
|
-
this.v3Utils = v3Utils;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
_classPrivateFieldLooseBase(this, _httpServer)[_httpServer] = new _HttpServer.default(options, webSocketClients, this.v3Utils); // share server
|
|
48
|
-
|
|
49
|
-
_classPrivateFieldLooseBase(this, _webSocketServer)[_webSocketServer] = new _WebSocketServer.default(options, webSocketClients, _classPrivateFieldLooseBase(this, _httpServer)[_httpServer].server, v3Utils);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
start() {
|
|
53
|
-
return Promise.all([_classPrivateFieldLooseBase(this, _httpServer)[_httpServer].start(), _classPrivateFieldLooseBase(this, _webSocketServer)[_webSocketServer].start()]);
|
|
54
|
-
} // stops the server
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
stop(timeout) {
|
|
58
|
-
return Promise.all([_classPrivateFieldLooseBase(this, _httpServer)[_httpServer].stop(timeout), _classPrivateFieldLooseBase(this, _webSocketServer)[_webSocketServer].stop()]);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
_create(functionKey, rawWebSocketEventDefinition) {
|
|
62
|
-
const webSocketEvent = new _WebSocketEventDefinition.default(rawWebSocketEventDefinition);
|
|
63
|
-
|
|
64
|
-
_classPrivateFieldLooseBase(this, _webSocketServer)[_webSocketServer].addRoute(functionKey, webSocketEvent);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
create(events) {
|
|
68
|
-
events.forEach(({
|
|
69
|
-
functionKey,
|
|
70
|
-
websocket
|
|
71
|
-
}) => {
|
|
72
|
-
this._create(functionKey, websocket);
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
exports.default = WebSocket;
|