@payloadcms/db-mongodb 3.0.0-canary.f83d96a → 3.0.0-canary.fb04843

Sign up to get free protection for your applications and to get access to all the features.
Files changed (177) hide show
  1. package/dist/connect.d.ts.map +1 -1
  2. package/dist/connect.js +18 -4
  3. package/dist/connect.js.map +1 -1
  4. package/dist/count.d.ts.map +1 -1
  5. package/dist/count.js +9 -2
  6. package/dist/count.js.map +1 -1
  7. package/dist/countGlobalVersions.d.ts +3 -0
  8. package/dist/countGlobalVersions.d.ts.map +1 -0
  9. package/dist/countGlobalVersions.js +40 -0
  10. package/dist/countGlobalVersions.js.map +1 -0
  11. package/dist/countVersions.d.ts +3 -0
  12. package/dist/countVersions.d.ts.map +1 -0
  13. package/dist/countVersions.js +40 -0
  14. package/dist/countVersions.js.map +1 -0
  15. package/dist/create.d.ts.map +1 -1
  16. package/dist/create.js +11 -2
  17. package/dist/create.js.map +1 -1
  18. package/dist/createGlobal.d.ts.map +1 -1
  19. package/dist/createGlobal.js +11 -6
  20. package/dist/createGlobal.js.map +1 -1
  21. package/dist/createGlobalVersion.d.ts +1 -1
  22. package/dist/createGlobalVersion.d.ts.map +1 -1
  23. package/dist/createGlobalVersion.js +14 -5
  24. package/dist/createGlobalVersion.js.map +1 -1
  25. package/dist/createMigration.d.ts.map +1 -1
  26. package/dist/createMigration.js +9 -7
  27. package/dist/createMigration.js.map +1 -1
  28. package/dist/createVersion.d.ts +1 -1
  29. package/dist/createVersion.d.ts.map +1 -1
  30. package/dist/createVersion.js +32 -10
  31. package/dist/createVersion.js.map +1 -1
  32. package/dist/deleteMany.d.ts.map +1 -1
  33. package/dist/deleteMany.js +1 -1
  34. package/dist/deleteMany.js.map +1 -1
  35. package/dist/deleteOne.d.ts.map +1 -1
  36. package/dist/deleteOne.js +12 -4
  37. package/dist/deleteOne.js.map +1 -1
  38. package/dist/deleteVersions.d.ts.map +1 -1
  39. package/dist/deleteVersions.js +1 -1
  40. package/dist/deleteVersions.js.map +1 -1
  41. package/dist/exports/migration-utils.d.ts +3 -0
  42. package/dist/exports/migration-utils.d.ts.map +1 -0
  43. package/dist/exports/migration-utils.js +4 -0
  44. package/dist/exports/migration-utils.js.map +1 -0
  45. package/dist/find.d.ts.map +1 -1
  46. package/dist/find.js +35 -6
  47. package/dist/find.js.map +1 -1
  48. package/dist/findGlobal.d.ts.map +1 -1
  49. package/dist/findGlobal.js +10 -4
  50. package/dist/findGlobal.js.map +1 -1
  51. package/dist/findGlobalVersions.d.ts.map +1 -1
  52. package/dist/findGlobalVersions.js +18 -7
  53. package/dist/findGlobalVersions.js.map +1 -1
  54. package/dist/findOne.d.ts.map +1 -1
  55. package/dist/findOne.js +28 -4
  56. package/dist/findOne.js.map +1 -1
  57. package/dist/findVersions.d.ts.map +1 -1
  58. package/dist/findVersions.js +17 -6
  59. package/dist/findVersions.js.map +1 -1
  60. package/dist/index.d.ts +59 -10
  61. package/dist/index.d.ts.map +1 -1
  62. package/dist/index.js +18 -7
  63. package/dist/index.js.map +1 -1
  64. package/dist/init.d.ts.map +1 -1
  65. package/dist/init.js +18 -16
  66. package/dist/init.js.map +1 -1
  67. package/dist/migrateFresh.js.map +1 -1
  68. package/dist/models/buildCollectionSchema.d.ts +1 -2
  69. package/dist/models/buildCollectionSchema.d.ts.map +1 -1
  70. package/dist/models/buildCollectionSchema.js +16 -4
  71. package/dist/models/buildCollectionSchema.js.map +1 -1
  72. package/dist/models/buildGlobalModel.js +2 -2
  73. package/dist/models/buildGlobalModel.js.map +1 -1
  74. package/dist/models/buildSchema.d.ts +1 -2
  75. package/dist/models/buildSchema.d.ts.map +1 -1
  76. package/dist/models/buildSchema.js +116 -23
  77. package/dist/models/buildSchema.js.map +1 -1
  78. package/dist/predefinedMigrations/migrateRelationshipsV2_V3.d.ts +6 -0
  79. package/dist/predefinedMigrations/migrateRelationshipsV2_V3.d.ts.map +1 -0
  80. package/dist/predefinedMigrations/migrateRelationshipsV2_V3.js +141 -0
  81. package/dist/predefinedMigrations/migrateRelationshipsV2_V3.js.map +1 -0
  82. package/dist/predefinedMigrations/migrateVersionsV1_V2.d.ts +5 -0
  83. package/dist/predefinedMigrations/migrateVersionsV1_V2.d.ts.map +1 -0
  84. package/dist/predefinedMigrations/migrateVersionsV1_V2.js +107 -0
  85. package/dist/predefinedMigrations/migrateVersionsV1_V2.js.map +1 -0
  86. package/dist/predefinedMigrations/relationships-v2-v3.d.ts +4 -0
  87. package/dist/predefinedMigrations/relationships-v2-v3.d.ts.map +1 -0
  88. package/dist/predefinedMigrations/relationships-v2-v3.js +9 -0
  89. package/dist/predefinedMigrations/relationships-v2-v3.js.map +1 -0
  90. package/dist/predefinedMigrations/versions-v1-v2.d.ts +4 -0
  91. package/dist/predefinedMigrations/versions-v1-v2.d.ts.map +1 -0
  92. package/dist/predefinedMigrations/versions-v1-v2.js +5 -95
  93. package/dist/predefinedMigrations/versions-v1-v2.js.map +1 -1
  94. package/dist/queries/buildAndOrConditions.d.ts.map +1 -1
  95. package/dist/queries/buildAndOrConditions.js +0 -2
  96. package/dist/queries/buildAndOrConditions.js.map +1 -1
  97. package/dist/queries/buildQuery.d.ts +2 -2
  98. package/dist/queries/buildQuery.d.ts.map +1 -1
  99. package/dist/queries/buildQuery.js +1 -2
  100. package/dist/queries/buildQuery.js.map +1 -1
  101. package/dist/queries/buildSearchParams.d.ts.map +1 -1
  102. package/dist/queries/buildSearchParams.js +28 -18
  103. package/dist/queries/buildSearchParams.js.map +1 -1
  104. package/dist/queries/buildSortParam.d.ts +2 -2
  105. package/dist/queries/buildSortParam.d.ts.map +1 -1
  106. package/dist/queries/buildSortParam.js +26 -17
  107. package/dist/queries/buildSortParam.js.map +1 -1
  108. package/dist/queries/getLocalizedSortProperty.spec.js +43 -43
  109. package/dist/queries/getLocalizedSortProperty.spec.js.map +1 -1
  110. package/dist/queries/parseParams.d.ts.map +1 -1
  111. package/dist/queries/parseParams.js +7 -5
  112. package/dist/queries/parseParams.js.map +1 -1
  113. package/dist/queries/sanitizeQueryValue.d.ts.map +1 -1
  114. package/dist/queries/sanitizeQueryValue.js +144 -27
  115. package/dist/queries/sanitizeQueryValue.js.map +1 -1
  116. package/dist/queryDrafts.d.ts.map +1 -1
  117. package/dist/queryDrafts.js +37 -10
  118. package/dist/queryDrafts.js.map +1 -1
  119. package/dist/transactions/beginTransaction.d.ts.map +1 -1
  120. package/dist/transactions/beginTransaction.js +2 -0
  121. package/dist/transactions/beginTransaction.js.map +1 -1
  122. package/dist/transactions/commitTransaction.d.ts.map +1 -1
  123. package/dist/transactions/commitTransaction.js +3 -0
  124. package/dist/transactions/commitTransaction.js.map +1 -1
  125. package/dist/transactions/rollbackTransaction.d.ts.map +1 -1
  126. package/dist/transactions/rollbackTransaction.js +13 -7
  127. package/dist/transactions/rollbackTransaction.js.map +1 -1
  128. package/dist/types.d.ts +7 -4
  129. package/dist/types.d.ts.map +1 -1
  130. package/dist/types.js.map +1 -1
  131. package/dist/updateGlobal.d.ts.map +1 -1
  132. package/dist/updateGlobal.js +18 -5
  133. package/dist/updateGlobal.js.map +1 -1
  134. package/dist/updateGlobalVersion.d.ts +2 -2
  135. package/dist/updateGlobalVersion.d.ts.map +1 -1
  136. package/dist/updateGlobalVersion.js +19 -5
  137. package/dist/updateGlobalVersion.js.map +1 -1
  138. package/dist/updateOne.d.ts.map +1 -1
  139. package/dist/updateOne.js +19 -5
  140. package/dist/updateOne.js.map +1 -1
  141. package/dist/updateVersion.d.ts +1 -1
  142. package/dist/updateVersion.d.ts.map +1 -1
  143. package/dist/updateVersion.js +18 -4
  144. package/dist/updateVersion.js.map +1 -1
  145. package/dist/upsert.d.ts +3 -0
  146. package/dist/upsert.d.ts.map +1 -0
  147. package/dist/upsert.js +15 -0
  148. package/dist/upsert.js.map +1 -0
  149. package/dist/utilities/buildJoinAggregation.d.ts +18 -0
  150. package/dist/utilities/buildJoinAggregation.d.ts.map +1 -0
  151. package/dist/utilities/buildJoinAggregation.js +159 -0
  152. package/dist/utilities/buildJoinAggregation.js.map +1 -0
  153. package/dist/utilities/buildProjectionFromSelect.d.ts +8 -0
  154. package/dist/utilities/buildProjectionFromSelect.d.ts.map +1 -0
  155. package/dist/utilities/buildProjectionFromSelect.js +171 -0
  156. package/dist/utilities/buildProjectionFromSelect.js.map +1 -0
  157. package/dist/utilities/getDBName.d.ts.map +1 -1
  158. package/dist/utilities/getDBName.js +3 -1
  159. package/dist/utilities/getDBName.js.map +1 -1
  160. package/dist/utilities/handleError.js +2 -2
  161. package/dist/utilities/handleError.js.map +1 -1
  162. package/dist/utilities/sanitizeInternalFields.d.ts +1 -2
  163. package/dist/utilities/sanitizeInternalFields.d.ts.map +1 -1
  164. package/dist/utilities/sanitizeInternalFields.js +1 -2
  165. package/dist/utilities/sanitizeInternalFields.js.map +1 -1
  166. package/dist/utilities/sanitizeRelationshipIDs.d.ts +9 -0
  167. package/dist/utilities/sanitizeRelationshipIDs.d.ts.map +1 -0
  168. package/dist/utilities/sanitizeRelationshipIDs.js +115 -0
  169. package/dist/utilities/sanitizeRelationshipIDs.js.map +1 -0
  170. package/dist/utilities/sanitizeRelationshipIDs.spec.js +383 -0
  171. package/dist/utilities/sanitizeRelationshipIDs.spec.js.map +1 -0
  172. package/dist/withSession.d.ts +3 -2
  173. package/dist/withSession.d.ts.map +1 -1
  174. package/dist/withSession.js +10 -4
  175. package/dist/withSession.js.map +1 -1
  176. package/license.md +22 -0
  177. package/package.json +24 -11
