payload 3.0.0-beta.125 → 3.0.0-beta.127
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/admin/RichText.d.ts +3 -1
- package/dist/admin/RichText.d.ts.map +1 -1
- package/dist/admin/RichText.js.map +1 -1
- package/dist/bin/index.js +1 -1
- package/dist/bin/index.js.map +1 -1
- package/dist/collections/operations/create.d.ts +2 -1
- package/dist/collections/operations/create.d.ts.map +1 -1
- package/dist/collections/operations/create.js +2 -10
- package/dist/collections/operations/create.js.map +1 -1
- package/dist/collections/operations/delete.d.ts +2 -1
- package/dist/collections/operations/delete.d.ts.map +1 -1
- package/dist/collections/operations/delete.js +2 -1
- package/dist/collections/operations/delete.js.map +1 -1
- package/dist/collections/operations/deleteByID.d.ts +2 -1
- package/dist/collections/operations/deleteByID.d.ts.map +1 -1
- package/dist/collections/operations/deleteByID.js +2 -1
- package/dist/collections/operations/deleteByID.js.map +1 -1
- package/dist/collections/operations/duplicate.d.ts +2 -1
- package/dist/collections/operations/duplicate.d.ts.map +1 -1
- package/dist/collections/operations/duplicate.js +2 -1
- package/dist/collections/operations/duplicate.js.map +1 -1
- package/dist/collections/operations/find.d.ts +2 -1
- package/dist/collections/operations/find.d.ts.map +1 -1
- package/dist/collections/operations/find.js +2 -1
- package/dist/collections/operations/find.js.map +1 -1
- package/dist/collections/operations/findByID.d.ts +2 -1
- package/dist/collections/operations/findByID.d.ts.map +1 -1
- package/dist/collections/operations/findByID.js +2 -1
- package/dist/collections/operations/findByID.js.map +1 -1
- package/dist/collections/operations/findVersionByID.d.ts +2 -1
- package/dist/collections/operations/findVersionByID.d.ts.map +1 -1
- package/dist/collections/operations/findVersionByID.js +2 -1
- package/dist/collections/operations/findVersionByID.js.map +1 -1
- package/dist/collections/operations/findVersions.d.ts +2 -1
- package/dist/collections/operations/findVersions.d.ts.map +1 -1
- package/dist/collections/operations/findVersions.js +2 -1
- package/dist/collections/operations/findVersions.js.map +1 -1
- package/dist/collections/operations/local/create.d.ts +2 -1
- package/dist/collections/operations/local/create.d.ts.map +1 -1
- package/dist/collections/operations/local/create.js +2 -1
- package/dist/collections/operations/local/create.js.map +1 -1
- package/dist/collections/operations/local/delete.d.ts +2 -1
- package/dist/collections/operations/local/delete.d.ts.map +1 -1
- package/dist/collections/operations/local/delete.js +2 -1
- package/dist/collections/operations/local/delete.js.map +1 -1
- package/dist/collections/operations/local/duplicate.d.ts +2 -1
- package/dist/collections/operations/local/duplicate.d.ts.map +1 -1
- package/dist/collections/operations/local/duplicate.js +2 -1
- package/dist/collections/operations/local/duplicate.js.map +1 -1
- package/dist/collections/operations/local/find.d.ts +3 -2
- package/dist/collections/operations/local/find.d.ts.map +1 -1
- package/dist/collections/operations/local/find.js +2 -2
- package/dist/collections/operations/local/find.js.map +1 -1
- package/dist/collections/operations/local/findByID.d.ts +3 -2
- package/dist/collections/operations/local/findByID.d.ts.map +1 -1
- package/dist/collections/operations/local/findByID.js +2 -1
- package/dist/collections/operations/local/findByID.js.map +1 -1
- package/dist/collections/operations/local/findVersionByID.d.ts +2 -1
- package/dist/collections/operations/local/findVersionByID.d.ts.map +1 -1
- package/dist/collections/operations/local/findVersionByID.js +2 -1
- package/dist/collections/operations/local/findVersionByID.js.map +1 -1
- package/dist/collections/operations/local/findVersions.d.ts +2 -1
- package/dist/collections/operations/local/findVersions.d.ts.map +1 -1
- package/dist/collections/operations/local/findVersions.js +2 -1
- package/dist/collections/operations/local/findVersions.js.map +1 -1
- package/dist/collections/operations/local/restoreVersion.d.ts +2 -1
- package/dist/collections/operations/local/restoreVersion.d.ts.map +1 -1
- package/dist/collections/operations/local/restoreVersion.js +2 -1
- package/dist/collections/operations/local/restoreVersion.js.map +1 -1
- package/dist/collections/operations/local/update.d.ts +2 -1
- package/dist/collections/operations/local/update.d.ts.map +1 -1
- package/dist/collections/operations/local/update.js +2 -1
- package/dist/collections/operations/local/update.js.map +1 -1
- package/dist/collections/operations/restoreVersion.d.ts +2 -1
- package/dist/collections/operations/restoreVersion.d.ts.map +1 -1
- package/dist/collections/operations/restoreVersion.js +2 -1
- package/dist/collections/operations/restoreVersion.js.map +1 -1
- package/dist/collections/operations/update.d.ts +2 -1
- package/dist/collections/operations/update.d.ts.map +1 -1
- package/dist/collections/operations/update.js +2 -1
- package/dist/collections/operations/update.js.map +1 -1
- package/dist/collections/operations/updateByID.d.ts +2 -1
- package/dist/collections/operations/updateByID.d.ts.map +1 -1
- package/dist/collections/operations/updateByID.js +8 -6
- package/dist/collections/operations/updateByID.js.map +1 -1
- package/dist/database/migrations/migrateRefresh.d.ts.map +1 -1
- package/dist/database/migrations/migrateRefresh.js +47 -47
- package/dist/database/migrations/migrateRefresh.js.map +1 -1
- package/dist/database/sanitizeJoinQuery.d.ts +3 -3
- package/dist/database/sanitizeJoinQuery.d.ts.map +1 -1
- package/dist/fields/hooks/afterRead/index.d.ts +2 -1
- package/dist/fields/hooks/afterRead/index.d.ts.map +1 -1
- package/dist/fields/hooks/afterRead/index.js +2 -1
- package/dist/fields/hooks/afterRead/index.js.map +1 -1
- package/dist/fields/hooks/afterRead/promise.d.ts +3 -2
- package/dist/fields/hooks/afterRead/promise.d.ts.map +1 -1
- package/dist/fields/hooks/afterRead/promise.js +12 -1
- package/dist/fields/hooks/afterRead/promise.js.map +1 -1
- package/dist/fields/hooks/afterRead/relationshipPopulationPromise.d.ts +3 -2
- package/dist/fields/hooks/afterRead/relationshipPopulationPromise.d.ts.map +1 -1
- package/dist/fields/hooks/afterRead/relationshipPopulationPromise.js +7 -3
- package/dist/fields/hooks/afterRead/relationshipPopulationPromise.js.map +1 -1
- package/dist/fields/hooks/afterRead/traverseFields.d.ts +3 -2
- package/dist/fields/hooks/afterRead/traverseFields.d.ts.map +1 -1
- package/dist/fields/hooks/afterRead/traverseFields.js +2 -1
- package/dist/fields/hooks/afterRead/traverseFields.js.map +1 -1
- package/dist/globals/operations/findOne.d.ts +2 -1
- package/dist/globals/operations/findOne.d.ts.map +1 -1
- package/dist/globals/operations/findOne.js +2 -1
- package/dist/globals/operations/findOne.js.map +1 -1
- package/dist/globals/operations/findVersionByID.d.ts +2 -1
- package/dist/globals/operations/findVersionByID.d.ts.map +1 -1
- package/dist/globals/operations/findVersionByID.js +2 -1
- package/dist/globals/operations/findVersionByID.js.map +1 -1
- package/dist/globals/operations/findVersions.d.ts +2 -1
- package/dist/globals/operations/findVersions.d.ts.map +1 -1
- package/dist/globals/operations/findVersions.js +2 -1
- package/dist/globals/operations/findVersions.js.map +1 -1
- package/dist/globals/operations/local/findOne.d.ts +2 -1
- package/dist/globals/operations/local/findOne.d.ts.map +1 -1
- package/dist/globals/operations/local/findOne.js +2 -1
- package/dist/globals/operations/local/findOne.js.map +1 -1
- package/dist/globals/operations/local/findVersionByID.d.ts +2 -1
- package/dist/globals/operations/local/findVersionByID.d.ts.map +1 -1
- package/dist/globals/operations/local/findVersionByID.js +2 -1
- package/dist/globals/operations/local/findVersionByID.js.map +1 -1
- package/dist/globals/operations/local/findVersions.d.ts +2 -1
- package/dist/globals/operations/local/findVersions.d.ts.map +1 -1
- package/dist/globals/operations/local/findVersions.js +2 -1
- package/dist/globals/operations/local/findVersions.js.map +1 -1
- package/dist/globals/operations/local/restoreVersion.d.ts +2 -1
- package/dist/globals/operations/local/restoreVersion.d.ts.map +1 -1
- package/dist/globals/operations/local/restoreVersion.js +2 -1
- package/dist/globals/operations/local/restoreVersion.js.map +1 -1
- package/dist/globals/operations/local/update.d.ts +2 -1
- package/dist/globals/operations/local/update.d.ts.map +1 -1
- package/dist/globals/operations/local/update.js +2 -1
- package/dist/globals/operations/local/update.js.map +1 -1
- package/dist/globals/operations/restoreVersion.d.ts +2 -1
- package/dist/globals/operations/restoreVersion.d.ts.map +1 -1
- package/dist/globals/operations/restoreVersion.js +2 -1
- package/dist/globals/operations/restoreVersion.js.map +1 -1
- package/dist/globals/operations/update.d.ts +2 -1
- package/dist/globals/operations/update.d.ts.map +1 -1
- package/dist/globals/operations/update.js +2 -1
- package/dist/globals/operations/update.js.map +1 -1
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/queues/config/jobsCollection.d.ts.map +1 -1
- package/dist/queues/config/jobsCollection.js +15 -13
- package/dist/queues/config/jobsCollection.js.map +1 -1
- package/dist/queues/config/types/index.d.ts +1 -1
- package/dist/queues/config/types/index.d.ts.map +1 -1
- package/dist/queues/config/types/index.js.map +1 -1
- package/dist/queues/operations/runJobs/index.js +1 -1
- package/dist/queues/operations/runJobs/index.js.map +1 -1
- package/dist/types/index.d.ts +5 -4
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js.map +1 -1
- package/dist/utilities/configToJSONSchema.d.ts.map +1 -1
- package/dist/utilities/configToJSONSchema.js +35 -0
- package/dist/utilities/configToJSONSchema.js.map +1 -1
- package/package.json +10 -10
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/collections/operations/updateByID.ts"],"sourcesContent":["import type { DeepPartial } from 'ts-essentials'\n\nimport httpStatus from 'http-status'\n\nimport type { FindOneArgs } from '../../database/types.js'\nimport type { Args } from '../../fields/hooks/beforeChange/index.js'\nimport type { CollectionSlug } from '../../index.js'\nimport type {\n PayloadRequest,\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 { generatePasswordSaltHash } from '../../auth/strategies/local/generatePasswordSaltHash.js'\nimport { hasWhereAccessResult } from '../../auth/types.js'\nimport { combineQueries } from '../../database/combineQueries.js'\nimport { APIError, Forbidden, NotFound } from '../../errors/index.js'\nimport { afterChange } from '../../fields/hooks/afterChange/index.js'\nimport { afterRead } from '../../fields/hooks/afterRead/index.js'\nimport { beforeChange } from '../../fields/hooks/beforeChange/index.js'\nimport { beforeValidate } from '../../fields/hooks/beforeValidate/index.js'\nimport { deleteAssociatedFiles } from '../../uploads/deleteAssociatedFiles.js'\nimport { generateFileData } from '../../uploads/generateFileData.js'\nimport { unlinkTempFiles } from '../../uploads/unlinkTempFiles.js'\nimport { uploadFiles } from '../../uploads/uploadFiles.js'\nimport { checkDocumentLockStatus } from '../../utilities/checkDocumentLockStatus.js'\nimport { commitTransaction } from '../../utilities/commitTransaction.js'\nimport { initTransaction } from '../../utilities/initTransaction.js'\nimport { killTransaction } from '../../utilities/killTransaction.js'\nimport { getLatestCollectionVersion } from '../../versions/getLatestCollectionVersion.js'\nimport { saveVersion } from '../../versions/saveVersion.js'\nimport { buildAfterOperation } from './utils.js'\n\nexport type Arguments<TSlug extends CollectionSlug> = {\n autosave?: boolean\n collection: Collection\n data: DeepPartial<RequiredDataFromCollectionSlug<TSlug>>\n depth?: number\n disableTransaction?: boolean\n disableVerificationEmail?: boolean\n draft?: boolean\n id: number | string\n overrideAccess?: boolean\n overrideLock?: boolean\n overwriteExistingFiles?: boolean\n publishSpecificLocale?: string\n req: PayloadRequest\n select?: SelectType\n showHiddenFields?: boolean\n}\n\nexport const updateByIDOperation = async <\n TSlug extends CollectionSlug,\n TSelect extends SelectFromCollectionSlug<TSlug> = SelectType,\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 // /////////////////////////////////////\n // beforeOperation - Collection\n // /////////////////////////////////////\n\n await args.collection.config.hooks.beforeOperation.reduce(async (priorHook, hook) => {\n await priorHook\n\n args =\n (await hook({\n args,\n collection: args.collection.config,\n context: args.req.context,\n operation: 'update',\n req: args.req,\n })) || args\n }, Promise.resolve())\n\n if (args.publishSpecificLocale) {\n args.req.locale = args.publishSpecificLocale\n }\n\n const {\n id,\n autosave = false,\n collection: { config: collectionConfig },\n collection,\n depth,\n draft: draftArg = false,\n overrideAccess,\n overrideLock,\n overwriteExistingFiles = false,\n publishSpecificLocale,\n req: {\n fallbackLocale,\n locale,\n payload: { config },\n payload,\n },\n req,\n select,\n showHiddenFields,\n } = args\n\n if (!id) {\n throw new APIError('Missing ID of document to update.', httpStatus.BAD_REQUEST)\n }\n\n let { data } = args\n const password = data?.password\n const shouldSaveDraft = Boolean(draftArg && collectionConfig.versions.drafts)\n const shouldSavePassword = Boolean(password && collectionConfig.auth && !shouldSaveDraft)\n\n // /////////////////////////////////////\n // Access\n // /////////////////////////////////////\n\n const accessResults = !overrideAccess\n ? await executeAccess({ id, data, req }, collectionConfig.access.update)\n : true\n const hasWherePolicy = hasWhereAccessResult(accessResults)\n\n // /////////////////////////////////////\n // Retrieve document\n // /////////////////////////////////////\n\n const findOneArgs: FindOneArgs = {\n collection: collectionConfig.slug,\n locale,\n req,\n where: combineQueries({ id: { equals: id } }, accessResults),\n }\n\n const docWithLocales = await getLatestCollectionVersion({\n id,\n config: collectionConfig,\n payload,\n query: findOneArgs,\n req,\n })\n\n if (!docWithLocales && !hasWherePolicy) {\n throw new NotFound(req.t)\n }\n if (!docWithLocales && hasWherePolicy) {\n throw new Forbidden(req.t)\n }\n\n // /////////////////////////////////////\n // Handle potentially locked documents\n // /////////////////////////////////////\n\n await checkDocumentLockStatus({\n id,\n collectionSlug: collectionConfig.slug,\n lockErrorMessage: `Document with ID ${id} is currently locked by another user and cannot be updated.`,\n overrideLock,\n req,\n })\n\n const originalDoc = await afterRead({\n collection: collectionConfig,\n context: req.context,\n depth: 0,\n doc: docWithLocales,\n draft: draftArg,\n fallbackLocale: null,\n global: null,\n locale,\n overrideAccess: true,\n req,\n showHiddenFields: true,\n })\n\n if (args.collection.config.auth) {\n ensureUsernameOrEmail<TSlug>({\n authOptions: args.collection.config.auth,\n collectionSlug: args.collection.config.slug,\n data: args.data,\n operation: 'update',\n originalDoc,\n req: args.req,\n })\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 operation: 'update',\n overwriteExistingFiles,\n req,\n throwOnMissingFile: false,\n })\n\n data = newFileData\n\n // /////////////////////////////////////\n // Delete any associated files\n // /////////////////////////////////////\n\n await deleteAssociatedFiles({\n collectionConfig,\n config,\n doc: docWithLocales,\n files: filesToUpload,\n overrideDelete: false,\n req,\n })\n\n // /////////////////////////////////////\n // beforeValidate - Fields\n // /////////////////////////////////////\n\n data = await beforeValidate<DeepPartial<DataFromCollectionSlug<TSlug>>>({\n id,\n collection: collectionConfig,\n context: req.context,\n data,\n doc: originalDoc,\n global: null,\n operation: 'update',\n overrideAccess,\n req,\n })\n\n // /////////////////////////////////////\n // beforeValidate - Collection\n // /////////////////////////////////////\n\n await collectionConfig.hooks.beforeValidate.reduce(async (priorHook, hook) => {\n await priorHook\n\n data =\n (await hook({\n collection: collectionConfig,\n context: req.context,\n data,\n operation: 'update',\n originalDoc,\n req,\n })) || data\n }, Promise.resolve())\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 // beforeChange - Collection\n // /////////////////////////////////////\n\n await collectionConfig.hooks.beforeChange.reduce(async (priorHook, hook) => {\n await priorHook\n\n data =\n (await hook({\n collection: collectionConfig,\n context: req.context,\n data,\n operation: 'update',\n originalDoc,\n req,\n })) || data\n }, Promise.resolve())\n\n // /////////////////////////////////////\n // beforeChange - Fields\n // /////////////////////////////////////\n\n let publishedDocWithLocales = docWithLocales\n let versionSnapshotResult\n\n const beforeChangeArgs: Args<DataFromCollectionSlug<TSlug>> = {\n id,\n collection: collectionConfig,\n context: req.context,\n data: { ...data, id },\n doc: originalDoc,\n docWithLocales: undefined,\n global: null,\n operation: 'update',\n req,\n skipValidation:\n shouldSaveDraft &&\n collectionConfig.versions.drafts &&\n !collectionConfig.versions.drafts.validate &&\n data._status !== 'published',\n }\n\n if (publishSpecificLocale) {\n publishedDocWithLocales = await getLatestCollectionVersion({\n id,\n config: collectionConfig,\n payload,\n published: true,\n query: findOneArgs,\n req,\n })\n\n versionSnapshotResult = await beforeChange({\n ...beforeChangeArgs,\n docWithLocales,\n })\n }\n\n let result = await beforeChange({\n ...beforeChangeArgs,\n docWithLocales: publishedDocWithLocales,\n })\n\n // /////////////////////////////////////\n // Handle potential password update\n // /////////////////////////////////////\n\n const dataToUpdate: Record<string, unknown> = { ...result }\n\n if (shouldSavePassword && typeof password === 'string') {\n const { hash, salt } = await generatePasswordSaltHash({\n collection: collectionConfig,\n password,\n req,\n })\n dataToUpdate.salt = salt\n dataToUpdate.hash = hash\n delete dataToUpdate.password\n delete data.password\n }\n\n // /////////////////////////////////////\n // Update\n // /////////////////////////////////////\n\n if (!shouldSaveDraft || data._status === 'published') {\n result = await req.payload.db.updateOne({\n id,\n collection: collectionConfig.slug,\n data: dataToUpdate,\n locale,\n req,\n select,\n })\n }\n\n // /////////////////////////////////////\n // Create version\n // /////////////////////////////////////\n\n if (collectionConfig.versions) {\n result = await saveVersion({\n id,\n autosave,\n collection: collectionConfig,\n docWithLocales: result,\n draft: shouldSaveDraft,\n payload,\n publishSpecificLocale,\n req,\n select,\n snapshot: versionSnapshotResult,\n })\n }\n\n // /////////////////////////////////////\n // afterRead - Fields\n // /////////////////////////////////////\n\n result = await afterRead({\n collection: collectionConfig,\n context: req.context,\n depth,\n doc: result,\n draft: draftArg,\n fallbackLocale,\n global: null,\n locale,\n overrideAccess,\n req,\n select,\n showHiddenFields,\n })\n\n // /////////////////////////////////////\n // afterRead - Collection\n // /////////////////////////////////////\n\n await collectionConfig.hooks.afterRead.reduce(async (priorHook, hook) => {\n await priorHook\n\n result =\n (await hook({\n collection: collectionConfig,\n context: req.context,\n doc: result,\n req,\n })) || result\n }, Promise.resolve())\n\n // /////////////////////////////////////\n // afterChange - Fields\n // /////////////////////////////////////\n\n result = await afterChange({\n collection: collectionConfig,\n context: req.context,\n data,\n doc: result,\n global: null,\n operation: 'update',\n previousDoc: originalDoc,\n req,\n })\n\n // /////////////////////////////////////\n // afterChange - Collection\n // /////////////////////////////////////\n\n await collectionConfig.hooks.afterChange.reduce(async (priorHook, hook) => {\n await priorHook\n\n result =\n (await hook({\n collection: collectionConfig,\n context: req.context,\n doc: result,\n operation: 'update',\n previousDoc: originalDoc,\n req,\n })) || result\n }, Promise.resolve())\n\n // /////////////////////////////////////\n // afterOperation - Collection\n // /////////////////////////////////////\n\n result = await buildAfterOperation({\n args,\n collection: collectionConfig,\n operation: 'updateByID',\n result,\n })\n\n await unlinkTempFiles({\n collectionConfig,\n config,\n req,\n })\n\n // /////////////////////////////////////\n // Return results\n // /////////////////////////////////////\n\n if (shouldCommit) {\n await commitTransaction(req)\n }\n\n return result as TransformCollectionWithSelect<TSlug, TSelect>\n } catch (error: unknown) {\n await killTransaction(args.req)\n throw error\n }\n}\n"],"names":["httpStatus","ensureUsernameOrEmail","executeAccess","generatePasswordSaltHash","hasWhereAccessResult","combineQueries","APIError","Forbidden","NotFound","afterChange","afterRead","beforeChange","beforeValidate","deleteAssociatedFiles","generateFileData","unlinkTempFiles","uploadFiles","checkDocumentLockStatus","commitTransaction","initTransaction","killTransaction","getLatestCollectionVersion","saveVersion","buildAfterOperation","updateByIDOperation","incomingArgs","args","shouldCommit","disableTransaction","req","collection","config","hooks","beforeOperation","reduce","priorHook","hook","context","operation","Promise","resolve","publishSpecificLocale","locale","id","autosave","collectionConfig","depth","draft","draftArg","overrideAccess","overrideLock","overwriteExistingFiles","fallbackLocale","payload","select","showHiddenFields","BAD_REQUEST","data","password","shouldSaveDraft","Boolean","versions","drafts","shouldSavePassword","auth","accessResults","access","update","hasWherePolicy","findOneArgs","slug","where","equals","docWithLocales","query","t","collectionSlug","lockErrorMessage","originalDoc","doc","global","authOptions","newFileData","files","filesToUpload","throwOnMissingFile","overrideDelete","upload","disableLocalStorage","publishedDocWithLocales","versionSnapshotResult","beforeChangeArgs","undefined","skipValidation","validate","_status","published","result","dataToUpdate","hash","salt","db","updateOne","snapshot","previousDoc","error"],"mappings":"AAEA,OAAOA,gBAAgB,cAAa;AAiBpC,SAASC,qBAAqB,QAAQ,sCAAqC;AAC3E,OAAOC,mBAAmB,8BAA6B;AACvD,SAASC,wBAAwB,QAAQ,0DAAyD;AAClG,SAASC,oBAAoB,QAAQ,sBAAqB;AAC1D,SAASC,cAAc,QAAQ,mCAAkC;AACjE,SAASC,QAAQ,EAAEC,SAAS,EAAEC,QAAQ,QAAQ,wBAAuB;AACrE,SAASC,WAAW,QAAQ,0CAAyC;AACrE,SAASC,SAAS,QAAQ,wCAAuC;AACjE,SAASC,YAAY,QAAQ,2CAA0C;AACvE,SAASC,cAAc,QAAQ,6CAA4C;AAC3E,SAASC,qBAAqB,QAAQ,yCAAwC;AAC9E,SAASC,gBAAgB,QAAQ,oCAAmC;AACpE,SAASC,eAAe,QAAQ,mCAAkC;AAClE,SAASC,WAAW,QAAQ,+BAA8B;AAC1D,SAASC,uBAAuB,QAAQ,6CAA4C;AACpF,SAASC,iBAAiB,QAAQ,uCAAsC;AACxE,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,0BAA0B,QAAQ,+CAA8C;AACzF,SAASC,WAAW,QAAQ,gCAA+B;AAC3D,SAASC,mBAAmB,QAAQ,aAAY;AAoBhD,OAAO,MAAMC,sBAAsB,OAIjCC;IAEA,IAAIC,OAAOD;IAEX,IAAI;QACF,MAAME,eAAe,CAACD,KAAKE,kBAAkB,IAAK,MAAMT,gBAAgBO,KAAKG,GAAG;QAEhF,wCAAwC;QACxC,+BAA+B;QAC/B,wCAAwC;QAExC,MAAMH,KAAKI,UAAU,CAACC,MAAM,CAACC,KAAK,CAACC,eAAe,CAACC,MAAM,CAAC,OAAOC,WAAWC;YAC1E,MAAMD;YAENT,OACE,AAAC,MAAMU,KAAK;gBACVV;gBACAI,Y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,MAAMlF,gBAAgB;YACpB8B;YACAd;YACAF;QACF;QAEA,wCAAwC;QACxC,iBAAiB;QACjB,wCAAwC;QAExC,IAAIF,cAAc;YAChB,MAAMT,kBAAkBW;QAC1B;QAEA,OAAOoE;IACT,EAAE,OAAOQ,OAAgB;QACvB,MAAMrF,gBAAgBM,KAAKG,GAAG;QAC9B,MAAM4E;IACR;AACF,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../../src/collections/operations/updateByID.ts"],"sourcesContent":["import type { DeepPartial } from 'ts-essentials'\n\nimport httpStatus from 'http-status'\n\nimport type { FindOneArgs } from '../../database/types.js'\nimport type { Args } from '../../fields/hooks/beforeChange/index.js'\nimport type { CollectionSlug } from '../../index.js'\nimport type {\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 { generatePasswordSaltHash } from '../../auth/strategies/local/generatePasswordSaltHash.js'\nimport { hasWhereAccessResult } from '../../auth/types.js'\nimport { combineQueries } from '../../database/combineQueries.js'\nimport { APIError, Forbidden, NotFound } from '../../errors/index.js'\nimport { afterChange } from '../../fields/hooks/afterChange/index.js'\nimport { afterRead } from '../../fields/hooks/afterRead/index.js'\nimport { beforeChange } from '../../fields/hooks/beforeChange/index.js'\nimport { beforeValidate } from '../../fields/hooks/beforeValidate/index.js'\nimport { deleteAssociatedFiles } from '../../uploads/deleteAssociatedFiles.js'\nimport { generateFileData } from '../../uploads/generateFileData.js'\nimport { unlinkTempFiles } from '../../uploads/unlinkTempFiles.js'\nimport { uploadFiles } from '../../uploads/uploadFiles.js'\nimport { checkDocumentLockStatus } from '../../utilities/checkDocumentLockStatus.js'\nimport { commitTransaction } from '../../utilities/commitTransaction.js'\nimport { initTransaction } from '../../utilities/initTransaction.js'\nimport { killTransaction } from '../../utilities/killTransaction.js'\nimport { getLatestCollectionVersion } from '../../versions/getLatestCollectionVersion.js'\nimport { saveVersion } from '../../versions/saveVersion.js'\nimport { buildAfterOperation } from './utils.js'\n\nexport type Arguments<TSlug extends CollectionSlug> = {\n autosave?: boolean\n collection: Collection\n data: DeepPartial<RequiredDataFromCollectionSlug<TSlug>>\n depth?: number\n disableTransaction?: boolean\n disableVerificationEmail?: boolean\n draft?: boolean\n id: number | string\n overrideAccess?: boolean\n overrideLock?: boolean\n overwriteExistingFiles?: boolean\n populate?: PopulateType\n publishSpecificLocale?: string\n req: PayloadRequest\n select?: SelectType\n showHiddenFields?: boolean\n}\n\nexport const updateByIDOperation = async <\n TSlug extends CollectionSlug,\n TSelect extends SelectFromCollectionSlug<TSlug> = SelectType,\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 // /////////////////////////////////////\n // beforeOperation - Collection\n // /////////////////////////////////////\n\n await args.collection.config.hooks.beforeOperation.reduce(async (priorHook, hook) => {\n await priorHook\n\n args =\n (await hook({\n args,\n collection: args.collection.config,\n context: args.req.context,\n operation: 'update',\n req: args.req,\n })) || args\n }, Promise.resolve())\n\n if (args.publishSpecificLocale) {\n args.req.locale = args.publishSpecificLocale\n }\n\n const {\n id,\n autosave = false,\n collection: { config: collectionConfig },\n collection,\n depth,\n draft: draftArg = false,\n overrideAccess,\n overrideLock,\n overwriteExistingFiles = false,\n populate,\n publishSpecificLocale,\n req: {\n fallbackLocale,\n locale,\n payload: { config },\n payload,\n },\n req,\n select,\n showHiddenFields,\n } = args\n\n if (!id) {\n throw new APIError('Missing ID of document to update.', httpStatus.BAD_REQUEST)\n }\n\n let { data } = args\n const password = data?.password\n const shouldSaveDraft = Boolean(draftArg && collectionConfig.versions.drafts)\n const shouldSavePassword = Boolean(password && collectionConfig.auth && !shouldSaveDraft)\n\n // /////////////////////////////////////\n // Access\n // /////////////////////////////////////\n\n const accessResults = !overrideAccess\n ? await executeAccess({ id, data, req }, collectionConfig.access.update)\n : true\n const hasWherePolicy = hasWhereAccessResult(accessResults)\n\n // /////////////////////////////////////\n // Retrieve document\n // /////////////////////////////////////\n\n const findOneArgs: FindOneArgs = {\n collection: collectionConfig.slug,\n locale,\n req,\n where: combineQueries({ id: { equals: id } }, accessResults),\n }\n\n const docWithLocales = await getLatestCollectionVersion({\n id,\n config: collectionConfig,\n payload,\n query: findOneArgs,\n req,\n })\n\n if (!docWithLocales && !hasWherePolicy) {\n throw new NotFound(req.t)\n }\n if (!docWithLocales && hasWherePolicy) {\n throw new Forbidden(req.t)\n }\n\n // /////////////////////////////////////\n // Handle potentially locked documents\n // /////////////////////////////////////\n\n await checkDocumentLockStatus({\n id,\n collectionSlug: collectionConfig.slug,\n lockErrorMessage: `Document with ID ${id} is currently locked by another user and cannot be updated.`,\n overrideLock,\n req,\n })\n\n const originalDoc = await afterRead({\n collection: collectionConfig,\n context: req.context,\n depth: 0,\n doc: docWithLocales,\n draft: draftArg,\n fallbackLocale: null,\n global: null,\n locale,\n overrideAccess: true,\n req,\n showHiddenFields: true,\n })\n\n if (args.collection.config.auth) {\n ensureUsernameOrEmail<TSlug>({\n authOptions: args.collection.config.auth,\n collectionSlug: args.collection.config.slug,\n data: args.data,\n operation: 'update',\n originalDoc,\n req: args.req,\n })\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 operation: 'update',\n overwriteExistingFiles,\n req,\n throwOnMissingFile: false,\n })\n\n data = newFileData\n\n // /////////////////////////////////////\n // Delete any associated files\n // /////////////////////////////////////\n\n await deleteAssociatedFiles({\n collectionConfig,\n config,\n doc: docWithLocales,\n files: filesToUpload,\n overrideDelete: false,\n req,\n })\n\n // /////////////////////////////////////\n // beforeValidate - Fields\n // /////////////////////////////////////\n\n data = await beforeValidate<DeepPartial<DataFromCollectionSlug<TSlug>>>({\n id,\n collection: collectionConfig,\n context: req.context,\n data,\n doc: originalDoc,\n global: null,\n operation: 'update',\n overrideAccess,\n req,\n })\n\n // /////////////////////////////////////\n // beforeValidate - Collection\n // /////////////////////////////////////\n\n await collectionConfig.hooks.beforeValidate.reduce(async (priorHook, hook) => {\n await priorHook\n\n data =\n (await hook({\n collection: collectionConfig,\n context: req.context,\n data,\n operation: 'update',\n originalDoc,\n req,\n })) || data\n }, Promise.resolve())\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 // beforeChange - Collection\n // /////////////////////////////////////\n\n await collectionConfig.hooks.beforeChange.reduce(async (priorHook, hook) => {\n await priorHook\n\n data =\n (await hook({\n collection: collectionConfig,\n context: req.context,\n data,\n operation: 'update',\n originalDoc,\n req,\n })) || data\n }, Promise.resolve())\n\n // /////////////////////////////////////\n // beforeChange - Fields\n // /////////////////////////////////////\n\n let publishedDocWithLocales = docWithLocales\n let versionSnapshotResult\n\n const beforeChangeArgs: Args<DataFromCollectionSlug<TSlug>> = {\n id,\n collection: collectionConfig,\n context: req.context,\n data: { ...data, id },\n doc: originalDoc,\n docWithLocales: undefined,\n global: null,\n operation: 'update',\n req,\n skipValidation:\n shouldSaveDraft &&\n collectionConfig.versions.drafts &&\n !collectionConfig.versions.drafts.validate &&\n data._status !== 'published',\n }\n\n if (publishSpecificLocale) {\n versionSnapshotResult = await beforeChange({\n ...beforeChangeArgs,\n docWithLocales,\n })\n\n const lastPublished = await getLatestCollectionVersion({\n id,\n config: collectionConfig,\n payload,\n published: true,\n query: findOneArgs,\n req,\n })\n\n publishedDocWithLocales = lastPublished ? lastPublished : {}\n }\n\n let result = await beforeChange({\n ...beforeChangeArgs,\n docWithLocales: publishedDocWithLocales,\n })\n\n // /////////////////////////////////////\n // Handle potential password update\n // /////////////////////////////////////\n\n const dataToUpdate: Record<string, unknown> = { ...result }\n\n if (shouldSavePassword && typeof password === 'string') {\n const { hash, salt } = await generatePasswordSaltHash({\n collection: collectionConfig,\n password,\n req,\n })\n dataToUpdate.salt = salt\n dataToUpdate.hash = hash\n delete dataToUpdate.password\n delete data.password\n }\n\n // /////////////////////////////////////\n // Update\n // /////////////////////////////////////\n\n if (!shouldSaveDraft || data._status === 'published') {\n result = await req.payload.db.updateOne({\n id,\n collection: collectionConfig.slug,\n data: dataToUpdate,\n locale,\n req,\n select,\n })\n }\n\n // /////////////////////////////////////\n // Create version\n // /////////////////////////////////////\n\n if (collectionConfig.versions) {\n result = await saveVersion({\n id,\n autosave,\n collection: collectionConfig,\n docWithLocales: result,\n draft: shouldSaveDraft,\n payload,\n publishSpecificLocale,\n req,\n select,\n snapshot: versionSnapshotResult,\n })\n }\n\n // /////////////////////////////////////\n // afterRead - Fields\n // /////////////////////////////////////\n\n result = await afterRead({\n collection: collectionConfig,\n context: req.context,\n depth,\n doc: result,\n draft: draftArg,\n fallbackLocale,\n global: null,\n locale,\n overrideAccess,\n populate,\n req,\n select,\n showHiddenFields,\n })\n\n // /////////////////////////////////////\n // afterRead - Collection\n // /////////////////////////////////////\n\n await collectionConfig.hooks.afterRead.reduce(async (priorHook, hook) => {\n await priorHook\n\n result =\n (await hook({\n collection: collectionConfig,\n context: req.context,\n doc: result,\n req,\n })) || result\n }, Promise.resolve())\n\n // /////////////////////////////////////\n // afterChange - Fields\n // /////////////////////////////////////\n\n result = await afterChange({\n collection: collectionConfig,\n context: req.context,\n data,\n doc: result,\n global: null,\n operation: 'update',\n previousDoc: originalDoc,\n req,\n })\n\n // /////////////////////////////////////\n // afterChange - Collection\n // /////////////////////////////////////\n\n await collectionConfig.hooks.afterChange.reduce(async (priorHook, hook) => {\n await priorHook\n\n result =\n (await hook({\n collection: collectionConfig,\n context: req.context,\n doc: result,\n operation: 'update',\n previousDoc: originalDoc,\n req,\n })) || result\n }, Promise.resolve())\n\n // /////////////////////////////////////\n // afterOperation - Collection\n // /////////////////////////////////////\n\n result = await buildAfterOperation({\n args,\n collection: collectionConfig,\n operation: 'updateByID',\n result,\n })\n\n await unlinkTempFiles({\n collectionConfig,\n config,\n req,\n })\n\n // /////////////////////////////////////\n // Return results\n // /////////////////////////////////////\n\n if (shouldCommit) {\n await commitTransaction(req)\n }\n\n return result as TransformCollectionWithSelect<TSlug, TSelect>\n } catch (error: unknown) {\n await killTransaction(args.req)\n throw error\n }\n}\n"],"names":["httpStatus","ensureUsernameOrEmail","executeAccess","generatePasswordSaltHash","hasWhereAccessResult","combineQueries","APIError","Forbidden","NotFound","afterChange","afterRead","beforeChange","beforeValidate","deleteAssociatedFiles","generateFileData","unlinkTempFiles","uploadFiles","checkDocumentLockStatus","commitTransaction","initTransaction","killTransaction","getLatestCollectionVersion","saveVersion","buildAfterOperation","updateByIDOperation","incomingArgs","args","shouldCommit","disableTransaction","req","collection","config","hooks","beforeOperation","reduce","priorHook","hook","context","operation","Promise","resolve","publishSpecificLocale","locale","id","autosave","collectionConfig","depth","draft","draftArg","overrideAccess","overrideLock","overwriteExistingFiles","populate","fallbackLocale","payload","select","showHiddenFields","BAD_REQUEST","data","password","shouldSaveDraft","Boolean","versions","drafts","shouldSavePassword","auth","accessResults","access","update","hasWherePolicy","findOneArgs","slug","where","equals","docWithLocales","query","t","collectionSlug","lockErrorMessage","originalDoc","doc","global","authOptions","newFileData","files","filesToUpload","throwOnMissingFile","overrideDelete","upload","disableLocalStorage","publishedDocWithLocales","versionSnapshotResult","beforeChangeArgs","undefined","skipValidation","validate","_status","lastPublished","published","result","dataToUpdate","hash","salt","db","updateOne","snapshot","previousDoc","error"],"mappings":"AAEA,OAAOA,gBAAgB,cAAa;AAkBpC,SAASC,qBAAqB,QAAQ,sCAAqC;AAC3E,OAAOC,mBAAmB,8BAA6B;AACvD,SAASC,wBAAwB,QAAQ,0DAAyD;AA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AAgB;QACvB,MAAMvF,gBAAgBM,KAAKG,GAAG;QAC9B,MAAM8E;IACR;AACF,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"migrateRefresh.d.ts","sourceRoot":"","sources":["../../../src/database/migrations/migrateRefresh.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAA;AAQtD;;GAEG;AACH,wBAAsB,cAAc,CAAC,IAAI,EAAE,mBAAmB,
|
|
1
|
+
{"version":3,"file":"migrateRefresh.d.ts","sourceRoot":"","sources":["../../../src/database/migrations/migrateRefresh.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAA;AAQtD;;GAEG;AACH,wBAAsB,cAAc,CAAC,IAAI,EAAE,mBAAmB,iBAwF7D"}
|
|
@@ -10,62 +10,62 @@ import { readMigrationFiles } from './readMigrationFiles.js';
|
|
|
10
10
|
const migrationFiles = await readMigrationFiles({
|
|
11
11
|
payload
|
|
12
12
|
});
|
|
13
|
-
const { existingMigrations
|
|
13
|
+
const { existingMigrations } = await getMigrations({
|
|
14
14
|
payload
|
|
15
15
|
});
|
|
16
|
-
if (!existingMigrations?.length) {
|
|
17
|
-
payload.logger.info({
|
|
18
|
-
msg: 'No migrations to rollback.'
|
|
19
|
-
});
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
payload.logger.info({
|
|
23
|
-
msg: `Rolling back batch ${latestBatch} consisting of ${existingMigrations.length} migration(s).`
|
|
24
|
-
});
|
|
25
16
|
const req = {
|
|
26
17
|
payload
|
|
27
18
|
};
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
19
|
+
if (existingMigrations?.length) {
|
|
20
|
+
payload.logger.info({
|
|
21
|
+
msg: `Rolling back all ${existingMigrations.length} migration(s).`
|
|
22
|
+
});
|
|
23
|
+
// Reverse order of migrations to rollback
|
|
24
|
+
existingMigrations.reverse();
|
|
25
|
+
for (const migration of existingMigrations){
|
|
26
|
+
try {
|
|
27
|
+
const migrationFile = migrationFiles.find((m)=>m.name === migration.name);
|
|
28
|
+
if (!migrationFile) {
|
|
29
|
+
throw new Error(`Migration ${migration.name} not found locally.`);
|
|
30
|
+
}
|
|
31
|
+
payload.logger.info({
|
|
32
|
+
msg: `Migrating down: ${migration.name}`
|
|
33
|
+
});
|
|
34
|
+
const start = Date.now();
|
|
35
|
+
await initTransaction(req);
|
|
36
|
+
await migrationFile.down({
|
|
37
|
+
payload,
|
|
38
|
+
req
|
|
39
|
+
});
|
|
40
|
+
payload.logger.info({
|
|
41
|
+
msg: `Migrated down: ${migration.name} (${Date.now() - start}ms)`
|
|
42
|
+
});
|
|
43
|
+
await payload.delete({
|
|
44
|
+
collection: 'payload-migrations',
|
|
45
|
+
req,
|
|
46
|
+
where: {
|
|
47
|
+
name: {
|
|
48
|
+
equals: migration.name
|
|
49
|
+
}
|
|
54
50
|
}
|
|
51
|
+
});
|
|
52
|
+
} catch (err) {
|
|
53
|
+
await killTransaction(req);
|
|
54
|
+
let msg = `Error running migration ${migration.name}. Rolling back.`;
|
|
55
|
+
if (err instanceof Error) {
|
|
56
|
+
msg += ` ${err.message}`;
|
|
55
57
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
msg += ` ${err.message}`;
|
|
58
|
+
payload.logger.error({
|
|
59
|
+
err,
|
|
60
|
+
msg
|
|
61
|
+
});
|
|
62
|
+
process.exit(1);
|
|
62
63
|
}
|
|
63
|
-
payload.logger.error({
|
|
64
|
-
err,
|
|
65
|
-
msg
|
|
66
|
-
});
|
|
67
|
-
process.exit(1);
|
|
68
64
|
}
|
|
65
|
+
} else {
|
|
66
|
+
payload.logger.info({
|
|
67
|
+
msg: 'No migrations to rollback.'
|
|
68
|
+
});
|
|
69
69
|
}
|
|
70
70
|
// Run all migrate up
|
|
71
71
|
for (const migration of migrationFiles){
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/database/migrations/migrateRefresh.ts"],"sourcesContent":["import type { PayloadRequest } from '../../types/index.js'\nimport type { BaseDatabaseAdapter } from '../types.js'\n\nimport { commitTransaction } from '../../utilities/commitTransaction.js'\nimport { initTransaction } from '../../utilities/initTransaction.js'\nimport { killTransaction } from '../../utilities/killTransaction.js'\nimport { getMigrations } from './getMigrations.js'\nimport { readMigrationFiles } from './readMigrationFiles.js'\n\n/**\n * Run all migration down functions before running up\n */\nexport async function migrateRefresh(this: BaseDatabaseAdapter) {\n const { payload } = this\n const migrationFiles = await readMigrationFiles({ payload })\n\n const { existingMigrations
|
|
1
|
+
{"version":3,"sources":["../../../src/database/migrations/migrateRefresh.ts"],"sourcesContent":["import type { PayloadRequest } from '../../types/index.js'\nimport type { BaseDatabaseAdapter } from '../types.js'\n\nimport { commitTransaction } from '../../utilities/commitTransaction.js'\nimport { initTransaction } from '../../utilities/initTransaction.js'\nimport { killTransaction } from '../../utilities/killTransaction.js'\nimport { getMigrations } from './getMigrations.js'\nimport { readMigrationFiles } from './readMigrationFiles.js'\n\n/**\n * Run all migration down functions before running up\n */\nexport async function migrateRefresh(this: BaseDatabaseAdapter) {\n const { payload } = this\n const migrationFiles = await readMigrationFiles({ payload })\n\n const { existingMigrations } = await getMigrations({\n payload,\n })\n\n const req = { payload } as PayloadRequest\n\n if (existingMigrations?.length) {\n payload.logger.info({\n msg: `Rolling back all ${existingMigrations.length} migration(s).`,\n })\n // Reverse order of migrations to rollback\n existingMigrations.reverse()\n\n for (const migration of existingMigrations) {\n try {\n const migrationFile = migrationFiles.find((m) => m.name === migration.name)\n if (!migrationFile) {\n throw new Error(`Migration ${migration.name} not found locally.`)\n }\n\n payload.logger.info({ msg: `Migrating down: ${migration.name}` })\n const start = Date.now()\n await initTransaction(req)\n await migrationFile.down({ payload, req })\n payload.logger.info({\n msg: `Migrated down: ${migration.name} (${Date.now() - start}ms)`,\n })\n await payload.delete({\n collection: 'payload-migrations',\n req,\n where: {\n name: {\n equals: migration.name,\n },\n },\n })\n } catch (err: unknown) {\n await killTransaction(req)\n let msg = `Error running migration ${migration.name}. Rolling back.`\n if (err instanceof Error) {\n msg += ` ${err.message}`\n }\n payload.logger.error({\n err,\n msg,\n })\n process.exit(1)\n }\n }\n } else {\n payload.logger.info({ msg: 'No migrations to rollback.' })\n }\n\n // Run all migrate up\n for (const migration of migrationFiles) {\n payload.logger.info({ msg: `Migrating: ${migration.name}` })\n try {\n const start = Date.now()\n await initTransaction(req)\n await migration.up({ payload, req })\n await payload.create({\n collection: 'payload-migrations',\n data: {\n name: migration.name,\n executed: true,\n },\n req,\n })\n await commitTransaction(req)\n\n payload.logger.info({ msg: `Migrated: ${migration.name} (${Date.now() - start}ms)` })\n } catch (err: unknown) {\n await killTransaction(req)\n let msg = `Error running migration ${migration.name}. Rolling back.`\n if (err instanceof Error) {\n msg += ` ${err.message}`\n }\n payload.logger.error({\n err,\n msg,\n })\n process.exit(1)\n }\n }\n}\n"],"names":["commitTransaction","initTransaction","killTransaction","getMigrations","readMigrationFiles","migrateRefresh","payload","migrationFiles","existingMigrations","req","length","logger","info","msg","reverse","migration","migrationFile","find","m","name","Error","start","Date","now","down","delete","collection","where","equals","err","message","error","process","exit","up","create","data","executed"],"mappings":"AAGA,SAASA,iBAAiB,QAAQ,uCAAsC;AACxE,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,aAAa,QAAQ,qBAAoB;AAClD,SAASC,kBAAkB,Q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QACf;IACF;AACF"}
|
|
@@ -11,12 +11,12 @@ type Args = {
|
|
|
11
11
|
* * Combines the access result for joined collection
|
|
12
12
|
* * Combines the default join's `where`
|
|
13
13
|
*/
|
|
14
|
-
export declare const sanitizeJoinQuery: ({ collectionConfig, joins: joinsQuery, overrideAccess, req, }: Args) => Promise<false | {
|
|
15
|
-
[
|
|
14
|
+
export declare const sanitizeJoinQuery: ({ collectionConfig, joins: joinsQuery, overrideAccess, req, }: Args) => Promise<false | Partial<{
|
|
15
|
+
[x: string]: false | {
|
|
16
16
|
limit?: number;
|
|
17
17
|
sort?: string;
|
|
18
18
|
where?: import("../types/index.js").Where;
|
|
19
19
|
};
|
|
20
|
-
}
|
|
20
|
+
}>>;
|
|
21
21
|
export {};
|
|
22
22
|
//# sourceMappingURL=sanitizeJoinQuery.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sanitizeJoinQuery.d.ts","sourceRoot":"","sources":["../../src/database/sanitizeJoinQuery.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAA;AAC/E,OAAO,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAOlE,KAAK,IAAI,GAAG;IACV,gBAAgB,EAAE,yBAAyB,CAAA;IAC3C,KAAK,CAAC,EAAE,SAAS,CAAA;IACjB,cAAc,EAAE,OAAO,CAAA;IACvB,GAAG,EAAE,cAAc,CAAA;CACpB,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,kEAK3B,IAAI;;;;;;
|
|
1
|
+
{"version":3,"file":"sanitizeJoinQuery.d.ts","sourceRoot":"","sources":["../../src/database/sanitizeJoinQuery.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAA;AAC/E,OAAO,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAOlE,KAAK,IAAI,GAAG;IACV,gBAAgB,EAAE,yBAAyB,CAAA;IAC3C,KAAK,CAAC,EAAE,SAAS,CAAA;IACjB,cAAc,EAAE,OAAO,CAAA;IACvB,GAAG,EAAE,cAAc,CAAA;CACpB,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,kEAK3B,IAAI;;;;;;GAkEN,CAAA"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { SanitizedCollectionConfig } from '../../../collections/config/types.js';
|
|
2
2
|
import type { SanitizedGlobalConfig } from '../../../globals/config/types.js';
|
|
3
3
|
import type { RequestContext } from '../../../index.js';
|
|
4
|
-
import type { JsonObject, PayloadRequest, SelectType } from '../../../types/index.js';
|
|
4
|
+
import type { JsonObject, PayloadRequest, PopulateType, SelectType } from '../../../types/index.js';
|
|
5
5
|
type Args<T extends JsonObject> = {
|
|
6
6
|
collection: null | SanitizedCollectionConfig;
|
|
7
7
|
context: RequestContext;
|
|
@@ -15,6 +15,7 @@ type Args<T extends JsonObject> = {
|
|
|
15
15
|
global: null | SanitizedGlobalConfig;
|
|
16
16
|
locale: string;
|
|
17
17
|
overrideAccess: boolean;
|
|
18
|
+
populate?: PopulateType;
|
|
18
19
|
req: PayloadRequest;
|
|
19
20
|
select?: SelectType;
|
|
20
21
|
showHiddenFields: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/fields/hooks/afterRead/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,sCAAsC,CAAA;AACrF,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAA;AAC7E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AACvD,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/fields/hooks/afterRead/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,sCAAsC,CAAA;AACrF,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAA;AAC7E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AACvD,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;AAMnG,KAAK,IAAI,CAAC,CAAC,SAAS,UAAU,IAAI;IAChC,UAAU,EAAE,IAAI,GAAG,yBAAyB,CAAA;IAC5C,OAAO,EAAE,cAAc,CAAA;IACvB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,KAAK,EAAE,MAAM,CAAA;IACb,GAAG,EAAE,CAAC,CAAA;IACN,KAAK,EAAE,OAAO,CAAA;IACd,cAAc,EAAE,IAAI,GAAG,MAAM,CAAA;IAC7B,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,MAAM,EAAE,IAAI,GAAG,qBAAqB,CAAA;IACpC,MAAM,EAAE,MAAM,CAAA;IACd,cAAc,EAAE,OAAO,CAAA;IACvB,QAAQ,CAAC,EAAE,YAAY,CAAA;IACvB,GAAG,EAAE,cAAc,CAAA;IACnB,MAAM,CAAC,EAAE,UAAU,CAAA;IACnB,gBAAgB,EAAE,OAAO,CAAA;CAC1B,CAAA;AAED;;;;;;;;GAQG;AAEH,wBAAsB,SAAS,CAAC,CAAC,SAAS,UAAU,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAgE/E"}
|
|
@@ -10,7 +10,7 @@ import { traverseFields } from './traverseFields.js';
|
|
|
10
10
|
* - Execute read access control
|
|
11
11
|
* - Populate relationships
|
|
12
12
|
*/ export async function afterRead(args) {
|
|
13
|
-
const { collection, context, currentDepth: incomingCurrentDepth, depth: incomingDepth, doc: incomingDoc, draft, fallbackLocale, findMany, flattenLocales = true, global, locale, overrideAccess, req, select, showHiddenFields } = args;
|
|
13
|
+
const { collection, context, currentDepth: incomingCurrentDepth, depth: incomingDepth, doc: incomingDoc, draft, fallbackLocale, findMany, flattenLocales = true, global, locale, overrideAccess, populate, req, select, showHiddenFields } = args;
|
|
14
14
|
const doc = deepCopyObjectSimple(incomingDoc);
|
|
15
15
|
const fieldPromises = [];
|
|
16
16
|
const populationPromises = [];
|
|
@@ -35,6 +35,7 @@ import { traverseFields } from './traverseFields.js';
|
|
|
35
35
|
locale,
|
|
36
36
|
overrideAccess,
|
|
37
37
|
path: [],
|
|
38
|
+
populate,
|
|
38
39
|
populationPromises,
|
|
39
40
|
req,
|
|
40
41
|
schemaPath: [],
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/fields/hooks/afterRead/index.ts"],"sourcesContent":["import type { SanitizedCollectionConfig } from '../../../collections/config/types.js'\nimport type { SanitizedGlobalConfig } from '../../../globals/config/types.js'\nimport type { RequestContext } from '../../../index.js'\nimport type { JsonObject, PayloadRequest, SelectType } from '../../../types/index.js'\n\nimport { deepCopyObjectSimple } from '../../../utilities/deepCopyObject.js'\nimport { getSelectMode } from '../../../utilities/getSelectMode.js'\nimport { traverseFields } from './traverseFields.js'\n\ntype Args<T extends JsonObject> = {\n collection: null | SanitizedCollectionConfig\n context: RequestContext\n currentDepth?: number\n depth: number\n doc: T\n draft: boolean\n fallbackLocale: null | string\n findMany?: boolean\n flattenLocales?: boolean\n global: null | SanitizedGlobalConfig\n locale: string\n overrideAccess: boolean\n req: PayloadRequest\n select?: SelectType\n showHiddenFields: boolean\n}\n\n/**\n * This function is responsible for the following actions, in order:\n * - Remove hidden fields from response\n * - Flatten locales into requested locale. If the input doc contains all locales, the output doc after this function will only contain the requested locale.\n * - Sanitize outgoing data (point field, etc.)\n * - Execute field hooks\n * - Execute read access control\n * - Populate relationships\n */\n\nexport async function afterRead<T extends JsonObject>(args: Args<T>): Promise<T> {\n const {\n collection,\n context,\n currentDepth: incomingCurrentDepth,\n depth: incomingDepth,\n doc: incomingDoc,\n draft,\n fallbackLocale,\n findMany,\n flattenLocales = true,\n global,\n locale,\n overrideAccess,\n req,\n select,\n showHiddenFields,\n } = args\n\n const doc = deepCopyObjectSimple(incomingDoc)\n const fieldPromises = []\n const populationPromises = []\n\n let depth =\n incomingDepth || incomingDepth === 0\n ? parseInt(String(incomingDepth), 10)\n : req.payload.config.defaultDepth\n if (depth > req.payload.config.maxDepth) {\n depth = req.payload.config.maxDepth\n }\n\n const currentDepth = incomingCurrentDepth || 1\n\n traverseFields({\n collection,\n context,\n currentDepth,\n depth,\n doc,\n draft,\n fallbackLocale,\n fieldPromises,\n fields: collection?.fields || global?.fields,\n findMany,\n flattenLocales,\n global,\n locale,\n overrideAccess,\n path: [],\n populationPromises,\n req,\n schemaPath: [],\n select,\n selectMode: select ? getSelectMode(select) : undefined,\n showHiddenFields,\n siblingDoc: doc,\n })\n\n await Promise.all(fieldPromises)\n await Promise.all(populationPromises)\n\n return doc\n}\n"],"names":["deepCopyObjectSimple","getSelectMode","traverseFields","afterRead","args","collection","context","currentDepth","incomingCurrentDepth","depth","incomingDepth","doc","incomingDoc","draft","fallbackLocale","findMany","flattenLocales","global","locale","overrideAccess","req","select","showHiddenFields","fieldPromises","populationPromises","parseInt","String","payload","config","defaultDepth","maxDepth","fields","path","schemaPath","selectMode","undefined","siblingDoc","Promise","all"],"mappings":"AAKA,SAASA,oBAAoB,QAAQ,uCAAsC;AAC3E,SAASC,aAAa,QAAQ,sCAAqC;AACnE,SAASC,cAAc,QAAQ,sBAAqB;
|
|
1
|
+
{"version":3,"sources":["../../../../src/fields/hooks/afterRead/index.ts"],"sourcesContent":["import type { SanitizedCollectionConfig } from '../../../collections/config/types.js'\nimport type { SanitizedGlobalConfig } from '../../../globals/config/types.js'\nimport type { RequestContext } from '../../../index.js'\nimport type { JsonObject, PayloadRequest, PopulateType, SelectType } from '../../../types/index.js'\n\nimport { deepCopyObjectSimple } from '../../../utilities/deepCopyObject.js'\nimport { getSelectMode } from '../../../utilities/getSelectMode.js'\nimport { traverseFields } from './traverseFields.js'\n\ntype Args<T extends JsonObject> = {\n collection: null | SanitizedCollectionConfig\n context: RequestContext\n currentDepth?: number\n depth: number\n doc: T\n draft: boolean\n fallbackLocale: null | string\n findMany?: boolean\n flattenLocales?: boolean\n global: null | SanitizedGlobalConfig\n locale: string\n overrideAccess: boolean\n populate?: PopulateType\n req: PayloadRequest\n select?: SelectType\n showHiddenFields: boolean\n}\n\n/**\n * This function is responsible for the following actions, in order:\n * - Remove hidden fields from response\n * - Flatten locales into requested locale. If the input doc contains all locales, the output doc after this function will only contain the requested locale.\n * - Sanitize outgoing data (point field, etc.)\n * - Execute field hooks\n * - Execute read access control\n * - Populate relationships\n */\n\nexport async function afterRead<T extends JsonObject>(args: Args<T>): Promise<T> {\n const {\n collection,\n context,\n currentDepth: incomingCurrentDepth,\n depth: incomingDepth,\n doc: incomingDoc,\n draft,\n fallbackLocale,\n findMany,\n flattenLocales = true,\n global,\n locale,\n overrideAccess,\n populate,\n req,\n select,\n showHiddenFields,\n } = args\n\n const doc = deepCopyObjectSimple(incomingDoc)\n const fieldPromises = []\n const populationPromises = []\n\n let depth =\n incomingDepth || incomingDepth === 0\n ? parseInt(String(incomingDepth), 10)\n : req.payload.config.defaultDepth\n if (depth > req.payload.config.maxDepth) {\n depth = req.payload.config.maxDepth\n }\n\n const currentDepth = incomingCurrentDepth || 1\n\n traverseFields({\n collection,\n context,\n currentDepth,\n depth,\n doc,\n draft,\n fallbackLocale,\n fieldPromises,\n fields: collection?.fields || global?.fields,\n findMany,\n flattenLocales,\n global,\n locale,\n overrideAccess,\n path: [],\n populate,\n populationPromises,\n req,\n schemaPath: [],\n select,\n selectMode: select ? getSelectMode(select) : undefined,\n showHiddenFields,\n siblingDoc: doc,\n })\n\n await Promise.all(fieldPromises)\n await Promise.all(populationPromises)\n\n return doc\n}\n"],"names":["deepCopyObjectSimple","getSelectMode","traverseFields","afterRead","args","collection","context","currentDepth","incomingCurrentDepth","depth","incomingDepth","doc","incomingDoc","draft","fallbackLocale","findMany","flattenLocales","global","locale","overrideAccess","populate","req","select","showHiddenFields","fieldPromises","populationPromises","parseInt","String","payload","config","defaultDepth","maxDepth","fields","path","schemaPath","selectMode","undefined","siblingDoc","Promise","all"],"mappings":"AAKA,SAASA,oBAAoB,QAAQ,uCAAsC;AAC3E,SAASC,aAAa,QAAQ,sCAAqC;AACnE,SAASC,cAAc,QAAQ,sBAAqB;AAqBpD;;;;;;;;CAQC,GAED,OAAO,eAAeC,UAAgCC,IAAa;IACjE,MAAM,EACJC,UAAU,EACVC,OAAO,EACPC,cAAcC,oBAAoB,EAClCC,OAAOC,aAAa,EACpBC,KAAKC,WAAW,EAChBC,KAAK,EACLC,cAAc,EACdC,QAAQ,EACRC,iBAAiB,IAAI,EACrBC,MAAM,EACNC,MAAM,EACNC,cAAc,EACdC,QAAQ,EACRC,GAAG,EACHC,MAAM,EACNC,gBAAgB,EACjB,GAAGnB;IAEJ,MAAMO,MAAMX,qBAAqBY;IACjC,MAAMY,gBAAgB,EAAE;IACxB,MAAMC,qBAAqB,EAAE;IAE7B,IAAIhB,QACFC,iBAAiBA,kBAAkB,IAC/BgB,SAASC,OAAOjB,gBAAgB,MAChCW,IAAIO,OAAO,CAACC,MAAM,CAACC,YAAY;IACrC,IAAIrB,QAAQY,IAAIO,OAAO,CAACC,MAAM,CAACE,QAAQ,EAAE;QACvCtB,QAAQY,IAAIO,OAAO,CAACC,MAAM,CAACE,QAAQ;IACrC;IAEA,MAAMxB,eAAeC,wBAAwB;IAE7CN,eAAe;QACbG;QACAC;QACAC;QACAE;QACAE;QACAE;QACAC;QACAU;QACAQ,QAAQ3B,YAAY2B,UAAUf,QAAQe;QACtCjB;QACAC;QACAC;QACAC;QACAC;QACAc,MAAM,EAAE;QACRb;QACAK;QACAJ;QACAa,YAAY,EAAE;QACdZ;QACAa,YAAYb,SAASrB,cAAcqB,UAAUc;QAC7Cb;QACAc,YAAY1B;IACd;IAEA,MAAM2B,QAAQC,GAAG,CAACf;IAClB,MAAMc,QAAQC,GAAG,CAACd;IAElB,OAAOd;AACT"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { SanitizedCollectionConfig } from '../../../collections/config/types.js';
|
|
2
2
|
import type { SanitizedGlobalConfig } from '../../../globals/config/types.js';
|
|
3
3
|
import type { RequestContext } from '../../../index.js';
|
|
4
|
-
import type { JsonObject, PayloadRequest, SelectMode, SelectType } from '../../../types/index.js';
|
|
4
|
+
import type { JsonObject, PayloadRequest, PopulateType, SelectMode, SelectType } from '../../../types/index.js';
|
|
5
5
|
import type { Field, TabAsField } from '../../config/types.js';
|
|
6
6
|
type Args = {
|
|
7
7
|
collection: null | SanitizedCollectionConfig;
|
|
@@ -29,6 +29,7 @@ type Args = {
|
|
|
29
29
|
* The parent's schemaPath (path without indexes).
|
|
30
30
|
*/
|
|
31
31
|
parentSchemaPath: string[];
|
|
32
|
+
populate?: PopulateType;
|
|
32
33
|
populationPromises: Promise<void>[];
|
|
33
34
|
req: PayloadRequest;
|
|
34
35
|
select?: SelectType;
|
|
@@ -38,6 +39,6 @@ type Args = {
|
|
|
38
39
|
triggerAccessControl?: boolean;
|
|
39
40
|
triggerHooks?: boolean;
|
|
40
41
|
};
|
|
41
|
-
export declare const promise: ({ collection, context, currentDepth, depth, doc, draft, fallbackLocale, field, fieldPromises, findMany, flattenLocales, global, locale, overrideAccess, parentPath, parentSchemaPath, populationPromises, req, select, selectMode, showHiddenFields, siblingDoc, triggerAccessControl, triggerHooks, }: Args) => Promise<void>;
|
|
42
|
+
export declare const promise: ({ collection, context, currentDepth, depth, doc, draft, fallbackLocale, field, fieldPromises, findMany, flattenLocales, global, locale, overrideAccess, parentPath, parentSchemaPath, populate, populationPromises, req, select, selectMode, showHiddenFields, siblingDoc, triggerAccessControl, triggerHooks, }: Args) => Promise<void>;
|
|
42
43
|
export {};
|
|
43
44
|
//# sourceMappingURL=promise.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"promise.d.ts","sourceRoot":"","sources":["../../../../src/fields/hooks/afterRead/promise.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,sCAAsC,CAAA;AACrF,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAA;AAC7E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AACvD,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"promise.d.ts","sourceRoot":"","sources":["../../../../src/fields/hooks/afterRead/promise.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,sCAAsC,CAAA;AACrF,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAA;AAC7E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AACvD,OAAO,KAAK,EACV,UAAU,EACV,cAAc,EACd,YAAY,EACZ,UAAU,EACV,UAAU,EACX,MAAM,yBAAyB,CAAA;AAChC,OAAO,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AAS9D,KAAK,IAAI,GAAG;IACV,UAAU,EAAE,IAAI,GAAG,yBAAyB,CAAA;IAC5C,OAAO,EAAE,cAAc,CAAA;IACvB,YAAY,EAAE,MAAM,CAAA;IACpB,KAAK,EAAE,MAAM,CAAA;IACb,GAAG,EAAE,UAAU,CAAA;IACf,KAAK,EAAE,OAAO,CAAA;IACd,cAAc,EAAE,IAAI,GAAG,MAAM,CAAA;IAC7B,KAAK,EAAE,KAAK,GAAG,UAAU,CAAA;IACzB;;OAEG;IACH,aAAa,EAAE,OAAO,CAAC,IAAI,CAAC,EAAE,CAAA;IAC9B,QAAQ,EAAE,OAAO,CAAA;IACjB,cAAc,EAAE,OAAO,CAAA;IACvB,MAAM,EAAE,IAAI,GAAG,qBAAqB,CAAA;IACpC,MAAM,EAAE,IAAI,GAAG,MAAM,CAAA;IACrB,cAAc,EAAE,OAAO,CAAA;IACvB;;OAEG;IACH,UAAU,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAA;IAC/B;;OAEG;IACH,gBAAgB,EAAE,MAAM,EAAE,CAAA;IAC1B,QAAQ,CAAC,EAAE,YAAY,CAAA;IACvB,kBAAkB,EAAE,OAAO,CAAC,IAAI,CAAC,EAAE,CAAA;IACnC,GAAG,EAAE,cAAc,CAAA;IACnB,MAAM,CAAC,EAAE,UAAU,CAAA;IACnB,UAAU,CAAC,EAAE,UAAU,CAAA;IACvB,gBAAgB,EAAE,OAAO,CAAA;IACzB,UAAU,EAAE,UAAU,CAAA;IACtB,oBAAoB,CAAC,EAAE,OAAO,CAAA;IAC9B,YAAY,CAAC,EAAE,OAAO,CAAA;CACvB,CAAA;AAUD,eAAO,MAAM,OAAO,qTA0BjB,IAAI,KAAG,OAAO,CAAC,IAAI,CAkrBrB,CAAA"}
|
|
@@ -11,7 +11,7 @@ import { traverseFields } from './traverseFields.js';
|
|
|
11
11
|
// - Execute field hooks
|
|
12
12
|
// - Execute read access control
|
|
13
13
|
// - Populate relationships
|
|
14
|
-
export const promise = async ({ collection, context, currentDepth, depth, doc, draft, fallbackLocale, field, fieldPromises, findMany, flattenLocales, global, locale, overrideAccess, parentPath, parentSchemaPath, populationPromises, req, select, selectMode, showHiddenFields, siblingDoc, triggerAccessControl = true, triggerHooks = true })=>{
|
|
14
|
+
export const promise = async ({ collection, context, currentDepth, depth, doc, draft, fallbackLocale, field, fieldPromises, findMany, flattenLocales, global, locale, overrideAccess, parentPath, parentSchemaPath, populate, populationPromises, req, select, selectMode, showHiddenFields, siblingDoc, triggerAccessControl = true, triggerHooks = true })=>{
|
|
15
15
|
const { path: fieldPath, schemaPath: fieldSchemaPath } = getFieldPaths({
|
|
16
16
|
field,
|
|
17
17
|
parentPath,
|
|
@@ -205,6 +205,7 @@ export const promise = async ({ collection, context, currentDepth, depth, doc, d
|
|
|
205
205
|
field,
|
|
206
206
|
locale,
|
|
207
207
|
overrideAccess,
|
|
208
|
+
populate,
|
|
208
209
|
req,
|
|
209
210
|
showHiddenFields,
|
|
210
211
|
siblingDoc
|
|
@@ -235,6 +236,7 @@ export const promise = async ({ collection, context, currentDepth, depth, doc, d
|
|
|
235
236
|
locale,
|
|
236
237
|
overrideAccess,
|
|
237
238
|
path: fieldPath,
|
|
239
|
+
populate,
|
|
238
240
|
populationPromises,
|
|
239
241
|
req,
|
|
240
242
|
schemaPath: fieldSchemaPath,
|
|
@@ -275,6 +277,7 @@ export const promise = async ({ collection, context, currentDepth, depth, doc, d
|
|
|
275
277
|
...fieldPath,
|
|
276
278
|
i
|
|
277
279
|
],
|
|
280
|
+
populate,
|
|
278
281
|
populationPromises,
|
|
279
282
|
req,
|
|
280
283
|
schemaPath: fieldSchemaPath,
|
|
@@ -309,6 +312,7 @@ export const promise = async ({ collection, context, currentDepth, depth, doc, d
|
|
|
309
312
|
...fieldPath,
|
|
310
313
|
i
|
|
311
314
|
],
|
|
315
|
+
populate,
|
|
312
316
|
populationPromises,
|
|
313
317
|
req,
|
|
314
318
|
schemaPath: fieldSchemaPath,
|
|
@@ -372,6 +376,7 @@ export const promise = async ({ collection, context, currentDepth, depth, doc, d
|
|
|
372
376
|
...fieldPath,
|
|
373
377
|
i
|
|
374
378
|
],
|
|
379
|
+
populate,
|
|
375
380
|
populationPromises,
|
|
376
381
|
req,
|
|
377
382
|
schemaPath: fieldSchemaPath,
|
|
@@ -409,6 +414,7 @@ export const promise = async ({ collection, context, currentDepth, depth, doc, d
|
|
|
409
414
|
...fieldPath,
|
|
410
415
|
i
|
|
411
416
|
],
|
|
417
|
+
populate,
|
|
412
418
|
populationPromises,
|
|
413
419
|
req,
|
|
414
420
|
schemaPath: fieldSchemaPath,
|
|
@@ -445,6 +451,7 @@ export const promise = async ({ collection, context, currentDepth, depth, doc, d
|
|
|
445
451
|
locale,
|
|
446
452
|
overrideAccess,
|
|
447
453
|
path: fieldPath,
|
|
454
|
+
populate,
|
|
448
455
|
populationPromises,
|
|
449
456
|
req,
|
|
450
457
|
schemaPath: fieldSchemaPath,
|
|
@@ -488,6 +495,7 @@ export const promise = async ({ collection, context, currentDepth, depth, doc, d
|
|
|
488
495
|
locale,
|
|
489
496
|
overrideAccess,
|
|
490
497
|
path: fieldPath,
|
|
498
|
+
populate,
|
|
491
499
|
populationPromises,
|
|
492
500
|
req,
|
|
493
501
|
schemaPath: fieldSchemaPath,
|
|
@@ -521,6 +529,7 @@ export const promise = async ({ collection, context, currentDepth, depth, doc, d
|
|
|
521
529
|
locale,
|
|
522
530
|
overrideAccess,
|
|
523
531
|
path: fieldPath,
|
|
532
|
+
populate,
|
|
524
533
|
populationPromises,
|
|
525
534
|
req,
|
|
526
535
|
schemaPath: fieldSchemaPath,
|
|
@@ -567,6 +576,7 @@ export const promise = async ({ collection, context, currentDepth, depth, doc, d
|
|
|
567
576
|
originalDoc: doc,
|
|
568
577
|
overrideAccess,
|
|
569
578
|
path: fieldPath,
|
|
579
|
+
populate,
|
|
570
580
|
populationPromises,
|
|
571
581
|
req,
|
|
572
582
|
schemaPath: fieldSchemaPath,
|
|
@@ -600,6 +610,7 @@ export const promise = async ({ collection, context, currentDepth, depth, doc, d
|
|
|
600
610
|
originalDoc: doc,
|
|
601
611
|
overrideAccess,
|
|
602
612
|
path: fieldPath,
|
|
613
|
+
populate,
|
|
603
614
|
populationPromises,
|
|
604
615
|
req,
|
|
605
616
|
schemaPath: fieldSchemaPath,
|