{"version":3,"file":"errorBoundaryUtils.cjs","names":["shouldThrowError"],"sources":["../../src/errorBoundaryUtils.ts"],"sourcesContent":["'use client'\nimport * as React from 'react'\nimport { shouldThrowError } from '@tanstack/query-core'\nimport type {\n  DefaultedQueryObserverOptions,\n  Query,\n  QueryKey,\n  QueryObserverResult,\n  ThrowOnError,\n} from '@tanstack/query-core'\nimport type { QueryErrorResetBoundaryValue } from './QueryErrorResetBoundary'\n\n/**\n * Turns off `retryOnMount` for a query that throws its errors (with `suspense` or `throwOnError`),\n * unless the error boundary has been reset, so a remount doesn't retry the failed query before the\n * user resets the boundary. Mutates the options.\n * @param options - The defaulted query options to adjust.\n * @param errorResetBoundary - The value of the nearest `QueryErrorResetBoundary`.\n * @param query - The query, used to evaluate a `throwOnError` function against its error.\n */\nexport const ensurePreventErrorBoundaryRetry = <\n  TQueryFnData,\n  TError,\n  TData,\n  TQueryData,\n  TQueryKey extends QueryKey,\n>(\n  options: DefaultedQueryObserverOptions<\n    TQueryFnData,\n    TError,\n    TData,\n    TQueryData,\n    TQueryKey\n  >,\n  errorResetBoundary: QueryErrorResetBoundaryValue,\n  query: Query<TQueryFnData, TError, TQueryData, TQueryKey> | undefined,\n) => {\n  const throwOnError =\n    query?.state.status === 'error' &&\n    typeof options.throwOnError === 'function'\n      ? shouldThrowError(options.throwOnError, [\n          query.state.error as TError,\n          query,\n        ])\n      : options.throwOnError\n\n  if (options.suspense || throwOnError) {\n    // Prevent retrying failed query if the error boundary has not been reset yet\n    if (!errorResetBoundary.isReset()) {\n      options.retryOnMount = false\n    }\n  }\n}\n\n/**\n * Clears the reset state of the error boundary after the component mounts, so later errors are\n * thrown to the boundary again.\n * @param errorResetBoundary - The value of the nearest `QueryErrorResetBoundary`.\n */\nexport const useClearResetErrorBoundary = (\n  errorResetBoundary: QueryErrorResetBoundaryValue,\n) => {\n  React.useEffect(() => {\n    errorResetBoundary.clearReset()\n  }, [errorResetBoundary])\n}\n\n/**\n * Checks whether the query error should be thrown to the nearest error boundary: the query errored\n * and isn't fetching, the boundary hasn't been reset, and either `suspense` is enabled with no data\n * or `throwOnError` says so.\n * @param params - The observer `result`, the `errorResetBoundary`, the `throwOnError` option, the\n * `query`, and the `suspense` option.\n * @returns `true` if the error should be thrown.\n */\nexport const getHasError = <\n  TData,\n  TError,\n  TQueryFnData,\n  TQueryData,\n  TQueryKey extends QueryKey,\n>({\n  result,\n  errorResetBoundary,\n  throwOnError,\n  query,\n  suspense,\n}: {\n  result: QueryObserverResult<TData, TError>\n  errorResetBoundary: QueryErrorResetBoundaryValue\n  throwOnError: ThrowOnError<TQueryFnData, TError, TQueryData, TQueryKey>\n  query: Query<TQueryFnData, TError, TQueryData, TQueryKey> | undefined\n  suspense: boolean | undefined\n}) => {\n  return (\n    result.isError &&\n    !errorResetBoundary.isReset() &&\n    !result.isFetching &&\n    query &&\n    ((suspense && result.data === undefined) ||\n      shouldThrowError(throwOnError, [result.error, query]))\n  )\n}\n"],"mappings":";;;;;;;;;;;;;;;AAoBA,MAAa,mCAOX,SAOA,oBACA,UACG;CACH,MAAM,eACJ,OAAO,MAAM,WAAW,WACxB,OAAO,QAAQ,iBAAiB,cAAA,GAC5BA,qBAAAA,iBAAAA,CAAiB,QAAQ,cAAc,CACrC,MAAM,MAAM,OACZ,KACF,CAAC,IACD,QAAQ;CAEd,IAAI,QAAQ,YAAY,cAElB;MAAA,CAAC,mBAAmB,QAAQ,GAC9B,QAAQ,eAAe;CAAA;AAG7B;;;;;;AAOA,MAAa,8BACX,uBACG;CACH,MAAM,gBAAgB;EACpB,mBAAmB,WAAW;CAChC,GAAG,CAAC,kBAAkB,CAAC;AACzB;;;;;;;;;AAUA,MAAa,eAMX,EACA,QACA,oBACA,cACA,OACA,eAOI;CACJ,OACE,OAAO,WACP,CAAC,mBAAmB,QAAQ,KAC5B,CAAC,OAAO,cACR,UACE,YAAY,OAAO,SAAS,KAAA,MAAA,GAC5BA,qBAAAA,iBAAAA,CAAiB,cAAc,CAAC,OAAO,OAAO,KAAK,CAAC;AAE1D"}