@payloadcms/db-mongodb 3.0.0-canary.e14c80d → 3.0.0-canary.e1fc0e0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (116) hide show
  1. package/dist/connect.d.ts.map +1 -1
  2. package/dist/connect.js +7 -3
  3. package/dist/connect.js.map +1 -1
  4. package/dist/create.d.ts.map +1 -1
  5. package/dist/create.js +7 -1
  6. package/dist/create.js.map +1 -1
  7. package/dist/createGlobal.d.ts.map +1 -1
  8. package/dist/createGlobal.js +10 -5
  9. package/dist/createGlobal.js.map +1 -1
  10. package/dist/createGlobalVersion.d.ts +1 -1
  11. package/dist/createGlobalVersion.d.ts.map +1 -1
  12. package/dist/createGlobalVersion.js +13 -4
  13. package/dist/createGlobalVersion.js.map +1 -1
  14. package/dist/createMigration.js +3 -3
  15. package/dist/createMigration.js.map +1 -1
  16. package/dist/createVersion.d.ts +1 -1
  17. package/dist/createVersion.d.ts.map +1 -1
  18. package/dist/createVersion.js +31 -9
  19. package/dist/createVersion.js.map +1 -1
  20. package/dist/deleteOne.js +1 -1
  21. package/dist/deleteOne.js.map +1 -1
  22. package/dist/find.d.ts.map +1 -1
  23. package/dist/find.js +20 -3
  24. package/dist/find.js.map +1 -1
  25. package/dist/findGlobal.js +1 -1
  26. package/dist/findGlobal.js.map +1 -1
  27. package/dist/findGlobalVersions.d.ts.map +1 -1
  28. package/dist/findGlobalVersions.js +2 -2
  29. package/dist/findGlobalVersions.js.map +1 -1
  30. package/dist/findOne.d.ts.map +1 -1
  31. package/dist/findOne.js +19 -3
  32. package/dist/findOne.js.map +1 -1
  33. package/dist/findVersions.js +1 -1
  34. package/dist/findVersions.js.map +1 -1
  35. package/dist/index.d.ts +6 -3
  36. package/dist/index.d.ts.map +1 -1
  37. package/dist/index.js +10 -5
  38. package/dist/index.js.map +1 -1
  39. package/dist/init.d.ts.map +1 -1
  40. package/dist/init.js +9 -6
  41. package/dist/init.js.map +1 -1
  42. package/dist/models/buildCollectionSchema.d.ts +1 -2
  43. package/dist/models/buildCollectionSchema.d.ts.map +1 -1
  44. package/dist/models/buildCollectionSchema.js +7 -4
  45. package/dist/models/buildCollectionSchema.js.map +1 -1
  46. package/dist/models/buildGlobalModel.js +2 -2
  47. package/dist/models/buildGlobalModel.js.map +1 -1
  48. package/dist/models/buildSchema.d.ts +1 -2
  49. package/dist/models/buildSchema.d.ts.map +1 -1
  50. package/dist/models/buildSchema.js +100 -11
  51. package/dist/models/buildSchema.js.map +1 -1
  52. package/dist/queries/buildQuery.d.ts +2 -2
  53. package/dist/queries/buildQuery.d.ts.map +1 -1
  54. package/dist/queries/buildQuery.js +1 -2
  55. package/dist/queries/buildQuery.js.map +1 -1
  56. package/dist/queries/buildSearchParams.d.ts.map +1 -1
  57. package/dist/queries/buildSearchParams.js +19 -11
  58. package/dist/queries/buildSearchParams.js.map +1 -1
  59. package/dist/queries/getLocalizedSortProperty.spec.js +1 -1
  60. package/dist/queries/getLocalizedSortProperty.spec.js.map +1 -1
  61. package/dist/queries/parseParams.d.ts.map +1 -1
  62. package/dist/queries/parseParams.js +3 -1
  63. package/dist/queries/parseParams.js.map +1 -1
  64. package/dist/queries/sanitizeQueryValue.d.ts.map +1 -1
  65. package/dist/queries/sanitizeQueryValue.js +142 -26
  66. package/dist/queries/sanitizeQueryValue.js.map +1 -1
  67. package/dist/queryDrafts.d.ts.map +1 -1
  68. package/dist/queryDrafts.js +21 -6
  69. package/dist/queryDrafts.js.map +1 -1
  70. package/dist/transactions/beginTransaction.d.ts.map +1 -1
  71. package/dist/transactions/beginTransaction.js +2 -0
  72. package/dist/transactions/beginTransaction.js.map +1 -1
  73. package/dist/transactions/commitTransaction.d.ts.map +1 -1
  74. package/dist/transactions/commitTransaction.js +3 -1
  75. package/dist/transactions/commitTransaction.js.map +1 -1
  76. package/dist/types.d.ts +7 -4
  77. package/dist/types.d.ts.map +1 -1
  78. package/dist/types.js.map +1 -1
  79. package/dist/updateGlobal.d.ts.map +1 -1
  80. package/dist/updateGlobal.js +8 -2
  81. package/dist/updateGlobal.js.map +1 -1
  82. package/dist/updateGlobalVersion.d.ts +2 -2
  83. package/dist/updateGlobalVersion.d.ts.map +1 -1
  84. package/dist/updateGlobalVersion.js +10 -3
  85. package/dist/updateGlobalVersion.js.map +1 -1
  86. package/dist/updateOne.d.ts.map +1 -1
  87. package/dist/updateOne.js +10 -3
  88. package/dist/updateOne.js.map +1 -1
  89. package/dist/updateVersion.d.ts +1 -1
  90. package/dist/updateVersion.d.ts.map +1 -1
  91. package/dist/updateVersion.js +8 -1
  92. package/dist/updateVersion.js.map +1 -1
  93. package/dist/upsert.d.ts +3 -0
  94. package/dist/upsert.d.ts.map +1 -0
  95. package/dist/upsert.js +14 -0
  96. package/dist/upsert.js.map +1 -0
  97. package/dist/utilities/buildJoinAggregation.d.ts +17 -0
  98. package/dist/utilities/buildJoinAggregation.d.ts.map +1 -0
  99. package/dist/utilities/buildJoinAggregation.js +148 -0
  100. package/dist/utilities/buildJoinAggregation.js.map +1 -0
  101. package/dist/utilities/getDBName.d.ts.map +1 -1
  102. package/dist/utilities/getDBName.js +3 -1
  103. package/dist/utilities/getDBName.js.map +1 -1
  104. package/dist/utilities/sanitizeInternalFields.d.ts +1 -2
  105. package/dist/utilities/sanitizeInternalFields.d.ts.map +1 -1
  106. package/dist/utilities/sanitizeInternalFields.js +1 -2
  107. package/dist/utilities/sanitizeInternalFields.js.map +1 -1
  108. package/dist/utilities/sanitizeRelationshipIDs.d.ts +9 -0
  109. package/dist/utilities/sanitizeRelationshipIDs.d.ts.map +1 -0
  110. package/dist/utilities/sanitizeRelationshipIDs.js +115 -0
  111. package/dist/utilities/sanitizeRelationshipIDs.js.map +1 -0
  112. package/dist/withSession.d.ts +1 -1
  113. package/dist/withSession.d.ts.map +1 -1
  114. package/dist/withSession.js +5 -3
  115. package/dist/withSession.js.map +1 -1
  116. package/package.json +9 -6
