Skip to content

Instantly share code, notes, and snippets.

View itsRems's full-sized avatar

Nicolas Theck itsRems

View GitHub Profile
@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) => {
@itsRems
itsRems / extractEnv.ts
Created February 19, 2022 01:49
Simple, shitty way of extracting .env's in nested folders, in ex. inside monorepos
import { existsSync, readFileSync } from "fs";
import { join } from "path";
export const production = process.env.NODE_ENV === 'production';
const envMap: {
[key: string]: Record<string, string>
} = {};
function getEnv (dirname: string, maxIteration: number = 10, currentIteration: number = 0): Record<string, string> {
@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>