@payloadcms/db-mongodb 4.0.0-internal.ea6e8f8 → 4.0.0-internal.ee5d8bd

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 (136) hide show
  1. package/dist/connect.d.ts.map +1 -1
  2. package/dist/connect.js +0 -1
  3. package/dist/connect.js.map +1 -1
  4. package/dist/count.d.ts.map +1 -1
  5. package/dist/count.js +4 -33
  6. package/dist/count.js.map +1 -1
  7. package/dist/countGlobalVersions.d.ts.map +1 -1
  8. package/dist/countGlobalVersions.js +0 -1
  9. package/dist/countGlobalVersions.js.map +1 -1
  10. package/dist/countVersions.d.ts.map +1 -1
  11. package/dist/countVersions.js +4 -36
  12. package/dist/countVersions.js.map +1 -1
  13. package/dist/createGlobalVersion.d.ts.map +1 -1
  14. package/dist/createGlobalVersion.js +0 -22
  15. package/dist/createGlobalVersion.js.map +1 -1
  16. package/dist/createVersion.d.ts.map +1 -1
  17. package/dist/createVersion.js +3 -16
  18. package/dist/createVersion.js.map +1 -1
  19. package/dist/deleteMany.d.ts.map +1 -1
  20. package/dist/deleteMany.js +0 -1
  21. package/dist/deleteMany.js.map +1 -1
  22. package/dist/deleteOne.d.ts.map +1 -1
  23. package/dist/deleteOne.js +1 -20
  24. package/dist/deleteOne.js.map +1 -1
  25. package/dist/deleteVersions.d.ts.map +1 -1
  26. package/dist/deleteVersions.js +0 -1
  27. package/dist/deleteVersions.js.map +1 -1
  28. package/dist/exports/migration-utils.d.ts +0 -1
  29. package/dist/exports/migration-utils.d.ts.map +1 -1
  30. package/dist/exports/migration-utils.js +0 -1
  31. package/dist/exports/migration-utils.js.map +1 -1
  32. package/dist/find.d.ts.map +1 -1
  33. package/dist/find.js +8 -44
  34. package/dist/find.js.map +1 -1
  35. package/dist/findDistinct.d.ts.map +1 -1
  36. package/dist/findDistinct.js +11 -70
  37. package/dist/findDistinct.js.map +1 -1
  38. package/dist/findGlobal.d.ts.map +1 -1
  39. package/dist/findGlobal.js +5 -34
  40. package/dist/findGlobal.js.map +1 -1
  41. package/dist/findGlobalVersions.d.ts.map +1 -1
  42. package/dist/findGlobalVersions.js +2 -10
  43. package/dist/findGlobalVersions.js.map +1 -1
  44. package/dist/findOne.d.ts.map +1 -1
  45. package/dist/findOne.js +5 -43
  46. package/dist/findOne.js.map +1 -1
  47. package/dist/findVersions.d.ts.map +1 -1
  48. package/dist/findVersions.js +5 -49
  49. package/dist/findVersions.js.map +1 -1
  50. package/dist/index.d.ts.map +1 -1
  51. package/dist/index.js +0 -4
  52. package/dist/index.js.map +1 -1
  53. package/dist/models/buildGlobalModel.d.ts.map +1 -1
  54. package/dist/models/buildGlobalModel.js +1 -30
  55. package/dist/models/buildGlobalModel.js.map +1 -1
  56. package/dist/models/buildSchema.d.ts.map +1 -1
  57. package/dist/models/buildSchema.js +10 -30
  58. package/dist/models/buildSchema.js.map +1 -1
  59. package/dist/predefinedMigrations/migrateSizesToVariants.js.map +1 -1
  60. package/dist/queries/buildAndOrConditions.d.ts +2 -4
  61. package/dist/queries/buildAndOrConditions.d.ts.map +1 -1
  62. package/dist/queries/buildAndOrConditions.js +1 -3
  63. package/dist/queries/buildAndOrConditions.js.map +1 -1
  64. package/dist/queries/buildQuery.d.ts +2 -4
  65. package/dist/queries/buildQuery.d.ts.map +1 -1
  66. package/dist/queries/buildQuery.js +1 -3
  67. package/dist/queries/buildQuery.js.map +1 -1
  68. package/dist/queries/buildSearchParams.d.ts +2 -4
  69. package/dist/queries/buildSearchParams.d.ts.map +1 -1
  70. package/dist/queries/buildSearchParams.js +44 -175
  71. package/dist/queries/buildSearchParams.js.map +1 -1
  72. package/dist/queries/getBuildQueryPlugin.d.ts +1 -3
  73. package/dist/queries/getBuildQueryPlugin.d.ts.map +1 -1
  74. package/dist/queries/getBuildQueryPlugin.js +1 -3
  75. package/dist/queries/getBuildQueryPlugin.js.map +1 -1
  76. package/dist/queries/parseParams.d.ts +2 -4
  77. package/dist/queries/parseParams.d.ts.map +1 -1
  78. package/dist/queries/parseParams.js +1 -5
  79. package/dist/queries/parseParams.js.map +1 -1
  80. package/dist/queryDrafts.d.ts.map +1 -1
  81. package/dist/queryDrafts.js +7 -38
  82. package/dist/queryDrafts.js.map +1 -1
  83. package/dist/transactions/commitTransaction.d.ts.map +1 -1
  84. package/dist/transactions/commitTransaction.js +7 -55
  85. package/dist/transactions/commitTransaction.js.map +1 -1
  86. package/dist/transactions/rollbackTransaction.d.ts.map +1 -1
  87. package/dist/transactions/rollbackTransaction.js +9 -10
  88. package/dist/transactions/rollbackTransaction.js.map +1 -1
  89. package/dist/updateGlobal.d.ts.map +1 -1
  90. package/dist/updateGlobal.js +7 -87
  91. package/dist/updateGlobal.js.map +1 -1
  92. package/dist/updateGlobalVersion.d.ts.map +1 -1
  93. package/dist/updateGlobalVersion.js +0 -1
  94. package/dist/updateGlobalVersion.js.map +1 -1
  95. package/dist/updateMany.d.ts.map +1 -1
  96. package/dist/updateMany.js +1 -3
  97. package/dist/updateMany.js.map +1 -1
  98. package/dist/updateOne.d.ts.map +1 -1
  99. package/dist/updateOne.js +2 -28
  100. package/dist/updateOne.js.map +1 -1
  101. package/dist/updateVersion.d.ts.map +1 -1
  102. package/dist/updateVersion.js +0 -1
  103. package/dist/updateVersion.js.map +1 -1
  104. package/dist/utilities/aggregatePaginate.d.ts +1 -2
  105. package/dist/utilities/aggregatePaginate.d.ts.map +1 -1
  106. package/dist/utilities/aggregatePaginate.js +4 -18
  107. package/dist/utilities/aggregatePaginate.js.map +1 -1
  108. package/dist/utilities/buildJoinAggregation.d.ts +2 -4
  109. package/dist/utilities/buildJoinAggregation.d.ts.map +1 -1
  110. package/dist/utilities/buildJoinAggregation.js +23 -118
  111. package/dist/utilities/buildJoinAggregation.js.map +1 -1
  112. package/dist/utilities/resolveJoins.d.ts +2 -6
  113. package/dist/utilities/resolveJoins.d.ts.map +1 -1
  114. package/dist/utilities/resolveJoins.js +26 -114
  115. package/dist/utilities/resolveJoins.js.map +1 -1
  116. package/package.json +16 -19
  117. package/dist/deleteBranchGlobal.d.ts +0 -10
  118. package/dist/deleteBranchGlobal.d.ts.map +0 -1
  119. package/dist/deleteBranchGlobal.js +0 -22
  120. package/dist/deleteBranchGlobal.js.map +0 -1
  121. package/dist/predefinedMigrations/branching.d.ts +0 -4
  122. package/dist/predefinedMigrations/branching.d.ts.map +0 -1
  123. package/dist/predefinedMigrations/branching.js +0 -9
  124. package/dist/predefinedMigrations/branching.js.map +0 -1
  125. package/dist/predefinedMigrations/migrateBranching.d.ts +0 -15
  126. package/dist/predefinedMigrations/migrateBranching.d.ts.map +0 -1
  127. package/dist/predefinedMigrations/migrateBranching.js +0 -88
  128. package/dist/predefinedMigrations/migrateBranching.js.map +0 -1
  129. package/dist/queries/buildBranchVisibility.d.ts +0 -11
  130. package/dist/queries/buildBranchVisibility.d.ts.map +0 -1
  131. package/dist/queries/buildBranchVisibility.js +0 -204
  132. package/dist/queries/buildBranchVisibility.js.map +0 -1
  133. package/dist/upsertBranchGlobalChange.d.ts +0 -3
  134. package/dist/upsertBranchGlobalChange.d.ts.map +0 -1
  135. package/dist/upsertBranchGlobalChange.js +0 -28
  136. package/dist/upsertBranchGlobalChange.js.map +0 -1
