@trpc/next 11.0.0-alpha-tmp-export-from-main.213 → 11.0.0-alpha-tmp-export-from-main.217
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.js +3 -101
- package/dist/app-dir/client.mjs +4 -100
- package/dist/app-dir/create-action-hook.js +104 -0
- package/dist/app-dir/create-action-hook.mjs +101 -0
- package/dist/app-dir/formDataToObject.js +34 -0
- package/dist/app-dir/formDataToObject.mjs +32 -0
- package/dist/app-dir/links/nextCache.js +1 -3
- package/dist/app-dir/links/nextCache.mjs +1 -1
- package/dist/app-dir/links/nextHttp.js +1 -4
- package/dist/app-dir/links/nextHttp.mjs +1 -2
- package/dist/app-dir/server.js +3 -35
- package/dist/app-dir/server.mjs +2 -32
- package/dist/{shared-2f1ecbeb.mjs → app-dir/shared.mjs} +1 -1
- package/dist/createTRPCNext.js +38 -0
- package/dist/createTRPCNext.mjs +36 -0
- package/dist/index.js +4 -229
- package/dist/index.mjs +2 -207
- package/dist/withTRPC.js +178 -0
- package/dist/withTRPC.mjs +176 -0
- package/package.json +8 -8
- package/dist/shared-62d181e7.js +0 -19
- /package/dist/{shared-a452b80f.js → app-dir/shared.js} +0 -0
package/dist/app-dir/client.js
CHANGED
|
@@ -1,106 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
3
|
var client = require('@trpc/client');
|
|
6
4
|
var core = require('@trpc/core');
|
|
7
|
-
var
|
|
8
|
-
var shared = require('../shared-a452b80f.js');
|
|
9
|
-
|
|
10
|
-
// ts-prune-ignore-next
|
|
11
|
-
function experimental_serverActionLink() {
|
|
12
|
-
return (runtime)=>({ op })=>core.observable((observer)=>{
|
|
13
|
-
const context = op.context;
|
|
14
|
-
context._action(shared.isFormData(op.input) ? op.input : runtime.transformer.serialize(op.input)).then((data)=>{
|
|
15
|
-
const transformed = core.transformResult(data, runtime.transformer);
|
|
16
|
-
if (!transformed.ok) {
|
|
17
|
-
observer.error(client.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(client.TRPCClientError.from(cause));
|
|
27
|
-
});
|
|
28
|
-
});
|
|
29
|
-
}
|
|
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
|
-
};
|
|
103
|
-
}
|
|
5
|
+
var createActionHook = require('./create-action-hook.js');
|
|
104
6
|
|
|
105
7
|
// ts-prune-ignore-next
|
|
106
8
|
function experimental_createTRPCNextAppDirClient(opts) {
|
|
@@ -141,6 +43,6 @@ function experimental_createTRPCNextAppDirClient(opts) {
|
|
|
141
43
|
// });
|
|
142
44
|
}
|
|
143
45
|
|
|
144
|
-
exports.experimental_createActionHook = experimental_createActionHook;
|
|
46
|
+
exports.experimental_createActionHook = createActionHook.experimental_createActionHook;
|
|
47
|
+
exports.experimental_serverActionLink = createActionHook.experimental_serverActionLink;
|
|
145
48
|
exports.experimental_createTRPCNextAppDirClient = experimental_createTRPCNextAppDirClient;
|
|
146
|
-
exports.experimental_serverActionLink = experimental_serverActionLink;
|
package/dist/app-dir/client.mjs
CHANGED
|
@@ -1,102 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
import { i as isFormData } from '../shared-2f1ecbeb.mjs';
|
|
5
|
-
|
|
6
|
-
// ts-prune-ignore-next
|
|
7
|
-
function experimental_serverActionLink() {
|
|
8
|
-
return (runtime)=>({ op })=>observable((observer)=>{
|
|
9
|
-
const context = op.context;
|
|
10
|
-
context._action(isFormData(op.input) ? op.input : runtime.transformer.serialize(op.input)).then((data)=>{
|
|
11
|
-
const transformed = transformResult(data, runtime.transformer);
|
|
12
|
-
if (!transformed.ok) {
|
|
13
|
-
observer.error(TRPCClientError.from(transformed.error, {}));
|
|
14
|
-
return;
|
|
15
|
-
}
|
|
16
|
-
observer.next({
|
|
17
|
-
context: op.context,
|
|
18
|
-
result: transformed.result
|
|
19
|
-
});
|
|
20
|
-
observer.complete();
|
|
21
|
-
}).catch((cause)=>{
|
|
22
|
-
observer.error(TRPCClientError.from(cause));
|
|
23
|
-
});
|
|
24
|
-
});
|
|
25
|
-
}
|
|
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
|
-
};
|
|
99
|
-
}
|
|
1
|
+
import { createTRPCUntypedClient, clientCallTypeToProcedureType } from '@trpc/client';
|
|
2
|
+
import { createRecursiveProxy } from '@trpc/core';
|
|
3
|
+
export { experimental_createActionHook, experimental_serverActionLink } from './create-action-hook.mjs';
|
|
100
4
|
|
|
101
5
|
// ts-prune-ignore-next
|
|
102
6
|
function experimental_createTRPCNextAppDirClient(opts) {
|
|
@@ -137,4 +41,4 @@ function experimental_createTRPCNextAppDirClient(opts) {
|
|
|
137
41
|
// });
|
|
138
42
|
}
|
|
139
43
|
|
|
140
|
-
export {
|
|
44
|
+
export { experimental_createTRPCNextAppDirClient };
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var client = require('@trpc/client');
|
|
4
|
+
var core = require('@trpc/core');
|
|
5
|
+
var React = require('react');
|
|
6
|
+
var shared = require('./shared.js');
|
|
7
|
+
|
|
8
|
+
// ts-prune-ignore-next
|
|
9
|
+
function experimental_serverActionLink() {
|
|
10
|
+
return (runtime)=>({ op })=>core.observable((observer)=>{
|
|
11
|
+
const context = op.context;
|
|
12
|
+
context._action(shared.isFormData(op.input) ? op.input : runtime.transformer.serialize(op.input)).then((data)=>{
|
|
13
|
+
const transformed = core.transformResult(data, runtime.transformer);
|
|
14
|
+
if (!transformed.ok) {
|
|
15
|
+
observer.error(client.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)=>{
|
|
24
|
+
observer.error(client.TRPCClientError.from(cause));
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
// ts-prune-ignore-next
|
|
29
|
+
function experimental_createActionHook(opts) {
|
|
30
|
+
const client$1 = client.createTRPCUntypedClient(opts);
|
|
31
|
+
return function useAction(handler, useActionOpts) {
|
|
32
|
+
const count = React.useRef(0);
|
|
33
|
+
const [state, setState] = React.useState({
|
|
34
|
+
status: 'idle'
|
|
35
|
+
});
|
|
36
|
+
const actionOptsRef = React.useRef(useActionOpts);
|
|
37
|
+
actionOptsRef.current = useActionOpts;
|
|
38
|
+
React.useEffect(()=>{
|
|
39
|
+
return ()=>{
|
|
40
|
+
// cleanup after unmount to prevent calling hook opts after unmount
|
|
41
|
+
count.current = -1;
|
|
42
|
+
actionOptsRef.current = undefined;
|
|
43
|
+
};
|
|
44
|
+
}, []);
|
|
45
|
+
const mutateAsync = React.useCallback((input, requestOptions)=>{
|
|
46
|
+
const idx = ++count.current;
|
|
47
|
+
const context = {
|
|
48
|
+
...requestOptions?.context,
|
|
49
|
+
_action (innerInput) {
|
|
50
|
+
return handler(innerInput);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
setState({
|
|
54
|
+
status: 'loading'
|
|
55
|
+
});
|
|
56
|
+
return client$1.mutation('serverAction', input, {
|
|
57
|
+
...requestOptions,
|
|
58
|
+
context
|
|
59
|
+
}).then(async (data)=>{
|
|
60
|
+
await actionOptsRef.current?.onSuccess?.(data);
|
|
61
|
+
if (idx !== count.current) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
setState({
|
|
65
|
+
status: 'success',
|
|
66
|
+
data: data
|
|
67
|
+
});
|
|
68
|
+
}).catch(async (error)=>{
|
|
69
|
+
await actionOptsRef.current?.onError?.(error);
|
|
70
|
+
throw error;
|
|
71
|
+
}).catch((error)=>{
|
|
72
|
+
if (idx !== count.current) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
setState({
|
|
76
|
+
status: 'error',
|
|
77
|
+
error: client.TRPCClientError.from(error, {})
|
|
78
|
+
});
|
|
79
|
+
throw error;
|
|
80
|
+
});
|
|
81
|
+
}, [
|
|
82
|
+
handler
|
|
83
|
+
]);
|
|
84
|
+
const mutate = React.useCallback((...args)=>{
|
|
85
|
+
void mutateAsync(...args).catch(()=>{
|
|
86
|
+
// ignored
|
|
87
|
+
});
|
|
88
|
+
}, [
|
|
89
|
+
mutateAsync
|
|
90
|
+
]);
|
|
91
|
+
return React.useMemo(()=>({
|
|
92
|
+
...state,
|
|
93
|
+
mutate,
|
|
94
|
+
mutateAsync
|
|
95
|
+
}), [
|
|
96
|
+
mutate,
|
|
97
|
+
mutateAsync,
|
|
98
|
+
state
|
|
99
|
+
]);
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
exports.experimental_createActionHook = experimental_createActionHook;
|
|
104
|
+
exports.experimental_serverActionLink = experimental_serverActionLink;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { TRPCClientError, createTRPCUntypedClient } from '@trpc/client';
|
|
2
|
+
import { observable, transformResult } from '@trpc/core';
|
|
3
|
+
import { useRef, useState, useEffect, useCallback, useMemo } from 'react';
|
|
4
|
+
import { isFormData } from './shared.mjs';
|
|
5
|
+
|
|
6
|
+
// ts-prune-ignore-next
|
|
7
|
+
function experimental_serverActionLink() {
|
|
8
|
+
return (runtime)=>({ op })=>observable((observer)=>{
|
|
9
|
+
const context = op.context;
|
|
10
|
+
context._action(isFormData(op.input) ? op.input : runtime.transformer.serialize(op.input)).then((data)=>{
|
|
11
|
+
const transformed = transformResult(data, runtime.transformer);
|
|
12
|
+
if (!transformed.ok) {
|
|
13
|
+
observer.error(TRPCClientError.from(transformed.error, {}));
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
observer.next({
|
|
17
|
+
context: op.context,
|
|
18
|
+
result: transformed.result
|
|
19
|
+
});
|
|
20
|
+
observer.complete();
|
|
21
|
+
}).catch((cause)=>{
|
|
22
|
+
observer.error(TRPCClientError.from(cause));
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
}
|
|
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
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export { experimental_createActionHook, experimental_serverActionLink };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/* eslint-disable @typescript-eslint/no-non-null-assertion */ function set(obj, path, value) {
|
|
4
|
+
if (typeof path === 'string') {
|
|
5
|
+
path = path.split(/[\.\[\]]/).filter(Boolean);
|
|
6
|
+
}
|
|
7
|
+
if (path.length > 1) {
|
|
8
|
+
const p = path.shift();
|
|
9
|
+
const isArrayIndex = /^\d+$/.test(path[0]);
|
|
10
|
+
obj[p] = obj[p] || (isArrayIndex ? [] : {});
|
|
11
|
+
set(obj[p], path, value);
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
const p1 = path[0];
|
|
15
|
+
if (obj[p1] === undefined) {
|
|
16
|
+
obj[p1] = value;
|
|
17
|
+
} else if (Array.isArray(obj[p1])) {
|
|
18
|
+
obj[p1].push(value);
|
|
19
|
+
} else {
|
|
20
|
+
obj[p1] = [
|
|
21
|
+
obj[p1],
|
|
22
|
+
value
|
|
23
|
+
];
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function formDataToObject(formData) {
|
|
27
|
+
const obj = {};
|
|
28
|
+
for (const [key, value] of formData.entries()){
|
|
29
|
+
set(obj, key, value);
|
|
30
|
+
}
|
|
31
|
+
return obj;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
exports.formDataToObject = formDataToObject;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-non-null-assertion */ function set(obj, path, value) {
|
|
2
|
+
if (typeof path === 'string') {
|
|
3
|
+
path = path.split(/[\.\[\]]/).filter(Boolean);
|
|
4
|
+
}
|
|
5
|
+
if (path.length > 1) {
|
|
6
|
+
const p = path.shift();
|
|
7
|
+
const isArrayIndex = /^\d+$/.test(path[0]);
|
|
8
|
+
obj[p] = obj[p] || (isArrayIndex ? [] : {});
|
|
9
|
+
set(obj[p], path, value);
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
const p1 = path[0];
|
|
13
|
+
if (obj[p1] === undefined) {
|
|
14
|
+
obj[p1] = value;
|
|
15
|
+
} else if (Array.isArray(obj[p1])) {
|
|
16
|
+
obj[p1].push(value);
|
|
17
|
+
} else {
|
|
18
|
+
obj[p1] = [
|
|
19
|
+
obj[p1],
|
|
20
|
+
value
|
|
21
|
+
];
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
function formDataToObject(formData) {
|
|
25
|
+
const obj = {};
|
|
26
|
+
for (const [key, value] of formData.entries()){
|
|
27
|
+
set(obj, key, value);
|
|
28
|
+
}
|
|
29
|
+
return obj;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export { formDataToObject };
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
3
|
var client = require('@trpc/client');
|
|
6
4
|
var core = require('@trpc/core');
|
|
7
5
|
var cache = require('next/cache');
|
|
8
|
-
var shared = require('
|
|
6
|
+
var shared = require('../shared.js');
|
|
9
7
|
|
|
10
8
|
// import "server-only";
|
|
11
9
|
// ts-prune-ignore-next
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { TRPCClientError } from '@trpc/client';
|
|
2
2
|
import { observable, callProcedure } from '@trpc/core';
|
|
3
3
|
import { unstable_cache } from 'next/cache';
|
|
4
|
-
import {
|
|
4
|
+
import { generateCacheTag } from '../shared.mjs';
|
|
5
5
|
|
|
6
6
|
// import "server-only";
|
|
7
7
|
// ts-prune-ignore-next
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
3
|
var client = require('@trpc/client');
|
|
6
|
-
var shared = require('
|
|
7
|
-
require('@trpc/core');
|
|
4
|
+
var shared = require('../shared.js');
|
|
8
5
|
|
|
9
6
|
// ts-prune-ignore-next
|
|
10
7
|
function experimental_nextHttpLink(opts) {
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { httpBatchLink, httpLink } from '@trpc/client';
|
|
2
|
-
import {
|
|
3
|
-
import '@trpc/core';
|
|
2
|
+
import { generateCacheTag } from '../shared.mjs';
|
|
4
3
|
|
|
5
4
|
// ts-prune-ignore-next
|
|
6
5
|
function experimental_nextHttpLink(opts) {
|
package/dist/app-dir/server.js
CHANGED
|
@@ -1,43 +1,11 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
3
|
var client = require('@trpc/client');
|
|
6
4
|
var core = require('@trpc/core');
|
|
7
5
|
var cache = require('next/cache');
|
|
8
6
|
var React = require('react');
|
|
9
|
-
var
|
|
10
|
-
|
|
11
|
-
/* eslint-disable @typescript-eslint/no-non-null-assertion */ function set(obj, path, value) {
|
|
12
|
-
if (typeof path === 'string') {
|
|
13
|
-
path = path.split(/[\.\[\]]/).filter(Boolean);
|
|
14
|
-
}
|
|
15
|
-
if (path.length > 1) {
|
|
16
|
-
const p = path.shift();
|
|
17
|
-
const isArrayIndex = /^\d+$/.test(path[0]);
|
|
18
|
-
obj[p] = obj[p] || (isArrayIndex ? [] : {});
|
|
19
|
-
set(obj[p], path, value);
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
const p1 = path[0];
|
|
23
|
-
if (obj[p1] === undefined) {
|
|
24
|
-
obj[p1] = value;
|
|
25
|
-
} else if (Array.isArray(obj[p1])) {
|
|
26
|
-
obj[p1].push(value);
|
|
27
|
-
} else {
|
|
28
|
-
obj[p1] = [
|
|
29
|
-
obj[p1],
|
|
30
|
-
value
|
|
31
|
-
];
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
function formDataToObject(formData) {
|
|
35
|
-
const obj = {};
|
|
36
|
-
for (const [key, value] of formData.entries()){
|
|
37
|
-
set(obj, key, value);
|
|
38
|
-
}
|
|
39
|
-
return obj;
|
|
40
|
-
}
|
|
7
|
+
var formDataToObject = require('./formDataToObject.js');
|
|
8
|
+
var shared = require('./shared.js');
|
|
41
9
|
|
|
42
10
|
/// <reference types="next" />
|
|
43
11
|
// ts-prune-ignore-next
|
|
@@ -77,7 +45,7 @@ function experimental_createServerActionHandler(t, opts) {
|
|
|
77
45
|
if (normalizeFormData && shared.isFormData(rawInput)) {
|
|
78
46
|
// Normalizes formdata so we can use `z.object({})` etc on the server
|
|
79
47
|
try {
|
|
80
|
-
rawInput = formDataToObject(rawInput);
|
|
48
|
+
rawInput = formDataToObject.formDataToObject(rawInput);
|
|
81
49
|
} catch {
|
|
82
50
|
throw new core.TRPCError({
|
|
83
51
|
code: 'INTERNAL_SERVER_ERROR',
|
package/dist/app-dir/server.mjs
CHANGED
|
@@ -2,38 +2,8 @@ import { createTRPCUntypedClient, clientCallTypeToProcedureType } from '@trpc/cl
|
|
|
2
2
|
import { createRecursiveProxy, TRPCError, transformTRPCResponse, getTRPCErrorFromUnknown, getErrorShape } from '@trpc/core';
|
|
3
3
|
import { revalidateTag } from 'next/cache';
|
|
4
4
|
import { cache } from 'react';
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
/* eslint-disable @typescript-eslint/no-non-null-assertion */ function set(obj, path, value) {
|
|
8
|
-
if (typeof path === 'string') {
|
|
9
|
-
path = path.split(/[\.\[\]]/).filter(Boolean);
|
|
10
|
-
}
|
|
11
|
-
if (path.length > 1) {
|
|
12
|
-
const p = path.shift();
|
|
13
|
-
const isArrayIndex = /^\d+$/.test(path[0]);
|
|
14
|
-
obj[p] = obj[p] || (isArrayIndex ? [] : {});
|
|
15
|
-
set(obj[p], path, value);
|
|
16
|
-
return;
|
|
17
|
-
}
|
|
18
|
-
const p1 = path[0];
|
|
19
|
-
if (obj[p1] === undefined) {
|
|
20
|
-
obj[p1] = value;
|
|
21
|
-
} else if (Array.isArray(obj[p1])) {
|
|
22
|
-
obj[p1].push(value);
|
|
23
|
-
} else {
|
|
24
|
-
obj[p1] = [
|
|
25
|
-
obj[p1],
|
|
26
|
-
value
|
|
27
|
-
];
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
function formDataToObject(formData) {
|
|
31
|
-
const obj = {};
|
|
32
|
-
for (const [key, value] of formData.entries()){
|
|
33
|
-
set(obj, key, value);
|
|
34
|
-
}
|
|
35
|
-
return obj;
|
|
36
|
-
}
|
|
5
|
+
import { formDataToObject } from './formDataToObject.mjs';
|
|
6
|
+
import { generateCacheTag, isFormData } from './shared.mjs';
|
|
37
7
|
|
|
38
8
|
/// <reference types="next" />
|
|
39
9
|
// ts-prune-ignore-next
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var core = require('@trpc/core');
|
|
4
|
+
var shared = require('@trpc/react-query/shared');
|
|
5
|
+
var React = require('react');
|
|
6
|
+
var withTRPC = require('./withTRPC.js');
|
|
7
|
+
|
|
8
|
+
/* istanbul ignore file -- @preserve */ // We're testing this through E2E-testing
|
|
9
|
+
function createTRPCNext(opts) {
|
|
10
|
+
const hooks = shared.createRootHooks(opts);
|
|
11
|
+
// TODO: maybe set TSSRContext to `never` when using `WithTRPCNoSSROptions`
|
|
12
|
+
const _withTRPC = withTRPC.withTRPC(opts);
|
|
13
|
+
return core.createFlatProxy((key)=>{
|
|
14
|
+
if (key === 'useContext' || key === 'useUtils') {
|
|
15
|
+
return ()=>{
|
|
16
|
+
const context = hooks.useUtils();
|
|
17
|
+
// create a stable reference of the utils context
|
|
18
|
+
return React.useMemo(()=>{
|
|
19
|
+
return shared.createReactQueryUtils(context);
|
|
20
|
+
}, [
|
|
21
|
+
context
|
|
22
|
+
]);
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
if (key === 'useQueries') {
|
|
26
|
+
return hooks.useQueries;
|
|
27
|
+
}
|
|
28
|
+
if (key === 'useSuspenseQueries') {
|
|
29
|
+
return hooks.useSuspenseQueries;
|
|
30
|
+
}
|
|
31
|
+
if (key === 'withTRPC') {
|
|
32
|
+
return _withTRPC;
|
|
33
|
+
}
|
|
34
|
+
return shared.createReactDecoration(key, hooks);
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
exports.createTRPCNext = createTRPCNext;
|