@payloadcms/db-mongodb 3.0.0-canary.b922438 → 3.0.0-canary.bda91d8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (138) hide show
  1. package/dist/connect.d.ts.map +1 -1
  2. package/dist/connect.js +7 -3
  3. package/dist/connect.js.map +1 -1
  4. package/dist/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 +10 -1
  14. package/dist/create.js.map +1 -1
  15. package/dist/createGlobal.d.ts.map +1 -1
  16. package/dist/createGlobal.js +10 -5
  17. package/dist/createGlobal.js.map +1 -1
  18. package/dist/createGlobalVersion.d.ts +1 -1
  19. package/dist/createGlobalVersion.d.ts.map +1 -1
  20. package/dist/createGlobalVersion.js +13 -4
  21. package/dist/createGlobalVersion.js.map +1 -1
  22. package/dist/createMigration.d.ts.map +1 -1
  23. package/dist/createMigration.js +8 -6
  24. package/dist/createMigration.js.map +1 -1
  25. package/dist/createVersion.d.ts +1 -1
  26. package/dist/createVersion.d.ts.map +1 -1
  27. package/dist/createVersion.js +31 -9
  28. package/dist/createVersion.js.map +1 -1
  29. package/dist/deleteOne.d.ts.map +1 -1
  30. package/dist/deleteOne.js +11 -3
  31. package/dist/deleteOne.js.map +1 -1
  32. package/dist/find.d.ts.map +1 -1
  33. package/dist/find.js +27 -3
  34. package/dist/find.js.map +1 -1
  35. package/dist/findGlobal.d.ts.map +1 -1
  36. package/dist/findGlobal.js +9 -3
  37. package/dist/findGlobal.js.map +1 -1
  38. package/dist/findGlobalVersions.d.ts.map +1 -1
  39. package/dist/findGlobalVersions.js +9 -3
  40. package/dist/findGlobalVersions.js.map +1 -1
  41. package/dist/findOne.d.ts.map +1 -1
  42. package/dist/findOne.js +27 -3
  43. package/dist/findOne.js.map +1 -1
  44. package/dist/findVersions.d.ts.map +1 -1
  45. package/dist/findVersions.js +9 -3
  46. package/dist/findVersions.js.map +1 -1
  47. package/dist/index.d.ts +6 -3
  48. package/dist/index.d.ts.map +1 -1
  49. package/dist/index.js +15 -6
  50. package/dist/index.js.map +1 -1
  51. package/dist/init.d.ts.map +1 -1
  52. package/dist/init.js +9 -6
  53. package/dist/init.js.map +1 -1
  54. package/dist/models/buildCollectionSchema.d.ts +1 -2
  55. package/dist/models/buildCollectionSchema.d.ts.map +1 -1
  56. package/dist/models/buildCollectionSchema.js +16 -4
  57. package/dist/models/buildCollectionSchema.js.map +1 -1
  58. package/dist/models/buildGlobalModel.js +2 -2
  59. package/dist/models/buildGlobalModel.js.map +1 -1
  60. package/dist/models/buildSchema.d.ts +1 -2
  61. package/dist/models/buildSchema.d.ts.map +1 -1
  62. package/dist/models/buildSchema.js +104 -12
  63. package/dist/models/buildSchema.js.map +1 -1
  64. package/dist/queries/buildQuery.d.ts +2 -2
  65. package/dist/queries/buildQuery.d.ts.map +1 -1
  66. package/dist/queries/buildQuery.js +1 -2
  67. package/dist/queries/buildQuery.js.map +1 -1
  68. package/dist/queries/buildSearchParams.d.ts.map +1 -1
  69. package/dist/queries/buildSearchParams.js +19 -11
  70. package/dist/queries/buildSearchParams.js.map +1 -1
  71. package/dist/queries/buildSortParam.d.ts +2 -2
  72. package/dist/queries/buildSortParam.d.ts.map +1 -1
  73. package/dist/queries/buildSortParam.js +26 -17
  74. package/dist/queries/buildSortParam.js.map +1 -1
  75. package/dist/queries/getLocalizedSortProperty.spec.js +1 -1
  76. package/dist/queries/getLocalizedSortProperty.spec.js.map +1 -1
  77. package/dist/queries/parseParams.d.ts.map +1 -1
  78. package/dist/queries/parseParams.js +3 -1
  79. package/dist/queries/parseParams.js.map +1 -1
  80. package/dist/queries/sanitizeQueryValue.d.ts.map +1 -1
  81. package/dist/queries/sanitizeQueryValue.js +145 -26
  82. package/dist/queries/sanitizeQueryValue.js.map +1 -1
  83. package/dist/queryDrafts.d.ts.map +1 -1
  84. package/dist/queryDrafts.js +29 -7
  85. package/dist/queryDrafts.js.map +1 -1
  86. package/dist/transactions/beginTransaction.d.ts.map +1 -1
  87. package/dist/transactions/beginTransaction.js +2 -0
  88. package/dist/transactions/beginTransaction.js.map +1 -1
  89. package/dist/transactions/commitTransaction.d.ts.map +1 -1
  90. package/dist/transactions/commitTransaction.js +3 -1
  91. package/dist/transactions/commitTransaction.js.map +1 -1
  92. package/dist/types.d.ts +7 -4
  93. package/dist/types.d.ts.map +1 -1
  94. package/dist/types.js.map +1 -1
  95. package/dist/updateGlobal.d.ts.map +1 -1
  96. package/dist/updateGlobal.js +17 -4
  97. package/dist/updateGlobal.js.map +1 -1
  98. package/dist/updateGlobalVersion.d.ts +2 -2
  99. package/dist/updateGlobalVersion.d.ts.map +1 -1
  100. package/dist/updateGlobalVersion.js +18 -4
  101. package/dist/updateGlobalVersion.js.map +1 -1
  102. package/dist/updateOne.d.ts.map +1 -1
  103. package/dist/updateOne.js +18 -4
  104. package/dist/updateOne.js.map +1 -1
  105. package/dist/updateVersion.d.ts +1 -1
  106. package/dist/updateVersion.d.ts.map +1 -1
  107. package/dist/updateVersion.js +17 -3
  108. package/dist/updateVersion.js.map +1 -1
  109. package/dist/upsert.d.ts +3 -0
  110. package/dist/upsert.d.ts.map +1 -0
  111. package/dist/upsert.js +15 -0
  112. package/dist/upsert.js.map +1 -0
  113. package/dist/utilities/buildJoinAggregation.d.ts +18 -0
  114. package/dist/utilities/buildJoinAggregation.d.ts.map +1 -0
  115. package/dist/utilities/buildJoinAggregation.js +159 -0
  116. package/dist/utilities/buildJoinAggregation.js.map +1 -0
  117. package/dist/utilities/buildProjectionFromSelect.d.ts +8 -0
  118. package/dist/utilities/buildProjectionFromSelect.d.ts.map +1 -0
  119. package/dist/utilities/buildProjectionFromSelect.js +171 -0
  120. package/dist/utilities/buildProjectionFromSelect.js.map +1 -0
  121. package/dist/utilities/getDBName.d.ts.map +1 -1
  122. package/dist/utilities/getDBName.js +3 -1
  123. package/dist/utilities/getDBName.js.map +1 -1
  124. package/dist/utilities/handleError.js +2 -2
  125. package/dist/utilities/handleError.js.map +1 -1
  126. package/dist/utilities/sanitizeInternalFields.d.ts +1 -2
  127. package/dist/utilities/sanitizeInternalFields.d.ts.map +1 -1
  128. package/dist/utilities/sanitizeInternalFields.js +1 -2
  129. package/dist/utilities/sanitizeInternalFields.js.map +1 -1
  130. package/dist/utilities/sanitizeRelationshipIDs.d.ts +9 -0
  131. package/dist/utilities/sanitizeRelationshipIDs.d.ts.map +1 -0
  132. package/dist/utilities/sanitizeRelationshipIDs.js +115 -0
  133. package/dist/utilities/sanitizeRelationshipIDs.js.map +1 -0
  134. package/dist/withSession.d.ts +1 -1
  135. package/dist/withSession.d.ts.map +1 -1
  136. package/dist/withSession.js +5 -3
  137. package/dist/withSession.js.map +1 -1
  138. package/package.json +9 -6
@@ -1,8 +1,10 @@
1
- import { combineQueries, flattenWhereToOperators } from 'payload';
1
+ import { buildVersionCollectionFields, combineQueries, flattenWhereToOperators } from 'payload';
2
2
  import { buildSortParam } from './queries/buildSortParam.js';
