@openapi-qraft/react 2.5.0 → 2.6.0

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.
@@ -1,9 +1,4 @@
1
- import type {
2
- ServiceOperationMutation,
3
- ServiceOperationMutationFn,
4
- ServiceOperationQuery,
5
- ServiceOperationQueryFn,
6
- } from '@openapi-qraft/tanstack-query-react-types';
1
+ import type { QraftServiceOperationsToken } from '@openapi-qraft/tanstack-query-react-types';
7
2
  import type { QueryClient } from '@tanstack/query-core';
8
3
  import type * as callbacks from './callbacks/index.js';
9
4
  import type * as operationInvokeModule from './callbacks/operationInvokeFn.js';
@@ -42,58 +37,141 @@ export type CreateAPIClientOptions =
42
37
  | CreateAPIBasicQueryClientOptions
43
38
  | CreateAPIQueryClientOptions;
44
39
 
40
+ /**
41
+ * Creates a QueryClient compatible API Client which contains all operations
42
+ * such as `useQuery`, `useMutation`.
43
+ *
44
+ * @example Fetching data with QueryClient
45
+ * ```ts
46
+ * const api = qraftAPIClient(services, callbacks, {
47
+ * requestFn: requestFn,
48
+ * baseUrl: 'https://api.example.com',
49
+ * queryClient: new QueryClient(),
50
+ * });
51
+ *
52
+ * api.service.operation({
53
+ * parameters: { path: { id: 1 } },
54
+ * });
55
+ * ```
56
+ */
45
57
  export function qraftAPIClient<
46
- Services extends ServicesDeclaration<Services>,
47
- TCallbacks extends Callbacks,
58
+ Services extends UnionServiceOperationsDeclaration<Services>,
59
+ Callbacks extends ServiceMethods,
48
60
  >(
49
- services: ServiceSchemasDeclaration<Services>,
50
- callbacks: TCallbacks,
51
- options: CreateAPIBasicClientOptions
52
- ): APIBasicClientServices<Services, TCallbacks>;
61
+ services: Services,
62
+ callbacks: Callbacks,
63
+ options: CreateAPIQueryClientOptions
64
+ ): APIDefaultQueryClientServices<Services>;
53
65
 
66
+ /**
67
+ * Creates a QueryClient compatible API Client which contains all operations
68
+ * such as `useQuery`, `useMutation`.
69
+ *
70
+ * @example Fetching data with QueryClient
71
+ * ```ts
72
+ * const api = qraftAPIClient(services, callbacks, {
73
+ * requestFn: requestFn,
74
+ * baseUrl: 'https://api.example.com',
75
+ * queryClient: new QueryClient(),
76
+ * });
77
+ *
78
+ * api.service.operation({
79
+ * parameters: { path: { id: 1 } },
80
+ * });
81
+ * ```
82
+ */
54
83
  export function qraftAPIClient<
55
- Services extends ServicesDeclaration<Services>,
56
- TCallbacks extends Required<Callbacks>,
84
+ Services extends UnionServiceOperationsDeclaration<Services>,
85
+ Callbacks extends PartialServiceMethods,
57
86
  >(
58
- services: ServiceSchemasDeclaration<Services>,
59
- callbacks: TCallbacks,
87
+ services: Services,
88
+ callbacks: Callbacks,
60
89
  options: CreateAPIQueryClientOptions
61
- ): Services;
90
+ ): APIQueryClientServices<Services, Callbacks>;
62
91
 
92
+ /**
93
+ * Creates a QueryClient compatible API Client which contains
94
+ * only state management manipulations such as `useIsMutating`,
95
+ * `setQueryData`, `getQueryData` and `invalidateQueries`.
96
+ *
97
+ * @example Invalidating queries with QueryClient
98
+ * ```ts
99
+ * const api = qraftAPIClient(services, callbacks, {
100
+ * // an instance of QueryClient shared between all clients
101
+ * queryClient: sharedQueryClient
102
+ * });
103
+ *
104
+ * api.service.operation.invalidateQueries({
105
+ * parameters: { path: { id: 1 } },
106
+ * });
107
+ */
63
108
  export function qraftAPIClient<
