1 | /**
|
2 | * @file Defines the ServerlessOfflineExecutionContext class.
|
3 | *
|
4 | * @author Luke Chavers <luke@c2cschools.com>
|
5 | * @author Kevin Sanders <kevin@c2cschools.com>
|
6 | * @since 5.0.0
|
7 | * @license See LICENSE.md for details about licensing.
|
8 | * @copyright 2017 C2C Schools, LLC
|
9 | */
|
10 |
|
11 | ;
|
12 |
|
13 | // Important Note
|
14 | // --------------
|
15 | // This module only loads a single dependency, directly, which is the
|
16 | // parent class for the class defined within. This is intended to force
|
17 | // dependency loading through the parent class, by way of the `$dep()`
|
18 | // method, in order to centralize dependency definition and loading.
|
19 |
|
20 | const BaseHttpExecutionContext = require(
|
21 | "./abstract/BaseHttpExecutionContext"
|
22 | );
|
23 |
|
24 | /**
|
25 | * Represents an execution context whereby an endpoint is executed
|
26 | * in the local environment via the 'serverless-offline' plugin.
|
27 | *
|
28 | * @memberOf ExecutionContext
|
29 | * @extends ExecutionContext.BaseHttpExecutionContext
|
30 | */
|
31 | class ServerlessOfflineExecutionContext extends BaseHttpExecutionContext {
|
32 |
|
33 | /**
|
34 | * @inheritDoc
|
35 | */
|
36 | _initialize( cfg ) {
|
37 |
|
38 | const me = this;
|
39 |
|
40 | // Call parent
|
41 | super._initialize( cfg );
|
42 |
|
43 | // Dev flags...
|
44 | me.useDevelopmentToken = true;
|
45 | }
|
46 |
|
47 | /**
|
48 | * Generates a fake requestId that is prefixed with four 3's.
|
49 | *
|
50 | * @private
|
51 | * @returns {string} A fake request ID.
|
52 | */
|
53 | _createFakeRequestId() {
|
54 |
|
55 | const me = this;
|
56 |
|
57 | // Although we want to generate a valid requestId (for realism),
|
58 | // we're going to set the first block of characters to something
|
59 | // that identifies the UUID as being unusual and, further, as
|
60 | // being generated by this line of execution contexts.
|
61 |
|
62 | // Dependencies
|
63 | const uuidUtils = me.$dep( "util/uuid" );
|
64 |
|
65 | return uuidUtils.generate( "3333" );
|
66 | }
|
67 |
|
68 | /**
|
69 | * Create a configuration object, suitable for this execution context,
|
70 | * to be used when instantiating a new logger object.
|
71 | *
|
72 | * This method overrides the default behavior by loosening the minimum
|
73 | * logging level to include "DEBUG" level log events in the log output.
|
74 | * It also sets the default log output mode to 'linear' (human readable).
|
75 | *
|
76 | * @private
|
77 | * @param {Object} [loggerConfigOverrides] - Optional overrides for the
|
78 | * context's default logger configuration.
|
79 | * @returns {Object} A plain configuration object to be passed to
|
80 | * the constructor of new Logger objects.
|
81 | */
|
82 | _createLoggerConfig( loggerConfigOverrides ) {
|
83 |
|
84 | // Allow debug messages, but not "trace"
|
85 | if ( loggerConfigOverrides.minLogLevel === undefined ) {
|
86 |
|
87 | loggerConfigOverrides.minLogLevel = 7;
|
88 | }
|
89 |
|
90 | // Output in a human-readable format.
|
91 | if ( loggerConfigOverrides.linear === undefined ) {
|
92 |
|
93 | loggerConfigOverrides.linear = true;
|
94 | }
|
95 |
|
96 | return super._createLoggerConfig( loggerConfigOverrides );
|
97 | }
|
98 | }
|
99 |
|
100 | module.exports = ServerlessOfflineExecutionContext;
|