@payloadcms/db-mongodb 3.0.0-canary.291e44c → 3.0.0-canary.2d0dd26

Sign up to get free protection for your applications and to get access to all the features.
Files changed (130) hide show
  1. package/dist/connect.d.ts.map +1 -1
  2. package/dist/connect.js +5 -0
  3. package/dist/connect.js.map +1 -1
  4. package/dist/count.d.ts.map +1 -1
  5. package/dist/count.js +8 -1
  6. package/dist/count.js.map +1 -1
  7. package/dist/countGlobalVersions.d.ts +3 -0
  8. package/dist/countGlobalVersions.d.ts.map +1 -0
  9. package/dist/countGlobalVersions.js +40 -0
  10. package/dist/countGlobalVersions.js.map +1 -0
  11. package/dist/countVersions.d.ts +3 -0
  12. package/dist/countVersions.d.ts.map +1 -0
  13. package/dist/countVersions.js +40 -0
  14. package/dist/countVersions.js.map +1 -0
  15. package/dist/create.d.ts.map +1 -1
  16. package/dist/create.js +3 -0
  17. package/dist/create.js.map +1 -1
  18. package/dist/createMigration.d.ts.map +1 -1
  19. package/dist/createMigration.js +6 -4
  20. package/dist/createMigration.js.map +1 -1
  21. package/dist/createVersion.js +2 -2
  22. package/dist/createVersion.js.map +1 -1
  23. package/dist/deleteOne.d.ts.map +1 -1
  24. package/dist/deleteOne.js +10 -2
  25. package/dist/deleteOne.js.map +1 -1
  26. package/dist/exports/migration-utils.d.ts +3 -0
  27. package/dist/exports/migration-utils.d.ts.map +1 -0
  28. package/dist/exports/migration-utils.js +4 -0
  29. package/dist/exports/migration-utils.js.map +1 -0
  30. package/dist/find.d.ts.map +1 -1
  31. package/dist/find.js +9 -3
  32. package/dist/find.js.map +1 -1
  33. package/dist/findGlobal.d.ts.map +1 -1
  34. package/dist/findGlobal.js +8 -2
  35. package/dist/findGlobal.js.map +1 -1
  36. package/dist/findGlobalVersions.d.ts.map +1 -1
  37. package/dist/findGlobalVersions.js +7 -2
  38. package/dist/findGlobalVersions.js.map +1 -1
  39. package/dist/findOne.d.ts.map +1 -1
  40. package/dist/findOne.js +9 -1
  41. package/dist/findOne.js.map +1 -1
  42. package/dist/findVersions.d.ts.map +1 -1
  43. package/dist/findVersions.js +8 -3
  44. package/dist/findVersions.js.map +1 -1
  45. package/dist/index.d.ts +18 -2
  46. package/dist/index.d.ts.map +1 -1
  47. package/dist/index.js +7 -2
  48. package/dist/index.js.map +1 -1
  49. package/dist/init.d.ts.map +1 -1
  50. package/dist/init.js +11 -12
  51. package/dist/init.js.map +1 -1
  52. package/dist/models/buildCollectionSchema.d.ts +2 -2
  53. package/dist/models/buildCollectionSchema.d.ts.map +1 -1
  54. package/dist/models/buildCollectionSchema.js +4 -4
  55. package/dist/models/buildCollectionSchema.js.map +1 -1
  56. package/dist/models/buildGlobalModel.d.ts +2 -2
  57. package/dist/models/buildGlobalModel.d.ts.map +1 -1
  58. package/dist/models/buildGlobalModel.js +4 -4
  59. package/dist/models/buildGlobalModel.js.map +1 -1
  60. package/dist/models/buildSchema.d.ts +2 -2
  61. package/dist/models/buildSchema.d.ts.map +1 -1
  62. package/dist/models/buildSchema.js +98 -62
  63. package/dist/models/buildSchema.js.map +1 -1
  64. package/dist/predefinedMigrations/migrateRelationshipsV2_V3.d.ts +6 -0
  65. package/dist/predefinedMigrations/migrateRelationshipsV2_V3.d.ts.map +1 -0
  66. package/dist/predefinedMigrations/migrateRelationshipsV2_V3.js +141 -0
  67. package/dist/predefinedMigrations/migrateRelationshipsV2_V3.js.map +1 -0
  68. package/dist/predefinedMigrations/migrateVersionsV1_V2.d.ts +5 -0
  69. package/dist/predefinedMigrations/migrateVersionsV1_V2.d.ts.map +1 -0
  70. package/dist/predefinedMigrations/migrateVersionsV1_V2.js +107 -0
  71. package/dist/predefinedMigrations/migrateVersionsV1_V2.js.map +1 -0
  72. package/dist/predefinedMigrations/relationships-v2-v3.d.ts +4 -0
  73. package/dist/predefinedMigrations/relationships-v2-v3.d.ts.map +1 -0
  74. package/dist/predefinedMigrations/relationships-v2-v3.js +9 -0
  75. package/dist/predefinedMigrations/relationships-v2-v3.js.map +1 -0
  76. package/dist/predefinedMigrations/versions-v1-v2.d.ts +4 -0
  77. package/dist/predefinedMigrations/versions-v1-v2.d.ts.map +1 -0
  78. package/dist/predefinedMigrations/versions-v1-v2.js +5 -95
  79. package/dist/predefinedMigrations/versions-v1-v2.js.map +1 -1
  80. package/dist/queries/buildSearchParams.d.ts.map +1 -1
  81. package/dist/queries/buildSearchParams.js +10 -7
  82. package/dist/queries/buildSearchParams.js.map +1 -1
  83. package/dist/queries/buildSortParam.d.ts +2 -2
  84. package/dist/queries/buildSortParam.d.ts.map +1 -1
  85. package/dist/queries/buildSortParam.js +26 -17
  86. package/dist/queries/buildSortParam.js.map +1 -1
  87. package/dist/queries/parseParams.d.ts.map +1 -1
  88. package/dist/queries/parseParams.js +4 -1
  89. package/dist/queries/parseParams.js.map +1 -1
  90. package/dist/queries/sanitizeQueryValue.d.ts +3 -2
  91. package/dist/queries/sanitizeQueryValue.d.ts.map +1 -1
  92. package/dist/queries/sanitizeQueryValue.js +157 -47
  93. package/dist/queries/sanitizeQueryValue.js.map +1 -1
  94. package/dist/queryDrafts.d.ts.map +1 -1
  95. package/dist/queryDrafts.js +28 -7
  96. package/dist/queryDrafts.js.map +1 -1
  97. package/dist/updateGlobal.d.ts.map +1 -1
  98. package/dist/updateGlobal.js +11 -3
  99. package/dist/updateGlobal.js.map +1 -1
  100. package/dist/updateGlobalVersion.d.ts +1 -1
  101. package/dist/updateGlobalVersion.d.ts.map +1 -1
  102. package/dist/updateGlobalVersion.js +11 -3
  103. package/dist/updateGlobalVersion.js.map +1 -1
  104. package/dist/updateOne.d.ts.map +1 -1
  105. package/dist/updateOne.js +10 -3
  106. package/dist/updateOne.js.map +1 -1
  107. package/dist/updateVersion.d.ts.map +1 -1
  108. package/dist/updateVersion.js +11 -3
  109. package/dist/updateVersion.js.map +1 -1
  110. package/dist/upsert.js +2 -1
  111. package/dist/upsert.js.map +1 -1
  112. package/dist/utilities/buildJoinAggregation.d.ts +4 -1
  113. package/dist/utilities/buildJoinAggregation.d.ts.map +1 -1
  114. package/dist/utilities/buildJoinAggregation.js +20 -9
  115. package/dist/utilities/buildJoinAggregation.js.map +1 -1
  116. package/dist/utilities/buildProjectionFromSelect.d.ts +8 -0
  117. package/dist/utilities/buildProjectionFromSelect.d.ts.map +1 -0
  118. package/dist/utilities/buildProjectionFromSelect.js +171 -0
  119. package/dist/utilities/buildProjectionFromSelect.js.map +1 -0
  120. package/dist/utilities/handleError.js +2 -2
  121. package/dist/utilities/handleError.js.map +1 -1
  122. package/dist/utilities/sanitizeRelationshipIDs.d.ts.map +1 -1
  123. package/dist/utilities/sanitizeRelationshipIDs.js +19 -5
  124. package/dist/utilities/sanitizeRelationshipIDs.js.map +1 -1
  125. package/dist/utilities/sanitizeRelationshipIDs.spec.js +408 -0
  126. package/dist/utilities/sanitizeRelationshipIDs.spec.js.map +1 -0
  127. package/license.md +22 -0
  128. package/package.json +21 -11
  129. package/dist/queries/mock.js +0 -2
  130. package/dist/queries/mock.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/updateGlobal.ts"],"sourcesContent":["import type { PayloadRequest, UpdateGlobal } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\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, req = {} as PayloadRequest },\n) {\n const Model = this.globals\n const options = {\n ...(await withSession(this, req)),\n lean: true,\n new: true,\n }\n\n let result\n\n const sanitizedData = sanitizeRelationshipIDs({\n config: this.payload.config,\n data,\n fields: this.payload.config.globals.find((global) => global.slug === slug).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":["sanitizeInternalFields","sanitizeRelationshipIDs","withSession","updateGlobal","slug","data","req","Model","globals","options","lean","new","result","sanitizedData","config","payload","fields","find","global","findOneAndUpdate","globalType","JSON","parse","stringify","id","_id"],"mappings":"AAIA,SAASA,sBAAsB,QAAQ,wCAAuC;AAC9E,SAASC,uBAAuB,QAAQ,yCAAwC;AAChF,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,eAA6B,eAAeA,aAEvD,EAAEC,IAAI,EAAEC,IAAI,EAAEC,MAAM,CAAC,CAAmB,EAAE;IAE1C,MAAMC,QAAQ,IAAI,CAACC,OAAO;IAC1B,MAAMC,UAAU;QACd,GAAI,MAAMP,YAAY,IAAI,EAAEI,IAAI;QAChCI,MAAM;QACNC,KAAK;IACP;IAEA,IAAIC;IAEJ,MAAMC,gBAAgBZ,wBAAwB;QAC5Ca,QAAQ,IAAI,CAACC,OAAO,CAACD,MAAM;QAC3BT;QACAW,QAAQ,IAAI,CAACD,OAAO,CAACD,MAAM,CAACN,OAAO,CAACS,IAAI,CAAC,CAACC,SAAWA,OAAOd,IAAI,KAAKA,MAAMY,MAAM;IACnF;IAEAJ,SAAS,MAAML,MAAMY,gBAAgB,CAAC;QAAEC,YAAYhB;IAAK,GAAGS,eAAeJ;IAE3EG,SAASS,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACX;IAEnC,uBAAuB;IACvBA,OAAOY,EAAE,GAAGZ,OAAOa,GAAG;IACtBb,SAASZ,uBAAuBY;IAEhC,OAAOA;AACT,EAAC"}
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({ adapter: this, fields, select }),\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","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;YAAEqB,SAAS,IAAI;YAAER;YAAQH;QAAO;IACxE;IAEA,IAAIY;IAEJ,MAAMC,gBAAgBrB,wBAAwB;QAC5Ca,QAAQ,IAAI,CAACD,OAAO,CAACC,MAAM;QAC3BT;QACAO;IACF;IAEAS,SAAS,MAAMX,MAAMa,gBAAgB,CAAC;QAAEC,YAAYpB;IAAK,GAAGkB,eAAehB;IAE3Ee,SAASI,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACN;IAEnC,uBAAuB;IACvBA,OAAOO,EAAE,GAAGP,OAAOQ,GAAG;IACtBR,SAASrB,uBAAuBqB;IAEhC,OAAOA;AACT,EAAC"}
@@ -1,4 +1,4 @@
1
1
  import { type TypeWithID, type UpdateGlobalVersionArgs } from 'payload';
2
2
  import type { MongooseAdapter } from './index.js';
3
- export declare function updateGlobalVersion<T extends TypeWithID>(this: MongooseAdapter, { id, global: globalSlug, locale, req, versionData, where, }: UpdateGlobalVersionArgs<T>): Promise<any>;
3
+ export declare function updateGlobalVersion<T extends TypeWithID>(this: MongooseAdapter, { id, global: globalSlug, locale, options: optionsArgs, req, select, versionData, where, }: UpdateGlobalVersionArgs<T>): Promise<any>;
4
4
  //# sourceMappingURL=updateGlobalVersion.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"updateGlobalVersion.d.ts","sourceRoot":"","sources":["../src/updateGlobalVersion.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,UAAU,EACf,KAAK,uBAAuB,EAC7B,MAAM,SAAS,CAAA;AAEhB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAKjD,wBAAsB,mBAAmB,CAAC,CAAC,SAAS,UAAU,EAC5D,IAAI,EAAE,eAAe,EACrB,EACE,EAAE,EACF,MAAM,EAAE,UAAU,EAClB,MAAM,EACN,GAA0B,EAC1B,WAAW,EACX,KAAK,GACN,EAAE,uBAAuB,CAAC,CAAC,CAAC,gBAqC9B"}
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,gBAyC9B"}
@@ -1,17 +1,25 @@
1
1
  import { buildVersionGlobalFields } from 'payload';
2
+ import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
2
3
  import { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.js';
3
4
  import { withSession } from './withSession.js';
4
- export async function updateGlobalVersion({ id, global: globalSlug, locale, req = {}, versionData, where }) {
5
+ export async function updateGlobalVersion({ id, global: globalSlug, locale, options: optionsArgs = {}, req = {}, select, versionData, where }) {
5
6
  const VersionModel = this.versions[globalSlug];
6
7
  const whereToUse = where || {
7
8
  id: {
8
9
  equals: id
9
10
  }
10
11
  };
12
+ const fields = buildVersionGlobalFields(this.payload.config, this.payload.config.globals.find((global)=>global.slug === globalSlug));
11
13
  const options = {
14
+ ...optionsArgs,
12
15
  ...await withSession(this, req),
13
16
  lean: true,
14
- new: true
17
+ new: true,
18
+ projection: buildProjectionFromSelect({
19
+ adapter: this,
20
+ fields,
21
+ select
22
+ })
15
23
  };
16
24
  const query = await VersionModel.buildQuery({
17
25
  locale,
@@ -21,7 +29,7 @@ export async function updateGlobalVersion({ id, global: globalSlug, locale, req
21
29
  const sanitizedData = sanitizeRelationshipIDs({
22
30
  config: this.payload.config,
23
31
  data: versionData,
24
- fields: buildVersionGlobalFields(this.payload.config, this.payload.config.globals.find((global)=>global.slug === globalSlug))
32
+ fields
25
33
  });
26
34
  const doc = await VersionModel.findOneAndUpdate(query, sanitizedData, options);
27
35
  const result = JSON.parse(JSON.stringify(doc));
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/updateGlobalVersion.ts"],"sourcesContent":["import {\n buildVersionGlobalFields,\n type PayloadRequest,\n type TypeWithID,\n type UpdateGlobalVersionArgs,\n} from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\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 req = {} as PayloadRequest,\n versionData,\n where,\n }: UpdateGlobalVersionArgs<T>,\n) {\n const VersionModel = this.versions[globalSlug]\n const whereToUse = where || { id: { equals: id } }\n const options = {\n ...(await withSession(this, req)),\n lean: true,\n new: true,\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: buildVersionGlobalFields(\n this.payload.config,\n this.payload.config.globals.find((global) => global.slug === globalSlug),\n ),\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","sanitizeRelationshipIDs","withSession","updateGlobalVersion","id","global","globalSlug","locale","req","versionData","where","VersionModel","versions","whereToUse","equals","options","lean","new","query","buildQuery","payload","sanitizedData","config","data","fields","globals","find","slug","doc","findOneAndUpdate","result","JSON","parse","stringify","verificationToken","_verificationToken","_id"],"mappings":"AAAA,SACEA,wBAAwB,QAInB,UAAS;AAIhB,SAASC,uBAAuB,QAAQ,yCAAwC;AAChF,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,eAAeC,oBAEpB,EACEC,EAAE,EACFC,QAAQC,UAAU,EAClBC,MAAM,EACNC,MAAM,CAAC,CAAmB,EAC1BC,WAAW,EACXC,KAAK,EACsB;IAE7B,MAAMC,eAAe,IAAI,CAACC,QAAQ,CAACN,WAAW;IAC9C,MAAMO,aAAaH,SAAS;QAAEN,IAAI;YAAEU,QAAQV;QAAG;IAAE;IACjD,MAAMW,UAAU;QACd,GAAI,MAAMb,YAAY,IAAI,EAAEM,IAAI;QAChCQ,MAAM;QACNC,KAAK;IACP;IAEA,MAAMC,QAAQ,MAAMP,aAAaQ,UAAU,CAAC;QAC1CZ;QACAa,SAAS,IAAI,CAACA,OAAO;QACrBV,OAAOG;IACT;IAEA,MAAMQ,gBAAgBpB,wBAAwB;QAC5CqB,QAAQ,IAAI,CAACF,OAAO,CAACE,MAAM;QAC3BC,MAAMd;QACNe,QAAQxB,yBACN,IAAI,CAACoB,OAAO,CAACE,MAAM,EACnB,IAAI,CAACF,OAAO,CAACE,MAAM,CAACG,OAAO,CAACC,IAAI,CAAC,CAACrB,SAAWA,OAAOsB,IAAI,KAAKrB;IAEjE;IAEA,MAAMsB,MAAM,MAAMjB,aAAakB,gBAAgB,CAACX,OAAOG,eAAeN;IAEtE,MAAMe,SAASC,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACL;IAEzC,MAAMM,oBAAoBN,IAAIO,kBAAkB;IAEhD,uBAAuB;IACvBL,OAAO1B,EAAE,GAAG0B,OAAOM,GAAG;IACtB,IAAIF,mBAAmB;QACrBJ,OAAOK,kBAAkB,GAAGD;IAC9B;IACA,OAAOJ;AACT"}
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 fields = buildVersionGlobalFields(\n this.payload.config,\n this.payload.config.globals.find((global) => global.slug === globalSlug),\n )\n\n const options: QueryOptions = {\n ...optionsArgs,\n ...(await withSession(this, req)),\n lean: true,\n new: true,\n projection: buildProjectionFromSelect({ adapter: this, fields, select }),\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","fields","payload","config","globals","find","slug","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;IACjD,MAAMc,SAASnB,yBACb,IAAI,CAACoB,OAAO,CAACC,MAAM,EACnB,IAAI,CAACD,OAAO,CAACC,MAAM,CAACC,OAAO,CAACC,IAAI,CAAC,CAACjB,SAAWA,OAAOkB,IAAI,KAAKjB;IAG/D,MAAME,UAAwB;QAC5B,GAAGC,WAAW;QACd,GAAI,MAAMP,YAAY,IAAI,EAAEQ,IAAI;QAChCc,MAAM;QACNC,KAAK;QACLC,YAAY1B,0BAA0B;YAAE2B,SAAS,IAAI;YAAET;YAAQP;QAAO;IACxE;IAEA,MAAMiB,QAAQ,MAAMd,aAAae,UAAU,CAAC;QAC1CtB;QACAY,SAAS,IAAI,CAACA,OAAO;QACrBN,OAAOG;IACT;IAEA,MAAMc,gBAAgB7B,wBAAwB;QAC5CmB,QAAQ,IAAI,CAACD,OAAO,CAACC,MAAM;QAC3BW,MAAMnB;QACNM;IACF;IAEA,MAAMc,MAAM,MAAMlB,aAAamB,gBAAgB,CAACL,OAAOE,eAAetB;IAEtE,MAAM0B,SAASC,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACL;IAEzC,MAAMM,oBAAoBN,IAAIO,kBAAkB;IAEhD,uBAAuB;IACvBL,OAAO9B,EAAE,GAAG8B,OAAOM,GAAG;IACtB,IAAIF,mBAAmB;QACrBJ,OAAOK,kBAAkB,GAAGD;IAC9B;IACA,OAAOJ;AACT"}
@@ -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;AASxD,eAAO,MAAM,SAAS,EAAE,SA8CvB,CAAA"}
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,SAiDvB,CAAA"}
package/dist/updateOne.js CHANGED
@@ -1,19 +1,26 @@
1
+ import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
1
2
  import { handleError } from './utilities/handleError.js';
2
3
  import { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js';
3
4
  import { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.js';
4
5
  import { withSession } from './withSession.js';
5
- export const updateOne = async function updateOne({ id, collection, data, locale, options: optionsArgs = {}, req = {}, where: whereArg }) {
6
+ export const updateOne = async function updateOne({ id, collection, data, locale, options: optionsArgs = {}, req = {}, select, where: whereArg }) {
6
7
  const where = id ? {
7
8
  id: {
8
9
  equals: id
9
10
  }
10
11
  } : whereArg;
11
12
  const Model = this.collections[collection];
13
+ const fields = this.payload.collections[collection].config.fields;
12
14
  const options = {
13
15
  ...optionsArgs,
14
16
  ...await withSession(this, req),
15
17
  lean: true,
16
- new: true
18
+ new: true,
19
+ projection: buildProjectionFromSelect({
20
+ adapter: this,
21
+ fields,
22
+ select
23
+ })
17
24
  };
18
25
  const query = await Model.buildQuery({
19
26
  locale,
@@ -24,7 +31,7 @@ export const updateOne = async function updateOne({ id, collection, data, locale
24
31
  const sanitizedData = sanitizeRelationshipIDs({
25
32
  config: this.payload.config,
26
33
  data,
27
- fields: this.payload.collections[collection].config.fields
34
+ fields
28
35
  });
29
36
  try {
30
37
  result = await Model.findOneAndUpdate(query, sanitizedData, options);
@@ -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 { 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 where: whereArg,\n },\n) {\n const where = id ? { id: { equals: id } } : whereArg\n const Model = this.collections[collection]\n const options: QueryOptions = {\n ...optionsArgs,\n ...(await withSession(this, req)),\n lean: true,\n new: true,\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: this.payload.collections[collection].config.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":["handleError","sanitizeInternalFields","sanitizeRelationshipIDs","withSession","updateOne","id","collection","data","locale","options","optionsArgs","req","where","whereArg","equals","Model","collections","lean","new","query","buildQuery","payload","result","sanitizedData","config","fields","findOneAndUpdate","error","JSON","parse","stringify","_id"],"mappings":"AAKA,SAASA,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,OAAOC,QAAQ,EAChB;IAED,MAAMD,QAAQP,KAAK;QAAEA,IAAI;YAAES,QAAQT;QAAG;IAAE,IAAIQ;IAC5C,MAAME,QAAQ,IAAI,CAACC,WAAW,CAACV,WAAW;IAC1C,MAAMG,UAAwB;QAC5B,GAAGC,WAAW;QACd,GAAI,MAAMP,YAAY,IAAI,EAAEQ,IAAI;QAChCM,MAAM;QACNC,KAAK;IACP;IAEA,MAAMC,QAAQ,MAAMJ,MAAMK,UAAU,CAAC;QACnCZ;QACAa,SAAS,IAAI,CAACA,OAAO;QACrBT;IACF;IAEA,IAAIU;IAEJ,MAAMC,gBAAgBrB,wBAAwB;QAC5CsB,QAAQ,IAAI,CAACH,OAAO,CAACG,MAAM;QAC3BjB;QACAkB,QAAQ,IAAI,CAACJ,OAAO,CAACL,WAAW,CAACV,WAAW,CAACkB,MAAM,CAACC,MAAM;IAC5D;IAEA,IAAI;QACFH,SAAS,MAAMP,MAAMW,gBAAgB,CAACP,OAAOI,eAAed;IAC9D,EAAE,OAAOkB,OAAO;QACd3B,YAAY;YAAEM;YAAYqB;YAAOhB;QAAI;IACvC;IAEAW,SAASM,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACR;IACnCA,OAAOjB,EAAE,GAAGiB,OAAOS,GAAG;IACtBT,SAASrB,uBAAuBqB;IAEhC,OAAOA;AACT,EAAC"}
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({ adapter: this, fields, select }),\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","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;YAAEyB,SAAS,IAAI;YAAEN;YAAQN;QAAO;IACxE;IAEA,MAAMa,QAAQ,MAAMT,MAAMU,UAAU,CAAC;QACnClB;QACAW,SAAS,IAAI,CAACA,OAAO;QACrBN;IACF;IAEA,IAAIc;IAEJ,MAAMC,gBAAgB1B,wBAAwB;QAC5CkB,QAAQ,IAAI,CAACD,OAAO,CAACC,MAAM;QAC3Bb;QACAW;IACF;IAEA,IAAI;QACFS,SAAS,MAAMX,MAAMa,gBAAgB,CAACJ,OAAOG,eAAenB;IAC9D,EAAE,OAAOqB,OAAO;QACd9B,YAAY;YAAEM;YAAYwB;YAAOnB;QAAI;IACvC;IAEAgB,SAASI,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACN;IACnCA,OAAOtB,EAAE,GAAGsB,OAAOO,GAAG;IACtBP,SAAS1B,uBAAuB0B;IAEhC,OAAOA;AACT,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"updateVersion.d.ts","sourceRoot":"","sources":["../src/updateVersion.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqD,KAAK,aAAa,EAAE,MAAM,SAAS,CAAA;AAO/F,eAAO,MAAM,aAAa,EAAE,aAuC3B,CAAA"}
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,aAoD3B,CAAA"}
@@ -1,17 +1,25 @@
1
1
  import { buildVersionCollectionFields } from 'payload';
2
+ import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
2
3
  import { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.js';
3
4
  import { withSession } from './withSession.js';
4
- export const updateVersion = async function updateVersion({ id, collection, locale, req = {}, versionData, where }) {
5
+ export const updateVersion = async function updateVersion({ id, collection, locale, options: optionsArgs = {}, req = {}, select, versionData, where }) {
5
6
  const VersionModel = this.versions[collection];
6
7
  const whereToUse = where || {
7
8
  id: {
8
9
  equals: id
9
10
  }
10
11
  };
12
+ const fields = buildVersionCollectionFields(this.payload.config, this.payload.collections[collection].config);
11
13
  const options = {
14
+ ...optionsArgs,
12
15
  ...await withSession(this, req),
13
16
  lean: true,
14
- new: true
17
+ new: true,
18
+ projection: buildProjectionFromSelect({
19
+ adapter: this,
20
+ fields,
21
+ select
22
+ })
15
23
  };
16
24
  const query = await VersionModel.buildQuery({
17
25
  locale,
@@ -21,7 +29,7 @@ export const updateVersion = async function updateVersion({ id, collection, loca
21
29
  const sanitizedData = sanitizeRelationshipIDs({
22
30
  config: this.payload.config,
23
31
  data: versionData,
24
- fields: buildVersionCollectionFields(this.payload.config, this.payload.collections[collection].config)
32
+ fields
25
33
  });
26
34
  const doc = await VersionModel.findOneAndUpdate(query, sanitizedData, options);
27
35
  const result = JSON.parse(JSON.stringify(doc));
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/updateVersion.ts"],"sourcesContent":["import { buildVersionCollectionFields, type PayloadRequest, type UpdateVersion } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.js'\nimport { withSession } from './withSession.js'\n\nexport const updateVersion: UpdateVersion = async function updateVersion(\n this: MongooseAdapter,\n { id, collection, locale, req = {} as PayloadRequest, versionData, where },\n) {\n const VersionModel = this.versions[collection]\n const whereToUse = where || { id: { equals: id } }\n const options = {\n ...(await withSession(this, req)),\n lean: true,\n new: true,\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: buildVersionCollectionFields(\n this.payload.config,\n this.payload.collections[collection].config,\n ),\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","sanitizeRelationshipIDs","withSession","updateVersion","id","collection","locale","req","versionData","where","VersionModel","versions","whereToUse","equals","options","lean","new","query","buildQuery","payload","sanitizedData","config","data","fields","collections","doc","findOneAndUpdate","result","JSON","parse","stringify","verificationToken","_verificationToken","_id"],"mappings":"AAAA,SAASA,4BAA4B,QAAiD,UAAS;AAI/F,SAASC,uBAAuB,QAAQ,yCAAwC;AAChF,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,gBAA+B,eAAeA,cAEzD,EAAEC,EAAE,EAAEC,UAAU,EAAEC,MAAM,EAAEC,MAAM,CAAC,CAAmB,EAAEC,WAAW,EAAEC,KAAK,EAAE;IAE1E,MAAMC,eAAe,IAAI,CAACC,QAAQ,CAACN,WAAW;IAC9C,MAAMO,aAAaH,SAAS;QAAEL,IAAI;YAAES,QAAQT;QAAG;IAAE;IACjD,MAAMU,UAAU;QACd,GAAI,MAAMZ,YAAY,IAAI,EAAEK,IAAI;QAChCQ,MAAM;QACNC,KAAK;IACP;IAEA,MAAMC,QAAQ,MAAMP,aAAaQ,UAAU,CAAC;QAC1CZ;QACAa,SAAS,IAAI,CAACA,OAAO;QACrBV,OAAOG;IACT;IAEA,MAAMQ,gBAAgBnB,wBAAwB;QAC5CoB,QAAQ,IAAI,CAACF,OAAO,CAACE,MAAM;QAC3BC,MAAMd;QACNe,QAAQvB,6BACN,IAAI,CAACmB,OAAO,CAACE,MAAM,EACnB,IAAI,CAACF,OAAO,CAACK,WAAW,CAACnB,WAAW,CAACgB,MAAM;IAE/C;IAEA,MAAMI,MAAM,MAAMf,aAAagB,gBAAgB,CAACT,OAAOG,eAAeN;IAEtE,MAAMa,SAASC,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACL;IAEzC,MAAMM,oBAAoBN,IAAIO,kBAAkB;IAEhD,uBAAuB;IACvBL,OAAOvB,EAAE,GAAGuB,OAAOM,GAAG;IACtB,IAAIF,mBAAmB;QACrBJ,OAAOK,kBAAkB,GAAGD;IAC9B;IACA,OAAOJ;AACT,EAAC"}
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({ adapter: this, fields, select }),\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,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CHANGED
@@ -1,4 +1,4 @@
1
- export const upsert = async function upsert({ collection, data, locale, req = {}, where }) {
1
+ export const upsert = async function upsert({ collection, data, locale, req = {}, select, where }) {
2
2
  return this.updateOne({
3
3
  collection,
4
4
  data,
@@ -7,6 +7,7 @@ export const upsert = async function upsert({ collection, data, locale, req = {}
7
7
  upsert: true
8
8
  },
9
9
  req,
10
+ select,
10
11
  where
11
12
  });
12
13
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/upsert.ts"],"sourcesContent":["import type { PayloadRequest, Upsert } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nexport const upsert: Upsert = async function upsert(\n this: MongooseAdapter,\n { collection, data, locale, req = {} as PayloadRequest, where },\n) {\n return this.updateOne({ collection, data, locale, options: { upsert: true }, req, where })\n}\n"],"names":["upsert","collection","data","locale","req","where","updateOne","options"],"mappings":"AAIA,OAAO,MAAMA,SAAiB,eAAeA,OAE3C,EAAEC,UAAU,EAAEC,IAAI,EAAEC,MAAM,EAAEC,MAAM,CAAC,CAAmB,EAAEC,KAAK,EAAE;IAE/D,OAAO,IAAI,CAACC,SAAS,CAAC;QAAEL;QAAYC;QAAMC;QAAQI,SAAS;YAAEP,QAAQ;QAAK;QAAGI;QAAKC;IAAM;AAC1F,EAAC"}
1
+ {"version":3,"sources":["../src/upsert.ts"],"sourcesContent":["import type { PayloadRequest, Upsert } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nexport const upsert: Upsert = async function upsert(\n this: MongooseAdapter,\n { collection, data, locale, req = {} as PayloadRequest, select, where },\n) {\n return this.updateOne({ collection, data, locale, options: { upsert: true }, req, select, where })\n}\n"],"names":["upsert","collection","data","locale","req","select","where","updateOne","options"],"mappings":"AAIA,OAAO,MAAMA,SAAiB,eAAeA,OAE3C,EAAEC,UAAU,EAAEC,IAAI,EAAEC,MAAM,EAAEC,MAAM,CAAC,CAAmB,EAAEC,MAAM,EAAEC,KAAK,EAAE;IAEvE,OAAO,IAAI,CAACC,SAAS,CAAC;QAAEN;QAAYC;QAAMC;QAAQK,SAAS;YAAER,QAAQ;QAAK;QAAGI;QAAKC;QAAQC;IAAM;AAClG,EAAC"}
@@ -8,8 +8,11 @@ type BuildJoinAggregationArgs = {
8
8
  joins: JoinQuery;
9
9
  limit?: number;
10
10
  locale: string;
11
+ projection?: Record<string, true>;
11
12
  query?: Where;
13
+ /** whether the query is from drafts */
14
+ versions?: boolean;
12
15
  };
13
- export declare const buildJoinAggregation: ({ adapter, collection, collectionConfig, joins, limit, locale, query, }: BuildJoinAggregationArgs) => Promise<PipelineStage[] | undefined>;
16
+ export declare const buildJoinAggregation: ({ adapter, collection, collectionConfig, joins, limit, locale, projection, query, versions, }: BuildJoinAggregationArgs) => Promise<PipelineStage[] | undefined>;
14
17
  export {};
15
18
  //# sourceMappingURL=buildJoinAggregation.d.ts.map
@@ -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,EAAE,cAAc,EAAE,SAAS,EAAE,yBAAyB,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAE1F,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAIlD,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;IAEd,KAAK,CAAC,EAAE,KAAK,CAAA;CACd,CAAA;AAED,eAAO,MAAM,oBAAoB,4EAQ9B,wBAAwB,KAAG,OAAO,CAAC,aAAa,EAAE,GAAG,SAAS,CAmJhE,CAAA"}
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,EAAE,cAAc,EAAE,SAAS,EAAE,yBAAyB,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAE1F,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAIlD,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,CA+JhE,CAAA"}
@@ -1,5 +1,5 @@
1
1
  import { buildSortParam } from '../queries/buildSortParam.js';
2
- export const buildJoinAggregation = async ({ adapter, collection, collectionConfig, joins, limit, locale, query })=>{
2
+ export const buildJoinAggregation = async ({ adapter, collection, collectionConfig, joins, limit, locale, projection, query, versions })=>{
3
3
  if (Object.keys(collectionConfig.joins).length === 0 || joins === false) {
4
4
  return;
5
5
  }
@@ -24,12 +24,18 @@ export const buildJoinAggregation = async ({ adapter, collection, collectionConf
24
24
  for (const slug of Object.keys(joinConfig)){
25
25
  for (const join of joinConfig[slug]){
26
26
  const joinModel = adapter.collections[join.field.collection];
27
- const { limit: limitJoin = 10, sort: sortJoin, where: whereJoin } = joins?.[join.schemaPath] || {};
27
+ if (projection && !projection[join.joinPath]) {
28
+ continue;
29
+ }
30
+ if (joins?.[join.joinPath] === false) {
31
+ continue;
32
+ }
33
+ const { limit: limitJoin = join.field.defaultLimit ?? 10, sort: sortJoin = join.field.defaultSort || collectionConfig.defaultSort, where: whereJoin } = joins?.[join.joinPath] || {};
28
34
  const sort = buildSortParam({
29
35
  config: adapter.payload.config,
30
36
  fields: adapter.payload.collections[slug].config.fields,
31
37
  locale,
32
- sort: sortJoin || collectionConfig.defaultSort,
38
+ sort: sortJoin,
33
39
  timestamps: true
34
40
  });
35
41
  const sortProperty = Object.keys(sort)[0];
@@ -56,13 +62,13 @@ export const buildJoinAggregation = async ({ adapter, collection, collectionConf
56
62
  }
57
63
  if (adapter.payload.config.localization && locale === 'all') {
58
64
  adapter.payload.config.localization.localeCodes.forEach((code)=>{
59
- const as = `${join.schemaPath}${code}`;
65
+ const as = `${versions ? `version.${join.joinPath}` : join.joinPath}${code}`;
60
66
  aggregate.push({
61
67
  $lookup: {
62
68
  as: `${as}.docs`,
63
69
  foreignField: `${join.field.on}${code}`,
64
- from: slug,
65
- localField: '_id',
70
+ from: adapter.collections[slug].collection.name,
71
+ localField: versions ? 'parent' : '_id',
66
72
  pipeline
67
73
  }
68
74
  }, {
@@ -99,13 +105,13 @@ export const buildJoinAggregation = async ({ adapter, collection, collectionConf
99
105
  });
100
106
  } else {
101
107
  const localeSuffix = join.field.localized && adapter.payload.config.localization && locale ? `.${locale}` : '';
102
- const as = `${join.schemaPath}${localeSuffix}`;
108
+ const as = `${versions ? `version.${join.joinPath}` : join.joinPath}${localeSuffix}`;
103
109
  aggregate.push({
104
110
  $lookup: {
105
111
  as: `${as}.docs`,
106
112
  foreignField: `${join.field.on}${localeSuffix}`,
107
- from: slug,
108
- localField: '_id',
113
+ from: adapter.collections[slug].collection.name,
114
+ localField: versions ? 'parent' : '_id',
109
115
  pipeline
110
116
  }
111
117
  }, {
@@ -142,6 +148,11 @@ export const buildJoinAggregation = async ({ adapter, collection, collectionConf
142
148
  }
143
149
  }
144
150
  }
151
+ if (projection) {
152
+ aggregate.push({
153
+ $project: projection
154
+ });
155
+ }
145
156
  return aggregate;
146
157
  };
147
158
 
@@ -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 // the where clause for the top collection\n query?: Where\n}\n\nexport const buildJoinAggregation = async ({\n adapter,\n collection,\n collectionConfig,\n joins,\n limit,\n locale,\n query,\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 const {\n limit: limitJoin = 10,\n sort: sortJoin,\n where: whereJoin,\n } = joins?.[join.schemaPath] || {}\n\n const sort = buildSortParam({\n config: adapter.payload.config,\n fields: adapter.payload.collections[slug].config.fields,\n locale,\n sort: sortJoin || collectionConfig.defaultSort,\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 = `${join.schemaPath}${code}`\n\n aggregate.push(\n {\n $lookup: {\n as: `${as}.docs`,\n foreignField: `${join.field.on}${code}`,\n from: slug,\n localField: '_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 = `${join.schemaPath}${localeSuffix}`\n\n aggregate.push(\n {\n $lookup: {\n as: `${as}.docs`,\n foreignField: `${join.field.on}${localeSuffix}`,\n from: slug,\n localField: '_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 return aggregate\n}\n"],"names":["buildSortParam","buildJoinAggregation","adapter","collection","collectionConfig","joins","limit","locale","query","Object","keys","length","joinConfig","payload","collections","config","aggregate","$sort","createdAt","push","$match","$limit","slug","join","joinModel","field","limitJoin","sort","sortJoin","where","whereJoin","schemaPath","fields","defaultSort","timestamps","sortProperty","sortDirection","buildQuery","pipeline","localization","localeCodes","forEach","code","as","$lookup","foreignField","on","from","localField","$addFields","$map","in","input","$gt","$size","$slice","localeSuffix","localized","Number","MAX_VALUE"],"mappings":"AAKA,SAASA,cAAc,QAAQ,+BAA8B;AAc7D,OAAO,MAAMC,uBAAuB,OAAO,EACzCC,OAAO,EACPC,UAAU,EACVC,gBAAgB,EAChBC,KAAK,EACLC,KAAK,EACLC,MAAM,EACNC,KAAK,EACoB;IACzB,IAAIC,OAAOC,IAAI,CAACN,iBAAiBC,KAAK,EAAEM,MAAM,KAAK,KAAKN,UAAU,OAAO;QACvE;IACF;IAEA,MAAMO,aAAaV,QAAQW,OAAO,CAACC,WAAW,CAACX,WAAW,CAACY,MAAM,CAACV,KAAK;IACvE,MAAMW,YAA6B;QACjC;YACEC,OAAO;gBAAEC,WAAW,CAAC;YAAE;QACzB;KACD;IAED,IAAIV,OAAO;QACTQ,UAAUG,IAAI,CAAC;YACbC,QAAQZ;QACV;IACF;IAEA,IAAIF,OAAO;QACTU,UAAUG,IAAI,CAAC;YACbE,QAAQf;QACV;IACF;IAEA,KAAK,MAAMgB,QAAQb,OAAOC,IAAI,CAACE,YAAa;QAC1C,KAAK,MAAMW,QAAQX,UAAU,CAACU,KAAK,CAAE;YACnC,MAAME,YAAYtB,QAAQY,WAAW,CAACS,KAAKE,KAAK,CAACtB,UAAU,CAAC;YAE5D,MAAM,EACJG,OAAOoB,YAAY,EAAE,EACrBC,MAAMC,QAAQ,EACdC,OAAOC,SAAS,EACjB,GAAGzB,OAAO,CAACkB,KAAKQ,UAAU,CAAC,IAAI,CAAC;YAEjC,MAAMJ,OAAO3B,eAAe;gBAC1Be,QAAQb,QAAQW,OAAO,CAACE,MAAM;gBAC9BiB,QAAQ9B,QAAQW,OAAO,CAACC,WAAW,CAACQ,KAAK,CAACP,MAAM,CAACiB,MAAM;gBACvDzB;gBACAoB,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CAAC,CAAC,EAAE;gCACdY,QAAQ;oCAAC,CAAC,CAAC,EAAEZ,GAAG,KAAK,CAAC;oCAAEjB;iCAAU;4BACpC;wBACF;oBACF;gBACF;YACF;QACF;IACF;IAEA,OAAOV;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.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,+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,QAAQjB;QACV;IACF;IAEA,KAAK,MAAMkB,QAAQb,OAAOC,IAAI,CAACE,YAAa;QAC1C,KAAK,MAAMW,QAAQX,UAAU,CAACU,KAAK,CAAE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C,QAAQ,EAAEe,KAAKG,QAAQ,CAAC,CAAC,GAAGH,KAAKG,QAAQ,CAAC,EAAEgC,aAAa,CAAC;gBAEpF1C,UAAUG,IAAI,CACZ;oBACE0B,SAAS;wBACPD,IAAI,CAAC,EAAEA,GAAG,KAAK,CAAC;wBAChBE,cAAc,CAAC,EAAEvB,KAAKE,KAAK,CAACsB,EAAE,CAAC,EAAEW,aAAa,CAAC;wBAC/CV,MAAMhD,QAAQc,WAAW,CAACQ,KAAK,CAACrB,UAAU,CAACgD,IAAI;wBAC/CC,YAAY1C,WAAW,WAAW;wBAClC+B;oBACF;gBACF,GACA;oBACEY,YAAY;wBACV,CAAC,CAAC,EAAEP,GAAG,KAAK,CAAC,CAAC,EAAE;4BACdQ,MAAM;gCACJR,IAAI;gCACJS,IAAI;gCACJC,OAAO,CAAC,CAAC,EAAEV,GAAG,KAAK,CAAC;4BACtB;wBACF;wBACA,CAAC,CAAC,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"}
@@ -0,0 +1,8 @@
1
+ import { type Field, type SelectType } from 'payload';
2
+ import type { MongooseAdapter } from '../index.js';
3
+ export declare const buildProjectionFromSelect: ({ adapter, fields, select, }: {
4
+ adapter: MongooseAdapter;
5
+ fields: Field[];
6
+ select?: SelectType;
7
+ }) => Record<string, true> | undefined;
8
+ //# sourceMappingURL=buildProjectionFromSelect.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"buildProjectionFromSelect.d.ts","sourceRoot":"","sources":["../../src/utilities/buildProjectionFromSelect.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,KAAK,EAGV,KAAK,UAAU,EAEhB,MAAM,SAAS,CAAA;AAGhB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AA4MlD,eAAO,MAAM,yBAAyB,iCAInC;IACD,OAAO,EAAE,eAAe,CAAA;IACxB,MAAM,EAAE,KAAK,EAAE,CAAA;IACf,MAAM,CAAC,EAAE,UAAU,CAAA;CACpB,KAAG,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,SAmB1B,CAAA"}
@@ -0,0 +1,171 @@
1
+ import { deepCopyObjectSimple } from 'payload';
2
+ import { fieldAffectsData, getSelectMode, tabHasName } from 'payload/shared';
3
+ const addFieldToProjection = ({ adapter, databaseSchemaPath, field, projection, withinLocalizedField })=>{
4
+ const { config } = adapter.payload;
5
+ if (withinLocalizedField && config.localization) {
6
+ for (const locale of config.localization.localeCodes){
7
+ const localeDatabaseSchemaPath = databaseSchemaPath.replace('<locale>', locale);
8
+ projection[`${localeDatabaseSchemaPath}${field.name}`] = true;
9
+ }
10
+ } else {
11
+ projection[`${databaseSchemaPath}${field.name}`] = true;
12
+ }
13
+ };
14
+ const traverseFields = ({ adapter, databaseSchemaPath = '', fields, projection, select, selectAllOnCurrentLevel = false, selectMode, withinLocalizedField = false })=>{
15
+ for (const field of fields){
16
+ if (fieldAffectsData(field)) {
17
+ if (selectMode === 'include') {
18
+ if (select[field.name] === true || selectAllOnCurrentLevel) {
19
+ addFieldToProjection({
20
+ adapter,
21
+ databaseSchemaPath,
22
+ field,
23
+ projection,
24
+ withinLocalizedField
25
+ });
26
+ continue;
27
+ }
28
+ if (!select[field.name]) {
29
+ continue;
30
+ }
31
+ }
32
+ if (selectMode === 'exclude') {
33
+ if (typeof select[field.name] === 'undefined') {
34
+ addFieldToProjection({
35
+ adapter,
36
+ databaseSchemaPath,
37
+ field,
38
+ projection,
39
+ withinLocalizedField
40
+ });
41
+ continue;
42
+ }
43
+ if (select[field.name] === false) {
44
+ continue;
45
+ }
46
+ }
47
+ }
48
+ let fieldDatabaseSchemaPath = databaseSchemaPath;
49
+ let fieldWithinLocalizedField = withinLocalizedField;
50
+ if (fieldAffectsData(field)) {
51
+ fieldDatabaseSchemaPath = `${databaseSchemaPath}${field.name}.`;
52
+ if (field.localized) {
53
+ fieldDatabaseSchemaPath = `${fieldDatabaseSchemaPath}<locale>.`;
54
+ fieldWithinLocalizedField = true;
55
+ }
56
+ }
57
+ switch(field.type){
58
+ case 'array':
59
+ case 'group':
60
+ case 'tab':
61
+ {
62
+ let fieldSelect;
63
+ if (field.type === 'tab' && !tabHasName(field)) {
64
+ fieldSelect = select;
65
+ } else {
66
+ fieldSelect = select[field.name];
67
+ }
68
+ if (field.type === 'array' && selectMode === 'include') {
69
+ fieldSelect['id'] = true;
70
+ }
71
+ traverseFields({
72
+ adapter,
73
+ databaseSchemaPath: fieldDatabaseSchemaPath,
74
+ fields: field.fields,
75
+ projection,
76
+ select: fieldSelect,
77
+ selectMode,
78
+ withinLocalizedField: fieldWithinLocalizedField
79
+ });
80
+ break;
81
+ }
82
+ case 'blocks':
83
+ {
84
+ const blocksSelect = select[field.name];
85
+ for (const block of field.blocks){
86
+ if (selectMode === 'include' && blocksSelect[block.slug] === true || selectMode === 'exclude' && typeof blocksSelect[block.slug] === 'undefined') {
87
+ traverseFields({
88
+ adapter,
89
+ databaseSchemaPath: fieldDatabaseSchemaPath,
90
+ fields: block.fields,
91
+ projection,
92
+ select: {},
93
+ selectAllOnCurrentLevel: true,
94
+ selectMode: 'include',
95
+ withinLocalizedField: fieldWithinLocalizedField
96
+ });
97
+ continue;
98
+ }
99
+ let blockSelectMode = selectMode;
100
+ if (selectMode === 'exclude' && blocksSelect[block.slug] === false) {
101
+ blockSelectMode = 'include';
102
+ }
103
+ if (typeof blocksSelect[block.slug] !== 'object') {
104
+ blocksSelect[block.slug] = {};
105
+ }
106
+ if (blockSelectMode === 'include') {
107
+ blocksSelect[block.slug]['id'] = true;
108
+ blocksSelect[block.slug]['blockType'] = true;
109
+ }
110
+ traverseFields({
111
+ adapter,
112
+ databaseSchemaPath: fieldDatabaseSchemaPath,
113
+ fields: block.fields,
114
+ projection,
115
+ select: blocksSelect[block.slug],
116
+ selectMode: blockSelectMode,
117
+ withinLocalizedField: fieldWithinLocalizedField
118
+ });
119
+ }
120
+ break;
121
+ }
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
+ default:
149
+ break;
150
+ }
151
+ }
152
+ };
153
+ export const buildProjectionFromSelect = ({ adapter, fields, select })=>{
154
+ if (!select) {
155
+ return;
156
+ }
157
+ const projection = {
158
+ _id: true
159
+ };
160
+ traverseFields({
161
+ adapter,
162
+ fields,
163
+ projection,
164
+ // Clone to safely mutate it later
165
+ select: deepCopyObjectSimple(select),
166
+ selectMode: getSelectMode(select)
167
+ });
168
+ return projection;
169
+ };
170
+
171
+ //# sourceMappingURL=buildProjectionFromSelect.js.map
@@ -0,0 +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","buildProjectionFromSelect","_id"],"mappings":"AAAA,SACEA,oBAAoB,QAMf,UAAS;AAChB,SAASC,gBAAgB,EAAEC,aAAa,EAAEC,UAAU,QAAQ,iBAAgB;AAI5E,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,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Y,MAAM;oBACpBX;oBACAY;oBACAE;oBACAb;gBACF;gBACA;YAEF,KAAK;gBACHS,eAAe;oBACbb;oBACAC;oBACAa,QAAQZ,MAAM0B,IAAI,CAACC,GAAG,CAAC,CAACC,MAAS,CAAA;4BAAE,GAAGA,GAAG;4BAAET,MAAM;wBAAM,CAAA;oBACvDlB;oBACAY;oBACAE;oBACAb;gBACF;gBACA;YAEF;gBACE;QACJ;IACF;AACF;AAEA,OAAO,MAAM2B,4BAA4B,CAAC,EACxC/B,OAAO,EACPc,MAAM,EACNC,MAAM,EAKP;IACC,IAAI,CAACA,QAAQ;QACX;IACF;IAEA,MAAMZ,aAAmC;QACvC6B,KAAK;IACP;IAEAnB,eAAe;QACbb;QACAc;QACAX;QACA,kCAAkC;QAClCY,QAAQpB,qBAAqBoB;QAC7BE,YAAYpB,cAAckB;IAC5B;IAEA,OAAOZ;AACT,EAAC"}
@@ -7,8 +7,8 @@ export const handleError = ({ collection, error, global, req })=>{
7
7
  collection,
8
8
  errors: [
9
9
  {
10
- field: Object.keys(error.keyValue)[0],
11
- message: req.t('error:valueMustBeUnique')
10
+ message: req.t('error:valueMustBeUnique'),
11
+ path: Object.keys(error.keyValue)[0]
12
12
  }
13
13
  ],
14
14
  global