payload 3.0.0-beta.2 → 3.0.0-beta.21
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.
- package/dist/admin/RichText.d.ts +18 -10
- package/dist/admin/RichText.d.ts.map +1 -1
- package/dist/admin/RichText.js.map +1 -1
- package/dist/admin/elements/PreviewButton.d.ts +2 -1
- package/dist/admin/elements/PreviewButton.d.ts.map +1 -1
- package/dist/admin/elements/PreviewButton.js.map +1 -1
- package/dist/admin/elements/PublishButton.d.ts +2 -1
- package/dist/admin/elements/PublishButton.d.ts.map +1 -1
- package/dist/admin/elements/PublishButton.js.map +1 -1
- package/dist/admin/elements/SaveButton.d.ts +2 -1
- package/dist/admin/elements/SaveButton.d.ts.map +1 -1
- package/dist/admin/elements/SaveButton.js.map +1 -1
- package/dist/admin/elements/SaveDraftButton.d.ts +2 -1
- package/dist/admin/elements/SaveDraftButton.d.ts.map +1 -1
- package/dist/admin/elements/SaveDraftButton.js.map +1 -1
- package/dist/admin/elements/Tab.d.ts +3 -0
- package/dist/admin/elements/Tab.d.ts.map +1 -1
- package/dist/admin/elements/Tab.js.map +1 -1
- package/dist/admin/elements/WithServerSideProps.d.ts +5 -0
- package/dist/admin/elements/WithServerSideProps.d.ts.map +1 -0
- package/dist/admin/elements/WithServerSideProps.js +3 -0
- package/dist/admin/elements/WithServerSideProps.js.map +1 -0
- package/dist/admin/forms/FieldDescription.d.ts +4 -2
- package/dist/admin/forms/FieldDescription.d.ts.map +1 -1
- package/dist/admin/forms/FieldDescription.js.map +1 -1
- package/dist/admin/forms/RowLabel.d.ts +2 -1
- package/dist/admin/forms/RowLabel.d.ts.map +1 -1
- package/dist/admin/forms/RowLabel.js.map +1 -1
- package/dist/admin/types.d.ts +2 -1
- package/dist/admin/types.d.ts.map +1 -1
- package/dist/admin/types.js.map +1 -1
- package/dist/admin/views/types.d.ts +2 -2
- package/dist/admin/views/types.d.ts.map +1 -1
- package/dist/admin/views/types.js.map +1 -1
- package/dist/auth/baseFields/apiKey.d.ts.map +1 -1
- package/dist/auth/baseFields/apiKey.js +6 -4
- package/dist/auth/baseFields/apiKey.js.map +1 -1
- package/dist/auth/cookies.d.ts +16 -4
- package/dist/auth/cookies.d.ts.map +1 -1
- package/dist/auth/cookies.js +45 -14
- package/dist/auth/cookies.js.map +1 -1
- package/dist/auth/defaultAccess.d.ts +2 -2
- package/dist/auth/defaultAccess.d.ts.map +1 -1
- package/dist/auth/defaultAccess.js.map +1 -1
- package/dist/auth/executeAccess.d.ts +2 -2
- package/dist/auth/executeAccess.d.ts.map +1 -1
- package/dist/auth/executeAccess.js.map +1 -1
- package/dist/auth/executeAuthStrategies.d.ts +3 -2
- package/dist/auth/executeAuthStrategies.d.ts.map +1 -1
- package/dist/auth/executeAuthStrategies.js.map +1 -1
- package/dist/auth/getAccessResults.d.ts +2 -2
- package/dist/auth/getAccessResults.d.ts.map +1 -1
- package/dist/auth/getAccessResults.js +1 -1
- package/dist/auth/getAccessResults.js.map +1 -1
- package/dist/auth/getFieldsToSign.d.ts +2 -2
- package/dist/auth/getFieldsToSign.d.ts.map +1 -1
- package/dist/auth/getFieldsToSign.js.map +1 -1
- package/dist/auth/operations/access.d.ts +2 -2
- package/dist/auth/operations/access.d.ts.map +1 -1
- package/dist/auth/operations/access.js.map +1 -1
- package/dist/auth/operations/auth.d.ts +5 -4
- package/dist/auth/operations/auth.d.ts.map +1 -1
- package/dist/auth/operations/auth.js.map +1 -1
- package/dist/auth/operations/forgotPassword.d.ts +2 -2
- package/dist/auth/operations/forgotPassword.d.ts.map +1 -1
- package/dist/auth/operations/forgotPassword.js +6 -5
- package/dist/auth/operations/forgotPassword.js.map +1 -1
- package/dist/auth/operations/init.d.ts +2 -2
- package/dist/auth/operations/init.d.ts.map +1 -1
- package/dist/auth/operations/init.js.map +1 -1
- package/dist/auth/operations/local/auth.js.map +1 -1
- package/dist/auth/operations/local/forgotPassword.d.ts +2 -2
- package/dist/auth/operations/local/forgotPassword.d.ts.map +1 -1
- package/dist/auth/operations/local/forgotPassword.js.map +1 -1
- package/dist/auth/operations/local/login.d.ts +2 -2
- package/dist/auth/operations/local/login.d.ts.map +1 -1
- package/dist/auth/operations/local/login.js.map +1 -1
- package/dist/auth/operations/local/resetPassword.d.ts +2 -2
- package/dist/auth/operations/local/resetPassword.d.ts.map +1 -1
- package/dist/auth/operations/local/resetPassword.js.map +1 -1
- package/dist/auth/operations/local/unlock.d.ts +2 -2
- package/dist/auth/operations/local/unlock.d.ts.map +1 -1
- package/dist/auth/operations/local/unlock.js.map +1 -1
- package/dist/auth/operations/local/verifyEmail.d.ts +2 -2
- package/dist/auth/operations/local/verifyEmail.d.ts.map +1 -1
- package/dist/auth/operations/local/verifyEmail.js.map +1 -1
- package/dist/auth/operations/login.d.ts +2 -2
- package/dist/auth/operations/login.d.ts.map +1 -1
- package/dist/auth/operations/login.js +17 -1
- package/dist/auth/operations/login.js.map +1 -1
- package/dist/auth/operations/logout.d.ts +2 -2
- package/dist/auth/operations/logout.d.ts.map +1 -1
- package/dist/auth/operations/logout.js.map +1 -1
- package/dist/auth/operations/me.d.ts +2 -2
- package/dist/auth/operations/me.d.ts.map +1 -1
- package/dist/auth/operations/me.js.map +1 -1
- package/dist/auth/operations/refresh.d.ts +2 -2
- package/dist/auth/operations/refresh.d.ts.map +1 -1
- package/dist/auth/operations/refresh.js.map +1 -1
- package/dist/auth/operations/registerFirstUser.d.ts +2 -2
- package/dist/auth/operations/registerFirstUser.d.ts.map +1 -1
- package/dist/auth/operations/registerFirstUser.js.map +1 -1
- package/dist/auth/operations/resetPassword.d.ts +2 -2
- package/dist/auth/operations/resetPassword.d.ts.map +1 -1
- package/dist/auth/operations/resetPassword.js.map +1 -1
- package/dist/auth/operations/unlock.d.ts +2 -2
- package/dist/auth/operations/unlock.d.ts.map +1 -1
- package/dist/auth/operations/unlock.js.map +1 -1
- package/dist/auth/operations/verifyEmail.d.ts +2 -2
- package/dist/auth/operations/verifyEmail.d.ts.map +1 -1
- package/dist/auth/operations/verifyEmail.js.map +1 -1
- package/dist/auth/sendVerificationEmail.d.ts +7 -8
- package/dist/auth/sendVerificationEmail.d.ts.map +1 -1
- package/dist/auth/sendVerificationEmail.js +7 -7
- package/dist/auth/sendVerificationEmail.js.map +1 -1
- package/dist/auth/strategies/local/incrementLoginAttempts.d.ts +2 -2
- package/dist/auth/strategies/local/incrementLoginAttempts.d.ts.map +1 -1
- package/dist/auth/strategies/local/incrementLoginAttempts.js.map +1 -1
- package/dist/auth/strategies/local/register.d.ts +2 -2
- package/dist/auth/strategies/local/register.d.ts.map +1 -1
- package/dist/auth/strategies/local/register.js.map +1 -1
- package/dist/auth/strategies/local/resetLoginAttempts.d.ts +2 -2
- package/dist/auth/strategies/local/resetLoginAttempts.d.ts.map +1 -1
- package/dist/auth/strategies/local/resetLoginAttempts.js.map +1 -1
- package/dist/auth/types.d.ts +5 -5
- package/dist/auth/types.d.ts.map +1 -1
- package/dist/auth/types.js.map +1 -1
- package/dist/bin/loader/index.d.ts.map +1 -1
- package/dist/bin/loader/index.js +6 -1
- package/dist/bin/loader/index.js.map +1 -1
- package/dist/bin/loader/resolveOriginalPath.d.ts +10 -0
- package/dist/bin/loader/resolveOriginalPath.d.ts.map +1 -0
- package/dist/bin/loader/resolveOriginalPath.js +32 -0
- package/dist/bin/loader/resolveOriginalPath.js.map +1 -0
- package/dist/collections/config/client.d.ts +17 -13
- package/dist/collections/config/client.d.ts.map +1 -1
- package/dist/collections/config/client.js +3 -1
- package/dist/collections/config/client.js.map +1 -1
- package/dist/collections/config/defaults.d.ts +6 -5
- package/dist/collections/config/defaults.d.ts.map +1 -1
- package/dist/collections/config/defaults.js +1 -0
- package/dist/collections/config/defaults.js.map +1 -1
- package/dist/collections/config/sanitize.d.ts +2 -3
- package/dist/collections/config/sanitize.d.ts.map +1 -1
- package/dist/collections/config/sanitize.js +7 -4
- package/dist/collections/config/sanitize.js.map +1 -1
- package/dist/collections/config/schema.d.ts.map +1 -1
- package/dist/collections/config/schema.js +3 -0
- package/dist/collections/config/schema.js.map +1 -1
- package/dist/collections/config/types.d.ts +33 -23
- package/dist/collections/config/types.d.ts.map +1 -1
- package/dist/collections/config/types.js.map +1 -1
- package/dist/collections/dataloader.d.ts.map +1 -1
- package/dist/collections/dataloader.js +4 -6
- package/dist/collections/dataloader.js.map +1 -1
- package/dist/collections/operations/count.d.ts +13 -0
- package/dist/collections/operations/count.d.ts.map +1 -0
- package/dist/collections/operations/count.js +75 -0
- package/dist/collections/operations/count.js.map +1 -0
- package/dist/collections/operations/create.d.ts +2 -2
- package/dist/collections/operations/create.d.ts.map +1 -1
- package/dist/collections/operations/create.js +4 -8
- package/dist/collections/operations/create.js.map +1 -1
- package/dist/collections/operations/delete.d.ts +2 -2
- package/dist/collections/operations/delete.d.ts.map +1 -1
- package/dist/collections/operations/delete.js.map +1 -1
- package/dist/collections/operations/deleteByID.d.ts +2 -2
- package/dist/collections/operations/deleteByID.d.ts.map +1 -1
- package/dist/collections/operations/deleteByID.js.map +1 -1
- package/dist/collections/operations/docAccess.d.ts +2 -2
- package/dist/collections/operations/docAccess.d.ts.map +1 -1
- package/dist/collections/operations/docAccess.js.map +1 -1
- package/dist/collections/operations/duplicate.d.ts +2 -2
- package/dist/collections/operations/duplicate.d.ts.map +1 -1
- package/dist/collections/operations/duplicate.js.map +1 -1
- package/dist/collections/operations/find.d.ts +2 -2
- package/dist/collections/operations/find.d.ts.map +1 -1
- package/dist/collections/operations/find.js.map +1 -1
- package/dist/collections/operations/findByID.d.ts +2 -2
- package/dist/collections/operations/findByID.d.ts.map +1 -1
- package/dist/collections/operations/findByID.js.map +1 -1
- package/dist/collections/operations/findVersionByID.d.ts +2 -2
- package/dist/collections/operations/findVersionByID.d.ts.map +1 -1
- package/dist/collections/operations/findVersionByID.js.map +1 -1
- package/dist/collections/operations/findVersions.d.ts +2 -2
- package/dist/collections/operations/findVersions.d.ts.map +1 -1
- package/dist/collections/operations/findVersions.js.map +1 -1
- package/dist/collections/operations/local/count.d.ts +20 -0
- package/dist/collections/operations/local/count.d.ts.map +1 -0
- package/dist/collections/operations/local/count.js +19 -0
- package/dist/collections/operations/local/count.js.map +1 -0
- package/dist/collections/operations/local/create.d.ts +4 -4
- package/dist/collections/operations/local/create.d.ts.map +1 -1
- package/dist/collections/operations/local/create.js.map +1 -1
- package/dist/collections/operations/local/delete.d.ts +4 -4
- package/dist/collections/operations/local/delete.d.ts.map +1 -1
- package/dist/collections/operations/local/delete.js.map +1 -1
- package/dist/collections/operations/local/duplicate.d.ts +4 -4
- package/dist/collections/operations/local/duplicate.d.ts.map +1 -1
- package/dist/collections/operations/local/duplicate.js.map +1 -1
- package/dist/collections/operations/local/find.d.ts +4 -4
- package/dist/collections/operations/local/find.d.ts.map +1 -1
- package/dist/collections/operations/local/find.js.map +1 -1
- package/dist/collections/operations/local/findByID.d.ts +4 -4
- package/dist/collections/operations/local/findByID.d.ts.map +1 -1
- package/dist/collections/operations/local/findByID.js.map +1 -1
- package/dist/collections/operations/local/findVersionByID.d.ts +4 -4
- package/dist/collections/operations/local/findVersionByID.d.ts.map +1 -1
- package/dist/collections/operations/local/findVersionByID.js.map +1 -1
- package/dist/collections/operations/local/findVersions.d.ts +4 -4
- package/dist/collections/operations/local/findVersions.d.ts.map +1 -1
- package/dist/collections/operations/local/findVersions.js.map +1 -1
- package/dist/collections/operations/local/index.d.ts +2 -0
- package/dist/collections/operations/local/index.d.ts.map +1 -1
- package/dist/collections/operations/local/index.js +2 -0
- package/dist/collections/operations/local/index.js.map +1 -1
- package/dist/collections/operations/local/restoreVersion.d.ts +4 -4
- package/dist/collections/operations/local/restoreVersion.d.ts.map +1 -1
- package/dist/collections/operations/local/restoreVersion.js.map +1 -1
- package/dist/collections/operations/local/update.d.ts +4 -4
- package/dist/collections/operations/local/update.d.ts.map +1 -1
- package/dist/collections/operations/local/update.js.map +1 -1
- package/dist/collections/operations/restoreVersion.d.ts +2 -2
- package/dist/collections/operations/restoreVersion.d.ts.map +1 -1
- package/dist/collections/operations/restoreVersion.js.map +1 -1
- package/dist/collections/operations/update.d.ts +2 -2
- package/dist/collections/operations/update.d.ts.map +1 -1
- package/dist/collections/operations/update.js +3 -3
- package/dist/collections/operations/update.js.map +1 -1
- package/dist/collections/operations/updateByID.d.ts +2 -2
- package/dist/collections/operations/updateByID.d.ts.map +1 -1
- package/dist/collections/operations/updateByID.js +2 -2
- package/dist/collections/operations/updateByID.js.map +1 -1
- package/dist/collections/operations/utils.d.ts +8 -2
- package/dist/collections/operations/utils.d.ts.map +1 -1
- package/dist/collections/operations/utils.js.map +1 -1
- package/dist/config/build.d.ts.map +1 -1
- package/dist/config/build.js +3 -4
- package/dist/config/build.js.map +1 -1
- package/dist/config/client.d.ts +2 -1
- package/dist/config/client.d.ts.map +1 -1
- package/dist/config/client.js +2 -1
- package/dist/config/client.js.map +1 -1
- package/dist/config/defaults.d.ts.map +1 -1
- package/dist/config/defaults.js +1 -0
- package/dist/config/defaults.js.map +1 -1
- package/dist/config/find.d.ts.map +1 -1
- package/dist/config/find.js +20 -9
- package/dist/config/find.js.map +1 -1
- package/dist/config/sanitize.d.ts +1 -1
- package/dist/config/sanitize.d.ts.map +1 -1
- package/dist/config/sanitize.js +28 -7
- package/dist/config/sanitize.js.map +1 -1
- package/dist/config/schema.d.ts.map +1 -1
- package/dist/config/schema.js +2 -1
- package/dist/config/schema.js.map +1 -1
- package/dist/config/types.d.ts +40 -54
- package/dist/config/types.d.ts.map +1 -1
- package/dist/config/types.js +3 -12
- package/dist/config/types.js.map +1 -1
- package/dist/database/migrations/migrate.js.map +1 -1
- package/dist/database/migrations/migrateDown.js.map +1 -1
- package/dist/database/migrations/migrateRefresh.js.map +1 -1
- package/dist/database/migrations/migrateReset.js.map +1 -1
- package/dist/database/queryValidation/validateQueryPaths.d.ts +2 -2
- package/dist/database/queryValidation/validateQueryPaths.d.ts.map +1 -1
- package/dist/database/queryValidation/validateQueryPaths.js +1 -1
- package/dist/database/queryValidation/validateQueryPaths.js.map +1 -1
- package/dist/database/queryValidation/validateSearchParams.d.ts +2 -2
- package/dist/database/queryValidation/validateSearchParams.d.ts.map +1 -1
- package/dist/database/queryValidation/validateSearchParams.js.map +1 -1
- package/dist/database/types.d.ts +29 -19
- package/dist/database/types.d.ts.map +1 -1
- package/dist/database/types.js.map +1 -1
- package/dist/email/consoleEmailAdapter.d.ts +3 -0
- package/dist/email/consoleEmailAdapter.d.ts.map +1 -0
- package/dist/email/consoleEmailAdapter.js +17 -0
- package/dist/email/consoleEmailAdapter.js.map +1 -0
- package/dist/email/defaults.d.ts +2 -2
- package/dist/email/defaults.d.ts.map +1 -1
- package/dist/email/defaults.js +3 -3
- package/dist/email/defaults.js.map +1 -1
- package/dist/email/getStringifiedToAddress.d.ts +3 -0
- package/dist/email/getStringifiedToAddress.d.ts.map +1 -0
- package/dist/email/getStringifiedToAddress.js +20 -0
- package/dist/email/getStringifiedToAddress.js.map +1 -0
- package/dist/email/sendEmail.d.ts +3 -2
- package/dist/email/sendEmail.d.ts.map +1 -1
- package/dist/email/sendEmail.js +8 -4
- package/dist/email/sendEmail.js.map +1 -1
- package/dist/email/types.d.ts +26 -18
- package/dist/email/types.d.ts.map +1 -1
- package/dist/email/types.js +5 -1
- package/dist/email/types.js.map +1 -1
- package/dist/errors/APIError.d.ts +2 -2
- package/dist/errors/APIError.d.ts.map +1 -1
- package/dist/errors/APIError.js +1 -2
- package/dist/errors/APIError.js.map +1 -1
- package/dist/errors/AuthenticationError.d.ts +2 -3
- package/dist/errors/AuthenticationError.d.ts.map +1 -1
- package/dist/errors/AuthenticationError.js +2 -3
- package/dist/errors/AuthenticationError.js.map +1 -1
- package/dist/errors/DuplicateCollection.d.ts +2 -3
- package/dist/errors/DuplicateCollection.d.ts.map +1 -1
- package/dist/errors/DuplicateCollection.js +2 -3
- package/dist/errors/DuplicateCollection.js.map +1 -1
- package/dist/errors/DuplicateFieldName.d.ts +2 -3
- package/dist/errors/DuplicateFieldName.d.ts.map +1 -1
- package/dist/errors/DuplicateFieldName.js +2 -3
- package/dist/errors/DuplicateFieldName.js.map +1 -1
- package/dist/errors/DuplicateGlobal.d.ts +2 -3
- package/dist/errors/DuplicateGlobal.d.ts.map +1 -1
- package/dist/errors/DuplicateGlobal.js +2 -3
- package/dist/errors/DuplicateGlobal.js.map +1 -1
- package/dist/errors/ErrorDeletingFile.d.ts +2 -3
- package/dist/errors/ErrorDeletingFile.d.ts.map +1 -1
- package/dist/errors/ErrorDeletingFile.js +2 -3
- package/dist/errors/ErrorDeletingFile.js.map +1 -1
- package/dist/errors/FileRetrievalError.d.ts +6 -0
- package/dist/errors/FileRetrievalError.d.ts.map +1 -0
- package/dist/errors/FileRetrievalError.js +13 -0
- package/dist/errors/FileRetrievalError.js.map +1 -0
- package/dist/errors/FileUploadError.d.ts +2 -3
- package/dist/errors/FileUploadError.d.ts.map +1 -1
- package/dist/errors/FileUploadError.js +2 -3
- package/dist/errors/FileUploadError.js.map +1 -1
- package/dist/errors/Forbidden.d.ts +2 -3
- package/dist/errors/Forbidden.d.ts.map +1 -1
- package/dist/errors/Forbidden.js +2 -3
- package/dist/errors/Forbidden.js.map +1 -1
- package/dist/errors/InvalidConfiguration.d.ts +2 -3
- package/dist/errors/InvalidConfiguration.d.ts.map +1 -1
- package/dist/errors/InvalidConfiguration.js +2 -3
- package/dist/errors/InvalidConfiguration.js.map +1 -1
- package/dist/errors/InvalidFieldName.d.ts +2 -3
- package/dist/errors/InvalidFieldName.d.ts.map +1 -1
- package/dist/errors/InvalidFieldName.js +2 -3
- package/dist/errors/InvalidFieldName.js.map +1 -1
- package/dist/errors/InvalidFieldRelationship.d.ts +2 -3
- package/dist/errors/InvalidFieldRelationship.d.ts.map +1 -1
- package/dist/errors/InvalidFieldRelationship.js +2 -3
- package/dist/errors/InvalidFieldRelationship.js.map +1 -1
- package/dist/errors/InvalidSchema.d.ts +2 -3
- package/dist/errors/InvalidSchema.d.ts.map +1 -1
- package/dist/errors/InvalidSchema.js +2 -3
- package/dist/errors/InvalidSchema.js.map +1 -1
- package/dist/errors/LockedAuth.d.ts +2 -3
- package/dist/errors/LockedAuth.d.ts.map +1 -1
- package/dist/errors/LockedAuth.js +2 -3
- package/dist/errors/LockedAuth.js.map +1 -1
- package/dist/errors/MissingCollectionLabel.d.ts +2 -3
- package/dist/errors/MissingCollectionLabel.d.ts.map +1 -1
- package/dist/errors/MissingCollectionLabel.js +2 -3
- package/dist/errors/MissingCollectionLabel.js.map +1 -1
- package/dist/errors/MissingEditorProp.d.ts +2 -3
- package/dist/errors/MissingEditorProp.d.ts.map +1 -1
- package/dist/errors/MissingEditorProp.js +2 -3
- package/dist/errors/MissingEditorProp.js.map +1 -1
- package/dist/errors/MissingFieldInputOptions.d.ts +2 -3
- package/dist/errors/MissingFieldInputOptions.d.ts.map +1 -1
- package/dist/errors/MissingFieldInputOptions.js +2 -3
- package/dist/errors/MissingFieldInputOptions.js.map +1 -1
- package/dist/errors/MissingFieldType.d.ts +2 -3
- package/dist/errors/MissingFieldType.d.ts.map +1 -1
- package/dist/errors/MissingFieldType.js +2 -3
- package/dist/errors/MissingFieldType.js.map +1 -1
- package/dist/errors/MissingFile.d.ts +2 -3
- package/dist/errors/MissingFile.d.ts.map +1 -1
- package/dist/errors/MissingFile.js +2 -3
- package/dist/errors/MissingFile.js.map +1 -1
- package/dist/errors/NotFound.d.ts +2 -3
- package/dist/errors/NotFound.d.ts.map +1 -1
- package/dist/errors/NotFound.js +2 -3
- package/dist/errors/NotFound.js.map +1 -1
- package/dist/errors/QueryError.d.ts +2 -3
- package/dist/errors/QueryError.d.ts.map +1 -1
- package/dist/errors/QueryError.js +2 -3
- package/dist/errors/QueryError.js.map +1 -1
- package/dist/errors/TimestampsRequired.d.ts +2 -3
- package/dist/errors/TimestampsRequired.d.ts.map +1 -1
- package/dist/errors/TimestampsRequired.js +2 -3
- package/dist/errors/TimestampsRequired.js.map +1 -1
- package/dist/errors/UnathorizedError.d.ts +2 -3
- package/dist/errors/UnathorizedError.d.ts.map +1 -1
- package/dist/errors/UnathorizedError.js +2 -3
- package/dist/errors/UnathorizedError.js.map +1 -1
- package/dist/errors/ValidationError.d.ts +2 -3
- package/dist/errors/ValidationError.d.ts.map +1 -1
- package/dist/errors/ValidationError.js +2 -3
- package/dist/errors/ValidationError.js.map +1 -1
- package/dist/errors/index.d.ts +20 -19
- package/dist/errors/index.d.ts.map +1 -1
- package/dist/errors/index.js +20 -19
- package/dist/errors/index.js.map +1 -1
- package/dist/exports/auth.d.ts +1 -0
- package/dist/exports/auth.d.ts.map +1 -1
- package/dist/exports/auth.js +1 -0
- package/dist/exports/auth.js.map +1 -1
- package/dist/exports/database.d.ts +1 -1
- package/dist/exports/database.d.ts.map +1 -1
- package/dist/exports/database.js.map +1 -1
- package/dist/exports/i18n.d.ts +2 -0
- package/dist/exports/i18n.d.ts.map +1 -0
- package/dist/exports/i18n.js +3 -0
- package/dist/exports/i18n.js.map +1 -0
- package/dist/exports/node.d.ts +3 -0
- package/dist/exports/node.d.ts.map +1 -1
- package/dist/exports/node.js +3 -1
- package/dist/exports/node.js.map +1 -1
- package/dist/exports/operations.d.ts +1 -0
- package/dist/exports/operations.d.ts.map +1 -1
- package/dist/exports/operations.js +1 -0
- package/dist/exports/operations.js.map +1 -1
- package/dist/exports/types.d.ts +1 -0
- package/dist/exports/types.d.ts.map +1 -1
- package/dist/exports/types.js.map +1 -1
- package/dist/exports/utilities.d.ts +7 -2
- package/dist/exports/utilities.d.ts.map +1 -1
- package/dist/exports/utilities.js +7 -3
- package/dist/exports/utilities.js.map +1 -1
- package/dist/fields/config/client.d.ts +129 -104
- package/dist/fields/config/client.d.ts.map +1 -1
- package/dist/fields/config/client.js +2 -1
- package/dist/fields/config/client.js.map +1 -1
- package/dist/fields/config/sanitize.d.ts +7 -2
- package/dist/fields/config/sanitize.d.ts.map +1 -1
- package/dist/fields/config/sanitize.js +61 -33
- package/dist/fields/config/sanitize.js.map +1 -1
- package/dist/fields/config/sanitize.spec.js +76 -82
- package/dist/fields/config/sanitize.spec.js.map +1 -1
- package/dist/fields/config/schema.d.ts.map +1 -1
- package/dist/fields/config/schema.js +7 -1
- package/dist/fields/config/schema.js.map +1 -1
- package/dist/fields/config/types.d.ts +69 -57
- package/dist/fields/config/types.d.ts.map +1 -1
- package/dist/fields/config/types.js.map +1 -1
- package/dist/fields/getDefaultValue.d.ts +2 -2
- package/dist/fields/getDefaultValue.d.ts.map +1 -1
- package/dist/fields/getDefaultValue.js.map +1 -1
- package/dist/fields/hooks/afterChange/index.d.ts +2 -2
- package/dist/fields/hooks/afterChange/index.d.ts.map +1 -1
- package/dist/fields/hooks/afterChange/index.js.map +1 -1
- package/dist/fields/hooks/afterChange/promise.d.ts +2 -2
- package/dist/fields/hooks/afterChange/promise.d.ts.map +1 -1
- package/dist/fields/hooks/afterChange/promise.js.map +1 -1
- package/dist/fields/hooks/afterChange/traverseFields.d.ts +2 -2
- package/dist/fields/hooks/afterChange/traverseFields.d.ts.map +1 -1
- package/dist/fields/hooks/afterChange/traverseFields.js.map +1 -1
- package/dist/fields/hooks/afterRead/index.d.ts +2 -2
- package/dist/fields/hooks/afterRead/index.d.ts.map +1 -1
- package/dist/fields/hooks/afterRead/index.js.map +1 -1
- package/dist/fields/hooks/afterRead/promise.d.ts +5 -2
- package/dist/fields/hooks/afterRead/promise.d.ts.map +1 -1
- package/dist/fields/hooks/afterRead/promise.js +7 -16
- package/dist/fields/hooks/afterRead/promise.js.map +1 -1
- package/dist/fields/hooks/afterRead/relationshipPopulationPromise.d.ts +2 -2
- package/dist/fields/hooks/afterRead/relationshipPopulationPromise.d.ts.map +1 -1
- package/dist/fields/hooks/afterRead/relationshipPopulationPromise.js.map +1 -1
- package/dist/fields/hooks/afterRead/traverseFields.d.ts +5 -2
- package/dist/fields/hooks/afterRead/traverseFields.d.ts.map +1 -1
- package/dist/fields/hooks/afterRead/traverseFields.js.map +1 -1
- package/dist/fields/hooks/beforeChange/index.d.ts +2 -2
- package/dist/fields/hooks/beforeChange/index.d.ts.map +1 -1
- package/dist/fields/hooks/beforeChange/index.js.map +1 -1
- package/dist/fields/hooks/beforeChange/promise.d.ts +2 -2
- package/dist/fields/hooks/beforeChange/promise.d.ts.map +1 -1
- package/dist/fields/hooks/beforeChange/promise.js +3 -1
- package/dist/fields/hooks/beforeChange/promise.js.map +1 -1
- package/dist/fields/hooks/beforeChange/traverseFields.d.ts +14 -2
- package/dist/fields/hooks/beforeChange/traverseFields.d.ts.map +1 -1
- package/dist/fields/hooks/beforeChange/traverseFields.js.map +1 -1
- package/dist/fields/hooks/beforeValidate/index.d.ts +2 -2
- package/dist/fields/hooks/beforeValidate/index.d.ts.map +1 -1
- package/dist/fields/hooks/beforeValidate/index.js.map +1 -1
- package/dist/fields/hooks/beforeValidate/promise.d.ts +8 -2
- package/dist/fields/hooks/beforeValidate/promise.d.ts.map +1 -1
- package/dist/fields/hooks/beforeValidate/promise.js +2 -0
- package/dist/fields/hooks/beforeValidate/promise.js.map +1 -1
- package/dist/fields/hooks/beforeValidate/traverseFields.d.ts +8 -2
- package/dist/fields/hooks/beforeValidate/traverseFields.d.ts.map +1 -1
- package/dist/fields/hooks/beforeValidate/traverseFields.js.map +1 -1
- package/dist/fields/validations.d.ts +6 -4
- package/dist/fields/validations.d.ts.map +1 -1
- package/dist/fields/validations.js +52 -10
- package/dist/fields/validations.js.map +1 -1
- package/dist/fields/validations.spec.js +6 -1
- package/dist/fields/validations.spec.js.map +1 -1
- package/dist/globals/config/client.d.ts +1 -1
- package/dist/globals/config/client.d.ts.map +1 -1
- package/dist/globals/config/client.js +2 -1
- package/dist/globals/config/client.js.map +1 -1
- package/dist/globals/config/sanitize.d.ts +2 -3
- package/dist/globals/config/sanitize.d.ts.map +1 -1
- package/dist/globals/config/sanitize.js +36 -35
- package/dist/globals/config/sanitize.js.map +1 -1
- package/dist/globals/config/schema.d.ts.map +1 -1
- package/dist/globals/config/schema.js +1 -0
- package/dist/globals/config/schema.js.map +1 -1
- package/dist/globals/config/types.d.ts +10 -9
- package/dist/globals/config/types.d.ts.map +1 -1
- package/dist/globals/config/types.js.map +1 -1
- package/dist/globals/operations/docAccess.d.ts +2 -2
- package/dist/globals/operations/docAccess.d.ts.map +1 -1
- package/dist/globals/operations/docAccess.js.map +1 -1
- package/dist/globals/operations/findOne.d.ts +2 -3
- package/dist/globals/operations/findOne.d.ts.map +1 -1
- package/dist/globals/operations/findOne.js.map +1 -1
- package/dist/globals/operations/findVersionByID.d.ts +2 -2
- package/dist/globals/operations/findVersionByID.d.ts.map +1 -1
- package/dist/globals/operations/findVersionByID.js.map +1 -1
- package/dist/globals/operations/findVersions.d.ts +2 -2
- package/dist/globals/operations/findVersions.d.ts.map +1 -1
- package/dist/globals/operations/findVersions.js.map +1 -1
- package/dist/globals/operations/local/findOne.d.ts +4 -4
- package/dist/globals/operations/local/findOne.d.ts.map +1 -1
- package/dist/globals/operations/local/findOne.js.map +1 -1
- package/dist/globals/operations/local/findVersionByID.d.ts +4 -4
- package/dist/globals/operations/local/findVersionByID.d.ts.map +1 -1
- package/dist/globals/operations/local/findVersionByID.js.map +1 -1
- package/dist/globals/operations/local/findVersions.d.ts +4 -4
- package/dist/globals/operations/local/findVersions.d.ts.map +1 -1
- package/dist/globals/operations/local/findVersions.js.map +1 -1
- package/dist/globals/operations/local/restoreVersion.d.ts +4 -4
- package/dist/globals/operations/local/restoreVersion.d.ts.map +1 -1
- package/dist/globals/operations/local/restoreVersion.js.map +1 -1
- package/dist/globals/operations/local/update.d.ts +4 -4
- package/dist/globals/operations/local/update.d.ts.map +1 -1
- package/dist/globals/operations/local/update.js.map +1 -1
- package/dist/globals/operations/restoreVersion.d.ts +2 -2
- package/dist/globals/operations/restoreVersion.d.ts.map +1 -1
- package/dist/globals/operations/restoreVersion.js.map +1 -1
- package/dist/globals/operations/update.d.ts +2 -2
- package/dist/globals/operations/update.d.ts.map +1 -1
- package/dist/globals/operations/update.js.map +1 -1
- package/dist/index.d.ts +17 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +32 -14
- package/dist/index.js.map +1 -1
- package/dist/preferences/deleteUserPreferences.d.ts +2 -2
- package/dist/preferences/deleteUserPreferences.d.ts.map +1 -1
- package/dist/preferences/deleteUserPreferences.js.map +1 -1
- package/dist/preferences/operations/delete.js +2 -2
- package/dist/preferences/operations/delete.js.map +1 -1
- package/dist/preferences/operations/update.d.ts +1 -1
- package/dist/preferences/operations/update.js +1 -1
- package/dist/preferences/operations/update.js.map +1 -1
- package/dist/preferences/requestHandlers/delete.d.ts.map +1 -1
- package/dist/preferences/requestHandlers/delete.js +18 -5
- package/dist/preferences/requestHandlers/delete.js.map +1 -1
- package/dist/preferences/requestHandlers/findOne.d.ts.map +1 -1
- package/dist/preferences/requestHandlers/findOne.js +18 -5
- package/dist/preferences/requestHandlers/findOne.js.map +1 -1
- package/dist/preferences/requestHandlers/update.d.ts.map +1 -1
- package/dist/preferences/requestHandlers/update.js +19 -7
- package/dist/preferences/requestHandlers/update.js.map +1 -1
- package/dist/preferences/types.d.ts +3 -4
- package/dist/preferences/types.d.ts.map +1 -1
- package/dist/preferences/types.js.map +1 -1
- package/dist/types/index.d.ts +21 -17
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js.map +1 -1
- package/dist/uploads/deleteAssociatedFiles.d.ts +2 -2
- package/dist/uploads/deleteAssociatedFiles.d.ts.map +1 -1
- package/dist/uploads/deleteAssociatedFiles.js.map +1 -1
- package/dist/uploads/docWithFilenameExists.d.ts +2 -2
- package/dist/uploads/docWithFilenameExists.d.ts.map +1 -1
- package/dist/uploads/docWithFilenameExists.js.map +1 -1
- package/dist/uploads/generateFileData.d.ts +2 -2
- package/dist/uploads/generateFileData.d.ts.map +1 -1
- package/dist/uploads/generateFileData.js +5 -4
- package/dist/uploads/generateFileData.js.map +1 -1
- package/dist/uploads/getExternalFile.d.ts +5 -4
- package/dist/uploads/getExternalFile.d.ts.map +1 -1
- package/dist/uploads/getExternalFile.js +10 -6
- package/dist/uploads/getExternalFile.js.map +1 -1
- package/dist/uploads/getFileByPath.d.ts +2 -2
- package/dist/uploads/getFileByPath.d.ts.map +1 -1
- package/dist/uploads/getFileByPath.js.map +1 -1
- package/dist/uploads/getImageSize.d.ts +2 -2
- package/dist/uploads/getImageSize.d.ts.map +1 -1
- package/dist/uploads/getImageSize.js +19 -5
- package/dist/uploads/getImageSize.js.map +1 -1
- package/dist/uploads/getSafeFilename.d.ts +2 -2
- package/dist/uploads/getSafeFilename.d.ts.map +1 -1
- package/dist/uploads/getSafeFilename.js.map +1 -1
- package/dist/uploads/imageResizer.d.ts +3 -3
- package/dist/uploads/imageResizer.d.ts.map +1 -1
- package/dist/uploads/imageResizer.js.map +1 -1
- package/dist/uploads/tempFile.d.ts +7 -0
- package/dist/uploads/tempFile.d.ts.map +1 -0
- package/dist/uploads/tempFile.js +39 -0
- package/dist/uploads/tempFile.js.map +1 -0
- package/dist/uploads/types.d.ts +12 -2
- package/dist/uploads/types.d.ts.map +1 -1
- package/dist/uploads/types.js.map +1 -1
- package/dist/uploads/unlinkTempFiles.d.ts +2 -2
- package/dist/uploads/unlinkTempFiles.d.ts.map +1 -1
- package/dist/uploads/unlinkTempFiles.js.map +1 -1
- package/dist/uploads/uploadFiles.d.ts +2 -2
- package/dist/uploads/uploadFiles.d.ts.map +1 -1
- package/dist/uploads/uploadFiles.js.map +1 -1
- package/dist/utilities/checkDuplicateCollections.js +1 -1
- package/dist/utilities/checkDuplicateCollections.js.map +1 -1
- package/dist/utilities/commitTransaction.d.ts +2 -2
- package/dist/utilities/commitTransaction.d.ts.map +1 -1
- package/dist/utilities/commitTransaction.js.map +1 -1
- package/dist/utilities/configToJSONSchema.d.ts.map +1 -1
- package/dist/utilities/configToJSONSchema.js +56 -1
- package/dist/utilities/configToJSONSchema.js.map +1 -1
- package/dist/utilities/configToJSONSchema.spec.js +2 -2
- package/dist/utilities/configToJSONSchema.spec.js.map +1 -1
- package/dist/utilities/createLocalReq.d.ts +3 -3
- package/dist/utilities/createLocalReq.d.ts.map +1 -1
- package/dist/utilities/createLocalReq.js +4 -2
- package/dist/utilities/createLocalReq.js.map +1 -1
- package/dist/utilities/getEntityPolicies.d.ts +2 -2
- package/dist/utilities/getEntityPolicies.d.ts.map +1 -1
- package/dist/utilities/getEntityPolicies.js.map +1 -1
- package/dist/utilities/importWithoutClientFiles.d.ts.map +1 -1
- package/dist/utilities/importWithoutClientFiles.js +7 -4
- package/dist/utilities/importWithoutClientFiles.js.map +1 -1
- package/dist/utilities/initTransaction.d.ts +2 -2
- package/dist/utilities/initTransaction.d.ts.map +1 -1
- package/dist/utilities/initTransaction.js.map +1 -1
- package/dist/utilities/isEntityHidden.d.ts +2 -2
- package/dist/utilities/isEntityHidden.d.ts.map +1 -1
- package/dist/utilities/isEntityHidden.js.map +1 -1
- package/dist/utilities/isReactComponent.d.ts +2 -0
- package/dist/utilities/isReactComponent.d.ts.map +1 -1
- package/dist/utilities/isReactComponent.js +8 -2
- package/dist/utilities/isReactComponent.js.map +1 -1
- package/dist/utilities/killTransaction.d.ts +2 -2
- package/dist/utilities/killTransaction.d.ts.map +1 -1
- package/dist/utilities/killTransaction.js.map +1 -1
- package/dist/utilities/parseCookies.js +1 -1
- package/dist/utilities/parseCookies.js.map +1 -1
- package/dist/utilities/telemetry/events/adminInit.d.ts +2 -2
- package/dist/utilities/telemetry/events/adminInit.d.ts.map +1 -1
- package/dist/utilities/telemetry/events/adminInit.js.map +1 -1
- package/dist/utilities/telemetry/index.d.ts +9 -0
- package/dist/utilities/telemetry/index.d.ts.map +1 -1
- package/dist/utilities/telemetry/index.js +62 -14
- package/dist/utilities/telemetry/index.js.map +1 -1
- package/dist/versions/deleteCollectionVersions.d.ts +2 -2
- package/dist/versions/deleteCollectionVersions.d.ts.map +1 -1
- package/dist/versions/deleteCollectionVersions.js.map +1 -1
- package/dist/versions/drafts/replaceWithDraftIfAvailable.d.ts +2 -2
- package/dist/versions/drafts/replaceWithDraftIfAvailable.d.ts.map +1 -1
- package/dist/versions/drafts/replaceWithDraftIfAvailable.js.map +1 -1
- package/dist/versions/enforceMaxVersions.d.ts +2 -2
- package/dist/versions/enforceMaxVersions.d.ts.map +1 -1
- package/dist/versions/enforceMaxVersions.js.map +1 -1
- package/dist/versions/getLatestCollectionVersion.d.ts +2 -2
- package/dist/versions/getLatestCollectionVersion.d.ts.map +1 -1
- package/dist/versions/getLatestCollectionVersion.js.map +1 -1
- package/dist/versions/getLatestGlobalVersion.d.ts +2 -2
- package/dist/versions/getLatestGlobalVersion.d.ts.map +1 -1
- package/dist/versions/getLatestGlobalVersion.js.map +1 -1
- package/dist/versions/saveVersion.d.ts +2 -2
- package/dist/versions/saveVersion.d.ts.map +1 -1
- package/dist/versions/saveVersion.js +1 -1
- package/dist/versions/saveVersion.js.map +1 -1
- package/package.json +71 -65
- package/auth.d.ts +0 -6
- package/auth.js +0 -6
- package/config.d.ts +0 -14
- package/config.js +0 -14
- package/database.d.ts +0 -23
- package/database.js +0 -22
- package/dist/email/build.d.ts +0 -5
- package/dist/email/build.d.ts.map +0 -1
- package/dist/email/build.js +0 -63
- package/dist/email/build.js.map +0 -1
- package/dist/email/mockHandler.d.ts +0 -5
- package/dist/email/mockHandler.d.ts.map +0 -1
- package/dist/email/mockHandler.js +0 -24
- package/dist/email/mockHandler.js.map +0 -1
- package/dist/utilities/getIDType.d.ts +0 -4
- package/dist/utilities/getIDType.d.ts.map +0 -1
- package/dist/utilities/getIDType.js +0 -8
- package/dist/utilities/getIDType.js.map +0 -1
- package/errors.d.ts +0 -2
- package/errors.js +0 -3
- package/node.d.ts +0 -3
- package/node.js +0 -4
- package/operations.d.ts +0 -30
- package/operations.js +0 -31
- package/src/index.ts +0 -486
- package/types.d.ts +0 -17
- package/types.js +0 -5
- package/uploads.d.ts +0 -2
- package/uploads.js +0 -3
- package/utilities.d.ts +0 -32
- package/utilities.js +0 -33
- package/versions.d.ts +0 -9
- package/versions.js +0 -9
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/configToJSONSchema.ts"],"sourcesContent":["import type { JSONSchema4, JSONSchema4TypeName } from 'json-schema'\n\nimport pluralize from 'pluralize'\nconst { singular } = pluralize\n\nimport type { SanitizedCollectionConfig } from '../collections/config/types.js'\nimport type { SanitizedConfig } from '../config/types.js'\nimport type { Field, FieldAffectingData, Option } from '../fields/config/types.js'\nimport type { SanitizedGlobalConfig } from '../globals/config/types.js'\n\nimport { fieldAffectsData, tabHasName } from '../fields/config/types.js'\nimport { deepCopyObject } from './deepCopyObject.js'\nimport { toWords } from './formatLabels.js'\nimport { getCollectionIDFieldTypes } from './getCollectionIDFieldTypes.js'\n\nconst fieldIsRequired = (field: Field) => {\n const isConditional = Boolean(field?.admin && field?.admin?.condition)\n if (isConditional) return false\n\n const isMarkedRequired = 'required' in field && field.required === true\n if (fieldAffectsData(field) && isMarkedRequired) return true\n\n // if any subfields are required, this field is required\n if ('fields' in field && field.type !== 'array') {\n return field.fields.some((subField) => fieldIsRequired(subField))\n }\n\n // if any tab subfields have required fields, this field is required\n if (field.type === 'tabs') {\n return field.tabs.some((tab) => {\n if ('name' in tab) {\n return tab.fields.some((subField) => fieldIsRequired(subField))\n }\n return false\n })\n }\n\n return false\n}\n\nfunction buildOptionEnums(options: Option[]): string[] {\n return options.map((option) => {\n if (typeof option === 'object' && 'value' in option) {\n return option.value\n }\n\n return option\n })\n}\n\nfunction generateEntitySchemas(\n entities: (SanitizedCollectionConfig | SanitizedGlobalConfig)[],\n): JSONSchema4 {\n const properties = [...entities].reduce((acc, { slug }) => {\n acc[slug] = {\n $ref: `#/definitions/${slug}`,\n }\n\n return acc\n }, {})\n\n return {\n type: 'object',\n additionalProperties: false,\n properties,\n required: Object.keys(properties),\n }\n}\n\n/**\n * Returns a JSON Schema Type with 'null' added if the field is not required.\n */\nexport function withNullableJSONSchemaType(\n fieldType: JSONSchema4TypeName,\n isRequired: boolean,\n): JSONSchema4TypeName | JSONSchema4TypeName[] {\n const fieldTypes = [fieldType]\n if (isRequired) return fieldType\n fieldTypes.push('null')\n return fieldTypes\n}\n\nexport function fieldsToJSONSchema(\n /**\n * Used for relationship fields, to determine whether to use a string or number type for the ID.\n * While there is a default ID field type set by the db adapter, they can differ on a collection-level\n * if they have custom ID fields.\n */\n collectionIDFieldTypes: { [key: string]: 'number' | 'string' },\n fields: Field[],\n /**\n * Allows you to define new top-level interfaces that can be re-used in the output schema.\n */\n interfaceNameDefinitions: Map<string, JSONSchema4>,\n config?: SanitizedConfig,\n): {\n properties: {\n [k: string]: JSONSchema4\n }\n required: string[]\n} {\n const requiredFieldNames = new Set<string>()\n\n return {\n properties: Object.fromEntries(\n fields.reduce((fieldSchemas, field) => {\n const isRequired = fieldAffectsData(field) && fieldIsRequired(field)\n if (isRequired) requiredFieldNames.add(field.name)\n\n let fieldSchema: JSONSchema4\n switch (field.type) {\n case 'text':\n if (field.hasMany === true) {\n fieldSchema = {\n type: withNullableJSONSchemaType('array', isRequired),\n items: { type: 'string' },\n }\n } else {\n fieldSchema = { type: withNullableJSONSchemaType('string', isRequired) }\n }\n break\n case 'textarea':\n case 'code':\n case 'email':\n case 'date': {\n fieldSchema = { type: withNullableJSONSchemaType('string', isRequired) }\n break\n }\n\n case 'number': {\n if (field.hasMany === true) {\n fieldSchema = {\n type: withNullableJSONSchemaType('array', isRequired),\n items: { type: 'number' },\n }\n } else {\n fieldSchema = { type: withNullableJSONSchemaType('number', isRequired) }\n }\n break\n }\n\n case 'checkbox': {\n fieldSchema = { type: withNullableJSONSchemaType('boolean', isRequired) }\n break\n }\n\n case 'json': {\n fieldSchema = {\n type: ['object', 'array', 'string', 'number', 'boolean', 'null'],\n }\n break\n }\n\n case 'richText': {\n if (field.editor.outputSchema) {\n fieldSchema = field.editor.outputSchema({\n collectionIDFieldTypes,\n config,\n field,\n interfaceNameDefinitions,\n isRequired,\n })\n } else {\n // Maintain backwards compatibility with existing rich text editors\n fieldSchema = {\n type: withNullableJSONSchemaType('array', isRequired),\n items: {\n type: 'object',\n },\n }\n }\n\n break\n }\n\n case 'radio': {\n fieldSchema = {\n type: withNullableJSONSchemaType('string', isRequired),\n enum: buildOptionEnums(field.options),\n }\n\n break\n }\n\n case 'select': {\n const optionEnums = buildOptionEnums(field.options)\n\n if (field.hasMany) {\n fieldSchema = {\n type: withNullableJSONSchemaType('array', isRequired),\n items: {\n type: 'string',\n enum: optionEnums,\n },\n }\n } else {\n fieldSchema = {\n type: withNullableJSONSchemaType('string', isRequired),\n enum: optionEnums,\n }\n }\n\n break\n }\n\n case 'point': {\n fieldSchema = {\n type: withNullableJSONSchemaType('array', isRequired),\n items: [\n {\n type: 'number',\n },\n {\n type: 'number',\n },\n ],\n maxItems: 2,\n minItems: 2,\n }\n break\n }\n\n case 'relationship': {\n if (Array.isArray(field.relationTo)) {\n if (field.hasMany) {\n fieldSchema = {\n type: withNullableJSONSchemaType('array', isRequired),\n items: {\n oneOf: field.relationTo.map((relation) => {\n return {\n type: 'object',\n additionalProperties: false,\n properties: {\n relationTo: {\n const: relation,\n },\n value: {\n oneOf: [\n {\n type: collectionIDFieldTypes[relation],\n },\n {\n $ref: `#/definitions/${relation}`,\n },\n ],\n },\n },\n required: ['value', 'relationTo'],\n }\n }),\n },\n }\n } else {\n fieldSchema = {\n oneOf: field.relationTo.map((relation) => {\n return {\n type: withNullableJSONSchemaType('object', isRequired),\n additionalProperties: false,\n properties: {\n relationTo: {\n const: relation,\n },\n value: {\n oneOf: [\n {\n type: collectionIDFieldTypes[relation],\n },\n {\n $ref: `#/definitions/${relation}`,\n },\n ],\n },\n },\n required: ['value', 'relationTo'],\n }\n }),\n }\n }\n } else if (field.hasMany) {\n fieldSchema = {\n type: withNullableJSONSchemaType('array', isRequired),\n items: {\n oneOf: [\n {\n type: collectionIDFieldTypes[field.relationTo],\n },\n {\n $ref: `#/definitions/${field.relationTo}`,\n },\n ],\n },\n }\n } else {\n fieldSchema = {\n oneOf: [\n {\n type: withNullableJSONSchemaType(\n collectionIDFieldTypes[field.relationTo],\n isRequired,\n ),\n },\n {\n $ref: `#/definitions/${field.relationTo}`,\n },\n ],\n }\n }\n\n break\n }\n\n case 'upload': {\n fieldSchema = {\n oneOf: [\n {\n type: collectionIDFieldTypes[field.relationTo],\n },\n {\n $ref: `#/definitions/${field.relationTo}`,\n },\n ],\n }\n if (!isRequired) fieldSchema.oneOf.push({ type: 'null' })\n break\n }\n\n case 'blocks': {\n fieldSchema = {\n type: withNullableJSONSchemaType('array', isRequired),\n items: {\n oneOf: field.blocks.map((block) => {\n const blockFieldSchemas = fieldsToJSONSchema(\n collectionIDFieldTypes,\n block.fields,\n interfaceNameDefinitions,\n config,\n )\n\n const blockSchema: JSONSchema4 = {\n type: 'object',\n additionalProperties: false,\n properties: {\n ...blockFieldSchemas.properties,\n blockType: {\n const: block.slug,\n },\n },\n required: ['blockType', ...blockFieldSchemas.required],\n }\n\n if (block.interfaceName) {\n interfaceNameDefinitions.set(block.interfaceName, blockSchema)\n\n return {\n $ref: `#/definitions/${block.interfaceName}`,\n }\n }\n\n return blockSchema\n }),\n },\n }\n break\n }\n\n case 'array': {\n fieldSchema = {\n type: withNullableJSONSchemaType('array', isRequired),\n items: {\n type: 'object',\n additionalProperties: false,\n ...fieldsToJSONSchema(\n collectionIDFieldTypes,\n field.fields,\n interfaceNameDefinitions,\n config,\n ),\n },\n }\n\n if (field.interfaceName) {\n interfaceNameDefinitions.set(field.interfaceName, fieldSchema)\n\n fieldSchema = {\n $ref: `#/definitions/${field.interfaceName}`,\n }\n }\n break\n }\n\n case 'row':\n case 'collapsible': {\n const childSchema = fieldsToJSONSchema(\n collectionIDFieldTypes,\n field.fields,\n interfaceNameDefinitions,\n config,\n )\n Object.entries(childSchema.properties).forEach(([propName, propSchema]) => {\n fieldSchemas.set(propName, propSchema)\n })\n childSchema.required.forEach((propName) => {\n requiredFieldNames.add(propName)\n })\n break\n }\n\n case 'tabs': {\n field.tabs.forEach((tab) => {\n const childSchema = fieldsToJSONSchema(\n collectionIDFieldTypes,\n tab.fields,\n interfaceNameDefinitions,\n config,\n )\n if (tabHasName(tab)) {\n // could have interface\n fieldSchemas.set(tab.name, {\n type: 'object',\n additionalProperties: false,\n ...childSchema,\n })\n requiredFieldNames.add(tab.name)\n } else {\n Object.entries(childSchema.properties).forEach(([propName, propSchema]) => {\n fieldSchemas.set(propName, propSchema)\n })\n childSchema.required.forEach((propName) => {\n requiredFieldNames.add(propName)\n })\n }\n })\n break\n }\n\n case 'group': {\n fieldSchema = {\n type: 'object',\n additionalProperties: false,\n ...fieldsToJSONSchema(\n collectionIDFieldTypes,\n field.fields,\n interfaceNameDefinitions,\n config,\n ),\n }\n\n if (field.interfaceName) {\n interfaceNameDefinitions.set(field.interfaceName, fieldSchema)\n\n fieldSchema = {\n $ref: `#/definitions/${field.interfaceName}`,\n }\n }\n break\n }\n\n default: {\n break\n }\n }\n\n if (fieldSchema && fieldAffectsData(field)) {\n fieldSchemas.set(field.name, fieldSchema)\n }\n\n return fieldSchemas\n }, new Map<string, JSONSchema4>()),\n ),\n required: Array.from(requiredFieldNames),\n }\n}\n\n// This function is part of the public API and is exported through payload/utilities\nexport function entityToJSONSchema(\n config: SanitizedConfig,\n incomingEntity: SanitizedCollectionConfig | SanitizedGlobalConfig,\n interfaceNameDefinitions: Map<string, JSONSchema4>,\n defaultIDType: 'number' | 'text',\n): JSONSchema4 {\n const entity: SanitizedCollectionConfig | SanitizedGlobalConfig = deepCopyObject(incomingEntity)\n const title = entity.typescript?.interface\n ? entity.typescript.interface\n : singular(toWords(entity.slug, true))\n\n const idField: FieldAffectingData = { name: 'id', type: defaultIDType as 'text', required: true }\n const customIdField = entity.fields.find(\n (field) => fieldAffectsData(field) && field.name === 'id',\n ) as FieldAffectingData\n\n if (customIdField && customIdField.type !== 'group' && customIdField.type !== 'tab') {\n customIdField.required = true\n } else {\n entity.fields.unshift(idField)\n }\n\n // mark timestamp fields required\n if ('timestamps' in entity && entity.timestamps !== false) {\n entity.fields = entity.fields.map((field) => {\n if (fieldAffectsData(field) && (field.name === 'createdAt' || field.name === 'updatedAt')) {\n return {\n ...field,\n required: true,\n }\n }\n return field\n })\n }\n\n if ('auth' in entity && entity.auth && !entity.auth?.disableLocalStrategy) {\n entity.fields.push({\n name: 'password',\n type: 'text',\n })\n }\n\n // Used for relationship fields, to determine whether to use a string or number type for the ID.\n const collectionIDFieldTypes = getCollectionIDFieldTypes({ config, defaultIDType })\n\n return {\n type: 'object',\n additionalProperties: false,\n title,\n ...fieldsToJSONSchema(collectionIDFieldTypes, entity.fields, interfaceNameDefinitions, config),\n }\n}\n\n/**\n * This is used for generating the TypeScript types (payload-types.ts) with the payload generate:types command.\n */\nexport function configToJSONSchema(\n config: SanitizedConfig,\n defaultIDType?: 'number' | 'text',\n): JSONSchema4 {\n // a mutable Map to store custom top-level `interfaceName` types. Fields with an `interfaceName` property will be moved to the top-level definitions here\n const interfaceNameDefinitions: Map<string, JSONSchema4> = new Map()\n\n // Collections and Globals have to be moved to the top-level definitions as well. Reason: The top-level type will be the `Config` type - we don't want all collection and global\n // types to be inlined inside the `Config` type\n const entityDefinitions: { [k: string]: JSONSchema4 } = [\n ...config.globals,\n ...config.collections,\n ].reduce((acc, entity) => {\n acc[entity.slug] = entityToJSONSchema(config, entity, interfaceNameDefinitions, defaultIDType)\n return acc\n }, {})\n\n return {\n additionalProperties: false,\n definitions: { ...entityDefinitions, ...Object.fromEntries(interfaceNameDefinitions) },\n // These properties here will be very simple, as all the complexity is in the definitions. These are just the properties for the top-level `Config` type\n type: 'object',\n properties: {\n collections: generateEntitySchemas(config.collections || []),\n globals: generateEntitySchemas(config.globals || []),\n },\n required: ['collections', 'globals'],\n title: 'Config',\n }\n}\n"],"names":["pluralize","singular","fieldAffectsData","tabHasName","deepCopyObject","toWords","getCollectionIDFieldTypes","fieldIsRequired","field","isConditional","Boolean","admin","condition","isMarkedRequired","required","type","fields","some","subField","tabs","tab","buildOptionEnums","options","map","option","value","generateEntitySchemas","entities","properties","reduce","acc","slug","$ref","additionalProperties","Object","keys","withNullableJSONSchemaType","fieldType","isRequired","fieldTypes","push","fieldsToJSONSchema","collectionIDFieldTypes","interfaceNameDefinitions","config","requiredFieldNames","Set","fromEntries","fieldSchemas","add","name","fieldSchema","hasMany","items","editor","outputSchema","enum","optionEnums","maxItems","minItems","Array","isArray","relationTo","oneOf","relation","const","blocks","block","blockFieldSchemas","blockSchema","blockType","interfaceName","set","childSchema","entries","forEach","propName","propSchema","Map","from","entityToJSONSchema","incomingEntity","defaultIDType","entity","title","typescript","interface","idField","customIdField","find","unshift","timestamps","auth","disableLocalStrategy","configToJSONSchema","entityDefinitions","globals","collections","definitions"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAEA,OAAOA,eAAe,YAAW;AACjC,MAAM,EAAEC,QAAQ,EAAE,GAAGD;AAOrB,SAASE,gBAAgB,EAAEC,UAAU,QAAQ,4BAA2B;AACxE,SAASC,cAAc,QAAQ,sBAAqB;AACpD,SAASC,OAAO,QAAQ,oBAAmB;AAC3C,SAASC,yBAAyB,QAAQ,iCAAgC;AAE1E,MAAMC,kBAAkB,CAACC;IACvB,MAAMC,gBAAgBC,QAAQF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,MAAM;YACNnC,MAAM;QACR;IACF;IAEA,iGAAiG;IACjG,MAAM2B,yBAAyBpC,0BAA0B;QAAEsC;QAAQsC;IAAc;IAEjF,OAAO;QACLnE,MAAM;QACNkB,sBAAsB;QACtBmD;QACA,GAAG3C,mBAAmBC,wBAAwByC,OAAOnE,MAAM,EAAE2B,0BAA0BC,OAAO;IAChG;AACF;AAEA;;CAEC,GACD,OAAO,SAASkD,mBACdlD,MAAuB,EACvBsC,aAAiC;IAEjC,yJAAyJ;IACzJ,MAAMvC,2BAAqD,IAAImC;IAE/D,gLAAgL;IAChL,+CAA+C;IAC/C,MAAMiB,oBAAkD;WACnDnD,OAAOoD,OAAO;WACdpD,OAAOqD,WAAW;KACtB,CAACpE,MAAM,CAAC,CAACC,KAAKqD;QACbrD,GAAG,CAACqD,OAAOpD,IAAI,CAAC,GAAGiD,mBAAmBpC,QAAQuC,QAAQxC,0BAA0BuC;QAChF,OAAOpD;IACT,GAAG,CAAC;IAEJ,OAAO;QACLG,sBAAsB;QACtBiE,aAAa;YAAE,GAAGH,iBAAiB;YAAE,GAAG7D,OAAOa,WAAW,CAACJ,yBAAyB;QAAC;QACrF,wJAAwJ;QACxJ5B,MAAM;QACNa,YAAY;YACVqE,aAAavE,sBAAsBkB,OAAOqD,WAAW,IAAI,EAAE;YAC3DD,SAAStE,sBAAsBkB,OAAOoD,OAAO,IAAI,EAAE;QACrD;QACAlF,UAAU;YAAC;YAAe;SAAU;QACpCsE,OAAO;IACT;AACF"}
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/configToJSONSchema.ts"],"sourcesContent":["import type { JSONSchema4, JSONSchema4TypeName } from 'json-schema'\n\nimport pluralize from 'pluralize'\nconst { singular } = pluralize\n\nimport type { SanitizedCollectionConfig } from '../collections/config/types.js'\nimport type { SanitizedConfig } from '../config/types.js'\nimport type { Field, FieldAffectingData, Option } from '../fields/config/types.js'\nimport type { SanitizedGlobalConfig } from '../globals/config/types.js'\n\nimport { fieldAffectsData, tabHasName } from '../fields/config/types.js'\nimport { deepCopyObject } from './deepCopyObject.js'\nimport { toWords } from './formatLabels.js'\nimport { getCollectionIDFieldTypes } from './getCollectionIDFieldTypes.js'\n\nconst fieldIsRequired = (field: Field) => {\n const isConditional = Boolean(field?.admin && field?.admin?.condition)\n if (isConditional) return false\n\n const isMarkedRequired = 'required' in field && field.required === true\n if (fieldAffectsData(field) && isMarkedRequired) return true\n\n // if any subfields are required, this field is required\n if ('fields' in field && field.type !== 'array') {\n return field.fields.some((subField) => fieldIsRequired(subField))\n }\n\n // if any tab subfields have required fields, this field is required\n if (field.type === 'tabs') {\n return field.tabs.some((tab) => {\n if ('name' in tab) {\n return tab.fields.some((subField) => fieldIsRequired(subField))\n }\n return false\n })\n }\n\n return false\n}\n\nfunction buildOptionEnums(options: Option[]): string[] {\n return options.map((option) => {\n if (typeof option === 'object' && 'value' in option) {\n return option.value\n }\n\n return option\n })\n}\n\nfunction generateEntitySchemas(\n entities: (SanitizedCollectionConfig | SanitizedGlobalConfig)[],\n): JSONSchema4 {\n const properties = [...entities].reduce((acc, { slug }) => {\n acc[slug] = {\n $ref: `#/definitions/${slug}`,\n }\n\n return acc\n }, {})\n\n return {\n type: 'object',\n additionalProperties: false,\n properties,\n required: Object.keys(properties),\n }\n}\n\nfunction generateLocaleEntitySchemas(localization: SanitizedConfig['localization']): JSONSchema4 {\n if (localization && 'locales' in localization && localization?.locales) {\n const localesFromConfig = localization?.locales\n\n const locales = [...localesFromConfig].map((locale) => {\n return locale.code\n }, [])\n\n return {\n type: 'string',\n enum: locales,\n }\n }\n\n return {\n type: 'null',\n }\n}\n\nfunction generateAuthEntitySchemas(entities: SanitizedCollectionConfig[]): JSONSchema4 {\n const properties: JSONSchema4[] = [...entities]\n .filter(({ auth }) => Boolean(auth))\n .map(({ slug }) => {\n return {\n allOf: [\n { $ref: `#/definitions/${slug}` },\n {\n type: 'object',\n additionalProperties: false,\n properties: {\n collection: { type: 'string', enum: [slug] },\n },\n required: ['collection'],\n },\n ],\n }\n }, {})\n\n return {\n oneOf: properties,\n }\n}\n\n/**\n * Returns a JSON Schema Type with 'null' added if the field is not required.\n */\nexport function withNullableJSONSchemaType(\n fieldType: JSONSchema4TypeName,\n isRequired: boolean,\n): JSONSchema4TypeName | JSONSchema4TypeName[] {\n const fieldTypes = [fieldType]\n if (isRequired) return fieldType\n fieldTypes.push('null')\n return fieldTypes\n}\n\nexport function fieldsToJSONSchema(\n /**\n * Used for relationship fields, to determine whether to use a string or number type for the ID.\n * While there is a default ID field type set by the db adapter, they can differ on a collection-level\n * if they have custom ID fields.\n */\n collectionIDFieldTypes: { [key: string]: 'number' | 'string' },\n fields: Field[],\n /**\n * Allows you to define new top-level interfaces that can be re-used in the output schema.\n */\n interfaceNameDefinitions: Map<string, JSONSchema4>,\n config?: SanitizedConfig,\n): {\n properties: {\n [k: string]: JSONSchema4\n }\n required: string[]\n} {\n const requiredFieldNames = new Set<string>()\n\n return {\n properties: Object.fromEntries(\n fields.reduce((fieldSchemas, field) => {\n const isRequired = fieldAffectsData(field) && fieldIsRequired(field)\n if (isRequired) requiredFieldNames.add(field.name)\n\n let fieldSchema: JSONSchema4\n switch (field.type) {\n case 'text':\n if (field.hasMany === true) {\n fieldSchema = {\n type: withNullableJSONSchemaType('array', isRequired),\n items: { type: 'string' },\n }\n } else {\n fieldSchema = { type: withNullableJSONSchemaType('string', isRequired) }\n }\n break\n case 'textarea':\n case 'code':\n case 'email':\n case 'date': {\n fieldSchema = { type: withNullableJSONSchemaType('string', isRequired) }\n break\n }\n\n case 'number': {\n if (field.hasMany === true) {\n fieldSchema = {\n type: withNullableJSONSchemaType('array', isRequired),\n items: { type: 'number' },\n }\n } else {\n fieldSchema = { type: withNullableJSONSchemaType('number', isRequired) }\n }\n break\n }\n\n case 'checkbox': {\n fieldSchema = { type: withNullableJSONSchemaType('boolean', isRequired) }\n break\n }\n\n case 'json': {\n fieldSchema = {\n type: ['object', 'array', 'string', 'number', 'boolean', 'null'],\n }\n break\n }\n\n case 'richText': {\n if (typeof field.editor === 'function') {\n throw new Error('Attempted to access unsanitized rich text editor.')\n }\n if (field.editor.outputSchema) {\n fieldSchema = field.editor.outputSchema({\n collectionIDFieldTypes,\n config,\n field,\n interfaceNameDefinitions,\n isRequired,\n })\n } else {\n // Maintain backwards compatibility with existing rich text editors\n fieldSchema = {\n type: withNullableJSONSchemaType('array', isRequired),\n items: {\n type: 'object',\n },\n }\n }\n\n break\n }\n\n case 'radio': {\n fieldSchema = {\n type: withNullableJSONSchemaType('string', isRequired),\n enum: buildOptionEnums(field.options),\n }\n\n break\n }\n\n case 'select': {\n const optionEnums = buildOptionEnums(field.options)\n\n if (field.hasMany) {\n fieldSchema = {\n type: withNullableJSONSchemaType('array', isRequired),\n items: {\n type: 'string',\n enum: optionEnums,\n },\n }\n } else {\n fieldSchema = {\n type: withNullableJSONSchemaType('string', isRequired),\n enum: optionEnums,\n }\n }\n\n break\n }\n\n case 'point': {\n fieldSchema = {\n type: withNullableJSONSchemaType('array', isRequired),\n items: [\n {\n type: 'number',\n },\n {\n type: 'number',\n },\n ],\n maxItems: 2,\n minItems: 2,\n }\n break\n }\n\n case 'relationship': {\n if (Array.isArray(field.relationTo)) {\n if (field.hasMany) {\n fieldSchema = {\n type: withNullableJSONSchemaType('array', isRequired),\n items: {\n oneOf: field.relationTo.map((relation) => {\n return {\n type: 'object',\n additionalProperties: false,\n properties: {\n relationTo: {\n const: relation,\n },\n value: {\n oneOf: [\n {\n type: collectionIDFieldTypes[relation],\n },\n {\n $ref: `#/definitions/${relation}`,\n },\n ],\n },\n },\n required: ['value', 'relationTo'],\n }\n }),\n },\n }\n } else {\n fieldSchema = {\n oneOf: field.relationTo.map((relation) => {\n return {\n type: withNullableJSONSchemaType('object', isRequired),\n additionalProperties: false,\n properties: {\n relationTo: {\n const: relation,\n },\n value: {\n oneOf: [\n {\n type: collectionIDFieldTypes[relation],\n },\n {\n $ref: `#/definitions/${relation}`,\n },\n ],\n },\n },\n required: ['value', 'relationTo'],\n }\n }),\n }\n }\n } else if (field.hasMany) {\n fieldSchema = {\n type: withNullableJSONSchemaType('array', isRequired),\n items: {\n oneOf: [\n {\n type: collectionIDFieldTypes[field.relationTo],\n },\n {\n $ref: `#/definitions/${field.relationTo}`,\n },\n ],\n },\n }\n } else {\n fieldSchema = {\n oneOf: [\n {\n type: withNullableJSONSchemaType(\n collectionIDFieldTypes[field.relationTo],\n isRequired,\n ),\n },\n {\n $ref: `#/definitions/${field.relationTo}`,\n },\n ],\n }\n }\n\n break\n }\n\n case 'upload': {\n fieldSchema = {\n oneOf: [\n {\n type: collectionIDFieldTypes[field.relationTo],\n },\n {\n $ref: `#/definitions/${field.relationTo}`,\n },\n ],\n }\n if (!isRequired) fieldSchema.oneOf.push({ type: 'null' })\n break\n }\n\n case 'blocks': {\n fieldSchema = {\n type: withNullableJSONSchemaType('array', isRequired),\n items: {\n oneOf: field.blocks.map((block) => {\n const blockFieldSchemas = fieldsToJSONSchema(\n collectionIDFieldTypes,\n block.fields,\n interfaceNameDefinitions,\n config,\n )\n\n const blockSchema: JSONSchema4 = {\n type: 'object',\n additionalProperties: false,\n properties: {\n ...blockFieldSchemas.properties,\n blockType: {\n const: block.slug,\n },\n },\n required: ['blockType', ...blockFieldSchemas.required],\n }\n\n if (block.interfaceName) {\n interfaceNameDefinitions.set(block.interfaceName, blockSchema)\n\n return {\n $ref: `#/definitions/${block.interfaceName}`,\n }\n }\n\n return blockSchema\n }),\n },\n }\n break\n }\n\n case 'array': {\n fieldSchema = {\n type: withNullableJSONSchemaType('array', isRequired),\n items: {\n type: 'object',\n additionalProperties: false,\n ...fieldsToJSONSchema(\n collectionIDFieldTypes,\n field.fields,\n interfaceNameDefinitions,\n config,\n ),\n },\n }\n\n if (field.interfaceName) {\n interfaceNameDefinitions.set(field.interfaceName, fieldSchema)\n\n fieldSchema = {\n $ref: `#/definitions/${field.interfaceName}`,\n }\n }\n break\n }\n\n case 'row':\n case 'collapsible': {\n const childSchema = fieldsToJSONSchema(\n collectionIDFieldTypes,\n field.fields,\n interfaceNameDefinitions,\n config,\n )\n Object.entries(childSchema.properties).forEach(([propName, propSchema]) => {\n fieldSchemas.set(propName, propSchema)\n })\n childSchema.required.forEach((propName) => {\n requiredFieldNames.add(propName)\n })\n break\n }\n\n case 'tabs': {\n field.tabs.forEach((tab) => {\n const childSchema = fieldsToJSONSchema(\n collectionIDFieldTypes,\n tab.fields,\n interfaceNameDefinitions,\n config,\n )\n if (tabHasName(tab)) {\n // could have interface\n fieldSchemas.set(tab.name, {\n type: 'object',\n additionalProperties: false,\n ...childSchema,\n })\n requiredFieldNames.add(tab.name)\n } else {\n Object.entries(childSchema.properties).forEach(([propName, propSchema]) => {\n fieldSchemas.set(propName, propSchema)\n })\n childSchema.required.forEach((propName) => {\n requiredFieldNames.add(propName)\n })\n }\n })\n break\n }\n\n case 'group': {\n fieldSchema = {\n type: 'object',\n additionalProperties: false,\n ...fieldsToJSONSchema(\n collectionIDFieldTypes,\n field.fields,\n interfaceNameDefinitions,\n config,\n ),\n }\n\n if (field.interfaceName) {\n interfaceNameDefinitions.set(field.interfaceName, fieldSchema)\n\n fieldSchema = {\n $ref: `#/definitions/${field.interfaceName}`,\n }\n }\n break\n }\n\n default: {\n break\n }\n }\n\n if (fieldSchema && fieldAffectsData(field)) {\n fieldSchemas.set(field.name, fieldSchema)\n }\n\n return fieldSchemas\n }, new Map<string, JSONSchema4>()),\n ),\n required: Array.from(requiredFieldNames),\n }\n}\n\n// This function is part of the public API and is exported through payload/utilities\nexport function entityToJSONSchema(\n config: SanitizedConfig,\n incomingEntity: SanitizedCollectionConfig | SanitizedGlobalConfig,\n interfaceNameDefinitions: Map<string, JSONSchema4>,\n defaultIDType: 'number' | 'text',\n): JSONSchema4 {\n const entity: SanitizedCollectionConfig | SanitizedGlobalConfig = deepCopyObject(incomingEntity)\n const title = entity.typescript?.interface\n ? entity.typescript.interface\n : singular(toWords(entity.slug, true))\n\n const idField: FieldAffectingData = { name: 'id', type: defaultIDType as 'text', required: true }\n const customIdField = entity.fields.find(\n (field) => fieldAffectsData(field) && field.name === 'id',\n ) as FieldAffectingData\n\n if (customIdField && customIdField.type !== 'group' && customIdField.type !== 'tab') {\n customIdField.required = true\n } else {\n entity.fields.unshift(idField)\n }\n\n // mark timestamp fields required\n if ('timestamps' in entity && entity.timestamps !== false) {\n entity.fields = entity.fields.map((field) => {\n if (fieldAffectsData(field) && (field.name === 'createdAt' || field.name === 'updatedAt')) {\n return {\n ...field,\n required: true,\n }\n }\n return field\n })\n }\n\n if ('auth' in entity && entity.auth && !entity.auth?.disableLocalStrategy) {\n entity.fields.push({\n name: 'password',\n type: 'text',\n })\n }\n\n // Used for relationship fields, to determine whether to use a string or number type for the ID.\n const collectionIDFieldTypes = getCollectionIDFieldTypes({ config, defaultIDType })\n\n return {\n type: 'object',\n additionalProperties: false,\n title,\n ...fieldsToJSONSchema(collectionIDFieldTypes, entity.fields, interfaceNameDefinitions, config),\n }\n}\n\n/**\n * This is used for generating the TypeScript types (payload-types.ts) with the payload generate:types command.\n */\nexport function configToJSONSchema(\n config: SanitizedConfig,\n defaultIDType?: 'number' | 'text',\n): JSONSchema4 {\n // a mutable Map to store custom top-level `interfaceName` types. Fields with an `interfaceName` property will be moved to the top-level definitions here\n const interfaceNameDefinitions: Map<string, JSONSchema4> = new Map()\n\n // Collections and Globals have to be moved to the top-level definitions as well. Reason: The top-level type will be the `Config` type - we don't want all collection and global\n // types to be inlined inside the `Config` type\n const entityDefinitions: { [k: string]: JSONSchema4 } = [\n ...config.globals,\n ...config.collections,\n ].reduce((acc, entity) => {\n acc[entity.slug] = entityToJSONSchema(config, entity, interfaceNameDefinitions, defaultIDType)\n return acc\n }, {})\n\n return {\n additionalProperties: false,\n definitions: { ...entityDefinitions, ...Object.fromEntries(interfaceNameDefinitions) },\n // These properties here will be very simple, as all the complexity is in the definitions. These are just the properties for the top-level `Config` type\n type: 'object',\n properties: {\n collections: generateEntitySchemas(config.collections || []),\n globals: generateEntitySchemas(config.globals || []),\n locale: generateLocaleEntitySchemas(config.localization),\n user: generateAuthEntitySchemas(config.collections),\n },\n required: ['user', 'locale', 'collections', 'globals'],\n title: 'Config',\n }\n}\n"],"names":["pluralize","singular","fieldAffectsData","tabHasName","deepCopyObject","toWords","getCollectionIDFieldTypes","fieldIsRequired","field","isConditional","Boolean","admin","condition","isMarkedRequired","required","type","fields","some","subField","tabs","tab","buildOptionEnums","options","map","option","value","generateEntitySchemas","entities","properties","reduce","acc","slug","$ref","additionalProperties","Object","keys","generateLocaleEntitySchemas","localization","locales","localesFromConfig","locale","code","enum","generateAuthEntitySchemas","filter","auth","allOf","collection","oneOf","withNullableJSONSchemaType","fieldType","isRequired","fieldTypes","push","fieldsToJSONSchema","collectionIDFieldTypes","interfaceNameDefinitions","config","requiredFieldNames","Set","fromEntries","fieldSchemas","add","name","fieldSchema","hasMany","items","editor","Error","outputSchema","optionEnums","maxItems","minItems","Array","isArray","relationTo","relation","const","blocks","block","blockFieldSchemas","blockSchema","blockType","interfaceName","set","childSchema","entries","forEach","propName","propSchema","Map","from","entityToJSONSchema","incomingEntity","defaultIDType","entity","title","typescript","interface","idField","customIdField","find","unshift","timestamps","disableLocalStrategy","configToJSONSchema","entityDefinitions","globals","collections","definitions","user"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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ig } from '../config/sanitize.js';
|
|
2
2
|
import { configToJSONSchema } from './configToJSONSchema.js';
|
|
3
3
|
describe('configToJSONSchema', ()=>{
|
|
4
|
-
it('should handle optional arrays with required fields', ()=>{
|
|
4
|
+
it('should handle optional arrays with required fields', async ()=>{
|
|
5
5
|
const config = {
|
|
6
6
|
collections: [
|
|
7
7
|
{
|
|
@@ -23,7 +23,7 @@ describe('configToJSONSchema', ()=>{
|
|
|
23
23
|
}
|
|
24
24
|
]
|
|
25
25
|
};
|
|
26
|
-
const sanitizedConfig = sanitizeConfig(config);
|
|
26
|
+
const sanitizedConfig = await sanitizeConfig(config);
|
|
27
27
|
const schema = configToJSONSchema(sanitizedConfig, 'text');
|
|
28
28
|
expect(schema?.definitions?.test).toStrictEqual({
|
|
29
29
|
additionalProperties: false,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/configToJSONSchema.spec.ts"],"sourcesContent":["import type { Config } from '../config/types.js'\n\nimport { sanitizeConfig } from '../config/sanitize.js'\nimport { configToJSONSchema } from './configToJSONSchema.js'\n\ndescribe('configToJSONSchema', () => {\n it('should handle optional arrays with required fields', () => {\n const config: Config = {\n collections: [\n {\n fields: [\n {\n name: 'someRequiredField',\n type: 'array',\n fields: [\n {\n name: 'someRequiredField',\n required: true,\n type: 'text',\n },\n ],\n },\n ],\n slug: 'test',\n timestamps: false,\n },\n ],\n }\n\n const sanitizedConfig = sanitizeConfig(config)\n const schema = configToJSONSchema(sanitizedConfig, 'text')\n\n expect(schema?.definitions?.test).toStrictEqual({\n additionalProperties: false,\n properties: {\n id: {\n type: 'string',\n },\n someRequiredField: {\n items: {\n additionalProperties: false,\n properties: {\n id: {\n type: ['string', 'null'],\n },\n someRequiredField: {\n type: 'string',\n },\n },\n required: ['someRequiredField'],\n type: 'object',\n },\n type: ['array', 'null'],\n },\n },\n required: ['id'],\n title: 'Test',\n type: 'object',\n })\n })\n})\n"],"names":["sanitizeConfig","configToJSONSchema","describe","it","config","collections","fields","name","type","required","slug","timestamps","sanitizedConfig","schema","expect","definitions","test","toStrictEqual","additionalProperties","properties","id","someRequiredField","items","title"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAEA,SAASA,cAAc,QAAQ,wBAAuB;AACtD,SAASC,kBAAkB,QAAQ,0BAAyB;AAE5DC,SAAS,sBAAsB;IAC7BC,GAAG,sDAAsD;QACvD,MAAMC,SAAiB;YACrBC,aAAa;gBACX;oBACEC,QAAQ;wBACN;4BACEC,MAAM;4BACNC,MAAM;4BACNF,QAAQ;gCACN;oCACEC,MAAM;oCACNE,UAAU;oCACVD,MAAM;gCACR;6BACD;wBACH;qBACD;oBACDE,MAAM;oBACNC,YAAY;gBACd;aACD;QACH;QAEA,MAAMC,
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/configToJSONSchema.spec.ts"],"sourcesContent":["import type { Config } from '../config/types.js'\n\nimport { sanitizeConfig } from '../config/sanitize.js'\nimport { configToJSONSchema } from './configToJSONSchema.js'\n\ndescribe('configToJSONSchema', () => {\n it('should handle optional arrays with required fields', async () => {\n const config: Config = {\n collections: [\n {\n fields: [\n {\n name: 'someRequiredField',\n type: 'array',\n fields: [\n {\n name: 'someRequiredField',\n required: true,\n type: 'text',\n },\n ],\n },\n ],\n slug: 'test',\n timestamps: false,\n },\n ],\n }\n\n const sanitizedConfig = await sanitizeConfig(config)\n const schema = configToJSONSchema(sanitizedConfig, 'text')\n\n expect(schema?.definitions?.test).toStrictEqual({\n additionalProperties: false,\n properties: {\n id: {\n type: 'string',\n },\n someRequiredField: {\n items: {\n additionalProperties: false,\n properties: {\n id: {\n type: ['string', 'null'],\n },\n someRequiredField: {\n type: 'string',\n },\n },\n required: ['someRequiredField'],\n type: 'object',\n },\n type: ['array', 'null'],\n },\n },\n required: ['id'],\n title: 'Test',\n type: 'object',\n })\n })\n})\n"],"names":["sanitizeConfig","configToJSONSchema","describe","it","config","collections","fields","name","type","required","slug","timestamps","sanitizedConfig","schema","expect","definitions","test","toStrictEqual","additionalProperties","properties","id","someRequiredField","items","title"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAEA,SAASA,cAAc,QAAQ,wBAAuB;AACtD,SAASC,kBAAkB,QAAQ,0BAAyB;AAE5DC,SAAS,sBAAsB;IAC7BC,GAAG,sDAAsD;QACvD,MAAMC,SAAiB;YACrBC,aAAa;gBACX;oBACEC,QAAQ;wBACN;4BACEC,MAAM;4BACNC,MAAM;4BACNF,QAAQ;gCACN;oCACEC,MAAM;oCACNE,UAAU;oCACVD,MAAM;gCACR;6BACD;wBACH;qBACD;oBACDE,MAAM;oBACNC,YAAY;gBACd;aACD;QACH;QAEA,MAAMC,kBAAkB,MAAMZ,eAAeI;QAC7C,MAAMS,SAASZ,mBAAmBW,iBAAiB;QAEnDE,OAAOD,QAAQE,aAAaC,MAAMC,aAAa,CAAC;YAC9CC,sBAAsB;YACtBC,YAAY;gBACVC,IAAI;oBACFZ,MAAM;gBACR;gBACAa,mBAAmB;oBACjBC,OAAO;wBACLJ,sBAAsB;wBACtBC,YAAY;4BACVC,IAAI;gCACFZ,MAAM;oCAAC;oCAAU;iCAAO;4BAC1B;4BACAa,mBAAmB;gCACjBb,MAAM;4BACR;wBACF;wBACAC,UAAU;4BAAC;yBAAoB;wBAC/BD,MAAM;oBACR;oBACAA,MAAM;wBAAC;wBAAS;qBAAO;gBACzB;YACF;YACAC,UAAU;gBAAC;aAAK;YAChBc,OAAO;YACPf,MAAM;QACR;IACF;AACF"}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import type { User } from '../auth/types.js';
|
|
2
2
|
import type { Payload, RequestContext } from '../index.js';
|
|
3
|
-
import type {
|
|
3
|
+
import type { PayloadRequestWithData } from '../types/index.js';
|
|
4
4
|
type CreateLocalReq = (options: {
|
|
5
5
|
context?: RequestContext;
|
|
6
6
|
fallbackLocale?: string;
|
|
7
7
|
locale?: string;
|
|
8
|
-
req?:
|
|
8
|
+
req?: PayloadRequestWithData;
|
|
9
9
|
user?: User;
|
|
10
|
-
}, payload: Payload) => Promise<
|
|
10
|
+
}, payload: Payload) => Promise<PayloadRequestWithData>;
|
|
11
11
|
export declare const createLocalReq: CreateLocalReq;
|
|
12
12
|
export {};
|
|
13
13
|
//# sourceMappingURL=createLocalReq.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createLocalReq.d.ts","sourceRoot":"","sources":["../../src/utilities/createLocalReq.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAA;AAC5C,OAAO,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAC1D,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"createLocalReq.d.ts","sourceRoot":"","sources":["../../src/utilities/createLocalReq.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAA;AAC5C,OAAO,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAC1D,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAA;AAsD/D,KAAK,cAAc,GAAG,CACpB,OAAO,EAAE;IACP,OAAO,CAAC,EAAE,cAAc,CAAA;IACxB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,GAAG,CAAC,EAAE,sBAAsB,CAAA;IAC5B,IAAI,CAAC,EAAE,IAAI,CAAA;CACZ,EACD,OAAO,EAAE,OAAO,KACb,OAAO,CAAC,sBAAsB,CAAC,CAAA;AACpC,eAAO,MAAM,cAAc,EAAE,cAmC5B,CAAA"}
|
|
@@ -22,7 +22,7 @@ const attachFakeURLProperties = (req)=>{
|
|
|
22
22
|
* *NOTE*
|
|
23
23
|
* If no URL is provided, the local API was called directly outside
|
|
24
24
|
* the context of a request. Therefore we create a fake URL object.
|
|
25
|
-
* `ts-
|
|
25
|
+
* `ts-expect-error` is used below for properties that are 'read-only'
|
|
26
26
|
* since they do not exist yet we can safely ignore the error.
|
|
27
27
|
*/ let urlObject;
|
|
28
28
|
function getURLObject() {
|
|
@@ -43,7 +43,7 @@ const attachFakeURLProperties = (req)=>{
|
|
|
43
43
|
// @ts-expect-error
|
|
44
44
|
if (!req.origin) req.origin = getURLObject().origin;
|
|
45
45
|
// @ts-expect-error
|
|
46
|
-
if (!req?.url) req.url = getURLObject().
|
|
46
|
+
if (!req?.url) req.url = getURLObject().href;
|
|
47
47
|
};
|
|
48
48
|
export const createLocalReq = async ({ context, fallbackLocale, locale: localeArg, req = {}, user }, payload)=>{
|
|
49
49
|
const i18n = req?.i18n || await getLocalI18n({
|
|
@@ -60,6 +60,8 @@ export const createLocalReq = async ({ context, fallbackLocale, locale: localeAr
|
|
|
60
60
|
req.fallbackLocale = fallbackLocaleFromConfig || defaultLocale;
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
|
+
// @ts-expect-error
|
|
64
|
+
if (!req.headers) req.headers = new Headers();
|
|
63
65
|
req.context = getRequestContext(req, context);
|
|
64
66
|
req.payloadAPI = req?.payloadAPI || 'local';
|
|
65
67
|
req.payload = payload;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/createLocalReq.ts"],"sourcesContent":["import type { User } from '../auth/types.js'\nimport type { Payload, RequestContext } from '../index.js'\nimport type {
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/createLocalReq.ts"],"sourcesContent":["import type { User } from '../auth/types.js'\nimport type { Payload, RequestContext } from '../index.js'\nimport type { PayloadRequestWithData } from '../types/index.js'\n\nimport { getDataLoader } from '../collections/dataloader.js'\nimport { getLocalI18n } from '../translations/getLocalI18n.js'\n\nfunction getRequestContext(\n req: PayloadRequestWithData = { context: null } as PayloadRequestWithData,\n context: RequestContext = {},\n): RequestContext {\n if (req.context) {\n if (Object.keys(req.context).length === 0 && req.context.constructor === Object) {\n // if req.context is `{}` avoid unnecessary spread\n return context\n } else {\n return { ...req.context, ...context }\n }\n } else {\n return context\n }\n}\n\nconst attachFakeURLProperties = (req: PayloadRequestWithData) => {\n /**\n * *NOTE*\n * If no URL is provided, the local API was called directly outside\n * the context of a request. Therefore we create a fake URL object.\n * `ts-expect-error` is used below for properties that are 'read-only'\n * since they do not exist yet we can safely ignore the error.\n */\n let urlObject\n\n function getURLObject() {\n if (urlObject) return urlObject\n const urlToUse = req?.url || req.payload.config?.serverURL || 'http://localhost'\n try {\n urlObject = new URL(urlToUse)\n } catch (error) {\n urlObject = new URL('http://localhost')\n }\n\n return urlObject\n }\n\n if (!req.host) req.host = getURLObject().host\n if (!req.protocol) req.protocol = getURLObject().protocol\n if (!req.pathname) req.pathname = getURLObject().pathname\n // @ts-expect-error\n if (!req.searchParams) req.searchParams = getURLObject().searchParams\n // @ts-expect-error\n if (!req.origin) req.origin = getURLObject().origin\n // @ts-expect-error\n if (!req?.url) req.url = getURLObject().href\n}\n\ntype CreateLocalReq = (\n options: {\n context?: RequestContext\n fallbackLocale?: string\n locale?: string\n req?: PayloadRequestWithData\n user?: User\n },\n payload: Payload,\n) => Promise<PayloadRequestWithData>\nexport const createLocalReq: CreateLocalReq = async (\n { context, fallbackLocale, locale: localeArg, req = {} as PayloadRequestWithData, user },\n payload,\n) => {\n const i18n = req?.i18n || (await getLocalI18n({ config: payload.config }))\n\n if (payload.config?.localization) {\n const locale = localeArg === '*' ? 'all' : localeArg\n const defaultLocale = payload.config.localization.defaultLocale\n req.locale = locale || req?.locale || defaultLocale\n const fallbackLocaleFromConfig = payload.config.localization.locales.find(\n ({ code }) => req.locale === code,\n )?.fallbackLocale\n if (typeof fallbackLocale !== 'undefined') {\n req.fallbackLocale = fallbackLocale\n } else if (typeof req?.fallbackLocale === 'undefined') {\n req.fallbackLocale = fallbackLocaleFromConfig || defaultLocale\n }\n }\n\n // @ts-expect-error\n if (!req.headers) req.headers = new Headers()\n req.context = getRequestContext(req, context)\n req.payloadAPI = req?.payloadAPI || 'local'\n req.payload = payload\n req.i18n = i18n\n req.t = i18n.t\n req.user = user || req?.user || null\n req.payloadDataLoader = req?.payloadDataLoader || getDataLoader(req)\n req.routeParams = req?.routeParams || {}\n req.query = req?.query || {}\n\n attachFakeURLProperties(req)\n\n return req\n}\n"],"names":["getDataLoader","getLocalI18n","getRequestContext","req","context","Object","keys","length","constructor","attachFakeURLProperties","urlObject","getURLObject","urlToUse","url","payload","config","serverURL","URL","error","host","protocol","pathname","searchParams","origin","href","createLocalReq","fallbackLocale","locale","localeArg","user","i18n","localization","defaultLocale","fallbackLocaleFromConfig","locales","find","code","headers","Headers","payloadAPI","t","payloadDataLoader","routeParams","query"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAIA,SAASA,aAAa,QAAQ,+BAA8B;AAC5D,SAASC,YAAY,QAAQ,kCAAiC;AAE9D,SAASC,kBACPC,MAA8B;IAAEC,SAAS;AAAK,CAA2B,EACzEA,UAA0B,CAAC,CAAC;IAE5B,IAAID,IAAIC,OAAO,EAAE;QACf,IAAIC,OAAOC,IAAI,CAACH,IAAIC,OAAO,EAAEG,MAAM,KAAK,KAAKJ,IAAIC,OAAO,CAACI,WAAW,KAAKH,QAAQ;YAC/E,kDAAkD;YAClD,OAAOD;QACT,OAAO;YACL,OAAO;gBAAE,GAAGD,IAAIC,OAAO;gBAAE,GAAGA,OAAO;YAAC;QACtC;IACF,OAAO;QACL,OAAOA;IACT;AACF;AAEA,MAAMK,0BAA0B,CAACN;IAC/B;;;;;;GAMC,GACD,IAAIO;IAEJ,SAASC;QACP,IAAID,WAAW,OAAOA;QACtB,MAAME,WAAWT,KAAKU,OAAOV,IAAIW,OAAO,CAACC,MAAM,EAAE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ACzCvB,IAAIuB,cAAc,GAAGA;QACvB,OAAO,IAAI,OAAOvB,KAAKuB,mBAAmB,aAAa;YACrDvB,IAAIuB,cAAc,GAAGO,4BAA4BD;QACnD;IACF;IAEA,mBAAmB;IACnB,IAAI,CAAC7B,IAAIkC,OAAO,EAAElC,IAAIkC,OAAO,GAAG,IAAIC;IACpCnC,IAAIC,OAAO,GAAGF,kBAAkBC,KAAKC;IACrCD,IAAIoC,UAAU,GAAGpC,KAAKoC,cAAc;IACpCpC,IAAIW,OAAO,GAAGA;IACdX,IAAI2B,IAAI,GAAGA;IACX3B,IAAIqC,CAAC,GAAGV,KAAKU,CAAC;IACdrC,IAAI0B,IAAI,GAAGA,QAAQ1B,KAAK0B,QAAQ;IAChC1B,IAAIsC,iBAAiB,GAAGtC,KAAKsC,qBAAqBzC,cAAcG;IAChEA,IAAIuC,WAAW,GAAGvC,KAAKuC,eAAe,CAAC;IACvCvC,IAAIwC,KAAK,GAAGxC,KAAKwC,SAAS,CAAC;IAE3BlC,wBAAwBN;IAExB,OAAOA;AACT,EAAC"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { CollectionPermission, GlobalPermission } from '../auth/types.js';
|
|
2
2
|
import type { SanitizedCollectionConfig } from '../collections/config/types.js';
|
|
3
3
|
import type { SanitizedGlobalConfig } from '../globals/config/types.js';
|
|
4
|
-
import type { AllOperations,
|
|
4
|
+
import type { AllOperations, PayloadRequestWithData } from '../types/index.js';
|
|
5
5
|
type Args = {
|
|
6
6
|
entity: SanitizedCollectionConfig | SanitizedGlobalConfig;
|
|
7
7
|
id?: number | string;
|
|
8
8
|
operations: AllOperations[];
|
|
9
|
-
req:
|
|
9
|
+
req: PayloadRequestWithData;
|
|
10
10
|
type: 'collection' | 'global';
|
|
11
11
|
};
|
|
12
12
|
type ReturnType<T extends Args> = T['type'] extends 'global' ? GlobalPermission : CollectionPermission;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getEntityPolicies.d.ts","sourceRoot":"","sources":["../../src/utilities/getEntityPolicies.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;AAC9E,OAAO,KAAK,EAAE,yBAAyB,EAAc,MAAM,gCAAgC,CAAA;AAG3F,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAA;AACvE,OAAO,KAAK,EAAE,aAAa,EAAY,
|
|
1
|
+
{"version":3,"file":"getEntityPolicies.d.ts","sourceRoot":"","sources":["../../src/utilities/getEntityPolicies.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;AAC9E,OAAO,KAAK,EAAE,yBAAyB,EAAc,MAAM,gCAAgC,CAAA;AAG3F,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAA;AACvE,OAAO,KAAK,EAAE,aAAa,EAAY,sBAAsB,EAAS,MAAM,mBAAmB,CAAA;AAI/F,KAAK,IAAI,GAAG;IACV,MAAM,EAAE,yBAAyB,GAAG,qBAAqB,CAAA;IACzD,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IACpB,UAAU,EAAE,aAAa,EAAE,CAAA;IAC3B,GAAG,EAAE,sBAAsB,CAAA;IAC3B,IAAI,EAAE,YAAY,GAAG,QAAQ,CAAA;CAC9B,CAAA;AAED,KAAK,UAAU,CAAC,CAAC,SAAS,IAAI,IAAI,CAAC,CAAC,MAAM,CAAC,SAAS,QAAQ,GACxD,gBAAgB,GAChB,oBAAoB,CAAA;AAYxB,wBAAsB,iBAAiB,CAAC,CAAC,SAAS,IAAI,EAAE,IAAI,EAAE,CAAC,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CA4NvF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/getEntityPolicies.ts"],"sourcesContent":["import type { CollectionPermission, GlobalPermission } from '../auth/types.js'\nimport type { SanitizedCollectionConfig, TypeWithID } from '../collections/config/types.js'\nimport type { Access } from '../config/types.js'\nimport type { FieldAccess } from '../fields/config/types.js'\nimport type { SanitizedGlobalConfig } from '../globals/config/types.js'\nimport type { AllOperations, Document, PayloadRequest, Where } from '../types/index.js'\n\nimport { tabHasName } from '../fields/config/types.js'\n\ntype Args = {\n entity: SanitizedCollectionConfig | SanitizedGlobalConfig\n id?: number | string\n operations: AllOperations[]\n req: PayloadRequest\n type: 'collection' | 'global'\n}\n\ntype ReturnType<T extends Args> = T['type'] extends 'global'\n ? GlobalPermission\n : CollectionPermission\n\ntype CreateAccessPromise = (args: {\n access: Access | FieldAccess\n accessLevel: 'entity' | 'field'\n disableWhere?: boolean\n operation: AllOperations\n policiesObj: {\n [key: string]: any\n }\n}) => Promise<void>\n\nexport async function getEntityPolicies<T extends Args>(args: T): Promise<ReturnType<T>> {\n const { id, type, entity, operations, req } = args\n const { data, payload, user } = req\n const isLoggedIn = !!user\n\n const policies = {\n fields: {},\n } as ReturnType<T>\n\n let docBeingAccessed\n\n async function getEntityDoc({ where }: { where?: Where } = {}): Promise<TypeWithID & Document> {\n if (entity.slug) {\n if (type === 'global') {\n return payload.findGlobal({\n slug: entity.slug,\n overrideAccess: true,\n req,\n })\n }\n\n if (type === 'collection' && id) {\n if (typeof where === 'object') {\n const paginatedRes = await payload.find({\n collection: entity.slug,\n depth: 0,\n limit: 1,\n overrideAccess: true,\n pagination: false,\n req,\n where: {\n ...where,\n and: [\n ...(where.and || []),\n {\n id: {\n equals: id,\n },\n },\n ],\n },\n })\n\n return paginatedRes?.docs?.[0] || undefined\n }\n\n return payload.findByID({\n id,\n collection: entity.slug,\n depth: 0,\n overrideAccess: true,\n req,\n })\n }\n }\n\n return undefined\n }\n\n const createAccessPromise: CreateAccessPromise = async ({\n access,\n accessLevel,\n disableWhere = false,\n operation,\n policiesObj,\n }) => {\n const mutablePolicies = policiesObj\n\n if (accessLevel === 'field' && docBeingAccessed === undefined) {\n // assign docBeingAccessed first as the promise to avoid multiple calls to getEntityDoc\n docBeingAccessed = getEntityDoc().then((doc) => {\n docBeingAccessed = doc\n })\n }\n // awaiting the promise to ensure docBeingAccessed is assigned before it is used\n await docBeingAccessed\n\n // https://payloadcms.slack.com/archives/C048Z9C2BEX/p1702054928343769\n const accessResult = await access({ id, data, doc: docBeingAccessed, req })\n\n if (typeof accessResult === 'object' && !disableWhere) {\n mutablePolicies[operation] = {\n permission:\n id || type === 'global' ? !!(await getEntityDoc({ where: accessResult })) : true,\n where: accessResult,\n }\n } else if (mutablePolicies[operation]?.permission !== false) {\n mutablePolicies[operation] = {\n permission: !!accessResult,\n }\n }\n }\n\n const executeFieldPolicies = async ({ entityPermission, fields, operation, policiesObj }) => {\n const mutablePolicies = policiesObj.fields\n\n await Promise.all(\n fields.map(async (field) => {\n if (field.name) {\n if (!mutablePolicies[field.name]) mutablePolicies[field.name] = {}\n\n if (field.access && typeof field.access[operation] === 'function') {\n await createAccessPromise({\n access: field.access[operation],\n accessLevel: 'field',\n disableWhere: true,\n operation,\n policiesObj: mutablePolicies[field.name],\n })\n } else {\n mutablePolicies[field.name][operation] = {\n permission: policiesObj[operation]?.permission,\n }\n }\n\n if (field.fields) {\n if (!mutablePolicies[field.name].fields) mutablePolicies[field.name].fields = {}\n\n await executeFieldPolicies({\n entityPermission,\n fields: field.fields,\n operation,\n policiesObj: mutablePolicies[field.name],\n })\n }\n\n if (field?.blocks) {\n if (!mutablePolicies[field.name]?.blocks) mutablePolicies[field.name].blocks = {}\n\n await Promise.all(\n field.blocks.map(async (block) => {\n if (!mutablePolicies[field.name].blocks?.[block.slug]) {\n mutablePolicies[field.name].blocks[block.slug] = {\n fields: {},\n [operation]: { permission: entityPermission },\n }\n } else if (!mutablePolicies[field.name].blocks[block.slug][operation]) {\n mutablePolicies[field.name].blocks[block.slug][operation] = {\n permission: entityPermission,\n }\n }\n\n await executeFieldPolicies({\n entityPermission,\n fields: block.fields,\n operation,\n policiesObj: mutablePolicies[field.name].blocks[block.slug],\n })\n }),\n )\n }\n } else if (field.fields) {\n await executeFieldPolicies({\n entityPermission,\n fields: field.fields,\n operation,\n policiesObj,\n })\n } else if (field.type === 'tabs') {\n await Promise.all(\n field.tabs.map(async (tab) => {\n if (tabHasName(tab)) {\n if (!mutablePolicies[tab.name]) {\n mutablePolicies[tab.name] = {\n fields: {},\n [operation]: { permission: entityPermission },\n }\n } else if (!mutablePolicies[tab.name][operation]) {\n mutablePolicies[tab.name][operation] = { permission: entityPermission }\n }\n await executeFieldPolicies({\n entityPermission,\n fields: tab.fields,\n operation,\n policiesObj: mutablePolicies[tab.name],\n })\n } else {\n await executeFieldPolicies({\n entityPermission,\n fields: tab.fields,\n operation,\n policiesObj,\n })\n }\n }),\n )\n }\n }),\n )\n }\n\n await operations.reduce(async (priorOperation, operation) => {\n await priorOperation\n\n let entityAccessPromise: Promise<void>\n\n if (typeof entity.access[operation] === 'function') {\n entityAccessPromise = createAccessPromise({\n access: entity.access[operation],\n accessLevel: 'entity',\n operation,\n policiesObj: policies,\n })\n } else {\n policies[operation] = {\n permission: isLoggedIn,\n }\n }\n\n await entityAccessPromise\n\n await executeFieldPolicies({\n entityPermission: policies[operation].permission,\n fields: entity.fields,\n operation,\n policiesObj: policies,\n })\n }, Promise.resolve())\n\n return policies\n}\n"],"names":["tabHasName","getEntityPolicies","args","id","type","entity","operations","req","data","payload","user","isLoggedIn","policies","fields","docBeingAccessed","getEntityDoc","where","slug","findGlobal","overrideAccess","paginatedRes","find","collection","depth","limit","pagination","and","equals","docs","undefined","findByID","createAccessPromise","access","accessLevel","disableWhere","operation","policiesObj","mutablePolicies","then","doc","accessResult","permission","executeFieldPolicies","entityPermission","Promise","all","map","field","name","blocks","block","tabs","tab","reduce","priorOperation","entityAccessPromise","resolve"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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B,MAAM,CAACG,UAAU;gBAChCF,aAAa;gBACbE;gBACAC,aAAaxB;YACf;QACF,OAAO;YACLA,QAAQ,CAACuB,UAAU,GAAG;gBACpBM,YAAY9B;YACd;QACF;QAEA,MAAM4C;QAEN,MAAMb,qBAAqB;YACzBC,kBAAkB/B,QAAQ,CAACuB,UAAU,CAACM,UAAU;YAChD5B,QAAQR,OAAOQ,MAAM;YACrBsB;YACAC,aAAaxB;QACf;IACF,GAAGgC,QAAQY,OAAO;IAElB,OAAO5C;AACT"}
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/getEntityPolicies.ts"],"sourcesContent":["import type { CollectionPermission, GlobalPermission } from '../auth/types.js'\nimport type { SanitizedCollectionConfig, TypeWithID } from '../collections/config/types.js'\nimport type { Access } from '../config/types.js'\nimport type { FieldAccess } from '../fields/config/types.js'\nimport type { SanitizedGlobalConfig } from '../globals/config/types.js'\nimport type { AllOperations, Document, PayloadRequestWithData, Where } from '../types/index.js'\n\nimport { tabHasName } from '../fields/config/types.js'\n\ntype Args = {\n entity: SanitizedCollectionConfig | SanitizedGlobalConfig\n id?: number | string\n operations: AllOperations[]\n req: PayloadRequestWithData\n type: 'collection' | 'global'\n}\n\ntype ReturnType<T extends Args> = T['type'] extends 'global'\n ? GlobalPermission\n : CollectionPermission\n\ntype CreateAccessPromise = (args: {\n access: Access | FieldAccess\n accessLevel: 'entity' | 'field'\n disableWhere?: boolean\n operation: AllOperations\n policiesObj: {\n [key: string]: any\n }\n}) => Promise<void>\n\nexport async function getEntityPolicies<T extends Args>(args: T): Promise<ReturnType<T>> {\n const { id, type, entity, operations, req } = args\n const { data, payload, user } = req\n const isLoggedIn = !!user\n\n const policies = {\n fields: {},\n } as ReturnType<T>\n\n let docBeingAccessed\n\n async function getEntityDoc({ where }: { where?: Where } = {}): Promise<TypeWithID & Document> {\n if (entity.slug) {\n if (type === 'global') {\n return payload.findGlobal({\n slug: entity.slug,\n overrideAccess: true,\n req,\n })\n }\n\n if (type === 'collection' && id) {\n if (typeof where === 'object') {\n const paginatedRes = await payload.find({\n collection: entity.slug,\n depth: 0,\n limit: 1,\n overrideAccess: true,\n pagination: false,\n req,\n where: {\n ...where,\n and: [\n ...(where.and || []),\n {\n id: {\n equals: id,\n },\n },\n ],\n },\n })\n\n return paginatedRes?.docs?.[0] || undefined\n }\n\n return payload.findByID({\n id,\n collection: entity.slug,\n depth: 0,\n overrideAccess: true,\n req,\n })\n }\n }\n\n return undefined\n }\n\n const createAccessPromise: CreateAccessPromise = async ({\n access,\n accessLevel,\n disableWhere = false,\n operation,\n policiesObj,\n }) => {\n const mutablePolicies = policiesObj\n\n if (accessLevel === 'field' && docBeingAccessed === undefined) {\n // assign docBeingAccessed first as the promise to avoid multiple calls to getEntityDoc\n docBeingAccessed = getEntityDoc().then((doc) => {\n docBeingAccessed = doc\n })\n }\n // awaiting the promise to ensure docBeingAccessed is assigned before it is used\n await docBeingAccessed\n\n // https://payloadcms.slack.com/archives/C048Z9C2BEX/p1702054928343769\n const accessResult = await access({ id, data, doc: docBeingAccessed, req })\n\n if (typeof accessResult === 'object' && !disableWhere) {\n mutablePolicies[operation] = {\n permission:\n id || type === 'global' ? !!(await getEntityDoc({ where: accessResult })) : true,\n where: accessResult,\n }\n } else if (mutablePolicies[operation]?.permission !== false) {\n mutablePolicies[operation] = {\n permission: !!accessResult,\n }\n }\n }\n\n const executeFieldPolicies = async ({ entityPermission, fields, operation, policiesObj }) => {\n const mutablePolicies = policiesObj.fields\n\n await Promise.all(\n fields.map(async (field) => {\n if (field.name) {\n if (!mutablePolicies[field.name]) mutablePolicies[field.name] = {}\n\n if (field.access && typeof field.access[operation] === 'function') {\n await createAccessPromise({\n access: field.access[operation],\n accessLevel: 'field',\n disableWhere: true,\n operation,\n policiesObj: mutablePolicies[field.name],\n })\n } else {\n mutablePolicies[field.name][operation] = {\n permission: policiesObj[operation]?.permission,\n }\n }\n\n if (field.fields) {\n if (!mutablePolicies[field.name].fields) mutablePolicies[field.name].fields = {}\n\n await executeFieldPolicies({\n entityPermission,\n fields: field.fields,\n operation,\n policiesObj: mutablePolicies[field.name],\n })\n }\n\n if (field?.blocks) {\n if (!mutablePolicies[field.name]?.blocks) mutablePolicies[field.name].blocks = {}\n\n await Promise.all(\n field.blocks.map(async (block) => {\n if (!mutablePolicies[field.name].blocks?.[block.slug]) {\n mutablePolicies[field.name].blocks[block.slug] = {\n fields: {},\n [operation]: { permission: entityPermission },\n }\n } else if (!mutablePolicies[field.name].blocks[block.slug][operation]) {\n mutablePolicies[field.name].blocks[block.slug][operation] = {\n permission: entityPermission,\n }\n }\n\n await executeFieldPolicies({\n entityPermission,\n fields: block.fields,\n operation,\n policiesObj: mutablePolicies[field.name].blocks[block.slug],\n })\n }),\n )\n }\n } else if (field.fields) {\n await executeFieldPolicies({\n entityPermission,\n fields: field.fields,\n operation,\n policiesObj,\n })\n } else if (field.type === 'tabs') {\n await Promise.all(\n field.tabs.map(async (tab) => {\n if (tabHasName(tab)) {\n if (!mutablePolicies[tab.name]) {\n mutablePolicies[tab.name] = {\n fields: {},\n [operation]: { permission: entityPermission },\n }\n } else if (!mutablePolicies[tab.name][operation]) {\n mutablePolicies[tab.name][operation] = { permission: entityPermission }\n }\n await executeFieldPolicies({\n entityPermission,\n fields: tab.fields,\n operation,\n policiesObj: mutablePolicies[tab.name],\n })\n } else {\n await executeFieldPolicies({\n entityPermission,\n fields: tab.fields,\n operation,\n policiesObj,\n })\n }\n }),\n )\n }\n }),\n )\n }\n\n await operations.reduce(async (priorOperation, operation) => {\n await priorOperation\n\n let entityAccessPromise: Promise<void>\n\n if (typeof entity.access[operation] === 'function') {\n entityAccessPromise = createAccessPromise({\n access: entity.access[operation],\n accessLevel: 'entity',\n operation,\n policiesObj: policies,\n })\n } else {\n policies[operation] = {\n permission: isLoggedIn,\n }\n }\n\n await entityAccessPromise\n\n await executeFieldPolicies({\n entityPermission: policies[operation].permission,\n fields: entity.fields,\n operation,\n policiesObj: policies,\n })\n }, Promise.resolve())\n\n return policies\n}\n"],"names":["tabHasName","getEntityPolicies","args","id","type","entity","operations","req","data","payload","user","isLoggedIn","policies","fields","docBeingAccessed","getEntityDoc","where","slug","findGlobal","overrideAccess","paginatedRes","find","collection","depth","limit","pagination","and","equals","docs","undefined","findByID","createAccessPromise","access","accessLevel","disableWhere","operation","policiesObj","mutablePolicies","then","doc","accessResult","permission","executeFieldPolicies","entityPermission","Promise","all","map","field","name","blocks","block","tabs","tab","reduce","priorOperation","entityAccessPromise","resolve"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAOA,SAASA,UAAU,QAAQ,4BAA2B;AAwBtD,OAAO,eAAeC,kBAAkCC,IAAO;IAC7D,MAAM,EAAEC,EAAE,EAAEC,IAAI,EAAEC,MAAM,EAAEC,UAAU,EAAEC,GAAG,EAAE,GAAGL;IAC9C,MAAM,EAAEM,IAAI,EAAEC,OAAO,EAAEC,IAAI,EAAE,GAAGH;IAChC,MAAMI,aAAa,CAAC,CAACD;IAErB,MAAME,WAAW;QACfC,QAAQ,CAAC;IACX;IAEA,IAAIC;IAEJ,eAAeC,aAAa,EAAEC,KAAK,EAAqB,GAAG,CAAC,CAAC;QAC3D,IAAIX,OAAOY,IAAI,EAAE;YACf,IAAIb,SAAS,UAAU;gBACrB,OAAOK,QAAQS,UAAU,CAAC;oBACxBD,MAAMZ,OAAOY,IAAI;oBACjBE,gBAAgB;oBAChBZ;gBACF;YACF;YAEA,IAAIH,SAAS,gBAAgBD,IAAI;gBAC/B,IAAI,OAAOa,UAAU,UAAU;oBAC7B,MAAMI,eAAe,MAAMX,QAAQY,IAAI,CAAC;wBACtCC,YAAYjB,OAAOY,IA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IAAIvC,MAAM;4BAClBsB;4BACAC,aAAaC,eAAe,CAACe,IAAIJ,IAAI,CAAC;wBACxC;oBACF,OAAO;wBACL,MAAMN,qBAAqB;4BACzBC;4BACA9B,QAAQuC,IAAIvC,MAAM;4BAClBsB;4BACAC;wBACF;oBACF;gBACF;YAEJ;QACF;IAEJ;IAEA,MAAM9B,WAAW+C,MAAM,CAAC,OAAOC,gBAAgBnB;QAC7C,MAAMmB;QAEN,IAAIC;QAEJ,IAAI,OAAOlD,OAAO2B,MAAM,CAACG,UAAU,KAAK,YAAY;YAClDoB,sBAAsBxB,oBAAoB;gBACxCC,QAAQ3B,OAAO2B,MAAM,CAACG,UAAU;gBAChCF,aAAa;gBACbE;gBACAC,aAAaxB;YACf;QACF,OAAO;YACLA,QAAQ,CAACuB,UAAU,GAAG;gBACpBM,YAAY9B;YACd;QACF;QAEA,MAAM4C;QAEN,MAAMb,qBAAqB;YACzBC,kBAAkB/B,QAAQ,CAACuB,UAAU,CAACM,UAAU;YAChD5B,QAAQR,OAAOQ,MAAM;YACrBsB;YACAC,aAAaxB;QACf;IACF,GAAGgC,QAAQY,OAAO;IAElB,OAAO5C;AACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"importWithoutClientFiles.d.ts","sourceRoot":"","sources":["../../src/utilities/importWithoutClientFiles.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AAKzD,eAAO,MAAM,wBAAwB,0BAAiC,MAAM,
|
|
1
|
+
{"version":3,"file":"importWithoutClientFiles.d.ts","sourceRoot":"","sources":["../../src/utilities/importWithoutClientFiles.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AAKzD,eAAO,MAAM,wBAAwB,0BAAiC,MAAM,eAO3E,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,YAAY,eAAsB,MAAM,6BAmBpD,CAAA"}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { register } from 'node:module';
|
|
2
|
-
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
2
|
+
import { URL, fileURLToPath, pathToFileURL } from 'node:url';
|
|
3
3
|
import path from 'path';
|
|
4
4
|
const filename = fileURLToPath(import.meta.url);
|
|
5
5
|
const dirname = path.dirname(filename);
|
|
6
6
|
export const importWithoutClientFiles = async (filePath)=>{
|
|
7
|
-
const
|
|
8
|
-
|
|
7
|
+
const { href: filePathUrl } = pathToFileURL(filePath);
|
|
8
|
+
const { href: loaderUrl } = pathToFileURL(path.resolve(dirname, '../../dist/bin/loader/index.js'));
|
|
9
|
+
register(loaderUrl, filePathUrl);
|
|
9
10
|
const result = await import(filePath);
|
|
10
11
|
return result;
|
|
11
12
|
};
|
|
@@ -17,7 +18,9 @@ export const importWithoutClientFiles = async (filePath)=>{
|
|
|
17
18
|
const config = await importWithoutClientFiles(configPath);
|
|
18
19
|
return await config.default;
|
|
19
20
|
}
|
|
20
|
-
const
|
|
21
|
+
const callerFilename = getCallerInfo()[1].getFileName();
|
|
22
|
+
const url = new URL(callerFilename);
|
|
23
|
+
const callerDir = path.dirname(fileURLToPath(url));
|
|
21
24
|
const fullConfigPath = path.resolve(callerDir, configPath);
|
|
22
25
|
const config = await importWithoutClientFiles(fullConfigPath);
|
|
23
26
|
return await config.default;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/importWithoutClientFiles.ts"],"sourcesContent":["import { register } from 'node:module'\nimport { fileURLToPath, pathToFileURL } from 'node:url'\nimport path from 'path'\n\nimport type { SanitizedConfig } from '../config/types.js'\n\nconst filename = fileURLToPath(import.meta.url)\nconst dirname = path.dirname(filename)\n\nexport const importWithoutClientFiles = async <T = unknown>(filePath: string) => {\n const
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/importWithoutClientFiles.ts"],"sourcesContent":["import { register } from 'node:module'\nimport { URL, fileURLToPath, pathToFileURL } from 'node:url'\nimport path from 'path'\n\nimport type { SanitizedConfig } from '../config/types.js'\n\nconst filename = fileURLToPath(import.meta.url)\nconst dirname = path.dirname(filename)\n\nexport const importWithoutClientFiles = async <T = unknown>(filePath: string) => {\n const { href: filePathUrl } = pathToFileURL(filePath)\n const { href: loaderUrl } = pathToFileURL(path.resolve(dirname, '../../dist/bin/loader/index.js'))\n\n register(loaderUrl, filePathUrl)\n const result = await import(filePath)\n return result as T\n}\n\n/**\n * Resolve and load Payload config from either a relative or absolute path\n */\nexport const importConfig = async (configPath: string) => {\n const isAbsolutePath = path.isAbsolute(configPath)\n if (isAbsolutePath) {\n const config = await importWithoutClientFiles<{ default: Promise<SanitizedConfig> }>(configPath)\n return await config.default\n }\n\n const callerFilename = getCallerInfo()[1].getFileName()\n\n const url = new URL(callerFilename)\n\n const callerDir = path.dirname(fileURLToPath(url))\n\n const fullConfigPath = path.resolve(callerDir, configPath)\n\n const config = await importWithoutClientFiles<{ default: Promise<SanitizedConfig> }>(\n fullConfigPath,\n )\n return await config.default\n}\n\nconst getCallerInfo = () => {\n const _prepareStackTrace = Error.prepareStackTrace\n try {\n let result = []\n Error.prepareStackTrace = (_, callSites) => {\n const callSitesWithoutCurrent = callSites.slice(1)\n result = callSitesWithoutCurrent\n return callSitesWithoutCurrent\n }\n\n new Error().stack\n return result\n } finally {\n Error.prepareStackTrace = _prepareStackTrace\n }\n}\n"],"names":["register","URL","fileURLToPath","pathToFileURL","path","filename","url","dirname","importWithoutClientFiles","filePath","href","filePathUrl","loaderUrl","resolve","result","importConfig","configPath","isAbsolutePath","isAbsolute","config","default","callerFilename","getCallerInfo","getFileName","callerDir","fullConfigPath","_prepareStackTrace","Error","prepareStackTrace","_","callSites","callSitesWithoutCurrent","slice","stack"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,SAASA,QAAQ,QAAQ,cAAa;AACtC,SAASC,GAAG,EAAEC,aAAa,EAAEC,aAAa,QAAQ,WAAU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
3
|
* Starts a new transaction using the db adapter with a random id and then assigns it to the req.transaction
|
|
4
4
|
* @returns true if beginning a transaction and false when req already has a transaction to use
|
|
5
5
|
*/
|
|
6
|
-
export declare function initTransaction(req:
|
|
6
|
+
export declare function initTransaction(req: PayloadRequestWithData): Promise<boolean>;
|
|
7
7
|
//# sourceMappingURL=initTransaction.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"initTransaction.d.ts","sourceRoot":"","sources":["../../src/utilities/initTransaction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"initTransaction.d.ts","sourceRoot":"","sources":["../../src/utilities/initTransaction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAA;AAE/D;;;GAGG;AACH,wBAAsB,eAAe,CAAC,GAAG,EAAE,sBAAsB,GAAG,OAAO,CAAC,OAAO,CAAC,CAuBnF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/initTransaction.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/initTransaction.ts"],"sourcesContent":["import type { PayloadRequestWithData } from '../types/index.js'\n\n/**\n * Starts a new transaction using the db adapter with a random id and then assigns it to the req.transaction\n * @returns true if beginning a transaction and false when req already has a transaction to use\n */\nexport async function initTransaction(req: PayloadRequestWithData): Promise<boolean> {\n const { payload, transactionID, transactionIDPromise } = req\n if (transactionID) {\n // we already have a transaction, we're not in charge of committing it\n return false\n }\n if (transactionIDPromise) {\n // wait for whoever else is already creating the transaction\n await transactionIDPromise\n return false\n }\n if (typeof payload.db.beginTransaction === 'function') {\n // create a new transaction\n req.transactionIDPromise = payload.db.beginTransaction().then((transactionID) => {\n if (transactionID) {\n req.transactionID = transactionID\n }\n delete req.transactionIDPromise\n })\n await req.transactionIDPromise\n return !!req.transactionID\n }\n return false\n}\n"],"names":["initTransaction","req","payload","transactionID","transactionIDPromise","db","beginTransaction","then"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAEA;;;CAGC,GACD,OAAO,eAAeA,gBAAgBC,GAA2B;IAC/D,MAAM,EAAEC,OAAO,EAAEC,aAAa,EAAEC,oBAAoB,EAAE,GAAGH;IACzD,IAAIE,eAAe;QACjB,sEAAsE;QACtE,OAAO;IACT;IACA,IAAIC,sBAAsB;QACxB,4DAA4D;QAC5D,MAAMA;QACN,OAAO;IACT;IACA,IAAI,OAAOF,QAAQG,EAAE,CAACC,gBAAgB,KAAK,YAAY;QACrD,2BAA2B;QAC3BL,IAAIG,oBAAoB,GAAGF,QAAQG,EAAE,CAACC,gBAAgB,GAAGC,IAAI,CAAC,CAACJ;YAC7D,IAAIA,eAAe;gBACjBF,IAAIE,aAAa,GAAGA;YACtB;YACA,OAAOF,IAAIG,oBAAoB;QACjC;QACA,MAAMH,IAAIG,oBAAoB;QAC9B,OAAO,CAAC,CAACH,IAAIE,aAAa;IAC5B;IACA,OAAO;AACT"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { User } from 'payload/auth';
|
|
2
1
|
import type { SanitizedCollectionConfig } from '../collections/config/types.js';
|
|
3
2
|
import type { SanitizedGlobalConfig } from '../globals/config/types.js';
|
|
3
|
+
import type { PayloadRequestWithData } from '../types/index.js';
|
|
4
4
|
export declare const isEntityHidden: ({ hidden, user, }: {
|
|
5
5
|
hidden: SanitizedCollectionConfig['admin']['hidden'] | SanitizedGlobalConfig['admin']['hidden'];
|
|
6
|
-
user:
|
|
6
|
+
user: PayloadRequestWithData['user'];
|
|
7
7
|
}) => boolean;
|
|
8
8
|
//# sourceMappingURL=isEntityHidden.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isEntityHidden.d.ts","sourceRoot":"","sources":["../../src/utilities/isEntityHidden.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"isEntityHidden.d.ts","sourceRoot":"","sources":["../../src/utilities/isEntityHidden.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAA;AAC/E,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAA;AACvE,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAA;AAE/D,eAAO,MAAM,cAAc,sBAGxB;IACD,MAAM,EAAE,yBAAyB,CAAC,OAAO,CAAC,CAAC,QAAQ,CAAC,GAAG,qBAAqB,CAAC,OAAO,CAAC,CAAC,QAAQ,CAAC,CAAA;IAC/F,IAAI,EAAE,sBAAsB,CAAC,MAAM,CAAC,CAAA;CACrC,YAEA,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/isEntityHidden.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/isEntityHidden.ts"],"sourcesContent":["import type { SanitizedCollectionConfig } from '../collections/config/types.js'\nimport type { SanitizedGlobalConfig } from '../globals/config/types.js'\nimport type { PayloadRequestWithData } from '../types/index.js'\n\nexport const isEntityHidden = ({\n hidden,\n user,\n}: {\n hidden: SanitizedCollectionConfig['admin']['hidden'] | SanitizedGlobalConfig['admin']['hidden']\n user: PayloadRequestWithData['user']\n}) => {\n return typeof hidden === 'function' ? hidden({ user }) : hidden === true\n}\n"],"names":["isEntityHidden","hidden","user"],"rangeMappings":";;;;","mappings":"AAIA,OAAO,MAAMA,iBAAiB,CAAC,EAC7BC,MAAM,EACNC,IAAI,EAIL;IACC,OAAO,OAAOD,WAAW,aAAaA,OAAO;QAAEC;IAAK,KAAKD,WAAW;AACtE,EAAC"}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type React from 'react';
|
|
2
|
+
export declare function isReactServerComponent<T extends any>(component: React.ComponentType | any): component is T;
|
|
3
|
+
export declare function isReactClientComponent<T extends any>(component: React.ComponentType | any): component is T;
|
|
2
4
|
export declare function isReactComponent<T extends any>(component: React.ComponentType | any): component is T;
|
|
3
5
|
export declare function isPlainFunction<T extends Function>(fn: any): fn is T;
|
|
4
6
|
//# sourceMappingURL=isReactComponent.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isReactComponent.d.ts","sourceRoot":"","sources":["../../src/utilities/isReactComponent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAM9B,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,GAAG,EAC5C,SAAS,EAAE,KAAK,CAAC,aAAa,GAAG,GAAG,GACnC,SAAS,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"isReactComponent.d.ts","sourceRoot":"","sources":["../../src/utilities/isReactComponent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAM9B,wBAAgB,sBAAsB,CAAC,CAAC,SAAS,GAAG,EAClD,SAAS,EAAE,KAAK,CAAC,aAAa,GAAG,GAAG,GACnC,SAAS,IAAI,CAAC,CAEhB;AAED,wBAAgB,sBAAsB,CAAC,CAAC,SAAS,GAAG,EAClD,SAAS,EAAE,KAAK,CAAC,aAAa,GAAG,GAAG,GACnC,SAAS,IAAI,CAAC,CAGhB;AAED,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,GAAG,EAC5C,SAAS,EAAE,KAAK,CAAC,aAAa,GAAG,GAAG,GACnC,SAAS,IAAI,CAAC,CAEhB;AAED,wBAAgB,eAAe,CAAC,CAAC,SAAS,QAAQ,EAAE,EAAE,EAAE,GAAG,GAAG,EAAE,IAAI,CAAC,CAEpE"}
|
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
import { isValidElement } from 'react';
|
|
2
2
|
import { isPlainObject } from './isPlainObject.js';
|
|
3
|
+
export function isReactServerComponent(component) {
|
|
4
|
+
return typeof component === 'function' && isValidElement(component);
|
|
5
|
+
}
|
|
6
|
+
export function isReactClientComponent(component) {
|
|
7
|
+
// Do this to test for client components (`use client` directive) bc they import as empty objects
|
|
8
|
+
return typeof component === 'object' && !isPlainObject(component);
|
|
9
|
+
}
|
|
3
10
|
export function isReactComponent(component) {
|
|
4
|
-
return
|
|
5
|
-
typeof component === 'object' && !isPlainObject(component);
|
|
11
|
+
return isReactServerComponent(component) || isReactClientComponent(component);
|
|
6
12
|
}
|
|
7
13
|
export function isPlainFunction(fn) {
|
|
8
14
|
return typeof fn === 'function' && !isReactComponent(fn);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/isReactComponent.ts"],"sourcesContent":["import type React from 'react'\n\nimport { isValidElement } from 'react'\n\nimport { isPlainObject } from './isPlainObject.js'\n\nexport function
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/isReactComponent.ts"],"sourcesContent":["import type React from 'react'\n\nimport { isValidElement } from 'react'\n\nimport { isPlainObject } from './isPlainObject.js'\n\nexport function isReactServerComponent<T extends any>(\n component: React.ComponentType | any,\n): component is T {\n return typeof component === 'function' && isValidElement(component)\n}\n\nexport function isReactClientComponent<T extends any>(\n component: React.ComponentType | any,\n): component is T {\n // Do this to test for client components (`use client` directive) bc they import as empty objects\n return typeof component === 'object' && !isPlainObject(component)\n}\n\nexport function isReactComponent<T extends any>(\n component: React.ComponentType | any,\n): component is T {\n return isReactServerComponent(component) || isReactClientComponent(component)\n}\n\nexport function isPlainFunction<T extends Function>(fn: any): fn is T {\n return typeof fn === 'function' && !isReactComponent(fn)\n}\n"],"names":["isValidElement","isPlainObject","isReactServerComponent","component","isReactClientComponent","isReactComponent","isPlainFunction","fn"],"rangeMappings":";;;;;;;;;;;;;;","mappings":"AAEA,SAASA,cAAc,QAAQ,QAAO;AAEtC,SAASC,aAAa,QAAQ,qBAAoB;AAElD,OAAO,SAASC,uBACdC,SAAoC;IAEpC,OAAO,OAAOA,cAAc,cAAcH,eAAeG;AAC3D;AAEA,OAAO,SAASC,uBACdD,SAAoC;IAEpC,iGAAiG;IACjG,OAAO,OAAOA,cAAc,YAAY,CAACF,cAAcE;AACzD;AAEA,OAAO,SAASE,iBACdF,SAAoC;IAEpC,OAAOD,uBAAuBC,cAAcC,uBAAuBD;AACrE;AAEA,OAAO,SAASG,gBAAoCC,EAAO;IACzD,OAAO,OAAOA,OAAO,cAAc,CAACF,iBAAiBE;AACvD"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { PayloadRequestWithData } from '../types/index.js';
|
|
2
2
|
/**
|
|
3
3
|
* Rollback the transaction from the req using the db adapter and removes it from the req
|
|
4
4
|
*/
|
|
5
|
-
export declare function killTransaction(req:
|
|
5
|
+
export declare function killTransaction(req: PayloadRequestWithData): Promise<void>;
|
|
6
6
|
//# sourceMappingURL=killTransaction.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"killTransaction.d.ts","sourceRoot":"","sources":["../../src/utilities/killTransaction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"killTransaction.d.ts","sourceRoot":"","sources":["../../src/utilities/killTransaction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAA;AAE/D;;GAEG;AACH,wBAAsB,eAAe,CAAC,GAAG,EAAE,sBAAsB,GAAG,OAAO,CAAC,IAAI,CAAC,CAMhF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/killTransaction.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/killTransaction.ts"],"sourcesContent":["import type { PayloadRequestWithData } from '../types/index.js'\n\n/**\n * Rollback the transaction from the req using the db adapter and removes it from the req\n */\nexport async function killTransaction(req: PayloadRequestWithData): Promise<void> {\n const { payload, transactionID } = req\n if (transactionID) {\n await payload.db.rollbackTransaction(req.transactionID)\n delete req.transactionID\n }\n}\n"],"names":["killTransaction","req","payload","transactionID","db","rollbackTransaction"],"rangeMappings":";;;;;;;;","mappings":"AAEA;;CAEC,GACD,OAAO,eAAeA,gBAAgBC,GAA2B;IAC/D,MAAM,EAAEC,OAAO,EAAEC,aAAa,EAAE,GAAGF;IACnC,IAAIE,eAAe;QACjB,MAAMD,QAAQE,EAAE,CAACC,mBAAmB,CAACJ,IAAIE,aAAa;QACtD,OAAOF,IAAIE,aAAa;IAC1B;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/parseCookies.ts"],"sourcesContent":["import APIError from '../errors/APIError.js'\n\nexport const parseCookies = (headers: Request['headers']): Map<string, string> => {\n const list = new Map<string, string>()\n const rc = headers.get('Cookie')\n\n if (rc) {\n rc.split(';').forEach((cookie) => {\n const parts = cookie.split('=')\n const key = parts.shift().trim()\n const encodedValue = parts.join('=')\n\n try {\n const decodedValue = decodeURI(encodedValue)\n list.set(key, decodedValue)\n } catch (e) {\n throw new APIError(`Error decoding cookie value for key ${key}: ${e.message}`)\n }\n })\n }\n\n return list\n}\n"],"names":["APIError","parseCookies","headers","list","Map","rc","get","split","forEach","cookie","parts","key","shift","trim","encodedValue","join","decodedValue","decodeURI","set","e","message"],"rangeMappings":";;;;;;;;;;;;;;;;;;","mappings":"AAAA,
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/parseCookies.ts"],"sourcesContent":["import { APIError } from '../errors/APIError.js'\n\nexport const parseCookies = (headers: Request['headers']): Map<string, string> => {\n const list = new Map<string, string>()\n const rc = headers.get('Cookie')\n\n if (rc) {\n rc.split(';').forEach((cookie) => {\n const parts = cookie.split('=')\n const key = parts.shift().trim()\n const encodedValue = parts.join('=')\n\n try {\n const decodedValue = decodeURI(encodedValue)\n list.set(key, decodedValue)\n } catch (e) {\n throw new APIError(`Error decoding cookie value for key ${key}: ${e.message}`)\n }\n })\n }\n\n return list\n}\n"],"names":["APIError","parseCookies","headers","list","Map","rc","get","split","forEach","cookie","parts","key","shift","trim","encodedValue","join","decodedValue","decodeURI","set","e","message"],"rangeMappings":";;;;;;;;;;;;;;;;;;","mappings":"AAAA,SAASA,QAAQ,QAAQ,wBAAuB;AAEhD,OAAO,MAAMC,eAAe,CAACC;IAC3B,MAAMC,OAAO,IAAIC;IACjB,MAAMC,KAAKH,QAAQI,GAAG,CAAC;IAEvB,IAAID,IAAI;QACNA,GAAGE,KAAK,CAAC,KAAKC,OAAO,CAAC,CAACC;YACrB,MAAMC,QAAQD,OAAOF,KAAK,CAAC;YAC3B,MAAMI,MAAMD,MAAME,KAAK,GAAGC,IAAI;YAC9B,MAAMC,eAAeJ,MAAMK,IAAI,CAAC;YAEhC,IAAI;gBACF,MAAMC,eAAeC,UAAUH;gBAC/BX,KAAKe,GAAG,CAACP,KAAKK;YAChB,EAAE,OAAOG,GAAG;gBACV,MAAM,IAAInB,SAAS,CAAC,oCAAoC,EAAEW,IAAI,EAAE,EAAEQ,EAAEC,OAAO,CAAC,CAAC;YAC/E;QACF;IACF;IAEA,OAAOjB;AACT,EAAC"}
|