payload 4.0.0-internal.d28e9fb → 4.0.0-internal.e16cf59
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/collections/config/sanitize.d.ts.map +1 -1
- package/dist/collections/config/sanitize.js +222 -228
- package/dist/collections/config/sanitize.js.map +1 -1
- package/dist/config/sanitize.d.ts.map +1 -1
- package/dist/config/sanitize.js +233 -254
- package/dist/config/sanitize.js.map +1 -1
- package/dist/exports/internal.d.ts +0 -1
- package/dist/exports/internal.d.ts.map +1 -1
- package/dist/exports/internal.js +0 -1
- package/dist/exports/internal.js.map +1 -1
- package/dist/fields/config/sanitize.d.ts.map +1 -1
- package/dist/fields/config/sanitize.js +323 -334
- package/dist/fields/config/sanitize.js.map +1 -1
- package/dist/globals/config/sanitize.d.ts.map +1 -1
- package/dist/globals/config/sanitize.js +125 -131
- package/dist/globals/config/sanitize.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -19
- package/dist/index.js.map +1 -1
- package/dist/utilities/flattenAllFields.d.ts.map +1 -1
- package/dist/utilities/flattenAllFields.js +93 -102
- package/dist/utilities/flattenAllFields.js.map +1 -1
- package/package.json +2 -2
- package/dist/utilities/sanitizeProfiler.d.ts +0 -38
- package/dist/utilities/sanitizeProfiler.d.ts.map +0 -1
- package/dist/utilities/sanitizeProfiler.js +0 -101
- package/dist/utilities/sanitizeProfiler.js.map +0 -1
|
@@ -3,7 +3,6 @@ import { DuplicateFieldName, InvalidConfiguration, InvalidFieldName, InvalidFiel
|
|
|
3
3
|
import { ReservedFieldName } from '../../errors/ReservedFieldName.js';
|
|
4
4
|
import { flattenAllFields } from '../../utilities/flattenAllFields.js';
|
|
5
5
|
import { formatLabels, toWords } from '../../utilities/formatLabels.js';
|
|
6
|
-
import { endSpan, startSpan } from '../../utilities/sanitizeProfiler.js';
|
|
7
6
|
import { validateTimezones } from '../../utilities/validateTimezones.js';
|
|
8
7
|
import { baseBlockFields } from '../baseFields/baseBlockFields.js';
|
|
9
8
|
import { baseIDField } from '../baseFields/baseIDField.js';
|
|
@@ -28,394 +27,384 @@ import { fieldAffectsData as _fieldAffectsData, fieldIsLocalized, tabHasName } f
|
|
|
28
27
|
if ('_sanitized' in field && field._sanitized === true) {
|
|
29
28
|
return result;
|
|
30
29
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
30
|
+
if ('_sanitized' in field) {
|
|
31
|
+
field._sanitized = true;
|
|
32
|
+
}
|
|
33
|
+
if (!field.type) {
|
|
34
|
+
throw new MissingFieldType(field);
|
|
35
|
+
}
|
|
36
|
+
const fieldAffectsData = _fieldAffectsData(field);
|
|
37
|
+
const { indexPath, schemaPath } = getFieldPaths({
|
|
38
|
+
field,
|
|
39
|
+
index,
|
|
40
|
+
parentIndexPath,
|
|
41
|
+
parentSchemaPath
|
|
42
|
+
});
|
|
43
|
+
// Reserved field name checks
|
|
44
|
+
if (isTopLevelField && fieldAffectsData && field.name) {
|
|
45
|
+
if (collectionConfig && collectionConfig.upload) {
|
|
46
|
+
if (reservedBaseUploadFieldNames.includes(field.name)) {
|
|
47
|
+
throw new ReservedFieldName(field, field.name);
|
|
48
|
+
}
|
|
38
49
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
index,
|
|
43
|
-
parentIndexPath,
|
|
44
|
-
parentSchemaPath
|
|
45
|
-
});
|
|
46
|
-
// Reserved field name checks
|
|
47
|
-
if (isTopLevelField && fieldAffectsData && field.name) {
|
|
48
|
-
if (collectionConfig && collectionConfig.upload) {
|
|
49
|
-
if (reservedBaseUploadFieldNames.includes(field.name)) {
|
|
50
|
-
throw new ReservedFieldName(field, field.name);
|
|
51
|
-
}
|
|
50
|
+
if (collectionConfig && collectionConfig.auth && typeof collectionConfig.auth === 'object' && !collectionConfig.auth.disableLocalStrategy) {
|
|
51
|
+
if (reservedBaseAuthFieldNames.includes(field.name)) {
|
|
52
|
+
throw new ReservedFieldName(field, field.name);
|
|
52
53
|
}
|
|
53
|
-
if (collectionConfig
|
|
54
|
-
|
|
54
|
+
if (collectionConfig.auth.verify) {
|
|
55
|
+
// @ts-expect-error - vestiges of when tsconfig was not strict. Feel free to improve
|
|
56
|
+
if (reservedAPIKeyFieldNames.includes(field.name)) {
|
|
55
57
|
throw new ReservedFieldName(field, field.name);
|
|
56
58
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
throw new ReservedFieldName(field, field.name);
|
|
61
|
-
}
|
|
62
|
-
// @ts-expect-error - vestiges of when tsconfig was not strict. Feel free to improve
|
|
63
|
-
if (reservedVerifyFieldNames.includes(field.name)) {
|
|
64
|
-
throw new ReservedFieldName(field, field.name);
|
|
65
|
-
}
|
|
59
|
+
// @ts-expect-error - vestiges of when tsconfig was not strict. Feel free to improve
|
|
60
|
+
if (reservedVerifyFieldNames.includes(field.name)) {
|
|
61
|
+
throw new ReservedFieldName(field, field.name);
|
|
66
62
|
}
|
|
67
63
|
}
|
|
68
64
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
65
|
+
}
|
|
66
|
+
// Invalid field name check
|
|
67
|
+
if (fieldAffectsData && field.name.includes('.')) {
|
|
68
|
+
throw new InvalidFieldName(field, field.name);
|
|
69
|
+
}
|
|
70
|
+
// Auto-label
|
|
71
|
+
if ('name' in field && field.name && typeof field.label !== 'object' && typeof field.label !== 'string' && typeof field.label !== 'function' && field.label !== false) {
|
|
72
|
+
field.label = toWords(field.name);
|
|
73
|
+
}
|
|
74
|
+
// Checkbox default
|
|
75
|
+
if (field.type === 'checkbox' && typeof field.defaultValue === 'undefined' && field.required === true) {
|
|
76
|
+
field.defaultValue = false;
|
|
77
|
+
}
|
|
78
|
+
// Join field sanitization
|
|
79
|
+
if (field.type === 'join') {
|
|
80
|
+
sanitizeJoinField({
|
|
81
|
+
config,
|
|
82
|
+
field,
|
|
83
|
+
joinPath,
|
|
84
|
+
joins,
|
|
85
|
+
orderableJoins,
|
|
86
|
+
parentIsLocalized,
|
|
87
|
+
polymorphicJoins
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
// Relationship/upload validation
|
|
91
|
+
if (field.type === 'relationship' || field.type === 'upload') {
|
|
92
|
+
if (Array.isArray(field.relationTo) && field.relationTo.length === 0) {
|
|
93
|
+
throw new Error(`Field "${field.name}" of type "${field.type}" has an empty relationTo array. At least one collection must be specified.`);
|
|
72
94
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
95
|
+
if (validRelationships) {
|
|
96
|
+
const relationships = Array.isArray(field.relationTo) ? field.relationTo : [
|
|
97
|
+
field.relationTo
|
|
98
|
+
];
|
|
99
|
+
relationships.forEach((relationship)=>{
|
|
100
|
+
if (!validRelationships.includes(relationship)) {
|
|
101
|
+
throw new InvalidFieldRelationship(field, relationship);
|
|
102
|
+
}
|
|
103
|
+
});
|
|
76
104
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
105
|
+
}
|
|
106
|
+
// Upload isSortable default
|
|
107
|
+
if (field.type === 'upload') {
|
|
108
|
+
if (!field.admin || !('isSortable' in field.admin)) {
|
|
109
|
+
field.admin = {
|
|
110
|
+
isSortable: true,
|
|
111
|
+
...field.admin
|
|
112
|
+
};
|
|
80
113
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
114
|
+
}
|
|
115
|
+
// Array ID field
|
|
116
|
+
if (field.type === 'array' && field.fields) {
|
|
117
|
+
const hasCustomID = field.fields.some((f)=>'name' in f && f.name === 'id');
|
|
118
|
+
if (!hasCustomID) {
|
|
119
|
+
field.fields.push(baseIDField);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
// Blocks/array labels
|
|
123
|
+
if ((field.type === 'blocks' || field.type === 'array') && field.label) {
|
|
124
|
+
field.labels = field.labels || formatLabels(field.name);
|
|
125
|
+
}
|
|
126
|
+
if (fieldAffectsData) {
|
|
127
|
+
if (existingFieldNames.has(field.name)) {
|
|
128
|
+
throw new DuplicateFieldName(field.name);
|
|
129
|
+
} else if (![
|
|
130
|
+
'blockName',
|
|
131
|
+
'id'
|
|
132
|
+
].includes(field.name)) {
|
|
133
|
+
existingFieldNames.add(field.name);
|
|
92
134
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
if (
|
|
96
|
-
|
|
135
|
+
if (typeof field.localized !== 'undefined') {
|
|
136
|
+
let shouldDisableLocalized = !config.localization;
|
|
137
|
+
if (process.env.NEXT_PUBLIC_PAYLOAD_COMPATIBILITY_allowLocalizedWithinLocalized !== 'true' && parentIsLocalized && // @todo PAYLOAD_DO_NOT_SANITIZE_LOCALIZED_PROPERTY=true will be the default in 4.0
|
|
138
|
+
process.env.PAYLOAD_DO_NOT_SANITIZE_LOCALIZED_PROPERTY !== 'true') {
|
|
139
|
+
shouldDisableLocalized = true;
|
|
97
140
|
}
|
|
98
|
-
if (
|
|
99
|
-
|
|
100
|
-
field.relationTo
|
|
101
|
-
];
|
|
102
|
-
relationships.forEach((relationship)=>{
|
|
103
|
-
if (!validRelationships.includes(relationship)) {
|
|
104
|
-
throw new InvalidFieldRelationship(field, relationship);
|
|
105
|
-
}
|
|
106
|
-
});
|
|
141
|
+
if (shouldDisableLocalized) {
|
|
142
|
+
delete field.localized;
|
|
107
143
|
}
|
|
108
144
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
145
|
+
if (typeof field.validate === 'undefined') {
|
|
146
|
+
if ('virtual' in field && field.virtual) {
|
|
147
|
+
field.validate = ()=>true;
|
|
148
|
+
} else {
|
|
149
|
+
const defaultValidate = validations[field.type];
|
|
150
|
+
if (defaultValidate) {
|
|
151
|
+
field.validate = (val, options)=>defaultValidate(val, {
|
|
152
|
+
...field,
|
|
153
|
+
...options
|
|
154
|
+
});
|
|
155
|
+
} else {
|
|
156
|
+
field.validate = ()=>true;
|
|
157
|
+
}
|
|
116
158
|
}
|
|
117
159
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
const hasCustomID = field.fields.some((f)=>'name' in f && f.name === 'id');
|
|
121
|
-
if (!hasCustomID) {
|
|
122
|
-
field.fields.push(baseIDField);
|
|
123
|
-
}
|
|
160
|
+
if (!field.hooks) {
|
|
161
|
+
field.hooks = {};
|
|
124
162
|
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
field.labels = field.labels || formatLabels(field.name);
|
|
163
|
+
if (!field.access) {
|
|
164
|
+
field.access = {};
|
|
128
165
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
if (shouldDisableLocalized) {
|
|
145
|
-
delete field.localized;
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
if (typeof field.validate === 'undefined') {
|
|
149
|
-
if ('virtual' in field && field.virtual) {
|
|
150
|
-
field.validate = ()=>true;
|
|
166
|
+
setDefaultBeforeDuplicate(field, parentIsLocalized);
|
|
167
|
+
}
|
|
168
|
+
if (!field.admin) {
|
|
169
|
+
field.admin = {};
|
|
170
|
+
}
|
|
171
|
+
if ('virtual' in field && field.virtual && field.admin.readOnly !== false && fieldAffectsData) {
|
|
172
|
+
field.admin.readOnly = true;
|
|
173
|
+
}
|
|
174
|
+
// Make sure that the richText field has an editor
|
|
175
|
+
if (field.type === 'richText') {
|
|
176
|
+
const sanitizeRichText = async (_config)=>{
|
|
177
|
+
if (!field.editor) {
|
|
178
|
+
if (_config.editor && !requireFieldLevelRichTextEditor) {
|
|
179
|
+
// config.editor should be sanitized at this point
|
|
180
|
+
field.editor = _config.editor;
|
|
151
181
|
} else {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
field.validate = (val, options)=>defaultValidate(val, {
|
|
155
|
-
...field,
|
|
156
|
-
...options
|
|
157
|
-
});
|
|
158
|
-
} else {
|
|
159
|
-
field.validate = ()=>true;
|
|
160
|
-
}
|
|
182
|
+
throw new MissingEditorProp(field) // while we allow disabling editor functionality, you should not have any richText fields defined if you do not have an editor
|
|
183
|
+
;
|
|
161
184
|
}
|
|
162
185
|
}
|
|
163
|
-
if (
|
|
164
|
-
field.
|
|
186
|
+
if (typeof field.editor === 'function') {
|
|
187
|
+
field.editor = await field.editor({
|
|
188
|
+
config: _config,
|
|
189
|
+
isRoot: requireFieldLevelRichTextEditor,
|
|
190
|
+
parentIsLocalized: parentIsLocalized || field.localized
|
|
191
|
+
});
|
|
165
192
|
}
|
|
166
|
-
if (
|
|
167
|
-
|
|
193
|
+
if (field.editor.i18n && Object.keys(field.editor.i18n).length >= 0) {
|
|
194
|
+
config.i18n.translations = deepMergeSimple(config.i18n.translations, field.editor.i18n);
|
|
168
195
|
}
|
|
169
|
-
|
|
196
|
+
};
|
|
197
|
+
if (richTextSanitizationPromises) {
|
|
198
|
+
richTextSanitizationPromises.push(sanitizeRichText);
|
|
199
|
+
} else {
|
|
200
|
+
await sanitizeRichText(config);
|
|
170
201
|
}
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
field.admin.readOnly = true;
|
|
202
|
+
}
|
|
203
|
+
if (field.type === 'blocks' && field.blocks) {
|
|
204
|
+
if (field.blockReferences && field.blocks?.length) {
|
|
205
|
+
throw new Error('You cannot have both blockReferences and blocks in the same blocks field');
|
|
176
206
|
}
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
const
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
// config.editor should be sanitized at this point
|
|
183
|
-
field.editor = _config.editor;
|
|
184
|
-
} else {
|
|
185
|
-
throw new MissingEditorProp(field) // while we allow disabling editor functionality, you should not have any richText fields defined if you do not have an editor
|
|
186
|
-
;
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
if (typeof field.editor === 'function') {
|
|
190
|
-
field.editor = await field.editor({
|
|
191
|
-
config: _config,
|
|
192
|
-
isRoot: requireFieldLevelRichTextEditor,
|
|
193
|
-
parentIsLocalized: parentIsLocalized || field.localized
|
|
194
|
-
});
|
|
195
|
-
}
|
|
196
|
-
if (field.editor.i18n && Object.keys(field.editor.i18n).length >= 0) {
|
|
197
|
-
config.i18n.translations = deepMergeSimple(config.i18n.translations, field.editor.i18n);
|
|
198
|
-
}
|
|
199
|
-
};
|
|
200
|
-
if (richTextSanitizationPromises) {
|
|
201
|
-
richTextSanitizationPromises.push(sanitizeRichText);
|
|
202
|
-
} else {
|
|
203
|
-
await sanitizeRichText(config);
|
|
207
|
+
const blockSlugs = [];
|
|
208
|
+
for (const block of field.blockReferences ?? field.blocks){
|
|
209
|
+
const blockSlug = typeof block === 'string' ? block : block.slug;
|
|
210
|
+
if (blockSlugs.includes(blockSlug)) {
|
|
211
|
+
throw new DuplicateFieldName(blockSlug);
|
|
204
212
|
}
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
throw new Error('You cannot have both blockReferences and blocks in the same blocks field');
|
|
213
|
+
blockSlugs.push(blockSlug);
|
|
214
|
+
if (typeof block === 'string') {
|
|
215
|
+
continue;
|
|
209
216
|
}
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
const blockSlug = typeof block === 'string' ? block : block.slug;
|
|
213
|
-
if (blockSlugs.includes(blockSlug)) {
|
|
214
|
-
throw new DuplicateFieldName(blockSlug);
|
|
215
|
-
}
|
|
216
|
-
blockSlugs.push(blockSlug);
|
|
217
|
-
if (typeof block === 'string') {
|
|
218
|
-
continue;
|
|
219
|
-
}
|
|
220
|
-
if (block._sanitized === true) {
|
|
221
|
-
continue;
|
|
222
|
-
}
|
|
223
|
-
block._sanitized = true;
|
|
224
|
-
block.fields = block.fields.concat(baseBlockFields);
|
|
225
|
-
block.labels = !block.labels ? formatLabels(block.slug) : block.labels;
|
|
226
|
-
block.fields = await sanitizeFields({
|
|
227
|
-
collectionConfig,
|
|
228
|
-
config,
|
|
229
|
-
existingFieldNames: new Set(),
|
|
230
|
-
fields: block.fields,
|
|
231
|
-
isTopLevelField: false,
|
|
232
|
-
parentIndexPath: '',
|
|
233
|
-
parentIsLocalized: parentIsLocalized || field.localized,
|
|
234
|
-
parentSchemaPath: schemaPath + '.' + block.slug,
|
|
235
|
-
requireFieldLevelRichTextEditor,
|
|
236
|
-
richTextSanitizationPromises,
|
|
237
|
-
validRelationships
|
|
238
|
-
});
|
|
217
|
+
if (block._sanitized === true) {
|
|
218
|
+
continue;
|
|
239
219
|
}
|
|
220
|
+
block._sanitized = true;
|
|
221
|
+
block.fields = block.fields.concat(baseBlockFields);
|
|
222
|
+
block.labels = !block.labels ? formatLabels(block.slug) : block.labels;
|
|
223
|
+
block.fields = await sanitizeFields({
|
|
224
|
+
collectionConfig,
|
|
225
|
+
config,
|
|
226
|
+
existingFieldNames: new Set(),
|
|
227
|
+
fields: block.fields,
|
|
228
|
+
isTopLevelField: false,
|
|
229
|
+
parentIndexPath: '',
|
|
230
|
+
parentIsLocalized: parentIsLocalized || field.localized,
|
|
231
|
+
parentSchemaPath: schemaPath + '.' + block.slug,
|
|
232
|
+
requireFieldLevelRichTextEditor,
|
|
233
|
+
richTextSanitizationPromises,
|
|
234
|
+
validRelationships
|
|
235
|
+
});
|
|
240
236
|
}
|
|
241
|
-
|
|
242
|
-
|
|
237
|
+
}
|
|
238
|
+
if ('fields' in field && field.fields) {
|
|
239
|
+
field.fields = await sanitizeFields({
|
|
240
|
+
collectionConfig,
|
|
241
|
+
config,
|
|
242
|
+
existingFieldNames: fieldAffectsData ? new Set() : existingFieldNames,
|
|
243
|
+
fields: field.fields,
|
|
244
|
+
isTopLevelField: isTopLevelField && !fieldAffectsData,
|
|
245
|
+
joinPath: fieldAffectsData ? `${joinPath ? joinPath + '.' : ''}${field.name}` : joinPath,
|
|
246
|
+
joins,
|
|
247
|
+
orderableJoins,
|
|
248
|
+
parentIndexPath: fieldAffectsData ? '' : indexPath,
|
|
249
|
+
parentIsLocalized: parentIsLocalized || fieldIsLocalized(field),
|
|
250
|
+
parentSchemaPath: schemaPath,
|
|
251
|
+
polymorphicJoins,
|
|
252
|
+
requireFieldLevelRichTextEditor,
|
|
253
|
+
richTextSanitizationPromises,
|
|
254
|
+
validRelationships
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
if (field.type === 'tabs') {
|
|
258
|
+
for(let j = 0; j < field.tabs.length; j++){
|
|
259
|
+
const tab = field.tabs[j];
|
|
260
|
+
const isNamedTab = tabHasName(tab);
|
|
261
|
+
if (isNamedTab && typeof tab.label === 'undefined') {
|
|
262
|
+
tab.label = toWords(tab.name);
|
|
263
|
+
}
|
|
264
|
+
const { indexPath: tabIndexPath, schemaPath: tabSchemaPath } = getFieldPaths({
|
|
265
|
+
field: tab,
|
|
266
|
+
index: j,
|
|
267
|
+
parentIndexPath: indexPath,
|
|
268
|
+
parentSchemaPath: schemaPath
|
|
269
|
+
});
|
|
270
|
+
if ('admin' in tab && tab.admin?.condition && typeof tab.admin.condition === 'function' && !tab.id) {
|
|
271
|
+
tab.id = tabSchemaPath;
|
|
272
|
+
}
|
|
273
|
+
tab.fields = await sanitizeFields({
|
|
243
274
|
collectionConfig,
|
|
244
275
|
config,
|
|
245
|
-
existingFieldNames:
|
|
246
|
-
fields:
|
|
247
|
-
isTopLevelField: isTopLevelField && !
|
|
248
|
-
joinPath:
|
|
276
|
+
existingFieldNames: isNamedTab ? new Set() : existingFieldNames,
|
|
277
|
+
fields: tab.fields,
|
|
278
|
+
isTopLevelField: isTopLevelField && !isNamedTab,
|
|
279
|
+
joinPath: isNamedTab ? `${joinPath ? joinPath + '.' : ''}${tab.name}` : joinPath,
|
|
249
280
|
joins,
|
|
250
281
|
orderableJoins,
|
|
251
|
-
parentIndexPath:
|
|
252
|
-
parentIsLocalized: parentIsLocalized ||
|
|
253
|
-
parentSchemaPath:
|
|
282
|
+
parentIndexPath: isNamedTab ? '' : tabIndexPath,
|
|
283
|
+
parentIsLocalized: parentIsLocalized || isNamedTab && tab.localized,
|
|
284
|
+
parentSchemaPath: tabSchemaPath,
|
|
254
285
|
polymorphicJoins,
|
|
255
286
|
requireFieldLevelRichTextEditor,
|
|
256
287
|
richTextSanitizationPromises,
|
|
257
288
|
validRelationships
|
|
258
289
|
});
|
|
290
|
+
field.tabs[j] = tab;
|
|
259
291
|
}
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
});
|
|
273
|
-
if ('admin' in tab && tab.admin?.condition && typeof tab.admin.condition === 'function' && !tab.id) {
|
|
274
|
-
tab.id = tabSchemaPath;
|
|
275
|
-
}
|
|
276
|
-
tab.fields = await sanitizeFields({
|
|
277
|
-
collectionConfig,
|
|
278
|
-
config,
|
|
279
|
-
existingFieldNames: isNamedTab ? new Set() : existingFieldNames,
|
|
280
|
-
fields: tab.fields,
|
|
281
|
-
isTopLevelField: isTopLevelField && !isNamedTab,
|
|
282
|
-
joinPath: isNamedTab ? `${joinPath ? joinPath + '.' : ''}${tab.name}` : joinPath,
|
|
283
|
-
joins,
|
|
284
|
-
orderableJoins,
|
|
285
|
-
parentIndexPath: isNamedTab ? '' : tabIndexPath,
|
|
286
|
-
parentIsLocalized: parentIsLocalized || isNamedTab && tab.localized,
|
|
287
|
-
parentSchemaPath: tabSchemaPath,
|
|
288
|
-
polymorphicJoins,
|
|
289
|
-
requireFieldLevelRichTextEditor,
|
|
290
|
-
richTextSanitizationPromises,
|
|
291
|
-
validRelationships
|
|
292
|
-
});
|
|
293
|
-
field.tabs[j] = tab;
|
|
294
|
-
}
|
|
292
|
+
}
|
|
293
|
+
if (field.type === 'ui') {
|
|
294
|
+
const existing = field.admin.disabled;
|
|
295
|
+
if (existing === undefined) {
|
|
296
|
+
field.admin.disabled = {
|
|
297
|
+
bulkEdit: true
|
|
298
|
+
};
|
|
299
|
+
} else if (existing !== true && typeof existing === 'object' && existing.bulkEdit === undefined) {
|
|
300
|
+
field.admin.disabled = {
|
|
301
|
+
...existing,
|
|
302
|
+
bulkEdit: true
|
|
303
|
+
};
|
|
295
304
|
}
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
}
|
|
305
|
+
}
|
|
306
|
+
// Timezone field insertion
|
|
307
|
+
if (field.type === 'date' && field.timezone) {
|
|
308
|
+
const name = field.name + '_tz';
|
|
309
|
+
let defaultTimezone = field.timezone && typeof field.timezone === 'object' ? field.timezone.defaultTimezone : config.admin?.timezones?.defaultTimezone;
|
|
310
|
+
const required = field.required || field.timezone && typeof field.timezone === 'object' && field.timezone.required;
|
|
311
|
+
const supportedTimezones = field.timezone && typeof field.timezone === 'object' && field.timezone.supportedTimezones ? field.timezone.supportedTimezones : config.admin?.timezones?.supportedTimezones;
|
|
312
|
+
const options = typeof supportedTimezones === 'function' ? supportedTimezones({
|
|
313
|
+
defaultTimezones
|
|
314
|
+
}) : supportedTimezones;
|
|
315
|
+
validateTimezones({
|
|
316
|
+
source: `field "${field.name}" timezone.supportedTimezones`,
|
|
317
|
+
timezones: options
|
|
318
|
+
});
|
|
319
|
+
if (options && options.length === 1 && options[0]?.value) {
|
|
320
|
+
defaultTimezone = options[0].value;
|
|
308
321
|
}
|
|
309
|
-
//
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
322
|
+
// Generate label for timezone field
|
|
323
|
+
const timezoneLabel = typeof field.label === 'string' ? `${field.label} Tz` : toWords(name);
|
|
324
|
+
const baseField = baseTimezoneField({
|
|
325
|
+
name,
|
|
326
|
+
defaultValue: defaultTimezone,
|
|
327
|
+
label: timezoneLabel,
|
|
328
|
+
options,
|
|
329
|
+
required
|
|
330
|
+
});
|
|
331
|
+
// Apply override if provided
|
|
332
|
+
const timezoneField = typeof field.timezone === 'object' && typeof field.timezone.override === 'function' ? field.timezone.override({
|
|
333
|
+
baseField
|
|
334
|
+
}) : baseField;
|
|
335
|
+
result.fieldsToInsert = [
|
|
336
|
+
timezoneField
|
|
337
|
+
];
|
|
338
|
+
}
|
|
339
|
+
// Virtual field handling
|
|
340
|
+
if ('virtual' in field && typeof field.virtual === 'string') {
|
|
341
|
+
const virtualField = field;
|
|
342
|
+
const configFields = (collectionConfig || globalConfig)?.fields;
|
|
343
|
+
if (configFields) {
|
|
344
|
+
let flattenFields = flattenAllFields({
|
|
345
|
+
fields: configFields
|
|
333
346
|
});
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
let flattenFields = flattenAllFields({
|
|
348
|
-
fields: configFields
|
|
349
|
-
});
|
|
350
|
-
const paths = field.virtual.split('.');
|
|
351
|
-
let isHasMany = false;
|
|
352
|
-
for (const [idx, segment] of paths.entries()){
|
|
353
|
-
const foundField = flattenFields.find((e)=>e.name === segment);
|
|
354
|
-
if (!foundField) {
|
|
355
|
-
break;
|
|
356
|
-
}
|
|
357
|
-
if (foundField.type === 'group' || foundField.type === 'tab' || foundField.type === 'array') {
|
|
358
|
-
flattenFields = foundField.flattenedFields;
|
|
359
|
-
} else if ((foundField.type === 'relationship' || foundField.type === 'upload') && idx !== paths.length - 1 && typeof foundField.relationTo === 'string') {
|
|
360
|
-
if (foundField.hasMany && (virtualField.type === 'text' || virtualField.type === 'number' || virtualField.type === 'select')) {
|
|
361
|
-
if (isHasMany) {
|
|
362
|
-
throw new InvalidConfiguration(`Virtual field ${virtualField.name} in ${globalConfig ? `global ${globalConfig.slug}` : `collection ${collectionConfig?.slug}`} references 2 or more hasMany relationships on the path ${virtualField.virtual} which is not allowed.`);
|
|
363
|
-
}
|
|
364
|
-
isHasMany = true;
|
|
365
|
-
virtualField.hasMany = true;
|
|
366
|
-
}
|
|
367
|
-
const relatedCollection = config.collections?.find((e)=>e.slug === foundField.relationTo);
|
|
368
|
-
if (relatedCollection) {
|
|
369
|
-
flattenFields = flattenAllFields({
|
|
370
|
-
fields: relatedCollection.fields
|
|
371
|
-
});
|
|
347
|
+
const paths = field.virtual.split('.');
|
|
348
|
+
let isHasMany = false;
|
|
349
|
+
for (const [idx, segment] of paths.entries()){
|
|
350
|
+
const foundField = flattenFields.find((e)=>e.name === segment);
|
|
351
|
+
if (!foundField) {
|
|
352
|
+
break;
|
|
353
|
+
}
|
|
354
|
+
if (foundField.type === 'group' || foundField.type === 'tab' || foundField.type === 'array') {
|
|
355
|
+
flattenFields = foundField.flattenedFields;
|
|
356
|
+
} else if ((foundField.type === 'relationship' || foundField.type === 'upload') && idx !== paths.length - 1 && typeof foundField.relationTo === 'string') {
|
|
357
|
+
if (foundField.hasMany && (virtualField.type === 'text' || virtualField.type === 'number' || virtualField.type === 'select')) {
|
|
358
|
+
if (isHasMany) {
|
|
359
|
+
throw new InvalidConfiguration(`Virtual field ${virtualField.name} in ${globalConfig ? `global ${globalConfig.slug}` : `collection ${collectionConfig?.slug}`} references 2 or more hasMany relationships on the path ${virtualField.virtual} which is not allowed.`);
|
|
372
360
|
}
|
|
361
|
+
isHasMany = true;
|
|
362
|
+
virtualField.hasMany = true;
|
|
363
|
+
}
|
|
364
|
+
const relatedCollection = config.collections?.find((e)=>e.slug === foundField.relationTo);
|
|
365
|
+
if (relatedCollection) {
|
|
366
|
+
flattenFields = flattenAllFields({
|
|
367
|
+
fields: relatedCollection.fields
|
|
368
|
+
});
|
|
373
369
|
}
|
|
374
370
|
}
|
|
375
371
|
}
|
|
376
372
|
}
|
|
377
|
-
return result;
|
|
378
|
-
} finally{
|
|
379
|
-
endSpan(__profSpan);
|
|
380
373
|
}
|
|
374
|
+
return result;
|
|
381
375
|
};
|
|
382
376
|
export const sanitizeFields = async ({ collectionConfig, config, existingFieldNames = new Set(), fields, globalConfig, isTopLevelField = true, joinPath = '', joins, orderableJoins, parentIndexPath = '', parentIsLocalized, parentSchemaPath = '', polymorphicJoins, requireFieldLevelRichTextEditor = false, richTextSanitizationPromises, validRelationships })=>{
|
|
383
377
|
if (!fields) {
|
|
384
378
|
return [];
|
|
385
379
|
}
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
fields
|
|
410
|
-
|
|
411
|
-
fields.splice(i + 1, 0, ...result.fieldsToInsert);
|
|
412
|
-
i += result.fieldsToInsert.length;
|
|
413
|
-
}
|
|
380
|
+
for(let i = 0; i < fields.length; i++){
|
|
381
|
+
const field = fields[i];
|
|
382
|
+
const result = await sanitizeField({
|
|
383
|
+
collectionConfig,
|
|
384
|
+
config,
|
|
385
|
+
existingFieldNames,
|
|
386
|
+
field,
|
|
387
|
+
globalConfig,
|
|
388
|
+
index: i,
|
|
389
|
+
isTopLevelField,
|
|
390
|
+
joinPath,
|
|
391
|
+
joins,
|
|
392
|
+
orderableJoins,
|
|
393
|
+
parentIndexPath,
|
|
394
|
+
parentIsLocalized,
|
|
395
|
+
parentSchemaPath,
|
|
396
|
+
polymorphicJoins,
|
|
397
|
+
requireFieldLevelRichTextEditor,
|
|
398
|
+
richTextSanitizationPromises,
|
|
399
|
+
validRelationships
|
|
400
|
+
});
|
|
401
|
+
fields[i] = field;
|
|
402
|
+
if (result.fieldsToInsert?.length) {
|
|
403
|
+
fields.splice(i + 1, 0, ...result.fieldsToInsert);
|
|
404
|
+
i += result.fieldsToInsert.length;
|
|
414
405
|
}
|
|
415
|
-
return fields;
|
|
416
|
-
} finally{
|
|
417
|
-
endSpan(__profSpan);
|
|
418
406
|
}
|
|
407
|
+
return fields;
|
|
419
408
|
};
|
|
420
409
|
|
|
421
410
|
//# sourceMappingURL=sanitize.js.map
|