@payloadcms/db-mongodb 4.0.0-internal.2a3c3bc → 4.0.0-internal.2d11d2e

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 (141) hide show
  1. package/dist/connect.d.ts.map +1 -1
  2. package/dist/connect.js +1 -0
  3. package/dist/connect.js.map +1 -1
  4. package/dist/count.d.ts.map +1 -1
  5. package/dist/count.js +33 -4
  6. package/dist/count.js.map +1 -1
  7. package/dist/countGlobalVersions.d.ts.map +1 -1
  8. package/dist/countGlobalVersions.js +10 -2
  9. package/dist/countGlobalVersions.js.map +1 -1
  10. package/dist/countVersions.d.ts.map +1 -1
  11. package/dist/countVersions.js +36 -4
  12. package/dist/countVersions.js.map +1 -1
  13. package/dist/createGlobalVersion.d.ts +1 -1
  14. package/dist/createGlobalVersion.d.ts.map +1 -1
  15. package/dist/createGlobalVersion.js +24 -1
  16. package/dist/createGlobalVersion.js.map +1 -1
  17. package/dist/createVersion.d.ts.map +1 -1
  18. package/dist/createVersion.js +16 -3
  19. package/dist/createVersion.js.map +1 -1
  20. package/dist/deleteBranchGlobal.d.ts +10 -0
  21. package/dist/deleteBranchGlobal.d.ts.map +1 -0
  22. package/dist/deleteBranchGlobal.js +26 -0
  23. package/dist/deleteBranchGlobal.js.map +1 -0
  24. package/dist/deleteMany.d.ts.map +1 -1
  25. package/dist/deleteMany.js +1 -0
  26. package/dist/deleteMany.js.map +1 -1
  27. package/dist/deleteOne.d.ts.map +1 -1
  28. package/dist/deleteOne.js +20 -1
  29. package/dist/deleteOne.js.map +1 -1
  30. package/dist/deleteVersions.d.ts.map +1 -1
  31. package/dist/deleteVersions.js +1 -0
  32. package/dist/deleteVersions.js.map +1 -1
  33. package/dist/exports/migration-utils.d.ts +1 -0
  34. package/dist/exports/migration-utils.d.ts.map +1 -1
  35. package/dist/exports/migration-utils.js +1 -0
  36. package/dist/exports/migration-utils.js.map +1 -1
  37. package/dist/find.d.ts.map +1 -1
  38. package/dist/find.js +44 -8
  39. package/dist/find.js.map +1 -1
  40. package/dist/findDistinct.d.ts.map +1 -1
  41. package/dist/findDistinct.js +70 -11
  42. package/dist/findDistinct.js.map +1 -1
  43. package/dist/findGlobal.d.ts.map +1 -1
  44. package/dist/findGlobal.js +48 -9
  45. package/dist/findGlobal.js.map +1 -1
  46. package/dist/findGlobalVersions.d.ts.map +1 -1
  47. package/dist/findGlobalVersions.js +10 -2
  48. package/dist/findGlobalVersions.js.map +1 -1
  49. package/dist/findOne.d.ts.map +1 -1
  50. package/dist/findOne.js +43 -5
  51. package/dist/findOne.js.map +1 -1
  52. package/dist/findVersions.d.ts.map +1 -1
  53. package/dist/findVersions.js +49 -5
  54. package/dist/findVersions.js.map +1 -1
  55. package/dist/index.d.ts.map +1 -1
  56. package/dist/index.js +4 -0
  57. package/dist/index.js.map +1 -1
  58. package/dist/models/buildGlobalModel.d.ts.map +1 -1
  59. package/dist/models/buildGlobalModel.js +30 -1
  60. package/dist/models/buildGlobalModel.js.map +1 -1
  61. package/dist/models/buildSchema.d.ts.map +1 -1
  62. package/dist/models/buildSchema.js +36 -10
  63. package/dist/models/buildSchema.js.map +1 -1
  64. package/dist/predefinedMigrations/branching.d.ts +4 -0
  65. package/dist/predefinedMigrations/branching.d.ts.map +1 -0
  66. package/dist/predefinedMigrations/branching.js +9 -0
  67. package/dist/predefinedMigrations/branching.js.map +1 -0
  68. package/dist/predefinedMigrations/migrateBranching.d.ts +17 -0
  69. package/dist/predefinedMigrations/migrateBranching.d.ts.map +1 -0
  70. package/dist/predefinedMigrations/migrateBranching.js +90 -0
  71. package/dist/predefinedMigrations/migrateBranching.js.map +1 -0
  72. package/dist/predefinedMigrations/migrateSizesToVariants.js.map +1 -1
  73. package/dist/queries/buildAndOrConditions.d.ts +4 -2
  74. package/dist/queries/buildAndOrConditions.d.ts.map +1 -1
  75. package/dist/queries/buildAndOrConditions.js +3 -1
  76. package/dist/queries/buildAndOrConditions.js.map +1 -1
  77. package/dist/queries/buildBranchVisibility.d.ts +11 -0
  78. package/dist/queries/buildBranchVisibility.d.ts.map +1 -0
  79. package/dist/queries/buildBranchVisibility.js +204 -0
  80. package/dist/queries/buildBranchVisibility.js.map +1 -0
  81. package/dist/queries/buildQuery.d.ts +4 -2
  82. package/dist/queries/buildQuery.d.ts.map +1 -1
  83. package/dist/queries/buildQuery.js +3 -1
  84. package/dist/queries/buildQuery.js.map +1 -1
  85. package/dist/queries/buildRelatedQueryPipeline.d.ts +7 -0
  86. package/dist/queries/buildRelatedQueryPipeline.d.ts.map +1 -0
  87. package/dist/queries/buildRelatedQueryPipeline.js +56 -0
  88. package/dist/queries/buildRelatedQueryPipeline.js.map +1 -0
  89. package/dist/queries/buildSearchParams.d.ts +4 -2
  90. package/dist/queries/buildSearchParams.d.ts.map +1 -1
  91. package/dist/queries/buildSearchParams.js +177 -45
  92. package/dist/queries/buildSearchParams.js.map +1 -1
  93. package/dist/queries/getBuildQueryPlugin.d.ts +3 -1
  94. package/dist/queries/getBuildQueryPlugin.d.ts.map +1 -1
  95. package/dist/queries/getBuildQueryPlugin.js +3 -1
  96. package/dist/queries/getBuildQueryPlugin.js.map +1 -1
  97. package/dist/queries/parseParams.d.ts +4 -2
  98. package/dist/queries/parseParams.d.ts.map +1 -1
  99. package/dist/queries/parseParams.js +5 -1
  100. package/dist/queries/parseParams.js.map +1 -1
  101. package/dist/queryDrafts.d.ts.map +1 -1
  102. package/dist/queryDrafts.js +39 -7
  103. package/dist/queryDrafts.js.map +1 -1
  104. package/dist/transactions/commitTransaction.d.ts.map +1 -1
  105. package/dist/transactions/commitTransaction.js +68 -7
  106. package/dist/transactions/commitTransaction.js.map +1 -1
  107. package/dist/transactions/rollbackTransaction.d.ts.map +1 -1
  108. package/dist/transactions/rollbackTransaction.js +10 -9
  109. package/dist/transactions/rollbackTransaction.js.map +1 -1
  110. package/dist/updateGlobal.d.ts.map +1 -1
  111. package/dist/updateGlobal.js +89 -7
  112. package/dist/updateGlobal.js.map +1 -1
  113. package/dist/updateGlobalVersion.d.ts.map +1 -1
  114. package/dist/updateGlobalVersion.js +1 -0
  115. package/dist/updateGlobalVersion.js.map +1 -1
  116. package/dist/updateMany.d.ts.map +1 -1
  117. package/dist/updateMany.js +3 -1
  118. package/dist/updateMany.js.map +1 -1
  119. package/dist/updateOne.d.ts.map +1 -1
  120. package/dist/updateOne.js +28 -2
  121. package/dist/updateOne.js.map +1 -1
  122. package/dist/updateVersion.d.ts.map +1 -1
  123. package/dist/updateVersion.js +1 -0
  124. package/dist/updateVersion.js.map +1 -1
  125. package/dist/upsertBranchGlobalChange.d.ts +3 -0
  126. package/dist/upsertBranchGlobalChange.d.ts.map +1 -0
  127. package/dist/upsertBranchGlobalChange.js +28 -0
  128. package/dist/upsertBranchGlobalChange.js.map +1 -0
  129. package/dist/utilities/aggregatePaginate.d.ts +2 -1
  130. package/dist/utilities/aggregatePaginate.d.ts.map +1 -1
  131. package/dist/utilities/aggregatePaginate.js +18 -4
  132. package/dist/utilities/aggregatePaginate.js.map +1 -1
  133. package/dist/utilities/buildJoinAggregation.d.ts +4 -2
  134. package/dist/utilities/buildJoinAggregation.d.ts.map +1 -1
  135. package/dist/utilities/buildJoinAggregation.js +158 -24
  136. package/dist/utilities/buildJoinAggregation.js.map +1 -1
  137. package/dist/utilities/resolveJoins.d.ts +6 -2
  138. package/dist/utilities/resolveJoins.d.ts.map +1 -1
  139. package/dist/utilities/resolveJoins.js +115 -26
  140. package/dist/utilities/resolveJoins.js.map +1 -1
  141. package/package.json +16 -19
