{"version":3,"sources":["../../src/uploads/types.ts"],"sourcesContent":["import type { ResizeOptions, Sharp, SharpOptions } from 'sharp'\n\nimport type { CollectionConfig, TypeWithID } from '../collections/config/types.js'\nimport type { PayloadComponent } from '../config/types.js'\nimport type { PayloadRequest } from '../types/index.js'\nimport type { WithMetadata } from './optionallyAppendMetadata.js'\n\nexport type FileSize = {\n  filename: null | string\n  filesize: null | number\n  height: null | number\n  mimeType: null | string\n  url?: null | string // TODO V4: make non-optional\n  width: null | number\n}\n\n// TODO: deprecate in Payload v4.\n/**\n * FileSizeImproved is a more precise type, and will replace FileSize in Payload v4.\n * This type is for internal use only as it will be deprecated in the future.\n * @internal\n */\nexport type FileSizeImproved = {\n  url: null | string\n} & FileSize\n\nexport type FileSizes = {\n  [size: string]: FileSize\n}\n\nexport type FileData = {\n  filename: string\n  filesize: number\n  focalX?: number\n  focalY?: number\n  height: number\n  mimeType: string\n  sizes: FileSizes\n  tempFilePath?: string\n  url?: string\n  width: number\n}\n\nexport type ProbedImageSize = {\n  height: number\n  width: number\n}\n\n/**\n * Params sent to the sharp `toFormat()` function\n * @link https://sharp.pixelplumbing.com/api-output#toformat\n */\nexport type ImageUploadFormatOptions = {\n  format: Parameters<Sharp['toFormat']>[0]\n  options?: Parameters<Sharp['toFormat']>[1]\n}\n\n/**\n * Params sent to the sharp trim() function\n * @link https://sharp.pixelplumbing.com/api-resize#trim\n */\nexport type ImageUploadTrimOptions = Parameters<Sharp['trim']>[0]\n\nexport type GenerateImageName = (args: {\n  extension: string\n  height: number\n  originalName: string\n  sizeName: string\n  width: number\n}) => string\n\nexport type ImageSize = {\n  /**\n   * Admin UI options that control how this image size appears in list views.\n   *\n   * NOTE: In Payload v4, these options (`disableGroupBy`, `disableListColumn` and `disableListFilter`)\n   * should default to `true` so image size subfields are hidden from list columns\n   * and filters by default, reducing noise in the admin UI.\n   */\n  admin?: {\n    /**\n     * If set to true, this image size will not be available\n     * as a selectable groupBy option in the collection list view.\n     * @default false\n     */\n    disableGroupBy?: boolean\n    /**\n     * If set to true, this image size will not be available\n     * as a selectable column in the collection list view.\n     * @default false\n     */\n    disableListColumn?: boolean\n    /**\n     * If set to true, this image size will not be available\n     * as a filter option in the collection list view.\n     * @default false\n     */\n    disableListFilter?: boolean\n  }\n  /**\n   * @deprecated prefer position\n   */\n  crop?: string // comes from sharp package\n  formatOptions?: ImageUploadFormatOptions\n  /**\n   * Generate a custom name for the file of this image size.\n   */\n  generateImageName?: GenerateImageName\n  name: string\n  trimOptions?: ImageUploadTrimOptions\n  /**\n   * When an uploaded image is smaller than the defined image size, we have 3 options:\n   *\n   * `undefined | false | true`\n   *\n   * 1. `undefined` [default]: uploading images with smaller width AND height than the image size will return null\n   * 2. `false`: always enlarge images to the image size\n   * 3. `true`: if the image is smaller than the image size, return the original image\n   */\n  withoutEnlargement?: ResizeOptions['withoutEnlargement']\n} & Omit<ResizeOptions, 'withoutEnlargement'>\n\nexport type GetAdminThumbnail = (args: { doc: Record<string, unknown> }) => false | null | string\n\nexport type AllowList = Array<{\n  hostname: string\n  pathname?: string\n  port?: string\n  protocol?: 'http' | 'https'\n  search?: string\n}>\n\nexport type FileAllowList = Array<{\n  extensions: string[]\n  mimeType: string\n}>\n\ntype Admin = {\n  components?: {\n    /**\n     * The Controls component to extend the upload controls in the admin panel.\n     */\n    controls?: PayloadComponent[]\n  }\n}\n\nexport type UploadConfig = {\n  /**\n   * The adapter name to use for uploads. Used for storage adapter telemetry.\n   * @default undefined\n   */\n  adapter?: string\n  /**\n   * The admin configuration for the upload field.\n   */\n  admin?: Admin\n  /**\n   * Represents an admin thumbnail, which can be either a React component or a string.\n   * - If a string, it should be one of the image size names.\n   * - A function that generates a fully qualified URL for the thumbnail, receives the doc as the only argument.\n   **/\n  adminThumbnail?: GetAdminThumbnail | string\n  /**\n   * Allow restricted file types known to be problematic.\n   * - If set to `true`, it will allow all file types.\n   * - If set to `false`, it will not allow file types and extensions known to be problematic.\n   * - This setting is overriden by the `mimeTypes` option.\n   * @default false\n   */\n  allowRestrictedFileTypes?: boolean\n  /**\n   * Enables bulk upload of files from the list view.\n   * @default true\n   */\n  bulkUpload?: boolean\n  /**\n   * Appends a cache tag to the image URL when fetching the thumbnail in the admin panel. It may be desirable to disable this when hosting via CDNs with strict parameters.\n   *\n   * @default true\n   */\n  cacheTags?: boolean\n  /**\n   * Sharp constructor options to be passed to the uploaded file.\n   * @link https://sharp.pixelplumbing.com/api-constructor/#sharp\n   */\n  constructorOptions?: SharpOptions\n  /**\n   * Enables cropping of images.\n   * @default true\n   */\n  crop?: boolean\n  /**\n   * Disable the ability to save files to disk.\n   * @default false\n   */\n  disableLocalStorage?: boolean\n  /**\n   * Enable displaying preview of the uploaded file in Upload fields related to this Collection.\n   * Can be locally overridden by `displayPreview` option in Upload field.\n   * @default false\n   */\n  displayPreview?: boolean\n  /**\n   *\n   * Accepts existing headers and returns the headers after filtering or modifying.\n   * If using this option, you should handle the removal of any sensitive cookies\n   * (like payload-prefixed cookies) to prevent leaking session information to external\n   * services. By default, Payload automatically filters out payload-prefixed cookies\n   * when this option is NOT defined.\n   *\n   * Useful for adding custom headers to fetch from external providers.\n   * @default undefined\n   */\n  externalFileHeaderFilter?: (headers: Record<string, string>) => Record<string, string>\n  /**\n   * Field slugs to use for a compound index instead of the default filename index.\n   */\n  filenameCompoundIndex?: string[]\n  /**\n   * Require files to be uploaded when creating a document.\n   * @default true\n   */\n  filesRequiredOnCreate?: boolean\n  /**\n   * Enables focal point positioning for image manipulation.\n   * @default true\n   */\n  focalPoint?: boolean\n  /**\n   * Format options for the uploaded file. Formatting image sizes needs to be done within each formatOptions individually.\n   */\n  formatOptions?: ImageUploadFormatOptions\n  /**\n   * Custom handlers to run when a file is fetched.\n   *\n   * - If a handler returns a Response, the response will be sent to the client and no further handlers will be run.\n   * - If a handler returns null, the next handler will be run.\n   * - If no handlers return a response the file will be returned by default.\n   *\n   * @link https://sharp.pixelplumbing.com/api-output/#toformat\n   * @default undefined\n   */\n  handlers?: ((\n    req: PayloadRequest,\n    args: {\n      doc: TypeWithID\n      headers?: Headers\n      params: {\n        clientUploadContext?: unknown\n        collection: string\n        filename: string\n        prefix?: string\n      }\n    },\n  ) => Promise<Response> | Promise<void> | Response | void)[]\n  /**\n   * Set to `true` to prevent the admin UI from showing file inputs during document creation, useful for programmatic file generation.\n   */\n  hideFileInputOnCreate?: boolean\n  /**\n   * Set to `true` to prevent the admin UI having a way to remove an existing file while editing.\n   */\n  hideRemoveFile?: boolean\n  imageSizes?: ImageSize[]\n  /**\n   * Restrict mimeTypes in the file picker. Array of valid mime types or mimetype wildcards\n   * @example ['image/*', 'application/pdf']\n   * @default undefined\n   */\n  mimeTypes?: string[]\n  /**\n   * Ability to modify the response headers fetching a file.\n   * @default undefined\n   */\n  modifyResponseHeaders?: ({ headers }: { headers: Headers }) => Headers | void\n  /**\n   * Controls the behavior of pasting/uploading files from URLs.\n   * If set to `false`, fetching from remote URLs is disabled.\n   * If an `allowList` is provided, server-side fetching will be enabled for specified URLs.\n   *\n   * @default true (client-side fetching enabled)\n   */\n  pasteURL?:\n    | {\n        allowList: AllowList\n      }\n    | false\n  /**\n   * Sharp resize options for the original image.\n   * @link https://sharp.pixelplumbing.com/api-resize#resize\n   * @default undefined\n   */\n  resizeOptions?: ResizeOptions\n  /**\n   *  Skip safe fetch when using server-side fetching for external files from these URLs.\n   *  @default false\n   */\n  skipSafeFetch?: AllowList | boolean\n  /**\n   * The directory to serve static files from. Defaults to collection slug.\n   * @default undefined\n   */\n  staticDir?: string\n  trimOptions?: ImageUploadTrimOptions\n  /**\n   * Optionally append metadata to the image during processing.\n   *\n   * Can be a boolean or a function.\n   *\n   * If true, metadata will be appended to the image.\n   * If false, no metadata will be appended.\n   * If a function, it will receive an object containing the metadata and should return a boolean indicating whether to append the metadata.\n   * @default false\n   */\n  withMetadata?: WithMetadata\n}\nexport type checkFileRestrictionsParams = {\n  collection: CollectionConfig\n  file: File\n  req: PayloadRequest\n}\n\nexport type SanitizedUploadConfig = {\n  staticDir: UploadConfig['staticDir']\n} & UploadConfig\n\nexport type File = {\n  /**\n   * The buffer of the file.\n   */\n  data: Buffer\n  /**\n   * The mimetype of the file.\n   */\n  mimetype: string\n  /**\n   * The name of the file.\n   */\n  name: string\n  /**\n   * The size of the file in bytes.\n   */\n  size: number\n  /**\n   * Path to the temp file on disk when useTempFiles is enabled. In this case file.data will be an empty buffer.\n   */\n  tempFilePath?: string\n}\n\nexport type FileToSave = {\n  /**\n   * The buffer of the file.\n   */\n  buffer: Buffer\n  /**\n   * The path to save the file.\n   */\n  path: string\n}\n\ntype Crop = {\n  height: number\n  unit: '%' | 'px'\n  width: number\n  x: number\n  y: number\n}\n\nexport type FocalPoint = {\n  x: number\n  y: number\n}\n\nexport type UploadEdits = {\n  crop?: Crop\n  focalPoint?: FocalPoint\n  heightInPixels?: number\n  widthInPixels?: number\n}\n"],"names":[],"mappings":"AAqXA,WAKC"}