@openapi-qraft/react 1.12.1 → 1.13.0-beta.1

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 CHANGED
@@ -1,5 +1,18 @@
1
1
  # @openapi-qraft/react
2
2
 
3
+ ## 1.13.0-beta.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 4e4a571: Add backward compatibility for `undefined` body mutations, allowing `useMutation` to support `mutate()` and `mutateAsync()` without arguments when the body is `undefined`.
8
+
9
+ ## 1.13.0-beta.0
10
+
11
+ ### Minor Changes
12
+
13
+ - 6d35890: Improve `userQuery()` to support calling without `{}` as the first argument if all parameters are optional or no parameters are required.
14
+ - 39a159c: Improve `useMutation` to support calling `mutate()` or `mutateAsync()` without arguments if body or parameters are optional or `undefined`.
15
+
3
16
  ## 1.12.1
4
17
 
5
18
  ## 1.12.1-beta.0
@@ -0,0 +1,4 @@
1
+ export type AreAllOptional<T> = NonNullable<T> extends never ? true : {
2
+ [K in keyof T]-?: undefined extends T[K] ? never : K;
3
+ }[keyof T] extends never ? true : false;
4
+ //# sourceMappingURL=AreAllOptional.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AreAllOptional.d.ts","sourceRoot":"","sources":["../../../src/lib/AreAllOptional.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,cAAc,CAAC,CAAC,IAC1B,WAAW,CAAC,CAAC,CAAC,SAAS,KAAK,GACxB,IAAI,GACJ;KACK,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,GAAG,SAAS,SAAS,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK,GAAG,CAAC;CACrD,CAAC,MAAM,CAAC,CAAC,SAAS,KAAK,GACxB,IAAI,GACJ,KAAK,CAAC"}
@@ -1,17 +1,28 @@
1
1
  import type { DefaultError, QueryClient } from '@tanstack/query-core';
2
2
  import type { UseMutationOptions, UseMutationResult } from '@tanstack/react-query';
3
+ import type { AreAllOptional } from '../lib/AreAllOptional.js';
3
4
  import type { ServiceOperationMutationKey } from './ServiceOperationKey.js';
4
5
  export interface ServiceOperationUseMutation<TSchema extends {
5
6
  url: string;
6
7
  method: string;
7
8
  }, TBody, TData, TParams, TError = DefaultError> {
8
9
  getMutationKey<TMutationKeyParams extends TParams | undefined = undefined>(parameters?: TMutationKeyParams): ServiceOperationMutationKey<TSchema, TMutationKeyParams>;
9
- useMutation<TVariables extends MutationVariables<TBody, TParams>, TContext = unknown>(parameters?: undefined, options?: Omit<UseMutationOptions<TData, TError, TVariables, TContext>, 'mutationKey'> & {
10
- mutationKey?: ServiceOperationMutationKey<TSchema, TParams>;
11
- }, queryClient?: QueryClient): UseMutationResult<TData, TError | Error, TVariables, TContext>;
12
- useMutation<TVariables extends TBody, TContext = unknown>(parameters: TParams, options?: Omit<UseMutationOptions<TData, TError, TVariables, TContext>, 'mutationKey'>, queryClient?: QueryClient): UseMutationResult<TData, TError | Error, TVariables, TContext>;
10
+ useMutation<TVariables extends MutationVariables<TBody, TParams>, TContext = unknown>(parameters?: undefined, options?: ServiceOperationUseMutationOptions<TSchema, TData, TParams, TVariables, TError, TContext>, queryClient?: QueryClient): UseMutationResult<TData, TError | Error, TVariables, TContext>;
11
+ useMutation<TVariables extends TBody, TContext = unknown>(parameters: AreAllOptional<TParams> extends true ? TParams | void : TParams, options?: ServiceOperationUseMutationOptions<TSchema, TData, TParams, TVariables, TError, TContext>, queryClient?: QueryClient): UseMutationResult<TData, TError | Error, AreAllOptional<TVariables> extends true ? TVariables | void : TVariables, TContext>;
13
12
  }