64
- Services extends ServicesDeclaration<Services>,
65
- TCallbacks extends Callbacks,
109
+ Services extends UnionServiceOperationsDeclaration<Services>,
110
+ Callbacks extends PartialServiceMethods,
66
111
  >(
67
- services: ServiceSchemasDeclaration<Services>,
68
- callbacks: TCallbacks,
112
+ services: Services,
113
+ callbacks: Callbacks,
69
114
  options: CreateAPIBasicQueryClientOptions
70
- ): APIBasicQueryClientServices<Services, TCallbacks>;
115
+ ): APIBasicQueryClientServices<Services, Callbacks>;
71
116
 
117
+ /**
118
+ * Creates a basic API Client which contains only "fetch" like
119
+ * operations without any state management using QueryClient.
120
+ *
121
+ * @example Fetching data without QueryClient
122
+ * ```ts
123
+ * const api = qraftAPIClient(services, callbacks, {
124
+ * requestFn: requestFn,
125
+ * baseUrl: 'https://api.example.com',
126
+ * });
127
+ *
128
+ * api.service.operation({
129
+ * parameters: { path: { id: 1 } },
130
+ * });
131
+ * ```
132
+ */
72
133
  export function qraftAPIClient<
73
- Services extends ServicesDeclaration<Services>,
74
- TCallbacks extends Callbacks,
134
+ Services extends UnionServiceOperationsDeclaration<Services>,
135
+ Callbacks extends PartialServiceMethods,
75
136
  >(
76
- services: ServiceSchemasDeclaration<Services>,
77
- callbacks: TCallbacks,
78
- options: CreateAPIQueryClientOptions
79
- ): APIQueryClientServices<Services, TCallbacks>;
137
+ services: Services,
138
+ callbacks: Callbacks,
139
+ options: CreateAPIBasicClientOptions
140
+ ): APIBasicClientServices<Services, Callbacks>;
80
141
 
142
+ /**
143
+ * Creates a utility API Client which contains only utility operations
144
+ * such as `getQueryKey`, `getInfiniteQueryKey` and `getMutationKey`.
145
+ *
146
+ * @example Getting query keys with utility client
147
+ * ```ts
148
+ * const api = qraftAPIClient(services, callbacks);
149
+ *
150
+ * api.service.operation.getQueryKey({
151
+ * parameters: { path: { id: 1 } },
152
+ * });
153
+ * ```
154
+ */
81
155
  export function qraftAPIClient<
82
- Services extends ServicesDeclaration<Services>,
83
- TCallbacks extends Callbacks,
156
+ Services extends UnionServiceOperationsDeclaration<Services>,
157
+ Callbacks extends Pick<PartialServiceMethods, UtilityOperationCallbacks>,
84
158
  >(
85
- services: ServiceSchemasDeclaration<Services>,
86
- callbacks: TCallbacks
87
- ): APIUtilityClientServices<Services, TCallbacks>;
159
+ services: Services,
160
+ callbacks: Callbacks
161
+ ): APIUtilityClientServices<Services, Callbacks>;
88
162
 
89
163
  export function qraftAPIClient<
