@payloadcms/db-mongodb 3.0.0-canary.c696728 → 3.0.0-canary.c96fa61
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/countGlobalVersions.d.ts +3 -0
- package/dist/countGlobalVersions.d.ts.map +1 -0
- package/dist/countGlobalVersions.js +33 -0
- package/dist/countGlobalVersions.js.map +1 -0
- package/dist/countVersions.d.ts +3 -0
- package/dist/countVersions.d.ts.map +1 -0
- package/dist/countVersions.js +33 -0
- package/dist/countVersions.js.map +1 -0
- package/dist/create.d.ts.map +1 -1
- package/dist/create.js +3 -0
- package/dist/create.js.map +1 -1
- package/dist/createMigration.d.ts.map +1 -1
- package/dist/createMigration.js +8 -6
- package/dist/createMigration.js.map +1 -1
- package/dist/createVersion.d.ts.map +1 -1
- package/dist/createVersion.js +18 -5
- package/dist/createVersion.js.map +1 -1
- package/dist/deleteOne.d.ts.map +1 -1
- package/dist/deleteOne.js +10 -2
- package/dist/deleteOne.js.map +1 -1
- package/dist/find.d.ts.map +1 -1
- package/dist/find.js +9 -2
- package/dist/find.js.map +1 -1
- package/dist/findGlobal.d.ts.map +1 -1
- package/dist/findGlobal.js +8 -2
- package/dist/findGlobal.js.map +1 -1
- package/dist/findGlobalVersions.d.ts.map +1 -1
- package/dist/findGlobalVersions.js +7 -1
- package/dist/findGlobalVersions.js.map +1 -1
- package/dist/findOne.d.ts.map +1 -1
- package/dist/findOne.js +9 -1
- package/dist/findOne.js.map +1 -1
- package/dist/findVersions.d.ts.map +1 -1
- package/dist/findVersions.js +8 -2
- package/dist/findVersions.js.map +1 -1
- package/dist/index.d.ts +5 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -4
- package/dist/index.js.map +1 -1
- package/dist/models/buildSchema.js +16 -1
- package/dist/models/buildSchema.js.map +1 -1
- package/dist/queries/buildSortParam.d.ts +2 -2
- package/dist/queries/buildSortParam.d.ts.map +1 -1
- package/dist/queries/buildSortParam.js +26 -17
- package/dist/queries/buildSortParam.js.map +1 -1
- package/dist/queries/sanitizeQueryValue.d.ts.map +1 -1
- package/dist/queries/sanitizeQueryValue.js +60 -48
- package/dist/queries/sanitizeQueryValue.js.map +1 -1
- package/dist/queryDrafts.d.ts.map +1 -1
- package/dist/queryDrafts.js +28 -6
- package/dist/queryDrafts.js.map +1 -1
- package/dist/types.d.ts +3 -1
- 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 +10 -3
- package/dist/updateGlobal.js.map +1 -1
- package/dist/updateGlobalVersion.d.ts +1 -1
- 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 +11 -3
- package/dist/updateOne.js.map +1 -1
- package/dist/updateVersion.d.ts.map +1 -1
- package/dist/updateVersion.js +10 -3
- 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 +15 -0
- package/dist/upsert.js.map +1 -0
- package/dist/utilities/buildJoinAggregation.d.ts +4 -1
- package/dist/utilities/buildJoinAggregation.d.ts.map +1 -1
- package/dist/utilities/buildJoinAggregation.js +23 -12
- package/dist/utilities/buildJoinAggregation.js.map +1 -1
- package/dist/utilities/buildProjectionFromSelect.d.ts +8 -0
- package/dist/utilities/buildProjectionFromSelect.d.ts.map +1 -0
- package/dist/utilities/buildProjectionFromSelect.js +171 -0
- package/dist/utilities/buildProjectionFromSelect.js.map +1 -0
- package/dist/utilities/handleError.js +2 -2
- package/dist/utilities/handleError.js.map +1 -1
- package/dist/utilities/sanitizeRelationshipIDs.d.ts.map +1 -1
- package/dist/utilities/sanitizeRelationshipIDs.js +6 -2
- package/dist/utilities/sanitizeRelationshipIDs.js.map +1 -1
- package/package.json +4 -4
@@ -1,6 +1,53 @@
|
|
1
1
|
import ObjectIdImport from 'bson-objectid';
|
2
2
|
import mongoose from 'mongoose';
|
3
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
|
+
};
|
4
51
|
const ObjectId = ObjectIdImport.default || ObjectIdImport;
|
5
52
|
export const sanitizeQueryValue = ({ field, hasCustomID, operator, path, val })=>{
|
6
53
|
let formattedValue = val;
|
@@ -35,7 +82,10 @@ export const sanitizeQueryValue = ({ field, hasCustomID, operator, path, val })=
|
|
35
82
|
};
|
36
83
|
}
|
37
84
|
}
|
38
|
-
} else if (Array.isArray(val)) {
|
85
|
+
} else if (Array.isArray(val) || typeof val === 'string' && val.split(',').length > 1) {
|
86
|
+
if (typeof val === 'string') {
|
87
|
+
formattedValue = createArrayFromCommaDelineated(val);
|
88
|
+
}
|
39
89
|
formattedValue = formattedValue.reduce((formattedValues, inVal)=>{
|
40
90
|
const newValues = [
|
41
91
|
inVal
|
@@ -77,8 +127,14 @@ export const sanitizeQueryValue = ({ field, hasCustomID, operator, path, val })=
|
|
77
127
|
formattedValue = formattedValue.map((arrayVal)=>parseFloat(arrayVal));
|
78
128
|
}
|
79
129
|
}
|
80
|
-
if (field.type === 'number'
|
81
|
-
formattedValue
|
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
|
+
}
|
82
138
|
}
|
83
139
|
if (field.type === 'date' && typeof val === 'string' && operator !== 'exists') {
|
84
140
|
formattedValue = new Date(val);
|
@@ -190,51 +246,7 @@ export const sanitizeQueryValue = ({ field, hasCustomID, operator, path, val })=
|
|
190
246
|
}
|
191
247
|
if (operator === 'exists') {
|
192
248
|
formattedValue = formattedValue === 'true' || formattedValue === true;
|
193
|
-
|
194
|
-
return {
|
195
|
-
rawQuery: {
|
196
|
-
$and: [
|
197
|
-
{
|
198
|
-
[path]: {
|
199
|
-
$exists: true
|
200
|
-
}
|
201
|
-
},
|
202
|
-
{
|
203
|
-
[path]: {
|
204
|
-
$ne: null
|
205
|
-
}
|
206
|
-
},
|
207
|
-
{
|
208
|
-
[path]: {
|
209
|
-
$ne: ''
|
210
|
-
}
|
211
|
-
}
|
212
|
-
]
|
213
|
-
}
|
214
|
-
};
|
215
|
-
} else {
|
216
|
-
return {
|
217
|
-
rawQuery: {
|
218
|
-
$or: [
|
219
|
-
{
|
220
|
-
[path]: {
|
221
|
-
$exists: false
|
222
|
-
}
|
223
|
-
},
|
224
|
-
{
|
225
|
-
[path]: {
|
226
|
-
$eq: null
|
227
|
-
}
|
228
|
-
},
|
229
|
-
{
|
230
|
-
[path]: {
|
231
|
-
$eq: ''
|
232
|
-
}
|
233
|
-
}
|
234
|
-
]
|
235
|
-
}
|
236
|
-
};
|
237
|
-
}
|
249
|
+
return buildExistsQuery(formattedValue, path);
|
238
250
|
}
|
239
251
|
}
|
240
252
|
if ((path === '_id' || path === 'parent') && operator === 'like' && formattedValue.length === 24 && !hasCustomID) {
|
@@ -1 +1 @@
|
|
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 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' && 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 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 if (formattedValue) {\n return {\n rawQuery: {\n $and: [\n { [path]: { $exists: true } },\n { [path]: { $ne: null } },\n { [path]: { $ne: '' } },\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 }\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","ObjectId","default","sanitizeQueryValue","field","hasCustomID","operator","path","val","formattedValue","formattedOperator","split","length","isValid","Types","undefined","includes","map","id","type","parsedNumber","parseFloat","Number","isNaN","Array","isArray","reduce","formattedValues","inVal","newValues","push","toLowerCase","arrayVal","Date","parse","value","relationTo","rawQuery","$and","$eq","lng","lat","maxDistance","minDistance","$geometry","coordinates","$maxDistance","$minDistance","$options","$regex","replace","$exists","$ne","$or"],"mappings":"AAEA,OAAOA,oBAAoB,gBAAe;AAC1C,OAAOC,cAAc,WAAU;AAC/B,SAASC,8BAA8B,QAAQ,UAAS;AAUxD,MAAMC,WAAYH,eAAeI,OAAO,IACtCJ;AACF,OAAO,MAAMK,qBAAqB,CAAC,EACjCC,KAAK,EACLC,WAAW,EACXC,QAAQ,EACRC,IAAI,EACJC,GAAG,EACoB;IAKvB,IAAIC,iBAAiBD;IACrB,IAAIE,oBAAoBJ;IAExB,yBAAyB;IACzB,IAAIC,SAAS,OAAO;QAClB,IAAI,OAAOC,QAAQ,YAAYA,IAAIG,KAAK,CAAC,KAAKC,MAAM,KAAK,GAAG;YAC1D,IAAI,CAACP,aAAa;gBAChB,MAAMQ,UAAUd,SAASe,KAAK,CAACb,QAAQ,CAACY,OAAO,CAACL;gBAEhD,IAAI,CAACK,SAAS;oBACZ,OAAO;wBAAEP,UAAUI;wBAAmBF,KAAKO;oBAAU;gBACvD,OAAO;oBACL,IAAI;wBAAC;wBAAM;qBAAS,CAACC,QAAQ,CAACV,WAAW;wBACvCG,iBAAiBT,+BAA+BS,gBAAgBQ,GAAG,CAAC,CAACC,KACnEjB,SAASiB;oBAEb,OAAO;wBACLT,iBAAiBR,SAASO;oBAC5B;gBACF;YACF;YAEA,IAAIJ,MAAMe,IAAI,KAAK,UAAU;gBAC3B,MAAMC,eAAeC,WAAWb;gBAEhC,IAA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EA,OAAO;QAAEjC,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;IACxC,IAAID,gBAAgB;QAClB,OAAO;YACLE,UAAU;gBACRC,MAAM;oBACJ;wBAAE,CAACF,KAAK,EAAE;4BAAEG,SAAS;wBAAK;oBAAE;oBAC5B;wBAAE,CAACH,KAAK,EAAE;4BAAEI,KAAK;wBAAK;oBAAE;oBACxB;wBAAE,CAACJ,KAAK,EAAE;4BAAEI,KAAK;wBAAG;oBAAE;iBACvB;YACH;QACF;IACF,OAAO;QACL,OAAO;YACLH,UAAU;gBACRI,KAAK;oBACH;wBAAE,CAACL,KAAK,EAAE;4BAAEG,SAAS;wBAAM;oBAAE;oBAC7B;wBAAE,CAACH,KAAK,EAAE;4BAAEM,KAAK;wBAAK;oBAAE;oBACxB;wBAAE,CAACN,KAAK,EAAE;4BAAEM,KAAK;wBAAG;oBAAE;iBACvB;YACH;QACF;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,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 +1 @@
|
|
1
|
-
{"version":3,"file":"queryDrafts.d.ts","sourceRoot":"","sources":["../src/queryDrafts.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAkB,WAAW,EAAE,MAAM,SAAS,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"}
|
package/dist/queryDrafts.js
CHANGED
@@ -1,8 +1,10 @@
|
|
1
|
-
import { combineQueries, flattenWhereToOperators } from 'payload';
|
1
|
+
import { buildVersionCollectionFields, combineQueries, flattenWhereToOperators } from 'payload';
|
2
2
|
import { buildSortParam } from './queries/buildSortParam.js';
|
3
|
+
import { buildJoinAggregation } from './utilities/buildJoinAggregation.js';
|
4
|
+
import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
|
3
5
|
import { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js';
|
4
6
|
import { withSession } from './withSession.js';
|
5
|
-
export const queryDrafts = async function queryDrafts({ collection, limit, locale, page, pagination, req = {}, sort: sortArg, where }) {
|
7
|
+
export const queryDrafts = async function queryDrafts({ collection, joins, limit, locale, page, pagination, req = {}, select, sort: sortArg, where }) {
|
6
8
|
const VersionModel = this.versions[collection];
|
7
9
|
const collectionConfig = this.payload.collections[collection].config;
|
8
10
|
const options = await withSession(this, req);
|
@@ -31,6 +33,11 @@ export const queryDrafts = async function queryDrafts({ collection, limit, local
|
|
31
33
|
payload: this.payload,
|
32
34
|
where: combinedWhere
|
33
35
|
});
|
36
|
+
const projection = buildProjectionFromSelect({
|
37
|
+
adapter: this,
|
38
|
+
fields: buildVersionCollectionFields(this.payload.config, collectionConfig),
|
39
|
+
select
|
40
|
+
});
|
34
41
|
// useEstimatedCount is faster, but not accurate, as it ignores any filters. It is thus set to true if there are no filters.
|
35
42
|
const useEstimatedCount = hasNearConstraint || !versionQuery || Object.keys(versionQuery).length === 0;
|
36
43
|
const paginationOptions = {
|
@@ -40,6 +47,7 @@ export const queryDrafts = async function queryDrafts({ collection, limit, local
|
|
40
47
|
options,
|
41
48
|
page,
|
42
49
|
pagination,
|
50
|
+
projection,
|
43
51
|
sort,
|
44
52
|
useEstimatedCount
|
45
53
|
};
|
@@ -68,7 +76,23 @@ export const queryDrafts = async function queryDrafts({ collection, limit, local
|
|
68
76
|
// limit must also be set here, it's ignored when pagination is false
|
69
77
|
paginationOptions.options.limit = limit;
|
70
78
|
}
|
71
|
-
|
79
|
+
let result;
|
80
|
+
const aggregate = await buildJoinAggregation({
|
81
|
+
adapter: this,
|
82
|
+
collection,
|
83
|
+
collectionConfig,
|
84
|
+
joins,
|
85
|
+
locale,
|
86
|
+
projection,
|
87
|
+
query: versionQuery,
|
88
|
+
versions: true
|
89
|
+
});
|
90
|
+
// build join aggregation
|
91
|
+
if (aggregate) {
|
92
|
+
result = await VersionModel.aggregatePaginate(VersionModel.aggregate(aggregate), paginationOptions);
|
93
|
+
} else {
|
94
|
+
result = await VersionModel.paginate(versionQuery, paginationOptions);
|
95
|
+
}
|
72
96
|
const docs = JSON.parse(JSON.stringify(result.docs));
|
73
97
|
return {
|
74
98
|
...result,
|
@@ -76,9 +100,7 @@ export const queryDrafts = async function queryDrafts({ collection, limit, local
|
|
76
100
|
doc = {
|
77
101
|
_id: doc.parent,
|
78
102
|
id: doc.parent,
|
79
|
-
...doc.version
|
80
|
-
createdAt: doc.createdAt,
|
81
|
-
updatedAt: doc.updatedAt
|
103
|
+
...doc.version
|
82
104
|
};
|
83
105
|
return sanitizeInternalFields(doc);
|
84
106
|
})
|
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 {
|
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,CAA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IndexOptions, Model, PaginateModel, SchemaOptions } from 'mongoose';
|
2
|
-
import type { ArrayField, BlocksField, CheckboxField, CodeField, CollapsibleField, DateField, EmailField, Field, GroupField, JoinField, JSONField, NumberField, Payload, PointField, RadioField, RelationshipField, RichTextField, RowField, SanitizedConfig, SelectField, TabsField, TextareaField, TextField, UploadField } from 'payload';
|
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
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) */
|
@@ -63,8 +63,10 @@ export type FieldToSchemaMap<TSchema> = {
|
|
63
63
|
};
|
64
64
|
export type MigrateUpArgs = {
|
65
65
|
payload: Payload;
|
66
|
+
req: PayloadRequest;
|
66
67
|
};
|
67
68
|
export type MigrateDownArgs = {
|
68
69
|
payload: Payload;
|
70
|
+
req: PayloadRequest;
|
69
71
|
};
|
70
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,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,UAAU,EACV,UAAU,EACV,i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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 {\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 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 }\nexport type MigrateDownArgs = { payload: Payload }\n"],"names":[],"mappings":"
|
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;AAS3D,eAAO,MAAM,YAAY,EAAE,YA+B1B,CAAA"}
|
package/dist/updateGlobal.js
CHANGED
@@ -1,18 +1,25 @@
|
|
1
|
+
import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
|
1
2
|
import { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js';
|
2
3
|
import { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.js';
|
3
4
|
import { withSession } from './withSession.js';
|
4
|
-
export const updateGlobal = async function updateGlobal({ slug, data, req = {} }) {
|
5
|
+
export const updateGlobal = async function updateGlobal({ slug, data, req = {}, select }) {
|
5
6
|
const Model = this.globals;
|
7
|
+
const fields = this.payload.config.globals.find((global)=>global.slug === slug).fields;
|
6
8
|
const options = {
|
7
9
|
...await withSession(this, req),
|
8
10
|
lean: true,
|
9
|
-
new: true
|
11
|
+
new: true,
|
12
|
+
projection: buildProjectionFromSelect({
|
13
|
+
adapter: this,
|
14
|
+
fields,
|
15
|
+
select
|
16
|
+
})
|
10
17
|
};
|
11
18
|
let result;
|
12
19
|
const sanitizedData = sanitizeRelationshipIDs({
|
13
20
|
config: this.payload.config,
|
14
21
|
data,
|
15
|
-
fields
|
22
|
+
fields
|
16
23
|
});
|
17
24
|
result = await Model.findOneAndUpdate({
|
18
25
|
globalType: slug
|
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 { 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
|
1
|
+
{"version":3,"sources":["../src/updateGlobal.ts"],"sourcesContent":["import type { PayloadRequest, UpdateGlobal } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js'\nimport { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.js'\nimport { withSession } from './withSession.js'\n\nexport const updateGlobal: UpdateGlobal = async function updateGlobal(\n this: MongooseAdapter,\n { slug, data, req = {} as PayloadRequest, select },\n) {\n const Model = this.globals\n const fields = this.payload.config.globals.find((global) => global.slug === slug).fields\n\n const options = {\n ...(await withSession(this, req)),\n lean: true,\n new: true,\n projection: buildProjectionFromSelect({ adapter: this, fields, select }),\n }\n\n let result\n\n const sanitizedData = sanitizeRelationshipIDs({\n config: this.payload.config,\n data,\n fields,\n })\n\n result = await Model.findOneAndUpdate({ globalType: slug }, sanitizedData, options)\n\n result = JSON.parse(JSON.stringify(result))\n\n // custom id type reset\n result.id = result._id\n result = sanitizeInternalFields(result)\n\n return result\n}\n"],"names":["buildProjectionFromSelect","sanitizeInternalFields","sanitizeRelationshipIDs","withSession","updateGlobal","slug","data","req","select","Model","globals","fields","payload","config","find","global","options","lean","new","projection","adapter","result","sanitizedData","findOneAndUpdate","globalType","JSON","parse","stringify","id","_id"],"mappings":"AAIA,SAASA,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,sBAAsB,QAAQ,wCAAuC;AAC9E,SAASC,uBAAuB,QAAQ,yCAAwC;AAChF,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,eAA6B,eAAeA,aAEvD,EAAEC,IAAI,EAAEC,IAAI,EAAEC,MAAM,CAAC,CAAmB,EAAEC,MAAM,EAAE;IAElD,MAAMC,QAAQ,IAAI,CAACC,OAAO;IAC1B,MAAMC,SAAS,IAAI,CAACC,OAAO,CAACC,MAAM,CAACH,OAAO,CAACI,IAAI,CAAC,CAACC,SAAWA,OAAOV,IAAI,KAAKA,MAAMM,MAAM;IAExF,MAAMK,UAAU;QACd,GAAI,MAAMb,YAAY,IAAI,EAAEI,IAAI;QAChCU,MAAM;QACNC,KAAK;QACLC,YAAYnB,0BAA0B;YAAEoB,SAAS,IAAI;YAAET;YAAQH;QAAO;IACxE;IAEA,IAAIa;IAEJ,MAAMC,gBAAgBpB,wBAAwB;QAC5CW,QAAQ,IAAI,CAACD,OAAO,CAACC,MAAM;QAC3BP;QACAK;IACF;IAEAU,SAAS,MAAMZ,MAAMc,gBAAgB,CAAC;QAAEC,YAAYnB;IAAK,GAAGiB,eAAeN;IAE3EK,SAASI,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACN;IAEnC,uBAAuB;IACvBA,OAAOO,EAAE,GAAGP,OAAOQ,GAAG;IACtBR,SAASpB,uBAAuBoB;IAEhC,OAAOA;AACT,EAAC"}
|
@@ -1,4 +1,4 @@
|
|
1
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: globalSlug, locale, req, versionData, where, }: UpdateGlobalVersionArgs<T>): Promise<any>;
|
3
|
+
export declare function updateGlobalVersion<T extends TypeWithID>(this: MongooseAdapter, { id, global: globalSlug, locale, req, select, versionData, where, }: UpdateGlobalVersionArgs<T>): Promise<any>;
|
4
4
|
//# sourceMappingURL=updateGlobalVersion.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"updateGlobalVersion.d.ts","sourceRoot":"","sources":["../src/updateGlobalVersion.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,UAAU,EACf,KAAK,uBAAuB,EAC7B,MAAM,SAAS,CAAA;AAEhB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;
|
1
|
+
{"version":3,"file":"updateGlobalVersion.d.ts","sourceRoot":"","sources":["../src/updateGlobalVersion.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,UAAU,EACf,KAAK,uBAAuB,EAC7B,MAAM,SAAS,CAAA;AAEhB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAMjD,wBAAsB,mBAAmB,CAAC,CAAC,SAAS,UAAU,EAC5D,IAAI,EAAE,eAAe,EACrB,EACE,EAAE,EACF,MAAM,EAAE,UAAU,EAClB,MAAM,EACN,GAA0B,EAC1B,MAAM,EACN,WAAW,EACX,KAAK,GACN,EAAE,uBAAuB,CAAC,CAAC,CAAC,gBAwC9B"}
|
@@ -1,17 +1,24 @@
|
|
1
1
|
import { buildVersionGlobalFields } from 'payload';
|
2
|
+
import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
|
2
3
|
import { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.js';
|
3
4
|
import { withSession } from './withSession.js';
|
4
|
-
export async function updateGlobalVersion({ id, global: globalSlug, locale, req = {}, versionData, where }) {
|
5
|
+
export async function updateGlobalVersion({ id, global: globalSlug, locale, req = {}, select, versionData, where }) {
|
5
6
|
const VersionModel = this.versions[globalSlug];
|
6
7
|
const whereToUse = where || {
|
7
8
|
id: {
|
8
9
|
equals: id
|
9
10
|
}
|
10
11
|
};
|
12
|
+
const fields = buildVersionGlobalFields(this.payload.config, this.payload.config.globals.find((global)=>global.slug === globalSlug));
|
11
13
|
const options = {
|
12
14
|
...await withSession(this, req),
|
13
15
|
lean: true,
|
14
|
-
new: true
|
16
|
+
new: true,
|
17
|
+
projection: buildProjectionFromSelect({
|
18
|
+
adapter: this,
|
19
|
+
fields,
|
20
|
+
select
|
21
|
+
})
|
15
22
|
};
|
16
23
|
const query = await VersionModel.buildQuery({
|
17
24
|
locale,
|
@@ -21,7 +28,7 @@ export async function updateGlobalVersion({ id, global: globalSlug, locale, req
|
|
21
28
|
const sanitizedData = sanitizeRelationshipIDs({
|
22
29
|
config: this.payload.config,
|
23
30
|
data: versionData,
|
24
|
-
fields
|
31
|
+
fields
|
25
32
|
});
|
26
33
|
const doc = await VersionModel.findOneAndUpdate(query, sanitizedData, options);
|
27
34
|
const result = JSON.parse(JSON.stringify(doc));
|
@@ -1 +1 @@
|
|
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
|
1
|
+
{"version":3,"sources":["../src/updateGlobalVersion.ts"],"sourcesContent":["import {\n buildVersionGlobalFields,\n type PayloadRequest,\n type TypeWithID,\n type UpdateGlobalVersionArgs,\n} from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.js'\nimport { withSession } from './withSession.js'\n\nexport async function updateGlobalVersion<T extends TypeWithID>(\n this: MongooseAdapter,\n {\n id,\n global: globalSlug,\n locale,\n req = {} as PayloadRequest,\n select,\n versionData,\n where,\n }: UpdateGlobalVersionArgs<T>,\n) {\n const VersionModel = this.versions[globalSlug]\n const whereToUse = where || { id: { equals: id } }\n const fields = buildVersionGlobalFields(\n this.payload.config,\n this.payload.config.globals.find((global) => global.slug === globalSlug),\n )\n\n const options = {\n ...(await withSession(this, req)),\n lean: true,\n new: true,\n projection: buildProjectionFromSelect({ adapter: this, fields, select }),\n }\n\n const query = await VersionModel.buildQuery({\n locale,\n payload: this.payload,\n where: whereToUse,\n })\n\n const sanitizedData = sanitizeRelationshipIDs({\n config: this.payload.config,\n data: versionData,\n fields,\n })\n\n const doc = await VersionModel.findOneAndUpdate(query, sanitizedData, options)\n\n const result = JSON.parse(JSON.stringify(doc))\n\n const verificationToken = doc._verificationToken\n\n // custom id type reset\n result.id = result._id\n if (verificationToken) {\n result._verificationToken = verificationToken\n }\n return result\n}\n"],"names":["buildVersionGlobalFields","buildProjectionFromSelect","sanitizeRelationshipIDs","withSession","updateGlobalVersion","id","global","globalSlug","locale","req","select","versionData","where","VersionModel","versions","whereToUse","equals","fields","payload","config","globals","find","slug","options","lean","new","projection","adapter","query","buildQuery","sanitizedData","data","doc","findOneAndUpdate","result","JSON","parse","stringify","verificationToken","_verificationToken","_id"],"mappings":"AAAA,SACEA,wBAAwB,QAInB,UAAS;AAIhB,SAASC,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,uBAAuB,QAAQ,yCAAwC;AAChF,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,eAAeC,oBAEpB,EACEC,EAAE,EACFC,QAAQC,UAAU,EAClBC,MAAM,EACNC,MAAM,CAAC,CAAmB,EAC1BC,MAAM,EACNC,WAAW,EACXC,KAAK,EACsB;IAE7B,MAAMC,eAAe,IAAI,CAACC,QAAQ,CAACP,WAAW;IAC9C,MAAMQ,aAAaH,SAAS;QAAEP,IAAI;YAAEW,QAAQX;QAAG;IAAE;IACjD,MAAMY,SAASjB,yBACb,IAAI,CAACkB,OAAO,CAACC,MAAM,EACnB,IAAI,CAACD,OAAO,CAACC,MAAM,CAACC,OAAO,CAACC,IAAI,CAAC,CAACf,SAAWA,OAAOgB,IAAI,KAAKf;IAG/D,MAAMgB,UAAU;QACd,GAAI,MAAMpB,YAAY,IAAI,EAAEM,IAAI;QAChCe,MAAM;QACNC,KAAK;QACLC,YAAYzB,0BAA0B;YAAE0B,SAAS,IAAI;YAAEV;YAAQP;QAAO;IACxE;IAEA,MAAMkB,QAAQ,MAAMf,aAAagB,UAAU,CAAC;QAC1CrB;QACAU,SAAS,IAAI,CAACA,OAAO;QACrBN,OAAOG;IACT;IAEA,MAAMe,gBAAgB5B,wBAAwB;QAC5CiB,QAAQ,IAAI,CAACD,OAAO,CAACC,MAAM;QAC3BY,MAAMpB;QACNM;IACF;IAEA,MAAMe,MAAM,MAAMnB,aAAaoB,gBAAgB,CAACL,OAAOE,eAAeP;IAEtE,MAAMW,SAASC,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACL;IAEzC,MAAMM,oBAAoBN,IAAIO,kBAAkB;IAEhD,uBAAuB;IACvBL,OAAO7B,EAAE,GAAG6B,OAAOM,GAAG;IACtB,IAAIF,mBAAmB;QACrBJ,OAAOK,kBAAkB,GAAGD;IAC9B;IACA,OAAOJ;AACT"}
|
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;AAUxD,eAAO,MAAM,SAAS,EAAE,SAiDvB,CAAA"}
|
package/dist/updateOne.js
CHANGED
@@ -1,18 +1,26 @@
|
|
1
|
+
import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
|
1
2
|
import { handleError } from './utilities/handleError.js';
|
2
3
|
import { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js';
|
3
4
|
import { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.js';
|
4
5
|
import { withSession } from './withSession.js';
|
5
|
-
export const updateOne = async function updateOne({ id, collection, data, locale, req = {}, where: whereArg }) {
|
6
|
+
export const updateOne = async function updateOne({ id, collection, data, locale, options: optionsArgs = {}, req = {}, select, where: whereArg }) {
|
6
7
|
const where = id ? {
|
7
8
|
id: {
|
8
9
|
equals: id
|
9
10
|
}
|
10
11
|
} : whereArg;
|
11
12
|
const Model = this.collections[collection];
|
13
|
+
const fields = this.payload.collections[collection].config.fields;
|
12
14
|
const options = {
|
15
|
+
...optionsArgs,
|
13
16
|
...await withSession(this, req),
|
14
17
|
lean: true,
|
15
|
-
new: true
|
18
|
+
new: true,
|
19
|
+
projection: buildProjectionFromSelect({
|
20
|
+
adapter: this,
|
21
|
+
fields,
|
22
|
+
select
|
23
|
+
})
|
16
24
|
};
|
17
25
|
const query = await Model.buildQuery({
|
18
26
|
locale,
|
@@ -23,7 +31,7 @@ export const updateOne = async function updateOne({ id, collection, data, locale
|
|
23
31
|
const sanitizedData = sanitizeRelationshipIDs({
|
24
32
|
config: this.payload.config,
|
25
33
|
data,
|
26
|
-
fields
|
34
|
+
fields
|
27
35
|
});
|
28
36
|
try {
|
29
37
|
result = await Model.findOneAndUpdate(query, sanitizedData, options);
|
package/dist/updateOne.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/updateOne.ts"],"sourcesContent":["import type { PayloadRequest, UpdateOne } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { handleError } from './utilities/handleError.js'\nimport { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js'\nimport { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.js'\nimport { withSession } from './withSession.js'\n\nexport const updateOne: UpdateOne = async function updateOne(\n this: MongooseAdapter,\n {
|
1
|
+
{"version":3,"sources":["../src/updateOne.ts"],"sourcesContent":["import type { QueryOptions } from 'mongoose'\nimport type { PayloadRequest, UpdateOne } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { handleError } from './utilities/handleError.js'\nimport { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js'\nimport { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.js'\nimport { withSession } from './withSession.js'\n\nexport const updateOne: UpdateOne = async function updateOne(\n this: MongooseAdapter,\n {\n id,\n collection,\n data,\n locale,\n options: optionsArgs = {},\n req = {} as PayloadRequest,\n select,\n where: whereArg,\n },\n) {\n const where = id ? { id: { equals: id } } : whereArg\n const Model = this.collections[collection]\n const fields = this.payload.collections[collection].config.fields\n const options: QueryOptions = {\n ...optionsArgs,\n ...(await withSession(this, req)),\n lean: true,\n new: true,\n projection: buildProjectionFromSelect({ adapter: this, fields, select }),\n }\n\n const query = await Model.buildQuery({\n locale,\n payload: this.payload,\n where,\n })\n\n let result\n\n const sanitizedData = sanitizeRelationshipIDs({\n config: this.payload.config,\n data,\n fields,\n })\n\n try {\n result = await Model.findOneAndUpdate(query, sanitizedData, options)\n } catch (error) {\n handleError({ collection, error, req })\n }\n\n result = JSON.parse(JSON.stringify(result))\n result.id = result._id\n result = sanitizeInternalFields(result)\n\n return result\n}\n"],"names":["buildProjectionFromSelect","handleError","sanitizeInternalFields","sanitizeRelationshipIDs","withSession","updateOne","id","collection","data","locale","options","optionsArgs","req","select","where","whereArg","equals","Model","collections","fields","payload","config","lean","new","projection","adapter","query","buildQuery","result","sanitizedData","findOneAndUpdate","error","JSON","parse","stringify","_id"],"mappings":"AAKA,SAASA,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,WAAW,QAAQ,6BAA4B;AACxD,SAASC,sBAAsB,QAAQ,wCAAuC;AAC9E,SAASC,uBAAuB,QAAQ,yCAAwC;AAChF,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,YAAuB,eAAeA,UAEjD,EACEC,EAAE,EACFC,UAAU,EACVC,IAAI,EACJC,MAAM,EACNC,SAASC,cAAc,CAAC,CAAC,EACzBC,MAAM,CAAC,CAAmB,EAC1BC,MAAM,EACNC,OAAOC,QAAQ,EAChB;IAED,MAAMD,QAAQR,KAAK;QAAEA,IAAI;YAAEU,QAAQV;QAAG;IAAE,IAAIS;IAC5C,MAAME,QAAQ,IAAI,CAACC,WAAW,CAACX,WAAW;IAC1C,MAAMY,SAAS,IAAI,CAACC,OAAO,CAACF,WAAW,CAACX,WAAW,CAACc,MAAM,CAACF,MAAM;IACjE,MAAMT,UAAwB;QAC5B,GAAGC,WAAW;QACd,GAAI,MAAMP,YAAY,IAAI,EAAEQ,IAAI;QAChCU,MAAM;QACNC,KAAK;QACLC,YAAYxB,0BAA0B;YAAEyB,SAAS,IAAI;YAAEN;YAAQN;QAAO;IACxE;IAEA,MAAMa,QAAQ,MAAMT,MAAMU,UAAU,CAAC;QACnClB;QACAW,SAAS,IAAI,CAACA,OAAO;QACrBN;IACF;IAEA,IAAIc;IAEJ,MAAMC,gBAAgB1B,wBAAwB;QAC5CkB,QAAQ,IAAI,CAACD,OAAO,CAACC,MAAM;QAC3Bb;QACAW;IACF;IAEA,IAAI;QACFS,SAAS,MAAMX,MAAMa,gBAAgB,CAACJ,OAAOG,eAAenB;IAC9D,EAAE,OAAOqB,OAAO;QACd9B,YAAY;YAAEM;YAAYwB;YAAOnB;QAAI;IACvC;IAEAgB,SAASI,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACN;IACnCA,OAAOtB,EAAE,GAAGsB,OAAOO,GAAG;IACtBP,SAAS1B,uBAAuB0B;IAEhC,OAAOA;AACT,EAAC"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"updateVersion.d.ts","sourceRoot":"","sources":["../src/updateVersion.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqD,KAAK,aAAa,EAAE,MAAM,SAAS,CAAA;
|
1
|
+
{"version":3,"file":"updateVersion.d.ts","sourceRoot":"","sources":["../src/updateVersion.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqD,KAAK,aAAa,EAAE,MAAM,SAAS,CAAA;AAQ/F,eAAO,MAAM,aAAa,EAAE,aA0C3B,CAAA"}
|
package/dist/updateVersion.js
CHANGED
@@ -1,17 +1,24 @@
|
|
1
1
|
import { buildVersionCollectionFields } from 'payload';
|
2
|
+
import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
|
2
3
|
import { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.js';
|
3
4
|
import { withSession } from './withSession.js';
|
4
|
-
export const updateVersion = async function updateVersion({ id, collection, locale, req = {}, versionData, where }) {
|
5
|
+
export const updateVersion = async function updateVersion({ id, collection, locale, req = {}, select, versionData, where }) {
|
5
6
|
const VersionModel = this.versions[collection];
|
6
7
|
const whereToUse = where || {
|
7
8
|
id: {
|
8
9
|
equals: id
|
9
10
|
}
|
10
11
|
};
|
12
|
+
const fields = buildVersionCollectionFields(this.payload.config, this.payload.collections[collection].config);
|
11
13
|
const options = {
|
12
14
|
...await withSession(this, req),
|
13
15
|
lean: true,
|
14
|
-
new: true
|
16
|
+
new: true,
|
17
|
+
projection: buildProjectionFromSelect({
|
18
|
+
adapter: this,
|
19
|
+
fields,
|
20
|
+
select
|
21
|
+
})
|
15
22
|
};
|
16
23
|
const query = await VersionModel.buildQuery({
|
17
24
|
locale,
|
@@ -21,7 +28,7 @@ export const updateVersion = async function updateVersion({ id, collection, loca
|
|
21
28
|
const sanitizedData = sanitizeRelationshipIDs({
|
22
29
|
config: this.payload.config,
|
23
30
|
data: versionData,
|
24
|
-
fields
|
31
|
+
fields
|
25
32
|
});
|
26
33
|
const doc = await VersionModel.findOneAndUpdate(query, sanitizedData, options);
|
27
34
|
const result = JSON.parse(JSON.stringify(doc));
|