payload 3.74.0-internal.b78b222 → 3.74.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (116) hide show
  1. package/dist/admin/functions/index.d.ts +5 -12
  2. package/dist/admin/functions/index.d.ts.map +1 -1
  3. package/dist/admin/functions/index.js.map +1 -1
  4. package/dist/admin/types.d.ts +1 -1
  5. package/dist/admin/types.d.ts.map +1 -1
  6. package/dist/admin/types.js.map +1 -1
  7. package/dist/admin/views/dashboard.d.ts +3 -2
  8. package/dist/admin/views/dashboard.d.ts.map +1 -1
  9. package/dist/admin/views/dashboard.js.map +1 -1
  10. package/dist/auth/operations/forgotPassword.d.ts +3 -3
  11. package/dist/auth/operations/forgotPassword.d.ts.map +1 -1
  12. package/dist/auth/operations/forgotPassword.js.map +1 -1
  13. package/dist/auth/operations/local/forgotPassword.d.ts +4 -4
  14. package/dist/auth/operations/local/forgotPassword.d.ts.map +1 -1
  15. package/dist/auth/operations/local/forgotPassword.js.map +1 -1
  16. package/dist/auth/operations/local/login.d.ts +6 -4
  17. package/dist/auth/operations/local/login.d.ts.map +1 -1
  18. package/dist/auth/operations/local/login.js.map +1 -1
  19. package/dist/auth/operations/local/resetPassword.d.ts +4 -4
  20. package/dist/auth/operations/local/resetPassword.d.ts.map +1 -1
  21. package/dist/auth/operations/local/resetPassword.js.map +1 -1
  22. package/dist/auth/operations/local/unlock.d.ts +3 -3
  23. package/dist/auth/operations/local/unlock.d.ts.map +1 -1
  24. package/dist/auth/operations/local/unlock.js.map +1 -1
  25. package/dist/auth/operations/local/verifyEmail.d.ts +4 -4
  26. package/dist/auth/operations/local/verifyEmail.d.ts.map +1 -1
  27. package/dist/auth/operations/local/verifyEmail.js.map +1 -1
  28. package/dist/auth/operations/login.d.ts +10 -8
  29. package/dist/auth/operations/login.d.ts.map +1 -1
  30. package/dist/auth/operations/login.js.map +1 -1
  31. package/dist/auth/operations/registerFirstUser.d.ts +3 -3
  32. package/dist/auth/operations/registerFirstUser.d.ts.map +1 -1
  33. package/dist/auth/operations/registerFirstUser.js.map +1 -1
  34. package/dist/auth/operations/resetPassword.d.ts +2 -2
  35. package/dist/auth/operations/resetPassword.d.ts.map +1 -1
  36. package/dist/auth/operations/resetPassword.js.map +1 -1
  37. package/dist/auth/operations/unlock.d.ts +3 -3
  38. package/dist/auth/operations/unlock.d.ts.map +1 -1
  39. package/dist/auth/operations/unlock.js.map +1 -1
  40. package/dist/collections/config/types.d.ts +2 -2
  41. package/dist/collections/config/types.d.ts.map +1 -1
  42. package/dist/collections/config/types.js.map +1 -1
  43. package/dist/collections/operations/create.d.ts.map +1 -1
  44. package/dist/collections/operations/create.js +0 -9
  45. package/dist/collections/operations/create.js.map +1 -1
  46. package/dist/collections/operations/delete.d.ts.map +1 -1
  47. package/dist/collections/operations/delete.js +0 -9
  48. package/dist/collections/operations/delete.js.map +1 -1
  49. package/dist/collections/operations/deleteByID.d.ts.map +1 -1
  50. package/dist/collections/operations/deleteByID.js +0 -9
  51. package/dist/collections/operations/deleteByID.js.map +1 -1
  52. package/dist/collections/operations/find.d.ts.map +1 -1
  53. package/dist/collections/operations/find.js +0 -9
  54. package/dist/collections/operations/find.js.map +1 -1
  55. package/dist/collections/operations/findByID.d.ts.map +1 -1
  56. package/dist/collections/operations/findByID.js +0 -9
  57. package/dist/collections/operations/findByID.js.map +1 -1
  58. package/dist/collections/operations/local/count.d.ts.map +1 -1
  59. package/dist/collections/operations/local/count.js.map +1 -1
  60. package/dist/collections/operations/local/countVersions.d.ts.map +1 -1
  61. package/dist/collections/operations/local/countVersions.js.map +1 -1
  62. package/dist/collections/operations/local/create.d.ts.map +1 -1
  63. package/dist/collections/operations/local/create.js.map +1 -1
  64. package/dist/collections/operations/local/delete.d.ts.map +1 -1
  65. package/dist/collections/operations/local/delete.js.map +1 -1
  66. package/dist/collections/operations/local/duplicate.d.ts.map +1 -1
  67. package/dist/collections/operations/local/duplicate.js.map +1 -1
  68. package/dist/collections/operations/local/find.d.ts.map +1 -1
  69. package/dist/collections/operations/local/find.js.map +1 -1
  70. package/dist/collections/operations/local/findByID.d.ts.map +1 -1
  71. package/dist/collections/operations/local/findByID.js.map +1 -1
  72. package/dist/collections/operations/local/findDistinct.d.ts.map +1 -1
  73. package/dist/collections/operations/local/findDistinct.js.map +1 -1
  74. package/dist/collections/operations/local/findVersionByID.d.ts.map +1 -1
  75. package/dist/collections/operations/local/findVersionByID.js.map +1 -1
  76. package/dist/collections/operations/local/findVersions.d.ts.map +1 -1
  77. package/dist/collections/operations/local/findVersions.js.map +1 -1
  78. package/dist/collections/operations/local/restoreVersion.d.ts.map +1 -1
  79. package/dist/collections/operations/local/restoreVersion.js.map +1 -1
  80. package/dist/collections/operations/local/update.d.ts.map +1 -1
  81. package/dist/collections/operations/local/update.js.map +1 -1
  82. package/dist/collections/operations/update.d.ts.map +1 -1
  83. package/dist/collections/operations/update.js +1 -10
  84. package/dist/collections/operations/update.js.map +1 -1
  85. package/dist/collections/operations/updateByID.d.ts.map +1 -1
  86. package/dist/collections/operations/updateByID.js +0 -9
  87. package/dist/collections/operations/updateByID.js.map +1 -1
  88. package/dist/globals/operations/local/countVersions.d.ts.map +1 -1
  89. package/dist/globals/operations/local/countVersions.js.map +1 -1
  90. package/dist/globals/operations/local/findOne.d.ts.map +1 -1
  91. package/dist/globals/operations/local/findOne.js.map +1 -1
  92. package/dist/globals/operations/local/findVersionByID.d.ts.map +1 -1
  93. package/dist/globals/operations/local/findVersionByID.js.map +1 -1
  94. package/dist/globals/operations/local/findVersions.d.ts.map +1 -1
  95. package/dist/globals/operations/local/findVersions.js.map +1 -1
  96. package/dist/globals/operations/local/restoreVersion.d.ts.map +1 -1
  97. package/dist/globals/operations/local/restoreVersion.js.map +1 -1
  98. package/dist/globals/operations/local/update.d.ts.map +1 -1
  99. package/dist/globals/operations/local/update.js.map +1 -1
  100. package/dist/index.bundled.d.ts +41 -46
  101. package/dist/index.d.ts +6 -9
  102. package/dist/index.d.ts.map +1 -1
  103. package/dist/index.js +1 -1
  104. package/dist/index.js.map +1 -1
  105. package/dist/preferences/config.d.ts.map +1 -1
  106. package/dist/preferences/config.js +13 -2
  107. package/dist/preferences/config.js.map +1 -1
  108. package/dist/utilities/addSelectGenericsToGeneratedTypes.spec.js +6 -4
  109. package/dist/utilities/addSelectGenericsToGeneratedTypes.spec.js.map +1 -1
  110. package/dist/utilities/configToJSONSchema.d.ts.map +1 -1
  111. package/dist/utilities/configToJSONSchema.js +21 -20
  112. package/dist/utilities/configToJSONSchema.js.map +1 -1
  113. package/dist/utilities/createLocalReq.d.ts.map +1 -1
  114. package/dist/utilities/createLocalReq.js +0 -8
  115. package/dist/utilities/createLocalReq.js.map +1 -1
  116. package/package.json +2 -2
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/collections/config/types.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport type { GraphQLInputObjectType, GraphQLNonNull, GraphQLObjectType } from 'graphql'\nimport type { DeepRequired, IsAny, MarkOptional } from 'ts-essentials'\n\nimport type {\n CustomStatus,\n CustomUpload,\n PublishButtonClientProps,\n PublishButtonServerProps,\n UnpublishButtonClientProps,\n UnpublishButtonServerProps,\n ViewTypes,\n} from '../../admin/types.js'\nimport type { Arguments as MeArguments } from '../../auth/operations/me.js'\nimport type {\n Arguments as RefreshArguments,\n Result as RefreshResult,\n} from '../../auth/operations/refresh.js'\nimport type { Auth, ClientUser, IncomingAuthType } from '../../auth/types.js'\nimport type {\n Access,\n AfterErrorHookArgs,\n AfterErrorResult,\n CustomComponent,\n EditConfig,\n Endpoint,\n EntityDescription,\n EntityDescriptionComponent,\n GeneratePreviewURL,\n LabelFunction,\n LivePreviewConfig,\n MetaConfig,\n PayloadComponent,\n StaticLabel,\n} from '../../config/types.js'\nimport type { DBIdentifierName } from '../../database/types.js'\nimport type {\n Field,\n FlattenedField,\n JoinField,\n RelationshipField,\n UploadField,\n} from '../../fields/config/types.js'\nimport type { CollectionFoldersConfiguration } from '../../folders/types.js'\nimport type {\n CollectionAdminCustom,\n CollectionCustom,\n CollectionSlug,\n GeneratedTypes,\n JsonObject,\n RequestContext,\n TypedAuthOperations,\n TypedCollection,\n TypedCollectionSelect,\n TypedLocale,\n} from '../../index.js'\nimport type {\n PayloadRequest,\n SelectIncludeType,\n SelectType,\n Sort,\n TransformCollectionWithSelect,\n Where,\n} from '../../types/index.js'\nimport type { SanitizedUploadConfig, UploadConfig } from '../../uploads/types.js'\nimport type {\n IncomingCollectionVersions,\n SanitizedCollectionVersions,\n} from '../../versions/types.js'\nimport type {\n AfterOperationArg,\n BeforeOperationArg,\n OperationMap,\n} from '../operations/utilities/types.js'\n\nexport type DataFromCollectionSlug<TSlug extends CollectionSlug> = TypedCollection[TSlug]\n\nexport type SelectFromCollectionSlug<TSlug extends CollectionSlug> = TypedCollectionSelect[TSlug]\n\n/**\n * Collection slugs that do not have drafts enabled.\n * Detects collections without drafts by checking for the absence of the `_status` field.\n */\nexport type CollectionsWithoutDrafts = {\n [TSlug in CollectionSlug]: DataFromCollectionSlug<TSlug> extends { _status?: any } ? never : TSlug\n}[CollectionSlug]\n\n/**\n * Conditionally allows or forbids the `draft` property based on collection configuration.\n * When `strictDraftTypes` is enabled, the `draft` property is forbidden on collections without drafts.\n */\nexport type DraftFlagFromCollectionSlug<TSlug extends CollectionSlug> = GeneratedTypes extends {\n strictDraftTypes: true\n}\n ? TSlug extends CollectionsWithoutDrafts\n ? {\n /**\n * The `draft` property is not allowed because this collection does not have `versions.drafts` enabled.\n */\n draft?: never\n }\n : {\n /**\n * Whether the document(s) should be queried from the versions table/collection or not. [More](https://payloadcms.com/docs/versions/drafts#draft-api)\n */\n draft?: boolean\n }\n : {\n /**\n * Whether the document(s) should be queried from the versions table/collection or not. [More](https://payloadcms.com/docs/versions/drafts#draft-api)\n */\n draft?: boolean\n }\n\nexport type AuthOperationsFromCollectionSlug<TSlug extends CollectionSlug> =\n TypedAuthOperations[TSlug]\n\nexport type RequiredDataFromCollection<TData extends JsonObject> = MarkOptional<\n TData,\n 'collection' | 'createdAt' | 'deletedAt' | 'id' | 'updatedAt'\n>\n\nexport type RequiredDataFromCollectionSlug<TSlug extends CollectionSlug> =\n RequiredDataFromCollection<DataFromCollectionSlug<TSlug>>\n\n/**\n * Helper type for draft data INPUT (e.g., create operations) - makes all fields optional except system fields\n * When creating a draft, required fields don't need to be provided as validation is skipped\n * The id field is optional since it's auto-generated\n */\nexport type DraftDataFromCollection<TData extends JsonObject> = Partial<\n Omit<TData, 'collection' | 'createdAt' | 'deletedAt' | 'id' | 'sizes' | 'updatedAt'>\n> &\n Partial<Pick<TData, 'collection' | 'createdAt' | 'deletedAt' | 'id' | 'sizes' | 'updatedAt'>>\n\nexport type DraftDataFromCollectionSlug<TSlug extends CollectionSlug> = DraftDataFromCollection<\n DataFromCollectionSlug<TSlug>\n>\n\n/**\n * Helper type for draft data OUTPUT (e.g., query results) - makes user fields optional but keeps id required\n * When querying drafts, required fields may be null/undefined as validation is skipped, but system fields like id are always present\n */\nexport type QueryDraftDataFromCollection<TData extends JsonObject> = Partial<\n Omit<TData, 'createdAt' | 'deletedAt' | 'id' | 'sizes' | 'updatedAt'>\n> &\n Partial<Pick<TData, 'createdAt' | 'deletedAt' | 'sizes' | 'updatedAt'>> &\n Pick<TData, 'id'>\n\nexport type QueryDraftDataFromCollectionSlug<TSlug extends CollectionSlug> =\n QueryDraftDataFromCollection<DataFromCollectionSlug<TSlug>>\n\nexport type HookOperationType =\n | 'autosave'\n | 'count'\n | 'countVersions'\n | 'create'\n | 'delete'\n | 'forgotPassword'\n | 'login'\n | 'read'\n | 'readDistinct'\n | 'refresh'\n | 'resetPassword'\n | 'restoreVersion'\n | 'update'\n\ntype CreateOrUpdateOperation = Extract<HookOperationType, 'create' | 'update'>\n\nexport type BeforeOperationHook<TOperationGeneric extends CollectionSlug = string> = (\n arg: BeforeOperationArg<TOperationGeneric>,\n) =>\n | Parameters<OperationMap<TOperationGeneric>[keyof OperationMap<TOperationGeneric>]>[0]\n | Promise<Parameters<OperationMap<TOperationGeneric>[keyof OperationMap<TOperationGeneric>]>[0]>\n | Promise<void>\n | void\n\nexport type BeforeValidateHook<T extends TypeWithID = any> = (args: {\n /** The collection which this hook is being run on */\n collection: SanitizedCollectionConfig\n context: RequestContext\n data?: Partial<T>\n /**\n * Hook operation being performed\n */\n operation: CreateOrUpdateOperation\n /**\n * Original document before change\n *\n * `undefined` on 'create' operation\n */\n originalDoc?: T\n req: PayloadRequest\n}) => any\n\nexport type BeforeChangeHook<T extends TypeWithID = any> = (args: {\n /** The collection which this hook is being run on */\n collection: SanitizedCollectionConfig\n context: RequestContext\n data: Partial<T>\n /**\n * Hook operation being performed\n */\n operation: CreateOrUpdateOperation\n /**\n * Original document before change\n *\n * `undefined` on 'create' operation\n */\n originalDoc?: T\n req: PayloadRequest\n}) => any\n\nexport type AfterChangeHook<T extends TypeWithID = any> = (args: {\n /** The collection which this hook is being run on */\n collection: SanitizedCollectionConfig\n context: RequestContext\n data: Partial<T>\n doc: T\n /**\n * Hook operation being performed\n */\n operation: CreateOrUpdateOperation\n /**\n * Whether access control is being overridden for this operation\n */\n overrideAccess?: boolean\n previousDoc: T\n req: PayloadRequest\n}) => any\n\nexport type BeforeReadHook<T extends TypeWithID = any> = (args: {\n /** The collection which this hook is being run on */\n collection: SanitizedCollectionConfig\n context: RequestContext\n doc: T\n /**\n * Whether access control is being overridden for this operation\n */\n overrideAccess?: boolean\n query: { [key: string]: any }\n req: PayloadRequest\n}) => any\n\nexport type AfterReadHook<T extends TypeWithID = any> = (args: {\n /** The collection which this hook is being run on */\n collection: SanitizedCollectionConfig\n context: RequestContext\n doc: T\n findMany?: boolean\n /**\n * Whether access control is being overridden for this operation\n */\n overrideAccess?: boolean\n query?: { [key: string]: any }\n req: PayloadRequest\n}) => any\n\nexport type BeforeDeleteHook = (args: {\n /** The collection which this hook is being run on */\n collection: SanitizedCollectionConfig\n context: RequestContext\n id: number | string\n req: PayloadRequest\n}) => any\n\nexport type AfterDeleteHook<T extends TypeWithID = any> = (args: {\n /** The collection which this hook is being run on */\n collection: SanitizedCollectionConfig\n context: RequestContext\n doc: T\n id: number | string\n req: PayloadRequest\n}) => any\n\nexport type AfterOperationHook<TOperationGeneric extends CollectionSlug = string> = (\n arg: AfterOperationArg<TOperationGeneric>,\n) =>\n | Awaited<ReturnType<OperationMap<TOperationGeneric>[keyof OperationMap<TOperationGeneric>]>>\n | Promise<\n Awaited<ReturnType<OperationMap<TOperationGeneric>[keyof OperationMap<TOperationGeneric>]>>\n >\n\nexport type BeforeLoginHook<T extends TypeWithID = any> = (args: {\n /** The collection which this hook is being run on */\n collection: SanitizedCollectionConfig\n context: RequestContext\n req: PayloadRequest\n user: T\n}) => any\n\nexport type AfterLoginHook<T extends TypeWithID = any> = (args: {\n /** The collection which this hook is being run on */\n collection: SanitizedCollectionConfig\n context: RequestContext\n req: PayloadRequest\n token: string\n user: T\n}) => any\n\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nexport type AfterLogoutHook<T extends TypeWithID = any> = (args: {\n /** The collection which this hook is being run on */\n collection: SanitizedCollectionConfig\n context: RequestContext\n req: PayloadRequest\n}) => any\n\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nexport type AfterMeHook<T extends TypeWithID = any> = (args: {\n /** The collection which this hook is being run on */\n collection: SanitizedCollectionConfig\n context: RequestContext\n req: PayloadRequest\n response: unknown\n}) => any\n\nexport type RefreshHook<T extends TypeWithID = any> = (args: {\n args: RefreshArguments\n user: T\n}) => Promise<RefreshResult | void> | (RefreshResult | void)\n\nexport type MeHook<T extends TypeWithID = any> = (args: {\n args: MeArguments\n user: T\n}) => ({ exp: number; user: T } | void) | Promise<{ exp: number; user: T } | void>\n\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nexport type AfterRefreshHook<T extends TypeWithID = any> = (args: {\n /** The collection which this hook is being run on */\n collection: SanitizedCollectionConfig\n context: RequestContext\n exp: number\n req: PayloadRequest\n token: string\n}) => any\n\nexport type AfterErrorHook = (\n args: { collection: SanitizedCollectionConfig } & AfterErrorHookArgs,\n) => AfterErrorResult | Promise<AfterErrorResult>\n\nexport type AfterForgotPasswordHook = (args: {\n args?: any\n /** The collection which this hook is being run on */\n collection: SanitizedCollectionConfig\n context: RequestContext\n}) => any\n\nexport type EnableFoldersOptions = {\n // Displays the folder collection and parentFolder field in the document view\n debug?: boolean\n}\n\nexport type BaseFilter = (args: {\n limit: number\n locale?: TypedLocale\n page: number\n req: PayloadRequest\n sort: string\n}) => null | Promise<null | Where> | Where\n\n/**\n * @deprecated Use `BaseFilter` instead.\n */\nexport type BaseListFilter = BaseFilter\n\nexport type CollectionAdminOptions = {\n /**\n * Defines a default base filter which will be applied in the following parts of the admin panel:\n * - List View\n * - Relationship fields for internal links within the Lexical editor\n *\n * This is especially useful for plugins like multi-tenant. For example,\n * a user may have access to multiple tenants, but should only see content\n * related to the currently active or selected tenant in those places.\n */\n baseFilter?: BaseFilter\n /**\n * @deprecated Use `baseFilter` instead. If both are defined,\n * `baseFilter` will take precedence. This property remains only\n * for backward compatibility and may be removed in a future version.\n *\n * Originally, `baseListFilter` was intended to filter only the List View\n * in the admin panel. However, base filtering is often required in other areas\n * such as internal link relationships in the Lexical editor.\n */\n baseListFilter?: BaseListFilter\n /**\n * Custom admin components\n */\n components?: {\n afterList?: CustomComponent[]\n afterListTable?: CustomComponent[]\n beforeList?: CustomComponent[]\n beforeListTable?: CustomComponent[]\n Description?: EntityDescriptionComponent\n /**\n * Components within the edit view\n */\n edit?: {\n /**\n * Inject custom components before the document controls\n */\n beforeDocumentControls?: CustomComponent[]\n /**\n * Inject custom components within the 3-dot menu dropdown\n */\n editMenuItems?: CustomComponent[]\n /**\n * Replaces the \"Preview\" button\n */\n PreviewButton?: CustomComponent\n /**\n * Replaces the \"Publish\" button\n * + drafts must be enabled\n */\n PublishButton?: PayloadComponent<PublishButtonServerProps, PublishButtonClientProps>\n /**\n * Replaces the \"Save\" button\n * + drafts must be disabled\n */\n SaveButton?: CustomComponent\n /**\n * Replaces the \"Save Draft\" button\n * + drafts must be enabled\n * + autosave must be disabled\n */\n SaveDraftButton?: CustomComponent\n /**\n * Replaces the \"Status\" section\n */\n Status?: CustomStatus\n /**\n * Replaces the \"Unpublish\" button\n * + drafts must be enabled\n */\n UnpublishButton?: PayloadComponent<UnpublishButtonServerProps, UnpublishButtonClientProps>\n /**\n * Replaces the \"Upload\" section\n * + upload must be enabled\n */\n Upload?: CustomUpload\n }\n listMenuItems?: CustomComponent[]\n views?: {\n /**\n * Replace, modify, or add new \"document\" views.\n * @link https://payloadcms.com/docs/custom-components/document-views\n */\n edit?: EditConfig\n /**\n * Replace or modify the \"list\" view.\n * @link https://payloadcms.com/docs/custom-components/list-view\n */\n list?: {\n actions?: CustomComponent[]\n Component?: PayloadComponent\n }\n }\n }\n /** Extension point to add your custom data. Available in server and client. */\n custom?: CollectionAdminCustom\n /**\n * Default columns to show in list view\n */\n defaultColumns?: string[]\n /**\n * Custom description for collection. This will also be used as JSDoc for the generated types\n */\n description?: EntityDescription\n /**\n * Disable the Copy To Locale button in the edit document view\n * @default false\n */\n disableCopyToLocale?: boolean\n /**\n * Performance opt-in. If true, will use the [Select API](https://payloadcms.com/docs/queries/select) when\n * loading the list view to query only the active columns, as opposed to the entire documents.\n * If your cells require specific fields that may be unselected, such as within hooks, etc.,\n * use `forceSelect` in conjunction with this property.\n *\n * @experimental This is an experimental feature and may change in the future. Use at your own risk.\n */\n enableListViewSelectAPI?: boolean\n enableRichTextLink?: boolean\n enableRichTextRelationship?: boolean\n /**\n * Function to format the URL for document links in the list view.\n * Return null to disable linking for that document.\n * Return a string to customize the link destination.\n * If not provided, uses the default admin edit URL.\n */\n formatDocURL?: (args: {\n collectionSlug: string\n /**\n * The default URL that would normally be used for this document link.\n * You can return this as-is, modify it, or completely replace it.\n */\n defaultURL: string\n doc: Record<string, unknown>\n req: PayloadRequest\n /**\n * The current view context where the link is being generated.\n * Most relevant values for document linking are 'list' and 'trash'.\n */\n viewType?: ViewTypes\n }) => null | string\n /**\n * Specify a navigational group for collections in the admin sidebar.\n * - Provide a string to place the entity in a custom group.\n * - Provide a record to define localized group names.\n * - Set to `false` to exclude the entity from the sidebar / dashboard without disabling its routes.\n */\n group?: false | Record<string, string> | string\n /**\n * @description Enable grouping by a field in the list view.\n * Uses `payload.findDistinct` under the hood to populate the group-by options.\n *\n * @experimental This option is currently in beta and may change in future releases. Use at your own risk.\n */\n groupBy?: boolean\n /**\n * Exclude the collection from the admin nav and routes\n */\n hidden?: ((args: { user: ClientUser }) => boolean) | boolean\n /**\n * Hide the API URL within the Edit view\n */\n hideAPIURL?: boolean\n /**\n * Additional fields to be searched via the full text search\n */\n listSearchableFields?: string[]\n /**\n * Live Preview options.\n *\n * @see https://payloadcms.com/docs/live-preview/overview\n */\n livePreview?: LivePreviewConfig\n meta?: MetaConfig\n pagination?: {\n defaultLimit?: number\n limits?: number[]\n }\n /**\n * Function to generate custom preview URL\n */\n preview?: GeneratePreviewURL\n /**\n * Field to use as title in Edit View and first column in List view\n */\n useAsTitle?: string\n}\n\n/** Manage all aspects of a data collection */\nexport type CollectionConfig<TSlug extends CollectionSlug = any> = {\n /**\n * Do not set this property manually. This is set to true during sanitization, to avoid\n * sanitizing the same collection multiple times.\n */\n _sanitized?: boolean\n /**\n * Access control\n */\n access?: {\n admin?: ({ req }: { req: PayloadRequest }) => boolean | Promise<boolean>\n create?: Access\n delete?: Access\n read?: Access\n readVersions?: Access\n unlock?: Access\n update?: Access\n }\n /**\n * Collection admin options\n */\n admin?: CollectionAdminOptions\n /**\n * Collection login options\n *\n * Use `true` to enable with default options\n */\n auth?: boolean | IncomingAuthType\n /**\n * Configuration for bulk operations\n */\n /** Extension point to add your custom data. Server only. */\n custom?: CollectionCustom\n /**\n * Used to override the default naming of the database table or collection with your using a function or string\n * @WARNING: If you change this property with existing data, you will need to handle the renaming of the table in your database or by using migrations\n */\n dbName?: DBIdentifierName\n defaultPopulate?: IsAny<SelectFromCollectionSlug<TSlug>> extends true\n ? SelectType\n : SelectFromCollectionSlug<TSlug>\n /**\n * Default field to sort by in collection list view\n */\n defaultSort?: Sort\n /**\n * Disable the bulk edit operation for the collection in the admin panel and the API\n */\n disableBulkEdit?: boolean\n /**\n * When true, do not show the \"Duplicate\" button while editing documents within this collection and prevent `duplicate` from all APIs\n */\n disableDuplicate?: boolean\n /**\n * Opt-in to enable query presets for this collection.\n * @see https://payloadcms.com/docs/query-presets/overview\n */\n enableQueryPresets?: boolean\n /**\n * Custom rest api endpoints, set false to disable all rest endpoints for this collection.\n */\n endpoints?: false | Omit<Endpoint, 'root'>[]\n fields: Field[]\n /**\n * Enables folders for this collection\n */\n folders?: boolean | CollectionFoldersConfiguration\n /**\n * Specify which fields should be selected always, regardless of the `select` query which can be useful that the field exists for access control / hooks\n */\n forceSelect?: IsAny<SelectFromCollectionSlug<TSlug>> extends true\n ? SelectIncludeType\n : SelectFromCollectionSlug<TSlug>\n /**\n * GraphQL configuration\n */\n graphQL?:\n | {\n disableMutations?: true\n disableQueries?: true\n pluralName?: string\n singularName?: string\n }\n | false\n /**\n * Hooks to modify Payload functionality\n */\n hooks?: {\n afterChange?: AfterChangeHook[]\n afterDelete?: AfterDeleteHook[]\n afterError?: AfterErrorHook[]\n afterForgotPassword?: AfterForgotPasswordHook[]\n afterLogin?: AfterLoginHook[]\n afterLogout?: AfterLogoutHook[]\n afterMe?: AfterMeHook[]\n afterOperation?: AfterOperationHook<TSlug>[]\n afterRead?: AfterReadHook[]\n afterRefresh?: AfterRefreshHook[]\n beforeChange?: BeforeChangeHook[]\n beforeDelete?: BeforeDeleteHook[]\n beforeLogin?: BeforeLoginHook[]\n beforeOperation?: BeforeOperationHook<TSlug>[]\n beforeRead?: BeforeReadHook[]\n beforeValidate?: BeforeValidateHook[]\n /**\n /**\n * Use the `me` hook to control the `me` operation.\n * Here, you can optionally instruct the me operation to return early,\n * and skip its default logic.\n */\n me?: MeHook[]\n /**\n * Use the `refresh` hook to control the refresh operation.\n * Here, you can optionally instruct the refresh operation to return early,\n * and skip its default logic.\n */\n refresh?: RefreshHook[]\n }\n /**\n * Define compound indexes for this collection.\n * This can be used to either speed up querying/sorting by 2 or more fields at the same time or\n * to ensure uniqueness between several fields.\n * Specify field paths\n * @example\n * [{ unique: true, fields: ['title', 'group.name'] }]\n * @default []\n */\n indexes?: CompoundIndex[]\n /**\n * Label configuration\n */\n labels?: {\n plural?: LabelFunction | StaticLabel\n singular?: LabelFunction | StaticLabel\n }\n /**\n * Enables / Disables the ability to lock documents while editing\n * @default true\n */\n lockDocuments?:\n | {\n duration: number\n }\n | false\n /**\n * If true, enables custom ordering for the collection, and documents in the listView can be reordered via drag and drop.\n * New documents are inserted at the end of the list according to this parameter.\n *\n * Under the hood, a field with {@link https://payloadcms.com/docs/configuration/collections#fractional-indexing|fractional indexing} is used to optimize inserts and reorderings.\n *\n * @default false\n *\n * @experimental There may be frequent breaking changes to this API\n */\n orderable?: boolean\n slug: string\n /**\n * Add `createdAt`, `deletedAt` and `updatedAt` fields\n *\n * @default true\n */\n timestamps?: boolean\n /**\n * Enables trash support for this collection.\n *\n * When enabled, documents will include a `deletedAt` timestamp field.\n * This allows documents to be marked as deleted without being permanently removed.\n * The `deletedAt` field will be set to the current date and time when a document is trashed.\n *\n * @experimental This is a beta feature and its behavior may be refined in future releases.\n * @default false\n */\n trash?: boolean\n /**\n * Options used in typescript generation\n */\n typescript?: {\n /**\n * Typescript generation name given to the interface type\n */\n interface?: string\n }\n /**\n * Customize the handling of incoming file uploads\n *\n * @default false // disable uploads\n */\n upload?: boolean | UploadConfig\n /**\n * Enable versioning. Set it to true to enable default versions settings,\n * or customize versions options by setting the property equal to an object\n * containing the version options.\n *\n * @default false // disable versioning\n */\n versions?: boolean | IncomingCollectionVersions\n}\n\nexport type SanitizedJoin = {\n /**\n * The field configuration defining the join\n */\n field: JoinField\n getForeignPath?(args: { locale?: TypedLocale }): string\n /**\n * The path of the join field in dot notation\n */\n joinPath: string\n /**\n * `parentIsLocalized` is true if any parent field of the\n * field configuration defining the join is localized\n */\n parentIsLocalized: boolean\n targetField: RelationshipField | UploadField\n}\n\nexport type SanitizedJoins = {\n [collectionSlug: string]: SanitizedJoin[]\n}\n\n/**\n * @todo remove the `DeepRequired` in v4.\n * We don't actually guarantee that all properties are set when sanitizing configs.\n */\nexport interface SanitizedCollectionConfig\n extends Omit<\n DeepRequired<CollectionConfig>,\n 'admin' | 'auth' | 'endpoints' | 'fields' | 'folders' | 'slug' | 'upload' | 'versions'\n > {\n admin: CollectionAdminOptions\n auth: Auth\n endpoints: Endpoint[] | false\n fields: Field[]\n /**\n * Fields in the database schema structure\n * Rows / collapsible / tabs w/o name `fields` merged to top, UIs are excluded\n */\n flattenedFields: FlattenedField[]\n /**\n * Object of collections to join 'Join Fields object keyed by collection\n */\n folders: CollectionFoldersConfiguration | false\n joins: SanitizedJoins\n\n /**\n * List of all polymorphic join fields\n */\n polymorphicJoins: SanitizedJoin[]\n\n sanitizedIndexes: SanitizedCompoundIndex[]\n\n slug: CollectionSlug\n upload: SanitizedUploadConfig\n versions?: SanitizedCollectionVersions\n}\n\nexport type Collection = {\n config: SanitizedCollectionConfig\n customIDType?: 'number' | 'text'\n graphQL?: {\n countType: GraphQLObjectType\n JWT: GraphQLObjectType\n mutationInputType: GraphQLNonNull<any>\n paginatedType: GraphQLObjectType\n type: GraphQLObjectType\n updateMutationInputType: GraphQLNonNull<any>\n versionType: GraphQLObjectType\n whereInputType: GraphQLInputObjectType\n }\n}\n\nexport type BulkOperationResult<TSlug extends CollectionSlug, TSelect extends SelectType> = {\n docs: TransformCollectionWithSelect<TSlug, TSelect>[]\n errors: {\n id: DataFromCollectionSlug<TSlug>['id']\n isPublic: boolean\n message: string\n }[]\n}\n\nexport type AuthCollection = {\n config: SanitizedCollectionConfig\n}\n\nexport type LocalizedMeta = {\n [locale: string]: {\n status: 'draft' | 'published'\n updatedAt: string\n }\n}\n\nexport type TypeWithID = {\n id: number | string\n}\n\nexport type TypeWithTimestamps = {\n [key: string]: unknown\n createdAt: string\n deletedAt?: null | string\n id: number | string\n updatedAt: string\n}\n\nexport type CompoundIndex = {\n fields: string[]\n unique?: boolean\n}\n\nexport type SanitizedCompoundIndex = {\n fields: {\n field: FlattenedField\n localizedPath: string\n path: string\n pathHasLocalized: boolean\n }[]\n unique: boolean\n}\n"],"names":[],"mappings":"AAAA,qDAAqD,GA+1BrD,WAQC"}
1
+ {"version":3,"sources":["../../../src/collections/config/types.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport type { GraphQLInputObjectType, GraphQLNonNull, GraphQLObjectType } from 'graphql'\nimport type { DeepRequired, IsAny, MarkOptional } from 'ts-essentials'\n\nimport type {\n CustomStatus,\n CustomUpload,\n PublishButtonClientProps,\n PublishButtonServerProps,\n UnpublishButtonClientProps,\n UnpublishButtonServerProps,\n ViewTypes,\n} from '../../admin/types.js'\nimport type { Arguments as MeArguments } from '../../auth/operations/me.js'\nimport type {\n Arguments as RefreshArguments,\n Result as RefreshResult,\n} from '../../auth/operations/refresh.js'\nimport type { Auth, ClientUser, IncomingAuthType } from '../../auth/types.js'\nimport type {\n Access,\n AfterErrorHookArgs,\n AfterErrorResult,\n CustomComponent,\n EditConfig,\n Endpoint,\n EntityDescription,\n EntityDescriptionComponent,\n GeneratePreviewURL,\n LabelFunction,\n LivePreviewConfig,\n MetaConfig,\n PayloadComponent,\n StaticLabel,\n} from '../../config/types.js'\nimport type { DBIdentifierName } from '../../database/types.js'\nimport type {\n Field,\n FlattenedField,\n JoinField,\n RelationshipField,\n UploadField,\n} from '../../fields/config/types.js'\nimport type { CollectionFoldersConfiguration } from '../../folders/types.js'\nimport type {\n CollectionAdminCustom,\n CollectionCustom,\n CollectionSlug,\n GeneratedTypes,\n JsonObject,\n RequestContext,\n TypedAuthOperations,\n TypedCollection,\n TypedCollectionSelect,\n TypedLocale,\n} from '../../index.js'\nimport type {\n PayloadRequest,\n SelectIncludeType,\n SelectType,\n Sort,\n TransformCollectionWithSelect,\n Where,\n} from '../../types/index.js'\nimport type { SanitizedUploadConfig, UploadConfig } from '../../uploads/types.js'\nimport type {\n IncomingCollectionVersions,\n SanitizedCollectionVersions,\n} from '../../versions/types.js'\nimport type {\n AfterOperationArg,\n BeforeOperationArg,\n OperationMap,\n} from '../operations/utilities/types.js'\n\nexport type DataFromCollectionSlug<TSlug extends CollectionSlug> = TypedCollection[TSlug]\n\nexport type SelectFromCollectionSlug<TSlug extends CollectionSlug> = TypedCollectionSelect[TSlug]\n\n/**\n * Collection slugs that do not have drafts enabled.\n * Detects collections without drafts by checking for the absence of the `_status` field.\n */\nexport type CollectionsWithoutDrafts = {\n [TSlug in CollectionSlug]: DataFromCollectionSlug<TSlug> extends { _status?: any } ? never : TSlug\n}[CollectionSlug]\n\n/**\n * Conditionally allows or forbids the `draft` property based on collection configuration.\n * When `strictDraftTypes` is enabled, the `draft` property is forbidden on collections without drafts.\n */\nexport type DraftFlagFromCollectionSlug<TSlug extends CollectionSlug> = GeneratedTypes extends {\n strictDraftTypes: true\n}\n ? TSlug extends CollectionsWithoutDrafts\n ? {\n /**\n * The `draft` property is not allowed because this collection does not have `versions.drafts` enabled.\n */\n draft?: never\n }\n : {\n /**\n * Whether the document(s) should be queried from the versions table/collection or not. [More](https://payloadcms.com/docs/versions/drafts#draft-api)\n */\n draft?: boolean\n }\n : {\n /**\n * Whether the document(s) should be queried from the versions table/collection or not. [More](https://payloadcms.com/docs/versions/drafts#draft-api)\n */\n draft?: boolean\n }\n\nexport type AuthOperationsFromCollectionSlug<TSlug extends CollectionSlug> =\n TypedAuthOperations[TSlug]\n\nexport type RequiredDataFromCollection<TData extends JsonObject> = MarkOptional<\n TData,\n 'createdAt' | 'deletedAt' | 'id' | 'updatedAt'\n>\n\nexport type RequiredDataFromCollectionSlug<TSlug extends CollectionSlug> =\n RequiredDataFromCollection<DataFromCollectionSlug<TSlug>>\n\n/**\n * Helper type for draft data INPUT (e.g., create operations) - makes all fields optional except system fields\n * When creating a draft, required fields don't need to be provided as validation is skipped\n * The id field is optional since it's auto-generated\n */\nexport type DraftDataFromCollection<TData extends JsonObject> = Partial<\n Omit<TData, 'createdAt' | 'deletedAt' | 'id' | 'sizes' | 'updatedAt'>\n> &\n Partial<Pick<TData, 'createdAt' | 'deletedAt' | 'id' | 'sizes' | 'updatedAt'>>\n\nexport type DraftDataFromCollectionSlug<TSlug extends CollectionSlug> = DraftDataFromCollection<\n DataFromCollectionSlug<TSlug>\n>\n\n/**\n * Helper type for draft data OUTPUT (e.g., query results) - makes user fields optional but keeps id required\n * When querying drafts, required fields may be null/undefined as validation is skipped, but system fields like id are always present\n */\nexport type QueryDraftDataFromCollection<TData extends JsonObject> = Partial<\n Omit<TData, 'createdAt' | 'deletedAt' | 'id' | 'sizes' | 'updatedAt'>\n> &\n Partial<Pick<TData, 'createdAt' | 'deletedAt' | 'sizes' | 'updatedAt'>> &\n Pick<TData, 'id'>\n\nexport type QueryDraftDataFromCollectionSlug<TSlug extends CollectionSlug> =\n QueryDraftDataFromCollection<DataFromCollectionSlug<TSlug>>\n\nexport type HookOperationType =\n | 'autosave'\n | 'count'\n | 'countVersions'\n | 'create'\n | 'delete'\n | 'forgotPassword'\n | 'login'\n | 'read'\n | 'readDistinct'\n | 'refresh'\n | 'resetPassword'\n | 'restoreVersion'\n | 'update'\n\ntype CreateOrUpdateOperation = Extract<HookOperationType, 'create' | 'update'>\n\nexport type BeforeOperationHook<TOperationGeneric extends CollectionSlug = string> = (\n arg: BeforeOperationArg<TOperationGeneric>,\n) =>\n | Parameters<OperationMap<TOperationGeneric>[keyof OperationMap<TOperationGeneric>]>[0]\n | Promise<Parameters<OperationMap<TOperationGeneric>[keyof OperationMap<TOperationGeneric>]>[0]>\n | Promise<void>\n | void\n\nexport type BeforeValidateHook<T extends TypeWithID = any> = (args: {\n /** The collection which this hook is being run on */\n collection: SanitizedCollectionConfig\n context: RequestContext\n data?: Partial<T>\n /**\n * Hook operation being performed\n */\n operation: CreateOrUpdateOperation\n /**\n * Original document before change\n *\n * `undefined` on 'create' operation\n */\n originalDoc?: T\n req: PayloadRequest\n}) => any\n\nexport type BeforeChangeHook<T extends TypeWithID = any> = (args: {\n /** The collection which this hook is being run on */\n collection: SanitizedCollectionConfig\n context: RequestContext\n data: Partial<T>\n /**\n * Hook operation being performed\n */\n operation: CreateOrUpdateOperation\n /**\n * Original document before change\n *\n * `undefined` on 'create' operation\n */\n originalDoc?: T\n req: PayloadRequest\n}) => any\n\nexport type AfterChangeHook<T extends TypeWithID = any> = (args: {\n /** The collection which this hook is being run on */\n collection: SanitizedCollectionConfig\n context: RequestContext\n data: Partial<T>\n doc: T\n /**\n * Hook operation being performed\n */\n operation: CreateOrUpdateOperation\n /**\n * Whether access control is being overridden for this operation\n */\n overrideAccess?: boolean\n previousDoc: T\n req: PayloadRequest\n}) => any\n\nexport type BeforeReadHook<T extends TypeWithID = any> = (args: {\n /** The collection which this hook is being run on */\n collection: SanitizedCollectionConfig\n context: RequestContext\n doc: T\n /**\n * Whether access control is being overridden for this operation\n */\n overrideAccess?: boolean\n query: { [key: string]: any }\n req: PayloadRequest\n}) => any\n\nexport type AfterReadHook<T extends TypeWithID = any> = (args: {\n /** The collection which this hook is being run on */\n collection: SanitizedCollectionConfig\n context: RequestContext\n doc: T\n findMany?: boolean\n /**\n * Whether access control is being overridden for this operation\n */\n overrideAccess?: boolean\n query?: { [key: string]: any }\n req: PayloadRequest\n}) => any\n\nexport type BeforeDeleteHook = (args: {\n /** The collection which this hook is being run on */\n collection: SanitizedCollectionConfig\n context: RequestContext\n id: number | string\n req: PayloadRequest\n}) => any\n\nexport type AfterDeleteHook<T extends TypeWithID = any> = (args: {\n /** The collection which this hook is being run on */\n collection: SanitizedCollectionConfig\n context: RequestContext\n doc: T\n id: number | string\n req: PayloadRequest\n}) => any\n\nexport type AfterOperationHook<TOperationGeneric extends CollectionSlug = string> = (\n arg: AfterOperationArg<TOperationGeneric>,\n) =>\n | Awaited<ReturnType<OperationMap<TOperationGeneric>[keyof OperationMap<TOperationGeneric>]>>\n | Promise<\n Awaited<ReturnType<OperationMap<TOperationGeneric>[keyof OperationMap<TOperationGeneric>]>>\n >\n\nexport type BeforeLoginHook<T extends TypeWithID = any> = (args: {\n /** The collection which this hook is being run on */\n collection: SanitizedCollectionConfig\n context: RequestContext\n req: PayloadRequest\n user: T\n}) => any\n\nexport type AfterLoginHook<T extends TypeWithID = any> = (args: {\n /** The collection which this hook is being run on */\n collection: SanitizedCollectionConfig\n context: RequestContext\n req: PayloadRequest\n token: string\n user: T\n}) => any\n\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nexport type AfterLogoutHook<T extends TypeWithID = any> = (args: {\n /** The collection which this hook is being run on */\n collection: SanitizedCollectionConfig\n context: RequestContext\n req: PayloadRequest\n}) => any\n\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nexport type AfterMeHook<T extends TypeWithID = any> = (args: {\n /** The collection which this hook is being run on */\n collection: SanitizedCollectionConfig\n context: RequestContext\n req: PayloadRequest\n response: unknown\n}) => any\n\nexport type RefreshHook<T extends TypeWithID = any> = (args: {\n args: RefreshArguments\n user: T\n}) => Promise<RefreshResult | void> | (RefreshResult | void)\n\nexport type MeHook<T extends TypeWithID = any> = (args: {\n args: MeArguments\n user: T\n}) => ({ exp: number; user: T } | void) | Promise<{ exp: number; user: T } | void>\n\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nexport type AfterRefreshHook<T extends TypeWithID = any> = (args: {\n /** The collection which this hook is being run on */\n collection: SanitizedCollectionConfig\n context: RequestContext\n exp: number\n req: PayloadRequest\n token: string\n}) => any\n\nexport type AfterErrorHook = (\n args: { collection: SanitizedCollectionConfig } & AfterErrorHookArgs,\n) => AfterErrorResult | Promise<AfterErrorResult>\n\nexport type AfterForgotPasswordHook = (args: {\n args?: any\n /** The collection which this hook is being run on */\n collection: SanitizedCollectionConfig\n context: RequestContext\n}) => any\n\nexport type EnableFoldersOptions = {\n // Displays the folder collection and parentFolder field in the document view\n debug?: boolean\n}\n\nexport type BaseFilter = (args: {\n limit: number\n locale?: TypedLocale\n page: number\n req: PayloadRequest\n sort: string\n}) => null | Promise<null | Where> | Where\n\n/**\n * @deprecated Use `BaseFilter` instead.\n */\nexport type BaseListFilter = BaseFilter\n\nexport type CollectionAdminOptions = {\n /**\n * Defines a default base filter which will be applied in the following parts of the admin panel:\n * - List View\n * - Relationship fields for internal links within the Lexical editor\n *\n * This is especially useful for plugins like multi-tenant. For example,\n * a user may have access to multiple tenants, but should only see content\n * related to the currently active or selected tenant in those places.\n */\n baseFilter?: BaseFilter\n /**\n * @deprecated Use `baseFilter` instead. If both are defined,\n * `baseFilter` will take precedence. This property remains only\n * for backward compatibility and may be removed in a future version.\n *\n * Originally, `baseListFilter` was intended to filter only the List View\n * in the admin panel. However, base filtering is often required in other areas\n * such as internal link relationships in the Lexical editor.\n */\n baseListFilter?: BaseListFilter\n /**\n * Custom admin components\n */\n components?: {\n afterList?: CustomComponent[]\n afterListTable?: CustomComponent[]\n beforeList?: CustomComponent[]\n beforeListTable?: CustomComponent[]\n Description?: EntityDescriptionComponent\n /**\n * Components within the edit view\n */\n edit?: {\n /**\n * Inject custom components before the document controls\n */\n beforeDocumentControls?: CustomComponent[]\n /**\n * Inject custom components within the 3-dot menu dropdown\n */\n editMenuItems?: CustomComponent[]\n /**\n * Replaces the \"Preview\" button\n */\n PreviewButton?: CustomComponent\n /**\n * Replaces the \"Publish\" button\n * + drafts must be enabled\n */\n PublishButton?: PayloadComponent<PublishButtonServerProps, PublishButtonClientProps>\n /**\n * Replaces the \"Save\" button\n * + drafts must be disabled\n */\n SaveButton?: CustomComponent\n /**\n * Replaces the \"Save Draft\" button\n * + drafts must be enabled\n * + autosave must be disabled\n */\n SaveDraftButton?: CustomComponent\n /**\n * Replaces the \"Status\" section\n */\n Status?: CustomStatus\n /**\n * Replaces the \"Unpublish\" button\n * + drafts must be enabled\n */\n UnpublishButton?: PayloadComponent<UnpublishButtonServerProps, UnpublishButtonClientProps>\n /**\n * Replaces the \"Upload\" section\n * + upload must be enabled\n */\n Upload?: CustomUpload\n }\n listMenuItems?: CustomComponent[]\n views?: {\n /**\n * Replace, modify, or add new \"document\" views.\n * @link https://payloadcms.com/docs/custom-components/document-views\n */\n edit?: EditConfig\n /**\n * Replace or modify the \"list\" view.\n * @link https://payloadcms.com/docs/custom-components/list-view\n */\n list?: {\n actions?: CustomComponent[]\n Component?: PayloadComponent\n }\n }\n }\n /** Extension point to add your custom data. Available in server and client. */\n custom?: CollectionAdminCustom\n /**\n * Default columns to show in list view\n */\n defaultColumns?: string[]\n /**\n * Custom description for collection. This will also be used as JSDoc for the generated types\n */\n description?: EntityDescription\n /**\n * Disable the Copy To Locale button in the edit document view\n * @default false\n */\n disableCopyToLocale?: boolean\n /**\n * Performance opt-in. If true, will use the [Select API](https://payloadcms.com/docs/queries/select) when\n * loading the list view to query only the active columns, as opposed to the entire documents.\n * If your cells require specific fields that may be unselected, such as within hooks, etc.,\n * use `forceSelect` in conjunction with this property.\n *\n * @experimental This is an experimental feature and may change in the future. Use at your own risk.\n */\n enableListViewSelectAPI?: boolean\n enableRichTextLink?: boolean\n enableRichTextRelationship?: boolean\n /**\n * Function to format the URL for document links in the list view.\n * Return null to disable linking for that document.\n * Return a string to customize the link destination.\n * If not provided, uses the default admin edit URL.\n */\n formatDocURL?: (args: {\n collectionSlug: string\n /**\n * The default URL that would normally be used for this document link.\n * You can return this as-is, modify it, or completely replace it.\n */\n defaultURL: string\n doc: Record<string, unknown>\n req: PayloadRequest\n /**\n * The current view context where the link is being generated.\n * Most relevant values for document linking are 'list' and 'trash'.\n */\n viewType?: ViewTypes\n }) => null | string\n /**\n * Specify a navigational group for collections in the admin sidebar.\n * - Provide a string to place the entity in a custom group.\n * - Provide a record to define localized group names.\n * - Set to `false` to exclude the entity from the sidebar / dashboard without disabling its routes.\n */\n group?: false | Record<string, string> | string\n /**\n * @description Enable grouping by a field in the list view.\n * Uses `payload.findDistinct` under the hood to populate the group-by options.\n *\n * @experimental This option is currently in beta and may change in future releases. Use at your own risk.\n */\n groupBy?: boolean\n /**\n * Exclude the collection from the admin nav and routes\n */\n hidden?: ((args: { user: ClientUser }) => boolean) | boolean\n /**\n * Hide the API URL within the Edit view\n */\n hideAPIURL?: boolean\n /**\n * Additional fields to be searched via the full text search\n */\n listSearchableFields?: string[]\n /**\n * Live Preview options.\n *\n * @see https://payloadcms.com/docs/live-preview/overview\n */\n livePreview?: LivePreviewConfig\n meta?: MetaConfig\n pagination?: {\n defaultLimit?: number\n limits?: number[]\n }\n /**\n * Function to generate custom preview URL\n */\n preview?: GeneratePreviewURL\n /**\n * Field to use as title in Edit View and first column in List view\n */\n useAsTitle?: string\n}\n\n/** Manage all aspects of a data collection */\nexport type CollectionConfig<TSlug extends CollectionSlug = any> = {\n /**\n * Do not set this property manually. This is set to true during sanitization, to avoid\n * sanitizing the same collection multiple times.\n */\n _sanitized?: boolean\n /**\n * Access control\n */\n access?: {\n admin?: ({ req }: { req: PayloadRequest }) => boolean | Promise<boolean>\n create?: Access\n delete?: Access\n read?: Access\n readVersions?: Access\n unlock?: Access\n update?: Access\n }\n /**\n * Collection admin options\n */\n admin?: CollectionAdminOptions\n /**\n * Collection login options\n *\n * Use `true` to enable with default options\n */\n auth?: boolean | IncomingAuthType\n /**\n * Configuration for bulk operations\n */\n /** Extension point to add your custom data. Server only. */\n custom?: CollectionCustom\n /**\n * Used to override the default naming of the database table or collection with your using a function or string\n * @WARNING: If you change this property with existing data, you will need to handle the renaming of the table in your database or by using migrations\n */\n dbName?: DBIdentifierName\n defaultPopulate?: IsAny<SelectFromCollectionSlug<TSlug>> extends true\n ? SelectType\n : SelectFromCollectionSlug<TSlug>\n /**\n * Default field to sort by in collection list view\n */\n defaultSort?: Sort\n /**\n * Disable the bulk edit operation for the collection in the admin panel and the API\n */\n disableBulkEdit?: boolean\n /**\n * When true, do not show the \"Duplicate\" button while editing documents within this collection and prevent `duplicate` from all APIs\n */\n disableDuplicate?: boolean\n /**\n * Opt-in to enable query presets for this collection.\n * @see https://payloadcms.com/docs/query-presets/overview\n */\n enableQueryPresets?: boolean\n /**\n * Custom rest api endpoints, set false to disable all rest endpoints for this collection.\n */\n endpoints?: false | Omit<Endpoint, 'root'>[]\n fields: Field[]\n /**\n * Enables folders for this collection\n */\n folders?: boolean | CollectionFoldersConfiguration\n /**\n * Specify which fields should be selected always, regardless of the `select` query which can be useful that the field exists for access control / hooks\n */\n forceSelect?: IsAny<SelectFromCollectionSlug<TSlug>> extends true\n ? SelectIncludeType\n : SelectFromCollectionSlug<TSlug>\n /**\n * GraphQL configuration\n */\n graphQL?:\n | {\n disableMutations?: true\n disableQueries?: true\n pluralName?: string\n singularName?: string\n }\n | false\n /**\n * Hooks to modify Payload functionality\n */\n hooks?: {\n afterChange?: AfterChangeHook[]\n afterDelete?: AfterDeleteHook[]\n afterError?: AfterErrorHook[]\n afterForgotPassword?: AfterForgotPasswordHook[]\n afterLogin?: AfterLoginHook[]\n afterLogout?: AfterLogoutHook[]\n afterMe?: AfterMeHook[]\n afterOperation?: AfterOperationHook<TSlug>[]\n afterRead?: AfterReadHook[]\n afterRefresh?: AfterRefreshHook[]\n beforeChange?: BeforeChangeHook[]\n beforeDelete?: BeforeDeleteHook[]\n beforeLogin?: BeforeLoginHook[]\n beforeOperation?: BeforeOperationHook<TSlug>[]\n beforeRead?: BeforeReadHook[]\n beforeValidate?: BeforeValidateHook[]\n /**\n /**\n * Use the `me` hook to control the `me` operation.\n * Here, you can optionally instruct the me operation to return early,\n * and skip its default logic.\n */\n me?: MeHook[]\n /**\n * Use the `refresh` hook to control the refresh operation.\n * Here, you can optionally instruct the refresh operation to return early,\n * and skip its default logic.\n */\n refresh?: RefreshHook[]\n }\n /**\n * Define compound indexes for this collection.\n * This can be used to either speed up querying/sorting by 2 or more fields at the same time or\n * to ensure uniqueness between several fields.\n * Specify field paths\n * @example\n * [{ unique: true, fields: ['title', 'group.name'] }]\n * @default []\n */\n indexes?: CompoundIndex[]\n /**\n * Label configuration\n */\n labels?: {\n plural?: LabelFunction | StaticLabel\n singular?: LabelFunction | StaticLabel\n }\n /**\n * Enables / Disables the ability to lock documents while editing\n * @default true\n */\n lockDocuments?:\n | {\n duration: number\n }\n | false\n /**\n * If true, enables custom ordering for the collection, and documents in the listView can be reordered via drag and drop.\n * New documents are inserted at the end of the list according to this parameter.\n *\n * Under the hood, a field with {@link https://payloadcms.com/docs/configuration/collections#fractional-indexing|fractional indexing} is used to optimize inserts and reorderings.\n *\n * @default false\n *\n * @experimental There may be frequent breaking changes to this API\n */\n orderable?: boolean\n slug: string\n /**\n * Add `createdAt`, `deletedAt` and `updatedAt` fields\n *\n * @default true\n */\n timestamps?: boolean\n /**\n * Enables trash support for this collection.\n *\n * When enabled, documents will include a `deletedAt` timestamp field.\n * This allows documents to be marked as deleted without being permanently removed.\n * The `deletedAt` field will be set to the current date and time when a document is trashed.\n *\n * @experimental This is a beta feature and its behavior may be refined in future releases.\n * @default false\n */\n trash?: boolean\n /**\n * Options used in typescript generation\n */\n typescript?: {\n /**\n * Typescript generation name given to the interface type\n */\n interface?: string\n }\n /**\n * Customize the handling of incoming file uploads\n *\n * @default false // disable uploads\n */\n upload?: boolean | UploadConfig\n /**\n * Enable versioning. Set it to true to enable default versions settings,\n * or customize versions options by setting the property equal to an object\n * containing the version options.\n *\n * @default false // disable versioning\n */\n versions?: boolean | IncomingCollectionVersions\n}\n\nexport type SanitizedJoin = {\n /**\n * The field configuration defining the join\n */\n field: JoinField\n getForeignPath?(args: { locale?: TypedLocale }): string\n /**\n * The path of the join field in dot notation\n */\n joinPath: string\n /**\n * `parentIsLocalized` is true if any parent field of the\n * field configuration defining the join is localized\n */\n parentIsLocalized: boolean\n targetField: RelationshipField | UploadField\n}\n\nexport type SanitizedJoins = {\n [collectionSlug: string]: SanitizedJoin[]\n}\n\n/**\n * @todo remove the `DeepRequired` in v4.\n * We don't actually guarantee that all properties are set when sanitizing configs.\n */\nexport interface SanitizedCollectionConfig\n extends Omit<\n DeepRequired<CollectionConfig>,\n 'admin' | 'auth' | 'endpoints' | 'fields' | 'folders' | 'slug' | 'upload' | 'versions'\n > {\n admin: CollectionAdminOptions\n auth: Auth\n endpoints: Endpoint[] | false\n fields: Field[]\n /**\n * Fields in the database schema structure\n * Rows / collapsible / tabs w/o name `fields` merged to top, UIs are excluded\n */\n flattenedFields: FlattenedField[]\n /**\n * Object of collections to join 'Join Fields object keyed by collection\n */\n folders: CollectionFoldersConfiguration | false\n joins: SanitizedJoins\n\n /**\n * List of all polymorphic join fields\n */\n polymorphicJoins: SanitizedJoin[]\n\n sanitizedIndexes: SanitizedCompoundIndex[]\n\n slug: CollectionSlug\n upload: SanitizedUploadConfig\n versions?: SanitizedCollectionVersions\n}\n\nexport type Collection = {\n config: SanitizedCollectionConfig\n customIDType?: 'number' | 'text'\n graphQL?: {\n countType: GraphQLObjectType\n JWT: GraphQLObjectType\n mutationInputType: GraphQLNonNull<any>\n paginatedType: GraphQLObjectType\n type: GraphQLObjectType\n updateMutationInputType: GraphQLNonNull<any>\n versionType: GraphQLObjectType\n whereInputType: GraphQLInputObjectType\n }\n}\n\nexport type BulkOperationResult<TSlug extends CollectionSlug, TSelect extends SelectType> = {\n docs: TransformCollectionWithSelect<TSlug, TSelect>[]\n errors: {\n id: DataFromCollectionSlug<TSlug>['id']\n isPublic: boolean\n message: string\n }[]\n}\n\nexport type AuthCollection = {\n config: SanitizedCollectionConfig\n}\n\nexport type LocalizedMeta = {\n [locale: string]: {\n status: 'draft' | 'published'\n updatedAt: string\n }\n}\n\nexport type TypeWithID = {\n id: number | string\n}\n\nexport type TypeWithTimestamps = {\n [key: string]: unknown\n createdAt: string\n deletedAt?: null | string\n id: number | string\n updatedAt: string\n}\n\nexport type CompoundIndex = {\n fields: string[]\n unique?: boolean\n}\n\nexport type SanitizedCompoundIndex = {\n fields: {\n field: FlattenedField\n localizedPath: string\n path: string\n pathHasLocalized: boolean\n }[]\n unique: boolean\n}\n"],"names":[],"mappings":"AAAA,qDAAq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AAE,QAAQ,CAAC,CAAA;AAElD,eAAO,MAAM,eAAe,GAC1B,KAAK,SAAS,cAAc,EAC5B,OAAO,SAAS,wBAAwB,CAAC,KAAK,CAAC,gBAEjC,SAAS,CAAC,KAAK,CAAC,KAC7B,OAAO,CAAC,6BAA6B,CAAC,KAAK,EAAE,OAAO,CAAC,CA8XvD,CAAA"}
@@ -199,15 +199,6 @@ export const createOperation = async (incomingArgs)=>{
199
199
  const verificationToken = doc._verificationToken;
200
200
  let result = sanitizeInternalFields(doc);
201
201
  // /////////////////////////////////////
202
- // Add collection property for auth collections
203
- // /////////////////////////////////////
204
- if (collectionConfig.auth) {
205
- result = {
206
- ...result,
207
- collection: collectionConfig.slug
208
- };
209
- }
210
- // /////////////////////////////////////
211
202
  // Create version
212
203
  // /////////////////////////////////////
213
204
  if (collectionConfig.versions) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/collections/operations/create.ts"],"sourcesContent":["import crypto from 'crypto'\n\nimport type { CollectionSlug, FindOptions, JsonObject } from '../../index.js'\nimport type {\n Document,\n PayloadRequest,\n PopulateType,\n SelectType,\n TransformCollectionWithSelect,\n} from '../../types/index.js'\nimport type {\n Collection,\n DataFromCollectionSlug,\n RequiredDataFromCollectionSlug,\n SelectFromCollectionSlug,\n} from '../config/types.js'\n\nimport { ensureUsernameOrEmail } from '../../auth/ensureUsernameOrEmail.js'\nimport { executeAccess } from '../../auth/executeAccess.js'\nimport { sendVerificationEmail } from '../../auth/sendVerificationEmail.js'\nimport { registerLocalStrategy } from '../../auth/strategies/local/register.js'\nimport { getDuplicateDocumentData } from '../../duplicateDocument/index.js'\nimport { afterChange } from '../../fields/hooks/afterChange/index.js'\nimport { afterRead } from '../../fields/hooks/afterRead/index.js'\nimport { beforeChange } from '../../fields/hooks/beforeChange/index.js'\nimport { beforeValidate } from '../../fields/hooks/beforeValidate/index.js'\nimport { saveVersion } from '../../index.js'\nimport { generateFileData } from '../../uploads/generateFileData.js'\nimport { unlinkTempFiles } from '../../uploads/unlinkTempFiles.js'\nimport { uploadFiles } from '../../uploads/uploadFiles.js'\nimport { commitTransaction } from '../../utilities/commitTransaction.js'\nimport {\n hasDraftsEnabled,\n hasDraftValidationEnabled,\n hasLocalizeStatusEnabled,\n} from '../../utilities/getVersionsConfig.js'\nimport { initTransaction } from '../../utilities/initTransaction.js'\nimport { killTransaction } from '../../utilities/killTransaction.js'\nimport { sanitizeInternalFields } from '../../utilities/sanitizeInternalFields.js'\nimport { sanitizeSelect } from '../../utilities/sanitizeSelect.js'\nimport { buildAfterOperation } from './utilities/buildAfterOperation.js'\nimport { buildBeforeOperation } from './utilities/buildBeforeOperation.js'\n\nexport type Arguments<TSlug extends CollectionSlug> = {\n autosave?: boolean\n collection: Collection\n data: RequiredDataFromCollectionSlug<TSlug>\n depth?: number\n disableTransaction?: boolean\n disableVerificationEmail?: boolean\n draft?: boolean\n duplicateFromID?: DataFromCollectionSlug<TSlug>['id']\n overrideAccess?: boolean\n overwriteExistingFiles?: boolean\n populate?: PopulateType\n publishAllLocales?: boolean\n publishSpecificLocale?: string\n req: PayloadRequest\n selectedLocales?: string[]\n showHiddenFields?: boolean\n} & Pick<FindOptions<TSlug, SelectType>, 'select'>\n\nexport const createOperation = async <\n TSlug extends CollectionSlug,\n TSelect extends SelectFromCollectionSlug<TSlug>,\n>(\n incomingArgs: Arguments<TSlug>,\n): Promise<TransformCollectionWithSelect<TSlug, TSelect>> => {\n let args = incomingArgs\n\n try {\n const shouldCommit = !args.disableTransaction && (await initTransaction(args.req))\n\n ensureUsernameOrEmail<TSlug>({\n authOptions: args.collection.config.auth,\n collectionSlug: args.collection.config.slug,\n data: args.data,\n operation: 'create',\n req: args.req,\n })\n\n // /////////////////////////////////////\n // beforeOperation - Collection\n // /////////////////////////////////////\n\n args = await buildBeforeOperation({\n args,\n collection: args.collection.config,\n operation: 'create',\n overrideAccess: args.overrideAccess!,\n })\n\n if (args.publishSpecificLocale) {\n args.req.locale = args.publishSpecificLocale\n }\n\n const {\n autosave = false,\n collection: { config: collectionConfig },\n collection,\n depth,\n disableVerificationEmail,\n draft = false,\n duplicateFromID,\n overrideAccess,\n overwriteExistingFiles = false,\n populate,\n publishAllLocales: publishAllLocalesArg,\n publishSpecificLocale,\n req: {\n fallbackLocale,\n locale,\n payload,\n payload: { config },\n },\n req,\n select: incomingSelect,\n selectedLocales,\n showHiddenFields,\n } = args\n\n let { data } = args\n\n const publishAllLocales =\n !draft &&\n (publishAllLocalesArg ?? (hasLocalizeStatusEnabled(collectionConfig) ? false : true))\n const isSavingDraft = Boolean(draft && hasDraftsEnabled(collectionConfig) && !publishAllLocales)\n\n if (isSavingDraft) {\n data._status = 'draft'\n }\n\n let duplicatedFromDocWithLocales: JsonObject = {}\n let duplicatedFromDoc: JsonObject = {}\n\n if (duplicateFromID) {\n const duplicateResult = await getDuplicateDocumentData({\n id: duplicateFromID,\n collectionConfig,\n draftArg: isSavingDraft,\n overrideAccess,\n req,\n selectedLocales,\n })\n\n duplicatedFromDoc = duplicateResult.duplicatedFromDoc\n duplicatedFromDocWithLocales = duplicateResult.duplicatedFromDocWithLocales\n }\n\n // /////////////////////////////////////\n // Access\n // /////////////////////////////////////\n\n if (!overrideAccess) {\n await executeAccess({ data, req }, collectionConfig.access.create)\n }\n\n // /////////////////////////////////////\n // Generate data for all files and sizes\n // /////////////////////////////////////\n\n const { data: newFileData, files: filesToUpload } = await generateFileData({\n collection,\n config,\n data,\n isDuplicating: Boolean(duplicateFromID),\n operation: 'create',\n originalDoc: duplicatedFromDoc,\n overwriteExistingFiles,\n req,\n throwOnMissingFile:\n !isSavingDraft && collection.config.upload.filesRequiredOnCreate !== false,\n })\n\n data = newFileData\n\n // /////////////////////////////////////\n // beforeValidate - Fields\n // /////////////////////////////////////\n\n data = await beforeValidate({\n collection: collectionConfig,\n context: req.context,\n data,\n doc: duplicatedFromDoc,\n global: null,\n operation: 'create',\n overrideAccess: overrideAccess!,\n req,\n })\n\n // /////////////////////////////////////\n // beforeValidate - Collections\n // /////////////////////////////////////\n\n if (collectionConfig.hooks.beforeValidate?.length) {\n for (const hook of collectionConfig.hooks.beforeValidate) {\n data =\n (await hook({\n collection: collectionConfig,\n context: req.context,\n data,\n operation: 'create',\n originalDoc: duplicatedFromDoc,\n req,\n })) || data\n }\n }\n\n // /////////////////////////////////////\n // beforeChange - Collection\n // /////////////////////////////////////\n\n if (collectionConfig.hooks?.beforeChange?.length) {\n for (const hook of collectionConfig.hooks.beforeChange) {\n data =\n (await hook({\n collection: collectionConfig,\n context: req.context,\n data,\n operation: 'create',\n originalDoc: duplicatedFromDoc,\n req,\n })) || data\n }\n }\n\n // /////////////////////////////////////\n // beforeChange - Fields\n // /////////////////////////////////////\n\n const resultWithLocales = await beforeChange<JsonObject>({\n collection: collectionConfig,\n context: req.context,\n data,\n doc: duplicatedFromDoc,\n docWithLocales: duplicatedFromDocWithLocales,\n global: null,\n operation: 'create',\n overrideAccess,\n req,\n skipValidation: isSavingDraft && !hasDraftValidationEnabled(collectionConfig),\n })\n\n if (\n config.localization &&\n collectionConfig.versions &&\n collectionConfig.versions.drafts &&\n collectionConfig.versions.drafts.localizeStatus &&\n publishAllLocales\n ) {\n let accessibleLocaleCodes = config.localization.localeCodes\n\n if (config.localization.filterAvailableLocales) {\n const filteredLocales = await config.localization.filterAvailableLocales({\n locales: config.localization.locales,\n req,\n })\n accessibleLocaleCodes = filteredLocales.map((locale) =>\n typeof locale === 'string' ? locale : locale.code,\n )\n }\n\n if (typeof resultWithLocales._status !== 'object' || resultWithLocales._status === null) {\n resultWithLocales._status = {}\n }\n\n for (const localeCode of accessibleLocaleCodes) {\n resultWithLocales._status[localeCode] = 'published'\n }\n }\n\n // /////////////////////////////////////\n // Write files to local storage\n // /////////////////////////////////////\n\n if (!collectionConfig.upload.disableLocalStorage) {\n await uploadFiles(payload, filesToUpload, req)\n }\n\n // /////////////////////////////////////\n // Create\n // /////////////////////////////////////\n\n let doc\n\n const select = sanitizeSelect({\n fields: collectionConfig.flattenedFields,\n forceSelect: collectionConfig.forceSelect,\n select: incomingSelect,\n })\n\n if (collectionConfig.auth && !collectionConfig.auth.disableLocalStrategy) {\n if (collectionConfig.auth.verify) {\n resultWithLocales._verified = Boolean(resultWithLocales._verified) || false\n resultWithLocales._verificationToken = crypto.randomBytes(20).toString('hex')\n }\n\n doc = await registerLocalStrategy({\n collection: collectionConfig,\n doc: resultWithLocales,\n password: data.password as string,\n payload: req.payload,\n req,\n })\n } else {\n doc = await payload.db.create({\n collection: collectionConfig.slug,\n data: resultWithLocales,\n req,\n })\n }\n\n const verificationToken = doc._verificationToken\n let result: Document = sanitizeInternalFields(doc)\n\n // /////////////////////////////////////\n // Add collection property for auth collections\n // /////////////////////////////////////\n\n if (collectionConfig.auth) {\n result = { ...result, collection: collectionConfig.slug }\n }\n\n // /////////////////////////////////////\n // Create version\n // /////////////////////////////////////\n\n if (collectionConfig.versions) {\n await saveVersion({\n id: result.id,\n autosave,\n collection: collectionConfig,\n docWithLocales: result,\n operation: 'create',\n payload,\n publishSpecificLocale,\n req,\n returning: false,\n })\n }\n\n // /////////////////////////////////////\n // Send verification email if applicable\n // /////////////////////////////////////\n\n if (collectionConfig.auth && collectionConfig.auth.verify && result.email) {\n await sendVerificationEmail({\n collection: { config: collectionConfig },\n config: payload.config,\n disableEmail: disableVerificationEmail!,\n email: payload.email,\n req,\n token: verificationToken,\n user: result,\n })\n }\n\n // /////////////////////////////////////\n // afterRead - Fields\n // /////////////////////////////////////\n\n result = await afterRead({\n collection: collectionConfig,\n context: req.context,\n depth: depth!,\n doc: result,\n draft,\n fallbackLocale: fallbackLocale!,\n global: null,\n locale: locale!,\n overrideAccess: overrideAccess!,\n populate,\n req,\n select,\n showHiddenFields: showHiddenFields!,\n })\n\n // /////////////////////////////////////\n // afterRead - Collection\n // /////////////////////////////////////\n\n if (collectionConfig.hooks?.afterRead?.length) {\n for (const hook of collectionConfig.hooks.afterRead) {\n result =\n (await hook({\n collection: collectionConfig,\n context: req.context,\n doc: result,\n overrideAccess,\n req,\n })) || result\n }\n }\n\n // /////////////////////////////////////\n // afterChange - Fields\n // /////////////////////////////////////\n\n result = await afterChange({\n collection: collectionConfig,\n context: req.context,\n data,\n doc: result,\n global: null,\n operation: 'create',\n previousDoc: {},\n req,\n })\n\n // /////////////////////////////////////\n // afterChange - Collection\n // /////////////////////////////////////\n\n if (collectionConfig.hooks?.afterChange?.length) {\n for (const hook of collectionConfig.hooks.afterChange) {\n result =\n (await hook({\n collection: collectionConfig,\n context: req.context,\n data,\n doc: result,\n operation: 'create',\n overrideAccess,\n previousDoc: {},\n req: args.req,\n })) || result\n }\n }\n\n // /////////////////////////////////////\n // afterOperation - Collection\n // /////////////////////////////////////\n\n result = await buildAfterOperation<TSlug>({\n args,\n collection: collectionConfig,\n operation: 'create',\n overrideAccess: args.overrideAccess!,\n result,\n })\n\n await unlinkTempFiles({ collectionConfig, config, req })\n\n // /////////////////////////////////////\n // Return results\n // /////////////////////////////////////\n\n if (shouldCommit) {\n await commitTransaction(req)\n }\n\n return result\n } catch (error: unknown) {\n await killTransaction(args.req)\n throw error\n }\n}\n"],"names":["crypto","ensureUsernameOrEmail","executeAccess","sendVerificationEmail","registerLocalStrategy","getDuplicateDocumentData","afterChange","afterRead","beforeChange","beforeValidate","saveVersion","generateFileData","unlinkTempFiles","uploadFiles","commitTransaction","hasDraftsEnabled","hasDraftValidationEnabled","hasLocalizeStatusEnabled","initTransaction","killTransaction","sanitizeInternalFields","sanitizeSelect","buildAfterOperation","buildBeforeOperation","createOperation","incomingArgs","args","shouldCommit","disableTransaction","req","authOptions","collection","config","auth","collectionSlug","slug","data","operation","overrideAccess","publishSpecificLocale","locale","autosave","collectionConfig","depth","disableVerificationEmail","draft","duplicateFromID","overwriteExistingFiles","populate","publishAllLocales","publishAllLocalesArg","fallbackLocale","payload","select","incomingSelect","selectedLocales","showHiddenFields","isSavingDraft","Boolean","_status","duplicatedFromDocWithLocales","duplicatedFromDoc","duplicateResult","id","draftArg","access","create","newFileData","files","filesToUpload","isDuplicating","originalDoc","throwOnMissingFile","upload","filesRequiredOnCreate","context","doc","global","hooks","length","hook","resultWithLocales","docWithLocales","skipValidation","localization","versions","drafts","localizeStatus","accessibleLocaleCodes","localeCodes","filterAvailableLocales","filteredLocales","locales","map","code","localeCode","disableLocalStorage","fields","flattenedFields","forceSelect","disableLocalStrategy","verify","_verified","_verificationToken","randomBytes","toString","password","db","verificationToken","result","returning","email","disableEmail","token","user","previousDoc","error"],"mappings":"AAAA,OAAOA,YAAY,SAAQ;AAiB3B,SAASC,qBAAqB,QAAQ,sCAAqC;AAC3E,SAASC,aAAa,QAAQ,8BAA6B;AAC3D,SAASC,qBAAqB,QAAQ,sCAAqC;AAC3E,SAASC,qBAAqB,QAAQ,0CAAyC;AAC/E,SAASC,wBAAwB,QAAQ,mCAAkC;AAC3E,SAASC,WAAW,QAAQ,0CAAyC;AACrE,SAASC,SAAS,QAAQ,wCAAuC;AACjE,SAASC,YAAY,QAAQ,2CAA0C;AACvE,SAASC,cAAc,QAAQ,6CAA4C;AAC3E,SAASC,WAAW,QAAQ,iBAAgB;AAC5C,SAASC,gBAAgB,QAAQ,oCAAmC;AACpE,SAASC,eAAe,QAAQ,mCAAkC;AAClE,SAASC,WAAW,QAAQ,+BAA8B;AAC1D,SAASC,iBAAiB,QAAQ,uCAAsC;AACxE,SACEC,gBAAgB,EAChBC,yBAAyB,EACzBC,wBAAwB,QACnB,uCAAsC;AAC7C,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,sBAAsB,QAAQ,4CAA2C;AAClF,SAASC,cAAc,QAAQ,oCAAmC;AAClE,SAASC,mBAAmB,QAAQ,qCAAoC;AACxE,SAASC,oBAAoB,QAAQ,sCAAqC;AAqB1E,OAAO,MAAMC,kBAAkB,OAI7BC;IAEA,IAAIC,OAAOD;IAEX,IAAI;QACF,MAAME,eAAe,CAACD,KAAKE,kBAAkB,IAAK,MAAMV,gBAAgBQ,KAAKG,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C,KAAK,EAAExE,aAAayE,QAAQ;YAC/C,KAAK,MAAMC,QAAQtC,iBAAiBoC,KAAK,CAACxE,WAAW,CAAE;gBACrDuG,SACE,AAAC,MAAM7B,KAAK;oBACVjD,YAAYW;oBACZiC,SAAS9C,IAAI8C,OAAO;oBACpBvC;oBACAwC,KAAKiC;oBACLxE,WAAW;oBACXC;oBACA6E,aAAa,CAAC;oBACdtF,KAAKH,KAAKG,GAAG;gBACf,MAAOgF;YACX;QACF;QAEA,wCAAwC;QACxC,8BAA8B;QAC9B,wCAAwC;QAExCA,SAAS,MAAMvF,oBAA2B;YACxCI;YACAK,YAAYW;YACZL,WAAW;YACXC,gBAAgBZ,KAAKY,cAAc;YACnCuE;QACF;QAEA,MAAMjG,gBAAgB;YAAE8B;YAAkBV;YAAQH;QAAI;QAEtD,wCAAwC;QACxC,iBAAiB;QACjB,wCAAwC;QAExC,IAAIF,cAAc;YAChB,MAAMb,kBAAkBe;QAC1B;QAEA,OAAOgF;IACT,EAAE,OAAOO,OAAgB;QACvB,MAAMjG,gBAAgBO,KAAKG,GAAG;QAC9B,MAAMuF;IACR;AACF,EAAC"}
1
+ {"version":3,"sources":["../../../src/collections/operations/create.ts"],"sourcesContent":["import crypto from 'crypto'\n\nimport type { CollectionSlug, FindOptions, JsonObject } from '../../index.js'\nimport type {\n Document,\n PayloadRequest,\n PopulateType,\n SelectType,\n TransformCollectionWithSelect,\n} from '../../types/index.js'\nimport type {\n Collection,\n DataFromCollectionSlug,\n RequiredDataFromCollectionSlug,\n SelectFromCollectionSlug,\n} from '../config/types.js'\n\nimport { ensureUsernameOrEmail } from '../../auth/ensureUsernameOrEmail.js'\nimport { executeAccess } from '../../auth/executeAccess.js'\nimport { sendVerificationEmail } from '../../auth/sendVerificationEmail.js'\nimport { registerLocalStrategy } from '../../auth/strategies/local/register.js'\nimport { getDuplicateDocumentData } from '../../duplicateDocument/index.js'\nimport { afterChange } from '../../fields/hooks/afterChange/index.js'\nimport { afterRead } from '../../fields/hooks/afterRead/index.js'\nimport { beforeChange } from '../../fields/hooks/beforeChange/index.js'\nimport { beforeValidate } from '../../fields/hooks/beforeValidate/index.js'\nimport { saveVersion } from '../../index.js'\nimport { generateFileData } from '../../uploads/generateFileData.js'\nimport { unlinkTempFiles } from '../../uploads/unlinkTempFiles.js'\nimport { uploadFiles } from '../../uploads/uploadFiles.js'\nimport { commitTransaction } from '../../utilities/commitTransaction.js'\nimport {\n hasDraftsEnabled,\n hasDraftValidationEnabled,\n hasLocalizeStatusEnabled,\n} from '../../utilities/getVersionsConfig.js'\nimport { initTransaction } from '../../utilities/initTransaction.js'\nimport { killTransaction } from '../../utilities/killTransaction.js'\nimport { sanitizeInternalFields } from '../../utilities/sanitizeInternalFields.js'\nimport { sanitizeSelect } from '../../utilities/sanitizeSelect.js'\nimport { buildAfterOperation } from './utilities/buildAfterOperation.js'\nimport { buildBeforeOperation } from './utilities/buildBeforeOperation.js'\n\nexport type Arguments<TSlug extends CollectionSlug> = {\n autosave?: boolean\n collection: Collection\n data: RequiredDataFromCollectionSlug<TSlug>\n depth?: number\n disableTransaction?: boolean\n disableVerificationEmail?: boolean\n draft?: boolean\n duplicateFromID?: DataFromCollectionSlug<TSlug>['id']\n overrideAccess?: boolean\n overwriteExistingFiles?: boolean\n populate?: PopulateType\n publishAllLocales?: boolean\n publishSpecificLocale?: string\n req: PayloadRequest\n selectedLocales?: string[]\n showHiddenFields?: boolean\n} & Pick<FindOptions<TSlug, SelectType>, 'select'>\n\nexport const createOperation = async <\n TSlug extends CollectionSlug,\n TSelect extends SelectFromCollectionSlug<TSlug>,\n>(\n incomingArgs: Arguments<TSlug>,\n): Promise<TransformCollectionWithSelect<TSlug, TSelect>> => {\n let args = incomingArgs\n\n try {\n const shouldCommit = !args.disableTransaction && (await initTransaction(args.req))\n\n ensureUsernameOrEmail<TSlug>({\n authOptions: args.collection.config.auth,\n collectionSlug: args.collection.config.slug,\n data: args.data,\n operation: 'create',\n req: args.req,\n })\n\n // /////////////////////////////////////\n // beforeOperation - Collection\n // /////////////////////////////////////\n\n args = await buildBeforeOperation({\n args,\n collection: args.collection.config,\n operation: 'create',\n overrideAccess: args.overrideAccess!,\n })\n\n if (args.publishSpecificLocale) {\n args.req.locale = args.publishSpecificLocale\n }\n\n const {\n autosave = false,\n collection: { config: collectionConfig },\n collection,\n depth,\n disableVerificationEmail,\n draft = false,\n duplicateFromID,\n overrideAccess,\n overwriteExistingFiles = false,\n populate,\n publishAllLocales: publishAllLocalesArg,\n publishSpecificLocale,\n req: {\n fallbackLocale,\n locale,\n payload,\n payload: { config },\n },\n req,\n select: incomingSelect,\n selectedLocales,\n showHiddenFields,\n } = args\n\n let { data } = args\n\n const publishAllLocales =\n !draft &&\n (publishAllLocalesArg ?? (hasLocalizeStatusEnabled(collectionConfig) ? false : true))\n const isSavingDraft = Boolean(draft && hasDraftsEnabled(collectionConfig) && !publishAllLocales)\n\n if (isSavingDraft) {\n data._status = 'draft'\n }\n\n let duplicatedFromDocWithLocales: JsonObject = {}\n let duplicatedFromDoc: JsonObject = {}\n\n if (duplicateFromID) {\n const duplicateResult = await getDuplicateDocumentData({\n id: duplicateFromID,\n collectionConfig,\n draftArg: isSavingDraft,\n overrideAccess,\n req,\n selectedLocales,\n })\n\n duplicatedFromDoc = duplicateResult.duplicatedFromDoc\n duplicatedFromDocWithLocales = duplicateResult.duplicatedFromDocWithLocales\n }\n\n // /////////////////////////////////////\n // Access\n // /////////////////////////////////////\n\n if (!overrideAccess) {\n await executeAccess({ data, req }, collectionConfig.access.create)\n }\n\n // /////////////////////////////////////\n // Generate data for all files and sizes\n // /////////////////////////////////////\n\n const { data: newFileData, files: filesToUpload } = await generateFileData({\n collection,\n config,\n data,\n isDuplicating: Boolean(duplicateFromID),\n operation: 'create',\n originalDoc: duplicatedFromDoc,\n overwriteExistingFiles,\n req,\n throwOnMissingFile:\n !isSavingDraft && collection.config.upload.filesRequiredOnCreate !== false,\n })\n\n data = newFileData\n\n // /////////////////////////////////////\n // beforeValidate - Fields\n // /////////////////////////////////////\n\n data = await beforeValidate({\n collection: collectionConfig,\n context: req.context,\n data,\n doc: duplicatedFromDoc,\n global: null,\n operation: 'create',\n overrideAccess: overrideAccess!,\n req,\n })\n\n // /////////////////////////////////////\n // beforeValidate - Collections\n // /////////////////////////////////////\n\n if (collectionConfig.hooks.beforeValidate?.length) {\n for (const hook of collectionConfig.hooks.beforeValidate) {\n data =\n (await hook({\n collection: collectionConfig,\n context: req.context,\n data,\n operation: 'create',\n originalDoc: duplicatedFromDoc,\n req,\n })) || data\n }\n }\n\n // /////////////////////////////////////\n // beforeChange - Collection\n // /////////////////////////////////////\n\n if (collectionConfig.hooks?.beforeChange?.length) {\n for (const hook of collectionConfig.hooks.beforeChange) {\n data =\n (await hook({\n collection: collectionConfig,\n context: req.context,\n data,\n operation: 'create',\n originalDoc: duplicatedFromDoc,\n req,\n })) || data\n }\n }\n\n // /////////////////////////////////////\n // beforeChange - Fields\n // /////////////////////////////////////\n\n const resultWithLocales = await beforeChange<JsonObject>({\n collection: collectionConfig,\n context: req.context,\n data,\n doc: duplicatedFromDoc,\n docWithLocales: duplicatedFromDocWithLocales,\n global: null,\n operation: 'create',\n overrideAccess,\n req,\n skipValidation: isSavingDraft && !hasDraftValidationEnabled(collectionConfig),\n })\n\n if (\n config.localization &&\n collectionConfig.versions &&\n collectionConfig.versions.drafts &&\n collectionConfig.versions.drafts.localizeStatus &&\n publishAllLocales\n ) {\n let accessibleLocaleCodes = config.localization.localeCodes\n\n if (config.localization.filterAvailableLocales) {\n const filteredLocales = await config.localization.filterAvailableLocales({\n locales: config.localization.locales,\n req,\n })\n accessibleLocaleCodes = filteredLocales.map((locale) =>\n typeof locale === 'string' ? locale : locale.code,\n )\n }\n\n if (typeof resultWithLocales._status !== 'object' || resultWithLocales._status === null) {\n resultWithLocales._status = {}\n }\n\n for (const localeCode of accessibleLocaleCodes) {\n resultWithLocales._status[localeCode] = 'published'\n }\n }\n\n // /////////////////////////////////////\n // Write files to local storage\n // /////////////////////////////////////\n\n if (!collectionConfig.upload.disableLocalStorage) {\n await uploadFiles(payload, filesToUpload, req)\n }\n\n // /////////////////////////////////////\n // Create\n // /////////////////////////////////////\n\n let doc\n\n const select = sanitizeSelect({\n fields: collectionConfig.flattenedFields,\n forceSelect: collectionConfig.forceSelect,\n select: incomingSelect,\n })\n\n if (collectionConfig.auth && !collectionConfig.auth.disableLocalStrategy) {\n if (collectionConfig.auth.verify) {\n resultWithLocales._verified = Boolean(resultWithLocales._verified) || false\n resultWithLocales._verificationToken = crypto.randomBytes(20).toString('hex')\n }\n\n doc = await registerLocalStrategy({\n collection: collectionConfig,\n doc: resultWithLocales,\n password: data.password as string,\n payload: req.payload,\n req,\n })\n } else {\n doc = await payload.db.create({\n collection: collectionConfig.slug,\n data: resultWithLocales,\n req,\n })\n }\n\n const verificationToken = doc._verificationToken\n let result: Document = sanitizeInternalFields(doc)\n\n // /////////////////////////////////////\n // Create version\n // /////////////////////////////////////\n\n if (collectionConfig.versions) {\n await saveVersion({\n id: result.id,\n autosave,\n collection: collectionConfig,\n docWithLocales: result,\n operation: 'create',\n payload,\n publishSpecificLocale,\n req,\n returning: false,\n })\n }\n\n // /////////////////////////////////////\n // Send verification email if applicable\n // /////////////////////////////////////\n\n if (collectionConfig.auth && collectionConfig.auth.verify && result.email) {\n await sendVerificationEmail({\n collection: { config: collectionConfig },\n config: payload.config,\n disableEmail: disableVerificationEmail!,\n email: payload.email,\n req,\n token: verificationToken,\n user: result,\n })\n }\n\n // /////////////////////////////////////\n // afterRead - Fields\n // /////////////////////////////////////\n\n result = await afterRead({\n collection: collectionConfig,\n context: req.context,\n depth: depth!,\n doc: result,\n draft,\n fallbackLocale: fallbackLocale!,\n global: null,\n locale: locale!,\n overrideAccess: overrideAccess!,\n populate,\n req,\n select,\n showHiddenFields: showHiddenFields!,\n })\n\n // /////////////////////////////////////\n // afterRead - Collection\n // /////////////////////////////////////\n\n if (collectionConfig.hooks?.afterRead?.length) {\n for (const hook of collectionConfig.hooks.afterRead) {\n result =\n (await hook({\n collection: collectionConfig,\n context: req.context,\n doc: result,\n overrideAccess,\n req,\n })) || result\n }\n }\n\n // /////////////////////////////////////\n // afterChange - Fields\n // /////////////////////////////////////\n\n result = await afterChange({\n collection: collectionConfig,\n context: req.context,\n data,\n doc: result,\n global: null,\n operation: 'create',\n previousDoc: {},\n req,\n })\n\n // /////////////////////////////////////\n // afterChange - Collection\n // /////////////////////////////////////\n\n if (collectionConfig.hooks?.afterChange?.length) {\n for (const hook of collectionConfig.hooks.afterChange) {\n result =\n (await hook({\n collection: collectionConfig,\n context: req.context,\n data,\n doc: result,\n operation: 'create',\n overrideAccess,\n previousDoc: {},\n req: args.req,\n })) || result\n }\n }\n\n // /////////////////////////////////////\n // afterOperation - Collection\n // /////////////////////////////////////\n\n result = await buildAfterOperation<TSlug>({\n args,\n collection: collectionConfig,\n operation: 'create',\n overrideAccess: args.overrideAccess!,\n result,\n })\n\n await unlinkTempFiles({ collectionConfig, config, req })\n\n // /////////////////////////////////////\n // Return results\n // /////////////////////////////////////\n\n if (shouldCommit) {\n await commitTransaction(req)\n }\n\n return result\n } catch (error: unknown) {\n await killTransaction(args.req)\n throw error\n }\n}\n"],"names":["crypto","ensureUsernameOrEmail","executeAccess","sendVerificationEmail","registerLocalStrategy","getDuplicateDocumentData","afterChange","afterRead","beforeChange","beforeValidate","saveVersion","generateFileData","unlinkTempFiles","uploadFiles","commitTransaction","hasDraftsEnabled","hasDraftValidationEnabled","hasLocalizeStatusEnabled","initTransaction","killTransaction","sanitizeInternalFields","sanitizeSelect","buildAfterOperation","buildBeforeOperation","createOperation","incomingArgs","args","shouldCommit","disableTransaction","req","authOptions","collection","config","auth","collectionSlug","slug","data","operation","overrideAccess","publishSpecificLocale","locale","autosave","collectionConfig","depth","disableVerificationEmail","draft","duplicateFromID","overwriteExistingFiles","populate","publishAllLocales","publishAllLocalesArg","fallbackLocale","payload","select","incomingSelect","selectedLocales","showHiddenFields","isSavingDraft","Boolean","_status","duplicatedFromDocWithLocales","duplicatedFromDoc","duplicateResult","id","draftArg","access","create","newFileData","files","filesToUpload","isDuplicating","originalDoc","throwOnMissingFile","upload","filesRequiredOnCreate","context","doc","global","hooks","length","hook","resultWithLocales","docWithLocales","skipValidation","localization","versions","drafts","localizeStatus","accessibleLocaleCodes","localeCodes","filterAvailableLocales","filteredLocales","locales","map","code","localeCode","disableLocalStorage","fields","flattenedFields","forceSelect","disableLocalStrategy","verify","_verified","_verificationToken","randomBytes","toString","password","db","verificationToken","result","returning","email","disableEmail","token","user","previousDoc","error"],"mappings":"AAAA,OAAOA,YAAY,SAAQ;AAiB3B,SAASC,qBAAqB,QAAQ,sCAAqC;AAC3E,SAASC,aAAa,QAAQ,8BAA6B;AAC3D,SAASC,qBAAqB,QAAQ,sCAAqC;AAC3E,SAASC,qBAAqB,QAAQ,0CAAyC;AAC/E,SAASC,wBAAwB,QAAQ,mCAAkC;AAC3E,SAASC,WAAW,QAAQ,0CAAyC;AACrE,SAASC,SAAS,QAAQ,wCAAuC;AACjE,SAASC,YAAY,QAAQ,2CAA0C;AACvE,SAASC,cAAc,QAAQ,6CAA4C;AAC3E,SAASC,WAAW,QAAQ,iBAAgB;AAC5C,SAASC,gBAAgB,QAAQ,oCAAmC;AACpE,SAASC,eAAe,QAAQ,mCAAkC;AAClE,SAASC,WAAW,QAAQ,+BAA8B;AAC1D,SAASC,iBAAiB,QAAQ,uCAAsC;AACxE,SACEC,gBAAgB,EAChBC,yBAAyB,EACzBC,wBAAwB,QACnB,uCAAsC;AAC7C,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,sBAAsB,QAAQ,4CAA2C;AAClF,SAASC,cAAc,QAAQ,oCAAmC;AAClE,SAASC,mBAAmB,QAAQ,qCAAoC;AACxE,SAASC,oBAAoB,QAAQ,sCAAqC;AAqB1E,OAAO,MAAMC,kBAAkB,OAI7BC;IAEA,IAAIC,OAAOD;IAEX,IAAI;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AAE;gBACrDuG,SACE,AAAC,MAAM7B,KAAK;oBACVjD,YAAYW;oBACZiC,SAAS9C,IAAI8C,OAAO;oBACpBvC;oBACAwC,KAAKiC;oBACLxE,WAAW;oBACXC;oBACA6E,aAAa,CAAC;oBACdtF,KAAKH,KAAKG,GAAG;gBACf,MAAOgF;YACX;QACF;QAEA,wCAAwC;QACxC,8BAA8B;QAC9B,wCAAwC;QAExCA,SAAS,MAAMvF,oBAA2B;YACxCI;YACAK,YAAYW;YACZL,WAAW;YACXC,gBAAgBZ,KAAKY,cAAc;YACnCuE;QACF;QAEA,MAAMjG,gBAAgB;YAAE8B;YAAkBV;YAAQH;QAAI;QAEtD,wCAAwC;QACxC,iBAAiB;QACjB,wCAAwC;QAExC,IAAIF,cAAc;YAChB,MAAMb,kBAAkBe;QAC1B;QAEA,OAAOgF;IACT,EAAE,OAAOO,OAAgB;QACvB,MAAMjG,gBAAgBO,KAAKG,GAAG;QAC9B,MAAMuF;IACR;AACF,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"delete.d.ts","sourceRoot":"","sources":["../../../src/collections/operations/delete.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AACjE,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAA;AAC3F,OAAO,KAAK,EACV,mBAAmB,EACnB,UAAU,EAEV,wBAAwB,EACzB,MAAM,oBAAoB,CAAA;AAuB3B,MAAM,MAAM,SAAS,GAAG;IACtB,UAAU,EAAE,UAAU,CAAA;IACtB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,kBAAkB,CAAC,EAAE,OAAO,CAAA;IAC5B,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,QAAQ,CAAC,EAAE,YAAY,CAAA;IACvB,GAAG,EAAE,cAAc,CAAA;IAC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AAwB,CAAC,KAAK,CAAC,gBAEjC,SAAS,KACtB,OAAO,CAAC,mBAAmB,CAAC,KAAK,EAAE,OAAO,CAAC,CA6S7C,CAAA"}
@@ -173,15 +173,6 @@ export const deleteOperation = async (incomingArgs)=>{
173
173
  showHiddenFields: showHiddenFields
174
174
  });
175
175
  // /////////////////////////////////////
176
- // Add collection property for auth collections
177
- // /////////////////////////////////////
178
- if (collectionConfig.auth) {
179
- result = {
180
- ...result,
181
- collection: collectionConfig.slug
182
- };
183
- }
184
- // /////////////////////////////////////
185
176
  // afterRead - Collection
186
177
  // /////////////////////////////////////
187
178
  if (collectionConfig.hooks?.afterRead?.length) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/collections/operations/delete.ts"],"sourcesContent":["import { status as httpStatus } from 'http-status'\n\nimport type { AccessResult } from '../../config/types.js'\nimport type { CollectionSlug, FindOptions } from '../../index.js'\nimport type { PayloadRequest, PopulateType, SelectType, Where } from '../../types/index.js'\nimport type {\n BulkOperationResult,\n Collection,\n DataFromCollectionSlug,\n SelectFromCollectionSlug,\n} from '../config/types.js'\n\nimport { executeAccess } from '../../auth/executeAccess.js'\nimport { combineQueries } from '../../database/combineQueries.js'\nimport { validateQueryPaths } from '../../database/queryValidation/validateQueryPaths.js'\nimport { sanitizeWhereQuery } from '../../database/sanitizeWhereQuery.js'\nimport { APIError } from '../../errors/index.js'\nimport { afterRead } from '../../fields/hooks/afterRead/index.js'\nimport { deleteUserPreferences } from '../../preferences/deleteUserPreferences.js'\nimport { deleteAssociatedFiles } from '../../uploads/deleteAssociatedFiles.js'\nimport { appendNonTrashedFilter } from '../../utilities/appendNonTrashedFilter.js'\nimport { checkDocumentLockStatus } from '../../utilities/checkDocumentLockStatus.js'\nimport { commitTransaction } from '../../utilities/commitTransaction.js'\nimport { hasScheduledPublishEnabled } from '../../utilities/getVersionsConfig.js'\nimport { initTransaction } from '../../utilities/initTransaction.js'\nimport { isErrorPublic } from '../../utilities/isErrorPublic.js'\nimport { killTransaction } from '../../utilities/killTransaction.js'\nimport { sanitizeSelect } from '../../utilities/sanitizeSelect.js'\nimport { deleteCollectionVersions } from '../../versions/deleteCollectionVersions.js'\nimport { deleteScheduledPublishJobs } from '../../versions/deleteScheduledPublishJobs.js'\nimport { buildAfterOperation } from './utilities/buildAfterOperation.js'\nimport { buildBeforeOperation } from './utilities/buildBeforeOperation.js'\n\nexport type Arguments = {\n collection: Collection\n depth?: number\n disableTransaction?: boolean\n overrideAccess?: boolean\n overrideLock?: boolean\n populate?: PopulateType\n req: PayloadRequest\n showHiddenFields?: boolean\n trash?: boolean\n where: Where\n} & Pick<FindOptions<string, SelectType>, 'select'>\n\nexport const deleteOperation = async <\n TSlug extends CollectionSlug,\n TSelect extends SelectFromCollectionSlug<TSlug>,\n>(\n incomingArgs: Arguments,\n): Promise<BulkOperationResult<TSlug, TSelect>> => {\n let args = incomingArgs\n\n try {\n const shouldCommit = !args.disableTransaction && (await initTransaction(args.req))\n // /////////////////////////////////////\n // beforeOperation - Collection\n // /////////////////////////////////////\n\n args = await buildBeforeOperation({\n args,\n collection: args.collection.config,\n operation: 'delete',\n overrideAccess: args.overrideAccess!,\n })\n\n const {\n collection: { config: collectionConfig },\n depth,\n overrideAccess,\n overrideLock,\n populate,\n req: {\n fallbackLocale,\n locale,\n payload: { config },\n payload,\n },\n req,\n select: incomingSelect,\n showHiddenFields,\n trash = false,\n where,\n } = args\n\n if (!where) {\n throw new APIError(\"Missing 'where' query of documents to delete.\", httpStatus.BAD_REQUEST)\n }\n\n // /////////////////////////////////////\n // Access\n // /////////////////////////////////////\n\n let accessResult: AccessResult\n\n if (!overrideAccess) {\n accessResult = await executeAccess({ req }, collectionConfig.access.delete)\n }\n\n await validateQueryPaths({\n collectionConfig,\n overrideAccess: overrideAccess!,\n req,\n where,\n })\n\n let fullWhere = combineQueries(where, accessResult!)\n\n // Exclude trashed documents when trash: false\n fullWhere = appendNonTrashedFilter({\n enableTrash: collectionConfig.trash,\n trash,\n where: fullWhere,\n })\n\n sanitizeWhereQuery({ fields: collectionConfig.flattenedFields, payload, where: fullWhere })\n\n const select = sanitizeSelect({\n fields: collectionConfig.flattenedFields,\n forceSelect: collectionConfig.forceSelect,\n select: incomingSelect,\n })\n\n // /////////////////////////////////////\n // Retrieve documents\n // /////////////////////////////////////\n\n const { docs } = await payload.db.find<DataFromCollectionSlug<TSlug>>({\n collection: collectionConfig.slug,\n locale: locale!,\n req,\n select,\n where: fullWhere,\n })\n\n const errors: BulkOperationResult<TSlug, TSelect>['errors'] = []\n\n const promises = docs.map(async (doc) => {\n let result\n\n const { id } = doc\n\n try {\n // Each document gets its own transaction when singleTransaction is enabled\n let docShouldCommit = false\n if (req.payload.db.bulkOperationsSingleTransaction) {\n docShouldCommit = await initTransaction(req)\n }\n\n // /////////////////////////////////////\n // Handle potentially locked documents\n // /////////////////////////////////////\n\n await checkDocumentLockStatus({\n id,\n collectionSlug: collectionConfig.slug,\n lockErrorMessage: `Document with ID ${id} is currently locked and cannot be deleted.`,\n overrideLock,\n req,\n })\n\n // /////////////////////////////////////\n // beforeDelete - Collection\n // /////////////////////////////////////\n\n if (collectionConfig.hooks?.beforeDelete?.length) {\n for (const hook of collectionConfig.hooks.beforeDelete) {\n await hook({\n id,\n collection: collectionConfig,\n context: req.context,\n req,\n })\n }\n }\n\n await deleteAssociatedFiles({\n collectionConfig,\n config,\n doc,\n overrideDelete: true,\n req,\n })\n\n // /////////////////////////////////////\n // Delete versions\n // /////////////////////////////////////\n\n if (collectionConfig.versions) {\n await deleteCollectionVersions({\n id,\n slug: collectionConfig.slug,\n payload,\n req,\n })\n }\n\n // /////////////////////////////////////\n // Delete scheduled posts\n // /////////////////////////////////////\n if (hasScheduledPublishEnabled(collectionConfig)) {\n await deleteScheduledPublishJobs({\n id,\n slug: collectionConfig.slug,\n payload,\n req,\n })\n }\n\n // /////////////////////////////////////\n // Delete document\n // /////////////////////////////////////\n\n await payload.db.deleteOne({\n collection: collectionConfig.slug,\n req,\n returning: false,\n where: {\n id: {\n equals: id,\n },\n },\n })\n\n // /////////////////////////////////////\n // afterRead - Fields\n // /////////////////////////////////////\n\n result = await afterRead({\n collection: collectionConfig,\n context: req.context,\n depth: depth!,\n doc: result || doc,\n // @ts-expect-error - vestiges of when tsconfig was not strict. Feel free to improve\n draft: undefined,\n fallbackLocale: fallbackLocale!,\n global: null,\n locale: locale!,\n overrideAccess: overrideAccess!,\n populate,\n req,\n select,\n showHiddenFields: showHiddenFields!,\n })\n\n // /////////////////////////////////////\n // Add collection property for auth collections\n // /////////////////////////////////////\n\n if (collectionConfig.auth) {\n result = { ...result, collection: collectionConfig.slug }\n }\n\n // /////////////////////////////////////\n // afterRead - Collection\n // /////////////////////////////////////\n\n if (collectionConfig.hooks?.afterRead?.length) {\n for (const hook of collectionConfig.hooks.afterRead) {\n result =\n (await hook({\n collection: collectionConfig,\n context: req.context,\n doc: result || doc,\n overrideAccess,\n req,\n })) || result\n }\n }\n\n // /////////////////////////////////////\n // afterDelete - Collection\n // /////////////////////////////////////\n\n if (collectionConfig.hooks?.afterDelete?.length) {\n for (const hook of collectionConfig.hooks.afterDelete) {\n result =\n (await hook({\n id,\n collection: collectionConfig,\n context: req.context,\n doc: result,\n req,\n })) || result\n }\n }\n\n // /////////////////////////////////////\n // 8. Return results\n // /////////////////////////////////////\n if (docShouldCommit) {\n await commitTransaction(req)\n }\n\n return result\n } catch (error) {\n const isPublic = error instanceof Error ? isErrorPublic(error, config) : false\n\n if (req.payload.db.bulkOperationsSingleTransaction) {\n await killTransaction(req)\n }\n errors.push({\n id: doc.id,\n isPublic,\n message: error instanceof Error ? error.message : 'Unknown error',\n })\n }\n return null\n })\n\n // Process sequentially when using single transaction mode to avoid shared state issues\n // Process in parallel when using one transaction for better performance\n let awaitedDocs\n if (req.payload.db.bulkOperationsSingleTransaction) {\n awaitedDocs = []\n for (const promise of promises) {\n awaitedDocs.push(await promise)\n }\n } else {\n awaitedDocs = await Promise.all(promises)\n }\n\n // /////////////////////////////////////\n // Delete Preferences\n // /////////////////////////////////////\n\n await deleteUserPreferences({\n collectionConfig,\n ids: docs.map(({ id }) => id),\n payload,\n req,\n })\n\n let result = {\n docs: awaitedDocs.filter(Boolean),\n errors,\n }\n\n // /////////////////////////////////////\n // afterOperation - Collection\n // /////////////////////////////////////\n\n result = await buildAfterOperation({\n args,\n collection: collectionConfig,\n operation: 'delete',\n overrideAccess,\n result,\n })\n\n if (shouldCommit) {\n await commitTransaction(req)\n }\n\n return result\n } catch (error: unknown) {\n await killTransaction(args.req)\n throw error\n }\n}\n"],"names":["status","httpStatus","executeAccess","combineQueries","validateQueryPaths","sanitizeWhereQuery","APIError","afterRead","deleteUserPreferences","deleteAssociatedFiles","appendNonTrashedFilter","checkDocumentLockStatus","commitTransaction","hasScheduledPublishEnabled","initTransaction","isErrorPublic","killTransaction","sanitizeSelect","deleteCollectionVersions","deleteScheduledPublishJobs","buildAfterOperation","buildBeforeOperation","deleteOperation","incomingArgs","args","shouldCommit","disableTransaction","req","collection","config","operation","overrideAccess","collectionConfig","depth","overrideLock","populate","fallbackLocale","locale","payload","select","incomingSelect","showHiddenFields","trash","where","BAD_REQUEST","accessResult","access","delete","fullWhere","enableTrash","fields","flattenedFields","forceSelect","docs","db","find","slug","errors","promises","map","doc","result","id","docShouldCommit","bulkOperationsSingleTransaction","collectionSlug","lockErrorMessage","hooks","beforeDelete","length","hook","context","overrideDelete","versions","deleteOne","returning","equals","draft","undefined","global","auth","afterDelete","error","isPublic","Error","push","message","awaitedDocs","promise","Promise","all","ids","filter","Boolean"],"mappings":"AAAA,SAASA,UAAUC,UAAU,QAAQ,cAAa;AAYlD,SAASC,aAAa,QAAQ,8BAA6B;AAC3D,SAASC,cAAc,QAAQ,mCAAkC;AACjE,SAASC,kBAAkB,QAAQ,uDAAsD;AACzF,SAASC,kBAAkB,QAAQ,uCAAsC;AACzE,SAASC,QAAQ,QAAQ,wBAAuB;AAChD,SAASC,SAAS,QAAQ,wCAAuC;AACjE,SAASC,qBAAqB,QA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AAO,CAACgB,EAAE,CAACU,+BAA+B,EAAE;YAClDuB,cAAc,EAAE;YAChB,KAAK,MAAMC,WAAW9B,SAAU;gBAC9B6B,YAAYF,IAAI,CAAC,MAAMG;YACzB;QACF,OAAO;YACLD,cAAc,MAAME,QAAQC,GAAG,CAAChC;QAClC;QAEA,wCAAwC;QACxC,qBAAqB;QACrB,wCAAwC;QAExC,MAAMlD,sBAAsB;YAC1BwB;YACA2D,KAAKtC,KAAKM,GAAG,CAAC,CAAC,EAAEG,EAAE,EAAE,GAAKA;YAC1BxB;YACAX;QACF;QAEA,IAAIkC,SAAS;YACXR,MAAMkC,YAAYK,MAAM,CAACC;YACzBpC;QACF;QAEA,wCAAwC;QACxC,8BAA8B;QAC9B,wCAAwC;QAExCI,SAAS,MAAMzC,oBAAoB;YACjCI;YACAI,YAAYI;YACZF,WAAW;YACXC;YACA8B;QACF;QAEA,IAAIpC,cAAc;YAChB,MAAMb,kBAAkBe;QAC1B;QAEA,OAAOkC;IACT,EAAE,OAAOqB,OAAgB;QACvB,MAAMlE,gBAAgBQ,KAAKG,GAAG;QAC9B,MAAMuD;IACR;AACF,EAAC"}
1
+ {"version":3,"sources":["../../../src/collections/operations/delete.ts"],"sourcesContent":["import { status as httpStatus } from 'http-status'\n\nimport type { AccessResult } from '../../config/types.js'\nimport type { CollectionSlug, FindOptions } from '../../index.js'\nimport type { PayloadRequest, PopulateType, SelectType, Where } from '../../types/index.js'\nimport type {\n BulkOperationResult,\n Collection,\n DataFromCollectionSlug,\n SelectFromCollectionSlug,\n} from '../config/types.js'\n\nimport { executeAccess } from '../../auth/executeAccess.js'\nimport { combineQueries } from '../../database/combineQueries.js'\nimport { validateQueryPaths } from '../../database/queryValidation/validateQueryPaths.js'\nimport { sanitizeWhereQuery } from '../../database/sanitizeWhereQuery.js'\nimport { APIError } from '../../errors/index.js'\nimport { afterRead } from '../../fields/hooks/afterRead/index.js'\nimport { deleteUserPreferences } from '../../preferences/deleteUserPreferences.js'\nimport { deleteAssociatedFiles } from '../../uploads/deleteAssociatedFiles.js'\nimport { appendNonTrashedFilter } from '../../utilities/appendNonTrashedFilter.js'\nimport { checkDocumentLockStatus } from '../../utilities/checkDocumentLockStatus.js'\nimport { commitTransaction } from '../../utilities/commitTransaction.js'\nimport { hasScheduledPublishEnabled } from '../../utilities/getVersionsConfig.js'\nimport { initTransaction } from '../../utilities/initTransaction.js'\nimport { isErrorPublic } from '../../utilities/isErrorPublic.js'\nimport { killTransaction } from '../../utilities/killTransaction.js'\nimport { sanitizeSelect } from '../../utilities/sanitizeSelect.js'\nimport { deleteCollectionVersions } from '../../versions/deleteCollectionVersions.js'\nimport { deleteScheduledPublishJobs } from '../../versions/deleteScheduledPublishJobs.js'\nimport { buildAfterOperation } from './utilities/buildAfterOperation.js'\nimport { buildBeforeOperation } from './utilities/buildBeforeOperation.js'\n\nexport type Arguments = {\n collection: Collection\n depth?: number\n disableTransaction?: boolean\n overrideAccess?: boolean\n overrideLock?: boolean\n populate?: PopulateType\n req: PayloadRequest\n showHiddenFields?: boolean\n trash?: boolean\n where: Where\n} & Pick<FindOptions<string, SelectType>, 'select'>\n\nexport const deleteOperation = async <\n TSlug extends CollectionSlug,\n TSelect extends SelectFromCollectionSlug<TSlug>,\n>(\n incomingArgs: Arguments,\n): Promise<BulkOperationResult<TSlug, TSelect>> => {\n let args = incomingArgs\n\n try {\n const shouldCommit = !args.disableTransaction && (await initTransaction(args.req))\n // /////////////////////////////////////\n // beforeOperation - Collection\n // /////////////////////////////////////\n\n args = await buildBeforeOperation({\n args,\n collection: args.collection.config,\n operation: 'delete',\n overrideAccess: args.overrideAccess!,\n })\n\n const {\n collection: { config: collectionConfig },\n depth,\n overrideAccess,\n overrideLock,\n populate,\n req: {\n fallbackLocale,\n locale,\n payload: { config },\n payload,\n },\n req,\n select: incomingSelect,\n showHiddenFields,\n trash = false,\n where,\n } = args\n\n if (!where) {\n throw new APIError(\"Missing 'where' query of documents to delete.\", httpStatus.BAD_REQUEST)\n }\n\n // /////////////////////////////////////\n // Access\n // /////////////////////////////////////\n\n let accessResult: AccessResult\n\n if (!overrideAccess) {\n accessResult = await executeAccess({ req }, collectionConfig.access.delete)\n }\n\n await validateQueryPaths({\n collectionConfig,\n overrideAccess: overrideAccess!,\n req,\n where,\n })\n\n let fullWhere = combineQueries(where, accessResult!)\n\n // Exclude trashed documents when trash: false\n fullWhere = appendNonTrashedFilter({\n enableTrash: collectionConfig.trash,\n trash,\n where: fullWhere,\n })\n\n sanitizeWhereQuery({ fields: collectionConfig.flattenedFields, payload, where: fullWhere })\n\n const select = sanitizeSelect({\n fields: collectionConfig.flattenedFields,\n forceSelect: collectionConfig.forceSelect,\n select: incomingSelect,\n })\n\n // /////////////////////////////////////\n // Retrieve documents\n // /////////////////////////////////////\n\n const { docs } = await payload.db.find<DataFromCollectionSlug<TSlug>>({\n collection: collectionConfig.slug,\n locale: locale!,\n req,\n select,\n where: fullWhere,\n })\n\n const errors: BulkOperationResult<TSlug, TSelect>['errors'] = []\n\n const promises = docs.map(async (doc) => {\n let result\n\n const { id } = doc\n\n try {\n // Each document gets its own transaction when singleTransaction is enabled\n let docShouldCommit = false\n if (req.payload.db.bulkOperationsSingleTransaction) {\n docShouldCommit = await initTransaction(req)\n }\n\n // /////////////////////////////////////\n // Handle potentially locked documents\n // /////////////////////////////////////\n\n await checkDocumentLockStatus({\n id,\n collectionSlug: collectionConfig.slug,\n lockErrorMessage: `Document with ID ${id} is currently locked and cannot be deleted.`,\n overrideLock,\n req,\n })\n\n // /////////////////////////////////////\n // beforeDelete - Collection\n // /////////////////////////////////////\n\n if (collectionConfig.hooks?.beforeDelete?.length) {\n for (const hook of collectionConfig.hooks.beforeDelete) {\n await hook({\n id,\n collection: collectionConfig,\n context: req.context,\n req,\n })\n }\n }\n\n await deleteAssociatedFiles({\n collectionConfig,\n config,\n doc,\n overrideDelete: true,\n req,\n })\n\n // /////////////////////////////////////\n // Delete versions\n // /////////////////////////////////////\n\n if (collectionConfig.versions) {\n await deleteCollectionVersions({\n id,\n slug: collectionConfig.slug,\n payload,\n req,\n })\n }\n\n // /////////////////////////////////////\n // Delete scheduled posts\n // /////////////////////////////////////\n if (hasScheduledPublishEnabled(collectionConfig)) {\n await deleteScheduledPublishJobs({\n id,\n slug: collectionConfig.slug,\n payload,\n req,\n })\n }\n\n // /////////////////////////////////////\n // Delete document\n // /////////////////////////////////////\n\n await payload.db.deleteOne({\n collection: collectionConfig.slug,\n req,\n returning: false,\n where: {\n id: {\n equals: id,\n },\n },\n })\n\n // /////////////////////////////////////\n // afterRead - Fields\n // /////////////////////////////////////\n\n result = await afterRead({\n collection: collectionConfig,\n context: req.context,\n depth: depth!,\n doc: result || doc,\n // @ts-expect-error - vestiges of when tsconfig was not strict. Feel free to improve\n draft: undefined,\n fallbackLocale: fallbackLocale!,\n global: null,\n locale: locale!,\n overrideAccess: overrideAccess!,\n populate,\n req,\n select,\n showHiddenFields: showHiddenFields!,\n })\n\n // /////////////////////////////////////\n // afterRead - Collection\n // /////////////////////////////////////\n\n if (collectionConfig.hooks?.afterRead?.length) {\n for (const hook of collectionConfig.hooks.afterRead) {\n result =\n (await hook({\n collection: collectionConfig,\n context: req.context,\n doc: result || doc,\n overrideAccess,\n req,\n })) || result\n }\n }\n\n // /////////////////////////////////////\n // afterDelete - Collection\n // /////////////////////////////////////\n\n if (collectionConfig.hooks?.afterDelete?.length) {\n for (const hook of collectionConfig.hooks.afterDelete) {\n result =\n (await hook({\n id,\n collection: collectionConfig,\n context: req.context,\n doc: result,\n req,\n })) || result\n }\n }\n\n // /////////////////////////////////////\n // 8. Return results\n // /////////////////////////////////////\n if (docShouldCommit) {\n await commitTransaction(req)\n }\n\n return result\n } catch (error) {\n const isPublic = error instanceof Error ? isErrorPublic(error, config) : false\n\n if (req.payload.db.bulkOperationsSingleTransaction) {\n await killTransaction(req)\n }\n errors.push({\n id: doc.id,\n isPublic,\n message: error instanceof Error ? error.message : 'Unknown error',\n })\n }\n return null\n })\n\n // Process sequentially when using single transaction mode to avoid shared state issues\n // Process in parallel when using one transaction for better performance\n let awaitedDocs\n if (req.payload.db.bulkOperationsSingleTransaction) {\n awaitedDocs = []\n for (const promise of promises) {\n awaitedDocs.push(await promise)\n }\n } else {\n awaitedDocs = await Promise.all(promises)\n }\n\n // /////////////////////////////////////\n // Delete Preferences\n // /////////////////////////////////////\n\n await deleteUserPreferences({\n collectionConfig,\n ids: docs.map(({ id }) => id),\n payload,\n req,\n })\n\n let result = {\n docs: awaitedDocs.filter(Boolean),\n errors,\n }\n\n // /////////////////////////////////////\n // afterOperation - Collection\n // /////////////////////////////////////\n\n result = await buildAfterOperation({\n args,\n collection: collectionConfig,\n operation: 'delete',\n overrideAccess,\n result,\n })\n\n if (shouldCommit) {\n await commitTransaction(req)\n }\n\n return result\n } catch (error: unknown) {\n await killTransaction(args.req)\n throw error\n }\n}\n"],"names":["status","httpStatus","executeAccess","combineQueries","validateQueryPaths","sanitizeWhereQuery","APIError","afterRead","deleteUserPreferences","deleteAssociatedFiles","appendNonTrashedFilter","checkDocumentLockStatus","commitTransaction","hasScheduledPublishEnabled","initTransaction","isErrorPublic","killTransaction","sanitizeSelect","deleteCollectionVersions","deleteScheduledPublishJobs","buildAfterOperation","buildBeforeOperation","deleteOperation","incomingArgs","args","shouldCommit","disableTransaction","req","collection","config","operation","overrideAccess","collectionConfig","depth","overrideLock","populate","fallbackLocale","locale","payload","select","incomingSelect","showHiddenFields","trash","where","BAD_REQUEST","accessResult","access","delete","fullWhere","enableTrash","fields","flattenedFields","forceSelect","docs","db","find","slug","errors","promises","map","doc","result","id","docShouldCommit","bulkOperationsSingleTransaction","collectionSlug","lockErrorMessage","hooks","beforeDelete","length","hook","context","overrideDelete","versions","deleteOne","returning","equals","draft","undefined","global","afterDelete","error","isPublic","Error","push","message","awaitedDocs","promise","Promise","all","ids","filter","Boolean"],"mappings":"AAAA,SAASA,UAAUC,UAAU,QAAQ,cAAa;AAYlD,SAASC,aAAa,QAAQ,8BAA6B;AAC3D,SAASC,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D,IAAIW,OAAO,CAACgB,EAAE,CAACU,+BAA+B,EAAE;YAClDsB,cAAc,EAAE;YAChB,KAAK,MAAMC,WAAW7B,SAAU;gBAC9B4B,YAAYF,IAAI,CAAC,MAAMG;YACzB;QACF,OAAO;YACLD,cAAc,MAAME,QAAQC,GAAG,CAAC/B;QAClC;QAEA,wCAAwC;QACxC,qBAAqB;QACrB,wCAAwC;QAExC,MAAMlD,sBAAsB;YAC1BwB;YACA0D,KAAKrC,KAAKM,GAAG,CAAC,CAAC,EAAEG,EAAE,EAAE,GAAKA;YAC1BxB;YACAX;QACF;QAEA,IAAIkC,SAAS;YACXR,MAAMiC,YAAYK,MAAM,CAACC;YACzBnC;QACF;QAEA,wCAAwC;QACxC,8BAA8B;QAC9B,wCAAwC;QAExCI,SAAS,MAAMzC,oBAAoB;YACjCI;YACAI,YAAYI;YACZF,WAAW;YACXC;YACA8B;QACF;QAEA,IAAIpC,cAAc;YAChB,MAAMb,kBAAkBe;QAC1B;QAEA,OAAOkC;IACT,EAAE,OAAOoB,OAAgB;QACvB,MAAMjE,gBAAgBQ,KAAKG,GAAG;QAC9B,MAAMsD;IACR;AACF,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"deleteByID.d.ts","sourceRoot":"","sources":["../../../src/collections/operations/deleteByID.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AACjE,OAAO,KAAK,EACV,cAAc,EACd,YAAY,EACZ,UAAU,EACV,6BAA6B,EAC9B,MAAM,sBAAsB,CAAA;AAC7B,OAAO,KAAK,EAAE,UAAU,EAA0B,MAAM,oBAAoB,CAAA;AAqB5E,MAAM,MAAM,SAAS,CAAC,KAAK,SAAS,cAAc,EAAE,OAAO,SAAS,UAAU,IAAI;IAChF,UAAU,EAAE,UAAU,CAAA;IACtB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,kBAAkB,CAAC,EAAE,OAAO,CAAA;IAC5B,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,CAAA;IAC1B,KAAK,CAAC,EAAE,OAAO,CAAA;CAChB,GAAG,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,OAAO,CAAC,EAAE,QAAQ,CAAC,CAAA;AAE/C,eAAO,MAAM,mBAAmB,GAAU,KAAK,SAAS,cAAc,EAAE,OAAO,SAAS,UAAU,gBAClF,SAAS,CAAC,KAAK,EAAE,OAAO,CAAC,KACtC,OAAO,CAAC,6BAA6B,CAAC,KAAK,EAAE,OAAO,CAAC,CA+OvD,CAAA"}
@@ -135,15 +135,6 @@ export const deleteByIDOperation = async (incomingArgs)=>{
135
135
  }
136
136
  });
137
137
  // /////////////////////////////////////
138
- // Add collection property for auth collections
139
- // /////////////////////////////////////
140
- if (collectionConfig.auth) {
141
- result = {
142
- ...result,
143
- collection: collectionConfig.slug
144
- };
145
- }
146
- // /////////////////////////////////////
147
138
  // Delete Preferences
148
139
  // /////////////////////////////////////
149
140
  await deleteUserPreferences({
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/collections/operations/deleteByID.ts"],"sourcesContent":["import type { CollectionSlug, FindOptions } from '../../index.js'\nimport type {\n PayloadRequest,\n PopulateType,\n SelectType,\n TransformCollectionWithSelect,\n} from '../../types/index.js'\nimport type { Collection, DataFromCollectionSlug } from '../config/types.js'\n\nimport { executeAccess } from '../../auth/executeAccess.js'\nimport { hasWhereAccessResult } from '../../auth/types.js'\nimport { combineQueries } from '../../database/combineQueries.js'\nimport { Forbidden, NotFound } from '../../errors/index.js'\nimport { afterRead } from '../../fields/hooks/afterRead/index.js'\nimport { deleteUserPreferences } from '../../preferences/deleteUserPreferences.js'\nimport { deleteAssociatedFiles } from '../../uploads/deleteAssociatedFiles.js'\nimport { appendNonTrashedFilter } from '../../utilities/appendNonTrashedFilter.js'\nimport { checkDocumentLockStatus } from '../../utilities/checkDocumentLockStatus.js'\nimport { commitTransaction } from '../../utilities/commitTransaction.js'\nimport { hasScheduledPublishEnabled } from '../../utilities/getVersionsConfig.js'\nimport { initTransaction } from '../../utilities/initTransaction.js'\nimport { killTransaction } from '../../utilities/killTransaction.js'\nimport { sanitizeSelect } from '../../utilities/sanitizeSelect.js'\nimport { deleteCollectionVersions } from '../../versions/deleteCollectionVersions.js'\nimport { deleteScheduledPublishJobs } from '../../versions/deleteScheduledPublishJobs.js'\nimport { buildAfterOperation } from './utilities/buildAfterOperation.js'\nimport { buildBeforeOperation } from './utilities/buildBeforeOperation.js'\n\nexport type Arguments<TSlug extends CollectionSlug, TSelect extends SelectType> = {\n collection: Collection\n depth?: number\n disableTransaction?: boolean\n id: number | string\n overrideAccess?: boolean\n overrideLock?: boolean\n populate?: PopulateType\n req: PayloadRequest\n showHiddenFields?: boolean\n trash?: boolean\n} & Pick<FindOptions<TSlug, TSelect>, 'select'>\n\nexport const deleteByIDOperation = async <TSlug extends CollectionSlug, TSelect extends SelectType>(\n incomingArgs: Arguments<TSlug, TSelect>,\n): Promise<TransformCollectionWithSelect<TSlug, TSelect>> => {\n let args = incomingArgs\n\n try {\n const shouldCommit = !args.disableTransaction && (await initTransaction(args.req))\n\n // /////////////////////////////////////\n // beforeOperation - Collection\n // /////////////////////////////////////\n\n args = await buildBeforeOperation({\n args,\n collection: args.collection.config,\n operation: 'delete',\n overrideAccess: args.overrideAccess!,\n })\n\n const {\n id,\n collection: { config: collectionConfig },\n depth,\n overrideAccess,\n overrideLock,\n populate,\n req: {\n fallbackLocale,\n locale,\n payload: { config },\n payload,\n },\n req,\n select: incomingSelect,\n showHiddenFields,\n trash = false,\n } = args\n\n // /////////////////////////////////////\n // Access\n // /////////////////////////////////////\n\n const accessResults = !overrideAccess\n ? await executeAccess({ id, req }, collectionConfig.access.delete)\n : true\n const hasWhereAccess = hasWhereAccessResult(accessResults)\n\n // /////////////////////////////////////\n // beforeDelete - Collection\n // /////////////////////////////////////\n\n if (collectionConfig.hooks?.beforeDelete?.length) {\n for (const hook of collectionConfig.hooks.beforeDelete) {\n await hook({\n id,\n collection: collectionConfig,\n context: req.context,\n req,\n })\n }\n }\n\n // /////////////////////////////////////\n // Retrieve document\n // /////////////////////////////////////\n\n let where = combineQueries({ id: { equals: id } }, accessResults)\n\n // Exclude trashed documents when trash: false\n where = appendNonTrashedFilter({\n enableTrash: collectionConfig.trash,\n trash,\n where,\n })\n\n const docToDelete = await req.payload.db.findOne({\n collection: collectionConfig.slug,\n locale: req.locale!,\n req,\n where,\n })\n\n if (!docToDelete && !hasWhereAccess) {\n throw new NotFound(req.t)\n }\n if (!docToDelete && hasWhereAccess) {\n throw new Forbidden(req.t)\n }\n\n // /////////////////////////////////////\n // Handle potentially locked documents\n // /////////////////////////////////////\n\n await checkDocumentLockStatus({\n id,\n collectionSlug: collectionConfig.slug,\n lockErrorMessage: `Document with ID ${id} is currently locked and cannot be deleted.`,\n overrideLock,\n req,\n })\n\n await deleteAssociatedFiles({\n collectionConfig,\n config,\n doc: docToDelete!,\n overrideDelete: true,\n req,\n })\n\n // /////////////////////////////////////\n // Delete versions\n // /////////////////////////////////////\n\n if (collectionConfig.versions) {\n await deleteCollectionVersions({\n id,\n slug: collectionConfig.slug,\n payload,\n req,\n })\n }\n\n // /////////////////////////////////////\n // Delete scheduled posts\n // /////////////////////////////////////\n if (hasScheduledPublishEnabled(collectionConfig)) {\n await deleteScheduledPublishJobs({\n id,\n slug: collectionConfig.slug,\n payload,\n req,\n })\n }\n\n const select = sanitizeSelect({\n fields: collectionConfig.flattenedFields,\n forceSelect: collectionConfig.forceSelect,\n select: incomingSelect,\n })\n\n // /////////////////////////////////////\n // Delete document\n // /////////////////////////////////////\n\n let result: DataFromCollectionSlug<TSlug> = await req.payload.db.deleteOne({\n collection: collectionConfig.slug,\n req,\n select,\n where: { id: { equals: id } },\n })\n\n // /////////////////////////////////////\n // Add collection property for auth collections\n // /////////////////////////////////////\n\n if (collectionConfig.auth) {\n result = { ...result, collection: collectionConfig.slug }\n }\n\n // /////////////////////////////////////\n // Delete Preferences\n // /////////////////////////////////////\n\n await deleteUserPreferences({\n collectionConfig,\n ids: [id],\n payload,\n req,\n })\n\n // /////////////////////////////////////\n // afterRead - Fields\n // /////////////////////////////////////\n\n result = await afterRead({\n collection: collectionConfig,\n context: req.context,\n depth: depth!,\n doc: result,\n draft: undefined!,\n fallbackLocale: fallbackLocale!,\n global: null,\n locale: locale!,\n overrideAccess: overrideAccess!,\n populate,\n req,\n select,\n showHiddenFields: showHiddenFields!,\n })\n\n // /////////////////////////////////////\n // afterRead - Collection\n // /////////////////////////////////////\n\n if (collectionConfig.hooks?.afterRead?.length) {\n for (const hook of collectionConfig.hooks.afterRead) {\n result =\n (await hook({\n collection: collectionConfig,\n context: req.context,\n doc: result,\n overrideAccess,\n req,\n })) || result\n }\n }\n\n // /////////////////////////////////////\n // afterDelete - Collection\n // /////////////////////////////////////\n\n if (collectionConfig.hooks?.afterDelete?.length) {\n for (const hook of collectionConfig.hooks.afterDelete) {\n result =\n (await hook({\n id,\n collection: collectionConfig,\n context: req.context,\n doc: result,\n req,\n })) || result\n }\n }\n\n // /////////////////////////////////////\n // afterOperation - Collection\n // /////////////////////////////////////\n\n result = await buildAfterOperation({\n args,\n collection: collectionConfig,\n operation: 'deleteByID',\n overrideAccess,\n result,\n })\n\n // /////////////////////////////////////\n // 8. Return results\n // /////////////////////////////////////\n\n if (shouldCommit) {\n await commitTransaction(req)\n }\n\n return result as TransformCollectionWithSelect<TSlug, TSelect>\n } catch (error: unknown) {\n await killTransaction(args.req)\n throw error\n }\n}\n"],"names":["executeAccess","hasWhereAccessResult","combineQueries","Forbidden","NotFound","afterRead","deleteUserPreferences","deleteAssociatedFiles","appendNonTrashedFilter","checkDocumentLockStatus","commitTransaction","hasScheduledPublishEnabled","initTransaction","killTransaction","sanitizeSelect","deleteCollectionVersions","deleteScheduledPublishJobs","buildAfterOperation","buildBeforeOperation","deleteByIDOperation","incomingArgs","args","shouldCommit","disableTransaction","req","collection","config","operation","overrideAccess","id","collectionConfig","depth","overrideLock","populate","fallbackLocale","locale","payload","select","incomingSelect","showHiddenFields","trash","accessResults","access","delete","hasWhereAccess","hooks","beforeDelete","length","hook","context","where","equals","enableTrash","docToDelete","db","findOne","slug","t","collectionSlug","lockErrorMessage","doc","overrideDelete","versions","fields","flattenedFields","forceSelect","result","deleteOne","auth","ids","draft","undefined","global","afterDelete","error"],"mappings":"AASA,SAASA,aAAa,QAAQ,8BAA6B;AAC3D,SAASC,oBAAoB,QAAQ,sBAAqB;AAC1D,SAASC,cAAc,QAAQ,mCAAkC;AACjE,SAASC,SAAS,EAAEC,QAAQ,QAAQ,wBAAuB;AAC3D,SAASC,SAAS,QAAQ,wCAAuC;AACjE,SAASC,qBAAqB,QAAQ,6CAA4C;AAClF,SAASC,qBAAqB,QAAQ,yCAAwC;AAC9E,SAASC,sBAAsB,QAAQ,4CAA2C;AAClF,SAASC,uBAAuB,QAAQ,6CAA4C;AACpF,SAASC,iBAAiB,QAAQ,uCAAsC;AACxE,SAASC,0BAA0B,QAAQ,uCAAsC;AACjF,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,cAAc,QAAQ,oCAAmC;AAClE,SAASC,wBAAwB,QAAQ,6CAA4C;AACrF,SAASC,0BAA0B,QAAQ,+CAA8C;AACzF,SAASC,mBAAmB,QAAQ,qCAAoC;AACxE,SAASC,oBAAoB,QAAQ,sCAAqC;AAe1E,OAAO,MAAMC,sBAAsB,OACjCC;IAEA,IAAIC,OAAOD;IAEX,IAAI;QACF,MAAME,eAAe,CAACD,KAAKE,kBAAkB,IAAK,MAAMX,gBAAgBS,KAAKG,GAAG;QAEhF,wCAAwC;QACxC,+BAA+B;QAC/B,wCAAwC;QAExCH,OAAO,MAAMH,qBAAqB;YAChCG;YACAI,YAAYJ,KAAKI,UAAU,CAACC,MAAM;YAClCC,WAAW;YACXC,gBAAgBP,KAAKO,cAAc;QACrC;QAEA,MAAM,EACJC,EAAE,EACFJ,YAAY,EAAEC,QAAQI,gBAAgB,EAAE,EACxCC,KAAK,EACLH,cAAc,E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wC;QAExC0C,SAAS,MAAM7D,UAAU;YACvBoB,YAAYK;YACZmB,SAASzB,IAAIyB,OAAO;YACpBlB,OAAOA;YACP6B,KAAKM;YACLI,OAAOC;YACPrC,gBAAgBA;YAChBsC,QAAQ;YACRrC,QAAQA;YACRP,gBAAgBA;YAChBK;YACAT;YACAa;YACAE,kBAAkBA;QACpB;QAEA,wCAAwC;QACxC,yBAAyB;QACzB,wCAAwC;QAExC,IAAIT,iBAAiBe,KAAK,EAAExC,WAAW0C,QAAQ;YAC7C,KAAK,MAAMC,QAAQlB,iBAAiBe,KAAK,CAACxC,SAAS,CAAE;gBACnD6D,SACE,AAAC,MAAMlB,KAAK;oBACVvB,YAAYK;oBACZmB,SAASzB,IAAIyB,OAAO;oBACpBW,KAAKM;oBACLtC;oBACAJ;gBACF,MAAO0C;YACX;QACF;QAEA,wCAAwC;QACxC,2BAA2B;QAC3B,wCAAwC;QAExC,IAAIpC,iBAAiBe,KAAK,EAAE4B,aAAa1B,QAAQ;YAC/C,KAAK,MAAMC,QAAQlB,iBAAiBe,KAAK,CAAC4B,WAAW,CAAE;gBACrDP,SACE,AAAC,MAAMlB,KAAK;oBACVnB;oBACAJ,YAAYK;oBACZmB,SAASzB,IAAIyB,OAAO;oBACpBW,KAAKM;oBACL1C;gBACF,MAAO0C;YACX;QACF;QAEA,wCAAwC;QACxC,8BAA8B;QAC9B,wCAAwC;QAExCA,SAAS,MAAMjD,oBAAoB;YACjCI;YACAI,YAAYK;YACZH,WAAW;YACXC;YACAsC;QACF;QAEA,wCAAwC;QACxC,oBAAoB;QACpB,wCAAwC;QAExC,IAAI5C,cAAc;YAChB,MAAMZ,kBAAkBc;QAC1B;QAEA,OAAO0C;IACT,EAAE,OAAOQ,OAAgB;QACvB,MAAM7D,gBAAgBQ,KAAKG,GAAG;QAC9B,MAAMkD;IACR;AACF,EAAC"}
1
+ {"version":3,"sources":["../../../src/collections/operations/deleteByID.ts"],"sourcesContent":["import type { CollectionSlug, FindOptions } from '../../index.js'\nimport type {\n PayloadRequest,\n PopulateType,\n SelectType,\n TransformCollectionWithSelect,\n} from '../../types/index.js'\nimport type { Collection, DataFromCollectionSlug } from '../config/types.js'\n\nimport { executeAccess } from '../../auth/executeAccess.js'\nimport { hasWhereAccessResult } from '../../auth/types.js'\nimport { combineQueries } from '../../database/combineQueries.js'\nimport { Forbidden, NotFound } from '../../errors/index.js'\nimport { afterRead } from '../../fields/hooks/afterRead/index.js'\nimport { deleteUserPreferences } from '../../preferences/deleteUserPreferences.js'\nimport { deleteAssociatedFiles } from '../../uploads/deleteAssociatedFiles.js'\nimport { appendNonTrashedFilter } from '../../utilities/appendNonTrashedFilter.js'\nimport { checkDocumentLockStatus } from '../../utilities/checkDocumentLockStatus.js'\nimport { commitTransaction } from '../../utilities/commitTransaction.js'\nimport { hasScheduledPublishEnabled } from '../../utilities/getVersionsConfig.js'\nimport { initTransaction } from '../../utilities/initTransaction.js'\nimport { killTransaction } from '../../utilities/killTransaction.js'\nimport { sanitizeSelect } from '../../utilities/sanitizeSelect.js'\nimport { deleteCollectionVersions } from '../../versions/deleteCollectionVersions.js'\nimport { deleteScheduledPublishJobs } from '../../versions/deleteScheduledPublishJobs.js'\nimport { buildAfterOperation } from './utilities/buildAfterOperation.js'\nimport { buildBeforeOperation } from './utilities/buildBeforeOperation.js'\n\nexport type Arguments<TSlug extends CollectionSlug, TSelect extends SelectType> = {\n collection: Collection\n depth?: number\n disableTransaction?: boolean\n id: number | string\n overrideAccess?: boolean\n overrideLock?: boolean\n populate?: PopulateType\n req: PayloadRequest\n showHiddenFields?: boolean\n trash?: boolean\n} & Pick<FindOptions<TSlug, TSelect>, 'select'>\n\nexport const deleteByIDOperation = async <TSlug extends CollectionSlug, TSelect extends SelectType>(\n incomingArgs: Arguments<TSlug, TSelect>,\n): Promise<TransformCollectionWithSelect<TSlug, TSelect>> => {\n let args = incomingArgs\n\n try {\n const shouldCommit = !args.disableTransaction && (await initTransaction(args.req))\n\n // /////////////////////////////////////\n // beforeOperation - Collection\n // /////////////////////////////////////\n\n args = await buildBeforeOperation({\n args,\n collection: args.collection.config,\n operation: 'delete',\n overrideAccess: args.overrideAccess!,\n })\n\n const {\n id,\n collection: { config: collectionConfig },\n depth,\n overrideAccess,\n overrideLock,\n populate,\n req: {\n fallbackLocale,\n locale,\n payload: { config },\n payload,\n },\n req,\n select: incomingSelect,\n showHiddenFields,\n trash = false,\n } = args\n\n // /////////////////////////////////////\n // Access\n // /////////////////////////////////////\n\n const accessResults = !overrideAccess\n ? await executeAccess({ id, req }, collectionConfig.access.delete)\n : true\n const hasWhereAccess = hasWhereAccessResult(accessResults)\n\n // /////////////////////////////////////\n // beforeDelete - Collection\n // /////////////////////////////////////\n\n if (collectionConfig.hooks?.beforeDelete?.length) {\n for (const hook of collectionConfig.hooks.beforeDelete) {\n await hook({\n id,\n collection: collectionConfig,\n context: req.context,\n req,\n })\n }\n }\n\n // /////////////////////////////////////\n // Retrieve document\n // /////////////////////////////////////\n\n let where = combineQueries({ id: { equals: id } }, accessResults)\n\n // Exclude trashed documents when trash: false\n where = appendNonTrashedFilter({\n enableTrash: collectionConfig.trash,\n trash,\n where,\n })\n\n const docToDelete = await req.payload.db.findOne({\n collection: collectionConfig.slug,\n locale: req.locale!,\n req,\n where,\n })\n\n if (!docToDelete && !hasWhereAccess) {\n throw new NotFound(req.t)\n }\n if (!docToDelete && hasWhereAccess) {\n throw new Forbidden(req.t)\n }\n\n // /////////////////////////////////////\n // Handle potentially locked documents\n // /////////////////////////////////////\n\n await checkDocumentLockStatus({\n id,\n collectionSlug: collectionConfig.slug,\n lockErrorMessage: `Document with ID ${id} is currently locked and cannot be deleted.`,\n overrideLock,\n req,\n })\n\n await deleteAssociatedFiles({\n collectionConfig,\n config,\n doc: docToDelete!,\n overrideDelete: true,\n req,\n })\n\n // /////////////////////////////////////\n // Delete versions\n // /////////////////////////////////////\n\n if (collectionConfig.versions) {\n await deleteCollectionVersions({\n id,\n slug: collectionConfig.slug,\n payload,\n req,\n })\n }\n\n // /////////////////////////////////////\n // Delete scheduled posts\n // /////////////////////////////////////\n if (hasScheduledPublishEnabled(collectionConfig)) {\n await deleteScheduledPublishJobs({\n id,\n slug: collectionConfig.slug,\n payload,\n req,\n })\n }\n\n const select = sanitizeSelect({\n fields: collectionConfig.flattenedFields,\n forceSelect: collectionConfig.forceSelect,\n select: incomingSelect,\n })\n\n // /////////////////////////////////////\n // Delete document\n // /////////////////////////////////////\n\n let result: DataFromCollectionSlug<TSlug> = await req.payload.db.deleteOne({\n collection: collectionConfig.slug,\n req,\n select,\n where: { id: { equals: id } },\n })\n\n // /////////////////////////////////////\n // Delete Preferences\n // /////////////////////////////////////\n\n await deleteUserPreferences({\n collectionConfig,\n ids: [id],\n payload,\n req,\n })\n\n // /////////////////////////////////////\n // afterRead - Fields\n // /////////////////////////////////////\n\n result = await afterRead({\n collection: collectionConfig,\n context: req.context,\n depth: depth!,\n doc: result,\n draft: undefined!,\n fallbackLocale: fallbackLocale!,\n global: null,\n locale: locale!,\n overrideAccess: overrideAccess!,\n populate,\n req,\n select,\n showHiddenFields: showHiddenFields!,\n })\n\n // /////////////////////////////////////\n // afterRead - Collection\n // /////////////////////////////////////\n\n if (collectionConfig.hooks?.afterRead?.length) {\n for (const hook of collectionConfig.hooks.afterRead) {\n result =\n (await hook({\n collection: collectionConfig,\n context: req.context,\n doc: result,\n overrideAccess,\n req,\n })) || result\n }\n }\n\n // /////////////////////////////////////\n // afterDelete - Collection\n // /////////////////////////////////////\n\n if (collectionConfig.hooks?.afterDelete?.length) {\n for (const hook of collectionConfig.hooks.afterDelete) {\n result =\n (await hook({\n id,\n collection: collectionConfig,\n context: req.context,\n doc: result,\n req,\n })) || result\n }\n }\n\n // /////////////////////////////////////\n // afterOperation - Collection\n // /////////////////////////////////////\n\n result = await buildAfterOperation({\n args,\n collection: collectionConfig,\n operation: 'deleteByID',\n overrideAccess,\n result,\n })\n\n // /////////////////////////////////////\n // 8. Return results\n // /////////////////////////////////////\n\n if (shouldCommit) {\n await commitTransaction(req)\n }\n\n return result as TransformCollectionWithSelect<TSlug, TSelect>\n } catch (error: unknown) {\n await killTransaction(args.req)\n throw error\n }\n}\n"],"names":["executeAccess","hasWhereAccessResult","combineQueries","Forbidden","NotFound","afterRead","deleteUserPreferences","deleteAssociatedFiles","appendNonTrashedFilter","checkDocumentLockStatus","commitTransaction","hasScheduledPublishEnabled","initTransaction","killTransaction","sanitizeSelect","deleteCollectionVersions","deleteScheduledPublishJobs","buildAfterOperation","buildBeforeOperation","deleteByIDOperation","incomingArgs","args","shouldCommit","disableTransaction","req","collection","config","operation","overrideAccess","id","collectionConfig","depth","overrideLock","populate","fallbackLocale","locale","payload","select","incomingSelect","showHiddenFields","trash","accessResults","access","delete","hasWhereAccess","hooks","beforeDelete","length","hook","context","where","equals","enableTrash","docToDelete","db","findOne","slug","t","collectionSlug","lockErrorMessage","doc","overrideDelete","versions","fields","flattenedFields","forceSelect","result","deleteOne","ids","draft","undefined","global","afterDelete","error"],"mappings":"AASA,SAASA,aAAa,QAAQ,8BAA6B;AAC3D,SAASC,oBAAoB,QAAQ,sBAAqB;AAC1D,SAASC,cAAc,QAAQ,mCAAkC;AACjE,SAASC,SAAS,EAAEC,QAAQ,QAAQ,wBAAuB;AAC3D,SAASC,SAAS,QAAQ,wCAAuC;AACjE,SAASC,qBAAqB,QAAQ,6CAA4C;AAClF,SAASC,qBAAqB,QAAQ,yCAAwC;AAC9E,SAASC,sBAAsB,QAAQ,4CAA2C;AAClF,SAASC,uBAAuB,QAAQ,6CAA4C;AACpF,SAASC,iBAAiB,QAAQ,uCAAsC;AACxE,SAASC,0BAA0B,QAAQ,uCAAsC;AACjF,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,cAAc,QAAQ,oCAAmC;AAClE,SAASC,wBAAwB,QAAQ,6CAA4C;AACrF,SAASC,0BAA0B,QAAQ,+CAA8C;AACzF,SAASC,mBAAmB,QAAQ,qCAA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