mirror of
https://github.com/versia-pub/server.git
synced 2025-12-06 16:38: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 { z } from "zod";
|
||||||
|
import { Hooks } from "./hooks";
|
||||||
import { Plugin, PluginConfigManager } from "./plugin";
|
import { Plugin, PluginConfigManager } from "./plugin";
|
||||||
import type { Manifest } from "./schema";
|
import type { Manifest } from "./schema";
|
||||||
|
|
||||||
|
|
@ -7,14 +8,16 @@ const myManifest: Manifest = {
|
||||||
description: "A plugin for my app",
|
description: "A plugin for my app",
|
||||||
version: "1.0.0",
|
version: "1.0.0",
|
||||||
};
|
};
|
||||||
|
|
||||||
const configManager = new PluginConfigManager(
|
const configManager = new PluginConfigManager(
|
||||||
z.object({
|
z.object({
|
||||||
apiKey: z.string(),
|
apiKey: z.string(),
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
const myPlugin = new Plugin(myManifest, configManager);
|
const myPlugin = new Plugin(myManifest, configManager);
|
||||||
|
|
||||||
myPlugin.registerHandler("request", (req) => {
|
myPlugin.registerHandler(Hooks.Response, (req) => {
|
||||||
console.info("Request received:", req);
|
console.info("Request received:", req);
|
||||||
return req;
|
return req;
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,9 @@
|
||||||
|
export enum Hooks {
|
||||||
|
Request = "request",
|
||||||
|
Response = "response",
|
||||||
|
}
|
||||||
|
|
||||||
export type ServerHooks = {
|
export type ServerHooks = {
|
||||||
request: (request: Request) => Request;
|
[Hooks.Request]: (request: Request) => Request;
|
||||||
response: (response: Response) => Response;
|
[Hooks.Response]: (response: Response) => Response;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue