@openapi-qraft/react 1.0.3 → 1.0.6
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/CHANGELOG.md +20 -0
- package/README.md +11 -0
- package/dist/ServiceOperation.d.ts +48 -40
- package/dist/ServiceOperation.d.ts.map +1 -1
- package/dist/callbacks/getInfiniteQueryData.js +3 -3
- package/dist/callbacks/getInfiniteQueryData.js.map +1 -1
- package/dist/callbacks/getInfiniteQueryKey.d.ts +1 -0
- package/dist/callbacks/getInfiniteQueryKey.d.ts.map +1 -1
- package/dist/callbacks/getInfiniteQueryKey.js +1 -1
- package/dist/callbacks/getInfiniteQueryKey.js.map +1 -1
- package/dist/callbacks/getMutationKey.d.ts +1 -1
- package/dist/callbacks/getMutationKey.d.ts.map +1 -1
- package/dist/callbacks/getQueryData.js +3 -3
- package/dist/callbacks/getQueryData.js.map +1 -1
- package/dist/callbacks/getQueryKey.d.ts +1 -0
- package/dist/callbacks/getQueryKey.d.ts.map +1 -1
- package/dist/callbacks/getQueryKey.js +4 -1
- package/dist/callbacks/getQueryKey.js.map +1 -1
- package/dist/callbacks/queryFn.d.ts +5 -13
- package/dist/callbacks/queryFn.d.ts.map +1 -1
- package/dist/callbacks/queryFn.js +3 -4
- package/dist/callbacks/queryFn.js.map +1 -1
- package/dist/callbacks/setInfiniteQueryData.js +2 -2
- package/dist/callbacks/setInfiniteQueryData.js.map +1 -1
- package/dist/callbacks/setQueryData.js +3 -3
- package/dist/callbacks/setQueryData.js.map +1 -1
- package/dist/callbacks/useInfiniteQuery.d.ts.map +1 -1
- package/dist/callbacks/useInfiniteQuery.js +5 -2
- package/dist/callbacks/useInfiniteQuery.js.map +1 -1
- package/dist/callbacks/useQueries.js +1 -1
- package/dist/callbacks/useQueries.js.map +1 -1
- package/dist/callbacks/useQuery.js +3 -3
- package/dist/callbacks/useQuery.js.map +1 -1
- package/dist/callbacks/useSuspenseInfiniteQuery.d.ts.map +1 -1
- package/dist/callbacks/useSuspenseInfiniteQuery.js +5 -2
- package/dist/callbacks/useSuspenseInfiniteQuery.js.map +1 -1
- package/dist/callbacks/useSuspenseQuery.js +3 -3
- package/dist/callbacks/useSuspenseQuery.js.map +1 -1
- package/dist/qraftAPIClient.d.ts +18 -7
- package/dist/qraftAPIClient.d.ts.map +1 -1
- package/dist/qraftAPIClient.js.map +1 -1
- package/package.json +7 -7
- package/src/ServiceOperation.ts +96 -49
- package/src/callbacks/getInfiniteQueryData.ts +3 -3
- package/src/callbacks/getInfiniteQueryKey.ts +1 -1
- package/src/callbacks/getQueryData.ts +3 -3
- package/src/callbacks/getQueryKey.ts +4 -4
- package/src/callbacks/queryFn.ts +12 -12
- package/src/callbacks/setInfiniteQueryData.ts +2 -2
- package/src/callbacks/setQueryData.ts +3 -3
- package/src/callbacks/useInfiniteQuery.ts +5 -2
- package/src/callbacks/useQueries.ts +1 -1
- package/src/callbacks/useQuery.ts +3 -3
- package/src/callbacks/useSuspenseInfiniteQuery.ts +5 -2
- package/src/callbacks/useSuspenseQuery.ts +3 -3
- package/src/qraftAPIClient.ts +27 -15
- package/src/lib/composeMutationKey.test.ts +0 -43
- package/src/lib/shelfMerge.test.ts +0 -94
- package/src/mocks/handlers.ts +0 -252
- package/src/mocks/node.ts +0 -5
- package/src/qraftAPIClient.test.tsx +0 -996
- package/src/setupTests.ts +0 -17
package/dist/qraftAPIClient.d.ts
CHANGED
|
@@ -4,12 +4,23 @@ import type { RequestClientSchema } from './RequestClient.js';
|
|
|
4
4
|
export type QraftClientOptions = {
|
|
5
5
|
context?: Context<QraftContextValue>;
|
|
6
6
|
};
|
|
7
|
-
export declare const qraftAPIClient: <Services extends
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
export declare const qraftAPIClient: <Services extends ServicesOutput<Services>, Callbacks extends ServicesCallbacks>(services: ServicesDeclaration<Services>, callbacks: Callbacks, options?: QraftClientOptions) => ServicesCallbacksFilter<Services, keyof Callbacks>;
|
|
8
|
+
type ServicesOutput<Services> = {
|
|
9
|
+
[service in keyof Services]: {
|
|
10
|
+
[method in keyof Services[service]]: {
|
|
11
|
+
schema: RequestClientSchema;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
type ServicesDeclaration<Services extends ServicesOutput<Services>> = {
|
|
16
|
+
[service in keyof Services]: {
|
|
17
|
+
[method in keyof Services[service]]: {
|
|
18
|
+
schema: Services[service][method]['schema'];
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
type ServicesCallbacks = Record<string, (...rest: any[]) => any>;
|
|
23
|
+
type ServicesCallbacksFilter<Services extends ServicesOutput<Services>, Callbacks> = Services extends {
|
|
13
24
|
[serviceName in keyof Services]: {
|
|
14
25
|
[method in keyof Services[serviceName]]: {
|
|
15
26
|
schema: RequestClientSchema;
|
|
@@ -17,7 +28,7 @@ type ServicesCallbacksFilter<Services, Callbacks> = Services extends {
|
|
|
17
28
|
};
|
|
18
29
|
} ? {
|
|
19
30
|
[serviceName in keyof Services]: {
|
|
20
|
-
[method in keyof Services[serviceName]]: Pick<Services[serviceName][method], FilterKeys<keyof Services[serviceName][method], Callbacks | 'schema'>>;
|
|
31
|
+
[method in keyof Services[serviceName]]: Pick<Services[serviceName][method], FilterKeys<keyof Services[serviceName][method], Callbacks | 'schema' | 'types'>>;
|
|
21
32
|
};
|
|
22
33
|
} : never;
|
|
23
34
|
type FilterKeys<T, K> = K extends T ? K : never;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"qraftAPIClient.d.ts","sourceRoot":"","sources":["../src/qraftAPIClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAGhC,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAE9D,MAAM,MAAM,kBAAkB,GAAG;IAC/B,OAAO,CAAC,EAAE,OAAO,CAAC,iBAAiB,CAAC,CAAC;CACtC,CAAC;AAEF,eAAO,MAAM,cAAc;
|
|
1
|
+
{"version":3,"file":"qraftAPIClient.d.ts","sourceRoot":"","sources":["../src/qraftAPIClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAGhC,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAE9D,MAAM,MAAM,kBAAkB,GAAG;IAC/B,OAAO,CAAC,EAAE,OAAO,CAAC,iBAAiB,CAAC,CAAC;CACtC,CAAC;AAEF,eAAO,MAAM,cAAc,4JAMf,kBAAkB,uDAoB7B,CAAC;AAeF,KAAK,cAAc,CAAC,QAAQ,IAAI;KAC7B,OAAO,IAAI,MAAM,QAAQ,GAAG;SAC1B,MAAM,IAAI,MAAM,QAAQ,CAAC,OAAO,CAAC,GAAG;YAAE,MAAM,EAAE,mBAAmB,CAAA;SAAE;KACrE;CACF,CAAC;AAEF,KAAK,mBAAmB,CAAC,QAAQ,SAAS,cAAc,CAAC,QAAQ,CAAC,IAAI;KACnE,OAAO,IAAI,MAAM,QAAQ,GAAG;SAC1B,MAAM,IAAI,MAAM,QAAQ,CAAC,OAAO,CAAC,GAAG;YACnC,MAAM,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,CAAC;SAC7C;KACF;CACF,CAAC;AAEF,KAAK,iBAAiB,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,CAAC,CAAC;AAEjE,KAAK,uBAAuB,CAC1B,QAAQ,SAAS,cAAc,CAAC,QAAQ,CAAC,EACzC,SAAS,IACP,QAAQ,SAAS;KAClB,WAAW,IAAI,MAAM,QAAQ,GAAG;SAC9B,MAAM,IAAI,MAAM,QAAQ,CAAC,WAAW,CAAC,GAAG;YAAE,MAAM,EAAE,mBAAmB,CAAA;SAAE;KACzE;CACF,GACG;KACG,WAAW,IAAI,MAAM,QAAQ,GAAG;SAC9B,MAAM,IAAI,MAAM,QAAQ,CAAC,WAAW,CAAC,GAAG,IAAI,CAC3C,QAAQ,CAAC,WAAW,CAAC,CAAC,MAAM,CAAC,EAC7B,UAAU,CACR,MAAM,QAAQ,CAAC,WAAW,CAAC,CAAC,MAAM,CAAC,EACnC,SAAS,GAAG,QAAQ,GAAG,OAAO,CAC/B,CACF;KACF;CACF,GACD,KAAK,CAAC;AAEV,KAAK,UAAU,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"qraftAPIClient.js","sourceRoot":"","sources":["../src/qraftAPIClient.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,6BAA6B,EAAE,MAAM,wCAAwC,CAAC;AAQvF,MAAM,CAAC,MAAM,cAAc,GAAG,
|
|
1
|
+
{"version":3,"file":"qraftAPIClient.js","sourceRoot":"","sources":["../src/qraftAPIClient.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,6BAA6B,EAAE,MAAM,wCAAwC,CAAC;AAQvF,MAAM,CAAC,MAAM,cAAc,GAAG,CAI5B,QAAuC,EACvC,SAAoB,EACpB,OAA4B,EACwB,EAAE;IACtD,OAAO,6BAA6B,CAClC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,EACtB,CAAC,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,EAAE;QAC3B,MAAM,gBAAgB,GAAG,SAAS,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;QACnD,IAAI,CAAC,kBAAkB,CAAC,gBAAgB,CAAC;YACvC,MAAM,IAAI,KAAK,CAAC,gCAAgC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QAEpE,IAAI,YAAY,IAAI,SAAS,EAAE,CAAC;YAC9B,OAAO,SAAS,CAAC,YAA+B,CAAC,CAC/C,OAAO,EACP,gBAAgB,CAAC,MAAM,EACvB,IAAI,CACL,CAAC;QACJ,CAAC;QAED,MAAM,IAAI,KAAK,CAAC,6BAA6B,MAAM,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC;IACvE,CAAC,CACO,CAAC;AACb,CAAC,CAAC;AAEF,SAAS,kBAAkB,CACzB,KAAc;IAEd,OAAO,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,QAAQ,IAAI,KAAK,CAAC;AAC1E,CAAC;AAED,SAAS,SAAS,CAAC,GAA4B,EAAE,IAAc;IAC7D,OAAO,IAAI,CAAC,MAAM,CAAU,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;QACvC,IAAI,GAAG,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,IAAI,GAAG;YAC9C,OAAO,GAAG,CAAC,GAAuB,CAAC,CAAC;IACxC,CAAC,EAAE,GAAG,CAAC,CAAC;AACV,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openapi-qraft/react",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6",
|
|
4
4
|
"description": "API client for React, providing type-safe requests and dynamic Tanstack Query React Hooks via a modular, Proxy-based architecture.",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "rimraf dist/ && tsc --project tsconfig.build.json",
|
|
7
|
-
"dev": "rimraf dist/ && tsc --project tsconfig.
|
|
7
|
+
"dev": "rimraf dist/ && tsc --project tsconfig.build.json --watch",
|
|
8
8
|
"test": "vitest run",
|
|
9
9
|
"typecheck": "tsc --noEmit",
|
|
10
|
-
"generate-qraft": "openapi-qraft
|
|
11
|
-
"generate-types": "openapi-qraft-typescript
|
|
10
|
+
"generate-qraft": "openapi-qraft src/tests/fixtures/openapi.json --clean -o src/tests/fixtures/api --openapi-types-import-path '../../openapi.js' --explicit-import-extensions",
|
|
11
|
+
"generate-types": "openapi-qraft-typescript src/tests/fixtures/openapi.json -o src/tests/fixtures/openapi.ts"
|
|
12
12
|
},
|
|
13
13
|
"type": "module",
|
|
14
14
|
"sideEffects": false,
|
|
15
15
|
"devDependencies": {
|
|
16
|
-
"@openapi-qraft/cli": "~1.0.
|
|
16
|
+
"@openapi-qraft/cli": "~1.0.3",
|
|
17
17
|
"@openapi-qraft/openapi-typescript": "^1.0.0",
|
|
18
18
|
"@tanstack/react-query": "^5.17.3",
|
|
19
19
|
"@testing-library/jest-dom": "^5.17.0",
|
|
@@ -37,8 +37,8 @@
|
|
|
37
37
|
"files": [
|
|
38
38
|
"dist",
|
|
39
39
|
"src",
|
|
40
|
-
"!dist/
|
|
41
|
-
"!src/
|
|
40
|
+
"!dist/tests/**",
|
|
41
|
+
"!src/tests/**"
|
|
42
42
|
],
|
|
43
43
|
"exports": {
|
|
44
44
|
"./package.json": "./package.json",
|
package/src/ServiceOperation.ts
CHANGED
|
@@ -29,22 +29,20 @@ import {
|
|
|
29
29
|
UseSuspenseQueryResult,
|
|
30
30
|
} from '@tanstack/react-query';
|
|
31
31
|
|
|
32
|
-
export type ServiceOperationQueryKey<
|
|
33
|
-
|
|
32
|
+
export type ServiceOperationQueryKey<
|
|
33
|
+
S extends { url: string; method: string },
|
|
34
34
|
T,
|
|
35
|
-
];
|
|
35
|
+
> = [S, T];
|
|
36
36
|
|
|
37
|
-
export type ServiceOperationInfiniteQueryKey<
|
|
38
|
-
|
|
37
|
+
export type ServiceOperationInfiniteQueryKey<
|
|
38
|
+
S extends { url: string; method: string },
|
|
39
39
|
T,
|
|
40
|
-
];
|
|
40
|
+
> = [S & { infinite: true }, T];
|
|
41
41
|
|
|
42
42
|
export type ServiceOperationMutationKey<
|
|
43
43
|
S extends Record<'url' | 'method', string>,
|
|
44
44
|
T extends unknown,
|
|
45
|
-
> = NonNullable<T> extends never
|
|
46
|
-
? [Pick<S, 'url' | 'method'>]
|
|
47
|
-
: [Pick<S, 'url' | 'method'>, T];
|
|
45
|
+
> = NonNullable<T> extends never ? [S] : [S, T];
|
|
48
46
|
|
|
49
47
|
export interface ServiceOperationQuery<
|
|
50
48
|
TSchema extends { url: string; method: string },
|
|
@@ -62,6 +60,11 @@ export interface ServiceOperationQuery<
|
|
|
62
60
|
ServiceOperationSetQueryData<TData, TParams>,
|
|
63
61
|
ServiceOperationSetInfiniteQueryData<TData, TParams> {
|
|
64
62
|
schema: TSchema;
|
|
63
|
+
types: {
|
|
64
|
+
parameters: TParams;
|
|
65
|
+
data: TData;
|
|
66
|
+
error: TError;
|
|
67
|
+
};
|
|
65
68
|
}
|
|
66
69
|
|
|
67
70
|
interface ServiceOperationUseQuery<
|
|
@@ -253,6 +256,12 @@ export interface ServiceOperationMutation<
|
|
|
253
256
|
ServiceOperationMutationFn<TSchema, TBody, TData, TParams>,
|
|
254
257
|
ServiceOperationSetQueryData<TData, TParams> {
|
|
255
258
|
schema: TSchema;
|
|
259
|
+
types: {
|
|
260
|
+
parameters: TParams;
|
|
261
|
+
data: TData;
|
|
262
|
+
error: TError;
|
|
263
|
+
body: TBody;
|
|
264
|
+
};
|
|
256
265
|
}
|
|
257
266
|
|
|
258
267
|
interface ServiceOperationUseMutation<
|
|
@@ -275,10 +284,7 @@ interface ServiceOperationUseMutation<
|
|
|
275
284
|
UseMutationOptions<TData, TError, TVariables, TContext>,
|
|
276
285
|
'mutationKey'
|
|
277
286
|
> & {
|
|
278
|
-
mutationKey?: ServiceOperationMutationKey<
|
|
279
|
-
TSchema,
|
|
280
|
-
NonNullable<TParams> extends never ? {} : TParams
|
|
281
|
-
>;
|
|
287
|
+
mutationKey?: ServiceOperationMutationKey<TSchema, TParams>;
|
|
282
288
|
},
|
|
283
289
|
queryClient?: QueryClient
|
|
284
290
|
): UseMutationResult<TData, TError | Error, TVariables, TContext>;
|
|
@@ -293,14 +299,13 @@ interface ServiceOperationUseMutation<
|
|
|
293
299
|
): UseMutationResult<TData, TError | Error, TVariables, TContext>;
|
|
294
300
|
}
|
|
295
301
|
|
|
296
|
-
|
|
297
|
-
TSchema extends { url: string; method: string },
|
|
302
|
+
interface UseMutationStateFiltersBase<
|
|
298
303
|
TBody,
|
|
299
304
|
TData,
|
|
300
305
|
TParams,
|
|
301
306
|
TError = DefaultError,
|
|
302
307
|
TContext = unknown,
|
|
303
|
-
>
|
|
308
|
+
> {
|
|
304
309
|
/**
|
|
305
310
|
* Match mutation key exactly
|
|
306
311
|
*/
|
|
@@ -321,23 +326,34 @@ type MutationFilters<
|
|
|
321
326
|
* Filter by mutation status
|
|
322
327
|
*/
|
|
323
328
|
status?: MutationStatus;
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
interface UseMutationStateFiltersByParameters<
|
|
332
|
+
TBody,
|
|
333
|
+
TData,
|
|
334
|
+
TParams,
|
|
335
|
+
TError = DefaultError,
|
|
336
|
+
TContext = unknown,
|
|
337
|
+
> extends UseMutationStateFiltersBase<TBody, TData, TParams, TError, TContext> {
|
|
338
|
+
/**
|
|
339
|
+
* Include mutations matching these parameters
|
|
340
|
+
*/
|
|
341
|
+
parameters?: PartialParams<TParams>;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
interface UseMutationStateFiltersByMutationKey<
|
|
345
|
+
TSchema extends { url: string; method: string },
|
|
346
|
+
TBody,
|
|
347
|
+
TData,
|
|
348
|
+
TParams,
|
|
349
|
+
TError = DefaultError,
|
|
350
|
+
TContext = unknown,
|
|
351
|
+
> extends UseMutationStateFiltersBase<TBody, TData, TParams, TError, TContext> {
|
|
352
|
+
/**
|
|
353
|
+
* Include mutations matching this mutation key
|
|
354
|
+
*/
|
|
355
|
+
mutationKey?: ServiceOperationMutationKey<TSchema, PartialParams<TParams>>;
|
|
356
|
+
}
|
|
341
357
|
|
|
342
358
|
type MutationVariables<TBody, TParams> = {
|
|
343
359
|
body: TBody;
|
|
@@ -360,14 +376,22 @@ interface ServiceOperationUseMutationState<
|
|
|
360
376
|
>,
|
|
361
377
|
>(
|
|
362
378
|
options?: {
|
|
363
|
-
filters?:
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
379
|
+
filters?:
|
|
380
|
+
| UseMutationStateFiltersByParameters<
|
|
381
|
+
TBody,
|
|
382
|
+
TData,
|
|
383
|
+
TParams,
|
|
384
|
+
TError,
|
|
385
|
+
TContext
|
|
386
|
+
>
|
|
387
|
+
| UseMutationStateFiltersByMutationKey<
|
|
388
|
+
TSchema,
|
|
389
|
+
TBody,
|
|
390
|
+
TData,
|
|
391
|
+
TParams,
|
|
392
|
+
TError,
|
|
393
|
+
TContext
|
|
394
|
+
>;
|
|
371
395
|
select?: (
|
|
372
396
|
mutation: Mutation<
|
|
373
397
|
TData,
|
|
@@ -381,6 +405,31 @@ interface ServiceOperationUseMutationState<
|
|
|
381
405
|
): Array<TResult>;
|
|
382
406
|
}
|
|
383
407
|
|
|
408
|
+
interface QueryFnOptionsBase<
|
|
409
|
+
TMeta extends Record<string, any>,
|
|
410
|
+
TSignal extends AbortSignal = AbortSignal,
|
|
411
|
+
> {
|
|
412
|
+
signal?: TSignal;
|
|
413
|
+
meta?: TMeta;
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
interface QueryFnOptionsByParameters<
|
|
417
|
+
TParams,
|
|
418
|
+
TMeta extends Record<string, any>,
|
|
419
|
+
TSignal extends AbortSignal = AbortSignal,
|
|
420
|
+
> extends QueryFnOptionsBase<TMeta, TSignal> {
|
|
421
|
+
parameters: TParams;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
interface QueryFnOptionsByQueryKey<
|
|
425
|
+
TSchema extends { url: string; method: string },
|
|
426
|
+
TParams,
|
|
427
|
+
TMeta extends Record<string, any>,
|
|
428
|
+
TSignal extends AbortSignal = AbortSignal,
|
|
429
|
+
> extends QueryFnOptionsBase<TMeta, TSignal> {
|
|
430
|
+
queryKey: ServiceOperationQueryKey<TSchema, TParams>;
|
|
431
|
+
}
|
|
432
|
+
|
|
384
433
|
interface ServiceOperationQueryFn<
|
|
385
434
|
TSchema extends { url: string; method: string },
|
|
386
435
|
TData,
|
|
@@ -390,10 +439,9 @@ interface ServiceOperationQueryFn<
|
|
|
390
439
|
TMeta extends Record<string, any>,
|
|
391
440
|
TSignal extends AbortSignal = AbortSignal,
|
|
392
441
|
>(
|
|
393
|
-
options:
|
|
394
|
-
|
|
|
395
|
-
|
|
|
396
|
-
),
|
|
442
|
+
options:
|
|
443
|
+
| QueryFnOptionsByParameters<TParams, TMeta, TSignal>
|
|
444
|
+
| QueryFnOptionsByQueryKey<TSchema, TParams, TMeta, TSignal>,
|
|
397
445
|
client: (
|
|
398
446
|
schema: TSchema,
|
|
399
447
|
options: {
|
|
@@ -408,10 +456,9 @@ interface ServiceOperationQueryFn<
|
|
|
408
456
|
TMeta extends Record<string, any>,
|
|
409
457
|
TSignal extends AbortSignal = AbortSignal,
|
|
410
458
|
>(
|
|
411
|
-
options:
|
|
412
|
-
|
|
|
413
|
-
|
|
|
414
|
-
),
|
|
459
|
+
options:
|
|
460
|
+
| QueryFnOptionsByParameters<TParams, TMeta, TSignal>
|
|
461
|
+
| QueryFnOptionsByQueryKey<TSchema, TParams, TMeta, TSignal>,
|
|
415
462
|
client: (
|
|
416
463
|
schema: TSchema,
|
|
417
464
|
options: {
|
|
@@ -18,9 +18,9 @@ export function getInfiniteQueryData<TData>(
|
|
|
18
18
|
>['getInfiniteQueryData']
|
|
19
19
|
>
|
|
20
20
|
): InfiniteData<TData> | undefined {
|
|
21
|
-
const [
|
|
21
|
+
const [parameters, queryClient] = args;
|
|
22
22
|
return queryClient.getQueryData([
|
|
23
|
-
{ url: schema.url, infinite: true },
|
|
24
|
-
|
|
23
|
+
{ url: schema.url, method: schema.method, infinite: true },
|
|
24
|
+
parameters,
|
|
25
25
|
] satisfies ServiceOperationInfiniteQueryKey<RequestClientSchema, unknown>);
|
|
26
26
|
}
|
|
@@ -17,7 +17,7 @@ export const getInfiniteQueryKey = (
|
|
|
17
17
|
>
|
|
18
18
|
) => {
|
|
19
19
|
return [
|
|
20
|
-
{ url: schema.url, infinite: true },
|
|
20
|
+
{ url: schema.url, method: schema.method, infinite: true },
|
|
21
21
|
args[0],
|
|
22
22
|
] satisfies ServiceOperationInfiniteQueryKey<RequestClientSchema, unknown>;
|
|
23
23
|
};
|
|
@@ -12,9 +12,9 @@ export function getQueryData<TData>(
|
|
|
12
12
|
ServiceOperationQuery<RequestClientSchema, unknown, TData>['getQueryData']
|
|
13
13
|
>
|
|
14
14
|
): TData | undefined {
|
|
15
|
-
const [
|
|
15
|
+
const [parameters, queryClient] = args;
|
|
16
16
|
return queryClient.getQueryData([
|
|
17
|
-
{ url: schema.url },
|
|
18
|
-
|
|
17
|
+
{ url: schema.url, method: schema.method },
|
|
18
|
+
parameters,
|
|
19
19
|
] satisfies ServiceOperationQueryKey<RequestClientSchema, unknown>);
|
|
20
20
|
}
|
|
@@ -12,8 +12,8 @@ export const getQueryKey = (
|
|
|
12
12
|
ServiceOperationQuery<RequestClientSchema, unknown, unknown>['getQueryKey']
|
|
13
13
|
>
|
|
14
14
|
) => {
|
|
15
|
-
return [
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
>;
|
|
15
|
+
return [
|
|
16
|
+
{ url: schema.url, method: schema.method },
|
|
17
|
+
args[0],
|
|
18
|
+
] satisfies ServiceOperationQueryKey<RequestClientSchema, unknown>;
|
|
19
19
|
};
|
package/src/callbacks/queryFn.ts
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import type { QraftClientOptions } from '../qraftAPIClient.js';
|
|
2
|
-
import type { RequestClientSchema } from '../RequestClient.js';
|
|
3
2
|
import { ServiceOperationQuery } from '../ServiceOperation.js';
|
|
4
3
|
|
|
5
|
-
export const queryFn
|
|
4
|
+
export const queryFn: <
|
|
5
|
+
TSchema extends { url: string; method: 'get' | 'head' | 'options' },
|
|
6
|
+
TData,
|
|
7
|
+
TParams,
|
|
8
|
+
>(
|
|
6
9
|
qraftOptions: QraftClientOptions | undefined,
|
|
7
|
-
schema:
|
|
8
|
-
args: Parameters<
|
|
9
|
-
|
|
10
|
-
>
|
|
11
|
-
) => {
|
|
10
|
+
schema: TSchema,
|
|
11
|
+
args: Parameters<ServiceOperationQuery<TSchema, TData, TParams>['queryFn']>
|
|
12
|
+
) => Promise<TData> = (_, schema, args) => {
|
|
12
13
|
const [options, client] = args;
|
|
13
|
-
const parameters =
|
|
14
|
-
'queryKey' in options ? options.queryKey[1] : options.parameters;
|
|
15
14
|
|
|
16
|
-
return client(schema, {
|
|
17
|
-
parameters
|
|
15
|
+
return client('queryKey' in options ? options.queryKey[0] : schema, {
|
|
16
|
+
parameters:
|
|
17
|
+
'queryKey' in options ? options.queryKey[1] : options.parameters,
|
|
18
18
|
meta: options.meta,
|
|
19
19
|
signal: options.signal,
|
|
20
|
-
})
|
|
20
|
+
}) as Promise<never>;
|
|
21
21
|
};
|
|
@@ -18,12 +18,12 @@ export function setInfiniteQueryData<TData>(
|
|
|
18
18
|
>['setInfiniteQueryData']
|
|
19
19
|
>
|
|
20
20
|
): InfiniteData<TData> | undefined {
|
|
21
|
-
const [
|
|
21
|
+
const [parameters, updater, queryClient, options] = args;
|
|
22
22
|
|
|
23
23
|
const queryKey: ServiceOperationInfiniteQueryKey<
|
|
24
24
|
RequestClientSchema,
|
|
25
25
|
unknown
|
|
26
|
-
> = [{ url: schema.url, infinite: true },
|
|
26
|
+
> = [{ url: schema.url, method: schema.method, infinite: true }, parameters];
|
|
27
27
|
|
|
28
28
|
return queryClient.setQueryData(queryKey, updater as never, options);
|
|
29
29
|
}
|
|
@@ -12,11 +12,11 @@ export function setQueryData<TData>(
|
|
|
12
12
|
ServiceOperationQuery<RequestClientSchema, unknown, TData>['setQueryData']
|
|
13
13
|
>
|
|
14
14
|
): TData | undefined {
|
|
15
|
-
const [
|
|
15
|
+
const [parameters, updater, queryClient, options] = args;
|
|
16
16
|
|
|
17
17
|
const queryKey: ServiceOperationQueryKey<RequestClientSchema, unknown> = [
|
|
18
|
-
{ url: schema.url },
|
|
19
|
-
|
|
18
|
+
{ url: schema.url, method: schema.method },
|
|
19
|
+
parameters,
|
|
20
20
|
];
|
|
21
21
|
|
|
22
22
|
return queryClient.setQueryData(queryKey, updater as never, options);
|
|
@@ -29,7 +29,7 @@ export const useInfiniteQuery: <
|
|
|
29
29
|
>['useInfiniteQuery']
|
|
30
30
|
>
|
|
31
31
|
) => UseInfiniteQueryResult<TData, TError> = (qraftOptions, schema, args) => {
|
|
32
|
-
const [
|
|
32
|
+
const [parameters, options, ...restArgs] = args;
|
|
33
33
|
|
|
34
34
|
const requestClient = useContext(qraftOptions?.context ?? QraftContext)
|
|
35
35
|
?.requestClient;
|
|
@@ -39,7 +39,10 @@ export const useInfiniteQuery: <
|
|
|
39
39
|
return useInfiniteQueryBase(
|
|
40
40
|
{
|
|
41
41
|
...options,
|
|
42
|
-
queryKey: [
|
|
42
|
+
queryKey: [
|
|
43
|
+
{ url: schema.url, method: schema.method, infinite: true },
|
|
44
|
+
parameters as never,
|
|
45
|
+
] as const,
|
|
43
46
|
queryFn:
|
|
44
47
|
options?.queryFn ??
|
|
45
48
|
function ({ queryKey: [, queryParams], signal, meta, pageParam }) {
|
|
@@ -35,7 +35,7 @@ export const useQueries: (
|
|
|
35
35
|
queries: options.queries.map(({ parameters, ...queryOptions }) => ({
|
|
36
36
|
...queryOptions,
|
|
37
37
|
queryKey: [
|
|
38
|
-
{ url: schema.url },
|
|
38
|
+
{ url: schema.url, method: schema.method },
|
|
39
39
|
parameters,
|
|
40
40
|
] satisfies ServiceOperationQueryKey<RequestClientSchema, unknown>,
|
|
41
41
|
queryFn:
|
|
@@ -25,7 +25,7 @@ export const useQuery: <
|
|
|
25
25
|
ServiceOperationQuery<RequestClientSchema, unknown, unknown>['useQuery']
|
|
26
26
|
>
|
|
27
27
|
) => UseQueryResult<TData, TError> = (qraftOptions, schema, args) => {
|
|
28
|
-
const [
|
|
28
|
+
const [parameters, options, ...restArgs] = args;
|
|
29
29
|
|
|
30
30
|
const requestClient = useContext(qraftOptions?.context ?? QraftContext)
|
|
31
31
|
?.requestClient;
|
|
@@ -33,8 +33,8 @@ export const useQuery: <
|
|
|
33
33
|
if (!requestClient) throw new Error(`QraftContext.requestClient not found`);
|
|
34
34
|
|
|
35
35
|
const queryKey: ServiceOperationQueryKey<RequestClientSchema, unknown> = [
|
|
36
|
-
{ url: schema.url },
|
|
37
|
-
|
|
36
|
+
{ url: schema.url, method: schema.method },
|
|
37
|
+
parameters,
|
|
38
38
|
];
|
|
39
39
|
|
|
40
40
|
return useQueryBase(
|
|
@@ -36,7 +36,7 @@ export const useSuspenseInfiniteQuery: <
|
|
|
36
36
|
schema,
|
|
37
37
|
args
|
|
38
38
|
) => {
|
|
39
|
-
const [
|
|
39
|
+
const [parameters, options, ...restArgs] = args;
|
|
40
40
|
|
|
41
41
|
const requestClient = useContext(qraftOptions?.context ?? QraftContext)
|
|
42
42
|
?.requestClient;
|
|
@@ -46,7 +46,10 @@ export const useSuspenseInfiniteQuery: <
|
|
|
46
46
|
return useSuspenseInfiniteQueryTanstack(
|
|
47
47
|
{
|
|
48
48
|
...options,
|
|
49
|
-
queryKey: [
|
|
49
|
+
queryKey: [
|
|
50
|
+
{ url: schema.url, method: schema.method, infinite: true },
|
|
51
|
+
parameters as never,
|
|
52
|
+
] as const,
|
|
50
53
|
queryFn:
|
|
51
54
|
options?.queryFn ??
|
|
52
55
|
function ({ queryKey: [, queryParams], signal, meta, pageParam }) {
|
|
@@ -31,7 +31,7 @@ export const useSuspenseQuery: <
|
|
|
31
31
|
>['useSuspenseQuery']
|
|
32
32
|
>
|
|
33
33
|
) => UseQueryResult<TData, TError> = (qraftOptions, schema, args) => {
|
|
34
|
-
const [
|
|
34
|
+
const [parameters, options, ...restArgs] = args;
|
|
35
35
|
|
|
36
36
|
const requestClient = useContext(qraftOptions?.context ?? QraftContext)
|
|
37
37
|
?.requestClient;
|
|
@@ -39,8 +39,8 @@ export const useSuspenseQuery: <
|
|
|
39
39
|
if (!requestClient) throw new Error(`QraftContext.requestClient not found`);
|
|
40
40
|
|
|
41
41
|
const queryKey: ServiceOperationQueryKey<RequestClientSchema, unknown> = [
|
|
42
|
-
{ url: schema.url },
|
|
43
|
-
|
|
42
|
+
{ url: schema.url, method: schema.method },
|
|
43
|
+
parameters,
|
|
44
44
|
];
|
|
45
45
|
|
|
46
46
|
return useSuspenseQueryTanstack(
|
package/src/qraftAPIClient.ts
CHANGED
|
@@ -9,20 +9,10 @@ export type QraftClientOptions = {
|
|
|
9
9
|
};
|
|
10
10
|
|
|
11
11
|
export const qraftAPIClient = <
|
|
12
|
-
Services extends
|
|
13
|
-
|
|
14
|
-
[method in keyof Services[service]]: { schema: RequestClientSchema };
|
|
15
|
-
};
|
|
16
|
-
},
|
|
17
|
-
Callbacks extends Record<string, (...rest: any[]) => any>,
|
|
12
|
+
Services extends ServicesOutput<Services>,
|
|
13
|
+
Callbacks extends ServicesCallbacks,
|
|
18
14
|
>(
|
|
19
|
-
services:
|
|
20
|
-
[service in keyof Services]: {
|
|
21
|
-
[method in keyof Services[service]]: {
|
|
22
|
-
schema: Services[service][method]['schema'];
|
|
23
|
-
};
|
|
24
|
-
};
|
|
25
|
-
},
|
|
15
|
+
services: ServicesDeclaration<Services>,
|
|
26
16
|
callbacks: Callbacks,
|
|
27
17
|
options?: QraftClientOptions
|
|
28
18
|
): ServicesCallbacksFilter<Services, keyof Callbacks> => {
|
|
@@ -59,7 +49,26 @@ function getByPath(obj: Record<string, unknown>, path: string[]) {
|
|
|
59
49
|
}, obj);
|
|
60
50
|
}
|
|
61
51
|
|
|
62
|
-
type
|
|
52
|
+
type ServicesOutput<Services> = {
|
|
53
|
+
[service in keyof Services]: {
|
|
54
|
+
[method in keyof Services[service]]: { schema: RequestClientSchema };
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
type ServicesDeclaration<Services extends ServicesOutput<Services>> = {
|
|
59
|
+
[service in keyof Services]: {
|
|
60
|
+
[method in keyof Services[service]]: {
|
|
61
|
+
schema: Services[service][method]['schema'];
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
type ServicesCallbacks = Record<string, (...rest: any[]) => any>;
|
|
67
|
+
|
|
68
|
+
type ServicesCallbacksFilter<
|
|
69
|
+
Services extends ServicesOutput<Services>,
|
|
70
|
+
Callbacks,
|
|
71
|
+
> = Services extends {
|
|
63
72
|
[serviceName in keyof Services]: {
|
|
64
73
|
[method in keyof Services[serviceName]]: { schema: RequestClientSchema };
|
|
65
74
|
};
|
|
@@ -68,7 +77,10 @@ type ServicesCallbacksFilter<Services, Callbacks> = Services extends {
|
|
|
68
77
|
[serviceName in keyof Services]: {
|
|
69
78
|
[method in keyof Services[serviceName]]: Pick<
|
|
70
79
|
Services[serviceName][method],
|
|
71
|
-
FilterKeys<
|
|
80
|
+
FilterKeys<
|
|
81
|
+
keyof Services[serviceName][method],
|
|
82
|
+
Callbacks | 'schema' | 'types'
|
|
83
|
+
>
|
|
72
84
|
>;
|
|
73
85
|
};
|
|
74
86
|
}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { composeMutationKey } from './composeMutationKey.js';
|
|
2
|
-
|
|
3
|
-
describe('composeMutationKey', () => {
|
|
4
|
-
it('should return mutation key with parameters', () => {
|
|
5
|
-
const schema = {
|
|
6
|
-
url: 'https://example.com',
|
|
7
|
-
method: 'get',
|
|
8
|
-
} as const;
|
|
9
|
-
|
|
10
|
-
const parameters = {
|
|
11
|
-
body: 'body',
|
|
12
|
-
requestBody: 'requestBody',
|
|
13
|
-
other: 'other',
|
|
14
|
-
};
|
|
15
|
-
const result = composeMutationKey(schema, parameters);
|
|
16
|
-
|
|
17
|
-
expect(result).toEqual([
|
|
18
|
-
{
|
|
19
|
-
url: schema.url,
|
|
20
|
-
method: schema.method,
|
|
21
|
-
},
|
|
22
|
-
{
|
|
23
|
-
other: 'other',
|
|
24
|
-
},
|
|
25
|
-
]);
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
it('should return mutation key without parameters', () => {
|
|
29
|
-
const schema = {
|
|
30
|
-
url: 'https://example.com',
|
|
31
|
-
method: 'get',
|
|
32
|
-
} as const;
|
|
33
|
-
|
|
34
|
-
const result = composeMutationKey(schema, undefined);
|
|
35
|
-
|
|
36
|
-
expect(result).toEqual([
|
|
37
|
-
{
|
|
38
|
-
url: schema.url,
|
|
39
|
-
method: schema.method,
|
|
40
|
-
},
|
|
41
|
-
]);
|
|
42
|
-
});
|
|
43
|
-
});
|