@trpc/next 11.18.1-canary.9 → 11.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/dist/app-dir/client.cjs +25 -30
  2. package/dist/app-dir/client.d.cts +5 -8
  3. package/dist/app-dir/client.d.cts.map +1 -1
  4. package/dist/app-dir/client.d.mts +5 -8
  5. package/dist/app-dir/client.d.mts.map +1 -1
  6. package/dist/app-dir/client.mjs +11 -15
  7. package/dist/app-dir/client.mjs.map +1 -1
  8. package/dist/app-dir/links/nextCache.cjs +15 -18
  9. package/dist/app-dir/links/nextCache.d.cts +1 -3
  10. package/dist/app-dir/links/nextCache.d.cts.map +1 -1
  11. package/dist/app-dir/links/nextCache.d.mts +1 -3
  12. package/dist/app-dir/links/nextCache.d.mts.map +1 -1
  13. package/dist/app-dir/links/nextCache.mjs +5 -7
  14. package/dist/app-dir/links/nextCache.mjs.map +1 -1
  15. package/dist/app-dir/links/nextHttp.cjs +7 -11
  16. package/dist/app-dir/links/nextHttp.d.cts +1 -3
  17. package/dist/app-dir/links/nextHttp.d.cts.map +1 -1
  18. package/dist/app-dir/links/nextHttp.d.mts +1 -3
  19. package/dist/app-dir/links/nextHttp.d.mts.map +1 -1
  20. package/dist/app-dir/links/nextHttp.mjs +5 -8
  21. package/dist/app-dir/links/nextHttp.mjs.map +1 -1
  22. package/dist/app-dir/server.cjs +18 -21
  23. package/dist/app-dir/server.d.cts +2 -2
  24. package/dist/app-dir/server.d.mts +2 -2
  25. package/dist/app-dir/server.mjs +3 -5
  26. package/dist/app-dir/server.mjs.map +1 -1
  27. package/dist/index.cjs +47 -36
  28. package/dist/index.d.cts +5 -9
  29. package/dist/index.d.cts.map +1 -1
  30. package/dist/index.d.mts +5 -9
  31. package/dist/index.d.mts.map +1 -1
  32. package/dist/index.mjs +12 -23
  33. package/dist/index.mjs.map +1 -1
  34. package/dist/objectSpread2-C2ceYbQe.cjs +67 -0
  35. package/dist/objectSpread2-Dh4InpQf.mjs +62 -0
  36. package/dist/{server.d-C5p0ZwB7.d.mts → server-BSCiwefJ.d.cts} +5 -13
  37. package/dist/server-BSCiwefJ.d.cts.map +1 -0
  38. package/dist/{server.d-DLnegS7F.d.cts → server-DQOX6CNV.d.mts} +5 -13
  39. package/dist/server-DQOX6CNV.d.mts.map +1 -0
  40. package/dist/shared-BcvoW6jT.cjs +26 -0
  41. package/dist/{shared-Bco66qhk.mjs → shared-DJ-gGeuI.mjs} +5 -6
  42. package/dist/shared-DJ-gGeuI.mjs.map +1 -0
  43. package/dist/ssrPrepass.cjs +23 -28
  44. package/dist/ssrPrepass.d.cts +2 -6
  45. package/dist/ssrPrepass.d.cts.map +1 -1
  46. package/dist/ssrPrepass.d.mts +2 -6
  47. package/dist/ssrPrepass.d.mts.map +1 -1
  48. package/dist/ssrPrepass.mjs +13 -17
  49. package/dist/ssrPrepass.mjs.map +1 -1
  50. package/dist/{withTRPC.d-DctYN4Yz.d.cts → withTRPC-BchtyodQ.d.mts} +5 -7
  51. package/dist/withTRPC-BchtyodQ.d.mts.map +1 -0
  52. package/dist/{withTRPC.d-B3f3A0sf.d.mts → withTRPC-DywCxFfq.d.cts} +5 -7
  53. package/dist/withTRPC-DywCxFfq.d.cts.map +1 -0
  54. package/package.json +14 -14
  55. package/src/app-dir/create-action-hook.tsx +16 -12
  56. package/src/ssrPrepass.ts +1 -2
  57. package/src/withTRPC.tsx +1 -2
  58. package/dist/chunk-DWy1uDak.cjs +0 -39
  59. package/dist/objectSpread2-3tHFGdJc.mjs +0 -114
  60. package/dist/objectSpread2-3tHFGdJc.mjs.map +0 -1
  61. package/dist/objectSpread2-CGXFkI72.cjs +0 -94
  62. package/dist/server.d-C5p0ZwB7.d.mts.map +0 -1
  63. package/dist/server.d-DLnegS7F.d.cts.map +0 -1
  64. package/dist/shared-Bco66qhk.mjs.map +0 -1
  65. package/dist/shared-COdt67yK.cjs +0 -29
  66. package/dist/withTRPC.d-B3f3A0sf.d.mts.map +0 -1
  67. package/dist/withTRPC.d-DctYN4Yz.d.cts.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":["opts: WithTRPCNoSSROptions<TRouter> | WithTRPCSSROptions<TRouter>","AppOrPage: NextComponentType<any, any, any>","props: AppPropsType<NextRouter, any> & {\n trpc?: $PrepassProps;\n }","queryClient","trpcClient","hydratedState: DehydratedState | undefined","appOrPageCtx: AppContextType","pageProps: Dict<unknown>","props: Dict<unknown>","opts: WithTRPCNoSSROptions<TRouter> | WithTRPCSSROptions<TRouter>"],"sources":["../src/withTRPC.tsx","../src/createTRPCNext.tsx"],"sourcesContent":["/**\n * Heavily based on urql's ssr\n * https://github.com/FormidableLabs/urql/blob/main/packages/next-urql/src/with-urql-client.ts\n */\nimport type { DehydratedState, QueryClient } from '@tanstack/react-query';\nimport { HydrationBoundary, QueryClientProvider } from '@tanstack/react-query';\nimport type {\n CreateTRPCClientOptions,\n TRPCClient,\n TRPCClientError,\n TRPCUntypedClient,\n} from '@trpc/client';\nimport type { CoercedTransformerParameters } from '@trpc/client/unstable-internals';\nimport {\n getTransformer,\n type TransformerOptions,\n} from '@trpc/client/unstable-internals';\nimport type {\n CreateTRPCReactOptions,\n CreateTRPCReactQueryClientConfig,\n} from '@trpc/react-query/shared';\nimport { createRootHooks, getQueryClient } from '@trpc/react-query/shared';\nimport type {\n AnyRouter,\n Dict,\n inferClientTypes,\n ResponseMeta,\n} from '@trpc/server/unstable-core-do-not-import';\nimport type {\n AppContextType,\n AppPropsType,\n NextComponentType,\n NextPageContext,\n} from 'next/dist/shared/lib/utils';\nimport type { NextRouter } from 'next/router';\nimport React, { useState } from 'react';\n\nexport type WithTRPCConfig<TRouter extends AnyRouter> =\n CreateTRPCClientOptions<TRouter> &\n CreateTRPCReactQueryClientConfig & {\n abortOnUnmount?: boolean;\n };\n\ntype WithTRPCOptions<TRouter extends AnyRouter> =\n CreateTRPCReactOptions<TRouter> & {\n config: (info: { ctx?: NextPageContext }) => WithTRPCConfig<TRouter>;\n } & TransformerOptions<inferClientTypes<TRouter>>;\n\nexport type TRPCPrepassHelper = (opts: {\n parent: WithTRPCSSROptions<AnyRouter>;\n WithTRPC: NextComponentType<any, any, any>;\n AppOrPage: NextComponentType<any, any, any>;\n}) => void;\nexport type WithTRPCSSROptions<TRouter extends AnyRouter> =\n WithTRPCOptions<TRouter> & {\n /**\n * If you enable this, you also need to add a `ssrPrepass`-prop\n * @see https://trpc.io/docs/client/nextjs/ssr\n */\n ssr:\n | true\n | ((opts: { ctx: NextPageContext }) => boolean | Promise<boolean>);\n responseMeta?: (opts: {\n ctx: NextPageContext;\n clientErrors: TRPCClientError<TRouter>[];\n }) => ResponseMeta;\n /**\n * use `import { ssrPrepass } from '@trpc/next/ssrPrepass'`\n * @see https://trpc.io/docs/client/nextjs/ssr\n */\n ssrPrepass: TRPCPrepassHelper;\n };\n\nexport type WithTRPCNoSSROptions<TRouter extends AnyRouter> =\n WithTRPCOptions<TRouter> & {\n ssr?: false;\n };\n\nexport type TRPCPrepassProps<\n TRouter extends AnyRouter,\n TSSRContext extends NextPageContext = NextPageContext,\n> = {\n config: WithTRPCConfig<TRouter>;\n queryClient: QueryClient;\n trpcClient: TRPCUntypedClient<TRouter> | TRPCClient<TRouter>;\n ssrState: 'prepass';\n ssrContext: TSSRContext;\n};\n\nexport function withTRPC<\n TRouter extends AnyRouter,\n TSSRContext extends NextPageContext = NextPageContext,\n>(opts: WithTRPCNoSSROptions<TRouter> | WithTRPCSSROptions<TRouter>) {\n const { config: getClientConfig } = opts;\n const transformer = getTransformer(\n (opts as CoercedTransformerParameters).transformer,\n );\n\n type $PrepassProps = TRPCPrepassProps<TRouter, TSSRContext>;\n return (AppOrPage: NextComponentType<any, any, any>): NextComponentType => {\n const trpc = createRootHooks<TRouter, TSSRContext>(opts);\n\n const WithTRPC = (\n props: AppPropsType<NextRouter, any> & {\n trpc?: $PrepassProps;\n },\n ) => {\n const [prepassProps] = useState(() => {\n if (props.trpc) {\n return props.trpc;\n }\n\n const config = getClientConfig({});\n const queryClient = getQueryClient(config);\n const trpcClient = trpc.createClient(config);\n\n return {\n abortOnUnmount: config.abortOnUnmount,\n queryClient,\n trpcClient,\n ssrState: opts.ssr ? ('mounting' as const) : (false as const),\n ssrContext: null,\n };\n });\n\n const { queryClient, trpcClient, ssrState, ssrContext } = prepassProps;\n\n // allow normal components to be wrapped, not just app/pages\n const trpcState = props.pageProps?.trpcState;\n\n const hydratedState: DehydratedState | undefined = React.useMemo(() => {\n if (!trpcState) {\n return trpcState;\n }\n\n return transformer.input.deserialize(trpcState);\n }, [trpcState]);\n\n return (\n <trpc.Provider\n abortOnUnmount={(prepassProps as any).abortOnUnmount ?? false}\n client={trpcClient}\n queryClient={queryClient}\n ssrState={ssrState}\n ssrContext={ssrContext}\n >\n <QueryClientProvider client={queryClient}>\n <HydrationBoundary state={hydratedState}>\n <AppOrPage {...props} />\n </HydrationBoundary>\n </QueryClientProvider>\n </trpc.Provider>\n );\n };\n\n if (opts.ssr) {\n opts.ssrPrepass({\n parent: opts,\n AppOrPage,\n WithTRPC,\n });\n } else if (AppOrPage.getInitialProps) {\n // Allow combining `getServerSideProps` and `getInitialProps`\n\n WithTRPC.getInitialProps = async (appOrPageCtx: AppContextType) => {\n // Determine if we are wrapping an App component or a Page component.\n const isApp = !!appOrPageCtx.Component;\n\n // Run the wrapped component's getInitialProps function.\n let pageProps: Dict<unknown> = {};\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const originalProps = await AppOrPage.getInitialProps!(\n appOrPageCtx as any,\n );\n const originalPageProps = isApp\n ? (originalProps.pageProps ?? {})\n : originalProps;\n\n pageProps = {\n ...originalPageProps,\n ...pageProps,\n };\n const getAppTreeProps = (props: Dict<unknown>) =>\n isApp ? { pageProps: props } : props;\n\n return getAppTreeProps(pageProps);\n };\n }\n\n const displayName = AppOrPage.displayName ?? AppOrPage.name ?? 'Component';\n WithTRPC.displayName = `withTRPC(${displayName})`;\n\n return WithTRPC as any;\n };\n}\n","/* istanbul ignore file -- @preserve */\n// We're testing this through E2E-testing\nimport type {\n CreateReactUtils,\n DecorateRouterRecord,\n TRPCUseQueries,\n TRPCUseSuspenseQueries,\n} from '@trpc/react-query/shared';\nimport {\n createReactDecoration,\n createReactQueryUtils,\n createRootHooks,\n} from '@trpc/react-query/shared';\nimport type {\n AnyRouter,\n ProtectedIntersection,\n} from '@trpc/server/unstable-core-do-not-import';\nimport { createFlatProxy } from '@trpc/server/unstable-core-do-not-import';\nimport type { NextPageContext } from 'next/types';\nimport { useMemo } from 'react';\nimport type { WithTRPCNoSSROptions, WithTRPCSSROptions } from './withTRPC';\nimport { withTRPC } from './withTRPC';\n\n/**\n * @internal\n */\nexport interface CreateTRPCNextBase<\n TRouter extends AnyRouter,\n TSSRContext extends NextPageContext,\n> {\n /**\n * @deprecated renamed to `useUtils` and will be removed in a future tRPC version\n *\n * @see https://trpc.io/docs/v11/client/react/useUtils\n */\n useContext(): CreateReactUtils<TRouter, TSSRContext>;\n /**\n * @see https://trpc.io/docs/v11/client/react/useUtils\n */\n useUtils(): CreateReactUtils<TRouter, TSSRContext>;\n withTRPC: ReturnType<typeof withTRPC<TRouter, TSSRContext>>;\n useQueries: TRPCUseQueries<TRouter>;\n useSuspenseQueries: TRPCUseSuspenseQueries<TRouter>;\n}\n\n/**\n * @internal\n */\nexport type CreateTRPCNext<\n TRouter extends AnyRouter,\n TSSRContext extends NextPageContext,\n> = ProtectedIntersection<\n CreateTRPCNextBase<TRouter, TSSRContext>,\n DecorateRouterRecord<\n TRouter['_def']['_config']['$types'],\n TRouter['_def']['record']\n >\n>;\n\nexport function createTRPCNext<\n TRouter extends AnyRouter,\n TSSRContext extends NextPageContext = NextPageContext,\n>(\n opts: WithTRPCNoSSROptions<TRouter> | WithTRPCSSROptions<TRouter>,\n): CreateTRPCNext<TRouter, TSSRContext> {\n const hooks = createRootHooks<TRouter, TSSRContext>(opts);\n\n // TODO: maybe set TSSRContext to `never` when using `WithTRPCNoSSROptions`\n const _withTRPC = withTRPC(opts);\n\n const proxy = createReactDecoration(hooks) as DecorateRouterRecord<\n TRouter['_def']['_config']['$types'],\n TRouter['_def']['record']\n >;\n\n return createFlatProxy((key) => {\n if (key === 'useContext' || key === 'useUtils') {\n return () => {\n const context = hooks.useUtils();\n // create a stable reference of the utils context\n return useMemo(() => {\n return (createReactQueryUtils as any)(context);\n }, [context]);\n };\n }\n\n if (key === 'useQueries') {\n return hooks.useQueries;\n }\n\n if (key === 'useSuspenseQueries') {\n return hooks.useSuspenseQueries;\n }\n\n if (key === 'withTRPC') {\n return _withTRPC;\n }\n\n return proxy[key];\n });\n}\n"],"mappings":";;;;;;;;;;AAyFA,SAAgB,SAGdA,MAAmE;CACnE,MAAM,EAAE,QAAQ,iBAAiB,GAAG;CACpC,MAAM,cAAc,eACjB,KAAsC,YACxC;AAGD,QAAO,CAACC,cAAmE;;EACzE,MAAM,OAAO,gBAAsC,KAAK;EAExD,MAAM,WAAW,CACfC,UAGG;;GACH,MAAM,CAAC,aAAa,GAAG,SAAS,MAAM;AACpC,QAAI,MAAM,KACR,QAAO,MAAM;IAGf,MAAM,SAAS,gBAAgB,CAAE,EAAC;IAClC,MAAMC,gBAAc,eAAe,OAAO;IAC1C,MAAMC,eAAa,KAAK,aAAa,OAAO;AAE5C,WAAO;KACL,gBAAgB,OAAO;KACvB;KACA;KACA,UAAU,KAAK,MAAO,aAAwB;KAC9C,YAAY;IACb;GACF,EAAC;GAEF,MAAM,EAAE,aAAa,YAAY,UAAU,YAAY,GAAG;GAG1D,MAAM,gCAAY,MAAM,+EAAW;GAEnC,MAAMC,gBAA6C,MAAM,QAAQ,MAAM;AACrE,SAAK,UACH,QAAO;AAGT,WAAO,YAAY,MAAM,YAAY,UAAU;GAChD,GAAE,CAAC,SAAU,EAAC;AAEf,0BACE,IAAC,KAAK;IACJ,mCAAiB,aAAqB,2EAAkB;IACxD,QAAQ;IACK;IACH;IACE;8BAEZ,IAAC;KAAoB,QAAQ;+BAC3B,IAAC;MAAkB,OAAO;gCACxB,IAAC,iDAAc,OAAS;OACN;MACA;KACR;EAEnB;AAED,MAAI,KAAK,IACP,MAAK,WAAW;GACd,QAAQ;GACR;GACA;EACD,EAAC;WACO,UAAU,gBAGnB,UAAS,kBAAkB,OAAOC,iBAAiC;;GAEjE,MAAM,UAAU,aAAa;GAG7B,IAAIC,YAA2B,CAAE;GAEjC,MAAM,gBAAgB,MAAM,UAAU,gBACpC,aACD;GACD,MAAM,oBAAoB,iCACrB,cAAc,kFAAa,CAAE,IAC9B;AAEJ,uFACK,oBACA;GAEL,MAAM,kBAAkB,CAACC,UACvB,QAAQ,EAAE,WAAW,MAAO,IAAG;AAEjC,UAAO,gBAAgB,UAAU;EAClC;EAGH,MAAM,+CAAc,UAAU,oFAAe,UAAU,2CAAQ;AAC/D,WAAS,eAAe,WAAW,YAAY;AAE/C,SAAO;CACR;AACF;;;;ACvID,SAAgB,eAIdC,MACsC;CACtC,MAAM,QAAQ,gBAAsC,KAAK;CAGzD,MAAM,YAAY,SAAS,KAAK;CAEhC,MAAM,QAAQ,sBAAsB,MAAM;AAK1C,QAAO,gBAAgB,CAAC,QAAQ;AAC9B,MAAI,QAAQ,gBAAgB,QAAQ,WAClC,QAAO,MAAM;GACX,MAAM,UAAU,MAAM,UAAU;AAEhC,UAAO,QAAQ,MAAM;AACnB,WAAO,AAAC,sBAA8B,QAAQ;GAC/C,GAAE,CAAC,OAAQ,EAAC;EACd;AAGH,MAAI,QAAQ,aACV,QAAO,MAAM;AAGf,MAAI,QAAQ,qBACV,QAAO,MAAM;AAGf,MAAI,QAAQ,WACV,QAAO;AAGT,SAAO,MAAM;CACd,EAAC;AACH"}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../src/withTRPC.tsx","../src/createTRPCNext.tsx"],"sourcesContent":["/**\n * Heavily based on urql's ssr\n * https://github.com/FormidableLabs/urql/blob/main/packages/next-urql/src/with-urql-client.ts\n */\nimport type { DehydratedState, QueryClient } from '@tanstack/react-query';\nimport { HydrationBoundary, QueryClientProvider } from '@tanstack/react-query';\nimport type {\n CreateTRPCClientOptions,\n TRPCClient,\n TRPCClientError,\n TRPCUntypedClient,\n} from '@trpc/client';\nimport type { CoercedTransformerParameters } from '@trpc/client/unstable-internals';\nimport {\n getTransformer,\n type TransformerOptions,\n} from '@trpc/client/unstable-internals';\nimport type {\n CreateTRPCReactOptions,\n CreateTRPCReactQueryClientConfig,\n} from '@trpc/react-query/shared';\nimport { createRootHooks, getQueryClient } from '@trpc/react-query/shared';\nimport type {\n AnyRouter,\n Dict,\n inferClientTypes,\n ResponseMeta,\n} from '@trpc/server/unstable-core-do-not-import';\nimport type {\n AppContextType,\n AppPropsType,\n NextComponentType,\n NextPageContext,\n} from 'next/dist/shared/lib/utils';\nimport type { NextRouter } from 'next/router';\nimport React, { useState } from 'react';\n\nexport type WithTRPCConfig<TRouter extends AnyRouter> =\n CreateTRPCClientOptions<TRouter> &\n CreateTRPCReactQueryClientConfig & {\n abortOnUnmount?: boolean;\n };\n\ntype WithTRPCOptions<TRouter extends AnyRouter> =\n CreateTRPCReactOptions<TRouter> & {\n config: (info: { ctx?: NextPageContext }) => WithTRPCConfig<TRouter>;\n } & TransformerOptions<inferClientTypes<TRouter>>;\n\nexport type TRPCPrepassHelper = (opts: {\n parent: WithTRPCSSROptions<AnyRouter>;\n WithTRPC: NextComponentType<any, any, any>;\n AppOrPage: NextComponentType<any, any, any>;\n}) => void;\nexport type WithTRPCSSROptions<TRouter extends AnyRouter> =\n WithTRPCOptions<TRouter> & {\n /**\n * If you enable this, you also need to add a `ssrPrepass`-prop\n * @see https://trpc.io/docs/client/nextjs/ssr\n */\n ssr:\n true | ((opts: { ctx: NextPageContext }) => boolean | Promise<boolean>);\n responseMeta?: (opts: {\n ctx: NextPageContext;\n clientErrors: TRPCClientError<TRouter>[];\n }) => ResponseMeta;\n /**\n * use `import { ssrPrepass } from '@trpc/next/ssrPrepass'`\n * @see https://trpc.io/docs/client/nextjs/ssr\n */\n ssrPrepass: TRPCPrepassHelper;\n };\n\nexport type WithTRPCNoSSROptions<TRouter extends AnyRouter> =\n WithTRPCOptions<TRouter> & {\n ssr?: false;\n };\n\nexport type TRPCPrepassProps<\n TRouter extends AnyRouter,\n TSSRContext extends NextPageContext = NextPageContext,\n> = {\n config: WithTRPCConfig<TRouter>;\n queryClient: QueryClient;\n trpcClient: TRPCUntypedClient<TRouter> | TRPCClient<TRouter>;\n ssrState: 'prepass';\n ssrContext: TSSRContext;\n};\n\nexport function withTRPC<\n TRouter extends AnyRouter,\n TSSRContext extends NextPageContext = NextPageContext,\n>(opts: WithTRPCNoSSROptions<TRouter> | WithTRPCSSROptions<TRouter>) {\n const { config: getClientConfig } = opts;\n const transformer = getTransformer(\n (opts as CoercedTransformerParameters).transformer,\n );\n\n type $PrepassProps = TRPCPrepassProps<TRouter, TSSRContext>;\n return (AppOrPage: NextComponentType<any, any, any>): NextComponentType => {\n const trpc = createRootHooks<TRouter, TSSRContext>(opts);\n\n const WithTRPC = (\n props: AppPropsType<NextRouter, any> & {\n trpc?: $PrepassProps;\n },\n ) => {\n const [prepassProps] = useState(() => {\n if (props.trpc) {\n return props.trpc;\n }\n\n const config = getClientConfig({});\n const queryClient = getQueryClient(config);\n const trpcClient = trpc.createClient(config);\n\n return {\n abortOnUnmount: config.abortOnUnmount,\n queryClient,\n trpcClient,\n ssrState: opts.ssr ? ('mounting' as const) : (false as const),\n ssrContext: null,\n };\n });\n\n const { queryClient, trpcClient, ssrState, ssrContext } = prepassProps;\n\n // allow normal components to be wrapped, not just app/pages\n const trpcState = props.pageProps?.trpcState;\n\n const hydratedState: DehydratedState | undefined = React.useMemo(() => {\n if (!trpcState) {\n return trpcState;\n }\n\n return transformer.input.deserialize(trpcState);\n }, [trpcState]);\n\n return (\n <trpc.Provider\n abortOnUnmount={(prepassProps as any).abortOnUnmount ?? false}\n client={trpcClient}\n queryClient={queryClient}\n ssrState={ssrState}\n ssrContext={ssrContext}\n >\n <QueryClientProvider client={queryClient}>\n <HydrationBoundary state={hydratedState}>\n <AppOrPage {...props} />\n </HydrationBoundary>\n </QueryClientProvider>\n </trpc.Provider>\n );\n };\n\n if (opts.ssr) {\n opts.ssrPrepass({\n parent: opts,\n AppOrPage,\n WithTRPC,\n });\n } else if (AppOrPage.getInitialProps) {\n // Allow combining `getServerSideProps` and `getInitialProps`\n\n WithTRPC.getInitialProps = async (appOrPageCtx: AppContextType) => {\n // Determine if we are wrapping an App component or a Page component.\n const isApp = !!appOrPageCtx.Component;\n\n // Run the wrapped component's getInitialProps function.\n let pageProps: Dict<unknown> = {};\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const originalProps = await AppOrPage.getInitialProps!(\n appOrPageCtx as any,\n );\n const originalPageProps = isApp\n ? (originalProps.pageProps ?? {})\n : originalProps;\n\n pageProps = {\n ...originalPageProps,\n ...pageProps,\n };\n const getAppTreeProps = (props: Dict<unknown>) =>\n isApp ? { pageProps: props } : props;\n\n return getAppTreeProps(pageProps);\n };\n }\n\n const displayName = AppOrPage.displayName ?? AppOrPage.name ?? 'Component';\n WithTRPC.displayName = `withTRPC(${displayName})`;\n\n return WithTRPC as any;\n };\n}\n","/* istanbul ignore file -- @preserve */\n// We're testing this through E2E-testing\nimport type {\n CreateReactUtils,\n DecorateRouterRecord,\n TRPCUseQueries,\n TRPCUseSuspenseQueries,\n} from '@trpc/react-query/shared';\nimport {\n createReactDecoration,\n createReactQueryUtils,\n createRootHooks,\n} from '@trpc/react-query/shared';\nimport type {\n AnyRouter,\n ProtectedIntersection,\n} from '@trpc/server/unstable-core-do-not-import';\nimport { createFlatProxy } from '@trpc/server/unstable-core-do-not-import';\nimport type { NextPageContext } from 'next/types';\nimport { useMemo } from 'react';\nimport type { WithTRPCNoSSROptions, WithTRPCSSROptions } from './withTRPC';\nimport { withTRPC } from './withTRPC';\n\n/**\n * @internal\n */\nexport interface CreateTRPCNextBase<\n TRouter extends AnyRouter,\n TSSRContext extends NextPageContext,\n> {\n /**\n * @deprecated renamed to `useUtils` and will be removed in a future tRPC version\n *\n * @see https://trpc.io/docs/v11/client/react/useUtils\n */\n useContext(): CreateReactUtils<TRouter, TSSRContext>;\n /**\n * @see https://trpc.io/docs/v11/client/react/useUtils\n */\n useUtils(): CreateReactUtils<TRouter, TSSRContext>;\n withTRPC: ReturnType<typeof withTRPC<TRouter, TSSRContext>>;\n useQueries: TRPCUseQueries<TRouter>;\n useSuspenseQueries: TRPCUseSuspenseQueries<TRouter>;\n}\n\n/**\n * @internal\n */\nexport type CreateTRPCNext<\n TRouter extends AnyRouter,\n TSSRContext extends NextPageContext,\n> = ProtectedIntersection<\n CreateTRPCNextBase<TRouter, TSSRContext>,\n DecorateRouterRecord<\n TRouter['_def']['_config']['$types'],\n TRouter['_def']['record']\n >\n>;\n\nexport function createTRPCNext<\n TRouter extends AnyRouter,\n TSSRContext extends NextPageContext = NextPageContext,\n>(\n opts: WithTRPCNoSSROptions<TRouter> | WithTRPCSSROptions<TRouter>,\n): CreateTRPCNext<TRouter, TSSRContext> {\n const hooks = createRootHooks<TRouter, TSSRContext>(opts);\n\n // TODO: maybe set TSSRContext to `never` when using `WithTRPCNoSSROptions`\n const _withTRPC = withTRPC(opts);\n\n const proxy = createReactDecoration(hooks) as DecorateRouterRecord<\n TRouter['_def']['_config']['$types'],\n TRouter['_def']['record']\n >;\n\n return createFlatProxy((key) => {\n if (key === 'useContext' || key === 'useUtils') {\n return () => {\n const context = hooks.useUtils();\n // create a stable reference of the utils context\n return useMemo(() => {\n return (createReactQueryUtils as any)(context);\n }, [context]);\n };\n }\n\n if (key === 'useQueries') {\n return hooks.useQueries;\n }\n\n if (key === 'useSuspenseQueries') {\n return hooks.useSuspenseQueries;\n }\n\n if (key === 'withTRPC') {\n return _withTRPC;\n }\n\n return proxy[key];\n });\n}\n"],"mappings":";;;;;;;AAwFA,SAAgB,SAGd,MAAmE;CACnE,MAAM,EAAE,QAAQ,oBAAoB;CACpC,MAAM,cAAc,eACjB,KAAsC,WACzC;C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,eAAA,CAAA,GACK,iBAAA,GACA,SACL;GACA,MAAM,mBAAmB,UACvB,QAAQ,EAAE,WAAW,MAAM,IAAI;GAEjC,OAAO,gBAAgB,SAAS;EAClC;EAIF,SAAS,cAAc,aAAA,QAAA,wBADH,UAAU,iBAAA,QAAA,0BAAA,KAAA,IAAA,wBAAe,UAAU,UAAA,QAAA,SAAA,KAAA,IAAA,OAAQ,YAChB;EAE/C,OAAO;CACT;AACF;;;;ACtIA,SAAgB,eAId,MACsC;CACtC,MAAM,QAAQ,gBAAsC,IAAI;CAGxD,MAAM,YAAY,SAAS,IAAI;CAE/B,MAAM,QAAQ,sBAAsB,KAAK;CAKzC,OAAO,iBAAiB,QAAQ;EAC9B,IAAI,QAAQ,gBAAgB,QAAQ,YAClC,aAAa;GACX,MAAM,UAAU,MAAM,SAAS;GAE/B,OAAO,cAAc;IACnB,OAAQ,sBAA8B,OAAO;GAC/C,GAAG,CAAC,OAAO,CAAC;EACd;EAGF,IAAI,QAAQ,cACV,OAAO,MAAM;EAGf,IAAI,QAAQ,sBACV,OAAO,MAAM;EAGf,IAAI,QAAQ,YACV,OAAO;EAGT,OAAO,MAAM;CACf,CAAC;AACH"}
@@ -0,0 +1,67 @@
1
+ //#region \0@oxc-project+runtime@0.149.0/helpers/esm/typeof.js
2
+ function _typeof(o) {
3
+ "@babel/helpers - typeof";
4
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
5
+ return typeof o;
6
+ } : function(o) {
7
+ return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
8
+ }, _typeof(o);
9
+ }
10
+ //#endregion
11
+ //#region \0@oxc-project+runtime@0.149.0/helpers/esm/toPrimitive.js
12
+ function toPrimitive(t, r) {
13
+ if ("object" != _typeof(t) || !t) return t;
14
+ var e = t[Symbol.toPrimitive];
15
+ if (void 0 !== e) {
16
+ var i = e.call(t, r || "default");
17
+ if ("object" != _typeof(i)) return i;
18
+ throw new TypeError("@@toPrimitive must return a primitive value.");
19
+ }
20
+ return ("string" === r ? String : Number)(t);
21
+ }
22
+ //#endregion
23
+ //#region \0@oxc-project+runtime@0.149.0/helpers/esm/toPropertyKey.js
24
+ function toPropertyKey(t) {
25
+ var i = toPrimitive(t, "string");
26
+ return "symbol" == _typeof(i) ? i : i + "";
27
+ }
28
+ //#endregion
29
+ //#region \0@oxc-project+runtime@0.149.0/helpers/esm/defineProperty.js
30
+ function _defineProperty(e, r, t) {
31
+ return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
32
+ value: t,
33
+ enumerable: !0,
34
+ configurable: !0,
35
+ writable: !0
36
+ }) : e[r] = t, e;
37
+ }
38
+ //#endregion
39
+ //#region \0@oxc-project+runtime@0.149.0/helpers/esm/objectSpread2.js
40
+ function ownKeys(e, r) {
41
+ var t = Object.keys(e);
42
+ if (Object.getOwnPropertySymbols) {
43
+ var o = Object.getOwnPropertySymbols(e);
44
+ r && (o = o.filter(function(r) {
45
+ return Object.getOwnPropertyDescriptor(e, r).enumerable;
46
+ })), t.push.apply(t, o);
47
+ }
48
+ return t;
49
+ }
50
+ function _objectSpread2(e) {
51
+ for (var r = 1; r < arguments.length; r++) {
52
+ var t = null != arguments[r] ? arguments[r] : {};
53
+ r % 2 ? ownKeys(Object(t), !0).forEach(function(r) {
54
+ _defineProperty(e, r, t[r]);
55
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function(r) {
56
+ Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
57
+ });
58
+ }
59
+ return e;
60
+ }
61
+ //#endregion
62
+ Object.defineProperty(exports, "_objectSpread2", {
63
+ enumerable: true,
64
+ get: function() {
65
+ return _objectSpread2;
66
+ }
67
+ });
@@ -0,0 +1,62 @@
1
+ //#region \0@oxc-project+runtime@0.149.0/helpers/esm/typeof.js
2
+ function _typeof(o) {
3
+ "@babel/helpers - typeof";
4
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
5
+ return typeof o;
6
+ } : function(o) {
7
+ return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
8
+ }, _typeof(o);
9
+ }
10
+ //#endregion
11
+ //#region \0@oxc-project+runtime@0.149.0/helpers/esm/toPrimitive.js
12
+ function toPrimitive(t, r) {
13
+ if ("object" != _typeof(t) || !t) return t;
14
+ var e = t[Symbol.toPrimitive];
15
+ if (void 0 !== e) {
16
+ var i = e.call(t, r || "default");
17
+ if ("object" != _typeof(i)) return i;
18
+ throw new TypeError("@@toPrimitive must return a primitive value.");
19
+ }
20
+ return ("string" === r ? String : Number)(t);
21
+ }
22
+ //#endregion
23
+ //#region \0@oxc-project+runtime@0.149.0/helpers/esm/toPropertyKey.js
24
+ function toPropertyKey(t) {
25
+ var i = toPrimitive(t, "string");
26
+ return "symbol" == _typeof(i) ? i : i + "";
27
+ }
28
+ //#endregion
29
+ //#region \0@oxc-project+runtime@0.149.0/helpers/esm/defineProperty.js
30
+ function _defineProperty(e, r, t) {
31
+ return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
32
+ value: t,
33
+ enumerable: !0,
34
+ configurable: !0,
35
+ writable: !0
36
+ }) : e[r] = t, e;
37
+ }
38
+ //#endregion
39
+ //#region \0@oxc-project+runtime@0.149.0/helpers/esm/objectSpread2.js
40
+ function ownKeys(e, r) {
41
+ var t = Object.keys(e);
42
+ if (Object.getOwnPropertySymbols) {
43
+ var o = Object.getOwnPropertySymbols(e);
44
+ r && (o = o.filter(function(r) {
45
+ return Object.getOwnPropertyDescriptor(e, r).enumerable;
46
+ })), t.push.apply(t, o);
47
+ }
48
+ return t;
49
+ }
50
+ function _objectSpread2(e) {
51
+ for (var r = 1; r < arguments.length; r++) {
52
+ var t = null != arguments[r] ? arguments[r] : {};
53
+ r % 2 ? ownKeys(Object(t), !0).forEach(function(r) {
54
+ _defineProperty(e, r, t[r]);
55
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function(r) {
56
+ Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
57
+ });
58
+ }
59
+ return e;
60
+ }
61
+ //#endregion
62
+ export { _objectSpread2 as t };
@@ -1,19 +1,13 @@
1
- import { AnyClientTypes, AnyProcedure, AnyRootTypes, AnyRouter, ErrorHandlerOptions, MaybePromise, ProcedureType, ProtectedIntersection, RootConfig, RouterRecord, Simplify, TRPCResponse, inferClientTypes, inferProcedureInput, inferTransformedProcedureOutput } from "@trpc/server/unstable-core-do-not-import";
2
1
  import { CreateTRPCClientOptions, Resolver, TRPCClient, TRPCUntypedClient } from "@trpc/client";
2
+ import { AnyClientTypes, AnyProcedure, AnyRootTypes, AnyRouter, ErrorHandlerOptions, MaybePromise, ProcedureType, ProtectedIntersection, RootConfig, RouterRecord, Simplify, TRPCResponse, inferClientTypes, inferProcedureInput, inferTransformedProcedureOutput } from "@trpc/server/unstable-core-do-not-import";
3
3
  import { CreateContextCallback, inferProcedureOutput } from "@trpc/server";
4
-
5
4
  //#region src/app-dir/shared.d.ts
6
-
7
5
  /**
8
6
  * @internal
9
7
  */
10
8
  interface CreateTRPCNextAppRouterOptions<TRouter extends AnyRouter> {
11
9
  config: () => CreateTRPCClientOptions<TRouter>;
12
10
  }
13
- /**
14
- * @internal
15
- */
16
-
17
11
  /**
18
12
  * @internal
19
13
  */
@@ -51,12 +45,12 @@ type DecorateProcedureServer<TType extends ProcedureType, TDef extends ResolverD
51
45
  } : TType extends 'subscription' ? {
52
46
  subscribe: Resolver<TDef>;
53
47
  } : never;
