@payloadcms/db-mongodb 3.24.0-canary.f229d8d → 3.24.0
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 +5 -2
- package/dist/count.js.map +1 -1
- package/dist/countGlobalVersions.d.ts.map +1 -1
- package/dist/countGlobalVersions.js +5 -3
- package/dist/countGlobalVersions.js.map +1 -1
- package/dist/countVersions.d.ts.map +1 -1
- package/dist/countVersions.js +5 -3
- package/dist/countVersions.js.map +1 -1
- package/dist/deleteMany.d.ts.map +1 -1
- package/dist/deleteMany.js +5 -2
- package/dist/deleteMany.js.map +1 -1
- package/dist/deleteOne.d.ts.map +1 -1
- package/dist/deleteOne.js +9 -3
- package/dist/deleteOne.js.map +1 -1
- package/dist/deleteVersions.d.ts +1 -1
- package/dist/deleteVersions.d.ts.map +1 -1
- package/dist/deleteVersions.js +5 -2
- package/dist/deleteVersions.js.map +1 -1
- package/dist/find.d.ts.map +1 -1
- package/dist/find.js +5 -2
- package/dist/find.js.map +1 -1
- package/dist/findGlobal.d.ts.map +1 -1
- package/dist/findGlobal.js +6 -3
- package/dist/findGlobal.js.map +1 -1
- package/dist/findGlobalVersions.d.ts.map +1 -1
- package/dist/findGlobalVersions.js +4 -3
- package/dist/findGlobalVersions.js.map +1 -1
- package/dist/findOne.d.ts.map +1 -1
- package/dist/findOne.js +5 -2
- package/dist/findOne.js.map +1 -1
- package/dist/findVersions.d.ts.map +1 -1
- package/dist/findVersions.js +6 -3
- package/dist/findVersions.js.map +1 -1
- package/dist/init.d.ts.map +1 -1
- package/dist/init.js +25 -17
- package/dist/init.js.map +1 -1
- package/dist/models/buildCollectionSchema.d.ts.map +1 -1
- package/dist/models/buildCollectionSchema.js +14 -10
- package/dist/models/buildCollectionSchema.js.map +1 -1
- package/dist/models/buildGlobalModel.d.ts.map +1 -1
- package/dist/models/buildGlobalModel.js +9 -5
- package/dist/models/buildGlobalModel.js.map +1 -1
- package/dist/models/buildSchema.d.ts +6 -1
- package/dist/models/buildSchema.d.ts.map +1 -1
- package/dist/models/buildSchema.js +220 -99
- package/dist/models/buildSchema.js.map +1 -1
- package/dist/predefinedMigrations/migrateRelationshipsV2_V3.d.ts.map +1 -1
- package/dist/predefinedMigrations/migrateRelationshipsV2_V3.js +6 -2
- package/dist/predefinedMigrations/migrateRelationshipsV2_V3.js.map +1 -1
- package/dist/queries/buildAndOrConditions.d.ts +2 -1
- package/dist/queries/buildAndOrConditions.d.ts.map +1 -1
- package/dist/queries/buildAndOrConditions.js +2 -1
- package/dist/queries/buildAndOrConditions.js.map +1 -1
- package/dist/queries/buildQuery.d.ts +6 -9
- package/dist/queries/buildQuery.d.ts.map +1 -1
- package/dist/queries/buildQuery.js +11 -34
- package/dist/queries/buildQuery.js.map +1 -1
- package/dist/queries/buildSearchParams.d.ts +2 -1
- package/dist/queries/buildSearchParams.d.ts.map +1 -1
- package/dist/queries/buildSearchParams.js +4 -1
- package/dist/queries/buildSearchParams.js.map +1 -1
- package/dist/queries/buildSortParam.d.ts +2 -1
- package/dist/queries/buildSortParam.d.ts.map +1 -1
- package/dist/queries/buildSortParam.js +2 -1
- package/dist/queries/buildSortParam.js.map +1 -1
- package/dist/queries/getBuildQueryPlugin.d.ts +14 -0
- package/dist/queries/getBuildQueryPlugin.d.ts.map +1 -0
- package/dist/queries/getBuildQueryPlugin.js +40 -0
- package/dist/queries/getBuildQueryPlugin.js.map +1 -0
- package/dist/queries/getLocalizedSortProperty.d.ts +2 -1
- package/dist/queries/getLocalizedSortProperty.d.ts.map +1 -1
- package/dist/queries/getLocalizedSortProperty.js +11 -3
- package/dist/queries/getLocalizedSortProperty.js.map +1 -1
- package/dist/queries/parseParams.d.ts +2 -1
- package/dist/queries/parseParams.d.ts.map +1 -1
- package/dist/queries/parseParams.js +3 -1
- package/dist/queries/parseParams.js.map +1 -1
- package/dist/queries/sanitizeQueryValue.d.ts +2 -1
- package/dist/queries/sanitizeQueryValue.d.ts.map +1 -1
- package/dist/queries/sanitizeQueryValue.js +6 -2
- package/dist/queries/sanitizeQueryValue.js.map +1 -1
- package/dist/queryDrafts.d.ts.map +1 -1
- package/dist/queryDrafts.js +6 -3
- package/dist/queryDrafts.js.map +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/updateGlobal.d.ts.map +1 -1
- package/dist/updateGlobal.js +3 -0
- package/dist/updateGlobal.js.map +1 -1
- package/dist/updateGlobalVersion.d.ts.map +1 -1
- package/dist/updateGlobalVersion.js +9 -3
- package/dist/updateGlobalVersion.js.map +1 -1
- package/dist/updateOne.d.ts.map +1 -1
- package/dist/updateOne.js +8 -2
- package/dist/updateOne.js.map +1 -1
- package/dist/updateVersion.d.ts.map +1 -1
- package/dist/updateVersion.js +9 -3
- package/dist/updateVersion.js.map +1 -1
- package/dist/utilities/buildJoinAggregation.d.ts.map +1 -1
- package/dist/utilities/buildJoinAggregation.js +155 -4
- package/dist/utilities/buildJoinAggregation.js.map +1 -1
- package/dist/utilities/buildProjectionFromSelect.d.ts.map +1 -1
- package/dist/utilities/buildProjectionFromSelect.js +18 -17
- package/dist/utilities/buildProjectionFromSelect.js.map +1 -1
- package/dist/utilities/sanitizeRelationshipIDs.d.ts +2 -1
- package/dist/utilities/sanitizeRelationshipIDs.d.ts.map +1 -1
- package/dist/utilities/sanitizeRelationshipIDs.js +7 -3
- package/dist/utilities/sanitizeRelationshipIDs.js.map +1 -1
- package/dist/utilities/sanitizeRelationshipIDs.spec.js +44 -0
- package/dist/utilities/sanitizeRelationshipIDs.spec.js.map +1 -1
- package/package.json +3 -3
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { buildVersionGlobalFields } from 'payload';
|
|
2
|
+
import { buildQuery } from './queries/buildQuery.js';
|
|
2
3
|
import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
|
|
3
4
|
import { getSession } from './utilities/getSession.js';
|
|
4
5
|
import { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.js';
|
|
@@ -11,20 +12,22 @@ export async function updateGlobalVersion({ id, global: globalSlug, locale, opti
|
|
|
11
12
|
};
|
|
12
13
|
const currentGlobal = this.payload.config.globals.find((global)=>global.slug === globalSlug);
|
|
13
14
|
const fields = buildVersionGlobalFields(this.payload.config, currentGlobal);
|
|
15
|
+
const flattenedFields = buildVersionGlobalFields(this.payload.config, currentGlobal, true);
|
|
14
16
|
const options = {
|
|
15
17
|
...optionsArgs,
|
|
16
18
|
lean: true,
|
|
17
19
|
new: true,
|
|
18
20
|
projection: buildProjectionFromSelect({
|
|
19
21
|
adapter: this,
|
|
20
|
-
fields:
|
|
22
|
+
fields: flattenedFields,
|
|
21
23
|
select
|
|
22
24
|
}),
|
|
23
25
|
session: await getSession(this, req)
|
|
24
26
|
};
|
|
25
|
-
const query = await
|
|
27
|
+
const query = await buildQuery({
|
|
28
|
+
adapter: this,
|
|
29
|
+
fields: flattenedFields,
|
|
26
30
|
locale,
|
|
27
|
-
payload: this.payload,
|
|
28
31
|
where: whereToUse
|
|
29
32
|
});
|
|
30
33
|
const sanitizedData = sanitizeRelationshipIDs({
|
|
@@ -33,6 +36,9 @@ export async function updateGlobalVersion({ id, global: globalSlug, locale, opti
|
|
|
33
36
|
fields
|
|
34
37
|
});
|
|
35
38
|
const doc = await VersionModel.findOneAndUpdate(query, sanitizedData, options);
|
|
39
|
+
if (!doc) {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
36
42
|
const result = JSON.parse(JSON.stringify(doc));
|
|
37
43
|
const verificationToken = doc._verificationToken;
|
|
38
44
|
// custom id type reset
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/updateGlobalVersion.ts"],"sourcesContent":["import type { QueryOptions } from 'mongoose'\n\nimport { buildVersionGlobalFields, type TypeWithID, type UpdateGlobalVersionArgs } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getSession } from './utilities/getSession.js'\nimport { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.js'\n\nexport async function updateGlobalVersion<T extends TypeWithID>(\n this: MongooseAdapter,\n {\n id,\n global: globalSlug,\n locale,\n options: optionsArgs = {},\n req,\n select,\n versionData,\n where,\n }: UpdateGlobalVersionArgs<T>,\n) {\n const VersionModel = this.versions[globalSlug]\n const whereToUse = where || { id: { equals: id } }\n\n const currentGlobal = this.payload.config.globals.find((global) => global.slug === globalSlug)\n const fields = buildVersionGlobalFields(this.payload.config, currentGlobal)\n\n const options: QueryOptions = {\n ...optionsArgs,\n lean: true,\n new: true,\n projection: buildProjectionFromSelect({\n adapter: this,\n fields:
|
|
1
|
+
{"version":3,"sources":["../src/updateGlobalVersion.ts"],"sourcesContent":["import type { QueryOptions } from 'mongoose'\n\nimport { buildVersionGlobalFields, type TypeWithID, type UpdateGlobalVersionArgs } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getSession } from './utilities/getSession.js'\nimport { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.js'\n\nexport async function updateGlobalVersion<T extends TypeWithID>(\n this: MongooseAdapter,\n {\n id,\n global: globalSlug,\n locale,\n options: optionsArgs = {},\n req,\n select,\n versionData,\n where,\n }: UpdateGlobalVersionArgs<T>,\n) {\n const VersionModel = this.versions[globalSlug]\n const whereToUse = where || { id: { equals: id } }\n\n const currentGlobal = this.payload.config.globals.find((global) => global.slug === globalSlug)\n const fields = buildVersionGlobalFields(this.payload.config, currentGlobal)\n const flattenedFields = buildVersionGlobalFields(this.payload.config, currentGlobal, true)\n const options: QueryOptions = {\n ...optionsArgs,\n lean: true,\n new: true,\n projection: buildProjectionFromSelect({\n adapter: this,\n fields: flattenedFields,\n select,\n }),\n session: await getSession(this, req),\n }\n\n const query = await buildQuery({\n adapter: this,\n fields: flattenedFields,\n locale,\n where: whereToUse,\n })\n\n const sanitizedData = sanitizeRelationshipIDs({\n config: this.payload.config,\n data: versionData,\n fields,\n })\n\n const doc = await VersionModel.findOneAndUpdate(query, sanitizedData, options)\n\n if (!doc) {\n return null\n }\n\n const result = JSON.parse(JSON.stringify(doc))\n\n const verificationToken = doc._verificationToken\n\n // custom id type reset\n result.id = result._id\n if (verificationToken) {\n result._verificationToken = verificationToken\n }\n return result\n}\n"],"names":["buildVersionGlobalFields","buildQuery","buildProjectionFromSelect","getSession","sanitizeRelationshipIDs","updateGlobalVersion","id","global","globalSlug","locale","options","optionsArgs","req","select","versionData","where","VersionModel","versions","whereToUse","equals","currentGlobal","payload","config","globals","find","slug","fields","flattenedFields","lean","new","projection","adapter","session","query","sanitizedData","data","doc","findOneAndUpdate","result","JSON","parse","stringify","verificationToken","_verificationToken","_id"],"mappings":"AAEA,SAASA,wBAAwB,QAAuD,UAAS;AAIjG,SAASC,UAAU,QAAQ,0BAAyB;AACpD,SAASC,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,uBAAuB,QAAQ,yCAAwC;AAEhF,OAAO,eAAeC,oBAEpB,EACEC,EAAE,EACFC,QAAQC,UAAU,EAClBC,MAAM,EACNC,SAASC,cAAc,CAAC,CAAC,EACzBC,GAAG,EACHC,MAAM,EACNC,WAAW,EACXC,KAAK,EACsB;IAE7B,MAAMC,eAAe,IAAI,CAACC,QAAQ,CAACT,WAAW;IAC9C,MAAMU,aAAaH,SAAS;QAAET,IAAI;YAAEa,QAAQb;QAAG;IAAE;IAEjD,MAAMc,gBAAgB,IAAI,CAACC,OAAO,CAACC,MAAM,CAACC,OAAO,CAACC,IAAI,CAAC,CAACjB,SAAWA,OAAOkB,IAAI,KAAKjB;IACnF,MAAMkB,SAAS1B,yBAAyB,IAAI,CAACqB,OAAO,CAACC,MAAM,EAAEF;IAC7D,MAAMO,kBAAkB3B,yBAAyB,IAAI,CAACqB,OAAO,CAACC,MAAM,EAAEF,eAAe;IACrF,MAAMV,UAAwB;QAC5B,GAAGC,WAAW;QACdiB,MAAM;QACNC,KAAK;QACLC,YAAY5B,0BAA0B;YACpC6B,SAAS,IAAI;YACbL,QAAQC;YACRd;QACF;QACAmB,SAAS,MAAM7B,WAAW,IAAI,EAAES;IAClC;IAEA,MAAMqB,QAAQ,MAAMhC,WAAW;QAC7B8B,SAAS,IAAI;QACbL,QAAQC;QACRlB;QACAM,OAAOG;IACT;IAEA,MAAMgB,gBAAgB9B,wBAAwB;QAC5CkB,QAAQ,IAAI,CAACD,OAAO,CAACC,MAAM;QAC3Ba,MAAMrB;QACNY;IACF;IAEA,MAAMU,MAAM,MAAMpB,aAAaqB,gBAAgB,CAACJ,OAAOC,eAAexB;IAEtE,IAAI,CAAC0B,KAAK;QACR,OAAO;IACT;IAEA,MAAME,SAASC,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACL;IAEzC,MAAMM,oBAAoBN,IAAIO,kBAAkB;IAEhD,uBAAuB;IACvBL,OAAOhC,EAAE,GAAGgC,OAAOM,GAAG;IACtB,IAAIF,mBAAmB;QACrBJ,OAAOK,kBAAkB,GAAGD;IAC9B;IACA,OAAOJ;AACT"}
|
package/dist/updateOne.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"updateOne.d.ts","sourceRoot":"","sources":["../src/updateOne.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"updateOne.d.ts","sourceRoot":"","sources":["../src/updateOne.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAWxC,eAAO,MAAM,SAAS,EAAE,SAkDvB,CAAA"}
|
package/dist/updateOne.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { buildQuery } from './queries/buildQuery.js';
|
|
1
2
|
import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
|
|
2
3
|
import { getSession } from './utilities/getSession.js';
|
|
3
4
|
import { handleError } from './utilities/handleError.js';
|
|
@@ -22,9 +23,11 @@ export const updateOne = async function updateOne({ id, collection, data, locale
|
|
|
22
23
|
}),
|
|
23
24
|
session: await getSession(this, req)
|
|
24
25
|
};
|
|
25
|
-
const query = await
|
|
26
|
+
const query = await buildQuery({
|
|
27
|
+
adapter: this,
|
|
28
|
+
collectionSlug: collection,
|
|
29
|
+
fields: this.payload.collections[collection].config.flattenedFields,
|
|
26
30
|
locale,
|
|
27
|
-
payload: this.payload,
|
|
28
31
|
where
|
|
29
32
|
});
|
|
30
33
|
let result;
|
|
@@ -42,6 +45,9 @@ export const updateOne = async function updateOne({ id, collection, data, locale
|
|
|
42
45
|
req
|
|
43
46
|
});
|
|
44
47
|
}
|
|
48
|
+
if (!result) {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
45
51
|
result = JSON.parse(JSON.stringify(result));
|
|
46
52
|
result.id = result._id;
|
|
47
53
|
result = sanitizeInternalFields(result);
|
package/dist/updateOne.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/updateOne.ts"],"sourcesContent":["import type { QueryOptions } from 'mongoose'\nimport type { UpdateOne } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getSession } from './utilities/getSession.js'\nimport { handleError } from './utilities/handleError.js'\nimport { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js'\nimport { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.js'\n\nexport const updateOne: UpdateOne = async function updateOne(\n this: MongooseAdapter,\n { id, collection, data, locale, options: optionsArgs = {}, req, select, where: whereArg },\n) {\n const where = id ? { id: { equals: id } } : whereArg\n const Model = this.collections[collection]\n const fields = this.payload.collections[collection].config.fields\n const options: QueryOptions = {\n ...optionsArgs,\n lean: true,\n new: true,\n projection: buildProjectionFromSelect({\n adapter: this,\n fields: this.payload.collections[collection].config.flattenedFields,\n select,\n }),\n session: await getSession(this, req),\n }\n\n const query = await
|
|
1
|
+
{"version":3,"sources":["../src/updateOne.ts"],"sourcesContent":["import type { QueryOptions } from 'mongoose'\nimport type { UpdateOne } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getSession } from './utilities/getSession.js'\nimport { handleError } from './utilities/handleError.js'\nimport { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js'\nimport { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.js'\n\nexport const updateOne: UpdateOne = async function updateOne(\n this: MongooseAdapter,\n { id, collection, data, locale, options: optionsArgs = {}, req, select, where: whereArg },\n) {\n const where = id ? { id: { equals: id } } : whereArg\n const Model = this.collections[collection]\n const fields = this.payload.collections[collection].config.fields\n const options: QueryOptions = {\n ...optionsArgs,\n lean: true,\n new: true,\n projection: buildProjectionFromSelect({\n adapter: this,\n fields: this.payload.collections[collection].config.flattenedFields,\n select,\n }),\n session: await getSession(this, req),\n }\n\n const query = await buildQuery({\n adapter: this,\n collectionSlug: collection,\n fields: this.payload.collections[collection].config.flattenedFields,\n locale,\n where,\n })\n\n let result\n\n const sanitizedData = sanitizeRelationshipIDs({\n config: this.payload.config,\n data,\n fields,\n })\n\n try {\n result = await Model.findOneAndUpdate(query, sanitizedData, options)\n } catch (error) {\n handleError({ collection, error, req })\n }\n\n if (!result) {\n return null\n }\n\n result = JSON.parse(JSON.stringify(result))\n result.id = result._id\n result = sanitizeInternalFields(result)\n\n return result\n}\n"],"names":["buildQuery","buildProjectionFromSelect","getSession","handleError","sanitizeInternalFields","sanitizeRelationshipIDs","updateOne","id","collection","data","locale","options","optionsArgs","req","select","where","whereArg","equals","Model","collections","fields","payload","config","lean","new","projection","adapter","flattenedFields","session","query","collectionSlug","result","sanitizedData","findOneAndUpdate","error","JSON","parse","stringify","_id"],"mappings":"AAKA,SAASA,UAAU,QAAQ,0BAAyB;AACpD,SAASC,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,WAAW,QAAQ,6BAA4B;AACxD,SAASC,sBAAsB,QAAQ,wCAAuC;AAC9E,SAASC,uBAAuB,QAAQ,yCAAwC;AAEhF,OAAO,MAAMC,YAAuB,eAAeA,UAEjD,EAAEC,EAAE,EAAEC,UAAU,EAAEC,IAAI,EAAEC,MAAM,EAAEC,SAASC,cAAc,CAAC,CAAC,EAAEC,GAAG,EAAEC,MAAM,EAAEC,OAAOC,QAAQ,EAAE;IAEzF,MAAMD,QAAQR,KAAK;QAAEA,IAAI;YAAEU,QAAQV;QAAG;IAAE,IAAIS;IAC5C,MAAME,QAAQ,IAAI,CAACC,WAAW,CAACX,WAAW;IAC1C,MAAMY,SAAS,IAAI,CAACC,OAAO,CAACF,WAAW,CAACX,WAAW,CAACc,MAAM,CAACF,MAAM;IACjE,MAAMT,UAAwB;QAC5B,GAAGC,WAAW;QACdW,MAAM;QACNC,KAAK;QACLC,YAAYxB,0BAA0B;YACpCyB,SAAS,IAAI;YACbN,QAAQ,IAAI,CAACC,OAAO,CAACF,WAAW,CAACX,WAAW,CAACc,MAAM,CAACK,eAAe;YACnEb;QACF;QACAc,SAAS,MAAM1B,WAAW,IAAI,EAAEW;IAClC;IAEA,MAAMgB,QAAQ,MAAM7B,WAAW;QAC7B0B,SAAS,IAAI;QACbI,gBAAgBtB;QAChBY,QAAQ,IAAI,CAACC,OAAO,CAACF,WAAW,CAACX,WAAW,CAACc,MAAM,CAACK,eAAe;QACnEjB;QACAK;IACF;IAEA,IAAIgB;IAEJ,MAAMC,gBAAgB3B,wBAAwB;QAC5CiB,QAAQ,IAAI,CAACD,OAAO,CAACC,MAAM;QAC3Bb;QACAW;IACF;IAEA,IAAI;QACFW,SAAS,MAAMb,MAAMe,gBAAgB,CAACJ,OAAOG,eAAerB;IAC9D,EAAE,OAAOuB,OAAO;QACd/B,YAAY;YAAEK;YAAY0B;YAAOrB;QAAI;IACvC;IAEA,IAAI,CAACkB,QAAQ;QACX,OAAO;IACT;IAEAA,SAASI,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACN;IACnCA,OAAOxB,EAAE,GAAGwB,OAAOO,GAAG;IACtBP,SAAS3B,uBAAuB2B;IAEhC,OAAOA;AACT,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"updateVersion.d.ts","sourceRoot":"","sources":["../src/updateVersion.ts"],"names":[],"mappings":"AAEA,OAAO,EAAgC,KAAK,aAAa,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"updateVersion.d.ts","sourceRoot":"","sources":["../src/updateVersion.ts"],"names":[],"mappings":"AAEA,OAAO,EAAgC,KAAK,aAAa,EAAE,MAAM,SAAS,CAAA;AAS1E,eAAO,MAAM,aAAa,EAAE,aA0D3B,CAAA"}
|
package/dist/updateVersion.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { buildVersionCollectionFields } from 'payload';
|
|
2
|
+
import { buildQuery } from './queries/buildQuery.js';
|
|
2
3
|
import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
|
|
3
4
|
import { getSession } from './utilities/getSession.js';
|
|
4
5
|
import { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.js';
|
|
@@ -10,20 +11,22 @@ export const updateVersion = async function updateVersion({ id, collection, loca
|
|
|
10
11
|
}
|
|
11
12
|
};
|
|
12
13
|
const fields = buildVersionCollectionFields(this.payload.config, this.payload.collections[collection].config);
|
|
14
|
+
const flattenedFields = buildVersionCollectionFields(this.payload.config, this.payload.collections[collection].config, true);
|
|
13
15
|
const options = {
|
|
14
16
|
...optionsArgs,
|
|
15
17
|
lean: true,
|
|
16
18
|
new: true,
|
|
17
19
|
projection: buildProjectionFromSelect({
|
|
18
20
|
adapter: this,
|
|
19
|
-
fields:
|
|
21
|
+
fields: flattenedFields,
|
|
20
22
|
select
|
|
21
23
|
}),
|
|
22
24
|
session: await getSession(this, req)
|
|
23
25
|
};
|
|
24
|
-
const query = await
|
|
26
|
+
const query = await buildQuery({
|
|
27
|
+
adapter: this,
|
|
28
|
+
fields: flattenedFields,
|
|
25
29
|
locale,
|
|
26
|
-
payload: this.payload,
|
|
27
30
|
where: whereToUse
|
|
28
31
|
});
|
|
29
32
|
const sanitizedData = sanitizeRelationshipIDs({
|
|
@@ -32,6 +35,9 @@ export const updateVersion = async function updateVersion({ id, collection, loca
|
|
|
32
35
|
fields
|
|
33
36
|
});
|
|
34
37
|
const doc = await VersionModel.findOneAndUpdate(query, sanitizedData, options);
|
|
38
|
+
if (!doc) {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
35
41
|
const result = JSON.parse(JSON.stringify(doc));
|
|
36
42
|
const verificationToken = doc._verificationToken;
|
|
37
43
|
// custom id type reset
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/updateVersion.ts"],"sourcesContent":["import type { QueryOptions } from 'mongoose'\n\nimport { buildVersionCollectionFields, type UpdateVersion } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getSession } from './utilities/getSession.js'\nimport { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.js'\n\nexport const updateVersion: UpdateVersion = async function updateVersion(\n this: MongooseAdapter,\n { id, collection, locale, options: optionsArgs = {}, req, select, versionData, where },\n) {\n const VersionModel = this.versions[collection]\n const whereToUse = where || { id: { equals: id } }\n const fields = buildVersionCollectionFields(\n this.payload.config,\n this.payload.collections[collection].config,\n )\n\n const options: QueryOptions = {\n ...optionsArgs,\n lean: true,\n new: true,\n projection: buildProjectionFromSelect({\n adapter: this,\n fields:
|
|
1
|
+
{"version":3,"sources":["../src/updateVersion.ts"],"sourcesContent":["import type { QueryOptions } from 'mongoose'\n\nimport { buildVersionCollectionFields, type UpdateVersion } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getSession } from './utilities/getSession.js'\nimport { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.js'\n\nexport const updateVersion: UpdateVersion = async function updateVersion(\n this: MongooseAdapter,\n { id, collection, locale, options: optionsArgs = {}, req, select, versionData, where },\n) {\n const VersionModel = this.versions[collection]\n const whereToUse = where || { id: { equals: id } }\n const fields = buildVersionCollectionFields(\n this.payload.config,\n this.payload.collections[collection].config,\n )\n\n const flattenedFields = buildVersionCollectionFields(\n this.payload.config,\n this.payload.collections[collection].config,\n true,\n )\n\n const options: QueryOptions = {\n ...optionsArgs,\n lean: true,\n new: true,\n projection: buildProjectionFromSelect({\n adapter: this,\n fields: flattenedFields,\n select,\n }),\n session: await getSession(this, req),\n }\n\n const query = await buildQuery({\n adapter: this,\n fields: flattenedFields,\n locale,\n where: whereToUse,\n })\n\n const sanitizedData = sanitizeRelationshipIDs({\n config: this.payload.config,\n data: versionData,\n fields,\n })\n\n const doc = await VersionModel.findOneAndUpdate(query, sanitizedData, options)\n\n if (!doc) {\n return null\n }\n\n const result = JSON.parse(JSON.stringify(doc))\n\n const verificationToken = doc._verificationToken\n\n // custom id type reset\n result.id = result._id\n if (verificationToken) {\n result._verificationToken = verificationToken\n }\n return result\n}\n"],"names":["buildVersionCollectionFields","buildQuery","buildProjectionFromSelect","getSession","sanitizeRelationshipIDs","updateVersion","id","collection","locale","options","optionsArgs","req","select","versionData","where","VersionModel","versions","whereToUse","equals","fields","payload","config","collections","flattenedFields","lean","new","projection","adapter","session","query","sanitizedData","data","doc","findOneAndUpdate","result","JSON","parse","stringify","verificationToken","_verificationToken","_id"],"mappings":"AAEA,SAASA,4BAA4B,QAA4B,UAAS;AA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,MAAMM,oBAAoBN,IAAIO,kBAAkB;IAEhD,uBAAuB;IACvBL,OAAO5B,EAAE,GAAG4B,OAAOM,GAAG;IACtB,IAAIF,mBAAmB;QACrBJ,OAAOK,kBAAkB,GAAGD;IAC9B;IACA,OAAOJ;AACT,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildJoinAggregation.d.ts","sourceRoot":"","sources":["../../src/utilities/buildJoinAggregation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAC7C,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"buildJoinAggregation.d.ts","sourceRoot":"","sources":["../../src/utilities/buildJoinAggregation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAC7C,OAAO,KAAK,EACV,cAAc,EAEd,SAAS,EACT,yBAAyB,EACzB,KAAK,EACN,MAAM,SAAS,CAAA;AAIhB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAKlD,KAAK,wBAAwB,GAAG;IAC9B,OAAO,EAAE,eAAe,CAAA;IACxB,UAAU,EAAE,cAAc,CAAA;IAC1B,gBAAgB,EAAE,yBAAyB,CAAA;IAC3C,KAAK,EAAE,SAAS,CAAA;IAEhB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,MAAM,CAAA;IACd,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAA;IAEjC,KAAK,CAAC,EAAE,KAAK,CAAA;IACb,uCAAuC;IACvC,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB,CAAA;AAED,eAAO,MAAM,oBAAoB,kGAU9B,wBAAwB,KAAG,OAAO,CAAC,aAAa,EAAE,GAAG,SAAS,CAkVhE,CAAA"}
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
+
import { fieldShouldBeLocalized } from 'payload/shared';
|
|
2
|
+
import { buildQuery } from '../queries/buildQuery.js';
|
|
1
3
|
import { buildSortParam } from '../queries/buildSortParam.js';
|
|
2
4
|
export const buildJoinAggregation = async ({ adapter, collection, collectionConfig, joins, limit, locale, projection, query, versions })=>{
|
|
3
|
-
if (Object.keys(collectionConfig.joins).length === 0 || joins === false) {
|
|
5
|
+
if (Object.keys(collectionConfig.joins).length === 0 && collectionConfig.polymorphicJoins.length == 0 || joins === false) {
|
|
4
6
|
return;
|
|
5
7
|
}
|
|
6
8
|
const joinConfig = adapter.payload.collections[collection].config.joins;
|
|
9
|
+
const polymorphicJoinsConfig = adapter.payload.collections[collection].config.polymorphicJoins;
|
|
7
10
|
const aggregate = [
|
|
8
11
|
{
|
|
9
12
|
$sort: {
|
|
@@ -21,16 +24,156 @@ export const buildJoinAggregation = async ({ adapter, collection, collectionConf
|
|
|
21
24
|
$limit: limit
|
|
22
25
|
});
|
|
23
26
|
}
|
|
27
|
+
for (const join of polymorphicJoinsConfig){
|
|
28
|
+
if (projection && !projection[join.joinPath]) {
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
if (joins?.[join.joinPath] === false) {
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
const { limit: limitJoin = join.field.defaultLimit ?? 10, page, sort: sortJoin = join.field.defaultSort || collectionConfig.defaultSort, where: whereJoin } = joins?.[join.joinPath] || {};
|
|
35
|
+
const aggregatedFields = [];
|
|
36
|
+
for (const collectionSlug of join.field.collection){
|
|
37
|
+
for (const field of adapter.payload.collections[collectionSlug].config.flattenedFields){
|
|
38
|
+
if (!aggregatedFields.some((eachField)=>eachField.name === field.name)) {
|
|
39
|
+
aggregatedFields.push(field);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
const sort = buildSortParam({
|
|
44
|
+
config: adapter.payload.config,
|
|
45
|
+
fields: aggregatedFields,
|
|
46
|
+
locale,
|
|
47
|
+
sort: sortJoin,
|
|
48
|
+
timestamps: true
|
|
49
|
+
});
|
|
50
|
+
const $match = await buildQuery({
|
|
51
|
+
adapter,
|
|
52
|
+
fields: aggregatedFields,
|
|
53
|
+
locale,
|
|
54
|
+
where: whereJoin
|
|
55
|
+
});
|
|
56
|
+
const sortProperty = Object.keys(sort)[0];
|
|
57
|
+
const sortDirection = sort[sortProperty] === 'asc' ? 1 : -1;
|
|
58
|
+
const projectSort = sortProperty !== '_id' && sortProperty !== 'relationTo';
|
|
59
|
+
const aliases = [];
|
|
60
|
+
const as = join.joinPath;
|
|
61
|
+
for (const collectionSlug of join.field.collection){
|
|
62
|
+
const alias = `${as}.docs.${collectionSlug}`;
|
|
63
|
+
aliases.push(alias);
|
|
64
|
+
aggregate.push({
|
|
65
|
+
$lookup: {
|
|
66
|
+
as: alias,
|
|
67
|
+
from: adapter.collections[collectionSlug].collection.name,
|
|
68
|
+
let: {
|
|
69
|
+
root_id_: '$_id'
|
|
70
|
+
},
|
|
71
|
+
pipeline: [
|
|
72
|
+
{
|
|
73
|
+
$addFields: {
|
|
74
|
+
relationTo: {
|
|
75
|
+
$literal: collectionSlug
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
$match: {
|
|
81
|
+
$and: [
|
|
82
|
+
{
|
|
83
|
+
$expr: {
|
|
84
|
+
$eq: [
|
|
85
|
+
`$${join.field.on}`,
|
|
86
|
+
'$$root_id_'
|
|
87
|
+
]
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
$match
|
|
91
|
+
]
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
$sort: {
|
|
96
|
+
[sortProperty]: sortDirection
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
// Unfortunately, we can't use $skip here because we can lose data, instead we do $slice then
|
|
101
|
+
$limit: page ? page * limitJoin : limitJoin
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
$project: {
|
|
105
|
+
value: '$_id',
|
|
106
|
+
...projectSort && {
|
|
107
|
+
[sortProperty]: 1
|
|
108
|
+
},
|
|
109
|
+
relationTo: 1
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
]
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
aggregate.push({
|
|
117
|
+
$addFields: {
|
|
118
|
+
[`${as}.docs`]: {
|
|
119
|
+
$concatArrays: aliases.map((alias)=>`$${alias}`)
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
aggregate.push({
|
|
124
|
+
$set: {
|
|
125
|
+
[`${as}.docs`]: {
|
|
126
|
+
$sortArray: {
|
|
127
|
+
input: `$${as}.docs`,
|
|
128
|
+
sortBy: {
|
|
129
|
+
[sortProperty]: sortDirection
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
const sliceValue = page ? [
|
|
136
|
+
(page - 1) * limitJoin,
|
|
137
|
+
limitJoin
|
|
138
|
+
] : [
|
|
139
|
+
limitJoin
|
|
140
|
+
];
|
|
141
|
+
aggregate.push({
|
|
142
|
+
$set: {
|
|
143
|
+
[`${as}.docs`]: {
|
|
144
|
+
$slice: [
|
|
145
|
+
`$${as}.docs`,
|
|
146
|
+
...sliceValue
|
|
147
|
+
]
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
aggregate.push({
|
|
152
|
+
$addFields: {
|
|
153
|
+
[`${as}.hasNextPage`]: {
|
|
154
|
+
$gt: [
|
|
155
|
+
{
|
|
156
|
+
$size: `$${as}.docs`
|
|
157
|
+
},
|
|
158
|
+
limitJoin || Number.MAX_VALUE
|
|
159
|
+
]
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
}
|
|
24
164
|
for (const slug of Object.keys(joinConfig)){
|
|
25
165
|
for (const join of joinConfig[slug]){
|
|
26
|
-
const joinModel = adapter.collections[join.field.collection];
|
|
27
166
|
if (projection && !projection[join.joinPath]) {
|
|
28
167
|
continue;
|
|
29
168
|
}
|
|
30
169
|
if (joins?.[join.joinPath] === false) {
|
|
31
170
|
continue;
|
|
32
171
|
}
|
|
33
|
-
const { limit: limitJoin = join.field.defaultLimit ?? 10, sort: sortJoin = join.field.defaultSort || collectionConfig.defaultSort, where: whereJoin } = joins?.[join.joinPath] || {};
|
|
172
|
+
const { limit: limitJoin = join.field.defaultLimit ?? 10, page, sort: sortJoin = join.field.defaultSort || collectionConfig.defaultSort, where: whereJoin } = joins?.[join.joinPath] || {};
|
|
173
|
+
if (Array.isArray(join.field.collection)) {
|
|
174
|
+
throw new Error('Unreachable');
|
|
175
|
+
}
|
|
176
|
+
const joinModel = adapter.collections[join.field.collection];
|
|
34
177
|
const sort = buildSortParam({
|
|
35
178
|
config: adapter.payload.config,
|
|
36
179
|
fields: adapter.payload.collections[slug].config.flattenedFields,
|
|
@@ -55,6 +198,11 @@ export const buildJoinAggregation = async ({ adapter, collection, collectionConf
|
|
|
55
198
|
}
|
|
56
199
|
}
|
|
57
200
|
];
|
|
201
|
+
if (page) {
|
|
202
|
+
pipeline.push({
|
|
203
|
+
$skip: (page - 1) * limitJoin
|
|
204
|
+
});
|
|
205
|
+
}
|
|
58
206
|
if (limitJoin > 0) {
|
|
59
207
|
pipeline.push({
|
|
60
208
|
$limit: limitJoin + 1
|
|
@@ -108,7 +256,10 @@ export const buildJoinAggregation = async ({ adapter, collection, collectionConf
|
|
|
108
256
|
}
|
|
109
257
|
});
|
|
110
258
|
} else {
|
|
111
|
-
const localeSuffix =
|
|
259
|
+
const localeSuffix = fieldShouldBeLocalized({
|
|
260
|
+
field: join.field,
|
|
261
|
+
parentIsLocalized: join.parentIsLocalized
|
|
262
|
+
}) && adapter.payload.config.localization && locale ? `.${locale}` : '';
|
|
112
263
|
const as = `${versions ? `version.${join.joinPath}` : join.joinPath}${localeSuffix}`;
|
|
113
264
|
let foreignField;
|
|
114
265
|
if (join.getForeignPath) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/buildJoinAggregation.ts"],"sourcesContent":["import type { PipelineStage } from 'mongoose'\nimport type { CollectionSlug, JoinQuery, SanitizedCollectionConfig, Where } from 'payload'\n\nimport type { MongooseAdapter } from '../index.js'\n\nimport { buildSortParam } from '../queries/buildSortParam.js'\n\ntype BuildJoinAggregationArgs = {\n adapter: MongooseAdapter\n collection: CollectionSlug\n collectionConfig: SanitizedCollectionConfig\n joins: JoinQuery\n // the number of docs to get at the top collection level\n limit?: number\n locale: string\n projection?: Record<string, true>\n // the where clause for the top collection\n query?: Where\n /** whether the query is from drafts */\n versions?: boolean\n}\n\nexport const buildJoinAggregation = async ({\n adapter,\n collection,\n collectionConfig,\n joins,\n limit,\n locale,\n projection,\n query,\n versions,\n}: BuildJoinAggregationArgs): Promise<PipelineStage[] | undefined> => {\n if (Object.keys(collectionConfig.joins).length === 0 || joins === false) {\n return\n }\n\n const joinConfig = adapter.payload.collections[collection].config.joins\n const aggregate: PipelineStage[] = [\n {\n $sort: { createdAt: -1 },\n },\n ]\n\n if (query) {\n aggregate.push({\n $match: query,\n })\n }\n\n if (limit) {\n aggregate.push({\n $limit: limit,\n })\n }\n\n for (const slug of Object.keys(joinConfig)) {\n for (const join of joinConfig[slug]) {\n const joinModel = adapter.collections[join.field.collection]\n\n if (projection && !projection[join.joinPath]) {\n continue\n }\n\n if (joins?.[join.joinPath] === false) {\n continue\n }\n\n const {\n limit: limitJoin = join.field.defaultLimit ?? 10,\n sort: sortJoin = join.field.defaultSort || collectionConfig.defaultSort,\n where: whereJoin,\n } = joins?.[join.joinPath] || {}\n\n const sort = buildSortParam({\n config: adapter.payload.config,\n fields: adapter.payload.collections[slug].config.flattenedFields,\n locale,\n sort: sortJoin,\n timestamps: true,\n })\n const sortProperty = Object.keys(sort)[0]\n const sortDirection = sort[sortProperty] === 'asc' ? 1 : -1\n\n const $match = await joinModel.buildQuery({\n locale,\n payload: adapter.payload,\n where: whereJoin,\n })\n\n const pipeline: Exclude<PipelineStage, PipelineStage.Merge | PipelineStage.Out>[] = [\n { $match },\n {\n $sort: { [sortProperty]: sortDirection },\n },\n ]\n\n if (limitJoin > 0) {\n pipeline.push({\n $limit: limitJoin + 1,\n })\n }\n\n let polymorphicSuffix = ''\n if (Array.isArray(join.targetField.relationTo)) {\n polymorphicSuffix = '.value'\n }\n\n if (adapter.payload.config.localization && locale === 'all') {\n adapter.payload.config.localization.localeCodes.forEach((code) => {\n const as = `${versions ? `version.${join.joinPath}` : join.joinPath}${code}`\n\n aggregate.push(\n {\n $lookup: {\n as: `${as}.docs`,\n foreignField: `${join.field.on}${code}${polymorphicSuffix}`,\n from: adapter.collections[slug].collection.name,\n localField: versions ? 'parent' : '_id',\n pipeline,\n },\n },\n {\n $addFields: {\n [`${as}.docs`]: {\n $map: {\n as: 'doc',\n in: '$$doc._id',\n input: `$${as}.docs`,\n },\n }, // Slicing the docs to match the limit\n [`${as}.hasNextPage`]: limitJoin\n ? { $gt: [{ $size: `$${as}.docs` }, limitJoin] }\n : false,\n // Boolean indicating if more docs than limit\n },\n },\n )\n if (limitJoin > 0) {\n aggregate.push({\n $addFields: {\n [`${as}.docs`]: {\n $slice: [`$${as}.docs`, limitJoin],\n },\n },\n })\n }\n })\n } else {\n const localeSuffix =\n join.field.localized && adapter.payload.config.localization && locale ? `.${locale}` : ''\n const as = `${versions ? `version.${join.joinPath}` : join.joinPath}${localeSuffix}`\n\n let foreignField: string\n\n if (join.getForeignPath) {\n foreignField = `${join.getForeignPath({ locale })}${polymorphicSuffix}`\n } else {\n foreignField = `${join.field.on}${polymorphicSuffix}`\n }\n\n aggregate.push(\n {\n $lookup: {\n as: `${as}.docs`,\n foreignField,\n from: adapter.collections[slug].collection.name,\n localField: versions ? 'parent' : '_id',\n pipeline,\n },\n },\n {\n $addFields: {\n [`${as}.docs`]: {\n $map: {\n as: 'doc',\n in: '$$doc._id',\n input: `$${as}.docs`,\n },\n }, // Slicing the docs to match the limit\n [`${as}.hasNextPage`]: {\n $gt: [{ $size: `$${as}.docs` }, limitJoin || Number.MAX_VALUE],\n }, // Boolean indicating if more docs than limit\n },\n },\n )\n if (limitJoin > 0) {\n aggregate.push({\n $addFields: {\n [`${as}.docs`]: {\n $slice: [`$${as}.docs`, limitJoin],\n },\n },\n })\n }\n }\n }\n }\n\n if (projection) {\n aggregate.push({ $project: projection })\n }\n\n return aggregate\n}\n"],"names":["buildSortParam","buildJoinAggregation","adapter","collection","collectionConfig","joins","limit","locale","projection","query","versions","Object","keys","length","joinConfig","payload","collections","config","aggregate","$sort","createdAt","push","$match","$limit","slug","join","joinModel","field","joinPath","limitJoin","defaultLimit","sort","sortJoin","defaultSort","where","whereJoin","fields","flattenedFields","timestamps","sortProperty","sortDirection","buildQuery","pipeline","polymorphicSuffix","Array","isArray","targetField","relationTo","localization","localeCodes","forEach","code","as","$lookup","foreignField","on","from","name","localField","$addFields","$map","in","input","$gt","$size","$slice","localeSuffix","localized","getForeignPath","Number","MAX_VALUE","$project"],"mappings":"AAKA,SAASA,cAAc,QAAQ,+BAA8B;AAiB7D,OAAO,MAAMC,uBAAuB,OAAO,EACzCC,OAAO,EACPC,UAAU,EACVC,gBAAgB,EAChBC,KAAK,EACLC,KAAK,EACLC,MAAM,EACNC,UAAU,EACVC,KAAK,EACLC,QAAQ,EACiB;IACzB,IAAIC,OAAOC,IAAI,CAACR,iBAAiBC,KAAK,EAAEQ,MAAM,KAAK,KAAKR,UAAU,OAAO;QACvE;IACF;IAEA,MAAMS,aAAaZ,QAAQa,OAAO,CAACC,WAAW,CAACb,WAAW,CAACc,MAAM,CAACZ,KAAK;IACvE,MAAMa,YAA6B;QACjC;YACEC,OAAO;gBAAEC,WAAW,CAAC;YAAE;QACzB;KACD;IAED,IAAIX,OAAO;QACTS,UAAUG,IAAI,CAAC;YACbC,QAAQb;QACV;IACF;IAEA,IAAIH,OAAO;QACTY,UAAUG,IAAI,CAAC;YACbE,Q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BACpC;wBACF;oBACF;gBACF;YACF;QACF;IACF;IAEA,IAAIrB,YAAY;QACdU,UAAUG,IAAI,CAAC;YAAEkD,UAAU/D;QAAW;IACxC;IAEA,OAAOU;AACT,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/buildJoinAggregation.ts"],"sourcesContent":["import type { PipelineStage } from 'mongoose'\nimport type {\n CollectionSlug,\n FlattenedField,\n JoinQuery,\n SanitizedCollectionConfig,\n Where,\n} from 'payload'\n\nimport { fieldShouldBeLocalized } from 'payload/shared'\n\nimport type { MongooseAdapter } from '../index.js'\n\nimport { buildQuery } from '../queries/buildQuery.js'\nimport { buildSortParam } from '../queries/buildSortParam.js'\n\ntype BuildJoinAggregationArgs = {\n adapter: MongooseAdapter\n collection: CollectionSlug\n collectionConfig: SanitizedCollectionConfig\n joins: JoinQuery\n // the number of docs to get at the top collection level\n limit?: number\n locale: string\n projection?: Record<string, true>\n // the where clause for the top collection\n query?: Where\n /** whether the query is from drafts */\n versions?: boolean\n}\n\nexport const buildJoinAggregation = async ({\n adapter,\n collection,\n collectionConfig,\n joins,\n limit,\n locale,\n projection,\n query,\n versions,\n}: BuildJoinAggregationArgs): Promise<PipelineStage[] | undefined> => {\n if (\n (Object.keys(collectionConfig.joins).length === 0 &&\n collectionConfig.polymorphicJoins.length == 0) ||\n joins === false\n ) {\n return\n }\n\n const joinConfig = adapter.payload.collections[collection].config.joins\n const polymorphicJoinsConfig = adapter.payload.collections[collection].config.polymorphicJoins\n const aggregate: PipelineStage[] = [\n {\n $sort: { createdAt: -1 },\n },\n ]\n\n if (query) {\n aggregate.push({\n $match: query,\n })\n }\n\n if (limit) {\n aggregate.push({\n $limit: limit,\n })\n }\n\n for (const join of polymorphicJoinsConfig) {\n if (projection && !projection[join.joinPath]) {\n continue\n }\n\n if (joins?.[join.joinPath] === false) {\n continue\n }\n\n const {\n limit: limitJoin = join.field.defaultLimit ?? 10,\n page,\n sort: sortJoin = join.field.defaultSort || collectionConfig.defaultSort,\n where: whereJoin,\n } = joins?.[join.joinPath] || {}\n\n const aggregatedFields: FlattenedField[] = []\n for (const collectionSlug of join.field.collection) {\n for (const field of adapter.payload.collections[collectionSlug].config.flattenedFields) {\n if (!aggregatedFields.some((eachField) => eachField.name === field.name)) {\n aggregatedFields.push(field)\n }\n }\n }\n\n const sort = buildSortParam({\n config: adapter.payload.config,\n fields: aggregatedFields,\n locale,\n sort: sortJoin,\n timestamps: true,\n })\n\n const $match = await buildQuery({\n adapter,\n fields: aggregatedFields,\n locale,\n where: whereJoin,\n })\n\n const sortProperty = Object.keys(sort)[0]\n const sortDirection = sort[sortProperty] === 'asc' ? 1 : -1\n\n const projectSort = sortProperty !== '_id' && sortProperty !== 'relationTo'\n\n const aliases: string[] = []\n\n const as = join.joinPath\n\n for (const collectionSlug of join.field.collection) {\n const alias = `${as}.docs.${collectionSlug}`\n aliases.push(alias)\n\n aggregate.push({\n $lookup: {\n as: alias,\n from: adapter.collections[collectionSlug].collection.name,\n let: {\n root_id_: '$_id',\n },\n pipeline: [\n {\n $addFields: {\n relationTo: {\n $literal: collectionSlug,\n },\n },\n },\n {\n $match: {\n $and: [\n {\n $expr: {\n $eq: [`$${join.field.on}`, '$$root_id_'],\n },\n },\n $match,\n ],\n },\n },\n {\n $sort: {\n [sortProperty]: sortDirection,\n },\n },\n {\n // Unfortunately, we can't use $skip here because we can lose data, instead we do $slice then\n $limit: page ? page * limitJoin : limitJoin,\n },\n {\n $project: {\n value: '$_id',\n ...(projectSort && {\n [sortProperty]: 1,\n }),\n relationTo: 1,\n },\n },\n ],\n },\n })\n }\n\n aggregate.push({\n $addFields: {\n [`${as}.docs`]: {\n $concatArrays: aliases.map((alias) => `$${alias}`),\n },\n },\n })\n\n aggregate.push({\n $set: {\n [`${as}.docs`]: {\n $sortArray: {\n input: `$${as}.docs`,\n sortBy: {\n [sortProperty]: sortDirection,\n },\n },\n },\n },\n })\n\n const sliceValue = page ? [(page - 1) * limitJoin, limitJoin] : [limitJoin]\n\n aggregate.push({\n $set: {\n [`${as}.docs`]: {\n $slice: [`$${as}.docs`, ...sliceValue],\n },\n },\n })\n\n aggregate.push({\n $addFields: {\n [`${as}.hasNextPage`]: {\n $gt: [{ $size: `$${as}.docs` }, limitJoin || Number.MAX_VALUE],\n },\n },\n })\n }\n\n for (const slug of Object.keys(joinConfig)) {\n for (const join of joinConfig[slug]) {\n if (projection && !projection[join.joinPath]) {\n continue\n }\n\n if (joins?.[join.joinPath] === false) {\n continue\n }\n\n const {\n limit: limitJoin = join.field.defaultLimit ?? 10,\n page,\n sort: sortJoin = join.field.defaultSort || collectionConfig.defaultSort,\n where: whereJoin,\n } = joins?.[join.joinPath] || {}\n\n if (Array.isArray(join.field.collection)) {\n throw new Error('Unreachable')\n }\n\n const joinModel = adapter.collections[join.field.collection]\n\n const sort = buildSortParam({\n config: adapter.payload.config,\n fields: adapter.payload.collections[slug].config.flattenedFields,\n locale,\n sort: sortJoin,\n timestamps: true,\n })\n const sortProperty = Object.keys(sort)[0]\n const sortDirection = sort[sortProperty] === 'asc' ? 1 : -1\n\n const $match = await joinModel.buildQuery({\n locale,\n payload: adapter.payload,\n where: whereJoin,\n })\n\n const pipeline: Exclude<PipelineStage, PipelineStage.Merge | PipelineStage.Out>[] = [\n { $match },\n {\n $sort: { [sortProperty]: sortDirection },\n },\n ]\n\n if (page) {\n pipeline.push({\n $skip: (page - 1) * limitJoin,\n })\n }\n\n if (limitJoin > 0) {\n pipeline.push({\n $limit: limitJoin + 1,\n })\n }\n\n let polymorphicSuffix = ''\n if (Array.isArray(join.targetField.relationTo)) {\n polymorphicSuffix = '.value'\n }\n\n if (adapter.payload.config.localization && locale === 'all') {\n adapter.payload.config.localization.localeCodes.forEach((code) => {\n const as = `${versions ? `version.${join.joinPath}` : join.joinPath}${code}`\n\n aggregate.push(\n {\n $lookup: {\n as: `${as}.docs`,\n foreignField: `${join.field.on}${code}${polymorphicSuffix}`,\n from: adapter.collections[slug].collection.name,\n localField: versions ? 'parent' : '_id',\n pipeline,\n },\n },\n {\n $addFields: {\n [`${as}.docs`]: {\n $map: {\n as: 'doc',\n in: '$$doc._id',\n input: `$${as}.docs`,\n },\n }, // Slicing the docs to match the limit\n [`${as}.hasNextPage`]: limitJoin\n ? { $gt: [{ $size: `$${as}.docs` }, limitJoin] }\n : false,\n // Boolean indicating if more docs than limit\n },\n },\n )\n if (limitJoin > 0) {\n aggregate.push({\n $addFields: {\n [`${as}.docs`]: {\n $slice: [`$${as}.docs`, limitJoin],\n },\n },\n })\n }\n })\n } else {\n const localeSuffix =\n fieldShouldBeLocalized({\n field: join.field,\n parentIsLocalized: join.parentIsLocalized,\n }) &&\n adapter.payload.config.localization &&\n locale\n ? `.${locale}`\n : ''\n const as = `${versions ? `version.${join.joinPath}` : join.joinPath}${localeSuffix}`\n\n let foreignField: string\n\n if (join.getForeignPath) {\n foreignField = `${join.getForeignPath({ locale })}${polymorphicSuffix}`\n } else {\n foreignField = `${join.field.on}${polymorphicSuffix}`\n }\n\n aggregate.push(\n {\n $lookup: {\n as: `${as}.docs`,\n foreignField,\n from: adapter.collections[slug].collection.name,\n localField: versions ? 'parent' : '_id',\n pipeline,\n },\n },\n {\n $addFields: {\n [`${as}.docs`]: {\n $map: {\n as: 'doc',\n in: '$$doc._id',\n input: `$${as}.docs`,\n },\n }, // Slicing the docs to match the limit\n [`${as}.hasNextPage`]: {\n $gt: [{ $size: `$${as}.docs` }, limitJoin || Number.MAX_VALUE],\n }, // Boolean indicating if more docs than limit\n },\n },\n )\n if (limitJoin > 0) {\n aggregate.push({\n $addFields: {\n [`${as}.docs`]: {\n $slice: [`$${as}.docs`, limitJoin],\n },\n },\n })\n }\n }\n }\n }\n\n if (projection) {\n aggregate.push({ $project: projection })\n }\n\n return aggregate\n}\n"],"names":["fieldShouldBeLocalized","buildQuery","buildSortParam","buildJoinAggregation","adapter","collection","collectionConfig","joins","limit","locale","projection","query","versions","Object","keys","length","polymorphicJoins","joinConfig","payload","collections","config","polymorphicJoinsConfig","aggregate","$sort","createdAt","push","$match","$limit","join","joinPath","limitJoin","field","defaultLimit","page","sort","sortJoin","defaultSort","where","whereJoin","aggregatedFields","collectionSlug","flattenedFields","some","eachField","name","fields","timestamps","sortProperty","sortDirection","projectSort","aliases","as","alias","$lookup","from","let","root_id_","pipeline","$addFields","relationTo","$literal","$and","$expr","$eq","on","$project","value","$concatArrays","map","$set","$sortArray","input","sortBy","sliceValue","$slice","$gt","$size","Number","MAX_VALUE","slug","Array","isArray","Error","joinModel","$skip","polymorphicSuffix","targetField","localization","localeCodes","forEach","code","foreignField","localField","$map","in","localeSuffix","parentIsLocalized","getForeignPath"],"mappings":"AASA,SAASA,sBAAsB,QAAQ,iBAAgB;AAIvD,SAASC,UAAU,QAAQ,2BAA0B;AACrD,SAASC,cAAc,QAAQ,+BAA8B;AAiB7D,OAAO,MAAMC,uBAAuB,OAAO,EACzCC,OAAO,EACPC,UAAU,EACVC,gBAAgB,EAChBC,KAAK,EACLC,KAAK,EACLC,MAAM,EACNC,UAAU,EACVC,KAAK,EACLC,QAAQ,EACiB;IACzB,IACE,AAACC,OAAOC,IAAI,CAACR,iBAAiBC,KAAK,EAAEQ,MAAM,KAAK,KAC9CT,iBAAiBU,gBAAgB,CAACD,MAAM,IAAI,KAC9CR,UAAU,OACV;QACA;IACF;IAEA,MAAMU,aAAab,QAAQc,OAAO,CAACC,WAAW,CAACd,WAAW,CAACe,MAAM,CAACb,KAAK;IACvE,MAAMc,yBAAyBjB,QAAQc,OAAO,CAACC,WAAW,CAACd,WAAW,CAACe,MAAM,CAACJ,gBAAgB;IAC9F,MAAMM,YAA6B;QACjC;YACEC,OAAO;gBAAEC,WAAW,CAAC;YAAE;QACzB;KACD;IAED,IAAIb,OAAO;QACTW,UAAUG,IAAI,CAAC;YACbC,QAAQf;QACV;IACF;IAEA,IAAIH,OAAO;QACTc,UAAUG,IAAI,CAAC;YACbE,QAAQnB;QACV;IACF;IAEA,KAAK,MAAMoB,QAAQP,uBAAwB;QACzC,IAA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;oBACE4B,SAAS;wBACPF,IAAI,GAAGA,GAAG,KAAK,CAAC;wBAChBwC;wBACArC,MAAMlD,QAAQe,WAAW,CAAC4D,KAAK,CAAC1E,UAAU,CAACuC,IAAI;wBAC/CgD,YAAYhF,WAAW,WAAW;wBAClC6C;oBACF;gBACF,GACA;oBACEC,YAAY;wBACV,CAAC,GAAGP,GAAG,KAAK,CAAC,CAAC,EAAE;4BACd0C,MAAM;gCACJ1C,IAAI;gCACJ2C,IAAI;gCACJvB,OAAO,CAAC,CAAC,EAAEpB,GAAG,KAAK,CAAC;4BACtB;wBACF;wBACA,CAAC,GAAGA,GAAG,YAAY,CAAC,CAAC,EAAE;4BACrBwB,KAAK;gCAAC;oCAAEC,OAAO,CAAC,CAAC,EAAEzB,GAAG,KAAK,CAAC;gCAAC;gCAAGrB,aAAa+C,OAAOC,SAAS;6BAAC;wBAChE;oBACF;gBACF;gBAEF,IAAIhD,YAAY,GAAG;oBACjBR,UAAUG,IAAI,CAAC;wBACbiC,YAAY;4BACV,CAAC,GAAGP,GAAG,KAAK,CAAC,CAAC,EAAE;gCACduB,QAAQ;oCAAC,CAAC,CAAC,EAAEvB,GAAG,KAAK,CAAC;oCAAErB;iCAAU;4BACpC;wBACF;oBACF;gBACF;YACF;QACF;IACF;IAEA,IAAIpB,YAAY;QACdY,UAAUG,IAAI,CAAC;YAAEwC,UAAUvD;QAAW;IACxC;IAEA,OAAOY;AACT,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildProjectionFromSelect.d.ts","sourceRoot":"","sources":["../../src/utilities/buildProjectionFromSelect.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAsB,cAAc,EAAc,UAAU,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"buildProjectionFromSelect.d.ts","sourceRoot":"","sources":["../../src/utilities/buildProjectionFromSelect.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAsB,cAAc,EAAc,UAAU,EAAE,MAAM,SAAS,CAAA;AASzF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AA6KlD,eAAO,MAAM,yBAAyB,iCAInC;IACD,OAAO,EAAE,eAAe,CAAA;IACxB,MAAM,EAAE,cAAc,EAAE,CAAA;IACxB,MAAM,CAAC,EAAE,UAAU,CAAA;CACpB,KAAG,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,SAmB1B,CAAA"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { deepCopyObjectSimple, fieldAffectsData, getSelectMode } from 'payload/shared';
|
|
2
|
-
const addFieldToProjection = ({ adapter, databaseSchemaPath, field,
|
|
1
|
+
import { deepCopyObjectSimple, fieldAffectsData, fieldShouldBeLocalized, getSelectMode } from 'payload/shared';
|
|
2
|
+
const addFieldToProjection = ({ adapter, databaseSchemaPath, field, parentIsLocalized, projection })=>{
|
|
3
3
|
const { config } = adapter.payload;
|
|
4
|
-
if (
|
|
4
|
+
if (parentIsLocalized && config.localization) {
|
|
5
5
|
for (const locale of config.localization.localeCodes){
|
|
6
6
|
const localeDatabaseSchemaPath = databaseSchemaPath.replace('<locale>', locale);
|
|
7
7
|
projection[`${localeDatabaseSchemaPath}${field.name}`] = true;
|
|
@@ -10,7 +10,7 @@ const addFieldToProjection = ({ adapter, databaseSchemaPath, field, projection,
|
|
|
10
10
|
projection[`${databaseSchemaPath}${field.name}`] = true;
|
|
11
11
|
}
|
|
12
12
|
};
|
|
13
|
-
const traverseFields = ({ adapter, databaseSchemaPath = '', fields, projection, select, selectAllOnCurrentLevel = false, selectMode
|
|
13
|
+
const traverseFields = ({ adapter, databaseSchemaPath = '', fields, parentIsLocalized = false, projection, select, selectAllOnCurrentLevel = false, selectMode })=>{
|
|
14
14
|
for (const field of fields){
|
|
15
15
|
if (fieldAffectsData(field)) {
|
|
16
16
|
if (selectMode === 'include') {
|
|
@@ -19,8 +19,8 @@ const traverseFields = ({ adapter, databaseSchemaPath = '', fields, projection,
|
|
|
19
19
|
adapter,
|
|
20
20
|
databaseSchemaPath,
|
|
21
21
|
field,
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
parentIsLocalized,
|
|
23
|
+
projection
|
|
24
24
|
});
|
|
25
25
|
continue;
|
|
26
26
|
}
|
|
@@ -34,8 +34,8 @@ const traverseFields = ({ adapter, databaseSchemaPath = '', fields, projection,
|
|
|
34
34
|
adapter,
|
|
35
35
|
databaseSchemaPath,
|
|
36
36
|
field,
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
parentIsLocalized,
|
|
38
|
+
projection
|
|
39
39
|
});
|
|
40
40
|
continue;
|
|
41
41
|
}
|
|
@@ -45,12 +45,13 @@ const traverseFields = ({ adapter, databaseSchemaPath = '', fields, projection,
|
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
let fieldDatabaseSchemaPath = databaseSchemaPath;
|
|
48
|
-
let fieldWithinLocalizedField = withinLocalizedField;
|
|
49
48
|
if (fieldAffectsData(field)) {
|
|
50
49
|
fieldDatabaseSchemaPath = `${databaseSchemaPath}${field.name}.`;
|
|
51
|
-
if (
|
|
50
|
+
if (fieldShouldBeLocalized({
|
|
51
|
+
field,
|
|
52
|
+
parentIsLocalized
|
|
53
|
+
})) {
|
|
52
54
|
fieldDatabaseSchemaPath = `${fieldDatabaseSchemaPath}<locale>.`;
|
|
53
|
-
fieldWithinLocalizedField = true;
|
|
54
55
|
}
|
|
55
56
|
}
|
|
56
57
|
switch(field.type){
|
|
@@ -66,10 +67,10 @@ const traverseFields = ({ adapter, databaseSchemaPath = '', fields, projection,
|
|
|
66
67
|
adapter,
|
|
67
68
|
databaseSchemaPath: fieldDatabaseSchemaPath,
|
|
68
69
|
fields: field.flattenedFields,
|
|
70
|
+
parentIsLocalized: parentIsLocalized || field.localized,
|
|
69
71
|
projection,
|
|
70
72
|
select: fieldSelect,
|
|
71
|
-
selectMode
|
|
72
|
-
withinLocalizedField: fieldWithinLocalizedField
|
|
73
|
+
selectMode
|
|
73
74
|
});
|
|
74
75
|
break;
|
|
75
76
|
}
|
|
@@ -83,11 +84,11 @@ const traverseFields = ({ adapter, databaseSchemaPath = '', fields, projection,
|
|
|
83
84
|
adapter,
|
|
84
85
|
databaseSchemaPath: fieldDatabaseSchemaPath,
|
|
85
86
|
fields: block.flattenedFields,
|
|
87
|
+
parentIsLocalized: parentIsLocalized || field.localized,
|
|
86
88
|
projection,
|
|
87
89
|
select: {},
|
|
88
90
|
selectAllOnCurrentLevel: true,
|
|
89
|
-
selectMode: 'include'
|
|
90
|
-
withinLocalizedField: fieldWithinLocalizedField
|
|
91
|
+
selectMode: 'include'
|
|
91
92
|
});
|
|
92
93
|
continue;
|
|
93
94
|
}
|
|
@@ -106,10 +107,10 @@ const traverseFields = ({ adapter, databaseSchemaPath = '', fields, projection,
|
|
|
106
107
|
adapter,
|
|
107
108
|
databaseSchemaPath: fieldDatabaseSchemaPath,
|
|
108
109
|
fields: block.flattenedFields,
|
|
110
|
+
parentIsLocalized: parentIsLocalized || field.localized,
|
|
109
111
|
projection,
|
|
110
112
|
select: blocksSelect[block.slug],
|
|
111
|
-
selectMode: blockSelectMode
|
|
112
|
-
withinLocalizedField: fieldWithinLocalizedField
|
|
113
|
+
selectMode: blockSelectMode
|
|
113
114
|
});
|
|
114
115
|
}
|
|
115
116
|
break;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/buildProjectionFromSelect.ts"],"sourcesContent":["import type { FieldAffectingData, FlattenedField, SelectMode, SelectType } from 'payload'\n\nimport {
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/buildProjectionFromSelect.ts"],"sourcesContent":["import type { FieldAffectingData, FlattenedField, SelectMode, SelectType } from 'payload'\n\nimport {\n deepCopyObjectSimple,\n fieldAffectsData,\n fieldShouldBeLocalized,\n getSelectMode,\n} from 'payload/shared'\n\nimport type { MongooseAdapter } from '../index.js'\n\nconst addFieldToProjection = ({\n adapter,\n databaseSchemaPath,\n field,\n parentIsLocalized,\n projection,\n}: {\n adapter: MongooseAdapter\n databaseSchemaPath: string\n field: FieldAffectingData\n parentIsLocalized: boolean\n projection: Record<string, true>\n}) => {\n const { config } = adapter.payload\n\n if (parentIsLocalized && config.localization) {\n for (const locale of config.localization.localeCodes) {\n const localeDatabaseSchemaPath = databaseSchemaPath.replace('<locale>', locale)\n projection[`${localeDatabaseSchemaPath}${field.name}`] = true\n }\n } else {\n projection[`${databaseSchemaPath}${field.name}`] = true\n }\n}\n\nconst traverseFields = ({\n adapter,\n databaseSchemaPath = '',\n fields,\n parentIsLocalized = false,\n projection,\n select,\n selectAllOnCurrentLevel = false,\n selectMode,\n}: {\n adapter: MongooseAdapter\n databaseSchemaPath?: string\n fields: FlattenedField[]\n parentIsLocalized?: boolean\n projection: Record<string, true>\n select: SelectType\n selectAllOnCurrentLevel?: boolean\n selectMode: SelectMode\n}) => {\n for (const field of fields) {\n if (fieldAffectsData(field)) {\n if (selectMode === 'include') {\n if (select[field.name] === true || selectAllOnCurrentLevel) {\n addFieldToProjection({\n adapter,\n databaseSchemaPath,\n field,\n parentIsLocalized,\n projection,\n })\n continue\n }\n\n if (!select[field.name]) {\n continue\n }\n }\n\n if (selectMode === 'exclude') {\n if (typeof select[field.name] === 'undefined') {\n addFieldToProjection({\n adapter,\n databaseSchemaPath,\n field,\n parentIsLocalized,\n projection,\n })\n continue\n }\n\n if (select[field.name] === false) {\n continue\n }\n }\n }\n\n let fieldDatabaseSchemaPath = databaseSchemaPath\n\n if (fieldAffectsData(field)) {\n fieldDatabaseSchemaPath = `${databaseSchemaPath}${field.name}.`\n\n if (fieldShouldBeLocalized({ field, parentIsLocalized })) {\n fieldDatabaseSchemaPath = `${fieldDatabaseSchemaPath}<locale>.`\n }\n }\n\n switch (field.type) {\n case 'array':\n case 'group':\n case 'tab': {\n const fieldSelect = select[field.name] as SelectType\n\n if (field.type === 'array' && selectMode === 'include') {\n fieldSelect['id'] = true\n }\n\n traverseFields({\n adapter,\n databaseSchemaPath: fieldDatabaseSchemaPath,\n fields: field.flattenedFields,\n parentIsLocalized: parentIsLocalized || field.localized,\n projection,\n select: fieldSelect,\n selectMode,\n })\n\n break\n }\n\n case 'blocks': {\n const blocksSelect = select[field.name] as SelectType\n\n for (const _block of field.blockReferences ?? field.blocks) {\n const block = typeof _block === 'string' ? adapter.payload.blocks[_block] : _block\n if (\n (selectMode === 'include' && blocksSelect[block.slug] === true) ||\n (selectMode === 'exclude' && typeof blocksSelect[block.slug] === 'undefined')\n ) {\n traverseFields({\n adapter,\n databaseSchemaPath: fieldDatabaseSchemaPath,\n fields: block.flattenedFields,\n parentIsLocalized: parentIsLocalized || field.localized,\n projection,\n select: {},\n selectAllOnCurrentLevel: true,\n selectMode: 'include',\n })\n continue\n }\n\n let blockSelectMode = selectMode\n\n if (selectMode === 'exclude' && blocksSelect[block.slug] === false) {\n blockSelectMode = 'include'\n }\n\n if (typeof blocksSelect[block.slug] !== 'object') {\n blocksSelect[block.slug] = {}\n }\n\n if (blockSelectMode === 'include') {\n blocksSelect[block.slug]['id'] = true\n blocksSelect[block.slug]['blockType'] = true\n }\n\n traverseFields({\n adapter,\n databaseSchemaPath: fieldDatabaseSchemaPath,\n fields: block.flattenedFields,\n parentIsLocalized: parentIsLocalized || field.localized,\n projection,\n select: blocksSelect[block.slug] as SelectType,\n selectMode: blockSelectMode,\n })\n }\n\n break\n }\n\n default:\n break\n }\n }\n}\n\nexport const buildProjectionFromSelect = ({\n adapter,\n fields,\n select,\n}: {\n adapter: MongooseAdapter\n fields: FlattenedField[]\n select?: SelectType\n}): Record<string, true> | undefined => {\n if (!select) {\n return\n }\n\n const projection: Record<string, true> = {\n _id: true,\n }\n\n traverseFields({\n adapter,\n fields,\n projection,\n // Clone to safely mutate it later\n select: deepCopyObjectSimple(select),\n selectMode: getSelectMode(select),\n })\n\n return projection\n}\n"],"names":["deepCopyObjectSimple","fieldAffectsData","fieldShouldBeLocalized","getSelectMode","addFieldToProjection","adapter","databaseSchemaPath","field","parentIsLocalized","projection","config","payload","localization","locale","localeCodes","localeDatabaseSchemaPath","replace","name","traverseFields","fields","select","selectAllOnCurrentLevel","selectMode","fieldDatabaseSchemaPath","type","fieldSelect","flattenedFields","localized","blocksSelect","_block","blockReferences","blocks","block","slug","blockSelectMode","buildProjectionFromSelect","_id"],"mappings":"AAEA,SACEA,oBAAoB,EACpBC,gBAAgB,EAChBC,sBAAsB,EACtBC,aAAa,QACR,iBAAgB;AAIvB,MAAMC,uBAAuB,CAAC,EAC5BC,OAAO,EACPC,kBAAkB,EAClBC,KAAK,EACLC,iBAAiB,EACjBC,UAAU,EAOX;IACC,MAAM,EAAEC,MAAM,EAAE,GAAGL,QAAQM,OAAO;IAElC,IAAIH,qBAAqBE,OAAOE,YAAY,EAAE;QAC5C,KAAK,MAAMC,UAAUH,OAAOE,YAAY,CAACE,WAAW,CAAE;YACpD,MAAMC,2BAA2BT,mBAAmBU,OAAO,CAAC,YAAYH;YACxEJ,UAAU,CAAC,GAAGM,2BAA2BR,MAAMU,IAAI,EAAE,CAAC,GAAG;QAC3D;IACF,OAAO;QACLR,UAAU,CAAC,GAAGH,qBAAqBC,MAAMU,IAAI,EAAE,CAAC,GAAG;IACrD;AACF;AAEA,MAAMC,iBAAiB,CAAC,EACtBb,OAAO,EACPC,qBAAqB,EAAE,EACvBa,MAAM,EACNX,oBAAoB,KAAK,EACzBC,UAAU,EACVW,MAAM,EACNC,0BAA0B,KAAK,EAC/BC,UAAU,EAUX;IACC,KAAK,MAAMf,SAASY,OAAQ;QAC1B,IAAIlB,iBAAiBM,QAAQ;YAC3B,IAAIe,eAAe,WAAW;gBAC5B,IAAIF,MAAM,CAACb,MAAMU,IAAI,CAAC,KAAK,QAAQI,yBAAyB;oBAC1DjB,qBAAqB;wBACnBC;wBACAC;wBACAC;wBACAC;wBACAC;oBACF;oBACA;gBACF;gBAEA,IAAI,CAACW,MAAM,CAACb,MAAMU,IAAI,CAAC,EAAE;oBACvB;gBACF;YACF;YAEA,IAAIK,e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