14
- export type MutationVariables<TBody, TParams> = {
13
+ export type MutationVariables<TBody, TParams> = AreAllOptional<TBody> extends true ? AreAllOptional<TParams> extends true ? ({
14
+ body?: TBody;
15
+ } & NonNullableObject<TParams>) | void : {
16
+ body?: TBody;
17
+ } & TParams : {
15
18
  body: TBody;
16
- } & (NonNullable<TParams> extends never ? {} : TParams);
19
+ } & NonNullableObject<TParams>;
20
+ type NonNullableObject<T> = NonNullable<T> extends never ? {} : T;
21
+ type ServiceOperationUseMutationOptions<TSchema extends {
22
+ url: string;
23
+ method: string;
24
+ }, TData, TParams, TVariables, TError, TContext = unknown> = Omit<UseMutationOptions<TData, TError, TVariables, TContext>, 'mutationKey'> & {
25
+ mutationKey?: ServiceOperationMutationKey<TSchema, TParams>;
26
+ };
27
+ export {};
17
28
  //# sourceMappingURL=ServiceOperationUseMutation.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ServiceOperationUseMutation.d.ts","sourceRoot":"","sources":["../../../src/service-operation/ServiceOperationUseMutation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACtE,OAAO,KAAK,EACV,kBAAkB,EAClB,iBAAiB,EAClB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,0BAA0B,CAAC;AAE5E,MAAM,WAAW,2BAA2B,CAC1C,OAAO,SAAS;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,EAC/C,KAAK,EACL,KAAK,EACL,OAAO,EACP,MAAM,GAAG,YAAY;IAErB,cAAc,CAAC,kBAAkB,SAAS,OAAO,GAAG,SAAS,GAAG,SAAS,EACvE,UAAU,CAAC,EAAE,kBAAkB,GAC9B,2BAA2B,CAAC,OAAO,EAAE,kBAAkB,CAAC,CAAC;IAE5D,WAAW,CACT,UAAU,SAAS,iBAAiB,CAAC,KAAK,EAAE,OAAO,CAAC,EACpD,QAAQ,GAAG,OAAO,EAElB,UAAU,CAAC,EAAE,SAAS,EACtB,OAAO,CAAC,EAAE,IAAI,CACZ,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,QAAQ,CAAC,EACvD,aAAa,CACd,GAAG;QACF,WAAW,CAAC,EAAE,2BAA2B,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;KAC7D,EACD,WAAW,CAAC,EAAE,WAAW,GACxB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,EAAE,UAAU,EAAE,QAAQ,CAAC,CAAC;IAElE,WAAW,CAAC,UAAU,SAAS,KAAK,EAAE,QAAQ,GAAG,OAAO,EACtD,UAAU,EAAE,OAAO,EACnB,OAAO,CAAC,EAAE,IAAI,CACZ,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,QAAQ,CAAC,EACvD,aAAa,CACd,EACD,WAAW,CAAC,EAAE,WAAW,GACxB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,EAAE,UAAU,EAAE,QAAQ,CAAC,CAAC;CACnE;AAED,MAAM,MAAM,iBAAiB,CAAC,KAAK,EAAE,OAAO,IAAI;IAC9C,IAAI,EAAE,KAAK,CAAC;CACb,GAAG,CAAC,WAAW,CAAC,OAAO,CAAC,SAAS,KAAK,GAAG,EAAE,GAAG,OAAO,CAAC,CAAC"}
