serverless-plugin-warmup 8.2.1 → 8.4.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/src/schema.js CHANGED
@@ -2,175 +2,191 @@
2
2
  * @description Define the additions to the serverless schema by this plugin.
3
3
  * */
4
4
  function extendServerlessSchema(serverless) {
5
- // Most of these are taken from
6
- // https://github.com/serverless/serverless/blob/master/lib/configSchema.js
7
- // https://github.com/serverless/serverless/blob/master/lib/plugins/aws/provider.js
8
- // https://github.com/serverless/serverless/blob/master/lib/plugins/aws/package/compile/events/schedule.js
5
+ // Most of these are taken from
6
+ // https://github.com/serverless/serverless/blob/master/lib/configSchema.js
7
+ // https://github.com/serverless/serverless/blob/master/lib/plugins/aws/provider.js
8
+ // https://github.com/serverless/serverless/blob/master/lib/plugins/aws/package/compile/events/schedule.js
9
9
 
10
- const rateSyntax = '^rate\\((?:1 (?:minute|hour|day)|(?:1\\d+|[2-9]\\d*) (?:minute|hour|day)s)\\)$';
11
- const cronSyntax = '^cron\\(\\S+ \\S+ \\S+ \\S+ \\S+ \\S+\\)$';
12
- const scheduleSyntax = `${rateSyntax}|${cronSyntax}`;
10
+ const rateSyntax =
11
+ '^rate\\((?:1 (?:minute|hour|day)|(?:1\\d+|[2-9]\\d*) (?:minute|hour|day)s)\\)$';
12
+ const cronSyntax = '^cron\\(\\S+ \\S+ \\S+ \\S+ \\S+ \\S+\\)$';
13
+ const scheduleSyntax = `${rateSyntax}|${cronSyntax}`;
13
14
 
14
- const globalConfigSchemaProperties = {
15
- folderName: { type: 'string' },
16
- cleanFolder: { type: 'boolean' },
17
- name: { type: 'string' },
18
- roleName: { type: 'string' },
19
- role: { $ref: '#/definitions/awsLambdaRole' },
20
- tags: { $ref: '#/definitions/awsResourceTags' },
21
- vpc: {
22
- anyOf: [
23
- { const: false }, // to deploy outside of the VPC
24
- { $ref: '#/definitions/awsLambdaVpcConfig' },
25
- ],
26
- },
27
- events: {
28
- type: 'array',
29
- items: {
30
- type: 'object',
31
- properties: {
32
- schedule: {
33
- anyOf: [
34
- { type: 'string', pattern: scheduleSyntax },
35
- {
36
- type: 'object',
37
- properties: {
38
- rate: {
39
- type: 'array',
40
- minItems: 1,
41
- items: {
42
- type: 'string',
43
- pattern: scheduleSyntax,
44
- },
45
- },
46
- enabled: { type: 'boolean' },
47
- name: {
48
- type: 'string', minLength: 1, maxLength: 64, pattern: '[\\.\\-_A-Za-z0-9]+',
49
- },
50
- description: { type: 'string', maxLength: 512 },
51
- input: {
52
- anyOf: [
53
- { type: 'string', maxLength: 8192 },
54
- {
55
- type: 'object',
56
- oneOf: [
57
- {
58
- properties: {
59
- body: { type: 'string', maxLength: 8192 },
60
- },
61
- required: ['body'],
62
- additionalProperties: false,
63
- },
64
- {
65
- not: {
66
- required: ['body'],
67
- },
68
- },
69
- ],
70
- },
71
- ],
72
- },
73
- inputPath: { type: 'string', maxLength: 256 },
74
- inputTransformer: {
75
- type: 'object',
76
- properties: {
77
- inputTemplate: {
78
- type: 'string',
79
- minLength: 1,
80
- maxLength: 8192,
81
- },
82
- inputPathsMap: { type: 'object' },
83
- },
84
- required: ['inputTemplate'],
85
- additionalProperties: false,
86
- },
87
- },
88
- required: ['rate'],
89
- additionalProperties: false,
90
- },
91
- ],
92
- },
93
- },
94
- required: ['schedule'],
95
- additionalProperties: false,
96
- },
97
- },
98
- architecture: { enum: ['arm64', 'x86_64'] },
99
- package: {
100
- type: 'object',
101
- properties: {
102
- artifact: { type: 'string' },
103
- patterns: { type: 'array', items: { type: 'string' } },
104
- individually: { type: 'boolean' },
105
- },
106
- additionalProperties: false,
107
- },
108
- memorySize: { $ref: '#/definitions/awsLambdaMemorySize' },
109
- timeout: { $ref: '#/definitions/awsLambdaTimeout' },
110
- environment: { $ref: '#/definitions/awsLambdaEnvironment' },
111
- tracing: { $ref: '#/definitions/awsLambdaTracing' },
112
- verbose: { type: 'boolean' },
113
- logRetentionInDays: { $ref: '#/definitions/awsLogRetentionInDays' },
114
- prewarm: { type: 'boolean' },
115
- };
15
+ const METHOD_SCHEDULER = 'scheduler';
16
+ const METHOD_EVENT_BUS = 'eventBus';
116
17
 
117
- const functionConfigSchemaProperties = {
118
- enabled: {
119
- anyOf: [
120
- { type: 'boolean' },
121
- { type: 'string' },
122
- { type: 'array', items: { type: 'string' } },
123
- ],
124
- },
125
- clientContext: {
126
- anyOf: [
127
- { const: false }, // to skip it
128
- { type: 'object' }, // any
129
- ],
130
- },
131
- payload: { type: 'object' }, // any
132
- payloadRaw: { type: 'boolean' },
133
- concurrency: { type: 'integer' },
134
- };
18
+ const globalConfigSchemaProperties = {
19
+ folderName: { type: 'string' },
20
+ cleanFolder: { type: 'boolean' },
21
+ name: { type: 'string' },
22
+ roleName: { type: 'string' },
23
+ role: { $ref: '#/definitions/awsLambdaRole' },
24
+ tags: { $ref: '#/definitions/awsResourceTags' },
25
+ vpc: {
26
+ anyOf: [
27
+ { const: false }, // to deploy outside of the VPC
28
+ { $ref: '#/definitions/awsLambdaVpcConfig' },
29
+ ],
30
+ },
31
+ events: {
32
+ type: 'array',
33
+ items: {
34
+ type: 'object',
35
+ properties: {
36
+ schedule: {
37
+ anyOf: [
38
+ { type: 'string', pattern: scheduleSyntax },
39
+ {
40
+ type: 'object',
41
+ properties: {
42
+ rate: {
43
+ type: 'array',
44
+ minItems: 1,
45
+ items: {
46
+ type: 'string',
47
+ pattern: scheduleSyntax,
48
+ },
49
+ },
50
+ enabled: { type: 'boolean' },
51
+ name: {
52
+ type: 'string',
53
+ minLength: 1,
54
+ maxLength: 64,
55
+ pattern: '[\\.\\-_A-Za-z0-9]+',
56
+ },
57
+ description: { type: 'string', maxLength: 512 },
58
+ input: {
59
+ anyOf: [
60
+ { type: 'string', maxLength: 8192 },
61
+ {
62
+ type: 'object',
63
+ oneOf: [
64
+ {
65
+ properties: {
66
+ body: { type: 'string', maxLength: 8192 },
67
+ },
68
+ required: ['body'],
69
+ additionalProperties: false,
70
+ },
71
+ {
72
+ not: {
73
+ required: ['body'],
74
+ },
75
+ },
76
+ ],
77
+ },
78
+ ],
79
+ },
80
+ inputPath: { type: 'string', maxLength: 256 },
81
+ inputTransformer: {
82
+ type: 'object',
83
+ properties: {
84
+ inputTemplate: {
85
+ type: 'string',
86
+ minLength: 1,
87
+ maxLength: 8192,
88
+ },
89
+ inputPathsMap: { type: 'object' },
90
+ },
91
+ required: ['inputTemplate'],
92
+ additionalProperties: false,
93
+ },
94
+ method: {
95
+ type: 'string',
96
+ enum: [METHOD_EVENT_BUS, METHOD_SCHEDULER],
97
+ },
98
+ timezone: {
99
+ type: 'string',
100
+ pattern: '[\\w\\-\\/]+',
101
+ },
102
+ },
103
+ required: ['rate'],
104
+ additionalProperties: false,
105
+ },
106
+ ],
107
+ },
108
+ },
109
+ required: ['schedule'],
110
+ additionalProperties: false,
111
+ },
112
+ },
113
+ architecture: { enum: ['arm64', 'x86_64'] },
114
+ package: {
115
+ type: 'object',
116
+ properties: {
117
+ artifact: { type: 'string' },
118
+ patterns: { type: 'array', items: { type: 'string' } },
119
+ individually: { type: 'boolean' },
120
+ },
121
+ additionalProperties: false,
122
+ },
123
+ memorySize: { $ref: '#/definitions/awsLambdaMemorySize' },
124
+ timeout: { $ref: '#/definitions/awsLambdaTimeout' },
125
+ environment: { $ref: '#/definitions/awsLambdaEnvironment' },
126
+ tracing: { $ref: '#/definitions/awsLambdaTracing' },
127
+ verbose: { type: 'boolean' },
128
+ logRetentionInDays: { $ref: '#/definitions/awsLogRetentionInDays' },
129
+ prewarm: { type: 'boolean' },
130
+ };
135
131
 
136
- if (!serverless.configSchemaHandler) return;
132
+ const functionConfigSchemaProperties = {
133
+ enabled: {
134
+ anyOf: [
135
+ { type: 'boolean' },
136
+ { type: 'string' },
137
+ { type: 'array', items: { type: 'string' } },
138
+ ],
139
+ },
140
+ alias: { type: 'string' },
141
+ clientContext: {
142
+ anyOf: [
143
+ { const: false }, // to skip it
144
+ { type: 'object' }, // any
145
+ ],
146
+ },
147
+ payload: { type: 'object' }, // any
148
+ payloadRaw: { type: 'boolean' },
149
+ concurrency: { type: 'integer' },
150
+ };
137
151
 
138
- if (typeof serverless.configSchemaHandler.defineCustomProperties === 'function') {
139
- serverless.configSchemaHandler.defineCustomProperties({
140
- properties: {
141
- warmup: {
142
- type: 'object',
143
- patternProperties: {
144
- '.*': {
145
- type: 'object',
146
- properties: { ...globalConfigSchemaProperties, ...functionConfigSchemaProperties },
147
- additionalProperties: false,
148
- },
149
- },
150
- },
151
- },
152
- });
153
- }
152
+ if (!serverless.configSchemaHandler) return;
154
153
 
155
- if (typeof serverless.configSchemaHandler.defineFunctionProperties === 'function') {
156
- serverless.configSchemaHandler.defineFunctionProperties('aws', {
157
- type: 'object',
158
- properties: {
159
- warmup: {
160
- type: 'object',
161
- patternProperties: {
162
- '.*': {
163
- type: 'object',
164
- properties: functionConfigSchemaProperties,
165
- additionalProperties: false,
166
- },
167
- },
168
- },
169
- },
170
- });
171
- }
154
+ if (typeof serverless.configSchemaHandler.defineCustomProperties === 'function') {
155
+ serverless.configSchemaHandler.defineCustomProperties({
156
+ properties: {
157
+ warmup: {
158
+ type: 'object',
159
+ patternProperties: {
160
+ '.*': {
161
+ type: 'object',
162
+ properties: { ...globalConfigSchemaProperties, ...functionConfigSchemaProperties },
163
+ additionalProperties: false,
164
+ },
165
+ },
166
+ },
167
+ },
168
+ });
169
+ }
170
+
171
+ if (typeof serverless.configSchemaHandler.defineFunctionProperties === 'function') {
172
+ serverless.configSchemaHandler.defineFunctionProperties('aws', {
173
+ type: 'object',
174
+ properties: {
175
+ warmup: {
176
+ type: 'object',
177
+ patternProperties: {
178
+ '.*': {
179
+ type: 'object',
180
+ properties: functionConfigSchemaProperties,
181
+ additionalProperties: false,
182
+ },
183
+ },
184
+ },
185
+ },
186
+ });
187
+ }
172
188
  }
173
189
 
174
190
  module.exports = {
175
- extendServerlessSchema,
191
+ extendServerlessSchema,
176
192
  };
package/src/utils.js CHANGED
@@ -1,5 +1,5 @@
1
1
  const capitalize = (name) => name.charAt(0).toUpperCase() + name.slice(1);
2
2
 
3
3
  module.exports = {
4
- capitalize,
4
+ capitalize,
5
5
  };