3
- import sanitizeInternalFields from './utilities/sanitizeInternalFields.js';
3
+ import { buildJoinAggregation } from './utilities/buildJoinAggregation.js';
4
+ import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
5
+ import { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js';
4
6
  import { withSession } from './withSession.js';
5
- export const queryDrafts = async function queryDrafts({ collection, limit, locale, page, pagination, req = {}, sort: sortArg, where }) {
7
+ export const queryDrafts = async function queryDrafts({ collection, joins, limit, locale, page, pagination, req = {}, select, sort: sortArg, where }) {
6
8
  const VersionModel = this.versions[collection];
7
9
  const collectionConfig = this.payload.collections[collection].config;
8
10
  const options = await withSession(this, req);
@@ -31,6 +33,11 @@ export const queryDrafts = async function queryDrafts({ collection, limit, local
31
33
  payload: this.payload,
32
34
  where: combinedWhere
33
35
  });
36
+ const projection = buildProjectionFromSelect({
37
+ adapter: this,
38
+ fields: buildVersionCollectionFields(this.payload.config, collectionConfig),
39
+ select
40
+ });
34
41
  // useEstimatedCount is faster, but not accurate, as it ignores any filters. It is thus set to true if there are no filters.
35
42
  const useEstimatedCount = hasNearConstraint || !versionQuery || Object.keys(versionQuery).length === 0;
36
43
  const paginationOptions = {
@@ -40,6 +47,7 @@ export const queryDrafts = async function queryDrafts({ collection, limit, local
40
47
  options,
41
48
  page,
42
49
  pagination,
50
+ projection,
43
51
  sort,
44
52
  useEstimatedCount
45
53
  };
@@ -68,7 +76,23 @@ export const queryDrafts = async function queryDrafts({ collection, limit, local
68
76
  // limit must also be set here, it's ignored when pagination is false
69
77
  paginationOptions.options.limit = limit;
70
78
  }
71
- const result = await VersionModel.paginate(versionQuery, paginationOptions);
79
+ let result;
80
+ const aggregate = await buildJoinAggregation({
81
+ adapter: this,
82
+ collection,
83
+ collectionConfig,
84
+ joins,
85
+ locale,
86
+ projection,
87
+ query: versionQuery,
88
+ versions: true
89
+ });
90
+ // build join aggregation
91
+ if (aggregate) {
92
+ result = await VersionModel.aggregatePaginate(VersionModel.aggregate(aggregate), paginationOptions);
93
+ } else {
94
+ result = await VersionModel.paginate(versionQuery, paginationOptions);
95
+ }
72
96
  const docs = JSON.parse(JSON.stringify(result.docs));
73
97
  return {
74
98
  ...result,
@@ -76,9 +100,7 @@ export const queryDrafts = async function queryDrafts({ collection, limit, local
76
100
  doc = {
77
101
  _id: doc.parent,
78
102
  id: doc.parent,
79
- ...doc.version,
80
- createdAt: doc.createdAt,
81
- updatedAt: doc.updatedAt
103
+ ...doc.version
82
104
  };
83
105
  return sanitizeInternalFields(doc);
84
106
  })
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/queryDrafts.ts"],"sourcesContent":["import type { PaginateOptions } from 'mongoose'\nimport type { PayloadRequest, QueryDrafts } from 'payload'\n\nimport { combineQueries, 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 queryDrafts: QueryDrafts = async function queryDrafts(\n this: MongooseAdapter,\n { collection, limit, locale, page, pagination, req = {} as PayloadRequest, sort: sortArg, where },\n) {\n const VersionModel = this.versions[collection]\n const collectionConfig = this.payload.collections[collection].config\n const options = await withSession(this, req)\n\n let hasNearConstraint\n let sort\n\n if (where) {\n const constraints = flattenWhereToOperators(where)\n hasNearConstraint = constraints.some((prop) => Object.keys(prop).some((key) => key === 'near'))\n }\n\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 combinedWhere = combineQueries({ latest: { equals: true } }, where)\n\n const versionQuery = await VersionModel.buildQuery({\n locale,\n payload: this.payload,\n where: combinedWhere,\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 =\n hasNearConstraint || !versionQuery || Object.keys(versionQuery).length === 0\n const paginationOptions: PaginateOptions = {\n forceCountFn: hasNearConstraint,\n lean: true,\n leanWithId: true,\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 (\n !useEstimatedCount &&\n Object.keys(versionQuery).length === 0 &&\n this.disableIndexHints !== true\n ) {\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 VersionModel.countDocuments(versionQuery, {\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\n const result = await VersionModel.paginate(versionQuery, paginationOptions)\n const docs = JSON.parse(JSON.stringify(result.docs))\n\n return {\n ...result,\n docs: docs.map((doc) => {\n doc = {\n _id: doc.parent,\n id: doc.parent,\n ...doc.version,\n createdAt: doc.createdAt,\n updatedAt: doc.updatedAt,\n }\n\n return sanitizeInternalFields(doc)\n }),\n }\n}\n"],"names":["combineQueries","flattenWhereToOperators","buildSortParam","sanitizeInternalFields","withSession","queryDrafts","collection","limit","locale","page","pagination","req","sort","sortArg","where","VersionModel","versions","collectionConfig","payload","collections","config","options","hasNearConstraint","constraints","some","prop","Object","keys","key","fields","defaultSort","timestamps","combinedWhere","latest","equals","versionQuery","buildQuery","useEstimatedCount","length","paginationOptions","forceCountFn","lean","leanWithId","collation","defaultLocale","disableIndexHints","useCustomCountFn","Promise","resolve","countDocuments","hint","_id","result","paginate","docs","JSON","parse","stringify","map","doc","parent","id","version","createdAt","updatedAt"],"mappings":"AAGA,SAASA,cAAc,EAAEC,uBAAuB,QAAQ,UAAS;AAIjE,SAASC,cAAc,QAAQ,8BAA6B;AAC5D,OAAOC,4BAA4B,wCAAuC;AAC1E,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,cAA2B,eAAeA,YAErD,EAAEC,UAAU,EAAEC,KAAK,EAAEC,MAAM,EAAEC,IAAI,EAAEC,UAAU,EAAEC,MAAM,CAAC,CAAmB,EAAEC,MAAMC,OAAO,EAAEC,KAAK,EAAE;IAEjG,MAAMC,eAAe,IAAI,CAACC,QAAQ,CAACV,WAAW;IAC9C,MAAMW,mBAAmB,IAAI,CAACC,OAAO,CAACC,WAAW,CAACb,WAAW,CAACc,MAAM;IACpE,MAAMC,UAAU,MAAMjB,YAAY,IAAI,EAAEO;IAExC,IAAIW;IACJ,IAAIV;IAEJ,IAAIE,O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IAAI5C,QAAQ,GAAG;QACbgC,kBAAkBhC,KAAK,GAAGA;QAC1B,qEAAqE;QACrEgC,kBAAkBlB,OAAO,CAACd,KAAK,GAAGA;IACpC;IAEA,MAAM6C,SAAS,MAAMrC,aAAasC,QAAQ,CAAClB,cAAcI;IACzD,MAAMe,OAAOC,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACL,OAAOE,IAAI;IAElD,OAAO;QACL,GAAGF,MAAM;QACTE,MAAMA,KAAKI,GAAG,CAAC,CAACC;YACdA,MAAM;gBACJR,KAAKQ,IAAIC,MAAM;gBACfC,IAAIF,IAAIC,MAAM;gBACd,GAAGD,IAAIG,OAAO;gBACdC,WAAWJ,IAAII,SAAS;gBACxBC,WAAWL,IAAIK,SAAS;YAC1B;YAEA,OAAO7D,uBAAuBwD;QAChC;IACF;AACF,EAAC"}
1
+ {"version":3,"sources":["../src/queryDrafts.ts"],"sourcesContent":["import type { PaginateOptions } from 'mongoose'\nimport type { PayloadRequest, QueryDrafts } from 'payload'\n\nimport { buildVersionCollectionFields, combineQueries, 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 queryDrafts: QueryDrafts = async function queryDrafts(\n this: MongooseAdapter,\n {\n collection,\n joins,\n limit,\n locale,\n page,\n pagination,\n req = {} as PayloadRequest,\n select,\n sort: sortArg,\n where,\n },\n) {\n const VersionModel = this.versions[collection]\n const collectionConfig = this.payload.collections[collection].config\n const options = await withSession(this, req)\n\n let hasNearConstraint\n let sort\n\n if (where) {\n const constraints = flattenWhereToOperators(where)\n hasNearConstraint = constraints.some((prop) => Object.keys(prop).some((key) => key === 'near'))\n }\n\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 combinedWhere = combineQueries({ latest: { equals: true } }, where)\n\n const versionQuery = await VersionModel.buildQuery({\n locale,\n payload: this.payload,\n where: combinedWhere,\n })\n\n const projection = buildProjectionFromSelect({\n adapter: this,\n fields: buildVersionCollectionFields(this.payload.config, collectionConfig),\n select,\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 =\n hasNearConstraint || !versionQuery || Object.keys(versionQuery).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 (\n !useEstimatedCount &&\n Object.keys(versionQuery).length === 0 &&\n this.disableIndexHints !== true\n ) {\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 VersionModel.countDocuments(versionQuery, {\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\n let result\n\n const aggregate = await buildJoinAggregation({\n adapter: this,\n collection,\n collectionConfig,\n joins,\n locale,\n projection,\n query: versionQuery,\n versions: true,\n })\n\n // build join aggregation\n if (aggregate) {\n result = await VersionModel.aggregatePaginate(\n VersionModel.aggregate(aggregate),\n paginationOptions,\n )\n } else {\n result = await VersionModel.paginate(versionQuery, paginationOptions)\n }\n\n const docs = JSON.parse(JSON.stringify(result.docs))\n\n return {\n ...result,\n docs: docs.map((doc) => {\n doc = {\n _id: doc.parent,\n id: doc.parent,\n ...doc.version,\n }\n\n return sanitizeInternalFields(doc)\n }),\n }\n}\n"],"names":["buildVersionCollectionFields","combineQueries","flattenWhereToOperators","buildSortParam","buildJoinAggregation","buildProjectionFromSelect","sanitizeInternalFields","withSession","queryDrafts","collection","joins","limit","locale","page","pagination","req","select","sort","sortArg","where","VersionModel","versions","collectionConfig","payload","collections","config","options","hasNearConstraint","constraints","some","prop","Object","keys","key","fields","defaultSort","timestamps","combinedWhere","latest","equals","versionQuery","buildQuery","projection","adapter","useEstimatedCount","length","paginationOptions","forceCountFn","lean","leanWithId","collation","defaultLocale","disableIndexHints","useCustomCountFn","Promise","resolve","countDocuments","hint","_id","result","aggregate","query","aggregatePaginate","paginate","docs","JSON","parse","stringify","map","doc","parent","id","version"],"mappings":"AAGA,SAASA,4BAA4B,EAAEC,cAAc,EAAEC,uBAAuB,QAAQ,UAAS;AAI/F,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,cAA2B,eAAeA,YAErD,EACEC,UAAU,EACVC,KAAK,EACLC,KAAK,EACLC,MAAM,EACNC,IAAI,EACJC,UAAU,EACVC,MAAM,CAAC,CAAmB,EAC1BC,MAAM,EACNC,MAAMC,OAAO,EACbC,KAAK,EACN;IAED,MAAMC,eAAe,IAAI,CAACC,QAAQ,CAACZ,WAAW;IAC9C,MAAMa,mBAAmB,IAAI,CAACC,OAAO,CAACC,WAAW,CAACf,WAAW,CAACgB,MAAM;IACpE,MAAMC,UAAU,MAAMnB,YAAY,IAAI,EAAEQ;IAExC,IAAIY;IACJ,IAAIV;IAEJ,IAAIE,OAAO;QACT,MAAMS,cA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ACnC,OAAOC,QAAQC,OAAO,CACpBnC,aAAaoC,cAAc,CAAChB,cAAc;gBACxCiB,MAAM;oBAAEC,KAAK;gBAAE;YACjB;QAEJ;IACF;IAEA,IAAI/C,QAAQ,GAAG;QACbmC,kBAAkBnC,KAAK,GAAGA;QAC1B,qEAAqE;QACrEmC,kBAAkBpB,OAAO,CAACf,KAAK,GAAGA;IACpC;IAEA,IAAIgD;IAEJ,MAAMC,YAAY,MAAMxD,qBAAqB;QAC3CuC,SAAS,IAAI;QACblC;QACAa;QACAZ;QACAE;QACA8B;QACAmB,OAAOrB;QACPnB,UAAU;IACZ;IAEA,yBAAyB;IACzB,IAAIuC,WAAW;QACbD,SAAS,MAAMvC,aAAa0C,iBAAiB,CAC3C1C,aAAawC,SAAS,CAACA,YACvBd;IAEJ,OAAO;QACLa,SAAS,MAAMvC,aAAa2C,QAAQ,CAACvB,cAAcM;IACrD;IAEA,MAAMkB,OAAOC,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACR,OAAOK,IAAI;IAElD,OAAO;QACL,GAAGL,MAAM;QACTK,MAAMA,KAAKI,GAAG,CAAC,CAACC;YACdA,MAAM;gBACJX,KAAKW,IAAIC,MAAM;gBACfC,IAAIF,IAAIC,MAAM;gBACd,GAAGD,IAAIG,OAAO;YAChB;YAEA,OAAOlE,uBAAuB+D;QAChC;IACF;AACF,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"beginTransaction.d.ts","sourceRoot":"","sources":["../../src/transactions/beginTransaction.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAO/C,eAAO,MAAM,gBAAgB,EAAE,gBAqB9B,CAAA"}
1
+ {"version":3,"file":"beginTransaction.d.ts","sourceRoot":"","sources":["../../src/transactions/beginTransaction.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAS/C,eAAO,MAAM,gBAAgB,EAAE,gBAqB9B,CAAA"}
@@ -1,5 +1,7 @@
1
1
  import { APIError } from 'payload';
2
2
  import { v4 as uuid } from 'uuid';
3
+ // Needs await to fulfill the interface
4
+ // eslint-disable-next-line @typescript-eslint/require-await
3
5
  export const beginTransaction = async function beginTransaction(options) {
4
6
  if (!this.connection) {
5
7
  throw new APIError('beginTransaction called while no connection to the database exists');
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/transactions/beginTransaction.ts"],"sourcesContent":["import type { TransactionOptions } from 'mongodb'\nimport type { BeginTransaction } from 'payload'\n\nimport { APIError } from 'payload'\nimport { v4 as uuid } from 'uuid'\n\nimport type { MongooseAdapter } from '../index.js'\n\nexport const beginTransaction: BeginTransaction = async function beginTransaction(\n this: MongooseAdapter,\n options: TransactionOptions,\n) {\n if (!this.connection) {\n throw new APIError('beginTransaction called while no connection to the database exists')\n }\n\n const client = this.connection.getClient()\n const id = uuid()\n\n if (!this.sessions[id]) {\n this.sessions[id] = client.startSession()\n }\n if (this.sessions[id].inTransaction()) {\n this.payload.logger.warn('beginTransaction called while transaction already exists')\n } else {\n this.sessions[id].startTransaction(options || (this.transactionOptions as TransactionOptions))\n }\n\n return id\n}\n"],"names":["APIError","v4","uuid","beginTransaction","options","connection","client","getClient","id","sessions","startSession","inTransaction","payload","logger","warn","startTransaction","transactionOptions"],"mappings":"AAGA,SAASA,QAAQ,QAAQ,UAAS;AAClC,SAASC,MAAMC,IAAI,QAAQ,OAAM;AAIjC,OAAO,MAAMC,mBAAqC,eAAeA,iBAE/DC,OAA2B;IAE3B,IAAI,CAAC,IAAI,CAACC,UAAU,EAAE;QACpB,MAAM,IAAIL,SAAS;IACrB;IAEA,MAAMM,SAAS,IAAI,CAACD,UAAU,CAACE,SAAS;IACxC,MAAMC,KAAKN;IAEX,IAAI,CAAC,IAAI,CAACO,QAAQ,CAACD,GAAG,EAAE;QACtB,IAAI,CAACC,QAAQ,CAACD,GAAG,GAAGF,OAAOI,YAAY;IACzC;IACA,IAAI,IAAI,CAACD,QAAQ,CAACD,GAAG,CAACG,aAAa,IAAI;QACrC,IAAI,CAACC,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC;IAC3B,OAAO;QACL,IAAI,CAACL,QAAQ,CAACD,GAAG,CAACO,gBAAgB,CAACX,WAAY,IAAI,CAACY,kBAAkB;IACxE;IAEA,OAAOR;AACT,EAAC"}
1
+ {"version":3,"sources":["../../src/transactions/beginTransaction.ts"],"sourcesContent":["import type { TransactionOptions } from 'mongodb'\nimport type { BeginTransaction } from 'payload'\n\nimport { APIError } from 'payload'\nimport { v4 as uuid } from 'uuid'\n\nimport type { MongooseAdapter } from '../index.js'\n\n// Needs await to fulfill the interface\n// eslint-disable-next-line @typescript-eslint/require-await\nexport const beginTransaction: BeginTransaction = async function beginTransaction(\n this: MongooseAdapter,\n options: TransactionOptions,\n) {\n if (!this.connection) {\n throw new APIError('beginTransaction called while no connection to the database exists')\n }\n\n const client = this.connection.getClient()\n const id = uuid()\n\n if (!this.sessions[id]) {\n this.sessions[id] = client.startSession()\n }\n if (this.sessions[id].inTransaction()) {\n this.payload.logger.warn('beginTransaction called while transaction already exists')\n } else {\n this.sessions[id].startTransaction(options || (this.transactionOptions as TransactionOptions))\n }\n\n return id\n}\n"],"names":["APIError","v4","uuid","beginTransaction","options","connection","client","getClient","id","sessions","startSession","inTransaction","payload","logger","warn","startTransaction","transactionOptions"],"mappings":"AAGA,SAASA,QAAQ,QAAQ,UAAS;AAClC,SAASC,MAAMC,IAAI,QAAQ,OAAM;AAIjC,uCAAuC;AACvC,4DAA4D;AAC5D,OAAO,MAAMC,mBAAqC,eAAeA,iBAE/DC,OAA2B;IAE3B,IAAI,CAAC,IAAI,CAACC,UAAU,EAAE;QACpB,MAAM,IAAIL,SAAS;IACrB;IAEA,MAAMM,SAAS,IAAI,CAACD,UAAU,CAACE,SAAS;IACxC,MAAMC,KAAKN;IAEX,IAAI,CAAC,IAAI,CAACO,QAAQ,CAACD,GAAG,EAAE;QACtB,IAAI,CAACC,QAAQ,CAACD,GAAG,GAAGF,OAAOI,YAAY;IACzC;IACA,IAAI,IAAI,CAACD,QAAQ,CAACD,GAAG,CAACG,aAAa,IAAI;QACrC,IAAI,CAACC,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC;IAC3B,OAAO;QACL,IAAI,CAACL,QAAQ,CAACD,GAAG,CAACO,gBAAgB,CAACX,WAAY,IAAI,CAACY,kBAAkB;IACxE;IAEA,OAAOR;AACT,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"commitTransaction.d.ts","sourceRoot":"","sources":["../../src/transactions/commitTransaction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAEhD,eAAO,MAAM,iBAAiB,EAAE,iBAc/B,CAAA"}
1
+ {"version":3,"file":"commitTransaction.d.ts","sourceRoot":"","sources":["../../src/transactions/commitTransaction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAEhD,eAAO,MAAM,iBAAiB,EAAE,iBAgB/B,CAAA"}
@@ -1,5 +1,7 @@
1
1
  export const commitTransaction = async function commitTransaction(id) {
2
- if (id instanceof Promise) return;
2
+ if (id instanceof Promise) {
3
+ return;
4
+ }
3
5
  if (!this.sessions[id]?.inTransaction()) {
4
6
  return;
5
7
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/transactions/commitTransaction.ts"],"sourcesContent":["import type { CommitTransaction } from 'payload'\n\nexport const commitTransaction: CommitTransaction = async function commitTransaction(id) {\n if (id instanceof Promise) return\n\n if (!this.sessions[id]?.inTransaction()) {\n return\n }\n\n await this.sessions[id].commitTransaction()\n try {\n await this.sessions[id].endSession()\n } catch (error) {\n // ending sessions is only best effort and won't impact anything if it fails since the transaction was committed\n }\n delete this.sessions[id]\n}\n"],"names":["commitTransaction","id","Promise","sessions","inTransaction","endSession","error"],"mappings":"AAEA,OAAO,MAAMA,oBAAuC,eAAeA,kBAAkBC,EAAE;IACrF,IAAIA,cAAcC,SAAS;IAE3B,IAAI,CAAC,IAAI,CAACC,QAAQ,CAACF,GAAG,EAAEG,iBAAiB;QACvC;IACF;IAEA,MAAM,IAAI,CAACD,QAAQ,CAACF,GAAG,CAACD,iBAAiB;IACzC,IAAI;QACF,MAAM,IAAI,CAACG,QAAQ,CAACF,GAAG,CAACI,UAAU;IACpC,EAAE,OAAOC,OAAO;IACd,gHAAgH;IAClH;IACA,OAAO,IAAI,CAACH,QAAQ,CAACF,GAAG;AAC1B,EAAC"}
1
+ {"version":3,"sources":["../../src/transactions/commitTransaction.ts"],"sourcesContent":["import type { CommitTransaction } from 'payload'\n\nexport const commitTransaction: CommitTransaction = async function commitTransaction(id) {\n if (id instanceof Promise) {\n return\n }\n\n if (!this.sessions[id]?.inTransaction()) {\n return\n }\n\n await this.sessions[id].commitTransaction()\n try {\n await this.sessions[id].endSession()\n } catch (error) {\n // ending sessions is only best effort and won't impact anything if it fails since the transaction was committed\n }\n delete this.sessions[id]\n}\n"],"names":["commitTransaction","id","Promise","sessions","inTransaction","endSession","error"],"mappings":"AAEA,OAAO,MAAMA,oBAAuC,eAAeA,kBAAkBC,EAAE;IACrF,IAAIA,cAAcC,SAAS;QACzB;IACF;IAEA,IAAI,CAAC,IAAI,CAACC,QAAQ,CAACF,GAAG,EAAEG,iBAAiB;QACvC;IACF;IAEA,MAAM,IAAI,CAACD,QAAQ,CAACF,GAAG,CAACD,iBAAiB;IACzC,IAAI;QACF,MAAM,IAAI,CAACG,QAAQ,CAACF,GAAG,CAACI,UAAU;IACpC,EAAE,OAAOC,OAAO;IACd,gHAAgH;IAClH;IACA,OAAO,IAAI,CAACH,QAAQ,CAACF,GAAG;AAC1B,EAAC"}
package/dist/types.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import type { IndexDefinition, IndexOptions, Model, PaginateModel, SchemaOptions } from 'mongoose';
2
- import type { ArrayField, BlockField, CheckboxField, CodeField, CollapsibleField, DateField, EmailField, Field, GroupField, JSONField, NumberField, Payload, PointField, RadioField, RelationshipField, RichTextField, RowField, SanitizedConfig, SelectField, TabsField, TextField, TextareaField, UploadField } from 'payload';
1
+ import type { AggregatePaginateModel, IndexDefinition, IndexOptions, Model, PaginateModel, SchemaOptions } from 'mongoose';
2
+ import type { ArrayField, BlocksField, CheckboxField, CodeField, CollapsibleField, DateField, EmailField, Field, GroupField, JoinField, JSONField, NumberField, Payload, PayloadRequest, PointField, RadioField, RelationshipField, RichTextField, RowField, SanitizedConfig, SelectField, TabsField, TextareaField, TextField, UploadField } from 'payload';
3
3
  import type { BuildQueryArgs } from './queries/buildQuery.js';
4
- export interface CollectionModel extends Model<any>, PaginateModel<any> {
4
+ export interface CollectionModel extends Model<any>, PaginateModel<any>, AggregatePaginateModel<any> {
5
5
  /** buildQuery is used to transform payload's where operator into what can be used by mongoose (e.g. id => _id) */
6
6
  buildQuery: (args: BuildQueryArgs) => Promise<Record<string, unknown>>;
7
7
  }
@@ -40,13 +40,14 @@ export type FieldGeneratorFunction<TSchema, TField extends Field> = (args: Field
40
40
  */
41
41
  export type FieldToSchemaMap<TSchema> = {
42
42
  array: FieldGeneratorFunction<TSchema, ArrayField>;
43
- blocks: FieldGeneratorFunction<TSchema, BlockField>;
43
+ blocks: FieldGeneratorFunction<TSchema, BlocksField>;
44
44
  checkbox: FieldGeneratorFunction<TSchema, CheckboxField>;
45
45
  code: FieldGeneratorFunction<TSchema, CodeField>;
46
46
  collapsible: FieldGeneratorFunction<TSchema, CollapsibleField>;
47
47
  date: FieldGeneratorFunction<TSchema, DateField>;
48
48
  email: FieldGeneratorFunction<TSchema, EmailField>;
49
49
  group: FieldGeneratorFunction<TSchema, GroupField>;
50
+ join: FieldGeneratorFunction<TSchema, JoinField>;
50
51
  json: FieldGeneratorFunction<TSchema, JSONField>;
51
52
  number: FieldGeneratorFunction<TSchema, NumberField>;
52
53
  point: FieldGeneratorFunction<TSchema, PointField>;
@@ -62,8 +63,10 @@ export type FieldToSchemaMap<TSchema> = {
62
63
  };
63
64
  export type MigrateUpArgs = {
64
65
  payload: Payload;
66
+ req: PayloadRequest;
65
67
  };
66
68
  export type MigrateDownArgs = {
67
69
  payload: Payload;
70
+ req: PayloadRequest;
68
71
  };
69
72
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAClG,OAAO,KAAK,EACV,UAAU,EACV,UAAU,EACV,aAAa,EACb,SAAS,EACT,gBAAgB,EAChB,SAAS,EACT,UAAU,EACV,KAAK,EACL,UAAU,EACV,SAAS,EACT,WAAW,EACX,OAAO,EACP,UAAU,EACV,UAAU,EACV,iBAAiB,EACjB,aAAa,EACb,QAAQ,EACR,eAAe,EACf,WAAW,EACX,SAAS,EACT,SAAS,EACT,aAAa,EACb,WAAW,EACZ,MAAM,SAAS,CAAA;AAEhB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AAE7D,MAAM,WAAW,eAAgB,SAAQ,KAAK,CAAC,GAAG,CAAC,EAAE,aAAa,CAAC,GAAG,CAAC;IACrE,kHAAkH;IAClH,UAAU,EAAE,CAAC,IAAI,EAAE,cAAc,KAAK,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAA;CACvE;AAED,MAAM,WAAW,mBAAoB,SAAQ,eAAe;IAC1D,uBAAuB,EAAE,IAAI,CAAA;IAC7B,kBAAkB,EAAE,MAAM,CAAA;CAC3B;AAED,MAAM,MAAM,WAAW,GAAG;IACxB,MAAM,EAAE,eAAe,CAAA;IACvB,OAAO,CAAC,EAAE,YAAY,CAAA;CACvB,CAAA;AAED,MAAM,WAAW,WAAY,SAAQ,KAAK,CAAC,QAAQ,CAAC;IAClD,UAAU,EAAE,CAAC,KA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IAAI,EAAE,sBAAsB,CAAC,OAAO,EAAE,SAAS,CAAC,CAAA;IAChD,MAAM,EAAE,sBAAsB,CAAC,OAAO,EAAE,WAAW,CAAC,CAAA;IACpD,KAAK,EAAE,sBAAsB,CAAC,OAAO,EAAE,UAAU,CAAC,CAAA;IAClD,KAAK,EAAE,sBAAsB,CAAC,OAAO,EAAE,UAAU,CAAC,CAAA;IAClD,YAAY,EAAE,sBAAsB,CAAC,OAAO,EAAE,iBAAiB,CAAC,CAAA;IAChE,QAAQ,EAAE,sBAAsB,CAAC,OAAO,EAAE,aAAa,CAAC,CAAA;IACxD,GAAG,EAAE,sBAAsB,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAA;IAC9C,MAAM,EAAE,sBAAsB,CAAC,OAAO,EAAE,WAAW,CAAC,CAAA;IACpD,IAAI,EAAE,sBAAsB,CAAC,OAAO,EAAE,SAAS,CAAC,CAAA;IAChD,IAAI,EAAE,sBAAsB,CAAC,OAAO,EAAE,SAAS,CAAC,CAAA;IAChD,QAAQ,EAAE,sBAAsB,CAAC,OAAO,EAAE,aAAa,CAAC,CAAA;IACxD,MAAM,EAAE,sBAAsB,CAAC,OAAO,EAAE,WAAW,CAAC,CAAA;CACrD,CAAA;AAED,MAAM,MAAM,aAAa,GAAG;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,GAAG,EAAE,cAAc,CAAA;CAAE,CAAA;AACrE,MAAM,MAAM,eAAe,GAAG;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,GAAG,EAAE,cAAc,CAAA;CAAE,CAAA"}
package/dist/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type { IndexDefinition, IndexOptions, Model, PaginateModel, SchemaOptions } from 'mongoose'\nimport type {\n ArrayField,\n BlockField,\n CheckboxField,\n CodeField,\n CollapsibleField,\n DateField,\n EmailField,\n Field,\n GroupField,\n JSONField,\n NumberField,\n Payload,\n PointField,\n RadioField,\n RelationshipField,\n RichTextField,\n RowField,\n SanitizedConfig,\n SelectField,\n TabsField,\n TextField,\n TextareaField,\n UploadField,\n} from 'payload'\n\nimport type { BuildQueryArgs } from './queries/buildQuery.js'\n\nexport interface CollectionModel extends Model<any>, PaginateModel<any> {\n /** buildQuery is used to transform payload's where operator into what can be used by mongoose (e.g. id => _id) */\n buildQuery: (args: BuildQueryArgs) => Promise<Record<string, unknown>> // TODO: Delete this\n}\n\nexport interface AuthCollectionModel extends CollectionModel {\n resetPasswordExpiration: Date\n resetPasswordToken: string\n}\n\nexport type TypeOfIndex = {\n fields: IndexDefinition\n options?: IndexOptions\n}\n\nexport interface GlobalModel extends Model<Document> {\n buildQuery: (query: unknown, locale?: string) => Promise<Record<string, unknown>>\n}\n\nexport type BuildSchema<TSchema> = (args: {\n config: SanitizedConfig\n fields: Field[]\n options: BuildSchemaOptions\n}) => TSchema\n\nexport type BuildSchemaOptions = {\n allowIDField?: boolean\n disableUnique?: boolean\n draftsEnabled?: boolean\n indexSortableFields?: boolean\n options?: SchemaOptions\n}\n\nexport type FieldGenerator<TSchema, TField> = {\n config: SanitizedConfig\n field: TField\n options: BuildSchemaOptions\n schema: TSchema\n}\n\n/**\n * Field config types that need representation in the database\n */\ntype FieldType =\n | 'array'\n | 'blocks'\n | 'checkbox'\n | 'code'\n | 'collapsible'\n | 'date'\n | 'email'\n | 'group'\n | 'json'\n | 'number'\n | 'point'\n | 'radio'\n | 'relationship'\n | 'richText'\n | 'row'\n | 'select'\n | 'tabs'\n | 'text'\n | 'textarea'\n | 'upload'\n\nexport type FieldGeneratorFunction<TSchema, TField extends Field> = (\n args: FieldGenerator<TSchema, TField>,\n) => void\n\n/**\n * Object mapping types to a schema based on TSchema\n */\nexport type FieldToSchemaMap<TSchema> = {\n array: FieldGeneratorFunction<TSchema, ArrayField>\n blocks: FieldGeneratorFunction<TSchema, BlockField>\n checkbox: FieldGeneratorFunction<TSchema, CheckboxField>\n code: FieldGeneratorFunction<TSchema, CodeField>\n collapsible: FieldGeneratorFunction<TSchema, CollapsibleField>\n date: FieldGeneratorFunction<TSchema, DateField>\n email: FieldGeneratorFunction<TSchema, EmailField>\n group: FieldGeneratorFunction<TSchema, GroupField>\n json: FieldGeneratorFunction<TSchema, JSONField>\n number: FieldGeneratorFunction<TSchema, NumberField>\n point: FieldGeneratorFunction<TSchema, PointField>\n radio: FieldGeneratorFunction<TSchema, RadioField>\n relationship: FieldGeneratorFunction<TSchema, RelationshipField>\n richText: FieldGeneratorFunction<TSchema, RichTextField>\n row: FieldGeneratorFunction<TSchema, RowField>\n select: FieldGeneratorFunction<TSchema, SelectField>\n tabs: FieldGeneratorFunction<TSchema, TabsField>\n text: FieldGeneratorFunction<TSchema, TextField>\n textarea: FieldGeneratorFunction<TSchema, TextareaField>\n upload: FieldGeneratorFunction<TSchema, UploadField>\n}\n\nexport type MigrateUpArgs = { payload: Payload }\nexport type MigrateDownArgs = { payload: Payload }\n"],"names":[],"mappings":"AA6HA,WAAkD"}
1
+ {"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type {\n AggregatePaginateModel,\n IndexDefinition,\n IndexOptions,\n Model,\n PaginateModel,\n SchemaOptions,\n} from 'mongoose'\nimport type {\n ArrayField,\n BlocksField,\n CheckboxField,\n CodeField,\n CollapsibleField,\n DateField,\n EmailField,\n Field,\n GroupField,\n JoinField,\n JSONField,\n NumberField,\n Payload,\n PayloadRequest,\n PointField,\n RadioField,\n RelationshipField,\n RichTextField,\n RowField,\n SanitizedConfig,\n SelectField,\n TabsField,\n TextareaField,\n TextField,\n UploadField,\n} from 'payload'\n\nimport type { BuildQueryArgs } from './queries/buildQuery.js'\n\nexport interface CollectionModel\n extends Model<any>,\n PaginateModel<any>,\n AggregatePaginateModel<any> {\n /** buildQuery is used to transform payload's where operator into what can be used by mongoose (e.g. id => _id) */\n buildQuery: (args: BuildQueryArgs) => Promise<Record<string, unknown>> // TODO: Delete this\n}\n\nexport interface AuthCollectionModel extends CollectionModel {\n resetPasswordExpiration: Date\n resetPasswordToken: string\n}\n\nexport type TypeOfIndex = {\n fields: IndexDefinition\n options?: IndexOptions\n}\n\nexport interface GlobalModel extends Model<Document> {\n buildQuery: (query: unknown, locale?: string) => Promise<Record<string, unknown>>\n}\n\nexport type BuildSchema<TSchema> = (args: {\n config: SanitizedConfig\n fields: Field[]\n options: BuildSchemaOptions\n}) => TSchema\n\nexport type BuildSchemaOptions = {\n allowIDField?: boolean\n disableUnique?: boolean\n draftsEnabled?: boolean\n indexSortableFields?: boolean\n options?: SchemaOptions\n}\n\nexport type FieldGenerator<TSchema, TField> = {\n config: SanitizedConfig\n field: TField\n options: BuildSchemaOptions\n schema: TSchema\n}\n\nexport type FieldGeneratorFunction<TSchema, TField extends Field> = (\n args: FieldGenerator<TSchema, TField>,\n) => void\n\n/**\n * Object mapping types to a schema based on TSchema\n */\nexport type FieldToSchemaMap<TSchema> = {\n array: FieldGeneratorFunction<TSchema, ArrayField>\n blocks: FieldGeneratorFunction<TSchema, BlocksField>\n checkbox: FieldGeneratorFunction<TSchema, CheckboxField>\n code: FieldGeneratorFunction<TSchema, CodeField>\n collapsible: FieldGeneratorFunction<TSchema, CollapsibleField>\n date: FieldGeneratorFunction<TSchema, DateField>\n email: FieldGeneratorFunction<TSchema, EmailField>\n group: FieldGeneratorFunction<TSchema, GroupField>\n join: FieldGeneratorFunction<TSchema, JoinField>\n json: FieldGeneratorFunction<TSchema, JSONField>\n number: FieldGeneratorFunction<TSchema, NumberField>\n point: FieldGeneratorFunction<TSchema, PointField>\n radio: FieldGeneratorFunction<TSchema, RadioField>\n relationship: FieldGeneratorFunction<TSchema, RelationshipField>\n richText: FieldGeneratorFunction<TSchema, RichTextField>\n row: FieldGeneratorFunction<TSchema, RowField>\n select: FieldGeneratorFunction<TSchema, SelectField>\n tabs: FieldGeneratorFunction<TSchema, TabsField>\n text: FieldGeneratorFunction<TSchema, TextField>\n textarea: FieldGeneratorFunction<TSchema, TextareaField>\n upload: FieldGeneratorFunction<TSchema, UploadField>\n}\n\nexport type MigrateUpArgs = { payload: Payload; req: PayloadRequest }\nexport type MigrateDownArgs = { payload: Payload; req: PayloadRequest }\n"],"names":[],"mappings":"AAiHA,WAAuE"}
@@ -1 +1 @@
1
- {"version":3,"file":"updateGlobal.d.ts","sourceRoot":"","sources":["../src/updateGlobal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAkB,YAAY,EAAE,MAAM,SAAS,CAAA;AAO3D,eAAO,MAAM,YAAY,EAAE,YAqB1B,CAAA"}
1
+ {"version":3,"file":"updateGlobal.d.ts","sourceRoot":"","sources":["../src/updateGlobal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAkB,YAAY,EAAE,MAAM,SAAS,CAAA;AAS3D,eAAO,MAAM,YAAY,EAAE,YA+B1B,CAAA"}
@@ -1,16 +1,29 @@
1
- import sanitizeInternalFields from './utilities/sanitizeInternalFields.js';
1
+ import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
2
+ import { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js';
3
+ import { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.js';
2
4
  import { withSession } from './withSession.js';
3
- export const updateGlobal = async function updateGlobal({ slug, data, req = {} }) {
5
+ export const updateGlobal = async function updateGlobal({ slug, data, req = {}, select }) {
4
6
  const Model = this.globals;
7
+ const fields = this.payload.config.globals.find((global)=>global.slug === slug).fields;
5
8
  const options = {
6
9
  ...await withSession(this, req),
7
10
  lean: true,
8
- new: true
11
+ new: true,
12
+ projection: buildProjectionFromSelect({
13
+ adapter: this,
14
+ fields,
15
+ select
16
+ })
9
17
  };
10
18
  let result;
19
+ const sanitizedData = sanitizeRelationshipIDs({
20
+ config: this.payload.config,
21
+ data,
22
+ fields
23
+ });
11
24
  result = await Model.findOneAndUpdate({
12
25
  globalType: slug
13
- }, data, options);
26
+ }, sanitizedData, options);
14
27
  result = JSON.parse(JSON.stringify(result));
15
28
  // custom id type reset
16
29
  result.id = result._id;
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/updateGlobal.ts"],"sourcesContent":["import type { PayloadRequest, UpdateGlobal } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport sanitizeInternalFields from './utilities/sanitizeInternalFields.js'\nimport { withSession } from './withSession.js'\n\nexport const updateGlobal: UpdateGlobal = async function updateGlobal(\n this: MongooseAdapter,\n { slug, data, req = {} as PayloadRequest },\n) {\n const Model = this.globals\n const options = {\n ...(await withSession(this, req)),\n lean: true,\n new: true,\n }\n\n let result\n result = await Model.findOneAndUpdate({ globalType: slug }, data, options)\n\n result = JSON.parse(JSON.stringify(result))\n\n // custom id type reset\n result.id = result._id\n result = sanitizeInternalFields(result)\n\n return result\n}\n"],"names":["sanitizeInternalFields","withSession","updateGlobal","slug","data","req","Model","globals","options","lean","new","result","findOneAndUpdate","globalType","JSON","parse","stringify","id","_id"],"mappings":"AAIA,OAAOA,4BAA4B,wCAAuC;AAC1E,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,eAA6B,eAAeA,aAEvD,EAAEC,IAAI,EAAEC,IAAI,EAAEC,MAAM,CAAC,CAAmB,EAAE;IAE1C,MAAMC,QAAQ,IAAI,CAACC,OAAO;IAC1B,MAAMC,UAAU;QACd,GAAI,MAAMP,YAAY,IAAI,EAAEI,IAAI;QAChCI,MAAM;QACNC,KAAK;IACP;IAEA,IAAIC;IACJA,SAAS,MAAML,MAAMM,gBAAgB,CAAC;QAAEC,YAAYV;IAAK,GAAGC,MAAMI;IAElEG,SAASG,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACL;IAEnC,uBAAuB;IACvBA,OAAOM,EAAE,GAAGN,OAAOO,GAAG;IACtBP,SAASX,uBAAuBW;IAEhC,OAAOA;AACT,EAAC"}
1
+ {"version":3,"sources":["../src/updateGlobal.ts"],"sourcesContent":["import type { PayloadRequest, UpdateGlobal } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js'\nimport { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.js'\nimport { withSession } from './withSession.js'\n\nexport const updateGlobal: UpdateGlobal = async function updateGlobal(\n this: MongooseAdapter,\n { slug, data, req = {} as PayloadRequest, select },\n) {\n const Model = this.globals\n const fields = this.payload.config.globals.find((global) => global.slug === slug).fields\n\n const options = {\n ...(await withSession(this, req)),\n lean: true,\n new: true,\n projection: buildProjectionFromSelect({ adapter: this, fields, select }),\n }\n\n let result\n\n const sanitizedData = sanitizeRelationshipIDs({\n config: this.payload.config,\n data,\n fields,\n })\n\n result = await Model.findOneAndUpdate({ globalType: slug }, sanitizedData, options)\n\n result = JSON.parse(JSON.stringify(result))\n\n // custom id type reset\n result.id = result._id\n result = sanitizeInternalFields(result)\n\n return result\n}\n"],"names":["buildProjectionFromSelect","sanitizeInternalFields","sanitizeRelationshipIDs","withSession","updateGlobal","slug","data","req","select","Model","globals","fields","payload","config","find","global","options","lean","new","projection","adapter","result","sanitizedData","findOneAndUpdate","globalType","JSON","parse","stringify","id","_id"],"mappings":"AAIA,SAASA,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,sBAAsB,QAAQ,wCAAuC;AAC9E,SAASC,uBAAuB,QAAQ,yCAAwC;AAChF,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,eAA6B,eAAeA,aAEvD,EAAEC,IAAI,EAAEC,IAAI,EAAEC,MAAM,CAAC,CAAmB,EAAEC,MAAM,EAAE;IAElD,MAAMC,QAAQ,IAAI,CAACC,OAAO;IAC1B,MAAMC,SAAS,IAAI,CAACC,OAAO,CAACC,MAAM,CAACH,OAAO,CAACI,IAAI,CAAC,CAACC,SAAWA,OAAOV,IAAI,KAAKA,MAAMM,MAAM;IAExF,MAAMK,UAAU;QACd,GAAI,MAAMb,YAAY,IAAI,EAAEI,IAAI;QAChCU,MAAM;QACNC,KAAK;QACLC,YAAYnB,0BAA0B;YAAEoB,SAAS,IAAI;YAAET;YAAQH;QAAO;IACxE;IAEA,IAAIa;IAEJ,MAAMC,gBAAgBpB,wBAAwB;QAC5CW,QAAQ,IAAI,CAACD,OAAO,CAACC,MAAM;QAC3BP;QACAK;IACF;IAEAU,SAAS,MAAMZ,MAAMc,gBAAgB,CAAC;QAAEC,YAAYnB;IAAK,GAAGiB,eAAeN;IAE3EK,SAASI,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACN;IAEnC,uBAAuB;IACvBA,OAAOO,EAAE,GAAGP,OAAOQ,GAAG;IACtBR,SAASpB,uBAAuBoB;IAEhC,OAAOA;AACT,EAAC"}
@@ -1,4 +1,4 @@
1
- import type { TypeWithID, UpdateGlobalVersionArgs } from 'payload';
1
+ import { type TypeWithID, type UpdateGlobalVersionArgs } from 'payload';
2
2
  import type { MongooseAdapter } from './index.js';
3
- export declare function updateGlobalVersion<T extends TypeWithID>(this: MongooseAdapter, { id, global, locale, req, versionData, where, }: UpdateGlobalVersionArgs<T>): Promise<any>;
3
+ export declare function updateGlobalVersion<T extends TypeWithID>(this: MongooseAdapter, { id, global: globalSlug, locale, req, select, versionData, where, }: UpdateGlobalVersionArgs<T>): Promise<any>;
4
4
  //# sourceMappingURL=updateGlobalVersion.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"updateGlobalVersion.d.ts","sourceRoot":"","sources":["../src/updateGlobalVersion.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAkB,UAAU,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAA;AAElF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAIjD,wBAAsB,mBAAmB,CAAC,CAAC,SAAS,UAAU,EAC5D,IAAI,EAAE,eAAe,EACrB,EACE,EAAE,EACF,MAAM,EACN,MAAM,EACN,GAA0B,EAC1B,WAAW,EACX,KAAK,GACN,EAAE,uBAAuB,CAAC,CAAC,CAAC,gBA4B9B"}
1
+ {"version":3,"file":"updateGlobalVersion.d.ts","sourceRoot":"","sources":["../src/updateGlobalVersion.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,UAAU,EACf,KAAK,uBAAuB,EAC7B,MAAM,SAAS,CAAA;AAEhB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAMjD,wBAAsB,mBAAmB,CAAC,CAAC,SAAS,UAAU,EAC5D,IAAI,EAAE,eAAe,EACrB,EACE,EAAE,EACF,MAAM,EAAE,UAAU,EAClB,MAAM,EACN,GAA0B,EAC1B,MAAM,EACN,WAAW,EACX,KAAK,GACN,EAAE,uBAAuB,CAAC,CAAC,CAAC,gBAwC9B"}
@@ -1,22 +1,36 @@
1
+ import { buildVersionGlobalFields } from 'payload';
2
+ import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
3
+ import { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.js';
1
4
  import { withSession } from './withSession.js';
2
- export async function updateGlobalVersion({ id, global, locale, req = {}, versionData, where }) {
3
- const VersionModel = this.versions[global];
5
+ export async function updateGlobalVersion({ id, global: globalSlug, locale, req = {}, select, versionData, where }) {
6
+ const VersionModel = this.versions[globalSlug];
4
7
  const whereToUse = where || {
5
8
  id: {
6
9
  equals: id
7
10
  }
8
11
  };
12
+ const fields = buildVersionGlobalFields(this.payload.config, this.payload.config.globals.find((global)=>global.slug === globalSlug));
9
13
  const options = {
10
14
  ...await withSession(this, req),
11
15
  lean: true,
12
- new: true
16
+ new: true,
17
+ projection: buildProjectionFromSelect({
18
+ adapter: this,
19
+ fields,
20
+ select
21
+ })
13
22
  };
14
23
  const query = await VersionModel.buildQuery({
15
24
  locale,
16
25
  payload: this.payload,
17
26
  where: whereToUse
18
27
  });
19
- const doc = await VersionModel.findOneAndUpdate(query, versionData, options);
28
+ const sanitizedData = sanitizeRelationshipIDs({
29
+ config: this.payload.config,
30
+ data: versionData,
31
+ fields
32
+ });
33
+ const doc = await VersionModel.findOneAndUpdate(query, sanitizedData, options);
20
34
  const result = JSON.parse(JSON.stringify(doc));
21
35
  const verificationToken = doc._verificationToken;
22
36
  // custom id type reset
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/updateGlobalVersion.ts"],"sourcesContent":["import type { PayloadRequest, TypeWithID, UpdateGlobalVersionArgs } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { withSession } from './withSession.js'\n\nexport async function updateGlobalVersion<T extends TypeWithID>(\n this: MongooseAdapter,\n {\n id,\n global,\n locale,\n req = {} as PayloadRequest,\n versionData,\n where,\n }: UpdateGlobalVersionArgs<T>,\n) {\n const VersionModel = this.versions[global]\n const whereToUse = where || { id: { equals: id } }\n const options = {\n ...(await withSession(this, req)),\n lean: true,\n new: true,\n }\n\n const query = await VersionModel.buildQuery({\n locale,\n payload: this.payload,\n where: whereToUse,\n })\n\n const doc = await VersionModel.findOneAndUpdate(query, versionData, options)\n\n const result = JSON.parse(JSON.stringify(doc))\n\n const verificationToken = doc._verificationToken\n\n // custom id type reset\n result.id = result._id\n if (verificationToken) {\n result._verificationToken = verificationToken\n }\n return result\n}\n"],"names":["withSession","updateGlobalVersion","id","global","locale","req","versionData","where","VersionModel","versions","whereToUse","equals","options","lean","new","query","buildQuery","payload","doc","findOneAndUpdate","result","JSON","parse","stringify","verificationToken","_verificationToken","_id"],"mappings":"AAIA,SAASA,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,eAAeC,oBAEpB,EACEC,EAAE,EACFC,MAAM,EACNC,MAAM,EACNC,MAAM,CAAC,CAAmB,EAC1BC,WAAW,EACXC,KAAK,EACsB;IAE7B,MAAMC,eAAe,IAAI,CAACC,QAAQ,CAACN,OAAO;IAC1C,MAAMO,aAAaH,SAAS;QAAEL,IAAI;YAAES,QAAQT;QAAG;IAAE;IACjD,MAAMU,UAAU;QACd,GAAI,MAAMZ,YAAY,IAAI,EAAEK,IAAI;QAChCQ,MAAM;QACNC,KAAK;IACP;IAEA,MAAMC,QAAQ,MAAMP,aAAaQ,UAAU,CAAC;QAC1CZ;QACAa,SAAS,IAAI,CAACA,OAAO;QACrBV,OAAOG;IACT;IAEA,MAAMQ,MAAM,MAAMV,aAAaW,gBAAgB,CAACJ,OAAOT,aAAaM;IAEpE,MAAMQ,SAASC,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACL;IAEzC,MAAMM,oBAAoBN,IAAIO,kBAAkB;IAEhD,uBAAuB;IACvBL,OAAOlB,EAAE,GAAGkB,OAAOM,GAAG;IACtB,IAAIF,mBAAmB;QACrBJ,OAAOK,kBAAkB,GAAGD;IAC9B;IACA,OAAOJ;AACT"}
1
+ {"version":3,"sources":["../src/updateGlobalVersion.ts"],"sourcesContent":["import {\n buildVersionGlobalFields,\n type PayloadRequest,\n type TypeWithID,\n type UpdateGlobalVersionArgs,\n} from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.js'\nimport { withSession } from './withSession.js'\n\nexport async function updateGlobalVersion<T extends TypeWithID>(\n this: MongooseAdapter,\n {\n id,\n global: globalSlug,\n locale,\n req = {} as PayloadRequest,\n select,\n versionData,\n where,\n }: UpdateGlobalVersionArgs<T>,\n) {\n const VersionModel = this.versions[globalSlug]\n const whereToUse = where || { id: { equals: id } }\n const fields = buildVersionGlobalFields(\n this.payload.config,\n this.payload.config.globals.find((global) => global.slug === globalSlug),\n )\n\n const options = {\n ...(await withSession(this, req)),\n lean: true,\n new: true,\n projection: buildProjectionFromSelect({ adapter: this, fields, select }),\n }\n\n const query = await VersionModel.buildQuery({\n locale,\n payload: this.payload,\n where: whereToUse,\n })\n\n const sanitizedData = sanitizeRelationshipIDs({\n config: this.payload.config,\n data: versionData,\n fields,\n })\n\n const doc = await VersionModel.findOneAndUpdate(query, sanitizedData, options)\n\n const result = JSON.parse(JSON.stringify(doc))\n\n const verificationToken = doc._verificationToken\n\n // custom id type reset\n result.id = result._id\n if (verificationToken) {\n result._verificationToken = verificationToken\n }\n return result\n}\n"],"names":["buildVersionGlobalFields","buildProjectionFromSelect","sanitizeRelationshipIDs","withSession","updateGlobalVersion","id","global","globalSlug","locale","req","select","versionData","where","VersionModel","versions","whereToUse","equals","fields","payload","config","globals","find","slug","options","lean","new","projection","adapter","query","buildQuery","sanitizedData","data","doc","findOneAndUpdate","result","JSON","parse","stringify","verificationToken","_verificationToken","_id"],"mappings":"AAAA,SACEA,wBAAwB,QAInB,UAAS;AAIhB,SAASC,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,uBAAuB,QAAQ,yCAAwC;AAChF,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,eAAeC,oBAEpB,EACEC,EAAE,EACFC,QAAQC,UAAU,EAClBC,MAAM,EACNC,MAAM,CAAC,CAAmB,EAC1BC,MAAM,EACNC,WAAW,EACXC,KAAK,EACsB;IAE7B,MAAMC,eAAe,IAAI,CAACC,QAAQ,CAACP,WAAW;IAC9C,MAAMQ,aAAaH,SAAS;QAAEP,IAAI;YAAEW,QAAQX;QAAG;IAAE;IACjD,MAAMY,SAASjB,yBACb,IAAI,CAACkB,OAAO,CAACC,MAAM,EACnB,IAAI,CAACD,OAAO,CAACC,MAAM,CAACC,OAAO,CAACC,IAAI,CAAC,CAACf,SAAWA,OAAOgB,IAAI,KAAKf;IAG/D,MAAMgB,UAAU;QACd,GAAI,MAAMpB,YAAY,IAAI,EAAEM,IAAI;QAChCe,MAAM;QACNC,KAAK;QACLC,YAAYzB,0BAA0B;YAAE0B,SAAS,IAAI;YAAEV;YAAQP;QAAO;IACxE;IAEA,MAAMkB,QAAQ,MAAMf,aAAagB,UAAU,CAAC;QAC1CrB;QACAU,SAAS,IAAI,CAACA,OAAO;QACrBN,OAAOG;IACT;IAEA,MAAMe,gBAAgB5B,wBAAwB;QAC5CiB,QAAQ,IAAI,CAACD,OAAO,CAACC,MAAM;QAC3BY,MAAMpB;QACNM;IACF;IAEA,MAAMe,MAAM,MAAMnB,aAAaoB,gBAAgB,CAACL,OAAOE,eAAeP;IAEtE,MAAMW,SAASC,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACL;IAEzC,MAAMM,oBAAoBN,IAAIO,kBAAkB;IAEhD,uBAAuB;IACvBL,OAAO7B,EAAE,GAAG6B,OAAOM,GAAG;IACtB,IAAIF,mBAAmB;QACrBJ,OAAOK,kBAAkB,GAAGD;IAC9B;IACA,OAAOJ;AACT"}
@@ -1 +1 @@
1
- {"version":3,"file":"updateOne.d.ts","sourceRoot":"","sources":["../src/updateOne.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAkB,SAAS,EAAE,MAAM,SAAS,CAAA;AAQxD,eAAO,MAAM,SAAS,EAAE,SA+BvB,CAAA"}
1
+ {"version":3,"file":"updateOne.d.ts","sourceRoot":"","sources":["../src/updateOne.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAkB,SAAS,EAAE,MAAM,SAAS,CAAA;AAUxD,eAAO,MAAM,SAAS,EAAE,SAiDvB,CAAA"}
package/dist/updateOne.js CHANGED
@@ -1,17 +1,26 @@
1
+ import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
1
2
  import { handleError } from './utilities/handleError.js';
2
- import sanitizeInternalFields from './utilities/sanitizeInternalFields.js';
3
+ import { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js';
4
+ import { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.js';
3
5
  import { withSession } from './withSession.js';
4
- export const updateOne = async function updateOne({ id, collection, data, locale, req = {}, where: whereArg }) {
6
+ export const updateOne = async function updateOne({ id, collection, data, locale, options: optionsArgs = {}, req = {}, select, where: whereArg }) {
5
7
  const where = id ? {
6
8
  id: {
7
9
  equals: id
8
10
  }
9
11
  } : whereArg;
10
12
  const Model = this.collections[collection];
13
+ const fields = this.payload.collections[collection].config.fields;
11
14
  const options = {
15
+ ...optionsArgs,
12
16
  ...await withSession(this, req),
13
17
  lean: true,
14
- new: true
18
+ new: true,
19
+ projection: buildProjectionFromSelect({
20
+ adapter: this,
21
+ fields,
22
+ select
23
+ })
15
24
  };
16
25
  const query = await Model.buildQuery({
17
26
  locale,
@@ -19,8 +28,13 @@ export const updateOne = async function updateOne({ id, collection, data, locale
19
28
  where
20
29
  });
21
30
  let result;
31
+ const sanitizedData = sanitizeRelationshipIDs({
32
+ config: this.payload.config,
33
+ data,
34
+ fields
35
+ });
22
36
  try {
23
- result = await Model.findOneAndUpdate(query, data, options);
37
+ result = await Model.findOneAndUpdate(query, sanitizedData, options);
24
38
  } catch (error) {
25
39
  handleError({
26
40
  collection,
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/updateOne.ts"],"sourcesContent":["import type { PayloadRequest, UpdateOne } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { handleError } from './utilities/handleError.js'\nimport sanitizeInternalFields from './utilities/sanitizeInternalFields.js'\nimport { withSession } from './withSession.js'\n\nexport const updateOne: UpdateOne = async function updateOne(\n this: MongooseAdapter,\n { id, collection, data, locale, req = {} as PayloadRequest, where: whereArg },\n) {\n const where = id ? { id: { equals: id } } : whereArg\n const Model = this.collections[collection]\n const options = {\n ...(await withSession(this, req)),\n lean: true,\n new: true,\n }\n\n const query = await Model.buildQuery({\n locale,\n payload: this.payload,\n where,\n })\n\n let result\n\n try {\n result = await Model.findOneAndUpdate(query, data, options)\n } catch (error) {\n handleError({ collection, error, req })\n }\n\n result = JSON.parse(JSON.stringify(result))\n result.id = result._id\n result = sanitizeInternalFields(result)\n\n return result\n}\n"],"names":["handleError","sanitizeInternalFields","withSession","updateOne","id","collection","data","locale","req","where","whereArg","equals","Model","collections","options","lean","new","query","buildQuery","payload","result","findOneAndUpdate","error","JSON","parse","stringify","_id"],"mappings":"AAIA,SAASA,WAAW,QAAQ,6BAA4B;AACxD,OAAOC,4BAA4B,wCAAuC;AAC1E,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,YAAuB,eAAeA,UAEjD,EAAEC,EAAE,EAAEC,UAAU,EAAEC,IAAI,EAAEC,MAAM,EAAEC,MAAM,CAAC,CAAmB,EAAEC,OAAOC,QAAQ,EAAE;IAE7E,MAAMD,QAAQL,KAAK;QAAEA,IAAI;YAAEO,QAAQP;QAAG;IAAE,IAAIM;IAC5C,MAAME,QAAQ,IAAI,CAACC,WAAW,CAACR,WAAW;IAC1C,MAAMS,UAAU;QACd,GAAI,MAAMZ,YAAY,IAAI,EAAEM,IAAI;QAChCO,MAAM;QACNC,KAAK;IACP;IAEA,MAAMC,QAAQ,MAAML,MAAMM,UAAU,CAAC;QACnCX;QACAY,SAAS,IAAI,CAACA,OAAO;QACrBV;IACF;IAEA,IAAIW;IAEJ,IAAI;QACFA,SAAS,MAAMR,MAAMS,gBAAgB,CAACJ,OAAOX,MAAMQ;IACrD,EAAE,OAAOQ,OAAO;QACdtB,YAAY;YAAEK;YAAYiB;YAAOd;QAAI;IACvC;IAEAY,SAASG,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACL;IACnCA,OAAOhB,EAAE,GAAGgB,OAAOM,GAAG;IACtBN,SAASnB,uBAAuBmB;IAEhC,OAAOA;AACT,EAAC"}
1
+ {"version":3,"sources":["../src/updateOne.ts"],"sourcesContent":["import type { QueryOptions } from 'mongoose'\nimport type { PayloadRequest, UpdateOne } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { handleError } from './utilities/handleError.js'\nimport { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js'\nimport { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.js'\nimport { withSession } from './withSession.js'\n\nexport const updateOne: UpdateOne = async function updateOne(\n this: MongooseAdapter,\n {\n id,\n collection,\n data,\n locale,\n options: optionsArgs = {},\n req = {} as PayloadRequest,\n select,\n where: whereArg,\n },\n) {\n const where = id ? { id: { equals: id } } : whereArg\n const Model = this.collections[collection]\n const fields = this.payload.collections[collection].config.fields\n const options: QueryOptions = {\n ...optionsArgs,\n ...(await withSession(this, req)),\n lean: true,\n new: true,\n projection: buildProjectionFromSelect({ adapter: this, fields, select }),\n }\n\n const query = await Model.buildQuery({\n locale,\n payload: this.payload,\n where,\n })\n\n let result\n\n const sanitizedData = sanitizeRelationshipIDs({\n config: this.payload.config,\n data,\n fields,\n })\n\n try {\n result = await Model.findOneAndUpdate(query, sanitizedData, options)\n } catch (error) {\n handleError({ collection, error, req })\n }\n\n result = JSON.parse(JSON.stringify(result))\n result.id = result._id\n result = sanitizeInternalFields(result)\n\n return result\n}\n"],"names":["buildProjectionFromSelect","handleError","sanitizeInternalFields","sanitizeRelationshipIDs","withSession","updateOne","id","collection","data","locale","options","optionsArgs","req","select","where","whereArg","equals","Model","collections","fields","payload","config","lean","new","projection","adapter","query","buildQuery","result","sanitizedData","findOneAndUpdate","error","JSON","parse","stringify","_id"],"mappings":"AAKA,SAASA,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,WAAW,QAAQ,6BAA4B;AACxD,SAASC,sBAAsB,QAAQ,wCAAuC;AAC9E,SAASC,uBAAuB,QAAQ,yCAAwC;AAChF,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,YAAuB,eAAeA,UAEjD,EACEC,EAAE,EACFC,UAAU,EACVC,IAAI,EACJC,MAAM,EACNC,SAASC,cAAc,CAAC,CAAC,EACzBC,MAAM,CAAC,CAAmB,EAC1BC,MAAM,EACNC,OAAOC,QAAQ,EAChB;IAED,MAAMD,QAAQR,KAAK;QAAEA,IAAI;YAAEU,QAAQV;QAAG;IAAE,IAAIS;IAC5C,MAAME,QAAQ,IAAI,CAACC,WAAW,CAACX,WAAW;IAC1C,MAAMY,SAAS,IAAI,CAACC,OAAO,CAACF,WAAW,CAACX,WAAW,CAACc,MAAM,CAACF,MAAM;IACjE,MAAMT,UAAwB;QAC5B,GAAGC,WAAW;QACd,GAAI,MAAMP,YAAY,IAAI,EAAEQ,IAAI;QAChCU,MAAM;QACNC,KAAK;QACLC,YAAYxB,0BAA0B;YAAEyB,SAAS,IAAI;YAAEN;YAAQN;QAAO;IACxE;IAEA,MAAMa,QAAQ,MAAMT,MAAMU,UAAU,CAAC;QACnClB;QACAW,SAAS,IAAI,CAACA,OAAO;QACrBN;IACF;IAEA,IAAIc;IAEJ,MAAMC,gBAAgB1B,wBAAwB;QAC5CkB,QAAQ,IAAI,CAACD,OAAO,CAACC,MAAM;QAC3Bb;QACAW;IACF;IAEA,IAAI;QACFS,SAAS,MAAMX,MAAMa,gBAAgB,CAACJ,OAAOG,eAAenB;IAC9D,EAAE,OAAOqB,OAAO;QACd9B,YAAY;YAAEM;YAAYwB;YAAOnB;QAAI;IACvC;IAEAgB,SAASI,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACN;IACnCA,OAAOtB,EAAE,GAAGsB,OAAOO,GAAG;IACtBP,SAAS1B,uBAAuB0B;IAEhC,OAAOA;AACT,EAAC"}
@@ -1,3 +1,3 @@
1
- import type { UpdateVersion } from 'payload';
1
+ import { type UpdateVersion } from 'payload';
2
2
  export declare const updateVersion: UpdateVersion;
3
3
  //# sourceMappingURL=updateVersion.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"updateVersion.d.ts","sourceRoot":"","sources":["../src/updateVersion.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAkB,aAAa,EAAE,MAAM,SAAS,CAAA;AAM5D,eAAO,MAAM,aAAa,EAAE,aA8B3B,CAAA"}
1
+ {"version":3,"file":"updateVersion.d.ts","sourceRoot":"","sources":["../src/updateVersion.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqD,KAAK,aAAa,EAAE,MAAM,SAAS,CAAA;AAQ/F,eAAO,MAAM,aAAa,EAAE,aA0C3B,CAAA"}
@@ -1,22 +1,36 @@
1
+ import { buildVersionCollectionFields } from 'payload';
2
+ import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
3
+ import { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.js';
1
4
  import { withSession } from './withSession.js';
2
- export const updateVersion = async function updateVersion({ id, collection, locale, req = {}, versionData, where }) {
5
+ export const updateVersion = async function updateVersion({ id, collection, locale, req = {}, select, versionData, where }) {
3
6
  const VersionModel = this.versions[collection];
4
7
  const whereToUse = where || {
5
8
  id: {
6
9
  equals: id
7
10
  }
8
11
  };
12
+ const fields = buildVersionCollectionFields(this.payload.config, this.payload.collections[collection].config);
9
13
  const options = {
10
14
  ...await withSession(this, req),
11
15
  lean: true,
12
- new: true
16
+ new: true,
17
+ projection: buildProjectionFromSelect({
18
+ adapter: this,
19
+ fields,
20
+ select
21
+ })
13
22
  };
14
23
  const query = await VersionModel.buildQuery({
15
24
  locale,
16
25
  payload: this.payload,
17
26
  where: whereToUse
18
27
  });
19
- const doc = await VersionModel.findOneAndUpdate(query, versionData, options);
28
+ const sanitizedData = sanitizeRelationshipIDs({
29
+ config: this.payload.config,
30
+ data: versionData,
31
+ fields
32
+ });
33
+ const doc = await VersionModel.findOneAndUpdate(query, sanitizedData, options);
20
34
  const result = JSON.parse(JSON.stringify(doc));
21
35
  const verificationToken = doc._verificationToken;
22
36
  // custom id type reset
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/updateVersion.ts"],"sourcesContent":["import type { PayloadRequest, UpdateVersion } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { withSession } from './withSession.js'\n\nexport const updateVersion: UpdateVersion = async function updateVersion(\n this: MongooseAdapter,\n { id, collection, locale, req = {} as PayloadRequest, versionData, where },\n) {\n const VersionModel = this.versions[collection]\n const whereToUse = where || { id: { equals: id } }\n const options = {\n ...(await withSession(this, req)),\n lean: true,\n new: true,\n }\n\n const query = await VersionModel.buildQuery({\n locale,\n payload: this.payload,\n where: whereToUse,\n })\n\n const doc = await VersionModel.findOneAndUpdate(query, versionData, options)\n\n const result = JSON.parse(JSON.stringify(doc))\n\n const verificationToken = doc._verificationToken\n\n // custom id type reset\n result.id = result._id\n if (verificationToken) {\n result._verificationToken = verificationToken\n }\n return result\n}\n"],"names":["withSession","updateVersion","id","collection","locale","req","versionData","where","VersionModel","versions","whereToUse","equals","options","lean","new","query","buildQuery","payload","doc","findOneAndUpdate","result","JSON","parse","stringify","verificationToken","_verificationToken","_id"],"mappings":"AAIA,SAASA,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,gBAA+B,eAAeA,cAEzD,EAAEC,EAAE,EAAEC,UAAU,EAAEC,MAAM,EAAEC,MAAM,CAAC,CAAmB,EAAEC,WAAW,EAAEC,KAAK,EAAE;IAE1E,MAAMC,eAAe,IAAI,CAACC,QAAQ,CAACN,WAAW;IAC9C,MAAMO,aAAaH,SAAS;QAAEL,IAAI;YAAES,QAAQT;QAAG;IAAE;IACjD,MAAMU,UAAU;QACd,GAAI,MAAMZ,YAAY,IAAI,EAAEK,IAAI;QAChCQ,MAAM;QACNC,KAAK;IACP;IAEA,MAAMC,QAAQ,MAAMP,aAAaQ,UAAU,CAAC;QAC1CZ;QACAa,SAAS,IAAI,CAACA,OAAO;QACrBV,OAAOG;IACT;IAEA,MAAMQ,MAAM,MAAMV,aAAaW,gBAAgB,CAACJ,OAAOT,aAAaM;IAEpE,MAAMQ,SAASC,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACL;IAEzC,MAAMM,oBAAoBN,IAAIO,kBAAkB;IAEhD,uBAAuB;IACvBL,OAAOlB,EAAE,GAAGkB,OAAOM,GAAG;IACtB,IAAIF,mBAAmB;QACrBJ,OAAOK,kBAAkB,GAAGD;IAC9B;IACA,OAAOJ;AACT,EAAC"}
1
+ {"version":3,"sources":["../src/updateVersion.ts"],"sourcesContent":["import { buildVersionCollectionFields, type PayloadRequest, type UpdateVersion } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.js'\nimport { withSession } from './withSession.js'\n\nexport const updateVersion: UpdateVersion = async function updateVersion(\n this: MongooseAdapter,\n { id, collection, locale, req = {} as PayloadRequest, select, versionData, where },\n) {\n const VersionModel = this.versions[collection]\n const whereToUse = where || { id: { equals: id } }\n const fields = buildVersionCollectionFields(\n this.payload.config,\n this.payload.collections[collection].config,\n )\n\n const options = {\n ...(await withSession(this, req)),\n lean: true,\n new: true,\n projection: buildProjectionFromSelect({ adapter: this, fields, select }),\n }\n\n const query = await VersionModel.buildQuery({\n locale,\n payload: this.payload,\n where: whereToUse,\n })\n\n const sanitizedData = sanitizeRelationshipIDs({\n config: this.payload.config,\n data: versionData,\n fields,\n })\n\n const doc = await VersionModel.findOneAndUpdate(query, sanitizedData, options)\n\n const result = JSON.parse(JSON.stringify(doc))\n\n const verificationToken = doc._verificationToken\n\n // custom id type reset\n result.id = result._id\n if (verificationToken) {\n result._verificationToken = verificationToken\n }\n return result\n}\n"],"names":["buildVersionCollectionFields","buildProjectionFromSelect","sanitizeRelationshipIDs","withSession","updateVersion","id","collection","locale","req","select","versionData","where","VersionModel","versions","whereToUse","equals","fields","payload","config","collections","options","lean","new","projection","adapter","query","buildQuery","sanitizedData","data","doc","findOneAndUpdate","result","JSON","parse","stringify","verificationToken","_verificationToken","_id"],"mappings":"AAAA,SAASA,4BAA4B,QAAiD,UAAS;AAI/F,SAASC,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,uBAAuB,QAAQ,yCAAwC;AAChF,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,gBAA+B,eAAeA,cAEzD,EAAEC,EAAE,EAAEC,UAAU,EAAEC,MAAM,EAAEC,MAAM,CAAC,CAAmB,EAAEC,MAAM,EAAEC,WAAW,EAAEC,KAAK,EAAE;IAElF,MAAMC,eAAe,IAAI,CAACC,QAAQ,CAACP,WAAW;IAC9C,MAAMQ,aAAaH,SAAS;QAAEN,IAAI;YAAEU,QAAQV;QAAG;IAAE;IACjD,MAAMW,SAAShB,6BACb,IAAI,CAACiB,OAAO,CAACC,MAAM,EACnB,IAAI,CAACD,OAAO,CAACE,WAAW,CAACb,WAAW,CAACY,MAAM;IAG7C,MAAME,UAAU;QACd,GAAI,MAAMjB,YAAY,IAAI,EAAEK,IAAI;QAChCa,MAAM;QACNC,KAAK;QACLC,YAAYtB,0BAA0B;YAAEuB,SAAS,IAAI;YAAER;YAAQP;QAAO;IACxE;IAEA,MAAMgB,QAAQ,MAAMb,aAAac,UAAU,CAAC;QAC1CnB;QACAU,SAAS,IAAI,CAACA,OAAO;QACrBN,OAAOG;IACT;IAEA,MAAMa,gBAAgBzB,wBAAwB;QAC5CgB,QAAQ,IAAI,CAACD,OAAO,CAACC,MAAM;QAC3BU,MAAMlB;QACNM;IACF;IAEA,MAAMa,MAAM,MAAMjB,aAAakB,gBAAgB,CAACL,OAAOE,eAAeP;IAEtE,MAAMW,SAASC,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACL;IAEzC,MAAMM,oBAAoBN,IAAIO,kBAAkB;IAEhD,uBAAuB;IACvBL,OAAO1B,EAAE,GAAG0B,OAAOM,GAAG;IACtB,IAAIF,mBAAmB;QACrBJ,OAAOK,kBAAkB,GAAGD;IAC9B;IACA,OAAOJ;AACT,EAAC"}
@@ -0,0 +1,3 @@
1
+ import type { Upsert } from 'payload';
2
+ export declare const upsert: Upsert;
3
+ //# sourceMappingURL=upsert.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"upsert.d.ts","sourceRoot":"","sources":["../src/upsert.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAkB,MAAM,EAAE,MAAM,SAAS,CAAA;AAIrD,eAAO,MAAM,MAAM,EAAE,MAKpB,CAAA"}
package/dist/upsert.js ADDED
@@ -0,0 +1,15 @@
1
+ export const upsert = async function upsert({ collection, data, locale, req = {}, select, where }) {
2
+ return this.updateOne({
3
+ collection,
4
+ data,
5
+ locale,
6
+ options: {
7
+ upsert: true
8
+ },
9
+ req,
10
+ select,
11
+ where
12
+ });
13
+ };
14
+
15
+ //# sourceMappingURL=upsert.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/upsert.ts"],"sourcesContent":["import type { PayloadRequest, Upsert } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nexport const upsert: Upsert = async function upsert(\n this: MongooseAdapter,\n { collection, data, locale, req = {} as PayloadRequest, select, where },\n) {\n return this.updateOne({ collection, data, locale, options: { upsert: true }, req, select, where })\n}\n"],"names":["upsert","collection","data","locale","req","select","where","updateOne","options"],"mappings":"AAIA,OAAO,MAAMA,SAAiB,eAAeA,OAE3C,EAAEC,UAAU,EAAEC,IAAI,EAAEC,MAAM,EAAEC,MAAM,CAAC,CAAmB,EAAEC,MAAM,EAAEC,KAAK,EAAE;IAEvE,OAAO,IAAI,CAACC,SAAS,CAAC;QAAEN;QAAYC;QAAMC;QAAQK,SAAS;YAAER,QAAQ;QAAK;QAAGI;QAAKC;QAAQC;IAAM;AAClG,EAAC"}
@@ -0,0 +1,18 @@
1
+ import type { PipelineStage } from 'mongoose';
2
+ import type { CollectionSlug, JoinQuery, SanitizedCollectionConfig, Where } from 'payload';
3
+ import type { MongooseAdapter } from '../index.js';
4
+ type BuildJoinAggregationArgs = {
5
+ adapter: MongooseAdapter;
6
+ collection: CollectionSlug;
7
+ collectionConfig: SanitizedCollectionConfig;
8
+ joins: JoinQuery;
9
+ limit?: number;
10
+ locale: string;
11
+ projection?: Record<string, true>;
12
+ query?: Where;
13
+ /** whether the query is from drafts */
14
+ versions?: boolean;
15
+ };
16
+ export declare const buildJoinAggregation: ({ adapter, collection, collectionConfig, joins, limit, locale, projection, query, versions, }: BuildJoinAggregationArgs) => Promise<PipelineStage[] | undefined>;
17
+ export {};
18
+ //# sourceMappingURL=buildJoinAggregation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"buildJoinAggregation.d.ts","sourceRoot":"","sources":["../../src/utilities/buildJoinAggregation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAC7C,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,yBAAyB,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAE1F,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAIlD,KAAK,wBAAwB,GAAG;IAC9B,OAAO,EAAE,eAAe,CAAA;IACxB,UAAU,EAAE,cAAc,CAAA;IAC1B,gBAAgB,EAAE,yBAAyB,CAAA;IAC3C,KAAK,EAAE,SAAS,CAAA;IAEhB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,MAAM,CAAA;IACd,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAA;IAEjC,KAAK,CAAC,EAAE,KAAK,CAAA;IACb,uCAAuC;IACvC,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB,CAAA;AAED,eAAO,MAAM,oBAAoB,kGAU9B,wBAAwB,KAAG,OAAO,CAAC,aAAa,EAAE,GAAG,SAAS,CA+JhE,CAAA"}