@trpc/next 10.26.0 → 10.27.0
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/dist/app-dir/client.d.ts +4 -7
- package/dist/app-dir/client.d.ts.map +1 -1
- package/dist/app-dir/client.js +144 -54
- package/dist/app-dir/client.mjs +144 -56
- package/dist/app-dir/client.test.d.ts +2 -0
- package/dist/app-dir/client.test.d.ts.map +1 -0
- package/dist/app-dir/create-action-hook.d.ts +51 -0
- package/dist/app-dir/create-action-hook.d.ts.map +1 -0
- package/dist/app-dir/formDataToObject.d.ts +2 -0
- package/dist/app-dir/formDataToObject.d.ts.map +1 -0
- package/dist/app-dir/server.d.ts +21 -2
- package/dist/app-dir/server.d.ts.map +1 -1
- package/dist/app-dir/server.js +88 -0
- package/dist/app-dir/server.mjs +89 -2
- package/dist/app-dir/shared.d.ts +21 -1
- package/dist/app-dir/shared.d.ts.map +1 -1
- package/dist/shared-2ca37369.js +15 -0
- package/dist/shared-59b269d5.mjs +13 -0
- package/dist/shared-bc6a2699.js +14 -0
- package/package.json +10 -10
- package/src/app-dir/client.test.tsx +408 -0
- package/src/app-dir/client.ts +71 -63
- package/src/app-dir/create-action-hook.tsx +218 -0
- package/src/app-dir/formDataToObject.test.ts +58 -0
- package/src/app-dir/formDataToObject.ts +36 -0
- package/src/app-dir/server.ts +110 -4
- package/src/app-dir/shared.ts +32 -0
package/dist/app-dir/client.d.ts
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
|
+
import { CreateTRPCProxyClient } from '@trpc/client';
|
|
1
2
|
import { AnyRouter } from '@trpc/server';
|
|
2
|
-
import { CreateTRPCNextAppRouterOptions
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
<TData extends Promise<unknown>[]>(cb: (t: UseProcedureRecord<TRouter>) => [...TData]): { [TKey in keyof TData]: import("@trpc/server").ThenArg<TData[TKey]>; };
|
|
6
|
-
<TData_1 extends Promise<unknown>>(cb: (t: UseProcedureRecord<TRouter>) => TData_1): import("@trpc/server").ThenArg<TData_1>;
|
|
7
|
-
};
|
|
8
|
-
}, UseProcedureRecord<TRouter>>;
|
|
3
|
+
import { CreateTRPCNextAppRouterOptions } from './shared';
|
|
4
|
+
export { experimental_createActionHook, experimental_serverActionLink, type UseTRPCActionResult, type inferActionResultProps, } from './create-action-hook';
|
|
5
|
+
export declare function experimental_createTRPCNextAppDirClient<TRouter extends AnyRouter>(opts: CreateTRPCNextAppRouterOptions<TRouter>): CreateTRPCProxyClient<TRouter>;
|
|
9
6
|
//# sourceMappingURL=client.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/app-dir/client.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/app-dir/client.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EAGtB,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"}
|
package/dist/app-dir/client.js
CHANGED
|
@@ -3,73 +3,163 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var client = require('@trpc/client');
|
|
6
|
-
var shared = require('@trpc/server/shared');
|
|
6
|
+
var shared$2 = require('@trpc/server/shared');
|
|
7
|
+
var shared$1 = require('@trpc/client/shared');
|
|
8
|
+
var observable = require('@trpc/server/observable');
|
|
9
|
+
var React = require('react');
|
|
10
|
+
var shared = require('../shared-2ca37369.js');
|
|
7
11
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
// ts-prune-ignore-next
|
|
13
|
+
function experimental_serverActionLink() {
|
|
14
|
+
return (runtime)=>({ op })=>observable.observable((observer)=>{
|
|
15
|
+
const context = op.context;
|
|
16
|
+
context._action(shared.isFormData(op.input) ? op.input : runtime.transformer.serialize(op.input)).then((data)=>{
|
|
17
|
+
const transformed = shared$1.transformResult(data, runtime);
|
|
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)=>observer.error(client.TRPCClientError.from(cause)));
|
|
28
|
+
});
|
|
13
29
|
}
|
|
14
|
-
|
|
15
|
-
function
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
30
|
+
// ts-prune-ignore-next
|
|
31
|
+
function experimental_createActionHook(opts) {
|
|
32
|
+
const client$1 = client.createTRPCUntypedClient(opts);
|
|
33
|
+
return function useAction(handler, useActionOpts) {
|
|
34
|
+
const count = React.useRef(0);
|
|
35
|
+
const [state, setState] = React.useState({
|
|
36
|
+
status: 'idle'
|
|
37
|
+
});
|
|
38
|
+
const actionOptsRef = React.useRef(useActionOpts);
|
|
39
|
+
actionOptsRef.current = useActionOpts;
|
|
40
|
+
React.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 = React.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$1.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: client.TRPCClientError.from(error, {})
|
|
80
|
+
});
|
|
81
|
+
throw error;
|
|
82
|
+
});
|
|
83
|
+
}, [
|
|
84
|
+
handler
|
|
85
|
+
]);
|
|
86
|
+
const mutate = React.useCallback((...args)=>{
|
|
87
|
+
void mutateAsync(...args).catch(()=>{
|
|
88
|
+
// ignored
|
|
89
|
+
});
|
|
90
|
+
}, [
|
|
91
|
+
mutateAsync
|
|
92
|
+
]);
|
|
93
|
+
return React.useMemo(()=>({
|
|
94
|
+
...state,
|
|
95
|
+
mutate,
|
|
96
|
+
mutateAsync
|
|
97
|
+
}), [
|
|
98
|
+
mutate,
|
|
99
|
+
mutateAsync,
|
|
100
|
+
state
|
|
101
|
+
]);
|
|
102
|
+
};
|
|
20
103
|
}
|
|
104
|
+
|
|
21
105
|
// ts-prune-ignore-next
|
|
22
106
|
function experimental_createTRPCNextAppDirClient(opts) {
|
|
23
107
|
const client$1 = client.createTRPCUntypedClient(opts.config());
|
|
24
|
-
const useProxy = createUseProxy(client
|
|
108
|
+
// const useProxy = createUseProxy<TRouter>(client);
|
|
25
109
|
const cache = new Map();
|
|
26
|
-
return
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
if (cached?.promise) {
|
|
55
|
-
return cached.promise;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
const fullPath = pathCopy.join('.');
|
|
59
|
-
const promise = client$1[procedureType](fullPath, ...args);
|
|
60
|
-
if (procedureType !== 'query') {
|
|
61
|
-
return promise;
|
|
62
|
-
}
|
|
63
|
-
const queryCacheKey1 = JSON.stringify([
|
|
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
|
+
return shared$2.createRecursiveProxy(({ path , args })=>{
|
|
131
|
+
// const pathCopy = [key, ...path];
|
|
132
|
+
const pathCopy = [
|
|
133
|
+
...path
|
|
134
|
+
];
|
|
135
|
+
const procedureType = client.clientCallTypeToProcedureType(pathCopy.pop());
|
|
136
|
+
if (procedureType === 'query') {
|
|
137
|
+
const queryCacheKey = JSON.stringify([
|
|
64
138
|
path,
|
|
65
139
|
args[0]
|
|
66
140
|
]);
|
|
67
|
-
cache.
|
|
68
|
-
|
|
69
|
-
|
|
141
|
+
const cached = cache.get(queryCacheKey);
|
|
142
|
+
if (cached?.promise) {
|
|
143
|
+
return cached.promise;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
const fullPath = pathCopy.join('.');
|
|
147
|
+
const promise = client$1[procedureType](fullPath, ...args);
|
|
148
|
+
if (procedureType !== 'query') {
|
|
70
149
|
return promise;
|
|
150
|
+
}
|
|
151
|
+
const queryCacheKey1 = JSON.stringify([
|
|
152
|
+
path,
|
|
153
|
+
args[0]
|
|
154
|
+
]);
|
|
155
|
+
cache.set(queryCacheKey1, {
|
|
156
|
+
promise
|
|
71
157
|
});
|
|
158
|
+
return promise;
|
|
72
159
|
});
|
|
160
|
+
// });
|
|
73
161
|
}
|
|
74
162
|
|
|
163
|
+
exports.experimental_createActionHook = experimental_createActionHook;
|
|
75
164
|
exports.experimental_createTRPCNextAppDirClient = experimental_createTRPCNextAppDirClient;
|
|
165
|
+
exports.experimental_serverActionLink = experimental_serverActionLink;
|
package/dist/app-dir/client.mjs
CHANGED
|
@@ -1,71 +1,159 @@
|
|
|
1
|
-
import { createTRPCUntypedClient, clientCallTypeToProcedureType } from '@trpc/client';
|
|
2
|
-
import { createRecursiveProxy
|
|
1
|
+
import { TRPCClientError, createTRPCUntypedClient, clientCallTypeToProcedureType } from '@trpc/client';
|
|
2
|
+
import { createRecursiveProxy } from '@trpc/server/shared';
|
|
3
|
+
import { transformResult } from '@trpc/client/shared';
|
|
4
|
+
import { observable } from '@trpc/server/observable';
|
|
5
|
+
import { useRef, useState, useEffect, useCallback, useMemo } from 'react';
|
|
6
|
+
import { i as isFormData } from '../shared-59b269d5.mjs';
|
|
3
7
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
// ts-prune-ignore-next
|
|
9
|
+
function experimental_serverActionLink() {
|
|
10
|
+
return (runtime)=>({ op })=>observable((observer)=>{
|
|
11
|
+
const context = op.context;
|
|
12
|
+
context._action(isFormData(op.input) ? op.input : runtime.transformer.serialize(op.input)).then((data)=>{
|
|
13
|
+
const transformed = transformResult(data, runtime);
|
|
14
|
+
if (!transformed.ok) {
|
|
15
|
+
observer.error(TRPCClientError.from(transformed.error, {}));
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
observer.next({
|
|
19
|
+
context: op.context,
|
|
20
|
+
result: transformed.result
|
|
21
|
+
});
|
|
22
|
+
observer.complete();
|
|
23
|
+
}).catch((cause)=>observer.error(TRPCClientError.from(cause)));
|
|
24
|
+
});
|
|
9
25
|
}
|
|
10
|
-
|
|
11
|
-
function
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
26
|
+
// ts-prune-ignore-next
|
|
27
|
+
function experimental_createActionHook(opts) {
|
|
28
|
+
const client = createTRPCUntypedClient(opts);
|
|
29
|
+
return function useAction(handler, useActionOpts) {
|
|
30
|
+
const count = useRef(0);
|
|
31
|
+
const [state, setState] = useState({
|
|
32
|
+
status: 'idle'
|
|
33
|
+
});
|
|
34
|
+
const actionOptsRef = useRef(useActionOpts);
|
|
35
|
+
actionOptsRef.current = useActionOpts;
|
|
36
|
+
useEffect(()=>{
|
|
37
|
+
return ()=>{
|
|
38
|
+
// cleanup after unmount to prevent calling hook opts after unmount
|
|
39
|
+
count.current = -1;
|
|
40
|
+
actionOptsRef.current = undefined;
|
|
41
|
+
};
|
|
42
|
+
}, []);
|
|
43
|
+
const mutateAsync = useCallback((input, requestOptions)=>{
|
|
44
|
+
const idx = ++count.current;
|
|
45
|
+
const context = {
|
|
46
|
+
...requestOptions?.context,
|
|
47
|
+
_action (innerInput) {
|
|
48
|
+
return handler(innerInput);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
setState({
|
|
52
|
+
status: 'loading'
|
|
53
|
+
});
|
|
54
|
+
return client.mutation('serverAction', input, {
|
|
55
|
+
...requestOptions,
|
|
56
|
+
context
|
|
57
|
+
}).then(async (data)=>{
|
|
58
|
+
await actionOptsRef.current?.onSuccess?.(data);
|
|
59
|
+
if (idx !== count.current) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
setState({
|
|
63
|
+
status: 'success',
|
|
64
|
+
data: data
|
|
65
|
+
});
|
|
66
|
+
}).catch(async (error)=>{
|
|
67
|
+
await actionOptsRef.current?.onError?.(error);
|
|
68
|
+
throw error;
|
|
69
|
+
}).catch((error)=>{
|
|
70
|
+
if (idx !== count.current) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
setState({
|
|
74
|
+
status: 'error',
|
|
75
|
+
error: TRPCClientError.from(error, {})
|
|
76
|
+
});
|
|
77
|
+
throw error;
|
|
78
|
+
});
|
|
79
|
+
}, [
|
|
80
|
+
handler
|
|
81
|
+
]);
|
|
82
|
+
const mutate = useCallback((...args)=>{
|
|
83
|
+
void mutateAsync(...args).catch(()=>{
|
|
84
|
+
// ignored
|
|
85
|
+
});
|
|
86
|
+
}, [
|
|
87
|
+
mutateAsync
|
|
88
|
+
]);
|
|
89
|
+
return useMemo(()=>({
|
|
90
|
+
...state,
|
|
91
|
+
mutate,
|
|
92
|
+
mutateAsync
|
|
93
|
+
}), [
|
|
94
|
+
mutate,
|
|
95
|
+
mutateAsync,
|
|
96
|
+
state
|
|
97
|
+
]);
|
|
98
|
+
};
|
|
16
99
|
}
|
|
100
|
+
|
|
17
101
|
// ts-prune-ignore-next
|
|
18
102
|
function experimental_createTRPCNextAppDirClient(opts) {
|
|
19
103
|
const client = createTRPCUntypedClient(opts.config());
|
|
20
|
-
const useProxy = createUseProxy(client);
|
|
104
|
+
// const useProxy = createUseProxy<TRouter>(client);
|
|
21
105
|
const cache = new Map();
|
|
22
|
-
return createFlatProxy((key)=>{
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
if (cached?.promise) {
|
|
51
|
-
return cached.promise;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
const fullPath = pathCopy.join('.');
|
|
55
|
-
const promise = client[procedureType](fullPath, ...args);
|
|
56
|
-
if (procedureType !== 'query') {
|
|
57
|
-
return promise;
|
|
58
|
-
}
|
|
59
|
-
const queryCacheKey1 = JSON.stringify([
|
|
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
|
+
return createRecursiveProxy(({ path , args })=>{
|
|
127
|
+
// const pathCopy = [key, ...path];
|
|
128
|
+
const pathCopy = [
|
|
129
|
+
...path
|
|
130
|
+
];
|
|
131
|
+
const procedureType = clientCallTypeToProcedureType(pathCopy.pop());
|
|
132
|
+
if (procedureType === 'query') {
|
|
133
|
+
const queryCacheKey = JSON.stringify([
|
|
60
134
|
path,
|
|
61
135
|
args[0]
|
|
62
136
|
]);
|
|
63
|
-
cache.
|
|
64
|
-
|
|
65
|
-
|
|
137
|
+
const cached = cache.get(queryCacheKey);
|
|
138
|
+
if (cached?.promise) {
|
|
139
|
+
return cached.promise;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
const fullPath = pathCopy.join('.');
|
|
143
|
+
const promise = client[procedureType](fullPath, ...args);
|
|
144
|
+
if (procedureType !== 'query') {
|
|
66
145
|
return promise;
|
|
146
|
+
}
|
|
147
|
+
const queryCacheKey1 = JSON.stringify([
|
|
148
|
+
path,
|
|
149
|
+
args[0]
|
|
150
|
+
]);
|
|
151
|
+
cache.set(queryCacheKey1, {
|
|
152
|
+
promise
|
|
67
153
|
});
|
|
154
|
+
return promise;
|
|
68
155
|
});
|
|
156
|
+
// });
|
|
69
157
|
}
|
|
70
158
|
|
|
71
|
-
export { experimental_createTRPCNextAppDirClient };
|
|
159
|
+
export { experimental_createActionHook, experimental_createTRPCNextAppDirClient, experimental_serverActionLink };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.test.d.ts","sourceRoot":"","sources":["../../src/app-dir/client.test.tsx"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { CreateTRPCClientOptions, TRPCClientError, TRPCLink } from '@trpc/client';
|
|
2
|
+
import { AnyProcedure, AnyRouter, MaybePromise, ProcedureOptions, Simplify, inferHandlerInput } from '@trpc/server';
|
|
3
|
+
import { TRPCActionHandler } from './server';
|
|
4
|
+
import { ActionHandlerDef } from './shared';
|
|
5
|
+
interface Def {
|
|
6
|
+
input?: any;
|
|
7
|
+
output?: any;
|
|
8
|
+
errorShape: any;
|
|
9
|
+
}
|
|
10
|
+
declare type MutationArgs<TDef extends Def> = TDef['input'] extends void ? [input?: undefined | void, opts?: ProcedureOptions] : [input: TDef['input'] | FormData, opts?: ProcedureOptions];
|
|
11
|
+
interface UseTRPCActionBaseResult<TDef extends Def> {
|
|
12
|
+
mutate: (...args: MutationArgs<TDef>) => void;
|
|
13
|
+
mutateAsync: (...args: MutationArgs<TDef>) => Promise<Def['output']>;
|
|
14
|
+
}
|
|
15
|
+
interface UseTRPCActionSuccessResult<TDef extends Def> extends UseTRPCActionBaseResult<TDef> {
|
|
16
|
+
data: TDef['output'];
|
|
17
|
+
error?: never;
|
|
18
|
+
status: 'success';
|
|
19
|
+
}
|
|
20
|
+
interface UseTRPCActionErrorResult<TDef extends Def> extends UseTRPCActionBaseResult<TDef> {
|
|
21
|
+
data?: never;
|
|
22
|
+
error: TRPCClientError<TDef['errorShape']>;
|
|
23
|
+
status: 'error';
|
|
24
|
+
}
|
|
25
|
+
interface UseTRPCActionIdleResult<TDef extends Def> extends UseTRPCActionBaseResult<TDef> {
|
|
26
|
+
data?: never;
|
|
27
|
+
error?: never;
|
|
28
|
+
status: 'idle';
|
|
29
|
+
}
|
|
30
|
+
interface UseTRPCActionLoadingResult<TDef extends Def> extends UseTRPCActionBaseResult<TDef> {
|
|
31
|
+
data?: never;
|
|
32
|
+
error?: never;
|
|
33
|
+
status: 'loading';
|
|
34
|
+
}
|
|
35
|
+
export declare type UseTRPCActionResult<TDef extends Def> = UseTRPCActionSuccessResult<TDef> | UseTRPCActionErrorResult<TDef> | UseTRPCActionIdleResult<TDef> | UseTRPCActionLoadingResult<TDef>;
|
|
36
|
+
export declare function experimental_serverActionLink<TRouter extends AnyRouter = AnyRouter>(): TRPCLink<TRouter>;
|
|
37
|
+
/**
|
|
38
|
+
* @internal
|
|
39
|
+
*/
|
|
40
|
+
export declare type inferActionResultProps<TProc extends AnyProcedure> = {
|
|
41
|
+
input: inferHandlerInput<TProc>[0];
|
|
42
|
+
output: TProc['_def']['_output_out'];
|
|
43
|
+
errorShape: TProc['_def']['_config']['$types']['errorShape'];
|
|
44
|
+
};
|
|
45
|
+
interface UseTRPCActionOptions<TDef extends Def> {
|
|
46
|
+
onSuccess?: (result: TDef['output']) => void | MaybePromise<void>;
|
|
47
|
+
onError?: (result: TRPCClientError<TDef['errorShape']>) => MaybePromise<void>;
|
|
48
|
+
}
|
|
49
|
+
export declare function experimental_createActionHook<TRouter extends AnyRouter>(opts: CreateTRPCClientOptions<TRouter>): <TDef extends ActionHandlerDef>(handler: TRPCActionHandler<TDef>, useActionOpts?: UseTRPCActionOptions<Simplify<TDef>> | undefined) => UseTRPCActionResult<TDef>;
|
|
50
|
+
export {};
|
|
51
|
+
//# sourceMappingURL=create-action-hook.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-action-hook.d.ts","sourceRoot":"","sources":["../../src/app-dir/create-action-hook.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,uBAAuB,EACvB,eAAe,EACf,QAAQ,EAGT,MAAM,cAAc,CAAC;AAEtB,OAAO,EACL,YAAY,EACZ,SAAS,EACT,YAAY,EACZ,gBAAgB,EAChB,QAAQ,EACR,iBAAiB,EAClB,MAAM,cAAc,CAAC;AAGtB,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,EAAE,gBAAgB,EAAc,MAAM,UAAU,CAAC;AAExD,UAAU,GAAG;IACX,KAAK,CAAC,EAAE,GAAG,CAAC;IACZ,MAAM,CAAC,EAAE,GAAG,CAAC;IACb,UAAU,EAAE,GAAG,CAAC;CACjB;AAED,aAAK,YAAY,CAAC,IAAI,SAAS,GAAG,IAAI,IAAI,CAAC,OAAO,CAAC,SAAS,IAA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 -1,5 +1,24 @@
|
|
|
1
1
|
import { CreateTRPCProxyClient } from '@trpc/client';
|
|
2
|
-
import { AnyRouter } from '@trpc/server';
|
|
3
|
-
import {
|
|
2
|
+
import { AnyProcedure, AnyRootConfig, AnyRouter, MaybePromise, Simplify } from '@trpc/server';
|
|
3
|
+
import { TRPCResponse } from '@trpc/server/rpc';
|
|
4
|
+
import { ActionHandlerDef, CreateTRPCNextAppRouterOptions, inferActionDef } from './shared';
|
|
4
5
|
export declare function experimental_createTRPCNextAppDirServer<TRouter extends AnyRouter>(opts: CreateTRPCNextAppRouterOptions<TRouter>): CreateTRPCProxyClient<TRouter>;
|
|
6
|
+
/**
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
export declare type TRPCActionHandler<TDef extends ActionHandlerDef> = (input: TDef['input'] | FormData) => Promise<TRPCResponse<TDef['output'], TDef['errorShape']>>;
|
|
10
|
+
export declare function experimental_createServerActionHandler<TInstance extends {
|
|
11
|
+
_config: AnyRootConfig;
|
|
12
|
+
}>(t: TInstance, opts: {
|
|
13
|
+
createContext: () => 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
|
+
}): <TProc extends AnyProcedure>(proc: TProc) => TRPCActionHandler<{
|
|
20
|
+
input: import("@trpc/server").ProcedureArgs<import("@trpc/server").inferProcedureParams<TProc>>[0];
|
|
21
|
+
output: TProc["_def"]["_output_out"];
|
|
22
|
+
errorShape: TProc["_def"]["_config"]["$types"]["errorShape"];
|
|
23
|
+
}>;
|
|
5
24
|
//# sourceMappingURL=server.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/app-dir/server.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/app-dir/server.ts"],"names":[],"mappings":"AACA,OAAO,EACL,qBAAqB,EAGtB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,YAAY,EACZ,aAAa,EACb,SAAS,EAET,YAAY,EACZ,QAAQ,EAIT,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAQhD,OAAO,EACL,gBAAgB,EAChB,8BAA8B,EAC9B,cAAc,EAEf,MAAM,UAAU,CAAC;AAGlB,wBAAgB,uCAAuC,CACrD,OAAO,SAAS,SAAS,EACzB,IAAI,EAAE,8BAA8B,CAAC,OAAO,CAAC,kCAkB9C;AAED;;GAEG;AACH,oBAAY,iBAAiB,CAAC,IAAI,SAAS,gBAAgB,IAAI,CAC7D,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,GAAG,QAAQ,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"}
|