the-forest/client/node_modules/.cache/babel-loader/1446cdb7770abc33d1f85cee1900bf53451c6eab295b67ad901f2f61ab58eca7.json

1 line
19 KiB
JSON
Raw Normal View History

2024-09-17 20:35:18 -04:00
{"ast":null,"code":"\"use client\";\n\n// src/useQueries.ts\nimport * as React from \"react\";\nimport { QueriesObserver, QueryObserver, notifyManager } from \"@tanstack/query-core\";\nimport { useQueryClient } from \"./QueryClientProvider.js\";\nimport { useIsRestoring } from \"./isRestoring.js\";\nimport { useQueryErrorResetBoundary } from \"./QueryErrorResetBoundary.js\";\nimport { ensurePreventErrorBoundaryRetry, getHasError, useClearResetErrorBoundary } from \"./errorBoundaryUtils.js\";\nimport { ensureSuspenseTimers, fetchOptimistic, shouldSuspend, willFetch } from \"./suspense.js\";\nfunction useQueries({\n queries,\n ...options\n}, queryClient) {\n const client = useQueryClient(queryClient);\n const isRestoring = useIsRestoring();\n const errorResetBoundary = useQueryErrorResetBoundary();\n const defaultedQueries = React.useMemo(() => queries.map(opts => {\n const defaultedOptions = client.defaultQueryOptions(opts);\n defaultedOptions._optimisticResults = isRestoring ? \"isRestoring\" : \"optimistic\";\n return defaultedOptions;\n }), [queries, client, isRestoring]);\n defaultedQueries.forEach(query => {\n ensureSuspenseTimers(query);\n ensurePreventErrorBoundaryRetry(query, errorResetBoundary);\n });\n useClearResetErrorBoundary(errorResetBoundary);\n const [observer] = React.useState(() => new QueriesObserver(client, defaultedQueries, options));\n const [optimisticResult, getCombinedResult, trackResult] = observer.getOptimisticResult(defaultedQueries, options.combine);\n React.useSyncExternalStore(React.useCallback(onStoreChange => isRestoring ? () => void 0 : observer.subscribe(notifyManager.batchCalls(onStoreChange)), [observer, isRestoring]), () => observer.getCurrentResult(), () => observer.getCurrentResult());\n React.useEffect(() => {\n observer.setQueries(defaultedQueries, options, {\n listeners: false\n });\n }, [defaultedQueries, options, observer]);\n const shouldAtLeastOneSuspend = optimisticResult.some((result, index) => shouldSuspend(defaultedQueries[index], result));\n const suspensePromises = shouldAtLeastOneSuspend ? optimisticResult.flatMap((result, index) => {\n const opts = defaultedQueries[index];\n if (opts) {\n const queryObserver = new QueryObserver(client, opts);\n if (shouldSuspend(opts, result)) {\n return fetchOptimistic(opts, queryObserver, errorResetBoundary);\n } else if (willFetch(result, isRestoring)) {\n void fetchOptimistic(opts, queryObserver, errorResetBoundary);\n }\n }\n return [];\n }) : [];\n if (suspensePromises.length > 0) {\n throw Promise.all(suspensePromises);\n }\n const firstSingleResultWhichShouldThrow = optimisticResult.find((result, index) => {\n const query = defaultedQueries[index];\n return query && getHasError({\n result,\n errorResetBoundary,\n throwOnError: query.throwOnError,\n query: client.getQueryCache().get(query.queryHash)\n });\n });\n if (firstSingleResultWhichShouldThrow?.error) {\n throw firstSingleResultWhichShouldThrow.error;\n }\n return getCombinedResult(trackResult());\n}\nexport { useQueries };","map":{"version":3,"names":["React","QueriesObserver","QueryObserver","notifyManager","useQueryClient","useIsRestoring","useQueryErrorResetBoundary","ensurePreventErrorBoundaryRetry","getHasError","useClearResetErrorBoundary","ensureSuspenseTimers","fetchOptimistic","shouldSuspend","willFetch","useQueries","queries","options","queryClient","client","isRestoring","errorResetBoundary","defaultedQueries","useMemo","map","opts","defaultedOptions","defaultQueryOptions","_optimisticResults","forEach","query","observer","useState","optimisticResult","getCombinedResult","trackResult","getOptimisticResult","combine","useSyncExternalStore","useCallback","onStoreChange","subscribe","batchCalls","getCurrentResult","useEffect","setQueries","listeners","shouldAtLeastOneSuspend","some","result","index","suspensePromises","flatMap","queryObserver","length","Promise","all","firstSingleResultWhichShouldThrow","find","throwOnError","getQ