Next.js website for Rocky Mountain Vending company featuring: - Product catalog with Stripe integration - Service areas and parts pages - Admin dashboard with Clerk authentication - SEO optimized pages with JSON-LD structured data Co-authored-by: Cursor <cursoragent@cursor.com>
1 line
No EOL
10 KiB
Text
1 line
No EOL
10 KiB
Text
{"version":3,"sources":["../../src/server/revalidation-utils.ts"],"sourcesContent":["import type { WorkStore } from './app-render/work-async-storage.external'\nimport type { IncrementalCache } from './lib/incremental-cache'\nimport { getCacheHandlers } from './use-cache/handlers'\n\n/** Run a callback, and execute any *new* revalidations added during its runtime. */\nexport async function withExecuteRevalidates<T>(\n store: WorkStore | undefined,\n callback: () => Promise<T>\n): Promise<T> {\n if (!store) {\n return callback()\n }\n // If we executed any revalidates during the request, then we don't want to execute them again.\n // save the state so we can check if anything changed after we're done running callbacks.\n const savedRevalidationState = cloneRevalidationState(store)\n try {\n return await callback()\n } finally {\n // Check if we have any new revalidates, and if so, wait until they are all resolved.\n const newRevalidates = diffRevalidationState(\n savedRevalidationState,\n cloneRevalidationState(store)\n )\n await executeRevalidates(store, newRevalidates)\n }\n}\n\ntype RevalidationState = Required<\n Pick<\n WorkStore,\n 'pendingRevalidatedTags' | 'pendingRevalidates' | 'pendingRevalidateWrites'\n >\n>\n\nfunction cloneRevalidationState(store: WorkStore): RevalidationState {\n return {\n pendingRevalidatedTags: store.pendingRevalidatedTags\n ? [...store.pendingRevalidatedTags]\n : [],\n pendingRevalidates: { ...store.pendingRevalidates },\n pendingRevalidateWrites: store.pendingRevalidateWrites\n ? [...store.pendingRevalidateWrites]\n : [],\n }\n}\n\nfunction diffRevalidationState(\n prev: RevalidationState,\n curr: RevalidationState\n): RevalidationState {\n const prevTagsWithProfile = new Set(\n prev.pendingRevalidatedTags.map((item) => {\n const profileKey =\n typeof item.profile === 'object'\n ? JSON.stringify(item.profile)\n : item.profile || ''\n return `${item.tag}:${profileKey}`\n })\n )\n const prevRevalidateWrites = new Set(prev.pendingRevalidateWrites)\n return {\n pendingRevalidatedTags: curr.pendingRevalidatedTags.filter((item) => {\n const profileKey =\n typeof item.profile === 'object'\n ? JSON.stringify(item.profile)\n : item.profile || ''\n return !prevTagsWithProfile.has(`${item.tag}:${profileKey}`)\n }),\n pendingRevalidates: Object.fromEntries(\n Object.entries(curr.pendingRevalidates).filter(\n ([key]) => !(key in prev.pendingRevalidates)\n )\n ),\n pendingRevalidateWrites: curr.pendingRevalidateWrites.filter(\n (promise) => !prevRevalidateWrites.has(promise)\n ),\n }\n}\n\nasync function revalidateTags(\n tagsWithProfile: Array<{\n tag: string\n profile?: string | { expire?: number }\n }>,\n incrementalCache: IncrementalCache | undefined,\n workStore?: WorkStore\n): Promise<void> {\n if (tagsWithProfile.length === 0) {\n return\n }\n\n const handlers = getCacheHandlers()\n const promises: Promise<void>[] = []\n\n // Group tags by profile for batch processing\n const tagsByProfile = new Map<\n | string\n | { stale?: number; revalidate?: number; expire?: number }\n | undefined,\n string[]\n >()\n\n for (const item of tagsWithProfile) {\n const profile = item.profile\n // Find existing profile by comparing values\n let existingKey = undefined\n for (const [key] of tagsByProfile) {\n if (\n typeof key === 'string' &&\n typeof profile === 'string' &&\n key === profile\n ) {\n existingKey = key\n break\n }\n if (\n typeof key === 'object' &&\n typeof profile === 'object' &&\n JSON.stringify(key) === JSON.stringify(profile)\n ) {\n existingKey = key\n break\n }\n if (key === profile) {\n existingKey = key\n break\n }\n }\n\n const profileKey = existingKey || profile\n if (!tagsByProfile.has(profileKey)) {\n tagsByProfile.set(profileKey, [])\n }\n tagsByProfile.get(profileKey)!.push(item.tag)\n }\n\n // Process each profile group\n for (const [profile, tagsForProfile] of tagsByProfile) {\n // Look up the cache profile from workStore if available\n let durations: { expire?: number } | undefined\n\n if (profile) {\n let cacheLife:\n | { stale?: number; revalidate?: number; expire?: number }\n | undefined\n\n if (typeof profile === 'object') {\n // Profile is already a cacheLife configuration object\n cacheLife = profile\n } else if (typeof profile === 'string') {\n // Profile is a string key, look it up in workStore\n cacheLife = workStore?.cacheLifeProfiles?.[profile]\n\n if (!cacheLife) {\n throw new Error(\n `Invalid profile provided \"${profile}\" must be configured under cacheLife in next.config or be \"max\"`\n )\n }\n }\n\n if (cacheLife) {\n durations = {\n expire: cacheLife.expire,\n }\n }\n }\n // If profile is not found and not 'max', durations will be undefined\n // which will trigger immediate expiration in the cache handler\n\n for (const handler of handlers || []) {\n if (profile) {\n promises.push(handler.updateTags?.(tagsForProfile, durations))\n } else {\n promises.push(handler.updateTags?.(tagsForProfile))\n }\n }\n\n if (incrementalCache) {\n promises.push(incrementalCache.revalidateTag(tagsForProfile, durations))\n }\n }\n\n await Promise.all(promises)\n}\n\nexport async function executeRevalidates(\n workStore: WorkStore,\n state?: RevalidationState\n) {\n const pendingRevalidatedTags =\n state?.pendingRevalidatedTags ?? workStore.pendingRevalidatedTags ?? []\n\n const pendingRevalidates =\n state?.pendingRevalidates ?? workStore.pendingRevalidates ?? {}\n\n const pendingRevalidateWrites =\n state?.pendingRevalidateWrites ?? workStore.pendingRevalidateWrites ?? []\n\n return Promise.all([\n revalidateTags(\n pendingRevalidatedTags,\n workStore.incrementalCache,\n workStore\n ),\n ...Object.values(pendingRevalidates),\n ...pendingRevalidateWrites,\n ])\n}\n"],"names":["executeRevalidates","withExecuteRevalidates","store","callback","savedRevalidationState","cloneRevalidationState","newRevalidates","diffRevalidationState","pendingRevalidatedTags","pendingRevalidates","pendingRevalidateWrites","prev","curr","prevTagsWithProfile","Set","map","item","profileKey","profile","JSON","stringify","tag","prevRevalidateWrites","filter","has","Object","fromEntries","entries","key","promise","revalidateTags","tagsWithProfile","incrementalCache","workStore","length","handlers","getCacheHandlers","promises","tagsByProfile","Map","existingKey","undefined","set","get","push","tagsForProfile","durations","cacheLife","cacheLifeProfiles","Error","expire","handler","updateTags","revalidateTag","Promise","all","state","values"],"mappings":";;;;;;;;;;;;;;;IAyLsBA,kBAAkB;eAAlBA;;IApLAC,sBAAsB;eAAtBA;;;0BAHW;AAG1B,eAAeA,uBACpBC,KAA4B,EAC5BC,QAA0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