routesync 1.0.31 → 1.0.33
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/cli.js +3 -4
- package/dist/react.d.mts +7 -13
- package/dist/react.d.ts +7 -13
- package/dist/react.js +7 -11
- package/dist/react.mjs +7 -11
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -9057,19 +9057,18 @@ var HookGenerator = class _HookGenerator {
|
|
|
9057
9057
|
for (const route of routes) {
|
|
9058
9058
|
const method = route.method.toUpperCase();
|
|
9059
9059
|
const hookName = _HookGenerator.toHookName(group, route.actionName);
|
|
9060
|
-
const queryKey = `['${group}', '${route.actionName}']`;
|
|
9061
9060
|
const contractName = `${toTypeName(group)}${toTypeName(route.actionName)}Contract`;
|
|
9062
9061
|
const hasParams = route.path.includes(":") || route.path.includes("{");
|
|
9063
|
-
const hasQuery = route.schema?.query || route.method.toUpperCase() === "GET";
|
|
9064
9062
|
const hasBody = route.schema?.body;
|
|
9065
|
-
const requiresOptions = hasParams || hasBody
|
|
9063
|
+
const requiresOptions = hasParams || hasBody;
|
|
9066
9064
|
if (method === "GET") {
|
|
9067
9065
|
lines.push(`/**`);
|
|
9068
9066
|
lines.push(` * @deprecated Generated hooks will become optional in v2.`);
|
|
9069
9067
|
lines.push(` * Prefer \`useApiQuery(api.${group}.${route.actionName}, ...args)\` for future compatibility.`);
|
|
9070
9068
|
lines.push(` */`);
|
|
9071
9069
|
lines.push(`export function ${hookName}(...args: [options${requiresOptions ? "" : "?"}: import('./api').${contractName}['request'], queryOptions?: import('routesync/react').ApiQueryOptions<import('./api').${contractName}['response'], import('./types').ApiError>]) {`);
|
|
9072
|
-
lines.push(`
|
|
9070
|
+
lines.push(` const [options, queryOptions] = args`);
|
|
9071
|
+
lines.push(` return useApiQuery<import('./api').${contractName}['response'], import('./api').${contractName}['request']['params'], import('./api').${contractName}['request']['body'], import('./types').ApiError>(api.${group}.${route.actionName}, options, queryOptions)`);
|
|
9073
9072
|
lines.push(`}`);
|
|
9074
9073
|
lines.push(``);
|
|
9075
9074
|
} else {
|
package/dist/react.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as _tanstack_react_query from '@tanstack/react-query';
|
|
2
|
-
import { UseQueryOptions, InfiniteData, UseInfiniteQueryOptions, UseSuspenseQueryOptions, UseMutationOptions, QueryClient } from '@tanstack/react-query';
|
|
2
|
+
import { UseQueryOptions, useQuery, InfiniteData, UseInfiniteQueryOptions, UseSuspenseQueryOptions, UseMutationOptions, QueryClient } from '@tanstack/react-query';
|
|
3
3
|
|
|
4
4
|
type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
5
5
|
type RouteTransform = (value: unknown) => unknown;
|
|
@@ -83,18 +83,12 @@ interface EndpointCallable<TResponse = unknown, TParams = unknown, TBody = unkno
|
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
type ApiQueryOptions<TResponse, TError = ApiError, TData = TResponse> = Omit<UseQueryOptions<TResponse, TError, TData>, 'queryKey' | 'queryFn'>;
|
|
86
|
-
declare function useApiQuery<TResponse
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
queryOptions?: Omit<UseSuspenseQueryOptions<TResponse, TError, TData>, 'queryKey' | 'queryFn'>
|
|
93
|
-
]): _tanstack_react_query.UseSuspenseQueryResult<TData, TError>;
|
|
94
|
-
declare function useApiInfiniteQuery<TResponse = unknown, TParams = unknown, TBody = unknown, TError = ApiError, TData = InfiniteData<TResponse>, TPageParam = unknown>(endpoint: EndpointCallable<TResponse, TParams, TBody>, ...args: [
|
|
95
|
-
...OptionalIfEmpty<EndpointCallableOptions<TParams, TBody>>,
|
|
96
|
-
queryOptions: Omit<UseInfiniteQueryOptions<TResponse, TError, TData, any, TPageParam>, 'queryKey' | 'queryFn'>
|
|
97
|
-
]): _tanstack_react_query.UseInfiniteQueryResult<TData, TError>;
|
|
86
|
+
declare function useApiQuery<TResponse, TParams, TBody, TError = ApiError, TData = TResponse>(endpoint: EndpointCallable<TResponse, TParams, TBody>, options: EndpointCallableOptions<TParams, TBody>, queryOptions?: ApiQueryOptions<TResponse, TError, TData>): ReturnType<typeof useQuery<TResponse, TError, TData>>;
|
|
87
|
+
declare function useApiQuery<TResponse, TParams, TBody, TError = ApiError, TData = TResponse>(endpoint: EndpointCallable<TResponse, TParams, TBody>, options?: EndpointCallableOptions<TParams, TBody>, queryOptions?: ApiQueryOptions<TResponse, TError, TData>): ReturnType<typeof useQuery<TResponse, TError, TData>>;
|
|
88
|
+
declare function useApiSuspenseQuery<TResponse = unknown, TParams = unknown, TBody = unknown, TError = ApiError, TData = TResponse>(endpoint: EndpointCallable<TResponse, TParams, TBody>, options?: EndpointCallableOptions<TParams, TBody>, queryOptions?: Omit<UseSuspenseQueryOptions<TResponse, TError, TData>, 'queryKey' | 'queryFn'>): _tanstack_react_query.UseSuspenseQueryResult<TData, TError>;
|
|
89
|
+
declare function useApiInfiniteQuery<TResponse = unknown, TParams = unknown, TBody = unknown, TError = ApiError, TData = InfiniteData<TResponse>, TPageParam = unknown>(endpoint: EndpointCallable<TResponse, TParams, TBody>, options: EndpointCallableOptions<TParams, TBody> | undefined, queryOptions: Omit<UseInfiniteQueryOptions<TResponse, TError, TData, any, TPageParam>, 'queryKey' | 'queryFn'> & {
|
|
90
|
+
getNextPageParam: UseInfiniteQueryOptions<TResponse, TError, TData, any, TPageParam>['getNextPageParam'];
|
|
91
|
+
}): _tanstack_react_query.UseInfiniteQueryResult<TData, TError>;
|
|
98
92
|
|
|
99
93
|
/**
|
|
100
94
|
* useApiMutation — accepts an endpoint callable directly.
|
package/dist/react.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as _tanstack_react_query from '@tanstack/react-query';
|
|
2
|
-
import { UseQueryOptions, InfiniteData, UseInfiniteQueryOptions, UseSuspenseQueryOptions, UseMutationOptions, QueryClient } from '@tanstack/react-query';
|
|
2
|
+
import { UseQueryOptions, useQuery, InfiniteData, UseInfiniteQueryOptions, UseSuspenseQueryOptions, UseMutationOptions, QueryClient } from '@tanstack/react-query';
|
|
3
3
|
|
|
4
4
|
type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
5
5
|
type RouteTransform = (value: unknown) => unknown;
|
|
@@ -83,18 +83,12 @@ interface EndpointCallable<TResponse = unknown, TParams = unknown, TBody = unkno
|
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
type ApiQueryOptions<TResponse, TError = ApiError, TData = TResponse> = Omit<UseQueryOptions<TResponse, TError, TData>, 'queryKey' | 'queryFn'>;
|
|
86
|
-
declare function useApiQuery<TResponse
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
queryOptions?: Omit<UseSuspenseQueryOptions<TResponse, TError, TData>, 'queryKey' | 'queryFn'>
|
|
93
|
-
]): _tanstack_react_query.UseSuspenseQueryResult<TData, TError>;
|
|
94
|
-
declare function useApiInfiniteQuery<TResponse = unknown, TParams = unknown, TBody = unknown, TError = ApiError, TData = InfiniteData<TResponse>, TPageParam = unknown>(endpoint: EndpointCallable<TResponse, TParams, TBody>, ...args: [
|
|
95
|
-
...OptionalIfEmpty<EndpointCallableOptions<TParams, TBody>>,
|
|
96
|
-
queryOptions: Omit<UseInfiniteQueryOptions<TResponse, TError, TData, any, TPageParam>, 'queryKey' | 'queryFn'>
|
|
97
|
-
]): _tanstack_react_query.UseInfiniteQueryResult<TData, TError>;
|
|
86
|
+
declare function useApiQuery<TResponse, TParams, TBody, TError = ApiError, TData = TResponse>(endpoint: EndpointCallable<TResponse, TParams, TBody>, options: EndpointCallableOptions<TParams, TBody>, queryOptions?: ApiQueryOptions<TResponse, TError, TData>): ReturnType<typeof useQuery<TResponse, TError, TData>>;
|
|
87
|
+
declare function useApiQuery<TResponse, TParams, TBody, TError = ApiError, TData = TResponse>(endpoint: EndpointCallable<TResponse, TParams, TBody>, options?: EndpointCallableOptions<TParams, TBody>, queryOptions?: ApiQueryOptions<TResponse, TError, TData>): ReturnType<typeof useQuery<TResponse, TError, TData>>;
|
|
88
|
+
declare function useApiSuspenseQuery<TResponse = unknown, TParams = unknown, TBody = unknown, TError = ApiError, TData = TResponse>(endpoint: EndpointCallable<TResponse, TParams, TBody>, options?: EndpointCallableOptions<TParams, TBody>, queryOptions?: Omit<UseSuspenseQueryOptions<TResponse, TError, TData>, 'queryKey' | 'queryFn'>): _tanstack_react_query.UseSuspenseQueryResult<TData, TError>;
|
|
89
|
+
declare function useApiInfiniteQuery<TResponse = unknown, TParams = unknown, TBody = unknown, TError = ApiError, TData = InfiniteData<TResponse>, TPageParam = unknown>(endpoint: EndpointCallable<TResponse, TParams, TBody>, options: EndpointCallableOptions<TParams, TBody> | undefined, queryOptions: Omit<UseInfiniteQueryOptions<TResponse, TError, TData, any, TPageParam>, 'queryKey' | 'queryFn'> & {
|
|
90
|
+
getNextPageParam: UseInfiniteQueryOptions<TResponse, TError, TData, any, TPageParam>['getNextPageParam'];
|
|
91
|
+
}): _tanstack_react_query.UseInfiniteQueryResult<TData, TError>;
|
|
98
92
|
|
|
99
93
|
/**
|
|
100
94
|
* useApiMutation — accepts an endpoint callable directly.
|
package/dist/react.js
CHANGED
|
@@ -32,29 +32,25 @@ module.exports = __toCommonJS(src_exports);
|
|
|
32
32
|
|
|
33
33
|
// packages/react/src/hooks/useQuery.ts
|
|
34
34
|
var import_react_query = require("@tanstack/react-query");
|
|
35
|
-
function useApiQuery(endpoint,
|
|
36
|
-
const options = args[0];
|
|
37
|
-
const queryOptions = args[1];
|
|
35
|
+
function useApiQuery(endpoint, options, queryOptions) {
|
|
38
36
|
const queryKey = endpoint.$queryKey(options);
|
|
37
|
+
const callEndpoint = endpoint;
|
|
39
38
|
return (0, import_react_query.useQuery)({
|
|
40
39
|
queryKey,
|
|
41
|
-
queryFn: () =>
|
|
40
|
+
queryFn: () => callEndpoint(options),
|
|
42
41
|
...queryOptions
|
|
43
42
|
});
|
|
44
43
|
}
|
|
45
|
-
function useApiSuspenseQuery(endpoint,
|
|
46
|
-
const options = args[0];
|
|
47
|
-
const queryOptions = args[1];
|
|
44
|
+
function useApiSuspenseQuery(endpoint, options, queryOptions) {
|
|
48
45
|
const queryKey = endpoint.$queryKey(options);
|
|
46
|
+
const callEndpoint = endpoint;
|
|
49
47
|
return (0, import_react_query.useSuspenseQuery)({
|
|
50
48
|
queryKey,
|
|
51
|
-
queryFn: () =>
|
|
49
|
+
queryFn: () => callEndpoint(options),
|
|
52
50
|
...queryOptions
|
|
53
51
|
});
|
|
54
52
|
}
|
|
55
|
-
function useApiInfiniteQuery(endpoint,
|
|
56
|
-
const options = args[0];
|
|
57
|
-
const queryOptions = args.length > 1 ? args[1] : args[0];
|
|
53
|
+
function useApiInfiniteQuery(endpoint, options, queryOptions) {
|
|
58
54
|
const queryKey = endpoint.$queryKey(options);
|
|
59
55
|
return (0, import_react_query.useInfiniteQuery)({
|
|
60
56
|
queryKey,
|
package/dist/react.mjs
CHANGED
|
@@ -1,28 +1,24 @@
|
|
|
1
1
|
// packages/react/src/hooks/useQuery.ts
|
|
2
2
|
import { useQuery, useSuspenseQuery, useInfiniteQuery } from "@tanstack/react-query";
|
|
3
|
-
function useApiQuery(endpoint,
|
|
4
|
-
const options = args[0];
|
|
5
|
-
const queryOptions = args[1];
|
|
3
|
+
function useApiQuery(endpoint, options, queryOptions) {
|
|
6
4
|
const queryKey = endpoint.$queryKey(options);
|
|
5
|
+
const callEndpoint = endpoint;
|
|
7
6
|
return useQuery({
|
|
8
7
|
queryKey,
|
|
9
|
-
queryFn: () =>
|
|
8
|
+
queryFn: () => callEndpoint(options),
|
|
10
9
|
...queryOptions
|
|
11
10
|
});
|
|
12
11
|
}
|
|
13
|
-
function useApiSuspenseQuery(endpoint,
|
|
14
|
-
const options = args[0];
|
|
15
|
-
const queryOptions = args[1];
|
|
12
|
+
function useApiSuspenseQuery(endpoint, options, queryOptions) {
|
|
16
13
|
const queryKey = endpoint.$queryKey(options);
|
|
14
|
+
const callEndpoint = endpoint;
|
|
17
15
|
return useSuspenseQuery({
|
|
18
16
|
queryKey,
|
|
19
|
-
queryFn: () =>
|
|
17
|
+
queryFn: () => callEndpoint(options),
|
|
20
18
|
...queryOptions
|
|
21
19
|
});
|
|
22
20
|
}
|
|
23
|
-
function useApiInfiniteQuery(endpoint,
|
|
24
|
-
const options = args[0];
|
|
25
|
-
const queryOptions = args.length > 1 ? args[1] : args[0];
|
|
21
|
+
function useApiInfiniteQuery(endpoint, options, queryOptions) {
|
|
26
22
|
const queryKey = endpoint.$queryKey(options);
|
|
27
23
|
return useInfiniteQuery({
|
|
28
24
|
queryKey,
|