@trpc/next 10.32.0 → 10.33.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/dist/app-dir/client.d.ts.map +1 -1
  2. package/dist/app-dir/client.js +5 -22
  3. package/dist/app-dir/client.mjs +5 -22
  4. package/dist/app-dir/create-action-hook.d.ts +3 -3
  5. package/dist/app-dir/create-action-hook.d.ts.map +1 -1
  6. package/dist/app-dir/links/nextCache.d.ts +11 -0
  7. package/dist/app-dir/links/nextCache.d.ts.map +1 -0
  8. package/dist/app-dir/links/nextCache.js +59 -0
  9. package/dist/app-dir/links/nextCache.mjs +55 -0
  10. package/dist/app-dir/links/nextHttp.d.ts +9 -0
  11. package/dist/app-dir/links/nextHttp.d.ts.map +1 -0
  12. package/dist/app-dir/links/nextHttp.js +40 -0
  13. package/dist/app-dir/links/nextHttp.mjs +36 -0
  14. package/dist/app-dir/server.d.ts +4 -3
  15. package/dist/app-dir/server.d.ts.map +1 -1
  16. package/dist/app-dir/server.js +32 -4
  17. package/dist/app-dir/server.mjs +32 -5
  18. package/dist/app-dir/shared.d.ts +2 -1
  19. package/dist/app-dir/shared.d.ts.map +1 -1
  20. package/dist/app-dir/types.d.ts +19 -0
  21. package/dist/app-dir/types.d.ts.map +1 -0
  22. package/dist/index.js +4 -4
  23. package/dist/index.mjs +4 -4
  24. package/dist/shared-642894f4.js +19 -0
  25. package/dist/{shared-2ca37369.js → shared-e49b9cdc.js} +5 -1
  26. package/dist/{shared-7b422d72.js → shared-f6996341.mjs} +4 -2
  27. package/dist/withTRPC.d.ts +2 -2
  28. package/dist/withTRPC.d.ts.map +1 -1
  29. package/package.json +19 -9
  30. package/src/app-dir/client.ts +1 -32
  31. package/src/app-dir/create-action-hook.tsx +7 -5
  32. package/src/app-dir/formDataToObject.ts +1 -1
  33. package/src/app-dir/links/nextCache.ts +72 -0
  34. package/src/app-dir/links/nextHttp.ts +54 -0
  35. package/src/app-dir/server.ts +38 -10
  36. package/src/app-dir/shared.ts +7 -1
  37. package/src/app-dir/types.ts +39 -0
  38. package/src/withTRPC.tsx +10 -9
  39. package/dist/shared-59b269d5.mjs +0 -13
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/app-dir/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,qBAAqB,EAEtB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,OAAO,EAAE,8BAA8B,EAAE,MAAM,UAAU,CAAC;AAE1D,OAAO,EAEL,6BAA6B,EAE7B,6BAA6B,EAE7B,KAAK,mBAAmB,EAExB,KAAK,sBAAsB,GAC5B,MAAM,sBAAsB,CAAC;AAkB9B,wBAAgB,uCAAuC,CACrD,OAAO,SAAS,SAAS,EACzB,IAAI,EAAE,8BAA8B,CAAC,OAAO,CAAC,kCA8D9C"}
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/app-dir/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,qBAAqB,EAEtB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,OAAO,EAAE,8BAA8B,EAAE,MAAM,UAAU,CAAC;AAE1D,OAAO,EAEL,6BAA6B,EAE7B,6BAA6B,EAE7B,KAAK,mBAAmB,EAExB,KAAK,sBAAsB,GAC5B,MAAM,sBAAsB,CAAC;AAS9B,wBAAgB,uCAAuC,CACrD,OAAO,SAAS,SAAS,EACzB,IAAI,EAAE,8BAA8B,CAAC,OAAO,CAAC,kCAwC9C"}
@@ -7,7 +7,7 @@ var shared$2 = require('@trpc/server/shared');
7
7
  var shared$1 = require('@trpc/client/shared');
8
8
  var observable = require('@trpc/server/observable');
9
9
  var React = require('react');
10
- var shared = require('../shared-2ca37369.js');
10
+ var shared = require('../shared-e49b9cdc.js');
11
11
 
12
12
  // ts-prune-ignore-next
13
13
  function experimental_serverActionLink() {
@@ -24,7 +24,9 @@ function experimental_serverActionLink() {
24
24
  result: transformed.result
25
25
  });
26
26
  observer.complete();
27
- }).catch((cause)=>observer.error(client.TRPCClientError.from(cause)));
27
+ }).catch((cause)=>{
28
+ observer.error(client.TRPCClientError.from(cause));
29
+ });
28
30
  });
29
31
  }
30
32
  // ts-prune-ignore-next
@@ -107,31 +109,12 @@ function experimental_createTRPCNextAppDirClient(opts) {
107
109
  const client$1 = client.createTRPCUntypedClient(opts.config());
108
110
  // const useProxy = createUseProxy<TRouter>(client);
109
111
  const cache = new Map();
110
- // return createFlatProxy<CreateTRPCNextAppRouter<TRouter>>((key) => {
111
- // if (key === 'use') {
112
- // return (
113
- // cb: (
114
- // t: UseProcedureRecord<TRouter>,
115
- // ) => Promise<unknown> | Promise<unknown>[],
116
- // ) => {
117
- // const promise = normalizePromiseArray(cb(useProxy));
118
- // throw promise;
119
- // // const [data, setData] = useState<unknown | unknown[]>();
120
- // // useEffect(() => {
121
- // // const promise = normalizePromiseArray(cb(useProxy));
122
- // // void promise.then(setData).catch((err) => {
123
- // // throw err;
124
- // // });
125
- // // // eslint-disable-next-line react-hooks/exhaustive-deps
126
- // // }, []);
127
- // // return data;
128
- // };
129
- // }
130
112
  return shared$2.createRecursiveProxy(({ path , args })=>{
131
113
  // const pathCopy = [key, ...path];
132
114
  const pathCopy = [
133
115
  ...path
134
116
  ];
117
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
135
118
  const procedureType = client.clientCallTypeToProcedureType(pathCopy.pop());
136
119
  if (procedureType === 'query') {
137
120
  const queryCacheKey = JSON.stringify([
@@ -3,7 +3,7 @@ import { createRecursiveProxy } from '@trpc/server/shared';
3
3
  import { transformResult } from '@trpc/client/shared';
4
4
  import { observable } from '@trpc/server/observable';
5
5
  import { useRef, useState, useEffect, useCallback, useMemo } from 'react';
6
- import { i as isFormData } from '../shared-59b269d5.mjs';
6
+ import { i as isFormData } from '../shared-f6996341.mjs';
7
7
 
8
8
  // ts-prune-ignore-next
9
9
  function experimental_serverActionLink() {
@@ -20,7 +20,9 @@ function experimental_serverActionLink() {
20
20
  result: transformed.result
21
21
  });
22
22
  observer.complete();
23
- }).catch((cause)=>observer.error(TRPCClientError.from(cause)));
23
+ }).catch((cause)=>{
24
+ observer.error(TRPCClientError.from(cause));
25
+ });
24
26
  });
25
27
  }
26
28
  // ts-prune-ignore-next