54
- type NextAppDirDecorateRouterRecord<TRoot extends AnyRootTypes, TRecord extends RouterRecord> = { [TKey in keyof TRecord]: TRecord[TKey] extends infer $Value ? $Value extends AnyProcedure ? DecorateProcedureServer<$Value['_def']['type'], {
48
+ type NextAppDirDecorateRouterRecord<TRoot extends AnyRootTypes, TRecord extends RouterRecord> = { [TKey in keyof TRecord]: TRecord[TKey] extends (infer $Value) ? $Value extends AnyProcedure ? DecorateProcedureServer<$Value['_def']['type'], {
55
49
  input: inferProcedureInput<$Value>;
56
50
  output: inferTransformedProcedureOutput<TRoot, $Value>;
57
51
  errorShape: TRoot['errorShape'];
58
52
  transformer: TRoot['transformer'];
59
- }> : $Value extends RouterRecord ? NextAppDirDecorateRouterRecord<TRoot, $Value> : never : never };
53
+ }> : $Value extends RouterRecord ? NextAppDirDecorateRouterRecord<TRoot, $Value> : never : never; };
60
54
  //#endregion
61
55
  //#region src/app-dir/server.d.ts
62
56
  declare function experimental_createTRPCNextAppDirServer<TRouter extends AnyRouter>(opts: CreateTRPCNextAppRouterOptions<TRouter>): NextAppDirDecorateRouterRecord<TRouter["_def"]["_config"]["$types"], TRouter["_def"]["record"]>;
