@payloadcms/db-mongodb 3.26.0-canary.bbb3083 → 3.27.0-canary.ecc3f49

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 (164) hide show
  1. package/dist/connect.d.ts.map +1 -1
  2. package/dist/connect.js +5 -1
  3. package/dist/connect.js.map +1 -1
  4. package/dist/count.d.ts.map +1 -1
  5. package/dist/count.js +8 -4
  6. package/dist/count.js.map +1 -1
  7. package/dist/countGlobalVersions.d.ts.map +1 -1
  8. package/dist/countGlobalVersions.js +8 -3
  9. package/dist/countGlobalVersions.js.map +1 -1
  10. package/dist/countVersions.d.ts.map +1 -1
  11. package/dist/countVersions.js +8 -3
  12. package/dist/countVersions.js.map +1 -1
  13. package/dist/create.d.ts.map +1 -1
  14. package/dist/create.js +13 -6
  15. package/dist/create.js.map +1 -1
  16. package/dist/createGlobal.d.ts +1 -1
  17. package/dist/createGlobal.d.ts.map +1 -1
  18. package/dist/createGlobal.js +12 -5
  19. package/dist/createGlobal.js.map +1 -1
  20. package/dist/createGlobalVersion.d.ts.map +1 -1
  21. package/dist/createGlobalVersion.js +13 -5
  22. package/dist/createGlobalVersion.js.map +1 -1
  23. package/dist/createMigration.d.ts.map +1 -1
  24. package/dist/createMigration.js.map +1 -1
  25. package/dist/createVersion.d.ts.map +1 -1
  26. package/dist/createVersion.js +13 -5
  27. package/dist/createVersion.js.map +1 -1
  28. package/dist/deleteMany.d.ts +1 -1
  29. package/dist/deleteMany.d.ts.map +1 -1
  30. package/dist/deleteMany.js +8 -4
  31. package/dist/deleteMany.js.map +1 -1
  32. package/dist/deleteOne.d.ts.map +1 -1
  33. package/dist/deleteOne.js +14 -6
  34. package/dist/deleteOne.js.map +1 -1
  35. package/dist/deleteVersions.d.ts.map +1 -1
  36. package/dist/deleteVersions.js +9 -4
  37. package/dist/deleteVersions.js.map +1 -1
  38. package/dist/find.d.ts.map +1 -1
  39. package/dist/find.js +25 -8
  40. package/dist/find.js.map +1 -1
  41. package/dist/findGlobal.d.ts.map +1 -1
  42. package/dist/findGlobal.js +8 -5
  43. package/dist/findGlobal.js.map +1 -1
  44. package/dist/findGlobalVersions.d.ts.map +1 -1
  45. package/dist/findGlobalVersions.js +8 -4
  46. package/dist/findGlobalVersions.js.map +1 -1
  47. package/dist/findOne.d.ts +1 -1
  48. package/dist/findOne.d.ts.map +1 -1
  49. package/dist/findOne.js +18 -8
  50. package/dist/findOne.js.map +1 -1
  51. package/dist/findVersions.d.ts.map +1 -1
  52. package/dist/findVersions.js +8 -4
  53. package/dist/findVersions.js.map +1 -1
  54. package/dist/index.d.ts +6 -7
  55. package/dist/index.d.ts.map +1 -1
  56. package/dist/index.js +6 -1
  57. package/dist/index.js.map +1 -1
  58. package/dist/init.d.ts.map +1 -1
  59. package/dist/init.js +1 -5
  60. package/dist/init.js.map +1 -1
  61. package/dist/migrateFresh.d.ts.map +1 -1
  62. package/dist/migrateFresh.js.map +1 -1
  63. package/dist/models/buildCollectionSchema.d.ts.map +1 -1
  64. package/dist/models/buildCollectionSchema.js +0 -4
  65. package/dist/models/buildCollectionSchema.js.map +1 -1
  66. package/dist/models/buildSchema.d.ts.map +1 -1
  67. package/dist/models/buildSchema.js +545 -515
  68. package/dist/models/buildSchema.js.map +1 -1
  69. package/dist/predefinedMigrations/migrateRelationshipsV2_V3.d.ts.map +1 -1
  70. package/dist/predefinedMigrations/migrateRelationshipsV2_V3.js +21 -8
  71. package/dist/predefinedMigrations/migrateRelationshipsV2_V3.js.map +1 -1
  72. package/dist/predefinedMigrations/migrateVersionsV1_V2.d.ts.map +1 -1
  73. package/dist/predefinedMigrations/migrateVersionsV1_V2.js +20 -8
  74. package/dist/predefinedMigrations/migrateVersionsV1_V2.js.map +1 -1
  75. package/dist/queries/buildSearchParams.d.ts +1 -1
  76. package/dist/queries/buildSearchParams.d.ts.map +1 -1
  77. package/dist/queries/buildSearchParams.js +42 -29
  78. package/dist/queries/buildSearchParams.js.map +1 -1
  79. package/dist/queries/buildSortParam.d.ts +2 -3
  80. package/dist/queries/buildSortParam.d.ts.map +1 -1
  81. package/dist/queries/buildSortParam.js +1 -1
  82. package/dist/queries/buildSortParam.js.map +1 -1
  83. package/dist/queries/getBuildQueryPlugin.d.ts.map +1 -1
  84. package/dist/queries/getBuildQueryPlugin.js +15 -8
  85. package/dist/queries/getBuildQueryPlugin.js.map +1 -1
  86. package/dist/queries/getLocalizedSortProperty.d.ts +1 -1
  87. package/dist/queries/getLocalizedSortProperty.d.ts.map +1 -1
  88. package/dist/queries/getLocalizedSortProperty.js +11 -6
  89. package/dist/queries/getLocalizedSortProperty.js.map +1 -1
  90. package/dist/queries/getLocalizedSortProperty.spec.js +8 -0
  91. package/dist/queries/getLocalizedSortProperty.spec.js.map +1 -1
  92. package/dist/queries/operatorMap.d.ts +1 -0
  93. package/dist/queries/operatorMap.d.ts.map +1 -1
  94. package/dist/queries/operatorMap.js.map +1 -1
  95. package/dist/queries/parseParams.d.ts +1 -1
  96. package/dist/queries/parseParams.d.ts.map +1 -1
  97. package/dist/queries/parseParams.js +3 -3
  98. package/dist/queries/parseParams.js.map +1 -1
  99. package/dist/queries/sanitizeQueryValue.d.ts +1 -1
  100. package/dist/queries/sanitizeQueryValue.d.ts.map +1 -1
  101. package/dist/queries/sanitizeQueryValue.js +30 -26
  102. package/dist/queries/sanitizeQueryValue.js.map +1 -1
  103. package/dist/queryDrafts.d.ts.map +1 -1
  104. package/dist/queryDrafts.js +26 -8
  105. package/dist/queryDrafts.js.map +1 -1
  106. package/dist/transactions/beginTransaction.d.ts.map +1 -1
  107. package/dist/transactions/beginTransaction.js +4 -2
  108. package/dist/transactions/beginTransaction.js.map +1 -1
  109. package/dist/transactions/commitTransaction.d.ts.map +1 -1
  110. package/dist/transactions/commitTransaction.js +1 -1
  111. package/dist/transactions/commitTransaction.js.map +1 -1
  112. package/dist/transactions/rollbackTransaction.d.ts.map +1 -1
  113. package/dist/transactions/rollbackTransaction.js +3 -3
  114. package/dist/transactions/rollbackTransaction.js.map +1 -1
  115. package/dist/types.d.ts +2 -2
  116. package/dist/types.d.ts.map +1 -1
  117. package/dist/types.js.map +1 -1
  118. package/dist/updateGlobal.d.ts.map +1 -1
  119. package/dist/updateGlobal.js +17 -7
  120. package/dist/updateGlobal.js.map +1 -1
  121. package/dist/updateGlobalVersion.d.ts +1 -1
  122. package/dist/updateGlobalVersion.d.ts.map +1 -1
  123. package/dist/updateGlobalVersion.js +14 -6
  124. package/dist/updateGlobalVersion.js.map +1 -1
  125. package/dist/updateMany.d.ts +3 -0
  126. package/dist/updateMany.d.ts.map +1 -0
  127. package/dist/updateMany.js +75 -0
  128. package/dist/updateMany.js.map +1 -0
  129. package/dist/updateOne.d.ts.map +1 -1
  130. package/dist/updateOne.js +17 -8
  131. package/dist/updateOne.js.map +1 -1
  132. package/dist/updateVersion.d.ts.map +1 -1
  133. package/dist/updateVersion.js +14 -5
  134. package/dist/updateVersion.js.map +1 -1
  135. package/dist/upsert.d.ts.map +1 -1
  136. package/dist/upsert.js +2 -1
  137. package/dist/upsert.js.map +1 -1
  138. package/dist/utilities/aggregatePaginate.d.ts +19 -0
  139. package/dist/utilities/aggregatePaginate.d.ts.map +1 -0
  140. package/dist/utilities/aggregatePaginate.js +78 -0
  141. package/dist/utilities/aggregatePaginate.js.map +1 -0
  142. package/dist/utilities/buildJoinAggregation.d.ts +5 -6
  143. package/dist/utilities/buildJoinAggregation.d.ts.map +1 -1
  144. package/dist/utilities/buildJoinAggregation.js +39 -36
  145. package/dist/utilities/buildJoinAggregation.js.map +1 -1
  146. package/dist/utilities/buildProjectionFromSelect.d.ts.map +1 -1
  147. package/dist/utilities/buildProjectionFromSelect.js +8 -4
  148. package/dist/utilities/buildProjectionFromSelect.js.map +1 -1
  149. package/dist/utilities/getDBName.d.ts +1 -1
  150. package/dist/utilities/getDBName.d.ts.map +1 -1
  151. package/dist/utilities/getDBName.js +6 -2
  152. package/dist/utilities/getDBName.js.map +1 -1
  153. package/dist/utilities/getEntity.d.ts +33 -0
  154. package/dist/utilities/getEntity.d.ts.map +1 -0
  155. package/dist/utilities/getEntity.js +49 -0
  156. package/dist/utilities/getEntity.js.map +1 -0
  157. package/dist/utilities/handleError.d.ts +1 -1
  158. package/dist/utilities/handleError.d.ts.map +1 -1
  159. package/dist/utilities/handleError.js +3 -2
  160. package/dist/utilities/handleError.js.map +1 -1
  161. package/dist/utilities/transform.d.ts.map +1 -1
  162. package/dist/utilities/transform.js +10 -9
  163. package/dist/utilities/transform.js.map +1 -1
  164. package/package.json +6 -5
