├── .husky ├── .gitignore ├── pre-commit └── commit-msg ├── .watchmanconfig ├── docs ├── .npmrc ├── tsconfig.build.json ├── public │ ├── logo.png │ ├── banner.png │ ├── favicon.ico │ ├── preview.png │ ├── docs-logo.png │ ├── favicon │ │ ├── favicon.ico │ │ ├── favicon-16x16.png │ │ ├── favicon-32x32.png │ │ ├── apple-touch-icon.png │ │ ├── android-chrome-192x192.png │ │ ├── android-chrome-512x512.png │ │ └── site.webmanifest │ ├── robots.txt │ ├── sitemap.xml │ ├── icons │ │ ├── npm.svg │ │ ├── pnpm.svg │ │ ├── yarn.svg │ │ ├── typescript.svg │ │ └── trpc.svg │ └── sitemap-0.xml ├── postcss.config.js ├── .eslintrc.json ├── pages │ ├── index.mdx │ ├── _app.mdx │ ├── _meta.json │ └── docs │ │ ├── _meta.json │ │ ├── dependency-injection.mdx │ │ ├── nestjs.mdx │ │ ├── graphql.mdx │ │ ├── structure.mdx │ │ ├── trpc.mdx │ │ ├── index.mdx │ │ └── integrations.mdx ├── types │ └── index.ts ├── next-sitemap.config.js ├── next-env.d.ts ├── svgr.d.ts ├── utils │ └── searchParams.ts ├── .gitignore ├── components │ ├── Iframe │ │ └── index.tsx │ ├── FeatureCard │ │ └── index.tsx │ ├── Footer │ │ └── index.tsx │ ├── Table │ │ └── index.tsx │ ├── Preview │ │ └── index.tsx │ └── Home │ │ └── index.tsx ├── tailwind.config.js ├── tsconfig.json ├── package.json ├── next.config.js ├── styles │ └── globals.css └── theme.config.jsx ├── .yarnrc.yml ├── .prettierrc ├── .prettierignore ├── packages ├── nestjs-trpc │ ├── lib │ │ ├── drivers │ │ │ ├── index.ts │ │ │ ├── express.driver.ts │ │ │ └── fastify.driver.ts │ │ ├── trpc.enum.ts │ │ ├── index.ts │ │ ├── generators │ │ │ ├── generator.constants.ts │ │ │ ├── generator.interface.ts │ │ │ ├── __tests__ │ │ │ │ ├── context.generator.spec.ts │ │ │ │ ├── middleware.generator.spec.ts │ │ │ │ ├── procedure.generator.spec.ts │ │ │ │ └── decorator.generator.spec.ts │ │ │ ├── static.generator.ts │ │ │ ├── context.generator.ts │ │ │ ├── decorator.generator.ts │ │ │ ├── router.generator.ts │ │ │ ├── generator.module.ts │ │ │ └── middleware.generator.ts │ │ ├── interfaces │ │ │ ├── scanner.interface.ts │ │ │ ├── index.ts │ │ │ ├── procedure-options.interface.ts │ │ │ ├── context.interface.ts │ │ │ ├── middleware.interface.ts │ │ │ ├── generator.interface.ts │ │ │ ├── module-options.interface.ts │ │ │ └── factory.interface.ts │ │ ├── utils │ │ │ ├── ts-morph.util.ts │ │ │ └── validate-each.util.ts │ │ ├── scanners │ │ │ ├── scanner.module.ts │ │ │ ├── file.scanner.ts │ │ │ └── imports.scanner.ts │ │ ├── decorators │ │ │ ├── index.ts │ │ │ ├── context.decorator.ts │ │ │ ├── query.decorator.ts │ │ │ ├── mutation.decorator.ts │ │ │ ├── router.decorator.ts │ │ │ ├── path.decorator.ts │ │ │ ├── type.decorator.ts │ │ │ ├── options.decorator.ts │ │ │ ├── raw-input.decorator.ts │ │ │ ├── input.decorator.ts │ │ │ ├── __tests__ │ │ │ │ ├── middlewares.decorator.spec.ts │ │ │ │ ├── router.decorator.spec.ts │ │ │ │ ├── type.decorator.spec.ts │ │ │ │ ├── path.decorator.spec.ts │ │ │ │ ├── options.decorator.spec.ts │ │ │ │ ├── raw-input.decorator.spec.ts │ │ │ │ ├── input.decorator.spec.ts │ │ │ │ ├── context.decorator.spec.ts │ │ │ │ ├── query.decorator.spec.ts │ │ │ │ └── mutation.decorator.spec.ts │ │ │ └── middlewares.decorator.ts │ │ ├── trpc.constants.ts │ │ ├── app-router.host.ts │ │ ├── factories │ │ │ ├── factory.module.ts │ │ │ ├── trpc.factory.ts │ │ │ ├── __tests__ │ │ │ │ ├── trpc.factory.spec.ts │ │ │ │ └── middleware.factory.spec.ts │ │ │ ├── middleware.factory.ts │ │ │ └── router.factory.ts │ │ ├── trpc.module.ts │ │ └── trpc.driver.ts │ ├── .npmignore │ ├── tsconfig.spec.json │ ├── tsconfig.build.json │ ├── tsconfig.json │ ├── .gitignore │ ├── jest.config.js │ ├── package.json │ └── README.md ├── tsconfig.json └── tsconfig.build.json ├── examples ├── nextjs-trpc │ ├── next.config.js │ ├── postcss.config.js │ ├── app │ │ ├── trpc.ts │ │ ├── page.tsx │ │ ├── client-side.tsx │ │ ├── layout.tsx │ │ └── globals.css │ ├── .gitignore │ ├── tailwind.config.js │ ├── package.json │ └── tsconfig.json ├── tsconfig.json ├── nestjs-express │ ├── src │ │ ├── user.schema.ts │ │ ├── main.ts │ │ ├── user.controller.ts │ │ ├── user.service.ts │ │ ├── app.context.ts │ │ ├── trpc-panel.controller.ts │ │ ├── app.module.ts │ │ ├── protected.middleware.ts │ │ └── user.router.ts │ ├── tsconfig.build.json │ ├── tsconfig.json │ ├── .gitignore │ ├── nest-cli.json │ └── package.json ├── nestjs-fastify │ ├── src │ │ ├── user.schema.ts │ │ ├── user.service.ts │ │ ├── user.controller.ts │ │ ├── main.ts │ │ ├── app.context.ts │ │ ├── protected.middleware.ts │ │ ├── logging.middleware.ts │ │ ├── app.module.ts │ │ ├── trpc-panel.controller.ts │ │ └── user.router.ts │ ├── tsconfig.build.json │ ├── tsconfig.json │ ├── .gitignore │ ├── nest-cli.json │ └── package.json └── tsconfig.build.json ├── renovate.json ├── .npmignore ├── .gitignore ├── .commitlintrc.json ├── .github └── workflows │ └── verify.yml ├── .release-it.json ├── LICENSE ├── eslint.config.mjs ├── package.json └── README.md /.husky/.gitignore: -------------------------------------------------------------------------------- 1 | _ -------------------------------------------------------------------------------- /.watchmanconfig: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.husky/pre-commit: -------------------------------------------------------------------------------- 1 | yarn lint-staged -------------------------------------------------------------------------------- /docs/.npmrc: -------------------------------------------------------------------------------- 1 | package-manager-strict=false -------------------------------------------------------------------------------- /.husky/commit-msg: -------------------------------------------------------------------------------- 1 | yarn commitlint -c --config .commitlintrc.json -E --edit -------------------------------------------------------------------------------- /.yarnrc.yml: -------------------------------------------------------------------------------- 1 | nodeLinker: pnp 2 | pnpMode: strict 3 | enableTelemetry: false -------------------------------------------------------------------------------- /docs/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json" 3 | } 4 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "trailingComma": "all", 3 | "singleQuote": true 4 | } -------------------------------------------------------------------------------- /docs/public/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinEdry/nestjs-trpc/HEAD/docs/public/logo.png -------------------------------------------------------------------------------- /docs/public/banner.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinEdry/nestjs-trpc/HEAD/docs/public/banner.png -------------------------------------------------------------------------------- /docs/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinEdry/nestjs-trpc/HEAD/docs/public/favicon.ico -------------------------------------------------------------------------------- /docs/public/preview.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinEdry/nestjs-trpc/HEAD/docs/public/preview.png -------------------------------------------------------------------------------- /docs/public/docs-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinEdry/nestjs-trpc/HEAD/docs/public/docs-logo.png -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | coverage/ 3 | docs/ 4 | public/ 5 | *.md 6 | *.mdx 7 | packages/**/__tests__/*.ts -------------------------------------------------------------------------------- /packages/nestjs-trpc/lib/drivers/index.ts: -------------------------------------------------------------------------------- 1 | export * from './fastify.driver'; 2 | export * from './express.driver'; 3 | -------------------------------------------------------------------------------- /docs/public/favicon/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinEdry/nestjs-trpc/HEAD/docs/public/favicon/favicon.ico -------------------------------------------------------------------------------- /docs/postcss.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | plugins: { 3 | tailwindcss: {}, 4 | autoprefixer: {}, 5 | }, 6 | } 7 | -------------------------------------------------------------------------------- /packages/nestjs-trpc/lib/trpc.enum.ts: -------------------------------------------------------------------------------- 1 | export enum ProcedureType { 2 | Query = 'Query', 3 | Mutation = 'Mutation', 4 | } 5 | -------------------------------------------------------------------------------- /docs/.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "next/core-web-vitals", 3 | "rules": { 4 | "prettier/prettier": "warn" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /docs/public/favicon/favicon-16x16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinEdry/nestjs-trpc/HEAD/docs/public/favicon/favicon-16x16.png -------------------------------------------------------------------------------- /docs/public/favicon/favicon-32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinEdry/nestjs-trpc/HEAD/docs/public/favicon/favicon-32x32.png -------------------------------------------------------------------------------- /docs/public/favicon/apple-touch-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinEdry/nestjs-trpc/HEAD/docs/public/favicon/apple-touch-icon.png -------------------------------------------------------------------------------- /examples/nextjs-trpc/next.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('next').NextConfig} */ 2 | const nextConfig = {} 3 | 4 | module.exports = nextConfig -------------------------------------------------------------------------------- /examples/nextjs-trpc/postcss.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | plugins: { 3 | tailwindcss: {}, 4 | autoprefixer: {}, 5 | }, 6 | } -------------------------------------------------------------------------------- /docs/pages/index.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | title: "NestJS-tRPC: Bringing type-safety to NestJS" 3 | --- 4 | 5 | import Home from "../components/Home" 6 | 7 | -------------------------------------------------------------------------------- /docs/public/favicon/android-chrome-192x192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinEdry/nestjs-trpc/HEAD/docs/public/favicon/android-chrome-192x192.png -------------------------------------------------------------------------------- /docs/public/favicon/android-chrome-512x512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KevinEdry/nestjs-trpc/HEAD/docs/public/favicon/android-chrome-512x512.png -------------------------------------------------------------------------------- /docs/types/index.ts: -------------------------------------------------------------------------------- 1 | import { SVGProps } from "react"; 2 | 3 | export type IconSvgProps = SVGProps & { 4 | size?: number; 5 | }; 6 | -------------------------------------------------------------------------------- /packages/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "files": [], 3 | "references": [ 4 | { 5 | "path": "./nestjs-trpc/tsconfig.build.json" 6 | } 7 | ] 8 | } 9 | -------------------------------------------------------------------------------- /examples/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "files": [], 3 | "references": [ 4 | { 5 | "path": "./nestjs-express/tsconfig.build.json" 6 | } 7 | ] 8 | } 9 | -------------------------------------------------------------------------------- /docs/next-sitemap.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('next-sitemap').IConfig} */ 2 | module.exports = { 3 | siteUrl: 'https://nestjs-trpc.io', 4 | generateRobotsTxt: true, 5 | }; -------------------------------------------------------------------------------- /packages/nestjs-trpc/lib/index.ts: -------------------------------------------------------------------------------- 1 | export * from './trpc.module'; 2 | export * from './interfaces'; 3 | export * from './decorators'; 4 | export * from './app-router.host'; 5 | -------------------------------------------------------------------------------- /docs/public/robots.txt: -------------------------------------------------------------------------------- 1 | # * 2 | User-agent: * 3 | Allow: / 4 | 5 | # Host 6 | Host: https://nestjs-trpc.io 7 | 8 | # Sitemaps 9 | Sitemap: https://nestjs-trpc.io/sitemap.xml 10 | -------------------------------------------------------------------------------- /packages/nestjs-trpc/lib/generators/generator.constants.ts: -------------------------------------------------------------------------------- 1 | export const TYPESCRIPT_PROJECT = 'TypescriptProject'; 2 | export const TYPESCRIPT_APP_ROUTER_SOURCE_FILE = 3 | 'TypescriptAppRouterSourceFile'; 4 | -------------------------------------------------------------------------------- /docs/public/sitemap.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | https://nestjs-trpc.io/sitemap-0.xml 4 | -------------------------------------------------------------------------------- /packages/nestjs-trpc/lib/interfaces/scanner.interface.ts: -------------------------------------------------------------------------------- 1 | export interface SourceMapping { 2 | version: number; 3 | file: string; 4 | sourceRoot: string; 5 | sources: Array; 6 | mappings: string; 7 | } 8 | -------------------------------------------------------------------------------- /packages/nestjs-trpc/lib/interfaces/index.ts: -------------------------------------------------------------------------------- 1 | export * from './module-options.interface'; 2 | export * from './middleware.interface'; 3 | export * from './procedure-options.interface'; 4 | export * from './context.interface'; 5 | -------------------------------------------------------------------------------- /docs/next-env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | 4 | // NOTE: This file should not be edited 5 | // see https://nextjs.org/docs/basic-features/typescript for more information. 6 | -------------------------------------------------------------------------------- /renovate.json: -------------------------------------------------------------------------------- 1 | { 2 | "semanticCommits": true, 3 | "labels": ["dependencies"], 4 | "packageRules": [ 5 | { 6 | "depTypeList": ["devDependencies"], 7 | "automerge": true 8 | } 9 | ], 10 | "extends": ["config:base"] 11 | } 12 | -------------------------------------------------------------------------------- /examples/nestjs-express/src/user.schema.ts: -------------------------------------------------------------------------------- 1 | import { z } from 'zod'; 2 | 3 | export const userSchema = z.object({ 4 | name: z.string(), 5 | email: z.string(), 6 | password: z.string(), 7 | }); 8 | 9 | export type User = z.infer; 10 | -------------------------------------------------------------------------------- /examples/nestjs-express/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.build.json", 3 | "compilerOptions": { 4 | "outDir": "./dist", 5 | "rootDir": "./src" 6 | }, 7 | "exclude": ["node_modules", "dist", "src/**/__tests__/*", "*.spec.ts"] 8 | } 9 | -------------------------------------------------------------------------------- /examples/nestjs-fastify/src/user.schema.ts: -------------------------------------------------------------------------------- 1 | import { z } from 'zod'; 2 | 3 | export const userSchema = z.object({ 4 | name: z.string(), 5 | email: z.string(), 6 | password: z.string(), 7 | }); 8 | 9 | export type User = z.infer; 10 | -------------------------------------------------------------------------------- /examples/nestjs-fastify/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.build.json", 3 | "compilerOptions": { 4 | "outDir": "./dist", 5 | "rootDir": "./src" 6 | }, 7 | "exclude": ["node_modules", "dist", "src/**/__tests__/*", "*.spec.ts"] 8 | } 9 | -------------------------------------------------------------------------------- /packages/nestjs-trpc/.npmignore: -------------------------------------------------------------------------------- 1 | # source 2 | lib 3 | tests 4 | index.ts 5 | tsconfig.json 6 | .prettierrc 7 | 8 | # misc 9 | .commitlintrc.json 10 | .release-it.json 11 | .eslintignore 12 | .eslintrc.js 13 | renovate.json 14 | .prettierignore 15 | .prettierrc -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | # source 2 | lib 3 | tests 4 | index.ts 5 | package-lock.json 6 | tsconfig.json 7 | .prettierrc 8 | 9 | # misc 10 | .commitlintrc.json 11 | .release-it.json 12 | .eslintignore 13 | .eslintrc.js 14 | renovate.json 15 | .prettierignore 16 | .prettierrc -------------------------------------------------------------------------------- /docs/svgr.d.ts: -------------------------------------------------------------------------------- 1 | declare module '*.svg' { 2 | import { FC, SVGProps } from 'react' 3 | const content: FC> 4 | export default content 5 | } 6 | 7 | declare module '*.svg?url' { 8 | const content: any 9 | export default content 10 | } -------------------------------------------------------------------------------- /packages/nestjs-trpc/lib/utils/ts-morph.util.ts: -------------------------------------------------------------------------------- 1 | import { SourceFile } from 'ts-morph'; 2 | 3 | export async function saveOrOverrideFile( 4 | sourceFile: SourceFile, 5 | ): Promise { 6 | sourceFile.formatText({ indentSize: 2 }); 7 | await sourceFile.save(); 8 | } 9 | -------------------------------------------------------------------------------- /docs/public/favicon/site.webmanifest: -------------------------------------------------------------------------------- 1 | {"name":"","short_name":"","icons":[{"src":"/android-chrome-192x192.png","sizes":"192x192","type":"image/png"},{"src":"/android-chrome-512x512.png","sizes":"512x512","type":"image/png"}],"theme_color":"#ffffff","background_color":"#ffffff","display":"standalone"} -------------------------------------------------------------------------------- /examples/nestjs-express/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.build.json", 3 | "compilerOptions": { 4 | "types": ["node"] 5 | }, 6 | "files": [], 7 | "include": [], 8 | "references": [ 9 | { 10 | "path": "./tsconfig.build.json" 11 | } 12 | ] 13 | } 14 | -------------------------------------------------------------------------------- /examples/nestjs-fastify/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.build.json", 3 | "compilerOptions": { 4 | "types": ["node"] 5 | }, 6 | "files": [], 7 | "include": [], 8 | "references": [ 9 | { 10 | "path": "./tsconfig.build.json" 11 | } 12 | ] 13 | } 14 | -------------------------------------------------------------------------------- /packages/nestjs-trpc/tsconfig.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "experimentalDecorators": true, 5 | "sourceMap": true, 6 | "outDir": "./dist/tests", 7 | "types": ["jest", "node"], 8 | "emitDecoratorMetadata": true 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /examples/nestjs-express/src/main.ts: -------------------------------------------------------------------------------- 1 | import { NestFactory } from '@nestjs/core'; 2 | import { AppModule } from './app.module'; 3 | 4 | async function bootstrap() { 5 | const app = await NestFactory.create(AppModule, { cors: true }); 6 | 7 | await app.listen(8080); 8 | } 9 | 10 | void bootstrap(); 11 | -------------------------------------------------------------------------------- /packages/nestjs-trpc/lib/interfaces/procedure-options.interface.ts: -------------------------------------------------------------------------------- 1 | import { ProcedureParams } from '@trpc/server'; 2 | import { ResolveOptions } from '@trpc/server/dist/core/internals/utils'; 3 | 4 | export type ProcedureOptions = ResolveOptions & { 5 | type: string; 6 | path: string; 7 | rawInput: string; 8 | }; 9 | -------------------------------------------------------------------------------- /examples/nextjs-trpc/app/trpc.ts: -------------------------------------------------------------------------------- 1 | import { createTRPCProxyClient, httpBatchLink } from "@trpc/client"; 2 | import { AppRouter } from "@server/@generated/server"; 3 | 4 | export const trpc = createTRPCProxyClient({ 5 | links: [ 6 | httpBatchLink({ 7 | url: `${process.env.NEXT_PUBLIC_NESTJS_SERVER}/trpc`, 8 | }), 9 | ], 10 | }); -------------------------------------------------------------------------------- /examples/nestjs-express/.gitignore: -------------------------------------------------------------------------------- 1 | # dependencies 2 | node_modules 3 | 4 | # IDE 5 | /.idea 6 | /.vscode 7 | 8 | # misc 9 | npm-debug.log 10 | .DS_Store 11 | 12 | # examples 13 | /test 14 | /coverage 15 | /.nyc_output 16 | test-schema.graphql 17 | *.test-definitions.ts 18 | 19 | # dist 20 | dist 21 | **/*.tsbuildinfo 22 | 23 | .yarn/ 24 | 25 | src/@generated -------------------------------------------------------------------------------- /examples/nestjs-fastify/.gitignore: -------------------------------------------------------------------------------- 1 | # dependencies 2 | node_modules 3 | 4 | # IDE 5 | /.idea 6 | /.vscode 7 | 8 | # misc 9 | npm-debug.log 10 | .DS_Store 11 | 12 | # examples 13 | /test 14 | /coverage 15 | /.nyc_output 16 | test-schema.graphql 17 | *.test-definitions.ts 18 | 19 | # dist 20 | dist 21 | **/*.tsbuildinfo 22 | 23 | .yarn/ 24 | 25 | src/@generated -------------------------------------------------------------------------------- /packages/nestjs-trpc/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.build.json", 3 | "compilerOptions": { 4 | "outDir": "./dist", 5 | "rootDir": "./lib", 6 | "incremental": false, 7 | "experimentalDecorators": true 8 | }, 9 | "include": ["lib/**/*.ts"], 10 | "exclude": ["node_modules", "dist", "lib/**/__tests__/*", "*.spec.ts"] 11 | } 12 | -------------------------------------------------------------------------------- /docs/pages/_app.mdx: -------------------------------------------------------------------------------- 1 | import '../styles/globals.css' 2 | import { Analytics } from "@vercel/analytics/react"; 3 | import { GeistSans } from 'geist/font/sans' 4 | 5 | export default function App({ Component, pageProps }) { 6 | return ( 7 |
8 | 9 | 10 |
11 | ) 12 | } -------------------------------------------------------------------------------- /packages/nestjs-trpc/lib/generators/generator.interface.ts: -------------------------------------------------------------------------------- 1 | import type { SchemaImports, TRPCContext } from '../interfaces'; 2 | import type { Class } from 'type-fest'; 3 | 4 | export interface GeneratorModuleOptions { 5 | rootModuleFilePath: string; 6 | context?: Class; 7 | outputDirPath?: string; 8 | schemaFileImports?: Array; 9 | } 10 | -------------------------------------------------------------------------------- /packages/nestjs-trpc/lib/scanners/scanner.module.ts: -------------------------------------------------------------------------------- 1 | import { Module } from '@nestjs/common'; 2 | import { FileScanner } from './file.scanner'; 3 | import { ImportsScanner } from './imports.scanner'; 4 | 5 | @Module({ 6 | imports: [], 7 | providers: [FileScanner, ImportsScanner], 8 | exports: [FileScanner, ImportsScanner], 9 | }) 10 | export class ScannerModule {} 11 | -------------------------------------------------------------------------------- /packages/nestjs-trpc/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.build.json", 3 | "compilerOptions": { 4 | "types": ["node"], 5 | "experimentalDecorators": true 6 | }, 7 | "files": [], 8 | "include": [], 9 | "references": [ 10 | { 11 | "path": "./tsconfig.build.json" 12 | }, 13 | { 14 | "path": "./tsconfig.spec.json" 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /examples/nestjs-express/nest-cli.json: -------------------------------------------------------------------------------- 1 | { 2 | "language": "ts", 3 | "collection": "@nestjs/schematics", 4 | "sourceRoot": "src", 5 | "compilerOptions": { 6 | "deleteOutDir": true 7 | }, 8 | "watchOptions": { 9 | "watchExclude": [ 10 | "src/@generated/**/*", 11 | "src/@generated/*", 12 | "**/@generated/**/*", 13 | "**/*.spec.ts" 14 | ] 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /examples/nestjs-fastify/nest-cli.json: -------------------------------------------------------------------------------- 1 | { 2 | "language": "ts", 3 | "collection": "@nestjs/schematics", 4 | "sourceRoot": "src", 5 | "compilerOptions": { 6 | "deleteOutDir": true 7 | }, 8 | "watchOptions": { 9 | "watchExclude": [ 10 | "src/@generated/**/*", 11 | "src/@generated/*", 12 | "**/@generated/**/*", 13 | "**/*.spec.ts" 14 | ] 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /examples/nextjs-trpc/app/page.tsx: -------------------------------------------------------------------------------- 1 | import ClientSide from "./client-side"; 2 | import { trpc } from "./trpc"; 3 | 4 | export default async function Home() { 5 | const userId = "randomUserId" 6 | const response = await trpc.users.getUserById.query({ userId }); 7 | 8 | return ( 9 |
10 |

Server side - {response.name}

11 | 12 |
13 | ); 14 | } -------------------------------------------------------------------------------- /packages/nestjs-trpc/.gitignore: -------------------------------------------------------------------------------- 1 | # dependencies 2 | node_modules 3 | 4 | # generated types 5 | /types 6 | 7 | # IDE 8 | /.idea 9 | /.awcache 10 | /.vscode 11 | 12 | # misc 13 | npm-debug.log 14 | .DS_Store 15 | 16 | # examples 17 | /test 18 | /coverage 19 | /.nyc_output 20 | test-schema.graphql 21 | *.test-definitions.ts 22 | 23 | # dist 24 | dist 25 | test/**/dist 26 | **/*.tsbuildinfo 27 | 28 | .yarn/ -------------------------------------------------------------------------------- /examples/nestjs-fastify/src/user.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@nestjs/common'; 2 | import { User } from './user.schema'; 3 | 4 | @Injectable() 5 | export class UserService { 6 | async test(): Promise { 7 | return 'test'; 8 | } 9 | 10 | async getUser(userId: string): Promise { 11 | return { 12 | name: 'user', 13 | email: 'user@email.com', 14 | password: '0000', 15 | }; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /examples/nestjs-express/src/user.controller.ts: -------------------------------------------------------------------------------- 1 | import { Controller, Get, Post } from '@nestjs/common'; 2 | 3 | @Controller('cats') 4 | export class CatsController { 5 | @Get() 6 | findAll(): string { 7 | return 'This action returns all cats'; 8 | } 9 | 10 | @Post() 11 | findPAll(): string { 12 | return 'This action returns all cats'; 13 | } 14 | 15 | @Post('bla') 16 | returnBla() { 17 | return 'This action returns all cats'; 18 | } 19 | 20 | } -------------------------------------------------------------------------------- /examples/nestjs-fastify/src/user.controller.ts: -------------------------------------------------------------------------------- 1 | import { Controller, Get, Post } from '@nestjs/common'; 2 | 3 | @Controller('cats') 4 | export class CatsController { 5 | @Get() 6 | findAll(): string { 7 | return 'This action returns all cats'; 8 | } 9 | 10 | @Post() 11 | findPAll(): string { 12 | return 'This action returns all cats'; 13 | } 14 | 15 | @Post('bla') 16 | returnBla() { 17 | return 'This action returns all cats'; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /examples/nestjs-fastify/src/main.ts: -------------------------------------------------------------------------------- 1 | import { NestFactory } from '@nestjs/core'; 2 | import { 3 | FastifyAdapter, 4 | NestFastifyApplication, 5 | } from '@nestjs/platform-fastify'; 6 | import { AppModule } from './app.module'; 7 | 8 | async function bootstrap() { 9 | const app = await NestFactory.create( 10 | AppModule, 11 | new FastifyAdapter(), 12 | { cors: true }, 13 | ); 14 | 15 | await app.listen(8080); 16 | } 17 | 18 | void bootstrap(); 19 | -------------------------------------------------------------------------------- /packages/nestjs-trpc/lib/interfaces/context.interface.ts: -------------------------------------------------------------------------------- 1 | import type { CreateExpressContextOptions } from '@trpc/server/adapters/express'; 2 | import type { CreateFastifyContextOptions } from '@trpc/server/adapters/fastify'; 3 | 4 | export type ContextOptions = 5 | | CreateExpressContextOptions 6 | | CreateFastifyContextOptions; 7 | 8 | export interface TRPCContext { 9 | create( 10 | opts: ContextOptions, 11 | ): Record | Promise>; 12 | } 13 | -------------------------------------------------------------------------------- /docs/utils/searchParams.ts: -------------------------------------------------------------------------------- 1 | const isArray = (value: unknown): value is Readonly | unknown[] => 2 | Array.isArray(value); 3 | 4 | export function searchParams( 5 | obj: Record | string[] | string>, 6 | ): string { 7 | return Object.entries(obj) 8 | .map(([key, value]) => { 9 | const values = isArray(value) ? value : [value]; 10 | 11 | return values.map((v) => `${key}=${encodeURIComponent(v)}`).join('&'); 12 | }) 13 | .join('&'); 14 | } -------------------------------------------------------------------------------- /examples/nextjs-trpc/app/client-side.tsx: -------------------------------------------------------------------------------- 1 | "use client"; 2 | 3 | import { useEffect, useState } from "react"; 4 | import { trpc } from "./trpc"; 5 | 6 | export default function ClientSide() { 7 | const [greeting, setGreeting] = useState(""); 8 | 9 | useEffect(() => { 10 | const userId = "randomUserId" 11 | trpc.users.getUserById.query({userId}).then((response) => { 12 | setGreeting(response.name); 13 | }); 14 | }); 15 | 16 | return
I am client side - {greeting}
; 17 | } -------------------------------------------------------------------------------- /packages/nestjs-trpc/jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | preset: 'ts-jest', 3 | testEnvironment: 'node', 4 | roots: ['/lib'], 5 | testMatch: ['**/__tests__/**/*.ts?(x)', '**/?(*.)+(spec|test).ts?(x)'], 6 | transform: { 7 | '^.+\\.tsx?$': ['ts-jest', { 8 | tsconfig: 'tsconfig.spec.json', 9 | diagnostics: { 10 | ignoreCodes: [151001] 11 | } 12 | }] 13 | }, 14 | moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'], 15 | }; -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # dependencies 2 | node_modules 3 | 4 | .pnp.* 5 | 6 | # generated types 7 | /types 8 | 9 | # IDE 10 | /.idea 11 | /.awcache 12 | /.vscode 13 | 14 | # misc 15 | npm-debug.log 16 | .DS_Store 17 | 18 | # examples 19 | /test 20 | /coverage 21 | /.nyc_output 22 | test-schema.graphql 23 | *.test-definitions.ts 24 | 25 | # dist 26 | dist 27 | test/**/dist 28 | **/*.tsbuildinfo 29 | 30 | .yarn/* 31 | !.yarn/cache 32 | !.yarn/patches 33 | !.yarn/plugins 34 | !.yarn/releases 35 | !.yarn/sdks 36 | !.yarn/versions -------------------------------------------------------------------------------- /examples/nestjs-express/src/user.service.ts: -------------------------------------------------------------------------------- 1 | import { 2 | BadRequestException, 3 | Inject, 4 | Injectable, 5 | forwardRef, 6 | } from '@nestjs/common'; 7 | import { User } from './user.schema'; 8 | 9 | @Injectable() 10 | export class UserService { 11 | async test(): Promise { 12 | return 'test'; 13 | } 14 | 15 | async getUser(userId: string): Promise { 16 | return { 17 | name: 'user', 18 | email: 'user@email.com', 19 | password: '0000', 20 | }; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /packages/nestjs-trpc/lib/decorators/index.ts: -------------------------------------------------------------------------------- 1 | export * from './router.decorator'; 2 | 3 | // Procedure Decorators 4 | export * from './middlewares.decorator'; 5 | export * from './mutation.decorator'; 6 | export * from './query.decorator'; 7 | 8 | // Procedure Param Decorators 9 | export * from './options.decorator'; 10 | export * from './context.decorator'; 11 | export * from './input.decorator'; 12 | export * from './raw-input.decorator'; 13 | export * from './type.decorator'; 14 | export * from './path.decorator'; 15 | -------------------------------------------------------------------------------- /examples/nextjs-trpc/app/layout.tsx: -------------------------------------------------------------------------------- 1 | import './globals.css' 2 | import { Inter } from 'next/font/google' 3 | 4 | const inter = Inter({ subsets: ['latin'] }) 5 | 6 | export const metadata = { 7 | title: 'Create Next App', 8 | description: 'Generated by create next app', 9 | } 10 | 11 | export default function RootLayout({ 12 | children, 13 | }: { 14 | children: React.ReactNode 15 | }) { 16 | return ( 17 | 18 | {children} 19 | 20 | ) 21 | } -------------------------------------------------------------------------------- /examples/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "composite": false, 4 | "module": "commonjs", 5 | "declaration": true, 6 | "declarationMap": true, 7 | "noImplicitAny": false, 8 | "incremental": false, 9 | "importHelpers": true, 10 | "removeComments": false, 11 | "noLib": false, 12 | "emitDecoratorMetadata": true, 13 | "experimentalDecorators": true, 14 | "target": "ES2021", 15 | "sourceMap": true, 16 | "skipLibCheck": true, 17 | "resolveJsonModule": true 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /examples/nextjs-trpc/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # next.js 12 | /.next/ 13 | /out/ 14 | 15 | # production 16 | /build 17 | 18 | # misc 19 | .DS_Store 20 | *.pem 21 | 22 | # debug 23 | npm-debug.log* 24 | yarn-debug.log* 25 | yarn-error.log* 26 | 27 | # local env files 28 | .env*.local 29 | 30 | # vercel 31 | .vercel 32 | 33 | # typescript 34 | *.tsbuildinfo 35 | next-env.d.ts -------------------------------------------------------------------------------- /docs/public/icons/npm.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /examples/nextjs-trpc/tailwind.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('tailwindcss').Config} */ 2 | module.exports = { 3 | content: [ 4 | './pages/**/*.{js,ts,jsx,tsx,mdx}', 5 | './components/**/*.{js,ts,jsx,tsx,mdx}', 6 | './app/**/*.{js,ts,jsx,tsx,mdx}', 7 | ], 8 | theme: { 9 | extend: { 10 | backgroundImage: { 11 | 'gradient-radial': 'radial-gradient(var(--tw-gradient-stops))', 12 | 'gradient-conic': 13 | 'conic-gradient(from 180deg at 50% 50%, var(--tw-gradient-stops))', 14 | }, 15 | }, 16 | }, 17 | plugins: [], 18 | } -------------------------------------------------------------------------------- /docs/pages/_meta.json: -------------------------------------------------------------------------------- 1 | { 2 | "index": { 3 | "title": "Introduction", 4 | "display": "hidden", 5 | "theme": { 6 | "breadcrumb": false, 7 | "footer": true, 8 | "sidebar": false, 9 | "toc": false, 10 | "pagination": false, 11 | "timestamp": false, 12 | "layout": "full" 13 | } 14 | }, 15 | "docs": { 16 | "title": "Docs", 17 | "type": "page" 18 | }, 19 | "contact": { 20 | "title": "Contact ↗", 21 | "type": "page", 22 | "href": "https://twitter.com/KevinEdry", 23 | "newWindow": true 24 | } 25 | } -------------------------------------------------------------------------------- /docs/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | .yarn/install-state.gz 8 | 9 | # testing 10 | /coverage 11 | 12 | # next.js 13 | /.next/ 14 | /out/ 15 | 16 | # production 17 | /build 18 | 19 | # misc 20 | .DS_Store 21 | *.pem 22 | 23 | # debug 24 | npm-debug.log* 25 | yarn-debug.log* 26 | yarn-error.log* 27 | 28 | # local env files 29 | .env*.local 30 | 31 | # vercel 32 | .vercel 33 | 34 | # typescript 35 | *.tsbuildinfo 36 | ../website/nestjs-trpc.io/next-env.d.ts 37 | -------------------------------------------------------------------------------- /docs/components/Iframe/index.tsx: -------------------------------------------------------------------------------- 1 | import clsx from 'clsx'; 2 | import type { ComponentPropsWithoutRef } from 'react'; 3 | import React, { useState } from 'react'; 4 | 5 | export const Iframe = ( 6 | props: { 7 | setLoaded: (loaded: boolean) => void; 8 | } & Omit, 'className'>, 9 | ) => { 10 | const { setLoaded } = props; 11 | return ( 12 |