@openapi-qraft/react 2.0.0-next.9 → 2.0.1-beta.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 +149 -0
- package/dist/cjs/callbacks/ensureInfiniteQueryData.cjs +10 -0
- package/dist/cjs/callbacks/ensureInfiniteQueryData.cjs.map +1 -0
- package/dist/cjs/callbacks/ensureQueryData.cjs +10 -0
- package/dist/cjs/callbacks/ensureQueryData.cjs.map +1 -0
- package/dist/cjs/callbacks/index.cjs +4 -0
- package/dist/cjs/callbacks/index.cjs.map +1 -1
- package/dist/cjs/lib/callQueryClientFetchMethod.cjs.map +1 -1
- package/dist/cjs/lib/requestFn.cjs +67 -64
- package/dist/cjs/lib/requestFn.cjs.map +1 -1
- package/dist/cjs/lib/responseUtils.cjs +41 -0
- package/dist/cjs/lib/responseUtils.cjs.map +1 -0
- package/dist/cjs/qraftAPIClient.cjs +2 -2
- package/dist/cjs/qraftAPIClient.cjs.map +1 -1
- package/dist/cjs/unstable__responseUtils.cjs +9 -0
- package/dist/cjs/unstable__responseUtils.cjs.map +1 -0
- package/dist/esm/callbacks/ensureInfiniteQueryData.js +8 -0
- package/dist/esm/callbacks/ensureInfiniteQueryData.js.map +1 -0
- package/dist/esm/callbacks/ensureQueryData.js +8 -0
- package/dist/esm/callbacks/ensureQueryData.js.map +1 -0
- package/dist/esm/callbacks/index.js +2 -0
- package/dist/esm/callbacks/index.js.map +1 -1
- package/dist/esm/lib/callQueryClientFetchMethod.js.map +1 -1
- package/dist/esm/lib/requestFn.js +66 -63
- package/dist/esm/lib/requestFn.js.map +1 -1
- package/dist/esm/lib/responseUtils.js +38 -0
- package/dist/esm/lib/responseUtils.js.map +1 -0
- package/dist/esm/qraftAPIClient.js +2 -2
- package/dist/esm/qraftAPIClient.js.map +1 -1
- package/dist/esm/unstable__responseUtils.js +2 -0
- package/dist/esm/unstable__responseUtils.js.map +1 -0
- package/dist/types/callbacks/ensureInfiniteQueryData.d.ts +8 -0
- package/dist/types/callbacks/ensureInfiniteQueryData.d.ts.map +1 -0
- package/dist/types/callbacks/ensureQueryData.d.ts +8 -0
- package/dist/types/callbacks/ensureQueryData.d.ts.map +1 -0
- package/dist/types/callbacks/index.d.ts +2 -0
- package/dist/types/callbacks/index.d.ts.map +1 -1
- package/dist/types/lib/callQueryClientFetchMethod.d.ts +1 -1
- package/dist/types/lib/callQueryClientFetchMethod.d.ts.map +1 -1
- package/dist/types/lib/requestFn.d.ts +17 -2
- package/dist/types/lib/requestFn.d.ts.map +1 -1
- package/dist/types/lib/responseUtils.d.ts +13 -0
- package/dist/types/lib/responseUtils.d.ts.map +1 -0
- package/dist/types/qraftAPIClient.d.ts +1 -1
- package/dist/types/qraftAPIClient.d.ts.map +1 -1
- package/dist/types/unstable__responseUtils.d.ts +2 -0
- package/dist/types/unstable__responseUtils.d.ts.map +1 -0
- package/package.json +16 -11
- package/src/callbacks/ensureInfiniteQueryData.ts +29 -0
- package/src/callbacks/ensureQueryData.ts +29 -0
- package/src/callbacks/index.ts +2 -0
- package/src/lib/callQueryClientFetchMethod.ts +3 -1
- package/src/lib/requestFn.ts +92 -115
- package/src/lib/responseUtils.ts +74 -0
- package/src/qraftAPIClient.ts +5 -2
- package/src/unstable__responseUtils.ts +1 -0
|
@@ -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 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 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","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":";;;;AAwFO,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,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ourcesContent":["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 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 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[]) {\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 | '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","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":";;;;AAwFO,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,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,gBACtB,CAAA,EAAA,MAAM,IAAIG,KAAAA,CAAM,CAAC,6BAA6B,EAAEM,IAAAA,CAAKL,IAAI,CAAC,KAAK,CAAC,CAAA,CAAA;AAElE,QAAA,IACEM,iBAAiB,mBACjBA,IAAAA,YAAAA,KAAiB,iBACjBA,YAAiB,KAAA,gBAAA,IACjBA,iBAAiB,qB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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;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unstable__responseUtils.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { callQueryClientMethodWithQueryKey } from '../lib/callQueryClientFetchMethod.js';
|
|
2
|
+
|
|
3
|
+
const ensureInfiniteQueryData = (qraftOptions, schema, args)=>{
|
|
4
|
+
return callQueryClientMethodWithQueryKey(qraftOptions, 'ensureInfiniteQueryData', schema, true, args);
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
export { ensureInfiniteQueryData };
|
|
8
|
+
//# sourceMappingURL=ensureInfiniteQueryData.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ensureInfiniteQueryData.js","sources":["../../../src/callbacks/ensureInfiniteQueryData.ts"],"sourcesContent":["import type { ServiceOperationFetchInfiniteQuery } from '@openapi-qraft/tanstack-query-react-types';\nimport type { DefaultError } from '@tanstack/query-core';\nimport type { CreateAPIQueryClientOptions } from '../qraftAPIClient.js';\nimport { callQueryClientMethodWithQueryKey } from '../lib/callQueryClientFetchMethod.js';\n\nexport const ensureInfiniteQueryData: <\n TSchema extends { url: string; method: 'get' | 'head' | 'options' },\n TData,\n TParams,\n>(\n qraftOptions: CreateAPIQueryClientOptions,\n schema: TSchema,\n args: Parameters<\n ServiceOperationFetchInfiniteQuery<\n TSchema,\n TData,\n TParams,\n DefaultError\n >['ensureInfiniteQueryData']\n >\n) => Promise<TData> = (qraftOptions, schema, args) => {\n return callQueryClientMethodWithQueryKey(\n qraftOptions,\n 'ensureInfiniteQueryData',\n schema,\n true,\n args as never\n ) as never;\n};\n"],"names":["ensureInfiniteQueryData","qraftOptions","schema","args","callQueryClientMethodWithQueryKey"],"mappings":";;AAKaA,MAAAA,uBAAAA,GAeS,CAACC,YAAAA,EAAcC,MAAQC,EAAAA,IAAAA,GAAAA;AAC3C,IAAA,OAAOC,iCACLH,CAAAA,YAAAA,EACA,yBACAC,EAAAA,MAAAA,EACA,IACAC,EAAAA,IAAAA,CAAAA,CAAAA;AAEJ;;;;"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { callQueryClientMethodWithQueryKey } from '../lib/callQueryClientFetchMethod.js';
|
|
2
|
+
|
|
3
|
+
const ensureQueryData = (qraftOptions, schema, args)=>{
|
|
4
|
+
return callQueryClientMethodWithQueryKey(qraftOptions, 'ensureQueryData', schema, false, args);
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
export { ensureQueryData };
|
|
8
|
+
//# sourceMappingURL=ensureQueryData.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ensureQueryData.js","sources":["../../../src/callbacks/ensureQueryData.ts"],"sourcesContent":["import type { ServiceOperationFetchQuery } from '@openapi-qraft/tanstack-query-react-types';\nimport type { DefaultError } from '@tanstack/query-core';\nimport type { CreateAPIQueryClientOptions } from '../qraftAPIClient.js';\nimport { callQueryClientMethodWithQueryKey } from '../lib/callQueryClientFetchMethod.js';\n\nexport const ensureQueryData: <\n TSchema extends { url: string; method: 'get' | 'head' | 'options' },\n TData,\n TParams,\n>(\n qraftOptions: CreateAPIQueryClientOptions,\n schema: TSchema,\n args: Parameters<\n ServiceOperationFetchQuery<\n TSchema,\n TData,\n TParams,\n DefaultError\n >['ensureQueryData']\n >\n) => Promise<TData> = (qraftOptions, schema, args) => {\n return callQueryClientMethodWithQueryKey(\n qraftOptions,\n 'ensureQueryData',\n schema,\n false,\n args as never\n ) as never;\n};\n"],"names":["ensureQueryData","qraftOptions","schema","args","callQueryClientMethodWithQueryKey"],"mappings":";;AAKaA,MAAAA,eAAAA,GAeS,CAACC,YAAAA,EAAcC,MAAQC,EAAAA,IAAAA,GAAAA;AAC3C,IAAA,OAAOC,iCACLH,CAAAA,YAAAA,EACA,iBACAC,EAAAA,MAAAA,EACA,KACAC,EAAAA,IAAAA,CAAAA,CAAAA;AAEJ;;;;"}
|
|
@@ -26,8 +26,10 @@ export { isMutating } from './isMutating.js';
|
|
|
26
26
|
export { useIsFetching } from './useIsFetching.js';
|
|
27
27
|
export { fetchQuery } from './fetchQuery.js';
|
|
28
28
|
export { prefetchQuery } from './prefetchQuery.js';
|
|
29
|
+
export { ensureQueryData } from './ensureQueryData.js';
|
|
29
30
|
export { fetchInfiniteQuery } from './fetchInfiniteQuery.js';
|
|
30
31
|
export { prefetchInfiniteQuery } from './prefetchInfiniteQuery.js';
|
|
32
|
+
export { ensureInfiniteQueryData } from './ensureInfiniteQueryData.js';
|
|
31
33
|
export { getQueryState } from './getQueryState.js';
|
|
32
34
|
export { getInfiniteQueryState } from './getInfiniteQueryState.js';
|
|
33
35
|
export { operationInvokeFn } from './operationInvokeFn.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"callQueryClientFetchMethod.js","sources":["../../../src/lib/callQueryClientFetchMethod.ts"],"sourcesContent":["import type { QueryClient } from '@tanstack/query-core';\nimport type { CreateAPIQueryClientOptions } from '../qraftAPIClient.js';\nimport type { OperationSchema, RequestFn } from './requestFn.js';\nimport { composeInfiniteQueryKey } from './composeInfiniteQueryKey.js';\nimport { composeQueryKey } from './composeQueryKey.js';\nimport { requestFnResponseResolver } from './requestFnResponseResolver.js';\nimport { shelfMerge } from './shelfMerge.js';\n\n/**\n * Calls a query client fetch method with parameters and options,\n * and automatically composes the `QueryKey` based on the schema and parameters.\n */\nexport function callQueryClientMethodWithQueryKey<\n QFMethod extends QueryKeyMethods,\n>(\n qraftOptions: CreateAPIQueryClientOptions,\n queryFilterMethod: QFMethod,\n schema: OperationSchema,\n infinite: boolean,\n args: QueryClientMethodArgs<QFMethod>\n): ReturnType<(typeof QueryClient.prototype)[QFMethod]> {\n const {\n requestFn: requestFnOption,\n baseUrl: baseUrlOption,\n queryFn: queryFnOption,\n parameters,\n ...options\n } = args[0] ?? {};\n\n const queryClient = qraftOptions.queryClient;\n const baseUrl = baseUrlOption ?? qraftOptions.baseUrl;\n\n if (queryFnOption && requestFnOption) {\n throw new Error(\n 'callQueryClientMethodWithQueryKey: options.queryFn and options.requestFn are mutually exclusive'\n );\n }\n\n const requestFn = requestFnOption ?? qraftOptions.requestFn;\n\n if (options.queryKey && parameters) {\n throw new Error(\n 'callQueryClientMethodWithQueryKey: options.queryKey and options.parameters are mutually exclusive'\n );\n }\n\n const queryFn =\n queryFnOption ??\n (requestFn\n ? // @ts-expect-error - Too complex union to type\n function ({ queryKey: [, queryParams], signal, meta, pageParam }) {\n return requestFn(schema, {\n parameters: infinite\n ? (shelfMerge(2, queryParams, pageParam) as never)\n : queryParams,\n baseUrl,\n signal,\n meta,\n }).then(requestFnResponseResolver, requestFnResponseResolver);\n }\n : undefined);\n\n // @ts-expect-error - Too complex union to type\n return queryClient[queryFilterMethod]({\n ...options,\n queryFn,\n queryKey:\n options.queryKey ??\n (infinite\n ? composeInfiniteQueryKey(schema, parameters)\n : composeQueryKey(schema, parameters)),\n });\n}\n\ntype QueryClientMethodArgs<QMethod extends keyof QueryClientPrototype> = [\n options: Parameters<QueryClientPrototype[QMethod]>[0] & {\n parameters?: unknown;\n baseUrl?: string;\n requestFn?: RequestFn<unknown, unknown>;\n },\n queryClient: QueryClient,\n];\n\ntype QueryKeyMethods =\n | QueryKeyMethod<'fetchQuery'>\n | QueryKeyMethod<'prefetchQuery'>\n | QueryKeyMethod<'fetchInfiniteQuery'>\n | QueryKeyMethod<'prefetchInfiniteQuery'>;\n\ntype QueryClientPrototype = typeof QueryClient.prototype;\n\ntype QueryKeyMethod<QFMethod extends keyof typeof QueryClient.prototype> =\n QFMethod;\n"],"names":["callQueryClientMethodWithQueryKey","qraftOptions","queryFilterMethod","schema","infinite","args","requestFn","requestFnOption","baseUrl","baseUrlOption","queryFn","queryFnOption","parameters","options","queryClient","Error","queryKey","queryParams","signal","meta","pageParam","shelfMerge","then","requestFnResponseResolver","undefined","composeInfiniteQueryKey","composeQueryKey"],"mappings":";;;;;AAQA;;;IAIO,SAASA,iCAAAA,CAGdC,YAAyC,EACzCC,iBAA2B,EAC3BC,MAAuB,EACvBC,QAAiB,EACjBC,IAAqC,EAAA;AAErC,IAAA,MAAM,EACJC,SAAWC,EAAAA,eAAe,EAC1BC,OAASC,EAAAA,aAAa,EACtBC,OAASC,EAAAA,aAAa,EACtBC,UAAU,EACV,GAAGC,OACJ,EAAA,GAAGR,IAAI,CAAC,CAAA,CAAE,IAAI,EAAC,CAAA;IAEhB,MAAMS,WAAAA,GAAcb,aAAaa,WAAW,CAAA;IAC5C,MAAMN,OAAAA,GAAUC,aAAiBR,IAAAA,YAAAA,CAAaO,OAAO,CAAA;AAErD,IAAA,IAAIG,iBAAiBJ,eAAiB,EAAA;AACpC,QAAA,MAAM,IAAIQ,KACR,CAAA,iGAAA,CAAA,CAAA;AAEJ,KAAA;IAEA,MAAMT,SAAAA,GAAYC,eAAmBN,IAAAA,YAAAA,CAAaK,SAAS,CAAA;IAE3D,IAAIO,OAAAA,CAAQG,QAAQ,IAAIJ,UAAY,EAAA;AAClC,QAAA,MAAM,IAAIG,KACR,CAAA,mGAAA,CAAA,CAAA;AAEJ,KAAA;AAEA,IAAA,MAAML,OACJC,GAAAA,aAAAA,KACCL,SAAAA,GAEG,SAAU,EAAEU,QAAAA,EAAU,GAAGC,WAAAA,CAAY,EAAEC,MAAM,EAAEC,IAAI,EAAEC,SAAS,EAAE,EAAA;AAC9D,QAAA,OAAOd,UAAUH,MAAQ,EAAA;AACvBS,YAAAA,UAAAA,EAAYR,QACPiB,GAAAA,UAAAA,CAAW,CAAGJ,EAAAA,WAAAA,EAAaG,SAC5BH,CAAAA,GAAAA,WAAAA;AACJT,YAAAA,OAAAA;AACAU,YAAAA,MAAAA;AACAC,YAAAA,IAAAA;SACCG,CAAAA,CAAAA,IAAI,CAACC,yBAA2BA,EAAAA,yBAAAA,CAAAA,CAAAA;AACrC,KAAA,GACAC,SAAQ,CAAA,CAAA;;IAGd,OAAOV,WAAW,CAACZ,iBAAAA,CAAkB,CAAC;AACpC,QAAA,GAAGW,OAAO;AACVH,QAAAA,OAAAA;QACAM,QACEH,EAAAA,OAAAA,CAAQG,QAAQ,KACfZ,QAAAA,GACGqB,wBAAwBtB,MAAQS,EAAAA,UAAAA,CAAAA,GAChCc,eAAgBvB,CAAAA,MAAAA,EAAQS,UAAU,CAAA,CAAA;AAC1C,KAAA,CAAA,CAAA;AACF;;;;"}
|
|
1
|
+
{"version":3,"file":"callQueryClientFetchMethod.js","sources":["../../../src/lib/callQueryClientFetchMethod.ts"],"sourcesContent":["import type { QueryClient } from '@tanstack/query-core';\nimport type { CreateAPIQueryClientOptions } from '../qraftAPIClient.js';\nimport type { OperationSchema, RequestFn } from './requestFn.js';\nimport { composeInfiniteQueryKey } from './composeInfiniteQueryKey.js';\nimport { composeQueryKey } from './composeQueryKey.js';\nimport { requestFnResponseResolver } from './requestFnResponseResolver.js';\nimport { shelfMerge } from './shelfMerge.js';\n\n/**\n * Calls a query client fetch method with parameters and options,\n * and automatically composes the `QueryKey` based on the schema and parameters.\n */\nexport function callQueryClientMethodWithQueryKey<\n QFMethod extends QueryKeyMethods,\n>(\n qraftOptions: CreateAPIQueryClientOptions,\n queryFilterMethod: QFMethod,\n schema: OperationSchema,\n infinite: boolean,\n args: QueryClientMethodArgs<QFMethod>\n): ReturnType<(typeof QueryClient.prototype)[QFMethod]> {\n const {\n requestFn: requestFnOption,\n baseUrl: baseUrlOption,\n queryFn: queryFnOption,\n parameters,\n ...options\n } = args[0] ?? {};\n\n const queryClient = qraftOptions.queryClient;\n const baseUrl = baseUrlOption ?? qraftOptions.baseUrl;\n\n if (queryFnOption && requestFnOption) {\n throw new Error(\n 'callQueryClientMethodWithQueryKey: options.queryFn and options.requestFn are mutually exclusive'\n );\n }\n\n const requestFn = requestFnOption ?? qraftOptions.requestFn;\n\n if (options.queryKey && parameters) {\n throw new Error(\n 'callQueryClientMethodWithQueryKey: options.queryKey and options.parameters are mutually exclusive'\n );\n }\n\n const queryFn =\n queryFnOption ??\n (requestFn\n ? // @ts-expect-error - Too complex union to type\n function ({ queryKey: [, queryParams], signal, meta, pageParam }) {\n return requestFn(schema, {\n parameters: infinite\n ? (shelfMerge(2, queryParams, pageParam) as never)\n : queryParams,\n baseUrl,\n signal,\n meta,\n }).then(requestFnResponseResolver, requestFnResponseResolver);\n }\n : undefined);\n\n // @ts-expect-error - Too complex union to type\n return queryClient[queryFilterMethod]({\n ...options,\n queryFn,\n queryKey:\n options.queryKey ??\n (infinite\n ? composeInfiniteQueryKey(schema, parameters)\n : composeQueryKey(schema, parameters)),\n });\n}\n\ntype QueryClientMethodArgs<QMethod extends keyof QueryClientPrototype> = [\n options: Parameters<QueryClientPrototype[QMethod]>[0] & {\n parameters?: unknown;\n baseUrl?: string;\n requestFn?: RequestFn<unknown, unknown>;\n },\n queryClient: QueryClient,\n];\n\ntype QueryKeyMethods =\n | QueryKeyMethod<'fetchQuery'>\n | QueryKeyMethod<'prefetchQuery'>\n | QueryKeyMethod<'ensureQueryData'>\n | QueryKeyMethod<'fetchInfiniteQuery'>\n | QueryKeyMethod<'prefetchInfiniteQuery'>\n | QueryKeyMethod<'ensureInfiniteQueryData'>;\n\ntype QueryClientPrototype = typeof QueryClient.prototype;\n\ntype QueryKeyMethod<QFMethod extends keyof typeof QueryClient.prototype> =\n QFMethod;\n"],"names":["callQueryClientMethodWithQueryKey","qraftOptions","queryFilterMethod","schema","infinite","args","requestFn","requestFnOption","baseUrl","baseUrlOption","queryFn","queryFnOption","parameters","options","queryClient","Error","queryKey","queryParams","signal","meta","pageParam","shelfMerge","then","requestFnResponseResolver","undefined","composeInfiniteQueryKey","composeQueryKey"],"mappings":";;;;;AAQA;;;IAIO,SAASA,iCAAAA,CAGdC,YAAyC,EACzCC,iBAA2B,EAC3BC,MAAuB,EACvBC,QAAiB,EACjBC,IAAqC,EAAA;AAErC,IAAA,MAAM,EACJC,SAAWC,EAAAA,eAAe,EAC1BC,OAASC,EAAAA,aAAa,EACtBC,OAASC,EAAAA,aAAa,EACtBC,UAAU,EACV,GAAGC,OACJ,EAAA,GAAGR,IAAI,CAAC,CAAA,CAAE,IAAI,EAAC,CAAA;IAEhB,MAAMS,WAAAA,GAAcb,aAAaa,WAAW,CAAA;IAC5C,MAAMN,OAAAA,GAAUC,aAAiBR,IAAAA,YAAAA,CAAaO,OAAO,CAAA;AAErD,IAAA,IAAIG,iBAAiBJ,eAAiB,EAAA;AACpC,QAAA,MAAM,IAAIQ,KACR,CAAA,iGAAA,CAAA,CAAA;AAEJ,KAAA;IAEA,MAAMT,SAAAA,GAAYC,eAAmBN,IAAAA,YAAAA,CAAaK,SAAS,CAAA;IAE3D,IAAIO,OAAAA,CAAQG,QAAQ,IAAIJ,UAAY,EAAA;AAClC,QAAA,MAAM,IAAIG,KACR,CAAA,mGAAA,CAAA,CAAA;AAEJ,KAAA;AAEA,IAAA,MAAML,OACJC,GAAAA,aAAAA,KACCL,SAAAA,GAEG,SAAU,EAAEU,QAAAA,EAAU,GAAGC,WAAAA,CAAY,EAAEC,MAAM,EAAEC,IAAI,EAAEC,SAAS,EAAE,EAAA;AAC9D,QAAA,OAAOd,UAAUH,MAAQ,EAAA;AACvBS,YAAAA,UAAAA,EAAYR,QACPiB,GAAAA,UAAAA,CAAW,CAAGJ,EAAAA,WAAAA,EAAaG,SAC5BH,CAAAA,GAAAA,WAAAA;AACJT,YAAAA,OAAAA;AACAU,YAAAA,MAAAA;AACAC,YAAAA,IAAAA;SACCG,CAAAA,CAAAA,IAAI,CAACC,yBAA2BA,EAAAA,yBAAAA,CAAAA,CAAAA;AACrC,KAAA,GACAC,SAAQ,CAAA,CAAA;;IAGd,OAAOV,WAAW,CAACZ,iBAAAA,CAAkB,CAAC;AACpC,QAAA,GAAGW,OAAO;AACVH,QAAAA,OAAAA;QACAM,QACEH,EAAAA,OAAAA,CAAQG,QAAQ,KACfZ,QAAAA,GACGqB,wBAAwBtB,MAAQS,EAAAA,UAAAA,CAAAA,GAChCc,eAAgBvB,CAAAA,MAAAA,EAAQS,UAAU,CAAA,CAAA;AAC1C,KAAA,CAAA,CAAA;AACF;;;;"}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { processResponse, resolveResponse } from './responseUtils.js';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* This function is used to make a request to a specified endpoint.
|
|
3
5
|
*
|
|
@@ -19,7 +21,7 @@
|
|
|
19
21
|
}
|
|
20
22
|
/**
|
|
21
23
|
* This function is used to make a request to a specified endpoint.
|
|
22
|
-
* It's
|
|
24
|
+
* It's necessary to create a custom `requestFn` with a custom `urlSerializer`
|
|
23
25
|
* and `bodySerializer`, with the tree-shaking of the default `requestFn`
|
|
24
26
|
* and its serializers.
|
|
25
27
|
*
|
|
@@ -34,17 +36,14 @@
|
|
|
34
36
|
* @throws {error: object|string, response: Response} Throws an error if the request fails. The error includes the error message and the response from the server.
|
|
35
37
|
*/ async function baseRequestFn(requestSchema, requestInfo, options) {
|
|
36
38
|
const { parameters, headers, body, ...requestInfoRest } = requestInfo;
|
|
37
|
-
const
|
|
39
|
+
const requestPayload = options.bodySerializer(requestSchema, body);
|
|
38
40
|
const baseFetch = options.fetch ?? fetch;
|
|
39
41
|
return baseFetch(options.urlSerializer(requestSchema, requestInfo), {
|
|
40
42
|
method: requestSchema.method.toUpperCase(),
|
|
41
|
-
body:
|
|
43
|
+
body: requestPayload?.body,
|
|
42
44
|
headers: mergeHeaders({
|
|
43
|
-
Accept: 'application/json'
|
|
44
|
-
|
|
45
|
-
}, headers, parameters?.header, requestBody instanceof FormData ? {
|
|
46
|
-
'Content-Type': null
|
|
47
|
-
} : undefined),
|
|
45
|
+
Accept: 'application/json'
|
|
46
|
+
}, requestPayload?.headers, headers, parameters?.header),
|
|
48
47
|
...requestInfoRest
|
|
49
48
|
}).then(processResponse).catch(resolveResponse);
|
|
50
49
|
}
|
|
@@ -119,23 +118,68 @@ function mergeHeaders(...allHeaders) {
|
|
|
119
118
|
}
|
|
120
119
|
return headers;
|
|
121
120
|
}
|
|
122
|
-
function bodySerializer(schema,
|
|
123
|
-
if (
|
|
124
|
-
if (
|
|
125
|
-
if (
|
|
126
|
-
|
|
127
|
-
|
|
121
|
+
function bodySerializer(schema, body) {
|
|
122
|
+
if (schema.method === 'get' || schema.method === 'head' || schema.method === 'options') return undefined;
|
|
123
|
+
if (body === undefined || body === null) return undefined;
|
|
124
|
+
if (typeof body === 'string') {
|
|
125
|
+
return {
|
|
126
|
+
body,
|
|
127
|
+
headers: {
|
|
128
|
+
'Content-Type': // prefer text/* media type
|
|
129
|
+
schema.mediaType?.find((mediaType)=>mediaType.includes('text/')) ?? // prefer JSON media type, assume that body is serialized as JSON
|
|
130
|
+
schema.mediaType?.find((mediaType)=>mediaType.includes('/json')) ?? 'text/plain'
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
if (body instanceof FormData) {
|
|
135
|
+
return {
|
|
136
|
+
body,
|
|
137
|
+
headers: {
|
|
138
|
+
// remove `Content-Type` if the serialized body is FormData;
|
|
139
|
+
// the browser will correctly set Content-Type & boundary expression
|
|
140
|
+
'Content-Type': null
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
if (body instanceof Blob) {
|
|
145
|
+
return {
|
|
146
|
+
body,
|
|
147
|
+
headers: {
|
|
148
|
+
'Content-Type': body.type || schema.mediaType?.find((mediaType)=>!(mediaType.includes('text/') && mediaType.includes('/form-data') && mediaType.includes('/json'))) || 'application/octet-stream'
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
let jsonMediaType = null;
|
|
153
|
+
let formDataMediaType = null;
|
|
154
|
+
if (schema.mediaType) {
|
|
155
|
+
for(let i = 0; i < schema.mediaType.length; i++){
|
|
156
|
+
const mediaType = schema.mediaType[i];
|
|
157
|
+
if (mediaType.includes('/json')) jsonMediaType = mediaType;
|
|
158
|
+
else if (mediaType.includes('/form-data')) formDataMediaType = mediaType;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
if (formDataMediaType) {
|
|
162
|
+
if (!jsonMediaType || // Prefer FormData serialization if one of the fields is a Blob
|
|
163
|
+
Object.values(body).some((value)=>value instanceof Blob)) {
|
|
164
|
+
return {
|
|
165
|
+
body: getRequestBodyFormData(body),
|
|
166
|
+
headers: {
|
|
167
|
+
// remove `Content-Type` if the serialized body is FormData;
|
|
168
|
+
// the browser will correctly set Content-Type & boundary expression
|
|
169
|
+
'Content-Type': null
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
}
|
|
128
173
|
}
|
|
129
|
-
return
|
|
174
|
+
return {
|
|
175
|
+
body: JSON.stringify(body),
|
|
176
|
+
headers: {
|
|
177
|
+
'Content-Type': jsonMediaType ?? 'application/json'
|
|
178
|
+
}
|
|
179
|
+
};
|
|
130
180
|
}
|
|
131
|
-
function getRequestBodyFormData(
|
|
181
|
+
function getRequestBodyFormData(body) {
|
|
132
182
|
if (body instanceof FormData) return body;
|
|
133
|
-
if (body === null) return;
|
|
134
|
-
if (body instanceof Blob) throw new Error('Blob not supported in form-data');
|
|
135
|
-
if (body instanceof ArrayBuffer) throw new Error('ArrayBuffer not supported in form-data');
|
|
136
|
-
if (body instanceof URLSearchParams) throw new Error('URLSearchParams not supported in form-data');
|
|
137
|
-
if (body instanceof ReadableStream) throw new Error('ReadableStream not supported in form-data');
|
|
138
|
-
if (typeof body === 'string') throw new Error('String not supported in form-data');
|
|
139
183
|
if (typeof body !== 'object') throw new Error(`Unsupported body type ${typeof body} in form-data.`);
|
|
140
184
|
const formData = new FormData();
|
|
141
185
|
const process = (key, value)=>{
|
|
@@ -154,47 +198,6 @@ function getRequestBodyFormData({ body }) {
|
|
|
154
198
|
});
|
|
155
199
|
return formData;
|
|
156
200
|
}
|
|
157
|
-
function getBodyContentType(body) {
|
|
158
|
-
if (!body) return;
|
|
159
|
-
if (body instanceof Blob) return body.type || 'application/octet-stream';
|
|
160
|
-
if (typeof body === 'string') return 'text/plain';
|
|
161
|
-
if (!(body instanceof FormData)) return 'application/json';
|
|
162
|
-
}
|
|
163
|
-
async function processResponse(response) {
|
|
164
|
-
if (response.status === 204 || response.headers.get('Content-Length') === '0') return response.ok ? {
|
|
165
|
-
data: {},
|
|
166
|
-
response
|
|
167
|
-
} : {
|
|
168
|
-
error: {},
|
|
169
|
-
response
|
|
170
|
-
};
|
|
171
|
-
if (isJsonResponse(response)) {
|
|
172
|
-
// clone response before parsing every time to allow multiple reads
|
|
173
|
-
const jsonResponse = response.clone().json();
|
|
174
|
-
return resolveResponse(response, response.ok ? jsonResponse : Promise.reject(await jsonResponse));
|
|
175
|
-
}
|
|
176
|
-
const jsonResponse = new Promise((resolve, reject)=>// attempt to parse JSON for successful responses, otherwise fail
|
|
177
|
-
response.clone().text().then(JSON.parse).then(resolve, reject));
|
|
178
|
-
return resolveResponse(response, response.ok ? jsonResponse : Promise.reject(await jsonResponse));
|
|
179
|
-
}
|
|
180
|
-
function isJsonResponse(response) {
|
|
181
|
-
const contentType = response.headers.get('Content-Type')?.toLowerCase();
|
|
182
|
-
return contentType?.includes('/json') || contentType?.includes('+json');
|
|
183
|
-
}
|
|
184
|
-
function resolveResponse(responseToReturn, responsePromise) {
|
|
185
|
-
if (!responsePromise) return Promise.reject({
|
|
186
|
-
error: responseToReturn,
|
|
187
|
-
response: undefined,
|
|
188
|
-
data: undefined
|
|
189
|
-
});
|
|
190
|
-
return responsePromise.then((data)=>({
|
|
191
|
-
data,
|
|
192
|
-
response: responseToReturn
|
|
193
|
-
})).catch((error)=>({
|
|
194
|
-
error,
|
|
195
|
-
response: responseToReturn
|
|
196
|
-
}));
|
|
197
|
-
}
|
|
198
201
|
|
|
199
202
|
export { baseRequestFn, bodySerializer, mergeHeaders, requestFn, urlSerializer };
|
|
200
203
|
//# sourceMappingURL=requestFn.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"requestFn.js","sources":["../../../src/lib/requestFn.ts"],"sourcesContent":["import type {\n HeadersOptions,\n OperationSchema,\n RequestFnInfo,\n RequestFnOptions,\n RequestFnResponse,\n} from '@openapi-qraft/tanstack-query-react-types';\n\n/**\n * This function is used to make a request to a specified endpoint.\n *\n * @template T The expected return type of the request.\n *\n * @param schema The schema of the operation to be performed. It includes the OpenAPI path, HTTP method and media type.\n * @param requestInfo The information required to make the request. It includes parameters, headers, body, etc.\n * @param [options] Optional. Additional options for the request. It includes custom urlSerializer, bodySerializer, and fetch function.\n *\n * @returns {Promise<T>} Returns a promise that resolves with the response of the request.\n *\n * @throws {error: object|string, response: Response} Throws an error if the request fails. The error includes the error message and the response from the server.\n */\nexport async function requestFn<TData, TError>(\n schema: OperationSchema,\n requestInfo: RequestFnInfo,\n options?: RequestFnOptions\n): Promise<RequestFnResponse<TData, TError>> {\n return baseRequestFn<TData, TError>(schema, requestInfo, {\n urlSerializer,\n bodySerializer,\n ...options,\n });\n}\n\n/**\n * This function is used to make a request to a specified endpoint.\n * It's needed to create a custom `requestFn` with a custom `urlSerializer`\n * and `bodySerializer`, with the tree-shaking of the default `requestFn`\n * and its serializers.\n *\n * @template T The expected return type of the request.\n *\n * @param requestSchema The schema of the operation to be performed. It includes the OpenAPI path, HTTP method and media type.\n * @param requestInfo The information required to make the request. It includes parameters, headers, body, etc.\n * @param options The options for the request. It includes urlSerializer, bodySerializer, and fetch function. The 'urlSerializer' and 'bodySerializer' are required.\n *\n * @returns {Promise<T>} Returns a promise that resolves with the response of the request.\n *\n * @throws {error: object|string, response: Response} Throws an error if the request fails. The error includes the error message and the response from the server.\n */\nexport async function baseRequestFn<TData, TError>(\n requestSchema: OperationSchema,\n requestInfo: RequestFnInfo,\n options: WithRequired<RequestFnOptions, 'urlSerializer' | 'bodySerializer'>\n): Promise<RequestFnResponse<TData, TError>> {\n const { parameters, headers, body, ...requestInfoRest } = requestInfo;\n\n const requestBody = options.bodySerializer(requestSchema, requestInfo);\n\n const baseFetch = options.fetch ?? fetch;\n\n return baseFetch(options.urlSerializer(requestSchema, requestInfo), {\n method: requestSchema.method.toUpperCase(),\n body: requestBody,\n headers: mergeHeaders(\n {\n Accept: 'application/json',\n 'Content-Type': requestSchema.mediaType ?? getBodyContentType(body),\n },\n headers,\n parameters?.header,\n requestBody instanceof FormData\n ? // remove `Content-Type` if the serialized body is FormData; the browser will correctly set Content-Type & boundary expression\n { 'Content-Type': null }\n : undefined\n ),\n ...requestInfoRest,\n })\n .then(processResponse as typeof processResponse<TData, TError>)\n .catch(resolveResponse as typeof resolveResponse<TData, TError>);\n}\n\n/**\n * Serializes the given schema and request payload into a URL string.\n *\n * This function is implemented according to the URI Template standard\n * defined in RFC 6570. It supports the expansion of path and query parameters,\n * correctly handling empty arrays, `null`, and `undefined` values by ignoring\n * them during the expansion process, as specified by the standard.\n *\n * For more information, refer to the official documentation:\n * https://datatracker.ietf.org/doc/html/rfc6570\n *\n * @param schema - The operation schema containing the URL template and method.\n * @param info - The request payload including baseUrl, path parameters, and query parameters.\n * @returns The fully constructed URL string.\n */\nexport function urlSerializer(\n schema: OperationSchema,\n info: Pick<RequestFnInfo, 'baseUrl' | 'parameters'>\n): string {\n const path = schema.url.replace(\n /{(.*?)}/g,\n (substring: string, group: string) => {\n if (\n info.parameters?.path &&\n Object.prototype.hasOwnProperty.call(info.parameters.path, group)\n ) {\n return encodeURI(String(info.parameters?.path[group]));\n }\n return substring;\n }\n );\n\n const baseUrl = info.baseUrl ?? '';\n\n if (info.parameters?.query) {\n return `${baseUrl}${path}${getQueryString(info.parameters.query)}`;\n }\n\n return `${baseUrl}${path}`;\n}\n\nfunction getQueryString(params: Record<string, any>): string {\n const qs: string[] = [];\n\n const append = (key: string, value: any) => {\n qs.push(`${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`);\n };\n\n const process = (key: string, value: any) => {\n if (typeof value === 'undefined' || value === null) return;\n\n if (Array.isArray(value)) {\n value.forEach((v) => {\n process(key, v);\n });\n } else if (typeof value === 'object') {\n Object.entries(value).forEach(([k, v]) => {\n process(`${key}[${k}]`, v);\n });\n } else {\n append(key, value);\n }\n };\n\n Object.entries(params).forEach(([key, value]) => {\n process(key, value);\n });\n\n if (qs.length > 0) {\n return `?${qs.join('&')}`;\n }\n\n return '';\n}\n\nexport function mergeHeaders(...allHeaders: (HeadersOptions | undefined)[]) {\n const headers = new Headers();\n\n for (const headerSet of allHeaders) {\n if (!headerSet || typeof headerSet !== 'object') {\n continue;\n }\n\n const headersIterator =\n headerSet instanceof Headers\n ? headerSet.entries()\n : Object.entries(headerSet);\n\n for (const [headerKey, headerValue] of headersIterator) {\n if (headerValue === null) {\n headers.delete(headerKey);\n } else if (headerValue !== undefined) {\n headers.set(headerKey, headerValue);\n }\n }\n }\n\n return headers;\n}\n\nexport function bodySerializer(schema: OperationSchema, info: RequestFnInfo) {\n if (info.body === undefined) return;\n\n if (\n schema.method === 'get' ||\n schema.method === 'head' ||\n schema.method === 'options'\n )\n return;\n\n if (schema.mediaType?.includes('/form-data'))\n return getRequestBodyFormData(info);\n\n if (\n !schema.mediaType?.includes('/json') &&\n (typeof info.body === 'string' ||\n info.body instanceof Blob ||\n info.body instanceof FormData)\n ) {\n return info.body;\n }\n\n return JSON.stringify(info.body);\n}\n\nfunction getRequestBodyFormData({\n body,\n}: Pick<RequestFnInfo, 'body'>): FormData | undefined {\n if (body instanceof FormData) return body;\n if (body === null) return;\n\n if (body instanceof Blob) throw new Error('Blob not supported in form-data');\n if (body instanceof ArrayBuffer)\n throw new Error('ArrayBuffer not supported in form-data');\n if (body instanceof URLSearchParams)\n throw new Error('URLSearchParams not supported in form-data');\n if (body instanceof ReadableStream)\n throw new Error('ReadableStream not supported in form-data');\n if (typeof body === 'string')\n throw new Error('String not supported in form-data');\n if (typeof body !== 'object')\n throw new Error(`Unsupported body type ${typeof body} in form-data.`);\n\n const formData = new FormData();\n\n const process = (key: string, value: any) => {\n if (typeof value === 'string' || value instanceof Blob) {\n formData.append(key, value);\n } else {\n formData.append(key, JSON.stringify(value));\n }\n };\n\n Object.entries(body)\n .filter(([_, value]) => typeof value !== 'undefined' && value !== null)\n .forEach(([key, value]) => {\n if (Array.isArray(value)) {\n value.forEach((v) => process(key, v));\n } else {\n process(key, value);\n }\n });\n\n return formData;\n}\n\nfunction getBodyContentType(body: RequestFnInfo['body']) {\n if (!body) return;\n if (body instanceof Blob) return body.type || 'application/octet-stream';\n if (typeof body === 'string') return 'text/plain';\n if (!(body instanceof FormData)) return 'application/json';\n}\n\nasync function processResponse<TData, TError>(\n response: Response\n): Promise<RequestFnResponse<TData, TError>> {\n if (response.status === 204 || response.headers.get('Content-Length') === '0')\n return (\n response.ok ? { data: {}, response } : { error: {}, response }\n ) as RequestFnResponse<TData, TError>;\n\n if (isJsonResponse(response)) {\n // clone response before parsing every time to allow multiple reads\n const jsonResponse = response.clone().json();\n return resolveResponse(\n response,\n response.ok ? jsonResponse : Promise.reject(await jsonResponse)\n );\n }\n\n const jsonResponse = new Promise<TData>((resolve, reject) =>\n // attempt to parse JSON for successful responses, otherwise fail\n response.clone().text().then(JSON.parse).then(resolve, reject)\n );\n\n return resolveResponse(\n response,\n response.ok ? jsonResponse : Promise.reject(await jsonResponse)\n );\n}\n\nfunction isJsonResponse(response: Response) {\n const contentType = response.headers.get('Content-Type')?.toLowerCase();\n return contentType?.includes('/json') || contentType?.includes('+json');\n}\n\nfunction resolveResponse<TData, TError>(\n error: Error\n): Promise<RequestFnResponse<TData, TError>>;\nfunction resolveResponse<TData, TError>(\n responseToReturn: Response,\n responsePromise: Promise<TData>\n): Promise<RequestFnResponse<TData, TError>>;\nfunction resolveResponse<TData, TError>(\n responseToReturn: Response | Error,\n responsePromise?: Promise<TData>\n): Promise<RequestFnResponse<TData, TError>> {\n if (!responsePromise)\n return Promise.reject({\n error: responseToReturn,\n response: undefined,\n data: undefined,\n });\n\n return responsePromise\n .then(\n (data) =>\n ({ data, response: responseToReturn }) as RequestFnResponse<\n TData,\n TError\n >\n )\n .catch(\n (error) =>\n ({ error, response: responseToReturn }) as RequestFnResponse<\n TData,\n TError\n >\n );\n}\n\ntype WithRequired<T, K extends keyof T> = T & {\n [_ in K]: {};\n};\n\nexport type {\n RequestFn,\n RequestFnResponse,\n HeadersOptions,\n RequestFnOptions,\n RequestFnInfo,\n OperationSchema,\n} from '@openapi-qraft/tanstack-query-react-types';\n\n/**\n * @deprecated use `RequestFnInfo` instead\n */\nexport type RequestFnPayload = RequestFnInfo;\n"],"names":["requestFn","schema","requestInfo","options","baseRequestFn","urlSerializer","bodySerializer","requestSchema","parameters","headers","body","requestInfoRest","requestBody","baseFetch","fetch","method","toUpperCase","mergeHeaders","Accept","mediaType","getBodyContentType","header","FormData","undefined","then","processResponse","catch","resolveResponse","info","path","url","replace","substring","group","Object","prototype","hasOwnProperty","call","encodeURI","String","baseUrl","query","getQueryString","params","qs","append","key","value","push","encodeURIComponent","process","Array","isArray","forEach","v","entries","k","length","join","allHeaders","Headers","headerSet","headersIterator","headerKey","headerValue","delete","set","includes","getRequestBodyFormData","Blob","JSON","stringify","Error","ArrayBuffer","URLSearchParams","ReadableStream","formData","filter","_","type","response","status","get","ok","data","error","isJsonResponse","jsonResponse","clone","json","Promise","reject","resolve","text","par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,IAAM7D,EAAAA,SAAAA;AACR,KAAA,CAAA,CAAA;AAEF,IAAA,OAAO2E,eACJ1E,CAAAA,IAAI,CACH,CAAC4D,QACE;AAAEA,YAAAA,IAAAA;YAAMJ,QAAUiB,EAAAA,gBAAAA;AAAiB,SAAA,CAKvCvE,CAAAA,CAAAA,KAAK,CACJ,CAAC2D,SACE;AAAEA,YAAAA,KAAAA;YAAOL,QAAUiB,EAAAA,gBAAAA;SAAiB,CAAA,CAAA,CAAA;AAK7C;;;;"}
|
|
1
|
+
{"version":3,"file":"requestFn.js","sources":["../../../src/lib/requestFn.ts"],"sourcesContent":["import type {\n HeadersOptions,\n OperationSchema,\n RequestFnInfo,\n RequestFnOptions,\n RequestFnResponse,\n} from '@openapi-qraft/tanstack-query-react-types';\nimport { processResponse, resolveResponse } from './responseUtils.js';\n\n/**\n * This function is used to make a request to a specified endpoint.\n *\n * @template T The expected return type of the request.\n *\n * @param schema The schema of the operation to be performed. It includes the OpenAPI path, HTTP method and media type.\n * @param requestInfo The information required to make the request. It includes parameters, headers, body, etc.\n * @param [options] Optional. Additional options for the request. It includes custom urlSerializer, bodySerializer, and fetch function.\n *\n * @returns {Promise<T>} Returns a promise that resolves with the response of the request.\n *\n * @throws {error: object|string, response: Response} Throws an error if the request fails. The error includes the error message and the response from the server.\n */\nexport async function requestFn<TData, TError>(\n schema: OperationSchema,\n requestInfo: RequestFnInfo,\n options?: RequestFnOptions\n): Promise<RequestFnResponse<TData, TError>> {\n return baseRequestFn<TData, TError>(schema, requestInfo, {\n urlSerializer,\n bodySerializer,\n ...options,\n });\n}\n\n/**\n * This function is used to make a request to a specified endpoint.\n * It's necessary to create a custom `requestFn` with a custom `urlSerializer`\n * and `bodySerializer`, with the tree-shaking of the default `requestFn`\n * and its serializers.\n *\n * @template T The expected return type of the request.\n *\n * @param requestSchema The schema of the operation to be performed. It includes the OpenAPI path, HTTP method and media type.\n * @param requestInfo The information required to make the request. It includes parameters, headers, body, etc.\n * @param options The options for the request. It includes urlSerializer, bodySerializer, and fetch function. The 'urlSerializer' and 'bodySerializer' are required.\n *\n * @returns {Promise<T>} Returns a promise that resolves with the response of the request.\n *\n * @throws {error: object|string, response: Response} Throws an error if the request fails. The error includes the error message and the response from the server.\n */\nexport async function baseRequestFn<TData, TError>(\n requestSchema: OperationSchema,\n requestInfo: RequestFnInfo,\n options: WithRequired<RequestFnOptions, 'urlSerializer' | 'bodySerializer'>\n): Promise<RequestFnResponse<TData, TError>> {\n const { parameters, headers, body, ...requestInfoRest } = requestInfo;\n\n const requestPayload = options.bodySerializer(requestSchema, body);\n\n const baseFetch = options.fetch ?? fetch;\n\n return baseFetch(options.urlSerializer(requestSchema, requestInfo), {\n method: requestSchema.method.toUpperCase(),\n body: requestPayload?.body,\n headers: mergeHeaders(\n { Accept: 'application/json' },\n requestPayload?.headers,\n headers,\n parameters?.header\n ),\n ...requestInfoRest,\n })\n .then(processResponse as typeof processResponse<TData, TError>)\n .catch(resolveResponse as typeof resolveResponse<TData, TError>);\n}\n\n/**\n * Serializes the given schema and request payload into a URL string.\n *\n * This function is implemented according to the URI Template standard\n * defined in RFC 6570. It supports the expansion of path and query parameters,\n * correctly handling empty arrays, `null`, and `undefined` values by ignoring\n * them during the expansion process, as specified by the standard.\n *\n * For more information, refer to the official documentation:\n * https://datatracker.ietf.org/doc/html/rfc6570\n *\n * @param schema - The operation schema containing the URL template and method.\n * @param info - The request payload including baseUrl, path parameters, and query parameters.\n * @returns The fully constructed URL string.\n */\nexport function urlSerializer(\n schema: OperationSchema,\n info: Pick<RequestFnInfo, 'baseUrl' | 'parameters'>\n): string {\n const path = schema.url.replace(\n /{(.*?)}/g,\n (substring: string, group: string) => {\n if (\n info.parameters?.path &&\n Object.prototype.hasOwnProperty.call(info.parameters.path, group)\n ) {\n return encodeURI(String(info.parameters?.path[group]));\n }\n return substring;\n }\n );\n\n const baseUrl = info.baseUrl ?? '';\n\n if (info.parameters?.query) {\n return `${baseUrl}${path}${getQueryString(info.parameters.query)}`;\n }\n\n return `${baseUrl}${path}`;\n}\n\nfunction getQueryString(params: Record<string, any>): string {\n const qs: string[] = [];\n\n const append = (key: string, value: any) => {\n qs.push(`${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`);\n };\n\n const process = (key: string, value: any) => {\n if (typeof value === 'undefined' || value === null) return;\n\n if (Array.isArray(value)) {\n value.forEach((v) => {\n process(key, v);\n });\n } else if (typeof value === 'object') {\n Object.entries(value).forEach(([k, v]) => {\n process(`${key}[${k}]`, v);\n });\n } else {\n append(key, value);\n }\n };\n\n Object.entries(params).forEach(([key, value]) => {\n process(key, value);\n });\n\n if (qs.length > 0) {\n return `?${qs.join('&')}`;\n }\n\n return '';\n}\n\nexport function mergeHeaders(...allHeaders: (HeadersOptions | undefined)[]) {\n const headers = new Headers();\n\n for (const headerSet of allHeaders) {\n if (!headerSet || typeof headerSet !== 'object') {\n continue;\n }\n\n const headersIterator =\n headerSet instanceof Headers\n ? headerSet.entries()\n : Object.entries(headerSet);\n\n for (const [headerKey, headerValue] of headersIterator) {\n if (headerValue === null) {\n headers.delete(headerKey);\n } else if (headerValue !== undefined) {\n headers.set(headerKey, headerValue);\n }\n }\n }\n\n return headers;\n}\n\nexport function bodySerializer(\n schema: OperationSchema,\n body: RequestFnInfo['body']\n) {\n if (\n schema.method === 'get' ||\n schema.method === 'head' ||\n schema.method === 'options'\n )\n return undefined;\n\n if (body === undefined || body === null) return undefined;\n\n if (typeof body === 'string') {\n return {\n body,\n headers: {\n 'Content-Type':\n // prefer text/* media type\n schema.mediaType?.find((mediaType) => mediaType.includes('text/')) ??\n // prefer JSON media type, assume that body is serialized as JSON\n schema.mediaType?.find((mediaType) => mediaType.includes('/json')) ??\n 'text/plain',\n },\n };\n }\n\n if (body instanceof FormData) {\n return {\n body,\n headers: {\n // remove `Content-Type` if the serialized body is FormData;\n // the browser will correctly set Content-Type & boundary expression\n 'Content-Type': null,\n },\n };\n }\n\n if (body instanceof Blob) {\n return {\n body,\n headers: {\n 'Content-Type':\n body.type ||\n schema.mediaType?.find(\n (mediaType) =>\n !(\n mediaType.includes('text/') &&\n mediaType.includes('/form-data') &&\n mediaType.includes('/json')\n )\n ) ||\n 'application/octet-stream',\n },\n };\n }\n\n let jsonMediaType: string | null = null;\n let formDataMediaType: string | null = null;\n\n if (schema.mediaType) {\n for (let i = 0; i < schema.mediaType.length; i++) {\n const mediaType = schema.mediaType[i];\n if (mediaType.includes('/json')) jsonMediaType = mediaType;\n else if (mediaType.includes('/form-data')) formDataMediaType = mediaType;\n }\n }\n\n if (formDataMediaType) {\n if (\n !jsonMediaType ||\n // Prefer FormData serialization if one of the fields is a Blob\n Object.values(body).some((value) => value instanceof Blob)\n ) {\n return {\n body: getRequestBodyFormData(body),\n headers: {\n // remove `Content-Type` if the serialized body is FormData;\n // the browser will correctly set Content-Type & boundary expression\n 'Content-Type': null,\n },\n };\n }\n }\n\n return {\n body: JSON.stringify(body),\n headers: {\n 'Content-Type': jsonMediaType ?? 'application/json',\n },\n };\n}\n\nfunction getRequestBodyFormData(\n body: NonNullable<RequestFnInfo['body']>\n): FormData {\n if (body instanceof FormData) return body;\n if (typeof body !== 'object')\n throw new Error(`Unsupported body type ${typeof body} in form-data.`);\n\n const formData = new FormData();\n\n const process = (key: string, value: any) => {\n if (typeof value === 'string' || value instanceof Blob) {\n formData.append(key, value);\n } else {\n formData.append(key, JSON.stringify(value));\n }\n };\n\n Object.entries(body)\n .filter(([_, value]) => typeof value !== 'undefined' && value !== null)\n .forEach(([key, value]) => {\n if (Array.isArray(value)) {\n value.forEach((v) => process(key, v));\n } else {\n process(key, value);\n }\n });\n\n return formData;\n}\n\ntype WithRequired<T, K extends keyof T> = T & {\n [_ in K]: {};\n};\n\nexport type {\n RequestFn,\n RequestFnResponse,\n HeadersOptions,\n RequestFnOptions,\n RequestFnInfo,\n OperationSchema,\n} from '@openapi-qraft/tanstack-query-react-types';\n\n/**\n * @deprecated use `RequestFnInfo` instead\n */\nexport type RequestFnPayload = RequestFnInfo;\n"],"names":["requestFn","schema","requestInfo","options","baseRequestFn","urlSerializer","bodySerializer","requestSchema","parameters","headers","body","requestInfoRest","requestPayload","baseFetch","fetch","method","toUpperCase","mergeHeaders","Accept","header","then","processResponse","catch","resolveResponse","info","path","url","replace","substring","group","Object","prototype","hasOwnProperty","call","encodeURI","String","baseUrl","query","getQueryString","params","qs","append","key","value","push","encodeURIComponent","process","Array","isArray","forEach","v","entries","k","length","join","allHeaders","Headers","headerSet","headersIterator","headerKey","headerValue","delete","undefined","set","mediaType","find","includes","FormData","Blob","type","jsonMediaType","formDataMediaType","i","values","some","getRequestBodyFormData","JSON","stringify","Error","formData","filter","_"],"mappings":";;AASA;;;;;;;;;;;;AAYC,IACM,eAAeA,SAAAA,CACpBC,MAAuB,EACvBC,WAA0B,EAC1BC,OAA0B,EAAA;IAE1B,OAAOC,aAAAA,CAA6BH,QAAQC,WAAa,EAAA;AACvDG,QAAAA,aAAAA;AACAC,QAAAA,cAAAA;AACA,QAAA,GAAGH,OAAO;AACZ,KAAA,CAAA,CAAA;AACF,CAAA;AAEA;;;;;;;;;;;;;;;AAeC,IACM,eAAeC,aAAAA,CACpBG,aAA8B,EAC9BL,WAA0B,EAC1BC,OAA2E,EAAA;IAE3E,MAAM,EAAEK,UAAU,EAAEC,OAAO,EAAEC,IAAI,EAAE,GAAGC,eAAAA,EAAiB,GAAGT,WAAAA,CAAAA;AAE1D,IAAA,MAAMU,cAAiBT,GAAAA,OAAAA,CAAQG,cAAc,CAACC,aAAeG,EAAAA,IAAAA,CAAAA,CAAAA;IAE7D,MAAMG,SAAAA,GAAYV,OAAQW,CAAAA,KAAK,IAAIA,KAAAA,CAAAA;AAEnC,IAAA,OAAOD,SAAUV,CAAAA,OAAAA,CAAQE,aAAa,CAACE,eAAeL,WAAc,CAAA,EAAA;QAClEa,MAAQR,EAAAA,aAAAA,CAAcQ,MAAM,CAACC,WAAW,EAAA;AACxCN,QAAAA,IAAAA,EAAME,cAAgBF,EAAAA,IAAAA;AACtBD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GAAKC,EAAAA,KAAAA,CAAAA,CAAAA;SAChB,MAAA;AACLoC,YAAAA,QAAAA,CAAStC,MAAM,CAACC,GAAKkC,EAAAA,IAAAA,CAAKC,SAAS,CAAClC,KAAAA,CAAAA,CAAAA,CAAAA;AACtC,SAAA;AACF,KAAA,CAAA;IAEAb,MAAOqB,CAAAA,OAAO,CAACzC,IACZsE,CAAAA,CAAAA,MAAM,CAAC,CAAC,CAACC,GAAGtC,KAAM,CAAA,GAAK,OAAOA,KAAU,KAAA,WAAA,IAAeA,UAAU,IACjEM,CAAAA,CAAAA,OAAO,CAAC,CAAC,CAACP,KAAKC,KAAM,CAAA,GAAA;QACpB,IAAII,KAAAA,CAAMC,OAAO,CAACL,KAAQ,CAAA,EAAA;AACxBA,YAAAA,KAAAA,CAAMM,OAAO,CAAC,CAACC,CAAAA,GAAMJ,QAAQJ,GAAKQ,EAAAA,CAAAA,CAAAA,CAAAA,CAAAA;SAC7B,MAAA;AACLJ,YAAAA,OAAAA,CAAQJ,GAAKC,EAAAA,KAAAA,CAAAA,CAAAA;AACf,SAAA;AACF,KAAA,CAAA,CAAA;IAEF,OAAOoC,QAAAA,CAAAA;AACT;;;;"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Processes the response from the server.
|
|
3
|
+
* @beta
|
|
4
|
+
*/ async function processResponse(response) {
|
|
5
|
+
if (response.status === 204 || response.headers.get('Content-Length') === '0') return response.ok ? {
|
|
6
|
+
data: {},
|
|
7
|
+
response
|
|
8
|
+
} : {
|
|
9
|
+
error: {},
|
|
10
|
+
response
|
|
11
|
+
};
|
|
12
|
+
const contentType = response.headers.get('Content-Type')?.toLowerCase();
|
|
13
|
+
const isJsonResponse = contentType?.includes('/json') || contentType?.includes('+json');
|
|
14
|
+
if (isJsonResponse) {
|
|
15
|
+
// clone response before parsing every time to allow multiple reads
|
|
16
|
+
const jsonResponse = response.clone().json();
|
|
17
|
+
return resolveResponse(response, response.ok ? jsonResponse : Promise.reject(await jsonResponse));
|
|
18
|
+
}
|
|
19
|
+
const textResponse = response.clone().text();
|
|
20
|
+
return resolveResponse(response, response.ok ? textResponse : Promise.reject(await textResponse));
|
|
21
|
+
}
|
|
22
|
+
function resolveResponse(responseToReturn, responsePromise) {
|
|
23
|
+
if (!responsePromise) return Promise.reject({
|
|
24
|
+
error: responseToReturn,
|
|
25
|
+
response: undefined,
|
|
26
|
+
data: undefined
|
|
27
|
+
});
|
|
28
|
+
return responsePromise.then((data)=>({
|
|
29
|
+
data,
|
|
30
|
+
response: responseToReturn
|
|
31
|
+
})).catch((error)=>({
|
|
32
|
+
error,
|
|
33
|
+
response: responseToReturn
|
|
34
|
+
}));
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export { processResponse, resolveResponse };
|
|
38
|
+
//# sourceMappingURL=responseUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"responseUtils.js","sources":["../../../src/lib/responseUtils.ts"],"sourcesContent":["import type { RequestFnResponse } from '@openapi-qraft/tanstack-query-react-types';\n\n/**\n * Processes the response from the server.\n * @beta\n */\nexport async function processResponse<TData, TError>(\n response: Response\n): Promise<RequestFnResponse<TData, TError>> {\n if (response.status === 204 || response.headers.get('Content-Length') === '0')\n return (\n response.ok ? { data: {}, response } : { error: {}, response }\n ) as RequestFnResponse<TData, TError>;\n\n const contentType = response.headers.get('Content-Type')?.toLowerCase();\n\n const isJsonResponse =\n contentType?.includes('/json') || contentType?.includes('+json');\n\n if (isJsonResponse) {\n // clone response before parsing every time to allow multiple reads\n const jsonResponse = response.clone().json();\n return resolveResponse(\n response,\n response.ok ? jsonResponse : Promise.reject(await jsonResponse)\n );\n }\n\n const textResponse = response.clone().text() as Promise<TData>;\n\n return resolveResponse(\n response,\n response.ok ? textResponse : Promise.reject(await textResponse)\n );\n}\n\n/**\n * Resolves the response from the server.\n * @beta\n */\nexport function resolveResponse<TData, TError>(\n error: Error\n): Promise<RequestFnResponse<TData, TError>>;\nexport function resolveResponse<TData, TError>(\n responseToReturn: Response,\n responsePromise: Promise<TData>\n): Promise<RequestFnResponse<TData, TError>>;\nexport function resolveResponse<TData, TError>(\n responseToReturn: Response | Error,\n responsePromise?: Promise<TData>\n): Promise<RequestFnResponse<TData, TError>> {\n if (!responsePromise)\n return Promise.reject({\n error: responseToReturn,\n response: undefined,\n data: undefined,\n });\n\n return responsePromise\n .then(\n (data) =>\n ({ data, response: responseToReturn }) as RequestFnResponse<\n TData,\n TError\n >\n )\n .catch(\n (error) =>\n ({ error, response: responseToReturn }) as RequestFnResponse<\n TData,\n TError\n >\n );\n}\n"],"names":["processResponse","response","status","headers","get","ok","data","error","contentType","toLowerCase","isJsonResponse","includes","jsonResponse","clone","json","resolveResponse","Promise","reject","textResponse","text","responseToReturn","responsePromise","undefined","then","catch"],"mappings":"AAEA;;;IAIO,eAAeA,eAAAA,CACpBC,QAAkB,EAAA;AAElB,IAAA,IAAIA,QAASC,CAAAA,MAAM,KAAK,GAAA,IAAOD,SAASE,OAAO,CAACC,GAAG,CAAC,gBAAsB,CAAA,KAAA,GAAA,EACxE,OACEH,QAAAA,CAASI,EAAE,GAAG;AAAEC,QAAAA,IAAAA,EAAM,EAAC;AAAGL,QAAAA,QAAAA;KAAa,GAAA;AAAEM,QAAAA,KAAAA,EAAO,EAAC;AAAGN,QAAAA,QAAAA;AAAS,KAAA,CAAA;AAGjE,IAAA,MAAMO,cAAcP,QAASE,CAAAA,OAAO,CAACC,GAAG,CAAC,cAAiBK,CAAAA,EAAAA,WAAAA,EAAAA,CAAAA;AAE1D,IAAA,MAAMC,cACJF,GAAAA,WAAAA,EAAaG,QAAS,CAAA,OAAA,CAAA,IAAYH,aAAaG,QAAS,CAAA,OAAA,CAAA,CAAA;AAE1D,IAAA,IAAID,cAAgB,EAAA;;AAElB,QAAA,MAAME,YAAeX,GAAAA,QAAAA,CAASY,KAAK,EAAA,CAAGC,IAAI,EAAA,CAAA;QAC1C,OAAOC,eAAAA,CACLd,UACAA,QAASI,CAAAA,EAAE,GAAGO,YAAeI,GAAAA,OAAAA,CAAQC,MAAM,CAAC,MAAML,YAAAA,CAAAA,CAAAA,CAAAA;AAEtD,KAAA;AAEA,IAAA,MAAMM,YAAejB,GAAAA,QAAAA,CAASY,KAAK,EAAA,CAAGM,IAAI,EAAA,CAAA;IAE1C,OAAOJ,eAAAA,CACLd,UACAA,QAASI,CAAAA,EAAE,GAAGa,YAAeF,GAAAA,OAAAA,CAAQC,MAAM,CAAC,MAAMC,YAAAA,CAAAA,CAAAA,CAAAA;AAEtD,CAAA;AAaO,SAASH,eAAAA,CACdK,gBAAkC,EAClCC,eAAgC,EAAA;AAEhC,IAAA,IAAI,CAACA,eAAAA,EACH,OAAOL,OAAAA,CAAQC,MAAM,CAAC;QACpBV,KAAOa,EAAAA,gBAAAA;QACPnB,QAAUqB,EAAAA,SAAAA;QACVhB,IAAMgB,EAAAA,SAAAA;AACR,KAAA,CAAA,CAAA;AAEF,IAAA,OAAOD,eACJE,CAAAA,IAAI,CACH,CAACjB,QACE;AAAEA,YAAAA,IAAAA;YAAML,QAAUmB,EAAAA,gBAAAA;AAAiB,SAAA,CAKvCI,CAAAA,CAAAA,KAAK,CACJ,CAACjB,SACE;AAAEA,YAAAA,KAAAA;YAAON,QAAUmB,EAAAA,gBAAAA;SAAiB,CAAA,CAAA,CAAA;AAK7C;;;;"}
|
|
@@ -11,8 +11,8 @@ function qraftAPIClient(services, callbacks, options) {
|
|
|
11
11
|
assertValidCallbackName(callbackName, callbacks);
|
|
12
12
|
const serviceOperation = getByPath(services, path);
|
|
13
13
|
if (!isServiceOperation(serviceOperation)) throw new Error(`Service operation not found: ${path.join('.')}`);
|
|
14
|
-
if (callbackName !== 'operationInvokeFn' && callbackName !== 'getQueryKey' && callbackName !== 'getMutationKey') {
|
|
15
|
-
if (!options || !('queryClient' in options && options.queryClient)) throw new Error(`'qraft.<service>.<operation>.${String(callbackName)}()' requires 'queryClient' in options.`);
|
|
14
|
+
if (callbackName !== 'operationInvokeFn' && callbackName !== 'getQueryKey' && callbackName !== 'getMutationKey' && callbackName !== 'getInfiniteQueryKey') {
|
|
15
|
+
if (!options || !('queryClient' in options && options.queryClient)) throw new Error(`'qraft.<service>.<operation>.${String(callbackName)}()' requires 'queryClient' in 'createAPIClient(...)' 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 {\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 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 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","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":";;AAwFO,SAASA,cAIdC,CAAAA,QAA6C,EAC7CC,SAAqB,EACrBC,OAAgC,EAAA;AAEhC,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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MF,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;;;;"}
|
|
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 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 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[]) {\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 | '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","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":";;AAwFO,SAASA,cAIdC,CAAAA,QAA6C,EAC7CC,SAAqB,EACrBC,OAAgC,EAAA;AAEhC,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,IAAI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AC9C,EAAA,MAAM,IAAIP,KACR,CAAA,CAAC,yIAAyI,CAAC,CAAA,CAAA;QAE/I,MAAM,IAAIA,MACR,CAAC,0CAA0C,EAAEW,MAAOJ,CAAAA,YAAAA,CAAAA,CAAc,8CAA8C,CAAC,CAAA,CAAA;AAErH,KAAA;AACF,CAAA;AAEA;;;IAIA,SAASC,uBAAuBJ,SAAmB,EAAA;;IAEjD,IAAIA,SAAAA,CAAUR,MAAM,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;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unstable__responseUtils.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ServiceOperationFetchInfiniteQuery } from '@openapi-qraft/tanstack-query-react-types';
|
|
2
|
+
import type { DefaultError } from '@tanstack/query-core';
|
|
3
|
+
import type { CreateAPIQueryClientOptions } from '../qraftAPIClient.js';
|
|
4
|
+
export declare const ensureInfiniteQueryData: <TSchema extends {
|
|
5
|
+
url: string;
|
|
6
|
+
method: 'get' | 'head' | 'options';
|
|
7
|
+
}, TData, TParams>(qraftOptions: CreateAPIQueryClientOptions, schema: TSchema, args: Parameters<ServiceOperationFetchInfiniteQuery<TSchema, TData, TParams, DefaultError>['ensureInfiniteQueryData']>) => Promise<TData>;
|
|
8
|
+
//# sourceMappingURL=ensureInfiniteQueryData.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ensureInfiniteQueryData.d.ts","sourceRoot":"","sources":["../../../src/callbacks/ensureInfiniteQueryData.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kCAAkC,EAAE,MAAM,2CAA2C,CAAC;AACpG,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,sBAAsB,CAAC;AAGxE,eAAO,MAAM,uBAAuB,EAAE,CACpC,OAAO,SAAS;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,KAAK,GAAG,MAAM,GAAG,SAAS,CAAA;CAAE,EACnE,KAAK,EACL,OAAO,EAEP,YAAY,EAAE,2BAA2B,EACzC,MAAM,EAAE,OAAO,EACf,IAAI,EAAE,UAAU,CACd,kCAAkC,CAChC,OAAO,EACP,KAAK,EACL,OAAO,EACP,YAAY,CACb,CAAC,yBAAyB,CAAC,CAC7B,KACE,OAAO,CAAC,KAAK,CAQjB,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ServiceOperationFetchQuery } from '@openapi-qraft/tanstack-query-react-types';
|
|
2
|
+
import type { DefaultError } from '@tanstack/query-core';
|
|
3
|
+
import type { CreateAPIQueryClientOptions } from '../qraftAPIClient.js';
|
|
4
|
+
export declare const ensureQueryData: <TSchema extends {
|
|
5
|
+
url: string;
|
|
6
|
+
method: 'get' | 'head' | 'options';
|
|
7
|
+
}, TData, TParams>(qraftOptions: CreateAPIQueryClientOptions, schema: TSchema, args: Parameters<ServiceOperationFetchQuery<TSchema, TData, TParams, DefaultError>['ensureQueryData']>) => Promise<TData>;
|
|
8
|
+
//# sourceMappingURL=ensureQueryData.d.ts.map
|