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,"file":"duplicate.d.ts","sourceRoot":"","sources":["../../../src/collections/operations/duplicate.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AACpD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAC1D,OAAO,KAAK,EAAE,UAAU,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAA;
|
|
1
|
+
{"version":3,"file":"duplicate.d.ts","sourceRoot":"","sources":["../../../src/collections/operations/duplicate.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AACpD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAC1D,OAAO,KAAK,EAAE,UAAU,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAA;AAkB5E,MAAM,MAAM,SAAS,GAAG;IACtB,UAAU,EAAE,UAAU,CAAA;IACtB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,EAAE,EAAE,MAAM,GAAG,MAAM,CAAA;IACnB,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,GAAG,EAAE,cAAc,CAAA;IACnB,gBAAgB,CAAC,EAAE,OAAO,CAAA;CAC3B,CAAA;AAED,eAAO,MAAM,kBAAkB,GAAU,KAAK,SAAS,cAAc,gBACrD,SAAS,KACtB,OAAO,CAAC,sBAAsB,CAAC,KAAK,CAAC,CAuTvC,CAAA"}
|
|
@@ -6,6 +6,7 @@ import { APIError, Forbidden, NotFound } from '../../errors/index.js';
|
|
|
6
6
|
import { afterChange } from '../../fields/hooks/afterChange/index.js';
|
|
7
7
|
import { afterRead } from '../../fields/hooks/afterRead/index.js';
|
|
8
8
|
import { beforeChange } from '../../fields/hooks/beforeChange/index.js';
|
|
9
|
+
import { beforeDuplicate } from '../../fields/hooks/beforeDuplicate/index.js';
|
|
9
10
|
import { beforeValidate } from '../../fields/hooks/beforeValidate/index.js';
|
|
10
11
|
import { commitTransaction } from '../../utilities/commitTransaction.js';
|
|
11
12
|
import { initTransaction } from '../../utilities/initTransaction.js';
|
|
@@ -57,7 +58,7 @@ export const duplicateOperation = async (incomingArgs)=>{
|
|
|
57
58
|
}
|
|
58
59
|
}, accessResults)
|
|
59
60
|
};
|
|
60
|
-
|
|
61
|
+
let docWithLocales = await getLatestCollectionVersion({
|
|
61
62
|
id,
|
|
62
63
|
config: collectionConfig,
|
|
63
64
|
payload,
|
|
@@ -73,6 +74,14 @@ export const duplicateOperation = async (incomingArgs)=>{
|
|
|
73
74
|
// remove the createdAt timestamp and id to rely on the db to set the default it
|
|
74
75
|
delete docWithLocales.createdAt;
|
|
75
76
|
delete docWithLocales.id;
|
|
77
|
+
docWithLocales = await beforeDuplicate({
|
|
78
|
+
id,
|
|
79
|
+
collection: collectionConfig,
|
|
80
|
+
context: req.context,
|
|
81
|
+
doc: docWithLocales,
|
|
82
|
+
overrideAccess,
|
|
83
|
+
req
|
|
84
|
+
});
|
|
76
85
|
// for version enabled collections, override the current status with draft, unless draft is explicitly set to false
|
|
77
86
|
if (shouldSaveDraft) {
|
|
78
87
|
docWithLocales._status = 'draft';
|
|
@@ -153,7 +162,6 @@ export const duplicateOperation = async (incomingArgs)=>{
|
|
|
153
162
|
data,
|
|
154
163
|
doc: originalDoc,
|
|
155
164
|
docWithLocales,
|
|
156
|
-
duplicate: true,
|
|
157
165
|
global: null,
|
|
158
166
|
operation,
|
|
159
167
|
req,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/collections/operations/duplicate.ts"],"sourcesContent":["import type { DeepPartial } from 'ts-essentials'\n\nimport httpStatus from 'http-status'\n\nimport type { FindOneArgs } from '../../database/types.js'\nimport type { CollectionSlug } from '../../index.js'\nimport type { PayloadRequest } from '../../types/index.js'\nimport type { Collection, DataFromCollectionSlug } from '../config/types.js'\n\nimport executeAccess from '../../auth/executeAccess.js'\nimport { hasWhereAccessResult } from '../../auth/types.js'\nimport { combineQueries } from '../../database/combineQueries.js'\nimport { APIError, Forbidden, NotFound } from '../../errors/index.js'\nimport { afterChange } from '../../fields/hooks/afterChange/index.js'\nimport { afterRead } from '../../fields/hooks/afterRead/index.js'\nimport { beforeChange } from '../../fields/hooks/beforeChange/index.js'\nimport { beforeValidate } from '../../fields/hooks/beforeValidate/index.js'\nimport { commitTransaction } from '../../utilities/commitTransaction.js'\nimport { initTransaction } from '../../utilities/initTransaction.js'\nimport { killTransaction } from '../../utilities/killTransaction.js'\nimport { getLatestCollectionVersion } from '../../versions/getLatestCollectionVersion.js'\nimport { saveVersion } from '../../versions/saveVersion.js'\nimport { buildAfterOperation } from './utils.js'\n\nexport type Arguments = {\n collection: Collection\n depth?: number\n draft?: boolean\n id: number | string\n overrideAccess?: boolean\n req: PayloadRequest\n showHiddenFields?: boolean\n}\n\nexport const duplicateOperation = async <TSlug extends CollectionSlug>(\n incomingArgs: Arguments,\n): Promise<DataFromCollectionSlug<TSlug>> => {\n let args = incomingArgs\n const operation = 'create'\n\n try {\n const shouldCommit = await initTransaction(args.req)\n\n // /////////////////////////////////////\n // beforeOperation - Collection\n // /////////////////////////////////////\n\n await args.collection.config.hooks.beforeOperation.reduce(async (priorHook, hook) => {\n await priorHook\n\n args =\n (await hook({\n args,\n collection: args.collection.config,\n context: args.req.context,\n operation,\n req: args.req,\n })) || args\n }, Promise.resolve())\n\n const {\n id,\n collection: { config: collectionConfig },\n depth,\n draft: draftArg = true,\n overrideAccess,\n req: { fallbackLocale, locale: localeArg, payload },\n req,\n showHiddenFields,\n } = args\n\n if (!id) {\n throw new APIError('Missing ID of document to duplicate.', httpStatus.BAD_REQUEST)\n }\n const shouldSaveDraft = Boolean(draftArg && collectionConfig.versions.drafts)\n\n // /////////////////////////////////////\n // Read Access\n // /////////////////////////////////////\n\n const accessResults = !overrideAccess\n ? await executeAccess({ id, req }, collectionConfig.access.read)\n : true\n const hasWherePolicy = hasWhereAccessResult(accessResults)\n\n // /////////////////////////////////////\n // Retrieve document\n // /////////////////////////////////////\n const findOneArgs: FindOneArgs = {\n collection: collectionConfig.slug,\n locale: req.locale,\n req,\n where: combineQueries({ id: { equals: id } }, accessResults),\n }\n\n const docWithLocales = await getLatestCollectionVersion({\n id,\n config: collectionConfig,\n payload,\n query: findOneArgs,\n req,\n })\n\n if (!docWithLocales && !hasWherePolicy) {\n throw new NotFound(req.t)\n }\n if (!docWithLocales && hasWherePolicy) {\n throw new Forbidden(req.t)\n }\n\n // remove the createdAt timestamp and id to rely on the db to set the default it\n delete docWithLocales.createdAt\n delete docWithLocales.id\n\n // for version enabled collections, override the current status with draft, unless draft is explicitly set to false\n if (shouldSaveDraft) {\n docWithLocales._status = 'draft'\n }\n\n let result\n\n const originalDoc = await afterRead({\n collection: collectionConfig,\n context: req.context,\n depth: 0,\n doc: docWithLocales,\n draft: draftArg,\n fallbackLocale: null,\n global: null,\n locale: req.locale,\n overrideAccess: true,\n req,\n showHiddenFields: true,\n })\n\n // /////////////////////////////////////\n // Create Access\n // /////////////////////////////////////\n\n if (!overrideAccess) {\n await executeAccess({ data: originalDoc, req }, collectionConfig.access.create)\n }\n\n // /////////////////////////////////////\n // beforeValidate - Fields\n // /////////////////////////////////////\n\n let data = await beforeValidate<DeepPartial<DataFromCollectionSlug<TSlug>>>({\n id,\n collection: collectionConfig,\n context: req.context,\n data: originalDoc,\n doc: originalDoc,\n duplicate: true,\n global: null,\n operation,\n overrideAccess,\n req,\n })\n\n // /////////////////////////////////////\n // beforeValidate - Collection\n // /////////////////////////////////////\n\n await collectionConfig.hooks.beforeValidate.reduce(async (priorHook, hook) => {\n await priorHook\n\n data =\n (await hook({\n collection: collectionConfig,\n context: req.context,\n data,\n operation,\n originalDoc,\n req,\n })) || result\n }, Promise.resolve())\n\n // /////////////////////////////////////\n // beforeChange - Collection\n // /////////////////////////////////////\n\n await collectionConfig.hooks.beforeChange.reduce(async (priorHook, hook) => {\n await priorHook\n\n data =\n (await hook({\n collection: collectionConfig,\n context: req.context,\n data,\n operation,\n originalDoc: result,\n req,\n })) || result\n }, Promise.resolve())\n\n // /////////////////////////////////////\n // beforeChange - Fields\n // /////////////////////////////////////\n\n result = await beforeChange({\n id,\n collection: collectionConfig,\n context: req.context,\n data,\n doc: originalDoc,\n docWithLocales,\n duplicate: true,\n global: null,\n operation,\n req,\n skipValidation:\n shouldSaveDraft &&\n collectionConfig.versions.drafts &&\n !collectionConfig.versions.drafts.validate,\n })\n\n // set req.locale back to the original locale\n req.locale = localeArg\n\n // /////////////////////////////////////\n // Create / Update\n // /////////////////////////////////////\n\n const versionDoc = await payload.db.create({\n collection: collectionConfig.slug,\n data: result,\n req,\n })\n\n // /////////////////////////////////////\n // Create version\n // /////////////////////////////////////\n\n if (collectionConfig.versions) {\n result = await saveVersion({\n id: versionDoc.id,\n collection: collectionConfig,\n docWithLocales: {\n ...versionDoc,\n createdAt: result.createdAt,\n },\n draft: shouldSaveDraft,\n payload,\n req,\n })\n }\n\n // /////////////////////////////////////\n // afterRead - Fields\n // /////////////////////////////////////\n\n result = await afterRead({\n collection: collectionConfig,\n context: req.context,\n depth,\n doc: versionDoc,\n draft: draftArg,\n fallbackLocale,\n global: null,\n locale: localeArg,\n overrideAccess,\n req,\n showHiddenFields,\n })\n\n // /////////////////////////////////////\n // afterRead - Collection\n // /////////////////////////////////////\n\n await collectionConfig.hooks.afterRead.reduce(async (priorHook, hook) => {\n await priorHook\n\n result =\n (await hook({\n collection: collectionConfig,\n context: req.context,\n doc: result,\n req,\n })) || result\n }, Promise.resolve())\n\n // /////////////////////////////////////\n // afterChange - Fields\n // /////////////////////////////////////\n\n result = await afterChange({\n collection: collectionConfig,\n context: req.context,\n data: versionDoc,\n doc: result,\n global: null,\n operation,\n previousDoc: {},\n req,\n })\n\n // /////////////////////////////////////\n // afterChange - Collection\n // /////////////////////////////////////\n\n await collectionConfig.hooks.afterChange.reduce(async (priorHook, hook) => {\n await priorHook\n\n result =\n (await hook({\n collection: collectionConfig,\n context: req.context,\n doc: result,\n operation,\n previousDoc: {},\n req,\n })) || result\n }, Promise.resolve())\n\n // /////////////////////////////////////\n // afterOperation - Collection\n // /////////////////////////////////////\n\n result = await buildAfterOperation({\n args,\n collection: collectionConfig,\n operation,\n result,\n })\n\n // /////////////////////////////////////\n // Return results\n // /////////////////////////////////////\n\n if (shouldCommit) {\n await commitTransaction(req)\n }\n\n return result\n } catch (error: unknown) {\n await killTransaction(args.req)\n throw error\n }\n}\n"],"names":["httpStatus","executeAccess","hasWhereAccessResult","combineQueries","APIError","Forbidden","NotFound","afterChange","afterRead","beforeChange","beforeValidate","commitTransaction","initTransaction","killTransaction","getLatestCollectionVersion","saveVersion","buildAfterOperation","duplicateOperation","incomingArgs","args","operation","shouldCommit","req","collection","config","hooks","beforeOperation","reduce","priorHook","hook","context","Promise","resolve","id","collectionConfig","depth","draft","draftArg","overrideAccess","fallbackLocale","locale","localeArg","payload","showHiddenFields","BAD_REQUEST","shouldSaveDraft","Boolean","versions","drafts","accessResults","access","read","hasWherePolicy","findOneArgs","slug","where","equals","docWithLocales","query","t","createdAt","_status","result","originalDoc","doc","global","data","create","duplicate","skipValidation","validate","versionDoc","db","previousDoc","error"],"mappings":"AAEA,OAAOA,gBAAgB,cAAa;AAOpC,OAAOC,mBAAmB,8BAA6B;AACvD,SAASC,oBAAoB,QAAQ,sBAAqB;AAC1D,SAASC,cAAc,QAAQ,mCAAkC;AACjE,SAASC,QAAQ,EAAEC,SAAS,EAAEC,QAAQ,QAAQ,wBAAuB;AACrE,SAASC,WAAW,QAAQ,0CAAyC;AACrE,SAASC,SAAS,QAAQ,wCAAuC;AACjE,SAASC,YAAY,QAAQ,2CAA0C;AACvE,SAASC,cAAc,QAAQ,6CAA4C;AAC3E,SAASC,iBAAiB,QAAQ,uCAAsC;AACxE,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,0BAA0B,QAAQ,+CAA8C;AACzF,SAASC,WAAW,QAAQ,gCAA+B;AAC3D,SAASC,mBAAmB,QAAQ,aAAY;AAYhD,OAAO,MAAMC,qBAAqB,OAChCC;IAEA,IAAIC,OAAOD;IACX,MAAME,YAAY;IAElB,IAAI;QACF,MAAMC,eAAe,MAAMT,gBAAgBO,KAAKG,GAAG;QAEnD,wCAAwC;QACxC,+BAA+B;QAC/B,wCAAwC;QAExC,MAAMH,KAAKI,UAAU,CAACC,MAAM,CAACC,KAAK,CAACC,eAAe,CAACC,MAAM,CAAC,OAAOC,WAAWC;YAC1E,MAAMD;YAENT,OACE,AAAC,MAAMU,KAAK;gBACVV;gBACAI,YAAYJ,KAAKI,UAAU,CAACC,MAAM;gBAClCM,SAASX,KAAKG,GAAG,CAACQ,OAAO;gBACzBV;gBACAE,KAAKH,KAAKG,G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wCAAwC;QACxC,uBAAuB;QACvB,wCAAwC;QAExC8B,SAAS,MAAMvD,YAAY;YACzBgB,YAAYW;YACZJ,SAASR,IAAIQ,OAAO;YACpBoC,MAAMK;YACNP,KAAKF;YACLG,QAAQ;YACR7C;YACAqD,aAAa,CAAC;YACdnD;QACF;QAEA,wCAAwC;QACxC,2BAA2B;QAC3B,wCAAwC;QAExC,MAAMY,iBAAiBT,KAAK,CAAClB,WAAW,CAACoB,MAAM,CAAC,OAAOC,WAAWC;YAChE,MAAMD;YAENkC,SACE,AAAC,MAAMjC,KAAK;gBACVN,YAAYW;gBACZJ,SAASR,IAAIQ,OAAO;gBACpBkC,KAAKF;gBACL1C;gBACAqD,aAAa,CAAC;gBACdnD;YACF,MAAOwC;QACX,GAAG/B,QAAQC,OAAO;QAElB,wCAAwC;QACxC,8BAA8B;QAC9B,wCAAwC;QAExC8B,SAAS,MAAM9C,oBAAoB;YACjCG;YACAI,YAAYW;YACZd;YACA0C;QACF;QAEA,wCAAwC;QACxC,iBAAiB;QACjB,wCAAwC;QAExC,IAAIzC,cAAc;YAChB,MAAMV,kBAAkBW;QAC1B;QAEA,OAAOwC;IACT,EAAE,OAAOY,OAAgB;QACvB,MAAM7D,gBAAgBM,KAAKG,GAAG;QAC9B,MAAMoD;IACR;AACF,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../../src/collections/operations/duplicate.ts"],"sourcesContent":["import type { DeepPartial } from 'ts-essentials'\n\nimport httpStatus from 'http-status'\n\nimport type { FindOneArgs } from '../../database/types.js'\nimport type { CollectionSlug } from '../../index.js'\nimport type { PayloadRequest } from '../../types/index.js'\nimport type { Collection, DataFromCollectionSlug } from '../config/types.js'\n\nimport executeAccess from '../../auth/executeAccess.js'\nimport { hasWhereAccessResult } from '../../auth/types.js'\nimport { combineQueries } from '../../database/combineQueries.js'\nimport { APIError, Forbidden, NotFound } from '../../errors/index.js'\nimport { afterChange } from '../../fields/hooks/afterChange/index.js'\nimport { afterRead } from '../../fields/hooks/afterRead/index.js'\nimport { beforeChange } from '../../fields/hooks/beforeChange/index.js'\nimport { beforeDuplicate } from '../../fields/hooks/beforeDuplicate/index.js'\nimport { beforeValidate } from '../../fields/hooks/beforeValidate/index.js'\nimport { commitTransaction } from '../../utilities/commitTransaction.js'\nimport { initTransaction } from '../../utilities/initTransaction.js'\nimport { killTransaction } from '../../utilities/killTransaction.js'\nimport { getLatestCollectionVersion } from '../../versions/getLatestCollectionVersion.js'\nimport { saveVersion } from '../../versions/saveVersion.js'\nimport { buildAfterOperation } from './utils.js'\n\nexport type Arguments = {\n collection: Collection\n depth?: number\n draft?: boolean\n id: number | string\n overrideAccess?: boolean\n req: PayloadRequest\n showHiddenFields?: boolean\n}\n\nexport const duplicateOperation = async <TSlug extends CollectionSlug>(\n incomingArgs: Arguments,\n): Promise<DataFromCollectionSlug<TSlug>> => {\n let args = incomingArgs\n const operation = 'create'\n\n try {\n const shouldCommit = await initTransaction(args.req)\n\n // /////////////////////////////////////\n // beforeOperation - Collection\n // /////////////////////////////////////\n\n await args.collection.config.hooks.beforeOperation.reduce(async (priorHook, hook) => {\n await priorHook\n\n args =\n (await hook({\n args,\n collection: args.collection.config,\n context: args.req.context,\n operation,\n req: args.req,\n })) || args\n }, Promise.resolve())\n\n const {\n id,\n collection: { config: collectionConfig },\n depth,\n draft: draftArg = true,\n overrideAccess,\n req: { fallbackLocale, locale: localeArg, payload },\n req,\n showHiddenFields,\n } = args\n\n if (!id) {\n throw new APIError('Missing ID of document to duplicate.', httpStatus.BAD_REQUEST)\n }\n const shouldSaveDraft = Boolean(draftArg && collectionConfig.versions.drafts)\n\n // /////////////////////////////////////\n // Read Access\n // /////////////////////////////////////\n\n const accessResults = !overrideAccess\n ? await executeAccess({ id, req }, collectionConfig.access.read)\n : true\n const hasWherePolicy = hasWhereAccessResult(accessResults)\n\n // /////////////////////////////////////\n // Retrieve document\n // /////////////////////////////////////\n const findOneArgs: FindOneArgs = {\n collection: collectionConfig.slug,\n locale: req.locale,\n req,\n where: combineQueries({ id: { equals: id } }, accessResults),\n }\n\n let docWithLocales = await getLatestCollectionVersion({\n id,\n config: collectionConfig,\n payload,\n query: findOneArgs,\n req,\n })\n\n if (!docWithLocales && !hasWherePolicy) {\n throw new NotFound(req.t)\n }\n if (!docWithLocales && hasWherePolicy) {\n throw new Forbidden(req.t)\n }\n\n // remove the createdAt timestamp and id to rely on the db to set the default it\n delete docWithLocales.createdAt\n delete docWithLocales.id\n\n docWithLocales = await beforeDuplicate({\n id,\n collection: collectionConfig,\n context: req.context,\n doc: docWithLocales,\n overrideAccess,\n req,\n })\n\n // for version enabled collections, override the current status with draft, unless draft is explicitly set to false\n if (shouldSaveDraft) {\n docWithLocales._status = 'draft'\n }\n\n let result\n\n const originalDoc = await afterRead({\n collection: collectionConfig,\n context: req.context,\n depth: 0,\n doc: docWithLocales,\n draft: draftArg,\n fallbackLocale: null,\n global: null,\n locale: req.locale,\n overrideAccess: true,\n req,\n showHiddenFields: true,\n })\n\n // /////////////////////////////////////\n // Create Access\n // /////////////////////////////////////\n\n if (!overrideAccess) {\n await executeAccess({ data: originalDoc, req }, collectionConfig.access.create)\n }\n\n // /////////////////////////////////////\n // beforeValidate - Fields\n // /////////////////////////////////////\n\n let data = await beforeValidate<DeepPartial<DataFromCollectionSlug<TSlug>>>({\n id,\n collection: collectionConfig,\n context: req.context,\n data: originalDoc,\n doc: originalDoc,\n duplicate: true,\n global: null,\n operation,\n overrideAccess,\n req,\n })\n\n // /////////////////////////////////////\n // beforeValidate - Collection\n // /////////////////////////////////////\n\n await collectionConfig.hooks.beforeValidate.reduce(async (priorHook, hook) => {\n await priorHook\n\n data =\n (await hook({\n collection: collectionConfig,\n context: req.context,\n data,\n operation,\n originalDoc,\n req,\n })) || result\n }, Promise.resolve())\n\n // /////////////////////////////////////\n // beforeChange - Collection\n // /////////////////////////////////////\n\n await collectionConfig.hooks.beforeChange.reduce(async (priorHook, hook) => {\n await priorHook\n\n data =\n (await hook({\n collection: collectionConfig,\n context: req.context,\n data,\n operation,\n originalDoc: result,\n req,\n })) || result\n }, Promise.resolve())\n\n // /////////////////////////////////////\n // beforeChange - Fields\n // /////////////////////////////////////\n\n result = await beforeChange({\n id,\n collection: collectionConfig,\n context: req.context,\n data,\n doc: originalDoc,\n docWithLocales,\n global: null,\n operation,\n req,\n skipValidation:\n shouldSaveDraft &&\n collectionConfig.versions.drafts &&\n !collectionConfig.versions.drafts.validate,\n })\n\n // set req.locale back to the original locale\n req.locale = localeArg\n\n // /////////////////////////////////////\n // Create / Update\n // /////////////////////////////////////\n\n const versionDoc = await payload.db.create({\n collection: collectionConfig.slug,\n data: result,\n req,\n })\n\n // /////////////////////////////////////\n // Create version\n // /////////////////////////////////////\n\n if (collectionConfig.versions) {\n result = await saveVersion({\n id: versionDoc.id,\n collection: collectionConfig,\n docWithLocales: {\n ...versionDoc,\n createdAt: result.createdAt,\n },\n draft: shouldSaveDraft,\n payload,\n req,\n })\n }\n\n // /////////////////////////////////////\n // afterRead - Fields\n // /////////////////////////////////////\n\n result = await afterRead({\n collection: collectionConfig,\n context: req.context,\n depth,\n doc: versionDoc,\n draft: draftArg,\n fallbackLocale,\n global: null,\n locale: localeArg,\n overrideAccess,\n req,\n showHiddenFields,\n })\n\n // /////////////////////////////////////\n // afterRead - Collection\n // /////////////////////////////////////\n\n await collectionConfig.hooks.afterRead.reduce(async (priorHook, hook) => {\n await priorHook\n\n result =\n (await hook({\n collection: collectionConfig,\n context: req.context,\n doc: result,\n req,\n })) || result\n }, Promise.resolve())\n\n // /////////////////////////////////////\n // afterChange - Fields\n // /////////////////////////////////////\n\n result = await afterChange({\n collection: collectionConfig,\n context: req.context,\n data: versionDoc,\n doc: result,\n global: null,\n operation,\n previousDoc: {},\n req,\n })\n\n // /////////////////////////////////////\n // afterChange - Collection\n // /////////////////////////////////////\n\n await collectionConfig.hooks.afterChange.reduce(async (priorHook, hook) => {\n await priorHook\n\n result =\n (await hook({\n collection: collectionConfig,\n context: req.context,\n doc: result,\n operation,\n previousDoc: {},\n req,\n })) || result\n }, Promise.resolve())\n\n // /////////////////////////////////////\n // afterOperation - Collection\n // /////////////////////////////////////\n\n result = await buildAfterOperation({\n args,\n collection: collectionConfig,\n operation,\n result,\n })\n\n // /////////////////////////////////////\n // Return results\n // /////////////////////////////////////\n\n if (shouldCommit) {\n await commitTransaction(req)\n }\n\n return result\n } catch (error: unknown) {\n await killTransaction(args.req)\n throw error\n }\n}\n"],"names":["httpStatus","executeAccess","hasWhereAccessResult","combineQueries","APIError","Forbidden","NotFound","afterChange","afterRead","beforeChange","beforeDuplicate","beforeValidate","commitTransaction","initTransaction","killTransaction","getLatestCollectionVersion","saveVersion","buildAfterOperation","duplicateOperation","incomingArgs","args","operation","shouldCommit","req","collection","config","hooks","beforeOperation","reduce","priorHook","hook","context","Promise","resolve","id","collectionConfig","depth","draft","draftArg","overrideAccess","fallbackLocale","locale","localeArg","payload","showHiddenFields","BAD_REQUEST","shouldSaveDraft","Boolean","versions","drafts","accessResults","access","read","hasWherePolicy","findOneArgs","slug","where","equals","docWithLocales","query","t","createdAt","doc","_status","result","originalDoc","global","data","create","duplicate","skipValidation","validate","versionDoc","db","previousDoc","error"],"mappings":"AAEA,OAAOA,gBAAgB,cAAa;AAOpC,OAAOC,mBAAmB,8BAA6B;AACvD,SAASC,oBAAoB,QAAQ,sBAAqB;AAC1D,SAASC,cAAc,QAAQ,mCAAkC;AACjE,SAASC,QAAQ,EAAEC,SAAS,EAAEC,QAAQ,QAAQ,wBAAuB;AACrE,SAASC,WAAW,QAAQ,0CAAyC;AACrE,SAASC,SAAS,QAAQ,wCAAuC;AACjE,SAASC,YAAY,QAAQ,2CAA0C;AACvE,SAASC,eAAe,QAAQ,8CAA6C;AAC7E,SAASC,cAAc,QAAQ,6CAA4C;AAC3E,SAASC,iBAAiB,QAAQ,uCAAsC;AACxE,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,0BAA0B,QAAQ,+C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ACF;QAEA,wCAAwC;QACxC,iBAAiB;QACjB,wCAAwC;QAExC,IAAI1C,cAAc;YAChB,MAAMV,kBAAkBW;QAC1B;QAEA,OAAOyC;IACT,EAAE,OAAOW,OAAgB;QACvB,MAAM7D,gBAAgBM,KAAKG,GAAG;QAC9B,MAAMoD;IACR;AACF,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"baseIDField.d.ts","sourceRoot":"","sources":["../../../src/fields/baseFields/baseIDField.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAKnD,eAAO,MAAM,WAAW,EAAE,
|
|
1
|
+
{"version":3,"file":"baseIDField.d.ts","sourceRoot":"","sources":["../../../src/fields/baseFields/baseIDField.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAKnD,eAAO,MAAM,WAAW,EAAE,SA2BzB,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/fields/baseFields/baseIDField.ts"],"sourcesContent":["import ObjectIdImport from 'bson-objectid'\n\nimport type { TextField } from '../config/types.js'\n\nconst ObjectId = (ObjectIdImport.default ||\n ObjectIdImport) as unknown as typeof ObjectIdImport.default\n\nexport const baseIDField: TextField = {\n name: 'id',\n type: 'text',\n admin: {\n hidden: true,\n },\n defaultValue: () => new ObjectId().toHexString(),\n hooks: {\n beforeChange: [\n ({ operation, value }) => {\n // If creating new doc, need to disregard any\n // ids that have been passed in because they will cause\n // primary key unique conflicts in relational DBs\n if (!value || (operation === 'create' && value)) {\n return new ObjectId().toHexString()\n }\n\n return value\n },\n ],\n },\n label: 'ID',\n}\n"],"names":["ObjectIdImport","ObjectId","default","baseIDField","name","type","admin","hidden","defaultValue","toHexString","hooks","beforeChange","operation","value","label"],"mappings":"AAAA,OAAOA,oBAAoB,gBAAe;AAI1C,MAAMC,WAAYD,eAAeE,OAAO,IACtCF;AAEF,OAAO,MAAMG,cAAyB;IACpCC,MAAM;IACNC,MAAM;IACNC,OAAO;QACLC,QAAQ;IACV;IACAC,cAAc,IAAM,IAAIP,WAAWQ,WAAW;IAC9CC,OAAO;QACLC,cAAc;YACZ,CAAC,EAAEC,SAAS,EAAEC,KAAK,EAAE;gBACnB,6CAA6C;gBAC7C,uDAAuD;gBACvD,iDAAiD;gBACjD,IAAI,CAACA,SAAUD,cAAc,YAAYC,OAAQ;oBAC/C,OAAO,IAAIZ,WAAWQ,WAAW;gBACnC;gBAEA,OAAOI;YACT;SACD;IACH;
|
|
1
|
+
{"version":3,"sources":["../../../src/fields/baseFields/baseIDField.ts"],"sourcesContent":["import ObjectIdImport from 'bson-objectid'\n\nimport type { TextField } from '../config/types.js'\n\nconst ObjectId = (ObjectIdImport.default ||\n ObjectIdImport) as unknown as typeof ObjectIdImport.default\n\nexport const baseIDField: TextField = {\n name: 'id',\n type: 'text',\n admin: {\n hidden: true,\n },\n defaultValue: () => new ObjectId().toHexString(),\n hooks: {\n beforeChange: [\n ({ operation, value }) => {\n // If creating new doc, need to disregard any\n // ids that have been passed in because they will cause\n // primary key unique conflicts in relational DBs\n if (!value || (operation === 'create' && value)) {\n return new ObjectId().toHexString()\n }\n\n return value\n },\n ],\n beforeDuplicate: [\n () => {\n return new ObjectId().toHexString()\n },\n ],\n },\n label: 'ID',\n}\n"],"names":["ObjectIdImport","ObjectId","default","baseIDField","name","type","admin","hidden","defaultValue","toHexString","hooks","beforeChange","operation","value","beforeDuplicate","label"],"mappings":"AAAA,OAAOA,oBAAoB,gBAAe;AAI1C,MAAMC,WAAYD,eAAeE,OAAO,IACtCF;AAEF,OAAO,MAAMG,cAAyB;IACpCC,MAAM;IACNC,MAAM;IACNC,OAAO;QACLC,QAAQ;IACV;IACAC,cAAc,IAAM,IAAIP,WAAWQ,WAAW;IAC9CC,OAAO;QACLC,cAAc;YACZ,CAAC,EAAEC,SAAS,EAAEC,KAAK,EAAE;gBACnB,6CAA6C;gBAC7C,uDAAuD;gBACvD,iDAAiD;gBACjD,IAAI,CAACA,SAAUD,cAAc,YAAYC,OAAQ;oBAC/C,OAAO,IAAIZ,WAAWQ,WAAW;gBACnC;gBAEA,OAAOI;YACT;SACD;QACDC,iBAAiB;YACf;gBACE,OAAO,IAAIb,WAAWQ,WAAW;YACnC;SACD;IACH;IACAM,OAAO;AACT,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sanitize.d.ts","sourceRoot":"","sources":["../../../src/fields/config/sanitize.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAA;AACzE,OAAO,KAAK,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AACpE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"sanitize.d.ts","sourceRoot":"","sources":["../../../src/fields/config/sanitize.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAA;AACzE,OAAO,KAAK,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AACpE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAgBvC,KAAK,IAAI,GAAG;IACV,gBAAgB,CAAC,EAAE,gBAAgB,CAAA;IACnC,MAAM,EAAE,MAAM,CAAA;IACd,kBAAkB,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;IAChC,MAAM,EAAE,KAAK,EAAE,CAAA;IACf,iBAAiB,EAAE,OAAO,CAAA;IAC1B;;;;OAIG;IACH,+BAA+B,CAAC,EAAE,OAAO,CAAA;IAEzC;;;OAGG;IACH,4BAA4B,CAAC,EAAE,KAAK,CAAC,CAAC,MAAM,EAAE,eAAe,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC,CAAA;IAChF;;;OAGG;IACH,kBAAkB,EAAE,IAAI,GAAG,MAAM,EAAE,CAAA;CACpC,CAAA;AAED,eAAO,MAAM,cAAc,oKASxB,IAAI,KAAG,OAAO,CAAC,KAAK,EAAE,CA0NxB,CAAA"}
|
|
@@ -2,7 +2,6 @@ import { deepMergeSimple } from '@payloadcms/translations/utilities';
|
|
|
2
2
|
import { DuplicateFieldName, InvalidFieldName, InvalidFieldRelationship, MissingFieldType } from '../../errors/index.js';
|
|
3
3
|
import { MissingEditorProp } from '../../errors/MissingEditorProp.js';
|
|
4
4
|
import { formatLabels, toWords } from '../../utilities/formatLabels.js';
|
|
5
|
-
import { baseBeforeDuplicateArrays } from '../baseFields/baseBeforeDuplicateArrays.js';
|
|
6
5
|
import { baseBlockFields } from '../baseFields/baseBlockFields.js';
|
|
7
6
|
import { baseIDField } from '../baseFields/baseIDField.js';
|
|
8
7
|
import { setDefaultBeforeDuplicate } from '../setDefaultBeforeDuplicate.js';
|
|
@@ -61,15 +60,6 @@ export const sanitizeFields = async ({ collectionConfig, config, existingFieldNa
|
|
|
61
60
|
}
|
|
62
61
|
if (field.type === 'array' && field.fields) {
|
|
63
62
|
field.fields.push(baseIDField);
|
|
64
|
-
if (field.localized) {
|
|
65
|
-
if (!field.hooks) {
|
|
66
|
-
field.hooks = {};
|
|
67
|
-
}
|
|
68
|
-
if (!field.hooks.beforeDuplicate) {
|
|
69
|
-
field.hooks.beforeDuplicate = [];
|
|
70
|
-
}
|
|
71
|
-
field.hooks.beforeDuplicate.push(baseBeforeDuplicateArrays);
|
|
72
|
-
}
|
|
73
63
|
}
|
|
74
64
|
if ((field.type === 'blocks' || field.type === 'array') && field.label) {
|
|
75
65
|
field.labels = field.labels || formatLabels(field.name);
|
|
@@ -144,15 +134,6 @@ export const sanitizeFields = async ({ collectionConfig, config, existingFieldNa
|
|
|
144
134
|
}
|
|
145
135
|
}
|
|
146
136
|
if (field.type === 'blocks' && field.blocks) {
|
|
147
|
-
if (field.localized) {
|
|
148
|
-
if (!field.hooks) {
|
|
149
|
-
field.hooks = {};
|
|
150
|
-
}
|
|
151
|
-
if (!field.hooks.beforeDuplicate) {
|
|
152
|
-
field.hooks.beforeDuplicate = [];
|
|
153
|
-
}
|
|
154
|
-
field.hooks.beforeDuplicate.push(baseBeforeDuplicateArrays);
|
|
155
|
-
}
|
|
156
137
|
for (const block of field.blocks){
|
|
157
138
|
if (block._sanitized === true) {
|
|
158
139
|
continue;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/fields/config/sanitize.ts"],"sourcesContent":["import { deepMergeSimple } from '@payloadcms/translations/utilities'\n\nimport type { CollectionConfig } from '../../collections/config/types.js'\nimport type { Config, SanitizedConfig } from '../../config/types.js'\nimport type { Field } from './types.js'\n\nimport {\n DuplicateFieldName,\n InvalidFieldName,\n InvalidFieldRelationship,\n MissingFieldType,\n} from '../../errors/index.js'\nimport { MissingEditorProp } from '../../errors/MissingEditorProp.js'\nimport { formatLabels, toWords } from '../../utilities/formatLabels.js'\nimport { baseBeforeDuplicateArrays } from '../baseFields/baseBeforeDuplicateArrays.js'\nimport { baseBlockFields } from '../baseFields/baseBlockFields.js'\nimport { baseIDField } from '../baseFields/baseIDField.js'\nimport { setDefaultBeforeDuplicate } from '../setDefaultBeforeDuplicate.js'\nimport validations from '../validations.js'\nimport { fieldAffectsData, tabHasName } from './types.js'\n\ntype Args = {\n collectionConfig?: CollectionConfig\n config: Config\n existingFieldNames?: Set<string>\n fields: Field[]\n parentIsLocalized: boolean\n /**\n * If true, a richText field will require an editor property to be set, as the sanitizeFields function will not add it from the payload config if not present.\n *\n * @default false\n */\n requireFieldLevelRichTextEditor?: boolean\n\n /**\n * If this property is set, RichText fields won't be sanitized immediately. Instead, they will be added to this array as promises\n * so that you can sanitize them together, after the config has been sanitized.\n */\n richTextSanitizationPromises?: Array<(config: SanitizedConfig) => Promise<void>>\n /**\n * If not null, will validate that upload and relationship fields do not relate to a collection that is not in this array.\n * This validation will be skipped if validRelationships is null.\n */\n validRelationships: null | string[]\n}\n\nexport const sanitizeFields = async ({\n collectionConfig,\n config,\n existingFieldNames = new Set(),\n fields,\n parentIsLocalized,\n requireFieldLevelRichTextEditor = false,\n richTextSanitizationPromises,\n validRelationships,\n}: Args): Promise<Field[]> => {\n if (!fields) {\n return []\n }\n\n for (let i = 0; i < fields.length; i++) {\n const field = fields[i]\n\n if ('_sanitized' in field && field._sanitized === true) {\n continue\n }\n\n if (!field.type) {\n throw new MissingFieldType(field)\n }\n\n // assert that field names do not contain forbidden characters\n if (fieldAffectsData(field) && field.name.includes('.')) {\n throw new InvalidFieldName(field, field.name)\n }\n\n // Auto-label\n if (\n 'name' in field &&\n field.name &&\n typeof field.label !== 'object' &&\n typeof field.label !== 'string' &&\n typeof field.label !== 'function' &&\n field.label !== false\n ) {\n field.label = toWords(field.name)\n }\n\n if (\n field.type === 'checkbox' &&\n typeof field.defaultValue === 'undefined' &&\n field.required === true\n ) {\n field.defaultValue = false\n }\n\n if (field.type === 'relationship' || field.type === 'upload') {\n if (validRelationships) {\n const relationships = Array.isArray(field.relationTo)\n ? field.relationTo\n : [field.relationTo]\n relationships.forEach((relationship: string) => {\n if (!validRelationships.includes(relationship)) {\n throw new InvalidFieldRelationship(field, relationship)\n }\n })\n }\n\n if (field.min && !field.minRows) {\n console.warn(\n `(payload): The \"min\" property is deprecated for the Relationship field \"${field.name}\" and will be removed in a future version. Please use \"minRows\" instead.`,\n )\n }\n if (field.max && !field.maxRows) {\n console.warn(\n `(payload): The \"max\" property is deprecated for the Relationship field \"${field.name}\" and will be removed in a future version. Please use \"maxRows\" instead.`,\n )\n }\n field.minRows = field.minRows || field.min\n field.maxRows = field.maxRows || field.max\n }\n\n if (field.type === 'upload') {\n if (!field.admin || !('isSortable' in field.admin)) {\n field.admin = {\n isSortable: true,\n ...field.admin,\n }\n }\n }\n\n if (field.type === 'array' && field.fields) {\n field.fields.push(baseIDField)\n if (field.localized) {\n if (!field.hooks) {\n field.hooks = {}\n }\n if (!field.hooks.beforeDuplicate) {\n field.hooks.beforeDuplicate = []\n }\n field.hooks.beforeDuplicate.push(baseBeforeDuplicateArrays)\n }\n }\n\n if ((field.type === 'blocks' || field.type === 'array') && field.label) {\n field.labels = field.labels || formatLabels(field.name)\n }\n\n if (fieldAffectsData(field)) {\n if (existingFieldNames.has(field.name)) {\n throw new DuplicateFieldName(field.name)\n } else if (!['blockName', 'id'].includes(field.name)) {\n existingFieldNames.add(field.name)\n }\n\n if (typeof field.localized !== 'undefined') {\n let shouldDisableLocalized = !config.localization\n\n if (!config.compatibility?.allowLocalizedWithinLocalized && parentIsLocalized) {\n shouldDisableLocalized = true\n }\n\n if (shouldDisableLocalized) {\n delete field.localized\n }\n }\n\n if (typeof field.validate === 'undefined') {\n const defaultValidate = validations[field.type]\n if (defaultValidate) {\n field.validate = (val, options) => defaultValidate(val, { ...field, ...options })\n } else {\n field.validate = () => true\n }\n }\n\n if (!field.hooks) {\n field.hooks = {}\n }\n if (!field.access) {\n field.access = {}\n }\n\n setDefaultBeforeDuplicate(field)\n }\n\n if (!field.admin) {\n field.admin = {}\n }\n\n // Make sure that the richText field has an editor\n if (field.type === 'richText') {\n const sanitizeRichText = async (_config: SanitizedConfig) => {\n if (!field.editor) {\n if (_config.editor && !requireFieldLevelRichTextEditor) {\n // config.editor should be sanitized at this point\n field.editor = _config.editor\n } else {\n throw new MissingEditorProp(field) // while we allow disabling editor functionality, you should not have any richText fields defined if you do not have an editor\n }\n }\n\n if (typeof field.editor === 'function') {\n field.editor = await field.editor({\n config: _config,\n isRoot: requireFieldLevelRichTextEditor,\n parentIsLocalized: parentIsLocalized || field.localized,\n })\n }\n\n if (field.editor.i18n && Object.keys(field.editor.i18n).length >= 0) {\n config.i18n.translations = deepMergeSimple(config.i18n.translations, field.editor.i18n)\n }\n }\n if (richTextSanitizationPromises) {\n richTextSanitizationPromises.push(sanitizeRichText)\n } else {\n await sanitizeRichText(config as unknown as SanitizedConfig)\n }\n }\n\n if (field.type === 'blocks' && field.blocks) {\n if (field.localized) {\n if (!field.hooks) {\n field.hooks = {}\n }\n if (!field.hooks.beforeDuplicate) {\n field.hooks.beforeDuplicate = []\n }\n field.hooks.beforeDuplicate.push(baseBeforeDuplicateArrays)\n }\n for (const block of field.blocks) {\n if (block._sanitized === true) {\n continue\n }\n block._sanitized = true\n block.fields = block.fields.concat(baseBlockFields)\n block.labels = !block.labels ? formatLabels(block.slug) : block.labels\n\n block.fields = await sanitizeFields({\n config,\n existingFieldNames: new Set(),\n fields: block.fields,\n parentIsLocalized: parentIsLocalized || field.localized,\n requireFieldLevelRichTextEditor,\n richTextSanitizationPromises,\n validRelationships,\n })\n }\n }\n\n if ('fields' in field && field.fields) {\n field.fields = await sanitizeFields({\n config,\n existingFieldNames: fieldAffectsData(field) ? new Set() : existingFieldNames,\n fields: field.fields,\n parentIsLocalized: parentIsLocalized || field.localized,\n requireFieldLevelRichTextEditor,\n richTextSanitizationPromises,\n validRelationships,\n })\n }\n\n if (field.type === 'tabs') {\n for (let j = 0; j < field.tabs.length; j++) {\n const tab = field.tabs[j]\n if (tabHasName(tab) && typeof tab.label === 'undefined') {\n tab.label = toWords(tab.name)\n }\n\n tab.fields = await sanitizeFields({\n config,\n existingFieldNames: tabHasName(tab) ? new Set() : existingFieldNames,\n fields: tab.fields,\n parentIsLocalized: parentIsLocalized || (tabHasName(tab) && tab.localized),\n requireFieldLevelRichTextEditor,\n richTextSanitizationPromises,\n validRelationships,\n })\n field.tabs[j] = tab\n }\n }\n\n if ('_sanitized' in field) {\n field._sanitized = true\n }\n\n fields[i] = field\n }\n\n return fields\n}\n"],"names":["deepMergeSimple","DuplicateFieldName","InvalidFieldName","InvalidFieldRelationship","MissingFieldType","MissingEditorProp","formatLabels","toWords","baseBeforeDuplicateArrays","baseBlockFields","baseIDField","setDefaultBeforeDuplicate","validations","fieldAffectsData","tabHasName","sanitizeFields","collectionConfig","config","existingFieldNames","Set","fields","parentIsLocalized","requireFieldLevelRichTextEditor","richTextSanitizationPromises","validRelationships","i","length","field","_sanitized","type","name","includes","label","defaultValue","required","relationships","Array","isArray","relationTo","forEach","relationship","min","minRows","console","warn","max","maxRows","admin","isSortable","push","localized","hooks","beforeDuplicate","labels","has","add","shouldDisableLocalized","localization","compatibility","allowLocalizedWithinLocalized","validate","defaultValidate","val","options","access","sanitizeRichText","_config","editor","isRoot","i18n","Object","keys","translations","blocks","block","concat","slug","j","tabs","tab"],"mappings":"AAAA,SAASA,eAAe,QAAQ,qCAAoC;AAMpE,SACEC,kBAAkB,EAClBC,gBAAgB,EAChBC,wBAAwB,EACxBC,gBAAgB,QACX,wBAAuB;AAC9B,SAASC,iBAAiB,QAAQ,oCAAmC;AACrE,SAASC,YAAY,EAAEC,OAAO,QAAQ,kCAAiC;AACvE,SAASC,yBAAyB,QAAQ,6CAA4C;AACtF,SAASC,eAAe,QAAQ,mCAAkC;AAClE,SAASC,WAAW,QAAQ,+BAA8B;AAC1D,SAASC,yBAAyB,QAAQ,kCAAiC;AAC3E,OAAOC,iBAAiB,oBAAmB;AAC3C,SAASC,gBAAgB,EAAEC,UAAU,QAAQ,aAAY;AA2BzD,OAAO,MAAMC,iBAAiB,OAAO,EACnCC,gBAAgB,EAChBC,MAAM,EACNC,qBAAqB,IAAIC,KAAK,EAC9BC,MAAM,EACNC,iBAAiB,EACjBC,kCAAkC,KAAK,EACvCC,4BAA4B,EAC5BC,kBAAkB,EACb;IACL,IAAI,CAACJ,QAAQ;QACX,OAAO,EAAE;IACX;IAEA,IAAK,IAAIK,IAAI,GAAGA,IAAIL,OAAOM,MAAM,EAAED,IAAK;QACtC,MAAME,QAAQP,MAAM,CAACK,EAAE;QAEvB,IAAI,gBAAgBE,SAASA,MAAMC,UAAU,KAAK,MAAM;YACtD;QACF;QAEA,IAAI,CAACD,MAAME,IAAI,EAAE;YACf,MAAM,IAAIzB,iBAAiBuB;QAC7B;QAEA,8DAA8D;QAC9D,IAAId,iBAAiBc,UAAUA,MAAMG,IAAI,CAACC,QAAQ,CAAC,MAAM;YACvD,MAAM,IA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AM;gBACpBC,mBAAmBA,qBAAqBM,MAAMuB,SAAS;gBACvD5B;gBACAC;gBACAC;YACF;QACF;QAEA,IAAIG,MAAME,IAAI,KAAK,QAAQ;YACzB,IAAK,IAAIgD,IAAI,GAAGA,IAAIlD,MAAMmD,IAAI,CAACpD,MAAM,EAAEmD,IAAK;gBAC1C,MAAME,MAAMpD,MAAMmD,IAAI,CAACD,EAAE;gBACzB,IAAI/D,WAAWiE,QAAQ,OAAOA,IAAI/C,KAAK,KAAK,aAAa;oBACvD+C,IAAI/C,KAAK,GAAGzB,QAAQwE,IAAIjD,IAAI;gBAC9B;gBAEAiD,IAAI3D,MAAM,GAAG,MAAML,eAAe;oBAChCE;oBACAC,oBAAoBJ,WAAWiE,OAAO,IAAI5D,QAAQD;oBAClDE,QAAQ2D,IAAI3D,MAAM;oBAClBC,mBAAmBA,qBAAsBP,WAAWiE,QAAQA,IAAI7B,SAAS;oBACzE5B;oBACAC;oBACAC;gBACF;gBACAG,MAAMmD,IAAI,CAACD,EAAE,GAAGE;YAClB;QACF;QAEA,IAAI,gBAAgBpD,OAAO;YACzBA,MAAMC,UAAU,GAAG;QACrB;QAEAR,MAAM,CAACK,EAAE,GAAGE;IACd;IAEA,OAAOP;AACT,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../../src/fields/config/sanitize.ts"],"sourcesContent":["import { deepMergeSimple } from '@payloadcms/translations/utilities'\n\nimport type { CollectionConfig } from '../../collections/config/types.js'\nimport type { Config, SanitizedConfig } from '../../config/types.js'\nimport type { Field } from './types.js'\n\nimport {\n DuplicateFieldName,\n InvalidFieldName,\n InvalidFieldRelationship,\n MissingFieldType,\n} from '../../errors/index.js'\nimport { MissingEditorProp } from '../../errors/MissingEditorProp.js'\nimport { formatLabels, toWords } from '../../utilities/formatLabels.js'\nimport { baseBlockFields } from '../baseFields/baseBlockFields.js'\nimport { baseIDField } from '../baseFields/baseIDField.js'\nimport { setDefaultBeforeDuplicate } from '../setDefaultBeforeDuplicate.js'\nimport validations from '../validations.js'\nimport { fieldAffectsData, tabHasName } from './types.js'\n\ntype Args = {\n collectionConfig?: CollectionConfig\n config: Config\n existingFieldNames?: Set<string>\n fields: Field[]\n parentIsLocalized: boolean\n /**\n * If true, a richText field will require an editor property to be set, as the sanitizeFields function will not add it from the payload config if not present.\n *\n * @default false\n */\n requireFieldLevelRichTextEditor?: boolean\n\n /**\n * If this property is set, RichText fields won't be sanitized immediately. Instead, they will be added to this array as promises\n * so that you can sanitize them together, after the config has been sanitized.\n */\n richTextSanitizationPromises?: Array<(config: SanitizedConfig) => Promise<void>>\n /**\n * If not null, will validate that upload and relationship fields do not relate to a collection that is not in this array.\n * This validation will be skipped if validRelationships is null.\n */\n validRelationships: null | string[]\n}\n\nexport const sanitizeFields = async ({\n collectionConfig,\n config,\n existingFieldNames = new Set(),\n fields,\n parentIsLocalized,\n requireFieldLevelRichTextEditor = false,\n richTextSanitizationPromises,\n validRelationships,\n}: Args): Promise<Field[]> => {\n if (!fields) {\n return []\n }\n\n for (let i = 0; i < fields.length; i++) {\n const field = fields[i]\n\n if ('_sanitized' in field && field._sanitized === true) {\n continue\n }\n\n if (!field.type) {\n throw new MissingFieldType(field)\n }\n\n // assert that field names do not contain forbidden characters\n if (fieldAffectsData(field) && field.name.includes('.')) {\n throw new InvalidFieldName(field, field.name)\n }\n\n // Auto-label\n if (\n 'name' in field &&\n field.name &&\n typeof field.label !== 'object' &&\n typeof field.label !== 'string' &&\n typeof field.label !== 'function' &&\n field.label !== false\n ) {\n field.label = toWords(field.name)\n }\n\n if (\n field.type === 'checkbox' &&\n typeof field.defaultValue === 'undefined' &&\n field.required === true\n ) {\n field.defaultValue = false\n }\n\n if (field.type === 'relationship' || field.type === 'upload') {\n if (validRelationships) {\n const relationships = Array.isArray(field.relationTo)\n ? field.relationTo\n : [field.relationTo]\n relationships.forEach((relationship: string) => {\n if (!validRelationships.includes(relationship)) {\n throw new InvalidFieldRelationship(field, relationship)\n }\n })\n }\n\n if (field.min && !field.minRows) {\n console.warn(\n `(payload): The \"min\" property is deprecated for the Relationship field \"${field.name}\" and will be removed in a future version. Please use \"minRows\" instead.`,\n )\n }\n if (field.max && !field.maxRows) {\n console.warn(\n `(payload): The \"max\" property is deprecated for the Relationship field \"${field.name}\" and will be removed in a future version. Please use \"maxRows\" instead.`,\n )\n }\n field.minRows = field.minRows || field.min\n field.maxRows = field.maxRows || field.max\n }\n\n if (field.type === 'upload') {\n if (!field.admin || !('isSortable' in field.admin)) {\n field.admin = {\n isSortable: true,\n ...field.admin,\n }\n }\n }\n\n if (field.type === 'array' && field.fields) {\n field.fields.push(baseIDField)\n }\n\n if ((field.type === 'blocks' || field.type === 'array') && field.label) {\n field.labels = field.labels || formatLabels(field.name)\n }\n\n if (fieldAffectsData(field)) {\n if (existingFieldNames.has(field.name)) {\n throw new DuplicateFieldName(field.name)\n } else if (!['blockName', 'id'].includes(field.name)) {\n existingFieldNames.add(field.name)\n }\n\n if (typeof field.localized !== 'undefined') {\n let shouldDisableLocalized = !config.localization\n\n if (!config.compatibility?.allowLocalizedWithinLocalized && parentIsLocalized) {\n shouldDisableLocalized = true\n }\n\n if (shouldDisableLocalized) {\n delete field.localized\n }\n }\n\n if (typeof field.validate === 'undefined') {\n const defaultValidate = validations[field.type]\n if (defaultValidate) {\n field.validate = (val, options) => defaultValidate(val, { ...field, ...options })\n } else {\n field.validate = () => true\n }\n }\n\n if (!field.hooks) {\n field.hooks = {}\n }\n if (!field.access) {\n field.access = {}\n }\n\n setDefaultBeforeDuplicate(field)\n }\n\n if (!field.admin) {\n field.admin = {}\n }\n\n // Make sure that the richText field has an editor\n if (field.type === 'richText') {\n const sanitizeRichText = async (_config: SanitizedConfig) => {\n if (!field.editor) {\n if (_config.editor && !requireFieldLevelRichTextEditor) {\n // config.editor should be sanitized at this point\n field.editor = _config.editor\n } else {\n throw new MissingEditorProp(field) // while we allow disabling editor functionality, you should not have any richText fields defined if you do not have an editor\n }\n }\n\n if (typeof field.editor === 'function') {\n field.editor = await field.editor({\n config: _config,\n isRoot: requireFieldLevelRichTextEditor,\n parentIsLocalized: parentIsLocalized || field.localized,\n })\n }\n\n if (field.editor.i18n && Object.keys(field.editor.i18n).length >= 0) {\n config.i18n.translations = deepMergeSimple(config.i18n.translations, field.editor.i18n)\n }\n }\n if (richTextSanitizationPromises) {\n richTextSanitizationPromises.push(sanitizeRichText)\n } else {\n await sanitizeRichText(config as unknown as SanitizedConfig)\n }\n }\n\n if (field.type === 'blocks' && field.blocks) {\n for (const block of field.blocks) {\n if (block._sanitized === true) {\n continue\n }\n block._sanitized = true\n block.fields = block.fields.concat(baseBlockFields)\n block.labels = !block.labels ? formatLabels(block.slug) : block.labels\n\n block.fields = await sanitizeFields({\n config,\n existingFieldNames: new Set(),\n fields: block.fields,\n parentIsLocalized: parentIsLocalized || field.localized,\n requireFieldLevelRichTextEditor,\n richTextSanitizationPromises,\n validRelationships,\n })\n }\n }\n\n if ('fields' in field && field.fields) {\n field.fields = await sanitizeFields({\n config,\n existingFieldNames: fieldAffectsData(field) ? new Set() : existingFieldNames,\n fields: field.fields,\n parentIsLocalized: parentIsLocalized || field.localized,\n requireFieldLevelRichTextEditor,\n richTextSanitizationPromises,\n validRelationships,\n })\n }\n\n if (field.type === 'tabs') {\n for (let j = 0; j < field.tabs.length; j++) {\n const tab = field.tabs[j]\n if (tabHasName(tab) && typeof tab.label === 'undefined') {\n tab.label = toWords(tab.name)\n }\n\n tab.fields = await sanitizeFields({\n config,\n existingFieldNames: tabHasName(tab) ? new Set() : existingFieldNames,\n fields: tab.fields,\n parentIsLocalized: parentIsLocalized || (tabHasName(tab) && tab.localized),\n requireFieldLevelRichTextEditor,\n richTextSanitizationPromises,\n validRelationships,\n })\n field.tabs[j] = tab\n }\n }\n\n if ('_sanitized' in field) {\n field._sanitized = true\n }\n\n fields[i] = field\n }\n\n return fields\n}\n"],"names":["deepMergeSimple","DuplicateFieldName","InvalidFieldName","InvalidFieldRelationship","MissingFieldType","MissingEditorProp","formatLabels","toWords","baseBlockFields","baseIDField","setDefaultBeforeDuplicate","validations","fieldAffectsData","tabHasName","sanitizeFields","collectionConfig","config","existingFieldNames","Set","fields","parentIsLocalized","requireFieldLevelRichTextEditor","richTextSanitizationPromises","validRelationships","i","length","field","_sanitized","type","name","includes","label","defaultValue","required","relationships","Array","isArray","relationTo","forEach","relationship","min","minRows","console","warn","max","maxRows","admin","isSortable","push","labels","has","add","localized","shouldDisableLocalized","localization","compatibility","allowLocalizedWithinLocalized","validate","defaultValidate","val","options","hooks","access","sanitizeRichText","_config","editor","isRoot","i18n","Object","keys","translations","blocks","block","concat","slug","j","tabs","tab"],"mappings":"AAAA,SAASA,eAAe,QAAQ,qCAAoC;AAMpE,SACEC,kBAAkB,EAClBC,gBAAgB,EAChBC,wBAAwB,EACxBC,gBAAgB,QACX,wBAAuB;AAC9B,SAASC,iBAAiB,QAAQ,oCAAmC;AACrE,SAASC,YAAY,EAAEC,OAAO,QAAQ,kCAAiC;AACvE,SAASC,eAAe,QAAQ,mCAAkC;AAClE,SAASC,WAAW,QAAQ,+BAA8B;AAC1D,SAASC,yBAAyB,QAAQ,kCAAiC;AAC3E,OAAOC,iBAAiB,oBAAmB;AAC3C,SAASC,gBAAgB,EAAEC,UAAU,QAAQ,aAAY;AA2BzD,OAAO,MAAMC,iBAAiB,OAAO,EACnCC,gBAAgB,EAChBC,MAAM,EACNC,qBAAqB,IAAIC,KAAK,EAC9BC,MAAM,EACNC,iBAAiB,EACjBC,kCAAkC,KAAK,EACvCC,4BAA4B,EAC5BC,kBAAkB,EACb;IACL,IAAI,CAACJ,QAAQ;QACX,OAAO,EAAE;IACX;IAEA,IAAK,IAAIK,IAAI,GAAGA,IAAIL,OAAOM,MAAM,EAAED,IAAK;QACtC,MAAME,QAAQP,MAAM,CAACK,EAAE;QAEvB,IAAI,gBAAgBE,SAASA,MAAMC,UAAU,KAAK,MAAM;YACtD;QACF;QAEA,IAAI,CAACD,MAAME,IAAI,EAAE;YACf,MAAM,IAAIxB,iBA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,IAAI3D,QAAQD;oBAClDE,QAAQ0D,IAAI1D,MAAM;oBAClBC,mBAAmBA,qBAAsBP,WAAWgE,QAAQA,IAAIzB,SAAS;oBACzE/B;oBACAC;oBACAC;gBACF;gBACAG,MAAMkD,IAAI,CAACD,EAAE,GAAGE;YAClB;QACF;QAEA,IAAI,gBAAgBnD,OAAO;YACzBA,MAAMC,UAAU,GAAG;QACrB;QAEAR,MAAM,CAACK,EAAE,GAAGE;IACd;IAEA,OAAOP;AACT,EAAC"}
|
|
@@ -7,7 +7,6 @@ type Args<T extends JsonObject> = {
|
|
|
7
7
|
data: T;
|
|
8
8
|
doc: T;
|
|
9
9
|
docWithLocales: JsonObject;
|
|
10
|
-
duplicate?: boolean;
|
|
11
10
|
global: null | SanitizedGlobalConfig;
|
|
12
11
|
id?: number | string;
|
|
13
12
|
operation: Operation;
|
|
@@ -20,9 +19,8 @@ type Args<T extends JsonObject> = {
|
|
|
20
19
|
* - Execute field hooks
|
|
21
20
|
* - Validate data
|
|
22
21
|
* - Transform data for storage
|
|
23
|
-
* - beforeDuplicate hooks (if duplicate)
|
|
24
22
|
* - Unflatten locales. The input `data` is the normal document for one locale. The output result will become the document with locales.
|
|
25
23
|
*/
|
|
26
|
-
export declare const beforeChange: <T extends JsonObject>({ id, collection, context, data: incomingData, doc, docWithLocales,
|
|
24
|
+
export declare const beforeChange: <T extends JsonObject>({ id, collection, context, data: incomingData, doc, docWithLocales, global, operation, req, skipValidation, }: Args<T>) => Promise<T>;
|
|
27
25
|
export {};
|
|
28
26
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/fields/hooks/beforeChange/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,sCAAsC,CAAA;AACrF,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAA;AAC7E,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AAMpG,KAAK,IAAI,CAAC,CAAC,SAAS,UAAU,IAAI;IAChC,UAAU,EAAE,IAAI,GAAG,yBAAyB,CAAA;IAC5C,OAAO,EAAE,cAAc,CAAA;IACvB,IAAI,EAAE,CAAC,CAAA;IACP,GAAG,EAAE,CAAC,CAAA;IACN,cAAc,EAAE,UAAU,CAAA;IAC1B,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/fields/hooks/beforeChange/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,sCAAsC,CAAA;AACrF,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAA;AAC7E,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AAMpG,KAAK,IAAI,CAAC,CAAC,SAAS,UAAU,IAAI;IAChC,UAAU,EAAE,IAAI,GAAG,yBAAyB,CAAA;IAC5C,OAAO,EAAE,cAAc,CAAA;IACvB,IAAI,EAAE,CAAC,CAAA;IACP,GAAG,EAAE,CAAC,CAAA;IACN,cAAc,EAAE,UAAU,CAAA;IAC1B,MAAM,EAAE,IAAI,GAAG,qBAAqB,CAAA;IACpC,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IACpB,SAAS,EAAE,SAAS,CAAA;IACpB,GAAG,EAAE,cAAc,CAAA;IACnB,cAAc,CAAC,EAAE,OAAO,CAAA;CACzB,CAAA;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,YAAY,GAAU,CAAC,SAAS,UAAU,iHAWpD,IAAI,CAAC,CAAC,CAAC,KAAG,OAAO,CAAC,CAAC,CA4CrB,CAAA"}
|
|
@@ -7,9 +7,8 @@ import { traverseFields } from './traverseFields.js';
|
|
|
7
7
|
* - Execute field hooks
|
|
8
8
|
* - Validate data
|
|
9
9
|
* - Transform data for storage
|
|
10
|
-
* - beforeDuplicate hooks (if duplicate)
|
|
11
10
|
* - Unflatten locales. The input `data` is the normal document for one locale. The output result will become the document with locales.
|
|
12
|
-
*/ export const beforeChange = async ({ id, collection, context, data: incomingData, doc, docWithLocales,
|
|
11
|
+
*/ export const beforeChange = async ({ id, collection, context, data: incomingData, doc, docWithLocales, global, operation, req, skipValidation })=>{
|
|
13
12
|
const data = deepCopyObjectSimple(incomingData);
|
|
14
13
|
const mergeLocaleActions = [];
|
|
15
14
|
const errors = [];
|
|
@@ -20,7 +19,6 @@ import { traverseFields } from './traverseFields.js';
|
|
|
20
19
|
data,
|
|
21
20
|
doc,
|
|
22
21
|
docWithLocales,
|
|
23
|
-
duplicate,
|
|
24
22
|
errors,
|
|
25
23
|
fields: collection?.fields || global?.fields,
|
|
26
24
|
global,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/fields/hooks/beforeChange/index.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'\n\nimport { ValidationError } from '../../../errors/index.js'\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 data: T\n doc: T\n docWithLocales: JsonObject\n
|
|
1
|
+
{"version":3,"sources":["../../../../src/fields/hooks/beforeChange/index.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'\n\nimport { ValidationError } from '../../../errors/index.js'\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 data: T\n doc: T\n docWithLocales: JsonObject\n global: null | SanitizedGlobalConfig\n id?: number | string\n operation: Operation\n req: PayloadRequest\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 beforeChange = async <T extends JsonObject>({\n id,\n collection,\n context,\n data: incomingData,\n doc,\n docWithLocales,\n global,\n operation,\n req,\n skipValidation,\n}: Args<T>): Promise<T> => {\n const data = deepCopyObjectSimple(incomingData)\n const mergeLocaleActions = []\n const errors: { field: string; message: string }[] = []\n\n await traverseFields({\n id,\n collection,\n context,\n data,\n doc,\n docWithLocales,\n errors,\n fields: collection?.fields || global?.fields,\n global,\n mergeLocaleActions,\n operation,\n path: [],\n req,\n schemaPath: [],\n siblingData: data,\n siblingDoc: doc,\n siblingDocWithLocales: docWithLocales,\n skipValidation,\n })\n\n if (errors.length > 0) {\n throw new ValidationError(\n {\n id,\n collection: collection?.slug,\n errors,\n global: global?.slug,\n },\n req.t,\n )\n }\n\n await mergeLocaleActions.reduce(async (priorAction, action) => {\n await priorAction\n await action()\n }, Promise.resolve())\n\n return data\n}\n"],"names":["ValidationError","deepCopyObjectSimple","traverseFields","beforeChange","id","collection","context","data","incomingData","doc","docWithLocales","global","operation","req","skipValidation","mergeLocaleActions","errors","fields","path","schemaPath","siblingData","siblingDoc","siblingDocWithLocales","length","slug","t","reduce","priorAction","action","Promise","resolve"],"mappings":"AAIA,SAASA,eAAe,QAAQ,2BAA0B;AAC1D,SAASC,oBAAoB,QAAQ,uCAAsC;AAC3E,SAASC,cAAc,QAAQ,sBAAqB;AAepD;;;;;;;CAOC,GACD,OAAO,MAAMC,eAAe,OAA6B,EACvDC,EAAE,EACFC,UAAU,EACVC,OAAO,EACPC,MAAMC,YAAY,EAClBC,GAAG,EACHC,cAAc,EACdC,MAAM,EACNC,SAAS,EACTC,GAAG,EACHC,cAAc,EACN;IACR,MAAMP,OAAON,qBAAqBO;IAClC,MAAMO,qBAAqB,EAAE;IAC7B,MAAMC,SAA+C,EAAE;IAEvD,MAAMd,eAAe;QACnBE;QACAC;QACAC;QACAC;QACAE;QACAC;QACAM;QACAC,QAAQZ,YAAYY,UAAUN,QAAQM;QACtCN;QACAI;QACAH;QACAM,MAAM,EAAE;QACRL;QACAM,YAAY,EAAE;QACdC,aAAab;QACbc,YAAYZ;QACZa,uBAAuBZ;QACvBI;IACF;IAEA,IAAIE,OAAOO,MAAM,GAAG,GAAG;QACrB,MAAM,IAAIvB,gBACR;YACEI;YACAC,YAAYA,YAAYmB;YACxBR;YACAL,QAAQA,QAAQa;QAClB,GACAX,IAAIY,CAAC;IAET;IAEA,MAAMV,mBAAmBW,MAAM,CAAC,OAAOC,aAAaC;QAClD,MAAMD;QACN,MAAMC;IACR,GAAGC,QAAQC,OAAO;IAElB,OAAOvB;AACT,EAAC"}
|
|
@@ -8,7 +8,6 @@ type Args = {
|
|
|
8
8
|
data: JsonObject;
|
|
9
9
|
doc: JsonObject;
|
|
10
10
|
docWithLocales: JsonObject;
|
|
11
|
-
duplicate: boolean;
|
|
12
11
|
errors: {
|
|
13
12
|
field: string;
|
|
14
13
|
message: string;
|
|
@@ -32,6 +31,6 @@ type Args = {
|
|
|
32
31
|
siblingDocWithLocales?: JsonObject;
|
|
33
32
|
skipValidation: boolean;
|
|
34
33
|
};
|
|
35
|
-
export declare const promise: ({ id, collection, context, data, doc, docWithLocales,
|
|
34
|
+
export declare const promise: ({ id, collection, context, data, doc, docWithLocales, errors, field, global, mergeLocaleActions, operation, parentPath, parentSchemaPath, req, siblingData, siblingDoc, siblingDocWithLocales, skipValidation, }: Args) => Promise<void>;
|
|
36
35
|
export {};
|
|
37
36
|
//# sourceMappingURL=promise.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"promise.d.ts","sourceRoot":"","sources":["../../../../src/fields/hooks/beforeChange/promise.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,sCAAsC,CAAA;AACrF,OAAO,KAAK,EAAE,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,EAAiB,UAAU,EAAmB,MAAM,uBAAuB,CAAA;
|
|
1
|
+
{"version":3,"file":"promise.d.ts","sourceRoot":"","sources":["../../../../src/fields/hooks/beforeChange/promise.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,sCAAsC,CAAA;AACrF,OAAO,KAAK,EAAE,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,EAAiB,UAAU,EAAmB,MAAM,uBAAuB,CAAA;AAS9F,KAAK,IAAI,GAAG;IACV,UAAU,EAAE,IAAI,GAAG,yBAAyB,CAAA;IAC5C,OAAO,EAAE,cAAc,CAAA;IACvB,IAAI,EAAE,UAAU,CAAA;IAChB,GAAG,EAAE,UAAU,CAAA;IACf,cAAc,EAAE,UAAU,CAAA;IAC1B,MAAM,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,EAAE,CAAA;IAC5C,KAAK,EAAE,KAAK,GAAG,UAAU,CAAA;IACzB,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;;OAEG;IACH,UAAU,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAA;IAC/B;;OAEG;IACH,gBAAgB,EAAE,MAAM,EAAE,CAAA;IAC1B,GAAG,EAAE,cAAc,CAAA;IACnB,WAAW,EAAE,UAAU,CAAA;IACvB,UAAU,EAAE,UAAU,CAAA;IACtB,qBAAqB,CAAC,EAAE,UAAU,CAAA;IAClC,cAAc,EAAE,OAAO,CAAA;CACxB,CAAA;AAUD,eAAO,MAAM,OAAO,qNAmBjB,IAAI,KAAG,OAAO,CAAC,IAAI,CAqarB,CAAA"}
|
|
@@ -2,7 +2,6 @@ import { MissingEditorProp } from '../../../errors/index.js';
|
|
|
2
2
|
import { deepMergeWithSourceArrays } from '../../../utilities/deepMerge.js';
|
|
3
3
|
import { fieldAffectsData, tabHasName } from '../../config/types.js';
|
|
4
4
|
import { getFieldPaths } from '../../getFieldPaths.js';
|
|
5
|
-
import { beforeDuplicate } from './beforeDuplicate.js';
|
|
6
5
|
import { getExistingRowDoc } from './getExistingRowDoc.js';
|
|
7
6
|
import { traverseFields } from './traverseFields.js';
|
|
8
7
|
// This function is responsible for the following actions, in order:
|
|
@@ -12,7 +11,7 @@ import { traverseFields } from './traverseFields.js';
|
|
|
12
11
|
// - Transform data for storage
|
|
13
12
|
// - beforeDuplicate hooks (if duplicate)
|
|
14
13
|
// - Unflatten locales
|
|
15
|
-
export const promise = async ({ id, collection, context, data, doc, docWithLocales,
|
|
14
|
+
export const promise = async ({ id, collection, context, data, doc, docWithLocales, errors, field, global, mergeLocaleActions, operation, parentPath, parentSchemaPath, req, siblingData, siblingDoc, siblingDocWithLocales, skipValidation })=>{
|
|
16
15
|
const passesCondition = field.admin?.condition ? Boolean(field.admin.condition(data, siblingData, {
|
|
17
16
|
user: req.user
|
|
18
17
|
})) : true;
|
|
@@ -113,11 +112,7 @@ export const promise = async ({ id, collection, context, data, doc, docWithLocal
|
|
|
113
112
|
mergeLocaleActions.push(async ()=>{
|
|
114
113
|
const localeData = await localization.localeCodes.reduce(async (localizedValuesPromise, locale)=>{
|
|
115
114
|
const localizedValues = await localizedValuesPromise;
|
|
116
|
-
|
|
117
|
-
if (duplicate && field.hooks?.beforeDuplicate?.length) {
|
|
118
|
-
beforeDuplicateArgs.value = fieldValue;
|
|
119
|
-
fieldValue = await beforeDuplicate(beforeDuplicateArgs);
|
|
120
|
-
}
|
|
115
|
+
const fieldValue = locale === req.locale ? siblingData[field.name] : siblingDocWithLocales?.[field.name]?.[locale];
|
|
121
116
|
// const result = await localizedValues
|
|
122
117
|
// update locale value if it's not undefined
|
|
123
118
|
if (typeof fieldValue !== 'undefined') {
|
|
@@ -133,10 +128,6 @@ export const promise = async ({ id, collection, context, data, doc, docWithLocal
|
|
|
133
128
|
siblingData[field.name] = localeData;
|
|
134
129
|
}
|
|
135
130
|
});
|
|
136
|
-
} else if (duplicate && field.hooks?.beforeDuplicate?.length) {
|
|
137
|
-
mergeLocaleActions.push(async ()=>{
|
|
138
|
-
siblingData[field.name] = await beforeDuplicate(beforeDuplicateArgs);
|
|
139
|
-
});
|
|
140
131
|
}
|
|
141
132
|
}
|
|
142
133
|
switch(field.type){
|
|
@@ -172,7 +163,6 @@ export const promise = async ({ id, collection, context, data, doc, docWithLocal
|
|
|
172
163
|
data,
|
|
173
164
|
doc,
|
|
174
165
|
docWithLocales,
|
|
175
|
-
duplicate,
|
|
176
166
|
errors,
|
|
177
167
|
fields: field.fields,
|
|
178
168
|
global,
|
|
@@ -201,7 +191,6 @@ export const promise = async ({ id, collection, context, data, doc, docWithLocal
|
|
|
201
191
|
data,
|
|
202
192
|
doc,
|
|
203
193
|
docWithLocales,
|
|
204
|
-
duplicate,
|
|
205
194
|
errors,
|
|
206
195
|
fields: field.fields,
|
|
207
196
|
global,
|
|
@@ -241,7 +230,6 @@ export const promise = async ({ id, collection, context, data, doc, docWithLocal
|
|
|
241
230
|
data,
|
|
242
231
|
doc,
|
|
243
232
|
docWithLocales,
|
|
244
|
-
duplicate,
|
|
245
233
|
errors,
|
|
246
234
|
fields: block.fields,
|
|
247
235
|
global,
|
|
@@ -274,7 +262,6 @@ export const promise = async ({ id, collection, context, data, doc, docWithLocal
|
|
|
274
262
|
data,
|
|
275
263
|
doc,
|
|
276
264
|
docWithLocales,
|
|
277
|
-
duplicate,
|
|
278
265
|
errors,
|
|
279
266
|
fields: field.fields,
|
|
280
267
|
global,
|
|
@@ -316,7 +303,6 @@ export const promise = async ({ id, collection, context, data, doc, docWithLocal
|
|
|
316
303
|
data,
|
|
317
304
|
doc,
|
|
318
305
|
docWithLocales,
|
|
319
|
-
duplicate,
|
|
320
306
|
errors,
|
|
321
307
|
fields: field.fields,
|
|
322
308
|
global,
|
|
@@ -341,7 +327,6 @@ export const promise = async ({ id, collection, context, data, doc, docWithLocal
|
|
|
341
327
|
data,
|
|
342
328
|
doc,
|
|
343
329
|
docWithLocales,
|
|
344
|
-
duplicate,
|
|
345
330
|
errors,
|
|
346
331
|
fields: field.tabs.map((tab)=>({
|
|
347
332
|
...tab,
|
|
@@ -378,7 +363,6 @@ export const promise = async ({ id, collection, context, data, doc, docWithLocal
|
|
|
378
363
|
context,
|
|
379
364
|
data,
|
|
380
365
|
docWithLocales,
|
|
381
|
-
duplicate,
|
|
382
366
|
errors,
|
|
383
367
|
field,
|
|
384
368
|
global,
|