diff --git a/apps/content/examples/contract.ts b/apps/content/examples/contract.ts index d79d0e2d..81bf55fb 100644 --- a/apps/content/examples/contract.ts +++ b/apps/content/examples/contract.ts @@ -1,12 +1,9 @@ import type { InferContractRouterInputs, InferContractRouterOutputs } from '@orpc/contract' import { oc } from '@orpc/contract' +import { ORPCError, os } from '@orpc/server' import { oz, ZodCoercer } from '@orpc/zod' import { z } from 'zod' -// Implement the contract - -import { ORPCError, os } from '@orpc/server' - // Define your contract first // This contract can replace server router in most-case @@ -63,6 +60,8 @@ export const contract = oc.router({ export type Inputs = InferContractRouterInputs export type Outputs = InferContractRouterOutputs +// Implement the contract + export type Context = { user?: { id: string } } export const base = os.context() export const pub /** os with ... */ = base.contract(contract) // Ensure every implement must be match contract @@ -114,11 +113,11 @@ export const router = pub.router({ }, }) +// Modern runtime that support fetch api like deno, bun, cloudflare workers, even node can used +import { createServer } from 'node:http' // Expose apis to the internet with fetch handler import { OpenAPIServerlessHandler } from '@orpc/openapi/fetch' import { CompositeHandler, ORPCHandler } from '@orpc/server/fetch' -// Modern runtime that support fetch api like deno, bun, cloudflare workers, even node can used -import { createServer } from 'node:http' import { createServerAdapter } from '@whatwg-node/server' const openapiHandler = new OpenAPIServerlessHandler(router, { diff --git a/apps/content/examples/open-api.ts b/apps/content/examples/open-api.ts index 2366a23d..30e551c4 100644 --- a/apps/content/examples/open-api.ts +++ b/apps/content/examples/open-api.ts @@ -1,8 +1,6 @@ import { generateOpenAPI } from '@orpc/openapi' -import { router } from 'examples/server' - -// or generate from contract import { contract } from 'examples/contract' +import { router } from 'examples/server' export const specFromServerRouter = generateOpenAPI({ router, diff --git a/apps/content/examples/server.ts b/apps/content/examples/server.ts index 62a77312..ad32f9a9 100644 --- a/apps/content/examples/server.ts +++ b/apps/content/examples/server.ts @@ -88,11 +88,11 @@ export const router = pub.router({ export type Inputs = InferRouterInputs export type Outputs = InferRouterOutputs +// Modern runtime that support fetch api like deno, bun, cloudflare workers, even node can used +import { createServer } from 'node:http' // Expose apis to the internet with fetch handler import { OpenAPIServerlessHandler } from '@orpc/openapi/fetch' import { CompositeHandler, ORPCHandler } from '@orpc/server/fetch' -// Modern runtime that support fetch api like deno, bun, cloudflare workers, even node can used -import { createServer } from 'node:http' import { createServerAdapter } from '@whatwg-node/server' const openapiHandler = new OpenAPIServerlessHandler(router, { diff --git a/packages/openapi/src/fetch/openapi-procedure-matcher.ts b/packages/openapi/src/fetch/openapi-procedure-matcher.ts index 31bba2b4..4e4f152c 100644 --- a/packages/openapi/src/fetch/openapi-procedure-matcher.ts +++ b/packages/openapi/src/fetch/openapi-procedure-matcher.ts @@ -55,9 +55,9 @@ export class OpenAPIProcedureMatcher { const path = match[0][1] const params = paramStash ? mapValues( - match[1] as ParamIndexMap, // if paramStash is defined, then match[1] is ParamIndexMap - v => paramStash[v]!, - ) + match[1] as ParamIndexMap, // if paramStash is defined, then match[1] is ParamIndexMap + v => paramStash[v]!, + ) : match[1] as Params // if paramStash is undefined, then match[1] is Params const { default: maybeProcedure } = await unlazy(getRouterChild(this.router, ...path)) diff --git a/packages/openapi/src/generator.ts b/packages/openapi/src/generator.ts index 5456f982..83b011c7 100644 --- a/packages/openapi/src/generator.ts +++ b/packages/openapi/src/generator.ts @@ -145,15 +145,15 @@ export async function generateOpenAPI( ...inputSchema, properties: inputSchema.properties ? Object.entries(inputSchema.properties).reduce( - (acc, [key, value]) => { - if (key !== name) { - acc[key] = value - } - - return acc - }, - {} as Record, - ) + (acc, [key, value]) => { + if (key !== name) { + acc[key] = value + } + + return acc + }, + {} as Record, + ) : undefined, required: inputSchema.required?.filter(v => v !== name), examples: inputSchema.examples?.map((example) => { diff --git a/packages/react/src/react-utils.ts b/packages/react/src/react-utils.ts index d4372057..ebf36ed7 100644 --- a/packages/react/src/react-utils.ts +++ b/packages/react/src/react-utils.ts @@ -35,10 +35,10 @@ export function createORPCUtils>( // for sure root is not procedure, so do not it procedure utils on root const procedureUtils = path.length ? createProcedureUtils({ - client, - queryClient: options.contextValue.queryClient, - path, - }) + client, + queryClient: options.contextValue.queryClient, + path, + }) : {} return new Proxy( diff --git a/packages/server/src/router-client.ts b/packages/server/src/router-client.ts index 0df11cb7..4de9ba3f 100644 --- a/packages/server/src/router-client.ts +++ b/packages/server/src/router-client.ts @@ -57,11 +57,11 @@ export function createRouterClient< const procedureCaller = isLazy(options.router) ? createProcedureClient({ - ...options, - procedure: createLazyProcedureFormAnyLazy(options.router), - context: options.context, - path: options.path, - }) + ...options, + procedure: createLazyProcedureFormAnyLazy(options.router), + context: options.context, + path: options.path, + }) : {} const recursive = new Proxy(procedureCaller, { diff --git a/playgrounds/nuxt/lib/orpc.ts b/playgrounds/nuxt/lib/orpc.ts index 274dd699..797baac4 100644 --- a/playgrounds/nuxt/lib/orpc.ts +++ b/playgrounds/nuxt/lib/orpc.ts @@ -1,6 +1,6 @@ +import type { router } from '~/server/router' import { createORPCFetchClient } from '@orpc/client' import { createORPCVueQueryUtils } from '@orpc/vue-query' -import type { router } from '~/server/router' export const client = createORPCFetchClient({ baseURL: 'http://localhost:3000/api', diff --git a/playgrounds/nuxt/plugins/vue-query.ts b/playgrounds/nuxt/plugins/vue-query.ts index 0c23ab11..4a79ab06 100644 --- a/playgrounds/nuxt/plugins/vue-query.ts +++ b/playgrounds/nuxt/plugins/vue-query.ts @@ -2,14 +2,14 @@ import type { DehydratedState, VueQueryPluginOptions, } from '@tanstack/vue-query' +// Nuxt 3 app aliases +import { defineNuxtPlugin, useState } from '#imports' import { dehydrate, hydrate, QueryClient, VueQueryPlugin, } from '@tanstack/vue-query' -// Nuxt 3 app aliases -import { defineNuxtPlugin, useState } from '#imports' export default defineNuxtPlugin((nuxt) => { const vueQueryState = useState('vue-query')