From c4d4378c50cfc6e89e9f13c3c0ae3ad52f8bbbcd Mon Sep 17 00:00:00 2001 From: Florian Lefebvre Date: Mon, 29 Apr 2024 19:36:02 +0200 Subject: [PATCH] chore: add changeset --- .changeset/green-deers-trade.md | 57 +++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 .changeset/green-deers-trade.md diff --git a/.changeset/green-deers-trade.md b/.changeset/green-deers-trade.md new file mode 100644 index 0000000000..065e7e520a --- /dev/null +++ b/.changeset/green-deers-trade.md @@ -0,0 +1,57 @@ +--- +"astro": minor +"@astrojs/db": minor +--- + +Adds a new `defineIntegration` helper and reworks typings for integrations authors extending Astro DB. + +This release adds a new `defineIntegration` helper through the `astro/integration` import that allows to define a type-safe integration and handle options validation (not required): + +```ts +import { defineIntegration } from "astro/integration" +import { z } from "astro/zod" + +export const integration = defineIntegration({ + name: "my-integration", + // optional + optionsSchema: z.object({ id: z.string() }), + setup({ options }) { + return { + hooks: { + "astro:config:setup": (params) => { + // ... + } + } + } + } +}) +``` + +Astro DB `defineDbIntegration` has been removed in favor of a way that works with this new `defineIntegration` (but also the `AstroIntegration` type): + +```ts +import {} from "astro" +import { defineIntegration } from "astro/integration" +import type { AstroDbHooks } from "@astrojs/db/types" + +declare module "astro" { + interface AstroIntegrationHooks extends AstroDbHooks {} +} + +export default defineIntegration({ + name: "db-test-integration", + setup() { + return { + hooks: { + 'astro:db:setup': ({ extendDb }) => { + extendDb({ + configEntrypoint: './integration/config.ts', + seedEntrypoint: './integration/seed.ts', + }); + }, + }, + } + } +}) + +``` \ No newline at end of file