Skip to content

Instantly share code, notes, and snippets.

View itsRems's full-sized avatar

Nicolas Theck itsRems

View GitHub Profile
@itsRems
itsRems / zod-prisma-select.ts
Last active June 14, 2024 10:13
Transforms zod objects into prisma-compatible `select` objects
import { z } from "zod";
export type ZodPrismaSelectInnerMapper<T extends z.ZodTypeAny> =
T extends z.ZodObject<infer Shape>
? {
select: {
[K in keyof Shape]: ZodPrismaSelectInnerMapper<Shape[K]>;
};
}
: T extends z.ZodArray<infer Item>
@itsRems
itsRems / loader.ts
Last active June 21, 2022 14:44
Fastify route loader
import { FastifyInstance, RouteOptions } from "fastify";
import { join } from "path";
import { walk } from "walk";
export async function registerRoutes(server: FastifyInstance, routesDir: string = 'routes') {
return await new Promise((resolve) => {
const path = join(`${__dirname}/${routesDir}`);
const files: string[] = [];
const walker = walk(path);
walker.on('file', (root, { name }, next) => {
@timcole
timcole / log.js
Last active February 16, 2020 00:22
Custom Log Example
export function Log(caller = "Router", ...logs) {
console.log(
`%c Notify.me %c ${caller} `,
"background: #a36ad8; color: #e8e8e8; border-radius: 3px 0 0 3px;",
"background: #6e4693; color: #e8e8e8; border-radius: 0 3px 3px 0;",
...logs
);
}