payload 3.62.0 → 3.63.0-internal.dc01f92

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.
@@ -1 +1 @@
1
- {"version":3,"file":"duplicate.d.ts","sourceRoot":"","sources":["../../../src/collections/endpoints/duplicate.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AAS3D,eAAO,MAAM,gBAAgB,EAAE,cAmC9B,CAAA"}
1
+ {"version":3,"file":"duplicate.d.ts","sourceRoot":"","sources":["../../../src/collections/endpoints/duplicate.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AAS3D,eAAO,MAAM,gBAAgB,EAAE,cAuC9B,CAAA"}
@@ -8,19 +8,17 @@ import { sanitizeSelectParam } from '../../utilities/sanitizeSelectParam.js';
8
8
  import { duplicateOperation } from '../operations/duplicate.js';
9
9
  export const duplicateHandler = async (req)=>{
10
10
  const { id, collection } = getRequestCollectionWithID(req);
11
- const { searchParams } = req;
12
- const depth = searchParams.get('depth');
13
- // draft defaults to true, unless explicitly set requested as false to prevent the newly duplicated document from being published
14
- const draft = searchParams.get('draft') !== 'false';
11
+ const { depth, draft, populate, select, selectedLocales } = req.query;
15
12
  const doc = await duplicateOperation({
16
13
  id,
17
14
  collection,
18
15
  data: req.data,
19
16
  depth: isNumber(depth) ? Number(depth) : undefined,
20
- draft,
21
- populate: sanitizePopulateParam(req.query.populate),
17
+ draft: draft === 'true',
18
+ populate: sanitizePopulateParam(populate),
22
19
  req,
23
- select: sanitizeSelectParam(req.query.select)
20
+ select: sanitizeSelectParam(select),
21
+ selectedLocales
24
22
  });
25
23
  const message = req.t('general:successfullyDuplicated', {
26
24
  label: getTranslation(collection.config.labels.singular, req.i18n)
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/collections/endpoints/duplicate.ts"],"sourcesContent":["import { getTranslation } from '@payloadcms/translations'\nimport { status as httpStatus } from 'http-status'\n\nimport type { PayloadHandler } from '../../config/types.js'\n\nimport { getRequestCollectionWithID } from '../../utilities/getRequestEntity.js'\nimport { headersWithCors } from '../../utilities/headersWithCors.js'\nimport { isNumber } from '../../utilities/isNumber.js'\nimport { sanitizePopulateParam } from '../../utilities/sanitizePopulateParam.js'\nimport { sanitizeSelectParam } from '../../utilities/sanitizeSelectParam.js'\nimport { duplicateOperation } from '../operations/duplicate.js'\n\nexport const duplicateHandler: PayloadHandler = async (req) => {\n const { id, collection } = getRequestCollectionWithID(req)\n const { searchParams } = req\n const depth = searchParams.get('depth')\n // draft defaults to true, unless explicitly set requested as false to prevent the newly duplicated document from being published\n const draft = searchParams.get('draft') !== 'false'\n\n const doc = await duplicateOperation({\n id,\n collection,\n data: req.data,\n depth: isNumber(depth) ? Number(depth) : undefined,\n draft,\n populate: sanitizePopulateParam(req.query.populate),\n req,\n select: sanitizeSelectParam(req.query.select),\n })\n\n const message = req.t('general:successfullyDuplicated', {\n label: getTranslation(collection.config.labels.singular, req.i18n),\n })\n\n return Response.json(\n {\n doc,\n message,\n },\n {\n headers: headersWithCors({\n headers: new Headers(),\n req,\n }),\n status: httpStatus.OK,\n },\n )\n}\n"],"names":["getTranslation","status","httpStatus","getRequestCollectionWithID","headersWithCors","isNumber","sanitizePopulateParam","sanitizeSelectParam","duplicateOperation","duplicateHandler","req","id","collection","searchParams","depth","get","draft","doc","data","Number","undefined","populate","query","select","message","t","label","config","labels","singular","i18n","Response","json","headers","Headers","OK"],"mappings":"AAAA,SAASA,cAAc,QAAQ,2BAA0B;AACzD,SAASC,UAAUC,UAAU,QAAQ,cAAa;AAIlD,SAASC,0BAA0B,QAAQ,sCAAqC;AAChF,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,QAAQ,QAAQ,8BAA6B;AACtD,SAASC,qBAAqB,QAAQ,2CAA0C;AAChF,SAASC,mBAAmB,QAAQ,yCAAwC;AAC5E,SAASC,kBAAkB,QAAQ,6BAA4B;AAE/D,OAAO,MAAMC,mBAAmC,OAAOC;IACrD,MAAM,EAAEC,EAAE,EAAEC,UAAU,EAAE,GAAGT,2BAA2BO;IACtD,MAAM,EAAEG,YAAY,EAAE,GAAGH;IACzB,MAAMI,QAAQD,aAAaE,GAAG,CAAC;IAC/B,iIAAiI;IACjI,MAAMC,QAAQH,aAAaE,GAAG,CAAC,aAAa;IAE5C,MAAME,MAAM,MAAMT,mBAAmB;QACnCG;QACAC;QACAM,MAAMR,IAAIQ,IAAI;QACdJ,OAAOT,SAASS,SAASK,OAAOL,SAASM;QACzCJ;QACAK,UAAUf,sBAAsBI,IAAIY,KAAK,CAACD,QAAQ;QAClDX;QACAa,QAAQhB,oBAAoBG,IAAIY,KAAK,CAACC,MAAM;IAC9C;IAEA,MAAMC,UAAUd,IAAIe,CAAC,CAAC,kCAAkC;QACtDC,OAAO1B,eAAeY,WAAWe,MAAM,CAACC,MAAM,CAACC,QAAQ,EAAEnB,IAAIoB,IAAI;IACnE;IAEA,OAAOC,SAASC,IAAI,CAClB;QACEf;QACAO;IACF,GACA;QACES,SAAS7B,gBAAgB;YACvB6B,SAAS,IAAIC;YACbxB;QACF;QACAT,QAAQC,WAAWiC,EAAE;IACvB;AAEJ,EAAC"}
1
+ {"version":3,"sources":["../../../src/collections/endpoints/duplicate.ts"],"sourcesContent":["import { getTranslation } from '@payloadcms/translations'\nimport { status as httpStatus } from 'http-status'\n\nimport type { PayloadHandler } from '../../config/types.js'\n\nimport { getRequestCollectionWithID } from '../../utilities/getRequestEntity.js'\nimport { headersWithCors } from '../../utilities/headersWithCors.js'\nimport { isNumber } from '../../utilities/isNumber.js'\nimport { sanitizePopulateParam } from '../../utilities/sanitizePopulateParam.js'\nimport { sanitizeSelectParam } from '../../utilities/sanitizeSelectParam.js'\nimport { duplicateOperation } from '../operations/duplicate.js'\n\nexport const duplicateHandler: PayloadHandler = async (req) => {\n const { id, collection } = getRequestCollectionWithID(req)\n const { depth, draft, populate, select, selectedLocales } = req.query as {\n depth?: string\n draft?: string\n populate?: Record<string, unknown>\n select?: Record<string, unknown>\n selectedLocales?: string[]\n }\n\n const doc = await duplicateOperation({\n id,\n collection,\n data: req.data,\n depth: isNumber(depth) ? Number(depth) : undefined,\n draft: draft === 'true',\n populate: sanitizePopulateParam(populate),\n req,\n select: sanitizeSelectParam(select),\n selectedLocales,\n })\n\n const message = req.t('general:successfullyDuplicated', {\n label: getTranslation(collection.config.labels.singular, req.i18n),\n })\n\n return Response.json(\n {\n doc,\n message,\n },\n {\n headers: headersWithCors({\n headers: new Headers(),\n req,\n }),\n status: httpStatus.OK,\n },\n )\n}\n"],"names":["getTranslation","status","httpStatus","getRequestCollectionWithID","headersWithCors","isNumber","sanitizePopulateParam","sanitizeSelectParam","duplicateOperation","duplicateHandler","req","id","collection","depth","draft","populate","select","selectedLocales","query","doc","data","Number","undefined","message","t","label","config","labels","singular","i18n","Response","json","headers","Headers","OK"],"mappings":"AAAA,SAASA,cAAc,QAAQ,2BAA0B;AACzD,SAASC,UAAUC,UAAU,QAAQ,cAAa;AAIlD,SAASC,0BAA0B,QAAQ,sCAAqC;AAChF,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,QAAQ,QAAQ,8BAA6B;AACtD,SAASC,qBAAqB,QAAQ,2CAA0C;AAChF,SAASC,mBAAmB,QAAQ,yCAAwC;AAC5E,SAASC,kBAAkB,QAAQ,6BAA4B;AAE/D,OAAO,MAAMC,mBAAmC,OAAOC;IACrD,MAAM,EAAEC,EAAE,EAAEC,UAAU,EAAE,GAAGT,2BAA2BO;IACtD,MAAM,EAAEG,KAAK,EAAEC,KAAK,EAAEC,QAAQ,EAAEC,MAAM,EAAEC,eAAe,EAAE,GAAGP,IAAIQ,KAAK;IAQrE,MAAMC,MAAM,MAAMX,mBAAmB;QACnCG;QACAC;QACAQ,MAAMV,IAAIU,IAAI;QACdP,OAAOR,SAASQ,SAASQ,OAAOR,SAASS;QACzCR,OAAOA,UAAU;QACjBC,UAAUT,sBAAsBS;QAChCL;QACAM,QAAQT,oBAAoBS;QAC5BC;IACF;IAEA,MAAMM,UAAUb,IAAIc,CAAC,CAAC,kCAAkC;QACtDC,OAAOzB,eAAeY,WAAWc,MAAM,CAACC,MAAM,CAACC,QAAQ,EAAElB,IAAImB,IAAI;IACnE;IAEA,OAAOC,SAASC,IAAI,CAClB;QACEZ;QACAI;IACF,GACA;QACES,SAAS5B,gBAAgB;YACvB4B,SAAS,IAAIC;YACbvB;QACF;QACAT,QAAQC,WAAWgC,EAAE;IACvB;AAEJ,EAAC"}
@@ -16,6 +16,7 @@ export type Arguments<TSlug extends CollectionSlug> = {
16
16
  publishSpecificLocale?: string;
17
17
  req: PayloadRequest;
18
18
  select?: SelectType;
19
+ selectedLocales?: string[];
19
20
  showHiddenFields?: boolean;
20
21
  };
21
22
  export declare const createOperation: <TSlug extends CollectionSlug, TSelect extends SelectFromCollectionSlug<TSlug>>(incomingArgs: Arguments<TSlug>) => Promise<TransformCollectionWithSelect<TSlug, TSelect>>;
@@ -1 +1 @@
1
- {"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../../src/collections/operations/create.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAc,MAAM,gBAAgB,CAAA;AAChE,OAAO,KAAK,EAEV,cAAc,EACd,YAAY,EACZ,UAAU,EACV,6BAA6B,EAC9B,MAAM,sBAAsB,CAAA;AAC7B,OAAO,KAAK,EACV,UAAU,EACV,sBAAsB,EACtB,8BAA8B,EAC9B,wBAAwB,EACzB,MAAM,oBAAoB,CAAA;AAsB3B,MAAM,MAAM,SAAS,CAAC,KAAK,SAAS,cAAc,IAAI;IACpD,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,UAAU,EAAE,UAAU,CAAA;IACtB,IAAI,EAAE,8BAA8B,CAAC,KAAK,CAAC,CAAA;IAC3C,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,kBAAkB,CAAC,EAAE,OAAO,CAAA;IAC5B,wB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AK,CAAC,EAAE,OAAO,CAAA;IACf,eAAe,CAAC,EAAE,sBAAsB,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,CAAA;IACrD,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,sBAAsB,CAAC,EAAE,OAAO,CAAA;IAChC,QAAQ,CAAC,EAAE,YAAY,CAAA;IACvB,qBAAqB,CAAC,EAAE,MAAM,CAAA;IAC9B,GAAG,EAAE,cAAc,CAAA;IACnB,MAAM,CAAC,EAAE,UAAU,CAAA;IACnB,eAAe,CAAC,EAAE,MAAM,EAAE,CAAA;IAC1B,gBAAgB,CAAC,EAAE,OAAO,CAAA;CAC3B,CAAA;AAED,eAAO,MAAM,eAAe,GAC1B,KAAK,SAAS,cAAc,EAC5B,OAAO,SAAS,wBAAwB,CAAC,KAAK,CAAC,gBAEjC,SAAS,CAAC,KAAK,CAAC,KAC7B,OAAO,CAAC,6BAA6B,CAAC,KAAK,EAAE,OAAO,CAAC,CAgWvD,CAAA"}
@@ -46,7 +46,7 @@ export const createOperation = async (incomingArgs)=>{
46
46
  if (args.publishSpecificLocale) {
47
47
  args.req.locale = args.publishSpecificLocale;
48
48
  }
49
- const { autosave = false, collection: { config: collectionConfig }, collection, depth, disableVerificationEmail, draft = false, duplicateFromID, overrideAccess, overwriteExistingFiles = false, populate, publishSpecificLocale, req: { fallbackLocale, locale, payload, payload: { config } }, req, select: incomingSelect, showHiddenFields } = args;
49
+ const { autosave = false, collection: { config: collectionConfig }, collection, depth, disableVerificationEmail, draft = false, duplicateFromID, overrideAccess, overwriteExistingFiles = false, populate, publishSpecificLocale, req: { fallbackLocale, locale, payload, payload: { config } }, req, select: incomingSelect, selectedLocales, showHiddenFields } = args;
50
50
  let { data } = args;
51
51
  const isSavingDraft = Boolean(draft && collectionConfig.versions.drafts);
52
52
  let duplicatedFromDocWithLocales = {};
@@ -58,7 +58,8 @@ export const createOperation = async (incomingArgs)=>{
58
58
  draftArg: isSavingDraft,
59
59
  isSavingDraft,
60
60
  overrideAccess,
61
- req
61
+ req,
62
+ selectedLocales
62
63
  });
63
64
  duplicatedFromDoc = duplicateResult.duplicatedFromDoc;
64
65
  duplicatedFromDocWithLocales = duplicateResult.duplicatedFromDocWithLocales;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/collections/operations/create.ts"],"sourcesContent":["import crypto from 'crypto'\n\nimport type { CollectionSlug, JsonObject } from '../../index.js'\nimport type {\n Document,\n PayloadRequest,\n PopulateType,\n SelectType,\n TransformCollectionWithSelect,\n} from '../../types/index.js'\nimport type {\n Collection,\n DataFromCollectionSlug,\n RequiredDataFromCollectionSlug,\n SelectFromCollectionSlug,\n} from '../config/types.js'\n\nimport { ensureUsernameOrEmail } from '../../auth/ensureUsernameOrEmail.js'\nimport { executeAccess } from '../../auth/executeAccess.js'\nimport { sendVerificationEmail } from '../../auth/sendVerificationEmail.js'\nimport { registerLocalStrategy } from '../../auth/strategies/local/register.js'\nimport { getDuplicateDocumentData } from '../../duplicateDocument/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 { saveVersion } from '../../index.js'\nimport { generateFileData } from '../../uploads/generateFileData.js'\nimport { unlinkTempFiles } from '../../uploads/unlinkTempFiles.js'\nimport { uploadFiles } from '../../uploads/uploadFiles.js'\nimport { commitTransaction } from '../../utilities/commitTransaction.js'\nimport { initTransaction } from '../../utilities/initTransaction.js'\nimport { killTransaction } from '../../utilities/killTransaction.js'\nimport { sanitizeInternalFields } from '../../utilities/sanitizeInternalFields.js'\nimport { sanitizeSelect } from '../../utilities/sanitizeSelect.js'\nimport { buildAfterOperation } from './utils.js'\n\nexport type Arguments<TSlug extends CollectionSlug> = {\n autosave?: boolean\n collection: Collection\n data: RequiredDataFromCollectionSlug<TSlug>\n depth?: number\n disableTransaction?: boolean\n disableVerificationEmail?: boolean\n draft?: boolean\n duplicateFromID?: DataFromCollectionSlug<TSlug>['id']\n overrideAccess?: boolean\n overwriteExistingFiles?: boolean\n populate?: PopulateType\n publishSpecificLocale?: string\n req: PayloadRequest\n select?: SelectType\n showHiddenFields?: boolean\n}\n\nexport const createOperation = async <\n TSlug extends CollectionSlug,\n TSelect extends SelectFromCollectionSlug<TSlug>,\n>(\n incomingArgs: Arguments<TSlug>,\n): Promise<TransformCollectionWithSelect<TSlug, TSelect>> => {\n let args = incomingArgs\n\n try {\n const shouldCommit = !args.disableTransaction && (await initTransaction(args.req))\n\n ensureUsernameOrEmail<TSlug>({\n authOptions: args.collection.config.auth,\n collectionSlug: args.collection.config.slug,\n data: args.data,\n operation: 'create',\n req: args.req,\n })\n\n // /////////////////////////////////////\n // beforeOperation - Collection\n // /////////////////////////////////////\n\n if (args.collection.config.hooks.beforeOperation?.length) {\n for (const hook of args.collection.config.hooks.beforeOperation) {\n args =\n (await hook({\n args,\n collection: args.collection.config,\n context: args.req.context,\n operation: 'create',\n req: args.req,\n })) || args\n }\n }\n\n if (args.publishSpecificLocale) {\n args.req.locale = args.publishSpecificLocale\n }\n\n const {\n autosave = false,\n collection: { config: collectionConfig },\n collection,\n depth,\n disableVerificationEmail,\n draft = false,\n duplicateFromID,\n overrideAccess,\n overwriteExistingFiles = false,\n populate,\n publishSpecificLocale,\n req: {\n fallbackLocale,\n locale,\n payload,\n payload: { config },\n },\n req,\n select: incomingSelect,\n showHiddenFields,\n } = args\n\n let { data } = args\n\n const isSavingDraft = Boolean(draft && collectionConfig.versions.drafts)\n\n let duplicatedFromDocWithLocales: JsonObject = {}\n let duplicatedFromDoc: JsonObject = {}\n\n if (duplicateFromID) {\n const duplicateResult = await getDuplicateDocumentData({\n id: duplicateFromID,\n collectionConfig,\n draftArg: isSavingDraft,\n isSavingDraft,\n overrideAccess,\n req,\n })\n\n duplicatedFromDoc = duplicateResult.duplicatedFromDoc\n duplicatedFromDocWithLocales = duplicateResult.duplicatedFromDocWithLocales\n }\n\n // /////////////////////////////////////\n // Access\n // /////////////////////////////////////\n\n if (!overrideAccess) {\n await executeAccess({ data, req }, collectionConfig.access.create)\n }\n\n // /////////////////////////////////////\n // Generate data for all files and sizes\n // /////////////////////////////////////\n\n const { data: newFileData, files: filesToUpload } = await generateFileData({\n collection,\n config,\n data,\n isDuplicating: Boolean(duplicateFromID),\n operation: 'create',\n originalDoc: duplicatedFromDoc,\n overwriteExistingFiles,\n req,\n throwOnMissingFile:\n !isSavingDraft && collection.config.upload.filesRequiredOnCreate !== false,\n })\n\n data = newFileData\n\n // /////////////////////////////////////\n // beforeValidate - Fields\n // /////////////////////////////////////\n\n data = await beforeValidate({\n collection: collectionConfig,\n context: req.context,\n data,\n doc: duplicatedFromDoc,\n global: null,\n operation: 'create',\n overrideAccess: overrideAccess!,\n req,\n })\n\n // /////////////////////////////////////\n // beforeValidate - Collections\n // /////////////////////////////////////\n\n if (collectionConfig.hooks.beforeValidate?.length) {\n for (const hook of collectionConfig.hooks.beforeValidate) {\n data =\n (await hook({\n collection: collectionConfig,\n context: req.context,\n data,\n operation: 'create',\n originalDoc: duplicatedFromDoc,\n req,\n })) || data\n }\n }\n\n // /////////////////////////////////////\n // beforeChange - Collection\n // /////////////////////////////////////\n\n if (collectionConfig.hooks?.beforeChange?.length) {\n for (const hook of collectionConfig.hooks.beforeChange) {\n data =\n (await hook({\n collection: collectionConfig,\n context: req.context,\n data,\n operation: 'create',\n originalDoc: duplicatedFromDoc,\n req,\n })) || data\n }\n }\n\n // /////////////////////////////////////\n // beforeChange - Fields\n // /////////////////////////////////////\n\n const resultWithLocales = await beforeChange<JsonObject>({\n collection: collectionConfig,\n context: req.context,\n data,\n doc: duplicatedFromDoc,\n docWithLocales: duplicatedFromDocWithLocales,\n global: null,\n operation: 'create',\n overrideAccess,\n req,\n skipValidation:\n isSavingDraft &&\n collectionConfig.versions.drafts &&\n !collectionConfig.versions.drafts.validate,\n })\n\n // /////////////////////////////////////\n // Write files to local storage\n // /////////////////////////////////////\n\n if (!collectionConfig.upload.disableLocalStorage) {\n await uploadFiles(payload, filesToUpload, req)\n }\n\n // /////////////////////////////////////\n // Create\n // /////////////////////////////////////\n\n let doc\n\n const select = sanitizeSelect({\n fields: collectionConfig.flattenedFields,\n forceSelect: collectionConfig.forceSelect,\n select: incomingSelect,\n })\n\n if (collectionConfig.auth && !collectionConfig.auth.disableLocalStrategy) {\n if (collectionConfig.auth.verify) {\n resultWithLocales._verified = Boolean(resultWithLocales._verified) || false\n resultWithLocales._verificationToken = crypto.randomBytes(20).toString('hex')\n }\n\n doc = await registerLocalStrategy({\n collection: collectionConfig,\n doc: resultWithLocales,\n password: data.password as string,\n payload: req.payload,\n req,\n })\n } else {\n doc = await payload.db.create({\n collection: collectionConfig.slug,\n data: resultWithLocales,\n req,\n })\n }\n\n const verificationToken = doc._verificationToken\n let result: Document = sanitizeInternalFields(doc)\n\n // /////////////////////////////////////\n // Create version\n // /////////////////////////////////////\n\n if (collectionConfig.versions) {\n await saveVersion({\n id: result.id,\n autosave,\n collection: collectionConfig,\n docWithLocales: result,\n operation: 'create',\n payload,\n publishSpecificLocale,\n req,\n })\n }\n\n // /////////////////////////////////////\n // Send verification email if applicable\n // /////////////////////////////////////\n\n if (collectionConfig.auth && collectionConfig.auth.verify && result.email) {\n await sendVerificationEmail({\n collection: { config: collectionConfig },\n config: payload.config,\n disableEmail: disableVerificationEmail!,\n email: payload.email,\n req,\n token: verificationToken,\n user: result,\n })\n }\n\n // /////////////////////////////////////\n // afterRead - Fields\n // /////////////////////////////////////\n\n result = await afterRead({\n collection: collectionConfig,\n context: req.context,\n depth: depth!,\n doc: result,\n draft,\n fallbackLocale: fallbackLocale!,\n global: null,\n locale: locale!,\n overrideAccess: overrideAccess!,\n populate,\n req,\n select,\n showHiddenFields: showHiddenFields!,\n })\n\n // /////////////////////////////////////\n // afterRead - Collection\n // /////////////////////////////////////\n\n if (collectionConfig.hooks?.afterRead?.length) {\n for (const hook of collectionConfig.hooks.afterRead) {\n result =\n (await hook({\n collection: collectionConfig,\n context: req.context,\n doc: result,\n req,\n })) || result\n }\n }\n\n // /////////////////////////////////////\n // afterChange - Fields\n // /////////////////////////////////////\n\n result = await afterChange({\n collection: collectionConfig,\n context: req.context,\n data,\n doc: result,\n global: null,\n operation: 'create',\n previousDoc: {},\n req,\n })\n\n // /////////////////////////////////////\n // afterChange - Collection\n // /////////////////////////////////////\n\n if (collectionConfig.hooks?.afterChange?.length) {\n for (const hook of collectionConfig.hooks.afterChange) {\n result =\n (await hook({\n collection: collectionConfig,\n context: req.context,\n data,\n doc: result,\n operation: 'create',\n previousDoc: {},\n req: args.req,\n })) || result\n }\n }\n\n // /////////////////////////////////////\n // afterOperation - Collection\n // /////////////////////////////////////\n\n result = await buildAfterOperation<TSlug>({\n args,\n collection: collectionConfig,\n operation: 'create',\n result,\n })\n\n await unlinkTempFiles({ collectionConfig, config, req })\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":["crypto","ensureUsernameOrEmail","executeAccess","sendVerificationEmail","registerLocalStrategy","getDuplicateDocumentData","afterChange","afterRead","beforeChange","beforeValidate","saveVersion","generateFileData","unlinkTempFiles","uploadFiles","commitTransaction","initTransaction","killTransaction","sanitizeInternalFields","sanitizeSelect","buildAfterOperation","createOperation","incomingArgs","args","shouldCommit","disableTransaction","req","authOptions","collection","config","auth","collectionSlug","slug","data","operation","hooks","beforeOperation","length","hook","context","publishSpecificLocale","locale","autosave","collectionConfig","depth","disableVerificationEmail","draft","duplicateFromID","overrideAccess","overwriteExistingFiles","populate","fallbackLocale","payload","select","incomingSelect","showHiddenFields","isSavingDraft","Boolean","versions","drafts","duplicatedFromDocWithLocales","duplicatedFromDoc","duplicateResult","id","draftArg","access","create","newFileData","files","filesToUpload","isDuplicating","originalDoc","throwOnMissingFile","upload","filesRequiredOnCreate","doc","global","resultWithLocales","docWithLocales","skipValidation","validate","disableLocalStorage","fields","flattenedFields","forceSelect","disableLocalStrategy","verify","_verified","_verificationToken","randomBytes","toString","password","db","verificationToken","result","email","disableEmail","token","user","previousDoc","error"],"mappings":"AAAA,OAAOA,YAAY,SAAQ;AAiB3B,SAASC,qBAAqB,QAAQ,sCAAqC;AAC3E,SAASC,aAAa,QAAQ,8BAA6B;AAC3D,SAASC,qBAAqB,QAAQ,sCAAqC;AAC3E,SAASC,qBAAqB,QAAQ,0CAAyC;AAC/E,SAASC,wBAAwB,QAAQ,mCAAkC;AAC3E,SAASC,WAAW,QAAQ,0CAAyC;AACrE,SAASC,SAAS,QAAQ,wCAAuC;AACjE,SAASC,YAAY,QAAQ,2CAA0C;AACvE,SAASC,cAAc,QAAQ,6CAA4C;AAC3E,SAASC,WAAW,QAAQ,iBAAgB;AAC5C,SAASC,gBAAgB,QAAQ,oCAAmC;AACpE,SAASC,eAAe,QAAQ,mCAAkC;AAClE,SAASC,WAAW,QAAQ,+BAA8B;AAC1D,SAASC,iBAAiB,QAAQ,uCAAsC;AACxE,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,sBAAsB,QAAQ,4CAA2C;AAClF,SAASC,cAAc,QAAQ,oCAAmC;AAClE,SAASC,mBAAmB,QAAQ,aAAY;AAoBhD,OAAO,MAAMC,kBAAkB,OAI7BC;IAEA,IAAIC,OAAOD;IAEX,IAAI;QACF,MAAME,eAAe,CAACD,KAAKE,kBAAkB,IAAK,MAAMT,gBAAgBO,KAAKG,GAAG;QAEhFxB,sBAA6B;YAC3ByB,aAAaJ,KAAKK,UAAU,CAACC,MAAM,CAACC,IAAI;YACxCC,gBAAgBR,KAAKK,UAAU,CAACC,MAAM,CAACG,IAAI;YAC3CC,MAAMV,KAAKU,IAAI;YACfC,WAAW;YACXR,KAAKH,KAAKG,GAAG;QACf;QAEA,wCAAwC;QACxC,+BAA+B;QAC/B,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AIa,OAAO;YACpBN;YACA0C,KAAKmB;YACLlB,QAAQ;YACR1C,WAAW;YACXiE,aAAa,CAAC;YACdzE;QACF;QAEA,wCAAwC;QACxC,2BAA2B;QAC3B,wCAAwC;QAExC,IAAIiB,iBAAiBR,KAAK,EAAE5B,aAAa8B,QAAQ;YAC/C,KAAK,MAAMC,QAAQK,iBAAiBR,KAAK,CAAC5B,WAAW,CAAE;gBACrDuF,SACE,AAAC,MAAMxD,KAAK;oBACVV,YAAYe;oBACZJ,SAASb,IAAIa,OAAO;oBACpBN;oBACA0C,KAAKmB;oBACL5D,WAAW;oBACXiE,aAAa,CAAC;oBACdzE,KAAKH,KAAKG,GAAG;gBACf,MAAOoE;YACX;QACF;QAEA,wCAAwC;QACxC,8BAA8B;QAC9B,wCAAwC;QAExCA,SAAS,MAAM1E,oBAA2B;YACxCG;YACAK,YAAYe;YACZT,WAAW;YACX4D;QACF;QAEA,MAAMjF,gBAAgB;YAAE8B;YAAkBd;YAAQH;QAAI;QAEtD,wCAAwC;QACxC,iBAAiB;QACjB,wCAAwC;QAExC,IAAIF,cAAc;YAChB,MAAMT,kBAAkBW;QAC1B;QAEA,OAAOoE;IACT,EAAE,OAAOM,OAAgB;QACvB,MAAMnF,gBAAgBM,KAAKG,GAAG;QAC9B,MAAM0E;IACR;AACF,EAAC"}
1
+ {"version":3,"sources":["../../../src/collections/operations/create.ts"],"sourcesContent":["import crypto from 'crypto'\n\nimport type { CollectionSlug, JsonObject } from '../../index.js'\nimport type {\n Document,\n PayloadRequest,\n PopulateType,\n SelectType,\n TransformCollectionWithSelect,\n} from '../../types/index.js'\nimport type {\n Collection,\n DataFromCollectionSlug,\n RequiredDataFromCollectionSlug,\n SelectFromCollectionSlug,\n} from '../config/types.js'\n\nimport { ensureUsernameOrEmail } from '../../auth/ensureUsernameOrEmail.js'\nimport { executeAccess } from '../../auth/executeAccess.js'\nimport { sendVerificationEmail } from '../../auth/sendVerificationEmail.js'\nimport { registerLocalStrategy } from '../../auth/strategies/local/register.js'\nimport { getDuplicateDocumentData } from '../../duplicateDocument/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 { saveVersion } from '../../index.js'\nimport { generateFileData } from '../../uploads/generateFileData.js'\nimport { unlinkTempFiles } from '../../uploads/unlinkTempFiles.js'\nimport { uploadFiles } from '../../uploads/uploadFiles.js'\nimport { commitTransaction } from '../../utilities/commitTransaction.js'\nimport { initTransaction } from '../../utilities/initTransaction.js'\nimport { killTransaction } from '../../utilities/killTransaction.js'\nimport { sanitizeInternalFields } from '../../utilities/sanitizeInternalFields.js'\nimport { sanitizeSelect } from '../../utilities/sanitizeSelect.js'\nimport { buildAfterOperation } from './utils.js'\n\nexport type Arguments<TSlug extends CollectionSlug> = {\n autosave?: boolean\n collection: Collection\n data: RequiredDataFromCollectionSlug<TSlug>\n depth?: number\n disableTransaction?: boolean\n disableVerificationEmail?: boolean\n draft?: boolean\n duplicateFromID?: DataFromCollectionSlug<TSlug>['id']\n overrideAccess?: boolean\n overwriteExistingFiles?: boolean\n populate?: PopulateType\n publishSpecificLocale?: string\n req: PayloadRequest\n select?: SelectType\n selectedLocales?: string[]\n showHiddenFields?: boolean\n}\n\nexport const createOperation = async <\n TSlug extends CollectionSlug,\n TSelect extends SelectFromCollectionSlug<TSlug>,\n>(\n incomingArgs: Arguments<TSlug>,\n): Promise<TransformCollectionWithSelect<TSlug, TSelect>> => {\n let args = incomingArgs\n\n try {\n const shouldCommit = !args.disableTransaction && (await initTransaction(args.req))\n\n ensureUsernameOrEmail<TSlug>({\n authOptions: args.collection.config.auth,\n collectionSlug: args.collection.config.slug,\n data: args.data,\n operation: 'create',\n req: args.req,\n })\n\n // /////////////////////////////////////\n // beforeOperation - Collection\n // /////////////////////////////////////\n\n if (args.collection.config.hooks.beforeOperation?.length) {\n for (const hook of args.collection.config.hooks.beforeOperation) {\n args =\n (await hook({\n args,\n collection: args.collection.config,\n context: args.req.context,\n operation: 'create',\n req: args.req,\n })) || args\n }\n }\n\n if (args.publishSpecificLocale) {\n args.req.locale = args.publishSpecificLocale\n }\n\n const {\n autosave = false,\n collection: { config: collectionConfig },\n collection,\n depth,\n disableVerificationEmail,\n draft = false,\n duplicateFromID,\n overrideAccess,\n overwriteExistingFiles = false,\n populate,\n publishSpecificLocale,\n req: {\n fallbackLocale,\n locale,\n payload,\n payload: { config },\n },\n req,\n select: incomingSelect,\n selectedLocales,\n showHiddenFields,\n } = args\n\n let { data } = args\n\n const isSavingDraft = Boolean(draft && collectionConfig.versions.drafts)\n\n let duplicatedFromDocWithLocales: JsonObject = {}\n let duplicatedFromDoc: JsonObject = {}\n\n if (duplicateFromID) {\n const duplicateResult = await getDuplicateDocumentData({\n id: duplicateFromID,\n collectionConfig,\n draftArg: isSavingDraft,\n isSavingDraft,\n overrideAccess,\n req,\n selectedLocales,\n })\n\n duplicatedFromDoc = duplicateResult.duplicatedFromDoc\n duplicatedFromDocWithLocales = duplicateResult.duplicatedFromDocWithLocales\n }\n\n // /////////////////////////////////////\n // Access\n // /////////////////////////////////////\n\n if (!overrideAccess) {\n await executeAccess({ data, req }, collectionConfig.access.create)\n }\n\n // /////////////////////////////////////\n // Generate data for all files and sizes\n // /////////////////////////////////////\n\n const { data: newFileData, files: filesToUpload } = await generateFileData({\n collection,\n config,\n data,\n isDuplicating: Boolean(duplicateFromID),\n operation: 'create',\n originalDoc: duplicatedFromDoc,\n overwriteExistingFiles,\n req,\n throwOnMissingFile:\n !isSavingDraft && collection.config.upload.filesRequiredOnCreate !== false,\n })\n\n data = newFileData\n\n // /////////////////////////////////////\n // beforeValidate - Fields\n // /////////////////////////////////////\n\n data = await beforeValidate({\n collection: collectionConfig,\n context: req.context,\n data,\n doc: duplicatedFromDoc,\n global: null,\n operation: 'create',\n overrideAccess: overrideAccess!,\n req,\n })\n\n // /////////////////////////////////////\n // beforeValidate - Collections\n // /////////////////////////////////////\n\n if (collectionConfig.hooks.beforeValidate?.length) {\n for (const hook of collectionConfig.hooks.beforeValidate) {\n data =\n (await hook({\n collection: collectionConfig,\n context: req.context,\n data,\n operation: 'create',\n originalDoc: duplicatedFromDoc,\n req,\n })) || data\n }\n }\n\n // /////////////////////////////////////\n // beforeChange - Collection\n // /////////////////////////////////////\n\n if (collectionConfig.hooks?.beforeChange?.length) {\n for (const hook of collectionConfig.hooks.beforeChange) {\n data =\n (await hook({\n collection: collectionConfig,\n context: req.context,\n data,\n operation: 'create',\n originalDoc: duplicatedFromDoc,\n req,\n })) || data\n }\n }\n\n // /////////////////////////////////////\n // beforeChange - Fields\n // /////////////////////////////////////\n\n const resultWithLocales = await beforeChange<JsonObject>({\n collection: collectionConfig,\n context: req.context,\n data,\n doc: duplicatedFromDoc,\n docWithLocales: duplicatedFromDocWithLocales,\n global: null,\n operation: 'create',\n overrideAccess,\n req,\n skipValidation:\n isSavingDraft &&\n collectionConfig.versions.drafts &&\n !collectionConfig.versions.drafts.validate,\n })\n\n // /////////////////////////////////////\n // Write files to local storage\n // /////////////////////////////////////\n\n if (!collectionConfig.upload.disableLocalStorage) {\n await uploadFiles(payload, filesToUpload, req)\n }\n\n // /////////////////////////////////////\n // Create\n // /////////////////////////////////////\n\n let doc\n\n const select = sanitizeSelect({\n fields: collectionConfig.flattenedFields,\n forceSelect: collectionConfig.forceSelect,\n select: incomingSelect,\n })\n\n if (collectionConfig.auth && !collectionConfig.auth.disableLocalStrategy) {\n if (collectionConfig.auth.verify) {\n resultWithLocales._verified = Boolean(resultWithLocales._verified) || false\n resultWithLocales._verificationToken = crypto.randomBytes(20).toString('hex')\n }\n\n doc = await registerLocalStrategy({\n collection: collectionConfig,\n doc: resultWithLocales,\n password: data.password as string,\n payload: req.payload,\n req,\n })\n } else {\n doc = await payload.db.create({\n collection: collectionConfig.slug,\n data: resultWithLocales,\n req,\n })\n }\n\n const verificationToken = doc._verificationToken\n let result: Document = sanitizeInternalFields(doc)\n\n // /////////////////////////////////////\n // Create version\n // /////////////////////////////////////\n\n if (collectionConfig.versions) {\n await saveVersion({\n id: result.id,\n autosave,\n collection: collectionConfig,\n docWithLocales: result,\n operation: 'create',\n payload,\n publishSpecificLocale,\n req,\n })\n }\n\n // /////////////////////////////////////\n // Send verification email if applicable\n // /////////////////////////////////////\n\n if (collectionConfig.auth && collectionConfig.auth.verify && result.email) {\n await sendVerificationEmail({\n collection: { config: collectionConfig },\n config: payload.config,\n disableEmail: disableVerificationEmail!,\n email: payload.email,\n req,\n token: verificationToken,\n user: result,\n })\n }\n\n // /////////////////////////////////////\n // afterRead - Fields\n // /////////////////////////////////////\n\n result = await afterRead({\n collection: collectionConfig,\n context: req.context,\n depth: depth!,\n doc: result,\n draft,\n fallbackLocale: fallbackLocale!,\n global: null,\n locale: locale!,\n overrideAccess: overrideAccess!,\n populate,\n req,\n select,\n showHiddenFields: showHiddenFields!,\n })\n\n // /////////////////////////////////////\n // afterRead - Collection\n // /////////////////////////////////////\n\n if (collectionConfig.hooks?.afterRead?.length) {\n for (const hook of collectionConfig.hooks.afterRead) {\n result =\n (await hook({\n collection: collectionConfig,\n context: req.context,\n doc: result,\n req,\n })) || result\n }\n }\n\n // /////////////////////////////////////\n // afterChange - Fields\n // /////////////////////////////////////\n\n result = await afterChange({\n collection: collectionConfig,\n context: req.context,\n data,\n doc: result,\n global: null,\n operation: 'create',\n previousDoc: {},\n req,\n })\n\n // /////////////////////////////////////\n // afterChange - Collection\n // /////////////////////////////////////\n\n if (collectionConfig.hooks?.afterChange?.length) {\n for (const hook of collectionConfig.hooks.afterChange) {\n result =\n (await hook({\n collection: collectionConfig,\n context: req.context,\n data,\n doc: result,\n operation: 'create',\n previousDoc: {},\n req: args.req,\n })) || result\n }\n }\n\n // /////////////////////////////////////\n // afterOperation - Collection\n // /////////////////////////////////////\n\n result = await buildAfterOperation<TSlug>({\n args,\n collection: collectionConfig,\n operation: 'create',\n result,\n })\n\n await unlinkTempFiles({ collectionConfig, config, req })\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":["crypto","ensureUsernameOrEmail","executeAccess","sendVerificationEmail","registerLocalStrategy","getDuplicateDocumentData","afterChange","afterRead","beforeChange","beforeValidate","saveVersion","generateFileData","unlinkTempFiles","uploadFiles","commitTransaction","initTransaction","killTransaction","sanitizeInternalFields","sanitizeSelect","buildAfterOperation","createOperation","incomingArgs","args","shouldCommit","disableTransaction","req","authOptions","collection","config","auth","collectionSlug","slug","data","operation","hooks","beforeOperation","length","hook","context","publishSpecificLocale","locale","autosave","collectionConfig","depth","disableVerificationEmail","draft","duplicateFromID","overrideAccess","overwriteExistingFiles","populate","fallbackLocale","payload","select","incomingSelect","selectedLocales","showHiddenFields","isSavingDraft","Boolean","versions","drafts","duplicatedFromDocWithLocales","duplicatedFromDoc","duplicateResult","id","draftArg","access","create","newFileData","files","filesToUpload","isDuplicating","originalDoc","throwOnMissingFile","upload","filesRequiredOnCreate","doc","global","resultWithLocales","docWithLocales","skipValidation","validate","disableLocalStorage","fields","flattenedFields","forceSelect","disableLocalStrategy","verify","_verified","_verificationToken","randomBytes","toString","password","db","verificationToken","result","email","disableEmail","token","user","previousDoc","error"],"mappings":"AAAA,OAAOA,YAAY,SAAQ;AAiB3B,SAASC,qBAAqB,QAAQ,sCAAqC;AAC3E,SAASC,aAAa,QAAQ,8BAA6B;AAC3D,SAASC,qBAAqB,QAAQ,sCAAqC;AAC3E,SAASC,qBAAqB,QAAQ,0CAAyC;AAC/E,SAASC,wBAAwB,QAAQ,mCAAkC;AAC3E,SAASC,WAAW,QAAQ,0CAAyC;AACrE,SAASC,SAAS,QAAQ,wCAAuC;AACjE,SAASC,YAAY,QAAQ,2CAA0C;AACvE,SAASC,cAAc,QAAQ,6CAA4C;AAC3E,SAASC,WAA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CA,SAAS,MAAM3E,oBAA2B;YACxCG;YACAK,YAAYe;YACZT,WAAW;YACX6D;QACF;QAEA,MAAMlF,gBAAgB;YAAE8B;YAAkBd;YAAQH;QAAI;QAEtD,wCAAwC;QACxC,iBAAiB;QACjB,wCAAwC;QAExC,IAAIF,cAAc;YAChB,MAAMT,kBAAkBW;QAC1B;QAEA,OAAOqE;IACT,EAAE,OAAOM,OAAgB;QACvB,MAAMpF,gBAAgBM,KAAKG,GAAG;QAC9B,MAAM2E;IACR;AACF,EAAC"}
@@ -63,6 +63,11 @@ export type Options<TSlug extends CollectionSlug, TSelect extends SelectType> =
63
63
  * Specify [select](https://payloadcms.com/docs/queries/select) to control which fields to include to the result.
64
64
  */
65
65
  select?: TSelect;
66
+ /**
67
+ * Specifies which locales to include when duplicating localized fields. Non-localized data is always duplicated.
68
+ * By default, all locales are duplicated.
69
+ */
70
+ selectedLocales?: string[];
66
71
  /**
67
72
  * Opt-in to receiving hidden fields. By default, they are hidden from returned documents in accordance to your config.
68
73
  * @default false
@@ -1 +1 @@
1
- {"version":3,"file":"duplicate.d.ts","sourceRoot":"","sources":["../../../../src/collections/operations/local/duplicate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAEhD,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AACrE,OAAO,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAChE,OAAO,KAAK,EACV,QAAQ,EACR,cAAc,EACd,YAAY,EACZ,UAAU,EACV,6BAA6B,EAC9B,MAAM,yBAAyB,CAAA;AAEhC,OAAO,KAAK,EACV,8BAA8B,EAC9B,wBAAwB,EACzB,MAAM,uBAAuB,CAAA;AAM9B,MAAM,MAAM,OAAO,CAAC,KAAK,SAAS,cAAc,EAAE,OAAO,SAAS,UAAU,IAAI;IAC9E;;OAEG;IACH,UAAU,EAAE,KAAK,CAAA;IACjB;;;;;OAKG;IACH,OAAO,CAAC,EAAE,cAAc,CAAA;IACxB;;OAEG;IACH,IAAI,CAAC,EAAE,WAAW,CAAC,8BAA8B,CAAC,KAAK,CAAC,CAAC,CAAA;IACzD;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAA;IACd;;;OAGG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAA;IAC5B;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,CAAA;IACf;;OAEG;IACH,cAAc,CAAC,EAAE,KAAK,GAAG,WAAW,CAAA;IACpC;;OAEG;IACH,EAAE,EAAE,MAAM,GAAG,MAAM,CAAA;IACnB;;OAEG;IACH,MAAM,CAAC,EAAE,WAAW,CAAA;IACpB;;;;OAIG;IACH,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB;;OAEG;IACH,QAAQ,CAAC,EAAE,YAAY,CAAA;IACvB;;;OAGG;IACH,GAAG,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC,CAAA;IAC7B;;OAEG;IACH,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB;;;OAGG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAA;IAC1B;;OAEG;IACH,IAAI,CAAC,EAAE,QAAQ,CAAA;CAChB,CAAA;AAED,wBAAsB,cAAc,CAClC,KAAK,SAAS,cAAc,EAC5B,OAAO,SAAS,wBAAwB,CAAC,KAAK,CAAC,EAE/C,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,GAC/B,OAAO,CAAC,6BAA6B,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,CA4CxD"}
1
+ {"version":3,"file":"duplicate.d.ts","sourceRoot":"","sources":["../../../../src/collections/operations/local/duplicate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAEhD,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAC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K,SAAS,cAAc,EAC5B,OAAO,SAAS,wBAAwB,CAAC,KAAK,CAAC,EAE/C,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,GAC/B,OAAO,CAAC,6BAA6B,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,CA8CxD"}
@@ -2,7 +2,7 @@ import { APIError } from '../../../errors/index.js';
2
2
  import { createLocalReq } from '../../../utilities/createLocalReq.js';
3
3
  import { duplicateOperation } from '../duplicate.js';
4
4
  export async function duplicateLocal(payload, options) {
5
- const { id, collection: collectionSlug, data, depth, disableTransaction, draft, overrideAccess = true, populate, select, showHiddenFields } = options;
5
+ const { id, collection: collectionSlug, data, depth, disableTransaction, draft, overrideAccess = true, populate, select, selectedLocales, showHiddenFields } = options;
6
6
  const collection = payload.collections[collectionSlug];
7
7
  if (!collection) {
8
8
  throw new APIError(`The collection with slug ${String(collectionSlug)} can't be found. Duplicate Operation.`);
@@ -22,6 +22,7 @@ export async function duplicateLocal(payload, options) {
22
22
  populate,
23
23
  req,
24
24
  select,
25
+ selectedLocales,
25
26
  showHiddenFields
26
27
  });
27
28
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/collections/operations/local/duplicate.ts"],"sourcesContent":["import type { DeepPartial } from 'ts-essentials'\n\nimport type { CollectionSlug, TypedLocale } from '../../..//index.js'\nimport type { Payload, RequestContext } from '../../../index.js'\nimport type {\n Document,\n PayloadRequest,\n PopulateType,\n SelectType,\n TransformCollectionWithSelect,\n} from '../../../types/index.js'\nimport type { CreateLocalReqOptions } from '../../../utilities/createLocalReq.js'\nimport type {\n RequiredDataFromCollectionSlug,\n SelectFromCollectionSlug,\n} from '../../config/types.js'\n\nimport { APIError } from '../../../errors/index.js'\nimport { createLocalReq } from '../../../utilities/createLocalReq.js'\nimport { duplicateOperation } from '../duplicate.js'\n\nexport type Options<TSlug extends CollectionSlug, TSelect extends SelectType> = {\n /**\n * the Collection slug to operate against.\n */\n collection: TSlug\n /**\n * [Context](https://payloadcms.com/docs/hooks/context), which will then be passed to `context` and `req.context`,\n * which can be read by hooks. Useful if you want to pass additional information to the hooks which\n * shouldn't be necessarily part of the document, for example a `triggerBeforeChange` option which can be read by the BeforeChange hook\n * to determine if it should run or not.\n */\n context?: RequestContext\n /**\n * Override the data for the document to duplicate.\n */\n data?: DeepPartial<RequiredDataFromCollectionSlug<TSlug>>\n /**\n * [Control auto-population](https://payloadcms.com/docs/queries/depth) of nested relationship and upload fields.\n */\n depth?: number\n /**\n * When set to `true`, a [database transactions](https://payloadcms.com/docs/database/transactions) will not be initialized.\n * @default false\n */\n disableTransaction?: boolean\n /**\n * Create a **draft** document. [More](https://payloadcms.com/docs/versions/drafts#draft-api)\n */\n draft?: boolean\n /**\n * Specify a [fallback locale](https://payloadcms.com/docs/configuration/localization) to use for any returned documents.\n */\n fallbackLocale?: false | TypedLocale\n /**\n * The ID of the document to duplicate from.\n */\n id: number | string\n /**\n * Specify [locale](https://payloadcms.com/docs/configuration/localization) for any returned documents.\n */\n locale?: TypedLocale\n /**\n * Skip access control.\n * Set to `false` if you want to respect Access Control for the operation, for example when fetching data for the front-end.\n * @default true\n */\n overrideAccess?: boolean\n /**\n * Specify [populate](https://payloadcms.com/docs/queries/select#populate) to control which fields to include to the result from populated documents.\n */\n populate?: PopulateType\n /**\n * The `PayloadRequest` object. You can pass it to thread the current [transaction](https://payloadcms.com/docs/database/transactions), user and locale to the operation.\n * Recommended to pass when using the Local API from hooks, as usually you want to execute the operation within the current transaction.\n */\n req?: Partial<PayloadRequest>\n /**\n * Specify [select](https://payloadcms.com/docs/queries/select) to control which fields to include to the result.\n */\n select?: TSelect\n /**\n * Opt-in to receiving hidden fields. By default, they are hidden from returned documents in accordance to your config.\n * @default false\n */\n showHiddenFields?: boolean\n /**\n * If you set `overrideAccess` to `false`, you can pass a user to use against the access control checks.\n */\n user?: Document\n}\n\nexport async function duplicateLocal<\n TSlug extends CollectionSlug,\n TSelect extends SelectFromCollectionSlug<TSlug>,\n>(\n payload: Payload,\n options: Options<TSlug, TSelect>,\n): Promise<TransformCollectionWithSelect<TSlug, TSelect>> {\n const {\n id,\n collection: collectionSlug,\n data,\n depth,\n disableTransaction,\n draft,\n overrideAccess = true,\n populate,\n select,\n showHiddenFields,\n } = options\n\n const collection = payload.collections[collectionSlug]\n\n if (!collection) {\n throw new APIError(\n `The collection with slug ${String(collectionSlug)} can't be found. Duplicate Operation.`,\n )\n }\n\n if (collection.config.disableDuplicate === true) {\n throw new APIError(\n `The collection with slug ${String(collectionSlug)} cannot be duplicated.`,\n 400,\n )\n }\n\n const req = await createLocalReq(options as CreateLocalReqOptions, payload)\n\n return duplicateOperation<TSlug, TSelect>({\n id,\n collection,\n data,\n depth,\n disableTransaction,\n draft,\n overrideAccess,\n populate,\n req,\n select,\n showHiddenFields,\n })\n}\n"],"names":["APIError","createLocalReq","duplicateOperation","duplicateLocal","payload","options","id","collection","collectionSlug","data","depth","disableTransaction","draft","overrideAccess","populate","select","showHiddenFields","collections","String","config","disableDuplicate","req"],"mappings":"AAiBA,SAASA,QAAQ,QAAQ,2BAA0B;AACnD,SAASC,cAAc,QAAQ,uCAAsC;AACrE,SAASC,kBAAkB,QAAQ,kBAAiB;AAyEpD,OAAO,eAAeC,eAIpBC,OAAgB,EAChBC,OAAgC;IAEhC,MAAM,EACJC,EAAE,EACFC,YAAYC,cAAc,EAC1BC,IAAI,EACJC,KAAK,EACLC,kBAAkB,EAClBC,KAAK,EACLC,iBAAiB,IAAI,EACrBC,QAAQ,EACRC,MAAM,EACNC,gBAAgB,EACjB,GAAGX;IAEJ,MAAME,aAAaH,QAAQa,WAAW,CAACT,eAAe;IAEtD,IAAI,CAACD,YAAY;QACf,MAAM,IAAIP,SACR,CAAC,yBAAyB,EAAEkB,OAAOV,gBAAgB,qCAAqC,CAAC;IAE7F;IAEA,IAAID,WAAWY,MAAM,CAACC,gBAAgB,KAAK,MAAM;QAC/C,MAAM,IAAIpB,SACR,CAAC,yBAAyB,EAAEkB,OAAOV,gBAAgB,sBAAsB,CAAC,EAC1E;IAEJ;IAEA,MAAMa,MAAM,MAAMpB,eAAeI,SAAkCD;IAEnE,OAAOF,mBAAmC;QACxCI;QACAC;QACAE;QACAC;QACAC;QACAC;QACAC;QACAC;QACAO;QACAN;QACAC;IACF;AACF"}
1
+ {"version":3,"sources":["../../../../src/collections/operations/local/duplicate.ts"],"sourcesContent":["import type { DeepPartial } from 'ts-essentials'\n\nimport type { CollectionSlug, TypedLocale } from '../../..//index.js'\nimport type { Payload, RequestContext } from '../../../index.js'\nimport type {\n Document,\n PayloadRequest,\n PopulateType,\n SelectType,\n TransformCollectionWithSelect,\n} from '../../../types/index.js'\nimport type { CreateLocalReqOptions } from '../../../utilities/createLocalReq.js'\nimport type {\n RequiredDataFromCollectionSlug,\n SelectFromCollectionSlug,\n} from '../../config/types.js'\n\nimport { APIError } from '../../../errors/index.js'\nimport { createLocalReq } from '../../../utilities/createLocalReq.js'\nimport { duplicateOperation } from '../duplicate.js'\n\nexport type Options<TSlug extends CollectionSlug, TSelect extends SelectType> = {\n /**\n * the Collection slug to operate against.\n */\n collection: TSlug\n /**\n * [Context](https://payloadcms.com/docs/hooks/context), which will then be passed to `context` and `req.context`,\n * which can be read by hooks. Useful if you want to pass additional information to the hooks which\n * shouldn't be necessarily part of the document, for example a `triggerBeforeChange` option which can be read by the BeforeChange hook\n * to determine if it should run or not.\n */\n context?: RequestContext\n /**\n * Override the data for the document to duplicate.\n */\n data?: DeepPartial<RequiredDataFromCollectionSlug<TSlug>>\n /**\n * [Control auto-population](https://payloadcms.com/docs/queries/depth) of nested relationship and upload fields.\n */\n depth?: number\n /**\n * When set to `true`, a [database transactions](https://payloadcms.com/docs/database/transactions) will not be initialized.\n * @default false\n */\n disableTransaction?: boolean\n /**\n * Create a **draft** document. [More](https://payloadcms.com/docs/versions/drafts#draft-api)\n */\n draft?: boolean\n /**\n * Specify a [fallback locale](https://payloadcms.com/docs/configuration/localization) to use for any returned documents.\n */\n fallbackLocale?: false | TypedLocale\n /**\n * The ID of the document to duplicate from.\n */\n id: number | string\n /**\n * Specify [locale](https://payloadcms.com/docs/configuration/localization) for any returned documents.\n */\n locale?: TypedLocale\n /**\n * Skip access control.\n * Set to `false` if you want to respect Access Control for the operation, for example when fetching data for the front-end.\n * @default true\n */\n overrideAccess?: boolean\n /**\n * Specify [populate](https://payloadcms.com/docs/queries/select#populate) to control which fields to include to the result from populated documents.\n */\n populate?: PopulateType\n /**\n * The `PayloadRequest` object. You can pass it to thread the current [transaction](https://payloadcms.com/docs/database/transactions), user and locale to the operation.\n * Recommended to pass when using the Local API from hooks, as usually you want to execute the operation within the current transaction.\n */\n req?: Partial<PayloadRequest>\n /**\n * Specify [select](https://payloadcms.com/docs/queries/select) to control which fields to include to the result.\n */\n select?: TSelect\n /**\n * Specifies which locales to include when duplicating localized fields. Non-localized data is always duplicated.\n * By default, all locales are duplicated.\n */\n selectedLocales?: string[]\n /**\n * Opt-in to receiving hidden fields. By default, they are hidden from returned documents in accordance to your config.\n * @default false\n */\n showHiddenFields?: boolean\n /**\n * If you set `overrideAccess` to `false`, you can pass a user to use against the access control checks.\n */\n user?: Document\n}\n\nexport async function duplicateLocal<\n TSlug extends CollectionSlug,\n TSelect extends SelectFromCollectionSlug<TSlug>,\n>(\n payload: Payload,\n options: Options<TSlug, TSelect>,\n): Promise<TransformCollectionWithSelect<TSlug, TSelect>> {\n const {\n id,\n collection: collectionSlug,\n data,\n depth,\n disableTransaction,\n draft,\n overrideAccess = true,\n populate,\n select,\n selectedLocales,\n showHiddenFields,\n } = options\n\n const collection = payload.collections[collectionSlug]\n\n if (!collection) {\n throw new APIError(\n `The collection with slug ${String(collectionSlug)} can't be found. Duplicate Operation.`,\n )\n }\n\n if (collection.config.disableDuplicate === true) {\n throw new APIError(\n `The collection with slug ${String(collectionSlug)} cannot be duplicated.`,\n 400,\n )\n }\n\n const req = await createLocalReq(options as CreateLocalReqOptions, payload)\n\n return duplicateOperation<TSlug, TSelect>({\n id,\n collection,\n data,\n depth,\n disableTransaction,\n draft,\n overrideAccess,\n populate,\n req,\n select,\n selectedLocales,\n showHiddenFields,\n })\n}\n"],"names":["APIError","createLocalReq","duplicateOperation","duplicateLocal","payload","options","id","collection","collectionSlug","data","depth","disableTransaction","draft","overrideAccess","populate","select","selectedLocales","showHiddenFields","collections","String","config","disableDuplicate","req"],"mappings":"AAiBA,SAASA,QAAQ,QAAQ,2BAA0B;AACnD,SAASC,cAAc,QAAQ,uCAAsC;AACrE,SAASC,kBAAkB,QAAQ,kBAAiB;AA8EpD,OAAO,eAAeC,eAIpBC,OAAgB,EAChBC,OAAgC;IAEhC,MAAM,EACJC,EAAE,EACFC,YAAYC,cAAc,EAC1BC,IAAI,EACJC,KAAK,EACLC,kBAAkB,EAClBC,KAAK,EACLC,iBAAiB,IAAI,EACrBC,QAAQ,EACRC,MAAM,EACNC,eAAe,EACfC,gBAAgB,EACjB,GAAGZ;IAEJ,MAAME,aAAaH,QAAQc,WAAW,CAACV,eAAe;IAEtD,IAAI,CAACD,YAAY;QACf,MAAM,IAAIP,SACR,CAAC,yBAAyB,EAAEmB,OAAOX,gBAAgB,qCAAqC,CAAC;IAE7F;IAEA,IAAID,WAAWa,MAAM,CAACC,gBAAgB,KAAK,MAAM;QAC/C,MAAM,IAAIrB,SACR,CAAC,yBAAyB,EAAEmB,OAAOX,gBAAgB,sBAAsB,CAAC,EAC1E;IAEJ;IAEA,MAAMc,MAAM,MAAMrB,eAAeI,SAAkCD;IAEnE,OAAOF,mBAAmC;QACxCI;QACAC;QACAE;QACAC;QACAC;QACAC;QACAC;QACAC;QACAQ;QACAP;QACAC;QACAC;IACF;AACF"}
@@ -7,8 +7,9 @@ type GetDuplicateDocumentArgs = {
7
7
  isSavingDraft?: boolean;
8
8
  overrideAccess?: boolean;
9
9
  req: PayloadRequest;
10
+ selectedLocales?: string[];
10
11
  };
11
- export declare const getDuplicateDocumentData: ({ id, collectionConfig, draftArg, isSavingDraft, overrideAccess, req, }: GetDuplicateDocumentArgs) => Promise<{
12
+ export declare const getDuplicateDocumentData: ({ id, collectionConfig, draftArg, isSavingDraft, overrideAccess, req, selectedLocales, }: GetDuplicateDocumentArgs) => Promise<{
12
13
  duplicatedFromDoc: JsonObject;
13
14
  duplicatedFromDocWithLocales: JsonObject;
14
15
  }>;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/duplicateDocument/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAA;AAE/E,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAYnE,KAAK,wBAAwB,GAAG;IAC9B,gBAAgB,EAAE,yBAAyB,CAAA;IAC3C,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,EAAE,EAAE,MAAM,GAAG,MAAM,CAAA;IACnB,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,GAAG,EAAE,cAAc,CAAA;CACpB,CAAA;AACD,eAAO,MAAM,wBAAwB,4EAOlC,wBAAwB,KAAG,OAAO,CAAC;IACpC,iBAAiB,EAAE,UAAU,CAAA;IAC7B,4BAA4B,EAAE,UAAU,CAAA;CACzC,CA0EA,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/duplicateDocument/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAA;AAE/E,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAanE,KAAK,wBAAwB,GAAG;IAC9B,gBAAgB,EAAE,yBAAyB,CAAA;IAC3C,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,EAAE,EAAE,MAAM,GAAG,MAAM,CAAA;IACnB,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,GAAG,EAAE,cAAc,CAAA;IACnB,eAAe,CAAC,EAAE,MAAM,EAAE,CAAA;CAC3B,CAAA;AACD,eAAO,MAAM,wBAAwB,6FAQlC,wBAAwB,KAAG,OAAO,CAAC;IACpC,iBAAiB,EAAE,UAAU,CAAA;IAC7B,4BAA4B,EAAE,UAAU,CAAA;CACzC,CAmFA,CAAA"}
@@ -6,8 +6,9 @@ import { NotFound } from '../errors/NotFound.js';
6
6
  import { afterRead } from '../fields/hooks/afterRead/index.js';
7
7
  import { beforeDuplicate } from '../fields/hooks/beforeDuplicate/index.js';
8
8
  import { deepCopyObjectSimple } from '../utilities/deepCopyObject.js';
9
+ import { filterDataToSelectedLocales } from '../utilities/filterDataToSelectedLocales.js';
9
10
  import { getLatestCollectionVersion } from '../versions/getLatestCollectionVersion.js';
10
- export const getDuplicateDocumentData = async ({ id, collectionConfig, draftArg, isSavingDraft, overrideAccess, req })=>{
11
+ export const getDuplicateDocumentData = async ({ id, collectionConfig, draftArg, isSavingDraft, overrideAccess, req, selectedLocales })=>{
11
12
  const { payload } = req;
12
13
  // /////////////////////////////////////
13
14
  // Read Access
@@ -37,6 +38,14 @@ export const getDuplicateDocumentData = async ({ id, collectionConfig, draftArg,
37
38
  query: findOneArgs,
38
39
  req
39
40
  });
41
+ if (selectedLocales && selectedLocales.length > 0 && duplicatedFromDocWithLocales) {
42
+ duplicatedFromDocWithLocales = filterDataToSelectedLocales({
43
+ configBlockReferences: payload.config.blocks,
44
+ docWithLocales: duplicatedFromDocWithLocales,
45
+ fields: collectionConfig.fields,
46
+ selectedLocales
47
+ });
48
+ }
40
49
  if (!duplicatedFromDocWithLocales && !hasWherePolicy) {
41
50
  throw new NotFound(req.t);
42
51
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/duplicateDocument/index.ts"],"sourcesContent":["import type { SanitizedCollectionConfig } from '../collections/config/types.js'\nimport type { FindOneArgs } from '../database/types.js'\nimport type { JsonObject, PayloadRequest } from '../types/index.js'\n\nimport { executeAccess } from '../auth/executeAccess.js'\nimport { hasWhereAccessResult } from '../auth/types.js'\nimport { combineQueries } from '../database/combineQueries.js'\nimport { Forbidden } from '../errors/Forbidden.js'\nimport { NotFound } from '../errors/NotFound.js'\nimport { afterRead } from '../fields/hooks/afterRead/index.js'\nimport { beforeDuplicate } from '../fields/hooks/beforeDuplicate/index.js'\nimport { deepCopyObjectSimple } from '../utilities/deepCopyObject.js'\nimport { getLatestCollectionVersion } from '../versions/getLatestCollectionVersion.js'\n\ntype GetDuplicateDocumentArgs = {\n collectionConfig: SanitizedCollectionConfig\n draftArg?: boolean\n id: number | string\n isSavingDraft?: boolean\n overrideAccess?: boolean\n req: PayloadRequest\n}\nexport const getDuplicateDocumentData = async ({\n id,\n collectionConfig,\n draftArg,\n isSavingDraft,\n overrideAccess,\n req,\n}: GetDuplicateDocumentArgs): Promise<{\n duplicatedFromDoc: JsonObject\n duplicatedFromDocWithLocales: JsonObject\n}> => {\n const { payload } = req\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 duplicatedFromDocWithLocales = await getLatestCollectionVersion({\n id,\n config: collectionConfig,\n payload,\n query: findOneArgs,\n req,\n })\n\n if (!duplicatedFromDocWithLocales && !hasWherePolicy) {\n throw new NotFound(req.t)\n }\n if (!duplicatedFromDocWithLocales && hasWherePolicy) {\n throw new Forbidden(req.t)\n }\n\n // remove the createdAt timestamp and rely on the db to set it\n if ('createdAt' in duplicatedFromDocWithLocales) {\n delete duplicatedFromDocWithLocales.createdAt\n }\n // remove the id and rely on the db to set it\n if ('id' in duplicatedFromDocWithLocales) {\n delete duplicatedFromDocWithLocales.id\n }\n\n duplicatedFromDocWithLocales = await beforeDuplicate({\n id,\n collection: collectionConfig,\n context: req.context,\n doc: duplicatedFromDocWithLocales,\n overrideAccess: 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 (isSavingDraft) {\n duplicatedFromDocWithLocales._status = 'draft'\n }\n\n const duplicatedFromDoc = await afterRead({\n collection: collectionConfig,\n context: req.context,\n depth: 0,\n doc: deepCopyObjectSimple(duplicatedFromDocWithLocales),\n draft: draftArg!,\n fallbackLocale: null,\n global: null,\n locale: req.locale!,\n overrideAccess: true,\n req,\n showHiddenFields: true,\n })\n\n return { duplicatedFromDoc, duplicatedFromDocWithLocales }\n}\n"],"names":["executeAccess","hasWhereAccessResult","combineQueries","Forbidden","NotFound","afterRead","beforeDuplicate","deepCopyObjectSimple","getLatestCollectionVersion","getDuplicateDocumentData","id","collectionConfig","draftArg","isSavingDraft","overrideAccess","req","payload","accessResults","access","read","hasWherePolicy","findOneArgs","collection","slug","locale","where","equals","duplicatedFromDocWithLocales","config","query","t","createdAt","context","doc","_status","duplicatedFromDoc","depth","draft","fallbackLocale","global","showHiddenFields"],"mappings":"AAIA,SAASA,aAAa,QAAQ,2BAA0B;AACxD,SAASC,oBAAoB,QAAQ,mBAAkB;AACvD,SAASC,cAAc,QAAQ,gCAA+B;AAC9D,SAASC,SAAS,QAAQ,yBAAwB;AAClD,SAASC,QAAQ,QAAQ,wBAAuB;AAChD,SAASC,SAAS,QAAQ,qCAAoC;AAC9D,SAASC,eAAe,QAAQ,2CAA0C;AAC1E,SAASC,oBAAoB,QAAQ,iCAAgC;AACrE,SAASC,0BAA0B,QAAQ,4CAA2C;AAUtF,OAAO,MAAMC,2BAA2B,OAAO,EAC7CC,EAAE,EACFC,gBAAgB,EAChBC,QAAQ,EACRC,aAAa,EACbC,cAAc,EACdC,GAAG,EACsB;IAIzB,MAAM,EAAEC,OAAO,EAAE,GA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ACAyB,kBAAkB;IACpB;IAEA,OAAO;QAAEL;QAAmBR;IAA6B;AAC3D,EAAC"}
1
+ {"version":3,"sources":["../../src/duplicateDocument/index.ts"],"sourcesContent":["import type { SanitizedCollectionConfig } from '../collections/config/types.js'\nimport type { FindOneArgs } from '../database/types.js'\nimport type { JsonObject, PayloadRequest } from '../types/index.js'\n\nimport { executeAccess } from '../auth/executeAccess.js'\nimport { hasWhereAccessResult } from '../auth/types.js'\nimport { combineQueries } from '../database/combineQueries.js'\nimport { Forbidden } from '../errors/Forbidden.js'\nimport { NotFound } from '../errors/NotFound.js'\nimport { afterRead } from '../fields/hooks/afterRead/index.js'\nimport { beforeDuplicate } from '../fields/hooks/beforeDuplicate/index.js'\nimport { deepCopyObjectSimple } from '../utilities/deepCopyObject.js'\nimport { filterDataToSelectedLocales } from '../utilities/filterDataToSelectedLocales.js'\nimport { getLatestCollectionVersion } from '../versions/getLatestCollectionVersion.js'\n\ntype GetDuplicateDocumentArgs = {\n collectionConfig: SanitizedCollectionConfig\n draftArg?: boolean\n id: number | string\n isSavingDraft?: boolean\n overrideAccess?: boolean\n req: PayloadRequest\n selectedLocales?: string[]\n}\nexport const getDuplicateDocumentData = async ({\n id,\n collectionConfig,\n draftArg,\n isSavingDraft,\n overrideAccess,\n req,\n selectedLocales,\n}: GetDuplicateDocumentArgs): Promise<{\n duplicatedFromDoc: JsonObject\n duplicatedFromDocWithLocales: JsonObject\n}> => {\n const { payload } = req\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 duplicatedFromDocWithLocales = await getLatestCollectionVersion({\n id,\n config: collectionConfig,\n payload,\n query: findOneArgs,\n req,\n })\n\n if (selectedLocales && selectedLocales.length > 0 && duplicatedFromDocWithLocales) {\n duplicatedFromDocWithLocales = filterDataToSelectedLocales({\n configBlockReferences: payload.config.blocks,\n docWithLocales: duplicatedFromDocWithLocales,\n fields: collectionConfig.fields,\n selectedLocales,\n })\n }\n\n if (!duplicatedFromDocWithLocales && !hasWherePolicy) {\n throw new NotFound(req.t)\n }\n if (!duplicatedFromDocWithLocales && hasWherePolicy) {\n throw new Forbidden(req.t)\n }\n\n // remove the createdAt timestamp and rely on the db to set it\n if ('createdAt' in duplicatedFromDocWithLocales) {\n delete duplicatedFromDocWithLocales.createdAt\n }\n // remove the id and rely on the db to set it\n if ('id' in duplicatedFromDocWithLocales) {\n delete duplicatedFromDocWithLocales.id\n }\n\n duplicatedFromDocWithLocales = await beforeDuplicate({\n id,\n collection: collectionConfig,\n context: req.context,\n doc: duplicatedFromDocWithLocales,\n overrideAccess: 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 (isSavingDraft) {\n duplicatedFromDocWithLocales._status = 'draft'\n }\n\n const duplicatedFromDoc = await afterRead({\n collection: collectionConfig,\n context: req.context,\n depth: 0,\n doc: deepCopyObjectSimple(duplicatedFromDocWithLocales),\n draft: draftArg!,\n fallbackLocale: null,\n global: null,\n locale: req.locale!,\n overrideAccess: true,\n req,\n showHiddenFields: true,\n })\n\n return { duplicatedFromDoc, duplicatedFromDocWithLocales }\n}\n"],"names":["executeAccess","hasWhereAccessResult","combineQueries","Forbidden","NotFound","afterRead","beforeDuplicate","deepCopyObjectSimple","filterDataToSelectedLocales","getLatestCollectionVersion","getDuplicateDocumentData","id","collectionConfig","draftArg","isSavingDraft","overrideAccess","req","selectedLocales","payload","accessResults","access","read","hasWherePolicy","findOneArgs","collection","slug","locale","where","equals","duplicatedFromDocWithLocales","config","query","length","configBlockReferences","blocks","docWithLocales","fields","t","createdAt","context","doc","_status","duplicatedFromDoc","depth","draft","fall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F;IACF;IAEA,IAAI,CAACY,gCAAgC,CAACP,gBAAgB;QACpD,MAAM,IAAIlB,SAASY,IAAIqB,CAAC;IAC1B;IACA,IAAI,CAACR,gCAAgCP,gBAAgB;QACnD,MAAM,IAAInB,UAAUa,IAAIqB,CAAC;IAC3B;IAEA,8DAA8D;IAC9D,IAAI,eAAeR,8BAA8B;QAC/C,OAAOA,6BAA6BS,SAAS;IAC/C;IACA,6CAA6C;IAC7C,IAAI,QAAQT,8BAA8B;QACxC,OAAOA,6BAA6BlB,EAAE;IACxC;IAEAkB,+BAA+B,MAAMvB,gBAAgB;QACnDK;QACAa,YAAYZ;QACZ2B,SAASvB,IAAIuB,OAAO;QACpBC,KAAKX;QACLd,gBAAgBA;QAChBC;IACF;IAEA,mHAAmH;IACnH,IAAIF,eAAe;QACjBe,6BAA6BY,OAAO,GAAG;IACzC;IAEA,MAAMC,oBAAoB,MAAMrC,UAAU;QACxCmB,YAAYZ;QACZ2B,SAASvB,IAAIuB,OAAO;QACpBI,OAAO;QACPH,KAAKjC,qBAAqBsB;QAC1Be,OAAO/B;QACPgC,gBAAgB;QAChBC,QAAQ;QACRpB,QAAQV,IAAIU,MAAM;QAClBX,gBAAgB;QAChBC;QACA+B,kBAAkB;IACpB;IAEA,OAAO;QAAEL;QAAmBb;IAA6B;AAC3D,EAAC"}
@@ -19,7 +19,7 @@ import { ReadonlyRequestCookies } from 'next/dist/server/web/spec-extension/adap
19
19
  import { PinoPretty } from 'pino-pretty';
20
20
  import { DatePickerProps } from 'react-datepicker';
21
21
 
22
- declare const clientTranslationKeys: ("authentication:account" | "authentication:accountOfCurrentUser" | "authentication:accountVerified" | "authentication:alreadyActivated" | "authentication:alreadyLoggedIn" | "authentication:apiKey" | "authentication:authenticated" | "authentication:backToLogin" | "authentication:beginCreateFirstUser" | "authentication:changePassword" | "authentication:checkYourEmailForPasswordReset" | "authentication:confirmGeneration" | "authentication:confirmPassword" | "authentication:createFirstUser" | "authentication:emailNotValid" | "authentication:emailOrUsername" | "authentication:emailSent" | "authentication:emailVerified" | "authentication:enableAPIKey" | "authentication:failedToUnlock" | "authentication:forceUnlock" | "authentication:forgotPassword" | "authentication:forgotPasswordEmailInstructions" | "authentication:forgotPasswordUsernameInstructions" | "authentication:usernameNotValid" | "authentication:forgotPasswordQuestion" | "authentication:generate" | "authentication:generateNewAPIKey" | "authentication:generatingNewAPIKeyWillInvalidate" | "authentication:logBackIn" | "authentication:loggedIn" | "authentication:loggedInChangePassword" | "authentication:loggedOutInactivity" | "authentication:loggedOutSuccessfully" | "authentication:loggingOut" | "authentication:login" | "authentication:logOut" | "authentication:logout" | "authentication:logoutSuccessful" | "authentication:logoutUser" | "authentication:newAPIKeyGenerated" | "authentication:newPassword" | "authentication:passed" | "authentication:passwordResetSuccessfully" | "authentication:resetPassword" | "authentication:stayLoggedIn" | "authentication:successfullyRegisteredFirstUser" | "authentication:successfullyUnlocked" | "authentication:tokenRefreshSuccessful" | "authentication:unableToVerify" | "authentication:username" | "authentication:verified" | "authentication:verifiedSuccessfully" | "authentication:verify" | "authentication:verifyUser" | "authentication:youAreInactive" | "error:autosaving" | "error:correctInvalidFields" | "error:deletingTitle" | "error:documentNotFound" | "error:emailOrPasswordIncorrect" | "error:insufficientClipboardPermissions" | "error:invalidClipboardData" | "error:invalidFileType" | "error:invalidRequestArgs" | "error:loadingDocument" | "error:logoutFailed" | "error:noMatchedField" | "error:notAllowedToAccessPage" | "error:previewing" | "error:problemUploadingFile" | "error:restoringTitle" | "error:tokenNotProvided" | "error:unableToCopy" | "error:unableToDeleteCount" | "error:unableToReindexCollection" | "error:unableToUpdateCount" | "error:unauthorized" | "error:unauthorizedAdmin" | "error:unknown" | "error:unPublishingDocument" | "error:unspecific" | "error:unverifiedEmail" | "error:userEmailAlreadyRegistered" | "error:usernameAlreadyRegistered" | "error:usernameOrPasswordIncorrect" | "fields:blocks" | "fields:addLabel" | "fields:addLink" | "fields:addNew" | "fields:addNewLabel" | "fields:addRelationship" | "fields:addUpload" | "fields:block" | "fields:blockType" | "fields:chooseBetweenCustomTextOrDocument" | "fields:chooseDocumentToLink" | "fields:chooseFromExisting" | "fields:collapseAll" | "fields:customURL" | "fields:editLink" | "fields:editRelationship" | "fields:enterURL" | "fields:internalLink" | "fields:itemsAndMore" | "fields:labelRelationship" | "fields:latitude" | "fields:linkedTo" | "fields:linkType" | "fields:longitude" | "fields:openInNewTab" | "fields:passwordsDoNotMatch" | "fields:removeRelationship" | "fields:removeUpload" | "fields:saveChanges" | "fields:searchForBlock" | "fields:searchForLanguage" | "fields:selectFieldsToEdit" | "fields:showAll" | "fields:swapRelationship" | "fields:swapUpload" | "fields:textToDisplay" | "fields:toggleBlock" | "fields:uploadNewLabel" | "folder:browseByFolder" | "folder:byFolder" | "folder:deleteFolder" | "folder:folderName" | "folder:folders" | "folder:folderTypeDescription" | "folder:itemHasBeenMoved" | "folder:itemHasBeenMovedToRoot" | "folder:itemsMovedToFolder" | "folder:itemsMovedToRoot" | "folder:moveFolder" | "folder:moveItemsToFolderConfirmation" | "folder:moveItemsToRootConfirmation" | "folder:moveItemToFolderConfirmation" | "folder:moveItemToRootConfirmation" | "folder:movingFromFolder" | "folder:newFolder" | "folder:noFolder" | "folder:renameFolder" | "folder:searchByNameInFolder" | "folder:selectFolderForItem" | "general:items" | "general:of" | "general:language" | "general:error" | "general:username" | "general:notFound" | "general:unauthorized" | "general:newLabel" | "general:name" | "general:aboutToDelete" | "general:aboutToPermanentlyDelete" | "general:aboutToPermanentlyDeleteTrash" | "general:aboutToRestore" | "general:aboutToRestoreAsDraft" | "general:aboutToRestoreAsDraftCount" | "general:aboutToRestoreCount" | "general:aboutToTrash" | "general:aboutToTrashCount" | "general:addBelow" | "general:addFilter" | "general:adminTheme" | "general:all" | "general:allCollections" | "general:allLocales" | "general:and" | "general:anotherUser" | "general:anotherUserTakenOver" | "general:applyChanges" | "general:ascending" | "general:automatic" | "general:backToDashboard" | "general:cancel" | "general:changesNotSaved" | "general:clear" | "general:clearAll" | "general:close" | "general:collapse" | "general:collections" | "general:columns" | "general:columnToSort" | "general:confirm" | "general:confirmCopy" | "general:confirmDeletion" | "general:confirmDuplication" | "general:confirmMove" | "general:confirmReindex" | "general:confirmReindexAll" | "general:confirmReindexDescription" | "general:confirmReindexDescriptionAll" | "general:confirmRestoration" | "general:copied" | "general:copy" | "general:copyField" | "general:copying" | "general:copyRow" | "general:copyWarning" | "general:create" | "general:created" | "general:createdAt" | "general:createNew" | "general:createNewLabel" | "general:creating" | "general:creatingNewLabel" | "general:currentlyEditing" | "general:custom" | "general:dark" | "general:dashboard" | "general:delete" | "general:deleted" | "general:deletedAt" | "general:deletedCountSuccessfully" | "general:deletedSuccessfully" | "general:deleteLabel" | "general:deletePermanently" | "general:deleting" | "general:depth" | "general:descending" | "general:deselectAllRows" | "general:document" | "general:documentIsTrashed" | "general:documentLocked" | "general:documents" | "general:duplicate" | "general:duplicateWithoutSaving" | "general:edit" | "general:editAll" | "general:editedSince" | "general:editing" | "general:editingTakenOver" | "general:editLabel" | "general:email" | "general:emailAddress" | "general:emptyTrash" | "general:emptyTrashLabel" | "general:enterAValue" | "general:errors" | "general:exitLivePreview" | "general:export" | "general:fallbackToDefaultLocale" | "general:false" | "general:filters" | "general:filterWhere" | "general:globals" | "general:goBack" | "general:groupByLabel" | "general:import" | "general:isEditing" | "general:item" | "general:lastModified" | "general:leaveAnyway" | "general:leaveWithoutSaving" | "general:light" | "general:livePreview" | "general:loading" | "general:locale" | "general:locales" | "general:menu" | "general:moreOptions" | "general:move" | "general:moveConfirm" | "general:moveCount" | "general:moveDown" | "general:moveUp" | "general:moving" | "general:movingCount" | "general:next" | "general:no" | "general:noDateSelected" | "general:noFiltersSet" | "general:noLabel" | "general:none" | "general:noOptions" | "general:noResults" | "general:nothingFound" | "general:noTrashResults" | "general:noUpcomingEventsScheduled" | "general:noValue" | "general:only" | "general:open" | "general:or" | "general:order" | "general:overwriteExistingData" | "general:pageNotFound" | "general:password" | "general:pasteField" | "general:pasteRow" | "general:payloadSettings" | "general:permanentlyDelete" | "general:permanentlyDeletedCountSuccessfully" | "general:perPage" | "general:previous" | "general:reindex" | "general:reindexingAll" | "general:remove" | "general:rename" | "general:reset" | "general:resetPreferences" | "general:resetPreferencesDescription" | "general:resettingPreferences" | "general:restore" | "general:restoreAsPublished" | "general:restoredCountSuccessfully" | "general:restoring" | "general:row" | "general:rows" | "general:save" | "general:saving" | "general:schedulePublishFor" | "general:searchBy" | "general:select" | "general:selectAll" | "general:selectAllRows" | "general:selectedCount" | "general:selectLabel" | "general:selectValue" | "general:showAllLabel" | "general:sorryNotFound" | "general:sort" | "general:sortByLabelDirection" | "general:stayOnThisPage" | "general:submissionSuccessful" | "general:submit" | "general:submitting" | "general:success" | "general:successfullyCreated" | "general:successfullyDuplicated" | "general:successfullyReindexed" | "general:takeOver" | "general:thisLanguage" | "general:time" | "general:timezone" | "general:titleDeleted" | "general:titleRestored" | "general:titleTrashed" | "general:trash" | "general:trashedCountSuccessfully" | "general:true" | "general:unsavedChanges" | "general:unsavedChangesDuplicate" | "general:untitled" | "general:upcomingEvents" | "general:updatedAt" | "general:updatedCountSuccessfully" | "general:updatedLabelSuccessfully" | "general:updatedSuccessfully" | "general:updateForEveryone" | "general:updating" | "general:uploading" | "general:uploadingBulk" | "general:user" | "general:users" | "general:value" | "general:viewing" | "general:viewReadOnly" | "general:welcome" | "general:yes" | "localization:cannotCopySameLocale" | "localization:copyFrom" | "localization:copyFromTo" | "localization:copyTo" | "localization:copyToLocale" | "localization:localeToPublish" | "localization:selectLocaleToCopy" | "operators:contains" | "operators:equals" | "operators:exists" | "operators:intersects" | "operators:near" | "operators:within" | "operators:isGreaterThan" | "operators:isGreaterThanOrEqualTo" | "operators:isIn" | "operators:isLessThan" | "operators:isLessThanOrEqualTo" | "operators:isLike" | "operators:isNotEqualTo" | "operators:isNotIn" | "operators:isNotLike" | "upload:addFile" | "upload:addFiles" | "upload:bulkUpload" | "upload:crop" | "upload:cropToolDescription" | "upload:download" | "upload:dragAndDrop" | "upload:editImage" | "upload:fileName" | "upload:fileSize" | "upload:filesToUpload" | "upload:fileToUpload" | "upload:focalPoint" | "upload:focalPointDescription" | "upload:height" | "upload:noFile" | "upload:pasteURL" | "upload:previewSizes" | "upload:selectCollectionToBrowse" | "upload:selectFile" | "upload:setCropArea" | "upload:setFocalPoint" | "upload:sizes" | "upload:sizesFor" | "upload:width" | "validation:username" | "validation:emailAddress" | "validation:enterNumber" | "validation:fieldHasNo" | "validation:greaterThanMax" | "validation:invalidBlock" | "validation:invalidBlocks" | "validation:invalidInput" | "validation:invalidSelection" | "validation:invalidSelections" | "validation:latitudeOutOfBounds" | "validation:lessThanMin" | "validation:limitReached" | "validation:longerThanMin" | "validation:longitudeOutOfBounds" | "validation:notValidDate" | "validation:required" | "validation:requiresAtLeast" | "validation:requiresNoMoreThan" | "validation:requiresTwoNumbers" | "validation:shorterThanMax" | "validation:timezoneRequired" | "validation:trueOrFalse" | "validation:validUploadID" | "version:version" | "version:aboutToRestore" | "version:restoring" | "version:type" | "version:aboutToPublishSelection" | "version:aboutToRestoreGlobal" | "version:aboutToRevertToPublished" | "version:aboutToUnpublish" | "version:aboutToUnpublishSelection" | "version:autosave" | "version:autosavedSuccessfully" | "version:autosavedVersion" | "version:changed" | "version:compareVersions" | "version:comparingAgainst" | "version:confirmPublish" | "version:confirmRevertToSaved" | "version:confirmUnpublish" | "version:confirmVersionRestoration" | "version:currentDraft" | "version:currentlyPublished" | "version:currentlyViewing" | "version:currentPublishedVersion" | "version:draft" | "version:draftSavedSuccessfully" | "version:lastSavedAgo" | "version:modifiedOnly" | "version:moreVersions" | "version:noFurtherVersionsFound" | "version:noLabelGroup" | "version:noRowsFound" | "version:noRowsSelected" | "version:preview" | "version:previouslyDraft" | "version:previouslyPublished" | "version:previousVersion" | "version:problemRestoringVersion" | "version:publish" | "version:publishAllLocales" | "version:publishChanges" | "version:published" | "version:publishIn" | "version:publishing" | "version:restoreAsDraft" | "version:restoredSuccessfully" | "version:restoreThisVersion" | "version:reverting" | "version:revertToPublished" | "version:saveDraft" | "version:scheduledSuccessfully" | "version:schedulePublish" | "version:selectLocales" | "version:selectVersionToCompare" | "version:showLocales" | "version:specificVersion" | "version:status" | "version:unpublish" | "version:unpublishing" | "version:versionAgo" | "version:versionID" | "version:versions" | "version:viewingVersion" | "version:viewingVersionGlobal" | "version:viewingVersions" | "version:viewingVersionsGlobal" | "general:aboutToDeleteCount" | "general:editingLabel" | "version:changedFieldsCount")[];
22
+ declare const clientTranslationKeys: ("authentication:account" | "authentication:accountOfCurrentUser" | "authentication:accountVerified" | "authentication:alreadyActivated" | "authentication:alreadyLoggedIn" | "authentication:apiKey" | "authentication:authenticated" | "authentication:backToLogin" | "authentication:beginCreateFirstUser" | "authentication:changePassword" | "authentication:checkYourEmailForPasswordReset" | "authentication:confirmGeneration" | "authentication:confirmPassword" | "authentication:createFirstUser" | "authentication:emailNotValid" | "authentication:emailOrUsername" | "authentication:emailSent" | "authentication:emailVerified" | "authentication:enableAPIKey" | "authentication:failedToUnlock" | "authentication:forceUnlock" | "authentication:forgotPassword" | "authentication:forgotPasswordEmailInstructions" | "authentication:forgotPasswordUsernameInstructions" | "authentication:usernameNotValid" | "authentication:forgotPasswordQuestion" | "authentication:generate" | "authentication:generateNewAPIKey" | "authentication:generatingNewAPIKeyWillInvalidate" | "authentication:logBackIn" | "authentication:loggedIn" | "authentication:loggedInChangePassword" | "authentication:loggedOutInactivity" | "authentication:loggedOutSuccessfully" | "authentication:loggingOut" | "authentication:login" | "authentication:logOut" | "authentication:logout" | "authentication:logoutSuccessful" | "authentication:logoutUser" | "authentication:newAPIKeyGenerated" | "authentication:newPassword" | "authentication:passed" | "authentication:passwordResetSuccessfully" | "authentication:resetPassword" | "authentication:stayLoggedIn" | "authentication:successfullyRegisteredFirstUser" | "authentication:successfullyUnlocked" | "authentication:tokenRefreshSuccessful" | "authentication:unableToVerify" | "authentication:username" | "authentication:verified" | "authentication:verifiedSuccessfully" | "authentication:verify" | "authentication:verifyUser" | "authentication:youAreInactive" | "error:autosaving" | "error:correctInvalidFields" | "error:deletingTitle" | "error:documentNotFound" | "error:emailOrPasswordIncorrect" | "error:insufficientClipboardPermissions" | "error:invalidClipboardData" | "error:invalidFileType" | "error:invalidRequestArgs" | "error:loadingDocument" | "error:logoutFailed" | "error:noMatchedField" | "error:notAllowedToAccessPage" | "error:previewing" | "error:problemUploadingFile" | "error:restoringTitle" | "error:tokenNotProvided" | "error:unableToCopy" | "error:unableToDeleteCount" | "error:unableToReindexCollection" | "error:unableToUpdateCount" | "error:unauthorized" | "error:unauthorizedAdmin" | "error:unknown" | "error:unPublishingDocument" | "error:unspecific" | "error:unverifiedEmail" | "error:userEmailAlreadyRegistered" | "error:usernameAlreadyRegistered" | "error:usernameOrPasswordIncorrect" | "fields:blocks" | "fields:addLabel" | "fields:addLink" | "fields:addNew" | "fields:addNewLabel" | "fields:addRelationship" | "fields:addUpload" | "fields:block" | "fields:blockType" | "fields:chooseBetweenCustomTextOrDocument" | "fields:chooseDocumentToLink" | "fields:chooseFromExisting" | "fields:collapseAll" | "fields:customURL" | "fields:editLink" | "fields:editRelationship" | "fields:enterURL" | "fields:internalLink" | "fields:itemsAndMore" | "fields:labelRelationship" | "fields:latitude" | "fields:linkedTo" | "fields:linkType" | "fields:longitude" | "fields:openInNewTab" | "fields:passwordsDoNotMatch" | "fields:removeRelationship" | "fields:removeUpload" | "fields:saveChanges" | "fields:searchForBlock" | "fields:searchForLanguage" | "fields:selectFieldsToEdit" | "fields:showAll" | "fields:swapRelationship" | "fields:swapUpload" | "fields:textToDisplay" | "fields:toggleBlock" | "fields:uploadNewLabel" | "folder:browseByFolder" | "folder:byFolder" | "folder:deleteFolder" | "folder:folderName" | "folder:folders" | "folder:folderTypeDescription" | "folder:itemHasBeenMoved" | "folder:itemHasBeenMovedToRoot" | "folder:itemsMovedToFolder" | "folder:itemsMovedToRoot" | "folder:moveFolder" | "folder:moveItemsToFolderConfirmation" | "folder:moveItemsToRootConfirmation" | "folder:moveItemToFolderConfirmation" | "folder:moveItemToRootConfirmation" | "folder:movingFromFolder" | "folder:newFolder" | "folder:noFolder" | "folder:renameFolder" | "folder:searchByNameInFolder" | "folder:selectFolderForItem" | "general:items" | "general:of" | "general:language" | "general:error" | "general:username" | "general:notFound" | "general:unauthorized" | "general:newLabel" | "general:name" | "general:aboutToDelete" | "general:aboutToPermanentlyDelete" | "general:aboutToPermanentlyDeleteTrash" | "general:aboutToRestore" | "general:aboutToRestoreAsDraft" | "general:aboutToRestoreAsDraftCount" | "general:aboutToRestoreCount" | "general:aboutToTrash" | "general:aboutToTrashCount" | "general:addBelow" | "general:addFilter" | "general:adminTheme" | "general:all" | "general:allCollections" | "general:allLocales" | "general:and" | "general:anotherUser" | "general:anotherUserTakenOver" | "general:applyChanges" | "general:ascending" | "general:automatic" | "general:backToDashboard" | "general:cancel" | "general:changesNotSaved" | "general:clear" | "general:clearAll" | "general:close" | "general:collapse" | "general:collections" | "general:columns" | "general:columnToSort" | "general:confirm" | "general:confirmCopy" | "general:confirmDeletion" | "general:confirmDuplication" | "general:confirmMove" | "general:confirmReindex" | "general:confirmReindexAll" | "general:confirmReindexDescription" | "general:confirmReindexDescriptionAll" | "general:confirmRestoration" | "general:copied" | "general:copy" | "general:copyField" | "general:copying" | "general:copyRow" | "general:copyWarning" | "general:create" | "general:created" | "general:createdAt" | "general:createNew" | "general:createNewLabel" | "general:creating" | "general:creatingNewLabel" | "general:currentlyEditing" | "general:custom" | "general:dark" | "general:dashboard" | "general:delete" | "general:deleted" | "general:deletedAt" | "general:deletedCountSuccessfully" | "general:deletedSuccessfully" | "general:deleteLabel" | "general:deletePermanently" | "general:deleting" | "general:depth" | "general:descending" | "general:deselectAllRows" | "general:document" | "general:documentIsTrashed" | "general:documentLocked" | "general:documents" | "general:duplicate" | "general:duplicateWithoutSaving" | "general:edit" | "general:editAll" | "general:editedSince" | "general:editing" | "general:editingTakenOver" | "general:editLabel" | "general:email" | "general:emailAddress" | "general:emptyTrash" | "general:emptyTrashLabel" | "general:enterAValue" | "general:errors" | "general:exitLivePreview" | "general:export" | "general:fallbackToDefaultLocale" | "general:false" | "general:filters" | "general:filterWhere" | "general:globals" | "general:goBack" | "general:groupByLabel" | "general:import" | "general:isEditing" | "general:item" | "general:lastModified" | "general:leaveAnyway" | "general:leaveWithoutSaving" | "general:light" | "general:livePreview" | "general:loading" | "general:locale" | "general:locales" | "general:menu" | "general:moreOptions" | "general:move" | "general:moveConfirm" | "general:moveCount" | "general:moveDown" | "general:moveUp" | "general:moving" | "general:movingCount" | "general:next" | "general:no" | "general:noDateSelected" | "general:noFiltersSet" | "general:noLabel" | "general:none" | "general:noOptions" | "general:noResults" | "general:nothingFound" | "general:noTrashResults" | "general:noUpcomingEventsScheduled" | "general:noValue" | "general:only" | "general:open" | "general:or" | "general:order" | "general:overwriteExistingData" | "general:pageNotFound" | "general:password" | "general:pasteField" | "general:pasteRow" | "general:payloadSettings" | "general:permanentlyDelete" | "general:permanentlyDeletedCountSuccessfully" | "general:perPage" | "general:previous" | "general:reindex" | "general:reindexingAll" | "general:remove" | "general:rename" | "general:reset" | "general:resetPreferences" | "general:resetPreferencesDescription" | "general:resettingPreferences" | "general:restore" | "general:restoreAsPublished" | "general:restoredCountSuccessfully" | "general:restoring" | "general:row" | "general:rows" | "general:save" | "general:saving" | "general:schedulePublishFor" | "general:searchBy" | "general:select" | "general:selectAll" | "general:selectAllRows" | "general:selectedCount" | "general:selectLabel" | "general:selectValue" | "general:showAllLabel" | "general:sorryNotFound" | "general:sort" | "general:sortByLabelDirection" | "general:stayOnThisPage" | "general:submissionSuccessful" | "general:submit" | "general:submitting" | "general:success" | "general:successfullyCreated" | "general:successfullyDuplicated" | "general:successfullyReindexed" | "general:takeOver" | "general:thisLanguage" | "general:time" | "general:timezone" | "general:titleDeleted" | "general:titleRestored" | "general:titleTrashed" | "general:trash" | "general:trashedCountSuccessfully" | "general:true" | "general:unsavedChanges" | "general:unsavedChangesDuplicate" | "general:untitled" | "general:upcomingEvents" | "general:updatedAt" | "general:updatedCountSuccessfully" | "general:updatedLabelSuccessfully" | "general:updatedSuccessfully" | "general:updateForEveryone" | "general:updating" | "general:uploading" | "general:uploadingBulk" | "general:user" | "general:users" | "general:value" | "general:viewing" | "general:viewReadOnly" | "general:welcome" | "general:yes" | "localization:cannotCopySameLocale" | "localization:copyFrom" | "localization:copyFromTo" | "localization:copyTo" | "localization:copyToLocale" | "localization:localeToPublish" | "localization:selectedLocales" | "localization:selectLocaleToCopy" | "localization:selectLocaleToDuplicate" | "operators:contains" | "operators:equals" | "operators:exists" | "operators:intersects" | "operators:near" | "operators:within" | "operators:isGreaterThan" | "operators:isGreaterThanOrEqualTo" | "operators:isIn" | "operators:isLessThan" | "operators:isLessThanOrEqualTo" | "operators:isLike" | "operators:isNotEqualTo" | "operators:isNotIn" | "operators:isNotLike" | "upload:addFile" | "upload:addFiles" | "upload:bulkUpload" | "upload:crop" | "upload:cropToolDescription" | "upload:download" | "upload:dragAndDrop" | "upload:editImage" | "upload:fileName" | "upload:fileSize" | "upload:filesToUpload" | "upload:fileToUpload" | "upload:focalPoint" | "upload:focalPointDescription" | "upload:height" | "upload:noFile" | "upload:pasteURL" | "upload:previewSizes" | "upload:selectCollectionToBrowse" | "upload:selectFile" | "upload:setCropArea" | "upload:setFocalPoint" | "upload:sizes" | "upload:sizesFor" | "upload:width" | "validation:username" | "validation:emailAddress" | "validation:enterNumber" | "validation:fieldHasNo" | "validation:greaterThanMax" | "validation:invalidBlock" | "validation:invalidBlocks" | "validation:invalidInput" | "validation:invalidSelection" | "validation:invalidSelections" | "validation:latitudeOutOfBounds" | "validation:lessThanMin" | "validation:limitReached" | "validation:longerThanMin" | "validation:longitudeOutOfBounds" | "validation:notValidDate" | "validation:required" | "validation:requiresAtLeast" | "validation:requiresNoMoreThan" | "validation:requiresTwoNumbers" | "validation:shorterThanMax" | "validation:timezoneRequired" | "validation:trueOrFalse" | "validation:validUploadID" | "version:version" | "version:aboutToRestore" | "version:restoring" | "version:type" | "version:aboutToPublishSelection" | "version:aboutToRestoreGlobal" | "version:aboutToRevertToPublished" | "version:aboutToUnpublish" | "version:aboutToUnpublishSelection" | "version:autosave" | "version:autosavedSuccessfully" | "version:autosavedVersion" | "version:changed" | "version:compareVersions" | "version:comparingAgainst" | "version:confirmPublish" | "version:confirmRevertToSaved" | "version:confirmUnpublish" | "version:confirmVersionRestoration" | "version:currentDraft" | "version:currentlyPublished" | "version:currentlyViewing" | "version:currentPublishedVersion" | "version:draft" | "version:draftSavedSuccessfully" | "version:lastSavedAgo" | "version:modifiedOnly" | "version:moreVersions" | "version:noFurtherVersionsFound" | "version:noLabelGroup" | "version:noRowsFound" | "version:noRowsSelected" | "version:preview" | "version:previouslyDraft" | "version:previouslyPublished" | "version:previousVersion" | "version:problemRestoringVersion" | "version:publish" | "version:publishAllLocales" | "version:publishChanges" | "version:published" | "version:publishIn" | "version:publishing" | "version:restoreAsDraft" | "version:restoredSuccessfully" | "version:restoreThisVersion" | "version:reverting" | "version:revertToPublished" | "version:saveDraft" | "version:scheduledSuccessfully" | "version:schedulePublish" | "version:selectLocales" | "version:selectVersionToCompare" | "version:showLocales" | "version:specificVersion" | "version:status" | "version:unpublish" | "version:unpublishing" | "version:versionAgo" | "version:versionID" | "version:versions" | "version:viewingVersion" | "version:viewingVersionGlobal" | "version:viewingVersions" | "version:viewingVersionsGlobal" | "general:aboutToDeleteCount" | "general:editingLabel" | "version:changedFieldsCount")[];
23
23
 
24
24
  declare const enTranslations: {
25
25
  authentication: {
@@ -445,7 +445,9 @@ declare const enTranslations: {
445
445
  copyTo: string;
446
446
  copyToLocale: string;
447
447
  localeToPublish: string;
448
+ selectedLocales: string;
448
449
  selectLocaleToCopy: string;
450
+ selectLocaleToDuplicate: string;
449
451
  };
450
452
  operators: {
451
453
  contains: string;
@@ -7821,6 +7823,7 @@ type Arguments$j<TSlug extends CollectionSlug> = {
7821
7823
  publishSpecificLocale?: string;
7822
7824
  req: PayloadRequest;
7823
7825
  select?: SelectType;
7826
+ selectedLocales?: string[];
7824
7827
  showHiddenFields?: boolean;
7825
7828
  };
7826
7829
  declare const createOperation: <TSlug extends CollectionSlug, TSelect extends SelectFromCollectionSlug<TSlug>>(incomingArgs: Arguments$j<TSlug>) => Promise<TransformCollectionWithSelect<TSlug, TSelect>>;
@@ -9319,6 +9322,11 @@ type Options$b<TSlug extends CollectionSlug, TSelect extends SelectType> = {
9319
9322
  * Specify [select](https://payloadcms.com/docs/queries/select) to control which fields to include to the result.
9320
9323
  */
9321
9324
  select?: TSelect;
9325
+ /**
9326
+ * Specifies which locales to include when duplicating localized fields. Non-localized data is always duplicated.
9327
+ * By default, all locales are duplicated.
9328
+ */
9329
+ selectedLocales?: string[];
9322
9330
  /**
9323
9331
  * Opt-in to receiving hidden fields. By default, they are hidden from returned documents in accordance to your config.
9324
9332
  * @default false
@@ -0,0 +1,19 @@
1
+ import type { Field } from '../fields/config/types.js';
2
+ import type { SanitizedConfig } from '../index.js';
3
+ import type { JsonObject } from '../types/index.js';
4
+ type FilterDataToSelectedLocalesArgs = {
5
+ configBlockReferences: SanitizedConfig['blocks'];
6
+ docWithLocales: JsonObject;
7
+ fields: Field[];
8
+ parentIsLocalized?: boolean;
9
+ selectedLocales: string[];
10
+ };
11
+ /**
12
+ * Filters localized field data to only include specified locales.
13
+ * For non-localized fields, returns all data as-is.
14
+ * For localized fields, if selectedLocales is provided, returns only those locales.
15
+ * If selectedLocales is not provided and field is localized, returns all locales.
16
+ */
17
+ export declare function filterDataToSelectedLocales({ configBlockReferences, docWithLocales, fields, parentIsLocalized, selectedLocales, }: FilterDataToSelectedLocalesArgs): JsonObject;
18
+ export {};
19
+ //# sourceMappingURL=filterDataToSelectedLocales.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"filterDataToSelectedLocales.d.ts","sourceRoot":"","sources":["../../src/utilities/filterDataToSelectedLocales.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAS,KAAK,EAAkB,MAAM,2BAA2B,CAAA;AAC7E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAClD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAInD,KAAK,+BAA+B,GAAG;IACrC,qBAAqB,EAAE,eAAe,CAAC,QAAQ,CAAC,CAAA;IAChD,cAAc,EAAE,UAAU,CAAA;IAC1B,MAAM,EAAE,KAAK,EAAE,CAAA;IACf,iBAAiB,CAAC,EAAE,OAAO,CAAA;IAC3B,eAAe,EAAE,MAAM,EAAE,CAAA;CAC1B,CAAA;AAED;;;;;GAKG;AACH,wBAAgB,2BAA2B,CAAC,EAC1C,qBAAqB,EACrB,cAAc,EACd,MAAM,EACN,iBAAyB,EACzB,eAAe,GAChB,EAAE,+BAA+B,GAAG,UAAU,CAsK9C"}
@@ -0,0 +1,167 @@
1
+ import { fieldAffectsData, fieldShouldBeLocalized, tabHasName } from '../fields/config/types.js';
2
+ /**
3
+ * Filters localized field data to only include specified locales.
4
+ * For non-localized fields, returns all data as-is.
5
+ * For localized fields, if selectedLocales is provided, returns only those locales.
6
+ * If selectedLocales is not provided and field is localized, returns all locales.
7
+ */ export function filterDataToSelectedLocales({ configBlockReferences, docWithLocales, fields, parentIsLocalized = false, selectedLocales }) {
8
+ if (!docWithLocales || typeof docWithLocales !== 'object') {
9
+ return docWithLocales;
10
+ }
11
+ const result = {};
12
+ for (const field of fields){
13
+ if (fieldAffectsData(field)) {
14
+ const fieldIsLocalized = fieldShouldBeLocalized({
15
+ field,
16
+ parentIsLocalized
17
+ });
18
+ switch(field.type){
19
+ case 'array':
20
+ {
21
+ if (Array.isArray(docWithLocales[field.name])) {
22
+ result[field.name] = docWithLocales[field.name].map((item)=>filterDataToSelectedLocales({
23
+ configBlockReferences,
24
+ docWithLocales: item,
25
+ fields: field.fields,
26
+ parentIsLocalized: fieldIsLocalized,
27
+ selectedLocales
28
+ }));
29
+ }
30
+ break;
31
+ }
32
+ case 'blocks':
33
+ {
34
+ if (field.name in docWithLocales && Array.isArray(docWithLocales[field.name])) {
35
+ result[field.name] = docWithLocales[field.name].map((blockData)=>{
36
+ let block;
37
+ if (configBlockReferences && field.blockReferences) {
38
+ for (const blockOrReference of field.blockReferences){
39
+ if (typeof blockOrReference === 'string') {
40
+ block = configBlockReferences.find((b)=>b.slug === blockData.blockType);
41
+ } else {
42
+ block = blockOrReference;
43
+ }
44
+ }
45
+ } else if (field.blocks) {
46
+ block = field.blocks.find((b)=>b.slug === blockData.blockType);
47
+ }
48
+ if (block) {
49
+ return filterDataToSelectedLocales({
50
+ configBlockReferences,
51
+ docWithLocales: blockData,
52
+ fields: block?.fields || [],
53
+ parentIsLocalized: fieldIsLocalized,
54
+ selectedLocales
55
+ });
56
+ }
57
+ return blockData;
58
+ });
59
+ }
60
+ break;
61
+ }
62
+ case 'group':
63
+ {
64
+ // Named groups create a nested data structure
65
+ if (fieldAffectsData(field) && field.name in docWithLocales && typeof docWithLocales[field.name] === 'object') {
66
+ result[field.name] = filterDataToSelectedLocales({
67
+ configBlockReferences,
68
+ docWithLocales: docWithLocales[field.name],
69
+ fields: field.fields,
70
+ parentIsLocalized: fieldIsLocalized,
71
+ selectedLocales
72
+ });
73
+ } else {
74
+ // Unnamed groups pass through the same data level
75
+ const nestedResult = filterDataToSelectedLocales({
76
+ configBlockReferences,
77
+ docWithLocales,
78
+ fields: field.fields,
79
+ parentIsLocalized,
80
+ selectedLocales
81
+ });
82
+ Object.assign(result, nestedResult);
83
+ }
84
+ break;
85
+ }
86
+ default:
87
+ {
88
+ // For all other data-affecting fields (text, number, select, etc.)
89
+ if (field.name in docWithLocales) {
90
+ const value = docWithLocales[field.name];
91
+ // If the field is localized and has locale data
92
+ if (fieldIsLocalized && value && typeof value === 'object' && !Array.isArray(value)) {
93
+ // If selectedLocales is provided, filter to only those locales
94
+ if (selectedLocales && selectedLocales.length > 0) {
95
+ const filtered = {};
96
+ for (const locale of selectedLocales){
97
+ if (locale in value) {
98
+ filtered[locale] = value[locale];
99
+ }
100
+ }
101
+ if (Object.keys(filtered).length > 0) {
102
+ result[field.name] = filtered;
103
+ }
104
+ } else {
105
+ // If no selectedLocales, include all locales
106
+ result[field.name] = value;
107
+ }
108
+ } else {
109
+ // Non-localized field or non-object value
110
+ result[field.name] = value;
111
+ }
112
+ }
113
+ break;
114
+ }
115
+ }
116
+ } else {
117
+ // Layout-only fields that don't affect data structure
118
+ switch(field.type){
119
+ case 'collapsible':
120
+ case 'row':
121
+ {
122
+ // These pass through the same data level
123
+ const nestedResult = filterDataToSelectedLocales({
124
+ configBlockReferences,
125
+ docWithLocales,
126
+ fields: field.fields,
127
+ parentIsLocalized,
128
+ selectedLocales
129
+ });
130
+ Object.assign(result, nestedResult);
131
+ break;
132
+ }
133
+ case 'tabs':
134
+ {
135
+ for (const tab of field.tabs){
136
+ if (tabHasName(tab)) {
137
+ // Named tabs create a nested data structure
138
+ if (tab.name in docWithLocales && typeof docWithLocales[tab.name] === 'object') {
139
+ result[tab.name] = filterDataToSelectedLocales({
140
+ configBlockReferences,
141
+ docWithLocales: docWithLocales[tab.name],
142
+ fields: tab.fields,
143
+ parentIsLocalized,
144
+ selectedLocales
145
+ });
146
+ }
147
+ } else {
148
+ // Unnamed tabs pass through the same data level
149
+ const nestedResult = filterDataToSelectedLocales({
150
+ configBlockReferences,
151
+ docWithLocales,
152
+ fields: tab.fields,
153
+ parentIsLocalized,
154
+ selectedLocales
155
+ });
156
+ Object.assign(result, nestedResult);
157
+ }
158
+ }
159
+ break;
160
+ }
161
+ }
162
+ }
163
+ }
164
+ return result;
165
+ }
166
+
167
+ //# sourceMappingURL=filterDataToSelectedLocales.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utilities/filterDataToSelectedLocales.ts"],"sourcesContent":["import type { Block, Field, FlattenedBlock } from '../fields/config/types.js'\nimport type { SanitizedConfig } from '../index.js'\nimport type { JsonObject } from '../types/index.js'\n\nimport { fieldAffectsData, fieldShouldBeLocalized, tabHasName } from '../fields/config/types.js'\n\ntype FilterDataToSelectedLocalesArgs = {\n configBlockReferences: SanitizedConfig['blocks']\n docWithLocales: JsonObject\n fields: Field[]\n parentIsLocalized?: boolean\n selectedLocales: string[]\n}\n\n/**\n * Filters localized field data to only include specified locales.\n * For non-localized fields, returns all data as-is.\n * For localized fields, if selectedLocales is provided, returns only those locales.\n * If selectedLocales is not provided and field is localized, returns all locales.\n */\nexport function filterDataToSelectedLocales({\n configBlockReferences,\n docWithLocales,\n fields,\n parentIsLocalized = false,\n selectedLocales,\n}: FilterDataToSelectedLocalesArgs): JsonObject {\n if (!docWithLocales || typeof docWithLocales !== 'object') {\n return docWithLocales\n }\n\n const result: JsonObject = {}\n\n for (const field of fields) {\n if (fieldAffectsData(field)) {\n const fieldIsLocalized = fieldShouldBeLocalized({ field, parentIsLocalized })\n\n switch (field.type) {\n case 'array': {\n if (Array.isArray(docWithLocales[field.name])) {\n result[field.name] = docWithLocales[field.name].map((item: JsonObject) =>\n filterDataToSelectedLocales({\n configBlockReferences,\n docWithLocales: item,\n fields: field.fields,\n parentIsLocalized: fieldIsLocalized,\n selectedLocales,\n }),\n )\n }\n break\n }\n\n case 'blocks': {\n if (field.name in docWithLocales && Array.isArray(docWithLocales[field.name])) {\n result[field.name] = docWithLocales[field.name].map((blockData: JsonObject) => {\n let block: Block | FlattenedBlock | undefined\n if (configBlockReferences && field.blockReferences) {\n for (const blockOrReference of field.blockReferences) {\n if (typeof blockOrReference === 'string') {\n block = configBlockReferences.find((b) => b.slug === blockData.blockType)\n } else {\n block = blockOrReference\n }\n }\n } else if (field.blocks) {\n block = field.blocks.find((b) => b.slug === blockData.blockType)\n }\n\n if (block) {\n return filterDataToSelectedLocales({\n configBlockReferences,\n docWithLocales: blockData,\n fields: block?.fields || [],\n parentIsLocalized: fieldIsLocalized,\n selectedLocales,\n })\n }\n\n return blockData\n })\n }\n break\n }\n\n case 'group': {\n // Named groups create a nested data structure\n if (\n fieldAffectsData(field) &&\n field.name in docWithLocales &&\n typeof docWithLocales[field.name] === 'object'\n ) {\n result[field.name] = filterDataToSelectedLocales({\n configBlockReferences,\n docWithLocales: docWithLocales[field.name] as JsonObject,\n fields: field.fields,\n parentIsLocalized: fieldIsLocalized,\n selectedLocales,\n })\n } else {\n // Unnamed groups pass through the same data level\n const nestedResult = filterDataToSelectedLocales({\n configBlockReferences,\n docWithLocales,\n fields: field.fields,\n parentIsLocalized,\n selectedLocales,\n })\n Object.assign(result, nestedResult)\n }\n break\n }\n\n default: {\n // For all other data-affecting fields (text, number, select, etc.)\n if (field.name in docWithLocales) {\n const value = docWithLocales[field.name]\n\n // If the field is localized and has locale data\n if (fieldIsLocalized && value && typeof value === 'object' && !Array.isArray(value)) {\n // If selectedLocales is provided, filter to only those locales\n if (selectedLocales && selectedLocales.length > 0) {\n const filtered: Record<string, unknown> = {}\n for (const locale of selectedLocales) {\n if (locale in value) {\n filtered[locale] = value[locale]\n }\n }\n if (Object.keys(filtered).length > 0) {\n result[field.name] = filtered\n }\n } else {\n // If no selectedLocales, include all locales\n result[field.name] = value\n }\n } else {\n // Non-localized field or non-object value\n result[field.name] = value\n }\n }\n break\n }\n }\n } else {\n // Layout-only fields that don't affect data structure\n switch (field.type) {\n case 'collapsible':\n case 'row': {\n // These pass through the same data level\n const nestedResult = filterDataToSelectedLocales({\n configBlockReferences,\n docWithLocales,\n fields: field.fields,\n parentIsLocalized,\n selectedLocales,\n })\n Object.assign(result, nestedResult)\n break\n }\n\n case 'tabs': {\n for (const tab of field.tabs) {\n if (tabHasName(tab)) {\n // Named tabs create a nested data structure\n if (tab.name in docWithLocales && typeof docWithLocales[tab.name] === 'object') {\n result[tab.name] = filterDataToSelectedLocales({\n configBlockReferences,\n docWithLocales: docWithLocales[tab.name],\n fields: tab.fields,\n parentIsLocalized,\n selectedLocales,\n })\n }\n } else {\n // Unnamed tabs pass through the same data level\n const nestedResult = filterDataToSelectedLocales({\n configBlockReferences,\n docWithLocales,\n fields: tab.fields,\n parentIsLocalized,\n selectedLocales,\n })\n Object.assign(result, nestedResult)\n }\n }\n break\n }\n }\n }\n }\n\n return result\n}\n"],"names":["fieldAffectsData","fieldShouldBeLocalized","tabHasName","filterDataToSelectedLocales","configBlockReferences","docWithLocales","fields","parentIsLocalized","selectedLocales","result","field","fieldIsLocalized","type","Array","isArray","name","map","item","blockData","block","blockReferences","blockOrReference","find","b","slug","blockType","blocks","nestedResult","Object","assign","value","length","filtered","locale","keys","tab","tabs"],"mappings":"AAIA,SAASA,gBAAgB,EAAEC,sBAAsB,EAAEC,UAAU,QAAQ,4BAA2B;AAUhG;;;;;CAKC,GACD,OAAO,SAASC,4BAA4B,EAC1CC,qBAAqB,EACrBC,cAAc,EACdC,MAAM,EACNC,oBAAoB,KAAK,EACzBC,eAAe,EACiB;IAChC,IAAI,CAACH,kBAAkB,OAAOA,mBAAmB,UAAU;QACzD,OAAOA;IACT;IAEA,MAAMI,SAAqB,CAAC;IAE5B,KAAK,MAAMC,SAASJ,OAAQ;QAC1B,IAAIN,iBAAiBU,QAAQ;YAC3B,MAAMC,mBAAmBV,uBAAuB;gBAAES;gBAAOH;YAAkB;YAE3E,OAAQG,MAAME,IAAI;gBAChB,KAAK;oBAAS;wBACZ,IAAIC,MAAMC,OAAO,CAACT,cAAc,CAACK,MAAMK,IAAI,CAAC,GAAG;4BAC7CN,MAAM,CAACC,MAAMK,IAAI,CAAC,GAAGV,cAAc,CAACK,MAAMK,IAAI,CAAC,CAACC,GAAG,CAAC,CAACC,OACnDd,4BAA4B;oCAC1BC;oCACAC,gBAAgBY;oCAChBX,QAAQI,MAAMJ,MAAM;oCACpBC,mBAAmBI;oCACnBH;gCACF;wBAEJ;wBACA;oBACF;gBAEA,KAAK;oBAAU;wBACb,IAAIE,MAAMK,IAAI,IAAIV,kBAAkBQ,MAAMC,OAAO,CAACT,cAAc,CAACK,MAAMK,IAAI,CAAC,GAAG;4BAC7EN,MAAM,CAACC,MAAMK,IAAI,CAAC,GAAGV,cAAc,CAACK,MAAMK,IAAI,CAA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AAI,CAAC;wCACxCT,QAAQ6B,IAAI7B,MAAM;wCAClBC;wCACAC;oCACF;gCACF;4BACF,OAAO;gCACL,gDAAgD;gCAChD,MAAMmB,eAAexB,4BAA4B;oCAC/CC;oCACAC;oCACAC,QAAQ6B,IAAI7B,MAAM;oCAClBC;oCACAC;gCACF;gCACAoB,OAAOC,MAAM,CAACpB,QAAQkB;4BACxB;wBACF;wBACA;oBACF;YACF;QACF;IACF;IAEA,OAAOlB;AACT"}
@@ -1 +1 @@
1
- {"version":3,"file":"payloadPackageList.d.ts","sourceRoot":"","sources":["../../src/versions/payloadPackageList.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,oBAAoB,UAyChC,CAAA"}
1
+ {"version":3,"file":"payloadPackageList.d.ts","sourceRoot":"","sources":["../../src/versions/payloadPackageList.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,oBAAoB,UA0ChC,CAAA"}
@@ -15,6 +15,7 @@ export const PAYLOAD_PACKAGE_LIST = [
15
15
  '@payloadcms/live-preview',
16
16
  '@payloadcms/live-preview-react',
17
17
  '@payloadcms/live-preview-vue',
18
+ '@payloadcms/kv-redis',
18
19
  '@payloadcms/next/utilities',
19
20
  '@payloadcms/payload-cloud',
20
21
  '@payloadcms/plugin-cloud-storage',
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/versions/payloadPackageList.ts"],"sourcesContent":["export const PAYLOAD_PACKAGE_LIST = [\n 'payload',\n '@payloadcms/bundler-vite',\n '@payloadcms/bundler-webpack',\n '@payloadcms/db-d1-sqlite',\n '@payloadcms/db-mongodb',\n '@payloadcms/db-postgres',\n '@payloadcms/db-sqlite',\n '@payloadcms/db-vercel-postgres',\n '@payloadcms/drizzle',\n '@payloadcms/ecommerce',\n '@payloadcms/email-nodemailer',\n '@payloadcms/email-resend',\n '@payloadcms/graphql',\n '@payloadcms/live-preview',\n '@payloadcms/live-preview-react',\n '@payloadcms/live-preview-vue',\n '@payloadcms/next/utilities',\n '@payloadcms/payload-cloud',\n '@payloadcms/plugin-cloud-storage',\n '@payloadcms/plugin-form-builder',\n '@payloadcms/plugin-import-export',\n '@payloadcms/plugin-mcp',\n '@payloadcms/plugin-multi-tenant',\n '@payloadcms/plugin-nested-docs',\n '@payloadcms/plugin-redirects',\n '@payloadcms/plugin-search',\n '@payloadcms/plugin-seo',\n '@payloadcms/plugin-stripe',\n '@payloadcms/plugin-zapier',\n '@payloadcms/richtext-lexical',\n '@payloadcms/richtext-slate',\n '@payloadcms/sdk',\n '@payloadcms/storage-azure',\n '@payloadcms/storage-gcs',\n '@payloadcms/storage-r2',\n '@payloadcms/storage-s3',\n '@payloadcms/storage-uploadthing',\n '@payloadcms/storage-vercel-blob',\n '@payloadcms/translations',\n '@payloadcms/ui/shared',\n]\n"],"names":["PAYLOAD_PACKAGE_LIST"],"mappings":"AAAA,OAAO,MAAMA,uBAAuB;IAClC;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CACD,CAAA"}
1
+ {"version":3,"sources":["../../src/versions/payloadPackageList.ts"],"sourcesContent":["export const PAYLOAD_PACKAGE_LIST = [\n 'payload',\n '@payloadcms/bundler-vite',\n '@payloadcms/bundler-webpack',\n '@payloadcms/db-d1-sqlite',\n '@payloadcms/db-mongodb',\n '@payloadcms/db-postgres',\n '@payloadcms/db-sqlite',\n '@payloadcms/db-vercel-postgres',\n '@payloadcms/drizzle',\n '@payloadcms/ecommerce',\n '@payloadcms/email-nodemailer',\n '@payloadcms/email-resend',\n '@payloadcms/graphql',\n '@payloadcms/live-preview',\n '@payloadcms/live-preview-react',\n '@payloadcms/live-preview-vue',\n '@payloadcms/kv-redis',\n '@payloadcms/next/utilities',\n '@payloadcms/payload-cloud',\n '@payloadcms/plugin-cloud-storage',\n '@payloadcms/plugin-form-builder',\n '@payloadcms/plugin-import-export',\n '@payloadcms/plugin-mcp',\n '@payloadcms/plugin-multi-tenant',\n '@payloadcms/plugin-nested-docs',\n '@payloadcms/plugin-redirects',\n '@payloadcms/plugin-search',\n '@payloadcms/plugin-seo',\n '@payloadcms/plugin-stripe',\n '@payloadcms/plugin-zapier',\n '@payloadcms/richtext-lexical',\n '@payloadcms/richtext-slate',\n '@payloadcms/sdk',\n '@payloadcms/storage-azure',\n '@payloadcms/storage-gcs',\n '@payloadcms/storage-r2',\n '@payloadcms/storage-s3',\n '@payloadcms/storage-uploadthing',\n '@payloadcms/storage-vercel-blob',\n '@payloadcms/translations',\n '@payloadcms/ui/shared',\n]\n"],"names":["PAYLOAD_PACKAGE_LIST"],"mappings":"AAAA,OAAO,MAAMA,uBAAuB;IAClC;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CACD,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "payload",
3
- "version": "3.62.0",
3
+ "version": "3.63.0-internal.dc01f92",
4
4
  "description": "Node, React, Headless CMS and Application Framework built on Next.js",
5
5
  "keywords": [
6
6
  "admin panel",
@@ -101,7 +101,7 @@
101
101
  "undici": "7.10.0",
102
102
  "uuid": "10.0.0",
103
103
  "ws": "^8.16.0",
104
- "@payloadcms/translations": "3.62.0"
104
+ "@payloadcms/translations": "3.63.0-internal.dc01f92"
105
105
  },
106
106
  "devDependencies": {
107
107
  "@hyrious/esbuild-plugin-commonjs": "0.2.6",