@geekmidas/client 10.0.0-alpha.9 → 10.0.0-alpha.91
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/README.md +40 -57
- package/dist/auth-fetcher.cjs +78 -3
- package/dist/auth-fetcher.cjs.map +1 -0
- package/dist/auth-fetcher.d.cts +156 -3
- package/dist/auth-fetcher.d.cts.map +1 -0
- package/dist/auth-fetcher.d.mts +156 -3
- package/dist/auth-fetcher.d.mts.map +1 -0
- package/dist/auth-fetcher.mjs +77 -3
- package/dist/auth-fetcher.mjs.map +1 -0
- package/dist/endpoint-hooks.cjs +11 -15
- package/dist/endpoint-hooks.cjs.map +1 -1
- package/dist/endpoint-hooks.d.cts +4 -7
- package/dist/endpoint-hooks.d.cts.map +1 -1
- package/dist/endpoint-hooks.d.mts +4 -7
- package/dist/endpoint-hooks.d.mts.map +1 -1
- package/dist/endpoint-hooks.mjs +5 -9
- package/dist/endpoint-hooks.mjs.map +1 -1
- package/dist/fetcher.cjs +115 -3
- package/dist/fetcher.cjs.map +1 -0
- package/dist/fetcher.d.cts +24 -3
- package/dist/fetcher.d.cts.map +1 -0
- package/dist/fetcher.d.mts +24 -3
- package/dist/fetcher.d.mts.map +1 -0
- package/dist/fetcher.mjs +90 -2
- package/dist/fetcher.mjs.map +1 -0
- package/dist/index.cjs +13 -6
- package/dist/index.d.cts +7 -5
- package/dist/index.d.mts +7 -5
- package/dist/index.mjs +7 -6
- package/dist/infer.cjs +0 -1
- package/dist/infer.d.cts +130 -2
- package/dist/infer.d.cts.map +1 -0
- package/dist/infer.d.mts +130 -2
- package/dist/infer.d.mts.map +1 -0
- package/dist/infer.mjs +1 -1
- package/dist/methods.cjs +21 -0
- package/dist/methods.cjs.map +1 -0
- package/dist/methods.d.cts +23 -0
- package/dist/methods.d.cts.map +1 -0
- package/dist/methods.d.mts +23 -0
- package/dist/methods.d.mts.map +1 -0
- package/dist/methods.mjs +19 -0
- package/dist/methods.mjs.map +1 -0
- package/dist/openapi-hooks.cjs +13 -16
- package/dist/openapi-hooks.cjs.map +1 -1
- package/dist/openapi-hooks.d.cts +8 -11
- package/dist/openapi-hooks.d.cts.map +1 -1
- package/dist/openapi-hooks.d.mts +8 -11
- package/dist/openapi-hooks.d.mts.map +1 -1
- package/dist/openapi-hooks.mjs +9 -12
- package/dist/openapi-hooks.mjs.map +1 -1
- package/dist/openapi-types.d.cts +5 -6
- package/dist/openapi-types.d.cts.map +1 -1
- package/dist/openapi-types.d.mts +5 -6
- package/dist/openapi-types.d.mts.map +1 -1
- package/dist/react-query.cjs +17 -16
- package/dist/react-query.cjs.map +1 -1
- package/dist/react-query.d.cts +12 -17
- package/dist/react-query.d.cts.map +1 -1
- package/dist/react-query.d.mts +12 -17
- package/dist/react-query.d.mts.map +1 -1
- package/dist/react-query.mjs +10 -9
- package/dist/react-query.mjs.map +1 -1
- package/dist/telemetry-g3BE86Wd.d.cts +68 -0
- package/dist/telemetry-g3BE86Wd.d.cts.map +1 -0
- package/dist/telemetry-g3BE86Wd.d.mts +68 -0
- package/dist/telemetry-g3BE86Wd.d.mts.map +1 -0
- package/dist/telemetry.cjs +128 -0
- package/dist/telemetry.cjs.map +1 -0
- package/dist/telemetry.d.cts +2 -0
- package/dist/telemetry.d.mts +2 -0
- package/dist/telemetry.mjs +125 -0
- package/dist/telemetry.mjs.map +1 -0
- package/dist/types.cjs +0 -1
- package/dist/types.d.cts +122 -2
- package/dist/types.d.cts.map +1 -0
- package/dist/types.d.mts +122 -2
- package/dist/types.d.mts.map +1 -0
- package/dist/types.mjs +1 -1
- package/package.json +22 -9
- package/dist/auth-fetcher-CBYuL6rx.d.cts +0 -158
- package/dist/auth-fetcher-CBYuL6rx.d.cts.map +0 -1
- package/dist/auth-fetcher-DOj0iz21.mjs +0 -77
- package/dist/auth-fetcher-DOj0iz21.mjs.map +0 -1
- package/dist/auth-fetcher-DxS8zOLc.d.mts +0 -158
- package/dist/auth-fetcher-DxS8zOLc.d.mts.map +0 -1
- package/dist/auth-fetcher-HILABmws.cjs +0 -82
- package/dist/auth-fetcher-HILABmws.cjs.map +0 -1
- package/dist/chunk-CUT6urMc.cjs +0 -30
- package/dist/fetcher-C1xtCKpT.d.mts +0 -25
- package/dist/fetcher-C1xtCKpT.d.mts.map +0 -1
- package/dist/fetcher-CakjC9C7.mjs +0 -88
- package/dist/fetcher-CakjC9C7.mjs.map +0 -1
- package/dist/fetcher-CwnSqc4D.cjs +0 -100
- package/dist/fetcher-CwnSqc4D.cjs.map +0 -1
- package/dist/fetcher-cDrfwN-Y.d.cts +0 -25
- package/dist/fetcher-cDrfwN-Y.d.cts.map +0 -1
- package/dist/infer-6KKCgmg1.cjs +0 -0
- package/dist/infer-CPRqfabW.d.cts +0 -133
- package/dist/infer-CPRqfabW.d.cts.map +0 -1
- package/dist/infer-D9CgpOuc.d.mts +0 -133
- package/dist/infer-D9CgpOuc.d.mts.map +0 -1
- package/dist/infer-uCUq1whM.mjs +0 -0
- package/dist/openapi.cjs +0 -526
- package/dist/openapi.cjs.map +0 -1
- package/dist/openapi.mjs +0 -501
- package/dist/openapi.mjs.map +0 -1
- package/dist/types-BH8WgGrm.mjs +0 -0
- package/dist/types-BMGM6sZc.d.mts +0 -110
- package/dist/types-BMGM6sZc.d.mts.map +0 -1
- package/dist/types-DMQMHePI.d.cts +0 -110
- package/dist/types-DMQMHePI.d.cts.map +0 -1
- package/dist/types-a8gm_IaQ.cjs +0 -0
package/dist/react-query.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react-query.cjs","names":["options: TypedQueryClientOptions","endpoint: T","config?: FilteredRequestConfig<Paths, T>","options?: Omit<\n\t\t\tUseQueryOptions<ExtractEndpointResponse<Paths, T>, Response>,\n\t\t\t'queryKey' | 'queryFn'\n\t\t>","options?: Omit<\n\t\t\tUseMutationOptions<\n\t\t\t\tExtractEndpointResponse<Paths, T>,\n\t\t\t\tResponse,\n\t\t\t\tFilteredRequestConfig<Paths, T>\n\t\t\t>,\n\t\t\t'mutationFn'\n\t\t>","config: FilteredRequestConfig<Paths, T>","options: Omit<\n\t\t\tUseInfiniteQueryOptions<\n\t\t\t\tTPageData,\n\t\t\t\tResponse,\n\t\t\t\t{ pages: TPageData[]; pageParams: TPageParam[] },\n\t\t\t\tunknown[],\n\t\t\t\tTPageParam\n\t\t\t>,\n\t\t\t'queryKey' | 'queryFn' | 'getNextPageParam' | 'initialPageParam'\n\t\t> & {\n\t\t\tgetNextPageParam: (\n\t\t\t\tlastPage: TPageData,\n\t\t\t\tallPages: TPageData[],\n\t\t\t\tlastPageParam: TPageParam,\n\t\t\t\tallPageParams: TPageParam[],\n\t\t\t) => TPageParam | undefined;\n\t\t\tinitialPageParam: TPageParam;\n\t\t}","key: unknown[]","queryClient: QueryClient","options?: TypedQueryClientOptions","client: TypedQueryClient<Paths>","options?: Omit<\n\t\tUseQueryOptions<ExtractEndpointResponse<Paths, T>, Response>,\n\t\t'queryKey' | 'queryFn'\n\t>","options?: Omit<\n\t\tUseMutationOptions<\n\t\t\tExtractEndpointResponse<Paths, T>,\n\t\t\tResponse,\n\t\t\tFilteredRequestConfig<Paths, T>\n\t\t>,\n\t\t'mutationFn'\n\t>","options: Omit<\n\t\tUseInfiniteQueryOptions<\n\t\t\tTPageData,\n\t\t\tResponse,\n\t\t\t{ pages: TPageData[]; pageParams: TPageParam[] },\n\t\t\tunknown[],\n\t\t\tTPageParam\n\t\t>,\n\t\t'queryKey' | 'queryFn' | 'getNextPageParam' | 'initialPageParam'\n\t> & {\n\t\tgetNextPageParam: (\n\t\t\tlastPage: TPageData,\n\t\t\tallPages: TPageData[],\n\t\t\tlastPageParam: TPageParam,\n\t\t\tallPageParams: TPageParam[],\n\t\t) => TPageParam | undefined;\n\t\tinitialPageParam: TPageParam;\n\t}"],"sources":["../src/react-query.ts"],"sourcesContent":["import type {\n\tQueryClient,\n\tQueryFunctionContext,\n\tUseInfiniteQueryOptions,\n\tUseMutationOptions,\n\tUseQueryOptions,\n} from '@tanstack/react-query';\nimport {\n\tuseInfiniteQuery,\n\tuseMutation,\n\tuseQuery,\n\tuseQueryClient,\n} from '@tanstack/react-query';\nimport { useMemo } from 'react';\nimport { createTypedFetcher } from './fetcher';\nimport type {\n\tExtractEndpointResponse,\n\tFetcherOptions,\n\tFilteredRequestConfig,\n\tMutationEndpoint,\n\tQueryEndpoint,\n\tTypedEndpoint,\n} from './types';\n\nexport interface TypedQueryClientOptions extends FetcherOptions {\n\tqueryClient?: QueryClient;\n}\n\nexport class TypedQueryClient<Paths> {\n\tprivate fetcher: ReturnType<typeof createTypedFetcher<Paths>>;\n\tprivate queryClient?: QueryClient;\n\n\tconstructor(options: TypedQueryClientOptions = {}) {\n\t\tthis.fetcher = createTypedFetcher<Paths>(options);\n\t\tthis.queryClient = options.queryClient;\n\t}\n\n\tuseQuery<T extends QueryEndpoint<Paths>>(\n\t\tendpoint: T,\n\t\tconfig?: FilteredRequestConfig<Paths, T>,\n\t\toptions?: Omit<\n\t\t\tUseQueryOptions<ExtractEndpointResponse<Paths, T>, Response>,\n\t\t\t'queryKey' | 'queryFn'\n\t\t>,\n\t) {\n\t\tconst queryKey = this.buildQueryKey(endpoint, config);\n\n\t\t// Memoize the combined options to prevent unnecessary re-renders\n\t\tconst memoizedOptions = useMemo(\n\t\t\t() => ({\n\t\t\t\tqueryKey,\n\t\t\t\tqueryFn: () => this.fetcher(endpoint, config),\n\t\t\t\t...options,\n\t\t\t}),\n\t\t\t// Dependencies: queryKey, endpoint, config, and options\n\t\t\t// Note: We stringify config and options to ensure stable references\n\t\t\t// eslint-disable-next-line react-hooks/exhaustive-deps\n\t\t\t[\n\t\t\t\tqueryKey.join(','),\n\t\t\t\tendpoint,\n\t\t\t\tJSON.stringify(config),\n\t\t\t\tJSON.stringify(options),\n\t\t\t],\n\t\t);\n\n\t\treturn useQuery<ExtractEndpointResponse<Paths, T>, Response>(\n\t\t\tmemoizedOptions,\n\t\t);\n\t}\n\n\tuseMutation<T extends MutationEndpoint<Paths>>(\n\t\tendpoint: T,\n\t\toptions?: Omit<\n\t\t\tUseMutationOptions<\n\t\t\t\tExtractEndpointResponse<Paths, T>,\n\t\t\t\tResponse,\n\t\t\t\tFilteredRequestConfig<Paths, T>\n\t\t\t>,\n\t\t\t'mutationFn'\n\t\t>,\n\t) {\n\t\t// Memoize the combined options to prevent unnecessary re-renders\n\t\tconst memoizedOptions = useMemo(\n\t\t\t() => ({\n\t\t\t\tmutationFn: (config: FilteredRequestConfig<Paths, T>) =>\n\t\t\t\t\tthis.fetcher(endpoint, config),\n\t\t\t\t...options,\n\t\t\t}),\n\t\t\t// Dependencies: endpoint and options\n\t\t\t// Note: We stringify options to ensure stable reference\n\t\t\t// eslint-disable-next-line react-hooks/exhaustive-deps\n\t\t\t[endpoint, JSON.stringify(options)],\n\t\t);\n\n\t\treturn useMutation<\n\t\t\tExtractEndpointResponse<Paths, T>,\n\t\t\tResponse,\n\t\t\tFilteredRequestConfig<Paths, T>\n\t\t>(memoizedOptions);\n\t}\n\n\tuseInfiniteQuery<\n\t\tT extends QueryEndpoint<Paths>,\n\t\tTPageData = ExtractEndpointResponse<Paths, T>,\n\t\tTPageParam = unknown,\n\t>(\n\t\tendpoint: T,\n\t\toptions: Omit<\n\t\t\tUseInfiniteQueryOptions<\n\t\t\t\tTPageData,\n\t\t\t\tResponse,\n\t\t\t\t{ pages: TPageData[]; pageParams: TPageParam[] },\n\t\t\t\tunknown[],\n\t\t\t\tTPageParam\n\t\t\t>,\n\t\t\t'queryKey' | 'queryFn' | 'getNextPageParam' | 'initialPageParam'\n\t\t> & {\n\t\t\tgetNextPageParam: (\n\t\t\t\tlastPage: TPageData,\n\t\t\t\tallPages: TPageData[],\n\t\t\t\tlastPageParam: TPageParam,\n\t\t\t\tallPageParams: TPageParam[],\n\t\t\t) => TPageParam | undefined;\n\t\t\tinitialPageParam: TPageParam;\n\t\t},\n\t\tconfig?: FilteredRequestConfig<Paths, T>,\n\t) {\n\t\tconst queryKey = this.buildQueryKey(endpoint, config);\n\n\t\t// Memoize the combined options to prevent unnecessary re-renders\n\t\tconst memoizedOptions = useMemo(\n\t\t\t() => ({\n\t\t\t\tqueryKey,\n\t\t\t\tqueryFn: ({\n\t\t\t\t\tpageParam,\n\t\t\t\t}: QueryFunctionContext<unknown[], TPageParam>) => {\n\t\t\t\t\tlet mergedConfig = config;\n\t\t\t\t\tif (pageParam !== undefined && config) {\n\t\t\t\t\t\t// If pageParam is an object, spread it into query\n\t\t\t\t\t\tconst pageQuery =\n\t\t\t\t\t\t\ttypeof pageParam === 'object' ? pageParam : { page: pageParam };\n\t\t\t\t\t\tmergedConfig = {\n\t\t\t\t\t\t\t...config,\n\t\t\t\t\t\t\tquery: { ...(config as any).query, ...pageQuery },\n\t\t\t\t\t\t} as any;\n\t\t\t\t\t} else if (pageParam !== undefined && !config) {\n\t\t\t\t\t\t// If pageParam is an object, use it directly, otherwise wrap in page property\n\t\t\t\t\t\tconst pageQuery =\n\t\t\t\t\t\t\ttypeof pageParam === 'object' ? pageParam : { page: pageParam };\n\t\t\t\t\t\tmergedConfig = { query: pageQuery } as any;\n\t\t\t\t\t}\n\t\t\t\t\treturn this.fetcher(endpoint, mergedConfig) as Promise<TPageData>;\n\t\t\t\t},\n\t\t\t\t...options,\n\t\t\t}),\n\t\t\t// Dependencies: queryKey, endpoint, config, and options\n\t\t\t// Note: We stringify config and options to ensure stable references\n\t\t\t// eslint-disable-next-line react-hooks/exhaustive-deps\n\t\t\t[\n\t\t\t\tqueryKey.join(','),\n\t\t\t\tendpoint,\n\t\t\t\tJSON.stringify(config),\n\t\t\t\tJSON.stringify(options),\n\t\t\t],\n\t\t);\n\n\t\treturn useInfiniteQuery<\n\t\t\tTPageData,\n\t\t\tResponse,\n\t\t\t{ pages: TPageData[]; pageParams: TPageParam[] },\n\t\t\tunknown[],\n\t\t\tTPageParam\n\t\t>(memoizedOptions);\n\t}\n\n\tbuildQueryKey<T extends TypedEndpoint<Paths>>(\n\t\tendpoint: T,\n\t\tconfig?: FilteredRequestConfig<Paths, T>,\n\t): unknown[] {\n\t\tconst key: unknown[] = [endpoint];\n\n\t\tif (config && 'params' in config && config.params) {\n\t\t\tkey.push({ params: config.params });\n\t\t}\n\n\t\tif (config && 'query' in config && config.query) {\n\t\t\tkey.push({ query: config.query });\n\t\t}\n\n\t\treturn key;\n\t}\n\n\t/**\n\t * Invalidate queries for a specific endpoint with optional config\n\t * @param endpoint - The endpoint to invalidate (e.g., 'GET /users')\n\t * @param config - Optional params/query to match specific queries\n\t * @returns Promise that resolves when invalidation is complete\n\t */\n\tinvalidateQueries<T extends QueryEndpoint<Paths>>(\n\t\tendpoint: T,\n\t\tconfig?: FilteredRequestConfig<Paths, T>,\n\t): Promise<void> {\n\t\tconst queryClient = this.getQueryClient();\n\t\tconst queryKey = this.buildQueryKey(endpoint, config);\n\n\t\treturn queryClient.invalidateQueries({\n\t\t\tqueryKey,\n\t\t\texact: !!config, // Use exact matching if config is provided\n\t\t});\n\t}\n\n\t/**\n\t * Invalidate all queries in the cache\n\t * @returns Promise that resolves when invalidation is complete\n\t */\n\tinvalidateAllQueries(): Promise<void> {\n\t\tconst queryClient = this.getQueryClient();\n\t\treturn queryClient.invalidateQueries();\n\t}\n\n\t/**\n\t * Get the underlying QueryClient instance\n\t * @returns The QueryClient instance\n\t */\n\tgetQueryClient(): QueryClient {\n\t\tif (this.queryClient) {\n\t\t\treturn this.queryClient;\n\t\t}\n\n\t\t// If no query client was provided, try to get it from context\n\t\t// This will throw if used outside of QueryClientProvider\n\t\tthrow new Error(\n\t\t\t'No QueryClient set, please provide a QueryClient via the queryClient option or ensure you are within a QueryClientProvider',\n\t\t);\n\t}\n\n\t/**\n\t * Set the QueryClient instance\n\t * @param queryClient - The QueryClient instance to use\n\t */\n\tsetQueryClient(queryClient: QueryClient): void {\n\t\tthis.queryClient = queryClient;\n\t}\n}\n\nexport function createTypedQueryClient<Paths>(\n\toptions?: TypedQueryClientOptions,\n) {\n\treturn new TypedQueryClient<Paths>(options);\n}\n\n// Hook exports for convenience\nexport function useTypedQuery<Paths, T extends QueryEndpoint<Paths>>(\n\tclient: TypedQueryClient<Paths>,\n\tendpoint: T,\n\tconfig?: FilteredRequestConfig<Paths, T>,\n\toptions?: Omit<\n\t\tUseQueryOptions<ExtractEndpointResponse<Paths, T>, Response>,\n\t\t'queryKey' | 'queryFn'\n\t>,\n) {\n\treturn client.useQuery(endpoint, config, options);\n}\n\nexport function useTypedMutation<Paths, T extends MutationEndpoint<Paths>>(\n\tclient: TypedQueryClient<Paths>,\n\tendpoint: T,\n\toptions?: Omit<\n\t\tUseMutationOptions<\n\t\t\tExtractEndpointResponse<Paths, T>,\n\t\t\tResponse,\n\t\t\tFilteredRequestConfig<Paths, T>\n\t\t>,\n\t\t'mutationFn'\n\t>,\n) {\n\treturn client.useMutation(endpoint, options);\n}\n\nexport function useTypedInfiniteQuery<\n\tPaths,\n\tT extends QueryEndpoint<Paths>,\n\tTPageData = ExtractEndpointResponse<Paths, T>,\n\tTPageParam = unknown,\n>(\n\tclient: TypedQueryClient<Paths>,\n\tendpoint: T,\n\toptions: Omit<\n\t\tUseInfiniteQueryOptions<\n\t\t\tTPageData,\n\t\t\tResponse,\n\t\t\t{ pages: TPageData[]; pageParams: TPageParam[] },\n\t\t\tunknown[],\n\t\t\tTPageParam\n\t\t>,\n\t\t'queryKey' | 'queryFn' | 'getNextPageParam' | 'initialPageParam'\n\t> & {\n\t\tgetNextPageParam: (\n\t\t\tlastPage: TPageData,\n\t\t\tallPages: TPageData[],\n\t\t\tlastPageParam: TPageParam,\n\t\t\tallPageParams: TPageParam[],\n\t\t) => TPageParam | undefined;\n\t\tinitialPageParam: TPageParam;\n\t},\n\tconfig?: FilteredRequestConfig<Paths, T>,\n) {\n\treturn client.useInfiniteQuery(endpoint, options, config);\n}\n\n/**\n * Hook to invalidate queries using the current QueryClient from context\n */\nexport function useTypedInvalidateQueries<Paths>(\n\tclient: TypedQueryClient<Paths>,\n) {\n\tconst queryClient = useQueryClient();\n\n\treturn {\n\t\t/**\n\t\t * Invalidate queries for a specific endpoint\n\t\t */\n\t\tinvalidateQueries: <T extends QueryEndpoint<Paths>>(\n\t\t\tendpoint: T,\n\t\t\tconfig?: FilteredRequestConfig<Paths, T>,\n\t\t) => {\n\t\t\tconst queryKey = client.buildQueryKey(endpoint, config);\n\t\t\treturn queryClient.invalidateQueries({\n\t\t\t\tqueryKey,\n\t\t\t\texact: !!config,\n\t\t\t});\n\t\t},\n\n\t\t/**\n\t\t * Invalidate all queries\n\t\t */\n\t\tinvalidateAllQueries: () => {\n\t\t\treturn queryClient.invalidateQueries();\n\t\t},\n\t};\n}\n"],"mappings":";;;;;;AA4BA,IAAa,mBAAb,MAAqC;CACpC,AAAQ;CACR,AAAQ;CAER,YAAYA,UAAmC,CAAE,GAAE;AAClD,OAAK,UAAU,mCAA0B,QAAQ;AACjD,OAAK,cAAc,QAAQ;CAC3B;CAED,SACCC,UACAC,QACAC,SAIC;EACD,MAAM,WAAW,KAAK,cAAc,UAAU,OAAO;EAGrD,MAAM,kBAAkB,mBACvB,OAAO;GACN;GACA,SAAS,MAAM,KAAK,QAAQ,UAAU,OAAO;GAC7C,GAAG;EACH,IAID;GACC,SAAS,KAAK,IAAI;GAClB;GACA,KAAK,UAAU,OAAO;GACtB,KAAK,UAAU,QAAQ;EACvB,EACD;AAED,SAAO,qCACN,gBACA;CACD;CAED,YACCF,UACAG,SAQC;EAED,MAAM,kBAAkB,mBACvB,OAAO;GACN,YAAY,CAACC,WACZ,KAAK,QAAQ,UAAU,OAAO;GAC/B,GAAG;EACH,IAID,CAAC,UAAU,KAAK,UAAU,QAAQ,AAAC,EACnC;AAED,SAAO,wCAIL,gBAAgB;CAClB;CAED,iBAKCJ,UACAK,SAkBAJ,QACC;EACD,MAAM,WAAW,KAAK,cAAc,UAAU,OAAO;EAGrD,MAAM,kBAAkB,mBACvB,OAAO;GACN;GACA,SAAS,CAAC,EACT,WAC6C,KAAK;IAClD,IAAI,eAAe;A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AAQ;AACjD;AAED,SAAgB,iBACfD,QACAT,UACAW,SAQC;AACD,QAAO,OAAO,YAAY,UAAU,QAAQ;AAC5C;AAED,SAAgB,sBAMfF,QACAT,UACAY,SAkBAX,QACC;AACD,QAAO,OAAO,iBAAiB,UAAU,SAAS,OAAO;AACzD;;;;AAKD,SAAgB,0BACfQ,QACC;CACD,MAAM,cAAc,4CAAgB;AAEpC,QAAO;EAIN,mBAAmB,CAClBT,UACAC,WACI;GACJ,MAAM,WAAW,OAAO,cAAc,UAAU,OAAO;AACvD,UAAO,YAAY,kBAAkB;IACpC;IACA,SAAS;GACT,EAAC;EACF;EAKD,sBAAsB,MAAM;AAC3B,UAAO,YAAY,mBAAmB;EACtC;CACD;AACD"}
|
|
1
|
+
{"version":3,"file":"react-query.cjs","names":["createTypedFetcher","useMemo","useQuery","useMutation","useInfiniteQuery","useQueryClient"],"sources":["../src/react-query.ts"],"sourcesContent":["import type {\n\tQueryClient,\n\tQueryFunctionContext,\n\tUseInfiniteQueryOptions,\n\tUseMutationOptions,\n\tUseQueryOptions,\n} from '@tanstack/react-query';\nimport {\n\tuseInfiniteQuery,\n\tuseMutation,\n\tuseQuery,\n\tuseQueryClient,\n} from '@tanstack/react-query';\nimport { useMemo } from 'react';\nimport { createTypedFetcher } from './fetcher';\nimport type {\n\tExtractEndpointResponse,\n\tFetcherOptions,\n\tFilteredRequestConfig,\n\tMutationEndpoint,\n\tQueryEndpoint,\n\tTypedEndpoint,\n} from './types';\n\nexport interface TypedQueryClientOptions extends FetcherOptions {\n\tqueryClient?: QueryClient;\n}\n\nexport class TypedQueryClient<Paths> {\n\tprivate fetcher: ReturnType<typeof createTypedFetcher<Paths>>;\n\tprivate queryClient?: QueryClient;\n\n\tconstructor(options: TypedQueryClientOptions = {}) {\n\t\tthis.fetcher = createTypedFetcher<Paths>(options);\n\t\tthis.queryClient = options.queryClient;\n\t}\n\n\tuseQuery<T extends QueryEndpoint<Paths>>(\n\t\tendpoint: T,\n\t\tconfig?: FilteredRequestConfig<Paths, T>,\n\t\toptions?: Omit<\n\t\t\tUseQueryOptions<ExtractEndpointResponse<Paths, T>, Response>,\n\t\t\t'queryKey' | 'queryFn'\n\t\t>,\n\t) {\n\t\tconst queryKey = this.buildQueryKey(endpoint, config);\n\n\t\t// Memoize the combined options to prevent unnecessary re-renders\n\t\tconst memoizedOptions = useMemo(\n\t\t\t() => ({\n\t\t\t\tqueryKey,\n\t\t\t\tqueryFn: () => this.fetcher(endpoint, config),\n\t\t\t\t...options,\n\t\t\t}),\n\t\t\t// Dependencies: queryKey, endpoint, config, and options\n\t\t\t// Note: We stringify config and options to ensure stable references\n\t\t\t// eslint-disable-next-line react-hooks/exhaustive-deps\n\t\t\t[\n\t\t\t\tqueryKey.join(','),\n\t\t\t\tendpoint,\n\t\t\t\tJSON.stringify(config),\n\t\t\t\tJSON.stringify(options),\n\t\t\t],\n\t\t);\n\n\t\treturn useQuery<ExtractEndpointResponse<Paths, T>, Response>(\n\t\t\tmemoizedOptions,\n\t\t);\n\t}\n\n\tuseMutation<T extends MutationEndpoint<Paths>>(\n\t\tendpoint: T,\n\t\toptions?: Omit<\n\t\t\tUseMutationOptions<\n\t\t\t\tExtractEndpointResponse<Paths, T>,\n\t\t\t\tResponse,\n\t\t\t\tFilteredRequestConfig<Paths, T>\n\t\t\t>,\n\t\t\t'mutationFn'\n\t\t>,\n\t) {\n\t\t// Memoize the combined options to prevent unnecessary re-renders\n\t\tconst memoizedOptions = useMemo(\n\t\t\t() => ({\n\t\t\t\tmutationFn: (config: FilteredRequestConfig<Paths, T>) =>\n\t\t\t\t\tthis.fetcher(endpoint, config),\n\t\t\t\t...options,\n\t\t\t}),\n\t\t\t// Dependencies: endpoint and options\n\t\t\t// Note: We stringify options to ensure stable reference\n\t\t\t// eslint-disable-next-line react-hooks/exhaustive-deps\n\t\t\t[endpoint, JSON.stringify(options)],\n\t\t);\n\n\t\treturn useMutation<\n\t\t\tExtractEndpointResponse<Paths, T>,\n\t\t\tResponse,\n\t\t\tFilteredRequestConfig<Paths, T>\n\t\t>(memoizedOptions);\n\t}\n\n\tuseInfiniteQuery<\n\t\tT extends QueryEndpoint<Paths>,\n\t\tTPageData = ExtractEndpointResponse<Paths, T>,\n\t\tTPageParam = unknown,\n\t>(\n\t\tendpoint: T,\n\t\toptions: Omit<\n\t\t\tUseInfiniteQueryOptions<\n\t\t\t\tTPageData,\n\t\t\t\tResponse,\n\t\t\t\t{ pages: TPageData[]; pageParams: TPageParam[] },\n\t\t\t\tunknown[],\n\t\t\t\tTPageParam\n\t\t\t>,\n\t\t\t'queryKey' | 'queryFn' | 'getNextPageParam' | 'initialPageParam'\n\t\t> & {\n\t\t\tgetNextPageParam: (\n\t\t\t\tlastPage: TPageData,\n\t\t\t\tallPages: TPageData[],\n\t\t\t\tlastPageParam: TPageParam,\n\t\t\t\tallPageParams: TPageParam[],\n\t\t\t) => TPageParam | undefined;\n\t\t\tinitialPageParam: TPageParam;\n\t\t},\n\t\tconfig?: FilteredRequestConfig<Paths, T>,\n\t) {\n\t\tconst queryKey = this.buildQueryKey(endpoint, config);\n\n\t\t// Memoize the combined options to prevent unnecessary re-renders\n\t\tconst memoizedOptions = useMemo(\n\t\t\t() => ({\n\t\t\t\tqueryKey,\n\t\t\t\tqueryFn: ({\n\t\t\t\t\tpageParam,\n\t\t\t\t}: QueryFunctionContext<unknown[], TPageParam>) => {\n\t\t\t\t\tlet mergedConfig = config;\n\t\t\t\t\tif (pageParam !== undefined && config) {\n\t\t\t\t\t\t// If pageParam is an object, spread it into query\n\t\t\t\t\t\tconst pageQuery =\n\t\t\t\t\t\t\ttypeof pageParam === 'object' ? pageParam : { page: pageParam };\n\t\t\t\t\t\tmergedConfig = {\n\t\t\t\t\t\t\t...config,\n\t\t\t\t\t\t\tquery: { ...(config as any).query, ...pageQuery },\n\t\t\t\t\t\t} as any;\n\t\t\t\t\t} else if (pageParam !== undefined && !config) {\n\t\t\t\t\t\t// If pageParam is an object, use it directly, otherwise wrap in page property\n\t\t\t\t\t\tconst pageQuery =\n\t\t\t\t\t\t\ttypeof pageParam === 'object' ? pageParam : { page: pageParam };\n\t\t\t\t\t\tmergedConfig = { query: pageQuery } as any;\n\t\t\t\t\t}\n\t\t\t\t\treturn this.fetcher(endpoint, mergedConfig) as Promise<TPageData>;\n\t\t\t\t},\n\t\t\t\t...options,\n\t\t\t}),\n\t\t\t// Dependencies: queryKey, endpoint, config, and options\n\t\t\t// Note: We stringify config and options to ensure stable references\n\t\t\t// eslint-disable-next-line react-hooks/exhaustive-deps\n\t\t\t[\n\t\t\t\tqueryKey.join(','),\n\t\t\t\tendpoint,\n\t\t\t\tJSON.stringify(config),\n\t\t\t\tJSON.stringify(options),\n\t\t\t],\n\t\t);\n\n\t\treturn useInfiniteQuery<\n\t\t\tTPageData,\n\t\t\tResponse,\n\t\t\t{ pages: TPageData[]; pageParams: TPageParam[] },\n\t\t\tunknown[],\n\t\t\tTPageParam\n\t\t>(memoizedOptions);\n\t}\n\n\tbuildQueryKey<T extends TypedEndpoint<Paths>>(\n\t\tendpoint: T,\n\t\tconfig?: FilteredRequestConfig<Paths, T>,\n\t): unknown[] {\n\t\tconst key: unknown[] = [endpoint];\n\n\t\tif (config && 'params' in config && config.params) {\n\t\t\tkey.push({ params: config.params });\n\t\t}\n\n\t\tif (config && 'query' in config && config.query) {\n\t\t\tkey.push({ query: config.query });\n\t\t}\n\n\t\treturn key;\n\t}\n\n\t/**\n\t * Invalidate queries for a specific endpoint with optional config\n\t * @param endpoint - The endpoint to invalidate (e.g., 'GET /users')\n\t * @param config - Optional params/query to match specific queries\n\t * @returns Promise that resolves when invalidation is complete\n\t */\n\tinvalidateQueries<T extends QueryEndpoint<Paths>>(\n\t\tendpoint: T,\n\t\tconfig?: FilteredRequestConfig<Paths, T>,\n\t): Promise<void> {\n\t\tconst queryClient = this.getQueryClient();\n\t\tconst queryKey = this.buildQueryKey(endpoint, config);\n\n\t\treturn queryClient.invalidateQueries({\n\t\t\tqueryKey,\n\t\t\texact: !!config, // Use exact matching if config is provided\n\t\t});\n\t}\n\n\t/**\n\t * Invalidate all queries in the cache\n\t * @returns Promise that resolves when invalidation is complete\n\t */\n\tinvalidateAllQueries(): Promise<void> {\n\t\tconst queryClient = this.getQueryClient();\n\t\treturn queryClient.invalidateQueries();\n\t}\n\n\t/**\n\t * Get the underlying QueryClient instance\n\t * @returns The QueryClient instance\n\t */\n\tgetQueryClient(): QueryClient {\n\t\tif (this.queryClient) {\n\t\t\treturn this.queryClient;\n\t\t}\n\n\t\t// If no query client was provided, try to get it from context\n\t\t// This will throw if used outside of QueryClientProvider\n\t\tthrow new Error(\n\t\t\t'No QueryClient set, please provide a QueryClient via the queryClient option or ensure you are within a QueryClientProvider',\n\t\t);\n\t}\n\n\t/**\n\t * Set the QueryClient instance\n\t * @param queryClient - The QueryClient instance to use\n\t */\n\tsetQueryClient(queryClient: QueryClient): void {\n\t\tthis.queryClient = queryClient;\n\t}\n}\n\nexport function createTypedQueryClient<Paths>(\n\toptions?: TypedQueryClientOptions,\n) {\n\treturn new TypedQueryClient<Paths>(options);\n}\n\n// Hook exports for convenience\nexport function useTypedQuery<Paths, T extends QueryEndpoint<Paths>>(\n\tclient: TypedQueryClient<Paths>,\n\tendpoint: T,\n\tconfig?: FilteredRequestConfig<Paths, T>,\n\toptions?: Omit<\n\t\tUseQueryOptions<ExtractEndpointResponse<Paths, T>, Response>,\n\t\t'queryKey' | 'queryFn'\n\t>,\n) {\n\treturn client.useQuery(endpoint, config, options);\n}\n\nexport function useTypedMutation<Paths, T extends MutationEndpoint<Paths>>(\n\tclient: TypedQueryClient<Paths>,\n\tendpoint: T,\n\toptions?: Omit<\n\t\tUseMutationOptions<\n\t\t\tExtractEndpointResponse<Paths, T>,\n\t\t\tResponse,\n\t\t\tFilteredRequestConfig<Paths, T>\n\t\t>,\n\t\t'mutationFn'\n\t>,\n) {\n\treturn client.useMutation(endpoint, options);\n}\n\nexport function useTypedInfiniteQuery<\n\tPaths,\n\tT extends QueryEndpoint<Paths>,\n\tTPageData = ExtractEndpointResponse<Paths, T>,\n\tTPageParam = unknown,\n>(\n\tclient: TypedQueryClient<Paths>,\n\tendpoint: T,\n\toptions: Omit<\n\t\tUseInfiniteQueryOptions<\n\t\t\tTPageData,\n\t\t\tResponse,\n\t\t\t{ pages: TPageData[]; pageParams: TPageParam[] },\n\t\t\tunknown[],\n\t\t\tTPageParam\n\t\t>,\n\t\t'queryKey' | 'queryFn' | 'getNextPageParam' | 'initialPageParam'\n\t> & {\n\t\tgetNextPageParam: (\n\t\t\tlastPage: TPageData,\n\t\t\tallPages: TPageData[],\n\t\t\tlastPageParam: TPageParam,\n\t\t\tallPageParams: TPageParam[],\n\t\t) => TPageParam | undefined;\n\t\tinitialPageParam: TPageParam;\n\t},\n\tconfig?: FilteredRequestConfig<Paths, T>,\n) {\n\treturn client.useInfiniteQuery(endpoint, options, config);\n}\n\n/**\n * Hook to invalidate queries using the current QueryClient from context\n */\nexport function useTypedInvalidateQueries<Paths>(\n\tclient: TypedQueryClient<Paths>,\n) {\n\tconst queryClient = useQueryClient();\n\n\treturn {\n\t\t/**\n\t\t * Invalidate queries for a specific endpoint\n\t\t */\n\t\tinvalidateQueries: <T extends QueryEndpoint<Paths>>(\n\t\t\tendpoint: T,\n\t\t\tconfig?: FilteredRequestConfig<Paths, T>,\n\t\t) => {\n\t\t\tconst queryKey = client.buildQueryKey(endpoint, config);\n\t\t\treturn queryClient.invalidateQueries({\n\t\t\t\tqueryKey,\n\t\t\t\texact: !!config,\n\t\t\t});\n\t\t},\n\n\t\t/**\n\t\t * Invalidate all queries\n\t\t */\n\t\tinvalidateAllQueries: () => {\n\t\t\treturn queryClient.invalidateQueries();\n\t\t},\n\t};\n}\n"],"mappings":";;;;;AA4BA,IAAa,mBAAb,MAAqC;CACpC;CACA;CAEA,YAAY,UAAmC,CAAC,GAAG;EAClD,KAAK,UAAUA,gBAAAA,mBAA0B,OAAO;EAChD,KAAK,cAAc,QAAQ;CAC5B;CAEA,SACC,UACA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@@ -1,24 +1,22 @@
|
|
|
1
|
-
import { ExtractEndpointResponse, FetcherOptions, FilteredRequestConfig, MutationEndpoint, QueryEndpoint, TypedEndpoint } from "./types
|
|
2
|
-
import * as _tanstack_react_query0 from "@tanstack/react-query";
|
|
1
|
+
import { ExtractEndpointResponse, FetcherOptions, FilteredRequestConfig, MutationEndpoint, QueryEndpoint, TypedEndpoint } from "./types.cjs";
|
|
3
2
|
import { QueryClient, UseInfiniteQueryOptions, UseMutationOptions, UseQueryOptions } from "@tanstack/react-query";
|
|
4
|
-
|
|
5
3
|
//#region src/react-query.d.ts
|
|
6
|
-
interface TypedQueryClientOptions extends FetcherOptions {
|
|
4
|
+
export interface TypedQueryClientOptions extends FetcherOptions {
|
|
7
5
|
queryClient?: QueryClient;
|
|
8
6
|
}
|
|
9
|
-
declare class TypedQueryClient<Paths> {
|
|
7
|
+
export declare class TypedQueryClient<Paths> {
|
|
10
8
|
private fetcher;
|
|
11
9
|
private queryClient?;
|
|
12
10
|
constructor(options?: TypedQueryClientOptions);
|
|
13
|
-
useQuery<T extends QueryEndpoint<Paths>>(endpoint: T, config?: FilteredRequestConfig<Paths, T>, options?: Omit<UseQueryOptions<ExtractEndpointResponse<Paths, T>, Response>, 'queryKey' | 'queryFn'>):
|
|
14
|
-
useMutation<T extends MutationEndpoint<Paths>>(endpoint: T, options?: Omit<UseMutationOptions<ExtractEndpointResponse<Paths, T>, Response, FilteredRequestConfig<Paths, T>>, 'mutationFn'>):
|
|
11
|
+
useQuery<T extends QueryEndpoint<Paths>>(endpoint: T, config?: FilteredRequestConfig<Paths, T>, options?: Omit<UseQueryOptions<ExtractEndpointResponse<Paths, T>, Response>, 'queryKey' | 'queryFn'>): import("@tanstack/react-query").UseQueryResult<ExtractEndpointResponse<Paths, T>, Response>;
|
|
12
|
+
useMutation<T extends MutationEndpoint<Paths>>(endpoint: T, options?: Omit<UseMutationOptions<ExtractEndpointResponse<Paths, T>, Response, FilteredRequestConfig<Paths, T>>, 'mutationFn'>): import("@tanstack/react-query").UseMutationResult<ExtractEndpointResponse<Paths, T>, Response, FilteredRequestConfig<Paths, T>, unknown>;
|
|
15
13
|
useInfiniteQuery<T extends QueryEndpoint<Paths>, TPageData = ExtractEndpointResponse<Paths, T>, TPageParam = unknown>(endpoint: T, options: Omit<UseInfiniteQueryOptions<TPageData, Response, {
|
|
16
14
|
pages: TPageData[];
|
|
17
15
|
pageParams: TPageParam[];
|
|
18
16
|
}, unknown[], TPageParam>, 'queryKey' | 'queryFn' | 'getNextPageParam' | 'initialPageParam'> & {
|
|
19
17
|
getNextPageParam: (lastPage: TPageData, allPages: TPageData[], lastPageParam: TPageParam, allPageParams: TPageParam[]) => TPageParam | undefined;
|
|
20
18
|
initialPageParam: TPageParam;
|
|
21
|
-
}, config?: FilteredRequestConfig<Paths, T>):
|
|
19
|
+
}, config?: FilteredRequestConfig<Paths, T>): import("@tanstack/react-query").UseInfiniteQueryResult<{
|
|
22
20
|
pages: TPageData[];
|
|
23
21
|
pageParams: TPageParam[];
|
|
24
22
|
}, Response>;
|
|
@@ -46,23 +44,23 @@ declare class TypedQueryClient<Paths> {
|
|
|
46
44
|
*/
|
|
47
45
|
setQueryClient(queryClient: QueryClient): void;
|
|
48
46
|
}
|
|
49
|
-
declare function createTypedQueryClient<Paths>(options?: TypedQueryClientOptions): TypedQueryClient<Paths>;
|
|
50
|
-
declare function useTypedQuery<Paths, T extends QueryEndpoint<Paths>>(client: TypedQueryClient<Paths>, endpoint: T, config?: FilteredRequestConfig<Paths, T>, options?: Omit<UseQueryOptions<ExtractEndpointResponse<Paths, T>, Response>, 'queryKey' | 'queryFn'>):
|
|
51
|
-
declare function useTypedMutation<Paths, T extends MutationEndpoint<Paths>>(client: TypedQueryClient<Paths>, endpoint: T, options?: Omit<UseMutationOptions<ExtractEndpointResponse<Paths, T>, Response, FilteredRequestConfig<Paths, T>>, 'mutationFn'>):
|
|
52
|
-
declare function useTypedInfiniteQuery<Paths, T extends QueryEndpoint<Paths>, TPageData = ExtractEndpointResponse<Paths, T>, TPageParam = unknown>(client: TypedQueryClient<Paths>, endpoint: T, options: Omit<UseInfiniteQueryOptions<TPageData, Response, {
|
|
47
|
+
export declare function createTypedQueryClient<Paths>(options?: TypedQueryClientOptions): TypedQueryClient<Paths>;
|
|
48
|
+
export declare function useTypedQuery<Paths, T extends QueryEndpoint<Paths>>(client: TypedQueryClient<Paths>, endpoint: T, config?: FilteredRequestConfig<Paths, T>, options?: Omit<UseQueryOptions<ExtractEndpointResponse<Paths, T>, Response>, 'queryKey' | 'queryFn'>): import("@tanstack/react-query").UseQueryResult<ExtractEndpointResponse<Paths, T>, Response>;
|
|
49
|
+
export declare function useTypedMutation<Paths, T extends MutationEndpoint<Paths>>(client: TypedQueryClient<Paths>, endpoint: T, options?: Omit<UseMutationOptions<ExtractEndpointResponse<Paths, T>, Response, FilteredRequestConfig<Paths, T>>, 'mutationFn'>): import("@tanstack/react-query").UseMutationResult<ExtractEndpointResponse<Paths, T>, Response, FilteredRequestConfig<Paths, T>, unknown>;
|
|
50
|
+
export declare function useTypedInfiniteQuery<Paths, T extends QueryEndpoint<Paths>, TPageData = ExtractEndpointResponse<Paths, T>, TPageParam = unknown>(client: TypedQueryClient<Paths>, endpoint: T, options: Omit<UseInfiniteQueryOptions<TPageData, Response, {
|
|
53
51
|
pages: TPageData[];
|
|
54
52
|
pageParams: TPageParam[];
|
|
55
53
|
}, unknown[], TPageParam>, 'queryKey' | 'queryFn' | 'getNextPageParam' | 'initialPageParam'> & {
|
|
56
54
|
getNextPageParam: (lastPage: TPageData, allPages: TPageData[], lastPageParam: TPageParam, allPageParams: TPageParam[]) => TPageParam | undefined;
|
|
57
55
|
initialPageParam: TPageParam;
|
|
58
|
-
}, config?: FilteredRequestConfig<Paths, T>):
|
|
56
|
+
}, config?: FilteredRequestConfig<Paths, T>): import("@tanstack/react-query").UseInfiniteQueryResult<{
|
|
59
57
|
pages: TPageData[];
|
|
60
58
|
pageParams: TPageParam[];
|
|
61
59
|
}, Response>;
|
|
62
60
|
/**
|
|
63
61
|
* Hook to invalidate queries using the current QueryClient from context
|
|
64
62
|
*/
|
|
65
|
-
declare function useTypedInvalidateQueries<Paths>(client: TypedQueryClient<Paths>): {
|
|
63
|
+
export declare function useTypedInvalidateQueries<Paths>(client: TypedQueryClient<Paths>): {
|
|
66
64
|
/**
|
|
67
65
|
* Invalidate queries for a specific endpoint
|
|
68
66
|
*/
|
|
@@ -72,8 +70,5 @@ declare function useTypedInvalidateQueries<Paths>(client: TypedQueryClient<Paths
|
|
|
72
70
|
*/
|
|
73
71
|
invalidateAllQueries: () => Promise<void>;
|
|
74
72
|
};
|
|
75
|
-
//# sourceMappingURL=react-query.d.ts.map
|
|
76
|
-
|
|
77
73
|
//#endregion
|
|
78
|
-
export { TypedQueryClient, TypedQueryClientOptions, createTypedQueryClient, useTypedInfiniteQuery, useTypedInvalidateQueries, useTypedMutation, useTypedQuery };
|
|
79
74
|
//# sourceMappingURL=react-query.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react-query.d.cts","names":[],"sources":["../src/react-query.ts"],"
|
|
1
|
+
{"version":3,"file":"react-query.d.cts","names":[],"sources":["../src/react-query.ts"],"mappings":";;;iBAwBiB,gCAAgC;EAChD,cAAc;;qBAGF,iBAAiB;UACrB;UACA;EAER,YAAY,UAAS;EAKrB,SAAS,UAAU,cAAc,QAChC,UAAU,GACV,SAAS,sBAAsB,OAAO,IACtC,UAAU,KACT,gBAAgB,wBAAwB,OAAO,IAAI,qEAEnD,eAAA,wBAAA,OAAA,IAAA;EA2BF,YAAY,UAAU,iBAAiB,QACtC,UAAU,GACV,UAAU,KACT,mBACC,wBAAwB,OAAO,IAC/B,UACA,sBAAsB,OAAO,qDAG9B,kBAAA,wBAAA,OAAA,IAAA,UAAA,sBAAA,OAAA;EAsBF,iBACC,UAAU,cAAc,QACxB,YAAY,wBAAwB,OAAO,IAC3C,sBAEA,UAAU,GACV,SAAS,KACR,wBACC,WACA;I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1
|
-
import { ExtractEndpointResponse, FetcherOptions, FilteredRequestConfig, MutationEndpoint, QueryEndpoint, TypedEndpoint } from "./types
|
|
2
|
-
import * as _tanstack_react_query0 from "@tanstack/react-query";
|
|
1
|
+
import { ExtractEndpointResponse, FetcherOptions, FilteredRequestConfig, MutationEndpoint, QueryEndpoint, TypedEndpoint } from "./types.mjs";
|
|
3
2
|
import { QueryClient, UseInfiniteQueryOptions, UseMutationOptions, UseQueryOptions } from "@tanstack/react-query";
|
|
4
|
-
|
|
5
3
|
//#region src/react-query.d.ts
|
|
6
|
-
interface TypedQueryClientOptions extends FetcherOptions {
|
|
4
|
+
export interface TypedQueryClientOptions extends FetcherOptions {
|
|
7
5
|
queryClient?: QueryClient;
|
|
8
6
|
}
|
|
9
|
-
declare class TypedQueryClient<Paths> {
|
|
7
|
+
export declare class TypedQueryClient<Paths> {
|
|
10
8
|
private fetcher;
|
|
11
9
|
private queryClient?;
|
|
12
10
|
constructor(options?: TypedQueryClientOptions);
|
|
13
|
-
useQuery<T extends QueryEndpoint<Paths>>(endpoint: T, config?: FilteredRequestConfig<Paths, T>, options?: Omit<UseQueryOptions<ExtractEndpointResponse<Paths, T>, Response>, 'queryKey' | 'queryFn'>):
|
|
14
|
-
useMutation<T extends MutationEndpoint<Paths>>(endpoint: T, options?: Omit<UseMutationOptions<ExtractEndpointResponse<Paths, T>, Response, FilteredRequestConfig<Paths, T>>, 'mutationFn'>):
|
|
11
|
+
useQuery<T extends QueryEndpoint<Paths>>(endpoint: T, config?: FilteredRequestConfig<Paths, T>, options?: Omit<UseQueryOptions<ExtractEndpointResponse<Paths, T>, Response>, 'queryKey' | 'queryFn'>): import("@tanstack/react-query").UseQueryResult<ExtractEndpointResponse<Paths, T>, Response>;
|
|
12
|
+
useMutation<T extends MutationEndpoint<Paths>>(endpoint: T, options?: Omit<UseMutationOptions<ExtractEndpointResponse<Paths, T>, Response, FilteredRequestConfig<Paths, T>>, 'mutationFn'>): import("@tanstack/react-query").UseMutationResult<ExtractEndpointResponse<Paths, T>, Response, FilteredRequestConfig<Paths, T>, unknown>;
|
|
15
13
|
useInfiniteQuery<T extends QueryEndpoint<Paths>, TPageData = ExtractEndpointResponse<Paths, T>, TPageParam = unknown>(endpoint: T, options: Omit<UseInfiniteQueryOptions<TPageData, Response, {
|
|
16
14
|
pages: TPageData[];
|
|
17
15
|
pageParams: TPageParam[];
|
|
18
16
|
}, unknown[], TPageParam>, 'queryKey' | 'queryFn' | 'getNextPageParam' | 'initialPageParam'> & {
|
|
19
17
|
getNextPageParam: (lastPage: TPageData, allPages: TPageData[], lastPageParam: TPageParam, allPageParams: TPageParam[]) => TPageParam | undefined;
|
|
20
18
|
initialPageParam: TPageParam;
|
|
21
|
-
}, config?: FilteredRequestConfig<Paths, T>):
|
|
19
|
+
}, config?: FilteredRequestConfig<Paths, T>): import("@tanstack/react-query").UseInfiniteQueryResult<{
|
|
22
20
|
pages: TPageData[];
|
|
23
21
|
pageParams: TPageParam[];
|
|
24
22
|
}, Response>;
|
|
@@ -46,23 +44,23 @@ declare class TypedQueryClient<Paths> {
|
|
|
46
44
|
*/
|
|
47
45
|
setQueryClient(queryClient: QueryClient): void;
|
|
48
46
|
}
|
|
49
|
-
declare function createTypedQueryClient<Paths>(options?: TypedQueryClientOptions): TypedQueryClient<Paths>;
|
|
50
|
-
declare function useTypedQuery<Paths, T extends QueryEndpoint<Paths>>(client: TypedQueryClient<Paths>, endpoint: T, config?: FilteredRequestConfig<Paths, T>, options?: Omit<UseQueryOptions<ExtractEndpointResponse<Paths, T>, Response>, 'queryKey' | 'queryFn'>):
|
|
51
|
-
declare function useTypedMutation<Paths, T extends MutationEndpoint<Paths>>(client: TypedQueryClient<Paths>, endpoint: T, options?: Omit<UseMutationOptions<ExtractEndpointResponse<Paths, T>, Response, FilteredRequestConfig<Paths, T>>, 'mutationFn'>):
|
|
52
|
-
declare function useTypedInfiniteQuery<Paths, T extends QueryEndpoint<Paths>, TPageData = ExtractEndpointResponse<Paths, T>, TPageParam = unknown>(client: TypedQueryClient<Paths>, endpoint: T, options: Omit<UseInfiniteQueryOptions<TPageData, Response, {
|
|
47
|
+
export declare function createTypedQueryClient<Paths>(options?: TypedQueryClientOptions): TypedQueryClient<Paths>;
|
|
48
|
+
export declare function useTypedQuery<Paths, T extends QueryEndpoint<Paths>>(client: TypedQueryClient<Paths>, endpoint: T, config?: FilteredRequestConfig<Paths, T>, options?: Omit<UseQueryOptions<ExtractEndpointResponse<Paths, T>, Response>, 'queryKey' | 'queryFn'>): import("@tanstack/react-query").UseQueryResult<ExtractEndpointResponse<Paths, T>, Response>;
|
|
49
|
+
export declare function useTypedMutation<Paths, T extends MutationEndpoint<Paths>>(client: TypedQueryClient<Paths>, endpoint: T, options?: Omit<UseMutationOptions<ExtractEndpointResponse<Paths, T>, Response, FilteredRequestConfig<Paths, T>>, 'mutationFn'>): import("@tanstack/react-query").UseMutationResult<ExtractEndpointResponse<Paths, T>, Response, FilteredRequestConfig<Paths, T>, unknown>;
|
|
50
|
+
export declare function useTypedInfiniteQuery<Paths, T extends QueryEndpoint<Paths>, TPageData = ExtractEndpointResponse<Paths, T>, TPageParam = unknown>(client: TypedQueryClient<Paths>, endpoint: T, options: Omit<UseInfiniteQueryOptions<TPageData, Response, {
|
|
53
51
|
pages: TPageData[];
|
|
54
52
|
pageParams: TPageParam[];
|
|
55
53
|
}, unknown[], TPageParam>, 'queryKey' | 'queryFn' | 'getNextPageParam' | 'initialPageParam'> & {
|
|
56
54
|
getNextPageParam: (lastPage: TPageData, allPages: TPageData[], lastPageParam: TPageParam, allPageParams: TPageParam[]) => TPageParam | undefined;
|
|
57
55
|
initialPageParam: TPageParam;
|
|
58
|
-
}, config?: FilteredRequestConfig<Paths, T>):
|
|
56
|
+
}, config?: FilteredRequestConfig<Paths, T>): import("@tanstack/react-query").UseInfiniteQueryResult<{
|
|
59
57
|
pages: TPageData[];
|
|
60
58
|
pageParams: TPageParam[];
|
|
61
59
|
}, Response>;
|
|
62
60
|
/**
|
|
63
61
|
* Hook to invalidate queries using the current QueryClient from context
|
|
64
62
|
*/
|
|
65
|
-
declare function useTypedInvalidateQueries<Paths>(client: TypedQueryClient<Paths>): {
|
|
63
|
+
export declare function useTypedInvalidateQueries<Paths>(client: TypedQueryClient<Paths>): {
|
|
66
64
|
/**
|
|
67
65
|
* Invalidate queries for a specific endpoint
|
|
68
66
|
*/
|
|
@@ -72,8 +70,5 @@ declare function useTypedInvalidateQueries<Paths>(client: TypedQueryClient<Paths
|
|
|
72
70
|
*/
|
|
73
71
|
invalidateAllQueries: () => Promise<void>;
|
|
74
72
|
};
|
|
75
|
-
//# sourceMappingURL=react-query.d.ts.map
|
|
76
|
-
|
|
77
73
|
//#endregion
|
|
78
|
-
export { TypedQueryClient, TypedQueryClientOptions, createTypedQueryClient, useTypedInfiniteQuery, useTypedInvalidateQueries, useTypedMutation, useTypedQuery };
|
|
79
74
|
//# sourceMappingURL=react-query.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react-query.d.mts","names":[],"sources":["../src/react-query.ts"],"
|
|
1
|
+
{"version":3,"file":"react-query.d.mts","names":[],"sources":["../src/react-query.ts"],"mappings":";;;iBAwBiB,gCAAgC;EAChD,cAAc;;qBAGF,iBAAiB;UACrB;UACA;EAER,YAAY,UAAS;EAKrB,SAAS,UAAU,cAAc,QAChC,UAAU,GACV,SAAS,sBAAsB,OAAO,IACtC,UAAU,KACT,gBAAgB,wBAAwB,OAAO,IAAI,qEAEnD,eAAA,wBAAA,OAAA,IAAA;EA2BF,YAAY,UAAU,iBAAiB,QACtC,UAAU,GACV,UAAU,KACT,mBACC,wBAAwB,OAAO,IAC/B,UACA,sBAAsB,OAAO,qDAG9B,kBAAA,wBAAA,OAAA,IAAA,UAAA,sBAAA,OAAA;EAsBF,iBACC,UAAU,cAAc,QACxB,YAAY,wBAAwB,OAAO,IAC3C,sBAEA,UAAU,GACV,SAAS,KACR,wBACC,WACA;IACE,OAAO;IAAa,YAAY;gBAEl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her
|
|
1
|
+
import { createTypedFetcher } from "./fetcher.mjs";
|
|
2
2
|
import { useInfiniteQuery, useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
|
3
3
|
import { useMemo } from "react";
|
|
4
|
-
|
|
5
4
|
//#region src/react-query.ts
|
|
6
5
|
var TypedQueryClient = class {
|
|
7
6
|
fetcher;
|
|
@@ -46,10 +45,7 @@ var TypedQueryClient = class {
|
|
|
46
45
|
...pageQuery
|
|
47
46
|
}
|
|
48
47
|
};
|
|
49
|
-
} else if (pageParam !== void 0 && !config) {
|
|
50
|
-
const pageQuery = typeof pageParam === "object" ? pageParam : { page: pageParam };
|
|
51
|
-
mergedConfig = { query: pageQuery };
|
|
52
|
-
}
|
|
48
|
+
} else if (pageParam !== void 0 && !config) mergedConfig = { query: typeof pageParam === "object" ? pageParam : { page: pageParam } };
|
|
53
49
|
return this.fetcher(endpoint, mergedConfig);
|
|
54
50
|
},
|
|
55
51
|
...options
|
|
@@ -86,8 +82,7 @@ var TypedQueryClient = class {
|
|
|
86
82
|
* @returns Promise that resolves when invalidation is complete
|
|
87
83
|
*/
|
|
88
84
|
invalidateAllQueries() {
|
|
89
|
-
|
|
90
|
-
return queryClient.invalidateQueries();
|
|
85
|
+
return this.getQueryClient().invalidateQueries();
|
|
91
86
|
}
|
|
92
87
|
/**
|
|
93
88
|
* Get the underlying QueryClient instance
|
|
@@ -123,6 +118,9 @@ function useTypedInfiniteQuery(client, endpoint, options, config) {
|
|
|
123
118
|
function useTypedInvalidateQueries(client) {
|
|
124
119
|
const queryClient = useQueryClient();
|
|
125
120
|
return {
|
|
121
|
+
/**
|
|
122
|
+
* Invalidate queries for a specific endpoint
|
|
123
|
+
*/
|
|
126
124
|
invalidateQueries: (endpoint, config) => {
|
|
127
125
|
const queryKey = client.buildQueryKey(endpoint, config);
|
|
128
126
|
return queryClient.invalidateQueries({
|
|
@@ -130,12 +128,15 @@ function useTypedInvalidateQueries(client) {
|
|
|
130
128
|
exact: !!config
|
|
131
129
|
});
|
|
132
130
|
},
|
|
131
|
+
/**
|
|
132
|
+
* Invalidate all queries
|
|
133
|
+
*/
|
|
133
134
|
invalidateAllQueries: () => {
|
|
134
135
|
return queryClient.invalidateQueries();
|
|
135
136
|
}
|
|
136
137
|
};
|
|
137
138
|
}
|
|
138
|
-
|
|
139
139
|
//#endregion
|
|
140
140
|
export { TypedQueryClient, createTypedQueryClient, useTypedInfiniteQuery, useTypedInvalidateQueries, useTypedMutation, useTypedQuery };
|
|
141
|
+
|
|
141
142
|
//# sourceMappingURL=react-query.mjs.map
|
package/dist/react-query.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react-query.mjs","names":["options: TypedQueryClientOptions","endpoint: T","config?: FilteredRequestConfig<Paths, T>","options?: Omit<\n\t\t\tUseQueryOptions<ExtractEndpointResponse<Paths, T>, Response>,\n\t\t\t'queryKey' | 'queryFn'\n\t\t>","options?: Omit<\n\t\t\tUseMutationOptions<\n\t\t\t\tExtractEndpointResponse<Paths, T>,\n\t\t\t\tResponse,\n\t\t\t\tFilteredRequestConfig<Paths, T>\n\t\t\t>,\n\t\t\t'mutationFn'\n\t\t>","config: FilteredRequestConfig<Paths, T>","options: Omit<\n\t\t\tUseInfiniteQueryOptions<\n\t\t\t\tTPageData,\n\t\t\t\tResponse,\n\t\t\t\t{ pages: TPageData[]; pageParams: TPageParam[] },\n\t\t\t\tunknown[],\n\t\t\t\tTPageParam\n\t\t\t>,\n\t\t\t'queryKey' | 'queryFn' | 'getNextPageParam' | 'initialPageParam'\n\t\t> & {\n\t\t\tgetNextPageParam: (\n\t\t\t\tlastPage: TPageData,\n\t\t\t\tallPages: TPageData[],\n\t\t\t\tlastPageParam: TPageParam,\n\t\t\t\tallPageParams: TPageParam[],\n\t\t\t) => TPageParam | undefined;\n\t\t\tinitialPageParam: TPageParam;\n\t\t}","key: unknown[]","queryClient: QueryClient","options?: TypedQueryClientOptions","client: TypedQueryClient<Paths>","options?: Omit<\n\t\tUseQueryOptions<ExtractEndpointResponse<Paths, T>, Response>,\n\t\t'queryKey' | 'queryFn'\n\t>","options?: Omit<\n\t\tUseMutationOptions<\n\t\t\tExtractEndpointResponse<Paths, T>,\n\t\t\tResponse,\n\t\t\tFilteredRequestConfig<Paths, T>\n\t\t>,\n\t\t'mutationFn'\n\t>","options: Omit<\n\t\tUseInfiniteQueryOptions<\n\t\t\tTPageData,\n\t\t\tResponse,\n\t\t\t{ pages: TPageData[]; pageParams: TPageParam[] },\n\t\t\tunknown[],\n\t\t\tTPageParam\n\t\t>,\n\t\t'queryKey' | 'queryFn' | 'getNextPageParam' | 'initialPageParam'\n\t> & {\n\t\tgetNextPageParam: (\n\t\t\tlastPage: TPageData,\n\t\t\tallPages: TPageData[],\n\t\t\tlastPageParam: TPageParam,\n\t\t\tallPageParams: TPageParam[],\n\t\t) => TPageParam | undefined;\n\t\tinitialPageParam: TPageParam;\n\t}"],"sources":["../src/react-query.ts"],"sourcesContent":["import type {\n\tQueryClient,\n\tQueryFunctionContext,\n\tUseInfiniteQueryOptions,\n\tUseMutationOptions,\n\tUseQueryOptions,\n} from '@tanstack/react-query';\nimport {\n\tuseInfiniteQuery,\n\tuseMutation,\n\tuseQuery,\n\tuseQueryClient,\n} from '@tanstack/react-query';\nimport { useMemo } from 'react';\nimport { createTypedFetcher } from './fetcher';\nimport type {\n\tExtractEndpointResponse,\n\tFetcherOptions,\n\tFilteredRequestConfig,\n\tMutationEndpoint,\n\tQueryEndpoint,\n\tTypedEndpoint,\n} from './types';\n\nexport interface TypedQueryClientOptions extends FetcherOptions {\n\tqueryClient?: QueryClient;\n}\n\nexport class TypedQueryClient<Paths> {\n\tprivate fetcher: ReturnType<typeof createTypedFetcher<Paths>>;\n\tprivate queryClient?: QueryClient;\n\n\tconstructor(options: TypedQueryClientOptions = {}) {\n\t\tthis.fetcher = createTypedFetcher<Paths>(options);\n\t\tthis.queryClient = options.queryClient;\n\t}\n\n\tuseQuery<T extends QueryEndpoint<Paths>>(\n\t\tendpoint: T,\n\t\tconfig?: FilteredRequestConfig<Paths, T>,\n\t\toptions?: Omit<\n\t\t\tUseQueryOptions<ExtractEndpointResponse<Paths, T>, Response>,\n\t\t\t'queryKey' | 'queryFn'\n\t\t>,\n\t) {\n\t\tconst queryKey = this.buildQueryKey(endpoint, config);\n\n\t\t// Memoize the combined options to prevent unnecessary re-renders\n\t\tconst memoizedOptions = useMemo(\n\t\t\t() => ({\n\t\t\t\tqueryKey,\n\t\t\t\tqueryFn: () => this.fetcher(endpoint, config),\n\t\t\t\t...options,\n\t\t\t}),\n\t\t\t// Dependencies: queryKey, endpoint, config, and options\n\t\t\t// Note: We stringify config and options to ensure stable references\n\t\t\t// eslint-disable-next-line react-hooks/exhaustive-deps\n\t\t\t[\n\t\t\t\tqueryKey.join(','),\n\t\t\t\tendpoint,\n\t\t\t\tJSON.stringify(config),\n\t\t\t\tJSON.stringify(options),\n\t\t\t],\n\t\t);\n\n\t\treturn useQuery<ExtractEndpointResponse<Paths, T>, Response>(\n\t\t\tmemoizedOptions,\n\t\t);\n\t}\n\n\tuseMutation<T extends MutationEndpoint<Paths>>(\n\t\tendpoint: T,\n\t\toptions?: Omit<\n\t\t\tUseMutationOptions<\n\t\t\t\tExtractEndpointResponse<Paths, T>,\n\t\t\t\tResponse,\n\t\t\t\tFilteredRequestConfig<Paths, T>\n\t\t\t>,\n\t\t\t'mutationFn'\n\t\t>,\n\t) {\n\t\t// Memoize the combined options to prevent unnecessary re-renders\n\t\tconst memoizedOptions = useMemo(\n\t\t\t() => ({\n\t\t\t\tmutationFn: (config: FilteredRequestConfig<Paths, T>) =>\n\t\t\t\t\tthis.fetcher(endpoint, config),\n\t\t\t\t...options,\n\t\t\t}),\n\t\t\t// Dependencies: endpoint and options\n\t\t\t// Note: We stringify options to ensure stable reference\n\t\t\t// eslint-disable-next-line react-hooks/exhaustive-deps\n\t\t\t[endpoint, JSON.stringify(options)],\n\t\t);\n\n\t\treturn useMutation<\n\t\t\tExtractEndpointResponse<Paths, T>,\n\t\t\tResponse,\n\t\t\tFilteredRequestConfig<Paths, T>\n\t\t>(memoizedOptions);\n\t}\n\n\tuseInfiniteQuery<\n\t\tT extends QueryEndpoint<Paths>,\n\t\tTPageData = ExtractEndpointResponse<Paths, T>,\n\t\tTPageParam = unknown,\n\t>(\n\t\tendpoint: T,\n\t\toptions: Omit<\n\t\t\tUseInfiniteQueryOptions<\n\t\t\t\tTPageData,\n\t\t\t\tResponse,\n\t\t\t\t{ pages: TPageData[]; pageParams: TPageParam[] },\n\t\t\t\tunknown[],\n\t\t\t\tTPageParam\n\t\t\t>,\n\t\t\t'queryKey' | 'queryFn' | 'getNextPageParam' | 'initialPageParam'\n\t\t> & {\n\t\t\tgetNextPageParam: (\n\t\t\t\tlastPage: TPageData,\n\t\t\t\tallPages: TPageData[],\n\t\t\t\tlastPageParam: TPageParam,\n\t\t\t\tallPageParams: TPageParam[],\n\t\t\t) => TPageParam | undefined;\n\t\t\tinitialPageParam: TPageParam;\n\t\t},\n\t\tconfig?: FilteredRequestConfig<Paths, T>,\n\t) {\n\t\tconst queryKey = this.buildQueryKey(endpoint, config);\n\n\t\t// Memoize the combined options to prevent unnecessary re-renders\n\t\tconst memoizedOptions = useMemo(\n\t\t\t() => ({\n\t\t\t\tqueryKey,\n\t\t\t\tqueryFn: ({\n\t\t\t\t\tpageParam,\n\t\t\t\t}: QueryFunctionContext<unknown[], TPageParam>) => {\n\t\t\t\t\tlet mergedConfig = config;\n\t\t\t\t\tif (pageParam !== undefined && config) {\n\t\t\t\t\t\t// If pageParam is an object, spread it into query\n\t\t\t\t\t\tconst pageQuery =\n\t\t\t\t\t\t\ttypeof pageParam === 'object' ? pageParam : { page: pageParam };\n\t\t\t\t\t\tmergedConfig = {\n\t\t\t\t\t\t\t...config,\n\t\t\t\t\t\t\tquery: { ...(config as any).query, ...pageQuery },\n\t\t\t\t\t\t} as any;\n\t\t\t\t\t} else if (pageParam !== undefined && !config) {\n\t\t\t\t\t\t// If pageParam is an object, use it directly, otherwise wrap in page property\n\t\t\t\t\t\tconst pageQuery =\n\t\t\t\t\t\t\ttypeof pageParam === 'object' ? pageParam : { page: pageParam };\n\t\t\t\t\t\tmergedConfig = { query: pageQuery } as any;\n\t\t\t\t\t}\n\t\t\t\t\treturn this.fetcher(endpoint, mergedConfig) as Promise<TPageData>;\n\t\t\t\t},\n\t\t\t\t...options,\n\t\t\t}),\n\t\t\t// Dependencies: queryKey, endpoint, config, and options\n\t\t\t// Note: We stringify config and options to ensure stable references\n\t\t\t// eslint-disable-next-line react-hooks/exhaustive-deps\n\t\t\t[\n\t\t\t\tqueryKey.join(','),\n\t\t\t\tendpoint,\n\t\t\t\tJSON.stringify(config),\n\t\t\t\tJSON.stringify(options),\n\t\t\t],\n\t\t);\n\n\t\treturn useInfiniteQuery<\n\t\t\tTPageData,\n\t\t\tResponse,\n\t\t\t{ pages: TPageData[]; pageParams: TPageParam[] },\n\t\t\tunknown[],\n\t\t\tTPageParam\n\t\t>(memoizedOptions);\n\t}\n\n\tbuildQueryKey<T extends TypedEndpoint<Paths>>(\n\t\tendpoint: T,\n\t\tconfig?: FilteredRequestConfig<Paths, T>,\n\t): unknown[] {\n\t\tconst key: unknown[] = [endpoint];\n\n\t\tif (config && 'params' in config && config.params) {\n\t\t\tkey.push({ params: config.params });\n\t\t}\n\n\t\tif (config && 'query' in config && config.query) {\n\t\t\tkey.push({ query: config.query });\n\t\t}\n\n\t\treturn key;\n\t}\n\n\t/**\n\t * Invalidate queries for a specific endpoint with optional config\n\t * @param endpoint - The endpoint to invalidate (e.g., 'GET /users')\n\t * @param config - Optional params/query to match specific queries\n\t * @returns Promise that resolves when invalidation is complete\n\t */\n\tinvalidateQueries<T extends QueryEndpoint<Paths>>(\n\t\tendpoint: T,\n\t\tconfig?: FilteredRequestConfig<Paths, T>,\n\t): Promise<void> {\n\t\tconst queryClient = this.getQueryClient();\n\t\tconst queryKey = this.buildQueryKey(endpoint, config);\n\n\t\treturn queryClient.invalidateQueries({\n\t\t\tqueryKey,\n\t\t\texact: !!config, // Use exact matching if config is provided\n\t\t});\n\t}\n\n\t/**\n\t * Invalidate all queries in the cache\n\t * @returns Promise that resolves when invalidation is complete\n\t */\n\tinvalidateAllQueries(): Promise<void> {\n\t\tconst queryClient = this.getQueryClient();\n\t\treturn queryClient.invalidateQueries();\n\t}\n\n\t/**\n\t * Get the underlying QueryClient instance\n\t * @returns The QueryClient instance\n\t */\n\tgetQueryClient(): QueryClient {\n\t\tif (this.queryClient) {\n\t\t\treturn this.queryClient;\n\t\t}\n\n\t\t// If no query client was provided, try to get it from context\n\t\t// This will throw if used outside of QueryClientProvider\n\t\tthrow new Error(\n\t\t\t'No QueryClient set, please provide a QueryClient via the queryClient option or ensure you are within a QueryClientProvider',\n\t\t);\n\t}\n\n\t/**\n\t * Set the QueryClient instance\n\t * @param queryClient - The QueryClient instance to use\n\t */\n\tsetQueryClient(queryClient: QueryClient): void {\n\t\tthis.queryClient = queryClient;\n\t}\n}\n\nexport function createTypedQueryClient<Paths>(\n\toptions?: TypedQueryClientOptions,\n) {\n\treturn new TypedQueryClient<Paths>(options);\n}\n\n// Hook exports for convenience\nexport function useTypedQuery<Paths, T extends QueryEndpoint<Paths>>(\n\tclient: TypedQueryClient<Paths>,\n\tendpoint: T,\n\tconfig?: FilteredRequestConfig<Paths, T>,\n\toptions?: Omit<\n\t\tUseQueryOptions<ExtractEndpointResponse<Paths, T>, Response>,\n\t\t'queryKey' | 'queryFn'\n\t>,\n) {\n\treturn client.useQuery(endpoint, config, options);\n}\n\nexport function useTypedMutation<Paths, T extends MutationEndpoint<Paths>>(\n\tclient: TypedQueryClient<Paths>,\n\tendpoint: T,\n\toptions?: Omit<\n\t\tUseMutationOptions<\n\t\t\tExtractEndpointResponse<Paths, T>,\n\t\t\tResponse,\n\t\t\tFilteredRequestConfig<Paths, T>\n\t\t>,\n\t\t'mutationFn'\n\t>,\n) {\n\treturn client.useMutation(endpoint, options);\n}\n\nexport function useTypedInfiniteQuery<\n\tPaths,\n\tT extends QueryEndpoint<Paths>,\n\tTPageData = ExtractEndpointResponse<Paths, T>,\n\tTPageParam = unknown,\n>(\n\tclient: TypedQueryClient<Paths>,\n\tendpoint: T,\n\toptions: Omit<\n\t\tUseInfiniteQueryOptions<\n\t\t\tTPageData,\n\t\t\tResponse,\n\t\t\t{ pages: TPageData[]; pageParams: TPageParam[] },\n\t\t\tunknown[],\n\t\t\tTPageParam\n\t\t>,\n\t\t'queryKey' | 'queryFn' | 'getNextPageParam' | 'initialPageParam'\n\t> & {\n\t\tgetNextPageParam: (\n\t\t\tlastPage: TPageData,\n\t\t\tallPages: TPageData[],\n\t\t\tlastPageParam: TPageParam,\n\t\t\tallPageParams: TPageParam[],\n\t\t) => TPageParam | undefined;\n\t\tinitialPageParam: TPageParam;\n\t},\n\tconfig?: FilteredRequestConfig<Paths, T>,\n) {\n\treturn client.useInfiniteQuery(endpoint, options, config);\n}\n\n/**\n * Hook to invalidate queries using the current QueryClient from context\n */\nexport function useTypedInvalidateQueries<Paths>(\n\tclient: TypedQueryClient<Paths>,\n) {\n\tconst queryClient = useQueryClient();\n\n\treturn {\n\t\t/**\n\t\t * Invalidate queries for a specific endpoint\n\t\t */\n\t\tinvalidateQueries: <T extends QueryEndpoint<Paths>>(\n\t\t\tendpoint: T,\n\t\t\tconfig?: FilteredRequestConfig<Paths, T>,\n\t\t) => {\n\t\t\tconst queryKey = client.buildQueryKey(endpoint, config);\n\t\t\treturn queryClient.invalidateQueries({\n\t\t\t\tqueryKey,\n\t\t\t\texact: !!config,\n\t\t\t});\n\t\t},\n\n\t\t/**\n\t\t * Invalidate all queries\n\t\t */\n\t\tinvalidateAllQueries: () => {\n\t\t\treturn queryClient.invalidateQueries();\n\t\t},\n\t};\n}\n"],"mappings":";;;;;AA4BA,IAAa,mBAAb,MAAqC;CACpC,AAAQ;CACR,AAAQ;CAER,YAAYA,UAAmC,CAAE,GAAE;AAClD,OAAK,UAAU,mBAA0B,QAAQ;AACjD,OAAK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C1C,KAAI,KAAK,EAAE,QAAQ,OAAO,OAAQ,EAAC;AAGpC,MAAI,UAAU,WAAW,UAAU,OAAO,MACzC,KAAI,KAAK,EAAE,OAAO,OAAO,MAAO,EAAC;AAGlC,SAAO;CACP;;;;;;;CAQD,kBACCN,UACAC,QACgB;EAChB,MAAM,cAAc,KAAK,gBAAgB;EACzC,MAAM,WAAW,KAAK,cAAc,UAAU,OAAO;AAErD,SAAO,YAAY,kBAAkB;GACpC;GACA,SAAS;EACT,EAAC;CACF;;;;;CAMD,uBAAsC;EACrC,MAAM,cAAc,KAAK,gBAAgB;AACzC,SAAO,YAAY,mBAAmB;CACtC;;;;;CAMD,iBAA8B;AAC7B,MAAI,KAAK,YACR,QAAO,KAAK;AAKb,QAAM,IAAI,MACT;CAED;;;;;CAMD,eAAeM,aAAgC;AAC9C,OAAK,cAAc;CACnB;AACD;AAED,SAAgB,uBACfC,SACC;AACD,QAAO,IAAI,iBAAwB;AACnC;AAGD,SAAgB,cACfC,QACAT,UACAC,QACAS,SAIC;AACD,QAAO,OAAO,SAAS,UAAU,QAAQ,QAAQ;AACjD;AAED,SAAgB,iBACfD,QACAT,UACAW,SAQC;AACD,QAAO,OAAO,YAAY,UAAU,QAAQ;AAC5C;AAED,SAAgB,sBAMfF,QACAT,UACAY,SAkBAX,QACC;AACD,QAAO,OAAO,iBAAiB,UAAU,SAAS,OAAO;AACzD;;;;AAKD,SAAgB,0BACfQ,QACC;CACD,MAAM,cAAc,gBAAgB;AAEpC,QAAO;EAIN,mBAAmB,CAClBT,UACAC,WACI;GACJ,MAAM,WAAW,OAAO,cAAc,UAAU,OAAO;AACvD,UAAO,YAAY,kBAAkB;IACpC;IACA,SAAS;GACT,EAAC;EACF;EAKD,sBAAsB,MAAM;AAC3B,UAAO,YAAY,mBAAmB;EACtC;CACD;AACD"}
|
|
1
|
+
{"version":3,"file":"react-query.mjs","names":[],"sources":["../src/react-query.ts"],"sourcesContent":["import type {\n\tQueryClient,\n\tQueryFunctionContext,\n\tUseInfiniteQueryOptions,\n\tUseMutationOptions,\n\tUseQueryOptions,\n} from '@tanstack/react-query';\nimport {\n\tuseInfiniteQuery,\n\tuseMutation,\n\tuseQuery,\n\tuseQueryClient,\n} from '@tanstack/react-query';\nimport { useMemo } from 'react';\nimport { createTypedFetcher } from './fetcher';\nimport type {\n\tExtractEndpointResponse,\n\tFetcherOptions,\n\tFilteredRequestConfig,\n\tMutationEndpoint,\n\tQueryEndpoint,\n\tTypedEndpoint,\n} from './types';\n\nexport interface TypedQueryClientOptions extends FetcherOptions {\n\tqueryClient?: QueryClient;\n}\n\nexport class TypedQueryClient<Paths> {\n\tprivate fetcher: ReturnType<typeof createTypedFetcher<Paths>>;\n\tprivate queryClient?: QueryClient;\n\n\tconstructor(options: TypedQueryClientOptions = {}) {\n\t\tthis.fetcher = createTypedFetcher<Paths>(options);\n\t\tthis.queryClient = options.queryClient;\n\t}\n\n\tuseQuery<T extends QueryEndpoint<Paths>>(\n\t\tendpoint: T,\n\t\tconfig?: FilteredRequestConfig<Paths, T>,\n\t\toptions?: Omit<\n\t\t\tUseQueryOptions<ExtractEndpointResponse<Paths, T>, Response>,\n\t\t\t'queryKey' | 'queryFn'\n\t\t>,\n\t) {\n\t\tconst queryKey = this.buildQueryKey(endpoint, config);\n\n\t\t// Memoize the combined options to prevent unnecessary re-renders\n\t\tconst memoizedOptions = useMemo(\n\t\t\t() => ({\n\t\t\t\tqueryKey,\n\t\t\t\tqueryFn: () => this.fetcher(endpoint, config),\n\t\t\t\t...options,\n\t\t\t}),\n\t\t\t// Dependencies: queryKey, endpoint, config, and options\n\t\t\t// Note: We stringify config and options to ensure stable references\n\t\t\t// eslint-disable-next-line react-hooks/exhaustive-deps\n\t\t\t[\n\t\t\t\tqueryKey.join(','),\n\t\t\t\tendpoint,\n\t\t\t\tJSON.stringify(config),\n\t\t\t\tJSON.stringify(options),\n\t\t\t],\n\t\t);\n\n\t\treturn useQuery<ExtractEndpointResponse<Paths, T>, Response>(\n\t\t\tmemoizedOptions,\n\t\t);\n\t}\n\n\tuseMutation<T extends MutationEndpoint<Paths>>(\n\t\tendpoint: T,\n\t\toptions?: Omit<\n\t\t\tUseMutationOptions<\n\t\t\t\tExtractEndpointResponse<Paths, T>,\n\t\t\t\tResponse,\n\t\t\t\tFilteredRequestConfig<Paths, T>\n\t\t\t>,\n\t\t\t'mutationFn'\n\t\t>,\n\t) {\n\t\t// Memoize the combined options to prevent unnecessary re-renders\n\t\tconst memoizedOptions = useMemo(\n\t\t\t() => ({\n\t\t\t\tmutationFn: (config: FilteredRequestConfig<Paths, T>) =>\n\t\t\t\t\tthis.fetcher(endpoint, config),\n\t\t\t\t...options,\n\t\t\t}),\n\t\t\t// Dependencies: endpoint and options\n\t\t\t// Note: We stringify options to ensure stable reference\n\t\t\t// eslint-disable-next-line react-hooks/exhaustive-deps\n\t\t\t[endpoint, JSON.stringify(options)],\n\t\t);\n\n\t\treturn useMutation<\n\t\t\tExtractEndpointResponse<Paths, T>,\n\t\t\tResponse,\n\t\t\tFilteredRequestConfig<Paths, T>\n\t\t>(memoizedOptions);\n\t}\n\n\tuseInfiniteQuery<\n\t\tT extends QueryEndpoint<Paths>,\n\t\tTPageData = ExtractEndpointResponse<Paths, T>,\n\t\tTPageParam = unknown,\n\t>(\n\t\tendpoint: T,\n\t\toptions: Omit<\n\t\t\tUseInfiniteQueryOptions<\n\t\t\t\tTPageData,\n\t\t\t\tResponse,\n\t\t\t\t{ pages: TPageData[]; pageParams: TPageParam[] },\n\t\t\t\tunknown[],\n\t\t\t\tTPageParam\n\t\t\t>,\n\t\t\t'queryKey' | 'queryFn' | 'getNextPageParam' | 'initialPageParam'\n\t\t> & {\n\t\t\tgetNextPageParam: (\n\t\t\t\tlastPage: TPageData,\n\t\t\t\tallPages: TPageData[],\n\t\t\t\tlastPageParam: TPageParam,\n\t\t\t\tallPageParams: TPageParam[],\n\t\t\t) => TPageParam | undefined;\n\t\t\tinitialPageParam: TPageParam;\n\t\t},\n\t\tconfig?: FilteredRequestConfig<Paths, T>,\n\t) {\n\t\tconst queryKey = this.buildQueryKey(endpoint, config);\n\n\t\t// Memoize the combined options to prevent unnecessary re-renders\n\t\tconst memoizedOptions = useMemo(\n\t\t\t() => ({\n\t\t\t\tqueryKey,\n\t\t\t\tqueryFn: ({\n\t\t\t\t\tpageParam,\n\t\t\t\t}: QueryFunctionContext<unknown[], TPageParam>) => {\n\t\t\t\t\tlet mergedConfig = config;\n\t\t\t\t\tif (pageParam !== undefined && config) {\n\t\t\t\t\t\t// If pageParam is an object, spread it into query\n\t\t\t\t\t\tconst pageQuery =\n\t\t\t\t\t\t\ttypeof pageParam === 'object' ? pageParam : { page: pageParam };\n\t\t\t\t\t\tmergedConfig = {\n\t\t\t\t\t\t\t...config,\n\t\t\t\t\t\t\tquery: { ...(config as any).query, ...pageQuery },\n\t\t\t\t\t\t} as any;\n\t\t\t\t\t} else if (pageParam !== undefined && !config) {\n\t\t\t\t\t\t// If pageParam is an object, use it directly, otherwise wrap in page property\n\t\t\t\t\t\tconst pageQuery =\n\t\t\t\t\t\t\ttypeof pageParam === 'object' ? pageParam : { page: pageParam };\n\t\t\t\t\t\tmergedConfig = { query: pageQuery } as any;\n\t\t\t\t\t}\n\t\t\t\t\treturn this.fetcher(endpoint, mergedConfig) as Promise<TPageData>;\n\t\t\t\t},\n\t\t\t\t...options,\n\t\t\t}),\n\t\t\t// Dependencies: queryKey, endpoint, config, and options\n\t\t\t// Note: We stringify config and options to ensure stable references\n\t\t\t// eslint-disable-next-line react-hooks/exhaustive-deps\n\t\t\t[\n\t\t\t\tqueryKey.join(','),\n\t\t\t\tendpoint,\n\t\t\t\tJSON.stringify(config),\n\t\t\t\tJSON.stringify(options),\n\t\t\t],\n\t\t);\n\n\t\treturn useInfiniteQuery<\n\t\t\tTPageData,\n\t\t\tResponse,\n\t\t\t{ pages: TPageData[]; pageParams: TPageParam[] },\n\t\t\tunknown[],\n\t\t\tTPageParam\n\t\t>(memoizedOptions);\n\t}\n\n\tbuildQueryKey<T extends TypedEndpoint<Paths>>(\n\t\tendpoint: T,\n\t\tconfig?: FilteredRequestConfig<Paths, T>,\n\t): unknown[] {\n\t\tconst key: unknown[] = [endpoint];\n\n\t\tif (config && 'params' in config && config.params) {\n\t\t\tkey.push({ params: config.params });\n\t\t}\n\n\t\tif (config && 'query' in config && config.query) {\n\t\t\tkey.push({ query: config.query });\n\t\t}\n\n\t\treturn key;\n\t}\n\n\t/**\n\t * Invalidate queries for a specific endpoint with optional config\n\t * @param endpoint - The endpoint to invalidate (e.g., 'GET /users')\n\t * @param config - Optional params/query to match specific queries\n\t * @returns Promise that resolves when invalidation is complete\n\t */\n\tinvalidateQueries<T extends QueryEndpoint<Paths>>(\n\t\tendpoint: T,\n\t\tconfig?: FilteredRequestConfig<Paths, T>,\n\t): Promise<void> {\n\t\tconst queryClient = this.getQueryClient();\n\t\tconst queryKey = this.buildQueryKey(endpoint, config);\n\n\t\treturn queryClient.invalidateQueries({\n\t\t\tqueryKey,\n\t\t\texact: !!config, // Use exact matching if config is provided\n\t\t});\n\t}\n\n\t/**\n\t * Invalidate all queries in the cache\n\t * @returns Promise that resolves when invalidation is complete\n\t */\n\tinvalidateAllQueries(): Promise<void> {\n\t\tconst queryClient = this.getQueryClient();\n\t\treturn queryClient.invalidateQueries();\n\t}\n\n\t/**\n\t * Get the underlying QueryClient instance\n\t * @returns The QueryClient instance\n\t */\n\tgetQueryClient(): QueryClient {\n\t\tif (this.queryClient) {\n\t\t\treturn this.queryClient;\n\t\t}\n\n\t\t// If no query client was provided, try to get it from context\n\t\t// This will throw if used outside of QueryClientProvider\n\t\tthrow new Error(\n\t\t\t'No QueryClient set, please provide a QueryClient via the queryClient option or ensure you are within a QueryClientProvider',\n\t\t);\n\t}\n\n\t/**\n\t * Set the QueryClient instance\n\t * @param queryClient - The QueryClient instance to use\n\t */\n\tsetQueryClient(queryClient: QueryClient): void {\n\t\tthis.queryClient = queryClient;\n\t}\n}\n\nexport function createTypedQueryClient<Paths>(\n\toptions?: TypedQueryClientOptions,\n) {\n\treturn new TypedQueryClient<Paths>(options);\n}\n\n// Hook exports for convenience\nexport function useTypedQuery<Paths, T extends QueryEndpoint<Paths>>(\n\tclient: TypedQueryClient<Paths>,\n\tendpoint: T,\n\tconfig?: FilteredRequestConfig<Paths, T>,\n\toptions?: Omit<\n\t\tUseQueryOptions<ExtractEndpointResponse<Paths, T>, Response>,\n\t\t'queryKey' | 'queryFn'\n\t>,\n) {\n\treturn client.useQuery(endpoint, config, options);\n}\n\nexport function useTypedMutation<Paths, T extends MutationEndpoint<Paths>>(\n\tclient: TypedQueryClient<Paths>,\n\tendpoint: T,\n\toptions?: Omit<\n\t\tUseMutationOptions<\n\t\t\tExtractEndpointResponse<Paths, T>,\n\t\t\tResponse,\n\t\t\tFilteredRequestConfig<Paths, T>\n\t\t>,\n\t\t'mutationFn'\n\t>,\n) {\n\treturn client.useMutation(endpoint, options);\n}\n\nexport function useTypedInfiniteQuery<\n\tPaths,\n\tT extends QueryEndpoint<Paths>,\n\tTPageData = ExtractEndpointResponse<Paths, T>,\n\tTPageParam = unknown,\n>(\n\tclient: TypedQueryClient<Paths>,\n\tendpoint: T,\n\toptions: Omit<\n\t\tUseInfiniteQueryOptions<\n\t\t\tTPageData,\n\t\t\tResponse,\n\t\t\t{ pages: TPageData[]; pageParams: TPageParam[] },\n\t\t\tunknown[],\n\t\t\tTPageParam\n\t\t>,\n\t\t'queryKey' | 'queryFn' | 'getNextPageParam' | 'initialPageParam'\n\t> & {\n\t\tgetNextPageParam: (\n\t\t\tlastPage: TPageData,\n\t\t\tallPages: TPageData[],\n\t\t\tlastPageParam: TPageParam,\n\t\t\tallPageParams: TPageParam[],\n\t\t) => TPageParam | undefined;\n\t\tinitialPageParam: TPageParam;\n\t},\n\tconfig?: FilteredRequestConfig<Paths, T>,\n) {\n\treturn client.useInfiniteQuery(endpoint, options, config);\n}\n\n/**\n * Hook to invalidate queries using the current QueryClient from context\n */\nexport function useTypedInvalidateQueries<Paths>(\n\tclient: TypedQueryClient<Paths>,\n) {\n\tconst queryClient = useQueryClient();\n\n\treturn {\n\t\t/**\n\t\t * Invalidate queries for a specific endpoint\n\t\t */\n\t\tinvalidateQueries: <T extends QueryEndpoint<Paths>>(\n\t\t\tendpoint: T,\n\t\t\tconfig?: FilteredRequestConfig<Paths, T>,\n\t\t) => {\n\t\t\tconst queryKey = client.buildQueryKey(endpoint, config);\n\t\t\treturn queryClient.invalidateQueries({\n\t\t\t\tqueryKey,\n\t\t\t\texact: !!config,\n\t\t\t});\n\t\t},\n\n\t\t/**\n\t\t * Invalidate all queries\n\t\t */\n\t\tinvalidateAllQueries: () => {\n\t\t\treturn queryClient.invalidateQueries();\n\t\t},\n\t};\n}\n"],"mappings":";;;;AA4BA,IAAa,mBAAb,MAAqC;CACpC;CACA;CAEA,YAAY,UAAmC,CAAC,GAAG;EAClD,KAAK,UAAU,mBAA0B,OAAO;EAChD,KAAK,cAAc,QAAQ;CAC5B;CAEA,SACC,UACA,QACA,SAIC;EACD,MAAM,WAAW,KAAK,cAAc,UAAU,MAAM;EAGpD,MAAM,kBAAkB,eAChB;GACN;GACA,eAAe,KAAK,QAAQ,UAAU,MAAM;GAC5C,GAAG;EACJ,IAIA;GACC,SAAS,KAAK,GAAG;GACjB;GACA,KAAK,UAAU,MAAM;GACrB,KAAK,UAAU,OAAO;EACvB,CACD;EAEA,OAAO,SACN,eACD;CACD;CAEA,YACC,UACA,SAQC;EAED,MAAM,kBAAkB,eAChB;GACN,aAAa,WACZ,KAAK,QAAQ,UAAU,MAAM;GAC9B,GAAG;EACJ,IAIA,CAAC,UAAU,KAAK,UAAU,OAAO,CAAC,CACnC;EAEA,OAAO,YAIL,eAAe;CAClB;CAEA,iBAKC,UACA,SAkBA,QACC;EACD,MAAM,WAAW,KAAK,cAAc,UAAU,MAAM;EAGpD,MAAM,kBAAkB,eAChB;GACN;GACA,UAAU,EACT,gBACkD;IAClD,IAAI,eAAe;IACnB,IAAI,cAAc,KAAA,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EA,SAAgB,iBACf,QACA,UACA,SAQC;CACD,OAAO,OAAO,YAAY,UAAU,OAAO;AAC5C;AAEA,SAAgB,sBAMf,QACA,UACA,SAkBA,QACC;CACD,OAAO,OAAO,iBAAiB,UAAU,SAAS,MAAM;AACzD;;;;AAKA,SAAgB,0BACf,QACC;CACD,MAAM,cAAc,eAAe;CAEnC,OAAO;;;;EAIN,oBACC,UACA,WACI;GACJ,MAAM,WAAW,OAAO,cAAc,UAAU,MAAM;GACtD,OAAO,YAAY,kBAAkB;IACpC;IACA,OAAO,CAAC,CAAC;GACV,CAAC;EACF;;;;EAKA,4BAA4B;GAC3B,OAAO,YAAY,kBAAkB;EACtC;CACD;AACD"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
//#region src/telemetry.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* W3C trace context on the requests a client makes to its own API, so a user
|
|
4
|
+
* action in the browser and the API request it causes are one trace.
|
|
5
|
+
*
|
|
6
|
+
* Two levels, chosen per request:
|
|
7
|
+
*
|
|
8
|
+
* - **An OpenTelemetry context is active** — a browser SDK has a span open, or
|
|
9
|
+
* this runs on a server (a Next.js server component, an API calling another
|
|
10
|
+
* API) inside a request span. The globally registered propagator writes the
|
|
11
|
+
* headers, so the current span is the parent: `traceparent`, `tracestate`,
|
|
12
|
+
* and whatever else that propagator carries.
|
|
13
|
+
* - **Otherwise** (level 1): one trace id per page view — per page load in a
|
|
14
|
+
* browser, per client in Node — a fresh span id per request, and a sampled
|
|
15
|
+
* flag decided once per page view from {@link ClientTelemetryOptions.sampleRate}.
|
|
16
|
+
*
|
|
17
|
+
* Nothing is sent to any origin but the API's own: a trace id is an identifier,
|
|
18
|
+
* and a third party has no business correlating a user's requests by it. And
|
|
19
|
+
* nothing at all where a `fetch` instrumentation is listening (a server with
|
|
20
|
+
* OpenTelemetry's undici instrumentation): it writes the request's own
|
|
21
|
+
* context, and two `traceparent` headers would be read as none.
|
|
22
|
+
*
|
|
23
|
+
* `@opentelemetry/api` is not imported. Every copy of it — whichever version
|
|
24
|
+
* an app bundles — registers its globals on `globalThis` under
|
|
25
|
+
* `Symbol.for('opentelemetry.js.api.1')`, which is how two copies in one page
|
|
26
|
+
* already share a provider. Reading the propagator and context manager from
|
|
27
|
+
* there costs a browser bundle nothing when no SDK is loaded, and still finds
|
|
28
|
+
* the SDK when one is.
|
|
29
|
+
*/
|
|
30
|
+
/** Telemetry on a client: `true` for the defaults, or these options. */
|
|
31
|
+
interface ClientTelemetryOptions {
|
|
32
|
+
/**
|
|
33
|
+
* The fraction of page views whose requests are sampled, from 0 to 1, when
|
|
34
|
+
* no OpenTelemetry context is active. Decided once per page view, so a
|
|
35
|
+
* page's requests are all kept or all dropped together.
|
|
36
|
+
*
|
|
37
|
+
* Use the stage's rate. The API caps an incoming sampled flag at its own
|
|
38
|
+
* rate anyway, and decides from the trace id the same way this does, so a
|
|
39
|
+
* page view sampled here at the API's rate is sampled there too.
|
|
40
|
+
* @default 1
|
|
41
|
+
*/
|
|
42
|
+
sampleRate?: number;
|
|
43
|
+
}
|
|
44
|
+
/** A `sampleRate` outside 0–1, which no sampler can honour. */
|
|
45
|
+
declare class InvalidClientSampleRate extends Error {
|
|
46
|
+
readonly sampleRate: number;
|
|
47
|
+
constructor(sampleRate: number);
|
|
48
|
+
}
|
|
49
|
+
/** Adds trace headers to a request to `url`, when it is the API's own. */
|
|
50
|
+
type TraceContextInjector = (url: string, headers: Record<string, string>) => void;
|
|
51
|
+
/**
|
|
52
|
+
* Whether a trace is sampled at `rate`, from its id.
|
|
53
|
+
*
|
|
54
|
+
* The same rule as OpenTelemetry's `TraceIdRatioBasedSampler`: the id's four
|
|
55
|
+
* 32-bit words XORed together, under `rate` of the 32-bit range. The trace id
|
|
56
|
+
* is random, so this samples `rate` of page views — and the API, applying the
|
|
57
|
+
* same rule to the same id at the same rate, keeps exactly the page views kept
|
|
58
|
+
* here rather than a random `rate` of them.
|
|
59
|
+
*/
|
|
60
|
+
declare function sampledAt(traceId: string, rate: number): boolean;
|
|
61
|
+
/**
|
|
62
|
+
* An injector for a client whose API is at `baseURL`, or undefined when
|
|
63
|
+
* telemetry is off.
|
|
64
|
+
*/
|
|
65
|
+
declare function traceContextInjector(baseURL: string, telemetry: boolean | ClientTelemetryOptions | undefined): TraceContextInjector | undefined;
|
|
66
|
+
//#endregion
|
|
67
|
+
export { traceContextInjector as a, sampledAt as i, InvalidClientSampleRate as n, TraceContextInjector as r, ClientTelemetryOptions as t };
|
|
68
|
+
//# sourceMappingURL=telemetry-g3BE86Wd.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"telemetry-g3BE86Wd.d.cts","names":[],"sources":["../src/telemetry.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;UA8BiB;;;;;;;;;;;EAWhB;;;cAIY,gCAAgC;WACvB;EAArB,YAAqB;;;KASV,wBACX,aACA,SAAS;;;;;;;;;;iBAiEM,UAAU,iBAAiB;;;;;iBA6E3B,qBACf,iBACA,qBAAqB,qCACnB"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
//#region src/telemetry.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* W3C trace context on the requests a client makes to its own API, so a user
|
|
4
|
+
* action in the browser and the API request it causes are one trace.
|
|
5
|
+
*
|
|
6
|
+
* Two levels, chosen per request:
|
|
7
|
+
*
|
|
8
|
+
* - **An OpenTelemetry context is active** — a browser SDK has a span open, or
|
|
9
|
+
* this runs on a server (a Next.js server component, an API calling another
|
|
10
|
+
* API) inside a request span. The globally registered propagator writes the
|
|
11
|
+
* headers, so the current span is the parent: `traceparent`, `tracestate`,
|
|
12
|
+
* and whatever else that propagator carries.
|
|
13
|
+
* - **Otherwise** (level 1): one trace id per page view — per page load in a
|
|
14
|
+
* browser, per client in Node — a fresh span id per request, and a sampled
|
|
15
|
+
* flag decided once per page view from {@link ClientTelemetryOptions.sampleRate}.
|
|
16
|
+
*
|
|
17
|
+
* Nothing is sent to any origin but the API's own: a trace id is an identifier,
|
|
18
|
+
* and a third party has no business correlating a user's requests by it. And
|
|
19
|
+
* nothing at all where a `fetch` instrumentation is listening (a server with
|
|
20
|
+
* OpenTelemetry's undici instrumentation): it writes the request's own
|
|
21
|
+
* context, and two `traceparent` headers would be read as none.
|
|
22
|
+
*
|
|
23
|
+
* `@opentelemetry/api` is not imported. Every copy of it — whichever version
|
|
24
|
+
* an app bundles — registers its globals on `globalThis` under
|
|
25
|
+
* `Symbol.for('opentelemetry.js.api.1')`, which is how two copies in one page
|
|
26
|
+
* already share a provider. Reading the propagator and context manager from
|
|
27
|
+
* there costs a browser bundle nothing when no SDK is loaded, and still finds
|
|
28
|
+
* the SDK when one is.
|
|
29
|
+
*/
|
|
30
|
+
/** Telemetry on a client: `true` for the defaults, or these options. */
|
|
31
|
+
interface ClientTelemetryOptions {
|
|
32
|
+
/**
|
|
33
|
+
* The fraction of page views whose requests are sampled, from 0 to 1, when
|
|
34
|
+
* no OpenTelemetry context is active. Decided once per page view, so a
|
|
35
|
+
* page's requests are all kept or all dropped together.
|
|
36
|
+
*
|
|
37
|
+
* Use the stage's rate. The API caps an incoming sampled flag at its own
|
|
38
|
+
* rate anyway, and decides from the trace id the same way this does, so a
|
|
39
|
+
* page view sampled here at the API's rate is sampled there too.
|
|
40
|
+
* @default 1
|
|
41
|
+
*/
|
|
42
|
+
sampleRate?: number;
|
|
43
|
+
}
|
|
44
|
+
/** A `sampleRate` outside 0–1, which no sampler can honour. */
|
|
45
|
+
declare class InvalidClientSampleRate extends Error {
|
|
46
|
+
readonly sampleRate: number;
|
|
47
|
+
constructor(sampleRate: number);
|
|
48
|
+
}
|
|
49
|
+
/** Adds trace headers to a request to `url`, when it is the API's own. */
|
|
50
|
+
type TraceContextInjector = (url: string, headers: Record<string, string>) => void;
|
|
51
|
+
/**
|
|
52
|
+
* Whether a trace is sampled at `rate`, from its id.
|
|
53
|
+
*
|
|
54
|
+
* The same rule as OpenTelemetry's `TraceIdRatioBasedSampler`: the id's four
|
|
55
|
+
* 32-bit words XORed together, under `rate` of the 32-bit range. The trace id
|
|
56
|
+
* is random, so this samples `rate` of page views — and the API, applying the
|
|
57
|
+
* same rule to the same id at the same rate, keeps exactly the page views kept
|
|
58
|
+
* here rather than a random `rate` of them.
|
|
59
|
+
*/
|
|
60
|
+
declare function sampledAt(traceId: string, rate: number): boolean;
|
|
61
|
+
/**
|
|
62
|
+
* An injector for a client whose API is at `baseURL`, or undefined when
|
|
63
|
+
* telemetry is off.
|
|
64
|
+
*/
|
|
65
|
+
declare function traceContextInjector(baseURL: string, telemetry: boolean | ClientTelemetryOptions | undefined): TraceContextInjector | undefined;
|
|
66
|
+
//#endregion
|
|
67
|
+
export { traceContextInjector as a, sampledAt as i, InvalidClientSampleRate as n, TraceContextInjector as r, ClientTelemetryOptions as t };
|
|
68
|
+
//# sourceMappingURL=telemetry-g3BE86Wd.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"telemetry-g3BE86Wd.d.mts","names":[],"sources":["../src/telemetry.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;UA8BiB;;;;;;;;;;;EAWhB;;;cAIY,gCAAgC;WACvB;EAArB,YAAqB;;;KASV,wBACX,aACA,SAAS;;;;;;;;;;iBAiEM,UAAU,iBAAiB;;;;;iBA6E3B,qBACf,iBACA,qBAAqB,qCACnB"}
|