From 83f16ea06c461ca711a252ef3f2148dc80177bda Mon Sep 17 00:00:00 2001 From: Alexander Niebuhr Date: Sat, 16 Mar 2024 07:02:01 +0100 Subject: [PATCH 1/9] adds integration options --- packages/form/src/index.ts | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/packages/form/src/index.ts b/packages/form/src/index.ts index 191e0c8..d83818c 100644 --- a/packages/form/src/index.ts +++ b/packages/form/src/index.ts @@ -3,15 +3,22 @@ import type { AstroIntegration } from "astro"; const VIRTUAL_MOD_ID = "simple:form"; const RESOLVED_VIRTUAL_MOD_ID = "\0" + VIRTUAL_MOD_ID; -export default function integration(): AstroIntegration { +export type Options = { + injectMiddleware?: false; +} + +export default function integration(opts?: Options): AstroIntegration { return { name: "simple-form", hooks: { "astro:config:setup"({ addMiddleware, updateConfig }) { - addMiddleware({ - entrypoint: "simple-stack-form/middleware", - order: "pre", - }); + const shouldInjectMiddleware = opts?.injectMiddleware ?? 'true' + if (shouldInjectMiddleware) { + addMiddleware({ + entrypoint: "simple-stack-form/middleware", + order: "pre", + }); + } updateConfig({ vite: { From d534229bacef5479fa0a2c5c84b9762f1bd67bb6 Mon Sep 17 00:00:00 2001 From: Alexander Niebuhr Date: Sat, 16 Mar 2024 07:27:47 +0100 Subject: [PATCH 2/9] fixes types --- packages/form/src/index.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/form/src/index.ts b/packages/form/src/index.ts index d83818c..1cbc479 100644 --- a/packages/form/src/index.ts +++ b/packages/form/src/index.ts @@ -4,15 +4,16 @@ const VIRTUAL_MOD_ID = "simple:form"; const RESOLVED_VIRTUAL_MOD_ID = "\0" + VIRTUAL_MOD_ID; export type Options = { - injectMiddleware?: false; -} + injectMiddleware?: true | false; +}; export default function integration(opts?: Options): AstroIntegration { return { name: "simple-form", hooks: { "astro:config:setup"({ addMiddleware, updateConfig }) { - const shouldInjectMiddleware = opts?.injectMiddleware ?? 'true' + const shouldInjectMiddleware: boolean = opts?.injectMiddleware ?? true; + console.log("simple-form:astro:config:setup", shouldInjectMiddleware); if (shouldInjectMiddleware) { addMiddleware({ entrypoint: "simple-stack-form/middleware", From be80caa397b8c59925386a039a151fa7838dac1b Mon Sep 17 00:00:00 2001 From: Alexander Niebuhr Date: Sat, 16 Mar 2024 07:28:27 +0100 Subject: [PATCH 3/9] removes debug log --- packages/form/src/index.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/form/src/index.ts b/packages/form/src/index.ts index 1cbc479..3dcb4e8 100644 --- a/packages/form/src/index.ts +++ b/packages/form/src/index.ts @@ -13,7 +13,6 @@ export default function integration(opts?: Options): AstroIntegration { hooks: { "astro:config:setup"({ addMiddleware, updateConfig }) { const shouldInjectMiddleware: boolean = opts?.injectMiddleware ?? true; - console.log("simple-form:astro:config:setup", shouldInjectMiddleware); if (shouldInjectMiddleware) { addMiddleware({ entrypoint: "simple-stack-form/middleware", From 3d9396b513050d79bc0671b63e35129213fdea97 Mon Sep 17 00:00:00 2001 From: Alexander Niebuhr Date: Mon, 18 Mar 2024 09:06:02 +0100 Subject: [PATCH 4/9] adds docs --- www/src/content/docs/form/reference.md | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 www/src/content/docs/form/reference.md diff --git a/www/src/content/docs/form/reference.md b/www/src/content/docs/form/reference.md new file mode 100644 index 0000000..14f91ea --- /dev/null +++ b/www/src/content/docs/form/reference.md @@ -0,0 +1,26 @@ +--- +title: Reference +description: Reference for simple-stack-form +sidebar: + order: 4 +--- + +## `injectMiddleware` + +**Type:** `true | false` + +The adapter option `injectMiddleware` allows to opt-out of the default behaviour, which injects a middleware. This could be useful if you want to add your own data retrivial and `POST` handling logic. + +```ts ins={3,7-9} +// astro.config.ts +import { defineConfig } from 'astro/config'; +import simpleStackForm from 'simple-stack-form'; + +export default defineConfig({ + integrations: [ + simpleStackForm({ + injectMiddleware: false, + }), + ], +}); +``` From de694e943e96123b7056f682ac2a4e22555ed7a7 Mon Sep 17 00:00:00 2001 From: Alexander Niebuhr Date: Mon, 18 Mar 2024 09:06:11 +0100 Subject: [PATCH 5/9] adds changeset --- .changeset/strong-monkeys-tell.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/strong-monkeys-tell.md diff --git a/.changeset/strong-monkeys-tell.md b/.changeset/strong-monkeys-tell.md new file mode 100644 index 0000000..32ad4d1 --- /dev/null +++ b/.changeset/strong-monkeys-tell.md @@ -0,0 +1,5 @@ +--- +"simple-stack-form": minor +--- + +Adds an adapter option to disable injection of middleware From 65b03d54eb8da03f6a334598e8a9334fa3920b99 Mon Sep 17 00:00:00 2001 From: Ben Holmes Date: Wed, 20 Mar 2024 07:29:54 -0400 Subject: [PATCH 6/9] edit: Reference -> API Reference --- www/src/content/docs/form/reference.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/www/src/content/docs/form/reference.md b/www/src/content/docs/form/reference.md index 14f91ea..8e49dce 100644 --- a/www/src/content/docs/form/reference.md +++ b/www/src/content/docs/form/reference.md @@ -1,5 +1,5 @@ --- -title: Reference +title: API Reference description: Reference for simple-stack-form sidebar: order: 4 From 86419b2db68b2f21a71c898cb47f57262b7767dc Mon Sep 17 00:00:00 2001 From: Ben Holmes Date: Wed, 20 Mar 2024 07:30:29 -0400 Subject: [PATCH 7/9] edit: Reference -> Config Reference --- www/src/content/docs/form/reference.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/www/src/content/docs/form/reference.md b/www/src/content/docs/form/reference.md index 8e49dce..6d36c50 100644 --- a/www/src/content/docs/form/reference.md +++ b/www/src/content/docs/form/reference.md @@ -1,5 +1,5 @@ --- -title: API Reference +title: Config Reference description: Reference for simple-stack-form sidebar: order: 4 From cbbd7407fa707458ffcb64037d89ea5a7b2da18b Mon Sep 17 00:00:00 2001 From: Ben Holmes Date: Wed, 20 Mar 2024 07:35:07 -0400 Subject: [PATCH 8/9] edit: the adapter option... --- www/src/content/docs/form/reference.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/www/src/content/docs/form/reference.md b/www/src/content/docs/form/reference.md index 6d36c50..0fe9f9e 100644 --- a/www/src/content/docs/form/reference.md +++ b/www/src/content/docs/form/reference.md @@ -9,7 +9,7 @@ sidebar: **Type:** `true | false` -The adapter option `injectMiddleware` allows to opt-out of the default behaviour, which injects a middleware. This could be useful if you want to add your own data retrivial and `POST` handling logic. +The adapter option `injectMiddleware` allows you to opt-out of middleware injection used to expose [`Astro.locals.form`](form/parse/#astrolocalsform). This could be useful if you want to add your own data retrieval and `POST` handling logic. ```ts ins={3,7-9} // astro.config.ts From bbdb10679da4d801f15951d6dfe33cd64f72e8c4 Mon Sep 17 00:00:00 2001 From: Ben Holmes Date: Wed, 20 Mar 2024 07:35:39 -0400 Subject: [PATCH 9/9] edit: tweak line highlight --- www/src/content/docs/form/reference.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/www/src/content/docs/form/reference.md b/www/src/content/docs/form/reference.md index 0fe9f9e..e6f3ffe 100644 --- a/www/src/content/docs/form/reference.md +++ b/www/src/content/docs/form/reference.md @@ -11,7 +11,7 @@ sidebar: The adapter option `injectMiddleware` allows you to opt-out of middleware injection used to expose [`Astro.locals.form`](form/parse/#astrolocalsform). This could be useful if you want to add your own data retrieval and `POST` handling logic. -```ts ins={3,7-9} +```ts ins={8} // astro.config.ts import { defineConfig } from 'astro/config'; import simpleStackForm from 'simple-stack-form';