@payloadcms/db-mongodb 3.1.1-canary.c40ff01 → 3.1.1
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/deleteOne.js +1 -1
- package/dist/deleteOne.js.map +1 -1
- package/dist/find.js +2 -2
- package/dist/find.js.map +1 -1
- package/dist/findGlobal.js +1 -1
- package/dist/findGlobal.js.map +1 -1
- package/dist/findGlobalVersions.d.ts.map +1 -1
- package/dist/findGlobalVersions.js +1 -1
- package/dist/findGlobalVersions.js.map +1 -1
- package/dist/findOne.js +1 -1
- package/dist/findOne.js.map +1 -1
- package/dist/findVersions.js +2 -2
- package/dist/findVersions.js.map +1 -1
- package/dist/init.d.ts.map +1 -1
- package/dist/init.js +2 -2
- package/dist/init.js.map +1 -1
- package/dist/predefinedMigrations/migrateRelationshipsV2_V3.d.ts.map +1 -1
- package/dist/predefinedMigrations/migrateRelationshipsV2_V3.js +15 -12
- package/dist/predefinedMigrations/migrateRelationshipsV2_V3.js.map +1 -1
- package/dist/queries/buildAndOrConditions.d.ts +2 -2
- package/dist/queries/buildAndOrConditions.d.ts.map +1 -1
- package/dist/queries/buildAndOrConditions.js.map +1 -1
- package/dist/queries/buildQuery.d.ts +2 -2
- package/dist/queries/buildQuery.d.ts.map +1 -1
- package/dist/queries/buildQuery.js +2 -2
- package/dist/queries/buildQuery.js.map +1 -1
- package/dist/queries/buildSearchParams.d.ts +2 -2
- package/dist/queries/buildSearchParams.d.ts.map +1 -1
- package/dist/queries/buildSearchParams.js +1 -1
- package/dist/queries/buildSearchParams.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.map +1 -1
- package/dist/queries/getLocalizedSortProperty.d.ts +3 -3
- package/dist/queries/getLocalizedSortProperty.d.ts.map +1 -1
- package/dist/queries/getLocalizedSortProperty.js +3 -6
- package/dist/queries/getLocalizedSortProperty.js.map +1 -1
- package/dist/queries/getLocalizedSortProperty.spec.js +83 -73
- package/dist/queries/getLocalizedSortProperty.spec.js.map +1 -1
- package/dist/queries/parseParams.d.ts +2 -2
- package/dist/queries/parseParams.d.ts.map +1 -1
- package/dist/queries/parseParams.js.map +1 -1
- package/dist/queries/sanitizeQueryValue.d.ts +2 -2
- package/dist/queries/sanitizeQueryValue.d.ts.map +1 -1
- package/dist/queries/sanitizeQueryValue.js +2 -2
- package/dist/queries/sanitizeQueryValue.js.map +1 -1
- package/dist/queryDrafts.js +2 -2
- package/dist/queryDrafts.js.map +1 -1
- package/dist/updateGlobal.d.ts.map +1 -1
- package/dist/updateGlobal.js +1 -1
- package/dist/updateGlobal.js.map +1 -1
- package/dist/updateGlobalVersion.d.ts.map +1 -1
- package/dist/updateGlobalVersion.js +3 -2
- package/dist/updateGlobalVersion.js.map +1 -1
- package/dist/updateOne.d.ts.map +1 -1
- package/dist/updateOne.js +1 -1
- package/dist/updateOne.js.map +1 -1
- package/dist/updateVersion.d.ts.map +1 -1
- package/dist/updateVersion.js +1 -1
- package/dist/updateVersion.js.map +1 -1
- package/dist/utilities/buildJoinAggregation.js +1 -1
- package/dist/utilities/buildJoinAggregation.js.map +1 -1
- package/dist/utilities/buildProjectionFromSelect.d.ts +2 -2
- package/dist/utilities/buildProjectionFromSelect.d.ts.map +1 -1
- package/dist/utilities/buildProjectionFromSelect.js +5 -37
- package/dist/utilities/buildProjectionFromSelect.js.map +1 -1
- package/dist/utilities/sanitizeRelationshipIDs.d.ts.map +1 -1
- package/dist/utilities/sanitizeRelationshipIDs.js +8 -8
- package/dist/utilities/sanitizeRelationshipIDs.js.map +1 -1
- package/dist/utilities/sanitizeRelationshipIDs.spec.js +17 -0
- package/dist/utilities/sanitizeRelationshipIDs.spec.js.map +1 -1
- package/package.json +3 -3
@@ -1,8 +1,8 @@
|
|
1
1
|
import type { PaginateOptions } from 'mongoose';
|
2
|
-
import type {
|
2
|
+
import type { FlattenedField, SanitizedConfig, Sort } from 'payload';
|
3
3
|
type Args = {
|
4
4
|
config: SanitizedConfig;
|
5
|
-
fields:
|
5
|
+
fields: FlattenedField[];
|
6
6
|
locale: string;
|
7
7
|
sort: Sort;
|
8
8
|
timestamps: boolean;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"buildSortParam.d.ts","sourceRoot":"","sources":["../../src/queries/buildSortParam.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAC/C,OAAO,KAAK,EAAE,
|
1
|
+
{"version":3,"file":"buildSortParam.d.ts","sourceRoot":"","sources":["../../src/queries/buildSortParam.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAC/C,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAIpE,KAAK,IAAI,GAAG;IACV,MAAM,EAAE,eAAe,CAAA;IACvB,MAAM,EAAE,cAAc,EAAE,CAAA;IACxB,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,EAAE,IAAI,CAAA;IACV,UAAU,EAAE,OAAO,CAAA;CACpB,CAAA;AAED,MAAM,MAAM,QAAQ,GAAG;IACrB,SAAS,EAAE,aAAa,CAAA;IACxB,QAAQ,EAAE,MAAM,CAAA;CACjB,EAAE,CAAA;AAEH,MAAM,MAAM,aAAa,GAAG,KAAK,GAAG,MAAM,CAAA;AAE1C,eAAO,MAAM,cAAc,kDAMxB,IAAI,KAAG,eAAe,CAAC,MAAM,CAsC/B,CAAA"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/queries/buildSortParam.ts"],"sourcesContent":["import type { PaginateOptions } from 'mongoose'\nimport type {
|
1
|
+
{"version":3,"sources":["../../src/queries/buildSortParam.ts"],"sourcesContent":["import type { PaginateOptions } from 'mongoose'\nimport type { FlattenedField, SanitizedConfig, Sort } from 'payload'\n\nimport { getLocalizedSortProperty } from './getLocalizedSortProperty.js'\n\ntype Args = {\n config: SanitizedConfig\n fields: FlattenedField[]\n locale: string\n sort: Sort\n timestamps: boolean\n}\n\nexport type SortArgs = {\n direction: SortDirection\n property: string\n}[]\n\nexport type SortDirection = 'asc' | 'desc'\n\nexport const buildSortParam = ({\n config,\n fields,\n locale,\n sort,\n timestamps,\n}: Args): PaginateOptions['sort'] => {\n if (!sort) {\n if (timestamps) {\n sort = '-createdAt'\n } else {\n sort = '-id'\n }\n }\n\n if (typeof sort === 'string') {\n sort = [sort]\n }\n\n const sorting = sort.reduce<PaginateOptions['sort']>((acc, item) => {\n let sortProperty: string\n let sortDirection: SortDirection\n if (item.indexOf('-') === 0) {\n sortProperty = item.substring(1)\n sortDirection = 'desc'\n } else {\n sortProperty = item\n sortDirection = 'asc'\n }\n if (sortProperty === 'id') {\n acc['_id'] = sortDirection\n return acc\n }\n const localizedProperty = getLocalizedSortProperty({\n config,\n fields,\n locale,\n segments: sortProperty.split('.'),\n })\n acc[localizedProperty] = sortDirection\n return acc\n }, {})\n\n return sorting\n}\n"],"names":["getLocalizedSortProperty","buildSortParam","config","fields","locale","sort","timestamps","sorting","reduce","acc","item","sortProperty","sortDirection","indexOf","substring","localizedProperty","segments","split"],"mappings":"AAGA,SAASA,wBAAwB,QAAQ,gCAA+B;AAiBxE,OAAO,MAAMC,iBAAiB,CAAC,EAC7BC,MAAM,EACNC,MAAM,EACNC,MAAM,EACNC,IAAI,EACJC,UAAU,EACL;IACL,IAAI,CAACD,MAAM;QACT,IAAIC,YAAY;YACdD,OAAO;QACT,OAAO;YACLA,OAAO;QACT;IACF;IAEA,IAAI,OAAOA,SAAS,UAAU;QAC5BA,OAAO;YAACA;SAAK;IACf;IAEA,MAAME,UAAUF,KAAKG,MAAM,CAA0B,CAACC,KAAKC;QACzD,IAAIC;QACJ,IAAIC;QACJ,IAAIF,KAAKG,OAAO,CAAC,SAAS,GAAG;YAC3BF,eAAeD,KAAKI,SAAS,CAAC;YAC9BF,gBAAgB;QAClB,OAAO;YACLD,eAAeD;YACfE,gBAAgB;QAClB;QACA,IAAID,iBAAiB,MAAM;YACzBF,GAAG,CAAC,MAAM,GAAGG;YACb,OAAOH;QACT;QACA,MAAMM,oBAAoBf,yBAAyB;YACjDE;YACAC;YACAC;YACAY,UAAUL,aAAaM,KAAK,CAAC;QAC/B;QACAR,GAAG,CAACM,kBAAkB,GAAGH;QACzB,OAAOH;IACT,GAAG,CAAC;IAEJ,OAAOF;AACT,EAAC"}
|
@@ -1,11 +1,11 @@
|
|
1
|
-
import type {
|
1
|
+
import type { FlattenedField, SanitizedConfig } from 'payload';
|
2
2
|
type Args = {
|
3
3
|
config: SanitizedConfig;
|
4
|
-
fields:
|
4
|
+
fields: FlattenedField[];
|
5
5
|
locale: string;
|
6
6
|
result?: string;
|
7
7
|
segments: string[];
|
8
8
|
};
|
9
|
-
export declare const getLocalizedSortProperty: ({ config, fields
|
9
|
+
export declare const getLocalizedSortProperty: ({ config, fields, locale, result: incomingResult, segments: incomingSegments, }: Args) => string;
|
10
10
|
export {};
|
11
11
|
//# sourceMappingURL=getLocalizedSortProperty.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"getLocalizedSortProperty.d.ts","sourceRoot":"","sources":["../../src/queries/getLocalizedSortProperty.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
1
|
+
{"version":3,"file":"getLocalizedSortProperty.d.ts","sourceRoot":"","sources":["../../src/queries/getLocalizedSortProperty.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAI9D,KAAK,IAAI,GAAG;IACV,MAAM,EAAE,eAAe,CAAA;IACvB,MAAM,EAAE,cAAc,EAAE,CAAA;IACxB,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,QAAQ,EAAE,MAAM,EAAE,CAAA;CACnB,CAAA;AAED,eAAO,MAAM,wBAAwB,oFAMlC,IAAI,KAAG,MA+ET,CAAA"}
|
@@ -1,13 +1,10 @@
|
|
1
|
-
import { flattenTopLevelFields } from 'payload';
|
2
1
|
import { fieldAffectsData, fieldIsPresentationalOnly } from 'payload/shared';
|
3
|
-
export const getLocalizedSortProperty = ({ config, fields
|
2
|
+
export const getLocalizedSortProperty = ({ config, fields, locale, result: incomingResult, segments: incomingSegments })=>{
|
4
3
|
// If localization is not enabled, accept exactly
|
5
4
|
// what is sent in
|
6
5
|
if (!config.localization) {
|
7
6
|
return incomingSegments.join('.');
|
8
7
|
}
|
9
|
-
// Flatten incoming fields (row, etc)
|
10
|
-
const fields = flattenTopLevelFields(incomingFields);
|
11
8
|
const segments = [
|
12
9
|
...incomingSegments
|
13
10
|
];
|
@@ -38,13 +35,13 @@ export const getLocalizedSortProperty = ({ config, fields: incomingFields, local
|
|
38
35
|
}
|
39
36
|
// If there are subfields, pass them through
|
40
37
|
if (matchedField.type === 'tab' || matchedField.type === 'group' || matchedField.type === 'array') {
|
41
|
-
nextFields = matchedField.
|
38
|
+
nextFields = matchedField.flattenedFields;
|
42
39
|
}
|
43
40
|
if (matchedField.type === 'blocks') {
|
44
41
|
nextFields = matchedField.blocks.reduce((flattenedBlockFields, block)=>{
|
45
42
|
return [
|
46
43
|
...flattenedBlockFields,
|
47
|
-
...block.
|
44
|
+
...block.flattenedFields.filter((blockField)=>fieldAffectsData(blockField) && blockField.name !== 'blockType' && blockField.name !== 'blockName' || !fieldAffectsData(blockField))
|
48
45
|
];
|
49
46
|
}, []);
|
50
47
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/queries/getLocalizedSortProperty.ts"],"sourcesContent":["import type {
|
1
|
+
{"version":3,"sources":["../../src/queries/getLocalizedSortProperty.ts"],"sourcesContent":["import type { FlattenedField, SanitizedConfig } from 'payload'\n\nimport { fieldAffectsData, fieldIsPresentationalOnly } from 'payload/shared'\n\ntype Args = {\n config: SanitizedConfig\n fields: FlattenedField[]\n locale: string\n result?: string\n segments: string[]\n}\n\nexport const getLocalizedSortProperty = ({\n config,\n fields,\n locale,\n result: incomingResult,\n segments: incomingSegments,\n}: Args): string => {\n // If localization is not enabled, accept exactly\n // what is sent in\n if (!config.localization) {\n return incomingSegments.join('.')\n }\n\n const segments = [...incomingSegments]\n\n // Retrieve first segment, and remove from segments\n const firstSegment = segments.shift()\n\n // Attempt to find a matched field\n const matchedField = fields.find(\n (field) => fieldAffectsData(field) && field.name === firstSegment,\n )\n\n if (matchedField && !fieldIsPresentationalOnly(matchedField)) {\n let nextFields: FlattenedField[]\n const remainingSegments = [...segments]\n let localizedSegment = matchedField.name\n\n if (matchedField.localized) {\n // Check to see if next segment is a locale\n if (segments.length > 0) {\n const nextSegmentIsLocale = config.localization.localeCodes.includes(remainingSegments[0])\n\n // If next segment is locale, remove it from remaining segments\n // and use it to localize the current segment\n if (nextSegmentIsLocale) {\n const nextSegment = remainingSegments.shift()\n localizedSegment = `${matchedField.name}.${nextSegment}`\n }\n } else {\n // If no more segments, but field is localized, use default locale\n localizedSegment = `${matchedField.name}.${locale}`\n }\n }\n\n // If there are subfields, pass them through\n if (\n matchedField.type === 'tab' ||\n matchedField.type === 'group' ||\n matchedField.type === 'array'\n ) {\n nextFields = matchedField.flattenedFields\n }\n\n if (matchedField.type === 'blocks') {\n nextFields = matchedField.blocks.reduce((flattenedBlockFields, block) => {\n return [\n ...flattenedBlockFields,\n ...block.flattenedFields.filter(\n (blockField) =>\n (fieldAffectsData(blockField) &&\n blockField.name !== 'blockType' &&\n blockField.name !== 'blockName') ||\n !fieldAffectsData(blockField),\n ),\n ]\n }, [])\n }\n\n const result = incomingResult ? `${incomingResult}.${localizedSegment}` : localizedSegment\n\n if (nextFields) {\n return getLocalizedSortProperty({\n config,\n fields: nextFields,\n locale,\n result,\n segments: remainingSegments,\n })\n }\n\n return result\n }\n\n return incomingSegments.join('.')\n}\n"],"names":["fieldAffectsData","fieldIsPresentationalOnly","getLocalizedSortProperty","config","fields","locale","result","incomingResult","segments","incomingSegments","localization","join","firstSegment","shift","matchedField","find","field","name","nextFields","remainingSegments","localizedSegment","localized","length","nextSegmentIsLocale","localeCodes","includes","nextSegment","type","flattenedFields","blocks","reduce","flattenedBlockFields","block","filter","blockField"],"mappings":"AAEA,SAASA,gBAAgB,EAAEC,yBAAyB,QAAQ,iBAAgB;AAU5E,OAAO,MAAMC,2BAA2B,CAAC,EACvCC,MAAM,EACNC,MAAM,EACNC,MAAM,EACNC,QAAQC,cAAc,EACtBC,UAAUC,gBAAgB,EACrB;IACL,iDAAiD;IACjD,kBAAkB;IAClB,IAAI,CAACN,OAAOO,YAAY,EAAE;QACxB,OAAOD,iBAAiBE,IAAI,CAAC;IAC/B;IAEA,MAAMH,WAAW;WAAIC;KAAiB;IAEtC,mDAAmD;IACnD,MAAMG,eAAeJ,SAASK,KAAK;IAEnC,kCAAkC;IAClC,MAAMC,eAAeV,OAAOW,IAAI,CAC9B,CAACC,QAAUhB,iBAAiBgB,UAAUA,MAAMC,IAAI,KAAKL;IAGvD,IAAIE,gBAAgB,CAACb,0BAA0Ba,eAAe;QAC5D,IAAII;QACJ,MAAMC,oBAAoB;eAAIX;SAAS;QACvC,IAAIY,mBAAmBN,aAAaG,IAAI;QAExC,IAAIH,aAAaO,SAAS,EAAE;YAC1B,2CAA2C;YAC3C,IAAIb,SAASc,MAAM,GAAG,GAAG;gBACvB,MAAMC,sBAAsBpB,OAAOO,YAAY,CAACc,WAAW,CAACC,QAAQ,CAACN,iBAAiB,CAAC,EAAE;gBAEzF,+DAA+D;gBAC/D,6CAA6C;gBAC7C,IAAII,qBAAqB;oBACvB,MAAMG,cAAcP,kBAAkBN,KAAK;oBAC3CO,mBAAmB,CAAC,EAAEN,aAAaG,IAAI,CAAC,CAAC,EAAES,YAAY,CAAC;gBAC1D;YACF,OAAO;gBACL,kEAAkE;gBAClEN,mBAAmB,CAAC,EAAEN,aAAaG,IAAI,CAAC,CAAC,EAAEZ,OAAO,CAAC;YACrD;QACF;QAEA,4CAA4C;QAC5C,IACES,aAAaa,IAAI,KAAK,SACtBb,aAAaa,IAAI,KAAK,WACtBb,aAAaa,IAAI,KAAK,SACtB;YACAT,aAAaJ,aAAac,eAAe;QAC3C;QAEA,IAAId,aAAaa,IAAI,KAAK,UAAU;YAClCT,aAAaJ,aAAae,MAAM,CAACC,MAAM,CAAC,CAACC,sBAAsBC;gBAC7D,OAAO;uBACFD;uBACAC,MAAMJ,eAAe,CAACK,MAAM,CAC7B,CAACC,aACC,AAAClC,iBAAiBkC,eAChBA,WAAWjB,IAAI,KAAK,eACpBiB,WAAWjB,IAAI,KAAK,eACtB,CAACjB,iBAAiBkC;iBAEvB;YACH,GAAG,EAAE;QACP;QAEA,MAAM5B,SAASC,iBAAiB,CAAC,EAAEA,eAAe,CAAC,EAAEa,iBAAiB,CAAC,GAAGA;QAE1E,IAAIF,YAAY;YACd,OAAOhB,yBAAyB;gBAC9BC;gBACAC,QAAQc;gBACRb;gBACAC;gBACAE,UAAUW;YACZ;QACF;QAEA,OAAOb;IACT;IAEA,OAAOG,iBAAiBE,IAAI,CAAC;AAC/B,EAAC"}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { sanitizeConfig } from 'payload';
|
1
|
+
import { flattenAllFields, sanitizeConfig } from 'payload';
|
2
2
|
import { getLocalizedSortProperty } from './getLocalizedSortProperty.js';
|
3
3
|
let config;
|
4
4
|
describe('get localized sort property', ()=>{
|
@@ -68,19 +68,21 @@ describe('get localized sort property', ()=>{
|
|
68
68
|
it('properly localizes nested sort properties', ()=>{
|
69
69
|
const result = getLocalizedSortProperty({
|
70
70
|
config,
|
71
|
-
fields:
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
71
|
+
fields: flattenAllFields({
|
72
|
+
fields: [
|
73
|
+
{
|
74
|
+
name: 'group',
|
75
|
+
type: 'group',
|
76
|
+
fields: [
|
77
|
+
{
|
78
|
+
name: 'title',
|
79
|
+
type: 'text',
|
80
|
+
localized: true
|
81
|
+
}
|
82
|
+
]
|
83
|
+
}
|
84
|
+
]
|
85
|
+
}),
|
84
86
|
locale: 'en',
|
85
87
|
segments: [
|
86
88
|
'group',
|
@@ -92,19 +94,21 @@ describe('get localized sort property', ()=>{
|
|
92
94
|
it('keeps requested locale with nested sort properties', ()=>{
|
93
95
|
const result = getLocalizedSortProperty({
|
94
96
|
config,
|
95
|
-
fields:
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
97
|
+
fields: flattenAllFields({
|
98
|
+
fields: [
|
99
|
+
{
|
100
|
+
name: 'group',
|
101
|
+
type: 'group',
|
102
|
+
fields: [
|
103
|
+
{
|
104
|
+
name: 'title',
|
105
|
+
type: 'text',
|
106
|
+
localized: true
|
107
|
+
}
|
108
|
+
]
|
109
|
+
}
|
110
|
+
]
|
111
|
+
}),
|
108
112
|
locale: 'en',
|
109
113
|
segments: [
|
110
114
|
'group',
|
@@ -117,18 +121,20 @@ describe('get localized sort property', ()=>{
|
|
117
121
|
it('properly localizes field within row', ()=>{
|
118
122
|
const result = getLocalizedSortProperty({
|
119
123
|
config,
|
120
|
-
fields:
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
124
|
+
fields: flattenAllFields({
|
125
|
+
fields: [
|
126
|
+
{
|
127
|
+
type: 'row',
|
128
|
+
fields: [
|
129
|
+
{
|
130
|
+
name: 'title',
|
131
|
+
type: 'text',
|
132
|
+
localized: true
|
133
|
+
}
|
134
|
+
]
|
135
|
+
}
|
136
|
+
]
|
137
|
+
}),
|
132
138
|
locale: 'en',
|
133
139
|
segments: [
|
134
140
|
'title'
|
@@ -139,23 +145,25 @@ describe('get localized sort property', ()=>{
|
|
139
145
|
it('properly localizes field within named tab', ()=>{
|
140
146
|
const result = getLocalizedSortProperty({
|
141
147
|
config,
|
142
|
-
fields:
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
148
|
+
fields: flattenAllFields({
|
149
|
+
fields: [
|
150
|
+
{
|
151
|
+
type: 'tabs',
|
152
|
+
tabs: [
|
153
|
+
{
|
154
|
+
name: 'tab',
|
155
|
+
fields: [
|
156
|
+
{
|
157
|
+
name: 'title',
|
158
|
+
type: 'text',
|
159
|
+
localized: true
|
160
|
+
}
|
161
|
+
]
|
162
|
+
}
|
163
|
+
]
|
164
|
+
}
|
165
|
+
]
|
166
|
+
}),
|
159
167
|
locale: 'en',
|
160
168
|
segments: [
|
161
169
|
'tab',
|
@@ -167,23 +175,25 @@ describe('get localized sort property', ()=>{
|
|
167
175
|
it('properly localizes field within unnamed tab', ()=>{
|
168
176
|
const result = getLocalizedSortProperty({
|
169
177
|
config,
|
170
|
-
fields:
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
178
|
+
fields: flattenAllFields({
|
179
|
+
fields: [
|
180
|
+
{
|
181
|
+
type: 'tabs',
|
182
|
+
tabs: [
|
183
|
+
{
|
184
|
+
fields: [
|
185
|
+
{
|
186
|
+
name: 'title',
|
187
|
+
type: 'text',
|
188
|
+
localized: true
|
189
|
+
}
|
190
|
+
],
|
191
|
+
label: 'Tab'
|
192
|
+
}
|
193
|
+
]
|
194
|
+
}
|
195
|
+
]
|
196
|
+
}),
|
187
197
|
locale: 'en',
|
188
198
|
segments: [
|
189
199
|
'title'
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/queries/getLocalizedSortProperty.spec.ts"],"sourcesContent":["import type { Config, SanitizedConfig } from 'payload'\n\nimport { sanitizeConfig } from 'payload'\n\nimport { getLocalizedSortProperty } from './getLocalizedSortProperty.js'\n\nlet config: SanitizedConfig\n\ndescribe('get localized sort property', () => {\n beforeAll(async () => {\n config = await sanitizeConfig({\n localization: {\n defaultLocale: 'en',\n fallback: true,\n locales: ['en', 'es'],\n },\n } as Config)\n })\n it('passes through a non-localized sort property', () => {\n const result = getLocalizedSortProperty({\n config,\n fields: [\n {\n name: 'title',\n type: 'text',\n },\n ],\n locale: 'en',\n segments: ['title'],\n })\n\n expect(result).toStrictEqual('title')\n })\n\n it('properly localizes an un-localized sort property', () => {\n const result = getLocalizedSortProperty({\n config,\n fields: [\n {\n name: 'title',\n type: 'text',\n localized: true,\n },\n ],\n locale: 'en',\n segments: ['title'],\n })\n\n expect(result).toStrictEqual('title.en')\n })\n\n it('keeps specifically asked-for localized sort properties', () => {\n const result = getLocalizedSortProperty({\n config,\n fields: [\n {\n name: 'title',\n type: 'text',\n localized: true,\n },\n ],\n locale: 'en',\n segments: ['title', 'es'],\n })\n\n expect(result).toStrictEqual('title.es')\n })\n\n it('properly localizes nested sort properties', () => {\n const result = getLocalizedSortProperty({\n config,\n fields: [\n
|
1
|
+
{"version":3,"sources":["../../src/queries/getLocalizedSortProperty.spec.ts"],"sourcesContent":["import type { Config, SanitizedConfig } from 'payload'\n\nimport { flattenAllFields, sanitizeConfig } from 'payload'\n\nimport { getLocalizedSortProperty } from './getLocalizedSortProperty.js'\n\nlet config: SanitizedConfig\n\ndescribe('get localized sort property', () => {\n beforeAll(async () => {\n config = await sanitizeConfig({\n localization: {\n defaultLocale: 'en',\n fallback: true,\n locales: ['en', 'es'],\n },\n } as Config)\n })\n it('passes through a non-localized sort property', () => {\n const result = getLocalizedSortProperty({\n config,\n fields: [\n {\n name: 'title',\n type: 'text',\n },\n ],\n locale: 'en',\n segments: ['title'],\n })\n\n expect(result).toStrictEqual('title')\n })\n\n it('properly localizes an un-localized sort property', () => {\n const result = getLocalizedSortProperty({\n config,\n fields: [\n {\n name: 'title',\n type: 'text',\n localized: true,\n },\n ],\n locale: 'en',\n segments: ['title'],\n })\n\n expect(result).toStrictEqual('title.en')\n })\n\n it('keeps specifically asked-for localized sort properties', () => {\n const result = getLocalizedSortProperty({\n config,\n fields: [\n {\n name: 'title',\n type: 'text',\n localized: true,\n },\n ],\n locale: 'en',\n segments: ['title', 'es'],\n })\n\n expect(result).toStrictEqual('title.es')\n })\n\n it('properly localizes nested sort properties', () => {\n const result = getLocalizedSortProperty({\n config,\n fields: flattenAllFields({\n fields: [\n {\n name: 'group',\n type: 'group',\n fields: [\n {\n name: 'title',\n type: 'text',\n localized: true,\n },\n ],\n },\n ],\n }),\n locale: 'en',\n segments: ['group', 'title'],\n })\n\n expect(result).toStrictEqual('group.title.en')\n })\n\n it('keeps requested locale with nested sort properties', () => {\n const result = getLocalizedSortProperty({\n config,\n fields: flattenAllFields({\n fields: [\n {\n name: 'group',\n type: 'group',\n fields: [\n {\n name: 'title',\n type: 'text',\n localized: true,\n },\n ],\n },\n ],\n }),\n locale: 'en',\n segments: ['group', 'title', 'es'],\n })\n\n expect(result).toStrictEqual('group.title.es')\n })\n\n it('properly localizes field within row', () => {\n const result = getLocalizedSortProperty({\n config,\n fields: flattenAllFields({\n fields: [\n {\n type: 'row',\n fields: [\n {\n name: 'title',\n type: 'text',\n localized: true,\n },\n ],\n },\n ],\n }),\n locale: 'en',\n segments: ['title'],\n })\n\n expect(result).toStrictEqual('title.en')\n })\n\n it('properly localizes field within named tab', () => {\n const result = getLocalizedSortProperty({\n config,\n fields: flattenAllFields({\n fields: [\n {\n type: 'tabs',\n tabs: [\n {\n name: 'tab',\n fields: [\n {\n name: 'title',\n type: 'text',\n localized: true,\n },\n ],\n },\n ],\n },\n ],\n }),\n locale: 'en',\n segments: ['tab', 'title'],\n })\n\n expect(result).toStrictEqual('tab.title.en')\n })\n\n it('properly localizes field within unnamed tab', () => {\n const result = getLocalizedSortProperty({\n config,\n fields: flattenAllFields({\n fields: [\n {\n type: 'tabs',\n tabs: [\n {\n fields: [\n {\n name: 'title',\n type: 'text',\n localized: true,\n },\n ],\n label: 'Tab',\n },\n ],\n },\n ],\n }),\n locale: 'en',\n segments: ['title'],\n })\n\n expect(result).toStrictEqual('title.en')\n })\n})\n"],"names":["flattenAllFields","sanitizeConfig","getLocalizedSortProperty","config","describe","beforeAll","localization","defaultLocale","fallback","locales","it","result","fields","name","type","locale","segments","expect","toStrictEqual","localized","tabs","label"],"mappings":"AAEA,SAASA,gBAAgB,EAAEC,cAAc,QAAQ,UAAS;AAE1D,SAASC,wBAAwB,QAAQ,gCAA+B;AAExE,IAAIC;AAEJC,SAAS,+BAA+B;IACtCC,UAAU;QACRF,SAAS,MAAMF,eAAe;YAC5BK,cAAc;gBACZC,eAAe;gBACfC,UAAU;gBACVC,SAAS;oBAAC;oBAAM;iBAAK;YACvB;QACF;IACF;IACAC,GAAG,gDAAgD;QACjD,MAAMC,SAAST,yBAAyB;YACtCC;YACAS,QAAQ;gBACN;oBACEC,MAAM;oBACNC,MAAM;gBACR;aACD;YACDC,QAAQ;YACRC,UAAU;gBAAC;aAAQ;QACrB;QAEAC,OAAON,QAAQO,aAAa,CAAC;IAC/B;IAEAR,GAAG,oDAAoD;QACrD,MAAMC,SAAST,yBAAyB;YACtCC;YACAS,QAAQ;gBACN;oBACEC,MAAM;oBACNC,MAAM;oBACNK,WAAW;gBACb;aACD;YACDJ,QAAQ;YACRC,UAAU;gBAAC;aAAQ;QACrB;QAEAC,OAAON,QAAQO,aAAa,CAAC;IAC/B;IAEAR,GAAG,0DAA0D;QAC3D,MAAMC,SAAST,yBAAyB;YACtCC;YACAS,QAAQ;gBACN;oBACEC,MAAM;oBACNC,MAAM;oBACNK,WAAW;gBACb;aACD;YACDJ,QAAQ;YACRC,UAAU;gBAAC;gBAAS;aAAK;QAC3B;QAEAC,OAAON,QAAQO,aAAa,CAAC;IAC/B;IAEAR,GAAG,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AAa,CAAC;IAC/B;IAEAR,GAAG,+CAA+C;QAChD,MAAMC,SAAST,yBAAyB;YACtCC;YACAS,QAAQZ,iBAAiB;gBACvBY,QAAQ;oBACN;wBACEE,MAAM;wBACNM,MAAM;4BACJ;gCACER,QAAQ;oCACN;wCACEC,MAAM;wCACNC,MAAM;wCACNK,WAAW;oCACb;iCACD;gCACDE,OAAO;4BACT;yBACD;oBACH;iBACD;YACH;YACAN,QAAQ;YACRC,UAAU;gBAAC;aAAQ;QACrB;QAEAC,OAAON,QAAQO,aAAa,CAAC;IAC/B;AACF"}
|
@@ -1,7 +1,7 @@
|
|
1
|
-
import type {
|
1
|
+
import type { FlattenedField, Payload, Where } from 'payload';
|
2
2
|
export declare function parseParams({ collectionSlug, fields, globalSlug, locale, payload, where, }: {
|
3
3
|
collectionSlug?: string;
|
4
|
-
fields:
|
4
|
+
fields: FlattenedField[];
|
5
5
|
globalSlug?: string;
|
6
6
|
locale: string;
|
7
7
|
payload: Payload;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"parseParams.d.ts","sourceRoot":"","sources":["../../src/queries/parseParams.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,
|
1
|
+
{"version":3,"file":"parseParams.d.ts","sourceRoot":"","sources":["../../src/queries/parseParams.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAY,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAQvE,wBAAsB,WAAW,CAAC,EAChC,cAAc,EACd,MAAM,EACN,UAAU,EACV,MAAM,EACN,OAAO,EACP,KAAK,GACN,EAAE;IACD,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,MAAM,EAAE,cAAc,EAAE,CAAA;IACxB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,EAAE,OAAO,CAAA;IAChB,KAAK,EAAE,KAAK,CAAA;CACb,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CA+DnC"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/queries/parseParams.ts"],"sourcesContent":["import type { FilterQuery } from 'mongoose'\nimport type {
|
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":"AAGA,SAASA,2BAA2B,QAAQ,UAAS;AACrD,SAASC,cAAc,QAAQ,iBAAgB;AAE/C,SAASC,oBAAoB,QAAQ,4BAA2B;AAChE,SAASC,gBAAgB,QAAQ,yBAAwB;AAEzD,OAAO,eAAeC,YAAY,EAChCC,cAAc,EACdC,MAAM,EACNC,UAAU,EACVC,MAAM,EACNC,OAAO,EACPC,KAAK,EAQN;IACC,IAAIC,SAAS,CAAC;IAEd,IAAI,OAAOD,UAAU,UAAU;QAC7B,uEAAuE;QACvE,KAAK,MAAME,kBAAkBC,OAAOC,IAAI,CAACJ,OAAQ;YAC/C,MAAMK,YAAYL,KAAK,CAACE,eAAe;YACvC,IAAII;YACJ,IAAIJ,eAAeK,WAAW,OAAO,OAAO;gBAC1CD,oBAAoB;YACtB,OAAO,IAAIJ,eAAeK,WAAW,OAAO,MAAM;gBAChDD,oBAAoB;YACtB;YACA,IAAIE,MAAMC,OAAO,CAACJ,YAAY;gBAC5B,MAAMK,kBAAkB,MAAMlB,qBAAqB;oBACjDG;oBACAC;oBACAC;oBACAC;oBACAC;oBACAC,OAAOK;gBACT;gBACA,IAAIK,gBAAgBC,MAAM,GAAG,GAAG;oBAC9BV,MAAM,CAACK,kBAAkB,GAAGI;gBAC9B;YACF,OAAO;gBACL,wEAAwE;gBACxE,kEAAkE;gBAClE,8EAA8E;gBAC9E,MAAME,gBAAgBZ,KAAK,CAACE,eAAe;gBAC3C,IAAI,OAAOU,kBAAkB,UAAU;oBACrC,KAAK,MAAMC,YAAYV,OAAOC,IAAI,CAACQ,eAAgB;wBACjD,IAAIrB,eAAeuB,QAAQ,CAACD,WAAuB;4BACjD,MAAME,cAAc,MAAMtB,iBAAiB;gCACzCE;gCACAC;gCACAC;gCACAmB,cAAcd;gCACdJ;gCACAe;gCACAd;gCACAkB,KAAKL,aAAa,CAACC,SAAS;4BAC9B;4BAEA,IAAIE,aAAaG,SAASH,aAAaI,MAAM;gCAC3ClB,SAAS;oCACP,GAAGA,MAAM;oCACT,CAACc,YAAYI,IAAI,CAAC,EAAEJ,YAAYG,KAAK;gCACvC;4BACF,OAAO,IAAI,OAAOH,aAAaG,UAAU,UAAU;gCACjDjB,SAASX,4BAA4BW,QAAQc,YAAYG,KAAK,EAAE;oCAC9D,6BAA6B;oCAC7BE,OAAO;gCACT;4BACF;wBACF;oBACF;gBACF;YACF;QACF;IACF;IAEA,OAAOnB;AACT"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"sanitizeQueryValue.d.ts","sourceRoot":"","sources":["../../src/queries/sanitizeQueryValue.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
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;AA6DD,eAAO,MAAM,kBAAkB,0DAO5B,sBAAsB,KAAG;IAC1B,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,GAAG,CAAC,EAAE,OAAO,CAAA;CAqTd,CAAA"}
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { Types } from 'mongoose';
|
2
|
-
import { createArrayFromCommaDelineated
|
2
|
+
import { createArrayFromCommaDelineated } from 'payload';
|
3
3
|
const buildExistsQuery = (formattedValue, path, treatEmptyString = true)=>{
|
4
4
|
if (formattedValue) {
|
5
5
|
return {
|
@@ -66,7 +66,7 @@ const getFieldFromSegments = ({ field, segments })=>{
|
|
66
66
|
}
|
67
67
|
if ('fields' in field) {
|
68
68
|
for(let i = 0; i < segments.length; i++){
|
69
|
-
const foundField =
|
69
|
+
const foundField = field.flattenedFields.find((each)=>each.name === segments[i]);
|
70
70
|
if (!foundField) {
|
71
71
|
break;
|
72
72
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/queries/sanitizeQueryValue.ts"],"sourcesContent":["import type { Block, Field, Payload, RelationshipField, TabAsField } from 'payload'\n\nimport { Types } from 'mongoose'\nimport { createArrayFromCommaDelineated, flattenTopLevelFields } from 'payload'\n\ntype SanitizeQueryValueArgs = {\n field: Field | TabAsField\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: Block | Field | TabAsField\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 = flattenTopLevelFields(field.fields).find(\n (each) => each.name === segments[i],\n )\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","flattenTopLevelFields","buildExistsQuery","formattedValue","path","treatEmptyString","rawQuery","$and","$exists","$ne","$or","$eq","getFieldFromSegments","field","segments","block","blocks","i","length","foundField","fields","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,EAAEC,qBAAqB,QAAQ,UAAS;AAW/E,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,6HAA6H;AAC7H,MAAMC,uBAAuB,CAAC,EAC5BC,KAAK,EACLC,QAAQ,EAIT;IACC,IAAI,YAAYD,OAAO;QACrB,KAAK,MAAME,SAASF,MAAMG,MAAM,CAAE;YAChC,MAAMH,QAAQD,qBAAqB;gBAAEC,OAAOE;gBAAOD;YAAS;YAC5D,IAAID,OAAO;gBACT,OAAOA;YACT;QACF;IACF;IAEA,IAAI,YAAYA,OAAO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BAAoB;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 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,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,6HAA6H;AAC7H,MAAMC,uBAAuB,CAAC,EAC5BC,KAAK,EACLC,QAAQ,EAIT;IACC,IAAI,YAAYD,OAAO;QACrB,KAAK,MAAME,SAASF,MAAMG,MAAM,CAAE;YAChC,MAAMH,QAAQD,qBAAq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,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"}
|
package/dist/queryDrafts.js
CHANGED
@@ -17,7 +17,7 @@ export const queryDrafts = async function queryDrafts({ collection, joins, limit
|
|
17
17
|
if (!hasNearConstraint) {
|
18
18
|
sort = buildSortParam({
|
19
19
|
config: this.payload.config,
|
20
|
-
fields: collectionConfig.
|
20
|
+
fields: collectionConfig.flattenedFields,
|
21
21
|
locale,
|
22
22
|
sort: sortArg || collectionConfig.defaultSort,
|
23
23
|
timestamps: true
|
@@ -35,7 +35,7 @@ export const queryDrafts = async function queryDrafts({ collection, joins, limit
|
|
35
35
|
});
|
36
36
|
const projection = buildProjectionFromSelect({
|
37
37
|
adapter: this,
|
38
|
-
fields: buildVersionCollectionFields(this.payload.config, collectionConfig),
|
38
|
+
fields: buildVersionCollectionFields(this.payload.config, collectionConfig, true),
|
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.
|
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 { 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.
|
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.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 where: combinedWhere,\n })\n\n const projection = buildProjectionFromSelect({\n adapter: this,\n fields: buildVersionCollectionFields(this.payload.config, collectionConfig, true),\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 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","flattenedFields","defaultSort","timestamps","combinedWhere","latest","equals","versionQuery","buildQuery","projection","adapter","useEstimatedCount","length","paginationOptions","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,MAA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