@payloadcms/db-mongodb 3.0.0-canary.c13f9ba → 3.0.0-canary.c696728

Sign up to get free protection for your applications and to get access to all the features.
Files changed (180) 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/create.d.ts +1 -1
  11. package/dist/create.d.ts.map +1 -1
  12. package/dist/create.js +14 -4
  13. package/dist/create.js.map +1 -1
  14. package/dist/createGlobal.d.ts +1 -1
  15. package/dist/createGlobal.d.ts.map +1 -1
  16. package/dist/createGlobal.js +11 -6
  17. package/dist/createGlobal.js.map +1 -1
  18. package/dist/createGlobalVersion.d.ts +1 -1
  19. package/dist/createGlobalVersion.d.ts.map +1 -1
  20. package/dist/createGlobalVersion.js +14 -5
  21. package/dist/createGlobalVersion.js.map +1 -1
  22. package/dist/createMigration.d.ts +1 -1
  23. package/dist/createMigration.d.ts.map +1 -1
  24. package/dist/createMigration.js +2 -2
  25. package/dist/createMigration.js.map +1 -1
  26. package/dist/createVersion.d.ts +1 -1
  27. package/dist/createVersion.d.ts.map +1 -1
  28. package/dist/createVersion.js +15 -6
  29. package/dist/createVersion.js.map +1 -1
  30. package/dist/deleteMany.d.ts +1 -1
  31. package/dist/deleteMany.d.ts.map +1 -1
  32. package/dist/deleteMany.js +1 -1
  33. package/dist/deleteMany.js.map +1 -1
  34. package/dist/deleteOne.d.ts +1 -1
  35. package/dist/deleteOne.d.ts.map +1 -1
  36. package/dist/deleteOne.js +2 -2
  37. package/dist/deleteOne.js.map +1 -1
  38. package/dist/deleteVersions.d.ts +1 -1
  39. package/dist/deleteVersions.d.ts.map +1 -1
  40. package/dist/deleteVersions.js +1 -1
  41. package/dist/deleteVersions.js.map +1 -1
  42. package/dist/destroy.d.ts +1 -1
  43. package/dist/destroy.d.ts.map +1 -1
  44. package/dist/destroy.js.map +1 -1
  45. package/dist/find.d.ts +1 -1
  46. package/dist/find.d.ts.map +1 -1
  47. package/dist/find.js +29 -6
  48. package/dist/find.js.map +1 -1
  49. package/dist/findGlobal.d.ts +1 -1
  50. package/dist/findGlobal.d.ts.map +1 -1
  51. package/dist/findGlobal.js +3 -3
  52. package/dist/findGlobal.js.map +1 -1
  53. package/dist/findGlobalVersions.d.ts +1 -1
  54. package/dist/findGlobalVersions.d.ts.map +1 -1
  55. package/dist/findGlobalVersions.js +12 -7
  56. package/dist/findGlobalVersions.js.map +1 -1
  57. package/dist/findOne.d.ts +1 -1
  58. package/dist/findOne.d.ts.map +1 -1
  59. package/dist/findOne.js +20 -4
  60. package/dist/findOne.js.map +1 -1
  61. package/dist/findVersions.d.ts +1 -1
  62. package/dist/findVersions.d.ts.map +1 -1
  63. package/dist/findVersions.js +10 -4
  64. package/dist/findVersions.js.map +1 -1
  65. package/dist/index.d.ts +49 -35
  66. package/dist/index.d.ts.map +1 -1
  67. package/dist/index.js +8 -4
  68. package/dist/index.js.map +1 -1
  69. package/dist/init.d.ts +1 -1
  70. package/dist/init.d.ts.map +1 -1
  71. package/dist/init.js +11 -8
  72. package/dist/init.js.map +1 -1
  73. package/dist/migrateFresh.d.ts.map +1 -1
  74. package/dist/migrateFresh.js +1 -1
  75. package/dist/migrateFresh.js.map +1 -1
  76. package/dist/models/buildCollectionSchema.d.ts +2 -29
  77. package/dist/models/buildCollectionSchema.d.ts.map +1 -1
  78. package/dist/models/buildCollectionSchema.js +16 -4
  79. package/dist/models/buildCollectionSchema.js.map +1 -1
  80. package/dist/models/buildGlobalModel.d.ts +1 -1
  81. package/dist/models/buildGlobalModel.d.ts.map +1 -1
  82. package/dist/models/buildGlobalModel.js +2 -2
  83. package/dist/models/buildGlobalModel.js.map +1 -1
  84. package/dist/models/buildSchema.d.ts +2 -29
  85. package/dist/models/buildSchema.d.ts.map +1 -1
  86. package/dist/models/buildSchema.js +100 -22
  87. package/dist/models/buildSchema.js.map +1 -1
  88. package/dist/predefinedMigrations/versions-v1-v2.js.map +1 -1
  89. package/dist/queries/buildAndOrConditions.d.ts +1 -2
  90. package/dist/queries/buildAndOrConditions.d.ts.map +1 -1
  91. package/dist/queries/buildAndOrConditions.js +0 -2
  92. package/dist/queries/buildAndOrConditions.js.map +1 -1
  93. package/dist/queries/buildQuery.d.ts +3 -4
  94. package/dist/queries/buildQuery.d.ts.map +1 -1
  95. package/dist/queries/buildQuery.js +2 -3
  96. package/dist/queries/buildQuery.js.map +1 -1
  97. package/dist/queries/buildSearchParams.d.ts +1 -2
  98. package/dist/queries/buildSearchParams.d.ts.map +1 -1
  99. package/dist/queries/buildSearchParams.js +21 -13
  100. package/dist/queries/buildSearchParams.js.map +1 -1
  101. package/dist/queries/buildSortParam.d.ts +2 -28
  102. package/dist/queries/buildSortParam.d.ts.map +1 -1
  103. package/dist/queries/buildSortParam.js.map +1 -1
  104. package/dist/queries/getLocalizedSortProperty.d.ts +1 -2
  105. package/dist/queries/getLocalizedSortProperty.d.ts.map +1 -1
  106. package/dist/queries/getLocalizedSortProperty.js +2 -2
  107. package/dist/queries/getLocalizedSortProperty.js.map +1 -1
  108. package/dist/queries/getLocalizedSortProperty.spec.js +44 -44
  109. package/dist/queries/getLocalizedSortProperty.spec.js.map +1 -1
  110. package/dist/queries/mock.js.map +1 -1
  111. package/dist/queries/operatorMap.js.map +1 -1
  112. package/dist/queries/parseParams.d.ts +1 -3
  113. package/dist/queries/parseParams.d.ts.map +1 -1
  114. package/dist/queries/parseParams.js +6 -7
  115. package/dist/queries/parseParams.js.map +1 -1
  116. package/dist/queries/sanitizeQueryValue.d.ts +1 -1
  117. package/dist/queries/sanitizeQueryValue.d.ts.map +1 -1
  118. package/dist/queries/sanitizeQueryValue.js +132 -25
  119. package/dist/queries/sanitizeQueryValue.js.map +1 -1
  120. package/dist/queryDrafts.d.ts +1 -1
  121. package/dist/queryDrafts.d.ts.map +1 -1
  122. package/dist/queryDrafts.js +10 -4
  123. package/dist/queryDrafts.js.map +1 -1
  124. package/dist/testCredentials.js.map +1 -1
  125. package/dist/transactions/beginTransaction.d.ts +1 -1
  126. package/dist/transactions/beginTransaction.d.ts.map +1 -1
  127. package/dist/transactions/beginTransaction.js +3 -1
  128. package/dist/transactions/beginTransaction.js.map +1 -1
  129. package/dist/transactions/commitTransaction.d.ts +1 -1
  130. package/dist/transactions/commitTransaction.d.ts.map +1 -1
  131. package/dist/transactions/commitTransaction.js +3 -0
  132. package/dist/transactions/commitTransaction.js.map +1 -1
  133. package/dist/transactions/rollbackTransaction.d.ts +1 -1
  134. package/dist/transactions/rollbackTransaction.d.ts.map +1 -1
  135. package/dist/transactions/rollbackTransaction.js +13 -7
  136. package/dist/transactions/rollbackTransaction.js.map +1 -1
  137. package/dist/types.d.ts +5 -31
  138. package/dist/types.d.ts.map +1 -1
  139. package/dist/types.js.map +1 -1
  140. package/dist/updateGlobal.d.ts +1 -1
  141. package/dist/updateGlobal.d.ts.map +1 -1
  142. package/dist/updateGlobal.js +9 -3
  143. package/dist/updateGlobal.js.map +1 -1
  144. package/dist/updateGlobalVersion.d.ts +2 -3
  145. package/dist/updateGlobalVersion.d.ts.map +1 -1
  146. package/dist/updateGlobalVersion.js +11 -4
  147. package/dist/updateGlobalVersion.js.map +1 -1
  148. package/dist/updateOne.d.ts +1 -1
  149. package/dist/updateOne.d.ts.map +1 -1
  150. package/dist/updateOne.js +15 -5
  151. package/dist/updateOne.js.map +1 -1
  152. package/dist/updateVersion.d.ts +1 -1
  153. package/dist/updateVersion.d.ts.map +1 -1
  154. package/dist/updateVersion.js +9 -2
  155. package/dist/updateVersion.js.map +1 -1
  156. package/dist/utilities/buildJoinAggregation.d.ts +15 -0
  157. package/dist/utilities/buildJoinAggregation.d.ts.map +1 -0
  158. package/dist/utilities/buildJoinAggregation.js +148 -0
  159. package/dist/utilities/buildJoinAggregation.js.map +1 -0
  160. package/dist/utilities/getDBName.d.ts +1 -1
  161. package/dist/utilities/getDBName.d.ts.map +1 -1
  162. package/dist/utilities/getDBName.js +3 -1
  163. package/dist/utilities/getDBName.js.map +1 -1
  164. package/dist/utilities/handleError.d.ts +6 -2
  165. package/dist/utilities/handleError.d.ts.map +1 -1
  166. package/dist/utilities/handleError.js +12 -9
  167. package/dist/utilities/handleError.js.map +1 -1
  168. package/dist/utilities/sanitizeInternalFields.d.ts +1 -2
  169. package/dist/utilities/sanitizeInternalFields.d.ts.map +1 -1
  170. package/dist/utilities/sanitizeInternalFields.js +1 -2
  171. package/dist/utilities/sanitizeInternalFields.js.map +1 -1
  172. package/dist/utilities/sanitizeRelationshipIDs.d.ts +9 -0
  173. package/dist/utilities/sanitizeRelationshipIDs.d.ts.map +1 -0
  174. package/dist/utilities/sanitizeRelationshipIDs.js +111 -0
  175. package/dist/utilities/sanitizeRelationshipIDs.js.map +1 -0
  176. package/dist/withSession.d.ts +3 -27
  177. package/dist/withSession.d.ts.map +1 -1
  178. package/dist/withSession.js +10 -4
  179. package/dist/withSession.js.map +1 -1
  180. package/package.json +14 -13
