@payloadcms/db-mongodb 3.0.0-canary.c27a334 → 3.0.0-canary.c96fa61

Sign up to get free protection for your applications and to get access to all the features.
Files changed (197) hide show
  1. package/README.md +1 -1
  2. package/dist/connect.d.ts +1 -1
  3. package/dist/connect.d.ts.map +1 -1
  4. package/dist/connect.js +13 -4
  5. package/dist/connect.js.map +1 -1
  6. package/dist/count.d.ts +1 -1
  7. package/dist/count.d.ts.map +1 -1
  8. package/dist/count.js +2 -2
  9. package/dist/count.js.map +1 -1
  10. package/dist/countGlobalVersions.d.ts +3 -0
  11. package/dist/countGlobalVersions.d.ts.map +1 -0
  12. package/dist/countGlobalVersions.js +33 -0
  13. package/dist/countGlobalVersions.js.map +1 -0
  14. package/dist/countVersions.d.ts +3 -0
  15. package/dist/countVersions.d.ts.map +1 -0
  16. package/dist/countVersions.js +33 -0
  17. package/dist/countVersions.js.map +1 -0
  18. package/dist/create.d.ts +1 -1
  19. package/dist/create.d.ts.map +1 -1
  20. package/dist/create.js +17 -4
  21. package/dist/create.js.map +1 -1
  22. package/dist/createGlobal.d.ts +1 -1
  23. package/dist/createGlobal.d.ts.map +1 -1
  24. package/dist/createGlobal.js +11 -6
  25. package/dist/createGlobal.js.map +1 -1
  26. package/dist/createGlobalVersion.d.ts +1 -1
  27. package/dist/createGlobalVersion.d.ts.map +1 -1
  28. package/dist/createGlobalVersion.js +14 -5
  29. package/dist/createGlobalVersion.js.map +1 -1
  30. package/dist/createMigration.d.ts +1 -1
  31. package/dist/createMigration.d.ts.map +1 -1
  32. package/dist/createMigration.js +9 -7
  33. package/dist/createMigration.js.map +1 -1
  34. package/dist/createVersion.d.ts +1 -1
  35. package/dist/createVersion.d.ts.map +1 -1
  36. package/dist/createVersion.js +32 -10
  37. package/dist/createVersion.js.map +1 -1
  38. package/dist/deleteMany.d.ts +1 -1
  39. package/dist/deleteMany.d.ts.map +1 -1
  40. package/dist/deleteMany.js +1 -1
  41. package/dist/deleteMany.js.map +1 -1
  42. package/dist/deleteOne.d.ts +1 -1
  43. package/dist/deleteOne.d.ts.map +1 -1
  44. package/dist/deleteOne.js +12 -4
  45. package/dist/deleteOne.js.map +1 -1
  46. package/dist/deleteVersions.d.ts +1 -1
  47. package/dist/deleteVersions.d.ts.map +1 -1
  48. package/dist/deleteVersions.js +1 -1
  49. package/dist/deleteVersions.js.map +1 -1
  50. package/dist/destroy.d.ts +1 -1
  51. package/dist/destroy.d.ts.map +1 -1
  52. package/dist/destroy.js.map +1 -1
  53. package/dist/find.d.ts +1 -1
  54. package/dist/find.d.ts.map +1 -1
  55. package/dist/find.js +36 -6
  56. package/dist/find.js.map +1 -1
  57. package/dist/findGlobal.d.ts +1 -1
  58. package/dist/findGlobal.d.ts.map +1 -1
  59. package/dist/findGlobal.js +11 -5
  60. package/dist/findGlobal.js.map +1 -1
  61. package/dist/findGlobalVersions.d.ts +1 -1
  62. package/dist/findGlobalVersions.d.ts.map +1 -1
  63. package/dist/findGlobalVersions.js +19 -8
  64. package/dist/findGlobalVersions.js.map +1 -1
  65. package/dist/findOne.d.ts +1 -1
  66. package/dist/findOne.d.ts.map +1 -1
  67. package/dist/findOne.js +28 -4
  68. package/dist/findOne.js.map +1 -1
  69. package/dist/findVersions.d.ts +1 -1
  70. package/dist/findVersions.d.ts.map +1 -1
  71. package/dist/findVersions.js +17 -5
  72. package/dist/findVersions.js.map +1 -1
  73. package/dist/index.d.ts +52 -35
  74. package/dist/index.d.ts.map +1 -1
  75. package/dist/index.js +17 -7
  76. package/dist/index.js.map +1 -1
  77. package/dist/init.d.ts +1 -1
  78. package/dist/init.d.ts.map +1 -1
  79. package/dist/init.js +11 -8
  80. package/dist/init.js.map +1 -1
  81. package/dist/migrateFresh.d.ts.map +1 -1
  82. package/dist/migrateFresh.js +1 -1
  83. package/dist/migrateFresh.js.map +1 -1
  84. package/dist/models/buildCollectionSchema.d.ts +2 -29
  85. package/dist/models/buildCollectionSchema.d.ts.map +1 -1
  86. package/dist/models/buildCollectionSchema.js +16 -4
  87. package/dist/models/buildCollectionSchema.js.map +1 -1
  88. package/dist/models/buildGlobalModel.d.ts +1 -1
  89. package/dist/models/buildGlobalModel.d.ts.map +1 -1
  90. package/dist/models/buildGlobalModel.js +2 -2
  91. package/dist/models/buildGlobalModel.js.map +1 -1
  92. package/dist/models/buildSchema.d.ts +2 -29
  93. package/dist/models/buildSchema.d.ts.map +1 -1
  94. package/dist/models/buildSchema.js +116 -23
  95. package/dist/models/buildSchema.js.map +1 -1
  96. package/dist/predefinedMigrations/versions-v1-v2.js.map +1 -1
  97. package/dist/queries/buildAndOrConditions.d.ts +1 -2
  98. package/dist/queries/buildAndOrConditions.d.ts.map +1 -1
  99. package/dist/queries/buildAndOrConditions.js +0 -2
  100. package/dist/queries/buildAndOrConditions.js.map +1 -1
  101. package/dist/queries/buildQuery.d.ts +3 -4
  102. package/dist/queries/buildQuery.d.ts.map +1 -1
  103. package/dist/queries/buildQuery.js +2 -3
  104. package/dist/queries/buildQuery.js.map +1 -1
  105. package/dist/queries/buildSearchParams.d.ts +1 -2
  106. package/dist/queries/buildSearchParams.d.ts.map +1 -1
  107. package/dist/queries/buildSearchParams.js +21 -13
  108. package/dist/queries/buildSearchParams.js.map +1 -1
  109. package/dist/queries/buildSortParam.d.ts +3 -29
  110. package/dist/queries/buildSortParam.d.ts.map +1 -1
  111. package/dist/queries/buildSortParam.js +26 -17
  112. package/dist/queries/buildSortParam.js.map +1 -1
  113. package/dist/queries/getLocalizedSortProperty.d.ts +1 -2
  114. package/dist/queries/getLocalizedSortProperty.d.ts.map +1 -1
  115. package/dist/queries/getLocalizedSortProperty.js +2 -2
  116. package/dist/queries/getLocalizedSortProperty.js.map +1 -1
  117. package/dist/queries/getLocalizedSortProperty.spec.js +44 -44
  118. package/dist/queries/getLocalizedSortProperty.spec.js.map +1 -1
  119. package/dist/queries/mock.js.map +1 -1
  120. package/dist/queries/operatorMap.js.map +1 -1
  121. package/dist/queries/parseParams.d.ts +1 -3
  122. package/dist/queries/parseParams.d.ts.map +1 -1
  123. package/dist/queries/parseParams.js +6 -7
  124. package/dist/queries/parseParams.js.map +1 -1
  125. package/dist/queries/sanitizeQueryValue.d.ts +1 -1
  126. package/dist/queries/sanitizeQueryValue.d.ts.map +1 -1
  127. package/dist/queries/sanitizeQueryValue.js +146 -27
  128. package/dist/queries/sanitizeQueryValue.js.map +1 -1
  129. package/dist/queryDrafts.d.ts +1 -1
  130. package/dist/queryDrafts.d.ts.map +1 -1
  131. package/dist/queryDrafts.js +37 -9
  132. package/dist/queryDrafts.js.map +1 -1
  133. package/dist/testCredentials.js.map +1 -1
  134. package/dist/transactions/beginTransaction.d.ts +1 -1
  135. package/dist/transactions/beginTransaction.d.ts.map +1 -1
  136. package/dist/transactions/beginTransaction.js +3 -1
  137. package/dist/transactions/beginTransaction.js.map +1 -1
  138. package/dist/transactions/commitTransaction.d.ts +1 -1
  139. package/dist/transactions/commitTransaction.d.ts.map +1 -1
  140. package/dist/transactions/commitTransaction.js +3 -0
  141. package/dist/transactions/commitTransaction.js.map +1 -1
  142. package/dist/transactions/rollbackTransaction.d.ts +1 -1
  143. package/dist/transactions/rollbackTransaction.d.ts.map +1 -1
  144. package/dist/transactions/rollbackTransaction.js +13 -7
  145. package/dist/transactions/rollbackTransaction.js.map +1 -1
  146. package/dist/types.d.ts +7 -31
  147. package/dist/types.d.ts.map +1 -1
  148. package/dist/types.js.map +1 -1
  149. package/dist/updateGlobal.d.ts +1 -1
  150. package/dist/updateGlobal.d.ts.map +1 -1
  151. package/dist/updateGlobal.js +18 -5
  152. package/dist/updateGlobal.js.map +1 -1
  153. package/dist/updateGlobalVersion.d.ts +2 -3
  154. package/dist/updateGlobalVersion.d.ts.map +1 -1
  155. package/dist/updateGlobalVersion.js +19 -5
  156. package/dist/updateGlobalVersion.js.map +1 -1
  157. package/dist/updateOne.d.ts +1 -1
  158. package/dist/updateOne.d.ts.map +1 -1
  159. package/dist/updateOne.js +25 -7
  160. package/dist/updateOne.js.map +1 -1
  161. package/dist/updateVersion.d.ts +1 -1
  162. package/dist/updateVersion.d.ts.map +1 -1
  163. package/dist/updateVersion.js +18 -4
  164. package/dist/updateVersion.js.map +1 -1
  165. package/dist/upsert.d.ts +3 -0
  166. package/dist/upsert.d.ts.map +1 -0
  167. package/dist/upsert.js +15 -0
  168. package/dist/upsert.js.map +1 -0
  169. package/dist/utilities/buildJoinAggregation.d.ts +18 -0
  170. package/dist/utilities/buildJoinAggregation.d.ts.map +1 -0
  171. package/dist/utilities/buildJoinAggregation.js +159 -0
  172. package/dist/utilities/buildJoinAggregation.js.map +1 -0
  173. package/dist/utilities/buildProjectionFromSelect.d.ts +8 -0
  174. package/dist/utilities/buildProjectionFromSelect.d.ts.map +1 -0
  175. package/dist/utilities/buildProjectionFromSelect.js +171 -0
  176. package/dist/utilities/buildProjectionFromSelect.js.map +1 -0
  177. package/dist/utilities/getDBName.d.ts +1 -1
  178. package/dist/utilities/getDBName.d.ts.map +1 -1
  179. package/dist/utilities/getDBName.js +3 -1
  180. package/dist/utilities/getDBName.js.map +1 -1
  181. package/dist/utilities/handleError.d.ts +6 -2
  182. package/dist/utilities/handleError.d.ts.map +1 -1
  183. package/dist/utilities/handleError.js +12 -9
  184. package/dist/utilities/handleError.js.map +1 -1
  185. package/dist/utilities/sanitizeInternalFields.d.ts +1 -2
  186. package/dist/utilities/sanitizeInternalFields.d.ts.map +1 -1
  187. package/dist/utilities/sanitizeInternalFields.js +1 -2
  188. package/dist/utilities/sanitizeInternalFields.js.map +1 -1
  189. package/dist/utilities/sanitizeRelationshipIDs.d.ts +9 -0
  190. package/dist/utilities/sanitizeRelationshipIDs.d.ts.map +1 -0
  191. package/dist/utilities/sanitizeRelationshipIDs.js +115 -0
  192. package/dist/utilities/sanitizeRelationshipIDs.js.map +1 -0
  193. package/dist/withSession.d.ts +3 -27
  194. package/dist/withSession.d.ts.map +1 -1
  195. package/dist/withSession.js +10 -4
  196. package/dist/withSession.js.map +1 -1
  197. package/package.json +14 -12
