@emeryld/rrroutes-client 2.8.1 → 2.8.3
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/README.md +10 -2
- package/dist/index.cjs +10 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +10 -14
- package/dist/index.mjs.map +1 -1
- package/dist/routesV3.client.batch.d.ts +3 -3
- package/dist/routesV3.client.d.ts +2 -2
- package/dist/routesV3.client.get.d.ts +1 -1
- package/dist/routesV3.client.infiniteGet.d.ts +1 -1
- package/dist/routesV3.client.mutation.d.ts +1 -1
- package/dist/routesV3.client.types.d.ts +51 -44
- package/package.json +1 -1
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { type AnyLeafLowProfile } from '@emeryld/rrroutes-contract';
|
|
2
2
|
import { type QueryClient } from '@tanstack/react-query';
|
|
3
|
-
import type { BranchBuildOptions, BuiltBranch, BuiltLeafMap, RouteClientFetch } from './routesV3.client.types';
|
|
3
|
+
import type { BranchBuildOptions, BuiltBranch, BuiltForLeaf, BuiltLeafMap, RouteClientFetch } from './routesV3.client.types';
|
|
4
4
|
type BuildBatchBranchDeps = {
|
|
5
5
|
fetchRaw: RouteClientFetch;
|
|
6
6
|
queryClient: QueryClient;
|
|
7
7
|
validateResponses: boolean;
|
|
8
|
-
getBuiltLeaf: (built:
|
|
8
|
+
getBuiltLeaf: (built: BuiltForLeaf<any>) => AnyLeafLowProfile;
|
|
9
9
|
encodeLeafKey: (leaf: AnyLeafLowProfile) => string;
|
|
10
10
|
toArgsTuple: (args: unknown) => unknown[];
|
|
11
11
|
};
|
|
12
|
-
export declare function buildBatchBranch<T extends BuiltLeafMap
|
|
12
|
+
export declare function buildBatchBranch<T extends BuiltLeafMap>(leaves: T, options: BranchBuildOptions, deps: BuildBatchBranchDeps): BuiltBranch<T>;
|
|
13
13
|
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { type AnyLeafLowProfile } from '@emeryld/rrroutes-contract';
|
|
2
2
|
import type { RouteClient, RouteClientOptions, RouterBuilder } from './routesV3.client.types';
|
|
3
|
-
export declare function createRouteClient<Names extends string = string
|
|
4
|
-
export declare function buildRouter<Routes extends Record<PropertyKey, AnyLeafLowProfile>, Names extends string = string
|
|
3
|
+
export declare function createRouteClient<Names extends string = string>(opts: RouteClientOptions<Names>): RouteClient<Names>;
|
|
4
|
+
export declare function buildRouter<Routes extends Record<PropertyKey, AnyLeafLowProfile>, Names extends string = string>(routeClient: RouteClient<Names>, routes: Routes): RouterBuilder<Routes, Names>;
|
|
@@ -11,5 +11,5 @@ type GetEnv = {
|
|
|
11
11
|
isVerboseDebug: boolean;
|
|
12
12
|
leafLabel: string;
|
|
13
13
|
};
|
|
14
|
-
export declare function buildGetLeaf<L extends AnyLeafLowProfile
|
|
14
|
+
export declare function buildGetLeaf<L extends AnyLeafLowProfile>(leaf: L, rqOpts: QueryBuildOptionsFor<L> | undefined, env: GetEnv): BuiltQuery<L>;
|
|
15
15
|
export {};
|
|
@@ -11,5 +11,5 @@ type InfiniteEnv = {
|
|
|
11
11
|
isVerboseDebug: boolean;
|
|
12
12
|
leafLabel: string;
|
|
13
13
|
};
|
|
14
|
-
export declare function buildInfiniteGetLeaf<L extends AnyLeafLowProfile
|
|
14
|
+
export declare function buildInfiniteGetLeaf<L extends AnyLeafLowProfile>(leaf: L, rqOpts: InfiniteBuildOptionsFor<L> | undefined, env: InfiniteEnv): BuiltInfinite<L>;
|
|
15
15
|
export {};
|
|
@@ -11,5 +11,5 @@ type MutationEnv = {
|
|
|
11
11
|
isVerboseDebug: boolean;
|
|
12
12
|
leafLabel: string;
|
|
13
13
|
};
|
|
14
|
-
export declare function buildMutationLeaf<L extends AnyLeafLowProfile
|
|
14
|
+
export declare function buildMutationLeaf<L extends AnyLeafLowProfile>(leaf: L, rqOpts: MutationBuildOptionsFor<L> | undefined, env: MutationEnv): BuiltMutation<L>;
|
|
15
15
|
export {};
|
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
import type { AnyLeafLowProfile, HttpMethod, InferBodyInput, InferOutput, InferParams, InferQuery, Prettify } from '@emeryld/rrroutes-contract';
|
|
2
2
|
import type { InfiniteData, QueryClient, QueryKey, UseInfiniteQueryOptions, UseInfiniteQueryResult, UseMutationOptions, UseMutationResult, UseQueryOptions, UseQueryResult } from '@tanstack/react-query';
|
|
3
|
+
declare global {
|
|
4
|
+
namespace RRRoutesClient {
|
|
5
|
+
interface Register {
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
/** Global default error type used across client hooks/builders. */
|
|
10
|
+
export type RRRoutesClientError = RRRoutesClient.Register extends {
|
|
11
|
+
error: infer TError;
|
|
12
|
+
} ? TError : unknown;
|
|
3
13
|
/** Helper type used when setting React Query cache data. */
|
|
4
14
|
export type Updater<T> = T | ((prev: T | undefined) => T | undefined) | undefined;
|
|
5
15
|
/** Cursor string extracted from paginated endpoints. */
|
|
@@ -153,7 +163,7 @@ export type QueryKeysFor<L extends AnyLeafLowProfile, T extends ArgsTuple<L>> =
|
|
|
153
163
|
QueryFromArgs<L, T> extends undefined ? {} : QueryFromArgs<L, T>
|
|
154
164
|
]>;
|
|
155
165
|
/** React Query build options specialized for a plain GET leaf. */
|
|
156
|
-
export type QueryBuildOptionsFor<L extends AnyLeafLowProfile
|
|
166
|
+
export type QueryBuildOptionsFor<L extends AnyLeafLowProfile> = Omit<UseQueryOptions<InferOutput<L>, RRRoutesClientError, InferOutput<L>, QueryKey>, 'queryKey' | 'queryFn'> & {
|
|
157
167
|
/** Hook invoked after a successful fetch + validation. */
|
|
158
168
|
onReceive?: OnReceive<L>;
|
|
159
169
|
};
|
|
@@ -186,36 +196,36 @@ type InfiniteBuildOnlyOptionsFor = {
|
|
|
186
196
|
splitPageSizeParam?: string;
|
|
187
197
|
};
|
|
188
198
|
/** Build options for feed-style GET leaves (`cfg.feed === true`). */
|
|
189
|
-
export type InfiniteBuildOptionsFor<L extends AnyLeafLowProfile
|
|
199
|
+
export type InfiniteBuildOptionsFor<L extends AnyLeafLowProfile> = Omit<UseInfiniteQueryOptions<InferOutput<L>, RRRoutesClientError, InfiniteData<InferOutput<L>>, QueryKey, Cursor>, 'queryKey' | 'queryFn' | 'getNextPageParam' | 'initialPageParam'> & InfiniteFeedCursorOptionsFor<L> & InfiniteBuildOnlyOptionsFor & {
|
|
190
200
|
/** Hook invoked after a successful fetch + validation. */
|
|
191
201
|
onReceive?: OnReceive<L>;
|
|
192
202
|
};
|
|
193
203
|
/** Build options for mutation leaves (non-GET). */
|
|
194
|
-
export type MutationBuildOptionsFor<L extends AnyLeafLowProfile
|
|
204
|
+
export type MutationBuildOptionsFor<L extends AnyLeafLowProfile> = Omit<UseMutationOptions<InferOutput<L>, RRRoutesClientError, InferBodyInput<L>, unknown>, 'mutationFn' | 'mutationKey'> & {
|
|
195
205
|
/** Hook invoked after a successful fetch + validation. */
|
|
196
206
|
onReceive?: OnReceive<L>;
|
|
197
207
|
};
|
|
198
208
|
/** Build options narrowed to the method/feed shape of the leaf. */
|
|
199
|
-
export type BuildOptionsFor<L extends AnyLeafLowProfile
|
|
209
|
+
export type BuildOptionsFor<L extends AnyLeafLowProfile> = L['method'] extends 'get' ? L['cfg']['feed'] extends true ? InfiniteBuildOptionsFor<L> : QueryBuildOptionsFor<L> : MutationBuildOptionsFor<L>;
|
|
200
210
|
/** React Query call options for `useEndpoint` on plain GET leaves. */
|
|
201
|
-
export type QueryUseEndpointOptionsFor<L extends AnyLeafLowProfile
|
|
211
|
+
export type QueryUseEndpointOptionsFor<L extends AnyLeafLowProfile> = Omit<UseQueryOptions<InferOutput<L>, RRRoutesClientError, InferOutput<L>, QueryKey>, 'queryKey' | 'queryFn'> & {
|
|
202
212
|
onReceive?: OnReceive<L>;
|
|
203
213
|
};
|
|
204
214
|
/** React Query call options for `useEndpoint` on feed GET leaves. */
|
|
205
|
-
export type InfiniteUseEndpointOptionsFor<L extends AnyLeafLowProfile
|
|
215
|
+
export type InfiniteUseEndpointOptionsFor<L extends AnyLeafLowProfile> = Omit<UseInfiniteQueryOptions<InferOutput<L>, RRRoutesClientError, InfiniteData<InferOutput<L>>, QueryKey, Cursor>, 'queryKey' | 'queryFn' | 'getNextPageParam' | 'initialPageParam'> & {
|
|
206
216
|
/** Hook invoked after a successful fetch + validation. */
|
|
207
217
|
onReceive?: OnReceive<L>;
|
|
208
218
|
} & InfiniteFeedCursorOptionsFor<L>;
|
|
209
219
|
/** React Query call options for `useEndpoint` on mutation leaves. */
|
|
210
|
-
export type MutationUseEndpointOptionsFor<L extends AnyLeafLowProfile
|
|
220
|
+
export type MutationUseEndpointOptionsFor<L extends AnyLeafLowProfile> = Omit<UseMutationOptions<InferOutput<L>, RRRoutesClientError, InferBodyInput<L>, unknown>, 'mutationFn' | 'mutationKey'> & {
|
|
211
221
|
onReceive?: OnReceive<L>;
|
|
212
222
|
};
|
|
213
223
|
/** Runtime hook options narrowed to the method/feed shape of the leaf. */
|
|
214
|
-
export type UseEndpointOptionsFor<L extends AnyLeafLowProfile
|
|
215
|
-
export type UseEndpointArgs<L extends AnyLeafLowProfile
|
|
216
|
-
export type QueryUseEndpointResultFor<L extends AnyLeafLowProfile
|
|
217
|
-
export type InfiniteUseEndpointResultFor<L extends AnyLeafLowProfile
|
|
218
|
-
export type MutationUseEndpointResultFor<L extends AnyLeafLowProfile
|
|
224
|
+
export type UseEndpointOptionsFor<L extends AnyLeafLowProfile> = L['method'] extends 'get' ? L['cfg']['feed'] extends true ? InfiniteUseEndpointOptionsFor<L> : QueryUseEndpointOptionsFor<L> : MutationUseEndpointOptionsFor<L>;
|
|
225
|
+
export type UseEndpointArgs<L extends AnyLeafLowProfile> = keyof ArgsFor<L> extends never ? [options?: UseEndpointOptionsFor<L>] : [args: ArgsFor<L>, options?: UseEndpointOptionsFor<L>];
|
|
226
|
+
export type QueryUseEndpointResultFor<L extends AnyLeafLowProfile> = UseEndpointResult<L, UseQueryResult<InferOutput<L>, RRRoutesClientError>>;
|
|
227
|
+
export type InfiniteUseEndpointResultFor<L extends AnyLeafLowProfile> = UseEndpointResult<L, UseInfiniteQueryResult<InfiniteData<InferOutput<L>>, RRRoutesClientError>>;
|
|
228
|
+
export type MutationUseEndpointResultFor<L extends AnyLeafLowProfile> = UseEndpointResult<L, UseMutationResult<InferOutput<L>, RRRoutesClientError, InferBodyInput<L>, unknown>>;
|
|
219
229
|
/** Shared capabilities exposed by every built endpoint helper. */
|
|
220
230
|
export type BuiltCommon<L extends AnyLeafLowProfile> = {
|
|
221
231
|
/**
|
|
@@ -235,14 +245,16 @@ export type BuiltCommon<L extends AnyLeafLowProfile> = {
|
|
|
235
245
|
* @param rest Optional params/query tuple for the leaf.
|
|
236
246
|
*/
|
|
237
247
|
setData: (...args: SetDataArgs<L>) => DataShape<L> | undefined;
|
|
248
|
+
/** Type-only metadata preserved on built leaves for inference/introspection. */
|
|
249
|
+
__rrroutesLeaf: L;
|
|
238
250
|
};
|
|
239
251
|
/** Hook+helpers for a standard GET endpoint. */
|
|
240
|
-
export type BuiltQuery<L extends AnyLeafLowProfile
|
|
252
|
+
export type BuiltQuery<L extends AnyLeafLowProfile> = BuiltCommon<L> & {
|
|
241
253
|
/**
|
|
242
254
|
* React hook bound to the GET leaf.
|
|
243
255
|
* @param args Optional params/query args, followed by optional React Query options.
|
|
244
256
|
*/
|
|
245
|
-
useEndpoint: (...args: UseEndpointArgs<L
|
|
257
|
+
useEndpoint: (...args: UseEndpointArgs<L>) => QueryUseEndpointResultFor<L>;
|
|
246
258
|
/**
|
|
247
259
|
* Direct fetch helper mirroring the query hook without touching the cache.
|
|
248
260
|
* @param args Optional params/query tuple for the leaf.
|
|
@@ -250,12 +262,12 @@ export type BuiltQuery<L extends AnyLeafLowProfile, TError = unknown> = BuiltCom
|
|
|
250
262
|
fetch: (...args: QueryFetchArgs<L>) => Promise<InferOutput<L>>;
|
|
251
263
|
};
|
|
252
264
|
/** Hook+helpers for a cursor-paginated GET endpoint. */
|
|
253
|
-
export type BuiltInfinite<L extends AnyLeafLowProfile
|
|
265
|
+
export type BuiltInfinite<L extends AnyLeafLowProfile> = BuiltCommon<L> & {
|
|
254
266
|
/**
|
|
255
267
|
* React hook bound to an infinite GET leaf.
|
|
256
268
|
* @param args Optional params/query args, followed by optional React Query options.
|
|
257
269
|
*/
|
|
258
|
-
useEndpoint: (...args: UseEndpointArgs<L
|
|
270
|
+
useEndpoint: (...args: UseEndpointArgs<L>) => InfiniteUseEndpointResultFor<L>;
|
|
259
271
|
/**
|
|
260
272
|
* Direct fetch helper for a single page of the feed (pass cursor in query args).
|
|
261
273
|
* @param args Optional params/query tuple for the leaf.
|
|
@@ -263,12 +275,12 @@ export type BuiltInfinite<L extends AnyLeafLowProfile, TError = unknown> = Built
|
|
|
263
275
|
fetch: (...args: QueryFetchArgs<L>) => Promise<InferOutput<L>>;
|
|
264
276
|
};
|
|
265
277
|
/** Hook+helpers for non-GET endpoints (mutations). */
|
|
266
|
-
export type BuiltMutation<L extends AnyLeafLowProfile
|
|
278
|
+
export type BuiltMutation<L extends AnyLeafLowProfile> = BuiltCommon<L> & {
|
|
267
279
|
/**
|
|
268
280
|
* React hook bound to a mutation leaf.
|
|
269
281
|
* @param args Optional params/query args, followed by optional React Query options.
|
|
270
282
|
*/
|
|
271
|
-
useEndpoint: (...args: UseEndpointArgs<L
|
|
283
|
+
useEndpoint: (...args: UseEndpointArgs<L>) => MutationUseEndpointResultFor<L>;
|
|
272
284
|
/**
|
|
273
285
|
* Direct fetch helper that bypasses React Query, useful for server actions or scripts.
|
|
274
286
|
* Pass params/query first (if required), followed by the body payload.
|
|
@@ -276,64 +288,59 @@ export type BuiltMutation<L extends AnyLeafLowProfile, TError = unknown> = Built
|
|
|
276
288
|
fetch: MutationFetcher<L>;
|
|
277
289
|
};
|
|
278
290
|
/** Type-safe union that resolves to the correct built helper for a leaf. */
|
|
279
|
-
type
|
|
280
|
-
metadata: {
|
|
281
|
-
leaf: L;
|
|
282
|
-
};
|
|
283
|
-
};
|
|
284
|
-
/** Type-safe union that resolves to the correct built helper for a leaf. */
|
|
285
|
-
export type BuiltForLeaf<L extends AnyLeafLowProfile, TError = unknown> = (L['method'] extends 'get' ? L['cfg']['feed'] extends true ? BuiltInfinite<L, TError> : BuiltQuery<L, TError> : BuiltMutation<L, TError>) & BuiltLeafMetadata<L>;
|
|
291
|
+
export type BuiltForLeaf<L extends AnyLeafLowProfile> = L['method'] extends 'get' ? L['cfg']['feed'] extends true ? BuiltInfinite<L> : BuiltQuery<L> : BuiltMutation<L>;
|
|
286
292
|
type LeafFromBuilt<B> = B extends BuiltForLeaf<infer L> ? L : AnyLeafLowProfile;
|
|
287
293
|
type SetDataUpdaterFromBuilt<B> = B extends {
|
|
288
294
|
setData: (updater: infer U, ...args: any[]) => any;
|
|
289
295
|
} ? U : never;
|
|
290
|
-
export type BuiltLeafLike
|
|
296
|
+
export type BuiltLeafLike = {
|
|
291
297
|
getQueryKeys: (...args: any[]) => any;
|
|
292
298
|
invalidate: (...args: any[]) => Promise<void>;
|
|
293
299
|
setData: (...args: any[]) => any;
|
|
294
300
|
useEndpoint: (...args: any[]) => any;
|
|
295
301
|
fetch: (...args: any[]) => Promise<any>;
|
|
302
|
+
__rrroutesLeaf: AnyLeafLowProfile;
|
|
296
303
|
};
|
|
297
|
-
export type BuiltLeafMap
|
|
304
|
+
export type BuiltLeafMap = Record<string, BuiltLeafLike>;
|
|
298
305
|
/** Per-leaf request shape sent to the batch endpoint. */
|
|
299
306
|
export type BranchFetchInputForLeaf<L extends AnyLeafLowProfile> = Prettify<(keyof ArgsFor<L> extends never ? {} : ArgsFor<L>) & (InferBodyInput<L> extends never ? {} : {
|
|
300
307
|
body?: InferBodyInput<L>;
|
|
301
308
|
})>;
|
|
302
309
|
/** Input payload keyed by alias for branch.fetch/useEndpoint calls. */
|
|
303
|
-
export type BranchFetchInput<T extends BuiltLeafMap
|
|
310
|
+
export type BranchFetchInput<T extends BuiltLeafMap> = {
|
|
304
311
|
[K in keyof T]: BranchFetchInputForLeaf<LeafFromBuilt<T[K]>>;
|
|
305
312
|
};
|
|
306
313
|
/** Optional args map for cache-key/invalidation helpers across a branch. */
|
|
307
|
-
export type BranchArgsInput<T extends BuiltLeafMap
|
|
314
|
+
export type BranchArgsInput<T extends BuiltLeafMap> = Partial<{
|
|
308
315
|
[K in keyof T]: ArgsFor<LeafFromBuilt<T[K]>>;
|
|
309
316
|
}>;
|
|
310
317
|
/** Branch fetch output keyed by alias. */
|
|
311
|
-
export type BranchFetchOutput<T extends BuiltLeafMap
|
|
318
|
+
export type BranchFetchOutput<T extends BuiltLeafMap> = {
|
|
312
319
|
[K in keyof T]: Awaited<ReturnType<T[K]['fetch']>>;
|
|
313
320
|
};
|
|
314
321
|
/** Per-leaf query keys keyed by alias. */
|
|
315
|
-
export type BranchQueryKeysOutput<T extends BuiltLeafMap
|
|
322
|
+
export type BranchQueryKeysOutput<T extends BuiltLeafMap> = {
|
|
316
323
|
[K in keyof T]: ReturnType<T[K]['getQueryKeys']>;
|
|
317
324
|
};
|
|
318
325
|
/** Input payload for branch.setData keyed by alias. */
|
|
319
|
-
export type BranchSetDataInput<T extends BuiltLeafMap
|
|
326
|
+
export type BranchSetDataInput<T extends BuiltLeafMap> = Partial<{
|
|
320
327
|
[K in keyof T]: {
|
|
321
328
|
updater: SetDataUpdaterFromBuilt<T[K]>;
|
|
322
329
|
args?: ArgsFor<LeafFromBuilt<T[K]>>;
|
|
323
330
|
};
|
|
324
331
|
}>;
|
|
325
332
|
/** Output of branch.setData keyed by alias. */
|
|
326
|
-
export type BranchSetDataOutput<T extends BuiltLeafMap
|
|
333
|
+
export type BranchSetDataOutput<T extends BuiltLeafMap> = Partial<{
|
|
327
334
|
[K in keyof T]: ReturnType<T[K]['setData']>;
|
|
328
335
|
}>;
|
|
329
|
-
type BranchOnReceive<T extends BuiltLeafMap
|
|
330
|
-
type BranchOnReceiveRegistrar<T extends BuiltLeafMap
|
|
336
|
+
type BranchOnReceive<T extends BuiltLeafMap> = (data: BranchFetchOutput<T>) => void;
|
|
337
|
+
type BranchOnReceiveRegistrar<T extends BuiltLeafMap> = (listener: BranchOnReceive<T>) => () => void;
|
|
331
338
|
/** React Query options for branch.useEndpoint. */
|
|
332
|
-
export type BranchUseEndpointOptions<T extends BuiltLeafMap
|
|
339
|
+
export type BranchUseEndpointOptions<T extends BuiltLeafMap> = Omit<UseQueryOptions<BranchFetchOutput<T>, RRRoutesClientError, BranchFetchOutput<T>, QueryKey>, 'queryKey' | 'queryFn'> & {
|
|
333
340
|
onReceive?: BranchOnReceive<T>;
|
|
334
341
|
};
|
|
335
342
|
/** Result returned by branch.useEndpoint. */
|
|
336
|
-
export type BranchUseEndpointResult<T extends BuiltLeafMap
|
|
343
|
+
export type BranchUseEndpointResult<T extends BuiltLeafMap> = UseQueryResult<BranchFetchOutput<T>, RRRoutesClientError> & {
|
|
337
344
|
onReceive: BranchOnReceiveRegistrar<T>;
|
|
338
345
|
};
|
|
339
346
|
/** Configuration for branch helpers that call a server batch endpoint. */
|
|
@@ -346,15 +353,15 @@ export type BranchBuildOptions = {
|
|
|
346
353
|
headers?: Record<string, string>;
|
|
347
354
|
};
|
|
348
355
|
/** Batched helper surface built from a record of built endpoints. */
|
|
349
|
-
export type BuiltBranch<T extends BuiltLeafMap
|
|
356
|
+
export type BuiltBranch<T extends BuiltLeafMap> = {
|
|
350
357
|
fetch: (input: BranchFetchInput<T>) => Promise<BranchFetchOutput<T>>;
|
|
351
|
-
useEndpoint: (input: BranchFetchInput<T>, options?: BranchUseEndpointOptions<T
|
|
358
|
+
useEndpoint: (input: BranchFetchInput<T>, options?: BranchUseEndpointOptions<T>) => BranchUseEndpointResult<T>;
|
|
352
359
|
getQueryKeys: (input?: BranchArgsInput<T>) => BranchQueryKeysOutput<T>;
|
|
353
360
|
invalidate: (input?: BranchArgsInput<T>) => Promise<void>;
|
|
354
361
|
setData: (input: BranchSetDataInput<T>) => BranchSetDataOutput<T>;
|
|
355
362
|
};
|
|
356
363
|
/** Public surface returned by `createRouteClient`. */
|
|
357
|
-
export type RouteClient<Names extends string = string
|
|
364
|
+
export type RouteClient<Names extends string = string> = {
|
|
358
365
|
/**
|
|
359
366
|
* Invalidate by a key prefix (e.g., ['get','api','users']).
|
|
360
367
|
* @param prefix Key parts shared by matching endpoints.
|
|
@@ -362,11 +369,11 @@ export type RouteClient<Names extends string = string, TError = unknown> = {
|
|
|
362
369
|
*/
|
|
363
370
|
invalidate: (prefix: string[], exact?: boolean) => Promise<void>;
|
|
364
371
|
/** Build a typed endpoint from a leaf. */
|
|
365
|
-
build: <L extends AnyLeafLowProfile>(leaf: L, opts?: BuildOptionsFor<L
|
|
372
|
+
build: <L extends AnyLeafLowProfile>(leaf: L, opts?: BuildOptionsFor<L>,
|
|
366
373
|
/** Optional metadata (third arg) to assign a debug name for filtering via `debug.only`. */
|
|
367
|
-
meta?: BuildMeta<Names>) => BuiltForLeaf<L
|
|
374
|
+
meta?: BuildMeta<Names>) => BuiltForLeaf<L>;
|
|
368
375
|
/** Build a batched helper from already-built endpoint helpers. */
|
|
369
|
-
buildBranch: <T extends BuiltLeafMap
|
|
376
|
+
buildBranch: <T extends BuiltLeafMap>(leaves: T, options: BranchBuildOptions) => BuiltBranch<T>;
|
|
370
377
|
/** Underlying React Query client (exposed for advanced scenarios). */
|
|
371
378
|
queryClient: QueryClient;
|
|
372
379
|
/**
|
|
@@ -379,7 +386,7 @@ export type RouteClient<Names extends string = string, TError = unknown> = {
|
|
|
379
386
|
* Helper signature returned by `buildRouter`, enabling lookups by name instead of leaves.
|
|
380
387
|
* Accepts the same build options/meta the underlying client does, narrowed per leaf shape.
|
|
381
388
|
*/
|
|
382
|
-
export type RouterBuilder<Routes extends Record<PropertyKey, AnyLeafLowProfile>, Names extends string = string
|
|
389
|
+
export type RouterBuilder<Routes extends Record<PropertyKey, AnyLeafLowProfile>, Names extends string = string> = <K extends keyof Routes>(key: K, opts?: BuildOptionsFor<Routes[K]>, meta?: BuildMeta<Names>) => BuiltForLeaf<Routes[K]>;
|
|
383
390
|
/**
|
|
384
391
|
* Arguments for the low-level RouteClient.fetch helper.
|
|
385
392
|
* This is intentionally NOT tied to AnyLeafLowProfile.
|