@payloadcms/db-mongodb 3.2.2-canary.d2399ed → 3.2.3-canary.2d2e7d5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (127) hide show
  1. package/dist/count.d.ts.map +1 -1
  2. package/dist/count.js +21 -19
  3. package/dist/count.js.map +1 -1
  4. package/dist/countGlobalVersions.d.ts.map +1 -1
  5. package/dist/countGlobalVersions.js +21 -19
  6. package/dist/countGlobalVersions.js.map +1 -1
  7. package/dist/countVersions.d.ts.map +1 -1
  8. package/dist/countVersions.js +21 -19
  9. package/dist/countVersions.js.map +1 -1
  10. package/dist/create.d.ts.map +1 -1
  11. package/dist/create.js +22 -22
  12. package/dist/create.js.map +1 -1
  13. package/dist/createGlobal.d.ts.map +1 -1
  14. package/dist/createGlobal.js +19 -21
  15. package/dist/createGlobal.js.map +1 -1
  16. package/dist/createGlobalVersion.d.ts.map +1 -1
  17. package/dist/createGlobalVersion.js +30 -35
  18. package/dist/createGlobalVersion.js.map +1 -1
  19. package/dist/createVersion.d.ts.map +1 -1
  20. package/dist/createVersion.js +30 -35
  21. package/dist/createVersion.js.map +1 -1
  22. package/dist/deleteMany.d.ts.map +1 -1
  23. package/dist/deleteMany.js +6 -6
  24. package/dist/deleteMany.js.map +1 -1
  25. package/dist/deleteOne.d.ts.map +1 -1
  26. package/dist/deleteOne.js +13 -17
  27. package/dist/deleteOne.js.map +1 -1
  28. package/dist/deleteVersions.d.ts.map +1 -1
  29. package/dist/deleteVersions.js +6 -6
  30. package/dist/deleteVersions.js.map +1 -1
  31. package/dist/find.d.ts.map +1 -1
  32. package/dist/find.js +74 -41
  33. package/dist/find.js.map +1 -1
  34. package/dist/findGlobal.d.ts.map +1 -1
  35. package/dist/findGlobal.js +18 -19
  36. package/dist/findGlobal.js.map +1 -1
  37. package/dist/findGlobalVersions.d.ts.map +1 -1
  38. package/dist/findGlobalVersions.js +62 -33
  39. package/dist/findGlobalVersions.js.map +1 -1
  40. package/dist/findOne.d.ts.map +1 -1
  41. package/dist/findOne.js +19 -32
  42. package/dist/findOne.js.map +1 -1
  43. package/dist/findVersions.d.ts.map +1 -1
  44. package/dist/findVersions.js +62 -34
  45. package/dist/findVersions.js.map +1 -1
  46. package/dist/predefinedMigrations/migrateRelationshipsV2_V3.d.ts.map +1 -1
  47. package/dist/predefinedMigrations/migrateRelationshipsV2_V3.js +16 -20
  48. package/dist/predefinedMigrations/migrateRelationshipsV2_V3.js.map +1 -1
  49. package/dist/predefinedMigrations/migrateVersionsV1_V2.js +2 -2
  50. package/dist/predefinedMigrations/migrateVersionsV1_V2.js.map +1 -1
  51. package/dist/queries/buildAndOrConditions.d.ts +1 -3
  52. package/dist/queries/buildAndOrConditions.d.ts.map +1 -1
  53. package/dist/queries/buildAndOrConditions.js +1 -2
  54. package/dist/queries/buildAndOrConditions.js.map +1 -1
  55. package/dist/queries/buildQuery.d.ts +0 -2
  56. package/dist/queries/buildQuery.d.ts.map +1 -1
  57. package/dist/queries/buildQuery.js +6 -2
  58. package/dist/queries/buildQuery.js.map +1 -1
  59. package/dist/queries/buildSearchParams.d.ts +1 -3
  60. package/dist/queries/buildSearchParams.d.ts.map +1 -1
  61. package/dist/queries/buildSearchParams.js +10 -14
  62. package/dist/queries/buildSearchParams.js.map +1 -1
  63. package/dist/queries/buildSortParam.d.ts +7 -1
  64. package/dist/queries/buildSortParam.d.ts.map +1 -1
  65. package/dist/queries/buildSortParam.js +2 -2
  66. package/dist/queries/buildSortParam.js.map +1 -1
  67. package/dist/queries/getLocalizedSortProperty.js +2 -2
  68. package/dist/queries/getLocalizedSortProperty.js.map +1 -1
  69. package/dist/queries/parseParams.d.ts +1 -3
  70. package/dist/queries/parseParams.d.ts.map +1 -1
  71. package/dist/queries/parseParams.js +1 -2
  72. package/dist/queries/parseParams.js.map +1 -1
  73. package/dist/queries/sanitizeQueryValue.d.ts.map +1 -1
  74. package/dist/queries/sanitizeQueryValue.js +0 -16
  75. package/dist/queries/sanitizeQueryValue.js.map +1 -1
  76. package/dist/queryDrafts.d.ts.map +1 -1
  77. package/dist/queryDrafts.js +65 -41
  78. package/dist/queryDrafts.js.map +1 -1
  79. package/dist/updateGlobal.d.ts.map +1 -1
  80. package/dist/updateGlobal.js +23 -25
  81. package/dist/updateGlobal.js.map +1 -1
  82. package/dist/updateGlobalVersion.d.ts.map +1 -1
  83. package/dist/updateGlobalVersion.js +27 -28
  84. package/dist/updateGlobalVersion.js.map +1 -1
  85. package/dist/updateOne.d.ts.map +1 -1
  86. package/dist/updateOne.js +24 -28
  87. package/dist/updateOne.js.map +1 -1
  88. package/dist/updateVersion.d.ts.map +1 -1
  89. package/dist/updateVersion.js +26 -28
  90. package/dist/updateVersion.js.map +1 -1
  91. package/dist/utilities/buildJoinAggregation.d.ts +4 -4
  92. package/dist/utilities/buildJoinAggregation.d.ts.map +1 -1
  93. package/dist/utilities/buildJoinAggregation.js +28 -7
  94. package/dist/utilities/buildJoinAggregation.js.map +1 -1
  95. package/dist/utilities/buildProjectionFromSelect.d.ts.map +1 -1
  96. package/dist/utilities/buildProjectionFromSelect.js +1 -18
  97. package/dist/utilities/buildProjectionFromSelect.js.map +1 -1
  98. package/dist/utilities/sanitizeInternalFields.d.ts +2 -0
  99. package/dist/utilities/sanitizeInternalFields.d.ts.map +1 -0
  100. package/dist/utilities/sanitizeInternalFields.js +20 -0
  101. package/dist/utilities/sanitizeInternalFields.js.map +1 -0
  102. package/dist/utilities/sanitizeRelationshipIDs.d.ts +9 -0
  103. package/dist/utilities/sanitizeRelationshipIDs.d.ts.map +1 -0
  104. package/dist/utilities/sanitizeRelationshipIDs.js +125 -0
  105. package/dist/utilities/sanitizeRelationshipIDs.js.map +1 -0
  106. package/dist/utilities/{transform.spec.js → sanitizeRelationshipIDs.spec.js} +7 -23
  107. package/dist/utilities/sanitizeRelationshipIDs.spec.js.map +1 -0
  108. package/dist/{getSession.d.ts → withSession.d.ts} +4 -2
  109. package/dist/withSession.d.ts.map +1 -0
  110. package/dist/{getSession.js → withSession.js} +5 -3
  111. package/dist/withSession.js.map +1 -0
  112. package/package.json +3 -3
  113. package/dist/getSession.d.ts.map +0 -1
  114. package/dist/getSession.js.map +0 -1
  115. package/dist/utilities/findMany.d.ts +0 -20
  116. package/dist/utilities/findMany.d.ts.map +0 -1
  117. package/dist/utilities/findMany.js +0 -84
  118. package/dist/utilities/findMany.js.map +0 -1
  119. package/dist/utilities/getHasNearConstraint.d.ts +0 -3
  120. package/dist/utilities/getHasNearConstraint.d.ts.map +0 -1
  121. package/dist/utilities/getHasNearConstraint.js +0 -26
  122. package/dist/utilities/getHasNearConstraint.js.map +0 -1
  123. package/dist/utilities/transform.d.ts +0 -17
  124. package/dist/utilities/transform.d.ts.map +0 -1
  125. package/dist/utilities/transform.js +0 -250
  126. package/dist/utilities/transform.js.map +0 -1
  127. package/dist/utilities/transform.spec.js.map +0 -1
