Last active
October 4, 2023 09:28
-
-
Save unnoq/02c10bb02b8c63a0b34a70f12bd905d4 to your computer and use it in GitHub Desktop.
trpc-simulation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { z } from 'zod'; | |
type Innput<TShape extends z.Schema> = { | |
innput: TShape; | |
config: any; | |
}; | |
type Fnn<TShape extends z.Schema> = (input: z.infer<TShape>) => void; | |
const fn: <TShape extends z.Schema, TFn extends Fnn<TShape>>( | |
innput: Innput<TShape>, | |
fnc: TFn | |
) => { fn: TFn; inn: Innput<TShape> } = (inn, fn) => ({ inn, fn }); | |
// const router: <T>(inq: T) => T = (i) => i | |
const inngest = { fn }; | |
const buildClientHelper: <TRouter extends Record<string, ReturnType<typeof fn>>, TKey extends keyof TRouter>( | |
router: TRouter | |
) => (event: TKey, input: z.infer<TRouter[TKey]['inn']['innput']>) => void = (router) => { | |
return (key, innput) => { | |
router[key].inn.innput; | |
}; | |
}; | |
// const buildClient = <TRouter extends Record<string, Innput<any>>>( | |
// router: TRouter | |
// ) => buildClientHelper<TRouter, keyof TRouter>(router); | |
const inngestRouter = { | |
'some/func': inngest.fn( | |
{ | |
innput: z.object({ | |
name2: z.string(), | |
name3: z.object({ | |
c: z.number().nullable(), | |
}), | |
}), | |
config: null, | |
}, | |
(input) => { | |
return 1; | |
} | |
), | |
}; | |
export const sendInngestEvent = buildClientHelper(inngestRouter); | |
const a = sendInngestEvent('some/func', { name2: 'hii', name3: { c: null } }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { z } from 'zod'; | |
type JsonZod = z.ZodString | z.ZodNumber; | |
type SafeZodObject = z.ZodObject<Record<string, JsonZod>>; | |
type Innput<TShape extends SafeZodObject> = { | |
innput: TShape; | |
config: any; | |
}; | |
const fn: <TShape extends SafeZodObject>( | |
innput: Innput<TShape>, | |
fnc: (innput: z.infer<TShape>) => void | |
) => Innput<TShape> = (i) => i; | |
const router: <T>(inq: T) => T = (i) => i; | |
const inngest = { fn, router }; | |
const buildClientHelper: <TRouter extends Record<string, Innput<any>>, TKey extends keyof TRouter>( | |
router: TRouter | |
) => (event: TKey, input: z.infer<TRouter[TKey]['innput']>) => null = () => () => null; | |
const buildClient = <TRouter extends Record<string, Innput<any>>>(router: TRouter) => | |
buildClientHelper<TRouter, keyof TRouter>(router); | |
const inngestRouter = inngest.router({ | |
'some/func': inngest.fn( | |
{ | |
innput: z.object({ | |
name: z.string(), | |
}), | |
config: null, | |
}, | |
(input) => { | |
return 1; | |
} | |
), | |
}); | |
export const sendInngestEvent = buildClient(inngestRouter); | |
const a = sendInngestEvent('some/func', { name: 'hii' }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment