@payloadcms/db-mongodb 3.0.0-canary.c27a334 → 3.0.0-canary.c96fa61

Sign up to get free protection for your applications and to get access to all the features.
Files changed (197) hide show
  1. package/README.md +1 -1
  2. package/dist/connect.d.ts +1 -1
  3. package/dist/connect.d.ts.map +1 -1
  4. package/dist/connect.js +13 -4
  5. package/dist/connect.js.map +1 -1
  6. package/dist/count.d.ts +1 -1
  7. package/dist/count.d.ts.map +1 -1
  8. package/dist/count.js +2 -2
  9. package/dist/count.js.map +1 -1
  10. package/dist/countGlobalVersions.d.ts +3 -0
  11. package/dist/countGlobalVersions.d.ts.map +1 -0
  12. package/dist/countGlobalVersions.js +33 -0
  13. package/dist/countGlobalVersions.js.map +1 -0
  14. package/dist/countVersions.d.ts +3 -0
  15. package/dist/countVersions.d.ts.map +1 -0
  16. package/dist/countVersions.js +33 -0
  17. package/dist/countVersions.js.map +1 -0
  18. package/dist/create.d.ts +1 -1
  19. package/dist/create.d.ts.map +1 -1
  20. package/dist/create.js +17 -4
  21. package/dist/create.js.map +1 -1
  22. package/dist/createGlobal.d.ts +1 -1
  23. package/dist/createGlobal.d.ts.map +1 -1
  24. package/dist/createGlobal.js +11 -6
  25. package/dist/createGlobal.js.map +1 -1
  26. package/dist/createGlobalVersion.d.ts +1 -1
  27. package/dist/createGlobalVersion.d.ts.map +1 -1
  28. package/dist/createGlobalVersion.js +14 -5
  29. package/dist/createGlobalVersion.js.map +1 -1
  30. package/dist/createMigration.d.ts +1 -1
  31. package/dist/createMigration.d.ts.map +1 -1
  32. package/dist/createMigration.js +9 -7
  33. package/dist/createMigration.js.map +1 -1
  34. package/dist/createVersion.d.ts +1 -1
  35. package/dist/createVersion.d.ts.map +1 -1
  36. package/dist/createVersion.js +32 -10
  37. package/dist/createVersion.js.map +1 -1
  38. package/dist/deleteMany.d.ts +1 -1
  39. package/dist/deleteMany.d.ts.map +1 -1
  40. package/dist/deleteMany.js +1 -1
  41. package/dist/deleteMany.js.map +1 -1
  42. package/dist/deleteOne.d.ts +1 -1
  43. package/dist/deleteOne.d.ts.map +1 -1
  44. package/dist/deleteOne.js +12 -4
  45. package/dist/deleteOne.js.map +1 -1
  46. package/dist/deleteVersions.d.ts +1 -1
  47. package/dist/deleteVersions.d.ts.map +1 -1
  48. package/dist/deleteVersions.js +1 -1
  49. package/dist/deleteVersions.js.map +1 -1
  50. package/dist/destroy.d.ts +1 -1
  51. package/dist/destroy.d.ts.map +1 -1
  52. package/dist/destroy.js.map +1 -1
  53. package/dist/find.d.ts +1 -1
  54. package/dist/find.d.ts.map +1 -1
  55. package/dist/find.js +36 -6
  56. package/dist/find.js.map +1 -1
  57. package/dist/findGlobal.d.ts +1 -1
  58. package/dist/findGlobal.d.ts.map +1 -1
  59. package/dist/findGlobal.js +11 -5
  60. package/dist/findGlobal.js.map +1 -1
  61. package/dist/findGlobalVersions.d.ts +1 -1
  62. package/dist/findGlobalVersions.d.ts.map +1 -1
  63. package/dist/findGlobalVersions.js +19 -8
  64. package/dist/findGlobalVersions.js.map +1 -1
  65. package/dist/findOne.d.ts +1 -1
  66. package/dist/findOne.d.ts.map +1 -1
  67. package/dist/findOne.js +28 -4
  68. package/dist/findOne.js.map +1 -1
  69. package/dist/findVersions.d.ts +1 -1
  70. package/dist/findVersions.d.ts.map +1 -1
  71. package/dist/findVersions.js +17 -5
  72. package/dist/findVersions.js.map +1 -1
  73. package/dist/index.d.ts +52 -35
  74. package/dist/index.d.ts.map +1 -1
  75. package/dist/index.js +17 -7
  76. package/dist/index.js.map +1 -1
  77. package/dist/init.d.ts +1 -1
  78. package/dist/init.d.ts.map +1 -1
  79. package/dist/init.js +11 -8
  80. package/dist/init.js.map +1 -1
  81. package/dist/migrateFresh.d.ts.map +1 -1
  82. package/dist/migrateFresh.js +1 -1
  83. package/dist/migrateFresh.js.map +1 -1
  84. package/dist/models/buildCollectionSchema.d.ts +2 -29
  85. package/dist/models/buildCollectionSchema.d.ts.map +1 -1
  86. package/dist/models/buildCollectionSchema.js +16 -4
  87. package/dist/models/buildCollectionSchema.js.map +1 -1
  88. package/dist/models/buildGlobalModel.d.ts +1 -1
  89. package/dist/models/buildGlobalModel.d.ts.map +1 -1
  90. package/dist/models/buildGlobalModel.js +2 -2
  91. package/dist/models/buildGlobalModel.js.map +1 -1
  92. package/dist/models/buildSchema.d.ts +2 -29
  93. package/dist/models/buildSchema.d.ts.map +1 -1
  94. package/dist/models/buildSchema.js +116 -23
  95. package/dist/models/buildSchema.js.map +1 -1
  96. package/dist/predefinedMigrations/versions-v1-v2.js.map +1 -1
  97. package/dist/queries/buildAndOrConditions.d.ts +1 -2
  98. package/dist/queries/buildAndOrConditions.d.ts.map +1 -1
  99. package/dist/queries/buildAndOrConditions.js +0 -2
  100. package/dist/queries/buildAndOrConditions.js.map +1 -1
  101. package/dist/queries/buildQuery.d.ts +3 -4
  102. package/dist/queries/buildQuery.d.ts.map +1 -1
  103. package/dist/queries/buildQuery.js +2 -3
  104. package/dist/queries/buildQuery.js.map +1 -1
  105. package/dist/queries/buildSearchParams.d.ts +1 -2
  106. package/dist/queries/buildSearchParams.d.ts.map +1 -1
  107. package/dist/queries/buildSearchParams.js +21 -13
  108. package/dist/queries/buildSearchParams.js.map +1 -1
  109. package/dist/queries/buildSortParam.d.ts +3 -29
  110. package/dist/queries/buildSortParam.d.ts.map +1 -1
  111. package/dist/queries/buildSortParam.js +26 -17
  112. package/dist/queries/buildSortParam.js.map +1 -1
  113. package/dist/queries/getLocalizedSortProperty.d.ts +1 -2
  114. package/dist/queries/getLocalizedSortProperty.d.ts.map +1 -1
  115. package/dist/queries/getLocalizedSortProperty.js +2 -2
  116. package/dist/queries/getLocalizedSortProperty.js.map +1 -1
  117. package/dist/queries/getLocalizedSortProperty.spec.js +44 -44
  118. package/dist/queries/getLocalizedSortProperty.spec.js.map +1 -1
  119. package/dist/queries/mock.js.map +1 -1
  120. package/dist/queries/operatorMap.js.map +1 -1
  121. package/dist/queries/parseParams.d.ts +1 -3
  122. package/dist/queries/parseParams.d.ts.map +1 -1
  123. package/dist/queries/parseParams.js +6 -7
  124. package/dist/queries/parseParams.js.map +1 -1
  125. package/dist/queries/sanitizeQueryValue.d.ts +1 -1
  126. package/dist/queries/sanitizeQueryValue.d.ts.map +1 -1
  127. package/dist/queries/sanitizeQueryValue.js +146 -27
  128. package/dist/queries/sanitizeQueryValue.js.map +1 -1
  129. package/dist/queryDrafts.d.ts +1 -1
  130. package/dist/queryDrafts.d.ts.map +1 -1
  131. package/dist/queryDrafts.js +37 -9
  132. package/dist/queryDrafts.js.map +1 -1
  133. package/dist/testCredentials.js.map +1 -1
  134. package/dist/transactions/beginTransaction.d.ts +1 -1
  135. package/dist/transactions/beginTransaction.d.ts.map +1 -1
  136. package/dist/transactions/beginTransaction.js +3 -1
  137. package/dist/transactions/beginTransaction.js.map +1 -1
  138. package/dist/transactions/commitTransaction.d.ts +1 -1
  139. package/dist/transactions/commitTransaction.d.ts.map +1 -1
  140. package/dist/transactions/commitTransaction.js +3 -0
  141. package/dist/transactions/commitTransaction.js.map +1 -1
  142. package/dist/transactions/rollbackTransaction.d.ts +1 -1
  143. package/dist/transactions/rollbackTransaction.d.ts.map +1 -1
  144. package/dist/transactions/rollbackTransaction.js +13 -7
  145. package/dist/transactions/rollbackTransaction.js.map +1 -1
  146. package/dist/types.d.ts +7 -31
  147. package/dist/types.d.ts.map +1 -1
  148. package/dist/types.js.map +1 -1
  149. package/dist/updateGlobal.d.ts +1 -1
  150. package/dist/updateGlobal.d.ts.map +1 -1
  151. package/dist/updateGlobal.js +18 -5
  152. package/dist/updateGlobal.js.map +1 -1
  153. package/dist/updateGlobalVersion.d.ts +2 -3
  154. package/dist/updateGlobalVersion.d.ts.map +1 -1
  155. package/dist/updateGlobalVersion.js +19 -5
  156. package/dist/updateGlobalVersion.js.map +1 -1
  157. package/dist/updateOne.d.ts +1 -1
  158. package/dist/updateOne.d.ts.map +1 -1
  159. package/dist/updateOne.js +25 -7
  160. package/dist/updateOne.js.map +1 -1
  161. package/dist/updateVersion.d.ts +1 -1
  162. package/dist/updateVersion.d.ts.map +1 -1
  163. package/dist/updateVersion.js +18 -4
  164. package/dist/updateVersion.js.map +1 -1
  165. package/dist/upsert.d.ts +3 -0
  166. package/dist/upsert.d.ts.map +1 -0
  167. package/dist/upsert.js +15 -0
  168. package/dist/upsert.js.map +1 -0
  169. package/dist/utilities/buildJoinAggregation.d.ts +18 -0
  170. package/dist/utilities/buildJoinAggregation.d.ts.map +1 -0
  171. package/dist/utilities/buildJoinAggregation.js +159 -0
  172. package/dist/utilities/buildJoinAggregation.js.map +1 -0
  173. package/dist/utilities/buildProjectionFromSelect.d.ts +8 -0
  174. package/dist/utilities/buildProjectionFromSelect.d.ts.map +1 -0
  175. package/dist/utilities/buildProjectionFromSelect.js +171 -0
  176. package/dist/utilities/buildProjectionFromSelect.js.map +1 -0
  177. package/dist/utilities/getDBName.d.ts +1 -1
  178. package/dist/utilities/getDBName.d.ts.map +1 -1
  179. package/dist/utilities/getDBName.js +3 -1
  180. package/dist/utilities/getDBName.js.map +1 -1
  181. package/dist/utilities/handleError.d.ts +6 -2
  182. package/dist/utilities/handleError.d.ts.map +1 -1
  183. package/dist/utilities/handleError.js +12 -9
  184. package/dist/utilities/handleError.js.map +1 -1
  185. package/dist/utilities/sanitizeInternalFields.d.ts +1 -2
  186. package/dist/utilities/sanitizeInternalFields.d.ts.map +1 -1
  187. package/dist/utilities/sanitizeInternalFields.js +1 -2
  188. package/dist/utilities/sanitizeInternalFields.js.map +1 -1
  189. package/dist/utilities/sanitizeRelationshipIDs.d.ts +9 -0
  190. package/dist/utilities/sanitizeRelationshipIDs.d.ts.map +1 -0
  191. package/dist/utilities/sanitizeRelationshipIDs.js +115 -0
  192. package/dist/utilities/sanitizeRelationshipIDs.js.map +1 -0
  193. package/dist/withSession.d.ts +3 -27
  194. package/dist/withSession.d.ts.map +1 -1
  195. package/dist/withSession.js +10 -4
  196. package/dist/withSession.js.map +1 -1
  197. package/package.json +14 -12
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/deleteMany.ts"],"sourcesContent":["import type { DeleteMany } from 'payload/database'\nimport type { PayloadRequestWithData } from 'payload/types'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { withSession } from './withSession.js'\n\nexport const deleteMany: DeleteMany = async function deleteMany(\n this: MongooseAdapter,\n { collection, req = {} as PayloadRequestWithData, where },\n) {\n const Model = this.collections[collection]\n const options = {\n ...withSession(this, req.transactionID),\n lean: true,\n }\n\n const query = await Model.buildQuery({\n payload: this.payload,\n where,\n })\n\n await Model.deleteMany(query, options)\n}\n"],"names":["withSession","deleteMany","collection","req","where","Model","collections","options","transactionID","lean","query","buildQuery","payload"],"rangeMappings":";;;;;;;;;;;;","mappings":"AAKA,SAASA,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,aAAyB,eAAeA,WAEnD,EAAEC,UAAU,EAAEC,MAAM,CAAC,CAA2B,EAAEC,KAAK,EAAE;IAEzD,MAAMC,QAAQ,IAAI,CAACC,WAAW,CAACJ,WAAW;IAC1C,MAAMK,UAAU;QACd,GAAGP,YAAY,IAAI,EAAEG,IAAIK,aAAa,CAAC;QACvCC,MAAM;IACR;IAEA,MAAMC,QAAQ,MAAML,MAAMM,UAAU,CAAC;QACnCC,SAAS,IAAI,CAACA,OAAO;QACrBR;IACF;IAEA,MAAMC,MAAMJ,UAAU,CAACS,OAAOH;AAChC,EAAC"}
1
+ {"version":3,"sources":["../src/deleteMany.ts"],"sourcesContent":["import type { DeleteMany, PayloadRequest } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { withSession } from './withSession.js'\n\nexport const deleteMany: DeleteMany = async function deleteMany(\n this: MongooseAdapter,\n { collection, req = {} as PayloadRequest, where },\n) {\n const Model = this.collections[collection]\n const options = {\n ...(await withSession(this, req)),\n lean: true,\n }\n\n const query = await Model.buildQuery({\n payload: this.payload,\n where,\n })\n\n await Model.deleteMany(query, options)\n}\n"],"names":["withSession","deleteMany","collection","req","where","Model","collections","options","lean","query","buildQuery","payload"],"mappings":"AAIA,SAASA,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,aAAyB,eAAeA,WAEnD,EAAEC,UAAU,EAAEC,MAAM,CAAC,CAAmB,EAAEC,KAAK,EAAE;IAEjD,MAAMC,QAAQ,IAAI,CAACC,WAAW,CAACJ,WAAW;IAC1C,MAAMK,UAAU;QACd,GAAI,MAAMP,YAAY,IAAI,EAAEG,IAAI;QAChCK,MAAM;IACR;IAEA,MAAMC,QAAQ,MAAMJ,MAAMK,UAAU,CAAC;QACnCC,SAAS,IAAI,CAACA,OAAO;QACrBP;IACF;IAEA,MAAMC,MAAMJ,UAAU,CAACQ,OAAOF;AAChC,EAAC"}
@@ -1,3 +1,3 @@
1
- import type { DeleteOne } from 'payload/database';
1
+ import type { DeleteOne } from 'payload';
2
2
  export declare const deleteOne: DeleteOne;