package/dist/find.js CHANGED
@@ -1,11 +1,12 @@
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 { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js';
4
5
  import { withSession } from './withSession.js';
5
- export const find = async function find({ collection, limit, locale, page, pagination, req = {}, sort: sortArg, where }) {
6
+ export const find = async function find({ collection, joins = {}, limit, locale, page, pagination, projection, req = {}, sort: sortArg, where }) {
6
7
  const Model = this.collections[collection];
7
8
  const collectionConfig = this.payload.collections[collection].config;
8
- const options = withSession(this, req.transactionID);
9
+ const options = await withSession(this, req);
9
10
  let hasNearConstraint = false;
10
11
  if (where) {
11
12
  const constraints = flattenWhereToOperators(where);
@@ -35,9 +36,17 @@ export const find = async function find({ collection, limit, locale, page, pagin
35
36
  options,
36
37
  page,
37
38
  pagination,
39
+ projection,
38
40
  sort,
39
41
  useEstimatedCount
40
42
  };
43
+ if (this.collation) {
44
+ const defaultLocale = 'en';
45
+ paginationOptions.collation = {
46
+ locale: locale && locale !== 'all' && locale !== '*' ? locale : defaultLocale,
47
+ ...this.collation
48
+ };
49
+ }
41
50
  if (!useEstimatedCount && Object.keys(query).length === 0 && this.disableIndexHints !== true) {
42
51
  // Improve the performance of the countDocuments query which is used if useEstimatedCount is set to false by adding
43
52
  // a hint. By default, if no hint is provided, MongoDB does not use an indexed field to count the returned documents,
@@ -61,12 +70,26 @@ export const find = async function find({ collection, limit, locale, page, pagin
61
70
  paginationOptions.pagination = false;
62
71
  }
63
72
  }
64
- const result = await Model.paginate(query, paginationOptions);
73
+ let result;
74
+ const aggregate = await buildJoinAggregation({
75
+ adapter: this,
76
+ collection,
77
+ collectionConfig,
78
+ joins,
79
+ limit,
80
+ locale,
81
+ query
82
+ });
83
+ // build join aggregation
84
+ if (aggregate) {
85
+ result = await Model.aggregatePaginate(Model.aggregate(aggregate), paginationOptions);
86
+ } else {
87
+ result = await Model.paginate(query, paginationOptions);
88
+ }
65
89
  const docs = JSON.parse(JSON.stringify(result.docs));
66
90
  return {
67
91
  ...result,
68
92
  docs: docs.map((doc)=>{
69
- // eslint-disable-next-line no-param-reassign
70
93
  doc.id = doc._id;
71
94
  return sanitizeInternalFields(doc);
72
95
  })
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,iBAAiBY,MAAM;YAC/BrB;YACAI,MA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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 { 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,\n locale,\n page,\n pagination,\n projection,\n req = {} as PayloadRequest,\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 (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 limit,\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","sanitizeInternalFields","withSession","find","collection","joins","limit","locale","page","pagination","projection","req","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","collation","defaultLocale","disableIndexHints","useCustomCountFn","Promise","resolve","countDocuments","hint","_id","result","aggregate","adapter","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,sBAAsB,QAAQ,wCAAuC;AAC9E,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,OAAa,eAAeA,KAEvC,EACEC,UAAU,EACVC,QAAQ,CAAC,CAAC,EACVC,KAAK,EACLC,MAAM,EACNC,IAAI,EACJC,UAAU,EACVC,UAAU,EACVC,MAAM,CAAC,CAAmB,EAC1BC,MAAMC,OAAO,E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BAA4B;QAC5BN,kBAAkBO,gBAAgB,GAAG;YACnC,OAAOC,QAAQC,OAAO,CACpB7B,MAAM8B,cAAc,CAACd,OAAO;gBAC1B,GAAGX,OAAO;gBACV0B,MAAM;oBAAEC,KAAK;gBAAE;YACjB;QAEJ;IACF;IAEA,IAAIzC,SAAS,GAAG;QACd6B,kBAAkB7B,KAAK,GAAGA;QAC1B,qEAAqE;QACrE6B,kBAAkBf,OAAO,CAACd,KAAK,GAAGA;QAElC,mCAAmC;QACnC,IAAIA,UAAU,GAAG;YACf6B,kBAAkB1B,UAAU,GAAG;QACjC;IACF;IAEA,IAAIuC;IAEJ,MAAMC,YAAY,MAAMjD,qBAAqB;QAC3CkD,SAAS,IAAI;QACb9C;QACAa;QACAZ;QACAC;QACAC;QACAwB;IACF;IACA,yBAAyB;IACzB,IAAIkB,WAAW;QACbD,SAAS,MAAMjC,MAAMoC,iBAAiB,CAACpC,MAAMkC,SAAS,CAACA,YAAYd;IACrE,OAAO;QACLa,SAAS,MAAMjC,MAAMqC,QAAQ,CAACrB,OAAOI;IACvC;IAEA,MAAMkB,OAAOC,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACR,OAAOK,IAAI;IAElD,OAAO;QACL,GAAGL,MAAM;QACTK,MAAMA,KAAKI,GAAG,CAAC,CAACC;YACdA,IAAIC,EAAE,GAAGD,IAAIX,GAAG;YAChB,OAAO9C,uBAAuByD;QAChC;IACF;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;AASzD,eAAO,MAAM,UAAU,EAAE,UA+BxB,CAAA"}
@@ -1,10 +1,10 @@
1
- import { combineQueries } from 'payload/database';
2
- import sanitizeInternalFields from './utilities/sanitizeInternalFields.js';
1
+ import { combineQueries } from 'payload';
2
+ import { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js';
3
3
  import { withSession } from './withSession.js';
4
4
  export const findGlobal = async function findGlobal({ slug, locale, req = {}, where }) {
5
5
  const Model = this.globals;
6
6
  const options = {
7
- ...withSession(this, req.transactionID),
7
+ ...await withSession(this, req),
8
8
  lean: true
9
9
  };
10
10
  const query = await Model.buildQuery({
@@ -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 { 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, where },\n) {\n const Model = this.globals\n const options = {\n ...(await withSession(this, req)),\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","lean","query","buildQuery","globalSlug","payload","globalType","equals","doc","findOne","_id","id","JSON","parse","stringify"],"mappings":"AAEA,SAASA,cAAc,QAAQ,UAAS;AAIxC,SAASC,sBAAsB,QAAQ,wCAAuC;AAC9E,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,aAAyB,eAAeA,WAEnD,EAAEC,IAAI,EAAEC,MAAM,EAAEC,MAAM,CAAC,CAAmB,EAAEC,KAAK,EAAE;IAEnD,MAAMC,QAAQ,IAAI,CAACC,OAAO;IAC1B,MAAMC,UAAU;QACd,GAAI,MAAMR,YAAY,IAAI,EAAEI,IAAI;QAChCK,MAAM;IACR;IAEA,MAAMC,QAAQ,MAAMJ,MAAMK,UAAU,CAAC;QACnCC,YAAYV;QACZC;QACAU,SAAS,IAAI,CAACA,OAAO;QACrBR,OAAOP,eAAe;YAAEgB,YAAY;gBAAEC,QAAQb;YAAK;QAAE,GAAGG;IAC1D;IAEA,IAAIW,MAAO,MAAMV,MAAMW,OAAO,CAACP,OAAO,CAAC,GAAGF;IAE1C,IAAI,CAACQ,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,MAAMjB,uBAAuBiB;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;AAUjE,eAAO,MAAM,kBAAkB,EAAE,kBA4GhC,CAAA"}
@@ -1,13 +1,12 @@
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 { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js';
5
4
  import { withSession } from './withSession.js';
6
5
  export const findGlobalVersions = async function findGlobalVersions({ global, limit, locale, page, pagination, req = {}, skip, sort: sortArg, where }) {
7
6
  const Model = this.versions[global];
8
- const versionFields = buildVersionGlobalFields(this.payload.globals.config.find(({ slug })=>slug === global));
7
+ const versionFields = buildVersionGlobalFields(this.payload.config, this.payload.globals.config.find(({ slug })=>slug === global));
9
8
  const options = {
10
- ...withSession(this, req.transactionID),
9
+ ...await withSession(this, req),
11
10
  limit,
12
11
  skip
13
12
  };
@@ -38,13 +37,20 @@ export const findGlobalVersions = async function findGlobalVersions({ global, li
38
37
  forceCountFn: hasNearConstraint,
39
38
  lean: true,
40
39
  leanWithId: true,
41
- offset: skip,
40
+ limit,
42
41
  options,
43
42
  page,
44
43
  pagination,
45
44
  sort,
46
45
  useEstimatedCount
47
46
  };
47
+ if (this.collation) {
48
+ const defaultLocale = 'en';
49
+ paginationOptions.collation = {
50
+ locale: locale && locale !== 'all' && locale !== '*' ? locale : defaultLocale,
51
+ ...this.collation
52
+ };
53
+ }
48
54
  if (!useEstimatedCount && Object.keys(query).length === 0 && this.disableIndexHints !== true) {
49
55
  // Improve the performance of the countDocuments query which is used if useEstimatedCount is set to false by adding
50
56
  // a hint. By default, if no hint is provided, MongoDB does not use an indexed field to count the returned documents,
@@ -73,7 +79,6 @@ export const findGlobalVersions = async function findGlobalVersions({ global, li
73
79
  return {
74
80
  ...result,
75
81
  docs: docs.map((doc)=>{
76
- // eslint-disable-next-line no-param-reassign
77
82
  doc.id = doc._id;
78
83
  return sanitizeInternalFields(doc);
79
84
  })
@@ -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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAIA,SAASA,uBAAuB,QAAQ,mBAAkB;AAC1D,SAASC,wBAAwB,QAAQ,mBAAkB;AAI3D,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,gBAAgBjB,yBACpB,IAAI,CAACkB,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;QACAK;IACF;IAEA,IAAIc,oBAAoB;IAExB,IAAIX,OAAO;QACT,MAAMY,cAAc3B,wBAAwBe;QAC5CW,oBAAoBC,YAAYC,IAAI,CAAC,CAACC,OAASC,OAAOC,IAAI,CAACF,MAAMD,IAAI,CAAC,CAACI,MAAQA,QAAQ;IACzF;IAEA,IAAInB;IACJ,IAAI,CAACa,mBAAmB;QACtBb,OAAOX,eAAe;YACpBmB,QAAQ,IAAI,CAACF,OAAO,CAACE,MAAM;YAC3BY,QAAQf;YACRV;YACAK,MAAMC,WAAW;YACjBoB,YAAY;QACd;IACF;IAEA,MAAMC,QAAQ,MAAMnB,MAAMoB,UAAU,CAAC;QACnCC,YAAY/B;QACZE;QACAW,SAAS,IAAI,CAACA,OAAO;QACrBJ;IACF;IAEA,4HAA4H;IAC5H,MAAMuB,oBAAoBZ,qBAAqB,CAACS,SAASL,OAAOC,IAAI,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 { 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 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 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","sanitizeInternalFields","withSession","findGlobalVersions","global","limit","locale","page","pagination","req","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","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,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,IAAI,EACJC,MAAMC,OAAO,EACbC,KAAK,EACN;IAED,MAAMC,QAAQ,IAAI,CAACC,QAAQ,CAACX,OAAO;IACnC,MAAMY,gBAAgBlB,yBACpB,IAAI,CAACmB,OAAO,CAACC,MAAM,EACnB,IAAI,CAACD,OAAO,CAACE,OAAO,CAACD,MAAM,CAACE,IAAI,CAAC,CAAC,EAAEC,IAAI,EAAE,GAAKA,SAASjB;IAE1D,MAAMkB,UAAU;QACd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AAE;YACjB;QAEJ;IACF;IAEA,IAAI5C,SAAS,GAAG;QACdgC,kBAAkBhC,KAAK,GAAGA;QAC1B,qEAAqE;QACrEgC,kBAAkBf,OAAO,CAACjB,KAAK,GAAGA;QAElC,mCAAmC;QACnC,IAAIA,UAAU,GAAG;YACfgC,kBAAkB7B,UAAU,GAAG;QACjC;IACF;IAEA,MAAM0C,SAAS,MAAMpC,MAAMqC,QAAQ,CAACnB,OAAOK;IAC3C,MAAMe,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,OAAOhD,uBAAuBwD;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;AAQhE,eAAO,MAAM,OAAO,EAAE,OA6CrB,CAAA"}
package/dist/findOne.js CHANGED
@@ -1,9 +1,11 @@
1
- import sanitizeInternalFields from './utilities/sanitizeInternalFields.js';
1
+ import { buildJoinAggregation } from './utilities/buildJoinAggregation.js';
2
+ import { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js';
2
3
  import { withSession } from './withSession.js';
3
- export const findOne = async function findOne({ collection, locale, req = {}, where }) {
4
+ export const findOne = async function findOne({ collection, joins, locale, req = {}, where }) {
4
5
  const Model = this.collections[collection];
6
+ const collectionConfig = this.payload.collections[collection].config;
5
7
  const options = {
6
- ...withSession(this, req.transactionID),
8
+ ...await withSession(this, req),
7
9
  lean: true
8
10
  };
9
11
  const query = await Model.buildQuery({
@@ -11,7 +13,21 @@ export const findOne = async function findOne({ collection, locale, req = {}, wh
11
13
  payload: this.payload,
12
14
  where
13
15
  });
14
- const doc = await Model.findOne(query, {}, options);
16
+ const aggregate = await buildJoinAggregation({
17
+ adapter: this,
18
+ collection,
19
+ collectionConfig,
20
+ joins,
21
+ limit: 1,
22
+ locale,
23
+ query
24
+ });
25
+ let doc;
26
+ if (aggregate) {
27
+ [doc] = await Model.aggregate(aggregate, options);
28
+ } else {
29
+ doc = await Model.findOne(query, {}, options);
30
+ }
15
31
  if (!doc) {
16
32
  return null;
17
33
  }
@@ -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 } from 'mongoose'\nimport type { Document, FindOne, PayloadRequest } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildJoinAggregation } from './utilities/buildJoinAggregation.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, 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 aggregate = await buildJoinAggregation({\n adapter: this,\n collection,\n collectionConfig,\n joins,\n limit: 1,\n locale,\n query,\n })\n\n let doc\n if (aggregate) {\n ;[doc] = await Model.aggregate(aggregate, options)\n } else {\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","sanitizeInternalFields","withSession","findOne","collection","joins","locale","req","where","Model","collections","collectionConfig","payload","config","options","lean","query","buildQuery","aggregate","adapter","limit","doc","result","JSON","parse","stringify","id","_id"],"mappings":"AAKA,SAASA,oBAAoB,QAAQ,sCAAqC;AAC1E,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,KAAK,EAAE;IAEhE,MAAMC,QAAQ,IAAI,CAACC,WAAW,CAACN,WAAW;IAC1C,MAAMO,mBAAmB,IAAI,CAACC,OAAO,CAACF,WAAW,CAACN,WAAW,CAACS,MAAM;IACpE,MAAMC,UAAgC;QACpC,GAAI,MAAMZ,YAAY,IAAI,EAAEK,IAAI;QAChCQ,MAAM;IACR;IAEA,MAAMC,QAAQ,MAAMP,MAAMQ,UAAU,CAAC;QACnCX;QACAM,SAAS,IAAI,CAACA,OAAO;QACrBJ;IACF;IAEA,MAAMU,YAAY,MAAMlB,qBAAqB;QAC3CmB,SAAS,IAAI;QACbf;QACAO;QACAN;QACAe,OAAO;QACPd;QACAU;IACF;IAEA,IAAIK;IACJ,IAAIH,WAAW;QACZ,CAACG,IAAI,GAAG,MAAMZ,MAAMS,SAAS,CAACA,WAAWJ;IAC5C,OAAO;QACLO,MAAM,MAAMZ,MAAMN,OAAO,CAACa,OAAO,CAAC,GAAGF;IACvC;IAEA,IAAI,CAACO,KAAK;QACR,OAAO;IACT;IAEA,IAAIC,SAAmBC,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACJ;IAEjD,uBAAuB;IACvBC,OAAOI,EAAE,GAAGJ,OAAOK,GAAG;IACtBL,SAASrB,uBAAuBqB;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;AAU3D,eAAO,MAAM,YAAY,EAAE,YAwG1B,CAAA"}
@@ -1,12 +1,12 @@
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 { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js';
4
4
  import { withSession } from './withSession.js';
5
5
  export const findVersions = async function findVersions({ collection, limit, locale, page, pagination, req = {}, skip, sort: sortArg, where }) {
6
6
  const Model = this.versions[collection];
7
7
  const collectionConfig = this.payload.collections[collection].config;
8
8
  const options = {
9
- ...withSession(this, req.transactionID),
9
+ ...await withSession(this, req),
10
10
  limit,
11
11
  skip
12
12
  };
@@ -43,6 +43,13 @@ export const findVersions = async function findVersions({ collection, limit, loc
43
43
  sort,
44
44
  useEstimatedCount
45
45
  };
46
+ if (this.collation) {
47
+ const defaultLocale = 'en';
48
+ paginationOptions.collation = {
49
+ locale: locale && locale !== 'all' && locale !== '*' ? locale : defaultLocale,
50
+ ...this.collation
51
+ };
52
+ }
46
53
  if (!useEstimatedCount && Object.keys(query).length === 0 && this.disableIndexHints !== true) {
47
54
  // Improve the performance of the countDocuments query which is used if useEstimatedCount is set to false by adding
48
55
  // a hint. By default, if no hint is provided, MongoDB does not use an indexed field to count the returned documents,
@@ -71,7 +78,6 @@ export const findVersions = async function findVersions({ collection, limit, loc
71
78
  return {
72
79
  ...result,
73
80
  docs: docs.map((doc)=>{
74
- // eslint-disable-next-line no-param-reassign
75
81
  doc.id = doc._id;
76
82
  return sanitizeInternalFields(doc);
77
83
  })
@@ -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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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,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 { 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 PayloadRequest,\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 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":["flattenWhereToOperators","buildSortParam","sanitizeInternalFields","withSession","findVersions","collection","limit","locale","page","pagination","req","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","collation","defaultLocale","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,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,IAAI,EACJC,MAAMC,OAAO,EACbC,KAAK,EACN;IAED,MAAMC,QAAQ,IAAI,CAACC,QAAQ,CAACX,WAAW;IACvC,MAAMY,mBAAmB,IAAI,CAACC,OAAO,CAACC,WAAW,CAACd,WAAW,CAACe,MAAM;IACpE,MAAMC,UAAU;QACd,GAAI,MAAMlB,YAAY,IAAI,EAAEO,IAAI;QAChCJ;QACAK;IACF;IAEA,IAAIW,oBAAoB;IAExB,IAAIR,OAAO;QACT,MAAMS,cAAcvB,wBAAwBc;QAC5CQ,oBAAoBC,YAAYC,IAAI,CAAC,CAACC,OAASC,OAAOC,IAAI,CAACF,MAAMD,IAAI,CAAC,CAACI,MAAQA,QAAQ;IACzF;IAEA,IAAIhB;IACJ,IAAI,CAACU,mBAAmB;QACtBV,OAAOX,eAAe;YACpBmB,QAAQ,IAAI,CAACF,OAAO,CAACE,MAAM;YAC3BS,QAAQZ,iBAAiBY,MAAM;YAC/BtB;YACAK,MAAMC,WAAW;YACjBiB,YAAY;QACd;IACF;IAEA,MAAMC,QAAQ,MAAMhB,MAAMiB,UAAU,CAAC;QACnCzB;QACAW,SAAS,IAAI,CAACA,OAAO;QACrBJ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
@@ -1,42 +1,41 @@
1
- /// <reference types="mongoose/types/aggregate.js" />
2
- /// <reference types="mongoose/types/callback.js" />
3
- /// <reference types="mongoose/types/collection.js" />
4
- /// <reference types="mongoose/types/connection.js" />
5
- /// <reference types="mongoose/types/cursor.js" />
6
- /// <reference types="mongoose/types/document.js" />
7
- /// <reference types="mongoose/types/error.js" />
8
- /// <reference types="mongoose/types/expressions.js" />
9
- /// <reference types="mongoose/types/helpers.js" />
10
- /// <reference types="mongoose/types/middlewares.js" />
11
- /// <reference types="mongoose/types/indexes.js" />
12
- /// <reference types="mongoose/types/models.js" />
13
- /// <reference types="mongoose/types/mongooseoptions.js" />
14
- /// <reference types="mongoose/types/pipelinestage.js" />
15
- /// <reference types="mongoose/types/populate.js" />
16
- /// <reference types="mongoose/types/query.js" />
17
- /// <reference types="mongoose/types/schemaoptions.js" />
18
- /// <reference types="mongoose/types/schematypes.js" />
19
- /// <reference types="mongoose/types/session.js" />
20
- /// <reference types="mongoose/types/types.js" />
21
- /// <reference types="mongoose/types/utility.js" />
22
- /// <reference types="mongoose/types/validation.js" />
23
- /// <reference types="mongoose/types/virtuals.js" />
24
- /// <reference types="mongoose/types/inferschematype.js" />
25
- /// <reference types="mongoose-paginate-v2" />
26
- import type { TransactionOptions } from 'mongodb';
1
+ import type { CollationOptions, TransactionOptions } from 'mongodb';
27
2
  import type { MongoMemoryReplSet } from 'mongodb-memory-server';
28
- import type { ClientSession, ConnectOptions, Connection } from 'mongoose';
29
- import type { BaseDatabaseAdapter, DatabaseAdapterObj } from 'payload/database';
30
- import type { CollectionModel, GlobalModel } from './types.js';
3
+ import type { ClientSession, Connection, ConnectOptions } from 'mongoose';
4
+ import type { BaseDatabaseAdapter, DatabaseAdapterObj } from 'payload';
5
+ import type { CollectionModel, GlobalModel, MigrateDownArgs, MigrateUpArgs } from './types.js';
31
6
  export type { MigrateDownArgs, MigrateUpArgs } from './types.js';
32
7
  export interface Args {
33
8
  /** Set to false to disable auto-pluralization of collection names, Defaults to true */
34
9
  autoPluralization?: boolean;
10
+ /**
11
+ * If enabled, collation allows for language-specific rules for string comparison.
12
+ * This configuration can include the following options:
13
+ *
14
+ * - `strength` (number): Comparison level (1: Primary, 2: Secondary, 3: Tertiary (default), 4: Quaternary, 5: Identical)
15
+ * - `caseLevel` (boolean): Include case comparison at strength level 1 or 2.
16
+ * - `caseFirst` (string): Sort order of case differences during tertiary level comparisons ("upper", "lower", "off").
17
+ * - `numericOrdering` (boolean): Compare numeric strings as numbers.
18
+ * - `alternate` (string): Consider whitespace and punctuation as base characters ("non-ignorable", "shifted").
19
+ * - `maxVariable` (string): Characters considered ignorable when `alternate` is "shifted" ("punct", "space").
20
+ * - `backwards` (boolean): Sort strings with diacritics from back of the string.
21
+ * - `normalization` (boolean): Check if text requires normalization and perform normalization.
22
+ *
23
+ * Available on MongoDB version 3.4 and up.
24
+ * The locale that gets passed is your current project's locale but defaults to "en".
25
+ *
26
+ * Example:
27
+ * {
28
+ * strength: 3
29
+ * }
30
+ *
31
+ * Defaults to disabled.
32
+ */
33
+ collation?: Omit<CollationOptions, 'locale'>;
35
34
  /** Extra configuration options */
36
- connectOptions?: ConnectOptions & {
35
+ connectOptions?: {
37
36
  /** Set false to disable $facet aggregation in non-supporting databases, Defaults to true */
38
37
  useFacet?: boolean;
39
- };
38
+ } & ConnectOptions;
40
39
  /** Set to true to disable hinting to MongoDB to use 'id' as index. This is currently done when counting documents for pagination. Disabling this optimization might fix some problems with AWS DocumentDB. Defaults to false */
41
40
  disableIndexHints?: boolean;
42
41
  migrationDir?: string;
@@ -44,22 +43,32 @@ export interface Args {
44
43
  * typed as any to avoid dependency
45
44
  */
46
45
  mongoMemoryServer?: MongoMemoryReplSet;
47
- transactionOptions?: TransactionOptions | false;
46
+ prodMigrations?: {
47
+ down: (args: MigrateDownArgs) => Promise<void>;
48
+ name: string;
49
+ up: (args: MigrateUpArgs) => Promise<void>;
50
+ }[];
51
+ transactionOptions?: false | TransactionOptions;
48
52
  /** The URL to connect to MongoDB or false to start payload and prevent connecting */
49
53
  url: false | string;
50
54
  }
51
- export type MongooseAdapter = BaseDatabaseAdapter & Args & {
55
+ export type MongooseAdapter = {
52
56
  collections: {
53
57
  [slug: string]: CollectionModel;
54
58
  };
55
59
  connection: Connection;
56
60
  globals: GlobalModel;
57
61
  mongoMemoryServer: MongoMemoryReplSet;
62
+ prodMigrations?: {
63
+ down: (args: MigrateDownArgs) => Promise<void>;
64
+ name: string;
65
+ up: (args: MigrateUpArgs) => Promise<void>;
66
+ }[];
58
67
  sessions: Record<number | string, ClientSession>;
59
68
  versions: {
60
69
  [slug: string]: CollectionModel;
61
70
  };
62
- };
71
+ } & Args & BaseDatabaseAdapter;
63
72
  declare module 'payload' {
64
73
  interface DatabaseAdapter extends Omit<BaseDatabaseAdapter, 'sessions'>, Omit<Args, 'migrationDir'> {
65
74
  collections: {
@@ -68,6 +77,11 @@ declare module 'payload' {
68
77
  connection: Connection;
69
78
  globals: GlobalModel;
70
79
  mongoMemoryServer: MongoMemoryReplSet;
80
+ prodMigrations?: {
81
+ down: (args: MigrateDownArgs) => Promise<void>;
82
+ name: string;
83
+ up: (args: MigrateUpArgs) => Promise<void>;
84
+ }[];
71
85
  sessions: Record<number | string, ClientSession>;
72
86
  transactionOptions: TransactionOptions;
73
87
  versions: {
@@ -75,5 +89,5 @@ declare module 'payload' {
75
89
  };
76
90
  }
77
91
  }
78
- export declare function mongooseAdapter({ autoPluralization, connectOptions, disableIndexHints, migrationDir: migrationDirArg, mongoMemoryServer, transactionOptions, url, }: Args): DatabaseAdapterObj;
92
+ export declare function mongooseAdapter({ autoPluralization, connectOptions, disableIndexHints, migrationDir: migrationDirArg, mongoMemoryServer, prodMigrations, transactionOptions, url, }: Args): DatabaseAdapterObj;
79
93
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OA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CAAC,CAAA;IAChD,QAAQ,EAAE;QACR,CAAC,IAAI,EAAE,MAAM,GAAG,eAAe,CAAA;KAChC,CAAA;CACF,GAAG,IAAI,GACN,mBAAmB,CAAA;AAErB,OAAO,QAAQ,SAAS,CAAC;IACvB,UAAiB,eACf,SAAQ,IAAI,CAAC,mBAAmB,EAAE,UAAU,CAAC,EAC3C,IAAI,CAAC,IAAI,EAAE,cAAc,CAAC;QAC5B,WAAW,EAAE;YACX,CAAC,IAAI,EAAE,MAAM,GAAG,eAAe,CAAA;SAChC,CAAA;QACD,UAAU,EAAE,UAAU,CAAA;QACtB,OAAO,EAAE,WAAW,CAAA;QACpB,iBAAiB,EAAE,kBAAkB,CAAA;QACrC,cAAc,CAAC,EAAE;YACf,IAAI,EAAE,CAAC,IAAI,EAAE,eAAe,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;YAC9C,IAAI,EAAE,MAAM,CAAA;YACZ,EAAE,EAAE,CAAC,IAAI,EAAE,aAAa,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;SAC3C,EAAE,CAAA;QACH,QAAQ,EAAE,MAAM,CAAC,MAAM,GAAG,MAAM,EAAE,aAAa,CAAC,CAAA;QAChD,kBAAkB,EAAE,kBAAkB,CAAA;QACtC,QAAQ,EAAE;YACR,CAAC,IAAI,EAAE,MAAM,GAAG,eAAe,CAAA;SAChC,CAAA;KACF;CACF;AAED,wBAAgB,eAAe,CAAC,EAC9B,iBAAwB,EACxB,cAAc,EACd,iBAAyB,EACzB,YAAY,EAAE,eAAe,EAC7B,iBAAiB,EACjB,cAAc,EACd,kBAAuB,EACvB,GAAG,GACJ,EAAE,IAAI,GAAG,kBAAkB,CA2D3B"}
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import fs from 'fs';
2
2
  import mongoose from 'mongoose';
3
3
  import path from 'path';
4
- import { createDatabaseAdapter } from 'payload/database';
4
+ import { createDatabaseAdapter } from 'payload';
5
5
  import { connect } from './connect.js';
6
6
  import { count } from './count.js';
7
7
  import { create } from './create.js';
@@ -28,7 +28,7 @@ import { updateGlobal } from './updateGlobal.js';
28
28
  import { updateGlobalVersion } from './updateGlobalVersion.js';
29
29
  import { updateOne } from './updateOne.js';
30
30
  import { updateVersion } from './updateVersion.js';
31
- export function mongooseAdapter({ autoPluralization = true, connectOptions, disableIndexHints = false, migrationDir: migrationDirArg, mongoMemoryServer, transactionOptions = {}, url }) {
31
+ export function mongooseAdapter({ autoPluralization = true, connectOptions, disableIndexHints = false, migrationDir: migrationDirArg, mongoMemoryServer, prodMigrations, transactionOptions = {}, url }) {
32
32
  function adapter({ payload }) {
33
33
  const migrationDir = findMigrationDir(migrationDirArg);
34
34
  mongoose.set('strictQuery', false);
@@ -37,8 +37,8 @@ export function mongooseAdapter({ autoPluralization = true, connectOptions, disa
37
37
  // Mongoose-specific
38
38
  autoPluralization,
39
39
  collections: {},
40
- connectOptions: connectOptions || {},
41
40
  connection: undefined,
41
+ connectOptions: connectOptions || {},
42
42
  count,
43
43
  disableIndexHints,
44
44
  globals: undefined,
@@ -69,7 +69,9 @@ export function mongooseAdapter({ autoPluralization = true, connectOptions, disa
69
69
  init,
70
70
  migrateFresh,
71
71
  migrationDir,
72
+ packageName: '@payloadcms/db-mongodb',
72
73
  payload,
74
+ prodMigrations,
73
75
  queryDrafts,
74
76
  rollbackTransaction,
75
77
  updateGlobal,
@@ -102,7 +104,9 @@ export function mongooseAdapter({ autoPluralization = true, connectOptions, disa
102
104
  const distDir = path.resolve(cwd, 'dist/migrations');
103
105
  const relativeMigrations = path.resolve(cwd, 'migrations');
104
106
  // Use arg if provided
105
- if (migrationDir) return migrationDir;
107
+ if (migrationDir) {
108
+ return migrationDir;
109
+ }
106
110
  // Check other common locations
107
111
  if (fs.existsSync(srcDir)) {
108
112
  return srcDir;