90
- Services extends ServicesDeclaration<Services>,
91
- TCallbacks extends Callbacks,
164
+ Services extends UnionServiceOperationsDeclaration<Services>,
165
+ Callbacks extends PartialServiceMethods,
92
166
  >(
93
- services: ServiceSchemasDeclaration<Services>,
94
- callbacks: TCallbacks,
167
+ services: Services,
168
+ callbacks: Callbacks,
95
169
  options?: CreateAPIClientOptions
96
- ): APIQueryClientServices<Services, TCallbacks> | Services {
170
+ ):
171
+ | APIQueryClientServices<Services, Callbacks>
172
+ | APIDefaultQueryClientServices<Services>
173
+ | APIBasicQueryClientServices<Services, Callbacks>
174
+ | APIUtilityClientServices<Services, Callbacks> {
97
175
  const stringTag = 'QraftAPIClient';
98
176
 
99
177
  const toString = (path: (symbol | string)[]): string => {
@@ -132,7 +210,14 @@ export function qraftAPIClient<
132
210
  return stringTag;
133
211
  }
134
212
 
135
- if (getPath.length !== 2 || key !== 'schema') return; // todo::maybe return callback?
213
+ if (key !== 'schema') return;
214
+ if (
215
+ getPath.length !== 2 &&
216
+ !('schema' in services) &&
217
+ getPath.length !== 1 &&
218
+ !(services[getPath[0] as never] as OperationsDeclaration<any>)?.schema
219
+ )
220
+ return;
136
221
 
137
222
  const serviceOperation = getByPath(services, getPath);
138
223
  if (!isServiceOperation(serviceOperation))
@@ -140,7 +225,10 @@ export function qraftAPIClient<
140
225
  return serviceOperation.schema;
141
226
  },
142
227
  function applyCallback(applyPath, args) {
143
- const { path, callbackName } = extractCallbackDetails(applyPath);
228
+ const { path, callbackName } = extractCallbackDetails(
229
+ applyPath,
230
+ services
231
+ );
144
232
 
145
233
  assertValidCallbackName(callbackName, callbacks);
146
234
 
@@ -168,13 +256,16 @@ export function qraftAPIClient<
168
256
  }
169
257
 
170
258
  function assertValidCallbackName<
