@payloadcms/db-mongodb 3.0.0-canary.a78fca3 → 3.0.0-canary.ab70b75

Sign up to get free protection for your applications and to get access to all the features.
Files changed (150) hide show
  1. package/dist/connect.d.ts.map +1 -1
  2. package/dist/connect.js +13 -4
  3. package/dist/connect.js.map +1 -1
  4. package/dist/count.d.ts.map +1 -1
  5. package/dist/count.js +1 -1
  6. package/dist/count.js.map +1 -1
  7. package/dist/create.d.ts.map +1 -1
  8. package/dist/create.js +14 -4
  9. package/dist/create.js.map +1 -1
  10. package/dist/createGlobal.d.ts.map +1 -1
  11. package/dist/createGlobal.js +11 -6
  12. package/dist/createGlobal.js.map +1 -1
  13. package/dist/createGlobalVersion.d.ts +1 -1
  14. package/dist/createGlobalVersion.d.ts.map +1 -1
  15. package/dist/createGlobalVersion.js +14 -5
  16. package/dist/createGlobalVersion.js.map +1 -1
  17. package/dist/createMigration.d.ts.map +1 -1
  18. package/dist/createMigration.js +3 -3
  19. package/dist/createMigration.js.map +1 -1
  20. package/dist/createVersion.d.ts +1 -1
  21. package/dist/createVersion.d.ts.map +1 -1
  22. package/dist/createVersion.js +32 -10
  23. package/dist/createVersion.js.map +1 -1
  24. package/dist/deleteMany.d.ts.map +1 -1
  25. package/dist/deleteMany.js +1 -1
  26. package/dist/deleteMany.js.map +1 -1
  27. package/dist/deleteOne.d.ts.map +1 -1
  28. package/dist/deleteOne.js +2 -2
  29. package/dist/deleteOne.js.map +1 -1
  30. package/dist/deleteVersions.d.ts.map +1 -1
  31. package/dist/deleteVersions.js +1 -1
  32. package/dist/deleteVersions.js.map +1 -1
  33. package/dist/destroy.js.map +1 -1
  34. package/dist/find.d.ts.map +1 -1
  35. package/dist/find.js +28 -5
  36. package/dist/find.js.map +1 -1
  37. package/dist/findGlobal.d.ts.map +1 -1
  38. package/dist/findGlobal.js +2 -2
  39. package/dist/findGlobal.js.map +1 -1
  40. package/dist/findGlobalVersions.d.ts.map +1 -1
  41. package/dist/findGlobalVersions.js +11 -5
  42. package/dist/findGlobalVersions.js.map +1 -1
  43. package/dist/findOne.d.ts.map +1 -1
  44. package/dist/findOne.js +20 -4
  45. package/dist/findOne.js.map +1 -1
  46. package/dist/findVersions.d.ts.map +1 -1
  47. package/dist/findVersions.js +9 -3
  48. package/dist/findVersions.js.map +1 -1
  49. package/dist/index.d.ts +52 -35
  50. package/dist/index.d.ts.map +1 -1
  51. package/dist/index.js +12 -6
  52. package/dist/index.js.map +1 -1
  53. package/dist/init.d.ts.map +1 -1
  54. package/dist/init.js +10 -7
  55. package/dist/init.js.map +1 -1
  56. package/dist/migrateFresh.js.map +1 -1
  57. package/dist/models/buildCollectionSchema.d.ts +1 -27
  58. package/dist/models/buildCollectionSchema.d.ts.map +1 -1
  59. package/dist/models/buildCollectionSchema.js +16 -4
  60. package/dist/models/buildCollectionSchema.js.map +1 -1
  61. package/dist/models/buildGlobalModel.js +2 -2
  62. package/dist/models/buildGlobalModel.js.map +1 -1
  63. package/dist/models/buildSchema.d.ts +1 -27
  64. package/dist/models/buildSchema.d.ts.map +1 -1
  65. package/dist/models/buildSchema.js +112 -22
  66. package/dist/models/buildSchema.js.map +1 -1
  67. package/dist/predefinedMigrations/versions-v1-v2.js.map +1 -1
  68. package/dist/queries/buildAndOrConditions.d.ts.map +1 -1
  69. package/dist/queries/buildAndOrConditions.js +0 -2
  70. package/dist/queries/buildAndOrConditions.js.map +1 -1
  71. package/dist/queries/buildQuery.d.ts +2 -2
  72. package/dist/queries/buildQuery.d.ts.map +1 -1
  73. package/dist/queries/buildQuery.js +1 -2
  74. package/dist/queries/buildQuery.js.map +1 -1
  75. package/dist/queries/buildSearchParams.d.ts.map +1 -1
  76. package/dist/queries/buildSearchParams.js +19 -11
  77. package/dist/queries/buildSearchParams.js.map +1 -1
  78. package/dist/queries/buildSortParam.d.ts +3 -28
  79. package/dist/queries/buildSortParam.d.ts.map +1 -1
  80. package/dist/queries/buildSortParam.js +26 -17
  81. package/dist/queries/buildSortParam.js.map +1 -1
  82. package/dist/queries/getLocalizedSortProperty.js.map +1 -1
  83. package/dist/queries/getLocalizedSortProperty.spec.js +43 -43
  84. package/dist/queries/getLocalizedSortProperty.spec.js.map +1 -1
  85. package/dist/queries/mock.js.map +1 -1
  86. package/dist/queries/operatorMap.js.map +1 -1
  87. package/dist/queries/parseParams.d.ts.map +1 -1
  88. package/dist/queries/parseParams.js +5 -6
  89. package/dist/queries/parseParams.js.map +1 -1
  90. package/dist/queries/sanitizeQueryValue.d.ts.map +1 -1
  91. package/dist/queries/sanitizeQueryValue.js +142 -26
  92. package/dist/queries/sanitizeQueryValue.js.map +1 -1
  93. package/dist/queryDrafts.d.ts.map +1 -1
  94. package/dist/queryDrafts.js +29 -8
  95. package/dist/queryDrafts.js.map +1 -1
  96. package/dist/testCredentials.js.map +1 -1
  97. package/dist/transactions/beginTransaction.d.ts.map +1 -1
  98. package/dist/transactions/beginTransaction.js +2 -0
  99. package/dist/transactions/beginTransaction.js.map +1 -1
  100. package/dist/transactions/commitTransaction.d.ts.map +1 -1
  101. package/dist/transactions/commitTransaction.js +3 -0
  102. package/dist/transactions/commitTransaction.js.map +1 -1
  103. package/dist/transactions/rollbackTransaction.d.ts.map +1 -1
  104. package/dist/transactions/rollbackTransaction.js +13 -7
  105. package/dist/transactions/rollbackTransaction.js.map +1 -1
  106. package/dist/types.d.ts +7 -29
  107. package/dist/types.d.ts.map +1 -1
  108. package/dist/types.js.map +1 -1
  109. package/dist/updateGlobal.d.ts.map +1 -1
  110. package/dist/updateGlobal.js +9 -3
  111. package/dist/updateGlobal.js.map +1 -1
  112. package/dist/updateGlobalVersion.d.ts +2 -2
  113. package/dist/updateGlobalVersion.d.ts.map +1 -1
  114. package/dist/updateGlobalVersion.js +11 -4
  115. package/dist/updateGlobalVersion.js.map +1 -1
  116. package/dist/updateOne.d.ts.map +1 -1
  117. package/dist/updateOne.js +17 -6
  118. package/dist/updateOne.js.map +1 -1
  119. package/dist/updateVersion.d.ts +1 -1
  120. package/dist/updateVersion.d.ts.map +1 -1
  121. package/dist/updateVersion.js +9 -2
  122. package/dist/updateVersion.js.map +1 -1
  123. package/dist/upsert.d.ts +3 -0
  124. package/dist/upsert.d.ts.map +1 -0
  125. package/dist/upsert.js +14 -0
  126. package/dist/upsert.js.map +1 -0
  127. package/dist/utilities/buildJoinAggregation.d.ts +17 -0
  128. package/dist/utilities/buildJoinAggregation.d.ts.map +1 -0
  129. package/dist/utilities/buildJoinAggregation.js +148 -0
  130. package/dist/utilities/buildJoinAggregation.js.map +1 -0
  131. package/dist/utilities/getDBName.d.ts.map +1 -1
  132. package/dist/utilities/getDBName.js +3 -1
  133. package/dist/utilities/getDBName.js.map +1 -1
  134. package/dist/utilities/handleError.d.ts +6 -2
  135. package/dist/utilities/handleError.d.ts.map +1 -1
  136. package/dist/utilities/handleError.js +11 -8
  137. package/dist/utilities/handleError.js.map +1 -1
  138. package/dist/utilities/sanitizeInternalFields.d.ts +1 -2
  139. package/dist/utilities/sanitizeInternalFields.d.ts.map +1 -1
  140. package/dist/utilities/sanitizeInternalFields.js +1 -2
  141. package/dist/utilities/sanitizeInternalFields.js.map +1 -1
  142. package/dist/utilities/sanitizeRelationshipIDs.d.ts +9 -0
  143. package/dist/utilities/sanitizeRelationshipIDs.d.ts.map +1 -0
  144. package/dist/utilities/sanitizeRelationshipIDs.js +115 -0
  145. package/dist/utilities/sanitizeRelationshipIDs.js.map +1 -0
  146. package/dist/withSession.d.ts +3 -27
  147. package/dist/withSession.d.ts.map +1 -1
  148. package/dist/withSession.js +10 -4
  149. package/dist/withSession.js.map +1 -1
  150. package/package.json +11 -9
