{"version":3,"sources":["../../../../src/build/segment-config/app/app-segment-config.ts"],"sourcesContent":["import { z } from 'next/dist/compiled/zod'\nimport { formatZodError } from '../../../shared/lib/zod'\n\nconst CookieSchema = z\n .object({\n name: z.string(),\n value: z.string(),\n httpOnly: z.boolean().optional(),\n path: z.string().optional(),\n })\n .strict()\n\nconst RuntimeSampleSchema = z\n .object({\n cookies: z.array(CookieSchema).optional(),\n headers: z.array(z.tuple([z.string(), z.string()])).optional(),\n params: z.record(z.union([z.string(), z.array(z.string())])).optional(),\n searchParams: z\n .record(z.union([z.string(), z.array(z.string()), z.undefined()]))\n .optional(),\n })\n .strict()\n\nconst StaticPrefetchSchema = z\n .object({\n mode: z.literal('static'),\n from: z.array(z.string()).optional(),\n expectUnableToVerify: z.boolean().optional(),\n })\n .strict()\n\nconst RuntimePrefetchSchema = z\n .object({\n mode: z.literal('runtime'),\n samples: z.array(RuntimeSampleSchema).min(1),\n from: z.array(z.string()).optional(),\n expectUnableToVerify: z.boolean().optional(),\n })\n .strict()\n\nconst PrefetchSchema = z.discriminatedUnion('mode', [\n StaticPrefetchSchema,\n RuntimePrefetchSchema,\n])\n\nexport type Prefetch = StaticPrefetch | RuntimePrefetch\nexport type PrefetchForTypeCheckInternal = __GenericPrefetch | Prefetch\n// the __GenericPrefetch type is used to avoid type widening issues with\n// our choice to make exports the medium for programming a Next.js application\n// With exports the type is controlled by the module and all we can do is assert on it\n// from a consumer. However with string literals in objects these are by default typed widely\n// and thus cannot match the discriminated union type. If we figure out a better way we should\n// delete the __GenericPrefetch member.\ninterface __GenericPrefetch {\n mode: string\n samples?: Array\n from?: string[]\n expectUnableToVerify?: boolean\n}\ninterface StaticPrefetch {\n mode: 'static'\n from?: string[]\n expectUnableToVerify?: boolean\n}\ninterface RuntimePrefetch {\n mode: 'runtime'\n samples: Array\n from?: string[]\n expectUnableToVerify?: boolean\n}\ntype WideRuntimeSample = {\n cookies?: RuntimeSample['cookies']\n headers?: Array\n params?: RuntimeSample['params']\n searchParams?: RuntimeSample['searchParams']\n}\ntype RuntimeSample = {\n cookies?: Array<{\n name: string\n value: string\n httpOnly?: boolean\n path?: string\n }>\n headers?: Array<[string, string]>\n params?: { [key: string]: string | string[] }\n searchParams?: { [key: string]: string | string[] | undefined }\n}\n\n/**\n * The schema for configuration for a page.\n */\nconst AppSegmentConfigSchema = z.object({\n /**\n * The number of seconds to revalidate the page or false to disable revalidation.\n */\n revalidate: z\n .union([z.number().int().nonnegative(), z.literal(false)])\n .optional(),\n\n /**\n * Whether the page supports dynamic parameters.\n */\n dynamicParams: z.boolean().optional(),\n\n /**\n * The dynamic behavior of the page.\n */\n dynamic: z\n .enum(['auto', 'error', 'force-static', 'force-dynamic'])\n .optional(),\n\n /**\n * The caching behavior of the page.\n */\n fetchCache: z\n .enum([\n 'auto',\n 'default-cache',\n 'only-cache',\n 'force-cache',\n 'force-no-store',\n 'default-no-store',\n 'only-no-store',\n ])\n .optional(),\n\n /**\n * How this segment should be prefetched.\n * (only applicable when `clientSegmentCache` is enabled)\n */\n unstable_prefetch: PrefetchSchema.optional(),\n\n /**\n * The preferred region for the page.\n */\n preferredRegion: z.union([z.string(), z.array(z.string())]).optional(),\n\n /**\n * The runtime to use for the page.\n */\n runtime: z.enum(['edge', 'nodejs']).optional(),\n\n /**\n * The maximum duration for the page in seconds.\n */\n maxDuration: z.number().int().nonnegative().optional(),\n})\n\n/**\n * Parse the app segment config.\n * @param data - The data to parse.\n * @param route - The route of the app.\n * @returns The parsed app segment config.\n */\nexport function parseAppSegmentConfig(\n data: unknown,\n route: string\n): AppSegmentConfig {\n const parsed = AppSegmentConfigSchema.safeParse(data, {\n errorMap: (issue, ctx) => {\n if (issue.path.length === 1) {\n switch (issue.path[0]) {\n case 'revalidate': {\n return {\n message: `Invalid revalidate value ${JSON.stringify(\n ctx.data\n )} on \"${route}\", must be a non-negative number or false`,\n }\n }\n case 'unstable_prefetch': {\n return {\n // @TODO replace this link with a link to the docs when they are written\n message: `Invalid unstable_prefetch value ${JSON.stringify(ctx.data)} on \"${route}\", must be an object with a mode of \"static\" or \"runtime\". Read more at https://nextjs.org/docs/messages/invalid-prefetch-configuration`,\n }\n }\n default:\n }\n }\n\n return { message: ctx.defaultError }\n },\n })\n\n if (!parsed.success) {\n throw formatZodError(\n `Invalid segment configuration options detected for \"${route}\". Read more at https://nextjs.org/docs/app/api-reference/file-conventions/route-segment-config`,\n parsed.error\n )\n }\n\n return parsed.data\n}\n\n/**\n * The configuration for a page.\n */\nexport type AppSegmentConfig = {\n /**\n * The revalidation period for the page in seconds, or false to disable ISR.\n */\n revalidate?: number | false\n\n /**\n * Whether the page supports dynamic parameters.\n */\n dynamicParams?: boolean\n\n /**\n * The dynamic behavior of the page.\n */\n dynamic?: 'auto' | 'error' | 'force-static' | 'force-dynamic'\n\n /**\n * The caching behavior of the page.\n */\n fetchCache?:\n | 'auto'\n | 'default-cache'\n | 'default-no-store'\n | 'force-cache'\n | 'force-no-store'\n | 'only-cache'\n | 'only-no-store'\n\n /**\n * How this segment should be prefetched.\n * (only applicable when `clientSegmentCache` is enabled)\n */\n unstable_prefetch?: Prefetch\n\n /**\n * The preferred region for the page.\n */\n preferredRegion?: string | string[]\n\n /**\n * The runtime to use for the page.\n */\n runtime?: 'edge' | 'nodejs'\n\n /**\n * The maximum duration for the page in seconds.\n */\n maxDuration?: number\n}\n\n/**\n * The keys of the configuration for a page.\n *\n * @internal - required to exclude zod types from the build\n */\nexport const AppSegmentConfigSchemaKeys = AppSegmentConfigSchema.keyof().options\n"],"names":["z","formatZodError","CookieSchema","object","name","string","value","httpOnly","boolean","optional","path","strict","RuntimeSampleSchema","cookies","array","headers","tuple","params","record","union","searchParams","undefined","StaticPrefetchSchema","mode","literal","from","expectUnableToVerify","RuntimePrefetchSchema","samples","min","PrefetchSchema","discriminatedUnion","AppSegmentConfigSchema","revalidate","number","int","nonnegative","dynamicParams","dynamic","enum","fetchCache","unstable_prefetch","preferredRegion","runtime","maxDuration","parseAppSegmentConfig","data","route","parsed","safeParse","errorMap","issue","ctx","length","message","JSON","stringify","defaultError","success","error","AppSegmentConfigSchemaKeys","keyof","options"],"mappings":"AAAA,SAASA,CAAC,QAAQ,yBAAwB;AAC1C,SAASC,cAAc,QAAQ,0BAAyB;AAExD,MAAMC,eAAeF,EAClBG,MAAM,CAAC;IACNC,MAAMJ,EAAEK,MAAM;IACdC,OAAON,EAAEK,MAAM;IACfE,UAAUP,EAAEQ,OAAO,GAAGC,QAAQ;IAC9BC,MAAMV,EAAEK,MAAM,GAAGI,QAAQ;AAC3B,GACCE,MAAM;AAET,MAAMC,sBAAsBZ,EACzBG,MAAM,CAAC;IACNU,SAASb,EAAEc,KAAK,CAACZ,cAAcO,QAAQ;IACvCM,SAASf,EAAEc,KAAK,CAACd,EAAEgB,KAAK,CAAC;QAAChB,EAAEK,MAAM;QAAIL,EAAEK,MAAM;KAAG,GAAGI,QAAQ;IAC5DQ,QAAQjB,EAAEkB,MAAM,CAAClB,EAAEmB,KAAK,CAAC;QAACnB,EAAEK,MAAM;QAAIL,EAAEc,KAAK,CAACd,EAAEK,MAAM;KAAI,GAAGI,QAAQ;IACrEW,cAAcpB,EACXkB,MAAM,CAAClB,EAAEmB,KAAK,CAAC;QAACnB,EAAEK,MAAM;QAAIL,EAAEc,KAAK,CAACd,EAAEK,MAAM;QAAKL,EAAEqB,SAAS;KAAG,GAC/DZ,QAAQ;AACb,GACCE,MAAM;AAET,MAAMW,uBAAuBtB,EAC1BG,MAAM,CAAC;IACNoB,MAAMvB,EAAEwB,OAAO,CAAC;IAChBC,MAAMzB,EAAEc,KAAK,CAACd,EAAEK,MAAM,IAAII,QAAQ;IAClCiB,sBAAsB1B,EAAEQ,OAAO,GAAGC,QAAQ;AAC5C,GACCE,MAAM;AAET,MAAMgB,wBAAwB3B,EAC3BG,MAAM,CAAC;IACNoB,MAAMvB,EAAEwB,OAAO,CAAC;IAChBI,SAAS5B,EAAEc,KAAK,CAACF,qBAAqBiB,GAAG,CAAC;IAC1CJ,MAAMz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