-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add manifest validation (#208)
* feat: add manifest validation * chore: disable color in test
- Loading branch information
Showing
13 changed files
with
1,342 additions
and
803 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
interface Bundle { | ||
export enum BundleFormat { | ||
ESZIP2 = 'eszip2', | ||
JS = 'js', | ||
} | ||
|
||
export interface Bundle { | ||
extension: string | ||
format: string | ||
format: BundleFormat | ||
hash: string | ||
} | ||
|
||
export type { Bundle } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
176 changes: 176 additions & 0 deletions
176
node/validation/manifest/__snapshots__/index.test.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,176 @@ | ||
// Vitest Snapshot v1 | ||
|
||
exports[`bundle > should throw on additional property in bundle 1`] = ` | ||
"Validation of Edge Functions manifest failed | ||
ADDTIONAL PROPERTY must NOT have additional properties | ||
4 | \\"asset\\": \\"f35baff44129a8f6be7db68590b2efd86ed4ba29000e2edbcaddc5d620d7d043.js\\", | ||
5 | \\"format\\": \\"js\\", | ||
> 6 | \\"foo\\": \\"bar\\" | ||
| ^^^^^ 😲 foo is not expected to be here! | ||
7 | } | ||
8 | ], | ||
9 | \\"routes\\": [" | ||
`; | ||
|
||
exports[`bundle > should throw on invalid format 1`] = ` | ||
"Validation of Edge Functions manifest failed | ||
ENUM must be equal to one of the allowed values | ||
(eszip2, js) | ||
3 | { | ||
4 | \\"asset\\": \\"f35baff44129a8f6be7db68590b2efd86ed4ba29000e2edbcaddc5d620d7d043.js\\", | ||
> 5 | \\"format\\": \\"foo\\" | ||
| ^^^^^ 👈🏽 Unexpected value, should be equal to one of the allowed values | ||
6 | } | ||
7 | ], | ||
8 | \\"routes\\": [" | ||
`; | ||
|
||
exports[`bundle > should throw on missing asset 1`] = ` | ||
"Validation of Edge Functions manifest failed | ||
REQUIRED must have required property 'asset' | ||
1 | { | ||
2 | \\"bundles\\": [ | ||
> 3 | { | ||
| ^ ☹️ asset is missing here! | ||
4 | \\"format\\": \\"js\\" | ||
5 | } | ||
6 | ]," | ||
`; | ||
exports[`bundle > should throw on missing format 1`] = ` | ||
"Validation of Edge Functions manifest failed | ||
REQUIRED must have required property 'format' | ||
1 | { | ||
2 | \\"bundles\\": [ | ||
> 3 | { | ||
| ^ ☹️ format is missing here! | ||
4 | \\"asset\\": \\"f35baff44129a8f6be7db68590b2efd86ed4ba29000e2edbcaddc5d620d7d043.js\\" | ||
5 | } | ||
6 | ]," | ||
`; | ||
exports[`layers > should throw on additional property 1`] = ` | ||
"Validation of Edge Functions manifest failed | ||
ADDTIONAL PROPERTY must NOT have additional properties | ||
25 | \\"name\\": \\"name\\", | ||
26 | \\"local\\": \\"local\\", | ||
> 27 | \\"foo\\": \\"bar\\" | ||
| ^^^^^ 😲 foo is not expected to be here! | ||
28 | } | ||
29 | ], | ||
30 | \\"bundler_version\\": \\"1.6.0\\"" | ||
`; | ||
exports[`layers > should throw on missing flag 1`] = ` | ||
"Validation of Edge Functions manifest failed | ||
REQUIRED must have required property 'flag' | ||
21 | ], | ||
22 | \\"layers\\": [ | ||
> 23 | { | ||
| ^ ☹️ flag is missing here! | ||
24 | \\"name\\": \\"name\\", | ||
25 | \\"local\\": \\"local\\" | ||
26 | }" | ||
`; | ||
exports[`layers > should throw on missing name 1`] = ` | ||
"Validation of Edge Functions manifest failed | ||
REQUIRED must have required property 'name' | ||
21 | ], | ||
22 | \\"layers\\": [ | ||
> 23 | { | ||
| ^ ☹️ name is missing here! | ||
24 | \\"flag\\": \\"flag\\", | ||
25 | \\"local\\": \\"local\\" | ||
26 | }" | ||
`; | ||
exports[`route > should throw on additional property 1`] = ` | ||
"Validation of Edge Functions manifest failed | ||
ADDTIONAL PROPERTY must NOT have additional properties | ||
11 | \\"function\\": \\"hello\\", | ||
12 | \\"pattern\\": \\"^/hello/?$\\", | ||
> 13 | \\"foo\\": \\"bar\\" | ||
| ^^^^^ 😲 foo is not expected to be here! | ||
14 | } | ||
15 | ], | ||
16 | \\"post_cache_routes\\": [" | ||
`; | ||
exports[`route > should throw on invalid pattern 1`] = ` | ||
"Validation of Edge Functions manifest failed | ||
FORMAT pattern needs to be a regex that starts with ^ and ends with $ without any additional slashes before and afterwards | ||
10 | \\"name\\": \\"name\\", | ||
11 | \\"function\\": \\"hello\\", | ||
> 12 | \\"pattern\\": \\"/^/hello/?$/\\" | ||
| ^^^^^^^^^^^^^^ 👈🏽 format pattern needs to be a regex that starts with ^ and ends with $ without any additional slashes before and afterwards | ||
13 | } | ||
14 | ], | ||
15 | \\"post_cache_routes\\": [" | ||
`; | ||
exports[`route > should throw on missing function 1`] = ` | ||
"Validation of Edge Functions manifest failed | ||
REQUIRED must have required property 'function' | ||
7 | ], | ||
8 | \\"routes\\": [ | ||
> 9 | { | ||
| ^ ☹️ function is missing here! | ||
10 | \\"name\\": \\"name\\", | ||
11 | \\"pattern\\": \\"^/hello/?$\\" | ||
12 | }" | ||
`; | ||
exports[`route > should throw on missing pattern 1`] = ` | ||
"Validation of Edge Functions manifest failed | ||
REQUIRED must have required property 'pattern' | ||
7 | ], | ||
8 | \\"routes\\": [ | ||
> 9 | { | ||
| ^ ☹️ pattern is missing here! | ||
10 | \\"name\\": \\"name\\", | ||
11 | \\"function\\": \\"hello\\" | ||
12 | }" | ||
`; | ||
exports[`should show multiple errors 1`] = ` | ||
"Validation of Edge Functions manifest failed | ||
ADDTIONAL PROPERTY must NOT have additional properties | ||
28 | ], | ||
29 | \\"bundler_version\\": \\"1.6.0\\", | ||
> 30 | \\"foo\\": \\"bar\\", | ||
| ^^^^^ 😲 foo is not expected to be here! | ||
31 | \\"baz\\": \\"bar\\" | ||
32 | } | ||
ADDTIONAL PROPERTY must NOT have additional properties | ||
29 | \\"bundler_version\\": \\"1.6.0\\", | ||
30 | \\"foo\\": \\"bar\\", | ||
> 31 | \\"baz\\": \\"bar\\" | ||
| ^^^^^ 😲 baz is not expected to be here! | ||
32 | }" | ||
`; | ||
exports[`should throw on additional property on root level 1`] = ` | ||
"Validation of Edge Functions manifest failed | ||
ADDTIONAL PROPERTY must NOT have additional properties | ||
28 | ], | ||
29 | \\"bundler_version\\": \\"1.6.0\\", | ||
> 30 | \\"foo\\": \\"bar\\" | ||
| ^^^^^ 😲 foo is not expected to be here! | ||
31 | }" | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export default class ManifestValidationError extends Error { | ||
constructor(message: string | undefined) { | ||
super(`Validation of Edge Functions manifest failed\n${message}`) | ||
|
||
this.name = 'ManifestValidationError' | ||
|
||
// https://github.com/microsoft/TypeScript-wiki/blob/0fecbda7263f130c57394d779b8ca13f0a2e9123/Breaking-Changes.md#extending-built-ins-like-error-array-and-map-may-no-longer-work | ||
Object.setPrototypeOf(this, ManifestValidationError.prototype) | ||
} | ||
} |
Oops, something went wrong.