{"version":3,"sources":["../../../src/server/app-render/dev-validation-worker-snapshot.ts"],"sourcesContent":["import type { AppRenderContext, ResolvedValidationInputs } from './app-render'\nimport type { PrefetchingMode } from './app-render'\nimport type { OpaqueFallbackRouteParams } from '../request/fallback-params'\nimport type { AnyStream } from './stream-ops'\nimport type {\n  DevValidationSnapshot,\n  SerializedValidationInputs,\n} from './dev-validation-worker-globals'\n\nimport { isNodeNextResponse } from '../base-http/helpers'\n\n/**\n * Builds the serializable snapshot the dev validation worker needs to rebuild\n * the render context and inputs and run `runValidationInDev` on the worker\n * thread. Reads only serializable data from the settled render; the live\n * objects (`componentMod`, the async-storage stores,\n * `getDynamicParamFromSegment`) are reconstructed on the worker from this seed.\n * Draining the debug channels is async, so this returns a promise.\n */\nexport async function buildDevValidationSnapshot(\n  ctx: AppRenderContext,\n  instantInputs: ResolvedValidationInputs | null,\n  staticInputs: ResolvedValidationInputs,\n  prefetchMode: PrefetchingMode,\n  fallbackRouteParams: OpaqueFallbackRouteParams | null,\n  devRenderDidError: boolean\n): Promise<DevValidationSnapshot> {\n  const requestStore = staticInputs.requestStore\n  const responseFinished =\n    !isNodeNextResponse(ctx.res) || ctx.res.originalResponse.writableFinished\n\n  // The instant and static inputs may share one debug channel, so drain each\n  // channel only once.\n  const chunksByChannel = new WeakMap<AnyStream, Uint8Array[]>()\n  const getDebugChunksOnce = async (\n    channel: AnyStream | undefined\n  ): Promise<Uint8Array[] | null> => {\n    if (!channel) {\n      return null\n    }\n    let chunks = chunksByChannel.get(channel)\n    if (!chunks) {\n      chunks = []\n      for await (const chunk of channel) {\n        chunks.push(chunk)\n      }\n      chunksByChannel.set(channel, chunks)\n    }\n    return chunks\n  }\n\n  const toSerializedInputs = async (\n    inputs: ResolvedValidationInputs\n  ): Promise<SerializedValidationInputs> => ({\n    accumulatedChunks: inputs.accumulatedChunks,\n    debugChunks: await getDebugChunksOnce(inputs.debugChannelClient),\n    startTime: inputs.startTime,\n    stageEndTimes: inputs.stageEndTimes,\n  })\n\n  return {\n    page: ctx.workStore.page,\n    route: ctx.workStore.route,\n    requestId: ctx.requestId,\n    responseFinished,\n    prefetchMode,\n    devRenderDidError,\n    nonce: ctx.nonce,\n    query: ctx.query,\n    request: {\n      headers: [...requestStore.headers.entries()],\n      urlPathname: requestStore.url.pathname,\n      urlSearch: requestStore.url.search,\n      rootParams: requestStore.rootParams,\n      isDraftMode: requestStore.draftMode.isEnabled,\n      isHmrRefresh: requestStore.isHmrRefresh ?? false,\n      hmrRefreshHash: requestStore.hmrRefreshHash,\n      requestStartTime: ctx.workStore.requestStartTime,\n    },\n    interpolatedParams: ctx.interpolatedParams,\n    requestFallbackRouteParams: ctx.fallbackRouteParams,\n    fallbackRouteParams,\n    optimisticRouting: ctx.renderOpts.experimental.optimisticRouting,\n    forceStatic: ctx.workStore.forceStatic,\n    validationLevel: ctx.workStore.validationLevel,\n    implicitTags: ctx.implicitTags.tags,\n    additionalClientReferenceManifestPages: ctx.workStore\n      .additionalClientReferenceManifestPages\n      ? [...ctx.workStore.additionalClientReferenceManifestPages]\n      : [],\n    isDebugChannelEnabled: !!ctx.renderOpts.setReactDebugChannel,\n    renderOpts: {\n      images: ctx.renderOpts.images,\n      allowEmptyStaticShell: ctx.renderOpts.allowEmptyStaticShell,\n    },\n    instantInputs: instantInputs\n      ? await toSerializedInputs(instantInputs)\n      : null,\n    staticInputs: await toSerializedInputs(staticInputs),\n  }\n}\n"],"names":["buildDevValidationSnapshot","ctx","instantInputs","staticInputs","prefetchMode","fallbackRouteParams","devRenderDidError","requestStore","responseFinished","isNodeNextResponse","res","originalResponse","writableFinished","chunksByChannel","WeakMap","getDebugChunksOnce","channel","chunks","get","chunk","push","set","toSerializedInputs","inputs","accumulatedChunks","debugChunks","debugChannelClient","startTime","stageEndTimes","page","workStore","route","requestId","nonce","query","request","headers","entries","urlPathname","url","pathname","urlSearch","search","rootParams","isDraftMode","draftMode","isEnabled","isHmrRefresh","hmrRefreshHash","requestStartTime","interpolatedParams","requestFallbackRouteParams","optimisticRouting","renderOpts","experimental","forceStatic","validationLevel","implicitTags","tags","additionalClientReferenceManifestPages","isDebugChannelEnabled","setReactDebugChannel","images","allowEmptyStaticShell"],"mappings":";;;;+BAmBsBA;;;eAAAA;;;yBAVa;AAU5B,eAAeA,2BACpBC,GAAqB,EACrBC,aAA8C,EAC9CC,YAAsC,EACtCC,YAA6B,EAC7BC,mBAAqD,EACrDC,iBAA0B;IAE1B,MAAMC,eAAeJ,aAAaI,YAAY;IAC9C,MAAMC,mBACJ,CAACC,IAAAA,2BAAkB,EAACR,IAAIS,GAAG,KAAKT,IAAIS,GAAG,CAACC,gBAAgB,CAACC,gBAAgB;IAE3E,2EAA2E;IAC3E,qBAAqB;IACrB,MAAMC,kBAAkB,IAAIC;IAC5B,MAAMC,qBAAqB,OACzBC;QAEA,IAAI,CAACA,SAAS;YACZ,OAAO;QACT;QACA,IAAIC,SAASJ,gBAAgBK,GAAG,CAACF;QACjC,IAAI,CAACC,QAAQ;YACXA,SAAS,EAAE;YACX,WAAW,MAAME,SAASH,QAAS;gBACjCC,OAAOG,IAAI,CAACD;YACd;YACAN,gBAAgBQ,GAAG,CAACL,SAASC;QAC/B;QACA,OAAOA;IACT;IAEA,MAAMK,qBAAqB,OACzBC,SACyC,CAAA;YACzCC,mBAAmBD,OAAOC,iBAAiB;YAC3CC,aAAa,MAAMV,mBAAmBQ,OAAOG,kBAAkB;YAC/DC,WAAWJ,OAAOI,SAAS;YAC3BC,eAAeL,OAAOK,aAAa;QACrC,CAAA;IAEA,OAAO;QACLC,MAAM5B,IAAI6B,SAAS,CAACD,IAAI;QACxBE,OAAO9B,IAAI6B,SAAS,CAACC,KAAK;QAC1BC,WAAW/B,IAAI+B,SAAS;QACxBxB;QACAJ;QACAE;QACA2B,OAAOhC,IAAIgC,KAAK;QAChBC,OAAOjC,IAAIiC,KAAK;QAChBC,SAAS;YACPC,SAAS;mBAAI7B,aAAa6B,OAAO,CAACC,OAAO;aAAG;YAC5CC,aAAa/B,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