@payloadcms/db-mongodb 3.1.1-canary.c40ff01 → 3.1.2-canary.eb1a61e
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/deleteOne.js +1 -1
- package/dist/deleteOne.js.map +1 -1
- package/dist/find.js +2 -2
- package/dist/find.js.map +1 -1
- package/dist/findGlobal.js +1 -1
- package/dist/findGlobal.js.map +1 -1
- package/dist/findGlobalVersions.d.ts.map +1 -1
- package/dist/findGlobalVersions.js +1 -1
- package/dist/findGlobalVersions.js.map +1 -1
- package/dist/findOne.js +1 -1
- package/dist/findOne.js.map +1 -1
- package/dist/findVersions.js +2 -2
- package/dist/findVersions.js.map +1 -1
- package/dist/init.d.ts.map +1 -1
- package/dist/init.js +2 -2
- package/dist/init.js.map +1 -1
- package/dist/predefinedMigrations/migrateRelationshipsV2_V3.d.ts.map +1 -1
- package/dist/predefinedMigrations/migrateRelationshipsV2_V3.js +15 -12
- package/dist/predefinedMigrations/migrateRelationshipsV2_V3.js.map +1 -1
- package/dist/queries/buildAndOrConditions.d.ts +2 -2
- package/dist/queries/buildAndOrConditions.d.ts.map +1 -1
- package/dist/queries/buildAndOrConditions.js.map +1 -1
- package/dist/queries/buildQuery.d.ts +2 -2
- package/dist/queries/buildQuery.d.ts.map +1 -1
- package/dist/queries/buildQuery.js +2 -2
- package/dist/queries/buildQuery.js.map +1 -1
- package/dist/queries/buildSearchParams.d.ts +2 -2
- package/dist/queries/buildSearchParams.d.ts.map +1 -1
- package/dist/queries/buildSearchParams.js +1 -1
- package/dist/queries/buildSearchParams.js.map +1 -1
- package/dist/queries/buildSortParam.d.ts +2 -2
- package/dist/queries/buildSortParam.d.ts.map +1 -1
- package/dist/queries/buildSortParam.js.map +1 -1
- package/dist/queries/getLocalizedSortProperty.d.ts +3 -3
- package/dist/queries/getLocalizedSortProperty.d.ts.map +1 -1
- package/dist/queries/getLocalizedSortProperty.js +3 -6
- package/dist/queries/getLocalizedSortProperty.js.map +1 -1
- package/dist/queries/getLocalizedSortProperty.spec.js +83 -73
- package/dist/queries/getLocalizedSortProperty.spec.js.map +1 -1
- package/dist/queries/parseParams.d.ts +2 -2
- package/dist/queries/parseParams.d.ts.map +1 -1
- package/dist/queries/parseParams.js.map +1 -1
- package/dist/queries/sanitizeQueryValue.d.ts +2 -2
- package/dist/queries/sanitizeQueryValue.d.ts.map +1 -1
- package/dist/queries/sanitizeQueryValue.js +2 -2
- package/dist/queries/sanitizeQueryValue.js.map +1 -1
- package/dist/queryDrafts.js +2 -2
- package/dist/queryDrafts.js.map +1 -1
- package/dist/updateGlobal.d.ts.map +1 -1
- package/dist/updateGlobal.js +1 -1
- package/dist/updateGlobal.js.map +1 -1
- package/dist/updateGlobalVersion.d.ts.map +1 -1
- package/dist/updateGlobalVersion.js +3 -2
- package/dist/updateGlobalVersion.js.map +1 -1
- package/dist/updateOne.d.ts.map +1 -1
- package/dist/updateOne.js +1 -1
- package/dist/updateOne.js.map +1 -1
- package/dist/updateVersion.d.ts.map +1 -1
- package/dist/updateVersion.js +1 -1
- package/dist/updateVersion.js.map +1 -1
- package/dist/utilities/buildJoinAggregation.js +1 -1
- package/dist/utilities/buildJoinAggregation.js.map +1 -1
- package/dist/utilities/buildProjectionFromSelect.d.ts +2 -2
- package/dist/utilities/buildProjectionFromSelect.d.ts.map +1 -1
- package/dist/utilities/buildProjectionFromSelect.js +5 -37
- package/dist/utilities/buildProjectionFromSelect.js.map +1 -1
- package/dist/utilities/sanitizeRelationshipIDs.d.ts.map +1 -1
- package/dist/utilities/sanitizeRelationshipIDs.js +8 -8
- package/dist/utilities/sanitizeRelationshipIDs.js.map +1 -1
- package/dist/utilities/sanitizeRelationshipIDs.spec.js +17 -0
- package/dist/utilities/sanitizeRelationshipIDs.spec.js.map +1 -1
- package/package.json +3 -3
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"updateGlobal.d.ts","sourceRoot":"","sources":["../src/updateGlobal.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAkB,YAAY,EAAE,MAAM,SAAS,CAAA;AAS3D,eAAO,MAAM,YAAY,EAAE,
|
1
|
+
{"version":3,"file":"updateGlobal.d.ts","sourceRoot":"","sources":["../src/updateGlobal.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAkB,YAAY,EAAE,MAAM,SAAS,CAAA;AAS3D,eAAO,MAAM,YAAY,EAAE,YAoC1B,CAAA"}
|
package/dist/updateGlobal.js
CHANGED
@@ -12,7 +12,7 @@ export const updateGlobal = async function updateGlobal({ slug, data, options: o
|
|
12
12
|
new: true,
|
13
13
|
projection: buildProjectionFromSelect({
|
14
14
|
adapter: this,
|
15
|
-
fields,
|
15
|
+
fields: this.payload.config.globals.find((global)=>global.slug === slug).flattenedFields,
|
16
16
|
select
|
17
17
|
})
|
18
18
|
};
|
package/dist/updateGlobal.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/updateGlobal.ts"],"sourcesContent":["import type { QueryOptions } from 'mongoose'\nimport type { PayloadRequest, UpdateGlobal } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js'\nimport { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.js'\nimport { withSession } from './withSession.js'\n\nexport const updateGlobal: UpdateGlobal = async function updateGlobal(\n this: MongooseAdapter,\n { slug, data, options: optionsArgs = {}, req = {} as PayloadRequest, select },\n) {\n const Model = this.globals\n const fields = this.payload.config.globals.find((global) => global.slug === slug).fields\n\n const options: QueryOptions = {\n ...optionsArgs,\n ...(await withSession(this, req)),\n lean: true,\n new: true,\n projection: buildProjectionFromSelect({
|
1
|
+
{"version":3,"sources":["../src/updateGlobal.ts"],"sourcesContent":["import type { QueryOptions } from 'mongoose'\nimport type { PayloadRequest, UpdateGlobal } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js'\nimport { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.js'\nimport { withSession } from './withSession.js'\n\nexport const updateGlobal: UpdateGlobal = async function updateGlobal(\n this: MongooseAdapter,\n { slug, data, options: optionsArgs = {}, req = {} as PayloadRequest, select },\n) {\n const Model = this.globals\n const fields = this.payload.config.globals.find((global) => global.slug === slug).fields\n\n const options: QueryOptions = {\n ...optionsArgs,\n ...(await withSession(this, req)),\n lean: true,\n new: true,\n projection: buildProjectionFromSelect({\n adapter: this,\n fields: this.payload.config.globals.find((global) => global.slug === slug).flattenedFields,\n select,\n }),\n }\n\n let result\n\n const sanitizedData = sanitizeRelationshipIDs({\n config: this.payload.config,\n data,\n fields,\n })\n\n result = await Model.findOneAndUpdate({ globalType: slug }, sanitizedData, options)\n\n result = JSON.parse(JSON.stringify(result))\n\n // custom id type reset\n result.id = result._id\n result = sanitizeInternalFields(result)\n\n return result\n}\n"],"names":["buildProjectionFromSelect","sanitizeInternalFields","sanitizeRelationshipIDs","withSession","updateGlobal","slug","data","options","optionsArgs","req","select","Model","globals","fields","payload","config","find","global","lean","new","projection","adapter","flattenedFields","result","sanitizedData","findOneAndUpdate","globalType","JSON","parse","stringify","id","_id"],"mappings":"AAKA,SAASA,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,sBAAsB,QAAQ,wCAAuC;AAC9E,SAASC,uBAAuB,QAAQ,yCAAwC;AAChF,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,eAA6B,eAAeA,aAEvD,EAAEC,IAAI,EAAEC,IAAI,EAAEC,SAASC,cAAc,CAAC,CAAC,EAAEC,MAAM,CAAC,CAAmB,EAAEC,MAAM,EAAE;IAE7E,MAAMC,QAAQ,IAAI,CAACC,OAAO;IAC1B,MAAMC,SAAS,IAAI,CAACC,OAAO,CAACC,MAAM,CAACH,OAAO,CAACI,IAAI,CAAC,CAACC,SAAWA,OAAOZ,IAAI,KAAKA,MAAMQ,MAAM;IAExF,MAAMN,UAAwB;QAC5B,GAAGC,WAAW;QACd,GAAI,MAAML,YAAY,IAAI,EAAEM,IAAI;QAChCS,MAAM;QACNC,KAAK;QACLC,YAAYpB,0BAA0B;YACpCqB,SAAS,IAAI;YACbR,QAAQ,IAAI,CAACC,OAAO,CAACC,MAAM,CAACH,OAAO,CAACI,IAAI,CAAC,CAACC,SAAWA,OAAOZ,IAAI,KAAKA,MAAMiB,eAAe;YAC1FZ;QACF;IACF;IAEA,IAAIa;IAEJ,MAAMC,gBAAgBtB,wBAAwB;QAC5Ca,QAAQ,IAAI,CAACD,OAAO,CAACC,MAAM;QAC3BT;QACAO;IACF;IAEAU,SAAS,MAAMZ,MAAMc,gBAAgB,CAAC;QAAEC,YAAYrB;IAAK,GAAGmB,eAAejB;IAE3EgB,SAASI,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACN;IAEnC,uBAAuB;IACvBA,OAAOO,EAAE,GAAGP,OAAOQ,GAAG;IACtBR,SAAStB,uBAAuBsB;IAEhC,OAAOA;AACT,EAAC"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"updateGlobalVersion.d.ts","sourceRoot":"","sources":["../src/updateGlobalVersion.ts"],"names":[],"mappings":"AAEA,OAAO,EAGL,KAAK,UAAU,EACf,KAAK,uBAAuB,EAC7B,MAAM,SAAS,CAAA;AAEhB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAMjD,wBAAsB,mBAAmB,CAAC,CAAC,SAAS,UAAU,EAC5D,IAAI,EAAE,eAAe,EACrB,EACE,EAAE,EACF,MAAM,EAAE,UAAU,EAClB,MAAM,EACN,OAAO,EAAE,WAAgB,EACzB,GAA0B,EAC1B,MAAM,EACN,WAAW,EACX,KAAK,GACN,EAAE,uBAAuB,CAAC,CAAC,CAAC,
|
1
|
+
{"version":3,"file":"updateGlobalVersion.d.ts","sourceRoot":"","sources":["../src/updateGlobalVersion.ts"],"names":[],"mappings":"AAEA,OAAO,EAGL,KAAK,UAAU,EACf,KAAK,uBAAuB,EAC7B,MAAM,SAAS,CAAA;AAEhB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAMjD,wBAAsB,mBAAmB,CAAC,CAAC,SAAS,UAAU,EAC5D,IAAI,EAAE,eAAe,EACrB,EACE,EAAE,EACF,MAAM,EAAE,UAAU,EAClB,MAAM,EACN,OAAO,EAAE,WAAgB,EACzB,GAA0B,EAC1B,MAAM,EACN,WAAW,EACX,KAAK,GACN,EAAE,uBAAuB,CAAC,CAAC,CAAC,gBA4C9B"}
|
@@ -9,7 +9,8 @@ export async function updateGlobalVersion({ id, global: globalSlug, locale, opti
|
|
9
9
|
equals: id
|
10
10
|
}
|
11
11
|
};
|
12
|
-
const
|
12
|
+
const currentGlobal = this.payload.config.globals.find((global)=>global.slug === globalSlug);
|
13
|
+
const fields = buildVersionGlobalFields(this.payload.config, currentGlobal);
|
13
14
|
const options = {
|
14
15
|
...optionsArgs,
|
15
16
|
...await withSession(this, req),
|
@@ -17,7 +18,7 @@ export async function updateGlobalVersion({ id, global: globalSlug, locale, opti
|
|
17
18
|
new: true,
|
18
19
|
projection: buildProjectionFromSelect({
|
19
20
|
adapter: this,
|
20
|
-
fields,
|
21
|
+
fields: buildVersionGlobalFields(this.payload.config, currentGlobal, true),
|
21
22
|
select
|
22
23
|
})
|
23
24
|
};
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/updateGlobalVersion.ts"],"sourcesContent":["import type { QueryOptions } from 'mongoose'\n\nimport {\n buildVersionGlobalFields,\n type PayloadRequest,\n type TypeWithID,\n type UpdateGlobalVersionArgs,\n} from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.js'\nimport { withSession } from './withSession.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 = {} as PayloadRequest,\n select,\n versionData,\n where,\n }: UpdateGlobalVersionArgs<T>,\n) {\n const VersionModel = this.versions[globalSlug]\n const whereToUse = where || { id: { equals: id } }\n const
|
1
|
+
{"version":3,"sources":["../src/updateGlobalVersion.ts"],"sourcesContent":["import type { QueryOptions } from 'mongoose'\n\nimport {\n buildVersionGlobalFields,\n type PayloadRequest,\n type TypeWithID,\n type UpdateGlobalVersionArgs,\n} from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.js'\nimport { withSession } from './withSession.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 = {} as PayloadRequest,\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 ...(await withSession(this, req)),\n lean: true,\n new: true,\n projection: buildProjectionFromSelect({\n adapter: this,\n fields: buildVersionGlobalFields(this.payload.config, currentGlobal, true),\n select,\n }),\n }\n\n const query = await VersionModel.buildQuery({\n locale,\n payload: this.payload,\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 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","buildProjectionFromSelect","sanitizeRelationshipIDs","withSession","updateGlobalVersion","id","global","globalSlug","locale","options","optionsArgs","req","select","versionData","where","VersionModel","versions","whereToUse","equals","currentGlobal","payload","config","globals","find","slug","fields","lean","new","projection","adapter","query","buildQuery","sanitizedData","data","doc","findOneAndUpdate","result","JSON","parse","stringify","verificationToken","_verificationToken","_id"],"mappings":"AAEA,SACEA,wBAAwB,QAInB,UAAS;AAIhB,SAASC,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,uBAAuB,QAAQ,yCAAwC;AAChF,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,eAAeC,oBAEpB,EACEC,EAAE,EACFC,QAAQC,UAAU,EAClBC,MAAM,EACNC,SAASC,cAAc,CAAC,CAAC,EACzBC,MAAM,CAAC,CAAmB,EAC1BC,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,SAASzB,yBAAyB,IAAI,CAACoB,OAAO,CAACC,MAAM,EAAEF;IAE7D,MAAMV,UAAwB;QAC5B,GAAGC,WAAW;QACd,GAAI,MAAMP,YAAY,IAAI,EAAEQ,IAAI;QAChCe,MAAM;QACNC,KAAK;QACLC,YAAY3B,0BAA0B;YACpC4B,SAAS,IAAI;YACbJ,QAAQzB,yBAAyB,IAAI,CAACoB,OAAO,CAACC,MAAM,EAAEF,eAAe;YACrEP;QACF;IACF;IAEA,MAAMkB,QAAQ,MAAMf,aAAagB,UAAU,CAAC;QAC1CvB;QACAY,SAAS,IAAI,CAACA,OAAO;QACrBN,OAAOG;IACT;IAEA,MAAMe,gBAAgB9B,wBAAwB;QAC5CmB,QAAQ,IAAI,CAACD,OAAO,CAACC,MAAM;QAC3BY,MAAMpB;QACNY;IACF;IAEA,MAAMS,MAAM,MAAMnB,aAAaoB,gBAAgB,CAACL,OAAOE,eAAevB;IAEtE,MAAM2B,SAASC,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACL;IAEzC,MAAMM,oBAAoBN,IAAIO,kBAAkB;IAEhD,uBAAuB;IACvBL,OAAO/B,EAAE,GAAG+B,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,EAAkB,SAAS,EAAE,MAAM,SAAS,CAAA;AAUxD,eAAO,MAAM,SAAS,EAAE,
|
1
|
+
{"version":3,"file":"updateOne.d.ts","sourceRoot":"","sources":["../src/updateOne.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAkB,SAAS,EAAE,MAAM,SAAS,CAAA;AAUxD,eAAO,MAAM,SAAS,EAAE,SAqDvB,CAAA"}
|
package/dist/updateOne.js
CHANGED
@@ -18,7 +18,7 @@ export const updateOne = async function updateOne({ id, collection, data, locale
|
|
18
18
|
new: true,
|
19
19
|
projection: buildProjectionFromSelect({
|
20
20
|
adapter: this,
|
21
|
-
fields,
|
21
|
+
fields: this.payload.collections[collection].config.flattenedFields,
|
22
22
|
select
|
23
23
|
})
|
24
24
|
};
|
package/dist/updateOne.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/updateOne.ts"],"sourcesContent":["import type { QueryOptions } from 'mongoose'\nimport type { PayloadRequest, UpdateOne } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { handleError } from './utilities/handleError.js'\nimport { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js'\nimport { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.js'\nimport { withSession } from './withSession.js'\n\nexport const updateOne: UpdateOne = async function updateOne(\n this: MongooseAdapter,\n {\n id,\n collection,\n data,\n locale,\n options: optionsArgs = {},\n req = {} as PayloadRequest,\n select,\n where: whereArg,\n },\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 ...(await withSession(this, req)),\n lean: true,\n new: true,\n projection: buildProjectionFromSelect({
|
1
|
+
{"version":3,"sources":["../src/updateOne.ts"],"sourcesContent":["import type { QueryOptions } from 'mongoose'\nimport type { PayloadRequest, UpdateOne } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { handleError } from './utilities/handleError.js'\nimport { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js'\nimport { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.js'\nimport { withSession } from './withSession.js'\n\nexport const updateOne: UpdateOne = async function updateOne(\n this: MongooseAdapter,\n {\n id,\n collection,\n data,\n locale,\n options: optionsArgs = {},\n req = {} as PayloadRequest,\n select,\n where: whereArg,\n },\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 ...(await withSession(this, req)),\n lean: true,\n new: true,\n projection: buildProjectionFromSelect({\n adapter: this,\n fields: this.payload.collections[collection].config.flattenedFields,\n select,\n }),\n }\n\n const query = await Model.buildQuery({\n locale,\n payload: this.payload,\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 result = JSON.parse(JSON.stringify(result))\n result.id = result._id\n result = sanitizeInternalFields(result)\n\n return result\n}\n"],"names":["buildProjectionFromSelect","handleError","sanitizeInternalFields","sanitizeRelationshipIDs","withSession","updateOne","id","collection","data","locale","options","optionsArgs","req","select","where","whereArg","equals","Model","collections","fields","payload","config","lean","new","projection","adapter","flattenedFields","query","buildQuery","result","sanitizedData","findOneAndUpdate","error","JSON","parse","stringify","_id"],"mappings":"AAKA,SAASA,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,WAAW,QAAQ,6BAA4B;AACxD,SAASC,sBAAsB,QAAQ,wCAAuC;AAC9E,SAASC,uBAAuB,QAAQ,yCAAwC;AAChF,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,YAAuB,eAAeA,UAEjD,EACEC,EAAE,EACFC,UAAU,EACVC,IAAI,EACJC,MAAM,EACNC,SAASC,cAAc,CAAC,CAAC,EACzBC,MAAM,CAAC,CAAmB,EAC1BC,MAAM,EACNC,OAAOC,QAAQ,EAChB;IAED,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;QACd,GAAI,MAAMP,YAAY,IAAI,EAAEQ,IAAI;QAChCU,MAAM;QACNC,KAAK;QACLC,YAAYxB,0BAA0B;YACpCyB,SAAS,IAAI;YACbN,QAAQ,IAAI,CAACC,OAAO,CAACF,WAAW,CAACX,WAAW,CAACc,MAAM,CAACK,eAAe;YACnEb;QACF;IACF;IAEA,MAAMc,QAAQ,MAAMV,MAAMW,UAAU,CAAC;QACnCnB;QACAW,SAAS,IAAI,CAACA,OAAO;QACrBN;IACF;IAEA,IAAIe;IAEJ,MAAMC,gBAAgB3B,wBAAwB;QAC5CkB,QAAQ,IAAI,CAACD,OAAO,CAACC,MAAM;QAC3Bb;QACAW;IACF;IAEA,IAAI;QACFU,SAAS,MAAMZ,MAAMc,gBAAgB,CAACJ,OAAOG,eAAepB;IAC9D,EAAE,OAAOsB,OAAO;QACd/B,YAAY;YAAEM;YAAYyB;YAAOpB;QAAI;IACvC;IAEAiB,SAASI,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACN;IACnCA,OAAOvB,EAAE,GAAGuB,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,EAAqD,KAAK,aAAa,EAAE,MAAM,SAAS,CAAA;AAQ/F,eAAO,MAAM,aAAa,EAAE,
|
1
|
+
{"version":3,"file":"updateVersion.d.ts","sourceRoot":"","sources":["../src/updateVersion.ts"],"names":[],"mappings":"AAEA,OAAO,EAAqD,KAAK,aAAa,EAAE,MAAM,SAAS,CAAA;AAQ/F,eAAO,MAAM,aAAa,EAAE,aA4D3B,CAAA"}
|
package/dist/updateVersion.js
CHANGED
@@ -17,7 +17,7 @@ export const updateVersion = async function updateVersion({ id, collection, loca
|
|
17
17
|
new: true,
|
18
18
|
projection: buildProjectionFromSelect({
|
19
19
|
adapter: this,
|
20
|
-
fields,
|
20
|
+
fields: buildVersionCollectionFields(this.payload.config, this.payload.collections[collection].config, true),
|
21
21
|
select
|
22
22
|
})
|
23
23
|
};
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/updateVersion.ts"],"sourcesContent":["import type { QueryOptions } from 'mongoose'\n\nimport { buildVersionCollectionFields, type PayloadRequest, type UpdateVersion } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.js'\nimport { withSession } from './withSession.js'\n\nexport const updateVersion: UpdateVersion = async function updateVersion(\n this: MongooseAdapter,\n {\n id,\n collection,\n locale,\n options: optionsArgs = {},\n req = {} as PayloadRequest,\n select,\n versionData,\n where,\n },\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 ...(await withSession(this, req)),\n lean: true,\n new: true,\n projection: buildProjectionFromSelect({
|
1
|
+
{"version":3,"sources":["../src/updateVersion.ts"],"sourcesContent":["import type { QueryOptions } from 'mongoose'\n\nimport { buildVersionCollectionFields, type PayloadRequest, type UpdateVersion } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.js'\nimport { withSession } from './withSession.js'\n\nexport const updateVersion: UpdateVersion = async function updateVersion(\n this: MongooseAdapter,\n {\n id,\n collection,\n locale,\n options: optionsArgs = {},\n req = {} as PayloadRequest,\n select,\n versionData,\n where,\n },\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 ...(await withSession(this, req)),\n lean: true,\n new: true,\n projection: buildProjectionFromSelect({\n adapter: this,\n fields: buildVersionCollectionFields(\n this.payload.config,\n this.payload.collections[collection].config,\n true,\n ),\n select,\n }),\n }\n\n const query = await VersionModel.buildQuery({\n locale,\n payload: this.payload,\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 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","buildProjectionFromSelect","sanitizeRelationshipIDs","withSession","updateVersion","id","collection","locale","options","optionsArgs","req","select","versionData","where","VersionModel","versions","whereToUse","equals","fields","payload","config","collections","lean","new","projection","adapter","query","buildQuery","sanitizedData","data","doc","findOneAndUpdate","result","JSON","parse","stringify","verificationToken","_verificationToken","_id"],"mappings":"AAEA,SAASA,4BAA4B,QAAiD,UAAS;AAI/F,SAASC,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,uBAAuB,QAAQ,yCAAwC;AAChF,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,gBAA+B,eAAeA,cAEzD,EACEC,EAAE,EACFC,UAAU,EACVC,MAAM,EACNC,SAASC,cAAc,CAAC,CAAC,EACzBC,MAAM,CAAC,CAAmB,EAC1BC,MAAM,EACNC,WAAW,EACXC,KAAK,EACN;IAED,MAAMC,eAAe,IAAI,CAACC,QAAQ,CAACT,WAAW;IAC9C,MAAMU,aAAaH,SAAS;QAAER,IAAI;YAAEY,QAAQZ;QAAG;IAAE;IACjD,MAAMa,SAASlB,6BACb,IAAI,CAACmB,OAAO,CAACC,MAAM,EACnB,IAAI,CAACD,OAAO,CAACE,WAAW,CAACf,WAAW,CAACc,MAAM;IAG7C,MAAMZ,UAAwB;QAC5B,GAAGC,WAAW;QACd,GAAI,MAAMN,YAAY,IAAI,EAAEO,IAAI;QAChCY,MAAM;QACNC,KAAK;QACLC,YAAYvB,0BAA0B;YACpCwB,SAAS,IAAI;YACbP,QAAQlB,6BACN,IAAI,CAACmB,OAAO,CAACC,MAAM,EACnB,IAAI,CAACD,OAAO,CAACE,WAAW,CAACf,WAAW,CAACc,MAAM,EAC3C;YAEFT;QACF;IACF;IAEA,MAAMe,QAAQ,MAAMZ,aAAaa,UAAU,CAAC;QAC1CpB;QACAY,SAAS,IAAI,CAACA,OAAO;QACrBN,OAAOG;IACT;IAEA,MAAMY,gBAAgB1B,wBAAwB;QAC5CkB,QAAQ,IAAI,CAACD,OAAO,CAACC,MAAM;QAC3BS,MAAMjB;QACNM;IACF;IAEA,MAAMY,MAAM,MAAMhB,aAAaiB,gBAAgB,CAACL,OAAOE,eAAepB;IAEtE,MAAMwB,SAASC,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACL;IAEzC,MAAMM,oBAAoBN,IAAIO,kBAAkB;IAEhD,uBAAuB;IACvBL,OAAO3B,EAAE,GAAG2B,OAAOM,GAAG;IACtB,IAAIF,mBAAmB;QACrBJ,OAAOK,kBAAkB,GAAGD;IAC9B;IACA,OAAOJ;AACT,EAAC"}
|
@@ -33,7 +33,7 @@ export const buildJoinAggregation = async ({ adapter, collection, collectionConf
|
|
33
33
|
const { limit: limitJoin = join.field.defaultLimit ?? 10, sort: sortJoin = join.field.defaultSort || collectionConfig.defaultSort, where: whereJoin } = joins?.[join.joinPath] || {};
|
34
34
|
const sort = buildSortParam({
|
35
35
|
config: adapter.payload.config,
|
36
|
-
fields: adapter.payload.collections[slug].config.
|
36
|
+
fields: adapter.payload.collections[slug].config.flattenedFields,
|
37
37
|
locale,
|
38
38
|
sort: sortJoin,
|
39
39
|
timestamps: true
|
@@ -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.fields,\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 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}`,\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 aggregate.push(\n {\n $lookup: {\n as: `${as}.docs`,\n foreignField: `${join.field.on}${localeSuffix}`,\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","timestamps","sortProperty","sortDirection","buildQuery","pipeline","localization","localeCodes","forEach","code","as","$lookup","foreignField","on","from","name","localField","$addFields","$map","in","input","$gt","$size","$slice","localeSuffix","localized","Number","MAX_VALUE","$project"],"mappings":"AAKA,SAASA,cAAc,QAAQ,+BAA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AAC,EAAEA,GAAG,YAAY,CAAC,CAAC,EAAE;4BACrBW,KAAK;gCAAC;oCAAEC,OAAO,CAAC,CAAC,EAAEZ,GAAG,KAAK,CAAC;gCAAC;gCAAGjB,aAAaiC,OAAOC,SAAS;6BAAC;wBAChE;oBACF;gBACF;gBAEF,IAAIlC,YAAY,GAAG;oBACjBX,UAAUG,IAAI,CAAC;wBACbgC,YAAY;4BACV,CAAC,CAAC,EAAEP,GAAG,KAAK,CAAC,CAAC,EAAE;gCACda,QAAQ;oCAAC,CAAC,CAAC,EAAEb,GAAG,KAAK,CAAC;oCAAEjB;iCAAU;4BACpC;wBACF;oBACF;gBACF;YACF;QACF;IACF;IAEA,IAAIrB,YAAY;QACdU,UAAUG,IAAI,CAAC;YAAE2C,UAAUxD;QAAW;IACxC;IAEA,OAAOU;AACT,EAAC"}
|
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 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}`,\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 aggregate.push(\n {\n $lookup: {\n as: `${as}.docs`,\n foreignField: `${join.field.on}${localeSuffix}`,\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","localization","localeCodes","forEach","code","as","$lookup","foreignField","on","from","name","localField","$addFields","$map","in","input","$gt","$size","$slice","localeSuffix","localized","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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KAAK,CAAC,CAAC,EAAE;gCACda,QAAQ;oCAAC,CAAC,CAAC,EAAEb,GAAG,KAAK,CAAC;oCAAElB;iCAAU;4BACpC;wBACF;oBACF;gBACF;YACF;QACF;IACF;IAEA,IAAIrB,YAAY;QACdU,UAAUG,IAAI,CAAC;YAAE4C,UAAUzD;QAAW;IACxC;IAEA,OAAOU;AACT,EAAC"}
|
@@ -1,8 +1,8 @@
|
|
1
|
-
import {
|
1
|
+
import type { FlattenedField, SelectType } from 'payload';
|
2
2
|
import type { MongooseAdapter } from '../index.js';
|
3
3
|
export declare const buildProjectionFromSelect: ({ adapter, fields, select, }: {
|
4
4
|
adapter: MongooseAdapter;
|
5
|
-
fields:
|
5
|
+
fields: FlattenedField[];
|
6
6
|
select?: SelectType;
|
7
7
|
}) => Record<string, true> | undefined;
|
8
8
|
//# sourceMappingURL=buildProjectionFromSelect.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"buildProjectionFromSelect.d.ts","sourceRoot":"","sources":["../../src/utilities/buildProjectionFromSelect.ts"],"names":[],"mappings":"AAAA,OAAO,
|
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;AAIzF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AA8KlD,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,5 +1,4 @@
|
|
1
|
-
import { deepCopyObjectSimple } from 'payload';
|
2
|
-
import { fieldAffectsData, getSelectMode, tabHasName } from 'payload/shared';
|
1
|
+
import { deepCopyObjectSimple, fieldAffectsData, getSelectMode } from 'payload/shared';
|
3
2
|
const addFieldToProjection = ({ adapter, databaseSchemaPath, field, projection, withinLocalizedField })=>{
|
4
3
|
const { config } = adapter.payload;
|
5
4
|
if (withinLocalizedField && config.localization) {
|
@@ -59,19 +58,14 @@ const traverseFields = ({ adapter, databaseSchemaPath = '', fields, projection,
|
|
59
58
|
case 'group':
|
60
59
|
case 'tab':
|
61
60
|
{
|
62
|
-
|
63
|
-
if (field.type === 'tab' && !tabHasName(field)) {
|
64
|
-
fieldSelect = select;
|
65
|
-
} else {
|
66
|
-
fieldSelect = select[field.name];
|
67
|
-
}
|
61
|
+
const fieldSelect = select[field.name];
|
68
62
|
if (field.type === 'array' && selectMode === 'include') {
|
69
63
|
fieldSelect['id'] = true;
|
70
64
|
}
|
71
65
|
traverseFields({
|
72
66
|
adapter,
|
73
67
|
databaseSchemaPath: fieldDatabaseSchemaPath,
|
74
|
-
fields: field.
|
68
|
+
fields: field.flattenedFields,
|
75
69
|
projection,
|
76
70
|
select: fieldSelect,
|
77
71
|
selectMode,
|
@@ -87,7 +81,7 @@ const traverseFields = ({ adapter, databaseSchemaPath = '', fields, projection,
|
|
87
81
|
traverseFields({
|
88
82
|
adapter,
|
89
83
|
databaseSchemaPath: fieldDatabaseSchemaPath,
|
90
|
-
fields: block.
|
84
|
+
fields: block.flattenedFields,
|
91
85
|
projection,
|
92
86
|
select: {},
|
93
87
|
selectAllOnCurrentLevel: true,
|
@@ -110,7 +104,7 @@ const traverseFields = ({ adapter, databaseSchemaPath = '', fields, projection,
|
|
110
104
|
traverseFields({
|
111
105
|
adapter,
|
112
106
|
databaseSchemaPath: fieldDatabaseSchemaPath,
|
113
|
-
fields: block.
|
107
|
+
fields: block.flattenedFields,
|
114
108
|
projection,
|
115
109
|
select: blocksSelect[block.slug],
|
116
110
|
selectMode: blockSelectMode,
|
@@ -119,32 +113,6 @@ const traverseFields = ({ adapter, databaseSchemaPath = '', fields, projection,
|
|
119
113
|
}
|
120
114
|
break;
|
121
115
|
}
|
122
|
-
case 'collapsible':
|
123
|
-
case 'row':
|
124
|
-
traverseFields({
|
125
|
-
adapter,
|
126
|
-
databaseSchemaPath,
|
127
|
-
fields: field.fields,
|
128
|
-
projection,
|
129
|
-
select,
|
130
|
-
selectMode,
|
131
|
-
withinLocalizedField
|
132
|
-
});
|
133
|
-
break;
|
134
|
-
case 'tabs':
|
135
|
-
traverseFields({
|
136
|
-
adapter,
|
137
|
-
databaseSchemaPath,
|
138
|
-
fields: field.tabs.map((tab)=>({
|
139
|
-
...tab,
|
140
|
-
type: 'tab'
|
141
|
-
})),
|
142
|
-
projection,
|
143
|
-
select,
|
144
|
-
selectMode,
|
145
|
-
withinLocalizedField
|
146
|
-
});
|
147
|
-
break;
|
148
116
|
default:
|
149
117
|
break;
|
150
118
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/buildProjectionFromSelect.ts"],"sourcesContent":["import {\n deepCopyObjectSimple,\n type Field,\n type FieldAffectingData,\n type SelectMode,\n type SelectType,\n type TabAsField,\n} from 'payload'\nimport { fieldAffectsData, getSelectMode, tabHasName } from 'payload/shared'\n\nimport type { MongooseAdapter } from '../index.js'\n\nconst addFieldToProjection = ({\n adapter,\n databaseSchemaPath,\n field,\n projection,\n withinLocalizedField,\n}: {\n adapter: MongooseAdapter\n databaseSchemaPath: string\n field: FieldAffectingData\n projection: Record<string, true>\n withinLocalizedField: boolean\n}) => {\n const { config } = adapter.payload\n\n if (withinLocalizedField && 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 projection,\n select,\n selectAllOnCurrentLevel = false,\n selectMode,\n withinLocalizedField = false,\n}: {\n adapter: MongooseAdapter\n databaseSchemaPath?: string\n fields: (Field | TabAsField)[]\n projection: Record<string, true>\n select: SelectType\n selectAllOnCurrentLevel?: boolean\n selectMode: SelectMode\n withinLocalizedField?: boolean\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 projection,\n withinLocalizedField,\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 projection,\n withinLocalizedField,\n })\n continue\n }\n\n if (select[field.name] === false) {\n continue\n }\n }\n }\n\n let fieldDatabaseSchemaPath = databaseSchemaPath\n let fieldWithinLocalizedField = withinLocalizedField\n\n if (fieldAffectsData(field)) {\n fieldDatabaseSchemaPath = `${databaseSchemaPath}${field.name}.`\n\n if (field.localized) {\n fieldDatabaseSchemaPath = `${fieldDatabaseSchemaPath}<locale>.`\n fieldWithinLocalizedField = true\n }\n }\n\n switch (field.type) {\n case 'array':\n case 'group':\n case 'tab': {\n let fieldSelect: SelectType\n\n if (field.type === 'tab' && !tabHasName(field)) {\n fieldSelect = select\n } else {\n fieldSelect = select[field.name] as SelectType\n }\n\n if (field.type === 'array' && selectMode === 'include') {\n fieldSelect['id'] = true\n }\n\n traverseFields({\n adapter,\n databaseSchemaPath: fieldDatabaseSchemaPath,\n fields: field.fields,\n projection,\n select: fieldSelect,\n selectMode,\n withinLocalizedField: fieldWithinLocalizedField,\n })\n\n break\n }\n\n case 'blocks': {\n const blocksSelect = select[field.name] as SelectType\n\n for (const block of field.blocks) {\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.fields,\n projection,\n select: {},\n selectAllOnCurrentLevel: true,\n selectMode: 'include',\n withinLocalizedField: fieldWithinLocalizedField,\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.fields,\n projection,\n select: blocksSelect[block.slug] as SelectType,\n selectMode: blockSelectMode,\n withinLocalizedField: fieldWithinLocalizedField,\n })\n }\n\n break\n }\n case 'collapsible':\n case 'row':\n traverseFields({\n adapter,\n databaseSchemaPath,\n fields: field.fields,\n projection,\n select,\n selectMode,\n withinLocalizedField,\n })\n break\n\n case 'tabs':\n traverseFields({\n adapter,\n databaseSchemaPath,\n fields: field.tabs.map((tab) => ({ ...tab, type: 'tab' })),\n projection,\n select,\n selectMode,\n withinLocalizedField,\n })\n break\n\n default:\n break\n }\n }\n}\n\nexport const buildProjectionFromSelect = ({\n adapter,\n fields,\n select,\n}: {\n adapter: MongooseAdapter\n fields: Field[]\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","getSelectMode","tabHasName","addFieldToProjection","adapter","databaseSchemaPath","field","projection","withinLocalizedField","config","payload","localization","locale","localeCodes","localeDatabaseSchemaPath","replace","name","traverseFields","fields","select","selectAllOnCurrentLevel","selectMode","fieldDatabaseSchemaPath","fieldWithinLocalizedField","localized","type","fieldSelect","blocksSelect","block","blocks","slug","blockSelectMode","tabs","map","tab","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;AACT,EAAC"}
|
1
|
+
{"version":3,"sources":["../../src/utilities/buildProjectionFromSelect.ts"],"sourcesContent":["import type { FieldAffectingData, FlattenedField, SelectMode, SelectType } from 'payload'\n\nimport { deepCopyObjectSimple, fieldAffectsData, getSelectMode } from 'payload/shared'\n\nimport type { MongooseAdapter } from '../index.js'\n\nconst addFieldToProjection = ({\n adapter,\n databaseSchemaPath,\n field,\n projection,\n withinLocalizedField,\n}: {\n adapter: MongooseAdapter\n databaseSchemaPath: string\n field: FieldAffectingData\n projection: Record<string, true>\n withinLocalizedField: boolean\n}) => {\n const { config } = adapter.payload\n\n if (withinLocalizedField && 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 projection,\n select,\n selectAllOnCurrentLevel = false,\n selectMode,\n withinLocalizedField = false,\n}: {\n adapter: MongooseAdapter\n databaseSchemaPath?: string\n fields: FlattenedField[]\n projection: Record<string, true>\n select: SelectType\n selectAllOnCurrentLevel?: boolean\n selectMode: SelectMode\n withinLocalizedField?: boolean\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 projection,\n withinLocalizedField,\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 projection,\n withinLocalizedField,\n })\n continue\n }\n\n if (select[field.name] === false) {\n continue\n }\n }\n }\n\n let fieldDatabaseSchemaPath = databaseSchemaPath\n let fieldWithinLocalizedField = withinLocalizedField\n\n if (fieldAffectsData(field)) {\n fieldDatabaseSchemaPath = `${databaseSchemaPath}${field.name}.`\n\n if (field.localized) {\n fieldDatabaseSchemaPath = `${fieldDatabaseSchemaPath}<locale>.`\n fieldWithinLocalizedField = true\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 projection,\n select: fieldSelect,\n selectMode,\n withinLocalizedField: fieldWithinLocalizedField,\n })\n\n break\n }\n\n case 'blocks': {\n const blocksSelect = select[field.name] as SelectType\n\n for (const block of field.blocks) {\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 projection,\n select: {},\n selectAllOnCurrentLevel: true,\n selectMode: 'include',\n withinLocalizedField: fieldWithinLocalizedField,\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 projection,\n select: blocksSelect[block.slug] as SelectType,\n selectMode: blockSelectMode,\n withinLocalizedField: fieldWithinLocalizedField,\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","getSelectMode","addFieldToProjection","adapter","databaseSchemaPath","field","projection","withinLocalizedField","config","payload","localization","locale","localeCodes","localeDatabaseSchemaPath","replace","name","traverseFields","fields","select","selectAllOnCurrentLevel","selectMode","fieldDatabaseSchemaPath","fieldWithinLocalizedField","localized","type","fieldSelect","flattenedFields","blocksSelect","block","blocks","slug","blockSelectMode","buildProjectionFromSelect","_id"],"mappings":"AAEA,SAASA,oBAAoB,EAAEC,gBAAgB,EAAEC,aAAa,QAAQ,iBAAgB;AAItF,MAAMC,uBAAuB,CAAC,EAC5BC,OAAO,EACPC,kBAAkB,EAClBC,KAAK,EACLC,UAAU,EACVC,oBAAoB,EAOrB;IACC,MAAM,EAAEC,MAAM,EAAE,GAAGL,QAAQM,OAAO;IAElC,IAAIF,wBAAwBC,OAAOE,YAAY,EAAE;QAC/C,KAAK,MAAMC,UAAUH,OAAOE,YAAY,CAACE,WAAW,CAAE;YACpD,MAAMC,2BAA2BT,mBAAmBU,OAAO,CAAC,YAAYH;YACxEL,UAAU,CAAC,CAAC,EAAEO,yBAAyB,EAAER,MAAMU,IAAI,CAAC,CAAC,CAAC,GAAG;QAC3D;IACF,OAAO;QACLT,UAAU,CAAC,CAAC,EAAEF,mBAAmB,EAAEC,MAAMU,IAAI,CAAC,CAAC,CAAC,GAAG;IACrD;AACF;AAEA,MAAMC,iBAAiB,CAAC,EACtBb,OAAO,EACPC,qBAAqB,EAAE,EACvBa,MAAM,EACNX,UAAU,EACVY,MAAM,EACNC,0BAA0B,KAAK,EAC/BC,UAAU,EACVb,uBAAuB,KAAK,EAU7B;IACC,KAAK,MAAMF,SAASY,OAAQ;QAC1B,IAAIjB,iBAAiBK,QAAQ;YAC3B,IAAIe,eAAe,WAAW;gBAC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.d.ts","sourceRoot":"","sources":["../../src/utilities/sanitizeRelationshipIDs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAoB,KAAK,EAAE,eAAe,EAA0B,MAAM,SAAS,CAAA;AAM/F,KAAK,IAAI,GAAG;IACV,MAAM,EAAE,eAAe,CAAA;IACvB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC7B,MAAM,EAAE,KAAK,EAAE,CAAA;CAChB,CAAA;
|
1
|
+
{"version":3,"file":"sanitizeRelationshipIDs.d.ts","sourceRoot":"","sources":["../../src/utilities/sanitizeRelationshipIDs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAoB,KAAK,EAAE,eAAe,EAA0B,MAAM,SAAS,CAAA;AAM/F,KAAK,IAAI,GAAG;IACV,MAAM,EAAE,eAAe,CAAA;IACvB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC7B,MAAM,EAAE,KAAK,EAAE,CAAA;CAChB,CAAA;AAoGD,eAAO,MAAM,uBAAuB,8BAIjC,IAAI,KAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAyC/B,CAAA"}
|
@@ -1,19 +1,19 @@
|
|
1
1
|
import { Types } from 'mongoose';
|
2
|
-
import {
|
2
|
+
import { traverseFields } from 'payload';
|
3
3
|
import { fieldAffectsData } from 'payload/shared';
|
4
4
|
function isValidRelationObject(value) {
|
5
5
|
return typeof value === 'object' && value !== null && 'relationTo' in value && 'value' in value;
|
6
6
|
}
|
7
7
|
const convertValue = ({ relatedCollection, value })=>{
|
8
8
|
const customIDField = relatedCollection.fields.find((field)=>fieldAffectsData(field) && field.name === 'id');
|
9
|
-
if (
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
9
|
+
if (customIDField) {
|
10
|
+
return value;
|
11
|
+
}
|
12
|
+
try {
|
13
|
+
return new Types.ObjectId(value);
|
14
|
+
} catch {
|
15
|
+
return value;
|
15
16
|
}
|
16
|
-
return value;
|
17
17
|
};
|
18
18
|
const sanitizeRelationship = ({ config, field, locale, ref, value })=>{
|
19
19
|
let relatedCollection;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/sanitizeRelationshipIDs.ts"],"sourcesContent":["import type { CollectionConfig, Field, SanitizedConfig, TraverseFieldsCallback } from 'payload'\n\nimport { Types } from 'mongoose'\nimport { APIError, traverseFields } from 'payload'\nimport { fieldAffectsData } from 'payload/shared'\n\ntype Args = {\n config: SanitizedConfig\n data: Record<string, unknown>\n fields: Field[]\n}\n\ninterface RelationObject {\n relationTo: string\n value: number | string\n}\n\nfunction isValidRelationObject(value: unknown): value is RelationObject {\n return typeof value === 'object' && value !== null && 'relationTo' in value && 'value' in value\n}\n\nconst convertValue = ({\n relatedCollection,\n value,\n}: {\n relatedCollection: CollectionConfig\n value: number | string\n}): number | string | Types.ObjectId => {\n const customIDField = relatedCollection.fields.find(\n (field) => fieldAffectsData(field) && field.name === 'id',\n )\n\n if (
|
1
|
+
{"version":3,"sources":["../../src/utilities/sanitizeRelationshipIDs.ts"],"sourcesContent":["import type { CollectionConfig, Field, SanitizedConfig, TraverseFieldsCallback } from 'payload'\n\nimport { Types } from 'mongoose'\nimport { APIError, traverseFields } from 'payload'\nimport { fieldAffectsData } from 'payload/shared'\n\ntype Args = {\n config: SanitizedConfig\n data: Record<string, unknown>\n fields: Field[]\n}\n\ninterface RelationObject {\n relationTo: string\n value: number | string\n}\n\nfunction isValidRelationObject(value: unknown): value is RelationObject {\n return typeof value === 'object' && value !== null && 'relationTo' in value && 'value' in value\n}\n\nconst convertValue = ({\n relatedCollection,\n value,\n}: {\n relatedCollection: CollectionConfig\n value: number | string\n}): number | string | Types.ObjectId => {\n const customIDField = relatedCollection.fields.find(\n (field) => fieldAffectsData(field) && field.name === 'id',\n )\n\n if (customIDField) {\n return value\n }\n\n try {\n return new Types.ObjectId(value)\n } catch {\n return value\n }\n}\n\nconst sanitizeRelationship = ({ config, field, locale, ref, value }) => {\n let relatedCollection: CollectionConfig | undefined\n let result = value\n\n const hasManyRelations = typeof field.relationTo !== 'string'\n\n if (!hasManyRelations) {\n relatedCollection = config.collections?.find(({ slug }) => slug === field.relationTo)\n }\n\n if (Array.isArray(value)) {\n result = value.map((val) => {\n // Handle has many\n if (relatedCollection && val && (typeof val === 'string' || typeof val === 'number')) {\n return convertValue({\n relatedCollection,\n value: val,\n })\n }\n\n // Handle has many - polymorphic\n if (isValidRelationObject(val)) {\n const relatedCollectionForSingleValue = config.collections?.find(\n ({ slug }) => slug === val.relationTo,\n )\n\n if (relatedCollectionForSingleValue) {\n return {\n relationTo: val.relationTo,\n value: convertValue({\n relatedCollection: relatedCollectionForSingleValue,\n value: val.value,\n }),\n }\n }\n }\n\n return val\n })\n }\n\n // Handle has one - polymorphic\n if (isValidRelationObject(value)) {\n relatedCollection = config.collections?.find(({ slug }) => slug === value.relationTo)\n\n if (relatedCollection) {\n result = {\n relationTo: value.relationTo,\n value: convertValue({ relatedCollection, value: value.value }),\n }\n }\n }\n\n // Handle has one\n if (relatedCollection && value && (typeof value === 'string' || typeof value === 'number')) {\n result = convertValue({\n relatedCollection,\n value,\n })\n }\n if (locale) {\n ref[locale] = result\n } else {\n ref[field.name] = result\n }\n}\n\nexport const sanitizeRelationshipIDs = ({\n config,\n data,\n fields,\n}: Args): Record<string, unknown> => {\n const sanitize: TraverseFieldsCallback = ({ field, ref }) => {\n if (!ref || typeof ref !== 'object') {\n return\n }\n\n if (field.type === 'relationship' || field.type === 'upload') {\n if (!ref[field.name]) {\n return\n }\n\n // handle localized relationships\n if (config.localization && field.localized) {\n const locales = config.localization.locales\n const fieldRef = ref[field.name]\n if (typeof fieldRef !== 'object') {\n return\n }\n\n for (const { code } of locales) {\n const value = ref[field.name][code]\n if (value) {\n sanitizeRelationship({ config, field, locale: code, ref: fieldRef, value })\n }\n }\n } else {\n // handle non-localized relationships\n sanitizeRelationship({\n config,\n field,\n locale: undefined,\n ref,\n value: ref[field.name],\n })\n }\n }\n }\n\n traverseFields({ callback: sanitize, fields, fillEmpty: false, ref: data })\n\n return data\n}\n"],"names":["Types","traverseFields","fieldAffectsData","isValidRelationObject","value","convertValue","relatedCollection","customIDField","fields","find","field","name","ObjectId","sanitizeRelationship","config","locale","ref","result","hasManyRelations","relationTo","collections","slug","Array","isArray","map","val","relatedCollectionForSingleValue","sanitizeRelationshipIDs","data","sanitize","type","localization","localized","locales","fieldRef","code","undefined","callback","fillEmpty"],"mappings":"AAEA,SAASA,KAAK,QAAQ,WAAU;AAChC,SAAmBC,cAAc,QAAQ,UAAS;AAClD,SAASC,gBAAgB,QAAQ,iBAAgB;AAajD,SAASC,sBAAsBC,KAAc;IAC3C,OAAO,OAAOA,UAAU,YAAYA,UAAU,QAAQ,gBAAgBA,SAAS,WAAWA;AAC5F;AAEA,MAAMC,eAAe,CAAC,EACpBC,iBAAiB,EACjBF,KAAK,EAIN;IACC,MAAMG,gBAAgBD,kBAAkBE,MAAM,CAACC,IAAI,CACjD,CAACC,QAAUR,iBAAiBQ,UAAUA,MAAMC,IAAI,KAAK;IAGvD,IAAIJ,eAAe;QACjB,OAAOH;IACT;IAEA,IAAI;QACF,OAAO,IAAIJ,MAAMY,QAAQ,CAACR;IAC5B,EAAE,OAAM;QACN,OAAOA;IACT;AACF;AAEA,MAAMS,uBAAuB,CAAC,EAAEC,MAAM,EAAEJ,KAAK,EAAEK,MAAM,EAAEC,GAAG,EAAEZ,KAAK,EAAE;IACjE,IAAIE;IACJ,IAAIW,SAASb;IAEb,MAAMc,mBAAmB,OAAOR,MAAMS,UAAU,KAAK;IAErD,IAAI,CAACD,kBAAkB;QACrBZ,oBAAoBQ,OAAOM,WAAW,EAAEX,KAAK,CAAC,EAAEY,IAAI,EAAE,GAAKA,SAASX,MAAMS,UAAU;IACtF;IAEA,IAAIG,MAAMC,OAAO,CAACnB,QAAQ;QACxBa,SAASb,MAAMoB,GAAG,CAAC,CAACC;YAClB,kBAAkB;YAClB,IAA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oB,IAAI,KAAK,kBAAkBpB,MAAMoB,IAAI,KAAK,UAAU;YAC5D,IAAI,CAACd,GAAG,CAACN,MAAMC,IAAI,CAAC,EAAE;gBACpB;YACF;YAEA,iCAAiC;YACjC,IAAIG,OAAOiB,YAAY,IAAIrB,MAAMsB,SAAS,EAAE;gBAC1C,MAAMC,UAAUnB,OAAOiB,YAAY,CAACE,OAAO;gBAC3C,MAAMC,WAAWlB,GAAG,CAACN,MAAMC,IAAI,CAAC;gBAChC,IAAI,OAAOuB,aAAa,UAAU;oBAChC;gBACF;gBAEA,KAAK,MAAM,EAAEC,IAAI,EAAE,IAAIF,QAAS;oBAC9B,MAAM7B,QAAQY,GAAG,CAACN,MAAMC,IAAI,CAAC,CAACwB,KAAK;oBACnC,IAAI/B,OAAO;wBACTS,qBAAqB;4BAAEC;4BAAQJ;4BAAOK,QAAQoB;4BAAMnB,KAAKkB;4BAAU9B;wBAAM;oBAC3E;gBACF;YACF,OAAO;gBACL,qCAAqC;gBACrCS,qBAAqB;oBACnBC;oBACAJ;oBACAK,QAAQqB;oBACRpB;oBACAZ,OAAOY,GAAG,CAACN,MAAMC,IAAI,CAAC;gBACxB;YACF;QACF;IACF;IAEAV,eAAe;QAAEoC,UAAUR;QAAUrB;QAAQ8B,WAAW;QAAOtB,KAAKY;IAAK;IAEzE,OAAOA;AACT,EAAC"}
|
@@ -197,6 +197,20 @@ const config = {
|
|
197
197
|
name: 'tabLocalized',
|
198
198
|
fields: relsFields,
|
199
199
|
localized: true
|
200
|
+
},
|
201
|
+
{
|
202
|
+
label: 'another',
|
203
|
+
fields: [
|
204
|
+
{
|
205
|
+
type: 'tabs',
|
206
|
+
tabs: [
|
207
|
+
{
|
208
|
+
name: 'nestedTab',
|
209
|
+
fields: relsFields
|
210
|
+
}
|
211
|
+
]
|
212
|
+
}
|
213
|
+
]
|
200
214
|
}
|
201
215
|
]
|
202
216
|
}
|
@@ -389,6 +403,9 @@ describe('sanitizeRelationshipIDs', ()=>{
|
|
389
403
|
es: {
|
390
404
|
...relsData
|
391
405
|
}
|
406
|
+
},
|
407
|
+
nestedTab: {
|
408
|
+
...relsData
|
392
409
|
}
|
393
410
|
};
|
394
411
|
const flattenValuesBefore = Object.values(flattenRelationshipValues(data));
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/sanitizeRelationshipIDs.spec.ts"],"sourcesContent":["import type { Field, SanitizedConfig } from 'payload'\n\nimport { Types } from 'mongoose'\n\nimport { sanitizeRelationshipIDs } from './sanitizeRelationshipIDs.js'\n\nconst flattenRelationshipValues = (obj: Record<string, any>, prefix = ''): Record<string, any> => {\n return Object.keys(obj).reduce(\n (acc, key) => {\n const fullKey = prefix ? `${prefix}.${key}` : key\n const value = obj[key]\n\n if (value && typeof value === 'object' && !(value instanceof Types.ObjectId)) {\n Object.assign(acc, flattenRelationshipValues(value, fullKey))\n // skip relationTo and blockType\n } else if (!fullKey.endsWith('relationTo') && !fullKey.endsWith('blockType')) {\n acc[fullKey] = value\n }\n\n return acc\n },\n {} as Record<string, any>,\n )\n}\n\nconst relsFields: Field[] = [\n {\n name: 'rel_1',\n type: 'relationship',\n relationTo: 'rels',\n },\n {\n name: 'rel_1_l',\n type: 'relationship',\n localized: true,\n relationTo: 'rels',\n },\n {\n name: 'rel_2',\n type: 'relationship',\n hasMany: true,\n relationTo: 'rels',\n },\n {\n name: 'rel_2_l',\n type: 'relationship',\n hasMany: true,\n localized: true,\n relationTo: 'rels',\n },\n {\n name: 'rel_3',\n type: 'relationship',\n relationTo: ['rels'],\n },\n {\n name: 'rel_3_l',\n type: 'relationship',\n localized: true,\n relationTo: ['rels'],\n },\n {\n name: 'rel_4',\n type: 'relationship',\n hasMany: true,\n relationTo: ['rels'],\n },\n {\n name: 'rel_4_l',\n type: 'relationship',\n hasMany: true,\n localized: true,\n relationTo: ['rels'],\n },\n]\n\nconst config = {\n collections: [\n {\n slug: 'docs',\n fields: [\n ...relsFields,\n {\n name: 'array',\n type: 'array',\n fields: [\n {\n name: 'array',\n type: 'array',\n fields: relsFields,\n },\n {\n name: 'blocks',\n type: 'blocks',\n blocks: [{ slug: 'block', fields: relsFields }],\n },\n ...relsFields,\n ],\n },\n {\n name: 'arrayLocalized',\n type: 'array',\n fields: [\n {\n name: 'array',\n type: 'array',\n fields: relsFields,\n },\n {\n name: 'blocks',\n type: 'blocks',\n blocks: [{ slug: 'block', fields: relsFields }],\n },\n ...relsFields,\n ],\n localized: true,\n },\n {\n name: 'blocks',\n type: 'blocks',\n blocks: [\n {\n slug: 'block',\n fields: [\n ...relsFields,\n {\n name: 'group',\n type: 'group',\n fields: relsFields,\n },\n {\n name: 'array',\n type: 'array',\n fields: relsFields,\n },\n ],\n },\n ],\n },\n {\n name: 'group',\n type: 'group',\n fields: [\n ...relsFields,\n {\n name: 'array',\n type: 'array',\n fields: relsFields,\n },\n ],\n },\n {\n name: 'groupLocalized',\n type: 'group',\n fields: [\n ...relsFields,\n {\n name: 'array',\n type: 'array',\n fields: relsFields,\n },\n ],\n localized: true,\n },\n {\n name: 'groupAndRow',\n type: 'group',\n fields: [\n {\n type: 'row',\n fields: [\n ...relsFields,\n {\n type: 'array',\n name: 'array',\n fields: relsFields,\n },\n ],\n },\n ],\n },\n {\n type: 'tabs',\n tabs: [\n {\n name: 'tab',\n fields: relsFields,\n },\n {\n name: 'tabLocalized',\n fields: relsFields,\n localized: true,\n },\n ],\n },\n ],\n },\n {\n slug: 'rels',\n fields: [],\n },\n ],\n localization: {\n defaultLocale: 'en',\n localeCodes: ['en', 'es'],\n locales: [\n { code: 'en', label: 'EN' },\n { code: 'es', label: 'ES' },\n ],\n },\n} as SanitizedConfig\n\nconst relsData = {\n rel_1: new Types.ObjectId().toHexString(),\n rel_1_l: {\n en: new Types.ObjectId().toHexString(),\n es: new Types.ObjectId().toHexString(),\n },\n rel_2: [new Types.ObjectId().toHexString()],\n rel_2_l: {\n en: [new Types.ObjectId().toHexString()],\n es: [new Types.ObjectId().toHexString()],\n },\n rel_3: {\n relationTo: 'rels',\n value: new Types.ObjectId().toHexString(),\n },\n rel_3_l: {\n en: {\n relationTo: 'rels',\n value: new Types.ObjectId().toHexString(),\n },\n es: {\n relationTo: 'rels',\n value: new Types.ObjectId().toHexString(),\n },\n },\n rel_4: [\n {\n relationTo: 'rels',\n value: new Types.ObjectId().toHexString(),\n },\n ],\n rel_4_l: {\n en: [\n {\n relationTo: 'rels',\n value: new Types.ObjectId().toHexString(),\n },\n ],\n es: [\n {\n relationTo: 'rels',\n value: new Types.ObjectId().toHexString(),\n },\n ],\n },\n}\n\ndescribe('sanitizeRelationshipIDs', () => {\n it('should sanitize relationships', () => {\n const data = {\n ...relsData,\n array: [\n {\n ...relsData,\n array: [{ ...relsData }],\n blocks: [\n {\n blockType: 'block',\n ...relsData,\n },\n ],\n },\n ],\n arrayLocalized: {\n en: [\n {\n ...relsData,\n array: [{ ...relsData }],\n blocks: [\n {\n blockType: 'block',\n ...relsData,\n },\n ],\n },\n ],\n es: [\n {\n ...relsData,\n array: [{ ...relsData }],\n blocks: [\n {\n blockType: 'block',\n ...relsData,\n },\n ],\n },\n ],\n },\n blocks: [\n {\n blockType: 'block',\n ...relsData,\n array: [{ ...relsData }],\n group: { ...relsData },\n },\n ],\n group: {\n ...relsData,\n array: [{ ...relsData }],\n },\n groupAndRow: {\n ...relsData,\n array: [{ ...relsData }],\n },\n groupLocalized: {\n en: {\n ...relsData,\n array: [{ ...relsData }],\n },\n es: {\n ...relsData,\n array: [{ ...relsData }],\n },\n },\n tab: { ...relsData },\n tabLocalized: {\n en: { ...relsData },\n es: { ...relsData },\n },\n }\n const flattenValuesBefore = Object.values(flattenRelationshipValues(data))\n\n sanitizeRelationshipIDs({ config, data, fields: config.collections[0].fields })\n const flattenValuesAfter = Object.values(flattenRelationshipValues(data))\n\n flattenValuesAfter.forEach((value, i) => {\n expect(value).toBeInstanceOf(Types.ObjectId)\n expect(flattenValuesBefore[i]).toBe(value.toHexString())\n })\n })\n})\n"],"names":["Types","sanitizeRelationshipIDs","flattenRelationshipValues","obj","prefix","Object","keys","reduce","acc","key","fullKey","value","ObjectId","assign","endsWith","relsFields","name","type","relationTo","localized","hasMany","config","collections","slug","fields","blocks","tabs","localization","defaultLocale","localeCodes","locales","code","label","relsData","rel_1","toHexString","rel_1_l","en","es","rel_2","rel_2_l","rel_3","rel_3_l","rel_4","rel_4_l","describe","it","data","array","blockType","arrayLocalized","group","groupAndRow","groupLocalized","tab","tabLocalized","flattenValuesBefore","values","flattenValuesAfter","forEach","i","expect","toBeInstanceOf","toBe"],"mappings":"AAEA,SAASA,KAAK,QAAQ,WAAU;AAEhC,SAASC,uBAAuB,QAAQ,+BAA8B;AAEtE,MAAMC,4BAA4B,CAACC,KAA0BC,SAAS,EAAE;IACtE,OAAOC,OAAOC,IAAI,CAACH,KAAKI,MAAM,CAC5B,CAACC,KAAKC;QACJ,MAAMC,UAAUN,SAAS,CAAC,EAAEA,OAAO,CAAC,EAAEK,IAAI,CAAC,GAAGA;QAC9C,MAAME,QAAQR,GAAG,CAACM,IAAI;QAEtB,IAAIE,SAAS,OAAOA,UAAU,YAAY,CAAEA,CAAAA,iBAAiBX,MAAMY,QAAQ,AAAD,GAAI;YAC5EP,OAAOQ,MAAM,CAACL,KAAKN,0BAA0BS,OAAOD;QACpD,gCAAgC;QAClC,OAAO,IAAI,CAACA,QAAQI,QAAQ,CAAC,iBAAiB,CAACJ,QAAQI,QAAQ,CAAC,cAAc;YAC5EN,GAAG,CAACE,QAAQ,GAAGC;QACjB;QAEA,OAAOH;IACT,GACA,CAAC;AAEL;AAEA,MAAMO,aAAsB;IAC1B;QACEC,MAAM;QACNC,MAAM;QACNC,YAAY;IACd;IACA;QACEF,MAAM;QACNC,MAAM;QACNE,WAAW;QACXD,YAAY;IACd;IACA;QACEF,MAAM;QACNC,MAAM;QACNG,SAAS;QACTF,YAAY;IACd;IACA;QACEF,MAAM;QACNC,MAAM;QACNG,SAAS;QACTD,WAAW;QACXD,YAAY;IACd;IACA;QACEF,MA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;oBAAC;wBAAE,GAAGf,QAAQ;oBAAC;iBAAE;YAC1B;YACAoB,gBAAgB;gBACdhB,IAAI;oBACF,GAAGJ,QAAQ;oBACXe,OAAO;wBAAC;4BAAE,GAAGf,QAAQ;wBAAC;qBAAE;gBAC1B;gBACAK,IAAI;oBACF,GAAGL,QAAQ;oBACXe,OAAO;wBAAC;4BAAE,GAAGf,QAAQ;wBAAC;qBAAE;gBAC1B;YACF;YACAqB,KAAK;gBAAE,GAAGrB,QAAQ;YAAC;YACnBsB,cAAc;gBACZlB,IAAI;oBAAE,GAAGJ,QAAQ;gBAAC;gBAClBK,IAAI;oBAAE,GAAGL,QAAQ;gBAAC;YACpB;QACF;QACA,MAAMuB,sBAAsBnD,OAAOoD,MAAM,CAACvD,0BAA0B6C;QAEpE9C,wBAAwB;YAAEoB;YAAQ0B;YAAMvB,QAAQH,OAAOC,WAAW,CAAC,EAAE,CAACE,MAAM;QAAC;QAC7E,MAAMkC,qBAAqBrD,OAAOoD,MAAM,CAACvD,0BAA0B6C;QAEnEW,mBAAmBC,OAAO,CAAC,CAAChD,OAAOiD;YACjCC,OAAOlD,OAAOmD,cAAc,CAAC9D,MAAMY,QAAQ;YAC3CiD,OAAOL,mBAAmB,CAACI,EAAE,EAAEG,IAAI,CAACpD,MAAMwB,WAAW;QACvD;IACF;AACF"}
|
1
|
+
{"version":3,"sources":["../../src/utilities/sanitizeRelationshipIDs.spec.ts"],"sourcesContent":["import type { Field, SanitizedConfig } from 'payload'\n\nimport { Types } from 'mongoose'\n\nimport { sanitizeRelationshipIDs } from './sanitizeRelationshipIDs.js'\n\nconst flattenRelationshipValues = (obj: Record<string, any>, prefix = ''): Record<string, any> => {\n return Object.keys(obj).reduce(\n (acc, key) => {\n const fullKey = prefix ? `${prefix}.${key}` : key\n const value = obj[key]\n\n if (value && typeof value === 'object' && !(value instanceof Types.ObjectId)) {\n Object.assign(acc, flattenRelationshipValues(value, fullKey))\n // skip relationTo and blockType\n } else if (!fullKey.endsWith('relationTo') && !fullKey.endsWith('blockType')) {\n acc[fullKey] = value\n }\n\n return acc\n },\n {} as Record<string, any>,\n )\n}\n\nconst relsFields: Field[] = [\n {\n name: 'rel_1',\n type: 'relationship',\n relationTo: 'rels',\n },\n {\n name: 'rel_1_l',\n type: 'relationship',\n localized: true,\n relationTo: 'rels',\n },\n {\n name: 'rel_2',\n type: 'relationship',\n hasMany: true,\n relationTo: 'rels',\n },\n {\n name: 'rel_2_l',\n type: 'relationship',\n hasMany: true,\n localized: true,\n relationTo: 'rels',\n },\n {\n name: 'rel_3',\n type: 'relationship',\n relationTo: ['rels'],\n },\n {\n name: 'rel_3_l',\n type: 'relationship',\n localized: true,\n relationTo: ['rels'],\n },\n {\n name: 'rel_4',\n type: 'relationship',\n hasMany: true,\n relationTo: ['rels'],\n },\n {\n name: 'rel_4_l',\n type: 'relationship',\n hasMany: true,\n localized: true,\n relationTo: ['rels'],\n },\n]\n\nconst config = {\n collections: [\n {\n slug: 'docs',\n fields: [\n ...relsFields,\n {\n name: 'array',\n type: 'array',\n fields: [\n {\n name: 'array',\n type: 'array',\n fields: relsFields,\n },\n {\n name: 'blocks',\n type: 'blocks',\n blocks: [{ slug: 'block', fields: relsFields }],\n },\n ...relsFields,\n ],\n },\n {\n name: 'arrayLocalized',\n type: 'array',\n fields: [\n {\n name: 'array',\n type: 'array',\n fields: relsFields,\n },\n {\n name: 'blocks',\n type: 'blocks',\n blocks: [{ slug: 'block', fields: relsFields }],\n },\n ...relsFields,\n ],\n localized: true,\n },\n {\n name: 'blocks',\n type: 'blocks',\n blocks: [\n {\n slug: 'block',\n fields: [\n ...relsFields,\n {\n name: 'group',\n type: 'group',\n fields: relsFields,\n },\n {\n name: 'array',\n type: 'array',\n fields: relsFields,\n },\n ],\n },\n ],\n },\n {\n name: 'group',\n type: 'group',\n fields: [\n ...relsFields,\n {\n name: 'array',\n type: 'array',\n fields: relsFields,\n },\n ],\n },\n {\n name: 'groupLocalized',\n type: 'group',\n fields: [\n ...relsFields,\n {\n name: 'array',\n type: 'array',\n fields: relsFields,\n },\n ],\n localized: true,\n },\n {\n name: 'groupAndRow',\n type: 'group',\n fields: [\n {\n type: 'row',\n fields: [\n ...relsFields,\n {\n type: 'array',\n name: 'array',\n fields: relsFields,\n },\n ],\n },\n ],\n },\n {\n type: 'tabs',\n tabs: [\n {\n name: 'tab',\n fields: relsFields,\n },\n {\n name: 'tabLocalized',\n fields: relsFields,\n localized: true,\n },\n {\n label: 'another',\n fields: [\n {\n type: 'tabs',\n tabs: [\n {\n name: 'nestedTab',\n fields: relsFields,\n },\n ],\n },\n ],\n },\n ],\n },\n ],\n },\n {\n slug: 'rels',\n fields: [],\n },\n ],\n localization: {\n defaultLocale: 'en',\n localeCodes: ['en', 'es'],\n locales: [\n { code: 'en', label: 'EN' },\n { code: 'es', label: 'ES' },\n ],\n },\n} as SanitizedConfig\n\nconst relsData = {\n rel_1: new Types.ObjectId().toHexString(),\n rel_1_l: {\n en: new Types.ObjectId().toHexString(),\n es: new Types.ObjectId().toHexString(),\n },\n rel_2: [new Types.ObjectId().toHexString()],\n rel_2_l: {\n en: [new Types.ObjectId().toHexString()],\n es: [new Types.ObjectId().toHexString()],\n },\n rel_3: {\n relationTo: 'rels',\n value: new Types.ObjectId().toHexString(),\n },\n rel_3_l: {\n en: {\n relationTo: 'rels',\n value: new Types.ObjectId().toHexString(),\n },\n es: {\n relationTo: 'rels',\n value: new Types.ObjectId().toHexString(),\n },\n },\n rel_4: [\n {\n relationTo: 'rels',\n value: new Types.ObjectId().toHexString(),\n },\n ],\n rel_4_l: {\n en: [\n {\n relationTo: 'rels',\n value: new Types.ObjectId().toHexString(),\n },\n ],\n es: [\n {\n relationTo: 'rels',\n value: new Types.ObjectId().toHexString(),\n },\n ],\n },\n}\n\ndescribe('sanitizeRelationshipIDs', () => {\n it('should sanitize relationships', () => {\n const data = {\n ...relsData,\n array: [\n {\n ...relsData,\n array: [{ ...relsData }],\n blocks: [\n {\n blockType: 'block',\n ...relsData,\n },\n ],\n },\n ],\n arrayLocalized: {\n en: [\n {\n ...relsData,\n array: [{ ...relsData }],\n blocks: [\n {\n blockType: 'block',\n ...relsData,\n },\n ],\n },\n ],\n es: [\n {\n ...relsData,\n array: [{ ...relsData }],\n blocks: [\n {\n blockType: 'block',\n ...relsData,\n },\n ],\n },\n ],\n },\n blocks: [\n {\n blockType: 'block',\n ...relsData,\n array: [{ ...relsData }],\n group: { ...relsData },\n },\n ],\n group: {\n ...relsData,\n array: [{ ...relsData }],\n },\n groupAndRow: {\n ...relsData,\n array: [{ ...relsData }],\n },\n groupLocalized: {\n en: {\n ...relsData,\n array: [{ ...relsData }],\n },\n es: {\n ...relsData,\n array: [{ ...relsData }],\n },\n },\n tab: { ...relsData },\n tabLocalized: {\n en: { ...relsData },\n es: { ...relsData },\n },\n nestedTab: { ...relsData },\n }\n const flattenValuesBefore = Object.values(flattenRelationshipValues(data))\n\n sanitizeRelationshipIDs({ config, data, fields: config.collections[0].fields })\n const flattenValuesAfter = Object.values(flattenRelationshipValues(data))\n\n flattenValuesAfter.forEach((value, i) => {\n expect(value).toBeInstanceOf(Types.ObjectId)\n expect(flattenValuesBefore[i]).toBe(value.toHexString())\n })\n })\n})\n"],"names":["Types","sanitizeRelationshipIDs","flattenRelationshipValues","obj","prefix","Object","keys","reduce","acc","key","fullKey","value","ObjectId","assign","endsWith","relsFields","name","type","relationTo","localized","hasMany","config","collections","slug","fields","blocks","tabs","label","localization","defaultLocale","localeCodes","locales","code","relsData","rel_1","toHexString","rel_1_l","en","es","rel_2","rel_2_l","rel_3","rel_3_l","rel_4","rel_4_l","describe","it","data","array","blockType","arrayLocalized","group","groupAndRow","groupLocalized","tab","tabLocalized","nestedTab","flattenValuesBefore","values","flattenValuesAfter","forEach","i","expect","toBeInstanceOf","toBe"],"mappings":"AAEA,SAASA,KAAK,QAAQ,WAAU;AAEhC,SAASC,uBAAuB,QAAQ,+BAA8B;AAEtE,MAAMC,4BAA4B,CAACC,KAA0BC,SAAS,EAA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c;gBACZlB,IAAI;oBAAE,GAAGJ,QAAQ;gBAAC;gBAClBK,IAAI;oBAAE,GAAGL,QAAQ;gBAAC;YACpB;YACAuB,WAAW;gBAAE,GAAGvB,QAAQ;YAAC;QAC3B;QACA,MAAMwB,sBAAsBpD,OAAOqD,MAAM,CAACxD,0BAA0B6C;QAEpE9C,wBAAwB;YAAEoB;YAAQ0B;YAAMvB,QAAQH,OAAOC,WAAW,CAAC,EAAE,CAACE,MAAM;QAAC;QAC7E,MAAMmC,qBAAqBtD,OAAOqD,MAAM,CAACxD,0BAA0B6C;QAEnEY,mBAAmBC,OAAO,CAAC,CAACjD,OAAOkD;YACjCC,OAAOnD,OAAOoD,cAAc,CAAC/D,MAAMY,QAAQ;YAC3CkD,OAAOL,mBAAmB,CAACI,EAAE,EAAEG,IAAI,CAACrD,MAAMwB,WAAW;QACvD;IACF;AACF"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@payloadcms/db-mongodb",
|
3
|
-
"version": "3.1.
|
3
|
+
"version": "3.1.2-canary.eb1a61e",
|
4
4
|
"description": "The officially supported MongoDB database adapter for Payload",
|
5
5
|
"homepage": "https://payloadcms.com",
|
6
6
|
"repository": {
|
@@ -49,10 +49,10 @@
|
|
49
49
|
"mongodb": "6.10.0",
|
50
50
|
"mongodb-memory-server": "^9",
|
51
51
|
"@payloadcms/eslint-config": "3.0.0",
|
52
|
-
"payload": "3.1.
|
52
|
+
"payload": "3.1.2-canary.eb1a61e"
|
53
53
|
},
|
54
54
|
"peerDependencies": {
|
55
|
-
"payload": "3.1.
|
55
|
+
"payload": "3.1.2-canary.eb1a61e"
|
56
56
|
},
|
57
57
|
"scripts": {
|
58
58
|
"build": "pnpm build:types && pnpm build:swc",
|