@@ -1,33 +1,121 @@
1
+ import ObjectIdImport from 'bson-objectid';
1
2
  import mongoose from 'mongoose';
2
- import { createArrayFromCommaDelineated } from 'payload/utilities';
3
+ import { createArrayFromCommaDelineated } from 'payload';
4
+ const buildExistsQuery = (formattedValue, path)=>{
5
+ if (formattedValue) {
6
+ return {
7
+ rawQuery: {
8
+ $and: [
9
+ {
10
+ [path]: {
11
+ $exists: true
12
+ }
13
+ },
14
+ {
15
+ [path]: {
16
+ $ne: null
17
+ }
18
+ },
19
+ {
20
+ [path]: {
21
+ $ne: ''
22
+ }
23
+ }
24
+ ]
25
+ }
26
+ };
27
+ } else {
28
+ return {
29
+ rawQuery: {
30
+ $or: [
31
+ {
32
+ [path]: {
33
+ $exists: false
34
+ }
35
+ },
36
+ {
37
+ [path]: {
38
+ $eq: null
39
+ }
40
+ },
41
+ {
42
+ [path]: {
43
+ $eq: ''
44
+ }
45
+ }
46
+ ]
47
+ }
48
+ };
49
+ }
50
+ };
51
+ const ObjectId = ObjectIdImport.default || ObjectIdImport;
3
52
  export const sanitizeQueryValue = ({ field, hasCustomID, operator, path, val })=>{
4
53
  let formattedValue = val;
5
54
  let formattedOperator = operator;
6
55
  // Disregard invalid _ids
7
- if (path === '_id' && typeof val === 'string' && val.split(',').length === 1) {
8
- if (!hasCustomID) {
9
- const isValid = mongoose.Types.ObjectId.isValid(val);
10
- if (!isValid) {
11
- return {
12
- operator: formattedOperator,
13
- val: undefined
14
- };
56
+ if (path === '_id') {
57
+ if (typeof val === 'string' && val.split(',').length === 1) {
58
+ if (!hasCustomID) {
59
+ const isValid = mongoose.Types.ObjectId.isValid(val);
60
+ if (!isValid) {
61
+ return {
62
+ operator: formattedOperator,
63
+ val: undefined
64
+ };
65
+ } else {
66
+ if ([
67
+ 'in',
68
+ 'not_in'
69
+ ].includes(operator)) {
70
+ formattedValue = createArrayFromCommaDelineated(formattedValue).map((id)=>ObjectId(id));
71
+ } else {
72
+ formattedValue = ObjectId(val);
73
+ }
74
+ }
15
75
  }
16
- }
17
- if (field.type === 'number') {
18
- const parsedNumber = parseFloat(val);
19
- if (Number.isNaN(parsedNumber)) {
20
- return {
21
- operator: formattedOperator,
22
- val: undefined
23
- };
76
+ if (field.type === 'number') {
77
+ const parsedNumber = parseFloat(val);
78
+ if (Number.isNaN(parsedNumber)) {
79
+ return {
80
+ operator: formattedOperator,
81
+ val: undefined
82
+ };
83
+ }
84
+ }
85
+ } else if (Array.isArray(val) || typeof val === 'string' && val.split(',').length > 1) {
86
+ if (typeof val === 'string') {
87
+ formattedValue = createArrayFromCommaDelineated(val);
24
88
  }
89
+ formattedValue = formattedValue.reduce((formattedValues, inVal)=>{
90
+ const newValues = [
91
+ inVal
92
+ ];
93
+ if (!hasCustomID) {
94
+ if (mongoose.Types.ObjectId.isValid(inVal)) {
95
+ newValues.push(ObjectId(inVal));
96
+ }
97
+ }
98
+ if (field.type === 'number') {
99
+ const parsedNumber = parseFloat(inVal);
100
+ if (!Number.isNaN(parsedNumber)) {
101
+ newValues.push(parsedNumber);
102
+ }
103
+ }
104
+ return [
105
+ ...formattedValues,
106
+ ...newValues
107
+ ];
108
+ }, []);
25
109
  }
26
110
  }
27
111
  // Cast incoming values as proper searchable types
28
112
  if (field.type === 'checkbox' && typeof val === 'string') {
29
- if (val.toLowerCase() === 'true') formattedValue = true;
30
- if (val.toLowerCase() === 'false') formattedValue = false;
113
+ if (val.toLowerCase() === 'true') {
114
+ formattedValue = true;
115
+ }
116
+ if (val.toLowerCase() === 'false') {
117
+ formattedValue = false;
118
+ }
31
119
  }
32
120
  if ([
33
121
  'all',
@@ -39,8 +127,14 @@ export const sanitizeQueryValue = ({ field, hasCustomID, operator, path, val })=
39
127
  formattedValue = formattedValue.map((arrayVal)=>parseFloat(arrayVal));
40
128
  }
41
129
  }
42
- if (field.type === 'number' && typeof formattedValue === 'string') {
43
- formattedValue = Number(val);
130
+ if (field.type === 'number') {
131
+ if (typeof formattedValue === 'string' && operator !== 'exists') {
132
+ formattedValue = Number(val);
133
+ }
134
+ if (operator === 'exists') {
135
+ formattedValue = val === 'true' ? true : val === 'false' ? false : Boolean(val);
136
+ return buildExistsQuery(formattedValue, path);
137
+ }
44
138
  }
45
139
  if (field.type === 'date' && typeof val === 'string' && operator !== 'exists') {
46
140
  formattedValue = new Date(val);
@@ -57,6 +151,11 @@ export const sanitizeQueryValue = ({ field, hasCustomID, operator, path, val })=
57
151
  }
58
152
  // Object equality requires the value to be the first key in the object that is being queried.
59
153
  if (operator === 'equals' && formattedValue && typeof formattedValue === 'object' && formattedValue.value && formattedValue.relationTo) {
154
+ const { value } = formattedValue;
155
+ const isValid = mongoose.Types.ObjectId.isValid(value);
156
+ if (isValid) {
157
+ formattedValue.value = ObjectId(value);
158
+ }
60
159
  return {
61
160
  rawQuery: {
62
161
  $and: [
@@ -74,20 +173,32 @@ export const sanitizeQueryValue = ({ field, hasCustomID, operator, path, val })=
74
173
  }
75
174
  };
76
175
  }
77
- if (operator === 'in' && Array.isArray(formattedValue)) {
176
+ if ([
177
+ 'in',
178
+ 'not_in'
179
+ ].includes(operator) && Array.isArray(formattedValue)) {
78
180
  formattedValue = formattedValue.reduce((formattedValues, inVal)=>{
79
181
  const newValues = [
80
182
  inVal
81
183
  ];
82
- if (mongoose.Types.ObjectId.isValid(inVal)) newValues.push(new mongoose.Types.ObjectId(inVal));
184
+ if (mongoose.Types.ObjectId.isValid(inVal)) {
185
+ newValues.push(ObjectId(inVal));
186
+ }
83
187
  const parsedNumber = parseFloat(inVal);
84
- if (!Number.isNaN(parsedNumber)) newValues.push(parsedNumber);
188
+ if (!Number.isNaN(parsedNumber)) {
189
+ newValues.push(parsedNumber);
190
+ }
85
191
  return [
86
192
  ...formattedValues,
87
193
  ...newValues
88
194
  ];
89
195
  }, []);
90
196
  }
197
+ if (operator === 'contains' && typeof formattedValue === 'string') {
198
+ if (mongoose.Types.ObjectId.isValid(formattedValue)) {
199
+ formattedValue = ObjectId(formattedValue);
200
+ }
201
+ }
91
202
  }
92
203
  // Set up specific formatting necessary by operators
93
204
  if (operator === 'near') {
@@ -113,8 +224,12 @@ export const sanitizeQueryValue = ({ field, hasCustomID, operator, path, val })=
113
224
  ]
114
225
  }
115
226
  };
116
- if (maxDistance) formattedValue.$maxDistance = parseFloat(maxDistance);
117
- if (minDistance) formattedValue.$minDistance = parseFloat(minDistance);
227
+ if (maxDistance) {
228
+ formattedValue.$maxDistance = parseFloat(maxDistance);
229
+ }
230
+ if (minDistance) {
231
+ formattedValue.$minDistance = parseFloat(minDistance);
232
+ }
118
233
  }
119
234
  }
120
235
  if (operator === 'within' || operator === 'intersects') {
@@ -123,12 +238,16 @@ export const sanitizeQueryValue = ({ field, hasCustomID, operator, path, val })=
123
238
  };
124
239
  }
125
240
  if (path !== '_id' || path === '_id' && hasCustomID && field.type === 'text') {
126
- if (operator === 'contains') {
241
+ if (operator === 'contains' && !mongoose.Types.ObjectId.isValid(formattedValue)) {
127
242
  formattedValue = {
128
243
  $options: 'i',
129
244
  $regex: formattedValue.replace(/[\\^$*+?.()|[\]{}]/g, '\\$&')
130
245
  };
131
246
  }
247
+ if (operator === 'exists') {
248
+ formattedValue = formattedValue === 'true' || formattedValue === true;
249
+ return buildExistsQuery(formattedValue, path);
250
+ }
132
251
  }
133
252
  if ((path === '_id' || path === 'parent') && operator === 'like' && formattedValue.length === 24 && !hasCustomID) {
134
253
  formattedOperator = 'equals';
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/queries/sanitizeQueryValue.ts"],"sourcesContent":["import type { Field, TabAsField } from 'payload/types'\n\nimport mongoose from 'mongoose'\nimport { createArrayFromCommaDelineated } from 'payload/utilities'\n\ntype SanitizeQueryValueArgs = {\n field: Field | TabAsField\n hasCustomID: boolean\n operator: string\n path: string\n val: any\n}\n\nexport const sanitizeQueryValue = ({\n field,\n hasCustomID,\n operator,\n path,\n val,\n}: SanitizeQueryValueArgs): {\n operator?: string\n rawQuery?: unknown\n val?: unknown\n} => {\n let formattedValue = val\n let formattedOperator = operator\n\n // Disregard invalid _ids\n if (path === '_id' && typeof val === 'string' && val.split(',').length === 1) {\n if (!hasCustomID) {\n const isValid = mongoose.Types.ObjectId.isValid(val)\n\n if (!isValid) {\n return { operator: formattedOperator, val: undefined }\n }\n }\n\n if (field.type === 'number') {\n const parsedNumber = parseFloat(val)\n\n if (Number.isNaN(parsedNumber)) {\n return { operator: formattedOperator, val: undefined }\n }\n }\n }\n\n // Cast incoming values as proper searchable types\n if (field.type === 'checkbox' && typeof val === 'string') {\n if (val.toLowerCase() === 'true') formattedValue = true\n if (val.toLowerCase() === 'false') formattedValue = false\n }\n\n if (['all', 'in', 'not_in'].includes(operator) && typeof formattedValue === 'string') {\n formattedValue = createArrayFromCommaDelineated(formattedValue)\n\n if (field.type === 'number') {\n formattedValue = formattedValue.map((arrayVal) => parseFloat(arrayVal))\n }\n }\n\n if (field.type === 'number' && typeof formattedValue === 'string') {\n formattedValue = Number(val)\n }\n\n if (field.type === 'date' && typeof val === 'string' && operator !== 'exists') {\n formattedValue = new Date(val)\n if (Number.isNaN(Date.parse(formattedValue))) {\n return undefined\n }\n }\n\n if (['relationship', 'upload'].includes(field.type)) {\n if (val === 'null') {\n formattedValue = null\n }\n\n // Object equality requires the value to be the first key in the object that is being queried.\n if (\n operator === 'equals' &&\n formattedValue &&\n typeof formattedValue === 'object' &&\n formattedValue.value &&\n formattedValue.relationTo\n ) {\n return {\n rawQuery: {\n $and: [\n { [`${path}.value`]: { $eq: formattedValue.value } },\n { [`${path}.relationTo`]: { $eq: formattedValue.relationTo } },\n ],\n },\n }\n }\n\n if (operator === 'in' && Array.isArray(formattedValue)) {\n formattedValue = formattedValue.reduce((formattedValues, inVal) => {\n const newValues = [inVal]\n if (mongoose.Types.ObjectId.isValid(inVal))\n newValues.push(new mongoose.Types.ObjectId(inVal))\n\n const parsedNumber = parseFloat(inVal)\n if (!Number.isNaN(parsedNumber)) newValues.push(parsedNumber)\n\n return [...formattedValues, ...newValues]\n }, [])\n }\n }\n\n // Set up specific formatting necessary by operators\n\n if (operator === 'near') {\n let lng\n let lat\n let maxDistance\n let minDistance\n\n if (Array.isArray(formattedValue)) {\n ;[lng, lat, maxDistance, minDistance] = formattedValue\n }\n\n if (typeof formattedValue === 'string') {\n ;[lng, lat, maxDistance, minDistance] = createArrayFromCommaDelineated(formattedValue)\n }\n\n if (lng == null || lat == null || (maxDistance == null && minDistance == null)) {\n formattedValue = undefined\n } else {\n formattedValue = {\n $geometry: { type: 'Point', coordinates: [parseFloat(lng), parseFloat(lat)] },\n }\n\n if (maxDistance) formattedValue.$maxDistance = parseFloat(maxDistance)\n if (minDistance) formattedValue.$minDistance = parseFloat(minDistance)\n }\n }\n\n if (operator === 'within' || operator === 'intersects') {\n formattedValue = {\n $geometry: formattedValue,\n }\n }\n\n if (path !== '_id' || (path === '_id' && hasCustomID && field.type === 'text')) {\n if (operator === 'contains') {\n formattedValue = {\n $options: 'i',\n $regex: formattedValue.replace(/[\\\\^$*+?.()|[\\]{}]/g, '\\\\$&'),\n }\n }\n }\n\n if (\n (path === '_id' || path === 'parent') &&\n operator === 'like' &&\n formattedValue.length === 24 &&\n !hasCustomID\n ) {\n formattedOperator = 'equals'\n }\n\n if (operator === 'exists') {\n formattedValue = formattedValue === 'true' || formattedValue === true\n\n // Clearable fields\n if (['relationship', 'select', 'upload'].includes(field.type)) {\n if (formattedValue) {\n return {\n rawQuery: {\n $and: [{ [path]: { $exists: true } }, { [path]: { $ne: null } }],\n },\n }\n } else {\n return {\n rawQuery: {\n $or: [{ [path]: { $exists: false } }, { [path]: { $eq: null } }],\n },\n }\n }\n }\n }\n\n return { operator: formattedOperator, val: formattedValue }\n}\n"],"names":["mongoose","createArrayFromCommaDelineated","sanitizeQueryValue","field","hasCustomID","operator","path","val","formattedValue","formattedOperator","split","length","isValid","Types","ObjectId","undefined","type","parsedNumber","parseFloat","Number","isNaN","toLowerCase","includes","map","arrayVal","Date","parse","value","relationTo","rawQuery","$and","$eq","Array","isArray","reduce","formattedValues","inVal","newValues","push","lng","lat","maxDistance","minDistance","$geometry","coordinates","$maxDistance","$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mB;QACnB,IAAI;YAAC;YAAgB;YAAU;SAAS,CAACc,QAAQ,CAACnB,MAAMa,IAAI,GAAG;YAC7D,IAAIR,gBAAgB;gBAClB,OAAO;oBACLqB,UAAU;wBACRC,MAAM;4BAAC;gCAAE,CAACxB,KAAK,EAAE;oCAAE4C,SAAS;gCAAK;4BAAE;4BAAG;gCAAE,CAAC5C,KAAK,EAAE;oCAAE6C,KAAK;gCAAK;4BAAE;yBAAE;oBAClE;gBACF;YACF,OAAO;gBACL,OAAO;oBACLtB,UAAU;wBACRuB,KAAK;4BAAC;gCAAE,CAAC9C,KAAK,EAAE;oCAAE4C,SAAS;gCAAM;4BAAE;4BAAG;gCAAE,CAAC5C,KAAK,EAAE;oCAAEyB,KAAK;gCAAK;4BAAE;yBAAE;oBAClE;gBACF;YACF;QACF;IACF;IAEA,OAAO;QAAE1B,UAAUI;QAAmBF,KAAKC;IAAe;AAC5D,EAAC"}
1
+ {"version":3,"sources":["../../src/queries/sanitizeQueryValue.ts"],"sourcesContent":["import type { Field, TabAsField } from 'payload'\n\nimport ObjectIdImport from 'bson-objectid'\nimport mongoose from 'mongoose'\nimport { createArrayFromCommaDelineated } from 'payload'\n\ntype SanitizeQueryValueArgs = {\n field: Field | TabAsField\n hasCustomID: boolean\n operator: string\n path: string\n val: any\n}\n\nconst buildExistsQuery = (formattedValue, path) => {\n if (formattedValue) {\n return {\n rawQuery: {\n $and: [\n { [path]: { $exists: true } },\n { [path]: { $ne: null } },\n { [path]: { $ne: '' } }, // Exclude null and empty string\n ],\n },\n }\n } else {\n return {\n rawQuery: {\n $or: [\n { [path]: { $exists: false } },\n { [path]: { $eq: null } },\n { [path]: { $eq: '' } }, // Treat empty string as null / undefined\n ],\n },\n }\n }\n}\n\nconst ObjectId = (ObjectIdImport.default ||\n ObjectIdImport) as unknown as typeof ObjectIdImport.default\nexport const sanitizeQueryValue = ({\n field,\n hasCustomID,\n operator,\n path,\n val,\n}: SanitizeQueryValueArgs): {\n operator?: string\n rawQuery?: unknown\n val?: unknown\n} => {\n let formattedValue = val\n let formattedOperator = operator\n\n // Disregard invalid _ids\n if (path === '_id') {\n if (typeof val === 'string' && val.split(',').length === 1) {\n if (!hasCustomID) {\n const isValid = mongoose.Types.ObjectId.isValid(val)\n\n if (!isValid) {\n return { operator: formattedOperator, val: undefined }\n } else {\n if (['in', 'not_in'].includes(operator)) {\n formattedValue = createArrayFromCommaDelineated(formattedValue).map((id) =>\n ObjectId(id),\n )\n } else {\n formattedValue = ObjectId(val)\n }\n }\n }\n\n if (field.type === 'number') {\n const parsedNumber = parseFloat(val)\n\n if (Number.isNaN(parsedNumber)) {\n return { operator: formattedOperator, val: undefined }\n }\n }\n } else if (Array.isArray(val) || (typeof val === 'string' && val.split(',').length > 1)) {\n if (typeof val === 'string') {\n formattedValue = createArrayFromCommaDelineated(val)\n }\n\n formattedValue = formattedValue.reduce((formattedValues, inVal) => {\n const newValues = [inVal]\n if (!hasCustomID) {\n if (mongoose.Types.ObjectId.isValid(inVal)) {\n newValues.push(ObjectId(inVal))\n }\n }\n\n if (field.type === 'number') {\n const parsedNumber = parseFloat(inVal)\n if (!Number.isNaN(parsedNumber)) {\n newValues.push(parsedNumber)\n }\n }\n\n return [...formattedValues, ...newValues]\n }, [])\n }\n }\n\n // Cast incoming values as proper searchable types\n if (field.type === 'checkbox' && typeof val === 'string') {\n if (val.toLowerCase() === 'true') {\n formattedValue = true\n }\n if (val.toLowerCase() === 'false') {\n formattedValue = false\n }\n }\n\n if (['all', 'in', 'not_in'].includes(operator) && typeof formattedValue === 'string') {\n formattedValue = createArrayFromCommaDelineated(formattedValue)\n\n if (field.type === 'number') {\n formattedValue = formattedValue.map((arrayVal) => parseFloat(arrayVal))\n }\n }\n\n if (field.type === 'number') {\n if (typeof formattedValue === 'string' && operator !== 'exists') {\n formattedValue = Number(val)\n }\n\n if (operator === 'exists') {\n formattedValue = val === 'true' ? true : val === 'false' ? false : Boolean(val)\n\n return buildExistsQuery(formattedValue, path)\n }\n }\n\n if (field.type === 'date' && typeof val === 'string' && operator !== 'exists') {\n formattedValue = new Date(val)\n if (Number.isNaN(Date.parse(formattedValue))) {\n return undefined\n }\n }\n\n if (['relationship', 'upload'].includes(field.type)) {\n if (val === 'null') {\n formattedValue = null\n }\n\n // Object equality requires the value to be the first key in the object that is being queried.\n if (\n operator === 'equals' &&\n formattedValue &&\n typeof formattedValue === 'object' &&\n formattedValue.value &&\n formattedValue.relationTo\n ) {\n const { value } = formattedValue\n const isValid = mongoose.Types.ObjectId.isValid(value)\n\n if (isValid) {\n formattedValue.value = ObjectId(value)\n }\n\n return {\n rawQuery: {\n $and: [\n { [`${path}.value`]: { $eq: formattedValue.value } },\n { [`${path}.relationTo`]: { $eq: formattedValue.relationTo } },\n ],\n },\n }\n }\n\n if (['in', 'not_in'].includes(operator) && Array.isArray(formattedValue)) {\n formattedValue = formattedValue.reduce((formattedValues, inVal) => {\n const newValues = [inVal]\n if (mongoose.Types.ObjectId.isValid(inVal)) {\n newValues.push(ObjectId(inVal))\n }\n\n const parsedNumber = parseFloat(inVal)\n if (!Number.isNaN(parsedNumber)) {\n newValues.push(parsedNumber)\n }\n\n return [...formattedValues, ...newValues]\n }, [])\n }\n\n if (operator === 'contains' && typeof formattedValue === 'string') {\n if (mongoose.Types.ObjectId.isValid(formattedValue)) {\n formattedValue = ObjectId(formattedValue)\n }\n }\n }\n\n // Set up specific formatting necessary by operators\n\n if (operator === 'near') {\n let lng\n let lat\n let maxDistance\n let minDistance\n\n if (Array.isArray(formattedValue)) {\n ;[lng, lat, maxDistance, minDistance] = formattedValue\n }\n\n if (typeof formattedValue === 'string') {\n ;[lng, lat, maxDistance, minDistance] = createArrayFromCommaDelineated(formattedValue)\n }\n\n if (lng == null || lat == null || (maxDistance == null && minDistance == null)) {\n formattedValue = undefined\n } else {\n formattedValue = {\n $geometry: { type: 'Point', coordinates: [parseFloat(lng), parseFloat(lat)] },\n }\n\n if (maxDistance) {\n formattedValue.$maxDistance = parseFloat(maxDistance)\n }\n if (minDistance) {\n formattedValue.$minDistance = parseFloat(minDistance)\n }\n }\n }\n\n if (operator === 'within' || operator === 'intersects') {\n formattedValue = {\n $geometry: formattedValue,\n }\n }\n\n if (path !== '_id' || (path === '_id' && hasCustomID && field.type === 'text')) {\n if (operator === 'contains' && !mongoose.Types.ObjectId.isValid(formattedValue)) {\n formattedValue = {\n $options: 'i',\n $regex: formattedValue.replace(/[\\\\^$*+?.()|[\\]{}]/g, '\\\\$&'),\n }\n }\n\n if (operator === 'exists') {\n formattedValue = formattedValue === 'true' || formattedValue === true\n\n return buildExistsQuery(formattedValue, path)\n }\n }\n\n if (\n (path === '_id' || path === 'parent') &&\n operator === 'like' &&\n formattedValue.length === 24 &&\n !hasCustomID\n ) {\n formattedOperator = 'equals'\n }\n\n if (operator === 'exists') {\n formattedValue = formattedValue === 'true' || formattedValue === true\n\n // Clearable fields\n if (['relationship', 'select', 'upload'].includes(field.type)) {\n if (formattedValue) {\n return {\n rawQuery: {\n $and: [{ [path]: { $exists: true } }, { [path]: { $ne: null } }],\n },\n }\n } else {\n return {\n rawQuery: {\n $or: [{ [path]: { $exists: false } }, { [path]: { $eq: null } }],\n },\n }\n }\n }\n }\n\n return { operator: formattedOperator, val: formattedValue }\n}\n"],"names":["ObjectIdImport","mongoose","createArrayFromCommaDelineated","buildExistsQuery","formattedValue","path","rawQuery","$and","$exists","$ne","$or","$eq","ObjectId","default","sanitizeQueryValue","field","hasCustomID","operator","val","formattedOperator","split","length","isValid","Types","undefined","includes","map","id","type","parsedNumber","parseFloat","Number","isNaN","Array","isArray","reduce","formattedValues","inVal","newValues","push","toLowerCase","arrayVal","Boolean","Date","parse","value","relationTo","lng","lat","maxDistance","minDistance","$geometry","coordinates","$maxDistance","$minDistance","$options","$regex","replace"],"mappings":"AAEA,OAAOA,oBAAoB,gBAAe;AAC1C,OAAOC,cAAc,WAAU;AAC/B,SAASC,8BAA8B,QAAQ,UAAS;AAUxD,MAAMC,mBAAmB,CAACC,gBAAgBC;I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IACF;IAEA,IAAIC,SAAS,SAAUA,SAAS,SAASW,eAAeD,MAAMa,IAAI,KAAK,QAAS;QAC9E,IAAIX,aAAa,cAAc,CAAChB,SAASsB,KAAK,CAACX,QAAQ,CAACU,OAAO,CAAClB,iBAAiB;YAC/EA,iBAAiB;gBACfmD,UAAU;gBACVC,QAAQpD,eAAeqD,OAAO,CAAC,uBAAuB;YACxD;QACF;QAEA,IAAIxC,aAAa,UAAU;YACzBb,iBAAiBA,mBAAmB,UAAUA,mBAAmB;YAEjE,OAAOD,iBAAiBC,gBAAgBC;QAC1C;IACF;IAEA,IACE,AAACA,CAAAA,SAAS,SAASA,SAAS,QAAO,KACnCY,aAAa,UACbb,eAAeiB,MAAM,KAAK,MAC1B,CAACL,aACD;QACAG,oBAAoB;IACtB;IAEA,IAAIF,aAAa,UAAU;QACzBb,iBAAiBA,mBAAmB,UAAUA,mBAAmB;QAEjE,mBAAmB;QACnB,IAAI;YAAC;YAAgB;YAAU;SAAS,CAACqB,QAAQ,CAACV,MAAMa,IAAI,GAAG;YAC7D,IAAIxB,gBAAgB;gBAClB,OAAO;oBACLE,UAAU;wBACRC,MAAM;4BAAC;gCAAE,CAACF,KAAK,EAAE;oCAAEG,SAAS;gCAAK;4BAAE;4BAAG;gCAAE,CAACH,KAAK,EAAE;oCAAEI,KAAK;gCAAK;4BAAE;yBAAE;oBAClE;gBACF;YACF,OAAO;gBACL,OAAO;oBACLH,UAAU;wBACRI,KAAK;4BAAC;gCAAE,CAACL,KAAK,EAAE;oCAAEG,SAAS;gCAAM;4BAAE;4BAAG;gCAAE,CAACH,KAAK,EAAE;oCAAEM,KAAK;gCAAK;4BAAE;yBAAE;oBAClE;gBACF;YACF;QACF;IACF;IAEA,OAAO;QAAEM,UAAUE;QAAmBD,KAAKd;IAAe;AAC5D,EAAC"}
@@ -1,3 +1,3 @@
1
- import type { QueryDrafts } from 'payload/database';
1
+ import type { QueryDrafts } from 'payload';
2
2
  export declare const queryDrafts: QueryDrafts;
3
3
  //# sourceMappingURL=queryDrafts.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"queryDrafts.d.ts","sourceRoot":"","sources":["../src/queryDrafts.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAWnD,eAAO,MAAM,WAAW,EAAE,WAmGzB,CAAA"}
1
+ {"version":3,"file":"queryDrafts.d.ts","sourceRoot":"","sources":["../src/queryDrafts.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAkB,WAAW,EAAE,MAAM,SAAS,CAAA;AAY1D,eAAO,MAAM,WAAW,EAAE,WAsIzB,CAAA"}
@@ -1,11 +1,13 @@
1
- import { combineQueries, flattenWhereToOperators } from 'payload/database';
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
- const options = withSession(this, req.transactionID);
10
+ const options = await withSession(this, req);
9
11
  let hasNearConstraint;
10
12
  let sort;
11
13
  if (where) {
@@ -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,9 +47,17 @@ 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
  };
54
+ if (this.collation) {
55
+ const defaultLocale = 'en';
56
+ paginationOptions.collation = {
57
+ locale: locale && locale !== 'all' && locale !== '*' ? locale : defaultLocale,
58
+ ...this.collation
59
+ };
60
+ }
46
61
  if (!useEstimatedCount && Object.keys(versionQuery).length === 0 && this.disableIndexHints !== true) {
47
62
  // Improve the performance of the countDocuments query which is used if useEstimatedCount is set to false by adding
48
63
  // a hint. By default, if no hint is provided, MongoDB does not use an indexed field to count the returned documents,
@@ -61,18 +76,31 @@ export const queryDrafts = async function queryDrafts({ collection, limit, local
61
76
  // limit must also be set here, it's ignored when pagination is false
62
77
  paginationOptions.options.limit = limit;
63
78
  }
64
- 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
+ }
65
96
  const docs = JSON.parse(JSON.stringify(result.docs));
66
97
  return {
67
98
  ...result,
68
99
  docs: docs.map((doc)=>{
69
- // eslint-disable-next-line no-param-reassign
70
100
  doc = {
71
101
  _id: doc.parent,
72
102
  id: doc.parent,
73
- ...doc.version,
74
- createdAt: doc.createdAt,
75
- updatedAt: doc.updatedAt
103
+ ...doc.version
76
104
  };
77
105
  return sanitizeInternalFields(doc);
78
106
  })
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/queryDrafts.ts"],"sourcesContent":["import type { PaginateOptions } from 'mongoose'\nimport type { QueryDrafts } from 'payload/database'\nimport type { PayloadRequestWithData } from 'payload/types'\n\nimport { combineQueries, flattenWhereToOperators } from 'payload/database'\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":"AAIA,SAASA,cAAc,EAAEC,uBAAuB,QAAQ,mBAAkB;AAI1E,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,UAAU,EACVC,MAAM,CAAC,CAA2B,EAClCC,MAAMC,OAAO,EACbC,KAAK,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;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 { 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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;QACrH,mHAAmH;QACnH,4BAA4B;QAC5BN,kBAAkBO,gBAAgB,GAAG;YACnC,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,"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,3 +1,3 @@
1
- import type { BeginTransaction } from 'payload/database';
1
+ import type { BeginTransaction } from 'payload';
2
2
  export declare const beginTransaction: BeginTransaction;
3
3
  //# sourceMappingURL=beginTransaction.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"beginTransaction.d.ts","sourceRoot":"","sources":["../../src/transactions/beginTransaction.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;AAOxD,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
- import { APIError } from 'payload/errors';
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/database'\n\nimport { APIError } from 'payload/errors'\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,iBAAgB;AACzC,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,3 +1,3 @@
1
- import type { CommitTransaction } from 'payload/database';
1
+ import type { CommitTransaction } from 'payload';
2
2
  export declare const commitTransaction: CommitTransaction;
3
3
  //# sourceMappingURL=commitTransaction.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"commitTransaction.d.ts","sourceRoot":"","sources":["../../src/transactions/commitTransaction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AAEzD,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/database'\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,3 +1,3 @@
1
- import type { RollbackTransaction } from 'payload/database';
1
+ import type { RollbackTransaction } from 'payload';
2
2
  export declare const rollbackTransaction: RollbackTransaction;
3
3
  //# sourceMappingURL=rollbackTransaction.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"rollbackTransaction.d.ts","sourceRoot":"","sources":["../../src/transactions/rollbackTransaction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAA;AAE3D,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/database'\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"}