From 9abc9877d91257cfb7c5c51cdffd68864dcafd21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20Bou=C3=A7as?= Date: Thu, 9 Nov 2023 11:00:58 +0000 Subject: [PATCH] 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. --- src/function/v2.ts | 42 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 37 insertions(+), 5 deletions(-) diff --git a/src/function/v2.ts b/src/function/v2.ts index 03682ce5..5f4d8984 100644 --- a/src/function/v2.ts +++ b/src/function/v2.ts @@ -1,13 +1,45 @@ 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. + * + * {@link} https://ntl.fyi/func-routing + */ + 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