{"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":["AppSegmentConfigSchemaKeys","parseAppSegmentConfig","CookieSchema","z","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","data","route","parsed","safeParse","errorMap","issue","ctx","length","message","JSON","stringify","defaultError","success","formatZodError","error","keyof","options"],"mappings":";;;;;;;;;;;;;;;IA2PaA,0BAA0B;eAA1BA;;IAjGGC,qBAAqB;eAArBA;;;qBA1JE;sBACa;AAE/B,MAAMC,eAAeC,MAAC,CACnBC,MAAM,CAAC;IACNC,MAAMF,MAAC,CAACG,MAAM;IACdC,OAAOJ,MAAC,CAACG,MAAM;IACfE,UAAUL,MAAC,CAACM,OAAO,GAAGC,QAAQ;IAC9BC,MAAMR,MAAC,CAACG,MAAM,GAAGI,QAAQ;AAC3B,GACCE,MAAM;AAET,MAAMC,sBAAsBV,MAAC,CAC1BC,MAAM,CAAC;IACNU,SAASX,MAAC,CAACY,KAAK,CAACb,cAAcQ,QAAQ;IACvCM,SAASb,MAAC,CAACY,KAAK,CAACZ,MAAC,CAACc,KAAK,CAAC;QAACd,MAAC,CAACG,MAAM;QAAIH,MAAC,CAACG,MAAM;KAAG,GAAGI,QAAQ;IAC5DQ,QAAQf,MAAC,CAACgB,MAAM,CAAChB,MAAC,CAACiB,KAAK,CAAC;QAACjB,MAAC,CAACG,MAAM;QAAIH,MAAC,CAACY,KAAK,CAACZ,MAAC,CAACG,MAAM;KAAI,GAAGI,QAAQ;IACrEW,cAAclB,MAAC,CACZgB,MAAM,CAAChB,MAAC,CAACiB,KAAK,CAAC;QAACjB,MAAC,CAACG,MAAM;QAAIH,MAAC,CAACY,KAAK,CAACZ,MAAC,CAACG,MAAM;QAAKH,MAAC,CAACmB,SAAS;KAAG,GAC/DZ,QAAQ;AACb,GACCE,MAAM;AAET,MAAMW,uBAAuBpB,MAAC,CAC3BC,MAAM,CAAC;IACNoB,MAAMrB,MAAC,CAACsB,OAAO,CAAC;IAChBC,MAAMvB,MAAC,CAACY,KAAK,CAACZ,MAAC,CAACG,MAAM,IAAII,QAAQ;IAClCiB,sBAAsBxB,MAAC,CAACM,OAAO,GAAGC,QAAQ;AAC5C,GACCE,MAAM;AAET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