{"version":3,"file":"QueryProvider.cjs","names":[],"sources":["../../src/query/QueryProvider.tsx"],"sourcesContent":["import { useState } from \"react\";\nimport type { ReactNode } from \"react\";\nimport { QueryClient, QueryClientProvider } from \"@tanstack/react-query\";\nimport type { DefaultOptions } from \"@tanstack/react-query\";\nimport { STALE_TIME, CACHE_TIME } from \"./constants\";\nimport { shouldRetryQuery } from \"./retry-policy\";\nimport { warnOnForeignClient } from \"./foreign-client-warning\";\n\nexport interface QueryProviderProps {\n    children: ReactNode;\n    /** Pass an existing client to share it across roots. */\n    client?: QueryClient;\n    /** Overrides for the default options applied when no `client` is provided. */\n    defaultOptions?: DefaultOptions;\n}\n\n/**\n * Wrapper around `QueryClientProvider` that bootstraps a `QueryClient` with\n * sane SDK defaults (5-minute stale time, 30-minute gc time, one retry for\n * failures worth replaying).\n *\n * Retries follow {@link shouldRetryQuery} rather than a flat count: a 4xx other\n * than 408/429 is the server refusing on purpose, and replaying it only doubles\n * the network log while the spinner keeps turning.\n */\nexport function QueryProvider({ children, client, defaultOptions }: QueryProviderProps) {\n    warnOnForeignClient(client);\n\n    const [internalClient] = useState<QueryClient>(\n        () =>\n            client ??\n            new QueryClient({\n                defaultOptions: {\n                    queries: {\n                        staleTime: STALE_TIME.DEFAULT,\n                        gcTime: CACHE_TIME.DEFAULT,\n                        retry: shouldRetryQuery,\n                        refetchOnWindowFocus: false,\n                        ...(defaultOptions?.queries ?? {}),\n                    },\n                    mutations: {\n                        retry: 0,\n                        ...(defaultOptions?.mutations ?? {}),\n                    },\n                },\n            }),\n    );\n\n    return <QueryClientProvider client={internalClient}>{children}</QueryClientProvider>;\n}\n"],"mappings":"sMAyBA,SAAgB,EAAc,CAAE,WAAU,SAAQ,kBAAsC,CACpF,EAAA,oBAAoB,CAAM,EAE1B,GAAM,CAAC,IAAA,EAAkB,EAAA,SAAA,KAEjB,GACA,IAAI,EAAA,YAAY,CACZ,eAAgB,CACZ,QAAS,CACL,UAAW,EAAA,WAAW,QACtB,OAAQ,EAAA,WAAW,QACnB,MAAO,EAAA,iBACP,qBAAsB,GACtB,GAAI,GAAgB,SAAW,CAAC,CACpC,EACA,UAAW,CACP,MAAO,EACP,GAAI,GAAgB,WAAa,CAAC,CACtC,CACJ,CACJ,CAAC,CACT,EAEA,OAAO,EAAA,EAAA,IAAA,CAAC,EAAA,oBAAD,CAAqB,OAAQ,EAAiB,UAA8B,CAAA,CACvF"}