@@ -83,8 +77,6 @@ declare function experimental_createServerActionHandler<TInstance extends {
83
77
  rethrowNextErrors?: boolean;
84
78
  }): <TProc extends AnyProcedure>(proc: TProc) => TRPCActionHandler<Simplify<inferActionDef<inferClientTypes<TInstance>, TProc>>>;
85
79
  declare function experimental_revalidateEndpoint(req: Request): Promise<Response>;
86
- //# sourceMappingURL=server.d.ts.map
87
-
88
80
  //#endregion
89
- export { ActionHandlerDef, CreateTRPCNextAppRouterOptions, TRPCActionHandler, experimental_createServerActionHandler, experimental_createTRPCNextAppDirServer, experimental_revalidateEndpoint };
90
- //# sourceMappingURL=server.d-C5p0ZwB7.d.mts.map
81
+ export { ActionHandlerDef as a, experimental_revalidateEndpoint as i, experimental_createServerActionHandler as n, CreateTRPCNextAppRouterOptions as o, experimental_createTRPCNextAppDirServer as r, TRPCActionHandler as t };
82
+ //# sourceMappingURL=server-BSCiwefJ.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server-BSCiwefJ.d.cts","names":[],"sources":["../src/app-dir/shared.ts","../src/app-dir/types.ts","../src/app-dir/server.ts"],"mappings":";;;;;;;UA8FiB,+BAA+B,gBAAgB;EAC9D,cAAc,wBAAwB;;;;;UAuBvB;EACf;EACA;EACA;;;;;KAOU,eACV,cAAc,gBACd,cAAc;EAEd,OAAO,oBAAoB;EAC3B,QAAQ,qBAAqB;EAC7B,YAAY;;;;KC5HT;EACH;EACA;EACA;EACA;;KAGU,wBACV,cAAc,eACd,aAAa,eACX;EAEE,OAAO,SAAS;EAChB,aACE,QAAQ,kBACL;IACD;IAAoB;;IAAoB;;IAG9C;EAEI,QAAQ,SAAS;IAEnB;EAEI,WAAW,SAAS;;KAIlB,+BACV,cAAc,cACd,gBAAgB,mBAEf,cAAc,UAAU,QAAQ,qBAAoB,UACjD,eAAe,eACb,wBACE;EAEE,OAAO,oBAAoB;EAC3B,QAAQ,gCAAgC,OAAO;EAC/C,YAAY;EACZ,aAAa;KAGjB,eAAe,eACb,+BAA+B,OAAO;;;iBCfhC,wCACd,gBAAgB,WAChB,MAAM,+BAA+B,WAAQ,+BAAA,sCAAA;;;;KAkCnC,kBAAkB,aAAa,qBACzC,OAAO,WAAW,kBACf,QAAQ,aAAa,gBAAgB;iBAE1B,uCACd;EACE,SAAS,WAAW;GAGtB,GAAG,WACH,MAAM,sBACJ,6CACM,aAAa;;;;;EAMnB;;;;EAIA,WACE,MAAM,oBAAoB;;;;;EAO5B;KAaiC,cAAc,cAAY,MACrD,UACL,kBACD,SAAS,eAAe,iBAAiB,YAAY;iBA4EnC,gCAAgC,KAAK,UAAO,QAAA"}
@@ -1,19 +1,13 @@
1
- import { CreateTRPCClientOptions, Resolver, TRPCClient, TRPCUntypedClient } from "@trpc/client";
2
1
  import { AnyClientTypes, AnyProcedure, AnyRootTypes, AnyRouter, ErrorHandlerOptions, MaybePromise, ProcedureType, ProtectedIntersection, RootConfig, RouterRecord, Simplify, TRPCResponse, inferClientTypes, inferProcedureInput, inferTransformedProcedureOutput } from "@trpc/server/unstable-core-do-not-import";
