bun-ws-router
Version:
A simple and efficient WebSocket router for Bun with Zod/Valibot message validation.
25 lines • 841 B
JavaScript
/* SPDX-FileCopyrightText: 2025-present Kriasoft */
/* SPDX-License-Identifier: MIT */
import * as v from "valibot";
export class ValibotValidatorAdapter {
getMessageType(schema) {
// In Valibot, we need to extract the literal value from the schema
const typeSchema = schema.entries.type;
if (typeSchema && typeSchema.type === "literal") {
return typeSchema.literal;
}
throw new Error("Schema must have a literal type field");
}
safeParse(schema, data) {
const result = v.safeParse(schema, data);
return {
success: result.success,
data: result.success ? result.output : undefined,
error: result.success ? undefined : result.issues,
};
}
infer() {
return {};
}
}
//# sourceMappingURL=adapter.js.map