@payloadcms/db-mongodb 3.24.0-canary.10637cd → 3.24.0-canary.1328522

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. package/dist/count.d.ts.map +1 -1
  2. package/dist/count.js +5 -2
  3. package/dist/count.js.map +1 -1
  4. package/dist/countGlobalVersions.d.ts.map +1 -1
  5. package/dist/countGlobalVersions.js +5 -3
  6. package/dist/countGlobalVersions.js.map +1 -1
  7. package/dist/countVersions.d.ts.map +1 -1
  8. package/dist/countVersions.js +5 -3
  9. package/dist/countVersions.js.map +1 -1
  10. package/dist/deleteMany.d.ts.map +1 -1
  11. package/dist/deleteMany.js +5 -2
  12. package/dist/deleteMany.js.map +1 -1
  13. package/dist/deleteOne.d.ts.map +1 -1
  14. package/dist/deleteOne.js +9 -3
  15. package/dist/deleteOne.js.map +1 -1
  16. package/dist/deleteVersions.d.ts +1 -1
  17. package/dist/deleteVersions.d.ts.map +1 -1
  18. package/dist/deleteVersions.js +5 -2
  19. package/dist/deleteVersions.js.map +1 -1
  20. package/dist/find.d.ts.map +1 -1
  21. package/dist/find.js +5 -2
  22. package/dist/find.js.map +1 -1
  23. package/dist/findGlobal.d.ts.map +1 -1
  24. package/dist/findGlobal.js +6 -3
  25. package/dist/findGlobal.js.map +1 -1
  26. package/dist/findGlobalVersions.d.ts.map +1 -1
  27. package/dist/findGlobalVersions.js +4 -3
  28. package/dist/findGlobalVersions.js.map +1 -1
  29. package/dist/findOne.d.ts.map +1 -1
  30. package/dist/findOne.js +5 -2
  31. package/dist/findOne.js.map +1 -1
  32. package/dist/findVersions.d.ts.map +1 -1
  33. package/dist/findVersions.js +6 -3
  34. package/dist/findVersions.js.map +1 -1
  35. package/dist/init.d.ts.map +1 -1
  36. package/dist/init.js +25 -17
  37. package/dist/init.js.map +1 -1
  38. package/dist/models/buildCollectionSchema.d.ts.map +1 -1
  39. package/dist/models/buildCollectionSchema.js +14 -18
  40. package/dist/models/buildCollectionSchema.js.map +1 -1
  41. package/dist/models/buildGlobalModel.d.ts.map +1 -1
  42. package/dist/models/buildGlobalModel.js +9 -5
  43. package/dist/models/buildGlobalModel.js.map +1 -1
  44. package/dist/models/buildSchema.d.ts +6 -1
  45. package/dist/models/buildSchema.d.ts.map +1 -1
  46. package/dist/models/buildSchema.js +220 -99
  47. package/dist/models/buildSchema.js.map +1 -1
  48. package/dist/predefinedMigrations/migrateRelationshipsV2_V3.d.ts.map +1 -1
  49. package/dist/predefinedMigrations/migrateRelationshipsV2_V3.js +6 -2
  50. package/dist/predefinedMigrations/migrateRelationshipsV2_V3.js.map +1 -1
  51. package/dist/queries/buildAndOrConditions.d.ts +2 -1
  52. package/dist/queries/buildAndOrConditions.d.ts.map +1 -1
  53. package/dist/queries/buildAndOrConditions.js +2 -1
  54. package/dist/queries/buildAndOrConditions.js.map +1 -1
  55. package/dist/queries/buildQuery.d.ts +6 -9
  56. package/dist/queries/buildQuery.d.ts.map +1 -1
  57. package/dist/queries/buildQuery.js +11 -34
  58. package/dist/queries/buildQuery.js.map +1 -1
  59. package/dist/queries/buildSearchParams.d.ts +2 -1
  60. package/dist/queries/buildSearchParams.d.ts.map +1 -1
  61. package/dist/queries/buildSearchParams.js +4 -1
  62. package/dist/queries/buildSearchParams.js.map +1 -1
  63. package/dist/queries/buildSortParam.d.ts +2 -1
  64. package/dist/queries/buildSortParam.d.ts.map +1 -1
  65. package/dist/queries/buildSortParam.js +2 -1
  66. package/dist/queries/buildSortParam.js.map +1 -1
  67. package/dist/queries/getBuildQueryPlugin.d.ts +14 -0
  68. package/dist/queries/getBuildQueryPlugin.d.ts.map +1 -0
  69. package/dist/queries/getBuildQueryPlugin.js +40 -0
  70. package/dist/queries/getBuildQueryPlugin.js.map +1 -0
  71. package/dist/queries/getLocalizedSortProperty.d.ts +2 -1
  72. package/dist/queries/getLocalizedSortProperty.d.ts.map +1 -1
  73. package/dist/queries/getLocalizedSortProperty.js +11 -3
  74. package/dist/queries/getLocalizedSortProperty.js.map +1 -1
  75. package/dist/queries/parseParams.d.ts +2 -1
  76. package/dist/queries/parseParams.d.ts.map +1 -1
  77. package/dist/queries/parseParams.js +3 -1
  78. package/dist/queries/parseParams.js.map +1 -1
  79. package/dist/queries/sanitizeQueryValue.d.ts +2 -1
  80. package/dist/queries/sanitizeQueryValue.d.ts.map +1 -1
  81. package/dist/queries/sanitizeQueryValue.js +6 -2
  82. package/dist/queries/sanitizeQueryValue.js.map +1 -1
  83. package/dist/queryDrafts.d.ts.map +1 -1
  84. package/dist/queryDrafts.js +6 -3
  85. package/dist/queryDrafts.js.map +1 -1
  86. package/dist/types.d.ts +1 -1
  87. package/dist/types.d.ts.map +1 -1
  88. package/dist/types.js.map +1 -1
  89. package/dist/updateGlobal.d.ts.map +1 -1
  90. package/dist/updateGlobal.js +3 -0
  91. package/dist/updateGlobal.js.map +1 -1
  92. package/dist/updateGlobalVersion.d.ts.map +1 -1
  93. package/dist/updateGlobalVersion.js +9 -3
  94. package/dist/updateGlobalVersion.js.map +1 -1
  95. package/dist/updateOne.d.ts.map +1 -1
  96. package/dist/updateOne.js +8 -2
  97. package/dist/updateOne.js.map +1 -1
  98. package/dist/updateVersion.d.ts.map +1 -1
  99. package/dist/updateVersion.js +9 -3
  100. package/dist/updateVersion.js.map +1 -1
  101. package/dist/utilities/buildJoinAggregation.d.ts.map +1 -1
  102. package/dist/utilities/buildJoinAggregation.js +155 -4
  103. package/dist/utilities/buildJoinAggregation.js.map +1 -1
  104. package/dist/utilities/buildProjectionFromSelect.d.ts.map +1 -1
  105. package/dist/utilities/buildProjectionFromSelect.js +18 -17
  106. package/dist/utilities/buildProjectionFromSelect.js.map +1 -1
  107. package/dist/utilities/sanitizeRelationshipIDs.d.ts +2 -1
  108. package/dist/utilities/sanitizeRelationshipIDs.d.ts.map +1 -1
  109. package/dist/utilities/sanitizeRelationshipIDs.js +7 -3
  110. package/dist/utilities/sanitizeRelationshipIDs.js.map +1 -1
  111. package/dist/utilities/sanitizeRelationshipIDs.spec.js +44 -0
  112. package/dist/utilities/sanitizeRelationshipIDs.spec.js.map +1 -1
  113. package/package.json +3 -3
