mirror of
https://github.com/versia-pub/server.git
synced 2025-12-06 08:28:19 +01:00
refactor(plugin): ♻️ Use enum instead of strings
This commit is contained in:
parent
98f8ec071c
commit
8a774fa05d
|
|
@ -1,4 +1,5 @@
|
|||
import { z } from "zod";
|
||||
import { Hooks } from "./hooks";
|
||||
import { Plugin, PluginConfigManager } from "./plugin";
|
||||
import type { Manifest } from "./schema";
|
||||
|
||||
|
|
@ -7,14 +8,16 @@ const myManifest: Manifest = {
|
|||
description: "A plugin for my app",
|
||||
version: "1.0.0",
|
||||
};
|
||||
|
||||
const configManager = new PluginConfigManager(
|
||||
z.object({
|
||||
apiKey: z.string(),
|
||||
}),
|
||||
);
|
||||
|
||||
const myPlugin = new Plugin(myManifest, configManager);
|
||||
|
||||
myPlugin.registerHandler("request", (req) => {
|
||||
myPlugin.registerHandler(Hooks.Response, (req) => {
|
||||
console.info("Request received:", req);
|
||||
return req;
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,4 +1,9 @@
|
|||
export enum Hooks {
|
||||
Request = "request",
|
||||
Response = "response",
|
||||
}
|
||||
|
||||
export type ServerHooks = {
|
||||
request: (request: Request) => Request;
|
||||
response: (response: Response) => Response;
|
||||
[Hooks.Request]: (request: Request) => Request;
|
||||
[Hooks.Response]: (response: Response) => Response;
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in a new issue