@payloadcms/db-mongodb 3.2.2-canary.a11698b → 3.2.2-canary.d2399ed

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 +19 -21
  3. package/dist/count.js.map +1 -1
  4. package/dist/countGlobalVersions.d.ts.map +1 -1
  5. package/dist/countGlobalVersions.js +19 -21
  6. package/dist/countGlobalVersions.js.map +1 -1
  7. package/dist/countVersions.d.ts.map +1 -1
  8. package/dist/countVersions.js +19 -21
  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 +21 -19
  15. package/dist/createGlobal.js.map +1 -1
  16. package/dist/createGlobalVersion.d.ts.map +1 -1
  17. package/dist/createGlobalVersion.js +35 -30
  18. package/dist/createGlobalVersion.js.map +1 -1
  19. package/dist/createVersion.d.ts.map +1 -1
  20. package/dist/createVersion.js +35 -30
  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 +17 -13
  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 +41 -74
  33. package/dist/find.js.map +1 -1
  34. package/dist/findGlobal.d.ts.map +1 -1
  35. package/dist/findGlobal.js +19 -18
  36. package/dist/findGlobal.js.map +1 -1
  37. package/dist/findGlobalVersions.d.ts.map +1 -1
  38. package/dist/findGlobalVersions.js +33 -62
  39. package/dist/findGlobalVersions.js.map +1 -1
  40. package/dist/findOne.d.ts.map +1 -1
  41. package/dist/findOne.js +32 -19
  42. package/dist/findOne.js.map +1 -1
  43. package/dist/findVersions.d.ts.map +1 -1
  44. package/dist/findVersions.js +34 -62
  45. package/dist/findVersions.js.map +1 -1
  46. package/dist/{withSession.d.ts → getSession.d.ts} +2 -4
  47. package/dist/getSession.d.ts.map +1 -0
  48. package/dist/{withSession.js → getSession.js} +3 -5
  49. package/dist/getSession.js.map +1 -0
  50. package/dist/predefinedMigrations/migrateRelationshipsV2_V3.d.ts.map +1 -1
  51. package/dist/predefinedMigrations/migrateRelationshipsV2_V3.js +20 -16
  52. package/dist/predefinedMigrations/migrateRelationshipsV2_V3.js.map +1 -1
  53. package/dist/predefinedMigrations/migrateVersionsV1_V2.js +2 -2
  54. package/dist/predefinedMigrations/migrateVersionsV1_V2.js.map +1 -1
  55. package/dist/queries/buildAndOrConditions.d.ts +3 -1
  56. package/dist/queries/buildAndOrConditions.d.ts.map +1 -1
  57. package/dist/queries/buildAndOrConditions.js +2 -1
  58. package/dist/queries/buildAndOrConditions.js.map +1 -1
  59. package/dist/queries/buildQuery.d.ts +2 -0
  60. package/dist/queries/buildQuery.d.ts.map +1 -1
  61. package/dist/queries/buildQuery.js +2 -6
  62. package/dist/queries/buildQuery.js.map +1 -1
  63. package/dist/queries/buildSearchParams.d.ts +3 -1
  64. package/dist/queries/buildSearchParams.d.ts.map +1 -1
  65. package/dist/queries/buildSearchParams.js +14 -10
  66. package/dist/queries/buildSearchParams.js.map +1 -1
  67. package/dist/queries/buildSortParam.d.ts +1 -7
  68. package/dist/queries/buildSortParam.d.ts.map +1 -1
  69. package/dist/queries/buildSortParam.js +2 -2
  70. package/dist/queries/buildSortParam.js.map +1 -1
  71. package/dist/queries/getLocalizedSortProperty.js +2 -2
  72. package/dist/queries/getLocalizedSortProperty.js.map +1 -1
  73. package/dist/queries/parseParams.d.ts +3 -1
  74. package/dist/queries/parseParams.d.ts.map +1 -1
  75. package/dist/queries/parseParams.js +2 -1
  76. package/dist/queries/parseParams.js.map +1 -1
  77. package/dist/queries/sanitizeQueryValue.d.ts.map +1 -1
  78. package/dist/queries/sanitizeQueryValue.js +16 -0
  79. package/dist/queries/sanitizeQueryValue.js.map +1 -1
  80. package/dist/queryDrafts.d.ts.map +1 -1
  81. package/dist/queryDrafts.js +41 -65
  82. package/dist/queryDrafts.js.map +1 -1
  83. package/dist/updateGlobal.d.ts.map +1 -1
  84. package/dist/updateGlobal.js +25 -23
  85. package/dist/updateGlobal.js.map +1 -1
  86. package/dist/updateGlobalVersion.d.ts.map +1 -1
  87. package/dist/updateGlobalVersion.js +28 -27
  88. package/dist/updateGlobalVersion.js.map +1 -1
  89. package/dist/updateOne.d.ts.map +1 -1
  90. package/dist/updateOne.js +28 -24
  91. package/dist/updateOne.js.map +1 -1
  92. package/dist/updateVersion.d.ts.map +1 -1
  93. package/dist/updateVersion.js +28 -26
  94. package/dist/updateVersion.js.map +1 -1
  95. package/dist/utilities/buildJoinAggregation.d.ts +4 -4
  96. package/dist/utilities/buildJoinAggregation.d.ts.map +1 -1
  97. package/dist/utilities/buildJoinAggregation.js +7 -28
  98. package/dist/utilities/buildJoinAggregation.js.map +1 -1
  99. package/dist/utilities/buildProjectionFromSelect.d.ts.map +1 -1
  100. package/dist/utilities/buildProjectionFromSelect.js +18 -1
  101. package/dist/utilities/buildProjectionFromSelect.js.map +1 -1
  102. package/dist/utilities/findMany.d.ts +20 -0
  103. package/dist/utilities/findMany.d.ts.map +1 -0
  104. package/dist/utilities/findMany.js +84 -0
  105. package/dist/utilities/findMany.js.map +1 -0
  106. package/dist/utilities/getHasNearConstraint.d.ts +3 -0
  107. package/dist/utilities/getHasNearConstraint.d.ts.map +1 -0
  108. package/dist/utilities/getHasNearConstraint.js +26 -0
  109. package/dist/utilities/getHasNearConstraint.js.map +1 -0
  110. package/dist/utilities/transform.d.ts +17 -0
  111. package/dist/utilities/transform.d.ts.map +1 -0
  112. package/dist/utilities/transform.js +250 -0
  113. package/dist/utilities/transform.js.map +1 -0
  114. package/dist/utilities/{sanitizeRelationshipIDs.spec.js → transform.spec.js} +23 -7
  115. package/dist/utilities/transform.spec.js.map +1 -0
  116. package/package.json +3 -3
  117. package/dist/utilities/sanitizeInternalFields.d.ts +0 -2
  118. package/dist/utilities/sanitizeInternalFields.d.ts.map +0 -1
  119. package/dist/utilities/sanitizeInternalFields.js +0 -20
  120. package/dist/utilities/sanitizeInternalFields.js.map +0 -1
  121. package/dist/utilities/sanitizeRelationshipIDs.d.ts +0 -9
  122. package/dist/utilities/sanitizeRelationshipIDs.d.ts.map +0 -1
  123. package/dist/utilities/sanitizeRelationshipIDs.js +0 -125
  124. package/dist/utilities/sanitizeRelationshipIDs.js.map +0 -1
  125. package/dist/utilities/sanitizeRelationshipIDs.spec.js.map +0 -1
  126. package/dist/withSession.d.ts.map +0 -1
  127. package/dist/withSession.js.map +0 -1