@@ -1 +1 @@
1
- {"version":3,"file":"connect.d.ts","sourceRoot":"","sources":["../src/connect.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAa,MAAM,SAAS,CAAA;AAOjD,eAAO,MAAM,OAAO,EAAE,OAkHrB,CAAA"}
1
+ {"version":3,"file":"connect.d.ts","sourceRoot":"","sources":["../src/connect.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAa,MAAM,SAAS,CAAA;AAOjD,eAAO,MAAM,OAAO,EAAE,OAmHrB,CAAA"}
package/dist/connect.js CHANGED
@@ -69,6 +69,7 @@ export const connect = async function connect(options = {
69
69
  this.collections[collection.slug],
70
70
  this.versions[collection.slug]
71
71
  ]),
72
+ this.globals,
72
73
  ...this.payload.config.globals.map((global)=>this.versions[global.slug])
73
74
  ].map(async (model)=>{
74
75
  await model?.ensureIndexes();
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/connect.ts"],"sourcesContent":["import type { ConnectOptions } from 'mongoose'\nimport type { Connect, Migration } from 'payload'\n\nimport mongoose from 'mongoose'\nimport { defaultBeginTransaction } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nexport const connect: Connect = async function connect(\n this: MongooseAdapter,\n options = {\n hotReload: false,\n },\n) {\n const { hotReload } = options\n\n if (this.url === false) {\n return\n }\n\n if (typeof this.url !== 'string') {\n throw new Error('Error: missing MongoDB connection URL.')\n }\n\n const urlToConnect = this.url\n\n const connectionOptions: ConnectOptions = {\n autoIndex: true,\n ...this.connectOptions,\n }\n\n if (hotReload) {\n connectionOptions.autoIndex = false\n }\n\n try {\n if (!this.connection) {\n this.connection = await mongoose.createConnection(urlToConnect, connectionOptions).asPromise()\n if (this.afterCreateConnection) {\n await this.afterCreateConnection(this)\n }\n }\n\n await this.connection.openUri(urlToConnect, connectionOptions)\n\n if (this.afterOpenConnection) {\n await this.afterOpenConnection(this)\n }\n\n if (this.useAlternativeDropDatabase) {\n if (this.connection.db) {\n // Firestore doesn't support dropDatabase, so we monkey patch\n // dropDatabase to delete all documents from all collections instead\n this.connection.db.dropDatabase = async function (): Promise<boolean> {\n const existingCollections = await this.listCollections().toArray()\n await Promise.all(\n existingCollections.map(async (collectionInfo) => {\n const collection = this.collection(collectionInfo.name)\n await collection.deleteMany({})\n }),\n )\n return true\n }\n this.connection.dropDatabase = async function () {\n await this.db?.dropDatabase()\n }\n }\n }\n\n // If we are running a replica set with MongoDB Memory Server,\n // wait until the replica set elects a primary before proceeding\n if (this.mongoMemoryServer) {\n this.payload.logger.info(\n 'Waiting for MongoDB Memory Server replica set to elect a primary...',\n )\n await new Promise((resolve) => setTimeout(resolve, 2000))\n }\n\n if (!this.connection.getClient().options.replicaSet) {\n this.transactionOptions = false\n this.beginTransaction = defaultBeginTransaction()\n }\n\n if (!hotReload) {\n if (process.env.PAYLOAD_DROP_DATABASE === 'true') {\n this.payload.logger.info('---- DROPPING DATABASE ----')\n await this.connection.dropDatabase()\n\n this.payload.logger.info('---- DROPPED DATABASE ----')\n }\n }\n\n if (this.ensureIndexes) {\n await Promise.all(\n [\n ...this.payload.config.collections.flatMap((collection) => [\n this.collections[collection.slug],\n this.versions[collection.slug],\n ]),\n ...this.payload.config.globals.map((global) => this.versions[global.slug]),\n ].map(async (model) => {\n await model?.ensureIndexes()\n }),\n )\n }\n\n if (process.env.NODE_ENV === 'production' && this.prodMigrations) {\n await this.migrate({ migrations: this.prodMigrations as unknown as Migration[] })\n }\n } catch (err) {\n let msg = `Error: cannot connect to MongoDB.`\n\n if (typeof err === 'object' && err && 'message' in err && typeof err.message === 'string') {\n msg = `${msg} Details: ${err.message}`\n }\n\n this.payload.logger.error({\n err,\n msg,\n })\n throw new Error(`Error: cannot connect to MongoDB: ${msg}`)\n }\n}\n"],"names":["mongoose","defaultBeginTransaction","connect","options","hotReload","url","Error","urlToConnect","connectionOptions","autoIndex","connectOptions","connection","createConnection","asPromise","afterCreateConnection","openUri","afterOpenConnection","useAlternativeDropDatabase","db","dropDatabase","existingCollections","listCollections","toArray","Promise","all","map","collectionInfo","collection","name","deleteMany","mongoMemoryServer","payload","logger","info","resolve","setTimeout","getClient","replicaSet","transactionOptions","beginTransaction","process","env","PAYLOAD_DROP_DATABASE","ensureIndexes","config","collections","flatMap","slug","versions","globals","global","model","NODE_ENV","prodMigrations","migrate","migrations","err","msg","message","error"],"mappings":"AAGA,OAAOA,cAAc,WAAU;AAC/B,SAASC,uBAAuB,QAAQ,UAAS;AAIjD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;gBAAEC,YAAY,IAAI,CAACF,cAAc;YAA2B;QACjF;IACF,EAAE,OAAOG,KAAK;QACZ,IAAIC,MAAM,CAAC,iCAAiC,CAAC;QAE7C,IAAI,OAAOD,QAAQ,YAAYA,OAAO,aAAaA,OAAO,OAAOA,IAAIE,OAAO,KAAK,UAAU;YACzFD,MAAM,GAAGA,IAAI,UAAU,EAAED,IAAIE,OAAO,EAAE;QACxC;QAEA,IAAI,CAAC3B,OAAO,CAACC,MAAM,CAAC2B,KAAK,CAAC;YACxBH;YACAC;QACF;QACA,MAAM,IAAInD,MAAM,CAAC,kCAAkC,EAAEmD,KAAK;IAC5D;AACF,EAAC"}
1
+ {"version":3,"sources":["../src/connect.ts"],"sourcesContent":["import type { ConnectOptions } from 'mongoose'\nimport type { Connect, Migration } from 'payload'\n\nimport mongoose from 'mongoose'\nimport { defaultBeginTransaction } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nexport const connect: Connect = async function connect(\n this: MongooseAdapter,\n options = {\n hotReload: false,\n },\n) {\n const { hotReload } = options\n\n if (this.url === false) {\n return\n }\n\n if (typeof this.url !== 'string') {\n throw new Error('Error: missing MongoDB connection URL.')\n }\n\n const urlToConnect = this.url\n\n const connectionOptions: ConnectOptions = {\n autoIndex: true,\n ...this.connectOptions,\n }\n\n if (hotReload) {\n connectionOptions.autoIndex = false\n }\n\n try {\n if (!this.connection) {\n this.connection = await mongoose.createConnection(urlToConnect, connectionOptions).asPromise()\n if (this.afterCreateConnection) {\n await this.afterCreateConnection(this)\n }\n }\n\n await this.connection.openUri(urlToConnect, connectionOptions)\n\n if (this.afterOpenConnection) {\n await this.afterOpenConnection(this)\n }\n\n if (this.useAlternativeDropDatabase) {\n if (this.connection.db) {\n // Firestore doesn't support dropDatabase, so we monkey patch\n // dropDatabase to delete all documents from all collections instead\n this.connection.db.dropDatabase = async function (): Promise<boolean> {\n const existingCollections = await this.listCollections().toArray()\n await Promise.all(\n existingCollections.map(async (collectionInfo) => {\n const collection = this.collection(collectionInfo.name)\n await collection.deleteMany({})\n }),\n )\n return true\n }\n this.connection.dropDatabase = async function () {\n await this.db?.dropDatabase()\n }\n }\n }\n\n // If we are running a replica set with MongoDB Memory Server,\n // wait until the replica set elects a primary before proceeding\n if (this.mongoMemoryServer) {\n this.payload.logger.info(\n 'Waiting for MongoDB Memory Server replica set to elect a primary...',\n )\n await new Promise((resolve) => setTimeout(resolve, 2000))\n }\n\n if (!this.connection.getClient().options.replicaSet) {\n this.transactionOptions = false\n this.beginTransaction = defaultBeginTransaction()\n }\n\n if (!hotReload) {\n if (process.env.PAYLOAD_DROP_DATABASE === 'true') {\n this.payload.logger.info('---- DROPPING DATABASE ----')\n await this.connection.dropDatabase()\n\n this.payload.logger.info('---- DROPPED DATABASE ----')\n }\n }\n\n if (this.ensureIndexes) {\n await Promise.all(\n [\n ...this.payload.config.collections.flatMap((collection) => [\n this.collections[collection.slug],\n this.versions[collection.slug],\n ]),\n this.globals,\n ...this.payload.config.globals.map((global) => this.versions[global.slug]),\n ].map(async (model) => {\n await model?.ensureIndexes()\n }),\n )\n }\n\n if (process.env.NODE_ENV === 'production' && this.prodMigrations) {\n await this.migrate({ migrations: this.prodMigrations as unknown as Migration[] })\n }\n } catch (err) {\n let msg = `Error: cannot connect to MongoDB.`\n\n if (typeof err === 'object' && err && 'message' in err && typeof err.message === 'string') {\n msg = `${msg} Details: ${err.message}`\n }\n\n this.payload.logger.error({\n err,\n msg,\n })\n throw new Error(`Error: cannot connect to MongoDB: ${msg}`)\n }\n}\n"],"names":["mongoose","defaultBeginTransaction","connect","options","hotReload","url","Error","urlToConnect","connectionOptions","autoIndex","connectOptions","connection","createConnection","asPromise","afterCreateConnection","openUri","afterOpenConnection","useAlternativeDropDatabase","db","dropDatabase","existingCollections","listCollections","toArray","Promise","all","map","collectionInfo","collection","name","deleteMany","mongoMemoryServer","payload","logger","info","resolve","setTimeout","getClient","replicaSet","transactionOptions","beginTransaction","process","env","PAYLOAD_DROP_DATABASE","ensureIndexes","config","collections","flatMap","slug","versions","globals","global","model","NODE_ENV","prodMigrations","migrate","migrations","err","msg","message","error"],"mappings":"AAGA,OAAOA,cAAc,WAAU;AAC/B,SAASC,uBAAuB,QAAQ,UAAS;AAIjD,OAAO,MAAMC,UAAmB,eAAeA,QAE7CC,UAAU;IACRC,WAAW;AACb,CAAC;IAED,MAAM,EAAEA,SAAS,EAAE,GAAGD;IAEtB,IAAI,IAAI,CAACE,GAAG,KAAK,OAAO;QACtB;IACF;IAEA,IAAI,OAAO,IAAI,CAACA,GAAG,KAAK,UAAU;QAChC,MAAM,IAAIC,MAAM;IAClB;IAEA,MAAMC,eAAe,IAAI,CAACF,GAAG;IAE7B,MAAMG,oBAAoC;QACxCC,WAAW;QACX,GAAG,IAAI,CAACC,cAAc;IACxB;IAEA,IAAIN,WAAW;QACbI,kBAAkBC,SAAS,GAAG;IAChC;IAEA,IAAI;QACF,IAAI,CAAC,IAAI,CAACE,UAAU,EAAE;YACpB,IAAI,CAACA,UAAU,GAAG,MAAMX,SAASY,gBAAgB,CAACL,cAAcC,mBAAmBK,SAAS;YAC5F,IAAI,IAAI,CAACC,qBAAqB,EAAE;gBAC9B,MAAM,IAAI,CAACA,qBAAqB,CAAC,IAAI;YACvC;QACF;QAEA,MAAM,IAAI,CAACH,UAAU,CAACI,OAAO,CAACR,cAAcC;QAE5C,IAAI,IAAI,CAACQ,mBAAmB,EAAE;YAC5B,MAAM,IAAI,CAACA,mBAAmB,CAAC,IAAI;QACrC;QAEA,IAAI,IAAI,CAACC,0BAA0B,EAAE;YACnC,IAAI,IAAI,CAACN,UAAU,CAACO,EAAE,EAAE;gBACtB,6DAA6D;gBAC7D,oEAAoE;gBACpE,IAAI,CAACP,UAAU,CAACO,EAAE,CAACC,YAAY,GAAG;oBAChC,MAAMC,sBAAsB,MAAM,IAAI,CAACC,eAAe,GAAGC,OAAO;oBAChE,MAAMC,QAAQC,GAAG,CACfJ,oBAAoBK,GAAG,CAAC,OAAOC;wBAC7B,MA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tB,GAAG,CAAC,OAAO0B;gBACX,MAAMA,OAAOR;YACf;QAEJ;QAEA,IAAIH,QAAQC,GAAG,CAACW,QAAQ,KAAK,gBAAgB,IAAI,CAACC,cAAc,EAAE;YAChE,MAAM,IAAI,CAACC,OAAO,CAAC;gBAAEC,YAAY,IAAI,CAACF,cAAc;YAA2B;QACjF;IACF,EAAE,OAAOG,KAAK;QACZ,IAAIC,MAAM,CAAC,iCAAiC,CAAC;QAE7C,IAAI,OAAOD,QAAQ,YAAYA,OAAO,aAAaA,OAAO,OAAOA,IAAIE,OAAO,KAAK,UAAU;YACzFD,MAAM,GAAGA,IAAI,UAAU,EAAED,IAAIE,OAAO,EAAE;QACxC;QAEA,IAAI,CAAC3B,OAAO,CAACC,MAAM,CAAC2B,KAAK,CAAC;YACxBH;YACAC;QACF;QACA,MAAM,IAAInD,MAAM,CAAC,kCAAkC,EAAEmD,KAAK;IAC5D;AACF,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"count.d.ts","sourceRoot":"","sources":["../src/count.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAUpC,eAAO,MAAM,KAAK,EAAE,KA2DnB,CAAA"}
1
+ {"version":3,"file":"count.d.ts","sourceRoot":"","sources":["../src/count.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAgBpC,eAAO,MAAM,KAAK,EAAE,KA+EnB,CAAA"}
package/dist/count.js CHANGED
@@ -1,12 +1,29 @@
1
- import { flattenWhereToOperators } from 'payload';
1
+ import { flattenWhereToOperators, resolveBranchQuery, resolveBranchReadState, rewriteBranchIDs } from 'payload';
2
+ import { buildBranchVisibilityStages } from './queries/buildBranchVisibility.js';
2
3
  import { buildQuery } from './queries/buildQuery.js';
3
4
  import { getCollection } from './utilities/getEntity.js';
4
5
  import { getSession } from './utilities/getSession.js';
5
- export const count = async function count({ collection: collectionSlug, locale, req, where = {} }) {
6
+ export const count = async function count({ branch, collection: collectionSlug, locale, req, where = {} }) {
6
7
  const { collectionConfig, Model } = getCollection({
7
8
  adapter: this,
8
9
  collectionSlug
9
10
  });
11
+ const branchReadState = resolveBranchReadState({
12
+ branch,
13
+ collectionSlug,
14
+ req
15
+ });
16
+ where = branchReadState.useBranching ? rewriteBranchIDs(where) ?? {} : await resolveBranchQuery({
17
+ branch,
18
+ collectionSlug,
19
+ req,
20
+ where
21
+ }) ?? {};
22
+ const branchVisibility = branchReadState.useBranching ? buildBranchVisibilityStages({
23
+ adapter: this,
24
+ branch: branchReadState.branch,
25
+ collectionSlug
26
+ }) : [];
10
27
  let hasNearConstraint = false;
11
28
  if (where) {
12
29
  const constraints = flattenWhereToOperators(where);
@@ -14,13 +31,15 @@ export const count = async function count({ collection: collectionSlug, locale,
14
31
  }
15
32
  const query = await buildQuery({
16
33
  adapter: this,
34
+ branch,
17
35
  collectionSlug,
18
36
  fields: collectionConfig.flattenedFields,
19
37
  locale,
38
+ req,
20
39
  where
21
40
  });
22
41
  // useEstimatedCount is faster, but not accurate, as it ignores any filters. It is thus set to true if there are no filters.
23
- const useEstimatedCount = hasNearConstraint || !query || Object.keys(query).length === 0;
42
+ const useEstimatedCount = !branchVisibility.length && (hasNearConstraint || !query || Object.keys(query).length === 0);
24
43
  const options = {
25
44
  session: await getSession(this, req)
26
45
  };
@@ -42,7 +61,17 @@ export const count = async function count({ collection: collectionSlug, locale,
42
61
  };
43
62
  }
44
63
  let result;
45
- if (useEstimatedCount) {
64
+ if (branchVisibility.length) {
65
+ result = await Model.aggregate([
66
+ {
67
+ $match: query
68
+ },
69
+ ...branchVisibility,
70
+ {
71
+ $count: 'count'
72
+ }
73
+ ], options).then((rows)=>rows[0]?.count ?? 0);
74
+ } else if (useEstimatedCount) {
46
75
  result = await Model.estimatedDocumentCount({
47
76
  session: options.session
48
77
  });
package/dist/count.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/count.ts"],"sourcesContent":["import type { CountOptions } from 'mongodb'\nimport type { Count } from 'payload'\n\nimport { flattenWhereToOperators } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { getCollection } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\n\nexport const count: Count = async function count(\n this: MongooseAdapter,\n { collection: collectionSlug, locale, req, where = {} },\n) {\n const { collectionConfig, Model } = getCollection({ adapter: this, collectionSlug })\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 query = await buildQuery({\n adapter: this,\n collectionSlug,\n fields: collectionConfig.flattenedFields,\n locale,\n where,\n })\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 = hasNearConstraint || !query || Object.keys(query).length === 0\n\n const options: CountOptions = {\n session: await getSession(this, req),\n }\n\n if (this.collation) {\n const localizationConfig = this.payload.config.localization\n const defaultLocale =\n (typeof localizationConfig === 'object' && localizationConfig?.defaultLocale) || 'en'\n\n options.collation = {\n locale: locale && locale !== 'all' && locale !== '*' ? locale : defaultLocale,\n ...this.collation,\n }\n }\n\n if (!useEstimatedCount && Object.keys(query).length === 0 && this.disableIndexHints !== true) {\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 options.hint = {\n _id: 1,\n }\n }\n\n let result: number\n if (useEstimatedCount) {\n result = await Model.estimatedDocumentCount({ session: options.session })\n } else {\n result = await Model.countDocuments(query, options)\n }\n\n return {\n totalDocs: result,\n }\n}\n"],"names":["flattenWhereToOperators","buildQuery","getCollection","getSession","count","collection","collectionSlug","locale","req","where","collectionConfig","Model","adapter","hasNearConstraint","constraints","some","prop","Object","keys","key","query","fields","flattenedFields","useEstimatedCount","length","options","session","collation","localizationConfig","payload","config","localization","defaultLocale","disableIndexHints","hint","_id","result","estimatedDocumentCount","countDocuments","totalDocs"],"mappings":"AAGA,SAASA,uBAAuB,QAAQ,UAAS;AAIjD,SAASC,UAAU,QAAQ,0BAAyB;AACpD,SAASC,aAAa,QAAQ,2BAA0B;AACxD,SAASC,UAAU,QAAQ,4BAA2B;AAEtD,OAAO,MAAMC,QAAe,eAAeA,MAEzC,EAAEC,YAAYC,cAAc,EAAEC,MAAM,EAAEC,GAAG,EAAEC,QAAQ,CAAC,CAAC,EAAE;IAEvD,MAAM,EAAEC,gBAAgB,EAAEC,KAAK,EAAE,GAAGT,cAAc;QAAEU,SAAS,IAAI;QAAEN;IAAe;IAElF,IAAIO,oBAAoB;IAExB,IAAIJ,OAAO;QACT,MAAMK,cAAcd,wBAAwBS;QAC5CI,oBAAoBC,YAAYC,IAAI,CAAC,CAACC,OAASC,OAAOC,IAAI,CAACF,MAAMD,IAAI,CAAC,CAACI,MAAQA,QAAQ;IACzF;IAEA,MAAMC,QAAQ,MAAMnB,WAAW;QAC7BW,SAAS,IAAI;QACbN;QACAe,QAAQX,iBAAiBY,eAAe;QACxCf;QACAE;IACF;IAEA,4HAA4H;IAC5H,MAAMc,oBAAoBV,qBAAqB,CAACO,SAASH,OAAOC,IAAI,CAACE,OAAOI,MAAM,KAAK;IAEvF,MAAMC,UAAwB;QAC5BC,SAAS,MAAMvB,WAAW,IAAI,EAAEK;IAClC;IAEA,IAAI,IAAI,CAACmB,SAAS,EAAE;QAClB,MAAMC,qBAAqB,IAAI,CAACC,OAAO,CAACC,MAAM,CAACC,YAAY;QAC3D,MAAMC,gBACJ,AAAC,OAAOJ,uBAAuB,YAAYA,oBAAoBI,iBAAkB;QAEnFP,QAAQE,SAAS,GAAG;YAClBpB,QAAQA,UAAUA,WAAW,SAASA,WAAW,MAAMA,SAASyB;YAChE,GAAG,IAAI,CAACL,SAAS;QACnB;IACF;IAEA,IAAI,CAACJ,qBAAqBN,OAAOC,IAAI,CAACE,OAAOI,MAAM,KAAK,KAAK,IAAI,CAACS,iBAAiB,KAAK,MAAM;QAC5F,mHAAmH;QACnH,qHAAqH;QACrH,mHAAmH;QACnH,4BAA4B;QAC5BR,QAAQS,IAAI,GAAG;YACbC,KAAK;QACP;IACF;IAEA,IAAIC;IACJ,IAAIb,mBAAmB;QACrBa,SAAS,MAAMzB,MAAM0B,sBAAsB,CAAC;YAAEX,SAASD,QAAQC,OAAO;QAAC;IACzE,OAAO;QACLU,SAAS,MAAMzB,MAAM2B,cAAc,CAAClB,OAAOK;IAC7C;IAEA,OAAO;QACLc,WAAWH;IACb;AACF,EAAC"}
1
+ {"version":3,"sources":["../src/count.ts"],"sourcesContent":["import type { CountOptions } from 'mongodb'\nimport type { Count } from 'payload'\n\nimport {\n flattenWhereToOperators,\n resolveBranchQuery,\n resolveBranchReadState,\n rewriteBranchIDs,\n} from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildBranchVisibilityStages } from './queries/buildBranchVisibility.js'\nimport { buildQuery } from './queries/buildQuery.js'\nimport { getCollection } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\n\nexport const count: Count = async function count(\n this: MongooseAdapter,\n { branch, collection: collectionSlug, locale, req, where = {} },\n) {\n const { collectionConfig, Model } = getCollection({ adapter: this, collectionSlug })\n const branchReadState = resolveBranchReadState({ branch, collectionSlug, req })\n\n where = branchReadState.useBranching\n ? (rewriteBranchIDs(where) ?? {})\n : ((await resolveBranchQuery({ branch, collectionSlug, req, where })) ?? {})\n const branchVisibility = branchReadState.useBranching\n ? buildBranchVisibilityStages({\n adapter: this,\n branch: branchReadState.branch,\n collectionSlug,\n })\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 query = await buildQuery({\n adapter: this,\n branch,\n collectionSlug,\n fields: collectionConfig.flattenedFields,\n locale,\n req,\n where,\n })\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 !branchVisibility.length && (hasNearConstraint || !query || Object.keys(query).length === 0)\n\n const options: CountOptions = {\n session: await getSession(this, req),\n }\n\n if (this.collation) {\n const localizationConfig = this.payload.config.localization\n const defaultLocale =\n (typeof localizationConfig === 'object' && localizationConfig?.defaultLocale) || 'en'\n\n options.collation = {\n locale: locale && locale !== 'all' && locale !== '*' ? locale : defaultLocale,\n ...this.collation,\n }\n }\n\n if (!useEstimatedCount && Object.keys(query).length === 0 && this.disableIndexHints !== true) {\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 options.hint = {\n _id: 1,\n }\n }\n\n let result: number\n if (branchVisibility.length) {\n result = await Model.aggregate(\n [{ $match: query }, ...branchVisibility, { $count: 'count' }],\n options,\n ).then((rows) => rows[0]?.count ?? 0)\n } else if (useEstimatedCount) {\n result = await Model.estimatedDocumentCount({ session: options.session })\n } else {\n result = await Model.countDocuments(query, options)\n }\n\n return {\n totalDocs: result,\n }\n}\n"],"names":["flattenWhereToOperators","resolveBranchQuery","resolveBranchReadState","rewriteBranchIDs","buildBranchVisibilityStages","buildQuery","getCollection","getSession","count","branch","collection","collectionSlug","locale","req","where","collectionConfig","Model","adapter","branchReadState","useBranching","branchVisibility","hasNearConstraint","constraints","some","prop","Object","keys","key","query","fields","flattenedFields","useEstimatedCount","length","options","session","collation","localizationConfig","payload","config","localization","defaultLocale","disableIndexHints","hint","_id","result","aggregate","$match","$count","then","rows","estimatedDocumentCount","countDocuments","totalDocs"],"mappings":"AAGA,SACEA,uBAAuB,EACvBC,kBAAkB,EAClBC,sBAAsB,EACtBC,gBAAgB,QACX,UAAS;AAIhB,SAASC,2BAA2B,QAAQ,qCA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AAqB,IAAI,CAACC,OAAO,CAACC,MAAM,CAACC,YAAY;QAC3D,MAAMC,gBACJ,AAAC,OAAOJ,uBAAuB,YAAYA,oBAAoBI,iBAAkB;QAEnFP,QAAQE,SAAS,GAAG;YAClBvB,QAAQA,UAAUA,WAAW,SAASA,WAAW,MAAMA,SAAS4B;YAChE,GAAG,IAAI,CAACL,SAAS;QACnB;IACF;IAEA,IAAI,CAACJ,qBAAqBN,OAAOC,IAAI,CAACE,OAAOI,MAAM,KAAK,KAAK,IAAI,CAACS,iBAAiB,KAAK,MAAM;QAC5F,mHAAmH;QACnH,qHAAqH;QACrH,mHAAmH;QACnH,4BAA4B;QAC5BR,QAAQS,IAAI,GAAG;YACbC,KAAK;QACP;IACF;IAEA,IAAIC;IACJ,IAAIxB,iBAAiBY,MAAM,EAAE;QAC3BY,SAAS,MAAM5B,MAAM6B,SAAS,CAC5B;YAAC;gBAAEC,QAAQlB;YAAM;eAAMR;YAAkB;gBAAE2B,QAAQ;YAAQ;SAAE,EAC7Dd,SACAe,IAAI,CAAC,CAACC,OAASA,IAAI,CAAC,EAAE,EAAEzC,SAAS;IACrC,OAAO,IAAIuB,mBAAmB;QAC5Ba,SAAS,MAAM5B,MAAMkC,sBAAsB,CAAC;YAAEhB,SAASD,QAAQC,OAAO;QAAC;IACzE,OAAO;QACLU,SAAS,MAAM5B,MAAMmC,cAAc,CAACvB,OAAOK;IAC7C;IAEA,OAAO;QACLmB,WAAWR;IACb;AACF,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"countGlobalVersions.d.ts","sourceRoot":"","sources":["../src/countGlobalVersions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAA;AAUlD,eAAO,MAAM,mBAAmB,EAAE,mBA0DjC,CAAA"}
1
+ {"version":3,"file":"countGlobalVersions.d.ts","sourceRoot":"","sources":["../src/countGlobalVersions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAA;AAclD,eAAO,MAAM,mBAAmB,EAAE,mBA6DjC,CAAA"}
@@ -1,13 +1,19 @@
1
- import { buildVersionGlobalFields, flattenWhereToOperators } from 'payload';
1
+ import { buildVersionGlobalFields, flattenWhereToOperators, resolveBranchGlobalVersionQuery } from 'payload';
2
2
  import { buildQuery } from './queries/buildQuery.js';
3
3
  import { getGlobal } from './utilities/getEntity.js';
4
4
  import { getSession } from './utilities/getSession.js';
5
- export const countGlobalVersions = async function countGlobalVersions({ global: globalSlug, locale, req, where = {} }) {
5
+ export const countGlobalVersions = async function countGlobalVersions({ branch, global: globalSlug, locale, req, where = {} }) {
6
6
  const { globalConfig, Model } = getGlobal({
7
7
  adapter: this,
8
8
  globalSlug,
9
9
  versions: true
10
10
  });
11
+ where = resolveBranchGlobalVersionQuery({
12
+ branch,
13
+ globalSlug,
14
+ req,
15
+ where
16
+ }) ?? {};
11
17
  let hasNearConstraint = false;
12
18
  if (where) {
13
19
  const constraints = flattenWhereToOperators(where);
@@ -15,8 +21,10 @@ export const countGlobalVersions = async function countGlobalVersions({ global:
15
21
  }
16
22
  const query = await buildQuery({
17
23
  adapter: this,
24
+ branch,
18
25
  fields: buildVersionGlobalFields(this.payload.config, globalConfig, true),
19
26
  locale,
27
+ req,
20
28
  where
21
29
  });
22
30
  // useEstimatedCount is faster, but not accurate, as it ignores any filters. It is thus set to true if there are no filters.
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/countGlobalVersions.ts"],"sourcesContent":["import type { CountOptions } from 'mongodb'\nimport type { CountGlobalVersions } from 'payload'\n\nimport { buildVersionGlobalFields, flattenWhereToOperators } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { getGlobal } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\n\nexport const countGlobalVersions: CountGlobalVersions = async function countGlobalVersions(\n this: MongooseAdapter,\n { global: globalSlug, locale, req, where = {} },\n) {\n const { globalConfig, Model } = getGlobal({ adapter: this, globalSlug, versions: true })\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 query = await buildQuery({\n adapter: this,\n fields: buildVersionGlobalFields(this.payload.config, globalConfig, true),\n locale,\n where,\n })\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 = hasNearConstraint || !query || Object.keys(query).length === 0\n\n const options: CountOptions = {\n session: await getSession(this, req),\n }\n\n if (this.collation) {\n const localizationConfig = this.payload.config.localization\n const defaultLocale =\n (typeof localizationConfig === 'object' && localizationConfig?.defaultLocale) || 'en'\n\n options.collation = {\n locale: locale && locale !== 'all' && locale !== '*' ? locale : defaultLocale,\n ...this.collation,\n }\n }\n\n if (!useEstimatedCount && Object.keys(query).length === 0 && this.disableIndexHints !== true) {\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 options.hint = {\n _id: 1,\n }\n }\n\n let result: number\n if (useEstimatedCount) {\n result = await Model.estimatedDocumentCount({ session: options.session })\n } else {\n result = await Model.countDocuments(query, options)\n }\n\n return {\n totalDocs: result,\n }\n}\n"],"names":["buildVersionGlobalFields","flattenWhereToOperators","buildQuery","getGlobal","getSession","countGlobalVersions","global","globalSlug","locale","req","where","globalConfig","Model","adapter","versions","hasNearConstraint","constraints","some","prop","Object","keys","key","query","fields","payload","config","useEstimatedCount","length","options","session","collation","localizationConfig","localization","defaultLocale","disableIndexHints","hint","_id","result","estimatedDocumentCount","countDocuments","totalDocs"],"mappings":"AAGA,SAASA,wBAAwB,EAAEC,uBAAuB,QAAQ,UAAS;AAI3E,SAASC,UAAU,QAAQ,0BAAyB;AACpD,SAASC,SAAS,QAAQ,2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AQO,IAAI,GAAG;YACbC,KAAK;QACP;IACF;IAEA,IAAIC;IACJ,IAAIX,mBAAmB;QACrBW,SAAS,MAAMzB,MAAM0B,sBAAsB,CAAC;YAAET,SAASD,QAAQC,OAAO;QAAC;IACzE,OAAO;QACLQ,SAAS,MAAMzB,MAAM2B,cAAc,CAACjB,OAAOM;IAC7C;IAEA,OAAO;QACLY,WAAWH;IACb;AACF,EAAC"}
1
+ {"version":3,"sources":["../src/countGlobalVersions.ts"],"sourcesContent":["import type { CountOptions } from 'mongodb'\nimport type { CountGlobalVersions } from 'payload'\n\nimport {\n buildVersionGlobalFields,\n flattenWhereToOperators,\n resolveBranchGlobalVersionQuery,\n} from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { getGlobal } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\n\nexport const countGlobalVersions: CountGlobalVersions = async function countGlobalVersions(\n this: MongooseAdapter,\n { branch, global: globalSlug, locale, req, where = {} },\n) {\n const { globalConfig, Model } = getGlobal({ adapter: this, globalSlug, versions: true })\n where = resolveBranchGlobalVersionQuery({ branch, globalSlug, req, where }) ?? {}\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 query = await buildQuery({\n adapter: this,\n branch,\n fields: buildVersionGlobalFields(this.payload.config, globalConfig, true),\n locale,\n req,\n where,\n })\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 = hasNearConstraint || !query || Object.keys(query).length === 0\n\n const options: CountOptions = {\n session: await getSession(this, req),\n }\n\n if (this.collation) {\n const localizationConfig = this.payload.config.localization\n const defaultLocale =\n (typeof localizationConfig === 'object' && localizationConfig?.defaultLocale) || 'en'\n\n options.collation = {\n locale: locale && locale !== 'all' && locale !== '*' ? locale : defaultLocale,\n ...this.collation,\n }\n }\n\n if (!useEstimatedCount && Object.keys(query).length === 0 && this.disableIndexHints !== true) {\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 options.hint = {\n _id: 1,\n }\n }\n\n let result: number\n if (useEstimatedCount) {\n result = await Model.estimatedDocumentCount({ session: options.session })\n } else {\n result = await Model.countDocuments(query, options)\n }\n\n return {\n totalDocs: result,\n }\n}\n"],"names":["buildVersionGlobalFields","flattenWhereToOperators","resolveBranchGlobalVersionQuery","buildQuery","getGlobal","getSession","countGlobalVersions","branch","global","globalSlug","locale","req","where","globalConfig","Model","adapter","versions","hasNearConstraint","constraints","some","prop","Object","keys","key","query","fields","payload","config","useEstimatedCount","length","options","session","collation","localizationConfig","localization","defaultLocale","disableIndexHints","hint","_id","result","estimatedDocumentCount","countDocuments","totalDocs"],"mappings":"AAGA,SACEA,wBAAwB,EACxBC,uBAAuB,EACvBC,+BAA+B,QAC1B,UAAS;AAIhB,SAASC,UAAU,QAAQ,0BAAyB;AACpD,SAASC,SAAS,QAAQ,2BAA0B;AACpD,SAASC,UAAU,QAAQ,4BAA2B;AAEtD,OAAO,MAAMC,sBAA2C,eAAeA,oBAErE,EAAEC,MAAM,EAAEC,QAAQC,UAAU,EAAEC,MAAM,EAAEC,GAAG,EAAEC,QAAQ,CAAC,CAAC,EAAE;IAEvD,MAAM,EAAEC,YAAY,EAAEC,KAAK,EAAE,GAAGV,UAAU;QAAEW,SAAS,IAAI;QAAEN;QAAYO,UAAU;IAAK;IACtFJ,QAAQV,gCAAgC;QAAEK;QAAQE;QAAYE;QAAKC;IAAM,MAAM,CAAC;IAEhF,IAAIK,oBAAoB;IAExB,IAAIL,OAAO;QACT,MAAMM,cAAcjB,wBAAwBW;QAC5CK,oBAAoBC,YAAYC,IAAI,CAAC,CAACC,OAASC,OAAOC,IAAI,CAACF,MAAMD,IAAI,CAAC,CAACI,MAAQA,QAAQ;IACzF;IAEA,MAAMC,QAAQ,MAAMrB,WAAW;QAC7BY,SAAS,IAAI;QACbR;QACAkB,QAAQzB,yBAAyB,IAAI,CAAC0B,OAAO,CAACC,MAAM,EAAEd,cAAc;QACpEH;QACAC;QACAC;IACF;IAEA,4HAA4H;IAC5H,MAAMgB,oBAAoBX,qBAAqB,CAACO,SAASH,OAAOC,IAAI,CAACE,OAAOK,MAAM,KAAK;IAEvF,MAAMC,UAAwB;QAC5BC,SAAS,MAAM1B,WAAW,IAAI,EAAEM;IAClC;IAEA,IAAI,IAAI,CAACqB,SAAS,EAAE;QAClB,MAAMC,qBAAqB,IAAI,CAACP,OAAO,CAACC,MAAM,CAACO,YAAY;QAC3D,MAAMC,gBACJ,AAAC,OAAOF,uBAAuB,YAAYA,oBAAoBE,iBAAkB;QAEnFL,QAAQE,SAAS,GAAG;YAClBtB,QAAQA,UAAUA,WAAW,SAASA,WAAW,MAAMA,SAASyB;YAChE,GAAG,IAAI,CAACH,SAAS;QACnB;IACF;IAEA,IAAI,CAACJ,qBAAqBP,OAAOC,IAAI,CAACE,OAAOK,MAAM,KAAK,KAAK,IAAI,CAACO,iBAAiB,KAAK,MAAM;QAC5F,mHAAmH;QACnH,qHAAqH;QACrH,mHAAmH;QACnH,4BAA4B;QAC5BN,QAAQO,IAAI,GAAG;YACbC,KAAK;QACP;IACF;IAEA,IAAIC;IACJ,IAAIX,mBAAmB;QACrBW,SAAS,MAAMzB,MAAM0B,sBAAsB,CAAC;YAAET,SAASD,QAAQC,OAAO;QAAC;IACzE,OAAO;QACLQ,SAAS,MAAMzB,MAAM2B,cAAc,CAACjB,OAAOM;IAC7C;IAEA,OAAO;QACLY,WAAWH;IACb;AACF,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"countVersions.d.ts","sourceRoot":"","sources":["../src/countVersions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAU5C,eAAO,MAAM,aAAa,EAAE,aA8D3B,CAAA"}
1
+ {"version":3,"file":"countVersions.d.ts","sourceRoot":"","sources":["../src/countVersions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAiB5C,eAAO,MAAM,aAAa,EAAE,aAqF3B,CAAA"}
@@ -1,13 +1,33 @@
1
- import { buildVersionCollectionFields, flattenWhereToOperators } from 'payload';
1
+ import { buildVersionCollectionFields, flattenWhereToOperators, resolveBranchReadState, resolveBranchVersionHistoryQuery, rewriteBranchVersionParents } from 'payload';
2
+ import { buildBranchVisibilityStages } from './queries/buildBranchVisibility.js';
2
3
  import { buildQuery } from './queries/buildQuery.js';
3
4
  import { getCollection } from './utilities/getEntity.js';
4
5
  import { getSession } from './utilities/getSession.js';
5
- export const countVersions = async function countVersions({ collection: collectionSlug, locale, req, where = {} }) {
6
+ export const countVersions = async function countVersions({ branch, collection: collectionSlug, locale, req, where = {} }) {
6
7
  const { collectionConfig, Model } = getCollection({
7
8
  adapter: this,
8
9
  collectionSlug,
9
10
  versions: true
10
11
  });
12
+ const branchReadState = resolveBranchReadState({
13
+ branch,
14
+ collectionSlug,
15
+ req
16
+ });
17
+ // Shares the list's predicate so the count in the Versions tab can never
18
+ // disagree with the rows the Versions view actually renders.
19
+ where = branchReadState.useBranching ? rewriteBranchVersionParents(where) ?? {} : await resolveBranchVersionHistoryQuery({
20
+ branch,
21
+ collectionSlug,
22
+ req,
23
+ where
24
+ }) ?? {};
25
+ const branchVisibility = branchReadState.useBranching ? buildBranchVisibilityStages({
26
+ adapter: this,
27
+ branch: branchReadState.branch,
28
+ collectionSlug,
29
+ mode: 'history'
30
+ }) : [];
11
31
  let hasNearConstraint = false;
12
32
  if (where) {
13
33
  const constraints = flattenWhereToOperators(where);
@@ -15,12 +35,14 @@ export const countVersions = async function countVersions({ collection: collecti
15
35
  }
16
36
  const query = await buildQuery({
17
37
  adapter: this,
38
+ branch,
18
39
  fields: buildVersionCollectionFields(this.payload.config, collectionConfig, true),
19
40
  locale,
41
+ req,
20
42
  where
21
43
  });
22
44
  // useEstimatedCount is faster, but not accurate, as it ignores any filters. It is thus set to true if there are no filters.
23
- const useEstimatedCount = hasNearConstraint || !query || Object.keys(query).length === 0;
45
+ const useEstimatedCount = !branchVisibility.length && (hasNearConstraint || !query || Object.keys(query).length === 0);
24
46
  const options = {
25
47
  session: await getSession(this, req)
26
48
  };
@@ -42,7 +64,17 @@ export const countVersions = async function countVersions({ collection: collecti
42
64
  };
43
65
  }
44
66
  let result;
45
- if (useEstimatedCount) {
67
+ if (branchVisibility.length) {
68
+ result = await Model.aggregate([
69
+ {
70
+ $match: query
71
+ },
72
+ ...branchVisibility,
73
+ {
74
+ $count: 'count'
75
+ }
76
+ ], options).then((rows)=>rows[0]?.count ?? 0);
77
+ } else if (useEstimatedCount) {
46
78
  result = await Model.estimatedDocumentCount({
47
79
  session: options.session
48
80
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/countVersions.ts"],"sourcesContent":["import type { CountOptions } from 'mongodb'\nimport type { CountVersions } from 'payload'\n\nimport { buildVersionCollectionFields, flattenWhereToOperators } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { getCollection } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\n\nexport const countVersions: CountVersions = async function countVersions(\n this: MongooseAdapter,\n { collection: collectionSlug, locale, req, where = {} },\n) {\n const { collectionConfig, Model } = getCollection({\n adapter: this,\n collectionSlug,\n versions: true,\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 query = await buildQuery({\n adapter: this,\n fields: buildVersionCollectionFields(this.payload.config, collectionConfig, true),\n locale,\n where,\n })\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 = hasNearConstraint || !query || Object.keys(query).length === 0\n\n const options: CountOptions = {\n session: await getSession(this, req),\n }\n\n if (this.collation) {\n const localizationConfig = this.payload.config.localization\n const defaultLocale =\n (typeof localizationConfig === 'object' && localizationConfig?.defaultLocale) || 'en'\n\n options.collation = {\n locale: locale && locale !== 'all' && locale !== '*' ? locale : defaultLocale,\n ...this.collation,\n }\n }\n\n if (!useEstimatedCount && Object.keys(query).length === 0 && this.disableIndexHints !== true) {\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 options.hint = {\n _id: 1,\n }\n }\n\n let result: number\n if (useEstimatedCount) {\n result = await Model.estimatedDocumentCount({ session: options.session })\n } else {\n result = await Model.countDocuments(query, options)\n }\n\n return {\n totalDocs: result,\n }\n}\n"],"names":["buildVersionCollectionFields","flattenWhereToOperators","buildQuery","getCollection","getSession","countVersions","collection","collectionSlug","locale","req","where","collectionConfig","Model","adapter","versions","hasNearConstraint","constraints","some","prop","Object","keys","key","query","fields","payload","config","useEstimatedCount","length","options","session","collation","localizationConfig","localization","defaultLocale","disableIndexHints","hint","_id","result","estimatedDocumentCount","countDocuments","totalDocs"],"mappings":"AAGA,SAASA,4BAA4B,EAAEC,uBAAuB,QAAQ,UAAS;AAI/E,SAASC,UAAU,QAAQ,0BAAyB;AACpD,SAASC,aAAa,QAAQ,2BAA0B;AACxD,SAASC,UAAU,QAAQ,4BAA2B;AAEtD,OAAO,MAAMC,gBAA+B,eAAeA,cAEzD,EAAEC,YAAYC,cAAc,EAAEC,MAAM,EAAEC,GAAG,EAAEC,QAAQ,CAAC,CAAC,EAAE;IAEvD,MAAM,EAAEC,gBAAgB,EAAEC,KAAK,EAAE,GAAGT,cAAc;QAChDU,SAAS,IAAI;QACbN;QACAO,UAAU;IACZ;IAEA,IAAIC,oBAAoB;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ions.ts"],"sourcesContent":["import type { CountOptions } from 'mongodb'\nimport type { CountVersions } from 'payload'\n\nimport {\n buildVersionCollectionFields,\n flattenWhereToOperators,\n resolveBranchReadState,\n resolveBranchVersionHistoryQuery,\n rewriteBranchVersionParents,\n} from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildBranchVisibilityStages } from './queries/buildBranchVisibility.js'\nimport { buildQuery } from './queries/buildQuery.js'\nimport { getCollection } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\n\nexport const countVersions: CountVersions = async function countVersions(\n this: MongooseAdapter,\n { branch, collection: collectionSlug, locale, req, where = {} },\n) {\n const { collectionConfig, Model } = getCollection({\n adapter: this,\n collectionSlug,\n versions: true,\n })\n const branchReadState = resolveBranchReadState({ branch, collectionSlug, req })\n\n // Shares the list's predicate so the count in the Versions tab can never\n // disagree with the rows the Versions view actually renders.\n where = branchReadState.useBranching\n ? (rewriteBranchVersionParents(where) ?? {})\n : ((await resolveBranchVersionHistoryQuery({ branch, collectionSlug, req, where })) ?? {})\n const branchVisibility = branchReadState.useBranching\n ? buildBranchVisibilityStages({\n adapter: this,\n branch: branchReadState.branch,\n collectionSlug,\n mode: 'history',\n })\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 query = await buildQuery({\n adapter: this,\n branch,\n fields: buildVersionCollectionFields(this.payload.config, collectionConfig, true),\n locale,\n req,\n where,\n })\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 !branchVisibility.length && (hasNearConstraint || !query || Object.keys(query).length === 0)\n\n const options: CountOptions = {\n session: await getSession(this, req),\n }\n\n if (this.collation) {\n const localizationConfig = this.payload.config.localization\n const defaultLocale =\n (typeof localizationConfig === 'object' && localizationConfig?.defaultLocale) || 'en'\n\n options.collation = {\n locale: locale && locale !== 'all' && locale !== '*' ? locale : defaultLocale,\n ...this.collation,\n }\n }\n\n if (!useEstimatedCount && Object.keys(query).length === 0 && this.disableIndexHints !== true) {\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 options.hint = {\n _id: 1,\n }\n }\n\n let result: number\n if (branchVisibility.length) {\n result = await Model.aggregate(\n [{ $match: query }, ...branchVisibility, { $count: 'count' }],\n options,\n ).then((rows) => rows[0]?.count ?? 0)\n } else if (useEstimatedCount) {\n result = await Model.estimatedDocumentCount({ session: options.session })\n } else {\n result = await Model.countDocuments(query, options)\n }\n\n return {\n totalDocs: result,\n }\n}\n"],"names":["buildVersionCollectionFields","flattenWhereToOperators","resolveBranchReadState","resolveBranchVersionHistoryQuery","rewriteBranchVersionParents","buildBranchVisibilityStages","buildQuery","getCollection","getSession","countVersions","branch","collection","collectionSlug","locale","req","where","collectionConfig","Model","adapter","versions","branchReadState","useBranching","branchVisibility","mode","hasNearConstraint","constraints","some","prop","Object","keys","key","query","fields","payload","config","useEstimatedCount","length","options","session","collation","localizationConfig","localization","defaultLocale","disableIndexHints","hint","_id","result","aggregate","$match","$count","then","rows","count","estimatedDocumentCount","countDocuments","totalDocs"],"mappings":"AAGA,SACEA,4BAA4B,EAC5BC,uBAAuB,EACvBC,sBAAsB,EACtBC,gCAAgC,EAChCC,2BAA2B,QACtB,UAAS;AAIhB,SAASC,2BAA2B,QAAQ,qCAAoC;AAChF,SAASC,UAAU,QAAQ,0BAAyB;AACpD,SAASC,aAAa,QAAQ,2BAA0B;AACxD,SAASC,UAAU,QAAQ,4BAA2B;AAEtD,OAAO,MAAMC,gBAA+B,eAAeA,cAEzD,EAAEC,MAAM,EAAEC,YAAYC,cAAc,EAAEC,MAAM,EAAEC,GAAG,EAAEC,QAAQ,CAAC,CAAC,EAAE;IAE/D,MAAM,EAAE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,WAAW,SAASA,WAAW,MAAMA,SAAS6B;YAChE,GAAG,IAAI,CAACH,SAAS;QACnB;IACF;IAEA,IAAI,CAACJ,qBAAqBP,OAAOC,IAAI,CAACE,OAAOK,MAAM,KAAK,KAAK,IAAI,CAACO,iBAAiB,KAAK,MAAM;QAC5F,mHAAmH;QACnH,qHAAqH;QACrH,mHAAmH;QACnH,4BAA4B;QAC5BN,QAAQO,IAAI,GAAG;YACbC,KAAK;QACP;IACF;IAEA,IAAIC;IACJ,IAAIxB,iBAAiBc,MAAM,EAAE;QAC3BU,SAAS,MAAM7B,MAAM8B,SAAS,CAC5B;YAAC;gBAAEC,QAAQjB;YAAM;eAAMT;YAAkB;gBAAE2B,QAAQ;YAAQ;SAAE,EAC7DZ,SACAa,IAAI,CAAC,CAACC,OAASA,IAAI,CAAC,EAAE,EAAEC,SAAS;IACrC,OAAO,IAAIjB,mBAAmB;QAC5BW,SAAS,MAAM7B,MAAMoC,sBAAsB,CAAC;YAAEf,SAASD,QAAQC,OAAO;QAAC;IACzE,OAAO;QACLQ,SAAS,MAAM7B,MAAMqC,cAAc,CAACvB,OAAOM;IAC7C;IAEA,OAAO;QACLkB,WAAWT;IACb;AACF,EAAC"}
@@ -1,3 +1,3 @@
1
- import { type CreateGlobalVersion } from 'payload';
1
+ import type { CreateGlobalVersion } from 'payload';
2
2
  export declare const createGlobalVersion: CreateGlobalVersion;
3
3
  //# sourceMappingURL=createGlobalVersion.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"createGlobalVersion.d.ts","sourceRoot":"","sources":["../src/createGlobalVersion.ts"],"names":[],"mappings":"AAAA,OAAO,EAA4B,KAAK,mBAAmB,EAAE,MAAM,SAAS,CAAA;AAQ5E,eAAO,MAAM,mBAAmB,EAAE,mBA+EjC,CAAA"}
1
+ {"version":3,"file":"createGlobalVersion.d.ts","sourceRoot":"","sources":["../src/createGlobalVersion.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAA;AAUlD,eAAO,MAAM,mBAAmB,EAAE,mBA6FjC,CAAA"}
@@ -1,4 +1,4 @@
1
- import { buildVersionGlobalFields } from 'payload';
1
+ import { buildVersionGlobalFields, MAIN_BRANCH, resolveBranch } from 'payload';
2
2
  import { getGlobal } from './utilities/getEntity.js';
3
3
  import { getSession } from './utilities/getSession.js';
4
4
  import { transform } from './utilities/transform.js';
@@ -8,7 +8,11 @@ export const createGlobalVersion = async function createGlobalVersion({ autosave
8
8
  globalSlug,
9
9
  versions: true
10
10
  });
11
+ const versionBranch = req?.payload?.config?.branching?.branchableGlobals?.has(globalSlug) ? resolveBranch({
12
+ req: req
13
+ }) : MAIN_BRANCH;
11
14
  const data = {
15
+ _branch: versionBranch,
12
16
  autosave,
13
17
  createdAt,
14
18
  latest: true,
@@ -35,6 +39,9 @@ export const createGlobalVersion = async function createGlobalVersion({ autosave
35
39
  let [doc] = await Model.create([
36
40
  data
37
41
  ], options);
42
+ // Scoped by `_branch`. Unlike collection versions, global versions have no
43
+ // `parent` to separate streams by — every version of a global shares one — so
44
+ // without this an unscoped clear would wipe main's latest flag from a branch.
38
45
  await Model.updateMany({
39
46
  $and: [
40
47
  {
@@ -46,6 +53,22 @@ export const createGlobalVersion = async function createGlobalVersion({ autosave
46
53
  latest: {
47
54
  $eq: true
48
55
  }
56
+ },
57
+ {
58
+ $or: [
59
+ {
60
+ _branch: {
61
+ $eq: versionBranch
62
+ }
63
+ },
64
+ ...versionBranch === MAIN_BRANCH ? [
65
+ {
66
+ _branch: {
67
+ $exists: false
68
+ }
69
+ }
70
+ ] : []
71
+ ]
49
72
  }
50
73
  ]
51
74
  }, {
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/createGlobalVersion.ts"],"sourcesContent":["import { buildVersionGlobalFields, type CreateGlobalVersion } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { getGlobal } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\nimport { transform } from './utilities/transform.js'\n\nexport const createGlobalVersion: CreateGlobalVersion = async function createGlobalVersion(\n this: MongooseAdapter,\n {\n autosave,\n createdAt,\n globalSlug,\n publishedLocale,\n req,\n returning,\n snapshot,\n updatedAt,\n versionData,\n },\n) {\n const { globalConfig, Model } = getGlobal({ adapter: this, globalSlug, versions: true })\n\n const data = {\n autosave,\n createdAt,\n latest: true,\n publishedLocale,\n snapshot,\n updatedAt,\n version: versionData,\n }\n if (!data.createdAt) {\n data.createdAt = new Date().toISOString()\n }\n\n const fields = buildVersionGlobalFields(this.payload.config, globalConfig)\n\n transform({\n adapter: this,\n data,\n fields,\n operation: 'write',\n })\n\n const options = {\n session: await getSession(this, req),\n // Timestamps are manually added by the write transform\n timestamps: false,\n }\n\n let [doc] = await Model.create([data], options)\n\n await Model.updateMany(\n {\n $and: [\n {\n _id: {\n $ne: doc._id,\n },\n },\n {\n latest: {\n $eq: true,\n },\n },\n ],\n },\n { $unset: { latest: 1 } },\n options,\n )\n\n if (returning === false) {\n return null\n }\n\n doc = doc.toObject()\n\n transform({\n adapter: this,\n data: doc,\n fields,\n operation: 'read',\n })\n\n return doc\n}\n"],"names":["buildVersionGlobalFields","getGlobal","getSession","transform","createGlobalVersion","autosave","createdAt","globalSlug","publishedLocale","req","returning","snapshot","updatedAt","versionData","globalConfig","Model","adapter","versions","data","latest","version","Date","toISOString","fields","payload","config","operation","options","session","timestamps","doc","create","updateMany","$and","_id","$ne","$eq","$unset","toObject"],"mappings":"AAAA,SAASA,wBAAwB,QAAkC,UAAS;AAI5E,SAASC,SAAS,QAAQ,2BAA0B;AACpD,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,SAAS,QAAQ,2BAA0B;AAEpD,OAAO,MAAMC,sBAA2C,eAAeA,oBAErE,EACEC,QAAQ,EACRC,SAAS,EACTC,UAAU,EACVC,eAAe,EACfC,GAAG,EACHC,SAAS,EACTC,QAAQ,EACRC,SAAS,EACTC,WAAW,EACZ;IAED,MAAM,EAAEC,YAAY,EAAEC,KAAK,EAAE,GAAGd,UAAU;QAAEe,SAAS,IAAI;QAAET;QAAYU,UAAU;IAAK;IAEtF,MAAMC,OAAO;QACXb;QACAC;QACAa,QAAQ;QACRX;QACAG;QACAC;QACAQ,SAASP;IACX;IACA,IAAI,CAACK,KAAKZ,SAAS,EAAE;QACnBY,KAAKZ,SAAS,GAAG,IAAIe,OAAOC,WAAW;IACzC;IAEA,MAAMC,SAASvB,yBAAyB,IAAI,CAACwB,OAAO,CAACC,MAAM,EAAEX;IAE7DX,UAAU;QACRa,SAAS,IAAI;QACbE;QACAK;QACAG,WAAW;IACb;IAEA,MAAMC,UAAU;QACdC,SAAS,MAAM1B,WAAW,IAAI,EAAEO;QAChC,uDAAuD;QACvDoB,YAAY;IACd;IAEA,IAAI,CAACC,IAAI,GAAG,MAAMf,MAAMgB,MAAM,CAAC;QAACb;KAAK,EAAES;IAEvC,MAAMZ,MAAMiB,UAAU,CACpB;QACEC,MAAM;YACJ;gBACEC,KAAK;oBACHC,KAAKL,IAAII,GAAG;gBACd;YACF;YACA;gBACEf,QAAQ;oBACNiB,KAAK;gBACP;YACF;SACD;IACH,GACA;QAAEC,QAAQ;YAAElB,QAAQ;QAAE;IAAE,GACxBQ;IAGF,IAAIjB,cAAc,OAAO;QACvB,OAAO;IACT;IAEAoB,MAAMA,IAAIQ,QAAQ;IAElBnC,UAAU;QACRa,SAAS,IAAI;QACbE,MAAMY;QACNP;QACAG,WAAW;IACb;IAEA,OAAOI;AACT,EAAC"}
1
+ {"version":3,"sources":["../src/createGlobalVersion.ts"],"sourcesContent":["import type { CreateGlobalVersion } from 'payload'\n\nimport { buildVersionGlobalFields, MAIN_BRANCH, resolveBranch } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { getGlobal } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\nimport { transform } from './utilities/transform.js'\n\nexport const createGlobalVersion: CreateGlobalVersion = async function createGlobalVersion(\n this: MongooseAdapter,\n {\n autosave,\n createdAt,\n globalSlug,\n publishedLocale,\n req,\n returning,\n snapshot,\n updatedAt,\n versionData,\n },\n) {\n const { globalConfig, Model } = getGlobal({ adapter: this, globalSlug, versions: true })\n\n const versionBranch = req?.payload?.config?.branching?.branchableGlobals?.has(globalSlug)\n ? resolveBranch({ req: req as never })\n : MAIN_BRANCH\n\n const data = {\n _branch: versionBranch,\n autosave,\n createdAt,\n latest: true,\n publishedLocale,\n snapshot,\n updatedAt,\n version: versionData,\n }\n if (!data.createdAt) {\n data.createdAt = new Date().toISOString()\n }\n\n const fields = buildVersionGlobalFields(this.payload.config, globalConfig)\n\n transform({\n adapter: this,\n data,\n fields,\n operation: 'write',\n })\n\n const options = {\n session: await getSession(this, req),\n // Timestamps are manually added by the write transform\n timestamps: false,\n }\n\n let [doc] = await Model.create([data], options)\n\n // Scoped by `_branch`. Unlike collection versions, global versions have no\n // `parent` to separate streams by — every version of a global shares one — so\n // without this an unscoped clear would wipe main's latest flag from a branch.\n await Model.updateMany(\n {\n $and: [\n {\n _id: {\n $ne: doc._id,\n },\n },\n {\n latest: {\n $eq: true,\n },\n },\n {\n $or: [\n { _branch: { $eq: versionBranch } },\n ...(versionBranch === MAIN_BRANCH ? [{ _branch: { $exists: false } }] : []),\n ],\n },\n ],\n },\n { $unset: { latest: 1 } },\n options,\n )\n\n if (returning === false) {\n return null\n }\n\n doc = doc.toObject()\n\n transform({\n adapter: this,\n data: doc,\n fields,\n operation: 'read',\n })\n\n return doc\n}\n"],"names":["buildVersionGlobalFields","MAIN_BRANCH","resolveBranch","getGlobal","getSession","transform","createGlobalVersion","autosave","createdAt","globalSlug","publishedLocale","req","returning","snapshot","updatedAt","versionData","globalConfig","Model","adapter","versions","versionBranch","payload","config","branching","branchableGlobals","has","data","_branch","latest","version","Date","toISOString","fields","operation","options","session","timestamps","doc","create","updateMany","$and","_id","$ne","$eq","$or","$exists","$unset","toObject"],"mappings":"AAEA,SAASA,wBAAwB,EAAEC,WAAW,EAAEC,aAAa,QAAQ,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;oBAAE;uBAC9BA,kBAAkBnB,cAAc;wBAAC;4BAAE0B,SAAS;gCAAEkB,SAAS;4BAAM;wBAAE;qBAAE,GAAG,EAAE;iBAC3E;YACH;SACD;IACH,GACA;QAAEC,QAAQ;YAAElB,QAAQ;QAAE;IAAE,GACxBM;IAGF,IAAItB,cAAc,OAAO;QACvB,OAAO;IACT;IAEAyB,MAAMA,IAAIU,QAAQ;IAElB1C,UAAU;QACRa,SAAS,IAAI;QACbQ,MAAMW;QACNL;QACAC,WAAW;IACb;IAEA,OAAOI;AACT,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"createVersion.d.ts","sourceRoot":"","sources":["../src/createVersion.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgC,KAAK,aAAa,EAAE,MAAM,SAAS,CAAA;AAQ1E,eAAO,MAAM,aAAa,EAAE,aAqG3B,CAAA"}
1
+ {"version":3,"file":"createVersion.d.ts","sourceRoot":"","sources":["../src/createVersion.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,aAAa,EAEnB,MAAM,SAAS,CAAA;AAQhB,eAAO,MAAM,aAAa,EAAE,aAkH3B,CAAA"}
@@ -1,4 +1,4 @@
1
- import { buildVersionCollectionFields } from 'payload';
1
+ import { buildVersionCollectionFields, resolveBranchVersionParent } from 'payload';
2
2
  import { getCollection } from './utilities/getEntity.js';
3
3
  import { getSession } from './utilities/getSession.js';
4
4
  import { transform } from './utilities/transform.js';
@@ -8,15 +8,25 @@ export const createVersion = async function createVersion({ autosave, collection
8
8
  collectionSlug,
9
9
  versions: true
10
10
  });
11
+ const branched = await resolveBranchVersionParent({
12
+ collectionSlug,
13
+ parent,
14
+ req,
15
+ versionData: versionData
16
+ });
11
17
  const data = {
12
18
  autosave,
13
19
  createdAt,
14
20
  latest: true,
15
- parent,
21
+ parent: branched.parent,
16
22
  publishedLocale,
17
23
  snapshot,
18
24
  updatedAt,
19
- version: versionData
25
+ version: versionData,
26
+ ...branched.versionData._branch ? {
27
+ _branch: branched.versionData._branch,
28
+ _branchParent: branched.versionData._branchParent
29
+ } : {}
20
30
  };
21
31
  if (!data.createdAt) {
22
32
  data.createdAt = new Date().toISOString();
@@ -36,6 +46,9 @@ export const createVersion = async function createVersion({ autosave, collection
36
46
  let [doc] = await Model.create([
37
47
  data
38
48
  ], options);
49
+ // No branch scoping needed here: a branch version's `parent` is the shadow
50
+ // row's own primary key, so main's chain and the branch's chain are already
51
+ // disjoint and `latest` clearing cannot cross between them.
39
52
  const parentQuery = {
40
53
  $or: [
41
54
  {
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/createVersion.ts"],"sourcesContent":["import { buildVersionCollectionFields, type CreateVersion } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { getCollection } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\nimport { transform } from './utilities/transform.js'\n\nexport const createVersion: CreateVersion = async function createVersion(\n this: MongooseAdapter,\n {\n autosave,\n collectionSlug,\n createdAt,\n parent,\n publishedLocale,\n req,\n returning,\n snapshot,\n updatedAt,\n versionData,\n },\n) {\n const { collectionConfig, Model } = getCollection({\n adapter: this,\n collectionSlug,\n versions: true,\n })\n\n const data = {\n autosave,\n createdAt,\n latest: true,\n parent,\n publishedLocale,\n snapshot,\n updatedAt,\n version: versionData,\n }\n if (!data.createdAt) {\n data.createdAt = new Date().toISOString()\n }\n\n const fields = buildVersionCollectionFields(this.payload.config, collectionConfig)\n\n transform({\n adapter: this,\n data,\n fields,\n operation: 'write',\n })\n\n const options = {\n session: await getSession(this, req),\n // Timestamps are manually added by the write transform\n timestamps: false,\n }\n\n let [doc] = await Model.create([data], options)\n\n const parentQuery = {\n $or: [\n {\n parent: {\n $eq: data.parent,\n },\n },\n ],\n }\n\n await Model.updateMany(\n {\n $and: [\n {\n _id: {\n $ne: doc._id,\n },\n },\n parentQuery,\n {\n latest: {\n $eq: true,\n },\n },\n {\n updatedAt: {\n $lt: new Date(doc.updatedAt),\n },\n },\n ],\n },\n { $unset: { latest: 1 } },\n options,\n )\n\n if (returning === false) {\n return null\n }\n\n doc = doc.toObject()\n\n transform({\n adapter: this,\n data: doc,\n fields,\n operation: 'read',\n })\n\n return doc\n}\n"],"names":["buildVersionCollectionFields","getCollection","getSession","transform","createVersion","autosave","collectionSlug","createdAt","parent","publishedLocale","req","returning","snapshot","updatedAt","versionData","collectionConfig","Model","adapter","versions","data","latest","version","Date","toISOString","fields","payload","config","operation","options","session","timestamps","doc","create","parentQuery","$or","$eq","updateMany","$and","_id","$ne","$lt","$unset","toObject"],"mappings":"AAAA,SAASA,4BAA4B,QAA4B,UAAS;AAI1E,SAASC,aAAa,QAAQ,2BAA0B;AACxD,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,SAAS,QAAQ,2BAA0B;AAEpD,OAAO,MAAMC,gBAA+B,eAAeA,cAEzD,EACEC,QAAQ,EACRC,cAAc,EACdC,SAAS,EACTC,MAAM,EACNC,eAAe,EACfC,GAAG,EACHC,SAAS,EACTC,QAAQ,EACRC,SAAS,EACTC,WAAW,EACZ;IAED,MAAM,EAAEC,gBAAgB,EAAEC,KAAK,EAAE,GAAGf,cAAc;QAChDgB,SAAS,IAAI;QACbX;QACAY,UAAU;IACZ;IAEA,MAAMC,OAAO;QACXd;QACAE;QACAa,QAAQ;QACRZ;QACAC;QACAG;QACAC;QACAQ,SAASP;IACX;IACA,IAAI,CAACK,KAAKZ,SAAS,EAAE;QACnBY,KAAKZ,SAAS,GAAG,IAAIe,OAAOC,WAAW;IACzC;IAEA,MAAMC,SAASxB,6BAA6B,IAAI,CAACyB,OAAO,CAACC,MAAM,EAAEX;IAEjEZ,UAAU;QACRc,SAAS,IAAI;QACbE;QACAK;QACAG,WAAW;IACb;IAEA,MAAMC,UAAU;QACdC,SAAS,MAAM3B,WAAW,IAAI,EAAEQ;QAChC,uDAAuD;QACvDoB,YAAY;IACd;IAEA,IAAI,CAACC,IAAI,GAAG,MAAMf,MAAMgB,MAAM,CAAC;QAACb;KAAK,EAAES;IAEvC,MAAMK,cAAc;QAClBC,KAAK;YACH;gBACE1B,QAAQ;oBACN2B,KAAKhB,KAAKX,MAAM;gBAClB;YACF;SACD;IACH;IAEA,MAAMQ,MAAMoB,UAAU,CACpB;QACEC,MAAM;YACJ;gBACEC,KAAK;oBACHC,KAAKR,IAAIO,GAAG;gBACd;YACF;YACAL;YACA;gBACEb,QAAQ;oBACNe,KAAK;gBACP;YACF;YACA;gBACEtB,WAAW;oBACT2B,KAAK,IAAIlB,KAAKS,IAAIlB,SAAS;gBAC7B;YACF;SACD;IACH,GACA;QAAE4B,QAAQ;YAAErB,QAAQ;QAAE;IAAE,GACxBQ;IAGF,IAAIjB,cAAc,OAAO;QACvB,OAAO;IACT;IAEAoB,MAAMA,IAAIW,QAAQ;IAElBvC,UAAU;QACRc,SAAS,IAAI;QACbE,MAAMY;QACNP;QACAG,WAAW;IACb;IAEA,OAAOI;AACT,EAAC"}
1
+ {"version":3,"sources":["../src/createVersion.ts"],"sourcesContent":["import {\n buildVersionCollectionFields,\n type CreateVersion,\n resolveBranchVersionParent,\n} from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { getCollection } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\nimport { transform } from './utilities/transform.js'\n\nexport const createVersion: CreateVersion = async function createVersion(\n this: MongooseAdapter,\n {\n autosave,\n collectionSlug,\n createdAt,\n parent,\n publishedLocale,\n req,\n returning,\n snapshot,\n updatedAt,\n versionData,\n },\n) {\n const { collectionConfig, Model } = getCollection({\n adapter: this,\n collectionSlug,\n versions: true,\n })\n\n const branched = await resolveBranchVersionParent({\n collectionSlug,\n parent,\n req,\n versionData: versionData as Record<string, unknown>,\n })\n\n const data = {\n autosave,\n createdAt,\n latest: true,\n parent: branched.parent,\n publishedLocale,\n snapshot,\n updatedAt,\n version: versionData,\n ...(branched.versionData._branch\n ? { _branch: branched.versionData._branch, _branchParent: branched.versionData._branchParent }\n : {}),\n }\n if (!data.createdAt) {\n data.createdAt = new Date().toISOString()\n }\n\n const fields = buildVersionCollectionFields(this.payload.config, collectionConfig)\n\n transform({\n adapter: this,\n data,\n fields,\n operation: 'write',\n })\n\n const options = {\n session: await getSession(this, req),\n // Timestamps are manually added by the write transform\n timestamps: false,\n }\n\n let [doc] = await Model.create([data], options)\n\n // No branch scoping needed here: a branch version's `parent` is the shadow\n // row's own primary key, so main's chain and the branch's chain are already\n // disjoint and `latest` clearing cannot cross between them.\n const parentQuery = {\n $or: [\n {\n parent: {\n $eq: data.parent,\n },\n },\n ],\n }\n\n await Model.updateMany(\n {\n $and: [\n {\n _id: {\n $ne: doc._id,\n },\n },\n parentQuery,\n {\n latest: {\n $eq: true,\n },\n },\n {\n updatedAt: {\n $lt: new Date(doc.updatedAt),\n },\n },\n ],\n },\n { $unset: { latest: 1 } },\n options,\n )\n\n if (returning === false) {\n return null\n }\n\n doc = doc.toObject()\n\n transform({\n adapter: this,\n data: doc,\n fields,\n operation: 'read',\n })\n\n return doc\n}\n"],"names":["buildVersionCollectionFields","resolveBranchVersionParent","getCollection","getSession","transform","createVersion","autosave","collectionSlug","createdAt","parent","publishedLocale","req","returning","snapshot","updatedAt","versionData","collectionConfig","Model","adapter","versions","branched","data","latest","version","_branch","_branchParent","Date","toISOString","fields","payload","config","operation","options","session","timestamps","doc","create","parentQuery","$or","$eq","updateMany","$and","_id","$ne","$lt","$unset","toObject"],"mappings":"AAAA,SACEA,4BAA4B,EAE5BC,0BAA0B,QACrB,UAAS;AAIhB,SAASC,aAAa,QAAQ,2BAA0B;AACxD,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,SAAS,QAAQ,2BAA0B;AAEpD,OAAO,MAAMC,gBAA+B,eAAeA,cAEzD,EACEC,QAAQ,EACRC,cAAc,EACdC,SAAS,EACTC,MAAM,EACNC,eAAe,EACfC,GAAG,EACHC,SAAS,EACTC,QAAQ,EACRC,SAAS,EACTC,WAAW,EACZ;IAED,MAAM,EAAEC,gBAAgB,EAAEC,KAAK,EAA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IAGF,IAAIpB,cAAc,OAAO;QACvB,OAAO;IACT;IAEAuB,MAAMA,IAAIW,QAAQ;IAElB1C,UAAU;QACRc,SAAS,IAAI;QACbG,MAAMc;QACNP;QACAG,WAAW;IACb;IAEA,OAAOI;AACT,EAAC"}
@@ -0,0 +1,10 @@
1
+ import type { DeleteBranchGlobal } from 'payload';
2
+ /**
3
+ * Drops a branch's copy of a global.
4
+ *
5
+ * Every global lives in one discriminated collection here, so the branch's copy is a
6
+ * sibling row identified by `globalType` and `_branch` — addressed directly rather than
7
+ * through any generic delete, since no other part of Payload deletes a global.
8
+ */
9
+ export declare const deleteBranchGlobal: DeleteBranchGlobal;
10
+ //# sourceMappingURL=deleteBranchGlobal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deleteBranchGlobal.d.ts","sourceRoot":"","sources":["../src/deleteBranchGlobal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAA;AASjD;;;;;;GAMG;AACH,eAAO,MAAM,kBAAkB,EAAE,kBAchC,CAAA"}
@@ -0,0 +1,26 @@
1
+ import { MAIN_BRANCH } from 'payload';
2
+ import { getGlobal } from './utilities/getEntity.js';
3
+ import { getSession } from './utilities/getSession.js';
4
+ /**
5
+ * Drops a branch's copy of a global.
6
+ *
7
+ * Every global lives in one discriminated collection here, so the branch's copy is a
8
+ * sibling row identified by `globalType` and `_branch` — addressed directly rather than
9
+ * through any generic delete, since no other part of Payload deletes a global.
10
+ */ export const deleteBranchGlobal = async function deleteBranchGlobal({ branch, globalSlug, req }) {
11
+ if (branch === MAIN_BRANCH) {
12
+ throw new Error('Cannot delete a main global as a branch copy.');
13
+ }
14
+ const { Model } = getGlobal({
15
+ adapter: this,
16
+ globalSlug
17
+ });
18
+ await Model.deleteOne({
19
+ _branch: branch,
20
+ globalType: globalSlug
21
+ }, {
22
+ session: await getSession(this, req)
23
+ });
24
+ };
25
+
26
+ //# sourceMappingURL=deleteBranchGlobal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/deleteBranchGlobal.ts"],"sourcesContent":["import type { DeleteBranchGlobal } from 'payload'\n\nimport { MAIN_BRANCH } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { getGlobal } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\n\n/**\n * Drops a branch's copy of a global.\n *\n * Every global lives in one discriminated collection here, so the branch's copy is a\n * sibling row identified by `globalType` and `_branch` — addressed directly rather than\n * through any generic delete, since no other part of Payload deletes a global.\n */\nexport const deleteBranchGlobal: DeleteBranchGlobal = async function deleteBranchGlobal(\n this: MongooseAdapter,\n { branch, globalSlug, req },\n) {\n if (branch === MAIN_BRANCH) {\n throw new Error('Cannot delete a main global as a branch copy.')\n }\n\n const { Model } = getGlobal({ adapter: this, globalSlug })\n\n await Model.deleteOne(\n { _branch: branch, globalType: globalSlug },\n { session: await getSession(this, req) },\n )\n}\n"],"names":["MAIN_BRANCH","getGlobal","getSession","deleteBranchGlobal","branch","globalSlug","req","Error","Model","adapter","deleteOne","_branch","globalType","session"],"mappings":"AAEA,SAASA,WAAW,QAAQ,UAAS;AAIrC,SAASC,SAAS,QAAQ,2BAA0B;AACpD,SAASC,UAAU,QAAQ,4BAA2B;AAEtD;;;;;;CAMC,GACD,OAAO,MAAMC,qBAAyC,eAAeA,mBAEnE,EAAEC,MAAM,EAAEC,UAAU,EAAEC,GAAG,EAAE;IAE3B,IAAIF,WAAWJ,aAAa;QAC1B,MAAM,IAAIO,MAAM;IAClB;IAEA,MAAM,EAAEC,KAAK,EAAE,GAAGP,UAAU;QAAEQ,SAAS,IAAI;QAAEJ;IAAW;IAExD,MAAMG,MAAME,SAAS,CACnB;QAAEC,SAASP;QAAQQ,YAAYP;IAAW,GAC1C;QAAEQ,SAAS,MAAMX,WAAW,IAAI,EAAEI;IAAK;AAE3C,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"deleteMany.d.ts","sourceRoot":"","sources":["../src/deleteMany.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,SAAS,CAAA;AAQzC,eAAO,MAAM,UAAU,EAAE,UAkBxB,CAAA"}
1
+ {"version":3,"file":"deleteMany.d.ts","sourceRoot":"","sources":["../src/deleteMany.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,SAAS,CAAA;AAQzC,eAAO,MAAM,UAAU,EAAE,UAmBxB,CAAA"}
@@ -10,6 +10,7 @@ export const deleteMany = async function deleteMany({ collection: collectionSlug
10
10
  adapter: this,
11
11
  collectionSlug,
12
12
  fields: collectionConfig.flattenedFields,
13
+ req,
13
14
  where
14
15
  });
15
16
  const options = {
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/deleteMany.ts"],"sourcesContent":["import type { DeleteOptions } from 'mongodb'\n\nimport { type DeleteMany } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { getCollection } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\n\nexport const deleteMany: DeleteMany = async function deleteMany(\n this: MongooseAdapter,\n { collection: collectionSlug, req, where },\n) {\n const { collectionConfig, Model } = getCollection({ adapter: this, collectionSlug })\n\n const query = await buildQuery({\n adapter: this,\n collectionSlug,\n fields: collectionConfig.flattenedFields,\n where,\n })\n\n const options: DeleteOptions = {\n session: await getSession(this, req),\n }\n\n await Model.deleteMany(query, options)\n}\n"],"names":["buildQuery","getCollection","getSession","deleteMany","collection","collectionSlug","req","where","collectionConfig","Model","adapter","query","fields","flattenedFields","options","session"],"mappings":"AAMA,SAASA,UAAU,QAAQ,0BAAyB;AACpD,SAASC,aAAa,QAAQ,2BAA0B;AACxD,SAASC,UAAU,QAAQ,4BAA2B;AAEtD,OAAO,MAAMC,aAAyB,eAAeA,WAEnD,EAAEC,YAAYC,cAAc,EAAEC,GAAG,EAAEC,KAAK,EAAE;IAE1C,MAAM,EAAEC,gBAAgB,EAAEC,KAAK,EAAE,GAAGR,cAAc;QAAES,SAAS,IAAI;QAAEL;IAAe;IAElF,MAAMM,QAAQ,MAAMX,WAAW;QAC7BU,SAAS,IAAI;QACbL;QACAO,QAAQJ,iBAAiBK,eAAe;QACxCN;IACF;IAEA,MAAMO,UAAyB;QAC7BC,SAAS,MAAMb,WAAW,IAAI,EAAEI;IAClC;IAEA,MAAMG,MAAMN,UAAU,CAACQ,OAAOG;AAChC,EAAC"}
1
+ {"version":3,"sources":["../src/deleteMany.ts"],"sourcesContent":["import type { DeleteOptions } from 'mongodb'\n\nimport { type DeleteMany } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { getCollection } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\n\nexport const deleteMany: DeleteMany = async function deleteMany(\n this: MongooseAdapter,\n { collection: collectionSlug, req, where },\n) {\n const { collectionConfig, Model } = getCollection({ adapter: this, collectionSlug })\n\n const query = await buildQuery({\n adapter: this,\n collectionSlug,\n fields: collectionConfig.flattenedFields,\n req,\n where,\n })\n\n const options: DeleteOptions = {\n session: await getSession(this, req),\n }\n\n await Model.deleteMany(query, options)\n}\n"],"names":["buildQuery","getCollection","getSession","deleteMany","collection","collectionSlug","req","where","collectionConfig","Model","adapter","query","fields","flattenedFields","options","session"],"mappings":"AAMA,SAASA,UAAU,QAAQ,0BAAyB;AACpD,SAASC,aAAa,QAAQ,2BAA0B;AACxD,SAASC,UAAU,QAAQ,4BAA2B;AAEtD,OAAO,MAAMC,aAAyB,eAAeA,WAEnD,EAAEC,YAAYC,cAAc,EAAEC,GAAG,EAAEC,KAAK,EAAE;IAE1C,MAAM,EAAEC,gBAAgB,EAAEC,KAAK,EAAE,GAAGR,cAAc;QAAES,SAAS,IAAI;QAAEL;IAAe;IAElF,MAAMM,QAAQ,MAAMX,WAAW;QAC7BU,SAAS,IAAI;QACbL;QACAO,QAAQJ,iBAAiBK,eAAe;QACxCP;QACAC;IACF;IAEA,MAAMO,UAAyB;QAC7BC,SAAS,MAAMb,WAAW,IAAI,EAAEI;IAClC;IAEA,MAAMG,MAAMN,UAAU,CAACQ,OAAOG;AAChC,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"deleteOne.d.ts","sourceRoot":"","sources":["../src/deleteOne.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAUxC,eAAO,MAAM,SAAS,EAAE,SAyCvB,CAAA"}
1
+ {"version":3,"file":"deleteOne.d.ts","sourceRoot":"","sources":["../src/deleteOne.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAYxC,eAAO,MAAM,SAAS,EAAE,SAqDvB,CAAA"}
package/dist/deleteOne.js CHANGED
@@ -1,17 +1,36 @@
1
+ import { resolveBranchDelete } from 'payload';
1
2
  import { buildQuery } from './queries/buildQuery.js';
2
3
  import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
3
4
  import { getCollection } from './utilities/getEntity.js';
4
5
  import { getSession } from './utilities/getSession.js';
5
6
  import { transform } from './utilities/transform.js';
6
- export const deleteOne = async function deleteOne({ collection: collectionSlug, req, returning, select, where }) {
7
+ export const deleteOne = async function deleteOne({ branch, collection: collectionSlug, req, returning, select, where }) {
7
8
  const { collectionConfig, Model } = getCollection({
8
9
  adapter: this,
9
10
  collectionSlug
10
11
  });
12
+ const branchDelete = await resolveBranchDelete({
13
+ branch,
14
+ collectionSlug,
15
+ req,
16
+ where
17
+ });
18
+ if (branchDelete.tombstoned) {
19
+ return returning === false ? null : branchDelete.doc;
20
+ }
21
+ if (branchDelete.deleteRowID !== undefined) {
22
+ where = {
23
+ id: {
24
+ equals: branchDelete.deleteRowID
25
+ }
26
+ };
27
+ }
11
28
  const query = await buildQuery({
12
29
  adapter: this,
30
+ branch,
13
31
  collectionSlug,
14
32
  fields: collectionConfig.flattenedFields,
33
+ req,
15
34
  where
16
35
  });
17
36
  const options = {