@trpc/next 11.0.0-next.91 → 11.0.0-rc.329
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/README.md +5 -5
- package/dist/app-dir/client.d.ts +3 -3
- package/dist/app-dir/client.d.ts.map +1 -1
- package/dist/app-dir/client.js +5 -105
- package/dist/app-dir/client.mjs +4 -102
- package/dist/app-dir/create-action-hook.d.ts +18 -6
- package/dist/app-dir/create-action-hook.d.ts.map +1 -1
- package/dist/app-dir/create-action-hook.js +108 -0
- package/dist/app-dir/create-action-hook.mjs +105 -0
- package/dist/app-dir/formDataToObject.js +34 -0
- package/dist/app-dir/formDataToObject.mjs +32 -0
- package/dist/app-dir/links/nextCache.d.ts +4 -3
- package/dist/app-dir/links/nextCache.d.ts.map +1 -1
- package/dist/app-dir/links/nextCache.js +9 -10
- package/dist/app-dir/links/nextCache.mjs +8 -7
- package/dist/app-dir/links/nextHttp.d.ts +11 -5
- package/dist/app-dir/links/nextHttp.d.ts.map +1 -1
- package/dist/app-dir/links/nextHttp.js +22 -23
- package/dist/app-dir/links/nextHttp.mjs +22 -21
- package/dist/app-dir/server.d.ts +19 -12
- package/dist/app-dir/server.d.ts.map +1 -1
- package/dist/app-dir/server.js +39 -55
- package/dist/app-dir/server.mjs +29 -43
- package/dist/app-dir/shared.d.ts +19 -13
- package/dist/app-dir/shared.d.ts.map +1 -1
- package/dist/{shared-e49b9cdc.js → app-dir/shared.js} +1 -1
- package/dist/{shared-f6996341.mjs → app-dir/shared.mjs} +2 -2
- package/dist/app-dir/types.d.ts +23 -11
- package/dist/app-dir/types.d.ts.map +1 -1
- package/dist/bundle-analysis.json +56 -44
- package/dist/createTRPCNext.d.ts +10 -8
- package/dist/createTRPCNext.d.ts.map +1 -1
- package/dist/createTRPCNext.js +38 -0
- package/dist/createTRPCNext.mjs +36 -0
- package/dist/index.js +4 -190
- package/dist/index.mjs +2 -185
- package/dist/ssrPrepass.d.ts +3 -0
- package/dist/ssrPrepass.d.ts.map +1 -0
- package/dist/ssrPrepass.js +139 -0
- package/dist/ssrPrepass.mjs +137 -0
- package/dist/withTRPC.d.ts +41 -13
- package/dist/withTRPC.d.ts.map +1 -1
- package/dist/withTRPC.js +86 -0
- package/dist/withTRPC.mjs +84 -0
- package/package.json +36 -25
- package/src/app-dir/client.ts +4 -4
- package/src/app-dir/create-action-hook.tsx +49 -19
- package/src/app-dir/links/nextCache.ts +20 -8
- package/src/app-dir/links/nextHttp.ts +50 -30
- package/src/app-dir/server.ts +86 -34
- package/src/app-dir/shared.ts +52 -25
- package/src/app-dir/types.ts +41 -29
- package/src/createTRPCNext.tsx +25 -16
- package/src/ssrPrepass.ts +185 -0
- package/src/withTRPC.tsx +102 -180
- package/ssrPrepass/index.d.ts +1 -0
- package/ssrPrepass/index.js +1 -0
- package/dist/shared-642894f4.js +0 -19
|
@@ -1,29 +1,28 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
3
|
var client = require('@trpc/client');
|
|
6
|
-
var
|
|
4
|
+
var unstableInternals = require('@trpc/client/unstable-internals');
|
|
7
5
|
var observable = require('@trpc/server/observable');
|
|
6
|
+
var unstableCoreDoNotImport = require('@trpc/server/unstable-core-do-not-import');
|
|
8
7
|
var cache = require('next/cache');
|
|
9
|
-
var shared = require('
|
|
10
|
-
require('@trpc/server/shared');
|
|
8
|
+
var shared = require('../shared.js');
|
|
11
9
|
|
|
12
10
|
// import "server-only";
|
|
13
11
|
// ts-prune-ignore-next
|
|
14
12
|
function experimental_nextCacheLink(opts) {
|
|
15
|
-
|
|
13
|
+
const transformer = unstableInternals.getTransformer(opts.transformer);
|
|
14
|
+
return ()=>({ op })=>observable.observable((observer)=>{
|
|
16
15
|
const { path , input , type , context } = op;
|
|
17
16
|
const cacheTag = shared.generateCacheTag(path, input);
|
|
18
17
|
// Let per-request revalidate override global revalidate
|
|
19
|
-
const requestRevalidate = typeof context
|
|
18
|
+
const requestRevalidate = typeof context['revalidate'] === 'number' || context['revalidate'] === false ? context['revalidate'] : undefined;
|
|
20
19
|
const revalidate = requestRevalidate ?? opts.revalidate ?? false;
|
|
21
20
|
const promise = opts.createContext().then(async (ctx)=>{
|
|
22
21
|
const callProc = async (_cachebuster)=>{
|
|
23
22
|
// // _cachebuster is not used by us but to make sure
|
|
24
23
|
// // that calls with different tags are properly separated
|
|
25
24
|
// // @link https://github.com/trpc/trpc/issues/4622
|
|
26
|
-
const procedureResult = await
|
|
25
|
+
const procedureResult = await unstableCoreDoNotImport.callProcedure({
|
|
27
26
|
procedures: opts.router._def.procedures,
|
|
28
27
|
path,
|
|
29
28
|
getRawInput: async ()=>input,
|
|
@@ -31,7 +30,7 @@ function experimental_nextCacheLink(opts) {
|
|
|
31
30
|
type
|
|
32
31
|
});
|
|
33
32
|
// We need to serialize cause the cache only accepts JSON
|
|
34
|
-
return
|
|
33
|
+
return transformer.input.serialize(procedureResult);
|
|
35
34
|
};
|
|
36
35
|
if (type === 'query') {
|
|
37
36
|
return cache.unstable_cache(callProc, path.split('.'), {
|
|
@@ -46,7 +45,7 @@ function experimental_nextCacheLink(opts) {
|
|
|
46
45
|
observer.error(client.TRPCClientError.from(cause));
|
|
47
46
|
});
|
|
48
47
|
promise.then((data)=>{
|
|
49
|
-
const transformedResult =
|
|
48
|
+
const transformedResult = transformer.output.deserialize(data);
|
|
50
49
|
observer.next({
|
|
51
50
|
result: {
|
|
52
51
|
data: transformedResult
|
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
import { TRPCClientError } from '@trpc/client';
|
|
2
|
-
import {
|
|
2
|
+
import { getTransformer } from '@trpc/client/unstable-internals';
|
|
3
3
|
import { observable } from '@trpc/server/observable';
|
|
4
|
+
import { callProcedure } from '@trpc/server/unstable-core-do-not-import';
|
|
4
5
|
import { unstable_cache } from 'next/cache';
|
|
5
|
-
import {
|
|
6
|
-
import '@trpc/server/shared';
|
|
6
|
+
import { generateCacheTag } from '../shared.mjs';
|
|
7
7
|
|
|
8
8
|
// import "server-only";
|
|
9
9
|
// ts-prune-ignore-next
|
|
10
10
|
function experimental_nextCacheLink(opts) {
|
|
11
|
-
|
|
11
|
+
const transformer = getTransformer(opts.transformer);
|
|
12
|
+
return ()=>({ op })=>observable((observer)=>{
|
|
12
13
|
const { path , input , type , context } = op;
|
|
13
14
|
const cacheTag = generateCacheTag(path, input);
|
|
14
15
|
// Let per-request revalidate override global revalidate
|
|
15
|
-
const requestRevalidate = typeof context
|
|
16
|
+
const requestRevalidate = typeof context['revalidate'] === 'number' || context['revalidate'] === false ? context['revalidate'] : undefined;
|
|
16
17
|
const revalidate = requestRevalidate ?? opts.revalidate ?? false;
|
|
17
18
|
const promise = opts.createContext().then(async (ctx)=>{
|
|
18
19
|
const callProc = async (_cachebuster)=>{
|
|
@@ -27,7 +28,7 @@ function experimental_nextCacheLink(opts) {
|
|
|
27
28
|
type
|
|
28
29
|
});
|
|
29
30
|
// We need to serialize cause the cache only accepts JSON
|
|
30
|
-
return
|
|
31
|
+
return transformer.input.serialize(procedureResult);
|
|
31
32
|
};
|
|
32
33
|
if (type === 'query') {
|
|
33
34
|
return unstable_cache(callProc, path.split('.'), {
|
|
@@ -42,7 +43,7 @@ function experimental_nextCacheLink(opts) {
|
|
|
42
43
|
observer.error(TRPCClientError.from(cause));
|
|
43
44
|
});
|
|
44
45
|
promise.then((data)=>{
|
|
45
|
-
const transformedResult =
|
|
46
|
+
const transformedResult = transformer.output.deserialize(data);
|
|
46
47
|
observer.next({
|
|
47
48
|
result: {
|
|
48
49
|
data: transformedResult
|
|
@@ -1,9 +1,15 @@
|
|
|
1
|
-
import { HTTPBatchLinkOptions, HTTPLinkOptions, TRPCLink } from '@trpc/client';
|
|
2
|
-
import { AnyRouter } from '@trpc/server';
|
|
3
|
-
|
|
4
|
-
batch?: TBatch;
|
|
1
|
+
import type { HTTPBatchLinkOptions, HTTPLinkOptions, TRPCLink } from '@trpc/client';
|
|
2
|
+
import type { AnyRootTypes, AnyRouter } from '@trpc/server/unstable-core-do-not-import';
|
|
3
|
+
interface NextLinkBaseOptions {
|
|
5
4
|
revalidate?: number | false;
|
|
5
|
+
batch?: boolean;
|
|
6
|
+
}
|
|
7
|
+
type NextLinkSingleOptions<TRoot extends AnyRootTypes> = NextLinkBaseOptions & Omit<HTTPLinkOptions<TRoot>, 'fetch'> & {
|
|
8
|
+
batch?: false;
|
|
6
9
|
};
|
|
7
|
-
|
|
10
|
+
type NextLinkBatchOptions<TRoot extends AnyRootTypes> = NextLinkBaseOptions & Omit<HTTPBatchLinkOptions<TRoot>, 'fetch'> & {
|
|
11
|
+
batch: true;
|
|
12
|
+
};
|
|
13
|
+
export declare function experimental_nextHttpLink<TRouter extends AnyRouter>(opts: NextLinkSingleOptions<TRouter['_def']['_config']['$types']> | NextLinkBatchOptions<TRouter['_def']['_config']['$types']>): TRPCLink<TRouter>;
|
|
8
14
|
export {};
|
|
9
15
|
//# sourceMappingURL=nextHttp.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nextHttp.d.ts","sourceRoot":"","sources":["../../../src/app-dir/links/nextHttp.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"nextHttp.d.ts","sourceRoot":"","sources":["../../../src/app-dir/links/nextHttp.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,oBAAoB,EACpB,eAAe,EACf,QAAQ,EACT,MAAM,cAAc,CAAC;AAEtB,OAAO,KAAK,EACV,YAAY,EACZ,SAAS,EACV,MAAM,0CAA0C,CAAC;AAGlD,UAAU,mBAAmB;IAC3B,UAAU,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC;IAC5B,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED,KAAK,qBAAqB,CAAC,KAAK,SAAS,YAAY,IAAI,mBAAmB,GAC1E,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC,GAAG;IACtC,KAAK,CAAC,EAAE,KAAK,CAAC;CACf,CAAC;AAEJ,KAAK,oBAAoB,CAAC,KAAK,SAAS,YAAY,IAAI,mBAAmB,GACzE,IAAI,CAAC,oBAAoB,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC,GAAG;IAC3C,KAAK,EAAE,IAAI,CAAC;CACb,CAAC;AAGJ,wBAAgB,yBAAyB,CAAC,OAAO,SAAS,SAAS,EACjE,IAAI,EACA,qBAAqB,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,CAAC,QAAQ,CAAC,CAAC,GAC3D,oBAAoB,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,CAAC,QAAQ,CAAC,CAAC,GAC7D,QAAQ,CAAC,OAAO,CAAC,CAyCnB"}
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
3
|
var client = require('@trpc/client');
|
|
6
|
-
var shared = require('
|
|
7
|
-
require('@trpc/server/shared');
|
|
4
|
+
var shared = require('../shared.js');
|
|
8
5
|
|
|
9
6
|
// ts-prune-ignore-next
|
|
10
7
|
function experimental_nextHttpLink(opts) {
|
|
@@ -13,26 +10,28 @@ function experimental_nextHttpLink(opts) {
|
|
|
13
10
|
const { path , input , context } = ctx.op;
|
|
14
11
|
const cacheTag = shared.generateCacheTag(path, input);
|
|
15
12
|
// Let per-request revalidate override global revalidate
|
|
16
|
-
const requestRevalidate = typeof context
|
|
13
|
+
const requestRevalidate = typeof context['revalidate'] === 'number' || context['revalidate'] === false ? context['revalidate'] : undefined;
|
|
17
14
|
const revalidate = requestRevalidate ?? opts.revalidate ?? false;
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
15
|
+
const _fetch = (url, fetchOpts)=>{
|
|
16
|
+
return fetch(url, {
|
|
17
|
+
...fetchOpts,
|
|
18
|
+
// cache: 'no-cache',
|
|
19
|
+
next: {
|
|
20
|
+
revalidate,
|
|
21
|
+
tags: [
|
|
22
|
+
cacheTag
|
|
23
|
+
]
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
const link = opts.batch ? client.httpBatchLink({
|
|
28
|
+
...opts,
|
|
29
|
+
fetch: _fetch
|
|
30
|
+
}) : client.httpLink({
|
|
31
|
+
...opts,
|
|
32
|
+
fetch: _fetch
|
|
33
|
+
});
|
|
34
|
+
return link(runtime)(ctx);
|
|
36
35
|
};
|
|
37
36
|
};
|
|
38
37
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { httpBatchLink, httpLink } from '@trpc/client';
|
|
2
|
-
import {
|
|
3
|
-
import '@trpc/server/shared';
|
|
2
|
+
import { generateCacheTag } from '../shared.mjs';
|
|
4
3
|
|
|
5
4
|
// ts-prune-ignore-next
|
|
6
5
|
function experimental_nextHttpLink(opts) {
|
|
@@ -9,26 +8,28 @@ function experimental_nextHttpLink(opts) {
|
|
|
9
8
|
const { path , input , context } = ctx.op;
|
|
10
9
|
const cacheTag = generateCacheTag(path, input);
|
|
11
10
|
// Let per-request revalidate override global revalidate
|
|
12
|
-
const requestRevalidate = typeof context
|
|
11
|
+
const requestRevalidate = typeof context['revalidate'] === 'number' || context['revalidate'] === false ? context['revalidate'] : undefined;
|
|
13
12
|
const revalidate = requestRevalidate ?? opts.revalidate ?? false;
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
13
|
+
const _fetch = (url, fetchOpts)=>{
|
|
14
|
+
return fetch(url, {
|
|
15
|
+
...fetchOpts,
|
|
16
|
+
// cache: 'no-cache',
|
|
17
|
+
next: {
|
|
18
|
+
revalidate,
|
|
19
|
+
tags: [
|
|
20
|
+
cacheTag
|
|
21
|
+
]
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
const link = opts.batch ? httpBatchLink({
|
|
26
|
+
...opts,
|
|
27
|
+
fetch: _fetch
|
|
28
|
+
}) : httpLink({
|
|
29
|
+
...opts,
|
|
30
|
+
fetch: _fetch
|
|
31
|
+
});
|
|
32
|
+
return link(runtime)(ctx);
|
|
32
33
|
};
|
|
33
34
|
};
|
|
34
35
|
}
|
package/dist/app-dir/server.d.ts
CHANGED
|
@@ -1,25 +1,32 @@
|
|
|
1
|
-
import { AnyProcedure,
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
export declare function experimental_createTRPCNextAppDirServer<TRouter extends AnyRouter>(opts: CreateTRPCNextAppRouterOptions<TRouter>): NextAppDirDecoratedProcedureRecord<TRouter["_def"]["_config"], TRouter["_def"]["record"]>;
|
|
1
|
+
import type { AnyProcedure, AnyRootTypes, AnyRouter, ErrorHandlerOptions, inferClientTypes, MaybePromise, RootConfig, Simplify, TRPCResponse } from '@trpc/server/unstable-core-do-not-import';
|
|
2
|
+
import type { ActionHandlerDef, CreateTRPCNextAppRouterOptions, inferActionDef } from './shared';
|
|
3
|
+
import type { NextAppDirDecorateRouterRecord } from './types';
|
|
4
|
+
export declare function experimental_createTRPCNextAppDirServer<TRouter extends AnyRouter>(opts: CreateTRPCNextAppRouterOptions<TRouter>): NextAppDirDecorateRouterRecord<TRouter["_def"]["_config"]["$types"], TRouter["_def"]["record"]>;
|
|
6
5
|
/**
|
|
7
6
|
* @internal
|
|
8
7
|
*/
|
|
9
8
|
export type TRPCActionHandler<TDef extends ActionHandlerDef> = (input: FormData | TDef['input']) => Promise<TRPCResponse<TDef['output'], TDef['errorShape']>>;
|
|
10
9
|
export declare function experimental_createServerActionHandler<TInstance extends {
|
|
11
|
-
_config:
|
|
12
|
-
}>(t: TInstance, opts: {
|
|
10
|
+
_config: RootConfig<AnyRootTypes>;
|
|
11
|
+
}>(t: TInstance, opts: (object extends TInstance['_config']['$types']['ctx'] ? {
|
|
12
|
+
createContext?: () => MaybePromise<TInstance['_config']['$types']['ctx']>;
|
|
13
|
+
} : {
|
|
13
14
|
createContext: () => MaybePromise<TInstance['_config']['$types']['ctx']>;
|
|
15
|
+
}) & {
|
|
14
16
|
/**
|
|
15
17
|
* Transform form data to a `Record` before passing it to the procedure
|
|
16
18
|
* @default true
|
|
17
19
|
*/
|
|
18
20
|
normalizeFormData?: boolean;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
/**
|
|
22
|
+
* Called when an error occurs in the handler
|
|
23
|
+
*/
|
|
24
|
+
onError?: (opts: ErrorHandlerOptions<TInstance['_config']['$types']['ctx']>) => void;
|
|
25
|
+
/**
|
|
26
|
+
* Rethrow errors that should be handled by Next.js
|
|
27
|
+
* @default true
|
|
28
|
+
*/
|
|
29
|
+
rethrowNextErrors?: boolean;
|
|
30
|
+
}): <TProc extends AnyProcedure>(proc: TProc) => TRPCActionHandler<Simplify<inferActionDef<inferClientTypes<TInstance>, TProc>>>;
|
|
24
31
|
export declare function experimental_revalidateEndpoint(req: Request): Promise<Response>;
|
|
25
32
|
//# sourceMappingURL=server.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/app-dir/server.ts"],"names":[],"mappings":"AAKA,OAAO,
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/app-dir/server.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,YAAY,EACZ,YAAY,EACZ,SAAS,EACT,mBAAmB,EACnB,gBAAgB,EAEhB,YAAY,EACZ,UAAU,EACV,QAAQ,EACR,YAAY,EACb,MAAM,0CAA0C,CAAC;AAalD,OAAO,KAAK,EACV,gBAAgB,EAChB,8BAA8B,EAC9B,cAAc,EACf,MAAM,UAAU,CAAC;AAElB,OAAO,KAAK,EAAE,8BAA8B,EAAE,MAAM,SAAS,CAAC;AAG9D,wBAAgB,uCAAuC,CACrD,OAAO,SAAS,SAAS,EACzB,IAAI,EAAE,8BAA8B,CAAC,OAAO,CAAC,mGA2B9C;AAWD;;GAEG;AACH,MAAM,MAAM,iBAAiB,CAAC,IAAI,SAAS,gBAAgB,IAAI,CAC7D,KAAK,EAAE,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,KAC5B,OAAO,CAAC,YAAY,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;AAE/D,wBAAgB,sCAAsC,CACpD,SAAS,SAAS;IAChB,OAAO,EAAE,UAAU,CAAC,YAAY,CAAC,CAAC;CACnC,EAED,CAAC,EAAE,SAAS,EACZ,IAAI,EAAE,CAAC,MAAM,SAAS,SAAS,CAAC,SAAS,CAAC,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,GACvD;IACE,aAAa,CAAC,EAAE,MAAM,YAAY,CAChC,SAAS,CAAC,SAAS,CAAC,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,CACtC,CAAC;CACH,GACD;IACE,aAAa,EAAE,MAAM,YAAY,CAC/B,SAAS,CAAC,SAAS,CAAC,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,CACtC,CAAC;CACH,CAAC,GAAG;IACP;;;OAGG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B;;OAEG;IACH,OAAO,CAAC,EAAE,CACR,IAAI,EAAE,mBAAmB,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,CAAC,KAC7D,IAAI,CAAC;IAEV;;;OAGG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B,sCAaO,KAAK,KACV,kBACD,SAAS,eAAe,iBAAiB,SAAS,CAAC,EAAE,KAAK,CAAC,CAAC,CAC7D,CAmEF;AAGD,wBAAsB,+BAA+B,CAAC,GAAG,EAAE,OAAO,qBAiBjE"}
|
package/dist/app-dir/server.js
CHANGED
|
@@ -1,44 +1,13 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
3
|
var client = require('@trpc/client');
|
|
6
|
-
var
|
|
7
|
-
var shared = require('@trpc/server/shared');
|
|
4
|
+
var unstableCoreDoNotImport = require('@trpc/server/unstable-core-do-not-import');
|
|
8
5
|
var cache = require('next/cache');
|
|
6
|
+
var notFound = require('next/dist/client/components/not-found');
|
|
7
|
+
var redirect = require('next/dist/client/components/redirect');
|
|
9
8
|
var React = require('react');
|
|
10
|
-
var
|
|
11
|
-
|
|
12
|
-
/* eslint-disable @typescript-eslint/no-non-null-assertion */ function set(obj, path, value) {
|
|
13
|
-
if (typeof path === 'string') {
|
|
14
|
-
path = path.split(/[\.\[\]]/).filter(Boolean);
|
|
15
|
-
}
|
|
16
|
-
if (path.length > 1) {
|
|
17
|
-
const p = path.shift();
|
|
18
|
-
const isArrayIndex = /^\d+$/.test(path[0]);
|
|
19
|
-
obj[p] = obj[p] || (isArrayIndex ? [] : {});
|
|
20
|
-
set(obj[p], path, value);
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
const p1 = path[0];
|
|
24
|
-
if (obj[p1] === undefined) {
|
|
25
|
-
obj[p1] = value;
|
|
26
|
-
} else if (Array.isArray(obj[p1])) {
|
|
27
|
-
obj[p1].push(value);
|
|
28
|
-
} else {
|
|
29
|
-
obj[p1] = [
|
|
30
|
-
obj[p1],
|
|
31
|
-
value
|
|
32
|
-
];
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
function formDataToObject(formData) {
|
|
36
|
-
const obj = {};
|
|
37
|
-
for (const [key, value] of formData.entries()){
|
|
38
|
-
set(obj, key, value);
|
|
39
|
-
}
|
|
40
|
-
return obj;
|
|
41
|
-
}
|
|
9
|
+
var formDataToObject = require('./formDataToObject.js');
|
|
10
|
+
var shared = require('./shared.js');
|
|
42
11
|
|
|
43
12
|
/// <reference types="next" />
|
|
44
13
|
// ts-prune-ignore-next
|
|
@@ -47,7 +16,7 @@ function experimental_createTRPCNextAppDirServer(opts) {
|
|
|
47
16
|
const config = opts.config();
|
|
48
17
|
return client.createTRPCUntypedClient(config);
|
|
49
18
|
});
|
|
50
|
-
return
|
|
19
|
+
return unstableCoreDoNotImport.createRecursiveProxy((callOpts)=>{
|
|
51
20
|
// lazily initialize client
|
|
52
21
|
const client$1 = getClient();
|
|
53
22
|
const pathCopy = [
|
|
@@ -57,7 +26,7 @@ function experimental_createTRPCNextAppDirServer(opts) {
|
|
|
57
26
|
const action = pathCopy.pop();
|
|
58
27
|
const procedurePath = pathCopy.join('.');
|
|
59
28
|
const procedureType = client.clientCallTypeToProcedureType(action);
|
|
60
|
-
const cacheTag = shared
|
|
29
|
+
const cacheTag = shared.generateCacheTag(procedurePath, callOpts.args[0]);
|
|
61
30
|
if (action === 'revalidate') {
|
|
62
31
|
cache.revalidateTag(cacheTag);
|
|
63
32
|
return;
|
|
@@ -65,54 +34,69 @@ function experimental_createTRPCNextAppDirServer(opts) {
|
|
|
65
34
|
return client$1[procedureType](procedurePath, ...callOpts.args);
|
|
66
35
|
});
|
|
67
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* Rethrow errors that should be handled by Next.js
|
|
39
|
+
*/ const throwNextErrors = (error)=>{
|
|
40
|
+
const { cause } = error;
|
|
41
|
+
if (redirect.isRedirectError(cause) || notFound.isNotFoundError(cause)) {
|
|
42
|
+
throw error.cause;
|
|
43
|
+
}
|
|
44
|
+
};
|
|
68
45
|
function experimental_createServerActionHandler(t, opts) {
|
|
69
46
|
const config = t._config;
|
|
70
|
-
const { normalizeFormData =true , createContext } = opts;
|
|
47
|
+
const { normalizeFormData =true , createContext , rethrowNextErrors =true , } = opts;
|
|
71
48
|
const transformer = config.transformer;
|
|
72
49
|
// TODO allow this to take a `TRouter` in addition to a `AnyProcedure`
|
|
73
50
|
return function createServerAction(proc) {
|
|
74
51
|
return async function actionHandler(rawInput) {
|
|
75
|
-
|
|
52
|
+
let ctx = undefined;
|
|
76
53
|
try {
|
|
77
|
-
|
|
78
|
-
if (normalizeFormData && shared
|
|
79
|
-
// Normalizes
|
|
54
|
+
ctx = await createContext?.() ?? {};
|
|
55
|
+
if (normalizeFormData && shared.isFormData(rawInput)) {
|
|
56
|
+
// Normalizes FormData so we can use `z.object({})` etc on the server
|
|
80
57
|
try {
|
|
81
|
-
rawInput = formDataToObject(rawInput);
|
|
58
|
+
rawInput = formDataToObject.formDataToObject(rawInput);
|
|
82
59
|
} catch {
|
|
83
|
-
throw new
|
|
60
|
+
throw new unstableCoreDoNotImport.TRPCError({
|
|
84
61
|
code: 'INTERNAL_SERVER_ERROR',
|
|
85
62
|
message: 'Failed to convert FormData to an object'
|
|
86
63
|
});
|
|
87
64
|
}
|
|
88
|
-
} else if (rawInput && !shared
|
|
65
|
+
} else if (rawInput && !shared.isFormData(rawInput)) {
|
|
89
66
|
rawInput = transformer.input.deserialize(rawInput);
|
|
90
67
|
}
|
|
91
|
-
const data = await proc({
|
|
68
|
+
const data = proc._def.experimental_caller ? await proc(rawInput) : await proc({
|
|
92
69
|
input: undefined,
|
|
93
|
-
ctx
|
|
94
|
-
path: '
|
|
70
|
+
ctx,
|
|
71
|
+
path: '',
|
|
95
72
|
getRawInput: async ()=>rawInput,
|
|
96
73
|
type: proc._def.type
|
|
97
74
|
});
|
|
98
|
-
const transformedJSON =
|
|
75
|
+
const transformedJSON = unstableCoreDoNotImport.transformTRPCResponse(config, {
|
|
99
76
|
result: {
|
|
100
77
|
data
|
|
101
78
|
}
|
|
102
79
|
});
|
|
103
80
|
return transformedJSON;
|
|
104
81
|
} catch (cause) {
|
|
105
|
-
const error =
|
|
106
|
-
|
|
82
|
+
const error = unstableCoreDoNotImport.getTRPCErrorFromUnknown(cause);
|
|
83
|
+
opts.onError?.({
|
|
84
|
+
ctx,
|
|
85
|
+
error,
|
|
86
|
+
input: rawInput,
|
|
87
|
+
path: '',
|
|
88
|
+
type: proc._def.type
|
|
89
|
+
});
|
|
90
|
+
rethrowNextErrors && throwNextErrors(error);
|
|
91
|
+
const shape = unstableCoreDoNotImport.getErrorShape({
|
|
107
92
|
config,
|
|
108
93
|
ctx,
|
|
109
94
|
error,
|
|
110
95
|
input: rawInput,
|
|
111
|
-
path: '
|
|
96
|
+
path: '',
|
|
112
97
|
type: proc._def.type
|
|
113
98
|
});
|
|
114
|
-
|
|
115
|
-
return shared.transformTRPCResponse(t._config, {
|
|
99
|
+
return unstableCoreDoNotImport.transformTRPCResponse(t._config, {
|
|
116
100
|
error: shape
|
|
117
101
|
});
|
|
118
102
|
}
|
package/dist/app-dir/server.mjs
CHANGED
|
@@ -1,40 +1,11 @@
|
|
|
1
1
|
import { createTRPCUntypedClient, clientCallTypeToProcedureType } from '@trpc/client';
|
|
2
|
-
import { TRPCError, getTRPCErrorFromUnknown } from '@trpc/server';
|
|
3
|
-
import { createRecursiveProxy, transformTRPCResponse, getErrorShape } from '@trpc/server/shared';
|
|
2
|
+
import { createRecursiveProxy, TRPCError, transformTRPCResponse, getTRPCErrorFromUnknown, getErrorShape } from '@trpc/server/unstable-core-do-not-import';
|
|
4
3
|
import { revalidateTag } from 'next/cache';
|
|
4
|
+
import { isNotFoundError } from 'next/dist/client/components/not-found';
|
|
5
|
+
import { isRedirectError } from 'next/dist/client/components/redirect';
|
|
5
6
|
import { cache } from 'react';
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
/* eslint-disable @typescript-eslint/no-non-null-assertion */ function set(obj, path, value) {
|
|
9
|
-
if (typeof path === 'string') {
|
|
10
|
-
path = path.split(/[\.\[\]]/).filter(Boolean);
|
|
11
|
-
}
|
|
12
|
-
if (path.length > 1) {
|
|
13
|
-
const p = path.shift();
|
|
14
|
-
const isArrayIndex = /^\d+$/.test(path[0]);
|
|
15
|
-
obj[p] = obj[p] || (isArrayIndex ? [] : {});
|
|
16
|
-
set(obj[p], path, value);
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
const p1 = path[0];
|
|
20
|
-
if (obj[p1] === undefined) {
|
|
21
|
-
obj[p1] = value;
|
|
22
|
-
} else if (Array.isArray(obj[p1])) {
|
|
23
|
-
obj[p1].push(value);
|
|
24
|
-
} else {
|
|
25
|
-
obj[p1] = [
|
|
26
|
-
obj[p1],
|
|
27
|
-
value
|
|
28
|
-
];
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
function formDataToObject(formData) {
|
|
32
|
-
const obj = {};
|
|
33
|
-
for (const [key, value] of formData.entries()){
|
|
34
|
-
set(obj, key, value);
|
|
35
|
-
}
|
|
36
|
-
return obj;
|
|
37
|
-
}
|
|
7
|
+
import { formDataToObject } from './formDataToObject.mjs';
|
|
8
|
+
import { generateCacheTag, isFormData } from './shared.mjs';
|
|
38
9
|
|
|
39
10
|
/// <reference types="next" />
|
|
40
11
|
// ts-prune-ignore-next
|
|
@@ -61,18 +32,26 @@ function experimental_createTRPCNextAppDirServer(opts) {
|
|
|
61
32
|
return client[procedureType](procedurePath, ...callOpts.args);
|
|
62
33
|
});
|
|
63
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* Rethrow errors that should be handled by Next.js
|
|
37
|
+
*/ const throwNextErrors = (error)=>{
|
|
38
|
+
const { cause } = error;
|
|
39
|
+
if (isRedirectError(cause) || isNotFoundError(cause)) {
|
|
40
|
+
throw error.cause;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
64
43
|
function experimental_createServerActionHandler(t, opts) {
|
|
65
44
|
const config = t._config;
|
|
66
|
-
const { normalizeFormData =true , createContext } = opts;
|
|
45
|
+
const { normalizeFormData =true , createContext , rethrowNextErrors =true , } = opts;
|
|
67
46
|
const transformer = config.transformer;
|
|
68
47
|
// TODO allow this to take a `TRouter` in addition to a `AnyProcedure`
|
|
69
48
|
return function createServerAction(proc) {
|
|
70
49
|
return async function actionHandler(rawInput) {
|
|
71
|
-
|
|
50
|
+
let ctx = undefined;
|
|
72
51
|
try {
|
|
73
|
-
|
|
52
|
+
ctx = await createContext?.() ?? {};
|
|
74
53
|
if (normalizeFormData && isFormData(rawInput)) {
|
|
75
|
-
// Normalizes
|
|
54
|
+
// Normalizes FormData so we can use `z.object({})` etc on the server
|
|
76
55
|
try {
|
|
77
56
|
rawInput = formDataToObject(rawInput);
|
|
78
57
|
} catch {
|
|
@@ -84,10 +63,10 @@ function experimental_createServerActionHandler(t, opts) {
|
|
|
84
63
|
} else if (rawInput && !isFormData(rawInput)) {
|
|
85
64
|
rawInput = transformer.input.deserialize(rawInput);
|
|
86
65
|
}
|
|
87
|
-
const data = await proc({
|
|
66
|
+
const data = proc._def.experimental_caller ? await proc(rawInput) : await proc({
|
|
88
67
|
input: undefined,
|
|
89
|
-
ctx
|
|
90
|
-
path: '
|
|
68
|
+
ctx,
|
|
69
|
+
path: '',
|
|
91
70
|
getRawInput: async ()=>rawInput,
|
|
92
71
|
type: proc._def.type
|
|
93
72
|
});
|
|
@@ -99,15 +78,22 @@ function experimental_createServerActionHandler(t, opts) {
|
|
|
99
78
|
return transformedJSON;
|
|
100
79
|
} catch (cause) {
|
|
101
80
|
const error = getTRPCErrorFromUnknown(cause);
|
|
81
|
+
opts.onError?.({
|
|
82
|
+
ctx,
|
|
83
|
+
error,
|
|
84
|
+
input: rawInput,
|
|
85
|
+
path: '',
|
|
86
|
+
type: proc._def.type
|
|
87
|
+
});
|
|
88
|
+
rethrowNextErrors && throwNextErrors(error);
|
|
102
89
|
const shape = getErrorShape({
|
|
103
90
|
config,
|
|
104
91
|
ctx,
|
|
105
92
|
error,
|
|
106
93
|
input: rawInput,
|
|
107
|
-
path: '
|
|
94
|
+
path: '',
|
|
108
95
|
type: proc._def.type
|
|
109
96
|
});
|
|
110
|
-
// TODO: send the right HTTP header?!
|
|
111
97
|
return transformTRPCResponse(t._config, {
|
|
112
98
|
error: shape
|
|
113
99
|
});
|
package/dist/app-dir/shared.d.ts
CHANGED
|
@@ -1,22 +1,28 @@
|
|
|
1
|
-
import { CreateTRPCClientOptions, Resolver, TRPCUntypedClient } from '@trpc/client';
|
|
2
|
-
import {
|
|
1
|
+
import type { CreateTRPCClientOptions, Resolver, TRPCUntypedClient } from '@trpc/client';
|
|
2
|
+
import type { inferProcedureOutput } from '@trpc/server';
|
|
3
|
+
import type { AnyClientTypes, AnyProcedure, AnyQueryProcedure, AnyRootTypes, AnyRouter, inferProcedureInput, inferTransformedProcedureOutput, ProtectedIntersection, RouterRecord } from '@trpc/server/unstable-core-do-not-import';
|
|
3
4
|
/**
|
|
4
5
|
* @internal
|
|
5
6
|
*/
|
|
6
|
-
export type UseProcedureRecord<
|
|
7
|
-
[TKey in keyof
|
|
7
|
+
export type UseProcedureRecord<TRoot extends AnyRootTypes, TRecord extends RouterRecord> = {
|
|
8
|
+
[TKey in keyof TRecord]: TRecord[TKey] extends infer $Value ? $Value extends RouterRecord ? UseProcedureRecord<TRoot, $Value> : $Value extends AnyQueryProcedure ? Resolver<{
|
|
9
|
+
input: inferProcedureInput<$Value>;
|
|
10
|
+
output: inferTransformedProcedureOutput<TRoot, $Value>;
|
|
11
|
+
errorShape: TRoot['errorShape'];
|
|
12
|
+
transformer: TRoot['transformer'];
|
|
13
|
+
}> : never : never;
|
|
8
14
|
};
|
|
9
|
-
export declare function createUseProxy<TRouter extends AnyRouter>(client: TRPCUntypedClient<TRouter>): UseProcedureRecord<TRouter>;
|
|
15
|
+
export declare function createUseProxy<TRouter extends AnyRouter>(client: TRPCUntypedClient<TRouter>): UseProcedureRecord<TRouter["_def"]["_config"]["$types"], TRouter["_def"]["record"]>;
|
|
10
16
|
type NextAppRouterUse<TRouter extends AnyRouter> = {
|
|
11
|
-
<TData extends Promise<unknown>[]>(cb: (t: UseProcedureRecord<TRouter>) => [...TData]): {
|
|
12
|
-
[TKey in keyof TData]:
|
|
17
|
+
<TData extends Promise<unknown>[]>(cb: (t: UseProcedureRecord<TRouter['_def']['_config']['$types'], TRouter['_def']['record']>) => [...TData]): {
|
|
18
|
+
[TKey in keyof TData]: Awaited<TData[TKey]>;
|
|
13
19
|
};
|
|
14
|
-
<TData extends Promise<unknown>>(cb: (t: UseProcedureRecord<TRouter>) => TData):
|
|
20
|
+
<TData extends Promise<unknown>>(cb: (t: UseProcedureRecord<TRouter['_def']['_config']['$types'], TRouter['_def']['record']>) => TData): Awaited<TData>;
|
|
15
21
|
};
|
|
16
22
|
type CreateTRPCNextAppRouterBase<TRouter extends AnyRouter> = {
|
|
17
23
|
use: NextAppRouterUse<TRouter>;
|
|
18
24
|
};
|
|
19
|
-
export type CreateTRPCNextAppRouter<TRouter extends AnyRouter> = ProtectedIntersection<CreateTRPCNextAppRouterBase<TRouter>, UseProcedureRecord<TRouter>>;
|
|
25
|
+
export type CreateTRPCNextAppRouter<TRouter extends AnyRouter> = ProtectedIntersection<CreateTRPCNextAppRouterBase<TRouter>, UseProcedureRecord<TRouter['_def']['_config']['$types'], TRouter['_def']['record']>>;
|
|
20
26
|
/**
|
|
21
27
|
* @internal
|
|
22
28
|
*/
|
|
@@ -39,10 +45,10 @@ export interface ActionHandlerDef {
|
|
|
39
45
|
/**
|
|
40
46
|
* @internal
|
|
41
47
|
*/
|
|
42
|
-
export type inferActionDef<
|
|
43
|
-
input:
|
|
44
|
-
output: TProc
|
|
45
|
-
errorShape:
|
|
48
|
+
export type inferActionDef<TRoot extends AnyClientTypes, TProc extends AnyProcedure> = {
|
|
49
|
+
input: inferProcedureInput<TProc>;
|
|
50
|
+
output: inferProcedureOutput<TProc>;
|
|
51
|
+
errorShape: TRoot['errorShape'];
|
|
46
52
|
};
|
|
47
53
|
export {};
|
|
48
54
|
//# sourceMappingURL=shared.d.ts.map
|