@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
@@ -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,OAmHrB,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,OAkHrB,CAAA"}
package/dist/connect.js CHANGED
@@ -69,7 +69,6 @@ export const connect = async function connect(options = {
69
69
  this.collections[collection.slug],
70
70
  this.versions[collection.slug]
71
71
  ]),
72
- this.globals,
73
72
  ...this.payload.config.globals.map((global)=>this.versions[global.slug])
74
73
  ].map(async (model)=>{
75
74
  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.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,G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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.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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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;AAgBpC,eAAO,MAAM,KAAK,EAAE,KA+EnB,CAAA"}
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"}
package/dist/count.js CHANGED
@@ -1,29 +1,12 @@
1
- import { flattenWhereToOperators, resolveBranchQuery, resolveBranchReadState, rewriteBranchIDs } from 'payload';
2
- import { buildBranchVisibilityStages } from './queries/buildBranchVisibility.js';
1
+ import { flattenWhereToOperators } from 'payload';
3
2
  import { buildQuery } from './queries/buildQuery.js';
4
3
  import { getCollection } from './utilities/getEntity.js';
5
4
  import { getSession } from './utilities/getSession.js';
6
- export const count = async function count({ branch, collection: collectionSlug, locale, req, where = {} }) {
5
+ export const count = async function count({ collection: collectionSlug, locale, req, where = {} }) {
7
6
  const { collectionConfig, Model } = getCollection({
8
7
  adapter: this,
9
8
  collectionSlug
10
9
  });
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
- }) : [];
27
10
  let hasNearConstraint = false;
28
11
  if (where) {
29
12
  const constraints = flattenWhereToOperators(where);
@@ -31,15 +14,13 @@ export const count = async function count({ branch, collection: collectionSlug,
31
14
  }
32
15
  const query = await buildQuery({
33
16
  adapter: this,
34
- branch,
35
17
  collectionSlug,
36
18
  fields: collectionConfig.flattenedFields,
37
19
  locale,
38
- req,
39
20
  where
40
21
  });
41
22
  // useEstimatedCount is faster, but not accurate, as it ignores any filters. It is thus set to true if there are no filters.
42
- const useEstimatedCount = !branchVisibility.length && (hasNearConstraint || !query || Object.keys(query).length === 0);
23
+ const useEstimatedCount = hasNearConstraint || !query || Object.keys(query).length === 0;
43
24
  const options = {
44
25
  session: await getSession(this, req)
45
26
  };
@@ -61,17 +42,7 @@ export const count = async function count({ branch, collection: collectionSlug,
61
42
  };
62
43
  }
63
44
  let result;
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) {
45
+ if (useEstimatedCount) {
75
46
  result = await Model.estimatedDocumentCount({
76
47
  session: options.session
77
48
  });
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 {\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,qCAAoC;AAChF,SAASC,UAAU,QAAQ,0BAAyB;AACpD,SAASC,aAAa,QAAQ,2BAA0B;AACxD,SAASC,UAAU,QAAQ,4BAA2B;AAEtD,OAAO,MAAMC,QAAe,eAAeA,MAEzC,EAAEC,MAAM,EAAEC,YAAYC,cAAc,EAAEC,MAAM,EAAEC,GAAG,EAAEC,QAAQ,CAAC,CAAC,EAAE;IAE/D,MAAM,EAAEC,gBAAgB,EAAEC,KAAK,EAAE,GAAGV,cAAc;QAAEW,SAAS,IAAI;QAAEN;IAAe;IAClF,MAAMO,kBAAkBhB,uBAAuB;QAAEO;QAAQE;QAAgBE;IAAI;IAE7EC,QAAQI,gBAAgBC,YAAY,GAC/BhB,iBAAiBW,UAAU,CAAC,IAC5B,AAAC,MAAMb,mBAAmB;QAAEQ;QAAQE;QAAgBE;QAAKC;IAAM,MAAO,CAAC;IAC5E,MAAMM,mBAAmBF,gBAAgBC,YAAY,GACjDf,4BAA4B;QAC1Ba,SAAS,IAAI;QACbR,QAAQS,gBAAgBT,MAAM;QAC9BE;IACF,KACA,EAAE;IAEN,IAAIU,oBAAoB;IAExB,I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S;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
+ {"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 +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,mBA2DjC,CAAA"}
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"}
@@ -17,7 +17,6 @@ export const countGlobalVersions = async function countGlobalVersions({ global:
17
17
  adapter: this,
18
18
  fields: buildVersionGlobalFields(this.payload.config, globalConfig, true),
19
19
  locale,
20
- req,
21
20
  where
22
21
  });
23
22
  // 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 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","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,2BAA0B;AACpD,SAASC,UAAU,QAAQ,4BAA2B;AAEtD,OAAO,MAAMC,sBAA2C,eAAeA,oBAErE,EAAEC,QAAQC,UAAU,EAAEC,MAAM,EAAEC,GAAG,EAAEC,QAAQ,CAAC,CAAC,EAAE;IAE/C,MAAM,EAAEC,YAAY,EAAEC,KAAK,EAAE,GAAGT,UAAU;QAAEU,SAAS,IAAI;QAAEN;QAAYO,UAAU;IAAK;IAEtF,IAAIC,oBAAoB;IAExB,IAAIL,OAAO;QACT,MAAMM,cAAcf,wBAAwBS;QAC5CK,oBAAoBC,YAAYC,IAAI,CAAC,CAACC,OAASC,OAAOC,IAAI,CAACF,MAAMD,IAAI,CAAC,CAACI,MAAQA,QAAQ;IACzF;IAEA,MAAMC,QAAQ,MAAMpB,WAAW;QAC7BW,SAAS,IAAI;QACbU,QAAQvB,yBAAyB,IAAI,CAACwB,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,MAAMzB,WAAW,IAAI,EAAEK;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
+ {"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,2BAA0B;AACpD,SAASC,UAAU,QAAQ,4BAA2B;AAEtD,OAAO,MAAMC,sBAA2C,eAAeA,oBAErE,EAAEC,QAAQC,UAAU,EAAEC,MAAM,EAAEC,GAAG,EAAEC,QAAQ,CAAC,CAAC,EAAE;IAE/C,MAAM,EAAEC,YAAY,EAAEC,KAAK,EAAE,GAAGT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7C;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;AAiB5C,eAAO,MAAM,aAAa,EAAE,aAqF3B,CAAA"}
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,33 +1,13 @@
1
- import { buildVersionCollectionFields, flattenWhereToOperators, resolveBranchReadState, resolveBranchVersionHistoryQuery, rewriteBranchVersionParents } from 'payload';
2
- import { buildBranchVisibilityStages } from './queries/buildBranchVisibility.js';
1
+ import { buildVersionCollectionFields, flattenWhereToOperators } from 'payload';
3
2
  import { buildQuery } from './queries/buildQuery.js';
4
3
  import { getCollection } from './utilities/getEntity.js';
5
4
  import { getSession } from './utilities/getSession.js';
6
- export const countVersions = async function countVersions({ branch, collection: collectionSlug, locale, req, where = {} }) {
5
+ export const countVersions = async function countVersions({ collection: collectionSlug, locale, req, where = {} }) {
7
6
  const { collectionConfig, Model } = getCollection({
8
7
  adapter: this,
9
8
  collectionSlug,
10
9
  versions: true
11
10
  });
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
- }) : [];
31
11
  let hasNearConstraint = false;
32
12
  if (where) {
33
13
  const constraints = flattenWhereToOperators(where);
@@ -35,14 +15,12 @@ export const countVersions = async function countVersions({ branch, collection:
35
15
  }
36
16
  const query = await buildQuery({
37
17
  adapter: this,
38
- branch,
39
18
  fields: buildVersionCollectionFields(this.payload.config, collectionConfig, true),
40
19
  locale,
41
- req,
42
20
  where
43
21
  });
44
22
  // useEstimatedCount is faster, but not accurate, as it ignores any filters. It is thus set to true if there are no filters.
45
- const useEstimatedCount = !branchVisibility.length && (hasNearConstraint || !query || Object.keys(query).length === 0);
23
+ const useEstimatedCount = hasNearConstraint || !query || Object.keys(query).length === 0;
46
24
  const options = {
47
25
  session: await getSession(this, req)
48
26
  };
@@ -64,17 +42,7 @@ export const countVersions = async function countVersions({ branch, collection:
64
42
  };
65
43
  }
66
44
  let result;
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) {
45
+ if (useEstimatedCount) {
78
46
  result = await Model.estimatedDocumentCount({
79
47
  session: options.session
80
48
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/countVersions.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,EAAEC,gBAAgB,EAAEC,KAAK,EAAE,GAAGV,cAAc;QAChDW,SAAS,IAAI;QACbN;QACAO,UAAU;IACZ;IACA,MAAMC,kBAAkBlB,uBAAuB;QAAEQ;QAAQE;QAAgBE;IAAI;IAE7E,yEAAyE;IACzE,6DAA6D;IAC7DC,QAAQK,gBAAgBC,YAAY,GAC/BjB,4BAA4BW,UAAU,CAAC,IACvC,AAAC,MAAMZ,iCAAiC;QAAEO;QAAQE;QAAgBE;QAAKC;IAAM,MAAO,CAAC;IAC1F,MAAMO,mBAAmBF,gBAAgBC,YAAY,GACjDhB,4BAA4B;QAC1Ba,SAAS,IAAI;QACbR,QAAQU,gBAAgBV,MAAM;QAC9BE;QACAW,MAAM;IACR,KACA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AE,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
+ {"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;IAExB,IAAIL,OAAO;QACT,MAAMM,cAAcf,wBAAwBS;QAC5CK,oBAAoBC,YAAYC,IAAI,CAAC,CAACC,OAASC,OAAOC,IAAI,CAACF,MAAMD,IAAI,CAAC,CAACI,MAAQA,QAAQ;IACzF;IAEA,MAAMC,QAAQ,MAAMpB,WAAW;QAC7BW,SAAS,IAAI;QACbU,QAAQvB,6BAA6B,IAAI,CAACwB,OAAO,CAACC,MAAM,EAAEd,kBAAkB;QAC5EH;QACAE;IACF;IAEA,4HAA4H;IAC5H,MAAMgB,oBAAoBX,qBAAqB,CAACO,SAASH,OAAOC,IAAI,CAACE,OAAOK,MAAM,KAAK;IAEvF,MAAMC,UAAwB;QAC5BC,SAAS,MAAMzB,WAAW,IAAI,EAAEK;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":"createGlobalVersion.d.ts","sourceRoot":"","sources":["../src/createGlobalVersion.ts"],"names":[],"mappings":"AACA,OAAO,EAA4B,KAAK,mBAAmB,EAAE,MAAM,SAAS,CAAA;AAQ5E,eAAO,MAAM,mBAAmB,EAAE,mBA6FjC,CAAA"}
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,4 +1,3 @@
1
- import { MAIN_BRANCH, resolveBranch } from 'payload';
2
1
  import { buildVersionGlobalFields } from 'payload';
3
2
  import { getGlobal } from './utilities/getEntity.js';
4
3
  import { getSession } from './utilities/getSession.js';
@@ -9,9 +8,7 @@ export const createGlobalVersion = async function createGlobalVersion({ autosave
9
8
  globalSlug,
10
9
  versions: true
11
10
  });
12
- const versionBranch = req?.payload?.config?.branching?.branchableGlobals?.has(globalSlug) ? resolveBranch(req) : MAIN_BRANCH;
13
11
  const data = {
14
- _branch: versionBranch,
15
12
  autosave,
16
13
  createdAt,
17
14
  latest: true,
@@ -38,9 +35,6 @@ export const createGlobalVersion = async function createGlobalVersion({ autosave
38
35
  let [doc] = await Model.create([
39
36
  data
40
37
  ], options);
41
- // Scoped by `_branch`. Unlike collection versions, global versions have no
42
- // `parent` to separate streams by — every version of a global shares one — so
43
- // without this an unscoped clear would wipe main's latest flag from a branch.
44
38
  await Model.updateMany({
45
39
  $and: [
46
40
  {
@@ -52,22 +46,6 @@ export const createGlobalVersion = async function createGlobalVersion({ autosave
52
46
  latest: {
53
47
  $eq: true
54
48
  }
55
- },
56
- {
57
- $or: [
58
- {
59
- _branch: {
60
- $eq: versionBranch
61
- }
62
- },
63
- ...versionBranch === MAIN_BRANCH ? [
64
- {
65
- _branch: {
66
- $exists: false
67
- }
68
- }
69
- ] : []
70
- ]
71
49
  }
72
50
  ]
73
51
  }, {
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/createGlobalVersion.ts"],"sourcesContent":["import { MAIN_BRANCH, resolveBranch } from 'payload'\nimport { 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 versionBranch = req?.payload?.config?.branching?.branchableGlobals?.has(globalSlug)\n ? resolveBranch(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":["MAIN_BRANCH","resolveBranch","buildVersionGlobalFields","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":"AAAA,SAASA,WAAW,EAAEC,aAAa,QAAQ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B,KAAKvB;wBAAc;oBAAE;uBAC9BA,kBAAkBpB,cAAc;wBAAC;4BAAE2B,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
+ {"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 +1 @@
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
+ {"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,4 +1,4 @@
1
- import { buildVersionCollectionFields, resolveBranchVersionParent } from 'payload';
1
+ import { buildVersionCollectionFields } 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,25 +8,15 @@ 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
- });
17
11
  const data = {
18
12
  autosave,
19
13
  createdAt,
20
14
  latest: true,
21
- parent: branched.parent,
15
+ parent,
22
16
  publishedLocale,
23
17
  snapshot,
24
18
  updatedAt,
25
- version: versionData,
26
- ...branched.versionData._branch ? {
27
- _branch: branched.versionData._branch,
28
- _branchParent: branched.versionData._branchParent
29
- } : {}
19
+ version: versionData
30
20
  };
31
21
  if (!data.createdAt) {
32
22
  data.createdAt = new Date().toISOString();
@@ -46,9 +36,6 @@ export const createVersion = async function createVersion({ autosave, collection
46
36
  let [doc] = await Model.create([
47
37
  data
48
38
  ], 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.
52
39
  const parentQuery = {
53
40
  $or: [
54
41
  {
@@ -1 +1 @@
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,EAAE,GAAGf,cAAc;QAChDgB,SAAS,IAAI;QACbX;QACAY,UAAU;IACZ;IAEA,MAAMC,WAAW,MAAMnB,2BAA2B;QAChDM;QACAE;QACAE;QACAI,aAAaA;IACf;IAEA,MAAMM,OAAO;QACXf;QACAE;QACAc,QAAQ;QACRb,QAAQW,SAASX,MAAM;QACvBC;QACAG;QACAC;QACAS,SAASR;QACT,GAAIK,SAASL,WAAW,CAACS,OAAO,GAC5B;YAAEA,SAASJ,SAASL,WAAW,CAACS,OAAO;YAAEC,eAAeL,SAASL,WAAW,CAACU,aAAa;QAAC,IAC3F,CAAC,CAAC;IACR;IACA,IAAI,CAACJ,KAAKb,SAAS,EAAE;QACnBa,KAAKb,SAAS,GAAG,IAAIkB,OAAOC,WAAW;IACzC;IAEA,MAAMC,SAAS5B,6BAA6B,IAAI,CAAC6B,OAAO,CAACC,MAAM,EAAEd;IAEjEZ,UAAU;QACRc,SAAS,IAAI;QACbG;QACAO;QACAG,WAAW;IACb;IAEA,MAAMC,UAAU;QACdC,SAAS,MAAM9B,WAAW,IAAI,EAAEQ;QAChC,uDAAuD;QACvDuB,YAAY;IACd;IAEA,IAAI,CAACC,IAAI,GAAG,MAAMlB,MAAMmB,MAAM,CAAC;QAACf;KAAK,EAAEW;IAEvC,2EAA2E;IAC3E,4EAA4E;IAC5E,4DAA4D;IAC5D,MAAMK,cAAc;QAClBC,KAAK;YACH;gBACE7B,QAAQ;oBACN8B,KAAKlB,KAAKZ,MAAM;gBAClB;YACF;SACD;IACH;IAEA,MAAMQ,MAAMuB,UAAU,CACpB;QACEC,MAAM;YACJ;gBACEC,KAAK;oBACHC,KAAKR,IAAIO,GAAG;gBACd;YACF;YACAL;YACA;gBACEf,QAAQ;oBACNiB,KAAK;gBACP;YACF;YACA;gBACEzB,WAAW;oBACT8B,KAAK,IAAIlB,KAAKS,IAAIrB,SAAS;gBAC7B;YACF;SACD;IACH,GACA;QAAE+B,QAAQ;YAAEvB,QAAQ;QAAE;IAAE,GACxBU;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"}
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,cA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AMY;QACNP;QACAG,WAAW;IACb;IAEA,OAAOI;AACT,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,UAmBxB,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,UAkBxB,CAAA"}
@@ -10,7 +10,6 @@ export const deleteMany = async function deleteMany({ collection: collectionSlug
10
10
  adapter: this,
11
11
  collectionSlug,
12
12
  fields: collectionConfig.flattenedFields,
13
- req,
14
13
  where
15
14
  });
16
15
  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 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
+ {"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 +1 @@
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"}
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"}
package/dist/deleteOne.js CHANGED
@@ -1,36 +1,17 @@
1
- import { resolveBranchDelete } 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 { transform } from './utilities/transform.js';
7
- export const deleteOne = async function deleteOne({ branch, collection: collectionSlug, req, returning, select, where }) {
6
+ export const deleteOne = async function deleteOne({ collection: collectionSlug, req, returning, select, where }) {
8
7
  const { collectionConfig, Model } = getCollection({
9
8
  adapter: this,
10
9
  collectionSlug
11
10
  });
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
- }
28
11
  const query = await buildQuery({
29
12
  adapter: this,
30
- branch,
31
13
  collectionSlug,
32
14
  fields: collectionConfig.flattenedFields,
33
- req,
34
15
  where
35
16
  });
36
17
  const options = {
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/deleteOne.ts"],"sourcesContent":["import type { QueryOptions } from 'mongoose'\nimport type { DeleteOne } from 'payload'\n\nimport { resolveBranchDelete } 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 deleteOne: DeleteOne = async function deleteOne(\n this: MongooseAdapter,\n { branch, collection: collectionSlug, req, returning, select, where },\n) {\n const { collectionConfig, Model } = getCollection({ adapter: this, collectionSlug })\n\n const branchDelete = await resolveBranchDelete({ branch, collectionSlug, req, where })\n\n if (branchDelete.tombstoned) {\n return returning === false ? null : (branchDelete.doc as any)\n }\n\n if (branchDelete.deleteRowID !== undefined) {\n where = { id: { equals: branchDelete.deleteRowID } }\n }\n\n const query = await buildQuery({\n adapter: this,\n branch,\n collectionSlug,\n fields: collectionConfig.flattenedFields,\n req,\n where,\n })\n\n const options = {\n projection: buildProjectionFromSelect({\n adapter: this,\n fields: collectionConfig.flattenedFields,\n select,\n }),\n session: await getSession(this, req),\n } satisfies QueryOptions\n\n if (returning === false) {\n await Model.deleteOne(query, options)?.lean()\n return null\n }\n\n const doc = await Model.findOneAndDelete(query, options)?.lean()\n\n if (!doc) {\n return null\n }\n\n transform({\n adapter: this,\n data: doc,\n fields: collectionConfig.fields,\n operation: 'read',\n })\n\n return doc\n}\n"],"names":["resolveBranchDelete","buildQuery","buildProjectionFromSelect","getCollection","getSession","transform","deleteOne","branch","collection","collectionSlug","req","returning","select","where","collectionConfig","Model","adapter","branchDelete","tombstoned","doc","deleteRowID","undefined","id","equals","query","fields","fl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,SAAS,IAAI;QACbgB,MAAMb;QACNM,QAAQX,iBAAiBW,MAAM;QAC/BQ,WAAW;IACb;IAEA,OAAOd;AACT,EAAC"}
1
+ {"version":3,"sources":["../src/deleteOne.ts"],"sourcesContent":["import type { QueryOptions } from 'mongoose'\nimport type { DeleteOne } 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 deleteOne: DeleteOne = async function deleteOne(\n this: MongooseAdapter,\n { collection: collectionSlug, req, returning, select, 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 = {\n projection: buildProjectionFromSelect({\n adapter: this,\n fields: collectionConfig.flattenedFields,\n select,\n }),\n session: await getSession(this, req),\n } satisfies QueryOptions\n\n if (returning === false) {\n await Model.deleteOne(query, options)?.lean()\n return null\n }\n\n const doc = await Model.findOneAndDelete(query, options)?.lean()\n\n if (!doc) {\n return null\n }\n\n transform({\n adapter: this,\n data: doc,\n fields: collectionConfig.fields,\n operation: 'read',\n })\n\n return doc\n}\n"],"names":["buildQuery","buildProjectionFromSelect","getCollection","getSession","transform","deleteOne","collection","collectionSlug","req","returning","select","where","collectionConfig","Model","adapter","query","fields","flattenedFields","options","projection","session","lean","doc","findOneAndDelete","data","operation"],"mappings":"AAKA,SAASA,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,YAAuB,eAAeA,UAEjD,EAAEC,YAAYC,cAAc,EAAEC,GAAG,EAAEC,SAAS,EAAEC,MAAM,EAAEC,KAAK,EAAE;IAE7D,MAAM,EAAEC,gBAAgB,EAAEC,KAAK,EAAE,GAAGX,cAAc;QAAEY,SAAS,IAAI;QAAEP;IAAe;IAElF,MAAMQ,QAAQ,MAAMf,WAAW;QAC7Bc,SAAS,IAAI;QACbP;QACAS,QAAQJ,iBAAiBK,eAAe;QACxCN;IACF;IAEA,MAAMO,UAAU;QACdC,YAAYlB,0BAA0B;YACpCa,SAAS,IAAI;YACbE,QAAQJ,iBAAiBK,eAAe;YACxCP;QACF;QACAU,SAAS,MAAMjB,WAAW,IAAI,EAAEK;IAClC;IAEA,IAAIC,cAAc,OAAO;QACvB,MAAMI,MAAMR,SAAS,CAACU,OAAOG,UAAUG;QACvC,OAAO;IACT;IAEA,MAAMC,MAAM,MAAMT,MAAMU,gBAAgB,CAACR,OAAOG,UAAUG;IAE1D,IAAI,CAACC,KAAK;QACR,OAAO;IACT;IAEAlB,UAAU;QACRU,SAAS,IAAI;QACbU,MAAMF;QACNN,QAAQJ,iBAAiBI,MAAM;QAC/BS,WAAW;IACb;IAEA,OAAOH;AACT,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"deleteVersions.d.ts","sourceRoot":"","sources":["../src/deleteVersions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAkB,MAAM,SAAS,CAAA;AAW7D,eAAO,MAAM,cAAc,EAAE,cAsC5B,CAAA"}
1
+ {"version":3,"file":"deleteVersions.d.ts","sourceRoot":"","sources":["../src/deleteVersions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAkB,MAAM,SAAS,CAAA;AAW7D,eAAO,MAAM,cAAc,EAAE,cAqC5B,CAAA"}
@@ -28,7 +28,6 @@ export const deleteVersions = async function deleteVersions({ collection: collec
28
28
  adapter: this,
29
29
  fields,
30
30
  locale,
31
- req,
32
31
  where
33
32
  });
34
33
  const session = await getSession(this, req);
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/deleteVersions.ts"],"sourcesContent":["import type { DeleteVersions, FlattenedField } from 'payload'\n\nimport { APIError, buildVersionCollectionFields, buildVersionGlobalFields } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\nimport type { CollectionModel } from './types.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { getCollection, getGlobal } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\n\nexport const deleteVersions: DeleteVersions = async function deleteVersions(\n this: MongooseAdapter,\n { collection: collectionSlug, globalSlug, locale, req, where },\n) {\n let fields: FlattenedField[]\n let VersionsModel: CollectionModel\n\n if (globalSlug) {\n const { globalConfig, Model } = getGlobal({\n adapter: this,\n globalSlug,\n versions: true,\n })\n fields = buildVersionGlobalFields(this.payload.config, globalConfig, true)\n VersionsModel = Model\n } else if (collectionSlug) {\n const { collectionConfig, Model } = getCollection({\n adapter: this,\n collectionSlug,\n versions: true,\n })\n fields = buildVersionCollectionFields(this.payload.config, collectionConfig, true)\n VersionsModel = Model\n } else {\n throw new APIError('Either collection or globalSlug must be passed.')\n }\n\n const query = await buildQuery({\n adapter: this,\n fields,\n locale,\n req,\n where,\n })\n\n const session = await getSession(this, req)\n\n await VersionsModel.deleteMany(query, { session })\n}\n"],"names":["APIError","buildVersionCollectionFields","buildVersionGlobalFields","buildQuery","getCollection","getGlobal","getSession","deleteVersions","collection","collectionSlug","globalSlug","locale","req","where","fields","VersionsModel","globalConfig","Model","adapter","versions","payload","config","collectionConfig","query","session","deleteMany"],"mappings":"AAEA,SAASA,QAAQ,EAAEC,4BAA4B,EAAEC,wBAAwB,QAAQ,UAAS;AAK1F,SAASC,UAAU,QAAQ,0BAAyB;AACpD,SAASC,aAAa,EAAEC,SAAS,QAAQ,2BAA0B;AACnE,SAASC,UAAU,QAAQ,4BAA2B;AAEtD,OAAO,MAAMC,iBAAiC,eAAeA,eAE3D,EAAEC,YAAYC,cAAc,EAAEC,UAAU,EAAEC,MAAM,EAAEC,GAAG,EAAEC,KAAK,EAAE;IAE9D,IAAIC;IACJ,IAAIC;IAEJ,IAAIL,YAAY;QACd,MAAM,EAAEM,YAAY,EAAEC,KAAK,EAAE,GAAGZ,UAAU;YACxCa,SAAS,IAAI;YACbR;YACAS,UAAU;QACZ;QACAL,SAASZ,yBAAyB,IAAI,CAACkB,OAAO,CAACC,MAAM,EAAEL,cAAc;QACrED,gBAAgBE;IAClB,OAAO,IAAIR,gBAAgB;QACzB,MAAM,EAAEa,gBAAgB,EAAEL,KAAK,EAAE,GAAGb,cAAc;YAChDc,SAAS,IAAI;YACbT;YACAU,UAAU;QACZ;QACAL,SAASb,6BAA6B,IAAI,CAACmB,OAAO,CAACC,MAAM,EAAEC,kBAAkB;QAC7EP,gBAAgBE;IAClB,OAAO;QACL,MAAM,IAAIjB,SAAS;IACrB;IAEA,MAAMuB,QAAQ,MAAMpB,WAAW;QAC7Be,SAAS,IAAI;QACbJ;QACAH;QACAC;QACAC;IACF;IAEA,MAAMW,UAAU,MAAMlB,WAAW,IAAI,EAAEM;IAEvC,MAAMG,cAAcU,UAAU,CAACF,OAAO;QAAEC;IAAQ;AAClD,EAAC"}
1
+ {"version":3,"sources":["../src/deleteVersions.ts"],"sourcesContent":["import type { DeleteVersions, FlattenedField } from 'payload'\n\nimport { APIError, buildVersionCollectionFields, buildVersionGlobalFields } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\nimport type { CollectionModel } from './types.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { getCollection, getGlobal } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\n\nexport const deleteVersions: DeleteVersions = async function deleteVersions(\n this: MongooseAdapter,\n { collection: collectionSlug, globalSlug, locale, req, where },\n) {\n let fields: FlattenedField[]\n let VersionsModel: CollectionModel\n\n if (globalSlug) {\n const { globalConfig, Model } = getGlobal({\n adapter: this,\n globalSlug,\n versions: true,\n })\n fields = buildVersionGlobalFields(this.payload.config, globalConfig, true)\n VersionsModel = Model\n } else if (collectionSlug) {\n const { collectionConfig, Model } = getCollection({\n adapter: this,\n collectionSlug,\n versions: true,\n })\n fields = buildVersionCollectionFields(this.payload.config, collectionConfig, true)\n VersionsModel = Model\n } else {\n throw new APIError('Either collection or globalSlug must be passed.')\n }\n\n const query = await buildQuery({\n adapter: this,\n fields,\n locale,\n where,\n })\n\n const session = await getSession(this, req)\n\n await VersionsModel.deleteMany(query, { session })\n}\n"],"names":["APIError","buildVersionCollectionFields","buildVersionGlobalFields","buildQuery","getCollection","getGlobal","getSession","deleteVersions","collection","collectionSlug","globalSlug","locale","req","where","fields","VersionsModel","globalConfig","Model","adapter","versions","payload","config","collectionConfig","query","session","deleteMany"],"mappings":"AAEA,SAASA,QAAQ,EAAEC,4BAA4B,EAAEC,wBAAwB,QAAQ,UAAS;AAK1F,SAASC,UAAU,QAAQ,0BAAyB;AACpD,SAASC,aAAa,EAAEC,SAAS,QAAQ,2BAA0B;AACnE,SAASC,UAAU,QAAQ,4BAA2B;AAEtD,OAAO,MAAMC,iBAAiC,eAAeA,eAE3D,EAAEC,YAAYC,cAAc,EAAEC,UAAU,EAAEC,MAAM,EAAEC,GAAG,EAAEC,KAAK,EAAE;IAE9D,IAAIC;IACJ,IAAIC;IAEJ,IAAIL,YAAY;QACd,MAAM,EAAEM,YAAY,EAAEC,KAAK,EAAE,GAAGZ,UAAU;YACxCa,SAAS,IAAI;YACbR;YACAS,UAAU;QACZ;QACAL,SAASZ,yBAAyB,IAAI,CAACkB,OAAO,CAACC,MAAM,EAAEL,cAAc;QACrED,gBAAgBE;IAClB,OAAO,IAAIR,gBAAgB;QACzB,MAAM,EAAEa,gBAAgB,EAAEL,KAAK,EAAE,GAAGb,cAAc;YAChDc,SAAS,IAAI;YACbT;YACAU,UAAU;QACZ;QACAL,SAASb,6BAA6B,IAAI,CAACmB,OAAO,CAACC,MAAM,EAAEC,kBAAkB;QAC7EP,gBAAgBE;IAClB,OAAO;QACL,MAAM,IAAIjB,SAAS;IACrB;IAEA,MAAMuB,QAAQ,MAAMpB,WAAW;QAC7Be,SAAS,IAAI;QACbJ;QACAH;QACAE;IACF;IAEA,MAAMW,UAAU,MAAMlB,WAAW,IAAI,EAAEM;IAEvC,MAAMG,cAAcU,UAAU,CAACF,OAAO;QAAEC;IAAQ;AAClD,EAAC"}
@@ -1,4 +1,3 @@
1
- export { migrateBranching } from '../predefinedMigrations/migrateBranching.js';
2
1
  export { localizeStatus, migrateLocalizeStatus, } from '../predefinedMigrations/migrateLocalizeStatus.js';
3
2
  export { migrateRelationshipsV2_V3 } from '../predefinedMigrations/migrateRelationshipsV2_V3.js';
4
3
  export { migrateSizesToVariants } from '../predefinedMigrations/migrateSizesToVariants.js';
@@ -1 +1 @@
1
- {"version":3,"file":"migration-utils.d.ts","sourceRoot":"","sources":["../../src/exports/migration-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,6CAA6C,CAAA;AAC9E,OAAO,EACL,cAAc,EACd,qBAAqB,GACtB,MAAM,kDAAkD,CAAA;AACzD,OAAO,EAAE,yBAAyB,EAAE,MAAM,sDAAsD,CAAA;AAChG,OAAO,EAAE,sBAAsB,EAAE,MAAM,mDAAmD,CAAA;AAC1F,OAAO,EAAE,oBAAoB,EAAE,MAAM,iDAAiD,CAAA"}
1
+ {"version":3,"file":"migration-utils.d.ts","sourceRoot":"","sources":["../../src/exports/migration-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,qBAAqB,GACtB,MAAM,kDAAkD,CAAA;AACzD,OAAO,EAAE,yBAAyB,EAAE,MAAM,sDAAsD,CAAA;AAChG,OAAO,EAAE,sBAAsB,EAAE,MAAM,mDAAmD,CAAA;AAC1F,OAAO,EAAE,oBAAoB,EAAE,MAAM,iDAAiD,CAAA"}
@@ -1,4 +1,3 @@
1
- export { migrateBranching } from '../predefinedMigrations/migrateBranching.js';
2
1
  export { localizeStatus, migrateLocalizeStatus } from '../predefinedMigrations/migrateLocalizeStatus.js';
3
2
  export { migrateRelationshipsV2_V3 } from '../predefinedMigrations/migrateRelationshipsV2_V3.js';
4
3
  export { migrateSizesToVariants } from '../predefinedMigrations/migrateSizesToVariants.js';