package/dist/deleteOne.js CHANGED
@@ -1,13 +1,21 @@
1
- import sanitizeInternalFields from './utilities/sanitizeInternalFields.js';
1
+ import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
2
+ import { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js';
2
3
  import { withSession } from './withSession.js';
3
- export const deleteOne = async function deleteOne({ collection, req = {}, where }) {
4
+ export const deleteOne = async function deleteOne({ collection, req = {}, select, where }) {
4
5
  const Model = this.collections[collection];
5
- const options = withSession(this, req.transactionID);
6
+ const options = await withSession(this, req);
6
7
  const query = await Model.buildQuery({
7
8
  payload: this.payload,
8
9
  where
9
10
  });
10
- const doc = await Model.findOneAndDelete(query, options).lean();
11
+ const doc = await Model.findOneAndDelete(query, {
12
+ ...options,
13
+ projection: buildProjectionFromSelect({
14
+ adapter: this,
15
+ fields: this.payload.collections[collection].config.fields,
16
+ select
17
+ })
18
+ }).lean();
11
19
  let result = JSON.parse(JSON.stringify(doc));
12
20
  // custom id type reset
13
21
  result.id = result._id;
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/deleteOne.ts"],"sourcesContent":["import type { DeleteOne, Document, PayloadRequestWithData } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport sanitizeInternalFields from './utilities/sanitizeInternalFields.js'\nimport { withSession } from './withSession.js'\n\nexport const deleteOne: DeleteOne = async function deleteOne(\n this: MongooseAdapter,\n { collection, req = {} as PayloadRequestWithData, where },\n) {\n const Model = this.collections[collection]\n const options = withSession(this, req.transactionID)\n\n const query = await Model.buildQuery({\n payload: this.payload,\n where,\n })\n\n const doc = await Model.findOneAndDelete(query, options).lean()\n\n let result: Document = JSON.parse(JSON.stringify(doc))\n\n // custom id type reset\n result.id = result._id\n result = sanitizeInternalFields(result)\n\n return result\n}\n"],"names":["sanitizeInternalFields","withSession","deleteOne","collection","req","where","Model","collections","options","transactionID","query","buildQuery","payload","doc","findOneAndDelete","lean","result","JSON","parse","stringify","id","_id"],"mappings":"AAIA,OAAOA,4BAA4B,wCAAuC;AAC1E,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,YAAuB,eAAeA,UAEjD,EAAEC,UAAU,EAAEC,MAAM,CAAC,CAA2B,EAAEC,KAAK,EAAE;IAEzD,MAAMC,QAAQ,IAAI,CAACC,WAAW,CAACJ,WAAW;IAC1C,MAAMK,UAAUP,YAAY,IAAI,EAAEG,IAAIK,aAAa;IAEnD,MAAMC,QAAQ,MAAMJ,MAAMK,UAAU,CAAC;QACnCC,SAAS,IAAI,CAACA,OAAO;QACrBP;IACF;IAEA,MAAMQ,MAAM,MAAMP,MAAMQ,gBAAgB,CAACJ,OAAOF,SAASO,IAAI;IAE7D,IAAIC,SAAmBC,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACN;IAEjD,uBAAuB;IACvBG,OAAOI,EAAE,GAAGJ,OAAOK,GAAG;IACtBL,SAAShB,uBAAuBgB;IAEhC,OAAOA;AACT,EAAC"}
1
+ {"version":3,"sources":["../src/deleteOne.ts"],"sourcesContent":["import type { DeleteOne, Document, PayloadRequest } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js'\nimport { withSession } from './withSession.js'\n\nexport const deleteOne: DeleteOne = async function deleteOne(\n this: MongooseAdapter,\n { collection, req = {} as PayloadRequest, select, where },\n) {\n const Model = this.collections[collection]\n const options = await withSession(this, req)\n\n const query = await Model.buildQuery({\n payload: this.payload,\n where,\n })\n\n const doc = await Model.findOneAndDelete(query, {\n ...options,\n projection: buildProjectionFromSelect({\n adapter: this,\n fields: this.payload.collections[collection].config.fields,\n select,\n }),\n }).lean()\n\n let result: Document = JSON.parse(JSON.stringify(doc))\n\n // custom id type reset\n result.id = result._id\n result = sanitizeInternalFields(result)\n\n return result\n}\n"],"names":["buildProjectionFromSelect","sanitizeInternalFields","withSession","deleteOne","collection","req","select","where","Model","collections","options","query","buildQuery","payload","doc","findOneAndDelete","projection","adapter","fields","config","lean","result","JSON","parse","stringify","id","_id"],"mappings":"AAIA,SAASA,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,sBAAsB,QAAQ,wCAAuC;AAC9E,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,YAAuB,eAAeA,UAEjD,EAAEC,UAAU,EAAEC,MAAM,CAAC,CAAmB,EAAEC,MAAM,EAAEC,KAAK,EAAE;IAEzD,MAAMC,QAAQ,IAAI,CAACC,WAAW,CAACL,WAAW;IAC1C,MAAMM,UAAU,MAAMR,YAAY,IAAI,EAAEG;IAExC,MAAMM,QAAQ,MAAMH,MAAMI,UAAU,CAAC;QACnCC,SAAS,IAAI,CAACA,OAAO;QACrBN;IACF;IAEA,MAAMO,MAAM,MAAMN,MAAMO,gBAAgB,CAACJ,OAAO;QAC9C,GAAGD,OAAO;QACVM,YAAYhB,0BAA0B;YACpCiB,SAAS,IAAI;YACbC,QAAQ,IAAI,CAACL,OAAO,CAACJ,WAAW,CAACL,WAAW,CAACe,MAAM,CAACD,MAAM;YAC1DZ;QACF;IACF,GAAGc,IAAI;IAEP,IAAIC,SAAmBC,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACV;IAEjD,uBAAuB;IACvBO,OAAOI,EAAE,GAAGJ,OAAOK,GAAG;IACtBL,SAASpB,uBAAuBoB;IAEhC,OAAOA;AACT,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"deleteVersions.d.ts","sourceRoot":"","sources":["../src/deleteVersions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAA0B,MAAM,SAAS,CAAA;AAMrE,eAAO,MAAM,cAAc,EAAE,cAiB5B,CAAA"}
1
+ {"version":3,"file":"deleteVersions.d.ts","sourceRoot":"","sources":["../src/deleteVersions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAkB,MAAM,SAAS,CAAA;AAM7D,eAAO,MAAM,cAAc,EAAE,cAiB5B,CAAA"}
@@ -2,7 +2,7 @@ import { withSession } from './withSession.js';
2
2
  export const deleteVersions = async function deleteVersions({ collection, locale, req = {}, where }) {
3
3
  const VersionsModel = this.versions[collection];
4
4
  const options = {
5
- ...withSession(this, req.transactionID),
5
+ ...await withSession(this, req),
6
6
  lean: true
7
7
  };
8
8
  const query = await VersionsModel.buildQuery({
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/deleteVersions.ts"],"sourcesContent":["import type { DeleteVersions, PayloadRequestWithData } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { withSession } from './withSession.js'\n\nexport const deleteVersions: DeleteVersions = async function deleteVersions(\n this: MongooseAdapter,\n { collection, locale, req = {} as PayloadRequestWithData, where },\n) {\n const VersionsModel = this.versions[collection]\n const options = {\n ...withSession(this, req.transactionID),\n lean: true,\n }\n\n const query = await VersionsModel.buildQuery({\n locale,\n payload: this.payload,\n where,\n })\n\n await VersionsModel.deleteMany(query, options)\n}\n"],"names":["withSession","deleteVersions","collection","locale","req","where","VersionsModel","versions","options","transactionID","lean","query","buildQuery","payload","deleteMany"],"mappings":"AAIA,SAASA,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,iBAAiC,eAAeA,eAE3D,EAAEC,UAAU,EAAEC,MAAM,EAAEC,MAAM,CAAC,CAA2B,EAAEC,KAAK,EAAE;IAEjE,MAAMC,gBAAgB,IAAI,CAACC,QAAQ,CAACL,WAAW;IAC/C,MAAMM,UAAU;QACd,GAAGR,YAAY,IAAI,EAAEI,IAAIK,aAAa,CAAC;QACvCC,MAAM;IACR;IAEA,MAAMC,QAAQ,MAAML,cAAcM,UAAU,CAAC;QAC3CT;QACAU,SAAS,IAAI,CAACA,OAAO;QACrBR;IACF;IAEA,MAAMC,cAAcQ,UAAU,CAACH,OAAOH;AACxC,EAAC"}
1
+ {"version":3,"sources":["../src/deleteVersions.ts"],"sourcesContent":["import type { DeleteVersions, PayloadRequest } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { withSession } from './withSession.js'\n\nexport const deleteVersions: DeleteVersions = async function deleteVersions(\n this: MongooseAdapter,\n { collection, locale, req = {} as PayloadRequest, where },\n) {\n const VersionsModel = this.versions[collection]\n const options = {\n ...(await withSession(this, req)),\n lean: true,\n }\n\n const query = await VersionsModel.buildQuery({\n locale,\n payload: this.payload,\n where,\n })\n\n await VersionsModel.deleteMany(query, options)\n}\n"],"names":["withSession","deleteVersions","collection","locale","req","where","VersionsModel","versions","options","lean","query","buildQuery","payload","deleteMany"],"mappings":"AAIA,SAASA,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,iBAAiC,eAAeA,eAE3D,EAAEC,UAAU,EAAEC,MAAM,EAAEC,MAAM,CAAC,CAAmB,EAAEC,KAAK,EAAE;IAEzD,MAAMC,gBAAgB,IAAI,CAACC,QAAQ,CAACL,WAAW;IAC/C,MAAMM,UAAU;QACd,GAAI,MAAMR,YAAY,IAAI,EAAEI,IAAI;QAChCK,MAAM;IACR;IAEA,MAAMC,QAAQ,MAAMJ,cAAcK,UAAU,CAAC;QAC3CR;QACAS,SAAS,IAAI,CAACA,OAAO;QACrBP;IACF;IAEA,MAAMC,cAAcO,UAAU,CAACH,OAAOF;AACxC,EAAC"}
@@ -0,0 +1,3 @@
1
+ export { migrateRelationshipsV2_V3 } from '../predefinedMigrations/migrateRelationshipsV2_V3.js';
2
+ export { migrateVersionsV1_V2 } from '../predefinedMigrations/migrateVersionsV1_V2.js';
3
+ //# sourceMappingURL=migration-utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migration-utils.d.ts","sourceRoot":"","sources":["../../src/exports/migration-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,sDAAsD,CAAA;AAChG,OAAO,EAAE,oBAAoB,EAAE,MAAM,iDAAiD,CAAA"}
@@ -0,0 +1,4 @@
1
+ export { migrateRelationshipsV2_V3 } from '../predefinedMigrations/migrateRelationshipsV2_V3.js';
2
+ export { migrateVersionsV1_V2 } from '../predefinedMigrations/migrateVersionsV1_V2.js';
3
+
4
+ //# sourceMappingURL=migration-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/exports/migration-utils.ts"],"sourcesContent":["export { migrateRelationshipsV2_V3 } from '../predefinedMigrations/migrateRelationshipsV2_V3.js'\nexport { migrateVersionsV1_V2 } from '../predefinedMigrations/migrateVersionsV1_V2.js'\n"],"names":["migrateRelationshipsV2_V3","migrateVersionsV1_V2"],"mappings":"AAAA,SAASA,yBAAyB,QAAQ,uDAAsD;AAChG,SAASC,oBAAoB,QAAQ,kDAAiD"}
@@ -1 +1 @@
1
- {"version":3,"file":"find.d.ts","sourceRoot":"","sources":["../src/find.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAA0B,MAAM,SAAS,CAAA;AAU3D,eAAO,MAAM,IAAI,EAAE,IA2FlB,CAAA"}
1
+ {"version":3,"file":"find.d.ts","sourceRoot":"","sources":["../src/find.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAkB,MAAM,SAAS,CAAA;AAYnD,eAAO,MAAM,IAAI,EAAE,IA6HlB,CAAA"}
package/dist/find.js CHANGED
@@ -1,11 +1,13 @@
1
1
  import { flattenWhereToOperators } from 'payload';
2
2
  import { buildSortParam } from './queries/buildSortParam.js';
3
- import sanitizeInternalFields from './utilities/sanitizeInternalFields.js';
3
+ import { buildJoinAggregation } from './utilities/buildJoinAggregation.js';
4
+ import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
5
+ import { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js';
4
6
  import { withSession } from './withSession.js';
5
- export const find = async function find({ collection, limit, locale, page, pagination, req = {}, sort: sortArg, where }) {
7
+ export const find = async function find({ collection, joins = {}, limit = 0, locale, page, pagination, projection, req = {}, select, sort: sortArg, where }) {
6
8
  const Model = this.collections[collection];
7
9
  const collectionConfig = this.payload.collections[collection].config;
8
- const options = withSession(this, req.transactionID);
10
+ const options = await withSession(this, req);
9
11
  let hasNearConstraint = false;
10
12
  if (where) {
11
13
  const constraints = flattenWhereToOperators(where);
@@ -29,15 +31,29 @@ export const find = async function find({ collection, limit, locale, page, pagin
29
31
  // useEstimatedCount is faster, but not accurate, as it ignores any filters. It is thus set to true if there are no filters.
30
32
  const useEstimatedCount = hasNearConstraint || !query || Object.keys(query).length === 0;
31
33
  const paginationOptions = {
32
- forceCountFn: hasNearConstraint,
33
34
  lean: true,
34
35
  leanWithId: true,
35
36
  options,
36
37
  page,
37
38
  pagination,
39
+ projection,
38
40
  sort,
39
41
  useEstimatedCount
40
42
  };
43
+ if (select) {
44
+ paginationOptions.projection = buildProjectionFromSelect({
45
+ adapter: this,
46
+ fields: collectionConfig.fields,
47
+ select
48
+ });
49
+ }
50
+ if (this.collation) {
51
+ const defaultLocale = 'en';
52
+ paginationOptions.collation = {
53
+ locale: locale && locale !== 'all' && locale !== '*' ? locale : defaultLocale,
54
+ ...this.collation
55
+ };
56
+ }
41
57
  if (!useEstimatedCount && Object.keys(query).length === 0 && this.disableIndexHints !== true) {
42
58
  // Improve the performance of the countDocuments query which is used if useEstimatedCount is set to false by adding
43
59
  // a hint. By default, if no hint is provided, MongoDB does not use an indexed field to count the returned documents,
@@ -61,12 +77,25 @@ export const find = async function find({ collection, limit, locale, page, pagin
61
77
  paginationOptions.pagination = false;
62
78
  }
63
79
  }
64
- const result = await Model.paginate(query, paginationOptions);
80
+ let result;
81
+ const aggregate = await buildJoinAggregation({
82
+ adapter: this,
83
+ collection,
84
+ collectionConfig,
85
+ joins,
86
+ locale,
87
+ query
88
+ });
89
+ // build join aggregation
90
+ if (aggregate) {
91
+ result = await Model.aggregatePaginate(Model.aggregate(aggregate), paginationOptions);
92
+ } else {
93
+ result = await Model.paginate(query, paginationOptions);
94
+ }
65
95
  const docs = JSON.parse(JSON.stringify(result.docs));
66
96
  return {
67
97
  ...result,
68
98
  docs: docs.map((doc)=>{
69
- // eslint-disable-next-line no-param-reassign
70
99
  doc.id = doc._id;
71
100
  return sanitizeInternalFields(doc);
72
101
  })
package/dist/find.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/find.ts"],"sourcesContent":["import type { PaginateOptions } from 'mongoose'\nimport type { Find, PayloadRequestWithData } from 'payload'\n\nimport { flattenWhereToOperators } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildSortParam } from './queries/buildSortParam.js'\nimport sanitizeInternalFields from './utilities/sanitizeInternalFields.js'\nimport { withSession } from './withSession.js'\n\nexport const find: Find = async function find(\n this: MongooseAdapter,\n {\n collection,\n limit,\n locale,\n page,\n pagination,\n req = {} as PayloadRequestWithData,\n sort: sortArg,\n where,\n },\n) {\n const Model = this.collections[collection]\n const collectionConfig = this.payload.collections[collection].config\n const options = withSession(this, req.transactionID)\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 let sort\n if (!hasNearConstraint) {\n sort = buildSortParam({\n config: this.payload.config,\n fields: collectionConfig.fields,\n locale,\n sort: sortArg || collectionConfig.defaultSort,\n timestamps: true,\n })\n }\n\n const query = await Model.buildQuery({\n locale,\n payload: this.payload,\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 const paginationOptions: PaginateOptions = {\n forceCountFn: hasNearConstraint,\n lean: true,\n leanWithId: true,\n options,\n page,\n pagination,\n sort,\n useEstimatedCount,\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 paginationOptions.useCustomCountFn = () => {\n return Promise.resolve(\n Model.countDocuments(query, {\n ...options,\n hint: { _id: 1 },\n }),\n )\n }\n }\n\n if (limit >= 0) {\n paginationOptions.limit = limit\n // limit must also be set here, it's ignored when pagination is false\n paginationOptions.options.limit = limit\n\n // Disable pagination if limit is 0\n if (limit === 0) {\n paginationOptions.pagination = false\n }\n }\n\n const result = await Model.paginate(query, paginationOptions)\n const docs = JSON.parse(JSON.stringify(result.docs))\n\n return {\n ...result,\n docs: docs.map((doc) => {\n // eslint-disable-next-line no-param-reassign\n doc.id = doc._id\n return sanitizeInternalFields(doc)\n }),\n }\n}\n"],"names":["flattenWhereToOperators","buildSortParam","sanitizeInternalFields","withSession","find","collection","limit","locale","page","pagination","req","sort","sortArg","where","Model","collections","collectionConfig","payload","config","options","transactionID","hasNearConstraint","constraints","some","prop","Object","keys","key","fields","defaultSort","timestamps","query","buildQuery","useEstimatedCount","length","paginationOptions","forceCountFn","lean","leanWithId","disableIndexHints","useCustomCountFn","Promise","resolve","countDocuments","hint","_id","result","paginate","docs","JSON","parse","stringify","map","doc","id"],"mappings":"AAGA,SAASA,uBAAuB,QAAQ,UAAS;AAIjD,SAASC,cAAc,QAAQ,8BAA6B;AAC5D,OAAOC,4BAA4B,wCAAuC;AAC1E,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,OAAa,eAAeA,KAEvC,EACEC,UAAU,EACVC,KAAK,EACLC,MAAM,EACNC,IAAI,EACJC,UAAU,EACVC,MAAM,CAAC,CAA2B,EAClCC,MAAMC,OAAO,EACbC,KAAK,EACN;IAED,MAAMC,QAAQ,IAAI,CAACC,WAAW,CAACV,WAAW;IAC1C,MAAMW,mBAAmB,IAAI,CAACC,OAAO,CAACF,WAAW,CAACV,WAAW,CAACa,MAAM;IACpE,MAAMC,UAAUhB,YAAY,IAAI,EAAEO,IAAIU,aAAa;IAEnD,IAAIC,oBAAoB;IAExB,IAAIR,OAAO;QACT,MAAMS,cAActB,wBAAwBa;QAC5CQ,oBAAoBC,YAAYC,IAAI,CAAC,CAACC,OAASC,OAAOC,IAAI,CAACF,MAAMD,IAAI,CAAC,CAACI,MAAQA,QAAQ;IACzF;IAEA,IAAIhB;IACJ,IAAI,CAACU,mBAAmB;QACtBV,OAAOV,eAAe;YACpBiB,QAAQ,IAAI,CAACD,OAAO,CAACC,MAAM;YAC3BU,QAAQZ,iBAAiBY,MAAM;YAC/BrB;YACAI,MAAMC,WAAWI,iBAAiBa,WAAW;YAC7CC,YAAY;QACd;IACF;IAEA,MAAMC,QAAQ,MAAMjB,MAAMkB,UAAU,CAAC;QACnCzB;QACAU,SAAS,IAAI,CAACA,OAAO;QACrBJ;IACF;IAEA,4HAA4H;IAC5H,MAAMoB,oBAAoBZ,qBAAqB,CAACU,SAASN,OAAOC,IAAI,CAACK,OAAOG,MAAM,KAAK;IACvF,MAAMC,oBAAqC;QACzCC,cAAcf;QACdgB,MAAM;QACNC,YAAY;QACZnB;QACAX;QACAC;QACAE;QACAsB;IACF;IAEA,IAAI,CAACA,qBAAqBR,OAAOC,IAAI,CAACK,OAAOG,MAAM,KAAK,KAAK,IAAI,CAACK,iBAAiB,KAAK,MAAM;QAC5F,mHAAmH;QACnH,qHAAqH;QACrH,mHAAmH;QACnH,4BAA4B;QAC5BJ,kBAAkBK,gBAAgB,GAAG;YACnC,OAAOC,QAAQC,OAAO,CACpB5B,MAAM6B,cAAc,CAACZ,OAAO;gBAC1B,GAAGZ,OAAO;gBACVyB,MAAM;oBAAEC,KAAK;gBAAE;YACjB;QAEJ;IACF;IAEA,IAAIvC,SAAS,GAAG;QACd6B,kBAAkB7B,KAAK,GAAGA;QAC1B,qEAAqE;QACrE6B,kBAAkBhB,OAAO,CAACb,KAAK,GAAGA;QAElC,mCAAmC;QACnC,IAAIA,UAAU,GAAG;YACf6B,kBAAkB1B,UAAU,GAAG;QACjC;IACF;IAEA,MAAMqC,SAAS,MAAMhC,MAAMiC,QAAQ,CAAChB,OAAOI;IAC3C,MAAMa,OAAOC,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACL,OAAOE,IAAI;IAElD,OAAO;QACL,GAAGF,MAAM;QACTE,MAAMA,KAAKI,GAAG,CAAC,CAACC;YACd,6CAA6C;YAC7CA,IAAIC,EAAE,GAAGD,IAAIR,GAAG;YAChB,OAAO3C,uBAAuBmD;QAChC;IACF;AACF,EAAC"}
1
+ {"version":3,"sources":["../src/find.ts"],"sourcesContent":["import type { PaginateOptions } from 'mongoose'\nimport type { Find, PayloadRequest } from 'payload'\n\nimport { flattenWhereToOperators } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildSortParam } from './queries/buildSortParam.js'\nimport { buildJoinAggregation } from './utilities/buildJoinAggregation.js'\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js'\nimport { withSession } from './withSession.js'\n\nexport const find: Find = async function find(\n this: MongooseAdapter,\n {\n collection,\n joins = {},\n limit = 0,\n locale,\n page,\n pagination,\n projection,\n req = {} as PayloadRequest,\n select,\n sort: sortArg,\n where,\n },\n) {\n const Model = this.collections[collection]\n const collectionConfig = this.payload.collections[collection].config\n const options = await withSession(this, req)\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 let sort\n if (!hasNearConstraint) {\n sort = buildSortParam({\n config: this.payload.config,\n fields: collectionConfig.fields,\n locale,\n sort: sortArg || collectionConfig.defaultSort,\n timestamps: true,\n })\n }\n\n const query = await Model.buildQuery({\n locale,\n payload: this.payload,\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 const paginationOptions: PaginateOptions = {\n lean: true,\n leanWithId: true,\n options,\n page,\n pagination,\n projection,\n sort,\n useEstimatedCount,\n }\n\n if (select) {\n paginationOptions.projection = buildProjectionFromSelect({\n adapter: this,\n fields: collectionConfig.fields,\n select,\n })\n }\n\n if (this.collation) {\n const defaultLocale = 'en'\n paginationOptions.collation = {\n locale: locale && locale !== 'all' && locale !== '*' ? locale : defaultLocale,\n ...this.collation,\n }\n }\n\n if (!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 paginationOptions.useCustomCountFn = () => {\n return Promise.resolve(\n Model.countDocuments(query, {\n ...options,\n hint: { _id: 1 },\n }),\n )\n }\n }\n\n if (limit >= 0) {\n paginationOptions.limit = limit\n // limit must also be set here, it's ignored when pagination is false\n paginationOptions.options.limit = limit\n\n // Disable pagination if limit is 0\n if (limit === 0) {\n paginationOptions.pagination = false\n }\n }\n\n let result\n\n const aggregate = await buildJoinAggregation({\n adapter: this,\n collection,\n collectionConfig,\n joins,\n locale,\n query,\n })\n // build join aggregation\n if (aggregate) {\n result = await Model.aggregatePaginate(Model.aggregate(aggregate), paginationOptions)\n } else {\n result = await Model.paginate(query, paginationOptions)\n }\n\n const docs = JSON.parse(JSON.stringify(result.docs))\n\n return {\n ...result,\n docs: docs.map((doc) => {\n doc.id = doc._id\n return sanitizeInternalFields(doc)\n }),\n }\n}\n"],"names":["flattenWhereToOperators","buildSortParam","buildJoinAggregation","buildProjectionFromSelect","sanitizeInternalFields","withSession","find","collection","joins","limit","locale","page","pagination","projection","req","select","sort","sortArg","where","Model","collections","collectionConfig","payload","config","options","hasNearConstraint","constraints","some","prop","Object","keys","key","fields","defaultSort","timestamps","query","buildQuery","useEstimatedCount","length","paginationOptions","lean","leanWithId","adapter","collation","defaultLocale","disableIndexHints","useCustomCountFn","Promise","resolve","countDocuments","hint","_id","result","aggregate","aggregatePaginate","paginate","docs","JSON","parse","stringify","map","doc","id"],"mappings":"AAGA,SAASA,uBAAuB,QAAQ,UAAS;AAIjD,SAASC,cAAc,QAAQ,8BAA6B;AAC5D,SAASC,oBAAoB,QAAQ,sCAAqC;AAC1E,SAASC,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,sBAAsB,QAAQ,wCAAuC;AAC9E,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,OAAa,eAAeA,KAEvC,EACEC,UAAU,EACVC,QAAQ,CAAC,CAAC,EACVC,QAAQ,CAAC,EACTC,MAAM,EACNC,IAAI,EACJC,UAAU,EACVC,UAAU,EACV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E,UA+BxB,CAAA"}
1
+ {"version":3,"file":"findGlobal.d.ts","sourceRoot":"","sources":["../src/findGlobal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAkB,MAAM,SAAS,CAAA;AAUzD,eAAO,MAAM,UAAU,EAAE,UAoCxB,CAAA"}
@@ -1,11 +1,17 @@
1
1
  import { combineQueries } from 'payload';
2
- import sanitizeInternalFields from './utilities/sanitizeInternalFields.js';
2
+ import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
3
+ import { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js';
3
4
  import { withSession } from './withSession.js';
4
- export const findGlobal = async function findGlobal({ slug, locale, req = {}, where }) {
5
+ export const findGlobal = async function findGlobal({ slug, locale, req = {}, select, where }) {
5
6
  const Model = this.globals;
6
7
  const options = {
7
- ...withSession(this, req.transactionID),
8
- lean: true
8
+ ...await withSession(this, req),
9
+ lean: true,
10
+ select: buildProjectionFromSelect({
11
+ adapter: this,
12
+ fields: this.payload.globals.config.find((each)=>each.slug === slug).fields,
13
+ select
14
+ })
9
15
  };
10
16
  const query = await Model.buildQuery({
11
17
  globalSlug: slug,
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/findGlobal.ts"],"sourcesContent":["import type { FindGlobal, PayloadRequestWithData } from 'payload'\n\nimport { combineQueries } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport sanitizeInternalFields from './utilities/sanitizeInternalFields.js'\nimport { withSession } from './withSession.js'\n\nexport const findGlobal: FindGlobal = async function findGlobal(\n this: MongooseAdapter,\n { slug, locale, req = {} as PayloadRequestWithData, where },\n) {\n const Model = this.globals\n const options = {\n ...withSession(this, req.transactionID),\n lean: true,\n }\n\n const query = await Model.buildQuery({\n globalSlug: slug,\n locale,\n payload: this.payload,\n where: combineQueries({ globalType: { equals: slug } }, where),\n })\n\n let doc = (await Model.findOne(query, {}, options)) as any\n\n if (!doc) {\n return null\n }\n if (doc._id) {\n doc.id = doc._id\n delete doc._id\n }\n\n doc = JSON.parse(JSON.stringify(doc))\n doc = sanitizeInternalFields(doc)\n\n return doc\n}\n"],"names":["combineQueries","sanitizeInternalFields","withSession","findGlobal","slug","locale","req","where","Model","globals","options","transactionID","lean","query","buildQuery","globalSlug","payload","globalType","equals","doc","findOne","_id","id","JSON","parse","stringify"],"mappings":"AAEA,SAASA,cAAc,QAAQ,UAAS;AAIxC,OAAOC,4BAA4B,wCAAuC;AAC1E,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,aAAyB,eAAeA,WAEnD,EAAEC,IAAI,EAAEC,MAAM,EAAEC,MAAM,CAAC,CAA2B,EAAEC,KAAK,EAAE;IAE3D,MAAMC,QAAQ,IAAI,CAACC,OAAO;IAC1B,MAAMC,UAAU;QACd,GAAGR,YAAY,IAAI,EAAEI,IAAIK,aAAa,CAAC;QACvCC,MAAM;IACR;IAEA,MAAMC,QAAQ,MAAML,MAAMM,UAAU,CAAC;QACnCC,YAAYX;QACZC;QACAW,SAAS,IAAI,CAACA,OAAO;QACrBT,OAAOP,eAAe;YAAEiB,YAAY;gBAAEC,QAAQd;YAAK;QAAE,GAAGG;IAC1D;IAEA,IAAIY,MAAO,MAAMX,MAAMY,OAAO,CAACP,OAAO,CAAC,GAAGH;IAE1C,IAAI,CAACS,KAAK;QACR,OAAO;IACT;IACA,IAAIA,IAAIE,GAAG,EAAE;QACXF,IAAIG,EAAE,GAAGH,IAAIE,GAAG;QAChB,OAAOF,IAAIE,GAAG;IAChB;IAEAF,MAAMI,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACN;IAChCA,MAAMlB,uBAAuBkB;IAE7B,OAAOA;AACT,EAAC"}
1
+ {"version":3,"sources":["../src/findGlobal.ts"],"sourcesContent":["import type { FindGlobal, PayloadRequest } from 'payload'\n\nimport { combineQueries } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js'\nimport { withSession } from './withSession.js'\n\nexport const findGlobal: FindGlobal = async function findGlobal(\n this: MongooseAdapter,\n { slug, locale, req = {} as PayloadRequest, select, where },\n) {\n const Model = this.globals\n const options = {\n ...(await withSession(this, req)),\n lean: true,\n select: buildProjectionFromSelect({\n adapter: this,\n fields: this.payload.globals.config.find((each) => each.slug === slug).fields,\n select,\n }),\n }\n\n const query = await Model.buildQuery({\n globalSlug: slug,\n locale,\n payload: this.payload,\n where: combineQueries({ globalType: { equals: slug } }, where),\n })\n\n let doc = (await Model.findOne(query, {}, options)) as any\n\n if (!doc) {\n return null\n }\n if (doc._id) {\n doc.id = doc._id\n delete doc._id\n }\n\n doc = JSON.parse(JSON.stringify(doc))\n doc = sanitizeInternalFields(doc)\n\n return doc\n}\n"],"names":["combineQueries","buildProjectionFromSelect","sanitizeInternalFields","withSession","findGlobal","slug","locale","req","select","where","Model","globals","options","lean","adapter","fields","payload","config","find","each","query","buildQuery","globalSlug","globalType","equals","doc","findOne","_id","id","JSON","parse","stringify"],"mappings":"AAEA,SAASA,cAAc,QAAQ,UAAS;AAIxC,SAASC,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,sBAAsB,QAAQ,wCAAuC;AAC9E,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,aAAyB,eAAeA,WAEnD,EAAEC,IAAI,EAAEC,MAAM,EAAEC,MAAM,CAAC,CAAmB,EAAEC,MAAM,EAAEC,KAAK,EAAE;IAE3D,MAAMC,QAAQ,IAAI,CAACC,OAAO;IAC1B,MAAMC,UAAU;QACd,GAAI,MAAMT,YAAY,IAAI,EAAEI,IAAI;QAChCM,MAAM;QACNL,QAAQP,0BAA0B;YAChCa,SAAS,IAAI;YACbC,QAAQ,IAAI,CAACC,OAAO,CAACL,OAAO,CAACM,MAAM,CAACC,IAAI,CAAC,CAACC,OAASA,KAAKd,IAAI,KAAKA,MAAMU,MAAM;YAC7EP;QACF;IACF;IAEA,MAAMY,QAAQ,MAAMV,MAAMW,UAAU,CAAC;QACnCC,YAAYjB;QACZC;QACAU,SAAS,IAAI,CAACA,OAAO;QACrBP,OAAOT,eAAe;YAAEuB,YAAY;gBAAEC,QAAQnB;YAAK;QAAE,GAAGI;IAC1D;IAEA,IAAIgB,MAAO,MAAMf,MAAMgB,OAAO,CAACN,OAAO,CAAC,GAAGR;IAE1C,IAAI,CAACa,KAAK;QACR,OAAO;IACT;IACA,IAAIA,IAAIE,GAAG,EAAE;QACXF,IAAIG,EAAE,GAAGH,IAAIE,GAAG;QAChB,OAAOF,IAAIE,GAAG;IAChB;IAEAF,MAAMI,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACN;IAChCA,MAAMvB,uBAAuBuB;IAE7B,OAAOA;AACT,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"findGlobalVersions.d.ts","sourceRoot":"","sources":["../src/findGlobalVersions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAA0B,MAAM,SAAS,CAAA;AAUzE,eAAO,MAAM,kBAAkB,EAAE,kBAoGhC,CAAA"}
1
+ {"version":3,"file":"findGlobalVersions.d.ts","sourceRoot":"","sources":["../src/findGlobalVersions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAkB,MAAM,SAAS,CAAA;AAWjE,eAAO,MAAM,kBAAkB,EAAE,kBA6GhC,CAAA"}
@@ -1,12 +1,13 @@
1
1
  import { buildVersionGlobalFields, flattenWhereToOperators } from 'payload';
2
2
  import { buildSortParam } from './queries/buildSortParam.js';
3
- import sanitizeInternalFields from './utilities/sanitizeInternalFields.js';
3
+ import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
4
+ import { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js';
4
5
  import { withSession } from './withSession.js';
5
- export const findGlobalVersions = async function findGlobalVersions({ global, limit, locale, page, pagination, req = {}, skip, sort: sortArg, where }) {
6
+ export const findGlobalVersions = async function findGlobalVersions({ global, limit, locale, page, pagination, req = {}, select, skip, sort: sortArg, where }) {
6
7
  const Model = this.versions[global];
7
- const versionFields = buildVersionGlobalFields(this.payload.globals.config.find(({ slug })=>slug === global));
8
+ const versionFields = buildVersionGlobalFields(this.payload.config, this.payload.globals.config.find(({ slug })=>slug === global));
8
9
  const options = {
9
- ...withSession(this, req.transactionID),
10
+ ...await withSession(this, req),
10
11
  limit,
11
12
  skip
12
13
  };
@@ -34,16 +35,27 @@ export const findGlobalVersions = async function findGlobalVersions({ global, li
34
35
  // useEstimatedCount is faster, but not accurate, as it ignores any filters. It is thus set to true if there are no filters.
35
36
  const useEstimatedCount = hasNearConstraint || !query || Object.keys(query).length === 0;
36
37
  const paginationOptions = {
37
- forceCountFn: hasNearConstraint,
38
38
  lean: true,
39
39
  leanWithId: true,
40
- offset: skip,
40
+ limit,
41
41
  options,
42
42
  page,
43
43
  pagination,
44
+ projection: buildProjectionFromSelect({
45
+ adapter: this,
46
+ fields: versionFields,
47
+ select
48
+ }),
44
49
  sort,
45
50
  useEstimatedCount
46
51
  };
52
+ if (this.collation) {
53
+ const defaultLocale = 'en';
54
+ paginationOptions.collation = {
55
+ locale: locale && locale !== 'all' && locale !== '*' ? locale : defaultLocale,
56
+ ...this.collation
57
+ };
58
+ }
47
59
  if (!useEstimatedCount && Object.keys(query).length === 0 && this.disableIndexHints !== true) {
48
60
  // Improve the performance of the countDocuments query which is used if useEstimatedCount is set to false by adding
49
61
  // a hint. By default, if no hint is provided, MongoDB does not use an indexed field to count the returned documents,
@@ -72,7 +84,6 @@ export const findGlobalVersions = async function findGlobalVersions({ global, li
72
84
  return {
73
85
  ...result,
74
86
  docs: docs.map((doc)=>{
75
- // eslint-disable-next-line no-param-reassign
76
87
  doc.id = doc._id;
77
88
  return sanitizeInternalFields(doc);
78
89
  })
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/findGlobalVersions.ts"],"sourcesContent":["import type { PaginateOptions } from 'mongoose'\nimport type { FindGlobalVersions, PayloadRequestWithData } from 'payload'\n\nimport { buildVersionGlobalFields, flattenWhereToOperators } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildSortParam } from './queries/buildSortParam.js'\nimport sanitizeInternalFields from './utilities/sanitizeInternalFields.js'\nimport { withSession } from './withSession.js'\n\nexport const findGlobalVersions: FindGlobalVersions = async function findGlobalVersions(\n this: MongooseAdapter,\n {\n global,\n limit,\n locale,\n page,\n pagination,\n req = {} as PayloadRequestWithData,\n skip,\n sort: sortArg,\n where,\n },\n) {\n const Model = this.versions[global]\n const versionFields = buildVersionGlobalFields(\n this.payload.globals.config.find(({ slug }) => slug === global),\n )\n const options = {\n ...withSession(this, req.transactionID),\n limit,\n skip,\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 let sort\n if (!hasNearConstraint) {\n sort = buildSortParam({\n config: this.payload.config,\n fields: versionFields,\n locale,\n sort: sortArg || '-updatedAt',\n timestamps: true,\n })\n }\n\n const query = await Model.buildQuery({\n globalSlug: global,\n locale,\n payload: this.payload,\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 const paginationOptions: PaginateOptions = {\n forceCountFn: hasNearConstraint,\n lean: true,\n leanWithId: true,\n offset: skip,\n options,\n page,\n pagination,\n sort,\n useEstimatedCount,\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 paginationOptions.useCustomCountFn = () => {\n return Promise.resolve(\n Model.countDocuments(query, {\n ...options,\n hint: { _id: 1 },\n }),\n )\n }\n }\n\n if (limit >= 0) {\n paginationOptions.limit = limit\n // limit must also be set here, it's ignored when pagination is false\n paginationOptions.options.limit = limit\n\n // Disable pagination if limit is 0\n if (limit === 0) {\n paginationOptions.pagination = false\n }\n }\n\n const result = await Model.paginate(query, paginationOptions)\n const docs = JSON.parse(JSON.stringify(result.docs))\n\n return {\n ...result,\n docs: docs.map((doc) => {\n // eslint-disable-next-line no-param-reassign\n doc.id = doc._id\n return sanitizeInternalFields(doc)\n }),\n }\n}\n"],"names":["buildVersionGlobalFields","flattenWhereToOperators","buildSortParam","sanitizeInternalFields","withSession","findGlobalVersions","global","limit","locale","page","pagination","req","skip","sort","sortArg","where","Model","versions","versionFields","payload","globals","config","find","slug","options","transactionID","hasNearConstraint","constraints","some","prop","Object","keys","key","fields","timestamps","query","buildQuery","globalSlug","useEstimatedCount","length","paginationOptions","forceCountFn","lean","leanWithId","offset","disableIndexHints","useCustomCountFn","Promise","resolve","countDocuments","hint","_id","result","paginate","docs","JSON","parse","stringify","map","doc","id"],"mappings":"AAGA,SAASA,wBAAwB,EAAEC,uBAAuB,QAAQ,UAAS;AAI3E,SAASC,cAAc,QAAQ,8BAA6B;AAC5D,OAAOC,4BAA4B,wCAAuC;AAC1E,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,qBAAyC,eAAeA,mBAEnE,EACEC,MAAM,EACNC,KAAK,EACLC,MAAM,EACNC,IAAI,EACJC,UAAU,EACVC,MAAM,CAAC,CAA2B,EAClCC,IAAI,EACJC,MAAMC,OAAO,EACbC,KAAK,EACN;IAED,MAAMC,QAAQ,IAAI,CAACC,QAAQ,CAACX,OAAO;IACnC,MAAMY,gBAAgBlB,yBACpB,IAAI,CAACmB,OAAO,CAACC,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC,CAAC,EAAEC,IAAI,EAAE,GAAKA,SAASjB;IAE1D,MAAMkB,UAAU;QACd,GAAGpB,YAAY,IAAI,EAAEO,IAAIc,aAAa,CAAC;QACvClB;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MAAM0C,SAAS,MAAMpC,MAAMqC,QAAQ,CAAClB,OAAOK;IAC3C,MAAMc,OAAOC,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACL,OAAOE,IAAI;IAElD,OAAO;QACL,GAAGF,MAAM;QACTE,MAAMA,KAAKI,GAAG,CAAC,CAACC;YACd,6CAA6C;YAC7CA,IAAIC,EAAE,GAAGD,IAAIR,GAAG;YAChB,OAAOhD,uBAAuBwD;QAChC;IACF;AACF,EAAC"}
1
+ {"version":3,"sources":["../src/findGlobalVersions.ts"],"sourcesContent":["import type { PaginateOptions } from 'mongoose'\nimport type { FindGlobalVersions, PayloadRequest } from 'payload'\n\nimport { buildVersionGlobalFields, flattenWhereToOperators } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildSortParam } from './queries/buildSortParam.js'\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js'\nimport { withSession } from './withSession.js'\n\nexport const findGlobalVersions: FindGlobalVersions = async function findGlobalVersions(\n this: MongooseAdapter,\n {\n global,\n limit,\n locale,\n page,\n pagination,\n req = {} as PayloadRequest,\n select,\n skip,\n sort: sortArg,\n where,\n },\n) {\n const Model = this.versions[global]\n const versionFields = buildVersionGlobalFields(\n this.payload.config,\n this.payload.globals.config.find(({ slug }) => slug === global),\n )\n const options = {\n ...(await withSession(this, req)),\n limit,\n skip,\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 let sort\n if (!hasNearConstraint) {\n sort = buildSortParam({\n config: this.payload.config,\n fields: versionFields,\n locale,\n sort: sortArg || '-updatedAt',\n timestamps: true,\n })\n }\n\n const query = await Model.buildQuery({\n globalSlug: global,\n locale,\n payload: this.payload,\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 const paginationOptions: PaginateOptions = {\n lean: true,\n leanWithId: true,\n limit,\n options,\n page,\n pagination,\n projection: buildProjectionFromSelect({ adapter: this, fields: versionFields, select }),\n sort,\n useEstimatedCount,\n }\n\n if (this.collation) {\n const defaultLocale = 'en'\n paginationOptions.collation = {\n locale: locale && locale !== 'all' && locale !== '*' ? locale : defaultLocale,\n ...this.collation,\n }\n }\n\n if (!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 paginationOptions.useCustomCountFn = () => {\n return Promise.resolve(\n Model.countDocuments(query, {\n ...options,\n hint: { _id: 1 },\n }),\n )\n }\n }\n\n if (limit >= 0) {\n paginationOptions.limit = limit\n // limit must also be set here, it's ignored when pagination is false\n paginationOptions.options.limit = limit\n\n // Disable pagination if limit is 0\n if (limit === 0) {\n paginationOptions.pagination = false\n }\n }\n\n const result = await Model.paginate(query, paginationOptions)\n const docs = JSON.parse(JSON.stringify(result.docs))\n\n return {\n ...result,\n docs: docs.map((doc) => {\n doc.id = doc._id\n return sanitizeInternalFields(doc)\n }),\n }\n}\n"],"names":["buildVersionGlobalFields","flattenWhereToOperators","buildSortParam","buildProjectionFromSelect","sanitizeInternalFields","withSession","findGlobalVersions","global","limit","locale","page","pagination","req","select","skip","sort","sortArg","where","Model","versions","versionFields","payload","config","globals","find","slug","options","hasNearConstraint","constraints","some","prop","Object","keys","key","fields","timestamps","query","buildQuery","globalSlug","useEstimatedCount","length","paginationOptions","lean","leanWithId","projection","adapter","collation","defaultLocale","disableIndexHints","useCustomCountFn","Promise","resolve","countDocuments","hint","_id","result","paginate","docs","JSON","parse","stringify","map","doc","id"],"mappings":"AAGA,SAASA,wBAAwB,EAAEC,uBAAuB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src/findOne.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAY,OAAO,EAA0B,MAAM,SAAS,CAAA;AAOxE,eAAO,MAAM,OAAO,EAAE,OA6BrB,CAAA"}
1
+ {"version":3,"file":"findOne.d.ts","sourceRoot":"","sources":["../src/findOne.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAY,OAAO,EAAkB,MAAM,SAAS,CAAA;AAShE,eAAO,MAAM,OAAO,EAAE,OAqDrB,CAAA"}
package/dist/findOne.js CHANGED
@@ -1,9 +1,12 @@
1
- import sanitizeInternalFields from './utilities/sanitizeInternalFields.js';
1
+ import { buildJoinAggregation } from './utilities/buildJoinAggregation.js';
2
+ import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
3
+ import { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js';
2
4
  import { withSession } from './withSession.js';
3
- export const findOne = async function findOne({ collection, locale, req = {}, where }) {
5
+ export const findOne = async function findOne({ collection, joins, locale, req = {}, select, where }) {
4
6
  const Model = this.collections[collection];
7
+ const collectionConfig = this.payload.collections[collection].config;
5
8
  const options = {
6
- ...withSession(this, req.transactionID),
9
+ ...await withSession(this, req),
7
10
  lean: true
8
11
  };
9
12
  const query = await Model.buildQuery({
@@ -11,7 +14,28 @@ export const findOne = async function findOne({ collection, locale, req = {}, wh
11
14
  payload: this.payload,
12
15
  where
13
16
  });
14
- const doc = await Model.findOne(query, {}, options);
17
+ const projection = buildProjectionFromSelect({
18
+ adapter: this,
19
+ fields: collectionConfig.fields,
20
+ select
21
+ });
22
+ const aggregate = await buildJoinAggregation({
23
+ adapter: this,
24
+ collection,
25
+ collectionConfig,
26
+ joins,
27
+ limit: 1,
28
+ locale,
29
+ projection,
30
+ query
31
+ });
32
+ let doc;
33
+ if (aggregate) {
34
+ [doc] = await Model.aggregate(aggregate, options);
35
+ } else {
36
+ options.projection = projection;
37
+ doc = await Model.findOne(query, {}, options);
38
+ }
15
39
  if (!doc) {
16
40
  return null;
17
41
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/findOne.ts"],"sourcesContent":["import type { MongooseQueryOptions } from 'mongoose'\nimport type { Document, FindOne, PayloadRequestWithData } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport sanitizeInternalFields from './utilities/sanitizeInternalFields.js'\nimport { withSession } from './withSession.js'\n\nexport const findOne: FindOne = async function findOne(\n this: MongooseAdapter,\n { collection, locale, req = {} as PayloadRequestWithData, where },\n) {\n const Model = this.collections[collection]\n const options: MongooseQueryOptions = {\n ...withSession(this, req.transactionID),\n lean: true,\n }\n\n const query = await Model.buildQuery({\n locale,\n payload: this.payload,\n where,\n })\n\n const doc = await Model.findOne(query, {}, options)\n\n if (!doc) {\n return null\n }\n\n let result: Document = JSON.parse(JSON.stringify(doc))\n\n // custom id type reset\n result.id = result._id\n result = sanitizeInternalFields(result)\n\n return result\n}\n"],"names":["sanitizeInternalFields","withSession","findOne","collection","locale","req","where","Model","collections","options","transactionID","lean","query","buildQuery","payload","doc","result","JSON","parse","stringify","id","_id"],"mappings":"AAKA,OAAOA,4BAA4B,wCAAuC;AAC1E,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,UAAmB,eAAeA,QAE7C,EAAEC,UAAU,EAAEC,MAAM,EAAEC,MAAM,CAAC,CAA2B,EAAEC,KAAK,EAAE;IAEjE,MAAMC,QAAQ,IAAI,CAACC,WAAW,CAACL,WAAW;IAC1C,MAAMM,UAAgC;QACpC,GAAGR,YAAY,IAAI,EAAEI,IAAIK,aAAa,CAAC;QACvCC,MAAM;IACR;IAEA,MAAMC,QAAQ,MAAML,MAAMM,UAAU,CAAC;QACnCT;QACAU,SAAS,IAAI,CAACA,OAAO;QACrBR;IACF;IAEA,MAAMS,MAAM,MAAMR,MAAML,OAAO,CAACU,OAAO,CAAC,GAAGH;IAE3C,IAAI,CAACM,KAAK;QACR,OAAO;IACT;IAEA,IAAIC,SAAmBC,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACJ;IAEjD,uBAAuB;IACvBC,OAAOI,EAAE,GAAGJ,OAAOK,GAAG;IACtBL,SAAShB,uBAAuBgB;IAEhC,OAAOA;AACT,EAAC"}
1
+ {"version":3,"sources":["../src/findOne.ts"],"sourcesContent":["import type { MongooseQueryOptions, QueryOptions } from 'mongoose'\nimport type { Document, FindOne, PayloadRequest } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildJoinAggregation } from './utilities/buildJoinAggregation.js'\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js'\nimport { withSession } from './withSession.js'\n\nexport const findOne: FindOne = async function findOne(\n this: MongooseAdapter,\n { collection, joins, locale, req = {} as PayloadRequest, select, where },\n) {\n const Model = this.collections[collection]\n const collectionConfig = this.payload.collections[collection].config\n const options: MongooseQueryOptions = {\n ...(await withSession(this, req)),\n lean: true,\n }\n\n const query = await Model.buildQuery({\n locale,\n payload: this.payload,\n where,\n })\n\n const projection = buildProjectionFromSelect({\n adapter: this,\n fields: collectionConfig.fields,\n select,\n })\n\n const aggregate = await buildJoinAggregation({\n adapter: this,\n collection,\n collectionConfig,\n joins,\n limit: 1,\n locale,\n projection,\n query,\n })\n\n let doc\n if (aggregate) {\n ;[doc] = await Model.aggregate(aggregate, options)\n } else {\n ;(options as Record<string, unknown>).projection = projection\n doc = await Model.findOne(query, {}, options)\n }\n\n if (!doc) {\n return null\n }\n\n let result: Document = JSON.parse(JSON.stringify(doc))\n\n // custom id type reset\n result.id = result._id\n result = sanitizeInternalFields(result)\n\n return result\n}\n"],"names":["buildJoinAggregation","buildProjectionFromSelect","sanitizeInternalFields","withSession","findOne","collection","joins","locale","req","select","where","Model","collections","collectionConfig","payload","config","options","lean","query","buildQuery","projection","adapter","fields","aggregate","limit","doc","result","JSON","parse","stringify","id","_id"],"mappings":"AAKA,SAASA,oBAAoB,QAAQ,sCAAqC;AAC1E,SAASC,yBAAyB,QAAQ,2C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AACA,OAAO,KAAK,EAAE,YAAY,EAA0B,MAAM,SAAS,CAAA;AAUnE,eAAO,MAAM,YAAY,EAAE,YAiG1B,CAAA"}
1
+ {"version":3,"file":"findVersions.d.ts","sourceRoot":"","sources":["../src/findVersions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAkB,MAAM,SAAS,CAAA;AAW3D,eAAO,MAAM,YAAY,EAAE,YA6G1B,CAAA"}
@@ -1,12 +1,13 @@
1
- import { flattenWhereToOperators } from 'payload';
1
+ import { buildVersionCollectionFields, flattenWhereToOperators } from 'payload';
2
2
  import { buildSortParam } from './queries/buildSortParam.js';
3
- import sanitizeInternalFields from './utilities/sanitizeInternalFields.js';
3
+ import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
4
+ import { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js';
4
5
  import { withSession } from './withSession.js';
5
- export const findVersions = async function findVersions({ collection, limit, locale, page, pagination, req = {}, skip, sort: sortArg, where }) {
6
+ export const findVersions = async function findVersions({ collection, limit, locale, page, pagination, req = {}, select, skip, sort: sortArg, where }) {
6
7
  const Model = this.versions[collection];
7
8
  const collectionConfig = this.payload.collections[collection].config;
8
9
  const options = {
9
- ...withSession(this, req.transactionID),
10
+ ...await withSession(this, req),
10
11
  limit,
11
12
  skip
12
13
  };
@@ -33,16 +34,27 @@ export const findVersions = async function findVersions({ collection, limit, loc
33
34
  // useEstimatedCount is faster, but not accurate, as it ignores any filters. It is thus set to true if there are no filters.
34
35
  const useEstimatedCount = hasNearConstraint || !query || Object.keys(query).length === 0;
35
36
  const paginationOptions = {
36
- forceCountFn: hasNearConstraint,
37
37
  lean: true,
38
38
  leanWithId: true,
39
39
  limit,
40
40
  options,
41
41
  page,
42
42
  pagination,
43
+ projection: buildProjectionFromSelect({
44
+ adapter: this,
45
+ fields: buildVersionCollectionFields(this.payload.config, collectionConfig),
46
+ select
47
+ }),
43
48
  sort,
44
49
  useEstimatedCount
45
50
  };
51
+ if (this.collation) {
52
+ const defaultLocale = 'en';
53
+ paginationOptions.collation = {
54
+ locale: locale && locale !== 'all' && locale !== '*' ? locale : defaultLocale,
55
+ ...this.collation
56
+ };
57
+ }
46
58
  if (!useEstimatedCount && Object.keys(query).length === 0 && this.disableIndexHints !== true) {
47
59
  // Improve the performance of the countDocuments query which is used if useEstimatedCount is set to false by adding
48
60
  // a hint. By default, if no hint is provided, MongoDB does not use an indexed field to count the returned documents,
@@ -71,7 +83,6 @@ export const findVersions = async function findVersions({ collection, limit, loc
71
83
  return {
72
84
  ...result,
73
85
  docs: docs.map((doc)=>{
74
- // eslint-disable-next-line no-param-reassign
75
86
  doc.id = doc._id;
76
87
  return sanitizeInternalFields(doc);
77
88
  })
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/findVersions.ts"],"sourcesContent":["import type { PaginateOptions } from 'mongoose'\nimport type { FindVersions, PayloadRequestWithData } from 'payload'\n\nimport { flattenWhereToOperators } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildSortParam } from './queries/buildSortParam.js'\nimport sanitizeInternalFields from './utilities/sanitizeInternalFields.js'\nimport { withSession } from './withSession.js'\n\nexport const findVersions: FindVersions = async function findVersions(\n this: MongooseAdapter,\n {\n collection,\n limit,\n locale,\n page,\n pagination,\n req = {} as PayloadRequestWithData,\n skip,\n sort: sortArg,\n where,\n },\n) {\n const Model = this.versions[collection]\n const collectionConfig = this.payload.collections[collection].config\n const options = {\n ...withSession(this, req.transactionID),\n limit,\n skip,\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 let sort\n if (!hasNearConstraint) {\n sort = buildSortParam({\n config: this.payload.config,\n fields: collectionConfig.fields,\n locale,\n sort: sortArg || '-updatedAt',\n timestamps: true,\n })\n }\n\n const query = await Model.buildQuery({\n locale,\n payload: this.payload,\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 const paginationOptions: PaginateOptions = {\n forceCountFn: hasNearConstraint,\n lean: true,\n leanWithId: true,\n limit,\n options,\n page,\n pagination,\n sort,\n useEstimatedCount,\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 paginationOptions.useCustomCountFn = () => {\n return Promise.resolve(\n Model.countDocuments(query, {\n ...options,\n hint: { _id: 1 },\n }),\n )\n }\n }\n\n if (limit >= 0) {\n paginationOptions.limit = limit\n // limit must also be set here, it's ignored when pagination is false\n paginationOptions.options.limit = limit\n\n // Disable pagination if limit is 0\n if (limit === 0) {\n paginationOptions.pagination = false\n }\n }\n\n const result = await Model.paginate(query, paginationOptions)\n const docs = JSON.parse(JSON.stringify(result.docs))\n\n return {\n ...result,\n docs: docs.map((doc) => {\n // eslint-disable-next-line no-param-reassign\n doc.id = doc._id\n return sanitizeInternalFields(doc)\n }),\n }\n}\n"],"names":["flattenWhereToOperators","buildSortParam","sanitizeInternalFields","withSession","findVersions","collection","limit","locale","page","pagination","req","skip","sort","sortArg","where","Model","versions","collectionConfig","payload","collections","config","options","transactionID","hasNearConstraint","constraints","some","prop","Object","keys","key","fields","timestamps","query","buildQuery","useEstimatedCount","length","paginationOptions","forceCountFn","lean","leanWithId","disableIndexHints","useCustomCountFn","Promise","resolve","countDocuments","hint","_id","result","paginate","docs","JSON","parse","stringify","map","doc","id"],"mappings":"AAGA,SAASA,uBAAuB,QAAQ,UAAS;AAIjD,SAASC,cAAc,QAAQ,8BAA6B;AAC5D,OAAOC,4BAA4B,wCAAuC;AAC1E,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MA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AkBK,gBAAgB,GAAG;YACnC,OAAOC,QAAQC,OAAO,CACpB5B,MAAM6B,cAAc,CAACZ,OAAO;gBAC1B,GAAGX,OAAO;gBACVwB,MAAM;oBAAEC,KAAK;gBAAE;YACjB;QAEJ;IACF;IAEA,IAAIxC,SAAS,GAAG;QACd8B,kBAAkB9B,KAAK,GAAGA;QAC1B,qEAAqE;QACrE8B,kBAAkBf,OAAO,CAACf,KAAK,GAAGA;QAElC,mCAAmC;QACnC,IAAIA,UAAU,GAAG;YACf8B,kBAAkB3B,UAAU,GAAG;QACjC;IACF;IAEA,MAAMsC,SAAS,MAAMhC,MAAMiC,QAAQ,CAAChB,OAAOI;IAC3C,MAAMa,OAAOC,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACL,OAAOE,IAAI;IAElD,OAAO;QACL,GAAGF,MAAM;QACTE,MAAMA,KAAKI,GAAG,CAAC,CAACC;YACd,6CAA6C;YAC7CA,IAAIC,EAAE,GAAGD,IAAIR,GAAG;YAChB,OAAO5C,uBAAuBoD;QAChC;IACF;AACF,EAAC"}
1
+ {"version":3,"sources":["../src/findVersions.ts"],"sourcesContent":["import type { PaginateOptions } from 'mongoose'\nimport type { FindVersions, PayloadRequest } from 'payload'\n\nimport { buildVersionCollectionFields, flattenWhereToOperators } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildSortParam } from './queries/buildSortParam.js'\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js'\nimport { withSession } from './withSession.js'\n\nexport const findVersions: FindVersions = async function findVersions(\n this: MongooseAdapter,\n {\n collection,\n limit,\n locale,\n page,\n pagination,\n req = {} as PayloadRequest,\n select,\n skip,\n sort: sortArg,\n where,\n },\n) {\n const Model = this.versions[collection]\n const collectionConfig = this.payload.collections[collection].config\n const options = {\n ...(await withSession(this, req)),\n limit,\n skip,\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 let sort\n if (!hasNearConstraint) {\n sort = buildSortParam({\n config: this.payload.config,\n fields: collectionConfig.fields,\n locale,\n sort: sortArg || '-updatedAt',\n timestamps: true,\n })\n }\n\n const query = await Model.buildQuery({\n locale,\n payload: this.payload,\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 const paginationOptions: PaginateOptions = {\n lean: true,\n leanWithId: true,\n limit,\n options,\n page,\n pagination,\n projection: buildProjectionFromSelect({\n adapter: this,\n fields: buildVersionCollectionFields(this.payload.config, collectionConfig),\n select,\n }),\n sort,\n useEstimatedCount,\n }\n\n if (this.collation) {\n const defaultLocale = 'en'\n paginationOptions.collation = {\n locale: locale && locale !== 'all' && locale !== '*' ? locale : defaultLocale,\n ...this.collation,\n }\n }\n\n if (!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 paginationOptions.useCustomCountFn = () => {\n return Promise.resolve(\n Model.countDocuments(query, {\n ...options,\n hint: { _id: 1 },\n }),\n )\n }\n }\n\n if (limit >= 0) {\n paginationOptions.limit = limit\n // limit must also be set here, it's ignored when pagination is false\n paginationOptions.options.limit = limit\n\n // Disable pagination if limit is 0\n if (limit === 0) {\n paginationOptions.pagination = false\n }\n }\n\n const result = await Model.paginate(query, paginationOptions)\n const docs = JSON.parse(JSON.stringify(result.docs))\n\n return {\n ...result,\n docs: docs.map((doc) => {\n doc.id = doc._id\n return sanitizeInternalFields(doc)\n }),\n }\n}\n"],"names":["buildVersionCollectionFields","flattenWhereToOperators","buildSortParam","buildProjectionFromSelect","sanitizeInternalFields","withSession","findVersions","collection","limit","locale","page","pagination","req","select","skip","sort","sortArg","where","Model","versions","collectionConfig","payload","collections","config","options","hasNearConstraint","constraints","some","prop","Object","keys","key","fields","timestamps","query","buildQuery","useEstimatedCount","length","paginationOptions","lean","leanWithId","projection","adapter","collation","defaultLocale","disableIndexHints","useCustomCountFn","Promise","resolve","countDocuments","hint","_id","result","paginate","docs","JSON","parse","stringify","map","doc","id"],"mappings":"AAGA,SAASA,4BAA4B,EAAEC,uBAAuB,QAAQ,UAAS;AAI/E,SAASC,cAAc,QAAQ,8BAA6B;AAC5D,SAASC,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,sBAAsB,QAAQ,wCAAuC;AAC9E,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,eAA6B,eAAeA,aAEvD,EACEC,UAAU,EACVC,KAAK,EACLC,MAAM,EACNC,IAAI,EACJC,UAAU,EACVC,MAAM,CAAC,CAAmB,EAC1BC,MAAM,EACNC,IAAI,EACJC,MAAMC,OAAO,EACbC,KAAK,EACN;IAED,MAAMC,QAAQ,IAAI,CAACC,QAAQ,CAACZ,WAAW;IACvC,MAAMa,mBAAmB,IAAI,CAACC,OAAO,CAACC,WAAW,CAACf,WAAW,CAACgB,MAAM;IACpE,MAAMC,UAAU;QACd,GAAI,MAAMnB,YAAY,IAAI,EAAEO,IAAI;QAChCJ;QACAM;IACF;IAEA,IAAIW,oBAAoB;IAExB,IAAIR,OAAO;QACT,MAAMS,cAAczB,wBAAwBgB;QAC5CQ,oBAAoBC,YAAYC,IAAI,CAAC,CAACC,OAASC,OAAOC,IAAI,CAACF,MAAMD,IAAI,CAAC,CAACI,MAAQA,QAAQ;IACzF;IAEA,IAAIhB;IACJ,IAAI,CAACU,mBAAmB;QACtBV,OAAOb,eAAe;YACpBqB,QAAQ,IAAI,CAACF,OAAO,CAACE,MAAM;YAC3BS,QAAQZ,iBAAiBY,MAAM;YAC/BvB;YACAM,MAAMC,WAAW;YACjBi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