payload 3.42.0 → 3.43.0-internal.c5bbc84
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/functions/index.d.ts +8 -0
- package/dist/admin/functions/index.d.ts.map +1 -1
- package/dist/admin/functions/index.js.map +1 -1
- package/dist/admin/types.d.ts +1 -1
- package/dist/admin/types.d.ts.map +1 -1
- package/dist/admin/types.js.map +1 -1
- package/dist/admin/views/folderList.d.ts +14 -5
- package/dist/admin/views/folderList.d.ts.map +1 -1
- package/dist/admin/views/folderList.js.map +1 -1
- package/dist/auth/crypto.d.ts.map +1 -1
- package/dist/auth/crypto.js +6 -3
- package/dist/auth/crypto.js.map +1 -1
- package/dist/auth/operations/unlock.d.ts.map +1 -1
- package/dist/auth/operations/unlock.js +1 -2
- package/dist/auth/operations/unlock.js.map +1 -1
- package/dist/auth/strategies/local/authenticate.d.ts.map +1 -1
- package/dist/auth/strategies/local/authenticate.js +1 -0
- package/dist/auth/strategies/local/authenticate.js.map +1 -1
- package/dist/bin/index.js.map +1 -1
- package/dist/bin/migrate.d.ts.map +1 -1
- package/dist/bin/migrate.js +2 -2
- package/dist/bin/migrate.js.map +1 -1
- package/dist/collections/config/client.d.ts.map +1 -1
- package/dist/collections/config/client.js +3 -1
- package/dist/collections/config/client.js.map +1 -1
- package/dist/collections/dataloader.d.ts.map +1 -1
- package/dist/collections/dataloader.js +0 -1
- package/dist/collections/dataloader.js.map +1 -1
- package/dist/collections/operations/delete.d.ts.map +1 -1
- package/dist/collections/operations/delete.js +1 -2
- package/dist/collections/operations/delete.js.map +1 -1
- package/dist/collections/operations/findVersions.js +0 -1
- package/dist/collections/operations/findVersions.js.map +1 -1
- package/dist/collections/operations/update.d.ts.map +1 -1
- package/dist/collections/operations/update.js +3 -2
- package/dist/collections/operations/update.js.map +1 -1
- package/dist/config/client.d.ts.map +1 -1
- package/dist/config/client.js +1 -1
- package/dist/config/client.js.map +1 -1
- package/dist/config/sanitize.d.ts.map +1 -1
- package/dist/config/sanitize.js +1 -2
- package/dist/config/sanitize.js.map +1 -1
- package/dist/database/queryValidation/validateQueryPaths.d.ts.map +1 -1
- package/dist/database/queryValidation/validateQueryPaths.js +0 -1
- package/dist/database/queryValidation/validateQueryPaths.js.map +1 -1
- package/dist/database/queryValidation/validateSearchParams.d.ts.map +1 -1
- package/dist/database/queryValidation/validateSearchParams.js +0 -1
- package/dist/database/queryValidation/validateSearchParams.js.map +1 -1
- package/dist/database/sanitizeJoinQuery.d.ts.map +1 -1
- package/dist/database/sanitizeJoinQuery.js +3 -1
- package/dist/database/sanitizeJoinQuery.js.map +1 -1
- package/dist/fields/config/client.d.ts.map +1 -1
- package/dist/fields/config/client.js +6 -1
- package/dist/fields/config/client.js.map +1 -1
- package/dist/fields/config/sanitize.d.ts.map +1 -1
- package/dist/fields/config/sanitize.js +0 -1
- package/dist/fields/config/sanitize.js.map +1 -1
- package/dist/fields/hooks/afterRead/index.d.ts.map +1 -1
- package/dist/fields/hooks/afterRead/index.js +0 -1
- package/dist/fields/hooks/afterRead/index.js.map +1 -1
- package/dist/fields/hooks/afterRead/relationshipPopulationPromise.d.ts.map +1 -1
- package/dist/fields/hooks/afterRead/relationshipPopulationPromise.js +1 -2
- package/dist/fields/hooks/afterRead/relationshipPopulationPromise.js.map +1 -1
- package/dist/fields/hooks/beforeChange/promise.d.ts.map +1 -1
- package/dist/fields/hooks/beforeChange/promise.js +0 -1
- package/dist/fields/hooks/beforeChange/promise.js.map +1 -1
- package/dist/fields/setDefaultBeforeDuplicate.js.map +1 -1
- package/dist/fields/validations.d.ts.map +1 -1
- package/dist/fields/validations.js +1 -2
- package/dist/fields/validations.js.map +1 -1
- package/dist/folders/types.d.ts +2 -0
- package/dist/folders/types.d.ts.map +1 -1
- package/dist/folders/types.js.map +1 -1
- package/dist/globals/config/client.d.ts.map +1 -1
- package/dist/globals/config/client.js +2 -1
- package/dist/globals/config/client.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -3
- package/dist/index.js.map +1 -1
- package/dist/queues/operations/runJobs/index.d.ts.map +1 -1
- package/dist/queues/operations/runJobs/index.js +0 -1
- package/dist/queues/operations/runJobs/index.js.map +1 -1
- package/dist/queues/operations/runJobs/runJSONJob/index.d.ts.map +1 -1
- package/dist/queues/operations/runJobs/runJSONJob/index.js +2 -2
- package/dist/queues/operations/runJobs/runJSONJob/index.js.map +1 -1
- package/dist/queues/operations/runJobs/runJob/getRunTaskFunction.d.ts.map +1 -1
- package/dist/queues/operations/runJobs/runJob/getRunTaskFunction.js +0 -1
- package/dist/queues/operations/runJobs/runJob/getRunTaskFunction.js.map +1 -1
- package/dist/queues/operations/runJobs/runJob/getUpdateJobFunction.d.ts.map +1 -1
- package/dist/queues/operations/runJobs/runJob/getUpdateJobFunction.js +1 -1
- package/dist/queues/operations/runJobs/runJob/getUpdateJobFunction.js.map +1 -1
- package/dist/queues/operations/runJobs/runJob/importHandlerPath.d.ts.map +1 -1
- package/dist/queues/operations/runJobs/runJob/importHandlerPath.js +1 -2
- package/dist/queues/operations/runJobs/runJob/importHandlerPath.js.map +1 -1
- package/dist/queues/operations/runJobs/runJob/index.d.ts.map +1 -1
- package/dist/queues/operations/runJobs/runJob/index.js +2 -2
- package/dist/queues/operations/runJobs/runJob/index.js.map +1 -1
- package/dist/uploads/cropImage.d.ts +0 -1
- package/dist/uploads/cropImage.d.ts.map +1 -1
- package/dist/uploads/cropImage.js +2 -3
- package/dist/uploads/cropImage.js.map +1 -1
- package/dist/uploads/endpoints/getFile.d.ts.map +1 -1
- package/dist/uploads/endpoints/getFile.js +0 -1
- package/dist/uploads/endpoints/getFile.js.map +1 -1
- package/dist/uploads/endpoints/getFileFromURL.d.ts.map +1 -1
- package/dist/uploads/endpoints/getFileFromURL.js +2 -3
- package/dist/uploads/endpoints/getFileFromURL.js.map +1 -1
- package/dist/uploads/fetchAPI-multipart/fileFactory.d.ts.map +1 -1
- package/dist/uploads/fetchAPI-multipart/fileFactory.js +1 -0
- package/dist/uploads/fetchAPI-multipart/fileFactory.js.map +1 -1
- package/dist/uploads/fetchAPI-multipart/processMultipart.d.ts +6 -0
- package/dist/uploads/fetchAPI-multipart/processMultipart.d.ts.map +1 -1
- package/dist/uploads/fetchAPI-multipart/processMultipart.js +0 -1
- package/dist/uploads/fetchAPI-multipart/processMultipart.js.map +1 -1
- package/dist/uploads/fetchAPI-multipart/processNested.d.ts +1 -1
- package/dist/uploads/fetchAPI-multipart/processNested.d.ts.map +1 -1
- package/dist/uploads/fetchAPI-multipart/processNested.js +0 -1
- package/dist/uploads/fetchAPI-multipart/processNested.js.map +1 -1
- package/dist/uploads/fetchAPI-multipart/utilities.d.ts +1 -1
- package/dist/uploads/fetchAPI-multipart/utilities.d.ts.map +1 -1
- package/dist/uploads/fetchAPI-multipart/utilities.js +0 -1
- package/dist/uploads/fetchAPI-multipart/utilities.js.map +1 -1
- package/dist/uploads/fetchAPI-stream-file/index.d.ts +1 -1
- package/dist/uploads/fetchAPI-stream-file/index.d.ts.map +1 -1
- package/dist/uploads/fetchAPI-stream-file/index.js +0 -1
- package/dist/uploads/fetchAPI-stream-file/index.js.map +1 -1
- package/dist/uploads/tempFile.d.ts +1 -1
- package/dist/uploads/tempFile.d.ts.map +1 -1
- package/dist/uploads/tempFile.js +0 -1
- package/dist/uploads/tempFile.js.map +1 -1
- package/dist/utilities/addLocalesToRequest.d.ts.map +1 -1
- package/dist/utilities/addLocalesToRequest.js +0 -1
- package/dist/utilities/addLocalesToRequest.js.map +1 -1
- package/dist/utilities/configToJSONSchema.d.ts.map +1 -1
- package/dist/utilities/configToJSONSchema.js +2 -1
- package/dist/utilities/configToJSONSchema.js.map +1 -1
- package/dist/utilities/deepCopyObject.js +1 -2
- package/dist/utilities/deepCopyObject.js.map +1 -1
- package/dist/utilities/fieldSchemaToJSON.d.ts.map +1 -1
- package/dist/utilities/fieldSchemaToJSON.js +0 -1
- package/dist/utilities/fieldSchemaToJSON.js.map +1 -1
- package/dist/utilities/flattenTopLevelFields.d.ts.map +1 -1
- package/dist/utilities/flattenTopLevelFields.js +0 -1
- package/dist/utilities/flattenTopLevelFields.js.map +1 -1
- package/dist/utilities/formatErrors.d.ts.map +1 -1
- package/dist/utilities/formatErrors.js +0 -1
- package/dist/utilities/formatErrors.js.map +1 -1
- package/dist/utilities/getCollectionIDFieldTypes.d.ts.map +1 -1
- package/dist/utilities/getCollectionIDFieldTypes.js +0 -1
- package/dist/utilities/getCollectionIDFieldTypes.js.map +1 -1
- package/dist/utilities/getDataByPath.d.ts.map +1 -1
- package/dist/utilities/getDataByPath.js +0 -1
- package/dist/utilities/getDataByPath.js.map +1 -1
- package/dist/utilities/getEntityPolicies.d.ts.map +1 -1
- package/dist/utilities/getEntityPolicies.js +3 -2
- package/dist/utilities/getEntityPolicies.js.map +1 -1
- package/dist/utilities/getFieldPermissions.d.ts.map +1 -1
- package/dist/utilities/getFieldPermissions.js +2 -3
- package/dist/utilities/getFieldPermissions.js.map +1 -1
- package/dist/utilities/getObjectDotNotation.d.ts.map +1 -1
- package/dist/utilities/getObjectDotNotation.js +0 -1
- package/dist/utilities/getObjectDotNotation.js.map +1 -1
- package/dist/utilities/getSiblingData.d.ts.map +1 -1
- package/dist/utilities/getSiblingData.js +0 -1
- package/dist/utilities/getSiblingData.js.map +1 -1
- package/dist/utilities/getUniqueListBy.d.ts.map +1 -1
- package/dist/utilities/getUniqueListBy.js +0 -1
- package/dist/utilities/getUniqueListBy.js.map +1 -1
- package/dist/utilities/handleEndpoints.d.ts.map +1 -1
- package/dist/utilities/handleEndpoints.js +2 -2
- package/dist/utilities/handleEndpoints.js.map +1 -1
- package/dist/utilities/logError.d.ts.map +1 -1
- package/dist/utilities/logError.js +0 -1
- package/dist/utilities/logError.js.map +1 -1
- package/dist/utilities/reduceFieldsToValues.d.ts.map +1 -1
- package/dist/utilities/reduceFieldsToValues.js +0 -1
- package/dist/utilities/reduceFieldsToValues.js.map +1 -1
- package/dist/utilities/sanitizeJoinParams.d.ts +1 -1
- package/dist/utilities/sanitizeJoinParams.d.ts.map +1 -1
- package/dist/utilities/sanitizeJoinParams.js +2 -2
- package/dist/utilities/sanitizeJoinParams.js.map +1 -1
- package/dist/utilities/sanitizePermissions.d.ts.map +1 -1
- package/dist/utilities/sanitizePermissions.js +2 -2
- package/dist/utilities/sanitizePermissions.js.map +1 -1
- package/dist/utilities/sanitizePopulateParam.d.ts.map +1 -1
- package/dist/utilities/sanitizePopulateParam.js +1 -1
- package/dist/utilities/sanitizePopulateParam.js.map +1 -1
- package/dist/utilities/sanitizeSelectParam.d.ts.map +1 -1
- package/dist/utilities/sanitizeSelectParam.js +4 -2
- package/dist/utilities/sanitizeSelectParam.js.map +1 -1
- package/dist/utilities/telemetry/conf/envPaths.d.ts +1 -1
- package/dist/utilities/telemetry/conf/envPaths.d.ts.map +1 -1
- package/dist/utilities/telemetry/conf/envPaths.js.map +1 -1
- package/dist/utilities/timestamp.d.ts +1 -1
- package/dist/utilities/timestamp.d.ts.map +1 -1
- package/dist/utilities/timestamp.js +0 -1
- package/dist/utilities/timestamp.js.map +1 -1
- package/dist/utilities/traverseFields.d.ts.map +1 -1
- package/dist/utilities/traverseFields.js +6 -1
- package/dist/utilities/traverseFields.js.map +1 -1
- package/dist/utilities/unflatten.d.ts.map +1 -1
- package/dist/utilities/unflatten.js +1 -2
- package/dist/utilities/unflatten.js.map +1 -1
- package/dist/utilities/wait.d.ts +1 -1
- package/dist/utilities/wait.d.ts.map +1 -1
- package/dist/utilities/wait.js +0 -1
- package/dist/utilities/wait.js.map +1 -1
- package/dist/versions/baseFields.d.ts +2 -7
- package/dist/versions/baseFields.d.ts.map +1 -1
- package/dist/versions/baseFields.js.map +1 -1
- package/dist/versions/drafts/replaceWithDraftIfAvailable.d.ts.map +1 -1
- package/dist/versions/drafts/replaceWithDraftIfAvailable.js +1 -0
- package/dist/versions/drafts/replaceWithDraftIfAvailable.js.map +1 -1
- package/dist/versions/getLatestGlobalVersion.d.ts.map +1 -1
- package/dist/versions/getLatestGlobalVersion.js +3 -1
- package/dist/versions/getLatestGlobalVersion.js.map +1 -1
- package/dist/versions/saveVersion.js +1 -1
- package/dist/versions/saveVersion.js.map +1 -1
- package/package.json +3 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/fields/config/sanitize.ts"],"sourcesContent":["// @ts-strict-ignore\nimport { deepMergeSimple } from '@payloadcms/translations/utilities'\nimport { v4 as uuid } from 'uuid'\n\nimport type {\n CollectionConfig,\n SanitizedJoin,\n SanitizedJoins,\n} from '../../collections/config/types.js'\nimport type { Config, SanitizedConfig } from '../../config/types.js'\nimport type { Field } from './types.js'\n\nimport {\n DuplicateFieldName,\n InvalidFieldName,\n InvalidFieldRelationship,\n MissingEditorProp,\n MissingFieldType,\n} from '../../errors/index.js'\nimport { ReservedFieldName } from '../../errors/ReservedFieldName.js'\nimport { formatLabels, toWords } from '../../utilities/formatLabels.js'\nimport { baseBlockFields } from '../baseFields/baseBlockFields.js'\nimport { baseIDField } from '../baseFields/baseIDField.js'\nimport { baseTimezoneField } from '../baseFields/timezone/baseField.js'\nimport { defaultTimezones } from '../baseFields/timezone/defaultTimezones.js'\nimport { setDefaultBeforeDuplicate } from '../setDefaultBeforeDuplicate.js'\nimport { validations } from '../validations.js'\nimport {\n reservedAPIKeyFieldNames,\n reservedBaseAuthFieldNames,\n reservedBaseUploadFieldNames,\n reservedVerifyFieldNames,\n} from './reservedFieldNames.js'\nimport { sanitizeJoinField } from './sanitizeJoinField.js'\nimport { fieldAffectsData as _fieldAffectsData, fieldIsLocalized, tabHasName } from './types.js'\n\ntype Args = {\n collectionConfig?: CollectionConfig\n config: Config\n existingFieldNames?: Set<string>\n fields: Field[]\n /**\n * Used to prevent unnecessary sanitization of fields that are not top-level.\n */\n isTopLevelField?: boolean\n joinPath?: string\n /**\n * When not passed in, assume that join are not supported (globals, arrays, blocks)\n */\n joins?: SanitizedJoins\n parentIsLocalized: boolean\n polymorphicJoins?: SanitizedJoin[]\n /**\n * If true, a richText field will require an editor property to be set, as the sanitizeFields function will not add it from the payload config if not present.\n *\n * @default false\n */\n requireFieldLevelRichTextEditor?: boolean\n /**\n * If this property is set, RichText fields won't be sanitized immediately. Instead, they will be added to this array as promises\n * so that you can sanitize them together, after the config has been sanitized.\n */\n richTextSanitizationPromises?: Array<(config: SanitizedConfig) => Promise<void>>\n /**\n * If not null, will validate that upload and relationship fields do not relate to a collection that is not in this array.\n * This validation will be skipped if validRelationships is null.\n */\n validRelationships: null | string[]\n}\n\nexport const sanitizeFields = async ({\n collectionConfig,\n config,\n existingFieldNames = new Set(),\n fields,\n isTopLevelField = true,\n joinPath = '',\n joins,\n parentIsLocalized,\n polymorphicJoins,\n requireFieldLevelRichTextEditor = false,\n richTextSanitizationPromises,\n validRelationships,\n}: Args): Promise<Field[]> => {\n if (!fields) {\n return []\n }\n\n for (let i = 0; i < fields.length; i++) {\n const field = fields[i]!\n\n if ('_sanitized' in field && field._sanitized === true) {\n continue\n }\n\n if ('_sanitized' in field) {\n field._sanitized = true\n }\n\n if (!field.type) {\n throw new MissingFieldType(field)\n }\n\n const fieldAffectsData = _fieldAffectsData(field)\n\n if (isTopLevelField && fieldAffectsData && field.name) {\n if (collectionConfig && collectionConfig.upload) {\n if (reservedBaseUploadFieldNames.includes(field.name)) {\n throw new ReservedFieldName(field, field.name)\n }\n }\n\n if (\n collectionConfig &&\n collectionConfig.auth &&\n typeof collectionConfig.auth === 'object' &&\n !collectionConfig.auth.disableLocalStrategy\n ) {\n if (reservedBaseAuthFieldNames.includes(field.name)) {\n throw new ReservedFieldName(field, field.name)\n }\n\n if (collectionConfig.auth.verify) {\n // @ts-expect-error - vestiges of when tsconfig was not strict. Feel free to improve\n if (reservedAPIKeyFieldNames.includes(field.name)) {\n throw new ReservedFieldName(field, field.name)\n }\n\n // @ts-expect-error - vestiges of when tsconfig was not strict. Feel free to improve\n if (reservedVerifyFieldNames.includes(field.name)) {\n throw new ReservedFieldName(field, field.name)\n }\n }\n }\n }\n\n // assert that field names do not contain forbidden characters\n if (fieldAffectsData && field.name.includes('.')) {\n throw new InvalidFieldName(field, field.name)\n }\n\n // Auto-label\n if (\n 'name' in field &&\n field.name &&\n typeof field.label !== 'object' &&\n typeof field.label !== 'string' &&\n typeof field.label !== 'function' &&\n field.label !== false\n ) {\n field.label = toWords(field.name)\n }\n\n if (\n field.type === 'checkbox' &&\n typeof field.defaultValue === 'undefined' &&\n field.required === true\n ) {\n field.defaultValue = false\n }\n\n if (field.type === 'join') {\n sanitizeJoinField({ config, field, joinPath, joins, parentIsLocalized, polymorphicJoins })\n }\n\n if (field.type === 'relationship' || field.type === 'upload') {\n if (validRelationships) {\n const relationships = Array.isArray(field.relationTo)\n ? field.relationTo\n : [field.relationTo]\n\n relationships.forEach((relationship: string) => {\n if (!validRelationships.includes(relationship)) {\n throw new InvalidFieldRelationship(field, relationship)\n }\n })\n }\n\n if (field.min && !field.minRows) {\n console.warn(\n `(payload): The \"min\" property is deprecated for the Relationship field \"${field.name}\" and will be removed in a future version. Please use \"minRows\" instead.`,\n )\n field.minRows = field.min\n }\n\n if (field.max && !field.maxRows) {\n console.warn(\n `(payload): The \"max\" property is deprecated for the Relationship field \"${field.name}\" and will be removed in a future version. Please use \"maxRows\" instead.`,\n )\n field.maxRows = field.max\n }\n }\n\n if (field.type === 'upload') {\n if (!field.admin || !('isSortable' in field.admin)) {\n field.admin = {\n isSortable: true,\n ...field.admin,\n }\n }\n }\n\n if (field.type === 'array' && field.fields) {\n field.fields.push(baseIDField)\n }\n\n if ((field.type === 'blocks' || field.type === 'array') && field.label) {\n field.labels = field.labels || formatLabels(field.name)\n }\n\n if (fieldAffectsData) {\n if (existingFieldNames.has(field.name)) {\n throw new DuplicateFieldName(field.name)\n } else if (!['blockName', 'id'].includes(field.name)) {\n existingFieldNames.add(field.name)\n }\n\n if (typeof field.localized !== 'undefined') {\n let shouldDisableLocalized = !config.localization\n\n if (\n process.env.NEXT_PUBLIC_PAYLOAD_COMPATIBILITY_allowLocalizedWithinLocalized !== 'true' &&\n parentIsLocalized &&\n // @todo PAYLOAD_DO_NOT_SANITIZE_LOCALIZED_PROPERTY=true will be the default in 4.0\n process.env.PAYLOAD_DO_NOT_SANITIZE_LOCALIZED_PROPERTY !== 'true'\n ) {\n shouldDisableLocalized = true\n }\n\n if (shouldDisableLocalized) {\n delete field.localized\n }\n }\n\n if (typeof field.validate === 'undefined') {\n const defaultValidate = validations[field.type]\n if (defaultValidate) {\n field.validate = (val, options) => defaultValidate(val, { ...field, ...options })\n } else {\n field.validate = (): true => true\n }\n }\n\n if (!field.hooks) {\n field.hooks = {}\n }\n\n if (!field.access) {\n field.access = {}\n }\n\n setDefaultBeforeDuplicate(field, parentIsLocalized)\n }\n\n if (!field.admin) {\n field.admin = {}\n }\n\n // Make sure that the richText field has an editor\n if (field.type === 'richText') {\n const sanitizeRichText = async (_config: SanitizedConfig) => {\n if (!field.editor) {\n if (_config.editor && !requireFieldLevelRichTextEditor) {\n // config.editor should be sanitized at this point\n field.editor = _config.editor\n } else {\n throw new MissingEditorProp(field) // while we allow disabling editor functionality, you should not have any richText fields defined if you do not have an editor\n }\n }\n\n if (typeof field.editor === 'function') {\n field.editor = await field.editor({\n config: _config,\n isRoot: requireFieldLevelRichTextEditor,\n parentIsLocalized: (parentIsLocalized || field.localized)!,\n })\n }\n\n if (field.editor.i18n && Object.keys(field.editor.i18n).length >= 0) {\n config.i18n!.translations = deepMergeSimple(config.i18n!.translations!, field.editor.i18n)\n }\n }\n if (richTextSanitizationPromises) {\n richTextSanitizationPromises.push(sanitizeRichText)\n } else {\n await sanitizeRichText(config as unknown as SanitizedConfig)\n }\n }\n\n if (field.type === 'blocks' && field.blocks) {\n if (field.blockReferences && field.blocks?.length) {\n throw new Error('You cannot have both blockReferences and blocks in the same blocks field')\n }\n\n const blockSlugs: string[] = []\n\n for (const block of field.blockReferences ?? field.blocks) {\n const blockSlug = typeof block === 'string' ? block : block.slug\n\n if (blockSlugs.includes(blockSlug)) {\n throw new DuplicateFieldName(blockSlug)\n }\n\n blockSlugs.push(blockSlug)\n\n if (typeof block === 'string') {\n continue\n }\n\n if (block._sanitized === true) {\n continue\n }\n\n block._sanitized = true\n block.fields = block.fields.concat(baseBlockFields)\n block.labels = !block.labels ? formatLabels(block.slug) : block.labels\n block.fields = await sanitizeFields({\n collectionConfig,\n config,\n existingFieldNames: new Set(),\n fields: block.fields,\n isTopLevelField: false,\n parentIsLocalized: (parentIsLocalized || field.localized)!,\n requireFieldLevelRichTextEditor,\n richTextSanitizationPromises,\n validRelationships,\n })\n }\n }\n\n if ('fields' in field && field.fields) {\n field.fields = await sanitizeFields({\n collectionConfig,\n config,\n existingFieldNames: fieldAffectsData ? new Set() : existingFieldNames,\n fields: field.fields,\n isTopLevelField: isTopLevelField && !fieldAffectsData,\n joinPath: fieldAffectsData ? `${joinPath ? joinPath + '.' : ''}${field.name}` : joinPath,\n joins,\n parentIsLocalized: parentIsLocalized || fieldIsLocalized(field),\n polymorphicJoins,\n requireFieldLevelRichTextEditor,\n richTextSanitizationPromises,\n validRelationships,\n })\n }\n\n if (field.type === 'tabs') {\n for (let j = 0; j < field.tabs.length; j++) {\n const tab = field.tabs[j]!\n\n const isNamedTab = tabHasName(tab)\n\n if (isNamedTab && typeof tab.label === 'undefined') {\n tab.label = toWords(tab.name)\n }\n\n if (\n 'admin' in tab &&\n tab.admin?.condition &&\n typeof tab.admin.condition === 'function' &&\n !tab.id\n ) {\n // Always attach a UUID to tabs with a condition so there's no conflicts even if there are duplicate nested names\n tab.id = isNamedTab ? `${tab.name}_${uuid()}` : uuid()\n }\n\n tab.fields = await sanitizeFields({\n collectionConfig,\n config,\n existingFieldNames: isNamedTab ? new Set() : existingFieldNames,\n fields: tab.fields,\n isTopLevelField: isTopLevelField && !isNamedTab,\n joinPath: isNamedTab ? `${joinPath ? joinPath + '.' : ''}${tab.name}` : joinPath,\n joins,\n parentIsLocalized: parentIsLocalized || (isNamedTab && tab.localized)!,\n polymorphicJoins,\n requireFieldLevelRichTextEditor,\n richTextSanitizationPromises,\n validRelationships,\n })\n\n field.tabs[j] = tab\n }\n }\n\n if (field.type === 'ui' && typeof field.admin.disableBulkEdit === 'undefined') {\n field.admin.disableBulkEdit = true\n }\n\n fields[i] = field\n\n // Insert our field after assignment\n if (field.type === 'date' && field.timezone) {\n const name = field.name + '_tz'\n const defaultTimezone = config.admin?.timezones?.defaultTimezone\n\n const supportedTimezones = config.admin?.timezones?.supportedTimezones\n\n const options =\n typeof supportedTimezones === 'function'\n ? supportedTimezones({ defaultTimezones })\n : supportedTimezones\n\n // Need to set the options here manually so that any database enums are generated correctly\n // The UI component will import the options from the config\n const timezoneField = baseTimezoneField({\n name,\n defaultValue: defaultTimezone,\n options,\n required: field.required,\n })\n\n fields.splice(++i, 0, timezoneField)\n }\n }\n\n return fields\n}\n"],"names":["deepMergeSimple","v4","uuid","DuplicateFieldName","InvalidFieldName","InvalidFieldRelationship","MissingEditorProp","MissingFieldType","ReservedFieldName","formatLabels","toWords","baseBlockFields","baseIDField","baseTimezoneField","defaultTimezones","setDefaultBeforeDuplicate","validations","reservedAPIKeyFieldNames","reservedBaseAuthFieldNames","reservedBaseUploadFieldNames","reservedVerifyFieldNames","sanitizeJoinField","fieldAffectsData","_fieldAffectsData","fieldIsLocalized","tabHasName","sanitizeFields","collectionConfig","config","existingFieldNames","Set","fields","isTopLevelField","joinPath","joins","parentIsLocalized","polymorphicJoins","requireFieldLevelRichTextEditor","richTextSanitizationPromises","validRelationships","i","length","field","_sanitized","type","name","upload","includes","auth","disableLocalStrategy","verify","label","defaultValue","required","relationships","Array","isArray","relationTo","forEach","relationship","min","minRows","console","warn","max","maxRows","admin","isSortable","push","labels","has","add","localized","shouldDisableLocalized","localization","process","env","NEXT_PUBLIC_PAYLOAD_COMPATIBILITY_allowLocalizedWithinLocalized","PAYLOAD_DO_NOT_SANITIZE_LOCALIZED_PROPERTY","validate","defaultValidate","val","options","hooks","access","sanitizeRichText","_config","editor","isRoot","i18n","Object","keys","translations","blocks","blockReferences","Error","blockSlugs","block","blockSlug","slug","concat","j","tabs","tab","isNamedTab","condition","id","disableBulkEdit","timezone","defaultTimezone","timezones","supportedTimezones","timezoneField","splice"],"mappings":"AAAA,oBAAoB;AACpB,SAASA,eAAe,QAAQ,qCAAoC;AACpE,SAASC,MAAMC,IAAI,QAAQ,OAAM;AAUjC,SACEC,kBAAkB,EAClBC,gBAAgB,EAChBC,wBAAwB,EACxBC,iBAAiB,EACjBC,gBAAgB,QACX,wBAAuB;AAC9B,SAASC,iBAAiB,QAAQ,oCAAmC;AACrE,SAASC,YAAY,EAAEC,OAAO,QAAQ,kCAAiC;AACvE,SAASC,eAAe,QAAQ,mCAAkC;AAClE,SAASC,WAAW,QAAQ,+BAA8B;AAC1D,SAASC,iBAAiB,QAAQ,sCAAqC;AACvE,SAASC,gBAAgB,QAAQ,6CAA4C;AAC7E,SAASC,yBAAyB,QAAQ,kCAAiC;AAC3E,SAASC,WAAW,QAAQ,oBAAmB;AAC/C,SACEC,wBAAwB,EACxBC,0BAA0B,EAC1BC,4BAA4B,EAC5BC,wBAAwB,QACnB,0BAAyB;AAChC,SAASC,iBAAiB,QAAQ,yBAAwB;AAC1D,SAASC,oBAAoBC,iBAAiB,EAAEC,gBAAgB,EAAEC,UAAU,QAAQ,aAAY;AAoChG,OAAO,MAAMC,iBAAiB,OAAO,EACnCC,gBAAgB,EAChBC,MAAM,EACNC,qBAAqB,IAAIC,KAAK,EAC9BC,MAAM,EACNC,kBAAkB,IAAI,EACtBC,WAAW,EAAE,EACbC,KAAK,EACLC,iBAAiB,EACjBC,gBAAgB,EAChBC,kCAAkC,KAAK,EACvCC,4BAA4B,EAC5BC,kBAAkB,EACb;IACL,IAAI,CAACR,QAAQ;QACX,OAAO,EAAE;IACX;IAEA,IAAK,IAAIS,IAAI,GAAGA,IAAIT,OAAOU,MAAM,EAAED,IAAK;QACtC,MAAME,QAAQX,MAAM,CAACS,EAAE;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oCAAoC;QACpC,IAAIA,MAAME,IAAI,KAAK,UAAUF,MAAMkE,QAAQ,EAAE;YAC3C,MAAM/D,OAAOH,MAAMG,IAAI,GAAG;YAC1B,MAAMgE,kBAAkBjF,OAAOsC,KAAK,EAAE4C,WAAWD;YAEjD,MAAME,qBAAqBnF,OAAOsC,KAAK,EAAE4C,WAAWC;YAEpD,MAAM7B,UACJ,OAAO6B,uBAAuB,aAC1BA,mBAAmB;gBAAEjG;YAAiB,KACtCiG;YAEN,2FAA2F;YAC3F,2DAA2D;YAC3D,MAAMC,gBAAgBnG,kBAAkB;gBACtCgC;gBACAO,cAAcyD;gBACd3B;gBACA7B,UAAUX,MAAMW,QAAQ;YAC1B;YAEAtB,OAAOkF,MAAM,CAAC,EAAEzE,GAAG,GAAGwE;QACxB;IACF;IAEA,OAAOjF;AACT,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../../src/fields/config/sanitize.ts"],"sourcesContent":["import { deepMergeSimple } from '@payloadcms/translations/utilities'\nimport { v4 as uuid } from 'uuid'\n\nimport type {\n CollectionConfig,\n SanitizedJoin,\n SanitizedJoins,\n} from '../../collections/config/types.js'\nimport type { Config, SanitizedConfig } from '../../config/types.js'\nimport type { Field } from './types.js'\n\nimport {\n DuplicateFieldName,\n InvalidFieldName,\n InvalidFieldRelationship,\n MissingEditorProp,\n MissingFieldType,\n} from '../../errors/index.js'\nimport { ReservedFieldName } from '../../errors/ReservedFieldName.js'\nimport { formatLabels, toWords } from '../../utilities/formatLabels.js'\nimport { baseBlockFields } from '../baseFields/baseBlockFields.js'\nimport { baseIDField } from '../baseFields/baseIDField.js'\nimport { baseTimezoneField } from '../baseFields/timezone/baseField.js'\nimport { defaultTimezones } from '../baseFields/timezone/defaultTimezones.js'\nimport { setDefaultBeforeDuplicate } from '../setDefaultBeforeDuplicate.js'\nimport { validations } from '../validations.js'\nimport {\n reservedAPIKeyFieldNames,\n reservedBaseAuthFieldNames,\n reservedBaseUploadFieldNames,\n reservedVerifyFieldNames,\n} from './reservedFieldNames.js'\nimport { sanitizeJoinField } from './sanitizeJoinField.js'\nimport { fieldAffectsData as _fieldAffectsData, fieldIsLocalized, tabHasName } from './types.js'\n\ntype Args = {\n collectionConfig?: CollectionConfig\n config: Config\n existingFieldNames?: Set<string>\n fields: Field[]\n /**\n * Used to prevent unnecessary sanitization of fields that are not top-level.\n */\n isTopLevelField?: boolean\n joinPath?: string\n /**\n * When not passed in, assume that join are not supported (globals, arrays, blocks)\n */\n joins?: SanitizedJoins\n parentIsLocalized: boolean\n polymorphicJoins?: SanitizedJoin[]\n /**\n * If true, a richText field will require an editor property to be set, as the sanitizeFields function will not add it from the payload config if not present.\n *\n * @default false\n */\n requireFieldLevelRichTextEditor?: boolean\n /**\n * If this property is set, RichText fields won't be sanitized immediately. Instead, they will be added to this array as promises\n * so that you can sanitize them together, after the config has been sanitized.\n */\n richTextSanitizationPromises?: Array<(config: SanitizedConfig) => Promise<void>>\n /**\n * If not null, will validate that upload and relationship fields do not relate to a collection that is not in this array.\n * This validation will be skipped if validRelationships is null.\n */\n validRelationships: null | string[]\n}\n\nexport const sanitizeFields = async ({\n collectionConfig,\n config,\n existingFieldNames = new Set(),\n fields,\n isTopLevelField = true,\n joinPath = '',\n joins,\n parentIsLocalized,\n polymorphicJoins,\n requireFieldLevelRichTextEditor = false,\n richTextSanitizationPromises,\n validRelationships,\n}: Args): Promise<Field[]> => {\n if (!fields) {\n return []\n }\n\n for (let i = 0; i < fields.length; i++) {\n const field = fields[i]!\n\n if ('_sanitized' in field && field._sanitized === true) {\n continue\n }\n\n if ('_sanitized' in field) {\n field._sanitized = true\n }\n\n if (!field.type) {\n throw new MissingFieldType(field)\n }\n\n const fieldAffectsData = _fieldAffectsData(field)\n\n if (isTopLevelField && fieldAffectsData && field.name) {\n if (collectionConfig && collectionConfig.upload) {\n if (reservedBaseUploadFieldNames.includes(field.name)) {\n throw new ReservedFieldName(field, field.name)\n }\n }\n\n if (\n collectionConfig &&\n collectionConfig.auth &&\n typeof collectionConfig.auth === 'object' &&\n !collectionConfig.auth.disableLocalStrategy\n ) {\n if (reservedBaseAuthFieldNames.includes(field.name)) {\n throw new ReservedFieldName(field, field.name)\n }\n\n if (collectionConfig.auth.verify) {\n // @ts-expect-error - vestiges of when tsconfig was not strict. Feel free to improve\n if (reservedAPIKeyFieldNames.includes(field.name)) {\n throw new ReservedFieldName(field, field.name)\n }\n\n // @ts-expect-error - vestiges of when tsconfig was not strict. Feel free to improve\n if (reservedVerifyFieldNames.includes(field.name)) {\n throw new ReservedFieldName(field, field.name)\n }\n }\n }\n }\n\n // assert that field names do not contain forbidden characters\n if (fieldAffectsData && field.name.includes('.')) {\n throw new InvalidFieldName(field, field.name)\n }\n\n // Auto-label\n if (\n 'name' in field &&\n field.name &&\n typeof field.label !== 'object' &&\n typeof field.label !== 'string' &&\n typeof field.label !== 'function' &&\n field.label !== false\n ) {\n field.label = toWords(field.name)\n }\n\n if (\n field.type === 'checkbox' &&\n typeof field.defaultValue === 'undefined' &&\n field.required === true\n ) {\n field.defaultValue = false\n }\n\n if (field.type === 'join') {\n sanitizeJoinField({ config, field, joinPath, joins, parentIsLocalized, polymorphicJoins })\n }\n\n if (field.type === 'relationship' || field.type === 'upload') {\n if (validRelationships) {\n const relationships = Array.isArray(field.relationTo)\n ? field.relationTo\n : [field.relationTo]\n\n relationships.forEach((relationship: string) => {\n if (!validRelationships.includes(relationship)) {\n throw new InvalidFieldRelationship(field, relationship)\n }\n })\n }\n\n if (field.min && !field.minRows) {\n console.warn(\n `(payload): The \"min\" property is deprecated for the Relationship field \"${field.name}\" and will be removed in a future version. Please use \"minRows\" instead.`,\n )\n field.minRows = field.min\n }\n\n if (field.max && !field.maxRows) {\n console.warn(\n `(payload): The \"max\" property is deprecated for the Relationship field \"${field.name}\" and will be removed in a future version. Please use \"maxRows\" instead.`,\n )\n field.maxRows = field.max\n }\n }\n\n if (field.type === 'upload') {\n if (!field.admin || !('isSortable' in field.admin)) {\n field.admin = {\n isSortable: true,\n ...field.admin,\n }\n }\n }\n\n if (field.type === 'array' && field.fields) {\n field.fields.push(baseIDField)\n }\n\n if ((field.type === 'blocks' || field.type === 'array') && field.label) {\n field.labels = field.labels || formatLabels(field.name)\n }\n\n if (fieldAffectsData) {\n if (existingFieldNames.has(field.name)) {\n throw new DuplicateFieldName(field.name)\n } else if (!['blockName', 'id'].includes(field.name)) {\n existingFieldNames.add(field.name)\n }\n\n if (typeof field.localized !== 'undefined') {\n let shouldDisableLocalized = !config.localization\n\n if (\n process.env.NEXT_PUBLIC_PAYLOAD_COMPATIBILITY_allowLocalizedWithinLocalized !== 'true' &&\n parentIsLocalized &&\n // @todo PAYLOAD_DO_NOT_SANITIZE_LOCALIZED_PROPERTY=true will be the default in 4.0\n process.env.PAYLOAD_DO_NOT_SANITIZE_LOCALIZED_PROPERTY !== 'true'\n ) {\n shouldDisableLocalized = true\n }\n\n if (shouldDisableLocalized) {\n delete field.localized\n }\n }\n\n if (typeof field.validate === 'undefined') {\n const defaultValidate = validations[field.type as keyof typeof validations]\n if (defaultValidate) {\n field.validate = (val: any, options: any) =>\n defaultValidate(val, { ...field, ...options })\n } else {\n field.validate = (): true => true\n }\n }\n\n if (!field.hooks) {\n field.hooks = {}\n }\n\n if (!field.access) {\n field.access = {}\n }\n\n setDefaultBeforeDuplicate(field, parentIsLocalized)\n }\n\n if (!field.admin) {\n field.admin = {}\n }\n\n // Make sure that the richText field has an editor\n if (field.type === 'richText') {\n const sanitizeRichText = async (_config: SanitizedConfig) => {\n if (!field.editor) {\n if (_config.editor && !requireFieldLevelRichTextEditor) {\n // config.editor should be sanitized at this point\n field.editor = _config.editor\n } else {\n throw new MissingEditorProp(field) // while we allow disabling editor functionality, you should not have any richText fields defined if you do not have an editor\n }\n }\n\n if (typeof field.editor === 'function') {\n field.editor = await field.editor({\n config: _config,\n isRoot: requireFieldLevelRichTextEditor,\n parentIsLocalized: (parentIsLocalized || field.localized)!,\n })\n }\n\n if (field.editor.i18n && Object.keys(field.editor.i18n).length >= 0) {\n config.i18n!.translations = deepMergeSimple(config.i18n!.translations!, field.editor.i18n)\n }\n }\n if (richTextSanitizationPromises) {\n richTextSanitizationPromises.push(sanitizeRichText)\n } else {\n await sanitizeRichText(config as unknown as SanitizedConfig)\n }\n }\n\n if (field.type === 'blocks' && field.blocks) {\n if (field.blockReferences && field.blocks?.length) {\n throw new Error('You cannot have both blockReferences and blocks in the same blocks field')\n }\n\n const blockSlugs: string[] = []\n\n for (const block of field.blockReferences ?? field.blocks) {\n const blockSlug = typeof block === 'string' ? block : block.slug\n\n if (blockSlugs.includes(blockSlug)) {\n throw new DuplicateFieldName(blockSlug)\n }\n\n blockSlugs.push(blockSlug)\n\n if (typeof block === 'string') {\n continue\n }\n\n if (block._sanitized === true) {\n continue\n }\n\n block._sanitized = true\n block.fields = block.fields.concat(baseBlockFields)\n block.labels = !block.labels ? formatLabels(block.slug) : block.labels\n block.fields = await sanitizeFields({\n collectionConfig,\n config,\n existingFieldNames: new Set(),\n fields: block.fields,\n isTopLevelField: false,\n parentIsLocalized: (parentIsLocalized || field.localized)!,\n requireFieldLevelRichTextEditor,\n richTextSanitizationPromises,\n validRelationships,\n })\n }\n }\n\n if ('fields' in field && field.fields) {\n field.fields = await sanitizeFields({\n collectionConfig,\n config,\n existingFieldNames: fieldAffectsData ? new Set() : existingFieldNames,\n fields: field.fields,\n isTopLevelField: isTopLevelField && !fieldAffectsData,\n joinPath: fieldAffectsData ? `${joinPath ? joinPath + '.' : ''}${field.name}` : joinPath,\n joins,\n parentIsLocalized: parentIsLocalized || fieldIsLocalized(field),\n polymorphicJoins,\n requireFieldLevelRichTextEditor,\n richTextSanitizationPromises,\n validRelationships,\n })\n }\n\n if (field.type === 'tabs') {\n for (let j = 0; j < field.tabs.length; j++) {\n const tab = field.tabs[j]!\n\n const isNamedTab = tabHasName(tab)\n\n if (isNamedTab && typeof tab.label === 'undefined') {\n tab.label = toWords(tab.name)\n }\n\n if (\n 'admin' in tab &&\n tab.admin?.condition &&\n typeof tab.admin.condition === 'function' &&\n !tab.id\n ) {\n // Always attach a UUID to tabs with a condition so there's no conflicts even if there are duplicate nested names\n tab.id = isNamedTab ? `${tab.name}_${uuid()}` : uuid()\n }\n\n tab.fields = await sanitizeFields({\n collectionConfig,\n config,\n existingFieldNames: isNamedTab ? new Set() : existingFieldNames,\n fields: tab.fields,\n isTopLevelField: isTopLevelField && !isNamedTab,\n joinPath: isNamedTab ? `${joinPath ? joinPath + '.' : ''}${tab.name}` : joinPath,\n joins,\n parentIsLocalized: parentIsLocalized || (isNamedTab && tab.localized)!,\n polymorphicJoins,\n requireFieldLevelRichTextEditor,\n richTextSanitizationPromises,\n validRelationships,\n })\n\n field.tabs[j] = tab\n }\n }\n\n if (field.type === 'ui' && typeof field.admin.disableBulkEdit === 'undefined') {\n field.admin.disableBulkEdit = true\n }\n\n fields[i] = field\n\n // Insert our field after assignment\n if (field.type === 'date' && field.timezone) {\n const name = field.name + '_tz'\n const defaultTimezone = config.admin?.timezones?.defaultTimezone\n\n const supportedTimezones = config.admin?.timezones?.supportedTimezones\n\n const options =\n typeof supportedTimezones === 'function'\n ? supportedTimezones({ defaultTimezones })\n : supportedTimezones\n\n // Need to set the options here manually so that any database enums are generated correctly\n // The UI component will import the options from the config\n const timezoneField = baseTimezoneField({\n name,\n defaultValue: defaultTimezone,\n options,\n required: field.required,\n })\n\n fields.splice(++i, 0, timezoneField)\n }\n }\n\n return fields\n}\n"],"names":["deepMergeSimple","v4","uuid","DuplicateFieldName","InvalidFieldName","InvalidFieldRelationship","MissingEditorProp","MissingFieldType","ReservedFieldName","formatLabels","toWords","baseBlockFields","baseIDField","baseTimezoneField","defaultTimezones","setDefaultBeforeDuplicate","validations","reservedAPIKeyFieldNames","reservedBaseAuthFieldNames","reservedBaseUploadFieldNames","reservedVerifyFieldNames","sanitizeJoinField","fieldAffectsData","_fieldAffectsData","fieldIsLocalized","tabHasName","sanitizeFields","collectionConfig","config","existingFieldNames","Set","fields","isTopLevelField","joinPath","joins","parentIsLocalized","polymorphicJoins","requireFieldLevelRichTextEditor","richTextSanitizationPromises","validRelationships","i","length","field","_sanitized","type","name","upload","includes","auth","disableLocalStrategy","verify","label","defaultValue","required","relationships","Array","isArray","relationTo","forEach","relationship","min","minRows","console","warn","max","maxRows","admin","isSortable","push","labels","has","add","localized","shouldDisableLocalized","localization","process","env","NEXT_PUBLIC_PAYLOAD_COMPATIBILITY_allowLocalizedWithinLocalized","PAYLOAD_DO_NOT_SANITIZE_LOCALIZED_PROPERTY","validate","defaultValidate","val","options","hooks","access","sanitizeRichText","_config","editor","isRoot","i18n","Object","keys","translations","blocks","blockReferences","Error","blockSlugs","block","blockSlug","slug","concat","j","tabs","tab","isNamedTab","condition","id","disableBulkEdit","timezone","defaultTimezone","timezones","supportedTimezones","timezoneField","splice"],"mappings":"AAAA,SAASA,eAAe,QAAQ,qCAAoC;AACpE,SAASC,MAAMC,IAAI,QAAQ,OAAM;AAUjC,SACEC,kBAAkB,EAClBC,gBAAgB,EAChBC,wBAAwB,EACxBC,iBAAiB,EACjBC,gBAAgB,QACX,wBAAuB;AAC9B,SAASC,iBAAiB,QAAQ,oCAAmC;AACrE,SAASC,YAAY,EAAEC,OAAO,QAAQ,kCAAiC;AACvE,SAASC,eAAe,QAAQ,mCAAkC;AAClE,SAASC,WAAW,QAAQ,+BAA8B;AAC1D,SAASC,iBAAiB,QAAQ,sCAAqC;AACvE,SAASC,gBAAgB,QAAQ,6CAA4C;AAC7E,SAASC,yBAAyB,QAAQ,kCAAiC;AAC3E,SAASC,WAAW,QAAQ,oBAAmB;AAC/C,SACEC,wBAAwB,EACxBC,0BAA0B,EAC1BC,4BAA4B,EAC5BC,wBAAwB,QACnB,0BAAyB;AAChC,SAASC,iBAAiB,QAAQ,yBAAwB;AAC1D,SAASC,oBAAoBC,iBAAiB,EAAEC,gBAAgB,EAAEC,UAAU,QAAQ,aAAY;AAoChG,OAAO,MAAMC,iBAAiB,OAAO,EACnCC,gBAAgB,EAChBC,MAAM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,GAAGZ;oBACxEC;oBACAC,mBAAmBA,qBAAsBqE,cAAcD,IAAI/B,SAAS;oBACpEpC;oBACAC;oBACAC;oBACAC;gBACF;gBAEAG,MAAM4D,IAAI,CAACD,EAAE,GAAGE;YAClB;QACF;QAEA,IAAI7D,MAAME,IAAI,KAAK,QAAQ,OAAOF,MAAMwB,KAAK,CAACyC,eAAe,KAAK,aAAa;YAC7EjE,MAAMwB,KAAK,CAACyC,eAAe,GAAG;QAChC;QAEA5E,MAAM,CAACS,EAAE,GAAGE;QAEZ,oCAAoC;QACpC,IAAIA,MAAME,IAAI,KAAK,UAAUF,MAAMkE,QAAQ,EAAE;YAC3C,MAAM/D,OAAOH,MAAMG,IAAI,GAAG;YAC1B,MAAMgE,kBAAkBjF,OAAOsC,KAAK,EAAE4C,WAAWD;YAEjD,MAAME,qBAAqBnF,OAAOsC,KAAK,EAAE4C,WAAWC;YAEpD,MAAM7B,UACJ,OAAO6B,uBAAuB,aAC1BA,mBAAmB;gBAAEjG;YAAiB,KACtCiG;YAEN,2FAA2F;YAC3F,2DAA2D;YAC3D,MAAMC,gBAAgBnG,kBAAkB;gBACtCgC;gBACAO,cAAcyD;gBACd3B;gBACA7B,UAAUX,MAAMW,QAAQ;YAC1B;YAEAtB,OAAOkF,MAAM,CAAC,EAAEzE,GAAG,GAAGwE;QACxB;IACF;IAEA,OAAOjF;AACT,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/fields/hooks/afterRead/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/fields/hooks/afterRead/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,sCAAsC,CAAA;AACrF,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAA;AAC7E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AACvD,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;AAKnG,KAAK,IAAI,CAAC,CAAC,SAAS,UAAU,IAAI;IAChC,UAAU,EAAE,IAAI,GAAG,yBAAyB,CAAA;IAC5C,OAAO,EAAE,cAAc,CAAA;IACvB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,KAAK,EAAE,MAAM,CAAA;IACb,GAAG,EAAE,CAAC,CAAA;IACN,KAAK,EAAE,OAAO,CAAA;IACd,cAAc,EAAE,IAAI,GAAG,MAAM,CAAA;IAC7B,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,MAAM,EAAE,IAAI,GAAG,qBAAqB,CAAA;IACpC,MAAM,EAAE,MAAM,CAAA;IACd,cAAc,EAAE,OAAO,CAAA;IACvB,QAAQ,CAAC,EAAE,YAAY,CAAA;IACvB,GAAG,EAAE,cAAc,CAAA;IACnB,MAAM,CAAC,EAAE,UAAU,CAAA;IACnB,gBAAgB,EAAE,OAAO,CAAA;CAC1B,CAAA;AAED;;;;;;;;GAQG;AAEH,wBAAsB,SAAS,CAAC,CAAC,SAAS,UAAU,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAmF/E"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/fields/hooks/afterRead/index.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"sources":["../../../../src/fields/hooks/afterRead/index.ts"],"sourcesContent":["import type { SanitizedCollectionConfig } from '../../../collections/config/types.js'\nimport type { SanitizedGlobalConfig } from '../../../globals/config/types.js'\nimport type { RequestContext } from '../../../index.js'\nimport type { JsonObject, PayloadRequest, PopulateType, SelectType } from '../../../types/index.js'\n\nimport { getSelectMode } from '../../../utilities/getSelectMode.js'\nimport { traverseFields } from './traverseFields.js'\n\ntype Args<T extends JsonObject> = {\n collection: null | SanitizedCollectionConfig\n context: RequestContext\n currentDepth?: number\n depth: number\n doc: T\n draft: boolean\n fallbackLocale: null | string\n findMany?: boolean\n flattenLocales?: boolean\n global: null | SanitizedGlobalConfig\n locale: string\n overrideAccess: boolean\n populate?: PopulateType\n req: PayloadRequest\n select?: SelectType\n showHiddenFields: boolean\n}\n\n/**\n * This function is responsible for the following actions, in order:\n * - Remove hidden fields from response\n * - Flatten locales into requested locale. If the input doc contains all locales, the output doc after this function will only contain the requested locale.\n * - Sanitize outgoing data (point field, etc.)\n * - Execute field hooks\n * - Execute read access control\n * - Populate relationships\n */\n\nexport async function afterRead<T extends JsonObject>(args: Args<T>): Promise<T> {\n const {\n collection,\n context,\n currentDepth: incomingCurrentDepth,\n depth: incomingDepth,\n doc: incomingDoc,\n draft,\n fallbackLocale,\n findMany,\n flattenLocales = true,\n global,\n locale,\n overrideAccess,\n populate,\n req,\n select,\n showHiddenFields,\n } = args\n\n const fieldPromises: Promise<void>[] = []\n const populationPromises: Promise<void>[] = []\n\n let depth =\n incomingDepth || incomingDepth === 0\n ? parseInt(String(incomingDepth), 10)\n : req.payload.config.defaultDepth\n if (depth > req.payload.config.maxDepth) {\n depth = req.payload.config.maxDepth\n }\n\n const currentDepth = incomingCurrentDepth || 1\n\n traverseFields({\n collection,\n context,\n currentDepth,\n depth,\n doc: incomingDoc,\n draft,\n fallbackLocale,\n fieldPromises,\n fields: (collection?.fields || global?.fields)!,\n findMany: findMany!,\n flattenLocales,\n global,\n locale,\n overrideAccess,\n parentIndexPath: '',\n parentIsLocalized: false,\n parentPath: '',\n parentSchemaPath: '',\n populate,\n populationPromises,\n req,\n select,\n selectMode: select ? getSelectMode(select) : undefined,\n showHiddenFields,\n siblingDoc: incomingDoc,\n })\n\n /**\n * Await all field and population promises in parallel.\n * A field promise is able to add more field promises to the fieldPromises array, which will not be\n * awaited in the first run.\n * This is why we need to loop again to process the new field promises, until there are no more field promises left.\n */\n let iterations = 0\n while (fieldPromises.length > 0 || populationPromises.length > 0) {\n const currentFieldPromises = fieldPromises.splice(0, fieldPromises.length)\n const currentPopulationPromises = populationPromises.splice(0, populationPromises.length)\n\n await Promise.all(currentFieldPromises)\n await Promise.all(currentPopulationPromises)\n\n iterations++\n if (iterations >= 100) {\n throw new Error(\n 'Infinite afterRead promise loop detected. A hook is likely adding field promises in an infinitely recursive way.',\n )\n }\n }\n return incomingDoc\n}\n"],"names":["getSelectMode","traverseFields","afterRead","args","collection","context","currentDepth","incomingCurrentDepth","depth","incomingDepth","doc","incomingDoc","draft","fallbackLocale","findMany","flattenLocales","global","locale","overrideAccess","populate","req","select","showHiddenFields","fieldPromises","populationPromises","parseInt","String","payload","config","defaultDepth","maxDepth","fields","parentIndexPath","parentIsLocalized","parentPath","parentSchemaPath","selectMode","undefined","siblingDoc","iterations","length","currentFieldPromises","splice","currentPopulationPromises","Promise","all","Error"],"mappings":"AAKA,SAASA,aAAa,QAAQ,sCAAqC;AACnE,SAASC,cAAc,QAAQ,sBAAqB;AAqBpD;;;;;;;;CAQC,GAED,OAAO,eAAeC,UAAgCC,IAAa;IACjE,MAAM,EACJC,UAAU,EACVC,OAAO,EACPC,cAAcC,oBAAoB,EAClCC,OAAOC,aAAa,EACpBC,KAAKC,WAAW,EAChBC,KAAK,EACLC,cAAc,EACdC,QAAQ,EACRC,iBAAiB,IAAI,EACrBC,MAAM,EACNC,MAAM,EACNC,cAAc,EACdC,QAAQ,EACRC,GAAG,EACHC,MAAM,EACNC,gBAAgB,EACjB,GAAGnB;IAEJ,MAAMoB,gBAAiC,EAAE;IACzC,MAAMC,qBAAsC,EAAE;IAE9C,IAAIhB,QACFC,iBAAiBA,kBAAkB,IAC/BgB,SAASC,OAAOjB,gBAAgB,MAChCW,IAAIO,OAAO,CAACC,MAAM,CAACC,YAAY;IACrC,IAAIrB,QAAQY,IAAIO,OAAO,CAACC,MAAM,CAACE,QAAQ,EAAE;QACvCtB,QAAQY,IAAIO,OAAO,CAACC,MAAM,CAACE,QAAQ;IACrC;IAEA,MAAMxB,eAAeC,wBAAwB;IAE7CN,eAAe;QACbG;QACAC;QACAC;QACAE;QACAE,KAAKC;QACLC;QACAC;QACAU;QACAQ,QAAS3B,YAAY2B,UAAUf,QAAQe;QACvCjB,UAAUA;QACVC;QACAC;QACAC;QACAC;QACAc,iBAAiB;QACjBC,mBAAmB;QACnBC,YAAY;QACZC,kBAAkB;QAClBhB;QACAK;QACAJ;QACAC;QACAe,YAAYf,SAASrB,cAAcqB,UAAUgB;QAC7Cf;QACAgB,YAAY3B;IACd;IAEA;;;;;GAKC,GACD,IAAI4B,aAAa;IACjB,MAAOhB,cAAciB,MAAM,GAAG,KAAKhB,mBAAmBgB,MAAM,GAAG,EAAG;QAChE,MAAMC,uBAAuBlB,cAAcmB,MAAM,CAAC,GAAGnB,cAAciB,MAAM;QACzE,MAAMG,4BAA4BnB,mBAAmBkB,MAAM,CAAC,GAAGlB,mBAAmBgB,MAAM;QAExF,MAAMI,QAAQC,GAAG,CAACJ;QAClB,MAAMG,QAAQC,GAAG,CAACF;QAElBJ;QACA,IAAIA,cAAc,KAAK;YACrB,MAAM,IAAIO,MACR;QAEJ;IACF;IACA,OAAOnC;AACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"relationshipPopulationPromise.d.ts","sourceRoot":"","sources":["../../../../src/fields/hooks/afterRead/relationshipPopulationPromise.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"relationshipPopulationPromise.d.ts","sourceRoot":"","sources":["../../../../src/fields/hooks/afterRead/relationshipPopulationPromise.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAA;AAC3E,OAAO,KAAK,EAAE,SAAS,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAoItF,KAAK,WAAW,GAAG;IACjB,YAAY,EAAE,MAAM,CAAA;IACpB,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,EAAE,OAAO,CAAA;IACd,cAAc,EAAE,IAAI,GAAG,MAAM,CAAA;IAC7B,KAAK,EAAE,SAAS,GAAG,iBAAiB,GAAG,WAAW,CAAA;IAClD,MAAM,EAAE,IAAI,GAAG,MAAM,CAAA;IACrB,cAAc,EAAE,OAAO,CAAA;IACvB,iBAAiB,EAAE,OAAO,CAAA;IAC1B,QAAQ,CAAC,EAAE,YAAY,CAAA;IACvB,GAAG,EAAE,cAAc,CAAA;IACnB,gBAAgB,EAAE,OAAO,CAAA;IACzB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;CAChC,CAAA;AAED,eAAO,MAAM,6BAA6B,gKAavC,WAAW,KAAG,OAAO,CAAC,IAAI,CAoH5B,CAAA"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// @ts-strict-ignore
|
|
2
1
|
import { createDataloaderCacheKey } from '../../../collections/dataloader.js';
|
|
3
2
|
import { fieldHasMaxDepth, fieldShouldBeLocalized, fieldSupportsMany } from '../../config/types.js';
|
|
4
3
|
// TODO: this function is mess, refactor logic
|
|
@@ -89,7 +88,7 @@ export const relationshipPopulationPromise = async ({ currentDepth, depth, draft
|
|
|
89
88
|
}) && locale === 'all' && typeof siblingDoc[field.name] === 'object' && siblingDoc[field.name] !== null) {
|
|
90
89
|
Object.keys(siblingDoc[field.name]).forEach((localeKey)=>{
|
|
91
90
|
if (Array.isArray(siblingDoc[field.name][localeKey])) {
|
|
92
|
-
siblingDoc[field.name][localeKey].forEach((
|
|
91
|
+
siblingDoc[field.name][localeKey].forEach((_relatedDoc, index)=>{
|
|
93
92
|
const rowPromise = async ()=>{
|
|
94
93
|
await populate({
|
|
95
94
|
currentDepth,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/fields/hooks/afterRead/relationshipPopulationPromise.ts"],"sourcesContent":["// @ts-strict-ignore\nimport type { PayloadRequest, PopulateType } from '../../../types/index.js'\nimport type { JoinField, RelationshipField, UploadField } from '../../config/types.js'\n\nimport { createDataloaderCacheKey } from '../../../collections/dataloader.js'\nimport { fieldHasMaxDepth, fieldShouldBeLocalized, fieldSupportsMany } from '../../config/types.js'\n\ntype PopulateArgs = {\n currentDepth: number\n data: Record<string, unknown>\n dataReference: Record<string, any>\n depth: number\n draft: boolean\n fallbackLocale: null | string\n field: JoinField | RelationshipField | UploadField\n index?: number\n key?: string\n locale: null | string\n overrideAccess: boolean\n populateArg?: PopulateType\n req: PayloadRequest\n showHiddenFields: boolean\n}\n\n// TODO: this function is mess, refactor logic\nconst populate = async ({\n currentDepth,\n data,\n dataReference,\n depth,\n draft,\n fallbackLocale,\n field,\n index,\n key,\n locale,\n overrideAccess,\n populateArg,\n req,\n showHiddenFields,\n}: PopulateArgs) => {\n const dataToUpdate = dataReference\n let relation\n if (field.type === 'join') {\n relation = Array.isArray(field.collection) ? data.relationTo : field.collection\n } else {\n relation = Array.isArray(field.relationTo) ? (data.relationTo as string) : field.relationTo\n }\n\n const relatedCollection = req.payload.collections[relation]\n\n if (relatedCollection) {\n let id: unknown\n\n if (field.type === 'join' && Array.isArray(field.collection)) {\n id = data.value\n } else if (field.type !== 'join' && Array.isArray(field.relationTo)) {\n id = data.value\n } else {\n id = data\n }\n\n let relationshipValue\n const shouldPopulate = depth && currentDepth <= depth\n\n if (\n typeof id !== 'string' &&\n typeof id !== 'number' &&\n typeof id?.toString === 'function' &&\n typeof id !== 'object'\n ) {\n id = id.toString()\n }\n\n if (shouldPopulate) {\n relationshipValue = await req.payloadDataLoader.load(\n createDataloaderCacheKey({\n collectionSlug: relatedCollection.config.slug,\n currentDepth: currentDepth + 1,\n depth,\n docID: id as string,\n draft,\n fallbackLocale: fallbackLocale!,\n locale: locale!,\n overrideAccess,\n populate: populateArg,\n select:\n populateArg?.[relatedCollection.config.slug] ??\n relatedCollection.config.defaultPopulate,\n showHiddenFields,\n transactionID: req.transactionID!,\n }),\n )\n }\n\n if (!relationshipValue) {\n // ids are visible regardless of access controls\n relationshipValue = id\n }\n if (typeof index === 'number' && typeof key === 'string') {\n if (field.type !== 'join' && Array.isArray(field.relationTo)) {\n dataToUpdate[field.name][key][index].value = relationshipValue\n } else {\n if (field.type === 'join' && Array.isArray(field.collection)) {\n dataToUpdate[field.name][key][index].value = relationshipValue\n } else {\n dataToUpdate[field.name][key][index] = relationshipValue\n }\n }\n } else if (typeof index === 'number' || typeof key === 'string') {\n if (field.type === 'join') {\n if (!Array.isArray(field.collection)) {\n dataToUpdate[field.name].docs[index ?? key!] = relationshipValue\n } else {\n dataToUpdate[field.name].docs[index ?? key!].value = relationshipValue\n }\n } else if (Array.isArray(field.relationTo)) {\n dataToUpdate[field.name][index ?? key!].value = relationshipValue\n } else {\n dataToUpdate[field.name][index ?? key!] = relationshipValue\n }\n } else if (field.type !== 'join' && Array.isArray(field.relationTo)) {\n dataToUpdate[field.name].value = relationshipValue\n } else {\n if (field.type === 'join' && Array.isArray(field.collection)) {\n dataToUpdate[field.name].value = relationshipValue\n } else {\n dataToUpdate[field.name] = relationshipValue\n }\n }\n }\n}\n\ntype PromiseArgs = {\n currentDepth: number\n depth: number\n draft: boolean\n fallbackLocale: null | string\n field: JoinField | RelationshipField | UploadField\n locale: null | string\n overrideAccess: boolean\n parentIsLocalized: boolean\n populate?: PopulateType\n req: PayloadRequest\n showHiddenFields: boolean\n siblingDoc: Record<string, any>\n}\n\nexport const relationshipPopulationPromise = async ({\n currentDepth,\n depth,\n draft,\n fallbackLocale,\n field,\n locale,\n overrideAccess,\n parentIsLocalized,\n populate: populateArg,\n req,\n showHiddenFields,\n siblingDoc,\n}: PromiseArgs): Promise<void> => {\n const resultingDoc = siblingDoc\n const populateDepth = fieldHasMaxDepth(field) && field.maxDepth! < depth ? field.maxDepth : depth\n const rowPromises: Promise<void>[] = []\n\n if (field.type === 'join' || (fieldSupportsMany(field) && field.hasMany)) {\n if (\n fieldShouldBeLocalized({ field, parentIsLocalized }) &&\n locale === 'all' &&\n typeof siblingDoc[field.name] === 'object' &&\n siblingDoc[field.name] !== null\n ) {\n Object.keys(siblingDoc[field.name]).forEach((localeKey) => {\n if (Array.isArray(siblingDoc[field.name][localeKey])) {\n siblingDoc[field.name][localeKey].forEach((relatedDoc, index) => {\n const rowPromise = async () => {\n await populate({\n currentDepth,\n data: siblingDoc[field.name][localeKey][index],\n dataReference: resultingDoc,\n depth: populateDepth!,\n draft,\n fallbackLocale,\n field,\n index,\n key: localeKey,\n locale,\n overrideAccess,\n populateArg,\n req,\n showHiddenFields,\n })\n }\n rowPromises.push(rowPromise())\n })\n }\n })\n } else if (\n Array.isArray(siblingDoc[field.name]) ||\n Array.isArray(siblingDoc[field.name]?.docs)\n ) {\n ;(Array.isArray(siblingDoc[field.name])\n ? siblingDoc[field.name]\n : siblingDoc[field.name].docs\n ).forEach((relatedDoc, index) => {\n const rowPromise = async () => {\n if (relatedDoc) {\n await populate({\n currentDepth,\n data:\n !(field.type === 'join' && Array.isArray(field.collection)) && relatedDoc?.id\n ? relatedDoc.id\n : relatedDoc,\n dataReference: resultingDoc,\n depth: populateDepth!,\n draft,\n fallbackLocale,\n field,\n index,\n locale,\n overrideAccess,\n populateArg,\n req,\n showHiddenFields,\n })\n }\n }\n\n rowPromises.push(rowPromise())\n })\n }\n } else if (\n field.localized &&\n locale === 'all' &&\n typeof siblingDoc[field.name] === 'object' &&\n siblingDoc[field.name] !== null\n ) {\n Object.keys(siblingDoc[field.name]).forEach((localeKey) => {\n const rowPromise = async () => {\n await populate({\n currentDepth,\n data: siblingDoc[field.name][localeKey],\n dataReference: resultingDoc,\n depth: populateDepth!,\n draft,\n fallbackLocale,\n field,\n key: localeKey,\n locale,\n overrideAccess,\n populateArg,\n req,\n showHiddenFields,\n })\n }\n rowPromises.push(rowPromise())\n })\n\n await Promise.all(rowPromises)\n } else if (siblingDoc[field.name]) {\n await populate({\n currentDepth,\n data: siblingDoc[field.name],\n dataReference: resultingDoc,\n depth: populateDepth!,\n draft,\n fallbackLocale,\n field,\n locale,\n overrideAccess,\n populateArg,\n req,\n showHiddenFields,\n })\n }\n await Promise.all(rowPromises)\n}\n"],"names":["createDataloaderCacheKey","fieldHasMaxDepth","fieldShouldBeLocalized","fieldSupportsMany","populate","currentDepth","data","dataReference","depth","draft","fallbackLocale","field","index","key","locale","overrideAccess","populateArg","req","showHiddenFields","dataToUpdate","relation","type","Array","isArray","collection","relationTo","relatedCollection","payload","collections","id","value","relationshipValue","shouldPopulate","toString","payloadDataLoader","load","collectionSlug","config","slug","docID","select","defaultPopulate","transactionID","name","docs","relationshipPopulationPromise","parentIsLocalized","siblingDoc","resultingDoc","populateDepth","maxDepth","rowPromises","hasMany","Object","keys","forEach","localeKey","relatedDoc","rowPromise","push","localized","Promise","all"],"mappings":"AAAA,oBAAoB;AAIpB,SAASA,wBAAwB,QAAQ,qCAAoC;AAC7E,SAASC,gBAAgB,EAAEC,sBAAsB,EAAEC,iBAAiB,QAAQ,wBAAuB;AAmBnG,8CAA8C;AAC9C,MAAMC,WAAW,OAAO,EACtBC,YAAY,EACZC,IAAI,EACJC,aAAa,EACbC,KAAK,EACLC,KAAK,EACLC,cAAc,EACdC,KAAK,EACLC,KAAK,EACLC,GAAG,EACHC,MAAM,EACNC,cAAc,EACdC,WAAW,EACXC,GAAG,EACHC,gBAAgB,EACH;IACb,MAAMC,eAAeZ;IACrB,IAAIa;IACJ,IAAIT,MAAMU,IAAI,KAAK,QAAQ;QACzBD,WAAWE,MAAMC,OAAO,CAACZ,MAAMa,UAAU,IAAIlB,KAAKmB,UAAU,GAAGd,MAAMa,UAAU;IACjF,OAAO;QACLJ,WAAWE,MAAMC,OAAO,CAACZ,MAAMc,UAAU,IAAKnB,KAAKmB,UAAU,GAAcd,MAAMc,UAAU;IAC7F;IAEA,MAAMC,oBAAoBT,IAAIU,OAAO,CAACC,WAAW,CAACR,SAAS;IAE3D,IAAIM,mBAAmB;QACrB,IAAIG;QAEJ,IAAIlB,MAAMU,IAAI,KAAK,UA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YACAC;YACAG;YACAC;YACAC;YACAC;YACAC;QACF;IACF;IACA,MAAM2C,QAAQC,GAAG,CAACX;AACpB,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../../../src/fields/hooks/afterRead/relationshipPopulationPromise.ts"],"sourcesContent":["import type { PayloadRequest, PopulateType } from '../../../types/index.js'\nimport type { JoinField, RelationshipField, UploadField } from '../../config/types.js'\n\nimport { createDataloaderCacheKey } from '../../../collections/dataloader.js'\nimport { fieldHasMaxDepth, fieldShouldBeLocalized, fieldSupportsMany } from '../../config/types.js'\n\ntype PopulateArgs = {\n currentDepth: number\n data: Record<string, unknown>\n dataReference: Record<string, any>\n depth: number\n draft: boolean\n fallbackLocale: null | string\n field: JoinField | RelationshipField | UploadField\n index?: number\n key?: string\n locale: null | string\n overrideAccess: boolean\n populateArg?: PopulateType\n req: PayloadRequest\n showHiddenFields: boolean\n}\n\n// TODO: this function is mess, refactor logic\nconst populate = async ({\n currentDepth,\n data,\n dataReference,\n depth,\n draft,\n fallbackLocale,\n field,\n index,\n key,\n locale,\n overrideAccess,\n populateArg,\n req,\n showHiddenFields,\n}: PopulateArgs) => {\n const dataToUpdate = dataReference\n let relation\n if (field.type === 'join') {\n relation = Array.isArray(field.collection) ? data.relationTo : field.collection\n } else {\n relation = Array.isArray(field.relationTo) ? (data.relationTo as string) : field.relationTo\n }\n\n const relatedCollection =\n req.payload.collections[relation as keyof typeof req.payload.collections]\n\n if (relatedCollection) {\n let id: unknown\n\n if (field.type === 'join' && Array.isArray(field.collection)) {\n id = data.value\n } else if (field.type !== 'join' && Array.isArray(field.relationTo)) {\n id = data.value\n } else {\n id = data\n }\n\n let relationshipValue\n const shouldPopulate = depth && currentDepth <= depth\n\n if (\n typeof id !== 'string' &&\n typeof id !== 'number' &&\n typeof id?.toString === 'function' &&\n typeof id !== 'object'\n ) {\n id = id.toString()\n }\n\n if (shouldPopulate) {\n relationshipValue = await req.payloadDataLoader.load(\n createDataloaderCacheKey({\n collectionSlug: relatedCollection.config.slug,\n currentDepth: currentDepth + 1,\n depth,\n docID: id as string,\n draft,\n fallbackLocale: fallbackLocale!,\n locale: locale!,\n overrideAccess,\n populate: populateArg,\n select:\n populateArg?.[relatedCollection.config.slug] ??\n relatedCollection.config.defaultPopulate,\n showHiddenFields,\n transactionID: req.transactionID!,\n }),\n )\n }\n\n if (!relationshipValue) {\n // ids are visible regardless of access controls\n relationshipValue = id\n }\n if (typeof index === 'number' && typeof key === 'string') {\n if (field.type !== 'join' && Array.isArray(field.relationTo)) {\n dataToUpdate[field.name][key][index].value = relationshipValue\n } else {\n if (field.type === 'join' && Array.isArray(field.collection)) {\n dataToUpdate[field.name][key][index].value = relationshipValue\n } else {\n dataToUpdate[field.name][key][index] = relationshipValue\n }\n }\n } else if (typeof index === 'number' || typeof key === 'string') {\n if (field.type === 'join') {\n if (!Array.isArray(field.collection)) {\n dataToUpdate[field.name].docs[index ?? key!] = relationshipValue\n } else {\n dataToUpdate[field.name].docs[index ?? key!].value = relationshipValue\n }\n } else if (Array.isArray(field.relationTo)) {\n dataToUpdate[field.name][index ?? key!].value = relationshipValue\n } else {\n dataToUpdate[field.name][index ?? key!] = relationshipValue\n }\n } else if (field.type !== 'join' && Array.isArray(field.relationTo)) {\n dataToUpdate[field.name].value = relationshipValue\n } else {\n if (field.type === 'join' && Array.isArray(field.collection)) {\n dataToUpdate[field.name].value = relationshipValue\n } else {\n dataToUpdate[field.name] = relationshipValue\n }\n }\n }\n}\n\ntype PromiseArgs = {\n currentDepth: number\n depth: number\n draft: boolean\n fallbackLocale: null | string\n field: JoinField | RelationshipField | UploadField\n locale: null | string\n overrideAccess: boolean\n parentIsLocalized: boolean\n populate?: PopulateType\n req: PayloadRequest\n showHiddenFields: boolean\n siblingDoc: Record<string, any>\n}\n\nexport const relationshipPopulationPromise = async ({\n currentDepth,\n depth,\n draft,\n fallbackLocale,\n field,\n locale,\n overrideAccess,\n parentIsLocalized,\n populate: populateArg,\n req,\n showHiddenFields,\n siblingDoc,\n}: PromiseArgs): Promise<void> => {\n const resultingDoc = siblingDoc\n const populateDepth = fieldHasMaxDepth(field) && field.maxDepth! < depth ? field.maxDepth : depth\n const rowPromises: Promise<void>[] = []\n\n if (field.type === 'join' || (fieldSupportsMany(field) && field.hasMany)) {\n if (\n fieldShouldBeLocalized({ field, parentIsLocalized }) &&\n locale === 'all' &&\n typeof siblingDoc[field.name] === 'object' &&\n siblingDoc[field.name] !== null\n ) {\n Object.keys(siblingDoc[field.name]).forEach((localeKey) => {\n if (Array.isArray(siblingDoc[field.name][localeKey])) {\n siblingDoc[field.name][localeKey].forEach((_relatedDoc: any, index: number) => {\n const rowPromise = async () => {\n await populate({\n currentDepth,\n data: siblingDoc[field.name][localeKey][index],\n dataReference: resultingDoc,\n depth: populateDepth!,\n draft,\n fallbackLocale,\n field,\n index,\n key: localeKey,\n locale,\n overrideAccess,\n populateArg,\n req,\n showHiddenFields,\n })\n }\n rowPromises.push(rowPromise())\n })\n }\n })\n } else if (\n Array.isArray(siblingDoc[field.name]) ||\n Array.isArray(siblingDoc[field.name]?.docs)\n ) {\n ;(Array.isArray(siblingDoc[field.name])\n ? siblingDoc[field.name]\n : siblingDoc[field.name].docs\n ).forEach((relatedDoc: any, index: number) => {\n const rowPromise = async () => {\n if (relatedDoc) {\n await populate({\n currentDepth,\n data:\n !(field.type === 'join' && Array.isArray(field.collection)) && relatedDoc?.id\n ? relatedDoc.id\n : relatedDoc,\n dataReference: resultingDoc,\n depth: populateDepth!,\n draft,\n fallbackLocale,\n field,\n index,\n locale,\n overrideAccess,\n populateArg,\n req,\n showHiddenFields,\n })\n }\n }\n\n rowPromises.push(rowPromise())\n })\n }\n } else if (\n field.localized &&\n locale === 'all' &&\n typeof siblingDoc[field.name] === 'object' &&\n siblingDoc[field.name] !== null\n ) {\n Object.keys(siblingDoc[field.name]).forEach((localeKey) => {\n const rowPromise = async () => {\n await populate({\n currentDepth,\n data: siblingDoc[field.name][localeKey],\n dataReference: resultingDoc,\n depth: populateDepth!,\n draft,\n fallbackLocale,\n field,\n key: localeKey,\n locale,\n overrideAccess,\n populateArg,\n req,\n showHiddenFields,\n })\n }\n rowPromises.push(rowPromise())\n })\n\n await Promise.all(rowPromises)\n } else if (siblingDoc[field.name]) {\n await populate({\n currentDepth,\n data: siblingDoc[field.name],\n dataReference: resultingDoc,\n depth: populateDepth!,\n draft,\n fallbackLocale,\n field,\n locale,\n overrideAccess,\n populateArg,\n req,\n showHiddenFields,\n })\n }\n await Promise.all(rowPromises)\n}\n"],"names":["createDataloaderCacheKey","fieldHasMaxDepth","fieldShouldBeLocalized","fieldSupportsMany","populate","currentDepth","data","dataReference","depth","draft","fallbackLocale","field","index","key","locale","overrideAccess","populateArg","req","showHiddenFields","dataToUpdate","relation","type","Array","isArray","collection","relationTo","relatedCollection","payload","collections","id","value","relationshipValue","shouldPopulate","toString","payloadDataLoader","load","collectionSlug","config","slug","docID","select","defaultPopulate","transactionID","name","docs","relationshipPopulationPromise","parentIsLocalized","siblingDoc","resultingDoc","populateDepth","maxDepth","rowPromises","hasMany","Object","keys","forEach","localeKey","_relatedDoc","rowPromise","push","relatedDoc","localized","Promise","all"],"mappings":"AAGA,SAASA,wBAAwB,QAAQ,qCAAoC;AAC7E,SAASC,gBAAgB,EAAEC,sBAAsB,EAAEC,iBAAiB,QAAQ,wBAAuB;AAmBnG,8CAA8C;AAC9C,MAAMC,WAAW,OAAO,EACtBC,YAAY,EACZC,IAAI,EACJC,aAAa,EACbC,KAAK,EACLC,KAAK,EACLC,cAAc,EACdC,KAAK,EACLC,KAAK,EACLC,GAAG,EACHC,MAAM,EACNC,cAAc,EACdC,WAAW,EACXC,GAAG,EACHC,gBAAgB,EACH;IACb,MAAMC,eAAeZ;IACrB,IAAIa;IACJ,IAAIT,MAAMU,IAAI,KAAK,QAAQ;QACzBD,WAAWE,MAAMC,OAAO,CAACZ,MAAMa,UAAU,IAAIlB,KAAKmB,UAAU,GAAGd,MAAMa,UAAU;IACjF,OAAO;QACLJ,WAAWE,M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;QACnB;QAEA,MAAMI,QAAQC,GAAG,CAACZ;IACpB,OAAO,IAAIJ,UAAU,CAACpC,MAAMgC,IAAI,CAAC,EAAE;QACjC,MAAMvC,SAAS;YACbC;YACAC,MAAMyC,UAAU,CAACpC,MAAMgC,IAAI,CAAC;YAC5BpC,eAAeyC;YACfxC,OAAOyC;YACPxC;YACAC;YACAC;YACAG;YACAC;YACAC;YACAC;YACAC;QACF;IACF;IACA,MAAM4C,QAAQC,GAAG,CAACZ;AACpB,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"promise.d.ts","sourceRoot":"","sources":["../../../../src/fields/hooks/beforeChange/promise.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"promise.d.ts","sourceRoot":"","sources":["../../../../src/fields/hooks/beforeChange/promise.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,sCAAsC,CAAA;AACrF,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAA;AACpE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAA;AAC7E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AACvD,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AACpF,OAAO,KAAK,EAAS,KAAK,EAAE,UAAU,EAAY,MAAM,uBAAuB,CAAA;AAiB/E,KAAK,IAAI,GAAG;IACV;;OAEG;IACH,SAAS,CAAC,EAAE,UAAU,CAAA;IACtB,UAAU,EAAE,IAAI,GAAG,yBAAyB,CAAA;IAC5C,OAAO,EAAE,cAAc,CAAA;IACvB,IAAI,EAAE,UAAU,CAAA;IAChB,GAAG,EAAE,UAAU,CAAA;IACf,cAAc,EAAE,UAAU,CAAA;IAC1B,MAAM,EAAE,oBAAoB,EAAE,CAAA;IAC9B,KAAK,EAAE,KAAK,GAAG,UAAU,CAAA;IACzB,UAAU,EAAE,MAAM,CAAA;IAClB;;;;OAIG;IACH,cAAc,EAAE,MAAM,CAAA;IACtB,MAAM,EAAE,IAAI,GAAG,qBAAqB,CAAA;IACpC,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IACpB,kBAAkB,EAAE,CAAC,MAAM,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,EAAE,CAAA;IAClD,SAAS,EAAE,SAAS,CAAA;IACpB,cAAc,EAAE,OAAO,CAAA;IACvB,eAAe,EAAE,MAAM,CAAA;IACvB,iBAAiB,EAAE,OAAO,CAAA;IAC1B,UAAU,EAAE,MAAM,CAAA;IAClB,gBAAgB,EAAE,MAAM,CAAA;IACxB,GAAG,EAAE,cAAc,CAAA;IACnB,WAAW,EAAE,UAAU,CAAA;IACvB,UAAU,EAAE,UAAU,CAAA;IACtB,qBAAqB,CAAC,EAAE,UAAU,CAAA;IAClC,aAAa,CAAC,EAAE,CAAC,KAAK,GAAG,UAAU,CAAC,EAAE,CAAA;IACtC,cAAc,EAAE,OAAO,CAAA;CACxB,CAAA;AAUD,eAAO,MAAM,OAAO,+TA0BjB,IAAI,KAAG,OAAO,CAAC,IAAI,CAyhBrB,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/fields/hooks/beforeChange/promise.ts"],"sourcesContent":["// @ts-strict-ignore\nimport type { RichTextAdapter } from '../../../admin/RichText.js'\nimport type { SanitizedCollectionConfig } from '../../../collections/config/types.js'\nimport type { ValidationFieldError } from '../../../errors/index.js'\nimport type { SanitizedGlobalConfig } from '../../../globals/config/types.js'\nimport type { RequestContext } from '../../../index.js'\nimport type { JsonObject, Operation, PayloadRequest } from '../../../types/index.js'\nimport type { Block, Field, TabAsField, Validate } from '../../config/types.js'\n\nimport { MissingEditorProp } from '../../../errors/index.js'\nimport { deepMergeWithSourceArrays } from '../../../utilities/deepMerge.js'\nimport { getTranslatedLabel } from '../../../utilities/getTranslatedLabel.js'\nimport { fieldAffectsData, fieldShouldBeLocalized, tabHasName } from '../../config/types.js'\nimport { getFieldPathsModified as getFieldPaths } from '../../getFieldPaths.js'\nimport { getExistingRowDoc } from './getExistingRowDoc.js'\nimport { traverseFields } from './traverseFields.js'\n\nfunction buildFieldLabel(parentLabel: string, label: string): string {\n const capitalizedLabel = label.charAt(0).toUpperCase() + label.slice(1)\n return parentLabel && capitalizedLabel\n ? `${parentLabel} > ${capitalizedLabel}`\n : capitalizedLabel || parentLabel\n}\n\ntype Args = {\n /**\n * Data of the nearest parent block. If no parent block exists, this will be the `undefined`\n */\n blockData?: JsonObject\n collection: null | SanitizedCollectionConfig\n context: RequestContext\n data: JsonObject\n doc: JsonObject\n docWithLocales: JsonObject\n errors: ValidationFieldError[]\n field: Field | TabAsField\n fieldIndex: number\n /**\n * Built up labels of parent fields\n *\n * @example \"Group Field > Tab Field > Text Field\"\n */\n fieldLabelPath: string\n global: null | SanitizedGlobalConfig\n id?: number | string\n mergeLocaleActions: (() => Promise<void> | void)[]\n operation: Operation\n overrideAccess: boolean\n parentIndexPath: string\n parentIsLocalized: boolean\n parentPath: string\n parentSchemaPath: string\n req: PayloadRequest\n siblingData: JsonObject\n siblingDoc: JsonObject\n siblingDocWithLocales?: JsonObject\n siblingFields?: (Field | TabAsField)[]\n skipValidation: boolean\n}\n\n// This function is responsible for the following actions, in order:\n// - Run condition\n// - Execute field hooks\n// - Validate data\n// - Transform data for storage\n// - beforeDuplicate hooks (if duplicate)\n// - Unflatten locales\n\nexport const promise = async ({\n id,\n blockData,\n collection,\n context,\n data,\n doc,\n docWithLocales,\n errors,\n field,\n fieldIndex,\n fieldLabelPath,\n global,\n mergeLocaleActions,\n operation,\n overrideAccess,\n parentIndexPath,\n parentIsLocalized,\n parentPath,\n parentSchemaPath,\n req,\n siblingData,\n siblingDoc,\n siblingDocWithLocales,\n siblingFields,\n skipValidation,\n}: Args): Promise<void> => {\n const { indexPath, path, schemaPath } = getFieldPaths({\n field,\n index: fieldIndex,\n parentIndexPath,\n parentPath,\n parentSchemaPath,\n })\n\n const { localization } = req.payload.config\n const defaultLocale = localization ? localization?.defaultLocale : 'en'\n const operationLocale = req.locale || defaultLocale\n\n const pathSegments = path ? path.split('.') : []\n const schemaPathSegments = schemaPath ? schemaPath.split('.') : []\n const indexPathSegments = indexPath ? indexPath.split('-').filter(Boolean)?.map(Number) : []\n\n const passesCondition = field.admin?.condition\n ? Boolean(\n field.admin.condition(data, siblingData, {\n blockData: blockData!,\n operation,\n path: pathSegments,\n user: req.user,\n }),\n )\n : true\n let skipValidationFromHere = skipValidation || !passesCondition\n\n if (fieldAffectsData(field)) {\n // skip validation if the field is localized and the incoming data is null\n if (fieldShouldBeLocalized({ field, parentIsLocalized }) && operationLocale !== defaultLocale) {\n if (['array', 'blocks'].includes(field.type) && siblingData[field.name!] === null) {\n skipValidationFromHere = true\n }\n }\n\n // Execute hooks\n if (field.hooks?.beforeChange) {\n for (const hook of field.hooks.beforeChange) {\n const hookedValue = await hook({\n blockData,\n collection,\n context,\n data,\n field,\n global,\n indexPath: indexPathSegments,\n operation,\n originalDoc: doc,\n path: pathSegments,\n previousSiblingDoc: siblingDoc,\n previousValue: siblingDoc[field.name!],\n req,\n schemaPath: schemaPathSegments,\n siblingData,\n siblingDocWithLocales,\n siblingFields: siblingFields!,\n value: siblingData[field.name!],\n })\n\n if (hookedValue !== undefined) {\n siblingData[field.name!] = hookedValue\n }\n }\n }\n\n // Validate\n if (!skipValidationFromHere && 'validate' in field && field.validate) {\n const valueToValidate = siblingData[field.name]\n let jsonError: object\n\n if (field.type === 'json' && typeof siblingData[field.name] === 'string') {\n try {\n JSON.parse(siblingData[field.name] as string)\n } catch (e) {\n jsonError = e\n }\n }\n\n const validateFn: Validate<object, object, object, object> = field.validate as Validate<\n object,\n object,\n object,\n object\n >\n\n const validationResult = await validateFn(valueToValidate as never, {\n ...field,\n id,\n blockData: blockData!,\n collectionSlug: collection?.slug,\n data: deepMergeWithSourceArrays(doc, data),\n event: 'submit',\n // @ts-expect-error\n jsonError,\n operation,\n overrideAccess,\n path: pathSegments,\n preferences: { fields: {} },\n previousValue: siblingDoc[field.name],\n req,\n siblingData: deepMergeWithSourceArrays(siblingDoc, siblingData),\n })\n\n if (typeof validationResult === 'string') {\n const fieldLabel = buildFieldLabel(\n fieldLabelPath,\n getTranslatedLabel(field?.label || field?.name, req.i18n),\n )\n\n errors.push({\n label: fieldLabel,\n message: validationResult,\n path,\n })\n }\n }\n\n // Push merge locale action if applicable\n if (localization && fieldShouldBeLocalized({ field, parentIsLocalized })) {\n mergeLocaleActions.push(() => {\n const localeData = {}\n\n for (const locale of localization.localeCodes) {\n const fieldValue =\n locale === req.locale\n ? siblingData[field.name!]\n : siblingDocWithLocales?.[field.name!]?.[locale]\n\n // update locale value if it's not undefined\n if (typeof fieldValue !== 'undefined') {\n localeData[locale] = fieldValue\n }\n }\n\n // If there are locales with data, set the data\n if (Object.keys(localeData).length > 0) {\n siblingData[field.name!] = localeData\n }\n })\n }\n }\n\n switch (field.type) {\n case 'array': {\n const rows = siblingData[field.name]\n\n if (Array.isArray(rows)) {\n const promises: Promise<void>[] = []\n\n rows.forEach((row, rowIndex) => {\n promises.push(\n traverseFields({\n id,\n blockData,\n collection,\n context,\n data,\n doc,\n docWithLocales,\n errors,\n fieldLabelPath:\n field?.label === false\n ? fieldLabelPath\n : buildFieldLabel(\n fieldLabelPath,\n `${getTranslatedLabel(field?.label || field?.name, req.i18n)} ${rowIndex + 1}`,\n ),\n fields: field.fields,\n global,\n mergeLocaleActions,\n operation,\n overrideAccess,\n parentIndexPath: '',\n parentIsLocalized: parentIsLocalized || field.localized,\n parentPath: path + '.' + rowIndex,\n parentSchemaPath: schemaPath,\n req,\n siblingData: row as JsonObject,\n siblingDoc: getExistingRowDoc(row as JsonObject, siblingDoc[field.name]),\n siblingDocWithLocales: getExistingRowDoc(\n row as JsonObject,\n siblingDocWithLocales?.[field.name],\n ),\n skipValidation: skipValidationFromHere,\n }),\n )\n })\n\n await Promise.all(promises)\n }\n\n break\n }\n\n case 'blocks': {\n const rows = siblingData[field.name]\n if (Array.isArray(rows)) {\n const promises: Promise<void>[] = []\n\n rows.forEach((row, rowIndex) => {\n const rowSiblingDoc = getExistingRowDoc(row as JsonObject, siblingDoc[field.name])\n\n const rowSiblingDocWithLocales = getExistingRowDoc(\n row as JsonObject,\n siblingDocWithLocales ? siblingDocWithLocales[field.name] : {},\n )\n\n const blockTypeToMatch = (row as JsonObject).blockType || rowSiblingDoc.blockType\n\n const block: Block | undefined =\n req.payload.blocks[blockTypeToMatch] ??\n ((field.blockReferences ?? field.blocks).find(\n (curBlock) => typeof curBlock !== 'string' && curBlock.slug === blockTypeToMatch,\n ) as Block | undefined)\n\n if (block) {\n promises.push(\n traverseFields({\n id,\n blockData: row,\n collection,\n context,\n data,\n doc,\n docWithLocales,\n errors,\n fieldLabelPath:\n field?.label === false\n ? fieldLabelPath\n : buildFieldLabel(\n fieldLabelPath,\n `${getTranslatedLabel(field?.label || field?.name, req.i18n)} ${rowIndex + 1}`,\n ),\n fields: block.fields,\n global,\n mergeLocaleActions,\n operation,\n overrideAccess,\n parentIndexPath: '',\n parentIsLocalized: parentIsLocalized || field.localized,\n parentPath: path + '.' + rowIndex,\n parentSchemaPath: schemaPath + '.' + block.slug,\n req,\n siblingData: row as JsonObject,\n siblingDoc: rowSiblingDoc,\n siblingDocWithLocales: rowSiblingDocWithLocales,\n skipValidation: skipValidationFromHere,\n }),\n )\n }\n })\n\n await Promise.all(promises)\n }\n\n break\n }\n\n case 'collapsible':\n case 'row': {\n await traverseFields({\n id,\n blockData,\n collection,\n context,\n data,\n doc,\n docWithLocales,\n errors,\n fieldLabelPath:\n field.type === 'row' || field?.label === false\n ? fieldLabelPath\n : buildFieldLabel(\n fieldLabelPath,\n getTranslatedLabel(field?.label || field?.type, req.i18n),\n ),\n fields: field.fields,\n global,\n mergeLocaleActions,\n operation,\n overrideAccess,\n parentIndexPath: indexPath,\n parentIsLocalized,\n parentPath,\n parentSchemaPath: schemaPath,\n req,\n siblingData,\n siblingDoc,\n siblingDocWithLocales: siblingDocWithLocales!,\n skipValidation: skipValidationFromHere,\n })\n\n break\n }\n\n case 'group': {\n let groupSiblingData = siblingData\n let groupSiblingDoc = siblingDoc\n let groupSiblingDocWithLocales = siblingDocWithLocales\n\n const isNamedGroup = fieldAffectsData(field)\n\n if (isNamedGroup) {\n if (typeof siblingData[field.name] !== 'object') {\n siblingData[field.name] = {}\n }\n\n if (typeof siblingDoc[field.name] !== 'object') {\n siblingDoc[field.name] = {}\n }\n\n if (typeof siblingDocWithLocales![field.name] !== 'object') {\n siblingDocWithLocales![field.name] = {}\n }\n if (typeof siblingData[field.name] !== 'object') {\n siblingData[field.name] = {}\n }\n\n if (typeof siblingDoc[field.name] !== 'object') {\n siblingDoc[field.name] = {}\n }\n\n if (typeof siblingDocWithLocales![field.name] !== 'object') {\n siblingDocWithLocales![field.name] = {}\n }\n\n groupSiblingData = siblingData[field.name] as JsonObject\n groupSiblingDoc = siblingDoc[field.name] as JsonObject\n groupSiblingDocWithLocales = siblingDocWithLocales![field.name] as JsonObject\n }\n\n const fallbackLabel = field?.label || (isNamedGroup ? field.name : field?.type)\n\n await traverseFields({\n id,\n blockData,\n collection,\n context,\n data,\n doc,\n docWithLocales,\n errors,\n fieldLabelPath:\n field?.label === false\n ? fieldLabelPath\n : buildFieldLabel(fieldLabelPath, getTranslatedLabel(fallbackLabel, req.i18n)),\n fields: field.fields,\n global,\n mergeLocaleActions,\n operation,\n overrideAccess,\n parentIndexPath: isNamedGroup ? '' : indexPath,\n parentIsLocalized: parentIsLocalized || field.localized,\n parentPath: isNamedGroup ? path : parentPath,\n parentSchemaPath: schemaPath,\n req,\n siblingData: groupSiblingData,\n siblingDoc: groupSiblingDoc,\n siblingDocWithLocales: groupSiblingDocWithLocales!,\n skipValidation: skipValidationFromHere,\n })\n\n break\n }\n\n case 'point': {\n // Transform point data for storage\n if (\n Array.isArray(siblingData[field.name]) &&\n siblingData[field.name][0] !== null &&\n siblingData[field.name][1] !== null\n ) {\n siblingData[field.name] = {\n type: 'Point',\n coordinates: [\n parseFloat(siblingData[field.name][0]),\n parseFloat(siblingData[field.name][1]),\n ],\n }\n }\n\n break\n }\n\n case 'richText': {\n if (!field?.editor) {\n throw new MissingEditorProp(field) // while we allow disabling editor functionality, you should not have any richText fields defined if you do not have an editor\n }\n\n if (typeof field?.editor === 'function') {\n throw new Error('Attempted to access unsanitized rich text editor.')\n }\n\n const editor: RichTextAdapter = field?.editor\n\n if (editor?.hooks?.beforeChange?.length) {\n for (const hook of editor.hooks.beforeChange) {\n const hookedValue = await hook({\n collection,\n context,\n data,\n docWithLocales,\n errors,\n field,\n fieldLabelPath:\n field?.label === false\n ? fieldLabelPath\n : buildFieldLabel(\n fieldLabelPath,\n getTranslatedLabel(field?.label || field?.name, req.i18n),\n ),\n global,\n indexPath: indexPathSegments,\n mergeLocaleActions,\n operation,\n originalDoc: doc,\n overrideAccess,\n parentIsLocalized,\n path: pathSegments,\n previousSiblingDoc: siblingDoc,\n previousValue: siblingDoc[field.name],\n req,\n schemaPath: schemaPathSegments,\n siblingData,\n siblingDocWithLocales,\n skipValidation,\n value: siblingData[field.name],\n })\n\n if (hookedValue !== undefined) {\n siblingData[field.name] = hookedValue\n }\n }\n }\n\n break\n }\n\n case 'tab': {\n let tabSiblingData = siblingData\n let tabSiblingDoc = siblingDoc\n let tabSiblingDocWithLocales = siblingDocWithLocales\n\n const isNamedTab = tabHasName(field)\n\n if (isNamedTab) {\n if (typeof siblingData[field.name] !== 'object') {\n siblingData[field.name] = {}\n }\n\n if (typeof siblingDoc[field.name] !== 'object') {\n siblingDoc[field.name] = {}\n }\n\n if (typeof siblingDocWithLocales![field.name] !== 'object') {\n siblingDocWithLocales![field.name] = {}\n }\n\n tabSiblingData = siblingData[field.name] as JsonObject\n tabSiblingDoc = siblingDoc[field.name] as JsonObject\n tabSiblingDocWithLocales = siblingDocWithLocales![field.name] as JsonObject\n }\n\n await traverseFields({\n id,\n blockData,\n collection,\n context,\n data,\n doc,\n docWithLocales,\n errors,\n fieldLabelPath:\n field?.label === false\n ? fieldLabelPath\n : buildFieldLabel(\n fieldLabelPath,\n getTranslatedLabel(field?.label || field.name!, req.i18n),\n ),\n fields: field.fields,\n global,\n mergeLocaleActions,\n operation,\n overrideAccess,\n parentIndexPath: isNamedTab ? '' : indexPath,\n parentIsLocalized: parentIsLocalized || field.localized,\n parentPath: isNamedTab ? path : parentPath,\n parentSchemaPath: schemaPath,\n req,\n siblingData: tabSiblingData,\n siblingDoc: tabSiblingDoc,\n siblingDocWithLocales: tabSiblingDocWithLocales!,\n skipValidation: skipValidationFromHere,\n })\n\n break\n }\n\n case 'tabs': {\n await traverseFields({\n id,\n blockData,\n collection,\n context,\n data,\n doc,\n docWithLocales,\n errors,\n fieldLabelPath:\n field?.label === false\n ? fieldLabelPath\n : buildFieldLabel(fieldLabelPath, getTranslatedLabel(field?.label || '', req.i18n)),\n fields: field.tabs.map((tab) => ({ ...tab, type: 'tab' })),\n global,\n mergeLocaleActions,\n operation,\n overrideAccess,\n parentIndexPath: indexPath,\n parentIsLocalized,\n parentPath: path,\n parentSchemaPath: schemaPath,\n req,\n siblingData,\n siblingDoc,\n siblingDocWithLocales: siblingDocWithLocales!,\n skipValidation: skipValidationFromHere,\n })\n\n break\n }\n\n default: {\n break\n }\n }\n}\n"],"names":["MissingEditorProp","deepMergeWithSourceArrays","getTranslatedLabel","fieldAffectsData","fieldShouldBeLocalized","tabHasName","getFieldPathsModified","getFieldPaths","getExistingRowDoc","traverseFields","buildFieldLabel","parentLabel","label","capitalizedLabel","charAt","toUpperCase","slice","promise","id","blockData","collection","context","data","doc","docWithLocales","errors","field","fieldIndex","fieldLabelPath","global","mergeLocaleActions","operation","overrideAccess","parentIndexPath","parentIsLocalized","parentPath","parentSchemaPath","req","siblingData","siblingDoc","siblingDocWithLocales","siblingFields","skipValidation","indexPath","path","schemaPath","index","localization","payload","config","defaultLocale","operationLocale","locale","pathSegments","split","schemaPathSegments","indexPathSegments","filter","Boolean","map","Number","passesCondition","admin","condition","user","skipValidationFromHere","includes","type","name","hooks","beforeChange","hook","hookedValue","originalDoc","previousSiblingDoc","previousValue","value","undefined","validate","valueToValidate","jsonError","JSON","parse","e","validateFn","validationResult","collectionSlug","slug","event","preferences","fields","fieldLabel","i18n","push","message","localeData","localeCodes","fieldValue","Object","keys","length","rows","Array","isArray","promises","forEach","row","rowIndex","localized","Promise","all","rowSiblingDoc","rowSiblingDocWithLocales","blockTypeToMatch","blockType","block","blocks","blockReferences","find","curBlock","groupSiblingData","groupSiblingDoc","groupSiblingDocWithLocales","isNamedGroup","fallbackLabel","coordinates","parseFloat","editor","Error","tabSiblingData","tabSiblingDoc","tabSiblingDocWithLocales","isNamedTab","tabs","tab"],"mappings":"AAAA,oBAAoB;AASpB,SAASA,iBAAiB,QAAQ,2BAA0B;AAC5D,SAASC,yBAAyB,QAAQ,kCAAiC;AAC3E,SAASC,kBAAkB,QAAQ,2CAA0C;AAC7E,SAASC,gBAAgB,EAAEC,sBAAsB,EAAEC,UAAU,QAAQ,wBAAuB;AAC5F,SAASC,yBAAyBC,aAAa,QAAQ,yBAAwB;AAC/E,SAASC,iBAAiB,QAAQ,yBAAwB;AAC1D,SAASC,cAAc,QAAQ,sBAAqB;AAEpD,SAASC,gBAAgBC,WAAmB,EAAEC,KAAa;IACzD,MAAMC,mBAAmBD,MAAME,MAAM,CAAC,GAAGC,WAAW,KAAKH,MAAMI,KAAK,CAAC;IACrE,OAAOL,eAAeE,mBAClB,GAAGF,YAAY,GAAG,EAAEE,kBAAkB,GACtCA,oBAAoBF;AAC1B;AAsCA,oEAAoE;AACpE,kBAAkB;AAClB,wBAAwB;AACxB,kBAAkB;AAClB,+BAA+B;AAC/B,yCAAyC;AACzC,sBAAsB;AAEtB,OAAO,MAAMM,UAAU,OAAO,EAC5BC,EAAE,EACFC,SAAS,EACTC,UAAU,EACVC,OAAO,EACPC,IAAI,EACJC,GAAG,EACH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ASc,MAAM0C,IAAI,EAAG/B,IAAIuD,IAAI;oBAEhEF,QAAQhE,MAAMgE,MAAM;oBACpB7D;oBACAC;oBACAC;oBACAC;oBACAC,iBAAiBmG,aAAa,KAAKzF;oBACnCT,mBAAmBA,qBAAqBR,MAAMkF,SAAS;oBACvDzE,YAAYiG,aAAaxF,OAAOT;oBAChCC,kBAAkBS;oBAClBR;oBACAC,aAAa2F;oBACb1F,YAAY2F;oBACZ1F,uBAAuB2F;oBACvBzF,gBAAgBuB;gBAClB;gBAEA;YACF;QAEA,KAAK;YAAQ;gBACX,MAAMxD,eAAe;oBACnBS;oBACAC;oBACAC;oBACAC;oBACAC;oBACAC;oBACAC;oBACAC;oBACAG,gBACEF,OAAOd,UAAU,QACbgB,iBACAlB,gBAAgBkB,gBAAgB1B,mBAAmBwB,OAAOd,SAAS,IAAIyB,IAAIuD,IAAI;oBACrFF,QAAQhE,MAAM2G,IAAI,CAAC1E,GAAG,CAAC,CAAC2E,MAAS,CAAA;4BAAE,GAAGA,GAAG;4BAAEnE,MAAM;wBAAM,CAAA;oBACvDtC;oBACAC;oBACAC;oBACAC;oBACAC,iBAAiBU;oBACjBT;oBACAC,YAAYS;oBACZR,kBAAkBS;oBAClBR;oBACAC;oBACAC;oBACAC,uBAAuBA;oBACvBE,gBAAgBuB;gBAClB;gBAEA;YACF;QAEA;YAAS;gBACP;YACF;IACF;AACF,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../../../src/fields/hooks/beforeChange/promise.ts"],"sourcesContent":["import type { RichTextAdapter } from '../../../admin/RichText.js'\nimport type { SanitizedCollectionConfig } from '../../../collections/config/types.js'\nimport type { ValidationFieldError } from '../../../errors/index.js'\nimport type { SanitizedGlobalConfig } from '../../../globals/config/types.js'\nimport type { RequestContext } from '../../../index.js'\nimport type { JsonObject, Operation, PayloadRequest } from '../../../types/index.js'\nimport type { Block, Field, TabAsField, Validate } from '../../config/types.js'\n\nimport { MissingEditorProp } from '../../../errors/index.js'\nimport { deepMergeWithSourceArrays } from '../../../utilities/deepMerge.js'\nimport { getTranslatedLabel } from '../../../utilities/getTranslatedLabel.js'\nimport { fieldAffectsData, fieldShouldBeLocalized, tabHasName } from '../../config/types.js'\nimport { getFieldPathsModified as getFieldPaths } from '../../getFieldPaths.js'\nimport { getExistingRowDoc } from './getExistingRowDoc.js'\nimport { traverseFields } from './traverseFields.js'\n\nfunction buildFieldLabel(parentLabel: string, label: string): string {\n const capitalizedLabel = label.charAt(0).toUpperCase() + label.slice(1)\n return parentLabel && capitalizedLabel\n ? `${parentLabel} > ${capitalizedLabel}`\n : capitalizedLabel || parentLabel\n}\n\ntype Args = {\n /**\n * Data of the nearest parent block. If no parent block exists, this will be the `undefined`\n */\n blockData?: JsonObject\n collection: null | SanitizedCollectionConfig\n context: RequestContext\n data: JsonObject\n doc: JsonObject\n docWithLocales: JsonObject\n errors: ValidationFieldError[]\n field: Field | TabAsField\n fieldIndex: number\n /**\n * Built up labels of parent fields\n *\n * @example \"Group Field > Tab Field > Text Field\"\n */\n fieldLabelPath: string\n global: null | SanitizedGlobalConfig\n id?: number | string\n mergeLocaleActions: (() => Promise<void> | void)[]\n operation: Operation\n overrideAccess: boolean\n parentIndexPath: string\n parentIsLocalized: boolean\n parentPath: string\n parentSchemaPath: string\n req: PayloadRequest\n siblingData: JsonObject\n siblingDoc: JsonObject\n siblingDocWithLocales?: JsonObject\n siblingFields?: (Field | TabAsField)[]\n skipValidation: boolean\n}\n\n// This function is responsible for the following actions, in order:\n// - Run condition\n// - Execute field hooks\n// - Validate data\n// - Transform data for storage\n// - beforeDuplicate hooks (if duplicate)\n// - Unflatten locales\n\nexport const promise = async ({\n id,\n blockData,\n collection,\n context,\n data,\n doc,\n docWithLocales,\n errors,\n field,\n fieldIndex,\n fieldLabelPath,\n global,\n mergeLocaleActions,\n operation,\n overrideAccess,\n parentIndexPath,\n parentIsLocalized,\n parentPath,\n parentSchemaPath,\n req,\n siblingData,\n siblingDoc,\n siblingDocWithLocales,\n siblingFields,\n skipValidation,\n}: Args): Promise<void> => {\n const { indexPath, path, schemaPath } = getFieldPaths({\n field,\n index: fieldIndex,\n parentIndexPath,\n parentPath,\n parentSchemaPath,\n })\n\n const { localization } = req.payload.config\n const defaultLocale = localization ? localization?.defaultLocale : 'en'\n const operationLocale = req.locale || defaultLocale\n\n const pathSegments = path ? path.split('.') : []\n const schemaPathSegments = schemaPath ? schemaPath.split('.') : []\n const indexPathSegments = indexPath ? indexPath.split('-').filter(Boolean)?.map(Number) : []\n\n const passesCondition = field.admin?.condition\n ? Boolean(\n field.admin.condition(data, siblingData, {\n blockData: blockData!,\n operation,\n path: pathSegments,\n user: req.user,\n }),\n )\n : true\n let skipValidationFromHere = skipValidation || !passesCondition\n\n if (fieldAffectsData(field)) {\n // skip validation if the field is localized and the incoming data is null\n if (fieldShouldBeLocalized({ field, parentIsLocalized }) && operationLocale !== defaultLocale) {\n if (['array', 'blocks'].includes(field.type) && siblingData[field.name!] === null) {\n skipValidationFromHere = true\n }\n }\n\n // Execute hooks\n if (field.hooks?.beforeChange) {\n for (const hook of field.hooks.beforeChange) {\n const hookedValue = await hook({\n blockData,\n collection,\n context,\n data,\n field,\n global,\n indexPath: indexPathSegments,\n operation,\n originalDoc: doc,\n path: pathSegments,\n previousSiblingDoc: siblingDoc,\n previousValue: siblingDoc[field.name!],\n req,\n schemaPath: schemaPathSegments,\n siblingData,\n siblingDocWithLocales,\n siblingFields: siblingFields!,\n value: siblingData[field.name!],\n })\n\n if (hookedValue !== undefined) {\n siblingData[field.name!] = hookedValue\n }\n }\n }\n\n // Validate\n if (!skipValidationFromHere && 'validate' in field && field.validate) {\n const valueToValidate = siblingData[field.name]\n let jsonError: object\n\n if (field.type === 'json' && typeof siblingData[field.name] === 'string') {\n try {\n JSON.parse(siblingData[field.name] as string)\n } catch (e) {\n jsonError = e as object\n }\n }\n\n const validateFn: Validate<object, object, object, object> = field.validate as Validate<\n object,\n object,\n object,\n object\n >\n\n const validationResult = await validateFn(valueToValidate as never, {\n ...field,\n id,\n blockData: blockData!,\n collectionSlug: collection?.slug,\n data: deepMergeWithSourceArrays(doc, data),\n event: 'submit',\n // @ts-expect-error\n jsonError,\n operation,\n overrideAccess,\n path: pathSegments,\n preferences: { fields: {} },\n previousValue: siblingDoc[field.name],\n req,\n siblingData: deepMergeWithSourceArrays(siblingDoc, siblingData),\n })\n\n if (typeof validationResult === 'string') {\n const fieldLabel = buildFieldLabel(\n fieldLabelPath,\n getTranslatedLabel(field?.label || field?.name, req.i18n),\n )\n\n errors.push({\n label: fieldLabel,\n message: validationResult,\n path,\n })\n }\n }\n\n // Push merge locale action if applicable\n if (localization && fieldShouldBeLocalized({ field, parentIsLocalized })) {\n mergeLocaleActions.push(() => {\n const localeData: Record<string, unknown> = {}\n\n for (const locale of localization.localeCodes) {\n const fieldValue =\n locale === req.locale\n ? siblingData[field.name!]\n : siblingDocWithLocales?.[field.name!]?.[locale]\n\n // update locale value if it's not undefined\n if (typeof fieldValue !== 'undefined') {\n localeData[locale] = fieldValue\n }\n }\n\n // If there are locales with data, set the data\n if (Object.keys(localeData).length > 0) {\n siblingData[field.name!] = localeData\n }\n })\n }\n }\n\n switch (field.type) {\n case 'array': {\n const rows = siblingData[field.name]\n\n if (Array.isArray(rows)) {\n const promises: Promise<void>[] = []\n\n rows.forEach((row, rowIndex) => {\n promises.push(\n traverseFields({\n id,\n blockData,\n collection,\n context,\n data,\n doc,\n docWithLocales,\n errors,\n fieldLabelPath:\n field?.label === false\n ? fieldLabelPath\n : buildFieldLabel(\n fieldLabelPath,\n `${getTranslatedLabel(field?.label || field?.name, req.i18n)} ${rowIndex + 1}`,\n ),\n fields: field.fields,\n global,\n mergeLocaleActions,\n operation,\n overrideAccess,\n parentIndexPath: '',\n parentIsLocalized: parentIsLocalized || field.localized,\n parentPath: path + '.' + rowIndex,\n parentSchemaPath: schemaPath,\n req,\n siblingData: row as JsonObject,\n siblingDoc: getExistingRowDoc(row as JsonObject, siblingDoc[field.name]),\n siblingDocWithLocales: getExistingRowDoc(\n row as JsonObject,\n siblingDocWithLocales?.[field.name],\n ),\n skipValidation: skipValidationFromHere,\n }),\n )\n })\n\n await Promise.all(promises)\n }\n\n break\n }\n\n case 'blocks': {\n const rows = siblingData[field.name]\n if (Array.isArray(rows)) {\n const promises: Promise<void>[] = []\n\n rows.forEach((row, rowIndex) => {\n const rowSiblingDoc = getExistingRowDoc(row as JsonObject, siblingDoc[field.name])\n\n const rowSiblingDocWithLocales = getExistingRowDoc(\n row as JsonObject,\n siblingDocWithLocales ? siblingDocWithLocales[field.name] : {},\n )\n\n const blockTypeToMatch = (row as JsonObject).blockType || rowSiblingDoc.blockType\n\n const block: Block | undefined =\n req.payload.blocks[blockTypeToMatch] ??\n ((field.blockReferences ?? field.blocks).find(\n (curBlock) => typeof curBlock !== 'string' && curBlock.slug === blockTypeToMatch,\n ) as Block | undefined)\n\n if (block) {\n promises.push(\n traverseFields({\n id,\n blockData: row,\n collection,\n context,\n data,\n doc,\n docWithLocales,\n errors,\n fieldLabelPath:\n field?.label === false\n ? fieldLabelPath\n : buildFieldLabel(\n fieldLabelPath,\n `${getTranslatedLabel(field?.label || field?.name, req.i18n)} ${rowIndex + 1}`,\n ),\n fields: block.fields,\n global,\n mergeLocaleActions,\n operation,\n overrideAccess,\n parentIndexPath: '',\n parentIsLocalized: parentIsLocalized || field.localized,\n parentPath: path + '.' + rowIndex,\n parentSchemaPath: schemaPath + '.' + block.slug,\n req,\n siblingData: row as JsonObject,\n siblingDoc: rowSiblingDoc,\n siblingDocWithLocales: rowSiblingDocWithLocales,\n skipValidation: skipValidationFromHere,\n }),\n )\n }\n })\n\n await Promise.all(promises)\n }\n\n break\n }\n\n case 'collapsible':\n case 'row': {\n await traverseFields({\n id,\n blockData,\n collection,\n context,\n data,\n doc,\n docWithLocales,\n errors,\n fieldLabelPath:\n field.type === 'row' || field?.label === false\n ? fieldLabelPath\n : buildFieldLabel(\n fieldLabelPath,\n getTranslatedLabel(field?.label || field?.type, req.i18n),\n ),\n fields: field.fields,\n global,\n mergeLocaleActions,\n operation,\n overrideAccess,\n parentIndexPath: indexPath,\n parentIsLocalized,\n parentPath,\n parentSchemaPath: schemaPath,\n req,\n siblingData,\n siblingDoc,\n siblingDocWithLocales: siblingDocWithLocales!,\n skipValidation: skipValidationFromHere,\n })\n\n break\n }\n\n case 'group': {\n let groupSiblingData = siblingData\n let groupSiblingDoc = siblingDoc\n let groupSiblingDocWithLocales = siblingDocWithLocales\n\n const isNamedGroup = fieldAffectsData(field)\n\n if (isNamedGroup) {\n if (typeof siblingData[field.name] !== 'object') {\n siblingData[field.name] = {}\n }\n\n if (typeof siblingDoc[field.name] !== 'object') {\n siblingDoc[field.name] = {}\n }\n\n if (typeof siblingDocWithLocales![field.name] !== 'object') {\n siblingDocWithLocales![field.name] = {}\n }\n if (typeof siblingData[field.name] !== 'object') {\n siblingData[field.name] = {}\n }\n\n if (typeof siblingDoc[field.name] !== 'object') {\n siblingDoc[field.name] = {}\n }\n\n if (typeof siblingDocWithLocales![field.name] !== 'object') {\n siblingDocWithLocales![field.name] = {}\n }\n\n groupSiblingData = siblingData[field.name] as JsonObject\n groupSiblingDoc = siblingDoc[field.name] as JsonObject\n groupSiblingDocWithLocales = siblingDocWithLocales![field.name] as JsonObject\n }\n\n const fallbackLabel = field?.label || (isNamedGroup ? field.name : field?.type)\n\n await traverseFields({\n id,\n blockData,\n collection,\n context,\n data,\n doc,\n docWithLocales,\n errors,\n fieldLabelPath:\n field?.label === false\n ? fieldLabelPath\n : buildFieldLabel(fieldLabelPath, getTranslatedLabel(fallbackLabel, req.i18n)),\n fields: field.fields,\n global,\n mergeLocaleActions,\n operation,\n overrideAccess,\n parentIndexPath: isNamedGroup ? '' : indexPath,\n parentIsLocalized: parentIsLocalized || field.localized,\n parentPath: isNamedGroup ? path : parentPath,\n parentSchemaPath: schemaPath,\n req,\n siblingData: groupSiblingData,\n siblingDoc: groupSiblingDoc,\n siblingDocWithLocales: groupSiblingDocWithLocales!,\n skipValidation: skipValidationFromHere,\n })\n\n break\n }\n\n case 'point': {\n // Transform point data for storage\n if (\n Array.isArray(siblingData[field.name]) &&\n siblingData[field.name][0] !== null &&\n siblingData[field.name][1] !== null\n ) {\n siblingData[field.name] = {\n type: 'Point',\n coordinates: [\n parseFloat(siblingData[field.name][0]),\n parseFloat(siblingData[field.name][1]),\n ],\n }\n }\n\n break\n }\n\n case 'richText': {\n if (!field?.editor) {\n throw new MissingEditorProp(field) // while we allow disabling editor functionality, you should not have any richText fields defined if you do not have an editor\n }\n\n if (typeof field?.editor === 'function') {\n throw new Error('Attempted to access unsanitized rich text editor.')\n }\n\n const editor: RichTextAdapter = field?.editor\n\n if (editor?.hooks?.beforeChange?.length) {\n for (const hook of editor.hooks.beforeChange) {\n const hookedValue = await hook({\n collection,\n context,\n data,\n docWithLocales,\n errors,\n field,\n fieldLabelPath:\n field?.label === false\n ? fieldLabelPath\n : buildFieldLabel(\n fieldLabelPath,\n getTranslatedLabel(field?.label || field?.name, req.i18n),\n ),\n global,\n indexPath: indexPathSegments,\n mergeLocaleActions,\n operation,\n originalDoc: doc,\n overrideAccess,\n parentIsLocalized,\n path: pathSegments,\n previousSiblingDoc: siblingDoc,\n previousValue: siblingDoc[field.name],\n req,\n schemaPath: schemaPathSegments,\n siblingData,\n siblingDocWithLocales,\n skipValidation,\n value: siblingData[field.name],\n })\n\n if (hookedValue !== undefined) {\n siblingData[field.name] = hookedValue\n }\n }\n }\n\n break\n }\n\n case 'tab': {\n let tabSiblingData = siblingData\n let tabSiblingDoc = siblingDoc\n let tabSiblingDocWithLocales = siblingDocWithLocales\n\n const isNamedTab = tabHasName(field)\n\n if (isNamedTab) {\n if (typeof siblingData[field.name] !== 'object') {\n siblingData[field.name] = {}\n }\n\n if (typeof siblingDoc[field.name] !== 'object') {\n siblingDoc[field.name] = {}\n }\n\n if (typeof siblingDocWithLocales![field.name] !== 'object') {\n siblingDocWithLocales![field.name] = {}\n }\n\n tabSiblingData = siblingData[field.name] as JsonObject\n tabSiblingDoc = siblingDoc[field.name] as JsonObject\n tabSiblingDocWithLocales = siblingDocWithLocales![field.name] as JsonObject\n }\n\n await traverseFields({\n id,\n blockData,\n collection,\n context,\n data,\n doc,\n docWithLocales,\n errors,\n fieldLabelPath:\n field?.label === false\n ? fieldLabelPath\n : buildFieldLabel(\n fieldLabelPath,\n getTranslatedLabel(field?.label || field.name!, req.i18n),\n ),\n fields: field.fields,\n global,\n mergeLocaleActions,\n operation,\n overrideAccess,\n parentIndexPath: isNamedTab ? '' : indexPath,\n parentIsLocalized: parentIsLocalized || field.localized,\n parentPath: isNamedTab ? path : parentPath,\n parentSchemaPath: schemaPath,\n req,\n siblingData: tabSiblingData,\n siblingDoc: tabSiblingDoc,\n siblingDocWithLocales: tabSiblingDocWithLocales!,\n skipValidation: skipValidationFromHere,\n })\n\n break\n }\n\n case 'tabs': {\n await traverseFields({\n id,\n blockData,\n collection,\n context,\n data,\n doc,\n docWithLocales,\n errors,\n fieldLabelPath:\n field?.label === false\n ? fieldLabelPath\n : buildFieldLabel(fieldLabelPath, getTranslatedLabel(field?.label || '', req.i18n)),\n fields: field.tabs.map((tab) => ({ ...tab, type: 'tab' })),\n global,\n mergeLocaleActions,\n operation,\n overrideAccess,\n parentIndexPath: indexPath,\n parentIsLocalized,\n parentPath: path,\n parentSchemaPath: schemaPath,\n req,\n siblingData,\n siblingDoc,\n siblingDocWithLocales: siblingDocWithLocales!,\n skipValidation: skipValidationFromHere,\n })\n\n break\n }\n\n default: {\n break\n }\n }\n}\n"],"names":["MissingEditorProp","deepMergeWithSourceArrays","getTranslatedLabel","fieldAffectsData","fieldShouldBeLocalized","tabHasName","getFieldPathsModified","getFieldPaths","getExistingRowDoc","traverseFields","buildFieldLabel","parentLabel","label","capitalizedLabel","charAt","toUpperCase","slice","promise","id","blockData","collection","context","data","doc","docWithLocales","errors","field","fieldIndex","fieldLabelPath","global","mergeLocaleActions","operation","overrideAccess","parentIndexPath","parentIsLocalized","parentPath","parentSchemaPath","req","siblingData","siblingDoc","siblingDocWithLocales","siblingFields","skipValidation","indexPath","path","schemaPath","index","localization","payload","config","defaultLocale","operationLocale","locale","pathSegments","split","schemaPathSegments","indexPathSegments","filter","Boolean","map","Number","passesCondition","admin","condition","user","skipValidationFromHere","includes","type","name","hooks","beforeChange","hook","hookedValue","originalDoc","previousSiblingDoc","previousValue","value","undefined","validate","valueToValidate","jsonError","JSON","parse","e","validateFn","validationResult","collectionSlug","slug","event","preferences","fields","fieldLabel","i18n","push","message","localeData","localeCodes","fieldValue","Object","keys","length","rows","Array","isArray","promises","forEach","row","rowIndex","localized","Promise","all","rowSiblingDoc","rowSiblingDocWithLocales","blockTypeToMatch","blockType","block","blocks","blockReferences","find","curBlock","groupSiblingData","groupSiblingDoc","groupSiblingDocWithLocales","isNamedGroup","fallbackLabel","coordinates","parseFloat","editor","Error","tabSiblingData","tabSiblingDoc","tabSiblingDocWithLocales","isNamedTab","tabs","tab"],"mappings":"AAQA,SAASA,iBAAiB,QAAQ,2BAA0B;AAC5D,SAASC,yBAAyB,QAAQ,kCAAiC;AAC3E,SAASC,kBAAkB,QAAQ,2CAA0C;AAC7E,SAASC,gBAAgB,EAAEC,sBAAsB,EAAEC,UAAU,QAAQ,wBAAuB;AAC5F,SAASC,yBAAyBC,aAAa,QAAQ,yBAAwB;AAC/E,SAASC,iBAAiB,QAAQ,yBAAwB;AAC1D,SAASC,cAAc,QAAQ,sBAAqB;AAEpD,SAASC,gBAAgBC,WAAmB,EAAEC,KAAa;IACzD,MAAMC,mBAAmBD,MAAME,MAAM,CAAC,GAAGC,WAAW,KAAKH,MAAMI,KAAK,CAAC;IACrE,OAAOL,eAAeE,mBAClB,GAAGF,YAAY,GAAG,EAAEE,kBAAkB,GACtCA,oBAAoBF;AAC1B;AAsCA,oEAAoE;AACpE,kBAAkB;AAClB,wBAAwB;AACxB,kBAAkB;AAClB,+BAA+B;AAC/B,yCAAyC;AACzC,sBAAsB;AAEtB,OAAO,MAAMM,UAAU,OAAO,EAC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G,gBACEF,OAAOd,UAAU,QACbgB,iBACAlB,gBACEkB,gBACA1B,mBAAmBwB,OAAOd,SAASc,MAAM0C,IAAI,EAAG/B,IAAIuD,IAAI;oBAEhEF,QAAQhE,MAAMgE,MAAM;oBACpB7D;oBACAC;oBACAC;oBACAC;oBACAC,iBAAiBmG,aAAa,KAAKzF;oBACnCT,mBAAmBA,qBAAqBR,MAAMkF,SAAS;oBACvDzE,YAAYiG,aAAaxF,OAAOT;oBAChCC,kBAAkBS;oBAClBR;oBACAC,aAAa2F;oBACb1F,YAAY2F;oBACZ1F,uBAAuB2F;oBACvBzF,gBAAgBuB;gBAClB;gBAEA;YACF;QAEA,KAAK;YAAQ;gBACX,MAAMxD,eAAe;oBACnBS;oBACAC;oBACAC;oBACAC;oBACAC;oBACAC;oBACAC;oBACAC;oBACAG,gBACEF,OAAOd,UAAU,QACbgB,iBACAlB,gBAAgBkB,gBAAgB1B,mBAAmBwB,OAAOd,SAAS,IAAIyB,IAAIuD,IAAI;oBACrFF,QAAQhE,MAAM2G,IAAI,CAAC1E,GAAG,CAAC,CAAC2E,MAAS,CAAA;4BAAE,GAAGA,GAAG;4BAAEnE,MAAM;wBAAM,CAAA;oBACvDtC;oBACAC;oBACAC;oBACAC;oBACAC,iBAAiBU;oBACjBT;oBACAC,YAAYS;oBACZR,kBAAkBS;oBAClBR;oBACAC;oBACAC;oBACAC,uBAAuBA;oBACvBE,gBAAgBuB;gBAClB;gBAEA;YACF;QAEA;YAAS;gBACP;YACF;IACF;AACF,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/fields/setDefaultBeforeDuplicate.ts"],"sourcesContent":["// @ts-strict-ignore\n// default beforeDuplicate hook for required and unique fields\nimport { type FieldAffectingData, type FieldHook, fieldShouldBeLocalized } from './config/types.js'\n\nconst isStringValue = (value) => typeof value === 'string' && value.trim() !== ''\nconst unique: FieldHook = ({ value }) => (isStringValue(value) ? `${value} - Copy` : undefined)\nconst localizedUnique: FieldHook = ({ req, value }) =>\n isStringValue(value) ? `${value} - ${req?.t('general:copy') ?? 'Copy'}` : undefined\n\nexport const setDefaultBeforeDuplicate = (\n field: FieldAffectingData,\n parentIsLocalized: boolean,\n) => {\n if (\n (('required' in field && field.required) || field.unique) &&\n (!field.hooks?.beforeDuplicate ||\n (Array.isArray(field.hooks.beforeDuplicate) && field.hooks.beforeDuplicate.length === 0))\n ) {\n if (field.unique) {\n if (['email', 'number', 'point', 'relationship', 'select', 'upload'].includes(field.type)) {\n field.hooks!.beforeDuplicate = [() => undefined]\n } else if (['code', 'json', 'text', 'textarea'].includes(field.type)) {\n field.hooks!.beforeDuplicate = fieldShouldBeLocalized({ field, parentIsLocalized })\n ? [localizedUnique]\n : [unique]\n }\n }\n }\n}\n"],"names":["fieldShouldBeLocalized","isStringValue","value","trim","unique","undefined","localizedUnique","req","t","setDefaultBeforeDuplicate","field","parentIsLocalized","required","hooks","beforeDuplicate","Array","isArray","length","includes","type"],"mappings":"AAAA,oBAAoB;AACpB,8DAA8D;AAC9D,SAAkDA,sBAAsB,QAAQ,oBAAmB;AAEnG,MAAMC,gBAAgB,CAACC,
|
|
1
|
+
{"version":3,"sources":["../../src/fields/setDefaultBeforeDuplicate.ts"],"sourcesContent":["// @ts-strict-ignore\n// default beforeDuplicate hook for required and unique fields\nimport { type FieldAffectingData, type FieldHook, fieldShouldBeLocalized } from './config/types.js'\n\nconst isStringValue = (value: unknown) => typeof value === 'string' && value.trim() !== ''\nconst unique: FieldHook = ({ value }) => (isStringValue(value) ? `${value} - Copy` : undefined)\nconst localizedUnique: FieldHook = ({ req, value }) =>\n isStringValue(value) ? `${value} - ${req?.t('general:copy') ?? 'Copy'}` : undefined\n\nexport const setDefaultBeforeDuplicate = (\n field: FieldAffectingData,\n parentIsLocalized: boolean,\n) => {\n if (\n (('required' in field && field.required) || field.unique) &&\n (!field.hooks?.beforeDuplicate ||\n (Array.isArray(field.hooks.beforeDuplicate) && field.hooks.beforeDuplicate.length === 0))\n ) {\n if (field.unique) {\n if (['email', 'number', 'point', 'relationship', 'select', 'upload'].includes(field.type)) {\n field.hooks!.beforeDuplicate = [() => undefined]\n } else if (['code', 'json', 'text', 'textarea'].includes(field.type)) {\n field.hooks!.beforeDuplicate = fieldShouldBeLocalized({ field, parentIsLocalized })\n ? [localizedUnique]\n : [unique]\n }\n }\n }\n}\n"],"names":["fieldShouldBeLocalized","isStringValue","value","trim","unique","undefined","localizedUnique","req","t","setDefaultBeforeDuplicate","field","parentIsLocalized","required","hooks","beforeDuplicate","Array","isArray","length","includes","type"],"mappings":"AAAA,oBAAoB;AACpB,8DAA8D;AAC9D,SAAkDA,sBAAsB,QAAQ,oBAAmB;AAEnG,MAAMC,gBAAgB,CAACC,QAAmB,OAAOA,UAAU,YAAYA,MAAMC,IAAI,OAAO;AACxF,MAAMC,SAAoB,CAAC,EAAEF,KAAK,EAAE,GAAMD,cAAcC,SAAS,GAAGA,MAAM,OAAO,CAAC,GAAGG;AACrF,MAAMC,kBAA6B,CAAC,EAAEC,GAAG,EAAEL,KAAK,EAAE,GAChDD,cAAcC,SAAS,GAAGA,MAAM,GAAG,EAAEK,KAAKC,EAAE,mBAAmB,QAAQ,GAAGH;AAE5E,OAAO,MAAMI,4BAA4B,CACvCC,OACAC;IAEA,IACE,AAAC,CAAA,AAAC,cAAcD,SAASA,MAAME,QAAQ,IAAKF,MAAMN,MAAM,AAAD,KACtD,CAAA,CAACM,MAAMG,KAAK,EAAEC,mBACZC,MAAMC,OAAO,CAACN,MAAMG,KAAK,CAACC,eAAe,KAAKJ,MAAMG,KAAK,CAACC,eAAe,CAACG,MAAM,KAAK,CAAC,GACzF;QACA,IAAIP,MAAMN,MAAM,EAAE;YAChB,IAAI;gBAAC;gBAAS;gBAAU;gBAAS;gBAAgB;gBAAU;aAAS,CAACc,QAAQ,CAACR,MAAMS,IAAI,GAAG;gBACzFT,MAAMG,KAAK,CAAEC,eAAe,GAAG;oBAAC,IAAMT;iBAAU;YAClD,OAAO,IAAI;gBAAC;gBAAQ;gBAAQ;gBAAQ;aAAW,CAACa,QAAQ,CAACR,MAAMS,IAAI,GAAG;gBACpET,MAAMG,KAAK,CAAEC,eAAe,GAAGd,uBAAuB;oBAAEU;oBAAOC;gBAAkB,KAC7E;oBAACL;iBAAgB,GACjB;oBAACF;iBAAO;YACd;QACF;IACF;AACF,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validations.d.ts","sourceRoot":"","sources":["../../src/fields/validations.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EACV,UAAU,EACV,WAAW,EACX,aAAa,EACb,SAAS,EACT,SAAS,EACT,UAAU,EACV,SAAS,EACT,WAAW,EACX,UAAU,EACV,UAAU,EACV,iBAAiB,EACjB,iBAAiB,EACjB,qBAAqB,EACrB,uBAAuB,EACvB,aAAa,EACb,WAAW,EACX,aAAa,EACb,SAAS,EACT,WAAW,EACX,QAAQ,
|
|
1
|
+
{"version":3,"file":"validations.d.ts","sourceRoot":"","sources":["../../src/fields/validations.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EACV,UAAU,EACV,WAAW,EACX,aAAa,EACb,SAAS,EACT,SAAS,EACT,UAAU,EACV,SAAS,EACT,WAAW,EACX,UAAU,EACV,UAAU,EACV,iBAAiB,EACjB,iBAAiB,EACjB,qBAAqB,EACrB,uBAAuB,EACvB,aAAa,EACb,WAAW,EACX,aAAa,EACb,SAAS,EACT,WAAW,EACX,QAAQ,EAET,MAAM,mBAAmB,CAAA;AAK1B,MAAM,MAAM,mBAAmB,GAAG,QAAQ,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,SAAS,CAAC,CAAA;AAE/E,MAAM,MAAM,uBAAuB,GAAG,QAAQ,CAAC,MAAM,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,SAAS,CAAC,CAAA;AAErF,MAAM,MAAM,yBAAyB,GAAG,QAAQ,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,SAAS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AM,KAAK,EAAE,oBAkBnB,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;CAmBvB,CAAA"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// @ts-strict-ignore
|
|
2
1
|
import Ajv from 'ajv';
|
|
3
2
|
import ObjectIdImport from 'bson-objectid';
|
|
4
3
|
const ObjectId = ObjectIdImport.default || ObjectIdImport;
|
|
@@ -211,7 +210,7 @@ export const json = (value, { jsonError, jsonSchema, req: { t }, required })=>{
|
|
|
211
210
|
return ajv.errorsText();
|
|
212
211
|
}
|
|
213
212
|
} catch (error) {
|
|
214
|
-
return error.message;
|
|
213
|
+
return error instanceof Error ? error.message : 'Unknown error';
|
|
215
214
|
}
|
|
216
215
|
}
|
|
217
216
|
return true;
|