I am a Dev
I am a Dev
TtRPC
Created by I am a Dev on 10/14/2023 in #❓-help
Hello, is there any way to create a base router with common procedures? like an interface
I want all routers that use it have the state procedure (subscriptions), so I can create a common hook later Although the implementation of the methods is completely different on each router, I just want to guarantee that they have those procedures, like an interface The hook basically will subscribe to the state on mount, and unsubscribe on unmount Thanks
8 replies
TtRPC
Created by I am a Dev on 10/6/2023 in #❓-help
There is a logger middleware like morgan for express?
There is a package with a nice logger middleware? Thanks
2 replies
TtRPC
Created by I am a Dev on 10/3/2023 in #❓-help
Review of inner and outer context with express
Hello, I didn't find any example that uses inner (for testing) and outer context with express. That's how I implemented it for my express trpc boilerplate, I wanted to know if I did it right, or if there was some error. Thank you so much TLDR; The inner context and options is a custom object with partial express options. the outer context and options is an extension of the inner but now the express options are mandatory.
import { initTRPC } from '@trpc/server';
import type * as trpcExpress from '@trpc/server/adapters/express';
import superjson from 'superjson';
import type { OpenApiMeta } from 'trpc-openapi';

// Fake prisma
const prisma = 'prisma';

export interface CreateInnerTRPCContextOptions
extends Partial<trpcExpress.CreateExpressContextOptions> {}

export interface AppInnerContext
extends Partial<trpcExpress.CreateExpressContextOptions> {
prisma: string;
}

export async function createInnerTRPCContext(
_opts: CreateInnerTRPCContextOptions,
): Promise<AppInnerContext> {
return {
prisma,
};
}

type CreateTRPCContextOptions = CreateInnerTRPCContextOptions &
trpcExpress.CreateExpressContextOptions;

export type AppContext = AppInnerContext &
trpcExpress.CreateExpressContextOptions;

export async function createTRPCContext(
opts: CreateTRPCContextOptions,
): Promise<AppContext> {
const innerContext = await createInnerTRPCContext(opts);

return {
...innerContext,
req: opts.req,
res: opts.res,
};
}

const t = initTRPC.meta<OpenApiMeta>().context<AppInnerContext>().create({
transformer: superjson,
});

export const createTRPCRouter = t.router;

export const publicProcedure = t.procedure;
import { initTRPC } from '@trpc/server';
import type * as trpcExpress from '@trpc/server/adapters/express';
import superjson from 'superjson';
import type { OpenApiMeta } from 'trpc-openapi';

// Fake prisma
const prisma = 'prisma';

export interface CreateInnerTRPCContextOptions
extends Partial<trpcExpress.CreateExpressContextOptions> {}

export interface AppInnerContext
extends Partial<trpcExpress.CreateExpressContextOptions> {
prisma: string;
}

export async function createInnerTRPCContext(
_opts: CreateInnerTRPCContextOptions,
): Promise<AppInnerContext> {
return {
prisma,
};
}

type CreateTRPCContextOptions = CreateInnerTRPCContextOptions &
trpcExpress.CreateExpressContextOptions;

export type AppContext = AppInnerContext &
trpcExpress.CreateExpressContextOptions;

export async function createTRPCContext(
opts: CreateTRPCContextOptions,
): Promise<AppContext> {
const innerContext = await createInnerTRPCContext(opts);

return {
...innerContext,
req: opts.req,
res: opts.res,
};
}

const t = initTRPC.meta<OpenApiMeta>().context<AppInnerContext>().create({
transformer: superjson,
});

export const createTRPCRouter = t.router;

export const publicProcedure = t.procedure;
2 replies
TtRPC
Created by I am a Dev on 10/3/2023 in #❓-help
Should i use lint rule explicit-function-return-type when use trpc?
No description
2 replies
TtRPC
Created by I am a Dev on 10/1/2023 in #❓-help
Name recommendations for my api endpoints that use swagger, trpc-panel, trpc-playground.
What name do you recommend for each one, in addition to the rest api and the trpc api endpoints. Like /api /trpc /trpc/panel Thanks
3 replies
TtRPC
Created by I am a Dev on 10/1/2023 in #❓-help
In the context should I put all my dependencies for my endpoint handlers?
For example I have the end point 'getStuff` In this endpoint the handler call 3 party apis and map the data to the tRPC output. But I have an API key rotator class, to do each request to a 3 party API with the different API key in each request. So should I put in the context the API key rotator class? And this should be a singleton like the db instance? Also the API key rotator has dependency on the db, to store the last used API key, and consult all API keys. Thanks
2 replies
TtRPC
Created by I am a Dev on 9/30/2023 in #❓-help
How to return a stream? like open ai api
I want that my api can have stream responses like open ai https://github.com/openai/openai-node#streaming-responses how can i do it? Thanks
5 replies
TtRPC
Created by I am a Dev on 9/29/2023 in #❓-help
I have an api with trpc, how can I consume it from dart/flutter?
2 replies
TtRPC
Created by I am a Dev on 9/28/2023 in #❓-help
Is there a guide of how to test?
I'm usually use vitest but in frontend of shared packages. I'm frontend trying to create my first api 🙂 Thanks
2 replies
TtRPC
Created by I am a Dev on 9/28/2023 in #❓-help
is there a simple boilerplate that has everything ready to deploy?
For example nodemon, reading the port for .env, etc. (I don't know if that's how it is haha) I use turborepo, so can be an internal package. But I want to see how the project configuration looks for the deploy. It's the first time I am creating a server, for now it will be deployed on a PC on an intranet. It's just a server to everyone in the intranet can access and modify a json file. Thanks
4 replies
TtRPC
Created by I am a Dev on 9/26/2023 in #❓-help
In a monorepo can I have 2 packages each one with different trpc server, and use both in 1 app?
I want to create 2 different APIs, and in my monorepo I have several apps, in some I want to use both, in others only 1 Thanks
5 replies
TtRPC
Created by I am a Dev on 9/26/2023 in #❓-help
Have you used electron-trpc? how does it work for you? Do you recommend it?
2 replies