diff --git a/classes/plugin/loader.test.ts b/classes/plugin/loader.test.ts index 8e8fc95f..1d3ddbec 100644 --- a/classes/plugin/loader.test.ts +++ b/classes/plugin/loader.test.ts @@ -154,14 +154,7 @@ describe("PluginLoader", () => { }); test("loadPlugin should load and return a Plugin instance", async () => { - const mockPlugin = new Plugin( - { - name: "test-plugin", - version: "1.1.0", - description: "Doobaee", - }, - new PluginConfigManager(z.object({})), - ); + const mockPlugin = new Plugin(new PluginConfigManager(z.object({}))); mock.module("/some/path/index.ts", () => ({ default: mockPlugin, })); @@ -186,10 +179,7 @@ describe("PluginLoader", () => { version: "1.1.0", description: "Doobaee", }; - const mockPlugin = new Plugin( - manifestContent, - new PluginConfigManager(z.object({})), - ); + const mockPlugin = new Plugin(new PluginConfigManager(z.object({}))); mockReaddir .mockResolvedValueOnce([ diff --git a/packages/plugin-kit/example.ts b/packages/plugin-kit/example.ts index 5c164ade..1d3e68e5 100644 --- a/packages/plugin-kit/example.ts +++ b/packages/plugin-kit/example.ts @@ -1,13 +1,6 @@ import { z } from "zod"; import { Hooks } from "./hooks"; import { Plugin, PluginConfigManager } from "./plugin"; -import type { Manifest } from "./schema"; - -const myManifest: Manifest = { - name: "my-plugin", - description: "A plugin for my app", - version: "1.0.0", -}; const configManager = new PluginConfigManager( z.object({ @@ -15,7 +8,7 @@ const configManager = new PluginConfigManager( }), ); -const myPlugin = new Plugin(myManifest, configManager); +const myPlugin = new Plugin(configManager); myPlugin.registerHandler(Hooks.Response, (req) => { console.info("Request received:", req); diff --git a/packages/plugin-kit/plugin.ts b/packages/plugin-kit/plugin.ts index cde98bc7..140f2b97 100644 --- a/packages/plugin-kit/plugin.ts +++ b/packages/plugin-kit/plugin.ts @@ -4,7 +4,6 @@ import type { z } from "zod"; import { type ZodError, fromZodError } from "zod-validation-error"; import type { HonoEnv } from "~/types/api"; import type { ServerHooks } from "./hooks"; -import { type Manifest, manifestSchema } from "./schema"; export type HonoPluginEnv = HonoEnv & { Variables: { @@ -19,12 +18,7 @@ export class Plugin { fn: (app: OpenAPIHono>) => void; }[] = []; - constructor( - private manifest: Manifest, - private configManager: PluginConfigManager, - ) { - this.validateManifest(manifest); - } + constructor(private configManager: PluginConfigManager) {} get middleware() { // Middleware that adds the plugin's configuration to the request object @@ -36,10 +30,6 @@ export class Plugin { ); } - public getManifest() { - return this.manifest; - } - public registerRoute( path: string, fn: (app: OpenAPIHono>) => void, @@ -76,19 +66,10 @@ export class Plugin { this.handlers[hook] = handler; } - private validateManifest(manifest: Manifest) { - try { - manifestSchema.parse(manifest); - } catch (error) { - throw fromZodError(error as ZodError); - } - } - static [Symbol.hasInstance](instance: unknown): boolean { return ( typeof instance === "object" && instance !== null && - "getManifest" in instance && "registerHandler" in instance ); } diff --git a/packages/plugin-kit/tests/manifest.test.ts b/packages/plugin-kit/tests/manifest.test.ts deleted file mode 100644 index 5ab888cd..00000000 --- a/packages/plugin-kit/tests/manifest.test.ts +++ /dev/null @@ -1,49 +0,0 @@ -import { describe, expect, it } from "bun:test"; -import { z } from "zod"; -import { Plugin, PluginConfigManager } from "../plugin"; -import type { Manifest } from "../schema"; - -describe("Manifest parsing tests", () => { - it("should parse a valid manifest", () => { - const manifest: Manifest = { - name: "plugin", - version: "1.0.0", - description: "A test plugin", - authors: [ - { - name: "Author", - email: "bob@joe.com", - url: "https://example.com", - }, - ], - repository: { - type: "git", - url: "https://example.com", - }, - }; - - const plugin = new Plugin( - manifest, - new PluginConfigManager(z.string()), - ); - - expect(plugin.getManifest()).toEqual(manifest); - }); - - it("should throw an error for an invalid manifest", () => { - const manifest = { - name: "plugin", - silly: "Manifest", - }; - - expect( - () => - new Plugin( - manifest as unknown as Manifest, - new PluginConfigManager(z.string()), - ), - ).toThrowError( - `Validation error: Required at "version"; Required at "description"`, - ); - }); -}); diff --git a/plugins/openid/index.ts b/plugins/openid/index.ts index 9d827979..3e8292ca 100644 --- a/plugins/openid/index.ts +++ b/plugins/openid/index.ts @@ -1,13 +1,7 @@ -import { Hooks, type Manifest, Plugin, PluginConfigManager } from "@versia/kit"; +import { Hooks, Plugin, PluginConfigManager } from "@versia/kit"; import { z } from "zod"; import authorizeRoute from "./routes/authorize"; -const myManifest: Manifest = { - name: "@versia/openid", - description: "OpenID authentication.", - version: "0.1.0", -}; - const configManager = new PluginConfigManager( z.object({ forced: z.boolean().default(false), @@ -65,7 +59,7 @@ const configManager = new PluginConfigManager( }), ); -const plugin = new Plugin(myManifest, configManager); +const plugin = new Plugin(configManager); plugin.registerHandler(Hooks.Response, (req) => { console.info("Request received:", req);