3
3
  //# sourceMappingURL=deleteOne.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"deleteOne.d.ts","sourceRoot":"","sources":["../src/deleteOne.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AASjD,eAAO,MAAM,SAAS,EAAE,SAqBvB,CAAA"}
1
+ {"version":3,"file":"deleteOne.d.ts","sourceRoot":"","sources":["../src/deleteOne.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAA4B,MAAM,SAAS,CAAA;AAQlE,eAAO,MAAM,SAAS,EAAE,SA4BvB,CAAA"}
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 } from 'payload/database'\nimport type { PayloadRequestWithData } from 'payload/types'\nimport type { Document } from 'payload/types'\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"],"rangeMappings":";;;;;;;;;;;;;;;","mappings":"AAMA,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,3 +1,3 @@
1
- import type { DeleteVersions } from 'payload/database';
1
+ import type { DeleteVersions } from 'payload';
2
2
  export declare const deleteVersions: DeleteVersions;
3
3
  //# sourceMappingURL=deleteVersions.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"deleteVersions.d.ts","sourceRoot":"","sources":["../src/deleteVersions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAOtD,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 } from 'payload/database'\nimport type { PayloadRequestWithData } from 'payload/types'\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"],"rangeMappings":";;;;;;;;;;;;;","mappings":"AAKA,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"}
