payload 3.0.0-beta.105 → 3.0.0-beta.106
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/collections/operations/duplicate.d.ts.map +1 -1
- package/dist/collections/operations/duplicate.js +10 -2
- package/dist/collections/operations/duplicate.js.map +1 -1
- package/dist/fields/baseFields/baseIDField.d.ts.map +1 -1
- package/dist/fields/baseFields/baseIDField.js +5 -0
- package/dist/fields/baseFields/baseIDField.js.map +1 -1
- package/dist/fields/config/sanitize.d.ts.map +1 -1
- package/dist/fields/config/sanitize.js +0 -19
- package/dist/fields/config/sanitize.js.map +1 -1
- package/dist/fields/hooks/beforeChange/index.d.ts +1 -3
- package/dist/fields/hooks/beforeChange/index.d.ts.map +1 -1
- package/dist/fields/hooks/beforeChange/index.js +1 -3
- package/dist/fields/hooks/beforeChange/index.js.map +1 -1
- package/dist/fields/hooks/beforeChange/promise.d.ts +1 -2
- package/dist/fields/hooks/beforeChange/promise.d.ts.map +1 -1
- package/dist/fields/hooks/beforeChange/promise.js +2 -18
- package/dist/fields/hooks/beforeChange/promise.js.map +1 -1
- package/dist/fields/hooks/beforeChange/traverseFields.d.ts +1 -2
- package/dist/fields/hooks/beforeChange/traverseFields.d.ts.map +1 -1
- package/dist/fields/hooks/beforeChange/traverseFields.js +1 -2
- package/dist/fields/hooks/beforeChange/traverseFields.js.map +1 -1
- package/dist/fields/hooks/beforeDuplicate/index.d.ts +19 -0
- package/dist/fields/hooks/beforeDuplicate/index.d.ts.map +1 -0
- package/dist/fields/hooks/beforeDuplicate/index.js +25 -0
- package/dist/fields/hooks/beforeDuplicate/index.js.map +1 -0
- package/dist/fields/hooks/beforeDuplicate/promise.d.ts +18 -0
- package/dist/fields/hooks/beforeDuplicate/promise.d.ts.map +1 -0
- package/dist/fields/hooks/beforeDuplicate/promise.js +299 -0
- package/dist/fields/hooks/beforeDuplicate/promise.js.map +1 -0
- package/dist/fields/hooks/beforeDuplicate/runHook.d.ts +3 -0
- package/dist/fields/hooks/beforeDuplicate/runHook.d.ts.map +1 -0
- package/dist/fields/hooks/beforeDuplicate/runHook.js +6 -0
- package/dist/fields/hooks/beforeDuplicate/runHook.js.map +1 -0
- package/dist/fields/hooks/beforeDuplicate/traverseFields.d.ts +18 -0
- package/dist/fields/hooks/beforeDuplicate/traverseFields.d.ts.map +1 -0
- package/dist/fields/hooks/beforeDuplicate/traverseFields.js +21 -0
- package/dist/fields/hooks/beforeDuplicate/traverseFields.js.map +1 -0
- package/package.json +2 -2
- package/dist/fields/baseFields/baseBeforeDuplicateArrays.d.ts +0 -6
- package/dist/fields/baseFields/baseBeforeDuplicateArrays.d.ts.map +0 -1
- package/dist/fields/baseFields/baseBeforeDuplicateArrays.js +0 -15
- package/dist/fields/baseFields/baseBeforeDuplicateArrays.js.map +0 -1
- package/dist/fields/hooks/beforeChange/beforeDuplicate.d.ts +0 -3
- package/dist/fields/hooks/beforeChange/beforeDuplicate.d.ts.map +0 -1
- package/dist/fields/hooks/beforeChange/beforeDuplicate.js +0 -6
- package/dist/fields/hooks/beforeChange/beforeDuplicate.js.map +0 -1
|
@@ -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 { SanitizedGlobalConfig } from '../../../globals/config/types.js'\nimport type { JsonObject, Operation, PayloadRequest, RequestContext } from '../../../types/index.js'\nimport type { Field, FieldHookArgs, TabAsField, ValidateOptions } from '../../config/types.js'\n\nimport { MissingEditorProp } from '../../../errors/index.js'\nimport { deepMergeWithSourceArrays } from '../../../utilities/deepMerge.js'\nimport { fieldAffectsData, tabHasName } from '../../config/types.js'\nimport { getFieldPaths } from '../../getFieldPaths.js'\nimport { beforeDuplicate } from './beforeDuplicate.js'\nimport { getExistingRowDoc } from './getExistingRowDoc.js'\nimport { traverseFields } from './traverseFields.js'\n\ntype Args = {\n collection: null | SanitizedCollectionConfig\n context: RequestContext\n data: JsonObject\n doc: JsonObject\n docWithLocales: JsonObject\n duplicate: boolean\n errors: { field: string; message: string }[]\n field: Field | TabAsField\n global: null | SanitizedGlobalConfig\n id?: number | string\n mergeLocaleActions: (() => Promise<void>)[]\n operation: Operation\n /**\n * The parent's path.\n */\n parentPath: (number | string)[]\n /**\n * The parent's schemaPath (path without indexes).\n */\n parentSchemaPath: string[]\n req: PayloadRequest\n siblingData: JsonObject\n siblingDoc: JsonObject\n siblingDocWithLocales?: JsonObject\n skipValidation: boolean\n}\n\n// This function is responsible for the following actions, in order:\n// - Run condition\n// - Execute field hooks\n// - Validate data\n// - Transform data for storage\n// - beforeDuplicate hooks (if duplicate)\n// - Unflatten locales\n\nexport const promise = async ({\n id,\n collection,\n context,\n data,\n doc,\n docWithLocales,\n duplicate,\n errors,\n field,\n global,\n mergeLocaleActions,\n operation,\n parentPath,\n parentSchemaPath,\n req,\n siblingData,\n siblingDoc,\n siblingDocWithLocales,\n skipValidation,\n}: Args): Promise<void> => {\n const passesCondition = field.admin?.condition\n ? Boolean(field.admin.condition(data, siblingData, { user: req.user }))\n : true\n let skipValidationFromHere = skipValidation || !passesCondition\n const { localization } = req.payload.config\n const defaultLocale = localization ? localization?.defaultLocale : 'en'\n const operationLocale = req.locale || defaultLocale\n\n const { path: fieldPath, schemaPath: fieldSchemaPath } = getFieldPaths({\n field,\n parentPath,\n parentSchemaPath,\n })\n\n if (fieldAffectsData(field)) {\n // skip validation if the field is localized and the incoming data is null\n if (field.localized && operationLocale !== defaultLocale) {\n if (['array', 'blocks'].includes(field.type) && siblingData[field.name] === null) {\n skipValidationFromHere = true\n }\n }\n\n // Execute hooks\n if (field.hooks?.beforeChange) {\n await field.hooks.beforeChange.reduce(async (priorHook, currentHook) => {\n await priorHook\n\n const hookedValue = await currentHook({\n collection,\n context,\n data,\n field,\n global,\n operation,\n originalDoc: doc,\n path: fieldPath,\n previousSiblingDoc: siblingDoc,\n previousValue: siblingDoc[field.name],\n req,\n schemaPath: parentSchemaPath,\n siblingData,\n siblingDocWithLocales,\n value: siblingData[field.name],\n })\n\n if (hookedValue !== undefined) {\n siblingData[field.name] = hookedValue\n }\n }, Promise.resolve())\n }\n\n // Validate\n if (!skipValidationFromHere && 'validate' in field && field.validate) {\n const valueToValidate = siblingData[field.name]\n let jsonError: object\n\n if (field.type === 'json' && typeof siblingData[field.name] === 'string') {\n try {\n JSON.parse(siblingData[field.name] as string)\n } catch (e) {\n jsonError = e\n }\n }\n\n const validationResult = await field.validate(valueToValidate, {\n ...field,\n id,\n collectionSlug: collection?.slug,\n data: deepMergeWithSourceArrays(doc, data),\n jsonError,\n operation,\n preferences: { fields: {} },\n previousValue: siblingDoc[field.name],\n req,\n siblingData: deepMergeWithSourceArrays(siblingDoc, siblingData),\n } as ValidateOptions<any, any, { jsonError: object }, any>)\n\n if (typeof validationResult === 'string') {\n errors.push({\n field: fieldPath.join('.'),\n message: validationResult,\n })\n }\n }\n\n const beforeDuplicateArgs: FieldHookArgs = {\n collection,\n context,\n data,\n field,\n global: undefined,\n path: fieldPath,\n previousSiblingDoc: siblingDoc,\n previousValue: siblingDoc[field.name],\n req,\n schemaPath: parentSchemaPath,\n siblingData,\n siblingDocWithLocales,\n value: siblingData[field.name],\n }\n\n // Push merge locale action if applicable\n if (localization && field.localized) {\n mergeLocaleActions.push(async () => {\n const localeData = await localization.localeCodes.reduce(\n async (localizedValuesPromise: Promise<JsonObject>, locale) => {\n const localizedValues = await localizedValuesPromise\n let fieldValue =\n locale === req.locale\n ? siblingData[field.name]\n : siblingDocWithLocales?.[field.name]?.[locale]\n\n if (duplicate && field.hooks?.beforeDuplicate?.length) {\n beforeDuplicateArgs.value = fieldValue\n fieldValue = await beforeDuplicate(beforeDuplicateArgs)\n }\n\n // const result = await localizedValues\n // update locale value if it's not undefined\n if (typeof fieldValue !== 'undefined') {\n return {\n ...localizedValues,\n [locale]: fieldValue,\n }\n }\n\n return localizedValuesPromise\n },\n Promise.resolve({}),\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 } else if (duplicate && field.hooks?.beforeDuplicate?.length) {\n mergeLocaleActions.push(async () => {\n siblingData[field.name] = await beforeDuplicate(beforeDuplicateArgs)\n })\n }\n }\n\n switch (field.type) {\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 'group': {\n if (typeof siblingData[field.name] !== 'object') {\n siblingData[field.name] = {}\n }\n if (typeof siblingDoc[field.name] !== 'object') {\n siblingDoc[field.name] = {}\n }\n if (typeof siblingDocWithLocales[field.name] !== 'object') {\n siblingDocWithLocales[field.name] = {}\n }\n\n await traverseFields({\n id,\n collection,\n context,\n data,\n doc,\n docWithLocales,\n duplicate,\n errors,\n fields: field.fields,\n global,\n mergeLocaleActions,\n operation,\n path: fieldPath,\n req,\n schemaPath: fieldSchemaPath,\n siblingData: siblingData[field.name] as JsonObject,\n siblingDoc: siblingDoc[field.name] as JsonObject,\n siblingDocWithLocales: siblingDocWithLocales[field.name] as JsonObject,\n skipValidation: skipValidationFromHere,\n })\n\n break\n }\n\n case 'array': {\n const rows = siblingData[field.name]\n\n if (Array.isArray(rows)) {\n const promises = []\n rows.forEach((row, i) => {\n promises.push(\n traverseFields({\n id,\n collection,\n context,\n data,\n doc,\n docWithLocales,\n duplicate,\n errors,\n fields: field.fields,\n global,\n mergeLocaleActions,\n operation,\n path: [...fieldPath, i],\n req,\n schemaPath: fieldSchemaPath,\n siblingData: row as JsonObject,\n siblingDoc: getExistingRowDoc(row as JsonObject, siblingDoc[field.name]),\n siblingDocWithLocales: getExistingRowDoc(\n row as JsonObject,\n siblingDocWithLocales[field.name],\n ),\n skipValidation: skipValidationFromHere,\n }),\n )\n })\n\n await Promise.all(promises)\n }\n\n break\n }\n\n case 'blocks': {\n const rows = siblingData[field.name]\n\n if (Array.isArray(rows)) {\n const promises = []\n rows.forEach((row, i) => {\n const rowSiblingDoc = getExistingRowDoc(row as JsonObject, siblingDoc[field.name])\n const rowSiblingDocWithLocales = getExistingRowDoc(\n row as JsonObject,\n siblingDocWithLocales[field.name],\n )\n\n const blockTypeToMatch = (row as JsonObject).blockType || rowSiblingDoc.blockType\n const block = field.blocks.find((blockType) => blockType.slug === blockTypeToMatch)\n\n if (block) {\n promises.push(\n traverseFields({\n id,\n collection,\n context,\n data,\n doc,\n docWithLocales,\n duplicate,\n errors,\n fields: block.fields,\n global,\n mergeLocaleActions,\n operation,\n path: [...fieldPath, i],\n req,\n schemaPath: fieldSchemaPath,\n siblingData: row as JsonObject,\n siblingDoc: rowSiblingDoc,\n siblingDocWithLocales: rowSiblingDocWithLocales,\n skipValidation: skipValidationFromHere,\n }),\n )\n }\n })\n\n await Promise.all(promises)\n }\n\n break\n }\n\n case 'row':\n case 'collapsible': {\n await traverseFields({\n id,\n collection,\n context,\n data,\n doc,\n docWithLocales,\n duplicate,\n errors,\n fields: field.fields,\n global,\n mergeLocaleActions,\n operation,\n path: fieldPath,\n req,\n schemaPath: fieldSchemaPath,\n siblingData,\n siblingDoc,\n siblingDocWithLocales,\n skipValidation: skipValidationFromHere,\n })\n\n break\n }\n\n case 'tab': {\n let tabSiblingData = siblingData\n let tabSiblingDoc = siblingDoc\n let tabSiblingDocWithLocales = siblingDocWithLocales\n\n if (tabHasName(field)) {\n if (typeof siblingData[field.name] !== 'object') {\n siblingData[field.name] = {}\n }\n if (typeof siblingDoc[field.name] !== 'object') {\n siblingDoc[field.name] = {}\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 collection,\n context,\n data,\n doc,\n docWithLocales,\n duplicate,\n errors,\n fields: field.fields,\n global,\n mergeLocaleActions,\n operation,\n path: fieldPath,\n req,\n schemaPath: fieldSchemaPath,\n siblingData: tabSiblingData,\n siblingDoc: tabSiblingDoc,\n siblingDocWithLocales: tabSiblingDocWithLocales,\n skipValidation: skipValidationFromHere,\n })\n\n break\n }\n\n case 'tabs': {\n await traverseFields({\n id,\n collection,\n context,\n data,\n doc,\n docWithLocales,\n duplicate,\n errors,\n fields: field.tabs.map((tab) => ({ ...tab, type: 'tab' })),\n global,\n mergeLocaleActions,\n operation,\n path: fieldPath,\n req,\n schemaPath: fieldSchemaPath,\n siblingData,\n siblingDoc,\n siblingDocWithLocales,\n skipValidation: skipValidationFromHere,\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 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 await editor.hooks.beforeChange.reduce(async (priorHook, currentHook) => {\n await priorHook\n\n const hookedValue = await currentHook({\n collection,\n context,\n data,\n docWithLocales,\n duplicate,\n errors,\n field,\n global,\n mergeLocaleActions,\n operation,\n originalDoc: doc,\n path: fieldPath,\n previousSiblingDoc: siblingDoc,\n previousValue: siblingDoc[field.name],\n req,\n schemaPath: parentSchemaPath,\n siblingData,\n siblingDocWithLocales,\n skipValidation,\n value: siblingData[field.name],\n })\n\n if (hookedValue !== undefined) {\n siblingData[field.name] = hookedValue\n }\n }, Promise.resolve())\n }\n\n break\n }\n\n default: {\n break\n }\n }\n}\n"],"names":["MissingEditorProp","deepMergeWithSourceArrays","fieldAffectsData","tabHasName","getFieldPaths","beforeDuplicate","getExistingRowDoc","traverseFields","promise","id","collection","context","data","doc","docWithLocales","duplicate","errors","field","global","mergeLocaleActions","operation","parentPath","parentSchemaPath","req","siblingData","siblingDoc","siblingDocWithLocales","skipValidation","passesCondition","admin","condition","Boolean","user","skipValidationFromHere","localization","payload","config","defaultLocale","operationLocale","locale","path","fieldPath","schemaPath","fieldSchemaPath","localized","includes","type","name","hooks","beforeChange","reduce","priorHook","currentHook","hookedValue","originalDoc","previousSiblingDoc","previousValue","value","undefined","Promise","resolve","validate","valueToValidate","jsonError","JSON","parse","e","validationResult","collectionSlug","slug","preferences","fields","push","join","message","beforeDuplicateArgs","localeData","localeCodes","localizedValuesPromise","localizedValues","fieldValue","length","Object","keys","Array","isArray","coordinates","parseFloat","rows","promises","forEach","row","i","all","rowSiblingDoc","rowSiblingDocWithLocales","blockTypeToMatch","blockType","block","blocks","find","tabSiblingData","tabSiblingDoc","tabSiblingDocWithLocales","tabs","map","tab","editor","Error"],"mappings":"AAMA,SAASA,iBAAiB,QAAQ,2BAA0B;AAC5D,SAASC,yBAAyB,QAAQ,kCAAiC;AAC3E,SAASC,gBAAgB,EAAEC,UAAU,QAAQ,wBAAuB;AACpE,SAASC,aAAa,QAAQ,yBAAwB;AACtD,SAASC,eAAe,QAAQ,uBAAsB;AACtD,SAASC,iBAAiB,QAAQ,yBAAwB;AAC1D,SAASC,cAAc,QAAQ,sBAAqB;AA8BpD,oEAAoE;AACpE,kBAAkB;AAClB,wBAAwB;AACxB,kBAAkB;AAClB,+BAA+B;AAC/B,yCAAyC;AACzC,sBAAsB;AAEtB,OAAO,MAAMC,UAAU,OAAO,EAC5BC,EAAE,EACFC,UAAU,EACVC,OAAO,EACPC,IAAI,EACJC,GAAG,EACHC,cAAc,EACdC,SAAS,EACTC,MAAM,EACNC,KAAK,EACLC,MAAM,EACNC,kBAAkB,EAClBC,SAAS,EACTC,UAAU,EACVC,gBAAgB,EAChBC,GAAG,EACHC,WAAW,EACXC,UAAU,EACVC,qBAAqB,EACrBC,cAAc,EACT;IAC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QAAQtD,MAAMuF,IAAI,CAACC,GAAG,CAAC,CAACC,MAAS,CAAA;4BAAE,GAAGA,GAAG;4BAAE5D,MAAM;wBAAM,CAAA;oBACvD5B;oBACAC;oBACAC;oBACAoB,MAAMC;oBACNlB;oBACAmB,YAAYC;oBACZnB;oBACAC;oBACAC;oBACAC,gBAAgBM;gBAClB;gBAEA;YACF;QAEA,KAAK;YAAY;gBACf,IAAI,CAAChB,OAAO0F,QAAQ;oBAClB,MAAM,IAAI3G,kBAAkBiB,OAAO,8HAA8H;;gBACnK;gBACA,IAAI,OAAOA,OAAO0F,WAAW,YAAY;oBACvC,MAAM,IAAIC,MAAM;gBAClB;gBAEA,MAAMD,SAA0B1F,OAAO0F;gBAEvC,IAAIA,QAAQ3D,OAAOC,cAAcgC,QAAQ;oBACvC,MAAM0B,OAAO3D,KAAK,CAACC,YAAY,CAACC,MAAM,CAAC,OAAOC,WAAWC;wBACvD,MAAMD;wBAEN,MAAME,cAAc,MAAMD,YAAY;4BACpC1C;4BACAC;4BACAC;4BACAE;4BACAC;4BACAC;4BACAC;4BACAC;4BACAC;4BACAC;4BACAkC,aAAazC;4BACb2B,MAAMC;4BACNc,oBAAoB9B;4BACpB+B,eAAe/B,UAAU,CAACR,MAAM8B,IAAI,CAAC;4BACrCxB;4BACAmB,YAAYpB;4BACZE;4BACAE;4BACAC;4BACA8B,OAAOjC,WAAW,CAACP,MAAM8B,IAAI,CAAC;wBAChC;wBAEA,IAAIM,gBAAgBK,WAAW;4BAC7BlC,WAAW,CAACP,MAAM8B,IAAI,CAAC,GAAGM;wBAC5B;oBACF,GAAGM,QAAQC,OAAO;gBACpB;gBAEA;YACF;QAEA;YAAS;gBACP;YACF;IACF;AACF,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../../../src/fields/hooks/beforeChange/promise.ts"],"sourcesContent":["import type { RichTextAdapter } from '../../../admin/RichText.js'\nimport type { SanitizedCollectionConfig } from '../../../collections/config/types.js'\nimport type { SanitizedGlobalConfig } from '../../../globals/config/types.js'\nimport type { JsonObject, Operation, PayloadRequest, RequestContext } from '../../../types/index.js'\nimport type { Field, FieldHookArgs, TabAsField, ValidateOptions } from '../../config/types.js'\n\nimport { MissingEditorProp } from '../../../errors/index.js'\nimport { deepMergeWithSourceArrays } from '../../../utilities/deepMerge.js'\nimport { fieldAffectsData, tabHasName } from '../../config/types.js'\nimport { getFieldPaths } from '../../getFieldPaths.js'\nimport { getExistingRowDoc } from './getExistingRowDoc.js'\nimport { traverseFields } from './traverseFields.js'\n\ntype Args = {\n collection: null | SanitizedCollectionConfig\n context: RequestContext\n data: JsonObject\n doc: JsonObject\n docWithLocales: JsonObject\n errors: { field: string; message: string }[]\n field: Field | TabAsField\n global: null | SanitizedGlobalConfig\n id?: number | string\n mergeLocaleActions: (() => Promise<void>)[]\n operation: Operation\n /**\n * The parent's path.\n */\n parentPath: (number | string)[]\n /**\n * The parent's schemaPath (path without indexes).\n */\n parentSchemaPath: string[]\n req: PayloadRequest\n siblingData: JsonObject\n siblingDoc: JsonObject\n siblingDocWithLocales?: JsonObject\n skipValidation: boolean\n}\n\n// This function is responsible for the following actions, in order:\n// - Run condition\n// - Execute field hooks\n// - Validate data\n// - Transform data for storage\n// - beforeDuplicate hooks (if duplicate)\n// - Unflatten locales\n\nexport const promise = async ({\n id,\n collection,\n context,\n data,\n doc,\n docWithLocales,\n errors,\n field,\n global,\n mergeLocaleActions,\n operation,\n parentPath,\n parentSchemaPath,\n req,\n siblingData,\n siblingDoc,\n siblingDocWithLocales,\n skipValidation,\n}: Args): Promise<void> => {\n const passesCondition = field.admin?.condition\n ? Boolean(field.admin.condition(data, siblingData, { user: req.user }))\n : true\n let skipValidationFromHere = skipValidation || !passesCondition\n const { localization } = req.payload.config\n const defaultLocale = localization ? localization?.defaultLocale : 'en'\n const operationLocale = req.locale || defaultLocale\n\n const { path: fieldPath, schemaPath: fieldSchemaPath } = getFieldPaths({\n field,\n parentPath,\n parentSchemaPath,\n })\n\n if (fieldAffectsData(field)) {\n // skip validation if the field is localized and the incoming data is null\n if (field.localized && operationLocale !== defaultLocale) {\n if (['array', 'blocks'].includes(field.type) && siblingData[field.name] === null) {\n skipValidationFromHere = true\n }\n }\n\n // Execute hooks\n if (field.hooks?.beforeChange) {\n await field.hooks.beforeChange.reduce(async (priorHook, currentHook) => {\n await priorHook\n\n const hookedValue = await currentHook({\n collection,\n context,\n data,\n field,\n global,\n operation,\n originalDoc: doc,\n path: fieldPath,\n previousSiblingDoc: siblingDoc,\n previousValue: siblingDoc[field.name],\n req,\n schemaPath: parentSchemaPath,\n siblingData,\n siblingDocWithLocales,\n value: siblingData[field.name],\n })\n\n if (hookedValue !== undefined) {\n siblingData[field.name] = hookedValue\n }\n }, Promise.resolve())\n }\n\n // Validate\n if (!skipValidationFromHere && 'validate' in field && field.validate) {\n const valueToValidate = siblingData[field.name]\n let jsonError: object\n\n if (field.type === 'json' && typeof siblingData[field.name] === 'string') {\n try {\n JSON.parse(siblingData[field.name] as string)\n } catch (e) {\n jsonError = e\n }\n }\n\n const validationResult = await field.validate(valueToValidate, {\n ...field,\n id,\n collectionSlug: collection?.slug,\n data: deepMergeWithSourceArrays(doc, data),\n jsonError,\n operation,\n preferences: { fields: {} },\n previousValue: siblingDoc[field.name],\n req,\n siblingData: deepMergeWithSourceArrays(siblingDoc, siblingData),\n } as ValidateOptions<any, any, { jsonError: object }, any>)\n\n if (typeof validationResult === 'string') {\n errors.push({\n field: fieldPath.join('.'),\n message: validationResult,\n })\n }\n }\n\n const beforeDuplicateArgs: FieldHookArgs = {\n collection,\n context,\n data,\n field,\n global: undefined,\n path: fieldPath,\n previousSiblingDoc: siblingDoc,\n previousValue: siblingDoc[field.name],\n req,\n schemaPath: parentSchemaPath,\n siblingData,\n siblingDocWithLocales,\n value: siblingData[field.name],\n }\n\n // Push merge locale action if applicable\n if (localization && field.localized) {\n mergeLocaleActions.push(async () => {\n const localeData = await localization.localeCodes.reduce(\n async (localizedValuesPromise: Promise<JsonObject>, locale) => {\n const localizedValues = await localizedValuesPromise\n const fieldValue =\n locale === req.locale\n ? siblingData[field.name]\n : siblingDocWithLocales?.[field.name]?.[locale]\n\n // const result = await localizedValues\n // update locale value if it's not undefined\n if (typeof fieldValue !== 'undefined') {\n return {\n ...localizedValues,\n [locale]: fieldValue,\n }\n }\n\n return localizedValuesPromise\n },\n Promise.resolve({}),\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 '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 'group': {\n if (typeof siblingData[field.name] !== 'object') {\n siblingData[field.name] = {}\n }\n if (typeof siblingDoc[field.name] !== 'object') {\n siblingDoc[field.name] = {}\n }\n if (typeof siblingDocWithLocales[field.name] !== 'object') {\n siblingDocWithLocales[field.name] = {}\n }\n\n await traverseFields({\n id,\n collection,\n context,\n data,\n doc,\n docWithLocales,\n errors,\n fields: field.fields,\n global,\n mergeLocaleActions,\n operation,\n path: fieldPath,\n req,\n schemaPath: fieldSchemaPath,\n siblingData: siblingData[field.name] as JsonObject,\n siblingDoc: siblingDoc[field.name] as JsonObject,\n siblingDocWithLocales: siblingDocWithLocales[field.name] as JsonObject,\n skipValidation: skipValidationFromHere,\n })\n\n break\n }\n\n case 'array': {\n const rows = siblingData[field.name]\n\n if (Array.isArray(rows)) {\n const promises = []\n rows.forEach((row, i) => {\n promises.push(\n traverseFields({\n id,\n collection,\n context,\n data,\n doc,\n docWithLocales,\n errors,\n fields: field.fields,\n global,\n mergeLocaleActions,\n operation,\n path: [...fieldPath, i],\n req,\n schemaPath: fieldSchemaPath,\n siblingData: row as JsonObject,\n siblingDoc: getExistingRowDoc(row as JsonObject, siblingDoc[field.name]),\n siblingDocWithLocales: getExistingRowDoc(\n row as JsonObject,\n siblingDocWithLocales[field.name],\n ),\n skipValidation: skipValidationFromHere,\n }),\n )\n })\n\n await Promise.all(promises)\n }\n\n break\n }\n\n case 'blocks': {\n const rows = siblingData[field.name]\n\n if (Array.isArray(rows)) {\n const promises = []\n rows.forEach((row, i) => {\n const rowSiblingDoc = getExistingRowDoc(row as JsonObject, siblingDoc[field.name])\n const rowSiblingDocWithLocales = getExistingRowDoc(\n row as JsonObject,\n siblingDocWithLocales[field.name],\n )\n\n const blockTypeToMatch = (row as JsonObject).blockType || rowSiblingDoc.blockType\n const block = field.blocks.find((blockType) => blockType.slug === blockTypeToMatch)\n\n if (block) {\n promises.push(\n traverseFields({\n id,\n collection,\n context,\n data,\n doc,\n docWithLocales,\n errors,\n fields: block.fields,\n global,\n mergeLocaleActions,\n operation,\n path: [...fieldPath, i],\n req,\n schemaPath: fieldSchemaPath,\n siblingData: row as JsonObject,\n siblingDoc: rowSiblingDoc,\n siblingDocWithLocales: rowSiblingDocWithLocales,\n skipValidation: skipValidationFromHere,\n }),\n )\n }\n })\n\n await Promise.all(promises)\n }\n\n break\n }\n\n case 'row':\n case 'collapsible': {\n await traverseFields({\n id,\n collection,\n context,\n data,\n doc,\n docWithLocales,\n errors,\n fields: field.fields,\n global,\n mergeLocaleActions,\n operation,\n path: fieldPath,\n req,\n schemaPath: fieldSchemaPath,\n siblingData,\n siblingDoc,\n siblingDocWithLocales,\n skipValidation: skipValidationFromHere,\n })\n\n break\n }\n\n case 'tab': {\n let tabSiblingData = siblingData\n let tabSiblingDoc = siblingDoc\n let tabSiblingDocWithLocales = siblingDocWithLocales\n\n if (tabHasName(field)) {\n if (typeof siblingData[field.name] !== 'object') {\n siblingData[field.name] = {}\n }\n if (typeof siblingDoc[field.name] !== 'object') {\n siblingDoc[field.name] = {}\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 collection,\n context,\n data,\n doc,\n docWithLocales,\n errors,\n fields: field.fields,\n global,\n mergeLocaleActions,\n operation,\n path: fieldPath,\n req,\n schemaPath: fieldSchemaPath,\n siblingData: tabSiblingData,\n siblingDoc: tabSiblingDoc,\n siblingDocWithLocales: tabSiblingDocWithLocales,\n skipValidation: skipValidationFromHere,\n })\n\n break\n }\n\n case 'tabs': {\n await traverseFields({\n id,\n collection,\n context,\n data,\n doc,\n docWithLocales,\n errors,\n fields: field.tabs.map((tab) => ({ ...tab, type: 'tab' })),\n global,\n mergeLocaleActions,\n operation,\n path: fieldPath,\n req,\n schemaPath: fieldSchemaPath,\n siblingData,\n siblingDoc,\n siblingDocWithLocales,\n skipValidation: skipValidationFromHere,\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 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 await editor.hooks.beforeChange.reduce(async (priorHook, currentHook) => {\n await priorHook\n\n const hookedValue = await currentHook({\n collection,\n context,\n data,\n docWithLocales,\n errors,\n field,\n global,\n mergeLocaleActions,\n operation,\n originalDoc: doc,\n path: fieldPath,\n previousSiblingDoc: siblingDoc,\n previousValue: siblingDoc[field.name],\n req,\n schemaPath: parentSchemaPath,\n siblingData,\n siblingDocWithLocales,\n skipValidation,\n value: siblingData[field.name],\n })\n\n if (hookedValue !== undefined) {\n siblingData[field.name] = hookedValue\n }\n }, Promise.resolve())\n }\n\n break\n }\n\n default: {\n break\n }\n }\n}\n"],"names":["MissingEditorProp","deepMergeWithSourceArrays","fieldAffectsData","tabHasName","getFieldPaths","getExistingRowDoc","traverseFields","promise","id","collection","context","data","doc","docWithLocales","errors","field","global","mergeLocaleActions","operation","parentPath","parentSchemaPath","req","siblingData","siblingDoc","siblingDocWithLocales","skipValidation","passesCondition","admin","condition","Boolean","user","skipValidationFromHere","localization","payload","config","defaultLocale","operationLocale","locale","path","fieldPath","schemaPath","fieldSchemaPath","localized","includes","type","name","hooks","beforeChange","reduce","priorHook","currentHook","hookedValue","originalDoc","previousSiblingDoc","previousValue","value","undefined","Promise","resolve","validate","valueToValidate","jsonError","JSON","parse","e","validationResult","collectionSlug","slug","preferences","fields","push","join","message","beforeDuplicateArgs","localeData","localeCodes","localizedValuesPromise","localizedValues","fieldValue","Object","keys","length","Array","isArray","coordinates","parseFloat","rows","promises","forEach","row","i","all","rowSiblingDoc","rowSiblingDocWithLocales","blockTypeToMatch","blockType","block","blocks","find","tabSiblingData","tabSiblingDoc","tabSiblingDocWithLocales","tabs","map","tab","editor","Error"],"mappings":"AAMA,SAASA,iBAAiB,QAAQ,2BAA0B;AAC5D,SAASC,yBAAyB,QAAQ,kCAAiC;AAC3E,SAASC,gBAAgB,EAAEC,UAAU,QAAQ,wBAAuB;AACpE,SAASC,aAAa,QAAQ,yBAAwB;AACtD,SAASC,iBAAiB,QAAQ,yBAAwB;AAC1D,SAASC,cAAc,QAAQ,sBAAqB;AA6BpD,oEAAoE;AACpE,kBAAkB;AAClB,wBAAwB;AACxB,kBAAkB;AAClB,+BAA+B;AAC/B,yCAAyC;AACzC,sBAAsB;AAEtB,OAAO,MAAMC,UAAU,OAAO,EAC5BC,EAAE,EACFC,UAAU,EACVC,OAAO,EACPC,IAAI,EACJC,GAAG,EACHC,cAAc,EACdC,MAAM,EACNC,KAAK,EACLC,MAAM,EACNC,kBAAkB,EAClBC,SAAS,EACTC,UAAU,EACVC,gBAAgB,EAChBC,GAAG,EACHC,WAAW,EACXC,UAAU,EACVC,qBAAqB,EACrBC,cAAc,EACT;IACL,MAAMC,kBAAkBX,MAAMY,KA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MAAM,IAAIC,MAAM;gBAClB;gBAEA,MAAMD,SAA0B1F,OAAO0F;gBAEvC,IAAIA,QAAQ3D,OAAOC,cAAckC,QAAQ;oBACvC,MAAMwB,OAAO3D,KAAK,CAACC,YAAY,CAACC,MAAM,CAAC,OAAOC,WAAWC;wBACvD,MAAMD;wBAEN,MAAME,cAAc,MAAMD,YAAY;4BACpCzC;4BACAC;4BACAC;4BACAE;4BACAC;4BACAC;4BACAC;4BACAC;4BACAC;4BACAkC,aAAaxC;4BACb0B,MAAMC;4BACNc,oBAAoB9B;4BACpB+B,eAAe/B,UAAU,CAACR,MAAM8B,IAAI,CAAC;4BACrCxB;4BACAmB,YAAYpB;4BACZE;4BACAE;4BACAC;4BACA8B,OAAOjC,WAAW,CAACP,MAAM8B,IAAI,CAAC;wBAChC;wBAEA,IAAIM,gBAAgBK,WAAW;4BAC7BlC,WAAW,CAACP,MAAM8B,IAAI,CAAC,GAAGM;wBAC5B;oBACF,GAAGM,QAAQC,OAAO;gBACpB;gBAEA;YACF;QAEA;YAAS;gBACP;YACF;IACF;AACF,EAAC"}
|
|
@@ -14,7 +14,6 @@ type Args = {
|
|
|
14
14
|
* The original data with locales (not modified by any hooks)
|
|
15
15
|
*/
|
|
16
16
|
docWithLocales: JsonObject;
|
|
17
|
-
duplicate: boolean;
|
|
18
17
|
errors: {
|
|
19
18
|
field: string;
|
|
20
19
|
message: string;
|
|
@@ -46,6 +45,6 @@ type Args = {
|
|
|
46
45
|
* - Transform data for storage
|
|
47
46
|
* - Unflatten locales. The input `data` is the normal document for one locale. The output result will become the document with locales.
|
|
48
47
|
*/
|
|
49
|
-
export declare const traverseFields: ({ id, collection, context, data, doc, docWithLocales,
|
|
48
|
+
export declare const traverseFields: ({ id, collection, context, data, doc, docWithLocales, errors, fields, global, mergeLocaleActions, operation, path, req, schemaPath, siblingData, siblingDoc, siblingDocWithLocales, skipValidation, }: Args) => Promise<void>;
|
|
50
49
|
export {};
|
|
51
50
|
//# 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,qBAAqB,EAAE,MAAM,kCAAkC,CAAA;AAC7E,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AACpG,OAAO,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AAI9D,KAAK,IAAI,GAAG;IACV,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,
|
|
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,qBAAqB,EAAE,MAAM,kCAAkC,CAAA;AAC7E,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AACpG,OAAO,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AAI9D,KAAK,IAAI,GAAG;IACV,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;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,EAAE,CAAA;IAC5C,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,CAAC,EAAE,CAAA;IAC3C,SAAS,EAAE,SAAS,CAAA;IACpB,IAAI,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAA;IACzB,GAAG,EAAE,cAAc,CAAA;IACnB,UAAU,EAAE,MAAM,EAAE,CAAA;IACpB,WAAW,EAAE,UAAU,CAAA;IACvB;;OAEG;IACH,UAAU,EAAE,UAAU,CAAA;IACtB;;OAEG;IACH,qBAAqB,EAAE,UAAU,CAAA;IACjC,cAAc,CAAC,EAAE,OAAO,CAAA;CACzB,CAAA;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,cAAc,0MAmBxB,IAAI,KAAG,OAAO,CAAC,IAAI,CA6BrB,CAAA"}
|
|
@@ -6,7 +6,7 @@ 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, collection, context, data, doc, docWithLocales,
|
|
9
|
+
*/ export const traverseFields = async ({ id, collection, context, data, doc, docWithLocales, errors, fields, global, mergeLocaleActions, operation, path, req, schemaPath, siblingData, siblingDoc, siblingDocWithLocales, skipValidation })=>{
|
|
10
10
|
const promises = [];
|
|
11
11
|
fields.forEach((field)=>{
|
|
12
12
|
promises.push(promise({
|
|
@@ -16,7 +16,6 @@ import { promise } from './promise.js';
|
|
|
16
16
|
data,
|
|
17
17
|
doc,
|
|
18
18
|
docWithLocales,
|
|
19
|
-
duplicate,
|
|
20
19
|
errors,
|
|
21
20
|
field,
|
|
22
21
|
global,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/fields/hooks/beforeChange/traverseFields.ts"],"sourcesContent":["import type { SanitizedCollectionConfig } from '../../../collections/config/types.js'\nimport type { SanitizedGlobalConfig } from '../../../globals/config/types.js'\nimport type { JsonObject, Operation, PayloadRequest, RequestContext } from '../../../types/index.js'\nimport type { Field, TabAsField } from '../../config/types.js'\n\nimport { promise } from './promise.js'\n\ntype Args = {\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
|
|
1
|
+
{"version":3,"sources":["../../../../src/fields/hooks/beforeChange/traverseFields.ts"],"sourcesContent":["import type { SanitizedCollectionConfig } from '../../../collections/config/types.js'\nimport type { SanitizedGlobalConfig } from '../../../globals/config/types.js'\nimport type { JsonObject, Operation, PayloadRequest, RequestContext } from '../../../types/index.js'\nimport type { Field, TabAsField } from '../../config/types.js'\n\nimport { promise } from './promise.js'\n\ntype Args = {\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: { field: string; message: string }[]\n fields: (Field | TabAsField)[]\n global: null | SanitizedGlobalConfig\n id?: number | string\n mergeLocaleActions: (() => Promise<void>)[]\n operation: Operation\n path: (number | string)[]\n req: PayloadRequest\n schemaPath: string[]\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}\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 collection,\n context,\n data,\n doc,\n docWithLocales,\n errors,\n fields,\n global,\n mergeLocaleActions,\n operation,\n path,\n req,\n schemaPath,\n siblingData,\n siblingDoc,\n siblingDocWithLocales,\n skipValidation,\n}: Args): Promise<void> => {\n const promises = []\n\n fields.forEach((field) => {\n promises.push(\n promise({\n id,\n collection,\n context,\n data,\n doc,\n docWithLocales,\n errors,\n field,\n global,\n mergeLocaleActions,\n operation,\n parentPath: path,\n parentSchemaPath: schemaPath,\n req,\n siblingData,\n siblingDoc,\n siblingDocWithLocales,\n skipValidation,\n }),\n )\n })\n\n await Promise.all(promises)\n}\n"],"names":["promise","traverseFields","id","collection","context","data","doc","docWithLocales","errors","fields","global","mergeLocaleActions","operation","path","req","schemaPath","siblingData","siblingDoc","siblingDocWithLocales","skipValidation","promises","forEach","field","push","parentPath","parentSchemaPath","Promise","all"],"mappings":"AAKA,SAASA,OAAO,QAAQ,eAAc;AAmCtC;;;;;;;CAOC,GACD,OAAO,MAAMC,iBAAiB,OAAO,EACnCC,EAAE,EACFC,UAAU,EACVC,OAAO,EACPC,IAAI,EACJC,GAAG,EACHC,cAAc,EACdC,MAAM,EACNC,MAAM,EACNC,MAAM,EACNC,kBAAkB,EAClBC,SAAS,EACTC,IAAI,EACJC,GAAG,EACHC,UAAU,EACVC,WAAW,EACXC,UAAU,EACVC,qBAAqB,EACrBC,cAAc,EACT;IACL,MAAMC,WAAW,EAAE;IAEnBX,OAAOY,OAAO,CAAC,CAACC;QACdF,SAASG,IAAI,CACXvB,QAAQ;YACNE;YACAC;YACAC;YACAC;YACAC;YACAC;YACAC;YACAc;YACAZ;YACAC;YACAC;YACAY,YAAYX;YACZY,kBAAkBV;YAClBD;YACAE;YACAC;YACAC;YACAC;QACF;IAEJ;IAEA,MAAMO,QAAQC,GAAG,CAACP;AACpB,EAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { SanitizedCollectionConfig } from '../../../collections/config/types.js';
|
|
2
|
+
import type { JsonObject, PayloadRequest, RequestContext } from '../../../types/index.js';
|
|
3
|
+
type Args<T extends JsonObject> = {
|
|
4
|
+
collection: null | SanitizedCollectionConfig;
|
|
5
|
+
context: RequestContext;
|
|
6
|
+
doc?: T;
|
|
7
|
+
id?: number | string;
|
|
8
|
+
overrideAccess: boolean;
|
|
9
|
+
req: PayloadRequest;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* This function is responsible for running beforeDuplicate hooks
|
|
13
|
+
* against a document including all locale data.
|
|
14
|
+
* It will run each field's beforeDuplicate hook
|
|
15
|
+
* and return the resulting docWithLocales.
|
|
16
|
+
*/
|
|
17
|
+
export declare const beforeDuplicate: <T extends JsonObject>({ id, collection, context, doc, overrideAccess, req, }: Args<T>) => Promise<T>;
|
|
18
|
+
export {};
|
|
19
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/fields/hooks/beforeDuplicate/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,sCAAsC,CAAA;AACrF,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AAKzF,KAAK,IAAI,CAAC,CAAC,SAAS,UAAU,IAAI;IAChC,UAAU,EAAE,IAAI,GAAG,yBAAyB,CAAA;IAC5C,OAAO,EAAE,cAAc,CAAA;IACvB,GAAG,CAAC,EAAE,CAAC,CAAA;IACP,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IACpB,cAAc,EAAE,OAAO,CAAA;IACvB,GAAG,EAAE,cAAc,CAAA;CACpB,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,eAAe,GAAU,CAAC,SAAS,UAAU,0DAOvD,IAAI,CAAC,CAAC,CAAC,KAAG,OAAO,CAAC,CAAC,CAiBrB,CAAA"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { deepCopyObjectSimple } from '../../../utilities/deepCopyObject.js';
|
|
2
|
+
import { traverseFields } from './traverseFields.js';
|
|
3
|
+
/**
|
|
4
|
+
* This function is responsible for running beforeDuplicate hooks
|
|
5
|
+
* against a document including all locale data.
|
|
6
|
+
* It will run each field's beforeDuplicate hook
|
|
7
|
+
* and return the resulting docWithLocales.
|
|
8
|
+
*/ export const beforeDuplicate = async ({ id, collection, context, doc, overrideAccess, req })=>{
|
|
9
|
+
const newDoc = deepCopyObjectSimple(doc);
|
|
10
|
+
await traverseFields({
|
|
11
|
+
id,
|
|
12
|
+
collection,
|
|
13
|
+
context,
|
|
14
|
+
doc: newDoc,
|
|
15
|
+
fields: collection?.fields,
|
|
16
|
+
overrideAccess,
|
|
17
|
+
path: [],
|
|
18
|
+
req,
|
|
19
|
+
schemaPath: [],
|
|
20
|
+
siblingDoc: newDoc
|
|
21
|
+
});
|
|
22
|
+
return newDoc;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/fields/hooks/beforeDuplicate/index.ts"],"sourcesContent":["import type { SanitizedCollectionConfig } from '../../../collections/config/types.js'\nimport type { JsonObject, PayloadRequest, RequestContext } from '../../../types/index.js'\n\nimport { deepCopyObjectSimple } from '../../../utilities/deepCopyObject.js'\nimport { traverseFields } from './traverseFields.js'\n\ntype Args<T extends JsonObject> = {\n collection: null | SanitizedCollectionConfig\n context: RequestContext\n doc?: T\n id?: number | string\n overrideAccess: boolean\n req: PayloadRequest\n}\n\n/**\n * This function is responsible for running beforeDuplicate hooks\n * against a document including all locale data.\n * It will run each field's beforeDuplicate hook\n * and return the resulting docWithLocales.\n */\nexport const beforeDuplicate = async <T extends JsonObject>({\n id,\n collection,\n context,\n doc,\n overrideAccess,\n req,\n}: Args<T>): Promise<T> => {\n const newDoc = deepCopyObjectSimple(doc)\n\n await traverseFields({\n id,\n collection,\n context,\n doc: newDoc,\n fields: collection?.fields,\n overrideAccess,\n path: [],\n req,\n schemaPath: [],\n siblingDoc: newDoc,\n })\n\n return newDoc\n}\n"],"names":["deepCopyObjectSimple","traverseFields","beforeDuplicate","id","collection","context","doc","overrideAccess","req","newDoc","fields","path","schemaPath","siblingDoc"],"mappings":"AAGA,SAASA,oBAAoB,QAAQ,uCAAsC;AAC3E,SAASC,cAAc,QAAQ,sBAAqB;AAWpD;;;;;CAKC,GACD,OAAO,MAAMC,kBAAkB,OAA6B,EAC1DC,EAAE,EACFC,UAAU,EACVC,OAAO,EACPC,GAAG,EACHC,cAAc,EACdC,GAAG,EACK;IACR,MAAMC,SAAST,qBAAqBM;IAEpC,MAAML,eAAe;QACnBE;QACAC;QACAC;QACAC,KAAKG;QACLC,QAAQN,YAAYM;QACpBH;QACAI,MAAM,EAAE;QACRH;QACAI,YAAY,EAAE;QACdC,YAAYJ;IACd;IAEA,OAAOA;AACT,EAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { SanitizedCollectionConfig } from '../../../collections/config/types.js';
|
|
2
|
+
import type { JsonObject, PayloadRequest, RequestContext } from '../../../types/index.js';
|
|
3
|
+
import type { Field, TabAsField } from '../../config/types.js';
|
|
4
|
+
type Args<T> = {
|
|
5
|
+
collection: null | SanitizedCollectionConfig;
|
|
6
|
+
context: RequestContext;
|
|
7
|
+
doc: T;
|
|
8
|
+
field: Field | TabAsField;
|
|
9
|
+
id?: number | string;
|
|
10
|
+
overrideAccess: boolean;
|
|
11
|
+
parentPath: (number | string)[];
|
|
12
|
+
parentSchemaPath: string[];
|
|
13
|
+
req: PayloadRequest;
|
|
14
|
+
siblingDoc: JsonObject;
|
|
15
|
+
};
|
|
16
|
+
export declare const promise: <T>({ id, collection, context, doc, field, overrideAccess, parentPath, parentSchemaPath, req, siblingDoc, }: Args<T>) => Promise<void>;
|
|
17
|
+
export {};
|
|
18
|
+
//# sourceMappingURL=promise.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"promise.d.ts","sourceRoot":"","sources":["../../../../src/fields/hooks/beforeDuplicate/promise.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,sCAAsC,CAAA;AACrF,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AACzF,OAAO,KAAK,EAAE,KAAK,EAAiB,UAAU,EAAE,MAAM,uBAAuB,CAAA;AAO7E,KAAK,IAAI,CAAC,CAAC,IAAI;IACb,UAAU,EAAE,IAAI,GAAG,yBAAyB,CAAA;IAC5C,OAAO,EAAE,cAAc,CAAA;IACvB,GAAG,EAAE,CAAC,CAAA;IACN,KAAK,EAAE,KAAK,GAAG,UAAU,CAAA;IACzB,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IACpB,cAAc,EAAE,OAAO,CAAA;IACvB,UAAU,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAA;IAC/B,gBAAgB,EAAE,MAAM,EAAE,CAAA;IAC1B,GAAG,EAAE,cAAc,CAAA;IACnB,UAAU,EAAE,UAAU,CAAA;CACvB,CAAA;AAED,eAAO,MAAM,OAAO,GAAU,CAAC,2GAW5B,IAAI,CAAC,CAAC,CAAC,KAAG,OAAO,CAAC,IAAI,CA6TxB,CAAA"}
|
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
import { fieldAffectsData, tabHasName } from '../../config/types.js';
|
|
2
|
+
import { getFieldPaths } from '../../getFieldPaths.js';
|
|
3
|
+
import { runBeforeDuplicateHooks } from './runHook.js';
|
|
4
|
+
import { traverseFields } from './traverseFields.js';
|
|
5
|
+
export const promise = async ({ id, collection, context, doc, field, overrideAccess, parentPath, parentSchemaPath, req, siblingDoc })=>{
|
|
6
|
+
const { localization } = req.payload.config;
|
|
7
|
+
const { path: fieldPath, schemaPath: fieldSchemaPath } = getFieldPaths({
|
|
8
|
+
field,
|
|
9
|
+
parentPath,
|
|
10
|
+
parentSchemaPath
|
|
11
|
+
});
|
|
12
|
+
if (fieldAffectsData(field)) {
|
|
13
|
+
let fieldData = siblingDoc?.[field.name];
|
|
14
|
+
const fieldIsLocalized = field.localized && localization;
|
|
15
|
+
// Run field beforeDuplicate hooks
|
|
16
|
+
if (Array.isArray(field.hooks?.beforeDuplicate)) {
|
|
17
|
+
if (fieldIsLocalized) {
|
|
18
|
+
const localeData = await localization.localeCodes.reduce(async (localizedValuesPromise, locale)=>{
|
|
19
|
+
const localizedValues = await localizedValuesPromise;
|
|
20
|
+
const beforeDuplicateArgs = {
|
|
21
|
+
collection,
|
|
22
|
+
context,
|
|
23
|
+
data: doc,
|
|
24
|
+
field,
|
|
25
|
+
global: undefined,
|
|
26
|
+
path: fieldPath,
|
|
27
|
+
previousSiblingDoc: siblingDoc,
|
|
28
|
+
previousValue: siblingDoc[field.name]?.[locale],
|
|
29
|
+
req,
|
|
30
|
+
schemaPath: parentSchemaPath,
|
|
31
|
+
siblingData: siblingDoc,
|
|
32
|
+
siblingDocWithLocales: siblingDoc,
|
|
33
|
+
value: siblingDoc[field.name]?.[locale]
|
|
34
|
+
};
|
|
35
|
+
const hookResult = await runBeforeDuplicateHooks(beforeDuplicateArgs);
|
|
36
|
+
if (typeof hookResult !== 'undefined') {
|
|
37
|
+
return {
|
|
38
|
+
...localizedValues,
|
|
39
|
+
[locale]: hookResult
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
return localizedValuesPromise;
|
|
43
|
+
}, Promise.resolve({}));
|
|
44
|
+
siblingDoc[field.name] = localeData;
|
|
45
|
+
} else {
|
|
46
|
+
const beforeDuplicateArgs = {
|
|
47
|
+
collection,
|
|
48
|
+
context,
|
|
49
|
+
data: doc,
|
|
50
|
+
field,
|
|
51
|
+
global: undefined,
|
|
52
|
+
path: fieldPath,
|
|
53
|
+
previousSiblingDoc: siblingDoc,
|
|
54
|
+
previousValue: siblingDoc[field.name],
|
|
55
|
+
req,
|
|
56
|
+
schemaPath: parentSchemaPath,
|
|
57
|
+
siblingData: siblingDoc,
|
|
58
|
+
siblingDocWithLocales: siblingDoc,
|
|
59
|
+
value: siblingDoc[field.name]
|
|
60
|
+
};
|
|
61
|
+
const hookResult = await runBeforeDuplicateHooks(beforeDuplicateArgs);
|
|
62
|
+
if (typeof hookResult !== 'undefined') {
|
|
63
|
+
siblingDoc[field.name] = hookResult;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
// First, for any localized fields, we will loop over locales
|
|
68
|
+
// and if locale data is present, traverse the sub fields.
|
|
69
|
+
// There are only a few different fields where this is possible.
|
|
70
|
+
if (fieldIsLocalized) {
|
|
71
|
+
if (typeof fieldData !== 'object' || fieldData === null) {
|
|
72
|
+
siblingDoc[field.name] = {};
|
|
73
|
+
fieldData = siblingDoc[field.name];
|
|
74
|
+
}
|
|
75
|
+
const promises = [];
|
|
76
|
+
localization.localeCodes.forEach((locale)=>{
|
|
77
|
+
if (fieldData[locale]) {
|
|
78
|
+
switch(field.type){
|
|
79
|
+
case 'tab':
|
|
80
|
+
case 'group':
|
|
81
|
+
{
|
|
82
|
+
promises.push(traverseFields({
|
|
83
|
+
id,
|
|
84
|
+
collection,
|
|
85
|
+
context,
|
|
86
|
+
doc,
|
|
87
|
+
fields: field.fields,
|
|
88
|
+
overrideAccess,
|
|
89
|
+
path: fieldSchemaPath,
|
|
90
|
+
req,
|
|
91
|
+
schemaPath: fieldSchemaPath,
|
|
92
|
+
siblingDoc: fieldData[locale]
|
|
93
|
+
}));
|
|
94
|
+
break;
|
|
95
|
+
}
|
|
96
|
+
case 'array':
|
|
97
|
+
{
|
|
98
|
+
const rows = fieldData[locale];
|
|
99
|
+
if (Array.isArray(rows)) {
|
|
100
|
+
const promises = [];
|
|
101
|
+
rows.forEach((row, i)=>{
|
|
102
|
+
promises.push(traverseFields({
|
|
103
|
+
id,
|
|
104
|
+
collection,
|
|
105
|
+
context,
|
|
106
|
+
doc,
|
|
107
|
+
fields: field.fields,
|
|
108
|
+
overrideAccess,
|
|
109
|
+
path: [
|
|
110
|
+
...fieldPath,
|
|
111
|
+
i
|
|
112
|
+
],
|
|
113
|
+
req,
|
|
114
|
+
schemaPath: fieldSchemaPath,
|
|
115
|
+
siblingDoc: row
|
|
116
|
+
}));
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
break;
|
|
120
|
+
}
|
|
121
|
+
case 'blocks':
|
|
122
|
+
{
|
|
123
|
+
const rows = fieldData[locale];
|
|
124
|
+
if (Array.isArray(rows)) {
|
|
125
|
+
const promises = [];
|
|
126
|
+
rows.forEach((row, i)=>{
|
|
127
|
+
const blockTypeToMatch = row.blockType;
|
|
128
|
+
const block = field.blocks.find((blockType)=>blockType.slug === blockTypeToMatch);
|
|
129
|
+
promises.push(traverseFields({
|
|
130
|
+
id,
|
|
131
|
+
collection,
|
|
132
|
+
context,
|
|
133
|
+
doc,
|
|
134
|
+
fields: block.fields,
|
|
135
|
+
overrideAccess,
|
|
136
|
+
path: [
|
|
137
|
+
...fieldPath,
|
|
138
|
+
i
|
|
139
|
+
],
|
|
140
|
+
req,
|
|
141
|
+
schemaPath: fieldSchemaPath,
|
|
142
|
+
siblingDoc: row
|
|
143
|
+
}));
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
break;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
await Promise.all(promises);
|
|
152
|
+
} else {
|
|
153
|
+
// If the field is not localized, but it affects data,
|
|
154
|
+
// we need to further traverse its children
|
|
155
|
+
// so the child fields can run beforeDuplicate hooks
|
|
156
|
+
switch(field.type){
|
|
157
|
+
case 'tab':
|
|
158
|
+
case 'group':
|
|
159
|
+
{
|
|
160
|
+
if (field.type === 'tab' && !tabHasName(field)) {
|
|
161
|
+
await traverseFields({
|
|
162
|
+
id,
|
|
163
|
+
collection,
|
|
164
|
+
context,
|
|
165
|
+
doc,
|
|
166
|
+
fields: field.fields,
|
|
167
|
+
overrideAccess,
|
|
168
|
+
path: fieldPath,
|
|
169
|
+
req,
|
|
170
|
+
schemaPath: fieldSchemaPath,
|
|
171
|
+
siblingDoc
|
|
172
|
+
});
|
|
173
|
+
} else {
|
|
174
|
+
if (typeof siblingDoc[field.name] !== 'object') {
|
|
175
|
+
siblingDoc[field.name] = {};
|
|
176
|
+
}
|
|
177
|
+
const groupDoc = siblingDoc[field.name];
|
|
178
|
+
await traverseFields({
|
|
179
|
+
id,
|
|
180
|
+
collection,
|
|
181
|
+
context,
|
|
182
|
+
doc,
|
|
183
|
+
fields: field.fields,
|
|
184
|
+
overrideAccess,
|
|
185
|
+
path: fieldPath,
|
|
186
|
+
req,
|
|
187
|
+
schemaPath: fieldSchemaPath,
|
|
188
|
+
siblingDoc: groupDoc
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
break;
|
|
192
|
+
}
|
|
193
|
+
case 'array':
|
|
194
|
+
{
|
|
195
|
+
const rows = siblingDoc[field.name];
|
|
196
|
+
if (Array.isArray(rows)) {
|
|
197
|
+
const promises = [];
|
|
198
|
+
rows.forEach((row, i)=>{
|
|
199
|
+
promises.push(traverseFields({
|
|
200
|
+
id,
|
|
201
|
+
collection,
|
|
202
|
+
context,
|
|
203
|
+
doc,
|
|
204
|
+
fields: field.fields,
|
|
205
|
+
overrideAccess,
|
|
206
|
+
path: [
|
|
207
|
+
...fieldPath,
|
|
208
|
+
i
|
|
209
|
+
],
|
|
210
|
+
req,
|
|
211
|
+
schemaPath: fieldSchemaPath,
|
|
212
|
+
siblingDoc: row
|
|
213
|
+
}));
|
|
214
|
+
});
|
|
215
|
+
await Promise.all(promises);
|
|
216
|
+
}
|
|
217
|
+
break;
|
|
218
|
+
}
|
|
219
|
+
case 'blocks':
|
|
220
|
+
{
|
|
221
|
+
const rows = siblingDoc[field.name];
|
|
222
|
+
if (Array.isArray(rows)) {
|
|
223
|
+
const promises = [];
|
|
224
|
+
rows.forEach((row, i)=>{
|
|
225
|
+
const blockTypeToMatch = row.blockType;
|
|
226
|
+
const block = field.blocks.find((blockType)=>blockType.slug === blockTypeToMatch);
|
|
227
|
+
if (block) {
|
|
228
|
+
row.blockType = blockTypeToMatch;
|
|
229
|
+
promises.push(traverseFields({
|
|
230
|
+
id,
|
|
231
|
+
collection,
|
|
232
|
+
context,
|
|
233
|
+
doc,
|
|
234
|
+
fields: block.fields,
|
|
235
|
+
overrideAccess,
|
|
236
|
+
path: [
|
|
237
|
+
...fieldPath,
|
|
238
|
+
i
|
|
239
|
+
],
|
|
240
|
+
req,
|
|
241
|
+
schemaPath: fieldSchemaPath,
|
|
242
|
+
siblingDoc: row
|
|
243
|
+
}));
|
|
244
|
+
}
|
|
245
|
+
});
|
|
246
|
+
await Promise.all(promises);
|
|
247
|
+
}
|
|
248
|
+
break;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
} else {
|
|
253
|
+
// Finally, we traverse fields which do not affect data here
|
|
254
|
+
switch(field.type){
|
|
255
|
+
case 'row':
|
|
256
|
+
case 'collapsible':
|
|
257
|
+
{
|
|
258
|
+
await traverseFields({
|
|
259
|
+
id,
|
|
260
|
+
collection,
|
|
261
|
+
context,
|
|
262
|
+
doc,
|
|
263
|
+
fields: field.fields,
|
|
264
|
+
overrideAccess,
|
|
265
|
+
path: fieldPath,
|
|
266
|
+
req,
|
|
267
|
+
schemaPath: fieldSchemaPath,
|
|
268
|
+
siblingDoc
|
|
269
|
+
});
|
|
270
|
+
break;
|
|
271
|
+
}
|
|
272
|
+
case 'tabs':
|
|
273
|
+
{
|
|
274
|
+
await traverseFields({
|
|
275
|
+
id,
|
|
276
|
+
collection,
|
|
277
|
+
context,
|
|
278
|
+
doc,
|
|
279
|
+
fields: field.tabs.map((tab)=>({
|
|
280
|
+
...tab,
|
|
281
|
+
type: 'tab'
|
|
282
|
+
})),
|
|
283
|
+
overrideAccess,
|
|
284
|
+
path: fieldPath,
|
|
285
|
+
req,
|
|
286
|
+
schemaPath: fieldSchemaPath,
|
|
287
|
+
siblingDoc
|
|
288
|
+
});
|
|
289
|
+
break;
|
|
290
|
+
}
|
|
291
|
+
default:
|
|
292
|
+
{
|
|
293
|
+
break;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
};
|
|
298
|
+
|
|
299
|
+
//# sourceMappingURL=promise.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/fields/hooks/beforeDuplicate/promise.ts"],"sourcesContent":["import type { SanitizedCollectionConfig } from '../../../collections/config/types.js'\nimport type { JsonObject, PayloadRequest, RequestContext } from '../../../types/index.js'\nimport type { Field, FieldHookArgs, TabAsField } from '../../config/types.js'\n\nimport { fieldAffectsData, tabHasName } from '../../config/types.js'\nimport { getFieldPaths } from '../../getFieldPaths.js'\nimport { runBeforeDuplicateHooks } from './runHook.js'\nimport { traverseFields } from './traverseFields.js'\n\ntype Args<T> = {\n collection: null | SanitizedCollectionConfig\n context: RequestContext\n doc: T\n field: Field | TabAsField\n id?: number | string\n overrideAccess: boolean\n parentPath: (number | string)[]\n parentSchemaPath: string[]\n req: PayloadRequest\n siblingDoc: JsonObject\n}\n\nexport const promise = async <T>({\n id,\n collection,\n context,\n doc,\n field,\n overrideAccess,\n parentPath,\n parentSchemaPath,\n req,\n siblingDoc,\n}: Args<T>): Promise<void> => {\n const { localization } = req.payload.config\n\n const { path: fieldPath, schemaPath: fieldSchemaPath } = getFieldPaths({\n field,\n parentPath,\n parentSchemaPath,\n })\n\n if (fieldAffectsData(field)) {\n let fieldData = siblingDoc?.[field.name]\n const fieldIsLocalized = field.localized && localization\n\n // Run field beforeDuplicate hooks\n if (Array.isArray(field.hooks?.beforeDuplicate)) {\n if (fieldIsLocalized) {\n const localeData = await localization.localeCodes.reduce(\n async (localizedValuesPromise: Promise<JsonObject>, locale) => {\n const localizedValues = await localizedValuesPromise\n\n const beforeDuplicateArgs: FieldHookArgs = {\n collection,\n context,\n data: doc,\n field,\n global: undefined,\n path: fieldPath,\n previousSiblingDoc: siblingDoc,\n previousValue: siblingDoc[field.name]?.[locale],\n req,\n schemaPath: parentSchemaPath,\n siblingData: siblingDoc,\n siblingDocWithLocales: siblingDoc,\n value: siblingDoc[field.name]?.[locale],\n }\n\n const hookResult = await runBeforeDuplicateHooks(beforeDuplicateArgs)\n\n if (typeof hookResult !== 'undefined') {\n return {\n ...localizedValues,\n [locale]: hookResult,\n }\n }\n\n return localizedValuesPromise\n },\n Promise.resolve({}),\n )\n\n siblingDoc[field.name] = localeData\n } else {\n const beforeDuplicateArgs: FieldHookArgs = {\n collection,\n context,\n data: doc,\n field,\n global: undefined,\n path: fieldPath,\n previousSiblingDoc: siblingDoc,\n previousValue: siblingDoc[field.name],\n req,\n schemaPath: parentSchemaPath,\n siblingData: siblingDoc,\n siblingDocWithLocales: siblingDoc,\n value: siblingDoc[field.name],\n }\n\n const hookResult = await runBeforeDuplicateHooks(beforeDuplicateArgs)\n if (typeof hookResult !== 'undefined') {\n siblingDoc[field.name] = hookResult\n }\n }\n }\n\n // First, for any localized fields, we will loop over locales\n // and if locale data is present, traverse the sub fields.\n // There are only a few different fields where this is possible.\n if (fieldIsLocalized) {\n if (typeof fieldData !== 'object' || fieldData === null) {\n siblingDoc[field.name] = {}\n fieldData = siblingDoc[field.name]\n }\n\n const promises = []\n\n localization.localeCodes.forEach((locale) => {\n if (fieldData[locale]) {\n switch (field.type) {\n case 'tab':\n case 'group': {\n promises.push(\n traverseFields({\n id,\n collection,\n context,\n doc,\n fields: field.fields,\n overrideAccess,\n path: fieldSchemaPath,\n req,\n schemaPath: fieldSchemaPath,\n siblingDoc: fieldData[locale],\n }),\n )\n\n break\n }\n\n case 'array': {\n const rows = fieldData[locale]\n\n if (Array.isArray(rows)) {\n const promises = []\n rows.forEach((row, i) => {\n promises.push(\n traverseFields({\n id,\n collection,\n context,\n doc,\n fields: field.fields,\n overrideAccess,\n path: [...fieldPath, i],\n req,\n schemaPath: fieldSchemaPath,\n siblingDoc: row,\n }),\n )\n })\n }\n break\n }\n\n case 'blocks': {\n const rows = fieldData[locale]\n\n if (Array.isArray(rows)) {\n const promises = []\n rows.forEach((row, i) => {\n const blockTypeToMatch = row.blockType\n\n const block = field.blocks.find(\n (blockType) => blockType.slug === blockTypeToMatch,\n )\n\n promises.push(\n traverseFields({\n id,\n collection,\n context,\n doc,\n fields: block.fields,\n overrideAccess,\n path: [...fieldPath, i],\n req,\n schemaPath: fieldSchemaPath,\n siblingDoc: row,\n }),\n )\n })\n }\n break\n }\n }\n }\n })\n\n await Promise.all(promises)\n } else {\n // If the field is not localized, but it affects data,\n // we need to further traverse its children\n // so the child fields can run beforeDuplicate hooks\n switch (field.type) {\n case 'tab':\n case 'group': {\n if (field.type === 'tab' && !tabHasName(field)) {\n await traverseFields({\n id,\n collection,\n context,\n doc,\n fields: field.fields,\n overrideAccess,\n path: fieldPath,\n req,\n schemaPath: fieldSchemaPath,\n siblingDoc,\n })\n } else {\n if (typeof siblingDoc[field.name] !== 'object') {\n siblingDoc[field.name] = {}\n }\n\n const groupDoc = siblingDoc[field.name] as Record<string, unknown>\n\n await traverseFields({\n id,\n collection,\n context,\n doc,\n fields: field.fields,\n overrideAccess,\n path: fieldPath,\n req,\n schemaPath: fieldSchemaPath,\n siblingDoc: groupDoc as JsonObject,\n })\n }\n\n break\n }\n\n case 'array': {\n const rows = siblingDoc[field.name]\n\n if (Array.isArray(rows)) {\n const promises = []\n rows.forEach((row, i) => {\n promises.push(\n traverseFields({\n id,\n collection,\n context,\n doc,\n fields: field.fields,\n overrideAccess,\n path: [...fieldPath, i],\n req,\n schemaPath: fieldSchemaPath,\n siblingDoc: row,\n }),\n )\n })\n await Promise.all(promises)\n }\n break\n }\n\n case 'blocks': {\n const rows = siblingDoc[field.name]\n\n if (Array.isArray(rows)) {\n const promises = []\n rows.forEach((row, i) => {\n const blockTypeToMatch = row.blockType\n const block = field.blocks.find((blockType) => blockType.slug === blockTypeToMatch)\n\n if (block) {\n ;(row as JsonObject).blockType = blockTypeToMatch\n\n promises.push(\n traverseFields({\n id,\n collection,\n context,\n doc,\n fields: block.fields,\n overrideAccess,\n path: [...fieldPath, i],\n req,\n schemaPath: fieldSchemaPath,\n siblingDoc: row,\n }),\n )\n }\n })\n await Promise.all(promises)\n }\n\n break\n }\n }\n }\n } else {\n // Finally, we traverse fields which do not affect data here\n switch (field.type) {\n case 'row':\n case 'collapsible': {\n await traverseFields({\n id,\n collection,\n context,\n doc,\n fields: field.fields,\n overrideAccess,\n path: fieldPath,\n req,\n schemaPath: fieldSchemaPath,\n siblingDoc,\n })\n\n break\n }\n\n case 'tabs': {\n await traverseFields({\n id,\n collection,\n context,\n doc,\n fields: field.tabs.map((tab) => ({ ...tab, type: 'tab' })),\n overrideAccess,\n path: fieldPath,\n req,\n schemaPath: fieldSchemaPath,\n siblingDoc,\n })\n\n break\n }\n\n default: {\n break\n }\n }\n }\n}\n"],"names":["fieldAffectsData","tabHasName","getFieldPaths","runBeforeDuplicateHooks","traverseFields","promise","id","collection","context","doc","field","overrideAccess","parentPath","parentSchemaPath","req","siblingDoc","localization","payload","config","path","fieldPath","schemaPath","fieldSchemaPath","fieldData","name","fieldIsLocalized","localized","Array","isArray","hooks","beforeDuplicate","localeData","localeCodes","reduce","localizedValuesPromise","locale","localizedValues","beforeDuplicateArgs","data","global","undefined","previousSiblingDoc","previousValue","siblingData","siblingDocWithLocales","value","hookResult","Promise","resolve","promises","forEach","type","push","fields","rows","row","i","blockTypeToMatch","blockType","block","blocks","find","slug","all","groupDoc","tabs","map","tab"],"mappings":"AAIA,SAASA,gBAAgB,EAAEC,UAAU,QAAQ,wBAAuB;AACpE,SAASC,aAAa,QAAQ,yBAAwB;AACtD,SAASC,uBAAuB,QAAQ,eAAc;AACtD,SAASC,cAAc,QAAQ,sBAAqB;AAepD,OAAO,MA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EA;oBACF;YACF;QACF;IACF,OAAO;QACL,4DAA4D;QAC5D,OAAQvC,MAAMyC,IAAI;YAChB,KAAK;YACL,KAAK;gBAAe;oBAClB,MAAM/C,eAAe;wBACnBE;wBACAC;wBACAC;wBACAC;wBACA4C,QAAQ3C,MAAM2C,MAAM;wBACpB1C;wBACAQ,MAAMC;wBACNN;wBACAO,YAAYC;wBACZP;oBACF;oBAEA;gBACF;YAEA,KAAK;gBAAQ;oBACX,MAAMX,eAAe;wBACnBE;wBACAC;wBACAC;wBACAC;wBACA4C,QAAQ3C,MAAMuD,IAAI,CAACC,GAAG,CAAC,CAACC,MAAS,CAAA;gCAAE,GAAGA,GAAG;gCAAEhB,MAAM;4BAAM,CAAA;wBACvDxC;wBACAQ,MAAMC;wBACNN;wBACAO,YAAYC;wBACZP;oBACF;oBAEA;gBACF;YAEA;gBAAS;oBACP;gBACF;QACF;IACF;AACF,EAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runHook.d.ts","sourceRoot":"","sources":["../../../../src/fields/hooks/beforeDuplicate/runHook.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAA;AAE1D,eAAO,MAAM,uBAAuB,SAAgB,aAAa,iBAI1C,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/fields/hooks/beforeDuplicate/runHook.ts"],"sourcesContent":["import type { FieldHookArgs } from '../../config/types.js'\n\nexport const runBeforeDuplicateHooks = async (args: FieldHookArgs) =>\n await args.field.hooks.beforeDuplicate.reduce(async (priorHook, currentHook) => {\n await priorHook\n return await currentHook(args)\n }, Promise.resolve())\n"],"names":["runBeforeDuplicateHooks","args","field","hooks","beforeDuplicate","reduce","priorHook","currentHook","Promise","resolve"],"mappings":"AAEA,OAAO,MAAMA,0BAA0B,OAAOC,OAC5C,MAAMA,KAAKC,KAAK,CAACC,KAAK,CAACC,eAAe,CAACC,MAAM,CAAC,OAAOC,WAAWC;QAC9D,MAAMD;QACN,OAAO,MAAMC,YAAYN;IAC3B,GAAGO,QAAQC,OAAO,IAAG"}
|