@trpc/next 11.1.2 → 11.1.3-alpha-tmp-tsdown.23

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 (80) hide show
  1. package/app-dir/client/package.json +1 -0
  2. package/app-dir/links/nextCache/package.json +1 -0
  3. package/app-dir/links/nextHttp/package.json +1 -0
  4. package/app-dir/server/package.json +1 -0
  5. package/dist/_virtual/rolldown_runtime.js +30 -0
  6. package/dist/app-dir/client.d.mts +13 -0
  7. package/dist/app-dir/client.d.mts.map +1 -0
  8. package/dist/app-dir/client.d.ts +12 -5
  9. package/dist/app-dir/client.d.ts.map +1 -1
  10. package/dist/app-dir/client.js +25 -43
  11. package/dist/app-dir/client.mjs +24 -40
  12. package/dist/app-dir/client.mjs.map +1 -0
  13. package/dist/app-dir/create-action-hook.d.mts +47 -0
  14. package/dist/app-dir/create-action-hook.d.mts.map +1 -0
  15. package/dist/app-dir/create-action-hook.d.ts +33 -36
  16. package/dist/app-dir/create-action-hook.d.ts.map +1 -1
  17. package/dist/app-dir/create-action-hook.js +85 -101
  18. package/dist/app-dir/create-action-hook.mjs +84 -98
  19. package/dist/app-dir/create-action-hook.mjs.map +1 -0
  20. package/dist/app-dir/links/nextCache.d.mts +16 -0
  21. package/dist/app-dir/links/nextCache.d.mts.map +1 -0
  22. package/dist/app-dir/links/nextCache.d.ts +13 -9
  23. package/dist/app-dir/links/nextCache.d.ts.map +1 -1
  24. package/dist/app-dir/links/nextCache.js +44 -58
  25. package/dist/app-dir/links/nextCache.mjs +43 -55
  26. package/dist/app-dir/links/nextCache.mjs.map +1 -0
  27. package/dist/app-dir/links/nextHttp.d.mts +19 -0
  28. package/dist/app-dir/links/nextHttp.d.mts.map +1 -0
  29. package/dist/app-dir/links/nextHttp.d.ts +12 -8
  30. package/dist/app-dir/links/nextHttp.d.ts.map +1 -1
  31. package/dist/app-dir/links/nextHttp.js +31 -35
  32. package/dist/app-dir/links/nextHttp.mjs +30 -32
  33. package/dist/app-dir/links/nextHttp.mjs.map +1 -0
  34. package/dist/app-dir/server.d.mts +36 -0
  35. package/dist/app-dir/server.d.mts.map +1 -0
  36. package/dist/app-dir/server.d.ts +30 -24
  37. package/dist/app-dir/server.d.ts.map +1 -1
  38. package/dist/app-dir/server.js +86 -112
  39. package/dist/app-dir/server.mjs +85 -109
  40. package/dist/app-dir/server.mjs.map +1 -0
  41. package/dist/app-dir/shared.d.mts +37 -0
  42. package/dist/app-dir/shared.d.mts.map +1 -0
  43. package/dist/app-dir/shared.d.ts +21 -39
  44. package/dist/app-dir/shared.d.ts.map +1 -1
  45. package/dist/app-dir/shared.js +12 -13
  46. package/dist/app-dir/shared.mjs +11 -10
  47. package/dist/app-dir/shared.mjs.map +1 -0
  48. package/dist/app-dir/types.d.mts +33 -0
  49. package/dist/app-dir/types.d.mts.map +1 -0
  50. package/dist/app-dir/types.d.ts +27 -25
  51. package/dist/app-dir/types.d.ts.map +1 -1
  52. package/dist/createTRPCNext.d.mts +38 -0
  53. package/dist/createTRPCNext.d.mts.map +1 -0
  54. package/dist/createTRPCNext.d.ts +30 -21
  55. package/dist/createTRPCNext.d.ts.map +1 -1
  56. package/dist/createTRPCNext.js +23 -35
  57. package/dist/createTRPCNext.mjs +22 -32
  58. package/dist/createTRPCNext.mjs.map +1 -0
  59. package/dist/index.d.mts +3 -0
  60. package/dist/index.d.ts +3 -3
  61. package/dist/index.js +4 -8
  62. package/dist/index.mjs +4 -2
  63. package/dist/ssrPrepass.d.mts +10 -0
  64. package/dist/ssrPrepass.d.mts.map +1 -0
  65. package/dist/ssrPrepass.d.ts +9 -2
  66. package/dist/ssrPrepass.d.ts.map +1 -1
  67. package/dist/ssrPrepass.js +99 -134
  68. package/dist/ssrPrepass.mjs +98 -131
  69. package/dist/ssrPrepass.mjs.map +1 -0
  70. package/dist/withTRPC.d.mts +55 -0
  71. package/dist/withTRPC.d.mts.map +1 -0
  72. package/dist/withTRPC.d.ts +47 -46
  73. package/dist/withTRPC.d.ts.map +1 -1
  74. package/dist/withTRPC.js +69 -82
  75. package/dist/withTRPC.mjs +68 -79
  76. package/dist/withTRPC.mjs.map +1 -0
  77. package/package.json +63 -33
  78. package/src/withTRPC.tsx +1 -2
  79. package/ssrPrepass/package.json +1 -0
  80. package/dist/index.d.ts.map +0 -1