171
- TCallbacks extends Record<string, (...rest: any[]) => unknown>,
259
+ Callbacks extends Record<string, (...rest: any[]) => unknown>,
172
260
  >(
173
261
  callbackName: string | number | symbol,
174
- callbacks: TCallbacks
175
- ): asserts callbackName is keyof TCallbacks {
262
+ callbacks: Callbacks
263
+ ): asserts callbackName is keyof Callbacks {
176
264
  if (!(callbackName in callbacks)) {
177
- if ((callbackName as OperationInvokeFnName) === 'operationInvokeFn')
265
+ if (
266
+ (callbackName as InvokeOperationCallback) ===
267
+ ('operationInvokeFn' satisfies InvokeOperationCallback)
268
+ )
178
269
  throw new Error(
179
270
  `Callback 'operationInvokeFn' is required for executing 'qraft.<service>.<operation>()', but it is not provided in the 'callbacks' object.`
180
271
  );
@@ -186,17 +277,29 @@ function assertValidCallbackName<
186
277
 
187
278
  /**
188
279
  * Extracts Callback details from the applyPath
189
- * @param applyPath
190
280
  */
191
- function extractCallbackDetails(applyPath: (string | symbol)[]) {
192
- // <service>.<operation>()
193
- if (applyPath.length === 2) {
281
+ function extractCallbackDetails(
282
+ applyPath: (string | symbol)[],
283
+ services: UnionServiceOperationsDeclaration<any>
284
+ ) {
285
+ // client.<service>.<operation>() [OperationInvokeFn]
286
+ // <service>.<operation>() [OperationInvokeFn]
287
+ // client() [OperationInvokeFn]
288
+ // client()
289
+ if (
290
+ (applyPath.length === 2 &&
291
+ !(services[applyPath[0] as never] as OperationsDeclaration<any>)
292
+ ?.schema) ||
293
+ (applyPath.length === 0 && 'schema' in services)
294
+ ) {
194
295
  return {
195
296
  path: applyPath,
196
- callbackName: 'operationInvokeFn' satisfies OperationInvokeFnName,
297
+ callbackName: 'operationInvokeFn' satisfies InvokeOperationCallback,
197
298
  };
198
299
  } else {
300
+ // client.<service>.<operation>.<method>()
199
301
  // <service>.<operation>.<method>()
302
+ // client.<method>()
200
303
  return {
201
304
  path: applyPath.slice(0, -1),
202
305
  // The last arg is for instance `.useMutation` or `.useQuery()`
@@ -218,190 +321,238 @@ function getByPath(obj: Record<string, unknown>, path: (string | symbol)[]) {
218
321
  }, obj);
219
322
  }
220
323
 
221
- type Callbacks = Partial<typeof callbacks>;
324
+ type ServiceMethods = typeof callbacks;
325
+
326
+ type PartialServiceMethods = Partial<ServiceMethods>;
327
+
328
+ type OperationDeclaration = {
329
+ schema: OperationSchema;
330
+ [QraftServiceOperationsToken]: Partial<
331
+ Record<
332
+ | QueryOperationCallbacks
333
+ | QueryOperationStateCallbacks
334
+ | MutationOperationCallbacks
335
+ | MutationOperationStateCallbacks
336
+ | UtilityOperationCallbacks,
337
+ any
338
+ >
339
+ > & {
340
+ types: any;
341
+ schema: OperationSchema;
342
+ (...args: any[]): any;
343
+ };
344
+ };
345
+
346
+ type OperationsDeclaration<Operations> = {
347
+ [operation in keyof Operations]: OperationDeclaration;
348
+ };
222
349
 
223
350
  type ServicesDeclaration<Services> = {
224
- [service in keyof Services]: {
225
- [method in keyof Services[service]]: {
226
- schema: OperationSchema;
227
- types: {
228
- parameters?: any;
229
- data?: any;
230
- error?: any;
231
- body?: any;
232
- };
233
- };
234
- };
351
+ [service in keyof Services]: OperationsDeclaration<Services[service]>;
235
352
  };
236
353
 
237
- type ServiceSchemasDeclaration<Services extends ServicesDeclaration<Services>> =
238
- {
239
- [service in keyof Services]: {
240
- [method in keyof Services[service]]: {
241
- schema: Services[service][method]['schema'];
242
- };
243
- };
244
- };
354
+ export type UnionServiceOperationsDeclaration<Services> =
355
+ | ServicesDeclaration<Services>
356
+ | OperationsDeclaration<Services>
357
+ | OperationDeclaration;
245
358
 
246
359
  type QueryOperationCallbacks = Extract<
247
- keyof Callbacks,
248
- | 'cancelQueries'
360
+ keyof ServiceMethods,
249
361
  | 'fetchInfiniteQuery'
250
362
  | 'fetchQuery'
363
+ | 'prefetchInfiniteQuery'
364
+ | 'prefetchQuery'
365
+ | 'refetchQueries'
366
+ | 'ensureQueryData'
367
+ | 'ensureInfiniteQueryData'
368
+ | 'useInfiniteQuery'
369
+ | 'useQueries'
370
+ | 'useQuery'
371
+ | 'useSuspenseInfiniteQuery'
372
+ | 'useSuspenseQueries'
373
+ | 'useSuspenseQuery'
374
+ >;
375
+
376
+ type QueryOperationStateCallbacks = Extract<
377
+ keyof ServiceMethods,
378
+ | 'cancelQueries'
251
379
  | 'getInfiniteQueryData'
252
- | 'getInfiniteQueryKey'
253
380
  | 'getInfiniteQueryState'
254
381
  | 'getQueriesData'
255
382
  | 'getQueryData'
256
- | 'getQueryKey'
257
383
  | 'getQueryState'
258
384
  | 'invalidateQueries'
259
385
  | 'isFetching'
260
- | 'prefetchInfiniteQuery'
261
- | 'prefetchQuery'
262
- | 'refetchQueries'
263
- | 'ensureQueryData'
264
- | 'ensureInfiniteQueryData'
265
386
  | 'removeQueries'
266
387
  | 'resetQueries'
267
388
  | 'setInfiniteQueryData'
268
389
  | 'setQueriesData'
269
390
  | 'setQueryData'
270
- | 'useInfiniteQuery'
271
391
  | 'useIsFetching'
272
- | 'useQueries'
273
- | 'useQuery'
274
- | 'useSuspenseInfiniteQuery'
275
- | 'useSuspenseQueries'
276
- | 'useSuspenseQuery'
277
392
  >;
278
393
 
279
- type MutationOperationCallbacks = Extract<
280
- keyof Callbacks,
281
- | 'getMutationKey'
282
- | 'isMutating'
283
- | 'useIsMutating'
284
- | 'useMutation'
285
- | 'useMutationState'
394
+ type MutationOperationCallbacks = Extract<keyof ServiceMethods, 'useMutation'>;
395
+
396
+ type MutationOperationStateCallbacks = Extract<
397
+ keyof ServiceMethods,
398
+ 'isMutating' | 'useIsMutating' | 'useMutationState'
399
+ >;
400
+
401
+ type InvokeOperationCallback = Extract<
402
+ keyof typeof operationInvokeModule,
403
+ 'operationInvokeFn'
404
+ >;
405
+
406
+ type UtilityOperationCallbacks = Extract<
407
+ keyof ServiceMethods,
408
+ 'getQueryKey' | 'getInfiniteQueryKey' | 'getMutationKey'
286
409
  >;
287
410
 
411
+ type OperationCallbackList =
412
+ | QueryOperationCallbacks
413
+ | QueryOperationStateCallbacks
414
+ | MutationOperationCallbacks
415
+ | MutationOperationStateCallbacks
416
+ | InvokeOperationCallback
417
+ | UtilityOperationCallbacks;
418
+
288
419
  export type APIQueryClientServices<
289
- TServices extends ServicesDeclaration<TServices>,
290
- TCallbacks extends Callbacks,
420
+ Services extends UnionServiceOperationsDeclaration<Services>,
421
+ Callbacks extends PartialServiceMethods,
291
422
  > = ServicesFilteredByCallbacks<
292
- TServices,
293
- TCallbacks,
294
- QueryOperationCallbacks,
295
- MutationOperationCallbacks
423
+ Services,
424
+ Extract<keyof Callbacks, OperationCallbackList>
296
425
  >;
297
426
 
427
+ export type APIDefaultQueryClientServices<
428
+ Services extends UnionServiceOperationsDeclaration<Services>,
429
+ > = Services extends OperationDeclaration
430
+ ? Services[QraftServiceOperationsToken]
431
+ : Services extends OperationsDeclaration<Services>
432
+ ? {
433
+ [operation in keyof Services]: Services[operation][QraftServiceOperationsToken];
434
+ }
435
+ : Services extends ServicesDeclaration<Services>
436
+ ? {
437
+ [service in keyof Services]: {
438
+ [operation in keyof Services[service]]: Services[service][operation][QraftServiceOperationsToken];
439
+ };
440
+ }
441
+ : never;
442
+
298
443
  export type APIBasicQueryClientServices<
299
- TServices extends ServicesDeclaration<TServices>,
300
- TCallbacks extends Callbacks,
444
+ Services extends UnionServiceOperationsDeclaration<Services>,
445
+ Callbacks extends PartialServiceMethods,
301
446
  > = ServicesFilteredByCallbacks<
302
- TServices,
303
- Omit<TCallbacks, 'operationInvokeFn'>,
304
- Extract<
305
- QueryOperationCallbacks,
306
- | 'resetQueries'
307
- | 'removeQueries'
308
- | 'cancelQueries'
309
- | 'invalidateQueries'
310
- | 'refetchQueries'
311
- | 'getQueryKey'
312
- | 'getInfiniteQueryState'
313
- | 'getInfiniteQueryData'
314
- | 'getInfiniteQueryKey'
315
- | 'setInfiniteQueryData'
316
- | 'getQueriesData'
317
- | 'setQueriesData'
318
- | 'getQueryState'
319
- | 'getQueryData'
320
- | 'setQueryData'
321
- | 'useIsFetching'
322
- | 'isFetching'
323
- >,
447
+ Services,
324
448
  Extract<
325
- MutationOperationCallbacks,
326
- 'getMutationKey' | 'useMutationState' | 'useIsMutating' | 'isMutating'
449
+ keyof Callbacks,
450
+ | QueryOperationStateCallbacks
451
+ | MutationOperationStateCallbacks
452
+ | UtilityOperationCallbacks
327
453
  >
328
454
  >;
329
455
 
330
- export type APIUtilityClientServices<
331
- TServices extends ServicesDeclaration<TServices>,
332
- TCallbacks extends Callbacks,
456
+ export type APIBasicClientServices<
457
+ Services extends UnionServiceOperationsDeclaration<Services>,
458
+ Callbacks extends PartialServiceMethods,
333
459
  > = ServicesFilteredByCallbacks<
334
- TServices,
335
- Omit<TCallbacks, 'operationInvokeFn'>,
336
- Extract<QueryOperationCallbacks, 'getQueryKey' | 'getInfiniteQueryKey'>,
337
- Extract<MutationOperationCallbacks, 'getMutationKey'>
460
+ Services,
461
+ Extract<keyof Callbacks, InvokeOperationCallback | UtilityOperationCallbacks>
338
462
  >;
339
463
 
340
- export type APIBasicClientServices<
341
- TServices extends ServicesDeclaration<TServices>,
342
- TCallbacks extends Callbacks,
343
- > = ServicesFilteredByCallbacks<
344
- TServices,
345
- TCallbacks,
346
- Extract<QueryOperationCallbacks, 'getQueryKey' | 'getInfiniteQueryKey'>,
347
- Extract<MutationOperationCallbacks, 'getMutationKey'>
464
+ export type APIUtilityClientServices<
465
+ Services extends UnionServiceOperationsDeclaration<Services>,
466
+ Callbacks extends Pick<PartialServiceMethods, UtilityOperationCallbacks>,
467
+ > = ServicesFilteredByUtilityCallbacks<
468
+ Services,
469
+ Extract<keyof Callbacks, UtilityOperationCallbacks>
348
470
  >;
349
471
 
350
472
  type ServicesFilteredByCallbacks<
351
- TServices extends ServicesDeclaration<TServices>,
352
- TCallbacks extends Callbacks,
353
- TQueryOperationCallbacks extends QueryOperationCallbacks,
354
- TMutationOperationCallbacks extends MutationOperationCallbacks,
355
- > = {
356
- [serviceName in keyof TServices]: {
357
- [method in keyof TServices[serviceName]]: TServices[serviceName][method]['schema']['method'] extends
358
- | 'get'
359
- | 'head'
360
- | 'options'
361
- ? Pick<
362
- ServiceOperationQuery<
363
- TServices[serviceName][method]['schema'],
364
- TServices[serviceName][method]['types']['data'],
365
- TServices[serviceName][method]['types']['parameters'],
366
- TServices[serviceName][method]['types']['error']
367
- >,
368
- | Extract<keyof TCallbacks, TQueryOperationCallbacks>
369
- | 'types'
370
- | 'schema'
473
+ Services extends UnionServiceOperationsDeclaration<Services>,
474
+ CallbackList extends OperationCallbackList,
475
+ > = Services extends OperationDeclaration
476
+ ? Pick<
477
+ Services[QraftServiceOperationsToken],
478
+ Extract<
479
+ keyof Services[QraftServiceOperationsToken],
480
+ CallbackList | 'schema' | 'types'
481
+ >
482
+ > &
483
+ OperationInvokeFn<Services[QraftServiceOperationsToken], CallbackList>
484
+ : Services extends OperationsDeclaration<Services>
485
+ ? {
486
+ [operation in keyof Services]: Pick<
487
+ Services[operation][QraftServiceOperationsToken],
488
+ Extract<
489
+ keyof Services[operation][QraftServiceOperationsToken],
490
+ CallbackList | 'schema' | 'types'
491
+ >
371
492
  > &
372
- (OperationInvokeFnName extends keyof TCallbacks
373
- ? ServiceOperationQueryFn<
374
- TServices[serviceName][method]['schema'],
375
- TServices[serviceName][method]['types']['data'],
376
- TServices[serviceName][method]['types']['parameters'],
377
- TServices[serviceName][method]['types']['error']
493
+ OperationInvokeFn<
494
+ Services[operation][QraftServiceOperationsToken],
495
+ CallbackList
496
+ >;
497
+ }
498
+ : Services extends ServicesDeclaration<Services>
499
+ ? {
500
+ [serviceName in keyof Services]: {
501
+ [operation in keyof Services[serviceName]]: Pick<
502
+ Services[serviceName][operation][QraftServiceOperationsToken],
503
+ Extract<
504
+ keyof Services[serviceName][operation][QraftServiceOperationsToken],
505
+ CallbackList | 'schema' | 'types'
378
506
  >
379
- : {})
380
- : Pick<
381
- ServiceOperationMutation<
382
- TServices[serviceName][method]['schema'],
383
- TServices[serviceName][method]['types']['body'],
384
- TServices[serviceName][method]['types']['data'],
385
- TServices[serviceName][method]['types']['parameters'],
386
- TServices[serviceName][method]['types']['error']
387
- >,
388
- | Extract<keyof TCallbacks, TMutationOperationCallbacks>
389
- | 'types'
390
- | 'schema'
391
- > &
392
- (OperationInvokeFnName extends keyof TCallbacks
393
- ? ServiceOperationMutationFn<
394
- TServices[serviceName][method]['schema'],
395
- TServices[serviceName][method]['types']['body'],
396
- TServices[serviceName][method]['types']['data'],
397
- TServices[serviceName][method]['types']['parameters'],
398
- TServices[serviceName][method]['types']['error']
507
+ > &
508
+ OperationInvokeFn<
509
+ Services[serviceName][operation][QraftServiceOperationsToken],
510
+ CallbackList
511
+ >;
512
+ };
513
+ }
514
+ : never;
515
+
516
+ type OperationInvokeFn<
517
+ InvokeFn extends (...args: any[]) => any,
518
+ CallbackList extends OperationCallbackList,
519
+ > = InvokeOperationCallback extends CallbackList
520
+ ? InvokeFn extends (...args: infer Args) => infer Result
521
+ ? { (...args: Args): Result }
522
+ : Record<string, never>
523
+ : Record<string, never>;
524
+
525
+ type ServicesFilteredByUtilityCallbacks<
526
+ Services extends UnionServiceOperationsDeclaration<Services>,
527
+ CallbackList extends UtilityOperationCallbacks,
528
+ > = Services extends OperationDeclaration
529
+ ? Pick<
530
+ Services[QraftServiceOperationsToken],
531
+ Extract<
532
+ keyof Services[QraftServiceOperationsToken],
533
+ CallbackList | 'schema' | 'types'
534
+ >
535
+ >
536
+ : Services extends OperationsDeclaration<Services>
537
+ ? {
538
+ [operation in keyof Services]: Pick<
539
+ Services[operation][QraftServiceOperationsToken],
540
+ Extract<
541
+ keyof Services[operation][QraftServiceOperationsToken],
542
+ CallbackList | 'schema' | 'types'
543
+ >
544
+ >;
545
+ }
546
+ : Services extends ServicesDeclaration<Services>
547
+ ? {
548
+ [serviceName in keyof Services]: {
549
+ [operation in keyof Services[serviceName]]: Pick<
550
+ Services[serviceName][operation][QraftServiceOperationsToken],
551
+ Extract<
552
+ keyof Services[serviceName][operation][QraftServiceOperationsToken],
553
+ CallbackList | 'schema' | 'types'
399
554
  >
400
- : {});
401
- };
402
- };
403
-
404
- type OperationInvokeFnName = Extract<
405
- keyof typeof operationInvokeModule,
406
- 'operationInvokeFn'
407
- >;
555
+ >;
556
+ };
557
+ }
558
+ : never;