@payloadcms/db-mongodb 3.24.0-canary.7d9fbaf → 3.24.0-canary.80e034e
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/count.d.ts.map +1 -1
- package/dist/count.js +5 -2
- package/dist/count.js.map +1 -1
- package/dist/countGlobalVersions.d.ts.map +1 -1
- package/dist/countGlobalVersions.js +5 -3
- package/dist/countGlobalVersions.js.map +1 -1
- package/dist/countVersions.d.ts.map +1 -1
- package/dist/countVersions.js +5 -3
- package/dist/countVersions.js.map +1 -1
- package/dist/create.js +15 -15
- package/dist/create.js.map +1 -1
- package/dist/createGlobal.d.ts.map +1 -1
- package/dist/createGlobal.js +15 -14
- package/dist/createGlobal.js.map +1 -1
- package/dist/createGlobalVersion.d.ts.map +1 -1
- package/dist/createGlobalVersion.js +26 -23
- package/dist/createGlobalVersion.js.map +1 -1
- package/dist/createVersion.d.ts.map +1 -1
- package/dist/createVersion.js +26 -31
- package/dist/createVersion.js.map +1 -1
- package/dist/deleteMany.d.ts.map +1 -1
- package/dist/deleteMany.js +5 -2
- package/dist/deleteMany.js.map +1 -1
- package/dist/deleteOne.d.ts.map +1 -1
- package/dist/deleteOne.js +17 -9
- package/dist/deleteOne.js.map +1 -1
- package/dist/deleteVersions.d.ts +1 -1
- package/dist/deleteVersions.d.ts.map +1 -1
- package/dist/deleteVersions.js +5 -2
- package/dist/deleteVersions.js.map +1 -1
- package/dist/find.d.ts.map +1 -1
- package/dist/find.js +13 -12
- package/dist/find.js.map +1 -1
- package/dist/findGlobal.d.ts.map +1 -1
- package/dist/findGlobal.js +15 -11
- package/dist/findGlobal.js.map +1 -1
- package/dist/findGlobalVersions.d.ts.map +1 -1
- package/dist/findGlobalVersions.js +14 -14
- package/dist/findGlobalVersions.js.map +1 -1
- package/dist/findOne.d.ts.map +1 -1
- package/dist/findOne.js +13 -8
- package/dist/findOne.js.map +1 -1
- package/dist/findVersions.d.ts.map +1 -1
- package/dist/findVersions.js +14 -13
- package/dist/findVersions.js.map +1 -1
- package/dist/init.d.ts.map +1 -1
- package/dist/init.js +1 -3
- package/dist/init.js.map +1 -1
- package/dist/models/buildCollectionSchema.d.ts.map +1 -1
- package/dist/models/buildCollectionSchema.js +2 -3
- package/dist/models/buildCollectionSchema.js.map +1 -1
- package/dist/models/buildGlobalModel.d.ts.map +1 -1
- package/dist/models/buildGlobalModel.js +1 -2
- package/dist/models/buildGlobalModel.js.map +1 -1
- package/dist/models/buildSchema.js +2 -0
- package/dist/models/buildSchema.js.map +1 -1
- package/dist/predefinedMigrations/migrateRelationshipsV2_V3.d.ts.map +1 -1
- package/dist/predefinedMigrations/migrateRelationshipsV2_V3.js +12 -7
- package/dist/predefinedMigrations/migrateRelationshipsV2_V3.js.map +1 -1
- package/dist/queries/buildQuery.d.ts +6 -9
- package/dist/queries/buildQuery.d.ts.map +1 -1
- package/dist/queries/buildQuery.js +11 -35
- package/dist/queries/buildQuery.js.map +1 -1
- package/dist/queries/buildSortParam.d.ts +1 -1
- package/dist/queries/buildSortParam.d.ts.map +1 -1
- package/dist/queries/buildSortParam.js.map +1 -1
- package/dist/queries/getBuildQueryPlugin.d.ts +14 -0
- package/dist/queries/getBuildQueryPlugin.d.ts.map +1 -0
- package/dist/queries/getBuildQueryPlugin.js +40 -0
- package/dist/queries/getBuildQueryPlugin.js.map +1 -0
- package/dist/queries/sanitizeQueryValue.d.ts.map +1 -1
- package/dist/queries/sanitizeQueryValue.js.map +1 -1
- package/dist/queryDrafts.d.ts.map +1 -1
- package/dist/queryDrafts.js +19 -17
- package/dist/queryDrafts.js.map +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/updateGlobal.d.ts.map +1 -1
- package/dist/updateGlobal.js +15 -12
- package/dist/updateGlobal.js.map +1 -1
- package/dist/updateGlobalVersion.d.ts.map +1 -1
- package/dist/updateGlobalVersion.js +21 -15
- package/dist/updateGlobalVersion.js.map +1 -1
- package/dist/updateOne.js +20 -11
- package/dist/updateOne.js.map +1 -1
- package/dist/updateVersion.d.ts.map +1 -1
- package/dist/updateVersion.js +21 -15
- package/dist/updateVersion.js.map +1 -1
- package/dist/utilities/buildJoinAggregation.d.ts.map +1 -1
- package/dist/utilities/buildJoinAggregation.js +150 -4
- package/dist/utilities/buildJoinAggregation.js.map +1 -1
- package/dist/utilities/buildProjectionFromSelect.d.ts.map +1 -1
- package/dist/utilities/buildProjectionFromSelect.js +14 -16
- package/dist/utilities/buildProjectionFromSelect.js.map +1 -1
- package/dist/utilities/transform.d.ts +27 -0
- package/dist/utilities/transform.d.ts.map +1 -0
- package/dist/utilities/transform.js +224 -0
- package/dist/utilities/transform.js.map +1 -0
- package/dist/utilities/{sanitizeRelationshipIDs.spec.js → transform.spec.js} +11 -5
- package/dist/utilities/transform.spec.js.map +1 -0
- package/package.json +3 -3
- package/dist/utilities/sanitizeInternalFields.d.ts +0 -2
- package/dist/utilities/sanitizeInternalFields.d.ts.map +0 -1
- package/dist/utilities/sanitizeInternalFields.js +0 -20
- package/dist/utilities/sanitizeInternalFields.js.map +0 -1
- package/dist/utilities/sanitizeRelationshipIDs.d.ts +0 -10
- package/dist/utilities/sanitizeRelationshipIDs.d.ts.map +0 -1
- package/dist/utilities/sanitizeRelationshipIDs.js +0 -130
- package/dist/utilities/sanitizeRelationshipIDs.js.map +0 -1
- package/dist/utilities/sanitizeRelationshipIDs.spec.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/queries/sanitizeQueryValue.ts"],"sourcesContent":["import type {\n FlattenedBlock,\n FlattenedBlocksField,\n FlattenedField,\n Payload,\n RelationshipField,\n} from 'payload'\n\nimport { Types } from 'mongoose'\nimport { createArrayFromCommaDelineated } from 'payload'\nimport { fieldShouldBeLocalized } from 'payload/shared'\n\ntype SanitizeQueryValueArgs = {\n field: FlattenedField\n hasCustomID: boolean\n locale?: string\n operator: string\n parentIsLocalized: boolean\n path: string\n payload: Payload\n val: any\n}\n\nconst buildExistsQuery = (formattedValue, path, treatEmptyString = true) => {\n if (formattedValue) {\n return {\n rawQuery: {\n $and: [\n { [path]: { $exists: true } },\n { [path]: { $ne: null } },\n ...(treatEmptyString ? [{ [path]: { $ne: '' } }] : []), // Treat empty string as null / undefined\n ],\n },\n }\n } else {\n return {\n rawQuery: {\n $or: [\n { [path]: { $exists: false } },\n { [path]: { $eq: null } },\n ...(treatEmptyString ? [{ [path]: { $eq: '' } }] : []), // Treat empty string as null / undefined\n ],\n },\n }\n }\n}\n\n// returns nestedField Field object from blocks.nestedField path because getLocalizedPaths splits them only for relationships\nconst getFieldFromSegments = ({\n field,\n payload,\n segments,\n}: {\n field: FlattenedBlock | FlattenedField\n payload: Payload\n segments: string[]\n}) => {\n if ('blocks' in field || 'blockReferences' in field) {\n const _field: FlattenedBlocksField = field as FlattenedBlocksField\n for (const _block of _field.blockReferences ?? _field.blocks) {\n const block: FlattenedBlock = typeof _block === 'string' ? payload.blocks[_block] : _block\n const field = getFieldFromSegments({ field: block, payload, segments })\n if (field) {\n return field\n }\n }\n }\n\n if ('fields' in field) {\n for (let i = 0; i < segments.length; i++) {\n const foundField = field.flattenedFields.find((each) => each.name === segments[i])\n\n if (!foundField) {\n break\n }\n\n if (foundField && segments.length - 1 === i) {\n return foundField\n }\n\n segments.shift()\n return getFieldFromSegments({ field: foundField, payload, segments })\n }\n }\n}\n\nexport const sanitizeQueryValue = ({\n field,\n hasCustomID,\n locale,\n operator,\n parentIsLocalized,\n path,\n payload,\n val,\n}: SanitizeQueryValueArgs): {\n operator?: string\n rawQuery?: unknown\n val?: unknown\n} => {\n let formattedValue = val\n let formattedOperator = operator\n\n if (['array', 'blocks', 'group', 'tab'].includes(field.type) && path.includes('.')) {\n const segments = path.split('.')\n segments.shift()\n const foundField = getFieldFromSegments({ field, payload, segments })\n\n if (foundField) {\n field = foundField\n }\n }\n\n // Disregard invalid _ids\n if (path === '_id') {\n if (typeof val === 'string' && val.split(',').length === 1) {\n if (!hasCustomID) {\n const isValid = Types.ObjectId.isValid(val)\n\n if (!isValid) {\n return { operator: formattedOperator, val: undefined }\n } else {\n if (['in', 'not_in'].includes(operator)) {\n formattedValue = createArrayFromCommaDelineated(formattedValue).map(\n (id) => new Types.ObjectId(id),\n )\n } else {\n formattedValue = new Types.ObjectId(val)\n }\n }\n }\n\n if (field.type === 'number') {\n const parsedNumber = parseFloat(val)\n\n if (Number.isNaN(parsedNumber)) {\n return { operator: formattedOperator, val: undefined }\n }\n }\n } else if (Array.isArray(val) || (typeof val === 'string' && val.split(',').length > 1)) {\n if (typeof val === 'string') {\n formattedValue = createArrayFromCommaDelineated(val)\n }\n\n formattedValue = formattedValue.reduce((formattedValues, inVal) => {\n if (!hasCustomID) {\n if (Types.ObjectId.isValid(inVal)) {\n formattedValues.push(new Types.ObjectId(inVal))\n }\n }\n\n if (field.type === 'number') {\n const parsedNumber = parseFloat(inVal)\n if (!Number.isNaN(parsedNumber)) {\n formattedValues.push(parsedNumber)\n }\n } else {\n formattedValues.push(inVal)\n }\n\n return formattedValues\n }, [])\n }\n }\n\n // Cast incoming values as proper searchable types\n if (field.type === 'checkbox' && typeof val === 'string') {\n if (val.toLowerCase() === 'true') {\n formattedValue = true\n }\n if (val.toLowerCase() === 'false') {\n formattedValue = false\n }\n }\n\n if (['all', 'in', 'not_in'].includes(operator) && typeof formattedValue === 'string') {\n formattedValue = createArrayFromCommaDelineated(formattedValue)\n\n if (field.type === 'number') {\n formattedValue = formattedValue.map((arrayVal) => parseFloat(arrayVal))\n }\n }\n\n if (field.type === 'number') {\n if (typeof formattedValue === 'string' && operator !== 'exists') {\n formattedValue = Number(val)\n }\n\n if (operator === 'exists') {\n formattedValue = val === 'true' ? true : val === 'false' ? false : Boolean(val)\n\n return buildExistsQuery(formattedValue, path)\n }\n }\n\n if (field.type === 'date' && typeof val === 'string' && operator !== 'exists') {\n formattedValue = new Date(val)\n if (Number.isNaN(Date.parse(formattedValue))) {\n return undefined\n }\n }\n\n if (['relationship', 'upload'].includes(field.type)) {\n if (val === 'null') {\n formattedValue = null\n }\n\n // Object equality requires the value to be the first key in the object that is being queried.\n if (\n operator === 'equals' &&\n formattedValue &&\n typeof formattedValue === 'object' &&\n formattedValue.value &&\n formattedValue.relationTo\n ) {\n const { value } = formattedValue\n const isValid = Types.ObjectId.isValid(value)\n\n if (isValid) {\n formattedValue.value = new Types.ObjectId(value)\n }\n\n let localizedPath = path\n\n if (\n fieldShouldBeLocalized({ field, parentIsLocalized }) &&\n payload.config.localization &&\n locale\n ) {\n localizedPath = `${path}.${locale}`\n }\n\n return {\n rawQuery: {\n $or: [\n {\n [localizedPath]: {\n $eq: {\n // disable auto sort\n /* eslint-disable */\n value: formattedValue.value,\n relationTo: formattedValue.relationTo,\n /* eslint-enable */\n },\n },\n },\n {\n [localizedPath]: {\n $eq: {\n relationTo: formattedValue.relationTo,\n value: formattedValue.value,\n },\n },\n },\n ],\n },\n }\n }\n\n const relationTo = (field as RelationshipField).relationTo\n\n if (['in', 'not_in'].includes(operator) && Array.isArray(formattedValue)) {\n formattedValue = formattedValue.reduce((formattedValues, inVal) => {\n if (!inVal) {\n return formattedValues\n }\n\n if (typeof relationTo === 'string' && payload.collections[relationTo].customIDType) {\n if (payload.collections[relationTo].customIDType === 'number') {\n const parsedNumber = parseFloat(inVal)\n if (!Number.isNaN(parsedNumber)) {\n formattedValues.push(parsedNumber)\n return formattedValues\n }\n }\n\n formattedValues.push(inVal)\n return formattedValues\n }\n\n if (\n Array.isArray(relationTo) &&\n relationTo.some((relationTo) => !!payload.collections[relationTo].customIDType)\n ) {\n if (Types.ObjectId.isValid(inVal.toString())) {\n formattedValues.push(new Types.ObjectId(inVal))\n } else {\n formattedValues.push(inVal)\n }\n return formattedValues\n }\n\n if (Types.ObjectId.isValid(inVal.toString())) {\n formattedValues.push(new Types.ObjectId(inVal))\n }\n\n return formattedValues\n }, [])\n }\n\n if (\n ['contains', 'equals', 'like', 'not_equals'].includes(operator) &&\n (!Array.isArray(relationTo) || !path.endsWith('.relationTo'))\n ) {\n if (typeof relationTo === 'string') {\n const customIDType = payload.collections[relationTo].customIDType\n\n if (customIDType) {\n if (customIDType === 'number') {\n formattedValue = parseFloat(val)\n\n if (Number.isNaN(formattedValue)) {\n return { operator: formattedOperator, val: undefined }\n }\n }\n } else {\n if (!Types.ObjectId.isValid(formattedValue)) {\n return { operator: formattedOperator, val: undefined }\n }\n formattedValue = new Types.ObjectId(formattedValue)\n }\n } else {\n const hasCustomIDType = relationTo.some(\n (relationTo) => !!payload.collections[relationTo].customIDType,\n )\n\n if (hasCustomIDType) {\n if (typeof val === 'string') {\n const formattedNumber = Number(val)\n formattedValue = [Types.ObjectId.isValid(val) ? new Types.ObjectId(val) : val]\n formattedOperator = operator === 'not_equals' ? 'not_in' : 'in'\n if (!Number.isNaN(formattedNumber)) {\n formattedValue.push(formattedNumber)\n }\n }\n } else {\n if (!Types.ObjectId.isValid(formattedValue)) {\n return { operator: formattedOperator, val: undefined }\n }\n formattedValue = new Types.ObjectId(formattedValue)\n }\n }\n }\n\n if (\n operator === 'all' &&\n Array.isArray(relationTo) &&\n path.endsWith('.value') &&\n Array.isArray(formattedValue)\n ) {\n formattedValue.forEach((v, i) => {\n if (Types.ObjectId.isValid(v)) {\n formattedValue[i] = new Types.ObjectId(v)\n }\n })\n }\n }\n\n // Set up specific formatting necessary by operators\n\n if (operator === 'near') {\n let lng\n let lat\n let maxDistance\n let minDistance\n\n if (Array.isArray(formattedValue)) {\n ;[lng, lat, maxDistance, minDistance] = formattedValue\n }\n\n if (typeof formattedValue === 'string') {\n ;[lng, lat, maxDistance, minDistance] = createArrayFromCommaDelineated(formattedValue)\n }\n\n if (lng == null || lat == null || (maxDistance == null && minDistance == null)) {\n formattedValue = undefined\n } else {\n formattedValue = {\n $geometry: { type: 'Point', coordinates: [parseFloat(lng), parseFloat(lat)] },\n }\n\n if (maxDistance && !Number.isNaN(Number(maxDistance))) {\n formattedValue.$maxDistance = parseFloat(maxDistance)\n }\n\n if (minDistance && !Number.isNaN(Number(minDistance))) {\n formattedValue.$minDistance = parseFloat(minDistance)\n }\n }\n }\n\n if (operator === 'within' || operator === 'intersects') {\n formattedValue = {\n $geometry: formattedValue,\n }\n }\n\n if (path !== '_id' || (path === '_id' && hasCustomID && field.type === 'text')) {\n if (operator === 'contains' && !Types.ObjectId.isValid(formattedValue)) {\n formattedValue = {\n $options: 'i',\n $regex: formattedValue.replace(/[\\\\^$*+?.()|[\\]{}]/g, '\\\\$&'),\n }\n }\n\n if (operator === 'exists') {\n formattedValue = formattedValue === 'true' || formattedValue === true\n\n // _id can't be empty string, will error Cast to ObjectId failed for value \"\"\n return buildExistsQuery(\n formattedValue,\n path,\n !['relationship', 'upload'].includes(field.type),\n )\n }\n }\n\n if (\n (path === '_id' || path === 'parent') &&\n operator === 'like' &&\n formattedValue.length === 24 &&\n !hasCustomID\n ) {\n formattedOperator = 'equals'\n }\n\n if (operator === 'exists') {\n formattedValue = formattedValue === 'true' || formattedValue === true\n\n // Clearable fields\n if (['relationship', 'select', 'upload'].includes(field.type)) {\n if (formattedValue) {\n return {\n rawQuery: {\n $and: [{ [path]: { $exists: true } }, { [path]: { $ne: null } }],\n },\n }\n } else {\n return {\n rawQuery: {\n $or: [{ [path]: { $exists: false } }, { [path]: { $eq: null } }],\n },\n }\n }\n }\n }\n\n return { operator: formattedOperator, val: formattedValue }\n}\n"],"names":["Types","createArrayFromCommaDelineated","fieldShouldBeLocalized","buildExistsQuery","formattedValue","path","treatEmptyString","rawQuery","$and","$exists","$ne","$or","$eq","getFieldFromSegments","field","payload","segments","_field","_block","blockReferences","blocks","block","i","length","foundField","flattenedFields","find","each","name","shift","sanitizeQueryValue","hasCustomID","locale","operator","parentIsLocalized","val","formattedOperator","includes","type","split","isValid","ObjectId","undefined","map","id","parsedNumber","parseFloat","Number","isNaN","Array","isArray","reduce","formattedValues","inVal","push","toLowerCase","arrayVal","Boolean","Date","parse","value","relationTo","localizedPath","config","localization","collections","customIDType","some","toString","endsWith","hasCustomIDType","formattedNumber","forEach","v","lng","lat","maxDistance","minDistance","$geometry","coordinates","$maxDistance","$minDistance","$options","$regex","replace"],"mappings":"AAQA,SAASA,KAAK,QAAQ,WAAU;AAChC,SAASC,8BAA8B,QAAQ,UAAS;AACxD,SAASC,sBAAsB,QAAQ,iBAAgB;AAavD,MAAMC,mBAAmB,CAACC,gBAAgBC,MAAMC,mBAAmB,IAAI;IACrE,IAAIF,gBAAgB;QAClB,OAAO;YACLG,UAAU;gBACRC,MAAM;oBACJ;wBAAE,CAACH,KAAK,EAAE;4BAAEI,SAAS;wBAAK;oBAAE;oBAC5B;wBAAE,CAACJ,KAAK,EAAE;4BAAEK,KAAK;wBAAK;oBAAE;uBACpBJ,mBAAmB;wBAAC;4BAAE,CAACD,KAAK,EAAE;gCAAEK,KAAK;4BAAG;wBAAE;qBAAE,GAAG,EAAE;iBACtD;YACH;QACF;IACF,OAAO;QACL,OAAO;YACLH,UAAU;gBACRI,KAAK;oBACH;wBAAE,CAACN,KAAK,EAAE;4BAAEI,SAAS;wBAAM;oBAAE;oBAC7B;wBAAE,CAACJ,KAAK,EAAE;4BAAEO,KAAK;wBAAK;oBAAE;uBACpBN,mBAAmB;wBAAC;4BAAE,CAACD,KAAK,EAAE;gCAAEO,KAAK;4BAAG;wBAAE;qBAAE,GAAG,EAAE;iBACtD;YACH;QACF;IACF;AACF;AAEA,6HAA6H;AAC7H,MAAMC,uBAAuB,CAAC,EAC5BC,KAAK,EACLC,OAAO,EACPC,QAAQ,EAKT;IACC,IAAI,YAAYF,SAAS,qBAAqBA,OAAO;QACnD,MAAMG,SAA+BH;QACrC,KAAK,MAAMI,UAAUD,OAAOE,eAAe,IAAIF,OAAOG,MAAM,CAAE;YAC5D,MAAMC,QAAwB,OAAOH,WAAW,WAAWH,QAAQK,MAAM,CAACF,OAAO,GAAGA;YACpF,MAAMJ,QAAQD,qBAAqB;gBAAEC,OAAOO;gBAAON;gBAASC;YAAS;Y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,KAAK,EAAE;oCAAEO,KAAK;gCAAK;4BAAE;yBAAE;oBAClE;gBACF;YACF;QACF;IACF;IAEA,OAAO;QAAEqB,UAAUG;QAAmBD,KAAK/B;IAAe;AAC5D,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../src/queries/sanitizeQueryValue.ts"],"sourcesContent":["import type {\n FlattenedBlock,\n FlattenedBlocksField,\n FlattenedField,\n Payload,\n RelationshipField,\n} from 'payload'\n\nimport { Types } from 'mongoose'\nimport { createArrayFromCommaDelineated } from 'payload'\nimport { fieldShouldBeLocalized } from 'payload/shared'\n\ntype SanitizeQueryValueArgs = {\n field: FlattenedField\n hasCustomID: boolean\n locale?: string\n operator: string\n parentIsLocalized: boolean\n path: string\n payload: Payload\n val: any\n}\n\nconst buildExistsQuery = (formattedValue, path, treatEmptyString = true) => {\n if (formattedValue) {\n return {\n rawQuery: {\n $and: [\n { [path]: { $exists: true } },\n { [path]: { $ne: null } },\n ...(treatEmptyString ? [{ [path]: { $ne: '' } }] : []), // Treat empty string as null / undefined\n ],\n },\n }\n } else {\n return {\n rawQuery: {\n $or: [\n { [path]: { $exists: false } },\n { [path]: { $eq: null } },\n ...(treatEmptyString ? [{ [path]: { $eq: '' } }] : []), // Treat empty string as null / undefined\n ],\n },\n }\n }\n}\n\n// returns nestedField Field object from blocks.nestedField path because getLocalizedPaths splits them only for relationships\nconst getFieldFromSegments = ({\n field,\n payload,\n segments,\n}: {\n field: FlattenedBlock | FlattenedField\n payload: Payload\n segments: string[]\n}) => {\n if ('blocks' in field || 'blockReferences' in field) {\n const _field: FlattenedBlocksField = field as FlattenedBlocksField\n for (const _block of _field.blockReferences ?? _field.blocks) {\n const block: FlattenedBlock = typeof _block === 'string' ? payload.blocks[_block] : _block\n const field = getFieldFromSegments({ field: block, payload, segments })\n if (field) {\n return field\n }\n }\n }\n\n if ('fields' in field) {\n for (let i = 0; i < segments.length; i++) {\n const foundField = field.flattenedFields.find((each) => each.name === segments[i])\n\n if (!foundField) {\n break\n }\n\n if (foundField && segments.length - 1 === i) {\n return foundField\n }\n\n segments.shift()\n return getFieldFromSegments({ field: foundField, payload, segments })\n }\n }\n}\n\nexport const sanitizeQueryValue = ({\n field,\n hasCustomID,\n locale,\n operator,\n parentIsLocalized,\n path,\n payload,\n val,\n}: SanitizeQueryValueArgs): {\n operator?: string\n rawQuery?: unknown\n val?: unknown\n} => {\n let formattedValue = val\n let formattedOperator = operator\n if (['array', 'blocks', 'group', 'tab'].includes(field.type) && path.includes('.')) {\n const segments = path.split('.')\n segments.shift()\n const foundField = getFieldFromSegments({ field, payload, segments })\n\n if (foundField) {\n field = foundField\n }\n }\n\n // Disregard invalid _ids\n if (path === '_id') {\n if (typeof val === 'string' && val.split(',').length === 1) {\n if (!hasCustomID) {\n const isValid = Types.ObjectId.isValid(val)\n\n if (!isValid) {\n return { operator: formattedOperator, val: undefined }\n } else {\n if (['in', 'not_in'].includes(operator)) {\n formattedValue = createArrayFromCommaDelineated(formattedValue).map(\n (id) => new Types.ObjectId(id),\n )\n } else {\n formattedValue = new Types.ObjectId(val)\n }\n }\n }\n\n if (field.type === 'number') {\n const parsedNumber = parseFloat(val)\n\n if (Number.isNaN(parsedNumber)) {\n return { operator: formattedOperator, val: undefined }\n }\n }\n } else if (Array.isArray(val) || (typeof val === 'string' && val.split(',').length > 1)) {\n if (typeof val === 'string') {\n formattedValue = createArrayFromCommaDelineated(val)\n }\n\n formattedValue = formattedValue.reduce((formattedValues, inVal) => {\n if (!hasCustomID) {\n if (Types.ObjectId.isValid(inVal)) {\n formattedValues.push(new Types.ObjectId(inVal))\n }\n }\n\n if (field.type === 'number') {\n const parsedNumber = parseFloat(inVal)\n if (!Number.isNaN(parsedNumber)) {\n formattedValues.push(parsedNumber)\n }\n } else {\n formattedValues.push(inVal)\n }\n\n return formattedValues\n }, [])\n }\n }\n\n // Cast incoming values as proper searchable types\n if (field.type === 'checkbox' && typeof val === 'string') {\n if (val.toLowerCase() === 'true') {\n formattedValue = true\n }\n if (val.toLowerCase() === 'false') {\n formattedValue = false\n }\n }\n\n if (['all', 'in', 'not_in'].includes(operator) && typeof formattedValue === 'string') {\n formattedValue = createArrayFromCommaDelineated(formattedValue)\n\n if (field.type === 'number') {\n formattedValue = formattedValue.map((arrayVal) => parseFloat(arrayVal))\n }\n }\n\n if (field.type === 'number') {\n if (typeof formattedValue === 'string' && operator !== 'exists') {\n formattedValue = Number(val)\n }\n\n if (operator === 'exists') {\n formattedValue = val === 'true' ? true : val === 'false' ? false : Boolean(val)\n\n return buildExistsQuery(formattedValue, path)\n }\n }\n\n if (field.type === 'date' && typeof val === 'string' && operator !== 'exists') {\n formattedValue = new Date(val)\n if (Number.isNaN(Date.parse(formattedValue))) {\n return undefined\n }\n }\n\n if (['relationship', 'upload'].includes(field.type)) {\n if (val === 'null') {\n formattedValue = null\n }\n\n // Object equality requires the value to be the first key in the object that is being queried.\n if (\n operator === 'equals' &&\n formattedValue &&\n typeof formattedValue === 'object' &&\n formattedValue.value &&\n formattedValue.relationTo\n ) {\n const { value } = formattedValue\n const isValid = Types.ObjectId.isValid(value)\n\n if (isValid) {\n formattedValue.value = new Types.ObjectId(value)\n }\n\n let localizedPath = path\n\n if (\n fieldShouldBeLocalized({ field, parentIsLocalized }) &&\n payload.config.localization &&\n locale\n ) {\n localizedPath = `${path}.${locale}`\n }\n\n return {\n rawQuery: {\n $or: [\n {\n [localizedPath]: {\n $eq: {\n // disable auto sort\n /* eslint-disable */\n value: formattedValue.value,\n relationTo: formattedValue.relationTo,\n /* eslint-enable */\n },\n },\n },\n {\n [localizedPath]: {\n $eq: {\n relationTo: formattedValue.relationTo,\n value: formattedValue.value,\n },\n },\n },\n ],\n },\n }\n }\n\n const relationTo = (field as RelationshipField).relationTo\n\n if (['in', 'not_in'].includes(operator) && Array.isArray(formattedValue)) {\n formattedValue = formattedValue.reduce((formattedValues, inVal) => {\n if (!inVal) {\n return formattedValues\n }\n\n if (typeof relationTo === 'string' && payload.collections[relationTo].customIDType) {\n if (payload.collections[relationTo].customIDType === 'number') {\n const parsedNumber = parseFloat(inVal)\n if (!Number.isNaN(parsedNumber)) {\n formattedValues.push(parsedNumber)\n return formattedValues\n }\n }\n\n formattedValues.push(inVal)\n return formattedValues\n }\n\n if (\n Array.isArray(relationTo) &&\n relationTo.some((relationTo) => !!payload.collections[relationTo].customIDType)\n ) {\n if (Types.ObjectId.isValid(inVal.toString())) {\n formattedValues.push(new Types.ObjectId(inVal))\n } else {\n formattedValues.push(inVal)\n }\n return formattedValues\n }\n\n if (Types.ObjectId.isValid(inVal.toString())) {\n formattedValues.push(new Types.ObjectId(inVal))\n }\n\n return formattedValues\n }, [])\n }\n\n if (\n ['contains', 'equals', 'like', 'not_equals'].includes(operator) &&\n (!Array.isArray(relationTo) || !path.endsWith('.relationTo'))\n ) {\n if (typeof relationTo === 'string') {\n const customIDType = payload.collections[relationTo].customIDType\n\n if (customIDType) {\n if (customIDType === 'number') {\n formattedValue = parseFloat(val)\n\n if (Number.isNaN(formattedValue)) {\n return { operator: formattedOperator, val: undefined }\n }\n }\n } else {\n if (!Types.ObjectId.isValid(formattedValue)) {\n return { operator: formattedOperator, val: undefined }\n }\n formattedValue = new Types.ObjectId(formattedValue)\n }\n } else {\n const hasCustomIDType = relationTo.some(\n (relationTo) => !!payload.collections[relationTo].customIDType,\n )\n\n if (hasCustomIDType) {\n if (typeof val === 'string') {\n const formattedNumber = Number(val)\n formattedValue = [Types.ObjectId.isValid(val) ? new Types.ObjectId(val) : val]\n formattedOperator = operator === 'not_equals' ? 'not_in' : 'in'\n if (!Number.isNaN(formattedNumber)) {\n formattedValue.push(formattedNumber)\n }\n }\n } else {\n if (!Types.ObjectId.isValid(formattedValue)) {\n return { operator: formattedOperator, val: undefined }\n }\n formattedValue = new Types.ObjectId(formattedValue)\n }\n }\n }\n\n if (\n operator === 'all' &&\n Array.isArray(relationTo) &&\n path.endsWith('.value') &&\n Array.isArray(formattedValue)\n ) {\n formattedValue.forEach((v, i) => {\n if (Types.ObjectId.isValid(v)) {\n formattedValue[i] = new Types.ObjectId(v)\n }\n })\n }\n }\n\n // Set up specific formatting necessary by operators\n\n if (operator === 'near') {\n let lng\n let lat\n let maxDistance\n let minDistance\n\n if (Array.isArray(formattedValue)) {\n ;[lng, lat, maxDistance, minDistance] = formattedValue\n }\n\n if (typeof formattedValue === 'string') {\n ;[lng, lat, maxDistance, minDistance] = createArrayFromCommaDelineated(formattedValue)\n }\n\n if (lng == null || lat == null || (maxDistance == null && minDistance == null)) {\n formattedValue = undefined\n } else {\n formattedValue = {\n $geometry: { type: 'Point', coordinates: [parseFloat(lng), parseFloat(lat)] },\n }\n\n if (maxDistance && !Number.isNaN(Number(maxDistance))) {\n formattedValue.$maxDistance = parseFloat(maxDistance)\n }\n\n if (minDistance && !Number.isNaN(Number(minDistance))) {\n formattedValue.$minDistance = parseFloat(minDistance)\n }\n }\n }\n\n if (operator === 'within' || operator === 'intersects') {\n formattedValue = {\n $geometry: formattedValue,\n }\n }\n\n if (path !== '_id' || (path === '_id' && hasCustomID && field.type === 'text')) {\n if (operator === 'contains' && !Types.ObjectId.isValid(formattedValue)) {\n formattedValue = {\n $options: 'i',\n $regex: formattedValue.replace(/[\\\\^$*+?.()|[\\]{}]/g, '\\\\$&'),\n }\n }\n\n if (operator === 'exists') {\n formattedValue = formattedValue === 'true' || formattedValue === true\n\n // _id can't be empty string, will error Cast to ObjectId failed for value \"\"\n return buildExistsQuery(\n formattedValue,\n path,\n !['relationship', 'upload'].includes(field.type),\n )\n }\n }\n\n if (\n (path === '_id' || path === 'parent') &&\n operator === 'like' &&\n formattedValue.length === 24 &&\n !hasCustomID\n ) {\n formattedOperator = 'equals'\n }\n\n if (operator === 'exists') {\n formattedValue = formattedValue === 'true' || formattedValue === true\n\n // Clearable fields\n if (['relationship', 'select', 'upload'].includes(field.type)) {\n if (formattedValue) {\n return {\n rawQuery: {\n $and: [{ [path]: { $exists: true } }, { [path]: { $ne: null } }],\n },\n }\n } else {\n return {\n rawQuery: {\n $or: [{ [path]: { $exists: false } }, { [path]: { $eq: null } }],\n },\n }\n }\n }\n }\n\n return { operator: formattedOperator, val: formattedValue }\n}\n"],"names":["Types","createArrayFromCommaDelineated","fieldShouldBeLocalized","buildExistsQuery","formattedValue","path","treatEmptyString","rawQuery","$and","$exists","$ne","$or","$eq","getFieldFromSegments","field","payload","segments","_field","_block","blockReferences","blocks","block","i","length","foundField","flattenedFields","find","each","name","shift","sanitizeQueryValue","hasCustomID","locale","operator","parentIsLocalized","val","formattedOperator","includes","type","split","isValid","ObjectId","undefined","map","id","parsedNumber","parseFloat","Number","isNaN","Array","isArray","reduce","formattedValues","inVal","push","toLowerCase","arrayVal","Boolean","Date","parse","value","relationTo","localizedPath","config","localization","collections","customIDType","some","toString","endsWith","hasCustomIDType","formattedNumber","forEach","v","lng","lat","maxDistance","minDistance","$geometry","coordinates","$maxDistance","$minDistance","$options","$regex","replace"],"mappings":"AAQA,SAASA,KAAK,QAAQ,WAAU;AAChC,SAASC,8BAA8B,QAAQ,UAAS;AACxD,SAASC,sBAAsB,QAAQ,iBAAgB;AAavD,MAAMC,mBAAmB,CAACC,gBAAgBC,MAAMC,mBAAmB,IAAI;IACrE,IAAIF,gBAAgB;QAClB,OAAO;YACLG,UAAU;gBACRC,MAAM;oBACJ;wBAAE,CAACH,KAAK,EAAE;4BAAEI,SAAS;wBAAK;oBAAE;oBAC5B;wBAAE,CAACJ,KAAK,EAAE;4BAAEK,KAAK;wBAAK;oBAAE;uBACpBJ,mBAAmB;wBAAC;4BAAE,CAACD,KAAK,EAAE;gCAAEK,KAAK;4BAAG;wBAAE;qBAAE,GAAG,EAAE;iBACtD;YACH;QACF;IACF,OAAO;QACL,OAAO;YACLH,UAAU;gBACRI,KAAK;oBACH;wBAAE,CAACN,KAAK,EAAE;4BAAEI,SAAS;wBAAM;oBAAE;oBAC7B;wBAAE,CAACJ,KAAK,EAAE;4BAAEO,KAAK;wBAAK;oBAAE;uBACpBN,mBAAmB;wBAAC;4BAAE,CAACD,K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,mBAAmB;QAEjE,mBAAmB;QACnB,IAAI;YAAC;YAAgB;YAAU;SAAS,CAACiC,QAAQ,CAACvB,MAAMwB,IAAI,GAAG;YAC7D,IAAIlC,gBAAgB;gBAClB,OAAO;oBACLG,UAAU;wBACRC,MAAM;4BAAC;gCAAE,CAACH,KAAK,EAAE;oCAAEI,SAAS;gCAAK;4BAAE;4BAAG;gCAAE,CAACJ,KAAK,EAAE;oCAAEK,KAAK;gCAAK;4BAAE;yBAAE;oBAClE;gBACF;YACF,OAAO;gBACL,OAAO;oBACLH,UAAU;wBACRI,KAAK;4BAAC;gCAAE,CAACN,KAAK,EAAE;oCAAEI,SAAS;gCAAM;4BAAE;4BAAG;gCAAE,CAACJ,KAAK,EAAE;oCAAEO,KAAK;gCAAK;4BAAE;yBAAE;oBAClE;gBACF;YACF;QACF;IACF;IAEA,OAAO;QAAEqB,UAAUG;QAAmBD,KAAK/B;IAAe;AAC5D,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queryDrafts.d.ts","sourceRoot":"","sources":["../src/queryDrafts.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"queryDrafts.d.ts","sourceRoot":"","sources":["../src/queryDrafts.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAa1C,eAAO,MAAM,WAAW,EAAE,WA8HzB,CAAA"}
|
package/dist/queryDrafts.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { buildVersionCollectionFields, combineQueries, flattenWhereToOperators } from 'payload';
|
|
2
|
+
import { buildQuery } from './queries/buildQuery.js';
|
|
2
3
|
import { buildSortParam } from './queries/buildSortParam.js';
|
|
3
4
|
import { buildJoinAggregation } from './utilities/buildJoinAggregation.js';
|
|
4
5
|
import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
|
|
5
6
|
import { getSession } from './utilities/getSession.js';
|
|
6
|
-
import {
|
|
7
|
+
import { transform } from './utilities/transform.js';
|
|
7
8
|
export const queryDrafts = async function queryDrafts({ collection, joins, limit, locale, page, pagination, req, select, sort: sortArg, where }) {
|
|
8
9
|
const VersionModel = this.versions[collection];
|
|
9
10
|
const collectionConfig = this.payload.collections[collection].config;
|
|
@@ -21,7 +22,6 @@ export const queryDrafts = async function queryDrafts({ collection, joins, limit
|
|
|
21
22
|
config: this.payload.config,
|
|
22
23
|
fields: collectionConfig.flattenedFields,
|
|
23
24
|
locale,
|
|
24
|
-
parentIsLocalized: false,
|
|
25
25
|
sort: sortArg || collectionConfig.defaultSort,
|
|
26
26
|
timestamps: true
|
|
27
27
|
});
|
|
@@ -31,14 +31,16 @@ export const queryDrafts = async function queryDrafts({ collection, joins, limit
|
|
|
31
31
|
equals: true
|
|
32
32
|
}
|
|
33
33
|
}, where);
|
|
34
|
-
const
|
|
34
|
+
const fields = buildVersionCollectionFields(this.payload.config, collectionConfig, true);
|
|
35
|
+
const versionQuery = await buildQuery({
|
|
36
|
+
adapter: this,
|
|
37
|
+
fields,
|
|
35
38
|
locale,
|
|
36
|
-
payload: this.payload,
|
|
37
39
|
where: combinedWhere
|
|
38
40
|
});
|
|
39
41
|
const projection = buildProjectionFromSelect({
|
|
40
42
|
adapter: this,
|
|
41
|
-
fields
|
|
43
|
+
fields,
|
|
42
44
|
select
|
|
43
45
|
});
|
|
44
46
|
// useEstimatedCount is faster, but not accurate, as it ignores any filters. It is thus set to true if there are no filters.
|
|
@@ -95,18 +97,18 @@ export const queryDrafts = async function queryDrafts({ collection, joins, limit
|
|
|
95
97
|
} else {
|
|
96
98
|
result = await VersionModel.paginate(versionQuery, paginationOptions);
|
|
97
99
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
100
|
+
transform({
|
|
101
|
+
adapter: this,
|
|
102
|
+
data: result.docs,
|
|
103
|
+
fields: buildVersionCollectionFields(this.payload.config, collectionConfig),
|
|
104
|
+
operation: 'read'
|
|
105
|
+
});
|
|
106
|
+
for(let i = 0; i < result.docs.length; i++){
|
|
107
|
+
const id = result.docs[i].parent;
|
|
108
|
+
result.docs[i] = result.docs[i].version;
|
|
109
|
+
result.docs[i].id = id;
|
|
110
|
+
}
|
|
111
|
+
return result;
|
|
110
112
|
};
|
|
111
113
|
|
|
112
114
|
//# sourceMappingURL=queryDrafts.js.map
|
package/dist/queryDrafts.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/queryDrafts.ts"],"sourcesContent":["import type { PaginateOptions, QueryOptions } from 'mongoose'\nimport type { QueryDrafts } from 'payload'\n\nimport { buildVersionCollectionFields, combineQueries, flattenWhereToOperators } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildSortParam } from './queries/buildSortParam.js'\nimport { buildJoinAggregation } from './utilities/buildJoinAggregation.js'\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getSession } from './utilities/getSession.js'\nimport {
|
|
1
|
+
{"version":3,"sources":["../src/queryDrafts.ts"],"sourcesContent":["import type { PaginateOptions, QueryOptions } from 'mongoose'\nimport type { QueryDrafts } from 'payload'\n\nimport { buildVersionCollectionFields, combineQueries, flattenWhereToOperators } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { buildSortParam } from './queries/buildSortParam.js'\nimport { buildJoinAggregation } from './utilities/buildJoinAggregation.js'\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getSession } from './utilities/getSession.js'\nimport { transform } from './utilities/transform.js'\n\nexport const queryDrafts: QueryDrafts = async function queryDrafts(\n this: MongooseAdapter,\n { collection, joins, limit, locale, page, pagination, req, select, sort: sortArg, where },\n) {\n const VersionModel = this.versions[collection]\n const collectionConfig = this.payload.collections[collection].config\n const options: QueryOptions = {\n session: await getSession(this, req),\n }\n\n let hasNearConstraint\n let sort\n\n if (where) {\n const constraints = flattenWhereToOperators(where)\n hasNearConstraint = constraints.some((prop) => Object.keys(prop).some((key) => key === 'near'))\n }\n\n if (!hasNearConstraint) {\n sort = buildSortParam({\n config: this.payload.config,\n fields: collectionConfig.flattenedFields,\n locale,\n sort: sortArg || collectionConfig.defaultSort,\n timestamps: true,\n })\n }\n\n const combinedWhere = combineQueries({ latest: { equals: true } }, where)\n\n const fields = buildVersionCollectionFields(this.payload.config, collectionConfig, true)\n const versionQuery = await buildQuery({\n adapter: this,\n fields,\n locale,\n where: combinedWhere,\n })\n\n const projection = buildProjectionFromSelect({\n adapter: this,\n fields,\n select,\n })\n // useEstimatedCount is faster, but not accurate, as it ignores any filters. It is thus set to true if there are no filters.\n const useEstimatedCount =\n hasNearConstraint || !versionQuery || Object.keys(versionQuery).length === 0\n const paginationOptions: PaginateOptions = {\n lean: true,\n leanWithId: true,\n options,\n page,\n pagination,\n projection,\n sort,\n useEstimatedCount,\n }\n\n if (this.collation) {\n const defaultLocale = 'en'\n paginationOptions.collation = {\n locale: locale && locale !== 'all' && locale !== '*' ? locale : defaultLocale,\n ...this.collation,\n }\n }\n\n if (\n !useEstimatedCount &&\n Object.keys(versionQuery).length === 0 &&\n this.disableIndexHints !== true\n ) {\n // Improve the performance of the countDocuments query which is used if useEstimatedCount is set to false by adding\n // a hint. By default, if no hint is provided, MongoDB does not use an indexed field to count the returned documents,\n // which makes queries very slow. This only happens when no query (filter) is provided. If one is provided, it uses\n // the correct indexed field\n paginationOptions.useCustomCountFn = () => {\n return Promise.resolve(\n VersionModel.countDocuments(versionQuery, {\n hint: { _id: 1 },\n }),\n )\n }\n }\n\n if (limit > 0) {\n paginationOptions.limit = limit\n // limit must also be set here, it's ignored when pagination is false\n paginationOptions.options.limit = limit\n }\n\n let result\n\n const aggregate = await buildJoinAggregation({\n adapter: this,\n collection,\n collectionConfig,\n joins,\n locale,\n projection,\n query: versionQuery,\n versions: true,\n })\n\n // build join aggregation\n if (aggregate) {\n result = await VersionModel.aggregatePaginate(\n VersionModel.aggregate(aggregate),\n paginationOptions,\n )\n } else {\n result = await VersionModel.paginate(versionQuery, paginationOptions)\n }\n\n transform({\n adapter: this,\n data: result.docs,\n fields: buildVersionCollectionFields(this.payload.config, collectionConfig),\n operation: 'read',\n })\n\n for (let i = 0; i < result.docs.length; i++) {\n const id = result.docs[i].parent\n result.docs[i] = result.docs[i].version\n result.docs[i].id = id\n }\n\n return result\n}\n"],"names":["buildVersionCollectionFields","combineQueries","flattenWhereToOperators","buildQuery","buildSortParam","buildJoinAggregation","buildProjectionFromSelect","getSession","transform","queryDrafts","collection","joins","limit","locale","page","pagination","req","select","sort","sortArg","where","VersionModel","versions","collectionConfig","payload","collections","config","options","session","hasNearConstraint","constraints","some","prop","Object","keys","key","fields","flattenedFields","defaultSort","timestamps","combinedWhere","latest","equals","versionQuery","adapter","projection","useEstimatedCount","length","paginationOptions","lean","leanWithId","collation","defaultLocale","disableIndexHints","useCustomCountFn","Promise","resolve","countDocuments","hint","_id","result","aggregate","query","aggregatePaginate","paginate","data","docs","operation","i","id","parent","version"],"mappings":"AAGA,SAASA,4BAA4B,EAAEC,cAAc,EAAEC,uBAAuB,QAAQ,UAAS;AAI/F,SAASC,UAAU,QAAQ,0BAAyB;AACpD,SAASC,cAAc,QAAQ,8BAA6B;AAC5D,SAASC,oBAAoB,QAAQ,sCAAqC;AAC1E,SAASC,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,SAAS,QAAQ,2BAA0B;AAEpD,OAAO,MAAMC,cAA2B,eAAeA,YAErD,EAAEC,UAAU,EAAEC,KAAK,EAAEC,KAAK,EAAEC,MAAM,EAAEC,IAAI,EAAEC,UAAU,EAAEC,GAAG,EAAEC,MAAM,EAAEC,MAAMC,OAAO,EA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AEA,OAAOT;AACT,EAAC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ClientSession } from 'mongodb';
|
|
2
2
|
import type { AggregatePaginateModel, IndexDefinition, IndexOptions, Model, PaginateModel, SchemaOptions } from 'mongoose';
|
|
3
3
|
import type { ArrayField, BlocksField, CheckboxField, CodeField, CollapsibleField, DateField, EmailField, Field, GroupField, JoinField, JSONField, NumberField, Payload, PayloadRequest, PointField, RadioField, RelationshipField, RichTextField, RowField, SanitizedConfig, SelectField, TabsField, TextareaField, TextField, UploadField } from 'payload';
|
|
4
|
-
import type { BuildQueryArgs } from './queries/
|
|
4
|
+
import type { BuildQueryArgs } from './queries/getBuildQueryPlugin.js';
|
|
5
5
|
export interface CollectionModel extends Model<any>, PaginateModel<any>, AggregatePaginateModel<any> {
|
|
6
6
|
/** buildQuery is used to transform payload's where operator into what can be used by mongoose (e.g. id => _id) */
|
|
7
7
|
buildQuery: (args: BuildQueryArgs) => Promise<Record<string, unknown>>;
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAC5C,OAAO,KAAK,EACV,sBAAsB,EACtB,eAAe,EACf,YAAY,EACZ,KAAK,EACL,aAAa,EACb,aAAa,EACd,MAAM,UAAU,CAAA;AACjB,OAAO,KAAK,EACV,UAAU,EACV,WAAW,EACX,aAAa,EACb,SAAS,EACT,gBAAgB,EAChB,SAAS,EACT,UAAU,EACV,KAAK,EACL,UAAU,EACV,SAAS,EACT,SAAS,EACT,WAAW,EACX,OAAO,EACP,cAAc,EACd,UAAU,EACV,UAAU,EACV,iBAAiB,EACjB,aAAa,EACb,QAAQ,EACR,eAAe,EACf,WAAW,EACX,SAAS,EACT,aAAa,EACb,SAAS,EACT,WAAW,EACZ,MAAM,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G;IAC5B;;;;;;;;;;;OAWG;IACH,OAAO,EAAE,OAAO,CAAA;IAChB;;OAEG;IACH,GAAG,EAAE,cAAc,CAAA;IACnB;;;;;;;;;;OAUG;IACH,OAAO,CAAC,EAAE,aAAa,CAAA;CACxB,CAAA"}
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type { ClientSession } from 'mongodb'\nimport type {\n AggregatePaginateModel,\n IndexDefinition,\n IndexOptions,\n Model,\n PaginateModel,\n SchemaOptions,\n} from 'mongoose'\nimport type {\n ArrayField,\n BlocksField,\n CheckboxField,\n CodeField,\n CollapsibleField,\n DateField,\n EmailField,\n Field,\n GroupField,\n JoinField,\n JSONField,\n NumberField,\n Payload,\n PayloadRequest,\n PointField,\n RadioField,\n RelationshipField,\n RichTextField,\n RowField,\n SanitizedConfig,\n SelectField,\n TabsField,\n TextareaField,\n TextField,\n UploadField,\n} from 'payload'\n\nimport type { BuildQueryArgs } from './queries/
|
|
1
|
+
{"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type { ClientSession } from 'mongodb'\nimport type {\n AggregatePaginateModel,\n IndexDefinition,\n IndexOptions,\n Model,\n PaginateModel,\n SchemaOptions,\n} from 'mongoose'\nimport type {\n ArrayField,\n BlocksField,\n CheckboxField,\n CodeField,\n CollapsibleField,\n DateField,\n EmailField,\n Field,\n GroupField,\n JoinField,\n JSONField,\n NumberField,\n Payload,\n PayloadRequest,\n PointField,\n RadioField,\n RelationshipField,\n RichTextField,\n RowField,\n SanitizedConfig,\n SelectField,\n TabsField,\n TextareaField,\n TextField,\n UploadField,\n} from 'payload'\n\nimport type { BuildQueryArgs } from './queries/getBuildQueryPlugin.js'\n\nexport interface CollectionModel\n extends Model<any>,\n PaginateModel<any>,\n AggregatePaginateModel<any> {\n /** buildQuery is used to transform payload's where operator into what can be used by mongoose (e.g. id => _id) */\n buildQuery: (args: BuildQueryArgs) => Promise<Record<string, unknown>> // TODO: Delete this\n}\n\nexport interface AuthCollectionModel extends CollectionModel {\n resetPasswordExpiration: Date\n resetPasswordToken: string\n}\n\nexport type TypeOfIndex = {\n fields: IndexDefinition\n options?: IndexOptions\n}\n\nexport interface GlobalModel extends Model<Document> {\n buildQuery: (query: unknown, locale?: string) => Promise<Record<string, unknown>>\n}\n\nexport type BuildSchema<TSchema> = (args: {\n config: SanitizedConfig\n fields: Field[]\n options: BuildSchemaOptions\n}) => TSchema\n\nexport type BuildSchemaOptions = {\n allowIDField?: boolean\n disableUnique?: boolean\n draftsEnabled?: boolean\n indexSortableFields?: boolean\n options?: SchemaOptions\n}\n\nexport type FieldGenerator<TSchema, TField> = {\n config: SanitizedConfig\n field: TField\n options: BuildSchemaOptions\n schema: TSchema\n}\n\nexport type FieldGeneratorFunction<TSchema, TField extends Field> = (\n args: FieldGenerator<TSchema, TField>,\n) => void\n\n/**\n * Object mapping types to a schema based on TSchema\n */\nexport type FieldToSchemaMap<TSchema> = {\n array: FieldGeneratorFunction<TSchema, ArrayField>\n blocks: FieldGeneratorFunction<TSchema, BlocksField>\n checkbox: FieldGeneratorFunction<TSchema, CheckboxField>\n code: FieldGeneratorFunction<TSchema, CodeField>\n collapsible: FieldGeneratorFunction<TSchema, CollapsibleField>\n date: FieldGeneratorFunction<TSchema, DateField>\n email: FieldGeneratorFunction<TSchema, EmailField>\n group: FieldGeneratorFunction<TSchema, GroupField>\n join: FieldGeneratorFunction<TSchema, JoinField>\n json: FieldGeneratorFunction<TSchema, JSONField>\n number: FieldGeneratorFunction<TSchema, NumberField>\n point: FieldGeneratorFunction<TSchema, PointField>\n radio: FieldGeneratorFunction<TSchema, RadioField>\n relationship: FieldGeneratorFunction<TSchema, RelationshipField>\n richText: FieldGeneratorFunction<TSchema, RichTextField>\n row: FieldGeneratorFunction<TSchema, RowField>\n select: FieldGeneratorFunction<TSchema, SelectField>\n tabs: FieldGeneratorFunction<TSchema, TabsField>\n text: FieldGeneratorFunction<TSchema, TextField>\n textarea: FieldGeneratorFunction<TSchema, TextareaField>\n upload: FieldGeneratorFunction<TSchema, UploadField>\n}\n\nexport type MigrateUpArgs = {\n /**\n * The Payload instance that you can use to execute Local API methods\n * To use the current transaction you must pass `req` to arguments\n * @example\n * ```ts\n * import { type MigrateUpArgs } from '@payloadcms/db-mongodb'\n *\n * export async function up({ session, payload, req }: MigrateUpArgs): Promise<void> {\n * const posts = await payload.find({ collection: 'posts', req })\n * }\n * ```\n */\n payload: Payload\n /**\n * The `PayloadRequest` object that contains the current transaction\n */\n req: PayloadRequest\n /**\n * The MongoDB client session that you can use to execute MongoDB methods directly within the current transaction.\n * @example\n * ```ts\n * import { type MigrateUpArgs } from '@payloadcms/db-mongodb'\n *\n * export async function up({ session, payload, req }: MigrateUpArgs): Promise<void> {\n * const { rows: posts } = await payload.db.collections.posts.collection.find({ session }).toArray()\n * }\n * ```\n */\n session?: ClientSession\n}\nexport type MigrateDownArgs = {\n /**\n * The Payload instance that you can use to execute Local API methods\n * To use the current transaction you must pass `req` to arguments\n * @example\n * ```ts\n * import { type MigrateDownArgs } from '@payloadcms/db-mongodb'\n *\n * export async function down({ session, payload, req }: MigrateDownArgs): Promise<void> {\n * const posts = await payload.find({ collection: 'posts', req })\n * }\n * ```\n */\n payload: Payload\n /**\n * The `PayloadRequest` object that contains the current transaction\n */\n req: PayloadRequest\n /**\n * The MongoDB client session that you can use to execute MongoDB methods directly within the current transaction.\n * @example\n * ```ts\n * import { type MigrateDownArgs } from '@payloadcms/db-mongodb'\n *\n * export async function down({ session, payload, req }: MigrateDownArgs): Promise<void> {\n * const { rows: posts } = await payload.db.collections.posts.collection.find({ session }).toArray()\n * }\n * ```\n */\n session?: ClientSession\n}\n"],"names":[],"mappings":"AAgJA,WA8BC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"updateGlobal.d.ts","sourceRoot":"","sources":["../src/updateGlobal.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"updateGlobal.d.ts","sourceRoot":"","sources":["../src/updateGlobal.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAQ3C,eAAO,MAAM,YAAY,EAAE,YA0B1B,CAAA"}
|
package/dist/updateGlobal.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
|
|
2
2
|
import { getSession } from './utilities/getSession.js';
|
|
3
|
-
import {
|
|
4
|
-
import { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.js';
|
|
3
|
+
import { transform } from './utilities/transform.js';
|
|
5
4
|
export const updateGlobal = async function updateGlobal({ slug, data, options: optionsArgs = {}, req, select }) {
|
|
6
5
|
const Model = this.globals;
|
|
7
6
|
const fields = this.payload.config.globals.find((global)=>global.slug === slug).fields;
|
|
@@ -16,19 +15,23 @@ export const updateGlobal = async function updateGlobal({ slug, data, options: o
|
|
|
16
15
|
}),
|
|
17
16
|
session: await getSession(this, req)
|
|
18
17
|
};
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
config: this.payload.config,
|
|
18
|
+
transform({
|
|
19
|
+
adapter: this,
|
|
22
20
|
data,
|
|
23
|
-
fields
|
|
21
|
+
fields,
|
|
22
|
+
globalSlug: slug,
|
|
23
|
+
operation: 'write'
|
|
24
24
|
});
|
|
25
|
-
result = await Model.findOneAndUpdate({
|
|
25
|
+
const result = await Model.findOneAndUpdate({
|
|
26
26
|
globalType: slug
|
|
27
|
-
},
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
27
|
+
}, data, options);
|
|
28
|
+
transform({
|
|
29
|
+
adapter: this,
|
|
30
|
+
data: result,
|
|
31
|
+
fields,
|
|
32
|
+
globalSlug: slug,
|
|
33
|
+
operation: 'read'
|
|
34
|
+
});
|
|
32
35
|
return result;
|
|
33
36
|
};
|
|
34
37
|
|
package/dist/updateGlobal.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/updateGlobal.ts"],"sourcesContent":["import type { QueryOptions } from 'mongoose'\nimport type { UpdateGlobal } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getSession } from './utilities/getSession.js'\nimport {
|
|
1
|
+
{"version":3,"sources":["../src/updateGlobal.ts"],"sourcesContent":["import type { QueryOptions } from 'mongoose'\nimport type { UpdateGlobal } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getSession } from './utilities/getSession.js'\nimport { transform } from './utilities/transform.js'\n\nexport const updateGlobal: UpdateGlobal = async function updateGlobal(\n this: MongooseAdapter,\n { slug, data, options: optionsArgs = {}, req, select },\n) {\n const Model = this.globals\n const fields = this.payload.config.globals.find((global) => global.slug === slug).fields\n\n const options: QueryOptions = {\n ...optionsArgs,\n lean: true,\n new: true,\n projection: buildProjectionFromSelect({\n adapter: this,\n fields: this.payload.config.globals.find((global) => global.slug === slug).flattenedFields,\n select,\n }),\n session: await getSession(this, req),\n }\n\n transform({ adapter: this, data, fields, globalSlug: slug, operation: 'write' })\n\n const result: any = await Model.findOneAndUpdate({ globalType: slug }, data, options)\n\n transform({ adapter: this, data: result, fields, globalSlug: slug, operation: 'read' })\n\n return result\n}\n"],"names":["buildProjectionFromSelect","getSession","transform","updateGlobal","slug","data","options","optionsArgs","req","select","Model","globals","fields","payload","config","find","global","lean","new","projection","adapter","flattenedFields","session","globalSlug","operation","result","findOneAndUpdate","globalType"],"mappings":"AAKA,SAASA,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,SAAS,QAAQ,2BAA0B;AAEpD,OAAO,MAAMC,eAA6B,eAAeA,aAEvD,EAAEC,IAAI,EAAEC,IAAI,EAAEC,SAASC,cAAc,CAAC,CAAC,EAAEC,GAAG,EAAEC,MAAM,EAAE;IAEtD,MAAMC,QAAQ,IAAI,CAACC,OAAO;IAC1B,MAAMC,SAAS,IAAI,CAACC,OAAO,CAACC,MAAM,CAACH,OAAO,CAACI,IAAI,CAAC,CAACC,SAAWA,OAAOZ,IAAI,KAAKA,MAAMQ,MAAM;IAExF,MAAMN,UAAwB;QAC5B,GAAGC,WAAW;QACdU,MAAM;QACNC,KAAK;QACLC,YAAYnB,0BAA0B;YACpCoB,SAAS,IAAI;YACbR,QAAQ,IAAI,CAACC,OAAO,CAACC,MAAM,CAACH,OAAO,CAACI,IAAI,CAAC,CAACC,SAAWA,OAAOZ,IAAI,KAAKA,MAAMiB,eAAe;YAC1FZ;QACF;QACAa,SAAS,MAAMrB,WAAW,IAAI,EAAEO;IAClC;IAEAN,UAAU;QAAEkB,SAAS,IAAI;QAAEf;QAAMO;QAAQW,YAAYnB;QAAMoB,WAAW;IAAQ;IAE9E,MAAMC,SAAc,MAAMf,MAAMgB,gBAAgB,CAAC;QAAEC,YAAYvB;IAAK,GAAGC,MAAMC;IAE7EJ,UAAU;QAAEkB,SAAS,IAAI;QAAEf,MAAMoB;QAAQb;QAAQW,YAAYnB;QAAMoB,WAAW;IAAO;IAErF,OAAOC;AACT,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"updateGlobalVersion.d.ts","sourceRoot":"","sources":["../src/updateGlobalVersion.ts"],"names":[],"mappings":"AAEA,OAAO,EAA4B,KAAK,UAAU,EAAE,KAAK,uBAAuB,EAAE,MAAM,SAAS,CAAA;AAEjG,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"updateGlobalVersion.d.ts","sourceRoot":"","sources":["../src/updateGlobalVersion.ts"],"names":[],"mappings":"AAEA,OAAO,EAA4B,KAAK,UAAU,EAAE,KAAK,uBAAuB,EAAE,MAAM,SAAS,CAAA;AAEjG,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAOjD,wBAAsB,mBAAmB,CAAC,CAAC,SAAS,UAAU,EAC5D,IAAI,EAAE,eAAe,EACrB,EACE,EAAE,EACF,MAAM,EAAE,UAAU,EAClB,MAAM,EACN,OAAO,EAAE,WAAgB,EACzB,GAAG,EACH,MAAM,EACN,WAAW,EACX,KAAK,GACN,EAAE,uBAAuB,CAAC,CAAC,CAAC,gBAsC9B"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { buildVersionGlobalFields } from 'payload';
|
|
2
|
+
import { buildQuery } from './queries/buildQuery.js';
|
|
2
3
|
import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
|
|
3
4
|
import { getSession } from './utilities/getSession.js';
|
|
4
|
-
import {
|
|
5
|
+
import { transform } from './utilities/transform.js';
|
|
5
6
|
export async function updateGlobalVersion({ id, global: globalSlug, locale, options: optionsArgs = {}, req, select, versionData, where }) {
|
|
6
7
|
const VersionModel = this.versions[globalSlug];
|
|
7
8
|
const whereToUse = where || {
|
|
@@ -11,36 +12,41 @@ export async function updateGlobalVersion({ id, global: globalSlug, locale, opti
|
|
|
11
12
|
};
|
|
12
13
|
const currentGlobal = this.payload.config.globals.find((global)=>global.slug === globalSlug);
|
|
13
14
|
const fields = buildVersionGlobalFields(this.payload.config, currentGlobal);
|
|
15
|
+
const flattenedFields = buildVersionGlobalFields(this.payload.config, currentGlobal, true);
|
|
14
16
|
const options = {
|
|
15
17
|
...optionsArgs,
|
|
16
18
|
lean: true,
|
|
17
19
|
new: true,
|
|
18
20
|
projection: buildProjectionFromSelect({
|
|
19
21
|
adapter: this,
|
|
20
|
-
fields:
|
|
22
|
+
fields: flattenedFields,
|
|
21
23
|
select
|
|
22
24
|
}),
|
|
23
25
|
session: await getSession(this, req)
|
|
24
26
|
};
|
|
25
|
-
const query = await
|
|
27
|
+
const query = await buildQuery({
|
|
28
|
+
adapter: this,
|
|
29
|
+
fields: flattenedFields,
|
|
26
30
|
locale,
|
|
27
|
-
payload: this.payload,
|
|
28
31
|
where: whereToUse
|
|
29
32
|
});
|
|
30
|
-
|
|
31
|
-
|
|
33
|
+
transform({
|
|
34
|
+
adapter: this,
|
|
32
35
|
data: versionData,
|
|
33
|
-
fields
|
|
36
|
+
fields,
|
|
37
|
+
operation: 'write'
|
|
34
38
|
});
|
|
35
|
-
const doc = await VersionModel.findOneAndUpdate(query,
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
// custom id type reset
|
|
39
|
-
result.id = result._id;
|
|
40
|
-
if (verificationToken) {
|
|
41
|
-
result._verificationToken = verificationToken;
|
|
39
|
+
const doc = await VersionModel.findOneAndUpdate(query, versionData, options);
|
|
40
|
+
if (!doc) {
|
|
41
|
+
return null;
|
|
42
42
|
}
|
|
43
|
-
|
|
43
|
+
transform({
|
|
44
|
+
adapter: this,
|
|
45
|
+
data: doc,
|
|
46
|
+
fields,
|
|
47
|
+
operation: 'read'
|
|
48
|
+
});
|
|
49
|
+
return doc;
|
|
44
50
|
}
|
|
45
51
|
|
|
46
52
|
//# sourceMappingURL=updateGlobalVersion.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/updateGlobalVersion.ts"],"sourcesContent":["import type { QueryOptions } from 'mongoose'\n\nimport { buildVersionGlobalFields, type TypeWithID, type UpdateGlobalVersionArgs } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getSession } from './utilities/getSession.js'\nimport {
|
|
1
|
+
{"version":3,"sources":["../src/updateGlobalVersion.ts"],"sourcesContent":["import type { QueryOptions } from 'mongoose'\n\nimport { buildVersionGlobalFields, type TypeWithID, type UpdateGlobalVersionArgs } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getSession } from './utilities/getSession.js'\nimport { transform } from './utilities/transform.js'\n\nexport async function updateGlobalVersion<T extends TypeWithID>(\n this: MongooseAdapter,\n {\n id,\n global: globalSlug,\n locale,\n options: optionsArgs = {},\n req,\n select,\n versionData,\n where,\n }: UpdateGlobalVersionArgs<T>,\n) {\n const VersionModel = this.versions[globalSlug]\n const whereToUse = where || { id: { equals: id } }\n\n const currentGlobal = this.payload.config.globals.find((global) => global.slug === globalSlug)\n const fields = buildVersionGlobalFields(this.payload.config, currentGlobal)\n const flattenedFields = buildVersionGlobalFields(this.payload.config, currentGlobal, true)\n const options: QueryOptions = {\n ...optionsArgs,\n lean: true,\n new: true,\n projection: buildProjectionFromSelect({\n adapter: this,\n fields: flattenedFields,\n select,\n }),\n session: await getSession(this, req),\n }\n\n const query = await buildQuery({\n adapter: this,\n fields: flattenedFields,\n locale,\n where: whereToUse,\n })\n\n transform({ adapter: this, data: versionData, fields, operation: 'write' })\n\n const doc = await VersionModel.findOneAndUpdate(query, versionData, options)\n\n if (!doc) {\n return null\n }\n\n transform({ adapter: this, data: doc, fields, operation: 'read' })\n\n return doc\n}\n"],"names":["buildVersionGlobalFields","buildQuery","buildProjectionFromSelect","getSession","transform","updateGlobalVersion","id","global","globalSlug","locale","options","optionsArgs","req","select","versionData","where","VersionModel","versions","whereToUse","equals","currentGlobal","payload","config","globals","find","slug","fields","flattenedFields","lean","new","projection","adapter","session","query","data","operation","doc","findOneAndUpdate"],"mappings":"AAEA,SAASA,wBAAwB,QAAuD,UAAS;AAIjG,SAASC,UAAU,QAAQ,0BAAyB;AACpD,SAASC,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,SAAS,QAAQ,2BAA0B;AAEpD,OAAO,eAAeC,oBAEpB,EACEC,EAAE,EACFC,QAAQC,UAAU,EAClBC,MAAM,EACNC,SAASC,cAAc,CAAC,CAAC,EACzBC,GAAG,EACHC,MAAM,EACNC,WAAW,EACXC,KAAK,EACsB;IAE7B,MAAMC,eAAe,IAAI,CAACC,QAAQ,CAACT,WAAW;IAC9C,MAAMU,aAAaH,SAAS;QAAET,IAAI;YAAEa,QAAQb;QAAG;IAAE;IAEjD,MAAMc,gBAAgB,IAAI,CAACC,OAAO,CAACC,MAAM,CAACC,OAAO,CAACC,IAAI,CAAC,CAACjB,SAAWA,OAAOkB,IAAI,KAAKjB;IACnF,MAAMkB,SAAS1B,yBAAyB,IAAI,CAACqB,OAAO,CAACC,MAAM,EAAEF;IAC7D,MAAMO,kBAAkB3B,yBAAyB,IAAI,CAACqB,OAAO,CAACC,MAAM,EAAEF,eAAe;IACrF,MAAMV,UAAwB;QAC5B,GAAGC,WAAW;QACdiB,MAAM;QACNC,KAAK;QACLC,YAAY5B,0BAA0B;YACpC6B,SAAS,IAAI;YACbL,QAAQC;YACRd;QACF;QACAmB,SAAS,MAAM7B,WAAW,IAAI,EAAES;IAClC;IAEA,MAAMqB,QAAQ,MAAMhC,WAAW;QAC7B8B,SAAS,IAAI;QACbL,QAAQC;QACRlB;QACAM,OAAOG;IACT;IAEAd,UAAU;QAAE2B,SAAS,IAAI;QAAEG,MAAMpB;QAAaY;QAAQS,WAAW;IAAQ;IAEzE,MAAMC,MAAM,MAAMpB,aAAaqB,gBAAgB,CAACJ,OAAOnB,aAAaJ;IAEpE,IAAI,CAAC0B,KAAK;QACR,OAAO;IACT;IAEAhC,UAAU;QAAE2B,SAAS,IAAI;QAAEG,MAAME;QAAKV;QAAQS,WAAW;IAAO;IAEhE,OAAOC;AACT"}
|
package/dist/updateOne.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import { buildQuery } from './queries/buildQuery.js';
|
|
1
2
|
import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
|
|
2
3
|
import { getSession } from './utilities/getSession.js';
|
|
3
4
|
import { handleError } from './utilities/handleError.js';
|
|
4
|
-
import {
|
|
5
|
-
import { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.js';
|
|
5
|
+
import { transform } from './utilities/transform.js';
|
|
6
6
|
export const updateOne = async function updateOne({ id, collection, data, locale, options: optionsArgs = {}, req, select, where: whereArg }) {
|
|
7
7
|
const where = id ? {
|
|
8
8
|
id: {
|
|
@@ -22,19 +22,22 @@ export const updateOne = async function updateOne({ id, collection, data, locale
|
|
|
22
22
|
}),
|
|
23
23
|
session: await getSession(this, req)
|
|
24
24
|
};
|
|
25
|
-
const query = await
|
|
25
|
+
const query = await buildQuery({
|
|
26
|
+
adapter: this,
|
|
27
|
+
collectionSlug: collection,
|
|
28
|
+
fields: this.payload.collections[collection].config.flattenedFields,
|
|
26
29
|
locale,
|
|
27
|
-
payload: this.payload,
|
|
28
30
|
where
|
|
29
31
|
});
|
|
30
32
|
let result;
|
|
31
|
-
|
|
32
|
-
|
|
33
|
+
transform({
|
|
34
|
+
adapter: this,
|
|
33
35
|
data,
|
|
34
|
-
fields
|
|
36
|
+
fields,
|
|
37
|
+
operation: 'write'
|
|
35
38
|
});
|
|
36
39
|
try {
|
|
37
|
-
result = await Model.findOneAndUpdate(query,
|
|
40
|
+
result = await Model.findOneAndUpdate(query, data, options);
|
|
38
41
|
} catch (error) {
|
|
39
42
|
handleError({
|
|
40
43
|
collection,
|
|
@@ -42,9 +45,15 @@ export const updateOne = async function updateOne({ id, collection, data, locale
|
|
|
42
45
|
req
|
|
43
46
|
});
|
|
44
47
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
+
if (!result) {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
transform({
|
|
52
|
+
adapter: this,
|
|
53
|
+
data: result,
|
|
54
|
+
fields,
|
|
55
|
+
operation: 'read'
|
|
56
|
+
});
|
|
48
57
|
return result;
|
|
49
58
|
};
|
|
50
59
|
|
package/dist/updateOne.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/updateOne.ts"],"sourcesContent":["import type { QueryOptions } from 'mongoose'\nimport type { UpdateOne } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport {
|
|
1
|
+
{"version":3,"sources":["../src/updateOne.ts"],"sourcesContent":["import type { QueryOptions } from 'mongoose'\nimport type { UpdateOne } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getSession } from './utilities/getSession.js'\nimport { handleError } from './utilities/handleError.js'\nimport { transform } from './utilities/transform.js'\n\nexport const updateOne: UpdateOne = async function updateOne(\n this: MongooseAdapter,\n { id, collection, data, locale, options: optionsArgs = {}, req, select, where: whereArg },\n) {\n const where = id ? { id: { equals: id } } : whereArg\n const Model = this.collections[collection]\n const fields = this.payload.collections[collection].config.fields\n const options: QueryOptions = {\n ...optionsArgs,\n lean: true,\n new: true,\n projection: buildProjectionFromSelect({\n adapter: this,\n fields: this.payload.collections[collection].config.flattenedFields,\n select,\n }),\n session: await getSession(this, req),\n }\n\n const query = await buildQuery({\n adapter: this,\n collectionSlug: collection,\n fields: this.payload.collections[collection].config.flattenedFields,\n locale,\n where,\n })\n\n let result\n\n transform({ adapter: this, data, fields, operation: 'write' })\n\n try {\n result = await Model.findOneAndUpdate(query, data, options)\n } catch (error) {\n handleError({ collection, error, req })\n }\n\n if (!result) {\n return null\n }\n\n transform({ adapter: this, data: result, fields, operation: 'read' })\n\n return result\n}\n"],"names":["buildQuery","buildProjectionFromSelect","getSession","handleError","transform","updateOne","id","collection","data","locale","options","optionsArgs","req","select","where","whereArg","equals","Model","collections","fields","payload","config","lean","new","projection","adapter","flattenedFields","session","query","collectionSlug","result","operation","findOneAndUpdate","error"],"mappings":"AAKA,SAASA,UAAU,QAAQ,0BAAyB;AACpD,SAASC,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,WAAW,QAAQ,6BAA4B;AACxD,SAASC,SAAS,QAAQ,2BAA0B;AAEpD,O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Version.d.ts","sourceRoot":"","sources":["../src/updateVersion.ts"],"names":[],"mappings":"AAEA,OAAO,EAAgC,KAAK,aAAa,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"updateVersion.d.ts","sourceRoot":"","sources":["../src/updateVersion.ts"],"names":[],"mappings":"AAEA,OAAO,EAAgC,KAAK,aAAa,EAAE,MAAM,SAAS,CAAA;AAS1E,eAAO,MAAM,aAAa,EAAE,aA+C3B,CAAA"}
|