2
+ import { CreateTRPCClientOptions, Resolver, TRPCClient, TRPCUntypedClient } from "@trpc/client";
3
3
  import { CreateContextCallback, inferProcedureOutput } from "@trpc/server";
4
-
5
4
  //#region src/app-dir/shared.d.ts
6
-
7
5
  /**
8
6
  * @internal
9
7
  */
10
8
  interface CreateTRPCNextAppRouterOptions<TRouter extends AnyRouter> {
11
9
  config: () => CreateTRPCClientOptions<TRouter>;
12
10
  }
13
- /**
14
- * @internal
15
- */
16
-
17
11
  /**
18
12
  * @internal
19
13
  */
@@ -51,12 +45,12 @@ type DecorateProcedureServer<TType extends ProcedureType, TDef extends ResolverD
51
45
  } : TType extends 'subscription' ? {
52
46
  subscribe: Resolver<TDef>;
53
47
  } : never;
54
- type NextAppDirDecorateRouterRecord<TRoot extends AnyRootTypes, TRecord extends RouterRecord> = { [TKey in keyof TRecord]: TRecord[TKey] extends infer $Value ? $Value extends AnyProcedure ? DecorateProcedureServer<$Value['_def']['type'], {
48
+ type NextAppDirDecorateRouterRecord<TRoot extends AnyRootTypes, TRecord extends RouterRecord> = { [TKey in keyof TRecord]: TRecord[TKey] extends (infer $Value) ? $Value extends AnyProcedure ? DecorateProcedureServer<$Value['_def']['type'], {
55
49
  input: inferProcedureInput<$Value>;
56
50
  output: inferTransformedProcedureOutput<TRoot, $Value>;
57
51
  errorShape: TRoot['errorShape'];
58
52
  transformer: TRoot['transformer'];
59
- }> : $Value extends RouterRecord ? NextAppDirDecorateRouterRecord<TRoot, $Value> : never : never };
53
+ }> : $Value extends RouterRecord ? NextAppDirDecorateRouterRecord<TRoot, $Value> : never : never; };
60
54
  //#endregion
