@payloadcms/db-mongodb 3.0.0-canary.8789b0b → 3.0.0-canary.893f1e5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (87) hide show
  1. package/dist/connect.d.ts.map +1 -1
  2. package/dist/connect.js +12 -0
  3. package/dist/connect.js.map +1 -1
  4. package/dist/countGlobalVersions.d.ts +3 -0
  5. package/dist/countGlobalVersions.d.ts.map +1 -0
  6. package/dist/countGlobalVersions.js +33 -0
  7. package/dist/countGlobalVersions.js.map +1 -0
  8. package/dist/countVersions.d.ts +3 -0
  9. package/dist/countVersions.d.ts.map +1 -0
  10. package/dist/countVersions.js +33 -0
  11. package/dist/countVersions.js.map +1 -0
  12. package/dist/create.d.ts.map +1 -1
  13. package/dist/create.js +3 -0
  14. package/dist/create.js.map +1 -1
  15. package/dist/createMigration.d.ts.map +1 -1
  16. package/dist/createMigration.js +6 -4
  17. package/dist/createMigration.js.map +1 -1
  18. package/dist/deleteOne.d.ts.map +1 -1
  19. package/dist/deleteOne.js +10 -2
  20. package/dist/deleteOne.js.map +1 -1
  21. package/dist/find.d.ts.map +1 -1
  22. package/dist/find.js +9 -2
  23. package/dist/find.js.map +1 -1
  24. package/dist/findGlobal.d.ts.map +1 -1
  25. package/dist/findGlobal.js +8 -2
  26. package/dist/findGlobal.js.map +1 -1
  27. package/dist/findGlobalVersions.d.ts.map +1 -1
  28. package/dist/findGlobalVersions.js +7 -1
  29. package/dist/findGlobalVersions.js.map +1 -1
  30. package/dist/findOne.d.ts.map +1 -1
  31. package/dist/findOne.js +9 -1
  32. package/dist/findOne.js.map +1 -1
  33. package/dist/findVersions.d.ts.map +1 -1
  34. package/dist/findVersions.js +8 -2
  35. package/dist/findVersions.js.map +1 -1
  36. package/dist/index.d.ts +8 -1
  37. package/dist/index.d.ts.map +1 -1
  38. package/dist/index.js +7 -2
  39. package/dist/index.js.map +1 -1
  40. package/dist/init.d.ts.map +1 -1
  41. package/dist/init.js +8 -9
  42. package/dist/init.js.map +1 -1
  43. package/dist/models/buildSchema.js +16 -1
  44. package/dist/models/buildSchema.js.map +1 -1
  45. package/dist/queries/buildSearchParams.d.ts.map +1 -1
  46. package/dist/queries/buildSearchParams.js +5 -1
  47. package/dist/queries/buildSearchParams.js.map +1 -1
  48. package/dist/queries/buildSortParam.d.ts +2 -2
  49. package/dist/queries/buildSortParam.d.ts.map +1 -1
  50. package/dist/queries/buildSortParam.js +26 -17
  51. package/dist/queries/buildSortParam.js.map +1 -1
  52. package/dist/queries/sanitizeQueryValue.d.ts.map +1 -1
  53. package/dist/queries/sanitizeQueryValue.js +4 -1
  54. package/dist/queries/sanitizeQueryValue.js.map +1 -1
  55. package/dist/queryDrafts.d.ts.map +1 -1
  56. package/dist/queryDrafts.js +28 -6
  57. package/dist/queryDrafts.js.map +1 -1
  58. package/dist/updateGlobal.d.ts.map +1 -1
  59. package/dist/updateGlobal.js +10 -3
  60. package/dist/updateGlobal.js.map +1 -1
  61. package/dist/updateGlobalVersion.d.ts +1 -1
  62. package/dist/updateGlobalVersion.d.ts.map +1 -1
  63. package/dist/updateGlobalVersion.js +10 -3
  64. package/dist/updateGlobalVersion.js.map +1 -1
  65. package/dist/updateOne.d.ts.map +1 -1
  66. package/dist/updateOne.js +10 -3
  67. package/dist/updateOne.js.map +1 -1
  68. package/dist/updateVersion.d.ts.map +1 -1
  69. package/dist/updateVersion.js +10 -3
  70. package/dist/updateVersion.js.map +1 -1
  71. package/dist/upsert.js +2 -1
  72. package/dist/upsert.js.map +1 -1
  73. package/dist/utilities/buildJoinAggregation.d.ts +4 -1
  74. package/dist/utilities/buildJoinAggregation.d.ts.map +1 -1
  75. package/dist/utilities/buildJoinAggregation.js +20 -9
  76. package/dist/utilities/buildJoinAggregation.js.map +1 -1
  77. package/dist/utilities/buildProjectionFromSelect.d.ts +8 -0
  78. package/dist/utilities/buildProjectionFromSelect.d.ts.map +1 -0
  79. package/dist/utilities/buildProjectionFromSelect.js +171 -0
  80. package/dist/utilities/buildProjectionFromSelect.js.map +1 -0
  81. package/dist/utilities/handleError.js +2 -2
  82. package/dist/utilities/handleError.js.map +1 -1
  83. package/dist/utilities/sanitizeRelationshipIDs.d.ts.map +1 -1
  84. package/dist/utilities/sanitizeRelationshipIDs.js +6 -2
  85. package/dist/utilities/sanitizeRelationshipIDs.js.map +1 -1
  86. package/license.md +22 -0
  87. package/package.json +11 -4