@@ -103,31 +105,12 @@ function experimental_createTRPCNextAppDirClient(opts) {
103
105
  const client = createTRPCUntypedClient(opts.config());
104
106
  // const useProxy = createUseProxy<TRouter>(client);
105
107
  const cache = new Map();
106
- // return createFlatProxy<CreateTRPCNextAppRouter<TRouter>>((key) => {
107
- // if (key === 'use') {
108
- // return (
109
- // cb: (
110
- // t: UseProcedureRecord<TRouter>,
111
- // ) => Promise<unknown> | Promise<unknown>[],
112
- // ) => {
113
- // const promise = normalizePromiseArray(cb(useProxy));
114
- // throw promise;
115
- // // const [data, setData] = useState<unknown | unknown[]>();
116
- // // useEffect(() => {
117
- // // const promise = normalizePromiseArray(cb(useProxy));
118
- // // void promise.then(setData).catch((err) => {
119
- // // throw err;
120
- // // });
121
- // // // eslint-disable-next-line react-hooks/exhaustive-deps
122
- // // }, []);
123
- // // return data;
124
- // };
125
- // }
126
108
  return createRecursiveProxy(({ path , args })=>{
127
109
  // const pathCopy = [key, ...path];
128
110
  const pathCopy = [
129
111
  ...path
130
112
  ];
113
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
131
114
  const procedureType = clientCallTypeToProcedureType(pathCopy.pop());
132
115
  if (procedureType === 'query') {
133
116
  const queryCacheKey = JSON.stringify([
@@ -2,7 +2,7 @@ import { CreateTRPCClientOptions, TRPCClientError, TRPCLink } from '@trpc/client
2
2
  import { AnyProcedure, AnyRouter, inferHandlerInput, MaybePromise, ProcedureOptions, Simplify } from '@trpc/server';
3
3
  import { TRPCActionHandler } from './server';
4
4
  import { ActionHandlerDef } from './shared';
5
- type MutationArgs<TDef extends ActionHandlerDef> = TDef['input'] extends void ? [input?: undefined | void, opts?: ProcedureOptions] : [input: TDef['input'] | FormData, opts?: ProcedureOptions];
5
+ type MutationArgs<TDef extends ActionHandlerDef> = TDef['input'] extends void ? [input?: undefined | void, opts?: ProcedureOptions] : [input: FormData | TDef['input'], opts?: ProcedureOptions];
6
6
  interface UseTRPCActionBaseResult<TDef extends ActionHandlerDef> {
7
7
  mutate: (...args: MutationArgs<TDef>) => void;
8
8
  mutateAsync: (...args: MutationArgs<TDef>) => Promise<TDef['output']>;
@@ -27,7 +27,7 @@ interface UseTRPCActionLoadingResult<TDef extends ActionHandlerDef> extends UseT
27
27
  error?: never;
28
28
  status: 'loading';
29
29
  }
30
- export type UseTRPCActionResult<TDef extends ActionHandlerDef> = UseTRPCActionSuccessResult<TDef> | UseTRPCActionErrorResult<TDef> | UseTRPCActionIdleResult<TDef> | UseTRPCActionLoadingResult<TDef>;
30
+ export type UseTRPCActionResult<TDef extends ActionHandlerDef> = UseTRPCActionErrorResult<TDef> | UseTRPCActionIdleResult<TDef> | UseTRPCActionLoadingResult<TDef> | UseTRPCActionSuccessResult<TDef>;
31
31
  export declare function experimental_serverActionLink<TRouter extends AnyRouter = AnyRouter>(): TRPCLink<TRouter>;
32
32
  /**
33
33
  * @internal
@@ -38,7 +38,7 @@ export type inferActionResultProps<TProc extends AnyProcedure> = {
38
38
  errorShape: TProc['_def']['_config']['$types']['errorShape'];
39
39
  };
40
40
  interface UseTRPCActionOptions<TDef extends ActionHandlerDef> {
41
- onSuccess?: (result: TDef['output']) => void | MaybePromise<void>;
41
+ onSuccess?: (result: TDef['output']) => MaybePromise<void> | void;
42
42
  onError?: (result: TRPCClientError<TDef['errorShape']>) => MaybePromise<void>;
43
43
  }
44
44
  export declare function experimental_createActionHook<TRouter extends AnyRouter>(opts: CreateTRPCClientOptions<TRouter>): <TDef extends ActionHandlerDef>(handler: TRPCActionHandler<TDef>, useActionOpts?: UseTRPCActionOptions<Simplify<TDef>> | undefined) => UseTRPCActionRes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MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,aAAa,CAAC,CAAC;IACrC,UAAU,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,CAAC,QAAQ,CAAC,CAAC,YAAY,CAAC,CAAC;CAC9D,CAAC;AAEF,UAAU,oBAAoB,CAAC,IAAI,SAAS,gBAAgB;IAC1D,SAAS,CAAC,EAAE,CAAC,MAAM,EAAE,IAAI,CAAC,QAAQ,CAAC,KAAK,YAAY,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IAClE,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,eAAe,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,KAAK,YAAY,CAAC,IAAI,CAAC,CAAC;CAC/E;AAGD,wBAAgB,6BAA6B,CAAC,OAAO,SAAS,SAAS,EACrE,IAAI,EAAE,uBAAuB,CAAC,OAAO,CAAC,oKA6FvC"}
@@ -0,0 +1,11 @@
1
+ import { TRPCLink } from '@trpc/client';
2
+ import { AnyRouter, inferRouterContext } from '@trpc/server';
3
+ type NextCacheLinkOptions<TRouter extends AnyRouter> = {
4
+ router: TRouter;
5
+ createContext: () => Promise<inferRouterContext<TRouter>>;
6
+ /** how many seconds the cache should hold before revalidating */
7
+ revalidate?: number | false;
8
+ };
9
+ export declare function experimental_nextCacheLink<TRouter extends AnyRouter>(opts: NextCacheLinkOptions<TRouter>): TRPCLink<TRouter>;
10
+ export {};
11
+ //# sourceMappingURL=nextCache.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nextCache.d.ts","sourceRoot":"","sources":["../../../src/app-dir/links/nextCache.ts"],"names":[],"mappings":"AAEA,OAAO,EAAmB,QAAQ,EAAE,MAAM,cAAc,CAAC;AACzD,OAAO,EAAE,SAAS,EAAiB,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAK5E,KAAK,oBAAoB,CAAC,OAAO,SAAS,SAAS,IAAI;IACrD,MAAM,EAAE,OAAO,CAAC;IAChB,aAAa,EAAE,MAAM,OAAO,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC,CAAC;IAC1D,iEAAiE;IACjE,UAAU,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC;CAC7B,CAAC;AAGF,wBAAgB,0BAA0B,CAAC,OAAO,SAAS,SAAS,EAClE,IAAI,EAAE,oBAAoB,CAAC,OAAO,CAAC,GAClC,QAAQ,CAAC,OAAO,CAAC,CAqDnB"}
@@ -0,0 +1,59 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var client = require('@trpc/client');
6
+ var server = require('@trpc/server');
7
+ var observable = require('@trpc/server/observable');
8
+ var cache = require('next/cache');
9
+ var shared = require('../../shared-e49b9cdc.js');
10
+ require('@trpc/server/shared');
11
+
12
+ // import "server-only";
13
+ // ts-prune-ignore-next
14
+ function experimental_nextCacheLink(opts) {
15
+ return (runtime)=>({ op })=>observable.observable((observer)=>{
16
+ const { path , input , type , context } = op;
17
+ const cacheTag = shared.generateCacheTag(path, input);
18
+ // Let per-request revalidate override global revalidate
19
+ const requestRevalidate = typeof context.revalidate === 'number' || context.revalidate === false ? context.revalidate : undefined;
20
+ const revalidate = requestRevalidate ?? opts.revalidate ?? false;
21
+ const promise = opts.createContext().then(async (ctx)=>{
22
+ const callProc = async ()=>{
23
+ const procedureResult = await server.callProcedure({
24
+ procedures: opts.router._def.procedures,
25
+ path,
26
+ rawInput: input,
27
+ ctx: ctx,
28
+ type
29
+ });
30
+ // We need to serialize cause the cache only accepts JSON
31
+ return runtime.transformer.serialize(procedureResult);
32
+ };
33
+ if (type === 'query') {
34
+ return cache.unstable_cache(callProc, path.split('.'), {
35
+ revalidate,
36
+ tags: [
37
+ cacheTag
38
+ ]
39
+ })();
40
+ }
41
+ return callProc();
42
+ }).catch((cause)=>{
43
+ observer.error(client.TRPCClientError.from(cause));
44
+ });
45
+ promise.then((data)=>{
46
+ const transformedResult = runtime.transformer.deserialize(data);
47
+ observer.next({
48
+ result: {
49
+ data: transformedResult
50
+ }
51
+ });
52
+ observer.complete();
53
+ }).catch((cause)=>{
54
+ observer.error(client.TRPCClientError.from(cause));
55
+ });
56
+ });
57
+ }
58
+
59
+ exports.experimental_nextCacheLink = experimental_nextCacheLink;
@@ -0,0 +1,55 @@
1
+ import { TRPCClientError } from '@trpc/client';
2
+ import { callProcedure } from '@trpc/server';
3
+ import { observable } from '@trpc/server/observable';
4
+ import { unstable_cache } from 'next/cache';
5
+ import { g as generateCacheTag } from '../../shared-f6996341.mjs';
6
+ import '@trpc/server/shared';
7
+
8
+ // import "server-only";
9
+ // ts-prune-ignore-next
10
+ function experimental_nextCacheLink(opts) {
11
+ return (runtime)=>({ op })=>observable((observer)=>{
12
+ const { path , input , type , context } = op;
13
+ const cacheTag = generateCacheTag(path, input);
14
+ // Let per-request revalidate override global revalidate
15
+ const requestRevalidate = typeof context.revalidate === 'number' || context.revalidate === false ? context.revalidate : undefined;
16
+ const revalidate = requestRevalidate ?? opts.revalidate ?? false;
17
+ const promise = opts.createContext().then(async (ctx)=>{
18
+ const callProc = async ()=>{
19
+ const procedureResult = await callProcedure({
20
+ procedures: opts.router._def.procedures,
21
+ path,
22
+ rawInput: input,
23
+ ctx: ctx,
24
+ type
25
+ });
26
+ // We need to serialize cause the cache only accepts JSON
27
+ return runtime.transformer.serialize(procedureResult);
28
+ };
29
+ if (type === 'query') {
30
+ return unstable_cache(callProc, path.split('.'), {
31
+ revalidate,
32
+ tags: [
33
+ cacheTag
34
+ ]
35
+ })();
36
+ }
37
+ return callProc();
38
+ }).catch((cause)=>{
39
+ observer.error(TRPCClientError.from(cause));
40
+ });
41
+ promise.then((data)=>{
42
+ const transformedResult = runtime.transformer.deserialize(data);
43
+ observer.next({
44
+ result: {
45
+ data: transformedResult
46
+ }
47
+ });
48
+ observer.complete();
49
+ }).catch((cause)=>{
50
+ observer.error(TRPCClientError.from(cause));
51
+ });
52
+ });
53
+ }
54
+
55
+ export { experimental_nextCacheLink };
@@ -0,0 +1,9 @@
1
+ import { HTTPBatchLinkOptions, HTTPLinkOptions, TRPCLink } from '@trpc/client';
2
+ import { AnyRouter } from '@trpc/server';
3
+ type NextFetchLinkOptions<TBatch extends boolean> = (TBatch extends true ? HTTPBatchLinkOptions : HTTPLinkOptions) & {
4
+ batch?: TBatch;
5
+ revalidate?: number | false;
6
+ };
7
+ export declare function experimental_nextHttpLink<TRouter extends AnyRouter, TBatch extends boolean>(opts: NextFetchLinkOptions<TBatch>): TRPCLink<TRouter>;
8
+ export {};
9
+ //# sourceMappingURL=nextHttp.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nextHttp.d.ts","sourceRoot":"","sources":["../../../src/app-dir/links/nextHttp.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,oBAAoB,EAEpB,eAAe,EACf,QAAQ,EACT,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAGzC,KAAK,oBAAoB,CAAC,MAAM,SAAS,OAAO,IAAI,CAAC,MAAM,SAAS,IAAI,GACpE,oBAAoB,GACpB,eAAe,CAAC,GAAG;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC;CAC7B,CAAC;AAGF,wBAAgB,yBAAyB,CACvC,OAAO,SAAS,SAAS,EACzB,MAAM,SAAS,OAAO,EACtB,IAAI,EAAE,oBAAoB,CAAC,MAAM,CAAC,GAAG,QAAQ,CAAC,OAAO,CAAC,CAgCvD"}
@@ -0,0 +1,40 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var client = require('@trpc/client');
6
+ var shared = require('../../shared-e49b9cdc.js');
7
+ require('@trpc/server/shared');
8
+
9
+ // ts-prune-ignore-next
10
+ function experimental_nextHttpLink(opts) {
11
+ return (runtime)=>{
12
+ return (ctx)=>{
13
+ const { path , input , context } = ctx.op;
14
+ const cacheTag = shared.generateCacheTag(path, input);
15
+ // Let per-request revalidate override global revalidate
16
+ const requestRevalidate = typeof context.revalidate === 'number' || context.revalidate === false ? context.revalidate : undefined;
17
+ const revalidate = requestRevalidate ?? opts.revalidate ?? false;
18
+ const linkFactory = opts.batch ? client.httpBatchLink : client.httpLink;
19
+ const link = linkFactory({
20
+ headers: opts.headers,
21
+ url: opts.url,
22
+ fetch: (url, fetchOpts)=>{
23
+ return fetch(url, {
24
+ ...fetchOpts,
25
+ // cache: 'no-cache',
26
+ next: {
27
+ revalidate,
28
+ tags: [
29
+ cacheTag
30
+ ]
31
+ }
32
+ });
33
+ }
34
+ })(runtime);
35
+ return link(ctx);
36
+ };
37
+ };
38
+ }
39
+
40
+ exports.experimental_nextHttpLink = experimental_nextHttpLink;
@@ -0,0 +1,36 @@
1
+ import { httpBatchLink, httpLink } from '@trpc/client';
2
+ import { g as generateCacheTag } from '../../shared-f6996341.mjs';
3
+ import '@trpc/server/shared';
4
+
5
+ // ts-prune-ignore-next
6
+ function experimental_nextHttpLink(opts) {
7
+ return (runtime)=>{
8
+ return (ctx)=>{
9
+ const { path , input , context } = ctx.op;
10
+ const cacheTag = generateCacheTag(path, input);
11
+ // Let per-request revalidate override global revalidate
12
+ const requestRevalidate = typeof context.revalidate === 'number' || context.revalidate === false ? context.revalidate : undefined;
13
+ const revalidate = requestRevalidate ?? opts.revalidate ?? false;
14
+ const linkFactory = opts.batch ? httpBatchLink : httpLink;
15
+ const link = linkFactory({
16
+ headers: opts.headers,
17
+ url: opts.url,
18
+ fetch: (url, fetchOpts)=>{
19
+ return fetch(url, {
20
+ ...fetchOpts,
21
+ // cache: 'no-cache',
22
+ next: {
23
+ revalidate,
24
+ tags: [
25
+ cacheTag
26
+ ]
27
+ }
28
+ });
29
+ }
30
+ })(runtime);
31
+ return link(ctx);
32
+ };
33
+ };
34
+ }
35
+
36
+ export { experimental_nextHttpLink };
@@ -1,12 +1,12 @@
1
- import { CreateTRPCProxyClient } from '@trpc/client';
2
1
  import { AnyProcedure, AnyRootConfig, AnyRouter, MaybePromise, Simplify } from '@trpc/server';
3
2
  import { TRPCResponse } from '@trpc/server/rpc';
4
3
  import { ActionHandlerDef, CreateTRPCNextAppRouterOptions, inferActionDef } from './shared';
5
- export declare function experimental_createTRPCNextAppDirServer<TRouter extends AnyRouter>(opts: CreateTRPCNextAppRouterOptions<TRouter>): CreateTRPCProxyClient<TRouter>;
4
+ import { NextAppDirDecoratedProcedureRecord } from './types';
5
+ export declare function experimental_createTRPCNextAppDirServer<TRouter extends AnyRouter>(opts: CreateTRPCNextAppRouterOptions<TRouter>): NextAppDirDecoratedProcedureRecord<TRouter["_def"]["record"]>;
6
6
  /**
7
7
  * @internal
8
8
  */
9
- export type TRPCActionHandler<TDef extends ActionHandlerDef> = (input: TDef['input'] | FormData) => Promise<TRPCResponse<TDef['output'], TDef['errorShape']>>;
9
+ export type TRPCActionHandler<TDef extends ActionHandlerDef> = (input: FormData | TDef['input']) => Promise<TRPCResponse<TDef['output'], TDef['errorShape']>>;
10
10
  export declare function experimental_createServerActionHandler<TInstance extends {
11
11
  _config: AnyRootConfig;
12
12
  }>(t: TInstance, opts: {
@@ -21,4 +21,5 @@ export declare function experimental_createServerActionHandler<TInstance extends
21
21
  output: TProc["_def"]["_output_out"];
22
22
  errorShape: TProc["_def"]["_config"]["$types"]["errorShape"];
23
23
  }>;
24
+ export declare function experimental_revalidateEndpoint(req: Request): Promise<Response>;
24
25
  //# sourceMappingURL=server.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/app-dir/server.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,qBAAqB,EAEtB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,YAAY,EACZ,aAAa,EACb,SAAS,EAIT,YAAY,EACZ,QAAQ,EAET,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAQhD,OAAO,EACL,gBAAgB,EAChB,8BAA8B,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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,aAAa,CAAC;CACxB,EAED,CAAC,EAAE,SAAS,EACZ,IAAI,EAAE;IACJ,aAAa,EAAE,MAAM,YAAY,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;IACzE;;;OAGG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B;;;;GAgEF;AAGD,wBAAsB,+BAA+B,CAAC,GAAG,EAAE,OAAO,qBAiBjE"}
@@ -5,8 +5,9 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var client = require('@trpc/client');
6
6
  var server = require('@trpc/server');
7
7
  var shared = require('@trpc/server/shared');
8
+ var cache = require('next/cache');
8
9
  var React = require('react');
9
- var shared$1 = require('../shared-2ca37369.js');
10
+ var shared$1 = require('../shared-e49b9cdc.js');
10
11
 
11
12
  /* eslint-disable @typescript-eslint/no-non-null-assertion */ function set(obj, path, value) {
12
13
  if (typeof path === 'string') {
@@ -52,9 +53,16 @@ function experimental_createTRPCNextAppDirServer(opts) {
52
53
  const pathCopy = [
53
54
  ...callOpts.path
54
55
  ];
55
- const procedureType = client.clientCallTypeToProcedureType(pathCopy.pop());
56
- const fullPath = pathCopy.join('.');
57
- return client$1[procedureType](fullPath, ...callOpts.args);
56
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
57
+ const action = pathCopy.pop();
58
+ const procedurePath = pathCopy.join('.');
59
+ const procedureType = client.clientCallTypeToProcedureType(action);
60
+ const cacheTag = shared$1.generateCacheTag(procedurePath, callOpts.args[0]);
61
+ if (action === 'revalidate') {
62
+ cache.revalidateTag(cacheTag);
63
+ return;
64
+ }
65
+ return client$1[procedureType](procedurePath, ...callOpts.args);
58
66
  });
59
67
  }
60
68
  function experimental_createServerActionHandler(t, opts) {
@@ -111,6 +119,26 @@ function experimental_createServerActionHandler(t, opts) {
111
119
  };
112
120
  };
113
121
  }
122
+ // ts-prune-ignore-next
123
+ async function experimental_revalidateEndpoint(req) {
124
+ const { cacheTag } = await req.json();
125
+ if (typeof cacheTag !== 'string') {
126
+ return new Response(JSON.stringify({
127
+ revalidated: false,
128
+ error: 'cacheTag must be a string'
129
+ }), {
130
+ status: 400
131
+ });
132
+ }
133
+ cache.revalidateTag(cacheTag);
134
+ return new Response(JSON.stringify({
135
+ revalidated: true,
136
+ now: Date.now()
137
+ }), {
138
+ status: 200
139
+ });
140
+ }
114
141
 
115
142
  exports.experimental_createServerActionHandler = experimental_createServerActionHandler;
116
143
  exports.experimental_createTRPCNextAppDirServer = experimental_createTRPCNextAppDirServer;
144
+ exports.experimental_revalidateEndpoint = experimental_revalidateEndpoint;
@@ -1,8 +1,9 @@
1
1
  import { createTRPCUntypedClient, clientCallTypeToProcedureType } from '@trpc/client';
2
2
  import { TRPCError, getTRPCErrorFromUnknown } from '@trpc/server';
3
3
  import { createRecursiveProxy, transformTRPCResponse, getErrorShape } from '@trpc/server/shared';
4
+ import { revalidateTag } from 'next/cache';
4
5
  import { cache } from 'react';
5
- import { i as isFormData } from '../shared-59b269d5.mjs';
6
+ import { g as generateCacheTag, i as isFormData } from '../shared-f6996341.mjs';
6
7
 
7
8
  /* eslint-disable @typescript-eslint/no-non-null-assertion */ function set(obj, path, value) {
8
9
  if (typeof path === 'string') {
@@ -48,9 +49,16 @@ function experimental_createTRPCNextAppDirServer(opts) {
48
49
  const pathCopy = [
49
50
  ...callOpts.path
50
51
  ];
51
- const procedureType = clientCallTypeToProcedureType(pathCopy.pop());
52
- const fullPath = pathCopy.join('.');
53
- return client[procedureType](fullPath, ...callOpts.args);
52
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
53
+ const action = pathCopy.pop();
54
+ const procedurePath = pathCopy.join('.');
55
+ const procedureType = clientCallTypeToProcedureType(action);
56
+ const cacheTag = generateCacheTag(procedurePath, callOpts.args[0]);
57
+ if (action === 'revalidate') {
58
+ revalidateTag(cacheTag);
59
+ return;
60
+ }
61
+ return client[procedureType](procedurePath, ...callOpts.args);
54
62
  });
55
63
  }
56
64
  function experimental_createServerActionHandler(t, opts) {
@@ -107,5 +115,24 @@ function experimental_createServerActionHandler(t, opts) {
107
115
  };
108
116
  };
109
117
  }
118
+ // ts-prune-ignore-next
119
+ async function experimental_revalidateEndpoint(req) {
120
+ const { cacheTag } = await req.json();
121
+ if (typeof cacheTag !== 'string') {
122
+ return new Response(JSON.stringify({
123
+ revalidated: false,
124
+ error: 'cacheTag must be a string'
125
+ }), {
126
+ status: 400
127
+ });
128
+ }
129
+ revalidateTag(cacheTag);
130
+ return new Response(JSON.stringify({
131
+ revalidated: true,
132
+ now: Date.now()
133
+ }), {
134
+ status: 200
135
+ });
136
+ }
110
137
 
111
- export { experimental_createServerActionHandler, experimental_createTRPCNextAppDirServer };
138
+ export { experimental_createServerActionHandler, experimental_createTRPCNextAppDirServer, experimental_revalidateEndpoint };
@@ -4,7 +4,7 @@ import { AnyProcedure, AnyQueryProcedure, AnyRouter, Filter, inferHandlerInput,
4
4
  * @internal
5
5
  */
6
6
  export type UseProcedureRecord<TRouter extends AnyRouter> = {
7
- [TKey in keyof Filter<TRouter['_def']['record'], AnyRouter | AnyQueryProcedure>]: TRouter['_def']['record'][TKey] extends AnyRouter ? UseProcedureRecord<TRouter['_def']['record'][TKey]> : Resolver<TRouter['_def']['record'][TKey]>;
7
+ [TKey in keyof Filter<TRouter['_def']['record'], AnyQueryProcedure | AnyRouter>]: TRouter['_def']['record'][TKey] extends AnyRouter ? UseProcedureRecord<TRouter['_def']['record'][TKey]> : Resolver<TRouter['_def']['record'][TKey]>;
8
8
  };
9
9
  export declare function createUseProxy<TRouter extends AnyRouter>(client: TRPCUntypedClient<TRouter>): UseProcedureRecord<TRouter>;
10
10
  type NextAppRouterUse<TRouter extends AnyRouter> = {
@@ -26,6 +26,7 @@ export interface CreateTRPCNextAppRouterOptions<TRouter extends AnyRouter> {
26
26
  /**
27
27
  * @internal
28
28
  */
29
+ export declare function generateCacheTag(procedurePath: string, input: any): string;
29
30
  export declare function isFormData(value: unknown): value is FormData;
30
31
  /**
31
32
  * @internal
@@ -1 +1 @@
1
- {"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../src/app-dir/shared.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,uBAAuB,EACvB,QAAQ,EACR,iBAAiB,EAClB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,YAAY,EACZ,iBAAiB,EACjB,SAAS,EACT,MAAM,EACN,iBAAiB,EACjB,qBAAqB,EACrB,OAAO,EACR,MAAM,cAAc,CAAC;AAGtB;;GAEG;AACH,MAAM,MAAM,kBAAkB,CAAC,OAAO,SAAS,SAAS,IAAI;KACzD,IAAI,IAAI,MAAM,MAAM,CACnB,OAAO,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,EACzB,SAAS,GAAG,iBAAiB,CAC9B,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,SAAS,SAAS,GACjD,kBAAkB,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAC,GACnD,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAC;CAC9C,CAAC;AAEF,wBAAgB,cAAc,CAAC,OAAO,SAAS,SAAS,EACtD,MAAM,EAAE,iBAAiB,CAAC,OAAO,CAAC,+BAOnC;AAED,KAAK,gBAAgB,CAAC,OAAO,SAAS,SAAS,IAAI;IACjD,CAAC,KAAK,SAAS,OAAO,CAAC,OAAO,CAAC,EAAE,EAC/B,EAAE,EAAE,CAAC,CAAC,EAAE,kBAAkB,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,KAAK,C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,KAAK,CAAC,CAAC;CACnB,CAAC;AACF,KAAK,2BAA2B,CAAC,OAAO,SAAS,SAAS,IAAI;IAC5D,GAAG,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAC;CAChC,CAAC;AACF,MAAM,MAAM,uBAAuB,CAAC,OAAO,SAAS,SAAS,IAC3D,qBAAqB,CACnB,2BAA2B,CAAC,OAAO,CAAC,EACpC,kBAAkB,CAAC,OAAO,CAAC,CAC5B,CAAC;AAEJ;;GAEG;AACH,MAAM,WAAW,8BAA8B,CAAC,OAAO,SAAS,SAAS;IACvE,MAAM,EAAE,MAAM,uBAAuB,CAAC,OAAO,CAAC,CAAC;CAChD;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,aAAa,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,UAIjE;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,QAAQ,CAM5D;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,KAAK,CAAC,EAAE,GAAG,CAAC;IACZ,MAAM,CAAC,EAAE,GAAG,CAAC;IACb,UAAU,EAAE,GAAG,CAAC;CACjB;AAGD;;GAEG;AACH,MAAM,MAAM,cAAc,CAAC,KAAK,SAAS,YAAY,IAAI;IACvD,KAAK,EAAE,iBAAiB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IACnC,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,aAAa,CAAC,CAAC;IACrC,UAAU,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,CAAC,QAAQ,CAAC,CAAC,YAAY,CAAC,CAAC;CAC9D,CAAC"}
@@ -0,0 +1,19 @@
1
+ import { Resolver } from '@trpc/client';
2
+ import { AnyMutationProcedure, AnyProcedure, AnyQueryProcedure, AnyRouter, AnySubscriptionProcedure, ProcedureRouterRecord } from '@trpc/server';
3
+ export type DecorateProcedureServer<TProcedure extends AnyProcedure> = TProcedure extends AnyQueryProcedure ? {
4
+ query: Resolver<TProcedure>;
5
+ revalidate: (input?: unknown) => Promise<{
6
+ revalidated: false;
7
+ error: string;
8
+ } | {
9
+ revalidated: true;
10
+ }>;
11
+ } : TProcedure extends AnyMutationProcedure ? {
12
+ mutate: Resolver<TProcedure>;
13
+ } : TProcedure extends AnySubscriptionProcedure ? {
14
+ subscribe: Resolver<TProcedure>;
15
+ } : never;
16
+ export type NextAppDirDecoratedProcedureRecord<TProcedures extends ProcedureRouterRecord> = {
17
+ [TKey in keyof TProcedures]: TProcedures[TKey] extends AnyRouter ? NextAppDirDecoratedProcedureRecord<TProcedures[TKey]['_def']['record']> : TProcedures[TKey] extends AnyProcedure ? DecorateProcedureServer<TProcedures[TKey]> : never;
18
+ };
19
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/app-dir/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACxC,OAAO,EACL,oBAAoB,EACpB,YAAY,EACZ,iBAAiB,EACjB,SAAS,EACT,wBAAwB,EACxB,qBAAqB,EACtB,MAAM,cAAc,CAAC;AAEtB,MAAM,MAAM,uBAAuB,CAAC,UAAU,SAAS,YAAY,IACjE,UAAU,SAAS,iBAAiB,GAChC;IACE,KAAK,EAAE,QAAQ,CAAC,UAAU,CAAC,CAAC;IAC5B,UAAU,EAAE,CACV,KAAK,CAAC,EAAE,OAAO,KACZ,OAAO,CACV;QAAE,WAAW,EAAE,KAAK,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,GAAG;QAAE,WAAW,EAAE,IAAI,CAAA;KAAE,CAC9D,CAAC;CACH,GACD,UAAU,SAAS,oBAAoB,GACvC;IACE,MAAM,EAAE,QAAQ,CAAC,UAAU,CAAC,CAAC;CAC9B,GACD,UAAU,SAAS,wBAAwB,GAC3C;IACE,SAAS,EAAE,QAAQ,CAAC,UAAU,CAAC,CAAC;CACjC,GACD,KAAK,CAAC;AAEZ,MAAM,MAAM,kCAAkC,CAC5C,WAAW,SAAS,qBAAqB,IACvC;KACD,IAAI,IAAI,MAAM,WAAW,GAAG,WAAW,CAAC,IAAI,CAAC,SAAS,SAAS,GAC5D,kCAAkC,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,CAAC,GACvE,WAAW,CAAC,IAAI,CAAC,SAAS,YAAY,GACtC,uBAAuB,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,GAC1C,KAAK;CACV,CAAC"}
package/dist/index.js CHANGED
@@ -67,7 +67,7 @@ function withTRPC(opts) {
67
67
  state: hydratedState
68
68
  }, /*#__PURE__*/ React__default["default"].createElement(AppOrPage, Object.assign({}, props)))));
69
69
  };
70
- if (AppOrPage.getInitialProps || opts.ssr) {
70
+ if (AppOrPage.getInitialProps ?? opts.ssr) {
71
71
  WithTRPC.getInitialProps = async (appOrPageCtx)=>{
72
72
  const AppTree = appOrPageCtx.AppTree;
73
73
  // Determine if we are wrapping an App component or a Page component.
@@ -146,8 +146,8 @@ function withTRPC(opts) {
146
146
  ].map((v)=>v.state.error).flatMap((err)=>err instanceof Error && err.name === 'TRPCClientError' ? [
147
147
  err
148
148
  ] : [])
149
- }) || {};
150
- for (const [key, value] of Object.entries(meta.headers || {})){
149
+ }) ?? {};
150
+ for (const [key, value] of Object.entries(meta.headers ?? {})){
151
151
  if (typeof value === 'string') {
152
152
  ctx.res?.setHeader(key, value);
153
153
  }
@@ -158,7 +158,7 @@ function withTRPC(opts) {
158
158
  return appTreeProps;
159
159
  };
160
160
  }
161
- const displayName = AppOrPage.displayName || AppOrPage.name || 'Component';
161
+ const displayName = AppOrPage.displayName ?? AppOrPage.name ?? 'Component';
162
162
  WithTRPC.displayName = `withTRPC(${displayName})`;
163
163
  return WithTRPC;
164
164
  };
package/dist/index.mjs CHANGED
@@ -58,7 +58,7 @@ function withTRPC(opts) {
58
58
  state: hydratedState
59
59
  }, /*#__PURE__*/ React.createElement(AppOrPage, Object.assign({}, props)))));
