@payloadcms/db-mongodb 3.10.0 → 3.11.1-canary.3f6217a

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.
Files changed (125) hide show
  1. package/dist/count.d.ts.map +1 -1
  2. package/dist/count.js +22 -18
  3. package/dist/count.js.map +1 -1
  4. package/dist/countGlobalVersions.d.ts.map +1 -1
  5. package/dist/countGlobalVersions.js +22 -18
  6. package/dist/countGlobalVersions.js.map +1 -1
  7. package/dist/countVersions.d.ts.map +1 -1
  8. package/dist/countVersions.js +22 -18
  9. package/dist/countVersions.js.map +1 -1
  10. package/dist/create.d.ts.map +1 -1
  11. package/dist/create.js +24 -21
  12. package/dist/create.js.map +1 -1
  13. package/dist/createGlobal.d.ts.map +1 -1
  14. package/dist/createGlobal.js +20 -20
  15. package/dist/createGlobal.js.map +1 -1
  16. package/dist/createGlobalVersion.d.ts.map +1 -1
  17. package/dist/createGlobalVersion.js +30 -33
  18. package/dist/createGlobalVersion.js.map +1 -1
  19. package/dist/createVersion.d.ts.map +1 -1
  20. package/dist/createVersion.js +31 -34
  21. package/dist/createVersion.js.map +1 -1
  22. package/dist/deleteMany.d.ts.map +1 -1
  23. package/dist/deleteMany.js +4 -5
  24. package/dist/deleteMany.js.map +1 -1
  25. package/dist/deleteOne.d.ts.map +1 -1
  26. package/dist/deleteOne.js +14 -18
  27. package/dist/deleteOne.js.map +1 -1
  28. package/dist/deleteVersions.d.ts.map +1 -1
  29. package/dist/deleteVersions.js +1 -2
  30. package/dist/deleteVersions.js.map +1 -1
  31. package/dist/find.d.ts.map +1 -1
  32. package/dist/find.js +74 -39
  33. package/dist/find.js.map +1 -1
  34. package/dist/findGlobal.d.ts.map +1 -1
  35. package/dist/findGlobal.js +17 -18
  36. package/dist/findGlobal.js.map +1 -1
  37. package/dist/findGlobalVersions.d.ts.map +1 -1
  38. package/dist/findGlobalVersions.js +62 -32
  39. package/dist/findGlobalVersions.js.map +1 -1
  40. package/dist/findOne.d.ts.map +1 -1
  41. package/dist/findOne.js +20 -29
  42. package/dist/findOne.js.map +1 -1
  43. package/dist/findVersions.d.ts.map +1 -1
  44. package/dist/findVersions.js +61 -32
  45. package/dist/findVersions.js.map +1 -1
  46. package/dist/index.d.ts +0 -1
  47. package/dist/index.d.ts.map +1 -1
  48. package/dist/index.js +0 -1
  49. package/dist/index.js.map +1 -1
  50. package/dist/migrateFresh.d.ts.map +1 -1
  51. package/dist/migrateFresh.js.map +1 -1
  52. package/dist/predefinedMigrations/migrateRelationshipsV2_V3.d.ts.map +1 -1
  53. package/dist/predefinedMigrations/migrateRelationshipsV2_V3.js +14 -18
  54. package/dist/predefinedMigrations/migrateRelationshipsV2_V3.js.map +1 -1
  55. package/dist/queries/buildAndOrConditions.d.ts +1 -3
  56. package/dist/queries/buildAndOrConditions.d.ts.map +1 -1
  57. package/dist/queries/buildAndOrConditions.js +1 -2
  58. package/dist/queries/buildAndOrConditions.js.map +1 -1
  59. package/dist/queries/buildQuery.d.ts +0 -2
  60. package/dist/queries/buildQuery.d.ts.map +1 -1
  61. package/dist/queries/buildQuery.js +6 -2
  62. package/dist/queries/buildQuery.js.map +1 -1
  63. package/dist/queries/buildSearchParams.d.ts +1 -3
  64. package/dist/queries/buildSearchParams.d.ts.map +1 -1
  65. package/dist/queries/buildSearchParams.js +10 -14
  66. package/dist/queries/buildSearchParams.js.map +1 -1
  67. package/dist/queries/buildSortParam.d.ts +7 -1
  68. package/dist/queries/buildSortParam.d.ts.map +1 -1
  69. package/dist/queries/buildSortParam.js +2 -2
  70. package/dist/queries/buildSortParam.js.map +1 -1
  71. package/dist/queries/getLocalizedSortProperty.js +2 -2
  72. package/dist/queries/getLocalizedSortProperty.js.map +1 -1
  73. package/dist/queries/parseParams.d.ts +1 -3
  74. package/dist/queries/parseParams.d.ts.map +1 -1
  75. package/dist/queries/parseParams.js +1 -2
  76. package/dist/queries/parseParams.js.map +1 -1
  77. package/dist/queries/sanitizeQueryValue.d.ts.map +1 -1
  78. package/dist/queries/sanitizeQueryValue.js +0 -16
  79. package/dist/queries/sanitizeQueryValue.js.map +1 -1
  80. package/dist/queryDrafts.d.ts.map +1 -1
  81. package/dist/queryDrafts.js +66 -40
  82. package/dist/queryDrafts.js.map +1 -1
  83. package/dist/updateGlobal.d.ts.map +1 -1
  84. package/dist/updateGlobal.js +21 -24
  85. package/dist/updateGlobal.js.map +1 -1
  86. package/dist/updateGlobalVersion.d.ts.map +1 -1
  87. package/dist/updateGlobalVersion.js +26 -28
  88. package/dist/updateGlobalVersion.js.map +1 -1
  89. package/dist/updateOne.d.ts.map +1 -1
  90. package/dist/updateOne.js +23 -28
  91. package/dist/updateOne.js.map +1 -1
  92. package/dist/updateVersion.d.ts.map +1 -1
  93. package/dist/updateVersion.js +24 -27
  94. package/dist/updateVersion.js.map +1 -1
  95. package/dist/utilities/buildJoinAggregation.d.ts +4 -4
  96. package/dist/utilities/buildJoinAggregation.d.ts.map +1 -1
  97. package/dist/utilities/buildJoinAggregation.js +28 -7
  98. package/dist/utilities/buildJoinAggregation.js.map +1 -1
  99. package/dist/utilities/buildProjectionFromSelect.d.ts.map +1 -1
  100. package/dist/utilities/buildProjectionFromSelect.js +1 -18
  101. package/dist/utilities/buildProjectionFromSelect.js.map +1 -1
  102. package/dist/utilities/sanitizeInternalFields.d.ts +2 -0
  103. package/dist/utilities/sanitizeInternalFields.d.ts.map +1 -0
  104. package/dist/utilities/sanitizeInternalFields.js +20 -0
  105. package/dist/utilities/sanitizeInternalFields.js.map +1 -0
  106. package/dist/utilities/sanitizeRelationshipIDs.d.ts +9 -0
  107. package/dist/utilities/sanitizeRelationshipIDs.d.ts.map +1 -0
  108. package/dist/utilities/sanitizeRelationshipIDs.js +125 -0
  109. package/dist/utilities/sanitizeRelationshipIDs.js.map +1 -0
  110. package/dist/utilities/{transform.spec.js → sanitizeRelationshipIDs.spec.js} +7 -23
  111. package/dist/utilities/sanitizeRelationshipIDs.spec.js.map +1 -0
  112. package/package.json +3 -3
  113. package/dist/utilities/findMany.d.ts +0 -20
  114. package/dist/utilities/findMany.d.ts.map +0 -1
  115. package/dist/utilities/findMany.js +0 -84
  116. package/dist/utilities/findMany.js.map +0 -1
  117. package/dist/utilities/getHasNearConstraint.d.ts +0 -3
  118. package/dist/utilities/getHasNearConstraint.d.ts.map +0 -1
  119. package/dist/utilities/getHasNearConstraint.js +0 -26
  120. package/dist/utilities/getHasNearConstraint.js.map +0 -1
  121. package/dist/utilities/transform.d.ts +0 -25
  122. package/dist/utilities/transform.d.ts.map +0 -1
  123. package/dist/utilities/transform.js +0 -254
  124. package/dist/utilities/transform.js.map +0 -1
  125. package/dist/utilities/transform.spec.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/queries/sanitizeQueryValue.ts"],"sourcesContent":["import type { FlattenedBlock, FlattenedField, Payload, RelationshipField } from 'payload'\n\nimport { Types } from 'mongoose'\nimport { createArrayFromCommaDelineated } from 'payload'\n\ntype SanitizeQueryValueArgs = {\n field: FlattenedField\n hasCustomID: boolean\n locale?: string\n operator: string\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\nconst sanitizeCoordinates = (coordinates: unknown[]): unknown[] => {\n const result: unknown[] = []\n\n for (const value of coordinates) {\n if (typeof value === 'string') {\n result.push(Number(value))\n } else if (Array.isArray(value)) {\n result.push(sanitizeCoordinates(value))\n } else {\n result.push(value)\n }\n }\n\n return result\n}\n\n// returns nestedField Field object from blocks.nestedField path because getLocalizedPaths splits them only for relationships\nconst getFieldFromSegments = ({\n field,\n segments,\n}: {\n field: FlattenedBlock | FlattenedField\n segments: string[]\n}) => {\n if ('blocks' in field) {\n for (const block of field.blocks) {\n const field = getFieldFromSegments({ field: block, 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, segments })\n }\n }\n}\n\nexport const sanitizeQueryValue = ({\n field,\n hasCustomID,\n locale,\n operator,\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, 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 (field.localized && payload.config.localization && locale) {\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\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) {\n formattedValue.$maxDistance = parseFloat(maxDistance)\n }\n if (minDistance) {\n formattedValue.$minDistance = parseFloat(minDistance)\n }\n }\n }\n\n if (operator === 'within' || operator === 'intersects') {\n if (\n formattedValue &&\n typeof formattedValue === 'object' &&\n Array.isArray(formattedValue.coordinates)\n ) {\n formattedValue.coordinates = sanitizeCoordinates(formattedValue.coordinates)\n }\n\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","buildExistsQuery","formattedValue","path","treatEmptyString","rawQuery","$and","$exists","$ne","$or","$eq","sanitizeCoordinates","coordinates","result","value","push","Number","Array","isArray","getFieldFromSegments","field","segments","block","blocks","i","length","foundField","flattenedFields","find","each","name","shift","sanitizeQueryValue","hasCustomID","locale","operator","payload","val","formattedOperator","includes","type","split","isValid","ObjectId","undefined","map","id","parsedNumber","parseFloat","isNaN","reduce","formattedValues","inVal","toLowerCase","arrayVal","Boolean","Date","parse","relationTo","localizedPath","localized","config","localization","collections","customIDType","some","toString","endsWith","hasCustomIDType","formattedNumber","lng","lat","maxDistance","minDistance","$geometry","$maxDistance","$minDistance","$options","$regex","replace"],"mappings":"AAEA,SAASA,KAAK,QAAQ,WAAU;AAChC,SAASC,8BAA8B,QAAQ,UAAS;AAYxD,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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;SAAS,CAACqC,QAAQ,CAACnB,MAAMoB,IAAI,GAAG;YAC7D,IAAItC,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;QAAEyB,UAAUG;QAAmBD,KAAKnC;IAAe;AAC5D,EAAC"}
1
+ {"version":3,"sources":["../../src/queries/sanitizeQueryValue.ts"],"sourcesContent":["import type { FlattenedBlock, FlattenedField, Payload, RelationshipField } from 'payload'\n\nimport { Types } from 'mongoose'\nimport { createArrayFromCommaDelineated } from 'payload'\n\ntype SanitizeQueryValueArgs = {\n field: FlattenedField\n hasCustomID: boolean\n locale?: string\n operator: string\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 segments,\n}: {\n field: FlattenedBlock | FlattenedField\n segments: string[]\n}) => {\n if ('blocks' in field) {\n for (const block of field.blocks) {\n const field = getFieldFromSegments({ field: block, 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, segments })\n }\n }\n}\n\nexport const sanitizeQueryValue = ({\n field,\n hasCustomID,\n locale,\n operator,\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, 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 (field.localized && payload.config.localization && locale) {\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\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) {\n formattedValue.$maxDistance = parseFloat(maxDistance)\n }\n if (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","buildExistsQuery","formattedValue","path","treatEmptyString","rawQuery","$and","$exists","$ne","$or","$eq","getFieldFromSegments","field","segments","block","blocks","i","length","foundField","flattenedFields","find","each","name","shift","sanitizeQueryValue","hasCustomID","locale","operator","payload","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","localized","config","localization","collections","customIDType","some","toString","endsWith","hasCustomIDType","formattedNumber","lng","lat","maxDistance","minDistance","$geometry","coordinates","$maxDistance","$minDistance","$options","$regex","replace"],"mappings":"AAEA,SAASA,KAAK,QAAQ,WAAU;AAChC,SAASC,8BAA8B,QAAQ,UAAS;AAYxD,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,QAAQ,EAIT;IACC,IAAI,YAAY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M,WAAW,EAAE,WAuFzB,CAAA"}
1
+ {"version":3,"file":"queryDrafts.d.ts","sourceRoot":"","sources":["../src/queryDrafts.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAY1C,eAAO,MAAM,WAAW,EAAE,WA4HzB,CAAA"}
@@ -1,17 +1,21 @@
1
- import { buildVersionCollectionFields, combineQueries } from 'payload';
1
+ import { buildVersionCollectionFields, combineQueries, flattenWhereToOperators } from 'payload';
2
2
  import { buildSortParam } from './queries/buildSortParam.js';
3
3
  import { buildJoinAggregation } from './utilities/buildJoinAggregation.js';
4
4
  import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
5
- import { findMany } from './utilities/findMany.js';
6
- import { getHasNearConstraint } from './utilities/getHasNearConstraint.js';
7
5
  import { getSession } from './utilities/getSession.js';
8
- import { transform } from './utilities/transform.js';
6
+ import { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js';
9
7
  export const queryDrafts = async function queryDrafts({ collection, joins, limit, locale, page, pagination, req, select, sort: sortArg, where }) {
10
8
  const VersionModel = this.versions[collection];
11
9
  const collectionConfig = this.payload.collections[collection].config;
12
- const session = await getSession(this, req);
13
- const hasNearConstraint = getHasNearConstraint(where);
10
+ const options = {
11
+ session: await getSession(this, req)
12
+ };
13
+ let hasNearConstraint;
14
14
  let sort;
15
+ if (where) {
16
+ const constraints = flattenWhereToOperators(where);
17
+ hasNearConstraint = constraints.some((prop)=>Object.keys(prop).some((key)=>key === 'near'));
18
+ }
15
19
  if (!hasNearConstraint) {
16
20
  sort = buildSortParam({
17
21
  config: this.payload.config,
@@ -29,57 +33,79 @@ export const queryDrafts = async function queryDrafts({ collection, joins, limit
29
33
  const versionQuery = await VersionModel.buildQuery({
30
34
  locale,
31
35
  payload: this.payload,
32
- session,
33
36
  where: combinedWhere
34
37
  });
35
- const versionFields = buildVersionCollectionFields(this.payload.config, collectionConfig, true);
36
38
  const projection = buildProjectionFromSelect({
37
39
  adapter: this,
38
- fields: versionFields,
40
+ fields: buildVersionCollectionFields(this.payload.config, collectionConfig, true),
39
41
  select
40
42
  });
41
43
  // useEstimatedCount is faster, but not accurate, as it ignores any filters. It is thus set to true if there are no filters.
42
44
  const useEstimatedCount = hasNearConstraint || !versionQuery || Object.keys(versionQuery).length === 0;
43
- const collation = this.collation ? {
44
- locale: locale && locale !== 'all' && locale !== '*' ? locale : 'en',
45
- ...this.collation
46
- } : undefined;
47
- const joinAgreggation = await buildJoinAggregation({
45
+ const paginationOptions = {
46
+ lean: true,
47
+ leanWithId: true,
48
+ options,
49
+ page,
50
+ pagination,
51
+ projection,
52
+ sort,
53
+ useEstimatedCount
54
+ };
55
+ if (this.collation) {
56
+ const defaultLocale = 'en';
57
+ paginationOptions.collation = {
58
+ locale: locale && locale !== 'all' && locale !== '*' ? locale : defaultLocale,
59
+ ...this.collation
60
+ };
61
+ }
62
+ if (!useEstimatedCount && Object.keys(versionQuery).length === 0 && this.disableIndexHints !== true) {
63
+ // Improve the performance of the countDocuments query which is used if useEstimatedCount is set to false by adding
64
+ // a hint. By default, if no hint is provided, MongoDB does not use an indexed field to count the returned documents,
65
+ // which makes queries very slow. This only happens when no query (filter) is provided. If one is provided, it uses
66
+ // the correct indexed field
67
+ paginationOptions.useCustomCountFn = ()=>{
68
+ return Promise.resolve(VersionModel.countDocuments(versionQuery, {
69
+ hint: {
70
+ _id: 1
71
+ }
72
+ }));
73
+ };
74
+ }
75
+ if (limit > 0) {
76
+ paginationOptions.limit = limit;
77
+ // limit must also be set here, it's ignored when pagination is false
78
+ paginationOptions.options.limit = limit;
79
+ }
80
+ let result;
81
+ const aggregate = await buildJoinAggregation({
48
82
  adapter: this,
49
83
  collection,
50
84
  collectionConfig,
51
85
  joins,
52
86
  locale,
53
87
  projection,
54
- session,
55
- versions: true
56
- });
57
- const result = await findMany({
58
- adapter: this,
59
- collation,
60
- collection: VersionModel.collection,
61
- joinAgreggation,
62
- limit,
63
- page,
64
- pagination,
65
- projection,
66
88
  query: versionQuery,
67
- session,
68
- sort,
69
- useEstimatedCount
70
- });
71
- transform({
72
- adapter: this,
73
- data: result.docs,
74
- fields: versionFields,
75
- operation: 'read'
89
+ versions: true
76
90
  });
77
- for(let i = 0; i < result.docs.length; i++){
78
- const id = result.docs[i].parent;
79
- result.docs[i] = result.docs[i].version;
80
- result.docs[i].id = id;
91
+ // build join aggregation
92
+ if (aggregate) {
93
+ result = await VersionModel.aggregatePaginate(VersionModel.aggregate(aggregate), paginationOptions);
94
+ } else {
95
+ result = await VersionModel.paginate(versionQuery, paginationOptions);
81
96
  }
82
- return result;
97
+ const docs = JSON.parse(JSON.stringify(result.docs));
98
+ return {
99
+ ...result,
100
+ docs: docs.map((doc)=>{
101
+ doc = {
102
+ _id: doc.parent,
103
+ id: doc.parent,
104
+ ...doc.version
105
+ };
106
+ return sanitizeInternalFields(doc);
107
+ })
108
+ };
83
109
  };
84
110
 
85
111
  //# sourceMappingURL=queryDrafts.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/queryDrafts.ts"],"sourcesContent":["import type { CollationOptions } from 'mongodb'\nimport type { QueryDrafts } from 'payload'\n\nimport { buildVersionCollectionFields, combineQueries } 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 { findMany } from './utilities/findMany.js'\nimport { getHasNearConstraint } from './utilities/getHasNearConstraint.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 session = await getSession(this, req)\n\n const hasNearConstraint = getHasNearConstraint(where)\n let sort\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 versionQuery = await VersionModel.buildQuery({\n locale,\n payload: this.payload,\n session,\n where: combinedWhere,\n })\n\n const versionFields = buildVersionCollectionFields(this.payload.config, collectionConfig, true)\n const projection = buildProjectionFromSelect({\n adapter: this,\n fields: versionFields,\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\n const collation: CollationOptions | undefined = this.collation\n ? {\n locale: locale && locale !== 'all' && locale !== '*' ? locale : 'en',\n ...this.collation,\n }\n : undefined\n\n const joinAgreggation = await buildJoinAggregation({\n adapter: this,\n collection,\n collectionConfig,\n joins,\n locale,\n projection,\n session,\n versions: true,\n })\n\n const result = await findMany({\n adapter: this,\n collation,\n collection: VersionModel.collection,\n joinAgreggation,\n limit,\n page,\n pagination,\n projection,\n query: versionQuery,\n session,\n sort,\n useEstimatedCount,\n })\n\n transform({\n adapter: this,\n data: result.docs,\n fields: versionFields,\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","buildSortParam","buildJoinAggregation","buildProjectionFromSelect","findMany","getHasNearConstraint","getSession","transform","queryDrafts","collection","joins","limit","locale","page","pagination","req","select","sort","sortArg","where","VersionModel","versions","collectionConfig","payload","collections","config","session","hasNearConstraint","fields","flattenedFields","defaultSort","timestamps","combinedWhere","latest","equals","versionQuery","buildQuery","versionFields","projection","adapter","useEstimatedCount","Object","keys","length","collation","undefined","joinAgreggation","result","query","data","docs","operation","i","id","parent","version"],"mappings":"AAGA,SAASA,4BAA4B,EAAEC,cAA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H;IAC5H,MAAMwB,oBACJb,qBAAqB,CAACQ,gBAAgBM,OAAOC,IAAI,CAACP,cAAcQ,MAAM,KAAK;IAE7E,MAAMC,YAA0C,IAAI,CAACA,SAAS,GAC1D;QACEhC,QAAQA,UAAUA,WAAW,SAASA,WAAW,MAAMA,SAAS;QAChE,GAAG,IAAI,CAACgC,SAAS;IACnB,IACAC;IAEJ,MAAMC,kBAAkB,MAAM5C,qBAAqB;QACjDqC,SAAS,IAAI;QACb9B;QACAa;QACAZ;QACAE;QACA0B;QACAZ;QACAL,UAAU;IACZ;IAEA,MAAM0B,SAAS,MAAM3C,SAAS;QAC5BmC,SAAS,IAAI;QACbK;QACAnC,YAAYW,aAAaX,UAAU;QACnCqC;QACAnC;QACAE;QACAC;QACAwB;QACAU,OAAOb;QACPT;QACAT;QACAuB;IACF;IAEAjC,UAAU;QACRgC,SAAS,IAAI;QACbU,MAAMF,OAAOG,IAAI;QACjBtB,QAAQS;QACRc,WAAW;IACb;IAEA,IAAK,IAAIC,IAAI,GAAGA,IAAIL,OAAOG,IAAI,CAACP,MAAM,EAAES,IAAK;QAC3C,MAAMC,KAAKN,OAAOG,IAAI,CAACE,EAAE,CAACE,MAAM;QAChCP,OAAOG,IAAI,CAACE,EAAE,GAAGL,OAAOG,IAAI,CAACE,EAAE,CAACG,OAAO;QACvCR,OAAOG,IAAI,CAACE,EAAE,CAACC,EAAE,GAAGA;IACtB;IAEA,OAAON;AACT,EAAC"}
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 { sanitizeInternalFields } from './utilities/sanitizeInternalFields.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 versionQuery = await VersionModel.buildQuery({\n locale,\n payload: this.payload,\n where: combinedWhere,\n })\n\n const projection = buildProjectionFromSelect({\n adapter: this,\n fields: buildVersionCollectionFields(this.payload.config, collectionConfig, true),\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 const docs = JSON.parse(JSON.stringify(result.docs))\n\n return {\n ...result,\n docs: docs.map((doc) => {\n doc = {\n _id: doc.parent,\n id: doc.parent,\n ...doc.version,\n }\n\n return sanitizeInternalFields(doc)\n }),\n }\n}\n"],"names":["buildVersionCollectionFields","combineQueries","flattenWhereToOperators","buildSortParam","buildJoinAggregation","buildProjectionFromSelect","getSession","sanitizeInternalFields","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","buildQuery","projection","adapter","useEstimatedCount","length","paginationOptions","lean","leanWithId","collation","defaultLocale","disableIndexHints","useCustomCountFn","Promise","resolve","countDocuments","hint","_id","result","aggregate","query","aggregatePaginate","paginate","docs","JSON","parse","stringify","map","doc","parent","id","version"],"mappings":"AAGA,SAASA,4BAA4B,EAAEC,cAAc,EAAEC,uBAAuB,QAAQ,UAAS;AAI/F,SAASC,cAAc,QAAQ,8BAA6B;AAC5D,SAASC,oBAAoB,QAAQ,sCAAqC;AAC1E,SAASC,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,sBAAsB,QAAQ,wCAAuC;AAE9E,OAAO,MAAMC,cAA2B,eAAeA,YAErD,EAAEC,UAAU,EAAEC,KAAK,EAAEC,KAAK,E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"updateGlobal.d.ts","sourceRoot":"","sources":["../src/updateGlobal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAQ3C,eAAO,MAAM,YAAY,EAAE,YAoC1B,CAAA"}
1
+ {"version":3,"file":"updateGlobal.d.ts","sourceRoot":"","sources":["../src/updateGlobal.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAS3C,eAAO,MAAM,YAAY,EAAE,YAoC1B,CAAA"}
@@ -1,37 +1,34 @@
1
1
  import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
2
2
  import { getSession } from './utilities/getSession.js';
3
- import { transform } from './utilities/transform.js';
3
+ import { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js';
4
+ import { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.js';
4
5
  export const updateGlobal = async function updateGlobal({ slug, data, options: optionsArgs = {}, req, select }) {
5
6
  const Model = this.globals;
6
- const fields = this.payload.config.globals.find((global)=>global.slug === slug).flattenedFields;
7
- const session = await getSession(this, req);
8
- transform({
9
- adapter: this,
10
- data,
11
- fields,
12
- operation: 'update',
13
- timestamps: optionsArgs.timestamps !== false
14
- });
15
- const result = await Model.collection.findOneAndUpdate({
16
- globalType: slug
17
- }, {
18
- $set: data
19
- }, {
7
+ const fields = this.payload.config.globals.find((global)=>global.slug === slug).fields;
8
+ const options = {
20
9
  ...optionsArgs,
10
+ lean: true,
11
+ new: true,
21
12
  projection: buildProjectionFromSelect({
22
13
  adapter: this,
23
- fields,
14
+ fields: this.payload.config.globals.find((global)=>global.slug === slug).flattenedFields,
24
15
  select
25
16
  }),
26
- returnDocument: 'after',
27
- session
28
- });
29
- transform({
30
- adapter: this,
31
- data: result,
32
- fields,
33
- operation: 'read'
17
+ session: await getSession(this, req)
18
+ };
19
+ let result;
20
+ const sanitizedData = sanitizeRelationshipIDs({
21
+ config: this.payload.config,
22
+ data,
23
+ fields
34
24
  });
25
+ result = await Model.findOneAndUpdate({
26
+ globalType: slug
27
+ }, sanitizedData, options);
28
+ result = JSON.parse(JSON.stringify(result));
29
+ // custom id type reset
30
+ result.id = result._id;
31
+ result = sanitizeInternalFields(result);
35
32
  return result;
36
33
  };
37
34
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/updateGlobal.ts"],"sourcesContent":["import 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).flattenedFields\n\n const session = await getSession(this, req)\n\n transform({\n adapter: this,\n data,\n fields,\n operation: 'update',\n timestamps: optionsArgs.timestamps !== false,\n })\n\n const result: any = await Model.collection.findOneAndUpdate(\n { globalType: slug },\n { $set: data },\n {\n ...optionsArgs,\n projection: buildProjectionFromSelect({ adapter: this, fields, select }),\n returnDocument: 'after',\n session,\n },\n )\n\n transform({\n adapter: this,\n data: result,\n fields,\n operation: 'read',\n })\n\n return result\n}\n"],"names":["buildProjectionFromSelect","getSession","transform","updateGlobal","slug","data","options","optionsArgs","req","select","Model","globals","fields","payload","config","find","global","flattenedFields","session","adapter","operation","timestamps","result","collection","findOneAndUpdate","globalType","$set","projection","returnDocument"],"mappings":"AAIA,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,MAAMa,eAAe;IAEjG,MAAMC,UAAU,MAAMjB,WAAW,IAAI,EAAEO;IAEvCN,UAAU;QACRiB,SAAS,IAAI;QACbd;QACAO;QACAQ,WAAW;QACXC,YAAYd,YAAYc,UAAU,KAAK;IACzC;IAEA,MAAMC,SAAc,MAAMZ,MAAMa,UAAU,CAACC,gBAAgB,CACzD;QAAEC,YAAYrB;IAAK,GACnB;QAAEsB,MAAMrB;IAAK,GACb;QACE,GAAGE,WAAW;QACdoB,YAAY3B,0BAA0B;YAAEmB,SAAS,IAAI;YAAEP;YAAQH;QAAO;QACtEmB,gBAAgB;QAChBV;IACF;IAGFhB,UAAU;QACRiB,SAAS,IAAI;QACbd,MAAMiB;QACNV;QACAQ,WAAW;IACb;IAEA,OAAOE;AACT,EAAC"}
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 { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js'\nimport { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.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 let result\n\n const sanitizedData = sanitizeRelationshipIDs({\n config: this.payload.config,\n data,\n fields,\n })\n\n result = await Model.findOneAndUpdate({ globalType: slug }, sanitizedData, options)\n\n result = JSON.parse(JSON.stringify(result))\n\n // custom id type reset\n result.id = result._id\n result = sanitizeInternalFields(result)\n\n return result\n}\n"],"names":["buildProjectionFromSelect","getSession","sanitizeInternalFields","sanitizeRelationshipIDs","updateGlobal","slug","data","options","optionsArgs","req","select","Model","globals","fields","payload","config","find","global","lean","new","projection","adapter","flattenedFields","session","result","sanitizedData","findOneAndUpdate","globalType","JSON","parse","stringify","id","_id"],"mappings":"AAKA,SAASA,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,sBAAsB,QAAQ,wCAAuC;AAC9E,SAASC,uBAAuB,QAAQ,yCAAwC;AAEhF,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,YAAYpB,0BAA0B;YACpCqB,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,MAAMtB,WAAW,IAAI,EAAEQ;IAClC;IAEA,IAAIe;IAEJ,MAAMC,gBAAgBtB,wBAAwB;QAC5CY,QAAQ,IAAI,CAACD,OAAO,CAACC,MAAM;QAC3BT;QACAO;IACF;IAEAW,SAAS,MAAMb,MAAMe,gBAAgB,CAAC;QAAEC,YAAYtB;IAAK,GAAGoB,eAAelB;IAE3EiB,SAASI,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACN;IAEnC,uBAAuB;IACvBA,OAAOO,EAAE,GAAGP,OAAOQ,GAAG;IACtBR,SAAStB,uBAAuBsB;IAEhC,OAAOA;AACT,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"updateGlobalVersion.d.ts","sourceRoot":"","sources":["../src/updateGlobalVersion.ts"],"names":[],"mappings":"AAAA,OAAO,EAA4B,KAAK,UAAU,EAAE,KAAK,uBAAuB,EAAE,MAAM,SAAS,CAAA;AAEjG,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAMjD,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,gBAkD9B"}
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;AAMjD,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,gBA4C9B"}
@@ -1,7 +1,7 @@
1
1
  import { buildVersionGlobalFields } from 'payload';
2
2
  import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
3
3
  import { getSession } from './utilities/getSession.js';
4
- import { transform } from './utilities/transform.js';
4
+ import { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.js';
5
5
  export async function updateGlobalVersion({ id, global: globalSlug, locale, options: optionsArgs = {}, req, select, versionData, where }) {
6
6
  const VersionModel = this.versions[globalSlug];
7
7
  const whereToUse = where || {
@@ -9,40 +9,38 @@ export async function updateGlobalVersion({ id, global: globalSlug, locale, opti
9
9
  equals: id
10
10
  }
11
11
  };
12
- const fields = buildVersionGlobalFields(this.payload.config, this.payload.config.globals.find((global)=>global.slug === globalSlug), true);
13
- const session = await getSession(this, req);
14
- const query = await VersionModel.buildQuery({
15
- locale,
16
- payload: this.payload,
17
- session,
18
- where: whereToUse
19
- });
20
- transform({
21
- adapter: this,
22
- data: versionData,
23
- fields,
24
- operation: 'update',
25
- timestamps: optionsArgs.timestamps !== false
26
- });
27
- const doc = await VersionModel.collection.findOneAndUpdate(query, {
28
- $set: versionData
29
- }, {
12
+ const currentGlobal = this.payload.config.globals.find((global)=>global.slug === globalSlug);
13
+ const fields = buildVersionGlobalFields(this.payload.config, currentGlobal);
14
+ const options = {
30
15
  ...optionsArgs,
16
+ lean: true,
17
+ new: true,
31
18
  projection: buildProjectionFromSelect({
32
19
  adapter: this,
33
- fields,
20
+ fields: buildVersionGlobalFields(this.payload.config, currentGlobal, true),
34
21
  select
35
22
  }),
36
- returnDocument: 'after',
37
- session
23
+ session: await getSession(this, req)
24
+ };
25
+ const query = await VersionModel.buildQuery({
26
+ locale,
27
+ payload: this.payload,
28
+ where: whereToUse
38
29
  });
39
- transform({
40
- adapter: this,
41
- data: doc,
42
- fields,
43
- operation: 'read'
30
+ const sanitizedData = sanitizeRelationshipIDs({
31
+ config: this.payload.config,
32
+ data: versionData,
33
+ fields
44
34
  });
45
- return doc;
35
+ const doc = await VersionModel.findOneAndUpdate(query, sanitizedData, options);
36
+ const result = JSON.parse(JSON.stringify(doc));
37
+ const verificationToken = doc._verificationToken;
38
+ // custom id type reset
39
+ result.id = result._id;
40
+ if (verificationToken) {
41
+ result._verificationToken = verificationToken;
42
+ }
43
+ return result;
46
44
  }
47
45
 
48
46
  //# sourceMappingURL=updateGlobalVersion.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/updateGlobalVersion.ts"],"sourcesContent":["import { 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 { 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 const fields = buildVersionGlobalFields(\n this.payload.config,\n this.payload.config.globals.find((global) => global.slug === globalSlug),\n true,\n )\n\n const session = await getSession(this, req)\n\n const query = await VersionModel.buildQuery({\n locale,\n payload: this.payload,\n session,\n where: whereToUse,\n })\n\n transform({\n adapter: this,\n data: versionData,\n fields,\n operation: 'update',\n timestamps: optionsArgs.timestamps !== false,\n })\n\n const doc: any = await VersionModel.collection.findOneAndUpdate(\n query,\n { $set: versionData },\n {\n ...optionsArgs,\n projection: buildProjectionFromSelect({\n adapter: this,\n fields,\n select,\n }),\n returnDocument: 'after',\n session,\n },\n )\n\n transform({\n adapter: this,\n data: doc,\n fields,\n operation: 'read',\n })\n\n return doc\n}\n"],"names":["buildVersionGlobalFields","buildProjectionFromSelect","getSession","transform","updateGlobalVersion","id","global","globalSlug","locale","options","optionsArgs","req","select","versionData","where","VersionModel","versions","whereToUse","equals","fields","payload","config","globals","find","slug","session","query","buildQuery","adapter","data","operation","timestamps","doc","collection","findOneAndUpdate","$set","projection","returnDocument"],"mappings":"AAAA,SAASA,wBAAwB,QAAuD,UAAS;AAIjG,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;IACjD,MAAMc,SAASnB,yBACb,IAAI,CAACoB,OAAO,CAACC,MAAM,EACnB,IAAI,CAACD,OAAO,CAACC,MAAM,CAACC,OAAO,CAACC,IAAI,CAAC,CAACjB,SAAWA,OAAOkB,IAAI,KAAKjB,aAC7D;IAGF,MAAMkB,UAAU,MAAMvB,WAAW,IAAI,EAAES;IAEvC,MAAMe,QAAQ,MAAMX,aAAaY,UAAU,CAAC;QAC1CnB;QACAY,SAAS,IAAI,CAACA,OAAO;QACrBK;QACAX,OAAOG;IACT;IAEAd,UAAU;QACRyB,SAAS,IAAI;QACbC,MAAMhB;QACNM;QACAW,WAAW;QACXC,YAAYrB,YAAYqB,UAAU,KAAK;IACzC;IAEA,MAAMC,MAAW,MAAMjB,aAAakB,UAAU,CAACC,gBAAgB,CAC7DR,OACA;QAAES,MAAMtB;IAAY,GACpB;QACE,GAAGH,WAAW;QACd0B,YAAYnC,0BAA0B;YACpC2B,SAAS,IAAI;YACbT;YACAP;QACF;QACAyB,gBAAgB;QAChBZ;IACF;IAGFtB,UAAU;QACRyB,SAAS,IAAI;QACbC,MAAMG;QACNb;QACAW,WAAW;IACb;IAEA,OAAOE;AACT"}
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 { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.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\n const options: QueryOptions = {\n ...optionsArgs,\n lean: true,\n new: true,\n projection: buildProjectionFromSelect({\n adapter: this,\n fields: buildVersionGlobalFields(this.payload.config, currentGlobal, true),\n select,\n }),\n session: await getSession(this, req),\n }\n\n const query = await VersionModel.buildQuery({\n locale,\n payload: this.payload,\n where: whereToUse,\n })\n\n const sanitizedData = sanitizeRelationshipIDs({\n config: this.payload.config,\n data: versionData,\n fields,\n })\n\n const doc = await VersionModel.findOneAndUpdate(query, sanitizedData, options)\n\n const result = JSON.parse(JSON.stringify(doc))\n\n const verificationToken = doc._verificationToken\n\n // custom id type reset\n result.id = result._id\n if (verificationToken) {\n result._verificationToken = verificationToken\n }\n return result\n}\n"],"names":["buildVersionGlobalFields","buildProjectionFromSelect","getSession","sanitizeRelationshipIDs","updateGlobalVersion","id","global","globalSlug","locale","options","optionsArgs","req","select","versionData","where","VersionModel","versions","whereToUse","equals","currentGlobal","payload","config","globals","find","slug","fields","lean","new","projection","adapter","session","query","buildQuery","sanitizedData","data","doc","findOneAndUpdate","result","JSON","parse","stringify","verificationToken","_verificationToken","_id"],"mappings":"AAEA,SAASA,wBAAwB,QAAuD,UAAS;AAIjG,SAASC,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,UAAU,QAAQ,4BAA2B;AAC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IAC9B;IACA,OAAOJ;AACT"}
@@ -1 +1 @@
1
- {"version":3,"file":"updateOne.d.ts","sourceRoot":"","sources":["../src/updateOne.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AASxC,eAAO,MAAM,SAAS,EAAE,SA+CvB,CAAA"}
1
+ {"version":3,"file":"updateOne.d.ts","sourceRoot":"","sources":["../src/updateOne.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAUxC,eAAO,MAAM,SAAS,EAAE,SA4CvB,CAAA"}
package/dist/updateOne.js CHANGED
@@ -1,7 +1,8 @@
1
1
  import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
2
2
  import { getSession } from './utilities/getSession.js';
3
3
  import { handleError } from './utilities/handleError.js';
4
- import { transform } from './utilities/transform.js';
4
+ import { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js';
5
+ import { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.js';
5
6
  export const updateOne = async function updateOne({ id, collection, data, locale, options: optionsArgs = {}, req, select, where: whereArg }) {
6
7
  const where = id ? {
7
8
  id: {
@@ -9,41 +10,31 @@ export const updateOne = async function updateOne({ id, collection, data, locale
9
10
  }
10
11
  } : whereArg;
11
12
  const Model = this.collections[collection];
12
- const fields = this.payload.collections[collection].config.flattenedFields;
13
- const session = await getSession(this, req);
13
+ const fields = this.payload.collections[collection].config.fields;
14
+ const options = {
15
+ ...optionsArgs,
16
+ lean: true,
17
+ new: true,
18
+ projection: buildProjectionFromSelect({
19
+ adapter: this,
20
+ fields: this.payload.collections[collection].config.flattenedFields,
21
+ select
22
+ }),
23
+ session: await getSession(this, req)
24
+ };
14
25
  const query = await Model.buildQuery({
15
26
  locale,
16
27
  payload: this.payload,
17
- session,
18
28
  where
19
29
  });
20
- transform({
21
- adapter: this,
30
+ let result;
31
+ const sanitizedData = sanitizeRelationshipIDs({
32
+ config: this.payload.config,
22
33
  data,
23
- fields,
24
- operation: 'update',
25
- timestamps: optionsArgs.timestamps !== false
34
+ fields
26
35
  });
27
36
  try {
28
- const result = await Model.collection.findOneAndUpdate(query, {
29
- $set: data
30
- }, {
31
- ...optionsArgs,
32
- projection: buildProjectionFromSelect({
33
- adapter: this,
34
- fields,
35
- select
36
- }),
37
- returnDocument: 'after',
38
- session
39
- });
40
- transform({
41
- adapter: this,
42
- data: result,
43
- fields,
44
- operation: 'read'
45
- });
46
- return result;
37
+ result = await Model.findOneAndUpdate(query, sanitizedData, options);
47
38
  } catch (error) {
48
39
  handleError({
49
40
  collection,
@@ -51,6 +42,10 @@ export const updateOne = async function updateOne({ id, collection, data, locale
51
42
  req
52
43
  });
53
44
  }
45
+ result = JSON.parse(JSON.stringify(result));
46
+ result.id = result._id;
47
+ result = sanitizeInternalFields(result);
48
+ return result;
54
49
  };
55
50
 
56
51
  //# sourceMappingURL=updateOne.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/updateOne.ts"],"sourcesContent":["import type { UpdateOne } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\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.flattenedFields\n\n const session = await getSession(this, req)\n\n const query = await Model.buildQuery({\n locale,\n payload: this.payload,\n session,\n where,\n })\n\n transform({\n adapter: this,\n data,\n fields,\n operation: 'update',\n timestamps: optionsArgs.timestamps !== false,\n })\n\n try {\n const result = await Model.collection.findOneAndUpdate(\n query,\n { $set: data },\n {\n ...optionsArgs,\n projection: buildProjectionFromSelect({ adapter: this, fields, select }),\n returnDocument: 'after',\n session,\n },\n )\n\n transform({\n adapter: this,\n data: result,\n fields,\n operation: 'read',\n })\n return result\n } catch (error) {\n handleError({ collection, error, req })\n }\n}\n"],"names":["buildProjectionFromSelect","getSession","handleError","transform","updateOne","id","collection","data","locale","options","optionsArgs","req","select","where","whereArg","equals","Model","collections","fields","payload","config","flattenedFields","session","query","buildQuery","adapter","operation","timestamps","result","findOneAndUpdate","$set","projection","returnDocument","error"],"mappings":"AAIA,SAASA,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,WAAW,QAAQ,6BAA4B;AACxD,SAASC,SAAS,QAAQ,2BAA0B;AAEpD,OAAO,MAAMC,YAAuB,eAAeA,UAEjD,EAAEC,EAAE,EAAEC,UAAU,EAAEC,IAAI,EAAEC,MAAM,EAAEC,SAASC,cAAc,CAAC,CAAC,EAAEC,GAAG,EAAEC,MAAM,EAAEC,OAAOC,QAAQ,EAAE;IAEzF,MAAMD,QAAQR,KAAK;QAAEA,IAAI;YAAEU,QAAQV;QAAG;IAAE,IAAIS;IAC5C,MAAME,QAAQ,IAAI,CAACC,WAAW,CAACX,WAAW;IAC1C,MAAMY,SAAS,IAAI,CAACC,OAAO,CAACF,WAAW,CAACX,WAAW,CAACc,MAAM,CAACC,eAAe;IAE1E,MAAMC,UAAU,MAAMrB,WAAW,IAAI,EAAEU;IAEvC,MAAMY,QAAQ,MAAMP,MAAMQ,UAAU,CAAC;QACnChB;QACAW,SAAS,IAAI,CAACA,OAAO;QACrBG;QACAT;IACF;IAEAV,UAAU;QACRsB,SAAS,IAAI;QACblB;QACAW;QACAQ,WAAW;QACXC,YAAYjB,YAAYiB,UAAU,KAAK;IACzC;IAEA,IAAI;QACF,MAAMC,SAAS,MAAMZ,MAAMV,UAAU,CAACuB,gBAAgB,CACpDN,OACA;YAAEO,MAAMvB;QAAK,GACb;YACE,GAAGG,WAAW;YACdqB,YAAY/B,0BAA0B;gBAAEyB,SAAS,IAAI;gBAAEP;gBAAQN;YAAO;YACtEoB,gBAAgB;YAChBV;QACF;QAGFnB,UAAU;YACRsB,SAAS,IAAI;YACblB,MAAMqB;YACNV;YACAQ,WAAW;QACb;QACA,OAAOE;IACT,EAAE,OAAOK,OAAO;QACd/B,YAAY;YAAEI;YAAY2B;YAAOtB;QAAI;IACvC;AACF,EAAC"}
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 { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getSession } from './utilities/getSession.js'\nimport { handleError } from './utilities/handleError.js'\nimport { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js'\nimport { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.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 Model.buildQuery({\n locale,\n payload: this.payload,\n where,\n })\n\n let result\n\n const sanitizedData = sanitizeRelationshipIDs({\n config: this.payload.config,\n data,\n fields,\n })\n\n try {\n result = await Model.findOneAndUpdate(query, sanitizedData, options)\n } catch (error) {\n handleError({ collection, error, req })\n }\n\n result = JSON.parse(JSON.stringify(result))\n result.id = result._id\n result = sanitizeInternalFields(result)\n\n return result\n}\n"],"names":["buildProjectionFromSelect","getSession","handleError","sanitizeInternalFields","sanitizeRelationshipIDs","updateOne","id","collection","data","locale","options","optionsArgs","req","select","where","whereArg","equals","Model","collections","fields","payload","config","lean","new","projection","adapter","flattenedFields","session","query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;IAEAkB,SAASI,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACN;IACnCA,OAAOxB,EAAE,GAAGwB,OAAOO,GAAG;IACtBP,SAAS3B,uBAAuB2B;IAEhC,OAAOA;AACT,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"updateVersion.d.ts","sourceRoot":"","sources":["../src/updateVersion.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgC,KAAK,aAAa,EAAE,MAAM,SAAS,CAAA;AAQ1E,eAAO,MAAM,aAAa,EAAE,aAwD3B,CAAA"}
1
+ {"version":3,"file":"updateVersion.d.ts","sourceRoot":"","sources":["../src/updateVersion.ts"],"names":[],"mappings":"AAEA,OAAO,EAAgC,KAAK,aAAa,EAAE,MAAM,SAAS,CAAA;AAQ1E,eAAO,MAAM,aAAa,EAAE,aAmD3B,CAAA"}