@@ -1 +1 @@
1
- {"version":3,"file":"connect.d.ts","sourceRoot":"","sources":["../src/connect.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAOtC,eAAO,MAAM,OAAO,EAAE,OAsErB,CAAA"}
1
+ {"version":3,"file":"connect.d.ts","sourceRoot":"","sources":["../src/connect.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAOtC,eAAO,MAAM,OAAO,EAAE,OA4ErB,CAAA"}
package/dist/connect.js CHANGED
@@ -49,9 +49,13 @@ export const connect = async function connect(options = {
49
49
  });
50
50
  }
51
51
  } catch (err) {
52
+ let msg = `Error: cannot connect to MongoDB.`;
53
+ if (typeof err === 'object' && err && 'message' in err && typeof err.message === 'string') {
54
+ msg = `${msg} Details: ${err.message}`;
55
+ }
52
56
  this.payload.logger.error({
53
57
  err,
54
- msg: `Error: cannot connect to MongoDB. Details: ${err.message}`
58
+ msg
55
59
  });
56
60
  process.exit(1);
57
61
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/connect.ts"],"sourcesContent":["import type { ConnectOptions } from 'mongoose'\nimport type { Connect } 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: { useFacet: undefined } & ConnectOptions = {\n autoIndex: true,\n ...this.connectOptions,\n useFacet: undefined,\n }\n\n if (hotReload) {\n connectionOptions.autoIndex = false\n }\n\n try {\n this.connection = (await mongoose.connect(urlToConnect, connectionOptions)).connection\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 await new Promise((resolve) => setTimeout(resolve, 2000))\n }\n\n const client = this.connection.getClient()\n\n if (!client.options.replicaSet) {\n this.transactionOptions = false\n this.beginTransaction = defaultBeginTransaction()\n }\n\n if (!this.mongoMemoryServer && !hotReload) {\n if (process.env.PAYLOAD_DROP_DATABASE === 'true') {\n this.payload.logger.info('---- DROPPING DATABASE ----')\n await mongoose.connection.dropDatabase()\n this.payload.logger.info('---- DROPPED DATABASE ----')\n }\n }\n\n if (this.ensureIndexes) {\n await Promise.all(\n this.payload.config.collections.map(async (coll) => {\n await this.collections[coll.slug]?.ensureIndexes()\n }),\n )\n }\n\n if (process.env.NODE_ENV === 'production' && this.prodMigrations) {\n await this.migrate({ migrations: this.prodMigrations })\n }\n } catch (err) {\n this.payload.logger.error({\n err,\n msg: `Error: cannot connect to MongoDB. Details: ${err.message}`,\n })\n process.exit(1)\n }\n}\n"],"names":["mongoose","defaultBeginTransaction","connect","options","hotReload","url","Error","urlToConnect","connectionOptions","autoIndex","connectOptions","useFacet","undefined","connection","mongoMemoryServer","Promise","resolve","setTimeout","client","getClient","replicaSet","transactionOptions","beginTransaction","process","env","PAYLOAD_DROP_DATABASE","payload","logger","info","dropDatabase","ensureIndexes","all","config","collections","map","coll","slug","NODE_ENV","prodMigrations","migrate","migrations","err","error","msg","message","exit"],"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,oBAA8D;QAClEC,WAAW;QACX,GAAG,IAAI,CAACC,cAAc;QACtBC,UAAUC;IACZ;IAEA,IAAIR,WAAW;QACbI,kBAAkBC,SAAS,GAAG;IAChC;IAEA,IAAI;QACF,IAAI,CAACI,UAAU,GAAG,AAAC,CAAA,MAAMb,SAASE,OAAO,CAACK,cAAcC,kBAAiB,EAAGK,UAAU;QAEtF,8DAA8D;QAC9D,gEAAgE;QAChE,IAAI,IAAI,CAACC,iBAAiB,EAAE;YAC1B,MAAM,IAAIC,QAAQ,CAACC,UAAYC,WAAWD,SAAS;QACrD;QAEA,MAAME,SAAS,IAAI,CAACL,UAAU,CAACM,SAAS;QAExC,IAAI,CAACD,OAAOf,OAAO,CAACiB,UAAU,EAAE;YAC9B,IAAI,CAACC,kBAAkB,GAAG;YAC1B,IAAI,CAACC,gBAAgB,GAAGrB;QAC1B;QAEA,IAAI,CAAC,IAAI,CAACa,iBAAiB,IAAI,CAACV,WAAW;YACzC,IAAImB,QAAQC,GAAG,CAACC,qBAAqB,KAAK,QAAQ;gBAChD,IAAI,CAACC,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC;gBACzB,MAAM5B,SAASa,UAAU,CAACgB,YAAY;gBACtC,IAAI,CAACH,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC;YAC3B;QACF;QAEA,IAAI,IAAI,CAACE,aAAa,EAAE;YACtB,MAAMf,QAAQgB,GAAG,CACf,IAAI,CAACL,OAAO,CAACM,MAAM,CAACC,WAAW,CAACC,GAAG,CAAC,OAAOC;gBACzC,MAAM,IAAI,CAACF,WAAW,CAACE,KAAKC,IAAI,CAAC,EAAEN;YACrC;QAEJ;QAEA,IAAIP,QAAQC,GAAG,CAACa,QAAQ,KAAK,gBAAgB,IAAI,CAACC,cAAc,EAAE;YAChE,MAAM,IAAI,CAACC,OAAO,CAAC;gBAAEC,YAAY,IAAI,CAACF,cAAc;YAAC;QACvD;IACF,EAAE,OAAOG,KAAK;QACZ,IAAI,CAACf,OAAO,CAACC,MAAM,CAACe,KAAK,CAAC;YACxBD;YACAE,KAAK,CAAC,2CAA2C,EAAEF,IAAIG,OAAO,EAAE;QAClE;QACArB,QAAQsB,IAAI,CAAC;IACf;AACF,EAAC"}
1
+ {"version":3,"sources":["../src/connect.ts"],"sourcesContent":["import type { ConnectOptions } from 'mongoose'\nimport type { Connect } 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: { useFacet: undefined } & ConnectOptions = {\n autoIndex: true,\n ...this.connectOptions,\n useFacet: undefined,\n }\n\n if (hotReload) {\n connectionOptions.autoIndex = false\n }\n\n try {\n this.connection = (await mongoose.connect(urlToConnect, connectionOptions)).connection\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 await new Promise((resolve) => setTimeout(resolve, 2000))\n }\n\n const client = this.connection.getClient()\n\n if (!client.options.replicaSet) {\n this.transactionOptions = false\n this.beginTransaction = defaultBeginTransaction()\n }\n\n if (!this.mongoMemoryServer && !hotReload) {\n if (process.env.PAYLOAD_DROP_DATABASE === 'true') {\n this.payload.logger.info('---- DROPPING DATABASE ----')\n await mongoose.connection.dropDatabase()\n this.payload.logger.info('---- DROPPED DATABASE ----')\n }\n }\n\n if (this.ensureIndexes) {\n await Promise.all(\n this.payload.config.collections.map(async (coll) => {\n await this.collections[coll.slug]?.ensureIndexes()\n }),\n )\n }\n\n if (process.env.NODE_ENV === 'production' && this.prodMigrations) {\n await this.migrate({ migrations: this.prodMigrations })\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 process.exit(1)\n }\n}\n"],"names":["mongoose","defaultBeginTransaction","connect","options","hotReload","url","Error","urlToConnect","connectionOptions","autoIndex","connectOptions","useFacet","undefined","connection","mongoMemoryServer","Promise","resolve","setTimeout","client","getClient","replicaSet","transactionOptions","beginTransaction","process","env","PAYLOAD_DROP_DATABASE","payload","logger","info","dropDatabase","ensureIndexes","all","config","collections","map","coll","slug","NODE_ENV","prodMigrations","migrate","migrations","err","msg","message","error","exit"],"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,oBAA8D;QAClEC,WAAW;QACX,GAAG,IAAI,CAACC,cAAc;QACtBC,UAAUC;IACZ;IAEA,IAAIR,WAAW;QACbI,kBAAkBC,SAAS,GAAG;IAChC;IAEA,IAAI;QACF,IAAI,CAACI,UAAU,GAAG,AAAC,CAAA,MAAMb,SAASE,OAAO,CAACK,cAAcC,kBAAiB,EAAGK,UAAU;QAEtF,8DAA8D;QAC9D,gEAAgE;QAChE,IAAI,IAAI,CAACC,iBAAiB,EAAE;YAC1B,MAAM,IAAIC,QAAQ,CAACC,UAAYC,WAAWD,SAAS;QACrD;QAEA,MAAME,SAAS,IAAI,CAACL,UAAU,CAACM,SAAS;QAExC,IAAI,CAACD,OAAOf,OAAO,CAACiB,UAAU,EAAE;YAC9B,IAAI,CAACC,kBAAkB,GAAG;YAC1B,IAAI,CAACC,gBAAgB,GAAGrB;QAC1B;QAEA,IAAI,CAAC,IAAI,CAACa,iBAAiB,IAAI,CAACV,WAAW;YACzC,IAAImB,QAAQC,GAAG,CAACC,qBAAqB,KAAK,QAAQ;gBAChD,IAAI,CAACC,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC;gBACzB,MAAM5B,SAASa,UAAU,CAACgB,YAAY;gBACtC,IAAI,CAACH,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC;YAC3B;QACF;QAEA,IAAI,IAAI,CAACE,aAAa,EAAE;YACtB,MAAMf,QAAQgB,GAAG,CACf,IAAI,CAACL,OAAO,CAACM,MAAM,CAACC,WAAW,CAACC,GAAG,CAAC,OAAOC;gBACzC,MAAM,IAAI,CAACF,WAAW,CAACE,KAAKC,IAAI,CAAC,EAAEN;YACrC;QAEJ;QAEA,IAAIP,QAAQC,GAAG,CAACa,QAAQ,KAAK,gBAAgB,IAAI,CAACC,cAAc,EAAE;YAChE,MAAM,IAAI,CAACC,OAAO,CAAC;gBAAEC,YAAY,IAAI,CAACF,cAAc;YAAC;QACvD;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,CAACjB,OAAO,CAACC,MAAM,CAACiB,KAAK,CAAC;YACxBH;YACAC;QACF;QACAnB,QAAQsB,IAAI,CAAC;IACf;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;AASpC,eAAO,MAAM,KAAK,EAAE,KA+CnB,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,KAgDnB,CAAA"}
package/dist/count.js CHANGED
@@ -1,8 +1,12 @@
1
1
  import { flattenWhereToOperators } from 'payload';
2
2
  import { buildQuery } from './queries/buildQuery.js';
3
+ import { getCollection } from './utilities/getEntity.js';
3
4
  import { getSession } from './utilities/getSession.js';
