From 1701a07a6c696fdc8d8fa9fbf2c2010b87c462cb Mon Sep 17 00:00:00 2001 From: kodemon Date: Mon, 21 Apr 2025 23:15:08 +0000 Subject: [PATCH] fix: zod request type --- libraries/request.ts | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/libraries/request.ts b/libraries/request.ts index d9ff296..097d05f 100644 --- a/libraries/request.ts +++ b/libraries/request.ts @@ -1,10 +1,37 @@ -import z from "zod"; +import z, { ZodLiteral, ZodNumber, ZodObject, ZodOptional, ZodString, ZodUnion, ZodUnknown } from "zod"; -export const request = z.object({ +export const request: ZodObject<{ + relay: ZodLiteral<"1.0">; + method: ZodString; + params: ZodOptional; + id: ZodUnion<[ZodString, ZodNumber]>; +}> = z.object({ relay: z.literal("1.0"), method: z.string(), - params: z.unknown(), + params: z.unknown().optional(), id: z.string().or(z.number()), }); -export type RelayRequest = z.infer; +export type RelayRequest = { + /** + * String specifying the version of the relay protocol. MUST be exactly "1.0". + */ + relay: "1.0"; + + /** + * String containing the name of the method to be invoked. + */ + method: string; + + /** + * Structured value that holds the parameter values to be used during the + * invocation of the method. + */ + params?: unknown; + + /** + * An identifier established by the Client that MUST contain a String, or non + * fractional Number value. + */ + id: string | number; +};