61
55
  //#region src/app-dir/server.d.ts
62
56
  declare function experimental_createTRPCNextAppDirServer<TRouter extends AnyRouter>(opts: CreateTRPCNextAppRouterOptions<TRouter>): NextAppDirDecorateRouterRecord<TRouter["_def"]["_config"]["$types"], TRouter["_def"]["record"]>;
@@ -83,8 +77,6 @@ declare function experimental_createServerActionHandler<TInstance extends {
83
77
  rethrowNextErrors?: boolean;
84
78
  }): <TProc extends AnyProcedure>(proc: TProc) => TRPCActionHandler<Simplify<inferActionDef<inferClientTypes<TInstance>, TProc>>>;
85
79
  declare function experimental_revalidateEndpoint(req: Request): Promise<Response>;
86
- //# sourceMappingURL=server.d.ts.map
87
-
88
80
  //#endregion
89
- export { ActionHandlerDef, CreateTRPCNextAppRouterOptions, TRPCActionHandler, experimental_createServerActionHandler, experimental_createTRPCNextAppDirServer, experimental_revalidateEndpoint };
90
- //# sourceMappingURL=server.d-DLnegS7F.d.cts.map
81
+ export { ActionHandlerDef as a, experimental_revalidateEndpoint as i, experimental_createServerActionHandler as n, CreateTRPCNextAppRouterOptions as o, experimental_createTRPCNextAppDirServer as r, TRPCActionHandler as t };
82
+ //# sourceMappingURL=server-DQOX6CNV.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server-DQOX6CNV.d.mts","names":[],"sources":["../src/app-dir/shared.ts","../src/app-dir/types.ts","../src/app-dir/server.ts"],"mappings":";;;;;;;UA8FiB,+BAA+B,gBAAgB;EAC9D,cAAc,wBAAwB;;;;;UAuBvB;EACf;EACA;EACA;;;;;KAOU,eACV,cAAc,gBACd,cAAc;EAEd,OAAO,oBAAoB;EAC3B,QAAQ,qBAAqB;EAC7B,YAAY;;;;KC5HT;EACH;EACA;EACA;EACA;;KAGU,wBACV,cAAc,eACd,aAAa,eACX;EAEE,OAAO,SAAS;EAChB,aACE,QAAQ,kBACL;IACD;IAAoB;;IAAoB;;IAG9C;EAEI,QAAQ,SAAS;IAEnB;EAEI,WAAW,SAAS;;KAIlB,+BACV,cAAc,cACd,gBAAgB,mBAEf,cAAc,UAAU,QAAQ,qBAAoB,UACjD,eAAe,eACb,wBACE;EAEE,OAAO,oBAAoB;EAC3B,QAAQ,gCAAgC,OAAO;EAC/C,YAAY;EACZ,aAAa;KAGjB,eAAe,eACb,+BAA+B,OAAO;;;iBCfhC,wCACd,gBAAgB,WAChB,MAAM,+BAA+B,WAAQ,+BAAA,sCAAA;;;;KAkCnC,kBAAkB,aAAa,qBACzC,OAAO,WAAW,kBACf,QAAQ,aAAa,gBAAgB;iBAE1B,uCACd;EACE,SAAS,WAAW;GAGtB,GAAG,WACH,MAAM,sBACJ,6CACM,aAAa;;;;;EAMnB;;;;EAIA,WACE,MAAM,oBAAoB;;;;;EAO5B;KAaiC,cAAc,cAAY,MACrD,UACL,kBACD,SAAS,eAAe,iBAAiB,YAAY;iBA4EnC,gCAAgC,KAAK,UAAO,QAAA"}
@@ -0,0 +1,26 @@
1
+ require("@trpc/server/unstable-core-do-not-import");
2
+ require("@trpc/client");
3
+ //#region src/app-dir/shared.ts
4
+ /**
5
+ * @internal
6
+ */
7
+ function generateCacheTag(procedurePath, input) {
8
+ return input ? `${procedurePath}?input=${JSON.stringify(input)}` : procedurePath;
9
+ }
10
+ function isFormData(value) {
11
+ if (typeof FormData === "undefined") return false;
12
+ return value instanceof FormData;
13
+ }
14
+ //#endregion
15
+ Object.defineProperty(exports, "generateCacheTag", {
16
+ enumerable: true,
17
+ get: function() {
18
+ return generateCacheTag;
19
+ }
20
+ });
21
+ Object.defineProperty(exports, "isFormData", {
22
+ enumerable: true,
23
+ get: function() {
24
+ return isFormData;
25
+ }
26
+ });
@@ -1,6 +1,5 @@
1
- import { createRecursiveProxy } from "@trpc/server/unstable-core-do-not-import";
2
- import { TRPCUntypedClient } from "@trpc/client";
3
-
1
+ import "@trpc/server/unstable-core-do-not-import";
2
+ import "@trpc/client";
4
3
  //#region src/app-dir/shared.ts
