payload 4.0.0-beta.6 → 4.0.0-beta.8
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/forms/Form.d.ts +5 -0
- package/dist/admin/forms/Form.d.ts.map +1 -1
- package/dist/admin/forms/Form.js.map +1 -1
- package/dist/admin/functions/index.d.ts +2 -0
- package/dist/admin/functions/index.d.ts.map +1 -1
- package/dist/admin/functions/index.js.map +1 -1
- package/dist/admin/getRequestLocale.d.ts +3 -1
- package/dist/admin/getRequestLocale.d.ts.map +1 -1
- package/dist/admin/getRequestLocale.js +12 -1
- package/dist/admin/getRequestLocale.js.map +1 -1
- package/dist/admin/initAdminContext.d.ts.map +1 -1
- package/dist/admin/initAdminContext.js +2 -1
- package/dist/admin/initAdminContext.js.map +1 -1
- package/dist/auth/baseFields/sessions.d.ts.map +1 -1
- package/dist/auth/baseFields/sessions.js +8 -0
- package/dist/auth/baseFields/sessions.js.map +1 -1
- package/dist/auth/createAuthToken.d.ts +30 -0
- package/dist/auth/createAuthToken.d.ts.map +1 -0
- package/dist/auth/createAuthToken.js +39 -0
- package/dist/auth/createAuthToken.js.map +1 -0
- package/dist/auth/endpoints/refresh.d.ts.map +1 -1
- package/dist/auth/endpoints/refresh.js +2 -1
- package/dist/auth/endpoints/refresh.js.map +1 -1
- package/dist/auth/executeAuthStrategies.d.ts.map +1 -1
- package/dist/auth/executeAuthStrategies.js +1 -0
- package/dist/auth/executeAuthStrategies.js.map +1 -1
- package/dist/auth/extractJWT.d.ts +7 -0
- package/dist/auth/extractJWT.d.ts.map +1 -1
- package/dist/auth/extractJWT.js +21 -8
- package/dist/auth/extractJWT.js.map +1 -1
- package/dist/auth/loginWithCookie.d.ts.map +1 -1
- package/dist/auth/loginWithCookie.js +1 -0
- package/dist/auth/loginWithCookie.js.map +1 -1
- package/dist/auth/operations/local/login.d.ts.map +1 -1
- package/dist/auth/operations/local/login.js +1 -0
- package/dist/auth/operations/local/login.js.map +1 -1
- package/dist/auth/operations/login.d.ts +2 -0
- package/dist/auth/operations/login.d.ts.map +1 -1
- package/dist/auth/operations/login.js +10 -20
- package/dist/auth/operations/login.js.map +1 -1
- package/dist/auth/operations/refresh.d.ts +7 -0
- package/dist/auth/operations/refresh.d.ts.map +1 -1
- package/dist/auth/operations/refresh.js +160 -96
- package/dist/auth/operations/refresh.js.map +1 -1
- package/dist/auth/operations/resetPassword.d.ts.map +1 -1
- package/dist/auth/operations/resetPassword.js +8 -20
- package/dist/auth/operations/resetPassword.js.map +1 -1
- package/dist/auth/redeemRefreshToken.d.ts +43 -0
- package/dist/auth/redeemRefreshToken.d.ts.map +1 -0
- package/dist/auth/redeemRefreshToken.js +116 -0
- package/dist/auth/redeemRefreshToken.js.map +1 -0
- package/dist/auth/sessions.d.ts +28 -2
- package/dist/auth/sessions.d.ts.map +1 -1
- package/dist/auth/sessions.js +36 -5
- package/dist/auth/sessions.js.map +1 -1
- package/dist/auth/strategies/local/authenticate.d.ts +3 -1
- package/dist/auth/strategies/local/authenticate.d.ts.map +1 -1
- package/dist/auth/strategies/local/authenticate.js +23 -19
- package/dist/auth/strategies/local/authenticate.js.map +1 -1
- package/dist/auth/strategies/local/generatePasswordSaltHash.d.ts +14 -1
- package/dist/auth/strategies/local/generatePasswordSaltHash.d.ts.map +1 -1
- package/dist/auth/strategies/local/generatePasswordSaltHash.js +31 -15
- package/dist/auth/strategies/local/generatePasswordSaltHash.js.map +1 -1
- package/dist/auth/types.d.ts +34 -1
- package/dist/auth/types.d.ts.map +1 -1
- package/dist/auth/types.js.map +1 -1
- package/dist/cli/commands/collections/deleteDocuments.d.ts.map +1 -1
- package/dist/cli/commands/collections/deleteDocuments.js +3 -1
- package/dist/cli/commands/collections/deleteDocuments.js.map +1 -1
- package/dist/collections/config/defaults.d.ts +2 -0
- package/dist/collections/config/defaults.d.ts.map +1 -1
- package/dist/collections/config/defaults.js +4 -0
- package/dist/collections/config/defaults.js.map +1 -1
- package/dist/collections/config/sanitize.d.ts.map +1 -1
- package/dist/collections/config/sanitize.js +3 -0
- package/dist/collections/config/sanitize.js.map +1 -1
- package/dist/collections/operations/create.js +11 -11
- package/dist/collections/operations/create.js.map +1 -1
- package/dist/collections/operations/inputSchemas.d.ts +6 -0
- package/dist/collections/operations/inputSchemas.d.ts.map +1 -1
- package/dist/collections/operations/inputSchemas.js +1 -0
- package/dist/collections/operations/inputSchemas.js.map +1 -1
- package/dist/collections/operations/renameFile.d.ts.map +1 -1
- package/dist/collections/operations/renameFile.js +64 -15
- package/dist/collections/operations/renameFile.js.map +1 -1
- package/dist/collections/operations/update.d.ts.map +1 -1
- package/dist/collections/operations/update.js +40 -19
- package/dist/collections/operations/update.js.map +1 -1
- package/dist/collections/operations/utilities/update.d.ts.map +1 -1
- package/dist/collections/operations/utilities/update.js +29 -40
- package/dist/collections/operations/utilities/update.js.map +1 -1
- package/dist/config/defaults.d.ts.map +1 -1
- package/dist/config/defaults.js +2 -1
- package/dist/config/defaults.js.map +1 -1
- package/dist/config/sanitize.d.ts.map +1 -1
- package/dist/config/sanitize.js +4 -0
- package/dist/config/sanitize.js.map +1 -1
- package/dist/config/types.d.ts +14 -7
- package/dist/config/types.d.ts.map +1 -1
- package/dist/config/types.js.map +1 -1
- package/dist/database/getLocalizedPaths.d.ts.map +1 -1
- package/dist/database/getLocalizedPaths.js +16 -1
- package/dist/database/getLocalizedPaths.js.map +1 -1
- package/dist/database/queryValidation/hasReadAccessToQueryPath.d.ts +17 -0
- package/dist/database/queryValidation/hasReadAccessToQueryPath.d.ts.map +1 -0
- package/dist/database/queryValidation/hasReadAccessToQueryPath.js +59 -0
- package/dist/database/queryValidation/hasReadAccessToQueryPath.js.map +1 -0
- package/dist/database/queryValidation/validateSearchParams.d.ts.map +1 -1
- package/dist/database/queryValidation/validateSearchParams.js +20 -23
- package/dist/database/queryValidation/validateSearchParams.js.map +1 -1
- package/dist/errors/DuplicateGlobal.d.ts.map +1 -1
- package/dist/errors/DuplicateGlobal.js +1 -1
- package/dist/errors/DuplicateGlobal.js.map +1 -1
- package/dist/errors/InvalidFieldName.js +1 -1
- package/dist/errors/InvalidFieldName.js.map +1 -1
- package/dist/errors/InvalidFieldRelationship.d.ts.map +1 -1
- package/dist/errors/InvalidFieldRelationship.js +1 -1
- package/dist/errors/InvalidFieldRelationship.js.map +1 -1
- package/dist/errors/MissingFieldInputOptions.js +1 -1
- package/dist/errors/MissingFieldInputOptions.js.map +1 -1
- package/dist/errors/ReservedFieldName.d.ts.map +1 -1
- package/dist/errors/ReservedFieldName.js +1 -1
- package/dist/errors/ReservedFieldName.js.map +1 -1
- package/dist/exports/build-config.d.ts.map +1 -1
- package/dist/exports/build-config.js +0 -2
- package/dist/exports/build-config.js.map +1 -1
- package/dist/exports/internal.d.ts +2 -1
- package/dist/exports/internal.d.ts.map +1 -1
- package/dist/exports/internal.js +2 -1
- package/dist/exports/internal.js.map +1 -1
- package/dist/exports/shared.d.ts +6 -3
- package/dist/exports/shared.d.ts.map +1 -1
- package/dist/exports/shared.js +6 -3
- package/dist/exports/shared.js.map +1 -1
- package/dist/fields/baseFields/authorship/index.d.ts +2 -1
- package/dist/fields/baseFields/authorship/index.d.ts.map +1 -1
- package/dist/fields/baseFields/authorship/index.js +12 -5
- package/dist/fields/baseFields/authorship/index.js.map +1 -1
- package/dist/fields/config/reservedFieldNames.d.ts.map +1 -1
- package/dist/fields/config/reservedFieldNames.js +2 -1
- package/dist/fields/config/reservedFieldNames.js.map +1 -1
- package/dist/fields/config/types.d.ts +8 -1
- package/dist/fields/config/types.d.ts.map +1 -1
- package/dist/fields/config/types.js.map +1 -1
- package/dist/fields/hooks/afterChange/promise.d.ts.map +1 -1
- package/dist/fields/hooks/afterChange/promise.js +2 -1
- package/dist/fields/hooks/afterChange/promise.js.map +1 -1
- package/dist/fields/hooks/afterRead/promise.d.ts.map +1 -1
- package/dist/fields/hooks/afterRead/promise.js +11 -9
- package/dist/fields/hooks/afterRead/promise.js.map +1 -1
- package/dist/fields/hooks/beforeChange/index.d.ts.map +1 -1
- package/dist/fields/hooks/beforeChange/index.js +4 -0
- package/dist/fields/hooks/beforeChange/index.js.map +1 -1
- package/dist/fields/hooks/beforeChange/promise.d.ts.map +1 -1
- package/dist/fields/hooks/beforeChange/promise.js +11 -1
- package/dist/fields/hooks/beforeChange/promise.js.map +1 -1
- package/dist/fields/hooks/beforeDuplicate/promise.d.ts.map +1 -1
- package/dist/fields/hooks/beforeDuplicate/promise.js +7 -2
- package/dist/fields/hooks/beforeDuplicate/promise.js.map +1 -1
- package/dist/fields/hooks/beforeValidate/getFallbackValue.d.ts.map +1 -1
- package/dist/fields/hooks/beforeValidate/getFallbackValue.js +3 -2
- package/dist/fields/hooks/beforeValidate/getFallbackValue.js.map +1 -1
- package/dist/fields/hooks/beforeValidate/promise.d.ts.map +1 -1
- package/dist/fields/hooks/beforeValidate/promise.js +19 -2
- package/dist/fields/hooks/beforeValidate/promise.js.map +1 -1
- package/dist/fields/validateJSONSchema.js +1 -1
- package/dist/fields/validateJSONSchema.js.map +1 -1
- package/dist/fields/validations.js +3 -3
- package/dist/fields/validations.js.map +1 -1
- package/dist/globals/operations/update.d.ts.map +1 -1
- package/dist/globals/operations/update.js +29 -40
- package/dist/globals/operations/update.js.map +1 -1
- package/dist/hierarchy/getInitialTreeData.js +1 -1
- package/dist/hierarchy/getInitialTreeData.js.map +1 -1
- package/dist/index.bundled.d.ts +278 -16
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/uploads/copyTempFileForDocument.d.ts +9 -0
- package/dist/uploads/copyTempFileForDocument.d.ts.map +1 -0
- package/dist/uploads/copyTempFileForDocument.js +15 -0
- package/dist/uploads/copyTempFileForDocument.js.map +1 -0
- package/dist/uploads/createSharedClientUploadDownload.d.ts +12 -0
- package/dist/uploads/createSharedClientUploadDownload.d.ts.map +1 -0
- package/dist/uploads/createSharedClientUploadDownload.js +36 -0
- package/dist/uploads/createSharedClientUploadDownload.js.map +1 -0
- package/dist/uploads/docWithFilenameExists.d.ts +2 -1
- package/dist/uploads/docWithFilenameExists.d.ts.map +1 -1
- package/dist/uploads/docWithFilenameExists.js +19 -9
- package/dist/uploads/docWithFilenameExists.js.map +1 -1
- package/dist/uploads/downloadFileToBuffer.d.ts +11 -0
- package/dist/uploads/downloadFileToBuffer.d.ts.map +1 -1
- package/dist/uploads/downloadFileToBuffer.js +32 -21
- package/dist/uploads/downloadFileToBuffer.js.map +1 -1
- package/dist/uploads/endpoints/getFile.d.ts +2 -1
- package/dist/uploads/endpoints/getFile.d.ts.map +1 -1
- package/dist/uploads/endpoints/getFile.js +6 -1
- package/dist/uploads/endpoints/getFile.js.map +1 -1
- package/dist/uploads/fileVersioning/naming.d.ts +0 -3
- package/dist/uploads/fileVersioning/naming.d.ts.map +1 -1
- package/dist/uploads/fileVersioning/naming.js +0 -4
- package/dist/uploads/fileVersioning/naming.js.map +1 -1
- package/dist/uploads/fileVersioning/storedFiles.d.ts.map +1 -1
- package/dist/uploads/fileVersioning/storedFiles.js +9 -1
- package/dist/uploads/fileVersioning/storedFiles.js.map +1 -1
- package/dist/uploads/formatFileMeta.d.ts +12 -0
- package/dist/uploads/formatFileMeta.d.ts.map +1 -0
- package/dist/uploads/formatFileMeta.js +14 -0
- package/dist/uploads/formatFileMeta.js.map +1 -0
- package/dist/uploads/generateFileData.d.ts +8 -1
- package/dist/uploads/generateFileData.d.ts.map +1 -1
- package/dist/uploads/generateFileData.js +533 -125
- package/dist/uploads/generateFileData.js.map +1 -1
- package/dist/uploads/generateFilePathOrURL.d.ts +3 -1
- package/dist/uploads/generateFilePathOrURL.d.ts.map +1 -1
- package/dist/uploads/generateFilePathOrURL.js +3 -2
- package/dist/uploads/generateFilePathOrURL.js.map +1 -1
- package/dist/uploads/getBaseFields.d.ts.map +1 -1
- package/dist/uploads/getBaseFields.js +51 -2
- package/dist/uploads/getBaseFields.js.map +1 -1
- package/dist/uploads/getFileContentRequirement.d.ts +9 -8
- package/dist/uploads/getFileContentRequirement.d.ts.map +1 -1
- package/dist/uploads/getFileContentRequirement.js +10 -6
- package/dist/uploads/getFileContentRequirement.js.map +1 -1
- package/dist/uploads/getFileFromUploadInstructions.d.ts +10 -0
- package/dist/uploads/getFileFromUploadInstructions.d.ts.map +1 -1
- package/dist/uploads/getFileFromUploadInstructions.js +65 -45
- package/dist/uploads/getFileFromUploadInstructions.js.map +1 -1
- package/dist/uploads/getFileTypeIdentity.d.ts.map +1 -1
- package/dist/uploads/getFileTypeIdentity.js +6 -2
- package/dist/uploads/getFileTypeIdentity.js.map +1 -1
- package/dist/uploads/getSafeFilename.d.ts +7 -1
- package/dist/uploads/getSafeFilename.d.ts.map +1 -1
- package/dist/uploads/getSafeFilename.js +19 -4
- package/dist/uploads/getSafeFilename.js.map +1 -1
- package/dist/uploads/isOriginalFileRequest.d.ts +25 -0
- package/dist/uploads/isOriginalFileRequest.d.ts.map +1 -0
- package/dist/uploads/isOriginalFileRequest.js +14 -0
- package/dist/uploads/isOriginalFileRequest.js.map +1 -0
- package/dist/uploads/isRequestTimeFile.d.ts +13 -0
- package/dist/uploads/isRequestTimeFile.d.ts.map +1 -0
- package/dist/uploads/isRequestTimeFile.js +9 -0
- package/dist/uploads/isRequestTimeFile.js.map +1 -0
- package/dist/uploads/registerUploadVariants.d.ts +20 -0
- package/dist/uploads/registerUploadVariants.d.ts.map +1 -0
- package/dist/uploads/registerUploadVariants.js +93 -0
- package/dist/uploads/registerUploadVariants.js.map +1 -0
- package/dist/uploads/sanitizeUploadData.d.ts.map +1 -1
- package/dist/uploads/sanitizeUploadData.js +3 -0
- package/dist/uploads/sanitizeUploadData.js.map +1 -1
- package/dist/uploads/transformState/cropUnits.d.ts +21 -0
- package/dist/uploads/transformState/cropUnits.d.ts.map +1 -0
- package/dist/uploads/transformState/cropUnits.js +23 -0
- package/dist/uploads/transformState/cropUnits.js.map +1 -0
- package/dist/uploads/transformState/getChangedTransformKeys.d.ts +6 -0
- package/dist/uploads/transformState/getChangedTransformKeys.d.ts.map +1 -0
- package/dist/uploads/transformState/getChangedTransformKeys.js +12 -0
- package/dist/uploads/transformState/getChangedTransformKeys.js.map +1 -0
- package/dist/uploads/transformState/getTransformKeyCoverageErrors.d.ts +15 -0
- package/dist/uploads/transformState/getTransformKeyCoverageErrors.d.ts.map +1 -0
- package/dist/uploads/transformState/getTransformKeyCoverageErrors.js +28 -0
- package/dist/uploads/transformState/getTransformKeyCoverageErrors.js.map +1 -0
- package/dist/uploads/transformState/planPersistedDefaultStages.d.ts +24 -0
- package/dist/uploads/transformState/planPersistedDefaultStages.d.ts.map +1 -0
- package/dist/uploads/transformState/planPersistedDefaultStages.js +32 -0
- package/dist/uploads/transformState/planPersistedDefaultStages.js.map +1 -0
- package/dist/uploads/transformState/planUpload.d.ts +95 -0
- package/dist/uploads/transformState/planUpload.d.ts.map +1 -0
- package/dist/uploads/transformState/planUpload.js +198 -0
- package/dist/uploads/transformState/planUpload.js.map +1 -0
- package/dist/uploads/transformState/resolveUploadEdits.d.ts +91 -0
- package/dist/uploads/transformState/resolveUploadEdits.d.ts.map +1 -0
- package/dist/uploads/transformState/resolveUploadEdits.js +397 -0
- package/dist/uploads/transformState/resolveUploadEdits.js.map +1 -0
- package/dist/uploads/transformState/transformKeyClaims.d.ts +14 -0
- package/dist/uploads/transformState/transformKeyClaims.d.ts.map +1 -0
- package/dist/uploads/transformState/transformKeyClaims.js +15 -0
- package/dist/uploads/transformState/transformKeyClaims.js.map +1 -0
- package/dist/uploads/transformState/transformStateSchema.d.ts +8 -0
- package/dist/uploads/transformState/transformStateSchema.d.ts.map +1 -0
- package/dist/uploads/transformState/transformStateSchema.js +155 -0
- package/dist/uploads/transformState/transformStateSchema.js.map +1 -0
- package/dist/uploads/transformState/validateTransformState.d.ts +15 -0
- package/dist/uploads/transformState/validateTransformState.d.ts.map +1 -0
- package/dist/uploads/transformState/validateTransformState.js +34 -0
- package/dist/uploads/transformState/validateTransformState.js.map +1 -0
- package/dist/uploads/transformers/createFileSource.d.ts +9 -0
- package/dist/uploads/transformers/createFileSource.d.ts.map +1 -0
- package/dist/uploads/transformers/createFileSource.js +58 -0
- package/dist/uploads/transformers/createFileSource.js.map +1 -0
- package/dist/uploads/transformers/createLazySourceGetter.d.ts +3 -1
- package/dist/uploads/transformers/createLazySourceGetter.d.ts.map +1 -1
- package/dist/uploads/transformers/createLazySourceGetter.js +2 -2
- package/dist/uploads/transformers/createLazySourceGetter.js.map +1 -1
- package/dist/uploads/transformers/getSourceFileResponse.d.ts +3 -1
- package/dist/uploads/transformers/getSourceFileResponse.d.ts.map +1 -1
- package/dist/uploads/transformers/getSourceFileResponse.js +2 -1
- package/dist/uploads/transformers/getSourceFileResponse.js.map +1 -1
- package/dist/uploads/transformers/handleDynamicFileRequest.d.ts +5 -3
- package/dist/uploads/transformers/handleDynamicFileRequest.d.ts.map +1 -1
- package/dist/uploads/transformers/handleDynamicFileRequest.js +155 -38
- package/dist/uploads/transformers/handleDynamicFileRequest.js.map +1 -1
- package/dist/uploads/transformers/planTransformerPipeline.d.ts +11 -1
- package/dist/uploads/transformers/planTransformerPipeline.d.ts.map +1 -1
- package/dist/uploads/transformers/planTransformerPipeline.js +28 -6
- package/dist/uploads/transformers/planTransformerPipeline.js.map +1 -1
- package/dist/uploads/transformers/resolveUploadDocument.d.ts +10 -3
- package/dist/uploads/transformers/resolveUploadDocument.d.ts.map +1 -1
- package/dist/uploads/transformers/resolveUploadDocument.js +18 -7
- package/dist/uploads/transformers/resolveUploadDocument.js.map +1 -1
- package/dist/uploads/transformers/transformUploadFile.d.ts +18 -7
- package/dist/uploads/transformers/transformUploadFile.d.ts.map +1 -1
- package/dist/uploads/transformers/transformUploadFile.js +96 -12
- package/dist/uploads/transformers/transformUploadFile.js.map +1 -1
- package/dist/uploads/transformers/types.d.ts +89 -3
- package/dist/uploads/transformers/types.d.ts.map +1 -1
- package/dist/uploads/transformers/types.js.map +1 -1
- package/dist/uploads/types.d.ts +20 -2
- package/dist/uploads/types.d.ts.map +1 -1
- package/dist/uploads/types.js.map +1 -1
- package/dist/utilities/configToJSONSchema.d.ts.map +1 -1
- package/dist/utilities/configToJSONSchema.js +14 -3
- package/dist/utilities/configToJSONSchema.js.map +1 -1
- package/dist/utilities/createPayloadRequestFromWebRequest.d.ts +12 -1
- package/dist/utilities/createPayloadRequestFromWebRequest.d.ts.map +1 -1
- package/dist/utilities/createPayloadRequestFromWebRequest.js +9 -3
- package/dist/utilities/createPayloadRequestFromWebRequest.js.map +1 -1
- package/dist/utilities/deepFreeze.d.ts +6 -0
- package/dist/utilities/deepFreeze.d.ts.map +1 -0
- package/dist/utilities/deepFreeze.js +14 -0
- package/dist/utilities/deepFreeze.js.map +1 -0
- package/dist/utilities/getDataByPath.d.ts.map +1 -1
- package/dist/utilities/getDataByPath.js +6 -9
- package/dist/utilities/getDataByPath.js.map +1 -1
- package/dist/utilities/getDataFromFormState.d.ts +10 -0
- package/dist/utilities/getDataFromFormState.d.ts.map +1 -0
- package/dist/utilities/getDataFromFormState.js +40 -0
- package/dist/utilities/getDataFromFormState.js.map +1 -0
- package/dist/utilities/getDateOnlyComparison.d.ts +27 -0
- package/dist/utilities/getDateOnlyComparison.d.ts.map +1 -0
- package/dist/utilities/getDateOnlyComparison.js +162 -0
- package/dist/utilities/getDateOnlyComparison.js.map +1 -0
- package/dist/utilities/getEntityPermissions/getEntityPermissions.d.ts.map +1 -1
- package/dist/utilities/getEntityPermissions/getEntityPermissions.js +5 -2
- package/dist/utilities/getEntityPermissions/getEntityPermissions.js.map +1 -1
- package/dist/utilities/getEntityPermissions/populateFieldPermissions.d.ts +4 -4
- package/dist/utilities/getEntityPermissions/populateFieldPermissions.d.ts.map +1 -1
- package/dist/utilities/getEntityPermissions/populateFieldPermissions.js +63 -32
- package/dist/utilities/getEntityPermissions/populateFieldPermissions.js.map +1 -1
- package/dist/utilities/getSiblingDataFromFormState.d.ts +8 -0
- package/dist/utilities/getSiblingDataFromFormState.d.ts.map +1 -0
- package/dist/utilities/{getSiblingData.js → getSiblingDataFromFormState.js} +11 -8
- package/dist/utilities/getSiblingDataFromFormState.js.map +1 -0
- package/dist/utilities/handleEndpoints.d.ts.map +1 -1
- package/dist/utilities/handleEndpoints.js +10 -2
- package/dist/utilities/handleEndpoints.js.map +1 -1
- package/dist/utilities/mergeLocalizedData.d.ts +1 -1
- package/dist/utilities/mergeLocalizedData.d.ts.map +1 -1
- package/dist/utilities/mergeLocalizedData.js +6 -2
- package/dist/utilities/mergeLocalizedData.js.map +1 -1
- package/dist/utilities/sanitizePermissions.d.ts +4 -1
- package/dist/utilities/sanitizePermissions.d.ts.map +1 -1
- package/dist/utilities/sanitizePermissions.js +34 -3
- package/dist/utilities/sanitizePermissions.js.map +1 -1
- package/dist/utilities/telemetry/featureInfo/getFeatureInfo.d.ts.map +1 -1
- package/dist/utilities/telemetry/featureInfo/getFeatureInfo.js +41 -7
- package/dist/utilities/telemetry/featureInfo/getFeatureInfo.js.map +1 -1
- package/dist/utilities/telemetry/featureInfo/types.d.ts +4 -1
- package/dist/utilities/telemetry/featureInfo/types.d.ts.map +1 -1
- package/dist/utilities/telemetry/featureInfo/types.js.map +1 -1
- package/dist/utilities/telemetry/index.d.ts +3 -5
- package/dist/utilities/telemetry/index.d.ts.map +1 -1
- package/dist/utilities/telemetry/index.js +14 -3
- package/dist/utilities/telemetry/index.js.map +1 -1
- package/dist/utilities/telemetry/widgetType.d.ts +6 -0
- package/dist/utilities/telemetry/widgetType.d.ts.map +1 -0
- package/dist/utilities/telemetry/widgetType.js +33 -0
- package/dist/utilities/telemetry/widgetType.js.map +1 -0
- package/dist/utilities/transformPointDataToPayload.d.ts.map +1 -1
- package/dist/utilities/transformPointDataToPayload.js +15 -1
- package/dist/utilities/transformPointDataToPayload.js.map +1 -1
- package/dist/utilities/unflatten.d.ts +17 -0
- package/dist/utilities/unflatten.d.ts.map +1 -1
- package/dist/utilities/unflatten.js +10 -4
- package/dist/utilities/unflatten.js.map +1 -1
- package/dist/versions/allLocalesPublicationStatus.d.ts +5 -5
- package/dist/versions/allLocalesPublicationStatus.d.ts.map +1 -1
- package/dist/versions/allLocalesPublicationStatus.js +2 -2
- package/dist/versions/allLocalesPublicationStatus.js.map +1 -1
- package/dist/versions/buildSingleLocalePublishData.d.ts +4 -4
- package/dist/versions/buildSingleLocalePublishData.d.ts.map +1 -1
- package/dist/versions/buildSingleLocalePublishData.js +8 -8
- package/dist/versions/buildSingleLocalePublishData.js.map +1 -1
- package/dist/versions/drafts/hasNonLocalizedDataChanged.d.ts +12 -0
- package/dist/versions/drafts/hasNonLocalizedDataChanged.d.ts.map +1 -0
- package/dist/versions/drafts/hasNonLocalizedDataChanged.js +165 -0
- package/dist/versions/drafts/hasNonLocalizedDataChanged.js.map +1 -0
- package/dist/versions/mergeLocalizedStatus.d.ts +9 -0
- package/dist/versions/mergeLocalizedStatus.d.ts.map +1 -0
- package/dist/versions/mergeLocalizedStatus.js +11 -0
- package/dist/versions/mergeLocalizedStatus.js.map +1 -0
- package/dist/versions/resolveLocalizedStatus.d.ts +19 -0
- package/dist/versions/resolveLocalizedStatus.d.ts.map +1 -0
- package/dist/versions/resolveLocalizedStatus.js +60 -0
- package/dist/versions/resolveLocalizedStatus.js.map +1 -0
- package/package.json +2 -2
- package/dist/fields/hooks/beforeChange/cloneDataFromOriginalDoc.d.ts +0 -3
- package/dist/fields/hooks/beforeChange/cloneDataFromOriginalDoc.d.ts.map +0 -1
- package/dist/fields/hooks/beforeChange/cloneDataFromOriginalDoc.js +0 -20
- package/dist/fields/hooks/beforeChange/cloneDataFromOriginalDoc.js.map +0 -1
- package/dist/utilities/getSiblingData.d.ts +0 -3
- package/dist/utilities/getSiblingData.d.ts.map +0 -1
- package/dist/utilities/getSiblingData.js.map +0 -1
- package/dist/utilities/reduceFieldsToValues.d.ts +0 -10
- package/dist/utilities/reduceFieldsToValues.d.ts.map +0 -1
- package/dist/utilities/reduceFieldsToValues.js +0 -24
- package/dist/utilities/reduceFieldsToValues.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/collections/operations/inputSchemas.ts"],"sourcesContent":["/**\n * Shared input schemas for collection data commands.\n *\n * The Payload CLI and MCP plugin use these schemas so they accept and validate the same input.\n * Local variants include trusted options that should only be available to local callers.\n */\nimport * as z from 'zod/mini'\n\nimport {\n dataSchema,\n defaultLimitSchema,\n defaultPageSchema,\n depthSchema,\n draftSchema,\n fallbackLocaleSchema,\n fieldSchema,\n idSchema,\n joinsSchema,\n limitSchema,\n localeSchema,\n overrideAccessSchema,\n overrideLockSchema,\n overwriteExistingFilesSchema,\n pageSchema,\n paginationSchema,\n populateSchema,\n publishAllLocalesSchema,\n requireIDOrWhere,\n requireReturningForSelect,\n returningSchema,\n selectedLocalesSchema,\n selectSchema,\n showHiddenFieldsSchema,\n slugSchema,\n sortSchema,\n trashSchema,\n unpublishAllLocalesSchema,\n whereSchema,\n writeDraftSchema,\n} from '../../utilities/sharedInputSchemas.js'\nimport { strictObject } from '../../utilities/zod.js'\n\nconst countDocumentsInputShape = {\n slug: slugSchema,\n locale: localeSchema,\n trash: trashSchema,\n where: whereSchema,\n}\n\nexport const countDocumentsInputSchema = strictObject(countDocumentsInputShape)\n\n/** For trusted local callers only. Includes access bypass. */\nexport const countDocumentsLocalInputSchema = strictObject({\n ...countDocumentsInputShape,\n overrideAccess: overrideAccessSchema,\n})\n\nconst countVersionsInputShape = {\n slug: slugSchema,\n locale: localeSchema,\n where: whereSchema,\n}\n\nexport const countVersionsInputSchema = strictObject(countVersionsInputShape)\n\n/** For trusted local callers only. Includes access bypass. */\nexport const countVersionsLocalInputSchema = strictObject({\n ...countVersionsInputShape,\n overrideAccess: overrideAccessSchema,\n})\n\nconst getCreateDocumentsInputShape = <TFile extends z.core.$ZodType>({\n file,\n}: {\n file: TFile\n}) => ({\n slug: slugSchema,\n depth: depthSchema,\n documents: z\n .array(\n z.strictObject({\n data: dataSchema,\n file: z.optional(file),\n }),\n )\n .check(z.minLength(1), z.describe('A JSON array of {\"data\": {...}, \"file\"?: ...} objects.')),\n draft: writeDraftSchema,\n fallbackLocale: fallbackLocaleSchema,\n locale: localeSchema,\n populate: populateSchema,\n publishAllLocales: publishAllLocalesSchema,\n returning: returningSchema,\n select: selectSchema,\n})\n\n/** Safe for remote interfaces. Excludes trusted Local API options. */\nexport const createDocumentsInputSchema = <TFile extends z.core.$ZodType>({\n file,\n}: {\n file: TFile\n}) => strictObject(getCreateDocumentsInputShape({ file }), z.superRefine(requireReturningForSelect))\n\n/** For trusted local callers only. Includes access bypass, file overwrites, and hidden fields. */\nexport const createDocumentsLocalInputSchema = <TFile extends z.core.$ZodType>({\n file,\n}: {\n file: TFile\n}) =>\n strictObject(\n {\n ...getCreateDocumentsInputShape({ file }),\n overrideAccess: overrideAccessSchema,\n overwriteExistingFiles: overwriteExistingFilesSchema,\n showHiddenFields: showHiddenFieldsSchema,\n },\n z.superRefine(requireReturningForSelect),\n )\n\nconst deleteDocumentsInputShape = {\n id: z.optional(idSchema),\n slug: slugSchema,\n depth: depthSchema,\n fallbackLocale: fallbackLocaleSchema,\n locale: localeSchema,\n where: whereSchema,\n}\n\nexport const deleteDocumentsInputSchema = strictObject(\n deleteDocumentsInputShape,\n z.superRefine(requireIDOrWhere),\n)\n\n/** For trusted local callers only. Includes access bypass. */\nexport const deleteDocumentsLocalInputSchema = strictObject(\n {\n ...deleteDocumentsInputShape,\n overrideAccess: overrideAccessSchema,\n },\n z.superRefine(requireIDOrWhere),\n)\n\nconst duplicateDocumentInputShape = {\n id: idSchema,\n slug: slugSchema,\n data: z.optional(dataSchema),\n depth: depthSchema,\n draft: writeDraftSchema,\n fallbackLocale: fallbackLocaleSchema,\n locale: localeSchema,\n populate: populateSchema,\n select: selectSchema,\n selectedLocales: selectedLocalesSchema,\n}\n\nexport const duplicateDocumentInputSchema = strictObject(duplicateDocumentInputShape)\n\n/** For trusted local callers only. Includes access bypass and hidden fields. */\nexport const duplicateDocumentLocalInputSchema = strictObject({\n ...duplicateDocumentInputShape,\n overrideAccess: overrideAccessSchema,\n showHiddenFields: showHiddenFieldsSchema,\n})\n\nconst findDistinctInputShape = {\n slug: slugSchema,\n depth: depthSchema,\n field: fieldSchema,\n limit: limitSchema,\n locale: localeSchema,\n page: pageSchema,\n populate: populateSchema,\n sort: sortSchema,\n trash: trashSchema,\n where: whereSchema,\n}\n\nexport const findDistinctInputSchema = strictObject(findDistinctInputShape)\n\n/** For trusted local callers only. Includes access bypass and hidden fields. */\nexport const findDistinctLocalInputSchema = strictObject({\n ...findDistinctInputShape,\n overrideAccess: overrideAccessSchema,\n showHiddenFields: showHiddenFieldsSchema,\n})\n\nconst findDocumentsInputShape = {\n id: z.optional(idSchema),\n slug: slugSchema,\n depth: depthSchema,\n draft: draftSchema,\n fallbackLocale: fallbackLocaleSchema,\n joins: joinsSchema,\n limit: defaultLimitSchema,\n locale: localeSchema,\n page: defaultPageSchema,\n pagination: paginationSchema,\n populate: populateSchema,\n select: selectSchema,\n sort: sortSchema,\n trash: trashSchema,\n where: whereSchema,\n}\n\nexport const findDocumentsInputSchema = strictObject(findDocumentsInputShape)\n\n/** For trusted local callers only. Includes access bypass and hidden fields. */\nexport const findDocumentsLocalInputSchema = strictObject({\n ...findDocumentsInputShape,\n overrideAccess: overrideAccessSchema,\n showHiddenFields: showHiddenFieldsSchema,\n})\n\nconst findVersionByIDInputShape = {\n id: idSchema,\n slug: slugSchema,\n depth: depthSchema,\n draft: draftSchema,\n fallbackLocale: fallbackLocaleSchema,\n locale: localeSchema,\n populate: populateSchema,\n select: selectSchema,\n trash: trashSchema,\n}\n\nexport const findVersionByIDInputSchema = strictObject(findVersionByIDInputShape)\n\n/** For trusted local callers only. Includes access bypass and hidden fields. */\nexport const findVersionByIDLocalInputSchema = strictObject({\n ...findVersionByIDInputShape,\n overrideAccess: overrideAccessSchema,\n showHiddenFields: showHiddenFieldsSchema,\n})\n\nconst findVersionsInputShape = {\n slug: slugSchema,\n depth: depthSchema,\n draft: draftSchema,\n fallbackLocale: fallbackLocaleSchema,\n limit: defaultLimitSchema,\n locale: localeSchema,\n page: defaultPageSchema,\n pagination: paginationSchema,\n populate: populateSchema,\n select: selectSchema,\n sort: sortSchema,\n trash: trashSchema,\n where: whereSchema,\n}\n\nexport const findVersionsInputSchema = strictObject(findVersionsInputShape)\n\n/** For trusted local callers only. Includes access bypass and hidden fields. */\nexport const findVersionsLocalInputSchema = strictObject({\n ...findVersionsInputShape,\n overrideAccess: overrideAccessSchema,\n showHiddenFields: showHiddenFieldsSchema,\n})\n\nexport const getCollectionSchemaInputSchema = strictObject({\n slug: slugSchema,\n})\n\nconst restoreVersionInputShape = {\n id: idSchema,\n slug: slugSchema,\n depth: depthSchema,\n draft: writeDraftSchema,\n fallbackLocale: fallbackLocaleSchema,\n locale: localeSchema,\n populate: populateSchema,\n select: selectSchema,\n}\n\nexport const restoreVersionInputSchema = strictObject(restoreVersionInputShape)\n\n/** For trusted local callers only. Includes access bypass and hidden fields. */\nexport const restoreVersionLocalInputSchema = strictObject({\n ...restoreVersionInputShape,\n overrideAccess: overrideAccessSchema,\n showHiddenFields: showHiddenFieldsSchema,\n})\n\nconst getUpdateDocumentInputShape = <TFile extends z.core.$ZodType>({ file }: { file: TFile }) => ({\n id: z.optional(idSchema),\n slug: slugSchema,\n data: dataSchema,\n depth: depthSchema,\n draft: writeDraftSchema,\n fallbackLocale: fallbackLocaleSchema,\n file: z.optional(file),\n limit: limitSchema,\n locale: localeSchema,\n overrideLock: overrideLockSchema,\n populate: populateSchema,\n publishAllLocales: publishAllLocalesSchema,\n returning: returningSchema,\n select: selectSchema,\n sort: sortSchema,\n trash: trashSchema,\n unpublishAllLocales: unpublishAllLocalesSchema,\n where: whereSchema,\n})\n\n/** Safe for remote interfaces. Excludes trusted Local API options. */\nexport const updateDocumentInputSchema = <TFile extends z.core.$ZodType>({\n file,\n}: {\n file: TFile\n}) =>\n strictObject(\n getUpdateDocumentInputShape({ file }),\n z.superRefine(requireIDOrWhere),\n z.superRefine(requireReturningForSelect),\n )\n\n/** For trusted local callers only. Includes access bypass, file overwrites, and hidden fields. */\nexport const updateDocumentLocalInputSchema = <TFile extends z.core.$ZodType>({\n file,\n}: {\n file: TFile\n}) =>\n strictObject(\n {\n ...getUpdateDocumentInputShape({ file }),\n overrideAccess: overrideAccessSchema,\n overwriteExistingFiles: overwriteExistingFilesSchema,\n showHiddenFields: showHiddenFieldsSchema,\n },\n z.superRefine(requireIDOrWhere),\n z.superRefine(requireReturningForSelect),\n )\n"],"names":["z","dataSchema","defaultLimitSchema","defaultPageSchema","depthSchema","draftSchema","fallbackLocaleSchema","fieldSchema","idSchema","joinsSchema","limitSchema","localeSchema","overrideAccessSchema","overrideLockSchema","overwriteExistingFilesSchema","pageSchema","paginationSchema","populateSchema","publishAllLocalesSchema","requireIDOrWhere","requireReturningForSelect","returningSchema","selectedLocalesSchema","selectSchema","showHiddenFieldsSchema","slugSchema","sortSchema","trashSchema","unpublishAllLocalesSchema","whereSchema","writeDraftSchema","strictObject","countDocumentsInputShape","slug","locale","trash","where","countDocumentsInputSchema","countDocumentsLocalInputSchema","overrideAccess","countVersionsInputShape","countVersionsInputSchema","countVersionsLocalInputSchema","getCreateDocumentsInputShape","file","depth","documents","array","data","optional","check","minLength","describe","draft","fallbackLocale","populate","publishAllLocales","returning","select","createDocumentsInputSchema","superRefine","createDocumentsLocalInputSchema","overwriteExistingFiles","showHiddenFields","deleteDocumentsInputShape","id","deleteDocumentsInputSchema","deleteDocumentsLocalInputSchema","duplicateDocumentInputShape","selectedLocales","duplicateDocumentInputSchema","duplicateDocumentLocalInputSchema","findDistinctInputShape","field","limit","page","sort","findDistinctInputSchema","findDistinctLocalInputSchema","findDocumentsInputShape","joins","pagination","findDocumentsInputSchema","findDocumentsLocalInputSchema","findVersionByIDInputShape","findVersionByIDInputSchema","findVersionByIDLocalInputSchema","findVersionsInputShape","findVersionsInputSchema","findVersionsLocalInputSchema","getCollectionSchemaInputSchema","restoreVersionInputShape","restoreVersionInputSchema","restoreVersionLocalInputSchema","getUpdateDocumentInputShape","overrideLock","unpublishAllLocales","updateDocumentInputSchema","updateDocumentLocalInputSchema"],"mappings":"AAAA;;;;;CAKC,GACD,YAAYA,OAAO,WAAU;AAE7B,SACEC,UAAU,EACVC,kBAAkB,EAClBC,iBAAiB,EACjBC,WAAW,EACXC,WAAW,EACXC,oBAAoB,EACpBC,WAAW,EACXC,QAAQ,EACRC,WAAW,EACXC,WAAW,EACXC,YAAY,EACZC,oBAAoB,EACpBC,kBAAkB,EAClBC,4BAA4B,EAC5BC,UAAU,EACVC,gBAAgB,EAChBC,cAAc,EACdC,uBAAuB,EACvBC,gBAAgB,EAChBC,yBAAyB,EACzBC,eAAe,EACfC,qBAAqB,EACrBC,YAAY,EACZC,sBAAsB,EACtBC,UAAU,EACVC,UAAU,EACVC,WAAW,EACXC,yBAAyB,EACzBC,WAAW,EACXC,gBAAgB,QACX,wCAAuC;AAC9C,SAASC,YAAY,QAAQ,yBAAwB;AAErD,MAAMC,2BAA2B;IAC/BC,MAAMR;IACNS,QAAQvB;IACRwB,OAAOR;IACPS,OAAOP;AACT;AAEA,OAAO,MAAMQ,4BAA4BN,aAAaC,0BAAyB;AAE/E,4DAA4D,GAC5D,OAAO,MAAMM,iCAAiCP,aAAa;IACzD,GAAGC,wBAAwB;IAC3BO,gBAAgB3B;AAClB,GAAE;AAEF,MAAM4B,0BAA0B;IAC9BP,MAAMR;IACNS,QAAQvB;IACRyB,OAAOP;AACT;AAEA,OAAO,MAAMY,2BAA2BV,aAAaS,yBAAwB;AAE7E,4DAA4D,GAC5D,OAAO,MAAME,gCAAgCX,aAAa;IACxD,GAAGS,uBAAuB;IAC1BD,gBAAgB3B;AAClB,GAAE;AAEF,MAAM+B,+BAA+B,CAAgC,EACnEC,IAAI,EAGL,GAAM,CAAA;QACLX,MAAMR;QACNoB,OAAOzC;QACP0C,WAAW9C,EACR+C,KAAK,CACJ/C,EAAE+B,YAAY,CAAC;YACbiB,MAAM/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Q,OAAOP;IACT,CAAA;AAEA,oEAAoE,GACpE,OAAO,MAAMoE,4BAA4B,CAAgC,EACvErD,IAAI,EAGL,GACCb,aACE+D,4BAA4B;QAAElD;IAAK,IACnC5C,EAAE4D,WAAW,CAACzC,mBACdnB,EAAE4D,WAAW,CAACxC,4BACf;AAEH,gGAAgG,GAChG,OAAO,MAAM8E,iCAAiC,CAAgC,EAC5EtD,IAAI,EAGL,GACCb,aACE;QACE,GAAG+D,4BAA4B;YAAElD;QAAK,EAAE;QACxCL,gBAAgB3B;QAChBkD,wBAAwBhD;QACxBiD,kBAAkBvC;IACpB,GACAxB,EAAE4D,WAAW,CAACzC,mBACdnB,EAAE4D,WAAW,CAACxC,4BACf"}
|
|
1
|
+
{"version":3,"sources":["../../../src/collections/operations/inputSchemas.ts"],"sourcesContent":["/**\n * Shared input schemas for collection data commands.\n *\n * The Payload CLI and MCP plugin use these schemas so they accept and validate the same input.\n * Local variants include trusted options that should only be available to local callers.\n */\nimport * as z from 'zod/mini'\n\nimport {\n dataSchema,\n defaultLimitSchema,\n defaultPageSchema,\n depthSchema,\n draftSchema,\n fallbackLocaleSchema,\n fieldSchema,\n idSchema,\n joinsSchema,\n limitSchema,\n localeSchema,\n overrideAccessSchema,\n overrideLockSchema,\n overwriteExistingFilesSchema,\n pageSchema,\n paginationSchema,\n populateSchema,\n publishAllLocalesSchema,\n requireIDOrWhere,\n requireReturningForSelect,\n returningSchema,\n selectedLocalesSchema,\n selectSchema,\n showHiddenFieldsSchema,\n slugSchema,\n sortSchema,\n trashSchema,\n unpublishAllLocalesSchema,\n whereSchema,\n writeDraftSchema,\n} from '../../utilities/sharedInputSchemas.js'\nimport { strictObject } from '../../utilities/zod.js'\n\nconst countDocumentsInputShape = {\n slug: slugSchema,\n locale: localeSchema,\n trash: trashSchema,\n where: whereSchema,\n}\n\nexport const countDocumentsInputSchema = strictObject(countDocumentsInputShape)\n\n/** For trusted local callers only. Includes access bypass. */\nexport const countDocumentsLocalInputSchema = strictObject({\n ...countDocumentsInputShape,\n overrideAccess: overrideAccessSchema,\n})\n\nconst countVersionsInputShape = {\n slug: slugSchema,\n locale: localeSchema,\n where: whereSchema,\n}\n\nexport const countVersionsInputSchema = strictObject(countVersionsInputShape)\n\n/** For trusted local callers only. Includes access bypass. */\nexport const countVersionsLocalInputSchema = strictObject({\n ...countVersionsInputShape,\n overrideAccess: overrideAccessSchema,\n})\n\nconst getCreateDocumentsInputShape = <TFile extends z.core.$ZodType>({\n file,\n}: {\n file: TFile\n}) => ({\n slug: slugSchema,\n depth: depthSchema,\n documents: z\n .array(\n z.strictObject({\n data: dataSchema,\n file: z.optional(file),\n }),\n )\n .check(z.minLength(1), z.describe('A JSON array of {\"data\": {...}, \"file\"?: ...} objects.')),\n draft: writeDraftSchema,\n fallbackLocale: fallbackLocaleSchema,\n locale: localeSchema,\n populate: populateSchema,\n publishAllLocales: publishAllLocalesSchema,\n returning: returningSchema,\n select: selectSchema,\n})\n\n/** Safe for remote interfaces. Excludes trusted Local API options. */\nexport const createDocumentsInputSchema = <TFile extends z.core.$ZodType>({\n file,\n}: {\n file: TFile\n}) => strictObject(getCreateDocumentsInputShape({ file }), z.superRefine(requireReturningForSelect))\n\n/** For trusted local callers only. Includes access bypass, file overwrites, and hidden fields. */\nexport const createDocumentsLocalInputSchema = <TFile extends z.core.$ZodType>({\n file,\n}: {\n file: TFile\n}) =>\n strictObject(\n {\n ...getCreateDocumentsInputShape({ file }),\n overrideAccess: overrideAccessSchema,\n overwriteExistingFiles: overwriteExistingFilesSchema,\n showHiddenFields: showHiddenFieldsSchema,\n },\n z.superRefine(requireReturningForSelect),\n )\n\nconst deleteDocumentsInputShape = {\n id: z.optional(idSchema),\n slug: slugSchema,\n depth: depthSchema,\n fallbackLocale: fallbackLocaleSchema,\n locale: localeSchema,\n trash: trashSchema,\n where: whereSchema,\n}\n\nexport const deleteDocumentsInputSchema = strictObject(\n deleteDocumentsInputShape,\n z.superRefine(requireIDOrWhere),\n)\n\n/** For trusted local callers only. Includes access bypass. */\nexport const deleteDocumentsLocalInputSchema = strictObject(\n {\n ...deleteDocumentsInputShape,\n overrideAccess: overrideAccessSchema,\n },\n z.superRefine(requireIDOrWhere),\n)\n\nconst duplicateDocumentInputShape = {\n id: idSchema,\n slug: slugSchema,\n data: z.optional(dataSchema),\n depth: depthSchema,\n draft: writeDraftSchema,\n fallbackLocale: fallbackLocaleSchema,\n locale: localeSchema,\n populate: populateSchema,\n select: selectSchema,\n selectedLocales: selectedLocalesSchema,\n}\n\nexport const duplicateDocumentInputSchema = strictObject(duplicateDocumentInputShape)\n\n/** For trusted local callers only. Includes access bypass and hidden fields. */\nexport const duplicateDocumentLocalInputSchema = strictObject({\n ...duplicateDocumentInputShape,\n overrideAccess: overrideAccessSchema,\n showHiddenFields: showHiddenFieldsSchema,\n})\n\nconst findDistinctInputShape = {\n slug: slugSchema,\n depth: depthSchema,\n field: fieldSchema,\n limit: limitSchema,\n locale: localeSchema,\n page: pageSchema,\n populate: populateSchema,\n sort: sortSchema,\n trash: trashSchema,\n where: whereSchema,\n}\n\nexport const findDistinctInputSchema = strictObject(findDistinctInputShape)\n\n/** For trusted local callers only. Includes access bypass and hidden fields. */\nexport const findDistinctLocalInputSchema = strictObject({\n ...findDistinctInputShape,\n overrideAccess: overrideAccessSchema,\n showHiddenFields: showHiddenFieldsSchema,\n})\n\nconst findDocumentsInputShape = {\n id: z.optional(idSchema),\n slug: slugSchema,\n depth: depthSchema,\n draft: draftSchema,\n fallbackLocale: fallbackLocaleSchema,\n joins: joinsSchema,\n limit: defaultLimitSchema,\n locale: localeSchema,\n page: defaultPageSchema,\n pagination: paginationSchema,\n populate: populateSchema,\n select: selectSchema,\n sort: sortSchema,\n trash: trashSchema,\n where: whereSchema,\n}\n\nexport const findDocumentsInputSchema = strictObject(findDocumentsInputShape)\n\n/** For trusted local callers only. Includes access bypass and hidden fields. */\nexport const findDocumentsLocalInputSchema = strictObject({\n ...findDocumentsInputShape,\n overrideAccess: overrideAccessSchema,\n showHiddenFields: showHiddenFieldsSchema,\n})\n\nconst findVersionByIDInputShape = {\n id: idSchema,\n slug: slugSchema,\n depth: depthSchema,\n draft: draftSchema,\n fallbackLocale: fallbackLocaleSchema,\n locale: localeSchema,\n populate: populateSchema,\n select: selectSchema,\n trash: trashSchema,\n}\n\nexport const findVersionByIDInputSchema = strictObject(findVersionByIDInputShape)\n\n/** For trusted local callers only. Includes access bypass and hidden fields. */\nexport const findVersionByIDLocalInputSchema = strictObject({\n ...findVersionByIDInputShape,\n overrideAccess: overrideAccessSchema,\n showHiddenFields: showHiddenFieldsSchema,\n})\n\nconst findVersionsInputShape = {\n slug: slugSchema,\n depth: depthSchema,\n draft: draftSchema,\n fallbackLocale: fallbackLocaleSchema,\n limit: defaultLimitSchema,\n locale: localeSchema,\n page: defaultPageSchema,\n pagination: paginationSchema,\n populate: populateSchema,\n select: selectSchema,\n sort: sortSchema,\n trash: trashSchema,\n where: whereSchema,\n}\n\nexport const findVersionsInputSchema = strictObject(findVersionsInputShape)\n\n/** For trusted local callers only. Includes access bypass and hidden fields. */\nexport const findVersionsLocalInputSchema = strictObject({\n ...findVersionsInputShape,\n overrideAccess: overrideAccessSchema,\n showHiddenFields: showHiddenFieldsSchema,\n})\n\nexport const getCollectionSchemaInputSchema = strictObject({\n slug: slugSchema,\n})\n\nconst restoreVersionInputShape = {\n id: idSchema,\n slug: slugSchema,\n depth: depthSchema,\n draft: writeDraftSchema,\n fallbackLocale: fallbackLocaleSchema,\n locale: localeSchema,\n populate: populateSchema,\n select: selectSchema,\n}\n\nexport const restoreVersionInputSchema = strictObject(restoreVersionInputShape)\n\n/** For trusted local callers only. Includes access bypass and hidden fields. */\nexport const restoreVersionLocalInputSchema = strictObject({\n ...restoreVersionInputShape,\n overrideAccess: overrideAccessSchema,\n showHiddenFields: showHiddenFieldsSchema,\n})\n\nconst getUpdateDocumentInputShape = <TFile extends z.core.$ZodType>({ file }: { file: TFile }) => ({\n id: z.optional(idSchema),\n slug: slugSchema,\n data: dataSchema,\n depth: depthSchema,\n draft: writeDraftSchema,\n fallbackLocale: fallbackLocaleSchema,\n file: z.optional(file),\n limit: limitSchema,\n locale: localeSchema,\n overrideLock: overrideLockSchema,\n populate: populateSchema,\n publishAllLocales: publishAllLocalesSchema,\n returning: returningSchema,\n select: selectSchema,\n sort: sortSchema,\n trash: trashSchema,\n unpublishAllLocales: unpublishAllLocalesSchema,\n where: whereSchema,\n})\n\n/** Safe for remote interfaces. Excludes trusted Local API options. */\nexport const updateDocumentInputSchema = <TFile extends z.core.$ZodType>({\n file,\n}: {\n file: TFile\n}) =>\n strictObject(\n getUpdateDocumentInputShape({ file }),\n z.superRefine(requireIDOrWhere),\n z.superRefine(requireReturningForSelect),\n )\n\n/** For trusted local callers only. Includes access bypass, file overwrites, and hidden fields. */\nexport const updateDocumentLocalInputSchema = <TFile extends z.core.$ZodType>({\n file,\n}: {\n file: TFile\n}) =>\n strictObject(\n {\n ...getUpdateDocumentInputShape({ file }),\n overrideAccess: overrideAccessSchema,\n overwriteExistingFiles: overwriteExistingFilesSchema,\n showHiddenFields: showHiddenFieldsSchema,\n },\n z.superRefine(requireIDOrWhere),\n z.superRefine(requireReturningForSelect),\n )\n"],"names":["z","dataSchema","defaultLimitSchema","defaultPageSchema","depthSchema","draftSchema","fallbackLocaleSchema","fieldSchema","idSchema","joinsSchema","limitSchema","localeSchema","overrideAccessSchema","overrideLockSchema","overwriteExistingFilesSchema","pageSchema","paginationSchema","populateSchema","publishAllLocalesSchema","requireIDOrWhere","requireReturningForSelect","returningSchema","selectedLocalesSchema","selectSchema","showHiddenFieldsSchema","slugSchema","sortSchema","trashSchema","unpublishAllLocalesSchema","whereSchema","writeDraftSchema","strictObject","countDocumentsInputShape","slug","locale","trash","where","countDocumentsInputSchema","countDocumentsLocalInputSchema","overrideAccess","countVersionsInputShape","countVersionsInputSchema","countVersionsLocalInputSchema","getCreateDocumentsInputShape","file","depth","documents","array","data","optional","check","minLength","describe","draft","fallbackLocale","populate","publishAllLocales","returning","select","createDocumentsInputSchema","superRefine","createDocumentsLocalInputSchema","overwriteExistingFiles","showHiddenFields","deleteDocumentsInputShape","id","deleteDocumentsInputSchema","deleteDocumentsLocalInputSchema","duplicateDocumentInputShape","selectedLocales","duplicateDocumentInputSchema","duplicateDocumentLocalInputSchema","findDistinctInputShape","field","limit","page","sort","findDistinctInputSchema","findDistinctLocalInputSchema","findDocumentsInputShape","joins","pagination","findDocumentsInputSchema","findDocumentsLocalInputSchema","findVersionByIDInputShape","findVersionByIDInputSchema","findVersionByIDLocalInputSchema","findVersionsInputShape","findVersionsInputSchema","findVersionsLocalInputSchema","getCollectionSchemaInputSchema","restoreVersionInputShape","restoreVersionInputSchema","restoreVersionLocalInputSchema","getUpdateDocumentInputShape","overrideLock","unpublishAllLocales","updateDocumentInputSchema","updateDocumentLocalInputSchema"],"mappings":"AAAA;;;;;CAKC,GACD,YAAYA,OAAO,WAAU;AAE7B,SACEC,UAAU,EACVC,kBAAkB,EAClBC,iBAAiB,EACjBC,WAAW,EACXC,WAAW,EACXC,oBAAoB,EACpBC,WAAW,EACXC,QAAQ,EACRC,WAAW,EACXC,WAAW,EACXC,YAAY,EACZC,oBAAoB,EACpBC,kBAAkB,EAClBC,4BAA4B,EAC5BC,UAAU,EACVC,gBAAgB,EAChBC,cAAc,EACdC,uBAAuB,EACvBC,gBAAgB,EAChBC,yBAAyB,EACzBC,eAAe,EACfC,qBAAqB,EACrBC,YAAY,EACZC,sBAAsB,EACtBC,UAAU,EACVC,UAAU,EACVC,WAAW,EACXC,yBAAyB,EACzBC,WAAW,EACXC,gBAAgB,QACX,wCAAuC;AAC9C,SAASC,YAAY,QAAQ,yBAAwB;AAErD,MAAMC,2BAA2B;IAC/BC,MAAMR;IACNS,QAAQvB;IACRwB,OAAOR;IACPS,OAAOP;AACT;AAEA,OAAO,MAAMQ,4BAA4BN,aAAaC,0BAAyB;AAE/E,4DAA4D,GAC5D,OAAO,MAAMM,iCAAiCP,aAAa;IACzD,GA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B;IAC3BpD,gBAAgB3B;IAChBmD,kBAAkBvC;AACpB,GAAE;AAEF,MAAMsE,8BAA8B,CAAgC,EAAElD,IAAI,EAAmB,GAAM,CAAA;QACjGqB,IAAIjE,EAAEiD,QAAQ,CAACzC;QACfyB,MAAMR;QACNuB,MAAM/C;QACN4C,OAAOzC;QACPiD,OAAOvB;QACPwB,gBAAgBhD;QAChBsC,MAAM5C,EAAEiD,QAAQ,CAACL;QACjB8B,OAAOhE;QACPwB,QAAQvB;QACRoF,cAAclF;QACd0C,UAAUtC;QACVuC,mBAAmBtC;QACnBuC,WAAWpC;QACXqC,QAAQnC;QACRqD,MAAMlD;QACNS,OAAOR;QACPqE,qBAAqBpE;QACrBQ,OAAOP;IACT,CAAA;AAEA,oEAAoE,GACpE,OAAO,MAAMoE,4BAA4B,CAAgC,EACvErD,IAAI,EAGL,GACCb,aACE+D,4BAA4B;QAAElD;IAAK,IACnC5C,EAAE4D,WAAW,CAACzC,mBACdnB,EAAE4D,WAAW,CAACxC,4BACf;AAEH,gGAAgG,GAChG,OAAO,MAAM8E,iCAAiC,CAAgC,EAC5EtD,IAAI,EAGL,GACCb,aACE;QACE,GAAG+D,4BAA4B;YAAElD;QAAK,EAAE;QACxCL,gBAAgB3B;QAChBkD,wBAAwBhD;QACxBiD,kBAAkBvC;IACpB,GACAxB,EAAE4D,WAAW,CAACzC,mBACdnB,EAAE4D,WAAW,CAACxC,4BACf"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renameFile.d.ts","sourceRoot":"","sources":["../../../src/collections/operations/renameFile.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;
|
|
1
|
+
{"version":3,"file":"renameFile.d.ts","sourceRoot":"","sources":["../../../src/collections/operations/renameFile.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAGtE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AAmCpD,MAAM,MAAM,mBAAmB,GAAG;IAChC,UAAU,EAAE,UAAU,CAAA;IACtB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,kBAAkB,CAAC,EAAE,OAAO,CAAA;IAC5B,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,QAAQ,EAAE,MAAM,CAAA;IAChB,EAAE,EAAE,MAAM,GAAG,MAAM,CAAA;IACnB,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,GAAG,EAAE,cAAc,CAAA;CACpB,CAAA;AAED,uEAAuE;AACvE,eAAO,MAAM,mBAAmB,iBAChB,mBAAmB,KAChC,OAAO,CAAC,UAAU,CAiRpB,CAAA"}
|
|
@@ -8,8 +8,10 @@ import { replaceStoredFileReferences } from '../../uploads/fileVersioning/archiv
|
|
|
8
8
|
import { removeUnreferencedStagedObjects, scheduleUnreferencedFileCleanup } from '../../uploads/fileVersioning/cleanup.js';
|
|
9
9
|
import { abortFileOperationScope, beginFileOperationScope, completeFileOperationScope, runFileOperationPlan } from '../../uploads/fileVersioning/fileOperationManager.js';
|
|
10
10
|
import { copyLocalFile } from '../../uploads/fileVersioning/localStorage.js';
|
|
11
|
-
import {
|
|
11
|
+
import { normalizeStorageKey } from '../../uploads/fileVersioning/naming.js';
|
|
12
12
|
import { collectStoredFiles, getStoredFileIdentity, withLegacyCloudUploadFileData } from '../../uploads/fileVersioning/storedFiles.js';
|
|
13
|
+
import { getUnplannedSafeFileName } from '../../uploads/getSafeFilename.js';
|
|
14
|
+
import { isRequestTimeFile } from '../../uploads/isRequestTimeFile.js';
|
|
13
15
|
import { commitTransaction } from '../../utilities/commitTransaction.js';
|
|
14
16
|
import { initTransaction } from '../../utilities/initTransaction.js';
|
|
15
17
|
import { killTransaction } from '../../utilities/killTransaction.js';
|
|
@@ -91,24 +93,29 @@ import { updateDocument } from './utilities/update.js';
|
|
|
91
93
|
filename,
|
|
92
94
|
oldFilename
|
|
93
95
|
});
|
|
94
|
-
const
|
|
95
|
-
|
|
96
|
-
const oldStem = originalMarkerIndex > 0 ? originalStem.slice(0, originalMarkerIndex) : path.posix.parse(stored.filename).name;
|
|
97
|
-
if (filename === `${oldStem}${path.posix.extname(oldFilename)}`) {
|
|
96
|
+
const mainStem = path.posix.parse(stored.filename).name;
|
|
97
|
+
if (newStem === mainStem) {
|
|
98
98
|
throw new APIError('The upload already has this filename.', 400);
|
|
99
99
|
}
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
100
|
+
const hasDefaultRole = ({ roles })=>roles.some(({ type })=>type === 'default');
|
|
101
|
+
const getNextFilename = ({ key, roles })=>{
|
|
102
|
+
const previousFilename = path.posix.basename(key);
|
|
103
|
+
if (!hasDefaultRole({
|
|
104
|
+
roles
|
|
105
|
+
}) && roles.some(({ type })=>type === 'original')) {
|
|
106
|
+
return `${newStem}${path.posix.extname(previousFilename)}`;
|
|
107
|
+
}
|
|
108
|
+
const suffix = previousFilename.startsWith(mainStem) ? previousFilename.slice(mainStem.length) : `-${previousFilename}`;
|
|
109
|
+
return `${newStem}${suffix}`;
|
|
110
|
+
};
|
|
111
|
+
// The main file keeps the requested name; other files take a counter if they collide with it.
|
|
112
|
+
const plannedKeys = new Set(storedFiles.filter(hasDefaultRole).map((file)=>getStoredFileIdentity({
|
|
113
|
+
key: path.posix.join(path.posix.dirname(file.key), getNextFilename(file))
|
|
105
114
|
})));
|
|
106
115
|
const replacements = new Map();
|
|
107
116
|
for (const file of storedFiles){
|
|
108
|
-
const
|
|
109
|
-
|
|
110
|
-
const suffix = previousFilename.startsWith(oldStem) ? previousFilename.slice(oldStem.length) : `-${previousFilename}`;
|
|
111
|
-
let nextFilename = hasOriginalRole ? originalFilename : `${newStem}${suffix}`;
|
|
117
|
+
const isMainFile = hasDefaultRole(file);
|
|
118
|
+
let nextFilename = getNextFilename(file);
|
|
112
119
|
const directory = path.posix.dirname(file.key);
|
|
113
120
|
let nextKey = path.posix.join(directory, nextFilename);
|
|
114
121
|
let nextIdentity = getStoredFileIdentity({
|
|
@@ -117,7 +124,7 @@ import { updateDocument } from './utilities/update.js';
|
|
|
117
124
|
const extension = path.posix.extname(nextFilename);
|
|
118
125
|
const stem = nextFilename.slice(0, -extension.length || undefined);
|
|
119
126
|
let collisionNumber = 1;
|
|
120
|
-
while(!
|
|
127
|
+
while(!isMainFile && plannedKeys.has(nextIdentity)){
|
|
121
128
|
nextFilename = `${stem}-${collisionNumber}${extension}`;
|
|
122
129
|
nextKey = path.posix.join(directory, nextFilename);
|
|
123
130
|
nextIdentity = getStoredFileIdentity({
|
|
@@ -131,6 +138,16 @@ import { updateDocument } from './utilities/update.js';
|
|
|
131
138
|
});
|
|
132
139
|
replacements.set(getStoredFileIdentity(file), key);
|
|
133
140
|
}
|
|
141
|
+
// Files are copied before the old ones are removed, so one file cannot take another file's current name.
|
|
142
|
+
const currentKeys = new Set(storedFiles.map((file)=>getStoredFileIdentity(file)));
|
|
143
|
+
for (const [from, to] of replacements){
|
|
144
|
+
const toIdentity = getStoredFileIdentity({
|
|
145
|
+
key: to
|
|
146
|
+
});
|
|
147
|
+
if (toIdentity !== from && currentKeys.has(toIdentity)) {
|
|
148
|
+
throw new APIError(`This upload already uses the filename ${path.posix.basename(to)}.`, 400);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
134
151
|
const renamed = replaceStoredFileReferences({
|
|
135
152
|
files: storedFiles,
|
|
136
153
|
replacements,
|
|
@@ -139,6 +156,38 @@ import { updateDocument } from './utilities/update.js';
|
|
|
139
156
|
if (!renamed) {
|
|
140
157
|
throw new APIError('The upload has no files to rename.', 400);
|
|
141
158
|
}
|
|
159
|
+
// A dynamic main file has no file of its own. It is built from the original and shares its name.
|
|
160
|
+
const renamedOriginal = renamed.original;
|
|
161
|
+
if (isRequestTimeFile({
|
|
162
|
+
entry: stored
|
|
163
|
+
}) && renamedOriginal?.filename) {
|
|
164
|
+
renamed.filename = renamedOriginal.filename;
|
|
165
|
+
}
|
|
166
|
+
// A size with no stored file has no file to copy, so only its name changes.
|
|
167
|
+
const renamedVariants = renamed.variants ?? {};
|
|
168
|
+
const usedNames = new Set([
|
|
169
|
+
renamed.filename,
|
|
170
|
+
renamedOriginal?.filename,
|
|
171
|
+
...Object.values(renamedVariants).map((variant)=>variant?.filename)
|
|
172
|
+
]);
|
|
173
|
+
for (const variant of Object.values(renamedVariants)){
|
|
174
|
+
if (!variant || !isRequestTimeFile({
|
|
175
|
+
entry: variant
|
|
176
|
+
}) || typeof variant.filename !== 'string') {
|
|
177
|
+
continue;
|
|
178
|
+
}
|
|
179
|
+
const suffix = variant.filename.startsWith(mainStem) ? variant.filename.slice(mainStem.length) : `-${variant.filename}`;
|
|
180
|
+
variant.filename = await getUnplannedSafeFileName({
|
|
181
|
+
canUseName: (name)=>!usedNames.has(name),
|
|
182
|
+
collectionSlug: collection.config.slug,
|
|
183
|
+
desiredFilename: `${newStem}${suffix}`,
|
|
184
|
+
excludeDocumentID: id,
|
|
185
|
+
prefix: variant.prefix ?? undefined,
|
|
186
|
+
req,
|
|
187
|
+
staticPath: operations ? undefined : collection.config.upload.staticDir
|
|
188
|
+
});
|
|
189
|
+
usedNames.add(variant.filename);
|
|
190
|
+
}
|
|
142
191
|
const staticDir = collection.config.upload.staticDir;
|
|
143
192
|
const result = await runFileOperationPlan({
|
|
144
193
|
cleanupStagedAfterWriteFailure: (objects)=>removeUnreferencedStagedObjects({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/collections/operations/renameFile.ts"],"sourcesContent":["import fs from 'node:fs/promises'\nimport path from 'node:path'\n\nimport type { JsonObject, PayloadRequest } from '../../types/index.js'\nimport type { Collection } from '../config/types.js'\n\nimport { executeAccess } from '../../auth/executeAccess.js'\nimport { hasWhereAccessResult } from '../../auth/types.js'\nimport { combineQueries } from '../../database/combineQueries.js'\nimport { APIError, Forbidden, NotFound } from '../../errors/index.js'\nimport { replaceStoredFileReferences } from '../../uploads/fileVersioning/archive.js'\nimport {\n removeUnreferencedStagedObjects,\n scheduleUnreferencedFileCleanup,\n} from '../../uploads/fileVersioning/cleanup.js'\nimport {\n abortFileOperationScope,\n beginFileOperationScope,\n completeFileOperationScope,\n runFileOperationPlan,\n} from '../../uploads/fileVersioning/fileOperationManager.js'\nimport { copyLocalFile } from '../../uploads/fileVersioning/localStorage.js'\nimport { getOriginalFilename, normalizeStorageKey } from '../../uploads/fileVersioning/naming.js'\nimport {\n collectStoredFiles,\n getStoredFileIdentity,\n withLegacyCloudUploadFileData,\n} from '../../uploads/fileVersioning/storedFiles.js'\nimport { commitTransaction } from '../../utilities/commitTransaction.js'\nimport { initTransaction } from '../../utilities/initTransaction.js'\nimport { killTransaction } from '../../utilities/killTransaction.js'\nimport { getLatestCollectionVersion } from '../../versions/getLatestCollectionVersion.js'\nimport { saveVersion } from '../../versions/saveVersion.js'\nimport { buildAfterOperation } from './utilities/buildAfterOperation.js'\nimport { buildBeforeOperation } from './utilities/buildBeforeOperation.js'\nimport { updateDocument } from './utilities/update.js'\n\nexport type RenameFileArguments = {\n collection: Collection\n depth?: number\n disableTransaction?: boolean\n draft?: boolean\n filename: string\n id: number | string\n overrideAccess?: boolean\n req: PayloadRequest\n}\n\n/** Renames the current managed file set without changing its bytes. */\nexport const renameFileOperation = async (\n incomingArgs: RenameFileArguments,\n): Promise<JsonObject> => {\n let args = { ...incomingArgs, data: { filename: incomingArgs.filename } }\n const { req } = args\n beginFileOperationScope({ req })\n\n try {\n const shouldCommit = !args.disableTransaction && (await initTransaction(req))\n args = await buildBeforeOperation({\n args,\n collection: args.collection.config,\n operation: 'updateByID',\n overrideAccess: args.overrideAccess ?? false,\n })\n\n const { id, collection, draft = false, overrideAccess = false } = args\n const { filename } = args.data\n if (!collection.config.upload) {\n throw new APIError('This collection does not support file rename.', 400)\n }\n\n const access = overrideAccess\n ? true\n : await executeAccess(\n { id, slug: collection.config.slug, data: { filename }, req },\n collection.config.access.update,\n )\n const where = combineQueries({ id: { equals: id } }, access)\n const query = { collection: collection.config.slug, locale: 'all' as const, req, where }\n const current = draft\n ? await getLatestCollectionVersion({\n id,\n config: collection.config,\n payload: req.payload,\n query,\n req,\n })\n : await req.payload.db.findOne(query)\n\n if (!current) {\n throw hasWhereAccessResult(access) ? new Forbidden(req.t) : new NotFound(req.t)\n }\n const stored = await withLegacyCloudUploadFileData({\n collection: collection.config,\n doc: current as JsonObject,\n req,\n })\n const operations = collection.config.upload.fileOperations\n const storedFiles = collectStoredFiles({ collection: collection.config, doc: stored, req })\n const oldOriginal = (stored.original as { filename?: string } | undefined)?.filename\n const oldFilename = oldOriginal ?? (stored.filename as string | undefined)\n\n if (!oldFilename || !storedFiles.length) {\n throw new APIError('This upload has no managed files to rename.', 400)\n }\n\n const { newStem } = validateRename({ filename, oldFilename })\n const originalStem = path.posix.parse(oldFilename).name\n const originalMarkerIndex = originalStem.lastIndexOf('-original')\n const oldStem =\n originalMarkerIndex > 0\n ? originalStem.slice(0, originalMarkerIndex)\n : path.posix.parse(stored.filename as string).name\n if (filename === `${oldStem}${path.posix.extname(oldFilename)}`) {\n throw new APIError('The upload already has this filename.', 400)\n }\n\n const originalFilename = getOriginalFilename({ filename })\n const plannedKeys = new Set(\n storedFiles\n .filter(({ roles }) => roles.some(({ type }) => type === 'original'))\n .map(({ key }) =>\n getStoredFileIdentity({\n key: path.posix.join(path.posix.dirname(key), originalFilename),\n }),\n ),\n )\n const replacements = new Map<string, string>()\n for (const file of storedFiles) {\n const previousFilename = path.posix.basename(file.key)\n const hasOriginalRole = file.roles.some(({ type }) => type === 'original')\n const suffix = previousFilename.startsWith(oldStem)\n ? previousFilename.slice(oldStem.length)\n : `-${previousFilename}`\n let nextFilename = hasOriginalRole ? originalFilename : `${newStem}${suffix}`\n const directory = path.posix.dirname(file.key)\n let nextKey = path.posix.join(directory, nextFilename)\n let nextIdentity = getStoredFileIdentity({\n key: nextKey,\n })\n const extension = path.posix.extname(nextFilename)\n const stem = nextFilename.slice(0, -extension.length || undefined)\n let collisionNumber = 1\n while (!hasOriginalRole && plannedKeys.has(nextIdentity)) {\n nextFilename = `${stem}-${collisionNumber}${extension}`\n nextKey = path.posix.join(directory, nextFilename)\n nextIdentity = getStoredFileIdentity({\n key: nextKey,\n })\n collisionNumber++\n }\n plannedKeys.add(nextIdentity)\n const key = normalizeStorageKey({ key: nextKey })\n replacements.set(getStoredFileIdentity(file), key)\n }\n\n const renamed = replaceStoredFileReferences({\n files: storedFiles,\n replacements,\n version: stored,\n })\n if (!renamed) {\n throw new APIError('The upload has no files to rename.', 400)\n }\n\n const staticDir = collection.config.upload.staticDir\n const result = await runFileOperationPlan({\n cleanupStagedAfterWriteFailure: (objects) =>\n removeUnreferencedStagedObjects({ collection: collection.config, objects, req }),\n req,\n stage: async ({ trackStagedObject }) => {\n for (const file of storedFiles) {\n const to = replacements.get(getStoredFileIdentity(file))!\n if (!operations && staticDir) {\n try {\n await copyLocalFile({ from: file.key, staticDir, to })\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code === 'EEXIST') {\n throw new APIError(`A file named ${path.posix.basename(to)} already exists.`, 409)\n }\n throw err\n }\n trackStagedObject({\n key: to,\n remove: () => fs.rm(path.join(staticDir, to), { force: true }),\n })\n } else if (operations?.copy) {\n // Keep source files readable until the document update and its transaction succeed.\n try {\n await operations.copy({ from: file.key, req, to, trackStagedObject })\n } catch (err) {\n if (isStorageCollision({ err })) {\n throw new APIError(`A file named ${path.posix.basename(to)} already exists.`, 409)\n }\n throw err\n }\n } else {\n throw new APIError('No safe copy operation is available for this upload.', 400)\n }\n }\n },\n write: async () => {\n if (collection.config.versions) {\n const previousVersions = await req.payload.db.findVersions({\n collection: collection.config.slug,\n limit: 1,\n req,\n where: { parent: { equals: id } },\n })\n\n if (!previousVersions.docs.length) {\n await saveVersion({\n id,\n collection: collection.config,\n docWithLocales: stored,\n draft: false,\n operation: 'update',\n payload: req.payload,\n req,\n })\n }\n }\n\n const data = {\n filename: renamed.filename,\n original: renamed.original,\n url: renamed.url,\n variants: renamed.variants,\n ...(draft ? { _status: 'draft' } : {}),\n }\n const updated = await updateDocument({\n id,\n autosave: false,\n collectionConfig: collection.config,\n config: req.payload.config,\n data,\n depth: args.depth ?? 0,\n docWithLocales: stored as never,\n draftArg: draft,\n fallbackLocale: req.fallbackLocale!,\n filesToUpload: [],\n locale: req.locale!,\n overrideAccess,\n overrideLock: false,\n payload: req.payload,\n req,\n select: undefined!,\n shouldManageLocalFiles: false,\n showHiddenFields: false,\n })\n\n await scheduleUnreferencedFileCleanup({\n candidates: storedFiles,\n collection: collection.config,\n req,\n })\n return updated\n },\n })\n\n const finalResult = await buildAfterOperation({\n args,\n collection: collection.config,\n operation: 'updateByID',\n overrideAccess,\n result,\n })\n\n if (shouldCommit) {\n await commitTransaction(req)\n }\n await completeFileOperationScope({ req })\n return finalResult as JsonObject\n } catch (err) {\n await killTransaction(req)\n await abortFileOperationScope({ req })\n throw err\n }\n}\n\nconst validateRename = ({ filename, oldFilename }: { filename: string; oldFilename: string }) => {\n if (\n typeof filename !== 'string' ||\n !filename ||\n filename === '.' ||\n filename === '..' ||\n filename.includes('/') ||\n filename.includes('\\\\') ||\n filename.includes('\\0')\n ) {\n throw new APIError('Invalid filename.', 400)\n }\n\n const oldExtension = path.posix.extname(oldFilename)\n const newExtension = path.posix.extname(filename)\n if (oldExtension.toLowerCase() !== newExtension.toLowerCase()) {\n throw new APIError('The new filename must keep the original file extension.', 400)\n }\n\n return {\n newStem: filename.slice(0, -newExtension.length || undefined),\n }\n}\n\nconst isStorageCollision = ({ err }: { err: unknown }): boolean => {\n if (!err || typeof err !== 'object') {\n return false\n }\n\n const { name, code, message, statusCode } = err as {\n code?: number | string\n message?: string\n name?: string\n statusCode?: number\n }\n\n return (\n code === 'EEXIST' ||\n code === 'PreconditionFailed' ||\n code === 412 ||\n name === 'PreconditionFailed' ||\n statusCode === 409 ||\n statusCode === 412 ||\n Boolean(message?.includes('Storage destination already exists'))\n )\n}\n"],"names":["fs","path","executeAccess","hasWhereAccessResult","combineQueries","APIError","Forbidden","NotFound","replaceStoredFileReferences","removeUnreferencedStagedObjects","scheduleUnreferencedFileCleanup","abortFileOperationScope","beginFileOperationScope","completeFileOperationScope","runFileOperationPlan","copyLocalFile","getOriginalFilename","normalizeStorageKey","collectStoredFiles","getStoredFileIdentity","withLegacyCloudUploadFileData","commitTransaction","initTransaction","killTransaction","getLatestCollectionVersion","saveVersion","buildAfterOperation","buildBeforeOperation","updateDocument","renameFileOperation","incomingArgs","args","data","filename","req","shouldCommit","disableTransaction","collection","config","operation","overrideAccess","id","draft","upload","access","slug","update","where","equals","query","locale","current","payload","db","findOne","t","stored","doc","operations","fileOperations","storedFiles","oldOriginal","original","oldFilename","length","newStem","validateRename","originalStem","posix","parse","name","originalMarkerIndex","lastIndexOf","oldStem","slice","extname","originalFilename","plannedKeys","Set","filter","roles","some","type","map","key","join","dirname","replacements","Map","file","previousFilename","basename","hasOriginalRole","suffix","startsWith","nextFilename","directory","nextKey","nextIdentity","extension","stem","undefined","collisionNumber","has","add","set","renamed","files","version","staticDir","result","cleanupStagedAfterWriteFailure","objects","stage","trackStagedObject","to","get","from","err","code","remove","rm","force","copy","isStorageCollision","write","versions","previousVersions","findVersions","limit","parent","docs","docWithLocales","url","variants","_status","updated","autosave","collectionConfig","depth","draftArg","fallbackLocale","filesToUpload","overrideLock","select","shouldManageLocalFiles","showHiddenFields","candidates","finalResult","includes","oldExtension","newExtension","toLowerCase","message","statusCode","Boolean"],"mappings":"AAAA,OAAOA,QAAQ,mBAAkB;AACjC,OAAOC,UAAU,YAAW;AAK5B,SAASC,aAAa,QAAQ,8BAA6B;AAC3D,SAASC,oBAAoB,QAAQ,sBAAqB;AAC1D,SAASC,cAAc,QAAQ,mCAAkC;AACjE,SAASC,QAAQ,EAAEC,SAAS,EAAEC,QAAQ,QAAQ,wBAAuB;AACrE,SAASC,2BAA2B,QAAQ,0CAAyC;AACrF,SACEC,+BAA+B,E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H,QAAQ,CAAC,OAClB;QACA,MAAM,IAAIhJ,SAAS,qBAAqB;IAC1C;IAEA,MAAMiJ,eAAerJ,KAAKmE,KAAK,CAACO,OAAO,CAACZ;IACxC,MAAMwF,eAAetJ,KAAKmE,KAAK,CAACO,OAAO,CAAC1C;IACxC,IAAIqH,aAAaE,WAAW,OAAOD,aAAaC,WAAW,IAAI;QAC7D,MAAM,IAAInJ,SAAS,2DAA2D;IAChF;IAEA,OAAO;QACL4D,SAAShC,SAASyC,KAAK,CAAC,GAAG,CAAC6E,aAAavF,MAAM,IAAIqC;IACrD;AACF;AAEA,MAAMuB,qBAAqB,CAAC,EAAEN,GAAG,EAAoB;IACnD,IAAI,CAACA,OAAO,OAAOA,QAAQ,UAAU;QACnC,OAAO;IACT;IAEA,MAAM,EAAEhD,IAAI,EAAEiD,IAAI,EAAEkC,OAAO,EAAEC,UAAU,EAAE,GAAGpC;IAO5C,OACEC,SAAS,YACTA,SAAS,wBACTA,SAAS,OACTjD,SAAS,wBACToF,eAAe,OACfA,eAAe,OACfC,QAAQF,SAASJ,SAAS;AAE9B"}
|
|
1
|
+
{"version":3,"sources":["../../../src/collections/operations/renameFile.ts"],"sourcesContent":["import fs from 'node:fs/promises'\nimport path from 'node:path'\n\nimport type { JsonObject, PayloadRequest } from '../../types/index.js'\nimport type { StoredFileRole } from '../../uploads/fileVersioning/types.js'\nimport type { FileSize } from '../../uploads/types.js'\nimport type { Collection } from '../config/types.js'\n\nimport { executeAccess } from '../../auth/executeAccess.js'\nimport { hasWhereAccessResult } from '../../auth/types.js'\nimport { combineQueries } from '../../database/combineQueries.js'\nimport { APIError, Forbidden, NotFound } from '../../errors/index.js'\nimport { replaceStoredFileReferences } from '../../uploads/fileVersioning/archive.js'\nimport {\n removeUnreferencedStagedObjects,\n scheduleUnreferencedFileCleanup,\n} from '../../uploads/fileVersioning/cleanup.js'\nimport {\n abortFileOperationScope,\n beginFileOperationScope,\n completeFileOperationScope,\n runFileOperationPlan,\n} from '../../uploads/fileVersioning/fileOperationManager.js'\nimport { copyLocalFile } from '../../uploads/fileVersioning/localStorage.js'\nimport { normalizeStorageKey } from '../../uploads/fileVersioning/naming.js'\nimport {\n collectStoredFiles,\n getStoredFileIdentity,\n withLegacyCloudUploadFileData,\n} from '../../uploads/fileVersioning/storedFiles.js'\nimport { getUnplannedSafeFileName } from '../../uploads/getSafeFilename.js'\nimport { isRequestTimeFile } from '../../uploads/isRequestTimeFile.js'\nimport { commitTransaction } from '../../utilities/commitTransaction.js'\nimport { initTransaction } from '../../utilities/initTransaction.js'\nimport { killTransaction } from '../../utilities/killTransaction.js'\nimport { getLatestCollectionVersion } from '../../versions/getLatestCollectionVersion.js'\nimport { saveVersion } from '../../versions/saveVersion.js'\nimport { buildAfterOperation } from './utilities/buildAfterOperation.js'\nimport { buildBeforeOperation } from './utilities/buildBeforeOperation.js'\nimport { updateDocument } from './utilities/update.js'\n\nexport type RenameFileArguments = {\n collection: Collection\n depth?: number\n disableTransaction?: boolean\n draft?: boolean\n filename: string\n id: number | string\n overrideAccess?: boolean\n req: PayloadRequest\n}\n\n/** Renames the current managed file set without changing its bytes. */\nexport const renameFileOperation = async (\n incomingArgs: RenameFileArguments,\n): Promise<JsonObject> => {\n let args = { ...incomingArgs, data: { filename: incomingArgs.filename } }\n const { req } = args\n beginFileOperationScope({ req })\n\n try {\n const shouldCommit = !args.disableTransaction && (await initTransaction(req))\n args = await buildBeforeOperation({\n args,\n collection: args.collection.config,\n operation: 'updateByID',\n overrideAccess: args.overrideAccess ?? false,\n })\n\n const { id, collection, draft = false, overrideAccess = false } = args\n const { filename } = args.data\n if (!collection.config.upload) {\n throw new APIError('This collection does not support file rename.', 400)\n }\n\n const access = overrideAccess\n ? true\n : await executeAccess(\n { id, slug: collection.config.slug, data: { filename }, req },\n collection.config.access.update,\n )\n const where = combineQueries({ id: { equals: id } }, access)\n const query = { collection: collection.config.slug, locale: 'all' as const, req, where }\n const current = draft\n ? await getLatestCollectionVersion({\n id,\n config: collection.config,\n payload: req.payload,\n query,\n req,\n })\n : await req.payload.db.findOne(query)\n\n if (!current) {\n throw hasWhereAccessResult(access) ? new Forbidden(req.t) : new NotFound(req.t)\n }\n const stored = await withLegacyCloudUploadFileData({\n collection: collection.config,\n doc: current as JsonObject,\n req,\n })\n const operations = collection.config.upload.fileOperations\n const storedFiles = collectStoredFiles({ collection: collection.config, doc: stored, req })\n const oldOriginal = (stored.original as { filename?: string } | undefined)?.filename\n const oldFilename = oldOriginal ?? (stored.filename as string | undefined)\n\n if (!oldFilename || !storedFiles.length) {\n throw new APIError('This upload has no managed files to rename.', 400)\n }\n\n const { newStem } = validateRename({ filename, oldFilename })\n const mainStem = path.posix.parse(stored.filename as string).name\n if (newStem === mainStem) {\n throw new APIError('The upload already has this filename.', 400)\n }\n\n const hasDefaultRole = ({ roles }: { roles: StoredFileRole[] }) =>\n roles.some(({ type }) => type === 'default')\n const getNextFilename = ({ key, roles }: { key: string; roles: StoredFileRole[] }) => {\n const previousFilename = path.posix.basename(key)\n if (!hasDefaultRole({ roles }) && roles.some(({ type }) => type === 'original')) {\n return `${newStem}${path.posix.extname(previousFilename)}`\n }\n const suffix = previousFilename.startsWith(mainStem)\n ? previousFilename.slice(mainStem.length)\n : `-${previousFilename}`\n\n return `${newStem}${suffix}`\n }\n // The main file keeps the requested name; other files take a counter if they collide with it.\n const plannedKeys = new Set(\n storedFiles.filter(hasDefaultRole).map((file) =>\n getStoredFileIdentity({\n key: path.posix.join(path.posix.dirname(file.key), getNextFilename(file)),\n }),\n ),\n )\n const replacements = new Map<string, string>()\n for (const file of storedFiles) {\n const isMainFile = hasDefaultRole(file)\n let nextFilename = getNextFilename(file)\n const directory = path.posix.dirname(file.key)\n let nextKey = path.posix.join(directory, nextFilename)\n let nextIdentity = getStoredFileIdentity({\n key: nextKey,\n })\n const extension = path.posix.extname(nextFilename)\n const stem = nextFilename.slice(0, -extension.length || undefined)\n let collisionNumber = 1\n while (!isMainFile && plannedKeys.has(nextIdentity)) {\n nextFilename = `${stem}-${collisionNumber}${extension}`\n nextKey = path.posix.join(directory, nextFilename)\n nextIdentity = getStoredFileIdentity({\n key: nextKey,\n })\n collisionNumber++\n }\n plannedKeys.add(nextIdentity)\n const key = normalizeStorageKey({ key: nextKey })\n replacements.set(getStoredFileIdentity(file), key)\n }\n // Files are copied before the old ones are removed, so one file cannot take another file's current name.\n const currentKeys = new Set(storedFiles.map((file) => getStoredFileIdentity(file)))\n for (const [from, to] of replacements) {\n const toIdentity = getStoredFileIdentity({ key: to })\n if (toIdentity !== from && currentKeys.has(toIdentity)) {\n throw new APIError(`This upload already uses the filename ${path.posix.basename(to)}.`, 400)\n }\n }\n\n const renamed = replaceStoredFileReferences({\n files: storedFiles,\n replacements,\n version: stored,\n })\n if (!renamed) {\n throw new APIError('The upload has no files to rename.', 400)\n }\n\n // A dynamic main file has no file of its own. It is built from the original and shares its name.\n const renamedOriginal = renamed.original as { filename?: string } | undefined\n if (isRequestTimeFile({ entry: stored }) && renamedOriginal?.filename) {\n renamed.filename = renamedOriginal.filename\n }\n\n // A size with no stored file has no file to copy, so only its name changes.\n const renamedVariants = (renamed.variants ?? {}) as Record<string, FileSize | null>\n const usedNames = new Set([\n renamed.filename,\n renamedOriginal?.filename,\n ...Object.values(renamedVariants).map((variant) => variant?.filename),\n ])\n for (const variant of Object.values(renamedVariants)) {\n if (\n !variant ||\n !isRequestTimeFile({ entry: variant }) ||\n typeof variant.filename !== 'string'\n ) {\n continue\n }\n const suffix = variant.filename.startsWith(mainStem)\n ? variant.filename.slice(mainStem.length)\n : `-${variant.filename}`\n variant.filename = await getUnplannedSafeFileName({\n canUseName: (name) => !usedNames.has(name),\n collectionSlug: collection.config.slug,\n desiredFilename: `${newStem}${suffix}`,\n excludeDocumentID: id,\n prefix: variant.prefix ?? undefined,\n req,\n staticPath: operations ? undefined : collection.config.upload.staticDir,\n })\n usedNames.add(variant.filename)\n }\n\n const staticDir = collection.config.upload.staticDir\n const result = await runFileOperationPlan({\n cleanupStagedAfterWriteFailure: (objects) =>\n removeUnreferencedStagedObjects({ collection: collection.config, objects, req }),\n req,\n stage: async ({ trackStagedObject }) => {\n for (const file of storedFiles) {\n const to = replacements.get(getStoredFileIdentity(file))!\n if (!operations && staticDir) {\n try {\n await copyLocalFile({ from: file.key, staticDir, to })\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code === 'EEXIST') {\n throw new APIError(`A file named ${path.posix.basename(to)} already exists.`, 409)\n }\n throw err\n }\n trackStagedObject({\n key: to,\n remove: () => fs.rm(path.join(staticDir, to), { force: true }),\n })\n } else if (operations?.copy) {\n // Keep source files readable until the document update and its transaction succeed.\n try {\n await operations.copy({ from: file.key, req, to, trackStagedObject })\n } catch (err) {\n if (isStorageCollision({ err })) {\n throw new APIError(`A file named ${path.posix.basename(to)} already exists.`, 409)\n }\n throw err\n }\n } else {\n throw new APIError('No safe copy operation is available for this upload.', 400)\n }\n }\n },\n write: async () => {\n if (collection.config.versions) {\n const previousVersions = await req.payload.db.findVersions({\n collection: collection.config.slug,\n limit: 1,\n req,\n where: { parent: { equals: id } },\n })\n\n if (!previousVersions.docs.length) {\n await saveVersion({\n id,\n collection: collection.config,\n docWithLocales: stored,\n draft: false,\n operation: 'update',\n payload: req.payload,\n req,\n })\n }\n }\n\n const data = {\n filename: renamed.filename,\n original: renamed.original,\n url: renamed.url,\n variants: renamed.variants,\n ...(draft ? { _status: 'draft' } : {}),\n }\n const updated = await updateDocument({\n id,\n autosave: false,\n collectionConfig: collection.config,\n config: req.payload.config,\n data,\n depth: args.depth ?? 0,\n docWithLocales: stored as never,\n draftArg: draft,\n fallbackLocale: req.fallbackLocale!,\n filesToUpload: [],\n locale: req.locale!,\n overrideAccess,\n overrideLock: false,\n payload: req.payload,\n req,\n select: undefined!,\n shouldManageLocalFiles: false,\n showHiddenFields: false,\n })\n\n await scheduleUnreferencedFileCleanup({\n candidates: storedFiles,\n collection: collection.config,\n req,\n })\n return updated\n },\n })\n\n const finalResult = await buildAfterOperation({\n args,\n collection: collection.config,\n operation: 'updateByID',\n overrideAccess,\n result,\n })\n\n if (shouldCommit) {\n await commitTransaction(req)\n }\n await completeFileOperationScope({ req })\n return finalResult as JsonObject\n } catch (err) {\n await killTransaction(req)\n await abortFileOperationScope({ req })\n throw err\n }\n}\n\nconst validateRename = ({ filename, oldFilename }: { filename: string; oldFilename: string }) => {\n if (\n typeof filename !== 'string' ||\n !filename ||\n filename === '.' ||\n filename === '..' ||\n filename.includes('/') ||\n filename.includes('\\\\') ||\n filename.includes('\\0')\n ) {\n throw new APIError('Invalid filename.', 400)\n }\n\n const oldExtension = path.posix.extname(oldFilename)\n const newExtension = path.posix.extname(filename)\n if (oldExtension.toLowerCase() !== newExtension.toLowerCase()) {\n throw new APIError('The new filename must keep the original file extension.', 400)\n }\n\n return {\n newStem: filename.slice(0, -newExtension.length || undefined),\n }\n}\n\nconst isStorageCollision = ({ err }: { err: unknown }): boolean => {\n if (!err || typeof err !== 'object') {\n return false\n }\n\n const { name, code, message, statusCode } = err as {\n code?: number | string\n message?: string\n name?: string\n statusCode?: number\n }\n\n return (\n code === 'EEXIST' ||\n code === 'PreconditionFailed' ||\n code === 412 ||\n name === 'PreconditionFailed' ||\n statusCode === 409 ||\n statusCode === 412 ||\n Boolean(message?.includes('Storage destination already exists'))\n )\n}\n"],"names":["fs","path","executeAccess","hasWhereAccessResult","combineQueries","APIError","Forbidden","NotFound","replaceStoredFileReferences","removeUnreferencedStagedObjects","scheduleUnreferencedFileCleanup","abortFileOperationScope","beginFileOperationScope","completeFileOperationScope","runFileOperationPlan","copyLocalFile","normalizeStorageKey","collectStoredFiles","getStoredFileIdentity","withLegacyCloudUploadFileData","getUnplannedSafeFileName","isRequestTimeFile","commitTransaction","initTransaction","killTransaction","getLatestCollectionVersion","saveVersion","buildAfterOperation","buildBeforeOperation","updateDocument","renameFileOperation","incomingArgs","args","data","filename","req","shouldCommit","disableTransaction","collection","config","operation","overrideAccess","id","draft","upload","access","slug","update","where","equals","query","locale","current","payload","db","findOne","t","stored","doc","operations","fileOperations","storedFiles","oldOriginal","original","oldFilename","length","newStem","validateRename","mainStem","posix","parse","name","hasDefaultRole","roles","some","type","getNextFilename","key","previousFilename","basename","extname","suffix","startsWith","slice","plannedKeys","Set","filter","map","file","join","dirname","replacements","Map","isMainFile","nextFilename","directory","nextKey","nextIdentity","extension","stem","undefined","collisionNumber","has","add","set","currentKeys","from","to","toIdentity","renamed","files","version","renamedOriginal","entry","renamedVariants","variants","usedNames","Object","values","variant","canUseName","collectionSlug","desiredFilename","excludeDocumentID","prefix","staticPath","staticDir","result","cleanupStagedAfterWriteFailure","objects","stage","trackStagedObject","get","err","code","remove","rm","force","copy","isStorageCollision","write","versions","previousVersions","findVersions","limit","parent","docs","docWithLocales","url","_status","updated","autosave","collectionConfig","depth","draftArg","fallbackLocale","filesToUpload","overrideLock","select","shouldManageLocalFiles","showHiddenFields","candidates","finalResult","includes","oldExtension","newExtension","toLowerCase","message","statusCode","Boolean"],"mappings":"AAAA,OAAOA,QAAQ,mBAAkB;AACjC,OAAOC,UAAU,YAAW;AAO5B,SAASC,aAAa,QAAQ,8BAA6B;AAC3D,SAASC,oBAAoB,QAAQ,sBAAqB;AAC1D,SAASC,cAAc,QAAQ,mCAAkC;AACjE,SAASC,QAAQ,EAAEC,SAAS,EAAEC,QAAQ,QAAQ,wBAAuB;AACrE,SAASC,2BAA2B,QAAQ,0CAAyC;AACrF,SACEC,+BAA+B,EAC/BC,+BAA+B,QAC1B,0CAAyC;AAChD,SACEC,uBAAuB,EACvBC,uBAAuB,EACvBC,0BAA0B,EAC1BC,oBAAoB,QACf,uDAAsD;AAC7D,SAASC,aAAa,QAAQ,+CAA8C;AAC5E,SAASC,mBAAmB,QAAQ,yCAAwC;AAC5E,SACEC,kBAAkB,EAClBC,qBAAqB,EACrBC,6BAA6B,QACxB,8CAA6C;AACpD,SAASC,wBAAwB,QAAQ,mCAAkC;AAC3E,SAASC,iBAAiB,QAAQ,qCAAoC;AACtE,SAASC,iBA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AS,qBAAqB;IAC1C;IAEA,MAAM+J,eAAenK,KAAKoE,KAAK,CAACW,OAAO,CAAChB;IACxC,MAAMqG,eAAepK,KAAKoE,KAAK,CAACW,OAAO,CAAC9C;IACxC,IAAIkI,aAAaE,WAAW,OAAOD,aAAaC,WAAW,IAAI;QAC7D,MAAM,IAAIjK,SAAS,2DAA2D;IAChF;IAEA,OAAO;QACL6D,SAAShC,SAASiD,KAAK,CAAC,GAAG,CAACkF,aAAapG,MAAM,IAAImC;IACrD;AACF;AAEA,MAAMuC,qBAAqB,CAAC,EAAEN,GAAG,EAAoB;IACnD,IAAI,CAACA,OAAO,OAAOA,QAAQ,UAAU;QACnC,OAAO;IACT;IAEA,MAAM,EAAE9D,IAAI,EAAE+D,IAAI,EAAEiC,OAAO,EAAEC,UAAU,EAAE,GAAGnC;IAO5C,OACEC,SAAS,YACTA,SAAS,wBACTA,SAAS,OACT/D,SAAS,wBACTiG,eAAe,OACfA,eAAe,OACfC,QAAQF,SAASJ,SAAS;AAE9B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"update.d.ts","sourceRoot":"","sources":["../../../src/collections/operations/update.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;
|
|
1
|
+
{"version":3,"file":"update.d.ts","sourceRoot":"","sources":["../../../src/collections/operations/update.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAKhD,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,UAAU,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAA;AACjG,OAAO,KAAK,EACV,mBAAmB,EACnB,UAAU,EAEV,8BAA8B,EAC9B,wBAAwB,EACzB,MAAM,oBAAoB,CAAA;AAQ3B,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,WAAW,EAAE,MAAM,gBAAgB,CAAA;AA6CtE,MAAM,MAAM,SAAS,CAAC,KAAK,SAAS,cAAc,IAAI;IACpD,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,UAAU,EAAE,UAAU,CAAA;IACtB,IAAI,EAAE,WAAW,CAAC,8BAA8B,CAAC,KAAK,CAAC,CAAC,CAAA;IACxD,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,kBAAkB,CAAC,EAAE,OAAO,CAAA;IAC5B,wBAAwB,CAAC,EAAE,OAAO,CAAA;IAClC,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,sBAAsB,CAAC,EAAE,OAAO,CAAA;IAChC,QAAQ,CAAC,EAAE,YAAY,CAAA;IACvB,iBAAiB,CAAC,EAAE,OAAO,CAAA;IAC3B,GAAG,EAAE,cAAc,CAAA;IACnB,gBAAgB,CAAC,EAAE,OAAO,CAAA;IAC1B;;;;OAIG;IACH,IAAI,CAAC,EAAE,IAAI,CAAA;IACX,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,mBAAmB,CAAC,EAAE,OAAO,CAAA;IAC7B,KAAK,EAAE,KAAK,CAAA;CACb,GAAG,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,UAAU,CAAC,EAAE,QAAQ,CAAC,CAAA;AAElD,eAAO,MAAM,eAAe,GAC1B,KAAK,SAAS,cAAc,EAC5B,OAAO,SAAS,wBAAwB,CAAC,KAAK,CAAC,gBAEjC,SAAS,CAAC,KAAK,CAAC,KAC7B,OAAO,CAAC,mBAAmB,CAAC,KAAK,EAAE,OAAO,CAAC,CA2d7C,CAAA"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { randomUUID } from 'node:crypto';
|
|
2
1
|
import fs from 'node:fs/promises';
|
|
3
|
-
import path from 'node:path';
|
|
4
2
|
import { executeAccess } from '../../auth/executeAccess.js';
|
|
5
3
|
import { combineQueries } from '../../database/combineQueries.js';
|
|
6
4
|
import { validateQueryPaths } from '../../database/queryValidation/validateQueryPaths.js';
|
|
7
5
|
import { validateSortQuery } from '../../database/queryValidation/validateSortQuery.js';
|
|
8
6
|
import { sanitizeWhereQuery } from '../../database/sanitizeWhereQuery.js';
|
|
9
7
|
import { APIError } from '../../errors/index.js';
|
|
8
|
+
import { copyTempFileForDocument } from '../../uploads/copyTempFileForDocument.js';
|
|
9
|
+
import { createSharedClientUploadDownload } from '../../uploads/createSharedClientUploadDownload.js';
|
|
10
10
|
import { runCloudFileUpdate } from '../../uploads/fileVersioning/cloudStorage.js';
|
|
11
11
|
import { abortFileOperationScope, beginFileOperationScope, completeFileOperationScope, shareFileOperationScope } from '../../uploads/fileVersioning/fileOperationManager.js';
|
|
12
12
|
import { withLegacyCloudUploadFileData } from '../../uploads/fileVersioning/storedFiles.js';
|
|
@@ -210,6 +210,7 @@ export const updateOperation = async (incomingArgs)=>{
|
|
|
210
210
|
throwOnMissingFile: false
|
|
211
211
|
}) : null;
|
|
212
212
|
const errors = [];
|
|
213
|
+
const sharedClientUploadDownload = createSharedClientUploadDownload();
|
|
213
214
|
const processDocument = async (incomingDoc)=>{
|
|
214
215
|
let docWithLocales = incomingDoc;
|
|
215
216
|
const { id } = docWithLocales;
|
|
@@ -225,9 +226,9 @@ export const updateOperation = async (incomingArgs)=>{
|
|
|
225
226
|
...req.file
|
|
226
227
|
} : undefined;
|
|
227
228
|
if (collectionConfig.upload && documentFile?.tempFilePath) {
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
229
|
+
documentTempFilePath = await copyTempFileForDocument({
|
|
230
|
+
tempFilePath: documentFile.tempFilePath
|
|
231
|
+
});
|
|
231
232
|
documentFile.tempFilePath = documentTempFilePath;
|
|
232
233
|
}
|
|
233
234
|
if (collectionConfig.upload && sharedGeneratedFileData === null) {
|
|
@@ -260,6 +261,7 @@ export const updateOperation = async (incomingArgs)=>{
|
|
|
260
261
|
locale: locale === 'all' || !locale ? config.localization ? config.localization.defaultLocale : undefined : locale,
|
|
261
262
|
localizedProperties: getLocalizedUploadProperties(collectionConfig.flattenedFields)
|
|
262
263
|
}),
|
|
264
|
+
fetchFullClientUpload: sharedClientUploadDownload.fetchFullClientUpload,
|
|
263
265
|
operation: 'update',
|
|
264
266
|
originalDoc: docWithLocales,
|
|
265
267
|
overwriteExistingFiles,
|
|
@@ -341,15 +343,24 @@ export const updateOperation = async (incomingArgs)=>{
|
|
|
341
343
|
message: error instanceof Error ? error.message : 'Unknown error'
|
|
342
344
|
});
|
|
343
345
|
} finally{
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
346
|
+
// generateFileData can replace the document's file with its copy of the shared client
|
|
347
|
+
// upload download. That copy is only on the document's request, so the operation
|
|
348
|
+
// cleanup misses it.
|
|
349
|
+
const downloadedTempFilePath = documentReq !== req ? documentReq.file?.tempFilePath : undefined;
|
|
350
|
+
for (const tempFilePath of new Set([
|
|
351
|
+
documentTempFilePath,
|
|
352
|
+
downloadedTempFilePath
|
|
353
|
+
])){
|
|
354
|
+
if (tempFilePath) {
|
|
355
|
+
await fs.rm(tempFilePath, {
|
|
356
|
+
force: true
|
|
357
|
+
}).catch((error)=>{
|
|
358
|
+
req.payload.logger.error({
|
|
359
|
+
err: error,
|
|
360
|
+
msg: 'Failed to remove temp file copy'
|
|
361
|
+
});
|
|
351
362
|
});
|
|
352
|
-
}
|
|
363
|
+
}
|
|
353
364
|
}
|
|
354
365
|
}
|
|
355
366
|
return null;
|
|
@@ -360,13 +371,23 @@ export const updateOperation = async (incomingArgs)=>{
|
|
|
360
371
|
// stay parallel. Other bulk updates retain their existing parallel behavior.
|
|
361
372
|
const processSequentially = req.payload.db.bulkOperationsSingleTransaction || Boolean(collectionConfig.upload && req.file);
|
|
362
373
|
let awaitedDocs;
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
374
|
+
try {
|
|
375
|
+
if (processSequentially) {
|
|
376
|
+
awaitedDocs = [];
|
|
377
|
+
for (const doc of docs){
|
|
378
|
+
awaitedDocs.push(await processDocument(doc));
|
|
379
|
+
}
|
|
380
|
+
} else {
|
|
381
|
+
awaitedDocs = await Promise.all(docs.map(processDocument));
|
|
367
382
|
}
|
|
368
|
-
}
|
|
369
|
-
|
|
383
|
+
} finally{
|
|
384
|
+
// Each document removes its own copy; the shared download is removed once here.
|
|
385
|
+
await sharedClientUploadDownload.removeSharedDownload().catch((error)=>{
|
|
386
|
+
req.payload.logger.error({
|
|
387
|
+
err: error,
|
|
388
|
+
msg: 'Failed to remove temp file'
|
|
389
|
+
});
|
|
390
|
+
});
|
|
370
391
|
}
|
|
371
392
|
await unlinkTempFiles({
|
|
372
393
|
collectionConfig,
|