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.
@@ -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
- const __profSpan = startSpan(`sanitizeField:${field.type}`);
32
- try {
33
- if ('_sanitized' in field) {
34
- field._sanitized = true;
35
- }
36
- if (!field.type) {
37
- throw new MissingFieldType(field);
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
- const fieldAffectsData = _fieldAffectsData(field);
40
- const { indexPath, schemaPath } = getFieldPaths({
41
- field,
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 && collectionConfig.auth && typeof collectionConfig.auth === 'object' && !collectionConfig.auth.disableLocalStrategy) {
54
- if (reservedBaseAuthFieldNames.includes(field.name)) {
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
- if (collectionConfig.auth.verify) {
58
- // @ts-expect-error - vestiges of when tsconfig was not strict. Feel free to improve
59
- if (reservedAPIKeyFieldNames.includes(field.name)) {
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
- // Invalid field name check
70
- if (fieldAffectsData && field.name.includes('.')) {
71
- throw new InvalidFieldName(field, field.name);
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
- // Auto-label
74
- if ('name' in field && field.name && typeof field.label !== 'object' && typeof field.label !== 'string' && typeof field.label !== 'function' && field.label !== false) {
75
- field.label = toWords(field.name);
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
- // Checkbox default
78
- if (field.type === 'checkbox' && typeof field.defaultValue === 'undefined' && field.required === true) {
79
- field.defaultValue = false;
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
- // Join field sanitization
82
- if (field.type === 'join') {
83
- sanitizeJoinField({
84
- config,
85
- field,
86
- joinPath,
87
- joins,
88
- orderableJoins,
89
- parentIsLocalized,
90
- polymorphicJoins
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
- // Relationship/upload validation
94
- if (field.type === 'relationship' || field.type === 'upload') {
95
- if (Array.isArray(field.relationTo) && field.relationTo.length === 0) {
96
- throw new Error(`Field "${field.name}" of type "${field.type}" has an empty relationTo array. At least one collection must be specified.`);
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 (validRelationships) {
99
- const relationships = Array.isArray(field.relationTo) ? field.relationTo : [
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
- // Upload isSortable default
110
- if (field.type === 'upload') {
111
- if (!field.admin || !('isSortable' in field.admin)) {
112
- field.admin = {
113
- isSortable: true,
114
- ...field.admin
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
- // Array ID field
119
- if (field.type === 'array' && field.fields) {
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
- // Blocks/array labels
126
- if ((field.type === 'blocks' || field.type === 'array') && field.label) {
127
- field.labels = field.labels || formatLabels(field.name);
163
+ if (!field.access) {
164
+ field.access = {};
128
165
  }
129
- if (fieldAffectsData) {
130
- if (existingFieldNames.has(field.name)) {
131
- throw new DuplicateFieldName(field.name);
132
- } else if (![
133
- 'blockName',
134
- 'id'
135
- ].includes(field.name)) {
136
- existingFieldNames.add(field.name);
137
- }
138
- if (typeof field.localized !== 'undefined') {
139
- let shouldDisableLocalized = !config.localization;
140
- 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
141
- process.env.PAYLOAD_DO_NOT_SANITIZE_LOCALIZED_PROPERTY !== 'true') {
142
- shouldDisableLocalized = true;
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
- const defaultValidate = validations[field.type];
153
- if (defaultValidate) {
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 (!field.hooks) {
164
- field.hooks = {};
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 (!field.access) {
167
- field.access = {};
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
- setDefaultBeforeDuplicate(field, parentIsLocalized);
196
+ };
197
+ if (richTextSanitizationPromises) {
198
+ richTextSanitizationPromises.push(sanitizeRichText);
199
+ } else {
200
+ await sanitizeRichText(config);
170
201
  }
171
- if (!field.admin) {
172
- field.admin = {};
173
- }
174
- if ('virtual' in field && field.virtual && field.admin.readOnly !== false && fieldAffectsData) {
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
- // Make sure that the richText field has an editor
178
- if (field.type === 'richText') {
179
- const sanitizeRichText = async (_config)=>{
180
- if (!field.editor) {
181
- if (_config.editor && !requireFieldLevelRichTextEditor) {
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
- if (field.type === 'blocks' && field.blocks) {
207
- if (field.blockReferences && field.blocks?.length) {
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
- const blockSlugs = [];
211
- for (const block of field.blockReferences ?? field.blocks){
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
- if ('fields' in field && field.fields) {
242
- field.fields = await sanitizeFields({
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: fieldAffectsData ? new Set() : existingFieldNames,
246
- fields: field.fields,
247
- isTopLevelField: isTopLevelField && !fieldAffectsData,
248
- joinPath: fieldAffectsData ? `${joinPath ? joinPath + '.' : ''}${field.name}` : 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: fieldAffectsData ? '' : indexPath,
252
- parentIsLocalized: parentIsLocalized || fieldIsLocalized(field),
253
- parentSchemaPath: schemaPath,
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
- if (field.type === 'tabs') {
261
- for(let j = 0; j < field.tabs.length; j++){
262
- const tab = field.tabs[j];
263
- const isNamedTab = tabHasName(tab);
264
- if (isNamedTab && typeof tab.label === 'undefined') {
265
- tab.label = toWords(tab.name);
266
- }
267
- const { indexPath: tabIndexPath, schemaPath: tabSchemaPath } = getFieldPaths({
268
- field: tab,
269
- index: j,
270
- parentIndexPath: indexPath,
271
- parentSchemaPath: schemaPath
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
- if (field.type === 'ui') {
297
- const existing = field.admin.disabled;
298
- if (existing === undefined) {
299
- field.admin.disabled = {
300
- bulkEdit: true
301
- };
302
- } else if (existing !== true && typeof existing === 'object' && existing.bulkEdit === undefined) {
303
- field.admin.disabled = {
304
- ...existing,
305
- bulkEdit: true
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
- // Timezone field insertion
310
- if (field.type === 'date' && field.timezone) {
311
- const name = field.name + '_tz';
312
- let defaultTimezone = field.timezone && typeof field.timezone === 'object' ? field.timezone.defaultTimezone : config.admin?.timezones?.defaultTimezone;
313
- const required = field.required || field.timezone && typeof field.timezone === 'object' && field.timezone.required;
314
- const supportedTimezones = field.timezone && typeof field.timezone === 'object' && field.timezone.supportedTimezones ? field.timezone.supportedTimezones : config.admin?.timezones?.supportedTimezones;
315
- const options = typeof supportedTimezones === 'function' ? supportedTimezones({
316
- defaultTimezones
317
- }) : supportedTimezones;
318
- validateTimezones({
319
- source: `field "${field.name}" timezone.supportedTimezones`,
320
- timezones: options
321
- });
322
- if (options && options.length === 1 && options[0]?.value) {
323
- defaultTimezone = options[0].value;
324
- }
325
- // Generate label for timezone field
326
- const timezoneLabel = typeof field.label === 'string' ? `${field.label} Tz` : toWords(name);
327
- const baseField = baseTimezoneField({
328
- name,
329
- defaultValue: defaultTimezone,
330
- label: timezoneLabel,
331
- options,
332
- required
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
- // Apply override if provided
335
- const timezoneField = typeof field.timezone === 'object' && typeof field.timezone.override === 'function' ? field.timezone.override({
336
- baseField
337
- }) : baseField;
338
- result.fieldsToInsert = [
339
- timezoneField
340
- ];
341
- }
342
- // Virtual field handling
343
- if ('virtual' in field && typeof field.virtual === 'string') {
344
- const virtualField = field;
345
- const configFields = (collectionConfig || globalConfig)?.fields;
346
- if (configFields) {
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
- const __profSpan = startSpan('sanitizeFields', String(fields.length));
387
- try {
388
- for(let i = 0; i < fields.length; i++){
389
- const field = fields[i];
390
- const result = await sanitizeField({
391
- collectionConfig,
392
- config,
393
- existingFieldNames,
394
- field,
395
- globalConfig,
396
- index: i,
397
- isTopLevelField,
398
- joinPath,
399
- joins,
400
- orderableJoins,
401
- parentIndexPath,
402
- parentIsLocalized,
403
- parentSchemaPath,
404
- polymorphicJoins,
405
- requireFieldLevelRichTextEditor,
406
- richTextSanitizationPromises,
407
- validRelationships
408
- });
409
- fields[i] = field;
410
- if (result.fieldsToInsert?.length) {
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