@@ -1,29 +1,38 @@
1
- import type { CreateReactUtils, DecorateRouterRecord, TRPCUseQueries, TRPCUseSuspenseQueries } from '@trpc/react-query/shared';
2
- import type { AnyRouter, ProtectedIntersection } from '@trpc/server/unstable-core-do-not-import';
3
- import type { NextPageContext } from 'next/types';
4
- import type { WithTRPCNoSSROptions, WithTRPCSSROptions } from './withTRPC';
5
- import { withTRPC } from './withTRPC';
1
+ import { WithTRPCNoSSROptions, WithTRPCSSROptions, withTRPC } from "./withTRPC.js";
2
+ import { AnyRouter, ProtectedIntersection } from "@trpc/server/unstable-core-do-not-import";
3
+ import { CreateReactUtils, DecorateRouterRecord, TRPCUseQueries, TRPCUseSuspenseQueries } from "@trpc/react-query/shared";
4
+ import { NextPageContext } from "next/types";
5
+
6
+ //#region src/createTRPCNext.d.ts
7
+ /**
8
+ * @internal
9
+ */
6
10
  /**
7
11
  * @internal
8
12
  */
9
- export interface CreateTRPCNextBase<TRouter extends AnyRouter, TSSRContext extends NextPageContext> {
10
- /**
11
- * @deprecated renamed to `useUtils` and will be removed in a future tRPC version
12
- *
13
- * @see https://trpc.io/docs/v11/client/react/useUtils
14
- */
15
- useContext(): CreateReactUtils<TRouter, TSSRContext>;
16
- /**
17
- * @see https://trpc.io/docs/v11/client/react/useUtils
18
- */
19
- useUtils(): CreateReactUtils<TRouter, TSSRContext>;
20
- withTRPC: ReturnType<typeof withTRPC<TRouter, TSSRContext>>;
21
- useQueries: TRPCUseQueries<TRouter>;
22
- useSuspenseQueries: TRPCUseSuspenseQueries<TRouter>;
13
+ interface CreateTRPCNextBase<TRouter extends AnyRouter, TSSRContext extends NextPageContext> {
14
+ /**
15
+ * @deprecated renamed to `useUtils` and will be removed in a future tRPC version
16
+ *
17
+ * @see https://trpc.io/docs/v11/client/react/useUtils
18
+ */
19
+ useContext(): CreateReactUtils<TRouter, TSSRContext>;
20
+ /**
21
+ * @see https://trpc.io/docs/v11/client/react/useUtils
22
+ */
23
+ useUtils(): CreateReactUtils<TRouter, TSSRContext>;
24
+ withTRPC: ReturnType<typeof withTRPC<TRouter, TSSRContext>>;
25
+ useQueries: TRPCUseQueries<TRouter>;
26
+ useSuspenseQueries: TRPCUseSuspenseQueries<TRouter>;
23
27
  }
24
28
  /**
25
29
  * @internal
26
30
  */
27
- export type CreateTRPCNext<TRouter extends AnyRouter, TSSRContext extends NextPageContext> = ProtectedIntersection<CreateTRPCNextBase<TRouter, TSSRContext>, DecorateRouterRecord<TRouter['_def']['_config']['$types'], TRouter['_def']['record']>>;
28
- export declare function createTRPCNext<TRouter extends AnyRouter, TSSRContext extends NextPageContext = NextPageContext>(opts: WithTRPCNoSSROptions<TRouter> | WithTRPCSSROptions<TRouter>): CreateTRPCNext<TRouter, TSSRContext>;
31
+ type CreateTRPCNext<TRouter extends AnyRouter, TSSRContext extends NextPageContext> = ProtectedIntersection<CreateTRPCNextBase<TRouter, TSSRContext>, DecorateRouterRecord<TRouter['_def']['_config']['$types'], TRouter['_def']['record']>>;
32
+ declare function createTRPCNext<TRouter extends AnyRouter, TSSRContext extends NextPageContext = NextPageContext>(opts: WithTRPCNoSSROptions<TRouter> | WithTRPCSSROptions<TRouter>): CreateTRPCNext<TRouter, TSSRContext>;
33
+
34
+ //#endregion
35
+ //# sourceMappingURL=createTRPCNext.d.ts.map
36
+
37
+ export { CreateTRPCNext, CreateTRPCNextBase, createTRPCNext };
29
38
  //# sourceMappingURL=createTRPCNext.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"createTRPCNext.d.ts","sourceRoot":"","sources":["../src/createTRPCNext.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,gBAAgB,EAChB,oBAAoB,EACpB,cAAc,EACd,sBAAsB,EACvB,MAAM,0BAA0B,CAAC;AAMlC,OAAO,KAAK,EACV,SAAS,EACT,qBAAqB,EACtB,MAAM,0CAA0C,CAAC;AAElD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElD,OAAO,KAAK,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAC3E,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtC;;GAEG;AACH,MAAM,WAAW,kBAAkB,CACjC,OAAO,SAAS,SAAS,EACzB,WAAW,SAAS,eAAe;IAEnC;;;;OAIG;IACH,UAAU,IAAI,gBAAgB,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;IACrD;;OAEG;IACH,QAAQ,IAAI,gBAAgB,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;IACnD,QAAQ,EAAE,UAAU,CAAC,OAAO,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC,CAAC;IAC5D,UAAU,EAAE,cAAc,CAAC,OAAO,CAAC,CAAC;IACpC,kBAAkB,EAAE,sBAAsB,CAAC,OAAO,CAAC,CAAC;CACrD;AAED;;GAEG;AACH,MAAM,MAAM,cAAc,CACxB,OAAO,SAAS,SAAS,EACzB,WAAW,SAAS,eAAe,IACjC,qBAAqB,CACvB,kBAAkB,CAAC,OAAO,EAAE,WAAW,CAAC,EACxC,oBAAoB,CAClB,OAAO,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,CAAC,QAAQ,CAAC,EACpC,OAAO,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,CAC1B,CACF,CAAC;AAEF,wBAAgB,cAAc,CAC5B,OAAO,SAAS,SAAS,EACzB,WAAW,SAAS,eAAe,GAAG,eAAe,EAErD,IAAI,EAAE,oBAAoB,CAAC,OAAO,CAAC,GAAG,kBAAkB,CAAC,OAAO,CAAC,GAChE,cAAc,CAAC,OAAO,EAAE,WAAW,CAAC,CAoCtC"}
1
+ {"version":3,"file":"createTRPCNext.d.ts","names":[],"sources":["../src/createTRPCNext.tsx"],"sourcesContent":[],"mappings":";;;;;;;;;;;;UA0BiB,mCACC,+BACI;EAFL;;;;;EASuB,UAAE,EAAA,EAA1B,gBAA0B,CAAT,OAAS,EAAA,WAAA,CAAA;EAAW;;;EAIF,QAArC,EAAA,EAAA,gBAAA,CAAiB,OAAjB,EAA0B,WAA1B,CAAA;EAAgB,QACS,EAA3B,UAA2B,CAAA,OAAT,QAAS,CAAA,OAAA,EAAS,WAAT,CAAA,CAAA;EAAO,UAAE,EAClC,cADkC,CACnB,OADmB,CAAA;EAAW,kBAA7B,EAER,sBAFQ,CAEe,OAFf,CAAA;;;;;AAER,KAMV,cANU,CAAA,gBAOJ,SAPI,EAAA,oBAQA,eARA,CAAA,GASlB,qBATkB,CAUpB,kBAVoB,CAUD,OAVC,EAUQ,WAVR,CAAA,EAWpB,oBAXoB,CAYlB,OAZkB,CAAA,MAAA,CAAA,CAAA,SAAA,CAAA,CAAA,QAAA,CAAA,EAalB,OAbkB,CAAA,MAAA,CAAA,CAAA,QAAA,CAAA,CAAA,CAAA;AAAsB,iBAiB5B,cAjB4B,CAAA,gBAkB1B,SAlB0B,EAAA,oBAmBtB,eAnBsB,GAmBJ,eAnBI,CAAA,CAAA,IAAA,EAqBpC,oBArBoC,CAqBf,OArBe,CAAA,GAqBJ,kBArBI,CAqBe,OArBf,CAAA,CAAA,EAsBzC,cAtByC,CAsB1B,OAtB0B,EAsBjB,WAtBiB,CAAA"}
@@ -1,39 +1,27 @@
1
- 'use strict';
1
+ const require_rolldown_runtime = require('./_virtual/rolldown_runtime.js');
2
+ const require__Users_julius_dev_trpc_packages_next_src_withTRPC = require('./withTRPC.js');
3
+ const __trpc_react_query_shared = require_rolldown_runtime.__toESM(require("@trpc/react-query/shared"));
4
+ const react = require_rolldown_runtime.__toESM(require("react"));
5
+ const __trpc_server_unstable_core_do_not_import = require_rolldown_runtime.__toESM(require("@trpc/server/unstable-core-do-not-import"));
2
6
 
3
- var shared = require('@trpc/react-query/shared');
4
- var unstableCoreDoNotImport = require('@trpc/server/unstable-core-do-not-import');
5
- var React = require('react');
6
- var withTRPC = require('./withTRPC.js');
7
-
8
- /* istanbul ignore file -- @preserve */ // We're testing this through E2E-testing
7
+ //#region src/createTRPCNext.tsx
9
8
  function createTRPCNext(opts) {
10
- const hooks = shared.createRootHooks(opts);
11
- // TODO: maybe set TSSRContext to `never` when using `WithTRPCNoSSROptions`
12
- const _withTRPC = withTRPC.withTRPC(opts);
13
- const proxy = shared.createReactDecoration(hooks);
14
- return unstableCoreDoNotImport.createFlatProxy((key)=>{
15
- if (key === 'useContext' || key === 'useUtils') {
16
- return ()=>{
17
- const context = hooks.useUtils();
18
- // create a stable reference of the utils context
19
- return React.useMemo(()=>{
20
- return shared.createReactQueryUtils(context);
21
- }, [
22
- context
23
- ]);
24
- };
25
- }
26
- if (key === 'useQueries') {
27
- return hooks.useQueries;
28
- }
29
- if (key === 'useSuspenseQueries') {
30
- return hooks.useSuspenseQueries;
31
- }
32
- if (key === 'withTRPC') {
33
- return _withTRPC;
34
- }
35
- return proxy[key];
36
- });
9
+ const hooks = (0, __trpc_react_query_shared.createRootHooks)(opts);
10
+ const _withTRPC = require__Users_julius_dev_trpc_packages_next_src_withTRPC.withTRPC(opts);
11
+ const proxy = (0, __trpc_react_query_shared.createReactDecoration)(hooks);
12
+ return (0, __trpc_server_unstable_core_do_not_import.createFlatProxy)((key) => {
13
+ if (key === "useContext" || key === "useUtils") return () => {
14
+ const context = hooks.useUtils();
15
+ return (0, react.useMemo)(() => {
16
+ return (0, __trpc_react_query_shared.createReactQueryUtils)(context);
17
+ }, [context]);
18
+ };
19
+ if (key === "useQueries") return hooks.useQueries;
20
+ if (key === "useSuspenseQueries") return hooks.useSuspenseQueries;
21
+ if (key === "withTRPC") return _withTRPC;
22
+ return proxy[key];
23
+ });
37
24
  }
38
25
 
39
- exports.createTRPCNext = createTRPCNext;
26
+ //#endregion
27
+ exports.createTRPCNext = createTRPCNext;
@@ -1,37 +1,27 @@
1
- import { createRootHooks, createReactDecoration, createReactQueryUtils } from '@trpc/react-query/shared';
2
- import { createFlatProxy } from '@trpc/server/unstable-core-do-not-import';
3
- import { useMemo } from 'react';
4
- import { withTRPC } from './withTRPC.mjs';
1
+ import { withTRPC } from "./withTRPC.mjs";
2
+ import { createReactDecoration, createReactQueryUtils, createRootHooks } from "@trpc/react-query/shared";
3
+ import { useMemo } from "react";
4
+ import { createFlatProxy } from "@trpc/server/unstable-core-do-not-import";
5
5
 
6
- /* istanbul ignore file -- @preserve */ // We're testing this through E2E-testing
6
+ //#region src/createTRPCNext.tsx
7
7
  function createTRPCNext(opts) {
8
- const hooks = createRootHooks(opts);
9
- // TODO: maybe set TSSRContext to `never` when using `WithTRPCNoSSROptions`
10
- const _withTRPC = withTRPC(opts);
11
- const proxy = createReactDecoration(hooks);
12
- return createFlatProxy((key)=>{
13
- if (key === 'useContext' || key === 'useUtils') {
14
- return ()=>{
15
- const context = hooks.useUtils();
16
- // create a stable reference of the utils context
17
- return useMemo(()=>{
18
- return createReactQueryUtils(context);
19
- }, [
20
- context
21
- ]);
22
- };
23
- }
24
- if (key === 'useQueries') {
25
- return hooks.useQueries;
26
- }
27
- if (key === 'useSuspenseQueries') {
28
- return hooks.useSuspenseQueries;
29
- }
30
- if (key === 'withTRPC') {
31
- return _withTRPC;
32
- }
33
- return proxy[key];
34
- });
8
+ const hooks = createRootHooks(opts);
9
+ const _withTRPC = withTRPC(opts);
10
+ const proxy = createReactDecoration(hooks);
11
+ return createFlatProxy((key) => {
12
+ if (key === "useContext" || key === "useUtils") return () => {
13
+ const context = hooks.useUtils();
14
+ return useMemo(() => {
15
+ return createReactQueryUtils(context);
16
+ }, [context]);
17
+ };
18
+ if (key === "useQueries") return hooks.useQueries;
19
+ if (key === "useSuspenseQueries") return hooks.useSuspenseQueries;
20
+ if (key === "withTRPC") return _withTRPC;
21
+ return proxy[key];
22
+ });
35
23
  }
36
24
 
25
+ //#endregion
37
26
  export { createTRPCNext };
27
+ //# sourceMappingURL=createTRPCNext.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createTRPCNext.mjs","names":["opts: WithTRPCNoSSROptions<TRouter> | WithTRPCSSROptions<TRouter>"],"sources":["../src/createTRPCNext.tsx"],"sourcesContent":["/* 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":";;;;;;AA2DA,SAAgB,eAIdA,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"}
@@ -0,0 +1,3 @@
1
+ import { TRPCPrepassHelper, TRPCPrepassProps, WithTRPCConfig, WithTRPCNoSSROptions, WithTRPCSSROptions, withTRPC$1 as withTRPC } from "./withTRPC.mjs";
2
+ import { CreateTRPCNext, CreateTRPCNextBase, createTRPCNext$1 as createTRPCNext } from "./createTRPCNext.mjs";
3
+ export { CreateTRPCNext, CreateTRPCNextBase, TRPCPrepassHelper, TRPCPrepassProps, WithTRPCConfig, WithTRPCNoSSROptions, WithTRPCSSROptions, createTRPCNext, withTRPC };
package/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export * from './withTRPC';
2
- export * from './createTRPCNext';
3
- //# sourceMappingURL=index.d.ts.map
1
+ import { TRPCPrepassHelper, TRPCPrepassProps, WithTRPCConfig, WithTRPCNoSSROptions, WithTRPCSSROptions, withTRPC } from "./withTRPC.js";
2
+ import { CreateTRPCNext, CreateTRPCNextBase, createTRPCNext } from "./createTRPCNext.js";
3
+ export { CreateTRPCNext, CreateTRPCNextBase, TRPCPrepassHelper, TRPCPrepassProps, WithTRPCConfig, WithTRPCNoSSROptions, WithTRPCSSROptions, createTRPCNext, withTRPC };
package/dist/index.js CHANGED
@@ -1,9 +1,5 @@
1
- 'use strict';
1
+ const require__Users_julius_dev_trpc_packages_next_src_withTRPC = require('./withTRPC.js');
2
+ const require__Users_julius_dev_trpc_packages_next_src_createTRPCNext = require('./createTRPCNext.js');
2
3
 
3
- var withTRPC = require('./withTRPC.js');
4
- var createTRPCNext = require('./createTRPCNext.js');
5
-
6
-
7
-
8
- exports.withTRPC = withTRPC.withTRPC;
9
- exports.createTRPCNext = createTRPCNext.createTRPCNext;
4
+ exports.createTRPCNext = require__Users_julius_dev_trpc_packages_next_src_createTRPCNext.createTRPCNext;
5
+ exports.withTRPC = require__Users_julius_dev_trpc_packages_next_src_withTRPC.withTRPC;
package/dist/index.mjs CHANGED
@@ -1,2 +1,4 @@
1
- export { withTRPC } from './withTRPC.mjs';
2
- export { createTRPCNext } from './createTRPCNext.mjs';
1
+ import { withTRPC } from "./withTRPC.mjs";
2
+ import { createTRPCNext } from "./createTRPCNext.mjs";
3
+
4
+ export { createTRPCNext, withTRPC };
@@ -0,0 +1,10 @@
1
+ import { TRPCPrepassHelper } from "./withTRPC.mjs";
2
+
3
+ //#region src/ssrPrepass.d.ts
4
+ declare const ssrPrepass: TRPCPrepassHelper;
5
+
6
+ //#endregion
7
+ //# sourceMappingURL=ssrPrepass.d.ts.map
8
+
9
+ export { ssrPrepass };
10
+ //# sourceMappingURL=ssrPrepass.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ssrPrepass.d.mts","names":[],"sources":["../src/ssrPrepass.ts"],"sourcesContent":[],"mappings":";;;cA8Ca,YAAY"}
@@ -1,3 +1,10 @@
1
- import type { TRPCPrepassHelper } from './withTRPC';
2
- export declare const ssrPrepass: TRPCPrepassHelper;
1
+ import { TRPCPrepassHelper } from "./withTRPC.js";
2
+
3
+ //#region src/ssrPrepass.d.ts
4
+ declare const ssrPrepass: TRPCPrepassHelper;
5
+
6
+ //#endregion
7
+ //# sourceMappingURL=ssrPrepass.d.ts.map
8
+
9
+ export { ssrPrepass };
3
10
  //# sourceMappingURL=ssrPrepass.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ssrPrepass.d.ts","sourceRoot":"","sources":["../src/ssrPrepass.ts"],"names":[],"mappings":"AAqBA,OAAO,KAAK,EAAE,iBAAiB,EAAoB,MAAM,YAAY,CAAC;AAyBtE,eAAO,MAAM,UAAU,EAAE,iBA0IxB,CAAC"}
1
+ {"version":3,"file":"ssrPrepass.d.ts","names":[],"sources":["../src/ssrPrepass.ts"],"sourcesContent":[],"mappings":";;;cA8Ca,YAAY"}
@@ -1,139 +1,104 @@
1
- 'use strict';
2
-
3
- var reactQuery = require('@tanstack/react-query');
4
- var client = require('@trpc/client');
5
- var unstableInternals = require('@trpc/client/unstable-internals');
6
- var shared = require('@trpc/react-query/shared');
7
- var React = require('react');
1
+ const require_rolldown_runtime = require('./_virtual/rolldown_runtime.js');
2
+ const __tanstack_react_query = require_rolldown_runtime.__toESM(require("@tanstack/react-query"));
3
+ const __trpc_client_unstable_internals = require_rolldown_runtime.__toESM(require("@trpc/client/unstable-internals"));
4
+ const __trpc_react_query_shared = require_rolldown_runtime.__toESM(require("@trpc/react-query/shared"));
5
+ const react = require_rolldown_runtime.__toESM(require("react"));
6
+ const __trpc_client = require_rolldown_runtime.__toESM(require("@trpc/client"));
8
7
 
8
+ //#region src/ssrPrepass.ts
9
9
  function transformQueryOrMutationCacheErrors(result) {
10
- const error = result.state.error;
11
- if (error instanceof Error && error.name === 'TRPCClientError') {
12
- const newError = {
13
- message: error.message,
14
- data: error.data,
15
- shape: error.shape
16
- };
17
- return {
18
- ...result,
19
- state: {
20
- ...result.state,
21
- error: newError
22
- }
23
- };
24
- }
25
- return result;
10
+ const error = result.state.error;
11
+ if (error instanceof Error && error.name === "TRPCClientError") {
12
+ const newError = {
13
+ message: error.message,
14
+ data: error.data,
15
+ shape: error.shape
16
+ };
17
+ return {
18
+ ...result,
19
+ state: {
20
+ ...result.state,
21
+ error: newError
22
+ }
23
+ };
24
+ }
25
+ return result;
26
26
  }
27
- const ssrPrepass = (opts)=>{
28
- const { parent, WithTRPC, AppOrPage } = opts;
29
- const transformer = unstableInternals.getTransformer(parent.transformer);
30
- WithTRPC.getInitialProps = async (appOrPageCtx)=>{
31
- const shouldSsr = async ()=>{
32
- if (typeof window !== 'undefined') {
33
- return false;
34
- }
35
- if (typeof parent.ssr === 'function') {
36
- try {
37
- return await parent.ssr({
38
- ctx: appOrPageCtx.ctx
39
- });
40
- } catch {
41
- return false;
42
- }
43
- }
44
- return parent.ssr;
45
- };
46
- const ssrEnabled = await shouldSsr();
47
- const AppTree = appOrPageCtx.AppTree;
48
- // Determine if we are wrapping an App component or a Page component.
49
- const isApp = !!appOrPageCtx.Component;
50
- const ctx = isApp ? appOrPageCtx.ctx : appOrPageCtx;
51
- // Run the wrapped component's getInitialProps function.
52
- let pageProps = {};
53
- if (AppOrPage.getInitialProps) {
54
- const originalProps = await AppOrPage.getInitialProps(appOrPageCtx);
55
- const originalPageProps = isApp ? originalProps.pageProps ?? {} : originalProps;
56
- pageProps = {
57
- ...originalPageProps,
58
- ...pageProps
59
- };
60
- }
61
- const getAppTreeProps = (props)=>isApp ? {
62
- pageProps: props
63
- } : props;
64
- if (typeof window !== 'undefined' || !ssrEnabled) {
65
- return getAppTreeProps(pageProps);
66
- }
67
- const config = parent.config({
68
- ctx
69
- });
70
- const trpcClient = client.createTRPCUntypedClient(config);
71
- const queryClient = shared.getQueryClient(config);
72
- const trpcProp = {
73
- config,
74
- trpcClient,
75
- queryClient,
76
- ssrState: 'prepass',
77
- ssrContext: ctx
78
- };
79
- const prepassProps = {
80
- pageProps,
81
- trpc: trpcProp
82
- };
83
- const reactDomServer = await import('react-dom/server');
84
- // Run the prepass step on AppTree. This will run all trpc queries on the server.
85
- // multiple prepass ensures that we can do batching on the server
86
- while(true){
87
- // render full tree
88
- reactDomServer.renderToString(React.createElement(AppTree, prepassProps));
89
- if (!queryClient.isFetching()) {
90
- break;
91
- }
92
- // wait until the query cache has settled it's promises
93
- await new Promise((resolve)=>{
94
- const unsub = queryClient.getQueryCache().subscribe((event)=>{
95
- if (event?.query.getObserversCount() === 0) {
96
- resolve();
97
- unsub();
98
- }
99
- });
100
- });
101
- }
102
- const dehydratedCache = reactQuery.dehydrate(queryClient, {
103
- shouldDehydrateQuery (query) {
104
- // filter out queries that are marked as trpc: { ssr: false } or are not enabled, but make sure errors are dehydrated
105
- const isExcludedFromSSr = query.state.fetchStatus === 'idle' && query.state.status === 'pending';
106
- return !isExcludedFromSSr;
107
- }
108
- });
109
- // since error instances can't be serialized, let's make them into `TRPCClientErrorLike`-objects
110
- const dehydratedCacheWithErrors = {
111
- ...dehydratedCache,
112
- queries: dehydratedCache.queries.map(transformQueryOrMutationCacheErrors),
113
- mutations: dehydratedCache.mutations.map(transformQueryOrMutationCacheErrors)
114
- };
115
- // dehydrate query client's state and add it to the props
116
- pageProps['trpcState'] = transformer.input.serialize(dehydratedCacheWithErrors);
117
- const appTreeProps = getAppTreeProps(pageProps);
118
- const meta = parent.responseMeta?.({
119
- ctx,
120
- clientErrors: [
121
- ...dehydratedCache.queries,
122
- ...dehydratedCache.mutations
123
- ].map((v)=>v.state.error).flatMap((err)=>err instanceof Error && err.name === 'TRPCClientError' ? [
124
- err
125
- ] : [])
126
- }) ?? {};
127
- for (const [key, value] of Object.entries(meta.headers ?? {})){
128
- if (typeof value === 'string') {
129
- ctx.res?.setHeader(key, value);
130
- }
131
- }
132
- if (meta.status && ctx.res) {
133
- ctx.res.statusCode = meta.status;
134
- }
135
- return appTreeProps;
136
- };
27
+ const ssrPrepass = (opts) => {
28
+ const { parent, WithTRPC, AppOrPage } = opts;
29
+ const transformer = (0, __trpc_client_unstable_internals.getTransformer)(parent.transformer);
30
+ WithTRPC.getInitialProps = async (appOrPageCtx) => {
31
+ const shouldSsr = async () => {
32
+ if (typeof window !== "undefined") return false;
33
+ if (typeof parent.ssr === "function") try {
34
+ return await parent.ssr({ ctx: appOrPageCtx.ctx });
35
+ } catch {
36
+ return false;
37
+ }
38
+ return parent.ssr;
39
+ };
40
+ const ssrEnabled = await shouldSsr();
41
+ const AppTree = appOrPageCtx.AppTree;
42
+ const isApp = !!appOrPageCtx.Component;
43
+ const ctx = isApp ? appOrPageCtx.ctx : appOrPageCtx;
44
+ let pageProps = {};
45
+ if (AppOrPage.getInitialProps) {
46
+ const originalProps = await AppOrPage.getInitialProps(appOrPageCtx);
47
+ const originalPageProps = isApp ? originalProps.pageProps ?? {} : originalProps;
48
+ pageProps = {
49
+ ...originalPageProps,
50
+ ...pageProps
51
+ };
52
+ }
53
+ const getAppTreeProps = (props) => isApp ? { pageProps: props } : props;
54
+ if (typeof window !== "undefined" || !ssrEnabled) return getAppTreeProps(pageProps);
55
+ const config = parent.config({ ctx });
56
+ const trpcClient = (0, __trpc_client.createTRPCUntypedClient)(config);
57
+ const queryClient = (0, __trpc_react_query_shared.getQueryClient)(config);
58
+ const trpcProp = {
59
+ config,
60
+ trpcClient,
61
+ queryClient,
62
+ ssrState: "prepass",
63
+ ssrContext: ctx
64
+ };
65
+ const prepassProps = {
66
+ pageProps,
67
+ trpc: trpcProp
68
+ };
69
+ const reactDomServer = await import("react-dom/server");
70
+ while (true) {
71
+ reactDomServer.renderToString((0, react.createElement)(AppTree, prepassProps));
72
+ if (!queryClient.isFetching()) break;
73
+ await new Promise((resolve) => {
74
+ const unsub = queryClient.getQueryCache().subscribe((event) => {
75
+ if (event?.query.getObserversCount() === 0) {
76
+ resolve();
77
+ unsub();
78
+ }
79
+ });
80
+ });
81
+ }
82
+ const dehydratedCache = (0, __tanstack_react_query.dehydrate)(queryClient, { shouldDehydrateQuery(query) {
83
+ const isExcludedFromSSr = query.state.fetchStatus === "idle" && query.state.status === "pending";
84
+ return !isExcludedFromSSr;
85
+ } });
86
+ const dehydratedCacheWithErrors = {
87
+ ...dehydratedCache,
88
+ queries: dehydratedCache.queries.map(transformQueryOrMutationCacheErrors),
89
+ mutations: dehydratedCache.mutations.map(transformQueryOrMutationCacheErrors)
90
+ };
91
+ pageProps["trpcState"] = transformer.input.serialize(dehydratedCacheWithErrors);
92
+ const appTreeProps = getAppTreeProps(pageProps);
93
+ const meta = parent.responseMeta?.({
94
+ ctx,
95
+ clientErrors: [...dehydratedCache.queries, ...dehydratedCache.mutations].map((v) => v.state.error).flatMap((err) => err instanceof Error && err.name === "TRPCClientError" ? [err] : [])
96
+ }) ?? {};
97
+ for (const [key, value] of Object.entries(meta.headers ?? {})) if (typeof value === "string") ctx.res?.setHeader(key, value);
98
+ if (meta.status && ctx.res) ctx.res.statusCode = meta.status;
99
+ return appTreeProps;
100
+ };
137
101
  };
138
102
 
139
- exports.ssrPrepass = ssrPrepass;
103
+ //#endregion
104
+ exports.ssrPrepass = ssrPrepass;