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
8.8 KiB
Text
1 line
No EOL
8.8 KiB
Text
{"version":3,"sources":["../../../src/server/after/after-context.ts"],"sourcesContent":["import PromiseQueue from 'next/dist/compiled/p-queue'\nimport type { RequestLifecycleOpts } from '../base-server'\nimport type { AfterCallback, AfterTask } from './after'\nimport { InvariantError } from '../../shared/lib/invariant-error'\nimport { isThenable } from '../../shared/lib/is-thenable'\nimport { workAsyncStorage } from '../app-render/work-async-storage.external'\nimport { withExecuteRevalidates } from '../revalidation-utils'\nimport { bindSnapshot } from '../app-render/async-local-storage'\nimport {\n workUnitAsyncStorage,\n type WorkUnitStore,\n} from '../app-render/work-unit-async-storage.external'\nimport { afterTaskAsyncStorage } from '../app-render/after-task-async-storage.external'\n\nexport type AfterContextOpts = {\n waitUntil: RequestLifecycleOpts['waitUntil'] | undefined\n onClose: RequestLifecycleOpts['onClose']\n onTaskError: RequestLifecycleOpts['onAfterTaskError'] | undefined\n}\n\nexport class AfterContext {\n private waitUntil: RequestLifecycleOpts['waitUntil'] | undefined\n private onClose: RequestLifecycleOpts['onClose']\n private onTaskError: RequestLifecycleOpts['onAfterTaskError'] | undefined\n\n private runCallbacksOnClosePromise: Promise<void> | undefined\n private callbackQueue: PromiseQueue\n private workUnitStores = new Set<WorkUnitStore>()\n\n constructor({ waitUntil, onClose, onTaskError }: AfterContextOpts) {\n this.waitUntil = waitUntil\n this.onClose = onClose\n this.onTaskError = onTaskError\n\n this.callbackQueue = new PromiseQueue()\n this.callbackQueue.pause()\n }\n\n public after(task: AfterTask): void {\n if (isThenable(task)) {\n if (!this.waitUntil) {\n errorWaitUntilNotAvailable()\n }\n this.waitUntil(\n task.catch((error) => this.reportTaskError('promise', error))\n )\n } else if (typeof task === 'function') {\n // TODO(after): implement tracing\n this.addCallback(task)\n } else {\n throw new Error('`after()`: Argument must be a promise or a function')\n }\n }\n\n private addCallback(callback: AfterCallback) {\n // if something is wrong, throw synchronously, bubbling up to the `after` callsite.\n if (!this.waitUntil) {\n errorWaitUntilNotAvailable()\n }\n\n const workUnitStore = workUnitAsyncStorage.getStore()\n if (workUnitStore) {\n this.workUnitStores.add(workUnitStore)\n }\n\n const afterTaskStore = afterTaskAsyncStorage.getStore()\n\n // This is used for checking if request APIs can be called inside `after`.\n // Note that we need to check the phase in which the *topmost* `after` was called (which should be \"action\"),\n // not the current phase (which might be \"after\" if we're in a nested after).\n // Otherwise, we might allow `after(() => headers())`, but not `after(() => after(() => headers()))`.\n const rootTaskSpawnPhase = afterTaskStore\n ? afterTaskStore.rootTaskSpawnPhase // nested after\n : workUnitStore?.phase // topmost after\n\n // this should only happen once.\n if (!this.runCallbacksOnClosePromise) {\n this.runCallbacksOnClosePromise = this.runCallbacksOnClose()\n this.waitUntil(this.runCallbacksOnClosePromise)\n }\n\n // Bind the callback to the current execution context (i.e. preserve all currently available ALS-es).\n // We do this because we want all of these to be equivalent in every regard except timing:\n // after(() => x())\n // after(x())\n // await x()\n const wrappedCallback = bindSnapshot(\n // WARNING: Don't make this a named function. It must be anonymous.\n // See: https://github.com/facebook/react/pull/34911\n async () => {\n try {\n await afterTaskAsyncStorage.run({ rootTaskSpawnPhase }, () =>\n callback()\n )\n } catch (error) {\n this.reportTaskError('function', error)\n }\n }\n )\n\n this.callbackQueue.add(wrappedCallback)\n }\n\n private async runCallbacksOnClose() {\n await new Promise<void>((resolve) => this.onClose!(resolve))\n return this.runCallbacks()\n }\n\n private async runCallbacks(): Promise<void> {\n if (this.callbackQueue.size === 0) return\n\n for (const workUnitStore of this.workUnitStores) {\n workUnitStore.phase = 'after'\n }\n\n const workStore = workAsyncStorage.getStore()\n if (!workStore) {\n throw new InvariantError('Missing workStore in AfterContext.runCallbacks')\n }\n\n return withExecuteRevalidates(workStore, () => {\n this.callbackQueue.start()\n return this.callbackQueue.onIdle()\n })\n }\n\n private reportTaskError(taskKind: 'promise' | 'function', error: unknown) {\n // TODO(after): this is fine for now, but will need better intergration with our error reporting.\n // TODO(after): should we log this if we have a onTaskError callback?\n console.error(\n taskKind === 'promise'\n ? `A promise passed to \\`after()\\` rejected:`\n : `An error occurred in a function passed to \\`after()\\`:`,\n error\n )\n if (this.onTaskError) {\n // this is very defensive, but we really don't want anything to blow up in an error handler\n try {\n this.onTaskError?.(error)\n } catch (handlerError) {\n console.error(\n new InvariantError(\n '`onTaskError` threw while handling an error thrown from an `after` task',\n {\n cause: handlerError,\n }\n )\n )\n }\n }\n }\n}\n\nfunction errorWaitUntilNotAvailable(): never {\n throw new Error(\n '`after()` will not work correctly, because `waitUntil` is not available in the current environment.'\n )\n}\n"],"names":["AfterContext","constructor","waitUntil","onClose","onTaskError","workUnitStores","Set","callbackQueue","PromiseQueue","pause","after","task","isThenable","errorWaitUntilNotAvailable","catch","error","reportTaskError","addCallback","Error","callback","workUnitStore","workUnitAsyncStorage","getStore","add","afterTaskStore","afterTaskAsyncStorage","rootTaskSpawnPhase","phase","runCallbacksOnClosePromise","runCallbacksOnClose","wrappedCallback","bindSnapshot","run","Promise","resolve","runCallbacks","size","workStore","workAsyncStorage","InvariantError","withExecuteRevalidates","start","onIdle","taskKind","console","handlerError","cause"],"mappings":";;;;+BAoBaA;;;eAAAA;;;+DApBY;gCAGM;4BACJ;0CACM;mCACM;mCACV;8CAItB;+CAC+B;;;;;;AAQ/B,MAAMA;IASXC,YAAY,EAAEC,SAAS,EAAEC,OAAO,EAAEC,WAAW,EAAoB,CAAE;aAF3DC,iBAAiB,IAAIC;QAG3B,IAAI,CAACJ,SAAS,GAAGA;QACjB,IAAI,CAACC,OAAO,GAAGA;QACf,IAAI,CAACC,WAAW,GAAGA;QAEnB,IAAI,CAACG,aAAa,GAAG,IAAIC,eAAY;QACrC,IAAI,CAACD,aAAa,CAACE,KAAK;IAC1B;IAEOC,MAAMC,IAAe,EAAQ;QAClC,IAAIC,IA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