@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.
- package/app-dir/client/package.json +1 -0
- package/app-dir/links/nextCache/package.json +1 -0
- package/app-dir/links/nextHttp/package.json +1 -0
- package/app-dir/server/package.json +1 -0
- package/dist/_virtual/rolldown_runtime.js +30 -0
- package/dist/app-dir/client.d.mts +13 -0
- package/dist/app-dir/client.d.mts.map +1 -0
- package/dist/app-dir/client.d.ts +12 -5
- package/dist/app-dir/client.d.ts.map +1 -1
- package/dist/app-dir/client.js +25 -43
- package/dist/app-dir/client.mjs +24 -40
- package/dist/app-dir/client.mjs.map +1 -0
- package/dist/app-dir/create-action-hook.d.mts +47 -0
- package/dist/app-dir/create-action-hook.d.mts.map +1 -0
- package/dist/app-dir/create-action-hook.d.ts +33 -36
- package/dist/app-dir/create-action-hook.d.ts.map +1 -1
- package/dist/app-dir/create-action-hook.js +85 -101
- package/dist/app-dir/create-action-hook.mjs +84 -98
- package/dist/app-dir/create-action-hook.mjs.map +1 -0
- package/dist/app-dir/links/nextCache.d.mts +16 -0
- package/dist/app-dir/links/nextCache.d.mts.map +1 -0
- package/dist/app-dir/links/nextCache.d.ts +13 -9
- package/dist/app-dir/links/nextCache.d.ts.map +1 -1
- package/dist/app-dir/links/nextCache.js +44 -58
- package/dist/app-dir/links/nextCache.mjs +43 -55
- package/dist/app-dir/links/nextCache.mjs.map +1 -0
- package/dist/app-dir/links/nextHttp.d.mts +19 -0
- package/dist/app-dir/links/nextHttp.d.mts.map +1 -0
- package/dist/app-dir/links/nextHttp.d.ts +12 -8
- package/dist/app-dir/links/nextHttp.d.ts.map +1 -1
- package/dist/app-dir/links/nextHttp.js +31 -35
- package/dist/app-dir/links/nextHttp.mjs +30 -32
- package/dist/app-dir/links/nextHttp.mjs.map +1 -0
- package/dist/app-dir/server.d.mts +36 -0
- package/dist/app-dir/server.d.mts.map +1 -0
- package/dist/app-dir/server.d.ts +30 -24
- package/dist/app-dir/server.d.ts.map +1 -1
- package/dist/app-dir/server.js +86 -112
- package/dist/app-dir/server.mjs +85 -109
- package/dist/app-dir/server.mjs.map +1 -0
- package/dist/app-dir/shared.d.mts +37 -0
- package/dist/app-dir/shared.d.mts.map +1 -0
- package/dist/app-dir/shared.d.ts +21 -39
- package/dist/app-dir/shared.d.ts.map +1 -1
- package/dist/app-dir/shared.js +12 -13
- package/dist/app-dir/shared.mjs +11 -10
- package/dist/app-dir/shared.mjs.map +1 -0
- package/dist/app-dir/types.d.mts +33 -0
- package/dist/app-dir/types.d.mts.map +1 -0
- package/dist/app-dir/types.d.ts +27 -25
- package/dist/app-dir/types.d.ts.map +1 -1
- package/dist/createTRPCNext.d.mts +38 -0
- package/dist/createTRPCNext.d.mts.map +1 -0
- package/dist/createTRPCNext.d.ts +30 -21
- package/dist/createTRPCNext.d.ts.map +1 -1
- package/dist/createTRPCNext.js +23 -35
- package/dist/createTRPCNext.mjs +22 -32
- package/dist/createTRPCNext.mjs.map +1 -0
- package/dist/index.d.mts +3 -0
- package/dist/index.d.ts +3 -3
- package/dist/index.js +4 -8
- package/dist/index.mjs +4 -2
- package/dist/ssrPrepass.d.mts +10 -0
- package/dist/ssrPrepass.d.mts.map +1 -0
- package/dist/ssrPrepass.d.ts +9 -2
- package/dist/ssrPrepass.d.ts.map +1 -1
- package/dist/ssrPrepass.js +99 -134
- package/dist/ssrPrepass.mjs +98 -131
- package/dist/ssrPrepass.mjs.map +1 -0
- package/dist/withTRPC.d.mts +55 -0
- package/dist/withTRPC.d.mts.map +1 -0
- package/dist/withTRPC.d.ts +47 -46
- package/dist/withTRPC.d.ts.map +1 -1
- package/dist/withTRPC.js +69 -82
- package/dist/withTRPC.mjs +68 -79
- package/dist/withTRPC.mjs.map +1 -0
- package/package.json +63 -33
- package/src/withTRPC.tsx +1 -2
- package/ssrPrepass/package.json +1 -0
- package/dist/index.d.ts.map +0 -1
package/dist/createTRPCNext.d.ts
CHANGED
|
@@ -1,29 +1,38 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
|
|
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
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
|
|
28
|
-
|
|
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","
|
|
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"}
|
package/dist/createTRPCNext.js
CHANGED
|
@@ -1,39 +1,27 @@
|
|
|
1
|
-
|
|
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
|
-
|
|
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
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
|
|
26
|
+
//#endregion
|
|
27
|
+
exports.createTRPCNext = createTRPCNext;
|
package/dist/createTRPCNext.mjs
CHANGED
|
@@ -1,37 +1,27 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { useMemo } from
|
|
4
|
-
import {
|
|
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
|
-
|
|
6
|
+
//#region src/createTRPCNext.tsx
|
|
7
7
|
function createTRPCNext(opts) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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"}
|
package/dist/index.d.mts
ADDED
|
@@ -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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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
|
-
|
|
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
|
-
|
|
4
|
-
|
|
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
|
@@ -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"}
|
package/dist/ssrPrepass.d.ts
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
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
|
package/dist/ssrPrepass.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ssrPrepass.d.ts","
|
|
1
|
+
{"version":3,"file":"ssrPrepass.d.ts","names":[],"sources":["../src/ssrPrepass.ts"],"sourcesContent":[],"mappings":";;;cA8Ca,YAAY"}
|
package/dist/ssrPrepass.js
CHANGED
|
@@ -1,139 +1,104 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
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
|
-
|
|
103
|
+
//#endregion
|
|
104
|
+
exports.ssrPrepass = ssrPrepass;
|