From f85539960cc073bbf6de4fe7fff8b0a018be412d Mon Sep 17 00:00:00 2001 From: Sasha <64744993+r1tsuu@users.noreply.github.com> Date: Tue, 5 Nov 2024 19:29:51 +0200 Subject: [PATCH] fix: type augmentation of `RequestContext` --- packages/payload/src/admin/RichText.ts | 3 ++- packages/payload/src/collections/config/types.ts | 2 +- .../payload/src/collections/operations/local/count.ts | 4 ++-- .../src/collections/operations/local/create.ts | 3 +-- .../src/collections/operations/local/delete.ts | 3 +-- .../src/collections/operations/local/duplicate.ts | 5 ++--- .../payload/src/collections/operations/local/find.ts | 9 +++++++-- .../src/collections/operations/local/findByID.ts | 10 ++++++++-- .../collections/operations/local/findVersionByID.ts | 4 ++-- .../src/collections/operations/local/findVersions.ts | 11 ++--------- .../collections/operations/local/restoreVersion.ts | 4 ++-- .../src/collections/operations/local/update.ts | 3 +-- packages/payload/src/fields/config/types.ts | 3 ++- .../payload/src/fields/hooks/afterChange/index.ts | 3 ++- .../payload/src/fields/hooks/afterChange/promise.ts | 3 ++- .../src/fields/hooks/afterChange/traverseFields.ts | 3 ++- packages/payload/src/fields/hooks/afterRead/index.ts | 8 ++------ .../payload/src/fields/hooks/afterRead/promise.ts | 9 ++------- .../src/fields/hooks/afterRead/traverseFields.ts | 9 ++------- .../payload/src/fields/hooks/beforeChange/index.ts | 3 ++- .../payload/src/fields/hooks/beforeChange/promise.ts | 3 ++- .../src/fields/hooks/beforeChange/traverseFields.ts | 3 ++- .../payload/src/fields/hooks/beforeDuplicate/index.ts | 3 ++- .../src/fields/hooks/beforeDuplicate/promise.ts | 3 ++- .../fields/hooks/beforeDuplicate/traverseFields.ts | 3 ++- .../payload/src/fields/hooks/beforeValidate/index.ts | 3 ++- .../src/fields/hooks/beforeValidate/promise.ts | 3 ++- .../src/fields/hooks/beforeValidate/traverseFields.ts | 3 ++- packages/payload/src/globals/config/types.ts | 4 ++-- packages/payload/src/types/index.ts | 5 +---- test/_community/int.spec.ts | 1 + test/_community/types.d.ts | 9 +++++++++ 32 files changed, 76 insertions(+), 69 deletions(-) create mode 100644 test/_community/types.d.ts diff --git a/packages/payload/src/admin/RichText.ts b/packages/payload/src/admin/RichText.ts index f3f7ae0fd8f..79b276218ae 100644 --- a/packages/payload/src/admin/RichText.ts +++ b/packages/payload/src/admin/RichText.ts @@ -12,7 +12,8 @@ import type { Validate, } from '../fields/config/types.js' import type { SanitizedGlobalConfig } from '../globals/config/types.js' -import type { JsonObject, Payload, PayloadRequest, RequestContext } from '../types/index.js' +import type { RequestContext } from '../index.js' +import type { JsonObject, Payload, PayloadRequest } from '../types/index.js' import type { RichTextFieldClientProps } from './fields/RichText.js' import type { CreateMappedComponent } from './types.js' diff --git a/packages/payload/src/collections/config/types.ts b/packages/payload/src/collections/config/types.ts index 4243b540803..64e53bb99b9 100644 --- a/packages/payload/src/collections/config/types.ts +++ b/packages/payload/src/collections/config/types.ts @@ -35,13 +35,13 @@ import type { Field, JoinField, RelationshipField, UploadField } from '../../fie import type { CollectionSlug, JsonObject, + RequestContext, TypedAuthOperations, TypedCollection, TypedCollectionSelect, } from '../../index.js' import type { PayloadRequest, - RequestContext, SelectType, Sort, TransformCollectionWithSelect, diff --git a/packages/payload/src/collections/operations/local/count.ts b/packages/payload/src/collections/operations/local/count.ts index bb7e1323426..df27550de72 100644 --- a/packages/payload/src/collections/operations/local/count.ts +++ b/packages/payload/src/collections/operations/local/count.ts @@ -1,5 +1,5 @@ -import type { CollectionSlug, Payload, TypedLocale } from '../../../index.js' -import type { Document, PayloadRequest, RequestContext, Where } from '../../../types/index.js' +import type { CollectionSlug, Payload, RequestContext, TypedLocale } from '../../../index.js' +import type { Document, PayloadRequest, Where } from '../../../types/index.js' import { APIError } from '../../../errors/index.js' import { createLocalReq } from '../../../utilities/createLocalReq.js' diff --git a/packages/payload/src/collections/operations/local/create.ts b/packages/payload/src/collections/operations/local/create.ts index 978c08e265c..9e14fd97a40 100644 --- a/packages/payload/src/collections/operations/local/create.ts +++ b/packages/payload/src/collections/operations/local/create.ts @@ -1,8 +1,7 @@ -import type { CollectionSlug, Payload, TypedLocale } from '../../../index.js' +import type { CollectionSlug, Payload, RequestContext, TypedLocale } from '../../../index.js' import type { Document, PayloadRequest, - RequestContext, SelectType, TransformCollectionWithSelect, } from '../../../types/index.js' diff --git a/packages/payload/src/collections/operations/local/delete.ts b/packages/payload/src/collections/operations/local/delete.ts index c57278cb27d..c82a75e5b1c 100644 --- a/packages/payload/src/collections/operations/local/delete.ts +++ b/packages/payload/src/collections/operations/local/delete.ts @@ -1,8 +1,7 @@ -import type { CollectionSlug, Payload, TypedLocale } from '../../../index.js' +import type { CollectionSlug, Payload, RequestContext, TypedLocale } from '../../../index.js' import type { Document, PayloadRequest, - RequestContext, SelectType, TransformCollectionWithSelect, Where, diff --git a/packages/payload/src/collections/operations/local/duplicate.ts b/packages/payload/src/collections/operations/local/duplicate.ts index c79381b08f4..93266663f33 100644 --- a/packages/payload/src/collections/operations/local/duplicate.ts +++ b/packages/payload/src/collections/operations/local/duplicate.ts @@ -1,13 +1,12 @@ import type { CollectionSlug, TypedLocale } from '../../..//index.js' -import type { Payload } from '../../../index.js' +import type { Payload, RequestContext } from '../../../index.js' import type { Document, PayloadRequest, - RequestContext, SelectType, TransformCollectionWithSelect, } from '../../../types/index.js' -import type { DataFromCollectionSlug, SelectFromCollectionSlug } from '../../config/types.js' +import type { SelectFromCollectionSlug } from '../../config/types.js' import { APIError } from '../../../errors/index.js' import { createLocalReq } from '../../../utilities/createLocalReq.js' diff --git a/packages/payload/src/collections/operations/local/find.ts b/packages/payload/src/collections/operations/local/find.ts index b6a75fba7fe..93cbdc1390c 100644 --- a/packages/payload/src/collections/operations/local/find.ts +++ b/packages/payload/src/collections/operations/local/find.ts @@ -1,9 +1,14 @@ import type { PaginatedDocs } from '../../../database/types.js' -import type { CollectionSlug, JoinQuery, Payload, TypedLocale } from '../../../index.js' +import type { + CollectionSlug, + JoinQuery, + Payload, + RequestContext, + TypedLocale, +} from '../../../index.js' import type { Document, PayloadRequest, - RequestContext, SelectType, Sort, TransformCollectionWithSelect, diff --git a/packages/payload/src/collections/operations/local/findByID.ts b/packages/payload/src/collections/operations/local/findByID.ts index 20978c08f7a..c50b1001acd 100644 --- a/packages/payload/src/collections/operations/local/findByID.ts +++ b/packages/payload/src/collections/operations/local/findByID.ts @@ -1,10 +1,16 @@ /* eslint-disable no-restricted-exports */ -import type { CollectionSlug, JoinQuery, Payload, SelectType, TypedLocale } from '../../../index.js' +import type { + CollectionSlug, + JoinQuery, + Payload, + RequestContext, + SelectType, + TypedLocale, +} from '../../../index.js' import type { ApplyDisableErrors, Document, PayloadRequest, - RequestContext, TransformCollectionWithSelect, } from '../../../types/index.js' import type { SelectFromCollectionSlug } from '../../config/types.js' diff --git a/packages/payload/src/collections/operations/local/findVersionByID.ts b/packages/payload/src/collections/operations/local/findVersionByID.ts index e672d2a578c..ee2928191d4 100644 --- a/packages/payload/src/collections/operations/local/findVersionByID.ts +++ b/packages/payload/src/collections/operations/local/findVersionByID.ts @@ -1,5 +1,5 @@ -import type { CollectionSlug, Payload, TypedLocale } from '../../../index.js' -import type { Document, PayloadRequest, RequestContext, SelectType } from '../../../types/index.js' +import type { CollectionSlug, Payload, RequestContext, TypedLocale } from '../../../index.js' +import type { Document, PayloadRequest, SelectType } from '../../../types/index.js' import type { TypeWithVersion } from '../../../versions/types.js' import type { DataFromCollectionSlug } from '../../config/types.js' diff --git a/packages/payload/src/collections/operations/local/findVersions.ts b/packages/payload/src/collections/operations/local/findVersions.ts index e6ab0048d5d..68bf2c68dd7 100644 --- a/packages/payload/src/collections/operations/local/findVersions.ts +++ b/packages/payload/src/collections/operations/local/findVersions.ts @@ -1,13 +1,6 @@ import type { PaginatedDocs } from '../../../database/types.js' -import type { CollectionSlug, Payload, TypedLocale } from '../../../index.js' -import type { - Document, - PayloadRequest, - RequestContext, - SelectType, - Sort, - Where, -} from '../../../types/index.js' +import type { CollectionSlug, Payload, RequestContext, TypedLocale } from '../../../index.js' +import type { Document, PayloadRequest, SelectType, Sort, Where } from '../../../types/index.js' import type { TypeWithVersion } from '../../../versions/types.js' import type { DataFromCollectionSlug } from '../../config/types.js' diff --git a/packages/payload/src/collections/operations/local/restoreVersion.ts b/packages/payload/src/collections/operations/local/restoreVersion.ts index 6e671dbf891..33e24d727fe 100644 --- a/packages/payload/src/collections/operations/local/restoreVersion.ts +++ b/packages/payload/src/collections/operations/local/restoreVersion.ts @@ -1,5 +1,5 @@ -import type { CollectionSlug, Payload, TypedLocale } from '../../../index.js' -import type { Document, PayloadRequest, RequestContext, SelectType } from '../../../types/index.js' +import type { CollectionSlug, Payload, RequestContext, TypedLocale } from '../../../index.js' +import type { Document, PayloadRequest, SelectType } from '../../../types/index.js' import type { DataFromCollectionSlug } from '../../config/types.js' import { APIError } from '../../../errors/index.js' diff --git a/packages/payload/src/collections/operations/local/update.ts b/packages/payload/src/collections/operations/local/update.ts index 2f13f33593d..218477e44fc 100644 --- a/packages/payload/src/collections/operations/local/update.ts +++ b/packages/payload/src/collections/operations/local/update.ts @@ -1,10 +1,9 @@ import type { DeepPartial } from 'ts-essentials' -import type { CollectionSlug, Payload, TypedLocale } from '../../../index.js' +import type { CollectionSlug, Payload, RequestContext, TypedLocale } from '../../../index.js' import type { Document, PayloadRequest, - RequestContext, SelectType, TransformCollectionWithSelect, Where, diff --git a/packages/payload/src/fields/config/types.ts b/packages/payload/src/fields/config/types.ts index f2fdee8a1fa..d7fc39db6a6 100644 --- a/packages/payload/src/fields/config/types.ts +++ b/packages/payload/src/fields/config/types.ts @@ -121,11 +121,12 @@ import type { JSONFieldValidation, PointFieldValidation, RadioFieldValidation, + RequestContext, Sort, TextareaFieldValidation, } from '../../index.js' import type { DocumentPreferences } from '../../preferences/types.js' -import type { Operation, PayloadRequest, RequestContext, Where } from '../../types/index.js' +import type { Operation, PayloadRequest, Where } from '../../types/index.js' import type { NumberFieldManyValidation, NumberFieldSingleValidation, diff --git a/packages/payload/src/fields/hooks/afterChange/index.ts b/packages/payload/src/fields/hooks/afterChange/index.ts index afb478dfe6c..b420cc61676 100644 --- a/packages/payload/src/fields/hooks/afterChange/index.ts +++ b/packages/payload/src/fields/hooks/afterChange/index.ts @@ -1,6 +1,7 @@ import type { SanitizedCollectionConfig } from '../../../collections/config/types.js' import type { SanitizedGlobalConfig } from '../../../globals/config/types.js' -import type { JsonObject, PayloadRequest, RequestContext } from '../../../types/index.js' +import type { RequestContext } from '../../../index.js' +import type { JsonObject, PayloadRequest } from '../../../types/index.js' import { deepCopyObjectSimple } from '../../../utilities/deepCopyObject.js' import { traverseFields } from './traverseFields.js' diff --git a/packages/payload/src/fields/hooks/afterChange/promise.ts b/packages/payload/src/fields/hooks/afterChange/promise.ts index 66c6d3c324a..c2252a4a041 100644 --- a/packages/payload/src/fields/hooks/afterChange/promise.ts +++ b/packages/payload/src/fields/hooks/afterChange/promise.ts @@ -1,7 +1,8 @@ import type { RichTextAdapter } from '../../../admin/RichText.js' import type { SanitizedCollectionConfig } from '../../../collections/config/types.js' import type { SanitizedGlobalConfig } from '../../../globals/config/types.js' -import type { JsonObject, PayloadRequest, RequestContext } from '../../../types/index.js' +import type { RequestContext } from '../../../index.js' +import type { JsonObject, PayloadRequest } from '../../../types/index.js' import type { Field, TabAsField } from '../../config/types.js' import { MissingEditorProp } from '../../../errors/index.js' diff --git a/packages/payload/src/fields/hooks/afterChange/traverseFields.ts b/packages/payload/src/fields/hooks/afterChange/traverseFields.ts index 793f2ae4289..cfd6133656f 100644 --- a/packages/payload/src/fields/hooks/afterChange/traverseFields.ts +++ b/packages/payload/src/fields/hooks/afterChange/traverseFields.ts @@ -1,6 +1,7 @@ import type { SanitizedCollectionConfig } from '../../../collections/config/types.js' import type { SanitizedGlobalConfig } from '../../../globals/config/types.js' -import type { JsonObject, PayloadRequest, RequestContext } from '../../../types/index.js' +import type { RequestContext } from '../../../index.js' +import type { JsonObject, PayloadRequest } from '../../../types/index.js' import type { Field, TabAsField } from '../../config/types.js' import { promise } from './promise.js' diff --git a/packages/payload/src/fields/hooks/afterRead/index.ts b/packages/payload/src/fields/hooks/afterRead/index.ts index 38f226d0421..cc02f1e9758 100644 --- a/packages/payload/src/fields/hooks/afterRead/index.ts +++ b/packages/payload/src/fields/hooks/afterRead/index.ts @@ -1,11 +1,7 @@ import type { SanitizedCollectionConfig } from '../../../collections/config/types.js' import type { SanitizedGlobalConfig } from '../../../globals/config/types.js' -import type { - JsonObject, - PayloadRequest, - RequestContext, - SelectType, -} from '../../../types/index.js' +import type { RequestContext } from '../../../index.js' +import type { JsonObject, PayloadRequest, SelectType } from '../../../types/index.js' import { deepCopyObjectSimple } from '../../../utilities/deepCopyObject.js' import { getSelectMode } from '../../../utilities/getSelectMode.js' diff --git a/packages/payload/src/fields/hooks/afterRead/promise.ts b/packages/payload/src/fields/hooks/afterRead/promise.ts index e1958ef3dfb..604784ffe7d 100644 --- a/packages/payload/src/fields/hooks/afterRead/promise.ts +++ b/packages/payload/src/fields/hooks/afterRead/promise.ts @@ -1,13 +1,8 @@ import type { RichTextAdapter } from '../../../admin/RichText.js' import type { SanitizedCollectionConfig } from '../../../collections/config/types.js' import type { SanitizedGlobalConfig } from '../../../globals/config/types.js' -import type { - JsonObject, - PayloadRequest, - RequestContext, - SelectMode, - SelectType, -} from '../../../types/index.js' +import type { RequestContext } from '../../../index.js' +import type { JsonObject, PayloadRequest, SelectMode, SelectType } from '../../../types/index.js' import type { Field, TabAsField } from '../../config/types.js' import { MissingEditorProp } from '../../../errors/index.js' diff --git a/packages/payload/src/fields/hooks/afterRead/traverseFields.ts b/packages/payload/src/fields/hooks/afterRead/traverseFields.ts index 2293299099c..e89d467eb32 100644 --- a/packages/payload/src/fields/hooks/afterRead/traverseFields.ts +++ b/packages/payload/src/fields/hooks/afterRead/traverseFields.ts @@ -1,12 +1,7 @@ import type { SanitizedCollectionConfig } from '../../../collections/config/types.js' import type { SanitizedGlobalConfig } from '../../../globals/config/types.js' -import type { - JsonObject, - PayloadRequest, - RequestContext, - SelectMode, - SelectType, -} from '../../../types/index.js' +import type { RequestContext } from '../../../index.js' +import type { JsonObject, PayloadRequest, SelectMode, SelectType } from '../../../types/index.js' import type { Field, TabAsField } from '../../config/types.js' import { promise } from './promise.js' diff --git a/packages/payload/src/fields/hooks/beforeChange/index.ts b/packages/payload/src/fields/hooks/beforeChange/index.ts index dcd15d63975..d8f89f8d28a 100644 --- a/packages/payload/src/fields/hooks/beforeChange/index.ts +++ b/packages/payload/src/fields/hooks/beforeChange/index.ts @@ -1,6 +1,7 @@ import type { SanitizedCollectionConfig } from '../../../collections/config/types.js' import type { SanitizedGlobalConfig } from '../../../globals/config/types.js' -import type { JsonObject, Operation, PayloadRequest, RequestContext } from '../../../types/index.js' +import type { RequestContext } from '../../../index.js' +import type { JsonObject, Operation, PayloadRequest } from '../../../types/index.js' import { ValidationError } from '../../../errors/index.js' import { deepCopyObjectSimple } from '../../../utilities/deepCopyObject.js' diff --git a/packages/payload/src/fields/hooks/beforeChange/promise.ts b/packages/payload/src/fields/hooks/beforeChange/promise.ts index ce52e45b36c..0cef7a1dbff 100644 --- a/packages/payload/src/fields/hooks/beforeChange/promise.ts +++ b/packages/payload/src/fields/hooks/beforeChange/promise.ts @@ -1,7 +1,8 @@ import type { RichTextAdapter } from '../../../admin/RichText.js' import type { SanitizedCollectionConfig } from '../../../collections/config/types.js' import type { SanitizedGlobalConfig } from '../../../globals/config/types.js' -import type { JsonObject, Operation, PayloadRequest, RequestContext } from '../../../types/index.js' +import type { RequestContext } from '../../../index.js' +import type { JsonObject, Operation, PayloadRequest } from '../../../types/index.js' import type { Field, FieldHookArgs, TabAsField, ValidateOptions } from '../../config/types.js' import { MissingEditorProp } from '../../../errors/index.js' diff --git a/packages/payload/src/fields/hooks/beforeChange/traverseFields.ts b/packages/payload/src/fields/hooks/beforeChange/traverseFields.ts index 24b193cd679..95f53b55813 100644 --- a/packages/payload/src/fields/hooks/beforeChange/traverseFields.ts +++ b/packages/payload/src/fields/hooks/beforeChange/traverseFields.ts @@ -1,6 +1,7 @@ import type { SanitizedCollectionConfig } from '../../../collections/config/types.js' import type { SanitizedGlobalConfig } from '../../../globals/config/types.js' -import type { JsonObject, Operation, PayloadRequest, RequestContext } from '../../../types/index.js' +import type { RequestContext } from '../../../index.js' +import type { JsonObject, Operation, PayloadRequest } from '../../../types/index.js' import type { Field, TabAsField } from '../../config/types.js' import { promise } from './promise.js' diff --git a/packages/payload/src/fields/hooks/beforeDuplicate/index.ts b/packages/payload/src/fields/hooks/beforeDuplicate/index.ts index 886885de0f2..a85bcac0d62 100644 --- a/packages/payload/src/fields/hooks/beforeDuplicate/index.ts +++ b/packages/payload/src/fields/hooks/beforeDuplicate/index.ts @@ -1,5 +1,6 @@ import type { SanitizedCollectionConfig } from '../../../collections/config/types.js' -import type { JsonObject, PayloadRequest, RequestContext } from '../../../types/index.js' +import type { RequestContext } from '../../../index.js' +import type { JsonObject, PayloadRequest } from '../../../types/index.js' import { deepCopyObjectSimple } from '../../../utilities/deepCopyObject.js' import { traverseFields } from './traverseFields.js' diff --git a/packages/payload/src/fields/hooks/beforeDuplicate/promise.ts b/packages/payload/src/fields/hooks/beforeDuplicate/promise.ts index 9fcd3b23f73..b9de60e0f90 100644 --- a/packages/payload/src/fields/hooks/beforeDuplicate/promise.ts +++ b/packages/payload/src/fields/hooks/beforeDuplicate/promise.ts @@ -1,5 +1,6 @@ import type { SanitizedCollectionConfig } from '../../../collections/config/types.js' -import type { JsonObject, PayloadRequest, RequestContext } from '../../../types/index.js' +import type { RequestContext } from '../../../index.js' +import type { JsonObject, PayloadRequest } from '../../../types/index.js' import type { Field, FieldHookArgs, TabAsField } from '../../config/types.js' import { fieldAffectsData, tabHasName } from '../../config/types.js' diff --git a/packages/payload/src/fields/hooks/beforeDuplicate/traverseFields.ts b/packages/payload/src/fields/hooks/beforeDuplicate/traverseFields.ts index 4b7f1f211fd..dd300dd0b74 100644 --- a/packages/payload/src/fields/hooks/beforeDuplicate/traverseFields.ts +++ b/packages/payload/src/fields/hooks/beforeDuplicate/traverseFields.ts @@ -1,5 +1,6 @@ import type { SanitizedCollectionConfig } from '../../../collections/config/types.js' -import type { JsonObject, PayloadRequest, RequestContext } from '../../../types/index.js' +import type { RequestContext } from '../../../index.js' +import type { JsonObject, PayloadRequest } from '../../../types/index.js' import type { Field, TabAsField } from '../../config/types.js' import { promise } from './promise.js' diff --git a/packages/payload/src/fields/hooks/beforeValidate/index.ts b/packages/payload/src/fields/hooks/beforeValidate/index.ts index fd412205e4e..d40d63d1225 100644 --- a/packages/payload/src/fields/hooks/beforeValidate/index.ts +++ b/packages/payload/src/fields/hooks/beforeValidate/index.ts @@ -1,6 +1,7 @@ import type { SanitizedCollectionConfig } from '../../../collections/config/types.js' import type { SanitizedGlobalConfig } from '../../../globals/config/types.js' -import type { JsonObject, PayloadRequest, RequestContext } from '../../../types/index.js' +import type { RequestContext } from '../../../index.js' +import type { JsonObject, PayloadRequest } from '../../../types/index.js' import { deepCopyObjectSimple } from '../../../utilities/deepCopyObject.js' import { traverseFields } from './traverseFields.js' diff --git a/packages/payload/src/fields/hooks/beforeValidate/promise.ts b/packages/payload/src/fields/hooks/beforeValidate/promise.ts index 3b9cd0267d0..17ed7755908 100644 --- a/packages/payload/src/fields/hooks/beforeValidate/promise.ts +++ b/packages/payload/src/fields/hooks/beforeValidate/promise.ts @@ -1,7 +1,8 @@ import type { RichTextAdapter } from '../../../admin/RichText.js' import type { SanitizedCollectionConfig } from '../../../collections/config/types.js' import type { SanitizedGlobalConfig } from '../../../globals/config/types.js' -import type { JsonObject, JsonValue, PayloadRequest, RequestContext } from '../../../types/index.js' +import type { RequestContext } from '../../../index.js' +import type { JsonObject, JsonValue, PayloadRequest } from '../../../types/index.js' import type { Field, TabAsField } from '../../config/types.js' import { MissingEditorProp } from '../../../errors/index.js' diff --git a/packages/payload/src/fields/hooks/beforeValidate/traverseFields.ts b/packages/payload/src/fields/hooks/beforeValidate/traverseFields.ts index 3b2f9d226da..63150a015d7 100644 --- a/packages/payload/src/fields/hooks/beforeValidate/traverseFields.ts +++ b/packages/payload/src/fields/hooks/beforeValidate/traverseFields.ts @@ -1,6 +1,7 @@ import type { SanitizedCollectionConfig } from '../../../collections/config/types.js' import type { SanitizedGlobalConfig } from '../../../globals/config/types.js' -import type { JsonObject, PayloadRequest, RequestContext } from '../../../types/index.js' +import type { RequestContext } from '../../../index.js' +import type { JsonObject, PayloadRequest } from '../../../types/index.js' import type { Field, TabAsField } from '../../config/types.js' import { promise } from './promise.js' diff --git a/packages/payload/src/globals/config/types.ts b/packages/payload/src/globals/config/types.ts index 3720d414cc7..47fe2bb31f7 100644 --- a/packages/payload/src/globals/config/types.ts +++ b/packages/payload/src/globals/config/types.ts @@ -19,8 +19,8 @@ import type { } from '../../config/types.js' import type { DBIdentifierName } from '../../database/types.js' import type { Field } from '../../fields/config/types.js' -import type { GlobalSlug, TypedGlobal, TypedGlobalSelect } from '../../index.js' -import type { PayloadRequest, RequestContext, Where } from '../../types/index.js' +import type { GlobalSlug, RequestContext, TypedGlobal, TypedGlobalSelect } from '../../index.js' +import type { PayloadRequest, Where } from '../../types/index.js' import type { IncomingGlobalVersions, SanitizedGlobalVersions } from '../../versions/types.js' export type DataFromGlobalSlug = TypedGlobal[TSlug] diff --git a/packages/payload/src/types/index.ts b/packages/payload/src/types/index.ts index e56da48fc48..278c826f81e 100644 --- a/packages/payload/src/types/index.ts +++ b/packages/payload/src/types/index.ts @@ -12,6 +12,7 @@ import type { CollectionSlug, DataFromGlobalSlug, GlobalSlug, + RequestContext, TypedLocale, TypedUser, } from '../index.js' @@ -94,10 +95,6 @@ export type PayloadRequest = CustomPayloadRequestProperties & PayloadRequestData & Required> -export interface RequestContext { - [key: string]: unknown -} - export type Operator = (typeof validOperators)[number] // Makes it so things like passing new Date() will error diff --git a/test/_community/int.spec.ts b/test/_community/int.spec.ts index 2e4fc730b41..ee66eb68d87 100644 --- a/test/_community/int.spec.ts +++ b/test/_community/int.spec.ts @@ -54,6 +54,7 @@ describe('_Community Tests', () => { data: { text: 'LOCAL API EXAMPLE', }, + context: {}, }) expect(newPost.text).toEqual('LOCAL API EXAMPLE') diff --git a/test/_community/types.d.ts b/test/_community/types.d.ts new file mode 100644 index 00000000000..8d5bd7d65c3 --- /dev/null +++ b/test/_community/types.d.ts @@ -0,0 +1,9 @@ +import type { RequestContext as OriginalRequestContext } from 'payload' + +declare module 'payload' { + // Create a new interface that merges your additional fields with the original one + export interface RequestContext extends OriginalRequestContext { + myObject?: string + // ... + } +}