MCPcopy Index your code
hub / github.com/serverless/serverless / constructor

Method constructor

packages/engine/src/index.js:40–258  ·  view source on GitHub ↗

* Creates an instance of ServerlessEngine. * @param {Object} params - The constructor parameters * @param {Object} [params.stateStore=null] - Store for persisting state with load() and save() methods * @param {Object} [params.projectConfig=null] - Configuration for the serverless containers

({
    stateStore = null,
    projectConfig = null,
    projectPath = null,
    stage,
    provider = null,
  } = {})

Source from the content-addressed store, hash-verified

38 * @throws {ServerlessError} When required parameters are missing or invalid
39 */
40 constructor({
41 stateStore = null,
42 projectConfig = null,
43 projectPath = null,
44 stage,
45 provider = null,
46 } = {}) {
47 // Ensure stateStore is set
48 if (!stateStore) {
49 throw new ServerlessError('stateStore is missing', 'MISSING_STATE_STORE')
50 }
51 // Ensure the stateStore has a get and set functions
52 if (
53 typeof stateStore.load !== 'function' ||
54 typeof stateStore.save !== 'function'
55 ) {
56 throw new ServerlessError(
57 'stateStore is missing load or save function',
58 'INVALID_STATE_STORE',
59 )
60 }
61 // Ensure projectConfig is set
62 if (!projectConfig) {
63 throw new ServerlessError(
64 'projectConfig is missing',
65 'MISSING_PROJECT_CONFIG',
66 )
67 }
68 // Ensure projectPath is set
69 if (!projectPath) {
70 throw new ServerlessError(
71 'projectPath is missing',
72 'MISSING_PROJECT_PATH',
73 )
74 }
75 // Validate provider
76 if (!provider) {
77 throw new ServerlessError('provider is missing', 'MISSING_PROVIDER')
78 }
79 if (!provider.type) {
80 throw new ServerlessError(
81 'provider.type is missing',
82 'MISSING_PROVIDER_TYPE',
83 )
84 }
85 if (provider.type !== 'aws') {
86 throw new ServerlessError(
87 'Only "aws" provider is supported at this time',
88 'INVALID_PROVIDER_TYPE',
89 )
90 }
91 // Ensure stage is set
92 if (!stage) {
93 throw new ServerlessError('stage is missing', 'MISSING_STAGE')
94 }
95 // Ensure stage is 3-12 characters long
96 // Needed to not create overly long cloud resource names.
97 // This is not in zod, so we validate here.

Callers

nothing calls this directly

Calls 5

prettyPrintZodErrorFunction · 0.90
obfuscateSensitiveDataFunction · 0.90
debugMethod · 0.80
loadMethod · 0.80

Tested by

no test coverage detected