1
+ {"version":3,"file":"ServiceOperationUseMutation.d.ts","sourceRoot":"","sources":["../../../src/service-operation/ServiceOperationUseMutation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACtE,OAAO,KAAK,EACV,kBAAkB,EAClB,iBAAiB,EAClB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,0BAA0B,CAAC;AAE5E,MAAM,WAAW,2BAA2B,CAC1C,OAAO,SAAS;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,EAC/C,KAAK,EACL,KAAK,EACL,OAAO,EACP,MAAM,GAAG,YAAY;IAErB,cAAc,CAAC,kBAAkB,SAAS,OAAO,GAAG,SAAS,GAAG,SAAS,EACvE,UAAU,CAAC,EAAE,kBAAkB,GAC9B,2BAA2B,CAAC,OAAO,EAAE,kBAAkB,CAAC,CAAC;IAE5D,WAAW,CACT,UAAU,SAAS,iBAAiB,CAAC,KAAK,EAAE,OAAO,CAAC,EACpD,QAAQ,GAAG,OAAO,EAElB,UAAU,CAAC,EAAE,SAAS,EACtB,OAAO,CAAC,EAAE,kCAAkC,CAC1C,OAAO,EACP,KAAK,EACL,OAAO,EACP,UAAU,EACV,MAAM,EACN,QAAQ,CACT,EACD,WAAW,CAAC,EAAE,WAAW,GACxB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,EAAE,UAAU,EAAE,QAAQ,CAAC,CAAC;IAElE,WAAW,CAAC,UAAU,SAAS,KAAK,EAAE,QAAQ,GAAG,OAAO,EACtD,UAAU,EAAE,cAAc,CAAC,OAAO,CAAC,SAAS,IAAI,GAAG,OAAO,GAAG,IAAI,GAAG,OAAO,EAC3E,OAAO,CAAC,EAAE,kCAAkC,CAC1C,OAAO,EACP,KAAK,EACL,OAAO,EACP,UAAU,EACV,MAAM,EACN,QAAQ,CACT,EACD,WAAW,CAAC,EAAE,WAAW,GACxB,iBAAiB,CAClB,KAAK,EACL,MAAM,GAAG,KAAK,EACd,cAAc,CAAC,UAAU,CAAC,SAAS,IAAI,GAAG,UAAU,GAAG,IAAI,GAAG,UAAU,EACxE,QAAQ,CACT,CAAC;CACH;AAED,MAAM,MAAM,iBAAiB,CAAC,KAAK,EAAE,OAAO,IAC1C,cAAc,CAAC,KAAK,CAAC,SAAS,IAAI,GAC9B,cAAc,CAAC,OAAO,CAAC,SAAS,IAAI,GAClC,CAAC;IAAE,IAAI,CAAC,EAAE,KAAK,CAAA;CAAE,GAAG,iBAAiB,CAAC,OAAO,CAAC,CAAC,GAAG,IAAI,GACtD;IAAE,IAAI,CAAC,EAAE,KAAK,CAAA;CAAE,GAAG,OAAO,GAC5B;IAAE,IAAI,EAAE,KAAK,CAAA;CAAE,GAAG,iBAAiB,CAAC,OAAO,CAAC,CAAC;AAEnD,KAAK,iBAAiB,CAAC,CAAC,IAAI,WAAW,CAAC,CAAC,CAAC,SAAS,KAAK,GAAG,EAAE,GAAG,CAAC,CAAC;AAElE,KAAK,kCAAkC,CACrC,OAAO,SAAS;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,EAC/C,KAAK,EACL,OAAO,EACP,UAAU,EACV,MAAM,EACN,QAAQ,GAAG,OAAO,IAChB,IAAI,CACN,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,QAAQ,CAAC,EACvD,aAAa,CACd,GAAG;IACF,WAAW,CAAC,EAAE,2BAA2B,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;CAC7D,CAAC"}
@@ -1,12 +1,13 @@
1
1
  import type { DefaultError, QueryClient } from '@tanstack/query-core';
2
2
  import type { DefinedInitialDataOptions, DefinedUseQueryResult, UndefinedInitialDataOptions, UseQueryResult } from '@tanstack/react-query';
3
+ import { AreAllOptional } from '../lib/AreAllOptional.js';
3
4
  import type { ServiceOperationQueryKey } from './ServiceOperationKey.js';
4
5
  export interface ServiceOperationUseQuery<TSchema extends {
5
6
  url: string;
6
7
  method: string;
7
8
  }, TQueryFnData, TParams = {}, TError = DefaultError> {
8
9
  getQueryKey<QueryKeyParams extends TParams | undefined = undefined>(parameters?: QueryKeyParams): ServiceOperationQueryKey<TSchema, QueryKeyParams>;
9
- useQuery<TData = TQueryFnData>(parameters: TParams | ServiceOperationQueryKey<TSchema, TParams>, options?: Omit<UndefinedInitialDataOptions<TQueryFnData, TError, TData, ServiceOperationQueryKey<TSchema, TParams>>, 'queryKey'>, queryClient?: QueryClient): UseQueryResult<TData, TError | Error>;
10
- useQuery<TData = TQueryFnData>(parameters: TParams | ServiceOperationQueryKey<TSchema, TParams>, options: Omit<DefinedInitialDataOptions<TQueryFnData, TError, TData, ServiceOperationQueryKey<TSchema, TParams>>, 'queryKey'>, queryClient?: QueryClient): DefinedUseQueryResult<TData, TError | Error>;
10
+ useQuery<TData = TQueryFnData>(parameters: ServiceOperationQueryKey<TSchema, TParams> | (AreAllOptional<TParams> extends true ? TParams | void : TParams), options?: Omit<UndefinedInitialDataOptions<TQueryFnData, TError, TData, ServiceOperationQueryKey<TSchema, TParams>>, 'queryKey'>, queryClient?: QueryClient): UseQueryResult<TData, TError | Error>;
11
+ useQuery<TData = TQueryFnData>(parameters: ServiceOperationQueryKey<TSchema, TParams> | (AreAllOptional<TParams> extends true ? TParams | void : TParams), options: Omit<DefinedInitialDataOptions<TQueryFnData, TError, TData, ServiceOperationQueryKey<TSchema, TParams>>, 'queryKey'>, queryClient?: QueryClient): DefinedUseQueryResult<TData, TError | Error>;
11
12
  }
12
13
  //# sourceMappingURL=ServiceOperationUseQuery.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ServiceOperationUseQuery.d.ts","sourceRoot":"","sources":["../../../src/service-operation/ServiceOperationUseQuery.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACtE,OAAO,KAAK,EACV,yBAAyB,EACzB,qBAAqB,EACrB,2BAA2B,EAC3B,cAAc,EACf,MAAM,uBAAuB,CAAC;AAE/B,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,0BAA0B,CAAC;AAEzE,MAAM,WAAW,wBAAwB,CACvC,OAAO,SAAS;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,EAC/C,YAAY,EACZ,OAAO,GAAG,EAAE,EACZ,MAAM,GAAG,YAAY;IAErB,WAAW,CAAC,cAAc,SAAS,OAAO,GAAG,SAAS,GAAG,SAAS,EAChE,UAAU,CAAC,EAAE,cAAc,GAC1B,wBAAwB,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC;IAErD,QAAQ,CAAC,KAAK,GAAG,YAAY,EAC3B,UAAU,EAAE,OAAO,GAAG,wBAAwB,CAAC,OAAO,EAAE,OAAO,CAAC,EAChE,OAAO,CAAC,EAAE,IAAI,CACZ,2BAA2B,CACzB,YAAY,EACZ,MAAM,EACN,KAAK,EACL,wBAAwB,CAAC,OAAO,EAAE,OAAO,CAAC,CAC3C,EACD,UAAU,CACX,EACD,WAAW,CAAC,EAAE,WAAW,GACxB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,CAAC,CAAC;IAEzC,QAAQ,CAAC,KAAK,GAAG,YAAY,EAC3B,UAAU,EAAE,OAAO,GAAG,wBAAwB,CAAC,OAAO,EAAE,OAAO,CAAC,EAChE,OAAO,EAAE,IAAI,CACX,yBAAyB,CACvB,YAAY,EACZ,MAAM,EACN,KAAK,EACL,wBAAwB,CAAC,OAAO,EAAE,OAAO,CAAC,CAC3C,EACD,UAAU,CACX,EACD,WAAW,CAAC,EAAE,WAAW,GACxB,qBAAqB,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,CAAC,CAAC;CACjD"}
1
+ {"version":3,"file":"ServiceOperationUseQuery.d.ts","sourceRoot":"","sources":["../../../src/service-operation/ServiceOperationUseQuery.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACtE,OAAO,KAAK,EACV,yBAAyB,EACzB,qBAAqB,EACrB,2BAA2B,EAC3B,cAAc,EACf,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,0BAA0B,CAAC;AAEzE,MAAM,WAAW,wBAAwB,CACvC,OAAO,SAAS;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,EAC/C,YAAY,EACZ,OAAO,GAAG,EAAE,EACZ,MAAM,GAAG,YAAY;IAErB,WAAW,CAAC,cAAc,SAAS,OAAO,GAAG,SAAS,GAAG,SAAS,EAChE,UAAU,CAAC,EAAE,cAAc,GAC1B,wBAAwB,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC;IAErD,QAAQ,CAAC,KAAK,GAAG,YAAY,EAC3B,UAAU,EACN,wBAAwB,CAAC,OAAO,EAAE,OAAO,CAAC,GAC1C,CAAC,cAAc,CAAC,OAAO,CAAC,SAAS,IAAI,GAAG,OAAO,GAAG,IAAI,GAAG,OAAO,CAAC,EACrE,OAAO,CAAC,EAAE,IAAI,CACZ,2BAA2B,CACzB,YAAY,EACZ,MAAM,EACN,KAAK,EACL,wBAAwB,CAAC,OAAO,EAAE,OAAO,CAAC,CAC3C,EACD,UAAU,CACX,EACD,WAAW,CAAC,EAAE,WAAW,GACxB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,CAAC,CAAC;IAEzC,QAAQ,CAAC,KAAK,GAAG,YAAY,EAC3B,UAAU,EACN,wBAAwB,CAAC,OAAO,EAAE,OAAO,CAAC,GAC1C,CAAC,cAAc,CAAC,OAAO,CAAC,SAAS,IAAI,GAAG,OAAO,GAAG,IAAI,GAAG,OAAO,CAAC,EACrE,OAAO,EAAE,IAAI,CACX,yBAAyB,CACvB,YAAY,EACZ,MAAM,EACN,KAAK,EACL,wBAAwB,CAAC,OAAO,EAAE,OAAO,CAAC,CAC3C,EACD,UAAU,CACX,EACD,WAAW,CAAC,EAAE,WAAW,GACxB,qBAAqB,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,CAAC,CAAC;CACjD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openapi-qraft/react",
3
- "version": "1.12.1",
3
+ "version": "1.13.0-beta.1",
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": "NODE_ENV=production rollup --config rollup.config.mjs && tsc --project tsconfig.build.json --emitDeclarationOnly",
@@ -15,9 +15,9 @@
15
15
  },
16
16
  "sideEffects": false,
17
17
  "devDependencies": {
18
- "@openapi-qraft/cli": "1.12.1",
18
+ "@openapi-qraft/cli": "1.13.0-beta.1",
19
19
  "@openapi-qraft/eslint-config": "1.0.0",
20
- "@openapi-qraft/openapi-typescript-plugin": "^1.0.6",
20
+ "@openapi-qraft/openapi-typescript-plugin": "^1.0.7-beta.1",
21
21
  "@openapi-qraft/rollup-config": "1.0.0",
22
22
  "@openapi-qraft/test-fixtures": "1.0.0",
23
23
  "@tanstack/react-query": "^5.17.3",
@@ -0,0 +1,8 @@
1
+ export type AreAllOptional<T> =
2
+ NonNullable<T> extends never
3
+ ? true
4
+ : {
5
+ [K in keyof T]-?: undefined extends T[K] ? never : K;
6
+ }[keyof T] extends never
7
+ ? true
8
+ : false;
@@ -4,6 +4,7 @@ import type {
4
4
  UseMutationResult,
5
5
  } from '@tanstack/react-query';
6
6
 
7
+ import type { AreAllOptional } from '../lib/AreAllOptional.js';
7
8
  import type { ServiceOperationMutationKey } from './ServiceOperationKey.js';
8
9
 
9
10
  export interface ServiceOperationUseMutation<
@@ -22,25 +23,55 @@ export interface ServiceOperationUseMutation<
22
23
  TContext = unknown,
23
24
  >(
24
25
  parameters?: undefined,
25
- options?: Omit<
26
- UseMutationOptions<TData, TError, TVariables, TContext>,
27
- 'mutationKey'
28
- > & {
29
- mutationKey?: ServiceOperationMutationKey<TSchema, TParams>;
30
- },
26
+ options?: ServiceOperationUseMutationOptions<
27
+ TSchema,
28
+ TData,
29
+ TParams,
30
+ TVariables,
31
+ TError,
32
+ TContext
33
+ >,
31
34
  queryClient?: QueryClient
32
35
  ): UseMutationResult<TData, TError | Error, TVariables, TContext>;
33
36
 
34
37
  useMutation<TVariables extends TBody, TContext = unknown>(
35
- parameters: TParams,
36
- options?: Omit<
37
- UseMutationOptions<TData, TError, TVariables, TContext>,
38
- 'mutationKey'
38
+ parameters: AreAllOptional<TParams> extends true ? TParams | void : TParams,
39
+ options?: ServiceOperationUseMutationOptions<
40
+ TSchema,
41
+ TData,
42
+ TParams,
43
+ TVariables,
44
+ TError,
45
+ TContext
39
46
  >,
40
47
  queryClient?: QueryClient
41
- ): UseMutationResult<TData, TError | Error, TVariables, TContext>;
48
+ ): UseMutationResult<
49
+ TData,
50
+ TError | Error,
51
+ AreAllOptional<TVariables> extends true ? TVariables | void : TVariables,
52
+ TContext
53
+ >;
42
54
  }
43
55
 
44
- export type MutationVariables<TBody, TParams> = {
45
- body: TBody;
46
- } & (NonNullable<TParams> extends never ? {} : TParams);
56
+ export type MutationVariables<TBody, TParams> =
57
+ AreAllOptional<TBody> extends true
58
+ ? AreAllOptional<TParams> extends true
59
+ ? ({ body?: TBody } & NonNullableObject<TParams>) | void
60
+ : { body?: TBody } & TParams
61
+ : { body: TBody } & NonNullableObject<TParams>;
62
+
63
+ type NonNullableObject<T> = NonNullable<T> extends never ? {} : T;
64
+
65
+ type ServiceOperationUseMutationOptions<
66
+ TSchema extends { url: string; method: string },
67
+ TData,
68
+ TParams,
69
+ TVariables,
70
+ TError,
71
+ TContext = unknown,
72
+ > = Omit<
73
+ UseMutationOptions<TData, TError, TVariables, TContext>,
74
+ 'mutationKey'
75
+ > & {
76
+ mutationKey?: ServiceOperationMutationKey<TSchema, TParams>;
77
+ };
@@ -6,6 +6,7 @@ import type {
6
6
  UseQueryResult,
7
7
  } from '@tanstack/react-query';
8
8
 
9
+ import { AreAllOptional } from '../lib/AreAllOptional.js';
9
10
  import type { ServiceOperationQueryKey } from './ServiceOperationKey.js';
10
11
 
11
12
  export interface ServiceOperationUseQuery<
@@ -19,7 +20,9 @@ export interface ServiceOperationUseQuery<
19
20
  ): ServiceOperationQueryKey<TSchema, QueryKeyParams>;
20
21
 
21
22
  useQuery<TData = TQueryFnData>(
22
- parameters: TParams | ServiceOperationQueryKey<TSchema, TParams>,
23
+ parameters:
24
+ | ServiceOperationQueryKey<TSchema, TParams>
25
+ | (AreAllOptional<TParams> extends true ? TParams | void : TParams),
23
26
  options?: Omit<
24
27
  UndefinedInitialDataOptions<
25
28
  TQueryFnData,
@@ -33,7 +36,9 @@ export interface ServiceOperationUseQuery<
33
36
  ): UseQueryResult<TData, TError | Error>;
34
37
 
35
38
  useQuery<TData = TQueryFnData>(
36
- parameters: TParams | ServiceOperationQueryKey<TSchema, TParams>,
39
+ parameters:
40
+ | ServiceOperationQueryKey<TSchema, TParams>
41
+ | (AreAllOptional<TParams> extends true ? TParams | void : TParams),
37
42
  options: Omit<
38
43
  DefinedInitialDataOptions<
39
44
  TQueryFnData,