@trpc/next 11.3.1 → 11.3.2-canary.2
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
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import type { CreateTRPCClientOptions, TRPCLink, TRPCProcedureOptions } from '@trpc/client';
|
|
2
|
-
import { TRPCClientError } from '@trpc/client';
|
|
3
|
-
import type { TransformerOptions } from '@trpc/client/unstable-internals';
|
|
4
|
-
import type { inferClientTypes, InferrableClientTypes, MaybePromise, Simplify, TypeError } from '@trpc/server/unstable-core-do-not-import';
|
|
5
|
-
import type { TRPCActionHandler } from './server';
|
|
6
|
-
import type { ActionHandlerDef } from './shared';
|
|
7
|
-
type MutationArgs<TDef extends ActionHandlerDef> = TDef['input'] extends void ? [input?: undefined | void, opts?: TRPCProcedureOptions] : [input: FormData | TDef['input'], opts?: TRPCProcedureOptions];
|
|
8
|
-
interface UseTRPCActionBaseResult<TDef extends ActionHandlerDef> {
|
|
9
|
-
mutate: (...args: MutationArgs<TDef>) => void;
|
|
10
|
-
mutateAsync: (...args: MutationArgs<TDef>) => Promise<TDef['output']>;
|
|
11
|
-
}
|
|
12
|
-
interface UseTRPCActionSuccessResult<TDef extends ActionHandlerDef> extends UseTRPCActionBaseResult<TDef> {
|
|
13
|
-
data: TDef['output'];
|
|
14
|
-
error?: never;
|
|
15
|
-
status: 'success';
|
|
16
|
-
}
|
|
17
|
-
interface UseTRPCActionErrorResult<TDef extends ActionHandlerDef> extends UseTRPCActionBaseResult<TDef> {
|
|
18
|
-
data?: never;
|
|
19
|
-
error: TRPCClientError<TDef['errorShape']>;
|
|
20
|
-
status: 'error';
|
|
21
|
-
}
|
|
22
|
-
interface UseTRPCActionIdleResult<TDef extends ActionHandlerDef> extends UseTRPCActionBaseResult<TDef> {
|
|
23
|
-
data?: never;
|
|
24
|
-
error?: never;
|
|
25
|
-
status: 'idle';
|
|
26
|
-
}
|
|
27
|
-
interface UseTRPCActionLoadingResult<TDef extends ActionHandlerDef> extends UseTRPCActionBaseResult<TDef> {
|
|
28
|
-
data?: never;
|
|
29
|
-
error?: never;
|
|
30
|
-
status: 'loading';
|
|
31
|
-
}
|
|
32
|
-
export type UseTRPCActionResult<TDef extends ActionHandlerDef> = UseTRPCActionErrorResult<TDef> | UseTRPCActionIdleResult<TDef> | UseTRPCActionLoadingResult<TDef> | UseTRPCActionSuccessResult<TDef>;
|
|
33
|
-
export declare function experimental_serverActionLink<TInferrable extends InferrableClientTypes>(...args: InferrableClientTypes extends TInferrable ? [
|
|
34
|
-
TypeError<'Generic parameter missing in `experimental_createActionHook<HERE>()` or experimental_serverActionLink<HERE>()'>
|
|
35
|
-
] : inferClientTypes<TInferrable>['transformer'] extends true ? [
|
|
36
|
-
opts: TransformerOptions<{
|
|
37
|
-
transformer: true;
|
|
38
|
-
}>
|
|
39
|
-
] : [
|
|
40
|
-
opts?: TransformerOptions<{
|
|
41
|
-
transformer: false;
|
|
42
|
-
}>
|
|
43
|
-
]): TRPCLink<TInferrable>;
|
|
44
|
-
interface UseTRPCActionOptions<TDef extends ActionHandlerDef> {
|
|
45
|
-
onSuccess?: (result: TDef['output']) => MaybePromise<void> | void;
|
|
46
|
-
onError?: (result: TRPCClientError<TDef['errorShape']>) => MaybePromise<void>;
|
|
47
|
-
}
|
|
48
|
-
export declare function experimental_createActionHook<TInferrable extends InferrableClientTypes>(opts: InferrableClientTypes extends TInferrable ? TypeError<'Generic parameter missing in `experimental_createActionHook<HERE>()`'> : CreateTRPCClientOptions<TInferrable>): <TDef extends ActionHandlerDef>(handler: TRPCActionHandler<TDef>, useActionOpts?: UseTRPCActionOptions<Simplify<TDef>>) => UseTRPCActionResult<TDef>;
|
|
49
|
-
export {};
|
|
50
|
-
//# sourceMappingURL=create-action-hook.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"create-action-hook.d.ts","sourceRoot":"","sources":["../../src/app-dir/create-action-hook.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,uBAAuB,EACvB,QAAQ,EACR,oBAAoB,EAErB,MAAM,cAAc,CAAC;AACtB,OAAO,EAA2B,eAAe,EAAE,MAAM,cAAc,CAAC;AACxE,OAAO,KAAK,EAEV,kBAAkB,EACnB,MAAM,iCAAiC,CAAC;AAGzC,OAAO,KAAK,EACV,gBAAgB,EAChB,qBAAqB,EACrB,YAAY,EACZ,QAAQ,EACR,SAAS,EACV,MAAM,0CAA0C,CAAC;AAGlD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAClD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAGjD,KAAK,YAAY,CAAC,IAAI,SAAS,gBAAgB,IAAI,IAAI,CAAC,OAAO,CAAC,SAAS,IAAI,GACzE,CAAC,KAAK,CAAC,EAAE,SAAS,GAAG,IAAI,EAAE,IAAI,CAAC,EAAE,oBAAoB,CAAC,GACvD,CAAC,KAAK,EAAE,QAAQ,GA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');
|
|
5
|
-
var observable = require('@trpc/server/observable');
|
|
6
|
-
var unstableCoreDoNotImport = require('@trpc/server/unstable-core-do-not-import');
|
|
7
|
-
var React = require('react');
|
|
8
|
-
var shared = require('./shared.js');
|
|
9
|
-
|
|
10
|
-
// ts-prune-ignore-next
|
|
11
|
-
function experimental_serverActionLink(...args) {
|
|
12
|
-
const [opts] = args;
|
|
13
|
-
const transformer = unstableInternals.getTransformer(opts?.transformer);
|
|
14
|
-
return ()=>({ op })=>observable.observable((observer)=>{
|
|
15
|
-
const context = op.context;
|
|
16
|
-
context._action(shared.isFormData(op.input) ? op.input : transformer.input.serialize(op.input)).then((data)=>{
|
|
17
|
-
const transformed = unstableCoreDoNotImport.transformResult(data, transformer.output);
|
|
18
|
-
if (!transformed.ok) {
|
|
19
|
-
observer.error(client.TRPCClientError.from(transformed.error, {}));
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
observer.next({
|
|
23
|
-
context: op.context,
|
|
24
|
-
result: transformed.result
|
|
25
|
-
});
|
|
26
|
-
observer.complete();
|
|
27
|
-
}).catch((cause)=>{
|
|
28
|
-
observer.error(client.TRPCClientError.from(cause));
|
|
29
|
-
});
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
// ts-prune-ignore-next
|
|
33
|
-
function experimental_createActionHook(opts) {
|
|
34
|
-
const client$1 = client.createTRPCUntypedClient(opts);
|
|
35
|
-
return function useAction(handler, useActionOpts) {
|
|
36
|
-
const count = React.useRef(0);
|
|
37
|
-
const [state, setState] = React.useState({
|
|
38
|
-
status: 'idle'
|
|
39
|
-
});
|
|
40
|
-
const actionOptsRef = React.useRef(useActionOpts);
|
|
41
|
-
actionOptsRef.current = useActionOpts;
|
|
42
|
-
React.useEffect(()=>{
|
|
43
|
-
return ()=>{
|
|
44
|
-
// cleanup after unmount to prevent calling hook opts after unmount
|
|
45
|
-
count.current = -1;
|
|
46
|
-
actionOptsRef.current = undefined;
|
|
47
|
-
};
|
|
48
|
-
}, []);
|
|
49
|
-
const mutateAsync = React.useCallback((input, requestOptions)=>{
|
|
50
|
-
const idx = ++count.current;
|
|
51
|
-
const context = {
|
|
52
|
-
...requestOptions?.context,
|
|
53
|
-
_action (innerInput) {
|
|
54
|
-
return handler(innerInput);
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
setState({
|
|
58
|
-
status: 'loading'
|
|
59
|
-
});
|
|
60
|
-
return client$1.mutation('serverAction', input, {
|
|
61
|
-
...requestOptions,
|
|
62
|
-
context
|
|
63
|
-
}).then(async (data)=>{
|
|
64
|
-
await actionOptsRef.current?.onSuccess?.(data);
|
|
65
|
-
if (idx !== count.current) {
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
setState({
|
|
69
|
-
status: 'success',
|
|
70
|
-
data: data
|
|
71
|
-
});
|
|
72
|
-
}).catch(async (error)=>{
|
|
73
|
-
await actionOptsRef.current?.onError?.(error);
|
|
74
|
-
throw error;
|
|
75
|
-
}).catch((error)=>{
|
|
76
|
-
if (idx !== count.current) {
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
setState({
|
|
80
|
-
status: 'error',
|
|
81
|
-
error: client.TRPCClientError.from(error, {})
|
|
82
|
-
});
|
|
83
|
-
throw error;
|
|
84
|
-
});
|
|
85
|
-
}, [
|
|
86
|
-
handler
|
|
87
|
-
]);
|
|
88
|
-
const mutate = React.useCallback((...args)=>{
|
|
89
|
-
void mutateAsync(...args).catch(()=>{
|
|
90
|
-
// ignored
|
|
91
|
-
});
|
|
92
|
-
}, [
|
|
93
|
-
mutateAsync
|
|
94
|
-
]);
|
|
95
|
-
return React.useMemo(()=>({
|
|
96
|
-
...state,
|
|
97
|
-
mutate,
|
|
98
|
-
mutateAsync
|
|
99
|
-
}), [
|
|
100
|
-
mutate,
|
|
101
|
-
mutateAsync,
|
|
102
|
-
state
|
|
103
|
-
]);
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
exports.experimental_createActionHook = experimental_createActionHook;
|
|
108
|
-
exports.experimental_serverActionLink = experimental_serverActionLink;
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import { createTRPCUntypedClient, TRPCClientError } from '@trpc/client';
|
|
2
|
-
import { getTransformer } from '@trpc/client/unstable-internals';
|
|
3
|
-
import { observable } from '@trpc/server/observable';
|
|
4
|
-
import { transformResult } from '@trpc/server/unstable-core-do-not-import';
|
|
5
|
-
import { useRef, useState, useEffect, useCallback, useMemo } from 'react';
|
|
6
|
-
import { isFormData } from './shared.mjs';
|
|
7
|
-
|
|
8
|
-
// ts-prune-ignore-next
|
|
9
|
-
function experimental_serverActionLink(...args) {
|
|
10
|
-
const [opts] = args;
|
|
11
|
-
const transformer = getTransformer(opts?.transformer);
|
|
12
|
-
return ()=>({ op })=>observable((observer)=>{
|
|
13
|
-
const context = op.context;
|
|
14
|
-
context._action(isFormData(op.input) ? op.input : transformer.input.serialize(op.input)).then((data)=>{
|
|
15
|
-
const transformed = transformResult(data, transformer.output);
|
|
16
|
-
if (!transformed.ok) {
|
|
17
|
-
observer.error(TRPCClientError.from(transformed.error, {}));
|
|
18
|
-
return;
|
|
19
|
-
}
|
|
20
|
-
observer.next({
|
|
21
|
-
context: op.context,
|
|
22
|
-
result: transformed.result
|
|
23
|
-
});
|
|
24
|
-
observer.complete();
|
|
25
|
-
}).catch((cause)=>{
|
|
26
|
-
observer.error(TRPCClientError.from(cause));
|
|
27
|
-
});
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
// ts-prune-ignore-next
|
|
31
|
-
function experimental_createActionHook(opts) {
|
|
32
|
-
const client = createTRPCUntypedClient(opts);
|
|
33
|
-
return function useAction(handler, useActionOpts) {
|
|
34
|
-
const count = useRef(0);
|
|
35
|
-
const [state, setState] = useState({
|
|
36
|
-
status: 'idle'
|
|
37
|
-
});
|
|
38
|
-
const actionOptsRef = useRef(useActionOpts);
|
|
39
|
-
actionOptsRef.current = useActionOpts;
|
|
40
|
-
useEffect(()=>{
|
|
41
|
-
return ()=>{
|
|
42
|
-
// cleanup after unmount to prevent calling hook opts after unmount
|
|
43
|
-
count.current = -1;
|
|
44
|
-
actionOptsRef.current = undefined;
|
|
45
|
-
};
|
|
46
|
-
}, []);
|
|
47
|
-
const mutateAsync = useCallback((input, requestOptions)=>{
|
|
48
|
-
const idx = ++count.current;
|
|
49
|
-
const context = {
|
|
50
|
-
...requestOptions?.context,
|
|
51
|
-
_action (innerInput) {
|
|
52
|
-
return handler(innerInput);
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
setState({
|
|
56
|
-
status: 'loading'
|
|
57
|
-
});
|
|
58
|
-
return client.mutation('serverAction', input, {
|
|
59
|
-
...requestOptions,
|
|
60
|
-
context
|
|
61
|
-
}).then(async (data)=>{
|
|
62
|
-
await actionOptsRef.current?.onSuccess?.(data);
|
|
63
|
-
if (idx !== count.current) {
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
setState({
|
|
67
|
-
status: 'success',
|
|
68
|
-
data: data
|
|
69
|
-
});
|
|
70
|
-
}).catch(async (error)=>{
|
|
71
|
-
await actionOptsRef.current?.onError?.(error);
|
|
72
|
-
throw error;
|
|
73
|
-
}).catch((error)=>{
|
|
74
|
-
if (idx !== count.current) {
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
setState({
|
|
78
|
-
status: 'error',
|
|
79
|
-
error: TRPCClientError.from(error, {})
|
|
80
|
-
});
|
|
81
|
-
throw error;
|
|
82
|
-
});
|
|
83
|
-
}, [
|
|
84
|
-
handler
|
|
85
|
-
]);
|
|
86
|
-
const mutate = useCallback((...args)=>{
|
|
87
|
-
void mutateAsync(...args).catch(()=>{
|
|
88
|
-
// ignored
|
|
89
|
-
});
|
|
90
|
-
}, [
|
|
91
|
-
mutateAsync
|
|
92
|
-
]);
|
|
93
|
-
return useMemo(()=>({
|
|
94
|
-
...state,
|
|
95
|
-
mutate,
|
|
96
|
-
mutateAsync
|
|
97
|
-
}), [
|
|
98
|
-
mutate,
|
|
99
|
-
mutateAsync,
|
|
100
|
-
state
|
|
101
|
-
]);
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
export { experimental_createActionHook, experimental_serverActionLink };
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { TRPCLink } from '@trpc/client';
|
|
2
|
-
import { type TransformerOptions } from '@trpc/client/unstable-internals';
|
|
3
|
-
import type { AnyRouter, inferClientTypes, inferRouterContext } from '@trpc/server/unstable-core-do-not-import';
|
|
4
|
-
type NextCacheLinkOptions<TRouter extends AnyRouter> = {
|
|
5
|
-
router: TRouter;
|
|
6
|
-
createContext: () => Promise<inferRouterContext<TRouter>>;
|
|
7
|
-
/** how many seconds the cache should hold before revalidating */
|
|
8
|
-
revalidate?: number | false;
|
|
9
|
-
} & TransformerOptions<inferClientTypes<TRouter>>;
|
|
10
|
-
export declare function experimental_nextCacheLink<TRouter extends AnyRouter>(opts: NextCacheLinkOptions<TRouter>): TRPCLink<TRouter>;
|
|
11
|
-
export {};
|
|
12
|
-
//# sourceMappingURL=nextCache.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"nextCache.d.ts","sourceRoot":"","sources":["../../../src/app-dir/links/nextCache.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAE7C,OAAO,EAEL,KAAK,kBAAkB,EACxB,MAAM,iCAAiC,CAAC;AAEzC,OAAO,KAAK,EACV,SAAS,EACT,gBAAgB,EAChB,kBAAkB,EACnB,MAAM,0CAA0C,CAAC;AAKlD,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,GAAG,kBAAkB,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,CAAC;AAGlD,wBAAgB,0BAA0B,CAAC,OAAO,SAAS,SAAS,EAClE,IAAI,EAAE,oBAAoB,CAAC,OAAO,CAAC,GAClC,QAAQ,CAAC,OAAO,CAAC,CA2DnB"}
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var client = require('@trpc/client');
|
|
4
|
-
var unstableInternals = require('@trpc/client/unstable-internals');
|
|
5
|
-
var observable = require('@trpc/server/observable');
|
|
6
|
-
var unstableCoreDoNotImport = require('@trpc/server/unstable-core-do-not-import');
|
|
7
|
-
var cache = require('next/cache');
|
|
8
|
-
var shared = require('../shared.js');
|
|
9
|
-
|
|
10
|
-
// import "server-only";
|
|
11
|
-
// ts-prune-ignore-next
|
|
12
|
-
function experimental_nextCacheLink(opts) {
|
|
13
|
-
const transformer = unstableInternals.getTransformer(opts.transformer);
|
|
14
|
-
return ()=>({ op })=>observable.observable((observer)=>{
|
|
15
|
-
const { path, input, type, context } = op;
|
|
16
|
-
const cacheTag = shared.generateCacheTag(path, input);
|
|
17
|
-
// Let per-request revalidate override global revalidate
|
|
18
|
-
const requestRevalidate = typeof context['revalidate'] === 'number' || context['revalidate'] === false ? context['revalidate'] : undefined;
|
|
19
|
-
const revalidate = requestRevalidate ?? opts.revalidate ?? false;
|
|
20
|
-
const promise = opts.createContext().then(async (ctx)=>{
|
|
21
|
-
const callProc = async (_cachebuster)=>{
|
|
22
|
-
// // _cachebuster is not used by us but to make sure
|
|
23
|
-
// // that calls with different tags are properly separated
|
|
24
|
-
// // @link https://github.com/trpc/trpc/issues/4622
|
|
25
|
-
const procedureResult = await unstableCoreDoNotImport.callProcedure({
|
|
26
|
-
router: opts.router,
|
|
27
|
-
path,
|
|
28
|
-
getRawInput: async ()=>input,
|
|
29
|
-
ctx: ctx,
|
|
30
|
-
type,
|
|
31
|
-
signal: undefined
|
|
32
|
-
});
|
|
33
|
-
// We need to serialize cause the cache only accepts JSON
|
|
34
|
-
return transformer.input.serialize(procedureResult);
|
|
35
|
-
};
|
|
36
|
-
if (type === 'query') {
|
|
37
|
-
return cache.unstable_cache(callProc, path.split('.'), {
|
|
38
|
-
revalidate,
|
|
39
|
-
tags: [
|
|
40
|
-
cacheTag
|
|
41
|
-
]
|
|
42
|
-
})(cacheTag);
|
|
43
|
-
}
|
|
44
|
-
return callProc();
|
|
45
|
-
}).catch((cause)=>{
|
|
46
|
-
observer.error(client.TRPCClientError.from(cause));
|
|
47
|
-
});
|
|
48
|
-
promise.then((data)=>{
|
|
49
|
-
const transformedResult = transformer.output.deserialize(data);
|
|
50
|
-
observer.next({
|
|
51
|
-
result: {
|
|
52
|
-
data: transformedResult
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
observer.complete();
|
|
56
|
-
}).catch((cause)=>{
|
|
57
|
-
observer.error(client.TRPCClientError.from(cause));
|
|
58
|
-
});
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
exports.experimental_nextCacheLink = experimental_nextCacheLink;
|
|
@@ -1,15 +0,0 @@
|
|
|
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 {
|
|
4
|
-
revalidate?: number | false;
|
|
5
|
-
batch?: boolean;
|
|
6
|
-
}
|
|
7
|
-
type NextLinkSingleOptions<TRoot extends AnyRootTypes> = NextLinkBaseOptions & Omit<HTTPLinkOptions<TRoot>, 'fetch'> & {
|
|
8
|
-
batch?: false;
|
|
9
|
-
};
|
|
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>;
|
|
14
|
-
export {};
|
|
15
|
-
//# sourceMappingURL=nextHttp.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
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,39 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var client = require('@trpc/client');
|
|
4
|
-
var shared = require('../shared.js');
|
|
5
|
-
|
|
6
|
-
// ts-prune-ignore-next
|
|
7
|
-
function experimental_nextHttpLink(opts) {
|
|
8
|
-
return (runtime)=>{
|
|
9
|
-
return (ctx)=>{
|
|
10
|
-
const { path, input, context } = ctx.op;
|
|
11
|
-
const cacheTag = shared.generateCacheTag(path, input);
|
|
12
|
-
// Let per-request revalidate override global revalidate
|
|
13
|
-
const requestRevalidate = typeof context['revalidate'] === 'number' || context['revalidate'] === false ? context['revalidate'] : undefined;
|
|
14
|
-
const revalidate = requestRevalidate ?? opts.revalidate ?? false;
|
|
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);
|
|
35
|
-
};
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
exports.experimental_nextHttpLink = experimental_nextHttpLink;
|
package/dist/app-dir/server.d.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import type { CreateContextCallback } from '@trpc/server';
|
|
2
|
-
import type { AnyProcedure, AnyRootTypes, AnyRouter, ErrorHandlerOptions, inferClientTypes, MaybePromise, RootConfig, Simplify, TRPCResponse } from '@trpc/server/unstable-core-do-not-import';
|
|
3
|
-
import type { ActionHandlerDef, CreateTRPCNextAppRouterOptions, inferActionDef } from './shared';
|
|
4
|
-
import type { NextAppDirDecorateRouterRecord } from './types';
|
|
5
|
-
export type { ActionHandlerDef };
|
|
6
|
-
export declare function experimental_createTRPCNextAppDirServer<TRouter extends AnyRouter>(opts: CreateTRPCNextAppRouterOptions<TRouter>): NextAppDirDecorateRouterRecord<TRouter["_def"]["_config"]["$types"], TRouter["_def"]["record"]>;
|
|
7
|
-
/**
|
|
8
|
-
* @internal
|
|
9
|
-
*/
|
|
10
|
-
export type TRPCActionHandler<TDef extends ActionHandlerDef> = (input: FormData | TDef['input']) => Promise<TRPCResponse<TDef['output'], TDef['errorShape']>>;
|
|
11
|
-
export declare function experimental_createServerActionHandler<TInstance extends {
|
|
12
|
-
_config: RootConfig<AnyRootTypes>;
|
|
13
|
-
}>(t: TInstance, opts: CreateContextCallback<TInstance['_config']['$types']['ctx'], () => MaybePromise<TInstance['_config']['$types']['ctx']>> & {
|
|
14
|
-
/**
|
|
15
|
-
* Transform form data to a `Record` before passing it to the procedure
|
|
16
|
-
* @default true
|
|
17
|
-
*/
|
|
18
|
-
normalizeFormData?: boolean;
|
|
19
|
-
/**
|
|
20
|
-
* Called when an error occurs in the handler
|
|
21
|
-
*/
|
|
22
|
-
onError?: (opts: ErrorHandlerOptions<TInstance['_config']['$types']['ctx']>) => void;
|
|
23
|
-
/**
|
|
24
|
-
* Rethrow errors that should be handled by Next.js
|
|
25
|
-
* @default true
|
|
26
|
-
*/
|
|
27
|
-
rethrowNextErrors?: boolean;
|
|
28
|
-
}): <TProc extends AnyProcedure>(proc: TProc) => TRPCActionHandler<Simplify<inferActionDef<inferClientTypes<TInstance>, TProc>>>;
|
|
29
|
-
export declare function experimental_revalidateEndpoint(req: Request): Promise<Response>;
|
|
30
|
-
//# sourceMappingURL=server.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/app-dir/server.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAE1D,OAAO,KAAK,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AYkC,KAAK,SAAS,YAAY,EAC3D,MAAM,KAAK,KACV,iBAAiB,CAClB,QAAQ,CAAC,cAAc,CAAC,gBAAgB,CAAC,SAAS,CAAC,EAAE,KAAK,CAAC,CAAC,CAC7D,CAuEF;AAGD,wBAAsB,+BAA+B,CAAC,GAAG,EAAE,OAAO,qBAiBjE"}
|
package/dist/app-dir/server.js
DELETED
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var client = require('@trpc/client');
|
|
4
|
-
var nextAppDir = require('@trpc/server/adapters/next-app-dir');
|
|
5
|
-
var unstableCoreDoNotImport = require('@trpc/server/unstable-core-do-not-import');
|
|
6
|
-
var cache = require('next/cache');
|
|
7
|
-
var React = require('react');
|
|
8
|
-
var shared = require('./shared.js');
|
|
9
|
-
|
|
10
|
-
/// <reference types="next" />
|
|
11
|
-
// ts-prune-ignore-next
|
|
12
|
-
function experimental_createTRPCNextAppDirServer(opts) {
|
|
13
|
-
const getClient = React.cache(()=>{
|
|
14
|
-
const config = opts.config();
|
|
15
|
-
return client.createTRPCUntypedClient(config);
|
|
16
|
-
});
|
|
17
|
-
return unstableCoreDoNotImport.createRecursiveProxy((callOpts)=>{
|
|
18
|
-
// lazily initialize client
|
|
19
|
-
const client$1 = getClient();
|
|
20
|
-
const pathCopy = [
|
|
21
|
-
...callOpts.path
|
|
22
|
-
];
|
|
23
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
24
|
-
const action = pathCopy.pop();
|
|
25
|
-
const procedurePath = pathCopy.join('.');
|
|
26
|
-
const procedureType = client.clientCallTypeToProcedureType(action);
|
|
27
|
-
const cacheTag = shared.generateCacheTag(procedurePath, callOpts.args[0]);
|
|
28
|
-
if (action === 'revalidate') {
|
|
29
|
-
cache.revalidateTag(cacheTag);
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
return client$1[procedureType](procedurePath, ...callOpts.args);
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
function experimental_createServerActionHandler(t, opts) {
|
|
36
|
-
const config = t._config;
|
|
37
|
-
const { normalizeFormData = true, createContext, rethrowNextErrors: shouldRethrowNextErrors = true } = opts;
|
|
38
|
-
const transformer = config.transformer;
|
|
39
|
-
// TODO allow this to take a `TRouter` in addition to a `AnyProcedure`
|
|
40
|
-
return function createServerAction(proc) {
|
|
41
|
-
return async function actionHandler(rawInput) {
|
|
42
|
-
let ctx = undefined;
|
|
43
|
-
try {
|
|
44
|
-
ctx = await createContext?.() ?? {};
|
|
45
|
-
if (normalizeFormData && shared.isFormData(rawInput)) {
|
|
46
|
-
// Normalizes FormData so we can use `z.object({})` etc on the server
|
|
47
|
-
try {
|
|
48
|
-
rawInput = unstableCoreDoNotImport.formDataToObject(rawInput);
|
|
49
|
-
} catch {
|
|
50
|
-
throw new unstableCoreDoNotImport.TRPCError({
|
|
51
|
-
code: 'INTERNAL_SERVER_ERROR',
|
|
52
|
-
message: 'Failed to convert FormData to an object'
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
} else if (rawInput && !shared.isFormData(rawInput)) {
|
|
56
|
-
rawInput = transformer.input.deserialize(rawInput);
|
|
57
|
-
}
|
|
58
|
-
const data = proc._def.experimental_caller ? await proc(rawInput) : await proc({
|
|
59
|
-
input: undefined,
|
|
60
|
-
ctx,
|
|
61
|
-
path: '',
|
|
62
|
-
getRawInput: async ()=>rawInput,
|
|
63
|
-
type: proc._def.type,
|
|
64
|
-
// is it possible to get the AbortSignal from the request?
|
|
65
|
-
signal: undefined
|
|
66
|
-
});
|
|
67
|
-
const transformedJSON = unstableCoreDoNotImport.transformTRPCResponse(config, {
|
|
68
|
-
result: {
|
|
69
|
-
data
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
return transformedJSON;
|
|
73
|
-
} catch (cause) {
|
|
74
|
-
const error = unstableCoreDoNotImport.getTRPCErrorFromUnknown(cause);
|
|
75
|
-
opts.onError?.({
|
|
76
|
-
ctx,
|
|
77
|
-
error,
|
|
78
|
-
input: rawInput,
|
|
79
|
-
path: '',
|
|
80
|
-
type: proc._def.type
|
|
81
|
-
});
|
|
82
|
-
if (shouldRethrowNextErrors) {
|
|
83
|
-
nextAppDir.rethrowNextErrors(error);
|
|
84
|
-
}
|
|
85
|
-
const shape = unstableCoreDoNotImport.getErrorShape({
|
|
86
|
-
config,
|
|
87
|
-
ctx,
|
|
88
|
-
error,
|
|
89
|
-
input: rawInput,
|
|
90
|
-
path: '',
|
|
91
|
-
type: proc._def.type
|
|
92
|
-
});
|
|
93
|
-
return unstableCoreDoNotImport.transformTRPCResponse(t._config, {
|
|
94
|
-
error: shape
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
};
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
// ts-prune-ignore-next
|
|
101
|
-
async function experimental_revalidateEndpoint(req) {
|
|
102
|
-
const { cacheTag } = await req.json();
|
|
103
|
-
if (typeof cacheTag !== 'string') {
|
|
104
|
-
return new Response(JSON.stringify({
|
|
105
|
-
revalidated: false,
|
|
106
|
-
error: 'cacheTag must be a string'
|
|
107
|
-
}), {
|
|
108
|
-
status: 400
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
cache.revalidateTag(cacheTag);
|
|
112
|
-
return new Response(JSON.stringify({
|
|
113
|
-
revalidated: true,
|
|
114
|
-
now: Date.now()
|
|
115
|
-
}), {
|
|
116
|
-
status: 200
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
exports.experimental_createServerActionHandler = experimental_createServerActionHandler;
|
|
121
|
-
exports.experimental_createTRPCNextAppDirServer = experimental_createTRPCNextAppDirServer;
|
|
122
|
-
exports.experimental_revalidateEndpoint = experimental_revalidateEndpoint;
|
package/dist/app-dir/shared.d.ts
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import type { CreateTRPCClientOptions, Resolver, TRPCClient } from '@trpc/client';
|
|
2
|
-
import { TRPCUntypedClient } from '@trpc/client';
|
|
3
|
-
import type { inferProcedureOutput } from '@trpc/server';
|
|
4
|
-
import type { AnyClientTypes, AnyProcedure, AnyQueryProcedure, AnyRootTypes, AnyRouter, inferProcedureInput, inferTransformedProcedureOutput, ProtectedIntersection, RouterRecord } from '@trpc/server/unstable-core-do-not-import';
|
|
5
|
-
/**
|
|
6
|
-
* @internal
|
|
7
|
-
*/
|
|
8
|
-
export type UseProcedureRecord<TRoot extends AnyRootTypes, TRecord extends RouterRecord> = {
|
|
9
|
-
[TKey in keyof TRecord]: TRecord[TKey] extends infer $Value ? $Value extends AnyQueryProcedure ? Resolver<{
|
|
10
|
-
input: inferProcedureInput<$Value>;
|
|
11
|
-
output: inferTransformedProcedureOutput<TRoot, $Value>;
|
|
12
|
-
errorShape: TRoot['errorShape'];
|
|
13
|
-
transformer: TRoot['transformer'];
|
|
14
|
-
}> : $Value extends RouterRecord ? UseProcedureRecord<TRoot, $Value> : never : never;
|
|
15
|
-
};
|
|
16
|
-
export declare function createUseProxy<TRouter extends AnyRouter>(client: TRPCUntypedClient<TRouter> | TRPCClient<TRouter>): UseProcedureRecord<TRouter["_def"]["_config"]["$types"], TRouter["_def"]["record"]>;
|
|
17
|
-
type NextAppRouterUse<TRouter extends AnyRouter> = {
|
|
18
|
-
<TData extends Promise<unknown>[]>(cb: (t: UseProcedureRecord<TRouter['_def']['_config']['$types'], TRouter['_def']['record']>) => [...TData]): {
|
|
19
|
-
[TKey in keyof TData]: Awaited<TData[TKey]>;
|
|
20
|
-
};
|
|
21
|
-
<TData extends Promise<unknown>>(cb: (t: UseProcedureRecord<TRouter['_def']['_config']['$types'], TRouter['_def']['record']>) => TData): Awaited<TData>;
|
|
22
|
-
};
|
|
23
|
-
type CreateTRPCNextAppRouterBase<TRouter extends AnyRouter> = {
|
|
24
|
-
use: NextAppRouterUse<TRouter>;
|
|
25
|
-
};
|
|
26
|
-
export type CreateTRPCNextAppRouter<TRouter extends AnyRouter> = ProtectedIntersection<CreateTRPCNextAppRouterBase<TRouter>, UseProcedureRecord<TRouter['_def']['_config']['$types'], TRouter['_def']['record']>>;
|
|
27
|
-
/**
|
|
28
|
-
* @internal
|
|
29
|
-
*/
|
|
30
|
-
export interface CreateTRPCNextAppRouterOptions<TRouter extends AnyRouter> {
|
|
31
|
-
config: () => CreateTRPCClientOptions<TRouter>;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* @internal
|
|
35
|
-
*/
|
|
36
|
-
export declare function generateCacheTag(procedurePath: string, input: any): string;
|
|
37
|
-
export declare function isFormData(value: unknown): value is FormData;
|
|
38
|
-
/**
|
|
39
|
-
* @internal
|
|
40
|
-
*/
|
|
41
|
-
export interface ActionHandlerDef {
|
|
42
|
-
input?: any;
|
|
43
|
-
output?: any;
|
|
44
|
-
errorShape: any;
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* @internal
|
|
48
|
-
*/
|
|
49
|
-
export type inferActionDef<TRoot extends AnyClientTypes, TProc extends AnyProcedure> = {
|
|
50
|
-
input: inferProcedureInput<TProc>;
|
|
51
|
-
output: inferProcedureOutput<TProc>;
|
|
52
|
-
errorShape: TRoot['errorShape'];
|
|
53
|
-
};
|
|
54
|
-
export {};
|
|
55
|
-
//# sourceMappingURL=shared.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../src/app-dir/shared.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,uBAAuB,EACvB,QAAQ,EACR,UAAU,EACX,MAAM,cAAc,CAAC;AACtB,OAAO,EAAoB,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACnE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AACzD,OAAO,KAAK,EACV,cAAc,EACd,YAAY,EACZ,iBAAiB,EACjB,YAAY,EACZ,SAAS,EACT,mBAAmB,EACnB,+BAA+B,EAC/B,qBAAqB,EACrB,YAAY,EACb,MAAM,0CAA0C,CA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|
2
|
-
|
|
3
|
-
require('@trpc/client');
|
|
4
|
-
require('@trpc/server/unstable-core-do-not-import');
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* @internal
|
|
8
|
-
*/ function generateCacheTag(procedurePath, input) {
|
|
9
|
-
return input ? `${procedurePath}?input=${JSON.stringify(input)}` : 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
|
-
exports.generateCacheTag = generateCacheTag;
|
|
20
|
-
exports.isFormData = isFormData;
|