4
- export const count = async function count({ collection, locale, req, where }) {
5
- const Model = this.collections[collection];
5
+ export const count = async function count({ collection: collectionSlug, locale, req, where = {} }) {
6
+ const { collectionConfig, Model } = getCollection({
7
+ adapter: this,
8
+ collectionSlug
9
+ });
6
10
  const options = {
7
11
  session: await getSession(this, req)
8
12
  };
@@ -13,8 +17,8 @@ export const count = async function count({ collection, locale, req, where }) {
13
17
  }
14
18
  const query = await buildQuery({
15
19
  adapter: this,
16
- collectionSlug: collection,
17
- fields: this.payload.collections[collection].config.flattenedFields,
20
+ collectionSlug,
21
+ fields: collectionConfig.flattenedFields,
18
22
  locale,
19
23
  where
20
24
  });
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 { getSession } from './utilities/getSession.js'\n\nexport const count: Count = async function count(\n this: MongooseAdapter,\n { collection, locale, req, where },\n) {\n const Model = this.collections[collection]\n const options: CountOptions = {\n session: await getSession(this, req),\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 collectionSlug: collection,\n fields: this.payload.collections[collection].config.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 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","getSession","count","collection","locale","req","where","Model","collections","options","session","hasNearConstraint","constraints","some","prop","Object","keys","key","query","adapter","collectionSlug","fields","payload","config","flattenedFields","useEstimatedCount","length","disableIndexHints","hint","_id","result","estimatedDocumentCount","countDocuments","totalDocs"],"mappings":"AAGA,SAASA,uBAAuB,QAAQ,UAAS;AAIjD,SAASC,UAAU,QAAQ,0BAAyB;AACpD,SAASC,UAAU,QAAQ,4BAA2B;AAEtD,OAAO,MAAMC,QAAe,eAAeA,MAEzC,EAAEC,UAAU,EAAEC,MAAM,EAAEC,GAAG,EAAEC,KAAK,EAAE;IAElC,MAAMC,QAAQ,IAAI,CAACC,WAAW,CAACL,WAAW;IAC1C,MAAMM,UAAwB;QAC5BC,SAAS,MAAMT,WAAW,IAAI,EAAEI;IAClC;IAEA,IAAIM,oBAAoB;IAExB,IAAIL,OAAO;QACT,MAAMM,cAAcb,wBAAwBO;QAC5CK,oBAAoBC,YAAYC,IAAI,CAAC,CAACC,OAASC,OAAOC,IAAI,CAACF,MAAMD,IAAI,CAAC,CAACI,MAAQA,QAAQ;IACzF;IAEA,MAAMC,QAAQ,MAAMlB,WAAW;QAC7BmB,SAAS,IAAI;QACbC,gBAAgBjB;QAChBkB,QAAQ,IAAI,CAACC,OAAO,CAACd,WAAW,CAACL,WAAW,CAACoB,MAAM,CAACC,eAAe;QACnEpB;QACAE;IACF;IAEA,4HAA4H;IAC5H,MAAMmB,oBAAoBd,qBAAqB,CAACO,SAASH,OAAOC,IAAI,CAACE,OAAOQ,MAAM,KAAK;IAEvF,IAAI,CAACD,qBAAqBV,OAAOC,IAAI,CAACE,OAAOQ,MAAM,KAAK,KAAK,IAAI,CAACC,iBAAiB,KAAK,MAAM;QAC5F,mHAAmH;QACnH,qHAAqH;QACrH,mHAAmH;QACnH,4BAA4B;QAC5BlB,QAAQmB,IAAI,GAAG;YACbC,KAAK;QACP;IACF;IAEA,IAAIC;IACJ,IAAIL,mBAAmB;QACrBK,SAAS,MAAMvB,MAAMwB,sBAAsB,CAAC;YAAErB,SAASD,QAAQC,OAAO;QAAC;IACzE,OAAO;QACLoB,SAAS,MAAMvB,MAAMyB,cAAc,CAACd,OAAOT;IAC7C;IAEA,OAAO;QACLwB,WAAWH;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 const options: CountOptions = {\n session: await getSession(this, req),\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 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 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","options","session","hasNearConstraint","constraints","some","prop","Object","keys","key","query","fields","flattenedFields","useEstimatedCount","length","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,MAAMO,UAAwB;QAC5BC,SAAS,MAAMX,WAAW,IAAI,EAAEK;IAClC;IAEA,IAAIO,oBAAoB;IAExB,IAAIN,OAAO;QACT,MAAMO,cAAchB,wBAAwBS;QAC5CM,oBAAoBC,YAAYC,IAAI,CAAC,CAACC,OAASC,OAAOC,IAAI,CAACF,MAAMD,IAAI,CAAC,CAACI,MAAQA,QAAQ;IACzF;IAEA,MAAMC,QAAQ,MAAMrB,WAAW;QAC7BW,SAAS,IAAI;QACbN;QACAiB,QAAQb,iBAAiBc,eAAe;QACxCjB;QACAE;IACF;IAEA,4HAA4H;IAC5H,MAAMgB,oBAAoBV,qBAAqB,CAACO,SAASH,OAAOC,IAAI,CAACE,OAAOI,MAAM,KAAK;IAEvF,IAAI,CAACD,qBAAqBN,OAAOC,IAAI,CAACE,OAAOI,MAAM,KAAK,KAAK,IAAI,CAACC,iBAAiB,KAAK,MAAM;QAC5F,mHAAmH;QACnH,qHAAqH;QACrH,mHAAmH;QACnH,4BAA4B;QAC5Bd,QAAQe,IAAI,GAAG;YACbC,KAAK;QACP;IACF;IAEA,IAAIC;IACJ,IAAIL,mBAAmB;QACrBK,SAAS,MAAMnB,MAAMoB,sBAAsB,CAAC;YAAEjB,SAASD,QAAQC,OAAO;QAAC;IACzE,OAAO;QACLgB,SAAS,MAAMnB,MAAMqB,cAAc,CAACV,OAAOT;IAC7C;IAEA,OAAO;QACLoB,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;AASlD,eAAO,MAAM,mBAAmB,EAAE,mBAkDjC,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,mBA+CjC,CAAA"}
@@ -1,8 +1,13 @@
1
1
  import { buildVersionGlobalFields, flattenWhereToOperators } from 'payload';
2
2
  import { buildQuery } from './queries/buildQuery.js';
3
+ import { getGlobal } from './utilities/getEntity.js';
3
4
  import { getSession } from './utilities/getSession.js';
4
- export const countGlobalVersions = async function countGlobalVersions({ global, locale, req, where }) {
5
- const Model = this.versions[global];
5
+ export const countGlobalVersions = async function countGlobalVersions({ global: globalSlug, locale, req, where = {} }) {
6
+ const { globalConfig, Model } = getGlobal({
7
+ adapter: this,
8
+ globalSlug,
9
+ versions: true
10
+ });
6
11
  const options = {
7
12
  session: await getSession(this, req)
8
13
  };
@@ -13,7 +18,7 @@ export const countGlobalVersions = async function countGlobalVersions({ global,
13
18
  }
14
19
  const query = await buildQuery({
15
20
  adapter: this,
16
- fields: buildVersionGlobalFields(this.payload.config, this.payload.globals.config.find((each)=>each.slug === global), true),
21
+ fields: buildVersionGlobalFields(this.payload.config, globalConfig, true),
17
22
  locale,
18
23
  where
19
24
  });
@@ -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 { getSession } from './utilities/getSession.js'\n\nexport const countGlobalVersions: CountGlobalVersions = async function countGlobalVersions(\n this: MongooseAdapter,\n { global, locale, req, where },\n) {\n const Model = this.versions[global]\n const options: CountOptions = {\n session: await getSession(this, req),\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: buildVersionGlobalFields(\n this.payload.config,\n this.payload.globals.config.find((each) => each.slug === global),\n true,\n ),\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 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","getSession","countGlobalVersions","global","locale","req","where","Model","versions","options","session","hasNearConstraint","constraints","some","prop","Object","keys","key","query","adapter","fields","payload","config","globals","find","each","slug","useEstimatedCount","length","disableIndexHints","hint","_id","result","estimatedDocumentCount","countDocuments","totalDocs"],"mappings":"AAGA,SAASA,wBAAwB,EAAEC,uBAAuB,QAAQ,UAAS;AAI3E,SAASC,UAAU,QAAQ,0BAAyB;AACpD,SAASC,UAAU,QAAQ,4BAA2B;AAEtD,OAAO,MAAMC,sBAA2C,eAAeA,oBAErE,EAAEC,MAAM,EAAEC,MAAM,EAAEC,GAAG,EAAEC,KAAK,EAAE;IAE9B,MAAMC,QAAQ,IAAI,CAACC,QAAQ,CAACL,OAAO;IACnC,MAAMM,UAAwB;QAC5BC,SAAS,MAAMT,WAAW,IAAI,EAAEI;IAClC;IAEA,IAAIM,oBAAoB;IAExB,IAAIL,OAAO;QACT,MAAMM,cAAcb,wBAAwBO;QAC5CK,oBAAoBC,YAAYC,IAAI,CAAC,CAACC,OAASC,OAAOC,IAAI,CAACF,MAAMD,IAAI,CAAC,CAACI,MAAQA,QAAQ;IACzF;IAEA,MAAMC,QAAQ,MAAMlB,WAAW;QAC7BmB,SAAS,IAAI;QACbC,QAAQtB,yBACN,IAAI,CAACuB,OAAO,CAACC,MAAM,EACnB,IAAI,CAACD,OAAO,CAACE,OAAO,CAACD,MAAM,CAACE,IAAI,CAAC,CAACC,OAASA,KAAKC,IAAI,KAAKvB,SACzD;QAEFC;QACAE;IACF;IAEA,4HAA4H;IAC5H,MAAMqB,oBAAoBhB,qBAAqB,CAACO,SAASH,OAAOC,IAAI,CAACE,OAAOU,MAAM,KAAK;IAEvF,IAAI,CAACD,qBAAqBZ,OAAOC,IAAI,CAACE,OAAOU,MAAM,KAAK,KAAK,IAAI,CAACC,iBAAiB,KAAK,MAAM;QAC5F,mHAAmH;QACnH,qHAAqH;QACrH,mHAAmH;QACnH,4BAA4B;QAC5BpB,QAAQqB,IAAI,GAAG;YACbC,KAAK;QACP;IACF;IAEA,IAAIC;IACJ,IAAIL,mBAAmB;QACrBK,SAAS,MAAMzB,MAAM0B,sBAAsB,CAAC;YAAEvB,SAASD,QAAQC,OAAO;QAAC;IACzE,OAAO;QACLsB,SAAS,MAAMzB,MAAM2B,cAAc,CAAChB,OAAOT;IAC7C;IAEA,OAAO;QACL0B,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 const options: CountOptions = {\n session: await getSession(this, req),\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: 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 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","options","session","hasNearConstraint","constraints","some","prop","Object","keys","key","query","fields","payload","config","useEstimatedCount","length","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,MAAMC,UAAwB;QAC5BC,SAAS,MAAMZ,WAAW,IAAI,EAAEK;IAClC;IAEA,IAAIQ,oBAAoB;IAExB,IAAIP,OAAO;QACT,MAAMQ,cAAcjB,wBAAwBS;QAC5CO,oBAAoBC,YAAYC,IAAI,CAAC,CAACC,OAASC,OAAOC,IAAI,CAACF,MAAMD,IAAI,CAAC,CAACI,MAAQA,QAAQ;IACzF;IAEA,MAAMC,QAAQ,MAAMtB,WAAW;QAC7BW,SAAS,IAAI;QACbY,QAAQzB,yBAAyB,IAAI,CAAC0B,OAAO,CAACC,MAAM,EAAEhB,cAAc;QACpEH;QACAE;IACF;IAEA,4HAA4H;IAC5H,MAAMkB,oBAAoBX,qBAAqB,CAACO,SAASH,OAAOC,IAAI,CAACE,OAAOK,MAAM,KAAK;IAEvF,IAAI,CAACD,qBAAqBP,OAAOC,IAAI,CAACE,OAAOK,MAAM,KAAK,KAAK,IAAI,CAACC,iBAAiB,KAAK,MAAM;QAC5F,mHAAmH;QACnH,qHAAqH;QACrH,mHAAmH;QACnH,4BAA4B;QAC5Bf,QAAQgB,IAAI,GAAG;YACbC,KAAK;QACP;IACF;IAEA,IAAIC;IACJ,IAAIL,mBAAmB;QACrBK,SAAS,MAAMrB,MAAMsB,sBAAsB,CAAC;YAAElB,SAASD,QAAQC,OAAO;QAAC;IACzE,OAAO;QACLiB,SAAS,MAAMrB,MAAMuB,cAAc,CAACX,OAAOT;IAC7C;IAEA,OAAO;QACLqB,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;AAS5C,eAAO,MAAM,aAAa,EAAE,aAkD3B,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,aAmD3B,CAAA"}
@@ -1,8 +1,13 @@
1
1
  import { buildVersionCollectionFields, flattenWhereToOperators } from 'payload';
2
2
  import { buildQuery } from './queries/buildQuery.js';
3
+ import { getCollection } from './utilities/getEntity.js';
3
4
  import { getSession } from './utilities/getSession.js';
4
- export const countVersions = async function countVersions({ collection, locale, req, where }) {
5
- const Model = this.versions[collection];
5
+ export const countVersions = async function countVersions({ collection: collectionSlug, locale, req, where = {} }) {
6
+ const { collectionConfig, Model } = getCollection({
7
+ adapter: this,
8
+ collectionSlug,
9
+ versions: true
10
+ });
6
11
  const options = {
7
12
  session: await getSession(this, req)
8
13
  };
@@ -13,7 +18,7 @@ export const countVersions = async function countVersions({ collection, locale,
13
18
  }
14
19
  const query = await buildQuery({
15
20
  adapter: this,
16
- fields: buildVersionCollectionFields(this.payload.config, this.payload.collections[collection].config, true),
21
+ fields: buildVersionCollectionFields(this.payload.config, collectionConfig, true),
17
22
  locale,
18
23
  where
19
24
  });
@@ -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 { getSession } from './utilities/getSession.js'\n\nexport const countVersions: CountVersions = async function countVersions(\n this: MongooseAdapter,\n { collection, locale, req, where },\n) {\n const Model = this.versions[collection]\n const options: CountOptions = {\n session: await getSession(this, req),\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(\n this.payload.config,\n this.payload.collections[collection].config,\n true,\n ),\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 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","getSession","countVersions","collection","locale","req","where","Model","versions","options","session","hasNearConstraint","constraints","some","prop","Object","keys","key","query","adapter","fields","payload","config","collections","useEstimatedCount","length","disableIndexHints","hint","_id","result","estimatedDocumentCount","countDocuments","totalDocs"],"mappings":"AAGA,SAASA,4BAA4B,EAAEC,uBAAuB,QAAQ,UAAS;AAI/E,SAASC,UAAU,QAAQ,0BAAyB;AACpD,SAASC,UAAU,QAAQ,4BAA2B;AAEtD,OAAO,MAAMC,gBAA+B,eAAeA,cAEzD,EAAEC,UAAU,EAAEC,MAAM,EAAEC,GAAG,EAAEC,KAAK,EAAE;IAElC,MAAMC,QAAQ,IAAI,CAACC,QAAQ,CAACL,WAAW;IACvC,MAAMM,UAAwB;QAC5BC,SAAS,MAAMT,WAAW,IAAI,EAAEI;IAClC;IAEA,IAAIM,oBAAoB;IAExB,IAAIL,OAAO;QACT,MAAMM,cAAcb,wBAAwBO;QAC5CK,oBAAoBC,YAAYC,IAAI,CAAC,CAACC,OAASC,OAAOC,IAAI,CAACF,MAAMD,IAAI,CAAC,CAACI,MAAQA,QAAQ;IACzF;IAEA,MAAMC,QAAQ,MAAMlB,WAAW;QAC7BmB,SAAS,IAAI;QACbC,QAAQtB,6BACN,IAAI,CAACuB,OAAO,CAACC,MAAM,EACnB,IAAI,CAACD,OAAO,CAACE,WAAW,CAACpB,WAAW,CAACmB,MAAM,EAC3C;QAEFlB;QACAE;IACF;IAEA,4HAA4H;IAC5H,MAAMkB,oBAAoBb,qBAAqB,CAACO,SAASH,OAAOC,IAAI,CAACE,OAAOO,MAAM,KAAK;IAEvF,IAAI,CAACD,qBAAqBT,OAAOC,IAAI,CAACE,OAAOO,MAAM,KAAK,KAAK,IAAI,CAACC,iBAAiB,KAAK,MAAM;QAC5F,mHAAmH;QACnH,qHAAqH;QACrH,mHAAmH;QACnH,4BAA4B;QAC5BjB,QAAQkB,IAAI,GAAG;YACbC,KAAK;QACP;IACF;IAEA,IAAIC;IACJ,IAAIL,mBAAmB;QACrBK,SAAS,MAAMtB,MAAMuB,sBAAsB,CAAC;YAAEpB,SAASD,QAAQC,OAAO;QAAC;IACzE,OAAO;QACLmB,SAAS,MAAMtB,MAAMwB,cAAc,CAACb,OAAOT;IAC7C;IAEA,OAAO;QACLuB,WAAWH;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 const options: CountOptions = {\n session: await getSession(this, req),\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 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","options","session","hasNearConstraint","constraints","some","prop","Object","keys","key","query","fields","payload","config","useEstimatedCount","length","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,MAAMC,UAAwB;QAC5BC,SAAS,MAAMZ,WAAW,IAAI,EAAEK;IAClC;IAEA,IAAIQ,oBAAoB;IAExB,IAAIP,OAAO;QACT,MAAMQ,cAAcjB,wBAAwBS;QAC5CO,oBAAoBC,YAAYC,IAAI,CAAC,CAACC,OAASC,OAAOC,IAAI,CAACF,MAAMD,IAAI,CAAC,CAACI,MAAQA,QAAQ;IACzF;IAEA,MAAMC,QAAQ,MAAMtB,WAAW;QAC7BW,SAAS,IAAI;QACbY,QAAQzB,6BAA6B,IAAI,CAAC0B,OAAO,CAACC,MAAM,EAAEhB,kBAAkB;QAC5EH;QACAE;IACF;IAEA,4HAA4H;IAC5H,MAAMkB,oBAAoBX,qBAAqB,CAACO,SAASH,OAAOC,IAAI,CAACE,OAAOK,MAAM,KAAK;IAEvF,IAAI,CAACD,qBAAqBP,OAAOC,IAAI,CAACE,OAAOK,MAAM,KAAK,KAAK,IAAI,CAACC,iBAAiB,KAAK,MAAM;QAC5F,mHAAmH;QACnH,qHAAqH;QACrH,mHAAmH;QACnH,4BAA4B;QAC5Bf,QAAQgB,IAAI,GAAG;YACbC,KAAK;QACP;IACF;IAEA,IAAIC;IACJ,IAAIL,mBAAmB;QACrBK,SAAS,MAAMrB,MAAMsB,sBAAsB,CAAC;YAAElB,SAASD,QAAQC,OAAO;QAAC;IACzE,OAAO;QACLiB,SAAS,MAAMrB,MAAMuB,cAAc,CAACX,OAAOT;IAC7C;IAEA,OAAO;QACLqB,WAAWH;IACb;AACF,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../src/create.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAY,MAAM,SAAS,CAAA;AAQ/C,eAAO,MAAM,MAAM,EAAE,MAsCpB,CAAA"}
1
+ {"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../src/create.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AASrC,eAAO,MAAM,MAAM,EAAE,MA0CpB,CAAA"}
package/dist/create.js CHANGED
@@ -1,8 +1,12 @@
1
+ import { getCollection } from './utilities/getEntity.js';
1
2
  import { getSession } from './utilities/getSession.js';
2
3
  import { handleError } from './utilities/handleError.js';
3
4
  import { transform } from './utilities/transform.js';
4
- export const create = async function create({ collection, data, req }) {
5
- const Model = this.collections[collection];
5
+ export const create = async function create({ collection: collectionSlug, data, req, returning }) {
6
+ const { collectionConfig, customIDType, Model } = getCollection({
7
+ adapter: this,
8
+ collectionSlug
9
+ });
6
10
  const options = {
7
11
  session: await getSession(this, req)
8
12
  };
@@ -10,10 +14,10 @@ export const create = async function create({ collection, data, req }) {
10
14
  transform({
11
15
  adapter: this,
12
16
  data,
13
- fields: this.payload.collections[collection].config.fields,
17
+ fields: collectionConfig.fields,
14
18
  operation: 'write'
15
19
  });
16
- if (this.payload.collections[collection].customIDType) {
20
+ if (customIDType) {
17
21
  data._id = data.id;
18
22
  }
19
23
  try {
@@ -23,16 +27,19 @@ export const create = async function create({ collection, data, req }) {
23
27
  ], options);
24
28
  } catch (error) {
25
29
  handleError({
26
- collection,
30
+ collection: collectionSlug,
27
31
  error,
28
32
  req
29
33
  });
30
34
  }
35
+ if (returning === false) {
36
+ return null;
37
+ }
31
38
  doc = doc.toObject();
32
39
  transform({
33
40
  adapter: this,
34
41
  data: doc,
35
- fields: this.payload.collections[collection].config.fields,
42
+ fields: collectionConfig.fields,
36
43
  operation: 'read'
37
44
  });
38
45
  return doc;
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/create.ts"],"sourcesContent":["import type { CreateOptions } from 'mongoose'\nimport type { Create, Document } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { getSession } from './utilities/getSession.js'\nimport { handleError } from './utilities/handleError.js'\nimport { transform } from './utilities/transform.js'\n\nexport const create: Create = async function create(\n this: MongooseAdapter,\n { collection, data, req },\n) {\n const Model = this.collections[collection]\n const options: CreateOptions = {\n session: await getSession(this, req),\n }\n\n let doc\n\n transform({\n adapter: this,\n data,\n fields: this.payload.collections[collection].config.fields,\n operation: 'write',\n })\n\n if (this.payload.collections[collection].customIDType) {\n data._id = data.id\n }\n\n try {\n ;[doc] = await Model.create([data], options)\n } catch (error) {\n handleError({ collection, error, req })\n }\n\n doc = doc.toObject()\n\n transform({\n adapter: this,\n data: doc,\n fields: this.payload.collections[collection].config.fields,\n operation: 'read',\n })\n\n return doc\n}\n"],"names":["getSession","handleError","transform","create","collection","data","req","Model","collections","options","session","doc","adapter","fields","payload","config","operation","customIDType","_id","id","error","toObject"],"mappings":"AAKA,SAASA,UAAU,QAAQ,4BAA2B;AACtD,SAASC,WAAW,QAAQ,6BAA4B;AACxD,SAASC,SAAS,QAAQ,2BAA0B;AAEpD,OAAO,MAAMC,SAAiB,eAAeA,OAE3C,EAAEC,UAAU,EAAEC,IAAI,EAAEC,GAAG,EAAE;IAEzB,MAAMC,QAAQ,IAAI,CAACC,WAAW,CAACJ,WAAW;IAC1C,MAAMK,UAAyB;QAC7BC,SAAS,MAAMV,WAAW,IAAI,EAAEM;IAClC;IAEA,IAAIK;IAEJT,UAAU;QACRU,SAAS,IAAI;QACbP;QACAQ,QAAQ,IAAI,CAACC,OAAO,CAACN,WAAW,CAACJ,WAAW,CAACW,MAAM,CAACF,MAAM;QAC1DG,WAAW;IACb;IAEA,IAAI,IAAI,CAACF,OAAO,CAACN,WAAW,CAACJ,WAAW,CAACa,YAAY,EAAE;QACrDZ,KAAKa,GAAG,GAAGb,KAAKc,EAAE;IACpB;IAEA,IAAI;;QACD,CAACR,IAAI,GAAG,MAAMJ,MAAMJ,MAAM,CAAC;YAACE;SAAK,EAAEI;IACtC,EAAE,OAAOW,OAAO;QACdnB,YAAY;YAAEG;YAAYgB;YAAOd;QAAI;IACvC;IAEAK,MAAMA,IAAIU,QAAQ;IAElBnB,UAAU;QACRU,SAAS,IAAI;QACbP,MAAMM;QACNE,QAAQ,IAAI,CAACC,OAAO,CAACN,WAAW,CAACJ,WAAW,CAACW,MAAM,CAACF,MAAM;QAC1DG,WAAW;IACb;IAEA,OAAOL;AACT,EAAC"}
1
+ {"version":3,"sources":["../src/create.ts"],"sourcesContent":["import type { CreateOptions } from 'mongoose'\nimport type { Create } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { getCollection } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\nimport { handleError } from './utilities/handleError.js'\nimport { transform } from './utilities/transform.js'\n\nexport const create: Create = async function create(\n this: MongooseAdapter,\n { collection: collectionSlug, data, req, returning },\n) {\n const { collectionConfig, customIDType, Model } = getCollection({ adapter: this, collectionSlug })\n\n const options: CreateOptions = {\n session: await getSession(this, req),\n }\n\n let doc\n\n transform({\n adapter: this,\n data,\n fields: collectionConfig.fields,\n operation: 'write',\n })\n\n if (customIDType) {\n data._id = data.id\n }\n\n try {\n ;[doc] = await Model.create([data], options)\n } catch (error) {\n handleError({ collection: collectionSlug, error, req })\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: collectionConfig.fields,\n operation: 'read',\n })\n\n return doc\n}\n"],"names":["getCollection","getSession","handleError","transform","create","collection","collectionSlug","data","req","returning","collectionConfig","customIDType","Model","adapter","options","session","doc","fields","operation","_id","id","error","toObject"],"mappings":"AAKA,SAASA,aAAa,QAAQ,2BAA0B;AACxD,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,WAAW,QAAQ,6BAA4B;AACxD,SAASC,SAAS,QAAQ,2BAA0B;AAEpD,OAAO,MAAMC,SAAiB,eAAeA,OAE3C,EAAEC,YAAYC,cAAc,EAAEC,IAAI,EAAEC,GAAG,EAAEC,SAAS,EAAE;IAEpD,MAAM,EAAEC,gBAAgB,EAAEC,YAAY,EAAEC,KAAK,EAAE,GAAGZ,cAAc;QAAEa,SAAS,IAAI;QAAEP;IAAe;IAEhG,MAAMQ,UAAyB;QAC7BC,SAAS,MAAMd,WAAW,IAAI,EAAEO;IAClC;IAEA,IAAIQ;IAEJb,UAAU;QACRU,SAAS,IAAI;QACbN;QACAU,QAAQP,iBAAiBO,MAAM;QAC/BC,WAAW;IACb;IAEA,IAAIP,cAAc;QAChBJ,KAAKY,GAAG,GAAGZ,KAAKa,EAAE;IACpB;IAEA,IAAI;;QACD,CAACJ,IAAI,GAAG,MAAMJ,MAAMR,MAAM,CAAC;YAACG;SAAK,EAAEO;IACtC,EAAE,OAAOO,OAAO;QACdnB,YAAY;YAAEG,YAAYC;YAAgBe;YAAOb;QAAI;IACvD;IACA,IAAIC,cAAc,OAAO;QACvB,OAAO;IACT;IAEAO,MAAMA,IAAIM,QAAQ;IAElBnB,UAAU;QACRU,SAAS,IAAI;QACbN,MAAMS;QACNC,QAAQP,iBAAiBO,MAAM;QAC/BC,WAAW;IACb;IAEA,OAAOF;AACT,EAAC"}
@@ -1,3 +1,3 @@
1
- import type { CreateGlobal } from 'payload';
1
+ import { type CreateGlobal } from 'payload';
2
2
  export declare const createGlobal: CreateGlobal;
3
3
  //# sourceMappingURL=createGlobal.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"createGlobal.d.ts","sourceRoot":"","sources":["../src/createGlobal.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAO3C,eAAO,MAAM,YAAY,EAAE,YA8B1B,CAAA"}
1
+ {"version":3,"file":"createGlobal.d.ts","sourceRoot":"","sources":["../src/createGlobal.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,SAAS,CAAA;AAQ3C,eAAO,MAAM,YAAY,EAAE,YAiC1B,CAAA"}
@@ -1,12 +1,16 @@
1
+ import { getGlobal } from './utilities/getEntity.js';
1
2
  import { getSession } from './utilities/getSession.js';
2
3
  import { transform } from './utilities/transform.js';
3
- export const createGlobal = async function createGlobal({ slug, data, req }) {
4
- const Model = this.globals;
4
+ export const createGlobal = async function createGlobal({ slug: globalSlug, data, req, returning }) {
5
+ const { globalConfig, Model } = getGlobal({
6
+ adapter: this,
7
+ globalSlug
8
+ });
5
9
  transform({
6
10
  adapter: this,
7
11
  data,
8
- fields: this.payload.config.globals.find((globalConfig)=>globalConfig.slug === slug).fields,
9
- globalSlug: slug,
12
+ fields: globalConfig.fields,
13
+ globalSlug,
10
14
  operation: 'write'
11
15
  });
12
16
  const options = {
@@ -15,11 +19,14 @@ export const createGlobal = async function createGlobal({ slug, data, req }) {
15
19
  let [result] = await Model.create([
16
20
  data
17
21
  ], options);
22
+ if (returning === false) {
23
+ return null;
24
+ }
18
25
  result = result.toObject();
19
26
  transform({
20
27
  adapter: this,
21
28
  data: result,
22
- fields: this.payload.config.globals.find((globalConfig)=>globalConfig.slug === slug).fields,
29
+ fields: globalConfig.fields,
23
30
  operation: 'read'
24
31
  });
25
32
  return result;
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/createGlobal.ts"],"sourcesContent":["import type { CreateOptions } from 'mongoose'\nimport type { CreateGlobal } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { getSession } from './utilities/getSession.js'\nimport { transform } from './utilities/transform.js'\n\nexport const createGlobal: CreateGlobal = async function createGlobal(\n this: MongooseAdapter,\n { slug, data, req },\n) {\n const Model = this.globals\n\n transform({\n adapter: this,\n data,\n fields: this.payload.config.globals.find((globalConfig) => globalConfig.slug === slug).fields,\n globalSlug: slug,\n operation: 'write',\n })\n\n const options: CreateOptions = {\n session: await getSession(this, req),\n }\n\n let [result] = (await Model.create([data], options)) as any\n\n result = result.toObject()\n\n transform({\n adapter: this,\n data: result,\n fields: this.payload.config.globals.find((globalConfig) => globalConfig.slug === slug).fields,\n operation: 'read',\n })\n\n return result\n}\n"],"names":["getSession","transform","createGlobal","slug","data","req","Model","globals","adapter","fields","payload","config","find","globalConfig","globalSlug","operation","options","session","result","create","toObject"],"mappings":"AAKA,SAASA,UAAU,QAAQ,4BAA2B;AACtD,SAASC,SAAS,QAAQ,2BAA0B;AAEpD,OAAO,MAAMC,eAA6B,eAAeA,aAEvD,EAAEC,IAAI,EAAEC,IAAI,EAAEC,GAAG,EAAE;IAEnB,MAAMC,QAAQ,IAAI,CAACC,OAAO;IAE1BN,UAAU;QACRO,SAAS,IAAI;QACbJ;QACAK,QAAQ,IAAI,CAACC,OAAO,CAACC,MAAM,CAACJ,OAAO,CAACK,IAAI,CAAC,CAACC,eAAiBA,aAAaV,IAAI,KAAKA,MAAMM,MAAM;QAC7FK,YAAYX;QACZY,WAAW;IACb;IAEA,MAAMC,UAAyB;QAC7BC,SAAS,MAAMjB,WAAW,IAAI,EAAEK;IAClC;IAEA,IAAI,CAACa,OAAO,GAAI,MAAMZ,MAAMa,MAAM,CAAC;QAACf;KAAK,EAAEY;IAE3CE,SAASA,OAAOE,QAAQ;IAExBnB,UAAU;QACRO,SAAS,IAAI;QACbJ,MAAMc;QACNT,QAAQ,IAAI,CAACC,OAAO,CAACC,MAAM,CAACJ,OAAO,CAACK,IAAI,CAAC,CAACC,eAAiBA,aAAaV,IAAI,KAAKA,MAAMM,MAAM;QAC7FM,WAAW;IACb;IAEA,OAAOG;AACT,EAAC"}
1
+ {"version":3,"sources":["../src/createGlobal.ts"],"sourcesContent":["import type { CreateOptions } from 'mongoose'\n\nimport { type CreateGlobal } 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 createGlobal: CreateGlobal = async function createGlobal(\n this: MongooseAdapter,\n { slug: globalSlug, data, req, returning },\n) {\n const { globalConfig, Model } = getGlobal({ adapter: this, globalSlug })\n\n transform({\n adapter: this,\n data,\n fields: globalConfig.fields,\n globalSlug,\n operation: 'write',\n })\n\n const options: CreateOptions = {\n session: await getSession(this, req),\n }\n\n let [result] = (await Model.create([data], options)) as any\n if (returning === false) {\n return null\n }\n\n result = result.toObject()\n\n transform({\n adapter: this,\n data: result,\n fields: globalConfig.fields,\n operation: 'read',\n })\n\n return result\n}\n"],"names":["getGlobal","getSession","transform","createGlobal","slug","globalSlug","data","req","returning","globalConfig","Model","adapter","fields","operation","options","session","result","create","toObject"],"mappings":"AAMA,SAASA,SAAS,QAAQ,2BAA0B;AACpD,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,SAAS,QAAQ,2BAA0B;AAEpD,OAAO,MAAMC,eAA6B,eAAeA,aAEvD,EAAEC,MAAMC,UAAU,EAAEC,IAAI,EAAEC,GAAG,EAAEC,SAAS,EAAE;IAE1C,MAAM,EAAEC,YAAY,EAAEC,KAAK,EAAE,GAAGV,UAAU;QAAEW,SAAS,IAAI;QAAEN;IAAW;IAEtEH,UAAU;QACRS,SAAS,IAAI;QACbL;QACAM,QAAQH,aAAaG,MAAM;QAC3BP;QACAQ,WAAW;IACb;IAEA,MAAMC,UAAyB;QAC7BC,SAAS,MAAMd,WAAW,IAAI,EAAEM;IAClC;IAEA,IAAI,CAACS,OAAO,GAAI,MAAMN,MAAMO,MAAM,CAAC;QAACX;KAAK,EAAEQ;IAC3C,IAAIN,cAAc,OAAO;QACvB,OAAO;IACT;IAEAQ,SAASA,OAAOE,QAAQ;IAExBhB,UAAU;QACRS,SAAS,IAAI;QACbL,MAAMU;QACNJ,QAAQH,aAAaG,MAAM;QAC3BC,WAAW;IACb;IAEA,OAAOG;AACT,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"createGlobalVersion.d.ts","sourceRoot":"","sources":["../src/createGlobalVersion.ts"],"names":[],"mappings":"AAEA,OAAO,EAA4B,KAAK,mBAAmB,EAAE,MAAM,SAAS,CAAA;AAO5E,eAAO,MAAM,mBAAmB,EAAE,mBA8EjC,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,mBAiFjC,CAAA"}
@@ -1,8 +1,13 @@
1
1
  import { buildVersionGlobalFields } from 'payload';
2
+ import { getGlobal } from './utilities/getEntity.js';
2
3
  import { getSession } from './utilities/getSession.js';
3
4
  import { transform } from './utilities/transform.js';
4
- export const createGlobalVersion = async function createGlobalVersion({ autosave, createdAt, globalSlug, parent, publishedLocale, req, snapshot, updatedAt, versionData }) {
5
- const VersionModel = this.versions[globalSlug];
5
+ export const createGlobalVersion = async function createGlobalVersion({ autosave, createdAt, globalSlug, parent, publishedLocale, req, returning, snapshot, updatedAt, versionData }) {
6
+ const { globalConfig, Model } = getGlobal({
7
+ adapter: this,
8
+ globalSlug,
9
+ versions: true
10
+ });
6
11
  const options = {
7
12
  session: await getSession(this, req)
8
13
  };
@@ -16,17 +21,17 @@ export const createGlobalVersion = async function createGlobalVersion({ autosave
16
21
  updatedAt,
17
22
  version: versionData
18
23
  };
19
- const fields = buildVersionGlobalFields(this.payload.config, this.payload.config.globals.find((global)=>global.slug === globalSlug));
24
+ const fields = buildVersionGlobalFields(this.payload.config, globalConfig);
20
25
  transform({
21
26
  adapter: this,
22
27
  data,
23
28
  fields,
24
29
  operation: 'write'
25
30
  });
26
- let [doc] = await VersionModel.create([
31
+ let [doc] = await Model.create([
27
32
  data
28
33
  ], options, req);
29
- await VersionModel.updateMany({
34
+ await Model.updateMany({
30
35
  $and: [
31
36
  {
32
37
  _id: {
@@ -49,6 +54,9 @@ export const createGlobalVersion = async function createGlobalVersion({ autosave
49
54
  latest: 1
50
55
  }
51
56
  }, options);
57
+ if (returning === false) {
58
+ return null;
59
+ }
52
60
  doc = doc.toObject();
53
61
  transform({
54
62
  adapter: this,
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/createGlobalVersion.ts"],"sourcesContent":["import type { CreateOptions } from 'mongoose'\n\nimport { buildVersionGlobalFields, type CreateGlobalVersion } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\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 parent,\n publishedLocale,\n req,\n snapshot,\n updatedAt,\n versionData,\n },\n) {\n const VersionModel = this.versions[globalSlug]\n const options: CreateOptions = {\n session: await getSession(this, req),\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\n const fields = buildVersionGlobalFields(\n this.payload.config,\n this.payload.config.globals.find((global) => global.slug === globalSlug),\n )\n\n transform({\n adapter: this,\n data,\n fields,\n operation: 'write',\n })\n\n let [doc] = await VersionModel.create([data], options, req)\n\n await VersionModel.updateMany(\n {\n $and: [\n {\n _id: {\n $ne: doc._id,\n },\n },\n {\n parent: {\n $eq: parent,\n },\n },\n {\n latest: {\n $eq: true,\n },\n },\n ],\n },\n { $unset: { latest: 1 } },\n options,\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","getSession","transform","createGlobalVersion","autosave","createdAt","globalSlug","parent","publishedLocale","req","snapshot","updatedAt","versionData","VersionModel","versions","options","session","data","latest","version","fields","payload","config","globals","find","global","slug","adapter","operation","doc","create","updateMany","$and","_id","$ne","$eq","$unset","toObject"],"mappings":"AAEA,SAASA,wBAAwB,QAAkC,UAAS;AAI5E,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,SAAS,QAAQ,2BAA0B;AAEpD,OAAO,MAAMC,sBAA2C,eAAeA,oBAErE,EACEC,QAAQ,EACRC,SAAS,EACTC,UAAU,EACVC,MAAM,EACNC,eAAe,EACfC,GAAG,EACHC,QAAQ,EACRC,SAAS,EACTC,WAAW,EACZ;IAED,MAAMC,eAAe,IAAI,CAACC,QAAQ,CAACR,WAAW;IAC9C,MAAMS,UAAyB;QAC7BC,SAAS,MAAMf,WAAW,IAAI,EAAEQ;IAClC;IAEA,MAAMQ,OAAO;QACXb;QACAC;QACAa,QAAQ;QACRX;QACAC;QACAE;QACAC;QACAQ,SAASP;IACX;IAEA,MAAMQ,SAASpB,yBACb,IAAI,CAACqB,OAAO,CAACC,MAAM,EACnB,IAAI,CAACD,OAAO,CAACC,MAAM,CAACC,OAAO,CAACC,IAAI,CAAC,CAACC,SAAWA,OAAOC,IAAI,KAAKpB;IAG/DJ,UAAU;QACRyB,SAAS,IAAI;QACbV;QACAG;QACAQ,WAAW;IACb;IAEA,IAAI,CAACC,IAAI,GAAG,MAAMhB,aAAaiB,MAAM,CAAC;QAACb;KAAK,EAAEF,SAASN;IAEvD,MAAMI,aAAakB,UAAU,CAC3B;QACEC,MAAM;YACJ;gBACEC,KAAK;oBACHC,KAAKL,IAAII,GAAG;gBACd;YACF;YACA;gBACE1B,QAAQ;oBACN4B,KAAK5B;gBACP;YACF;YACA;gBACEW,QAAQ;oBACNiB,KAAK;gBACP;YACF;SACD;IACH,GACA;QAAEC,QAAQ;YAAElB,QAAQ;QAAE;IAAE,GACxBH;IAGFc,MAAMA,IAAIQ,QAAQ;IAElBnC,UAAU;QACRyB,SAAS,IAAI;QACbV,MAAMY;QACNT;QACAQ,WAAW;IACb;IAEA,OAAOC;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 parent,\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 options = {\n session: await getSession(this, req),\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\n const fields = buildVersionGlobalFields(this.payload.config, globalConfig)\n\n transform({\n adapter: this,\n data,\n fields,\n operation: 'write',\n })\n\n let [doc] = await Model.create([data], options, req)\n\n await Model.updateMany(\n {\n $and: [\n {\n _id: {\n $ne: doc._id,\n },\n },\n {\n parent: {\n $eq: parent,\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","parent","publishedLocale","req","returning","snapshot","updatedAt","versionData","globalConfig","Model","adapter","versions","options","session","data","latest","version","fields","payload","config","operation","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,MAAM,EACNC,eAAe,EACfC,GAAG,EACHC,SAAS,EACTC,QAAQ,EACRC,SAAS,EACTC,WAAW,EACZ;IAED,MAAM,EAAEC,YAAY,EAAEC,KAAK,EAAE,GAAGf,UAAU;QAAEgB,SAAS,IAAI;QAAEV;QAAYW,UAAU;IAAK;IAEtF,MAAMC,UAAU;QACdC,SAAS,MAAMlB,WAAW,IAAI,EAAEQ;IAClC;IAEA,MAAMW,OAAO;QACXhB;QACAC;QACAgB,QAAQ;QACRd;QACAC;QACAG;QACAC;QACAU,SAAST;IACX;IAEA,MAAMU,SAASxB,yBAAyB,IAAI,CAACyB,OAAO,CAACC,MAAM,EAAEX;IAE7DZ,UAAU;QACRc,SAAS,IAAI;QACbI;QACAG;QACAG,WAAW;IACb;IAEA,IAAI,CAACC,IAAI,GAAG,MAAMZ,MAAMa,MAAM,CAAC;QAACR;KAAK,EAAEF,SAAST;IAEhD,MAAMM,MAAMc,UAAU,CACpB;QACEC,MAAM;YACJ;gBACEC,KAAK;oBACHC,KAAKL,IAAII,GAAG;gBACd;YACF;YACA;gBACExB,QAAQ;oBACN0B,KAAK1B;gBACP;YACF;YACA;gBACEc,QAAQ;oBACNY,KAAK;gBACP;YACF;SACD;IACH,GACA;QAAEC,QAAQ;YAAEb,QAAQ;QAAE;IAAE,GACxBH;IAGF,IAAIR,cAAc,OAAO;QACvB,OAAO;IACT;IAEAiB,MAAMA,IAAIQ,QAAQ;IAElBjC,UAAU;QACRc,SAAS,IAAI;QACbI,MAAMO;QACNJ;QACAG,WAAW;IACb;IAEA,OAAOC;AACT,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"createMigration.d.ts","sourceRoot":"","sources":["../src/createMigration.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAyB,MAAM,SAAS,CAAA;AAqBrE,eAAO,MAAM,eAAe,EAAE,eAuC7B,CAAA"}
1
+ {"version":3,"file":"createMigration.d.ts","sourceRoot":"","sources":["../src/createMigration.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAyB,MAAM,SAAS,CAAA;AAqBrE,eAAO,MAAM,eAAe,EAAE,eAwC7B,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/createMigration.ts"],"sourcesContent":["import type { CreateMigration, MigrationTemplateArgs } from 'payload'\n\nimport fs from 'fs'\nimport path from 'path'\nimport { getPredefinedMigration, writeMigrationIndex } from 'payload'\nimport { fileURLToPath } from 'url'\n\nconst migrationTemplate = ({ downSQL, imports, upSQL }: MigrationTemplateArgs): string => `import {\n MigrateDownArgs,\n MigrateUpArgs,\n} from '@payloadcms/db-mongodb'\n${imports ?? ''}\nexport async function up({ payload, req, session }: MigrateUpArgs): Promise<void> {\n${upSQL ?? ` // Migration code`}\n}\n\nexport async function down({ payload, req, session }: MigrateDownArgs): Promise<void> {\n${downSQL ?? ` // Migration code`}\n}\n`\n\nexport const createMigration: CreateMigration = async function createMigration({\n file,\n migrationName,\n payload,\n skipEmpty,\n}) {\n const filename = fileURLToPath(import.meta.url)\n const dirname = path.dirname(filename)\n\n const dir = payload.db.migrationDir\n if (!fs.existsSync(dir)) {\n fs.mkdirSync(dir)\n }\n const predefinedMigration = await getPredefinedMigration({\n dirname,\n file,\n migrationName,\n payload,\n })\n\n const migrationFileContent = migrationTemplate(predefinedMigration)\n\n const [yyymmdd, hhmmss] = new Date().toISOString().split('T')\n const formattedDate = yyymmdd.replace(/\\D/g, '')\n const formattedTime = hhmmss.split('.')[0].replace(/\\D/g, '')\n\n const timestamp = `${formattedDate}_${formattedTime}`\n\n const formattedName = migrationName?.replace(/\\W/g, '_')\n const fileName = migrationName ? `${timestamp}_${formattedName}.ts` : `${timestamp}_migration.ts`\n const filePath = `${dir}/${fileName}`\n\n if (!skipEmpty) {\n fs.writeFileSync(filePath, migrationFileContent)\n }\n\n writeMigrationIndex({ migrationsDir: payload.db.migrationDir })\n\n payload.logger.info({ msg: `Migration created at ${filePath}` })\n}\n"],"names":["fs","path","getPredefinedMigration","writeMigrationIndex","fileURLToPath","migrationTemplate","downSQL","imports","upSQL","createMigration","file","migrationName","payload","skipEmpty","filename","url","dirname","dir","db","migrationDir","existsSync","mkdirSync","predefinedMigration","migrationFileContent","yyymmdd","hhmmss","Date","toISOString","split","formattedDate","replace","formattedTime","timestamp","formattedName","fileName","filePath","writeFileSync","migrationsDir","logger","info","msg"],"mappings":"AAEA,OAAOA,QAAQ,KAAI;AACnB,OAAOC,UAAU,OAAM;AACvB,SAASC,sBAAsB,EAAEC,mBAAmB,QAAQ,UAAS;AACrE,SAASC,aAAa,QAAQ,MAAK;AAEnC,MAAMC,oBAAoB,CAAC,EAAEC,OAAO,EAAEC,OAAO,EAAEC,KAAK,EAAyB,GAAa,CAAC;;;;AAI3F,EAAED,WAAW,GAAG;;AAEhB,EAAEC,SAAS,CAAC,mBAAmB,CAAC,CAAC;;;;AAIjC,EAAEF,WAAW,CAAC,mBAAmB,CAAC,CAAC;;AAEnC,CAAC;AAED,OAAO,MAAMG,kBAAmC,eAAeA,gBAAgB,EAC7EC,IAAI,EACJC,aAAa,EACbC,OAAO,EACPC,SAAS,EACV;IACC,MAAMC,WAAWV,cAAc,YAAYW,GAAG;IAC9C,MAAMC,UAAUf,KAAKe,OAAO,CAACF;IAE7B,MAAMG,MAAML,QAAQM,EAAE,CAACC,YAAY;IACnC,IAAI,CAACnB,GAAGoB,UAAU,CAACH,MAAM;QACvBjB,GAAGqB,SAAS,CAACJ;IACf;IACA,MAAMK,sBAAsB,MAAMpB,uBAAuB;QACvDc;QACAN;QACAC;QACAC;IACF;IAEA,MAAMW,uBAAuBlB,kBAAkBiB;IAE/C,MAAM,CAACE,SAASC,OAAO,GAAG,IAAIC,OAAOC,WAAW,GAAGC,KAAK,CAAC;IACzD,MAAMC,gBAAgBL,QAAQM,OAAO,CAAC,OAAO;IAC7C,MAAMC,gBAAgBN,OAAOG,KAAK,CAAC,IAAI,CAAC,EAAE,CAACE,OAAO,CAAC,OAAO;IAE1D,MAAME,YAAY,GAAGH,cAAc,CAAC,EAAEE,eAAe;IAErD,MAAME,gBAAgBtB,eAAemB,QAAQ,OAAO;IACpD,MAAMI,WAAWvB,gBAAgB,GAAGqB,UAAU,CAAC,EAAEC,cAAc,GAAG,CAAC,GAAG,GAAGD,UAAU,aAAa,CAAC;IACjG,MAAMG,WAAW,GAAGlB,IAAI,CAAC,EAAEiB,UAAU;IAErC,IAAI,CAACrB,WAAW;QACdb,GAAGoC,aAAa,CAACD,UAAUZ;IAC7B;IAEApB,oBAAoB;QAAEkC,eAAezB,QAAQM,EAAE,CAACC,YAAY;IAAC;IAE7DP,QAAQ0B,MAAM,CAACC,IAAI,CAAC;QAAEC,KAAK,CAAC,qBAAqB,EAAEL,UAAU;IAAC;AAChE,EAAC"}
1
+ {"version":3,"sources":["../src/createMigration.ts"],"sourcesContent":["import type { CreateMigration, MigrationTemplateArgs } from 'payload'\n\nimport fs from 'fs'\nimport path from 'path'\nimport { getPredefinedMigration, writeMigrationIndex } from 'payload'\nimport { fileURLToPath } from 'url'\n\nconst migrationTemplate = ({ downSQL, imports, upSQL }: MigrationTemplateArgs): string => `import {\n MigrateDownArgs,\n MigrateUpArgs,\n} from '@payloadcms/db-mongodb'\n${imports ?? ''}\nexport async function up({ payload, req, session }: MigrateUpArgs): Promise<void> {\n${upSQL ?? ` // Migration code`}\n}\n\nexport async function down({ payload, req, session }: MigrateDownArgs): Promise<void> {\n${downSQL ?? ` // Migration code`}\n}\n`\n\nexport const createMigration: CreateMigration = async function createMigration({\n file,\n migrationName,\n payload,\n skipEmpty,\n}) {\n const filename = fileURLToPath(import.meta.url)\n const dirname = path.dirname(filename)\n\n const dir = payload.db.migrationDir\n if (!fs.existsSync(dir)) {\n fs.mkdirSync(dir)\n }\n const predefinedMigration = await getPredefinedMigration({\n dirname,\n file,\n migrationName,\n payload,\n })\n\n const migrationFileContent = migrationTemplate(predefinedMigration)\n\n const [yyymmdd, hhmmss] = new Date().toISOString().split('T')\n\n const formattedDate = yyymmdd!.replace(/\\D/g, '')\n const formattedTime = hhmmss!.split('.')[0]!.replace(/\\D/g, '')\n\n const timestamp = `${formattedDate}_${formattedTime}`\n\n const formattedName = migrationName?.replace(/\\W/g, '_')\n const fileName = migrationName ? `${timestamp}_${formattedName}.ts` : `${timestamp}_migration.ts`\n const filePath = `${dir}/${fileName}`\n\n if (!skipEmpty) {\n fs.writeFileSync(filePath, migrationFileContent)\n }\n\n writeMigrationIndex({ migrationsDir: payload.db.migrationDir })\n\n payload.logger.info({ msg: `Migration created at ${filePath}` })\n}\n"],"names":["fs","path","getPredefinedMigration","writeMigrationIndex","fileURLToPath","migrationTemplate","downSQL","imports","upSQL","createMigration","file","migrationName","payload","skipEmpty","filename","url","dirname","dir","db","migrationDir","existsSync","mkdirSync","predefinedMigration","migrationFileContent","yyymmdd","hhmmss","Date","toISOString","split","formattedDate","replace","formattedTime","timestamp","formattedName","fileName","filePath","writeFileSync","migrationsDir","logger","info","msg"],"mappings":"AAEA,OAAOA,QAAQ,KAAI;AACnB,OAAOC,UAAU,OAAM;AACvB,SAASC,sBAAsB,EAAEC,mBAAmB,QAAQ,UAAS;AACrE,SAASC,aAAa,QAAQ,MAAK;AAEnC,MAAMC,oBAAoB,CAAC,EAAEC,OAAO,EAAEC,OAAO,EAAEC,KAAK,EAAyB,GAAa,CAAC;;;;AAI3F,EAAED,WAAW,GAAG;;AAEhB,EAAEC,SAAS,CAAC,mBAAmB,CAAC,CAAC;;;;AAIjC,EAAEF,WAAW,CAAC,mBAAmB,CAAC,CAAC;;AAEnC,CAAC;AAED,OAAO,MAAMG,kBAAmC,eAAeA,gBAAgB,EAC7EC,IAAI,EACJC,aAAa,EACbC,OAAO,EACPC,SAAS,EACV;IACC,MAAMC,WAAWV,cAAc,YAAYW,GAAG;IAC9C,MAAMC,UAAUf,KAAKe,OAAO,CAACF;IAE7B,MAAMG,MAAML,QAAQM,EAAE,CAACC,YAAY;IACnC,IAAI,CAACnB,GAAGoB,UAAU,CAACH,MAAM;QACvBjB,GAAGqB,SAAS,CAACJ;IACf;IACA,MAAMK,sBAAsB,MAAMpB,uBAAuB;QACvDc;QACAN;QACAC;QACAC;IACF;IAEA,MAAMW,uBAAuBlB,kBAAkBiB;IAE/C,MAAM,CAACE,SAASC,OAAO,GAAG,IAAIC,OAAOC,WAAW,GAAGC,KAAK,CAAC;IAEzD,MAAMC,gBAAgBL,QAASM,OAAO,CAAC,OAAO;IAC9C,MAAMC,gBAAgBN,OAAQG,KAAK,CAAC,IAAI,CAAC,EAAE,CAAEE,OAAO,CAAC,OAAO;IAE5D,MAAME,YAAY,GAAGH,cAAc,CAAC,EAAEE,eAAe;IAErD,MAAME,gBAAgBtB,eAAemB,QAAQ,OAAO;IACpD,MAAMI,WAAWvB,gBAAgB,GAAGqB,UAAU,CAAC,EAAEC,cAAc,GAAG,CAAC,GAAG,GAAGD,UAAU,aAAa,CAAC;IACjG,MAAMG,WAAW,GAAGlB,IAAI,CAAC,EAAEiB,UAAU;IAErC,IAAI,CAACrB,WAAW;QACdb,GAAGoC,aAAa,CAACD,UAAUZ;IAC7B;IAEApB,oBAAoB;QAAEkC,eAAezB,QAAQM,EAAE,CAACC,YAAY;IAAC;IAE7DP,QAAQ0B,MAAM,CAACC,IAAI,CAAC;QAAEC,KAAK,CAAC,qBAAqB,EAAEL,UAAU;IAAC;AAChE,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"createVersion.d.ts","sourceRoot":"","sources":["../src/createVersion.ts"],"names":[],"mappings":"AAEA,OAAO,EAAgC,KAAK,aAAa,EAAE,MAAM,SAAS,CAAA;AAO1E,eAAO,MAAM,aAAa,EAAE,aAyF3B,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,aAgG3B,CAAA"}
@@ -1,8 +1,13 @@
1
1
  import { buildVersionCollectionFields } from 'payload';
2
+ import { getCollection } from './utilities/getEntity.js';
2
3
  import { getSession } from './utilities/getSession.js';
3
4
  import { transform } from './utilities/transform.js';
4
- export const createVersion = async function createVersion({ autosave, collectionSlug, createdAt, parent, publishedLocale, req, snapshot, updatedAt, versionData }) {
5
- const VersionModel = this.versions[collectionSlug];
5
+ export const createVersion = async function createVersion({ autosave, collectionSlug, createdAt, parent, publishedLocale, req, returning, snapshot, updatedAt, versionData }) {
6
+ const { collectionConfig, Model } = getCollection({
7
+ adapter: this,
8
+ collectionSlug,
9
+ versions: true
10
+ });
6
11
  const options = {
7
12
  session: await getSession(this, req)
8
13
  };
@@ -16,14 +21,14 @@ export const createVersion = async function createVersion({ autosave, collection
16
21
  updatedAt,
17
22
  version: versionData
18
23
  };
19
- const fields = buildVersionCollectionFields(this.payload.config, this.payload.collections[collectionSlug].config);
24
+ const fields = buildVersionCollectionFields(this.payload.config, collectionConfig);
20
25
  transform({
21
26
  adapter: this,
22
27
  data,
23
28
  fields,
24
29
  operation: 'write'
25
30
  });
26
- let [doc] = await VersionModel.create([
31
+ let [doc] = await Model.create([
27
32
  data
28
33
  ], options, req);
29
34
  const parentQuery = {
@@ -35,7 +40,7 @@ export const createVersion = async function createVersion({ autosave, collection
35
40
  }
36
41
  ]
37
42
  };
38
- await VersionModel.updateMany({
43
+ await Model.updateMany({
39
44
  $and: [
40
45
  {
41
46
  _id: {
@@ -59,6 +64,9 @@ export const createVersion = async function createVersion({ autosave, collection
59
64
  latest: 1
60
65
  }
61
66
  }, options);
67
+ if (returning === false) {
68
+ return null;
69
+ }
62
70
  doc = doc.toObject();
63
71
  transform({
64
72
  adapter: this,
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/createVersion.ts"],"sourcesContent":["import type { CreateOptions } from 'mongoose'\n\nimport { buildVersionCollectionFields, type CreateVersion } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\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 snapshot,\n updatedAt,\n versionData,\n },\n) {\n const VersionModel = this.versions[collectionSlug]\n const options: CreateOptions = {\n session: await getSession(this, req),\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\n const fields = buildVersionCollectionFields(\n this.payload.config,\n this.payload.collections[collectionSlug].config,\n )\n\n transform({\n adapter: this,\n data,\n fields,\n operation: 'write',\n })\n\n let [doc] = await VersionModel.create([data], options, req)\n\n const parentQuery = {\n $or: [\n {\n parent: {\n $eq: data.parent,\n },\n },\n ],\n }\n\n await VersionModel.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 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","getSession","transform","createVersion","autosave","collectionSlug","createdAt","parent","publishedLocale","req","snapshot","updatedAt","versionData","VersionModel","versions","options","session","data","latest","version","fields","payload","config","collections","adapter","operation","doc","create","parentQuery","$or","$eq","updateMany","$and","_id","$ne","$lt","Date","$unset","toObject"],"mappings":"AAEA,SAASA,4BAA4B,QAA4B,UAAS;AAI1E,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,QAAQ,EACRC,SAAS,EACTC,WAAW,EACZ;IAED,MAAMC,eAAe,IAAI,CAACC,QAAQ,CAACT,eAAe;IAClD,MAAMU,UAAyB;QAC7BC,SAAS,MAAMf,WAAW,IAAI,EAAEQ;IAClC;IAEA,MAAMQ,OAAO;QACXb;QACAE;QACAY,QAAQ;QACRX;QACAC;QACAE;QACAC;QACAQ,SAASP;IACX;IAEA,MAAMQ,SAASpB,6BACb,IAAI,CAACqB,OAAO,CAACC,MAAM,EACnB,IAAI,CAACD,OAAO,CAACE,WAAW,CAAClB,eAAe,CAACiB,MAAM;IAGjDpB,UAAU;QACRsB,SAAS,IAAI;QACbP;QACAG;QACAK,WAAW;IACb;IAEA,IAAI,CAACC,IAAI,GAAG,MAAMb,aAAac,MAAM,CAAC;QAACV;KAAK,EAAEF,SAASN;IAEvD,MAAMmB,cAAc;QAClBC,KAAK;YACH;gBACEtB,QAAQ;oBACNuB,KAAKb,KAAKV,MAAM;gBAClB;YACF;SACD;IACH;IAEA,MAAMM,aAAakB,UAAU,CAC3B;QACEC,MAAM;YACJ;gBACEC,KAAK;oBACHC,KAAKR,IAAIO,GAAG;gBACd;YACF;YACAL;YACA;gBACEV,QAAQ;oBACNY,KAAK;gBACP;YACF;YACA;gBACEnB,WAAW;oBACTwB,KAAK,IAAIC,KAAKV,IAAIf,SAAS;gBAC7B;YACF;SACD;IACH,GACA;QAAE0B,QAAQ;YAAEnB,QAAQ;QAAE;IAAE,GACxBH;IAGFW,MAAMA,IAAIY,QAAQ;IAElBpC,UAAU;QACRsB,SAAS,IAAI;QACbP,MAAMS;QACNN;QACAK,WAAW;IACb;IAEA,OAAOC;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 options = {\n session: await getSession(this, req),\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\n const fields = buildVersionCollectionFields(this.payload.config, collectionConfig)\n\n transform({\n adapter: this,\n data,\n fields,\n operation: 'write',\n })\n\n let [doc] = await Model.create([data], options, req)\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","options","session","data","latest","version","fields","payload","config","operation","doc","create","parentQuery","$or","$eq","updateMany","$and","_id","$ne","$lt","Date","$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,UAAU;QACdC,SAAS,MAAMlB,WAAW,IAAI,EAAEQ;IAClC;IAEA,MAAMW,OAAO;QACXhB;QACAE;QACAe,QAAQ;QACRd;QACAC;QACAG;QACAC;QACAU,SAAST;IACX;IAEA,MAAMU,SAASxB,6BAA6B,IAAI,CAACyB,OAAO,CAACC,MAAM,EAAEX;IAEjEZ,UAAU;QACRc,SAAS,IAAI;QACbI;QACAG;QACAG,WAAW;IACb;IAEA,IAAI,CAACC,IAAI,GAAG,MAAMZ,MAAMa,MAAM,CAAC;QAACR;KAAK,EAAEF,SAAST;IAEhD,MAAMoB,cAAc;QAClBC,KAAK;YACH;gBACEvB,QAAQ;oBACNwB,KAAKX,KAAKb,MAAM;gBAClB;YACF;SACD;IACH;IAEA,MAAMQ,MAAMiB,UAAU,CACpB;QACEC,MAAM;YACJ;gBACEC,KAAK;oBACHC,KAAKR,IAAIO,GAAG;gBACd;YACF;YACAL;YACA;gBACER,QAAQ;oBACNU,KAAK;gBACP;YACF;YACA;gBACEnB,WAAW;oBACTwB,KAAK,IAAIC,KAAKV,IAAIf,SAAS;gBAC7B;YACF;SACD;IACH,GACA;QAAE0B,QAAQ;YAAEjB,QAAQ;QAAE;IAAE,GACxBH;IAGF,IAAIR,cAAc,OAAO;QACvB,OAAO;IACT;IAEAiB,MAAMA,IAAIY,QAAQ;IAElBrC,UAAU;QACRc,SAAS,IAAI;QACbI,MAAMO;QACNJ;QACAG,WAAW;IACb;IAEA,OAAOC;AACT,EAAC"}
@@ -1,3 +1,3 @@
1
- import type { DeleteMany } from 'payload';
1
+ import { type DeleteMany } from 'payload';
2
2
  export declare const deleteMany: DeleteMany;
3
3
  //# sourceMappingURL=deleteMany.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"deleteMany.d.ts","sourceRoot":"","sources":["../src/deleteMany.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAOzC,eAAO,MAAM,UAAU,EAAE,UAiBxB,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"}
@@ -1,14 +1,18 @@
1
1
  import { buildQuery } from './queries/buildQuery.js';
2
+ import { getCollection } from './utilities/getEntity.js';
2
3
  import { getSession } from './utilities/getSession.js';
3
- export const deleteMany = async function deleteMany({ collection, req, where }) {
4
- const Model = this.collections[collection];
4
+ export const deleteMany = async function deleteMany({ collection: collectionSlug, req, where }) {
5
+ const { collectionConfig, Model } = getCollection({
6
+ adapter: this,
7
+ collectionSlug
8
+ });
5
9
  const options = {
6
10
  session: await getSession(this, req)
7
11
  };
8
12
  const query = await buildQuery({
9
13
  adapter: this,
10
- collectionSlug: collection,
11
- fields: this.payload.collections[collection].config.flattenedFields,
14
+ collectionSlug,
15
+ fields: collectionConfig.flattenedFields,
12
16
  where
13
17
  });
14
18
  await Model.deleteMany(query, options);
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/deleteMany.ts"],"sourcesContent":["import type { DeleteOptions } from 'mongodb'\nimport type { DeleteMany } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { getSession } from './utilities/getSession.js'\n\nexport const deleteMany: DeleteMany = async function deleteMany(\n this: MongooseAdapter,\n { collection, req, where },\n) {\n const Model = this.collections[collection]\n const options: DeleteOptions = {\n session: await getSession(this, req),\n }\n\n const query = await buildQuery({\n adapter: this,\n collectionSlug: collection,\n fields: this.payload.collections[collection].config.flattenedFields,\n where,\n })\n\n await Model.deleteMany(query, options)\n}\n"],"names":["buildQuery","getSession","deleteMany","collection","req","where","Model","collections","options","session","query","adapter","collectionSlug","fields","payload","config","flattenedFields"],"mappings":"AAKA,SAASA,UAAU,QAAQ,0BAAyB;AACpD,SAASC,UAAU,QAAQ,4BAA2B;AAEtD,OAAO,MAAMC,aAAyB,eAAeA,WAEnD,EAAEC,UAAU,EAAEC,GAAG,EAAEC,KAAK,EAAE;IAE1B,MAAMC,QAAQ,IAAI,CAACC,WAAW,CAACJ,WAAW;IAC1C,MAAMK,UAAyB;QAC7BC,SAAS,MAAMR,WAAW,IAAI,EAAEG;IAClC;IAEA,MAAMM,QAAQ,MAAMV,WAAW;QAC7BW,SAAS,IAAI;QACbC,gBAAgBT;QAChBU,QAAQ,IAAI,CAACC,OAAO,CAACP,WAAW,CAACJ,WAAW,CAACY,MAAM,CAACC,eAAe;QACnEX;IACF;IAEA,MAAMC,MAAMJ,UAAU,CAACQ,OAAOF;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 options: DeleteOptions = {\n session: await getSession(this, req),\n }\n\n const query = await buildQuery({\n adapter: this,\n collectionSlug,\n fields: collectionConfig.flattenedFields,\n where,\n })\n\n await Model.deleteMany(query, options)\n}\n"],"names":["buildQuery","getCollection","getSession","deleteMany","collection","collectionSlug","req","where","collectionConfig","Model","adapter","options","session","query","fields","flattenedFields"],"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,UAAyB;QAC7BC,SAAS,MAAMV,WAAW,IAAI,EAAEI;IAClC;IAEA,MAAMO,QAAQ,MAAMb,WAAW;QAC7BU,SAAS,IAAI;QACbL;QACAS,QAAQN,iBAAiBO,eAAe;QACxCR;IACF;IAEA,MAAME,MAAMN,UAAU,CAACU,OAAOF;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;AASxC,eAAO,MAAM,SAAS,EAAE,SAmCvB,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"}