5
4
  /**
6
5
  * @internal
@@ -12,7 +11,7 @@ function isFormData(value) {
12
11
  if (typeof FormData === "undefined") return false;
13
12
  return value instanceof FormData;
14
13
  }
15
-
16
14
  //#endregion
17
- export { generateCacheTag, isFormData };
18
- //# sourceMappingURL=shared-Bco66qhk.mjs.map
15
+ export { isFormData as n, generateCacheTag as t };
16
+
17
+ //# sourceMappingURL=shared-DJ-gGeuI.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shared-DJ-gGeuI.mjs","names":[],"sources":["../src/app-dir/shared.ts"],"sourcesContent":["import type {\n CreateTRPCClientOptions,\n Resolver,\n TRPCClient,\n} from '@trpc/client';\nimport { getUntypedClient, TRPCUntypedClient } from '@trpc/client';\nimport type { inferProcedureOutput } from '@trpc/server';\nimport type {\n AnyClientTypes,\n AnyProcedure,\n AnyQueryProcedure,\n AnyRootTypes,\n AnyRouter,\n inferProcedureInput,\n inferTransformedProcedureOutput,\n ProtectedIntersection,\n RouterRecord,\n} from '@trpc/server/unstable-core-do-not-import';\nimport { createRecursiveProxy } from '@trpc/server/unstable-core-do-not-import';\n\n/**\n * @internal\n */\nexport type UseProcedureRecord<\n TRoot extends AnyRootTypes,\n TRecord extends RouterRecord,\n> = {\n [TKey in keyof TRecord]: TRecord[TKey] extends infer $Value\n ? $Value extends AnyQueryProcedure\n ? Resolver<{\n input: inferProcedureInput<$Value>;\n output: inferTransformedProcedureOutput<TRoot, $Value>;\n errorShape: TRoot['errorShape'];\n transformer: TRoot['transformer'];\n }>\n : $Value extends RouterRecord\n ? UseProcedureRecord<TRoot, $Value>\n : never\n : never;\n};\n\nexport function createUseProxy<TRouter extends AnyRouter>(\n client: TRPCUntypedClient<TRouter> | TRPCClient<TRouter>,\n) {\n const untypedClient: TRPCUntypedClient<TRouter> =\n client instanceof TRPCUntypedClient ? client : getUntypedClient(client);\n\n return createRecursiveProxy<\n UseProcedureRecord<\n TRouter['_def']['_config']['$types'],\n TRouter['_def']['record']\n >\n >((opts) => {\n const path = opts.path.join('.');\n\n return untypedClient.query(path, ...opts.args);\n });\n}\n\ntype NextAppRouterUse<TRouter extends AnyRouter> = {\n <TData extends Promise<unknown>[]>(\n cb: (\n t: UseProcedureRecord<\n TRouter['_def']['_config']['$types'],\n TRouter['_def']['record']\n >,\n ) => [...TData],\n ): {\n [TKey in keyof TData]: Awaited<TData[TKey]>;\n };\n <TData extends Promise<unknown>>(\n cb: (\n t: UseProcedureRecord<\n TRouter['_def']['_config']['$types'],\n TRouter['_def']['record']\n >,\n ) => TData,\n ): Awaited<TData>;\n};\ntype CreateTRPCNextAppRouterBase<TRouter extends AnyRouter> = {\n use: NextAppRouterUse<TRouter>;\n};\nexport type CreateTRPCNextAppRouter<TRouter extends AnyRouter> =\n ProtectedIntersection<\n CreateTRPCNextAppRouterBase<TRouter>,\n UseProcedureRecord<\n TRouter['_def']['_config']['$types'],\n TRouter['_def']['record']\n >\n >;\n\n/**\n * @internal\n */\nexport interface CreateTRPCNextAppRouterOptions<TRouter extends AnyRouter> {\n config: () => CreateTRPCClientOptions<TRouter>;\n}\n\n/**\n * @internal\n */\nexport function generateCacheTag(procedurePath: string, input: any) {\n return input\n ? `${procedurePath}?input=${JSON.stringify(input)}`\n : procedurePath;\n}\n\nexport function isFormData(value: unknown): value is FormData {\n if (typeof FormData === 'undefined') {\n // FormData is not supported\n return false;\n }\n return value instanceof FormData;\n}\n\n/**\n * @internal\n */\nexport interface ActionHandlerDef {\n input?: any;\n output?: any;\n errorShape: any;\n}\n\n// ts-prune-ignore-next\n/**\n * @internal\n */\nexport type inferActionDef<\n TRoot extends AnyClientTypes,\n TProc extends AnyProcedure,\n> = {\n input: inferProcedureInput<TProc>;\n output: inferProcedureOutput<TProc>;\n errorShape: TRoot['errorShape'];\n};\n"],"mappings":";;;;;;AAqGA,SAAgB,iBAAiB,eAAuB,OAAY;CAClE,OAAO,QACH,GAAG,cAAc,SAAS,KAAK,UAAU,KAAK,MAC9C;AACN;AAEA,SAAgB,WAAW,OAAmC;CAC5D,IAAI,OAAO,aAAa,aAEtB,OAAO;CAET,OAAO,iBAAiB;AAC1B"}
@@ -1,13 +1,11 @@
1
- const require_chunk = require('./chunk-DWy1uDak.cjs');
2
- const require_objectSpread2$1 = require('./objectSpread2-CGXFkI72.cjs');
3
- const __tanstack_react_query = require_chunk.__toESM(require("@tanstack/react-query"));
4
- const __trpc_client_unstable_internals = require_chunk.__toESM(require("@trpc/client/unstable-internals"));
5
- const __trpc_react_query_shared = require_chunk.__toESM(require("@trpc/react-query/shared"));
6
- const react = require_chunk.__toESM(require("react"));
7
- const __trpc_client = require_chunk.__toESM(require("@trpc/client"));
8
-
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_objectSpread2 = require("./objectSpread2-C2ceYbQe.cjs");
3
+ let _tanstack_react_query = require("@tanstack/react-query");
4
+ let _trpc_client_unstable_internals = require("@trpc/client/unstable-internals");
5
+ let _trpc_react_query_shared = require("@trpc/react-query/shared");
6
+ let react = require("react");
7
+ let _trpc_client = require("@trpc/client");
9
8
  //#region src/ssrPrepass.ts
10
- var import_objectSpread2 = require_chunk.__toESM(require_objectSpread2$1.require_objectSpread2(), 1);
11
9
  function transformQueryOrMutationCacheErrors(result) {
12
10
  const error = result.state.error;
13
11
  if (error instanceof Error && error.name === "TRPCClientError") {
@@ -16,13 +14,13 @@ function transformQueryOrMutationCacheErrors(result) {
16
14
  data: error.data,
17
15
  shape: error.shape
18
16
  };
19
- return (0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, result), {}, { state: (0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, result.state), {}, { error: newError }) });
17
+ return require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, result), {}, { state: require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, result.state), {}, { error: newError }) });
20
18
  }
21
19
  return result;
22
20
  }
23
21
  const ssrPrepass = (opts) => {
24
22
  const { parent, WithTRPC, AppOrPage } = opts;
25
- const transformer = (0, __trpc_client_unstable_internals.getTransformer)(parent.transformer);
23
+ const transformer = (0, _trpc_client_unstable_internals.getTransformer)(parent.transformer);
26
24
  WithTRPC.getInitialProps = async (appOrPageCtx) => {
27
25
  var _parent$responseMeta, _parent$responseMeta2, _meta$headers;
28
26
  const shouldSsr = async () => {
@@ -43,23 +41,22 @@ const ssrPrepass = (opts) => {
43
41
  var _originalProps$pagePr;
44
42
  const originalProps = await AppOrPage.getInitialProps(appOrPageCtx);
45
43
  const originalPageProps = isApp ? (_originalProps$pagePr = originalProps.pageProps) !== null && _originalProps$pagePr !== void 0 ? _originalProps$pagePr : {} : originalProps;
46
- pageProps = (0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, originalPageProps), pageProps);
44
+ pageProps = require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, originalPageProps), pageProps);
47
45
  }
48
46
  const getAppTreeProps = (props) => isApp ? { pageProps: props } : props;
49
47
  if (typeof window !== "undefined" || !ssrEnabled) return getAppTreeProps(pageProps);
50
48
  const config = parent.config({ ctx });
51
- const trpcClient = (0, __trpc_client.createTRPCUntypedClient)(config);
52
- const queryClient = (0, __trpc_react_query_shared.getQueryClient)(config);
53
- const trpcProp = {
54
- config,
55
- trpcClient,
56
- queryClient,
57
- ssrState: "prepass",
58
- ssrContext: ctx
59
- };
49
+ const trpcClient = (0, _trpc_client.createTRPCUntypedClient)(config);
50
+ const queryClient = (0, _trpc_react_query_shared.getQueryClient)(config);
60
51
  const prepassProps = {
61
52
  pageProps,
62
- trpc: trpcProp
53
+ trpc: {
54
+ config,
55
+ trpcClient,
56
+ queryClient,
57
+ ssrState: "prepass",
58
+ ssrContext: ctx
59
+ }
63
60
  };
64
61
  const reactDomServer = await import("react-dom/server");
65
62
  while (true) {
@@ -74,11 +71,10 @@ const ssrPrepass = (opts) => {
74
71
  });
75
72
  });
76
73
  }
77
- const dehydratedCache = (0, __tanstack_react_query.dehydrate)(queryClient, { shouldDehydrateQuery(query) {
78
- const isExcludedFromSSr = query.state.fetchStatus === "idle" && query.state.status === "pending";
79
- return !isExcludedFromSSr;
74
+ const dehydratedCache = (0, _tanstack_react_query.dehydrate)(queryClient, { shouldDehydrateQuery(query) {
75
+ return !(query.state.fetchStatus === "idle" && query.state.status === "pending");
80
76
  } });
81
- const dehydratedCacheWithErrors = (0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, dehydratedCache), {}, {
77
+ const dehydratedCacheWithErrors = require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, dehydratedCache), {}, {
82
78
  queries: dehydratedCache.queries.map(transformQueryOrMutationCacheErrors),
83
79
  mutations: dehydratedCache.mutations.map(transformQueryOrMutationCacheErrors)
84
80
  });
@@ -96,6 +92,5 @@ const ssrPrepass = (opts) => {
96
92
  return appTreeProps;
97
93
  };
98
94
  };
99
-
100
95
  //#endregion
101
- exports.ssrPrepass = ssrPrepass;
96
+ exports.ssrPrepass = ssrPrepass;
@@ -1,9 +1,5 @@
1
- import { TRPCPrepassHelper } from "./withTRPC.d-DctYN4Yz.cjs";
2
-
1
+ import { t as TRPCPrepassHelper } from "./withTRPC-DywCxFfq.cjs";
3
2
  //#region src/ssrPrepass.d.ts
4
- declare const ssrPrepass: TRPCPrepassHelper;
5
- //# sourceMappingURL=ssrPrepass.d.ts.map
6
-
3
+ export declare const ssrPrepass: TRPCPrepassHelper;
7
4
  //#endregion
8
- export { ssrPrepass };
9
5
  //# sourceMappingURL=ssrPrepass.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ssrPrepass.d.cts","names":[],"sources":["../src/ssrPrepass.ts"],"sourcesContent":[],"mappings":";;;cA8Ca,YAAY"}
1
+ {"version":3,"file":"ssrPrepass.d.cts","names":[],"sources":["../src/ssrPrepass.ts"],"mappings":";;qBA6Ca,YAAY"}
@@ -1,9 +1,5 @@
1
- import { TRPCPrepassHelper } from "./withTRPC.d-B3f3A0sf.mjs";
2
-
1
+ import { t as TRPCPrepassHelper } from "./withTRPC-BchtyodQ.mjs";
3
2
  //#region src/ssrPrepass.d.ts
4
- declare const ssrPrepass: TRPCPrepassHelper;
5
- //# sourceMappingURL=ssrPrepass.d.ts.map
6
-
3
+ export declare const ssrPrepass: TRPCPrepassHelper;
7
4
  //#endregion
8
- export { ssrPrepass };
9
5
  //# sourceMappingURL=ssrPrepass.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ssrPrepass.d.mts","names":[],"sources":["../src/ssrPrepass.ts"],"sourcesContent":[],"mappings":";;;cA8Ca,YAAY"}
1
+ {"version":3,"file":"ssrPrepass.d.mts","names":[],"sources":["../src/ssrPrepass.ts"],"mappings":";;qBA6Ca,YAAY"}
@@ -1,12 +1,10 @@
1
- import { __toESM, require_objectSpread2 } from "./objectSpread2-3tHFGdJc.mjs";
1
+ import { t as _objectSpread2 } from "./objectSpread2-Dh4InpQf.mjs";
2
2
  import { dehydrate } from "@tanstack/react-query";
3
3
  import { getTransformer } from "@trpc/client/unstable-internals";
4
4
  import { getQueryClient } from "@trpc/react-query/shared";
5
5
  import { createElement } from "react";
6
6
  import { createTRPCUntypedClient } from "@trpc/client";
7
-
8
7
  //#region src/ssrPrepass.ts
9
- var import_objectSpread2 = __toESM(require_objectSpread2(), 1);
10
8
  function transformQueryOrMutationCacheErrors(result) {
11
9
  const error = result.state.error;
12
10
  if (error instanceof Error && error.name === "TRPCClientError") {
@@ -15,7 +13,7 @@ function transformQueryOrMutationCacheErrors(result) {
15
13
  data: error.data,
16
14
  shape: error.shape
17
15
  };
18
- return (0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, result), {}, { state: (0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, result.state), {}, { error: newError }) });
16
+ return _objectSpread2(_objectSpread2({}, result), {}, { state: _objectSpread2(_objectSpread2({}, result.state), {}, { error: newError }) });
19
17
  }