@@ -32,7 +32,6 @@ export const updateMany = async function updateMany({ collection: collectionSlug
32
32
  collectionSlug,
33
33
  fields: collectionConfig.flattenedFields,
34
34
  locale,
35
- req,
36
35
  where
37
36
  });
38
37
  const $inc = {};
@@ -79,8 +78,7 @@ export const updateMany = async function updateMany({ collection: collectionSlug
79
78
  adapter: this,
80
79
  fields: collectionConfig.flattenedFields,
81
80
  select
82
- }),
83
- returnDocument: 'after'
81
+ })
84
82
  };
85
83
  try {
86
84
  if (typeof limit === 'number' && limit > 0) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/updateMany.ts"],"sourcesContent":["import type { QueryOptions, UpdateQuery } from 'mongoose'\n\nimport { flattenWhereToOperators, type UpdateMany } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { buildSortParam } from './queries/buildSortParam.js'\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getCollection } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\nimport { handleError } from './utilities/handleError.js'\nimport { transform } from './utilities/transform.js'\n\nexport const updateMany: UpdateMany = async function updateMany(\n this: MongooseAdapter,\n {\n collection: collectionSlug,\n data,\n limit,\n locale,\n options: optionsArgs = {},\n req,\n returning,\n select,\n sort: sortArg,\n where,\n },\n) {\n let hasNearConstraint = false\n\n if (where) {\n const constraints = flattenWhereToOperators(where)\n hasNearConstraint = constraints.some((prop) => Object.keys(prop).some((key) => key === 'near'))\n }\n\n const { collectionConfig, Model } = getCollection({ adapter: this, collectionSlug })\n\n let sort: Record<string, unknown> | undefined\n if (!hasNearConstraint) {\n sort = buildSortParam({\n adapter: this,\n config: this.payload.config,\n fields: collectionConfig.flattenedFields,\n locale,\n sort: sortArg || collectionConfig.defaultSort,\n timestamps: true,\n })\n }\n\n let query = await buildQuery({\n adapter: this,\n collectionSlug,\n fields: collectionConfig.flattenedFields,\n locale,\n req,\n where,\n })\n\n const $inc: Record<string, number> = {}\n const $push: Record<string, { $each: any[] } | any> = {}\n const $addToSet: Record<string, { $each: any[] } | any> = {}\n const $pull: Record<string, { $in: any[] } | any> = {}\n\n transform({\n $addToSet,\n $inc,\n $pull,\n $push,\n adapter: this,\n data,\n fields: collectionConfig.fields,\n operation: 'write',\n })\n\n const updateOps: UpdateQuery<any> = {}\n\n if (Object.keys($inc).length) {\n updateOps.$inc = $inc\n }\n if (Object.keys($push).length) {\n updateOps.$push = $push\n }\n if (Object.keys($addToSet).length) {\n updateOps.$addToSet = $addToSet\n }\n if (Object.keys($pull).length) {\n updateOps.$pull = $pull\n }\n if (Object.keys(updateOps).length) {\n updateOps.$set = data\n data = updateOps\n }\n\n const baseOptions = {\n ...optionsArgs,\n session: await getSession(this, req),\n // Timestamps are manually added by the write transform\n timestamps: false,\n } satisfies QueryOptions\n\n const findOptions: QueryOptions = {\n ...baseOptions,\n lean: true,\n projection: buildProjectionFromSelect({\n adapter: this,\n fields: collectionConfig.flattenedFields,\n select,\n }),\n returnDocument: 'after',\n }\n\n try {\n if (typeof limit === 'number' && limit > 0) {\n const documentsToUpdate = await Model.find(\n query,\n {},\n { ...findOptions, limit, projection: { _id: 1 }, sort },\n )\n if (documentsToUpdate.length === 0) {\n return null\n }\n\n query = { _id: { $in: documentsToUpdate.map((doc) => doc._id) } }\n }\n\n await Model.updateMany(query, data, baseOptions)\n } catch (error) {\n handleError({ collection: collectionSlug, error, req })\n }\n\n if (returning === false) {\n return null\n }\n\n const result = await Model.find(\n query,\n {},\n {\n ...findOptions,\n sort,\n },\n )\n\n transform({\n adapter: this,\n data: result,\n fields: collectionConfig.fields,\n operation: 'read',\n })\n\n return result\n}\n"],"names":["flattenWhereToOperators","buildQuery","buildSortParam","buildProjectionFromSelect","getCollection","getSession","handleError","transform","updateMany","collection","collectionSlug","data","limit","locale","options","optionsArgs","req","returning","select","sort","sortArg","where","hasNearConstraint","constraints","some","prop","Object","keys","key","collectionConfig","Model","adapter","config","payload","fields","flattenedFields","defaultSort","timestamps","query","$inc","$push","$addToSet","$pull","operation","updateOps","length","$set","baseOptions","session","findOptions","lean","projection","returnDocument","documentsToUpdate","find","_id","$in","map","doc","error","result"],"mappings":"AAEA,SAASA,uBAAuB,QAAyB,UAAS;AAIlE,SAASC,UAAU,QAAQ,0BAAyB;AACpD,SAASC,cAAc,QAAQ,8BAA6B;AAC5D,SAASC,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,aAAa,QAAQ,2BAA0B;AACxD,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,WAAW,QAAQ,6BAA4B;AACxD,SAASC,SAAS,QAAQ,2BAA0B;AAEpD,OAAO,MAAMC,aAAyB,eAAeA,WAEnD,EACEC,YAAYC,cAAc,EAC1BC,IAAI,EACJC,KAAK,EACLC,MAAM,E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;AACT,EAAC"}
1
+ {"version":3,"sources":["../src/updateMany.ts"],"sourcesContent":["import type { QueryOptions, UpdateQuery } from 'mongoose'\n\nimport { flattenWhereToOperators, type UpdateMany } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { buildSortParam } from './queries/buildSortParam.js'\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getCollection } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\nimport { handleError } from './utilities/handleError.js'\nimport { transform } from './utilities/transform.js'\n\nexport const updateMany: UpdateMany = async function updateMany(\n this: MongooseAdapter,\n {\n collection: collectionSlug,\n data,\n limit,\n locale,\n options: optionsArgs = {},\n req,\n returning,\n select,\n sort: sortArg,\n where,\n },\n) {\n let hasNearConstraint = false\n\n if (where) {\n const constraints = flattenWhereToOperators(where)\n hasNearConstraint = constraints.some((prop) => Object.keys(prop).some((key) => key === 'near'))\n }\n\n const { collectionConfig, Model } = getCollection({ adapter: this, collectionSlug })\n\n let sort: Record<string, unknown> | undefined\n if (!hasNearConstraint) {\n sort = buildSortParam({\n adapter: this,\n config: this.payload.config,\n fields: collectionConfig.flattenedFields,\n locale,\n sort: sortArg || collectionConfig.defaultSort,\n timestamps: true,\n })\n }\n\n let query = await buildQuery({\n adapter: this,\n collectionSlug,\n fields: collectionConfig.flattenedFields,\n locale,\n where,\n })\n\n const $inc: Record<string, number> = {}\n const $push: Record<string, { $each: any[] } | any> = {}\n const $addToSet: Record<string, { $each: any[] } | any> = {}\n const $pull: Record<string, { $in: any[] } | any> = {}\n\n transform({\n $addToSet,\n $inc,\n $pull,\n $push,\n adapter: this,\n data,\n fields: collectionConfig.fields,\n operation: 'write',\n })\n\n const updateOps: UpdateQuery<any> = {}\n\n if (Object.keys($inc).length) {\n updateOps.$inc = $inc\n }\n if (Object.keys($push).length) {\n updateOps.$push = $push\n }\n if (Object.keys($addToSet).length) {\n updateOps.$addToSet = $addToSet\n }\n if (Object.keys($pull).length) {\n updateOps.$pull = $pull\n }\n if (Object.keys(updateOps).length) {\n updateOps.$set = data\n data = updateOps\n }\n\n const baseOptions = {\n ...optionsArgs,\n session: await getSession(this, req),\n // Timestamps are manually added by the write transform\n timestamps: false,\n } satisfies QueryOptions\n\n const findOptions: QueryOptions = {\n ...baseOptions,\n lean: true,\n projection: buildProjectionFromSelect({\n adapter: this,\n fields: collectionConfig.flattenedFields,\n select,\n }),\n }\n\n try {\n if (typeof limit === 'number' && limit > 0) {\n const documentsToUpdate = await Model.find(\n query,\n {},\n { ...findOptions, limit, projection: { _id: 1 }, sort },\n )\n if (documentsToUpdate.length === 0) {\n return null\n }\n\n query = { _id: { $in: documentsToUpdate.map((doc) => doc._id) } }\n }\n\n await Model.updateMany(query, data, baseOptions)\n } catch (error) {\n handleError({ collection: collectionSlug, error, req })\n }\n\n if (returning === false) {\n return null\n }\n\n const result = await Model.find(\n query,\n {},\n {\n ...findOptions,\n sort,\n },\n )\n\n transform({\n adapter: this,\n data: result,\n fields: collectionConfig.fields,\n operation: 'read',\n })\n\n return result\n}\n"],"names":["flattenWhereToOperators","buildQuery","buildSortParam","buildProjectionFromSelect","getCollection","getSession","handleError","transform","updateMany","collection","collectionSlug","data","limit","locale","options","optionsArgs","req","returning","select","sort","sortArg","where","hasNearConstraint","constraints","some","prop","Object","keys","key","collectionConfig","Model","adapter","config","payload","fields","flattenedFields","defaultSort","timestamps","query","$inc","$push","$addToSet","$pull","operation","updateOps","length","$set","baseOptions","session","findOptions","lean","projection","documentsToUpdate","find","_id","$in","map","doc","error","result"],"mappings":"AAEA,SAASA,uBAAuB,QAAyB,UAAS;AAIlE,SAASC,UAAU,QAAQ,0BAAyB;AACpD,SAASC,cAAc,QAAQ,8BAA6B;AAC5D,SAASC,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,aAAa,QAAQ,2BAA0B;AACxD,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,WAAW,QAAQ,6BAA4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;IAGFZ,UAAU;QACRwB,SAAS,IAAI;QACbpB,MAAMgD;QACNzB,QAAQL,iBAAiBK,MAAM;QAC/BS,WAAW;IACb;IAEA,OAAOgB;AACT,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"updateOne.d.ts","sourceRoot":"","sources":["../src/updateOne.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAaxC,eAAO,MAAM,SAAS,EAAE,SAuHvB,CAAA"}
1
+ {"version":3,"file":"updateOne.d.ts","sourceRoot":"","sources":["../src/updateOne.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAWxC,eAAO,MAAM,SAAS,EAAE,SAsGvB,CAAA"}
package/dist/updateOne.js CHANGED
@@ -1,23 +1,14 @@
1
- import { applyBranchIDProjection, resolveBranchRowID, withBranchIDSelect } from 'payload';
2
1
  import { buildQuery } from './queries/buildQuery.js';
3
2
  import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
4
3
  import { getCollection } from './utilities/getEntity.js';
5
4
  import { getSession } from './utilities/getSession.js';
6
5
  import { handleError } from './utilities/handleError.js';
7
6
  import { transform } from './utilities/transform.js';
8
- export const updateOne = async function updateOne({ id, branch, collection: collectionSlug, data, locale, options: optionsArgs = {}, req, returning, select, where: whereArg = {} }) {
7
+ export const updateOne = async function updateOne({ id, collection: collectionSlug, data, locale, options: optionsArgs = {}, req, returning, select, where: whereArg = {} }) {
9
8
  const { collectionConfig, Model } = getCollection({
10
9
  adapter: this,
11
10
  collectionSlug
12
11
  });
13
- if (id !== undefined && id !== null) {
14
- id = await resolveBranchRowID({
15
- id,
16
- branch,
17
- collectionSlug,
18
- req
19
- });
20
- }
21
12
  const where = id ? {
22
13
  id: {
23
14
  equals: id
@@ -26,11 +17,9 @@ export const updateOne = async function updateOne({ id, branch, collection: coll
26
17
  const fields = collectionConfig.fields;
27
18
  const query = await buildQuery({
28
19
  adapter: this,
29
- branch,
30
20
  collectionSlug,
31
21
  fields: collectionConfig.flattenedFields,
32
22
  locale,
33
- req,
34
23
  where
35
24
  });
36
25
  let result;
@@ -78,12 +67,7 @@ export const updateOne = async function updateOne({ id, branch, collection: coll
78
67
  projection: buildProjectionFromSelect({
79
68
  adapter: this,
80
69
  fields: collectionConfig.flattenedFields,
81
- select: withBranchIDSelect({
82
- branch,
83
- collectionSlug,
84
- req,
85
- select
86
- })
70
+ select
87
71
  }),
88
72
  returnDocument: 'after'
89
73
  };
@@ -116,16 +100,6 @@ export const updateOne = async function updateOne({ id, branch, collection: coll
116
100
  fields,
117
101
  operation: 'read'
118
102
  });
119
- // The row written on a branch is the shadow row, so the document it returns
120
- // carries that row's primary key rather than the document's canonical ID.
121
- applyBranchIDProjection({
122
- branch,
123
- collectionSlug,
124
- docs: [
125
- result
126
- ],
127
- req
128
- });
129
103
  return result;
130
104
  };
131
105
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/updateOne.ts"],"sourcesContent":["import type { QueryOptions, UpdateQuery } from 'mongoose'\nimport type { UpdateOne } from 'payload'\n\nimport { applyBranchIDProjection, resolveBranchRowID, withBranchIDSelect } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getCollection } from './utilities/getEntity.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 {\n id,\n branch,\n collection: collectionSlug,\n data,\n locale,\n options: optionsArgs = {},\n req,\n returning,\n select,\n where: whereArg = {},\n },\n) {\n const { collectionConfig, Model } = getCollection({ adapter: this, collectionSlug })\n\n if (id !== undefined && id !== null) {\n id = await resolveBranchRowID({ id, branch, collectionSlug, req })\n }\n\n const where = id ? { id: { equals: id } } : whereArg\n const fields = collectionConfig.fields\n\n const query = await buildQuery({\n adapter: this,\n branch,\n collectionSlug,\n fields: collectionConfig.flattenedFields,\n locale,\n req,\n where,\n })\n\n let result\n\n let updateData: UpdateQuery<any> = data\n\n const $inc: Record<string, number> = {}\n const $push: Record<string, { $each: any[] } | any> = {}\n const $addToSet: Record<string, { $each: any[] } | any> = {}\n const $pull: Record<string, { $in: any[] } | any> = {}\n\n transform({\n $addToSet,\n $inc,\n $pull,\n $push,\n adapter: this,\n data,\n fields,\n operation: 'write',\n })\n\n const updateOps: UpdateQuery<any> = {}\n\n if (Object.keys($inc).length) {\n updateOps.$inc = $inc\n }\n if (Object.keys($push).length) {\n updateOps.$push = $push\n }\n if (Object.keys($addToSet).length) {\n updateOps.$addToSet = $addToSet\n }\n if (Object.keys($pull).length) {\n updateOps.$pull = $pull\n }\n if (Object.keys(updateOps).length) {\n updateOps.$set = updateData\n updateData = updateOps\n }\n\n const baseOptions = {\n ...optionsArgs,\n session: await getSession(this, req),\n // Timestamps are manually added by the write transform\n timestamps: false,\n } satisfies QueryOptions\n\n const findOptions: QueryOptions = {\n ...baseOptions,\n lean: true,\n projection: buildProjectionFromSelect({\n adapter: this,\n fields: collectionConfig.flattenedFields,\n select: withBranchIDSelect({ branch, collectionSlug, req, select }),\n }),\n returnDocument: 'after',\n }\n\n try {\n if (returning === false) {\n await Model.updateOne(query, updateData, baseOptions)\n transform({ adapter: this, data, fields, operation: 'read' })\n return null\n } else {\n result = await Model.findOneAndUpdate(query, updateData, findOptions)\n }\n } catch (error) {\n handleError({ collection: collectionSlug, error, req })\n }\n\n if (!result) {\n return null\n }\n\n transform({ adapter: this, data: result, fields, operation: 'read' })\n\n // The row written on a branch is the shadow row, so the document it returns\n // carries that row's primary key rather than the document's canonical ID.\n applyBranchIDProjection({\n branch,\n collectionSlug,\n docs: [result as Record<string, unknown>],\n req,\n })\n\n return result\n}\n"],"names":["applyBranchIDProjection","resolveBranchRowID","withBranchIDSelect","buildQuery","buildProjectionFromSelect","getCollection","getSession","handleError","transform","updateOne","id","branch","collection","collectionSlug","data","locale","options","optionsArgs","req","returning","select","where","whereArg","collectionConfig","Model","adapter","undefined","equals","fields","query","flattenedFields","result","updateData","$inc","$push","$addToSet","$pull","operation","updateOps","Object","keys","length","$set","baseOptions","session","timestamps","findOptions","lean","projection","returnDocument","findOneAndUpdate","error","docs"],"mappings":"AAGA,SAASA,uBAAuB,EAAEC,kBAAkB,EAAEC,kBAAkB,QAAQ,UAAS;AAIzF,SAASC,UAAU,QAAQ,0BAAyB;AACpD,SAASC,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,aAAa,QAAQ,2BAA0B;AACxD,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,WAAW,QAAQ,6BAA4B;AACxD,SAASC,SAAS,QAAQ,2BAA0B;AAEpD,OAAO,MAAMC,YAAuB,eAAeA,UAEjD,EACEC,EAAE,EACFC,MAAM,EACNC,YAAYC,cAAc,EAC1BC,IAAI,EACJC,MAAM,EACNC,SAASC,cAAc,CAAC,CAAC,EACzBC,GAAG,EACHC,SAAS,EACTC,MAAM,EACNC,OAAOC,WAAW,CAAC,CAAC,EACrB;IAED,MAAM,EAAEC,gBAAgB,EAAEC,KAAK,EAAE,GAAGnB,cAAc;QAAEoB,SAAS,IAAI;QAAEZ;IAAe;IAElF,IAAIH,OAAOgB,aAAahB,OAAO,MAAM;QACnCA,KAAK,MAAMT,mBAAmB;YAAES;YAAIC;YAAQE;YAAgBK;QAAI;IAClE;IAEA,MAAMG,QAAQX,KAAK;QAAEA,IAAI;YAAEiB,QAAQjB;QAAG;IAAE,IAAIY;IAC5C,MAAMM,SAASL,iBAAiBK,MAAM;IAEtC,MAAMC,QAAQ,MAAM1B,WAAW;QAC7BsB,SAAS,IAAI;QACbd;QACAE;QACAe,QAAQL,iBAAiBO,eAAe;QACxCf;QACAG;QACAG;IACF;IAEA,IAAIU;IAEJ,IAAIC,aAA+BlB;IAEnC,MAAMmB,OAA+B,CAAC;IACtC,MAAMC,Q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AY;YAAEK,YAAYC;YAAgBsC;YAAOjC;QAAI;IACvD;IAEA,IAAI,CAACa,QAAQ;QACX,OAAO;IACT;IAEAvB,UAAU;QAAEiB,SAAS,IAAI;QAAEX,MAAMiB;QAAQH;QAAQS,WAAW;IAAO;IAEnE,4EAA4E;IAC5E,0EAA0E;IAC1ErC,wBAAwB;QACtBW;QACAE;QACAuC,MAAM;YAACrB;SAAkC;QACzCb;IACF;IAEA,OAAOa;AACT,EAAC"}
1
+ {"version":3,"sources":["../src/updateOne.ts"],"sourcesContent":["import type { QueryOptions, UpdateQuery } 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 { getCollection } from './utilities/getEntity.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 {\n id,\n collection: collectionSlug,\n data,\n locale,\n options: optionsArgs = {},\n req,\n returning,\n select,\n where: whereArg = {},\n },\n) {\n const { collectionConfig, Model } = getCollection({ adapter: this, collectionSlug })\n const where = id ? { id: { equals: id } } : whereArg\n const fields = collectionConfig.fields\n\n const query = await buildQuery({\n adapter: this,\n collectionSlug,\n fields: collectionConfig.flattenedFields,\n locale,\n where,\n })\n\n let result\n\n let updateData: UpdateQuery<any> = data\n\n const $inc: Record<string, number> = {}\n const $push: Record<string, { $each: any[] } | any> = {}\n const $addToSet: Record<string, { $each: any[] } | any> = {}\n const $pull: Record<string, { $in: any[] } | any> = {}\n\n transform({\n $addToSet,\n $inc,\n $pull,\n $push,\n adapter: this,\n data,\n fields,\n operation: 'write',\n })\n\n const updateOps: UpdateQuery<any> = {}\n\n if (Object.keys($inc).length) {\n updateOps.$inc = $inc\n }\n if (Object.keys($push).length) {\n updateOps.$push = $push\n }\n if (Object.keys($addToSet).length) {\n updateOps.$addToSet = $addToSet\n }\n if (Object.keys($pull).length) {\n updateOps.$pull = $pull\n }\n if (Object.keys(updateOps).length) {\n updateOps.$set = updateData\n updateData = updateOps\n }\n\n const baseOptions = {\n ...optionsArgs,\n session: await getSession(this, req),\n // Timestamps are manually added by the write transform\n timestamps: false,\n } satisfies QueryOptions\n\n const findOptions: QueryOptions = {\n ...baseOptions,\n lean: true,\n projection: buildProjectionFromSelect({\n adapter: this,\n fields: collectionConfig.flattenedFields,\n select,\n }),\n returnDocument: 'after',\n }\n\n try {\n if (returning === false) {\n await Model.updateOne(query, updateData, baseOptions)\n transform({ adapter: this, data, fields, operation: 'read' })\n return null\n } else {\n result = await Model.findOneAndUpdate(query, updateData, findOptions)\n }\n } catch (error) {\n handleError({ collection: collectionSlug, 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","getCollection","getSession","handleError","transform","updateOne","id","collection","collectionSlug","data","locale","options","optionsArgs","req","returning","select","where","whereArg","collectionConfig","Model","adapter","equals","fields","query","flattenedFields","result","updateData","$inc","$push","$addToSet","$pull","operation","updateOps","Object","keys","length","$set","baseOptions","session","timestamps","findOptions","lean","projection","returnDocument","findOneAndUpdate","error"],"mappings":"AAKA,SAASA,UAAU,QAAQ,0BAAyB;AACpD,SAASC,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,aAAa,QAAQ,2BAA0B;AACxD,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,WAAW,QAAQ,6BAA4B;AACxD,SAASC,SAAS,QAAQ,2BAA0B;AAEpD,OAAO,MAAMC,YAAuB,eAAeA,UAEjD,EACEC,EAAE,EACFC,YAAYC,cAAc,EAC1BC,IAAI,EACJC,MAAM,EACNC,SAASC,cAAc,CAAC,CAAC,EACzBC,GAAG,EACHC,SAAS,EACTC,MAAM,EACNC,OAAOC,WAAW,CAAC,CAAC,EACrB;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ACbE,QAAQJ,iBAAiBM,eAAe;YACxCT;QACF;QACA4B,gBAAgB;IAClB;IAEA,IAAI;QACF,IAAI7B,cAAc,OAAO;YACvB,MAAMK,MAAMd,SAAS,CAACkB,OAAOG,YAAYW;YACzCjC,UAAU;gBAAEgB,SAAS,IAAI;gBAAEX;gBAAMa;gBAAQS,WAAW;YAAO;YAC3D,OAAO;QACT,OAAO;YACLN,SAAS,MAAMN,MAAMyB,gBAAgB,CAACrB,OAAOG,YAAYc;QAC3D;IACF,EAAE,OAAOK,OAAO;QACd1C,YAAY;YAAEI,YAAYC;YAAgBqC;YAAOhC;QAAI;IACvD;IAEA,IAAI,CAACY,QAAQ;QACX,OAAO;IACT;IAEArB,UAAU;QAAEgB,SAAS,IAAI;QAAEX,MAAMgB;QAAQH;QAAQS,WAAW;IAAO;IAEnE,OAAON;AACT,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"updateVersion.d.ts","sourceRoot":"","sources":["../src/updateVersion.ts"],"names":[],"mappings":"AAEA,OAAO,EAAgC,KAAK,aAAa,EAAE,MAAM,SAAS,CAAA;AAU1E,eAAO,MAAM,aAAa,EAAE,aAmE3B,CAAA"}
1
+ {"version":3,"file":"updateVersion.d.ts","sourceRoot":"","sources":["../src/updateVersion.ts"],"names":[],"mappings":"AAEA,OAAO,EAAgC,KAAK,aAAa,EAAE,MAAM,SAAS,CAAA;AAU1E,eAAO,MAAM,aAAa,EAAE,aAkE3B,CAAA"}
@@ -21,7 +21,6 @@ export const updateVersion = async function updateVersion({ id, collection: coll
21
21
  adapter: this,
22
22
  fields: flattenedFields,
23
23
  locale,
24
- req,
25
24
  where: whereToUse
26
25
  });
27
26
  transform({
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/updateVersion.ts"],"sourcesContent":["import type { QueryOptions } from 'mongoose'\n\nimport { buildVersionCollectionFields, type UpdateVersion } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getCollection } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\nimport { transform } from './utilities/transform.js'\n\nexport const updateVersion: UpdateVersion = async function updateVersion(\n this: MongooseAdapter,\n {\n id,\n collection: collectionSlug,\n locale,\n options: optionsArgs = {},\n req,\n returning,\n select,\n versionData,\n where,\n },\n) {\n const { collectionConfig, Model } = getCollection({\n adapter: this,\n collectionSlug,\n versions: true,\n })\n\n const whereToUse = where || { id: { equals: id } }\n const fields = buildVersionCollectionFields(this.payload.config, collectionConfig)\n\n const flattenedFields = buildVersionCollectionFields(this.payload.config, collectionConfig, true)\n\n const query = await buildQuery({\n adapter: this,\n fields: flattenedFields,\n locale,\n req,\n where: whereToUse,\n })\n\n transform({ adapter: this, data: versionData, fields, operation: 'write' })\n\n const baseOptions = {\n ...optionsArgs,\n session: await getSession(this, req),\n // Timestamps are manually added by the write transform\n timestamps: false,\n } satisfies QueryOptions\n\n const findOptions: QueryOptions = {\n ...baseOptions,\n lean: true,\n projection: buildProjectionFromSelect({\n adapter: this,\n fields: flattenedFields,\n select,\n }),\n returnDocument: 'after',\n }\n\n if (returning === false) {\n await Model.updateOne(query, versionData, baseOptions)\n return null\n }\n\n const doc = await Model.findOneAndUpdate(query, versionData, findOptions)\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":["buildVersionCollectionFields","buildQuery","buildProjectionFromSelect","getCollection","getSession","transform","updateVersion","id","collection","collectionSlug","locale","options","optionsArgs","req","returning","select","versionData","where","collectionConfig","Model","adapter","versions","whereToUse","equals","fields","payload","config","flattenedFields","query","data","operation","baseOptions","session","timestamps","findOptions","lean","projection","returnDocument","updateOne","doc","findOneAndUpdate"],"mappings":"AAEA,SAASA,4BAA4B,QAA4B,UAAS;AAI1E,SAASC,UAAU,QAAQ,0BAAyB;AACpD,SAASC,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,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AEAlC,UAAU;QAAEe,SAAS,IAAI;QAAES,MAAMU;QAAKf;QAAQM,WAAW;IAAO;IAEhE,OAAOS;AACT,EAAC"}
1
+ {"version":3,"sources":["../src/updateVersion.ts"],"sourcesContent":["import type { QueryOptions } from 'mongoose'\n\nimport { buildVersionCollectionFields, type UpdateVersion } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getCollection } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\nimport { transform } from './utilities/transform.js'\n\nexport const updateVersion: UpdateVersion = async function updateVersion(\n this: MongooseAdapter,\n {\n id,\n collection: collectionSlug,\n locale,\n options: optionsArgs = {},\n req,\n returning,\n select,\n versionData,\n where,\n },\n) {\n const { collectionConfig, Model } = getCollection({\n adapter: this,\n collectionSlug,\n versions: true,\n })\n\n const whereToUse = where || { id: { equals: id } }\n const fields = buildVersionCollectionFields(this.payload.config, collectionConfig)\n\n const flattenedFields = buildVersionCollectionFields(this.payload.config, collectionConfig, true)\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 baseOptions = {\n ...optionsArgs,\n session: await getSession(this, req),\n // Timestamps are manually added by the write transform\n timestamps: false,\n } satisfies QueryOptions\n\n const findOptions: QueryOptions = {\n ...baseOptions,\n lean: true,\n projection: buildProjectionFromSelect({\n adapter: this,\n fields: flattenedFields,\n select,\n }),\n returnDocument: 'after',\n }\n\n if (returning === false) {\n await Model.updateOne(query, versionData, baseOptions)\n return null\n }\n\n const doc = await Model.findOneAndUpdate(query, versionData, findOptions)\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":["buildVersionCollectionFields","buildQuery","buildProjectionFromSelect","getCollection","getSession","transform","updateVersion","id","collection","collectionSlug","locale","options","optionsArgs","req","returning","select","versionData","where","collectionConfig","Model","adapter","versions","whereToUse","equals","fields","payload","config","flattenedFields","query","data","operation","baseOptions","session","timestamps","findOptions","lean","projection","returnDocument","updateOne","doc","findOneAndUpdate"],"mappings":"AAEA,SAASA,4BAA4B,QAA4B,UAAS;AAI1E,SAASC,UAAU,QAAQ,0BAAyB;AACpD,SAASC,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,aAAa,QAAQ,2BAA0B;AACxD,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,SAAS,QAAQ,2BAA0B;AAEpD,OAAO,MAAMC,gBAA+B,eAAeA,cAEzD,EACEC,EAAE,EACFC,YAAYC,cAAc,EAC1BC,MAAM,EACNC,SAASC,cAAc,CAAC,CAAC,EACzBC,GAAG,EACHC,SAAS,EACTC,MAAM,EACNC,WAAW,EACXC,KAAK,EACN;IAED,MAAM,EAAEC,gBAAgB,EAAEC,KAAK,EAAE,GAAGhB,cAAc;QAChDiB,SAAS,IAAI;QACbX;QACAY,UAAU;IACZ;IAEA,MAAMC,aAAaL,SAAS;QAAEV,IAAI;YAAEgB,QAAQhB;QAAG;IAAE;IACjD,MAAMiB,SAASxB,6BAA6B,IAAI,CAACyB,OAAO,CAACC,MAAM,EAAER;IAEjE,MAAMS,kBAAkB3B,6BAA6B,IAAI,CAACyB,OAAO,CAACC,MAAM,EAAER,kBAAkB;IAE5F,MAAMU,QAAQ,MAAM3B,WAAW;QAC7BmB,SAAS,IAAI;QACbI,QAAQG;QACRjB;QACAO,OAAOK;IACT;IAEAjB,UAAU;QAAEe,SAAS,IAAI;QAAES,MAAMb;QAAaQ;QAAQM,WAAW;IAAQ;IAEzE,MAAMC,cAAc;QAClB,GAAGnB,WAAW;QACdoB,SAAS,MAAM5B,WAAW,IAAI,EAAES;QAChC,uDAAuD;QACvDoB,YAAY;IACd;IAEA,MAAMC,cAA4B;QAChC,GAAGH,WAAW;QACdI,MAAM;QACNC,YAAYlC,0BAA0B;YACpCkB,SAAS,IAAI;YACbI,QAAQG;YACRZ;QACF;QACAsB,gBAAgB;IAClB;IAEA,IAAIvB,cAAc,OAAO;QACvB,MAAMK,MAAMmB,SAAS,CAACV,OAAOZ,aAAae;QAC1C,OAAO;IACT;IAEA,MAAMQ,MAAM,MAAMpB,MAAMqB,gBAAgB,CAACZ,OAAOZ,aAAakB;IAE7D,IAAI,CAACK,KAAK;QACR,OAAO;IACT;IAEAlC,UAAU;QAAEe,SAAS,IAAI;QAAES,MAAMU;QAAKf;QAAQM,WAAW;IAAO;IAEhE,OAAOS;AACT,EAAC"}
@@ -2,9 +2,8 @@ import type { CollationOptions } from 'mongodb';
2
2
  import type { ClientSession, Model, PipelineStage } from 'mongoose';
3
3
  import type { PaginatedDocs } from 'payload';
4
4
  import type { MongooseAdapter } from '../index.js';
5
- export declare const aggregatePaginate: ({ adapter, branchVisibility, collation, joinAggregation, limit, Model, page, pagination, projection, query, session, sort, sortAggregation, useEstimatedCount, }: {
5
+ export declare const aggregatePaginate: ({ adapter, collation, joinAggregation, limit, Model, page, pagination, projection, query, session, sort, sortAggregation, useEstimatedCount, }: {
6
6
  adapter: MongooseAdapter;
7
- branchVisibility?: PipelineStage[];
8
7
  collation?: CollationOptions;
9
8
  joinAggregation?: PipelineStage[];
10
9
  limit?: number;
@@ -1 +1 @@
1
- {"version":3,"file":"aggregatePaginate.d.ts","sourceRoot":"","sources":["../../src/utilities/aggregatePaginate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAC/C,OAAO,KAAK,EAAE,aAAa,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AACnE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAE5C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAElD,eAAO,MAAM,iBAAiB,qKAe3B;IACD,OAAO,EAAE,eAAe,CAAA;IACxB,gBAAgB,C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AAO,CAAA;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACpC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC9B,OAAO,CAAC,EAAE,aAAa,CAAA;IACvB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,eAAe,CAAC,EAAE,aAAa,EAAE,CAAA;IACjC,iBAAiB,CAAC,EAAE,OAAO,CAAA;CAC5B,KAAG,OAAO,CAAC,aAAa,CAAC,GAAG,CAAC,CAwF7B,CAAA"}
@@ -1,9 +1,8 @@
1
- export const aggregatePaginate = async ({ adapter, branchVisibility, collation, joinAggregation, limit, Model, page, pagination, projection, query, session, sort, sortAggregation, useEstimatedCount })=>{
1
+ export const aggregatePaginate = async ({ adapter, collation, joinAggregation, limit, Model, page, pagination, projection, query, session, sort, sortAggregation, useEstimatedCount })=>{
2
2
  const aggregation = [
3
3
  {
4
4
  $match: query
5
- },
6
- ...branchVisibility ?? []
5
+ }
7
6
  ];
8
7
  if (sortAggregation && sortAggregation.length > 0) {
9
8
  for (const stage of sortAggregation){
@@ -41,20 +40,7 @@ export const aggregatePaginate = async ({ adapter, branchVisibility, collation,
41
40
  }
42
41
  let countPromise = Promise.resolve(null);
43
42
  if (pagination !== false && limit) {
44
- if (branchVisibility?.length) {
45
- countPromise = Model.aggregate([
46
- {
47
- $match: query
48
- },
49
- ...branchVisibility,
50
- {
51
- $count: 'count'
52
- }
53
- ], {
54
- collation,
55
- session
56
- }).then((result)=>result[0]?.count ?? 0);
57
- } else if (useEstimatedCount) {
43
+ if (useEstimatedCount) {
58
44
  countPromise = Model.estimatedDocumentCount(query);
59
45
  } else {
60
46
  // Only hint the _id index for unfiltered counts. With a filter, MongoDB picks the matching index on its own,
@@ -79,7 +65,7 @@ export const aggregatePaginate = async ({ adapter, branchVisibility, collation,
79
65
  countPromise
80
66
  ]);
81
67
  const count = countResult === null ? docs.length : countResult;
82
- const totalPages = pagination !== false && typeof limit === 'number' && limit !== 0 ? Math.max(1, Math.ceil(count / limit)) : 1;
68
+ const totalPages = pagination !== false && typeof limit === 'number' && limit !== 0 ? Math.ceil(count / limit) : 1;
83
69
  const hasPrevPage = typeof page === 'number' && pagination !== false && page > 1;
84
70
  const hasNextPage = typeof page === 'number' && pagination !== false && totalPages > page;
85
71
  const pagingCounter = typeof page === 'number' && pagination !== false && typeof limit === 'number' ? (page - 1) * limit + 1 : 1;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utilities/aggregatePaginate.ts"],"sourcesContent":["import type { CollationOptions } from 'mongodb'\nimport type { ClientSession, Model, PipelineStage } from 'mongoose'\nimport type { PaginatedDocs } from 'payload'\n\nimport type { MongooseAdapter } from '../index.js'\n\nexport const aggregatePaginate = async ({\n adapter,\n branchVisibility,\n collation,\n joinAggregation,\n limit,\n Model,\n page,\n pagination,\n projection,\n query,\n session,\n sort,\n sortAggregation,\n useEstimatedCount,\n}: {\n adapter: MongooseAdapter\n branchVisibility?: PipelineStage[]\n collation?: CollationOptions\n joinAggregation?: PipelineStage[]\n limit?: number\n Model: Model<any>\n page?: number\n pagination?: boolean\n projection?: Record<string, boolean>\n query: Record<string, unknown>\n session?: ClientSession\n sort?: object\n sortAggregation?: PipelineStage[]\n useEstimatedCount?: boolean\n}): Promise<PaginatedDocs<any>> => {\n const aggregation: PipelineStage[] = [{ $match: query }, ...(branchVisibility ?? [])]\n\n if (sortAggregation && sortAggregation.length > 0) {\n for (const stage of sortAggregation) {\n aggregation.push(stage)\n }\n }\n\n if (sort) {\n const $sort: Record<string, -1 | 1> = {}\n\n Object.entries(sort).forEach(([key, value]) => {\n $sort[key] = value === 'desc' ? -1 : 1\n })\n\n aggregation.push({ $sort })\n }\n\n if (page) {\n aggregation.push({ $skip: (page - 1) * (limit ?? 0) })\n }\n\n if (limit) {\n aggregation.push({ $limit: limit })\n }\n\n if (joinAggregation) {\n for (const stage of joinAggregation) {\n aggregation.push(stage)\n }\n }\n\n if (projection) {\n aggregation.push({ $project: projection })\n }\n\n let countPromise: Promise<null | number> = Promise.resolve(null)\n\n if (pagination !== false && limit) {\n if (branchVisibility?.length) {\n countPromise = Model.aggregate(\n [{ $match: query }, ...branchVisibility, { $count: 'count' }],\n { collation, session },\n ).then((result) => result[0]?.count ?? 0)\n } else if (useEstimatedCount) {\n countPromise = Model.estimatedDocumentCount(query)\n } else {\n // Only hint the _id index for unfiltered counts. With a filter, MongoDB picks the matching index on its own,\n // while forcing _id would make it scan the whole collection.\n const hint =\n adapter.disableIndexHints !== true && Object.keys(query).length === 0\n ? { _id: 1 }\n : undefined\n countPromise = Model.countDocuments(query, {\n collation,\n session,\n ...(hint ? { hint } : {}),\n })\n }\n }\n\n const [docs, countResult] = await Promise.all([\n Model.aggregate(aggregation, { collation, session }),\n countPromise,\n ])\n\n const count = countResult === null ? docs.length : countResult\n\n const totalPages =\n pagination !== false && typeof limit === 'number' && limit !== 0\n ? Math.max(1, Math.ceil(count / limit))\n : 1\n\n const hasPrevPage = typeof page === 'number' && pagination !== false && page > 1\n const hasNextPage = typeof page === 'number' && pagination !== false && totalPages > page\n const pagingCounter =\n typeof page === 'number' && pagination !== false && typeof limit === 'number'\n ? (page - 1) * limit + 1\n : 1\n\n const result: PaginatedDocs = {\n docs,\n hasNextPage,\n hasPrevPage,\n limit: limit ?? 0,\n nextPage: hasNextPage ? page + 1 : null,\n page,\n pagingCounter,\n prevPage: hasPrevPage ? page - 1 : null,\n totalDocs: count,\n totalPages,\n }\n\n return result\n}\n"],"names":["aggregatePaginate","adapter","branchVisibility","collation","joinAggregation","limit","Model","page","pagination","projection","query","session","sort","sortAggregation","useEstimatedCount","aggregation","$match","length","stage","push","$sort","Object","entries","forEach","key","value","$skip","$limit","$project","countPromise","Promise","resolve","aggregate","$count","then","result","count","estimatedDocumentCount","hint","disableIndexHints","keys","_id","undefined","countDocuments","docs","countResult","all","totalPages","Math","max","ceil","hasPrevPage","hasNextPage","pagingCounter","nextPage","prevPage","totalDocs"],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AACT,EAAC"}
1
+ {"version":3,"sources":["../../src/utilities/aggregatePaginate.ts"],"sourcesContent":["import type { CollationOptions } from 'mongodb'\nimport type { ClientSession, Model, PipelineStage } from 'mongoose'\nimport type { PaginatedDocs } from 'payload'\n\nimport type { MongooseAdapter } from '../index.js'\n\nexport const aggregatePaginate = async ({\n adapter,\n collation,\n joinAggregation,\n limit,\n Model,\n page,\n pagination,\n projection,\n query,\n session,\n sort,\n sortAggregation,\n useEstimatedCount,\n}: {\n adapter: MongooseAdapter\n collation?: CollationOptions\n joinAggregation?: PipelineStage[]\n limit?: number\n Model: Model<any>\n page?: number\n pagination?: boolean\n projection?: Record<string, boolean>\n query: Record<string, unknown>\n session?: ClientSession\n sort?: object\n sortAggregation?: PipelineStage[]\n useEstimatedCount?: boolean\n}): Promise<PaginatedDocs<any>> => {\n const aggregation: PipelineStage[] = [{ $match: query }]\n\n if (sortAggregation && sortAggregation.length > 0) {\n for (const stage of sortAggregation) {\n aggregation.push(stage)\n }\n }\n\n if (sort) {\n const $sort: Record<string, -1 | 1> = {}\n\n Object.entries(sort).forEach(([key, value]) => {\n $sort[key] = value === 'desc' ? -1 : 1\n })\n\n aggregation.push({ $sort })\n }\n\n if (page) {\n aggregation.push({ $skip: (page - 1) * (limit ?? 0) })\n }\n\n if (limit) {\n aggregation.push({ $limit: limit })\n }\n\n if (joinAggregation) {\n for (const stage of joinAggregation) {\n aggregation.push(stage)\n }\n }\n\n if (projection) {\n aggregation.push({ $project: projection })\n }\n\n let countPromise: Promise<null | number> = Promise.resolve(null)\n\n if (pagination !== false && limit) {\n if (useEstimatedCount) {\n countPromise = Model.estimatedDocumentCount(query)\n } else {\n // Only hint the _id index for unfiltered counts. With a filter, MongoDB picks the matching index on its own,\n // while forcing _id would make it scan the whole collection.\n const hint =\n adapter.disableIndexHints !== true && Object.keys(query).length === 0\n ? { _id: 1 }\n : undefined\n countPromise = Model.countDocuments(query, {\n collation,\n session,\n ...(hint ? { hint } : {}),\n })\n }\n }\n\n const [docs, countResult] = await Promise.all([\n Model.aggregate(aggregation, { collation, session }),\n countPromise,\n ])\n\n const count = countResult === null ? docs.length : countResult\n\n const totalPages =\n pagination !== false && typeof limit === 'number' && limit !== 0 ? Math.ceil(count / limit) : 1\n\n const hasPrevPage = typeof page === 'number' && pagination !== false && page > 1\n const hasNextPage = typeof page === 'number' && pagination !== false && totalPages > page\n const pagingCounter =\n typeof page === 'number' && pagination !== false && typeof limit === 'number'\n ? (page - 1) * limit + 1\n : 1\n\n const result: PaginatedDocs = {\n docs,\n hasNextPage,\n hasPrevPage,\n limit: limit ?? 0,\n nextPage: hasNextPage ? page + 1 : null,\n page,\n pagingCounter,\n prevPage: hasPrevPage ? page - 1 : null,\n totalDocs: count,\n totalPages,\n }\n\n return result\n}\n"],"names":["aggregatePaginate","adapter","collation","joinAggregation","limit","Model","page","pagination","projection","query","session","sort","sortAggregation","useEstimatedCount","aggregation","$match","length","stage","push","$sort","Object","entries","forEach","key","value","$skip","$limit","$project","countPromise","Promise","resolve","estimatedDocumentCount","hint","disableIndexHints","keys","_id","undefined","countDocuments","docs","countResult","all","aggregate","count","totalPages","Math","ceil","hasPrevPage","hasNextPage","pagingCounter","result","nextPage","prevPage","totalDocs"],"mappings":"AAMA,OAAO,MAAMA,oBAAoB,OAAO,EACtCC,OAAO,EACPC,SAAS,EACTC,eAAe,EACfC,KAAK,EACLC,KAAK,EACLC,IAAI,EACJC,UAAU,EACVC,UAAU,EACVC,KAAK,EACLC,OAAO,EACPC,IAAI,EACJC,eAAe,EACfC,iBAAiB,EAelB;IACC,MAAMC,cAA+B;QAAC;YAAEC,QAAQN;QAAM;KAAE;IAExD,IAAIG,mBAAmBA,gBAAgBI,MAAM,GAAG,GAAG;QACjD,KAAK,MAAMC,SAASL,gBAAiB;YACnCE,YAAYI,IAAI,CAACD;QACnB;IACF;IAEA,IAAIN,MAAM;QACR,MAAMQ,QAAgC,CAAC;QAEvCC,OAAOC,OAAO,CAACV,MAAMW,OAAO,CAAC,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AEhG,MAAM0C,cAAc,OAAOxC,SAAS,YAAYC,eAAe,SAASD,OAAO;IAC/E,MAAMyC,cAAc,OAAOzC,SAAS,YAAYC,eAAe,SAASoC,aAAarC;IACrF,MAAM0C,gBACJ,OAAO1C,SAAS,YAAYC,eAAe,SAAS,OAAOH,UAAU,WACjE,AAACE,CAAAA,OAAO,CAAA,IAAKF,QAAQ,IACrB;IAEN,MAAM6C,SAAwB;QAC5BX;QACAS;QACAD;QACA1C,OAAOA,SAAS;QAChB8C,UAAUH,cAAczC,OAAO,IAAI;QACnCA;QACA0C;QACAG,UAAUL,cAAcxC,OAAO,IAAI;QACnC8C,WAAWV;QACXC;IACF;IAEA,OAAOM;AACT,EAAC"}
@@ -1,9 +1,8 @@
1
1
  import type { PipelineStage } from 'mongoose';
2
- import { type CollectionSlug, type JoinQuery, type PayloadRequest, type SanitizedCollectionConfig } from 'payload';
2
+ import { type CollectionSlug, type JoinQuery, type SanitizedCollectionConfig } from 'payload';
3
3
  import type { MongooseAdapter } from '../index.js';
4
4
  type BuildJoinAggregationArgs = {
5
5
  adapter: MongooseAdapter;
6
- branch?: false | string;
7
6
  collection: CollectionSlug;
8
7
  collectionConfig: SanitizedCollectionConfig;
9
8
  draftsEnabled?: boolean;
@@ -11,10 +10,9 @@ type BuildJoinAggregationArgs = {
11
10
  locale?: string;
12
11
  projection?: Record<string, true>;
13
12
  query?: Record<string, unknown>;
14
- req?: Partial<PayloadRequest>;
15
13
  /** whether the query is from drafts */
16
14
  versions?: boolean;
17
15
  };
18
- export declare const buildJoinAggregation: ({ adapter, branch, collection, collectionConfig, draftsEnabled, joins, locale, projection, req, versions, }: BuildJoinAggregationArgs) => Promise<PipelineStage[]>;
16
+ export declare const buildJoinAggregation: ({ adapter, collection, collectionConfig, draftsEnabled, joins, locale, projection, versions, }: BuildJoinAggregationArgs) => Promise<PipelineStage[]>;
19
17
  export {};
20
18
  //# sourceMappingURL=buildJoinAggregation.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"buildJoinAggregation.d.ts","sourceRoot":"","sources":["../../src/utilities/buildJoinAggregation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAE7C,OAAO,EAIL,KAAK,cAAc,EAKnB,KAAK,SAAS,EACd,KAAK,cAAc,EAKnB,KAAK,yBAAyB,EAE/B,MAAM,SAAS,CAAA;AAGhB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAQlD,KAAK,wBAAwB,GAAG;IAC9B,OAAO,EAAE,eAAe,CAAA;IACxB,MAAM,CAAC,EAAE,KAAK,GAAG,MAAM,CAAA;IACvB,UAAU,EAAE,cAAc,CAAA;IAC1B,gBAAgB,EAAE,yBAAyB,CAAA;IAC3C,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,KAAK,CAAC,EAAE,SAAS,CAAA;IACjB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAA;IAEjC,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC/B,GAAG,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC,CAAA;IAC7B,uCAAuC;IACvC,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB,CAAA;AAED,eAAO,MAAM,oBAAoB,gHAW9B,wBAAwB,KAAG,OAAO,CAAC,aAAa,EAAE,CAiiBpD,CAAA"}
1
+ {"version":3,"file":"buildJoinAggregation.d.ts","sourceRoot":"","sources":["../../src/utilities/buildJoinAggregation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAE7C,OAAO,EAIL,KAAK,cAAc,EAInB,KAAK,SAAS,EACd,KAAK,yBAAyB,EAC/B,MAAM,SAAS,CAAA;AAGhB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAOlD,KAAK,wBAAwB,GAAG;IAC9B,OAAO,EAAE,eAAe,CAAA;IACxB,UAAU,EAAE,cAAc,CAAA;IAC1B,gBAAgB,EAAE,yBAAyB,CAAA;IAC3C,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,KAAK,CAAC,EAAE,SAAS,CAAA;IACjB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAA;IAEjC,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC/B,uCAAuC;IACvC,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB,CAAA;AAED,eAAO,MAAM,oBAAoB,mGAS9B,wBAAwB,KAAG,OAAO,CAAC,aAAa,EAAE,CAgdpD,CAAA"}
@@ -1,10 +1,9 @@
1
- import { APIError, appendVersionToQueryKey, buildVersionCollectionFields, combineQueries, getBranchPredicateSync, getQueryDraftsSort, resolveBranchReadState, resolveBranchVersionQuery, rewriteBranchIDs, rewriteBranchVersionParents } from 'payload';
1
+ import { APIError, appendVersionToQueryKey, buildVersionCollectionFields, combineQueries, getQueryDraftsSort } from 'payload';
2
2
  import { fieldShouldBeLocalized, hasDraftsEnabled } from 'payload/shared';
3
- import { buildBranchVisibilityStages } from '../queries/buildBranchVisibility.js';
4
3
  import { buildQuery } from '../queries/buildQuery.js';
5
4
  import { buildSortParam } from '../queries/buildSortParam.js';
6
5
  import { getCollection } from './getEntity.js';
7
- export const buildJoinAggregation = async ({ adapter, branch, collection, collectionConfig, draftsEnabled, joins, locale, projection, req, versions })=>{
6
+ export const buildJoinAggregation = async ({ adapter, collection, collectionConfig, draftsEnabled, joins, locale, projection, versions })=>{
8
7
  if (!adapter.useJoinAggregations) {
9
8
  return [];
10
9
  }
@@ -50,10 +49,8 @@ export const buildJoinAggregation = async ({ adapter, branch, collection, collec
50
49
  });
51
50
  const $match = await buildQuery({
52
51
  adapter,
53
- branch,
54
52
  fields: aggregatedFields,
55
53
  locale,
56
- req,
57
54
  where: whereJoin
58
55
  });
59
56
  const sortProperty = Object.keys(sort)[0]// assert because buildSortParam always returns at least 1 key.
@@ -65,29 +62,6 @@ export const buildJoinAggregation = async ({ adapter, branch, collection, collec
65
62
  for (const collectionSlug of join.field.collection){
66
63
  const alias = `${as}.docs.${collectionSlug}`;
67
64
  aliases.push(alias);
68
- const joinBranchPredicate = getBranchPredicateSync({
69
- branch,
70
- collectionSlug,
71
- req
72
- });
73
- const joinBranchReadState = resolveBranchReadState({
74
- branch,
75
- collectionSlug,
76
- req
77
- });
78
- const branchMatch = joinBranchPredicate ? await buildQuery({
79
- adapter,
80
- branch,
81
- fields: adapter.payload.collections[collectionSlug].config.flattenedFields,
82
- locale,
83
- req,
84
- where: joinBranchPredicate
85
- }) : undefined;
86
- const branchVisibility = joinBranchReadState.useBranching ? buildBranchVisibilityStages({
87
- adapter,
88
- branch: joinBranchReadState.branch,
89
- collectionSlug
90
- }) : [];
91
65
  const basePipeline = [
92
66
  {
93
67
  $addFields: {
@@ -107,26 +81,10 @@ export const buildJoinAggregation = async ({ adapter, branch, collection, collec
107
81
  ]
108
82
  }
109
83
  },
110
- $match,
111
- ...branchMatch ? [
112
- branchMatch
113
- ] : []
84
+ $match
114
85
  ]
115
86
  }
116
- },
117
- ...branchVisibility,
118
- ...joinBranchPredicate || branchVisibility.length ? [
119
- {
120
- $set: {
121
- _id: {
122
- $ifNull: [
123
- '$_branchDocID',
124
- '$_id'
125
- ]
126
- }
127
- }
128
- }
129
- ] : []
87
+ }
130
88
  ];
131
89
  const { Model: JoinModel } = getCollection({
132
90
  adapter,
@@ -146,10 +104,12 @@ export const buildJoinAggregation = async ({ adapter, branch, collection, collec
146
104
  [sortProperty]: sortDirection
147
105
  }
148
106
  },
149
- {
150
- // Unfortunately, we can't use $skip here because we can lose data, instead we do $slice then
151
- $limit: page ? page * limitJoin : limitJoin
152
- },
107
+ ...limitJoin > 0 ? [
108
+ {
109
+ // Unfortunately, we can't use $skip here because we can lose data, instead we do $slice then
110
+ $limit: page ? page * limitJoin : limitJoin
111
+ }
112
+ ] : [],
153
113
  {
154
114
  $project: {
155
115
  value: '$_id',
@@ -233,16 +193,18 @@ export const buildJoinAggregation = async ({ adapter, branch, collection, collec
233
193
  }
234
194
  }
235
195
  });
236
- aggregate.push({
237
- $set: {
238
- [`${as}.docs`]: {
239
- $slice: [
240
- `$${as}.docs`,
241
- ...sliceValue
242
- ]
196
+ if (limitJoin > 0) {
197
+ aggregate.push({
198
+ $set: {
199
+ [`${as}.docs`]: {
200
+ $slice: [
201
+ `$${as}.docs`,
202
+ ...sliceValue
203
+ ]
204
+ }
243
205
  }
244
- }
245
- });
206
+ });
207
+ }
246
208
  }
247
209
  for (const slug of Object.keys(joinConfig)){
248
210
  const joinsList = joinConfig[slug];
@@ -289,75 +251,19 @@ export const buildJoinAggregation = async ({ adapter, branch, collection, collec
289
251
  });
290
252
  const sortProperty = Object.keys(sort)[0];
291
253
  const sortDirection = sort[sortProperty] === 'asc' ? 1 : -1;
292
- // A join subquery must carry the same branch predicate as the top-level
293
- // read, or a branch would see main's related documents.
294
- const joinBranchPredicate = getBranchPredicateSync({
295
- branch,
296
- collectionSlug: collectionConfig.slug,
297
- req
298
- });
299
- const joinBranchReadState = resolveBranchReadState({
300
- branch,
301
- collectionSlug: collectionConfig.slug,
302
- req
303
- });
304
- const resolvedWhereJoin = useDrafts ? joinBranchReadState.useBranching ? rewriteBranchVersionParents(appendVersionToQueryKey(whereJoin)) ?? {} : await resolveBranchVersionQuery({
305
- branch,
306
- collectionSlug: collectionConfig.slug,
307
- req,
308
- where: appendVersionToQueryKey(whereJoin)
309
- }) ?? {} : joinBranchReadState.useBranching ? rewriteBranchIDs(whereJoin) ?? {} : joinBranchPredicate ? {
310
- and: [
311
- whereJoin,
312
- joinBranchPredicate
313
- ]
314
- } : whereJoin;
315
254
  const $match = await JoinModel.buildQuery({
316
- branch,
317
255
  locale,
318
256
  payload: adapter.payload,
319
- req,
320
- where: useDrafts ? combineQueries(resolvedWhereJoin, {
257
+ where: useDrafts ? combineQueries(appendVersionToQueryKey(whereJoin), {
321
258
  latest: {
322
259
  equals: true
323
260
  }
324
- }) : resolvedWhereJoin
261
+ }) : whereJoin
325
262
  });
326
- const branchVisibility = joinBranchReadState.useBranching ? buildBranchVisibilityStages({
327
- adapter,
328
- branch: joinBranchReadState.branch,
329
- collectionSlug: collectionConfig.slug,
330
- mode: useDrafts ? 'drafts' : 'documents'
331
- }) : [];
332
263
  const pipeline = [
333
264
  {
334
265
  $match
335
266
  },
336
- ...branchVisibility,
337
- // Surface the canonical document ID rather than the shadow row's own
338
- // primary key, so join results address documents the same way every
339
- // other read does.
340
- ...joinBranchPredicate || branchVisibility.length ? [
341
- useDrafts ? {
342
- $set: {
343
- parent: {
344
- $ifNull: [
345
- '$_branchParent',
346
- '$parent'
347
- ]
348
- }
349
- }
350
- } : {
351
- $set: {
352
- _id: {
353
- $ifNull: [
354
- '$_branchDocID',
355
- '$_id'
356
- ]
357
- }
358
- }
359
- }
360
- ] : [],
361
267
  {
362
268
  $sort: {
363
269
  [sortProperty]: sortDirection
@@ -388,7 +294,6 @@ export const buildJoinAggregation = async ({ adapter, branch, collection, collec
388
294
  {
389
295
  $match
390
296
  },
391
- ...branchVisibility,
392
297
  {
393
298
  $count: 'result'
394
299
  }