Skip to content

Commit 9abc987

Browse files
feat: add preferStatic type to config (#443)
**Which problem is this pull request solving?** Adds a new `preferStatic` type to the functions config. Also, makes the `path` and `schedule` properties mutually exclusive. Finally, it adds some JSDoc comments to each property.
1 parent d558f36 commit 9abc987

File tree

1 file changed

+37
-5
lines changed

1 file changed

+37
-5
lines changed

src/function/v2.ts

+37-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,45 @@
11
export type { Context } from '@netlify/serverless-functions-api'
22

33
type Path = `/${string}`
4-
54
type HTTPMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'OPTIONS'
6-
75
type CronSchedule = string
86

9-
export interface Config {
10-
path?: Path | Path[]
7+
interface BaseConfig {
8+
/**
9+
* Configures the function to serve any static files that match the request
10+
* URL and render the function only if no matching files exist.
11+
*/
12+
preferStatic?: boolean
13+
14+
/**
15+
* Limits the HTTP methods for which the function will run. If not set, the
16+
* function will run for all supported methods.
17+
*/
1118
method?: HTTPMethod | HTTPMethod[]
12-
schedule?: CronSchedule
1319
}
20+
21+
interface ConfigWithPath extends BaseConfig {
22+
/**
23+
* One or more URL paths for which the function will run. Paths must begin
24+
* with a forward slash.
25+
*
26+
* {@link} https://ntl.fyi/func-routing
27+
*/
28+
path?: Path | Path[]
29+
30+
schedule?: never
31+
}
32+
33+
interface ConfigWithSchedule extends BaseConfig {
34+
path?: never
35+
36+
/**
37+
* Cron expression representing the schedule at which the function will be
38+
* automatically invoked.
39+
*
40+
* {@link} https://ntl.fyi/sched-func
41+
*/
42+
schedule: CronSchedule
43+
}
44+
45+
export type Config = ConfigWithPath | ConfigWithSchedule

0 commit comments

Comments
 (0)