Skip to content

Commit 0a9271d

Browse files
fix: rename edge functions manifest property (#6544)
* fix: rename edge functions manifest property * fix: rename property in manifest generation
1 parent 9ba8975 commit 0a9271d

File tree

6 files changed

+55
-121
lines changed

6 files changed

+55
-121
lines changed

packages/edge-bundler/node/config.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -293,14 +293,14 @@ test('Loads function paths from the in-source `config` function', async () => {
293293
path: '/user-func1',
294294
headers: {
295295
'x-must-be-there': {
296-
style: 'exists',
296+
matcher: 'exists',
297297
},
298298
'x-must-match': {
299299
pattern: '^(foo|bar)$',
300-
style: 'regex',
300+
matcher: 'regex',
301301
},
302302
'x-must-not-be-there': {
303-
style: 'missing',
303+
matcher: 'missing',
304304
},
305305
},
306306
})

packages/edge-bundler/node/declaration.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { BundleError } from './bundle_error.js'
22
import { FunctionConfig, FunctionConfigWithAllPossibleFields, HeadersConfig, HTTPMethod, Path } from './config.js'
33
import { FeatureFlags } from './feature_flags.js'
44

5-
export type HeaderMatch = { pattern: string; style: 'regex' } | { style: 'exists' | 'missing' }
5+
export type HeaderMatch = { pattern: string; matcher: 'regex' } | { matcher: 'exists' | 'missing' }
66
type HeaderMatchers = Record<string, HeaderMatch>
77

88
interface BaseDeclaration {
@@ -192,9 +192,9 @@ export const getHeaderMatchers = (headers?: HeadersConfig): HeaderMatchers => {
192192

193193
for (const header in headers) {
194194
if (typeof headers[header] === 'boolean') {
195-
matchers[header] = { style: headers[header] ? 'exists' : 'missing' }
195+
matchers[header] = { matcher: headers[header] ? 'exists' : 'missing' }
196196
} else if (typeof headers[header] === 'string') {
197-
matchers[header] = { style: 'regex', pattern: normalizePattern(headers[header]) }
197+
matchers[header] = { matcher: 'regex', pattern: normalizePattern(headers[header]) }
198198
} else {
199199
throw new BundleError(new Error(headerConfigError))
200200
}

packages/edge-bundler/node/manifest.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -237,11 +237,11 @@ test('excludedPath from ISC goes into function_config, TOML goes into routes', (
237237

238238
const matcher = getRouteMatcher(manifest)
239239

240-
expect(matcher('/showcases/boho-style')).toBeDefined()
240+
expect(matcher('/showcases/boho-matcher')).toBeDefined()
241241
expect(matcher('/checkout/address')).toBeDefined()
242242
expect(matcher('/checkout/terms-and-conditions')).toBeUndefined()
243243
expect(matcher('/checkout/scrooge-mc-duck-animation.css')).toBeUndefined()
244-
expect(matcher('/showcases/boho-style/expensive-chair.jpg')).toBeUndefined()
244+
expect(matcher('/showcases/boho-matcher/expensive-chair.jpg')).toBeUndefined()
245245
})
246246

247247
test('URLPattern named groups are supported', () => {
@@ -640,25 +640,25 @@ describe('Header matching', () => {
640640
path: '/f1/*',
641641
headers: {
642642
'x-absent': {
643-
style: 'missing',
643+
matcher: 'missing',
644644
},
645645
'x-also-present': {
646-
style: 'exists',
646+
matcher: 'exists',
647647
},
648648
'x-match-exact': {
649649
pattern: '^exact$',
650-
style: 'regex',
650+
matcher: 'regex',
651651
},
652652
'x-match-prefix': {
653653
pattern: '^prefix(.*)$',
654-
style: 'regex',
654+
matcher: 'regex',
655655
},
656656
'x-match-suffix': {
657657
pattern: '^(.*)suffix$',
658-
style: 'regex',
658+
matcher: 'regex',
659659
},
660660
'x-present': {
661-
style: 'exists',
661+
matcher: 'exists',
662662
},
663663
},
664664
},

packages/edge-bundler/node/validation/manifest/__snapshots__/index.test.ts.snap

Lines changed: 21 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -53,72 +53,6 @@ REQUIRED must have required property 'format'
5353
6 | ],]
5454
`;
5555
56-
exports[`headers > should throw on additional property in headers 1`] = `
57-
[ManifestValidationError: Validation of Edge Functions manifest failed
58-
ADDTIONAL PROPERTY must NOT have additional properties
59-
60-
33 | "x-custom-header": {
61-
34 | "style": "exists",
62-
> 35 | "foo": "bar"
63-
| ^^^^^ 😲 foo is not expected to be here!
64-
36 | }
65-
37 | }
66-
38 | }]
67-
`;
68-
69-
exports[`headers > should throw on invalid pattern format 1`] = `
70-
[ManifestValidationError: Validation of Edge Functions manifest failed
71-
FORMAT must match format "regexPattern"
72-
73-
33 | "x-custom-header": {
74-
34 | "style": "regex",
75-
> 35 | "pattern": "/^Bearer .+/"
76-
| ^^^^^^^^^^^^^^ 👈🏽 format must match format "regexPattern"
77-
36 | }
78-
37 | }
79-
38 | }]
80-
`;
81-
82-
exports[`headers > should throw on invalid style value 1`] = `
83-
[ManifestValidationError: Validation of Edge Functions manifest failed
84-
ENUM must be equal to one of the allowed values
85-
(exists, missing, regex)
86-
87-
32 | "headers": {
88-
33 | "x-custom-header": {
89-
> 34 | "style": "invalid"
90-
| ^^^^^^^^^ 👈🏽 Unexpected value, should be equal to one of the allowed values
91-
35 | }
92-
36 | }
93-
37 | }]
94-
`;
95-
96-
exports[`headers > should throw on missing style property 1`] = `
97-
[ManifestValidationError: Validation of Edge Functions manifest failed
98-
REQUIRED must have required property 'style'
99-
100-
31 | "bundler_version": "1.6.0",
101-
32 | "headers": {
102-
> 33 | "x-custom-header": {
103-
| ^ ☹️ style is missing here!
104-
34 | "pattern": "^Bearer .+"
105-
35 | }
106-
36 | }]
107-
`;
108-
109-
exports[`headers > should throw when style is regex but pattern is missing 1`] = `
110-
[ManifestValidationError: Validation of Edge Functions manifest failed
111-
REQUIRED must have required property 'pattern'
112-
113-
31 | "bundler_version": "1.6.0",
114-
32 | "headers": {
115-
> 33 | "x-custom-header": {
116-
| ^ ☹️ pattern is missing here!
117-
34 | "style": "regex"
118-
35 | }
119-
36 | }]
120-
`;
121-
12256
exports[`import map URL > should throw on wrong type 1`] = `
12357
[ManifestValidationError: Validation of Edge Functions manifest failed
12458
TYPE must be string
@@ -230,63 +164,63 @@ exports[`route headers > should throw on additional property in headers 1`] = `
230164
ADDTIONAL PROPERTY must NOT have additional properties
231165
232166
15 | "x-custom-header": {
233-
16 | "style": "exists",
167+
16 | "matcher": "exists",
234168
> 17 | "foo": "bar"
235169
| ^^^^^ 😲 foo is not expected to be here!
236170
18 | }
237171
19 | }
238172
20 | }]
239173
`;
240174
175+
exports[`route headers > should throw on invalid matcher value 1`] = `
176+
[ManifestValidationError: Validation of Edge Functions manifest failed
177+
ENUM must be equal to one of the allowed values
178+
(exists, missing, regex)
179+
180+
14 | "headers": {
181+
15 | "x-custom-header": {
182+
> 16 | "matcher": "invalid"
183+
| ^^^^^^^^^ 👈🏽 Unexpected value, should be equal to one of the allowed values
184+
17 | }
185+
18 | }
186+
19 | }]
187+
`;
188+
241189
exports[`route headers > should throw on invalid pattern format 1`] = `
242190
[ManifestValidationError: Validation of Edge Functions manifest failed
243191
FORMAT must match format "regexPattern"
244192
245193
15 | "x-custom-header": {
246-
16 | "style": "regex",
194+
16 | "matcher": "regex",
247195
> 17 | "pattern": "/^Bearer .+/"
248196
| ^^^^^^^^^^^^^^ 👈🏽 format must match format "regexPattern"
249197
18 | }
250198
19 | }
251199
20 | }]
252200
`;
253201
254-
exports[`route headers > should throw on invalid style value 1`] = `
255-
[ManifestValidationError: Validation of Edge Functions manifest failed
256-
ENUM must be equal to one of the allowed values
257-
(exists, missing, regex)
258-
259-
14 | "headers": {
260-
15 | "x-custom-header": {
261-
> 16 | "style": "invalid"
262-
| ^^^^^^^^^ 👈🏽 Unexpected value, should be equal to one of the allowed values
263-
17 | }
264-
18 | }
265-
19 | }]
266-
`;
267-
268-
exports[`route headers > should throw on missing style property 1`] = `
202+
exports[`route headers > should throw on missing matcher property 1`] = `
269203
[ManifestValidationError: Validation of Edge Functions manifest failed
270-
REQUIRED must have required property 'style'
204+
REQUIRED must have required property 'matcher'
271205
272206
13 | "generator": "@netlify/fake-plugin@1.0.0",
273207
14 | "headers": {
274208
> 15 | "x-custom-header": {
275-
| ^ ☹️ style is missing here!
209+
| ^ ☹️ matcher is missing here!
276210
16 | "pattern": "^Bearer .+$"
277211
17 | }
278212
18 | }]
279213
`;
280214
281-
exports[`route headers > should throw when style is regex but pattern is missing 1`] = `
215+
exports[`route headers > should throw when matcher is regex but pattern is missing 1`] = `
282216
[ManifestValidationError: Validation of Edge Functions manifest failed
283217
REQUIRED must have required property 'pattern'
284218
285219
13 | "generator": "@netlify/fake-plugin@1.0.0",
286220
14 | "headers": {
287221
> 15 | "x-custom-header": {
288222
| ^ ☹️ pattern is missing here!
289-
16 | "style": "regex"
223+
16 | "matcher": "regex"
290224
17 | }
291225
18 | }]
292226
`;

packages/edge-bundler/node/validation/manifest/index.test.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -182,41 +182,41 @@ describe('import map URL', () => {
182182
})
183183

184184
describe('route headers', () => {
185-
test('should accept valid headers with exists style', () => {
185+
test('should accept valid headers with exists matcher', () => {
186186
const manifest = getBaseManifest()
187187
manifest.routes[0].headers = {
188188
'x-custom-header': {
189-
style: 'exists',
189+
matcher: 'exists',
190190
},
191191
}
192192

193193
expect(() => validateManifest(manifest)).not.toThrowError()
194194
})
195195

196-
test('should accept valid headers with missing style', () => {
196+
test('should accept valid headers with missing matcher', () => {
197197
const manifest = getBaseManifest()
198198
manifest.routes[0].headers = {
199199
'x-custom-header': {
200-
style: 'missing',
200+
matcher: 'missing',
201201
},
202202
}
203203

204204
expect(() => validateManifest(manifest)).not.toThrowError()
205205
})
206206

207-
test('should accept valid headers with regex style and pattern', () => {
207+
test('should accept valid headers with regex matcher and pattern', () => {
208208
const manifest = getBaseManifest()
209209
manifest.routes[0].headers = {
210210
'x-custom-header': {
211-
style: 'regex',
211+
matcher: 'regex',
212212
pattern: '^Bearer .+$',
213213
},
214214
}
215215

216216
expect(() => validateManifest(manifest)).not.toThrowError()
217217
})
218218

219-
test('should throw on missing style property', () => {
219+
test('should throw on missing matcher property', () => {
220220
const manifest = getBaseManifest()
221221
manifest.routes[0].headers = {
222222
'x-custom-header': {
@@ -227,22 +227,22 @@ describe('route headers', () => {
227227
expect(() => validateManifest(manifest)).toThrowErrorMatchingSnapshot()
228228
})
229229

230-
test('should throw on invalid style value', () => {
230+
test('should throw on invalid matcher value', () => {
231231
const manifest = getBaseManifest()
232232
manifest.routes[0].headers = {
233233
'x-custom-header': {
234-
style: 'invalid',
234+
matcher: 'invalid',
235235
},
236236
}
237237

238238
expect(() => validateManifest(manifest)).toThrowErrorMatchingSnapshot()
239239
})
240240

241-
test('should throw when style is regex but pattern is missing', () => {
241+
test('should throw when matcher is regex but pattern is missing', () => {
242242
const manifest = getBaseManifest()
243243
manifest.routes[0].headers = {
244244
'x-custom-header': {
245-
style: 'regex',
245+
matcher: 'regex',
246246
},
247247
}
248248

@@ -253,7 +253,7 @@ describe('route headers', () => {
253253
const manifest = getBaseManifest()
254254
manifest.routes[0].headers = {
255255
'x-custom-header': {
256-
style: 'regex',
256+
matcher: 'regex',
257257
pattern: '/^Bearer .+/',
258258
},
259259
}
@@ -265,25 +265,25 @@ describe('route headers', () => {
265265
const manifest = getBaseManifest()
266266
manifest.routes[0].headers = {
267267
'x-custom-header': {
268-
style: 'exists',
268+
matcher: 'exists',
269269
foo: 'bar',
270270
},
271271
}
272272

273273
expect(() => validateManifest(manifest)).toThrowErrorMatchingSnapshot()
274274
})
275275

276-
test('should accept multiple headers with different styles', () => {
276+
test('should accept multiple headers with different matchers', () => {
277277
const manifest = getBaseManifest()
278278
manifest.routes[0].headers = {
279279
'x-exists-header': {
280-
style: 'exists',
280+
matcher: 'exists',
281281
},
282282
'x-missing-header': {
283-
style: 'missing',
283+
matcher: 'missing',
284284
},
285285
authorization: {
286-
style: 'regex',
286+
matcher: 'regex',
287287
pattern: '^Bearer [a-zA-Z0-9]+$',
288288
},
289289
}

packages/edge-bundler/node/validation/manifest/schema.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,21 @@ const headersSchema = {
2323
patternProperties: {
2424
'.*': {
2525
type: 'object',
26-
required: ['style'],
26+
required: ['matcher'],
2727
properties: {
2828
pattern: {
2929
type: 'string',
3030
format: 'regexPattern',
3131
},
32-
style: {
32+
matcher: {
3333
type: 'string',
3434
enum: ['exists', 'missing', 'regex'],
3535
},
3636
},
3737
additionalProperties: false,
3838
if: {
3939
properties: {
40-
style: { const: 'regex' },
40+
matcher: { const: 'regex' },
4141
},
4242
},
4343
then: {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy