@openapi-qraft/react 2.0.0-next.1 → 2.0.0-next.3
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 +13 -0
- package/dist/cjs/qraftAPIClient.cjs +1 -1
- package/dist/cjs/qraftAPIClient.cjs.map +1 -1
- package/dist/esm/qraftAPIClient.js +1 -1
- 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-codemod.d.ts +3 -0
- package/dist/types/migrate-to-v2-codemod.d.ts.map +1 -0
- package/dist/types/qraftAPIClient.d.ts +3 -1
- package/dist/types/qraftAPIClient.d.ts.map +1 -1
- package/dist/types/qraftPredefinedParametersRequestFn.d.ts +1 -1
- package/dist/types/qraftPredefinedParametersRequestFn.d.ts.map +1 -1
- package/dist/types/service-operation/ServiceOperationGetQueryState.d.ts +4 -3
- package/dist/types/service-operation/ServiceOperationGetQueryState.d.ts.map +1 -1
- package/package.json +5 -3
- package/src/index.ts +1 -0
- package/src/migrate-to-v2-codemod.ts +118 -0
- package/src/qraftAPIClient.ts +21 -3
- package/src/qraftPredefinedParametersRequestFn.ts +17 -8
- package/src/service-operation/ServiceOperationGetQueryState.ts +8 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @openapi-qraft/react
|
|
2
2
|
|
|
3
|
+
## 2.0.0-next.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 7e51026: Added the ability to call `getQueryKey`, `getMutationKey`, and similar non-request operations without providing `requestFn` or `baseUrl`
|
|
8
|
+
|
|
9
|
+
## 2.0.0-next.2
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 56191e1: Updated the `getQueryState(...)` function to support being invoked without parameters if they are not required. This enhancement simplifies the usage in scenarios where the parameters are optional, providing a more flexible API.
|
|
14
|
+
- bbcac65: Refined all types related to value in the `qraftPredefinedParametersRequestFn(...)` function.
|
|
15
|
+
|
|
3
16
|
## 2.0.0-next.1
|
|
4
17
|
|
|
5
18
|
### Minor Changes
|
|
@@ -14,7 +14,7 @@ function qraftAPIClient(services, callbacks, options) {
|
|
|
14
14
|
const serviceOperation = getByPath(services, path);
|
|
15
15
|
if (!isServiceOperation(serviceOperation)) throw new Error(`Service operation not found: ${path.join('.')}`);
|
|
16
16
|
if (callbackName !== 'operationInvokeFn' && callbackName !== 'getQueryKey' && callbackName !== 'getMutationKey') {
|
|
17
|
-
if (!('queryClient' in options && options.queryClient)) throw new Error(`'qraft.<service>.<operation>.${String(callbackName)}()' requires 'queryClient' in options.`);
|
|
17
|
+
if (!options || !('queryClient' in options && options.queryClient)) throw new Error(`'qraft.<service>.<operation>.${String(callbackName)}()' requires 'queryClient' in options.`);
|
|
18
18
|
}
|
|
19
19
|
// @ts-expect-error - Too complex union type
|
|
20
20
|
return callbacks[callbackName](options, serviceOperation.schema, args);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"qraftAPIClient.cjs","sources":["../../src/qraftAPIClient.ts"],"sourcesContent":["import 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 type {\n ServiceOperationMutation,\n ServiceOperationQuery,\n} from './service-operation/index.js';\nimport type { ServiceOperationMutationFn } from './service-operation/ServiceOperationMutationFn.js';\nimport type { ServiceOperationQueryFn } from './service-operation/ServiceOperationQueryFn.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 CreateAPIQueryClientOptions\n extends CreateAPIBasicClientOptions {\n queryClient: QueryClient;\n}\n\n/**\n * @deprecated use `CreateAPIClientOptions` instead\n */\nexport type QraftClientOptions =\n | CreateAPIBasicClientOptions\n | CreateAPIQueryClientOptions;\n\nexport type CreateAPIClientOptions =\n | CreateAPIBasicClientOptions\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: 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 options: CreateAPIClientOptions\n): APIQueryClientServices<Services, TCallbacks> | Services {\n return createRecursiveProxy(\n function getCallback(getPath, key) {\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 )\n if (!('queryClient' in options && options.queryClient))\n throw new Error(\n `'qraft.<service>.<operation>.${String(callbackName)}()' requires 'queryClient' in 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[]) {\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[]) {\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 | '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 APIBasicClientServices<\n TServices extends ServicesDeclaration<TServices>,\n TCallbacks extends Callbacks,\n> = ServicesFilteredByCallbacks<\n TServices,\n TCallbacks,\n Extract<QueryOperationCallbacks, 'getQueryKey'>,\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","createRecursiveProxy","getCallback","getPath","key","length","serviceOperation","getByPath","isServiceOperation","Error","join","schema","applyCallback","applyPath","args","path","callbackName","extractCallbackDetails","assertValidCallbackName","queryClient","String","slice","input","obj","reduce","acc"],"mappings":";;;;AAmEO,SAASA,cAIdC,CAAAA,QAA6C,EAC7CC,SAAqB,EACrBC,OAA+B,EAAA;AAE/B,IAAA,OAAOC,yCACL,CAAA,SAASC,WAAYC,CAAAA,OAAO,EAAEC,GAAG,EAAA;AAC/B,QAAA,IAAID,QAAQE,MAAM,KAAK,KAAKD,GAAQ,KAAA,QAAA,EAAU;QAE9C,MAAME,gBAAAA,GAAmBC,UAAUT,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ryClient } 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 type {\n ServiceOperationMutation,\n ServiceOperationQuery,\n} from './service-operation/index.js';\nimport type { ServiceOperationMutationFn } from './service-operation/ServiceOperationMutationFn.js';\nimport type { ServiceOperationQueryFn } from './service-operation/ServiceOperationQueryFn.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 CreateAPIQueryClientOptions\n extends CreateAPIBasicClientOptions {\n queryClient: QueryClient;\n}\n\n/**\n * @deprecated use `CreateAPIClientOptions` instead\n */\nexport type QraftClientOptions =\n | CreateAPIBasicClientOptions\n | CreateAPIQueryClientOptions;\n\nexport type CreateAPIClientOptions =\n | CreateAPIBasicClientOptions\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: 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 return createRecursiveProxy(\n function getCallback(getPath, key) {\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 )\n if (!options || !('queryClient' in options && options.queryClient))\n throw new Error(\n `'qraft.<service>.<operation>.${String(callbackName)}()' requires 'queryClient' in 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[]) {\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[]) {\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 | '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 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","createRecursiveProxy","getCallback","getPath","key","length","serviceOperation","getByPath","isServiceOperation","Error","join","schema","applyCallback","applyPath","args","path","callbackName","extractCallbackDetails","assertValidCallbackName","queryClient","String","slice","input","obj","reduce","acc"],"mappings":";;;;AA2EO,SAASA,cAIdC,CAAAA,QAA6C,EAC7CC,SAAqB,EACrBC,OAAgC,EAAA;AAEhC,IAAA,OAAOC,yCACL,CAAA,SAASC,WAAYC,CAAAA,OAAO,EAAEC,GAAG,EAAA;AAC/B,QAAA,IAAID,QAAQE,MAAM,KAAK,KAAKD,GAAQ,KAAA,QAAA,EAAU;QAE9C,MAAME,gBAAAA,GAAmBC,UAAUT,QAAUK,EAAAA,OAAAA,CAAAA,CAAAA;AAC7C,QAAA,IAAI,CAACK,kBAAAA,CAAmBF,gBACtB,CAAA,EAAA,MAAM,IAAIG,KAAAA,CAAM,CAAC,6BAA6B,EAAEN,OAAAA,CAAQO,IAAI,CAAC,KAAK,CAAC,CAAA,CAAA;AACrE,QAAA,OAAOJ,iBAAiBK,MAAM,CAAA;AAChC,KAAA,EACA,SAASC,aAAAA,CAAcC,SAAS,EAAEC,IAAI,EAAA;AACpC,QAAA,MAAM,EAAEC,IAAI,EAAEC,YAAY,EAAE,GAAGC,sBAAuBJ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AM,KAAK,CAAG,EAAA;QAC1B,OAAO;YACLU,IAAMF,EAAAA,SAAAA;YACNG,YAAc,EAAA,mBAAA;AAChB,SAAA,CAAA;KACK,MAAA;;QAEL,OAAO;AACLD,YAAAA,IAAAA,EAAMF,SAAUQ,CAAAA,KAAK,CAAC,CAAA,EAAG,CAAC,CAAA,CAAA;;AAE1BL,YAAAA,YAAAA,EAAcH,SAAS,CAACA,SAAUR,CAAAA,MAAM,GAAG,CAAE,CAAA;AAC/C,SAAA,CAAA;AACF,KAAA;AACF,CAAA;AAEA,SAASG,mBACPc,KAAc,EAAA;AAEd,IAAA,OAAOA,KAAU,KAAA,IAAA,IAAQ,OAAOA,KAAAA,KAAU,YAAY,QAAYA,IAAAA,KAAAA,CAAAA;AACpE,CAAA;AAEA,SAASf,SAAAA,CAAUgB,GAA4B,EAAER,IAAc,EAAA;AAC7D,IAAA,OAAOA,IAAKS,CAAAA,MAAM,CAAU,CAACC,GAAKrB,EAAAA,GAAAA,GAAAA;QAChC,IAAIqB,GAAAA,IAAO,OAAOA,GAAQ,KAAA,QAAA,IAAYrB,OAAOqB,GAC3C,EAAA,OAAOA,GAAG,CAACrB,GAAwB,CAAA,CAAA;KACpCmB,EAAAA,GAAAA,CAAAA,CAAAA;AACL;;;;"}
|
|
@@ -12,7 +12,7 @@ function qraftAPIClient(services, callbacks, options) {
|
|
|
12
12
|
const serviceOperation = getByPath(services, path);
|
|
13
13
|
if (!isServiceOperation(serviceOperation)) throw new Error(`Service operation not found: ${path.join('.')}`);
|
|
14
14
|
if (callbackName !== 'operationInvokeFn' && callbackName !== 'getQueryKey' && callbackName !== 'getMutationKey') {
|
|
15
|
-
if (!('queryClient' in options && options.queryClient)) throw new Error(`'qraft.<service>.<operation>.${String(callbackName)}()' requires 'queryClient' in options.`);
|
|
15
|
+
if (!options || !('queryClient' in options && options.queryClient)) throw new Error(`'qraft.<service>.<operation>.${String(callbackName)}()' requires 'queryClient' in options.`);
|
|
16
16
|
}
|
|
17
17
|
// @ts-expect-error - Too complex union type
|
|
18
18
|
return callbacks[callbackName](options, serviceOperation.schema, args);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"qraftAPIClient.js","sources":["../../src/qraftAPIClient.ts"],"sourcesContent":["import 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 type {\n ServiceOperationMutation,\n ServiceOperationQuery,\n} from './service-operation/index.js';\nimport type { ServiceOperationMutationFn } from './service-operation/ServiceOperationMutationFn.js';\nimport type { ServiceOperationQueryFn } from './service-operation/ServiceOperationQueryFn.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 CreateAPIQueryClientOptions\n extends CreateAPIBasicClientOptions {\n queryClient: QueryClient;\n}\n\n/**\n * @deprecated use `CreateAPIClientOptions` instead\n */\nexport type QraftClientOptions =\n | CreateAPIBasicClientOptions\n | CreateAPIQueryClientOptions;\n\nexport type CreateAPIClientOptions =\n | CreateAPIBasicClientOptions\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: 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 options: CreateAPIClientOptions\n): APIQueryClientServices<Services, TCallbacks> | Services {\n return createRecursiveProxy(\n function getCallback(getPath, key) {\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 )\n if (!('queryClient' in options && options.queryClient))\n throw new Error(\n `'qraft.<service>.<operation>.${String(callbackName)}()' requires 'queryClient' in 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[]) {\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[]) {\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 | '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 APIBasicClientServices<\n TServices extends ServicesDeclaration<TServices>,\n TCallbacks extends Callbacks,\n> = ServicesFilteredByCallbacks<\n TServices,\n TCallbacks,\n Extract<QueryOperationCallbacks, 'getQueryKey'>,\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","createRecursiveProxy","getCallback","getPath","key","length","serviceOperation","getByPath","isServiceOperation","Error","join","schema","applyCallback","applyPath","args","path","callbackName","extractCallbackDetails","assertValidCallbackName","queryClient","String","slice","input","obj","reduce","acc"],"mappings":";;AAmEO,SAASA,cAIdC,CAAAA,QAA6C,EAC7CC,SAAqB,EACrBC,OAA+B,EAAA;AAE/B,IAAA,OAAOC,oBACL,CAAA,SAASC,WAAYC,CAAAA,OAAO,EAAEC,GAAG,EAAA;AAC/B,QAAA,IAAID,QAAQE,MAAM,KAAK,KAAKD,GAAQ,KAAA,QAAA,EAAU;QAE9C,MAAME,gBAAAA,GAAmBC,UAAUT,QAAUK,EAAAA,OAAAA,CAAAA,CAAAA;AAC7C,QAAA,IAAI,CAACK,kBAAAA,CAAmBF,gBACtB,CAAA,EAAA,MAAM,IAAIG,KAAAA,CAAM,CAAC,6BAA6B,EAAEN,OAAAA,CAAQO,IAAI,CAAC,KAAK,CAAC,CAAA,CAAA;AACrE,QAAA,OAAOJ,iBAAiBK,MAAM,CAAA;AAChC,KAAA,EACA,SAASC,aAAAA,CAAcC,SAAS,EAAEC,IAAI,EAAA;AACpC,QAAA,MAAM,EAAEC,IAAI,EAAEC,YAAY,EAAE,GAAGC,sBAAuBJ,CAAAA,SAAAA,CAAAA,CAAAA;AAEtDK,QAAAA,uBAAAA,CAAwBF,YAAcjB,EAAAA,SAAAA,CAAAA,CAAAA;QAEtC,MAAMO,gBAAAA,GAAmBC,UAAUT,QAAUiB,EAAAA,IAAAA,CAAAA,CAAAA;AAE7C,QAAA,IAAI,CAACP,kBAAAA,CAAmBF,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AAAA,YAAAA,EAAcH,SAAS,CAACA,SAAUR,CAAAA,MAAM,GAAG,CAAE,CAAA;AAC/C,SAAA,CAAA;AACF,KAAA;AACF,CAAA;AAEA,SAASG,mBACPc,KAAc,EAAA;AAEd,IAAA,OAAOA,KAAU,KAAA,IAAA,IAAQ,OAAOA,KAAAA,KAAU,YAAY,QAAYA,IAAAA,KAAAA,CAAAA;AACpE,CAAA;AAEA,SAASf,SAAAA,CAAUgB,GAA4B,EAAER,IAAc,EAAA;AAC7D,IAAA,OAAOA,IAAKS,CAAAA,MAAM,CAAU,CAACC,GAAKrB,EAAAA,GAAAA,GAAAA;QAChC,IAAIqB,GAAAA,IAAO,OAAOA,GAAQ,KAAA,QAAA,IAAYrB,OAAOqB,GAC3C,EAAA,OAAOA,GAAG,CAACrB,GAAwB,CAAA,CAAA;KACpCmB,EAAAA,GAAAA,CAAAA,CAAAA;AACL;;;;"}
|
|
1
|
+
{"version":3,"file":"qraftAPIClient.js","sources":["../../src/qraftAPIClient.ts"],"sourcesContent":["import 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 type {\n ServiceOperationMutation,\n ServiceOperationQuery,\n} from './service-operation/index.js';\nimport type { ServiceOperationMutationFn } from './service-operation/ServiceOperationMutationFn.js';\nimport type { ServiceOperationQueryFn } from './service-operation/ServiceOperationQueryFn.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 CreateAPIQueryClientOptions\n extends CreateAPIBasicClientOptions {\n queryClient: QueryClient;\n}\n\n/**\n * @deprecated use `CreateAPIClientOptions` instead\n */\nexport type QraftClientOptions =\n | CreateAPIBasicClientOptions\n | CreateAPIQueryClientOptions;\n\nexport type CreateAPIClientOptions =\n | CreateAPIBasicClientOptions\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: 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 return createRecursiveProxy(\n function getCallback(getPath, key) {\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 )\n if (!options || !('queryClient' in options && options.queryClient))\n throw new Error(\n `'qraft.<service>.<operation>.${String(callbackName)}()' requires 'queryClient' in 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[]) {\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[]) {\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 | '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 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","createRecursiveProxy","getCallback","getPath","key","length","serviceOperation","getByPath","isServiceOperation","Error","join","schema","applyCallback","applyPath","args","path","callbackName","extractCallbackDetails","assertValidCallbackName","queryClient","String","slice","input","obj","re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KrB,EAAAA,GAAAA,GAAAA;QAChC,IAAIqB,GAAAA,IAAO,OAAOA,GAAQ,KAAA,QAAA,IAAYrB,OAAOqB,GAC3C,EAAA,OAAOA,GAAG,CAACrB,GAAwB,CAAA,CAAA;KACpCmB,EAAAA,GAAAA,CAAAA,CAAAA;AACL;;;;"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { qraftAPIClient, type CreateAPIClientOptions, type CreateAPIBasicClientOptions, type CreateAPIQueryClientOptions, type APIQueryClientServices, type APIBasicClientServices, type QraftClientOptions, } from './qraftAPIClient.js';
|
|
1
|
+
export { qraftAPIClient, type CreateAPIClientOptions, type CreateAPIBasicClientOptions, type CreateAPIQueryClientOptions, type APIQueryClientServices, type APIBasicClientServices, type APIUtilityClientServices, type QraftClientOptions, } from './qraftAPIClient.js';
|
|
2
2
|
export { requestFn, baseRequestFn, urlSerializer, bodySerializer, mergeHeaders, type RequestFnResponse, } from './lib/requestFn.js';
|
|
3
3
|
export type { RequestFnPayload, RequestFnOptions, HeadersOptions, OperationSchema, RequestFn, } from './lib/requestFn.js';
|
|
4
4
|
export type * from './service-operation/index.js';
|
|
@@ -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,2BAA2B,EAChC,KAAK,2BAA2B,EAChC,KAAK,sBAAsB,EAC3B,KAAK,sBAAsB,EAC3B,KAAK,kBAAkB,GACxB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,SAAS,EACT,aAAa,EACb,aAAa,EACb,cAAc,EACd,YAAY,EACZ,KAAK,iBAAiB,GACvB,MAAM,oBAAoB,CAAC;AAE5B,YAAY,EACV,gBAAgB,EAChB,gBAAgB,EAChB,cAAc,EACd,eAAe,EACf,SAAS,GACV,MAAM,oBAAoB,CAAC;AAE5B,mBAAmB,8BAA8B,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,KAAK,sBAAsB,EAC3B,KAAK,2BAA2B,EAChC,KAAK,2BAA2B,EAChC,KAAK,sBAAsB,EAC3B,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,iBAAiB,GACvB,MAAM,oBAAoB,CAAC;AAE5B,YAAY,EACV,gBAAgB,EAChB,gBAAgB,EAChB,cAAc,EACd,eAAe,EACf,SAAS,GACV,MAAM,oBAAoB,CAAC;AAE5B,mBAAmB,8BAA8B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migrate-to-v2-codemod.d.ts","sourceRoot":"","sources":["../../src/migrate-to-v2-codemod.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,GAAG,EAGH,QAAQ,EAER,OAAO,EACR,MAAM,aAAa,CAAC;AAErB,MAAM,CAAC,OAAO,UAAU,WAAW,CACjC,IAAI,EAAE,QAAQ,EACd,GAAG,EAAE,GAAG,EACR,OAAO,EAAE,OAAO,UA2EjB"}
|
|
@@ -20,6 +20,7 @@ export type CreateAPIClientOptions = CreateAPIBasicClientOptions | CreateAPIQuer
|
|
|
20
20
|
export declare function qraftAPIClient<Services extends ServicesDeclaration<Services>, TCallbacks extends Callbacks>(services: ServiceSchemasDeclaration<Services>, callbacks: TCallbacks, options: CreateAPIBasicClientOptions): APIBasicClientServices<Services, TCallbacks>;
|
|
21
21
|
export declare function qraftAPIClient<Services extends ServicesDeclaration<Services>, TCallbacks extends Required<Callbacks>>(services: ServiceSchemasDeclaration<Services>, callbacks: TCallbacks, options: CreateAPIQueryClientOptions): Services;
|
|
22
22
|
export declare function qraftAPIClient<Services extends ServicesDeclaration<Services>, TCallbacks extends Callbacks>(services: ServiceSchemasDeclaration<Services>, callbacks: TCallbacks, options: CreateAPIQueryClientOptions): APIQueryClientServices<Services, TCallbacks>;
|
|
23
|
+
export declare function qraftAPIClient<Services extends ServicesDeclaration<Services>, TCallbacks extends Callbacks>(services: ServiceSchemasDeclaration<Services>, callbacks: TCallbacks): APIUtilityClientServices<Services, TCallbacks>;
|
|
23
24
|
type Callbacks = Partial<typeof callbacks>;
|
|
24
25
|
type ServicesDeclaration<Services> = {
|
|
25
26
|
[service in keyof Services]: {
|
|
@@ -44,7 +45,8 @@ type ServiceSchemasDeclaration<Services extends ServicesDeclaration<Services>> =
|
|
|
44
45
|
type QueryOperationCallbacks = Extract<keyof Callbacks, 'cancelQueries' | 'fetchInfiniteQuery' | 'fetchQuery' | 'getInfiniteQueryData' | 'getInfiniteQueryKey' | 'getInfiniteQueryState' | 'getQueriesData' | 'getQueryData' | 'getQueryKey' | 'getQueryState' | 'invalidateQueries' | 'isFetching' | 'prefetchInfiniteQuery' | 'prefetchQuery' | 'refetchQueries' | 'removeQueries' | 'resetQueries' | 'setInfiniteQueryData' | 'setQueriesData' | 'setQueryData' | 'useInfiniteQuery' | 'useIsFetching' | 'useQueries' | 'useQuery' | 'useSuspenseInfiniteQuery' | 'useSuspenseQueries' | 'useSuspenseQuery'>;
|
|
45
46
|
type MutationOperationCallbacks = Extract<keyof Callbacks, 'getMutationKey' | 'isMutating' | 'useIsMutating' | 'useMutation' | 'useMutationState'>;
|
|
46
47
|
export type APIQueryClientServices<TServices extends ServicesDeclaration<TServices>, TCallbacks extends Callbacks> = ServicesFilteredByCallbacks<TServices, TCallbacks, QueryOperationCallbacks, MutationOperationCallbacks>;
|
|
47
|
-
export type
|
|
48
|
+
export type APIUtilityClientServices<TServices extends ServicesDeclaration<TServices>, TCallbacks extends Callbacks> = ServicesFilteredByCallbacks<TServices, Omit<TCallbacks, 'operationInvokeFn'>, Extract<QueryOperationCallbacks, 'getQueryKey' | 'getInfiniteQueryKey'>, Extract<MutationOperationCallbacks, 'getMutationKey'>>;
|
|
49
|
+
export type APIBasicClientServices<TServices extends ServicesDeclaration<TServices>, TCallbacks extends Callbacks> = ServicesFilteredByCallbacks<TServices, TCallbacks, Extract<QueryOperationCallbacks, 'getQueryKey' | 'getInfiniteQueryKey'>, Extract<MutationOperationCallbacks, 'getMutationKey'>>;
|
|
48
50
|
type ServicesFilteredByCallbacks<TServices extends ServicesDeclaration<TServices>, TCallbacks extends Callbacks, TQueryOperationCallbacks extends QueryOperationCallbacks, TMutationOperationCallbacks extends MutationOperationCallbacks> = {
|
|
49
51
|
[serviceName in keyof TServices]: {
|
|
50
52
|
[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']> : {});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"qraftAPIClient.d.ts","sourceRoot":"","sources":["../../src/qraftAPIClient.ts"],"names":[],"mappings":"AAA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CAAC,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,EAC/C,SAAS,CAAC,WAAW,CAAC,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,YAAY,CAAC,EACrD,SAAS,CAAC,WAAW,CAAC,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,CACjD,GACD,EAAE,CAAC;KACd;CACF,CAAC;AAEF,KAAK,qBAAqB,GAAG,OAAO,CAClC,MAAM,OAAO,qBAAqB,EAClC,mBAAmB,CACpB,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { RequestFn } from './lib/requestFn.js';
|
|
2
|
-
export type QraftPredefinedParameterValue<
|
|
2
|
+
export type QraftPredefinedParameterValue<TValue> = TValue | (() => Promise<TValue | undefined>) | undefined;
|
|
3
3
|
export type InputPredefinedParametersItem<TValue> = {
|
|
4
4
|
requestPattern: string;
|
|
5
5
|
parameters: Array<{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"qraftPredefinedParametersRequestFn.d.ts","sourceRoot":"","sources":["../../src/qraftPredefinedParametersRequestFn.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,SAAS,EAIV,MAAM,oBAAoB,CAAC;AAG5B,MAAM,MAAM,6BAA6B,CAAC,
|
|
1
|
+
{"version":3,"file":"qraftPredefinedParametersRequestFn.d.ts","sourceRoot":"","sources":["../../src/qraftPredefinedParametersRequestFn.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,SAAS,EAIV,MAAM,oBAAoB,CAAC;AAG5B,MAAM,MAAM,6BAA6B,CAAC,MAAM,IAC5C,MAAM,GACN,CAAC,MAAM,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC,GACnC,SAAS,CAAC;AAEd,MAAM,MAAM,6BAA6B,CAAC,MAAM,IAAI;IAClD,cAAc,EAAE,MAAM,CAAC;IACvB,UAAU,EAAE,KAAK,CAAC;QAChB,EAAE,EAAE,QAAQ,GAAG,OAAO,GAAG,QAAQ,CAAC;QAClC,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,EAAE,6BAA6B,CAAC,MAAM,CAAC,CAAC;KAC9C,CAAC,CAAC;CACJ,CAAC;AAEF,KAAK,iCAAiC,GAClC,KAAK,GACL,MAAM,GACN,KAAK,GACL,OAAO,GACP,QAAQ,GACR,SAAS,GACT,MAAM,GACN,OAAO,CAAC;AAEZ,MAAM,MAAM,8BAA8B,GAAG;IAC3C,cAAc,EAAE,MAAM,CAAC;IACvB,OAAO,EACH,KAAK,CAAC,iCAAiC,CAAC,GACxC,aAAa,CAAC,QAAQ,CAAC,iCAAiC,CAAC,CAAC,CAAC;IAC/D,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,GAAG,aAAa,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC;CACxD,CAAC;AAEF,wBAAgB,kCAAkC,CAChD,8BAA8B,SAAS,6BAA6B,CAAC,GAAG,CAAC,EACzE,KAAK,EACL,MAAM,EAEN,yBAAyB,EACrB,KAAK,CAAC,8BAA8B,CAAC,GACrC,aAAa,CAAC,QAAQ,CAAC,8BAA8B,CAAC,CAAC,EAC3D,0BAA0B,EACtB,KAAK,CAAC,8BAA8B,CAAC,GACrC,aAAa,CAAC,QAAQ,CAAC,8BAA8B,CAAC,CAAC,EAC3D,SAAS,EAAE,SAAS,CAAC,KAAK,EAAE,MAAM,CAAC,GAClC,SAAS,CAAC,KAAK,EAAE,MAAM,CAAC,CA6C1B"}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import type { DefaultError, QueryState } from '@tanstack/query-core';
|
|
2
2
|
import type { OperationInfiniteData } from './OperationInfiniteData.js';
|
|
3
3
|
import type { ServiceOperationInfiniteQueryKey, ServiceOperationQueryKey } from './ServiceOperationKey.js';
|
|
4
|
+
import { AreAllOptional } from '../lib/AreAllOptional.js';
|
|
4
5
|
export interface ServiceOperationGetQueryState<TSchema extends {
|
|
5
6
|
url: string;
|
|
6
7
|
method: string;
|
|
7
|
-
}, TData, TParams
|
|
8
|
-
getQueryState(parameters: TParams | ServiceOperationQueryKey<TSchema, TParams>): QueryState<TData, TError> | undefined;
|
|
9
|
-
getInfiniteQueryState(parameters: TParams | ServiceOperationInfiniteQueryKey<TSchema, TParams>): QueryState<OperationInfiniteData<TData, TParams>, TError> | undefined;
|
|
8
|
+
}, TData, TParams, TError = DefaultError> {
|
|
9
|
+
getQueryState(parameters: AreAllOptional<TParams> extends true ? TParams | ServiceOperationQueryKey<TSchema, TParams> | void : TParams | ServiceOperationQueryKey<TSchema, TParams>): QueryState<TData, TError> | undefined;
|
|
10
|
+
getInfiniteQueryState(parameters: AreAllOptional<TParams> extends true ? TParams | ServiceOperationInfiniteQueryKey<TSchema, TParams> | void : TParams | ServiceOperationInfiniteQueryKey<TSchema, TParams>): QueryState<OperationInfiniteData<TData, TParams>, TError> | undefined;
|
|
10
11
|
}
|
|
11
12
|
//# sourceMappingURL=ServiceOperationGetQueryState.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ServiceOperationGetQueryState.d.ts","sourceRoot":"","sources":["../../../src/service-operation/ServiceOperationGetQueryState.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AACrE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACxE,OAAO,KAAK,EACV,gCAAgC,EAChC,wBAAwB,EACzB,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"ServiceOperationGetQueryState.d.ts","sourceRoot":"","sources":["../../../src/service-operation/ServiceOperationGetQueryState.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AACrE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACxE,OAAO,KAAK,EACV,gCAAgC,EAChC,wBAAwB,EACzB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAE1D,MAAM,WAAW,6BAA6B,CAC5C,OAAO,SAAS;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,EAC/C,KAAK,EACL,OAAO,EACP,MAAM,GAAG,YAAY;IAErB,aAAa,CACX,UAAU,EAAE,cAAc,CAAC,OAAO,CAAC,SAAS,IAAI,GAC5C,OAAO,GAAG,wBAAwB,CAAC,OAAO,EAAE,OAAO,CAAC,GAAG,IAAI,GAC3D,OAAO,GAAG,wBAAwB,CAAC,OAAO,EAAE,OAAO,CAAC,GACvD,UAAU,CAAC,KAAK,EAAE,MAAM,CAAC,GAAG,SAAS,CAAC;IAEzC,qBAAqB,CACnB,UAAU,EAAE,cAAc,CAAC,OAAO,CAAC,SAAS,IAAI,GAC5C,OAAO,GAAG,gCAAgC,CAAC,OAAO,EAAE,OAAO,CAAC,GAAG,IAAI,GACnE,OAAO,GAAG,gCAAgC,CAAC,OAAO,EAAE,OAAO,CAAC,GAC/D,UAAU,CAAC,qBAAqB,CAAC,KAAK,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,GAAG,SAAS,CAAC;CAC1E"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openapi-qraft/react",
|
|
3
|
-
"version": "2.0.0-next.
|
|
3
|
+
"version": "2.0.0-next.3",
|
|
4
4
|
"description": "API client for React, providing type-safe requests and dynamic Tanstack Query React Hooks via a modular, Proxy-based architecture.",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "NODE_ENV=production rollup --config rollup.config.mjs && tsc --project tsconfig.build.json --emitDeclarationOnly",
|
|
@@ -15,20 +15,22 @@
|
|
|
15
15
|
},
|
|
16
16
|
"sideEffects": false,
|
|
17
17
|
"devDependencies": {
|
|
18
|
-
"@openapi-qraft/cli": "2.0.0-next.
|
|
18
|
+
"@openapi-qraft/cli": "2.0.0-next.3",
|
|
19
19
|
"@openapi-qraft/eslint-config": "1.0.0",
|
|
20
|
-
"@openapi-qraft/openapi-typescript-plugin": "^1.2.0-next.
|
|
20
|
+
"@openapi-qraft/openapi-typescript-plugin": "^1.2.0-next.3",
|
|
21
21
|
"@openapi-qraft/rollup-config": "1.1.0-next.0",
|
|
22
22
|
"@openapi-qraft/test-fixtures": "1.0.0",
|
|
23
23
|
"@tanstack/react-query": "^5.17.3",
|
|
24
24
|
"@testing-library/jest-dom": "^5.17.0",
|
|
25
25
|
"@testing-library/react": "^13.4.0",
|
|
26
26
|
"@testing-library/user-event": "^14.5.2",
|
|
27
|
+
"@types/jscodeshift": "^0.11.11",
|
|
27
28
|
"@types/react": "^18.2.47",
|
|
28
29
|
"@vitejs/plugin-react": "latest",
|
|
29
30
|
"@vitest/coverage-v8": "^1.1.3",
|
|
30
31
|
"eslint": "^9.0.0",
|
|
31
32
|
"globals": "^15.0.0",
|
|
33
|
+
"jscodeshift": "^17.0.0",
|
|
32
34
|
"jsdom": "latest",
|
|
33
35
|
"msw": "^2.0.12",
|
|
34
36
|
"prettier": "^3.3.3",
|
package/src/index.ts
CHANGED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import {
|
|
2
|
+
API,
|
|
3
|
+
ASTPath,
|
|
4
|
+
CallExpression,
|
|
5
|
+
FileInfo,
|
|
6
|
+
MemberExpression,
|
|
7
|
+
Options,
|
|
8
|
+
} from 'jscodeshift';
|
|
9
|
+
|
|
10
|
+
export default function transformer(
|
|
11
|
+
file: FileInfo,
|
|
12
|
+
api: API,
|
|
13
|
+
options: Options
|
|
14
|
+
) {
|
|
15
|
+
const j = api.jscodeshift;
|
|
16
|
+
const root = j(file.source);
|
|
17
|
+
|
|
18
|
+
const methodNames = [
|
|
19
|
+
'fetchQuery',
|
|
20
|
+
'fetchInfiniteQuery',
|
|
21
|
+
'prefetchQuery',
|
|
22
|
+
'prefetchInfiniteQuery',
|
|
23
|
+
'getQueryData',
|
|
24
|
+
'getQueriesData',
|
|
25
|
+
'setQueryData',
|
|
26
|
+
'getQueryState',
|
|
27
|
+
'setQueriesData',
|
|
28
|
+
'invalidateQueries',
|
|
29
|
+
'refetchQueries',
|
|
30
|
+
'cancelQueries',
|
|
31
|
+
'removeQueries',
|
|
32
|
+
'resetQueries',
|
|
33
|
+
'isFetching',
|
|
34
|
+
'isMutating',
|
|
35
|
+
'setInfiniteQueryData',
|
|
36
|
+
'getInfiniteQueryData',
|
|
37
|
+
'getInfiniteQueryState',
|
|
38
|
+
];
|
|
39
|
+
|
|
40
|
+
const hooksWithTwoArgs = [
|
|
41
|
+
'useSuspenseQueries',
|
|
42
|
+
'useIsFetching',
|
|
43
|
+
'useMutationState',
|
|
44
|
+
'useIsMutating',
|
|
45
|
+
];
|
|
46
|
+
|
|
47
|
+
const hooksWithThreeArgs = [
|
|
48
|
+
'useQuery',
|
|
49
|
+
'useMutation',
|
|
50
|
+
'useInfiniteQuery',
|
|
51
|
+
'useQueries',
|
|
52
|
+
'useSuspenseQuery',
|
|
53
|
+
'useSuspenseInfiniteQuery',
|
|
54
|
+
];
|
|
55
|
+
|
|
56
|
+
const apiClientVariableNames = getAPIClientVariableNames(options);
|
|
57
|
+
|
|
58
|
+
return root
|
|
59
|
+
.find(j.CallExpression)
|
|
60
|
+
.forEach((path: ASTPath<CallExpression>) => {
|
|
61
|
+
const callee = path.node.callee;
|
|
62
|
+
if (callee.type === 'MemberExpression') {
|
|
63
|
+
const apiClientCallMethodName = getAPIClientCallMethodName(
|
|
64
|
+
callee,
|
|
65
|
+
apiClientVariableNames
|
|
66
|
+
);
|
|
67
|
+
if (apiClientCallMethodName) {
|
|
68
|
+
if (methodNames.includes(apiClientCallMethodName)) {
|
|
69
|
+
// Remove the last argument `queryClient`
|
|
70
|
+
path.node.arguments = path.node.arguments.slice(0, -1);
|
|
71
|
+
} else if (
|
|
72
|
+
hooksWithTwoArgs.includes(apiClientCallMethodName) &&
|
|
73
|
+
path.node.arguments.length === 2
|
|
74
|
+
) {
|
|
75
|
+
// Remove the second argument for specific hooks if there are exactly two arguments
|
|
76
|
+
path.node.arguments = path.node.arguments.slice(0, 1);
|
|
77
|
+
} else if (
|
|
78
|
+
hooksWithThreeArgs.includes(apiClientCallMethodName) &&
|
|
79
|
+
path.node.arguments.length === 3
|
|
80
|
+
) {
|
|
81
|
+
// Remove the third argument for specific hooks if there are exactly three arguments
|
|
82
|
+
path.node.arguments = path.node.arguments.slice(0, 2);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
})
|
|
87
|
+
.toSource();
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function getAPIClientCallMethodName(
|
|
91
|
+
node: MemberExpression,
|
|
92
|
+
apiClientNames: string[]
|
|
93
|
+
): string | undefined {
|
|
94
|
+
if (
|
|
95
|
+
node.object.type === 'MemberExpression' &&
|
|
96
|
+
node.object.object.type === 'MemberExpression' &&
|
|
97
|
+
node.object.object.object.type === 'Identifier' &&
|
|
98
|
+
node.object.object.property.type === 'Identifier' &&
|
|
99
|
+
node.object.property.type === 'Identifier' &&
|
|
100
|
+
node.property.type === 'Identifier'
|
|
101
|
+
) {
|
|
102
|
+
const apiClientVariableName = node.object.object.object.name;
|
|
103
|
+
|
|
104
|
+
if (apiClientNames.includes(apiClientVariableName))
|
|
105
|
+
return node.property.name;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function getAPIClientVariableNames(options: Options) {
|
|
110
|
+
const apiClientVariableNameOption = options['api-client-variable-name'];
|
|
111
|
+
|
|
112
|
+
if (!apiClientVariableNameOption) return ['api', 'qraft'];
|
|
113
|
+
|
|
114
|
+
return String(apiClientVariableNameOption)
|
|
115
|
+
.split(',')
|
|
116
|
+
.map((name) => name.trim())
|
|
117
|
+
.filter(Boolean);
|
|
118
|
+
}
|
package/src/qraftAPIClient.ts
CHANGED
|
@@ -65,13 +65,21 @@ export function qraftAPIClient<
|
|
|
65
65
|
options: CreateAPIQueryClientOptions
|
|
66
66
|
): APIQueryClientServices<Services, TCallbacks>;
|
|
67
67
|
|
|
68
|
+
export function qraftAPIClient<
|
|
69
|
+
Services extends ServicesDeclaration<Services>,
|
|
70
|
+
TCallbacks extends Callbacks,
|
|
71
|
+
>(
|
|
72
|
+
services: ServiceSchemasDeclaration<Services>,
|
|
73
|
+
callbacks: TCallbacks
|
|
74
|
+
): APIUtilityClientServices<Services, TCallbacks>;
|
|
75
|
+
|
|
68
76
|
export function qraftAPIClient<
|
|
69
77
|
Services extends ServicesDeclaration<Services>,
|
|
70
78
|
TCallbacks extends Callbacks,
|
|
71
79
|
>(
|
|
72
80
|
services: ServiceSchemasDeclaration<Services>,
|
|
73
81
|
callbacks: TCallbacks,
|
|
74
|
-
options
|
|
82
|
+
options?: CreateAPIClientOptions
|
|
75
83
|
): APIQueryClientServices<Services, TCallbacks> | Services {
|
|
76
84
|
return createRecursiveProxy(
|
|
77
85
|
function getCallback(getPath, key) {
|
|
@@ -97,7 +105,7 @@ export function qraftAPIClient<
|
|
|
97
105
|
callbackName !== 'getQueryKey' &&
|
|
98
106
|
callbackName !== 'getMutationKey'
|
|
99
107
|
)
|
|
100
|
-
if (!('queryClient' in options && options.queryClient))
|
|
108
|
+
if (!options || !('queryClient' in options && options.queryClient))
|
|
101
109
|
throw new Error(
|
|
102
110
|
`'qraft.<service>.<operation>.${String(callbackName)}()' requires 'queryClient' in options.`
|
|
103
111
|
);
|
|
@@ -235,13 +243,23 @@ export type APIQueryClientServices<
|
|
|
235
243
|
MutationOperationCallbacks
|
|
236
244
|
>;
|
|
237
245
|
|
|
246
|
+
export type APIUtilityClientServices<
|
|
247
|
+
TServices extends ServicesDeclaration<TServices>,
|
|
248
|
+
TCallbacks extends Callbacks,
|
|
249
|
+
> = ServicesFilteredByCallbacks<
|
|
250
|
+
TServices,
|
|
251
|
+
Omit<TCallbacks, 'operationInvokeFn'>,
|
|
252
|
+
Extract<QueryOperationCallbacks, 'getQueryKey' | 'getInfiniteQueryKey'>,
|
|
253
|
+
Extract<MutationOperationCallbacks, 'getMutationKey'>
|
|
254
|
+
>;
|
|
255
|
+
|
|
238
256
|
export type APIBasicClientServices<
|
|
239
257
|
TServices extends ServicesDeclaration<TServices>,
|
|
240
258
|
TCallbacks extends Callbacks,
|
|
241
259
|
> = ServicesFilteredByCallbacks<
|
|
242
260
|
TServices,
|
|
243
261
|
TCallbacks,
|
|
244
|
-
Extract<QueryOperationCallbacks, 'getQueryKey'>,
|
|
262
|
+
Extract<QueryOperationCallbacks, 'getQueryKey' | 'getInfiniteQueryKey'>,
|
|
245
263
|
Extract<MutationOperationCallbacks, 'getMutationKey'>
|
|
246
264
|
>;
|
|
247
265
|
|
|
@@ -7,9 +7,10 @@ import type {
|
|
|
7
7
|
} from './lib/requestFn.js';
|
|
8
8
|
import { shelfMerge } from './lib/shelfMerge.js';
|
|
9
9
|
|
|
10
|
-
export type QraftPredefinedParameterValue<
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
export type QraftPredefinedParameterValue<TValue> =
|
|
11
|
+
| TValue
|
|
12
|
+
| (() => Promise<TValue | undefined>)
|
|
13
|
+
| undefined;
|
|
13
14
|
|
|
14
15
|
export type InputPredefinedParametersItem<TValue> = {
|
|
15
16
|
requestPattern: string;
|
|
@@ -131,10 +132,18 @@ async function resolveQraftPredefinedParameters<T>(
|
|
|
131
132
|
);
|
|
132
133
|
}
|
|
133
134
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
135
|
+
type QraftPredefinedParameterResolvedValue<TData> = TData extends () => Promise<
|
|
136
|
+
infer TAsyncData
|
|
137
|
+
>
|
|
138
|
+
? TAsyncData
|
|
139
|
+
: TData;
|
|
140
|
+
|
|
141
|
+
async function resolveQraftPredefinedParameterValue<TData>(
|
|
142
|
+
value: QraftPredefinedParameterValue<TData>
|
|
143
|
+
): Promise<QraftPredefinedParameterResolvedValue<TData>> {
|
|
137
144
|
if (value && typeof value === 'function')
|
|
138
|
-
return (await
|
|
139
|
-
|
|
145
|
+
return (await (
|
|
146
|
+
value as () => Promise<TData | undefined>
|
|
147
|
+
)()) as QraftPredefinedParameterResolvedValue<TData>;
|
|
148
|
+
return value as QraftPredefinedParameterResolvedValue<TData>;
|
|
140
149
|
}
|
|
@@ -4,18 +4,23 @@ import type {
|
|
|
4
4
|
ServiceOperationInfiniteQueryKey,
|
|
5
5
|
ServiceOperationQueryKey,
|
|
6
6
|
} from './ServiceOperationKey.js';
|
|
7
|
+
import { AreAllOptional } from '../lib/AreAllOptional.js';
|
|
7
8
|
|
|
8
9
|
export interface ServiceOperationGetQueryState<
|
|
9
10
|
TSchema extends { url: string; method: string },
|
|
10
11
|
TData,
|
|
11
|
-
TParams
|
|
12
|
+
TParams,
|
|
12
13
|
TError = DefaultError,
|
|
13
14
|
> {
|
|
14
15
|
getQueryState(
|
|
15
|
-
parameters: TParams
|
|
16
|
+
parameters: AreAllOptional<TParams> extends true
|
|
17
|
+
? TParams | ServiceOperationQueryKey<TSchema, TParams> | void
|
|
18
|
+
: TParams | ServiceOperationQueryKey<TSchema, TParams>
|
|
16
19
|
): QueryState<TData, TError> | undefined;
|
|
17
20
|
|
|
18
21
|
getInfiniteQueryState(
|
|
19
|
-
parameters: TParams
|
|
22
|
+
parameters: AreAllOptional<TParams> extends true
|
|
23
|
+
? TParams | ServiceOperationInfiniteQueryKey<TSchema, TParams> | void
|
|
24
|
+
: TParams | ServiceOperationInfiniteQueryKey<TSchema, TParams>
|
|
20
25
|
): QueryState<OperationInfiniteData<TData, TParams>, TError> | undefined;
|
|
21
26
|
}
|