@@ -1,31 +1,27 @@
1
1
  import { Types } from 'mongoose';
2
2
  import { buildVersionCollectionFields } from 'payload';
3
- import { getSession } from './getSession.js';
4
- import { transform } from './utilities/transform.js';
3
+ import { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.js';
4
+ import { withSession } from './withSession.js';
5
5
  export const createVersion = async function createVersion({ autosave, collectionSlug, createdAt, parent, publishedLocale, req = {}, snapshot, updatedAt, versionData }) {
6
6
  const VersionModel = this.versions[collectionSlug];
7
- const session = await getSession(this, req);
8
- const data = {
9
- autosave,
10
- createdAt,
11
- latest: true,
12
- parent,
13
- publishedLocale,
14
- snapshot,
15
- updatedAt,
16
- version: versionData
17
- };
18
- const fields = buildVersionCollectionFields(this.payload.config, this.payload.collections[collectionSlug].config, true);
19
- transform({
20
- adapter: this,
21
- data,
22
- fields,
23
- operation: 'create'
24
- });
25
- const { insertedId } = await VersionModel.collection.insertOne(data, {
26
- session
7
+ const options = await withSession(this, req);
8
+ const data = sanitizeRelationshipIDs({
9
+ config: this.payload.config,
10
+ data: {
11
+ autosave,
12
+ createdAt,
13
+ latest: true,
14
+ parent,
15
+ publishedLocale,
16
+ snapshot,
17
+ updatedAt,
18
+ version: versionData
19
+ },
20
+ fields: buildVersionCollectionFields(this.payload.config, this.payload.collections[collectionSlug].config)
27
21
  });
28
- data._id = insertedId;
22
+ const [doc] = await VersionModel.create([
23
+ data
24
+ ], options, req);
29
25
  const parentQuery = {
30
26
  $or: [
31
27
  {
@@ -42,11 +38,11 @@ export const createVersion = async function createVersion({ autosave, collection
42
38
  }
43
39
  });
44
40
  }
45
- await VersionModel.collection.updateMany({
41
+ await VersionModel.updateMany({
46
42
  $and: [
47
43
  {
48
44
  _id: {
49
- $ne: insertedId
45
+ $ne: doc._id
50
46
  }
51
47
  },
52
48
  parentQuery,
@@ -60,16 +56,15 @@ export const createVersion = async function createVersion({ autosave, collection
60
56
  $unset: {
61
57
  latest: 1
62
58
  }
63
- }, {
64
- session
65
- });
66
- transform({
67
- adapter: this,
68
- data,
69
- fields,
70
- operation: 'read'
71
- });
72
- return data;
59
+ }, options);
60
+ const result = JSON.parse(JSON.stringify(doc));
61
+ const verificationToken = doc._verificationToken;
62
+ // custom id type reset
63
+ result.id = result._id;
64
+ if (verificationToken) {
65
+ result._verificationToken = verificationToken;
66
+ }
67
+ return result;
73
68
  };
74
69
 
75
70
  //# sourceMappingURL=createVersion.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/createVersion.ts"],"sourcesContent":["import { Types } from 'mongoose'\nimport { buildVersionCollectionFields, type CreateVersion, type PayloadRequest } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { getSession } from './getSession.js'\nimport { transform } from './utilities/transform.js'\n\nexport const createVersion: CreateVersion = async function createVersion(\n this: MongooseAdapter,\n {\n autosave,\n collectionSlug,\n createdAt,\n parent,\n publishedLocale,\n req = {} as PayloadRequest,\n snapshot,\n updatedAt,\n versionData,\n },\n) {\n const VersionModel = this.versions[collectionSlug]\n const session = await getSession(this, req)\n\n const data: any = {\n autosave,\n createdAt,\n latest: true,\n parent,\n publishedLocale,\n snapshot,\n updatedAt,\n version: versionData,\n }\n\n const fields = buildVersionCollectionFields(\n this.payload.config,\n this.payload.collections[collectionSlug].config,\n true,\n )\n\n transform({\n adapter: this,\n data,\n fields,\n operation: 'create',\n })\n\n const { insertedId } = await VersionModel.collection.insertOne(data, { session })\n data._id = insertedId\n\n const parentQuery = {\n $or: [\n {\n parent: {\n $eq: data.parent,\n },\n },\n ],\n }\n if ((data.parent as unknown) instanceof Types.ObjectId) {\n parentQuery.$or.push({\n parent: {\n $eq: data.parent.toString(),\n },\n })\n }\n\n await VersionModel.collection.updateMany(\n {\n $and: [\n {\n _id: {\n $ne: insertedId,\n },\n },\n parentQuery,\n {\n latest: {\n $eq: true,\n },\n },\n ],\n },\n { $unset: { latest: 1 } },\n { session },\n )\n\n transform({\n adapter: this,\n data,\n fields,\n operation: 'read',\n })\n\n return data\n}\n"],"names":["Types","buildVersionCollectionFields","getSession","transform","createVersion","autosave","collectionSlug","createdAt","parent","publishedLocale","req","snapshot","updatedAt","versionData","VersionModel","versions","session","data","latest","version","fields","payload","config","collections","adapter","operation","insertedId","collection","insertOne","_id","parentQuery","$or","$eq","ObjectId","push","toString","updateMany","$and","$ne","$unset"],"mappings":"AAAA,SAASA,KAAK,QAAQ,WAAU;AAChC,SAASC,4BAA4B,QAAiD,UAAS;AAI/F,SAASC,UAAU,QAAQ,kBAAiB;AAC5C,SAASC,SAAS,QAAQ,2BAA0B;AAEpD,OAAO,MAAMC,gBAA+B,eAAeA,cAEzD,EACEC,QAAQ,EACRC,cAAc,EACdC,SAAS,EACTC,MAAM,EACNC,eAAe,EACfC,MAAM,CAAC,CAAmB,EAC1BC,QAAQ,EACRC,SAAS,EACTC,WAAW,EACZ;IAED,MAAMC,eAAe,IAAI,CAACC,QAAQ,CAACT,eAAe;IAClD,MAAMU,UAAU,MAAMd,WAAW,IAAI,EAAEQ;IAEvC,MAAMO,OAAY;QAChBZ;QACAE;QACAW,QAAQ;QACRV;QACAC;QACAE;QACAC;QACAO,SAASN;IACX;IAEA,MAAMO,SAASnB,6BACb,IAAI,CAACoB,OAAO,CAACC,MAAM,EACnB,IAAI,CAACD,OAAO,CAACE,WAAW,CAACjB,eAAe,CAACgB,MAAM,EAC/C;IAGFnB,UAAU;QACRqB,SAAS,IAAI;QACbP;QACAG;QACAK,WAAW;IACb;IAEA,MAAM,EAAEC,UAAU,EAAE,GAAG,MAAMZ,aAAaa,UAAU,CAACC,SAAS,CAACX,MAAM;QAAED;IAAQ;IAC/EC,KAAKY,GAAG,GAAGH;IAEX,MAAMI,cAAc;QAClBC,KAAK;YACH;gBACEvB,QAAQ;oBACNwB,KAAKf,KAAKT,MAAM;gBAClB;YACF;SACD;IACH;IACA,IAAI,AAACS,KAAKT,MAAM,YAAwBR,MAAMiC,QAAQ,EAAE;QACtDH,YAAYC,GAAG,CAACG,IAAI,CAAC;YACnB1B,QAAQ;gBACNwB,KAAKf,KAAKT,MAAM,CAAC2B,QAAQ;YAC3B;QACF;IACF;IAEA,MAAMrB,aAAaa,UAAU,CAACS,UAAU,CACtC;QACEC,MAAM;YACJ;gBACER,KAAK;oBACHS,KAAKZ;gBACP;YACF;YACAI;YACA;gBACEZ,QAAQ;oBACNc,KAAK;gBACP;YACF;SACD;IACH,GACA;QAAEO,QAAQ;YAAErB,QAAQ;QAAE;IAAE,GACxB;QAAEF;IAAQ;IAGZb,UAAU;QACRqB,SAAS,IAAI;QACbP;QACAG;QACAK,WAAW;IACb;IAEA,OAAOR;AACT,EAAC"}
1
+ {"version":3,"sources":["../src/createVersion.ts"],"sourcesContent":["import { Types } from 'mongoose'\nimport {\n buildVersionCollectionFields,\n type CreateVersion,\n type Document,\n type PayloadRequest,\n} from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.js'\nimport { withSession } from './withSession.js'\n\nexport const createVersion: CreateVersion = async function createVersion(\n this: MongooseAdapter,\n {\n autosave,\n collectionSlug,\n createdAt,\n parent,\n publishedLocale,\n req = {} as PayloadRequest,\n snapshot,\n updatedAt,\n versionData,\n },\n) {\n const VersionModel = this.versions[collectionSlug]\n const options = await withSession(this, req)\n\n const data = sanitizeRelationshipIDs({\n config: this.payload.config,\n data: {\n autosave,\n createdAt,\n latest: true,\n parent,\n publishedLocale,\n snapshot,\n updatedAt,\n version: versionData,\n },\n fields: buildVersionCollectionFields(\n this.payload.config,\n this.payload.collections[collectionSlug].config,\n ),\n })\n\n const [doc] = await VersionModel.create([data], options, req)\n\n const parentQuery = {\n $or: [\n {\n parent: {\n $eq: data.parent,\n },\n },\n ],\n }\n if (data.parent instanceof Types.ObjectId) {\n parentQuery.$or.push({\n parent: {\n $eq: data.parent.toString(),\n },\n })\n }\n\n await VersionModel.updateMany(\n {\n $and: [\n {\n _id: {\n $ne: doc._id,\n },\n },\n parentQuery,\n {\n latest: {\n $eq: true,\n },\n },\n ],\n },\n { $unset: { latest: 1 } },\n options,\n )\n\n const result: Document = JSON.parse(JSON.stringify(doc))\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":["Types","buildVersionCollectionFields","sanitizeRelationshipIDs","withSession","createVersion","autosave","collectionSlug","createdAt","parent","publishedLocale","req","snapshot","updatedAt","versionData","VersionModel","versions","options","data","config","payload","latest","version","fields","collections","doc","create","parentQuery","$or","$eq","ObjectId","push","toString","updateMany","$and","_id","$ne","$unset","result","JSON","parse","stringify","verificationToken","_verificationToken","id"],"mappings":"AAAA,SAASA,KAAK,QAAQ,WAAU;AAChC,SACEC,4BAA4B,QAIvB,UAAS;AAIhB,SAASC,uBAAuB,QAAQ,yCAAwC;AAChF,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,gBAA+B,eAAeA,cAEzD,EACEC,QAAQ,EACRC,cAAc,EACdC,SAAS,EACTC,MAAM,EACNC,eAAe,EACfC,MAAM,CAAC,CAAmB,EAC1BC,QAAQ,EACRC,SAAS,EACTC,WAAW,EACZ;IAED,MAAMC,eAAe,IAAI,CAACC,QAAQ,CAACT,eAAe;IAClD,MAAMU,UAAU,MAAMb,YAAY,IAAI,EAAEO;IAExC,MAAMO,OAAOf,wBAAwB;QACnCgB,QAAQ,IAAI,CAACC,OAAO,CAACD,MAAM;QAC3BD,MAAM;YACJZ;YACAE;YACAa,QAAQ;YACRZ;YACAC;YACAE;YACAC;YACAS,SAASR;QACX;QACAS,QAAQrB,6BACN,IAAI,CAACkB,OAAO,CAACD,MAAM,EACnB,IAAI,CAACC,OAAO,CAACI,WAAW,CAACjB,eAAe,CAACY,MAAM;IAEnD;IAEA,MAAM,CAACM,IAAI,GAAG,MAAMV,aAAaW,MAAM,CAAC;QAACR;KAAK,EAAED,SAASN;IAEzD,MAAMgB,cAAc;QAClBC,KAAK;YACH;gBACEnB,QAAQ;oBACNoB,KAAKX,KAAKT,MAAM;gBAClB;YACF;SACD;IACH;IACA,IAAIS,KAAKT,MAAM,YAAYR,MAAM6B,QAAQ,EAAE;QACzCH,YAAYC,GAAG,CAACG,IAAI,CAAC;YACnBtB,QAAQ;gBACNoB,KAAKX,KAAKT,MAAM,CAACuB,QAAQ;YAC3B;QACF;IACF;IAEA,MAAMjB,aAAakB,UAAU,CAC3B;QACEC,MAAM;YACJ;gBACEC,KAAK;oBACHC,KAAKX,IAAIU,GAAG;gBACd;YACF;YACAR;YACA;gBACEN,QAAQ;oBACNQ,KAAK;gBACP;YACF;SACD;IACH,GACA;QAAEQ,QAAQ;YAAEhB,QAAQ;QAAE;IAAE,GACxBJ;IAGF,MAAMqB,SAAmBC,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAAChB;IACnD,MAAMiB,oBAAoBjB,IAAIkB,kBAAkB;IAEhD,uBAAuB;IACvBL,OAAOM,EAAE,GAAGN,OAAOH,GAAG;IACtB,IAAIO,mBAAmB;QACrBJ,OAAOK,kBAAkB,GAAGD;IAC9B;IACA,OAAOJ;AACT,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"deleteMany.d.ts","sourceRoot":"","sources":["../src/deleteMany.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAkB,MAAM,SAAS,CAAA;AAMzD,eAAO,MAAM,UAAU,EAAE,UAiBxB,CAAA"}
1
+ {"version":3,"file":"deleteMany.d.ts","sourceRoot":"","sources":["../src/deleteMany.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAkB,MAAM,SAAS,CAAA;AAMzD,eAAO,MAAM,UAAU,EAAE,UAgBxB,CAAA"}
@@ -1,15 +1,15 @@
1
- import { getSession } from './getSession.js';
1
+ import { withSession } from './withSession.js';
2
2
  export const deleteMany = async function deleteMany({ collection, req = {}, where }) {
3
3
  const Model = this.collections[collection];
4
- const session = await getSession(this, req);
4
+ const options = {
5
+ ...await withSession(this, req),
6
+ lean: true
7
+ };
5
8
  const query = await Model.buildQuery({
6
9
  payload: this.payload,
7
- session,
8
10
  where
9
11
  });
10
- await Model.collection.deleteMany(query, {
11
- session
12
- });
12
+ await Model.deleteMany(query, options);
13
13
  };
14
14
 
15
15
  //# sourceMappingURL=deleteMany.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/deleteMany.ts"],"sourcesContent":["import type { DeleteMany, PayloadRequest } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { getSession } from './getSession.js'\n\nexport const deleteMany: DeleteMany = async function deleteMany(\n this: MongooseAdapter,\n { collection, req = {} as PayloadRequest, where },\n) {\n const Model = this.collections[collection]\n\n const session = await getSession(this, req)\n\n const query = await Model.buildQuery({\n payload: this.payload,\n session,\n where,\n })\n\n await Model.collection.deleteMany(query, {\n session,\n })\n}\n"],"names":["getSession","deleteMany","collection","req","where","Model","collections","session","query","buildQuery","payload"],"mappings":"AAIA,SAASA,UAAU,QAAQ,kBAAiB;AAE5C,OAAO,MAAMC,aAAyB,eAAeA,WAEnD,EAAEC,UAAU,EAAEC,MAAM,CAAC,CAAmB,EAAEC,KAAK,EAAE;IAEjD,MAAMC,QAAQ,IAAI,CAACC,WAAW,CAACJ,WAAW;IAE1C,MAAMK,UAAU,MAAMP,WAAW,IAAI,EAAEG;IAEvC,MAAMK,QAAQ,MAAMH,MAAMI,UAAU,CAAC;QACnCC,SAAS,IAAI,CAACA,OAAO;QACrBH;QACAH;IACF;IAEA,MAAMC,MAAMH,UAAU,CAACD,UAAU,CAACO,OAAO;QACvCD;IACF;AACF,EAAC"}
1
+ {"version":3,"sources":["../src/deleteMany.ts"],"sourcesContent":["import type { DeleteMany, PayloadRequest } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { withSession } from './withSession.js'\n\nexport const deleteMany: DeleteMany = async function deleteMany(\n this: MongooseAdapter,\n { collection, req = {} as PayloadRequest, where },\n) {\n const Model = this.collections[collection]\n const options = {\n ...(await withSession(this, req)),\n lean: true,\n }\n\n const query = await Model.buildQuery({\n payload: this.payload,\n where,\n })\n\n await Model.deleteMany(query, options)\n}\n"],"names":["withSession","deleteMany","collection","req","where","Model","collections","options","lean","query","buildQuery","payload"],"mappings":"AAIA,SAASA,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,aAAyB,eAAeA,WAEnD,EAAEC,UAAU,EAAEC,MAAM,CAAC,CAAmB,EAAEC,KAAK,EAAE;IAEjD,MAAMC,QAAQ,IAAI,CAACC,WAAW,CAACJ,WAAW;IAC1C,MAAMK,UAAU;QACd,GAAI,MAAMP,YAAY,IAAI,EAAEG,IAAI;QAChCK,MAAM;IACR;IAEA,MAAMC,QAAQ,MAAMJ,MAAMK,UAAU,CAAC;QACnCC,SAAS,IAAI,CAACA,OAAO;QACrBP;IACF;IAEA,MAAMC,MAAMJ,UAAU,CAACQ,OAAOF;AAChC,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"deleteOne.d.ts","sourceRoot":"","sources":["../src/deleteOne.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAkB,MAAM,SAAS,CAAA;AAQxD,eAAO,MAAM,SAAS,EAAE,SAgCvB,CAAA"}
1
+ {"version":3,"file":"deleteOne.d.ts","sourceRoot":"","sources":["../src/deleteOne.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAA4B,MAAM,SAAS,CAAA;AAQlE,eAAO,MAAM,SAAS,EAAE,SA4BvB,CAAA"}
package/dist/deleteOne.js CHANGED
@@ -1,30 +1,26 @@
1
- import { getSession } from './getSession.js';
2
1
  import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
3
- import { transform } from './utilities/transform.js';
2
+ import { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js';
3
+ import { withSession } from './withSession.js';
4
4
  export const deleteOne = async function deleteOne({ collection, req = {}, select, where }) {
5
5
  const Model = this.collections[collection];
6
- const session = await getSession(this, req);
6
+ const options = await withSession(this, req);
7
7
  const query = await Model.buildQuery({
8
8
  payload: this.payload,
9
- session,
10
9
  where
11
10
  });
12
- const fields = this.payload.collections[collection].config.flattenedFields;
13
- const doc = await Model.collection.findOneAndDelete(query, {
11
+ const doc = await Model.findOneAndDelete(query, {
12
+ ...options,
14
13
  projection: buildProjectionFromSelect({
15
14
  adapter: this,
16
- fields,
15
+ fields: this.payload.collections[collection].config.flattenedFields,
17
16
  select
18
- }),
19
- session
20
- });
21
- transform({
22
- adapter: this,
23
- data: doc,
24
- fields,
25
- operation: 'read'
26
- });
27
- return doc;
17
+ })
18
+ }).lean();
19
+ let result = JSON.parse(JSON.stringify(doc));
20
+ // custom id type reset
21
+ result.id = result._id;
22
+ result = sanitizeInternalFields(result);
23
+ return result;
28
24
  };
29
25
 
30
26
  //# sourceMappingURL=deleteOne.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/deleteOne.ts"],"sourcesContent":["import type { DeleteOne, PayloadRequest } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { getSession } from './getSession.js'\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { transform } from './utilities/transform.js'\n\nexport const deleteOne: DeleteOne = async function deleteOne(\n this: MongooseAdapter,\n { collection, req = {} as PayloadRequest, select, where },\n) {\n const Model = this.collections[collection]\n const session = await getSession(this, req)\n\n const query = await Model.buildQuery({\n payload: this.payload,\n session,\n where,\n })\n\n const fields = this.payload.collections[collection].config.flattenedFields\n\n const doc = await Model.collection.findOneAndDelete(query, {\n projection: buildProjectionFromSelect({\n adapter: this,\n fields,\n select,\n }),\n session,\n })\n\n transform({\n adapter: this,\n data: doc,\n fields,\n operation: 'read',\n })\n\n return doc\n}\n"],"names":["getSession","buildProjectionFromSelect","transform","deleteOne","collection","req","select","where","Model","collections","session","query","buildQuery","payload","fields","config","flattenedFields","doc","findOneAndDelete","projection","adapter","data","operation"],"mappings":"AAIA,SAASA,UAAU,QAAQ,kBAAiB;AAC5C,SAASC,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,SAAS,QAAQ,2BAA0B;AAEpD,OAAO,MAAMC,YAAuB,eAAeA,UAEjD,EAAEC,UAAU,EAAEC,MAAM,CAAC,CAAmB,EAAEC,MAAM,EAAEC,KAAK,EAAE;IAEzD,MAAMC,QAAQ,IAAI,CAACC,WAAW,CAACL,WAAW;IAC1C,MAAMM,UAAU,MAAMV,WAAW,IAAI,EAAEK;IAEvC,MAAMM,QAAQ,MAAMH,MAAMI,UAAU,CAAC;QACnCC,SAAS,IAAI,CAACA,OAAO;QACrBH;QACAH;IACF;IAEA,MAAMO,SAAS,IAAI,CAACD,OAAO,CAACJ,WAAW,CAACL,WAAW,CAACW,MAAM,CAACC,eAAe;IAE1E,MAAMC,MAAM,MAAMT,MAAMJ,UAAU,CAACc,gBAAgB,CAACP,OAAO;QACzDQ,YAAYlB,0BAA0B;YACpCmB,SAAS,IAAI;YACbN;YACAR;QACF;QACAI;IACF;IAEAR,UAAU;QACRkB,SAAS,IAAI;QACbC,MAAMJ;QACNH;QACAQ,WAAW;IACb;IAEA,OAAOL;AACT,EAAC"}
1
+ {"version":3,"sources":["../src/deleteOne.ts"],"sourcesContent":["import type { DeleteOne, Document, PayloadRequest } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js'\nimport { withSession } from './withSession.js'\n\nexport const deleteOne: DeleteOne = async function deleteOne(\n this: MongooseAdapter,\n { collection, req = {} as PayloadRequest, select, where },\n) {\n const Model = this.collections[collection]\n const options = await withSession(this, req)\n\n const query = await Model.buildQuery({\n payload: this.payload,\n where,\n })\n\n const doc = await Model.findOneAndDelete(query, {\n ...options,\n projection: buildProjectionFromSelect({\n adapter: this,\n fields: this.payload.collections[collection].config.flattenedFields,\n select,\n }),\n }).lean()\n\n let result: Document = JSON.parse(JSON.stringify(doc))\n\n // custom id type reset\n result.id = result._id\n result = sanitizeInternalFields(result)\n\n return result\n}\n"],"names":["buildProjectionFromSelect","sanitizeInternalFields","withSession","deleteOne","collection","req","select","where","Model","collections","options","query","buildQuery","payload","doc","findOneAndDelete","projection","adapter","fields","config","flattenedFields","lean","result","JSON","parse","stringify","id","_id"],"mappings":"AAIA,SAASA,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,sBAAsB,QAAQ,wCAAuC;AAC9E,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,YAAuB,eAAeA,UAEjD,EAAEC,UAAU,EAAEC,MAAM,CAAC,CAAmB,EAAEC,MAAM,EAAEC,KAAK,EAAE;IAEzD,MAAMC,QAAQ,IAAI,CAACC,WAAW,CAACL,WAAW;IAC1C,MAAMM,UAAU,MAAMR,YAAY,IAAI,EAAEG;IAExC,MAAMM,QAAQ,MAAMH,MAAMI,UAAU,CAAC;QACnCC,SAAS,IAAI,CAACA,OAAO;QACrBN;IACF;IAEA,MAAMO,MAAM,MAAMN,MAAMO,gBAAgB,CAACJ,OAAO;QAC9C,GAAGD,OAAO;QACVM,YAAYhB,0BAA0B;YACpCiB,SAAS,IAAI;YACbC,QAAQ,IAAI,CAACL,OAAO,CAACJ,WAAW,CAACL,WAAW,CAACe,MAAM,CAACC,eAAe;YACnEd;QACF;IACF,GAAGe,IAAI;IAEP,IAAIC,SAAmBC,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACX;IAEjD,uBAAuB;IACvBQ,OAAOI,EAAE,GAAGJ,OAAOK,GAAG;IACtBL,SAASrB,uBAAuBqB;IAEhC,OAAOA;AACT,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"deleteVersions.d.ts","sourceRoot":"","sources":["../src/deleteVersions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAkB,MAAM,SAAS,CAAA;AAM7D,eAAO,MAAM,cAAc,EAAE,cAkB5B,CAAA"}
1
+ {"version":3,"file":"deleteVersions.d.ts","sourceRoot":"","sources":["../src/deleteVersions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAkB,MAAM,SAAS,CAAA;AAM7D,eAAO,MAAM,cAAc,EAAE,cAiB5B,CAAA"}
@@ -1,16 +1,16 @@
1
- import { getSession } from './getSession.js';
1
+ import { withSession } from './withSession.js';
2
2
  export const deleteVersions = async function deleteVersions({ collection, locale, req = {}, where }) {
3
3
  const VersionsModel = this.versions[collection];
4
- const session = await getSession(this, req);
4
+ const options = {
5
+ ...await withSession(this, req),
6
+ lean: true
7
+ };
5
8
  const query = await VersionsModel.buildQuery({
6
9
  locale,
7
10
  payload: this.payload,
8
- session,
9
11
  where
10
12
  });
11
- await VersionsModel.collection.deleteMany(query, {
12
- session
13
- });
13
+ await VersionsModel.deleteMany(query, options);
14
14
  };
15
15
 
16
16
  //# sourceMappingURL=deleteVersions.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/deleteVersions.ts"],"sourcesContent":["import type { DeleteVersions, PayloadRequest } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { getSession } from './getSession.js'\n\nexport const deleteVersions: DeleteVersions = async function deleteVersions(\n this: MongooseAdapter,\n { collection, locale, req = {} as PayloadRequest, where },\n) {\n const VersionsModel = this.versions[collection]\n\n const session = await getSession(this, req)\n\n const query = await VersionsModel.buildQuery({\n locale,\n payload: this.payload,\n session,\n where,\n })\n\n await VersionsModel.collection.deleteMany(query, {\n session,\n })\n}\n"],"names":["getSession","deleteVersions","collection","locale","req","where","VersionsModel","versions","session","query","buildQuery","payload","deleteMany"],"mappings":"AAIA,SAASA,UAAU,QAAQ,kBAAiB;AAE5C,OAAO,MAAMC,iBAAiC,eAAeA,eAE3D,EAAEC,UAAU,EAAEC,MAAM,EAAEC,MAAM,CAAC,CAAmB,EAAEC,KAAK,EAAE;IAEzD,MAAMC,gBAAgB,IAAI,CAACC,QAAQ,CAACL,WAAW;IAE/C,MAAMM,UAAU,MAAMR,WAAW,IAAI,EAAEI;IAEvC,MAAMK,QAAQ,MAAMH,cAAcI,UAAU,CAAC;QAC3CP;QACAQ,SAAS,IAAI,CAACA,OAAO;QACrBH;QACAH;IACF;IAEA,MAAMC,cAAcJ,UAAU,CAACU,UAAU,CAACH,OAAO;QAC/CD;IACF;AACF,EAAC"}
1
+ {"version":3,"sources":["../src/deleteVersions.ts"],"sourcesContent":["import type { DeleteVersions, PayloadRequest } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { withSession } from './withSession.js'\n\nexport const deleteVersions: DeleteVersions = async function deleteVersions(\n this: MongooseAdapter,\n { collection, locale, req = {} as PayloadRequest, where },\n) {\n const VersionsModel = this.versions[collection]\n const options = {\n ...(await withSession(this, req)),\n lean: true,\n }\n\n const query = await VersionsModel.buildQuery({\n locale,\n payload: this.payload,\n where,\n })\n\n await VersionsModel.deleteMany(query, options)\n}\n"],"names":["withSession","deleteVersions","collection","locale","req","where","VersionsModel","versions","options","lean","query","buildQuery","payload","deleteMany"],"mappings":"AAIA,SAASA,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,iBAAiC,eAAeA,eAE3D,EAAEC,UAAU,EAAEC,MAAM,EAAEC,MAAM,CAAC,CAAmB,EAAEC,KAAK,EAAE;IAEzD,MAAMC,gBAAgB,IAAI,CAACC,QAAQ,CAACL,WAAW;IAC/C,MAAMM,UAAU;QACd,GAAI,MAAMR,YAAY,IAAI,EAAEI,IAAI;QAChCK,MAAM;IACR;IAEA,MAAMC,QAAQ,MAAMJ,cAAcK,UAAU,CAAC;QAC3CR;QACAS,SAAS,IAAI,CAACA,OAAO;QACrBP;IACF;IAEA,MAAMC,cAAcO,UAAU,CAACH,OAAOF;AACxC,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"find.d.ts","sourceRoot":"","sources":["../src/find.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAkB,MAAM,SAAS,CAAA;AAYnD,eAAO,MAAM,IAAI,EAAE,IAoFlB,CAAA"}
1
+ {"version":3,"file":"find.d.ts","sourceRoot":"","sources":["../src/find.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAkB,MAAM,SAAS,CAAA;AAYnD,eAAO,MAAM,IAAI,EAAE,IA6HlB,CAAA"}
package/dist/find.js CHANGED
@@ -1,21 +1,23 @@
1
- import { getSession } from './getSession.js';
1
+ import { flattenWhereToOperators } from 'payload';
2
2
  import { buildSortParam } from './queries/buildSortParam.js';
3
3
  import { buildJoinAggregation } from './utilities/buildJoinAggregation.js';
4
4
  import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
5
- import { findMany } from './utilities/findMany.js';
6
- import { getHasNearConstraint } from './utilities/getHasNearConstraint.js';
7
- import { transform } from './utilities/transform.js';
8
- export const find = async function find({ collection, joins = {}, limit = 0, locale, page, pagination, req = {}, select, sort: sortArg, where }) {
5
+ import { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js';
6
+ import { withSession } from './withSession.js';
7
+ export const find = async function find({ collection, joins = {}, limit = 0, locale, page, pagination, projection, req = {}, select, sort: sortArg, where }) {
9
8
  const Model = this.collections[collection];
10
9
  const collectionConfig = this.payload.collections[collection].config;
11
- const session = await getSession(this, req);
12
- const hasNearConstraint = getHasNearConstraint(where);
13
- const fields = collectionConfig.flattenedFields;
10
+ const options = await withSession(this, req);
11
+ let hasNearConstraint = false;
12
+ if (where) {
13
+ const constraints = flattenWhereToOperators(where);
14
+ hasNearConstraint = constraints.some((prop)=>Object.keys(prop).some((key)=>key === 'near'));
15
+ }
14
16
  let sort;
15
17
  if (!hasNearConstraint) {
16
18
  sort = buildSortParam({
17
19
  config: this.payload.config,
18
- fields,
20
+ fields: collectionConfig.flattenedFields,
19
21
  locale,
20
22
  sort: sortArg || collectionConfig.defaultSort,
21
23
  timestamps: true
@@ -24,49 +26,80 @@ export const find = async function find({ collection, joins = {}, limit = 0, loc
24
26
  const query = await Model.buildQuery({
25
27
  locale,
26
28
  payload: this.payload,
27
- session,
28
29
  where
29
30
  });
30
31
  // useEstimatedCount is faster, but not accurate, as it ignores any filters. It is thus set to true if there are no filters.
31
32
  const useEstimatedCount = hasNearConstraint || !query || Object.keys(query).length === 0;
32
- const projection = buildProjectionFromSelect({
33
- adapter: this,
34
- fields,
35
- select
36
- });
37
- const collation = this.collation ? {
38
- locale: locale && locale !== 'all' && locale !== '*' ? locale : 'en',
39
- ...this.collation
40
- } : undefined;
41
- const joinAgreggation = await buildJoinAggregation({
42
- adapter: this,
43
- collection,
44
- collectionConfig,
45
- joins,
46
- locale,
47
- session
48
- });
49
- const result = await findMany({
50
- adapter: this,
51
- collation,
52
- collection: Model.collection,
53
- joinAgreggation,
54
- limit,
33
+ const paginationOptions = {
34
+ lean: true,
35
+ leanWithId: true,
36
+ options,
55
37
  page,
56
38
  pagination,
57
39
  projection,
58
- query,
59
- session,
60
40
  sort,
61
41
  useEstimatedCount
62
- });
63
- transform({
42
+ };
43
+ if (select) {
44
+ paginationOptions.projection = buildProjectionFromSelect({
45
+ adapter: this,
46
+ fields: collectionConfig.flattenedFields,
47
+ select
48
+ });
49
+ }
50
+ if (this.collation) {
51
+ const defaultLocale = 'en';
52
+ paginationOptions.collation = {
53
+ locale: locale && locale !== 'all' && locale !== '*' ? locale : defaultLocale,
54
+ ...this.collation
55
+ };
56
+ }
57
+ if (!useEstimatedCount && Object.keys(query).length === 0 && this.disableIndexHints !== true) {
58
+ // Improve the performance of the countDocuments query which is used if useEstimatedCount is set to false by adding
59
+ // a hint. By default, if no hint is provided, MongoDB does not use an indexed field to count the returned documents,
60
+ // which makes queries very slow. This only happens when no query (filter) is provided. If one is provided, it uses
61
+ // the correct indexed field
62
+ paginationOptions.useCustomCountFn = ()=>{
63
+ return Promise.resolve(Model.countDocuments(query, {
64
+ ...options,
65
+ hint: {
66
+ _id: 1
67
+ }
68
+ }));
69
+ };
70
+ }
71
+ if (limit >= 0) {
72
+ paginationOptions.limit = limit;
73
+ // limit must also be set here, it's ignored when pagination is false
74
+ paginationOptions.options.limit = limit;
75
+ // Disable pagination if limit is 0
76
+ if (limit === 0) {
77
+ paginationOptions.pagination = false;
78
+ }
79
+ }
80
+ let result;
81
+ const aggregate = await buildJoinAggregation({
64
82
  adapter: this,
65
- data: result.docs,
66
- fields,
67
- operation: 'read'
83
+ collection,
84
+ collectionConfig,
85
+ joins,
86
+ locale,
87
+ query
68
88
  });
69
- return result;
89
+ // build join aggregation
90
+ if (aggregate) {
91
+ result = await Model.aggregatePaginate(Model.aggregate(aggregate), paginationOptions);
92
+ } else {
93
+ result = await Model.paginate(query, paginationOptions);
94
+ }
95
+ const docs = JSON.parse(JSON.stringify(result.docs));
96
+ return {
97
+ ...result,
98
+ docs: docs.map((doc)=>{
99
+ doc.id = doc._id;
100
+ return sanitizeInternalFields(doc);
101
+ })
102
+ };
70
103
  };
71
104
 
72
105
  //# sourceMappingURL=find.js.map
package/dist/find.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/find.ts"],"sourcesContent":["import type { CollationOptions } from 'mongodb'\nimport type { Find, PayloadRequest } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { getSession } from './getSession.js'\nimport { buildSortParam } from './queries/buildSortParam.js'\nimport { buildJoinAggregation } from './utilities/buildJoinAggregation.js'\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { findMany } from './utilities/findMany.js'\nimport { getHasNearConstraint } from './utilities/getHasNearConstraint.js'\nimport { transform } from './utilities/transform.js'\n\nexport const find: Find = async function find(\n this: MongooseAdapter,\n {\n collection,\n joins = {},\n limit = 0,\n locale,\n page,\n pagination,\n req = {} as PayloadRequest,\n select,\n sort: sortArg,\n where,\n },\n) {\n const Model = this.collections[collection]\n const collectionConfig = this.payload.collections[collection].config\n const session = await getSession(this, req)\n\n const hasNearConstraint = getHasNearConstraint(where)\n\n const fields = collectionConfig.flattenedFields\n\n let sort\n if (!hasNearConstraint) {\n sort = buildSortParam({\n config: this.payload.config,\n fields,\n locale,\n sort: sortArg || collectionConfig.defaultSort,\n timestamps: true,\n })\n }\n\n const query = await Model.buildQuery({\n locale,\n payload: this.payload,\n session,\n where,\n })\n\n // useEstimatedCount is faster, but not accurate, as it ignores any filters. It is thus set to true if there are no filters.\n const useEstimatedCount = hasNearConstraint || !query || Object.keys(query).length === 0\n\n const projection = buildProjectionFromSelect({\n adapter: this,\n fields,\n select,\n })\n\n const collation: CollationOptions | undefined = this.collation\n ? {\n locale: locale && locale !== 'all' && locale !== '*' ? locale : 'en',\n ...this.collation,\n }\n : undefined\n\n const joinAgreggation = await buildJoinAggregation({\n adapter: this,\n collection,\n collectionConfig,\n joins,\n locale,\n session,\n })\n\n const result = await findMany({\n adapter: this,\n collation,\n collection: Model.collection,\n joinAgreggation,\n limit,\n page,\n pagination,\n projection,\n query,\n session,\n sort,\n useEstimatedCount,\n })\n\n transform({ adapter: this, data: result.docs, fields, operation: 'read' })\n\n return result\n}\n"],"names":["getSession","buildSortParam","buildJoinAggregation","buildProjectionFromSelect","findMany","getHasNearConstraint","transform","find","collection","joins","limit","locale","page","pagination","req","select","sort","sortArg","where","Model","collections","collectionConfig","payload","config","session","hasNearConstraint","fields","flattenedFields","defaultSort","timestamps","query","buildQuery","useEstimatedCount","Object","keys","length","projection","adapter","collation","undefined","joinAgreggation","result","data","docs","operation"],"mappings":"AAKA,SAASA,UAAU,QAAQ,kBAAiB;AAC5C,SAASC,cAAc,QAAQ,8BAA6B;AAC5D,SAASC,oBAAoB,QAAQ,sCAAqC;AAC1E,SAASC,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,QAAQ,QAAQ,0BAAyB;AAClD,SAASC,oBAAoB,QAAQ,sCAAqC;AAC1E,SAASC,SAAS,QAAQ,2BAA0B;AAEpD,OAAO,MAAMC,OAAa,eAAeA,KAEvC,EACEC,UAAU,EACVC,QAAQ,CAAC,CAAC,EACVC,QAAQ,CAAC,EACTC,MAAM,EACNC,IAAI,EACJC,UAAU,EACVC,MAAM,CAAC,CAAmB,EAC1BC,MAAM,EACNC,MAAMC,OAAO,EACbC,KAAK,EACN;IAED,MAAMC,QAAQ,IAAI,CAACC,WAAW,CAACZ,WAAW;IAC1C,MAAMa,mBAAmB,IAAI,CAACC,OAAO,CAACF,WAAW,CAACZ,WAAW,CAACe,MAAM;IACpE,MAAMC,UAAU,MAAMxB,WAAW,IAAI,EAAEc;IAEvC,MAAMW,oBAAoBpB,qBAAqBa;IAE/C,MAAMQ,SAASL,iBAAiBM,eAAe;IAE/C,IAAIX;IACJ,IAAI,CAACS,mBAAmB;QACtBT,OAAOf,eAAe;YACpBsB,QAAQ,IAAI,CAACD,OAAO,CAACC,MAAM;YAC3BG;YACAf;YACAK,MAAMC,WAAWI,iBAAiBO,WAAW;YAC7CC,YAAY;QACd;IACF;IAEA,MAAMC,QAAQ,MAAMX,MAAMY,UAAU,CAAC;QACnCpB;QACAW,SAAS,IAAI,CAACA,OAAO;QACrBE;QACAN;IACF;IAEA,4HAA4H;IAC5H,MAAMc,oBAAoBP,qBAAqB,CAACK,SAASG,OAAOC,IAAI,CAACJ,OAAOK,MAAM,KAAK;IAEvF,MAAMC,aAAajC,0BAA0B;QAC3CkC,SAAS,IAAI;QACbX;QACAX;IACF;IAEA,MAAMuB,YAA0C,IAAI,CAACA,SAAS,GAC1D;QACE3B,QAAQA,UAAUA,WAAW,SAASA,WAAW,MAAMA,SAAS;QAChE,GAAG,IAAI,CAAC2B,SAAS;IACnB,IACAC;IAEJ,MAAMC,kBAAkB,MAAMtC,qBAAqB;QACjDmC,SAAS,IAAI;QACb7B;QACAa;QACAZ;QACAE;QACAa;IACF;IAEA,MAAMiB,SAAS,MAAMrC,SAAS;QAC5BiC,SAAS,IAAI;QACbC;QACA9B,YAAYW,MAAMX,UAAU;QAC5BgC;QACA9B;QACAE;QACAC;QACAuB;QACAN;QACAN;QACAR;QACAgB;IACF;IAEA1B,UAAU;QAAE+B,SAAS,IAAI;QAAEK,MAAMD,OAAOE,IAAI;QAAEjB;QAAQkB,WAAW;IAAO;IAExE,OAAOH;AACT,EAAC"}
1
+ {"version":3,"sources":["../src/find.ts"],"sourcesContent":["import type { PaginateOptions } from 'mongoose'\nimport type { Find, PayloadRequest } from 'payload'\n\nimport { flattenWhereToOperators } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildSortParam } from './queries/buildSortParam.js'\nimport { buildJoinAggregation } from './utilities/buildJoinAggregation.js'\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js'\nimport { withSession } from './withSession.js'\n\nexport const find: Find = async function find(\n this: MongooseAdapter,\n {\n collection,\n joins = {},\n limit = 0,\n locale,\n page,\n pagination,\n projection,\n req = {} as PayloadRequest,\n select,\n sort: sortArg,\n where,\n },\n) {\n const Model = this.collections[collection]\n const collectionConfig = this.payload.collections[collection].config\n const options = await withSession(this, req)\n\n let hasNearConstraint = false\n\n if (where) {\n const constraints = flattenWhereToOperators(where)\n hasNearConstraint = constraints.some((prop) => Object.keys(prop).some((key) => key === 'near'))\n }\n\n let sort\n if (!hasNearConstraint) {\n sort = buildSortParam({\n config: this.payload.config,\n fields: collectionConfig.flattenedFields,\n locale,\n sort: sortArg || collectionConfig.defaultSort,\n timestamps: true,\n })\n }\n\n const query = await Model.buildQuery({\n locale,\n payload: this.payload,\n where,\n })\n\n // useEstimatedCount is faster, but not accurate, as it ignores any filters. It is thus set to true if there are no filters.\n const useEstimatedCount = hasNearConstraint || !query || Object.keys(query).length === 0\n const paginationOptions: PaginateOptions = {\n lean: true,\n leanWithId: true,\n options,\n page,\n pagination,\n projection,\n sort,\n useEstimatedCount,\n }\n\n if (select) {\n paginationOptions.projection = buildProjectionFromSelect({\n adapter: this,\n fields: collectionConfig.flattenedFields,\n select,\n })\n }\n\n if (this.collation) {\n const defaultLocale = 'en'\n paginationOptions.collation = {\n locale: locale && locale !== 'all' && locale !== '*' ? locale : defaultLocale,\n ...this.collation,\n }\n }\n\n if (!useEstimatedCount && Object.keys(query).length === 0 && this.disableIndexHints !== true) {\n // Improve the performance of the countDocuments query which is used if useEstimatedCount is set to false by adding\n // a hint. By default, if no hint is provided, MongoDB does not use an indexed field to count the returned documents,\n // which makes queries very slow. This only happens when no query (filter) is provided. If one is provided, it uses\n // the correct indexed field\n paginationOptions.useCustomCountFn = () => {\n return Promise.resolve(\n Model.countDocuments(query, {\n ...options,\n hint: { _id: 1 },\n }),\n )\n }\n }\n\n if (limit >= 0) {\n paginationOptions.limit = limit\n // limit must also be set here, it's ignored when pagination is false\n paginationOptions.options.limit = limit\n\n // Disable pagination if limit is 0\n if (limit === 0) {\n paginationOptions.pagination = false\n }\n }\n\n let result\n\n const aggregate = await buildJoinAggregation({\n adapter: this,\n collection,\n collectionConfig,\n joins,\n locale,\n query,\n })\n // build join aggregation\n if (aggregate) {\n result = await Model.aggregatePaginate(Model.aggregate(aggregate), paginationOptions)\n } else {\n result = await Model.paginate(query, paginationOptions)\n }\n\n const docs = JSON.parse(JSON.stringify(result.docs))\n\n return {\n ...result,\n docs: docs.map((doc) => {\n doc.id = doc._id\n return sanitizeInternalFields(doc)\n }),\n }\n}\n"],"names":["flattenWhereToOperators","buildSortParam","buildJoinAggregation","buildProjectionFromSelect","sanitizeInternalFields","withSession","find","collection","joins","limit","locale","page","pagination","projection","req","select","sort","sortArg","where","Model","collections","collectionConfig","payload","config","options","hasNearConstraint","constraints","some","prop","Object","keys","key","fields","flattenedFields","defaultSort","timestamps","query","buildQuery","useEstimatedCount","length","paginationOptions","lean","leanWithId","adapter","collation","defaultLocale","disableIndexHints","useCustomCountFn","Promise","resolve","countDocuments","hint","_id","result","aggregate","aggregatePaginate","paginate","docs","JSON","parse","stringify","map","doc","id"],"mappings":"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"}
@@ -1 +1 @@
1
- {"version":3,"file":"findGlobal.d.ts","sourceRoot":"","sources":["../src/findGlobal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAkB,MAAM,SAAS,CAAA;AAUzD,eAAO,MAAM,UAAU,EAAE,UAkCxB,CAAA"}
1
+ {"version":3,"file":"findGlobal.d.ts","sourceRoot":"","sources":["../src/findGlobal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAkB,MAAM,SAAS,CAAA;AAUzD,eAAO,MAAM,UAAU,EAAE,UAoCxB,CAAA"}
@@ -1,39 +1,38 @@
1
1
  import { combineQueries } from 'payload';
2
- import { getSession } from './getSession.js';
3
2
  import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
4
- import { transform } from './utilities/transform.js';
3
+ import { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js';
4
+ import { withSession } from './withSession.js';
5
5
  export const findGlobal = async function findGlobal({ slug, locale, req = {}, select, where }) {
6
6
  const Model = this.globals;
7
- const session = await getSession(this, req);
7
+ const options = {
8
+ ...await withSession(this, req),
9
+ lean: true,
10
+ select: buildProjectionFromSelect({
11
+ adapter: this,
12
+ fields: this.payload.globals.config.find((each)=>each.slug === slug).flattenedFields,
13
+ select
14
+ })
15
+ };
8
16
  const query = await Model.buildQuery({
9
17
  globalSlug: slug,
10
18
  locale,
11
19
  payload: this.payload,
12
- session,
13
20
  where: combineQueries({
14
21
  globalType: {
15
22
  equals: slug
16
23
  }
17
24
  }, where)
18
25
  });
19
- const fields = this.payload.globals.config.find((each)=>each.slug === slug).flattenedFields;
20
- const doc = await Model.collection.findOne(query, {
21
- projection: buildProjectionFromSelect({
22
- adapter: this,
23
- fields,
24
- select
25
- }),
26
- session: await getSession(this, req)
27
- });
26
+ let doc = await Model.findOne(query, {}, options);
28
27
  if (!doc) {
29
28
  return null;
30
29
  }
31
- transform({
32
- adapter: this,
33
- data: doc,
34
- fields,
35
- operation: 'read'
36
- });
30
+ if (doc._id) {
31
+ doc.id = doc._id;
32
+ delete doc._id;
33
+ }
34
+ doc = JSON.parse(JSON.stringify(doc));
35
+ doc = sanitizeInternalFields(doc);
37
36
  return doc;
38
37
  };
39
38
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/findGlobal.ts"],"sourcesContent":["import type { FindGlobal, PayloadRequest } from 'payload'\n\nimport { combineQueries } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { getSession } from './getSession.js'\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { transform } from './utilities/transform.js'\n\nexport const findGlobal: FindGlobal = async function findGlobal(\n this: MongooseAdapter,\n { slug, locale, req = {} as PayloadRequest, select, where },\n) {\n const Model = this.globals\n\n const session = await getSession(this, req)\n\n const query = await Model.buildQuery({\n globalSlug: slug,\n locale,\n payload: this.payload,\n session,\n where: combineQueries({ globalType: { equals: slug } }, where),\n })\n\n const fields = this.payload.globals.config.find((each) => each.slug === slug).flattenedFields\n\n const doc = await Model.collection.findOne(query, {\n projection: buildProjectionFromSelect({\n adapter: this,\n fields,\n select,\n }),\n session: await getSession(this, req),\n })\n\n if (!doc) {\n return null\n }\n\n transform({ adapter: this, data: doc, fields, operation: 'read' })\n\n return doc as any\n}\n"],"names":["combineQueries","getSession","buildProjectionFromSelect","transform","findGlobal","slug","locale","req","select","where","Model","globals","session","query","buildQuery","globalSlug","payload","globalType","equals","fields","config","find","each","flattenedFields","doc","collection","findOne","projection","adapter","data","operation"],"mappings":"AAEA,SAASA,cAAc,QAAQ,UAAS;AAIxC,SAASC,UAAU,QAAQ,kBAAiB;AAC5C,SAASC,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,SAAS,QAAQ,2BAA0B;AAEpD,OAAO,MAAMC,aAAyB,eAAeA,WAEnD,EAAEC,IAAI,EAAEC,MAAM,EAAEC,MAAM,CAAC,CAAmB,EAAEC,MAAM,EAAEC,KAAK,EAAE;IAE3D,MAAMC,QAAQ,IAAI,CAACC,OAAO;IAE1B,MAAMC,UAAU,MAAMX,WAAW,IAAI,EAAEM;IAEvC,MAAMM,QAAQ,MAAMH,MAAMI,UAAU,CAAC;QACnCC,YAAYV;QACZC;QACAU,SAAS,IAAI,CAACA,OAAO;QACrBJ;QACAH,OAAOT,eAAe;YAAEiB,YAAY;gBAAEC,QAAQb;YAAK;QAAE,GAAGI;IAC1D;IAEA,MAAMU,SAAS,IAAI,CAACH,OAAO,CAACL,OAAO,CAACS,MAAM,CAACC,IAAI,CAAC,CAACC,OAASA,KAAKjB,IAAI,KAAKA,MAAMkB,eAAe;IAE7F,MAAMC,MAAM,MAAMd,MAAMe,UAAU,CAACC,OAAO,CAACb,OAAO;QAChDc,YAAYzB,0BAA0B;YACpC0B,SAAS,IAAI;YACbT;YACAX;QACF;QACAI,SAAS,MAAMX,WAAW,IAAI,EAAEM;IAClC;IAEA,IAAI,CAACiB,KAAK;QACR,OAAO;IACT;IAEArB,UAAU;QAAEyB,SAAS,IAAI;QAAEC,MAAML;QAAKL;QAAQW,WAAW;IAAO;IAEhE,OAAON;AACT,EAAC"}
1
+ {"version":3,"sources":["../src/findGlobal.ts"],"sourcesContent":["import type { FindGlobal, PayloadRequest } from 'payload'\n\nimport { combineQueries } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js'\nimport { withSession } from './withSession.js'\n\nexport const findGlobal: FindGlobal = async function findGlobal(\n this: MongooseAdapter,\n { slug, locale, req = {} as PayloadRequest, select, where },\n) {\n const Model = this.globals\n const options = {\n ...(await withSession(this, req)),\n lean: true,\n select: buildProjectionFromSelect({\n adapter: this,\n fields: this.payload.globals.config.find((each) => each.slug === slug).flattenedFields,\n select,\n }),\n }\n\n const query = await Model.buildQuery({\n globalSlug: slug,\n locale,\n payload: this.payload,\n where: combineQueries({ globalType: { equals: slug } }, where),\n })\n\n let doc = (await Model.findOne(query, {}, options)) as any\n\n if (!doc) {\n return null\n }\n if (doc._id) {\n doc.id = doc._id\n delete doc._id\n }\n\n doc = JSON.parse(JSON.stringify(doc))\n doc = sanitizeInternalFields(doc)\n\n return doc\n}\n"],"names":["combineQueries","buildProjectionFromSelect","sanitizeInternalFields","withSession","findGlobal","slug","locale","req","select","where","Model","globals","options","lean","adapter","fields","payload","config","find","each","flattenedFields","query","buildQuery","globalSlug","globalType","equals","doc","findOne","_id","id","JSON","parse","stringify"],"mappings":"AAEA,SAASA,cAAc,QAAQ,UAAS;AAIxC,SAASC,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,sBAAsB,QAAQ,wCAAuC;AAC9E,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,aAAyB,eAAeA,WAEnD,EAAEC,IAAI,EAAEC,MAAM,EAAEC,MAAM,CAAC,CAAmB,EAAEC,MAAM,EAAEC,KAAK,EAAE;IAE3D,MAAMC,QAAQ,IAAI,CAACC,OAAO;IAC1B,MAAMC,UAAU;QACd,GAAI,MAAMT,YAAY,IAAI,EAAEI,IAAI;QAChCM,MAAM;QACNL,QAAQP,0BAA0B;YAChCa,SAAS,IAAI;YACbC,QAAQ,IAAI,CAACC,OAAO,CAACL,OAAO,CAACM,MAAM,CAACC,IAAI,CAAC,CAACC,OAASA,KAAKd,IAAI,KAAKA,MAAMe,eAAe;YACtFZ;QACF;IACF;IAEA,MAAMa,QAAQ,MAAMX,MAAMY,UAAU,CAAC;QACnCC,YAAYlB;QACZC;QACAU,SAAS,IAAI,CAACA,OAAO;QACrBP,OAAOT,eAAe;YAAEwB,YAAY;gBAAEC,QAAQpB;YAAK;QAAE,GAAGI;IAC1D;IAEA,IAAIiB,MAAO,MAAMhB,MAAMiB,OAAO,CAACN,OAAO,CAAC,GAAGT;IAE1C,IAAI,CAACc,KAAK;QACR,OAAO;IACT;IACA,IAAIA,IAAIE,GAAG,EAAE;QACXF,IAAIG,EAAE,GAAGH,IAAIE,GAAG;QAChB,OAAOF,IAAIE,GAAG;IAChB;IAEAF,MAAMI,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACN;IAChCA,MAAMxB,uBAAuBwB;IAE7B,OAAOA;AACT,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"findGlobalVersions.d.ts","sourceRoot":"","sources":["../src/findGlobalVersions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAkB,MAAM,SAAS,CAAA;AAajE,eAAO,MAAM,kBAAkB,EAAE,kBAgFhC,CAAA"}
1
+ {"version":3,"file":"findGlobalVersions.d.ts","sourceRoot":"","sources":["../src/findGlobalVersions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAkB,MAAM,SAAS,CAAA;AAWjE,eAAO,MAAM,kBAAkB,EAAE,kBA8GhC,CAAA"}