the-forest/client/node_modules/.cache/babel-loader/54682a49e47ddb564f9252720513248ba0e8497794f2affb80851fcf76a811b0.json
2024-09-17 20:35:18 -04:00

1 line
15 KiB
JSON

{"ast":null,"code":"// src/hydration.ts\nfunction defaultTransformerFn(data) {\n return data;\n}\nfunction dehydrateMutation(mutation) {\n return {\n mutationKey: mutation.options.mutationKey,\n state: mutation.state,\n ...(mutation.options.scope && {\n scope: mutation.options.scope\n }),\n ...(mutation.meta && {\n meta: mutation.meta\n })\n };\n}\nfunction dehydrateQuery(query, serializeData) {\n return {\n state: {\n ...query.state,\n ...(query.state.data !== void 0 && {\n data: serializeData(query.state.data)\n })\n },\n queryKey: query.queryKey,\n queryHash: query.queryHash,\n ...(query.state.status === \"pending\" && {\n promise: query.promise?.then(serializeData).catch(error => {\n if (process.env.NODE_ENV !== \"production\") {\n console.error(`A query that was dehydrated as pending ended up rejecting. [${query.queryHash}]: ${error}; The error will be redacted in production builds`);\n }\n return Promise.reject(new Error(\"redacted\"));\n })\n }),\n ...(query.meta && {\n meta: query.meta\n })\n };\n}\nfunction defaultShouldDehydrateMutation(mutation) {\n return mutation.state.isPaused;\n}\nfunction defaultShouldDehydrateQuery(query) {\n return query.state.status === \"success\";\n}\nfunction dehydrate(client, options = {}) {\n const filterMutation = options.shouldDehydrateMutation ?? client.getDefaultOptions().dehydrate?.shouldDehydrateMutation ?? defaultShouldDehydrateMutation;\n const mutations = client.getMutationCache().getAll().flatMap(mutation => filterMutation(mutation) ? [dehydrateMutation(mutation)] : []);\n const filterQuery = options.shouldDehydrateQuery ?? client.getDefaultOptions().dehydrate?.shouldDehydrateQuery ?? defaultShouldDehydrateQuery;\n const serializeData = options.serializeData ?? client.getDefaultOptions().dehydrate?.serializeData ?? defaultTransformerFn;\n const queries = client.getQueryCache().getAll().flatMap(query => filterQuery(query) ? [dehydrateQuery(query, serializeData)] : []);\n return {\n mutations,\n queries\n };\n}\nfunction hydrate(client, dehydratedState, options) {\n if (typeof dehydratedState !== \"object\" || dehydratedState === null) {\n return;\n }\n const mutationCache = client.getMutationCache();\n const queryCache = client.getQueryCache();\n const deserializeData = options?.defaultOptions?.deserializeData ?? client.getDefaultOptions().hydrate?.deserializeData ?? defaultTransformerFn;\n const mutations = dehydratedState.mutations || [];\n const queries = dehydratedState.queries || [];\n mutations.forEach(({\n state,\n ...mutationOptions\n }) => {\n mutationCache.build(client, {\n ...client.getDefaultOptions().hydrate?.mutations,\n ...options?.defaultOptions?.mutations,\n ...mutationOptions\n }, state);\n });\n queries.forEach(({\n queryKey,\n state,\n queryHash,\n meta,\n promise\n }) => {\n let query = queryCache.get(queryHash);\n const data = state.data === void 0 ? state.data : deserializeData(state.data);\n if (query) {\n if (query.state.dataUpdatedAt < state.dataUpdatedAt) {\n const {\n fetchStatus: _ignored,\n ...serializedState\n } = state;\n query.setState({\n ...serializedState,\n data\n });\n }\n } else {\n query = queryCache.build(client, {\n ...client.getDefaultOptions().hydrate?.queries,\n ...options?.defaultOptions?.queries,\n queryKey,\n queryHash,\n meta\n },\n // Reset fetch status to idle to avoid\n // query being stuck in fetching state upon hydration\n {\n ...state,\n data,\n fetchStatus: \"idle\"\n });\n }\n if (promise) {\n const initialPromise = Promise.resolve(promise).then(deserializeData);\n void query.fetch(void 0, {\n initialPromise\n });\n }\n });\n}\nexport { defaultShouldDehydrateMutation, defaultShouldDehydrateQuery, dehydrate, hydrate };","map":{"version":3,"names":["defaultTransformerFn","data","dehydrateMutation","mutation","mutationKey","options","state","scope","meta","dehydrateQuery","query","serializeData","queryKey","queryHash","status","promise","then","catch","error","process","env","NODE_ENV","console","Promise","reject","Error","defaultShouldDehydrateMutation","isPaused","defaultShouldDehydrateQuery","dehydrate","client","filterMutation","shouldDehydrateMutation","getDefaultOptions","mutations","getMutationCache","getAll","flatMap","filterQuery","shouldDehydrateQuery","queries","getQueryCache","hydrate","dehydratedState","mutationCache","queryCache","deserializeData","defaultOptions","forEach","mutationOptions","build","get","dataUpdatedAt","fetchStatus","_ignored","serializedState","setState","initialPromise","resolve","fetch"],"sources":["/Users/shoofle/Projects/the-forest/node_modules/@tanstack/query-core/src/hydration.ts"],"sourcesContent":["import type {\n DefaultError,\n MutationKey,\n MutationMeta,\n MutationOptions,\n MutationScope,\n QueryKey,\n QueryMeta,\n QueryOptions,\n} from './types'\nimport type { QueryClient } from './queryClient'\nimport type { Query, QueryState } from './query'\nimport type { Mutation, MutationState } from './mutation'\n\n// TYPES\ntype TransformerFn = (data: any) => any\nfunction defaultTransformerFn(data: any): any {\n return data\n}\n\nexport interface DehydrateOptions {\n serializeData?: TransformerFn\n shouldDehydrateMutation?: (mutation: Mutation) => boolean\n shouldDehydrateQuery?: (query: Query) => boolean\n}\n\nexport interface HydrateOptions {\n defaultOptions?: {\n deserializeData?: TransformerFn\n queries?: QueryOptions\n mutations?: MutationOptions<unknown, DefaultError, unknown, unknown>\n }\n}\n\ninterface DehydratedMutation {\n mutationKey?: MutationKey\n state: MutationState\n meta?: MutationMeta\n scope?: MutationScope\n}\n\ninterface DehydratedQuery {\n queryHash: string\n queryKey: QueryKey\n state: QueryState\n promise?: Promise<unknown>\n meta?: QueryMeta\n}\n\nexport interface DehydratedState {\n mutations: Array<DehydratedMutation>\n queries: Array<DehydratedQuery>\n}\n\n// FUNCTIONS\n\nfunction dehydrateMutation(mutation: Mutation): DehydratedMutation {\n return {\n mutationKey: mutation.options.mutationKey,\n state: mutation.state,\n ...(mutation.options.scope && { scope: mutation.options.scope }),\n ...(mutation.meta && { meta: mutation.meta }),\n }\n}\n\n// Most config is not dehydrated but instead meant to configure again when\n// consuming the de/rehydrated data, typically with useQuery on the client.\n// Sometimes it might make sense to prefetch data on the server and include\n// in the html-payload, but not consume it on the initial render.\nfunction dehydrateQuery(\n query: Query,\n serializeData: TransformerFn,\n): DehydratedQuery {\n return {\n state: {\n ...query.state,\n ...(query.state.data !== undefined && {\n data: serializeData(query.state.data),\n }),\n },\n queryKey: query.queryKey,\n queryHash: query.queryHash,\n ...(query.state.status === 'pending' && {\n promise: query.promise?.then(serializeData).catch((error) => {\n if (process.env.NODE_ENV !== 'production') {\n console.error(\n `A query that was dehydrated as pending ended up rejecting. [${query.queryHash}]: ${error}; The error will be redacted in production builds`,\n )\n }\n return Promise.reject(new Error('redacted'))\n }),\n }),\n ...(query.meta && { meta: query.meta }),\n }\n}\n\nexport function defaultShouldDehydrateMutation(mutation: Mutation) {\n return mutation.state.isPaused\n}\n\nexport function defaultShouldDehydrateQuery(query: Query) {\n return query.state.status === 'success'\n}\n\nexport function dehydrate(\n client: QueryClient,\n options: DehydrateOptions = {},\n): DehydratedState {\n const filterMutation =\n options.shouldDehydrateMutation ??\n client.getDefaultOptions().dehydrate?.shouldDehydrateMutation ??\n defaultShouldDehydrateMutation\n\n const mutations = client\n .getMutationCache()\n .getAll()\n .flatMap((mutation) =>\n filterMutation(mutation) ? [dehydrateMutation(mutation)] : [],\n )\n\n const filterQuery =\n options.shouldDehydrateQuery ??\n client.getDefaultOptions().dehydrate?.shouldDehydrateQuery ??\n defaultShouldDehydrateQuery\n\n const serializeData =\n options.serializeData ??\n client.getDefaultOptions().dehydrate?.serializeData ??\n defaultTransformerFn\n\n const queries = client\n .getQueryCache()\n .getAll()\n .flatMap((query) =>\n filterQuery(query) ? [dehydrateQuery(query, serializeData)] : [],\n )\n\n return { mutations, queries }\n}\n\nexport function hydrate(\n client: QueryClient,\n dehydratedState: unknown,\n options?: HydrateOptions,\n): void {\n if (typeof dehydratedState !== 'object' || dehydratedState === null) {\n return\n }\n\n const mutationCache = client.getMutationCache()\n const queryCache = client.getQueryCache()\n const deserializeData =\n options?.defaultOptions?.deserializeData ??\n client.getDefaultOptions().hydrate?.deserializeData ??\n defaultTransformerFn\n\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n const mutations = (dehydratedState as DehydratedState).mutations || []\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n const queries = (dehydratedState as DehydratedState).queries || []\n\n mutations.forEach(({ state, ...mutationOptions }) => {\n mutationCache.build(\n client,\n {\n ...client.getDefaultOptions().hydrate?.mutations,\n ...options?.defaultOptions?.mutations,\n ...mutationOptions,\n },\n state,\n )\n })\n\n queries.forEach(({ queryKey, state, queryHash, meta, promise }) => {\n let query = queryCache.get(queryHash)\n\n const data =\n state.data === undefined ? state.data : deserializeData(state.data)\n\n // Do not hydrate if an existing query exists with newer data\n if (query) {\n if (query.state.dataUpdatedAt < state.dataUpdatedAt) {\n // omit fetchStatus from dehydrated state\n // so that query stays in its current fetchStatus\n const { fetchStatus: _ignored, ...serializedState } = state\n query.setState({\n ...serializedState,\n data,\n })\n }\n } else {\n // Restore query\n query = queryCache.build(\n client,\n {\n ...client.getDefaultOptions().hydrate?.queries,\n ...options?.defaultOptions?.queries,\n queryKey,\n queryHash,\n meta,\n },\n // Reset fetch status to idle to avoid\n // query being stuck in fetching state upon hydration\n {\n ...state,\n data,\n fetchStatus: 'idle',\n },\n )\n }\n\n if (promise) {\n // Note: `Promise.resolve` required cause\n // RSC transformed promises are not thenable\n const initialPromise = Promise.resolve(promise).then(deserializeData)\n\n // this doesn't actually fetch - it just creates a retryer\n // which will re-use the passed `initialPromise`\n void query.fetch(undefined, { initialPromise })\n }\n })\n}\n"],"mappings":";AAgBA,SAASA,qBAAqBC,IAAA,EAAgB;EAC5C,OAAOA,IAAA;AACT;AAsCA,SAASC,kBAAkBC,QAAA,EAAwC;EACjE,OAAO;IACLC,WAAA,EAAaD,QAAA,CAASE,OAAA,CAAQD,WAAA;IAC9BE,KAAA,EAAOH,QAAA,CAASG,KAAA;IAChB,IAAIH,QAAA,CAASE,OAAA,CAAQE,KAAA,IAAS;MAAEA,KAAA,EAAOJ,QAAA,CAASE,OAAA,CAAQE;IAAM;IAC9D,IAAIJ,QAAA,CAASK,IAAA,IAAQ;MAAEA,IAAA,EAAML,QAAA,CAASK;IAAK;EAC7C;AACF;AAMA,SAASC,eACPC,KAAA,EACAC,aAAA,EACiB;EACjB,OAAO;IACLL,KAAA,EAAO;MACL,GAAGI,KAAA,C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