domi?
domi?
TTCTheo's Typesafe Cult
Created by domi? on 8/13/2023 in #questions
How do tRPC WebSockets work with NextJS
Hey! I've recently stumbled upon this repo: https://github.com/trpc/examples-next-prisma-websockets-starter. I'm a little confused on how it would be able to hold a connection with a serverless environment.
20 replies
TTCTheo's Typesafe Cult
Created by domi? on 6/2/2023 in #questions
React.FC equivalent for RSC
Is there a "React.FC" equivalent for React Server Components?
14 replies
TTCTheo's Typesafe Cult
Created by domi? on 5/2/2023 in #questions
Prisma middleware infinite loop
Hey 👋 I have a separate table in my db that's responsible for storing logs of actions. I want to simplify the dx by creating a Prisma middleware that will automatically create these logs. This is my current implementation:
prisma.$use(async (params, next) => {
const { model, action } = params;

if (model === 'Todo' && (action === 'create')) {
await prisma.logEntry.create({
data: {
type: 'CREATED_TODO',
user: {
connect: {
id: params.args.data.userId
}
}
}
});
}

return next(params);
});
prisma.$use(async (params, next) => {
const { model, action } = params;

if (model === 'Todo' && (action === 'create')) {
await prisma.logEntry.create({
data: {
type: 'CREATED_TODO',
user: {
connect: {
id: params.args.data.userId
}
}
}
});
}

return next(params);
});
However, I'd like to improve this to be batching these db calls into one prisma.$transaction():
const result = await prisma.$transaction([
prisma.todo.create(params.args),
prisma.logEntry.create({
data: {
type: 'CREATED_TODO',
user: {
connect: {
id: params.args.data.userId
}
}
}
})
]);
const result = await prisma.$transaction([
prisma.todo.create(params.args),
prisma.logEntry.create({
data: {
type: 'CREATED_TODO',
user: {
connect: {
id: params.args.data.userId
}
}
}
})
]);
However, this causes an infinite loop, because prisma.todo.create() calls the middleawre again. Any suggestions on how to get around this?
2 replies
TTCTheo's Typesafe Cult
Created by domi? on 3/13/2023 in #questions
Dev stack for almost completely static website
Hi 👋 I'm about to build a very small, 1 page website, with no dynamic data or any reactivity really. Just a site to display some info and put a contant number. Maybe in the future add a small form and minor reactivity, but not for now. My question is, what is the best way to approach this quick project? I think most frameworks would be overkill here, what's best? Thanks
5 replies
TTCTheo's Typesafe Cult
Created by domi? on 1/17/2023 in #questions
Local Database for Vercel hosted api functions
Hey waveBoye wondering if its possible to use file system based local databases for Nextjs functions. Even just using node fs, or something like https://github.com/typicode/lowdb
10 replies
TTCTheo's Typesafe Cult
Created by domi? on 1/4/2023 in #questions
NextAuth wrong error redirect
hey 👋 Each time there is an error, I get redirected back to the login page instead of the error page. Any ideas why? Example after an error: http://localhost:3000/auth/login?callbackUrl=http%3A%2F%2Flocalhost%3A3000%2Fauth%2Flinked-accounts&error=OAuthAccountNotLinked
2 replies
TTCTheo's Typesafe Cult
Created by domi? on 1/2/2023 in #questions
Overwrite the default types of AdapterUser
Hey 👋 I'm writign a custom adapter for Next Auth, and it breaks quite a lot of the default behavior, so I'd like to modify the default types provided. For some reason, it's not letting me, any ideas why?
2 replies
TTCTheo's Typesafe Cult
Created by domi? on 12/26/2022 in #questions
Prisma - differences between id, unique, and index
Hey 👋, Could someone explain the difference between @id, @unique, and @index?
30 replies
TTCTheo's Typesafe Cult
Created by domi? on 12/22/2022 in #questions
tRPC SSG - Page rendering error
7 replies
TTCTheo's Typesafe Cult
Created by domi? on 12/17/2022 in #questions
TailwindCSS Plugin - Allow arbitrary values
Hey 👋 I'm creating a TailwindCSS plugin, and I'd like to allow for arbitrary values. I couldn't find a setting where I can enable that. Any ideas?
2 replies
TTCTheo's Typesafe Cult
Created by domi? on 12/11/2022 in #questions
tRPC prefetching for Electron app
Hey 👋 I have a pretty basic Electron app, where I use tRPC to communicate with the server. I'd like to prefetch all the endpoints I'll need and display a loading screen, so that once the app is loaded the isn't any loading between switching pages. I saw that tRPC has a prefetch API for NextJS, is there something similar I could use in this situation?
3 replies
TTCTheo's Typesafe Cult
Created by domi? on 12/9/2022 in #questions
Next Auth sessions not working in production only
2 replies
TTCTheo's Typesafe Cult
Created by domi? on 11/17/2022 in #questions
Module augmentation - Typesafe Electron IPC
Hey 👋 I want to extend the Electron type definitions to make the channels for IPC communication more typesafe. For this, I'll need to override the types of the class BrowserWindow. Only the types, the underlying JavaScript will be the same. The problem is, I can't figure out how to override the electron module type defintions without running into Duplicate identifier or Cannot redeclare block-scoped variable.
2 replies
TTCTheo's Typesafe Cult
Created by domi? on 11/15/2022 in #questions
Really weird TypeScript behavior
Hey. I have this really weird type inference error. So the types do get inferred correctly, as you can see in the first screenshot below. However, when I actually want to call the function the types disappear and become type never 👀 The type inference correctly picks up the fact that the function parameters can either be "1" and no arguments, or "2" and no arguments.
7 replies
TTCTheo's Typesafe Cult
Created by domi? on 11/14/2022 in #questions
TypeScript Mapped Types
Hey. I have this type which uses mapped types to generate this other type. It works a little bit, but I'd like it to generate a different type of type union.
3 replies
TTCTheo's Typesafe Cult
Created by domi? on 11/13/2022 in #questions
TypeScript Generics
Hey. I need some help with TypeScript generics
21 replies
TTCTheo's Typesafe Cult
Created by domi? on 11/11/2022 in #questions
Type error at custom fetch function for tRPC client
6 replies
TTCTheo's Typesafe Cult
Created by domi? on 11/8/2022 in #questions
tRPC React - why the useState hook?
Hey. I've been following the docs for setting up tRPC for a React based project. I noted in the docs that they recommend wrapping the tRPC client into a useState(). Could someone explain why?
21 replies
TTCTheo's Typesafe Cult
Created by domi? on 11/6/2022 in #questions
Turbopack + Electron
Could I use Turbopack to bundle an Electron app?
8 replies
TTCTheo's Typesafe Cult
Created by domi? on 11/4/2022 in #questions
Exporting tRPC routes to another project
Hi everyone. I'm currently running an Electron app, which contains the main project. I also have a NextJS app which handles the website for the download of the Electron app, and it has the application's API un der pages/api, which the Electron app communicates with. I really like using tRPC, so I was wondering if it's possible to somehow infer the tRPC types across the two projects. (These two projects are under different repos)
5 replies