@@ -1,11 +1,12 @@
1
1
  import { 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 { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js';
4
5
  import { withSession } from './withSession.js';
5
- export const queryDrafts = async function queryDrafts({ collection, limit, locale, page, pagination, req = {}, sort: sortArg, where }) {
6
+ export const queryDrafts = async function queryDrafts({ collection, joins, limit, locale, page, pagination, req = {}, sort: sortArg, where }) {
6
7
  const VersionModel = this.versions[collection];
7
8
  const collectionConfig = this.payload.collections[collection].config;
8
- const options = withSession(this, req.transactionID);
9
+ const options = await withSession(this, req);
9
10
  let hasNearConstraint;
10
11
  let sort;
11
12
  if (where) {
@@ -43,6 +44,13 @@ export const queryDrafts = async function queryDrafts({ collection, limit, local
43
44
  sort,
44
45
  useEstimatedCount
45
46
  };
47
+ if (this.collation) {
48
+ const defaultLocale = 'en';
49
+ paginationOptions.collation = {
50
+ locale: locale && locale !== 'all' && locale !== '*' ? locale : defaultLocale,
51
+ ...this.collation
52
+ };
53
+ }
46
54
  if (!useEstimatedCount && Object.keys(versionQuery).length === 0 && this.disableIndexHints !== true) {
47
55
  // Improve the performance of the countDocuments query which is used if useEstimatedCount is set to false by adding
48
56
  // a hint. By default, if no hint is provided, MongoDB does not use an indexed field to count the returned documents,
@@ -61,18 +69,31 @@ export const queryDrafts = async function queryDrafts({ collection, limit, local
61
69
  // limit must also be set here, it's ignored when pagination is false
62
70
  paginationOptions.options.limit = limit;
63
71
  }
64
- const result = await VersionModel.paginate(versionQuery, paginationOptions);
72
+ let result;
73
+ const aggregate = await buildJoinAggregation({
74
+ adapter: this,
75
+ collection,
76
+ collectionConfig,
77
+ joins,
78
+ limit,
79
+ locale,
80
+ query: versionQuery,
81
+ versions: true
82
+ });
83
+ // build join aggregation
84
+ if (aggregate) {
85
+ result = await VersionModel.aggregatePaginate(VersionModel.aggregate(aggregate), paginationOptions);
86
+ } else {
87
+ result = await VersionModel.paginate(versionQuery, paginationOptions);
88
+ }
65
89
  const docs = JSON.parse(JSON.stringify(result.docs));
66
90
  return {
67
91
  ...result,
68
92
  docs: docs.map((doc)=>{
69
- // eslint-disable-next-line no-param-reassign
70
93
  doc = {
71
94
  _id: doc.parent,
72
95
  id: doc.parent,
73
- ...doc.version,
74
- createdAt: doc.createdAt,
75
- updatedAt: doc.updatedAt
96
+ ...doc.version
76
97
  };
77
98
  return sanitizeInternalFields(doc);
78
99
  })
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/queryDrafts.ts"],"sourcesContent":["import type { PaginateOptions } from 'mongoose'\nimport type { PayloadRequestWithData, 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 {\n collection,\n limit,\n locale,\n page,\n pagination,\n req = {} as PayloadRequestWithData,\n sort: sortArg,\n where,\n },\n) {\n const VersionModel = this.versions[collection]\n const collectionConfig = this.payload.collections[collection].config\n const options = withSession(this, req.transactionID)\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 (\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 // eslint-disable-next-line no-param-reassign\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","transactionID","hasNearConstraint","constraints","some","prop","Object","keys","key","fields","defaultSort","timestamps","combinedWhere","latest","equals","versionQuery","buildQuery","useEstimatedCount","length","paginationOptions","forceCountFn","lean","leanWithId","disableIndexHints","useCustomCountFn","Promise","resolve","countDocuments","hint","_id","result","paginate","docs","JSON","parse","stringify","map","doc","parent","id","version","createdAt","updatedAt"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","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,EACEC,UAAU,EACVC,KAAK,EACLC,MAAM,EACNC,IAAI,EACJC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C,QAAQC,OAAO,CACpBhC,aAAaiC,cAAc,CAACZ,cAAc;gBACxCa,MAAM;oBAAEC,KAAK;gBAAE;YACjB;QAEJ;IACF;IAEA,IAAI3C,QAAQ,GAAG;QACbiC,kBAAkBjC,KAAK,GAAGA;QAC1B,qEAAqE;QACrEiC,kBAAkBnB,OAAO,CAACd,KAAK,GAAGA;IACpC;IAEA,MAAM4C,SAAS,MAAMpC,aAAaqC,QAAQ,CAAChB,cAAcI;IACzD,MAAMa,OAAOC,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACL,OAAOE,IAAI;IAElD,OAAO;QACL,GAAGF,MAAM;QACTE,MAAMA,KAAKI,GAAG,CAAC,CAACC;YACd,6CAA6C;YAC7CA,MAAM;gBACJR,KAAKQ,IAAIC,MAAM;gBACfC,IAAIF,IAAIC,MAAM;gBACd,GAAGD,IAAIG,OAAO;gBACdC,WAAWJ,IAAII,SAAS;gBACxBC,WAAWL,IAAIK,SAAS;YAC1B;YAEA,OAAO5D,uBAAuBuD;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 { 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 { 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 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 // 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 let result\n\n const aggregate = await buildJoinAggregation({\n adapter: this,\n collection,\n collectionConfig,\n joins,\n limit,\n locale,\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":["combineQueries","flattenWhereToOperators","buildSortParam","buildJoinAggregation","sanitizeInternalFields","withSession","queryDrafts","collection","joins","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","aggregate","adapter","query","aggregatePaginate","paginate","docs","JSON","parse","stringify","map","doc","parent","id","version"],"mappings":"AAGA,SAASA,cAAc,EAAEC,uBAAuB,QAAQ,UAAS;AAIjE,SAASC,cAAc,QAAQ,8BAA6B;AAC5D,SAASC,oBAAoB,QAAQ,sCAAqC;AAC1E,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,MAAMC,OAAO,EACbC,KAAK,EACN;IAED,MAAMC,eAAe,IAAI,CAACC,QAAQ,CAACX,WAAW;IAC9C,MAAMY,mBAAmB,IAAI,CAACC,OAAO,CAACC,WAAW,CAACd,WAAW,CAACe,MAAM;IACpE,MAAMC,UAAU,MAAMlB,YAAY,IAAI,EAAEQ;IAExC,IAAIW;IACJ,IAAIV;IAEJ,IAAIE,OAAO;QACT,MAAMS,cAAcxB,wBAAwBe;QAC5CQ,oBAAoBC,YAAYC,IAAI,CAAC,CAACC,OAASC,OAAOC,IAAI,CAACF,MAAMD,IAAI,CAAC,CAACI,MAAQA,Q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AEJ,MAAMC,YAAY,MAAMpD,qBAAqB;QAC3CqD,SAAS,IAAI;QACbjD;QACAY;QACAX;QACAC;QACAC;QACA+C,OAAOpB;QACPnB,UAAU;IACZ;IAEA,yBAAyB;IACzB,IAAIqC,WAAW;QACbD,SAAS,MAAMrC,aAAayC,iBAAiB,CAC3CzC,aAAasC,SAAS,CAACA,YACvBd;IAEJ,OAAO;QACLa,SAAS,MAAMrC,aAAa0C,QAAQ,CAACtB,cAAcI;IACrD;IAEA,MAAMmB,OAAOC,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACT,OAAOM,IAAI;IAElD,OAAO;QACL,GAAGN,MAAM;QACTM,MAAMA,KAAKI,GAAG,CAAC,CAACC;YACdA,MAAM;gBACJZ,KAAKY,IAAIC,MAAM;gBACfC,IAAIF,IAAIC,MAAM;gBACd,GAAGD,IAAIG,OAAO;YAChB;YAEA,OAAOhE,uBAAuB6D;QAChC;IACF;AACF,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/testCredentials.ts"],"sourcesContent":["export const email = 'test@test.com'\nexport const password = 'test123'\nexport const connection = {\n name: 'payloadmemory',\n port: 27018,\n url: 'mongodb://127.0.0.1',\n}\n"],"names":["email","password","connection","name","port","url"],"rangeMappings":";;;;;;","mappings":"AAAA,OAAO,MAAMA,QAAQ,gBAAe;AACpC,OAAO,MAAMC,WAAW,UAAS;AACjC,OAAO,MAAMC,aAAa;IACxBC,MAAM;IACNC,MAAM;IACNC,KAAK;AACP,EAAC"}
1
+ {"version":3,"sources":["../src/testCredentials.ts"],"sourcesContent":["export const email = 'test@test.com'\nexport const password = 'test123'\nexport const connection = {\n name: 'payloadmemory',\n port: 27018,\n url: 'mongodb://127.0.0.1',\n}\n"],"names":["email","password","connection","name","port","url"],"mappings":"AAAA,OAAO,MAAMA,QAAQ,gBAAe;AACpC,OAAO,MAAMC,WAAW,UAAS;AACjC,OAAO,MAAMC,aAAa;IACxBC,MAAM;IACNC,MAAM;IACNC,KAAK;AACP,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"],"rangeMappings":";;;;;;;;;;;;;;;;;","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,iBAY/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,4 +1,7 @@
1
1
  export const commitTransaction = async function commitTransaction(id) {
2
+ if (id instanceof Promise) {
3
+ return;
4
+ }
2
5
  if (!this.sessions[id]?.inTransaction()) {
3
6
  return;
4
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 (!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","sessions","inTransaction","endSession","error"],"rangeMappings":";;;;;;;;;;;","mappings":"AAEA,OAAO,MAAMA,oBAAuC,eAAeA,kBAAkBC,EAAE;IACrF,IAAI,CAAC,IAAI,CAACC,QAAQ,CAACD,GAAG,EAAEE,iBAAiB;QACvC;IACF;IAEA,MAAM,IAAI,CAACD,QAAQ,CAACD,GAAG,CAACD,iBAAiB;IACzC,IAAI;QACF,MAAM,IAAI,CAACE,QAAQ,CAACD,GAAG,CAACG,UAAU;IACpC,EAAE,OAAOC,OAAO;IACd,gHAAgH;IAClH;IACA,OAAO,IAAI,CAACH,QAAQ,CAACD,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"}
@@ -1 +1 @@
1
- {"version":3,"file":"rollbackTransaction.d.ts","sourceRoot":"","sources":["../../src/transactions/rollbackTransaction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAA;AAElD,eAAO,MAAM,mBAAmB,EAAE,mBAwBjC,CAAA"}
1
+ {"version":3,"file":"rollbackTransaction.d.ts","sourceRoot":"","sources":["../../src/transactions/rollbackTransaction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAA;AAElD,eAAO,MAAM,mBAAmB,EAAE,mBAgCjC,CAAA"}
@@ -1,23 +1,29 @@
1
- export const rollbackTransaction = async function rollbackTransaction(id = '') {
1
+ export const rollbackTransaction = async function rollbackTransaction(incomingID = '') {
2
+ let transactionID;
3
+ if (incomingID instanceof Promise) {
4
+ transactionID = await incomingID;
5
+ } else {
6
+ transactionID = incomingID;
7
+ }
2
8
  // if multiple operations are using the same transaction, the first will flow through and delete the session.
3
9
  // subsequent calls should be ignored.
4
- if (!this.sessions[id]) {
10
+ if (!this.sessions[transactionID]) {
5
11
  return;
6
12
  }
7
13
  // when session exists but is not inTransaction something unexpected is happening to the session
8
- if (!this.sessions[id].inTransaction()) {
14
+ if (!this.sessions[transactionID].inTransaction()) {
9
15
  this.payload.logger.warn('rollbackTransaction called when no transaction exists');
10
- delete this.sessions[id];
16
+ delete this.sessions[transactionID];
11
17
  return;
12
18
  }
13
19
  // the first call for rollback should be aborted and deleted causing any other operations with the same transaction to fail
14
20
  try {
15
- await this.sessions[id].abortTransaction();
16
- await this.sessions[id].endSession();
21
+ await this.sessions[transactionID].abortTransaction();
22
+ await this.sessions[transactionID].endSession();
17
23
  } catch (error) {
18
24
  // ignore the error as it is likely a race condition from multiple errors
19
25
  }
20
- delete this.sessions[id];
26
+ delete this.sessions[transactionID];
21
27
  };
22
28
 
23
29
  //# sourceMappingURL=rollbackTransaction.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/transactions/rollbackTransaction.ts"],"sourcesContent":["import type { RollbackTransaction } from 'payload'\n\nexport const rollbackTransaction: RollbackTransaction = async function rollbackTransaction(\n id = '',\n) {\n // if multiple operations are using the same transaction, the first will flow through and delete the session.\n // subsequent calls should be ignored.\n if (!this.sessions[id]) {\n return\n }\n\n // when session exists but is not inTransaction something unexpected is happening to the session\n if (!this.sessions[id].inTransaction()) {\n this.payload.logger.warn('rollbackTransaction called when no transaction exists')\n delete this.sessions[id]\n return\n }\n\n // the first call for rollback should be aborted and deleted causing any other operations with the same transaction to fail\n try {\n await this.sessions[id].abortTransaction()\n await this.sessions[id].endSession()\n } catch (error) {\n // ignore the error as it is likely a race condition from multiple errors\n }\n delete this.sessions[id]\n}\n"],"names":["rollbackTransaction","id","sessions","inTransaction","payload","logger","warn","abortTransaction","endSession","error"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;","mappings":"AAEA,OAAO,MAAMA,sBAA2C,eAAeA,oBACrEC,KAAK,EAAE;IAEP,6GAA6G;IAC7G,sCAAsC;IACtC,IAAI,CAAC,IAAI,CAACC,QAAQ,CAACD,GAAG,EAAE;QACtB;IACF;IAEA,gGAAgG;IAChG,IAAI,CAAC,IAAI,CAACC,QAAQ,CAACD,GAAG,CAACE,aAAa,IAAI;QACtC,IAAI,CAACC,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC;QACzB,OAAO,IAAI,CAACJ,QAAQ,CAACD,GAAG;QACxB;IACF;IAEA,2HAA2H;IAC3H,IAAI;QACF,MAAM,IAAI,CAACC,QAAQ,CAACD,GAAG,CAACM,gBAAgB;QACxC,MAAM,IAAI,CAACL,QAAQ,CAACD,GAAG,CAACO,UAAU;IACpC,EAAE,OAAOC,OAAO;IACd,yEAAyE;IAC3E;IACA,OAAO,IAAI,CAACP,QAAQ,CAACD,GAAG;AAC1B,EAAC"}
1
+ {"version":3,"sources":["../../src/transactions/rollbackTransaction.ts"],"sourcesContent":["import type { RollbackTransaction } from 'payload'\n\nexport const rollbackTransaction: RollbackTransaction = async function rollbackTransaction(\n incomingID = '',\n) {\n let transactionID: number | string\n\n if (incomingID instanceof Promise) {\n transactionID = await incomingID\n } else {\n transactionID = incomingID\n }\n\n // if multiple operations are using the same transaction, the first will flow through and delete the session.\n // subsequent calls should be ignored.\n if (!this.sessions[transactionID]) {\n return\n }\n\n // when session exists but is not inTransaction something unexpected is happening to the session\n if (!this.sessions[transactionID].inTransaction()) {\n this.payload.logger.warn('rollbackTransaction called when no transaction exists')\n delete this.sessions[transactionID]\n return\n }\n\n // the first call for rollback should be aborted and deleted causing any other operations with the same transaction to fail\n try {\n await this.sessions[transactionID].abortTransaction()\n await this.sessions[transactionID].endSession()\n } catch (error) {\n // ignore the error as it is likely a race condition from multiple errors\n }\n delete this.sessions[transactionID]\n}\n"],"names":["rollbackTransaction","incomingID","transactionID","Promise","sessions","inTransaction","payload","logger","warn","abortTransaction","endSession","error"],"mappings":"AAEA,OAAO,MAAMA,sBAA2C,eAAeA,oBACrEC,aAAa,EAAE;IAEf,IAAIC;IAEJ,IAAID,sBAAsBE,SAAS;QACjCD,gBAAgB,MAAMD;IACxB,OAAO;QACLC,gBAAgBD;IAClB;IAEA,6GAA6G;IAC7G,sCAAsC;IACtC,IAAI,CAAC,IAAI,CAACG,QAAQ,CAACF,cAAc,EAAE;QACjC;IACF;IAEA,gGAAgG;IAChG,IAAI,CAAC,IAAI,CAACE,QAAQ,CAACF,cAAc,CAACG,aAAa,IAAI;QACjD,IAAI,CAACC,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC;QACzB,OAAO,IAAI,CAACJ,QAAQ,CAACF,cAAc;QACnC;IACF;IAEA,2HAA2H;IAC3H,IAAI;QACF,MAAM,IAAI,CAACE,QAAQ,CAACF,cAAc,CAACO,gBAAgB;QACnD,MAAM,IAAI,CAACL,QAAQ,CAACF,cAAc,CAACQ,UAAU;IAC/C,EAAE,OAAOC,OAAO;IACd,yEAAyE;IAC3E;IACA,OAAO,IAAI,CAACP,QAAQ,CAACF,cAAc;AACrC,EAAC"}
package/dist/types.d.ts CHANGED
@@ -1,32 +1,7 @@
1
- /// <reference types="mongoose/types/aggregate.js" />
2
- /// <reference types="mongoose/types/callback.js" />
3
- /// <reference types="mongoose/types/collection.js" />
4
- /// <reference types="mongoose/types/connection.js" />
5
- /// <reference types="mongoose/types/cursor.js" />
6
- /// <reference types="mongoose/types/document.js" />
7
- /// <reference types="mongoose/types/error.js" />
8
- /// <reference types="mongoose/types/expressions.js" />
9
- /// <reference types="mongoose/types/helpers.js" />
10
- /// <reference types="mongoose/types/middlewares.js" />
11
- /// <reference types="mongoose/types/indexes.js" />
12
- /// <reference types="mongoose/types/models.js" />
13
- /// <reference types="mongoose/types/mongooseoptions.js" />
14
- /// <reference types="mongoose/types/pipelinestage.js" />
15
- /// <reference types="mongoose/types/populate.js" />
16
- /// <reference types="mongoose/types/query.js" />
17
- /// <reference types="mongoose/types/schemaoptions.js" />
18
- /// <reference types="mongoose/types/schematypes.js" />
19
- /// <reference types="mongoose/types/session.js" />
20
- /// <reference types="mongoose/types/types.js" />
21
- /// <reference types="mongoose/types/utility.js" />
22
- /// <reference types="mongoose/types/validation.js" />
23
- /// <reference types="mongoose/types/virtuals.js" />
24
- /// <reference types="mongoose/types/inferschematype.js" />
25
- /// <reference types="mongoose-paginate-v2" />
26
- import type { IndexDefinition, IndexOptions, Model, PaginateModel, SchemaOptions } from 'mongoose';
27
- 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';
28
3
  import type { BuildQueryArgs } from './queries/buildQuery.js';
29
- export interface CollectionModel extends Model<any>, PaginateModel<any> {
4
+ export interface CollectionModel extends Model<any>, PaginateModel<any>, AggregatePaginateModel<any> {
30
5
  /** buildQuery is used to transform payload's where operator into what can be used by mongoose (e.g. id => _id) */
31
6
  buildQuery: (args: BuildQueryArgs) => Promise<Record<string, unknown>>;
32
7
  }
@@ -65,13 +40,14 @@ export type FieldGeneratorFunction<TSchema, TField extends Field> = (args: Field
65
40
  */
66
41
  export type FieldToSchemaMap<TSchema> = {
67
42
  array: FieldGeneratorFunction<TSchema, ArrayField>;
68
- blocks: FieldGeneratorFunction<TSchema, BlockField>;
43
+ blocks: FieldGeneratorFunction<TSchema, BlocksField>;
69
44
  checkbox: FieldGeneratorFunction<TSchema, CheckboxField>;
70
45
  code: FieldGeneratorFunction<TSchema, CodeField>;
71
46
  collapsible: FieldGeneratorFunction<TSchema, CollapsibleField>;
72
47
  date: FieldGeneratorFunction<TSchema, DateField>;
73
48
  email: FieldGeneratorFunction<TSchema, EmailField>;
74
49
  group: FieldGeneratorFunction<TSchema, GroupField>;
50
+ join: FieldGeneratorFunction<TSchema, JoinField>;
75
51
  json: FieldGeneratorFunction<TSchema, JSONField>;
76
52
  number: FieldGeneratorFunction<TSchema, NumberField>;
77
53
  point: FieldGeneratorFunction<TSchema, PointField>;
@@ -87,8 +63,10 @@ export type FieldToSchemaMap<TSchema> = {
87
63
  };
88
64
  export type MigrateUpArgs = {
89
65
  payload: Payload;
66
+ req: PayloadRequest;
90
67
  };
91
68
  export type MigrateDownArgs = {
92
69
  payload: Payload;
70
+ req: PayloadRequest;
93
71
  };
94
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,KAAK,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,MAA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,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":[],"rangeMappings":"","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,EAA0B,YAAY,EAAE,MAAM,SAAS,CAAA;AAOnE,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;AAQ3D,eAAO,MAAM,YAAY,EAAE,YA4B1B,CAAA"}
@@ -1,16 +1,22 @@
1
- import sanitizeInternalFields from './utilities/sanitizeInternalFields.js';
1
+ import { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js';
2
+ import { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.js';
2
3
  import { withSession } from './withSession.js';
3
4
  export const updateGlobal = async function updateGlobal({ slug, data, req = {} }) {
4
5
  const Model = this.globals;
5
6
  const options = {
6
- ...withSession(this, req.transactionID),
7
+ ...await withSession(this, req),
7
8
  lean: true,
8
9
  new: true
9
10
  };
10
11
  let result;
12
+ const sanitizedData = sanitizeRelationshipIDs({
13
+ config: this.payload.config,
14
+ data,
15
+ fields: this.payload.config.globals.find((global)=>global.slug === slug).fields
16
+ });
11
17
  result = await Model.findOneAndUpdate({
12
18
  globalType: slug
13
- }, data, options);
19
+ }, sanitizedData, options);
14
20
  result = JSON.parse(JSON.stringify(result));
15
21
  // custom id type reset
16
22
  result.id = result._id;
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/updateGlobal.ts"],"sourcesContent":["import type { PayloadRequestWithData, 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 PayloadRequestWithData },\n) {\n const Model = this.globals\n const options = {\n ...withSession(this, req.transactionID),\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","transactionID","lean","new","result","findOneAndUpdate","globalType","JSON","parse","stringify","id","_id"],"rangeMappings":";;;;;;;;;;;;;;;;;;","mappings":"AAIA,OAAOA,4BAA4B,wCAAuC;AAC1E,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,eAA6B,eAAeA,aAEvD,EAAEC,IAAI,EAAEC,IAAI,EAAEC,MAAM,CAAC,CAA2B,EAAE;IAElD,MAAMC,QAAQ,IAAI,CAACC,OAAO;IAC1B,MAAMC,UAAU;QACd,GAAGP,YAAY,IAAI,EAAEI,IAAII,aAAa,CAAC;QACvCC,MAAM;QACNC,KAAK;IACP;IAEA,IAAIC;IACJA,SAAS,MAAMN,MAAMO,gBAAgB,CAAC;QAAEC,YAAYX;IAAK,GAAGC,MAAMI;IAElEI,SAASG,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACL;IAEnC,uBAAuB;IACvBA,OAAOM,EAAE,GAAGN,OAAOO,GAAG;IACtBP,SAASZ,uBAAuBY;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 { 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 },\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\n const sanitizedData = sanitizeRelationshipIDs({\n config: this.payload.config,\n data,\n fields: this.payload.config.globals.find((global) => global.slug === slug).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":["sanitizeInternalFields","sanitizeRelationshipIDs","withSession","updateGlobal","slug","data","req","Model","globals","options","lean","new","result","sanitizedData","config","payload","fields","find","global","findOneAndUpdate","globalType","JSON","parse","stringify","id","_id"],"mappings":"AAIA,SAASA,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,EAAE;IAE1C,MAAMC,QAAQ,IAAI,CAACC,OAAO;IAC1B,MAAMC,UAAU;QACd,GAAI,MAAMP,YAAY,IAAI,EAAEI,IAAI;QAChCI,MAAM;QACNC,KAAK;IACP;IAEA,IAAIC;IAEJ,MAAMC,gBAAgBZ,wBAAwB;QAC5Ca,QAAQ,IAAI,CAACC,OAAO,CAACD,MAAM;QAC3BT;QACAW,QAAQ,IAAI,CAACD,OAAO,CAACD,MAAM,CAACN,OAAO,CAACS,IAAI,CAAC,CAACC,SAAWA,OAAOd,IAAI,KAAKA,MAAMY,MAAM;IACnF;IAEAJ,SAAS,MAAML,MAAMY,gBAAgB,CAAC;QAAEC,YAAYhB;IAAK,GAAGS,eAAeJ;IAE3EG,SAASS,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACX;IAEnC,uBAAuB;IACvBA,OAAOY,EAAE,GAAGZ,OAAOa,GAAG;IACtBb,SAASZ,uBAAuBY;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, 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,EAA0B,UAAU,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAA;AAE1F,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,GAAkC,EAClC,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;AAKjD,wBAAsB,mBAAmB,CAAC,CAAC,SAAS,UAAU,EAC5D,IAAI,EAAE,eAAe,EACrB,EACE,EAAE,EACF,MAAM,EAAE,UAAU,EAClB,MAAM,EACN,GAA0B,EAC1B,WAAW,EACX,KAAK,GACN,EAAE,uBAAuB,CAAC,CAAC,CAAC,gBAqC9B"}
@@ -1,13 +1,15 @@
1
+ import { buildVersionGlobalFields } from 'payload';
2
+ import { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.js';
1
3
  import { withSession } from './withSession.js';
2
- export async function updateGlobalVersion({ id, global, locale, req = {}, versionData, where }) {
3
- const VersionModel = this.versions[global];
4
+ export async function updateGlobalVersion({ id, global: globalSlug, locale, req = {}, versionData, where }) {
5
+ const VersionModel = this.versions[globalSlug];
4
6
  const whereToUse = where || {
5
7
  id: {
6
8
  equals: id
7
9
  }
8
10
  };
9
11
  const options = {
10
- ...withSession(this, req.transactionID),
12
+ ...await withSession(this, req),
11
13
  lean: true,
12
14
  new: true
13
15
  };
@@ -16,7 +18,12 @@ export async function updateGlobalVersion({ id, global, locale, req = {}, versio
16
18
  payload: this.payload,
17
19
  where: whereToUse
18
20
  });
19
- const doc = await VersionModel.findOneAndUpdate(query, versionData, options);
21
+ const sanitizedData = sanitizeRelationshipIDs({
22
+ config: this.payload.config,
23
+ data: versionData,
24
+ fields: buildVersionGlobalFields(this.payload.config, this.payload.config.globals.find((global)=>global.slug === globalSlug))
25
+ });
26
+ const doc = await VersionModel.findOneAndUpdate(query, sanitizedData, options);
20
27
  const result = JSON.parse(JSON.stringify(doc));
21
28
  const verificationToken = doc._verificationToken;
22
29
  // custom id type reset
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/updateGlobalVersion.ts"],"sourcesContent":["import type { PayloadRequestWithData, 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 PayloadRequestWithData,\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 ...withSession(this, req.transactionID),\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","transactionID","lean","new","query","buildQuery","payload","doc","findOneAndUpdate","result","JSON","parse","stringify","verificationToken","_verificationToken","_id"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAIA,SAASA,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,eAAeC,oBAEpB,EACEC,EAAE,EACFC,MAAM,EACNC,MAAM,EACNC,MAAM,CAAC,CAA2B,EAClCC,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,GAAGZ,YAAY,IAAI,EAAEK,IAAIQ,aAAa,CAAC;QACvCC,MAAM;QACNC,KAAK;IACP;IAEA,MAAMC,QAAQ,MAAMR,aAAaS,UAAU,CAAC;QAC1Cb;QACAc,SAAS,IAAI,CAACA,OAAO;QACrBX,OAAOG;IACT;IAEA,MAAMS,MAAM,MAAMX,aAAaY,gBAAgB,CAACJ,OAAOV,aAAaM;IAEpE,MAAMS,SAASC,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACL;IAEzC,MAAMM,oBAAoBN,IAAIO,kBAAkB;IAEhD,uBAAuB;IACvBL,OAAOnB,EAAE,GAAGmB,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 { 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 versionData,\n where,\n }: UpdateGlobalVersionArgs<T>,\n) {\n const VersionModel = this.versions[globalSlug]\n const whereToUse = where || { id: { equals: id } }\n const options = {\n ...(await withSession(this, req)),\n lean: true,\n new: true,\n }\n\n const query = await VersionModel.buildQuery({\n locale,\n payload: this.payload,\n where: whereToUse,\n })\n\n const sanitizedData = sanitizeRelationshipIDs({\n config: this.payload.config,\n data: versionData,\n fields: buildVersionGlobalFields(\n this.payload.config,\n this.payload.config.globals.find((global) => global.slug === globalSlug),\n ),\n })\n\n const doc = await VersionModel.findOneAndUpdate(query, sanitizedData, options)\n\n const result = JSON.parse(JSON.stringify(doc))\n\n const verificationToken = doc._verificationToken\n\n // custom id type reset\n result.id = result._id\n if (verificationToken) {\n result._verificationToken = verificationToken\n }\n return result\n}\n"],"names":["buildVersionGlobalFields","sanitizeRelationshipIDs","withSession","updateGlobalVersion","id","global","globalSlug","locale","req","versionData","where","VersionModel","versions","whereToUse","equals","options","lean","new","query","buildQuery","payload","sanitizedData","config","data","fields","globals","find","slug","doc","findOneAndUpdate","result","JSON","parse","stringify","verificationToken","_verificationToken","_id"],"mappings":"AAAA,SACEA,wBAAwB,QAInB,UAAS;AAIhB,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,WAAW,EACXC,KAAK,EACsB;IAE7B,MAAMC,eAAe,IAAI,CAACC,QAAQ,CAACN,WAAW;IAC9C,MAAMO,aAAaH,SAAS;QAAEN,IAAI;YAAEU,QAAQV;QAAG;IAAE;IACjD,MAAMW,UAAU;QACd,GAAI,MAAMb,YAAY,IAAI,EAAEM,IAAI;QAChCQ,MAAM;QACNC,KAAK;IACP;IAEA,MAAMC,QAAQ,MAAMP,aAAaQ,UAAU,CAAC;QAC1CZ;QACAa,SAAS,IAAI,CAACA,OAAO;QACrBV,OAAOG;IACT;IAEA,MAAMQ,gBAAgBpB,wBAAwB;QAC5CqB,QAAQ,IAAI,CAACF,OAAO,CAACE,MAAM;QAC3BC,MAAMd;QACNe,QAAQxB,yBACN,IAAI,CAACoB,OAAO,CAACE,MAAM,EACnB,IAAI,CAACF,OAAO,CAACE,MAAM,CAACG,OAAO,CAACC,IAAI,CAAC,CAACrB,SAAWA,OAAOsB,IAAI,KAAKrB;IAEjE;IAEA,MAAMsB,MAAM,MAAMjB,aAAakB,gBAAgB,CAACX,OAAOG,eAAeN;IAEtE,MAAMe,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"}
@@ -1 +1 @@
1
- {"version":3,"file":"updateOne.d.ts","sourceRoot":"","sources":["../src/updateOne.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAA0B,SAAS,EAAE,MAAM,SAAS,CAAA;AAQhE,eAAO,MAAM,SAAS,EAAE,SA+BvB,CAAA"}
1
+ {"version":3,"file":"updateOne.d.ts","sourceRoot":"","sources":["../src/updateOne.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAkB,SAAS,EAAE,MAAM,SAAS,CAAA;AASxD,eAAO,MAAM,SAAS,EAAE,SA8CvB,CAAA"}
package/dist/updateOne.js CHANGED
@@ -1,7 +1,8 @@
1
- import handleError from './utilities/handleError.js';
2
- import sanitizeInternalFields from './utilities/sanitizeInternalFields.js';
1
+ import { handleError } from './utilities/handleError.js';
2
+ import { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js';
3
+ import { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.js';
3
4
  import { withSession } from './withSession.js';
4
- export const updateOne = async function updateOne({ id, collection, data, locale, req = {}, where: whereArg }) {
5
+ export const updateOne = async function updateOne({ id, collection, data, locale, options: optionsArgs = {}, req = {}, where: whereArg }) {
5
6
  const where = id ? {
6
7
  id: {
7
8
  equals: id
@@ -9,7 +10,8 @@ export const updateOne = async function updateOne({ id, collection, data, locale
9
10
  } : whereArg;
10
11
  const Model = this.collections[collection];
11
12
  const options = {
12
- ...withSession(this, req.transactionID),
13
+ ...optionsArgs,
14
+ ...await withSession(this, req),
13
15
  lean: true,
14
16
  new: true
15
17
  };
@@ -19,10 +21,19 @@ export const updateOne = async function updateOne({ id, collection, data, locale
19
21
  where
20
22
  });
21
23
  let result;
24
+ const sanitizedData = sanitizeRelationshipIDs({
25
+ config: this.payload.config,
26
+ data,
27
+ fields: this.payload.collections[collection].config.fields
28
+ });
22
29
  try {
23
- result = await Model.findOneAndUpdate(query, data, options);
30
+ result = await Model.findOneAndUpdate(query, sanitizedData, options);
24
31
  } catch (error) {
25
- handleError(error, req);
32
+ handleError({
33
+ collection,
34
+ error,
35
+ req
36
+ });
26
37
  }
27
38
  result = JSON.parse(JSON.stringify(result));
28
39
  result.id = result._id;
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/updateOne.ts"],"sourcesContent":["import type { PayloadRequestWithData, 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 PayloadRequestWithData, where: whereArg },\n) {\n const where = id ? { id: { equals: id } } : whereArg\n const Model = this.collections[collection]\n const options = {\n ...withSession(this, req.transactionID),\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(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","transactionID","lean","new","query","buildQuery","payload","result","findOneAndUpdate","error","JSON","parse","stringify","_id"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAIA,OAAOA,iBAAiB,6BAA4B;AACpD,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,CAA2B,EAAEC,OAAOC,QAAQ,EAAE;IAErF,MAAMD,QAAQL,KAAK;QAAEA,IAAI;YAAEO,QAAQP;QAAG;IAAE,IAAIM;IAC5C,MAAME,QAAQ,IAAI,CAACC,WAAW,CAACR,WAAW;IAC1C,MAAMS,UAAU;QACd,GAAGZ,YAAY,IAAI,EAAEM,IAAIO,aAAa,CAAC;QACvCC,MAAM;QACNC,KAAK;IACP;IAEA,MAAMC,QAAQ,MAAMN,MAAMO,UAAU,CAAC;QACnCZ;QACAa,SAAS,IAAI,CAACA,OAAO;QACrBX;IACF;IAEA,IAAIY;IAEJ,IAAI;QACFA,SAAS,MAAMT,MAAMU,gBAAgB,CAACJ,OAAOZ,MAAMQ;IACrD,EAAE,OAAOS,OAAO;QACdvB,YAAYuB,OAAOf;IACrB;IAEAa,SAASG,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACL;IACnCA,OAAOjB,EAAE,GAAGiB,OAAOM,GAAG;IACtBN,SAASpB,uBAAuBoB;IAEhC,OAAOA;AACT,EAAC"}
1
+ {"version":3,"sources":["../src/updateOne.ts"],"sourcesContent":["import type { QueryOptions } from 'mongoose'\nimport type { PayloadRequest, UpdateOne } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { handleError } from './utilities/handleError.js'\nimport { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js'\nimport { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.js'\nimport { withSession } from './withSession.js'\n\nexport const updateOne: UpdateOne = async function updateOne(\n this: MongooseAdapter,\n {\n id,\n collection,\n data,\n locale,\n options: optionsArgs = {},\n req = {} as PayloadRequest,\n where: whereArg,\n },\n) {\n const where = id ? { id: { equals: id } } : whereArg\n const Model = this.collections[collection]\n const options: QueryOptions = {\n ...optionsArgs,\n ...(await withSession(this, req)),\n lean: true,\n new: true,\n }\n\n const query = await Model.buildQuery({\n locale,\n payload: this.payload,\n where,\n })\n\n let result\n\n const sanitizedData = sanitizeRelationshipIDs({\n config: this.payload.config,\n data,\n fields: this.payload.collections[collection].config.fields,\n })\n\n try {\n result = await Model.findOneAndUpdate(query, sanitizedData, options)\n } catch (error) {\n handleError({ collection, error, req })\n }\n\n result = JSON.parse(JSON.stringify(result))\n result.id = result._id\n result = sanitizeInternalFields(result)\n\n return result\n}\n"],"names":["handleError","sanitizeInternalFields","sanitizeRelationshipIDs","withSession","updateOne","id","collection","data","locale","options","optionsArgs","req","where","whereArg","equals","Model","collections","lean","new","query","buildQuery","payload","result","sanitizedData","config","fields","findOneAndUpdate","error","JSON","parse","stringify","_id"],"mappings":"AAKA,SAASA,WAAW,QAAQ,6BAA4B;AACxD,SAASC,sBAAsB,QAAQ,wCAAuC;AAC9E,SAASC,uBAAuB,QAAQ,yCAAwC;AAChF,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,YAAuB,eAAeA,UAEjD,EACEC,EAAE,EACFC,UAAU,EACVC,IAAI,EACJC,MAAM,EACNC,SAASC,cAAc,CAAC,CAAC,EACzBC,MAAM,CAAC,CAAmB,EAC1BC,OAAOC,QAAQ,EAChB;IAED,MAAMD,QAAQP,KAAK;QAAEA,IAAI;YAAES,QAAQT;QAAG;IAAE,IAAIQ;IAC5C,MAAME,QAAQ,IAAI,CAACC,WAAW,CAACV,WAAW;IAC1C,MAAMG,UAAwB;QAC5B,GAAGC,WAAW;QACd,GAAI,MAAMP,YAAY,IAAI,EAAEQ,IAAI;QAChCM,MAAM;QACNC,KAAK;IACP;IAEA,MAAMC,QAAQ,MAAMJ,MAAMK,UAAU,CAAC;QACnCZ;QACAa,SAAS,IAAI,CAACA,OAAO;QACrBT;IACF;IAEA,IAAIU;IAEJ,MAAMC,gBAAgBrB,wBAAwB;QAC5CsB,QAAQ,IAAI,CAACH,OAAO,CAACG,MAAM;QAC3BjB;QACAkB,QAAQ,IAAI,CAACJ,OAAO,CAACL,WAAW,CAACV,WAAW,CAACkB,MAAM,CAACC,MAAM;IAC5D;IAEA,IAAI;QACFH,SAAS,MAAMP,MAAMW,gBAAgB,CAACP,OAAOI,eAAed;IAC9D,EAAE,OAAOkB,OAAO;QACd3B,YAAY;YAAEM;YAAYqB;YAAOhB;QAAI;IACvC;IAEAW,SAASM,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACR;IACnCA,OAAOjB,EAAE,GAAGiB,OAAOS,GAAG;IACtBT,SAASrB,uBAAuBqB;IAEhC,OAAOA;AACT,EAAC"}
@@ -1,3 +1,3 @@
1
- import type { UpdateVersion } from 'payload';
1
+ import { type UpdateVersion } from 'payload';
2
2
  export declare const updateVersion: UpdateVersion;
3
3
  //# sourceMappingURL=updateVersion.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"updateVersion.d.ts","sourceRoot":"","sources":["../src/updateVersion.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAA0B,aAAa,EAAE,MAAM,SAAS,CAAA;AAMpE,eAAO,MAAM,aAAa,EAAE,aA8B3B,CAAA"}
1
+ {"version":3,"file":"updateVersion.d.ts","sourceRoot":"","sources":["../src/updateVersion.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqD,KAAK,aAAa,EAAE,MAAM,SAAS,CAAA;AAO/F,eAAO,MAAM,aAAa,EAAE,aAuC3B,CAAA"}
@@ -1,3 +1,5 @@
1
+ import { buildVersionCollectionFields } from 'payload';
2
+ import { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.js';
1
3
  import { withSession } from './withSession.js';
2
4
  export const updateVersion = async function updateVersion({ id, collection, locale, req = {}, versionData, where }) {
3
5
  const VersionModel = this.versions[collection];
@@ -7,7 +9,7 @@ export const updateVersion = async function updateVersion({ id, collection, loca
7
9
  }
8
10
  };
9
11
  const options = {
10
- ...withSession(this, req.transactionID),
12
+ ...await withSession(this, req),
11
13
  lean: true,
12
14
  new: true
13
15
  };
@@ -16,7 +18,12 @@ export const updateVersion = async function updateVersion({ id, collection, loca
16
18
  payload: this.payload,
17
19
  where: whereToUse
18
20
  });
19
- const doc = await VersionModel.findOneAndUpdate(query, versionData, options);
21
+ const sanitizedData = sanitizeRelationshipIDs({
22
+ config: this.payload.config,
23
+ data: versionData,
24
+ fields: buildVersionCollectionFields(this.payload.config, this.payload.collections[collection].config)
25
+ });
26
+ const doc = await VersionModel.findOneAndUpdate(query, sanitizedData, options);
20
27
  const result = JSON.parse(JSON.stringify(doc));
21
28
  const verificationToken = doc._verificationToken;
22
29
  // custom id type reset
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/updateVersion.ts"],"sourcesContent":["import type { PayloadRequestWithData, 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 PayloadRequestWithData, versionData, where },\n) {\n const VersionModel = this.versions[collection]\n const whereToUse = where || { id: { equals: id } }\n const options = {\n ...withSession(this, req.transactionID),\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","transactionID","lean","new","query","buildQuery","payload","doc","findOneAndUpdate","result","JSON","parse","stringify","verificationToken","_verificationToken","_id"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAIA,SAASA,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,gBAA+B,eAAeA,cAEzD,EAAEC,EAAE,EAAEC,UAAU,EAAEC,MAAM,EAAEC,MAAM,CAAC,CAA2B,EAAEC,WAAW,EAAEC,KAAK,EAAE;IAElF,MAAMC,eAAe,IAAI,CAACC,QAAQ,CAACN,WAAW;IAC9C,MAAMO,aAAaH,SAAS;QAAEL,IAAI;YAAES,QAAQT;QAAG;IAAE;IACjD,MAAMU,UAAU;QACd,GAAGZ,YAAY,IAAI,EAAEK,IAAIQ,aAAa,CAAC;QACvCC,MAAM;QACNC,KAAK;IACP;IAEA,MAAMC,QAAQ,MAAMR,aAAaS,UAAU,CAAC;QAC1Cb;QACAc,SAAS,IAAI,CAACA,OAAO;QACrBX,OAAOG;IACT;IAEA,MAAMS,MAAM,MAAMX,aAAaY,gBAAgB,CAACJ,OAAOV,aAAaM;IAEpE,MAAMS,SAASC,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACL;IAEzC,MAAMM,oBAAoBN,IAAIO,kBAAkB;IAEhD,uBAAuB;IACvBL,OAAOnB,EAAE,GAAGmB,OAAOM,GAAG;IACtB,IAAIF,mBAAmB;QACrBJ,OAAOK,kBAAkB,GAAGD;IAC9B;IACA,OAAOJ;AACT,EAAC"}
1
+ {"version":3,"sources":["../src/updateVersion.ts"],"sourcesContent":["import { buildVersionCollectionFields, type PayloadRequest, type UpdateVersion } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.js'\nimport { withSession } from './withSession.js'\n\nexport const updateVersion: UpdateVersion = async function updateVersion(\n this: MongooseAdapter,\n { id, collection, locale, req = {} as PayloadRequest, versionData, where },\n) {\n const VersionModel = this.versions[collection]\n const whereToUse = where || { id: { equals: id } }\n const options = {\n ...(await withSession(this, req)),\n lean: true,\n new: true,\n }\n\n const query = await VersionModel.buildQuery({\n locale,\n payload: this.payload,\n where: whereToUse,\n })\n\n const sanitizedData = sanitizeRelationshipIDs({\n config: this.payload.config,\n data: versionData,\n fields: buildVersionCollectionFields(\n this.payload.config,\n this.payload.collections[collection].config,\n ),\n })\n\n const doc = await VersionModel.findOneAndUpdate(query, sanitizedData, options)\n\n const result = JSON.parse(JSON.stringify(doc))\n\n const verificationToken = doc._verificationToken\n\n // custom id type reset\n result.id = result._id\n if (verificationToken) {\n result._verificationToken = verificationToken\n }\n return result\n}\n"],"names":["buildVersionCollectionFields","sanitizeRelationshipIDs","withSession","updateVersion","id","collection","locale","req","versionData","where","VersionModel","versions","whereToUse","equals","options","lean","new","query","buildQuery","payload","sanitizedData","config","data","fields","collections","doc","findOneAndUpdate","result","JSON","parse","stringify","verificationToken","_verificationToken","_id"],"mappings":"AAAA,SAASA,4BAA4B,QAAiD,UAAS;AAI/F,SAASC,uBAAuB,QAAQ,yCAAwC;AAChF,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,gBAA+B,eAAeA,cAEzD,EAAEC,EAAE,EAAEC,UAAU,EAAEC,MAAM,EAAEC,MAAM,CAAC,CAAmB,EAAEC,WAAW,EAAEC,KAAK,EAAE;IAE1E,MAAMC,eAAe,IAAI,CAACC,QAAQ,CAACN,WAAW;IAC9C,MAAMO,aAAaH,SAAS;QAAEL,IAAI;YAAES,QAAQT;QAAG;IAAE;IACjD,MAAMU,UAAU;QACd,GAAI,MAAMZ,YAAY,IAAI,EAAEK,IAAI;QAChCQ,MAAM;QACNC,KAAK;IACP;IAEA,MAAMC,QAAQ,MAAMP,aAAaQ,UAAU,CAAC;QAC1CZ;QACAa,SAAS,IAAI,CAACA,OAAO;QACrBV,OAAOG;IACT;IAEA,MAAMQ,gBAAgBnB,wBAAwB;QAC5CoB,QAAQ,IAAI,CAACF,OAAO,CAACE,MAAM;QAC3BC,MAAMd;QACNe,QAAQvB,6BACN,IAAI,CAACmB,OAAO,CAACE,MAAM,EACnB,IAAI,CAACF,OAAO,CAACK,WAAW,CAACnB,WAAW,CAACgB,MAAM;IAE/C;IAEA,MAAMI,MAAM,MAAMf,aAAagB,gBAAgB,CAACT,OAAOG,eAAeN;IAEtE,MAAMa,SAASC,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACL;IAEzC,MAAMM,oBAAoBN,IAAIO,kBAAkB;IAEhD,uBAAuB;IACvBL,OAAOvB,EAAE,GAAGuB,OAAOM,GAAG;IACtB,IAAIF,mBAAmB;QACrBJ,OAAOK,kBAAkB,GAAGD;IAC9B;IACA,OAAOJ;AACT,EAAC"}
@@ -0,0 +1,3 @@
1
+ import type { Upsert } from 'payload';
2
+ export declare const upsert: Upsert;
3
+ //# sourceMappingURL=upsert.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"upsert.d.ts","sourceRoot":"","sources":["../src/upsert.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAkB,MAAM,EAAE,MAAM,SAAS,CAAA;AAIrD,eAAO,MAAM,MAAM,EAAE,MAKpB,CAAA"}
package/dist/upsert.js ADDED
@@ -0,0 +1,14 @@
1
+ export const upsert = async function upsert({ collection, data, locale, req = {}, where }) {
2
+ return this.updateOne({
3
+ collection,
4
+ data,
5
+ locale,
6
+ options: {
7
+ upsert: true
8
+ },
9
+ req,
10
+ where
11
+ });
12
+ };
13
+
14
+ //# sourceMappingURL=upsert.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/upsert.ts"],"sourcesContent":["import type { PayloadRequest, Upsert } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nexport const upsert: Upsert = async function upsert(\n this: MongooseAdapter,\n { collection, data, locale, req = {} as PayloadRequest, where },\n) {\n return this.updateOne({ collection, data, locale, options: { upsert: true }, req, where })\n}\n"],"names":["upsert","collection","data","locale","req","where","updateOne","options"],"mappings":"AAIA,OAAO,MAAMA,SAAiB,eAAeA,OAE3C,EAAEC,UAAU,EAAEC,IAAI,EAAEC,MAAM,EAAEC,MAAM,CAAC,CAAmB,EAAEC,KAAK,EAAE;IAE/D,OAAO,IAAI,CAACC,SAAS,CAAC;QAAEL;QAAYC;QAAMC;QAAQI,SAAS;YAAEP,QAAQ;QAAK;QAAGI;QAAKC;IAAM;AAC1F,EAAC"}