package/dist/destroy.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import type { Destroy } from 'payload/database';
1
+ import type { Destroy } from 'payload';
2
2
  export declare const destroy: Destroy;
3
3
  //# sourceMappingURL=destroy.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"destroy.d.ts","sourceRoot":"","sources":["../src/destroy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAM/C,eAAO,MAAM,OAAO,EAAE,OAQrB,CAAA"}
1
+ {"version":3,"file":"destroy.d.ts","sourceRoot":"","sources":["../src/destroy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAMtC,eAAO,MAAM,OAAO,EAAE,OAQrB,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/destroy.ts"],"sourcesContent":["import type { Destroy } from 'payload/database'\n\nimport mongoose from 'mongoose'\n\nimport type { MongooseAdapter } from './index.js'\n\nexport const destroy: Destroy = async function destroy(this: MongooseAdapter) {\n if (this.mongoMemoryServer) {\n await this.mongoMemoryServer.stop()\n } else {\n await mongoose.disconnect()\n }\n\n Object.keys(mongoose.models).map((model) => mongoose.deleteModel(model))\n}\n"],"names":["mongoose","destroy","mongoMemoryServer","stop","disconnect","Object","keys","models","map","model","deleteModel"],"rangeMappings":";;;;;;;;","mappings":"AAEA,OAAOA,cAAc,WAAU;AAI/B,OAAO,MAAMC,UAAmB,eAAeA;IAC7C,IAAI,IAAI,CAACC,iBAAiB,EAAE;QAC1B,MAAM,IAAI,CAACA,iBAAiB,CAACC,IAAI;IACnC,OAAO;QACL,MAAMH,SAASI,UAAU;IAC3B;IAEAC,OAAOC,IAAI,CAACN,SAASO,MAAM,EAAEC,GAAG,CAAC,CAACC,QAAUT,SAASU,WAAW,CAACD;AACnE,EAAC"}
1
+ {"version":3,"sources":["../src/destroy.ts"],"sourcesContent":["import type { Destroy } from 'payload'\n\nimport mongoose from 'mongoose'\n\nimport type { MongooseAdapter } from './index.js'\n\nexport const destroy: Destroy = async function destroy(this: MongooseAdapter) {\n if (this.mongoMemoryServer) {\n await this.mongoMemoryServer.stop()\n } else {\n await mongoose.disconnect()\n }\n\n Object.keys(mongoose.models).map((model) => mongoose.deleteModel(model))\n}\n"],"names":["mongoose","destroy","mongoMemoryServer","stop","disconnect","Object","keys","models","map","model","deleteModel"],"mappings":"AAEA,OAAOA,cAAc,WAAU;AAI/B,OAAO,MAAMC,UAAmB,eAAeA;IAC7C,IAAI,IAAI,CAACC,iBAAiB,EAAE;QAC1B,MAAM,IAAI,CAACA,iBAAiB,CAACC,IAAI;IACnC,OAAO;QACL,MAAMH,SAASI,UAAU;IAC3B;IAEAC,OAAOC,IAAI,CAACN,SAASO,MAAM,EAAEC,GAAG,CAAC,CAACC,QAAUT,SAASU,WAAW,CAACD;AACnE,EAAC"}
package/dist/find.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import type { Find } from 'payload/database';
1
+ import type { Find } from 'payload';
2
2
  export declare const find: Find;
