@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.
- package/CHANGELOG.md +21 -0
- package/dist/cjs/qraftAPIClient.cjs +11 -6
- package/dist/cjs/qraftAPIClient.cjs.map +1 -1
- package/dist/esm/qraftAPIClient.js +11 -6
- package/dist/esm/qraftAPIClient.js.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/migrate-to-v2.6.0-codemod.d.ts +3 -0
- package/dist/types/migrate-to-v2.6.0-codemod.d.ts.map +1 -0
- package/dist/types/qraftAPIClient.d.ts +132 -34
- package/dist/types/qraftAPIClient.d.ts.map +1 -1
- package/package.json +11 -6
- package/src/index.ts +2 -0
- package/src/migrate-to-v2.6.0-codemod.ts +55 -0
- package/src/qraftAPIClient.ts +343 -192
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
# @openapi-qraft/react
|
|
2
2
|
|
|
3
|
+
## 2.6.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- c71e7f9: ### Multiple API Client Generation
|
|
8
|
+
|
|
9
|
+
- Added support for generating multiple custom API client functions for a single OpenAPI specification with the new `--create-api-client-fn` option
|
|
10
|
+
- Improved modularity by allowing the creation of API clients with specific sets of services and callbacks
|
|
11
|
+
- Enhanced type inference by removing generic type parameters from `qraftAPIClient` function, making it more user-friendly
|
|
12
|
+
|
|
13
|
+
#### Breaking Changes
|
|
14
|
+
|
|
15
|
+
- Removed generic type parameters from `qraftAPIClient` function - types are now automatically inferred from arguments
|
|
16
|
+
- Updated return type of `createAPIClient` which may require changes to code that references this type in contexts or variables
|
|
17
|
+
- Added a migration guide and codemod script to help users update their code to the new API
|
|
18
|
+
|
|
19
|
+
### Patch Changes
|
|
20
|
+
|
|
21
|
+
- Updated dependencies [c71e7f9]
|
|
22
|
+
- @openapi-qraft/tanstack-query-react-types@2.6.0
|
|
23
|
+
|
|
3
24
|
## 2.5.0
|
|
4
25
|
|
|
5
26
|
### Minor Changes
|
|
@@ -29,12 +29,13 @@ function qraftAPIClient(services, callbacks, options) {
|
|
|
29
29
|
} else if (key === Symbol.toStringTag) {
|
|
30
30
|
return stringTag;
|
|
31
31
|
}
|
|
32
|
-
if (
|
|
32
|
+
if (key !== 'schema') return;
|
|
33
|
+
if (getPath.length !== 2 && !('schema' in services) && getPath.length !== 1 && !services[getPath[0]]?.schema) return;
|
|
33
34
|
const serviceOperation = getByPath(services, getPath);
|
|
34
35
|
if (!isServiceOperation(serviceOperation)) throw new Error(`Service operation not found: ${getPath.join('.')}`);
|
|
35
36
|
return serviceOperation.schema;
|
|
36
37
|
}, function applyCallback(applyPath, args) {
|
|
37
|
-
const { path, callbackName } = extractCallbackDetails(applyPath);
|
|
38
|
+
const { path, callbackName } = extractCallbackDetails(applyPath, services);
|
|
38
39
|
assertValidCallbackName(callbackName, callbacks);
|
|
39
40
|
const serviceOperation = getByPath(services, path);
|
|
40
41
|
if (!isServiceOperation(serviceOperation)) throw new Error(`Service operation not found: ${path.join('.')}`);
|
|
@@ -53,16 +54,20 @@ function assertValidCallbackName(callbackName, callbacks) {
|
|
|
53
54
|
}
|
|
54
55
|
/**
|
|
55
56
|
* Extracts Callback details from the applyPath
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
// <service>.<operation>()
|
|
59
|
-
|
|
57
|
+
*/ function extractCallbackDetails(applyPath, services) {
|
|
58
|
+
// client.<service>.<operation>() [OperationInvokeFn]
|
|
59
|
+
// <service>.<operation>() [OperationInvokeFn]
|
|
60
|
+
// client() [OperationInvokeFn]
|
|
61
|
+
// client()
|
|
62
|
+
if (applyPath.length === 2 && !services[applyPath[0]]?.schema || applyPath.length === 0 && 'schema' in services) {
|
|
60
63
|
return {
|
|
61
64
|
path: applyPath,
|
|
62
65
|
callbackName: 'operationInvokeFn'
|
|
63
66
|
};
|
|
64
67
|
} else {
|
|
68
|
+
// client.<service>.<operation>.<method>()
|
|
65
69
|
// <service>.<operation>.<method>()
|
|
70
|
+
// client.<method>()
|
|
66
71
|
return {
|
|
67
72
|
path: applyPath.slice(0, -1),
|
|
68
73
|
// The last arg is for instance `.useMutation` or `.useQuery()`
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"qraftAPIClient.cjs","sources":["../../src/qraftAPIClient.ts"],"sourcesContent":["import type {\n ServiceOperationMutation,\n ServiceOperationMutationFn,\n ServiceOperationQuery,\n ServiceOperationQueryFn,\n} from '@openapi-qraft/tanstack-query-react-types';\nimport type { QueryClient } from '@tanstack/query-core';\nimport type * as callbacks from './callbacks/index.js';\nimport type * as operationInvokeModule from './callbacks/operationInvokeFn.js';\nimport type {\n OperationSchema,\n RequestFnInfo,\n RequestFnResponse,\n} from './lib/requestFn.js';\nimport { createRecursiveProxy } from './lib/createRecursiveProxy.js';\n\nexport interface CreateAPIBasicClientOptions {\n requestFn<TData, TError>(\n schema: OperationSchema,\n requestInfo: RequestFnInfo\n ): Promise<RequestFnResponse<TData, TError>>;\n baseUrl: string;\n}\n\nexport interface CreateAPIBasicQueryClientOptions {\n queryClient: QueryClient;\n}\n\nexport interface CreateAPIQueryClientOptions\n extends CreateAPIBasicClientOptions,\n CreateAPIBasicQueryClientOptions {}\n\n/**\n * @deprecated use `CreateAPIClientOptions` instead\n */\nexport type QraftClientOptions =\n | CreateAPIBasicClientOptions\n | CreateAPIQueryClientOptions;\n\nexport type CreateAPIClientOptions =\n | CreateAPIBasicClientOptions\n | CreateAPIBasicQueryClientOptions\n | CreateAPIQueryClientOptions;\n\nexport function qraftAPIClient<\n Services extends ServicesDeclaration<Services>,\n TCallbacks extends Callbacks,\n>(\n services: ServiceSchemasDeclaration<Services>,\n callbacks: TCallbacks,\n options: CreateAPIBasicClientOptions\n): APIBasicClientServices<Services, TCallbacks>;\n\nexport function qraftAPIClient<\n Services extends ServicesDeclaration<Services>,\n TCallbacks extends Required<Callbacks>,\n>(\n services: ServiceSchemasDeclaration<Services>,\n callbacks: TCallbacks,\n options: CreateAPIQueryClientOptions\n): Services;\n\nexport function qraftAPIClient<\n Services extends ServicesDeclaration<Services>,\n TCallbacks extends Callbacks,\n>(\n services: ServiceSchemasDeclaration<Services>,\n callbacks: TCallbacks,\n options: CreateAPIBasicQueryClientOptions\n): APIBasicQueryClientServices<Services, TCallbacks>;\n\nexport function qraftAPIClient<\n Services extends ServicesDeclaration<Services>,\n TCallbacks extends Callbacks,\n>(\n services: ServiceSchemasDeclaration<Services>,\n callbacks: TCallbacks,\n options: CreateAPIQueryClientOptions\n): APIQueryClientServices<Services, TCallbacks>;\n\nexport function qraftAPIClient<\n Services extends ServicesDeclaration<Services>,\n TCallbacks extends Callbacks,\n>(\n services: ServiceSchemasDeclaration<Services>,\n callbacks: TCallbacks\n): APIUtilityClientServices<Services, TCallbacks>;\n\nexport function qraftAPIClient<\n Services extends ServicesDeclaration<Services>,\n TCallbacks extends Callbacks,\n>(\n services: ServiceSchemasDeclaration<Services>,\n callbacks: TCallbacks,\n options?: CreateAPIClientOptions\n): APIQueryClientServices<Services, TCallbacks> | Services {\n const stringTag = 'QraftAPIClient';\n\n const toString = (path: (symbol | string)[]): string => {\n return `[${stringTag}${path.length ? ' ' + path.join('.') : ''}]`;\n };\n\n const primitiveMethods = {\n [Symbol.toPrimitive](\n this: undefined,\n path: (string | symbol)[],\n hint: 'string' | 'number' | 'default'\n ): unknown {\n if (hint === 'number') return NaN;\n if (hint === 'string') return toString(path);\n return getByPath(services, path);\n },\n valueOf(this: undefined, path: (string | symbol)[]): unknown {\n return getByPath(services, path);\n },\n toJSON(this: undefined, path: (string | symbol)[]): string {\n return JSON.stringify(getByPath(services, path));\n },\n toString(this: undefined, path: (string | symbol)[]): string {\n return toString(path);\n },\n };\n\n return createRecursiveProxy(\n function getCallback(getPath, key) {\n if (Object.prototype.hasOwnProperty.call(primitiveMethods, key)) {\n return primitiveMethods[key as keyof typeof primitiveMethods].bind(\n undefined,\n getPath\n );\n } else if (key === Symbol.toStringTag) {\n return stringTag;\n }\n\n if (getPath.length !== 2 || key !== 'schema') return; // todo::maybe return callback?\n\n const serviceOperation = getByPath(services, getPath);\n if (!isServiceOperation(serviceOperation))\n throw new Error(`Service operation not found: ${getPath.join('.')}`);\n return serviceOperation.schema;\n },\n function applyCallback(applyPath, args) {\n const { path, callbackName } = extractCallbackDetails(applyPath);\n\n assertValidCallbackName(callbackName, callbacks);\n\n const serviceOperation = getByPath(services, path);\n\n if (!isServiceOperation(serviceOperation))\n throw new Error(`Service operation not found: ${path.join('.')}`);\n\n if (\n callbackName !== 'operationInvokeFn' &&\n callbackName !== 'getQueryKey' &&\n callbackName !== 'getMutationKey' &&\n callbackName !== 'getInfiniteQueryKey'\n )\n if (!options || !('queryClient' in options && options.queryClient))\n throw new Error(\n `'qraft.<service>.<operation>.${String(callbackName)}()' requires 'queryClient' in 'createAPIClient(...)' options.`\n );\n\n // @ts-expect-error - Too complex union type\n return callbacks[callbackName](options, serviceOperation.schema, args);\n },\n []\n ) as never;\n}\n\nfunction assertValidCallbackName<\n TCallbacks extends Record<string, (...rest: any[]) => unknown>,\n>(\n callbackName: string | number | symbol,\n callbacks: TCallbacks\n): asserts callbackName is keyof TCallbacks {\n if (!(callbackName in callbacks)) {\n if ((callbackName as OperationInvokeFnName) === 'operationInvokeFn')\n throw new Error(\n `Callback 'operationInvokeFn' is required for executing 'qraft.<service>.<operation>()', but it is not provided in the 'callbacks' object.`\n );\n throw new Error(\n `Callback for 'qraft.<service>.<operation>.${String(callbackName)}()' is not provided in the 'callbacks' object.`\n );\n }\n}\n\n/**\n * Extracts Callback details from the applyPath\n * @param applyPath\n */\nfunction extractCallbackDetails(applyPath: (string | symbol)[]) {\n // <service>.<operation>()\n if (applyPath.length === 2) {\n return {\n path: applyPath,\n callbackName: 'operationInvokeFn' satisfies OperationInvokeFnName,\n };\n } else {\n // <service>.<operation>.<method>()\n return {\n path: applyPath.slice(0, -1),\n // The last arg is for instance `.useMutation` or `.useQuery()`\n callbackName: applyPath[applyPath.length - 1],\n };\n }\n}\n\nfunction isServiceOperation(\n input: unknown\n): input is { schema: OperationSchema } {\n return input !== null && typeof input === 'object' && 'schema' in input;\n}\n\nfunction getByPath(obj: Record<string, unknown>, path: (string | symbol)[]) {\n return path.reduce<unknown>((acc, key) => {\n if (acc && typeof acc === 'object' && key in acc)\n return acc[key as keyof typeof acc];\n }, obj);\n}\n\ntype Callbacks = Partial<typeof callbacks>;\n\ntype ServicesDeclaration<Services> = {\n [service in keyof Services]: {\n [method in keyof Services[service]]: {\n schema: OperationSchema;\n types: {\n parameters?: any;\n data?: any;\n error?: any;\n body?: any;\n };\n };\n };\n};\n\ntype ServiceSchemasDeclaration<Services extends ServicesDeclaration<Services>> =\n {\n [service in keyof Services]: {\n [method in keyof Services[service]]: {\n schema: Services[service][method]['schema'];\n };\n };\n };\n\ntype QueryOperationCallbacks = Extract<\n keyof Callbacks,\n | 'cancelQueries'\n | 'fetchInfiniteQuery'\n | 'fetchQuery'\n | 'getInfiniteQueryData'\n | 'getInfiniteQueryKey'\n | 'getInfiniteQueryState'\n | 'getQueriesData'\n | 'getQueryData'\n | 'getQueryKey'\n | 'getQueryState'\n | 'invalidateQueries'\n | 'isFetching'\n | 'prefetchInfiniteQuery'\n | 'prefetchQuery'\n | 'refetchQueries'\n | 'ensureQueryData'\n | 'ensureInfiniteQueryData'\n | 'removeQueries'\n | 'resetQueries'\n | 'setInfiniteQueryData'\n | 'setQueriesData'\n | 'setQueryData'\n | 'useInfiniteQuery'\n | 'useIsFetching'\n | 'useQueries'\n | 'useQuery'\n | 'useSuspenseInfiniteQuery'\n | 'useSuspenseQueries'\n | 'useSuspenseQuery'\n>;\n\ntype MutationOperationCallbacks = Extract<\n keyof Callbacks,\n | 'getMutationKey'\n | 'isMutating'\n | 'useIsMutating'\n | 'useMutation'\n | 'useMutationState'\n>;\n\nexport type APIQueryClientServices<\n TServices extends ServicesDeclaration<TServices>,\n TCallbacks extends Callbacks,\n> = ServicesFilteredByCallbacks<\n TServices,\n TCallbacks,\n QueryOperationCallbacks,\n MutationOperationCallbacks\n>;\n\nexport type APIBasicQueryClientServices<\n TServices extends ServicesDeclaration<TServices>,\n TCallbacks extends Callbacks,\n> = ServicesFilteredByCallbacks<\n TServices,\n Omit<TCallbacks, 'operationInvokeFn'>,\n Extract<\n QueryOperationCallbacks,\n | 'resetQueries'\n | 'removeQueries'\n | 'cancelQueries'\n | 'invalidateQueries'\n | 'refetchQueries'\n | 'getQueryKey'\n | 'getInfiniteQueryState'\n | 'getInfiniteQueryData'\n | 'getInfiniteQueryKey'\n | 'setInfiniteQueryData'\n | 'getQueriesData'\n | 'setQueriesData'\n | 'getQueryState'\n | 'getQueryData'\n | 'setQueryData'\n | 'useIsFetching'\n | 'isFetching'\n >,\n Extract<\n MutationOperationCallbacks,\n 'getMutationKey' | 'useMutationState' | 'useIsMutating' | 'isMutating'\n >\n>;\n\nexport type APIUtilityClientServices<\n TServices extends ServicesDeclaration<TServices>,\n TCallbacks extends Callbacks,\n> = ServicesFilteredByCallbacks<\n TServices,\n Omit<TCallbacks, 'operationInvokeFn'>,\n Extract<QueryOperationCallbacks, 'getQueryKey' | 'getInfiniteQueryKey'>,\n Extract<MutationOperationCallbacks, 'getMutationKey'>\n>;\n\nexport type APIBasicClientServices<\n TServices extends ServicesDeclaration<TServices>,\n TCallbacks extends Callbacks,\n> = ServicesFilteredByCallbacks<\n TServices,\n TCallbacks,\n Extract<QueryOperationCallbacks, 'getQueryKey' | 'getInfiniteQueryKey'>,\n Extract<MutationOperationCallbacks, 'getMutationKey'>\n>;\n\ntype ServicesFilteredByCallbacks<\n TServices extends ServicesDeclaration<TServices>,\n TCallbacks extends Callbacks,\n TQueryOperationCallbacks extends QueryOperationCallbacks,\n TMutationOperationCallbacks extends MutationOperationCallbacks,\n> = {\n [serviceName in keyof TServices]: {\n [method in keyof TServices[serviceName]]: TServices[serviceName][method]['schema']['method'] extends\n | 'get'\n | 'head'\n | 'options'\n ? Pick<\n ServiceOperationQuery<\n TServices[serviceName][method]['schema'],\n TServices[serviceName][method]['types']['data'],\n TServices[serviceName][method]['types']['parameters'],\n TServices[serviceName][method]['types']['error']\n >,\n | Extract<keyof TCallbacks, TQueryOperationCallbacks>\n | 'types'\n | 'schema'\n > &\n (OperationInvokeFnName extends keyof TCallbacks\n ? ServiceOperationQueryFn<\n TServices[serviceName][method]['schema'],\n TServices[serviceName][method]['types']['data'],\n TServices[serviceName][method]['types']['parameters'],\n TServices[serviceName][method]['types']['error']\n >\n : {})\n : Pick<\n ServiceOperationMutation<\n TServices[serviceName][method]['schema'],\n TServices[serviceName][method]['types']['body'],\n TServices[serviceName][method]['types']['data'],\n TServices[serviceName][method]['types']['parameters'],\n TServices[serviceName][method]['types']['error']\n >,\n | Extract<keyof TCallbacks, TMutationOperationCallbacks>\n | 'types'\n | 'schema'\n > &\n (OperationInvokeFnName extends keyof TCallbacks\n ? ServiceOperationMutationFn<\n TServices[serviceName][method]['schema'],\n TServices[serviceName][method]['types']['body'],\n TServices[serviceName][method]['types']['data'],\n TServices[serviceName][method]['types']['parameters'],\n TServices[serviceName][method]['types']['error']\n >\n : {});\n };\n};\n\ntype OperationInvokeFnName = Extract<\n keyof typeof operationInvokeModule,\n 'operationInvokeFn'\n>;\n"],"names":["qraftAPIClient","services","callbacks","options","stringTag","toString","path","length","join","primitiveMethods","Symbol","toPrimitive","hint","NaN","getByPath","valueOf","toJSON","JSON","stringify","createRecursiveProxy","getCallback","getPath","key","Object","prototype","hasOwnProperty","call","bind","undefined","toStringTag","serviceOperation","isServiceOperation","Error","schema","applyCallback","applyPath","args","callbackName","extractCallbackDetails","assertValidCallbackName","queryClient","String","slice","input","obj","reduce","acc"],"mappings":";;;;AAwFO,SAASA,cAIdC,CAAAA,QAA6C,EAC7CC,SAAqB,EACrBC,OAAgC,EAAA;AAEhC,IAAA,MAAMC,SAAY,GAAA,gBAAA,CAAA;AAElB,IAAA,MA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,GAAAA,GAAAA;QAChC,IAAIwB,GAAAA,IAAO,OAAOA,GAAQ,KAAA,QAAA,IAAYxB,OAAOwB,GAC3C,EAAA,OAAOA,GAAG,CAACxB,GAAwB,CAAA,CAAA;KACpCsB,EAAAA,GAAAA,CAAAA,CAAAA;AACL;;;;"}
|
|
1
|
+
{"version":3,"file":"qraftAPIClient.cjs","sources":["../../src/qraftAPIClient.ts"],"sourcesContent":["import type { QraftServiceOperationsToken } from '@openapi-qraft/tanstack-query-react-types';\nimport type { QueryClient } from '@tanstack/query-core';\nimport type * as callbacks from './callbacks/index.js';\nimport type * as operationInvokeModule from './callbacks/operationInvokeFn.js';\nimport type {\n OperationSchema,\n RequestFnInfo,\n RequestFnResponse,\n} from './lib/requestFn.js';\nimport { createRecursiveProxy } from './lib/createRecursiveProxy.js';\n\nexport interface CreateAPIBasicClientOptions {\n requestFn<TData, TError>(\n schema: OperationSchema,\n requestInfo: RequestFnInfo\n ): Promise<RequestFnResponse<TData, TError>>;\n baseUrl: string;\n}\n\nexport interface CreateAPIBasicQueryClientOptions {\n queryClient: QueryClient;\n}\n\nexport interface CreateAPIQueryClientOptions\n extends CreateAPIBasicClientOptions,\n CreateAPIBasicQueryClientOptions {}\n\n/**\n * @deprecated use `CreateAPIClientOptions` instead\n */\nexport type QraftClientOptions =\n | CreateAPIBasicClientOptions\n | CreateAPIQueryClientOptions;\n\nexport type CreateAPIClientOptions =\n | CreateAPIBasicClientOptions\n | CreateAPIBasicQueryClientOptions\n | CreateAPIQueryClientOptions;\n\n/**\n * Creates a QueryClient compatible API Client which contains all operations\n * such as `useQuery`, `useMutation`.\n *\n * @example Fetching data with QueryClient\n * ```ts\n * const api = qraftAPIClient(services, callbacks, {\n * requestFn: requestFn,\n * baseUrl: 'https://api.example.com',\n * queryClient: new QueryClient(),\n * });\n *\n * api.service.operation({\n * parameters: { path: { id: 1 } },\n * });\n * ```\n */\nexport function qraftAPIClient<\n Services extends UnionServiceOperationsDeclaration<Services>,\n Callbacks extends ServiceMethods,\n>(\n services: Services,\n callbacks: Callbacks,\n options: CreateAPIQueryClientOptions\n): APIDefaultQueryClientServices<Services>;\n\n/**\n * Creates a QueryClient compatible API Client which contains all operations\n * such as `useQuery`, `useMutation`.\n *\n * @example Fetching data with QueryClient\n * ```ts\n * const api = qraftAPIClient(services, callbacks, {\n * requestFn: requestFn,\n * baseUrl: 'https://api.example.com',\n * queryClient: new QueryClient(),\n * });\n *\n * api.service.operation({\n * parameters: { path: { id: 1 } },\n * });\n * ```\n */\nexport function qraftAPIClient<\n Services extends UnionServiceOperationsDeclaration<Services>,\n Callbacks extends PartialServiceMethods,\n>(\n services: Services,\n callbacks: Callbacks,\n options: CreateAPIQueryClientOptions\n): APIQueryClientServices<Services, Callbacks>;\n\n/**\n * Creates a QueryClient compatible API Client which contains\n * only state management manipulations such as `useIsMutating`,\n * `setQueryData`, `getQueryData` and `invalidateQueries`.\n *\n * @example Invalidating queries with QueryClient\n * ```ts\n * const api = qraftAPIClient(services, callbacks, {\n * // an instance of QueryClient shared between all clients\n * queryClient: sharedQueryClient\n * });\n *\n * api.service.operation.invalidateQueries({\n * parameters: { path: { id: 1 } },\n * });\n */\nexport function qraftAPIClient<\n Services extends UnionServiceOperationsDeclaration<Services>,\n Callbacks extends PartialServiceMethods,\n>(\n services: Services,\n callbacks: Callbacks,\n options: CreateAPIBasicQueryClientOptions\n): APIBasicQueryClientServices<Services, Callbacks>;\n\n/**\n * Creates a basic API Client which contains only \"fetch\" like\n * operations without any state management using QueryClient.\n *\n * @example Fetching data without QueryClient\n * ```ts\n * const api = qraftAPIClient(services, callbacks, {\n * requestFn: requestFn,\n * baseUrl: 'https://api.example.com',\n * });\n *\n * api.service.operation({\n * parameters: { path: { id: 1 } },\n * });\n * ```\n */\nexport function qraftAPIClient<\n Services extends UnionServiceOperationsDeclaration<Services>,\n Callbacks extends PartialServiceMethods,\n>(\n services: Services,\n callbacks: Callbacks,\n options: CreateAPIBasicClientOptions\n): APIBasicClientServices<Services, Callbacks>;\n\n/**\n * Creates a utility API Client which contains only utility operations\n * such as `getQueryKey`, `getInfiniteQueryKey` and `getMutationKey`.\n *\n * @example Getting query keys with utility client\n * ```ts\n * const api = qraftAPIClient(services, callbacks);\n *\n * api.service.operation.getQueryKey({\n * parameters: { path: { id: 1 } },\n * });\n * ```\n */\nexport function qraftAPIClient<\n Services extends UnionServiceOperationsDeclaration<Services>,\n Callbacks extends Pick<PartialServiceMethods, UtilityOperationCallbacks>,\n>(\n services: Services,\n callbacks: Callbacks\n): APIUtilityClientServices<Services, Callbacks>;\n\nexport function qraftAPIClient<\n Services extends UnionServiceOperationsDeclaration<Services>,\n Callbacks extends PartialServiceMethods,\n>(\n services: Services,\n callbacks: Callbacks,\n options?: CreateAPIClientOptions\n):\n | APIQueryClientServices<Services, Callbacks>\n | APIDefaultQueryClientServices<Services>\n | APIBasicQueryClientServices<Services, Callbacks>\n | APIUtilityClientServices<Services, Callbacks> {\n const stringTag = 'QraftAPIClient';\n\n const toString = (path: (symbol | string)[]): string => {\n return `[${stringTag}${path.length ? ' ' + path.join('.') : ''}]`;\n };\n\n const primitiveMethods = {\n [Symbol.toPrimitive](\n this: undefined,\n path: (string | symbol)[],\n hint: 'string' | 'number' | 'default'\n ): unknown {\n if (hint === 'number') return NaN;\n if (hint === 'string') return toString(path);\n return getByPath(services, path);\n },\n valueOf(this: undefined, path: (string | symbol)[]): unknown {\n return getByPath(services, path);\n },\n toJSON(this: undefined, path: (string | symbol)[]): string {\n return JSON.stringify(getByPath(services, path));\n },\n toString(this: undefined, path: (string | symbol)[]): string {\n return toString(path);\n },\n };\n\n return createRecursiveProxy(\n function getCallback(getPath, key) {\n if (Object.prototype.hasOwnProperty.call(primitiveMethods, key)) {\n return primitiveMethods[key as keyof typeof primitiveMethods].bind(\n undefined,\n getPath\n );\n } else if (key === Symbol.toStringTag) {\n return stringTag;\n }\n\n if (key !== 'schema') return;\n if (\n getPath.length !== 2 &&\n !('schema' in services) &&\n getPath.length !== 1 &&\n !(services[getPath[0] as never] as OperationsDeclaration<any>)?.schema\n )\n return;\n\n const serviceOperation = getByPath(services, getPath);\n if (!isServiceOperation(serviceOperation))\n throw new Error(`Service operation not found: ${getPath.join('.')}`);\n return serviceOperation.schema;\n },\n function applyCallback(applyPath, args) {\n const { path, callbackName } = extractCallbackDetails(\n applyPath,\n services\n );\n\n assertValidCallbackName(callbackName, callbacks);\n\n const serviceOperation = getByPath(services, path);\n\n if (!isServiceOperation(serviceOperation))\n throw new Error(`Service operation not found: ${path.join('.')}`);\n\n if (\n callbackName !== 'operationInvokeFn' &&\n callbackName !== 'getQueryKey' &&\n callbackName !== 'getMutationKey' &&\n callbackName !== 'getInfiniteQueryKey'\n )\n if (!options || !('queryClient' in options && options.queryClient))\n throw new Error(\n `'qraft.<service>.<operation>.${String(callbackName)}()' requires 'queryClient' in 'createAPIClient(...)' options.`\n );\n\n // @ts-expect-error - Too complex union type\n return callbacks[callbackName](options, serviceOperation.schema, args);\n },\n []\n ) as never;\n}\n\nfunction assertValidCallbackName<\n Callbacks extends Record<string, (...rest: any[]) => unknown>,\n>(\n callbackName: string | number | symbol,\n callbacks: Callbacks\n): asserts callbackName is keyof Callbacks {\n if (!(callbackName in callbacks)) {\n if (\n (callbackName as InvokeOperationCallback) ===\n ('operationInvokeFn' satisfies InvokeOperationCallback)\n )\n throw new Error(\n `Callback 'operationInvokeFn' is required for executing 'qraft.<service>.<operation>()', but it is not provided in the 'callbacks' object.`\n );\n throw new Error(\n `Callback for 'qraft.<service>.<operation>.${String(callbackName)}()' is not provided in the 'callbacks' object.`\n );\n }\n}\n\n/**\n * Extracts Callback details from the applyPath\n */\nfunction extractCallbackDetails(\n applyPath: (string | symbol)[],\n services: UnionServiceOperationsDeclaration<any>\n) {\n // client.<service>.<operation>() [OperationInvokeFn]\n // <service>.<operation>() [OperationInvokeFn]\n // client() [OperationInvokeFn]\n // client()\n if (\n (applyPath.length === 2 &&\n !(services[applyPath[0] as never] as OperationsDeclaration<any>)\n ?.schema) ||\n (applyPath.length === 0 && 'schema' in services)\n ) {\n return {\n path: applyPath,\n callbackName: 'operationInvokeFn' satisfies InvokeOperationCallback,\n };\n } else {\n // client.<service>.<operation>.<method>()\n // <service>.<operation>.<method>()\n // client.<method>()\n return {\n path: applyPath.slice(0, -1),\n // The last arg is for instance `.useMutation` or `.useQuery()`\n callbackName: applyPath[applyPath.length - 1],\n };\n }\n}\n\nfunction isServiceOperation(\n input: unknown\n): input is { schema: OperationSchema } {\n return input !== null && typeof input === 'object' && 'schema' in input;\n}\n\nfunction getByPath(obj: Record<string, unknown>, path: (string | symbol)[]) {\n return path.reduce<unknown>((acc, key) => {\n if (acc && typeof acc === 'object' && key in acc)\n return acc[key as keyof typeof acc];\n }, obj);\n}\n\ntype ServiceMethods = typeof callbacks;\n\ntype PartialServiceMethods = Partial<ServiceMethods>;\n\ntype OperationDeclaration = {\n schema: OperationSchema;\n [QraftServiceOperationsToken]: Partial<\n Record<\n | QueryOperationCallbacks\n | QueryOperationStateCallbacks\n | MutationOperationCallbacks\n | MutationOperationStateCallbacks\n | UtilityOperationCallbacks,\n any\n >\n > & {\n types: any;\n schema: OperationSchema;\n (...args: any[]): any;\n };\n};\n\ntype OperationsDeclaration<Operations> = {\n [operation in keyof Operations]: OperationDeclaration;\n};\n\ntype ServicesDeclaration<Services> = {\n [service in keyof Services]: OperationsDeclaration<Services[service]>;\n};\n\nexport type UnionServiceOperationsDeclaration<Services> =\n | ServicesDeclaration<Services>\n | OperationsDeclaration<Services>\n | OperationDeclaration;\n\ntype QueryOperationCallbacks = Extract<\n keyof ServiceMethods,\n | 'fetchInfiniteQuery'\n | 'fetchQuery'\n | 'prefetchInfiniteQuery'\n | 'prefetchQuery'\n | 'refetchQueries'\n | 'ensureQueryData'\n | 'ensureInfiniteQueryData'\n | 'useInfiniteQuery'\n | 'useQueries'\n | 'useQuery'\n | 'useSuspenseInfiniteQuery'\n | 'useSuspenseQueries'\n | 'useSuspenseQuery'\n>;\n\ntype QueryOperationStateCallbacks = Extract<\n keyof ServiceMethods,\n | 'cancelQueries'\n | 'getInfiniteQueryData'\n | 'getInfiniteQueryState'\n | 'getQueriesData'\n | 'getQueryData'\n | 'getQueryState'\n | 'invalidateQueries'\n | 'isFetching'\n | 'removeQueries'\n | 'resetQueries'\n | 'setInfiniteQueryData'\n | 'setQueriesData'\n | 'setQueryData'\n | 'useIsFetching'\n>;\n\ntype MutationOperationCallbacks = Extract<keyof ServiceMethods, 'useMutation'>;\n\ntype MutationOperationStateCallbacks = Extract<\n keyof ServiceMethods,\n 'isMutating' | 'useIsMutating' | 'useMutationState'\n>;\n\ntype InvokeOperationCallback = Extract<\n keyof typeof operationInvokeModule,\n 'operationInvokeFn'\n>;\n\ntype UtilityOperationCallbacks = Extract<\n keyof ServiceMethods,\n 'getQueryKey' | 'getInfiniteQueryKey' | 'getMutationKey'\n>;\n\ntype OperationCallbackList =\n | QueryOperationCallbacks\n | QueryOperationStateCallbacks\n | MutationOperationCallbacks\n | MutationOperationStateCallbacks\n | InvokeOperationCallback\n | UtilityOperationCallbacks;\n\nexport type APIQueryClientServices<\n Services extends UnionServiceOperationsDeclaration<Services>,\n Callbacks extends PartialServiceMethods,\n> = ServicesFilteredByCallbacks<\n Services,\n Extract<keyof Callbacks, OperationCallbackList>\n>;\n\nexport type APIDefaultQueryClientServices<\n Services extends UnionServiceOperationsDeclaration<Services>,\n> = Services extends OperationDeclaration\n ? Services[QraftServiceOperationsToken]\n : Services extends OperationsDeclaration<Services>\n ? {\n [operation in keyof Services]: Services[operation][QraftServiceOperationsToken];\n }\n : Services extends ServicesDeclaration<Services>\n ? {\n [service in keyof Services]: {\n [operation in keyof Services[service]]: Services[service][operation][QraftServiceOperationsToken];\n };\n }\n : never;\n\nexport type APIBasicQueryClientServices<\n Services extends UnionServiceOperationsDeclaration<Services>,\n Callbacks extends PartialServiceMethods,\n> = ServicesFilteredByCallbacks<\n Services,\n Extract<\n keyof Callbacks,\n | QueryOperationStateCallbacks\n | MutationOperationStateCallbacks\n | UtilityOperationCallbacks\n >\n>;\n\nexport type APIBasicClientServices<\n Services extends UnionServiceOperationsDeclaration<Services>,\n Callbacks extends PartialServiceMethods,\n> = ServicesFilteredByCallbacks<\n Services,\n Extract<keyof Callbacks, InvokeOperationCallback | UtilityOperationCallbacks>\n>;\n\nexport type APIUtilityClientServices<\n Services extends UnionServiceOperationsDeclaration<Services>,\n Callbacks extends Pick<PartialServiceMethods, UtilityOperationCallbacks>,\n> = ServicesFilteredByUtilityCallbacks<\n Services,\n Extract<keyof Callbacks, UtilityOperationCallbacks>\n>;\n\ntype ServicesFilteredByCallbacks<\n Services extends UnionServiceOperationsDeclaration<Services>,\n CallbackList extends OperationCallbackList,\n> = Services extends OperationDeclaration\n ? Pick<\n Services[QraftServiceOperationsToken],\n Extract<\n keyof Services[QraftServiceOperationsToken],\n CallbackList | 'schema' | 'types'\n >\n > &\n OperationInvokeFn<Services[QraftServiceOperationsToken], CallbackList>\n : Services extends OperationsDeclaration<Services>\n ? {\n [operation in keyof Services]: Pick<\n Services[operation][QraftServiceOperationsToken],\n Extract<\n keyof Services[operation][QraftServiceOperationsToken],\n CallbackList | 'schema' | 'types'\n >\n > &\n OperationInvokeFn<\n Services[operation][QraftServiceOperationsToken],\n CallbackList\n >;\n }\n : Services extends ServicesDeclaration<Services>\n ? {\n [serviceName in keyof Services]: {\n [operation in keyof Services[serviceName]]: Pick<\n Services[serviceName][operation][QraftServiceOperationsToken],\n Extract<\n keyof Services[serviceName][operation][QraftServiceOperationsToken],\n CallbackList | 'schema' | 'types'\n >\n > &\n OperationInvokeFn<\n Services[serviceName][operation][QraftServiceOperationsToken],\n CallbackList\n >;\n };\n }\n : never;\n\ntype OperationInvokeFn<\n InvokeFn extends (...args: any[]) => any,\n CallbackList extends OperationCallbackList,\n> = InvokeOperationCallback extends CallbackList\n ? InvokeFn extends (...args: infer Args) => infer Result\n ? { (...args: Args): Result }\n : Record<string, never>\n : Record<string, never>;\n\ntype ServicesFilteredByUtilityCallbacks<\n Services extends UnionServiceOperationsDeclaration<Services>,\n CallbackList extends UtilityOperationCallbacks,\n> = Services extends OperationDeclaration\n ? Pick<\n Services[QraftServiceOperationsToken],\n Extract<\n keyof Services[QraftServiceOperationsToken],\n CallbackList | 'schema' | 'types'\n >\n >\n : Services extends OperationsDeclaration<Services>\n ? {\n [operation in keyof Services]: Pick<\n Services[operation][QraftServiceOperationsToken],\n Extract<\n keyof Services[operation][QraftServiceOperationsToken],\n CallbackList | 'schema' | 'types'\n >\n >;\n }\n : Services extends ServicesDeclaration<Services>\n ? {\n [serviceName in keyof Services]: {\n [operation in keyof Services[serviceName]]: Pick<\n Services[serviceName][operation][QraftServiceOperationsToken],\n Extract<\n keyof Services[serviceName][operation][QraftServiceOperationsToken],\n CallbackList | 'schema' | 'types'\n >\n >;\n };\n }\n : never;\n"],"names":["qraftAPIClient","services","callbacks","options","stringTag","toString","path","length","join","primitiveMethods","Symbol","toPrimitive","hint","NaN","getByPath","valueOf","toJSON","JSON","stringify","createRecursiveProxy","getCallback","getPath","key","Object","prototype","hasOwnProperty","call","bind","undefined","toStringTag","schema","serviceOperation","isServiceOperation","Error","applyCallback","applyPath","args","callbackName","extractCallbackDetails","assertValidCallbackName","queryClient","String","slice","input","obj","reduce","acc"],"mappings":";;;;AAkKO,SAASA,cAIdC,CAAAA,QAAkB,EAClBC,SAAoB,EACpBC,OAAgC,EAAA;AAMhC,IAAA,MAAMC,SAAY,GAAA,gBAAA,CAAA;AAElB,IAAA,MAAMC,WAAW,CAACC,IAAAA,GAAAA;AAChB,QAAA,OAAO,CAAC,CAAC,EAAEF,SAAAA,CAAU,EAAEE,IAAKC,CAAAA,MAAM,GAAG,GAAA,GAAMD,KAAKE,IAAI,CAAC,GAAO,CAAA,GAAA,EAAA,CAAG,CAAC,CAAC,CAAA;AACnE,KAAA,CAAA;AAEA,IAAA,MAAMC,gBAAmB,GAAA;AACvB,QAAA,CAACC,OAAOC,WAAW,EAEjBL,CAAAA,IAAyB,EACz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IAAKuC,CAAAA,MAAM,CAAU,CAACC,GAAKxB,EAAAA,GAAAA,GAAAA;QAChC,IAAIwB,GAAAA,IAAO,OAAOA,GAAQ,KAAA,QAAA,IAAYxB,OAAOwB,GAC3C,EAAA,OAAOA,GAAG,CAACxB,GAAwB,CAAA,CAAA;KACpCsB,EAAAA,GAAAA,CAAAA,CAAAA;AACL;;;;"}
|
|
@@ -27,12 +27,13 @@ function qraftAPIClient(services, callbacks, options) {
|
|
|
27
27
|
} else if (key === Symbol.toStringTag) {
|
|
28
28
|
return stringTag;
|
|
29
29
|
}
|
|
30
|
-
if (
|
|
30
|
+
if (key !== 'schema') return;
|
|
31
|
+
if (getPath.length !== 2 && !('schema' in services) && getPath.length !== 1 && !services[getPath[0]]?.schema) return;
|
|
31
32
|
const serviceOperation = getByPath(services, getPath);
|
|
32
33
|
if (!isServiceOperation(serviceOperation)) throw new Error(`Service operation not found: ${getPath.join('.')}`);
|
|
33
34
|
return serviceOperation.schema;
|
|
34
35
|
}, function applyCallback(applyPath, args) {
|
|
35
|
-
const { path, callbackName } = extractCallbackDetails(applyPath);
|
|
36
|
+
const { path, callbackName } = extractCallbackDetails(applyPath, services);
|
|
36
37
|
assertValidCallbackName(callbackName, callbacks);
|
|
37
38
|
const serviceOperation = getByPath(services, path);
|
|
38
39
|
if (!isServiceOperation(serviceOperation)) throw new Error(`Service operation not found: ${path.join('.')}`);
|
|
@@ -51,16 +52,20 @@ function assertValidCallbackName(callbackName, callbacks) {
|
|
|
51
52
|
}
|
|
52
53
|
/**
|
|
53
54
|
* Extracts Callback details from the applyPath
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
// <service>.<operation>()
|
|
57
|
-
|
|
55
|
+
*/ function extractCallbackDetails(applyPath, services) {
|
|
56
|
+
// client.<service>.<operation>() [OperationInvokeFn]
|
|
57
|
+
// <service>.<operation>() [OperationInvokeFn]
|
|
58
|
+
// client() [OperationInvokeFn]
|
|
59
|
+
// client()
|
|
60
|
+
if (applyPath.length === 2 && !services[applyPath[0]]?.schema || applyPath.length === 0 && 'schema' in services) {
|
|
58
61
|
return {
|
|
59
62
|
path: applyPath,
|
|
60
63
|
callbackName: 'operationInvokeFn'
|
|
61
64
|
};
|
|
62
65
|
} else {
|
|
66
|
+
// client.<service>.<operation>.<method>()
|
|
63
67
|
// <service>.<operation>.<method>()
|
|
68
|
+
// client.<method>()
|
|
64
69
|
return {
|
|
65
70
|
path: applyPath.slice(0, -1),
|
|
66
71
|
// The last arg is for instance `.useMutation` or `.useQuery()`
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"qraftAPIClient.js","sources":["../../src/qraftAPIClient.ts"],"sourcesContent":["import type {\n ServiceOperationMutation,\n ServiceOperationMutationFn,\n ServiceOperationQuery,\n ServiceOperationQueryFn,\n} from '@openapi-qraft/tanstack-query-react-types';\nimport type { QueryClient } from '@tanstack/query-core';\nimport type * as callbacks from './callbacks/index.js';\nimport type * as operationInvokeModule from './callbacks/operationInvokeFn.js';\nimport type {\n OperationSchema,\n RequestFnInfo,\n RequestFnResponse,\n} from './lib/requestFn.js';\nimport { createRecursiveProxy } from './lib/createRecursiveProxy.js';\n\nexport interface CreateAPIBasicClientOptions {\n requestFn<TData, TError>(\n schema: OperationSchema,\n requestInfo: RequestFnInfo\n ): Promise<RequestFnResponse<TData, TError>>;\n baseUrl: string;\n}\n\nexport interface CreateAPIBasicQueryClientOptions {\n queryClient: QueryClient;\n}\n\nexport interface CreateAPIQueryClientOptions\n extends CreateAPIBasicClientOptions,\n CreateAPIBasicQueryClientOptions {}\n\n/**\n * @deprecated use `CreateAPIClientOptions` instead\n */\nexport type QraftClientOptions =\n | CreateAPIBasicClientOptions\n | CreateAPIQueryClientOptions;\n\nexport type CreateAPIClientOptions =\n | CreateAPIBasicClientOptions\n | CreateAPIBasicQueryClientOptions\n | CreateAPIQueryClientOptions;\n\nexport function qraftAPIClient<\n Services extends ServicesDeclaration<Services>,\n TCallbacks extends Callbacks,\n>(\n services: ServiceSchemasDeclaration<Services>,\n callbacks: TCallbacks,\n options: CreateAPIBasicClientOptions\n): APIBasicClientServices<Services, TCallbacks>;\n\nexport function qraftAPIClient<\n Services extends ServicesDeclaration<Services>,\n TCallbacks extends Required<Callbacks>,\n>(\n services: ServiceSchemasDeclaration<Services>,\n callbacks: TCallbacks,\n options: CreateAPIQueryClientOptions\n): Services;\n\nexport function qraftAPIClient<\n Services extends ServicesDeclaration<Services>,\n TCallbacks extends Callbacks,\n>(\n services: ServiceSchemasDeclaration<Services>,\n callbacks: TCallbacks,\n options: CreateAPIBasicQueryClientOptions\n): APIBasicQueryClientServices<Services, TCallbacks>;\n\nexport function qraftAPIClient<\n Services extends ServicesDeclaration<Services>,\n TCallbacks extends Callbacks,\n>(\n services: ServiceSchemasDeclaration<Services>,\n callbacks: TCallbacks,\n options: CreateAPIQueryClientOptions\n): APIQueryClientServices<Services, TCallbacks>;\n\nexport function qraftAPIClient<\n Services extends ServicesDeclaration<Services>,\n TCallbacks extends Callbacks,\n>(\n services: ServiceSchemasDeclaration<Services>,\n callbacks: TCallbacks\n): APIUtilityClientServices<Services, TCallbacks>;\n\nexport function qraftAPIClient<\n Services extends ServicesDeclaration<Services>,\n TCallbacks extends Callbacks,\n>(\n services: ServiceSchemasDeclaration<Services>,\n callbacks: TCallbacks,\n options?: CreateAPIClientOptions\n): APIQueryClientServices<Services, TCallbacks> | Services {\n const stringTag = 'QraftAPIClient';\n\n const toString = (path: (symbol | string)[]): string => {\n return `[${stringTag}${path.length ? ' ' + path.join('.') : ''}]`;\n };\n\n const primitiveMethods = {\n [Symbol.toPrimitive](\n this: undefined,\n path: (string | symbol)[],\n hint: 'string' | 'number' | 'default'\n ): unknown {\n if (hint === 'number') return NaN;\n if (hint === 'string') return toString(path);\n return getByPath(services, path);\n },\n valueOf(this: undefined, path: (string | symbol)[]): unknown {\n return getByPath(services, path);\n },\n toJSON(this: undefined, path: (string | symbol)[]): string {\n return JSON.stringify(getByPath(services, path));\n },\n toString(this: undefined, path: (string | symbol)[]): string {\n return toString(path);\n },\n };\n\n return createRecursiveProxy(\n function getCallback(getPath, key) {\n if (Object.prototype.hasOwnProperty.call(primitiveMethods, key)) {\n return primitiveMethods[key as keyof typeof primitiveMethods].bind(\n undefined,\n getPath\n );\n } else if (key === Symbol.toStringTag) {\n return stringTag;\n }\n\n if (getPath.length !== 2 || key !== 'schema') return; // todo::maybe return callback?\n\n const serviceOperation = getByPath(services, getPath);\n if (!isServiceOperation(serviceOperation))\n throw new Error(`Service operation not found: ${getPath.join('.')}`);\n return serviceOperation.schema;\n },\n function applyCallback(applyPath, args) {\n const { path, callbackName } = extractCallbackDetails(applyPath);\n\n assertValidCallbackName(callbackName, callbacks);\n\n const serviceOperation = getByPath(services, path);\n\n if (!isServiceOperation(serviceOperation))\n throw new Error(`Service operation not found: ${path.join('.')}`);\n\n if (\n callbackName !== 'operationInvokeFn' &&\n callbackName !== 'getQueryKey' &&\n callbackName !== 'getMutationKey' &&\n callbackName !== 'getInfiniteQueryKey'\n )\n if (!options || !('queryClient' in options && options.queryClient))\n throw new Error(\n `'qraft.<service>.<operation>.${String(callbackName)}()' requires 'queryClient' in 'createAPIClient(...)' options.`\n );\n\n // @ts-expect-error - Too complex union type\n return callbacks[callbackName](options, serviceOperation.schema, args);\n },\n []\n ) as never;\n}\n\nfunction assertValidCallbackName<\n TCallbacks extends Record<string, (...rest: any[]) => unknown>,\n>(\n callbackName: string | number | symbol,\n callbacks: TCallbacks\n): asserts callbackName is keyof TCallbacks {\n if (!(callbackName in callbacks)) {\n if ((callbackName as OperationInvokeFnName) === 'operationInvokeFn')\n throw new Error(\n `Callback 'operationInvokeFn' is required for executing 'qraft.<service>.<operation>()', but it is not provided in the 'callbacks' object.`\n );\n throw new Error(\n `Callback for 'qraft.<service>.<operation>.${String(callbackName)}()' is not provided in the 'callbacks' object.`\n );\n }\n}\n\n/**\n * Extracts Callback details from the applyPath\n * @param applyPath\n */\nfunction extractCallbackDetails(applyPath: (string | symbol)[]) {\n // <service>.<operation>()\n if (applyPath.length === 2) {\n return {\n path: applyPath,\n callbackName: 'operationInvokeFn' satisfies OperationInvokeFnName,\n };\n } else {\n // <service>.<operation>.<method>()\n return {\n path: applyPath.slice(0, -1),\n // The last arg is for instance `.useMutation` or `.useQuery()`\n callbackName: applyPath[applyPath.length - 1],\n };\n }\n}\n\nfunction isServiceOperation(\n input: unknown\n): input is { schema: OperationSchema } {\n return input !== null && typeof input === 'object' && 'schema' in input;\n}\n\nfunction getByPath(obj: Record<string, unknown>, path: (string | symbol)[]) {\n return path.reduce<unknown>((acc, key) => {\n if (acc && typeof acc === 'object' && key in acc)\n return acc[key as keyof typeof acc];\n }, obj);\n}\n\ntype Callbacks = Partial<typeof callbacks>;\n\ntype ServicesDeclaration<Services> = {\n [service in keyof Services]: {\n [method in keyof Services[service]]: {\n schema: OperationSchema;\n types: {\n parameters?: any;\n data?: any;\n error?: any;\n body?: any;\n };\n };\n };\n};\n\ntype ServiceSchemasDeclaration<Services extends ServicesDeclaration<Services>> =\n {\n [service in keyof Services]: {\n [method in keyof Services[service]]: {\n schema: Services[service][method]['schema'];\n };\n };\n };\n\ntype QueryOperationCallbacks = Extract<\n keyof Callbacks,\n | 'cancelQueries'\n | 'fetchInfiniteQuery'\n | 'fetchQuery'\n | 'getInfiniteQueryData'\n | 'getInfiniteQueryKey'\n | 'getInfiniteQueryState'\n | 'getQueriesData'\n | 'getQueryData'\n | 'getQueryKey'\n | 'getQueryState'\n | 'invalidateQueries'\n | 'isFetching'\n | 'prefetchInfiniteQuery'\n | 'prefetchQuery'\n | 'refetchQueries'\n | 'ensureQueryData'\n | 'ensureInfiniteQueryData'\n | 'removeQueries'\n | 'resetQueries'\n | 'setInfiniteQueryData'\n | 'setQueriesData'\n | 'setQueryData'\n | 'useInfiniteQuery'\n | 'useIsFetching'\n | 'useQueries'\n | 'useQuery'\n | 'useSuspenseInfiniteQuery'\n | 'useSuspenseQueries'\n | 'useSuspenseQuery'\n>;\n\ntype MutationOperationCallbacks = Extract<\n keyof Callbacks,\n | 'getMutationKey'\n | 'isMutating'\n | 'useIsMutating'\n | 'useMutation'\n | 'useMutationState'\n>;\n\nexport type APIQueryClientServices<\n TServices extends ServicesDeclaration<TServices>,\n TCallbacks extends Callbacks,\n> = ServicesFilteredByCallbacks<\n TServices,\n TCallbacks,\n QueryOperationCallbacks,\n MutationOperationCallbacks\n>;\n\nexport type APIBasicQueryClientServices<\n TServices extends ServicesDeclaration<TServices>,\n TCallbacks extends Callbacks,\n> = ServicesFilteredByCallbacks<\n TServices,\n Omit<TCallbacks, 'operationInvokeFn'>,\n Extract<\n QueryOperationCallbacks,\n | 'resetQueries'\n | 'removeQueries'\n | 'cancelQueries'\n | 'invalidateQueries'\n | 'refetchQueries'\n | 'getQueryKey'\n | 'getInfiniteQueryState'\n | 'getInfiniteQueryData'\n | 'getInfiniteQueryKey'\n | 'setInfiniteQueryData'\n | 'getQueriesData'\n | 'setQueriesData'\n | 'getQueryState'\n | 'getQueryData'\n | 'setQueryData'\n | 'useIsFetching'\n | 'isFetching'\n >,\n Extract<\n MutationOperationCallbacks,\n 'getMutationKey' | 'useMutationState' | 'useIsMutating' | 'isMutating'\n >\n>;\n\nexport type APIUtilityClientServices<\n TServices extends ServicesDeclaration<TServices>,\n TCallbacks extends Callbacks,\n> = ServicesFilteredByCallbacks<\n TServices,\n Omit<TCallbacks, 'operationInvokeFn'>,\n Extract<QueryOperationCallbacks, 'getQueryKey' | 'getInfiniteQueryKey'>,\n Extract<MutationOperationCallbacks, 'getMutationKey'>\n>;\n\nexport type APIBasicClientServices<\n TServices extends ServicesDeclaration<TServices>,\n TCallbacks extends Callbacks,\n> = ServicesFilteredByCallbacks<\n TServices,\n TCallbacks,\n Extract<QueryOperationCallbacks, 'getQueryKey' | 'getInfiniteQueryKey'>,\n Extract<MutationOperationCallbacks, 'getMutationKey'>\n>;\n\ntype ServicesFilteredByCallbacks<\n TServices extends ServicesDeclaration<TServices>,\n TCallbacks extends Callbacks,\n TQueryOperationCallbacks extends QueryOperationCallbacks,\n TMutationOperationCallbacks extends MutationOperationCallbacks,\n> = {\n [serviceName in keyof TServices]: {\n [method in keyof TServices[serviceName]]: TServices[serviceName][method]['schema']['method'] extends\n | 'get'\n | 'head'\n | 'options'\n ? Pick<\n ServiceOperationQuery<\n TServices[serviceName][method]['schema'],\n TServices[serviceName][method]['types']['data'],\n TServices[serviceName][method]['types']['parameters'],\n TServices[serviceName][method]['types']['error']\n >,\n | Extract<keyof TCallbacks, TQueryOperationCallbacks>\n | 'types'\n | 'schema'\n > &\n (OperationInvokeFnName extends keyof TCallbacks\n ? ServiceOperationQueryFn<\n TServices[serviceName][method]['schema'],\n TServices[serviceName][method]['types']['data'],\n TServices[serviceName][method]['types']['parameters'],\n TServices[serviceName][method]['types']['error']\n >\n : {})\n : Pick<\n ServiceOperationMutation<\n TServices[serviceName][method]['schema'],\n TServices[serviceName][method]['types']['body'],\n TServices[serviceName][method]['types']['data'],\n TServices[serviceName][method]['types']['parameters'],\n TServices[serviceName][method]['types']['error']\n >,\n | Extract<keyof TCallbacks, TMutationOperationCallbacks>\n | 'types'\n | 'schema'\n > &\n (OperationInvokeFnName extends keyof TCallbacks\n ? ServiceOperationMutationFn<\n TServices[serviceName][method]['schema'],\n TServices[serviceName][method]['types']['body'],\n TServices[serviceName][method]['types']['data'],\n TServices[serviceName][method]['types']['parameters'],\n TServices[serviceName][method]['types']['error']\n >\n : {});\n };\n};\n\ntype OperationInvokeFnName = Extract<\n keyof typeof operationInvokeModule,\n 'operationInvokeFn'\n>;\n"],"names":["qraftAPIClient","services","callbacks","options","stringTag","toString","path","length","join","primitiveMethods","Symbol","toPrimitive","hint","NaN","getByPath","valueOf","toJSON","JSON","stringify","createRecursiveProxy","getCallback","getPath","key","Object","prototype","hasOwnProperty","call","bind","undefined","toStringTag","serviceOperation","isServiceOperation","Error","schema","applyCallback","applyPath","args","callbackName","extractCallbackDetails","assertValidCallbackName","queryClient","String","slice","input","obj","reduce","acc"],"mappings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E,CAAA;AAEA,SAAS7B,SAAAA,CAAU8B,GAA4B,EAAEtC,IAAyB,EAAA;AACxE,IAAA,OAAOA,IAAKuC,CAAAA,MAAM,CAAU,CAACC,GAAKxB,EAAAA,GAAAA,GAAAA;QAChC,IAAIwB,GAAAA,IAAO,OAAOA,GAAQ,KAAA,QAAA,IAAYxB,OAAOwB,GAC3C,EAAA,OAAOA,GAAG,CAACxB,GAAwB,CAAA,CAAA;KACpCsB,EAAAA,GAAAA,CAAAA,CAAAA;AACL;;;;"}
|
|
1
|
+
{"version":3,"file":"qraftAPIClient.js","sources":["../../src/qraftAPIClient.ts"],"sourcesContent":["import type { QraftServiceOperationsToken } from '@openapi-qraft/tanstack-query-react-types';\nimport type { QueryClient } from '@tanstack/query-core';\nimport type * as callbacks from './callbacks/index.js';\nimport type * as operationInvokeModule from './callbacks/operationInvokeFn.js';\nimport type {\n OperationSchema,\n RequestFnInfo,\n RequestFnResponse,\n} from './lib/requestFn.js';\nimport { createRecursiveProxy } from './lib/createRecursiveProxy.js';\n\nexport interface CreateAPIBasicClientOptions {\n requestFn<TData, TError>(\n schema: OperationSchema,\n requestInfo: RequestFnInfo\n ): Promise<RequestFnResponse<TData, TError>>;\n baseUrl: string;\n}\n\nexport interface CreateAPIBasicQueryClientOptions {\n queryClient: QueryClient;\n}\n\nexport interface CreateAPIQueryClientOptions\n extends CreateAPIBasicClientOptions,\n CreateAPIBasicQueryClientOptions {}\n\n/**\n * @deprecated use `CreateAPIClientOptions` instead\n */\nexport type QraftClientOptions =\n | CreateAPIBasicClientOptions\n | CreateAPIQueryClientOptions;\n\nexport type CreateAPIClientOptions =\n | CreateAPIBasicClientOptions\n | CreateAPIBasicQueryClientOptions\n | CreateAPIQueryClientOptions;\n\n/**\n * Creates a QueryClient compatible API Client which contains all operations\n * such as `useQuery`, `useMutation`.\n *\n * @example Fetching data with QueryClient\n * ```ts\n * const api = qraftAPIClient(services, callbacks, {\n * requestFn: requestFn,\n * baseUrl: 'https://api.example.com',\n * queryClient: new QueryClient(),\n * });\n *\n * api.service.operation({\n * parameters: { path: { id: 1 } },\n * });\n * ```\n */\nexport function qraftAPIClient<\n Services extends UnionServiceOperationsDeclaration<Services>,\n Callbacks extends ServiceMethods,\n>(\n services: Services,\n callbacks: Callbacks,\n options: CreateAPIQueryClientOptions\n): APIDefaultQueryClientServices<Services>;\n\n/**\n * Creates a QueryClient compatible API Client which contains all operations\n * such as `useQuery`, `useMutation`.\n *\n * @example Fetching data with QueryClient\n * ```ts\n * const api = qraftAPIClient(services, callbacks, {\n * requestFn: requestFn,\n * baseUrl: 'https://api.example.com',\n * queryClient: new QueryClient(),\n * });\n *\n * api.service.operation({\n * parameters: { path: { id: 1 } },\n * });\n * ```\n */\nexport function qraftAPIClient<\n Services extends UnionServiceOperationsDeclaration<Services>,\n Callbacks extends PartialServiceMethods,\n>(\n services: Services,\n callbacks: Callbacks,\n options: CreateAPIQueryClientOptions\n): APIQueryClientServices<Services, Callbacks>;\n\n/**\n * Creates a QueryClient compatible API Client which contains\n * only state management manipulations such as `useIsMutating`,\n * `setQueryData`, `getQueryData` and `invalidateQueries`.\n *\n * @example Invalidating queries with QueryClient\n * ```ts\n * const api = qraftAPIClient(services, callbacks, {\n * // an instance of QueryClient shared between all clients\n * queryClient: sharedQueryClient\n * });\n *\n * api.service.operation.invalidateQueries({\n * parameters: { path: { id: 1 } },\n * });\n */\nexport function qraftAPIClient<\n Services extends UnionServiceOperationsDeclaration<Services>,\n Callbacks extends PartialServiceMethods,\n>(\n services: Services,\n callbacks: Callbacks,\n options: CreateAPIBasicQueryClientOptions\n): APIBasicQueryClientServices<Services, Callbacks>;\n\n/**\n * Creates a basic API Client which contains only \"fetch\" like\n * operations without any state management using QueryClient.\n *\n * @example Fetching data without QueryClient\n * ```ts\n * const api = qraftAPIClient(services, callbacks, {\n * requestFn: requestFn,\n * baseUrl: 'https://api.example.com',\n * });\n *\n * api.service.operation({\n * parameters: { path: { id: 1 } },\n * });\n * ```\n */\nexport function qraftAPIClient<\n Services extends UnionServiceOperationsDeclaration<Services>,\n Callbacks extends PartialServiceMethods,\n>(\n services: Services,\n callbacks: Callbacks,\n options: CreateAPIBasicClientOptions\n): APIBasicClientServices<Services, Callbacks>;\n\n/**\n * Creates a utility API Client which contains only utility operations\n * such as `getQueryKey`, `getInfiniteQueryKey` and `getMutationKey`.\n *\n * @example Getting query keys with utility client\n * ```ts\n * const api = qraftAPIClient(services, callbacks);\n *\n * api.service.operation.getQueryKey({\n * parameters: { path: { id: 1 } },\n * });\n * ```\n */\nexport function qraftAPIClient<\n Services extends UnionServiceOperationsDeclaration<Services>,\n Callbacks extends Pick<PartialServiceMethods, UtilityOperationCallbacks>,\n>(\n services: Services,\n callbacks: Callbacks\n): APIUtilityClientServices<Services, Callbacks>;\n\nexport function qraftAPIClient<\n Services extends UnionServiceOperationsDeclaration<Services>,\n Callbacks extends PartialServiceMethods,\n>(\n services: Services,\n callbacks: Callbacks,\n options?: CreateAPIClientOptions\n):\n | APIQueryClientServices<Services, Callbacks>\n | APIDefaultQueryClientServices<Services>\n | APIBasicQueryClientServices<Services, Callbacks>\n | APIUtilityClientServices<Services, Callbacks> {\n const stringTag = 'QraftAPIClient';\n\n const toString = (path: (symbol | string)[]): string => {\n return `[${stringTag}${path.length ? ' ' + path.join('.') : ''}]`;\n };\n\n const primitiveMethods = {\n [Symbol.toPrimitive](\n this: undefined,\n path: (string | symbol)[],\n hint: 'string' | 'number' | 'default'\n ): unknown {\n if (hint === 'number') return NaN;\n if (hint === 'string') return toString(path);\n return getByPath(services, path);\n },\n valueOf(this: undefined, path: (string | symbol)[]): unknown {\n return getByPath(services, path);\n },\n toJSON(this: undefined, path: (string | symbol)[]): string {\n return JSON.stringify(getByPath(services, path));\n },\n toString(this: undefined, path: (string | symbol)[]): string {\n return toString(path);\n },\n };\n\n return createRecursiveProxy(\n function getCallback(getPath, key) {\n if (Object.prototype.hasOwnProperty.call(primitiveMethods, key)) {\n return primitiveMethods[key as keyof typeof primitiveMethods].bind(\n undefined,\n getPath\n );\n } else if (key === Symbol.toStringTag) {\n return stringTag;\n }\n\n if (key !== 'schema') return;\n if (\n getPath.length !== 2 &&\n !('schema' in services) &&\n getPath.length !== 1 &&\n !(services[getPath[0] as never] as OperationsDeclaration<any>)?.schema\n )\n return;\n\n const serviceOperation = getByPath(services, getPath);\n if (!isServiceOperation(serviceOperation))\n throw new Error(`Service operation not found: ${getPath.join('.')}`);\n return serviceOperation.schema;\n },\n function applyCallback(applyPath, args) {\n const { path, callbackName } = extractCallbackDetails(\n applyPath,\n services\n );\n\n assertValidCallbackName(callbackName, callbacks);\n\n const serviceOperation = getByPath(services, path);\n\n if (!isServiceOperation(serviceOperation))\n throw new Error(`Service operation not found: ${path.join('.')}`);\n\n if (\n callbackName !== 'operationInvokeFn' &&\n callbackName !== 'getQueryKey' &&\n callbackName !== 'getMutationKey' &&\n callbackName !== 'getInfiniteQueryKey'\n )\n if (!options || !('queryClient' in options && options.queryClient))\n throw new Error(\n `'qraft.<service>.<operation>.${String(callbackName)}()' requires 'queryClient' in 'createAPIClient(...)' options.`\n );\n\n // @ts-expect-error - Too complex union type\n return callbacks[callbackName](options, serviceOperation.schema, args);\n },\n []\n ) as never;\n}\n\nfunction assertValidCallbackName<\n Callbacks extends Record<string, (...rest: any[]) => unknown>,\n>(\n callbackName: string | number | symbol,\n callbacks: Callbacks\n): asserts callbackName is keyof Callbacks {\n if (!(callbackName in callbacks)) {\n if (\n (callbackName as InvokeOperationCallback) ===\n ('operationInvokeFn' satisfies InvokeOperationCallback)\n )\n throw new Error(\n `Callback 'operationInvokeFn' is required for executing 'qraft.<service>.<operation>()', but it is not provided in the 'callbacks' object.`\n );\n throw new Error(\n `Callback for 'qraft.<service>.<operation>.${String(callbackName)}()' is not provided in the 'callbacks' object.`\n );\n }\n}\n\n/**\n * Extracts Callback details from the applyPath\n */\nfunction extractCallbackDetails(\n applyPath: (string | symbol)[],\n services: UnionServiceOperationsDeclaration<any>\n) {\n // client.<service>.<operation>() [OperationInvokeFn]\n // <service>.<operation>() [OperationInvokeFn]\n // client() [OperationInvokeFn]\n // client()\n if (\n (applyPath.length === 2 &&\n !(services[applyPath[0] as never] as OperationsDeclaration<any>)\n ?.schema) ||\n (applyPath.length === 0 && 'schema' in services)\n ) {\n return {\n path: applyPath,\n callbackName: 'operationInvokeFn' satisfies InvokeOperationCallback,\n };\n } else {\n // client.<service>.<operation>.<method>()\n // <service>.<operation>.<method>()\n // client.<method>()\n return {\n path: applyPath.slice(0, -1),\n // The last arg is for instance `.useMutation` or `.useQuery()`\n callbackName: applyPath[applyPath.length - 1],\n };\n }\n}\n\nfunction isServiceOperation(\n input: unknown\n): input is { schema: OperationSchema } {\n return input !== null && typeof input === 'object' && 'schema' in input;\n}\n\nfunction getByPath(obj: Record<string, unknown>, path: (string | symbol)[]) {\n return path.reduce<unknown>((acc, key) => {\n if (acc && typeof acc === 'object' && key in acc)\n return acc[key as keyof typeof acc];\n }, obj);\n}\n\ntype ServiceMethods = typeof callbacks;\n\ntype PartialServiceMethods = Partial<ServiceMethods>;\n\ntype OperationDeclaration = {\n schema: OperationSchema;\n [QraftServiceOperationsToken]: Partial<\n Record<\n | QueryOperationCallbacks\n | QueryOperationStateCallbacks\n | MutationOperationCallbacks\n | MutationOperationStateCallbacks\n | UtilityOperationCallbacks,\n any\n >\n > & {\n types: any;\n schema: OperationSchema;\n (...args: any[]): any;\n };\n};\n\ntype OperationsDeclaration<Operations> = {\n [operation in keyof Operations]: OperationDeclaration;\n};\n\ntype ServicesDeclaration<Services> = {\n [service in keyof Services]: OperationsDeclaration<Services[service]>;\n};\n\nexport type UnionServiceOperationsDeclaration<Services> =\n | ServicesDeclaration<Services>\n | OperationsDeclaration<Services>\n | OperationDeclaration;\n\ntype QueryOperationCallbacks = Extract<\n keyof ServiceMethods,\n | 'fetchInfiniteQuery'\n | 'fetchQuery'\n | 'prefetchInfiniteQuery'\n | 'prefetchQuery'\n | 'refetchQueries'\n | 'ensureQueryData'\n | 'ensureInfiniteQueryData'\n | 'useInfiniteQuery'\n | 'useQueries'\n | 'useQuery'\n | 'useSuspenseInfiniteQuery'\n | 'useSuspenseQueries'\n | 'useSuspenseQuery'\n>;\n\ntype QueryOperationStateCallbacks = Extract<\n keyof ServiceMethods,\n | 'cancelQueries'\n | 'getInfiniteQueryData'\n | 'getInfiniteQueryState'\n | 'getQueriesData'\n | 'getQueryData'\n | 'getQueryState'\n | 'invalidateQueries'\n | 'isFetching'\n | 'removeQueries'\n | 'resetQueries'\n | 'setInfiniteQueryData'\n | 'setQueriesData'\n | 'setQueryData'\n | 'useIsFetching'\n>;\n\ntype MutationOperationCallbacks = Extract<keyof ServiceMethods, 'useMutation'>;\n\ntype MutationOperationStateCallbacks = Extract<\n keyof ServiceMethods,\n 'isMutating' | 'useIsMutating' | 'useMutationState'\n>;\n\ntype InvokeOperationCallback = Extract<\n keyof typeof operationInvokeModule,\n 'operationInvokeFn'\n>;\n\ntype UtilityOperationCallbacks = Extract<\n keyof ServiceMethods,\n 'getQueryKey' | 'getInfiniteQueryKey' | 'getMutationKey'\n>;\n\ntype OperationCallbackList =\n | QueryOperationCallbacks\n | QueryOperationStateCallbacks\n | MutationOperationCallbacks\n | MutationOperationStateCallbacks\n | InvokeOperationCallback\n | UtilityOperationCallbacks;\n\nexport type APIQueryClientServices<\n Services extends UnionServiceOperationsDeclaration<Services>,\n Callbacks extends PartialServiceMethods,\n> = ServicesFilteredByCallbacks<\n Services,\n Extract<keyof Callbacks, OperationCallbackList>\n>;\n\nexport type APIDefaultQueryClientServices<\n Services extends UnionServiceOperationsDeclaration<Services>,\n> = Services extends OperationDeclaration\n ? Services[QraftServiceOperationsToken]\n : Services extends OperationsDeclaration<Services>\n ? {\n [operation in keyof Services]: Services[operation][QraftServiceOperationsToken];\n }\n : Services extends ServicesDeclaration<Services>\n ? {\n [service in keyof Services]: {\n [operation in keyof Services[service]]: Services[service][operation][QraftServiceOperationsToken];\n };\n }\n : never;\n\nexport type APIBasicQueryClientServices<\n Services extends UnionServiceOperationsDeclaration<Services>,\n Callbacks extends PartialServiceMethods,\n> = ServicesFilteredByCallbacks<\n Services,\n Extract<\n keyof Callbacks,\n | QueryOperationStateCallbacks\n | MutationOperationStateCallbacks\n | UtilityOperationCallbacks\n >\n>;\n\nexport type APIBasicClientServices<\n Services extends UnionServiceOperationsDeclaration<Services>,\n Callbacks extends PartialServiceMethods,\n> = ServicesFilteredByCallbacks<\n Services,\n Extract<keyof Callbacks, InvokeOperationCallback | UtilityOperationCallbacks>\n>;\n\nexport type APIUtilityClientServices<\n Services extends UnionServiceOperationsDeclaration<Services>,\n Callbacks extends Pick<PartialServiceMethods, UtilityOperationCallbacks>,\n> = ServicesFilteredByUtilityCallbacks<\n Services,\n Extract<keyof Callbacks, UtilityOperationCallbacks>\n>;\n\ntype ServicesFilteredByCallbacks<\n Services extends UnionServiceOperationsDeclaration<Services>,\n CallbackList extends OperationCallbackList,\n> = Services extends OperationDeclaration\n ? Pick<\n Services[QraftServiceOperationsToken],\n Extract<\n keyof Services[QraftServiceOperationsToken],\n CallbackList | 'schema' | 'types'\n >\n > &\n OperationInvokeFn<Services[QraftServiceOperationsToken], CallbackList>\n : Services extends OperationsDeclaration<Services>\n ? {\n [operation in keyof Services]: Pick<\n Services[operation][QraftServiceOperationsToken],\n Extract<\n keyof Services[operation][QraftServiceOperationsToken],\n CallbackList | 'schema' | 'types'\n >\n > &\n OperationInvokeFn<\n Services[operation][QraftServiceOperationsToken],\n CallbackList\n >;\n }\n : Services extends ServicesDeclaration<Services>\n ? {\n [serviceName in keyof Services]: {\n [operation in keyof Services[serviceName]]: Pick<\n Services[serviceName][operation][QraftServiceOperationsToken],\n Extract<\n keyof Services[serviceName][operation][QraftServiceOperationsToken],\n CallbackList | 'schema' | 'types'\n >\n > &\n OperationInvokeFn<\n Services[serviceName][operation][QraftServiceOperationsToken],\n CallbackList\n >;\n };\n }\n : never;\n\ntype OperationInvokeFn<\n InvokeFn extends (...args: any[]) => any,\n CallbackList extends OperationCallbackList,\n> = InvokeOperationCallback extends CallbackList\n ? InvokeFn extends (...args: infer Args) => infer Result\n ? { (...args: Args): Result }\n : Record<string, never>\n : Record<string, never>;\n\ntype ServicesFilteredByUtilityCallbacks<\n Services extends UnionServiceOperationsDeclaration<Services>,\n CallbackList extends UtilityOperationCallbacks,\n> = Services extends OperationDeclaration\n ? Pick<\n Services[QraftServiceOperationsToken],\n Extract<\n keyof Services[QraftServiceOperationsToken],\n CallbackList | 'schema' | 'types'\n >\n >\n : Services extends OperationsDeclaration<Services>\n ? {\n [operation in keyof Services]: Pick<\n Services[operation][QraftServiceOperationsToken],\n Extract<\n keyof Services[operation][QraftServiceOperationsToken],\n CallbackList | 'schema' | 'types'\n >\n >;\n }\n : Services extends ServicesDeclaration<Services>\n ? {\n [serviceName in keyof Services]: {\n [operation in keyof Services[serviceName]]: Pick<\n Services[serviceName][operation][QraftServiceOperationsToken],\n Extract<\n keyof Services[serviceName][operation][QraftServiceOperationsToken],\n CallbackList | 'schema' | 'types'\n >\n >;\n };\n }\n : never;\n"],"names":["qraftAPIClient","services","callbacks","options","stringTag","toString","path","length","join","primitiveMethods","Symbol","toPrimitive","hint","NaN","getByPath","valueOf","toJSON","JSON","stringify","createRecursiveProxy","getCallback","getPath","key","Object","prototype","hasOwnProperty","call","bind","undefined","toStringTag","schema","serviceOperation","isServiceOperation","Error","applyCallback","applyPath","args","callbackName","extractCallbackDetails","assertValidCallbackName","queryClient","String","slice","input","obj","reduce","acc"],"mappings":";;AAkKO,SAASA,cAIdC,CAAAA,QAAkB,EAClBC,SAAoB,EACpBC,OAAgC,EAAA;AAMhC,IAAA,MAAMC,SAAY,GAAA,gBAAA,CAAA;AAElB,IAAA,MAAMC,WAAW,CAACC,IAAAA,GAAAA;AAChB,QAAA,OAAO,CAAC,CAAC,EAAEF,SAAAA,CAAU,EAAEE,IAAKC,CAAAA,MAAM,GAAG,GAAA,GAAMD,KAAKE,IAAI,CAAC,GAAO,CAAA,GAAA,EAAA,CAA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AAU,YAAY,QAAYA,IAAAA,KAAAA,CAAAA;AACpE,CAAA;AAEA,SAAS7B,SAAAA,CAAU8B,GAA4B,EAAEtC,IAAyB,EAAA;AACxE,IAAA,OAAOA,IAAKuC,CAAAA,MAAM,CAAU,CAACC,GAAKxB,EAAAA,GAAAA,GAAAA;QAChC,IAAIwB,GAAAA,IAAO,OAAOA,GAAQ,KAAA,QAAA,IAAYxB,OAAOwB,GAC3C,EAAA,OAAOA,GAAG,CAACxB,GAAwB,CAAA,CAAA;KACpCsB,EAAAA,GAAAA,CAAAA,CAAAA;AACL;;;;"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { qraftAPIClient, type CreateAPIClientOptions, type CreateAPIBasicQueryClientOptions, type CreateAPIBasicClientOptions, type CreateAPIQueryClientOptions, type APIQueryClientServices, type APIBasicQueryClientServices, type APIBasicClientServices, type APIUtilityClientServices, type QraftClientOptions, } from './qraftAPIClient.js';
|
|
1
|
+
export { qraftAPIClient, type CreateAPIClientOptions, type CreateAPIBasicQueryClientOptions, type CreateAPIBasicClientOptions, type CreateAPIQueryClientOptions, type APIQueryClientServices, type APIDefaultQueryClientServices, type APIBasicQueryClientServices, type APIBasicClientServices, type APIUtilityClientServices, type UnionServiceOperationsDeclaration, type QraftClientOptions, } from './qraftAPIClient.js';
|
|
2
2
|
export { requestFn, baseRequestFn, urlSerializer, bodySerializer, mergeHeaders, type RequestFn, type RequestFnResponse, type HeadersOptions, type RequestFnOptions, type RequestFnInfo, type OperationSchema, type RequestFnPayload, } from './lib/requestFn.js';
|
|
3
3
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,KAAK,sBAAsB,EAC3B,KAAK,gCAAgC,EACrC,KAAK,2BAA2B,EAChC,KAAK,2BAA2B,EAChC,KAAK,sBAAsB,EAC3B,KAAK,2BAA2B,EAChC,KAAK,sBAAsB,EAC3B,KAAK,wBAAwB,EAC7B,KAAK,kBAAkB,GACxB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,SAAS,EACT,aAAa,EACb,aAAa,EACb,cAAc,EACd,YAAY,EACZ,KAAK,SAAS,EACd,KAAK,iBAAiB,EACtB,KAAK,cAAc,EACnB,KAAK,gBAAgB,EACrB,KAAK,aAAa,EAClB,KAAK,eAAe,EACpB,KAAK,gBAAgB,GACtB,MAAM,oBAAoB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,KAAK,sBAAsB,EAC3B,KAAK,gCAAgC,EACrC,KAAK,2BAA2B,EAChC,KAAK,2BAA2B,EAChC,KAAK,sBAAsB,EAC3B,KAAK,6BAA6B,EAClC,KAAK,2BAA2B,EAChC,KAAK,sBAAsB,EAC3B,KAAK,wBAAwB,EAC7B,KAAK,iCAAiC,EACtC,KAAK,kBAAkB,GACxB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,SAAS,EACT,aAAa,EACb,aAAa,EACb,cAAc,EACd,YAAY,EACZ,KAAK,SAAS,EACd,KAAK,iBAAiB,EACtB,KAAK,cAAc,EACnB,KAAK,gBAAgB,EACrB,KAAK,aAAa,EAClB,KAAK,eAAe,EACpB,KAAK,gBAAgB,GACtB,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migrate-to-v2.6.0-codemod.d.ts","sourceRoot":"","sources":["../../src/migrate-to-v2.6.0-codemod.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAE1D,MAAM,CAAC,OAAO,UAAU,WAAW,CACjC,IAAI,EAAE,QAAQ,EACd,GAAG,EAAE,GAAG,EACR,OAAO,EAAE,OAAO,UAiDjB"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { QraftServiceOperationsToken } from '@openapi-qraft/tanstack-query-react-types';
|
|
2
2
|
import type { QueryClient } from '@tanstack/query-core';
|
|
3
3
|
import type * as callbacks from './callbacks/index.js';
|
|
4
4
|
import type * as operationInvokeModule from './callbacks/operationInvokeFn.js';
|
|
@@ -17,43 +17,141 @@ export interface CreateAPIQueryClientOptions extends CreateAPIBasicClientOptions
|
|
|
17
17
|
*/
|
|
18
18
|
export type QraftClientOptions = CreateAPIBasicClientOptions | CreateAPIQueryClientOptions;
|
|
19
19
|
export type CreateAPIClientOptions = CreateAPIBasicClientOptions | CreateAPIBasicQueryClientOptions | CreateAPIQueryClientOptions;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
20
|
+
/**
|
|
21
|
+
* Creates a QueryClient compatible API Client which contains all operations
|
|
22
|
+
* such as `useQuery`, `useMutation`.
|
|
23
|
+
*
|
|
24
|
+
* @example Fetching data with QueryClient
|
|
25
|
+
* ```ts
|
|
26
|
+
* const api = qraftAPIClient(services, callbacks, {
|
|
27
|
+
* requestFn: requestFn,
|
|
28
|
+
* baseUrl: 'https://api.example.com',
|
|
29
|
+
* queryClient: new QueryClient(),
|
|
30
|
+
* });
|
|
31
|
+
*
|
|
32
|
+
* api.service.operation({
|
|
33
|
+
* parameters: { path: { id: 1 } },
|
|
34
|
+
* });
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export declare function qraftAPIClient<Services extends UnionServiceOperationsDeclaration<Services>, Callbacks extends ServiceMethods>(services: Services, callbacks: Callbacks, options: CreateAPIQueryClientOptions): APIDefaultQueryClientServices<Services>;
|
|
38
|
+
/**
|
|
39
|
+
* Creates a QueryClient compatible API Client which contains all operations
|
|
40
|
+
* such as `useQuery`, `useMutation`.
|
|
41
|
+
*
|
|
42
|
+
* @example Fetching data with QueryClient
|
|
43
|
+
* ```ts
|
|
44
|
+
* const api = qraftAPIClient(services, callbacks, {
|
|
45
|
+
* requestFn: requestFn,
|
|
46
|
+
* baseUrl: 'https://api.example.com',
|
|
47
|
+
* queryClient: new QueryClient(),
|
|
48
|
+
* });
|
|
49
|
+
*
|
|
50
|
+
* api.service.operation({
|
|
51
|
+
* parameters: { path: { id: 1 } },
|
|
52
|
+
* });
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
export declare function qraftAPIClient<Services extends UnionServiceOperationsDeclaration<Services>, Callbacks extends PartialServiceMethods>(services: Services, callbacks: Callbacks, options: CreateAPIQueryClientOptions): APIQueryClientServices<Services, Callbacks>;
|
|
56
|
+
/**
|
|
57
|
+
* Creates a QueryClient compatible API Client which contains
|
|
58
|
+
* only state management manipulations such as `useIsMutating`,
|
|
59
|
+
* `setQueryData`, `getQueryData` and `invalidateQueries`.
|
|
60
|
+
*
|
|
61
|
+
* @example Invalidating queries with QueryClient
|
|
62
|
+
* ```ts
|
|
63
|
+
* const api = qraftAPIClient(services, callbacks, {
|
|
64
|
+
* // an instance of QueryClient shared between all clients
|
|
65
|
+
* queryClient: sharedQueryClient
|
|
66
|
+
* });
|
|
67
|
+
*
|
|
68
|
+
* api.service.operation.invalidateQueries({
|
|
69
|
+
* parameters: { path: { id: 1 } },
|
|
70
|
+
* });
|
|
71
|
+
*/
|
|
72
|
+
export declare function qraftAPIClient<Services extends UnionServiceOperationsDeclaration<Services>, Callbacks extends PartialServiceMethods>(services: Services, callbacks: Callbacks, options: CreateAPIBasicQueryClientOptions): APIBasicQueryClientServices<Services, Callbacks>;
|
|
73
|
+
/**
|
|
74
|
+
* Creates a basic API Client which contains only "fetch" like
|
|
75
|
+
* operations without any state management using QueryClient.
|
|
76
|
+
*
|
|
77
|
+
* @example Fetching data without QueryClient
|
|
78
|
+
* ```ts
|
|
79
|
+
* const api = qraftAPIClient(services, callbacks, {
|
|
80
|
+
* requestFn: requestFn,
|
|
81
|
+
* baseUrl: 'https://api.example.com',
|
|
82
|
+
* });
|
|
83
|
+
*
|
|
84
|
+
* api.service.operation({
|
|
85
|
+
* parameters: { path: { id: 1 } },
|
|
86
|
+
* });
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
export declare function qraftAPIClient<Services extends UnionServiceOperationsDeclaration<Services>, Callbacks extends PartialServiceMethods>(services: Services, callbacks: Callbacks, options: CreateAPIBasicClientOptions): APIBasicClientServices<Services, Callbacks>;
|
|
90
|
+
/**
|
|
91
|
+
* Creates a utility API Client which contains only utility operations
|
|
92
|
+
* such as `getQueryKey`, `getInfiniteQueryKey` and `getMutationKey`.
|
|
93
|
+
*
|
|
94
|
+
* @example Getting query keys with utility client
|
|
95
|
+
* ```ts
|
|
96
|
+
* const api = qraftAPIClient(services, callbacks);
|
|
97
|
+
*
|
|
98
|
+
* api.service.operation.getQueryKey({
|
|
99
|
+
* parameters: { path: { id: 1 } },
|
|
100
|
+
* });
|
|
101
|
+
* ```
|
|
102
|
+
*/
|
|
103
|
+
export declare function qraftAPIClient<Services extends UnionServiceOperationsDeclaration<Services>, Callbacks extends Pick<PartialServiceMethods, UtilityOperationCallbacks>>(services: Services, callbacks: Callbacks): APIUtilityClientServices<Services, Callbacks>;
|
|
104
|
+
type ServiceMethods = typeof callbacks;
|
|
105
|
+
type PartialServiceMethods = Partial<ServiceMethods>;
|
|
106
|
+
type OperationDeclaration = {
|
|
107
|
+
schema: OperationSchema;
|
|
108
|
+
[QraftServiceOperationsToken]: Partial<Record<QueryOperationCallbacks | QueryOperationStateCallbacks | MutationOperationCallbacks | MutationOperationStateCallbacks | UtilityOperationCallbacks, any>> & {
|
|
109
|
+
types: any;
|
|
110
|
+
schema: OperationSchema;
|
|
111
|
+
(...args: any[]): any;
|
|
37
112
|
};
|
|
38
113
|
};
|
|
39
|
-
type
|
|
114
|
+
type OperationsDeclaration<Operations> = {
|
|
115
|
+
[operation in keyof Operations]: OperationDeclaration;
|
|
116
|
+
};
|
|
117
|
+
type ServicesDeclaration<Services> = {
|
|
118
|
+
[service in keyof Services]: OperationsDeclaration<Services[service]>;
|
|
119
|
+
};
|
|
120
|
+
export type UnionServiceOperationsDeclaration<Services> = ServicesDeclaration<Services> | OperationsDeclaration<Services> | OperationDeclaration;
|
|
121
|
+
type QueryOperationCallbacks = Extract<keyof ServiceMethods, 'fetchInfiniteQuery' | 'fetchQuery' | 'prefetchInfiniteQuery' | 'prefetchQuery' | 'refetchQueries' | 'ensureQueryData' | 'ensureInfiniteQueryData' | 'useInfiniteQuery' | 'useQueries' | 'useQuery' | 'useSuspenseInfiniteQuery' | 'useSuspenseQueries' | 'useSuspenseQuery'>;
|
|
122
|
+
type QueryOperationStateCallbacks = Extract<keyof ServiceMethods, 'cancelQueries' | 'getInfiniteQueryData' | 'getInfiniteQueryState' | 'getQueriesData' | 'getQueryData' | 'getQueryState' | 'invalidateQueries' | 'isFetching' | 'removeQueries' | 'resetQueries' | 'setInfiniteQueryData' | 'setQueriesData' | 'setQueryData' | 'useIsFetching'>;
|
|
123
|
+
type MutationOperationCallbacks = Extract<keyof ServiceMethods, 'useMutation'>;
|
|
124
|
+
type MutationOperationStateCallbacks = Extract<keyof ServiceMethods, 'isMutating' | 'useIsMutating' | 'useMutationState'>;
|
|
125
|
+
type InvokeOperationCallback = Extract<keyof typeof operationInvokeModule, 'operationInvokeFn'>;
|
|
126
|
+
type UtilityOperationCallbacks = Extract<keyof ServiceMethods, 'getQueryKey' | 'getInfiniteQueryKey' | 'getMutationKey'>;
|
|
127
|
+
type OperationCallbackList = QueryOperationCallbacks | QueryOperationStateCallbacks | MutationOperationCallbacks | MutationOperationStateCallbacks | InvokeOperationCallback | UtilityOperationCallbacks;
|
|
128
|
+
export type APIQueryClientServices<Services extends UnionServiceOperationsDeclaration<Services>, Callbacks extends PartialServiceMethods> = ServicesFilteredByCallbacks<Services, Extract<keyof Callbacks, OperationCallbackList>>;
|
|
129
|
+
export type APIDefaultQueryClientServices<Services extends UnionServiceOperationsDeclaration<Services>> = Services extends OperationDeclaration ? Services[QraftServiceOperationsToken] : Services extends OperationsDeclaration<Services> ? {
|
|
130
|
+
[operation in keyof Services]: Services[operation][QraftServiceOperationsToken];
|
|
131
|
+
} : Services extends ServicesDeclaration<Services> ? {
|
|
40
132
|
[service in keyof Services]: {
|
|
41
|
-
[
|
|
42
|
-
schema: Services[service][method]['schema'];
|
|
43
|
-
};
|
|
133
|
+
[operation in keyof Services[service]]: Services[service][operation][QraftServiceOperationsToken];
|
|
44
134
|
};
|
|
45
|
-
};
|
|
46
|
-
type
|
|
47
|
-
type
|
|
48
|
-
export type
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
[method in keyof TServices[serviceName]]: TServices[serviceName][method]['schema']['method'] extends 'get' | 'head' | 'options' ? Pick<ServiceOperationQuery<TServices[serviceName][method]['schema'], TServices[serviceName][method]['types']['data'], TServices[serviceName][method]['types']['parameters'], TServices[serviceName][method]['types']['error']>, Extract<keyof TCallbacks, TQueryOperationCallbacks> | 'types' | 'schema'> & (OperationInvokeFnName extends keyof TCallbacks ? ServiceOperationQueryFn<TServices[serviceName][method]['schema'], TServices[serviceName][method]['types']['data'], TServices[serviceName][method]['types']['parameters'], TServices[serviceName][method]['types']['error']> : {}) : Pick<ServiceOperationMutation<TServices[serviceName][method]['schema'], TServices[serviceName][method]['types']['body'], TServices[serviceName][method]['types']['data'], TServices[serviceName][method]['types']['parameters'], TServices[serviceName][method]['types']['error']>, Extract<keyof TCallbacks, TMutationOperationCallbacks> | 'types' | 'schema'> & (OperationInvokeFnName extends keyof TCallbacks ? ServiceOperationMutationFn<TServices[serviceName][method]['schema'], TServices[serviceName][method]['types']['body'], TServices[serviceName][method]['types']['data'], TServices[serviceName][method]['types']['parameters'], TServices[serviceName][method]['types']['error']> : {});
|
|
135
|
+
} : never;
|
|
136
|
+
export type APIBasicQueryClientServices<Services extends UnionServiceOperationsDeclaration<Services>, Callbacks extends PartialServiceMethods> = ServicesFilteredByCallbacks<Services, Extract<keyof Callbacks, QueryOperationStateCallbacks | MutationOperationStateCallbacks | UtilityOperationCallbacks>>;
|
|
137
|
+
export type APIBasicClientServices<Services extends UnionServiceOperationsDeclaration<Services>, Callbacks extends PartialServiceMethods> = ServicesFilteredByCallbacks<Services, Extract<keyof Callbacks, InvokeOperationCallback | UtilityOperationCallbacks>>;
|
|
138
|
+
export type APIUtilityClientServices<Services extends UnionServiceOperationsDeclaration<Services>, Callbacks extends Pick<PartialServiceMethods, UtilityOperationCallbacks>> = ServicesFilteredByUtilityCallbacks<Services, Extract<keyof Callbacks, UtilityOperationCallbacks>>;
|
|
139
|
+
type ServicesFilteredByCallbacks<Services extends UnionServiceOperationsDeclaration<Services>, CallbackList extends OperationCallbackList> = Services extends OperationDeclaration ? Pick<Services[QraftServiceOperationsToken], Extract<keyof Services[QraftServiceOperationsToken], CallbackList | 'schema' | 'types'>> & OperationInvokeFn<Services[QraftServiceOperationsToken], CallbackList> : Services extends OperationsDeclaration<Services> ? {
|
|
140
|
+
[operation in keyof Services]: Pick<Services[operation][QraftServiceOperationsToken], Extract<keyof Services[operation][QraftServiceOperationsToken], CallbackList | 'schema' | 'types'>> & OperationInvokeFn<Services[operation][QraftServiceOperationsToken], CallbackList>;
|
|
141
|
+
} : Services extends ServicesDeclaration<Services> ? {
|
|
142
|
+
[serviceName in keyof Services]: {
|
|
143
|
+
[operation in keyof Services[serviceName]]: Pick<Services[serviceName][operation][QraftServiceOperationsToken], Extract<keyof Services[serviceName][operation][QraftServiceOperationsToken], CallbackList | 'schema' | 'types'>> & OperationInvokeFn<Services[serviceName][operation][QraftServiceOperationsToken], CallbackList>;
|
|
55
144
|
};
|
|
56
|
-
};
|
|
57
|
-
type
|
|
145
|
+
} : never;
|
|
146
|
+
type OperationInvokeFn<InvokeFn extends (...args: any[]) => any, CallbackList extends OperationCallbackList> = InvokeOperationCallback extends CallbackList ? InvokeFn extends (...args: infer Args) => infer Result ? {
|
|
147
|
+
(...args: Args): Result;
|
|
148
|
+
} : Record<string, never> : Record<string, never>;
|
|
149
|
+
type ServicesFilteredByUtilityCallbacks<Services extends UnionServiceOperationsDeclaration<Services>, CallbackList extends UtilityOperationCallbacks> = Services extends OperationDeclaration ? Pick<Services[QraftServiceOperationsToken], Extract<keyof Services[QraftServiceOperationsToken], CallbackList | 'schema' | 'types'>> : Services extends OperationsDeclaration<Services> ? {
|
|
150
|
+
[operation in keyof Services]: Pick<Services[operation][QraftServiceOperationsToken], Extract<keyof Services[operation][QraftServiceOperationsToken], CallbackList | 'schema' | 'types'>>;
|
|
151
|
+
} : Services extends ServicesDeclaration<Services> ? {
|
|
152
|
+
[serviceName in keyof Services]: {
|
|
153
|
+
[operation in keyof Services[serviceName]]: Pick<Services[serviceName][operation][QraftServiceOperationsToken], Extract<keyof Services[serviceName][operation][QraftServiceOperationsToken], CallbackList | 'schema' | 'types'>>;
|
|
154
|
+
};
|
|
155
|
+
} : never;
|
|
58
156
|
export {};
|
|
59
157
|
//# sourceMappingURL=qraftAPIClient.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"qraftAPIClient.d.ts","sourceRoot":"","sources":["../../src/qraftAPIClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"qraftAPIClient.d.ts","sourceRoot":"","sources":["../../src/qraftAPIClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,2CAA2C,CAAC;AAC7F,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,KAAK,KAAK,SAAS,MAAM,sBAAsB,CAAC;AACvD,OAAO,KAAK,KAAK,qBAAqB,MAAM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