@@ -1,27 +1,31 @@
1
1
  import { Types } from 'mongoose';
2
2
  import { buildVersionCollectionFields } from 'payload';
3
- import { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.js';
4
- import { withSession } from './withSession.js';
3
+ import { getSession } from './getSession.js';
4
+ import { transform } from './utilities/transform.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 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)
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
21
27
  });
22
- const [doc] = await VersionModel.create([
23
- data
24
- ], options, req);
28
+ data._id = insertedId;
25
29
  const parentQuery = {
26
30
  $or: [
27
31
  {
@@ -38,11 +42,11 @@ export const createVersion = async function createVersion({ autosave, collection
38
42
  }
39
43
  });
40
44
  }
41
- await VersionModel.updateMany({
45
+ await VersionModel.collection.updateMany({
42
46
  $and: [
43
47
  {
44
48
  _id: {
45
- $ne: doc._id
49
+ $ne: insertedId
46
50
  }
47
51
  },
48
52
  parentQuery,
@@ -56,15 +60,16 @@ export const createVersion = async function createVersion({ autosave, collection
56
60
  $unset: {
57
61
  latest: 1
58
62
  }
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;
63
+ }, {
64
+ session
65
+ });
66
+ transform({
67
+ adapter: this,
68
+ data,
69
+ fields,
70
+ operation: 'read'
71
+ });
72
+ return data;
68
73
  };
69
74
 
70
75
  //# sourceMappingURL=createVersion.js.map
@@ -1 +1 @@
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
+ {"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 +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,UAgBxB,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,UAiBxB,CAAA"}
@@ -1,15 +1,15 @@
1
- import { withSession } from './withSession.js';
1
+ import { getSession } from './getSession.js';
2
2
  export const deleteMany = async function deleteMany({ collection, req = {}, where }) {
3
3
  const Model = this.collections[collection];
4
- const options = {
5
- ...await withSession(this, req),
6
- lean: true
7
- };
4
+ const session = await getSession(this, req);
8
5
  const query = await Model.buildQuery({
9
6
  payload: this.payload,
7
+ session,
10
8
  where
11
9
  });
12
- await Model.deleteMany(query, options);
10
+ await Model.collection.deleteMany(query, {
11
+ session
12
+ });
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 { 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
+ {"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 +1 @@
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"}
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"}
package/dist/deleteOne.js CHANGED
@@ -1,26 +1,30 @@
1
+ import { getSession } from './getSession.js';
1
2
  import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
2
- import { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js';
3
- import { withSession } from './withSession.js';
3
+ import { transform } from './utilities/transform.js';
4
4
  export const deleteOne = async function deleteOne({ collection, req = {}, select, where }) {
5
5
  const Model = this.collections[collection];
6
- const options = await withSession(this, req);
6
+ const session = await getSession(this, req);
7
7
  const query = await Model.buildQuery({
8
8
  payload: this.payload,
9
+ session,
9
10
  where
10
11
  });
11
- const doc = await Model.findOneAndDelete(query, {
12
- ...options,
12
+ const fields = this.payload.collections[collection].config.flattenedFields;
13
+ const doc = await Model.collection.findOneAndDelete(query, {
13
14
  projection: buildProjectionFromSelect({
14
15
  adapter: this,
15
- fields: this.payload.collections[collection].config.flattenedFields,
16
+ fields,
16
17
  select
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;
18
+ }),
19
+ session
20
+ });
21
+ transform({
22
+ adapter: this,
23
+ data: doc,
24
+ fields,
25
+ operation: 'read'
26
+ });
27
+ return doc;
24
28
  };
25
29
 
26
30
  //# sourceMappingURL=deleteOne.js.map
@@ -1 +1 @@
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
+ {"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 +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,cAiB5B,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,cAkB5B,CAAA"}
@@ -1,16 +1,16 @@
1
- import { withSession } from './withSession.js';
1
+ import { getSession } from './getSession.js';
2
2
  export const deleteVersions = async function deleteVersions({ collection, locale, req = {}, where }) {
3
3
  const VersionsModel = this.versions[collection];
4
- const options = {
5
- ...await withSession(this, req),
6
- lean: true
7
- };
4
+ const session = await getSession(this, req);
8
5
  const query = await VersionsModel.buildQuery({
9
6
  locale,
10
7
  payload: this.payload,
8
+ session,
11
9
  where
12
10
  });
13
- await VersionsModel.deleteMany(query, options);
11
+ await VersionsModel.collection.deleteMany(query, {
12
+ session
13
+ });
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 { 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
+ {"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 +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,IA6HlB,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,IAoFlB,CAAA"}
package/dist/find.js CHANGED
@@ -1,23 +1,21 @@
1
- import { flattenWhereToOperators } from 'payload';
1
+ import { getSession } from './getSession.js';
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 { 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 }) {
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 }) {
8
9
  const Model = this.collections[collection];
9
10
  const collectionConfig = this.payload.collections[collection].config;
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
- }
11
+ const session = await getSession(this, req);
12
+ const hasNearConstraint = getHasNearConstraint(where);
13
+ const fields = collectionConfig.flattenedFields;
16
14
  let sort;
17
15
  if (!hasNearConstraint) {
18
16
  sort = buildSortParam({
19
17
  config: this.payload.config,
20
- fields: collectionConfig.flattenedFields,
18
+ fields,
21
19
  locale,
22
20
  sort: sortArg || collectionConfig.defaultSort,
23
21
  timestamps: true
@@ -26,80 +24,49 @@ export const find = async function find({ collection, joins = {}, limit = 0, loc
26
24
  const query = await Model.buildQuery({
27
25
  locale,
28
26
  payload: this.payload,
27
+ session,
29
28
  where
30
29
  });
31
30
  // useEstimatedCount is faster, but not accurate, as it ignores any filters. It is thus set to true if there are no filters.
32
31
  const useEstimatedCount = hasNearConstraint || !query || Object.keys(query).length === 0;
33
- const paginationOptions = {
34
- lean: true,
35
- leanWithId: true,
36
- options,
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,
37
55
  page,
38
56
  pagination,
39
57
  projection,
58
+ query,
59
+ session,
40
60
  sort,
41
61
  useEstimatedCount
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({
62
+ });
63
+ transform({
82
64
  adapter: this,
83
- collection,
84
- collectionConfig,
85
- joins,
86
- locale,
87
- query
65
+ data: result.docs,
66
+ fields,
67
+ operation: 'read'
88
68
  });
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
- };
69
+ return result;
103
70
  };
104
71
 
105
72
  //# sourceMappingURL=find.js.map
package/dist/find.js.map CHANGED
@@ -1 +1 @@
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
+ {"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 +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,UAoCxB,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,UAkCxB,CAAA"}
@@ -1,38 +1,39 @@
1
1
  import { combineQueries } from 'payload';
2
+ import { getSession } from './getSession.js';
2
3
  import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
3
- import { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js';
4
- import { withSession } from './withSession.js';
4
+ import { transform } from './utilities/transform.js';
5
5
  export const findGlobal = async function findGlobal({ slug, locale, req = {}, select, where }) {
6
6
  const Model = this.globals;
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
- };
7
+ const session = await getSession(this, req);
16
8
  const query = await Model.buildQuery({
17
9
  globalSlug: slug,
18
10
  locale,
19
11
  payload: this.payload,
12
+ session,
20
13
  where: combineQueries({
21
14
  globalType: {
22
15
  equals: slug
23
16
  }
24
17
  }, where)
25
18
  });
26
- let doc = await Model.findOne(query, {}, options);
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
+ });
27
28
  if (!doc) {
28
29
  return null;
29
30
  }
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);
31
+ transform({
32
+ adapter: this,
33
+ data: doc,
34
+ fields,
35
+ operation: 'read'
36
+ });
36
37
  return doc;
37
38
  };
38
39
 
@@ -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 { 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
+ {"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 +1 @@
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"}
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"}