@creatorem/next-trpc 1.0.11 → 1.0.12
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/create-trpc-api.js +15 -1
- package/dist/create-trpc-client.js +12 -1
- package/package.json +1 -1
package/dist/create-trpc-api.js
CHANGED
|
@@ -11,7 +11,21 @@ const parseInput = (request, endpoint) => {
|
|
|
11
11
|
const paramsObj = {};
|
|
12
12
|
// Convert URLSearchParams to object
|
|
13
13
|
for (const [key, value] of searchParams) {
|
|
14
|
-
|
|
14
|
+
try {
|
|
15
|
+
// Try to parse as JSON first, but only for complex types (arrays/objects)
|
|
16
|
+
// Skip JSON parsing for simple primitives to preserve string values
|
|
17
|
+
const parsed = JSON.parse(value);
|
|
18
|
+
if (Array.isArray(parsed) || (typeof parsed === 'object' && parsed !== null)) {
|
|
19
|
+
paramsObj[key] = parsed;
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
paramsObj[key] = value;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
catch (_a) {
|
|
26
|
+
// If JSON parsing fails, keep as string
|
|
27
|
+
paramsObj[key] = value;
|
|
28
|
+
}
|
|
15
29
|
}
|
|
16
30
|
// Validate input with endpoint schema
|
|
17
31
|
return endpoint.input.parse(paramsObj);
|
|
@@ -9,7 +9,18 @@ const getTrpcFetch = ({ endpointSlug, url, headers, }) => async (input) => {
|
|
|
9
9
|
if (input) {
|
|
10
10
|
const searchParams = new URLSearchParams();
|
|
11
11
|
for (const [key, value] of Object.entries(input)) {
|
|
12
|
-
|
|
12
|
+
if (Array.isArray(value)) {
|
|
13
|
+
// Handle arrays by JSON stringifying them
|
|
14
|
+
searchParams.append(key, JSON.stringify(value));
|
|
15
|
+
}
|
|
16
|
+
else if (value !== null && typeof value === 'object') {
|
|
17
|
+
// Handle objects by JSON stringifying them
|
|
18
|
+
searchParams.append(key, JSON.stringify(value));
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
// Handle primitive values as strings
|
|
22
|
+
searchParams.append(key, String(value));
|
|
23
|
+
}
|
|
13
24
|
}
|
|
14
25
|
requestUrl += `?${searchParams.toString()}`;
|
|
15
26
|
}
|