60
60
  };
61
- if (AppOrPage.getInitialProps || opts.ssr) {
61
+ if (AppOrPage.getInitialProps ?? opts.ssr) {
62
62
  WithTRPC.getInitialProps = async (appOrPageCtx)=>{
63
63
  const AppTree = appOrPageCtx.AppTree;
64
64
  // Determine if we are wrapping an App component or a Page component.
@@ -137,8 +137,8 @@ function withTRPC(opts) {
137
137
  ].map((v)=>v.state.error).flatMap((err)=>err instanceof Error && err.name === 'TRPCClientError' ? [
138
138
  err
139
139
  ] : [])
140
- }) || {};
141
- for (const [key, value] of Object.entries(meta.headers || {})){
140
+ }) ?? {};
141
+ for (const [key, value] of Object.entries(meta.headers ?? {})){
142
142
  if (typeof value === 'string') {
143
143
  ctx.res?.setHeader(key, value);
144
144
  }
@@ -149,7 +149,7 @@ function withTRPC(opts) {
149
149
  return appTreeProps;
150
150
  };
151
151
  }
152
- const displayName = AppOrPage.displayName || AppOrPage.name || 'Component';
152
+ const displayName = AppOrPage.displayName ?? AppOrPage.name ?? 'Component';
153
153
  WithTRPC.displayName = `withTRPC(${displayName})`;