@@ -1 +1 @@
1
- {"version":3,"file":"count.d.ts","sourceRoot":"","sources":["../src/count.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAQpC,eAAO,MAAM,KAAK,EAAE,KA6CnB,CAAA"}
1
+ {"version":3,"file":"count.d.ts","sourceRoot":"","sources":["../src/count.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AASpC,eAAO,MAAM,KAAK,EAAE,KA+CnB,CAAA"}
package/dist/count.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { flattenWhereToOperators } from 'payload';
2
+ import { buildQuery } from './queries/buildQuery.js';
2
3
  import { getSession } from './utilities/getSession.js';
3
4
  export const count = async function count({ collection, locale, req, where }) {
4
5
  const Model = this.collections[collection];
@@ -10,9 +11,11 @@ export const count = async function count({ collection, locale, req, where }) {
10
11
  const constraints = flattenWhereToOperators(where);
11
12
  hasNearConstraint = constraints.some((prop)=>Object.keys(prop).some((key)=>key === 'near'));
12
13
  }
13
- const query = await Model.buildQuery({
14
+ const query = await buildQuery({
15
+ adapter: this,
16
+ collectionSlug: collection,
17
+ fields: this.payload.collections[collection].config.flattenedFields,
14
18
  locale,
15
- payload: this.payload,
16
19
  where
17
20
  });
18
21
  // useEstimatedCount is faster, but not accurate, as it ignores any filters. It is thus set to true if there are no filters.
package/dist/count.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/count.ts"],"sourcesContent":["import type { CountOptions } from 'mongodb'\nimport type { Count } from 'payload'\n\nimport { flattenWhereToOperators } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { getSession } from './utilities/getSession.js'\n\nexport const count: Count = async function count(\n this: MongooseAdapter,\n { collection, locale, req, where },\n) {\n const Model = this.collections[collection]\n const options: CountOptions = {\n session: await getSession(this, req),\n }\n\n let hasNearConstraint = false\n\n if (where) {\n const constraints = flattenWhereToOperators(where)\n hasNearConstraint = constraints.some((prop) => Object.keys(prop).some((key) => key === 'near'))\n }\n\n const query = await 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\n if (!useEstimatedCount && Object.keys(query).length === 0 && this.disableIndexHints !== true) {\n // Improve the performance of the countDocuments query which is used if useEstimatedCount is set to false by adding\n // a hint. By default, if no hint is provided, MongoDB does not use an indexed field to count the returned documents,\n // which makes queries very slow. This only happens when no query (filter) is provided. If one is provided, it uses\n // the correct indexed field\n options.hint = {\n _id: 1,\n }\n }\n\n let result: number\n if (useEstimatedCount) {\n result = await Model.estimatedDocumentCount({ session: options.session })\n } else {\n result = await Model.countDocuments(query, options)\n }\n\n return {\n totalDocs: result,\n }\n}\n"],"names":["flattenWhereToOperators","getSession","count","collection","locale","req","where","Model","collections","options","session","hasNearConstraint","constraints","some","prop","Object","keys","key","query","buildQuery","payload","useEstimatedCount","length","disableIndexHints","hint","_id","result","estimatedDocumentCount","countDocuments","totalDocs"],"mappings":"AAGA,SAASA,uBAAuB,QAAQ,UAAS;AAIjD,SAASC,UAAU,QAAQ,4BAA2B;AAEtD,OAAO,MAAMC,QAAe,eAAeA,MAEzC,EAAEC,UAAU,EAAEC,MAAM,EAAEC,GAAG,EAAEC,KAAK,EAAE;IAElC,MAAMC,QAAQ,IAAI,CAACC,WAAW,CAACL,WAAW;IAC1C,MAAMM,UAAwB;QAC5BC,SAAS,MAAMT,WAAW,IAAI,EAAEI;IAClC;IAEA,IAAIM,oBAAoB;IAExB,IAAIL,OAAO;QACT,MAAMM,cAAcZ,wBAAwBM;QAC5CK,oBAAoBC,YAAYC,IAAI,CAAC,CAACC,OAASC,OAAOC,IAAI,CAACF,MAAMD,IAAI,CAAC,CAACI,MAAQA,QAAQ;IACzF;IAEA,MAAMC,QAAQ,MAAMX,MAAMY,UAAU,CAAC;QACnCf;QACAgB,SAAS,IAAI,CAACA,OAAO;QACrBd;IACF;IAEA,4HAA4H;IAC5H,MAAMe,oBAAoBV,qBAAqB,CAACO,SAASH,OAAOC,IAAI,CAACE,OAAOI,MAAM,KAAK;IAEvF,IAAI,CAACD,qBAAqBN,OAAOC,IAAI,CAACE,OAAOI,MAAM,KAAK,KAAK,IAAI,CAACC,iBAAiB,KAAK,MAAM;QAC5F,mHAAmH;QACnH,qHAAqH;QACrH,mHAAmH;QACnH,4BAA4B;QAC5Bd,QAAQe,IAAI,GAAG;YACbC,KAAK;QACP;IACF;IAEA,IAAIC;IACJ,IAAIL,mBAAmB;QACrBK,SAAS,MAAMnB,MAAMoB,sBAAsB,CAAC;YAAEjB,SAASD,QAAQC,OAAO;QAAC;IACzE,OAAO;QACLgB,SAAS,MAAMnB,MAAMqB,cAAc,CAACV,OAAOT;IAC7C;IAEA,OAAO;QACLoB,WAAWH;IACb;AACF,EAAC"}
1
+ {"version":3,"sources":["../src/count.ts"],"sourcesContent":["import type { CountOptions } from 'mongodb'\nimport type { Count } from 'payload'\n\nimport { flattenWhereToOperators } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { getSession } from './utilities/getSession.js'\n\nexport const count: Count = async function count(\n this: MongooseAdapter,\n { collection, locale, req, where },\n) {\n const Model = this.collections[collection]\n const options: CountOptions = {\n session: await getSession(this, req),\n }\n\n let hasNearConstraint = false\n\n if (where) {\n const constraints = flattenWhereToOperators(where)\n hasNearConstraint = constraints.some((prop) => Object.keys(prop).some((key) => key === 'near'))\n }\n\n const query = await buildQuery({\n adapter: this,\n collectionSlug: collection,\n fields: this.payload.collections[collection].config.flattenedFields,\n locale,\n where,\n })\n\n // useEstimatedCount is faster, but not accurate, as it ignores any filters. It is thus set to true if there are no filters.\n const useEstimatedCount = hasNearConstraint || !query || Object.keys(query).length === 0\n\n if (!useEstimatedCount && Object.keys(query).length === 0 && this.disableIndexHints !== true) {\n // Improve the performance of the countDocuments query which is used if useEstimatedCount is set to false by adding\n // a hint. By default, if no hint is provided, MongoDB does not use an indexed field to count the returned documents,\n // which makes queries very slow. This only happens when no query (filter) is provided. If one is provided, it uses\n // the correct indexed field\n options.hint = {\n _id: 1,\n }\n }\n\n let result: number\n if (useEstimatedCount) {\n result = await Model.estimatedDocumentCount({ session: options.session })\n } else {\n result = await Model.countDocuments(query, options)\n }\n\n return {\n totalDocs: result,\n }\n}\n"],"names":["flattenWhereToOperators","buildQuery","getSession","count","collection","locale","req","where","Model","collections","options","session","hasNearConstraint","constraints","some","prop","Object","keys","key","query","adapter","collectionSlug","fields","payload","config","flattenedFields","useEstimatedCount","length","disableIndexHints","hint","_id","result","estimatedDocumentCount","countDocuments","totalDocs"],"mappings":"AAGA,SAASA,uBAAuB,QAAQ,UAAS;AAIjD,SAASC,UAAU,QAAQ,0BAAyB;AACpD,SAASC,UAAU,QAAQ,4BAA2B;AAEtD,OAAO,MAAMC,QAAe,eAAeA,MAEzC,EAAEC,UAAU,EAAEC,MAAM,EAAEC,GAAG,EAAEC,KAAK,EAAE;IAElC,MAAMC,QAAQ,IAAI,CAACC,WAAW,CAACL,WAAW;IAC1C,MAAMM,UAAwB;QAC5BC,SAAS,MAAMT,WAAW,IAAI,EAAEI;IAClC;IAEA,IAAIM,oBAAoB;IAExB,IAAIL,OAAO;QACT,MAAMM,cAAcb,wBAAwBO;QAC5CK,oBAAoBC,YAAYC,IAAI,CAAC,CAACC,OAASC,OAAOC,IAAI,CAACF,MAAMD,IAAI,CAAC,CAACI,MAAQA,QAAQ;IACzF;IAEA,MAAMC,QAAQ,MAAMlB,WAAW;QAC7BmB,SAAS,IAAI;QACbC,gBAAgBjB;QAChBkB,QAAQ,IAAI,CAACC,OAAO,CAACd,WAAW,CAACL,WAAW,CAACoB,MAAM,CAACC,eAAe;QACnEpB;QACAE;IACF;IAEA,4HAA4H;IAC5H,MAAMmB,oBAAoBd,qBAAqB,CAACO,SAASH,OAAOC,IAAI,CAACE,OAAOQ,MAAM,KAAK;IAEvF,IAAI,CAACD,qBAAqBV,OAAOC,IAAI,CAACE,OAAOQ,MAAM,KAAK,KAAK,IAAI,CAACC,iBAAiB,KAAK,MAAM;QAC5F,mHAAmH;QACnH,qHAAqH;QACrH,mHAAmH;QACnH,4BAA4B;QAC5BlB,QAAQmB,IAAI,GAAG;YACbC,KAAK;QACP;IACF;IAEA,IAAIC;IACJ,IAAIL,mBAAmB;QACrBK,SAAS,MAAMvB,MAAMwB,sBAAsB,CAAC;YAAErB,SAASD,QAAQC,OAAO;QAAC;IACzE,OAAO;QACLoB,SAAS,MAAMvB,MAAMyB,cAAc,CAACd,OAAOT;IAC7C;IAEA,OAAO;QACLwB,WAAWH;IACb;AACF,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"countGlobalVersions.d.ts","sourceRoot":"","sources":["../src/countGlobalVersions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAA;AAQlD,eAAO,MAAM,mBAAmB,EAAE,mBA6CjC,CAAA"}
1
+ {"version":3,"file":"countGlobalVersions.d.ts","sourceRoot":"","sources":["../src/countGlobalVersions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAA;AASlD,eAAO,MAAM,mBAAmB,EAAE,mBAkDjC,CAAA"}
@@ -1,4 +1,5 @@
1
- import { flattenWhereToOperators } from 'payload';
1
+ import { buildVersionGlobalFields, flattenWhereToOperators } from 'payload';
2
+ import { buildQuery } from './queries/buildQuery.js';
2
3
  import { getSession } from './utilities/getSession.js';
3
4
  export const countGlobalVersions = async function countGlobalVersions({ global, locale, req, where }) {
4
5
  const Model = this.versions[global];
@@ -10,9 +11,10 @@ export const countGlobalVersions = async function countGlobalVersions({ global,
10
11
  const constraints = flattenWhereToOperators(where);
11
12
  hasNearConstraint = constraints.some((prop)=>Object.keys(prop).some((key)=>key === 'near'));
12
13
  }
13
- const query = await Model.buildQuery({
14
+ const query = await buildQuery({
15
+ adapter: this,
16
+ fields: buildVersionGlobalFields(this.payload.config, this.payload.globals.config.find((each)=>each.slug === global), true),
14
17
  locale,
15
- payload: this.payload,
16
18
  where
17
19
  });
18
20
  // useEstimatedCount is faster, but not accurate, as it ignores any filters. It is thus set to true if there are no filters.
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/countGlobalVersions.ts"],"sourcesContent":["import type { CountOptions } from 'mongodb'\nimport type { CountGlobalVersions } from 'payload'\n\nimport { flattenWhereToOperators } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { getSession } from './utilities/getSession.js'\n\nexport const countGlobalVersions: CountGlobalVersions = async function countGlobalVersions(\n this: MongooseAdapter,\n { global, locale, req, where },\n) {\n const Model = this.versions[global]\n const options: CountOptions = {\n session: await getSession(this, req),\n }\n\n let hasNearConstraint = false\n\n if (where) {\n const constraints = flattenWhereToOperators(where)\n hasNearConstraint = constraints.some((prop) => Object.keys(prop).some((key) => key === 'near'))\n }\n\n const query = await 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\n if (!useEstimatedCount && Object.keys(query).length === 0 && this.disableIndexHints !== true) {\n // Improve the performance of the countDocuments query which is used if useEstimatedCount is set to false by adding\n // a hint. By default, if no hint is provided, MongoDB does not use an indexed field to count the returned documents,\n // which makes queries very slow. This only happens when no query (filter) is provided. If one is provided, it uses\n // the correct indexed field\n options.hint = {\n _id: 1,\n }\n }\n\n let result: number\n if (useEstimatedCount) {\n result = await Model.estimatedDocumentCount({ session: options.session })\n } else {\n result = await Model.countDocuments(query, options)\n }\n\n return {\n totalDocs: result,\n }\n}\n"],"names":["flattenWhereToOperators","getSession","countGlobalVersions","global","locale","req","where","Model","versions","options","session","hasNearConstraint","constraints","some","prop","Object","keys","key","query","buildQuery","payload","useEstimatedCount","length","disableIndexHints","hint","_id","result","estimatedDocumentCount","countDocuments","totalDocs"],"mappings":"AAGA,SAASA,uBAAuB,QAAQ,UAAS;AAIjD,SAASC,UAAU,QAAQ,4BAA2B;AAEtD,OAAO,MAAMC,sBAA2C,eAAeA,oBAErE,EAAEC,MAAM,EAAEC,MAAM,EAAEC,GAAG,EAAEC,KAAK,EAAE;IAE9B,MAAMC,QAAQ,IAAI,CAACC,QAAQ,CAACL,OAAO;IACnC,MAAMM,UAAwB;QAC5BC,SAAS,MAAMT,WAAW,IAAI,EAAEI;IAClC;IAEA,IAAIM,oBAAoB;IAExB,IAAIL,OAAO;QACT,MAAMM,cAAcZ,wBAAwBM;QAC5CK,oBAAoBC,YAAYC,IAAI,CAAC,CAACC,OAASC,OAAOC,IAAI,CAACF,MAAMD,IAAI,CAAC,CAACI,MAAQA,QAAQ;IACzF;IAEA,MAAMC,QAAQ,MAAMX,MAAMY,UAAU,CAAC;QACnCf;QACAgB,SAAS,IAAI,CAACA,OAAO;QACrBd;IACF;IAEA,4HAA4H;IAC5H,MAAMe,oBAAoBV,qBAAqB,CAACO,SAASH,OAAOC,IAAI,CAACE,OAAOI,MAAM,KAAK;IAEvF,IAAI,CAACD,qBAAqBN,OAAOC,IAAI,CAACE,OAAOI,MAAM,KAAK,KAAK,IAAI,CAACC,iBAAiB,KAAK,MAAM;QAC5F,mHAAmH;QACnH,qHAAqH;QACrH,mHAAmH;QACnH,4BAA4B;QAC5Bd,QAAQe,IAAI,GAAG;YACbC,KAAK;QACP;IACF;IAEA,IAAIC;IACJ,IAAIL,mBAAmB;QACrBK,SAAS,MAAMnB,MAAMoB,sBAAsB,CAAC;YAAEjB,SAASD,QAAQC,OAAO;QAAC;IACzE,OAAO;QACLgB,SAAS,MAAMnB,MAAMqB,cAAc,CAACV,OAAOT;IAC7C;IAEA,OAAO;QACLoB,WAAWH;IACb;AACF,EAAC"}
1
+ {"version":3,"sources":["../src/countGlobalVersions.ts"],"sourcesContent":["import type { CountOptions } from 'mongodb'\nimport type { CountGlobalVersions } from 'payload'\n\nimport { buildVersionGlobalFields, flattenWhereToOperators } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { getSession } from './utilities/getSession.js'\n\nexport const countGlobalVersions: CountGlobalVersions = async function countGlobalVersions(\n this: MongooseAdapter,\n { global, locale, req, where },\n) {\n const Model = this.versions[global]\n const options: CountOptions = {\n session: await getSession(this, req),\n }\n\n let hasNearConstraint = false\n\n if (where) {\n const constraints = flattenWhereToOperators(where)\n hasNearConstraint = constraints.some((prop) => Object.keys(prop).some((key) => key === 'near'))\n }\n\n const query = await buildQuery({\n adapter: this,\n fields: buildVersionGlobalFields(\n this.payload.config,\n this.payload.globals.config.find((each) => each.slug === global),\n true,\n ),\n locale,\n where,\n })\n\n // useEstimatedCount is faster, but not accurate, as it ignores any filters. It is thus set to true if there are no filters.\n const useEstimatedCount = hasNearConstraint || !query || Object.keys(query).length === 0\n\n if (!useEstimatedCount && Object.keys(query).length === 0 && this.disableIndexHints !== true) {\n // Improve the performance of the countDocuments query which is used if useEstimatedCount is set to false by adding\n // a hint. By default, if no hint is provided, MongoDB does not use an indexed field to count the returned documents,\n // which makes queries very slow. This only happens when no query (filter) is provided. If one is provided, it uses\n // the correct indexed field\n options.hint = {\n _id: 1,\n }\n }\n\n let result: number\n if (useEstimatedCount) {\n result = await Model.estimatedDocumentCount({ session: options.session })\n } else {\n result = await Model.countDocuments(query, options)\n }\n\n return {\n totalDocs: result,\n }\n}\n"],"names":["buildVersionGlobalFields","flattenWhereToOperators","buildQuery","getSession","countGlobalVersions","global","locale","req","where","Model","versions","options","session","hasNearConstraint","constraints","some","prop","Object","keys","key","query","adapter","fields","payload","config","globals","find","each","slug","useEstimatedCount","length","disableIndexHints","hint","_id","result","estimatedDocumentCount","countDocuments","total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B,MAAM2B,cAAc,CAAChB,OAAOT;IAC7C;IAEA,OAAO;QACL0B,WAAWH;IACb;AACF,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"countVersions.d.ts","sourceRoot":"","sources":["../src/countVersions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAQ5C,eAAO,MAAM,aAAa,EAAE,aA6C3B,CAAA"}
1
+ {"version":3,"file":"countVersions.d.ts","sourceRoot":"","sources":["../src/countVersions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAS5C,eAAO,MAAM,aAAa,EAAE,aAkD3B,CAAA"}
@@ -1,4 +1,5 @@
1
- import { flattenWhereToOperators } from 'payload';
1
+ import { buildVersionCollectionFields, flattenWhereToOperators } from 'payload';
2
+ import { buildQuery } from './queries/buildQuery.js';
2
3
  import { getSession } from './utilities/getSession.js';
3
4
  export const countVersions = async function countVersions({ collection, locale, req, where }) {
4
5
  const Model = this.versions[collection];
@@ -10,9 +11,10 @@ export const countVersions = async function countVersions({ collection, locale,
10
11
  const constraints = flattenWhereToOperators(where);
11
12
  hasNearConstraint = constraints.some((prop)=>Object.keys(prop).some((key)=>key === 'near'));
12
13
  }
13
- const query = await Model.buildQuery({
14
+ const query = await buildQuery({
15
+ adapter: this,
16
+ fields: buildVersionCollectionFields(this.payload.config, this.payload.collections[collection].config, true),
14
17
  locale,
15
- payload: this.payload,
16
18
  where
17
19
  });
18
20
  // useEstimatedCount is faster, but not accurate, as it ignores any filters. It is thus set to true if there are no filters.
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/countVersions.ts"],"sourcesContent":["import type { CountOptions } from 'mongodb'\nimport type { CountVersions } from 'payload'\n\nimport { flattenWhereToOperators } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { getSession } from './utilities/getSession.js'\n\nexport const countVersions: CountVersions = async function countVersions(\n this: MongooseAdapter,\n { collection, locale, req, where },\n) {\n const Model = this.versions[collection]\n const options: CountOptions = {\n session: await getSession(this, req),\n }\n\n let hasNearConstraint = false\n\n if (where) {\n const constraints = flattenWhereToOperators(where)\n hasNearConstraint = constraints.some((prop) => Object.keys(prop).some((key) => key === 'near'))\n }\n\n const query = await 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\n if (!useEstimatedCount && Object.keys(query).length === 0 && this.disableIndexHints !== true) {\n // Improve the performance of the countDocuments query which is used if useEstimatedCount is set to false by adding\n // a hint. By default, if no hint is provided, MongoDB does not use an indexed field to count the returned documents,\n // which makes queries very slow. This only happens when no query (filter) is provided. If one is provided, it uses\n // the correct indexed field\n options.hint = {\n _id: 1,\n }\n }\n\n let result: number\n if (useEstimatedCount) {\n result = await Model.estimatedDocumentCount({ session: options.session })\n } else {\n result = await Model.countDocuments(query, options)\n }\n\n return {\n totalDocs: result,\n }\n}\n"],"names":["flattenWhereToOperators","getSession","countVersions","collection","locale","req","where","Model","versions","options","session","hasNearConstraint","constraints","some","prop","Object","keys","key","query","buildQuery","payload","useEstimatedCount","length","disableIndexHints","hint","_id","result","estimatedDocumentCount","countDocuments","totalDocs"],"mappings":"AAGA,SAASA,uBAAuB,QAAQ,UAAS;AAIjD,SAASC,UAAU,QAAQ,4BAA2B;AAEtD,OAAO,MAAMC,gBAA+B,eAAeA,cAEzD,EAAEC,UAAU,EAAEC,MAAM,EAAEC,GAAG,EAAEC,KAAK,EAAE;IAElC,MAAMC,QAAQ,IAAI,CAACC,QAAQ,CAACL,WAAW;IACvC,MAAMM,UAAwB;QAC5BC,SAAS,MAAMT,WAAW,IAAI,EAAEI;IAClC;IAEA,IAAIM,oBAAoB;IAExB,IAAIL,OAAO;QACT,MAAMM,cAAcZ,wBAAwBM;QAC5CK,oBAAoBC,YAAYC,IAAI,CAAC,CAACC,OAASC,OAAOC,IAAI,CAACF,MAAMD,IAAI,CAAC,CAACI,MAAQA,QAAQ;IACzF;IAEA,MAAMC,QAAQ,MAAMX,MAAMY,UAAU,CAAC;QACnCf;QACAgB,SAAS,IAAI,CAACA,OAAO;QACrBd;IACF;IAEA,4HAA4H;IAC5H,MAAMe,oBAAoBV,qBAAqB,CAACO,SAASH,OAAOC,IAAI,CAACE,OAAOI,MAAM,KAAK;IAEvF,IAAI,CAACD,qBAAqBN,OAAOC,IAAI,CAACE,OAAOI,MAAM,KAAK,KAAK,IAAI,CAACC,iBAAiB,KAAK,MAAM;QAC5F,mHAAmH;QACnH,qHAAqH;QACrH,mHAAmH;QACnH,4BAA4B;QAC5Bd,QAAQe,IAAI,GAAG;YACbC,KAAK;QACP;IACF;IAEA,IAAIC;IACJ,IAAIL,mBAAmB;QACrBK,SAAS,MAAMnB,MAAMoB,sBAAsB,CAAC;YAAEjB,SAASD,QAAQC,OAAO;QAAC;IACzE,OAAO;QACLgB,SAAS,MAAMnB,MAAMqB,cAAc,CAACV,OAAOT;IAC7C;IAEA,OAAO;QACLoB,WAAWH;IACb;AACF,EAAC"}
1
+ {"version":3,"sources":["../src/countVersions.ts"],"sourcesContent":["import type { CountOptions } from 'mongodb'\nimport type { CountVersions } from 'payload'\n\nimport { buildVersionCollectionFields, flattenWhereToOperators } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { getSession } from './utilities/getSession.js'\n\nexport const countVersions: CountVersions = async function countVersions(\n this: MongooseAdapter,\n { collection, locale, req, where },\n) {\n const Model = this.versions[collection]\n const options: CountOptions = {\n session: await getSession(this, req),\n }\n\n let hasNearConstraint = false\n\n if (where) {\n const constraints = flattenWhereToOperators(where)\n hasNearConstraint = constraints.some((prop) => Object.keys(prop).some((key) => key === 'near'))\n }\n\n const query = await buildQuery({\n adapter: this,\n fields: buildVersionCollectionFields(\n this.payload.config,\n this.payload.collections[collection].config,\n true,\n ),\n locale,\n where,\n })\n\n // useEstimatedCount is faster, but not accurate, as it ignores any filters. It is thus set to true if there are no filters.\n const useEstimatedCount = hasNearConstraint || !query || Object.keys(query).length === 0\n\n if (!useEstimatedCount && Object.keys(query).length === 0 && this.disableIndexHints !== true) {\n // Improve the performance of the countDocuments query which is used if useEstimatedCount is set to false by adding\n // a hint. By default, if no hint is provided, MongoDB does not use an indexed field to count the returned documents,\n // which makes queries very slow. This only happens when no query (filter) is provided. If one is provided, it uses\n // the correct indexed field\n options.hint = {\n _id: 1,\n }\n }\n\n let result: number\n if (useEstimatedCount) {\n result = await Model.estimatedDocumentCount({ session: options.session })\n } else {\n result = await Model.countDocuments(query, options)\n }\n\n return {\n totalDocs: result,\n }\n}\n"],"names":["buildVersionCollectionFields","flattenWhereToOperators","buildQuery","getSession","countVersions","collection","locale","req","where","Model","versions","options","session","hasNearConstraint","constraints","some","prop","Object","keys","key","query","adapter","fields","payload","config","collections","useEstimatedCount","length","disableIndexHints","hint","_id","result","estimatedDocumentCount","countDocuments","totalDocs"],"mappings":"AAGA,SAASA,4BAA4B,EAAEC,uBAAuB,QAAQ,UAAS;AAI/E,SAASC,UAAU,QAAQ,0BAAyB;AACpD,SAASC,UAAU,QAAQ,4BAA2B;AAEtD,OAAO,MAAMC,gBAA+B,eAAeA,cAEzD,EAAEC,UAAU,EAAEC,MAAM,EAAEC,GAAG,EAAEC,KAAK,EAAE;IAElC,MAAMC,QAAQ,IAAI,CAACC,QAAQ,CAACL,WAAW;IACvC,MAAMM,UAAwB;QAC5BC,SAAS,MAAMT,WAAW,IAAI,EAAEI;IAClC;IAEA,IAAIM,oBAAoB;IAExB,IAAIL,OAAO;QACT,MAAMM,cAAcb,wBAAwBO;QAC5CK,oBAAoBC,YAAYC,IAAI,CAAC,CAACC,OAASC,OAAOC,IAAI,CAACF,MAAMD,IAAI,CAAC,CAACI,MAAQA,QAAQ;IACzF;IAEA,MAAMC,QAAQ,MAAMlB,WAAW;QAC7BmB,SAAS,IAAI;QACbC,QAAQtB,6BACN,IAAI,CAACuB,OAAO,CAACC,MAAM,EACnB,IAAI,CAACD,OAAO,CAACE,WAAW,CAACpB,WAAW,CAACmB,MAAM,EAC3C;QAEFlB;QACAE;IACF;IAEA,4HAA4H;IAC5H,MAAMkB,oBAAoBb,qBAAqB,CAACO,SAASH,OAAOC,IAAI,CAACE,OAAOO,MAAM,KAAK;IAEvF,IAAI,CAACD,qBAAqBT,OAAOC,IAAI,CAACE,OAAOO,MAAM,KAAK,KAAK,IAAI,CAACC,iBAAiB,KAAK,MAAM;QAC5F,mHAAmH;QACnH,qHAAqH;QACrH,mHAAmH;QACnH,4BAA4B;QAC5BjB,QAAQkB,IAAI,GAAG;YACbC,KAAK;QACP;IACF;IAEA,IAAIC;IACJ,IAAIL,mBAAmB;QACrBK,SAAS,MAAMtB,MAAMuB,sBAAsB,CAAC;YAAEpB,SAASD,QAAQC,OAAO;QAAC;IACzE,OAAO;QACLmB,SAAS,MAAMtB,MAAMwB,cAAc,CAACb,OAAOT;IAC7C;IAEA,OAAO;QACLuB,WAAWH;IACb;AACF,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"deleteMany.d.ts","sourceRoot":"","sources":["../src/deleteMany.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAMzC,eAAO,MAAM,UAAU,EAAE,UAexB,CAAA"}
1
+ {"version":3,"file":"deleteMany.d.ts","sourceRoot":"","sources":["../src/deleteMany.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAOzC,eAAO,MAAM,UAAU,EAAE,UAiBxB,CAAA"}
@@ -1,11 +1,14 @@
1
+ import { buildQuery } from './queries/buildQuery.js';
1
2
  import { getSession } from './utilities/getSession.js';
2
3
  export const deleteMany = async function deleteMany({ collection, req, where }) {
3
4
  const Model = this.collections[collection];
4
5
  const options = {
5
6
  session: await getSession(this, req)
6
7
  };
7
- const query = await Model.buildQuery({
8
- payload: this.payload,
8
+ const query = await buildQuery({
9
+ adapter: this,
10
+ collectionSlug: collection,
11
+ fields: this.payload.collections[collection].config.flattenedFields,
9
12
  where
10
13
  });
11
14
  await Model.deleteMany(query, options);
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/deleteMany.ts"],"sourcesContent":["import type { DeleteOptions } from 'mongodb'\nimport type { DeleteMany } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { getSession } from './utilities/getSession.js'\n\nexport const deleteMany: DeleteMany = async function deleteMany(\n this: MongooseAdapter,\n { collection, req, where },\n) {\n const Model = this.collections[collection]\n const options: DeleteOptions = {\n session: await getSession(this, req),\n }\n\n const query = await Model.buildQuery({\n payload: this.payload,\n where,\n })\n\n await Model.deleteMany(query, options)\n}\n"],"names":["getSession","deleteMany","collection","req","where","Model","collections","options","session","query","buildQuery","payload"],"mappings":"AAKA,SAASA,UAAU,QAAQ,4BAA2B;AAEtD,OAAO,MAAMC,aAAyB,eAAeA,WAEnD,EAAEC,UAAU,EAAEC,GAAG,EAAEC,KAAK,EAAE;IAE1B,MAAMC,QAAQ,IAAI,CAACC,WAAW,CAACJ,WAAW;IAC1C,MAAMK,UAAyB;QAC7BC,SAAS,MAAMR,WAAW,IAAI,EAAEG;IAClC;IAEA,MAAMM,QAAQ,MAAMJ,MAAMK,UAAU,CAAC;QACnCC,SAAS,IAAI,CAACA,OAAO;QACrBP;IACF;IAEA,MAAMC,MAAMJ,UAAU,CAACQ,OAAOF;AAChC,EAAC"}
1
+ {"version":3,"sources":["../src/deleteMany.ts"],"sourcesContent":["import type { DeleteOptions } from 'mongodb'\nimport type { DeleteMany } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { getSession } from './utilities/getSession.js'\n\nexport const deleteMany: DeleteMany = async function deleteMany(\n this: MongooseAdapter,\n { collection, req, where },\n) {\n const Model = this.collections[collection]\n const options: DeleteOptions = {\n session: await getSession(this, req),\n }\n\n const query = await buildQuery({\n adapter: this,\n collectionSlug: collection,\n fields: this.payload.collections[collection].config.flattenedFields,\n where,\n })\n\n await Model.deleteMany(query, options)\n}\n"],"names":["buildQuery","getSession","deleteMany","collection","req","where","Model","collections","options","session","query","adapter","collectionSlug","fields","payload","config","flattenedFields"],"mappings":"AAKA,SAASA,UAAU,QAAQ,0BAAyB;AACpD,SAASC,UAAU,QAAQ,4BAA2B;AAEtD,OAAO,MAAMC,aAAyB,eAAeA,WAEnD,EAAEC,UAAU,EAAEC,GAAG,EAAEC,KAAK,EAAE;IAE1B,MAAMC,QAAQ,IAAI,CAACC,WAAW,CAACJ,WAAW;IAC1C,MAAMK,UAAyB;QAC7BC,SAAS,MAAMR,WAAW,IAAI,EAAEG;IAClC;IAEA,MAAMM,QAAQ,MAAMV,WAAW;QAC7BW,SAAS,IAAI;QACbC,gBAAgBT;QAChBU,QAAQ,IAAI,CAACC,OAAO,CAACP,WAAW,CAACJ,WAAW,CAACY,MAAM,CAACC,eAAe;QACnEX;IACF;IAEA,MAAMC,MAAMJ,UAAU,CAACQ,OAAOF;AAChC,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"deleteOne.d.ts","sourceRoot":"","sources":["../src/deleteOne.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAY,MAAM,SAAS,CAAA;AAQlD,eAAO,MAAM,SAAS,EAAE,SA4BvB,CAAA"}
1
+ {"version":3,"file":"deleteOne.d.ts","sourceRoot":"","sources":["../src/deleteOne.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAY,MAAM,SAAS,CAAA;AASlD,eAAO,MAAM,SAAS,EAAE,SAkCvB,CAAA"}
package/dist/deleteOne.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { buildQuery } from './queries/buildQuery.js';
1
2
  import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
2
3
  import { getSession } from './utilities/getSession.js';
3
4
  import { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js';
@@ -11,11 +12,16 @@ export const deleteOne = async function deleteOne({ collection, req, select, whe
11
12
  }),
12
13
  session: await getSession(this, req)
13
14
  };
14
- const query = await Model.buildQuery({
15
- payload: this.payload,
15
+ const query = await buildQuery({
16
+ adapter: this,
17
+ collectionSlug: collection,
18
+ fields: this.payload.collections[collection].config.flattenedFields,
16
19
  where
17
20
  });
18
- const doc = await Model.findOneAndDelete(query, options).lean();
21
+ const doc = await Model.findOneAndDelete(query, options)?.lean();
22
+ if (!doc) {
23
+ return null;
24
+ }
19
25
  let result = JSON.parse(JSON.stringify(doc));
20
26
  // custom id type reset
21
27
  result.id = result._id;
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/deleteOne.ts"],"sourcesContent":["import type { QueryOptions } from 'mongoose'\nimport type { DeleteOne, Document } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getSession } from './utilities/getSession.js'\nimport { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js'\n\nexport const deleteOne: DeleteOne = async function deleteOne(\n this: MongooseAdapter,\n { collection, req, select, where },\n) {\n const Model = this.collections[collection]\n const options: QueryOptions = {\n projection: buildProjectionFromSelect({\n adapter: this,\n fields: this.payload.collections[collection].config.flattenedFields,\n select,\n }),\n session: await getSession(this, req),\n }\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":["buildProjectionFromSelect","getSession","sanitizeInternalFields","deleteOne","collection","req","select","where","Model","collections","options","projection","adapter","fields","payload","config","flattenedFields","session","query","buildQuery","doc","findOneAndDelete","lean","result","JSON","parse","stringify","id","_id"],"mappings":"AAKA,SAASA,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,sBAAsB,QAAQ,wCAAuC;AAE9E,OAAO,MAAMC,YAAuB,eAAeA,UAEjD,EAAEC,UAAU,EAAEC,GAAG,EAAEC,MAAM,EAAEC,KAAK,EAAE;IAElC,MAAMC,QAAQ,IAAI,CAACC,WAAW,CAACL,WAAW;IAC1C,MAAMM,UAAwB;QAC5BC,YAAYX,0BAA0B;YACpCY,SAAS,IAAI;YACbC,QAAQ,IAAI,CAACC,OAAO,CAACL,WAAW,CAACL,WAAW,CAACW,MAAM,CAACC,eAAe;YACnEV;QACF;QACAW,SAAS,MAAMhB,WAAW,IAAI,EAAEI;IAClC;IAEA,MAAMa,QAAQ,MAAMV,MAAMW,UAAU,CAAC;QACnCL,SAAS,IAAI,CAACA,OAAO;QACrBP;IACF;IAEA,MAAMa,MAAM,MAAMZ,MAAMa,gBAAgB,CAACH,OAAOR,SAASY,IAAI;IAE7D,IAAIC,SAAmBC,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACN;IAEjD,uBAAuB;IACvBG,OAAOI,EAAE,GAAGJ,OAAOK,GAAG;IACtBL,SAASrB,uBAAuBqB;IAEhC,OAAOA;AACT,EAAC"}
1
+ {"version":3,"sources":["../src/deleteOne.ts"],"sourcesContent":["import type { QueryOptions } from 'mongoose'\nimport type { DeleteOne, Document } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getSession } from './utilities/getSession.js'\nimport { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js'\n\nexport const deleteOne: DeleteOne = async function deleteOne(\n this: MongooseAdapter,\n { collection, req, select, where },\n) {\n const Model = this.collections[collection]\n const options: QueryOptions = {\n projection: buildProjectionFromSelect({\n adapter: this,\n fields: this.payload.collections[collection].config.flattenedFields,\n select,\n }),\n session: await getSession(this, req),\n }\n\n const query = await buildQuery({\n adapter: this,\n collectionSlug: collection,\n fields: this.payload.collections[collection].config.flattenedFields,\n where,\n })\n\n const doc = await Model.findOneAndDelete(query, options)?.lean()\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":["buildQuery","buildProjectionFromSelect","getSession","sanitizeInternalFields","deleteOne","collection","req","select","where","Model","collections","options","projection","adapter","fields","payload","config","flattenedFields","session","query","collectionSlug","doc","findOneAndDelete","lean","result","JSON","parse","stringify","id","_id"],"mappings":"AAKA,SAASA,UAAU,QAAQ,0BAAyB;AACpD,SAASC,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,sBAAsB,QAAQ,wCAAuC;AAE9E,OAAO,MAAMC,YAAuB,eAAeA,UAEjD,EAAEC,UAAU,EAAEC,GAAG,EAAEC,MAAM,EAAEC,KAAK,EAAE;IAElC,MAAMC,QAAQ,IAAI,CAACC,WAAW,CAACL,WAAW;IAC1C,MAAMM,UAAwB;QAC5BC,YAAYX,0BAA0B;YACpCY,SAAS,IAAI;YACbC,QAAQ,IAAI,CAACC,OAAO,CAACL,WAAW,CAACL,WAAW,CAACW,MAAM,CAACC,eAAe;YACnEV;QACF;QACAW,SAAS,MAAMhB,WAAW,IAAI,EAAEI;IAClC;IAEA,MAAMa,QAAQ,MAAMnB,WAAW;QAC7Ba,SAAS,IAAI;QACbO,gBAAgBf;QAChBS,QAAQ,IAAI,CAACC,OAAO,CAACL,WAAW,CAACL,WAAW,CAACW,MAAM,CAACC,eAAe;QACnET;IACF;IAEA,MAAMa,MAAM,MAAMZ,MAAMa,gBAAgB,CAACH,OAAOR,UAAUY;IAE1D,IAAI,CAACF,KAAK;QACR,OAAO;IACT;IAEA,IAAIG,SAAmBC,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACN;IAEjD,uBAAuB;IACvBG,OAAOI,EAAE,GAAGJ,OAAOK,GAAG;IACtBL,SAASrB,uBAAuBqB;IAEhC,OAAOA;AACT,EAAC"}
@@ -1,3 +1,3 @@
1
- import type { DeleteVersions } from 'payload';
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,SAAS,CAAA;AAM7C,eAAO,MAAM,cAAc,EAAE,cAe5B,CAAA"}
1
+ {"version":3,"file":"deleteVersions.d.ts","sourceRoot":"","sources":["../src/deleteVersions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgC,KAAK,cAAc,EAAE,MAAM,SAAS,CAAA;AAO3E,eAAO,MAAM,cAAc,EAAE,cAoB5B,CAAA"}
@@ -1,10 +1,13 @@
1
+ import { buildVersionCollectionFields } from 'payload';
2
+ import { buildQuery } from './queries/buildQuery.js';
1
3
  import { getSession } from './utilities/getSession.js';
2
4
  export const deleteVersions = async function deleteVersions({ collection, locale, req, where }) {
3
5
  const VersionsModel = this.versions[collection];
4
6
  const session = await getSession(this, req);
5
- const query = await VersionsModel.buildQuery({
7
+ const query = await buildQuery({
8
+ adapter: this,
9
+ fields: buildVersionCollectionFields(this.payload.config, this.payload.collections[collection].config, true),
6
10
  locale,
7
- payload: this.payload,
8
11
  where
9
12
  });
10
13
  await VersionsModel.deleteMany(query, {
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/deleteVersions.ts"],"sourcesContent":["import type { DeleteVersions } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { getSession } from './utilities/getSession.js'\n\nexport const deleteVersions: DeleteVersions = async function deleteVersions(\n this: MongooseAdapter,\n { collection, locale, req, where },\n) {\n const VersionsModel = this.versions[collection]\n\n const session = await getSession(this, req)\n\n const query = await VersionsModel.buildQuery({\n locale,\n payload: this.payload,\n where,\n })\n\n await VersionsModel.deleteMany(query, { session })\n}\n"],"names":["getSession","deleteVersions","collection","locale","req","where","VersionsModel","versions","session","query","buildQuery","payload","deleteMany"],"mappings":"AAIA,SAASA,UAAU,QAAQ,4BAA2B;AAEtD,OAAO,MAAMC,iBAAiC,eAAeA,eAE3D,EAAEC,UAAU,EAAEC,MAAM,EAAEC,GAAG,EAAEC,KAAK,EAAE;IAElC,MAAMC,gBAAgB,IAAI,CAACC,QAAQ,CAACL,WAAW;IAE/C,MAAMM,UAAU,MAAMR,WAAW,IAAI,EAAEI;IAEvC,MAAMK,QAAQ,MAAMH,cAAcI,UAAU,CAAC;QAC3CP;QACAQ,SAAS,IAAI,CAACA,OAAO;QACrBN;IACF;IAEA,MAAMC,cAAcM,UAAU,CAACH,OAAO;QAAED;IAAQ;AAClD,EAAC"}
1
+ {"version":3,"sources":["../src/deleteVersions.ts"],"sourcesContent":["import { buildVersionCollectionFields, type DeleteVersions } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { getSession } from './utilities/getSession.js'\n\nexport const deleteVersions: DeleteVersions = async function deleteVersions(\n this: MongooseAdapter,\n { collection, locale, req, where },\n) {\n const VersionsModel = this.versions[collection]\n\n const session = await getSession(this, req)\n\n const query = await buildQuery({\n adapter: this,\n fields: buildVersionCollectionFields(\n this.payload.config,\n this.payload.collections[collection].config,\n true,\n ),\n locale,\n where,\n })\n\n await VersionsModel.deleteMany(query, { session })\n}\n"],"names":["buildVersionCollectionFields","buildQuery","getSession","deleteVersions","collection","locale","req","where","VersionsModel","versions","session","query","adapter","fields","payload","config","collections","deleteMany"],"mappings":"AAAA,SAASA,4BAA4B,QAA6B,UAAS;AAI3E,SAASC,UAAU,QAAQ,0BAAyB;AACpD,SAASC,UAAU,QAAQ,4BAA2B;AAEtD,OAAO,MAAMC,iBAAiC,eAAeA,eAE3D,EAAEC,UAAU,EAAEC,MAAM,EAAEC,GAAG,EAAEC,KAAK,EAAE;IAElC,MAAMC,gBAAgB,IAAI,CAACC,QAAQ,CAACL,WAAW;IAE/C,MAAMM,UAAU,MAAMR,WAAW,IAAI,EAAEI;IAEvC,MAAMK,QAAQ,MAAMV,WAAW;QAC7BW,SAAS,IAAI;QACbC,QAAQb,6BACN,IAAI,CAACc,OAAO,CAACC,MAAM,EACnB,IAAI,CAACD,OAAO,CAACE,WAAW,CAACZ,WAAW,CAACW,MAAM,EAC3C;QAEFV;QACAE;IACF;IAEA,MAAMC,cAAcS,UAAU,CAACN,OAAO;QAAED;IAAQ;AAClD,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"find.d.ts","sourceRoot":"","sources":["../src/find.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAYnC,eAAO,MAAM,IAAI,EAAE,IAgIlB,CAAA"}
1
+ {"version":3,"file":"find.d.ts","sourceRoot":"","sources":["../src/find.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAanC,eAAO,MAAM,IAAI,EAAE,IAkIlB,CAAA"}
package/dist/find.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { flattenWhereToOperators } from 'payload';
2
+ import { buildQuery } from './queries/buildQuery.js';
2
3
  import { buildSortParam } from './queries/buildSortParam.js';
3
4
  import { buildJoinAggregation } from './utilities/buildJoinAggregation.js';
4
5
  import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
@@ -23,9 +24,11 @@ export const find = async function find({ collection, joins = {}, limit = 0, loc
23
24
  timestamps: true
24
25
  });
25
26
  }
26
- const query = await Model.buildQuery({
27
+ const query = await buildQuery({
28
+ adapter: this,
29
+ collectionSlug: collection,
30
+ fields: this.payload.collections[collection].config.flattenedFields,
27
31
  locale,
28
- payload: this.payload,
29
32
  where
30
33
  });
31
34
  // useEstimatedCount is faster, but not accurate, as it ignores any filters. It is thus set to true if there are no filters.
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'\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 { getSession } from './utilities/getSession.js'\nimport { sanitizeInternalFields } from './utilities/sanitizeInternalFields.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,\n select,\n sort: sortArg,\n where,\n },\n) {\n const Model = this.collections[collection]\n const collectionConfig = this.payload.collections[collection].config\n\n const session = await getSession(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.flattenedFields,\n locale,\n sort: sortArg || collectionConfig.defaultSort,\n timestamps: true,\n })\n }\n\n const query = await Model.buildQuery({\n locale,\n payload: this.payload,\n where,\n })\n\n // useEstimatedCount is faster, but not accurate, as it ignores any filters. It is thus set to true if there are no filters.\n const useEstimatedCount = hasNearConstraint || !query || Object.keys(query).length === 0\n const paginationOptions: PaginateOptions = {\n lean: true,\n leanWithId: true,\n options: {\n session,\n },\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.flattenedFields,\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 hint: { _id: 1 },\n session,\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","getSession","sanitizeInternalFields","find","collection","joins","limit","locale","page","pagination","projection","req","select","sort","sortArg","where","Model","collections","collectionConfig","payload","config","session","hasNearConstraint","constraints","some","prop","Object","keys","key","fields","flattenedFields","defaultSort","timestamps","query","buildQuery","useEstimatedCount","length","paginationOptions","lean","leanWithId","options","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,UAAU,QAAQ,4BAA2B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EAAC"}
1
+ {"version":3,"sources":["../src/find.ts"],"sourcesContent":["import type { PaginateOptions } from 'mongoose'\nimport type { Find } from 'payload'\n\nimport { flattenWhereToOperators } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { buildSortParam } from './queries/buildSortParam.js'\nimport { buildJoinAggregation } from './utilities/buildJoinAggregation.js'\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getSession } from './utilities/getSession.js'\nimport { sanitizeInternalFields } from './utilities/sanitizeInternalFields.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,\n select,\n sort: sortArg,\n where,\n },\n) {\n const Model = this.collections[collection]\n const collectionConfig = this.payload.collections[collection].config\n\n const session = await getSession(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.flattenedFields,\n locale,\n sort: sortArg || collectionConfig.defaultSort,\n timestamps: true,\n })\n }\n\n const query = await buildQuery({\n adapter: this,\n collectionSlug: collection,\n fields: this.payload.collections[collection].config.flattenedFields,\n locale,\n where,\n })\n\n // useEstimatedCount is faster, but not accurate, as it ignores any filters. It is thus set to true if there are no filters.\n const useEstimatedCount = hasNearConstraint || !query || Object.keys(query).length === 0\n const paginationOptions: PaginateOptions = {\n lean: true,\n leanWithId: true,\n options: {\n session,\n },\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.flattenedFields,\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 hint: { _id: 1 },\n session,\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","buildQuery","buildSortParam","buildJoinAggregation","buildProjectionFromSelect","getSession","sanitizeInternalFields","find","collection","joins","limit","locale","page","pagination","projection","req","select","sort","sortArg","where","Model","collections","collectionConfig","payload","config","session","hasNearConstraint","constraints","some","prop","Object","keys","key","fields","flattenedFields","defaultSort","timestamps","query","adapter","collectionSlug","useEstimatedCount","length","paginationOptions","lean","leanWithId","options","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,UAAU,QAAQ,0BAAyB;AACpD,SAASC,cAAc,QAAQ,8BAA6B;AAC5D,SAASC,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,OAAOI,IAAI;IAElD,OAAO;QACL,GAAGJ,MAAM;QACTI,MAAMA,KAAKI,GAAG,CAAC,CAACC;YACdA,IAAIC,EAAE,GAAGD,IAAIV,GAAG;YAChB,OAAOhD,uBAAuB0D;QAChC;IACF;AACF,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"findGlobal.d.ts","sourceRoot":"","sources":["../src/findGlobal.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAUzC,eAAO,MAAM,UAAU,EAAE,UAoCxB,CAAA"}
1
+ {"version":3,"file":"findGlobal.d.ts","sourceRoot":"","sources":["../src/findGlobal.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAWzC,eAAO,MAAM,UAAU,EAAE,UAsCxB,CAAA"}
@@ -1,22 +1,25 @@
1
1
  import { combineQueries } from 'payload';
2
+ import { buildQuery } from './queries/buildQuery.js';
2
3
  import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
3
4
  import { getSession } from './utilities/getSession.js';
4
5
  import { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js';
5
6
  export const findGlobal = async function findGlobal({ slug, locale, req, select, where }) {
6
7
  const Model = this.globals;
8
+ const fields = this.payload.globals.config.find((each)=>each.slug === slug).flattenedFields;
7
9
  const options = {
8
10
  lean: true,
9
11
  select: buildProjectionFromSelect({
10
12
  adapter: this,
11
- fields: this.payload.globals.config.find((each)=>each.slug === slug).flattenedFields,
13
+ fields,
12
14
  select
13
15
  }),
14
16
  session: await getSession(this, req)
15
17
  };
16
- const query = await Model.buildQuery({
18
+ const query = await buildQuery({
19
+ adapter: this,
20
+ fields,
17
21
  globalSlug: slug,
18
22
  locale,
19
- payload: this.payload,
20
23
  where: combineQueries({
21
24
  globalType: {
22
25
  equals: slug
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/findGlobal.ts"],"sourcesContent":["import type { QueryOptions } from 'mongoose'\nimport type { FindGlobal } from 'payload'\n\nimport { combineQueries } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getSession } from './utilities/getSession.js'\nimport { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js'\n\nexport const findGlobal: FindGlobal = async function findGlobal(\n this: MongooseAdapter,\n { slug, locale, req, select, where },\n) {\n const Model = this.globals\n const options: QueryOptions = {\n lean: true,\n select: buildProjectionFromSelect({\n adapter: this,\n fields: this.payload.globals.config.find((each) => each.slug === slug).flattenedFields,\n select,\n }),\n session: await getSession(this, req),\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","getSession","sanitizeInternalFields","findGlobal","slug","locale","req","select","where","Model","globals","options","lean","adapter","fields","payload","config","find","each","flattenedFields","session","query","buildQuery","globalSlug","globalType","equals","doc","findOne","_id","id","JSON","parse","stringify"],"mappings":"AAGA,SAASA,cAAc,QAAQ,UAAS;AAIxC,SAASC,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,sBAAsB,QAAQ,wCAAuC;AAE9E,OAAO,MAAMC,aAAyB,eAAeA,WAEnD,EAAEC,IAAI,EAAEC,MAAM,EAAEC,GAAG,EAAEC,MAAM,EAAEC,KAAK,EAAE;IAEpC,MAAMC,QAAQ,IAAI,CAACC,OAAO;IAC1B,MAAMC,UAAwB;QAC5BC,MAAM;QACNL,QAAQP,0BAA0B;YAChCa,SAAS,IAAI;YACbC,QAAQ,IAAI,CAACC,OAAO,CAACL,OAAO,CAACM,MAAM,CAACC,IAAI,CAAC,CAACC,OAASA,KAAKd,IAAI,KAAKA,MAAMe,eAAe;YACtFZ;QACF;QACAa,SAAS,MAAMnB,WAAW,IAAI,EAAEK;IAClC;IAEA,MAAMe,QAAQ,MAAMZ,MAAMa,UAAU,CAAC;QACnCC,YAAYnB;QACZC;QACAU,SAAS,IAAI,CAACA,OAAO;QACrBP,OAAOT,eAAe;YAAEyB,YAAY;gBAAEC,QAAQrB;YAAK;QAAE,GAAGI;IAC1D;IAEA,IAAIkB,MAAO,MAAMjB,MAAMkB,OAAO,CAACN,OAAO,CAAC,GAAGV;IAE1C,IAAI,CAACe,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,MAAMxB,uBAAuBwB;IAE7B,OAAOA;AACT,EAAC"}
1
+ {"version":3,"sources":["../src/findGlobal.ts"],"sourcesContent":["import type { QueryOptions } from 'mongoose'\nimport type { FindGlobal } from 'payload'\n\nimport { combineQueries } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getSession } from './utilities/getSession.js'\nimport { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js'\n\nexport const findGlobal: FindGlobal = async function findGlobal(\n this: MongooseAdapter,\n { slug, locale, req, select, where },\n) {\n const Model = this.globals\n const fields = this.payload.globals.config.find((each) => each.slug === slug).flattenedFields\n const options: QueryOptions = {\n lean: true,\n select: buildProjectionFromSelect({\n adapter: this,\n fields,\n select,\n }),\n session: await getSession(this, req),\n }\n\n const query = await buildQuery({\n adapter: this,\n fields,\n globalSlug: slug,\n locale,\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","buildQuery","buildProjectionFromSelect","getSession","sanitizeInternalFields","findGlobal","slug","locale","req","select","where","Model","globals","fields","payload","config","find","each","flattenedFields","options","lean","adapter","session","query","globalSlug","globalType","equals","doc","findOne","_id","id","JSON","parse","stringify"],"mappings":"AAGA,SAASA,cAAc,QAAQ,UAAS;AAIxC,SAASC,UAAU,QAAQ,0BAAyB;AACpD,SAASC,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,sBAAsB,QAAQ,wCAAuC;AAE9E,OAAO,MAAMC,aAAyB,eAAeA,WAEnD,EAAEC,IAAI,EAAEC,MAAM,EAAEC,GAAG,EAAEC,MAAM,EAAEC,KAAK,EAAE;IAEpC,MAAMC,QAAQ,IAAI,CAACC,OAAO;IAC1B,MAAMC,SAAS,IAAI,CAACC,OAAO,CAACF,OAAO,CAACG,MAAM,CAACC,IAAI,CAAC,CAACC,OAASA,KAAKX,IAAI,KAAKA,MAAMY,eAAe;IAC7F,MAAMC,UAAwB;QAC5BC,MAAM;QACNX,QAAQP,0BAA0B;YAChCmB,SAAS,IAAI;YACbR;YACAJ;QACF;QACAa,SAAS,MAAMnB,WAAW,IAAI,EAAEK;IAClC;IAEA,MAAMe,QAAQ,MAAMtB,WAAW;QAC7BoB,SAAS,IAAI;QACbR;QACAW,YAAYlB;QACZC;QACAG,OAAOV,eAAe;YAAEyB,YAAY;gBAAEC,QAAQpB;YAAK;QAAE,GAAGI;IAC1D;IAEA,IAAIiB,MAAO,MAAMhB,MAAMiB,OAAO,CAACL,OAAO,CAAC,GAAGJ;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,MAAMvB,uBAAuBuB;IAE7B,OAAOA;AACT,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"findGlobalVersions.d.ts","sourceRoot":"","sources":["../src/findGlobalVersions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAA;AAWjD,eAAO,MAAM,kBAAkB,EAAE,kBAqGhC,CAAA"}
1
+ {"version":3,"file":"findGlobalVersions.d.ts","sourceRoot":"","sources":["../src/findGlobalVersions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAA;AAYjD,eAAO,MAAM,kBAAkB,EAAE,kBAqGhC,CAAA"}
@@ -1,4 +1,5 @@
1
1
  import { buildVersionGlobalFields, flattenWhereToOperators } from 'payload';
2
+ import { buildQuery } from './queries/buildQuery.js';
2
3
  import { buildSortParam } from './queries/buildSortParam.js';
3
4
  import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
4
5
  import { getSession } from './utilities/getSession.js';
@@ -27,10 +28,10 @@ export const findGlobalVersions = async function findGlobalVersions({ global, li
27
28
  timestamps: true
28
29
  });
29
30
  }
30
- const query = await Model.buildQuery({
31
- globalSlug: global,
31
+ const query = await buildQuery({
32
+ adapter: this,
33
+ fields: versionFields,
32
34
  locale,
33
- payload: this.payload,
34
35
  where
35
36
  });
36
37
  // useEstimatedCount is faster, but not accurate, as it ignores any filters. It is thus set to true if there are no filters.
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/findGlobalVersions.ts"],"sourcesContent":["import type { PaginateOptions, QueryOptions } from 'mongoose'\nimport type { FindGlobalVersions } 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 { getSession } from './utilities/getSession.js'\nimport { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js'\n\nexport const findGlobalVersions: FindGlobalVersions = async function findGlobalVersions(\n this: MongooseAdapter,\n { global, limit, locale, page, pagination, req, select, skip, sort: sortArg, where },\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 true,\n )\n\n const session = await getSession(this, req)\n const options: QueryOptions = {\n limit,\n session,\n skip,\n }\n\n let hasNearConstraint = false\n\n if (where) {\n const constraints = flattenWhereToOperators(where)\n hasNearConstraint = constraints.some((prop) => Object.keys(prop).some((key) => key === 'near'))\n }\n\n let sort\n if (!hasNearConstraint) {\n sort = buildSortParam({\n config: this.payload.config,\n fields: versionFields,\n locale,\n sort: sortArg || '-updatedAt',\n timestamps: true,\n })\n }\n\n const query = await Model.buildQuery({\n globalSlug: global,\n locale,\n payload: this.payload,\n where,\n })\n\n // useEstimatedCount is faster, but not accurate, as it ignores any filters. It is thus set to true if there are no filters.\n const useEstimatedCount = hasNearConstraint || !query || Object.keys(query).length === 0\n const paginationOptions: PaginateOptions = {\n lean: true,\n leanWithId: true,\n limit,\n options,\n page,\n pagination,\n projection: buildProjectionFromSelect({ adapter: this, fields: versionFields, select }),\n sort,\n useEstimatedCount,\n }\n\n if (this.collation) {\n const defaultLocale = 'en'\n paginationOptions.collation = {\n locale: locale && locale !== 'all' && locale !== '*' ? locale : defaultLocale,\n ...this.collation,\n }\n }\n\n if (!useEstimatedCount && Object.keys(query).length === 0 && this.disableIndexHints !== true) {\n // Improve the performance of the countDocuments query which is used if useEstimatedCount is set to false by adding\n // a hint. By default, if no hint is provided, MongoDB does not use an indexed field to count the returned documents,\n // which makes queries very slow. This only happens when no query (filter) is provided. If one is provided, it uses\n // the correct indexed field\n paginationOptions.useCustomCountFn = () => {\n return Promise.resolve(\n Model.countDocuments(query, {\n hint: { _id: 1 },\n session,\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","getSession","sanitizeInternalFields","findGlobalVersions","global","limit","locale","page","pagination","req","select","skip","sort","sortArg","where","Model","versions","versionFields","payload","config","globals","find","slug","session","options","hasNearConstraint","constraints","some","prop","Object","keys","key","fields","timestamps","query","buildQuery","globalSlug","useEstimatedCount","length","paginationOptions","lean","leanWithId","projection","adapter","collation","defaultLocale","disableIndexHints","useCustomCountFn","Promise","resolve","countDocuments","hint","_id","result","paginate","docs","JSON","parse","stringify","map","doc","id"],"mappings":"AAGA,SAASA,wBAAwB,EAAEC,uBAAuB,QAAQ,UAAS;AAI3E,SAASC,cAAc,QAAQ,8BAA6B;AAC5D,SAASC,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,sBAAsB,QAAQ,wCAAuC;AAE9E,OAAO,MAAMC,qBAAyC,eAAeA,mBAEnE,EAAEC,MAAM,EAAEC,KAAK,EAAEC,MAAM,EAAEC,IAAI,EAAEC,UAAU,EAAEC,GAAG,EAAEC,MAAM,EAAEC,IAAI,EAAEC,MAAMC,OAAO,EAAEC,KAAK,EAAE;IAEpF,MAAMC,QAAQ,IAAI,CAACC,QAAQ,CAACZ,OAAO;IACnC,MAAMa,gBAAgBpB,yBACpB,IAAI,CAACqB,OAAO,CAACC,MAAM,EACnB,IAAI,CAACD,OAAO,CAACE,OAAO,CAACD,MA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HAAmH;QACnH,4BAA4B;QAC5BP,kBAAkBQ,gBAAgB,GAAG;YACnC,OAAOC,QAAQC,OAAO,CACpBlC,MAAMmC,cAAc,CAAChB,OAAO;gBAC1BiB,MAAM;oBAAEC,KAAK;gBAAE;gBACf7B;YACF;QAEJ;IACF;IAEA,IAAIlB,SAAS,GAAG;QACdkC,kBAAkBlC,KAAK,GAAGA;QAC1B,qEAAqE;QACrEkC,kBAAkBf,OAAO,CAACnB,KAAK,GAAGA;QAElC,mCAAmC;QACnC,IAAIA,UAAU,GAAG;YACfkC,kBAAkB/B,UAAU,GAAG;QACjC;IACF;IAEA,MAAM6C,SAAS,MAAMtC,MAAMuC,QAAQ,CAACpB,OAAOK;IAC3C,MAAMgB,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,OAAOlD,uBAAuB0D;QAChC;IACF;AACF,EAAC"}
1
+ {"version":3,"sources":["../src/findGlobalVersions.ts"],"sourcesContent":["import type { PaginateOptions, QueryOptions } from 'mongoose'\nimport type { FindGlobalVersions } from 'payload'\n\nimport { buildVersionGlobalFields, flattenWhereToOperators } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { buildSortParam } from './queries/buildSortParam.js'\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getSession } from './utilities/getSession.js'\nimport { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js'\n\nexport const findGlobalVersions: FindGlobalVersions = async function findGlobalVersions(\n this: MongooseAdapter,\n { global, limit, locale, page, pagination, req, select, skip, sort: sortArg, where },\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 true,\n )\n\n const session = await getSession(this, req)\n const options: QueryOptions = {\n limit,\n session,\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 buildQuery({\n adapter: this,\n fields: versionFields,\n locale,\n where,\n })\n\n // useEstimatedCount is faster, but not accurate, as it ignores any filters. It is thus set to true if there are no filters.\n const useEstimatedCount = hasNearConstraint || !query || Object.keys(query).length === 0\n const paginationOptions: PaginateOptions = {\n lean: true,\n leanWithId: true,\n limit,\n options,\n page,\n pagination,\n projection: buildProjectionFromSelect({ adapter: this, fields: versionFields, select }),\n sort,\n useEstimatedCount,\n }\n\n if (this.collation) {\n const defaultLocale = 'en'\n paginationOptions.collation = {\n locale: locale && locale !== 'all' && locale !== '*' ? locale : defaultLocale,\n ...this.collation,\n }\n }\n\n if (!useEstimatedCount && Object.keys(query).length === 0 && this.disableIndexHints !== true) {\n // Improve the performance of the countDocuments query which is used if useEstimatedCount is set to false by adding\n // a hint. By default, if no hint is provided, MongoDB does not use an indexed field to count the returned documents,\n // which makes queries very slow. This only happens when no query (filter) is provided. If one is provided, it uses\n // the correct indexed field\n paginationOptions.useCustomCountFn = () => {\n return Promise.resolve(\n Model.countDocuments(query, {\n hint: { _id: 1 },\n session,\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","buildQuery","buildSortParam","buildProjectionFromSelect","getSession","sanitizeInternalFields","findGlobalVersions","global","limit","locale","page","pagination","req","select","skip","sort","sortArg","where","Model","versions","versionFields","payload","config","globals","find","slug","session","options","hasNearConstraint","constraints","some","prop","Object","keys","key","fields","timestamps","query","adapter","useEstimatedCount","length","paginationOptions","lean","leanWithId","projection","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,UAAU,QAAQ,0BAAyB;AACpD,SAASC,cAAc,QAAQ,8BAA6B;AAC5D,SAASC,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,sBAAsB,QAAQ,wCAAuC;AAE9E,OAAO,MAAMC,qBAAyC,eAAeA,mBAEnE,EAAEC,MAAM,EAAEC,KAAK,EAAEC,MAAM,EAAEC,IAAI,EAAEC,UAAU,EAAEC,GAAG,EAAEC,MAAM,EAAEC,IAAI,EAAEC,MAAMC,OAAO,EAAEC,KAAK,EAAE;IAEpF,MAAMC,QAAQ,IAAI,CAACC,QAAQ,CAACZ,OAAO;IACnC,MAAMa,gBAAgBrB,yBACpB,IAAI,CAACsB,OAAO,CAACC,MAAM,EACnB,IAAI,CAACD,OAAO,CAACE,OAAO,CAACD,MAAM,CAACE,IAAI,CAAC,CAAC,EAAEC,IAAI,EAAE,GAAKA,SAASlB,SACxD;IAGF,MAAMmB,UAAU,MAAMtB,WAAW,IAAI,EAAEQ;IACvC,MAAMe,UAAwB;QAC5BnB;QACAkB;QACAZ;IACF;IAEA,IAAIc,oBAAoB;IAExB,IAAIX,OAAO;QACT,MAAMY,cAAc7B,wBAAwBiB;QAC5CW,oBAAoBC,YAAYC,IAAI,CAAC,CAACC,OAASC,OAAOC,IAAI,CAACF,MAAMD,IAAI,C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9B,UAAU,GAAG;QACjC;IACF;IAEA,MAAM2C,SAAS,MAAMpC,MAAMqC,QAAQ,CAAClB,OAAOI;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"}
@@ -1 +1 @@
1
- {"version":3,"file":"findOne.d.ts","sourceRoot":"","sources":["../src/findOne.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAY,OAAO,EAAE,MAAM,SAAS,CAAA;AAShD,eAAO,MAAM,OAAO,EAAE,OAsDrB,CAAA"}
1
+ {"version":3,"file":"findOne.d.ts","sourceRoot":"","sources":["../src/findOne.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAY,OAAO,EAAE,MAAM,SAAS,CAAA;AAUhD,eAAO,MAAM,OAAO,EAAE,OAwDrB,CAAA"}
package/dist/findOne.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { buildQuery } from './queries/buildQuery.js';
1
2
  import { buildJoinAggregation } from './utilities/buildJoinAggregation.js';
2
3
  import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
3
4
  import { getSession } from './utilities/getSession.js';
@@ -10,9 +11,11 @@ export const findOne = async function findOne({ collection, joins, locale, req,
10
11
  lean: true,
11
12
  session
12
13
  };
13
- const query = await Model.buildQuery({
14
+ const query = await buildQuery({
15
+ adapter: this,
16
+ collectionSlug: collection,
17
+ fields: collectionConfig.flattenedFields,
14
18
  locale,
15
- payload: this.payload,
16
19
  where
17
20
  });
18
21
  const projection = buildProjectionFromSelect({
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/findOne.ts"],"sourcesContent":["import type { AggregateOptions, QueryOptions } from 'mongoose'\nimport type { Document, FindOne } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildJoinAggregation } from './utilities/buildJoinAggregation.js'\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getSession } from './utilities/getSession.js'\nimport { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js'\n\nexport const findOne: FindOne = async function findOne(\n this: MongooseAdapter,\n { collection, joins, locale, req, select, where },\n) {\n const Model = this.collections[collection]\n const collectionConfig = this.payload.collections[collection].config\n const session = await getSession(this, req)\n const options: AggregateOptions & QueryOptions = {\n lean: true,\n session,\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.flattenedFields,\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, { session })\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","getSession","sanitizeInternalFields","findOne","collection","joins","locale","req","select","where","Model","collections","collectionConfig","payload","config","session","options","lean","query","buildQuery","projection","adapter","fields","flattenedFields","aggregate","limit","doc","result","JSON","parse","stringify","id","_id"],"mappings":"AAKA,SAASA,oBAAoB,QAAQ,sCAAqC;AAC1E,SAASC,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,sBAAsB,QAAQ,wCAAuC;AAE9E,OAAO,MAAMC,UAAmB,eAAeA,QAE7C,EAAEC,UAAU,EAAEC,KAAK,EAAEC,MAAM,EAAEC,GAAG,EAAEC,MAAM,EAAEC,KAAK,EAAE;IAEjD,MAAMC,QAAQ,IAAI,CAACC,WAAW,CAACP,WAAW;IAC1C,MAAMQ,mBAAmB,IAAI,CAACC,OAAO,CAACF,WAAW,CAACP,WAAW,CAACU,MAAM;IACpE,MAAMC,UAAU,MAAMd,WAAW,IAAI,EAAEM;IACvC,MAAMS,UAA2C;QAC/CC,MAAM;QACNF;IACF;IAEA,MAAMG,QAAQ,MAAMR,MAAMS,UAAU,CAAC;QACnCb;QACAO,SAAS,IAAI,CAACA,OAAO;QACrBJ;IACF;IAEA,MAAMW,aAAapB,0BAA0B;QAC3CqB,SAAS,IAAI;QACbC,QAAQV,iBAAiBW,eAAe;QACxCf;IACF;IAEA,MAAMgB,YAAY,MAAMzB,qBAAqB;QAC3CsB,SAAS,IAAI;QACbjB;QACAQ;QACAP;QACAoB,OAAO;QACPnB;QACAc;QACAF;IACF;IAEA,IAAIQ;IACJ,IAAIF,WAAW;;QACZ,CAACE,IAAI,GAAG,MAAMhB,MAAMc,SAAS,CAACA,WAAW;YAAET;QAAQ;IACtD,OAAO;;QACHC,QAAoCI,UAAU,GAAGA;QACnDM,MAAM,MAAMhB,MAAMP,OAAO,CAACe,OAAO,CAAC,GAAGF;IACvC;IAEA,IAAI,CAACU,KAAK;QACR,OAAO;IACT;IAEA,IAAIC,SAAmBC,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACJ;IAEjD,uBAAuB;IACvBC,OAAOI,EAAE,GAAGJ,OAAOK,GAAG;IACtBL,SAASzB,uBAAuByB;IAEhC,OAAOA;AACT,EAAC"}
1
+ {"version":3,"sources":["../src/findOne.ts"],"sourcesContent":["import type { AggregateOptions, QueryOptions } from 'mongoose'\nimport type { Document, FindOne } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { buildJoinAggregation } from './utilities/buildJoinAggregation.js'\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getSession } from './utilities/getSession.js'\nimport { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js'\n\nexport const findOne: FindOne = async function findOne(\n this: MongooseAdapter,\n { collection, joins, locale, req, select, where },\n) {\n const Model = this.collections[collection]\n const collectionConfig = this.payload.collections[collection].config\n const session = await getSession(this, req)\n const options: AggregateOptions & QueryOptions = {\n lean: true,\n session,\n }\n\n const query = await buildQuery({\n adapter: this,\n collectionSlug: collection,\n fields: collectionConfig.flattenedFields,\n locale,\n where,\n })\n\n const projection = buildProjectionFromSelect({\n adapter: this,\n fields: collectionConfig.flattenedFields,\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, { session })\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":["buildQuery","buildJoinAggregation","buildProjectionFromSelect","getSession","sanitizeInternalFields","findOne","collection","joins","locale","req","select","where","Model","collections","collectionConfig","payload","config","session","options","lean","query","adapter","collectionSlug","fields","flattenedFields","projection","aggregate","limit","doc","result","JSON","parse","stringify","id","_id"],"mappings":"AAKA,SAASA,UAAU,QAAQ,0BAAyB;AACpD,SAASC,oBAAoB,QAAQ,sCAAqC;AAC1E,SAASC,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,sBAAsB,QAAQ,wCAAuC;AAE9E,OAAO,MAAMC,UAAmB,eAAeA,QAE7C,EAAEC,UAAU,EAAEC,KAAK,EAAEC,MAAM,EAAEC,GAAG,EAAEC,MAAM,EAAEC,KAAK,EAAE;IAEjD,MAAMC,QAAQ,IAAI,CAACC,WAAW,CAACP,WAAW;IAC1C,MAAMQ,mBAAmB,IAAI,CAACC,OAAO,CAACF,WAAW,CAACP,WAAW,CAACU,MAAM;IACpE,MAAMC,UAAU,MAAMd,WAAW,IAAI,EAAEM;IACvC,MAAMS,UAA2C;QAC/CC,MAAM;QACNF;IACF;IAEA,MAAMG,QAAQ,MAAMpB,WAAW;QAC7BqB,SAAS,IAAI;QACbC,gBAAgBhB;QAChBiB,QAAQT,iBAAiBU,eAAe;QACxChB;QACAG;IACF;IAEA,MAAMc,aAAavB,0BAA0B;QAC3CmB,SAAS,IAAI;QACbE,QAAQT,iBAAiBU,eAAe;QACxCd;IACF;IAEA,MAAMgB,YAAY,MAAMzB,qBAAqB;QAC3CoB,SAAS,IAAI;QACbf;QACAQ;QACAP;QACAoB,OAAO;QACPnB;QACAiB;QACAL;IACF;IAEA,IAAIQ;IACJ,IAAIF,WAAW;;QACZ,CAACE,IAAI,GAAG,MAAMhB,MAAMc,SAAS,CAACA,WAAW;YAAET;QAAQ;IACtD,OAAO;;QACHC,QAAoCO,UAAU,GAAGA;QACnDG,MAAM,MAAMhB,MAAMP,OAAO,CAACe,OAAO,CAAC,GAAGF;IACvC;IAEA,IAAI,CAACU,KAAK;QACR,OAAO;IACT;IAEA,IAAIC,SAAmBC,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACJ;IAEjD,uBAAuB;IACvBC,OAAOI,EAAE,GAAGJ,OAAOK,GAAG;IACtBL,SAASzB,uBAAuByB;IAEhC,OAAOA;AACT,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"findVersions.d.ts","sourceRoot":"","sources":["../src/findVersions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAW3C,eAAO,MAAM,YAAY,EAAE,YAmG1B,CAAA"}
1
+ {"version":3,"file":"findVersions.d.ts","sourceRoot":"","sources":["../src/findVersions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAY3C,eAAO,MAAM,YAAY,EAAE,YAsG1B,CAAA"}
@@ -1,4 +1,5 @@
1
1
  import { buildVersionCollectionFields, flattenWhereToOperators } from 'payload';
2
+ import { buildQuery } from './queries/buildQuery.js';
2
3
  import { buildSortParam } from './queries/buildSortParam.js';
3
4
  import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
4
5
  import { getSession } from './utilities/getSession.js';
@@ -27,9 +28,11 @@ export const findVersions = async function findVersions({ collection, limit, loc
27
28
  timestamps: true
28
29
  });
29
30
  }
30
- const query = await Model.buildQuery({
31
+ const fields = buildVersionCollectionFields(this.payload.config, collectionConfig, true);
32
+ const query = await buildQuery({
33
+ adapter: this,
34
+ fields,
31
35
  locale,
32
- payload: this.payload,
33
36
  where
34
37
  });
35
38
  // useEstimatedCount is faster, but not accurate, as it ignores any filters. It is thus set to true if there are no filters.
@@ -43,7 +46,7 @@ export const findVersions = async function findVersions({ collection, limit, loc
43
46
  pagination,
44
47
  projection: buildProjectionFromSelect({
45
48
  adapter: this,
46
- fields: buildVersionCollectionFields(this.payload.config, collectionConfig, true),
49
+ fields,
47
50
  select
48
51
  }),
49
52
  sort,
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/findVersions.ts"],"sourcesContent":["import type { PaginateOptions, QueryOptions } from 'mongoose'\nimport type { FindVersions } 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 { getSession } from './utilities/getSession.js'\nimport { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js'\n\nexport const findVersions: FindVersions = async function findVersions(\n this: MongooseAdapter,\n { collection, limit, locale, page, pagination, req = {}, select, skip, sort: sortArg, where },\n) {\n const Model = this.versions[collection]\n const collectionConfig = this.payload.collections[collection].config\n const session = await getSession(this, req)\n const options: QueryOptions = {\n limit,\n session,\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.flattenedFields,\n locale,\n sort: sortArg || '-updatedAt',\n timestamps: true,\n })\n }\n\n const query = await Model.buildQuery({\n locale,\n payload: this.payload,\n where,\n })\n\n // useEstimatedCount is faster, but not accurate, as it ignores any filters. It is thus set to true if there are no filters.\n const useEstimatedCount = hasNearConstraint || !query || Object.keys(query).length === 0\n const paginationOptions: PaginateOptions = {\n lean: true,\n leanWithId: true,\n limit,\n options,\n page,\n pagination,\n projection: buildProjectionFromSelect({\n adapter: this,\n fields: buildVersionCollectionFields(this.payload.config, collectionConfig, true),\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 hint: { _id: 1 },\n session,\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","getSession","sanitizeInternalFields","findVersions","collection","limit","locale","page","pagination","req","select","skip","sort","sortArg","where","Model","versions","collectionConfig","payload","collections","config","session","options","hasNearConstraint","constraints","some","prop","Object","keys","key","fields","flattenedFields","timestamps","query","buildQuery","useEstimatedCount","length","paginationOptions","lean","leanWithId","projection","adapter","collation","defaultLocale","disableIndexHints","useCustomCountFn","Promise","resolve","countDocuments","hint","_id","result","paginate","docs","JSON","parse","stringify","map","doc","id"],"mappings":"AAGA,SAASA,4BAA4B,EAAEC,uBAAuB,QAAQ,UAAS;AAI/E,SAASC,cAAc,QAAQ,8BAA6B;AAC5D,SAASC,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,sBAAsB,QAAQ,wCAAuC;AAE9E,OAAO,MAAMC,eAA6B,eAAeA,aAEvD,EAAEC,UAAU,EAAEC,KAAK,EAAEC,MAAM,EAAEC,IAAI,EAAEC,UAAU,EAAEC,MAAM,CAAC,CAAC,EAAEC,MAAM,EAAEC,IAAI,EAAEC,MAAMC,OAAO,EAAEC,KAAK,EAAE;IAE7F,MAAMC,QAAQ,IAAI,CAACC,QAAQ,CAACZ,WAAW;IACvC,MAAMa,mBAAmB,IAAI,CAACC,OAAO,CAACC,WAAW,CAACf,WAAW,CAACgB,MAAM;IACpE,MAAMC,UAAU,MAAMpB,WAAW,IAAI,EAAEQ;IACvC,MAAMa,UAAwB;QAC5BjB;QACAgB;QACAV;IACF;IAEA,IAAIY,oBAAoB;IAExB,IAAIT,OAAO;QACT,MAAMU,cAAc1B,wBAAwBgB;QAC5CS,oBAAoBC,YAAYC,IAAI,CAAC,CAACC,OAASC,OAAOC,IAAI,CAACF,MAAMD,IAAI,CAAC,CAACI,MAAQA,QAAQ;IACzF;IAEA,IAAIjB;IACJ,IAAI,CAACW,mBAAmB;QACtBX,OAAOb,eAAe;YACpBqB,QAAQ,IAAI,CAACF,OAAO,CAACE,MAAM;YAC3BU,QAAQb,iBAAiBc,eAAe;Y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OI;IAC3C,MAAMgB,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"}
1
+ {"version":3,"sources":["../src/findVersions.ts"],"sourcesContent":["import type { PaginateOptions, QueryOptions } from 'mongoose'\nimport type { FindVersions } from 'payload'\n\nimport { buildVersionCollectionFields, flattenWhereToOperators } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { buildSortParam } from './queries/buildSortParam.js'\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getSession } from './utilities/getSession.js'\nimport { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js'\n\nexport const findVersions: FindVersions = async function findVersions(\n this: MongooseAdapter,\n { collection, limit, locale, page, pagination, req = {}, select, skip, sort: sortArg, where },\n) {\n const Model = this.versions[collection]\n const collectionConfig = this.payload.collections[collection].config\n const session = await getSession(this, req)\n const options: QueryOptions = {\n limit,\n session,\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.flattenedFields,\n locale,\n sort: sortArg || '-updatedAt',\n timestamps: true,\n })\n }\n\n const fields = buildVersionCollectionFields(this.payload.config, collectionConfig, true)\n\n const query = await buildQuery({\n adapter: this,\n fields,\n locale,\n where,\n })\n\n // useEstimatedCount is faster, but not accurate, as it ignores any filters. It is thus set to true if there are no filters.\n const useEstimatedCount = hasNearConstraint || !query || Object.keys(query).length === 0\n const paginationOptions: PaginateOptions = {\n lean: true,\n leanWithId: true,\n limit,\n options,\n page,\n pagination,\n projection: buildProjectionFromSelect({\n adapter: this,\n fields,\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 hint: { _id: 1 },\n session,\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","buildQuery","buildSortParam","buildProjectionFromSelect","getSession","sanitizeInternalFields","findVersions","collection","limit","locale","page","pagination","req","select","skip","sort","sortArg","where","Model","versions","collectionConfig","payload","collections","config","session","options","hasNearConstraint","constraints","some","prop","Object","keys","key","fields","flattenedFields","timestamps","query","adapter","useEstimatedCount","length","paginationOptions","lean","leanWithId","projection","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,UAAU,QAAQ,0BAAyB;AACpD,SAASC,cAAc,QAAQ,8BAA6B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O,MAAM,IAAI,EAAE,IAqFlB,CAAA"}
1
+ {"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../src/init.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAA6B,MAAM,SAAS,CAAA;AAgB9D,eAAO,MAAM,IAAI,EAAE,IA6FlB,CAAA"}