diff --git a/.npmrc b/.npmrc index bac7fb0..116d16a 100644 --- a/.npmrc +++ b/.npmrc @@ -1,2 +1,2 @@ -shamefully-hoist=true ignore-workspace-root-check=true +shamefully-hoist=true diff --git a/package.json b/package.json index 2a2fb70..ab511df 100644 --- a/package.json +++ b/package.json @@ -1,46 +1,18 @@ { - "name": "trpc-nuxt", - "type": "module", - "version": "0.0.3", - "license": "MIT", - "main": "./dist/module.cjs", - "types": "./dist/types.d.ts", - "exports": { - ".": { - "import": "./dist/module.mjs", - "require": "./dist/module.cjs" - }, - "./api": { - "import": "./dist/runtime/api.mjs", - "types": "./dist/runtime/api.d.ts" - } - }, - "files": [ - "dist", - "*.d.ts" - ], + "name": "monorepo", + "packageManager": "pnpm@7.0.0", "scripts": { - "prepack": "nuxt-module-build", - "dev": "nuxi dev playground", - "dev:build": "nuxi build playground", - "dev:prepare": "nuxt-module-build --stub && nuxi prepare playground", + "dev": "nr --parallel --filter trpc-nuxt --filter playground dev", "lint": "eslint .", - "lint:fix": "eslint . --fix" - }, - "dependencies": { - "@nuxt/kit": "^3.0.0-rc.3", - "@trpc/server": "^9.23.2", - "fs-extra": "^10.1.0", - "pathe": "^0.3.0", - "ufo": "^0.8.4" + "lint:fix": "eslint . --fix", + "prepare": "nr --filter playground prepare" }, "devDependencies": { "@antfu/eslint-config": "^0.23.1", + "@antfu/ni": "^0.16.2", "@nuxt/module-builder": "latest", - "@types/fs-extra": "^9.0.13", - "eslint": "latest", - "nuxt": "^3.0.0-rc.3", - "zod": "^3.16.0" + "eslint": "^8.14.0", + "pnpm": "^7.1.0" }, "eslintConfig": { "extends": "@antfu" diff --git a/packages/playground/.gitignore b/packages/playground/.gitignore new file mode 100644 index 0000000..d233591 --- /dev/null +++ b/packages/playground/.gitignore @@ -0,0 +1,7 @@ +node_modules +*.log* +.nuxt +.nitro +.cache +.output +.env \ No newline at end of file diff --git a/packages/playground/README.md b/packages/playground/README.md new file mode 100644 index 0000000..61b9202 --- /dev/null +++ b/packages/playground/README.md @@ -0,0 +1,42 @@ +# Nuxt 3 Minimal Starter + +Look at the [nuxt 3 documentation](https://v3.nuxtjs.org) to learn more. + +## Setup + +Make sure to install the dependencies: + +```bash +# yarn +yarn install + +# npm +npm install + +# pnpm +pnpm install --shamefully-hoist +``` + +## Development Server + +Start the development server on http://localhost:3000 + +```bash +npm run dev +``` + +## Production + +Build the application for production: + +```bash +npm run build +``` + +Locally preview production build: + +```bash +npm run preview +``` + +Checkout the [deployment documentation](https://v3.nuxtjs.org/docs/deployment) for more information. diff --git a/packages/playground/app.vue b/packages/playground/app.vue new file mode 100644 index 0000000..8b51c07 --- /dev/null +++ b/packages/playground/app.vue @@ -0,0 +1,18 @@ + + + diff --git a/packages/playground/nuxt.config.ts b/packages/playground/nuxt.config.ts new file mode 100644 index 0000000..6992cb0 --- /dev/null +++ b/packages/playground/nuxt.config.ts @@ -0,0 +1,6 @@ +import { defineNuxtConfig } from 'nuxt' + +// https://v3.nuxtjs.org/api/configuration/nuxt.config +export default defineNuxtConfig({ + modules: ['trpc-nuxt'], +}) diff --git a/packages/playground/package.json b/packages/playground/package.json new file mode 100644 index 0000000..eb0b712 --- /dev/null +++ b/packages/playground/package.json @@ -0,0 +1,18 @@ +{ + "name": "playground", + "private": true, + "scripts": { + "build": "nuxt build", + "dev": "nuxt dev", + "generate": "nuxt generate", + "preview": "nuxt preview", + "prepare": "nuxt prepare" + }, + "dependencies": { + "trpc-nuxt": "link:../trpc", + "zod": "^3.16.0" + }, + "devDependencies": { + "nuxt": "3.0.0-rc.3" + } +} diff --git a/packages/playground/server/fn/index.ts b/packages/playground/server/fn/index.ts new file mode 100644 index 0000000..34b262b --- /dev/null +++ b/packages/playground/server/fn/index.ts @@ -0,0 +1,11 @@ +// generated by trpc-nuxt + import * as trpc from '@trpc/server' + + export const router = trpc + .router() + .query('hello', { + resolve: () => 'world', + }); + + export type Router = typeof router + \ No newline at end of file diff --git a/packages/playground/tsconfig.json b/packages/playground/tsconfig.json new file mode 100644 index 0000000..4b34df1 --- /dev/null +++ b/packages/playground/tsconfig.json @@ -0,0 +1,3 @@ +{ + "extends": "./.nuxt/tsconfig.json" +} diff --git a/README.md b/packages/trpc/README.md similarity index 100% rename from README.md rename to packages/trpc/README.md diff --git a/packages/trpc/client.d.ts b/packages/trpc/client.d.ts new file mode 100644 index 0000000..047203f --- /dev/null +++ b/packages/trpc/client.d.ts @@ -0,0 +1 @@ +export * from './dist/runtime/client' diff --git a/handler.d.ts b/packages/trpc/handler.d.ts similarity index 100% rename from handler.d.ts rename to packages/trpc/handler.d.ts diff --git a/packages/trpc/package.json b/packages/trpc/package.json new file mode 100644 index 0000000..da9dea2 --- /dev/null +++ b/packages/trpc/package.json @@ -0,0 +1,45 @@ +{ + "name": "trpc-nuxt", + "type": "module", + "version": "0.0.3", + "license": "MIT", + "main": "./dist/module.cjs", + "types": "./dist/types.d.ts", + "exports": { + ".": { + "import": "./dist/module.mjs", + "require": "./dist/module.cjs" + }, + "./api": { + "import": "./dist/runtime/api.mjs", + "types": "./dist/runtime/api.d.ts" + }, + "./client": { + "import": "./dist/runtime/client.mjs", + "types": "./dist/runtime/client.d.ts" + } + }, + "files": [ + "dist", + "*.d.ts" + ], + "scripts": { + "build": "nuxt-module-build", + "dev": "nuxt-module-build --stub" + }, + "dependencies": { + "@nuxt/kit": "^3.0.0-rc.3", + "@trpc/client": "^9.23.3", + "@trpc/server": "^9.23.2", + "fs-extra": "^10.1.0", + "h3": "^0.7.8", + "ohash": "^0.1.0", + "pathe": "^0.3.0", + "ufo": "^0.8.4" + }, + "devDependencies": { + "@nuxt/module-builder": "latest", + "@types/fs-extra": "^9.0.13", + "nuxt": "^3.0.0-rc.3" + } +} diff --git a/packages/trpc/src/module.ts b/packages/trpc/src/module.ts new file mode 100644 index 0000000..5638523 --- /dev/null +++ b/packages/trpc/src/module.ts @@ -0,0 +1,93 @@ +import { dirname, join, resolve } from 'pathe' +import { addServerHandler, defineNuxtModule } from '@nuxt/kit' +import fs from 'fs-extra' + +export interface ModuleOptions {} + +export default defineNuxtModule({ + meta: { + name: 'trpc-nuxt', + configKey: 'trpc', + }, + defaults: {}, + async setup(_options, nuxt) { + const clientPath = join(nuxt.options.buildDir, 'trpc-client.ts') + const handlerPath = join(nuxt.options.buildDir, 'trpc-handler.ts') + + nuxt.hook('config', () => { + nuxt.options.build.transpile.push('trpc-nuxt/client') + }) + + addServerHandler({ + route: '/trpc/*', + handler: handlerPath, + }) + + nuxt.hook('autoImports:extend', (imports) => { + imports.push( + { name: 'useTrpcQuery', from: clientPath }, + { name: 'useTrpcLazyQuery', from: clientPath }, + { name: 'useTrpcMutation', from: clientPath }, + ) + }) + + const srcDir = nuxt.options.srcDir + const optionsPath = resolve(srcDir, 'server/fn/index.ts') + + await fs.ensureDir(dirname(clientPath)) + + nuxt.options.build.transpile.push('trpc-nuxt/client') + nuxt.hook('autoImports:extend', (imports) => { + imports.push( + { name: 'useTrpcQuery', as: 'useTrpcQuery', from: clientPath }, + { name: 'useTrpcLazyQuery', as: 'useTrpcLazyQuery', from: clientPath }, + { name: 'useTrpcMutation', as: 'useTrpcMutation', from: clientPath }, + ) + }) + + await fs.writeFile(clientPath, ` + import * as trpc from '@trpc/client' + import { createTRPCComposables } from 'trpc-nuxt/client' + import { router } from '~/server/fn' + + const client = trpc.createTRPCClient({ + url: process.browser ? '/trpc' : 'http://localhost:3000/trpc', + }) + + const { + useTrpcQuery, + useTrpcLazyQuery, + useTrpcMutation + } = createTRPCComposables(client) + + export { + useTrpcQuery, + useTrpcLazyQuery, + useTrpcMutation + } + `) + + await fs.writeFile(handlerPath, ` + import { createTRPCHandler } from 'trpc-nuxt/api' + import * as functions from '~/server/fn' + export default createTRPCHandler({ + router: functions.router + }) + `) + + if (!fs.existsSync(optionsPath)) { + await fs.writeFile(optionsPath, ` + // Generated by trpc-nuxt + import * as trpc from '@trpc/server' + + export const router = trpc + .router() + .query('hello', { + resolve: () => 'world', + }); + + export type Router = typeof router + `.trimStart()) + } + }, +}) diff --git a/src/runtime/api.ts b/packages/trpc/src/runtime/api.ts similarity index 96% rename from src/runtime/api.ts rename to packages/trpc/src/runtime/api.ts index dd4faa6..2b76d90 100644 --- a/src/runtime/api.ts +++ b/packages/trpc/src/runtime/api.ts @@ -51,7 +51,7 @@ export function createTRPCHandler({ body: isMethod(event, 'GET') ? null : await useBody(event), query: $url.searchParams, }, - path: $url.pathname.substring(url.length + 5), + path: $url.pathname.substring(url.length + 1), createContext: async () => createContext?.(req), responseMeta, }) diff --git a/packages/trpc/src/runtime/client.ts b/packages/trpc/src/runtime/client.ts new file mode 100644 index 0000000..99d8b09 --- /dev/null +++ b/packages/trpc/src/runtime/client.ts @@ -0,0 +1,33 @@ +import { objectHash } from 'ohash' +import type { TRPCClient } from '@trpc/client' +import { useAsyncData, useLazyAsyncData } from '#imports' + +// type ReturnType = T extends (...args: any) => infer R ? R : never + +export function createTRPCComposables>(client: T): { + useTrpcQuery: (...args: Parameters) => ReturnType + useTrpcLazyQuery: (...args: Parameters) => ReturnType + useTrpcMutation: (...args: Parameters) => ReturnType +} + +export function createTRPCComposables< + T extends TRPCClient, +>(client: T) { + const useTrpcQuery = (...args: Parameters) => { + return useAsyncData(`trpc-${objectHash(args[0] + (args[1] ? JSON.stringify(args[1]) : ''))}`, () => client.query(...args)) + } + + const useTrpcLazyQuery = (...args: Parameters) => { + return useLazyAsyncData(`trpc-${objectHash(args[0] + (args[1] ? JSON.stringify(args[1]) : ''))}`, () => client.query(...args)) + } + + const useTrpcMutation = (...args: Parameters) => { + return useAsyncData(`trpc-${objectHash(args[0] + (args[1] ? JSON.stringify(args[1]) : ''))}`, () => client.mutation(...args)) + } + + return { + useTrpcQuery, + useTrpcLazyQuery, + useTrpcMutation, + } +} diff --git a/packages/trpc/tsconfig.json b/packages/trpc/tsconfig.json new file mode 100644 index 0000000..68f2e4a --- /dev/null +++ b/packages/trpc/tsconfig.json @@ -0,0 +1,14 @@ +{ + "compilerOptions": { + "target": "es2018", + "module": "esnext", + "lib": ["esnext"], + "moduleResolution": "node", + "esModuleInterop": true, + "strict": true, + "strictNullChecks": true, + "resolveJsonModule": true, + "skipLibCheck": true, + "skipDefaultLibCheck": true + } +} diff --git a/playground/app.vue b/playground/app.vue deleted file mode 100644 index a5f2c39..0000000 --- a/playground/app.vue +++ /dev/null @@ -1,8 +0,0 @@ - - - diff --git a/playground/nuxt.config.ts b/playground/nuxt.config.ts deleted file mode 100644 index 5fed57e..0000000 --- a/playground/nuxt.config.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { defineNuxtConfig } from 'nuxt' -import MyModule from '..' - -export default defineNuxtConfig({ - modules: [ - MyModule, - ], - myModule: { - addPlugin: true, - }, -}) diff --git a/playground/package.json b/playground/package.json deleted file mode 100644 index 51466b1..0000000 --- a/playground/package.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "name": "playground", - "private": true -} diff --git a/playground/server/fn/index.ts b/playground/server/fn/index.ts deleted file mode 100644 index 3e80091..0000000 --- a/playground/server/fn/index.ts +++ /dev/null @@ -1,11 +0,0 @@ -// generated by trpc-nuxt -import * as trpc from '@trpc/server' - -export const router = trpc - .router() - .query('hello', { - resolve: () => 'world', - }) - -export type Router = typeof router - diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f2d13aa..f0661c7 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -5,29 +5,54 @@ importers: .: specifiers: '@antfu/eslint-config': ^0.23.1 - '@nuxt/kit': ^3.0.0-rc.3 + '@antfu/ni': ^0.16.2 '@nuxt/module-builder': latest - '@trpc/server': ^9.23.2 - '@types/fs-extra': ^9.0.13 - eslint: latest - fs-extra: ^10.1.0 - nuxt: ^3.0.0-rc.3 - pathe: ^0.3.0 - ufo: ^0.8.4 + eslint: ^8.14.0 + pnpm: ^7.1.0 + devDependencies: + '@antfu/eslint-config': 0.23.1_eslint@8.15.0 + '@antfu/ni': 0.16.2 + '@nuxt/module-builder': 0.1.7 + eslint: 8.15.0 + pnpm: 7.1.0 + + packages/playground: + specifiers: + nuxt: 3.0.0-rc.3 + trpc-nuxt: link:../trpc zod: ^3.16.0 + dependencies: + trpc-nuxt: link:../trpc + zod: 3.16.0 + devDependencies: + nuxt: 3.0.0-rc.3 + + packages/trpc: + specifiers: + '@nuxt/kit': ^3.0.0-rc.3 + '@nuxt/module-builder': latest + '@trpc/client': ^9.23.3 + '@trpc/server': ^9.23.2 + '@types/fs-extra': ^9.0.13 + fs-extra: ^10.1.0 + h3: ^0.7.8 + nuxt: ^3.0.0-rc.3 + ohash: ^0.1.0 + pathe: ^0.3.0 + ufo: ^0.8.4 dependencies: '@nuxt/kit': 3.0.0-rc.3 - '@trpc/server': 9.23.3 + '@trpc/client': 9.23.4_@trpc+server@9.23.4 + '@trpc/server': 9.23.4 fs-extra: 10.1.0 + h3: 0.7.8 + ohash: 0.1.0 pathe: 0.3.0 ufo: 0.8.4 devDependencies: - '@antfu/eslint-config': 0.23.1_eslint@8.15.0 '@nuxt/module-builder': 0.1.7 '@types/fs-extra': 9.0.13 - eslint: 8.15.0 nuxt: 3.0.0-rc.3 - zod: 3.16.0 packages: @@ -38,7 +63,7 @@ packages: '@jridgewell/gen-mapping': 0.1.1 '@jridgewell/trace-mapping': 0.3.13 - /@antfu/eslint-config-basic/0.23.1_doddzorl55y6dbr5ij3nshfl64: + /@antfu/eslint-config-basic/0.23.1_ae4wjpjlz2l2qm7erdt4inxtpu: resolution: {integrity: sha512-9h0hqK+E/upIrSVTo2Nt2SQoKRqouDhiJcrdkOx3RgvQkcZItuZnpWI2WGDMWQ3WTjE4fYyd+F4p7Mx/QHvX8w==} peerDependencies: eslint: '>=7.4.0' @@ -47,7 +72,7 @@ packages: eslint-plugin-antfu: 0.23.1_eslint@8.15.0 eslint-plugin-eslint-comments: 3.2.0_eslint@8.15.0 eslint-plugin-html: 6.2.0 - eslint-plugin-import: 2.26.0_doddzorl55y6dbr5ij3nshfl64 + eslint-plugin-import: 2.26.0_ae4wjpjlz2l2qm7erdt4inxtpu eslint-plugin-jsonc: 2.2.1_eslint@8.15.0 eslint-plugin-markdown: 2.2.1_eslint@8.15.0 eslint-plugin-n: 15.2.0_eslint@8.15.0 @@ -85,9 +110,9 @@ packages: eslint: '>=7.4.0' typescript: '>=3.9' dependencies: - '@antfu/eslint-config-basic': 0.23.1_doddzorl55y6dbr5ij3nshfl64 - '@typescript-eslint/eslint-plugin': 5.23.0_doddzorl55y6dbr5ij3nshfl64 - '@typescript-eslint/parser': 5.23.0_eslint@8.15.0 + '@antfu/eslint-config-basic': 0.23.1_ae4wjpjlz2l2qm7erdt4inxtpu + '@typescript-eslint/eslint-plugin': 5.24.0_ae4wjpjlz2l2qm7erdt4inxtpu + '@typescript-eslint/parser': 5.24.0_eslint@8.15.0 eslint: 8.15.0 transitivePeerDependencies: - eslint-import-resolver-typescript @@ -117,12 +142,12 @@ packages: dependencies: '@antfu/eslint-config-react': 0.23.1_eslint@8.15.0 '@antfu/eslint-config-vue': 0.23.1_eslint@8.15.0 - '@typescript-eslint/eslint-plugin': 5.23.0_doddzorl55y6dbr5ij3nshfl64 - '@typescript-eslint/parser': 5.23.0_eslint@8.15.0 + '@typescript-eslint/eslint-plugin': 5.24.0_ae4wjpjlz2l2qm7erdt4inxtpu + '@typescript-eslint/parser': 5.24.0_eslint@8.15.0 eslint: 8.15.0 eslint-plugin-eslint-comments: 3.2.0_eslint@8.15.0 eslint-plugin-html: 6.2.0 - eslint-plugin-import: 2.26.0_doddzorl55y6dbr5ij3nshfl64 + eslint-plugin-import: 2.26.0_ae4wjpjlz2l2qm7erdt4inxtpu eslint-plugin-jsonc: 2.2.1_eslint@8.15.0 eslint-plugin-n: 15.2.0_eslint@8.15.0 eslint-plugin-promise: 6.0.0_eslint@8.15.0 @@ -138,6 +163,11 @@ packages: - typescript dev: true + /@antfu/ni/0.16.2: + resolution: {integrity: sha512-HZH4I07EYKU4KZLtUYm/zEmaDIhaq51H/qu45uH1AcUPWqMGbB7evE/TnSr0SGInEA+oQs4Is5Vn/PmQhfuU5w==} + hasBin: true + dev: true + /@babel/code-frame/7.16.7: resolution: {integrity: sha512-iAXqUn8IIeBTNd72xsFlgaXHkMBMt6y4HJp1tIaK465CWLT/fG1aqB7ykr95gHHmlBdGbFeWWfyB4NJJ0nmeIg==} engines: {node: '>=6.9.0'} @@ -375,6 +405,13 @@ packages: - supports-color dev: true + /@babel/runtime/7.17.9: + resolution: {integrity: sha512-lSiBBvodq29uShpWGNbgFdKYNiFDo5/HIYsaCEY9ff4sb10x9jizo2+pRrSyF4jKZCXqgzuqBOQKbUm90gQwJg==} + engines: {node: '>=6.9.0'} + dependencies: + regenerator-runtime: 0.13.9 + dev: false + /@babel/standalone/7.17.11: resolution: {integrity: sha512-47wVYBeTktYHwtzlFuK7qqV/H5X6mU4MUNqpQ9iiJOqnP8rWL0eX0GWLKRsv8D8suYzhuS1K/dtwgGr+26U7Gg==} engines: {node: '>=6.9.0'} @@ -871,8 +908,17 @@ packages: estree-walker: 2.0.2 picomatch: 2.3.1 - /@trpc/server/9.23.3: - resolution: {integrity: sha512-J8TWw/Y5TFp6QGfdry224TgfnkqXETpxAwYZS+dwf3uYCQG49sdl9RUgrf5V2IxVnQA5OXQtjDHJUSzHM7okwQ==} + /@trpc/client/9.23.4_@trpc+server@9.23.4: + resolution: {integrity: sha512-usZgbydmqqzUqJQD5yY9f+KftYBKz6ed0J90MYETqRwXl9XtR9kKOwRRMBQwZDdeMhai3Hlk4sDWeC9HR3auRQ==} + peerDependencies: + '@trpc/server': 9.23.4 + dependencies: + '@babel/runtime': 7.17.9 + '@trpc/server': 9.23.4 + dev: false + + /@trpc/server/9.23.4: + resolution: {integrity: sha512-nlOgft5g4BziNplDHhw7f4m9+k8lRPFtVVi8VGxOINt7sQ8pzzEti0WMIl2BX6gugw92t+kae2O5e793AFJs9g==} dev: false /@trysound/sax/0.2.0: @@ -942,8 +988,8 @@ packages: resolution: {integrity: sha512-PBjIUxZHOuj0R15/xuwJYjFi+KZdNFrehocChv4g5hu6aFroHue8m0lBP0POdK2nKzbw0cgV1mws8+V/JAcEkQ==} dev: true - /@typescript-eslint/eslint-plugin/5.23.0_doddzorl55y6dbr5ij3nshfl64: - resolution: {integrity: sha512-hEcSmG4XodSLiAp1uxv/OQSGsDY6QN3TcRU32gANp+19wGE1QQZLRS8/GV58VRUoXhnkuJ3ZxNQ3T6Z6zM59DA==} + /@typescript-eslint/eslint-plugin/5.24.0_ae4wjpjlz2l2qm7erdt4inxtpu: + resolution: {integrity: sha512-6bqFGk6wa9+6RrU++eLknKyDqXU1Oc8nyoLu5a1fU17PNRJd9UBr56rMF7c4DRaRtnarlkQ4jwxUbvBo8cNlpw==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} peerDependencies: '@typescript-eslint/parser': ^5.0.0 @@ -953,10 +999,10 @@ packages: typescript: optional: true dependencies: - '@typescript-eslint/parser': 5.23.0_eslint@8.15.0 - '@typescript-eslint/scope-manager': 5.23.0 - '@typescript-eslint/type-utils': 5.23.0_eslint@8.15.0 - '@typescript-eslint/utils': 5.23.0_eslint@8.15.0 + '@typescript-eslint/parser': 5.24.0_eslint@8.15.0 + '@typescript-eslint/scope-manager': 5.24.0 + '@typescript-eslint/type-utils': 5.24.0_eslint@8.15.0 + '@typescript-eslint/utils': 5.24.0_eslint@8.15.0 debug: 4.3.4 eslint: 8.15.0 functional-red-black-tree: 1.0.1 @@ -968,8 +1014,8 @@ packages: - supports-color dev: true - /@typescript-eslint/parser/5.23.0_eslint@8.15.0: - resolution: {integrity: sha512-V06cYUkqcGqpFjb8ttVgzNF53tgbB/KoQT/iB++DOIExKmzI9vBJKjZKt/6FuV9c+zrDsvJKbJ2DOCYwX91cbw==} + /@typescript-eslint/parser/5.24.0_eslint@8.15.0: + resolution: {integrity: sha512-4q29C6xFYZ5B2CXqSBBdcS0lPyfM9M09DoQLtHS5kf+WbpV8pBBhHDLNhXfgyVwFnhrhYzOu7xmg02DzxeF2Uw==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} peerDependencies: eslint: ^6.0.0 || ^7.0.0 || ^8.0.0 @@ -978,25 +1024,25 @@ packages: typescript: optional: true dependencies: - '@typescript-eslint/scope-manager': 5.23.0 - '@typescript-eslint/types': 5.23.0 - '@typescript-eslint/typescript-estree': 5.23.0 + '@typescript-eslint/scope-manager': 5.24.0 + '@typescript-eslint/types': 5.24.0 + '@typescript-eslint/typescript-estree': 5.24.0 debug: 4.3.4 eslint: 8.15.0 transitivePeerDependencies: - supports-color dev: true - /@typescript-eslint/scope-manager/5.23.0: - resolution: {integrity: sha512-EhjaFELQHCRb5wTwlGsNMvzK9b8Oco4aYNleeDlNuL6qXWDF47ch4EhVNPh8Rdhf9tmqbN4sWDk/8g+Z/J8JVw==} + /@typescript-eslint/scope-manager/5.24.0: + resolution: {integrity: sha512-WpMWipcDzGmMzdT7NtTjRXFabx10WleLUGrJpuJLGaxSqpcyq5ACpKSD5VE40h2nz3melQ91aP4Du7lh9FliCA==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} dependencies: - '@typescript-eslint/types': 5.23.0 - '@typescript-eslint/visitor-keys': 5.23.0 + '@typescript-eslint/types': 5.24.0 + '@typescript-eslint/visitor-keys': 5.24.0 dev: true - /@typescript-eslint/type-utils/5.23.0_eslint@8.15.0: - resolution: {integrity: sha512-iuI05JsJl/SUnOTXA9f4oI+/4qS/Zcgk+s2ir+lRmXI+80D8GaGwoUqs4p+X+4AxDolPpEpVUdlEH4ADxFy4gw==} + /@typescript-eslint/type-utils/5.24.0_eslint@8.15.0: + resolution: {integrity: sha512-uGi+sQiM6E5CeCZYBXiaIvIChBXru4LZ1tMoeKbh1Lze+8BO9syUG07594C4lvN2YPT4KVeIupOJkVI+9/DAmQ==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} peerDependencies: eslint: '*' @@ -1005,7 +1051,7 @@ packages: typescript: optional: true dependencies: - '@typescript-eslint/utils': 5.23.0_eslint@8.15.0 + '@typescript-eslint/utils': 5.24.0_eslint@8.15.0 debug: 4.3.4 eslint: 8.15.0 tsutils: 3.21.0 @@ -1013,13 +1059,13 @@ packages: - supports-color dev: true - /@typescript-eslint/types/5.23.0: - resolution: {integrity: sha512-NfBsV/h4dir/8mJwdZz7JFibaKC3E/QdeMEDJhiAE3/eMkoniZ7MjbEMCGXw6MZnZDMN3G9S0mH/6WUIj91dmw==} + /@typescript-eslint/types/5.24.0: + resolution: {integrity: sha512-Tpg1c3shTDgTmZd3qdUyd+16r/pGmVaVEbLs+ufuWP0EruVbUiEOmpBBQxBb9a8iPRxi8Rb2oiwOxuZJzSq11A==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} dev: true - /@typescript-eslint/typescript-estree/5.23.0: - resolution: {integrity: sha512-xE9e0lrHhI647SlGMl+m+3E3CKPF1wzvvOEWnuE3CCjjT7UiRnDGJxmAcVKJIlFgK6DY9RB98eLr1OPigPEOGg==} + /@typescript-eslint/typescript-estree/5.24.0: + resolution: {integrity: sha512-zcor6vQkQmZAQfebSPVwUk/FD+CvnsnlfKXYeQDsWXRF+t7SBPmIfNia/wQxCSeu1h1JIjwV2i9f5/DdSp/uDw==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} peerDependencies: typescript: '*' @@ -1027,8 +1073,8 @@ packages: typescript: optional: true dependencies: - '@typescript-eslint/types': 5.23.0 - '@typescript-eslint/visitor-keys': 5.23.0 + '@typescript-eslint/types': 5.24.0 + '@typescript-eslint/visitor-keys': 5.24.0 debug: 4.3.4 globby: 11.1.0 is-glob: 4.0.3 @@ -1038,16 +1084,16 @@ packages: - supports-color dev: true - /@typescript-eslint/utils/5.23.0_eslint@8.15.0: - resolution: {integrity: sha512-dbgaKN21drqpkbbedGMNPCtRPZo1IOUr5EI9Jrrh99r5UW5Q0dz46RKXeSBoPV+56R6dFKpbrdhgUNSJsDDRZA==} + /@typescript-eslint/utils/5.24.0_eslint@8.15.0: + resolution: {integrity: sha512-K05sbWoeCBJH8KXu6hetBJ+ukG0k2u2KlgD3bN+v+oBKm8adJqVHpSSLHNzqyuv0Lh4GVSAUgZ5lB4icmPmWLw==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} peerDependencies: eslint: ^6.0.0 || ^7.0.0 || ^8.0.0 dependencies: '@types/json-schema': 7.0.11 - '@typescript-eslint/scope-manager': 5.23.0 - '@typescript-eslint/types': 5.23.0 - '@typescript-eslint/typescript-estree': 5.23.0 + '@typescript-eslint/scope-manager': 5.24.0 + '@typescript-eslint/types': 5.24.0 + '@typescript-eslint/typescript-estree': 5.24.0 eslint: 8.15.0 eslint-scope: 5.1.1 eslint-utils: 3.0.0_eslint@8.15.0 @@ -1056,11 +1102,11 @@ packages: - typescript dev: true - /@typescript-eslint/visitor-keys/5.23.0: - resolution: {integrity: sha512-Vd4mFNchU62sJB8pX19ZSPog05B0Y0CE2UxAZPT5k4iqhRYjPnqyY3woMxCd0++t9OTqkgjST+1ydLBi7e2Fvg==} + /@typescript-eslint/visitor-keys/5.24.0: + resolution: {integrity: sha512-qzGwSXMyMnogcAo+/2fU+jhlPPVMXlIH2PeAonIKjJSoDKl1+lJVvG5Z5Oud36yU0TWK2cs1p/FaSN5J2OUFYA==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} dependencies: - '@typescript-eslint/types': 5.23.0 + '@typescript-eslint/types': 5.24.0 eslint-visitor-keys: 3.3.0 dev: true @@ -1750,7 +1796,6 @@ packages: /cookie-es/0.5.0: resolution: {integrity: sha512-RyZrFi6PNpBFbIaQjXDlFIhFVqV42QeKSZX1yQIl6ihImq6vcHNGMtqQ/QzY3RMPuYSkvsRwtnt5M9NeYxKt0g==} - dev: true /core-util-is/1.0.3: resolution: {integrity: sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==} @@ -2576,7 +2621,7 @@ packages: - supports-color dev: true - /eslint-module-utils/2.7.3_cphntlaow2spielwlvsegonsm4: + /eslint-module-utils/2.7.3_bi6p7cyrvxrvblpcgmvuwzeqom: resolution: {integrity: sha512-088JEC7O3lDZM9xGe0RerkOMd0EjFl+Yvd1jPWIkMT5u3H9+HC34mWWPnqPrN13gieT9pBOO+Qt07Nb/6TresQ==} engines: {node: '>=4'} peerDependencies: @@ -2594,7 +2639,7 @@ packages: eslint-import-resolver-webpack: optional: true dependencies: - '@typescript-eslint/parser': 5.23.0_eslint@8.15.0 + '@typescript-eslint/parser': 5.24.0_eslint@8.15.0 debug: 3.2.7 eslint-import-resolver-node: 0.3.6 find-up: 2.1.0 @@ -2605,7 +2650,7 @@ packages: /eslint-plugin-antfu/0.23.1_eslint@8.15.0: resolution: {integrity: sha512-GCc4hqHqPPVM4xIFHUKJFpOZbl9C48t9SupePiNjFisUHAxrZj/c1EHCt0LV0TONJHtSZDR53NNWMuB3O2USSg==} dependencies: - '@typescript-eslint/utils': 5.23.0_eslint@8.15.0 + '@typescript-eslint/utils': 5.24.0_eslint@8.15.0 transitivePeerDependencies: - eslint - supports-color @@ -2640,7 +2685,7 @@ packages: htmlparser2: 7.2.0 dev: true - /eslint-plugin-import/2.26.0_doddzorl55y6dbr5ij3nshfl64: + /eslint-plugin-import/2.26.0_ae4wjpjlz2l2qm7erdt4inxtpu: resolution: {integrity: sha512-hYfi3FXaM8WPLf4S1cikh/r4IxnO6zrhZbEGz2b660EJRbuxgpDS5gkCuYgGWg2xxh2rBuIr4Pvhve/7c31koA==} engines: {node: '>=4'} peerDependencies: @@ -2650,14 +2695,14 @@ packages: '@typescript-eslint/parser': optional: true dependencies: - '@typescript-eslint/parser': 5.23.0_eslint@8.15.0 + '@typescript-eslint/parser': 5.24.0_eslint@8.15.0 array-includes: 3.1.5 array.prototype.flat: 1.3.0 debug: 2.6.9 doctrine: 2.1.0 eslint: 8.15.0 eslint-import-resolver-node: 0.3.6 - eslint-module-utils: 2.7.3_cphntlaow2spielwlvsegonsm4 + eslint-module-utils: 2.7.3_bi6p7cyrvxrvblpcgmvuwzeqom has: 1.0.3 is-core-module: 2.9.0 is-glob: 4.0.3 @@ -3327,7 +3372,6 @@ packages: destr: 1.1.1 radix3: 0.1.2 ufo: 0.8.4 - dev: true /has-bigints/1.0.2: resolution: {integrity: sha512-tSvCKtBr9lkF0Ex0aQiP9N+OpV4zi2r/Nee5VkRDbaqv35RLYMzbwQfFSZZH0kR+Rd6302UJZ2p/bJCEoR3VoQ==} @@ -4569,7 +4613,6 @@ packages: /ohash/0.1.0: resolution: {integrity: sha512-KvclyhWseX6F2UTEEp9Qzybb0LTGorTSVufAToV5tR2B6Q64rVhKhkcU/o+mBaiqGa5+PdobtfSVelp8VOCR6A==} - dev: true /ohmyfetch/0.4.17: resolution: {integrity: sha512-jUpCDJIDlTZdS4PE3veoHIXoUSm2NRJfFMIROd29/qeOsbJEoEYBzJ6re+W1hskc44ej11IL//scfhckIcCN8Q==} @@ -4812,6 +4855,12 @@ packages: engines: {node: '>=4'} dev: true + /pnpm/7.1.0: + resolution: {integrity: sha512-iT2Hk2jycfh8NXoEnwpg7oCNMwsMlheSR9QAgkhWtRHvjfAAtp0HsKEOA62ILoAwbvv/ea8Ph5lTQLsGQJRq+w==} + engines: {node: '>=14.19'} + hasBin: true + dev: true + /postcss-calc/8.2.4_postcss@8.4.13: resolution: {integrity: sha512-SmWMSJmB8MRnnULldx0lQIyhSNvuDl9HfrZkaqqE/WHAhToYsAvDq+yAsA/kIyINDszOp3Rh0GFoNuH5Ypsm3Q==} peerDependencies: @@ -5204,7 +5253,6 @@ packages: /radix3/0.1.2: resolution: {integrity: sha512-Mpfd/OuX0zoJ6ojLD/RTOHvJPg6e6PjINtmYzV87kIXc5iUtDz34i7gg4SV4XjqRJTmSiYO/g9i/mKWGf4z8wg==} - dev: true /randombytes/2.1.0: resolution: {integrity: sha512-vYl3iOX+4CKUWuxGi9Ukhie6fsqXqS9FE2Zaic4tNFD2N2QQaXOMFbuKK4QmDHC0JO6B1Zp41J0LpT0oR68amQ==} @@ -5307,6 +5355,10 @@ packages: redis-errors: 1.2.0 dev: true + /regenerator-runtime/0.13.9: + resolution: {integrity: sha512-p3VT+cOEgxFsRRA9X4lkI1E+k2/CtnKtU4gcxyaCUreilL/vqI6CdZ3wxVUx3UOUg+gnUOQQcRI7BmSI656MYA==} + dev: false + /regexp-tree/0.1.24: resolution: {integrity: sha512-s2aEVuLhvnVJW6s/iPgEGK6R+/xngd2jNQ+xy4bXNDKxZKJH6jpPHY6kVeVv1IeLCHgswRj+Kl3ELaDjG6V1iw==} hasBin: true @@ -6512,7 +6564,7 @@ packages: /wide-align/1.1.5: resolution: {integrity: sha512-eDMORYaPNZ4sQIuuYPDHdQvf4gyCF9rEEV/yPxGfwPkRodwEgiMUUXTx/dex+Me0wxx53S+NgUHaP7y3MGlDmg==} dependencies: - string-width: 1.0.2 + string-width: 4.2.3 dev: true /word-wrap/1.2.3: @@ -6606,4 +6658,4 @@ packages: /zod/3.16.0: resolution: {integrity: sha512-szrIkryADbTM+xBt2a1KoS2CJQXec4f9xG78bj5MJeEH/XqmmHpnO+fG3IE115AKBJak+2HrbxLZkc9mhdbDKA==} - dev: true + dev: false diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index 52fdbb5..924b55f 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -1,2 +1,2 @@ packages: - - playground + - packages/* diff --git a/src/module.ts b/src/module.ts deleted file mode 100644 index e0df8b3..0000000 --- a/src/module.ts +++ /dev/null @@ -1,72 +0,0 @@ -import { fileURLToPath } from 'url' -import { dirname, resolve } from 'path' -import { addServerHandler, addTemplate, defineNuxtModule } from '@nuxt/kit' -import fs from 'fs-extra' - -export interface ModuleOptions {} - -export default defineNuxtModule({ - meta: { - name: 'trpc-nuxt', - configKey: 'trpc', - }, - defaults: {}, - async setup(_options, nuxt) { - const srcDir = nuxt.options.srcDir - // const root = nuxt.options.rootDir - // const clientPath = join(nuxt.options.buildDir, 'trpc-client.ts') - // const runtimeDir = fileURLToPath(new URL('./runtime', import.meta.url)) - // const serverPath = resolve(root, 'server/fn') - const buildDir = fileURLToPath(new URL(nuxt.options.buildDir, import.meta.url)) - // const rootDir = fileURLToPath(new URL(root, import.meta.url)) - - // nuxt.hook('config', (options) => { - // options.build.transpile.push('trpc-nuxt/client') - // }) - - // nuxt.hook('autoImports:extend', (imports) => { - // imports.push({ - // from: clientPath, - // name: 'useServerFn', - // as: 'useServerFn', - // }) - // }) - - const routePath = resolve(srcDir, 'server/fn/index.ts') - await fs.ensureDir(dirname(routePath)) - if (!fs.existsSync(routePath)) { - await fs.writeFile(routePath, ` - // generated by trpc-nuxt - import * as trpc from '@trpc/server' - - export const router = trpc - .router() - .query('hello', { - resolve: () => 'world', - }); - - export type Router = typeof router - `.trimStart()) - } - - const handlerPath = resolve(srcDir, 'server/fn') - addTemplate({ - filename: 'trpc-handler.mjs', - write: true, - getContents() { - return ` - import { createTRPCHandler } from 'trpc-nuxt/api' - import * as functions from "${handlerPath}" - export default createTRPCHandler({ - router: functions.router - }) - `.trimStart() - }, - }) - - addServerHandler({ - route: '/api/trpc/*', - handler: resolve(buildDir, 'trpc-handler.mjs'), - }) - }, -}) diff --git a/tsconfig.json b/tsconfig.json deleted file mode 100644 index 9dd826f..0000000 --- a/tsconfig.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "extends": "./playground/.nuxt/tsconfig.json" -}