@@ -1 +1 @@
1
- {"version":3,"file":"connect.d.ts","sourceRoot":"","sources":["../src/connect.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAMtC,eAAO,MAAM,OAAO,EAAE,OA8DrB,CAAA"}
1
+ {"version":3,"file":"connect.d.ts","sourceRoot":"","sources":["../src/connect.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAMtC,eAAO,MAAM,OAAO,EAAE,OA6ErB,CAAA"}
package/dist/connect.js CHANGED
@@ -37,6 +37,18 @@ export const connect = async function connect(options = {
37
37
  this.payload.logger.info('---- DROPPED DATABASE ----');
38
38
  }
39
39
  }
40
+ if (this.ensureIndexes) {
41
+ await Promise.all(this.payload.config.collections.map(async (coll)=>{
42
+ await new Promise((resolve, reject)=>{
43
+ this.collections[coll.slug]?.ensureIndexes(function(err) {
44
+ if (err) {
45
+ reject(err);
46
+ }
47
+ resolve(true);
48
+ });
49
+ });
50
+ }));
51
+ }
40
52
  if (process.env.NODE_ENV === 'production' && this.prodMigrations) {
41
53
  await this.migrate({
42
54
  migrations: this.prodMigrations
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/connect.ts"],"sourcesContent":["import type { ConnectOptions } from 'mongoose'\nimport type { Connect } from 'payload'\n\nimport mongoose from 'mongoose'\n\nimport type { MongooseAdapter } from './index.js'\n\nexport const connect: Connect = async function connect(\n this: MongooseAdapter,\n options = {\n hotReload: false,\n },\n) {\n const { hotReload } = options\n\n if (this.url === false) {\n return\n }\n\n if (typeof this.url !== 'string') {\n throw new Error('Error: missing MongoDB connection URL.')\n }\n\n const urlToConnect = this.url\n\n const connectionOptions: { useFacet: undefined } & ConnectOptions = {\n autoIndex: true,\n ...this.connectOptions,\n useFacet: undefined,\n }\n\n if (hotReload) {\n connectionOptions.autoIndex = false\n }\n\n try {\n this.connection = (await mongoose.connect(urlToConnect, connectionOptions)).connection\n\n // If we are running a replica set with MongoDB Memory Server,\n // wait until the replica set elects a primary before proceeding\n if (this.mongoMemoryServer) {\n await new Promise((resolve) => setTimeout(resolve, 2000))\n }\n\n const client = this.connection.getClient()\n\n if (!client.options.replicaSet) {\n this.transactionOptions = false\n this.beginTransaction = undefined\n }\n\n if (!this.mongoMemoryServer && !hotReload) {\n if (process.env.PAYLOAD_DROP_DATABASE === 'true') {\n this.payload.logger.info('---- DROPPING DATABASE ----')\n await mongoose.connection.dropDatabase()\n this.payload.logger.info('---- DROPPED DATABASE ----')\n }\n }\n\n if (process.env.NODE_ENV === 'production' && this.prodMigrations) {\n await this.migrate({ migrations: this.prodMigrations })\n }\n } catch (err) {\n this.payload.logger.error({\n err,\n msg: `Error: cannot connect to MongoDB. Details: ${err.message}`,\n })\n process.exit(1)\n }\n}\n"],"names":["mongoose","connect","options","hotReload","url","Error","urlToConnect","connectionOptions","autoIndex","connectOptions","useFacet","undefined","connection","mongoMemoryServer","Promise","resolve","setTimeout","client","getClient","replicaSet","transactionOptions","beginTransaction","process","env","PAYLOAD_DROP_DATABASE","payload","logger","info","dropDatabase","NODE_ENV","prodMigrations","migrate","migrations","err","error","msg","message","exit"],"mappings":"AAGA,OAAOA,cAAc,WAAU;AAI/B,OAAO,MAAMC,UAAmB,eAAeA,QAE7CC,UAAU;IACRC,WAAW;AACb,CAAC;IAED,MAAM,EAAEA,SAAS,EAAE,GAAGD;IAEtB,IAAI,IAAI,CAACE,GAAG,KAAK,OAAO;QACtB;IACF;IAEA,IAAI,OAAO,IAAI,CAACA,GAAG,KAAK,UAAU;QAChC,MAAM,IAAIC,MAAM;IAClB;IAEA,MAAMC,eAAe,IAAI,C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type { ConnectOptions } from 'mongoose'\nimport type { Connect } from 'payload'\n\nimport mongoose from 'mongoose'\n\nimport type { MongooseAdapter } from './index.js'\n\nexport const connect: Connect = async function connect(\n this: MongooseAdapter,\n options = {\n hotReload: false,\n },\n) {\n const { hotReload } = options\n\n if (this.url === false) {\n return\n }\n\n if (typeof this.url !== 'string') {\n throw new Error('Error: missing MongoDB connection URL.')\n }\n\n const urlToConnect = this.url\n\n const connectionOptions: { useFacet: undefined } & ConnectOptions = {\n autoIndex: true,\n ...this.connectOptions,\n useFacet: undefined,\n }\n\n if (hotReload) {\n connectionOptions.autoIndex = false\n }\n\n try {\n this.connection = (await mongoose.connect(urlToConnect, connectionOptions)).connection\n\n // If we are running a replica set with MongoDB Memory Server,\n // wait until the replica set elects a primary before proceeding\n if (this.mongoMemoryServer) {\n await new Promise((resolve) => setTimeout(resolve, 2000))\n }\n\n const client = this.connection.getClient()\n\n if (!client.options.replicaSet) {\n this.transactionOptions = false\n this.beginTransaction = undefined\n }\n\n if (!this.mongoMemoryServer && !hotReload) {\n if (process.env.PAYLOAD_DROP_DATABASE === 'true') {\n this.payload.logger.info('---- DROPPING DATABASE ----')\n await mongoose.connection.dropDatabase()\n this.payload.logger.info('---- DROPPED DATABASE ----')\n }\n }\n\n if (this.ensureIndexes) {\n await Promise.all(\n this.payload.config.collections.map(async (coll) => {\n await new Promise((resolve, reject) => {\n this.collections[coll.slug]?.ensureIndexes(function (err) {\n if (err) {\n reject(err)\n }\n resolve(true)\n })\n })\n }),\n )\n }\n\n if (process.env.NODE_ENV === 'production' && this.prodMigrations) {\n await this.migrate({ migrations: this.prodMigrations })\n }\n } catch (err) {\n this.payload.logger.error({\n err,\n msg: `Error: cannot connect to MongoDB. Details: ${err.message}`,\n })\n process.exit(1)\n }\n}\n"],"names":["mongoose","connect","options","hotReload","url","Error","urlToConnect","connectionOptions","autoIndex","connectOptions","useFacet","undefined","connection","mongoMemoryServer","Promise","resolve","setTimeout","client","getClient","replicaSet","transactionOptions","beginTransaction","process","env","PAYLOAD_DROP_DATABASE","payload","logger","info","dropDatabase","ensureIndexes","all","config","collections","map","coll","reject","slug","err","NODE_ENV","prodMigrations","migrate","migrations","error","msg","message","exit"],"mappings":"AAGA,OAAOA,cAAc,WAAU;AAI/B,OAAO,MAAMC,UAAmB,eAAeA,QAE7CC,UAAU;IACRC,WAAW;AACb,CAAC;IAED,MAAM,EAAEA,SAAS,EAAE,GAAGD;IAEtB,IAAI,IAAI,CAACE,GAAG,KAAK,OAAO;QACtB;IACF;IAEA,IAAI,OAAO,IAAI,CAACA,GAAG,KAAK,UAAU;QAChC,MAAM,IAAIC,MAAM;IAClB;IAEA,MAAMC,eAAe,IAAI,CAACF,GAAG;IAE7B,MAAMG,oBAA8D;QAClEC,WAAW;QACX,GAAG,IAAI,CAACC,cAAc;QACtBC,UAAUC;IACZ;IAEA,IAAIR,WAAW;QACbI,kBAAkBC,SAAS,GAAG;IAChC;IAEA,IAAI;QACF,IAAI,CAACI,UAAU,GAAG,AAAC,CAAA,MAAMZ,SAASC,OAAO,CAACK,cAAcC,kBAAiB,EAAGK,UAAU;QAEtF,8DAA8D;QAC9D,gEAAgE;QAChE,IAAI,IAAI,CAACC,iBAAiB,EAAE;YAC1B,MAAM,IAAIC,QAAQ,CAACC,UAAYC,WAAWD,SAAS;QACrD;QAEA,MAAME,SAAS,IAAI,CAACL,UAAU,CAACM,SAAS;QAExC,IAAI,CAACD,OAAOf,OAAO,CAACiB,UAAU,EAAE;YAC9B,IAAI,CAACC,kBAAkB,GAAG;YAC1B,IAAI,CAACC,gBAAgB,GAAGV;QAC1B;QAEA,IAAI,CAAC,IAAI,CAACE,iBAAiB,IAAI,CAACV,WAAW;YACzC,IAAImB,QAAQC,GAAG,CAACC,qBAAqB,KAAK,QAAQ;gBAChD,IAAI,CAACC,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC;gBACzB,MAAM3B,SAASY,UAAU,CAACgB,YAAY;gBACtC,IAAI,CAACH,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC;YAC3B;QACF;QAEA,IAAI,IAAI,CAACE,aAAa,EAAE;YACtB,MAAMf,QAAQgB,GAAG,CACf,IAAI,CAACL,OAAO,CAACM,MAAM,CAACC,WAAW,CAACC,GAAG,CAAC,OAAOC;gBACzC,MAAM,IAAIpB,QAAQ,CAACC,SAASoB;oBAC1B,IAAI,CAACH,WAAW,CAACE,KAAKE,IAAI,CAAC,EAAEP,cAAc,SAAUQ,GAAG;wBACtD,IAAIA,KAAK;4BACPF,OAAOE;wBACT;wBACAtB,QAAQ;oBACV;gBACF;YACF;QAEJ;QAEA,IAAIO,QAAQC,GAAG,CAACe,QAAQ,KAAK,gBAAgB,IAAI,CAACC,cAAc,EAAE;YAChE,MAAM,IAAI,CAACC,OAAO,CAAC;gBAAEC,YAAY,IAAI,CAACF,cAAc;YAAC;QACvD;IACF,EAAE,OAAOF,KAAK;QACZ,IAAI,CAACZ,OAAO,CAACC,MAAM,CAACgB,KAAK,CAAC;YACxBL;YACAM,KAAK,CAAC,2CAA2C,EAAEN,IAAIO,OAAO,CAAC,CAAC;QAClE;QACAtB,QAAQuB,IAAI,CAAC;IACf;AACF,EAAC"}
@@ -0,0 +1,3 @@
1
+ import type { CountGlobalVersions } from 'payload';
2
+ export declare const countGlobalVersions: CountGlobalVersions;
3
+ //# sourceMappingURL=countGlobalVersions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"countGlobalVersions.d.ts","sourceRoot":"","sources":["../src/countGlobalVersions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAkB,MAAM,SAAS,CAAA;AAQlE,eAAO,MAAM,mBAAmB,EAAE,mBAsCjC,CAAA"}
@@ -0,0 +1,33 @@
1
+ import { flattenWhereToOperators } from 'payload';
2
+ import { withSession } from './withSession.js';
3
+ export const countGlobalVersions = async function countGlobalVersions({ global, locale, req = {}, where }) {
4
+ const Model = this.versions[global];
5
+ const options = await withSession(this, req);
6
+ let hasNearConstraint = false;
7
+ if (where) {
8
+ const constraints = flattenWhereToOperators(where);
9
+ hasNearConstraint = constraints.some((prop)=>Object.keys(prop).some((key)=>key === 'near'));
10
+ }
11
+ const query = await Model.buildQuery({
12
+ locale,
13
+ payload: this.payload,
14
+ where
15
+ });
16
+ // useEstimatedCount is faster, but not accurate, as it ignores any filters. It is thus set to true if there are no filters.
17
+ const useEstimatedCount = hasNearConstraint || !query || Object.keys(query).length === 0;
18
+ if (!useEstimatedCount && Object.keys(query).length === 0 && this.disableIndexHints !== true) {
19
+ // Improve the performance of the countDocuments query which is used if useEstimatedCount is set to false by adding
20
+ // a hint. By default, if no hint is provided, MongoDB does not use an indexed field to count the returned documents,
21
+ // which makes queries very slow. This only happens when no query (filter) is provided. If one is provided, it uses
22
+ // the correct indexed field
23
+ options.hint = {
24
+ _id: 1
25
+ };
26
+ }
27
+ const result = await Model.countDocuments(query, options);
28
+ return {
29
+ totalDocs: result
30
+ };
31
+ };
32
+
33
+ //# sourceMappingURL=countGlobalVersions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/countGlobalVersions.ts"],"sourcesContent":["import type { QueryOptions } from 'mongoose'\nimport type { CountGlobalVersions, PayloadRequest } from 'payload'\n\nimport { flattenWhereToOperators } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { withSession } from './withSession.js'\n\nexport const countGlobalVersions: CountGlobalVersions = async function countGlobalVersions(\n this: MongooseAdapter,\n { global, locale, req = {} as PayloadRequest, where },\n) {\n const Model = this.versions[global]\n const options: QueryOptions = 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 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\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 options.hint = {\n _id: 1,\n }\n }\n\n const result = await Model.countDocuments(query, options)\n\n return {\n totalDocs: result,\n }\n}\n"],"names":["flattenWhereToOperators","withSession","countGlobalVersions","global","locale","req","where","Model","versions","options","hasNearConstraint","constraints","some","prop","Object","keys","key","query","buildQuery","payload","useEstimatedCount","length","disableIndexHints","hint","_id","result","countDocuments","totalDocs"],"mappings":"AAGA,SAASA,uBAAuB,QAAQ,UAAS;AAIjD,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,sBAA2C,eAAeA,oBAErE,EAAEC,MAAM,EAAEC,MAAM,EAAEC,MAAM,CAAC,CAAmB,EAAEC,KAAK,EAAE;IAErD,MAAMC,QAAQ,IAAI,CAACC,QAAQ,CAACL,OAAO;IACnC,MAAMM,UAAwB,MAAMR,YAAY,IAAI,EAAEI;IAEtD,IAAIK,oBAAoB;IAExB,IAAIJ,OAAO;QACT,MAAMK,cAAcX,wBAAwBM;QAC5CI,oBAAoBC,YAAYC,IAAI,CAAC,CAACC,OAASC,OAAOC,IAAI,CAACF,MAAMD,IAAI,CAAC,CAACI,MAAQA,QAAQ;IACzF;IAEA,MAAMC,QAAQ,MAAMV,MAAMW,UAAU,CAAC;QACnCd;QACAe,SAAS,IAAI,CAACA,OAAO;QACrBb;IACF;IAEA,4HAA4H;IAC5H,MAAMc,oBAAoBV,qBAAqB,CAACO,SAASH,OAAOC,IAAI,CAACE,OAAOI,MAAM,KAAK;IAEvF,IAAI,CAACD,qBAAqBN,OAAOC,IAAI,CAACE,OAAOI,MAAM,KAAK,KAAK,IAAI,CAACC,iBAAiB,KAAK,MAAM;QAC5F,mHAAmH;QACnH,qHAAqH;QACrH,mHAAmH;QACnH,4BAA4B;QAC5Bb,QAAQc,IAAI,GAAG;YACbC,KAAK;QACP;IACF;IAEA,MAAMC,SAAS,MAAMlB,MAAMmB,cAAc,CAACT,OAAOR;IAEjD,OAAO;QACLkB,WAAWF;IACb;AACF,EAAC"}
@@ -0,0 +1,3 @@
1
+ import type { CountVersions } from 'payload';
2
+ export declare const countVersions: CountVersions;
3
+ //# sourceMappingURL=countVersions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"countVersions.d.ts","sourceRoot":"","sources":["../src/countVersions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAkB,MAAM,SAAS,CAAA;AAQ5D,eAAO,MAAM,aAAa,EAAE,aAsC3B,CAAA"}
@@ -0,0 +1,33 @@
1
+ import { flattenWhereToOperators } from 'payload';
2
+ import { withSession } from './withSession.js';
3
+ export const countVersions = async function countVersions({ collection, locale, req = {}, where }) {
4
+ const Model = this.versions[collection];
5
+ const options = await withSession(this, req);
6
+ let hasNearConstraint = false;
7
+ if (where) {
8
+ const constraints = flattenWhereToOperators(where);
9
+ hasNearConstraint = constraints.some((prop)=>Object.keys(prop).some((key)=>key === 'near'));
10
+ }
11
+ const query = await Model.buildQuery({
12
+ locale,
13
+ payload: this.payload,
14
+ where
15
+ });
16
+ // useEstimatedCount is faster, but not accurate, as it ignores any filters. It is thus set to true if there are no filters.
17
+ const useEstimatedCount = hasNearConstraint || !query || Object.keys(query).length === 0;
18
+ if (!useEstimatedCount && Object.keys(query).length === 0 && this.disableIndexHints !== true) {
19
+ // Improve the performance of the countDocuments query which is used if useEstimatedCount is set to false by adding
20
+ // a hint. By default, if no hint is provided, MongoDB does not use an indexed field to count the returned documents,
21
+ // which makes queries very slow. This only happens when no query (filter) is provided. If one is provided, it uses
22
+ // the correct indexed field
23
+ options.hint = {
24
+ _id: 1
25
+ };
26
+ }
27
+ const result = await Model.countDocuments(query, options);
28
+ return {
29
+ totalDocs: result
30
+ };
31
+ };
32
+
33
+ //# sourceMappingURL=countVersions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/countVersions.ts"],"sourcesContent":["import type { QueryOptions } from 'mongoose'\nimport type { CountVersions, PayloadRequest } from 'payload'\n\nimport { flattenWhereToOperators } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { withSession } from './withSession.js'\n\nexport const countVersions: CountVersions = async function countVersions(\n this: MongooseAdapter,\n { collection, locale, req = {} as PayloadRequest, where },\n) {\n const Model = this.versions[collection]\n const options: QueryOptions = 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 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\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 options.hint = {\n _id: 1,\n }\n }\n\n const result = await Model.countDocuments(query, options)\n\n return {\n totalDocs: result,\n }\n}\n"],"names":["flattenWhereToOperators","withSession","countVersions","collection","locale","req","where","Model","versions","options","hasNearConstraint","constraints","some","prop","Object","keys","key","query","buildQuery","payload","useEstimatedCount","length","disableIndexHints","hint","_id","result","countDocuments","totalDocs"],"mappings":"AAGA,SAASA,uBAAuB,QAAQ,UAAS;AAIjD,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,gBAA+B,eAAeA,cAEzD,EAAEC,UAAU,EAAEC,MAAM,EAAEC,MAAM,CAAC,CAAmB,EAAEC,KAAK,EAAE;IAEzD,MAAMC,QAAQ,IAAI,CAACC,QAAQ,CAACL,WAAW;IACvC,MAAMM,UAAwB,MAAMR,YAAY,IAAI,EAAEI;IAEtD,IAAIK,oBAAoB;IAExB,IAAIJ,OAAO;QACT,MAAMK,cAAcX,wBAAwBM;QAC5CI,oBAAoBC,YAAYC,IAAI,CAAC,CAACC,OAASC,OAAOC,IAAI,CAACF,MAAMD,IAAI,CAAC,CAACI,MAAQA,QAAQ;IACzF;IAEA,MAAMC,QAAQ,MAAMV,MAAMW,UAAU,CAAC;QACnCd;QACAe,SAAS,IAAI,CAACA,OAAO;QACrBb;IACF;IAEA,4HAA4H;IAC5H,MAAMc,oBAAoBV,qBAAqB,CAACO,SAASH,OAAOC,IAAI,CAACE,OAAOI,MAAM,KAAK;IAEvF,IAAI,CAACD,qBAAqBN,OAAOC,IAAI,CAACE,OAAOI,MAAM,KAAK,KAAK,IAAI,CAACC,iBAAiB,KAAK,MAAM;QAC5F,mHAAmH;QACnH,qHAAqH;QACrH,mHAAmH;QACnH,4BAA4B;QAC5Bb,QAAQc,IAAI,GAAG;YACbC,KAAK;QACP;IACF;IAEA,MAAMC,SAAS,MAAMlB,MAAMmB,cAAc,CAACT,OAAOR;IAEjD,OAAO;QACLkB,WAAWF;IACb;AACF,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../src/create.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAA4B,MAAM,SAAS,CAAA;AAQ/D,eAAO,MAAM,MAAM,EAAE,MA+BpB,CAAA"}
1
+ {"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../src/create.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAA4B,MAAM,SAAS,CAAA;AAQ/D,eAAO,MAAM,MAAM,EAAE,MAmCpB,CAAA"}
package/dist/create.js CHANGED
@@ -10,6 +10,9 @@ export const create = async function create({ collection, data, req = {} }) {
10
10
  data,
11
11
  fields: this.payload.collections[collection].config.fields
12
12
  });
13
+ if (this.payload.collections[collection].customIDType) {
14
+ sanitizedData._id = sanitizedData.id;
15
+ }
13
16
  try {
14
17
  [doc] = await Model.create([
15
18
  sanitizedData
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/create.ts"],"sourcesContent":["import type { Create, Document, PayloadRequest } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { handleError } from './utilities/handleError.js'\nimport { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.js'\nimport { withSession } from './withSession.js'\n\nexport const create: Create = async function create(\n this: MongooseAdapter,\n { collection, data, req = {} as PayloadRequest },\n) {\n const Model = this.collections[collection]\n const options = await withSession(this, req)\n let doc\n\n const sanitizedData = sanitizeRelationshipIDs({\n config: this.payload.config,\n data,\n fields: this.payload.collections[collection].config.fields,\n })\n\n try {\n ;[doc] = await Model.create([sanitizedData], options)\n } catch (error) {\n handleError({ collection, error, req })\n }\n\n // doc.toJSON does not do stuff like converting ObjectIds to string, or date strings to date objects. That's why we use JSON.parse/stringify here\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\n return result\n}\n"],"names":["handleError","sanitizeRelationshipIDs","withSession","create","collection","data","req","Model","collections","options","doc","sanitizedData","config","payload","fields","error","result","JSON","parse","stringify","verificationToken","_verificationToken","id","_id"],"mappings":"AAIA,SAASA,WAAW,QAAQ,6BAA4B;AACxD,SAASC,uBAAuB,QAAQ,yCAAwC;AAChF,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,SAAiB,eAAeA,OAE3C,EAAEC,UAAU,EAAEC,IAAI,EAAEC,MAAM,CAAC,CAAmB,EAAE;IAEhD,MAAMC,QAAQ,IAAI,CAACC,WAAW,CAACJ,WAAW;IAC1C,MAAMK,UAAU,MAAMP,YAAY,IAAI,EAAEI;IACxC,IAAII;IAEJ,MAAMC,gBAAgBV,wBAAwB;QAC5CW,QAAQ,IAAI,CAACC,OAAO,CAACD,MAAM;QAC3BP;QACAS,QAAQ,IAAI,CAACD,OAAO,CAACL,WAAW,CAACJ,WAAW,CAACQ,MAAM,CAACE,MAAM;IAC5D;IAEA,IAAI;QACD,CAACJ,IAAI,GAAG,MAAMH,MAAMJ,MAAM,CAAC;YAACQ;SAAc,EAAEF;IAC/C,EAAE,OAAOM,OAAO;QACdf,YAAY;YAAEI;YAAYW;YAAOT;QAAI;IACvC;IAEA,iJAAiJ;IACjJ,MAAMU,SAAmBC,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACT;IACnD,MAAMU,oBAAoBV,IAAIW,kBAAkB;IAEhD,uBAAuB;IACvBL,OAAOM,EAAE,GAAGN,OAAOO,GAAG;IACtB,IAAIH,mBAAmB;QACrBJ,OAAOK,kBAAkB,GAAGD;IAC9B;IAEA,OAAOJ;AACT,EAAC"}
1
+ {"version":3,"sources":["../src/create.ts"],"sourcesContent":["import type { Create, Document, PayloadRequest } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { handleError } from './utilities/handleError.js'\nimport { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.js'\nimport { withSession } from './withSession.js'\n\nexport const create: Create = async function create(\n this: MongooseAdapter,\n { collection, data, req = {} as PayloadRequest },\n) {\n const Model = this.collections[collection]\n const options = await withSession(this, req)\n let doc\n\n const sanitizedData = sanitizeRelationshipIDs({\n config: this.payload.config,\n data,\n fields: this.payload.collections[collection].config.fields,\n })\n\n if (this.payload.collections[collection].customIDType) {\n sanitizedData._id = sanitizedData.id\n }\n\n try {\n ;[doc] = await Model.create([sanitizedData], options)\n } catch (error) {\n handleError({ collection, error, req })\n }\n\n // doc.toJSON does not do stuff like converting ObjectIds to string, or date strings to date objects. That's why we use JSON.parse/stringify here\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\n return result\n}\n"],"names":["handleError","sanitizeRelationshipIDs","withSession","create","collection","data","req","Model","collections","options","doc","sanitizedData","config","payload","fields","customIDType","_id","id","error","result","JSON","parse","stringify","verificationToken","_verificationToken"],"mappings":"AAIA,SAASA,WAAW,QAAQ,6BAA4B;AACxD,SAASC,uBAAuB,QAAQ,yCAAwC;AAChF,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,SAAiB,eAAeA,OAE3C,EAAEC,UAAU,EAAEC,IAAI,EAAEC,MAAM,CAAC,CAAmB,EAAE;IAEhD,MAAMC,QAAQ,IAAI,CAACC,WAAW,CAACJ,WAAW;IAC1C,MAAMK,UAAU,MAAMP,YAAY,IAAI,EAAEI;IACxC,IAAII;IAEJ,MAAMC,gBAAgBV,wBAAwB;QAC5CW,QAAQ,IAAI,CAACC,OAAO,CAACD,MAAM;QAC3BP;QACAS,QAAQ,IAAI,CAACD,OAAO,CAACL,WAAW,CAACJ,WAAW,CAACQ,MAAM,CAACE,MAAM;IAC5D;IAEA,IAAI,IAAI,CAACD,OAAO,CAACL,WAAW,CAACJ,WAAW,CAACW,YAAY,EAAE;QACrDJ,cAAcK,GAAG,GAAGL,cAAcM,EAAE;IACtC;IAEA,IAAI;QACD,CAACP,IAAI,GAAG,MAAMH,MAAMJ,MAAM,CAAC;YAACQ;SAAc,EAAEF;IAC/C,EAAE,OAAOS,OAAO;QACdlB,YAAY;YAAEI;YAAYc;YAAOZ;QAAI;IACvC;IAEA,iJAAiJ;IACjJ,MAAMa,SAAmBC,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACZ;IACnD,MAAMa,oBAAoBb,IAAIc,kBAAkB;IAEhD,uBAAuB;IACvBL,OAAOF,EAAE,GAAGE,OAAOH,GAAG;IACtB,IAAIO,mBAAmB;QACrBJ,OAAOK,kBAAkB,GAAGD;IAC9B;IAEA,OAAOJ;AACT,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"createMigration.d.ts","sourceRoot":"","sources":["../src/createMigration.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAyB,MAAM,SAAS,CAAA;AAsBrE,eAAO,MAAM,eAAe,EAAE,eAgC7B,CAAA"}
1
+ {"version":3,"file":"createMigration.d.ts","sourceRoot":"","sources":["../src/createMigration.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAyB,MAAM,SAAS,CAAA;AAqBrE,eAAO,MAAM,eAAe,EAAE,eAmC7B,CAAA"}
@@ -1,13 +1,12 @@
1
1
  import fs from 'fs';
2
2
  import path from 'path';
3
- import { getPredefinedMigration } from 'payload';
3
+ import { getPredefinedMigration, writeMigrationIndex } from 'payload';
4
4
  import { fileURLToPath } from 'url';
5
5
  const migrationTemplate = ({ downSQL, imports, upSQL })=>`import {
6
- MigrateUpArgs,
7
6
  MigrateDownArgs,
7
+ MigrateUpArgs,
8
8
  } from '@payloadcms/db-mongodb'
9
- ${imports}
10
-
9
+ ${imports ?? ''}
11
10
  export async function up({ payload, req }: MigrateUpArgs): Promise<void> {
12
11
  ${upSQL ?? ` // Migration code`}
13
12
  }
@@ -38,6 +37,9 @@ export const createMigration = async function createMigration({ file, migrationN
38
37
  const fileName = migrationName ? `${timestamp}_${formattedName}.ts` : `${timestamp}_migration.ts`;
39
38
  const filePath = `${dir}/${fileName}`;
40
39
  fs.writeFileSync(filePath, migrationFileContent);
40
+ writeMigrationIndex({
41
+ migrationsDir: payload.db.migrationDir
42
+ });
41
43
  payload.logger.info({
42
44
  msg: `Migration created at ${filePath}`
43
45
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/createMigration.ts"],"sourcesContent":["import type { CreateMigration, MigrationTemplateArgs } from 'payload'\n\nimport fs from 'fs'\nimport path from 'path'\nimport { getPredefinedMigration } from 'payload'\nimport { fileURLToPath } from 'url'\n\nconst migrationTemplate = ({ downSQL, imports, upSQL }: MigrationTemplateArgs): string => `import {\n MigrateUpArgs,\n MigrateDownArgs,\n} from '@payloadcms/db-mongodb'\n${imports}\n\nexport async function up({ payload, req }: MigrateUpArgs): Promise<void> {\n${upSQL ?? ` // Migration code`}\n}\n\nexport async function down({ payload, req }: MigrateDownArgs): Promise<void> {\n${downSQL ?? ` // Migration code`}\n}\n`\n\nexport const createMigration: CreateMigration = async function createMigration({\n file,\n migrationName,\n payload,\n}) {\n const filename = fileURLToPath(import.meta.url)\n const dirname = path.dirname(filename)\n\n const dir = payload.db.migrationDir\n if (!fs.existsSync(dir)) {\n fs.mkdirSync(dir)\n }\n const predefinedMigration = await getPredefinedMigration({\n dirname,\n file,\n migrationName,\n payload,\n })\n\n const migrationFileContent = migrationTemplate(predefinedMigration)\n\n const [yyymmdd, hhmmss] = new Date().toISOString().split('T')\n const formattedDate = yyymmdd.replace(/\\D/g, '')\n const formattedTime = hhmmss.split('.')[0].replace(/\\D/g, '')\n\n const timestamp = `${formattedDate}_${formattedTime}`\n\n const formattedName = migrationName?.replace(/\\W/g, '_')\n const fileName = migrationName ? `${timestamp}_${formattedName}.ts` : `${timestamp}_migration.ts`\n const filePath = `${dir}/${fileName}`\n fs.writeFileSync(filePath, migrationFileContent)\n payload.logger.info({ msg: `Migration created at ${filePath}` })\n}\n"],"names":["fs","path","getPredefinedMigration","fileURLToPath","migrationTemplate","downSQL","imports","upSQL","createMigration","file","migrationName","payload","filename","url","dirname","dir","db","migrationDir","existsSync","mkdirSync","predefinedMigration","migrationFileContent","yyymmdd","hhmmss","Date","toISOString","split","formattedDate","replace","formattedTime","timestamp","formattedName","fileName","filePath","writeFileSync","logger","info","msg"],"mappings":"AAEA,OAAOA,QAAQ,KAAI;AACnB,OAAOC,UAAU,OAAM;AACvB,SAASC,sBAAsB,QAAQ,UAAS;AAChD,SAASC,aAAa,QAAQ,MAAK;AAEnC,MAAMC,oBAAoB,CAAC,EAAEC,OAAO,EAAEC,OAAO,EAAEC,KAAK,EAAyB,GAAa,CAAC;;;;AAI3F,EAAED,QAAQ;;;AAGV,EAAEC,SAAS,CAAC,mBAAmB,CAAC,CAAC;;;;AAIjC,EAAEF,WAAW,CAAC,mBAAmB,CAAC,CAAC;;AAEnC,CAAC;AAED,OAAO,MAAMG,kBAAmC,eAAeA,gBAAgB,EAC7EC,IAAI,EACJC,aAAa,EACbC,OAAO,EACR;IACC,MAAMC,WAAWT,cAAc,YAAYU,GAAG;IAC9C,MAAMC,UAAUb,KAAKa,OAAO,CAACF;IAE7B,MAAMG,MAAMJ,QAAQK,EAAE,CAACC,YAAY;IACnC,IAAI,CAACjB,GAAGkB,UAAU,CAACH,MAAM;QACvBf,GAAGmB,SAAS,CAACJ;IACf;IACA,MAAMK,sBAAsB,MAAMlB,uBAAuB;QACvDY;QACAL;QACAC;QACAC;IACF;IAEA,MAAMU,uBAAuBjB,kBAAkBgB;IAE/C,MAAM,CAACE,SAASC,OAAO,GAAG,IAAIC,OAAOC,WAAW,GAAGC,KAAK,CAAC;IACzD,MAAMC,gBAAgBL,QAAQM,OAAO,CAAC,OAAO;IAC7C,MAAMC,gBAAgBN,OAAOG,KAAK,CAAC,IAAI,CAAC,EAAE,CAACE,OAAO,CAAC,OAAO;IAE1D,MAAME,YAAY,CAAC,EAAEH,cAAc,CAAC,EAAEE,cAAc,CAAC;IAErD,MAAME,gBAAgBrB,eAAekB,QAAQ,OAAO;IACpD,MAAMI,WAAWtB,gBAAgB,CAAC,EAAEoB,UAAU,CAAC,EAAEC,cAAc,GAAG,CAAC,GAAG,CAAC,EAAED,UAAU,aAAa,CAAC;IACjG,MAAMG,WAAW,CAAC,EAAElB,IAAI,CAAC,EAAEiB,SAAS,CAAC;IACrChC,GAAGkC,aAAa,CAACD,UAAUZ;IAC3BV,QAAQwB,MAAM,CAACC,IAAI,CAAC;QAAEC,KAAK,CAAC,qBAAqB,EAAEJ,SAAS,CAAC;IAAC;AAChE,EAAC"}
1
+ {"version":3,"sources":["../src/createMigration.ts"],"sourcesContent":["import type { CreateMigration, MigrationTemplateArgs } from 'payload'\n\nimport fs from 'fs'\nimport path from 'path'\nimport { getPredefinedMigration, writeMigrationIndex } from 'payload'\nimport { fileURLToPath } from 'url'\n\nconst migrationTemplate = ({ downSQL, imports, upSQL }: MigrationTemplateArgs): string => `import {\n MigrateDownArgs,\n MigrateUpArgs,\n} from '@payloadcms/db-mongodb'\n${imports ?? ''}\nexport async function up({ payload, req }: MigrateUpArgs): Promise<void> {\n${upSQL ?? ` // Migration code`}\n}\n\nexport async function down({ payload, req }: MigrateDownArgs): Promise<void> {\n${downSQL ?? ` // Migration code`}\n}\n`\n\nexport const createMigration: CreateMigration = async function createMigration({\n file,\n migrationName,\n payload,\n}) {\n const filename = fileURLToPath(import.meta.url)\n const dirname = path.dirname(filename)\n\n const dir = payload.db.migrationDir\n if (!fs.existsSync(dir)) {\n fs.mkdirSync(dir)\n }\n const predefinedMigration = await getPredefinedMigration({\n dirname,\n file,\n migrationName,\n payload,\n })\n\n const migrationFileContent = migrationTemplate(predefinedMigration)\n\n const [yyymmdd, hhmmss] = new Date().toISOString().split('T')\n const formattedDate = yyymmdd.replace(/\\D/g, '')\n const formattedTime = hhmmss.split('.')[0].replace(/\\D/g, '')\n\n const timestamp = `${formattedDate}_${formattedTime}`\n\n const formattedName = migrationName?.replace(/\\W/g, '_')\n const fileName = migrationName ? `${timestamp}_${formattedName}.ts` : `${timestamp}_migration.ts`\n const filePath = `${dir}/${fileName}`\n fs.writeFileSync(filePath, migrationFileContent)\n\n writeMigrationIndex({ migrationsDir: payload.db.migrationDir })\n\n payload.logger.info({ msg: `Migration created at ${filePath}` })\n}\n"],"names":["fs","path","getPredefinedMigration","writeMigrationIndex","fileURLToPath","migrationTemplate","downSQL","imports","upSQL","createMigration","file","migrationName","payload","filename","url","dirname","dir","db","migrationDir","existsSync","mkdirSync","predefinedMigration","migrationFileContent","yyymmdd","hhmmss","Date","toISOString","split","formattedDate","replace","formattedTime","timestamp","formattedName","fileName","filePath","writeFileSync","migrationsDir","logger","info","msg"],"mappings":"AAEA,OAAOA,QAAQ,KAAI;AACnB,OAAOC,UA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,aAAa,CAACD,UAAUZ;IAE3BnB,oBAAoB;QAAEiC,eAAexB,QAAQK,EAAE,CAACC,YAAY;IAAC;IAE7DN,QAAQyB,MAAM,CAACC,IAAI,CAAC;QAAEC,KAAK,CAAC,qBAAqB,EAAEL,SAAS,CAAC;IAAC;AAChE,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;AAOlE,eAAO,MAAM,SAAS,EAAE,SAqBvB,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,13 +1,21 @@
1
+ import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
1
2
  import { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js';
2
3
  import { withSession } from './withSession.js';
3
- export const deleteOne = async function deleteOne({ collection, req = {}, where }) {
4
+ export const deleteOne = async function deleteOne({ collection, req = {}, select, where }) {
4
5
  const Model = this.collections[collection];
5
6
  const options = await withSession(this, req);
6
7
  const query = await Model.buildQuery({
7
8
  payload: this.payload,
8
9
  where
9
10
  });
10
- const doc = await Model.findOneAndDelete(query, options).lean();
11
+ const doc = await Model.findOneAndDelete(query, {
12
+ ...options,
13
+ projection: buildProjectionFromSelect({
14
+ adapter: this,
15
+ fields: this.payload.collections[collection].config.fields,
16
+ select
17
+ })
18
+ }).lean();
11
19
  let result = JSON.parse(JSON.stringify(doc));
12
20
  // custom id type reset
13
21
  result.id = result._id;
@@ -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 { 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, 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, options).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":["sanitizeInternalFields","withSession","deleteOne","collection","req","where","Model","collections","options","query","buildQuery","payload","doc","findOneAndDelete","lean","result","JSON","parse","stringify","id","_id"],"mappings":"AAIA,SAASA,sBAAsB,QAAQ,wCAAuC;AAC9E,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,YAAuB,eAAeA,UAEjD,EAAEC,UAAU,EAAEC,MAAM,CAAC,CAAmB,EAAEC,KAAK,EAAE;IAEjD,MAAMC,QAAQ,IAAI,CAACC,WAAW,CAACJ,WAAW;IAC1C,MAAMK,UAAU,MAAMP,YAAY,IAAI,EAAEG;IAExC,MAAMK,QAAQ,MAAMH,MAAMI,UAAU,CAAC;QACnCC,SAAS,IAAI,CAACA,OAAO;QACrBN;IACF;IAEA,MAAMO,MAAM,MAAMN,MAAMO,gBAAgB,CAACJ,OAAOD,SAASM,IAAI;IAE7D,IAAIC,SAAmBC,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACN;IAEjD,uBAAuB;IACvBG,OAAOI,EAAE,GAAGJ,OAAOK,GAAG;IACtBL,SAASf,uBAAuBe;IAEhC,OAAOA;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.fields,\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","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,CAACD,MAAM;YAC1DZ;QACF;IACF,GAAGc,IAAI;IAEP,IAAIC,SAAmBC,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACV;IAEjD,uBAAuB;IACvBO,OAAOI,EAAE,GAAGJ,OAAOK,GAAG;IACtBL,SAASpB,uBAAuBoB;IAEhC,OAAOA;AACT,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;AAWnD,eAAO,MAAM,IAAI,EAAE,IAsHlB,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,IA8HlB,CAAA"}
package/dist/find.js CHANGED
@@ -1,9 +1,10 @@
1
1
  import { flattenWhereToOperators } from 'payload';
2
2
  import { buildSortParam } from './queries/buildSortParam.js';
3
3
  import { buildJoinAggregation } from './utilities/buildJoinAggregation.js';
4
+ import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
4
5
  import { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js';
5
6
  import { withSession } from './withSession.js';
6
- export const find = async function find({ collection, joins = {}, limit = 0, locale, page, pagination, projection, req = {}, sort: sortArg, where }) {
7
+ export const find = async function find({ collection, joins = {}, limit = 0, locale, page, pagination, projection, req = {}, select, sort: sortArg, where }) {
7
8
  const Model = this.collections[collection];
8
9
  const collectionConfig = this.payload.collections[collection].config;
9
10
  const options = await withSession(this, req);
@@ -40,6 +41,13 @@ export const find = async function find({ collection, joins = {}, limit = 0, loc
40
41
  sort,
41
42
  useEstimatedCount
42
43
  };
44
+ if (select) {
45
+ paginationOptions.projection = buildProjectionFromSelect({
46
+ adapter: this,
47
+ fields: collectionConfig.fields,
48
+ select
49
+ });
50
+ }
43
51
  if (this.collation) {
44
52
  const defaultLocale = 'en';
45
53
  paginationOptions.collation = {
@@ -76,7 +84,6 @@ export const find = async function find({ collection, joins = {}, limit = 0, loc
76
84
  collection,
77
85
  collectionConfig,
78
86
  joins,
79
- limit,
80
87
  locale,
81
88
  query
82
89
  });
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 { 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 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.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 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 forceCountFn: hasNearConstraint,\n lean: true,\n leanWithId: true,\n options,\n page,\n pagination,\n projection,\n sort,\n useEstimatedCount,\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 limit,\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","sanitizeInternalFields","withSession","find","collection","joins","limit","locale","page","pagination","projection","req","sort","sortArg","where","Model","collections","collectionConfig","payload","config","options","hasNearConstraint","constraints","some","prop","Object","keys","key","fields","defaultSort","timestamps","query","buildQuery","useEstimatedCount","length","paginationOptions","forceCountFn","lean","leanWithId","collation","defaultLocale","disableIndexHints","useCustomCountFn","Promise","resolve","countDocuments","hint","_id","result","aggregate","adapter","aggregatePaginate","paginate","docs","JSON","parse","stringify","map","doc","id"],"mappings":"AAGA,SAASA,uBAAuB,QAAQ,UAAS;AAIjD,SAASC,cAAc,QAAQ,8BAA6B;AAC5D,SAASC,oBAAoB,QAAQ,sCAAqC;AAC1E,SAASC,sBAAsB,QAAQ,wCAAuC;AAC9E,SAASC,WAAW,QAAQ,mBAAkB;A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,GAAG,IAAI,CAACD,SAAS;QACnB;IACF;IAEA,IAAI,CAACN,qBAAqBR,OAAOC,IAAI,CAACK,OAAOG,MAAM,KAAK,KAAK,IAAI,CAACO,iBAAiB,KAAK,MAAM;QAC5F,mHAAmH;QACnH,qHAAqH;QACrH,mHAAmH;QACnH,4BAA4B;QAC5BN,kBAAkBO,gBAAgB,GAAG;YACnC,OAAOC,QAAQC,OAAO,CACpB7B,MAAM8B,cAAc,CAACd,OAAO;gBAC1B,GAAGX,OAAO;gBACV0B,MAAM;oBAAEC,KAAK;gBAAE;YACjB;QAEJ;IACF;IAEA,IAAIzC,SAAS,GAAG;QACd6B,kBAAkB7B,KAAK,GAAGA;QAC1B,qEAAqE;QACrE6B,kBAAkBf,OAAO,CAACd,KAAK,GAAGA;QAElC,mCAAmC;QACnC,IAAIA,UAAU,GAAG;YACf6B,kBAAkB1B,UAAU,GAAG;QACjC;IACF;IAEA,IAAIuC;IAEJ,MAAMC,YAAY,MAAMjD,qBAAqB;QAC3CkD,SAAS,IAAI;QACb9C;QACAa;QACAZ;QACAC;QACAC;QACAwB;IACF;IACA,yBAAyB;IACzB,IAAIkB,WAAW;QACbD,SAAS,MAAMjC,MAAMoC,iBAAiB,CAACpC,MAAMkC,SAAS,CAACA,YAAYd;IACrE,OAAO;QACLa,SAAS,MAAMjC,MAAMqC,QAAQ,CAACrB,OAAOI;IACvC;IAEA,MAAMkB,OAAOC,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACR,OAAOK,IAAI;IAElD,OAAO;QACL,GAAGL,MAAM;QACTK,MAAMA,KAAKI,GAAG,CAAC,CAACC;YACdA,IAAIC,EAAE,GAAGD,IAAIX,GAAG;YAChB,OAAO9C,uBAAuByD;QAChC;IACF;AACF,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.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 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 forceCountFn: hasNearConstraint,\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.fields,\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","defaultSort","timestamps","query","buildQuery","useEstimatedCount","length","paginationOptions","forceCountFn","lean","leanWithId","adapter","collation","defaultLocale","disableIndexHints","useCustomCountFn","Promise","resolve","countDocuments","hint","_id","result","aggregate","aggregatePaginate","paginate","docs","JSON","parse","stringify","map","doc","id"],"mappings":"AAGA,SAASA,uBAAuB,QAAQ,UAAS;AAIjD,SAASC,cAAc,QAAQ,8BAA6B;AAC5D,SAASC,oBAAoB,QAAQ,sCAAqC;AAC1E,SAASC,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,sBAAsB,QAAQ,wCAAuC;AAC9E,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,OAAa,eAAeA,KAEvC,EACEC,UAAU,EACVC,QAAQ,CAAC,CAAC,EACVC,QAAQ,CAAC,EACTC,MAAM,E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U,EAAkB,MAAM,SAAS,CAAA;AASzD,eAAO,MAAM,UAAU,EAAE,UA+BxB,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,11 +1,17 @@
1
1
  import { combineQueries } from 'payload';
2
+ import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
2
3
  import { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js';
3
4
  import { withSession } from './withSession.js';
4
- export const findGlobal = async function findGlobal({ slug, locale, req = {}, where }) {
5
+ export const findGlobal = async function findGlobal({ slug, locale, req = {}, select, where }) {
5
6
  const Model = this.globals;
6
7
  const options = {
7
8
  ...await withSession(this, req),
8
- lean: true
9
+ lean: true,
10
+ select: buildProjectionFromSelect({
11
+ adapter: this,
12
+ fields: this.payload.globals.config.find((each)=>each.slug === slug).fields,
13
+ select
14
+ })
9
15
  };
10
16
  const query = await Model.buildQuery({
11
17
  globalSlug: slug,
@@ -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 { 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, where },\n) {\n const Model = this.globals\n const options = {\n ...(await withSession(this, req)),\n lean: true,\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","sanitizeInternalFields","withSession","findGlobal","slug","locale","req","where","Model","globals","options","lean","query","buildQuery","globalSlug","payload","globalType","equals","doc","findOne","_id","id","JSON","parse","stringify"],"mappings":"AAEA,SAASA,cAAc,QAAQ,UAAS;AAIxC,SAASC,sBAAsB,QAAQ,wCAAuC;AAC9E,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,aAAyB,eAAeA,WAEnD,EAAEC,IAAI,EAAEC,MAAM,EAAEC,MAAM,CAAC,CAAmB,EAAEC,KAAK,EAAE;IAEnD,MAAMC,QAAQ,IAAI,CAACC,OAAO;IAC1B,MAAMC,UAAU;QACd,GAAI,MAAMR,YAAY,IAAI,EAAEI,IAAI;QAChCK,MAAM;IACR;IAEA,MAAMC,QAAQ,MAAMJ,MAAMK,UAAU,CAAC;QACnCC,YAAYV;QACZC;QACAU,SAAS,IAAI,CAACA,OAAO;QACrBR,OAAOP,eAAe;YAAEgB,YAAY;gBAAEC,QAAQb;YAAK;QAAE,GAAGG;IAC1D;IAEA,IAAIW,MAAO,MAAMV,MAAMW,OAAO,CAACP,OAAO,CAAC,GAAGF;IAE1C,IAAI,CAACQ,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,MAAMjB,uBAAuBiB;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 { 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).fields,\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","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,MAAMU,MAAM;YAC7EP;QACF;IACF;IAEA,MAAMY,QAAQ,MAAMV,MAAMW,UAAU,CAAC;QACnCC,YAAYjB;QACZC;QACAU,SAAS,IAAI,CAACA,OAAO;QACrBP,OAAOT,eAAe;YAAEuB,YAAY;gBAAEC,QAAQnB;YAAK;QAAE,GAAGI;IAC1D;IAEA,IAAIgB,MAAO,MAAMf,MAAMgB,OAAO,CAACN,OAAO,CAAC,GAAGR;IAE1C,IAAI,CAACa,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,MAAMvB,uBAAuBuB;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;AAUjE,eAAO,MAAM,kBAAkB,EAAE,kBA4GhC,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"}
@@ -1,8 +1,9 @@
1
1
  import { buildVersionGlobalFields, flattenWhereToOperators } from 'payload';
2
2
  import { buildSortParam } from './queries/buildSortParam.js';
3
+ import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
3
4
  import { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js';
4
5
  import { withSession } from './withSession.js';
5
- export const findGlobalVersions = async function findGlobalVersions({ global, limit, locale, page, pagination, req = {}, skip, sort: sortArg, where }) {
6
+ export const findGlobalVersions = async function findGlobalVersions({ global, limit, locale, page, pagination, req = {}, select, skip, sort: sortArg, where }) {
6
7
  const Model = this.versions[global];
7
8
  const versionFields = buildVersionGlobalFields(this.payload.config, this.payload.globals.config.find(({ slug })=>slug === global));
8
9
  const options = {
@@ -41,6 +42,11 @@ export const findGlobalVersions = async function findGlobalVersions({ global, li
41
42
  options,
42
43
  page,
43
44
  pagination,
45
+ projection: buildProjectionFromSelect({
46
+ adapter: this,
47
+ fields: versionFields,
48
+ select
49
+ }),
44
50
  sort,
45
51
  useEstimatedCount
46
52
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/findGlobalVersions.ts"],"sourcesContent":["import type { PaginateOptions } from 'mongoose'\nimport type { FindGlobalVersions, PayloadRequest } from 'payload'\n\nimport { buildVersionGlobalFields, flattenWhereToOperators } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildSortParam } from './queries/buildSortParam.js'\nimport { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js'\nimport { withSession } from './withSession.js'\n\nexport const findGlobalVersions: FindGlobalVersions = async function findGlobalVersions(\n this: MongooseAdapter,\n {\n global,\n limit,\n locale,\n page,\n pagination,\n req = {} as PayloadRequest,\n skip,\n sort: sortArg,\n where,\n },\n) {\n const Model = this.versions[global]\n const versionFields = buildVersionGlobalFields(\n this.payload.config,\n this.payload.globals.config.find(({ slug }) => slug === global),\n )\n const options = {\n ...(await withSession(this, req)),\n limit,\n skip,\n }\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: versionFields,\n locale,\n sort: sortArg || '-updatedAt',\n timestamps: true,\n })\n }\n\n const query = await Model.buildQuery({\n globalSlug: global,\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 forceCountFn: hasNearConstraint,\n lean: true,\n leanWithId: true,\n limit,\n options,\n page,\n pagination,\n sort,\n useEstimatedCount,\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 const result = await Model.paginate(query, paginationOptions)\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":["buildVersionGlobalFields","flattenWhereToOperators","buildSortParam","sanitizeInternalFields","withSession","findGlobalVersions","global","limit","locale","page","pagination","req","skip","sort","sortArg","where","Model","versions","versionFields","payload","config","globals","find","slug","options","hasNearConstraint","constraints","some","prop","Object","keys","key","fields","timestamps","query","buildQuery","globalSlug","useEstimatedCount","length","paginationOptions","forceCountFn","lean","leanWithId","collation","defaultLocale","disableIndexHints","useCustomCountFn","Promise","resolve","countDocuments","hint","_id","result","paginate","docs","JSON","parse","stringify","map","doc","id"],"mappings":"AAGA,SAASA,wBAAwB,EAAEC,uBAAuB,QAAQ,UAAS;AAI3E,SAASC,cAAc,QAAQ,8BAA6B;AAC5D,SAASC,sBAAsB,QAAQ,wCAAu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AE;QAClB,MAAMC,gBAAgB;QACtBL,kBAAkBI,SAAS,GAAG;YAC5BnC,QAAQA,UAAUA,WAAW,SAASA,WAAW,MAAMA,SAASoC;YAChE,GAAG,IAAI,CAACD,SAAS;QACnB;IACF;IAEA,IAAI,CAACN,qBAAqBR,OAAOC,IAAI,CAACI,OAAOI,MAAM,KAAK,KAAK,IAAI,CAACO,iBAAiB,KAAK,MAAM;QAC5F,mHAAmH;QACnH,qHAAqH;QACrH,mHAAmH;QACnH,4BAA4B;QAC5BN,kBAAkBO,gBAAgB,GAAG;YACnC,OAAOC,QAAQC,OAAO,CACpBhC,MAAMiC,cAAc,CAACf,OAAO;gBAC1B,GAAGV,OAAO;gBACV0B,MAAM;oBAAEC,KAAK;gBAAE;YACjB;QAEJ;IACF;IAEA,IAAI5C,SAAS,GAAG;QACdgC,kBAAkBhC,KAAK,GAAGA;QAC1B,qEAAqE;QACrEgC,kBAAkBf,OAAO,CAACjB,KAAK,GAAGA;QAElC,mCAAmC;QACnC,IAAIA,UAAU,GAAG;YACfgC,kBAAkB7B,UAAU,GAAG;QACjC;IACF;IAEA,MAAM0C,SAAS,MAAMpC,MAAMqC,QAAQ,CAACnB,OAAOK;IAC3C,MAAMe,OAAOC,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACL,OAAOE,IAAI;IAElD,OAAO;QACL,GAAGF,MAAM;QACTE,MAAMA,KAAKI,GAAG,CAAC,CAACC;YACdA,IAAIC,EAAE,GAAGD,IAAIR,GAAG;YAChB,OAAOhD,uBAAuBwD;QAChC;IACF;AACF,EAAC"}
1
+ {"version":3,"sources":["../src/findGlobalVersions.ts"],"sourcesContent":["import type { PaginateOptions } from 'mongoose'\nimport type { FindGlobalVersions, PayloadRequest } from 'payload'\n\nimport { buildVersionGlobalFields, flattenWhereToOperators } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildSortParam } from './queries/buildSortParam.js'\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js'\nimport { withSession } from './withSession.js'\n\nexport const findGlobalVersions: FindGlobalVersions = async function findGlobalVersions(\n this: MongooseAdapter,\n {\n global,\n limit,\n locale,\n page,\n pagination,\n req = {} as PayloadRequest,\n select,\n skip,\n sort: sortArg,\n where,\n },\n) {\n const Model = this.versions[global]\n const versionFields = buildVersionGlobalFields(\n this.payload.config,\n this.payload.globals.config.find(({ slug }) => slug === global),\n )\n const options = {\n ...(await withSession(this, req)),\n limit,\n skip,\n }\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: versionFields,\n locale,\n sort: sortArg || '-updatedAt',\n timestamps: true,\n })\n }\n\n const query = await Model.buildQuery({\n globalSlug: global,\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 forceCountFn: hasNearConstraint,\n lean: true,\n leanWithId: true,\n limit,\n options,\n page,\n pagination,\n projection: buildProjectionFromSelect({ adapter: this, fields: versionFields, select }),\n sort,\n useEstimatedCount,\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 const result = await Model.paginate(query, paginationOptions)\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":["buildVersionGlobalFields","flattenWhereToOperators","buildSortParam","buildProjectionFromSelect","sanitizeInternalFields","withSession","findGlobalVersions","global","limit","locale","page","pagination","req","select","skip","sort","sortArg","where","Model","versions","versionFields","payload","config","globals","find","slug","options","hasNearConstraint","constraints","some","prop","Object","keys","key","fields","timestamps","query","buildQuery","globalSlug","useEstimatedCount","length","paginationOptions","forceCountFn","lean","leanWithId","projection","adapter","collation","defaultLocale","disableIndexHints","useCustomCountFn","Promise","resolve","countDocuments","hint","_id","result","paginate","docs","JSON","parse","stringify","map","doc","id"],"mappings":"AAGA,SAASA,wBAAwB,EAAEC,uBAAuB,QAAQ,UAAS;AAI3E,SAASC,cAAc,QAAQ,8BAA6B;AAC5D,SAASC,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,sBAAsB,QAAQ,wCAAuC;AAC9E,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,qBAAyC,eAAeA,mBAEnE,EACEC,MAAM,EACNC,KAAK,EACLC,MAAM,EACNC,IAAI,EACJC,UAAU,EACVC,MAAM,CAAC,CAAmB,EAC1BC,MAAM,EACNC,IAAI,EACJC,MAAMC,OAAO,EACbC,KAAK,EACN;IAED,MAAMC,QAAQ,IAAI,CAACC,QAAQ,CAACZ,OAAO;IACnC,MAAMa,gBAAgBpB,yBACpB,IAAI,CAACqB,OAAO,CAACC,MAAM,EACnB,IAAI,CAACD,OAAO,CAACE,OAAO,CAACD,MAAM,CAACE,IAAI,CAA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QAC5BR,kBAAkBS,gBAAgB,GAAG;YACnC,OAAOC,QAAQC,OAAO,CACpBlC,MAAMmC,cAAc,CAACjB,OAAO;gBAC1B,GAAGV,OAAO;gBACV4B,MAAM;oBAAEC,KAAK;gBAAE;YACjB;QAEJ;IACF;IAEA,IAAI/C,SAAS,GAAG;QACdiC,kBAAkBjC,KAAK,GAAGA;QAC1B,qEAAqE;QACrEiC,kBAAkBf,OAAO,CAAClB,KAAK,GAAGA;QAElC,mCAAmC;QACnC,IAAIA,UAAU,GAAG;YACfiC,kBAAkB9B,UAAU,GAAG;QACjC;IACF;IAEA,MAAM6C,SAAS,MAAMtC,MAAMuC,QAAQ,CAACrB,OAAOK;IAC3C,MAAMiB,OAAOC,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACL,OAAOE,IAAI;IAElD,OAAO;QACL,GAAGF,MAAM;QACTE,MAAMA,KAAKI,GAAG,CAAC,CAACC;YACdA,IAAIC,EAAE,GAAGD,IAAIR,GAAG;YAChB,OAAOnD,uBAAuB2D;QAChC;IACF;AACF,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"findOne.d.ts","sourceRoot":"","sources":["../src/findOne.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAY,OAAO,EAAkB,MAAM,SAAS,CAAA;AAQhE,eAAO,MAAM,OAAO,EAAE,OA6CrB,CAAA"}
1
+ {"version":3,"file":"findOne.d.ts","sourceRoot":"","sources":["../src/findOne.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAY,OAAO,EAAkB,MAAM,SAAS,CAAA;AAShE,eAAO,MAAM,OAAO,EAAE,OAqDrB,CAAA"}
package/dist/findOne.js CHANGED
@@ -1,7 +1,8 @@
1
1
  import { buildJoinAggregation } from './utilities/buildJoinAggregation.js';
2
+ import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
2
3
  import { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js';
3
4
  import { withSession } from './withSession.js';
4
- export const findOne = async function findOne({ collection, joins, locale, req = {}, where }) {
5
+ export const findOne = async function findOne({ collection, joins, locale, req = {}, select, where }) {
5
6
  const Model = this.collections[collection];
6
7
  const collectionConfig = this.payload.collections[collection].config;
7
8
  const options = {
@@ -13,6 +14,11 @@ export const findOne = async function findOne({ collection, joins, locale, req =
13
14
  payload: this.payload,
14
15
  where
15
16
  });
17
+ const projection = buildProjectionFromSelect({
18
+ adapter: this,
19
+ fields: collectionConfig.fields,
20
+ select
21
+ });
16
22
  const aggregate = await buildJoinAggregation({
17
23
  adapter: this,
18
24
  collection,
@@ -20,12 +26,14 @@ export const findOne = async function findOne({ collection, joins, locale, req =
20
26
  joins,
21
27
  limit: 1,
22
28
  locale,
29
+ projection,
23
30
  query
24
31
  });
25
32
  let doc;
26
33
  if (aggregate) {
27
34
  [doc] = await Model.aggregate(aggregate, options);
28
35
  } else {
36
+ options.projection = projection;
29
37
  doc = await Model.findOne(query, {}, options);
30
38
  }
31
39
  if (!doc) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/findOne.ts"],"sourcesContent":["import type { MongooseQueryOptions } from 'mongoose'\nimport type { Document, FindOne, PayloadRequest } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildJoinAggregation } from './utilities/buildJoinAggregation.js'\nimport { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js'\nimport { withSession } from './withSession.js'\n\nexport const findOne: FindOne = async function findOne(\n this: MongooseAdapter,\n { collection, joins, locale, req = {} as PayloadRequest, where },\n) {\n const Model = this.collections[collection]\n const collectionConfig = this.payload.collections[collection].config\n const options: MongooseQueryOptions = {\n ...(await withSession(this, req)),\n lean: true,\n }\n\n const query = await Model.buildQuery({\n locale,\n payload: this.payload,\n where,\n })\n\n const aggregate = await buildJoinAggregation({\n adapter: this,\n collection,\n collectionConfig,\n joins,\n limit: 1,\n locale,\n query,\n })\n\n let doc\n if (aggregate) {\n ;[doc] = await Model.aggregate(aggregate, options)\n } else {\n doc = await Model.findOne(query, {}, options)\n }\n\n if (!doc) {\n return null\n }\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":["buildJoinAggregation","sanitizeInternalFields","withSession","findOne","collection","joins","locale","req","where","Model","collections","collectionConfig","payload","config","options","lean","query","buildQuery","aggregate","adapter","limit","doc","result","JSON","parse","stringify","id","_id"],"mappings":"AAKA,SAASA,oBAAoB,QAAQ,sCAAqC;AAC1E,SAASC,sBAAsB,QAAQ,wCAAuC;AAC9E,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,UAAmB,eAAeA,QAE7C,EAAEC,UAAU,EAAEC,KAAK,EAAEC,MAAM,EAAEC,MAAM,CAAC,CAAmB,EAAEC,KAAK,EAAE;IAEhE,MAAMC,QAAQ,IAAI,CAACC,WAAW,CAACN,WAAW;IAC1C,MAAMO,mBAAmB,IAAI,CAACC,OAAO,CAACF,WAAW,CAACN,WAAW,CAACS,MAAM;IACpE,MAAMC,UAAgC;QACpC,GAAI,MAAMZ,YAAY,IAAI,EAAEK,IAAI;QAChCQ,MAAM;IACR;IAEA,MAAMC,QAAQ,MAAMP,MAAMQ,UAAU,CAAC;QACnCX;QACAM,SAAS,IAAI,CAACA,OAAO;QACrBJ;IACF;IAEA,MAAMU,YAAY,MAAMlB,qBAAqB;QAC3CmB,SAAS,IAAI;QACbf;QACAO;QACAN;QACAe,OAAO;QACPd;QACAU;IACF;IAEA,IAAIK;IACJ,IAAIH,WAAW;QACZ,CAACG,IAAI,GAAG,MAAMZ,MAAMS,SAAS,CAACA,WAAWJ;IAC5C,OAAO;QACLO,MAAM,MAAMZ,MAAMN,OAAO,CAACa,OAAO,CAAC,GAAGF;IACvC;IAEA,IAAI,CAACO,KAAK;QACR,OAAO;IACT;IAEA,IAAIC,SAAmBC,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACJ;IAEjD,uBAAuB;IACvBC,OAAOI,EAAE,GAAGJ,OAAOK,GAAG;IACtBL,SAASrB,uBAAuBqB;IAEhC,OAAOA;AACT,EAAC"}
1
+ {"version":3,"sources":["../src/findOne.ts"],"sourcesContent":["import type { MongooseQueryOptions, QueryOptions } from 'mongoose'\nimport type { Document, FindOne, PayloadRequest } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\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 findOne: FindOne = async function findOne(\n this: MongooseAdapter,\n { collection, joins, locale, req = {} as PayloadRequest, select, where },\n) {\n const Model = this.collections[collection]\n const collectionConfig = this.payload.collections[collection].config\n const options: MongooseQueryOptions = {\n ...(await withSession(this, req)),\n lean: true,\n }\n\n const query = await Model.buildQuery({\n locale,\n payload: this.payload,\n where,\n })\n\n const projection = buildProjectionFromSelect({\n adapter: this,\n fields: collectionConfig.fields,\n select,\n })\n\n const aggregate = await buildJoinAggregation({\n adapter: this,\n collection,\n collectionConfig,\n joins,\n limit: 1,\n locale,\n projection,\n query,\n })\n\n let doc\n if (aggregate) {\n ;[doc] = await Model.aggregate(aggregate, options)\n } else {\n ;(options as Record<string, unknown>).projection = projection\n doc = await Model.findOne(query, {}, options)\n }\n\n if (!doc) {\n return null\n }\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":["buildJoinAggregation","buildProjectionFromSelect","sanitizeInternalFields","withSession","findOne","collection","joins","locale","req","select","where","Model","collections","collectionConfig","payload","config","options","lean","query","buildQuery","projection","adapter","fields","aggregate","limit","doc","result","JSON","parse","stringify","id","_id"],"mappings":"AAKA,SAASA,oBAAoB,QAAQ,sCAAqC;AAC1E,SAASC,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,sBAAsB,QAAQ,wCAAuC;AAC9E,SAAS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;AAU3D,eAAO,MAAM,YAAY,EAAE,YAwG1B,CAAA"}
1
+ {"version":3,"file":"findVersions.d.ts","sourceRoot":"","sources":["../src/findVersions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAkB,MAAM,SAAS,CAAA;AAW3D,eAAO,MAAM,YAAY,EAAE,YA8G1B,CAAA"}
@@ -1,8 +1,9 @@
1
- import { flattenWhereToOperators } from 'payload';
1
+ import { buildVersionCollectionFields, flattenWhereToOperators } from 'payload';
2
2
  import { buildSortParam } from './queries/buildSortParam.js';
3
+ import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
3
4
  import { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js';
4
5
  import { withSession } from './withSession.js';
5
- export const findVersions = async function findVersions({ collection, limit, locale, page, pagination, req = {}, skip, sort: sortArg, where }) {
6
+ export const findVersions = async function findVersions({ collection, limit, locale, page, pagination, req = {}, select, skip, sort: sortArg, where }) {
6
7
  const Model = this.versions[collection];
7
8
  const collectionConfig = this.payload.collections[collection].config;
8
9
  const options = {
@@ -40,6 +41,11 @@ export const findVersions = async function findVersions({ collection, limit, loc
40
41
  options,
41
42
  page,
42
43
  pagination,
44
+ projection: buildProjectionFromSelect({
45
+ adapter: this,
46
+ fields: buildVersionCollectionFields(this.payload.config, collectionConfig),
47
+ select
48
+ }),
43
49
  sort,
44
50
  useEstimatedCount
45
51
  };