{"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().or(z.null()),\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().or(z.null())])).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.null()]))\n      .optional(),\n  })\n  .strict()\n\nconst InstantConfigStaticSchema = z\n  .object({\n    prefetch: z.literal('static'),\n    samples: z.array(RuntimeSampleSchema).min(1).optional(),\n    from: z.array(z.string()).optional(),\n    unstable_disableValidation: z.literal(true).optional(),\n    unstable_disableDevValidation: z.literal(true).optional(),\n    unstable_disableBuildValidation: z.literal(true).optional(),\n  })\n  .strict()\n\nconst InstantConfigRuntimeSchema = z\n  .object({\n    prefetch: z.literal('runtime'),\n    samples: z.array(RuntimeSampleSchema).min(1),\n    from: z.array(z.string()).optional(),\n    unstable_disableValidation: z.literal(true).optional(),\n    unstable_disableDevValidation: z.literal(true).optional(),\n    unstable_disableBuildValidation: z.literal(true).optional(),\n  })\n  .strict()\n\nconst InstantConfigSchema = z.union([\n  z.discriminatedUnion('prefetch', [\n    InstantConfigStaticSchema,\n    InstantConfigRuntimeSchema,\n  ]),\n  z.literal(false),\n])\n\nexport type Instant = InstantConfigStatic | InstantConfigRuntime | false\n\nexport type InstantConfigForTypeCheckInternal = __GenericInstantConfig | Instant\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 __GenericInstantConfig {\n  prefetch: string\n  samples?: Array<WideInstantSample>\n  from?: string[]\n  unstable_disableValidation?: boolean\n  unstable_disableDevValidation?: boolean\n  unstable_disableBuildValidation?: boolean\n}\n\ninterface InstantConfigStatic {\n  prefetch: 'static'\n  samples?: Array<InstantSample>\n  from?: string[]\n  unstable_disableValidation?: true\n  unstable_disableDevValidation?: true\n  unstable_disableBuildValidation?: true\n}\n\ninterface InstantConfigRuntime {\n  prefetch: 'runtime'\n  samples: Array<InstantSample>\n  from?: string[]\n  unstable_disableValidation?: true\n  unstable_disableDevValidation?: true\n  unstable_disableBuildValidation?: true\n}\n\ntype WideInstantSample = {\n  cookies?: InstantSample['cookies']\n  headers?: Array<string[]>\n  params?: InstantSample['params']\n  searchParams?: InstantSample['searchParams']\n}\n\nexport type InstantSample = {\n  cookies?: Array<{\n    name: string\n    value: string | null\n  }>\n  headers?: Array<[string, string | null]>\n  params?: { [key: string]: string | string[] }\n  searchParams?: { [key: string]: string | string[] | null }\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   */\n  unstable_instant: InstantConfigSchema.optional(),\n\n  /**\n   * The stale time for dynamic responses in seconds.\n   * Controls how long the client-side router cache retains dynamic page data.\n   * Pages only — not allowed in layouts.\n   */\n  unstable_dynamicStaleTime: z.number().int().nonnegative().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_instant': {\n            return {\n              // @TODO replace this link with a link to the docs when they are written\n              message: `Invalid unstable_instant value ${JSON.stringify(ctx.data)} on \"${route}\", must be an object with \\`prefetch: \"static\"\\` or \\`prefetch: \"runtime\"\\`, or \\`false\\`. Read more at https://nextjs.org/docs/messages/invalid-instant-configuration`,\n            }\n          }\n          case 'unstable_dynamicStaleTime': {\n            return {\n              message: `Invalid unstable_dynamicStaleTime value ${JSON.stringify(ctx.data)} on \"${route}\", must be a non-negative number`,\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   */\n  unstable_instant?: Instant\n\n  /**\n   * The stale time for dynamic responses in seconds.\n   * Controls how long the client-side router cache retains dynamic page data.\n   * Pages only — not allowed in layouts.\n   */\n  unstable_dynamicStaleTime?: number\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","or","null","strict","RuntimeSampleSchema","cookies","array","optional","headers","tuple","params","record","union","searchParams","InstantConfigStaticSchema","prefetch","literal","samples","min","from","unstable_disableValidation","unstable_disableDevValidation","unstable_disableBuildValidation","InstantConfigRuntimeSchema","InstantConfigSchema","discriminatedUnion","AppSegmentConfigSchema","revalidate","number","int","nonnegative","dynamicParams","boolean","dynamic","enum","fetchCache","unstable_instant","unstable_dynamicStaleTime","preferredRegion","runtime","maxDuration","parseAppSegmentConfig","data","route","parsed","safeParse","errorMap","issue","ctx","path","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,GAAGE,EAAE,CAACP,EAAEQ,IAAI;AAC7B,GACCC,MAAM;AAET,MAAMC,sBAAsBV,EACzBG,M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