@trpc/next 11.3.1 → 11.3.2-canary.4
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/app-dir/client.cjs +115 -0
- package/dist/app-dir/client.d.cts +50 -0
- package/dist/app-dir/client.d.cts.map +1 -0
- package/dist/app-dir/client.d.mts +50 -0
- package/dist/app-dir/client.d.mts.map +1 -0
- package/dist/app-dir/client.mjs +109 -40
- package/dist/app-dir/client.mjs.map +1 -0
- package/dist/app-dir/links/nextCache.cjs +48 -0
- package/dist/app-dir/links/nextCache.d.cts +15 -0
- package/dist/app-dir/links/nextCache.d.cts.map +1 -0
- package/dist/app-dir/links/nextCache.d.mts +15 -0
- package/dist/app-dir/links/nextCache.d.mts.map +1 -0
- 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.cjs +35 -0
- package/dist/app-dir/links/nextHttp.d.cts +18 -0
- package/dist/app-dir/links/nextHttp.d.cts.map +1 -0
- package/dist/app-dir/links/nextHttp.d.mts +18 -0
- package/dist/app-dir/links/nextHttp.d.mts.map +1 -0
- package/dist/app-dir/links/nextHttp.mjs +30 -32
- package/dist/app-dir/links/nextHttp.mjs.map +1 -0
- package/dist/app-dir/server.cjs +96 -0
- package/dist/app-dir/server.d.cts +2 -0
- package/dist/app-dir/server.d.mts +2 -0
- package/dist/app-dir/server.mjs +85 -109
- package/dist/app-dir/server.mjs.map +1 -0
- package/dist/chunk-CUT6urMc.cjs +30 -0
- package/dist/index.cjs +95 -0
- package/dist/index.d.cts +35 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +35 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +94 -2
- package/dist/index.mjs.map +1 -0
- package/dist/server.d-BXv5jwlB.d.mts +90 -0
- package/dist/server.d-BXv5jwlB.d.mts.map +1 -0
- package/dist/server.d-DLnegS7F.d.cts +90 -0
- package/dist/server.d-DLnegS7F.d.cts.map +1 -0
- package/dist/shared-C9SS-IYg.cjs +29 -0
- package/dist/shared-FEQznZ-6.mjs +18 -0
- package/dist/shared-FEQznZ-6.mjs.map +1 -0
- package/dist/ssrPrepass.cjs +104 -0
- package/dist/ssrPrepass.d.cts +9 -0
- package/dist/ssrPrepass.d.cts.map +1 -0
- package/dist/ssrPrepass.d.mts +9 -0
- package/dist/ssrPrepass.d.mts.map +1 -0
- package/dist/ssrPrepass.mjs +98 -131
- package/dist/ssrPrepass.mjs.map +1 -0
- package/dist/withTRPC.d-BY6FsDWi.d.mts +54 -0
- package/dist/withTRPC.d-BY6FsDWi.d.mts.map +1 -0
- package/dist/withTRPC.d-DctYN4Yz.d.cts +54 -0
- package/dist/withTRPC.d-DctYN4Yz.d.cts.map +1 -0
- package/package.json +63 -34
- package/ssrPrepass/package.json +1 -0
- package/app-dir/client/index.d.ts +0 -1
- package/app-dir/client/index.js +0 -1
- package/app-dir/links/nextCache/index.d.ts +0 -1
- package/app-dir/links/nextCache/index.js +0 -1
- package/app-dir/links/nextHttp/index.d.ts +0 -1
- package/app-dir/links/nextHttp/index.js +0 -1
- package/app-dir/server/index.d.ts +0 -1
- package/app-dir/server/index.js +0 -1
- package/dist/app-dir/client.d.ts +0 -6
- package/dist/app-dir/client.d.ts.map +0 -1
- package/dist/app-dir/client.js +0 -48
- package/dist/app-dir/create-action-hook.d.ts +0 -50
- package/dist/app-dir/create-action-hook.d.ts.map +0 -1
- package/dist/app-dir/create-action-hook.js +0 -108
- package/dist/app-dir/create-action-hook.mjs +0 -105
- package/dist/app-dir/links/nextCache.d.ts +0 -12
- package/dist/app-dir/links/nextCache.d.ts.map +0 -1
- package/dist/app-dir/links/nextCache.js +0 -62
- package/dist/app-dir/links/nextHttp.d.ts +0 -15
- package/dist/app-dir/links/nextHttp.d.ts.map +0 -1
- package/dist/app-dir/links/nextHttp.js +0 -39
- package/dist/app-dir/server.d.ts +0 -30
- package/dist/app-dir/server.d.ts.map +0 -1
- package/dist/app-dir/server.js +0 -122
- package/dist/app-dir/shared.d.ts +0 -55
- package/dist/app-dir/shared.d.ts.map +0 -1
- package/dist/app-dir/shared.js +0 -20
- package/dist/app-dir/shared.mjs +0 -17
- package/dist/app-dir/types.d.ts +0 -31
- package/dist/app-dir/types.d.ts.map +0 -1
- package/dist/createTRPCNext.d.ts +0 -29
- package/dist/createTRPCNext.d.ts.map +0 -1
- package/dist/createTRPCNext.js +0 -39
- package/dist/createTRPCNext.mjs +0 -37
- package/dist/index.d.ts +0 -3
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -9
- package/dist/ssrPrepass.d.ts +0 -3
- package/dist/ssrPrepass.d.ts.map +0 -1
- package/dist/ssrPrepass.js +0 -139
- package/dist/withTRPC.d.ts +0 -54
- package/dist/withTRPC.d.ts.map +0 -1
- package/dist/withTRPC.js +0 -84
- package/dist/withTRPC.mjs +0 -82
- package/ssrPrepass/index.d.ts +0 -1
- package/ssrPrepass/index.js +0 -1
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
const require_chunk = require('../../chunk-CUT6urMc.cjs');
|
|
2
|
+
const require_shared = require('../../shared-C9SS-IYg.cjs');
|
|
3
|
+
const __trpc_client = require_chunk.__toESM(require("@trpc/client"));
|
|
4
|
+
|
|
5
|
+
//#region src/app-dir/links/nextHttp.ts
|
|
6
|
+
function experimental_nextHttpLink(opts) {
|
|
7
|
+
return (runtime) => {
|
|
8
|
+
return (ctx) => {
|
|
9
|
+
const { path, input, context } = ctx.op;
|
|
10
|
+
const cacheTag = require_shared.generateCacheTag(path, input);
|
|
11
|
+
const requestRevalidate = typeof context["revalidate"] === "number" || context["revalidate"] === false ? context["revalidate"] : void 0;
|
|
12
|
+
const revalidate = requestRevalidate ?? opts.revalidate ?? false;
|
|
13
|
+
const _fetch = (url, fetchOpts) => {
|
|
14
|
+
return fetch(url, {
|
|
15
|
+
...fetchOpts,
|
|
16
|
+
next: {
|
|
17
|
+
revalidate,
|
|
18
|
+
tags: [cacheTag]
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
const link = opts.batch ? (0, __trpc_client.httpBatchLink)({
|
|
23
|
+
...opts,
|
|
24
|
+
fetch: _fetch
|
|
25
|
+
}) : (0, __trpc_client.httpLink)({
|
|
26
|
+
...opts,
|
|
27
|
+
fetch: _fetch
|
|
28
|
+
});
|
|
29
|
+
return link(runtime)(ctx);
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
//#endregion
|
|
35
|
+
exports.experimental_nextHttpLink = experimental_nextHttpLink;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { HTTPBatchLinkOptions, HTTPLinkOptions, TRPCLink } from "@trpc/client";
|
|
2
|
+
import { AnyRootTypes, AnyRouter } from "@trpc/server/unstable-core-do-not-import";
|
|
3
|
+
|
|
4
|
+
//#region src/app-dir/links/nextHttp.d.ts
|
|
5
|
+
interface NextLinkBaseOptions {
|
|
6
|
+
revalidate?: number | false;
|
|
7
|
+
batch?: boolean;
|
|
8
|
+
}
|
|
9
|
+
type NextLinkSingleOptions<TRoot extends AnyRootTypes> = NextLinkBaseOptions & Omit<HTTPLinkOptions<TRoot>, 'fetch'> & {
|
|
10
|
+
batch?: false;
|
|
11
|
+
};
|
|
12
|
+
type NextLinkBatchOptions<TRoot extends AnyRootTypes> = NextLinkBaseOptions & Omit<HTTPBatchLinkOptions<TRoot>, 'fetch'> & {
|
|
13
|
+
batch: true;
|
|
14
|
+
};
|
|
15
|
+
declare function experimental_nextHttpLink<TRouter extends AnyRouter>(opts: NextLinkSingleOptions<TRouter['_def']['_config']['$types']> | NextLinkBatchOptions<TRouter['_def']['_config']['$types']>): TRPCLink<TRouter>;
|
|
16
|
+
//#endregion
|
|
17
|
+
export { experimental_nextHttpLink };
|
|
18
|
+
//# sourceMappingURL=nextHttp.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nextHttp.d.cts","names":[],"sources":["../../../src/app-dir/links/nextHttp.ts"],"sourcesContent":[],"mappings":";;;;UAYU,mBAAA;;EAAA,KAAA,CAAA,EAAA,OAAA;AAAmB;KAKxB,qBAAqB,CAAA,cAAe,YAAf,CAAA,GAA+B,mBAA/B,GACxB,IADwB,CACnB,eADmB,CACH,KADG,CAAA,EAAA,OAAA,CAAA,GAAA;EAAA,KAAe,CAAA,EAAA,KAAA;CAAY;KAKhD,oBAJkB,CAAA,cAIiB,YAJjB,CAAA,GAIiC,mBAJjC,GAKrB,IALqB,CAKhB,oBALgB,CAKK,KALL,CAAA,EAAA,OAAA,CAAA,GAAA;EAAK,KAArB,EAAA,IAAA;CAAe;AAAhB,iBAUU,yBAVV,CAAA,gBAUoD,SAVpD,CAAA,CAAA,IAAA,EAYA,qBAZA,CAYsB,OAZtB,CAAA,MAAA,CAAA,CAAA,SAAA,CAAA,CAAA,QAAA,CAAA,CAAA,GAaA,oBAbA,CAaqB,OAbrB,CAAA,MAAA,CAAA,CAAA,SAAA,CAAA,CAAA,QAAA,CAAA,CAAA,CAAA,EAcH,QAdG,CAcM,OAdN,CAAA"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { AnyRootTypes, AnyRouter } from "@trpc/server/unstable-core-do-not-import";
|
|
2
|
+
import { HTTPBatchLinkOptions, HTTPLinkOptions, TRPCLink } from "@trpc/client";
|
|
3
|
+
|
|
4
|
+
//#region src/app-dir/links/nextHttp.d.ts
|
|
5
|
+
interface NextLinkBaseOptions {
|
|
6
|
+
revalidate?: number | false;
|
|
7
|
+
batch?: boolean;
|
|
8
|
+
}
|
|
9
|
+
type NextLinkSingleOptions<TRoot extends AnyRootTypes> = NextLinkBaseOptions & Omit<HTTPLinkOptions<TRoot>, 'fetch'> & {
|
|
10
|
+
batch?: false;
|
|
11
|
+
};
|
|
12
|
+
type NextLinkBatchOptions<TRoot extends AnyRootTypes> = NextLinkBaseOptions & Omit<HTTPBatchLinkOptions<TRoot>, 'fetch'> & {
|
|
13
|
+
batch: true;
|
|
14
|
+
};
|
|
15
|
+
declare function experimental_nextHttpLink<TRouter extends AnyRouter>(opts: NextLinkSingleOptions<TRouter['_def']['_config']['$types']> | NextLinkBatchOptions<TRouter['_def']['_config']['$types']>): TRPCLink<TRouter>;
|
|
16
|
+
//#endregion
|
|
17
|
+
export { experimental_nextHttpLink };
|
|
18
|
+
//# sourceMappingURL=nextHttp.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nextHttp.d.mts","names":[],"sources":["../../../src/app-dir/links/nextHttp.ts"],"sourcesContent":[],"mappings":";;;;UAYU,mBAAA;;EAAA,KAAA,CAAA,EAAA,OAAA;AAAmB;KAKxB,qBAAqB,CAAA,cAAe,YAAf,CAAA,GAA+B,mBAA/B,GACxB,IADwB,CACnB,eADmB,CACH,KADG,CAAA,EAAA,OAAA,CAAA,GAAA;EAAA,KAAe,CAAA,EAAA,KAAA;CAAY;KAKhD,oBAJkB,CAAA,cAIiB,YAJjB,CAAA,GAIiC,mBAJjC,GAKrB,IALqB,CAKhB,oBALgB,CAKK,KALL,CAAA,EAAA,OAAA,CAAA,GAAA;EAAK,KAArB,EAAA,IAAA;CAAe;AAAhB,iBAUU,yBAVV,CAAA,gBAUoD,SAVpD,CAAA,CAAA,IAAA,EAYA,qBAZA,CAYsB,OAZtB,CAAA,MAAA,CAAA,CAAA,SAAA,CAAA,CAAA,QAAA,CAAA,CAAA,GAaA,oBAbA,CAaqB,OAbrB,CAAA,MAAA,CAAA,CAAA,SAAA,CAAA,CAAA,QAAA,CAAA,CAAA,CAAA,EAcH,QAdG,CAcM,OAdN,CAAA"}
|
|
@@ -1,37 +1,35 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { generateCacheTag } from "../../shared-FEQznZ-6.mjs";
|
|
2
|
+
import { httpBatchLink, httpLink } from "@trpc/client";
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
//#region src/app-dir/links/nextHttp.ts
|
|
5
5
|
function experimental_nextHttpLink(opts) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
});
|
|
32
|
-
return link(runtime)(ctx);
|
|
33
|
-
};
|
|
34
|
-
};
|
|
6
|
+
return (runtime) => {
|
|
7
|
+
return (ctx) => {
|
|
8
|
+
const { path, input, context } = ctx.op;
|
|
9
|
+
const cacheTag = generateCacheTag(path, input);
|
|
10
|
+
const requestRevalidate = typeof context["revalidate"] === "number" || context["revalidate"] === false ? context["revalidate"] : void 0;
|
|
11
|
+
const revalidate = requestRevalidate ?? opts.revalidate ?? false;
|
|
12
|
+
const _fetch = (url, fetchOpts) => {
|
|
13
|
+
return fetch(url, {
|
|
14
|
+
...fetchOpts,
|
|
15
|
+
next: {
|
|
16
|
+
revalidate,
|
|
17
|
+
tags: [cacheTag]
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
const link = opts.batch ? httpBatchLink({
|
|
22
|
+
...opts,
|
|
23
|
+
fetch: _fetch
|
|
24
|
+
}) : httpLink({
|
|
25
|
+
...opts,
|
|
26
|
+
fetch: _fetch
|
|
27
|
+
});
|
|
28
|
+
return link(runtime)(ctx);
|
|
29
|
+
};
|
|
30
|
+
};
|
|
35
31
|
}
|
|
36
32
|
|
|
33
|
+
//#endregion
|
|
37
34
|
export { experimental_nextHttpLink };
|
|
35
|
+
//# sourceMappingURL=nextHttp.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nextHttp.mjs","names":["opts:\n | NextLinkSingleOptions<TRouter['_def']['_config']['$types']>\n | NextLinkBatchOptions<TRouter['_def']['_config']['$types']>","_fetch: NonNullable<HTTPLinkOptions<AnyRootTypes>['fetch']>"],"sources":["../../../src/app-dir/links/nextHttp.ts"],"sourcesContent":["import type {\n HTTPBatchLinkOptions,\n HTTPLinkOptions,\n TRPCLink,\n} from '@trpc/client';\nimport { httpBatchLink, httpLink } from '@trpc/client';\nimport type {\n AnyRootTypes,\n AnyRouter,\n} from '@trpc/server/unstable-core-do-not-import';\nimport { generateCacheTag } from '../shared';\n\ninterface NextLinkBaseOptions {\n revalidate?: number | false;\n batch?: boolean;\n}\n\ntype NextLinkSingleOptions<TRoot extends AnyRootTypes> = NextLinkBaseOptions &\n Omit<HTTPLinkOptions<TRoot>, 'fetch'> & {\n batch?: false;\n };\n\ntype NextLinkBatchOptions<TRoot extends AnyRootTypes> = NextLinkBaseOptions &\n Omit<HTTPBatchLinkOptions<TRoot>, 'fetch'> & {\n batch: true;\n };\n\n// ts-prune-ignore-next\nexport function experimental_nextHttpLink<TRouter extends AnyRouter>(\n opts:\n | NextLinkSingleOptions<TRouter['_def']['_config']['$types']>\n | NextLinkBatchOptions<TRouter['_def']['_config']['$types']>,\n): TRPCLink<TRouter> {\n return (runtime) => {\n return (ctx) => {\n const { path, input, context } = ctx.op;\n const cacheTag = generateCacheTag(path, input);\n\n // Let per-request revalidate override global revalidate\n const requestRevalidate =\n typeof context['revalidate'] === 'number' ||\n context['revalidate'] === false\n ? context['revalidate']\n : undefined;\n\n const revalidate = requestRevalidate ?? opts.revalidate ?? false;\n\n const _fetch: NonNullable<HTTPLinkOptions<AnyRootTypes>['fetch']> = (\n url,\n fetchOpts,\n ) => {\n return fetch(url, {\n ...fetchOpts,\n // cache: 'no-cache',\n next: {\n revalidate,\n tags: [cacheTag],\n },\n });\n };\n const link = opts.batch\n ? httpBatchLink({\n ...(opts as any),\n fetch: _fetch,\n })\n : httpLink({\n ...(opts as any),\n fetch: _fetch,\n });\n\n return link(runtime)(ctx);\n };\n };\n}\n"],"mappings":";;;;AA4BA,SAAgB,0BACdA,MAGmB;AACnB,QAAO,CAAC,YAAY;AAClB,SAAO,CAAC,QAAQ;GACd,MAAM,EAAE,MAAM,OAAO,SAAS,GAAG,IAAI;GACrC,MAAM,WAAW,iBAAiB,MAAM,MAAM;GAG9C,MAAM,2BACG,QAAQ,kBAAkB,YACjC,QAAQ,kBAAkB,QACtB,QAAQ;GAGd,MAAM,aAAa,qBAAqB,KAAK,cAAc;GAE3D,MAAMC,SAA8D,CAClE,KACA,cACG;AACH,WAAO,MAAM,KAAK;KAChB,GAAG;KAEH,MAAM;MACJ;MACA,MAAM,CAAC,QAAS;KACjB;IACF,EAAC;GACH;GACD,MAAM,OAAO,KAAK,QACd,cAAc;IACZ,GAAI;IACJ,OAAO;GACR,EAAC,GACF,SAAS;IACP,GAAI;IACJ,OAAO;GACR,EAAC;AAEN,UAAO,KAAK,QAAQ,CAAC,IAAI;EAC1B;CACF;AACF"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
const require_chunk = require('../chunk-CUT6urMc.cjs');
|
|
2
|
+
const require_shared = require('../shared-C9SS-IYg.cjs');
|
|
3
|
+
const react = require_chunk.__toESM(require("react"));
|
|
4
|
+
const __trpc_server_unstable_core_do_not_import = require_chunk.__toESM(require("@trpc/server/unstable-core-do-not-import"));
|
|
5
|
+
const __trpc_client = require_chunk.__toESM(require("@trpc/client"));
|
|
6
|
+
const __trpc_server_adapters_next_app_dir = require_chunk.__toESM(require("@trpc/server/adapters/next-app-dir"));
|
|
7
|
+
const next_cache = require_chunk.__toESM(require("next/cache"));
|
|
8
|
+
|
|
9
|
+
//#region src/app-dir/server.ts
|
|
10
|
+
function experimental_createTRPCNextAppDirServer(opts) {
|
|
11
|
+
const getClient = (0, react.cache)(() => {
|
|
12
|
+
const config = opts.config();
|
|
13
|
+
return (0, __trpc_client.createTRPCUntypedClient)(config);
|
|
14
|
+
});
|
|
15
|
+
return (0, __trpc_server_unstable_core_do_not_import.createRecursiveProxy)((callOpts) => {
|
|
16
|
+
const client = getClient();
|
|
17
|
+
const pathCopy = [...callOpts.path];
|
|
18
|
+
const action = pathCopy.pop();
|
|
19
|
+
const procedurePath = pathCopy.join(".");
|
|
20
|
+
const procedureType = (0, __trpc_client.clientCallTypeToProcedureType)(action);
|
|
21
|
+
const cacheTag = require_shared.generateCacheTag(procedurePath, callOpts.args[0]);
|
|
22
|
+
if (action === "revalidate") {
|
|
23
|
+
(0, next_cache.revalidateTag)(cacheTag);
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
return client[procedureType](procedurePath, ...callOpts.args);
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
function experimental_createServerActionHandler(t, opts) {
|
|
30
|
+
const config = t._config;
|
|
31
|
+
const { normalizeFormData = true, createContext, rethrowNextErrors: shouldRethrowNextErrors = true } = opts;
|
|
32
|
+
const transformer = config.transformer;
|
|
33
|
+
return function createServerAction(proc) {
|
|
34
|
+
return async function actionHandler(rawInput) {
|
|
35
|
+
let ctx = void 0;
|
|
36
|
+
try {
|
|
37
|
+
ctx = await createContext?.() ?? {};
|
|
38
|
+
if (normalizeFormData && require_shared.isFormData(rawInput)) try {
|
|
39
|
+
rawInput = (0, __trpc_server_unstable_core_do_not_import.formDataToObject)(rawInput);
|
|
40
|
+
} catch {
|
|
41
|
+
throw new __trpc_server_unstable_core_do_not_import.TRPCError({
|
|
42
|
+
code: "INTERNAL_SERVER_ERROR",
|
|
43
|
+
message: "Failed to convert FormData to an object"
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
else if (rawInput && !require_shared.isFormData(rawInput)) rawInput = transformer.input.deserialize(rawInput);
|
|
47
|
+
const data = proc._def.experimental_caller ? await proc(rawInput) : await proc({
|
|
48
|
+
input: void 0,
|
|
49
|
+
ctx,
|
|
50
|
+
path: "",
|
|
51
|
+
getRawInput: async () => rawInput,
|
|
52
|
+
type: proc._def.type,
|
|
53
|
+
signal: void 0
|
|
54
|
+
});
|
|
55
|
+
const transformedJSON = (0, __trpc_server_unstable_core_do_not_import.transformTRPCResponse)(config, { result: { data } });
|
|
56
|
+
return transformedJSON;
|
|
57
|
+
} catch (cause) {
|
|
58
|
+
const error = (0, __trpc_server_unstable_core_do_not_import.getTRPCErrorFromUnknown)(cause);
|
|
59
|
+
opts.onError?.({
|
|
60
|
+
ctx,
|
|
61
|
+
error,
|
|
62
|
+
input: rawInput,
|
|
63
|
+
path: "",
|
|
64
|
+
type: proc._def.type
|
|
65
|
+
});
|
|
66
|
+
if (shouldRethrowNextErrors) (0, __trpc_server_adapters_next_app_dir.rethrowNextErrors)(error);
|
|
67
|
+
const shape = (0, __trpc_server_unstable_core_do_not_import.getErrorShape)({
|
|
68
|
+
config,
|
|
69
|
+
ctx,
|
|
70
|
+
error,
|
|
71
|
+
input: rawInput,
|
|
72
|
+
path: "",
|
|
73
|
+
type: proc._def.type
|
|
74
|
+
});
|
|
75
|
+
return (0, __trpc_server_unstable_core_do_not_import.transformTRPCResponse)(t._config, { error: shape });
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
async function experimental_revalidateEndpoint(req) {
|
|
81
|
+
const { cacheTag } = await req.json();
|
|
82
|
+
if (typeof cacheTag !== "string") return new Response(JSON.stringify({
|
|
83
|
+
revalidated: false,
|
|
84
|
+
error: "cacheTag must be a string"
|
|
85
|
+
}), { status: 400 });
|
|
86
|
+
(0, next_cache.revalidateTag)(cacheTag);
|
|
87
|
+
return new Response(JSON.stringify({
|
|
88
|
+
revalidated: true,
|
|
89
|
+
now: Date.now()
|
|
90
|
+
}), { status: 200 });
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
//#endregion
|
|
94
|
+
exports.experimental_createServerActionHandler = experimental_createServerActionHandler;
|
|
95
|
+
exports.experimental_createTRPCNextAppDirServer = experimental_createTRPCNextAppDirServer;
|
|
96
|
+
exports.experimental_revalidateEndpoint = experimental_revalidateEndpoint;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { ActionHandlerDef, TRPCActionHandler, experimental_createServerActionHandler, experimental_createTRPCNextAppDirServer, experimental_revalidateEndpoint } from "../server.d-DLnegS7F.cjs";
|
|
2
|
+
export { ActionHandlerDef, TRPCActionHandler, experimental_createServerActionHandler, experimental_createTRPCNextAppDirServer, experimental_revalidateEndpoint };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { ActionHandlerDef, TRPCActionHandler, experimental_createServerActionHandler, experimental_createTRPCNextAppDirServer, experimental_revalidateEndpoint } from "../server.d-BXv5jwlB.mjs";
|
|
2
|
+
export { ActionHandlerDef, TRPCActionHandler, experimental_createServerActionHandler, experimental_createTRPCNextAppDirServer, experimental_revalidateEndpoint };
|
package/dist/app-dir/server.mjs
CHANGED
|
@@ -1,118 +1,94 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { createRecursiveProxy, formDataToObject,
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
1
|
+
import { generateCacheTag, isFormData } from "../shared-FEQznZ-6.mjs";
|
|
2
|
+
import { cache } from "react";
|
|
3
|
+
import { TRPCError, createRecursiveProxy, formDataToObject, getErrorShape, getTRPCErrorFromUnknown, transformTRPCResponse } from "@trpc/server/unstable-core-do-not-import";
|
|
4
|
+
import { clientCallTypeToProcedureType, createTRPCUntypedClient } from "@trpc/client";
|
|
5
|
+
import { rethrowNextErrors } from "@trpc/server/adapters/next-app-dir";
|
|
6
|
+
import { revalidateTag } from "next/cache";
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
// ts-prune-ignore-next
|
|
8
|
+
//#region src/app-dir/server.ts
|
|
10
9
|
function experimental_createTRPCNextAppDirServer(opts) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
return client[procedureType](procedurePath, ...callOpts.args);
|
|
31
|
-
});
|
|
10
|
+
const getClient = cache(() => {
|
|
11
|
+
const config = opts.config();
|
|
12
|
+
return createTRPCUntypedClient(config);
|
|
13
|
+
});
|
|
14
|
+
return createRecursiveProxy((callOpts) => {
|
|
15
|
+
const client = getClient();
|
|
16
|
+
const pathCopy = [...callOpts.path];
|
|
17
|
+
const action = pathCopy.pop();
|
|
18
|
+
const procedurePath = pathCopy.join(".");
|
|
19
|
+
const procedureType = clientCallTypeToProcedureType(action);
|
|
20
|
+
const cacheTag = generateCacheTag(procedurePath, callOpts.args[0]);
|
|
21
|
+
if (action === "revalidate") {
|
|
22
|
+
revalidateTag(cacheTag);
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
return client[procedureType](procedurePath, ...callOpts.args);
|
|
26
|
+
});
|
|
32
27
|
}
|
|
33
28
|
function experimental_createServerActionHandler(t, opts) {
|
|
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
|
-
const shape = getErrorShape({
|
|
84
|
-
config,
|
|
85
|
-
ctx,
|
|
86
|
-
error,
|
|
87
|
-
input: rawInput,
|
|
88
|
-
path: '',
|
|
89
|
-
type: proc._def.type
|
|
90
|
-
});
|
|
91
|
-
return transformTRPCResponse(t._config, {
|
|
92
|
-
error: shape
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
};
|
|
96
|
-
};
|
|
29
|
+
const config = t._config;
|
|
30
|
+
const { normalizeFormData = true, createContext, rethrowNextErrors: shouldRethrowNextErrors = true } = opts;
|
|
31
|
+
const transformer = config.transformer;
|
|
32
|
+
return function createServerAction(proc) {
|
|
33
|
+
return async function actionHandler(rawInput) {
|
|
34
|
+
let ctx = void 0;
|
|
35
|
+
try {
|
|
36
|
+
ctx = await createContext?.() ?? {};
|
|
37
|
+
if (normalizeFormData && isFormData(rawInput)) try {
|
|
38
|
+
rawInput = formDataToObject(rawInput);
|
|
39
|
+
} catch {
|
|
40
|
+
throw new TRPCError({
|
|
41
|
+
code: "INTERNAL_SERVER_ERROR",
|
|
42
|
+
message: "Failed to convert FormData to an object"
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
else if (rawInput && !isFormData(rawInput)) rawInput = transformer.input.deserialize(rawInput);
|
|
46
|
+
const data = proc._def.experimental_caller ? await proc(rawInput) : await proc({
|
|
47
|
+
input: void 0,
|
|
48
|
+
ctx,
|
|
49
|
+
path: "",
|
|
50
|
+
getRawInput: async () => rawInput,
|
|
51
|
+
type: proc._def.type,
|
|
52
|
+
signal: void 0
|
|
53
|
+
});
|
|
54
|
+
const transformedJSON = transformTRPCResponse(config, { result: { data } });
|
|
55
|
+
return transformedJSON;
|
|
56
|
+
} catch (cause) {
|
|
57
|
+
const error = getTRPCErrorFromUnknown(cause);
|
|
58
|
+
opts.onError?.({
|
|
59
|
+
ctx,
|
|
60
|
+
error,
|
|
61
|
+
input: rawInput,
|
|
62
|
+
path: "",
|
|
63
|
+
type: proc._def.type
|
|
64
|
+
});
|
|
65
|
+
if (shouldRethrowNextErrors) rethrowNextErrors(error);
|
|
66
|
+
const shape = getErrorShape({
|
|
67
|
+
config,
|
|
68
|
+
ctx,
|
|
69
|
+
error,
|
|
70
|
+
input: rawInput,
|
|
71
|
+
path: "",
|
|
72
|
+
type: proc._def.type
|
|
73
|
+
});
|
|
74
|
+
return transformTRPCResponse(t._config, { error: shape });
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
};
|
|
97
78
|
}
|
|
98
|
-
// ts-prune-ignore-next
|
|
99
79
|
async function experimental_revalidateEndpoint(req) {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
return new Response(JSON.stringify({
|
|
111
|
-
revalidated: true,
|
|
112
|
-
now: Date.now()
|
|
113
|
-
}), {
|
|
114
|
-
status: 200
|
|
115
|
-
});
|
|
80
|
+
const { cacheTag } = await req.json();
|
|
81
|
+
if (typeof cacheTag !== "string") return new Response(JSON.stringify({
|
|
82
|
+
revalidated: false,
|
|
83
|
+
error: "cacheTag must be a string"
|
|
84
|
+
}), { status: 400 });
|
|
85
|
+
revalidateTag(cacheTag);
|
|
86
|
+
return new Response(JSON.stringify({
|
|
87
|
+
revalidated: true,
|
|
88
|
+
now: Date.now()
|
|
89
|
+
}), { status: 200 });
|
|
116
90
|
}
|
|
117
91
|
|
|
92
|
+
//#endregion
|
|
118
93
|
export { experimental_createServerActionHandler, experimental_createTRPCNextAppDirServer, experimental_revalidateEndpoint };
|
|
94
|
+
//# sourceMappingURL=server.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.mjs","names":["opts: CreateTRPCNextAppRouterOptions<TRouter>","t: TInstance","opts: CreateContextCallback<\n TInstance['_config']['$types']['ctx'],\n () => MaybePromise<TInstance['_config']['$types']['ctx']>\n > & {\n /**\n * Transform form data to a `Record` before passing it to the procedure\n * @default true\n */\n normalizeFormData?: boolean;\n /**\n * Called when an error occurs in the handler\n */\n onError?: (\n opts: ErrorHandlerOptions<TInstance['_config']['$types']['ctx']>,\n ) => void;\n\n /**\n * Rethrow errors that should be handled by Next.js\n * @default true\n */\n rethrowNextErrors?: boolean;\n }","proc: TProc","rawInput: FormData | inferProcedureInput<TProc>","ctx: TInstance['_config']['$types']['ctx'] | undefined","req: Request"],"sources":["../../src/app-dir/server.ts"],"sourcesContent":["/// <reference types=\"next\" />\nimport {\n clientCallTypeToProcedureType,\n createTRPCUntypedClient,\n} from '@trpc/client';\nimport type { CreateContextCallback } from '@trpc/server';\nimport { rethrowNextErrors } from '@trpc/server/adapters/next-app-dir';\nimport type {\n AnyProcedure,\n AnyRootTypes,\n AnyRouter,\n ErrorHandlerOptions,\n inferClientTypes,\n inferProcedureInput,\n MaybePromise,\n RootConfig,\n Simplify,\n TRPCResponse,\n} from '@trpc/server/unstable-core-do-not-import';\nimport {\n createRecursiveProxy,\n formDataToObject,\n getErrorShape,\n getTRPCErrorFromUnknown,\n transformTRPCResponse,\n TRPCError,\n} from '@trpc/server/unstable-core-do-not-import';\nimport { revalidateTag } from 'next/cache';\nimport { cache } from 'react';\nimport type {\n ActionHandlerDef,\n CreateTRPCNextAppRouterOptions,\n inferActionDef,\n} from './shared';\nimport { generateCacheTag, isFormData } from './shared';\nimport type { NextAppDirDecorateRouterRecord } from './types';\n\nexport type { ActionHandlerDef };\n\n// ts-prune-ignore-next\nexport function experimental_createTRPCNextAppDirServer<\n TRouter extends AnyRouter,\n>(opts: CreateTRPCNextAppRouterOptions<TRouter>) {\n const getClient = cache(() => {\n const config = opts.config();\n return createTRPCUntypedClient(config);\n });\n\n return createRecursiveProxy<\n NextAppDirDecorateRouterRecord<\n TRouter['_def']['_config']['$types'],\n TRouter['_def']['record']\n >\n >((callOpts) => {\n // lazily initialize client\n const client = getClient();\n\n const pathCopy = [...callOpts.path];\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const action = pathCopy.pop()!;\n const procedurePath = pathCopy.join('.');\n const procedureType = clientCallTypeToProcedureType(action);\n const cacheTag = generateCacheTag(procedurePath, callOpts.args[0]);\n\n if (action === 'revalidate') {\n revalidateTag(cacheTag);\n return;\n }\n\n return (client[procedureType] as any)(procedurePath, ...callOpts.args);\n });\n}\n\n/**\n * @internal\n */\nexport type TRPCActionHandler<TDef extends ActionHandlerDef> = (\n input: FormData | TDef['input'],\n) => Promise<TRPCResponse<TDef['output'], TDef['errorShape']>>;\n\nexport function experimental_createServerActionHandler<\n TInstance extends {\n _config: RootConfig<AnyRootTypes>;\n },\n>(\n t: TInstance,\n opts: CreateContextCallback<\n TInstance['_config']['$types']['ctx'],\n () => MaybePromise<TInstance['_config']['$types']['ctx']>\n > & {\n /**\n * Transform form data to a `Record` before passing it to the procedure\n * @default true\n */\n normalizeFormData?: boolean;\n /**\n * Called when an error occurs in the handler\n */\n onError?: (\n opts: ErrorHandlerOptions<TInstance['_config']['$types']['ctx']>,\n ) => void;\n\n /**\n * Rethrow errors that should be handled by Next.js\n * @default true\n */\n rethrowNextErrors?: boolean;\n },\n) {\n const config = t._config;\n const {\n normalizeFormData = true,\n createContext,\n rethrowNextErrors: shouldRethrowNextErrors = true,\n } = opts;\n\n const transformer = config.transformer;\n\n // TODO allow this to take a `TRouter` in addition to a `AnyProcedure`\n return function createServerAction<TProc extends AnyProcedure>(\n proc: TProc,\n ): TRPCActionHandler<\n Simplify<inferActionDef<inferClientTypes<TInstance>, TProc>>\n > {\n return async function actionHandler(\n rawInput: FormData | inferProcedureInput<TProc>,\n ) {\n let ctx: TInstance['_config']['$types']['ctx'] | undefined = undefined;\n try {\n ctx = (await createContext?.()) ?? {};\n if (normalizeFormData && isFormData(rawInput)) {\n // Normalizes FormData so we can use `z.object({})` etc on the server\n try {\n rawInput = formDataToObject(rawInput);\n } catch {\n throw new TRPCError({\n code: 'INTERNAL_SERVER_ERROR',\n message: 'Failed to convert FormData to an object',\n });\n }\n } else if (rawInput && !isFormData(rawInput)) {\n rawInput = transformer.input.deserialize(rawInput);\n }\n\n const data = proc._def.experimental_caller\n ? await proc(rawInput as any)\n : await proc({\n input: undefined,\n ctx,\n path: '',\n getRawInput: async () => rawInput,\n type: proc._def.type,\n // is it possible to get the AbortSignal from the request?\n signal: undefined,\n });\n\n const transformedJSON = transformTRPCResponse(config, {\n result: {\n data,\n },\n });\n return transformedJSON;\n } catch (cause) {\n const error = getTRPCErrorFromUnknown(cause);\n\n opts.onError?.({\n ctx,\n error,\n input: rawInput,\n path: '',\n type: proc._def.type,\n });\n\n if (shouldRethrowNextErrors) {\n rethrowNextErrors(error);\n }\n\n const shape = getErrorShape({\n config,\n ctx,\n error,\n input: rawInput,\n path: '',\n type: proc._def.type,\n });\n\n return transformTRPCResponse(t._config, {\n error: shape,\n });\n }\n } as TRPCActionHandler<\n inferActionDef<TInstance['_config']['$types'], TProc>\n >;\n };\n}\n\n// ts-prune-ignore-next\nexport async function experimental_revalidateEndpoint(req: Request) {\n const { cacheTag } = await req.json();\n\n if (typeof cacheTag !== 'string') {\n return new Response(\n JSON.stringify({\n revalidated: false,\n error: 'cacheTag must be a string',\n }),\n { status: 400 },\n );\n }\n\n revalidateTag(cacheTag);\n return new Response(JSON.stringify({ revalidated: true, now: Date.now() }), {\n status: 200,\n });\n}\n"],"mappings":";;;;;;;;AAwCA,SAAgB,wCAEdA,MAA+C;CAC/C,MAAM,YAAY,MAAM,MAAM;EAC5B,MAAM,SAAS,KAAK,QAAQ;AAC5B,SAAO,wBAAwB,OAAO;CACvC,EAAC;AAEF,QAAO,qBAKL,CAAC,aAAa;EAEd,MAAM,SAAS,WAAW;EAE1B,MAAM,WAAW,CAAC,GAAG,SAAS,IAAK;EAEnC,MAAM,SAAS,SAAS,KAAK;EAC7B,MAAM,gBAAgB,SAAS,KAAK,IAAI;EACxC,MAAM,gBAAgB,8BAA8B,OAAO;EAC3D,MAAM,WAAW,iBAAiB,eAAe,SAAS,KAAK,GAAG;AAElE,MAAI,WAAW,cAAc;AAC3B,iBAAc,SAAS;AACvB;EACD;AAED,SAAO,AAAC,OAAO,eAAuB,eAAe,GAAG,SAAS,KAAK;CACvE,EAAC;AACH;AASD,SAAgB,uCAKdC,GACAC,MAsBA;CACA,MAAM,SAAS,EAAE;CACjB,MAAM,EACJ,oBAAoB,MACpB,eACA,mBAAmB,0BAA0B,MAC9C,GAAG;CAEJ,MAAM,cAAc,OAAO;AAG3B,QAAO,SAAS,mBACdC,MAGA;AACA,SAAO,eAAe,cACpBC,UACA;GACA,IAAIC;AACJ,OAAI;AACF,UAAO,MAAM,iBAAiB,IAAK,CAAE;AACrC,QAAI,qBAAqB,WAAW,SAAS,CAE3C,KAAI;AACF,gBAAW,iBAAiB,SAAS;IACtC,QAAO;AACN,WAAM,IAAI,UAAU;MAClB,MAAM;MACN,SAAS;KACV;IACF;aACQ,aAAa,WAAW,SAAS,CAC1C,YAAW,YAAY,MAAM,YAAY,SAAS;IAGpD,MAAM,OAAO,KAAK,KAAK,sBACnB,MAAM,KAAK,SAAgB,GAC3B,MAAM,KAAK;KACT;KACA;KACA,MAAM;KACN,aAAa,YAAY;KACzB,MAAM,KAAK,KAAK;KAEhB;IACD,EAAC;IAEN,MAAM,kBAAkB,sBAAsB,QAAQ,EACpD,QAAQ,EACN,KACD,EACF,EAAC;AACF,WAAO;GACR,SAAQ,OAAO;IACd,MAAM,QAAQ,wBAAwB,MAAM;AAE5C,SAAK,UAAU;KACb;KACA;KACA,OAAO;KACP,MAAM;KACN,MAAM,KAAK,KAAK;IACjB,EAAC;AAEF,QAAI,wBACF,mBAAkB,MAAM;IAG1B,MAAM,QAAQ,cAAc;KAC1B;KACA;KACA;KACA,OAAO;KACP,MAAM;KACN,MAAM,KAAK,KAAK;IACjB,EAAC;AAEF,WAAO,sBAAsB,EAAE,SAAS,EACtC,OAAO,MACR,EAAC;GACH;EACF;CAGF;AACF;AAGD,eAAsB,gCAAgCC,KAAc;CAClE,MAAM,EAAE,UAAU,GAAG,MAAM,IAAI,MAAM;AAErC,YAAW,aAAa,SACtB,QAAO,IAAI,SACT,KAAK,UAAU;EACb,aAAa;EACb,OAAO;CACR,EAAC,EACF,EAAE,QAAQ,IAAK;AAInB,eAAc,SAAS;AACvB,QAAO,IAAI,SAAS,KAAK,UAAU;EAAE,aAAa;EAAM,KAAK,KAAK,KAAK;CAAE,EAAC,EAAE,EAC1E,QAAQ,IACT;AACF"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
//#region rolldown:runtime
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
10
|
+
key = keys[i];
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
12
|
+
get: ((k) => from[k]).bind(null, key),
|
|
13
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
19
|
+
value: mod,
|
|
20
|
+
enumerable: true
|
|
21
|
+
}) : target, mod));
|
|
22
|
+
|
|
23
|
+
//#endregion
|
|
24
|
+
|
|
25
|
+
Object.defineProperty(exports, '__toESM', {
|
|
26
|
+
enumerable: true,
|
|
27
|
+
get: function () {
|
|
28
|
+
return __toESM;
|
|
29
|
+
}
|
|
30
|
+
});
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
const require_chunk = require('./chunk-CUT6urMc.cjs');
|
|
2
|
+
const __tanstack_react_query = require_chunk.__toESM(require("@tanstack/react-query"));
|
|
3
|
+
const __trpc_client_unstable_internals = require_chunk.__toESM(require("@trpc/client/unstable-internals"));
|
|
4
|
+
const __trpc_react_query_shared = require_chunk.__toESM(require("@trpc/react-query/shared"));
|
|
5
|
+
const react = require_chunk.__toESM(require("react"));
|
|
6
|
+
const react_jsx_runtime = require_chunk.__toESM(require("react/jsx-runtime"));
|
|
7
|
+
const __trpc_server_unstable_core_do_not_import = require_chunk.__toESM(require("@trpc/server/unstable-core-do-not-import"));
|
|
8
|
+
|
|
9
|
+
//#region src/withTRPC.tsx
|
|
10
|
+
function withTRPC(opts) {
|
|
11
|
+
const { config: getClientConfig } = opts;
|
|
12
|
+
const transformer = (0, __trpc_client_unstable_internals.getTransformer)(opts.transformer);
|
|
13
|
+
return (AppOrPage) => {
|
|
14
|
+
const trpc = (0, __trpc_react_query_shared.createRootHooks)(opts);
|
|
15
|
+
const WithTRPC = (props) => {
|
|
16
|
+
const [prepassProps] = (0, react.useState)(() => {
|
|
17
|
+
if (props.trpc) return props.trpc;
|
|
18
|
+
const config = getClientConfig({});
|
|
19
|
+
const queryClient$1 = (0, __trpc_react_query_shared.getQueryClient)(config);
|
|
20
|
+
const trpcClient$1 = trpc.createClient(config);
|
|
21
|
+
return {
|
|
22
|
+
abortOnUnmount: config.abortOnUnmount,
|
|
23
|
+
queryClient: queryClient$1,
|
|
24
|
+
trpcClient: trpcClient$1,
|
|
25
|
+
ssrState: opts.ssr ? "mounting" : false,
|
|
26
|
+
ssrContext: null
|
|
27
|
+
};
|
|
28
|
+
});
|
|
29
|
+
const { queryClient, trpcClient, ssrState, ssrContext } = prepassProps;
|
|
30
|
+
const trpcState = props.pageProps?.trpcState;
|
|
31
|
+
const hydratedState = react.default.useMemo(() => {
|
|
32
|
+
if (!trpcState) return trpcState;
|
|
33
|
+
return transformer.input.deserialize(trpcState);
|
|
34
|
+
}, [trpcState]);
|
|
35
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(trpc.Provider, {
|
|
36
|
+
abortOnUnmount: prepassProps.abortOnUnmount ?? false,
|
|
37
|
+
client: trpcClient,
|
|
38
|
+
queryClient,
|
|
39
|
+
ssrState,
|
|
40
|
+
ssrContext,
|
|
41
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__tanstack_react_query.QueryClientProvider, {
|
|
42
|
+
client: queryClient,
|
|
43
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__tanstack_react_query.HydrationBoundary, {
|
|
44
|
+
state: hydratedState,
|
|
45
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(AppOrPage, { ...props })
|
|
46
|
+
})
|
|
47
|
+
})
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
if (opts.ssr) opts.ssrPrepass({
|
|
51
|
+
parent: opts,
|
|
52
|
+
AppOrPage,
|
|
53
|
+
WithTRPC
|
|
54
|
+
});
|
|
55
|
+
else if (AppOrPage.getInitialProps) WithTRPC.getInitialProps = async (appOrPageCtx) => {
|
|
56
|
+
const isApp = !!appOrPageCtx.Component;
|
|
57
|
+
let pageProps = {};
|
|
58
|
+
const originalProps = await AppOrPage.getInitialProps(appOrPageCtx);
|
|
59
|
+
const originalPageProps = isApp ? originalProps.pageProps ?? {} : originalProps;
|
|
60
|
+
pageProps = {
|
|
61
|
+
...originalPageProps,
|
|
62
|
+
...pageProps
|
|
63
|
+
};
|
|
64
|
+
const getAppTreeProps = (props) => isApp ? { pageProps: props } : props;
|
|
65
|
+
return getAppTreeProps(pageProps);
|
|
66
|
+
};
|
|
67
|
+
const displayName = AppOrPage.displayName ?? AppOrPage.name ?? "Component";
|
|
68
|
+
WithTRPC.displayName = `withTRPC(${displayName})`;
|
|
69
|
+
return WithTRPC;
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
//#endregion
|
|
74
|
+
//#region src/createTRPCNext.tsx
|
|
75
|
+
function createTRPCNext(opts) {
|
|
76
|
+
const hooks = (0, __trpc_react_query_shared.createRootHooks)(opts);
|
|
77
|
+
const _withTRPC = withTRPC(opts);
|
|
78
|
+
const proxy = (0, __trpc_react_query_shared.createReactDecoration)(hooks);
|
|
79
|
+
return (0, __trpc_server_unstable_core_do_not_import.createFlatProxy)((key) => {
|
|
80
|
+
if (key === "useContext" || key === "useUtils") return () => {
|
|
81
|
+
const context = hooks.useUtils();
|
|
82
|
+
return (0, react.useMemo)(() => {
|
|
83
|
+
return (0, __trpc_react_query_shared.createReactQueryUtils)(context);
|
|
84
|
+
}, [context]);
|
|
85
|
+
};
|
|
86
|
+
if (key === "useQueries") return hooks.useQueries;
|
|
87
|
+
if (key === "useSuspenseQueries") return hooks.useSuspenseQueries;
|
|
88
|
+
if (key === "withTRPC") return _withTRPC;
|
|
89
|
+
return proxy[key];
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
//#endregion
|
|
94
|
+
exports.createTRPCNext = createTRPCNext;
|
|
95
|
+
exports.withTRPC = withTRPC;
|