@payloadcms/db-mongodb 4.0.0-internal.e55ccef → 4.0.0-internal.f05c47f
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.
- package/dist/count.d.ts.map +1 -1
- package/dist/count.js +8 -2
- package/dist/count.js.map +1 -1
- package/dist/createGlobalVersion.d.ts.map +1 -1
- package/dist/createGlobalVersion.js +22 -0
- package/dist/createGlobalVersion.js.map +1 -1
- package/dist/createVersion.d.ts.map +1 -1
- package/dist/createVersion.js +16 -3
- package/dist/createVersion.js.map +1 -1
- package/dist/deleteOne.d.ts.map +1 -1
- package/dist/deleteOne.js +18 -1
- package/dist/deleteOne.js.map +1 -1
- package/dist/find.d.ts.map +1 -1
- package/dist/find.js +16 -3
- package/dist/find.js.map +1 -1
- package/dist/findGlobal.d.ts.map +1 -1
- package/dist/findGlobal.js +26 -4
- package/dist/findGlobal.js.map +1 -1
- package/dist/findGlobalVersions.d.ts.map +1 -1
- package/dist/findGlobalVersions.js +8 -2
- package/dist/findGlobalVersions.js.map +1 -1
- package/dist/findOne.d.ts.map +1 -1
- package/dist/findOne.js +18 -2
- package/dist/findOne.js.map +1 -1
- package/dist/queries/buildSortParam.spec.js +1 -1
- package/dist/queries/buildSortParam.spec.js.map +1 -1
- package/dist/queries/getLocalizedSortProperty.spec.js +1 -1
- package/dist/queries/getLocalizedSortProperty.spec.js.map +1 -1
- package/dist/queryDrafts.d.ts.map +1 -1
- package/dist/queryDrafts.js +11 -3
- package/dist/queryDrafts.js.map +1 -1
- package/dist/updateGlobal.d.ts.map +1 -1
- package/dist/updateGlobal.js +60 -7
- package/dist/updateGlobal.js.map +1 -1
- package/dist/updateJobs.d.ts.map +1 -1
- package/dist/updateJobs.js +70 -13
- package/dist/updateJobs.js.map +1 -1
- package/dist/updateOne.d.ts.map +1 -1
- package/dist/updateOne.js +10 -1
- package/dist/updateOne.js.map +1 -1
- package/dist/utilities/buildJoinAggregation.d.ts +3 -2
- package/dist/utilities/buildJoinAggregation.d.ts.map +1 -1
- package/dist/utilities/buildJoinAggregation.js +31 -4
- package/dist/utilities/buildJoinAggregation.js.map +1 -1
- package/dist/utilities/resolveJoins.d.ts +4 -2
- package/dist/utilities/resolveJoins.d.ts.map +1 -1
- package/dist/utilities/resolveJoins.js +16 -2
- package/dist/utilities/resolveJoins.js.map +1 -1
- package/dist/utilities/transform.d.ts.map +1 -1
- package/dist/utilities/transform.js +15 -0
- package/dist/utilities/transform.js.map +1 -1
- package/dist/utilities/transform.spec.js +67 -0
- package/dist/utilities/transform.spec.js.map +1 -1
- package/package.json +4 -4
package/dist/count.d.ts.map
CHANGED
|
@@ -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,
|
|
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"}
|
package/dist/count.js
CHANGED
|
@@ -1,12 +1,18 @@
|
|
|
1
|
-
import { flattenWhereToOperators } from 'payload';
|
|
1
|
+
import { flattenWhereToOperators, resolveBranchQuery } 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({ collection: collectionSlug, locale, req, where = {} }) {
|
|
5
|
+
export const count = async function count({ branch, 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
|
+
}) ?? {};
|
|
10
16
|
let hasNearConstraint = false;
|
|
11
17
|
if (where) {
|
|
12
18
|
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 } 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;
|
|
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,MAAM,EAAEC,GAAG,EAAEC,QAAQ,CAAC,CAAC,EAAE;IAE/D,MAAM,EAAEC,gBAAgB,EAAEC,KAAK,EAAE,GAAGV,cAAc;QAAEW,SAAS,IAAI;QAAEN;IAAe;IAElFG,QAAQ,AAAC,MAAMV,mBAAmB;QAAEK;QAAQE;QAAgBE;QAAKC;IAAM,MAAO,CAAC;IAE/E,IAAII,oBAAoB;IAExB,IAAIJ,OAAO;QACT,MAAMK,cAAchB,wBAAwBW;QAC5CI,oBAAoBC,YAAYC,IAAI,CAAC,CAACC,OAASC,OAAOC,IAAI,CAACF,MAAMD,IAAI,CAAC,CAACI,MAAQA,QAAQ;IACzF;IAEA,MAAMC,QAAQ,MAAMpB,WAAW;QAC7BY,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,MAAMxB,WAAW,IAAI,EAAEM;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":"createGlobalVersion.d.ts","sourceRoot":"","sources":["../src/createGlobalVersion.ts"],"names":[],"mappings":"
|
|
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,3 +1,4 @@
|
|
|
1
|
+
import { MAIN_BRANCH, resolveBranch } from 'payload';
|
|
1
2
|
import { buildVersionGlobalFields } from 'payload';
|
|
2
3
|
import { getGlobal } from './utilities/getEntity.js';
|
|
3
4
|
import { getSession } from './utilities/getSession.js';
|
|
@@ -8,7 +9,9 @@ export const createGlobalVersion = async function createGlobalVersion({ autosave
|
|
|
8
9
|
globalSlug,
|
|
9
10
|
versions: true
|
|
10
11
|
});
|
|
12
|
+
const versionBranch = req?.payload?.config?.branching?.branchableGlobals?.has(globalSlug) ? resolveBranch(req) : MAIN_BRANCH;
|
|
11
13
|
const data = {
|
|
14
|
+
_branch: versionBranch,
|
|
12
15
|
autosave,
|
|
13
16
|
createdAt,
|
|
14
17
|
latest: true,
|
|
@@ -35,6 +38,9 @@ export const createGlobalVersion = async function createGlobalVersion({ autosave
|
|
|
35
38
|
let [doc] = await Model.create([
|
|
36
39
|
data
|
|
37
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.
|
|
38
44
|
await Model.updateMany({
|
|
39
45
|
$and: [
|
|
40
46
|
{
|
|
@@ -46,6 +52,22 @@ export const createGlobalVersion = async function createGlobalVersion({ autosave
|
|
|
46
52
|
latest: {
|
|
47
53
|
$eq: true
|
|
48
54
|
}
|
|
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
|
+
]
|
|
49
71
|
}
|
|
50
72
|
]
|
|
51
73
|
}, {
|
|
@@ -1 +1 @@
|
|
|
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, req)\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","
|
|
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,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,cAC1ER,cAAcU,OACdX;IAEJ,MAAM0B,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,SAAS9B,yBAAyB,IAAI,CAACmB,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,SAASvB;IAEhD,2EAA2E;IAC3E,8EAA8E;IAC9E,8EAA8E;IAC9E,MAAMM,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,kBAAkBpB,cAAc;wBAAC;4BAAE2B,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":"createVersion.d.ts","sourceRoot":"","sources":["../src/createVersion.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
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"}
|
package/dist/createVersion.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { buildVersionCollectionFields } from 'payload';
|
|
1
|
+
import { buildVersionCollectionFields, resolveBranchVersionParent } 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,15 +8,25 @@ 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
|
+
});
|
|
11
17
|
const data = {
|
|
12
18
|
autosave,
|
|
13
19
|
createdAt,
|
|
14
20
|
latest: true,
|
|
15
|
-
parent,
|
|
21
|
+
parent: branched.parent,
|
|
16
22
|
publishedLocale,
|
|
17
23
|
snapshot,
|
|
18
24
|
updatedAt,
|
|
19
|
-
version: versionData
|
|
25
|
+
version: versionData,
|
|
26
|
+
...branched.versionData._branch ? {
|
|
27
|
+
_branch: branched.versionData._branch,
|
|
28
|
+
_branchParent: branched.versionData._branchParent
|
|
29
|
+
} : {}
|
|
20
30
|
};
|
|
21
31
|
if (!data.createdAt) {
|
|
22
32
|
data.createdAt = new Date().toISOString();
|
|
@@ -36,6 +46,9 @@ export const createVersion = async function createVersion({ autosave, collection
|
|
|
36
46
|
let [doc] = await Model.create([
|
|
37
47
|
data
|
|
38
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.
|
|
39
52
|
const parentQuery = {
|
|
40
53
|
$or: [
|
|
41
54
|
{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/createVersion.ts"],"sourcesContent":["import {
|
|
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":"AAA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;YACH;gBACE7B,QAAQ;oBACN8B,KAAKlB,KAAKZ,MAAM;gBAClB;YACF;SACD;IACH;IAEA,MAAMQ,MAAMuB,UAAU,CACpB;QACEC,MAAM;YACJ;gBACEC,KAAK;oBACHC,KAAKR,IAAIO,GAAG;gBACd;YACF;YACAL;YACA;gBACEf,QAAQ;oBACNiB,KAAK;gBACP;YACF;YACA;gBACEzB,WAAW;oBACT8B,KAAK,IAAIlB,KAAKS,IAAIrB,SAAS;gBAC7B;YACF;SACD;IACH,GACA;QAAE+B,QAAQ;YAAEvB,QAAQ;QAAE;IAAE,GACxBU;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"}
|
package/dist/deleteOne.d.ts.map
CHANGED
|
@@ -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;
|
|
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"}
|
package/dist/deleteOne.js
CHANGED
|
@@ -1,13 +1,30 @@
|
|
|
1
|
+
import { resolveBranchDelete } from 'payload';
|
|
1
2
|
import { buildQuery } from './queries/buildQuery.js';
|
|
2
3
|
import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
|
|
3
4
|
import { getCollection } from './utilities/getEntity.js';
|
|
4
5
|
import { getSession } from './utilities/getSession.js';
|
|
5
6
|
import { transform } from './utilities/transform.js';
|
|
6
|
-
export const deleteOne = async function deleteOne({ collection: collectionSlug, req, returning, select, where }) {
|
|
7
|
+
export const deleteOne = async function deleteOne({ branch, collection: collectionSlug, req, returning, select, where }) {
|
|
7
8
|
const { collectionConfig, Model } = getCollection({
|
|
8
9
|
adapter: this,
|
|
9
10
|
collectionSlug
|
|
10
11
|
});
|
|
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
|
+
}
|
|
11
28
|
const query = await buildQuery({
|
|
12
29
|
adapter: this,
|
|
13
30
|
collectionSlug,
|
package/dist/deleteOne.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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","
|
|
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"}
|
package/dist/find.d.ts.map
CHANGED
|
@@ -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;AAgBnC,eAAO,MAAM,IAAI,EAAE,
|
|
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,IA4LlB,CAAA"}
|
package/dist/find.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { flattenWhereToOperators } from 'payload';
|
|
1
|
+
import { applyBranchIDProjection, flattenWhereToOperators, resolveBranchQuery } 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,11 +8,17 @@ 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({ collection: collectionSlug, draftsEnabled, joins = {}, limit = 0, locale, page, pagination, projection, req, select, sort: sortArg, where = {} }) {
|
|
11
|
+
export const find = async function find({ branch, 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
|
+
}) ?? {};
|
|
16
22
|
let hasNearConstraint = false;
|
|
17
23
|
if (where) {
|
|
18
24
|
const constraints = flattenWhereToOperators(where);
|
|
@@ -112,7 +118,8 @@ export const find = async function find({ collection: collectionSlug, draftsEnab
|
|
|
112
118
|
joins,
|
|
113
119
|
locale,
|
|
114
120
|
projection: paginationOptions.projection,
|
|
115
|
-
query
|
|
121
|
+
query,
|
|
122
|
+
req
|
|
116
123
|
});
|
|
117
124
|
if (aggregate || sortAggregation.length > 0) {
|
|
118
125
|
result = await aggregatePaginate({
|
|
@@ -148,6 +155,12 @@ export const find = async function find({ collection: collectionSlug, draftsEnab
|
|
|
148
155
|
fields: collectionConfig.fields,
|
|
149
156
|
operation: 'read'
|
|
150
157
|
});
|
|
158
|
+
applyBranchIDProjection({
|
|
159
|
+
branch,
|
|
160
|
+
collectionSlug,
|
|
161
|
+
docs: result.docs,
|
|
162
|
+
req
|
|
163
|
+
});
|
|
151
164
|
return result;
|
|
152
165
|
};
|
|
153
166
|
|
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 { 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 || 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,oBAAoB,QAAQ,sCAAqC;AAC1E,SAASC,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,aAAa,QAAQ,2BAA0B;AACxD,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,YAAY,QAAQ,8BAA6B;AAC1D,SAASC,SAAS,QAAQ,2BAA0B;AAEpD,OAAO,MAAMC,OAAa,eAAeA,KAEvC,EACEC,YAAYC,cAAc,EAC1BC,aAAa,EACbC,QAAQ,CAAC,CAAC,EACVC,QAAQ,CAAC,EACTC,MAAM,EACNC,IAAI,EACJC,UAAU,EACVC,UAAU,EACVC,GAAG,EACHC,MAAM,EACNC,MAAMC,OAAO,EACbC,QAAQ,CAAC,CAAC,EACX;IAED,MAAM,EAAEC,gBAAgB,EAAEC,KAAK,EAAE,GAAGpB,cAAc;QAAEqB,SAAS,IAAI;QAAEf;IAAe;IAElF,IAAIgB,oBAAoB;IAExB,IAAIJ,OAAO;QACT,MAAMK,cAAc7B,wBAAwBwB;QAC5CI,oBAAoBC,YAAYC,IAAI,CAAC,CAACC,OAASC,OAAOC,IAAI,CAACF,MAAMD,IAAI,CAAC,CAACI,MAA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Ba;YACAS,mBAAmBE,kBAAkBF,iBAAiB;QACxD;IACF,OAAO;QACLiB,SAAS,MAAMnC,MAAMuC,QAAQ,CAACvB,OAAOI;IACvC;IAEA,IAAI,CAAC,IAAI,CAACoB,mBAAmB,EAAE;QAC7B,MAAM1D,aAAa;YACjBmB,SAAS,IAAI;YACbf;YACAuD,MAAMN,OAAOM,IAAI;YACjBrD;YACAE;QACF;IACF;IAEAP,UAAU;QACRkB,SAAS,IAAI;QACbyC,MAAMP,OAAOM,IAAI;QACjB7B,QAAQb,iBAAiBa,MAAM;QAC/B+B,WAAW;IACb;IAEA,OAAOR;AACT,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../src/find.ts"],"sourcesContent":["import type { PaginateOptions, PipelineStage } from 'mongoose'\nimport type { Find } from 'payload'\n\nimport { applyBranchIDProjection, flattenWhereToOperators, resolveBranchQuery } 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 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 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","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","collation","localizationConfig","localization","defaultLocale","disableIndexHints","useCustomCountFn","Promise","resolve","countDocuments","hint","_id","result","aggregate","joinAggregation","undefined","paginate","useJoinAggregations","docs","data","operation"],"mappings":"AAGA,SAASA,uBAAuB,EAAEC,uBAAuB,EAAEC,kBAAkB,QAAQ,UAAS;AAI9F,SAASC,UAAU,QAAQ,0BAAyB;AACpD,SAASC,cAAc,QAAQ,8BAA6B;AAC5D,SAASC,iBAAiB,QAAQ,mCAAkC;AACpE,SAASC,oBAAoB,QAAQ,sCAAqC;AAC1E,SAASC,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,aAAa,QAAQ,2BAA0B;AACxD,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,YAAY,QAAQ,8BAA6B;AAC1D,SAASC,SAAS,QAAQ,2BAA0B;AAEpD,OAAO,MAAMC,OAAa,eAAeA,KAEvC,EACEC,MAAM,EACNC,YAAYC,cAAc,EAC1BC,aAAa,EACbC,QAAQ,CAAC,CAAC,EACVC,QAAQ,CAAC,EACTC,MAAM,EACNC,IAAI,EACJC,UAAU,EACVC,UAAU,EACVC,GAAG,EACHC,MAAM,EACNC,MAAMC,OAAO,EACbC,QAAQ,CAAC,CAAC,EACX;IAED,MAAM,EAAEC,gBAAgB,EAAEC,KAAK,EAAE,GAAGrB,cAAc;QAAEsB,SAAS,IAAI;QAAEf;IAAe;IAElFY,QAAQ,AAAC,MAAMzB,mBAAmB;QAAEW;QAAQE;QAAgBQ;QAAKI;IAAM,MAAO,CAAC;IAE/E,IAAII,oBAAoB;IAExB,IAAIJ,OAAO;QACT,MAAMK,cAAc/B,wBAAwB0B;QAC5CI,oBAAoBC,YAAYC,IAAI,CAAC,CAACC,OAASC,OAAOC,IAAI,CAACF,MAAMD,IAAI,CAAC,CAACI,MAAQA,QAAQ;IACzF;IAEA,MAAMC,kBAAmC,EAAE;IAE3C,IAAIb;IACJ,IAAI,CAACM,mBAAmB;QACtBN,OAAOrB,eAAe;YACpB0B,SAAS,IAAI;YACbS,QAAQ,IAAI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CAACoB,mBAAmB,EAAE;QAC7B,MAAM3D,aAAa;YACjBoB,SAAS,IAAI;YACbf;YACAuD,MAAMN,OAAOM,IAAI;YACjBrD;YACAE;QACF;IACF;IAEAR,UAAU;QACRmB,SAAS,IAAI;QACbyC,MAAMP,OAAOM,IAAI;QACjB7B,QAAQb,iBAAiBa,MAAM;QAC/B+B,WAAW;IACb;IAEAxE,wBAAwB;QACtBa;QACAE;QACAuD,MAAMN,OAAOM,IAAI;QACjB/C;IACF;IAEA,OAAOyC;AACT,EAAC"}
|
package/dist/findGlobal.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"findGlobal.d.ts","sourceRoot":"","sources":["../src/findGlobal.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"findGlobal.d.ts","sourceRoot":"","sources":["../src/findGlobal.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAkBzC,eAAO,MAAM,UAAU,EAAE,UAqDxB,CAAA"}
|
package/dist/findGlobal.js
CHANGED
|
@@ -1,15 +1,21 @@
|
|
|
1
|
-
import { combineQueries } from 'payload';
|
|
1
|
+
import { branchGlobalNeedsBothRows, combineQueries, pickBranchGlobal, resolveBranch, resolveBranchGlobalQuery } from 'payload';
|
|
2
2
|
import { buildQuery } from './queries/buildQuery.js';
|
|
3
3
|
import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
|
|
4
4
|
import { getGlobal } from './utilities/getEntity.js';
|
|
5
5
|
import { getSession } from './utilities/getSession.js';
|
|
6
6
|
import { transform } from './utilities/transform.js';
|
|
7
|
-
export const findGlobal = async function findGlobal({ slug: globalSlug, locale, req, select, where = {} }) {
|
|
7
|
+
export const findGlobal = async function findGlobal({ slug: globalSlug, branch, locale, req, select, where = {} }) {
|
|
8
8
|
const { globalConfig, Model } = getGlobal({
|
|
9
9
|
adapter: this,
|
|
10
10
|
globalSlug
|
|
11
11
|
});
|
|
12
12
|
const fields = globalConfig.flattenedFields;
|
|
13
|
+
const branchedWhere = resolveBranchGlobalQuery({
|
|
14
|
+
branch,
|
|
15
|
+
globalSlug,
|
|
16
|
+
req,
|
|
17
|
+
where
|
|
18
|
+
});
|
|
13
19
|
const query = await buildQuery({
|
|
14
20
|
adapter: this,
|
|
15
21
|
fields,
|
|
@@ -19,7 +25,7 @@ export const findGlobal = async function findGlobal({ slug: globalSlug, locale,
|
|
|
19
25
|
globalType: {
|
|
20
26
|
equals: globalSlug
|
|
21
27
|
}
|
|
22
|
-
},
|
|
28
|
+
}, branchedWhere ?? {})
|
|
23
29
|
});
|
|
24
30
|
const options = {
|
|
25
31
|
lean: true,
|
|
@@ -30,7 +36,23 @@ export const findGlobal = async function findGlobal({ slug: globalSlug, locale,
|
|
|
30
36
|
}),
|
|
31
37
|
session: await getSession(this, req)
|
|
32
38
|
};
|
|
33
|
-
|
|
39
|
+
// A global is one document, so the branch's row and main's row can be fetched
|
|
40
|
+
// together and the branch's preferred in memory. There is no result set to
|
|
41
|
+
// paginate, so nothing a post-query step could get wrong.
|
|
42
|
+
let doc;
|
|
43
|
+
if (branchGlobalNeedsBothRows({
|
|
44
|
+
branch,
|
|
45
|
+
globalSlug,
|
|
46
|
+
req
|
|
47
|
+
})) {
|
|
48
|
+
const rows = await Model.find(query, {}, {
|
|
49
|
+
...options,
|
|
50
|
+
limit: 2
|
|
51
|
+
}).lean();
|
|
52
|
+
doc = pickBranchGlobal(rows, branch || resolveBranch(req));
|
|
53
|
+
} else {
|
|
54
|
+
doc = await Model.findOne(query, {}, options);
|
|
55
|
+
}
|
|
34
56
|
if (!doc) {
|
|
35
57
|
return null;
|
|
36
58
|
}
|
package/dist/findGlobal.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/findGlobal.ts"],"sourcesContent":["import type { QueryOptions } from 'mongoose'\nimport type { FindGlobal } from 'payload'\n\nimport {
|
|
1
|
+
{"version":3,"sources":["../src/findGlobal.ts"],"sourcesContent":["import type { QueryOptions } from 'mongoose'\nimport type { FindGlobal } from 'payload'\n\nimport {\n branchGlobalNeedsBothRows,\n combineQueries,\n pickBranchGlobal,\n resolveBranch,\n resolveBranchGlobalQuery,\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(\n this: MongooseAdapter,\n { slug: globalSlug, branch, locale, req, select, where = {} },\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 fields,\n globalSlug,\n locale,\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,\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: any\n\n if (branchGlobalNeedsBothRows({ branch, globalSlug, req })) {\n const rows = await Model.find(query, {}, { ...options, limit: 2 }).lean()\n\n doc = pickBranchGlobal(rows as Record<string, any>[], branch || resolveBranch(req as never))\n } else {\n doc = await Model.findOne(query, {}, options)\n }\n\n if (!doc) {\n return null\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","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,QACnB,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,EAAE;IAE7D,MAAM,EAAEC,YAAY,EAAEC,KAAK,EAAE,GAAGZ,UAAU;QAAEa,SAAS,IAAI;QAAER;IAAW;IAEtE,MAAMS,SAASH,aAAaI,eAAe;IAE3C,MAAMC,gBAAgBnB,yBAAyB;QAAES;QAAQD;QAAYG;QAAKE;IAAM;IAEhF,MAAMO,QAAQ,MAAMnB,WAAW;QAC7Be,SAAS,IAAI;QACbC;QACAT;QACAE;QACAG,OAAOhB,eAAe;YAAEwB,YAAY;gBAAEC,QAAQd;YAAW;QAAE,GAAGW,iBAAiB,CAAC;IAClF;IAEA,MAAMI,UAAwB;QAC5BC,MAAM;QACNZ,QAAQV,0BAA0B;YAChCc,SAAS,IAAI;YACbC;YACAL;QACF;QACAa,SAAS,MAAMrB,WAAW,IAAI,EAAEO;IAClC;IAEA,8EAA8E;IAC9E,2EAA2E;IAC3E,0DAA0D;IAC1D,IAAIe;IAEJ,IAAI9B,0BAA0B;QAAEa;QAAQD;QAAYG;IAAI,IAAI;QAC1D,MAAMgB,OAAO,MAAMZ,MAAMa,IAAI,CAACR,OAAO,CAAC,GAAG;YAAE,GAAGG,OAAO;YAAEM,OAAO;QAAE,GAAGL,IAAI;QAEvEE,MAAM5B,iBAAiB6B,MAA+BlB,UAAUV,cAAcY;IAChF,OAAO;QACLe,MAAM,MAAMX,MAAMe,OAAO,CAACV,OAAO,CAAC,GAAGG;IACvC;IAEA,IAAI,CAACG,KAAK;QACR,OAAO;IACT;IAEArB,UAAU;QACRW,SAAS,IAAI;QACbe,MAAML;QACNT,QAAQH,aAAaG,MAAM;QAC3Be,WAAW;IACb;IAEA,OAAON;AACT,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"findGlobalVersions.d.ts","sourceRoot":"","sources":["../src/findGlobalVersions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"findGlobalVersions.d.ts","sourceRoot":"","sources":["../src/findGlobalVersions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAA;AAkBjD,eAAO,MAAM,kBAAkB,EAAE,kBAoIhC,CAAA"}
|
|
@@ -1,16 +1,22 @@
|
|
|
1
|
-
import { buildVersionGlobalFields, flattenWhereToOperators } from 'payload';
|
|
1
|
+
import { buildVersionGlobalFields, flattenWhereToOperators, resolveBranchGlobalVersionQuery } from 'payload';
|
|
2
2
|
import { buildQuery } from './queries/buildQuery.js';
|
|
3
3
|
import { buildSortParam } from './queries/buildSortParam.js';
|
|
4
4
|
import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
|
|
5
5
|
import { getGlobal } from './utilities/getEntity.js';
|
|
6
6
|
import { getSession } from './utilities/getSession.js';
|
|
7
7
|
import { transform } from './utilities/transform.js';
|
|
8
|
-
export const findGlobalVersions = async function findGlobalVersions({ global: globalSlug, limit = 0, locale, page, pagination, req, select, sort: sortArg, where = {} }) {
|
|
8
|
+
export const findGlobalVersions = async function findGlobalVersions({ branch, global: globalSlug, limit = 0, locale, page, pagination, req, select, sort: sortArg, where = {} }) {
|
|
9
9
|
const { globalConfig, Model } = getGlobal({
|
|
10
10
|
adapter: this,
|
|
11
11
|
globalSlug,
|
|
12
12
|
versions: true
|
|
13
13
|
});
|
|
14
|
+
where = resolveBranchGlobalVersionQuery({
|
|
15
|
+
branch,
|
|
16
|
+
globalSlug,
|
|
17
|
+
req,
|
|
18
|
+
where
|
|
19
|
+
}) ?? {};
|
|
14
20
|
const versionFields = buildVersionGlobalFields(this.payload.config, globalConfig, true);
|
|
15
21
|
let hasNearConstraint = false;
|
|
16
22
|
if (where) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/findGlobalVersions.ts"],"sourcesContent":["import type { PaginateOptions, QueryOptions } from 'mongoose'\nimport type { FindGlobalVersions } from 'payload'\n\nimport {
|
|
1
|
+
{"version":3,"sources":["../src/findGlobalVersions.ts"],"sourcesContent":["import type { PaginateOptions, QueryOptions } from 'mongoose'\nimport type { FindGlobalVersions } from 'payload'\n\nimport {\n APIError,\n buildVersionGlobalFields,\n flattenWhereToOperators,\n resolveBranchGlobalVersionQuery,\n} from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { buildSortParam } from './queries/buildSortParam.js'\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getGlobal } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\nimport { transform } from './utilities/transform.js'\n\nexport const findGlobalVersions: FindGlobalVersions = async function findGlobalVersions(\n this: MongooseAdapter,\n {\n branch,\n global: globalSlug,\n limit = 0,\n locale,\n page,\n pagination,\n req,\n select,\n sort: sortArg,\n where = {},\n },\n) {\n const { globalConfig, Model } = getGlobal({ adapter: this, globalSlug, versions: true })\n\n where = resolveBranchGlobalVersionQuery({ branch, globalSlug, req, where }) ?? {}\n\n const versionFields = buildVersionGlobalFields(this.payload.config, globalConfig, 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 let sort\n if (!hasNearConstraint) {\n sort = buildSortParam({\n adapter: this,\n config: this.payload.config,\n fields: versionFields,\n locale,\n sort: sortArg || '-updatedAt',\n timestamps: true,\n })\n }\n\n const query = await buildQuery({\n adapter: this,\n fields: versionFields,\n locale,\n where,\n })\n\n const session = await getSession(this, req)\n // Calculate skip from page for cases where pagination is disabled but offset is still needed\n const skip = typeof page === 'number' && page > 1 ? (page - 1) * (limit || 0) : undefined\n const options: QueryOptions = {\n limit,\n session,\n skip,\n }\n\n // useEstimatedCount is faster, but not accurate, as it ignores any filters. It is thus set to true if there are no filters.\n const useEstimatedCount = hasNearConstraint || !query || Object.keys(query).length === 0\n const paginationOptions: PaginateOptions = {\n lean: true,\n leanWithId: true,\n limit,\n options,\n page,\n pagination,\n projection: buildProjectionFromSelect({ adapter: this, fields: versionFields, select }),\n sort,\n useEstimatedCount,\n }\n\n if (this.collation) {\n const 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 const result = await Model.paginate(query, paginationOptions)\n\n transform({\n adapter: this,\n data: result.docs,\n fields: buildVersionGlobalFields(this.payload.config, globalConfig),\n operation: 'read',\n })\n\n return result\n}\n"],"names":["buildVersionGlobalFields","flattenWhereToOperators","resolveBranchGlobalVersionQuery","buildQuery","buildSortParam","buildProjectionFromSelect","getGlobal","getSession","transform","findGlobalVersions","branch","global","globalSlug","limit","locale","page","pagination","req","select","sort","sortArg","where","globalConfig","Model","adapter","versions","versionFields","payload","config","hasNearConstraint","constraints","some","prop","Object","keys","key","fields","timestamps","query","session","skip","undefined","options","useEstimatedCount","length","paginationOptions","lean","leanWithId","projection","collation","localizationConfig","localization","defaultLocale","disableIndexHints","useCustomCountFn","Promise","resolve","countDocuments","hint","_id","result","paginate","data","docs","operation"],"mappings":"AAGA,SAEEA,wBAAwB,EACxBC,uBAAuB,EACvBC,+BAA+B,QAC1B,UAAS;AAIhB,SAASC,UAAU,QAAQ,0BAAyB;AACpD,SAASC,cAAc,QAAQ,8BAA6B;AAC5D,SAASC,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,SAAS,QAAQ,2BAA0B;AACpD,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,SAAS,QAAQ,2BAA0B;AAEpD,OAAO,MAAMC,qBAAyC,eAAeA,mBAEnE,EACEC,MAAM,EACNC,QAAQC,UAAU,EAClBC,QAAQ,CAAC,EACTC,MAAM,EACNC,IAAI,EACJC,UAAU,EACVC,GAAG,EACHC,MAAM,EACNC,M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S,IAAI;QACbsC,MAAMF,OAAOG,IAAI;QACjB3B,QAAQpC,yBAAyB,IAAI,CAAC2B,OAAO,CAACC,MAAM,EAAEN;QACtD0C,WAAW;IACb;IAEA,OAAOJ;AACT,EAAC"}
|
package/dist/findOne.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"findOne.d.ts","sourceRoot":"","sources":["../src/findOne.ts"],"names":[],"mappings":"AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"findOne.d.ts","sourceRoot":"","sources":["../src/findOne.ts"],"names":[],"mappings":"AAEA,OAAO,EAA2B,KAAK,OAAO,EAAsB,MAAM,SAAS,CAAA;AAanF,eAAO,MAAM,OAAO,EAAE,OAkFrB,CAAA"}
|
package/dist/findOne.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { applyBranchIDProjection, resolveBranchQuery } from 'payload';
|
|
1
2
|
import { buildQuery } from './queries/buildQuery.js';
|
|
2
3
|
import { aggregatePaginate } from './utilities/aggregatePaginate.js';
|
|
3
4
|
import { buildJoinAggregation } from './utilities/buildJoinAggregation.js';
|
|
@@ -6,11 +7,17 @@ import { getCollection } from './utilities/getEntity.js';
|
|
|
6
7
|
import { getSession } from './utilities/getSession.js';
|
|
7
8
|
import { resolveJoins } from './utilities/resolveJoins.js';
|
|
8
9
|
import { transform } from './utilities/transform.js';
|
|
9
|
-
export const findOne = async function findOne({ collection: collectionSlug, draftsEnabled, joins, locale, req, select, where = {} }) {
|
|
10
|
+
export const findOne = async function findOne({ branch, collection: collectionSlug, draftsEnabled, joins, locale, req, select, where = {} }) {
|
|
10
11
|
const { collectionConfig, Model } = getCollection({
|
|
11
12
|
adapter: this,
|
|
12
13
|
collectionSlug
|
|
13
14
|
});
|
|
15
|
+
where = await resolveBranchQuery({
|
|
16
|
+
branch,
|
|
17
|
+
collectionSlug,
|
|
18
|
+
req,
|
|
19
|
+
where
|
|
20
|
+
}) ?? {};
|
|
14
21
|
const query = await buildQuery({
|
|
15
22
|
adapter: this,
|
|
16
23
|
collectionSlug,
|
|
@@ -31,7 +38,8 @@ export const findOne = async function findOne({ collection: collectionSlug, draf
|
|
|
31
38
|
joins,
|
|
32
39
|
locale,
|
|
33
40
|
projection,
|
|
34
|
-
query
|
|
41
|
+
query,
|
|
42
|
+
req
|
|
35
43
|
});
|
|
36
44
|
const session = await getSession(this, req);
|
|
37
45
|
const options = {
|
|
@@ -76,6 +84,14 @@ export const findOne = async function findOne({ collection: collectionSlug, draf
|
|
|
76
84
|
fields: collectionConfig.fields,
|
|
77
85
|
operation: 'read'
|
|
78
86
|
});
|
|
87
|
+
applyBranchIDProjection({
|
|
88
|
+
branch,
|
|
89
|
+
collectionSlug,
|
|
90
|
+
docs: [
|
|
91
|
+
doc
|
|
92
|
+
],
|
|
93
|
+
req
|
|
94
|
+
});
|
|
79
95
|
return doc;
|
|
80
96
|
};
|
|
81
97
|
|