@emeryld/rrroutes-client 2.1.8 → 2.1.9

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.
@@ -124,13 +124,21 @@ export type ArgsTuple<L extends AnyLeaf> = keyof ArgsFor<L> extends never ? [] :
124
124
  /** Cache data shape for setData(...) */
125
125
  export type DataShape<L extends AnyLeaf> = L['method'] extends 'get' ? L['cfg']['feed'] extends true ? InfiniteData<OutputOf<L>> : OutputOf<L> : OutputOf<L>;
126
126
  type ArgsFromTuple<L extends AnyLeaf, T extends ArgsTuple<L>> = T extends [infer A] ? A : undefined;
127
+ type ParamsFromArgs<L extends AnyLeaf, T extends ArgsTuple<L>> = ArgsFromTuple<L, T> extends {
128
+ params: infer P;
129
+ } ? P : undefined;
127
130
  type QueryFromArgs<L extends AnyLeaf, T extends ArgsTuple<L>> = ArgsFromTuple<L, T> extends {
128
131
  query: infer Q;
129
132
  } ? Q : undefined;
130
133
  /** Typed query key array derived from the leaf plus the specific args passed in. */
134
+ type SplitUrl<L extends string> = L extends `/${infer A}` ? SplitUrl<A> : L extends `${infer A}/${infer B}` ? [A, ...SplitUrl<B>] : [L];
135
+ type MapParams<P extends any[], Params> = P extends [infer A, ...infer Rest] ? A extends `:${infer Key}` ? [Params extends Record<Key, infer V> ? string extends V ? A : V : A, ...MapParams<Rest, Params>] : [
136
+ A,
137
+ ...MapParams<Rest, Params>
138
+ ] : [];
131
139
  export type QueryKeysFor<L extends AnyLeaf, T extends ArgsTuple<L>> = Prettify<readonly [
132
140
  L['method'],
133
- ...string[],
141
+ ...MapParams<SplitUrl<L['path']>, ParamsFromArgs<L, T>>,
134
142
  QueryFromArgs<L, T> extends undefined ? {} : QueryFromArgs<L, T>
135
143
  ]>;
136
144
  /** React Query build options specialized for a plain GET leaf. */
@@ -148,7 +156,7 @@ export type BuiltCommon<L extends AnyLeaf> = {
148
156
  * @param args Optional params/query tuple for the leaf.
149
157
  * @returns Query key tuple.
150
158
  */
151
- getQueryKeys: <A extends ArgsTuple<L> = ArgsTuple<L>>(...args: A) => QueryKeysFor<L, A>;
159
+ getQueryKeys: <const A extends ArgsTuple<L> = ArgsTuple<L>>(...args: A) => QueryKeysFor<L, A>;
152
160
  /**
153
161
  * Invalidate exactly this endpoint instance.
154
162
  * @param args Optional params/query tuple for the leaf.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@emeryld/rrroutes-client",
3
- "version": "2.1.8",
3
+ "version": "2.1.9",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",