payload 3.0.0-beta.124 → 3.0.0-beta.126
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 +4 -1
- package/dist/admin/RichText.d.ts.map +1 -1
- package/dist/admin/RichText.js.map +1 -1
- package/dist/collections/config/types.d.ts +2 -2
- package/dist/collections/config/types.d.ts.map +1 -1
- package/dist/collections/config/types.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 -1
- 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 +11 -3
- 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 +23 -7
- 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/count.d.ts +2 -2
- package/dist/collections/operations/local/count.d.ts.map +1 -1
- package/dist/collections/operations/local/count.js.map +1 -1
- package/dist/collections/operations/local/create.d.ts +3 -2
- 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 +3 -2
- 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 +3 -2
- 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 +4 -3
- package/dist/collections/operations/local/find.d.ts.map +1 -1
- package/dist/collections/operations/local/find.js.map +1 -1
- package/dist/collections/operations/local/findByID.d.ts +4 -3
- 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 +3 -2
- 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 +3 -2
- 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 +3 -2
- 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 +3 -2
- 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/sanitizeJoinQuery.d.ts +22 -0
- package/dist/database/sanitizeJoinQuery.d.ts.map +1 -0
- package/dist/database/sanitizeJoinQuery.js +61 -0
- package/dist/database/sanitizeJoinQuery.js.map +1 -0
- package/dist/fields/config/types.d.ts +6 -3
- package/dist/fields/config/types.d.ts.map +1 -1
- package/dist/fields/config/types.js.map +1 -1
- package/dist/fields/hooks/afterChange/index.d.ts +2 -1
- package/dist/fields/hooks/afterChange/index.d.ts.map +1 -1
- package/dist/fields/hooks/afterChange/index.js.map +1 -1
- package/dist/fields/hooks/afterChange/promise.d.ts +2 -1
- package/dist/fields/hooks/afterChange/promise.d.ts.map +1 -1
- package/dist/fields/hooks/afterChange/promise.js.map +1 -1
- package/dist/fields/hooks/afterChange/traverseFields.d.ts +2 -1
- package/dist/fields/hooks/afterChange/traverseFields.d.ts.map +1 -1
- package/dist/fields/hooks/afterChange/traverseFields.js.map +1 -1
- package/dist/fields/hooks/afterRead/index.d.ts +3 -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 +4 -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 +4 -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/fields/hooks/beforeChange/index.d.ts +2 -1
- package/dist/fields/hooks/beforeChange/index.d.ts.map +1 -1
- package/dist/fields/hooks/beforeChange/index.js.map +1 -1
- package/dist/fields/hooks/beforeChange/promise.d.ts +2 -1
- package/dist/fields/hooks/beforeChange/promise.d.ts.map +1 -1
- package/dist/fields/hooks/beforeChange/promise.js.map +1 -1
- package/dist/fields/hooks/beforeChange/traverseFields.d.ts +2 -1
- package/dist/fields/hooks/beforeChange/traverseFields.d.ts.map +1 -1
- package/dist/fields/hooks/beforeChange/traverseFields.js.map +1 -1
- package/dist/fields/hooks/beforeDuplicate/index.d.ts +2 -1
- package/dist/fields/hooks/beforeDuplicate/index.d.ts.map +1 -1
- package/dist/fields/hooks/beforeDuplicate/index.js.map +1 -1
- package/dist/fields/hooks/beforeDuplicate/promise.d.ts +2 -1
- package/dist/fields/hooks/beforeDuplicate/promise.d.ts.map +1 -1
- package/dist/fields/hooks/beforeDuplicate/promise.js.map +1 -1
- package/dist/fields/hooks/beforeDuplicate/traverseFields.d.ts +2 -1
- package/dist/fields/hooks/beforeDuplicate/traverseFields.d.ts.map +1 -1
- package/dist/fields/hooks/beforeDuplicate/traverseFields.js.map +1 -1
- package/dist/fields/hooks/beforeValidate/index.d.ts +2 -1
- package/dist/fields/hooks/beforeValidate/index.d.ts.map +1 -1
- package/dist/fields/hooks/beforeValidate/index.js.map +1 -1
- package/dist/fields/hooks/beforeValidate/promise.d.ts +2 -1
- package/dist/fields/hooks/beforeValidate/promise.d.ts.map +1 -1
- package/dist/fields/hooks/beforeValidate/promise.js.map +1 -1
- package/dist/fields/hooks/beforeValidate/traverseFields.d.ts +2 -1
- package/dist/fields/hooks/beforeValidate/traverseFields.d.ts.map +1 -1
- package/dist/fields/hooks/beforeValidate/traverseFields.js.map +1 -1
- package/dist/globals/config/types.d.ts +2 -2
- package/dist/globals/config/types.d.ts.map +1 -1
- package/dist/globals/config/types.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 +6 -8
- 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 +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/collections/operations/findByID.ts"],"sourcesContent":["import type { FindOneArgs } from '../../database/types.js'\nimport type { CollectionSlug, JoinQuery } from '../../index.js'\nimport type {\n ApplyDisableErrors,\n PayloadRequest,\n SelectType,\n TransformCollectionWithSelect,\n} from '../../types/index.js'\nimport type {\n Collection,\n DataFromCollectionSlug,\n SelectFromCollectionSlug,\n} from '../config/types.js'\n\nimport executeAccess from '../../auth/executeAccess.js'\nimport { combineQueries } from '../../database/combineQueries.js'\nimport { NotFound } from '../../errors/index.js'\nimport { afterRead } from '../../fields/hooks/afterRead/index.js'\nimport { killTransaction } from '../../utilities/killTransaction.js'\nimport replaceWithDraftIfAvailable from '../../versions/drafts/replaceWithDraftIfAvailable.js'\nimport { buildAfterOperation } from './utils.js'\n\nexport type Arguments = {\n collection: Collection\n currentDepth?: number\n depth?: number\n disableErrors?: boolean\n draft?: boolean\n id: number | string\n includeLockStatus?: boolean\n joins?: JoinQuery\n overrideAccess?: boolean\n req: PayloadRequest\n select?: SelectType\n showHiddenFields?: boolean\n}\n\nexport const findByIDOperation = async <\n TSlug extends CollectionSlug,\n TDisableErrors extends boolean,\n TSelect extends SelectFromCollectionSlug<TSlug>,\n>(\n incomingArgs: Arguments,\n): Promise<ApplyDisableErrors<TransformCollectionWithSelect<TSlug, TSelect>, TDisableErrors>> => {\n let args = incomingArgs\n\n try {\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: 'read',\n req: args.req,\n })) || args\n }, Promise.resolve())\n\n const {\n id,\n collection: { config: collectionConfig },\n currentDepth,\n depth,\n disableErrors,\n draft: draftEnabled = false,\n includeLockStatus,\n joins,\n overrideAccess = false,\n req: { fallbackLocale, locale, t },\n req,\n select,\n showHiddenFields,\n } = args\n\n // /////////////////////////////////////\n // Access\n // /////////////////////////////////////\n\n const accessResult = !overrideAccess\n ? await executeAccess({ id, disableErrors, req }, collectionConfig.access.read)\n : true\n\n // If errors are disabled, and access returns false, return null\n if (accessResult === false) {\n return null\n }\n\n const findOneArgs: FindOneArgs = {\n collection: collectionConfig.slug,\n joins: req.payloadAPI === 'GraphQL' ? false : joins,\n locale,\n req: {\n transactionID: req.transactionID,\n } as PayloadRequest,\n select,\n where: combineQueries({ id: { equals: id } }, accessResult),\n }\n\n // /////////////////////////////////////\n // Find by ID\n // /////////////////////////////////////\n\n if (!findOneArgs.where.and[0].id) {\n throw new NotFound(t)\n }\n\n let result: DataFromCollectionSlug<TSlug> = await req.payload.db.findOne(findOneArgs)\n\n if (!result) {\n if (!disableErrors) {\n throw new NotFound(req.t)\n }\n\n return null\n }\n\n // /////////////////////////////////////\n // Include Lock Status if required\n // /////////////////////////////////////\n\n if (includeLockStatus && id) {\n let lockStatus = null\n\n try {\n const lockDocumentsProp = collectionConfig?.lockDocuments\n\n const lockDurationDefault = 300 // Default 5 minutes in seconds\n const lockDuration =\n typeof lockDocumentsProp === 'object' ? lockDocumentsProp.duration : lockDurationDefault\n const lockDurationInMilliseconds = lockDuration * 1000\n\n const lockedDocument = await req.payload.find({\n collection: 'payload-locked-documents',\n depth: 1,\n limit: 1,\n overrideAccess: false,\n pagination: false,\n req,\n where: {\n and: [\n {\n 'document.relationTo': {\n equals: collectionConfig.slug,\n },\n },\n {\n 'document.value': {\n equals: id,\n },\n },\n // Query where the lock is newer than the current time minus lock time\n {\n updatedAt: {\n greater_than: new Date(new Date().getTime() - lockDurationInMilliseconds),\n },\n },\n ],\n },\n })\n\n if (lockedDocument && lockedDocument.docs.length > 0) {\n lockStatus = lockedDocument.docs[0]\n }\n } catch {\n // swallow error\n }\n\n result._isLocked = !!lockStatus\n result._userEditing = lockStatus?.user?.value ?? null\n }\n\n // /////////////////////////////////////\n // Replace document with draft if available\n // /////////////////////////////////////\n\n if (collectionConfig.versions?.drafts && draftEnabled) {\n result = await replaceWithDraftIfAvailable({\n accessResult,\n doc: result,\n entity: collectionConfig,\n entityType: 'collection',\n overrideAccess,\n req,\n select,\n })\n }\n\n // /////////////////////////////////////\n // beforeRead - Collection\n // /////////////////////////////////////\n\n await collectionConfig.hooks.beforeRead.reduce(async (priorHook, hook) => {\n await priorHook\n\n result =\n (await hook({\n collection: collectionConfig,\n context: req.context,\n doc: result,\n query: findOneArgs.where,\n req,\n })) || result\n }, Promise.resolve())\n\n // /////////////////////////////////////\n // afterRead - Fields\n // /////////////////////////////////////\n\n result = await afterRead({\n collection: collectionConfig,\n context: req.context,\n currentDepth,\n depth,\n doc: result,\n draft: draftEnabled,\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 query: findOneArgs.where,\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: 'findByID',\n result,\n })\n\n // /////////////////////////////////////\n // Return results\n // /////////////////////////////////////\n\n return result as ApplyDisableErrors<\n TransformCollectionWithSelect<TSlug, TSelect>,\n TDisableErrors\n >\n } catch (error: unknown) {\n await killTransaction(args.req)\n throw error\n }\n}\n"],"names":["executeAccess","combineQueries","NotFound","afterRead","killTransaction","replaceWithDraftIfAvailable","buildAfterOperation","findByIDOperation","incomingArgs","args","collection","config","hooks","beforeOperation","reduce","priorHook","hook","context","req","operation","Promise","resolve","id","collectionConfig","currentDepth","depth","disableErrors","draft","draftEnabled","includeLockStatus","joins","overrideAccess","fallbackLocale","locale","t","select","showHiddenFields","accessResult","access","read","findOneArgs","slug","payloadAPI","transactionID","where","equals","and","result","payload","db","findOne","lockStatus","lockDocumentsProp","lockDocuments","lockDurationDefault","lockDuration","duration","lockDurationInMilliseconds","lockedDocument","find","limit","pagination","updatedAt","greater_than","Date","getTime","docs","length","_isLocked","_userEditing","user","value","versions","drafts","doc","entity","entityType","beforeRead","query","global","error"],"mappings":"AAcA,OAAOA,mBAAmB,8BAA6B;AACvD,SAASC,cAAc,Q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wCAAwC;QACxC,8BAA8B;QAC9B,wCAAwC;QAExC0B,SAAS,MAAMzC,oBAAoB;YACjCG;YACAC,YAAYa;YACZJ,WAAW;YACX4B;QACF;QAEA,wCAAwC;QACxC,iBAAiB;QACjB,wCAAwC;QAExC,OAAOA;IAIT,EAAE,OAAOiC,OAAgB;QACvB,MAAM5E,gBAAgBK,KAAKS,GAAG;QAC9B,MAAM8D;IACR;AACF,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../../src/collections/operations/findByID.ts"],"sourcesContent":["import type { FindOneArgs } from '../../database/types.js'\nimport type { CollectionSlug, JoinQuery } from '../../index.js'\nimport type {\n ApplyDisableErrors,\n PayloadRequest,\n PopulateType,\n SelectType,\n TransformCollectionWithSelect,\n} from '../../types/index.js'\nimport type {\n Collection,\n DataFromCollectionSlug,\n SelectFromCollectionSlug,\n} from '../config/types.js'\n\nimport executeAccess from '../../auth/executeAccess.js'\nimport { combineQueries } from '../../database/combineQueries.js'\nimport { sanitizeJoinQuery } from '../../database/sanitizeJoinQuery.js'\nimport { NotFound } from '../../errors/index.js'\nimport { afterRead } from '../../fields/hooks/afterRead/index.js'\nimport { validateQueryPaths } from '../../index.js'\nimport { killTransaction } from '../../utilities/killTransaction.js'\nimport replaceWithDraftIfAvailable from '../../versions/drafts/replaceWithDraftIfAvailable.js'\nimport { buildAfterOperation } from './utils.js'\n\nexport type Arguments = {\n collection: Collection\n currentDepth?: number\n depth?: number\n disableErrors?: boolean\n draft?: boolean\n id: number | string\n includeLockStatus?: boolean\n joins?: JoinQuery\n overrideAccess?: boolean\n populate?: PopulateType\n req: PayloadRequest\n select?: SelectType\n showHiddenFields?: boolean\n}\n\nexport const findByIDOperation = async <\n TSlug extends CollectionSlug,\n TDisableErrors extends boolean,\n TSelect extends SelectFromCollectionSlug<TSlug>,\n>(\n incomingArgs: Arguments,\n): Promise<ApplyDisableErrors<TransformCollectionWithSelect<TSlug, TSelect>, TDisableErrors>> => {\n let args = incomingArgs\n\n try {\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: 'read',\n req: args.req,\n })) || args\n }, Promise.resolve())\n\n const {\n id,\n collection: { config: collectionConfig },\n currentDepth,\n depth,\n disableErrors,\n draft: draftEnabled = false,\n includeLockStatus,\n joins,\n overrideAccess = false,\n populate,\n req: { fallbackLocale, locale, t },\n req,\n select,\n showHiddenFields,\n } = args\n\n // /////////////////////////////////////\n // Access\n // /////////////////////////////////////\n\n const accessResult = !overrideAccess\n ? await executeAccess({ id, disableErrors, req }, collectionConfig.access.read)\n : true\n\n // If errors are disabled, and access returns false, return null\n if (accessResult === false) {\n return null\n }\n\n const where = combineQueries({ id: { equals: id } }, accessResult)\n\n const sanitizedJoins = await sanitizeJoinQuery({\n collectionConfig,\n joins,\n overrideAccess,\n req,\n })\n\n const findOneArgs: FindOneArgs = {\n collection: collectionConfig.slug,\n joins: req.payloadAPI === 'GraphQL' ? false : sanitizedJoins,\n locale,\n req: {\n transactionID: req.transactionID,\n } as PayloadRequest,\n select,\n where,\n }\n\n await validateQueryPaths({\n collectionConfig,\n overrideAccess,\n req,\n where,\n })\n\n // /////////////////////////////////////\n // Find by ID\n // /////////////////////////////////////\n\n if (!findOneArgs.where.and[0].id) {\n throw new NotFound(t)\n }\n\n let result: DataFromCollectionSlug<TSlug> = await req.payload.db.findOne(findOneArgs)\n\n if (!result) {\n if (!disableErrors) {\n throw new NotFound(req.t)\n }\n\n return null\n }\n\n // /////////////////////////////////////\n // Include Lock Status if required\n // /////////////////////////////////////\n\n if (includeLockStatus && id) {\n let lockStatus = null\n\n try {\n const lockDocumentsProp = collectionConfig?.lockDocuments\n\n const lockDurationDefault = 300 // Default 5 minutes in seconds\n const lockDuration =\n typeof lockDocumentsProp === 'object' ? lockDocumentsProp.duration : lockDurationDefault\n const lockDurationInMilliseconds = lockDuration * 1000\n\n const lockedDocument = await req.payload.find({\n collection: 'payload-locked-documents',\n depth: 1,\n limit: 1,\n overrideAccess: false,\n pagination: false,\n req,\n where: {\n and: [\n {\n 'document.relationTo': {\n equals: collectionConfig.slug,\n },\n },\n {\n 'document.value': {\n equals: id,\n },\n },\n // Query where the lock is newer than the current time minus lock time\n {\n updatedAt: {\n greater_than: new Date(new Date().getTime() - lockDurationInMilliseconds),\n },\n },\n ],\n },\n })\n\n if (lockedDocument && lockedDocument.docs.length > 0) {\n lockStatus = lockedDocument.docs[0]\n }\n } catch {\n // swallow error\n }\n\n result._isLocked = !!lockStatus\n result._userEditing = lockStatus?.user?.value ?? null\n }\n\n // /////////////////////////////////////\n // Replace document with draft if available\n // /////////////////////////////////////\n\n if (collectionConfig.versions?.drafts && draftEnabled) {\n result = await replaceWithDraftIfAvailable({\n accessResult,\n doc: result,\n entity: collectionConfig,\n entityType: 'collection',\n overrideAccess,\n req,\n select,\n })\n }\n\n // /////////////////////////////////////\n // beforeRead - Collection\n // /////////////////////////////////////\n\n await collectionConfig.hooks.beforeRead.reduce(async (priorHook, hook) => {\n await priorHook\n\n result =\n (await hook({\n collection: collectionConfig,\n context: req.context,\n doc: result,\n query: findOneArgs.where,\n req,\n })) || result\n }, Promise.resolve())\n\n // /////////////////////////////////////\n // afterRead - Fields\n // /////////////////////////////////////\n\n result = await afterRead({\n collection: collectionConfig,\n context: req.context,\n currentDepth,\n depth,\n doc: result,\n draft: draftEnabled,\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 query: findOneArgs.where,\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: 'findByID',\n result,\n })\n\n // /////////////////////////////////////\n // Return results\n // /////////////////////////////////////\n\n return result as ApplyDisableErrors<\n TransformCollectionWithSelect<TSlug, TSelect>,\n TDisableErrors\n >\n } catch (error: unknown) {\n await killTransaction(args.req)\n throw error\n }\n}\n"],"names":["executeAccess","combineQueries","sanitizeJoinQuery","NotFound","afterRead","validateQueryPaths","killTransaction","replaceWithDraftIfAvailable","buildAfterOperation","findByIDOperation","incomingArgs","args","collection","config","hooks","beforeOperation","reduce","priorHook","hook","context","req","operation","Promise","resolve","id","collectionConfig","currentDepth","depth","disableErrors","draft","draftEnabled","includeLockStatus","joins","overrideAccess","populate","fallbackLocale","locale","t","select","showHiddenFields","accessResult","access","read","where","equals","sanitizedJoins","findOneArgs","slug","payloadAPI","transactionID","and","result","payload","db","findOne","lockStatus","lockDocumentsProp","lockDocuments","lockDurationDefault","lockDuration","duration","lockDurationInMilliseconds","lockedDocument","find","limit","pagination","updatedAt","greater_than","Date","getTime","docs","length","_isLocked","_userEditing","user","value","versions","drafts","doc","entity","entityType","beforeRead","query","global","error"],"mappings":"AAeA,OAAOA,mBAAmB,8BAA6B;AACvD,SAASC,cAAc,QAAQ,mCAAkC;AACjE,SAASC,iBAAiB,QAAQ,sCAAqC;AACvE,SAASC,QAAQ,QAAQ,wBAAuB;AAChD,SAASC,SAAS,QAAQ,wCAAuC;AACjE,SAASC,kBAAkB,QAAQ,iBAAgB;AACnD,SAASC,eAAe,QAAQ,qCAAoC;AACpE,OAAOC,iCAAiC,uDAAsD;AAC9F,SAASC,mBAAmB,QAAQ,aAAY;AAkBhD,OAAO,MAAMC,oBAAoB,OAK/BC;IAEA,IAAIC,OAAOD;IAEX,IAAI;QACF,wCAAwC;QACxC,+BAA+B;QAC/B,wCAAwC;QAExC,MAAMC,KAAKC,UAAU,CAACC,MAAM,CAACC,KAAK,CAACC,eAAe,CAACC,MAAM,CAAC,OAAOC,WAAWC;YAC1E,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AAG;QAC9B,MAAMgE;IACR;AACF,EAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { PayloadRequest, SelectType } from '../../types/index.js';
|
|
1
|
+
import type { PayloadRequest, PopulateType, SelectType } from '../../types/index.js';
|
|
2
2
|
import type { TypeWithVersion } from '../../versions/types.js';
|
|
3
3
|
import type { Collection, TypeWithID } from '../config/types.js';
|
|
4
4
|
export type Arguments = {
|
|
@@ -8,6 +8,7 @@ export type Arguments = {
|
|
|
8
8
|
disableErrors?: boolean;
|
|
9
9
|
id: number | string;
|
|
10
10
|
overrideAccess?: boolean;
|
|
11
|
+
populate?: PopulateType;
|
|
11
12
|
req: PayloadRequest;
|
|
12
13
|
select?: SelectType;
|
|
13
14
|
showHiddenFields?: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"findVersionByID.d.ts","sourceRoot":"","sources":["../../../src/collections/operations/findVersionByID.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;
|
|
1
|
+
{"version":3,"file":"findVersionByID.d.ts","sourceRoot":"","sources":["../../../src/collections/operations/findVersionByID.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AACpF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;AAC9D,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AAQhE,MAAM,MAAM,SAAS,GAAG;IACtB,UAAU,EAAE,UAAU,CAAA;IACtB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,EAAE,EAAE,MAAM,GAAG,MAAM,CAAA;IACnB,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,QAAQ,CAAC,EAAE,YAAY,CAAA;IACvB,GAAG,EAAE,cAAc,CAAA;IACnB,MAAM,CAAC,EAAE,UAAU,CAAA;IACnB,gBAAgB,CAAC,EAAE,OAAO,CAAA;CAC3B,CAAA;AAED,eAAO,MAAM,wBAAwB,GAAU,KAAK,SAAS,UAAU,cAC/D,SAAS,KACd,OAAO,CAAC,eAAe,CAAC,KAAK,CAAC,CAkIhC,CAAA"}
|
|
@@ -5,7 +5,7 @@ import { APIError, Forbidden, NotFound } from '../../errors/index.js';
|
|
|
5
5
|
import { afterRead } from '../../fields/hooks/afterRead/index.js';
|
|
6
6
|
import { killTransaction } from '../../utilities/killTransaction.js';
|
|
7
7
|
export const findVersionByIDOperation = async (args)=>{
|
|
8
|
-
const { id, collection: { config: collectionConfig }, currentDepth, depth, disableErrors, overrideAccess, req: { fallbackLocale, locale, payload }, req, select, showHiddenFields } = args;
|
|
8
|
+
const { id, collection: { config: collectionConfig }, currentDepth, depth, disableErrors, overrideAccess, populate, req: { fallbackLocale, locale, payload }, req, select, showHiddenFields } = args;
|
|
9
9
|
if (!id) {
|
|
10
10
|
throw new APIError('Missing ID of version.', httpStatus.BAD_REQUEST);
|
|
11
11
|
}
|
|
@@ -79,6 +79,7 @@ export const findVersionByIDOperation = async (args)=>{
|
|
|
79
79
|
global: null,
|
|
80
80
|
locale,
|
|
81
81
|
overrideAccess,
|
|
82
|
+
populate,
|
|
82
83
|
req,
|
|
83
84
|
select: typeof select?.version === 'object' ? select.version : undefined,
|
|
84
85
|
showHiddenFields
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/collections/operations/findVersionByID.ts"],"sourcesContent":["import httpStatus from 'http-status'\n\nimport type { PayloadRequest, SelectType } from '../../types/index.js'\nimport type { TypeWithVersion } from '../../versions/types.js'\nimport type { Collection, TypeWithID } from '../config/types.js'\n\nimport executeAccess from '../../auth/executeAccess.js'\nimport { combineQueries } from '../../database/combineQueries.js'\nimport { APIError, Forbidden, NotFound } from '../../errors/index.js'\nimport { afterRead } from '../../fields/hooks/afterRead/index.js'\nimport { killTransaction } from '../../utilities/killTransaction.js'\n\nexport type Arguments = {\n collection: Collection\n currentDepth?: number\n depth?: number\n disableErrors?: boolean\n id: number | string\n overrideAccess?: boolean\n req: PayloadRequest\n select?: SelectType\n showHiddenFields?: boolean\n}\n\nexport const findVersionByIDOperation = async <TData extends TypeWithID = any>(\n args: Arguments,\n): Promise<TypeWithVersion<TData>> => {\n const {\n id,\n collection: { config: collectionConfig },\n currentDepth,\n depth,\n disableErrors,\n overrideAccess,\n req: { fallbackLocale, locale, payload },\n req,\n select,\n showHiddenFields,\n } = args\n\n if (!id) {\n throw new APIError('Missing ID of version.', httpStatus.BAD_REQUEST)\n }\n\n try {\n // /////////////////////////////////////\n // Access\n // /////////////////////////////////////\n\n const accessResults = !overrideAccess\n ? await executeAccess({ id, disableErrors, req }, collectionConfig.access.readVersions)\n : true\n\n // If errors are disabled, and access returns false, return null\n if (accessResults === false) {\n return null\n }\n\n const hasWhereAccess = typeof accessResults === 'object'\n\n const fullWhere = combineQueries({ id: { equals: id } }, accessResults)\n\n // /////////////////////////////////////\n // Find by ID\n // /////////////////////////////////////\n\n const versionsQuery = await payload.db.findVersions<TData>({\n collection: collectionConfig.slug,\n limit: 1,\n locale,\n pagination: false,\n req,\n select,\n where: fullWhere,\n })\n\n const result = versionsQuery.docs[0]\n\n if (!result) {\n if (!disableErrors) {\n if (!hasWhereAccess) {\n throw new NotFound(req.t)\n }\n if (hasWhereAccess) {\n throw new Forbidden(req.t)\n }\n }\n\n return null\n }\n\n // /////////////////////////////////////\n // beforeRead - Collection\n // /////////////////////////////////////\n\n await collectionConfig.hooks.beforeRead.reduce(async (priorHook, hook) => {\n await priorHook\n\n result.version =\n (await hook({\n collection: collectionConfig,\n context: req.context,\n doc: result.version,\n query: fullWhere,\n req,\n })) || result.version\n }, Promise.resolve())\n\n // /////////////////////////////////////\n // afterRead - Fields\n // /////////////////////////////////////\n\n result.version = await afterRead({\n collection: collectionConfig,\n context: req.context,\n currentDepth,\n depth,\n doc: result.version,\n draft: undefined,\n fallbackLocale,\n global: null,\n locale,\n overrideAccess,\n req,\n select: typeof select?.version === 'object' ? select.version : undefined,\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.version =\n (await hook({\n collection: collectionConfig,\n context: req.context,\n doc: result.version,\n query: fullWhere,\n req,\n })) || result.version\n }, Promise.resolve())\n\n // /////////////////////////////////////\n // Return results\n // /////////////////////////////////////\n\n return result\n } catch (error: unknown) {\n await killTransaction(req)\n throw error\n }\n}\n"],"names":["httpStatus","executeAccess","combineQueries","APIError","Forbidden","NotFound","afterRead","killTransaction","findVersionByIDOperation","args","id","collection","config","collectionConfig","currentDepth","depth","disableErrors","overrideAccess","req","fallbackLocale","locale","payload","select","showHiddenFields","BAD_REQUEST","accessResults","access","readVersions","hasWhereAccess","fullWhere","equals","versionsQuery","db","findVersions","slug","limit","pagination","where","result","docs","t","hooks","beforeRead","reduce","priorHook","hook","version","context","doc","query","Promise","resolve","draft","undefined","global","error"],"mappings":"AAAA,OAAOA,gBAAgB,cAAa;AAMpC,OAAOC,mBAAmB,8BAA6B;AACvD,SAASC,cAAc,QAAQ,mCAAkC;AACjE,SAASC,QAAQ,EAAEC,SAAS,EAAEC,QAAQ,QAAQ,wBAAuB;AACrE,SAASC,SAAS,QAAQ,wCAAuC;AACjE,SAASC,eAAe,QAAQ,qCAAoC;
|
|
1
|
+
{"version":3,"sources":["../../../src/collections/operations/findVersionByID.ts"],"sourcesContent":["import httpStatus from 'http-status'\n\nimport type { PayloadRequest, PopulateType, SelectType } from '../../types/index.js'\nimport type { TypeWithVersion } from '../../versions/types.js'\nimport type { Collection, TypeWithID } from '../config/types.js'\n\nimport executeAccess from '../../auth/executeAccess.js'\nimport { combineQueries } from '../../database/combineQueries.js'\nimport { APIError, Forbidden, NotFound } from '../../errors/index.js'\nimport { afterRead } from '../../fields/hooks/afterRead/index.js'\nimport { killTransaction } from '../../utilities/killTransaction.js'\n\nexport type Arguments = {\n collection: Collection\n currentDepth?: number\n depth?: number\n disableErrors?: boolean\n id: number | string\n overrideAccess?: boolean\n populate?: PopulateType\n req: PayloadRequest\n select?: SelectType\n showHiddenFields?: boolean\n}\n\nexport const findVersionByIDOperation = async <TData extends TypeWithID = any>(\n args: Arguments,\n): Promise<TypeWithVersion<TData>> => {\n const {\n id,\n collection: { config: collectionConfig },\n currentDepth,\n depth,\n disableErrors,\n overrideAccess,\n populate,\n req: { fallbackLocale, locale, payload },\n req,\n select,\n showHiddenFields,\n } = args\n\n if (!id) {\n throw new APIError('Missing ID of version.', httpStatus.BAD_REQUEST)\n }\n\n try {\n // /////////////////////////////////////\n // Access\n // /////////////////////////////////////\n\n const accessResults = !overrideAccess\n ? await executeAccess({ id, disableErrors, req }, collectionConfig.access.readVersions)\n : true\n\n // If errors are disabled, and access returns false, return null\n if (accessResults === false) {\n return null\n }\n\n const hasWhereAccess = typeof accessResults === 'object'\n\n const fullWhere = combineQueries({ id: { equals: id } }, accessResults)\n\n // /////////////////////////////////////\n // Find by ID\n // /////////////////////////////////////\n\n const versionsQuery = await payload.db.findVersions<TData>({\n collection: collectionConfig.slug,\n limit: 1,\n locale,\n pagination: false,\n req,\n select,\n where: fullWhere,\n })\n\n const result = versionsQuery.docs[0]\n\n if (!result) {\n if (!disableErrors) {\n if (!hasWhereAccess) {\n throw new NotFound(req.t)\n }\n if (hasWhereAccess) {\n throw new Forbidden(req.t)\n }\n }\n\n return null\n }\n\n // /////////////////////////////////////\n // beforeRead - Collection\n // /////////////////////////////////////\n\n await collectionConfig.hooks.beforeRead.reduce(async (priorHook, hook) => {\n await priorHook\n\n result.version =\n (await hook({\n collection: collectionConfig,\n context: req.context,\n doc: result.version,\n query: fullWhere,\n req,\n })) || result.version\n }, Promise.resolve())\n\n // /////////////////////////////////////\n // afterRead - Fields\n // /////////////////////////////////////\n\n result.version = await afterRead({\n collection: collectionConfig,\n context: req.context,\n currentDepth,\n depth,\n doc: result.version,\n draft: undefined,\n fallbackLocale,\n global: null,\n locale,\n overrideAccess,\n populate,\n req,\n select: typeof select?.version === 'object' ? select.version : undefined,\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.version =\n (await hook({\n collection: collectionConfig,\n context: req.context,\n doc: result.version,\n query: fullWhere,\n req,\n })) || result.version\n }, Promise.resolve())\n\n // /////////////////////////////////////\n // Return results\n // /////////////////////////////////////\n\n return result\n } catch (error: unknown) {\n await killTransaction(req)\n throw error\n }\n}\n"],"names":["httpStatus","executeAccess","combineQueries","APIError","Forbidden","NotFound","afterRead","killTransaction","findVersionByIDOperation","args","id","collection","config","collectionConfig","currentDepth","depth","disableErrors","overrideAccess","populate","req","fallbackLocale","locale","payload","select","showHiddenFields","BAD_REQUEST","accessResults","access","readVersions","hasWhereAccess","fullWhere","equals","versionsQuery","db","findVersions","slug","limit","pagination","where","result","docs","t","hooks","beforeRead","reduce","priorHook","hook","version","context","doc","query","Promise","resolve","draft","undefined","global","error"],"mappings":"AAAA,OAAOA,gBAAgB,cAAa;AAMpC,OAAOC,mBAAmB,8BAA6B;AACvD,SAASC,cAAc,QAAQ,mCAAkC;AACjE,SAASC,QAAQ,EAAEC,SAAS,EAAEC,QAAQ,QAAQ,wBAAuB;AACrE,SAASC,SAAS,QAAQ,wCAAuC;AACjE,SAASC,eAAe,QAAQ,qCAAoC;AAepE,OAAO,MAAMC,2BAA2B,OACtCC;IAEA,MAAM,EACJC,EAAE,EACFC,YAAY,EAAEC,QAAQC,gBAAgB,EAAE,EACxCC,YAAY,EACZC,KAAK,EACLC,aAAa,EACbC,cAAc,EACdC,QAAQ,EACRC,KAAK,EAAEC,cAAc,EAAEC,MAAM,EAAEC,OAAO,EAAE,EACxCH,G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oB,OAAOQ,OAAO;QACzB,GAAGI,QAAQC,OAAO;QAElB,wCAAwC;QACxC,qBAAqB;QACrB,wCAAwC;QAExCb,OAAOQ,OAAO,GAAG,MAAMzC,UAAU;YAC/BK,YAAYE;YACZmC,SAAS7B,IAAI6B,OAAO;YACpBlC;YACAC;YACAkC,KAAKV,OAAOQ,OAAO;YACnBM,OAAOC;YACPlC;YACAmC,QAAQ;YACRlC;YACAJ;YACAC;YACAC;YACAI,QAAQ,OAAOA,QAAQwB,YAAY,WAAWxB,OAAOwB,OAAO,GAAGO;YAC/D9B;QACF;QAEA,wCAAwC;QACxC,yBAAyB;QACzB,wCAAwC;QAExC,MAAMX,iBAAiB6B,KAAK,CAACpC,SAAS,CAACsC,MAAM,CAAC,OAAOC,WAAWC;YAC9D,MAAMD;YAENN,OAAOQ,OAAO,GACZ,AAAC,MAAMD,KAAK;gBACVnC,YAAYE;gBACZmC,SAAS7B,IAAI6B,OAAO;gBACpBC,KAAKV,OAAOQ,OAAO;gBACnBG,OAAOpB;gBACPX;YACF,MAAOoB,OAAOQ,OAAO;QACzB,GAAGI,QAAQC,OAAO;QAElB,wCAAwC;QACxC,iBAAiB;QACjB,wCAAwC;QAExC,OAAOb;IACT,EAAE,OAAOiB,OAAgB;QACvB,MAAMjD,gBAAgBY;QACtB,MAAMqC;IACR;AACF,EAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { PaginatedDocs } from '../../database/types.js';
|
|
2
|
-
import type { PayloadRequest, SelectType, Sort, Where } from '../../types/index.js';
|
|
2
|
+
import type { PayloadRequest, PopulateType, SelectType, Sort, Where } from '../../types/index.js';
|
|
3
3
|
import type { TypeWithVersion } from '../../versions/types.js';
|
|
4
4
|
import type { Collection } from '../config/types.js';
|
|
5
5
|
export type Arguments = {
|
|
@@ -9,6 +9,7 @@ export type Arguments = {
|
|
|
9
9
|
overrideAccess?: boolean;
|
|
10
10
|
page?: number;
|
|
11
11
|
pagination?: boolean;
|
|
12
|
+
populate?: PopulateType;
|
|
12
13
|
req?: PayloadRequest;
|
|
13
14
|
select?: SelectType;
|
|
14
15
|
showHiddenFields?: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"findVersions.d.ts","sourceRoot":"","sources":["../../../src/collections/operations/findVersions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAA;AAC5D,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAA;
|
|
1
|
+
{"version":3,"file":"findVersions.d.ts","sourceRoot":"","sources":["../../../src/collections/operations/findVersions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAA;AAC5D,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,UAAU,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAA;AACjG,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;AAC9D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AAUpD,MAAM,MAAM,SAAS,GAAG;IACtB,UAAU,EAAE,UAAU,CAAA;IACtB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,QAAQ,CAAC,EAAE,YAAY,CAAA;IACvB,GAAG,CAAC,EAAE,cAAc,CAAA;IACpB,MAAM,CAAC,EAAE,UAAU,CAAA;IACnB,gBAAgB,CAAC,EAAE,OAAO,CAAA;IAC1B,IAAI,CAAC,EAAE,IAAI,CAAA;IACX,KAAK,CAAC,EAAE,KAAK,CAAA;CACd,CAAA;AAED,eAAO,MAAM,qBAAqB,GAAU,KAAK,SAAS,eAAe,CAAC,KAAK,CAAC,QACxE,SAAS,KACd,OAAO,CAAC,aAAa,CAAC,KAAK,CAAC,CA2J9B,CAAA"}
|
|
@@ -6,7 +6,7 @@ import { killTransaction } from '../../utilities/killTransaction.js';
|
|
|
6
6
|
import sanitizeInternalFields from '../../utilities/sanitizeInternalFields.js';
|
|
7
7
|
import { buildVersionCollectionFields } from '../../versions/buildCollectionFields.js';
|
|
8
8
|
export const findVersionsOperation = async (args)=>{
|
|
9
|
-
const { collection: { config: collectionConfig }, depth, limit, overrideAccess, page, pagination = true, req: { fallbackLocale, locale, payload }, req, select, showHiddenFields, sort, where } = args;
|
|
9
|
+
const { collection: { config: collectionConfig }, depth, limit, overrideAccess, page, pagination = true, populate, req: { fallbackLocale, locale, payload }, req, select, showHiddenFields, sort, where } = args;
|
|
10
10
|
try {
|
|
11
11
|
// /////////////////////////////////////
|
|
12
12
|
// Access
|
|
@@ -78,6 +78,7 @@ export const findVersionsOperation = async (args)=>{
|
|
|
78
78
|
global: null,
|
|
79
79
|
locale,
|
|
80
80
|
overrideAccess,
|
|
81
|
+
populate,
|
|
81
82
|
req,
|
|
82
83
|
select: typeof select?.version === 'object' ? select.version : undefined,
|
|
83
84
|
showHiddenFields
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/collections/operations/findVersions.ts"],"sourcesContent":["import type { PaginatedDocs } from '../../database/types.js'\nimport type { PayloadRequest, SelectType, Sort, Where } from '../../types/index.js'\nimport type { TypeWithVersion } from '../../versions/types.js'\nimport type { Collection } from '../config/types.js'\n\nimport executeAccess from '../../auth/executeAccess.js'\nimport { combineQueries } from '../../database/combineQueries.js'\nimport { validateQueryPaths } from '../../database/queryValidation/validateQueryPaths.js'\nimport { afterRead } from '../../fields/hooks/afterRead/index.js'\nimport { killTransaction } from '../../utilities/killTransaction.js'\nimport sanitizeInternalFields from '../../utilities/sanitizeInternalFields.js'\nimport { buildVersionCollectionFields } from '../../versions/buildCollectionFields.js'\n\nexport type Arguments = {\n collection: Collection\n depth?: number\n limit?: number\n overrideAccess?: boolean\n page?: number\n pagination?: boolean\n req?: PayloadRequest\n select?: SelectType\n showHiddenFields?: boolean\n sort?: Sort\n where?: Where\n}\n\nexport const findVersionsOperation = async <TData extends TypeWithVersion<TData>>(\n args: Arguments,\n): Promise<PaginatedDocs<TData>> => {\n const {\n collection: { config: collectionConfig },\n depth,\n limit,\n overrideAccess,\n page,\n pagination = true,\n req: { fallbackLocale, locale, payload },\n req,\n select,\n showHiddenFields,\n sort,\n where,\n } = args\n\n try {\n // /////////////////////////////////////\n // Access\n // /////////////////////////////////////\n\n let accessResults\n\n if (!overrideAccess) {\n accessResults = await executeAccess({ req }, collectionConfig.access.readVersions)\n }\n\n const versionFields = buildVersionCollectionFields(payload.config, collectionConfig)\n\n await validateQueryPaths({\n collectionConfig,\n overrideAccess,\n req,\n versionFields,\n where,\n })\n\n const fullWhere = combineQueries(where, accessResults)\n\n // /////////////////////////////////////\n // Find\n // /////////////////////////////////////\n\n const paginatedDocs = await payload.db.findVersions<TData>({\n collection: collectionConfig.slug,\n limit: limit ?? 10,\n locale,\n page: page || 1,\n pagination,\n req,\n select,\n sort,\n where: fullWhere,\n })\n\n // /////////////////////////////////////\n // beforeRead - Collection\n // /////////////////////////////////////\n\n let result = {\n ...paginatedDocs,\n docs: await Promise.all(\n paginatedDocs.docs.map(async (doc) => {\n const docRef = doc\n await collectionConfig.hooks.beforeRead.reduce(async (priorHook, hook) => {\n await priorHook\n\n docRef.version =\n (await hook({\n collection: collectionConfig,\n context: req.context,\n doc: docRef.version,\n query: fullWhere,\n req,\n })) || docRef.version\n }, Promise.resolve())\n\n return docRef\n }),\n ),\n } as PaginatedDocs<TData>\n\n // /////////////////////////////////////\n // afterRead - Fields\n // /////////////////////////////////////\n\n result = {\n ...result,\n docs: await Promise.all(\n result.docs.map(async (data) => ({\n ...data,\n version: await afterRead({\n collection: collectionConfig,\n context: req.context,\n depth,\n doc: data.version,\n draft: undefined,\n fallbackLocale,\n findMany: true,\n global: null,\n locale,\n overrideAccess,\n req,\n select: typeof select?.version === 'object' ? select.version : undefined,\n showHiddenFields,\n }),\n })),\n ),\n }\n\n // /////////////////////////////////////\n // afterRead - Collection\n // /////////////////////////////////////\n\n result = {\n ...result,\n docs: await Promise.all(\n result.docs.map(async (doc) => {\n const docRef = doc\n\n await collectionConfig.hooks.afterRead.reduce(async (priorHook, hook) => {\n await priorHook\n\n docRef.version =\n (await hook({\n collection: collectionConfig,\n context: req.context,\n doc: doc.version,\n findMany: true,\n query: fullWhere,\n req,\n })) || doc.version\n }, Promise.resolve())\n\n return docRef\n }),\n ),\n }\n\n // /////////////////////////////////////\n // Return results\n // /////////////////////////////////////\n\n result = {\n ...result,\n docs: result.docs.map((doc) => sanitizeInternalFields<TData>(doc)),\n }\n\n return result\n } catch (error: unknown) {\n await killTransaction(req)\n throw error\n }\n}\n"],"names":["executeAccess","combineQueries","validateQueryPaths","afterRead","killTransaction","sanitizeInternalFields","buildVersionCollectionFields","findVersionsOperation","args","collection","config","collectionConfig","depth","limit","overrideAccess","page","pagination","req","fallbackLocale","locale","payload","select","showHiddenFields","sort","where","accessResults","access","readVersions","versionFields","fullWhere","paginatedDocs","db","findVersions","slug","result","docs","Promise","all","map","doc","docRef","hooks","beforeRead","reduce","priorHook","hook","version","context","query","resolve","data","draft","undefined","findMany","global","error"],"mappings":"AAKA,OAAOA,mBAAmB,8BAA6B;AACvD,SAASC,cAAc,QAAQ,mCAAkC;AACjE,SAASC,kBAAkB,QAAQ,uDAAsD;AACzF,SAASC,SAAS,QAAQ,wCAAuC;AACjE,SAASC,eAAe,QAAQ,qCAAoC;AACpE,OAAOC,4BAA4B,4CAA2C;AAC9E,SAASC,4BAA4B,QAAQ,0CAAyC;
|
|
1
|
+
{"version":3,"sources":["../../../src/collections/operations/findVersions.ts"],"sourcesContent":["import type { PaginatedDocs } from '../../database/types.js'\nimport type { PayloadRequest, PopulateType, SelectType, Sort, Where } from '../../types/index.js'\nimport type { TypeWithVersion } from '../../versions/types.js'\nimport type { Collection } from '../config/types.js'\n\nimport executeAccess from '../../auth/executeAccess.js'\nimport { combineQueries } from '../../database/combineQueries.js'\nimport { validateQueryPaths } from '../../database/queryValidation/validateQueryPaths.js'\nimport { afterRead } from '../../fields/hooks/afterRead/index.js'\nimport { killTransaction } from '../../utilities/killTransaction.js'\nimport sanitizeInternalFields from '../../utilities/sanitizeInternalFields.js'\nimport { buildVersionCollectionFields } from '../../versions/buildCollectionFields.js'\n\nexport type Arguments = {\n collection: Collection\n depth?: number\n limit?: number\n overrideAccess?: boolean\n page?: number\n pagination?: boolean\n populate?: PopulateType\n req?: PayloadRequest\n select?: SelectType\n showHiddenFields?: boolean\n sort?: Sort\n where?: Where\n}\n\nexport const findVersionsOperation = async <TData extends TypeWithVersion<TData>>(\n args: Arguments,\n): Promise<PaginatedDocs<TData>> => {\n const {\n collection: { config: collectionConfig },\n depth,\n limit,\n overrideAccess,\n page,\n pagination = true,\n populate,\n req: { fallbackLocale, locale, payload },\n req,\n select,\n showHiddenFields,\n sort,\n where,\n } = args\n\n try {\n // /////////////////////////////////////\n // Access\n // /////////////////////////////////////\n\n let accessResults\n\n if (!overrideAccess) {\n accessResults = await executeAccess({ req }, collectionConfig.access.readVersions)\n }\n\n const versionFields = buildVersionCollectionFields(payload.config, collectionConfig)\n\n await validateQueryPaths({\n collectionConfig,\n overrideAccess,\n req,\n versionFields,\n where,\n })\n\n const fullWhere = combineQueries(where, accessResults)\n\n // /////////////////////////////////////\n // Find\n // /////////////////////////////////////\n\n const paginatedDocs = await payload.db.findVersions<TData>({\n collection: collectionConfig.slug,\n limit: limit ?? 10,\n locale,\n page: page || 1,\n pagination,\n req,\n select,\n sort,\n where: fullWhere,\n })\n\n // /////////////////////////////////////\n // beforeRead - Collection\n // /////////////////////////////////////\n\n let result = {\n ...paginatedDocs,\n docs: await Promise.all(\n paginatedDocs.docs.map(async (doc) => {\n const docRef = doc\n await collectionConfig.hooks.beforeRead.reduce(async (priorHook, hook) => {\n await priorHook\n\n docRef.version =\n (await hook({\n collection: collectionConfig,\n context: req.context,\n doc: docRef.version,\n query: fullWhere,\n req,\n })) || docRef.version\n }, Promise.resolve())\n\n return docRef\n }),\n ),\n } as PaginatedDocs<TData>\n\n // /////////////////////////////////////\n // afterRead - Fields\n // /////////////////////////////////////\n\n result = {\n ...result,\n docs: await Promise.all(\n result.docs.map(async (data) => ({\n ...data,\n version: await afterRead({\n collection: collectionConfig,\n context: req.context,\n depth,\n doc: data.version,\n draft: undefined,\n fallbackLocale,\n findMany: true,\n global: null,\n locale,\n overrideAccess,\n populate,\n req,\n select: typeof select?.version === 'object' ? select.version : undefined,\n showHiddenFields,\n }),\n })),\n ),\n }\n\n // /////////////////////////////////////\n // afterRead - Collection\n // /////////////////////////////////////\n\n result = {\n ...result,\n docs: await Promise.all(\n result.docs.map(async (doc) => {\n const docRef = doc\n\n await collectionConfig.hooks.afterRead.reduce(async (priorHook, hook) => {\n await priorHook\n\n docRef.version =\n (await hook({\n collection: collectionConfig,\n context: req.context,\n doc: doc.version,\n findMany: true,\n query: fullWhere,\n req,\n })) || doc.version\n }, Promise.resolve())\n\n return docRef\n }),\n ),\n }\n\n // /////////////////////////////////////\n // Return results\n // /////////////////////////////////////\n\n result = {\n ...result,\n docs: result.docs.map((doc) => sanitizeInternalFields<TData>(doc)),\n }\n\n return result\n } catch (error: unknown) {\n await killTransaction(req)\n throw error\n }\n}\n"],"names":["executeAccess","combineQueries","validateQueryPaths","afterRead","killTransaction","sanitizeInternalFields","buildVersionCollectionFields","findVersionsOperation","args","collection","config","collectionConfig","depth","limit","overrideAccess","page","pagination","populate","req","fallbackLocale","locale","payload","select","showHiddenFields","sort","where","accessResults","access","readVersions","versionFields","fullWhere","paginatedDocs","db","findVersions","slug","result","docs","Promise","all","map","doc","docRef","hooks","beforeRead","reduce","priorHook","hook","version","context","query","resolve","data","draft","undefined","findMany","global","error"],"mappings":"AAKA,OAAOA,mBAAmB,8BAA6B;AACv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;wBACVL,OAAOnB;wBACPZ;oBACF,MAAOsB,IAAIO,OAAO;gBACtB,GAAGV,QAAQa,OAAO;gBAElB,OAAOT;YACT;QAEJ;QAEA,wCAAwC;QACxC,iBAAiB;QACjB,wCAAwC;QAExCN,SAAS;YACP,GAAGA,MAAM;YACTC,MAAMD,OAAOC,IAAI,CAACG,GAAG,CAAC,CAACC,MAAQnC,uBAA8BmC;QAC/D;QAEA,OAAOL;IACT,EAAE,OAAOqB,OAAgB;QACvB,MAAMpD,gBAAgBc;QACtB,MAAMsC;IACR;AACF,EAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { CollectionSlug, Payload, TypedLocale } from '../../../index.js';
|
|
2
|
-
import type { Document, PayloadRequest,
|
|
1
|
+
import type { CollectionSlug, Payload, RequestContext, TypedLocale } from '../../../index.js';
|
|
2
|
+
import type { Document, PayloadRequest, Where } from '../../../types/index.js';
|
|
3
3
|
export type Options<TSlug extends CollectionSlug> = {
|
|
4
4
|
collection: TSlug;
|
|
5
5
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"count.d.ts","sourceRoot":"","sources":["../../../../src/collections/operations/local/count.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;
|
|
1
|
+
{"version":3,"file":"count.d.ts","sourceRoot":"","sources":["../../../../src/collections/operations/local/count.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC7F,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAA;AAM9E,MAAM,MAAM,OAAO,CAAC,KAAK,SAAS,cAAc,IAAI;IAClD,UAAU,EAAE,KAAK,CAAA;IACjB;;OAEG;IACH,OAAO,CAAC,EAAE,cAAc,CAAA;IACxB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,MAAM,CAAC,EAAE,WAAW,CAAA;IACpB,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,GAAG,CAAC,EAAE,cAAc,CAAA;IACpB,IAAI,CAAC,EAAE,QAAQ,CAAA;IACf,KAAK,CAAC,EAAE,KAAK,CAAA;CACd,CAAA;AAED,wBAA8B,UAAU,CAAC,KAAK,SAAS,cAAc,EACnE,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC,GACtB,OAAO,CAAC;IAAE,SAAS,EAAE,MAAM,CAAA;CAAE,CAAC,CAkBhC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/collections/operations/local/count.ts"],"sourcesContent":["import type { CollectionSlug, Payload, TypedLocale } from '../../../index.js'\nimport type { Document, PayloadRequest,
|
|
1
|
+
{"version":3,"sources":["../../../../src/collections/operations/local/count.ts"],"sourcesContent":["import type { CollectionSlug, Payload, RequestContext, TypedLocale } from '../../../index.js'\nimport type { Document, PayloadRequest, Where } from '../../../types/index.js'\n\nimport { APIError } from '../../../errors/index.js'\nimport { createLocalReq } from '../../../utilities/createLocalReq.js'\nimport { countOperation } from '../count.js'\n\nexport type Options<TSlug extends CollectionSlug> = {\n collection: TSlug\n /**\n * context, which will then be passed to req.context, which can be read by hooks\n */\n context?: RequestContext\n depth?: number\n disableErrors?: boolean\n locale?: TypedLocale\n overrideAccess?: boolean\n req?: PayloadRequest\n user?: Document\n where?: Where\n}\n\nexport default async function countLocal<TSlug extends CollectionSlug>(\n payload: Payload,\n options: Options<TSlug>,\n): Promise<{ totalDocs: number }> {\n const { collection: collectionSlug, disableErrors, overrideAccess = true, where } = 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. Count Operation.`,\n )\n }\n\n return countOperation<TSlug>({\n collection,\n disableErrors,\n overrideAccess,\n req: await createLocalReq(options, payload),\n where,\n })\n}\n"],"names":["APIError","createLocalReq","countOperation","countLocal","payload","options","collection","collectionSlug","disableErrors","overrideAccess","where","collections","String","req"],"mappings":"AAGA,SAASA,QAAQ,QAAQ,2BAA0B;AACnD,SAASC,cAAc,QAAQ,uCAAsC;AACrE,SAASC,cAAc,QAAQ,cAAa;AAiB5C,eAAe,eAAeC,WAC5BC,OAAgB,EAChBC,OAAuB;IAEvB,MAAM,EAAEC,YAAYC,cAAc,EAAEC,aAAa,EAAEC,iBAAiB,IAAI,EAAEC,KAAK,EAAE,GAAGL;IAEpF,MAAMC,aAAaF,QAAQO,WAAW,CAACJ,eAAe;IAEtD,IAAI,CAACD,YAAY;QACf,MAAM,IAAIN,SACR,CAAC,yBAAyB,EAAEY,OAAOL,gBAAgB,iCAAiC,CAAC;IAEzF;IAEA,OAAOL,eAAsB;QAC3BI;QACAE;QACAC;QACAI,KAAK,MAAMZ,eAAeI,SAASD;QACnCM;IACF;AACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { CollectionSlug, Payload, TypedLocale } from '../../../index.js';
|
|
2
|
-
import type { Document, PayloadRequest,
|
|
1
|
+
import type { CollectionSlug, Payload, RequestContext, TypedLocale } from '../../../index.js';
|
|
2
|
+
import type { Document, PayloadRequest, PopulateType, SelectType, TransformCollectionWithSelect } from '../../../types/index.js';
|
|
3
3
|
import type { File } from '../../../uploads/types.js';
|
|
4
4
|
import type { RequiredDataFromCollectionSlug, SelectFromCollectionSlug } from '../../config/types.js';
|
|
5
5
|
export type Options<TSlug extends CollectionSlug, TSelect extends SelectType> = {
|
|
@@ -19,6 +19,7 @@ export type Options<TSlug extends CollectionSlug, TSelect extends SelectType> =
|
|
|
19
19
|
locale?: TypedLocale;
|
|
20
20
|
overrideAccess?: boolean;
|
|
21
21
|
overwriteExistingFiles?: boolean;
|
|
22
|
+
populate?: PopulateType;
|
|
22
23
|
req?: PayloadRequest;
|
|
23
24
|
select?: TSelect;
|
|
24
25
|
showHiddenFields?: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../../../src/collections/operations/local/create.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;
|
|
1
|
+
{"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../../../src/collections/operations/local/create.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC7F,OAAO,KAAK,EACV,QAAQ,EACR,cAAc,EACd,YAAY,EACZ,UAAU,EACV,6BAA6B,EAC9B,MAAM,yBAAyB,CAAA;AAChC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,2BAA2B,CAAA;AACrD,OAAO,KAAK,EACV,8BAA8B,EAC9B,wBAAwB,EACzB,MAAM,uBAAuB,CAAA;AAO9B,MAAM,MAAM,OAAO,CAAC,KAAK,SAAS,cAAc,EAAE,OAAO,SAAS,UAAU,IAAI;IAC9E,UAAU,EAAE,KAAK,CAAA;IACjB;;OAEG;IACH,OAAO,CAAC,EAAE,cAAc,CAAA;IACxB,IAAI,EAAE,8BAA8B,CAAC,KAAK,CAAC,CAAA;IAC3C,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,kBAAkB,CAAC,EAAE,OAAO,CAAA;IAC5B,wBAAwB,CAAC,EAAE,OAAO,CAAA;IAClC,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,cAAc,CAAC,EAAE,WAAW,CAAA;IAC5B,IAAI,CAAC,EAAE,IAAI,CAAA;IACX,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,MAAM,CAAC,EAAE,WAAW,CAAA;IACpB,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,sBAAsB,CAAC,EAAE,OAAO,CAAA;IAChC,QAAQ,CAAC,EAAE,YAAY,CAAA;IACvB,GAAG,CAAC,EAAE,cAAc,CAAA;IACpB,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,gBAAgB,CAAC,EAAE,OAAO,CAAA;IAC1B,IAAI,CAAC,EAAE,QAAQ,CAAA;CAChB,CAAA;AAGD,wBAA8B,WAAW,CACvC,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,CAyCxD"}
|
|
@@ -4,7 +4,7 @@ import { createLocalReq } from '../../../utilities/createLocalReq.js';
|
|
|
4
4
|
import { createOperation } from '../create.js';
|
|
5
5
|
// eslint-disable-next-line no-restricted-exports
|
|
6
6
|
export default async function createLocal(payload, options) {
|
|
7
|
-
const { collection: collectionSlug, data, depth, disableTransaction, disableVerificationEmail, draft, file, filePath, overrideAccess = true, overwriteExistingFiles = false, select, showHiddenFields } = options;
|
|
7
|
+
const { collection: collectionSlug, data, depth, disableTransaction, disableVerificationEmail, draft, file, filePath, overrideAccess = true, overwriteExistingFiles = false, populate, select, showHiddenFields } = options;
|
|
8
8
|
const collection = payload.collections[collectionSlug];
|
|
9
9
|
if (!collection) {
|
|
10
10
|
throw new APIError(`The collection with slug ${String(collectionSlug)} can't be found. Create Operation.`);
|
|
@@ -20,6 +20,7 @@ export default async function createLocal(payload, options) {
|
|
|
20
20
|
draft,
|
|
21
21
|
overrideAccess,
|
|
22
22
|
overwriteExistingFiles,
|
|
23
|
+
populate,
|
|
23
24
|
req,
|
|
24
25
|
select,
|
|
25
26
|
showHiddenFields
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/collections/operations/local/create.ts"],"sourcesContent":["import type { CollectionSlug, Payload, TypedLocale } from '../../../index.js'\nimport type {\n Document,\n PayloadRequest,\n
|
|
1
|
+
{"version":3,"sources":["../../../../src/collections/operations/local/create.ts"],"sourcesContent":["import type { CollectionSlug, Payload, RequestContext, TypedLocale } from '../../../index.js'\nimport type {\n Document,\n PayloadRequest,\n PopulateType,\n SelectType,\n TransformCollectionWithSelect,\n} from '../../../types/index.js'\nimport type { File } from '../../../uploads/types.js'\nimport type {\n RequiredDataFromCollectionSlug,\n SelectFromCollectionSlug,\n} from '../../config/types.js'\n\nimport { APIError } from '../../../errors/index.js'\nimport { getFileByPath } from '../../../uploads/getFileByPath.js'\nimport { createLocalReq } from '../../../utilities/createLocalReq.js'\nimport { createOperation } from '../create.js'\n\nexport type Options<TSlug extends CollectionSlug, TSelect extends SelectType> = {\n collection: TSlug\n /**\n * context, which will then be passed to req.context, which can be read by hooks\n */\n context?: RequestContext\n data: RequiredDataFromCollectionSlug<TSlug>\n depth?: number\n disableTransaction?: boolean\n disableVerificationEmail?: boolean\n draft?: boolean\n fallbackLocale?: TypedLocale\n file?: File\n filePath?: string\n locale?: TypedLocale\n overrideAccess?: boolean\n overwriteExistingFiles?: boolean\n populate?: PopulateType\n req?: PayloadRequest\n select?: TSelect\n showHiddenFields?: boolean\n user?: Document\n}\n\n// eslint-disable-next-line no-restricted-exports\nexport default async function createLocal<\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 collection: collectionSlug,\n data,\n depth,\n disableTransaction,\n disableVerificationEmail,\n draft,\n file,\n filePath,\n overrideAccess = true,\n overwriteExistingFiles = false,\n populate,\n select,\n showHiddenFields,\n } = options\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. Create Operation.`,\n )\n }\n\n const req = await createLocalReq(options, payload)\n req.file = file ?? (await getFileByPath(filePath))\n\n return createOperation<TSlug, TSelect>({\n collection,\n data,\n depth,\n disableTransaction,\n disableVerificationEmail,\n draft,\n overrideAccess,\n overwriteExistingFiles,\n populate,\n req,\n select,\n showHiddenFields,\n })\n}\n"],"names":["APIError","getFileByPath","createLocalReq","createOperation","createLocal","payload","options","collection","collectionSlug","data","depth","disableTransaction","disableVerificationEmail","draft","file","filePath","overrideAccess","overwriteExistingFiles","populate","select","showHiddenFields","collections","String","req"],"mappings":"AAcA,SAASA,QAAQ,QAAQ,2BAA0B;AACnD,SAASC,aAAa,QAAQ,oCAAmC;AACjE,SAASC,cAAc,QAAQ,uCAAsC;AACrE,SAASC,eAAe,QAAQ,eAAc;AA0B9C,iDAAiD;AACjD,eAAe,eAAeC,YAI5BC,OAAgB,EAChBC,OAAgC;IAEhC,MAAM,EACJC,YAAYC,cAAc,EAC1BC,IAAI,EACJC,KAAK,EACLC,kBAAkB,EAClBC,wBAAwB,EACxBC,KAAK,EACLC,IAAI,EACJC,QAAQ,EACRC,iBAAiB,IAAI,EACrBC,yBAAyB,KAAK,EAC9BC,QAAQ,EACRC,MAAM,EACNC,gBAAgB,EACjB,GAAGd;IACJ,MAAMC,aAAaF,QAAQgB,WAAW,CAACb,eAAe;IAEtD,IAAI,CAACD,YAAY;QACf,MAAM,IAAIP,SACR,CAAC,yBAAyB,EAAEsB,OAAOd,gBAAgB,kCAAkC,CAAC;IAE1F;IAEA,MAAMe,MAAM,MAAMrB,eAAeI,SAASD;IAC1CkB,IAAIT,IAAI,GAAGA,QAAS,MAAMb,cAAcc;IAExC,OAAOZ,gBAAgC;QACrCI;QACAE;QACAC;QACAC;QACAC;QACAC;QACAG;QACAC;QACAC;QACAK;QACAJ;QACAC;IACF;AACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { CollectionSlug, Payload, TypedLocale } from '../../../index.js';
|
|
2
|
-
import type { Document, PayloadRequest,
|
|
1
|
+
import type { CollectionSlug, Payload, RequestContext, TypedLocale } from '../../../index.js';
|
|
2
|
+
import type { Document, PayloadRequest, PopulateType, SelectType, TransformCollectionWithSelect, Where } from '../../../types/index.js';
|
|
3
3
|
import type { BulkOperationResult, SelectFromCollectionSlug } from '../../config/types.js';
|
|
4
4
|
export type BaseOptions<TSlug extends CollectionSlug, TSelect extends SelectType> = {
|
|
5
5
|
collection: TSlug;
|
|
@@ -13,6 +13,7 @@ export type BaseOptions<TSlug extends CollectionSlug, TSelect extends SelectType
|
|
|
13
13
|
locale?: TypedLocale;
|
|
14
14
|
overrideAccess?: boolean;
|
|
15
15
|
overrideLock?: boolean;
|
|
16
|
+
populate?: PopulateType;
|
|
16
17
|
req?: PayloadRequest;
|
|
17
18
|
select?: TSelect;
|
|
18
19
|
showHiddenFields?: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"delete.d.ts","sourceRoot":"","sources":["../../../../src/collections/operations/local/delete.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;
|
|
1
|
+
{"version":3,"file":"delete.d.ts","sourceRoot":"","sources":["../../../../src/collections/operations/local/delete.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC7F,OAAO,KAAK,EACV,QAAQ,EACR,cAAc,EACd,YAAY,EACZ,UAAU,EACV,6BAA6B,EAC7B,KAAK,EACN,MAAM,yBAAyB,CAAA;AAChC,OAAO,KAAK,EAAE,mBAAmB,EAAE,wBAAwB,EAAE,MAAM,uBAAuB,CAAA;AAO1F,MAAM,MAAM,WAAW,CAAC,KAAK,SAAS,cAAc,EAAE,OAAO,SAAS,UAAU,IAAI;IAClF,UAAU,EAAE,KAAK,CAAA;IACjB;;OAEG;IACH,OAAO,CAAC,EAAE,cAAc,CAAA;IACxB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,kBAAkB,CAAC,EAAE,OAAO,CAA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e,WAAW,CACxB,KAAK,SAAS,cAAc,EAC5B,OAAO,SAAS,wBAAwB,CAAC,KAAK,CAAC,EAE/C,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,WAAW,CAAC,KAAK,EAAE,OAAO,CAAC,GACnC,OAAO,CAAC,mBAAmB,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,CAAA;AAC/C,iBAAe,WAAW,CACxB,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,mBAAmB,CAAC,KAAK,EAAE,OAAO,CAAC,GAAG,6BAA6B,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,CAAA;AAiD/F,eAAe,WAAW,CAAA"}
|
|
@@ -3,7 +3,7 @@ import { createLocalReq } from '../../../utilities/createLocalReq.js';
|
|
|
3
3
|
import { deleteOperation } from '../delete.js';
|
|
4
4
|
import { deleteByIDOperation } from '../deleteByID.js';
|
|
5
5
|
async function deleteLocal(payload, options) {
|
|
6
|
-
const { id, collection: collectionSlug, depth, disableTransaction, overrideAccess = true, overrideLock, select, showHiddenFields, where } = options;
|
|
6
|
+
const { id, collection: collectionSlug, depth, disableTransaction, overrideAccess = true, overrideLock, populate, select, showHiddenFields, where } = options;
|
|
7
7
|
const collection = payload.collections[collectionSlug];
|
|
8
8
|
if (!collection) {
|
|
9
9
|
throw new APIError(`The collection with slug ${String(collectionSlug)} can't be found. Delete Operation.`);
|
|
@@ -15,6 +15,7 @@ async function deleteLocal(payload, options) {
|
|
|
15
15
|
disableTransaction,
|
|
16
16
|
overrideAccess,
|
|
17
17
|
overrideLock,
|
|
18
|
+
populate,
|
|
18
19
|
req: await createLocalReq(options, payload),
|
|
19
20
|
select,
|
|
20
21
|
showHiddenFields,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/collections/operations/local/delete.ts"],"sourcesContent":["import type { CollectionSlug, Payload, TypedLocale } from '../../../index.js'\nimport type {\n Document,\n PayloadRequest,\n
|
|
1
|
+
{"version":3,"sources":["../../../../src/collections/operations/local/delete.ts"],"sourcesContent":["import type { CollectionSlug, Payload, RequestContext, TypedLocale } from '../../../index.js'\nimport type {\n Document,\n PayloadRequest,\n PopulateType,\n SelectType,\n TransformCollectionWithSelect,\n Where,\n} from '../../../types/index.js'\nimport type { BulkOperationResult, SelectFromCollectionSlug } from '../../config/types.js'\n\nimport { APIError } from '../../../errors/index.js'\nimport { createLocalReq } from '../../../utilities/createLocalReq.js'\nimport { deleteOperation } from '../delete.js'\nimport { deleteByIDOperation } from '../deleteByID.js'\n\nexport type BaseOptions<TSlug extends CollectionSlug, TSelect extends SelectType> = {\n collection: TSlug\n /**\n * context, which will then be passed to req.context, which can be read by hooks\n */\n context?: RequestContext\n depth?: number\n disableTransaction?: boolean\n fallbackLocale?: TypedLocale\n locale?: TypedLocale\n overrideAccess?: boolean\n overrideLock?: boolean\n populate?: PopulateType\n req?: PayloadRequest\n select?: TSelect\n showHiddenFields?: boolean\n user?: Document\n}\n\nexport type ByIDOptions<\n TSlug extends CollectionSlug,\n TSelect extends SelectFromCollectionSlug<TSlug>,\n> = {\n id: number | string\n where?: never\n} & BaseOptions<TSlug, TSelect>\n\nexport type ManyOptions<\n TSlug extends CollectionSlug,\n TSelect extends SelectFromCollectionSlug<TSlug>,\n> = {\n id?: never\n where: Where\n} & BaseOptions<TSlug, TSelect>\n\nexport type Options<\n TSlug extends CollectionSlug,\n TSelect extends SelectFromCollectionSlug<TSlug>,\n> = ByIDOptions<TSlug, TSelect> | ManyOptions<TSlug, TSelect>\n\nasync function deleteLocal<\n TSlug extends CollectionSlug,\n TSelect extends SelectFromCollectionSlug<TSlug>,\n>(\n payload: Payload,\n options: ByIDOptions<TSlug, TSelect>,\n): Promise<TransformCollectionWithSelect<TSlug, TSelect>>\nasync function deleteLocal<\n TSlug extends CollectionSlug,\n TSelect extends SelectFromCollectionSlug<TSlug>,\n>(\n payload: Payload,\n options: ManyOptions<TSlug, TSelect>,\n): Promise<BulkOperationResult<TSlug, TSelect>>\nasync function deleteLocal<\n TSlug extends CollectionSlug,\n TSelect extends SelectFromCollectionSlug<TSlug>,\n>(\n payload: Payload,\n options: Options<TSlug, TSelect>,\n): Promise<BulkOperationResult<TSlug, TSelect> | TransformCollectionWithSelect<TSlug, TSelect>>\nasync function deleteLocal<\n TSlug extends CollectionSlug,\n TSelect extends SelectFromCollectionSlug<TSlug>,\n>(\n payload: Payload,\n options: Options<TSlug, TSelect>,\n): Promise<BulkOperationResult<TSlug, TSelect> | TransformCollectionWithSelect<TSlug, TSelect>> {\n const {\n id,\n collection: collectionSlug,\n depth,\n disableTransaction,\n overrideAccess = true,\n overrideLock,\n populate,\n select,\n showHiddenFields,\n where,\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. Delete Operation.`,\n )\n }\n\n const args = {\n id,\n collection,\n depth,\n disableTransaction,\n overrideAccess,\n overrideLock,\n populate,\n req: await createLocalReq(options, payload),\n select,\n showHiddenFields,\n where,\n }\n\n if (options.id) {\n return deleteByIDOperation<TSlug, TSelect>(args)\n }\n return deleteOperation<TSlug, TSelect>(args)\n}\n\nexport default deleteLocal\n"],"names":["APIError","createLocalReq","deleteOperation","deleteByIDOperation","deleteLocal","payload","options","id","collection","collectionSlug","depth","disableTransaction","overrideAccess","overrideLock","populate","select","showHiddenFields","where","collections","String","args","req"],"mappings":"AAWA,SAASA,QAAQ,QAAQ,2BAA0B;AACnD,SAASC,cAAc,QAAQ,uCAAsC;AACrE,SAASC,eAAe,QAAQ,eAAc;AAC9C,SAASC,mBAAmB,QAAQ,mBAAkB;AA+DtD,eAAeC,YAIbC,OAAgB,EAChBC,OAAgC;IAEhC,MAAM,EACJC,EAAE,EACFC,YAAYC,cAAc,EAC1BC,KAAK,EACLC,kBAAkB,EAClBC,iBAAiB,IAAI,EACrBC,YAAY,EACZC,QAAQ,EACRC,MAAM,EACNC,gBAAgB,EAChBC,KAAK,EACN,GAAGX;IAEJ,MAAME,aAAaH,QAAQa,WAAW,CAACT,eAAe;IAEtD,IAAI,CAACD,YAAY;QACf,MAAM,IAAIR,SACR,CAAC,yBAAyB,EAAEmB,OAAOV,gBAAgB,kCAAkC,CAAC;IAE1F;IAEA,MAAMW,OAAO;QACXb;QACAC;QACAE;QACAC;QACAC;QACAC;QACAC;QACAO,KAAK,MAAMpB,eAAeK,SAASD;QACnCU;QACAC;QACAC;IACF;IAEA,IAAIX,QAAQC,EAAE,EAAE;QACd,OAAOJ,oBAAoCiB;IAC7C;IACA,OAAOlB,gBAAgCkB;AACzC;AAEA,eAAehB,YAAW"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { CollectionSlug, TypedLocale } from '../../..//index.js';
|
|
2
|
-
import type { Payload } from '../../../index.js';
|
|
3
|
-
import type { Document, PayloadRequest,
|
|
2
|
+
import type { Payload, RequestContext } from '../../../index.js';
|
|
3
|
+
import type { Document, PayloadRequest, PopulateType, SelectType, TransformCollectionWithSelect } from '../../../types/index.js';
|
|
4
4
|
import type { SelectFromCollectionSlug } from '../../config/types.js';
|
|
5
5
|
export type Options<TSlug extends CollectionSlug, TSelect extends SelectType> = {
|
|
6
6
|
collection: TSlug;
|
|
@@ -15,6 +15,7 @@ export type Options<TSlug extends CollectionSlug, TSelect extends SelectType> =
|
|
|
15
15
|
id: number | string;
|
|
16
16
|
locale?: TypedLocale;
|
|
17
17
|
overrideAccess?: boolean;
|
|
18
|
+
populate?: PopulateType;
|
|
18
19
|
req?: PayloadRequest;
|
|
19
20
|
select?: TSelect;
|
|
20
21
|
showHiddenFields?: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"duplicate.d.ts","sourceRoot":"","sources":["../../../../src/collections/operations/local/duplicate.ts"],"names":[],"mappings":"AAAA,OAAO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AAE,OAAO,EAChB,OAAO,EAAE,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,GAC/B,OAAO,CAAC,6BAA6B,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,CAyCxD"}
|
|
@@ -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 duplicate(payload, options) {
|
|
5
|
-
const { id, collection: collectionSlug, depth, disableTransaction, draft, overrideAccess = true, select, showHiddenFields } = options;
|
|
5
|
+
const { id, collection: collectionSlug, depth, disableTransaction, draft, overrideAccess = true, populate, select, 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.`);
|
|
@@ -18,6 +18,7 @@ export async function duplicate(payload, options) {
|
|
|
18
18
|
disableTransaction,
|
|
19
19
|
draft,
|
|
20
20
|
overrideAccess,
|
|
21
|
+
populate,
|
|
21
22
|
req,
|
|
22
23
|
select,
|
|
23
24
|
showHiddenFields
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/collections/operations/local/duplicate.ts"],"sourcesContent":["import type { CollectionSlug, TypedLocale } from '../../..//index.js'\nimport type { Payload } from '../../../index.js'\nimport type {\n Document,\n PayloadRequest,\n
|
|
1
|
+
{"version":3,"sources":["../../../../src/collections/operations/local/duplicate.ts"],"sourcesContent":["import 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 { SelectFromCollectionSlug } 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 collection: TSlug\n /**\n * context, which will then be passed to req.context, which can be read by hooks\n */\n context?: RequestContext\n depth?: number\n disableTransaction?: boolean\n draft?: boolean\n fallbackLocale?: TypedLocale\n id: number | string\n locale?: TypedLocale\n overrideAccess?: boolean\n populate?: PopulateType\n req?: PayloadRequest\n select?: TSelect\n showHiddenFields?: boolean\n user?: Document\n}\n\nexport async function duplicate<\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 depth,\n disableTransaction,\n draft,\n overrideAccess = true,\n populate,\n select,\n showHiddenFields,\n } = options\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, payload)\n\n return duplicateOperation<TSlug, TSelect>({\n id,\n collection,\n depth,\n disableTransaction,\n draft,\n overrideAccess,\n populate,\n req,\n select,\n showHiddenFields,\n })\n}\n"],"names":["APIError","createLocalReq","duplicateOperation","duplicate","payload","options","id","collection","collectionSlug","depth","disableTransaction","draft","overrideAccess","populate","select","showHiddenFields","collections","String","config","disableDuplicate","req"],"mappings":"AAWA,SAASA,QAAQ,QAAQ,2BAA0B;AACnD,SAASC,cAAc,QAAQ,uCAAsC;AACrE,SAASC,kBAAkB,QAAQ,kBAAiB;AAsBpD,OAAO,eAAeC,UAIpBC,OAAgB,EAChBC,OAAgC;IAEhC,MAAM,EACJC,EAAE,EACFC,YAAYC,cAAc,EAC1BC,KAAK,EACLC,kBAAkB,EAClBC,KAAK,EACLC,iBAAiB,IAAI,EACrBC,QAAQ,EACRC,MAAM,EACNC,gBAAgB,EACjB,GAAGV;IACJ,MAAME,aAAaH,QAAQY,WAAW,CAACR,eAAe;IAEtD,IAAI,CAACD,YAAY;QACf,MAAM,IAAIP,SACR,CAAC,yBAAyB,EAAEiB,OAAOT,gBAAgB,qCAAqC,CAAC;IAE7F;IAEA,IAAID,WAAWW,MAAM,CAACC,gBAAgB,KAAK,MAAM;QAC/C,MAAM,IAAInB,SACR,CAAC,yBAAyB,EAAEiB,OAAOT,gBAAgB,sBAAsB,CAAC,EAC1E;IAEJ;IAEA,MAAMY,MAAM,MAAMnB,eAAeI,SAASD;IAE1C,OAAOF,mBAAmC;QACxCI;QACAC;QACAE;QACAC;QACAC;QACAC;QACAC;QACAO;QACAN;QACAC;IACF;AACF"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { PaginatedDocs } from '../../../database/types.js';
|
|
2
|
-
import type { CollectionSlug, JoinQuery, Payload, TypedLocale } from '../../../index.js';
|
|
3
|
-
import type { Document, PayloadRequest,
|
|
2
|
+
import type { CollectionSlug, JoinQuery, Payload, RequestContext, TypedLocale } from '../../../index.js';
|
|
3
|
+
import type { Document, PayloadRequest, PopulateType, SelectType, Sort, TransformCollectionWithSelect, Where } from '../../../types/index.js';
|
|
4
4
|
import type { SelectFromCollectionSlug } from '../../config/types.js';
|
|
5
5
|
export type Options<TSlug extends CollectionSlug, TSelect extends SelectType> = {
|
|
6
6
|
collection: TSlug;
|
|
@@ -14,12 +14,13 @@ export type Options<TSlug extends CollectionSlug, TSelect extends SelectType> =
|
|
|
14
14
|
draft?: boolean;
|
|
15
15
|
fallbackLocale?: TypedLocale;
|
|
16
16
|
includeLockStatus?: boolean;
|
|
17
|
-
joins?: JoinQuery
|
|
17
|
+
joins?: JoinQuery<TSlug>;
|
|
18
18
|
limit?: number;
|
|
19
19
|
locale?: 'all' | TypedLocale;
|
|
20
20
|
overrideAccess?: boolean;
|
|
21
21
|
page?: number;
|
|
22
22
|
pagination?: boolean;
|
|
23
|
+
populate?: PopulateType;
|
|
23
24
|
req?: PayloadRequest;
|
|
24
25
|
select?: TSelect;
|
|
25
26
|
showHiddenFields?: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"find.d.ts","sourceRoot":"","sources":["../../../../src/collections/operations/local/find.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAC/D,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"find.d.ts","sourceRoot":"","sources":["../../../../src/collections/operations/local/find.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAC/D,OAAO,KAAK,EACV,cAAc,EACd,SAAS,EACT,OAAO,EACP,cAAc,EACd,WAAW,EACZ,MAAM,mBAAmB,CAAA;AAC1B,OAAO,KAAK,EACV,QAAQ,EACR,cAAc,EACd,YAAY,EACZ,UAAU,EACV,IAAI,EACJ,6BAA6B,EAC7B,KAAK,EACN,MAAM,yBAAyB,CAAA;AAChC,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,uBAAuB,CAAA;AAMrE,MAAM,MAAM,OAAO,CAAC,KAAK,SAAS,cAAc,EAAE,OAAO,SAAS,UAAU,IAAI;IAC9E,UAAU,EAAE,KAAK,CAAA;IACjB;;OAEG;IACH,OAAO,CAAC,EAAE,cAAc,CAAA;IACxB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,cAAc,CAAC,EAAE,WAAW,CAAA;IAC5B,iBAAiB,CAAC,EAAE,OAAO,CAAA;IAC3B,KAAK,CAAC,EAAE,SAAS,CAAC,KAAK,CAAC,CAAA;IACxB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,MAAM,CAAC,EAAE,KAAK,GAAG,WAAW,CAAA;IAC5B,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,QAAQ,CAAC,EAAE,YAAY,CAAA;IACvB,GAAG,CAAC,EAAE,cAAc,CAAA;IACpB,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,gBAAgB,CAAC,EAAE,OAAO,CAAA;IAC1B,IAAI,CAAC,EAAE,IAAI,CAAA;IACX,IAAI,CAAC,EAAE,QAAQ,CAAA;IACf,KAAK,CAAC,EAAE,KAAK,CAAA;CACd,CAAA;AAED,wBAAsB,SAAS,CAC7B,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,aAAa,CAAC,6BAA6B,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC,CA8CvE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/collections/operations/local/find.ts"],"sourcesContent":["import type { PaginatedDocs } from '../../../database/types.js'\nimport type {
|
|
1
|
+
{"version":3,"sources":["../../../../src/collections/operations/local/find.ts"],"sourcesContent":["import type { PaginatedDocs } from '../../../database/types.js'\nimport type {\n CollectionSlug,\n JoinQuery,\n Payload,\n RequestContext,\n TypedLocale,\n} from '../../../index.js'\nimport type {\n Document,\n PayloadRequest,\n PopulateType,\n SelectType,\n Sort,\n TransformCollectionWithSelect,\n Where,\n} from '../../../types/index.js'\nimport type { SelectFromCollectionSlug } from '../../config/types.js'\n\nimport { APIError } from '../../../errors/index.js'\nimport { createLocalReq } from '../../../utilities/createLocalReq.js'\nimport { findOperation } from '../find.js'\n\nexport type Options<TSlug extends CollectionSlug, TSelect extends SelectType> = {\n collection: TSlug\n /**\n * context, which will then be passed to req.context, which can be read by hooks\n */\n context?: RequestContext\n currentDepth?: number\n depth?: number\n disableErrors?: boolean\n draft?: boolean\n fallbackLocale?: TypedLocale\n includeLockStatus?: boolean\n joins?: JoinQuery<TSlug>\n limit?: number\n locale?: 'all' | TypedLocale\n overrideAccess?: boolean\n page?: number\n pagination?: boolean\n populate?: PopulateType\n req?: PayloadRequest\n select?: TSelect\n showHiddenFields?: boolean\n sort?: Sort\n user?: Document\n where?: Where\n}\n\nexport async function findLocal<\n TSlug extends CollectionSlug,\n TSelect extends SelectFromCollectionSlug<TSlug>,\n>(\n payload: Payload,\n options: Options<TSlug, TSelect>,\n): Promise<PaginatedDocs<TransformCollectionWithSelect<TSlug, TSelect>>> {\n const {\n collection: collectionSlug,\n currentDepth,\n depth,\n disableErrors,\n draft = false,\n includeLockStatus,\n joins,\n limit,\n overrideAccess = true,\n page,\n pagination = true,\n select,\n // select,\n showHiddenFields,\n sort,\n where,\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. Find Operation.`,\n )\n }\n\n return findOperation<TSlug, TSelect>({\n collection,\n currentDepth,\n depth,\n disableErrors,\n draft,\n includeLockStatus,\n joins,\n limit,\n overrideAccess,\n page,\n pagination,\n req: await createLocalReq(options, payload),\n select,\n showHiddenFields,\n sort,\n where,\n })\n}\n"],"names":["APIError","createLocalReq","findOperation","findLocal","payload","options","collection","collectionSlug","currentDepth","depth","disableErrors","draft","includeLockStatus","joins","limit","overrideAccess","page","pagination","select","showHiddenFields","sort","where","collections","String","req"],"mappings":"AAmBA,SAASA,QAAQ,QAAQ,2BAA0B;AACnD,SAASC,cAAc,QAAQ,uCAAsC;AACrE,SAASC,aAAa,QAAQ,aAAY;AA6B1C,OAAO,eAAeC,UAIpBC,OAAgB,EAChBC,OAAgC;IAEhC,MAAM,EACJC,YAAYC,cAAc,EAC1BC,YAAY,EACZC,KAAK,EACLC,aAAa,EACbC,QAAQ,KAAK,EACbC,iBAAiB,EACjBC,KAAK,EACLC,KAAK,EACLC,iBAAiB,IAAI,EACrBC,IAAI,EACJC,aAAa,IAAI,EACjBC,MAAM,EACN,UAAU;IACVC,gBAAgB,EAChBC,IAAI,EACJC,KAAK,EACN,GAAGhB;IAEJ,MAAMC,aAAaF,QAAQkB,WAAW,CAACf,eAAe;IAEtD,IAAI,CAACD,YAAY;QACf,MAAM,IAAIN,SACR,CAAC,yBAAyB,EAAEuB,OAAOhB,gBAAgB,gCAAgC,CAAC;IAExF;IAEA,OAAOL,cAA8B;QACnCI;QACAE;QACAC;QACAC;QACAC;QACAC;QACAC;QACAC;QACAC;QACAC;QACAC;QACAO,KAAK,MAAMvB,eAAeI,SAASD;QACnCc;QACAC;QACAC;QACAC;IACF;AACF"}
|