Skip to content

Commit

Permalink
fix: add ef-method field (#5270)
Browse files Browse the repository at this point in the history
  • Loading branch information
Skn0tt authored Aug 31, 2023
1 parent 6ca9952 commit eb83967
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 1 deletion.
11 changes: 10 additions & 1 deletion packages/config/src/edge_functions.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { isString, validProperties } from './validate/helpers.js'

const cacheValues = ['manual', 'off']
const methodValues = ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS']

const isMethod = (value: unknown) => typeof value === 'string' && methodValues.includes(value.toUpperCase())

export const validations = [
{
property: 'edge_functions.*',
...validProperties(['path', 'excludedPath', 'pattern', 'excludedPattern', 'function', 'cache'], []),
...validProperties(['path', 'excludedPath', 'pattern', 'excludedPattern', 'function', 'cache', 'method'], []),
example: () => ({ edge_functions: [{ path: '/hello', function: 'hello' }] }),
},
{
Expand Down Expand Up @@ -78,4 +81,10 @@ export const validations = [
message: `must be one of: ${cacheValues.join(', ')}`,
example: () => ({ edge_functions: [{ cache: cacheValues[0], path: '/hello', function: 'hello' }] }),
},
{
property: 'edge_functions.*.method',
check: (value) => isMethod(value) || (Array.isArray(value) && value.length !== 0 && value.every(isMethod)),
message: `must be one of or array of: ${methodValues.join(', ')}`,
example: () => ({ edge_functions: [{ method: ['PUT', 'DELETE'], path: '/hello', function: 'hello' }] }),
},
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[[edge_functions]]
function = "function2"
path = "/function2"
method = ["GET", "HEAD"]
26 changes: 26 additions & 0 deletions packages/config/tests/validate/snapshots/tests.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -1518,6 +1518,7 @@ Generated by [AVA](https://avajs.dev).
- excludedPattern␊
- function␊
- cache␊
- method␊
Invalid syntax␊
Expand Down Expand Up @@ -1812,3 +1813,28 @@ Generated by [AVA](https://avajs.dev).
cache = "manual"␊
path = "/external/path"␊
function = "hello"`

## edge_functions.any.method: disallowed values

> Snapshot 1
`When resolving config file packages/config/tests/validate/fixtures/edge_functions_method_disallowed/netlify.toml:␊
Configuration property edge_functions[0].method must be one of or array of: GET, POST, PUT, PATCH, DELETE, OPTIONS␊
Invalid syntax␊
[[edge_functions]]␊
method = [␊
"GET",␊
"HEAD"␊
]␊
Valid syntax␊
[[edge_functions]]␊
method = [␊
"PUT",␊
"DELETE"␊
]␊
path = "/external/path"␊
function = "hello"`
Binary file modified packages/config/tests/validate/snapshots/tests.js.snap
Binary file not shown.
5 changes: 5 additions & 0 deletions packages/config/tests/validate/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,3 +315,8 @@ test('edge_functions.any.mode: disallowed values', async (t) => {
const output = await new Fixture('./fixtures/edge_functions_mode_disallowed').runWithConfig()
t.snapshot(normalizeOutput(output))
})

test('edge_functions.any.method: disallowed values', async (t) => {
const output = await new Fixture('./fixtures/edge_functions_method_disallowed').runWithConfig()
t.snapshot(normalizeOutput(output))
})

0 comments on commit eb83967

Please sign in to comment.