@payloadcms/db-mongodb 4.0.0-internal.567a487 → 4.0.0-internal.5a4aa81

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 (75) hide show
  1. package/dist/count.d.ts.map +1 -1
  2. package/dist/count.js +2 -8
  3. package/dist/count.js.map +1 -1
  4. package/dist/countVersions.d.ts.map +1 -1
  5. package/dist/countVersions.js +2 -10
  6. package/dist/countVersions.js.map +1 -1
  7. package/dist/create.d.ts.map +1 -1
  8. package/dist/create.js +2 -1
  9. package/dist/create.js.map +1 -1
  10. package/dist/createGlobalVersion.d.ts.map +1 -1
  11. package/dist/createGlobalVersion.js +1 -23
  12. package/dist/createGlobalVersion.js.map +1 -1
  13. package/dist/createMigration.d.ts.map +1 -1
  14. package/dist/createMigration.js +9 -2
  15. package/dist/createMigration.js.map +1 -1
  16. package/dist/createVersion.d.ts.map +1 -1
  17. package/dist/createVersion.js +4 -17
  18. package/dist/createVersion.js.map +1 -1
  19. package/dist/deleteOne.d.ts.map +1 -1
  20. package/dist/deleteOne.js +1 -18
  21. package/dist/deleteOne.js.map +1 -1
  22. package/dist/find.d.ts.map +1 -1
  23. package/dist/find.js +6 -25
  24. package/dist/find.js.map +1 -1
  25. package/dist/findDistinct.d.ts.map +1 -1
  26. package/dist/findDistinct.js +2 -10
  27. package/dist/findDistinct.js.map +1 -1
  28. package/dist/findGlobal.d.ts.map +1 -1
  29. package/dist/findGlobal.js +4 -26
  30. package/dist/findGlobal.js.map +1 -1
  31. package/dist/findGlobalVersions.d.ts.map +1 -1
  32. package/dist/findGlobalVersions.js +2 -8
  33. package/dist/findGlobalVersions.js.map +1 -1
  34. package/dist/findOne.d.ts.map +1 -1
  35. package/dist/findOne.js +4 -25
  36. package/dist/findOne.js.map +1 -1
  37. package/dist/findVersions.d.ts.map +1 -1
  38. package/dist/findVersions.js +3 -17
  39. package/dist/findVersions.js.map +1 -1
  40. package/dist/index.d.ts.map +1 -1
  41. package/dist/index.js +0 -2
  42. package/dist/index.js.map +1 -1
  43. package/dist/migrateFresh.d.ts +4 -2
  44. package/dist/migrateFresh.d.ts.map +1 -1
  45. package/dist/migrateFresh.js +20 -6
  46. package/dist/migrateFresh.js.map +1 -1
  47. package/dist/predefinedMigrations/migrateRelationshipsV2_V3.d.ts.map +1 -1
  48. package/dist/predefinedMigrations/migrateRelationshipsV2_V3.js +4 -4
  49. package/dist/predefinedMigrations/migrateRelationshipsV2_V3.js.map +1 -1
  50. package/dist/queries/buildSearchParams.d.ts.map +1 -1
  51. package/dist/queries/buildSearchParams.js +139 -6
  52. package/dist/queries/buildSearchParams.js.map +1 -1
  53. package/dist/queries/parseParams.js.map +1 -1
  54. package/dist/queryDrafts.d.ts.map +1 -1
  55. package/dist/queryDrafts.js +5 -17
  56. package/dist/queryDrafts.js.map +1 -1
  57. package/dist/updateGlobal.d.ts.map +1 -1
  58. package/dist/updateGlobal.js +7 -68
  59. package/dist/updateGlobal.js.map +1 -1
  60. package/dist/updateOne.d.ts.map +1 -1
  61. package/dist/updateOne.js +2 -26
  62. package/dist/updateOne.js.map +1 -1
  63. package/dist/utilities/buildJoinAggregation.d.ts +2 -3
  64. package/dist/utilities/buildJoinAggregation.d.ts.map +1 -1
  65. package/dist/utilities/buildJoinAggregation.js +6 -33
  66. package/dist/utilities/buildJoinAggregation.js.map +1 -1
  67. package/dist/utilities/resolveJoins.d.ts +2 -4
  68. package/dist/utilities/resolveJoins.d.ts.map +1 -1
  69. package/dist/utilities/resolveJoins.js +2 -16
  70. package/dist/utilities/resolveJoins.js.map +1 -1
  71. package/package.json +6 -6
  72. package/dist/deleteBranchGlobal.d.ts +0 -10
  73. package/dist/deleteBranchGlobal.d.ts.map +0 -1
  74. package/dist/deleteBranchGlobal.js +0 -22
  75. package/dist/deleteBranchGlobal.js.map +0 -1
