UNPKG

pusher-zod

Version:

Pusher with type safety using Zod to parse the data

46 lines (43 loc) 3.18 kB
import PusherServer from 'pusher'; import { z } from 'zod'; declare function createPusherServer<S extends Record<string, Record<string, z.ZodType<any, any>>>, P extends Partial<Record<string, z.ZodType<any, any>>> = Record<string, never>>({ setup, channel_id_separator, userEvents, }: { setup: S; channel_id_separator?: "_" | "-" | "=" | "@" | "," | "." | ";"; userEvents?: P; }): { TypeSafePusherServer: { new (opts: PusherServer.Options): { invoke<K extends keyof S, E extends keyof S[K]>(channelName: K extends string ? K : never, channel_id: K extends string ? string : never, eventName: E extends string ? E : never, data: z.TypeOf<S[K][E]>): Promise<PusherServer.Response>; invokeBatch<K extends keyof S, E extends keyof S[K]>(batch: { channel: K; channel_id: string | number; name: E; data: z.TypeOf<S[K][E]>; socket_id?: string; info?: any; }[]): Promise<PusherServer.Response>; sendToUser<E extends keyof P>(userId: string, event: E, data: z.infer<Exclude<P[E], undefined>>): Promise<PusherServer.Response>; getChannels<K extends keyof S>(): Array<K>; getPrivateChannels<K extends keyof S>(): Array<Extract<K, `private-${string}`>>; getPresenceChannels<K extends keyof S>(): Array<Extract<keyof S, `presence-${string}`>>; isPrivateChannel<K extends keyof S>(channel: K): channel is Extract<K, `private-${string}`>; isPresenceChannel<K extends keyof S>(channel: K): channel is Extract<K, `presence-${string}`>; trigger(channel: string | Array<string>, event: string, data: any, params?: PusherServer.TriggerParams): Promise<PusherServer.Response>; trigger(channel: string | Array<string>, event: string, data: any): Promise<PusherServer.Response>; triggerBatch(events: Array<PusherServer.BatchEvent>): Promise<PusherServer.Response>; get(opts: PusherServer.GetOptions): Promise<PusherServer.Response>; post(opts: PusherServer.PostOptions): Promise<PusherServer.Response>; authenticate(socketId: string, channel: string, data?: PusherServer.PresenceChannelData): PusherServer.ChannelAuthResponse; authorizeChannel(socketId: string, channel: string, data?: PusherServer.PresenceChannelData): PusherServer.ChannelAuthResponse; authenticateUser(socketId: string, userData: PusherServer.UserChannelData): PusherServer.UserAuthResponse; terminateUserConnections(userId: string): Promise<PusherServer.Response>; webhook(request: PusherServer.WebHookRequest): PusherServer.WebHook; createSignedQueryString(opts: PusherServer.SignedQueryStringOptions): string; }; forCluster(cluster: string, opts: PusherServer.BaseOptions): PusherServer; forURL(connectionString: string, opts?: Partial<PusherServer.Options>): PusherServer; WebHook: typeof PusherServer.WebHook; Response: typeof PusherServer.Response; }; }; export { createPusherServer, createPusherServer as default };