154
154
  return WithTRPC;
155
155
  };
@@ -0,0 +1,19 @@
1
+ import '@trpc/server/shared';
2
+
3
+ /**
4
+ * @internal
5
+ */
6
+ function generateCacheTag(procedurePath, input) {
7
+ return input
8
+ ? `${procedurePath}?input=${JSON.stringify(input)}`
9
+ : procedurePath;
10
+ }
11
+ function isFormData(value) {
12
+ if (typeof FormData === 'undefined') {
13
+ // FormData is not supported
14
+ return false;
15
+ }
16
+ return value instanceof FormData;
17
+ }
18
+
19
+ export { generateCacheTag as g, isFormData as i };
@@ -4,7 +4,10 @@ require('@trpc/server/shared');
4
4
 
5
5
  /**
6
6
  * @internal
7
- */ function isFormData(value) {
7
+ */ function generateCacheTag(procedurePath, input) {
8
+ return input ? `${procedurePath}?input=${JSON.stringify(input)}` : procedurePath;
9
+ }
10
+ function isFormData(value) {
8
11
  if (typeof FormData === 'undefined') {
9
12
  // FormData is not supported
10
13
  return false;
@@ -12,4 +15,5 @@ require('@trpc/server/shared');
12
15
  return value instanceof FormData;
13
16
  }
14
17
 
18
+ exports.generateCacheTag = generateCacheTag;
15
19
  exports.isFormData = isFormData;
@@ -2,7 +2,9 @@ import '@trpc/server/shared';
2
2
 
3
3
  /**
4
4
  * @internal
5
- */
5
+ */ function generateCacheTag(procedurePath, input) {
6
+ return input ? `${procedurePath}?input=${JSON.stringify(input)}` : procedurePath;
7
+ }
6
8
  function isFormData(value) {
7
9
  if (typeof FormData === 'undefined') {
8
10
  // FormData is not supported
@@ -11,4 +13,4 @@ function isFormData(value) {
11
13
  return value instanceof FormData;
12
14
  }
13
15
 
14
- export { isFormData as i };
16
+ export { generateCacheTag as g, isFormData as i };
@@ -4,9 +4,9 @@ import { CreateTRPCReactOptions, CreateTRPCReactQueryClientConfig } from '@trpc/
4
4
  import type { AnyRouter } from '@trpc/server';
5
5
  import type { ResponseMeta } from '@trpc/server/http';
6
6
  import { NextComponentType, NextPageContext } from 'next/dist/shared/lib/utils';
7
- export type WithTRPCConfig<TRouter extends AnyRouter> = CreateTRPCClientOptions<TRouter> & {
7
+ export type WithTRPCConfig<TRouter extends AnyRouter> = CreateTRPCClientOptions<TRouter> & CreateTRPCReactQueryClientConfig & {
8
8
  abortOnUnmount?: boolean;
9
- } & CreateTRPCReactQueryClientConfig;
9
+ };
10
10
  interface WithTRPCOptions<TRouter extends AnyRouter> extends CreateTRPCReactOptions<TRouter> {
11
11
  config: (info: {
12
12
  ctx?: NextPageContext;
@@ -1 +1 @@
1
- {"version":3,"file":"withTRPC.d.ts","sourceRoot":"","sources":["../src/withTRPC.tsx"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AAC5D,OAAO,EAIL,eAAe,EAEhB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,sBAAsB,EACtB,gCAAgC,EAEjC,MAAM,0BAA0B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E,oBAAoB,CAAC,OAAO,CAAC,GAAG,kBAAkB,CAAC,OAAO,CAAC,eAU9C,kBAAkB,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,KAAG,iBAAiB,CA+KxE"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trpc/next",
3
- "version": "10.32.0",
3
+ "version": "10.33.1",
4
4
  "description": "The tRPC Next.js library",
5
5
  "author": "KATT",
6
6
  "license": "MIT",
@@ -44,6 +44,16 @@
44
44
  "import": "./dist/app-dir/client.mjs",
45
45
  "require": "./dist/app-dir/client.js",
46
46
  "default": "./dist/app-dir/client.js"
47
+ },
48
+ "./app-dir/links/nextCache": {
49
+ "import": "./dist/app-dir/links/nextCache.mjs",
50
+ "require": "./dist/app-dir/links/nextCache.js",
51
+ "default": "./dist/app-dir/links/nextCache.js"
52
+ },
53
+ "./app-dir/links/nextHttp": {
54
+ "import": "./dist/app-dir/links/nextHttp.mjs",
55
+ "require": "./dist/app-dir/links/nextHttp.js",
56
+ "default": "./dist/app-dir/links/nextHttp.js"
47
57
  }
48
58
  },
49
59
  "files": [
@@ -56,9 +66,9 @@
56
66
  ],
57
67
  "peerDependencies": {
58
68
  "@tanstack/react-query": "^4.18.0",
59
- "@trpc/client": "10.32.0",
60
- "@trpc/react-query": "10.32.0",
61
- "@trpc/server": "10.32.0",
69
+ "@trpc/client": "10.33.1",
70
+ "@trpc/react-query": "10.33.1",
71
+ "@trpc/server": "10.33.1",
62
72
  "next": "*",
63
73
  "react": ">=16.8.0",
64
74
  "react-dom": ">=16.8.0"
@@ -68,16 +78,16 @@
68
78
  },
69
79
  "devDependencies": {
70
80
  "@tanstack/react-query": "^4.18.0",
71
- "@trpc/client": "10.32.0",
72
- "@trpc/react-query": "10.32.0",
73
- "@trpc/server": "10.32.0",
81
+ "@trpc/client": "10.33.1",
82
+ "@trpc/react-query": "10.33.1",
83
+ "@trpc/server": "10.33.1",
74
84
  "@types/express": "^4.17.17",
75
85
  "@types/node": "^18.16.16",
76
86
  "@types/react": "^18.2.8",
77
87
  "@types/react-dom": "^18.2.4",
78
88
  "eslint": "^8.40.0",
79
89
  "express": "^4.17.1",
80
- "next": "^13.4.3",
90
+ "next": "^13.4.8",
81
91
  "react": "^18.2.0",
82
92
  "react-dom": "^18.2.0",
83
93
  "rollup": "^2.79.1",
@@ -90,5 +100,5 @@
90
100
  "funding": [
91
101
  "https://trpc.io/sponsor"
92
102
  ],
93
- "gitHead": "f8cf27c773b97dedb5eb95ca548cee7acb55c92a"
103
+ "gitHead": "403be02df05c29a9c3a77256805674baf6b6b125"
94
104
  }
@@ -18,15 +18,6 @@ export {
18
18
  type inferActionResultProps,
19
19
  } from './create-action-hook';
20
20
 
21
- // function normalizePromiseArray<TValue>(
22
- // promise: Promise<TValue> | Promise<TValue>[],
23
- // ) {
24
- // if (Array.isArray(promise)) {
25
- // return Promise.all(promise);
26
- // }
27
- // return promise;
28
- // }
29
-
30
21
  type QueryResult = {
31
22
  data?: unknown;
32
23
  error?: unknown;
@@ -41,33 +32,11 @@ export function experimental_createTRPCNextAppDirClient<
41
32
  // const useProxy = createUseProxy<TRouter>(client);
42
33
 
43
34
  const cache = new Map<string, QueryResult>();
44
- // return createFlatProxy<CreateTRPCNextAppRouter<TRouter>>((key) => {
45
- // if (key === 'use') {
46
- // return (
47
- // cb: (
48
- // t: UseProcedureRecord<TRouter>,
49
- // ) => Promise<unknown> | Promise<unknown>[],
50
- // ) => {
51
- // const promise = normalizePromiseArray(cb(useProxy));
52
- // throw promise;
53
- // // const [data, setData] = useState<unknown | unknown[]>();
54
-
55
- // // useEffect(() => {
56
- // // const promise = normalizePromiseArray(cb(useProxy));
57
-
58
- // // void promise.then(setData).catch((err) => {
59
- // // throw err;
60
- // // });
61
- // // // eslint-disable-next-line react-hooks/exhaustive-deps
62
- // // }, []);
63
-
64
- // // return data;
65
- // };
66
- // }
67
35
 
68
36
  return createRecursiveProxy(({ path, args }) => {
69
37
  // const pathCopy = [key, ...path];
70
38
  const pathCopy = [...path];
39
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
71
40
  const procedureType = clientCallTypeToProcedureType(pathCopy.pop()!);
72
41
 
73
42
  if (procedureType === 'query') {
@@ -21,7 +21,7 @@ import { ActionHandlerDef, isFormData } from './shared';
21
21
 
22
22
  type MutationArgs<TDef extends ActionHandlerDef> = TDef['input'] extends void
23
23
  ? [input?: undefined | void, opts?: ProcedureOptions]
24
- : [input: TDef['input'] | FormData, opts?: ProcedureOptions];
24
+ : [input: FormData | TDef['input'], opts?: ProcedureOptions];
25
25
 
26
26
  interface UseTRPCActionBaseResult<TDef extends ActionHandlerDef> {
27
27
  mutate: (...args: MutationArgs<TDef>) => void;
@@ -58,10 +58,10 @@ interface UseTRPCActionLoadingResult<TDef extends ActionHandlerDef>
58
58
 
59
59
  // ts-prune-ignore-next
60
60
  export type UseTRPCActionResult<TDef extends ActionHandlerDef> =
61
- | UseTRPCActionSuccessResult<TDef>
62
61
  | UseTRPCActionErrorResult<TDef>
63
62
  | UseTRPCActionIdleResult<TDef>
64
- | UseTRPCActionLoadingResult<TDef>;
63
+ | UseTRPCActionLoadingResult<TDef>
64
+ | UseTRPCActionSuccessResult<TDef>;
65
65
 
66
66
  type ActionContext = {
67
67
  _action: (...args: any[]) => Promise<any>;
@@ -95,7 +95,9 @@ export function experimental_serverActionLink<
95
95
  });
96
96
  observer.complete();
97
97
  })
98
- .catch((cause) => observer.error(TRPCClientError.from(cause)));
98
+ .catch((cause) => {
99
+ observer.error(TRPCClientError.from(cause));
100
+ });
99
101
  });
100
102
  }
101
103
 
@@ -110,7 +112,7 @@ export type inferActionResultProps<TProc extends AnyProcedure> = {
110
112
  };
111
113
 
112
114
  interface UseTRPCActionOptions<TDef extends ActionHandlerDef> {
113
- onSuccess?: (result: TDef['output']) => void | MaybePromise<void>;
115
+ onSuccess?: (result: TDef['output']) => MaybePromise<void> | void;
114
116
  onError?: (result: TRPCClientError<TDef['errorShape']>) => MaybePromise<void>;
115
117
  }
116
118
 
@@ -1,7 +1,7 @@
1
1
  /* eslint-disable @typescript-eslint/no-non-null-assertion */
2
2
  function set(
3
3
  obj: Record<string, any>,
4
- path: string | string[],
4
+ path: string[] | string,
5
5
  value: unknown,
6
6
  ): void {
7
7
  if (typeof path === 'string') {
@@ -0,0 +1,72 @@
1
+ // import "server-only";
2
+
3
+ import { TRPCClientError, TRPCLink } from '@trpc/client';
4
+ import { AnyRouter, callProcedure, inferRouterContext } from '@trpc/server';
5
+ import { observable } from '@trpc/server/observable';
6
+ import { unstable_cache } from 'next/cache';
7
+ import { generateCacheTag } from '../shared';
8
+
9
+ type NextCacheLinkOptions<TRouter extends AnyRouter> = {
10
+ router: TRouter;
11
+ createContext: () => Promise<inferRouterContext<TRouter>>;
12
+ /** how many seconds the cache should hold before revalidating */
13
+ revalidate?: number | false;
14
+ };
15
+
16
+ // ts-prune-ignore-next
17
+ export function experimental_nextCacheLink<TRouter extends AnyRouter>(
18
+ opts: NextCacheLinkOptions<TRouter>,
19
+ ): TRPCLink<TRouter> {
20
+ return (runtime) =>
21
+ ({ op }) =>
22
+ observable((observer) => {
23
+ const { path, input, type, context } = op;
24
+
25
+ const cacheTag = generateCacheTag(path, input);
26
+ // Let per-request revalidate override global revalidate
27
+ const requestRevalidate =
28
+ typeof context.revalidate === 'number' || context.revalidate === false
29
+ ? context.revalidate
30
+ : undefined;
31
+ const revalidate = requestRevalidate ?? opts.revalidate ?? false;
32
+
33
+ const promise = opts
34
+ .createContext()
35
+ .then(async (ctx) => {
36
+ const callProc = async () => {
37
+ const procedureResult = await callProcedure({
38
+ procedures: opts.router._def.procedures,
39
+ path,
40
+ rawInput: input,
41
+ ctx: ctx,
42
+ type,
43
+ });
44
+
45
+ // We need to serialize cause the cache only accepts JSON
46
+ return runtime.transformer.serialize(procedureResult);
47
+ };
48
+
49
+ if (type === 'query') {
50
+ return unstable_cache(callProc, path.split('.'), {
51
+ revalidate,
52
+ tags: [cacheTag],
53
+ })();
54
+ }
55
+
56
+ return callProc();
57
+ })
58
+ .catch((cause) => {
59
+ observer.error(TRPCClientError.from(cause));
60
+ });
61
+
62
+ promise
63
+ .then((data) => {
64
+ const transformedResult = runtime.transformer.deserialize(data);
65
+ observer.next({ result: { data: transformedResult } });
66
+ observer.complete();
67
+ })
68
+ .catch((cause) => {
69
+ observer.error(TRPCClientError.from(cause));
70
+ });
71
+ });
72
+ }
@@ -0,0 +1,54 @@
1
+ import {
2
+ httpBatchLink,
3
+ HTTPBatchLinkOptions,
4
+ httpLink,
5
+ HTTPLinkOptions,
6
+ TRPCLink,
7
+ } from '@trpc/client';
8
+ import { AnyRouter } from '@trpc/server';
9
+ import { generateCacheTag } from '../shared';
10
+
11
+ type NextFetchLinkOptions<TBatch extends boolean> = (TBatch extends true
12
+ ? HTTPBatchLinkOptions
13
+ : HTTPLinkOptions) & {
14
+ batch?: TBatch;
15
+ revalidate?: number | false;
16
+ };
17
+
18
+ // ts-prune-ignore-next
19
+ export function experimental_nextHttpLink<
20
+ TRouter extends AnyRouter,
21
+ TBatch extends boolean,
22
+ >(opts: NextFetchLinkOptions<TBatch>): TRPCLink<TRouter> {
23
+ return (runtime) => {
24
+ return (ctx) => {
25
+ const { path, input, context } = ctx.op;
26
+ const cacheTag = generateCacheTag(path, input);
27
+
28
+ // Let per-request revalidate override global revalidate
29
+ const requestRevalidate =
30
+ typeof context.revalidate === 'number' || context.revalidate === false
31
+ ? context.revalidate
32
+ : undefined;
33
+ const revalidate = requestRevalidate ?? opts.revalidate ?? false;
34
+
35
+ const linkFactory = opts.batch ? httpBatchLink : httpLink;
36
+ const link = linkFactory({
37
+ headers: opts.headers as any,
38
+ url: opts.url,
39
+ fetch: (url, fetchOpts) => {
40
+ return fetch(url, {
41
+ ...fetchOpts,
42
+ // cache: 'no-cache',
43
+ next: {
44
+ revalidate,
45
+ tags: [cacheTag],
46
+ },
47
+ });
48
+ },
49
+ })(runtime);
50
+
51
+ return link(ctx);
52
+ };
53
+ };
54
+ }
@@ -1,7 +1,6 @@
1
1
  /// <reference types="next" />
2
2
  import {
3
3
  clientCallTypeToProcedureType,
4
- CreateTRPCProxyClient,
5
4
  createTRPCUntypedClient,
6
5
  } from '@trpc/client';
7
6
  import {
@@ -21,14 +20,17 @@ import {
21
20
  getErrorShape,
22
21
  transformTRPCResponse,
23
22
  } from '@trpc/server/shared';
23
+ import { revalidateTag } from 'next/cache';
24
24
  import { cache } from 'react';
25
25
  import { formDataToObject } from './formDataToObject';
26
26
  import {
27
27
  ActionHandlerDef,
28
28
  CreateTRPCNextAppRouterOptions,
29
+ generateCacheTag,
29
30
  inferActionDef,
30
31
  isFormData,
31
32
  } from './shared';
33
+ import { NextAppDirDecoratedProcedureRecord } from './types';
32
34
 
33
35
  // ts-prune-ignore-next
34
36
  export function experimental_createTRPCNextAppDirServer<
@@ -44,20 +46,26 @@ export function experimental_createTRPCNextAppDirServer<
44
46
  const client = getClient();
45
47
 
46
48
  const pathCopy = [...callOpts.path];
47
- const procedureType = clientCallTypeToProcedureType(
48
- pathCopy.pop() as string,
49
- );
50
- const fullPath = pathCopy.join('.');
49
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
50
+ const action = pathCopy.pop()!;
51
+ const procedurePath = pathCopy.join('.');
52
+ const procedureType = clientCallTypeToProcedureType(action);
53
+ const cacheTag = generateCacheTag(procedurePath, callOpts.args[0]);
54
+
55
+ if (action === 'revalidate') {
56
+ revalidateTag(cacheTag);
57
+ return;
58
+ }
51
59
 
52
- return (client[procedureType] as any)(fullPath, ...callOpts.args);
53
- }) as CreateTRPCProxyClient<TRouter>;
60
+ return (client[procedureType] as any)(procedurePath, ...callOpts.args);
61
+ }) as NextAppDirDecoratedProcedureRecord<TRouter['_def']['record']>;
54
62
  }
55
63
 
56
64
  /**
57
65
  * @internal
58
66
  */
59
67
  export type TRPCActionHandler<TDef extends ActionHandlerDef> = (
60
- input: TDef['input'] | FormData,
68
+ input: FormData | TDef['input'],
61
69
  ) => Promise<TRPCResponse<TDef['output'], TDef['errorShape']>>;
62
70
 
63
71
  export function experimental_createServerActionHandler<
@@ -85,9 +93,9 @@ export function experimental_createServerActionHandler<
85
93
  proc: TProc,
86
94
  ): TRPCActionHandler<Simplify<inferActionDef<TProc>>> {
87
95
  return async function actionHandler(
88
- rawInput: inferProcedureInput<TProc> | FormData,
96
+ rawInput: FormData | inferProcedureInput<TProc>,
89
97
  ) {
90
- const ctx: undefined | TInstance['_config']['$types']['ctx'] = undefined;
98
+ const ctx: TInstance['_config']['$types']['ctx'] | undefined = undefined;
91
99
  try {
92
100
  const ctx = await createContext();
93
101
  if (normalizeFormData && isFormData(rawInput)) {
@@ -138,3 +146,23 @@ export function experimental_createServerActionHandler<
138
146
  } as TRPCActionHandler<inferActionDef<TProc>>;
139
147
  };
140
148
  }
149
+
150
+ // ts-prune-ignore-next
151
+ export async function experimental_revalidateEndpoint(req: Request) {
152
+ const { cacheTag } = await req.json();
153
+
154
+ if (typeof cacheTag !== 'string') {
155
+ return new Response(
156
+ JSON.stringify({
157
+ revalidated: false,
158
+ error: 'cacheTag must be a string',
159
+ }),
160
+ { status: 400 },
161
+ );
162
+ }
163
+
164
+ revalidateTag(cacheTag);
165
+ return new Response(JSON.stringify({ revalidated: true, now: Date.now() }), {
166
+ status: 200,
167
+ });
168
+ }
@@ -20,7 +20,7 @@ import { createRecursiveProxy } from '@trpc/server/shared';
20
20
  export type UseProcedureRecord<TRouter extends AnyRouter> = {
21
21
  [TKey in keyof Filter<
22
22
  TRouter['_def']['record'],
23
- AnyRouter | AnyQueryProcedure
23
+ AnyQueryProcedure | AnyRouter
24
24
  >]: TRouter['_def']['record'][TKey] extends AnyRouter
25
25
  ? UseProcedureRecord<TRouter['_def']['record'][TKey]>
26
26
  : Resolver<TRouter['_def']['record'][TKey]>;
@@ -65,6 +65,12 @@ export interface CreateTRPCNextAppRouterOptions<TRouter extends AnyRouter> {
65
65
  /**
66
66
  * @internal
67
67
  */
68
+ export function generateCacheTag(procedurePath: string, input: any) {
69
+ return input
70
+ ? `${procedurePath}?input=${JSON.stringify(input)}`
71
+ : procedurePath;
72
+ }
73
+
68
74
  export function isFormData(value: unknown): value is FormData {
69
75
  if (typeof FormData === 'undefined') {
70
76
  // FormData is not supported
@@ -0,0 +1,39 @@
1
+ import { Resolver } from '@trpc/client';
2
+ import {
3
+ AnyMutationProcedure,
4
+ AnyProcedure,
5
+ AnyQueryProcedure,
6
+ AnyRouter,
7
+ AnySubscriptionProcedure,
8
+ ProcedureRouterRecord,
9
+ } from '@trpc/server';
10
+
11
+ export type DecorateProcedureServer<TProcedure extends AnyProcedure> =
12
+ TProcedure extends AnyQueryProcedure
13
+ ? {
14
+ query: Resolver<TProcedure>;
15
+ revalidate: (
16
+ input?: unknown,
17
+ ) => Promise<
18
+ { revalidated: false; error: string } | { revalidated: true }
19
+ >;
20
+ }
21
+ : TProcedure extends AnyMutationProcedure
22
+ ? {
23
+ mutate: Resolver<TProcedure>;
24
+ }
25
+ : TProcedure extends AnySubscriptionProcedure
26
+ ? {
27
+ subscribe: Resolver<TProcedure>;
28
+ }
29
+ : never;
30
+
31
+ export type NextAppDirDecoratedProcedureRecord<
32
+ TProcedures extends ProcedureRouterRecord,
33
+ > = {
34
+ [TKey in keyof TProcedures]: TProcedures[TKey] extends AnyRouter
35
+ ? NextAppDirDecoratedProcedureRecord<TProcedures[TKey]['_def']['record']>
36
+ : TProcedures[TKey] extends AnyProcedure
37
+ ? DecorateProcedureServer<TProcedures[TKey]>
38
+ : never;
39
+ };
package/src/withTRPC.tsx CHANGED
@@ -36,8 +36,8 @@ import ssrPrepass from 'react-ssr-prepass';
36
36
 
37
37
  function transformQueryOrMutationCacheErrors<
38
38
  TState extends
39
- | DehydratedState['queries'][0]
40
- | DehydratedState['mutations'][0],
39
+ | DehydratedState['mutations'][0]
40
+ | DehydratedState['queries'][0],
41
41
  >(result: TState): TState {
42
42
  const error = result.state.error as Maybe<TRPCClientError<any>>;
43
43
  if (error instanceof Error && error.name === 'TRPCClientError') {
@@ -57,9 +57,10 @@ function transformQueryOrMutationCacheErrors<
57
57
  return result;
58
58
  }
59
59
  export type WithTRPCConfig<TRouter extends AnyRouter> =
60
- CreateTRPCClientOptions<TRouter> & {
61
- abortOnUnmount?: boolean;
62
- } & CreateTRPCReactQueryClientConfig;
60
+ CreateTRPCClientOptions<TRouter> &
61
+ CreateTRPCReactQueryClientConfig & {
62
+ abortOnUnmount?: boolean;
63
+ };
63
64
 
64
65
  interface WithTRPCOptions<TRouter extends AnyRouter>
65
66
  extends CreateTRPCReactOptions<TRouter> {
@@ -142,7 +143,7 @@ export function withTRPC<
142
143
  );
143
144
  };
144
145
 
145
- if (AppOrPage.getInitialProps || opts.ssr) {
146
+ if (AppOrPage.getInitialProps ?? opts.ssr) {
146
147
  WithTRPC.getInitialProps = async (appOrPageCtx: AppContextType) => {
147
148
  const AppTree = appOrPageCtx.AppTree;
148
149
 
@@ -248,9 +249,9 @@ export function withTRPC<
248
249
  ? [err as TRPCClientError<TRouter>]
249
250
  : [],
250
251
  ),
251
- }) || {};
252
+ }) ?? {};
252
253
 
253
- for (const [key, value] of Object.entries(meta.headers || {})) {
254
+ for (const [key, value] of Object.entries(meta.headers ?? {})) {
254
255
  if (typeof value === 'string') {
255
256
  ctx.res?.setHeader(key, value);
256
257
  }
@@ -262,7 +263,7 @@ export function withTRPC<
262
263
  };
263
264
  }
264
265
 
265
- const displayName = AppOrPage.displayName || AppOrPage.name || 'Component';
266
+ const displayName = AppOrPage.displayName ?? AppOrPage.name ?? 'Component';
266
267
  WithTRPC.displayName = `withTRPC(${displayName})`;
267
268
 
268
269
  return WithTRPC as any;
@@ -1,13 +0,0 @@
1
- import '@trpc/server/shared';
2
-
3
- /**
4
- * @internal
5
- */ function isFormData(value) {
6
- if (typeof FormData === 'undefined') {
7
- // FormData is not supported
8
- return false;
9
- }
10
- return value instanceof FormData;
11
- }
12
-
13
- export { isFormData as i };