routesync 1.0.29 → 1.0.30
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/react.d.mts +10 -36
- package/dist/react.d.ts +10 -36
- package/dist/react.js +5 -20
- package/dist/react.mjs +5 -20
- package/dist/sdk.d.mts +3 -1
- package/dist/sdk.d.ts +3 -1
- package/package.json +1 -1
package/dist/react.d.mts
CHANGED
|
@@ -45,6 +45,12 @@ interface RouteDefinition<TResponse = unknown, TParams = unknown, TBody = unknow
|
|
|
45
45
|
_typeBody?: TBody;
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
+
type CallOptions<TParams = unknown, TBody = unknown> = {
|
|
49
|
+
params?: TParams;
|
|
50
|
+
query?: Record<string, any>;
|
|
51
|
+
body?: TBody;
|
|
52
|
+
headers?: Record<string, string>;
|
|
53
|
+
};
|
|
48
54
|
type EndpointCallableOptions<TParams, TBody> = (unknown extends TParams ? {} : {
|
|
49
55
|
params: TParams;
|
|
50
56
|
}) & (unknown extends TBody ? {
|
|
@@ -66,36 +72,25 @@ interface ApiError {
|
|
|
66
72
|
}
|
|
67
73
|
interface EndpointCallable<TResponse = unknown, TParams = unknown, TBody = unknown> {
|
|
68
74
|
(...args: OptionalIfEmpty<EndpointCallableOptions<TParams, TBody>>): Promise<TResponse>;
|
|
75
|
+
(options: EndpointCallableOptions<TParams, TBody> | undefined): Promise<TResponse>;
|
|
76
|
+
(options: CallOptions<TParams, TBody>): Promise<TResponse>;
|
|
69
77
|
/** Original RouteDefinition — used by useApiQuery / useApiMutation */
|
|
70
78
|
$def: RouteDefinition<TResponse, TParams, TBody>;
|
|
71
79
|
/** Stable TanStack query key: [group, action] */
|
|
72
80
|
$key: string[];
|
|
73
81
|
/** Consistent query key builder that incorporates params/query if provided */
|
|
74
|
-
$queryKey: (
|
|
82
|
+
$queryKey: (options?: EndpointCallableOptions<TParams, TBody>) => unknown[];
|
|
75
83
|
}
|
|
76
84
|
|
|
77
|
-
/**
|
|
78
|
-
* useApiQuery — accepts an endpoint callable directly.
|
|
79
|
-
*
|
|
80
|
-
* Usage:
|
|
81
|
-
* const { data, isLoading } = useApiQuery(api.produk.list)
|
|
82
|
-
* const { data } = useApiQuery(api.produk.detail, { params: { id: 10 } })
|
|
83
|
-
*/
|
|
84
85
|
type ApiQueryOptions<TResponse, TError = ApiError, TData = TResponse> = Omit<UseQueryOptions<TResponse, TError, TData>, 'queryKey' | 'queryFn'>;
|
|
85
86
|
declare function useApiQuery<TResponse = unknown, TParams = unknown, TBody = unknown, TError = ApiError, TData = TResponse>(endpoint: EndpointCallable<TResponse, TParams, TBody>, ...args: [
|
|
86
87
|
...OptionalIfEmpty<EndpointCallableOptions<TParams, TBody>>,
|
|
87
|
-
queryOptions?:
|
|
88
|
+
queryOptions?: ApiQueryOptions<TResponse, TError, TData>
|
|
88
89
|
]): _tanstack_react_query.UseQueryResult<NoInfer<TData>, TError>;
|
|
89
|
-
/**
|
|
90
|
-
* useApiSuspenseQuery — generic wrapper for Suspense-enabled data fetching (TanStack v5).
|
|
91
|
-
*/
|
|
92
90
|
declare function useApiSuspenseQuery<TResponse = unknown, TParams = unknown, TBody = unknown, TError = ApiError, TData = TResponse>(endpoint: EndpointCallable<TResponse, TParams, TBody>, ...args: [
|
|
93
91
|
...OptionalIfEmpty<EndpointCallableOptions<TParams, TBody>>,
|
|
94
92
|
queryOptions?: Omit<UseSuspenseQueryOptions<TResponse, TError, TData>, 'queryKey' | 'queryFn'>
|
|
95
93
|
]): _tanstack_react_query.UseSuspenseQueryResult<TData, TError>;
|
|
96
|
-
/**
|
|
97
|
-
* useApiInfiniteQuery — framework agnostic paginated fetching.
|
|
98
|
-
*/
|
|
99
94
|
declare function useApiInfiniteQuery<TResponse = unknown, TParams = unknown, TBody = unknown, TError = ApiError, TData = InfiniteData<TResponse>, TPageParam = unknown>(endpoint: EndpointCallable<TResponse, TParams, TBody>, ...args: [
|
|
100
95
|
...OptionalIfEmpty<EndpointCallableOptions<TParams, TBody>>,
|
|
101
96
|
queryOptions: Omit<UseInfiniteQueryOptions<TResponse, TError, TData, any, TPageParam>, 'queryKey' | 'queryFn'>
|
|
@@ -120,32 +115,11 @@ interface ApiMutationOptions<TData, TError, TVariables, TContext = unknown> exte
|
|
|
120
115
|
}
|
|
121
116
|
declare function useApiMutation<TResponse = unknown, TParams = unknown, TBody = unknown, TError = ApiError, TContext = unknown>(endpoint: EndpointCallable<TResponse, TParams, TBody>, options?: ApiMutationOptions<TResponse, TError, EndpointCallableOptions<TParams, TBody>, TContext>): _tanstack_react_query.UseMutationResult<TResponse, TError, EndpointCallableOptions<TParams, TBody>, TContext>;
|
|
122
117
|
|
|
123
|
-
/**
|
|
124
|
-
* useApiQueryClient — a typed wrapper over TanStack's QueryClient
|
|
125
|
-
*
|
|
126
|
-
* Provides ergonomic helpers like invalidateEndpoint and prefetchEndpoint
|
|
127
|
-
* with strong typing based on the RouteSync SDK contracts.
|
|
128
|
-
*/
|
|
129
118
|
declare function useApiQueryClient(): {
|
|
130
119
|
queryClient: QueryClient;
|
|
131
|
-
/**
|
|
132
|
-
* Invalidate specific queries related to an endpoint.
|
|
133
|
-
* Optionally pass parameters to invalidate a more specific cache entry.
|
|
134
|
-
*/
|
|
135
120
|
invalidateEndpoint: <TResponse, TParams, TBody>(endpoint: EndpointCallable<TResponse, TParams, TBody>, options?: EndpointCallableOptions<TParams, TBody>) => Promise<void>;
|
|
136
|
-
/**
|
|
137
|
-
* Prefetch data for an endpoint into the cache.
|
|
138
|
-
* Useful for SSR, RSC hydration, or proactive prefetching.
|
|
139
|
-
*/
|
|
140
121
|
prefetchEndpoint: <TResponse, TParams, TBody>(endpoint: EndpointCallable<TResponse, TParams, TBody>, options?: EndpointCallableOptions<TParams, TBody>) => Promise<void>;
|
|
141
|
-
/**
|
|
142
|
-
* Manually update the cache for a specific endpoint.
|
|
143
|
-
* Often used for optimistic updates in mutations.
|
|
144
|
-
*/
|
|
145
122
|
setEndpointData: <TResponse, TParams, TBody>(endpoint: EndpointCallable<TResponse, TParams, TBody>, options: EndpointCallableOptions<TParams, TBody> | undefined, updater: TResponse | ((oldData: TResponse | undefined) => TResponse)) => unknown;
|
|
146
|
-
/**
|
|
147
|
-
* Retrieve the current cached data for a specific endpoint.
|
|
148
|
-
*/
|
|
149
123
|
getEndpointData: <TResponse, TParams, TBody>(endpoint: EndpointCallable<TResponse, TParams, TBody>, options?: EndpointCallableOptions<TParams, TBody>) => TResponse | undefined;
|
|
150
124
|
};
|
|
151
125
|
|
package/dist/react.d.ts
CHANGED
|
@@ -45,6 +45,12 @@ interface RouteDefinition<TResponse = unknown, TParams = unknown, TBody = unknow
|
|
|
45
45
|
_typeBody?: TBody;
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
+
type CallOptions<TParams = unknown, TBody = unknown> = {
|
|
49
|
+
params?: TParams;
|
|
50
|
+
query?: Record<string, any>;
|
|
51
|
+
body?: TBody;
|
|
52
|
+
headers?: Record<string, string>;
|
|
53
|
+
};
|
|
48
54
|
type EndpointCallableOptions<TParams, TBody> = (unknown extends TParams ? {} : {
|
|
49
55
|
params: TParams;
|
|
50
56
|
}) & (unknown extends TBody ? {
|
|
@@ -66,36 +72,25 @@ interface ApiError {
|
|
|
66
72
|
}
|
|
67
73
|
interface EndpointCallable<TResponse = unknown, TParams = unknown, TBody = unknown> {
|
|
68
74
|
(...args: OptionalIfEmpty<EndpointCallableOptions<TParams, TBody>>): Promise<TResponse>;
|
|
75
|
+
(options: EndpointCallableOptions<TParams, TBody> | undefined): Promise<TResponse>;
|
|
76
|
+
(options: CallOptions<TParams, TBody>): Promise<TResponse>;
|
|
69
77
|
/** Original RouteDefinition — used by useApiQuery / useApiMutation */
|
|
70
78
|
$def: RouteDefinition<TResponse, TParams, TBody>;
|
|
71
79
|
/** Stable TanStack query key: [group, action] */
|
|
72
80
|
$key: string[];
|
|
73
81
|
/** Consistent query key builder that incorporates params/query if provided */
|
|
74
|
-
$queryKey: (
|
|
82
|
+
$queryKey: (options?: EndpointCallableOptions<TParams, TBody>) => unknown[];
|
|
75
83
|
}
|
|
76
84
|
|
|
77
|
-
/**
|
|
78
|
-
* useApiQuery — accepts an endpoint callable directly.
|
|
79
|
-
*
|
|
80
|
-
* Usage:
|
|
81
|
-
* const { data, isLoading } = useApiQuery(api.produk.list)
|
|
82
|
-
* const { data } = useApiQuery(api.produk.detail, { params: { id: 10 } })
|
|
83
|
-
*/
|
|
84
85
|
type ApiQueryOptions<TResponse, TError = ApiError, TData = TResponse> = Omit<UseQueryOptions<TResponse, TError, TData>, 'queryKey' | 'queryFn'>;
|
|
85
86
|
declare function useApiQuery<TResponse = unknown, TParams = unknown, TBody = unknown, TError = ApiError, TData = TResponse>(endpoint: EndpointCallable<TResponse, TParams, TBody>, ...args: [
|
|
86
87
|
...OptionalIfEmpty<EndpointCallableOptions<TParams, TBody>>,
|
|
87
|
-
queryOptions?:
|
|
88
|
+
queryOptions?: ApiQueryOptions<TResponse, TError, TData>
|
|
88
89
|
]): _tanstack_react_query.UseQueryResult<NoInfer<TData>, TError>;
|
|
89
|
-
/**
|
|
90
|
-
* useApiSuspenseQuery — generic wrapper for Suspense-enabled data fetching (TanStack v5).
|
|
91
|
-
*/
|
|
92
90
|
declare function useApiSuspenseQuery<TResponse = unknown, TParams = unknown, TBody = unknown, TError = ApiError, TData = TResponse>(endpoint: EndpointCallable<TResponse, TParams, TBody>, ...args: [
|
|
93
91
|
...OptionalIfEmpty<EndpointCallableOptions<TParams, TBody>>,
|
|
94
92
|
queryOptions?: Omit<UseSuspenseQueryOptions<TResponse, TError, TData>, 'queryKey' | 'queryFn'>
|
|
95
93
|
]): _tanstack_react_query.UseSuspenseQueryResult<TData, TError>;
|
|
96
|
-
/**
|
|
97
|
-
* useApiInfiniteQuery — framework agnostic paginated fetching.
|
|
98
|
-
*/
|
|
99
94
|
declare function useApiInfiniteQuery<TResponse = unknown, TParams = unknown, TBody = unknown, TError = ApiError, TData = InfiniteData<TResponse>, TPageParam = unknown>(endpoint: EndpointCallable<TResponse, TParams, TBody>, ...args: [
|
|
100
95
|
...OptionalIfEmpty<EndpointCallableOptions<TParams, TBody>>,
|
|
101
96
|
queryOptions: Omit<UseInfiniteQueryOptions<TResponse, TError, TData, any, TPageParam>, 'queryKey' | 'queryFn'>
|
|
@@ -120,32 +115,11 @@ interface ApiMutationOptions<TData, TError, TVariables, TContext = unknown> exte
|
|
|
120
115
|
}
|
|
121
116
|
declare function useApiMutation<TResponse = unknown, TParams = unknown, TBody = unknown, TError = ApiError, TContext = unknown>(endpoint: EndpointCallable<TResponse, TParams, TBody>, options?: ApiMutationOptions<TResponse, TError, EndpointCallableOptions<TParams, TBody>, TContext>): _tanstack_react_query.UseMutationResult<TResponse, TError, EndpointCallableOptions<TParams, TBody>, TContext>;
|
|
122
117
|
|
|
123
|
-
/**
|
|
124
|
-
* useApiQueryClient — a typed wrapper over TanStack's QueryClient
|
|
125
|
-
*
|
|
126
|
-
* Provides ergonomic helpers like invalidateEndpoint and prefetchEndpoint
|
|
127
|
-
* with strong typing based on the RouteSync SDK contracts.
|
|
128
|
-
*/
|
|
129
118
|
declare function useApiQueryClient(): {
|
|
130
119
|
queryClient: QueryClient;
|
|
131
|
-
/**
|
|
132
|
-
* Invalidate specific queries related to an endpoint.
|
|
133
|
-
* Optionally pass parameters to invalidate a more specific cache entry.
|
|
134
|
-
*/
|
|
135
120
|
invalidateEndpoint: <TResponse, TParams, TBody>(endpoint: EndpointCallable<TResponse, TParams, TBody>, options?: EndpointCallableOptions<TParams, TBody>) => Promise<void>;
|
|
136
|
-
/**
|
|
137
|
-
* Prefetch data for an endpoint into the cache.
|
|
138
|
-
* Useful for SSR, RSC hydration, or proactive prefetching.
|
|
139
|
-
*/
|
|
140
121
|
prefetchEndpoint: <TResponse, TParams, TBody>(endpoint: EndpointCallable<TResponse, TParams, TBody>, options?: EndpointCallableOptions<TParams, TBody>) => Promise<void>;
|
|
141
|
-
/**
|
|
142
|
-
* Manually update the cache for a specific endpoint.
|
|
143
|
-
* Often used for optimistic updates in mutations.
|
|
144
|
-
*/
|
|
145
122
|
setEndpointData: <TResponse, TParams, TBody>(endpoint: EndpointCallable<TResponse, TParams, TBody>, options: EndpointCallableOptions<TParams, TBody> | undefined, updater: TResponse | ((oldData: TResponse | undefined) => TResponse)) => unknown;
|
|
146
|
-
/**
|
|
147
|
-
* Retrieve the current cached data for a specific endpoint.
|
|
148
|
-
*/
|
|
149
123
|
getEndpointData: <TResponse, TParams, TBody>(endpoint: EndpointCallable<TResponse, TParams, TBody>, options?: EndpointCallableOptions<TParams, TBody>) => TResponse | undefined;
|
|
150
124
|
};
|
|
151
125
|
|
package/dist/react.js
CHANGED
|
@@ -59,11 +59,11 @@ function useApiInfiniteQuery(endpoint, ...args) {
|
|
|
59
59
|
return (0, import_react_query.useInfiniteQuery)({
|
|
60
60
|
queryKey,
|
|
61
61
|
queryFn: ({ pageParam }) => {
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
66
|
-
return endpoint(
|
|
62
|
+
const callOptions = {
|
|
63
|
+
...options,
|
|
64
|
+
query: { ...options?.query, page: pageParam }
|
|
65
|
+
};
|
|
66
|
+
return endpoint(callOptions);
|
|
67
67
|
},
|
|
68
68
|
...queryOptions
|
|
69
69
|
});
|
|
@@ -93,35 +93,20 @@ function useApiQueryClient() {
|
|
|
93
93
|
const queryClient = (0, import_react_query3.useQueryClient)();
|
|
94
94
|
return {
|
|
95
95
|
queryClient,
|
|
96
|
-
/**
|
|
97
|
-
* Invalidate specific queries related to an endpoint.
|
|
98
|
-
* Optionally pass parameters to invalidate a more specific cache entry.
|
|
99
|
-
*/
|
|
100
96
|
invalidateEndpoint: (endpoint, options) => {
|
|
101
97
|
return queryClient.invalidateQueries({
|
|
102
98
|
queryKey: endpoint.$queryKey(options)
|
|
103
99
|
});
|
|
104
100
|
},
|
|
105
|
-
/**
|
|
106
|
-
* Prefetch data for an endpoint into the cache.
|
|
107
|
-
* Useful for SSR, RSC hydration, or proactive prefetching.
|
|
108
|
-
*/
|
|
109
101
|
prefetchEndpoint: (endpoint, options) => {
|
|
110
102
|
return queryClient.prefetchQuery({
|
|
111
103
|
queryKey: endpoint.$queryKey(options),
|
|
112
104
|
queryFn: () => endpoint(options)
|
|
113
105
|
});
|
|
114
106
|
},
|
|
115
|
-
/**
|
|
116
|
-
* Manually update the cache for a specific endpoint.
|
|
117
|
-
* Often used for optimistic updates in mutations.
|
|
118
|
-
*/
|
|
119
107
|
setEndpointData: (endpoint, options, updater) => {
|
|
120
108
|
return queryClient.setQueryData(endpoint.$queryKey(options), updater);
|
|
121
109
|
},
|
|
122
|
-
/**
|
|
123
|
-
* Retrieve the current cached data for a specific endpoint.
|
|
124
|
-
*/
|
|
125
110
|
getEndpointData: (endpoint, options) => {
|
|
126
111
|
return queryClient.getQueryData(endpoint.$queryKey(options));
|
|
127
112
|
}
|
package/dist/react.mjs
CHANGED
|
@@ -27,11 +27,11 @@ function useApiInfiniteQuery(endpoint, ...args) {
|
|
|
27
27
|
return useInfiniteQuery({
|
|
28
28
|
queryKey,
|
|
29
29
|
queryFn: ({ pageParam }) => {
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
return endpoint(
|
|
30
|
+
const callOptions = {
|
|
31
|
+
...options,
|
|
32
|
+
query: { ...options?.query, page: pageParam }
|
|
33
|
+
};
|
|
34
|
+
return endpoint(callOptions);
|
|
35
35
|
},
|
|
36
36
|
...queryOptions
|
|
37
37
|
});
|
|
@@ -61,35 +61,20 @@ function useApiQueryClient() {
|
|
|
61
61
|
const queryClient = useQueryClient2();
|
|
62
62
|
return {
|
|
63
63
|
queryClient,
|
|
64
|
-
/**
|
|
65
|
-
* Invalidate specific queries related to an endpoint.
|
|
66
|
-
* Optionally pass parameters to invalidate a more specific cache entry.
|
|
67
|
-
*/
|
|
68
64
|
invalidateEndpoint: (endpoint, options) => {
|
|
69
65
|
return queryClient.invalidateQueries({
|
|
70
66
|
queryKey: endpoint.$queryKey(options)
|
|
71
67
|
});
|
|
72
68
|
},
|
|
73
|
-
/**
|
|
74
|
-
* Prefetch data for an endpoint into the cache.
|
|
75
|
-
* Useful for SSR, RSC hydration, or proactive prefetching.
|
|
76
|
-
*/
|
|
77
69
|
prefetchEndpoint: (endpoint, options) => {
|
|
78
70
|
return queryClient.prefetchQuery({
|
|
79
71
|
queryKey: endpoint.$queryKey(options),
|
|
80
72
|
queryFn: () => endpoint(options)
|
|
81
73
|
});
|
|
82
74
|
},
|
|
83
|
-
/**
|
|
84
|
-
* Manually update the cache for a specific endpoint.
|
|
85
|
-
* Often used for optimistic updates in mutations.
|
|
86
|
-
*/
|
|
87
75
|
setEndpointData: (endpoint, options, updater) => {
|
|
88
76
|
return queryClient.setQueryData(endpoint.$queryKey(options), updater);
|
|
89
77
|
},
|
|
90
|
-
/**
|
|
91
|
-
* Retrieve the current cached data for a specific endpoint.
|
|
92
|
-
*/
|
|
93
78
|
getEndpointData: (endpoint, options) => {
|
|
94
79
|
return queryClient.getQueryData(endpoint.$queryKey(options));
|
|
95
80
|
}
|
package/dist/sdk.d.mts
CHANGED
|
@@ -142,12 +142,14 @@ interface ApiError {
|
|
|
142
142
|
}
|
|
143
143
|
interface EndpointCallable<TResponse = unknown, TParams = unknown, TBody = unknown> {
|
|
144
144
|
(...args: OptionalIfEmpty<EndpointCallableOptions<TParams, TBody>>): Promise<TResponse>;
|
|
145
|
+
(options: EndpointCallableOptions<TParams, TBody> | undefined): Promise<TResponse>;
|
|
146
|
+
(options: CallOptions<TParams, TBody>): Promise<TResponse>;
|
|
145
147
|
/** Original RouteDefinition — used by useApiQuery / useApiMutation */
|
|
146
148
|
$def: RouteDefinition<TResponse, TParams, TBody>;
|
|
147
149
|
/** Stable TanStack query key: [group, action] */
|
|
148
150
|
$key: string[];
|
|
149
151
|
/** Consistent query key builder that incorporates params/query if provided */
|
|
150
|
-
$queryKey: (
|
|
152
|
+
$queryKey: (options?: EndpointCallableOptions<TParams, TBody>) => unknown[];
|
|
151
153
|
}
|
|
152
154
|
type ApiGroupProxy<G extends Record<string, RouteDefinition<any, any, any>>> = {
|
|
153
155
|
[K in keyof G]: EndpointCallable<G[K] extends RouteDefinition<infer R, any, any> ? R : unknown, G[K] extends RouteDefinition<any, infer P, any> ? P : unknown, G[K] extends RouteDefinition<any, any, infer B> ? B : unknown>;
|
package/dist/sdk.d.ts
CHANGED
|
@@ -142,12 +142,14 @@ interface ApiError {
|
|
|
142
142
|
}
|
|
143
143
|
interface EndpointCallable<TResponse = unknown, TParams = unknown, TBody = unknown> {
|
|
144
144
|
(...args: OptionalIfEmpty<EndpointCallableOptions<TParams, TBody>>): Promise<TResponse>;
|
|
145
|
+
(options: EndpointCallableOptions<TParams, TBody> | undefined): Promise<TResponse>;
|
|
146
|
+
(options: CallOptions<TParams, TBody>): Promise<TResponse>;
|
|
145
147
|
/** Original RouteDefinition — used by useApiQuery / useApiMutation */
|
|
146
148
|
$def: RouteDefinition<TResponse, TParams, TBody>;
|
|
147
149
|
/** Stable TanStack query key: [group, action] */
|
|
148
150
|
$key: string[];
|
|
149
151
|
/** Consistent query key builder that incorporates params/query if provided */
|
|
150
|
-
$queryKey: (
|
|
152
|
+
$queryKey: (options?: EndpointCallableOptions<TParams, TBody>) => unknown[];
|
|
151
153
|
}
|
|
152
154
|
type ApiGroupProxy<G extends Record<string, RouteDefinition<any, any, any>>> = {
|
|
153
155
|
[K in keyof G]: EndpointCallable<G[K] extends RouteDefinition<infer R, any, any> ? R : unknown, G[K] extends RouteDefinition<any, infer P, any> ? P : unknown, G[K] extends RouteDefinition<any, any, infer B> ? B : unknown>;
|