@payloadcms/db-mongodb 3.9.0 → 3.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/count.d.ts.map +1 -1
- package/dist/count.js +20 -22
- package/dist/count.js.map +1 -1
- package/dist/countGlobalVersions.d.ts.map +1 -1
- package/dist/countGlobalVersions.js +20 -22
- package/dist/countGlobalVersions.js.map +1 -1
- package/dist/countVersions.d.ts.map +1 -1
- package/dist/countVersions.js +20 -22
- package/dist/countVersions.js.map +1 -1
- package/dist/create.d.ts.map +1 -1
- package/dist/create.js +23 -24
- package/dist/create.js.map +1 -1
- package/dist/createGlobal.d.ts.map +1 -1
- package/dist/createGlobal.js +22 -20
- package/dist/createGlobal.js.map +1 -1
- package/dist/createGlobalVersion.d.ts.map +1 -1
- package/dist/createGlobalVersion.js +36 -31
- package/dist/createGlobalVersion.js.map +1 -1
- package/dist/createVersion.d.ts.map +1 -1
- package/dist/createVersion.js +37 -32
- package/dist/createVersion.js.map +1 -1
- package/dist/deleteMany.d.ts.map +1 -1
- package/dist/deleteMany.js +7 -7
- package/dist/deleteMany.js.map +1 -1
- package/dist/deleteOne.d.ts.map +1 -1
- package/dist/deleteOne.js +18 -14
- package/dist/deleteOne.js.map +1 -1
- package/dist/deleteVersions.d.ts.map +1 -1
- package/dist/deleteVersions.js +7 -7
- package/dist/deleteVersions.js.map +1 -1
- package/dist/find.d.ts.map +1 -1
- package/dist/find.js +41 -74
- package/dist/find.js.map +1 -1
- package/dist/findGlobal.d.ts.map +1 -1
- package/dist/findGlobal.js +20 -19
- package/dist/findGlobal.js.map +1 -1
- package/dist/findGlobalVersions.d.ts.map +1 -1
- package/dist/findGlobalVersions.js +34 -63
- package/dist/findGlobalVersions.js.map +1 -1
- package/dist/findOne.d.ts.map +1 -1
- package/dist/findOne.js +33 -21
- package/dist/findOne.js.map +1 -1
- package/dist/findVersions.d.ts.map +1 -1
- package/dist/findVersions.js +34 -62
- package/dist/findVersions.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/migrateFresh.d.ts.map +1 -1
- package/dist/migrateFresh.js.map +1 -1
- package/dist/predefinedMigrations/migrateRelationshipsV2_V3.d.ts.map +1 -1
- package/dist/predefinedMigrations/migrateRelationshipsV2_V3.js +20 -16
- package/dist/predefinedMigrations/migrateRelationshipsV2_V3.js.map +1 -1
- package/dist/predefinedMigrations/migrateVersionsV1_V2.js +4 -4
- package/dist/predefinedMigrations/migrateVersionsV1_V2.js.map +1 -1
- package/dist/queries/buildAndOrConditions.d.ts +3 -1
- package/dist/queries/buildAndOrConditions.d.ts.map +1 -1
- package/dist/queries/buildAndOrConditions.js +2 -1
- package/dist/queries/buildAndOrConditions.js.map +1 -1
- package/dist/queries/buildQuery.d.ts +2 -0
- package/dist/queries/buildQuery.d.ts.map +1 -1
- package/dist/queries/buildQuery.js +2 -6
- package/dist/queries/buildQuery.js.map +1 -1
- package/dist/queries/buildSearchParams.d.ts +3 -1
- package/dist/queries/buildSearchParams.d.ts.map +1 -1
- package/dist/queries/buildSearchParams.js +15 -10
- package/dist/queries/buildSearchParams.js.map +1 -1
- package/dist/queries/buildSortParam.d.ts +1 -7
- package/dist/queries/buildSortParam.d.ts.map +1 -1
- package/dist/queries/buildSortParam.js +2 -2
- package/dist/queries/buildSortParam.js.map +1 -1
- package/dist/queries/getLocalizedSortProperty.js +2 -2
- package/dist/queries/getLocalizedSortProperty.js.map +1 -1
- package/dist/queries/parseParams.d.ts +3 -1
- package/dist/queries/parseParams.d.ts.map +1 -1
- package/dist/queries/parseParams.js +2 -1
- package/dist/queries/parseParams.js.map +1 -1
- package/dist/queries/sanitizeQueryValue.d.ts +2 -1
- package/dist/queries/sanitizeQueryValue.d.ts.map +1 -1
- package/dist/queries/sanitizeQueryValue.js +33 -6
- package/dist/queries/sanitizeQueryValue.js.map +1 -1
- package/dist/queryDrafts.d.ts.map +1 -1
- package/dist/queryDrafts.js +42 -66
- package/dist/queryDrafts.js.map +1 -1
- package/dist/updateGlobal.d.ts.map +1 -1
- package/dist/updateGlobal.js +27 -24
- package/dist/updateGlobal.js.map +1 -1
- package/dist/updateGlobalVersion.d.ts.map +1 -1
- package/dist/updateGlobalVersion.js +30 -28
- package/dist/updateGlobalVersion.js.map +1 -1
- package/dist/updateOne.d.ts.map +1 -1
- package/dist/updateOne.js +30 -25
- package/dist/updateOne.js.map +1 -1
- package/dist/updateVersion.d.ts.map +1 -1
- package/dist/updateVersion.js +30 -27
- package/dist/updateVersion.js.map +1 -1
- package/dist/upsert.d.ts.map +1 -1
- package/dist/upsert.js +1 -1
- package/dist/upsert.js.map +1 -1
- package/dist/utilities/buildJoinAggregation.d.ts +4 -4
- package/dist/utilities/buildJoinAggregation.d.ts.map +1 -1
- package/dist/utilities/buildJoinAggregation.js +13 -30
- package/dist/utilities/buildJoinAggregation.js.map +1 -1
- package/dist/utilities/buildProjectionFromSelect.d.ts.map +1 -1
- package/dist/utilities/buildProjectionFromSelect.js +18 -1
- package/dist/utilities/buildProjectionFromSelect.js.map +1 -1
- package/dist/utilities/findMany.d.ts +20 -0
- package/dist/utilities/findMany.d.ts.map +1 -0
- package/dist/utilities/findMany.js +84 -0
- package/dist/utilities/findMany.js.map +1 -0
- package/dist/utilities/getHasNearConstraint.d.ts +3 -0
- package/dist/utilities/getHasNearConstraint.d.ts.map +1 -0
- package/dist/utilities/getHasNearConstraint.js +26 -0
- package/dist/utilities/getHasNearConstraint.js.map +1 -0
- package/dist/utilities/getSession.d.ts +9 -0
- package/dist/utilities/getSession.d.ts.map +1 -0
- package/dist/{withSession.js → utilities/getSession.js} +7 -6
- package/dist/utilities/getSession.js.map +1 -0
- package/dist/utilities/handleError.d.ts +3 -2
- package/dist/utilities/handleError.d.ts.map +1 -1
- package/dist/utilities/handleError.js +8 -7
- package/dist/utilities/handleError.js.map +1 -1
- package/dist/utilities/transform.d.ts +25 -0
- package/dist/utilities/transform.d.ts.map +1 -0
- package/dist/utilities/transform.js +254 -0
- package/dist/utilities/transform.js.map +1 -0
- package/dist/utilities/{sanitizeRelationshipIDs.spec.js → transform.spec.js} +23 -7
- package/dist/utilities/transform.spec.js.map +1 -0
- package/package.json +4 -4
- package/dist/utilities/sanitizeInternalFields.d.ts +0 -2
- package/dist/utilities/sanitizeInternalFields.d.ts.map +0 -1
- package/dist/utilities/sanitizeInternalFields.js +0 -20
- package/dist/utilities/sanitizeInternalFields.js.map +0 -1
- package/dist/utilities/sanitizeRelationshipIDs.d.ts +0 -9
- package/dist/utilities/sanitizeRelationshipIDs.d.ts.map +0 -1
- package/dist/utilities/sanitizeRelationshipIDs.js +0 -125
- package/dist/utilities/sanitizeRelationshipIDs.js.map +0 -1
- package/dist/utilities/sanitizeRelationshipIDs.spec.js.map +0 -1
- package/dist/withSession.d.ts +0 -11
- package/dist/withSession.d.ts.map +0 -1
- package/dist/withSession.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/queries/parseParams.ts"],"sourcesContent":["import type { FilterQuery } from 'mongoose'\nimport type { FlattenedField, Operator, Payload, Where } from 'payload'\n\nimport { deepMergeWithCombinedArrays } from 'payload'\nimport { validOperators } from 'payload/shared'\n\nimport { buildAndOrConditions } from './buildAndOrConditions.js'\nimport { buildSearchParam } from './buildSearchParams.js'\n\nexport async function parseParams({\n collectionSlug,\n fields,\n globalSlug,\n locale,\n payload,\n where,\n}: {\n collectionSlug?: string\n fields: FlattenedField[]\n globalSlug?: string\n locale: string\n payload: Payload\n where: Where\n}): Promise<Record<string, unknown>> {\n let result = {} as FilterQuery<any>\n\n if (typeof where === 'object') {\n // We need to determine if the whereKey is an AND, OR, or a schema path\n for (const relationOrPath of Object.keys(where)) {\n const condition = where[relationOrPath]\n let conditionOperator: '$and' | '$or'\n if (relationOrPath.toLowerCase() === 'and') {\n conditionOperator = '$and'\n } else if (relationOrPath.toLowerCase() === 'or') {\n conditionOperator = '$or'\n }\n if (Array.isArray(condition)) {\n const builtConditions = await buildAndOrConditions({\n collectionSlug,\n fields,\n globalSlug,\n locale,\n payload,\n where: condition,\n })\n if (builtConditions.length > 0) {\n result[conditionOperator] = builtConditions\n }\n } else {\n // It's a path - and there can be multiple comparisons on a single path.\n // For example - title like 'test' and title not equal to 'tester'\n // So we need to loop on keys again here to handle each operator independently\n const pathOperators = where[relationOrPath]\n if (typeof pathOperators === 'object') {\n for (const operator of Object.keys(pathOperators)) {\n if (validOperators.includes(operator as Operator)) {\n const searchParam = await buildSearchParam({\n collectionSlug,\n fields,\n globalSlug,\n incomingPath: relationOrPath,\n locale,\n operator,\n payload,\n val: pathOperators[operator],\n })\n\n if (searchParam?.value && searchParam?.path) {\n result = {\n ...result,\n [searchParam.path]: searchParam.value,\n }\n } else if (typeof searchParam?.value === 'object') {\n result = deepMergeWithCombinedArrays(result, searchParam.value, {\n // dont clone Types.ObjectIDs\n clone: false,\n })\n }\n }\n }\n }\n }\n }\n }\n\n return result\n}\n"],"names":["deepMergeWithCombinedArrays","validOperators","buildAndOrConditions","buildSearchParam","parseParams","collectionSlug","fields","globalSlug","locale","payload","where","result","relationOrPath","Object","keys","condition","conditionOperator","toLowerCase","Array","isArray","builtConditions","length","pathOperators","operator","includes","searchParam","incomingPath","val","value","path","clone"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../src/queries/parseParams.ts"],"sourcesContent":["import type { ClientSession } from 'mongodb'\nimport type { FilterQuery } from 'mongoose'\nimport type { FlattenedField, Operator, Payload, Where } from 'payload'\n\nimport { deepMergeWithCombinedArrays } from 'payload'\nimport { validOperators } from 'payload/shared'\n\nimport { buildAndOrConditions } from './buildAndOrConditions.js'\nimport { buildSearchParam } from './buildSearchParams.js'\n\nexport async function parseParams({\n collectionSlug,\n fields,\n globalSlug,\n locale,\n payload,\n session,\n where,\n}: {\n collectionSlug?: string\n fields: FlattenedField[]\n globalSlug?: string\n locale: string\n payload: Payload\n session?: ClientSession\n where: Where\n}): Promise<Record<string, unknown>> {\n let result = {} as FilterQuery<any>\n\n if (typeof where === 'object') {\n // We need to determine if the whereKey is an AND, OR, or a schema path\n for (const relationOrPath of Object.keys(where)) {\n const condition = where[relationOrPath]\n let conditionOperator: '$and' | '$or'\n if (relationOrPath.toLowerCase() === 'and') {\n conditionOperator = '$and'\n } else if (relationOrPath.toLowerCase() === 'or') {\n conditionOperator = '$or'\n }\n if (Array.isArray(condition)) {\n const builtConditions = await buildAndOrConditions({\n collectionSlug,\n fields,\n globalSlug,\n locale,\n payload,\n where: condition,\n })\n if (builtConditions.length > 0) {\n result[conditionOperator] = builtConditions\n }\n } else {\n // It's a path - and there can be multiple comparisons on a single path.\n // For example - title like 'test' and title not equal to 'tester'\n // So we need to loop on keys again here to handle each operator independently\n const pathOperators = where[relationOrPath]\n if (typeof pathOperators === 'object') {\n for (const operator of Object.keys(pathOperators)) {\n if (validOperators.includes(operator as Operator)) {\n const searchParam = await buildSearchParam({\n collectionSlug,\n fields,\n globalSlug,\n incomingPath: relationOrPath,\n locale,\n operator,\n payload,\n session,\n val: pathOperators[operator],\n })\n\n if (searchParam?.value && searchParam?.path) {\n result = {\n ...result,\n [searchParam.path]: searchParam.value,\n }\n } else if (typeof searchParam?.value === 'object') {\n result = deepMergeWithCombinedArrays(result, searchParam.value, {\n // dont clone Types.ObjectIDs\n clone: false,\n })\n }\n }\n }\n }\n }\n }\n }\n\n return result\n}\n"],"names":["deepMergeWithCombinedArrays","validOperators","buildAndOrConditions","buildSearchParam","parseParams","collectionSlug","fields","globalSlug","locale","payload","session","where","result","relationOrPath","Object","keys","condition","conditionOperator","toLowerCase","Array","isArray","builtConditions","length","pathOperators","operator","includes","searchParam","incomingPath","val","value","path","clone"],"mappings":"AAIA,SAASA,2BAA2B,QAAQ,UAAS;AACrD,SAASC,cAAc,QAAQ,iBAAgB;AAE/C,SAASC,oBAAoB,QAAQ,4BAA2B;AAChE,SAASC,gBAAgB,QAAQ,yBAAwB;AAEzD,OAAO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YG,KAAK,EAAE;oCAC9D,6BAA6B;oCAC7BE,OAAO;gCACT;4BACF;wBACF;oBACF;gBACF;YACF;QACF;IACF;IAEA,OAAOnB;AACT"}
|
|
@@ -2,12 +2,13 @@ import type { FlattenedField, Payload } from 'payload';
|
|
|
2
2
|
type SanitizeQueryValueArgs = {
|
|
3
3
|
field: FlattenedField;
|
|
4
4
|
hasCustomID: boolean;
|
|
5
|
+
locale?: string;
|
|
5
6
|
operator: string;
|
|
6
7
|
path: string;
|
|
7
8
|
payload: Payload;
|
|
8
9
|
val: any;
|
|
9
10
|
};
|
|
10
|
-
export declare const sanitizeQueryValue: ({ field, hasCustomID, operator, path, payload, val, }: SanitizeQueryValueArgs) => {
|
|
11
|
+
export declare const sanitizeQueryValue: ({ field, hasCustomID, locale, operator, path, payload, val, }: SanitizeQueryValueArgs) => {
|
|
11
12
|
operator?: string;
|
|
12
13
|
rawQuery?: unknown;
|
|
13
14
|
val?: unknown;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sanitizeQueryValue.d.ts","sourceRoot":"","sources":["../../src/queries/sanitizeQueryValue.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAkB,cAAc,EAAE,OAAO,EAAqB,MAAM,SAAS,CAAA;AAKzF,KAAK,sBAAsB,GAAG;IAC5B,KAAK,EAAE,cAAc,CAAA;IACrB,WAAW,EAAE,OAAO,CAAA;IACpB,QAAQ,EAAE,MAAM,CAAA;IAChB,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,OAAO,CAAA;IAChB,GAAG,EAAE,GAAG,CAAA;CACT,CAAA;
|
|
1
|
+
{"version":3,"file":"sanitizeQueryValue.d.ts","sourceRoot":"","sources":["../../src/queries/sanitizeQueryValue.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAkB,cAAc,EAAE,OAAO,EAAqB,MAAM,SAAS,CAAA;AAKzF,KAAK,sBAAsB,GAAG;IAC5B,KAAK,EAAE,cAAc,CAAA;IACrB,WAAW,EAAE,OAAO,CAAA;IACpB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,QAAQ,EAAE,MAAM,CAAA;IAChB,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,OAAO,CAAA;IAChB,GAAG,EAAE,GAAG,CAAA;CACT,CAAA;AA6ED,eAAO,MAAM,kBAAkB,kEAQ5B,sBAAsB,KAAG;IAC1B,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,GAAG,CAAC,EAAE,OAAO,CAAA;CAoVd,CAAA"}
|
|
@@ -51,6 +51,19 @@ const buildExistsQuery = (formattedValue, path, treatEmptyString = true)=>{
|
|
|
51
51
|
};
|
|
52
52
|
}
|
|
53
53
|
};
|
|
54
|
+
const sanitizeCoordinates = (coordinates)=>{
|
|
55
|
+
const result = [];
|
|
56
|
+
for (const value of coordinates){
|
|
57
|
+
if (typeof value === 'string') {
|
|
58
|
+
result.push(Number(value));
|
|
59
|
+
} else if (Array.isArray(value)) {
|
|
60
|
+
result.push(sanitizeCoordinates(value));
|
|
61
|
+
} else {
|
|
62
|
+
result.push(value);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return result;
|
|
66
|
+
};
|
|
54
67
|
// returns nestedField Field object from blocks.nestedField path because getLocalizedPaths splits them only for relationships
|
|
55
68
|
const getFieldFromSegments = ({ field, segments })=>{
|
|
56
69
|
if ('blocks' in field) {
|
|
@@ -81,7 +94,7 @@ const getFieldFromSegments = ({ field, segments })=>{
|
|
|
81
94
|
}
|
|
82
95
|
}
|
|
83
96
|
};
|
|
84
|
-
export const sanitizeQueryValue = ({ field, hasCustomID, operator, path, payload, val })=>{
|
|
97
|
+
export const sanitizeQueryValue = ({ field, hasCustomID, locale, operator, path, payload, val })=>{
|
|
85
98
|
let formattedValue = val;
|
|
86
99
|
let formattedOperator = operator;
|
|
87
100
|
if ([
|
|
@@ -200,17 +213,28 @@ export const sanitizeQueryValue = ({ field, hasCustomID, operator, path, payload
|
|
|
200
213
|
if (isValid) {
|
|
201
214
|
formattedValue.value = new Types.ObjectId(value);
|
|
202
215
|
}
|
|
216
|
+
let localizedPath = path;
|
|
217
|
+
if (field.localized && payload.config.localization && locale) {
|
|
218
|
+
localizedPath = `${path}.${locale}`;
|
|
219
|
+
}
|
|
203
220
|
return {
|
|
204
221
|
rawQuery: {
|
|
205
|
-
$
|
|
222
|
+
$or: [
|
|
206
223
|
{
|
|
207
|
-
[
|
|
208
|
-
$eq:
|
|
224
|
+
[localizedPath]: {
|
|
225
|
+
$eq: {
|
|
226
|
+
// disable auto sort
|
|
227
|
+
/* eslint-disable */ value: formattedValue.value,
|
|
228
|
+
relationTo: formattedValue.relationTo
|
|
229
|
+
}
|
|
209
230
|
}
|
|
210
231
|
},
|
|
211
232
|
{
|
|
212
|
-
[
|
|
213
|
-
$eq:
|
|
233
|
+
[localizedPath]: {
|
|
234
|
+
$eq: {
|
|
235
|
+
relationTo: formattedValue.relationTo,
|
|
236
|
+
value: formattedValue.value
|
|
237
|
+
}
|
|
214
238
|
}
|
|
215
239
|
}
|
|
216
240
|
]
|
|
@@ -338,6 +362,9 @@ export const sanitizeQueryValue = ({ field, hasCustomID, operator, path, payload
|
|
|
338
362
|
}
|
|
339
363
|
}
|
|
340
364
|
if (operator === 'within' || operator === 'intersects') {
|
|
365
|
+
if (formattedValue && typeof formattedValue === 'object' && Array.isArray(formattedValue.coordinates)) {
|
|
366
|
+
formattedValue.coordinates = sanitizeCoordinates(formattedValue.coordinates);
|
|
367
|
+
}
|
|
341
368
|
formattedValue = {
|
|
342
369
|
$geometry: formattedValue
|
|
343
370
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/queries/sanitizeQueryValue.ts"],"sourcesContent":["import type { FlattenedBlock, FlattenedField, Payload, RelationshipField } from 'payload'\n\nimport { Types } from 'mongoose'\nimport { createArrayFromCommaDelineated } from 'payload'\n\ntype SanitizeQueryValueArgs = {\n field: FlattenedField\n hasCustomID: boolean\n operator: string\n path: string\n payload: Payload\n val: any\n}\n\nconst buildExistsQuery = (formattedValue, path, treatEmptyString = true) => {\n if (formattedValue) {\n return {\n rawQuery: {\n $and: [\n { [path]: { $exists: true } },\n { [path]: { $ne: null } },\n ...(treatEmptyString ? [{ [path]: { $ne: '' } }] : []), // Treat empty string as null / undefined\n ],\n },\n }\n } else {\n return {\n rawQuery: {\n $or: [\n { [path]: { $exists: false } },\n { [path]: { $eq: null } },\n ...(treatEmptyString ? [{ [path]: { $eq: '' } }] : []), // Treat empty string as null / undefined\n ],\n },\n }\n }\n}\n\n// returns nestedField Field object from blocks.nestedField path because getLocalizedPaths splits them only for relationships\nconst getFieldFromSegments = ({\n field,\n segments,\n}: {\n field: FlattenedBlock | FlattenedField\n segments: string[]\n}) => {\n if ('blocks' in field) {\n for (const block of field.blocks) {\n const field = getFieldFromSegments({ field: block, segments })\n if (field) {\n return field\n }\n }\n }\n\n if ('fields' in field) {\n for (let i = 0; i < segments.length; i++) {\n const foundField = field.flattenedFields.find((each) => each.name === segments[i])\n\n if (!foundField) {\n break\n }\n\n if (foundField && segments.length - 1 === i) {\n return foundField\n }\n\n segments.shift()\n return getFieldFromSegments({ field: foundField, segments })\n }\n }\n}\n\nexport const sanitizeQueryValue = ({\n field,\n hasCustomID,\n operator,\n path,\n payload,\n val,\n}: SanitizeQueryValueArgs): {\n operator?: string\n rawQuery?: unknown\n val?: unknown\n} => {\n let formattedValue = val\n let formattedOperator = operator\n\n if (['array', 'blocks', 'group', 'tab'].includes(field.type) && path.includes('.')) {\n const segments = path.split('.')\n segments.shift()\n const foundField = getFieldFromSegments({ field, segments })\n\n if (foundField) {\n field = foundField\n }\n }\n\n // Disregard invalid _ids\n if (path === '_id') {\n if (typeof val === 'string' && val.split(',').length === 1) {\n if (!hasCustomID) {\n const isValid = 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(\n (id) => new Types.ObjectId(id),\n )\n } else {\n formattedValue = new Types.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 if (!hasCustomID) {\n if (Types.ObjectId.isValid(inVal)) {\n formattedValues.push(new Types.ObjectId(inVal))\n }\n }\n\n if (field.type === 'number') {\n const parsedNumber = parseFloat(inVal)\n if (!Number.isNaN(parsedNumber)) {\n formattedValues.push(parsedNumber)\n }\n } else {\n formattedValues.push(inVal)\n }\n\n return formattedValues\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 = Types.ObjectId.isValid(value)\n\n if (isValid) {\n formattedValue.value = new Types.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 const relationTo = (field as RelationshipField).relationTo\n\n if (['in', 'not_in'].includes(operator) && Array.isArray(formattedValue)) {\n formattedValue = formattedValue.reduce((formattedValues, inVal) => {\n if (!inVal) {\n return formattedValues\n }\n\n if (typeof relationTo === 'string' && payload.collections[relationTo].customIDType) {\n if (payload.collections[relationTo].customIDType === 'number') {\n const parsedNumber = parseFloat(inVal)\n if (!Number.isNaN(parsedNumber)) {\n formattedValues.push(parsedNumber)\n return formattedValues\n }\n }\n\n formattedValues.push(inVal)\n return formattedValues\n }\n\n if (\n Array.isArray(relationTo) &&\n relationTo.some((relationTo) => !!payload.collections[relationTo].customIDType)\n ) {\n if (Types.ObjectId.isValid(inVal.toString())) {\n formattedValues.push(new Types.ObjectId(inVal))\n } else {\n formattedValues.push(inVal)\n }\n return formattedValues\n }\n\n if (Types.ObjectId.isValid(inVal.toString())) {\n formattedValues.push(new Types.ObjectId(inVal))\n }\n\n return formattedValues\n }, [])\n }\n\n if (\n ['contains', 'equals', 'like', 'not_equals'].includes(operator) &&\n (!Array.isArray(relationTo) || !path.endsWith('.relationTo'))\n ) {\n if (typeof relationTo === 'string') {\n const customIDType = payload.collections[relationTo].customIDType\n\n if (customIDType) {\n if (customIDType === 'number') {\n formattedValue = parseFloat(val)\n\n if (Number.isNaN(formattedValue)) {\n return { operator: formattedOperator, val: undefined }\n }\n }\n } else {\n if (!Types.ObjectId.isValid(formattedValue)) {\n return { operator: formattedOperator, val: undefined }\n }\n formattedValue = new Types.ObjectId(formattedValue)\n }\n } else {\n const hasCustomIDType = relationTo.some(\n (relationTo) => !!payload.collections[relationTo].customIDType,\n )\n\n if (hasCustomIDType) {\n if (typeof val === 'string') {\n const formattedNumber = Number(val)\n formattedValue = [Types.ObjectId.isValid(val) ? new Types.ObjectId(val) : val]\n formattedOperator = operator === 'not_equals' ? 'not_in' : 'in'\n if (!Number.isNaN(formattedNumber)) {\n formattedValue.push(formattedNumber)\n }\n }\n } else {\n if (!Types.ObjectId.isValid(formattedValue)) {\n return { operator: formattedOperator, val: undefined }\n }\n formattedValue = new Types.ObjectId(formattedValue)\n }\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' && !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 // _id can't be empty string, will error Cast to ObjectId failed for value \"\"\n return buildExistsQuery(\n formattedValue,\n path,\n !['relationship', 'upload'].includes(field.type),\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":["Types","createArrayFromCommaDelineated","buildExistsQuery","formattedValue","path","treatEmptyString","rawQuery","$and","$exists","$ne","$or","$eq","getFieldFromSegments","field","segments","block","blocks","i","length","foundField","flattenedFields","find","each","name","shift","sanitizeQueryValue","hasCustomID","operator","payload","val","formattedOperator","includes","type","split","isValid","ObjectId","undefined","map","id","parsedNumber","parseFloat","Number","isNaN","Array","isArray","reduce","formattedValues","inVal","push","toLowerCase","arrayVal","Boolean","Date","parse","value","relationTo","collections","customIDType","some","toString","endsWith","hasCustomIDType","formattedNumber","lng","lat","maxDistance","minDistance","$geometry","coordinates","$maxDistance","$minDistance","$options","$regex","replace"],"mappings":"AAEA,SAASA,KAAK,QAAQ,WAAU;AAChC,SAASC,8BAA8B,QAAQ,UAAS;AAWxD,MAAMC,mBAAmB,CAACC,gBAAgBC,MAAMC,mBAAmB,IAAI;IACrE,IAAIF,gBAAgB;QAClB,OAAO;YACLG,UAAU;gBACRC,MAAM;oBACJ;wBAAE,CAACH,KAAK,EAAE;4BAAEI,SAAS;wBAAK;oBAAE;oBAC5B;wBAAE,CAACJ,KAAK,EAAE;4BAAEK,KAAK;wBAAK;oBAAE;uBACpBJ,mBAAmB;wBAAC;4BAAE,CAACD,KAAK,EAAE;gCAAEK,KAAK;4BAAG;wBAAE;qBAAE,GAAG,EAAE;iBACtD;YACH;QACF;IACF,OAAO;QACL,OAAO;YACLH,UAAU;gBACRI,KAAK;oBACH;wBAAE,CAACN,KAA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C9E,IAAIL,aAAa,cAAc,CAAC3B,MAAMmC,QAAQ,CAACD,OAAO,CAAC/B,iBAAiB;YACtEA,iBAAiB;gBACfoE,UAAU;gBACVC,QAAQrE,eAAesE,OAAO,CAAC,uBAAuB;YACxD;QACF;QAEA,IAAI9C,aAAa,UAAU;YACzBxB,iBAAiBA,mBAAmB,UAAUA,mBAAmB;YAEjE,6EAA6E;YAC7E,OAAOD,iBACLC,gBACAC,MACA,CAAC;gBAAC;gBAAgB;aAAS,CAAC2B,QAAQ,CAAClB,MAAMmB,IAAI;QAEnD;IACF;IAEA,IACE,AAAC5B,CAAAA,SAAS,SAASA,SAAS,QAAO,KACnCuB,aAAa,UACbxB,eAAee,MAAM,KAAK,MAC1B,CAACQ,aACD;QACAI,oBAAoB;IACtB;IAEA,IAAIH,aAAa,UAAU;QACzBxB,iBAAiBA,mBAAmB,UAAUA,mBAAmB;QAEjE,mBAAmB;QACnB,IAAI;YAAC;YAAgB;YAAU;SAAS,CAAC4B,QAAQ,CAAClB,MAAMmB,IAAI,GAAG;YAC7D,IAAI7B,gBAAgB;gBAClB,OAAO;oBACLG,UAAU;wBACRC,MAAM;4BAAC;gCAAE,CAACH,KAAK,EAAE;oCAAEI,SAAS;gCAAK;4BAAE;4BAAG;gCAAE,CAACJ,KAAK,EAAE;oCAAEK,KAAK;gCAAK;4BAAE;yBAAE;oBAClE;gBACF;YACF,OAAO;gBACL,OAAO;oBACLH,UAAU;wBACRI,KAAK;4BAAC;gCAAE,CAACN,KAAK,EAAE;oCAAEI,SAAS;gCAAM;4BAAE;4BAAG;gCAAE,CAACJ,KAAK,EAAE;oCAAEO,KAAK;gCAAK;4BAAE;yBAAE;oBAClE;gBACF;YACF;QACF;IACF;IAEA,OAAO;QAAEgB,UAAUG;QAAmBD,KAAK1B;IAAe;AAC5D,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../src/queries/sanitizeQueryValue.ts"],"sourcesContent":["import type { FlattenedBlock, FlattenedField, Payload, RelationshipField } from 'payload'\n\nimport { Types } from 'mongoose'\nimport { createArrayFromCommaDelineated } from 'payload'\n\ntype SanitizeQueryValueArgs = {\n field: FlattenedField\n hasCustomID: boolean\n locale?: string\n operator: string\n path: string\n payload: Payload\n val: any\n}\n\nconst buildExistsQuery = (formattedValue, path, treatEmptyString = true) => {\n if (formattedValue) {\n return {\n rawQuery: {\n $and: [\n { [path]: { $exists: true } },\n { [path]: { $ne: null } },\n ...(treatEmptyString ? [{ [path]: { $ne: '' } }] : []), // Treat empty string as null / undefined\n ],\n },\n }\n } else {\n return {\n rawQuery: {\n $or: [\n { [path]: { $exists: false } },\n { [path]: { $eq: null } },\n ...(treatEmptyString ? [{ [path]: { $eq: '' } }] : []), // Treat empty string as null / undefined\n ],\n },\n }\n }\n}\n\nconst sanitizeCoordinates = (coordinates: unknown[]): unknown[] => {\n const result: unknown[] = []\n\n for (const value of coordinates) {\n if (typeof value === 'string') {\n result.push(Number(value))\n } else if (Array.isArray(value)) {\n result.push(sanitizeCoordinates(value))\n } else {\n result.push(value)\n }\n }\n\n return result\n}\n\n// returns nestedField Field object from blocks.nestedField path because getLocalizedPaths splits them only for relationships\nconst getFieldFromSegments = ({\n field,\n segments,\n}: {\n field: FlattenedBlock | FlattenedField\n segments: string[]\n}) => {\n if ('blocks' in field) {\n for (const block of field.blocks) {\n const field = getFieldFromSegments({ field: block, segments })\n if (field) {\n return field\n }\n }\n }\n\n if ('fields' in field) {\n for (let i = 0; i < segments.length; i++) {\n const foundField = field.flattenedFields.find((each) => each.name === segments[i])\n\n if (!foundField) {\n break\n }\n\n if (foundField && segments.length - 1 === i) {\n return foundField\n }\n\n segments.shift()\n return getFieldFromSegments({ field: foundField, segments })\n }\n }\n}\n\nexport const sanitizeQueryValue = ({\n field,\n hasCustomID,\n locale,\n operator,\n path,\n payload,\n val,\n}: SanitizeQueryValueArgs): {\n operator?: string\n rawQuery?: unknown\n val?: unknown\n} => {\n let formattedValue = val\n let formattedOperator = operator\n\n if (['array', 'blocks', 'group', 'tab'].includes(field.type) && path.includes('.')) {\n const segments = path.split('.')\n segments.shift()\n const foundField = getFieldFromSegments({ field, segments })\n\n if (foundField) {\n field = foundField\n }\n }\n\n // Disregard invalid _ids\n if (path === '_id') {\n if (typeof val === 'string' && val.split(',').length === 1) {\n if (!hasCustomID) {\n const isValid = 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(\n (id) => new Types.ObjectId(id),\n )\n } else {\n formattedValue = new Types.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 if (!hasCustomID) {\n if (Types.ObjectId.isValid(inVal)) {\n formattedValues.push(new Types.ObjectId(inVal))\n }\n }\n\n if (field.type === 'number') {\n const parsedNumber = parseFloat(inVal)\n if (!Number.isNaN(parsedNumber)) {\n formattedValues.push(parsedNumber)\n }\n } else {\n formattedValues.push(inVal)\n }\n\n return formattedValues\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 = Types.ObjectId.isValid(value)\n\n if (isValid) {\n formattedValue.value = new Types.ObjectId(value)\n }\n\n let localizedPath = path\n\n if (field.localized && payload.config.localization && locale) {\n localizedPath = `${path}.${locale}`\n }\n\n return {\n rawQuery: {\n $or: [\n {\n [localizedPath]: {\n $eq: {\n // disable auto sort\n /* eslint-disable */\n value: formattedValue.value,\n relationTo: formattedValue.relationTo,\n /* eslint-enable */\n },\n },\n },\n {\n [localizedPath]: {\n $eq: {\n relationTo: formattedValue.relationTo,\n value: formattedValue.value,\n },\n },\n },\n ],\n },\n }\n }\n\n const relationTo = (field as RelationshipField).relationTo\n\n if (['in', 'not_in'].includes(operator) && Array.isArray(formattedValue)) {\n formattedValue = formattedValue.reduce((formattedValues, inVal) => {\n if (!inVal) {\n return formattedValues\n }\n\n if (typeof relationTo === 'string' && payload.collections[relationTo].customIDType) {\n if (payload.collections[relationTo].customIDType === 'number') {\n const parsedNumber = parseFloat(inVal)\n if (!Number.isNaN(parsedNumber)) {\n formattedValues.push(parsedNumber)\n return formattedValues\n }\n }\n\n formattedValues.push(inVal)\n return formattedValues\n }\n\n if (\n Array.isArray(relationTo) &&\n relationTo.some((relationTo) => !!payload.collections[relationTo].customIDType)\n ) {\n if (Types.ObjectId.isValid(inVal.toString())) {\n formattedValues.push(new Types.ObjectId(inVal))\n } else {\n formattedValues.push(inVal)\n }\n return formattedValues\n }\n\n if (Types.ObjectId.isValid(inVal.toString())) {\n formattedValues.push(new Types.ObjectId(inVal))\n }\n\n return formattedValues\n }, [])\n }\n\n if (\n ['contains', 'equals', 'like', 'not_equals'].includes(operator) &&\n (!Array.isArray(relationTo) || !path.endsWith('.relationTo'))\n ) {\n if (typeof relationTo === 'string') {\n const customIDType = payload.collections[relationTo].customIDType\n\n if (customIDType) {\n if (customIDType === 'number') {\n formattedValue = parseFloat(val)\n\n if (Number.isNaN(formattedValue)) {\n return { operator: formattedOperator, val: undefined }\n }\n }\n } else {\n if (!Types.ObjectId.isValid(formattedValue)) {\n return { operator: formattedOperator, val: undefined }\n }\n formattedValue = new Types.ObjectId(formattedValue)\n }\n } else {\n const hasCustomIDType = relationTo.some(\n (relationTo) => !!payload.collections[relationTo].customIDType,\n )\n\n if (hasCustomIDType) {\n if (typeof val === 'string') {\n const formattedNumber = Number(val)\n formattedValue = [Types.ObjectId.isValid(val) ? new Types.ObjectId(val) : val]\n formattedOperator = operator === 'not_equals' ? 'not_in' : 'in'\n if (!Number.isNaN(formattedNumber)) {\n formattedValue.push(formattedNumber)\n }\n }\n } else {\n if (!Types.ObjectId.isValid(formattedValue)) {\n return { operator: formattedOperator, val: undefined }\n }\n formattedValue = new Types.ObjectId(formattedValue)\n }\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 if (\n formattedValue &&\n typeof formattedValue === 'object' &&\n Array.isArray(formattedValue.coordinates)\n ) {\n formattedValue.coordinates = sanitizeCoordinates(formattedValue.coordinates)\n }\n\n formattedValue = {\n $geometry: formattedValue,\n }\n }\n\n if (path !== '_id' || (path === '_id' && hasCustomID && field.type === 'text')) {\n if (operator === 'contains' && !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 // _id can't be empty string, will error Cast to ObjectId failed for value \"\"\n return buildExistsQuery(\n formattedValue,\n path,\n !['relationship', 'upload'].includes(field.type),\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":["Types","createArrayFromCommaDelineated","buildExistsQuery","formattedValue","path","treatEmptyString","rawQuery","$and","$exists","$ne","$or","$eq","sanitizeCoordinates","coordinates","result","value","push","Number","Array","isArray","getFieldFromSegments","field","segments","block","blocks","i","length","foundField","flattenedFields","find","each","name","shift","sanitizeQueryValue","hasCustomID","locale","operator","payload","val","formattedOperator","includes","type","split","isValid","ObjectId","undefined","map","id","parsedNumber","parseFloat","isNaN","reduce","formattedValues","inVal","toLowerCase","arrayVal","Boolean","Date","parse","relationTo","localizedPath","localized","config","localization","collections","customIDType","some","toString","endsWith","hasCustomIDType","formattedNumber","lng","lat","maxDistance","minDistance","$geometry","$maxDistance","$minDistance","$options","$regex","replace"],"mappings":"AAEA,SAASA,KAAK,QAAQ,WAAU;AAChC,SAASC,8BAA8B,QAAQ,UAAS;AAYxD,MAAMC,mBAAmB,CAACC,gBAAgBC,MAAMC,mBAAmB,IAAI;IACrE,IAAIF,gBAAgB;QAClB,OAAO;YACLG,UAAU;gBACRC,MAAM;oBACJ;wBAAE,CAACH,KAAK,EAAE;4BAAEI,SAAS;wBAAK;oBAAE;oBAC5B;wBAAE,CAACJ,KAAK,EAAE;4BAAEK,KAAK;wBAAK;oBAAE;uBACpBJ,mBAAmB;wBAAC;4BAAE,CAACD,KAAK,EAAE;gCAAEK,KAAK;4BAAG;wBAAE;qBAAE,GAAG,EAAE;iBACtD;YACH;QACF;IACF,OAAO;QACL,OAAO;YACLH,UAAU;gBACRI,KAAK;oBACH;wBAAE,CAACN,KAAK,EAAE;4BAAEI,SAAS;wBAAM;oBAAE;oBAC7B;wBAAE,CAACJ,KAAK,EAAE;4BAAEO,KAAK;wBAAK;oBAAE;uBACpBN,mBAAmB;wBAAC;4BAAE,CAACD,KAAK,EAAE;gCAAEO,KAAK;4BAAG;wBAAE;qBAAE,GAAG,EAAE;iBACtD;YACH;QACF;IACF;AACF;AAEA,MAAMC,sBAAsB,CAACC;IAC3B,MAAMC,SAAoB,EAAE;IAE5B,KAAK,MAAMC,SAASF,YAAa;QAC/B,IAAI,OAAOE,UAAU,UAAU;YAC7BD,OAAOE,IAAI,CAACC,OAAOF;QACrB,OAAO,IAAIG,MAAMC,OAAO,CAACJ,QAAQ;YAC/BD,OAAOE,IAAI,CAACJ,oBAAoBG;QAClC,OAAO;YACLD,OAAOE,IAAI,CAACD;QACd;IACF;IAEA,OAAOD;AACT;AAEA,6HAA6H;AAC7H,MAAMM,uBAAuB,CAAC,EAC5BC,KAAK,EACLC,QAAQ,EAIT;IACC,IAAI,YAAYD,OA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}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queryDrafts.d.ts","sourceRoot":"","sources":["../src/queryDrafts.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"queryDrafts.d.ts","sourceRoot":"","sources":["../src/queryDrafts.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAc1C,eAAO,MAAM,WAAW,EAAE,WAuFzB,CAAA"}
|
package/dist/queryDrafts.js
CHANGED
|
@@ -1,19 +1,17 @@
|
|
|
1
|
-
import { buildVersionCollectionFields, combineQueries
|
|
1
|
+
import { buildVersionCollectionFields, combineQueries } from 'payload';
|
|
2
2
|
import { buildSortParam } from './queries/buildSortParam.js';
|
|
3
3
|
import { buildJoinAggregation } from './utilities/buildJoinAggregation.js';
|
|
4
4
|
import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
5
|
+
import { findMany } from './utilities/findMany.js';
|
|
6
|
+
import { getHasNearConstraint } from './utilities/getHasNearConstraint.js';
|
|
7
|
+
import { getSession } from './utilities/getSession.js';
|
|
8
|
+
import { transform } from './utilities/transform.js';
|
|
9
|
+
export const queryDrafts = async function queryDrafts({ collection, joins, limit, locale, page, pagination, req, select, sort: sortArg, where }) {
|
|
8
10
|
const VersionModel = this.versions[collection];
|
|
9
11
|
const collectionConfig = this.payload.collections[collection].config;
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
+
const session = await getSession(this, req);
|
|
13
|
+
const hasNearConstraint = getHasNearConstraint(where);
|
|
12
14
|
let sort;
|
|
13
|
-
if (where) {
|
|
14
|
-
const constraints = flattenWhereToOperators(where);
|
|
15
|
-
hasNearConstraint = constraints.some((prop)=>Object.keys(prop).some((key)=>key === 'near'));
|
|
16
|
-
}
|
|
17
15
|
if (!hasNearConstraint) {
|
|
18
16
|
sort = buildSortParam({
|
|
19
17
|
config: this.payload.config,
|
|
@@ -31,79 +29,57 @@ export const queryDrafts = async function queryDrafts({ collection, joins, limit
|
|
|
31
29
|
const versionQuery = await VersionModel.buildQuery({
|
|
32
30
|
locale,
|
|
33
31
|
payload: this.payload,
|
|
32
|
+
session,
|
|
34
33
|
where: combinedWhere
|
|
35
34
|
});
|
|
35
|
+
const versionFields = buildVersionCollectionFields(this.payload.config, collectionConfig, true);
|
|
36
36
|
const projection = buildProjectionFromSelect({
|
|
37
37
|
adapter: this,
|
|
38
|
-
fields:
|
|
38
|
+
fields: versionFields,
|
|
39
39
|
select
|
|
40
40
|
});
|
|
41
41
|
// useEstimatedCount is faster, but not accurate, as it ignores any filters. It is thus set to true if there are no filters.
|
|
42
42
|
const useEstimatedCount = hasNearConstraint || !versionQuery || Object.keys(versionQuery).length === 0;
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
pagination,
|
|
49
|
-
projection,
|
|
50
|
-
sort,
|
|
51
|
-
useEstimatedCount
|
|
52
|
-
};
|
|
53
|
-
if (this.collation) {
|
|
54
|
-
const defaultLocale = 'en';
|
|
55
|
-
paginationOptions.collation = {
|
|
56
|
-
locale: locale && locale !== 'all' && locale !== '*' ? locale : defaultLocale,
|
|
57
|
-
...this.collation
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
if (!useEstimatedCount && Object.keys(versionQuery).length === 0 && this.disableIndexHints !== true) {
|
|
61
|
-
// Improve the performance of the countDocuments query which is used if useEstimatedCount is set to false by adding
|
|
62
|
-
// a hint. By default, if no hint is provided, MongoDB does not use an indexed field to count the returned documents,
|
|
63
|
-
// which makes queries very slow. This only happens when no query (filter) is provided. If one is provided, it uses
|
|
64
|
-
// the correct indexed field
|
|
65
|
-
paginationOptions.useCustomCountFn = ()=>{
|
|
66
|
-
return Promise.resolve(VersionModel.countDocuments(versionQuery, {
|
|
67
|
-
hint: {
|
|
68
|
-
_id: 1
|
|
69
|
-
}
|
|
70
|
-
}));
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
if (limit > 0) {
|
|
74
|
-
paginationOptions.limit = limit;
|
|
75
|
-
// limit must also be set here, it's ignored when pagination is false
|
|
76
|
-
paginationOptions.options.limit = limit;
|
|
77
|
-
}
|
|
78
|
-
let result;
|
|
79
|
-
const aggregate = await buildJoinAggregation({
|
|
43
|
+
const collation = this.collation ? {
|
|
44
|
+
locale: locale && locale !== 'all' && locale !== '*' ? locale : 'en',
|
|
45
|
+
...this.collation
|
|
46
|
+
} : undefined;
|
|
47
|
+
const joinAgreggation = await buildJoinAggregation({
|
|
80
48
|
adapter: this,
|
|
81
49
|
collection,
|
|
82
50
|
collectionConfig,
|
|
83
51
|
joins,
|
|
84
52
|
locale,
|
|
85
53
|
projection,
|
|
86
|
-
|
|
54
|
+
session,
|
|
87
55
|
versions: true
|
|
88
56
|
});
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
57
|
+
const result = await findMany({
|
|
58
|
+
adapter: this,
|
|
59
|
+
collation,
|
|
60
|
+
collection: VersionModel.collection,
|
|
61
|
+
joinAgreggation,
|
|
62
|
+
limit,
|
|
63
|
+
page,
|
|
64
|
+
pagination,
|
|
65
|
+
projection,
|
|
66
|
+
query: versionQuery,
|
|
67
|
+
session,
|
|
68
|
+
sort,
|
|
69
|
+
useEstimatedCount
|
|
70
|
+
});
|
|
71
|
+
transform({
|
|
72
|
+
adapter: this,
|
|
73
|
+
data: result.docs,
|
|
74
|
+
fields: versionFields,
|
|
75
|
+
operation: 'read'
|
|
76
|
+
});
|
|
77
|
+
for(let i = 0; i < result.docs.length; i++){
|
|
78
|
+
const id = result.docs[i].parent;
|
|
79
|
+
result.docs[i] = result.docs[i].version;
|
|
80
|
+
result.docs[i].id = id;
|
|
94
81
|
}
|
|
95
|
-
|
|
96
|
-
return {
|
|
97
|
-
...result,
|
|
98
|
-
docs: docs.map((doc)=>{
|
|
99
|
-
doc = {
|
|
100
|
-
_id: doc.parent,
|
|
101
|
-
id: doc.parent,
|
|
102
|
-
...doc.version
|
|
103
|
-
};
|
|
104
|
-
return sanitizeInternalFields(doc);
|
|
105
|
-
})
|
|
106
|
-
};
|
|
82
|
+
return result;
|
|
107
83
|
};
|
|
108
84
|
|
|
109
85
|
//# sourceMappingURL=queryDrafts.js.map
|
package/dist/queryDrafts.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/queryDrafts.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"sources":["../src/queryDrafts.ts"],"sourcesContent":["import type { CollationOptions } from 'mongodb'\nimport type { QueryDrafts } from 'payload'\n\nimport { buildVersionCollectionFields, combineQueries } 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 { findMany } from './utilities/findMany.js'\nimport { getHasNearConstraint } from './utilities/getHasNearConstraint.js'\nimport { getSession } from './utilities/getSession.js'\nimport { transform } from './utilities/transform.js'\n\nexport const queryDrafts: QueryDrafts = async function queryDrafts(\n this: MongooseAdapter,\n { collection, joins, limit, locale, page, pagination, req, select, sort: sortArg, where },\n) {\n const VersionModel = this.versions[collection]\n const collectionConfig = this.payload.collections[collection].config\n const session = await getSession(this, req)\n\n const hasNearConstraint = getHasNearConstraint(where)\n let sort\n\n if (!hasNearConstraint) {\n sort = buildSortParam({\n config: this.payload.config,\n fields: collectionConfig.flattenedFields,\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 session,\n where: combinedWhere,\n })\n\n const versionFields = buildVersionCollectionFields(this.payload.config, collectionConfig, true)\n const projection = buildProjectionFromSelect({\n adapter: this,\n fields: versionFields,\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\n const collation: CollationOptions | undefined = this.collation\n ? {\n locale: locale && locale !== 'all' && locale !== '*' ? locale : 'en',\n ...this.collation,\n }\n : undefined\n\n const joinAgreggation = await buildJoinAggregation({\n adapter: this,\n collection,\n collectionConfig,\n joins,\n locale,\n projection,\n session,\n versions: true,\n })\n\n const result = await findMany({\n adapter: this,\n collation,\n collection: VersionModel.collection,\n joinAgreggation,\n limit,\n page,\n pagination,\n projection,\n query: versionQuery,\n session,\n sort,\n useEstimatedCount,\n })\n\n transform({\n adapter: this,\n data: result.docs,\n fields: versionFields,\n operation: 'read',\n })\n\n for (let i = 0; i < result.docs.length; i++) {\n const id = result.docs[i].parent\n result.docs[i] = result.docs[i].version\n result.docs[i].id = id\n }\n\n return result\n}\n"],"names":["buildVersionCollectionFields","combineQueries","buildSortParam","buildJoinAggregation","buildProjectionFromSelect","findMany","getHasNearConstraint","getSession","transform","queryDrafts","collection","joins","limit","locale","page","pagination","req","select","sort","sortArg","where","VersionModel","versions","collectionConfig","payload","collections","config","session","hasNearConstraint","fields","flattenedFields","defaultSort","timestamps","combinedWhere","latest","equals","versionQuery","buildQuery","versionFields","projection","adapter","useEstimatedCount","Object","keys","length","collation","undefined","joinAgreggation","result","query","data","docs","operation","i","id","parent","version"],"mappings":"AAGA,SAASA,4BAA4B,EAAEC,cAAc,QAAQ,UAAS;AAItE,SAASC,cAAc,QAAQ,8BAA6B;AAC5D,SAASC,oBAAoB,QAAQ,sCAAqC;AAC1E,SAASC,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,QAAQ,QAAQ,0BAAyB;AAClD,SAASC,oBAAoB,QAAQ,sCAAqC;AAC1E,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,SAAS,QAAQ,2BAA0B;AAEpD,OAAO,MAA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,SAAS,IAAI;QACb9B;QACAa;QACAZ;QACAE;QACA0B;QACAZ;QACAL,UAAU;IACZ;IAEA,MAAM0B,SAAS,MAAM3C,SAAS;QAC5BmC,SAAS,IAAI;QACbK;QACAnC,YAAYW,aAAaX,UAAU;QACnCqC;QACAnC;QACAE;QACAC;QACAwB;QACAU,OAAOb;QACPT;QACAT;QACAuB;IACF;IAEAjC,UAAU;QACRgC,SAAS,IAAI;QACbU,MAAMF,OAAOG,IAAI;QACjBtB,QAAQS;QACRc,WAAW;IACb;IAEA,IAAK,IAAIC,IAAI,GAAGA,IAAIL,OAAOG,IAAI,CAACP,MAAM,EAAES,IAAK;QAC3C,MAAMC,KAAKN,OAAOG,IAAI,CAACE,EAAE,CAACE,MAAM;QAChCP,OAAOG,IAAI,CAACE,EAAE,GAAGL,OAAOG,IAAI,CAACE,EAAE,CAACG,OAAO;QACvCR,OAAOG,IAAI,CAACE,EAAE,CAACC,EAAE,GAAGA;IACtB;IAEA,OAAON;AACT,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"updateGlobal.d.ts","sourceRoot":"","sources":["../src/updateGlobal.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"updateGlobal.d.ts","sourceRoot":"","sources":["../src/updateGlobal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAQ3C,eAAO,MAAM,YAAY,EAAE,YAoC1B,CAAA"}
|
package/dist/updateGlobal.js
CHANGED
|
@@ -1,34 +1,37 @@
|
|
|
1
1
|
import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
export const updateGlobal = async function updateGlobal({ slug, data, options: optionsArgs = {}, req = {}, select }) {
|
|
2
|
+
import { getSession } from './utilities/getSession.js';
|
|
3
|
+
import { transform } from './utilities/transform.js';
|
|
4
|
+
export const updateGlobal = async function updateGlobal({ slug, data, options: optionsArgs = {}, req, select }) {
|
|
6
5
|
const Model = this.globals;
|
|
7
|
-
const fields = this.payload.config.globals.find((global)=>global.slug === slug).
|
|
8
|
-
const
|
|
6
|
+
const fields = this.payload.config.globals.find((global)=>global.slug === slug).flattenedFields;
|
|
7
|
+
const session = await getSession(this, req);
|
|
8
|
+
transform({
|
|
9
|
+
adapter: this,
|
|
10
|
+
data,
|
|
11
|
+
fields,
|
|
12
|
+
operation: 'update',
|
|
13
|
+
timestamps: optionsArgs.timestamps !== false
|
|
14
|
+
});
|
|
15
|
+
const result = await Model.collection.findOneAndUpdate({
|
|
16
|
+
globalType: slug
|
|
17
|
+
}, {
|
|
18
|
+
$set: data
|
|
19
|
+
}, {
|
|
9
20
|
...optionsArgs,
|
|
10
|
-
...await withSession(this, req),
|
|
11
|
-
lean: true,
|
|
12
|
-
new: true,
|
|
13
21
|
projection: buildProjectionFromSelect({
|
|
14
22
|
adapter: this,
|
|
15
|
-
fields
|
|
23
|
+
fields,
|
|
16
24
|
select
|
|
17
|
-
})
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
25
|
+
}),
|
|
26
|
+
returnDocument: 'after',
|
|
27
|
+
session
|
|
28
|
+
});
|
|
29
|
+
transform({
|
|
30
|
+
adapter: this,
|
|
31
|
+
data: result,
|
|
32
|
+
fields,
|
|
33
|
+
operation: 'read'
|
|
24
34
|
});
|
|
25
|
-
result = await Model.findOneAndUpdate({
|
|
26
|
-
globalType: slug
|
|
27
|
-
}, sanitizedData, options);
|
|
28
|
-
result = JSON.parse(JSON.stringify(result));
|
|
29
|
-
// custom id type reset
|
|
30
|
-
result.id = result._id;
|
|
31
|
-
result = sanitizeInternalFields(result);
|
|
32
35
|
return result;
|
|
33
36
|
};
|
|
34
37
|
|
package/dist/updateGlobal.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/updateGlobal.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"sources":["../src/updateGlobal.ts"],"sourcesContent":["import type { UpdateGlobal } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getSession } from './utilities/getSession.js'\nimport { transform } from './utilities/transform.js'\n\nexport const updateGlobal: UpdateGlobal = async function updateGlobal(\n this: MongooseAdapter,\n { slug, data, options: optionsArgs = {}, req, select },\n) {\n const Model = this.globals\n const fields = this.payload.config.globals.find((global) => global.slug === slug).flattenedFields\n\n const session = await getSession(this, req)\n\n transform({\n adapter: this,\n data,\n fields,\n operation: 'update',\n timestamps: optionsArgs.timestamps !== false,\n })\n\n const result: any = await Model.collection.findOneAndUpdate(\n { globalType: slug },\n { $set: data },\n {\n ...optionsArgs,\n projection: buildProjectionFromSelect({ adapter: this, fields, select }),\n returnDocument: 'after',\n session,\n },\n )\n\n transform({\n adapter: this,\n data: result,\n fields,\n operation: 'read',\n })\n\n return result\n}\n"],"names":["buildProjectionFromSelect","getSession","transform","updateGlobal","slug","data","options","optionsArgs","req","select","Model","globals","fields","payload","config","find","global","flattenedFields","session","adapter","operation","timestamps","result","collection","findOneAndUpdate","globalType","$set","projection","returnDocument"],"mappings":"AAIA,SAASA,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,SAAS,QAAQ,2BAA0B;AAEpD,OAAO,MAAMC,eAA6B,eAAeA,aAEvD,EAAEC,IAAI,EAAEC,IAAI,EAAEC,SAASC,cAAc,CAAC,CAAC,EAAEC,GAAG,EAAEC,MAAM,EAAE;IAEtD,MAAMC,QAAQ,IAAI,CAACC,OAAO;IAC1B,MAAMC,SAAS,IAAI,CAACC,OAAO,CAACC,MAAM,CAACH,OAAO,CAACI,IAAI,CAAC,CAACC,SAAWA,OAAOZ,IAAI,KAAKA,MAAMa,eAAe;IAEjG,MAAMC,UAAU,MAAMjB,WAAW,IAAI,EAAEO;IAEvCN,UAAU;QACRiB,SAAS,IAAI;QACbd;QACAO;QACAQ,WAAW;QACXC,YAAYd,YAAYc,UAAU,KAAK;IACzC;IAEA,MAAMC,SAAc,MAAMZ,MAAMa,UAAU,CAACC,gBAAgB,CACzD;QAAEC,YAAYrB;IAAK,GACnB;QAAEsB,MAAMrB;IAAK,GACb;QACE,GAAGE,WAAW;QACdoB,YAAY3B,0BAA0B;YAAEmB,SAAS,IAAI;YAAEP;YAAQH;QAAO;QACtEmB,gBAAgB;QAChBV;IACF;IAGFhB,UAAU;QACRiB,SAAS,IAAI;QACbd,MAAMiB;QACNV;QACAQ,WAAW;IACb;IAEA,OAAOE;AACT,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"updateGlobalVersion.d.ts","sourceRoot":"","sources":["../src/updateGlobalVersion.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"updateGlobalVersion.d.ts","sourceRoot":"","sources":["../src/updateGlobalVersion.ts"],"names":[],"mappings":"AAAA,OAAO,EAA4B,KAAK,UAAU,EAAE,KAAK,uBAAuB,EAAE,MAAM,SAAS,CAAA;AAEjG,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,OAAO,EAAE,WAAgB,EACzB,GAAG,EACH,MAAM,EACN,WAAW,EACX,KAAK,GACN,EAAE,uBAAuB,CAAC,CAAC,CAAC,gBAkD9B"}
|
|
@@ -1,46 +1,48 @@
|
|
|
1
1
|
import { buildVersionGlobalFields } from 'payload';
|
|
2
2
|
import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
export async function updateGlobalVersion({ id, global: globalSlug, locale, options: optionsArgs = {}, req
|
|
3
|
+
import { getSession } from './utilities/getSession.js';
|
|
4
|
+
import { transform } from './utilities/transform.js';
|
|
5
|
+
export async function updateGlobalVersion({ id, global: globalSlug, locale, options: optionsArgs = {}, req, select, versionData, where }) {
|
|
6
6
|
const VersionModel = this.versions[globalSlug];
|
|
7
7
|
const whereToUse = where || {
|
|
8
8
|
id: {
|
|
9
9
|
equals: id
|
|
10
10
|
}
|
|
11
11
|
};
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const options = {
|
|
15
|
-
...optionsArgs,
|
|
16
|
-
...await withSession(this, req),
|
|
17
|
-
lean: true,
|
|
18
|
-
new: true,
|
|
19
|
-
projection: buildProjectionFromSelect({
|
|
20
|
-
adapter: this,
|
|
21
|
-
fields: buildVersionGlobalFields(this.payload.config, currentGlobal, true),
|
|
22
|
-
select
|
|
23
|
-
})
|
|
24
|
-
};
|
|
12
|
+
const fields = buildVersionGlobalFields(this.payload.config, this.payload.config.globals.find((global)=>global.slug === globalSlug), true);
|
|
13
|
+
const session = await getSession(this, req);
|
|
25
14
|
const query = await VersionModel.buildQuery({
|
|
26
15
|
locale,
|
|
27
16
|
payload: this.payload,
|
|
17
|
+
session,
|
|
28
18
|
where: whereToUse
|
|
29
19
|
});
|
|
30
|
-
|
|
31
|
-
|
|
20
|
+
transform({
|
|
21
|
+
adapter: this,
|
|
32
22
|
data: versionData,
|
|
33
|
-
fields
|
|
23
|
+
fields,
|
|
24
|
+
operation: 'update',
|
|
25
|
+
timestamps: optionsArgs.timestamps !== false
|
|
26
|
+
});
|
|
27
|
+
const doc = await VersionModel.collection.findOneAndUpdate(query, {
|
|
28
|
+
$set: versionData
|
|
29
|
+
}, {
|
|
30
|
+
...optionsArgs,
|
|
31
|
+
projection: buildProjectionFromSelect({
|
|
32
|
+
adapter: this,
|
|
33
|
+
fields,
|
|
34
|
+
select
|
|
35
|
+
}),
|
|
36
|
+
returnDocument: 'after',
|
|
37
|
+
session
|
|
38
|
+
});
|
|
39
|
+
transform({
|
|
40
|
+
adapter: this,
|
|
41
|
+
data: doc,
|
|
42
|
+
fields,
|
|
43
|
+
operation: 'read'
|
|
34
44
|
});
|
|
35
|
-
|
|
36
|
-
const result = JSON.parse(JSON.stringify(doc));
|
|
37
|
-
const verificationToken = doc._verificationToken;
|
|
38
|
-
// custom id type reset
|
|
39
|
-
result.id = result._id;
|
|
40
|
-
if (verificationToken) {
|
|
41
|
-
result._verificationToken = verificationToken;
|
|
42
|
-
}
|
|
43
|
-
return result;
|
|
45
|
+
return doc;
|
|
44
46
|
}
|
|
45
47
|
|
|
46
48
|
//# sourceMappingURL=updateGlobalVersion.js.map
|