@@ -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;AAUpC,eAAO,MAAM,KAAK,EAAE,KA6DnB,CAAA"}
1
+ {"version":3,"file":"count.d.ts","sourceRoot":"","sources":["../src/count.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAUpC,eAAO,MAAM,KAAK,EAAE,KA2DnB,CAAA"}
package/dist/count.js CHANGED
@@ -1,18 +1,12 @@
1
- import { flattenWhereToOperators, resolveBranchQuery } from 'payload';
1
+ import { flattenWhereToOperators } from 'payload';
2
2
  import { buildQuery } from './queries/buildQuery.js';
3
3
  import { getCollection } from './utilities/getEntity.js';
4
4
  import { getSession } from './utilities/getSession.js';
5
- export const count = async function count({ branch, collection: collectionSlug, locale, req, where = {} }) {
5
+ export const count = async function count({ collection: collectionSlug, locale, req, where = {} }) {
6
6
  const { collectionConfig, Model } = getCollection({
7
7
  adapter: this,
8
8
  collectionSlug
9
9
  });
10
- where = await resolveBranchQuery({
11
- branch,
12
- collectionSlug,
13
- req,
14
- where
15
- }) ?? {};
16
10
  let hasNearConstraint = false;
17
11
  if (where) {
18
12
  const constraints = flattenWhereToOperators(where);
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, resolveBranchQuery } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { getCollection } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\n\nexport const count: Count = async function count(\n this: MongooseAdapter,\n { branch, collection: collectionSlug, locale, req, where = {} },\n) {\n const { collectionConfig, Model } = getCollection({ adapter: this, collectionSlug })\n\n where = (await resolveBranchQuery({ branch, collectionSlug, req, where })) ?? {}\n\n let hasNearConstraint = false\n\n if (where) {\n const constraints = flattenWhereToOperators(where)\n hasNearConstraint = constraints.some((prop) => Object.keys(prop).some((key) => key === 'near'))\n }\n\n const query = await buildQuery({\n adapter: this,\n collectionSlug,\n fields: collectionConfig.flattenedFields,\n locale,\n where,\n })\n\n // useEstimatedCount is faster, but not accurate, as it ignores any filters. It is thus set to true if there are no filters.\n const useEstimatedCount = hasNearConstraint || !query || Object.keys(query).length === 0\n\n const options: CountOptions = {\n session: await getSession(this, req),\n }\n\n if (this.collation) {\n const localizationConfig = this.payload.config.localization\n const defaultLocale =\n (typeof localizationConfig === 'object' && localizationConfig?.defaultLocale) || 'en'\n\n options.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 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","resolveBranchQuery","buildQuery","getCollection","getSession","count","branch","collection","collectionSlug","locale","req","where","collectionConfig","Model","adapter","hasNearConstraint","constraints","some","prop","Object","keys","key","query","fields","flattenedFields","useEstimatedCount","length","options","session","collation","localizationConfig","payload","config","localization","defaultLocale","disableIndexHints","hint","_id","result","estimatedDocumentCount","countDocuments","totalDocs"],"mappings":"AAGA,SAASA,uBAAuB,EAAEC,kBAAkB,QAAQ,UAAS;AAIrE,SAASC,UAAU,QAAQ,0BAAyB;AACpD,SAASC,aAAa,QAAQ,2BAA0B;AACxD,SAASC,UAAU,QAAQ,4BAA2B;AAEtD,OAAO,MAAMC,QAAe,eAAeA,MAEzC,EAAEC,MAAM,EAAEC,YAAYC,cAAc,EAAEC,M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;QACrBa,SAAS,MAAMzB,MAAM0B,sBAAsB,CAAC;YAAEX,SAASD,QAAQC,OAAO;QAAC;IACzE,OAAO;QACLU,SAAS,MAAMzB,MAAM2B,cAAc,CAAClB,OAAOK;IAC7C;IAEA,OAAO;QACLc,WAAWH;IACb;AACF,EAAC"}
1
+ {"version":3,"sources":["../src/count.ts"],"sourcesContent":["import type { CountOptions } from 'mongodb'\nimport type { Count } from 'payload'\n\nimport { flattenWhereToOperators } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { getCollection } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\n\nexport const count: Count = async function count(\n this: MongooseAdapter,\n { collection: collectionSlug, locale, req, where = {} },\n) {\n const { collectionConfig, Model } = getCollection({ adapter: this, collectionSlug })\n\n let hasNearConstraint = false\n\n if (where) {\n const constraints = flattenWhereToOperators(where)\n hasNearConstraint = constraints.some((prop) => Object.keys(prop).some((key) => key === 'near'))\n }\n\n const query = await buildQuery({\n adapter: this,\n collectionSlug,\n fields: collectionConfig.flattenedFields,\n locale,\n where,\n })\n\n // useEstimatedCount is faster, but not accurate, as it ignores any filters. It is thus set to true if there are no filters.\n const useEstimatedCount = hasNearConstraint || !query || Object.keys(query).length === 0\n\n const options: CountOptions = {\n session: await getSession(this, req),\n }\n\n if (this.collation) {\n const localizationConfig = this.payload.config.localization\n const defaultLocale =\n (typeof localizationConfig === 'object' && localizationConfig?.defaultLocale) || 'en'\n\n options.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 options.hint = {\n _id: 1,\n }\n }\n\n let result: number\n if (useEstimatedCount) {\n result = await Model.estimatedDocumentCount({ session: options.session })\n } else {\n result = await Model.countDocuments(query, options)\n }\n\n return {\n totalDocs: result,\n }\n}\n"],"names":["flattenWhereToOperators","buildQuery","getCollection","getSession","count","collection","collectionSlug","locale","req","where","collectionConfig","Model","adapter","hasNearConstraint","constraints","some","prop","Object","keys","key","query","fields","flattenedFields","useEstimatedCount","length","options","session","collation","localizationConfig","payload","config","localization","defaultLocale","disableIndexHints","hint","_id","result","estimatedDocumentCount","countDocuments","totalDocs"],"mappings":"AAGA,SAASA,uBAAuB,QAAQ,UAAS;AAIjD,SAASC,UAAU,QAAQ,0BAAyB;AACpD,SAASC,aAAa,QAAQ,2BAA0B;AACxD,SAASC,UAAU,QAAQ,4BAA2B;AAEtD,OAAO,MAAMC,QAAe,eAAeA,MAEzC,EAAEC,YAAYC,cAAc,EAAEC,MAAM,EAAEC,GAAG,EAAEC,QAAQ,CAAC,CAAC,EAAE;IAEvD,MAAM,EAAEC,gBAAgB,EAAEC,KAAK,EAAE,GAAGT,cAAc;QAAEU,SAAS,IAAI;QAAEN;IAAe;IAElF,IAAIO,oBAAoB;IAExB,IAAIJ,OAAO;QACT,MAAMK,cAAcd,wBAAwBS;QAC5CI,oBAAoBC,YAAYC,IAAI,CAAC,CAACC,OAASC,OAAOC,IAAI,CAACF,MAAMD,IAAI,CAAC,CAACI,MAAQA,QAAQ;IACzF;IAEA,MAAMC,QAAQ,MAAMnB,WAAW;QAC7BW,SAAS,IAAI;QACbN;QACAe,QAAQX,iBAAiBY,eAAe;QACxCf;QACAE;IACF;IAEA,4HAA4H;IAC5H,MAAMc,oBAAoBV,qBAAqB,CAACO,SAASH,OAAOC,IAAI,CAACE,OAAOI,MAAM,KAAK;IAEvF,MAAMC,UAAwB;QAC5BC,SAAS,MAAMvB,WAAW,IAAI,EAAEK;IAClC;IAEA,IAAI,IAAI,CAACmB,SAAS,EAAE;QAClB,MAAMC,qBAAqB,IAAI,CAACC,OAAO,CAACC,MAAM,CAACC,YAAY;QAC3D,MAAMC,gBACJ,AAAC,OAAOJ,uBAAuB,YAAYA,oBAAoBI,iBAAkB;QAEnFP,QAAQE,SAAS,GAAG;YAClBpB,QAAQA,UAAUA,WAAW,SAASA,WAAW,MAAMA,SAASyB;YAChE,GAAG,IAAI,CAACL,SAAS;QACnB;IACF;IAEA,IAAI,CAACJ,qBAAqBN,OAAOC,IAAI,CAACE,OAAOI,MAAM,KAAK,KAAK,IAAI,CAACS,iBAAiB,KAAK,MAAM;QAC5F,mHAAmH;QACnH,qHAAqH;QACrH,mHAAmH;QACnH,4BAA4B;QAC5BR,QAAQS,IAAI,GAAG;YACbC,KAAK;QACP;IACF;IAEA,IAAIC;IACJ,IAAIb,mBAAmB;QACrBa,SAAS,MAAMzB,MAAM0B,sBAAsB,CAAC;YAAEX,SAASD,QAAQC,OAAO;QAAC;IACzE,OAAO;QACLU,SAAS,MAAMzB,MAAM2B,cAAc,CAAClB,OAAOK;IAC7C;IAEA,OAAO;QACLc,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;AAc5C,eAAO,MAAM,aAAa,EAAE,aAkE3B,CAAA"}
1
+ {"version":3,"file":"countVersions.d.ts","sourceRoot":"","sources":["../src/countVersions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAU5C,eAAO,MAAM,aAAa,EAAE,aA8D3B,CAAA"}
@@ -1,21 +1,13 @@
1
- import { buildVersionCollectionFields, flattenWhereToOperators, resolveBranchVersionHistoryQuery } from 'payload';
1
+ import { buildVersionCollectionFields, flattenWhereToOperators } from 'payload';
2
2
  import { buildQuery } from './queries/buildQuery.js';
3
3
  import { getCollection } from './utilities/getEntity.js';
4
4
  import { getSession } from './utilities/getSession.js';
5
- export const countVersions = async function countVersions({ branch, collection: collectionSlug, locale, req, where = {} }) {
5
+ export const countVersions = async function countVersions({ collection: collectionSlug, locale, req, where = {} }) {
6
6
  const { collectionConfig, Model } = getCollection({
7
7
  adapter: this,
8
8
  collectionSlug,
9
9
  versions: true
10
10
  });
11
- // Shares the list's predicate so the count in the Versions tab can never
12
- // disagree with the rows the Versions view actually renders.
13
- where = resolveBranchVersionHistoryQuery({
14
- branch,
15
- collectionSlug,
16
- req,
17
- where
18
- }) ?? {};
19
11
  let hasNearConstraint = false;
20
12
  if (where) {
21
13
  const constraints = flattenWhereToOperators(where);
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/countVersions.ts"],"sourcesContent":["import type { CountOptions } from 'mongodb'\nimport type { CountVersions } from 'payload'\n\nimport {\n buildVersionCollectionFields,\n flattenWhereToOperators,\n resolveBranchVersionHistoryQuery,\n} from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { getCollection } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\n\nexport const countVersions: CountVersions = async function countVersions(\n this: MongooseAdapter,\n { branch, collection: collectionSlug, locale, req, where = {} },\n) {\n const { collectionConfig, Model } = getCollection({\n adapter: this,\n collectionSlug,\n versions: true,\n })\n\n // Shares the list's predicate so the count in the Versions tab can never\n // disagree with the rows the Versions view actually renders.\n where = resolveBranchVersionHistoryQuery({ branch, collectionSlug, req, where }) ?? {}\n\n let hasNearConstraint = false\n\n if (where) {\n const constraints = flattenWhereToOperators(where)\n hasNearConstraint = constraints.some((prop) => Object.keys(prop).some((key) => key === 'near'))\n }\n\n const query = await buildQuery({\n adapter: this,\n fields: buildVersionCollectionFields(this.payload.config, collectionConfig, true),\n locale,\n where,\n })\n\n // useEstimatedCount is faster, but not accurate, as it ignores any filters. It is thus set to true if there are no filters.\n const useEstimatedCount = hasNearConstraint || !query || Object.keys(query).length === 0\n\n const options: CountOptions = {\n session: await getSession(this, req),\n }\n\n if (this.collation) {\n const localizationConfig = this.payload.config.localization\n const defaultLocale =\n (typeof localizationConfig === 'object' && localizationConfig?.defaultLocale) || 'en'\n\n options.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 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","resolveBranchVersionHistoryQuery","buildQuery","getCollection","getSession","countVersions","branch","collection","collectionSlug","locale","req","where","collectionConfig","Model","adapter","versions","hasNearConstraint","constraints","some","prop","Object","keys","key","query","fields","payload","config","useEstimatedCount","length","options","session","collation","localizationConfig","localization","defaultLocale","disableIndexHints","hint","_id","result","estimatedDocumentCount","countDocuments","totalDocs"],"mappings":"AAGA,SACEA,4BAA4B,EAC5BC,uBAAuB,EACvBC,gCAAgC,QAC3B,UAAS;AAIhB,SAASC,UAAU,QAAQ,0BAAyB;AACpD,SAASC,aAAa,QAAQ,2BAA0B;AACxD,SAASC,UAAU,QAAQ,4BAA2B;AAEtD,OAAO,MAAMC,gBAA+B,eAAeA,cAEzD,EAAEC,MAAM,EAAEC,YAAYC,cAAc,EAAEC,MAAM,EAAEC,GAAG,EAAEC,QAAQ,CAAC,CAAC,EAAE;IAE/D,MAAM,EAAEC,gBAAgB,EAAEC,KAAK,EAAE,GAAGV,cAAc;QAChDW,SAAS,IAAI;QACbN;QACAO,UAAU;IACZ;IAEA,yEAAyE;IACzE,6DAA6D;IAC7DJ,QAAQV,iCA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;IAC7C;IAEA,OAAO;QACLY,WAAWH;IACb;AACF,EAAC"}
1
+ {"version":3,"sources":["../src/countVersions.ts"],"sourcesContent":["import type { CountOptions } from 'mongodb'\nimport type { CountVersions } from 'payload'\n\nimport { buildVersionCollectionFields, flattenWhereToOperators } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { getCollection } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\n\nexport const countVersions: CountVersions = async function countVersions(\n this: MongooseAdapter,\n { collection: collectionSlug, locale, req, where = {} },\n) {\n const { collectionConfig, Model } = getCollection({\n adapter: this,\n collectionSlug,\n versions: true,\n })\n\n let hasNearConstraint = false\n\n if (where) {\n const constraints = flattenWhereToOperators(where)\n hasNearConstraint = constraints.some((prop) => Object.keys(prop).some((key) => key === 'near'))\n }\n\n const query = await buildQuery({\n adapter: this,\n fields: buildVersionCollectionFields(this.payload.config, collectionConfig, true),\n locale,\n where,\n })\n\n // useEstimatedCount is faster, but not accurate, as it ignores any filters. It is thus set to true if there are no filters.\n const useEstimatedCount = hasNearConstraint || !query || Object.keys(query).length === 0\n\n const options: CountOptions = {\n session: await getSession(this, req),\n }\n\n if (this.collation) {\n const localizationConfig = this.payload.config.localization\n const defaultLocale =\n (typeof localizationConfig === 'object' && localizationConfig?.defaultLocale) || 'en'\n\n options.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 options.hint = {\n _id: 1,\n }\n }\n\n let result: number\n if (useEstimatedCount) {\n result = await Model.estimatedDocumentCount({ session: options.session })\n } else {\n result = await Model.countDocuments(query, options)\n }\n\n return {\n totalDocs: result,\n }\n}\n"],"names":["buildVersionCollectionFields","flattenWhereToOperators","buildQuery","getCollection","getSession","countVersions","collection","collectionSlug","locale","req","where","collectionConfig","Model","adapter","versions","hasNearConstraint","constraints","some","prop","Object","keys","key","query","fields","payload","config","useEstimatedCount","length","options","session","collation","localizationConfig","localization","defaultLocale","disableIndexHints","hint","_id","result","estimatedDocumentCount","countDocuments","totalDocs"],"mappings":"AAGA,SAASA,4BAA4B,EAAEC,uBAAuB,QAAQ,UAAS;AAI/E,SAASC,UAAU,QAAQ,0BAAyB;AACpD,SAASC,aAAa,QAAQ,2BAA0B;AACxD,SAASC,UAAU,QAAQ,4BAA2B;AAEtD,OAAO,MAAMC,gBAA+B,eAAeA,cAEzD,EAAEC,YAAYC,cAAc,EAAEC,MAAM,EAAEC,GAAG,EAAEC,QAAQ,CAAC,CAAC,EAAE;IAEvD,MAAM,EAAEC,gBAAgB,EAAEC,KAAK,EAAE,GAAGT,cAAc;QAChDU,SAAS,IAAI;QACbN;QACAO,UAAU;IACZ;IAEA,IAAIC,oBAAoB;IAExB,IAAIL,OAAO;QACT,MAAMM,cAAcf,wBAAwBS;QAC5CK,oBAAoBC,YAAYC,IAAI,CAAC,CAACC,OAASC,OAAOC,IAAI,CAACF,MAAMD,IAAI,CAAC,CAACI,MAAQA,QAAQ;IACzF;IAEA,MAAMC,QAAQ,MAAMpB,WAAW;QAC7BW,SAAS,IAAI;QACbU,QAAQvB,6BAA6B,IAAI,CAACwB,OAAO,CAACC,MAAM,EAAEd,kBAAkB;QAC5EH;QACAE;IACF;IAEA,4HAA4H;IAC5H,MAAMgB,oBAAoBX,qBAAqB,CAACO,SAASH,OAAOC,IAAI,CAACE,OAAOK,MAAM,KAAK;IAEvF,MAAMC,UAAwB;QAC5BC,SAAS,MAAMzB,WAAW,IAAI,EAAEK;IAClC;IAEA,IAAI,IAAI,CAACqB,SAAS,EAAE;QAClB,MAAMC,qBAAqB,IAAI,CAACP,OAAO,CAACC,MAAM,CAACO,YAAY;QAC3D,MAAMC,gBACJ,AAAC,OAAOF,uBAAuB,YAAYA,oBAAoBE,iBAAkB;QAEnFL,QAAQE,SAAS,GAAG;YAClBtB,QAAQA,UAAUA,WAAW,SAASA,WAAW,MAAMA,SAASyB;YAChE,GAAG,IAAI,CAACH,SAAS;QACnB;IACF;IAEA,IAAI,CAACJ,qBAAqBP,OAAOC,IAAI,CAACE,OAAOK,MAAM,KAAK,KAAK,IAAI,CAACO,iBAAiB,KAAK,MAAM;QAC5F,mHAAmH;QACnH,qHAAqH;QACrH,mHAAmH;QACnH,4BAA4B;QAC5BN,QAAQO,IAAI,GAAG;YACbC,KAAK;QACP;IACF;IAEA,IAAIC;IACJ,IAAIX,mBAAmB;QACrBW,SAAS,MAAMzB,MAAM0B,sBAAsB,CAAC;YAAET,SAASD,QAAQC,OAAO;QAAC;IACzE,OAAO;QACLQ,SAAS,MAAMzB,MAAM2B,cAAc,CAACjB,OAAOM;IAC7C;IAEA,OAAO;QACLY,WAAWH;IACb;AACF,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../src/create.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAWrC,eAAO,MAAM,MAAM,EAAE,MA+DpB,CAAA"}
1
+ {"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../src/create.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAWrC,eAAO,MAAM,MAAM,EAAE,MAgEpB,CAAA"}
package/dist/create.js CHANGED
@@ -21,7 +21,8 @@ export const create = async function create({ collection: collectionSlug, custom
21
21
  if (customIDType) {
22
22
  data._id = data.id;
23
23
  } else if (customID) {
24
- if (Types.ObjectId.isValid(customID)) {
24
+ // Mongoose 9 no longer treats numbers as valid ObjectIDs, so only strings are worth casting
25
+ if (typeof customID === 'string' && Types.ObjectId.isValid(customID)) {
25
26
  data._id = new Types.ObjectId(customID);
26
27
  } else {
27
28
  data._id = customID;
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/create.ts"],"sourcesContent":["import type { Create } from 'payload'\n\nimport { type CreateOptions, Types } from 'mongoose'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { getCollection } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\nimport { handleError } from './utilities/handleError.js'\nimport { transform } from './utilities/transform.js'\n\nexport const create: Create = async function create(\n this: MongooseAdapter,\n { collection: collectionSlug, customID, data, req, returning },\n) {\n const { collectionConfig, customIDType, Model } = getCollection({ adapter: this, collectionSlug })\n\n let doc\n\n if (!data.createdAt) {\n data.createdAt = new Date().toISOString()\n }\n\n transform({\n adapter: this,\n data,\n fields: collectionConfig.fields,\n operation: 'write',\n })\n\n if (customIDType) {\n data._id = data.id\n } else if (customID) {\n if (Types.ObjectId.isValid(customID)) {\n data._id = new Types.ObjectId(customID)\n } else {\n data._id = customID\n }\n } else if (this.allowIDOnCreate && data.id) {\n try {\n data._id = new Types.ObjectId(data.id as string)\n } catch (error) {\n this.payload.logger.error(\n `It appears you passed ID to create operation data but it cannot be sanitized to ObjectID, value - ${JSON.stringify(data.id)}`,\n )\n throw error\n }\n }\n\n const options: CreateOptions = {\n session: await getSession(this, req),\n // Timestamps are manually added by the write transform\n timestamps: false,\n }\n\n try {\n ;[doc] = await Model.create([data], options)\n } catch (error) {\n handleError({ collection: collectionSlug, error, req })\n }\n if (returning === false) {\n return null\n }\n\n doc = doc.toObject()\n\n transform({\n adapter: this,\n data: doc,\n fields: collectionConfig.fields,\n operation: 'read',\n })\n\n return doc\n}\n"],"names":["Types","getCollection","getSession","handleError","transform","create","collection","collectionSlug","customID","data","req","returning","collectionConfig","customIDType","Model","adapter","doc","createdAt","Date","toISOString","fields","operation","_id","id","ObjectId","isValid","allowIDOnCreate","error","payload","logger","JSON","stringify","options","session","timestamps","toObject"],"mappings":"AAEA,SAA6BA,KAAK,QAAQ,WAAU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IAAI,GAAG,MAAMF,MAAMT,MAAM,CAAC;YAACI;SAAK,EAAEuB;IACtC,EAAE,OAAOL,OAAO;QACdxB,YAAY;YAAEG,YAAYC;YAAgBoB;YAAOjB;QAAI;IACvD;IACA,IAAIC,cAAc,OAAO;QACvB,OAAO;IACT;IAEAK,MAAMA,IAAImB,QAAQ;IAElB/B,UAAU;QACRW,SAAS,IAAI;QACbN,MAAMO;QACNI,QAAQR,iBAAiBQ,MAAM;QAC/BC,WAAW;IACb;IAEA,OAAOL;AACT,EAAC"}
1
+ {"version":3,"sources":["../src/create.ts"],"sourcesContent":["import type { Create } from 'payload'\n\nimport { type CreateOptions, Types } from 'mongoose'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { getCollection } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\nimport { handleError } from './utilities/handleError.js'\nimport { transform } from './utilities/transform.js'\n\nexport const create: Create = async function create(\n this: MongooseAdapter,\n { collection: collectionSlug, customID, data, req, returning },\n) {\n const { collectionConfig, customIDType, Model } = getCollection({ adapter: this, collectionSlug })\n\n let doc\n\n if (!data.createdAt) {\n data.createdAt = new Date().toISOString()\n }\n\n transform({\n adapter: this,\n data,\n fields: collectionConfig.fields,\n operation: 'write',\n })\n\n if (customIDType) {\n data._id = data.id\n } else if (customID) {\n // Mongoose 9 no longer treats numbers as valid ObjectIDs, so only strings are worth casting\n if (typeof customID === 'string' && Types.ObjectId.isValid(customID)) {\n data._id = new Types.ObjectId(customID)\n } else {\n data._id = customID\n }\n } else if (this.allowIDOnCreate && data.id) {\n try {\n data._id = new Types.ObjectId(data.id as string)\n } catch (error) {\n this.payload.logger.error(\n `It appears you passed ID to create operation data but it cannot be sanitized to ObjectID, value - ${JSON.stringify(data.id)}`,\n )\n throw error\n }\n }\n\n const options: CreateOptions = {\n session: await getSession(this, req),\n // Timestamps are manually added by the write transform\n timestamps: false,\n }\n\n try {\n ;[doc] = await Model.create([data], options)\n } catch (error) {\n handleError({ collection: collectionSlug, error, req })\n }\n if (returning === false) {\n return null\n }\n\n doc = doc.toObject()\n\n transform({\n adapter: this,\n data: doc,\n fields: collectionConfig.fields,\n operation: 'read',\n })\n\n return doc\n}\n"],"names":["Types","getCollection","getSession","handleError","transform","create","collection","collectionSlug","customID","data","req","returning","collectionConfig","customIDType","Model","adapter","doc","createdAt","Date","toISOString","fields","operation","_id","id","ObjectId","isValid","allowIDOnCreate","error","payload","logger","JSON","stringify","options","session","timestamps","toObject"],"mappings":"AAEA,SAA6BA,KAAK,QAAQ,WAAU;AAIpD,SAASC,aAAa,QAAQ,2BAA0B;AACxD,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,WAAW,QAAQ,6BAA4B;AACxD,SAASC,SAAS,QAAQ,2BAA0B;AAEpD,OAAO,MAAMC,SAAiB,eAAeA,OAE3C,EAAEC,YAAYC,cAAc,EAAEC,QAAQ,EAAEC,IAAI,EAAEC,GAAG,EAAEC,SAAS,EAAE;IAE9D,MAAM,EAAEC,gBAAgB,EAAEC,YAAY,EAAEC,KAAK,EAAE,GAAGb,cAAc;QAAEc,SAAS,IAAI;QAAER;IAAe;IAEhG,IAAIS;IAEJ,IAAI,CAACP,KAAKQ,SAAS,EAAE;QACnBR,KAAKQ,SAAS,GAAG,IAAIC,OAAOC,WAAW;IACzC;IAEAf,UAAU;QACRW,SAAS,IAAI;QACbN;QACAW,QAAQR,iBAAiBQ,MAAM;QAC/BC,WAAW;IACb;IAEA,IAAIR,cAAc;QAChBJ,KAAKa,GAAG,GAAGb,KAAKc,EAAE;IACpB,OAAO,IAAIf,UAAU;QACnB,4FAA4F;QAC5F,IAAI,OAAOA,aAAa,YAAYR,MAAMwB,QAAQ,CAACC,OAAO,CAACjB,WAAW;YACpEC,KAAKa,GAAG,GAAG,IAAItB,MAAMwB,QAAQ,CAAChB;QAChC,OAAO;YACLC,KAAKa,GAAG,GAAGd;QACb;IACF,OAAO,IAAI,IAAI,CAACkB,eAAe,IAAIjB,KAAKc,EAAE,EAAE;QAC1C,IAAI;YACFd,KAAKa,GAAG,GAAG,IAAItB,MAAMwB,QAAQ,CAACf,KAAKc,EAAE;QACvC,EAAE,OAAOI,OAAO;YACd,IAAI,CAACC,OAAO,CAACC,MAAM,CAACF,KAAK,CACvB,CAAC,kGAAkG,EAAEG,KAAKC,SAAS,CAACtB,KAAKc,EAAE,GAAG;YAEhI,MAAMI;QACR;IACF;IAEA,MAAMK,UAAyB;QAC7BC,SAAS,MAAM/B,WAAW,IAAI,EAAEQ;QAChC,uDAAuD;QACvDwB,YAAY;IACd;IAEA,IAAI;;QACD,CAAClB,IAAI,GAAG,MAAMF,MAAMT,MAAM,CAAC;YAACI;SAAK,EAAEuB;IACtC,EAAE,OAAOL,OAAO;QACdxB,YAAY;YAAEG,YAAYC;YAAgBoB;YAAOjB;QAAI;IACvD;IACA,IAAIC,cAAc,OAAO;QACvB,OAAO;IACT;IAEAK,MAAMA,IAAImB,QAAQ;IAElB/B,UAAU;QACRW,SAAS,IAAI;QACbN,MAAMO;QACNI,QAAQR,iBAAiBQ,MAAM;QAC/BC,WAAW;IACb;IAEA,OAAOL;AACT,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"createGlobalVersion.d.ts","sourceRoot":"","sources":["../src/createGlobalVersion.ts"],"names":[],"mappings":"AACA,OAAO,EAA4B,KAAK,mBAAmB,EAAE,MAAM,SAAS,CAAA;AAQ5E,eAAO,MAAM,mBAAmB,EAAE,mBA6FjC,CAAA"}
1
+ {"version":3,"file":"createGlobalVersion.d.ts","sourceRoot":"","sources":["../src/createGlobalVersion.ts"],"names":[],"mappings":"AAAA,OAAO,EAA4B,KAAK,mBAAmB,EAAE,MAAM,SAAS,CAAA;AAQ5E,eAAO,MAAM,mBAAmB,EAAE,mBA+EjC,CAAA"}
@@ -1,4 +1,3 @@
1
- import { MAIN_BRANCH, resolveBranch } from 'payload';
2
1
  import { buildVersionGlobalFields } from 'payload';
3
2
  import { getGlobal } from './utilities/getEntity.js';
4
3
  import { getSession } from './utilities/getSession.js';
@@ -9,9 +8,7 @@ export const createGlobalVersion = async function createGlobalVersion({ autosave
9
8
  globalSlug,
10
9
  versions: true
11
10
  });
12
- const versionBranch = req?.payload?.config?.branching?.branchableGlobals?.has(globalSlug) ? resolveBranch(req) : MAIN_BRANCH;
13
11
  const data = {
14
- _branch: versionBranch,
15
12
  autosave,
16
13
  createdAt,
17
14
  latest: true,
@@ -37,10 +34,7 @@ export const createGlobalVersion = async function createGlobalVersion({ autosave
37
34
  };
38
35
  let [doc] = await Model.create([
39
36
  data
40
- ], options, req);
41
- // Scoped by `_branch`. Unlike collection versions, global versions have no
42
- // `parent` to separate streams by — every version of a global shares one — so
43
- // without this an unscoped clear would wipe main's latest flag from a branch.
37
+ ], options);
44
38
  await Model.updateMany({
45
39
  $and: [
46
40
  {
@@ -52,22 +46,6 @@ export const createGlobalVersion = async function createGlobalVersion({ autosave
52
46
  latest: {
53
47
  $eq: true
54
48
  }
55
- },
56
- {
57
- $or: [
58
- {
59
- _branch: {
60
- $eq: versionBranch
61
- }
62
- },
63
- ...versionBranch === MAIN_BRANCH ? [
64
- {
65
- _branch: {
66
- $exists: false
67
- }
68
- }
69
- ] : []
70
- ]
71
49
  }
72
50
  ]
73
51
  }, {
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/createGlobalVersion.ts"],"sourcesContent":["import { MAIN_BRANCH, resolveBranch } from 'payload'\nimport { buildVersionGlobalFields, type CreateGlobalVersion } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { getGlobal } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\nimport { transform } from './utilities/transform.js'\n\nexport const createGlobalVersion: CreateGlobalVersion = async function createGlobalVersion(\n this: MongooseAdapter,\n {\n autosave,\n createdAt,\n globalSlug,\n publishedLocale,\n req,\n returning,\n snapshot,\n updatedAt,\n versionData,\n },\n) {\n const { globalConfig, Model } = getGlobal({ adapter: this, globalSlug, versions: true })\n\n const versionBranch = req?.payload?.config?.branching?.branchableGlobals?.has(globalSlug)\n ? resolveBranch(req as never)\n : MAIN_BRANCH\n\n const data = {\n _branch: versionBranch,\n autosave,\n createdAt,\n latest: true,\n publishedLocale,\n snapshot,\n updatedAt,\n version: versionData,\n }\n if (!data.createdAt) {\n data.createdAt = new Date().toISOString()\n }\n\n const fields = buildVersionGlobalFields(this.payload.config, globalConfig)\n\n transform({\n adapter: this,\n data,\n fields,\n operation: 'write',\n })\n\n const options = {\n session: await getSession(this, req),\n // Timestamps are manually added by the write transform\n timestamps: false,\n }\n\n let [doc] = await Model.create([data], options, req)\n\n // Scoped by `_branch`. Unlike collection versions, global versions have no\n // `parent` to separate streams by — every version of a global shares one — so\n // without this an unscoped clear would wipe main's latest flag from a branch.\n await Model.updateMany(\n {\n $and: [\n {\n _id: {\n $ne: doc._id,\n },\n },\n {\n latest: {\n $eq: true,\n },\n },\n {\n $or: [\n { _branch: { $eq: versionBranch } },\n ...(versionBranch === MAIN_BRANCH ? [{ _branch: { $exists: false } }] : []),\n ],\n },\n ],\n },\n { $unset: { latest: 1 } },\n options,\n )\n\n if (returning === false) {\n return null\n }\n\n doc = doc.toObject()\n\n transform({\n adapter: this,\n data: doc,\n fields,\n operation: 'read',\n })\n\n return doc\n}\n"],"names":["MAIN_BRANCH","resolveBranch","buildVersionGlobalFields","getGlobal","getSession","transform","createGlobalVersion","autosave","createdAt","globalSlug","publishedLocale","req","returning","snapshot","updatedAt","versionData","globalConfig","Model","adapter","versions","versionBranch","payload","config","branching","branchableGlobals","has","data","_branch","latest","version","Date","toISOString","fields","operation","options","session","timestamps","doc","create","updateMany","$and","_id","$ne","$eq","$or","$exists","$unset","toObject"],"mappings":"AAAA,SAASA,WAAW,EAAEC,aAAa,QAAQ,UAAS;AACpD,SAASC,wBAAwB,QAAkC,UAAS;AAI5E,SAASC,SAAS,QAAQ,2BAA0B;AACpD,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,SAAS,QAAQ,2BAA0B;AAEpD,OAAO,MAAMC,sBAA2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;YAAElB,QAAQ;QAAE;IAAE,GACxBM;IAGF,IAAItB,cAAc,OAAO;QACvB,OAAO;IACT;IAEAyB,MAAMA,IAAIU,QAAQ;IAElB1C,UAAU;QACRa,SAAS,IAAI;QACbQ,MAAMW;QACNL;QACAC,WAAW;IACb;IAEA,OAAOI;AACT,EAAC"}
1
+ {"version":3,"sources":["../src/createGlobalVersion.ts"],"sourcesContent":["import { buildVersionGlobalFields, type CreateGlobalVersion } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { getGlobal } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\nimport { transform } from './utilities/transform.js'\n\nexport const createGlobalVersion: CreateGlobalVersion = async function createGlobalVersion(\n this: MongooseAdapter,\n {\n autosave,\n createdAt,\n globalSlug,\n publishedLocale,\n req,\n returning,\n snapshot,\n updatedAt,\n versionData,\n },\n) {\n const { globalConfig, Model } = getGlobal({ adapter: this, globalSlug, versions: true })\n\n const data = {\n autosave,\n createdAt,\n latest: true,\n publishedLocale,\n snapshot,\n updatedAt,\n version: versionData,\n }\n if (!data.createdAt) {\n data.createdAt = new Date().toISOString()\n }\n\n const fields = buildVersionGlobalFields(this.payload.config, globalConfig)\n\n transform({\n adapter: this,\n data,\n fields,\n operation: 'write',\n })\n\n const options = {\n session: await getSession(this, req),\n // Timestamps are manually added by the write transform\n timestamps: false,\n }\n\n let [doc] = await Model.create([data], options)\n\n await Model.updateMany(\n {\n $and: [\n {\n _id: {\n $ne: doc._id,\n },\n },\n {\n latest: {\n $eq: true,\n },\n },\n ],\n },\n { $unset: { latest: 1 } },\n options,\n )\n\n if (returning === false) {\n return null\n }\n\n doc = doc.toObject()\n\n transform({\n adapter: this,\n data: doc,\n fields,\n operation: 'read',\n })\n\n return doc\n}\n"],"names":["buildVersionGlobalFields","getGlobal","getSession","transform","createGlobalVersion","autosave","createdAt","globalSlug","publishedLocale","req","returning","snapshot","updatedAt","versionData","globalConfig","Model","adapter","versions","data","latest","version","Date","toISOString","fields","payload","config","operation","options","session","timestamps","doc","create","updateMany","$and","_id","$ne","$eq","$unset","toObject"],"mappings":"AAAA,SAASA,wBAAwB,QAAkC,UAAS;AAI5E,SAASC,SAAS,QAAQ,2BAA0B;AACpD,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,SAAS,QAAQ,2BAA0B;AAEpD,OAAO,MAAMC,sBAA2C,eAAeA,oBAErE,EACEC,QAAQ,EACRC,SAAS,EACTC,UAAU,EACVC,eAAe,EACfC,GAAG,EACHC,SAAS,EACTC,QAAQ,EACRC,SAAS,EACTC,WAAW,EACZ;IAED,MAAM,EAAEC,YAAY,EAAEC,KAAK,EAAE,GAAGd,UAAU;QAAEe,SAAS,IAAI;QAAET;QAAYU,UAAU;IAAK;IAEtF,MAAMC,OAAO;QACXb;QACAC;QACAa,QAAQ;QACRX;QACAG;QACAC;QACAQ,SAASP;IACX;IACA,IAAI,CAACK,KAAKZ,SAAS,EAAE;QACnBY,KAAKZ,SAAS,GAAG,IAAIe,OAAOC,WAAW;IACzC;IAEA,MAAMC,SAASvB,yBAAyB,IAAI,CAACwB,OAAO,CAACC,MAAM,EAAEX;IAE7DX,UAAU;QACRa,SAAS,IAAI;QACbE;QACAK;QACAG,WAAW;IACb;IAEA,MAAMC,UAAU;QACdC,SAAS,MAAM1B,WAAW,IAAI,EAAEO;QAChC,uDAAuD;QACvDoB,YAAY;IACd;IAEA,IAAI,CAACC,IAAI,GAAG,MAAMf,MAAMgB,MAAM,CAAC;QAACb;KAAK,EAAES;IAEvC,MAAMZ,MAAMiB,UAAU,CACpB;QACEC,MAAM;YACJ;gBACEC,KAAK;oBACHC,KAAKL,IAAII,GAAG;gBACd;YACF;YACA;gBACEf,QAAQ;oBACNiB,KAAK;gBACP;YACF;SACD;IACH,GACA;QAAEC,QAAQ;YAAElB,QAAQ;QAAE;IAAE,GACxBQ;IAGF,IAAIjB,cAAc,OAAO;QACvB,OAAO;IACT;IAEAoB,MAAMA,IAAIQ,QAAQ;IAElBnC,UAAU;QACRa,SAAS,IAAI;QACbE,MAAMY;QACNP;QACAG,WAAW;IACb;IAEA,OAAOI;AACT,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"createMigration.d.ts","sourceRoot":"","sources":["../src/createMigration.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAyB,MAAM,SAAS,CAAA;AAqBrE,eAAO,MAAM,eAAe,EAAE,eAwC7B,CAAA"}
1
+ {"version":3,"file":"createMigration.d.ts","sourceRoot":"","sources":["../src/createMigration.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAyB,MAAM,SAAS,CAAA;AAqBrE,eAAO,MAAM,eAAe,EAAE,eA4C7B,CAAA"}
@@ -36,15 +36,22 @@ export const createMigration = async function createMigration({ file, migrationN
36
36
  const formattedName = migrationName?.replace(/\W/g, '_');
37
37
  const fileName = migrationName ? `${timestamp}_${formattedName}.ts` : `${timestamp}_migration.ts`;
38
38
  const filePath = `${dir}/${fileName}`;
39
- if (!skipEmpty) {
40
- fs.writeFileSync(filePath, migrationFileContent);
39
+ if (skipEmpty) {
40
+ return {
41
+ created: false
42
+ };
41
43
  }
44
+ fs.writeFileSync(filePath, migrationFileContent);
42
45
  writeMigrationIndex({
43
46
  migrationsDir: payload.db.migrationDir
44
47
  });
45
48
  payload.logger.info({
46
49
  msg: `Migration created at ${filePath}`
47
50
  });
51
+ return {
52
+ created: true,
53
+ path: filePath
54
+ };
48
55
  };
49
56
 
50
57
  //# sourceMappingURL=createMigration.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/createMigration.ts"],"sourcesContent":["import type { CreateMigration, MigrationTemplateArgs } from 'payload'\n\nimport fs from 'fs'\nimport path from 'path'\nimport { getPredefinedMigration, writeMigrationIndex } from 'payload'\nimport { fileURLToPath } from 'url'\n\nconst migrationTemplate = ({ downSQL, imports, upSQL }: MigrationTemplateArgs): string => `import {\n MigrateDownArgs,\n MigrateUpArgs,\n} from '@payloadcms/db-mongodb'\n${imports ?? ''}\nexport async function up({ payload, req, session }: MigrateUpArgs): Promise<void> {\n${upSQL ?? ` // Migration code`}\n}\n\nexport async function down({ payload, req, session }: MigrateDownArgs): Promise<void> {\n${downSQL ?? ` // Migration code`}\n}\n`\n\nexport const createMigration: CreateMigration = async function createMigration({\n file,\n migrationName,\n payload,\n skipEmpty,\n}) {\n const filename = fileURLToPath(import.meta.url)\n const dirname = path.dirname(filename)\n\n const dir = payload.db.migrationDir\n if (!fs.existsSync(dir)) {\n fs.mkdirSync(dir)\n }\n const predefinedMigration = await getPredefinedMigration({\n dirname,\n file,\n migrationName,\n payload,\n })\n\n const migrationFileContent = migrationTemplate(predefinedMigration)\n\n const [yyymmdd, hhmmss] = new Date().toISOString().split('T')\n\n const formattedDate = yyymmdd!.replace(/\\D/g, '')\n const formattedTime = hhmmss!.split('.')[0]!.replace(/\\D/g, '')\n\n const timestamp = `${formattedDate}_${formattedTime}`\n\n const formattedName = migrationName?.replace(/\\W/g, '_')\n const fileName = migrationName ? `${timestamp}_${formattedName}.ts` : `${timestamp}_migration.ts`\n const filePath = `${dir}/${fileName}`\n\n if (!skipEmpty) {\n fs.writeFileSync(filePath, migrationFileContent)\n }\n\n writeMigrationIndex({ migrationsDir: payload.db.migrationDir })\n\n payload.logger.info({ msg: `Migration created at ${filePath}` })\n}\n"],"names":["fs","path","getPredefinedMigration","writeMigrationIndex","fileURLToPath","migrationTemplate","downSQL","imports","upSQL","createMigration","file","migrationName","payload","skipEmpty","filename","url","dirname","dir","db","migrationDir","existsSync","mkdirSync","predefinedMigration","migrationFileContent","yyymmdd","hhmmss","Date","toISOString","split","formattedDate","replace","formattedTime","timestamp","formattedName","fileName","filePath","writeFileSync","migrationsDir","logger","info","msg"],"mappings":"AAEA,OAAOA,QAAQ,KAAI;AACnB,OAAOC,UAAU,OAAM;AACvB,SAASC,sBAAsB,EAAEC,mBAAmB,QAAQ,UAAS;AACrE,SAASC,aAAa,QAAQ,MAAK;AAEnC,MAA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AAQ0B,MAAM,CAACC,IAAI,CAAC;QAAEC,KAAK,CAAC,qBAAqB,EAAEL,UAAU;IAAC;AAChE,EAAC"}
1
+ {"version":3,"sources":["../src/createMigration.ts"],"sourcesContent":["import type { CreateMigration, MigrationTemplateArgs } from 'payload'\n\nimport fs from 'fs'\nimport path from 'path'\nimport { getPredefinedMigration, writeMigrationIndex } from 'payload'\nimport { fileURLToPath } from 'url'\n\nconst migrationTemplate = ({ downSQL, imports, upSQL }: MigrationTemplateArgs): string => `import {\n MigrateDownArgs,\n MigrateUpArgs,\n} from '@payloadcms/db-mongodb'\n${imports ?? ''}\nexport async function up({ payload, req, session }: MigrateUpArgs): Promise<void> {\n${upSQL ?? ` // Migration code`}\n}\n\nexport async function down({ payload, req, session }: MigrateDownArgs): Promise<void> {\n${downSQL ?? ` // Migration code`}\n}\n`\n\nexport const createMigration: CreateMigration = async function createMigration({\n file,\n migrationName,\n payload,\n skipEmpty,\n}) {\n const filename = fileURLToPath(import.meta.url)\n const dirname = path.dirname(filename)\n\n const dir = payload.db.migrationDir\n if (!fs.existsSync(dir)) {\n fs.mkdirSync(dir)\n }\n const predefinedMigration = await getPredefinedMigration({\n dirname,\n file,\n migrationName,\n payload,\n })\n\n const migrationFileContent = migrationTemplate(predefinedMigration)\n\n const [yyymmdd, hhmmss] = new Date().toISOString().split('T')\n\n const formattedDate = yyymmdd!.replace(/\\D/g, '')\n const formattedTime = hhmmss!.split('.')[0]!.replace(/\\D/g, '')\n\n const timestamp = `${formattedDate}_${formattedTime}`\n\n const formattedName = migrationName?.replace(/\\W/g, '_')\n const fileName = migrationName ? `${timestamp}_${formattedName}.ts` : `${timestamp}_migration.ts`\n const filePath = `${dir}/${fileName}`\n\n if (skipEmpty) {\n return { created: false }\n }\n\n fs.writeFileSync(filePath, migrationFileContent)\n\n writeMigrationIndex({ migrationsDir: payload.db.migrationDir })\n\n payload.logger.info({ msg: `Migration created at ${filePath}` })\n\n return { created: true, path: filePath }\n}\n"],"names":["fs","path","getPredefinedMigration","writeMigrationIndex","fileURLToPath","migrationTemplate","downSQL","imports","upSQL","createMigration","file","migrationName","payload","skipEmpty","filename","url","dirname","dir","db","migrationDir","existsSync","mkdirSync","predefinedMigration","migrationFileContent","yyymmdd","hhmmss","Date","toISOString","split","formattedDate","replace","formattedTime","timestamp","formattedName","fileName","filePath","created","writeFileSync","migrationsDir","logger","info","msg"],"mappings":"AAEA,OAAOA,QAAQ,KAAI;AACnB,OAAOC,UAAU,OAAM;AACvB,SAASC,sBAAsB,EAAEC,mBAAmB,QAAQ,UAAS;AACrE,SAASC,aAAa,QAAQ,MAAK;AAEnC,MAAMC,oBAAoB,CAAC,EAAEC,OAAO,EAAEC,OAAO,EAAEC,KAAK,EAAyB,GAAa,CAAC;;;;AAI3F,EAAED,WAAW,GAAG;;AAEhB,EAAEC,SAAS,CAAC,mBAAmB,CAAC,CAAC;;;;AAIjC,EAAEF,WAAW,CAAC,mBAAmB,CAAC,CAAC;;AAEnC,CAAC;AAED,OAAO,MAAMG,kBAAmC,eAAeA,gBAAgB,EAC7EC,IAAI,EACJC,aAAa,EACbC,OAAO,EACPC,SAAS,EACV;IACC,MAAMC,WAAWV,cAAc,YAAYW,GAAG;IAC9C,MAAMC,UAAUf,KAAKe,OAAO,CAACF;IAE7B,MAAMG,MAAML,QAAQM,EAAE,CAACC,YAAY;IACnC,IAAI,CAACnB,GAAGoB,UAAU,CAACH,MAAM;QACvBjB,GAAGqB,SAAS,CAACJ;IACf;IACA,MAAMK,sBAAsB,MAAMpB,uBAAuB;QACvDc;QACAN;QACAC;QACAC;IACF;IAEA,MAAMW,uBAAuBlB,kBAAkBiB;IAE/C,MAAM,CAACE,SAASC,OAAO,GAAG,IAAIC,OAAOC,WAAW,GAAGC,KAAK,CAAC;IAEzD,MAAMC,gBAAgBL,QAASM,OAAO,CAAC,OAAO;IAC9C,MAAMC,gBAAgBN,OAAQG,KAAK,CAAC,IAAI,CAAC,EAAE,CAAEE,OAAO,CAAC,OAAO;IAE5D,MAAME,YAAY,GAAGH,cAAc,CAAC,EAAEE,eAAe;IAErD,MAAME,gBAAgBtB,eAAemB,QAAQ,OAAO;IACpD,MAAMI,WAAWvB,gBAAgB,GAAGqB,UAAU,CAAC,EAAEC,cAAc,GAAG,CAAC,GAAG,GAAGD,UAAU,aAAa,CAAC;IACjG,MAAMG,WAAW,GAAGlB,IAAI,CAAC,EAAEiB,UAAU;IAErC,IAAIrB,WAAW;QACb,OAAO;YAAEuB,SAAS;QAAM;IAC1B;IAEApC,GAAGqC,aAAa,CAACF,UAAUZ;IAE3BpB,oBAAoB;QAAEmC,eAAe1B,QAAQM,EAAE,CAACC,YAAY;IAAC;IAE7DP,QAAQ2B,MAAM,CAACC,IAAI,CAAC;QAAEC,KAAK,CAAC,qBAAqB,EAAEN,UAAU;IAAC;IAE9D,OAAO;QAAEC,SAAS;QAAMnC,MAAMkC;IAAS;AACzC,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"createVersion.d.ts","sourceRoot":"","sources":["../src/createVersion.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,aAAa,EAEnB,MAAM,SAAS,CAAA;AAQhB,eAAO,MAAM,aAAa,EAAE,aAkH3B,CAAA"}
1
+ {"version":3,"file":"createVersion.d.ts","sourceRoot":"","sources":["../src/createVersion.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgC,KAAK,aAAa,EAAE,MAAM,SAAS,CAAA;AAQ1E,eAAO,MAAM,aAAa,EAAE,aAqG3B,CAAA"}
@@ -1,4 +1,4 @@
1
- import { buildVersionCollectionFields, resolveBranchVersionParent } from 'payload';
1
+ import { buildVersionCollectionFields } from 'payload';
2
2
  import { getCollection } from './utilities/getEntity.js';
3
3
  import { getSession } from './utilities/getSession.js';
4
4
  import { transform } from './utilities/transform.js';
@@ -8,25 +8,15 @@ export const createVersion = async function createVersion({ autosave, collection
8
8
  collectionSlug,
9
9
  versions: true
10
10
  });
11
- const branched = await resolveBranchVersionParent({
12
- collectionSlug,
13
- parent,
14
- req,
15
- versionData: versionData
16
- });
17
11
  const data = {
18
12
  autosave,
19
13
  createdAt,
20
14
  latest: true,
21
- parent: branched.parent,
15
+ parent,
22
16
  publishedLocale,
23
17
  snapshot,
24
18
  updatedAt,
25
- version: versionData,
26
- ...branched.versionData._branch ? {
27
- _branch: branched.versionData._branch,
28
- _branchParent: branched.versionData._branchParent
29
- } : {}
19
+ version: versionData
30
20
  };
31
21
  if (!data.createdAt) {
32
22
  data.createdAt = new Date().toISOString();
@@ -45,10 +35,7 @@ export const createVersion = async function createVersion({ autosave, collection
45
35
  };
46
36
  let [doc] = await Model.create([
47
37
  data
48
- ], options, req);
49
- // No branch scoping needed here: a branch version's `parent` is the shadow
50
- // row's own primary key, so main's chain and the branch's chain are already
51
- // disjoint and `latest` clearing cannot cross between them.
38
+ ], options);
52
39
  const parentQuery = {
53
40
  $or: [
54
41
  {
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/createVersion.ts"],"sourcesContent":["import {\n buildVersionCollectionFields,\n type CreateVersion,\n resolveBranchVersionParent,\n} from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { getCollection } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\nimport { transform } from './utilities/transform.js'\n\nexport const createVersion: CreateVersion = async function createVersion(\n this: MongooseAdapter,\n {\n autosave,\n collectionSlug,\n createdAt,\n parent,\n publishedLocale,\n req,\n returning,\n snapshot,\n updatedAt,\n versionData,\n },\n) {\n const { collectionConfig, Model } = getCollection({\n adapter: this,\n collectionSlug,\n versions: true,\n })\n\n const branched = await resolveBranchVersionParent({\n collectionSlug,\n parent,\n req,\n versionData: versionData as Record<string, unknown>,\n })\n\n const data = {\n autosave,\n createdAt,\n latest: true,\n parent: branched.parent,\n publishedLocale,\n snapshot,\n updatedAt,\n version: versionData,\n ...(branched.versionData._branch\n ? { _branch: branched.versionData._branch, _branchParent: branched.versionData._branchParent }\n : {}),\n }\n if (!data.createdAt) {\n data.createdAt = new Date().toISOString()\n }\n\n const fields = buildVersionCollectionFields(this.payload.config, collectionConfig)\n\n transform({\n adapter: this,\n data,\n fields,\n operation: 'write',\n })\n\n const options = {\n session: await getSession(this, req),\n // Timestamps are manually added by the write transform\n timestamps: false,\n }\n\n let [doc] = await Model.create([data], options, req)\n\n // No branch scoping needed here: a branch version's `parent` is the shadow\n // row's own primary key, so main's chain and the branch's chain are already\n // disjoint and `latest` clearing cannot cross between them.\n const parentQuery = {\n $or: [\n {\n parent: {\n $eq: data.parent,\n },\n },\n ],\n }\n\n await Model.updateMany(\n {\n $and: [\n {\n _id: {\n $ne: doc._id,\n },\n },\n parentQuery,\n {\n latest: {\n $eq: true,\n },\n },\n {\n updatedAt: {\n $lt: new Date(doc.updatedAt),\n },\n },\n ],\n },\n { $unset: { latest: 1 } },\n options,\n )\n\n if (returning === false) {\n return null\n }\n\n doc = doc.toObject()\n\n transform({\n adapter: this,\n data: doc,\n fields,\n operation: 'read',\n })\n\n return doc\n}\n"],"names":["buildVersionCollectionFields","resolveBranchVersionParent","getCollection","getSession","transform","createVersion","autosave","collectionSlug","createdAt","parent","publishedLocale","req","returning","snapshot","updatedAt","versionData","collectionConfig","Model","adapter","versions","branched","data","latest","version","_branch","_branchParent","Date","toISOString","fields","payload","config","operation","options","session","timestamps","doc","create","parentQuery","$or","$eq","updateMany","$and","_id","$ne","$lt","$unset","toObject"],"mappings":"AAAA,SACEA,4BAA4B,EAE5BC,0BAA0B,QACrB,UAAS;AAIhB,SAASC,aAAa,QAAQ,2BAA0B;AACxD,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,SAAS,QAAQ,2BAA0B;AAEpD,OAAO,MAAMC,gBAA+B,eAAeA,cAEzD,EACEC,QAAQ,EACRC,cAAc,EACdC,SAAS,EACTC,MAAM,EACNC,eAAe,EACfC,GAAG,EACHC,SAAS,EACTC,QAAQ,EACRC,SAAS,EACTC,WAAW,EACZ;IAED,MAAM,EAAEC,gBAAgB,EAAEC,KAAK,EAAE,GA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BU;IAGF,IAAIpB,cAAc,OAAO;QACvB,OAAO;IACT;IAEAuB,MAAMA,IAAIW,QAAQ;IAElB1C,UAAU;QACRc,SAAS,IAAI;QACbG,MAAMc;QACNP;QACAG,WAAW;IACb;IAEA,OAAOI;AACT,EAAC"}
1
+ {"version":3,"sources":["../src/createVersion.ts"],"sourcesContent":["import { buildVersionCollectionFields, type CreateVersion } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { getCollection } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\nimport { transform } from './utilities/transform.js'\n\nexport const createVersion: CreateVersion = async function createVersion(\n this: MongooseAdapter,\n {\n autosave,\n collectionSlug,\n createdAt,\n parent,\n publishedLocale,\n req,\n returning,\n snapshot,\n updatedAt,\n versionData,\n },\n) {\n const { collectionConfig, Model } = getCollection({\n adapter: this,\n collectionSlug,\n versions: true,\n })\n\n const data = {\n autosave,\n createdAt,\n latest: true,\n parent,\n publishedLocale,\n snapshot,\n updatedAt,\n version: versionData,\n }\n if (!data.createdAt) {\n data.createdAt = new Date().toISOString()\n }\n\n const fields = buildVersionCollectionFields(this.payload.config, collectionConfig)\n\n transform({\n adapter: this,\n data,\n fields,\n operation: 'write',\n })\n\n const options = {\n session: await getSession(this, req),\n // Timestamps are manually added by the write transform\n timestamps: false,\n }\n\n let [doc] = await Model.create([data], options)\n\n const parentQuery = {\n $or: [\n {\n parent: {\n $eq: data.parent,\n },\n },\n ],\n }\n\n await Model.updateMany(\n {\n $and: [\n {\n _id: {\n $ne: doc._id,\n },\n },\n parentQuery,\n {\n latest: {\n $eq: true,\n },\n },\n {\n updatedAt: {\n $lt: new Date(doc.updatedAt),\n },\n },\n ],\n },\n { $unset: { latest: 1 } },\n options,\n )\n\n if (returning === false) {\n return null\n }\n\n doc = doc.toObject()\n\n transform({\n adapter: this,\n data: doc,\n fields,\n operation: 'read',\n })\n\n return doc\n}\n"],"names":["buildVersionCollectionFields","getCollection","getSession","transform","createVersion","autosave","collectionSlug","createdAt","parent","publishedLocale","req","returning","snapshot","updatedAt","versionData","collectionConfig","Model","adapter","versions","data","latest","version","Date","toISOString","fields","payload","config","operation","options","session","timestamps","doc","create","parentQuery","$or","$eq","updateMany","$and","_id","$ne","$lt","$unset","toObject"],"mappings":"AAAA,SAASA,4BAA4B,QAA4B,UAAS;AAI1E,SAASC,aAAa,QAAQ,2BAA0B;AACxD,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,SAAS,QAAQ,2BAA0B;AAEpD,OAAO,MAAMC,gBAA+B,eAAeA,cAEzD,EACEC,QAAQ,EACRC,cAAc,EACdC,SAAS,EACTC,MAAM,EACNC,eAAe,EACfC,GAAG,EACHC,SAAS,EACTC,QAAQ,EACRC,SAAS,EACTC,WAAW,EACZ;IAED,MAAM,EAAEC,gBAAgB,EAAEC,KAAK,EAAE,GAAGf,cAAc;QAChDgB,SAAS,IAAI;QACbX;QACAY,UAAU;IACZ;IAEA,MAAMC,OAAO;QACXd;QACAE;QACAa,QAAQ;QACRZ;QACAC;QACAG;QACAC;QACAQ,SAASP;IACX;IACA,IAAI,CAACK,KAAKZ,SAAS,EAAE;QACnBY,KAAKZ,SAAS,GAAG,IAAIe,OAAOC,WAAW;IACzC;IAEA,MAAMC,SAASxB,6BAA6B,IAAI,CAACyB,OAAO,CAACC,MAAM,EAAEX;IAEjEZ,UAAU;QACRc,SAAS,IAAI;QACbE;QACAK;QACAG,WAAW;IACb;IAEA,MAAMC,UAAU;QACdC,SAAS,MAAM3B,WAAW,IAAI,EAAEQ;QAChC,uDAAuD;QACvDoB,YAAY;IACd;IAEA,IAAI,CAACC,IAAI,GAAG,MAAMf,MAAMgB,MAAM,CAAC;QAACb;KAAK,EAAES;IAEvC,MAAMK,cAAc;QAClBC,KAAK;YACH;gBACE1B,QAAQ;oBACN2B,KAAKhB,KAAKX,MAAM;gBAClB;YACF;SACD;IACH;IAEA,MAAMQ,MAAMoB,UAAU,CACpB;QACEC,MAAM;YACJ;gBACEC,KAAK;oBACHC,KAAKR,IAAIO,GAAG;gBACd;YACF;YACAL;YACA;gBACEb,QAAQ;oBACNe,KAAK;gBACP;YACF;YACA;gBACEtB,WAAW;oBACT2B,KAAK,IAAIlB,KAAKS,IAAIlB,SAAS;gBAC7B;YACF;SACD;IACH,GACA;QAAE4B,QAAQ;YAAErB,QAAQ;QAAE;IAAE,GACxBQ;IAGF,IAAIjB,cAAc,OAAO;QACvB,OAAO;IACT;IAEAoB,MAAMA,IAAIW,QAAQ;IAElBvC,UAAU;QACRc,SAAS,IAAI;QACbE,MAAMY;QACNP;QACAG,WAAW;IACb;IAEA,OAAOI;AACT,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"deleteOne.d.ts","sourceRoot":"","sources":["../src/deleteOne.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAYxC,eAAO,MAAM,SAAS,EAAE,SAmDvB,CAAA"}
1
+ {"version":3,"file":"deleteOne.d.ts","sourceRoot":"","sources":["../src/deleteOne.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAUxC,eAAO,MAAM,SAAS,EAAE,SAyCvB,CAAA"}
package/dist/deleteOne.js CHANGED
@@ -1,30 +1,13 @@
1
- import { resolveBranchDelete } from 'payload';
2
1
  import { buildQuery } from './queries/buildQuery.js';
3
2
  import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
4
3
  import { getCollection } from './utilities/getEntity.js';
5
4
  import { getSession } from './utilities/getSession.js';
6
5
  import { transform } from './utilities/transform.js';
7
- export const deleteOne = async function deleteOne({ branch, collection: collectionSlug, req, returning, select, where }) {
6
+ export const deleteOne = async function deleteOne({ collection: collectionSlug, req, returning, select, where }) {
8
7
  const { collectionConfig, Model } = getCollection({
9
8
  adapter: this,
10
9
  collectionSlug
11
10
  });
12
- const branchDelete = await resolveBranchDelete({
13
- branch,
14
- collectionSlug,
15
- req,
16
- where
17
- });
18
- if (branchDelete.tombstoned) {
19
- return returning === false ? null : branchDelete.doc;
20
- }
21
- if (branchDelete.deleteRowID !== undefined) {
22
- where = {
23
- id: {
24
- equals: branchDelete.deleteRowID
25
- }
26
- };
27
- }
28
11
  const query = await buildQuery({
29
12
  adapter: this,
30
13
  collectionSlug,
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/deleteOne.ts"],"sourcesContent":["import type { QueryOptions } from 'mongoose'\nimport type { DeleteOne } from 'payload'\n\nimport { resolveBranchDelete } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getCollection } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\nimport { transform } from './utilities/transform.js'\n\nexport const deleteOne: DeleteOne = async function deleteOne(\n this: MongooseAdapter,\n { branch, collection: collectionSlug, req, returning, select, where },\n) {\n const { collectionConfig, Model } = getCollection({ adapter: this, collectionSlug })\n\n const branchDelete = await resolveBranchDelete({ branch, collectionSlug, req, where })\n\n if (branchDelete.tombstoned) {\n return returning === false ? null : (branchDelete.doc as any)\n }\n\n if (branchDelete.deleteRowID !== undefined) {\n where = { id: { equals: branchDelete.deleteRowID } }\n }\n\n const query = await buildQuery({\n adapter: this,\n collectionSlug,\n fields: collectionConfig.flattenedFields,\n where,\n })\n\n const options = {\n projection: buildProjectionFromSelect({\n adapter: this,\n fields: collectionConfig.flattenedFields,\n select,\n }),\n session: await getSession(this, req),\n } satisfies QueryOptions\n\n if (returning === false) {\n await Model.deleteOne(query, options)?.lean()\n return null\n }\n\n const doc = await Model.findOneAndDelete(query, options)?.lean()\n\n if (!doc) {\n return null\n }\n\n transform({\n adapter: this,\n data: doc,\n fields: collectionConfig.fields,\n operation: 'read',\n })\n\n return doc\n}\n"],"names":["resolveBranchDelete","buildQuery","buildProjectionFromSelect","getCollection","getSession","transform","deleteOne","branch","collection","collectionSlug","req","returning","select","where","collectionConfig","Model","adapter","branchDelete","tombstoned","doc","deleteRowID","undefined","id","equals","query","fields","flattenedFields","options","projection","session","lean","findOneAndDelete","data","operation"],"mappings":"AAGA,SAASA,mBAAmB,QAAQ,UAAS;AAI7C,SAASC,UAAU,QAAQ,0BAAyB;AACpD,SAASC,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,aAAa,QAAQ,2BAA0B;AACxD,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,SAAS,QAAQ,2BAA0B;AAEpD,OAAO,MAAMC,YAAuB,eAAeA,UAEjD,EAAEC,MAAM,EAAEC,YAAYC,cAAc,EAAEC,GAAG,EAAEC,SAAS,EAAEC,MAAM,EAAEC,KAAK,EAAE;IAErE,MAAM,EAAEC,gBAAgB,EAAEC,KAAK,EAAE,GAAGZ,cAAc;QAAEa,SAAS,IAAI;QAAEP;IAAe;IAElF,MAAMQ,eAAe,MAAMjB,oBAAoB;QAAEO;QAAQE;QAAgBC;QAAKG;IAAM;IAEpF,IAAII,aAAaC,UAAU,EAAE;QAC3B,OAAOP,cAAc,QAAQ,OAAQM,aAAaE,GAAG;IACvD;IAEA,IAAIF,aAAaG,WAAW,KAAKC,WAAW;QAC1CR,QAAQ;YAAES,IAAI;gBAAEC,QAAQN,aAAaG,WAAW;YAAC;QAAE;IACrD;IAEA,MAAMI,QAAQ,MAAMvB,WAAW;QAC7Be,SAAS,IAAI;QACbP;QACAgB,QAAQX,iBAAiBY,eAAe;QACxCb;IACF;IAEA,MAAMc,UAAU;QACdC,YAAY1B,0BAA0B;YACpCc,SAAS,IAAI;YACbS,QAAQX,iBAAiBY,eAAe;YACxCd;QACF;QACAiB,SAAS,MAAMzB,WAAW,IAAI,EAAEM;IAClC;IAEA,IAAIC,cAAc,OAAO;QACvB,MAAMI,MAAMT,SAAS,CAACkB,OAAOG,UAAUG;QACvC,OAAO;IACT;IAEA,MAAMX,MAAM,MAAMJ,MAAMgB,gBAAgB,CAACP,OAAOG,UAAUG;IAE1D,IAAI,CAACX,KAAK;QACR,OAAO;IACT;IAEAd,UAAU;QACRW,SAAS,IAAI;QACbgB,MAAMb;QACNM,QAAQX,iBAAiBW,MAAM;QAC/BQ,WAAW;IACb;IAEA,OAAOd;AACT,EAAC"}
1
+ {"version":3,"sources":["../src/deleteOne.ts"],"sourcesContent":["import type { QueryOptions } from 'mongoose'\nimport type { DeleteOne } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getCollection } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\nimport { transform } from './utilities/transform.js'\n\nexport const deleteOne: DeleteOne = async function deleteOne(\n this: MongooseAdapter,\n { collection: collectionSlug, req, returning, select, where },\n) {\n const { collectionConfig, Model } = getCollection({ adapter: this, collectionSlug })\n\n const query = await buildQuery({\n adapter: this,\n collectionSlug,\n fields: collectionConfig.flattenedFields,\n where,\n })\n\n const options = {\n projection: buildProjectionFromSelect({\n adapter: this,\n fields: collectionConfig.flattenedFields,\n select,\n }),\n session: await getSession(this, req),\n } satisfies QueryOptions\n\n if (returning === false) {\n await Model.deleteOne(query, options)?.lean()\n return null\n }\n\n const doc = await Model.findOneAndDelete(query, options)?.lean()\n\n if (!doc) {\n return null\n }\n\n transform({\n adapter: this,\n data: doc,\n fields: collectionConfig.fields,\n operation: 'read',\n })\n\n return doc\n}\n"],"names":["buildQuery","buildProjectionFromSelect","getCollection","getSession","transform","deleteOne","collection","collectionSlug","req","returning","select","where","collectionConfig","Model","adapter","query","fields","flattenedFields","options","projection","session","lean","doc","findOneAndDelete","data","operation"],"mappings":"AAKA,SAASA,UAAU,QAAQ,0BAAyB;AACpD,SAASC,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,aAAa,QAAQ,2BAA0B;AACxD,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,SAAS,QAAQ,2BAA0B;AAEpD,OAAO,MAAMC,YAAuB,eAAeA,UAEjD,EAAEC,YAAYC,cAAc,EAAEC,GAAG,EAAEC,SAAS,EAAEC,MAAM,EAAEC,KAAK,EAAE;IAE7D,MAAM,EAAEC,gBAAgB,EAAEC,KAAK,EAAE,GAAGX,cAAc;QAAEY,SAAS,IAAI;QAAEP;IAAe;IAElF,MAAMQ,QAAQ,MAAMf,WAAW;QAC7Bc,SAAS,IAAI;QACbP;QACAS,QAAQJ,iBAAiBK,eAAe;QACxCN;IACF;IAEA,MAAMO,UAAU;QACdC,YAAYlB,0BAA0B;YACpCa,SAAS,IAAI;YACbE,QAAQJ,iBAAiBK,eAAe;YACxCP;QACF;QACAU,SAAS,MAAMjB,WAAW,IAAI,EAAEK;IAClC;IAEA,IAAIC,cAAc,OAAO;QACvB,MAAMI,MAAMR,SAAS,CAACU,OAAOG,UAAUG;QACvC,OAAO;IACT;IAEA,MAAMC,MAAM,MAAMT,MAAMU,gBAAgB,CAACR,OAAOG,UAAUG;IAE1D,IAAI,CAACC,KAAK;QACR,OAAO;IACT;IAEAlB,UAAU;QACRU,SAAS,IAAI;QACbU,MAAMF;QACNN,QAAQJ,iBAAiBI,MAAM;QAC/BS,WAAW;IACb;IAEA,OAAOH;AACT,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;AAqBnC,eAAO,MAAM,IAAI,EAAE,IA8LlB,CAAA"}
1
+ {"version":3,"file":"find.d.ts","sourceRoot":"","sources":["../src/find.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAgBnC,eAAO,MAAM,IAAI,EAAE,IAiLlB,CAAA"}
package/dist/find.js CHANGED
@@ -1,4 +1,4 @@
1
- import { applyBranchIDProjection, flattenWhereToOperators, resolveBranchQuery, withBranchIDSelect } from 'payload';
1
+ import { flattenWhereToOperators } from 'payload';
2
2
  import { buildQuery } from './queries/buildQuery.js';
3
3
  import { buildSortParam } from './queries/buildSortParam.js';
4
4
  import { aggregatePaginate } from './utilities/aggregatePaginate.js';
@@ -8,17 +8,11 @@ import { getCollection } from './utilities/getEntity.js';
8
8
  import { getSession } from './utilities/getSession.js';
9
9
  import { resolveJoins } from './utilities/resolveJoins.js';
10
10
  import { transform } from './utilities/transform.js';
11
- export const find = async function find({ branch, collection: collectionSlug, draftsEnabled, joins = {}, limit = 0, locale, page, pagination, projection, req, select, sort: sortArg, where = {} }) {
11
+ export const find = async function find({ collection: collectionSlug, draftsEnabled, joins = {}, limit = 0, locale, page, pagination, projection, req, select, sort: sortArg, where = {} }) {
12
12
  const { collectionConfig, Model } = getCollection({
13
13
  adapter: this,
14
14
  collectionSlug
15
15
  });
16
- where = await resolveBranchQuery({
17
- branch,
18
- collectionSlug,
19
- req,
20
- where
21
- }) ?? {};
22
16
  let hasNearConstraint = false;
23
17
  if (where) {
24
18
  const constraints = flattenWhereToOperators(where);
@@ -59,17 +53,11 @@ export const find = async function find({ branch, collection: collectionSlug, dr
59
53
  sort,
60
54
  useEstimatedCount
61
55
  };
62
- const selectWithBranchID = withBranchIDSelect({
63
- branch,
64
- collectionSlug,
65
- req,
66
- select
67
- });
68
- if (selectWithBranchID) {
56
+ if (select) {
69
57
  paginationOptions.projection = buildProjectionFromSelect({
70
58
  adapter: this,
71
59
  fields: collectionConfig.flattenedFields,
72
- select: selectWithBranchID
60
+ select
73
61
  });
74
62
  }
75
63
  if (this.collation) {
@@ -124,10 +112,9 @@ export const find = async function find({ branch, collection: collectionSlug, dr
124
112
  joins,
125
113
  locale,
126
114
  projection: paginationOptions.projection,
127
- query,
128
- req
115
+ query
129
116
  });
130
- if (aggregate || sortAggregation.length > 0) {
117
+ if (aggregate.length > 0 || sortAggregation.length > 0) {
131
118
  result = await aggregatePaginate({
132
119
  adapter: this,
133
120
  collation: paginationOptions.collation,
@@ -161,12 +148,6 @@ export const find = async function find({ branch, collection: collectionSlug, dr
161
148
  fields: collectionConfig.fields,
162
149
  operation: 'read'
163
150
  });
164
- applyBranchIDProjection({
165
- branch,
166
- collectionSlug,
167
- docs: result.docs,
168
- req
169
- });
170
151
  return result;
171
152
  };
172
153
 
package/dist/find.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/find.ts"],"sourcesContent":["import type { PaginateOptions, PipelineStage } from 'mongoose'\nimport type { Find } from 'payload'\n\nimport {\n applyBranchIDProjection,\n flattenWhereToOperators,\n resolveBranchQuery,\n withBranchIDSelect,\n} from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { buildSortParam } from './queries/buildSortParam.js'\nimport { aggregatePaginate } from './utilities/aggregatePaginate.js'\nimport { buildJoinAggregation } from './utilities/buildJoinAggregation.js'\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getCollection } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\nimport { resolveJoins } from './utilities/resolveJoins.js'\nimport { transform } from './utilities/transform.js'\n\nexport const find: Find = async function find(\n this: MongooseAdapter,\n {\n branch,\n collection: collectionSlug,\n draftsEnabled,\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 { collectionConfig, Model } = getCollection({ adapter: this, collectionSlug })\n\n where = (await resolveBranchQuery({ branch, collectionSlug, req, where })) ?? {}\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 sortAggregation: PipelineStage[] = []\n\n let sort\n if (!hasNearConstraint) {\n sort = buildSortParam({\n adapter: this,\n config: this.payload.config,\n fields: collectionConfig.flattenedFields,\n locale,\n sort: sortArg || collectionConfig.defaultSort,\n sortAggregation,\n timestamps: collectionConfig.timestamps || false,\n })\n }\n\n const query = await buildQuery({\n adapter: this,\n collectionSlug,\n fields: collectionConfig.flattenedFields,\n locale,\n where,\n })\n\n const session = await getSession(this, req)\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 const selectWithBranchID = withBranchIDSelect({ branch, collectionSlug, req, select })\n\n if (selectWithBranchID) {\n paginationOptions.projection = buildProjectionFromSelect({\n adapter: this,\n fields: collectionConfig.flattenedFields,\n select: selectWithBranchID,\n })\n }\n\n if (this.collation) {\n const localizationConfig = this.payload.config.localization\n const defaultLocale =\n (typeof localizationConfig === 'object' && localizationConfig?.defaultLocale) || 'en'\n\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 collation: paginationOptions.collation,\n hint: { _id: 1 },\n session,\n }),\n )\n }\n } else if (!useEstimatedCount && this.collation) {\n // Workaround for mongoose-paginate-v2 bug: chaining .collation() on countDocuments breaks\n // session context in transactions (mongoose 8.x). Provide custom count function that passes\n // collation as an option instead. See: https://github.com/aravindnc/mongoose-paginate-v2/pull/240\n // TODO: Remove this workaround once mongoose-paginate-v2 is updated with the fix.\n paginationOptions.useCustomCountFn = () => {\n return Promise.resolve(\n Model.countDocuments(query, {\n collation: paginationOptions.collation,\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\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: collectionSlug,\n collectionConfig,\n draftsEnabled,\n joins,\n locale,\n projection: paginationOptions.projection,\n query,\n req,\n })\n\n if (aggregate || sortAggregation.length > 0) {\n result = await aggregatePaginate({\n adapter: this,\n collation: paginationOptions.collation,\n joinAggregation: aggregate,\n limit: paginationOptions.limit,\n Model,\n page: paginationOptions.page,\n pagination: paginationOptions.pagination,\n projection: paginationOptions.projection,\n query,\n session: paginationOptions.options?.session ?? undefined,\n sort: paginationOptions.sort as object,\n sortAggregation,\n useEstimatedCount: paginationOptions.useEstimatedCount,\n })\n } else {\n result = await Model.paginate(query, paginationOptions)\n }\n\n if (!this.useJoinAggregations) {\n await resolveJoins({\n adapter: this,\n collectionSlug,\n docs: result.docs as Record<string, unknown>[],\n joins,\n locale,\n })\n }\n\n transform({\n adapter: this,\n data: result.docs,\n fields: collectionConfig.fields,\n operation: 'read',\n })\n\n applyBranchIDProjection({\n branch,\n collectionSlug,\n docs: result.docs as Record<string, unknown>[],\n req,\n })\n\n return result\n}\n"],"names":["applyBranchIDProjection","flattenWhereToOperators","resolveBranchQuery","withBranchIDSelect","buildQuery","buildSortParam","aggregatePaginate","buildJoinAggregation","buildProjectionFromSelect","getCollection","getSession","resolveJoins","transform","find","branch","collection","collectionSlug","draftsEnabled","joins","limit","locale","page","pagination","projection","req","select","sort","sortArg","where","collectionConfig","Model","adapter","hasNearConstraint","constraints","some","prop","Object","keys","key","sortAggregation","config","payload","fields","flattenedFields","defaultSort","timestamps","query","session","useEstimatedCount","length","paginationOptions","lean","leanWithId","options","selectWithBranchID","collation","localizationConfig","localization","defaultLocale","disableIndexHints","useCustomCountFn","Promise","resolve","countDocuments","hint","_id","result","aggregate","joinAggregation","undefined","paginate","useJoinAggregations","docs","data","operation"],"m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B,EAAE;QAC7B,MAAM5D,aAAa;YACjBoB,SAAS,IAAI;YACbf;YACAwD,MAAMN,OAAOM,IAAI;YACjBtD;YACAE;QACF;IACF;IAEAR,UAAU;QACRmB,SAAS,IAAI;QACb0C,MAAMP,OAAOM,IAAI;QACjB9B,QAAQb,iBAAiBa,MAAM;QAC/BgC,WAAW;IACb;IAEA1E,wBAAwB;QACtBc;QACAE;QACAwD,MAAMN,OAAOM,IAAI;QACjBhD;IACF;IAEA,OAAO0C;AACT,EAAC"}
1
+ {"version":3,"sources":["../src/find.ts"],"sourcesContent":["import type { PaginateOptions, PipelineStage } 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 { aggregatePaginate } from './utilities/aggregatePaginate.js'\nimport { buildJoinAggregation } from './utilities/buildJoinAggregation.js'\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getCollection } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\nimport { resolveJoins } from './utilities/resolveJoins.js'\nimport { transform } from './utilities/transform.js'\n\nexport const find: Find = async function find(\n this: MongooseAdapter,\n {\n collection: collectionSlug,\n draftsEnabled,\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 { collectionConfig, Model } = getCollection({ adapter: this, collectionSlug })\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 sortAggregation: PipelineStage[] = []\n\n let sort\n if (!hasNearConstraint) {\n sort = buildSortParam({\n adapter: this,\n config: this.payload.config,\n fields: collectionConfig.flattenedFields,\n locale,\n sort: sortArg || collectionConfig.defaultSort,\n sortAggregation,\n timestamps: collectionConfig.timestamps || false,\n })\n }\n\n const query = await buildQuery({\n adapter: this,\n collectionSlug,\n fields: collectionConfig.flattenedFields,\n locale,\n where,\n })\n\n const session = await getSession(this, req)\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 localizationConfig = this.payload.config.localization\n const defaultLocale =\n (typeof localizationConfig === 'object' && localizationConfig?.defaultLocale) || 'en'\n\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 collation: paginationOptions.collation,\n hint: { _id: 1 },\n session,\n }),\n )\n }\n } else if (!useEstimatedCount && this.collation) {\n // Workaround for mongoose-paginate-v2 bug: chaining .collation() on countDocuments breaks\n // session context in transactions (mongoose 8.x). Provide custom count function that passes\n // collation as an option instead. See: https://github.com/aravindnc/mongoose-paginate-v2/pull/240\n // TODO: Remove this workaround once mongoose-paginate-v2 is updated with the fix.\n paginationOptions.useCustomCountFn = () => {\n return Promise.resolve(\n Model.countDocuments(query, {\n collation: paginationOptions.collation,\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\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: collectionSlug,\n collectionConfig,\n draftsEnabled,\n joins,\n locale,\n projection: paginationOptions.projection,\n query,\n })\n\n if (aggregate.length > 0 || sortAggregation.length > 0) {\n result = await aggregatePaginate({\n adapter: this,\n collation: paginationOptions.collation,\n joinAggregation: aggregate,\n limit: paginationOptions.limit,\n Model,\n page: paginationOptions.page,\n pagination: paginationOptions.pagination,\n projection: paginationOptions.projection,\n query,\n session: paginationOptions.options?.session ?? undefined,\n sort: paginationOptions.sort as object,\n sortAggregation,\n useEstimatedCount: paginationOptions.useEstimatedCount,\n })\n } else {\n result = await Model.paginate(query, paginationOptions)\n }\n\n if (!this.useJoinAggregations) {\n await resolveJoins({\n adapter: this,\n collectionSlug,\n docs: result.docs as Record<string, unknown>[],\n joins,\n locale,\n })\n }\n\n transform({\n adapter: this,\n data: result.docs,\n fields: collectionConfig.fields,\n operation: 'read',\n })\n\n return result\n}\n"],"names":["flattenWhereToOperators","buildQuery","buildSortParam","aggregatePaginate","buildJoinAggregation","buildProjectionFromSelect","getCollection","getSession","resolveJoins","transform","find","collection","collectionSlug","draftsEnabled","joins","limit","locale","page","pagination","projection","req","select","sort","sortArg","where","collectionConfig","Model","adapter","hasNearConstraint","constraints","some","prop","Object","keys","key","sortAggregation","config","payload","fields","flattenedFields","defaultSort","timestamps","query","session","useEstimatedCount","length","paginationOptions","lean","leanWithId","options","collation","localizationConfig","localization","defaultLocale","disableIndexHints","useCustomCountFn","Promise","resolve","countDocuments","hint","_id","result","aggregate","joinAggregation","undefined","paginate","useJoinAggregations","docs","data","operation"],"mappings":"AAGA,SAASA,uBAAuB,QAAQ,UAAS;AAIjD,SAASC,UAAU,QAAQ,0BAAyB;AACpD,SAASC,cAAc,QAAQ,8BAA6B;AAC5D,SAASC,iBAAiB,QAAQ,mCAAkC;AACpE,SAASC,oBAA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AAkB,MAAM,SAAS,CAAA;AA6C3D,eAAO,MAAM,YAAY,EAAE,YA+Q1B,CAAA"}
1
+ {"version":3,"file":"findDistinct.d.ts","sourceRoot":"","sources":["../src/findDistinct.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAkB,MAAM,SAAS,CAAA;AA6C3D,eAAO,MAAM,YAAY,EAAE,YAsQ1B,CAAA"}
@@ -1,4 +1,4 @@
1
- import { getFieldByPath, resolveBranchQuery } from 'payload';
1
+ import { getFieldByPath } from 'payload';
2
2
  import { buildQuery } from './queries/buildQuery.js';
3
3
  import { buildSortParam } from './queries/buildSortParam.js';
4
4
  import { getCollection } from './utilities/getEntity.js';
@@ -29,15 +29,7 @@ export const findDistinct = async function(args) {
29
29
  adapter: this,
30
30
  collectionSlug: args.collection
31
31
  });
32
- // Distinct values describe the documents the caller can see, so they are subject to
33
- // the same branch predicate as a list read. Without it a branch's shadow rows fed
34
- // main's distinct values and the branch's own edits were invisible in its own.
35
- const where = await resolveBranchQuery({
36
- branch: args.branch,
37
- collectionSlug: args.collection,
38
- req: args.req,
39
- where: args.where
40
- }) ?? {};
32
+ const { where = {} } = args;
41
33
  let sortAggregation = [];
42
34
  const sort = buildSortParam({
43
35
  adapter: this,