20
18
  return result;
21
19
  }
@@ -42,23 +40,22 @@ const ssrPrepass = (opts) => {
42
40
  var _originalProps$pagePr;
43
41
  const originalProps = await AppOrPage.getInitialProps(appOrPageCtx);
44
42
  const originalPageProps = isApp ? (_originalProps$pagePr = originalProps.pageProps) !== null && _originalProps$pagePr !== void 0 ? _originalProps$pagePr : {} : originalProps;
45
- pageProps = (0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, originalPageProps), pageProps);
43
+ pageProps = _objectSpread2(_objectSpread2({}, originalPageProps), pageProps);
46
44
  }
47
45
  const getAppTreeProps = (props) => isApp ? { pageProps: props } : props;
48
46
  if (typeof window !== "undefined" || !ssrEnabled) return getAppTreeProps(pageProps);
49
47
  const config = parent.config({ ctx });
50
48
  const trpcClient = createTRPCUntypedClient(config);
51
49
  const queryClient = getQueryClient(config);
52
- const trpcProp = {
53
- config,
54
- trpcClient,
55
- queryClient,
56
- ssrState: "prepass",
57
- ssrContext: ctx
58
- };
59
50
  const prepassProps = {
60
51
  pageProps,
61
- trpc: trpcProp
52
+ trpc: {
53
+ config,
54
+ trpcClient,
55
+ queryClient,
56
+ ssrState: "prepass",
57
+ ssrContext: ctx
58
+ }
62
59
  };
63
60
  const reactDomServer = await import("react-dom/server");
64
61
  while (true) {
@@ -74,10 +71,9 @@ const ssrPrepass = (opts) => {
74
71
  });
75
72
  }
76
73
  const dehydratedCache = dehydrate(queryClient, { shouldDehydrateQuery(query) {
77
- const isExcludedFromSSr = query.state.fetchStatus === "idle" && query.state.status === "pending";
78
- return !isExcludedFromSSr;
74
+ return !(query.state.fetchStatus === "idle" && query.state.status === "pending");
79
75
  } });
80
- const dehydratedCacheWithErrors = (0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, dehydratedCache), {}, {
76
+ const dehydratedCacheWithErrors = _objectSpread2(_objectSpread2({}, dehydratedCache), {}, {
81
77
  queries: dehydratedCache.queries.map(transformQueryOrMutationCacheErrors),
82
78
  mutations: dehydratedCache.mutations.map(transformQueryOrMutationCacheErrors)
83
79
  });
@@ -95,7 +91,7 @@ const ssrPrepass = (opts) => {
95
91
  return appTreeProps;
96
92
  };
97
93
  };
98
-
99
94
  //#endregion
100
95
  export { ssrPrepass };
96
+
101
97
  //# sourceMappingURL=ssrPrepass.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"ssrPrepass.mjs","names":["result: TState","newError: TRPCClientErrorLike<any>","ssrPrepass: TRPCPrepassHelper","appOrPageCtx: AppContextType","ctx: NextPageContext","pageProps: Dict<unknown>","props: Record<string, unknown>","trpcProp: $PrepassProps"],"sources":["../src/ssrPrepass.ts"],"sourcesContent":["/**\n * Heavily based on urql's ssr\n * https://github.com/FormidableLabs/urql/blob/main/packages/next-urql/src/with-urql-client.ts\n */\nimport type { DehydratedState } from '@tanstack/react-query';\nimport { dehydrate } from '@tanstack/react-query';\nimport { createTRPCUntypedClient } from '@trpc/client';\nimport type { TRPCClientError, TRPCClientErrorLike } from '@trpc/client';\nimport type { CoercedTransformerParameters } from '@trpc/client/unstable-internals';\nimport { getTransformer } from '@trpc/client/unstable-internals';\nimport { getQueryClient } from '@trpc/react-query/shared';\nimport type {\n AnyRouter,\n Dict,\n Maybe,\n} from '@trpc/server/unstable-core-do-not-import';\nimport type {\n AppContextType,\n NextPageContext,\n} from 'next/dist/shared/lib/utils';\nimport { createElement } from 'react';\nimport type { TRPCPrepassHelper, TRPCPrepassProps } from './withTRPC';\n\nfunction transformQueryOrMutationCacheErrors<\n TState extends\n | DehydratedState['mutations'][0]\n | DehydratedState['queries'][0],\n>(result: TState): TState {\n const error = result.state.error as Maybe<TRPCClientError<any>>;\n if (error instanceof Error && error.name === 'TRPCClientError') {\n const newError: TRPCClientErrorLike<any> = {\n message: error.message,\n data: error.data,\n shape: error.shape,\n };\n return {\n ...result,\n state: {\n ...result.state,\n error: newError,\n },\n };\n }\n return result;\n}\n\nexport const ssrPrepass: TRPCPrepassHelper = (opts) => {\n const { parent, WithTRPC, AppOrPage } = opts;\n type $PrepassProps = TRPCPrepassProps<AnyRouter, any>;\n\n const transformer = getTransformer(\n (parent as CoercedTransformerParameters).transformer,\n );\n WithTRPC.getInitialProps = async (appOrPageCtx: AppContextType) => {\n const shouldSsr = async () => {\n if (typeof window !== 'undefined') {\n return false;\n }\n if (typeof parent.ssr === 'function') {\n try {\n return await parent.ssr({ ctx: appOrPageCtx.ctx });\n } catch {\n return false;\n }\n }\n return parent.ssr;\n };\n const ssrEnabled = await shouldSsr();\n const AppTree = appOrPageCtx.AppTree;\n\n // Determine if we are wrapping an App component or a Page component.\n const isApp = !!appOrPageCtx.Component;\n const ctx: NextPageContext = isApp\n ? appOrPageCtx.ctx\n : (appOrPageCtx as any as NextPageContext);\n\n // Run the wrapped component's getInitialProps function.\n let pageProps: Dict<unknown> = {};\n if (AppOrPage.getInitialProps) {\n const originalProps = await AppOrPage.getInitialProps(\n appOrPageCtx as any,\n );\n const originalPageProps = isApp\n ? (originalProps.pageProps ?? {})\n : originalProps;\n\n pageProps = {\n ...originalPageProps,\n ...pageProps,\n };\n }\n const getAppTreeProps = (props: Record<string, unknown>) =>\n isApp ? { pageProps: props } : props;\n\n if (typeof window !== 'undefined' || !ssrEnabled) {\n return getAppTreeProps(pageProps);\n }\n\n const config = parent.config({ ctx });\n const trpcClient = createTRPCUntypedClient(config);\n const queryClient = getQueryClient(config);\n\n const trpcProp: $PrepassProps = {\n config,\n trpcClient,\n queryClient,\n ssrState: 'prepass',\n ssrContext: ctx,\n };\n const prepassProps = {\n pageProps,\n trpc: trpcProp,\n };\n\n const reactDomServer = await import('react-dom/server');\n\n // Run the prepass step on AppTree. This will run all trpc queries on the server.\n // multiple prepass ensures that we can do batching on the server\n while (true) {\n // render full tree\n reactDomServer.renderToString(createElement(AppTree, prepassProps));\n if (!queryClient.isFetching()) {\n // the render didn't cause the queryClient to fetch anything\n break;\n }\n\n // wait until the query cache has settled it's promises\n await new Promise<void>((resolve) => {\n const unsub = queryClient.getQueryCache().subscribe((event) => {\n if (event?.query.getObserversCount() === 0) {\n resolve();\n unsub();\n }\n });\n });\n }\n const dehydratedCache = dehydrate(queryClient, {\n shouldDehydrateQuery(query) {\n // filter out queries that are marked as trpc: { ssr: false } or are not enabled, but make sure errors are dehydrated\n const isExcludedFromSSr =\n query.state.fetchStatus === 'idle' &&\n query.state.status === 'pending';\n return !isExcludedFromSSr;\n },\n });\n // since error instances can't be serialized, let's make them into `TRPCClientErrorLike`-objects\n const dehydratedCacheWithErrors = {\n ...dehydratedCache,\n queries: dehydratedCache.queries.map(transformQueryOrMutationCacheErrors),\n mutations: dehydratedCache.mutations.map(\n transformQueryOrMutationCacheErrors,\n ),\n };\n\n // dehydrate query client's state and add it to the props\n pageProps['trpcState'] = transformer.input.serialize(\n dehydratedCacheWithErrors,\n );\n\n const appTreeProps = getAppTreeProps(pageProps);\n\n const meta =\n parent.responseMeta?.({\n ctx,\n clientErrors: [...dehydratedCache.queries, ...dehydratedCache.mutations]\n .map((v) => v.state.error)\n .flatMap((err) =>\n err instanceof Error && err.name === 'TRPCClientError'\n ? [err as TRPCClientError<AnyRouter>]\n : [],\n ),\n }) ?? {};\n\n for (const [key, value] of Object.entries(meta.headers ?? {})) {\n if (typeof value === 'string') {\n ctx.res?.setHeader(key, value);\n }\n }\n if (meta.status && ctx.res) {\n ctx.res.statusCode = meta.status;\n }\n\n return appTreeProps;\n };\n};\n"],"mappings":";;;;;;;;;AAuBA,SAAS,oCAIPA,QAAwB;CACxB,MAAM,QAAQ,OAAO,MAAM;AAC3B,KAAI,iBAAiB,SAAS,MAAM,SAAS,mBAAmB;EAC9D,MAAMC,WAAqC;GACzC,SAAS,MAAM;GACf,MAAM,MAAM;GACZ,OAAO,MAAM;EACd;AACD,iFACK,eACH,+EACK,OAAO,cACV,OAAO;CAGZ;AACD,QAAO;AACR;AAED,MAAaC,aAAgC,CAAC,SAAS;CACrD,MAAM,EAAE,QAAQ,UAAU,WAAW,GAAG;CAGxC,MAAM,cAAc,eACjB,OAAwC,YAC1C;AACD,UAAS,kBAAkB,OAAOC,iBAAiC;;EACjE,MAAM,YAAY,YAAY;AAC5B,cAAW,WAAW,YACpB,QAAO;AAET,cAAW,OAAO,QAAQ,WACxB,KAAI;AACF,WAAO,MAAM,OAAO,IAAI,EAAE,KAAK,aAAa,IAAK,EAAC;GACnD,kBAAO;AACN,WAAO;GACR;AAEH,UAAO,OAAO;EACf;EACD,MAAM,aAAa,MAAM,WAAW;EACpC,MAAM,UAAU,aAAa;EAG7B,MAAM,UAAU,aAAa;EAC7B,MAAMC,MAAuB,QACzB,aAAa,MACZ;EAGL,IAAIC,YAA2B,CAAE;AACjC,MAAI,UAAU,iBAAiB;;GAC7B,MAAM,gBAAgB,MAAM,UAAU,gBACpC,aACD;GACD,MAAM,oBAAoB,iCACrB,cAAc,kFAAa,CAAE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EACJ,EAAC,uEAAI,CAAE;AAEV,OAAK,MAAM,CAAC,KAAK,MAAM,IAAI,OAAO,yBAAQ,KAAK,gEAAW,CAAE,EAAC,CAC3D,YAAW,UAAU,UAAU;;AAC7B,mBAAI,wCAAJ,SAAS,UAAU,KAAK,MAAM;EAC/B;AAEH,MAAI,KAAK,UAAU,IAAI,IACrB,KAAI,IAAI,aAAa,KAAK;AAG5B,SAAO;CACR;AACF"}