3
3
  //# sourceMappingURL=find.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"find.d.ts","sourceRoot":"","sources":["../src/find.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAA;AAW5C,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,IA8HlB,CAAA"}
package/dist/find.js CHANGED
@@ -1,11 +1,13 @@
1
- import { flattenWhereToOperators } from 'payload/database';
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);
@@ -35,9 +37,24 @@ export const find = async function find({ collection, limit, locale, page, pagin
35
37
  options,
36
38
  page,
37
39
  pagination,
40
+ projection,
38
41
  sort,
39
42
  useEstimatedCount
40
43
  };
44
+ if (select) {
45
+ paginationOptions.projection = buildProjectionFromSelect({
46
+ adapter: this,
47
+ fields: collectionConfig.fields,
48
+ select
49
+ });
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
+ }
41
58
  if (!useEstimatedCount && Object.keys(query).length === 0 && this.disableIndexHints !== true) {
42
59
  // Improve the performance of the countDocuments query which is used if useEstimatedCount is set to false by adding
43
60
  // a hint. By default, if no hint is provided, MongoDB does not use an indexed field to count the returned documents,
@@ -61,12 +78,25 @@ export const find = async function find({ collection, limit, locale, page, pagin
61
78
  paginationOptions.pagination = false;
62
79
  }
63
80
  }
64
- const result = await Model.paginate(query, paginationOptions);
81
+ let result;
82
+ const aggregate = await buildJoinAggregation({
83
+ adapter: this,
84
+ collection,
85
+ collectionConfig,
86
+ joins,
87
+ locale,
88
+ query
89
+ });
90
+ // build join aggregation
91
+ if (aggregate) {
92
+ result = await Model.aggregatePaginate(Model.aggregate(aggregate), paginationOptions);
93
+ } else {
94
+ result = await Model.paginate(query, paginationOptions);
95
+ }
65
96
  const docs = JSON.parse(JSON.stringify(result.docs));
66
97
  return {
67
98
  ...result,
68
99
  docs: docs.map((doc)=>{
69
- // eslint-disable-next-line no-param-reassign
70
100
  doc.id = doc._id;
71
101
  return sanitizeInternalFields(doc);
72
102
  })
package/dist/find.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/find.ts"],"sourcesContent":["import type { PaginateOptions } from 'mongoose'\nimport type { Find } from 'payload/database'\nimport type { PayloadRequestWithData } from 'payload/types'\n\nimport { flattenWhereToOperators } from 'payload/database'\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"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAIA,SAASA,uBAAuB,QAAQ,mBAAkB;AAI1D,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,iBAA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,"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 forceCountFn: hasNearConstraint,\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","forceCountFn","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,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ACF;AACF,EAAC"}
@@ -1,3 +1,3 @@
1
- import type { FindGlobal } from 'payload/database';
1
+ import type { FindGlobal } from 'payload';
2
2
  export declare const findGlobal: FindGlobal;
3
3
  //# sourceMappingURL=findGlobal.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"findGlobal.d.ts","sourceRoot":"","sources":["../src/findGlobal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAUlD,eAAO,MAAM,UAAU,EAAE,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
- import { combineQueries } from 'payload/database';
2
- import sanitizeInternalFields from './utilities/sanitizeInternalFields.js';
1
+ import { combineQueries } from 'payload';
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 } from 'payload/database'\nimport type { PayloadRequestWithData } from 'payload/types'\n\nimport { combineQueries } from 'payload/database'\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"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAGA,SAASA,cAAc,QAAQ,mBAAkB;AAIjD,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,3 +1,3 @@
1
- import type { FindGlobalVersions } from 'payload/database';
1
+ import type { FindGlobalVersions } from 'payload';
2
2
  export declare const findGlobalVersions: FindGlobalVersions;
3
3
  //# sourceMappingURL=findGlobalVersions.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"findGlobalVersions.d.ts","sourceRoot":"","sources":["../src/findGlobalVersions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAA;AAY1D,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,kBA8GhC,CAAA"}
@@ -1,13 +1,13 @@
1
- import { flattenWhereToOperators } from 'payload/database';
2
- import { buildVersionGlobalFields } from 'payload/versions';
1
+ import { buildVersionGlobalFields, flattenWhereToOperators } from 'payload';
3
2
  import { buildSortParam } from './queries/buildSortParam.js';
4
- import sanitizeInternalFields from './utilities/sanitizeInternalFields.js';
3
+ import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
4
+ import { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js';
5
5
  import { withSession } from './withSession.js';
6
- 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 }) {
7
7
  const Model = this.versions[global];
8
- 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));
9
9
  const options = {
10
- ...withSession(this, req.transactionID),
10
+ ...await withSession(this, req),
11
11
  limit,
12
12
  skip
13
13
  };
