@payloadcms/db-mongodb 4.0.0-internal.7803e2c → 4.0.0-internal.7b53b6d

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 (38) hide show
  1. package/dist/countGlobalVersions.d.ts.map +1 -1
  2. package/dist/countGlobalVersions.js +2 -9
  3. package/dist/countGlobalVersions.js.map +1 -1
  4. package/dist/createGlobalVersion.js +1 -3
  5. package/dist/createGlobalVersion.js.map +1 -1
  6. package/dist/deleteBranchGlobal.d.ts.map +1 -1
  7. package/dist/deleteBranchGlobal.js +0 -4
  8. package/dist/deleteBranchGlobal.js.map +1 -1
  9. package/dist/findGlobal.d.ts.map +1 -1
  10. package/dist/findGlobal.js +11 -21
  11. package/dist/findGlobal.js.map +1 -1
  12. package/dist/predefinedMigrations/branching.d.ts +1 -1
  13. package/dist/predefinedMigrations/branching.d.ts.map +1 -1
  14. package/dist/predefinedMigrations/branching.js +2 -2
  15. package/dist/predefinedMigrations/branching.js.map +1 -1
  16. package/dist/predefinedMigrations/migrateBranching.d.ts +0 -2
  17. package/dist/predefinedMigrations/migrateBranching.d.ts.map +1 -1
  18. package/dist/predefinedMigrations/migrateBranching.js +0 -2
  19. package/dist/predefinedMigrations/migrateBranching.js.map +1 -1
  20. package/dist/queries/buildSearchParams.d.ts.map +1 -1
  21. package/dist/queries/buildSearchParams.js +60 -61
  22. package/dist/queries/buildSearchParams.js.map +1 -1
  23. package/dist/queryDrafts.js +0 -1
  24. package/dist/queryDrafts.js.map +1 -1
  25. package/dist/updateGlobal.d.ts.map +1 -1
  26. package/dist/updateGlobal.js +13 -15
  27. package/dist/updateGlobal.js.map +1 -1
  28. package/dist/utilities/buildJoinAggregation.d.ts.map +1 -1
  29. package/dist/utilities/buildJoinAggregation.js +5 -36
  30. package/dist/utilities/buildJoinAggregation.js.map +1 -1
  31. package/dist/utilities/resolveJoins.d.ts.map +1 -1
  32. package/dist/utilities/resolveJoins.js +3 -4
  33. package/dist/utilities/resolveJoins.js.map +1 -1
  34. package/package.json +3 -3
  35. package/dist/queries/buildRelatedQueryPipeline.d.ts +0 -7
  36. package/dist/queries/buildRelatedQueryPipeline.d.ts.map +0 -1
  37. package/dist/queries/buildRelatedQueryPipeline.js +0 -56
  38. package/dist/queries/buildRelatedQueryPipeline.js.map +0 -1
