import type { I18n, TFunction } from '@payloadcms/translations'; import type DataLoader from 'dataloader'; import type { OptionalKeys, RequiredKeys } from 'ts-essentials'; import type { URL } from 'url'; import type { DataFromCollectionSlug, QueryDraftDataFromCollectionSlug, TypeWithID, TypeWithTimestamps } from '../collections/config/types.js'; import type payload from '../index.js'; import type { CollectionSlug, DataFromGlobalSlug, GlobalSlug, Payload, RequestContext, TypedCollectionJoins, TypedCollectionSelect, TypedFallbackLocale, TypedLocale, TypedUser } from '../index.js'; import type { Operator } from './constants.js'; export type { Payload } from '../index.js'; export type CustomPayloadRequestProperties = { context: RequestContext; /** The locale that should be used for a field when it is not translated to the requested locale */ fallbackLocale?: TypedFallbackLocale; i18n: I18n; /** * The requested locale if specified * Only available for localized collections * * Suppressing warning below as it is a valid use case - won't be an issue if generated types exist */ locale?: 'all' | TypedLocale; /** * The payload object */ payload: typeof payload; /** * The context in which the request is being made */ payloadAPI: 'GraphQL' | 'local' | 'REST'; /** Optimized document loader */ payloadDataLoader: { /** * Wraps `payload.find` with a cache to deduplicate requests * @experimental This is may be replaced by a more robust cache strategy in future versions * By calling this method with the same arguments many times in one request, it will only be handled one time * const result = await req.payloadDataLoader.find({ * collection, * req, * where: findWhere, * }) */ find: Payload['find']; } & DataLoader; /** Resized versions of the image that was uploaded during this request */ payloadUploadSizes?: Record; /** Query params on the request */ query: Record; /** Any response headers that are required to be set when a response is sent */ responseHeaders?: Headers; /** The route parameters * @example * /:collection/:id -> /posts/123 * { collection: 'posts', id: '123' } */ routeParams?: Record; /** Translate function - duplicate of i18n.t */ t: TFunction; /** * Identifier for the database transaction for interactions in a single, all-or-nothing operation. * Can also be used to ensure consistency when multiple operations try to create a transaction concurrently on the same request. */ transactionID?: number | Promise | string; /** * Used to ensure consistency when multiple operations try to create a transaction concurrently on the same request * @deprecated This is not used anywhere, instead `transactionID` is used for the above. Will be removed in next major version. */ transactionIDPromise?: Promise; /** The signed-in user */ user: null | TypedUser; } & Pick; type PayloadRequestData = { /** * Data from the request body * * Within Payload operations, i.e. hooks, data will be there * BUT in custom endpoints it will not be, you will need to * use either: * 1. `const data = await req.json()` * * 2. import { addDataAndFileToRequest } from 'payload' * `await addDataAndFileToRequest(req)` * * You should not expect this object to be the document data. It is the request data. * */ data?: JsonObject; /** The file on the request, same rules apply as the `data` property */ file?: { /** * Context of the file when it was uploaded via client side. */ clientUploadContext?: unknown; data: Buffer; mimetype: string; name: string; size: number; tempFilePath?: string; }; }; export interface PayloadRequest extends CustomPayloadRequestProperties, Partial, PayloadRequestData { headers: Request['headers']; } export type { Operator }; export type JsonValue = JsonArray | JsonObject | unknown; export type JsonArray = Array; export interface JsonObject { [key: string]: any; } export type WhereField = { [key in Operator]?: JsonValue; }; export type Where = { [key: string]: Where[] | WhereField; and?: Where[]; or?: Where[]; }; export type Sort = Array | string; type SerializableValue = boolean | number | object | string; export type DefaultValue = ((args: { locale?: TypedLocale; req: PayloadRequest; user: PayloadRequest['user']; }) => SerializableValue) | SerializableValue; /** * Applies pagination for join fields for including collection relationships */ export type JoinQuery = TypedCollectionJoins[TSlug] extends Record ? false | Partial<{ [K in keyof TypedCollectionJoins[TSlug]]: { count?: boolean; limit?: number; page?: number; sort?: string; where?: Where; } | false; }> : never; export type Document = any; export type Operation = 'create' | 'delete' | 'read' | 'update'; export type VersionOperations = 'readVersions'; export type AuthOperations = 'unlock'; export type AllOperations = AuthOperations | Operation | VersionOperations; export declare function docHasTimestamps(doc: any): doc is TypeWithTimestamps; export type IfAny = 0 extends 1 & T ? Y : N; export type IsAny = IfAny; export type ReplaceAny = IsAny extends true ? DefaultType : T; export type SelectIncludeType = { [k: string]: SelectIncludeType | true; }; export type SelectExcludeType = { [k: string]: false | SelectExcludeType; }; export type SelectMode = 'exclude' | 'include'; export type SelectType = SelectExcludeType | SelectIncludeType; export type ApplyDisableErrors = false extends DisableErrors ? T : null | T; export type TransformDataWithSelect, Select extends SelectType> = Select extends never ? Data : string extends keyof Select ? Data : string extends keyof Omit ? Select extends SelectIncludeType ? { [K in Data extends TypeWithID ? 'id' | keyof Select : keyof Select]: K extends 'id' ? number | string : unknown; } : Data : Select extends SelectIncludeType ? { [K in keyof Data as K extends keyof Select ? Select[K] extends object | true ? K : never : K extends 'id' ? K : never]: Data[K]; } : { [K in keyof Data as K extends keyof Select ? Select[K] extends object | undefined ? K : never : K]: Data[K]; }; export type TransformCollectionWithSelect = TSelect extends SelectType ? TransformDataWithSelect, TSelect> : DataFromCollectionSlug; export type DraftTransformCollectionWithSelect = TSelect extends SelectType ? TransformDataWithSelect, TSelect> : QueryDraftDataFromCollectionSlug; export type TransformGlobalWithSelect = TSelect extends SelectType ? TransformDataWithSelect, TSelect> : DataFromGlobalSlug; export type PopulateType = Partial; export type ResolvedFilterOptions = { [collection: string]: Where; }; export type PickPreserveOptional = Partial>>> & Pick>>; export type MaybePromise = Promise | T; //# sourceMappingURL=index.d.ts.map