@@ -38,13 +38,25 @@ export const findGlobalVersions = async function findGlobalVersions({ global, li
38
38
  forceCountFn: hasNearConstraint,
39
39
  lean: true,
40
40
  leanWithId: true,
41
- offset: skip,
41
+ limit,
42
42
  options,
43
43
  page,
44
44
  pagination,
45
+ projection: buildProjectionFromSelect({
46
+ adapter: this,
47
+ fields: versionFields,
48
+ select
49
+ }),
45
50
  sort,
46
51
  useEstimatedCount
47
52
  };
53
+ if (this.collation) {
54
+ const defaultLocale = 'en';
55
+ paginationOptions.collation = {
56
+ locale: locale && locale !== 'all' && locale !== '*' ? locale : defaultLocale,
57
+ ...this.collation
58
+ };
59
+ }
48
60
  if (!useEstimatedCount && Object.keys(query).length === 0 && this.disableIndexHints !== true) {
49
61
  // Improve the performance of the countDocuments query which is used if useEstimatedCount is set to false by adding
50
62
  // a hint. By default, if no hint is provided, MongoDB does not use an indexed field to count the returned documents,
@@ -73,7 +85,6 @@ export const findGlobalVersions = async function findGlobalVersions({ global, li
73
85
  return {
74
86
  ...result,
75
87
  docs: docs.map((doc)=>{
76
- // eslint-disable-next-line no-param-reassign
77
88
  doc.id = doc._id;
78
89
  return sanitizeInternalFields(doc);
79
90
  })
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/findGlobalVersions.ts"],"sourcesContent":["import type { PaginateOptions } from 'mongoose'\nimport type { FindGlobalVersions } from 'payload/database'\nimport type { PayloadRequestWithData } from 'payload/types'\n\nimport { flattenWhereToOperators } from 'payload/database'\nimport { buildVersionGlobalFields } from 'payload/versions'\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":["flattenWhereToOperators","buildVersionGlobalFields","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"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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CAACI,OAAOI,MAAM,KAAK;IACvF,MAAMC,oBAAqC;QACzCC,cAAcf;QACdgB,MAAM;QACNC,YAAY;QACZC,QAAQhC;QACRY;QACAf;QACAC;QACAG;QACAyB;IACF;IAEA,IAAI,CAACA,qBAAqBR,OAAOC,IAAI,CAACI,OAAOI,MAAM,KAAK,KAAK,IAAI,CAACM,iBAAiB,KAAK,MAAM;QAC5F,mHAAmH;QACnH,qHAAqH;QACrH,mHAAmH;QACnH,4BAA4B;QAC5BL,kBAAkBM,gBAAgB,GAAG;YACnC,OAAOC,QAAQC,OAAO,CACpBhC,MAAMiC,cAAc,CAACd,OAAO;gBAC1B,GAAGX,OAAO;gBACV0B,MAAM;oBAAEC,KAAK;gBAAE;YACjB;QAEJ;IACF;IAEA,IAAI5C,SAAS,GAAG;QACdiC,kBAAkBjC,KAAK,GAAGA;QAC1B,qEAAqE;QACrEiC,kBAAkBhB,OAAO,CAACjB,KAAK,GAAGA;QAElC,mCAAmC;QACnC,IAAIA,UAAU,GAAG;YACfiC,kBAAkB9B,UAAU,GAAG;QACjC;IACF;IAEA,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 forceCountFn: hasNearConstraint,\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","forceCountFn","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,QAAQ,UAAS;AAI3E,SAASC,cAAc,QAAQ,8BAA6B;AAC5D,SAASC,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,sBAAsB,QAAQ,wCAAuC;AAC9E,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,qBAAyC,eAAeA,mBAEnE,EACEC,MAAM,EACNC,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,OAAO;IACnC,MAAMa,gBAAgBpB,yBACpB,IAAI,CAACqB,OAAO,CAACC,MAAM,EACnB,IAAI,CAACD,OAAO,CAACE,OAAO,CAACD,MAAM,CAACE,IAAI,C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B;QAC5BR,kBAAkBS,gBAAgB,GAAG;YACnC,OAAOC,QAAQC,OAAO,CACpBlC,MAAMmC,cAAc,CAACjB,OAAO;gBAC1B,GAAGV,OAAO;gBACV4B,MAAM;oBAAEC,KAAK;gBAAE;YACjB;QAEJ;IACF;IAEA,IAAI/C,SAAS,GAAG;QACdiC,kBAAkBjC,KAAK,GAAGA;QAC1B,qEAAqE;QACrEiC,kBAAkBf,OAAO,CAAClB,KAAK,GAAGA;QAElC,mCAAmC;QACnC,IAAIA,UAAU,GAAG;YACfiC,kBAAkB9B,UAAU,GAAG;QACjC;IACF;IAEA,MAAM6C,SAAS,MAAMtC,MAAMuC,QAAQ,CAACrB,OAAOK;IAC3C,MAAMiB,OAAOC,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACL,OAAOE,IAAI;IAElD,OAAO;QACL,GAAGF,MAAM;QACTE,MAAMA,KAAKI,GAAG,CAAC,CAACC;YACdA,IAAIC,EAAE,GAAGD,IAAIR,GAAG;YAChB,OAAOnD,uBAAuB2D;QAChC;IACF;AACF,EAAC"}
package/dist/findOne.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import type { FindOne } from 'payload/database';
1
+ import type { FindOne } from 'payload';
2
2
  export declare const findOne: FindOne;
3
3
  //# sourceMappingURL=findOne.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"findOne.d.ts","sourceRoot":"","sources":["../src/findOne.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAS/C,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 { FindOne } from 'payload/database'\nimport type { PayloadRequestWithData } from 'payload/types'\nimport type { Document } from 'payload/types'\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"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;","mappings":"AAOA,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,2CAA0C;AACpF,SAASC,sBAAsB,QAAQ,wCAAuC;AAC9E,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,UAAmB,eAAeA,QAE7C,EAAEC,UAAU,EAAEC,KAAK,EAAEC,MAAM,EAAEC,MAAM,CAAC,CAAmB,EAAEC,MAAM,EAAEC,KAAK,EAAE;IAExE,MAAMC,QAAQ,IAAI,CAACC,WAAW,CAACP,WAAW;IAC1C,MAAMQ,mBAAmB,IAAI,CAACC,OAAO,CAACF,WAAW,CAACP,WAAW,CAACU,MAAM;IACpE,MAAMC,UAAgC;QACpC,GAAI,MAAMb,YAAY,IAAI,EAAEK,IAAI;QAChCS,MAAM;IACR;IAEA,MAAMC,QAAQ,MAAMP,MAAMQ,UAAU,CAAC;QACnCZ;QACAO,SAAS,IAAI,CAACA,OAAO;QACrBJ;IACF;IAEA,MAAMU,aAAanB,0BAA0B;QAC3CoB,SAAS,IAAI;QACbC,QAAQT,iBAAiBS,MAAM;QAC/Bb;IACF;IAEA,MAAMc,YAAY,MAAMvB,qBAAqB;QAC3CqB,SAAS,IAAI;QACbhB;QACAQ;QACAP;QACAkB,OAAO;QACPjB;QACAa;QACAF;IACF;IAEA,IAAIO;IACJ,IAAIF,WAAW;QACZ,CAACE,IAAI,GAAG,MAAMd,MAAMY,SAAS,CAACA,WAAWP;IAC5C,OAAO;QACHA,QAAoCI,UAAU,GAAGA;QACnDK,MAAM,MAAMd,MAAMP,OAAO,CAACc,OAAO,CAAC,GAAGF;IACvC;IAEA,IAAI,CAACS,KAAK;QACR,OAAO;IACT;IAEA,IAAIC,SAAmBC,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACJ;IAEjD,uBAAuB;IACvBC,OAAOI,EAAE,GAAGJ,OAAOK,GAAG;IACtBL,SAASxB,uBAAuBwB;IAEhC,OAAOA;AACT,EAAC"}
@@ -1,3 +1,3 @@
1
- import type { FindVersions } from 'payload/database';
1
+ import type { FindVersions } from 'payload';
2
2
  export declare const findVersions: FindVersions;
3
3
  //# sourceMappingURL=findVersions.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"findVersions.d.ts","sourceRoot":"","sources":["../src/findVersions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAWpD,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,YA8G1B,CAAA"}
@@ -1,12 +1,13 @@
1
- import { flattenWhereToOperators } from 'payload/database';
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
  };
@@ -40,9 +41,21 @@ export const findVersions = async function findVersions({ collection, limit, loc
40
41
  options,
41
42
  page,
42
43
  pagination,
44
+ projection: buildProjectionFromSelect({
45
+ adapter: this,
46
+ fields: buildVersionCollectionFields(this.payload.config, collectionConfig),
47
+ select
48
+ }),
43
49
  sort,
44
50
  useEstimatedCount
45
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
+ }
46
59
  if (!useEstimatedCount && Object.keys(query).length === 0 && this.disableIndexHints !== true) {
47
60
  // Improve the performance of the countDocuments query which is used if useEstimatedCount is set to false by adding
48
61
  // a hint. By default, if no hint is provided, MongoDB does not use an indexed field to count the returned documents,
@@ -71,7 +84,6 @@ export const findVersions = async function findVersions({ collection, limit, loc
71
84
  return {
72
85
  ...result,
73
86
  docs: docs.map((doc)=>{
74
- // eslint-disable-next-line no-param-reassign
75
87
  doc.id = doc._id;
76
88
  return sanitizeInternalFields(doc);
77
89
  })
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/findVersions.ts"],"sourcesContent":["import type { PaginateOptions } from 'mongoose'\nimport type { FindVersions } from 'payload/database'\nimport type { PayloadRequestWithData } from 'payload/types'\n\nimport { flattenWhereToOperators } from 'payload/database'\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"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAIA,SAASA,uBAAuB,QAAQ,mBAAkB;AAI1D,SAASC,cAAc,QAAQ,8BAA6B;AAC5D,OAAOC,4BAA4B,wCAAuC;AAC1E,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,eAA6B,eAAeA,aAEvD,EACEC,UAAU,EACVC,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,WAAW;IACvC,MAAMY,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EAAqE;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 forceCountFn: hasNearConstraint,\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","forceCountFn","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;YACjBiB,YAAY;QACd;IACF;IAEA,MAAMC,QAAQ,MAAMhB,MAAMiB,UAAU,CAAC;QACnC1B;QACAY,SAAS,IAAI,CAACA,OAAO;QACrBJ;IACF;IAEA,4HAA4H;IAC5H,MAAMmB,oBAAoBX,qBAAqB,CAACS,SAASL,OAAOC,IAAI,CA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