@payloadcms/db-mongodb 3.0.0-canary.e14c80d → 3.0.0-canary.e198dc5
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/connect.d.ts.map +1 -1
- package/dist/connect.js +7 -3
- package/dist/connect.js.map +1 -1
- package/dist/create.d.ts.map +1 -1
- package/dist/create.js +7 -1
- package/dist/create.js.map +1 -1
- package/dist/createGlobal.d.ts.map +1 -1
- package/dist/createGlobal.js +10 -5
- package/dist/createGlobal.js.map +1 -1
- package/dist/createGlobalVersion.d.ts +1 -1
- package/dist/createGlobalVersion.d.ts.map +1 -1
- package/dist/createGlobalVersion.js +13 -4
- package/dist/createGlobalVersion.js.map +1 -1
- package/dist/createMigration.js +2 -2
- package/dist/createMigration.js.map +1 -1
- package/dist/createVersion.d.ts +1 -1
- package/dist/createVersion.d.ts.map +1 -1
- package/dist/createVersion.js +31 -9
- package/dist/createVersion.js.map +1 -1
- package/dist/deleteOne.js +1 -1
- package/dist/deleteOne.js.map +1 -1
- package/dist/find.d.ts.map +1 -1
- package/dist/find.js +20 -3
- package/dist/find.js.map +1 -1
- package/dist/findGlobal.js +1 -1
- package/dist/findGlobal.js.map +1 -1
- package/dist/findGlobalVersions.d.ts.map +1 -1
- package/dist/findGlobalVersions.js +2 -2
- package/dist/findGlobalVersions.js.map +1 -1
- package/dist/findOne.d.ts.map +1 -1
- package/dist/findOne.js +19 -3
- package/dist/findOne.js.map +1 -1
- package/dist/findVersions.js +1 -1
- package/dist/findVersions.js.map +1 -1
- package/dist/index.d.ts +6 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -5
- package/dist/index.js.map +1 -1
- package/dist/init.d.ts.map +1 -1
- package/dist/init.js +9 -6
- package/dist/init.js.map +1 -1
- package/dist/models/buildCollectionSchema.d.ts +1 -2
- package/dist/models/buildCollectionSchema.d.ts.map +1 -1
- package/dist/models/buildCollectionSchema.js +7 -4
- package/dist/models/buildCollectionSchema.js.map +1 -1
- package/dist/models/buildGlobalModel.js +2 -2
- package/dist/models/buildGlobalModel.js.map +1 -1
- package/dist/models/buildSchema.d.ts +1 -2
- package/dist/models/buildSchema.d.ts.map +1 -1
- package/dist/models/buildSchema.js +88 -11
- package/dist/models/buildSchema.js.map +1 -1
- package/dist/queries/buildQuery.d.ts +2 -2
- package/dist/queries/buildQuery.d.ts.map +1 -1
- package/dist/queries/buildQuery.js +1 -2
- package/dist/queries/buildQuery.js.map +1 -1
- package/dist/queries/buildSearchParams.d.ts.map +1 -1
- package/dist/queries/buildSearchParams.js +19 -11
- package/dist/queries/buildSearchParams.js.map +1 -1
- package/dist/queries/getLocalizedSortProperty.spec.js +1 -1
- package/dist/queries/getLocalizedSortProperty.spec.js.map +1 -1
- package/dist/queries/parseParams.d.ts.map +1 -1
- package/dist/queries/parseParams.js +3 -1
- package/dist/queries/parseParams.js.map +1 -1
- package/dist/queries/sanitizeQueryValue.d.ts.map +1 -1
- package/dist/queries/sanitizeQueryValue.js +142 -26
- package/dist/queries/sanitizeQueryValue.js.map +1 -1
- package/dist/queryDrafts.js +1 -1
- package/dist/queryDrafts.js.map +1 -1
- package/dist/transactions/beginTransaction.d.ts.map +1 -1
- package/dist/transactions/beginTransaction.js +2 -0
- package/dist/transactions/beginTransaction.js.map +1 -1
- package/dist/transactions/commitTransaction.d.ts.map +1 -1
- package/dist/transactions/commitTransaction.js +3 -1
- package/dist/transactions/commitTransaction.js.map +1 -1
- package/dist/types.d.ts +7 -4
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/updateGlobal.d.ts.map +1 -1
- package/dist/updateGlobal.js +8 -2
- package/dist/updateGlobal.js.map +1 -1
- package/dist/updateGlobalVersion.d.ts +2 -2
- package/dist/updateGlobalVersion.d.ts.map +1 -1
- package/dist/updateGlobalVersion.js +10 -3
- package/dist/updateGlobalVersion.js.map +1 -1
- package/dist/updateOne.d.ts.map +1 -1
- package/dist/updateOne.js +10 -3
- package/dist/updateOne.js.map +1 -1
- package/dist/updateVersion.d.ts +1 -1
- package/dist/updateVersion.d.ts.map +1 -1
- package/dist/updateVersion.js +8 -1
- package/dist/updateVersion.js.map +1 -1
- package/dist/upsert.d.ts +3 -0
- package/dist/upsert.d.ts.map +1 -0
- package/dist/upsert.js +14 -0
- package/dist/upsert.js.map +1 -0
- package/dist/utilities/buildJoinAggregation.d.ts +15 -0
- package/dist/utilities/buildJoinAggregation.d.ts.map +1 -0
- package/dist/utilities/buildJoinAggregation.js +148 -0
- package/dist/utilities/buildJoinAggregation.js.map +1 -0
- package/dist/utilities/getDBName.d.ts.map +1 -1
- package/dist/utilities/getDBName.js +3 -1
- package/dist/utilities/getDBName.js.map +1 -1
- package/dist/utilities/sanitizeInternalFields.d.ts +1 -2
- package/dist/utilities/sanitizeInternalFields.d.ts.map +1 -1
- package/dist/utilities/sanitizeInternalFields.js +1 -2
- package/dist/utilities/sanitizeInternalFields.js.map +1 -1
- package/dist/utilities/sanitizeRelationshipIDs.d.ts +9 -0
- package/dist/utilities/sanitizeRelationshipIDs.d.ts.map +1 -0
- package/dist/utilities/sanitizeRelationshipIDs.js +111 -0
- package/dist/utilities/sanitizeRelationshipIDs.js.map +1 -0
- package/dist/withSession.d.ts +1 -1
- package/dist/withSession.d.ts.map +1 -1
- package/dist/withSession.js +5 -3
- package/dist/withSession.js.map +1 -1
- package/package.json +9 -6
@@ -1,33 +1,118 @@
|
|
1
|
+
import ObjectIdImport from 'bson-objectid';
|
1
2
|
import mongoose from 'mongoose';
|
2
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'
|
8
|
-
if (
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
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
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
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
|
+
}
|
24
84
|
}
|
85
|
+
} else if (Array.isArray(val)) {
|
86
|
+
formattedValue = formattedValue.reduce((formattedValues, inVal)=>{
|
87
|
+
const newValues = [
|
88
|
+
inVal
|
89
|
+
];
|
90
|
+
if (!hasCustomID) {
|
91
|
+
if (mongoose.Types.ObjectId.isValid(inVal)) {
|
92
|
+
newValues.push(ObjectId(inVal));
|
93
|
+
}
|
94
|
+
}
|
95
|
+
if (field.type === 'number') {
|
96
|
+
const parsedNumber = parseFloat(inVal);
|
97
|
+
if (!Number.isNaN(parsedNumber)) {
|
98
|
+
newValues.push(parsedNumber);
|
99
|
+
}
|
100
|
+
}
|
101
|
+
return [
|
102
|
+
...formattedValues,
|
103
|
+
...newValues
|
104
|
+
];
|
105
|
+
}, []);
|
25
106
|
}
|
26
107
|
}
|
27
108
|
// Cast incoming values as proper searchable types
|
28
109
|
if (field.type === 'checkbox' && typeof val === 'string') {
|
29
|
-
if (val.toLowerCase() === 'true')
|
30
|
-
|
110
|
+
if (val.toLowerCase() === 'true') {
|
111
|
+
formattedValue = true;
|
112
|
+
}
|
113
|
+
if (val.toLowerCase() === 'false') {
|
114
|
+
formattedValue = false;
|
115
|
+
}
|
31
116
|
}
|
32
117
|
if ([
|
33
118
|
'all',
|
@@ -39,8 +124,14 @@ export const sanitizeQueryValue = ({ field, hasCustomID, operator, path, val })=
|
|
39
124
|
formattedValue = formattedValue.map((arrayVal)=>parseFloat(arrayVal));
|
40
125
|
}
|
41
126
|
}
|
42
|
-
if (field.type === 'number'
|
43
|
-
formattedValue
|
127
|
+
if (field.type === 'number') {
|
128
|
+
if (typeof formattedValue === 'string' && operator !== 'exists') {
|
129
|
+
formattedValue = Number(val);
|
130
|
+
}
|
131
|
+
if (operator === 'exists') {
|
132
|
+
formattedValue = val === 'true' ? true : val === 'false' ? false : Boolean(val);
|
133
|
+
return buildExistsQuery(formattedValue, path);
|
134
|
+
}
|
44
135
|
}
|
45
136
|
if (field.type === 'date' && typeof val === 'string' && operator !== 'exists') {
|
46
137
|
formattedValue = new Date(val);
|
@@ -57,6 +148,11 @@ export const sanitizeQueryValue = ({ field, hasCustomID, operator, path, val })=
|
|
57
148
|
}
|
58
149
|
// Object equality requires the value to be the first key in the object that is being queried.
|
59
150
|
if (operator === 'equals' && formattedValue && typeof formattedValue === 'object' && formattedValue.value && formattedValue.relationTo) {
|
151
|
+
const { value } = formattedValue;
|
152
|
+
const isValid = mongoose.Types.ObjectId.isValid(value);
|
153
|
+
if (isValid) {
|
154
|
+
formattedValue.value = ObjectId(value);
|
155
|
+
}
|
60
156
|
return {
|
61
157
|
rawQuery: {
|
62
158
|
$and: [
|
@@ -74,20 +170,32 @@ export const sanitizeQueryValue = ({ field, hasCustomID, operator, path, val })=
|
|
74
170
|
}
|
75
171
|
};
|
76
172
|
}
|
77
|
-
if (
|
173
|
+
if ([
|
174
|
+
'in',
|
175
|
+
'not_in'
|
176
|
+
].includes(operator) && Array.isArray(formattedValue)) {
|
78
177
|
formattedValue = formattedValue.reduce((formattedValues, inVal)=>{
|
79
178
|
const newValues = [
|
80
179
|
inVal
|
81
180
|
];
|
82
|
-
if (mongoose.Types.ObjectId.isValid(inVal))
|
181
|
+
if (mongoose.Types.ObjectId.isValid(inVal)) {
|
182
|
+
newValues.push(ObjectId(inVal));
|
183
|
+
}
|
83
184
|
const parsedNumber = parseFloat(inVal);
|
84
|
-
if (!Number.isNaN(parsedNumber))
|
185
|
+
if (!Number.isNaN(parsedNumber)) {
|
186
|
+
newValues.push(parsedNumber);
|
187
|
+
}
|
85
188
|
return [
|
86
189
|
...formattedValues,
|
87
190
|
...newValues
|
88
191
|
];
|
89
192
|
}, []);
|
90
193
|
}
|
194
|
+
if (operator === 'contains' && typeof formattedValue === 'string') {
|
195
|
+
if (mongoose.Types.ObjectId.isValid(formattedValue)) {
|
196
|
+
formattedValue = ObjectId(formattedValue);
|
197
|
+
}
|
198
|
+
}
|
91
199
|
}
|
92
200
|
// Set up specific formatting necessary by operators
|
93
201
|
if (operator === 'near') {
|
@@ -113,8 +221,12 @@ export const sanitizeQueryValue = ({ field, hasCustomID, operator, path, val })=
|
|
113
221
|
]
|
114
222
|
}
|
115
223
|
};
|
116
|
-
if (maxDistance)
|
117
|
-
|
224
|
+
if (maxDistance) {
|
225
|
+
formattedValue.$maxDistance = parseFloat(maxDistance);
|
226
|
+
}
|
227
|
+
if (minDistance) {
|
228
|
+
formattedValue.$minDistance = parseFloat(minDistance);
|
229
|
+
}
|
118
230
|
}
|
119
231
|
}
|
120
232
|
if (operator === 'within' || operator === 'intersects') {
|
@@ -123,12 +235,16 @@ export const sanitizeQueryValue = ({ field, hasCustomID, operator, path, val })=
|
|
123
235
|
};
|
124
236
|
}
|
125
237
|
if (path !== '_id' || path === '_id' && hasCustomID && field.type === 'text') {
|
126
|
-
if (operator === 'contains') {
|
238
|
+
if (operator === 'contains' && !mongoose.Types.ObjectId.isValid(formattedValue)) {
|
127
239
|
formattedValue = {
|
128
240
|
$options: 'i',
|
129
241
|
$regex: formattedValue.replace(/[\\^$*+?.()|[\]{}]/g, '\\$&')
|
130
242
|
};
|
131
243
|
}
|
244
|
+
if (operator === 'exists') {
|
245
|
+
formattedValue = formattedValue === 'true' || formattedValue === true;
|
246
|
+
return buildExistsQuery(formattedValue, path);
|
247
|
+
}
|
132
248
|
}
|
133
249
|
if ((path === '_id' || path === 'parent') && operator === 'like' && formattedValue.length === 24 && !hasCustomID) {
|
134
250
|
formattedOperator = 'equals';
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/queries/sanitizeQueryValue.ts"],"sourcesContent":["import type { Field, TabAsField } from 'payload'\n\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\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","$minDistance","$options","$regex","replace","$exists","$ne","$or"],"mappings":"AAEA,OAAOA,cAAc,WAAU;AAC/B,SAASC,8BAA8B,QAAQ,UAAS;AAUxD,OAAO,MAAMC,qBAAqB,CAAC,EACjCC,KAAK,EACLC,WAAW,EACXC,QAAQ,EACRC,IAAI,EACJC,GAAG,EACoB;IAKvB,IAAIC,iBAAiBD;IACrB,IAAIE,oBAAoBJ;IAExB,yBAAyB;IACzB,IAAIC,SAAS,SAAS,OAAOC,QAAQ,YAAYA,IAAIG,KAAK,CAAC,KAAKC,MAAM,KAAK,GAAG;QAC5E,IAAI,CAACP,aAAa;YAChB,MAAMQ,UAAUZ,SAASa,KAAK,CAACC,QAAQ,CAACF,OAAO,CAACL;YAEhD,IAAI,CAACK,SAAS;gBACZ,OAAO;oBAAEP,UAAUI;oBAAmBF,KAAKQ;gBAAU;YACvD;QACF;QAEA,IAAIZ,MAAMa,IAAI,KAAK,UAAU;YAC3B,MAAMC,eAAeC,WAAWX;YAEhC,IAAIY,OAAOC,KAAK,CAACH,eAAe;gBAC9B,OAAO;oBAAEZ,UAAUI;oBAAmBF,KAAKQ;gBAAU;YACvD;QACF;IACF;IAEA,kDAAkD;IAClD,IAAIZ,MAAMa,IAAI,KAAK,cAAc,OAAOT,QAAQ,UAAU;QACxD,IAAIA,IAAIc,WAAW,OAAO,QAAQb,iBAAiB;QACnD,IAAID,IAAIc,WAAW,OAAO,SAASb,iBAAiB;IACtD;IAEA,IAAI;QAAC;QAAO;QAAM;KAAS,CAACc,QAAQ,CAACjB,aAAa,OAAOG,mBAAmB,UAAU;QACpFA,iBAAiBP,+BAA+BO;QAEhD,IAAIL,MAAMa,IAAI,KAAK,UAAU;YAC3BR,iBAAiBA,eAAee,GA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I,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)) {\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;IACxC,IAAID,gBAAgB;QAClB,OAAO;YACLE,UAAU;gBACRC,MAAM;oBACJ;wBAAE,CAACF,KAAK,EAAE;4BAAEG,SAAS;wBAAK;oBAAE;oBAC5B;wBAAE,CAACH,KAAK,E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Bb,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"}
|
package/dist/queryDrafts.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import { combineQueries, flattenWhereToOperators } from 'payload';
|
2
2
|
import { buildSortParam } from './queries/buildSortParam.js';
|
3
|
-
import sanitizeInternalFields from './utilities/sanitizeInternalFields.js';
|
3
|
+
import { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js';
|
4
4
|
import { withSession } from './withSession.js';
|
5
5
|
export const queryDrafts = async function queryDrafts({ collection, limit, locale, page, pagination, req = {}, sort: sortArg, where }) {
|
6
6
|
const VersionModel = this.versions[collection];
|
package/dist/queryDrafts.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/queryDrafts.ts"],"sourcesContent":["import type { PaginateOptions } from 'mongoose'\nimport type { PayloadRequest, QueryDrafts } from 'payload'\n\nimport { combineQueries, flattenWhereToOperators } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildSortParam } from './queries/buildSortParam.js'\nimport sanitizeInternalFields from './utilities/sanitizeInternalFields.js'\nimport { withSession } from './withSession.js'\n\nexport const queryDrafts: QueryDrafts = async function queryDrafts(\n this: MongooseAdapter,\n { collection, limit, locale, page, pagination, req = {} as PayloadRequest, sort: sortArg, where },\n) {\n const VersionModel = this.versions[collection]\n const collectionConfig = this.payload.collections[collection].config\n const options = await withSession(this, req)\n\n let hasNearConstraint\n let sort\n\n if (where) {\n const constraints = flattenWhereToOperators(where)\n hasNearConstraint = constraints.some((prop) => Object.keys(prop).some((key) => key === 'near'))\n }\n\n if (!hasNearConstraint) {\n sort = buildSortParam({\n config: this.payload.config,\n fields: collectionConfig.fields,\n locale,\n sort: sortArg || collectionConfig.defaultSort,\n timestamps: true,\n })\n }\n\n const combinedWhere = combineQueries({ latest: { equals: true } }, where)\n\n const versionQuery = await VersionModel.buildQuery({\n locale,\n payload: this.payload,\n where: combinedWhere,\n })\n\n // useEstimatedCount is faster, but not accurate, as it ignores any filters. It is thus set to true if there are no filters.\n const useEstimatedCount =\n hasNearConstraint || !versionQuery || Object.keys(versionQuery).length === 0\n const paginationOptions: PaginateOptions = {\n forceCountFn: hasNearConstraint,\n lean: true,\n leanWithId: true,\n options,\n page,\n pagination,\n sort,\n useEstimatedCount,\n }\n\n if (this.collation) {\n const defaultLocale = 'en'\n paginationOptions.collation = {\n locale: locale && locale !== 'all' && locale !== '*' ? locale : defaultLocale,\n ...this.collation,\n }\n }\n\n if (\n !useEstimatedCount &&\n Object.keys(versionQuery).length === 0 &&\n this.disableIndexHints !== true\n ) {\n // Improve the performance of the countDocuments query which is used if useEstimatedCount is set to false by adding\n // a hint. By default, if no hint is provided, MongoDB does not use an indexed field to count the returned documents,\n // which makes queries very slow. This only happens when no query (filter) is provided. If one is provided, it uses\n // the correct indexed field\n paginationOptions.useCustomCountFn = () => {\n return Promise.resolve(\n VersionModel.countDocuments(versionQuery, {\n hint: { _id: 1 },\n }),\n )\n }\n }\n\n if (limit > 0) {\n paginationOptions.limit = limit\n // limit must also be set here, it's ignored when pagination is false\n paginationOptions.options.limit = limit\n }\n\n const result = await VersionModel.paginate(versionQuery, paginationOptions)\n const docs = JSON.parse(JSON.stringify(result.docs))\n\n return {\n ...result,\n docs: docs.map((doc) => {\n doc = {\n _id: doc.parent,\n id: doc.parent,\n ...doc.version,\n createdAt: doc.createdAt,\n updatedAt: doc.updatedAt,\n }\n\n return sanitizeInternalFields(doc)\n }),\n }\n}\n"],"names":["combineQueries","flattenWhereToOperators","buildSortParam","sanitizeInternalFields","withSession","queryDrafts","collection","limit","locale","page","pagination","req","sort","sortArg","where","VersionModel","versions","collectionConfig","payload","collections","config","options","hasNearConstraint","constraints","some","prop","Object","keys","key","fields","defaultSort","timestamps","combinedWhere","latest","equals","versionQuery","buildQuery","useEstimatedCount","length","paginationOptions","forceCountFn","lean","leanWithId","collation","defaultLocale","disableIndexHints","useCustomCountFn","Promise","resolve","countDocuments","hint","_id","result","paginate","docs","JSON","parse","stringify","map","doc","parent","id","version","createdAt","updatedAt"],"mappings":"AAGA,SAASA,cAAc,EAAEC,uBAAuB,QAAQ,UAAS;AAIjE,SAASC,cAAc,QAAQ,8BAA6B;AAC5D,
|
1
|
+
{"version":3,"sources":["../src/queryDrafts.ts"],"sourcesContent":["import type { PaginateOptions } from 'mongoose'\nimport type { PayloadRequest, QueryDrafts } from 'payload'\n\nimport { combineQueries, flattenWhereToOperators } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildSortParam } from './queries/buildSortParam.js'\nimport { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js'\nimport { withSession } from './withSession.js'\n\nexport const queryDrafts: QueryDrafts = async function queryDrafts(\n this: MongooseAdapter,\n { collection, limit, locale, page, pagination, req = {} as PayloadRequest, sort: sortArg, where },\n) {\n const VersionModel = this.versions[collection]\n const collectionConfig = this.payload.collections[collection].config\n const options = await withSession(this, req)\n\n let hasNearConstraint\n let sort\n\n if (where) {\n const constraints = flattenWhereToOperators(where)\n hasNearConstraint = constraints.some((prop) => Object.keys(prop).some((key) => key === 'near'))\n }\n\n if (!hasNearConstraint) {\n sort = buildSortParam({\n config: this.payload.config,\n fields: collectionConfig.fields,\n locale,\n sort: sortArg || collectionConfig.defaultSort,\n timestamps: true,\n })\n }\n\n const combinedWhere = combineQueries({ latest: { equals: true } }, where)\n\n const versionQuery = await VersionModel.buildQuery({\n locale,\n payload: this.payload,\n where: combinedWhere,\n })\n\n // useEstimatedCount is faster, but not accurate, as it ignores any filters. It is thus set to true if there are no filters.\n const useEstimatedCount =\n hasNearConstraint || !versionQuery || Object.keys(versionQuery).length === 0\n const paginationOptions: PaginateOptions = {\n forceCountFn: hasNearConstraint,\n lean: true,\n leanWithId: true,\n options,\n page,\n pagination,\n sort,\n useEstimatedCount,\n }\n\n if (this.collation) {\n const defaultLocale = 'en'\n paginationOptions.collation = {\n locale: locale && locale !== 'all' && locale !== '*' ? locale : defaultLocale,\n ...this.collation,\n }\n }\n\n if (\n !useEstimatedCount &&\n Object.keys(versionQuery).length === 0 &&\n this.disableIndexHints !== true\n ) {\n // Improve the performance of the countDocuments query which is used if useEstimatedCount is set to false by adding\n // a hint. By default, if no hint is provided, MongoDB does not use an indexed field to count the returned documents,\n // which makes queries very slow. This only happens when no query (filter) is provided. If one is provided, it uses\n // the correct indexed field\n paginationOptions.useCustomCountFn = () => {\n return Promise.resolve(\n VersionModel.countDocuments(versionQuery, {\n hint: { _id: 1 },\n }),\n )\n }\n }\n\n if (limit > 0) {\n paginationOptions.limit = limit\n // limit must also be set here, it's ignored when pagination is false\n paginationOptions.options.limit = limit\n }\n\n const result = await VersionModel.paginate(versionQuery, paginationOptions)\n const docs = JSON.parse(JSON.stringify(result.docs))\n\n return {\n ...result,\n docs: docs.map((doc) => {\n doc = {\n _id: doc.parent,\n id: doc.parent,\n ...doc.version,\n createdAt: doc.createdAt,\n updatedAt: doc.updatedAt,\n }\n\n return sanitizeInternalFields(doc)\n }),\n }\n}\n"],"names":["combineQueries","flattenWhereToOperators","buildSortParam","sanitizeInternalFields","withSession","queryDrafts","collection","limit","locale","page","pagination","req","sort","sortArg","where","VersionModel","versions","collectionConfig","payload","collections","config","options","hasNearConstraint","constraints","some","prop","Object","keys","key","fields","defaultSort","timestamps","combinedWhere","latest","equals","versionQuery","buildQuery","useEstimatedCount","length","paginationOptions","forceCountFn","lean","leanWithId","collation","defaultLocale","disableIndexHints","useCustomCountFn","Promise","resolve","countDocuments","hint","_id","result","paginate","docs","JSON","parse","stringify","map","doc","parent","id","version","createdAt","updatedAt"],"mappings":"AAGA,SAASA,cAAc,EAAEC,uBAAuB,QAAQ,UAAS;AAIjE,SAASC,cAAc,QAAQ,8BAA6B;AAC5D,SAASC,sBAAsB,QAAQ,wCAAuC;AAC9E,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,cAA2B,eAAeA,YAErD,EAAEC,UAAU,EAAEC,KAAK,EAAEC,MAAM,EAAEC,IAAI,EAAEC,UAAU,EAAEC,MAAM,CAAC,CAAmB,EAAEC,MAAMC,OAAO,EAAEC,KAAK,EAAE;IAEjG,MAAMC,eAAe,IAAI,CAACC,QAAQ,CAACV,WAAW;IAC9C,MAAMW,mBAAmB,IAAI,CAACC,OAAO,CAACC,WAAW,CAACb,WAAW,CAACc,MAAM;IACpE,MAAMC,UAAU,MAAMjB,YAAY,IAAI,EAAEO;IAExC,IAAIW;IACJ,IAAIV;IAEJ,IAAIE,OAAO;QACT,MAAMS,cAActB,wBAAwBa;QAC5CQ,oBAAoBC,YAAYC,IAAI,CAAC,CAACC,OAASC,OAAOC,IAAI,CAACF,MAAMD,IAAI,CAAC,CAACI,MAAQA,QAAQ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MAAMrC,aAAasC,QAAQ,CAAClB,cAAcI;IACzD,MAAMe,OAAOC,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACL,OAAOE,IAAI;IAElD,OAAO;QACL,GAAGF,MAAM;QACTE,MAAMA,KAAKI,GAAG,CAAC,CAACC;YACdA,MAAM;gBACJR,KAAKQ,IAAIC,MAAM;gBACfC,IAAIF,IAAIC,MAAM;gBACd,GAAGD,IAAIG,OAAO;gBACdC,WAAWJ,IAAII,SAAS;gBACxBC,WAAWL,IAAIK,SAAS;YAC1B;YAEA,OAAO7D,uBAAuBwD;QAChC;IACF;AACF,EAAC"}
|
@@ -1 +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;
|
1
|
+
{"version":3,"file":"beginTransaction.d.ts","sourceRoot":"","sources":["../../src/transactions/beginTransaction.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAS/C,eAAO,MAAM,gBAAgB,EAAE,gBAqB9B,CAAA"}
|
@@ -1,5 +1,7 @@
|
|
1
1
|
import { APIError } from 'payload';
|
2
2
|
import { v4 as uuid } from 'uuid';
|
3
|
+
// Needs await to fulfill the interface
|
4
|
+
// eslint-disable-next-line @typescript-eslint/require-await
|
3
5
|
export const beginTransaction = async function beginTransaction(options) {
|
4
6
|
if (!this.connection) {
|
5
7
|
throw new APIError('beginTransaction called while no connection to the database exists');
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/transactions/beginTransaction.ts"],"sourcesContent":["import type { TransactionOptions } from 'mongodb'\nimport type { BeginTransaction } from 'payload'\n\nimport { APIError } from 'payload'\nimport { v4 as uuid } from 'uuid'\n\nimport type { MongooseAdapter } from '../index.js'\n\nexport const beginTransaction: BeginTransaction = async function beginTransaction(\n this: MongooseAdapter,\n options: TransactionOptions,\n) {\n if (!this.connection) {\n throw new APIError('beginTransaction called while no connection to the database exists')\n }\n\n const client = this.connection.getClient()\n const id = uuid()\n\n if (!this.sessions[id]) {\n this.sessions[id] = client.startSession()\n }\n if (this.sessions[id].inTransaction()) {\n this.payload.logger.warn('beginTransaction called while transaction already exists')\n } else {\n this.sessions[id].startTransaction(options || (this.transactionOptions as TransactionOptions))\n }\n\n return id\n}\n"],"names":["APIError","v4","uuid","beginTransaction","options","connection","client","getClient","id","sessions","startSession","inTransaction","payload","logger","warn","startTransaction","transactionOptions"],"mappings":"AAGA,SAASA,QAAQ,QAAQ,UAAS;AAClC,SAASC,MAAMC,IAAI,QAAQ,OAAM;AAIjC,OAAO,MAAMC,mBAAqC,eAAeA,iBAE/DC,OAA2B;IAE3B,IAAI,CAAC,IAAI,CAACC,UAAU,EAAE;QACpB,MAAM,IAAIL,SAAS;IACrB;IAEA,MAAMM,SAAS,IAAI,CAACD,UAAU,CAACE,SAAS;IACxC,MAAMC,KAAKN;IAEX,IAAI,CAAC,IAAI,CAACO,QAAQ,CAACD,GAAG,EAAE;QACtB,IAAI,CAACC,QAAQ,CAACD,GAAG,GAAGF,OAAOI,YAAY;IACzC;IACA,IAAI,IAAI,CAACD,QAAQ,CAACD,GAAG,CAACG,aAAa,IAAI;QACrC,IAAI,CAACC,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC;IAC3B,OAAO;QACL,IAAI,CAACL,QAAQ,CAACD,GAAG,CAACO,gBAAgB,CAACX,WAAY,IAAI,CAACY,kBAAkB;IACxE;IAEA,OAAOR;AACT,EAAC"}
|
1
|
+
{"version":3,"sources":["../../src/transactions/beginTransaction.ts"],"sourcesContent":["import type { TransactionOptions } from 'mongodb'\nimport type { BeginTransaction } from 'payload'\n\nimport { APIError } from 'payload'\nimport { v4 as uuid } from 'uuid'\n\nimport type { MongooseAdapter } from '../index.js'\n\n// Needs await to fulfill the interface\n// eslint-disable-next-line @typescript-eslint/require-await\nexport const beginTransaction: BeginTransaction = async function beginTransaction(\n this: MongooseAdapter,\n options: TransactionOptions,\n) {\n if (!this.connection) {\n throw new APIError('beginTransaction called while no connection to the database exists')\n }\n\n const client = this.connection.getClient()\n const id = uuid()\n\n if (!this.sessions[id]) {\n this.sessions[id] = client.startSession()\n }\n if (this.sessions[id].inTransaction()) {\n this.payload.logger.warn('beginTransaction called while transaction already exists')\n } else {\n this.sessions[id].startTransaction(options || (this.transactionOptions as TransactionOptions))\n }\n\n return id\n}\n"],"names":["APIError","v4","uuid","beginTransaction","options","connection","client","getClient","id","sessions","startSession","inTransaction","payload","logger","warn","startTransaction","transactionOptions"],"mappings":"AAGA,SAASA,QAAQ,QAAQ,UAAS;AAClC,SAASC,MAAMC,IAAI,QAAQ,OAAM;AAIjC,uCAAuC;AACvC,4DAA4D;AAC5D,OAAO,MAAMC,mBAAqC,eAAeA,iBAE/DC,OAA2B;IAE3B,IAAI,CAAC,IAAI,CAACC,UAAU,EAAE;QACpB,MAAM,IAAIL,SAAS;IACrB;IAEA,MAAMM,SAAS,IAAI,CAACD,UAAU,CAACE,SAAS;IACxC,MAAMC,KAAKN;IAEX,IAAI,CAAC,IAAI,CAACO,QAAQ,CAACD,GAAG,EAAE;QACtB,IAAI,CAACC,QAAQ,CAACD,GAAG,GAAGF,OAAOI,YAAY;IACzC;IACA,IAAI,IAAI,CAACD,QAAQ,CAACD,GAAG,CAACG,aAAa,IAAI;QACrC,IAAI,CAACC,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC;IAC3B,OAAO;QACL,IAAI,CAACL,QAAQ,CAACD,GAAG,CAACO,gBAAgB,CAACX,WAAY,IAAI,CAACY,kBAAkB;IACxE;IAEA,OAAOR;AACT,EAAC"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"commitTransaction.d.ts","sourceRoot":"","sources":["../../src/transactions/commitTransaction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAEhD,eAAO,MAAM,iBAAiB,EAAE,
|
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 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/transactions/commitTransaction.ts"],"sourcesContent":["import type { CommitTransaction } from 'payload'\n\nexport const commitTransaction: CommitTransaction = async function commitTransaction(id) {\n if (id instanceof Promise) return\n\n if (!this.sessions[id]?.inTransaction()) {\n return\n }\n\n await this.sessions[id].commitTransaction()\n try {\n await this.sessions[id].endSession()\n } catch (error) {\n // ending sessions is only best effort and won't impact anything if it fails since the transaction was committed\n }\n delete this.sessions[id]\n}\n"],"names":["commitTransaction","id","Promise","sessions","inTransaction","endSession","error"],"mappings":"AAEA,OAAO,MAAMA,oBAAuC,eAAeA,kBAAkBC,EAAE;IACrF,IAAIA,cAAcC,SAAS;
|
1
|
+
{"version":3,"sources":["../../src/transactions/commitTransaction.ts"],"sourcesContent":["import type { CommitTransaction } from 'payload'\n\nexport const commitTransaction: CommitTransaction = async function commitTransaction(id) {\n if (id instanceof Promise) {\n return\n }\n\n if (!this.sessions[id]?.inTransaction()) {\n return\n }\n\n await this.sessions[id].commitTransaction()\n try {\n await this.sessions[id].endSession()\n } catch (error) {\n // ending sessions is only best effort and won't impact anything if it fails since the transaction was committed\n }\n delete this.sessions[id]\n}\n"],"names":["commitTransaction","id","Promise","sessions","inTransaction","endSession","error"],"mappings":"AAEA,OAAO,MAAMA,oBAAuC,eAAeA,kBAAkBC,EAAE;IACrF,IAAIA,cAAcC,SAAS;QACzB;IACF;IAEA,IAAI,CAAC,IAAI,CAACC,QAAQ,CAACF,GAAG,EAAEG,iBAAiB;QACvC;IACF;IAEA,MAAM,IAAI,CAACD,QAAQ,CAACF,GAAG,CAACD,iBAAiB;IACzC,IAAI;QACF,MAAM,IAAI,CAACG,QAAQ,CAACF,GAAG,CAACI,UAAU;IACpC,EAAE,OAAOC,OAAO;IACd,gHAAgH;IAClH;IACA,OAAO,IAAI,CAACH,QAAQ,CAACF,GAAG;AAC1B,EAAC"}
|
package/dist/types.d.ts
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
import type { IndexDefinition, IndexOptions, Model, PaginateModel, SchemaOptions } from 'mongoose';
|
2
|
-
import type { ArrayField,
|
1
|
+
import type { AggregatePaginateModel, IndexDefinition, IndexOptions, Model, PaginateModel, SchemaOptions } from 'mongoose';
|
2
|
+
import type { ArrayField, BlocksField, CheckboxField, CodeField, CollapsibleField, DateField, EmailField, Field, GroupField, JoinField, JSONField, NumberField, Payload, PayloadRequest, PointField, RadioField, RelationshipField, RichTextField, RowField, SanitizedConfig, SelectField, TabsField, TextareaField, TextField, UploadField } from 'payload';
|
3
3
|
import type { BuildQueryArgs } from './queries/buildQuery.js';
|
4
|
-
export interface CollectionModel extends Model<any>, PaginateModel<any> {
|
4
|
+
export interface CollectionModel extends Model<any>, PaginateModel<any>, AggregatePaginateModel<any> {
|
5
5
|
/** buildQuery is used to transform payload's where operator into what can be used by mongoose (e.g. id => _id) */
|
6
6
|
buildQuery: (args: BuildQueryArgs) => Promise<Record<string, unknown>>;
|
7
7
|
}
|
@@ -40,13 +40,14 @@ export type FieldGeneratorFunction<TSchema, TField extends Field> = (args: Field
|
|
40
40
|
*/
|
41
41
|
export type FieldToSchemaMap<TSchema> = {
|
42
42
|
array: FieldGeneratorFunction<TSchema, ArrayField>;
|
43
|
-
blocks: FieldGeneratorFunction<TSchema,
|
43
|
+
blocks: FieldGeneratorFunction<TSchema, BlocksField>;
|
44
44
|
checkbox: FieldGeneratorFunction<TSchema, CheckboxField>;
|
45
45
|
code: FieldGeneratorFunction<TSchema, CodeField>;
|
46
46
|
collapsible: FieldGeneratorFunction<TSchema, CollapsibleField>;
|
47
47
|
date: FieldGeneratorFunction<TSchema, DateField>;
|
48
48
|
email: FieldGeneratorFunction<TSchema, EmailField>;
|
49
49
|
group: FieldGeneratorFunction<TSchema, GroupField>;
|
50
|
+
join: FieldGeneratorFunction<TSchema, JoinField>;
|
50
51
|
json: FieldGeneratorFunction<TSchema, JSONField>;
|
51
52
|
number: FieldGeneratorFunction<TSchema, NumberField>;
|
52
53
|
point: FieldGeneratorFunction<TSchema, PointField>;
|
@@ -62,8 +63,10 @@ export type FieldToSchemaMap<TSchema> = {
|
|
62
63
|
};
|
63
64
|
export type MigrateUpArgs = {
|
64
65
|
payload: Payload;
|
66
|
+
req: PayloadRequest;
|
65
67
|
};
|
66
68
|
export type MigrateDownArgs = {
|
67
69
|
payload: Payload;
|
70
|
+
req: PayloadRequest;
|
68
71
|
};
|
69
72
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,sBAAsB,EACtB,eAAe,EACf,YAAY,EACZ,KAAK,EACL,aAAa,EACb,aAAa,EACd,MAAM,UAAU,CAAA;AACjB,OAAO,KAAK,EACV,UAAU,EACV,WAAW,EACX,aAAa,EACb,SAAS,EACT,gBAAgB,EAChB,SAAS,EACT,UAAU,EACV,KAAK,EACL,UAAU,EACV,SAAS,EACT,SAAS,EACT,WAAW,EACX,OAAO,EACP,cAAc,EACd,UAAU,EACV,UAAU,EACV,iBAAiB,EACjB,aAAa,EACb,QAAQ,EACR,eAAe,EACf,WAAW,EACX,SAAS,EACT,aAAa,EACb,SAAS,EACT,WAAW,EACZ,MAAM,SAAS,CAAA;AAEhB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AAE7D,MAAM,WAAW,eACf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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 {
|
1
|
+
{"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type {\n AggregatePaginateModel,\n IndexDefinition,\n IndexOptions,\n Model,\n PaginateModel,\n SchemaOptions,\n} from 'mongoose'\nimport type {\n ArrayField,\n BlocksField,\n CheckboxField,\n CodeField,\n CollapsibleField,\n DateField,\n EmailField,\n Field,\n GroupField,\n JoinField,\n JSONField,\n NumberField,\n Payload,\n PayloadRequest,\n PointField,\n RadioField,\n RelationshipField,\n RichTextField,\n RowField,\n SanitizedConfig,\n SelectField,\n TabsField,\n TextareaField,\n TextField,\n UploadField,\n} from 'payload'\n\nimport type { BuildQueryArgs } from './queries/buildQuery.js'\n\nexport interface CollectionModel\n extends Model<any>,\n PaginateModel<any>,\n AggregatePaginateModel<any> {\n /** buildQuery is used to transform payload's where operator into what can be used by mongoose (e.g. id => _id) */\n buildQuery: (args: BuildQueryArgs) => Promise<Record<string, unknown>> // TODO: Delete this\n}\n\nexport interface AuthCollectionModel extends CollectionModel {\n resetPasswordExpiration: Date\n resetPasswordToken: string\n}\n\nexport type TypeOfIndex = {\n fields: IndexDefinition\n options?: IndexOptions\n}\n\nexport interface GlobalModel extends Model<Document> {\n buildQuery: (query: unknown, locale?: string) => Promise<Record<string, unknown>>\n}\n\nexport type BuildSchema<TSchema> = (args: {\n config: SanitizedConfig\n fields: Field[]\n options: BuildSchemaOptions\n}) => TSchema\n\nexport type BuildSchemaOptions = {\n allowIDField?: boolean\n disableUnique?: boolean\n draftsEnabled?: boolean\n indexSortableFields?: boolean\n options?: SchemaOptions\n}\n\nexport type FieldGenerator<TSchema, TField> = {\n config: SanitizedConfig\n field: TField\n options: BuildSchemaOptions\n schema: TSchema\n}\n\nexport type FieldGeneratorFunction<TSchema, TField extends Field> = (\n args: FieldGenerator<TSchema, TField>,\n) => void\n\n/**\n * Object mapping types to a schema based on TSchema\n */\nexport type FieldToSchemaMap<TSchema> = {\n array: FieldGeneratorFunction<TSchema, ArrayField>\n blocks: FieldGeneratorFunction<TSchema, BlocksField>\n checkbox: FieldGeneratorFunction<TSchema, CheckboxField>\n code: FieldGeneratorFunction<TSchema, CodeField>\n collapsible: FieldGeneratorFunction<TSchema, CollapsibleField>\n date: FieldGeneratorFunction<TSchema, DateField>\n email: FieldGeneratorFunction<TSchema, EmailField>\n group: FieldGeneratorFunction<TSchema, GroupField>\n join: FieldGeneratorFunction<TSchema, JoinField>\n json: FieldGeneratorFunction<TSchema, JSONField>\n number: FieldGeneratorFunction<TSchema, NumberField>\n point: FieldGeneratorFunction<TSchema, PointField>\n radio: FieldGeneratorFunction<TSchema, RadioField>\n relationship: FieldGeneratorFunction<TSchema, RelationshipField>\n richText: FieldGeneratorFunction<TSchema, RichTextField>\n row: FieldGeneratorFunction<TSchema, RowField>\n select: FieldGeneratorFunction<TSchema, SelectField>\n tabs: FieldGeneratorFunction<TSchema, TabsField>\n text: FieldGeneratorFunction<TSchema, TextField>\n textarea: FieldGeneratorFunction<TSchema, TextareaField>\n upload: FieldGeneratorFunction<TSchema, UploadField>\n}\n\nexport type MigrateUpArgs = { payload: Payload; req: PayloadRequest }\nexport type MigrateDownArgs = { payload: Payload; req: PayloadRequest }\n"],"names":[],"mappings":"AAiHA,WAAuE"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"updateGlobal.d.ts","sourceRoot":"","sources":["../src/updateGlobal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAkB,YAAY,EAAE,MAAM,SAAS,CAAA;
|
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"}
|
package/dist/updateGlobal.js
CHANGED
@@ -1,4 +1,5 @@
|
|
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;
|
@@ -8,9 +9,14 @@ export const updateGlobal = async function updateGlobal({ slug, data, req = {} }
|
|
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
|
-
},
|
19
|
+
}, sanitizedData, options);
|
14
20
|
result = JSON.parse(JSON.stringify(result));
|
15
21
|
// custom id type reset
|
16
22
|
result.id = result._id;
|
package/dist/updateGlobal.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/updateGlobal.ts"],"sourcesContent":["import type { PayloadRequest, UpdateGlobal } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport sanitizeInternalFields from './utilities/sanitizeInternalFields.js'\nimport { withSession } from './withSession.js'\n\nexport const updateGlobal: UpdateGlobal = async function updateGlobal(\n this: MongooseAdapter,\n { slug, data, req = {} as PayloadRequest },\n) {\n const Model = this.globals\n const options = {\n ...(await withSession(this, req)),\n lean: true,\n new: true,\n }\n\n let result\n result = await Model.findOneAndUpdate({ globalType: slug },
|
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
|
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,
|
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,6 +1,8 @@
|
|
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[
|
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
|
@@ -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
|
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
|
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"}
|
package/dist/updateOne.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"updateOne.d.ts","sourceRoot":"","sources":["../src/updateOne.ts"],"names":[],"mappings":"
|
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
1
|
import { handleError } from './utilities/handleError.js';
|
2
|
-
import sanitizeInternalFields from './utilities/sanitizeInternalFields.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,6 +10,7 @@ export const updateOne = async function updateOne({ id, collection, data, locale
|
|
9
10
|
} : whereArg;
|
10
11
|
const Model = this.collections[collection];
|
11
12
|
const options = {
|
13
|
+
...optionsArgs,
|
12
14
|
...await withSession(this, req),
|
13
15
|
lean: true,
|
14
16
|
new: true
|
@@ -19,8 +21,13 @@ 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,
|
30
|
+
result = await Model.findOneAndUpdate(query, sanitizedData, options);
|
24
31
|
} catch (error) {
|
25
32
|
handleError({
|
26
33
|
collection,
|