1
+ {"version":3,"file":"ssrPrepass.mjs","names":[],"sources":["../src/ssrPrepass.ts"],"sourcesContent":["/**\n * Heavily based on urql's ssr\n * https://github.com/FormidableLabs/urql/blob/main/packages/next-urql/src/with-urql-client.ts\n */\nimport type { DehydratedState } from '@tanstack/react-query';\nimport { dehydrate } from '@tanstack/react-query';\nimport { createTRPCUntypedClient } from '@trpc/client';\nimport type { TRPCClientError, TRPCClientErrorLike } from '@trpc/client';\nimport type { CoercedTransformerParameters } from '@trpc/client/unstable-internals';\nimport { getTransformer } from '@trpc/client/unstable-internals';\nimport { getQueryClient } from '@trpc/react-query/shared';\nimport type {\n AnyRouter,\n Dict,\n Maybe,\n} from '@trpc/server/unstable-core-do-not-import';\nimport type {\n AppContextType,\n NextPageContext,\n} from 'next/dist/shared/lib/utils';\nimport { createElement } from 'react';\nimport type { TRPCPrepassHelper, TRPCPrepassProps } from './withTRPC';\n\nfunction transformQueryOrMutationCacheErrors<\n TState extends\n DehydratedState['mutations'][0] | DehydratedState['queries'][0],\n>(result: TState): TState {\n const error = result.state.error as Maybe<TRPCClientError<any>>;\n if (error instanceof Error && error.name === 'TRPCClientError') {\n const newError: TRPCClientErrorLike<any> = {\n message: error.message,\n data: error.data,\n shape: error.shape,\n };\n return {\n ...result,\n state: {\n ...result.state,\n error: newError,\n },\n };\n }\n return result;\n}\n\nexport const ssrPrepass: TRPCPrepassHelper = (opts) => {\n const { parent, WithTRPC, AppOrPage } = opts;\n type $PrepassProps = TRPCPrepassProps<AnyRouter, any>;\n\n const transformer = getTransformer(\n (parent as CoercedTransformerParameters).transformer,\n );\n WithTRPC.getInitialProps = async (appOrPageCtx: AppContextType) => {\n const shouldSsr = async () => {\n if (typeof window !== 'undefined') {\n return false;\n }\n if (typeof parent.ssr === 'function') {\n try {\n return await parent.ssr({ ctx: appOrPageCtx.ctx });\n } catch {\n return false;\n }\n }\n return parent.ssr;\n };\n const ssrEnabled = await shouldSsr();\n const AppTree = appOrPageCtx.AppTree;\n\n // Determine if we are wrapping an App component or a Page component.\n const isApp = !!appOrPageCtx.Component;\n const ctx: NextPageContext = isApp\n ? appOrPageCtx.ctx\n : (appOrPageCtx as any as NextPageContext);\n\n // Run the wrapped component's getInitialProps function.\n let pageProps: Dict<unknown> = {};\n if (AppOrPage.getInitialProps) {\n const originalProps = await AppOrPage.getInitialProps(\n appOrPageCtx as any,\n );\n const originalPageProps = isApp\n ? (originalProps.pageProps ?? {})\n : originalProps;\n\n pageProps = {\n ...originalPageProps,\n ...pageProps,\n };\n }\n const getAppTreeProps = (props: Record<string, unknown>) =>\n isApp ? { pageProps: props } : props;\n\n if (typeof window !== 'undefined' || !ssrEnabled) {\n return getAppTreeProps(pageProps);\n }\n\n const config = parent.config({ ctx });\n const trpcClient = createTRPCUntypedClient(config);\n const queryClient = getQueryClient(config);\n\n const trpcProp: $PrepassProps = {\n config,\n trpcClient,\n queryClient,\n ssrState: 'prepass',\n ssrContext: ctx,\n };\n const prepassProps = {\n pageProps,\n trpc: trpcProp,\n };\n\n const reactDomServer = await import('react-dom/server');\n\n // Run the prepass step on AppTree. This will run all trpc queries on the server.\n // multiple prepass ensures that we can do batching on the server\n while (true) {\n // render full tree\n reactDomServer.renderToString(createElement(AppTree, prepassProps));\n if (!queryClient.isFetching()) {\n // the render didn't cause the queryClient to fetch anything\n break;\n }\n\n // wait until the query cache has settled it's promises\n await new Promise<void>((resolve) => {\n const unsub = queryClient.getQueryCache().subscribe((event) => {\n if (event?.query.getObserversCount() === 0) {\n resolve();\n unsub();\n }\n });\n });\n }\n const dehydratedCache = dehydrate(queryClient, {\n shouldDehydrateQuery(query) {\n // filter out queries that are marked as trpc: { ssr: false } or are not enabled, but make sure errors are dehydrated\n const isExcludedFromSSr =\n query.state.fetchStatus === 'idle' &&\n query.state.status === 'pending';\n return !isExcludedFromSSr;\n },\n });\n // since error instances can't be serialized, let's make them into `TRPCClientErrorLike`-objects\n const dehydratedCacheWithErrors = {\n ...dehydratedCache,\n queries: dehydratedCache.queries.map(transformQueryOrMutationCacheErrors),\n mutations: dehydratedCache.mutations.map(\n transformQueryOrMutationCacheErrors,\n ),\n };\n\n // dehydrate query client's state and add it to the props\n pageProps['trpcState'] = transformer.input.serialize(\n dehydratedCacheWithErrors,\n );\n\n const appTreeProps = getAppTreeProps(pageProps);\n\n const meta =\n parent.responseMeta?.({\n ctx,\n clientErrors: [...dehydratedCache.queries, ...dehydratedCache.mutations]\n .map((v) => v.state.error)\n .flatMap((err) =>\n err instanceof Error && err.name === 'TRPCClientError'\n ? [err as TRPCClientError<AnyRouter>]\n : [],\n ),\n }) ?? {};\n\n for (const [key, value] of Object.entries(meta.headers ?? {})) {\n if (typeof value === 'string') {\n ctx.res?.setHeader(key, value);\n }\n }\n if (meta.status && ctx.res) {\n ctx.res.statusCode = meta.status;\n }\n\n return appTreeProps;\n };\n};\n"],"mappings":";;;;;;;AAuBA,SAAS,oCAGP,QAAwB;CACxB,MAAM,QAAQ,OAAO,MAAM;CAC3B,IAAI,iBAAiB,SAAS,MAAM,SAAS,mBAAmB;EAC9D,MAAM,WAAqC;GACzC,SAAS,MAAM;GACf,MAAM,MAAM;GACZ,OAAO,MAAM;EACf;EACA,OAAA,eAAA,eAAA,CAAA,GACK,MAAA,GAAA,CAAA,GAAA,EACH,OAAA,eAAA,eAAA,CAAA,GACK,OAAO,KAAA,GAAA,CAAA,GAAA,EACV,OAAO,SAAA,CACT,EAAA,CACF;CACF;CACA,OAAO;AACT;AAEA,MAAa,cAAiC,SAAS;CACrD,MAAM,EAAE,QAAQ,UAAU,cAAc;CA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