@@ -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;AAclD,eAAO,MAAM,mBAAmB,EAAE,mBA6DjC,CAAA"}
1
+ {"version":3,"file":"countGlobalVersions.d.ts","sourceRoot":"","sources":["../src/countGlobalVersions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAA;AAUlD,eAAO,MAAM,mBAAmB,EAAE,mBA2DjC,CAAA"}
@@ -1,19 +1,13 @@
1
- import { buildVersionGlobalFields, flattenWhereToOperators, resolveBranchGlobalVersionQuery } from 'payload';
1
+ import { buildVersionGlobalFields, flattenWhereToOperators } from 'payload';
2
2
  import { buildQuery } from './queries/buildQuery.js';
3
3
  import { getGlobal } from './utilities/getEntity.js';
4
4
  import { getSession } from './utilities/getSession.js';
5
- export const countGlobalVersions = async function countGlobalVersions({ branch, global: globalSlug, locale, req, where = {} }) {
5
+ export const countGlobalVersions = async function countGlobalVersions({ global: globalSlug, locale, req, where = {} }) {
6
6
  const { globalConfig, Model } = getGlobal({
7
7
  adapter: this,
8
8
  globalSlug,
9
9
  versions: true
10
10
  });
11
- where = resolveBranchGlobalVersionQuery({
12
- branch,
13
- globalSlug,
14
- req,
15
- where
16
- }) ?? {};
17
11
  let hasNearConstraint = false;
18
12
  if (where) {
19
13
  const constraints = flattenWhereToOperators(where);
@@ -21,7 +15,6 @@ export const countGlobalVersions = async function countGlobalVersions({ branch,
21
15
  }
22
16
  const query = await buildQuery({
23
17
  adapter: this,
24
- branch,
25
18
  fields: buildVersionGlobalFields(this.payload.config, globalConfig, true),
26
19
  locale,
27
20
  req,
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/countGlobalVersions.ts"],"sourcesContent":["import type { CountOptions } from 'mongodb'\nimport type { CountGlobalVersions } from 'payload'\n\nimport {\n buildVersionGlobalFields,\n flattenWhereToOperators,\n resolveBranchGlobalVersionQuery,\n} from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { getGlobal } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\n\nexport const countGlobalVersions: CountGlobalVersions = async function countGlobalVersions(\n this: MongooseAdapter,\n { branch, global: globalSlug, locale, req, where = {} },\n) {\n const { globalConfig, Model } = getGlobal({ adapter: this, globalSlug, versions: true })\n where = resolveBranchGlobalVersionQuery({ branch, globalSlug, 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 branch,\n fields: buildVersionGlobalFields(this.payload.config, globalConfig, true),\n locale,\n req,\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":["buildVersionGlobalFields","flattenWhereToOperators","resolveBranchGlobalVersionQuery","buildQuery","getGlobal","getSession","countGlobalVersions","branch","global","globalSlug","locale","req","where","globalConfig","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,wBAAwB,EACxBC,uBAAuB,EACvBC,+BAA+B,QAC1B,UAAS;AAIhB,SAASC,UAAU,QAAQ,0BAAyB;AACpD,SAASC,SAAS,QAAQ,2BAA0B;AACpD,SAASC,UAAU,QAAQ,4BAA2B;AAEtD,OAAO,MAAMC,sBAA2C,eAAeA,oBAErE,EAAEC,MAAM,EAAEC,QAAQC,UAAU,EAAEC,MAAM,EAAEC,GAAG,EAAEC,QAAQ,CAAC,CAAC,EAAE;IAEvD,MAAM,EAAEC,YAAY,EAAEC,KAAK,EAAE,GAAGV,UAAU;QAAEW,SAAS,IAAI;QAAEN;QAAYO,UAAU;IAAK;IACtFJ,QAAQV,gCAAgC;QAAEK;QAAQE;QAAYE;QAAKC;IAAM,MAAM,CAAC;IAEhF,IAAIK,oBAAoB;IAExB,IAAIL,OAAO;QACT,MAAMM,cAAcjB,wBAAwBW;QAC5CK,oBAAoBC,YAAYC,IAAI,CAAC,CAACC,OAASC,OAAOC,IAAI,CAACF,MAAMD,IAAI,CAAC,CAACI,MAAQA,QAAQ;IACzF;IAEA,MAAMC,QAAQ,MAAMrB,WAAW;QAC7BY,SAAS,IAAI;QACbR;QACAkB,QAAQzB,yBAAyB,IAAI,CAAC0B,OAAO,CAACC,MAAM,EAAEd,cAAc;QACpEH;QACAC;QACAC;IACF;IAEA,4HAA4H;IAC5H,MAAMgB,oBAAoBX,qBAAqB,CAACO,SAASH,OAAOC,IAAI,CAACE,OAAOK,MAAM,KAAK;IAEvF,MAAMC,UAAwB;QAC5BC,SAAS,MAAM1B,WAAW,IAAI,EAAEM;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
+ {"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 { getGlobal } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\n\nexport const countGlobalVersions: CountGlobalVersions = async function countGlobalVersions(\n this: MongooseAdapter,\n { global: globalSlug, locale, req, where = {} },\n) {\n const { globalConfig, Model } = getGlobal({ adapter: this, globalSlug, versions: true })\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(this.payload.config, globalConfig, true),\n locale,\n req,\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":["buildVersionGlobalFields","flattenWhereToOperators","buildQuery","getGlobal","getSession","countGlobalVersions","global","globalSlug","locale","req","where","globalConfig","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,wBAAwB,EAAEC,uBAAuB,QAAQ,UAAS;AAI3E,SA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mH;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"}
@@ -8,9 +8,7 @@ export const createGlobalVersion = async function createGlobalVersion({ autosave
8
8
  globalSlug,
9
9
  versions: true
10
10
  });
11
- const versionBranch = req?.payload?.config?.branching?.branchableGlobals?.has(globalSlug) ? resolveBranch({
12
- req: req
13
- }) : MAIN_BRANCH;
11
+ const versionBranch = req?.payload?.config?.branching?.branchableGlobals?.has(globalSlug) ? resolveBranch(req) : MAIN_BRANCH;
14
12
  const data = {
15
13
  _branch: versionBranch,
16
14
  autosave,
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/createGlobalVersion.ts"],"sourcesContent":["import type { CreateGlobalVersion } from 'payload'\n\nimport { buildVersionGlobalFields, MAIN_BRANCH, resolveBranch } 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: 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)\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":["buildVersionGlobalFields","MAIN_BRANCH","resolveBranch","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":"AAEA,SAASA,wBAAwB,EAAEC,WAAW,EAAEC,aAAa,QAAQ,UAAS;AAI9E,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,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,MAAMW;QACNL;QACAC,WAAW;IACb;IAEA,OAAOI;AACT,EAAC"}
1
+ {"version":3,"sources":["../src/createGlobalVersion.ts"],"sourcesContent":["import type { CreateGlobalVersion } from 'payload'\n\nimport { buildVersionGlobalFields, MAIN_BRANCH, resolveBranch } 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)\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":["buildVersionGlobalFields","MAIN_BRANCH","resolveBranch","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":"AAEA,SAASA,wBAAwB,EAAEC,WAAW,EAAEC,aAAa,QAAQ,UAAS;AAI9E,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,gBAAgBT,KAAKU,SAASC,QAAQC,WAAWC,mBAAmBC,IAAIhB,cAC1EP,cAAcS,OACdV;IAEJ,MAAMyB,OAAO;QACXC,SAASP;QACTb;QACAC;QACAoB,QAAQ;QACRlB;QACAG;QACAC;QACAe,SAASd;IACX;IACA,IAAI,CAACW,KAAKlB,SAAS,EAAE;QACnBkB,KAAKlB,SAAS,GAAG,IAAIsB,OAAOC,WAAW;IACzC;IAEA,MAAMC,SAAShC,yBAAyB,IAAI,CAACqB,OAAO,CAACC,MAAM,EAAEN;IAE7DX,UAAU;QACRa,SAAS,IAAI;QACbQ;QACAM;QACAC,WAAW;IACb;IAEA,MAAMC,UAAU;QACdC,SAAS,MAAM/B,WAAW,IAAI,EAAEO;QAChC,uDAAuD;QACvDyB,YAAY;IACd;IAEA,IAAI,CAACC,IAAI,GAAG,MAAMpB,MAAMqB,MAAM,CAAC;QAACZ;KAAK,EAAEQ;IAEvC,2EAA2E;IAC3E,8EAA8E;IAC9E,8EAA8E;IAC9E,MAAMjB,MAAMsB,UAAU,CACpB;QACEC,MAAM;YACJ;gBACEC,KAAK;oBACHC,KAAKL,IAAII,GAAG;gBACd;YACF;YACA;gBACEb,QAAQ;oBACNe,KAAK;gBACP;YACF;YACA;gBACEC,KAAK;oBACH;wBAAEjB,SAAS;4BAAEgB,KAAKvB;wBAAc;oBAAE;uBAC9BA,kBAAkBnB,cAAc;wBAAC;4BAAE0B,SAAS;gCAAEkB,SAAS;4BAAM;wBAAE;qBAAE,GAAG,EAAE;iBAC3E;YACH;SACD;IACH,GACA;QAAEC,QAAQ;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 +1 @@
1
- {"version":3,"file":"deleteBranchGlobal.d.ts","sourceRoot":"","sources":["../src/deleteBranchGlobal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAA;AASjD;;;;;;GAMG;AACH,eAAO,MAAM,kBAAkB,EAAE,kBAchC,CAAA"}
1
+ {"version":3,"file":"deleteBranchGlobal.d.ts","sourceRoot":"","sources":["../src/deleteBranchGlobal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAA;AAOjD;;;;;;GAMG;AACH,eAAO,MAAM,kBAAkB,EAAE,kBAUhC,CAAA"}
@@ -1,4 +1,3 @@
1
- import { MAIN_BRANCH } from 'payload';
2
1
  import { getGlobal } from './utilities/getEntity.js';
3
2
  import { getSession } from './utilities/getSession.js';
4
3
  /**
@@ -8,9 +7,6 @@ import { getSession } from './utilities/getSession.js';
8
7
  * sibling row identified by `globalType` and `_branch` — addressed directly rather than
9
8
  * through any generic delete, since no other part of Payload deletes a global.
10
9
  */ export const deleteBranchGlobal = async function deleteBranchGlobal({ branch, globalSlug, req }) {
11
- if (branch === MAIN_BRANCH) {
12
- throw new Error('Cannot delete a main global as a branch copy.');
13
- }
14
10
  const { Model } = getGlobal({
15
11
  adapter: this,
16
12
  globalSlug
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/deleteBranchGlobal.ts"],"sourcesContent":["import type { DeleteBranchGlobal } from 'payload'\n\nimport { MAIN_BRANCH } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { getGlobal } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\n\n/**\n * Drops a branch's copy of a global.\n *\n * Every global lives in one discriminated collection here, so the branch's copy is a\n * sibling row identified by `globalType` and `_branch` — addressed directly rather than\n * through any generic delete, since no other part of Payload deletes a global.\n */\nexport const deleteBranchGlobal: DeleteBranchGlobal = async function deleteBranchGlobal(\n this: MongooseAdapter,\n { branch, globalSlug, req },\n) {\n if (branch === MAIN_BRANCH) {\n throw new Error('Cannot delete a main global as a branch copy.')\n }\n\n const { Model } = getGlobal({ adapter: this, globalSlug })\n\n await Model.deleteOne(\n { _branch: branch, globalType: globalSlug },\n { session: await getSession(this, req) },\n )\n}\n"],"names":["MAIN_BRANCH","getGlobal","getSession","deleteBranchGlobal","branch","globalSlug","req","Error","Model","adapter","deleteOne","_branch","globalType","session"],"mappings":"AAEA,SAASA,WAAW,QAAQ,UAAS;AAIrC,SAASC,SAAS,QAAQ,2BAA0B;AACpD,SAASC,UAAU,QAAQ,4BAA2B;AAEtD;;;;;;CAMC,GACD,OAAO,MAAMC,qBAAyC,eAAeA,mBAEnE,EAAEC,MAAM,EAAEC,UAAU,EAAEC,GAAG,EAAE;IAE3B,IAAIF,WAAWJ,aAAa;QAC1B,MAAM,IAAIO,MAAM;IAClB;IAEA,MAAM,EAAEC,KAAK,EAAE,GAAGP,UAAU;QAAEQ,SAAS,IAAI;QAAEJ;IAAW;IAExD,MAAMG,MAAME,SAAS,CACnB;QAAEC,SAASP;QAAQQ,YAAYP;IAAW,GAC1C;QAAEQ,SAAS,MAAMX,WAAW,IAAI,EAAEI;IAAK;AAE3C,EAAC"}
1
+ {"version":3,"sources":["../src/deleteBranchGlobal.ts"],"sourcesContent":["import type { DeleteBranchGlobal } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { getGlobal } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\n\n/**\n * Drops a branch's copy of a global.\n *\n * Every global lives in one discriminated collection here, so the branch's copy is a\n * sibling row identified by `globalType` and `_branch` — addressed directly rather than\n * through any generic delete, since no other part of Payload deletes a global.\n */\nexport const deleteBranchGlobal: DeleteBranchGlobal = async function deleteBranchGlobal(\n this: MongooseAdapter,\n { branch, globalSlug, req },\n) {\n const { Model } = getGlobal({ adapter: this, globalSlug })\n\n await Model.deleteOne(\n { _branch: branch, globalType: globalSlug },\n { session: await getSession(this, req) },\n )\n}\n"],"names":["getGlobal","getSession","deleteBranchGlobal","branch","globalSlug","req","Model","adapter","deleteOne","_branch","globalType","session"],"mappings":"AAIA,SAASA,SAAS,QAAQ,2BAA0B;AACpD,SAASC,UAAU,QAAQ,4BAA2B;AAEtD;;;;;;CAMC,GACD,OAAO,MAAMC,qBAAyC,eAAeA,mBAEnE,EAAEC,MAAM,EAAEC,UAAU,EAAEC,GAAG,EAAE;IAE3B,MAAM,EAAEC,KAAK,EAAE,GAAGN,UAAU;QAAEO,SAAS,IAAI;QAAEH;IAAW;IAExD,MAAME,MAAME,SAAS,CACnB;QAAEC,SAASN;QAAQO,YAAYN;IAAW,GAC1C;QAAEO,SAAS,MAAMV,WAAW,IAAI,EAAEI;IAAK;AAE3C,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"findGlobal.d.ts","sourceRoot":"","sources":["../src/findGlobal.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAkB,MAAM,SAAS,CAAA;AAmBzD,eAAO,MAAM,UAAU,EAAE,UA6DxB,CAAA"}
1
+ {"version":3,"file":"findGlobal.d.ts","sourceRoot":"","sources":["../src/findGlobal.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAkB,MAAM,SAAS,CAAA;AAmBzD,eAAO,MAAM,UAAU,EAAE,UAuDxB,CAAA"}
@@ -29,26 +29,18 @@ export const findGlobal = async function findGlobal({ slug: globalSlug, branch,
29
29
  }
30
30
  }, branchedWhere ?? {})
31
31
  });
32
- const projection = buildProjectionFromSelect({
33
- adapter: this,
34
- fields,
35
- select: withBranchGlobalSelect({
36
- branch,
37
- globalSlug,
38
- req,
39
- select
40
- })
41
- });
42
- if (projection && branchGlobalNeedsBothRows({
43
- branch,
44
- globalSlug,
45
- req
46
- })) {
47
- projection._branch = true;
48
- }
49
32
  const options = {
50
33
  lean: true,
51
- select: projection,
34
+ select: buildProjectionFromSelect({
35
+ adapter: this,
36
+ fields,
37
+ select: withBranchGlobalSelect({
38
+ branch,
39
+ globalSlug,
40
+ req,
41
+ select
42
+ })
43
+ }),
52
44
  session: await getSession(this, req)
53
45
  };
54
46
  // A global is one document, so the branch's row and main's row can be fetched
@@ -64,9 +56,7 @@ export const findGlobal = async function findGlobal({ slug: globalSlug, branch,
64
56
  ...options,
65
57
  limit: 2
66
58
  }).lean();
67
- doc = pickBranchGlobal(rows, branch || resolveBranch({
68
- req: req
69
- }));
59
+ doc = pickBranchGlobal(rows, branch || resolveBranch(req));
70
60
  } else {
71
61
  doc = await Model.findOne(query, {}, options).lean();
72
62
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/findGlobal.ts"],"sourcesContent":["import type { QueryOptions } from 'mongoose'\nimport type { FindGlobal, FindGlobalArgs } from 'payload'\n\nimport {\n branchGlobalNeedsBothRows,\n combineQueries,\n pickBranchGlobal,\n resolveBranch,\n resolveBranchGlobalQuery,\n withBranchGlobalSelect,\n} from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getGlobal } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\nimport { transform } from './utilities/transform.js'\n\nexport const findGlobal: FindGlobal = async function findGlobal<T extends Record<string, unknown>>(\n this: MongooseAdapter,\n { slug: globalSlug, branch, locale, req, select, where = {} }: FindGlobalArgs,\n) {\n const { globalConfig, Model } = getGlobal({ adapter: this, globalSlug })\n\n const fields = globalConfig.flattenedFields\n\n const branchedWhere = resolveBranchGlobalQuery({ branch, globalSlug, req, where })\n\n const query = await buildQuery({\n adapter: this,\n branch,\n fields,\n globalSlug,\n locale,\n req,\n where: combineQueries({ globalType: { equals: globalSlug } }, branchedWhere ?? {}),\n })\n\n const projection = buildProjectionFromSelect({\n adapter: this,\n fields,\n select: withBranchGlobalSelect({ branch, globalSlug, req, select }),\n })\n\n if (projection && branchGlobalNeedsBothRows({ branch, globalSlug, req })) {\n projection._branch = true\n }\n\n const options: QueryOptions = {\n lean: true,\n select: projection,\n session: await getSession(this, req),\n }\n\n // A global is one document, so the branch's row and main's row can be fetched\n // together and the branch's preferred in memory. There is no result set to\n // paginate, so nothing a post-query step could get wrong.\n let doc: T | undefined\n\n if (branchGlobalNeedsBothRows({ branch, globalSlug, req })) {\n const rows = await Model.find(query, {}, { ...options, limit: 2 }).lean<T[]>()\n\n doc = pickBranchGlobal(rows, branch || resolveBranch({ req: req as never }))\n } else {\n doc = (await Model.findOne(query, {}, options).lean<T>()) as T\n }\n\n if (!doc) {\n return null as unknown as T\n }\n\n transform({\n adapter: this,\n data: doc,\n fields: globalConfig.fields,\n operation: 'read',\n })\n\n return doc\n}\n"],"names":["branchGlobalNeedsBothRows","combineQueries","pickBranchGlobal","resolveBranch","resolveBranchGlobalQuery","withBranchGlobalSelect","buildQuery","buildProjectionFromSelect","getGlobal","getSession","transform","findGlobal","slug","globalSlug","branch","locale","req","select","where","globalConfig","Model","adapter","fields","flattenedFields","branchedWhere","query","globalType","equals","projection","_branch","options","lean","session","doc","rows","find","limit","findOne","data","operation"],"mappings":"AAGA,SACEA,yBAAyB,EACzBC,cAAc,EACdC,gBAAgB,EAChBC,aAAa,EACbC,wBAAwB,EACxBC,sBAAsB,QACjB,UAAS;AAIhB,SAASC,UAAU,QAAQ,0BAAyB;AACpD,SAASC,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,SAAS,QAAQ,2BAA0B;AACpD,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,SAAS,QAAQ,2BAA0B;AAEpD,OAAO,MAAMC,aAAyB,eAAeA,WAEnD,EAAEC,MAAMC,UAAU,EAAEC,MAAM,EAAEC,MAAM,EAAEC,GAAG,EAAEC,MAAM,EAAEC,QAAQ,CAAC,CAAC,EAAkB;IAE7E,MAAM,EAAEC,YAAY,EAAEC,KAAK,EAAE,GAAGZ,UAAU;QAAEa,SAAS,IAAI;QAAER;IAAW;IAEtE,MAAMS,SAASH,aAAaI,eAAe;IAE3C,MAAMC,gBAAgBpB,yBAAyB;QAAEU;QAAQD;QAAYG;QAAKE;IAAM;IAEhF,MAAMO,QAAQ,MAAMnB,WAAW;QAC7Be,SAAS,IAAI;QACbP;QACAQ;QACAT;QACAE;QACAC;QACAE,OAAOjB,eAAe;YAAEyB,YAAY;gBAAEC,QAAQd;YAAW;QAAE,GAAGW,iBAAiB,CAAC;IAClF;IAEA,MAAMI,aAAarB,0BAA0B;QAC3Cc,SAAS,IAAI;QACbC;QACAL,QAAQZ,uBAAuB;YAAES;YAAQD;YAAYG;YAAKC;QAAO;IACnE;IAEA,IAAIW,cAAc5B,0BAA0B;QAAEc;QAAQD;QAAYG;IAAI,IAAI;QACxEY,WAAWC,OAAO,GAAG;IACvB;IAEA,MAAMC,UAAwB;QAC5BC,MAAM;QACNd,QAAQW;QACRI,SAAS,MAAMvB,WAAW,IAAI,EAAEO;IAClC;IAEA,8EAA8E;IAC9E,2EAA2E;IAC3E,0DAA0D;IAC1D,IAAIiB;IAEJ,IAAIjC,0BAA0B;QAAEc;QAAQD;QAAYG;IAAI,IAAI;QAC1D,MAAMkB,OAAO,MAAMd,MAAMe,IAAI,CAACV,OAAO,CAAC,GAAG;YAAE,GAAGK,OAAO;YAAEM,OAAO;QAAE,GAAGL,IAAI;QAEvEE,MAAM/B,iBAAiBgC,MAAMpB,UAAUX,cAAc;YAAEa,KAAKA;QAAa;IAC3E,OAAO;QACLiB,MAAO,MAAMb,MAAMiB,OAAO,CAACZ,OAAO,CAAC,GAAGK,SAASC,IAAI;IACrD;IAEA,IAAI,CAACE,KAAK;QACR,OAAO;IACT;IAEAvB,UAAU;QACRW,SAAS,IAAI;QACbiB,MAAML;QACNX,QAAQH,aAAaG,MAAM;QAC3BiB,WAAW;IACb;IAEA,OAAON;AACT,EAAC"}
1
+ {"version":3,"sources":["../src/findGlobal.ts"],"sourcesContent":["import type { QueryOptions } from 'mongoose'\nimport type { FindGlobal, FindGlobalArgs } from 'payload'\n\nimport {\n branchGlobalNeedsBothRows,\n combineQueries,\n pickBranchGlobal,\n resolveBranch,\n resolveBranchGlobalQuery,\n withBranchGlobalSelect,\n} from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getGlobal } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\nimport { transform } from './utilities/transform.js'\n\nexport const findGlobal: FindGlobal = async function findGlobal<T extends Record<string, unknown>>(\n this: MongooseAdapter,\n { slug: globalSlug, branch, locale, req, select, where = {} }: FindGlobalArgs,\n) {\n const { globalConfig, Model } = getGlobal({ adapter: this, globalSlug })\n\n const fields = globalConfig.flattenedFields\n\n const branchedWhere = resolveBranchGlobalQuery({ branch, globalSlug, req, where })\n\n const query = await buildQuery({\n adapter: this,\n branch,\n fields,\n globalSlug,\n locale,\n req,\n where: combineQueries({ globalType: { equals: globalSlug } }, branchedWhere ?? {}),\n })\n\n const options: QueryOptions = {\n lean: true,\n select: buildProjectionFromSelect({\n adapter: this,\n fields,\n select: withBranchGlobalSelect({ branch, globalSlug, req, select }),\n }),\n session: await getSession(this, req),\n }\n\n // A global is one document, so the branch's row and main's row can be fetched\n // together and the branch's preferred in memory. There is no result set to\n // paginate, so nothing a post-query step could get wrong.\n let doc: T | undefined\n\n if (branchGlobalNeedsBothRows({ branch, globalSlug, req })) {\n const rows = await Model.find(query, {}, { ...options, limit: 2 }).lean<T[]>()\n\n doc = pickBranchGlobal(rows, branch || resolveBranch(req as never))\n } else {\n doc = (await Model.findOne(query, {}, options).lean<T>()) as T\n }\n\n if (!doc) {\n return null as unknown as T\n }\n\n transform({\n adapter: this,\n data: doc,\n fields: globalConfig.fields,\n operation: 'read',\n })\n\n return doc\n}\n"],"names":["branchGlobalNeedsBothRows","combineQueries","pickBranchGlobal","resolveBranch","resolveBranchGlobalQuery","withBranchGlobalSelect","buildQuery","buildProjectionFromSelect","getGlobal","getSession","transform","findGlobal","slug","globalSlug","branch","locale","req","select","where","globalConfig","Model","adapter","fields","flattenedFields","branchedWhere","query","globalType","equals","options","lean","session","doc","rows","find","limit","findOne","data","operation"],"mappings":"AAGA,SACEA,yBAAyB,EACzBC,cAAc,EACdC,gBAAgB,EAChBC,aAAa,EACbC,wBAAwB,EACxBC,sBAAsB,QACjB,UAAS;AAIhB,SAASC,UAAU,QAAQ,0BAAyB;AACpD,SAASC,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,SAAS,QAAQ,2BAA0B;AACpD,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,SAAS,QAAQ,2BAA0B;AAEpD,OAAO,MAAMC,aAAyB,eAAeA,WAEnD,EAAEC,MAAMC,UAAU,EAAEC,MAAM,EAAEC,MAAM,EAAEC,GAAG,EAAEC,MAAM,EAAEC,QAAQ,CAAC,CAAC,EAAkB;IAE7E,MAAM,EAAEC,YAAY,EAAEC,KAAK,EAAE,GAAGZ,UAAU;QAAEa,SAAS,IAAI;QAAER;IAAW;IAEtE,MAAMS,SAASH,aAAaI,eAAe;IAE3C,MAAMC,gBAAgBpB,yBAAyB;QAAEU;QAAQD;QAAYG;QAAKE;IAAM;IAEhF,MAAMO,QAAQ,MAAMnB,WAAW;QAC7Be,SAAS,IAAI;QACbP;QACAQ;QACAT;QACAE;QACAC;QACAE,OAAOjB,eAAe;YAAEyB,YAAY;gBAAEC,QAAQd;YAAW;QAAE,GAAGW,iBAAiB,CAAC;IAClF;IAEA,MAAMI,UAAwB;QAC5BC,MAAM;QACNZ,QAAQV,0BAA0B;YAChCc,SAAS,IAAI;YACbC;YACAL,QAAQZ,uBAAuB;gBAAES;gBAAQD;gBAAYG;gBAAKC;YAAO;QACnE;QACAa,SAAS,MAAMrB,WAAW,IAAI,EAAEO;IAClC;IAEA,8EAA8E;IAC9E,2EAA2E;IAC3E,0DAA0D;IAC1D,IAAIe;IAEJ,IAAI/B,0BAA0B;QAAEc;QAAQD;QAAYG;IAAI,IAAI;QAC1D,MAAMgB,OAAO,MAAMZ,MAAMa,IAAI,CAACR,OAAO,CAAC,GAAG;YAAE,GAAGG,OAAO;YAAEM,OAAO;QAAE,GAAGL,IAAI;QAEvEE,MAAM7B,iBAAiB8B,MAAMlB,UAAUX,cAAca;IACvD,OAAO;QACLe,MAAO,MAAMX,MAAMe,OAAO,CAACV,OAAO,CAAC,GAAGG,SAASC,IAAI;IACrD;IAEA,IAAI,CAACE,KAAK;QACR,OAAO;IACT;IAEArB,UAAU;QACRW,SAAS,IAAI;QACbe,MAAML;QACNT,QAAQH,aAAaG,MAAM;QAC3Be,WAAW;IACb;IAEA,OAAON;AACT,EAAC"}
@@ -1,4 +1,4 @@
1
1
  declare const imports = "import { migrateBranching } from '@payloadcms/db-mongodb/migration-utils'";
2
- declare const upSQL = " // Index synchronization must run outside the migration transaction.\n await migrateBranching({\n payload,\n })\n";
2
+ declare const upSQL = " await migrateBranching({\n payload,\n session,\n })\n";
3
3
  export { imports, upSQL };
4
4
  //# sourceMappingURL=branching.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"branching.d.ts","sourceRoot":"","sources":["../../src/predefinedMigrations/branching.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,OAAO,8EAA8E,CAAA;AAC3F,QAAA,MAAM,KAAK,6HAIV,CAAA;AAED,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAA"}
1
+ {"version":3,"file":"branching.d.ts","sourceRoot":"","sources":["../../src/predefinedMigrations/branching.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,OAAO,8EAA8E,CAAA;AAC3F,QAAA,MAAM,KAAK,mEAIV,CAAA;AAED,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAA"}
@@ -1,7 +1,7 @@
1
1
  const imports = `import { migrateBranching } from '@payloadcms/db-mongodb/migration-utils'`;
2
- const upSQL = ` // Index synchronization must run outside the migration transaction.
3
- await migrateBranching({
2
+ const upSQL = ` await migrateBranching({
4
3
  payload,
4
+ session,
5
5
  })
6
6
  `;
7
7
  export { imports, upSQL };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/predefinedMigrations/branching.ts"],"sourcesContent":["const imports = `import { migrateBranching } from '@payloadcms/db-mongodb/migration-utils'`\nconst upSQL = ` // Index synchronization must run outside the migration transaction.\n await migrateBranching({\n payload,\n })\n`\n\nexport { imports, upSQL }\n"],"names":["imports","upSQL"],"mappings":"AAAA,MAAMA,UAAU,CAAC,yEAAyE,CAAC;AAC3F,MAAMC,QAAQ,CAAC;;;;AAIf,CAAC;AAED,SAASD,OAAO,EAAEC,KAAK,GAAE"}
1
+ {"version":3,"sources":["../../src/predefinedMigrations/branching.ts"],"sourcesContent":["const imports = `import { migrateBranching } from '@payloadcms/db-mongodb/migration-utils'`\nconst upSQL = ` await migrateBranching({\n payload,\n session,\n })\n`\n\nexport { imports, upSQL }\n"],"names":["imports","upSQL"],"mappings":"AAAA,MAAMA,UAAU,CAAC,yEAAyE,CAAC;AAC3F,MAAMC,QAAQ,CAAC;;;;AAIf,CAAC;AAED,SAASD,OAAO,EAAEC,KAAK,GAAE"}
@@ -9,8 +9,6 @@ type BranchingMigrationArgs = {
9
9
  *
10
10
  * Run this generated migration after enabling branching. Backfill errors stop the migration
11
11
  * before any indexes are removed, so uniqueness conflicts remain visible and recoverable.
12
- * Index synchronization removes indexes not declared in the configured Mongoose schema;
13
- * declare user-managed indexes in that schema before running this migration.
14
12
  */
15
13
  export declare const migrateBranching: ({ payload, session, }: BranchingMigrationArgs) => Promise<void>;
16
14
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"migrateBranching.d.ts","sourceRoot":"","sources":["../../src/predefinedMigrations/migrateBranching.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAC7C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAOtC,KAAK,sBAAsB,GAAG;IAC5B,OAAO,EAAE,OAAO,CAAA;IAChB,OAAO,CAAC,EAAE,aAAa,CAAA;CACxB,CAAA;AAQD;;;;;;;GAOG;AACH,eAAO,MAAM,gBAAgB,0BAG1B,sBAAsB,KAAG,OAAO,CAAC,IAAI,CAqEvC,CAAA"}
1
+ {"version":3,"file":"migrateBranching.d.ts","sourceRoot":"","sources":["../../src/predefinedMigrations/migrateBranching.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAC7C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAOtC,KAAK,sBAAsB,GAAG;IAC5B,OAAO,EAAE,OAAO,CAAA;IAChB,OAAO,CAAC,EAAE,aAAa,CAAA;CACxB,CAAA;AAQD;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,0BAG1B,sBAAsB,KAAG,OAAO,CAAC,IAAI,CAqEvC,CAAA"}
@@ -16,8 +16,6 @@ const legacyMainFilter = {
16
16
  *
17
17
  * Run this generated migration after enabling branching. Backfill errors stop the migration
18
18
  * before any indexes are removed, so uniqueness conflicts remain visible and recoverable.
19
- * Index synchronization removes indexes not declared in the configured Mongoose schema;
20
- * declare user-managed indexes in that schema before running this migration.
21
19
  */ export const migrateBranching = async ({ payload, session })=>{
22
20
  const branching = payload.config.branching;
23
21
  if (!branching?.enabled) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/predefinedMigrations/migrateBranching.ts"],"sourcesContent":["import type { ClientSession } from 'mongoose'\nimport type { Payload } from 'payload'\n\nimport { branchField, MAIN_BRANCH } from 'payload'\n\nimport type { MongooseAdapter } from '../index.js'\nimport type { CollectionModel, GlobalModel } from '../types.js'\n\ntype BranchingMigrationArgs = {\n payload: Payload\n session?: ClientSession\n}\n\ntype SyncableModel = CollectionModel | GlobalModel\n\nconst legacyMainFilter = {\n $or: [{ [branchField]: { $exists: false } }, { [branchField]: null }],\n}\n\n/**\n * Backfills branch identity before replacing legacy indexes with the current schema indexes.\n *\n * Run this generated migration after enabling branching. Backfill errors stop the migration\n * before any indexes are removed, so uniqueness conflicts remain visible and recoverable.\n * Index synchronization removes indexes not declared in the configured Mongoose schema;\n * declare user-managed indexes in that schema before running this migration.\n */\nexport const migrateBranching = async ({\n payload,\n session,\n}: BranchingMigrationArgs): Promise<void> => {\n const branching = payload.config.branching\n\n if (!branching?.enabled) {\n payload.logger.info({ msg: 'Branching is not enabled, skipping branching migration' })\n return\n }\n\n const adapter = payload.db as MongooseAdapter\n const modelsToSync = new Set<SyncableModel>()\n const updateOptions = session ? { session } : {}\n\n payload.logger.info({ msg: 'Starting branching data and index migration' })\n\n for (const collectionSlug of branching.branchableCollections) {\n const collectionModel = adapter.collections[collectionSlug]\n const versionModel = adapter.versions[collectionSlug]\n\n if (!collectionModel) {\n throw new Error(`Could not find MongoDB model for branchable collection \"${collectionSlug}\".`)\n }\n\n await collectionModel.collection.updateMany(\n legacyMainFilter,\n { $set: { [branchField]: MAIN_BRANCH } },\n updateOptions,\n )\n modelsToSync.add(collectionModel)\n\n if (versionModel) {\n await versionModel.collection.updateMany(\n legacyMainFilter,\n { $set: { [branchField]: MAIN_BRANCH } },\n updateOptions,\n )\n modelsToSync.add(versionModel)\n }\n }\n\n if (branching.branchableGlobals.size) {\n await adapter.globals.collection.updateMany(\n {\n ...legacyMainFilter,\n globalType: { $in: Array.from(branching.branchableGlobals) },\n },\n { $set: { [branchField]: MAIN_BRANCH } },\n updateOptions,\n )\n modelsToSync.add(adapter.globals)\n\n for (const globalSlug of branching.branchableGlobals) {\n const versionModel = adapter.versions[globalSlug]\n\n if (versionModel) {\n await versionModel.collection.updateMany(\n legacyMainFilter,\n { $set: { [branchField]: MAIN_BRANCH } },\n updateOptions,\n )\n modelsToSync.add(versionModel)\n }\n }\n }\n\n for (const model of modelsToSync) {\n await model.syncIndexes()\n }\n\n payload.logger.info({ msg: 'Branching data and index migration completed successfully' })\n}\n"],"names":["branchField","MAIN_BRANCH","legacyMainFilter","$or","$exists","migrateBranching","payload","session","branching","config","enabled","logger","info","msg","adapter","db","modelsToSync","Set","updateOptions","collectionSlug","branchableCollections","collectionModel","collections","versionModel","versions","Error","collection","updateMany","$set","add","branchableGlobals","size","globals","globalType","$in","Array","from","globalSlug","model","syncIndexes"],"mappings":"AAGA,SAASA,WAAW,EAAEC,WAAW,QAAQ,UAAS;AAYlD,MAAMC,mBAAmB;IACvBC,KAAK;QAAC;YAAE,CAACH,YAAY,EAAE;gBAAEI,SAAS;YAAM;QAAE;QAAG;YAAE,CAACJ,YAAY,EAAE;QAAK;KAAE;AACvE;AAEA;;;;;;;CAOC,GACD,OAAO,MAAMK,mBAAmB,OAAO,EACrCC,OAAO,EACPC,OAAO,EACgB;IACvB,MAAMC,YAAYF,QAAQG,MAAM,CAACD,SAAS;IAE1C,IAAI,CAACA,WAAWE,SAAS;QACvBJ,QAAQK,MAAM,CAACC,I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MAAMA,aAAaG,UAAU,CAACC,UAAU,CACtCzB,kBACA;oBAAE0B,MAAM;wBAAE,CAAC5B,YAAY,EAAEC;oBAAY;gBAAE,GACvCiB;gBAEFF,aAAaa,GAAG,CAACN;YACnB;QACF;IACF;IAEA,KAAK,MAAMe,SAAStB,aAAc;QAChC,MAAMsB,MAAMC,WAAW;IACzB;IAEAjC,QAAQK,MAAM,CAACC,IAAI,CAAC;QAAEC,KAAK;IAA4D;AACzF,EAAC"}
1
+ {"version":3,"sources":["../../src/predefinedMigrations/migrateBranching.ts"],"sourcesContent":["import type { ClientSession } from 'mongoose'\nimport type { Payload } from 'payload'\n\nimport { branchField, MAIN_BRANCH } from 'payload'\n\nimport type { MongooseAdapter } from '../index.js'\nimport type { CollectionModel, GlobalModel } from '../types.js'\n\ntype BranchingMigrationArgs = {\n payload: Payload\n session?: ClientSession\n}\n\ntype SyncableModel = CollectionModel | GlobalModel\n\nconst legacyMainFilter = {\n $or: [{ [branchField]: { $exists: false } }, { [branchField]: null }],\n}\n\n/**\n * Backfills branch identity before replacing legacy indexes with the current schema indexes.\n *\n * Run this generated migration after enabling branching. Backfill errors stop the migration\n * before any indexes are removed, so uniqueness conflicts remain visible and recoverable.\n */\nexport const migrateBranching = async ({\n payload,\n session,\n}: BranchingMigrationArgs): Promise<void> => {\n const branching = payload.config.branching\n\n if (!branching?.enabled) {\n payload.logger.info({ msg: 'Branching is not enabled, skipping branching migration' })\n return\n }\n\n const adapter = payload.db as MongooseAdapter\n const modelsToSync = new Set<SyncableModel>()\n const updateOptions = session ? { session } : {}\n\n payload.logger.info({ msg: 'Starting branching data and index migration' })\n\n for (const collectionSlug of branching.branchableCollections) {\n const collectionModel = adapter.collections[collectionSlug]\n const versionModel = adapter.versions[collectionSlug]\n\n if (!collectionModel) {\n throw new Error(`Could not find MongoDB model for branchable collection \"${collectionSlug}\".`)\n }\n\n await collectionModel.collection.updateMany(\n legacyMainFilter,\n { $set: { [branchField]: MAIN_BRANCH } },\n updateOptions,\n )\n modelsToSync.add(collectionModel)\n\n if (versionModel) {\n await versionModel.collection.updateMany(\n legacyMainFilter,\n { $set: { [branchField]: MAIN_BRANCH } },\n updateOptions,\n )\n modelsToSync.add(versionModel)\n }\n }\n\n if (branching.branchableGlobals.size) {\n await adapter.globals.collection.updateMany(\n {\n ...legacyMainFilter,\n globalType: { $in: Array.from(branching.branchableGlobals) },\n },\n { $set: { [branchField]: MAIN_BRANCH } },\n updateOptions,\n )\n modelsToSync.add(adapter.globals)\n\n for (const globalSlug of branching.branchableGlobals) {\n const versionModel = adapter.versions[globalSlug]\n\n if (versionModel) {\n await versionModel.collection.updateMany(\n legacyMainFilter,\n { $set: { [branchField]: MAIN_BRANCH } },\n updateOptions,\n )\n modelsToSync.add(versionModel)\n }\n }\n }\n\n for (const model of modelsToSync) {\n await model.syncIndexes()\n }\n\n payload.logger.info({ msg: 'Branching data and index migration completed successfully' })\n}\n"],"names":["branchField","MAIN_BRANCH","legacyMainFilter","$or","$exists","migrateBranching","payload","session","branching","config","enabled","logger","info","msg","adapter","db","modelsToSync","Set","updateOptions","collectionSlug","branchableCollections","collectionModel","collections","versionModel","versions","Error","collection","updateMany","$set","add","branchableGlobals","size","globals","globalType","$in","Array","from","globalSlug","model","syncIndexes"],"mappings":"AAGA,SAASA,WAAW,EAAEC,WAAW,QAAQ,UAAS;AAYlD,MAAMC,mBAAmB;IACvBC,KAAK;QAAC;YAAE,CAACH,YAAY,EAAE;gBAAEI,SAAS;YAAM;QAAE;QAAG;YAAE,CAACJ,YAAY,EAAE;QAAK;KAAE;AACvE;AAEA;;;;;CAKC,GACD,OAAO,MAAMK,mBAAmB,OAAO,EACrCC,OAAO,EACPC,OAAO,EACgB;IACvB,MAAMC,YAAYF,QAAQG,MAAM,CAACD,SAAS;IAE1C,IAAI,CAACA,WAAWE,SAAS;QACvBJ,QAAQK,MAAM,CAACC,IAAI,CAAC;YAAEC,KAAK;QAAyD;QACpF;IACF;IAEA,MAAMC,UAAUR,QAAQS,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CAAC5B,YAAY,EAAEC;oBAAY;gBAAE,GACvCiB;gBAEFF,aAAaa,GAAG,CAACN;YACnB;QACF;IACF;IAEA,KAAK,MAAMe,SAAStB,aAAc;QAChC,MAAMsB,MAAMC,WAAW;IACzB;IAEAjC,QAAQK,MAAM,CAACC,IAAI,CAAC;QAAEC,KAAK;IAA4D;AACzF,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"buildSearchParams.d.ts","sourceRoot":"","sources":["../../src/queries/buildSearchParams.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,cAAc,EAEd,QAAQ,EAER,OAAO,EACP,cAAc,EAEf,MAAM,SAAS,CAAA;AA6BhB,KAAK,WAAW,GAAG;IACjB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,KAAK,CAAC,EAAE,OAAO,CAAA;CAChB,CAAA;AAED;;GAEG;AACH,wBAAsB,gBAAgB,CAAC,EACrC,MAAM,EACN,cAAc,EACd,MAAM,EACN,UAAU,EACV,YAAY,EACZ,MAAM,EACN,QAAQ,EACR,iBAAiB,EACjB,OAAO,EACP,GAAG,EACH,GAAG,GACJ,EAAE;IACD,MAAM,CAAC,EAAE,KAAK,GAAG,MAAM,CAAA;IACvB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,MAAM,EAAE,cAAc,EAAE,CAAA;IACxB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,YAAY,EAAE,MAAM,CAAA;IACpB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,QAAQ,EAAE,QAAQ,CAAA;IAClB,iBAAiB,EAAE,OAAO,CAAA;IAC1B,OAAO,EAAE,OAAO,CAAA;IAChB,GAAG,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC,CAAA;IAC7B,GAAG,EAAE,OAAO,CAAA;CACb,GAAG,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC,CA2bnC"}
1
+ {"version":3,"file":"buildSearchParams.d.ts","sourceRoot":"","sources":["../../src/queries/buildSearchParams.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,cAAc,EAEd,QAAQ,EAER,OAAO,EACP,cAAc,EAEf,MAAM,SAAS,CAAA;AA4BhB,KAAK,WAAW,GAAG;IACjB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,KAAK,CAAC,EAAE,OAAO,CAAA;CAChB,CAAA;AA2ED;;GAEG;AACH,wBAAsB,gBAAgB,CAAC,EACrC,MAAM,EACN,cAAc,EACd,MAAM,EACN,UAAU,EACV,YAAY,EACZ,MAAM,EACN,QAAQ,EACR,iBAAiB,EACjB,OAAO,EACP,GAAG,EACH,GAAG,GACJ,EAAE;IACD,MAAM,CAAC,EAAE,KAAK,GAAG,MAAM,CAAA;IACvB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,MAAM,EAAE,cAAc,EAAE,CAAA;IACxB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,YAAY,EAAE,MAAM,CAAA;IACpB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,QAAQ,EAAE,QAAQ,CAAA;IAClB,iBAAiB,EAAE,OAAO,CAAA;IAC1B,OAAO,EAAE,OAAO,CAAA;IAChB,GAAG,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC,CAAA;IAC7B,GAAG,EAAE,OAAO,CAAA;CACb,GAAG,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC,CA2bnC"}
@@ -4,9 +4,68 @@ import { hasManyRelationshipOperatorSet, isNestedRelationshipQuery, validOperato
4
4
  import { getCollection } from '../utilities/getEntity.js';
5
5
  import { isObjectID } from '../utilities/isObjectID.js';
6
6
  import { buildBranchVisibilityStages } from './buildBranchVisibility.js';
7
- import { buildRelatedQueryPipeline } from './buildRelatedQueryPipeline.js';
8
7
  import { operatorMap } from './operatorMap.js';
9
8
  import { sanitizeQueryValue } from './sanitizeQueryValue.js';
9
+ const resolveRelatedBranchQuery = async ({ branch, collectionSlug, payload, req, where })=>{
10
+ const adapter = payload.db;
11
+ const branchReadState = resolveBranchReadState({
12
+ branch,
13
+ collectionSlug,
14
+ req
15
+ });
16
+ const resolvedWhere = branchReadState.useBranching ? rewriteBranchIDs(where) : await resolveBranchQuery({
17
+ branch,
18
+ collectionSlug,
19
+ req,
20
+ where
21
+ });
22
+ return {
23
+ branchVisibility: branchReadState.useBranching ? buildBranchVisibilityStages({
24
+ adapter,
25
+ branch: branchReadState.branch,
26
+ collectionSlug
27
+ }) : [],
28
+ where: resolvedWhere ?? {}
29
+ };
30
+ };
31
+ const findRelatedDocuments = async ({ branchVisibility, Model, projection, query })=>{
32
+ if (branchVisibility.length) {
33
+ return Model.aggregate([
34
+ {
35
+ $match: query
36
+ },
37
+ ...branchVisibility,
38
+ {
39
+ $project: projection
40
+ }
41
+ ]);
42
+ }
43
+ return Model.find(query).lean().select(projection);
44
+ };
45
+ const findRelatedDistinctValues = async ({ branchVisibility, Model, path, query })=>{
46
+ if (!branchVisibility.length) {
47
+ return Model.distinct(path, query);
48
+ }
49
+ return Model.aggregate([
50
+ {
51
+ $match: query
52
+ },
53
+ ...branchVisibility,
54
+ {
55
+ $project: {
56
+ value: `$${path}`
57
+ }
58
+ },
59
+ {
60
+ $unwind: '$value'
61
+ },
62
+ {
63
+ $group: {
64
+ _id: '$value'
65
+ }
66
+ }
67
+ ]).then((results)=>results.map(({ _id })=>_id));
68
+ };
10
69
  /**
11
70
  * Convert the Payload key / value / operator into a MongoDB query
12
71
  */ export async function buildSearchParam({ branch, collectionSlug, fields, globalSlug, incomingPath, locale, operator, parentIsLocalized, payload, req, val }) {
@@ -554,65 +613,5 @@ import { sanitizeQueryValue } from './sanitizeQueryValue.js';
554
613
  }
555
614
  };
556
615
  }
557
- const resolveRelatedBranchQuery = async ({ branch, collectionSlug, payload, req, where })=>{
558
- const adapter = payload.db;
559
- const branchReadState = resolveBranchReadState({
560
- branch,
561
- collectionSlug,
562
- req
563
- });
564
- const resolvedWhere = branchReadState.useBranching ? rewriteBranchIDs(where) : await resolveBranchQuery({
565
- branch,
566
- collectionSlug,
567
- req,
568
- where
569
- });
570
- return {
571
- branchVisibility: branchReadState.useBranching ? buildBranchVisibilityStages({
572
- adapter,
573
- branch: branchReadState.branch,
574
- collectionSlug
575
- }) : [],
576
- where: resolvedWhere ?? {}
577
- };
578
- };
579
- const findRelatedDocuments = async ({ branchVisibility, Model, projection, query })=>{
580
- if (branchVisibility.length) {
581
- return Model.aggregate([
582
- ...buildRelatedQueryPipeline({
583
- branchVisibility,
584
- query
585
- }),
586
- {
587
- $project: projection
588
- }
589
- ]);
590
- }
591
- return Model.find(query).lean().select(projection);
592
- };
593
- const findRelatedDistinctValues = async ({ branchVisibility, Model, path, query })=>{
594
- if (!branchVisibility.length) {
595
- return Model.distinct(path, query);
596
- }
597
- return Model.aggregate([
598
- ...buildRelatedQueryPipeline({
599
- branchVisibility,
600
- query
601
- }),
602
- {
603
- $project: {
604
- value: `$${path}`
605
- }
606
- },
607
- {
608
- $unwind: '$value'
609
- },
610
- {
611
- $group: {
612
- _id: '$value'
613
- }
614
- }
615
- ]).then((results)=>results.map(({ _id })=>_id));
616
- };
617
616
 
618
617
  //# sourceMappingURL=buildSearchParams.js.map