From d3e81f1f76e3004f04ee2ccd40d54e15b511d4a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20Bou=C3=A7as?= Date: Thu, 9 Nov 2023 10:50:35 +0000 Subject: [PATCH 1/3] feat: add `preferStatic` type to config --- src/function/v2.ts | 40 +++++++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/src/function/v2.ts b/src/function/v2.ts index 03682ce5..500de1bb 100644 --- a/src/function/v2.ts +++ b/src/function/v2.ts @@ -1,13 +1,43 @@ export type { Context } from '@netlify/serverless-functions-api' type Path = `/${string}` - type HTTPMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'OPTIONS' - type CronSchedule = string -export interface Config { - path?: Path | Path[] +interface BaseConfig { + /** + * Configures the function to serve any static files that match the request + * URL and render the function only if no matching files exist. + */ + preferStatic?: boolean + + /** + * Limits the HTTP methods for which the function will run. If not set, the + * function will run for all supported methods. + */ method?: HTTPMethod | HTTPMethod[] - schedule?: CronSchedule } + +interface ConfigWithPath extends BaseConfig { + /** + * One or more URL paths for which the function will run. Paths must begin + * with a forward slash. + */ + path: Path | Path[] + + schedule?: never +} + +interface ConfigWithSchedule extends BaseConfig { + path?: never + + /** + * Cron expression representing the schedule at which the function will be + * automatically invoked. + * + * {@link} https://ntl.fyi/sched-func + */ + schedule: CronSchedule +} + +export type Config = ConfigWithPath | ConfigWithSchedule From c896c3f4b1a20168b0fc42d966c40f1561ac4112 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20Bou=C3=A7as?= Date: Thu, 9 Nov 2023 10:53:12 +0000 Subject: [PATCH 2/3] chore: add link --- src/function/v2.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/function/v2.ts b/src/function/v2.ts index 500de1bb..b5020545 100644 --- a/src/function/v2.ts +++ b/src/function/v2.ts @@ -22,6 +22,8 @@ interface ConfigWithPath extends BaseConfig { /** * One or more URL paths for which the function will run. Paths must begin * with a forward slash. + * + * {@link} https://ntl.fyi/func-routing */ path: Path | Path[] From 144079ccba72aed6d4c500527af3093bc2ea34d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20Bou=C3=A7as?= Date: Thu, 9 Nov 2023 10:55:39 +0000 Subject: [PATCH 3/3] fix: make `path` optional --- src/function/v2.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/function/v2.ts b/src/function/v2.ts index b5020545..5f4d8984 100644 --- a/src/function/v2.ts +++ b/src/function/v2.ts @@ -25,7 +25,7 @@ interface ConfigWithPath extends BaseConfig { * * {@link} https://ntl.fyi/func-routing */ - path: Path | Path[] + path?: Path | Path[] schedule?: never }