@@ -1 +1 @@
1
- {"version":3,"file":"updateOne.d.ts","sourceRoot":"","sources":["../src/updateOne.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAkB,SAAS,EAAE,MAAM,SAAS,CAAA;AAQxD,eAAO,MAAM,SAAS,EAAE,SA+BvB,CAAA"}
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"}
package/dist/updateOne.js CHANGED
@@ -1,7 +1,8 @@
1
1
  import { handleError } from './utilities/handleError.js';
2
- import sanitizeInternalFields from './utilities/sanitizeInternalFields.js';
2
+ import { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js';
3
+ import { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.js';
3
4
  import { withSession } from './withSession.js';
4
- export const updateOne = async function updateOne({ id, collection, data, locale, req = {}, where: whereArg }) {
5
+ export const updateOne = async function updateOne({ id, collection, data, locale, options: optionsArgs = {}, req = {}, where: whereArg }) {
5
6
  const where = id ? {
6
7
  id: {
7
8
  equals: id
@@ -9,6 +10,7 @@ export const updateOne = async function updateOne({ id, collection, data, locale
9
10
  } : whereArg;
10
11
  const Model = this.collections[collection];
11
12
  const options = {
13
+ ...optionsArgs,
12
14
  ...await withSession(this, req),
13
15
  lean: true,
14
16
  new: true
@@ -19,8 +21,13 @@ export const updateOne = async function updateOne({ id, collection, data, locale
19
21
  where
20
22
  });
21
23
  let result;
24
+ const sanitizedData = sanitizeRelationshipIDs({
25
+ config: this.payload.config,
26
+ data,
27
+ fields: this.payload.collections[collection].config.fields
28
+ });
22
29
  try {
23
- result = await Model.findOneAndUpdate(query, data, options);
30
+ result = await Model.findOneAndUpdate(query, sanitizedData, options);
24
31
  } catch (error) {
25
32
  handleError({
26
33
  collection,
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/updateOne.ts"],"sourcesContent":["import 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 { withSession } from './withSession.js'\n\nexport const updateOne: UpdateOne = async function updateOne(\n this: MongooseAdapter,\n { id, collection, data, locale, req = {} as PayloadRequest, where: whereArg },\n) {\n const where = id ? { id: { equals: id } } : whereArg\n const Model = this.collections[collection]\n const options = {\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 try {\n result = await Model.findOneAndUpdate(query, data, 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","withSession","updateOne","id","collection","data","locale","req","where","whereArg","equals","Model","collections","options","lean","new","query","buildQuery","payload","result","findOneAndUpdate","error","JSON","parse","stringify","_id"],"mappings":"AAIA,SAASA,WAAW,QAAQ,6BAA4B;AACxD,OAAOC,4BAA4B,wCAAuC;AAC1E,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,YAAuB,eAAeA,UAEjD,EAAEC,EAAE,EAAEC,UAAU,EAAEC,IAAI,EAAEC,MAAM,EAAEC,MAAM,CAAC,CAAmB,EAAEC,OAAOC,QAAQ,EAAE;IAE7E,MAAMD,QAAQL,KAAK;QAAEA,IAAI;YAAEO,QAAQP;QAAG;IAAE,IAAIM;IAC5C,MAAME,QAAQ,IAAI,CAACC,WAAW,CAACR,WAAW;IAC1C,MAAMS,UAAU;QACd,GAAI,MAAMZ,YAAY,IAAI,EAAEM,IAAI;QAChCO,MAAM;QACNC,KAAK;IACP;IAEA,MAAMC,QAAQ,MAAML,MAAMM,UAAU,CAAC;QACnCX;QACAY,SAAS,IAAI,CAACA,OAAO;QACrBV;IACF;IAEA,IAAIW;IAEJ,IAAI;QACFA,SAAS,MAAMR,MAAMS,gBAAgB,CAACJ,OAAOX,MAAMQ;IACrD,EAAE,OAAOQ,OAAO;QACdtB,YAAY;YAAEK;YAAYiB;YAAOd;QAAI;IACvC;IAEAY,SAASG,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACL;IACnCA,OAAOhB,EAAE,GAAGgB,OAAOM,GAAG;IACtBN,SAASnB,uBAAuBmB;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 { 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,3 +1,3 @@
1
- import type { UpdateVersion } from 'payload';
1
+ import { type UpdateVersion } from 'payload';
2
2
  export declare const updateVersion: UpdateVersion;
3
3
  //# sourceMappingURL=updateVersion.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"updateVersion.d.ts","sourceRoot":"","sources":["../src/updateVersion.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAkB,aAAa,EAAE,MAAM,SAAS,CAAA;AAM5D,eAAO,MAAM,aAAa,EAAE,aA8B3B,CAAA"}
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,3 +1,5 @@
1
+ import { buildVersionCollectionFields } from 'payload';
2
+ import { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.js';
1
3
  import { withSession } from './withSession.js';
2
4
  export const updateVersion = async function updateVersion({ id, collection, locale, req = {}, versionData, where }) {
3
5
  const VersionModel = this.versions[collection];
@@ -16,7 +18,12 @@ export const updateVersion = async function updateVersion({ id, collection, loca
16
18
  payload: this.payload,
17
19
  where: whereToUse
18
20
  });
19
- const doc = await VersionModel.findOneAndUpdate(query, versionData, options);
21
+ const sanitizedData = sanitizeRelationshipIDs({
22
+ config: this.payload.config,
23
+ data: versionData,
24
+ fields: buildVersionCollectionFields(this.payload.config, this.payload.collections[collection].config)
25
+ });
26
+ const doc = await VersionModel.findOneAndUpdate(query, sanitizedData, options);
20
27
  const result = JSON.parse(JSON.stringify(doc));
21
28
  const verificationToken = doc._verificationToken;
22
29
  // custom id type reset
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/updateVersion.ts"],"sourcesContent":["import type { PayloadRequest, UpdateVersion } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\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 doc = await VersionModel.findOneAndUpdate(query, versionData, 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":["withSession","updateVersion","id","collection","locale","req","versionData","where","VersionModel","versions","whereToUse","equals","options","lean","new","query","buildQuery","payload","doc","findOneAndUpdate","result","JSON","parse","stringify","verificationToken","_verificationToken","_id"],"mappings":"AAIA,SAASA,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,MAAM,MAAMV,aAAaW,gBAAgB,CAACJ,OAAOT,aAAaM;IAEpE,MAAMQ,SAASC,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACL;IAEzC,MAAMM,oBAAoBN,IAAIO,kBAAkB;IAEhD,uBAAuB;IACvBL,OAAOlB,EAAE,GAAGkB,OAAOM,GAAG;IACtB,IAAIF,mBAAmB;QACrBJ,OAAOK,kBAAkB,GAAGD;IAC9B;IACA,OAAOJ;AACT,EAAC"}
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"}
@@ -0,0 +1,3 @@
1
+ import type { Upsert } from 'payload';
2
+ export declare const upsert: Upsert;
3
+ //# sourceMappingURL=upsert.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"upsert.d.ts","sourceRoot":"","sources":["../src/upsert.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAkB,MAAM,EAAE,MAAM,SAAS,CAAA;AAIrD,eAAO,MAAM,MAAM,EAAE,MAKpB,CAAA"}
package/dist/upsert.js ADDED
@@ -0,0 +1,14 @@
1
+ export const upsert = async function upsert({ collection, data, locale, req = {}, where }) {
2
+ return this.updateOne({
3
+ collection,
4
+ data,
5
+ locale,
6
+ options: {
7
+ upsert: true
8
+ },
9
+ req,
10
+ where
11
+ });
12
+ };
13
+
14
+ //# sourceMappingURL=upsert.js.map
@@ -0,0 +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"}
@@ -0,0 +1,17 @@
1
+ import type { PipelineStage } from 'mongoose';
2
+ import type { CollectionSlug, JoinQuery, SanitizedCollectionConfig, Where } from 'payload';
3
+ import type { MongooseAdapter } from '../index.js';
4
+ type BuildJoinAggregationArgs = {
5
+ adapter: MongooseAdapter;
6
+ collection: CollectionSlug;
7
+ collectionConfig: SanitizedCollectionConfig;
8
+ joins: JoinQuery;
9
+ limit?: number;
10
+ locale: string;
11
+ query?: Where;
12
+ /** whether the query is from drafts */
13
+ versions?: boolean;
14
+ };
15
+ export declare const buildJoinAggregation: ({ adapter, collection, collectionConfig, joins, limit, locale, query, versions, }: BuildJoinAggregationArgs) => Promise<PipelineStage[] | undefined>;
16
+ export {};
17
+ //# sourceMappingURL=buildJoinAggregation.d.ts.map
@@ -0,0 +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;IACb,uCAAuC;IACvC,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB,CAAA;AAED,eAAO,MAAM,oBAAoB,sFAS9B,wBAAwB,KAAG,OAAO,CAAC,aAAa,EAAE,GAAG,SAAS,CAmJhE,CAAA"}
@@ -0,0 +1,148 @@
1
+ import { buildSortParam } from '../queries/buildSortParam.js';
2
+ export const buildJoinAggregation = async ({ adapter, collection, collectionConfig, joins, limit, locale, query, versions })=>{
3
+ if (Object.keys(collectionConfig.joins).length === 0 || joins === false) {
4
+ return;
5
+ }
6
+ const joinConfig = adapter.payload.collections[collection].config.joins;
7
+ const aggregate = [
8
+ {
9
+ $sort: {
10
+ createdAt: -1
11
+ }
12
+ }
13
+ ];
14
+ if (query) {
15
+ aggregate.push({
16
+ $match: query
17
+ });
18
+ }
19
+ if (limit) {
20
+ aggregate.push({
21
+ $limit: limit
22
+ });
23
+ }
24
+ for (const slug of Object.keys(joinConfig)){
25
+ for (const join of joinConfig[slug]){
26
+ const joinModel = adapter.collections[join.field.collection];
27
+ const { limit: limitJoin = 10, sort: sortJoin, where: whereJoin } = joins?.[join.schemaPath] || {};
28
+ const sort = buildSortParam({
29
+ config: adapter.payload.config,
30
+ fields: adapter.payload.collections[slug].config.fields,
31
+ locale,
32
+ sort: sortJoin || collectionConfig.defaultSort,
33
+ timestamps: true
34
+ });
35
+ const sortProperty = Object.keys(sort)[0];
36
+ const sortDirection = sort[sortProperty] === 'asc' ? 1 : -1;
37
+ const $match = await joinModel.buildQuery({
38
+ locale,
39
+ payload: adapter.payload,
40
+ where: whereJoin
41
+ });
42
+ const pipeline = [
43
+ {
44
+ $match
45
+ },
46
+ {
47
+ $sort: {
48
+ [sortProperty]: sortDirection
49
+ }
50
+ }
51
+ ];
52
+ if (limitJoin > 0) {
53
+ pipeline.push({
54
+ $limit: limitJoin + 1
55
+ });
56
+ }
57
+ if (adapter.payload.config.localization && locale === 'all') {
58
+ adapter.payload.config.localization.localeCodes.forEach((code)=>{
59
+ const as = `${versions ? `version.${join.schemaPath}` : join.schemaPath}${code}`;
60
+ aggregate.push({
61
+ $lookup: {
62
+ as: `${as}.docs`,
63
+ foreignField: `${join.field.on}${code}`,
64
+ from: slug,
65
+ localField: versions ? 'parent' : '_id',
66
+ pipeline
67
+ }
68
+ }, {
69
+ $addFields: {
70
+ [`${as}.docs`]: {
71
+ $map: {
72
+ as: 'doc',
73
+ in: '$$doc._id',
74
+ input: `$${as}.docs`
75
+ }
76
+ },
77
+ [`${as}.hasNextPage`]: limitJoin ? {
78
+ $gt: [
79
+ {
80
+ $size: `$${as}.docs`
81
+ },
82
+ limitJoin
83
+ ]
84
+ } : false
85
+ }
86
+ });
87
+ if (limitJoin > 0) {
88
+ aggregate.push({
89
+ $addFields: {
90
+ [`${as}.docs`]: {
91
+ $slice: [
92
+ `$${as}.docs`,
93
+ limitJoin
94
+ ]
95
+ }
96
+ }
97
+ });
98
+ }
99
+ });
100
+ } else {
101
+ const localeSuffix = join.field.localized && adapter.payload.config.localization && locale ? `.${locale}` : '';
102
+ const as = `${versions ? `version.${join.schemaPath}` : join.schemaPath}${localeSuffix}`;
103
+ aggregate.push({
104
+ $lookup: {
105
+ as: `${as}.docs`,
106
+ foreignField: `${join.field.on}${localeSuffix}`,
107
+ from: slug,
108
+ localField: versions ? 'parent' : '_id',
109
+ pipeline
110
+ }
111
+ }, {
112
+ $addFields: {
113
+ [`${as}.docs`]: {
114
+ $map: {
115
+ as: 'doc',
116
+ in: '$$doc._id',
117
+ input: `$${as}.docs`
118
+ }
119
+ },
120
+ [`${as}.hasNextPage`]: {
121
+ $gt: [
122
+ {
123
+ $size: `$${as}.docs`
124
+ },
125
+ limitJoin || Number.MAX_VALUE
126
+ ]
127
+ }
128
+ }
129
+ });
130
+ if (limitJoin > 0) {
131
+ aggregate.push({
132
+ $addFields: {
133
+ [`${as}.docs`]: {
134
+ $slice: [
135
+ `$${as}.docs`,
136
+ limitJoin
137
+ ]
138
+ }
139
+ }
140
+ });
141
+ }
142
+ }
143
+ }
144
+ }
145
+ return aggregate;
146
+ };
147
+
148
+ //# sourceMappingURL=buildJoinAggregation.js.map
@@ -0,0 +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 /** 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 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 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 = `${versions ? `version.${join.schemaPath}` : 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: 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.schemaPath}` : 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: 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 return aggregate\n}\n"],"names":["buildSortParam","buildJoinAggregation","adapter","collection","collectionConfig","joins","limit","locale","query","versions","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;AAgB7D,OAAO,MAAMC,uBAAuB,OAAO,EACzCC,OAAO,EACPC,UAAU,EACVC,gBAAgB,EAChBC,KAAK,EACLC,KAAK,EACLC,MAAM,EACNC,KAAK,EACLC,QAAQ,EACiB;IACzB,IAAIC,OAAOC,IAAI,CAACP,iBAAiBC,KAAK,EAAEO,MAAM,KAAK,KAAKP,UAAU,OAAO;QACvE;IACF;IAEA,MAAMQ,aAAaX,QAAQY,OAAO,CAACC,WAAW,CAACZ,WAAW,CAACa,MAAM,CAACX,KAAK;IACvE,MAAMY,YAA6B;QACjC;YACEC,OAAO;gBAAEC,WAAW,CAAC;YAAE;QACzB;KACD;IAED,IAAIX,OAAO;QACTS,UAAUG,IAAI,CAAC;YACbC,QAAQb;QACV;IACF;IAEA,IAAIF,OAAO;QACTW,UAAUG,IAAI,CAAC;YACbE,QAAQhB;QACV;IACF;IAEA,KAAK,MAAMiB,QAAQb,OAAOC,IAAI,CAACE,YAAa;QAC1C,KAAK,MAAM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GG;AACH,eAAO,MAAM,SAAS,0DAKnB,IAAI,KAAG,MAiBT,CAAA"}
1
+ {"version":3,"file":"getDBName.d.ts","sourceRoot":"","sources":["../../src/utilities/getDBName.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAE/C,KAAK,IAAI,GAAG;IACV,MAAM,EAAE;QACN,MAAM,CAAC,EAAE,gBAAgB,CAAA;QACzB,QAAQ,CAAC,EAAE,gBAAgB,CAAA;QAC3B,IAAI,CAAC,EAAE,MAAM,CAAA;QACb,IAAI,CAAC,EAAE,MAAM,CAAA;KACd,CAAA;IACD,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,MAAM,CAAC,EAAE,QAAQ,GAAG,UAAU,CAAA;IAC9B,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,SAAS,0DAKnB,IAAI,KAAG,MAmBT,CAAA"}
@@ -12,7 +12,9 @@
12
12
  } else {
13
13
  result = name ?? slug;
14
14
  }
15
- if (versions) result = `_${result}_versions`;
15
+ if (versions) {
16
+ result = `_${result}_versions`;
17
+ }
16
18
  return result;
17
19
  };
18
20
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utilities/getDBName.ts"],"sourcesContent":["import type { DBIdentifierName } from 'payload'\n\ntype Args = {\n config: {\n dbName?: DBIdentifierName\n enumName?: DBIdentifierName\n name?: string\n slug?: string\n }\n locales?: boolean\n target?: 'dbName' | 'enumName'\n versions?: boolean\n}\n\n/**\n * Used to name database enums and collections\n * Returns the collection or enum name for a given entity\n */\nexport const getDBName = ({\n config: { name, slug },\n config,\n target = 'dbName',\n versions = false,\n}: Args): string => {\n let result: string\n let custom = config[target]\n\n if (!custom && target === 'enumName') {\n custom = config['dbName']\n }\n\n if (custom) {\n result = typeof custom === 'function' ? custom({}) : custom\n } else {\n result = name ?? slug\n }\n\n if (versions) result = `_${result}_versions`\n\n return result\n}\n"],"names":["getDBName","config","name","slug","target","versions","result","custom"],"mappings":"AAcA;;;CAGC,GACD,OAAO,MAAMA,YAAY,CAAC,EACxBC,QAAQ,EAAEC,IAAI,EAAEC,IAAI,EAAE,EACtBF,MAAM,EACNG,SAAS,QAAQ,EACjBC,WAAW,KAAK,EACX;IACL,IAAIC;IACJ,IAAIC,SAASN,MAAM,CAACG,OAAO;IAE3B,IAAI,CAACG,UAAUH,WAAW,YAAY;QACpCG,SAASN,MAAM,CAAC,SAAS;IAC3B;IAEA,IAAIM,QAAQ;QACVD,SAAS,OAAOC,WAAW,aAAaA,OAAO,CAAC,KAAKA;IACvD,OAAO;QACLD,SAASJ,QAAQC;IACnB;IAEA,IAAIE,UAAUC,SAAS,CAAC,CAAC,EAAEA,OAAO,SAAS,CAAC;IAE5C,OAAOA;AACT,EAAC"}
1
+ {"version":3,"sources":["../../src/utilities/getDBName.ts"],"sourcesContent":["import type { DBIdentifierName } from 'payload'\n\ntype Args = {\n config: {\n dbName?: DBIdentifierName\n enumName?: DBIdentifierName\n name?: string\n slug?: string\n }\n locales?: boolean\n target?: 'dbName' | 'enumName'\n versions?: boolean\n}\n\n/**\n * Used to name database enums and collections\n * Returns the collection or enum name for a given entity\n */\nexport const getDBName = ({\n config: { name, slug },\n config,\n target = 'dbName',\n versions = false,\n}: Args): string => {\n let result: string\n let custom = config[target]\n\n if (!custom && target === 'enumName') {\n custom = config['dbName']\n }\n\n if (custom) {\n result = typeof custom === 'function' ? custom({}) : custom\n } else {\n result = name ?? slug\n }\n\n if (versions) {\n result = `_${result}_versions`\n }\n\n return result\n}\n"],"names":["getDBName","config","name","slug","target","versions","result","custom"],"mappings":"AAcA;;;CAGC,GACD,OAAO,MAAMA,YAAY,CAAC,EACxBC,QAAQ,EAAEC,IAAI,EAAEC,IAAI,EAAE,EACtBF,MAAM,EACNG,SAAS,QAAQ,EACjBC,WAAW,KAAK,EACX;IACL,IAAIC;IACJ,IAAIC,SAASN,MAAM,CAACG,OAAO;IAE3B,IAAI,CAACG,UAAUH,WAAW,YAAY;QACpCG,SAASN,MAAM,CAAC,SAAS;IAC3B;IAEA,IAAIM,QAAQ;QACVD,SAAS,OAAOC,WAAW,aAAaA,OAAO,CAAC,KAAKA;IACvD,OAAO;QACLD,SAASJ,QAAQC;IACnB;IAEA,IAAIE,UAAU;QACZC,SAAS,CAAC,CAAC,EAAEA,OAAO,SAAS,CAAC;IAChC;IAEA,OAAOA;AACT,EAAC"}
@@ -1,3 +1,2 @@
1
- declare const sanitizeInternalFields: <T extends Record<string, unknown>>(incomingDoc: T) => T;
2
- export default sanitizeInternalFields;
1
+ export declare const sanitizeInternalFields: <T extends Record<string, unknown>>(incomingDoc: T) => T;
3
2
  //# sourceMappingURL=sanitizeInternalFields.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"sanitizeInternalFields.d.ts","sourceRoot":"","sources":["../../src/utilities/sanitizeInternalFields.ts"],"names":[],"mappings":"AAEA,QAAA,MAAM,sBAAsB,GAAI,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,eAAe,CAAC,KAAG,CAiBvE,CAAA;AAEb,eAAe,sBAAsB,CAAA"}
1
+ {"version":3,"file":"sanitizeInternalFields.d.ts","sourceRoot":"","sources":["../../src/utilities/sanitizeInternalFields.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,sBAAsB,GAAI,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,eAAe,CAAC,KAAG,CAiB9E,CAAA"}
@@ -1,7 +1,7 @@
1
1
  const internalFields = [
2
2
  '__v'
3
3
  ];
4
- const sanitizeInternalFields = (incomingDoc)=>Object.entries(incomingDoc).reduce((newDoc, [key, val])=>{
4
+ export const sanitizeInternalFields = (incomingDoc)=>Object.entries(incomingDoc).reduce((newDoc, [key, val])=>{
5
5
  if (key === '_id') {
6
6
  return {
7
7
  ...newDoc,
@@ -16,6 +16,5 @@ const sanitizeInternalFields = (incomingDoc)=>Object.entries(incomingDoc).reduce
16
16
  [key]: val
17
17
  };
18
18
  }, {});
19
- export default sanitizeInternalFields;
20
19
 
21
20
  //# sourceMappingURL=sanitizeInternalFields.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utilities/sanitizeInternalFields.ts"],"sourcesContent":["const internalFields = ['__v']\n\nconst sanitizeInternalFields = <T extends Record<string, unknown>>(incomingDoc: T): T =>\n Object.entries(incomingDoc).reduce((newDoc, [key, val]): T => {\n if (key === '_id') {\n return {\n ...newDoc,\n id: val,\n }\n }\n\n if (internalFields.indexOf(key) > -1) {\n return newDoc\n }\n\n return {\n ...newDoc,\n [key]: val,\n }\n }, {} as T)\n\nexport default sanitizeInternalFields\n"],"names":["internalFields","sanitizeInternalFields","incomingDoc","Object","entries","reduce","newDoc","key","val","id","indexOf"],"mappings":"AAAA,MAAMA,iBAAiB;IAAC;CAAM;AAE9B,MAAMC,yBAAyB,CAAoCC,cACjEC,OAAOC,OAAO,CAACF,aAAaG,MAAM,CAAC,CAACC,QAAQ,CAACC,KAAKC,IAAI;QACpD,IAAID,QAAQ,OAAO;YACjB,OAAO;gBACL,GAAGD,MAAM;gBACTG,IAAID;YACN;QACF;QAEA,IAAIR,eAAeU,OAAO,CAACH,OAAO,CAAC,GAAG;YACpC,OAAOD;QACT;QAEA,OAAO;YACL,GAAGA,MAAM;YACT,CAACC,IAAI,EAAEC;QACT;IACF,GAAG,CAAC;AAEN,eAAeP,uBAAsB"}
1
+ {"version":3,"sources":["../../src/utilities/sanitizeInternalFields.ts"],"sourcesContent":["const internalFields = ['__v']\n\nexport const sanitizeInternalFields = <T extends Record<string, unknown>>(incomingDoc: T): T =>\n Object.entries(incomingDoc).reduce((newDoc, [key, val]): T => {\n if (key === '_id') {\n return {\n ...newDoc,\n id: val,\n }\n }\n\n if (internalFields.indexOf(key) > -1) {\n return newDoc\n }\n\n return {\n ...newDoc,\n [key]: val,\n }\n }, {} as T)\n"],"names":["internalFields","sanitizeInternalFields","incomingDoc","Object","entries","reduce","newDoc","key","val","id","indexOf"],"mappings":"AAAA,MAAMA,iBAAiB;IAAC;CAAM;AAE9B,OAAO,MAAMC,yBAAyB,CAAoCC,cACxEC,OAAOC,OAAO,CAACF,aAAaG,MAAM,CAAC,CAACC,QAAQ,CAACC,KAAKC,IAAI;QACpD,IAAID,QAAQ,OAAO;YACjB,OAAO;gBACL,GAAGD,MAAM;gBACTG,IAAID;YACN;QACF;QAEA,IAAIR,eAAeU,OAAO,CAACH,OAAO,CAAC,GAAG;YACpC,OAAOD;QACT;QAEA,OAAO;YACL,GAAGA,MAAM;YACT,CAACC,IAAI,EAAEC;QACT;IACF,GAAG,CAAC,GAAO"}
@@ -0,0 +1,9 @@
1
+ import type { Field, SanitizedConfig } from 'payload';
2
+ type Args = {
3
+ config: SanitizedConfig;
4
+ data: Record<string, unknown>;
5
+ fields: Field[];
6
+ };
7
+ export declare const sanitizeRelationshipIDs: ({ config, data, fields, }: Args) => Record<string, unknown>;
8
+ export {};
9
+ //# sourceMappingURL=sanitizeRelationshipIDs.d.ts.map
@@ -0,0 +1 @@
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;AAuGD,eAAO,MAAM,uBAAuB,8BAIjC,IAAI,KAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CA6B/B,CAAA"}
@@ -0,0 +1,115 @@
1
+ import mongoose from 'mongoose';
2
+ import { APIError, traverseFields } from 'payload';
3
+ import { fieldAffectsData } from 'payload/shared';
4
+ function isValidRelationObject(value) {
5
+ return typeof value === 'object' && value !== null && 'relationTo' in value && 'value' in value;
6
+ }
7
+ const convertValue = ({ relatedCollection, value })=>{
8
+ const customIDField = relatedCollection.fields.find((field)=>fieldAffectsData(field) && field.name === 'id');
9
+ if (!customIDField) {
10
+ try {
11
+ return new mongoose.Types.ObjectId(value);
12
+ } catch (error) {
13
+ throw new APIError(`Failed to create ObjectId from value: ${value}. Error: ${error.message}`, 400);
14
+ }
15
+ }
16
+ return value;
17
+ };
18
+ const sanitizeRelationship = ({ config, field, locale, ref, value })=>{
19
+ let relatedCollection;
20
+ let result = value;
21
+ const hasManyRelations = typeof field.relationTo !== 'string';
22
+ if (!hasManyRelations) {
23
+ relatedCollection = config.collections?.find(({ slug })=>slug === field.relationTo);
24
+ }
25
+ if (Array.isArray(value)) {
26
+ result = value.map((val)=>{
27
+ // Handle has many
28
+ if (relatedCollection && val && (typeof val === 'string' || typeof val === 'number')) {
29
+ return convertValue({
30
+ relatedCollection,
31
+ value: val
32
+ });
33
+ }
34
+ // Handle has many - polymorphic
35
+ if (isValidRelationObject(val)) {
36
+ const relatedCollectionForSingleValue = config.collections?.find(({ slug })=>slug === val.relationTo);
37
+ if (relatedCollectionForSingleValue) {
38
+ return {
39
+ relationTo: val.relationTo,
40
+ value: convertValue({
41
+ relatedCollection: relatedCollectionForSingleValue,
42
+ value: val.value
43
+ })
44
+ };
45
+ }
46
+ }
47
+ return val;
48
+ });
49
+ }
50
+ // Handle has one - polymorphic
51
+ if (isValidRelationObject(value)) {
52
+ relatedCollection = config.collections?.find(({ slug })=>slug === value.relationTo);
53
+ if (relatedCollection) {
54
+ result = {
55
+ relationTo: value.relationTo,
56
+ value: convertValue({
57
+ relatedCollection,
58
+ value: value.value
59
+ })
60
+ };
61
+ }
62
+ }
63
+ // Handle has one
64
+ if (relatedCollection && value && (typeof value === 'string' || typeof value === 'number')) {
65
+ result = convertValue({
66
+ relatedCollection,
67
+ value
68
+ });
69
+ }
70
+ if (locale) {
71
+ ref[locale] = result;
72
+ } else {
73
+ ref[field.name] = result;
74
+ }
75
+ };
76
+ export const sanitizeRelationshipIDs = ({ config, data, fields })=>{
77
+ const sanitize = ({ field, ref })=>{
78
+ if (field.type === 'relationship' || field.type === 'upload') {
79
+ // handle localized relationships
80
+ if (config.localization && field.localized) {
81
+ const locales = config.localization.locales;
82
+ const fieldRef = ref[field.name];
83
+ for (const { code } of locales){
84
+ if (ref[field.name]?.[code]) {
85
+ const value = ref[field.name][code];
86
+ sanitizeRelationship({
87
+ config,
88
+ field,
89
+ locale: code,
90
+ ref: fieldRef,
91
+ value
92
+ });
93
+ }
94
+ }
95
+ } else {
96
+ // handle non-localized relationships
97
+ sanitizeRelationship({
98
+ config,
99
+ field,
100
+ locale: undefined,
101
+ ref,
102
+ value: ref[field.name]
103
+ });
104
+ }
105
+ }
106
+ };
107
+ traverseFields({
108
+ callback: sanitize,
109
+ fields,
110
+ ref: data
111
+ });
112
+ return data;
113
+ };
114
+
115
+ //# sourceMappingURL=sanitizeRelationshipIDs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utilities/sanitizeRelationshipIDs.ts"],"sourcesContent":["import type { CollectionConfig, Field, SanitizedConfig, TraverseFieldsCallback } from 'payload'\n\nimport mongoose 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}): mongoose.Types.ObjectId | number | string => {\n const customIDField = relatedCollection.fields.find(\n (field) => fieldAffectsData(field) && field.name === 'id',\n )\n\n if (!customIDField) {\n try {\n return new mongoose.Types.ObjectId(value)\n } catch (error) {\n throw new APIError(\n `Failed to create ObjectId from value: ${value}. Error: ${error.message}`,\n 400,\n )\n }\n }\n\n return value\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 (field.type === 'relationship' || field.type === 'upload') {\n // handle localized relationships\n if (config.localization && field.localized) {\n const locales = config.localization.locales\n const fieldRef = ref[field.name]\n for (const { code } of locales) {\n if (ref[field.name]?.[code]) {\n const value = ref[field.name][code]\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, ref: data })\n\n return data\n}\n"],"names":["mongoose","APIError","traverseFields","fieldAffectsData","isValidRelationObject","value","convertValue","relatedCollection","customIDField","fields","find","field","name","Types","ObjectId","error","message","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"],"mappings":"AAEA,OAAOA,cAAc,WAAU;AAC/B,SAASC,QAAQ,EAAEC,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,IAAI,CAACJ,eAAe;QAClB,IAAI;YACF,OAAO,IAAIR,SAASa,KAAK,CAACC,QAAQ,CAACT;QACrC,EAAE,OAAOU,OAAO;YACd,MAAM,IAAId,SACR,CAAC,sCAAsC,EAAEI,MAAM,SAAS,EAAEU,MAAMC,OAAO,CAAC,CAAC,EACzE;QAEJ;IACF;IAEA,OAAOX;AACT;AAEA,MAAMY,uBAAuB,CAAC,EAAEC,MAAM,EAAEP,KAAK,EAAEQ,MAAM,EAAEC,GAAG,EAAEf,KAAK,EAAE;IACjE,IAAIE;IACJ,IAAIc,SAAShB;IAEb,MAAMiB,mBAAmB,OAAOX,MAAMY,UAAU,KAAK;IAErD,IAAI,CAACD,kBAAkB;QACrBf,oBAAoBW,OAAOM,WAAW,EAAEd,KAAK,CAAC,EAAEe,IAAI,EAAE,GAAKA,SAASd,MAAMY,UAAU;IACtF;IAEA,IAAIG,MAAMC,OAA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GAAG,EAAE;QACtD,IAAIT,MAAMuB,IAAI,KAAK,kBAAkBvB,MAAMuB,IAAI,KAAK,UAAU;YAC5D,iCAAiC;YACjC,IAAIhB,OAAOiB,YAAY,IAAIxB,MAAMyB,SAAS,EAAE;gBAC1C,MAAMC,UAAUnB,OAAOiB,YAAY,CAACE,OAAO;gBAC3C,MAAMC,WAAWlB,GAAG,CAACT,MAAMC,IAAI,CAAC;gBAChC,KAAK,MAAM,EAAE2B,IAAI,EAAE,IAAIF,QAAS;oBAC9B,IAAIjB,GAAG,CAACT,MAAMC,IAAI,CAAC,EAAE,CAAC2B,KAAK,EAAE;wBAC3B,MAAMlC,QAAQe,GAAG,CAACT,MAAMC,IAAI,CAAC,CAAC2B,KAAK;wBACnCtB,qBAAqB;4BAAEC;4BAAQP;4BAAOQ,QAAQoB;4BAAMnB,KAAKkB;4BAAUjC;wBAAM;oBAC3E;gBACF;YACF,OAAO;gBACL,qCAAqC;gBACrCY,qBAAqB;oBACnBC;oBACAP;oBACAQ,QAAQqB;oBACRpB;oBACAf,OAAOe,GAAG,CAACT,MAAMC,IAAI,CAAC;gBACxB;YACF;QACF;IACF;IAEAV,eAAe;QAAEuC,UAAUR;QAAUxB;QAAQW,KAAKY;IAAK;IAEvD,OAAOA;AACT,EAAC"}
@@ -7,5 +7,5 @@ import type { MongooseAdapter } from './index.js';
7
7
  */
8
8
  export declare function withSession(db: MongooseAdapter, req: PayloadRequest): Promise<{
9
9
  session: ClientSession;
10
- } | object>;
10
+ } | Record<string, never>>;
11
11
  //# sourceMappingURL=withSession.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"withSession.d.ts","sourceRoot":"","sources":["../src/withSession.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAC7C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAE7C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAEjD;;;GAGG;AACH,wBAAsB,WAAW,CAC/B,EAAE,EAAE,eAAe,EACnB,GAAG,EAAE,cAAc,GAClB,OAAO,CAAC;IAAE,OAAO,EAAE,aAAa,CAAA;CAAE,GAAG,MAAM,CAAC,CAQ9C"}
1
+ {"version":3,"file":"withSession.d.ts","sourceRoot":"","sources":["../src/withSession.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAC7C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAE7C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAEjD;;;GAGG;AACH,wBAAsB,WAAW,CAC/B,EAAE,EAAE,eAAe,EACnB,GAAG,EAAE,cAAc,GAClB,OAAO,CAAC;IAAE,OAAO,EAAE,aAAa,CAAA;CAAE,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAU7D"}
@@ -6,9 +6,11 @@
6
6
  if (transactionID instanceof Promise) {
7
7
  transactionID = await req.transactionID;
8
8
  }
9
- if (req) return db.sessions[transactionID] ? {
10
- session: db.sessions[transactionID]
11
- } : {};
9
+ if (req) {
10
+ return db.sessions[transactionID] ? {
11
+ session: db.sessions[transactionID]
12
+ } : {};
13
+ }
12
14
  }
13
15
 
14
16
  //# sourceMappingURL=withSession.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/withSession.ts"],"sourcesContent":["import type { ClientSession } from 'mongoose'\nimport type { PayloadRequest } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\n/**\n * returns the session belonging to the transaction of the req.session if exists\n * @returns ClientSession\n */\nexport async function withSession(\n db: MongooseAdapter,\n req: PayloadRequest,\n): Promise<{ session: ClientSession } | object> {\n let transactionID = req.transactionID\n\n if (transactionID instanceof Promise) {\n transactionID = await req.transactionID\n }\n\n if (req) return db.sessions[transactionID] ? { session: db.sessions[transactionID] } : {}\n}\n"],"names":["withSession","db","req","transactionID","Promise","sessions","session"],"mappings":"AAKA;;;CAGC,GACD,OAAO,eAAeA,YACpBC,EAAmB,EACnBC,GAAmB;IAEnB,IAAIC,gBAAgBD,IAAIC,aAAa;IAErC,IAAIA,yBAAyBC,SAAS;QACpCD,gBAAgB,MAAMD,IAAIC,aAAa;IACzC;IAEA,IAAID,KAAK,OAAOD,GAAGI,QAAQ,CAACF,cAAc,GAAG;QAAEG,SAASL,GAAGI,QAAQ,CAACF,cAAc;IAAC,IAAI,CAAC;AAC1F"}
1
+ {"version":3,"sources":["../src/withSession.ts"],"sourcesContent":["import type { ClientSession } from 'mongoose'\nimport type { PayloadRequest } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\n/**\n * returns the session belonging to the transaction of the req.session if exists\n * @returns ClientSession\n */\nexport async function withSession(\n db: MongooseAdapter,\n req: PayloadRequest,\n): Promise<{ session: ClientSession } | Record<string, never>> {\n let transactionID = req.transactionID\n\n if (transactionID instanceof Promise) {\n transactionID = await req.transactionID\n }\n\n if (req) {\n return db.sessions[transactionID] ? { session: db.sessions[transactionID] } : {}\n }\n}\n"],"names":["withSession","db","req","transactionID","Promise","sessions","session"],"mappings":"AAKA;;;CAGC,GACD,OAAO,eAAeA,YACpBC,EAAmB,EACnBC,GAAmB;IAEnB,IAAIC,gBAAgBD,IAAIC,aAAa;IAErC,IAAIA,yBAAyBC,SAAS;QACpCD,gBAAgB,MAAMD,IAAIC,aAAa;IACzC;IAEA,IAAID,KAAK;QACP,OAAOD,GAAGI,QAAQ,CAACF,cAAc,GAAG;YAAEG,SAASL,GAAGI,QAAQ,CAACF,cAAc;QAAC,IAAI,CAAC;IACjF;AACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@payloadcms/db-mongodb",
3
- "version": "3.0.0-canary.e14c80d",
3
+ "version": "3.0.0-canary.e1fc0e0",
4
4
  "description": "The officially supported MongoDB database adapter for Payload",
5
5
  "homepage": "https://payloadcms.com",
6
6
  "repository": {
@@ -29,24 +29,27 @@
29
29
  "bson-objectid": "2.0.4",
30
30
  "http-status": "1.6.2",
31
31
  "mongoose": "6.12.3",
32
+ "mongoose-aggregate-paginate-v2": "1.0.6",
32
33
  "mongoose-paginate-v2": "1.7.22",
33
34
  "prompts": "2.4.2",
34
35
  "uuid": "10.0.0"
35
36
  },
36
37
  "devDependencies": {
37
- "@types/mongoose-aggregate-paginate-v2": "1.0.9",
38
+ "@types/mongoose-aggregate-paginate-v2": "1.0.6",
38
39
  "mongodb": "4.17.1",
39
40
  "mongodb-memory-server": "^9",
40
- "@payloadcms/eslint-config": "3.0.0-beta.59",
41
- "payload": "3.0.0-canary.e14c80d"
41
+ "@payloadcms/eslint-config": "3.0.0-beta.112",
42
+ "payload": "3.0.0-canary.e1fc0e0"
42
43
  },
43
44
  "peerDependencies": {
44
- "payload": "3.0.0-canary.e14c80d"
45
+ "payload": "3.0.0-canary.e1fc0e0"
45
46
  },
46
47
  "scripts": {
47
48
  "build": "pnpm build:types && pnpm build:swc",
48
49
  "build:swc": "swc ./src -d ./dist --config-file .swcrc-build --strip-leading-paths",
49
50
  "build:types": "tsc --emitDeclarationOnly --outDir dist",
50
- "clean": "rimraf {dist,*.tsbuildinfo}"
51
+ "clean": "rimraf {dist,*.tsbuildinfo}",
52
+ "lint": "eslint .",
53
+ "lint:fix": "eslint . --fix"
51
54
  }
52
55
  }