payload 3.91.0-internal.c1569dc → 3.92.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin.js +3 -14
- package/dist/bin/index.d.ts.map +1 -1
- package/dist/bin/index.js +15 -0
- package/dist/bin/index.js.map +1 -1
- package/dist/bin/index.spec.js +54 -0
- package/dist/bin/index.spec.js.map +1 -0
- package/dist/collections/operations/findVersionByID.d.ts.map +1 -1
- package/dist/collections/operations/findVersionByID.js +7 -0
- package/dist/collections/operations/findVersionByID.js.map +1 -1
- package/dist/collections/operations/findVersions.d.ts.map +1 -1
- package/dist/collections/operations/findVersions.js +5 -0
- package/dist/collections/operations/findVersions.js.map +1 -1
- package/dist/database/createSchemaBuildContext.d.ts +12 -0
- package/dist/database/createSchemaBuildContext.d.ts.map +1 -0
- package/dist/database/createSchemaBuildContext.js +24 -0
- package/dist/database/createSchemaBuildContext.js.map +1 -0
- package/dist/database/createSchemaBuildContext.spec.js +146 -0
- package/dist/database/createSchemaBuildContext.spec.js.map +1 -0
- package/dist/database/sanitizeJoinQuery.d.ts.map +1 -1
- package/dist/database/sanitizeJoinQuery.js +2 -1
- package/dist/database/sanitizeJoinQuery.js.map +1 -1
- package/dist/errors/APIError.d.ts +4 -0
- package/dist/errors/APIError.d.ts.map +1 -1
- package/dist/errors/APIError.js +5 -1
- package/dist/errors/APIError.js.map +1 -1
- package/dist/errors/AuthenticationError.d.ts.map +1 -1
- package/dist/errors/AuthenticationError.js +1 -0
- package/dist/errors/AuthenticationError.js.map +1 -1
- package/dist/errors/DuplicateCollection.d.ts.map +1 -1
- package/dist/errors/DuplicateCollection.js +1 -0
- package/dist/errors/DuplicateCollection.js.map +1 -1
- package/dist/errors/DuplicateFieldName.d.ts.map +1 -1
- package/dist/errors/DuplicateFieldName.js +1 -0
- package/dist/errors/DuplicateFieldName.js.map +1 -1
- package/dist/errors/DuplicateGlobal.d.ts.map +1 -1
- package/dist/errors/DuplicateGlobal.js +1 -0
- package/dist/errors/DuplicateGlobal.js.map +1 -1
- package/dist/errors/ErrorDeletingFile.d.ts.map +1 -1
- package/dist/errors/ErrorDeletingFile.js +1 -0
- package/dist/errors/ErrorDeletingFile.js.map +1 -1
- package/dist/errors/FileRetrievalError.d.ts.map +1 -1
- package/dist/errors/FileRetrievalError.js +1 -0
- package/dist/errors/FileRetrievalError.js.map +1 -1
- package/dist/errors/FileUploadError.d.ts.map +1 -1
- package/dist/errors/FileUploadError.js +1 -0
- package/dist/errors/FileUploadError.js.map +1 -1
- package/dist/errors/Forbidden.d.ts.map +1 -1
- package/dist/errors/Forbidden.js +1 -0
- package/dist/errors/Forbidden.js.map +1 -1
- package/dist/errors/InvalidConfiguration.d.ts.map +1 -1
- package/dist/errors/InvalidConfiguration.js +1 -0
- package/dist/errors/InvalidConfiguration.js.map +1 -1
- package/dist/errors/InvalidFieldJoin.d.ts.map +1 -1
- package/dist/errors/InvalidFieldJoin.js +1 -0
- package/dist/errors/InvalidFieldJoin.js.map +1 -1
- package/dist/errors/InvalidFieldName.d.ts.map +1 -1
- package/dist/errors/InvalidFieldName.js +1 -0
- package/dist/errors/InvalidFieldName.js.map +1 -1
- package/dist/errors/InvalidFieldRelationship.d.ts.map +1 -1
- package/dist/errors/InvalidFieldRelationship.js +1 -0
- package/dist/errors/InvalidFieldRelationship.js.map +1 -1
- package/dist/errors/InvalidSchema.d.ts.map +1 -1
- package/dist/errors/InvalidSchema.js +1 -0
- package/dist/errors/InvalidSchema.js.map +1 -1
- package/dist/errors/Locked.d.ts.map +1 -1
- package/dist/errors/Locked.js +1 -0
- package/dist/errors/Locked.js.map +1 -1
- package/dist/errors/LockedAuth.d.ts.map +1 -1
- package/dist/errors/LockedAuth.js +1 -0
- package/dist/errors/LockedAuth.js.map +1 -1
- package/dist/errors/MissingCollectionLabel.d.ts.map +1 -1
- package/dist/errors/MissingCollectionLabel.js +1 -0
- package/dist/errors/MissingCollectionLabel.js.map +1 -1
- package/dist/errors/MissingEditorProp.d.ts.map +1 -1
- package/dist/errors/MissingEditorProp.js +1 -0
- package/dist/errors/MissingEditorProp.js.map +1 -1
- package/dist/errors/MissingFieldInputOptions.d.ts.map +1 -1
- package/dist/errors/MissingFieldInputOptions.js +1 -0
- package/dist/errors/MissingFieldInputOptions.js.map +1 -1
- package/dist/errors/MissingFieldType.d.ts.map +1 -1
- package/dist/errors/MissingFieldType.js +1 -0
- package/dist/errors/MissingFieldType.js.map +1 -1
- package/dist/errors/MissingFile.d.ts.map +1 -1
- package/dist/errors/MissingFile.js +1 -0
- package/dist/errors/MissingFile.js.map +1 -1
- package/dist/errors/NotFound.d.ts.map +1 -1
- package/dist/errors/NotFound.js +1 -0
- package/dist/errors/NotFound.js.map +1 -1
- package/dist/errors/QueryError.d.ts.map +1 -1
- package/dist/errors/QueryError.js +1 -0
- package/dist/errors/QueryError.js.map +1 -1
- package/dist/errors/ReservedFieldName.d.ts.map +1 -1
- package/dist/errors/ReservedFieldName.js +1 -0
- package/dist/errors/ReservedFieldName.js.map +1 -1
- package/dist/errors/TimestampsRequired.d.ts.map +1 -1
- package/dist/errors/TimestampsRequired.js +1 -0
- package/dist/errors/TimestampsRequired.js.map +1 -1
- package/dist/errors/UnauthorizedError.d.ts.map +1 -1
- package/dist/errors/UnauthorizedError.js +1 -0
- package/dist/errors/UnauthorizedError.js.map +1 -1
- package/dist/errors/UnverifiedEmail.d.ts.map +1 -1
- package/dist/errors/UnverifiedEmail.js +1 -0
- package/dist/errors/UnverifiedEmail.js.map +1 -1
- package/dist/errors/ValidationError.d.ts.map +1 -1
- package/dist/errors/ValidationError.js +1 -0
- package/dist/errors/ValidationError.js.map +1 -1
- package/dist/exports/internal.d.ts +2 -0
- package/dist/exports/internal.d.ts.map +1 -1
- package/dist/exports/internal.js +1 -0
- package/dist/exports/internal.js.map +1 -1
- package/dist/fields/hooks/beforeChange/flattenValidationData.d.ts +14 -0
- package/dist/fields/hooks/beforeChange/flattenValidationData.d.ts.map +1 -0
- package/dist/fields/hooks/beforeChange/flattenValidationData.js +36 -0
- package/dist/fields/hooks/beforeChange/flattenValidationData.js.map +1 -0
- package/dist/fields/hooks/beforeChange/promise.d.ts +2 -1
- package/dist/fields/hooks/beforeChange/promise.d.ts.map +1 -1
- package/dist/fields/hooks/beforeChange/promise.js +96 -22
- package/dist/fields/hooks/beforeChange/promise.js.map +1 -1
- package/dist/fields/hooks/beforeChange/traverseFields.d.ts +2 -1
- package/dist/fields/hooks/beforeChange/traverseFields.d.ts.map +1 -1
- package/dist/fields/hooks/beforeChange/traverseFields.js +2 -1
- package/dist/fields/hooks/beforeChange/traverseFields.js.map +1 -1
- package/dist/globals/operations/findVersionByID.d.ts.map +1 -1
- package/dist/globals/operations/findVersionByID.js +7 -0
- package/dist/globals/operations/findVersionByID.js.map +1 -1
- package/dist/globals/operations/findVersions.d.ts.map +1 -1
- package/dist/globals/operations/findVersions.js +5 -0
- package/dist/globals/operations/findVersions.js.map +1 -1
- package/dist/index.bundled.d.ts +6 -1
- package/dist/queues/utilities/updateJob.d.ts.map +1 -1
- package/dist/queues/utilities/updateJob.js +15 -0
- package/dist/queues/utilities/updateJob.js.map +1 -1
- package/dist/utilities/getEntityPermissions/getEntityPermissions.d.ts.map +1 -1
- package/dist/utilities/getEntityPermissions/getEntityPermissions.js +1 -0
- package/dist/utilities/getEntityPermissions/getEntityPermissions.js.map +1 -1
- package/dist/utilities/getNextJsHMRURL.d.ts.map +1 -1
- package/dist/utilities/getNextJsHMRURL.js +4 -2
- package/dist/utilities/getNextJsHMRURL.js.map +1 -1
- package/dist/utilities/getNextJsHMRURL.spec.js +11 -0
- package/dist/utilities/getNextJsHMRURL.spec.js.map +1 -1
- package/dist/utilities/getVersionsConfig.d.ts +4 -0
- package/dist/utilities/getVersionsConfig.d.ts.map +1 -1
- package/dist/utilities/getVersionsConfig.js +5 -0
- package/dist/utilities/getVersionsConfig.js.map +1 -1
- package/lexicalLoader.mjs +26 -0
- package/package.json +10 -9
|
@@ -1 +1 @@
|
|
|
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 { 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 { type RequestContext, validateBlocksFilterOptions } from '../../../index.js'\nimport { deepMergeWithSourceArrays } from '../../../utilities/deepMerge.js'\nimport { getTranslatedLabel } from '../../../utilities/getTranslatedLabel.js'\nimport { fieldAffectsData, fieldShouldBeLocalized, tabHasName } from '../../config/types.js'\nimport { getFieldPaths } from '../../getFieldPaths.js'\nimport { getExistingRowDoc } from './getExistingRowDoc.js'\nimport { traverseFields } from './traverseFields.js'\n\nfunction buildFieldLabel(parentLabel: string, label: string | undefined): string {\n if (!label) {\n return parentLabel\n }\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 submittedTopLevelFieldNames?: ReadonlySet<string>\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 submittedTopLevelFieldNames,\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 const isOutsideSubmittedFieldScope =\n submittedTopLevelFieldNames !== undefined &&\n fieldAffectsData(field) &&\n !submittedTopLevelFieldNames.has(pathSegments[0]!)\n let skipValidationFromHere = skipValidation || isOutsideSubmittedFieldScope || !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 ('hooks' in field && 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 if (hasInvalidFieldValueShape({ field, value: siblingData[field.name!] })) {\n errors.push({\n label: buildFieldLabel(\n fieldLabelPath,\n getTranslatedLabel(field?.label || field?.name, req.i18n),\n ),\n message: req.t('validation:invalidInput'),\n path,\n })\n return\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 let filterOptionsError = false\n\n if (field.type === 'blocks' && field.filterOptions) {\n // Re-run filteroptions. If the validation error is due to filteroptions, we need to add error paths to all the blocks\n // that are no longer valid\n const validationResult = await validateBlocksFilterOptions({\n id,\n data,\n filterOptions: field.filterOptions,\n req,\n siblingData,\n value: siblingData[field.name],\n })\n if (validationResult?.invalidBlockSlugs?.length) {\n filterOptionsError = true\n let rowIndex = -1\n for (const block of siblingData[field.name] as JsonObject[]) {\n rowIndex++\n if (validationResult.invalidBlockSlugs.includes(block.blockType as string)) {\n const blockConfigOrSlug = (field.blockReferences ?? field.blocks).find(\n (blockFromField) =>\n typeof blockFromField === 'string'\n ? blockFromField === block.blockType\n : blockFromField.slug === block.blockType,\n ) as Block | undefined\n const blockConfig =\n typeof blockConfigOrSlug !== 'string'\n ? blockConfigOrSlug\n : req.payload.config?.blocks?.[blockConfigOrSlug]\n\n const blockLabelPath =\n field?.label === false\n ? fieldLabelPath\n : buildFieldLabel(\n fieldLabelPath,\n `${getTranslatedLabel(field?.label || field?.name, req.i18n)} > ${req.t('fields:block')} ${rowIndex + 1} (${getTranslatedLabel(blockConfig?.labels?.singular || block.blockType, req.i18n)})`,\n )\n\n errors.push({\n label: blockLabelPath,\n message: req.t('validation:invalidBlock', { block: block.blockType }),\n path: `${path}.${rowIndex}.id`,\n })\n }\n }\n }\n }\n\n if (!filterOptionsError) {\n // If the error is due to block filterOptions, we want to push the errors for each individual block, not the blocks\n // field itself => only push the error if the field is not a block field with validation failure due to filterOptions\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\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 submittedTopLevelFieldNames,\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 const blockLabelPath =\n field?.label === false\n ? fieldLabelPath\n : buildFieldLabel(\n fieldLabelPath,\n `${getTranslatedLabel(field?.label || field?.name, req.i18n)} > ${req.t('fields:block')} ${rowIndex + 1} (${getTranslatedLabel(block?.labels?.singular || blockTypeToMatch, req.i18n)})`,\n )\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: blockLabelPath,\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 submittedTopLevelFieldNames,\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 submittedTopLevelFieldNames,\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 submittedTopLevelFieldNames,\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: skipValidationFromHere,\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 submittedTopLevelFieldNames,\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 submittedTopLevelFieldNames,\n })\n\n break\n }\n\n default: {\n break\n }\n }\n}\n\nfunction hasInvalidFieldValueShape({\n field,\n value,\n}: {\n field: Field | TabAsField\n value: unknown\n}): boolean {\n if (value === null || typeof value === 'undefined' || !fieldAffectsData(field)) {\n return false\n }\n\n if (field.type === 'array' || field.type === 'blocks') {\n // Form state may use a numeric row count, while submitted values use arrays.\n return !(Array.isArray(value) || typeof value === 'number')\n }\n\n if (field.type === 'number') {\n // Only hasMany number fields may receive arrays.\n return typeof value === 'object' && !(field.hasMany && Array.isArray(value))\n }\n\n if ((field.type === 'relationship' || field.type === 'upload') && field.hasMany) {\n // HasMany relationships/uploads may receive arrays or one valid polymorphic value.\n if (typeof value !== 'object' || Array.isArray(value)) {\n return false\n }\n\n const relationshipValue = value as Record<PropertyKey, unknown>\n const valuePrototype = Object.getPrototypeOf(value)\n const isSinglePolymorphicRelationshipValue =\n Array.isArray(field.relationTo) &&\n (valuePrototype === null || valuePrototype === Object.prototype) &&\n Object.hasOwn(relationshipValue, 'relationTo') &&\n Object.hasOwn(relationshipValue, 'value') &&\n Reflect.ownKeys(relationshipValue).length === 2 &&\n typeof relationshipValue.relationTo === 'string' &&\n field.relationTo.includes(relationshipValue.relationTo) &&\n (typeof relationshipValue.value === 'string' || typeof relationshipValue.value === 'number')\n\n return !isSinglePolymorphicRelationshipValue\n }\n\n return false\n}\n"],"names":["MissingEditorProp","validateBlocksFilterOptions","deepMergeWithSourceArrays","getTranslatedLabel","fieldAffectsData","fieldShouldBeLocalized","tabHasName","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","submittedTopLevelFieldNames","indexPath","path","schemaPath","index","localization","payload","config","defaultLocale","operationLocale","locale","pathSegments","split","schemaPathSegments","indexPathSegments","filter","Boolean","map","Number","passesCondition","admin","condition","user","isOutsideSubmittedFieldScope","undefined","has","skipValidationFromHere","includes","type","name","hooks","beforeChange","hook","hookedValue","originalDoc","previousSiblingDoc","previousValue","value","hasInvalidFieldValueShape","push","i18n","message","t","validate","valueToValidate","jsonError","JSON","parse","e","validateFn","validationResult","collectionSlug","slug","event","preferences","fields","filterOptionsError","filterOptions","invalidBlockSlugs","length","rowIndex","block","blockType","blockConfigOrSlug","blockReferences","blocks","find","blockFromField","blockConfig","blockLabelPath","labels","singular","fieldLabel","localeData","localeCodes","fieldValue","Object","keys","rows","Array","isArray","promises","forEach","row","localized","Promise","all","rowSiblingDoc","rowSiblingDocWithLocales","blockTypeToMatch","curBlock","groupSiblingData","groupSiblingDoc","groupSiblingDocWithLocales","isNamedGroup","fallbackLabel","coordinates","parseFloat","editor","Error","tabSiblingData","tabSiblingDoc","tabSiblingDocWithLocales","isNamedTab","tabs","tab","hasMany","relationshipValue","valuePrototype","getPrototypeOf","isSinglePolymorphicRelationshipValue","relationTo","prototype","hasOwn","Reflect","ownKeys"],"mappings":"AAOA,SAASA,iBAAiB,QAAQ,2BAA0B;AAC5D,SAA8BC,2BAA2B,QAAQ,oBAAmB;AACpF,SAASC,yBAAyB,QAAQ,kCAAiC;AAC3E,SAASC,kBAAkB,QAAQ,2CAA0C;AAC7E,SAASC,gBAAgB,EAAEC,sBAAsB,EAAEC,UAAU,QAAQ,wBAA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AK,WAAW7C,MAAM6C,IAAI,KAAK,UAAU;QACrD,6EAA6E;QAC7E,OAAO,CAAEmD,CAAAA,MAAMC,OAAO,CAAC3C,UAAU,OAAOA,UAAU,QAAO;IAC3D;IAEA,IAAItD,MAAM6C,IAAI,KAAK,UAAU;QAC3B,iDAAiD;QACjD,OAAO,OAAOS,UAAU,YAAY,CAAEtD,CAAAA,MAAM2H,OAAO,IAAI3B,MAAMC,OAAO,CAAC3C,MAAK;IAC5E;IAEA,IAAI,AAACtD,CAAAA,MAAM6C,IAAI,KAAK,kBAAkB7C,MAAM6C,IAAI,KAAK,QAAO,KAAM7C,MAAM2H,OAAO,EAAE;QAC/E,mFAAmF;QACnF,IAAI,OAAOrE,UAAU,YAAY0C,MAAMC,OAAO,CAAC3C,QAAQ;YACrD,OAAO;QACT;QAEA,MAAMsE,oBAAoBtE;QAC1B,MAAMuE,iBAAiBhC,OAAOiC,cAAc,CAACxE;QAC7C,MAAMyE,uCACJ/B,MAAMC,OAAO,CAACjG,MAAMgI,UAAU,KAC7BH,CAAAA,mBAAmB,QAAQA,mBAAmBhC,OAAOoC,SAAS,AAAD,KAC9DpC,OAAOqC,MAAM,CAACN,mBAAmB,iBACjC/B,OAAOqC,MAAM,CAACN,mBAAmB,YACjCO,QAAQC,OAAO,CAACR,mBAAmBhD,MAAM,KAAK,KAC9C,OAAOgD,kBAAkBI,UAAU,KAAK,YACxChI,MAAMgI,UAAU,CAACpF,QAAQ,CAACgF,kBAAkBI,UAAU,KACrD,CAAA,OAAOJ,kBAAkBtE,KAAK,KAAK,YAAY,OAAOsE,kBAAkBtE,KAAK,KAAK,QAAO;QAE5F,OAAO,CAACyE;IACV;IAEA,OAAO;AACT"}
|
|
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 { 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 { type RequestContext, validateBlocksFilterOptions } from '../../../index.js'\nimport { deepMergeWithSourceArrays } from '../../../utilities/deepMerge.js'\nimport { getTranslatedLabel } from '../../../utilities/getTranslatedLabel.js'\nimport { isolateObjectProperty } from '../../../utilities/isolateObjectProperty.js'\nimport { fieldAffectsData, fieldShouldBeLocalized, tabHasName } from '../../config/types.js'\nimport { getFieldPaths } from '../../getFieldPaths.js'\nimport { flattenValidationData } from './flattenValidationData.js'\nimport { getExistingRowDoc } from './getExistingRowDoc.js'\nimport { traverseFields } from './traverseFields.js'\n\nfunction buildFieldLabel(parentLabel: string, label: string | undefined): string {\n if (!label) {\n return parentLabel\n }\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 blockFields?: Field[]\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 submittedTopLevelFieldNames?: ReadonlySet<string>\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 blockFields,\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 submittedTopLevelFieldNames,\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 const isOutsideSubmittedFieldScope =\n submittedTopLevelFieldNames !== undefined &&\n fieldAffectsData(field) &&\n !submittedTopLevelFieldNames.has(pathSegments[0]!)\n let skipValidationFromHere = skipValidation || isOutsideSubmittedFieldScope || !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 ('hooks' in field && 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 if (hasInvalidFieldValueShape({ field, value: siblingData[field.name!] })) {\n errors.push({\n label: buildFieldLabel(\n fieldLabelPath,\n getTranslatedLabel(field?.label || field?.name, req.i18n),\n ),\n message: req.t('validation:invalidInput'),\n path,\n })\n return\n }\n\n // Validate\n if (!skipValidationFromHere && 'validate' in field && field.validate) {\n const valueToValidate = siblingData[field.name]\n\n // With `locale: 'all'` a localized scalar is a locale-keyed object; validate each locale, not the\n // wrapper. Containers (`group`/`array`/`blocks`) are excluded - per-locale child validation is a follow-up.\n const isLocaleKeyedValue =\n operationLocale === 'all' &&\n localization &&\n fieldShouldBeLocalized({ field, parentIsLocalized }) &&\n field.type !== 'group' &&\n valueToValidate !== null &&\n typeof valueToValidate === 'object' &&\n !Array.isArray(valueToValidate)\n\n const localizedValuesToValidate: { locale?: string; value: unknown }[] = isLocaleKeyedValue\n ? localization.localeCodes\n .filter((locale) => locale in (valueToValidate as JsonObject))\n .map((locale) => ({ locale, value: (valueToValidate as JsonObject)[locale] }))\n : [{ value: valueToValidate }]\n\n // No recognized locales (e.g. `{}`): validate `undefined` once so required/optional still apply.\n if (localizedValuesToValidate.length === 0) {\n localizedValuesToValidate.push({ value: undefined })\n }\n\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 let validationResult: string | true = true\n let failedLocale: string | undefined\n\n const validationData = deepMergeWithSourceArrays<JsonObject>(doc, data)\n const validationSiblingData = deepMergeWithSourceArrays<JsonObject>(siblingDoc, siblingData)\n\n for (const { locale, value } of localizedValuesToValidate) {\n // Scope `req.locale` to the current locale via a proxy, without mutating the shared request.\n const validationReq = locale ? isolateObjectProperty(req, 'locale') : req\n if (locale) {\n validationReq.locale = locale\n }\n\n const localeContext = locale\n ? {\n blockData:\n blockData && blockFields\n ? flattenValidationData({\n config: req.payload.config,\n data: blockData,\n fields: blockFields,\n locale,\n parentIsLocalized,\n })\n : blockData,\n data: flattenValidationData({\n config: req.payload.config,\n data: validationData,\n fields: (collection?.fields || global?.fields)!,\n locale,\n }),\n siblingData: flattenValidationData({\n config: req.payload.config,\n data: validationSiblingData,\n fields: siblingFields!,\n locale,\n parentIsLocalized,\n }),\n }\n : { blockData, data: validationData, siblingData: validationSiblingData }\n\n validationResult = await validateFn(value as never, {\n ...field,\n id,\n blockData: localeContext.blockData!,\n collectionSlug: collection?.slug,\n data: localeContext.data,\n event: 'submit',\n // @ts-expect-error generic validation options cannot infer JSON fields\n jsonError,\n operation,\n overrideAccess,\n path: pathSegments,\n preferences: { fields: {} },\n previousValue: locale\n ? (siblingDoc[field.name] as JsonObject)?.[locale]\n : siblingDoc[field.name],\n req: validationReq,\n siblingData: localeContext.siblingData,\n })\n\n if (typeof validationResult === 'string') {\n failedLocale = locale\n break\n }\n }\n\n if (typeof validationResult === 'string') {\n let filterOptionsError = false\n\n if (field.type === 'blocks' && field.filterOptions) {\n // Re-run filteroptions. If the validation error is due to filteroptions, we need to add error paths to all the blocks\n // that are no longer valid\n const validationResult = await validateBlocksFilterOptions({\n id,\n data,\n filterOptions: field.filterOptions,\n req,\n siblingData,\n value: siblingData[field.name],\n })\n if (validationResult?.invalidBlockSlugs?.length) {\n filterOptionsError = true\n let rowIndex = -1\n for (const block of siblingData[field.name] as JsonObject[]) {\n rowIndex++\n if (validationResult.invalidBlockSlugs.includes(block.blockType as string)) {\n const blockConfigOrSlug = (field.blockReferences ?? field.blocks).find(\n (blockFromField) =>\n typeof blockFromField === 'string'\n ? blockFromField === block.blockType\n : blockFromField.slug === block.blockType,\n ) as Block | undefined\n const blockConfig =\n typeof blockConfigOrSlug !== 'string'\n ? blockConfigOrSlug\n : req.payload.config?.blocks?.[blockConfigOrSlug]\n\n const blockLabelPath =\n field?.label === false\n ? fieldLabelPath\n : buildFieldLabel(\n fieldLabelPath,\n `${getTranslatedLabel(field?.label || field?.name, req.i18n)} > ${req.t('fields:block')} ${rowIndex + 1} (${getTranslatedLabel(blockConfig?.labels?.singular || block.blockType, req.i18n)})`,\n )\n\n errors.push({\n label: blockLabelPath,\n message: req.t('validation:invalidBlock', { block: block.blockType }),\n path: `${path}.${rowIndex}.id`,\n })\n }\n }\n }\n }\n\n if (!filterOptionsError) {\n // If the error is due to block filterOptions, we want to push the errors for each individual block, not the blocks\n // field itself => only push the error if the field is not a block field with validation failure due to filterOptions\n const fieldLabel = buildFieldLabel(\n fieldLabelPath,\n getTranslatedLabel(field?.label || field?.name, req.i18n),\n )\n\n errors.push({\n label: failedLocale ? `${fieldLabel} (${failedLocale})` : fieldLabel,\n message: validationResult,\n path,\n })\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 // With `locale: 'all'`, siblingData holds a locale-keyed object (`{ en, es }`) rather than a single\n // locale's value - take each submitted locale, falling back to the existing doc for ones not sent.\n const submittedValue = siblingData[field.name!]\n const isAllLocales =\n req.locale === 'all' &&\n submittedValue !== null &&\n typeof submittedValue === 'object' &&\n !Array.isArray(submittedValue)\n\n for (const locale of localization.localeCodes) {\n const existingValue = siblingDocWithLocales?.[field.name!]?.[locale]\n\n const fieldValue = isAllLocales\n ? locale in (submittedValue as Record<string, unknown>)\n ? (submittedValue as Record<string, unknown>)[locale]\n : existingValue\n : locale === req.locale\n ? submittedValue\n : existingValue\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 blockFields,\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 submittedTopLevelFieldNames,\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 const blockLabelPath =\n field?.label === false\n ? fieldLabelPath\n : buildFieldLabel(\n fieldLabelPath,\n `${getTranslatedLabel(field?.label || field?.name, req.i18n)} > ${req.t('fields:block')} ${rowIndex + 1} (${getTranslatedLabel(block?.labels?.singular || blockTypeToMatch, req.i18n)})`,\n )\n\n if (block) {\n promises.push(\n traverseFields({\n id,\n blockData: row,\n blockFields: block.fields,\n collection,\n context,\n data,\n doc,\n docWithLocales,\n errors,\n fieldLabelPath: blockLabelPath,\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 submittedTopLevelFieldNames,\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 blockFields,\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 submittedTopLevelFieldNames,\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 blockFields,\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 submittedTopLevelFieldNames,\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: skipValidationFromHere,\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 blockFields,\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 submittedTopLevelFieldNames,\n })\n\n break\n }\n\n case 'tabs': {\n await traverseFields({\n id,\n blockData,\n blockFields,\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 submittedTopLevelFieldNames,\n })\n\n break\n }\n\n default: {\n break\n }\n }\n}\n\nfunction hasInvalidFieldValueShape({\n field,\n value,\n}: {\n field: Field | TabAsField\n value: unknown\n}): boolean {\n if (value === null || typeof value === 'undefined' || !fieldAffectsData(field)) {\n return false\n }\n\n if (field.type === 'array' || field.type === 'blocks') {\n // Form state may use a numeric row count, while submitted values use arrays.\n return !(Array.isArray(value) || typeof value === 'number')\n }\n\n if (field.type === 'number') {\n // Only hasMany number fields may receive arrays.\n return typeof value === 'object' && !(field.hasMany && Array.isArray(value))\n }\n\n if ((field.type === 'relationship' || field.type === 'upload') && field.hasMany) {\n // HasMany relationships/uploads may receive arrays or one valid polymorphic value.\n if (typeof value !== 'object' || Array.isArray(value)) {\n return false\n }\n\n const relationshipValue = value as Record<PropertyKey, unknown>\n const valuePrototype = Object.getPrototypeOf(value)\n const isSinglePolymorphicRelationshipValue =\n Array.isArray(field.relationTo) &&\n (valuePrototype === null || valuePrototype === Object.prototype) &&\n Object.hasOwn(relationshipValue, 'relationTo') &&\n Object.hasOwn(relationshipValue, 'value') &&\n Reflect.ownKeys(relationshipValue).length === 2 &&\n typeof relationshipValue.relationTo === 'string' &&\n field.relationTo.includes(relationshipValue.relationTo) &&\n (typeof relationshipValue.value === 'string' || typeof relationshipValue.value === 'number')\n\n return !isSinglePolymorphicRelationshipValue\n }\n\n return false\n}\n"],"names":["MissingEditorProp","validateBlocksFilterOptions","deepMergeWithSourceArrays","getTranslatedLabel","isolateObjectProperty","fieldAffectsData","fieldShouldBeLocalized","tabHasName","getFieldPaths","flattenValidationData","getExistingRowDoc","traverseFields","buildFieldLabel","parentLabel","label","capitalizedLabel","charAt","toUpperCase","slice","promise","id","blockData","blockFields","collection","context","data","doc","docWithLocales","errors","field","fieldIndex","fieldLabelPath","global","mergeLocaleActions","operation","overrideAccess","parentIndexPath","parentIsLocalized","parentPath","parentSchemaPath","req","siblingData","siblingDoc","siblingDocWithLocales","siblingFields","skipValidation","submittedTopLevelFieldNames","indexPath","path","schemaPath","index","localization","payload","config","defaultLocale","operationLocale","locale","pathSegments","split","schemaPathSegments","indexPathSegments","filter","Boolean","map","Number","passesCondition","admin","condition","user","isOutsideSubmittedFieldScope","undefined","has","skipValidationFromHere","includes","type","name","hooks","beforeChange","hook","hookedValue","originalDoc","previousSiblingDoc","previousValue","value","hasInvalidFieldValueShape","push","i18n","message","t","validate","valueToValidate","isLocaleKeyedValue","Array","isArray","localizedValuesToValidate","localeCodes","length","jsonError","JSON","parse","e","validateFn","validationResult","failedLocale","validationData","validationSiblingData","validationReq","localeContext","fields","collectionSlug","slug","event","preferences","filterOptionsError","filterOptions","invalidBlockSlugs","rowIndex","block","blockType","blockConfigOrSlug","blockReferences","blocks","find","blockFromField","blockConfig","blockLabelPath","labels","singular","fieldLabel","localeData","submittedValue","isAllLocales","existingValue","fieldValue","Object","keys","rows","promises","forEach","row","localized","Promise","all","rowSiblingDoc","rowSiblingDocWithLocales","blockTypeToMatch","curBlock","groupSiblingData","groupSiblingDoc","groupSiblingDocWithLocales","isNamedGroup","fallbackLabel","coordinates","parseFloat","editor","Error","tabSiblingData","tabSiblingDoc","tabSiblingDocWithLocales","isNamedTab","tabs","tab","hasMany","relationshipValue","valuePrototype","getPrototypeOf","isSinglePolymorphicRelationshipValue","relationTo","prototype","hasOwn","Reflect","ownKeys"],"mappings":"AAOA,SAASA,iBAAiB,QAAQ,2BAA0B;AAC5D,SAA8BC,2BAA2B,QAAQ,oBAAmB;AACpF,SAASC,yBAAyB,QAAQ,kCAAiC;AAC3E,SAASC,kBAAkB,QAAQ,2CAA0C;AAC7E,SAASC,qBAAqB,QAAQ,8CAA6C;AACnF,SAASC,gBAAgB,EAAEC,sBAAsB,EAAEC,UAAU,QAAQ,wBAAuB;AAC5F,SAASC,aAAa,QAAQ,yBAAwB;AACtD,SAASC,qBAAqB,QAAQ,6BAA4B;AAClE,SAASC,iBAAiB,QAAQ,yBAAwB;AAC1D,SAASC,cAAc,QAAQ,sBAAqB;AAEpD,SAASC,gBAAgBC,WAAmB,EAAEC,KAAyB;IACrE,IAAI,CAACA,OAAO;QACV,OAAOD;IACT;IACA,MAAME,mBAAmBD,MAAME,MAAM,CAAC,GAAGC,WAAW,KAAKH,MAAMI,KAAK,CAAC;IACrE,OAAOL,eAAeE,mBAClB,GAAGF,YAAY,GAAG,EAAEE,kBAAkB,GACtCA,oBAAoBF;AAC1B;AAwCA,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,WAAW,EACXC,UAAU,EACVC,OAAO,EACPC,IAAI,EACJC,GAAG,EACHC,cAAc,EACdC,MAAM,EACNC,KAAK,EACLC,UAAU,EACVC,cAAc,EACdC,MAAM,EACNC,kBAAkB,EAClBC,SAAS,EACTC,cAAc,EACdC,eAAe,EACfC,iBAAiB,EACjBC,UAAU,EACVC,gBAAgB,EAChBC,GAAG,EACHC,WAAW,EACXC,UAAU,EACVC,qBAAqB,EACrBC,aAAa,EACb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CAAEkB,CAAAA,MAAMC,OAAO,CAACV,UAAU,OAAOA,UAAU,QAAO;IAC3D;IAEA,IAAItD,MAAM6C,IAAI,KAAK,UAAU;QAC3B,iDAAiD;QACjD,OAAO,OAAOS,UAAU,YAAY,CAAEtD,CAAAA,MAAMqI,OAAO,IAAItE,MAAMC,OAAO,CAACV,MAAK;IAC5E;IAEA,IAAI,AAACtD,CAAAA,MAAM6C,IAAI,KAAK,kBAAkB7C,MAAM6C,IAAI,KAAK,QAAO,KAAM7C,MAAMqI,OAAO,EAAE;QAC/E,mFAAmF;QACnF,IAAI,OAAO/E,UAAU,YAAYS,MAAMC,OAAO,CAACV,QAAQ;YACrD,OAAO;QACT;QAEA,MAAMgF,oBAAoBhF;QAC1B,MAAMiF,iBAAiB9B,OAAO+B,cAAc,CAAClF;QAC7C,MAAMmF,uCACJ1E,MAAMC,OAAO,CAAChE,MAAM0I,UAAU,KAC7BH,CAAAA,mBAAmB,QAAQA,mBAAmB9B,OAAOkC,SAAS,AAAD,KAC9DlC,OAAOmC,MAAM,CAACN,mBAAmB,iBACjC7B,OAAOmC,MAAM,CAACN,mBAAmB,YACjCO,QAAQC,OAAO,CAACR,mBAAmBnE,MAAM,KAAK,KAC9C,OAAOmE,kBAAkBI,UAAU,KAAK,YACxC1I,MAAM0I,UAAU,CAAC9F,QAAQ,CAAC0F,kBAAkBI,UAAU,KACrD,CAAA,OAAOJ,kBAAkBhF,KAAK,KAAK,YAAY,OAAOgF,kBAAkBhF,KAAK,KAAK,QAAO;QAE5F,OAAO,CAACmF;IACV;IAEA,OAAO;AACT"}
|
|
@@ -9,6 +9,7 @@ type Args = {
|
|
|
9
9
|
* Data of the nearest parent block. If no parent block exists, this will be the `undefined`
|
|
10
10
|
*/
|
|
11
11
|
blockData?: JsonObject;
|
|
12
|
+
blockFields?: Field[];
|
|
12
13
|
collection: null | SanitizedCollectionConfig;
|
|
13
14
|
context: RequestContext;
|
|
14
15
|
data: JsonObject;
|
|
@@ -61,6 +62,6 @@ type Args = {
|
|
|
61
62
|
* - Transform data for storage
|
|
62
63
|
* - Unflatten locales. The input `data` is the normal document for one locale. The output result will become the document with locales.
|
|
63
64
|
*/
|
|
64
|
-
export declare const traverseFields: ({ id, blockData, collection, context, data, doc, docWithLocales, errors, fieldLabelPath, fields, global, mergeLocaleActions, operation, overrideAccess, parentIndexPath, parentIsLocalized, parentPath, parentSchemaPath, req, siblingData, siblingDoc, siblingDocWithLocales, skipValidation, submittedTopLevelFieldNames, }: Args) => Promise<void>;
|
|
65
|
+
export declare const traverseFields: ({ id, blockData, blockFields, collection, context, data, doc, docWithLocales, errors, fieldLabelPath, fields, global, mergeLocaleActions, operation, overrideAccess, parentIndexPath, parentIsLocalized, parentPath, parentSchemaPath, req, siblingData, siblingDoc, siblingDocWithLocales, skipValidation, submittedTopLevelFieldNames, }: Args) => Promise<void>;
|
|
65
66
|
export {};
|
|
66
67
|
//# sourceMappingURL=traverseFields.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"traverseFields.d.ts","sourceRoot":"","sources":["../../../../src/fields/hooks/beforeChange/traverseFields.ts"],"names":[],"mappings":"AAAA,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,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AAI9D,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;;OAEG;IACH,GAAG,EAAE,UAAU,CAAA;IACf;;OAEG;IACH,cAAc,EAAE,UAAU,CAAA;IAC1B,MAAM,EAAE,oBAAoB,EAAE,CAAA;IAC9B;;;;OAIG;IACH,cAAc,EAAE,MAAM,CAAA;IACtB,MAAM,EAAE,CAAC,KAAK,GAAG,UAAU,CAAC,EAAE,CAAA;IAC9B,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;;OAEG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAA;IAC3B,UAAU,EAAE,MAAM,CAAA;IAClB,gBAAgB,EAAE,MAAM,CAAA;IACxB,GAAG,EAAE,cAAc,CAAA;IACnB,WAAW,EAAE,UAAU,CAAA;IACvB;;OAEG;IACH,UAAU,EAAE,UAAU,CAAA;IACtB;;OAEG;IACH,qBAAqB,EAAE,UAAU,CAAA;IACjC,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,2BAA2B,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,CAAA;CAClD,CAAA;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,cAAc,
|
|
1
|
+
{"version":3,"file":"traverseFields.d.ts","sourceRoot":"","sources":["../../../../src/fields/hooks/beforeChange/traverseFields.ts"],"names":[],"mappings":"AAAA,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;AAC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B,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,CAAA;CAClD,CAAA;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,cAAc,+UA0BxB,IAAI,KAAG,OAAO,CAAC,IAAI,CAsCrB,CAAA"}
|
|
@@ -6,12 +6,13 @@ import { promise } from './promise.js';
|
|
|
6
6
|
* - Validate data
|
|
7
7
|
* - Transform data for storage
|
|
8
8
|
* - Unflatten locales. The input `data` is the normal document for one locale. The output result will become the document with locales.
|
|
9
|
-
*/ export const traverseFields = async ({ id, blockData, collection, context, data, doc, docWithLocales, errors, fieldLabelPath, fields, global, mergeLocaleActions, operation, overrideAccess, parentIndexPath, parentIsLocalized, parentPath, parentSchemaPath, req, siblingData, siblingDoc, siblingDocWithLocales, skipValidation, submittedTopLevelFieldNames })=>{
|
|
9
|
+
*/ export const traverseFields = async ({ id, blockData, blockFields, collection, context, data, doc, docWithLocales, errors, fieldLabelPath, fields, global, mergeLocaleActions, operation, overrideAccess, parentIndexPath, parentIsLocalized, parentPath, parentSchemaPath, req, siblingData, siblingDoc, siblingDocWithLocales, skipValidation, submittedTopLevelFieldNames })=>{
|
|
10
10
|
const promises = [];
|
|
11
11
|
fields.forEach((field, fieldIndex)=>{
|
|
12
12
|
promises.push(promise({
|
|
13
13
|
id,
|
|
14
14
|
blockData,
|
|
15
|
+
blockFields,
|
|
15
16
|
collection,
|
|
16
17
|
context,
|
|
17
18
|
data,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/fields/hooks/beforeChange/traverseFields.ts"],"sourcesContent":["import 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 { Field, TabAsField } from '../../config/types.js'\n\nimport { promise } from './promise.js'\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 /**\n * The original data (not modified by any hooks)\n */\n doc: JsonObject\n /**\n * The original data with locales (not modified by any hooks)\n */\n docWithLocales: JsonObject\n errors: ValidationFieldError[]\n /**\n * Built up labels of parent fields\n *\n * @example \"Group Field > Tab Field > Text Field\"\n */\n fieldLabelPath: string\n fields: (Field | TabAsField)[]\n global: null | SanitizedGlobalConfig\n id?: number | string\n mergeLocaleActions: (() => Promise<void> | void)[]\n operation: Operation\n overrideAccess: boolean\n parentIndexPath: string\n /**\n * @todo make required in v4.0\n */\n parentIsLocalized?: boolean\n parentPath: string\n parentSchemaPath: string\n req: PayloadRequest\n siblingData: JsonObject\n /**\n * The original siblingData (not modified by any hooks)\n */\n siblingDoc: JsonObject\n /**\n * The original siblingData with locales (not modified by any hooks)\n */\n siblingDocWithLocales: JsonObject\n skipValidation?: boolean\n submittedTopLevelFieldNames?: ReadonlySet<string>\n}\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 * - Unflatten locales. The input `data` is the normal document for one locale. The output result will become the document with locales.\n */\nexport const traverseFields = async ({\n id,\n blockData,\n collection,\n context,\n data,\n doc,\n docWithLocales,\n errors,\n fieldLabelPath,\n fields,\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 skipValidation,\n submittedTopLevelFieldNames,\n}: Args): Promise<void> => {\n const promises: Promise<void>[] = []\n\n fields.forEach((field, fieldIndex) => {\n promises.push(\n promise({\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: parentIsLocalized!,\n parentPath,\n parentSchemaPath,\n req,\n siblingData,\n siblingDoc,\n siblingDocWithLocales,\n siblingFields: fields,\n skipValidation: skipValidation!,\n submittedTopLevelFieldNames,\n }),\n )\n })\n\n await Promise.all(promises)\n}\n"],"names":["promise","traverseFields","id","blockData","collection","context","data","doc","docWithLocales","errors","fieldLabelPath","fields","global","mergeLocaleActions","operation","overrideAccess","parentIndexPath","parentIsLocalized","parentPath","parentSchemaPath","req","siblingData","siblingDoc","siblingDocWithLocales","skipValidation","submittedTopLevelFieldNames","promises","forEach","field","fieldIndex","push","siblingFields","Promise","all"],"mappings":"AAOA,SAASA,OAAO,QAAQ,eAAc;
|
|
1
|
+
{"version":3,"sources":["../../../../src/fields/hooks/beforeChange/traverseFields.ts"],"sourcesContent":["import 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 { Field, TabAsField } from '../../config/types.js'\n\nimport { promise } from './promise.js'\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 blockFields?: Field[]\n collection: null | SanitizedCollectionConfig\n context: RequestContext\n data: JsonObject\n /**\n * The original data (not modified by any hooks)\n */\n doc: JsonObject\n /**\n * The original data with locales (not modified by any hooks)\n */\n docWithLocales: JsonObject\n errors: ValidationFieldError[]\n /**\n * Built up labels of parent fields\n *\n * @example \"Group Field > Tab Field > Text Field\"\n */\n fieldLabelPath: string\n fields: (Field | TabAsField)[]\n global: null | SanitizedGlobalConfig\n id?: number | string\n mergeLocaleActions: (() => Promise<void> | void)[]\n operation: Operation\n overrideAccess: boolean\n parentIndexPath: string\n /**\n * @todo make required in v4.0\n */\n parentIsLocalized?: boolean\n parentPath: string\n parentSchemaPath: string\n req: PayloadRequest\n siblingData: JsonObject\n /**\n * The original siblingData (not modified by any hooks)\n */\n siblingDoc: JsonObject\n /**\n * The original siblingData with locales (not modified by any hooks)\n */\n siblingDocWithLocales: JsonObject\n skipValidation?: boolean\n submittedTopLevelFieldNames?: ReadonlySet<string>\n}\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 * - Unflatten locales. The input `data` is the normal document for one locale. The output result will become the document with locales.\n */\nexport const traverseFields = async ({\n id,\n blockData,\n blockFields,\n collection,\n context,\n data,\n doc,\n docWithLocales,\n errors,\n fieldLabelPath,\n fields,\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 skipValidation,\n submittedTopLevelFieldNames,\n}: Args): Promise<void> => {\n const promises: Promise<void>[] = []\n\n fields.forEach((field, fieldIndex) => {\n promises.push(\n promise({\n id,\n blockData,\n blockFields,\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: parentIsLocalized!,\n parentPath,\n parentSchemaPath,\n req,\n siblingData,\n siblingDoc,\n siblingDocWithLocales,\n siblingFields: fields,\n skipValidation: skipValidation!,\n submittedTopLevelFieldNames,\n }),\n )\n })\n\n await Promise.all(promises)\n}\n"],"names":["promise","traverseFields","id","blockData","blockFields","collection","context","data","doc","docWithLocales","errors","fieldLabelPath","fields","global","mergeLocaleActions","operation","overrideAccess","parentIndexPath","parentIsLocalized","parentPath","parentSchemaPath","req","siblingData","siblingDoc","siblingDocWithLocales","skipValidation","submittedTopLevelFieldNames","promises","forEach","field","fieldIndex","push","siblingFields","Promise","all"],"mappings":"AAOA,SAASA,OAAO,QAAQ,eAAc;AAqDtC;;;;;;;CAOC,GACD,OAAO,MAAMC,iBAAiB,OAAO,EACnCC,EAAE,EACFC,SAAS,EACTC,WAAW,EACXC,UAAU,EACVC,OAAO,EACPC,IAAI,EACJC,GAAG,EACHC,cAAc,EACdC,MAAM,EACNC,cAAc,EACdC,MAAM,EACNC,MAAM,EACNC,kBAAkB,EAClBC,SAAS,EACTC,cAAc,EACdC,eAAe,EACfC,iBAAiB,EACjBC,UAAU,EACVC,gBAAgB,EAChBC,GAAG,EACHC,WAAW,EACXC,UAAU,EACVC,qBAAqB,EACrBC,cAAc,EACdC,2BAA2B,EACtB;IACL,MAAMC,WAA4B,EAAE;IAEpCf,OAAOgB,OAAO,CAAC,CAACC,OAAOC;QACrBH,SAASI,IAAI,CACX/B,QAAQ;YACNE;YACAC;YACAC;YACAC;YACAC;YACAC;YACAC;YACAC;YACAC;YACAmB;YACAC;YACAnB;YACAE;YACAC;YACAC;YACAC;YACAC;YACAC,mBAAmBA;YACnBC;YACAC;YACAC;YACAC;YACAC;YACAC;YACAQ,eAAepB;YACfa,gBAAgBA;YAChBC;QACF;IAEJ;IAEA,MAAMO,QAAQC,GAAG,CAACP;AACpB,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"findVersionByID.d.ts","sourceRoot":"","sources":["../../../src/globals/operations/findVersionByID.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4CAA4C,CAAA;AAE7E,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AACpF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;AAC9D,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAA;
|
|
1
|
+
{"version":3,"file":"findVersionByID.d.ts","sourceRoot":"","sources":["../../../src/globals/operations/findVersionByID.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4CAA4C,CAAA;AAE7E,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AACpF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;AAC9D,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAA;AAa/D,MAAM,MAAM,SAAS,GAAG;IACtB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,YAAY,EAAE,qBAAqB,CAAA;IACnC,EAAE,EAAE,MAAM,GAAG,MAAM,CAAA;IACnB,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,QAAQ,CAAC,EAAE,YAAY,CAAA;IACvB,GAAG,EAAE,cAAc,CAAA;IACnB,gBAAgB,CAAC,EAAE,OAAO,CAAA;CAC3B,GAAG,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE,UAAU,CAAC,EAAE,QAAQ,CAAC,CAAA;AAEnD,eAAO,MAAM,wBAAwB,GAAU,CAAC,SAAS,eAAe,CAAC,CAAC,CAAC,cACnE,SAAS,KACd,OAAO,CAAC,CAAC,CAuJX,CAAA"}
|
|
@@ -3,12 +3,19 @@ import { combineQueries } from '../../database/combineQueries.js';
|
|
|
3
3
|
import { Forbidden, NotFound } from '../../errors/index.js';
|
|
4
4
|
import { afterRead } from '../../fields/hooks/afterRead/index.js';
|
|
5
5
|
import { deepCopyObjectSimple } from '../../utilities/deepCopyObject.js';
|
|
6
|
+
import { hasVersionsEnabled } from '../../utilities/getVersionsConfig.js';
|
|
6
7
|
import { killTransaction } from '../../utilities/killTransaction.js';
|
|
7
8
|
import { sanitizeSelect } from '../../utilities/sanitizeSelect.js';
|
|
8
9
|
import { buildVersionGlobalFields } from '../../versions/buildGlobalFields.js';
|
|
9
10
|
import { getQueryDraftsSelect } from '../../versions/drafts/getQueryDraftsSelect.js';
|
|
10
11
|
export const findVersionByIDOperation = async (args)=>{
|
|
11
12
|
const { id, currentDepth, depth, disableErrors, globalConfig, overrideAccess, populate, req: { fallbackLocale, locale, payload }, req, select: incomingSelect, showHiddenFields } = args;
|
|
13
|
+
if (!hasVersionsEnabled(globalConfig)) {
|
|
14
|
+
if (disableErrors) {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
throw new NotFound(req.t);
|
|
18
|
+
}
|
|
12
19
|
try {
|
|
13
20
|
// /////////////////////////////////////
|
|
14
21
|
// Access
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/globals/operations/findVersionByID.ts"],"sourcesContent":["import type { FindOptions } from '../../collections/operations/local/find.js'\nimport type { FindGlobalVersionsArgs } from '../../database/types.js'\nimport type { PayloadRequest, PopulateType, SelectType } from '../../types/index.js'\nimport type { TypeWithVersion } from '../../versions/types.js'\nimport type { SanitizedGlobalConfig } from '../config/types.js'\n\nimport { executeAccess } from '../../auth/executeAccess.js'\nimport { combineQueries } from '../../database/combineQueries.js'\nimport { Forbidden, NotFound } from '../../errors/index.js'\nimport { afterRead } from '../../fields/hooks/afterRead/index.js'\nimport { deepCopyObjectSimple } from '../../utilities/deepCopyObject.js'\nimport { killTransaction } from '../../utilities/killTransaction.js'\nimport { sanitizeSelect } from '../../utilities/sanitizeSelect.js'\nimport { buildVersionGlobalFields } from '../../versions/buildGlobalFields.js'\nimport { getQueryDraftsSelect } from '../../versions/drafts/getQueryDraftsSelect.js'\n\nexport type Arguments = {\n currentDepth?: number\n depth?: number\n disableErrors?: boolean\n globalConfig: SanitizedGlobalConfig\n id: number | string\n overrideAccess?: boolean\n populate?: PopulateType\n req: PayloadRequest\n showHiddenFields?: boolean\n} & Pick<FindOptions<string, SelectType>, 'select'>\n\nexport const findVersionByIDOperation = async <T extends TypeWithVersion<T> = any>(\n args: Arguments,\n): Promise<T> => {\n const {\n id,\n currentDepth,\n depth,\n disableErrors,\n globalConfig,\n overrideAccess,\n populate,\n req: { fallbackLocale, locale, payload },\n req,\n select: incomingSelect,\n showHiddenFields,\n } = args\n\n try {\n // /////////////////////////////////////\n // Access\n // /////////////////////////////////////\n\n const accessResults = !overrideAccess\n ? await executeAccess({ id, disableErrors, req }, globalConfig.access.readVersions)\n : true\n\n // If errors are disabled, and access returns false, return null\n if (accessResults === false) {\n return null!\n }\n\n const isValidID =\n (typeof id === 'string' && id.length > 0) || (typeof id === 'number' && Number.isFinite(id))\n\n if (!isValidID) {\n throw new NotFound(req.t)\n }\n\n const hasWhereAccess = typeof accessResults === 'object'\n\n const select = sanitizeSelect({\n fields: buildVersionGlobalFields(payload.config, globalConfig, true),\n forceSelect: getQueryDraftsSelect({ select: globalConfig.forceSelect }),\n select: incomingSelect,\n versions: true,\n })\n\n const findGlobalVersionsArgs: FindGlobalVersionsArgs = {\n global: globalConfig.slug,\n limit: 1,\n locale: locale!,\n req,\n select,\n where: combineQueries({ id: { equals: id } }, accessResults),\n }\n\n // /////////////////////////////////////\n // Find by ID\n // /////////////////////////////////////\n\n const { docs: results } = await payload.db.findGlobalVersions(findGlobalVersionsArgs)\n if (!results || results?.length === 0) {\n if (!disableErrors) {\n if (!hasWhereAccess) {\n throw new NotFound(req.t)\n }\n if (hasWhereAccess) {\n throw new Forbidden(req.t)\n }\n }\n\n return null!\n }\n\n // Clone the result - it may have come back memoized\n let result: any = deepCopyObjectSimple(results[0])\n\n if (!result.version) {\n result.version = {}\n }\n\n // Patch globalType onto version doc\n result.version.globalType = globalConfig.slug\n\n // /////////////////////////////////////\n // beforeRead - Collection\n // /////////////////////////////////////\n\n if (globalConfig.hooks?.beforeRead?.length) {\n for (const hook of globalConfig.hooks.beforeRead) {\n result =\n (await hook({\n context: req.context,\n doc: result.version,\n global: globalConfig,\n overrideAccess,\n req,\n })) || result.version\n }\n }\n\n // /////////////////////////////////////\n // afterRead - Fields\n // /////////////////////////////////////\n\n result.version = await afterRead({\n collection: null,\n context: req.context,\n currentDepth,\n depth: depth!,\n doc: result.version,\n draft: undefined!,\n fallbackLocale: fallbackLocale!,\n global: globalConfig,\n locale: locale!,\n overrideAccess: overrideAccess!,\n populate,\n req,\n select: typeof select?.version === 'object' ? select.version : undefined,\n showHiddenFields: showHiddenFields!,\n })\n\n // /////////////////////////////////////\n // afterRead - Global\n // /////////////////////////////////////\n\n if (globalConfig.hooks?.afterRead?.length) {\n for (const hook of globalConfig.hooks.afterRead) {\n result.version =\n (await hook({\n context: req.context,\n doc: result.version,\n global: globalConfig,\n overrideAccess,\n query: findGlobalVersionsArgs.where,\n req,\n })) || result.version\n }\n }\n\n return result\n } catch (error: unknown) {\n await killTransaction(req)\n throw error\n }\n}\n"],"names":["executeAccess","combineQueries","Forbidden","NotFound","afterRead","deepCopyObjectSimple","killTransaction","sanitizeSelect","buildVersionGlobalFields","getQueryDraftsSelect","findVersionByIDOperation","args","id","currentDepth","depth","disableErrors","globalConfig","overrideAccess","populate","req","fallbackLocale","locale","payload","select","incomingSelect","showHiddenFields","accessResults","access","readVersions","isValidID","length","Number","isFinite","
|
|
1
|
+
{"version":3,"sources":["../../../src/globals/operations/findVersionByID.ts"],"sourcesContent":["import type { FindOptions } from '../../collections/operations/local/find.js'\nimport type { FindGlobalVersionsArgs } from '../../database/types.js'\nimport type { PayloadRequest, PopulateType, SelectType } from '../../types/index.js'\nimport type { TypeWithVersion } from '../../versions/types.js'\nimport type { SanitizedGlobalConfig } from '../config/types.js'\n\nimport { executeAccess } from '../../auth/executeAccess.js'\nimport { combineQueries } from '../../database/combineQueries.js'\nimport { Forbidden, NotFound } from '../../errors/index.js'\nimport { afterRead } from '../../fields/hooks/afterRead/index.js'\nimport { deepCopyObjectSimple } from '../../utilities/deepCopyObject.js'\nimport { hasVersionsEnabled } from '../../utilities/getVersionsConfig.js'\nimport { killTransaction } from '../../utilities/killTransaction.js'\nimport { sanitizeSelect } from '../../utilities/sanitizeSelect.js'\nimport { buildVersionGlobalFields } from '../../versions/buildGlobalFields.js'\nimport { getQueryDraftsSelect } from '../../versions/drafts/getQueryDraftsSelect.js'\n\nexport type Arguments = {\n currentDepth?: number\n depth?: number\n disableErrors?: boolean\n globalConfig: SanitizedGlobalConfig\n id: number | string\n overrideAccess?: boolean\n populate?: PopulateType\n req: PayloadRequest\n showHiddenFields?: boolean\n} & Pick<FindOptions<string, SelectType>, 'select'>\n\nexport const findVersionByIDOperation = async <T extends TypeWithVersion<T> = any>(\n args: Arguments,\n): Promise<T> => {\n const {\n id,\n currentDepth,\n depth,\n disableErrors,\n globalConfig,\n overrideAccess,\n populate,\n req: { fallbackLocale, locale, payload },\n req,\n select: incomingSelect,\n showHiddenFields,\n } = args\n\n if (!hasVersionsEnabled(globalConfig)) {\n if (disableErrors) {\n return null!\n }\n\n throw new NotFound(req.t)\n }\n\n try {\n // /////////////////////////////////////\n // Access\n // /////////////////////////////////////\n\n const accessResults = !overrideAccess\n ? await executeAccess({ id, disableErrors, req }, globalConfig.access.readVersions)\n : true\n\n // If errors are disabled, and access returns false, return null\n if (accessResults === false) {\n return null!\n }\n\n const isValidID =\n (typeof id === 'string' && id.length > 0) || (typeof id === 'number' && Number.isFinite(id))\n\n if (!isValidID) {\n throw new NotFound(req.t)\n }\n\n const hasWhereAccess = typeof accessResults === 'object'\n\n const select = sanitizeSelect({\n fields: buildVersionGlobalFields(payload.config, globalConfig, true),\n forceSelect: getQueryDraftsSelect({ select: globalConfig.forceSelect }),\n select: incomingSelect,\n versions: true,\n })\n\n const findGlobalVersionsArgs: FindGlobalVersionsArgs = {\n global: globalConfig.slug,\n limit: 1,\n locale: locale!,\n req,\n select,\n where: combineQueries({ id: { equals: id } }, accessResults),\n }\n\n // /////////////////////////////////////\n // Find by ID\n // /////////////////////////////////////\n\n const { docs: results } = await payload.db.findGlobalVersions(findGlobalVersionsArgs)\n if (!results || results?.length === 0) {\n if (!disableErrors) {\n if (!hasWhereAccess) {\n throw new NotFound(req.t)\n }\n if (hasWhereAccess) {\n throw new Forbidden(req.t)\n }\n }\n\n return null!\n }\n\n // Clone the result - it may have come back memoized\n let result: any = deepCopyObjectSimple(results[0])\n\n if (!result.version) {\n result.version = {}\n }\n\n // Patch globalType onto version doc\n result.version.globalType = globalConfig.slug\n\n // /////////////////////////////////////\n // beforeRead - Collection\n // /////////////////////////////////////\n\n if (globalConfig.hooks?.beforeRead?.length) {\n for (const hook of globalConfig.hooks.beforeRead) {\n result =\n (await hook({\n context: req.context,\n doc: result.version,\n global: globalConfig,\n overrideAccess,\n req,\n })) || result.version\n }\n }\n\n // /////////////////////////////////////\n // afterRead - Fields\n // /////////////////////////////////////\n\n result.version = await afterRead({\n collection: null,\n context: req.context,\n currentDepth,\n depth: depth!,\n doc: result.version,\n draft: undefined!,\n fallbackLocale: fallbackLocale!,\n global: globalConfig,\n locale: locale!,\n overrideAccess: overrideAccess!,\n populate,\n req,\n select: typeof select?.version === 'object' ? select.version : undefined,\n showHiddenFields: showHiddenFields!,\n })\n\n // /////////////////////////////////////\n // afterRead - Global\n // /////////////////////////////////////\n\n if (globalConfig.hooks?.afterRead?.length) {\n for (const hook of globalConfig.hooks.afterRead) {\n result.version =\n (await hook({\n context: req.context,\n doc: result.version,\n global: globalConfig,\n overrideAccess,\n query: findGlobalVersionsArgs.where,\n req,\n })) || result.version\n }\n }\n\n return result\n } catch (error: unknown) {\n await killTransaction(req)\n throw error\n }\n}\n"],"names":["executeAccess","combineQueries","Forbidden","NotFound","afterRead","deepCopyObjectSimple","hasVersionsEnabled","killTransaction","sanitizeSelect","buildVersionGlobalFields","getQueryDraftsSelect","findVersionByIDOperation","args","id","currentDepth","depth","disableErrors","globalConfig","overrideAccess","populate","req","fallbackLocale","locale","payload","select","incomingSelect","showHiddenFields","t","accessResults","access","readVersions","isValidID","length","Number","isFinite","hasWhereAccess","fields","config","forceSelect","versions","findGlobalVersionsArgs","global","slug","limit","where","equals","docs","results","db","findGlobalVersions","result","version","globalType","hooks","beforeRead","hook","context","doc","collection","draft","undefined","query","error"],"mappings":"AAMA,SAASA,aAAa,QAAQ,8BAA6B;AAC3D,SAASC,cAAc,QAAQ,mCAAkC;AACjE,SAASC,SAAS,EAAEC,QA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C,IAAIoC,OAAO;YACpB1C;YACAC,OAAOA;YACP0C,KAAKP,OAAOC,OAAO;YACnBQ,OAAOC;YACPvC,gBAAgBA;YAChBoB,QAAQxB;YACRK,QAAQA;YACRJ,gBAAgBA;YAChBC;YACAC;YACAI,QAAQ,OAAOA,QAAQ2B,YAAY,WAAW3B,OAAO2B,OAAO,GAAGS;YAC/DlC,kBAAkBA;QACpB;QAEA,wCAAwC;QACxC,qBAAqB;QACrB,wCAAwC;QAExC,IAAIT,aAAaoC,KAAK,EAAEjD,WAAW4B,QAAQ;YACzC,KAAK,MAAMuB,QAAQtC,aAAaoC,KAAK,CAACjD,SAAS,CAAE;gBAC/C8C,OAAOC,OAAO,GACZ,AAAC,MAAMI,KAAK;oBACVC,SAASpC,IAAIoC,OAAO;oBACpBC,KAAKP,OAAOC,OAAO;oBACnBV,QAAQxB;oBACRC;oBACA2C,OAAOrB,uBAAuBI,KAAK;oBACnCxB;gBACF,MAAO8B,OAAOC,OAAO;YACzB;QACF;QAEA,OAAOD;IACT,EAAE,OAAOY,OAAgB;QACvB,MAAMvD,gBAAgBa;QACtB,MAAM0C;IACR;AACF,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"findVersions.d.ts","sourceRoot":"","sources":["../../../src/globals/operations/findVersions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4CAA4C,CAAA;AAC7E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAA;AAC5D,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,UAAU,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAA;AACjG,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;AAC9D,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAA;
|
|
1
|
+
{"version":3,"file":"findVersions.d.ts","sourceRoot":"","sources":["../../../src/globals/operations/findVersions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4CAA4C,CAAA;AAC7E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAA;AAC5D,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,UAAU,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAA;AACjG,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;AAC9D,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAA;AAe/D,MAAM,MAAM,SAAS,GAAG;IACtB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,YAAY,EAAE,qBAAqB,CAAA;IACnC,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,QAAQ,CAAC,EAAE,YAAY,CAAA;IACvB,GAAG,CAAC,EAAE,cAAc,CAAA;IACpB,gBAAgB,CAAC,EAAE,OAAO,CAAA;IAC1B,IAAI,CAAC,EAAE,IAAI,CAAA;IACX,KAAK,CAAC,EAAE,KAAK,CAAA;CACd,GAAG,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE,UAAU,CAAC,EAAE,QAAQ,CAAC,CAAA;AAEnD,eAAO,MAAM,qBAAqB,GAAU,CAAC,SAAS,eAAe,CAAC,CAAC,CAAC,QAChE,SAAS,KACd,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,CA6J1B,CAAA"}
|
|
@@ -2,7 +2,9 @@ import { executeAccess } from '../../auth/executeAccess.js';
|
|
|
2
2
|
import { combineQueries } from '../../database/combineQueries.js';
|
|
3
3
|
import { validateQueryPaths } from '../../database/queryValidation/validateQueryPaths.js';
|
|
4
4
|
import { validateSortQuery } from '../../database/queryValidation/validateSortQuery.js';
|
|
5
|
+
import { NotFound } from '../../errors/index.js';
|
|
5
6
|
import { afterRead } from '../../fields/hooks/afterRead/index.js';
|
|
7
|
+
import { hasVersionsEnabled } from '../../utilities/getVersionsConfig.js';
|
|
6
8
|
import { killTransaction } from '../../utilities/killTransaction.js';
|
|
7
9
|
import { sanitizeInternalFields } from '../../utilities/sanitizeInternalFields.js';
|
|
8
10
|
import { sanitizeSelect } from '../../utilities/sanitizeSelect.js';
|
|
@@ -12,6 +14,9 @@ export const findVersionsOperation = async (args)=>{
|
|
|
12
14
|
const { depth, globalConfig, limit, overrideAccess, page, pagination = true, populate, select: incomingSelect, showHiddenFields, sort, where } = args;
|
|
13
15
|
const req = args.req;
|
|
14
16
|
const { fallbackLocale, locale, payload } = req;
|
|
17
|
+
if (!hasVersionsEnabled(globalConfig)) {
|
|
18
|
+
throw new NotFound(req.t);
|
|
19
|
+
}
|
|
15
20
|
const versionFields = buildVersionGlobalFields(payload.config, globalConfig, true);
|
|
16
21
|
try {
|
|
17
22
|
// /////////////////////////////////////
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/globals/operations/findVersions.ts"],"sourcesContent":["import type { FindOptions } from '../../collections/operations/local/find.js'\nimport type { PaginatedDocs } from '../../database/types.js'\nimport type { PayloadRequest, PopulateType, SelectType, Sort, Where } from '../../types/index.js'\nimport type { TypeWithVersion } from '../../versions/types.js'\nimport type { SanitizedGlobalConfig } from '../config/types.js'\n\nimport { executeAccess } from '../../auth/executeAccess.js'\nimport { combineQueries } from '../../database/combineQueries.js'\nimport { validateQueryPaths } from '../../database/queryValidation/validateQueryPaths.js'\nimport { validateSortQuery } from '../../database/queryValidation/validateSortQuery.js'\nimport { afterRead } from '../../fields/hooks/afterRead/index.js'\nimport { killTransaction } from '../../utilities/killTransaction.js'\nimport { sanitizeInternalFields } from '../../utilities/sanitizeInternalFields.js'\nimport { sanitizeSelect } from '../../utilities/sanitizeSelect.js'\nimport { buildVersionGlobalFields } from '../../versions/buildGlobalFields.js'\nimport { getQueryDraftsSelect } from '../../versions/drafts/getQueryDraftsSelect.js'\n\nexport type Arguments = {\n depth?: number\n globalConfig: SanitizedGlobalConfig\n limit?: number\n overrideAccess?: boolean\n page?: number\n pagination?: boolean\n populate?: PopulateType\n req?: PayloadRequest\n showHiddenFields?: boolean\n sort?: Sort\n where?: Where\n} & Pick<FindOptions<string, SelectType>, 'select'>\n\nexport const findVersionsOperation = async <T extends TypeWithVersion<T>>(\n args: Arguments,\n): Promise<PaginatedDocs<T>> => {\n const {\n depth,\n globalConfig,\n limit,\n overrideAccess,\n page,\n pagination = true,\n populate,\n select: incomingSelect,\n showHiddenFields,\n sort,\n where,\n } = args\n const req = args.req!\n const { fallbackLocale, locale, payload } = req\n\n const versionFields = buildVersionGlobalFields(payload.config, globalConfig, true)\n\n try {\n // /////////////////////////////////////\n // Access\n // /////////////////////////////////////\n\n const accessResults = !overrideAccess\n ? await executeAccess({ req }, globalConfig.access.readVersions)\n : true\n\n await validateQueryPaths({\n globalConfig,\n overrideAccess: overrideAccess!,\n req,\n versionFields,\n where: where!,\n })\n\n await validateSortQuery({\n globalConfig,\n overrideAccess: overrideAccess!,\n req,\n sort,\n versionFields,\n })\n\n const fullWhere = combineQueries(where!, accessResults)\n\n const select = sanitizeSelect({\n fields: buildVersionGlobalFields(payload.config, globalConfig, true),\n forceSelect: getQueryDraftsSelect({ select: globalConfig.forceSelect }),\n select: incomingSelect,\n versions: true,\n })\n\n // /////////////////////////////////////\n // Find\n // /////////////////////////////////////\n\n const usePagination = pagination && limit !== 0\n const sanitizedLimit = limit ?? (usePagination ? 10 : 0)\n const sanitizedPage = page || 1\n\n const paginatedDocs = await payload.db.findGlobalVersions<T>({\n global: globalConfig.slug,\n limit: sanitizedLimit,\n locale: locale!,\n page: sanitizedPage,\n pagination,\n req,\n select,\n sort,\n where: fullWhere,\n })\n\n // /////////////////////////////////////\n // afterRead - Fields\n // /////////////////////////////////////\n\n let result = {\n ...paginatedDocs,\n docs: await Promise.all(\n paginatedDocs.docs.map(async (data) => {\n if (!data.version) {\n // Fallback if not selected\n ;(data as any).version = {}\n }\n return {\n ...data,\n version: await afterRead<T>({\n collection: null,\n context: req.context,\n depth: depth!,\n doc: {\n ...data.version,\n // Patch globalType onto version doc\n globalType: globalConfig.slug,\n },\n draft: undefined!,\n fallbackLocale: fallbackLocale!,\n findMany: true,\n global: globalConfig,\n locale: locale!,\n overrideAccess: overrideAccess!,\n populate,\n req,\n select,\n showHiddenFields: showHiddenFields!,\n }),\n }\n }),\n ),\n } as PaginatedDocs<T>\n\n // /////////////////////////////////////\n // afterRead - Global\n // /////////////////////////////////////\n\n if (globalConfig.hooks?.afterRead?.length) {\n result.docs = await Promise.all(\n result.docs.map(async (doc) => {\n const docRef = doc\n\n for (const hook of globalConfig.hooks.afterRead) {\n docRef.version =\n (await hook({\n context: req.context,\n doc: doc.version,\n findMany: true,\n global: globalConfig,\n overrideAccess,\n query: fullWhere,\n req,\n })) || doc.version\n }\n\n return docRef\n }),\n )\n }\n\n // /////////////////////////////////////\n // Return results\n // /////////////////////////////////////\n\n result = {\n ...result,\n docs: result.docs.map((doc) => sanitizeInternalFields<T>(doc)),\n }\n\n return result\n } catch (error: unknown) {\n await killTransaction(req)\n throw error\n }\n}\n"],"names":["executeAccess","combineQueries","validateQueryPaths","validateSortQuery","afterRead","killTransaction","sanitizeInternalFields","sanitizeSelect","buildVersionGlobalFields","getQueryDraftsSelect","findVersionsOperation","args","depth","globalConfig","limit","overrideAccess","page","pagination","populate","select","incomingSelect","showHiddenFields","sort","where","req","fallbackLocale","locale","payload","versionFields","config","accessResults","access","readVersions","fullWhere","fields","forceSelect","versions","usePagination","sanitizedLimit","sanitizedPage","paginatedDocs","db","findGlobalVersions","global","slug","result","docs","Promise","all","map","data","version","collection","context","doc","globalType","draft","undefined","findMany","hooks","length","docRef","hook","query","error"],"mappings":"AAMA,SAASA,aAAa,QAAQ,8BAA6B;AAC3D,SAASC,cAAc,QAAQ,mCAAkC;AACjE,SAASC,kBAAkB,QAAQ,uDAAsD;AACzF,SAASC,iBAAiB,QAAQ,sDAAqD;AACvF,SAASC,SAAS,QAAQ,wCAAuC;AACjE,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,sBAAsB,QAAQ,4CAA2C;AAClF,SAASC,cAAc,QAAQ,oCAAmC;AAClE,SAASC,wBAAwB,QAAQ,sCAAqC;AAC9E,SAASC,oBAAoB,QAAQ,gDAA+C;AAgBpF,OAAO,MAAMC,wBAAwB,OACnCC;IAEA,MAAM,EACJC,KAAK,EACLC,YAAY,EACZC,KAAK,EACLC,cAAc,EACdC,IAAI,EACJC,aAAa,IAAI,EACjBC,QAAQ,EACRC,QAAQC,cAAc,EACtBC,gBAAgB,EAChBC,IAAI,EACJC,KAAK,EACN,GAAGZ;IACJ,MAAMa,MAAMb,KAAKa,GAAG;IACpB,MAAM,EAAEC,cAAc,EAAEC,MAAM,EAAEC,OAAO,EAAE,GAAGH;IAE5C,
|
|
1
|
+
{"version":3,"sources":["../../../src/globals/operations/findVersions.ts"],"sourcesContent":["import type { FindOptions } from '../../collections/operations/local/find.js'\nimport type { PaginatedDocs } from '../../database/types.js'\nimport type { PayloadRequest, PopulateType, SelectType, Sort, Where } from '../../types/index.js'\nimport type { TypeWithVersion } from '../../versions/types.js'\nimport type { SanitizedGlobalConfig } from '../config/types.js'\n\nimport { executeAccess } from '../../auth/executeAccess.js'\nimport { combineQueries } from '../../database/combineQueries.js'\nimport { validateQueryPaths } from '../../database/queryValidation/validateQueryPaths.js'\nimport { validateSortQuery } from '../../database/queryValidation/validateSortQuery.js'\nimport { NotFound } from '../../errors/index.js'\nimport { afterRead } from '../../fields/hooks/afterRead/index.js'\nimport { hasVersionsEnabled } from '../../utilities/getVersionsConfig.js'\nimport { killTransaction } from '../../utilities/killTransaction.js'\nimport { sanitizeInternalFields } from '../../utilities/sanitizeInternalFields.js'\nimport { sanitizeSelect } from '../../utilities/sanitizeSelect.js'\nimport { buildVersionGlobalFields } from '../../versions/buildGlobalFields.js'\nimport { getQueryDraftsSelect } from '../../versions/drafts/getQueryDraftsSelect.js'\n\nexport type Arguments = {\n depth?: number\n globalConfig: SanitizedGlobalConfig\n limit?: number\n overrideAccess?: boolean\n page?: number\n pagination?: boolean\n populate?: PopulateType\n req?: PayloadRequest\n showHiddenFields?: boolean\n sort?: Sort\n where?: Where\n} & Pick<FindOptions<string, SelectType>, 'select'>\n\nexport const findVersionsOperation = async <T extends TypeWithVersion<T>>(\n args: Arguments,\n): Promise<PaginatedDocs<T>> => {\n const {\n depth,\n globalConfig,\n limit,\n overrideAccess,\n page,\n pagination = true,\n populate,\n select: incomingSelect,\n showHiddenFields,\n sort,\n where,\n } = args\n const req = args.req!\n const { fallbackLocale, locale, payload } = req\n\n if (!hasVersionsEnabled(globalConfig)) {\n throw new NotFound(req.t)\n }\n\n const versionFields = buildVersionGlobalFields(payload.config, globalConfig, true)\n\n try {\n // /////////////////////////////////////\n // Access\n // /////////////////////////////////////\n\n const accessResults = !overrideAccess\n ? await executeAccess({ req }, globalConfig.access.readVersions)\n : true\n\n await validateQueryPaths({\n globalConfig,\n overrideAccess: overrideAccess!,\n req,\n versionFields,\n where: where!,\n })\n\n await validateSortQuery({\n globalConfig,\n overrideAccess: overrideAccess!,\n req,\n sort,\n versionFields,\n })\n\n const fullWhere = combineQueries(where!, accessResults)\n\n const select = sanitizeSelect({\n fields: buildVersionGlobalFields(payload.config, globalConfig, true),\n forceSelect: getQueryDraftsSelect({ select: globalConfig.forceSelect }),\n select: incomingSelect,\n versions: true,\n })\n\n // /////////////////////////////////////\n // Find\n // /////////////////////////////////////\n\n const usePagination = pagination && limit !== 0\n const sanitizedLimit = limit ?? (usePagination ? 10 : 0)\n const sanitizedPage = page || 1\n\n const paginatedDocs = await payload.db.findGlobalVersions<T>({\n global: globalConfig.slug,\n limit: sanitizedLimit,\n locale: locale!,\n page: sanitizedPage,\n pagination,\n req,\n select,\n sort,\n where: fullWhere,\n })\n\n // /////////////////////////////////////\n // afterRead - Fields\n // /////////////////////////////////////\n\n let result = {\n ...paginatedDocs,\n docs: await Promise.all(\n paginatedDocs.docs.map(async (data) => {\n if (!data.version) {\n // Fallback if not selected\n ;(data as any).version = {}\n }\n return {\n ...data,\n version: await afterRead<T>({\n collection: null,\n context: req.context,\n depth: depth!,\n doc: {\n ...data.version,\n // Patch globalType onto version doc\n globalType: globalConfig.slug,\n },\n draft: undefined!,\n fallbackLocale: fallbackLocale!,\n findMany: true,\n global: globalConfig,\n locale: locale!,\n overrideAccess: overrideAccess!,\n populate,\n req,\n select,\n showHiddenFields: showHiddenFields!,\n }),\n }\n }),\n ),\n } as PaginatedDocs<T>\n\n // /////////////////////////////////////\n // afterRead - Global\n // /////////////////////////////////////\n\n if (globalConfig.hooks?.afterRead?.length) {\n result.docs = await Promise.all(\n result.docs.map(async (doc) => {\n const docRef = doc\n\n for (const hook of globalConfig.hooks.afterRead) {\n docRef.version =\n (await hook({\n context: req.context,\n doc: doc.version,\n findMany: true,\n global: globalConfig,\n overrideAccess,\n query: fullWhere,\n req,\n })) || doc.version\n }\n\n return docRef\n }),\n )\n }\n\n // /////////////////////////////////////\n // Return results\n // /////////////////////////////////////\n\n result = {\n ...result,\n docs: result.docs.map((doc) => sanitizeInternalFields<T>(doc)),\n }\n\n return result\n } catch (error: unknown) {\n await killTransaction(req)\n throw error\n }\n}\n"],"names":["executeAccess","combineQueries","validateQueryPaths","validateSortQuery","NotFound","afterRead","hasVersionsEnabled","killTransaction","sanitizeInternalFields","sanitizeSelect","buildVersionGlobalFields","getQueryDraftsSelect","findVersionsOperation","args","depth","globalConfig","limit","overrideAccess","page","pagination","populate","select","incomingSelect","showHiddenFields","sort","where","req","fallbackLocale","locale","payload","t","versionFields","config","accessResults","access","readVersions","fullWhere","fields","forceSelect","versions","usePagination","sanitizedLimit","sanitizedPage","paginatedDocs","db","findGlobalVersions","global","slug","result","docs","Promise","all","map","data","version","collection","context","doc","globalType","draft","undefined","findMany","hooks","length","docRef","hook","query","error"],"mappings":"AAMA,SAASA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D,WAAW0D,QAAQ;YACzCf,OAAOC,IAAI,GAAG,MAAMC,QAAQC,GAAG,CAC7BH,OAAOC,IAAI,CAACG,GAAG,CAAC,OAAOK;gBACrB,MAAMO,SAASP;gBAEf,KAAK,MAAMQ,QAAQlD,aAAa+C,KAAK,CAACzD,SAAS,CAAE;oBAC/C2D,OAAOV,OAAO,GACZ,AAAC,MAAMW,KAAK;wBACVT,SAAS9B,IAAI8B,OAAO;wBACpBC,KAAKA,IAAIH,OAAO;wBAChBO,UAAU;wBACVf,QAAQ/B;wBACRE;wBACAiD,OAAO9B;wBACPV;oBACF,MAAO+B,IAAIH,OAAO;gBACtB;gBAEA,OAAOU;YACT;QAEJ;QAEA,wCAAwC;QACxC,iBAAiB;QACjB,wCAAwC;QAExChB,SAAS;YACP,GAAGA,MAAM;YACTC,MAAMD,OAAOC,IAAI,CAACG,GAAG,CAAC,CAACK,MAAQjD,uBAA0BiD;QAC3D;QAEA,OAAOT;IACT,EAAE,OAAOmB,OAAgB;QACvB,MAAM5D,gBAAgBmB;QACtB,MAAMyC;IACR;AACF,EAAC"}
|
package/dist/index.bundled.d.ts
CHANGED
|
@@ -743,6 +743,10 @@ declare class ExtendableError<TData extends object = {
|
|
|
743
743
|
}
|
|
744
744
|
/**
|
|
745
745
|
* Class representing an API error.
|
|
746
|
+
*
|
|
747
|
+
* Every error class sets `this.name` explicitly rather than reading `this.constructor.name`, as
|
|
748
|
+
* minifiers rename classes and can inline them as anonymous class expressions, which would leave
|
|
749
|
+
* `name` mangled or empty in production builds. Subclasses should do the same.
|
|
746
750
|
* @extends ExtendableError
|
|
747
751
|
*/
|
|
748
752
|
declare class APIError<TData extends null | object = {
|
|
@@ -12862,6 +12866,7 @@ type Args$b = {
|
|
|
12862
12866
|
* Data of the nearest parent block. If no parent block exists, this will be the `undefined`
|
|
12863
12867
|
*/
|
|
12864
12868
|
blockData?: JsonObject;
|
|
12869
|
+
blockFields?: Field[];
|
|
12865
12870
|
collection: null | SanitizedCollectionConfig;
|
|
12866
12871
|
context: RequestContext;
|
|
12867
12872
|
data: JsonObject;
|
|
@@ -12914,7 +12919,7 @@ type Args$b = {
|
|
|
12914
12919
|
* - Transform data for storage
|
|
12915
12920
|
* - Unflatten locales. The input `data` is the normal document for one locale. The output result will become the document with locales.
|
|
12916
12921
|
*/
|
|
12917
|
-
declare const traverseFields$2: ({ id, blockData, collection, context, data, doc, docWithLocales, errors, fieldLabelPath, fields, global, mergeLocaleActions, operation, overrideAccess, parentIndexPath, parentIsLocalized, parentPath, parentSchemaPath, req, siblingData, siblingDoc, siblingDocWithLocales, skipValidation, submittedTopLevelFieldNames, }: Args$b) => Promise<void>;
|
|
12922
|
+
declare const traverseFields$2: ({ id, blockData, blockFields, collection, context, data, doc, docWithLocales, errors, fieldLabelPath, fields, global, mergeLocaleActions, operation, overrideAccess, parentIndexPath, parentIsLocalized, parentPath, parentSchemaPath, req, siblingData, siblingDoc, siblingDocWithLocales, skipValidation, submittedTopLevelFieldNames, }: Args$b) => Promise<void>;
|
|
12918
12923
|
|
|
12919
12924
|
type Args$a<T> = {
|
|
12920
12925
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"updateJob.d.ts","sourceRoot":"","sources":["../../../src/queues/utilities/updateJob.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,GAAG,
|
|
1
|
+
{"version":3,"file":"updateJob.d.ts","sourceRoot":"","sources":["../../../src/queues/utilities/updateJob.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,GAAG,EAAU,MAAM,gBAAgB,CAAA;AACjD,OAAO,KAAK,EAAE,cAAc,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAA;AAKvE,KAAK,QAAQ,GAAG;IACd,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,CAAA;IAClB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,kBAAkB,CAAC,EAAE,OAAO,CAAA;IAC5B,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,GAAG,EAAE,cAAc,CAAA;IACnB,SAAS,CAAC,EAAE,OAAO,CAAA;CACpB,CAAA;AAED,KAAK,QAAQ,GAAG;IACd,EAAE,EAAE,MAAM,GAAG,MAAM,CAAA;IACnB,KAAK,CAAC,EAAE,KAAK,CAAA;IACb,IAAI,CAAC,EAAE,KAAK,CAAA;IACZ,KAAK,CAAC,EAAE,KAAK,CAAA;CACd,CAAA;AAED,KAAK,SAAS,GAAG;IACf,EAAE,CAAC,EAAE,KAAK,CAAA;IACV,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,IAAI,CAAC,EAAE,IAAI,CAAA;IACX,KAAK,EAAE,KAAK,CAAA;CACb,CAAA;AAED,KAAK,WAAW,GAAG,CAAC,QAAQ,GAAG,SAAS,CAAC,GAAG,QAAQ,CAAA;AAEpD;;GAEG;AACH,wBAAsB,SAAS,CAAC,IAAI,EAAE,QAAQ,GAAG,QAAQ,4BAKxD;AAED;;;;GAIG;AACH,wBAAsB,UAAU,CAAC,EAC/B,EAAE,EACF,IAAI,EACJ,KAAK,EACL,kBAAkB,EAClB,KAAK,EAAE,QAAQ,EACf,GAAG,EACH,SAAS,EACT,IAAI,EACJ,KAAK,EAAE,QAAQ,GAChB,EAAE,WAAW,GAAG,OAAO,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CA4ErC"}
|
|
@@ -20,6 +20,21 @@ import { getCurrentDate } from './getCurrentDate.js';
|
|
|
20
20
|
}
|
|
21
21
|
} : whereArg;
|
|
22
22
|
if (depth || req.payload.config?.jobs?.runHooks) {
|
|
23
|
+
if (id && data.log && '$push' in data.log) {
|
|
24
|
+
const job = await req.payload.findByID({
|
|
25
|
+
id,
|
|
26
|
+
collection: jobsCollectionSlug,
|
|
27
|
+
depth: 0,
|
|
28
|
+
req
|
|
29
|
+
});
|
|
30
|
+
data = {
|
|
31
|
+
...data,
|
|
32
|
+
log: [
|
|
33
|
+
...job.log ?? [],
|
|
34
|
+
data.log.$push
|
|
35
|
+
]
|
|
36
|
+
};
|
|
37
|
+
}
|
|
23
38
|
const result = await req.payload.update({
|
|
24
39
|
id,
|
|
25
40
|
collection: jobsCollectionSlug,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/queues/utilities/updateJob.ts"],"sourcesContent":["import type { ManyOptions } from '../../collections/operations/local/update.js'\nimport type { UpdateJobsArgs } from '../../database/types.js'\nimport type { Job } from '../../index.js'\nimport type { PayloadRequest, Sort, Where } from '../../types/index.js'\n\nimport { jobAfterRead, jobsCollectionSlug } from '../config/collection.js'\nimport { getCurrentDate } from './getCurrentDate.js'\n\ntype BaseArgs = {\n data: Partial<Job>\n depth?: number\n disableTransaction?: boolean\n limit?: number\n req: PayloadRequest\n returning?: boolean\n}\n\ntype ArgsByID = {\n id: number | string\n limit?: never\n sort?: never\n where?: never\n}\n\ntype ArgsWhere = {\n id?: never\n limit?: number\n sort?: Sort\n where: Where\n}\n\ntype RunJobsArgs = (ArgsByID | ArgsWhere) & BaseArgs\n\n/**\n * Convenience method for updateJobs by id\n */\nexport async function updateJob(args: ArgsByID & BaseArgs) {\n const result = await updateJobs(args)\n if (result) {\n return result[0]\n }\n}\n\n/**\n * Helper for updating jobs in the most performant way possible.\n * Handles deciding whether it can used direct db methods or not, and if so,\n * manually runs the afterRead hook that populates the `taskStatus` property.\n */\nexport async function updateJobs({\n id,\n data,\n depth,\n disableTransaction,\n limit: limitArg,\n req,\n returning,\n sort,\n where: whereArg,\n}: RunJobsArgs): Promise<Job[] | null> {\n const limit = id ? 1 : limitArg\n const where = id ? { id: { equals: id } } : whereArg\n\n if (depth || req.payload.config?.jobs?.runHooks) {\n const result = await req.payload.update({\n id,\n collection: jobsCollectionSlug,\n data,\n depth,\n disableTransaction,\n limit,\n req,\n where,\n } as ManyOptions<any, any>)\n if (returning === false || !result) {\n return null\n }\n return result.docs as Job[]\n }\n\n const jobReq = {\n transactionID:\n req.payload.db.name !== 'mongoose'\n ? ((await req.payload.db.beginTransaction()) as string)\n : undefined,\n }\n\n if (typeof data.updatedAt === 'undefined') {\n // Ensure updatedAt date is always updated\n data.updatedAt = getCurrentDate().toISOString()\n }\n\n const args: UpdateJobsArgs = id\n ? {\n id,\n data,\n req: jobReq,\n returning,\n }\n : {\n data,\n limit,\n req: jobReq,\n returning,\n sort,\n where: where as Where,\n }\n\n const updatedJobs: Job[] | null = await req.payload.db.updateJobs(args)\n\n if (req.payload.db.name !== 'mongoose' && jobReq.transactionID) {\n await req.payload.db.commitTransaction(jobReq.transactionID)\n }\n\n if (returning === false || !updatedJobs?.length) {\n return null\n }\n\n return updatedJobs.map((updatedJob) => {\n return jobAfterRead({\n config: req.payload.config,\n doc: updatedJob,\n })\n })\n}\n"],"names":["jobAfterRead","jobsCollectionSlug","getCurrentDate","updateJob","args","result","updateJobs","id","data","depth","disableTransaction","limit","limitArg","req","returning","sort","where","whereArg","equals","payload","config","jobs","runHooks","
|
|
1
|
+
{"version":3,"sources":["../../../src/queues/utilities/updateJob.ts"],"sourcesContent":["import type { ManyOptions } from '../../collections/operations/local/update.js'\nimport type { UpdateJobsArgs } from '../../database/types.js'\nimport type { Job, JobLog } from '../../index.js'\nimport type { PayloadRequest, Sort, Where } from '../../types/index.js'\n\nimport { jobAfterRead, jobsCollectionSlug } from '../config/collection.js'\nimport { getCurrentDate } from './getCurrentDate.js'\n\ntype BaseArgs = {\n data: Partial<Job>\n depth?: number\n disableTransaction?: boolean\n limit?: number\n req: PayloadRequest\n returning?: boolean\n}\n\ntype ArgsByID = {\n id: number | string\n limit?: never\n sort?: never\n where?: never\n}\n\ntype ArgsWhere = {\n id?: never\n limit?: number\n sort?: Sort\n where: Where\n}\n\ntype RunJobsArgs = (ArgsByID | ArgsWhere) & BaseArgs\n\n/**\n * Convenience method for updateJobs by id\n */\nexport async function updateJob(args: ArgsByID & BaseArgs) {\n const result = await updateJobs(args)\n if (result) {\n return result[0]\n }\n}\n\n/**\n * Helper for updating jobs in the most performant way possible.\n * Handles deciding whether it can used direct db methods or not, and if so,\n * manually runs the afterRead hook that populates the `taskStatus` property.\n */\nexport async function updateJobs({\n id,\n data,\n depth,\n disableTransaction,\n limit: limitArg,\n req,\n returning,\n sort,\n where: whereArg,\n}: RunJobsArgs): Promise<Job[] | null> {\n const limit = id ? 1 : limitArg\n const where = id ? { id: { equals: id } } : whereArg\n\n if (depth || req.payload.config?.jobs?.runHooks) {\n if (id && data.log && '$push' in data.log) {\n const job = await req.payload.findByID({\n id,\n collection: jobsCollectionSlug,\n depth: 0,\n req,\n })\n\n data = { ...data, log: [...(job.log ?? []), data.log.$push as JobLog] }\n }\n\n const result = await req.payload.update({\n id,\n collection: jobsCollectionSlug,\n data,\n depth,\n disableTransaction,\n limit,\n req,\n where,\n } as ManyOptions<any, any>)\n if (returning === false || !result) {\n return null\n }\n return result.docs as Job[]\n }\n\n const jobReq = {\n transactionID:\n req.payload.db.name !== 'mongoose'\n ? ((await req.payload.db.beginTransaction()) as string)\n : undefined,\n }\n\n if (typeof data.updatedAt === 'undefined') {\n // Ensure updatedAt date is always updated\n data.updatedAt = getCurrentDate().toISOString()\n }\n\n const args: UpdateJobsArgs = id\n ? {\n id,\n data,\n req: jobReq,\n returning,\n }\n : {\n data,\n limit,\n req: jobReq,\n returning,\n sort,\n where: where as Where,\n }\n\n const updatedJobs: Job[] | null = await req.payload.db.updateJobs(args)\n\n if (req.payload.db.name !== 'mongoose' && jobReq.transactionID) {\n await req.payload.db.commitTransaction(jobReq.transactionID)\n }\n\n if (returning === false || !updatedJobs?.length) {\n return null\n }\n\n return updatedJobs.map((updatedJob) => {\n return jobAfterRead({\n config: req.payload.config,\n doc: updatedJob,\n })\n })\n}\n"],"names":["jobAfterRead","jobsCollectionSlug","getCurrentDate","updateJob","args","result","updateJobs","id","data","depth","disableTransaction","limit","limitArg","req","returning","sort","where","whereArg","equals","payload","config","jobs","runHooks","log","job","findByID","collection","$push","update","docs","jobReq","transactionID","db","name","beginTransaction","undefined","updatedAt","toISOString","updatedJobs","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AO,CAACa,EAAE,CAACE,gBAAgB,KACvCC;IACR;IAEA,IAAI,OAAO3B,KAAK4B,SAAS,KAAK,aAAa;QACzC,0CAA0C;QAC1C5B,KAAK4B,SAAS,GAAGlC,iBAAiBmC,WAAW;IAC/C;IAEA,MAAMjC,OAAuBG,KACzB;QACEA;QACAC;QACAK,KAAKiB;QACLhB;IACF,IACA;QACEN;QACAG;QACAE,KAAKiB;QACLhB;QACAC;QACAC,OAAOA;IACT;IAEJ,MAAMsB,cAA4B,MAAMzB,IAAIM,OAAO,CAACa,EAAE,CAAC1B,UAAU,CAACF;IAElE,IAAIS,IAAIM,OAAO,CAACa,EAAE,CAACC,IAAI,KAAK,cAAcH,OAAOC,aAAa,EAAE;QAC9D,MAAMlB,IAAIM,OAAO,CAACa,EAAE,CAACO,iBAAiB,CAACT,OAAOC,aAAa;IAC7D;IAEA,IAAIjB,cAAc,SAAS,CAACwB,aAAaE,QAAQ;QAC/C,OAAO;IACT;IAEA,OAAOF,YAAYG,GAAG,CAAC,CAACC;QACtB,OAAO1C,aAAa;YAClBoB,QAAQP,IAAIM,OAAO,CAACC,MAAM;YAC1BuB,KAAKD;QACP;IACF;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getEntityPermissions.d.ts","sourceRoot":"","sources":["../../../src/utilities/getEntityPermissions/getEntityPermissions.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,gBAAgB,EAChB,oBAAoB,EAEpB,gBAAgB,EAEjB,MAAM,qBAAqB,CAAA;AAC5B,OAAO,KAAK,EAAE,yBAAyB,EAAE,UAAU,EAAE,MAAM,mCAAmC,CAAA;AAC9F,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAA;AAC1E,OAAO,KAAK,EAAE,SAAS,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAA;AACtE,OAAO,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,cAAc,EAAS,MAAM,sBAAsB,CAAA;AAO5F,MAAM,MAAM,0BAA0B,GAAG,MAAM,CAC7C,SAAS,EACT,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAC7C,CAAA;AAED,MAAM,MAAM,SAAS,GAAG,UAAU,GAAG,UAAU,CAAA;AAE/C,KAAK,UAAU,CAAC,WAAW,SAAS,YAAY,GAAG,QAAQ,IAAI,WAAW,SAAS,QAAQ,GACvF,gBAAgB,GAChB,oBAAoB,CAAA;AAExB,KAAK,IAAI,CAAC,WAAW,SAAS,YAAY,GAAG,QAAQ,IAAI;IACvD,0BAA0B,EAAE,0BAA0B,CAAA;IACtD;;OAEG;IACH,IAAI,CAAC,EAAE,UAAU,CAAA;IACjB,MAAM,EAAE,WAAW,SAAS,YAAY,GAAG,yBAAyB,GAAG,qBAAqB,CAAA;IAC5F,UAAU,EAAE,WAAW,CAAA;IACvB;;OAEG;IACH,UAAU,EAAE,aAAa,EAAE,CAAA;IAC3B,GAAG,EAAE,cAAc,CAAA;CACpB,GAAG,CACA;IACE,SAAS,EAAE,KAAK,CAAA;IAChB,EAAE,CAAC,EAAE,KAAK,CAAA;CACX,GACD;IACE,SAAS,EAAE,IAAI,CAAA;IACf,EAAE,EAAE,WAAW,SAAS,YAAY,GAAG,qBAAqB,GAAG,SAAS,CAAA;CACzE,CACJ,CAAA;AAYD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAsB,oBAAoB,CAAC,WAAW,SAAS,YAAY,GAAG,QAAQ,EACpF,IAAI,EAAE,IAAI,CAAC,WAAW,CAAC,GACtB,OAAO,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"getEntityPermissions.d.ts","sourceRoot":"","sources":["../../../src/utilities/getEntityPermissions/getEntityPermissions.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,gBAAgB,EAChB,oBAAoB,EAEpB,gBAAgB,EAEjB,MAAM,qBAAqB,CAAA;AAC5B,OAAO,KAAK,EAAE,yBAAyB,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