payload 3.0.0-alpha.65 → 3.0.0-alpha.66
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/admin/RichText.d.ts +3 -0
- package/dist/admin/RichText.d.ts.map +1 -1
- package/dist/admin/RichText.js.map +1 -1
- package/dist/admin/elements/Tab.d.ts +3 -0
- package/dist/admin/elements/Tab.d.ts.map +1 -1
- package/dist/admin/elements/Tab.js.map +1 -1
- package/dist/admin/types.d.ts +1 -1
- package/dist/admin/types.d.ts.map +1 -1
- package/dist/admin/types.js.map +1 -1
- package/dist/auth/getAccessResults.js +1 -1
- package/dist/auth/getAccessResults.js.map +1 -1
- package/dist/auth/operations/forgotPassword.js +3 -2
- package/dist/auth/operations/forgotPassword.js.map +1 -1
- package/dist/auth/sendVerificationEmail.js +3 -2
- package/dist/auth/sendVerificationEmail.js.map +1 -1
- package/dist/bin/loader/index.d.ts.map +1 -1
- package/dist/bin/loader/index.js +2 -1
- package/dist/bin/loader/index.js.map +1 -1
- package/dist/bin/loader/resolveOriginalPath.d.ts +10 -0
- package/dist/bin/loader/resolveOriginalPath.d.ts.map +1 -0
- package/dist/bin/loader/resolveOriginalPath.js +32 -0
- package/dist/bin/loader/resolveOriginalPath.js.map +1 -0
- package/dist/collections/config/sanitize.d.ts +2 -3
- package/dist/collections/config/sanitize.d.ts.map +1 -1
- package/dist/collections/config/sanitize.js +7 -4
- package/dist/collections/config/sanitize.js.map +1 -1
- package/dist/collections/config/schema.d.ts.map +1 -1
- package/dist/collections/config/schema.js +1 -0
- package/dist/collections/config/schema.js.map +1 -1
- package/dist/config/build.d.ts.map +1 -1
- package/dist/config/build.js +3 -4
- package/dist/config/build.js.map +1 -1
- package/dist/config/sanitize.d.ts +1 -1
- package/dist/config/sanitize.d.ts.map +1 -1
- package/dist/config/sanitize.js +28 -7
- package/dist/config/sanitize.js.map +1 -1
- package/dist/config/schema.js +1 -1
- package/dist/config/schema.js.map +1 -1
- package/dist/config/types.d.ts +11 -2
- package/dist/config/types.d.ts.map +1 -1
- package/dist/config/types.js.map +1 -1
- package/dist/database/queryValidation/validateQueryPaths.js +1 -1
- package/dist/database/queryValidation/validateQueryPaths.js.map +1 -1
- package/dist/email/consoleEmailAdapter.d.ts.map +1 -1
- package/dist/email/consoleEmailAdapter.js +1 -0
- package/dist/email/consoleEmailAdapter.js.map +1 -1
- package/dist/email/types.d.ts +1 -0
- package/dist/email/types.d.ts.map +1 -1
- package/dist/email/types.js.map +1 -1
- package/dist/errors/APIError.d.ts +2 -2
- package/dist/errors/APIError.d.ts.map +1 -1
- package/dist/errors/APIError.js +1 -2
- package/dist/errors/APIError.js.map +1 -1
- package/dist/errors/AuthenticationError.d.ts +2 -3
- package/dist/errors/AuthenticationError.d.ts.map +1 -1
- package/dist/errors/AuthenticationError.js +2 -3
- package/dist/errors/AuthenticationError.js.map +1 -1
- package/dist/errors/DuplicateCollection.d.ts +2 -3
- package/dist/errors/DuplicateCollection.d.ts.map +1 -1
- package/dist/errors/DuplicateCollection.js +2 -3
- package/dist/errors/DuplicateCollection.js.map +1 -1
- package/dist/errors/DuplicateFieldName.d.ts +2 -3
- package/dist/errors/DuplicateFieldName.d.ts.map +1 -1
- package/dist/errors/DuplicateFieldName.js +2 -3
- package/dist/errors/DuplicateFieldName.js.map +1 -1
- package/dist/errors/DuplicateGlobal.d.ts +2 -3
- package/dist/errors/DuplicateGlobal.d.ts.map +1 -1
- package/dist/errors/DuplicateGlobal.js +2 -3
- package/dist/errors/DuplicateGlobal.js.map +1 -1
- package/dist/errors/ErrorDeletingFile.d.ts +2 -3
- package/dist/errors/ErrorDeletingFile.d.ts.map +1 -1
- package/dist/errors/ErrorDeletingFile.js +2 -3
- package/dist/errors/ErrorDeletingFile.js.map +1 -1
- package/dist/errors/FileRetrievalError.d.ts +6 -0
- package/dist/errors/FileRetrievalError.d.ts.map +1 -0
- package/dist/errors/FileRetrievalError.js +13 -0
- package/dist/errors/FileRetrievalError.js.map +1 -0
- package/dist/errors/FileUploadError.d.ts +2 -3
- package/dist/errors/FileUploadError.d.ts.map +1 -1
- package/dist/errors/FileUploadError.js +2 -3
- package/dist/errors/FileUploadError.js.map +1 -1
- package/dist/errors/Forbidden.d.ts +2 -3
- package/dist/errors/Forbidden.d.ts.map +1 -1
- package/dist/errors/Forbidden.js +2 -3
- package/dist/errors/Forbidden.js.map +1 -1
- package/dist/errors/InvalidConfiguration.d.ts +2 -3
- package/dist/errors/InvalidConfiguration.d.ts.map +1 -1
- package/dist/errors/InvalidConfiguration.js +2 -3
- package/dist/errors/InvalidConfiguration.js.map +1 -1
- package/dist/errors/InvalidFieldName.d.ts +2 -3
- package/dist/errors/InvalidFieldName.d.ts.map +1 -1
- package/dist/errors/InvalidFieldName.js +2 -3
- package/dist/errors/InvalidFieldName.js.map +1 -1
- package/dist/errors/InvalidFieldRelationship.d.ts +2 -3
- package/dist/errors/InvalidFieldRelationship.d.ts.map +1 -1
- package/dist/errors/InvalidFieldRelationship.js +2 -3
- package/dist/errors/InvalidFieldRelationship.js.map +1 -1
- package/dist/errors/InvalidSchema.d.ts +2 -3
- package/dist/errors/InvalidSchema.d.ts.map +1 -1
- package/dist/errors/InvalidSchema.js +2 -3
- package/dist/errors/InvalidSchema.js.map +1 -1
- package/dist/errors/LockedAuth.d.ts +2 -3
- package/dist/errors/LockedAuth.d.ts.map +1 -1
- package/dist/errors/LockedAuth.js +2 -3
- package/dist/errors/LockedAuth.js.map +1 -1
- package/dist/errors/MissingCollectionLabel.d.ts +2 -3
- package/dist/errors/MissingCollectionLabel.d.ts.map +1 -1
- package/dist/errors/MissingCollectionLabel.js +2 -3
- package/dist/errors/MissingCollectionLabel.js.map +1 -1
- package/dist/errors/MissingEditorProp.d.ts +2 -3
- package/dist/errors/MissingEditorProp.d.ts.map +1 -1
- package/dist/errors/MissingEditorProp.js +2 -3
- package/dist/errors/MissingEditorProp.js.map +1 -1
- package/dist/errors/MissingFieldInputOptions.d.ts +2 -3
- package/dist/errors/MissingFieldInputOptions.d.ts.map +1 -1
- package/dist/errors/MissingFieldInputOptions.js +2 -3
- package/dist/errors/MissingFieldInputOptions.js.map +1 -1
- package/dist/errors/MissingFieldType.d.ts +2 -3
- package/dist/errors/MissingFieldType.d.ts.map +1 -1
- package/dist/errors/MissingFieldType.js +2 -3
- package/dist/errors/MissingFieldType.js.map +1 -1
- package/dist/errors/MissingFile.d.ts +2 -3
- package/dist/errors/MissingFile.d.ts.map +1 -1
- package/dist/errors/MissingFile.js +2 -3
- package/dist/errors/MissingFile.js.map +1 -1
- package/dist/errors/NotFound.d.ts +2 -3
- package/dist/errors/NotFound.d.ts.map +1 -1
- package/dist/errors/NotFound.js +2 -3
- package/dist/errors/NotFound.js.map +1 -1
- package/dist/errors/QueryError.d.ts +2 -3
- package/dist/errors/QueryError.d.ts.map +1 -1
- package/dist/errors/QueryError.js +2 -3
- package/dist/errors/QueryError.js.map +1 -1
- package/dist/errors/TimestampsRequired.d.ts +2 -3
- package/dist/errors/TimestampsRequired.d.ts.map +1 -1
- package/dist/errors/TimestampsRequired.js +2 -3
- package/dist/errors/TimestampsRequired.js.map +1 -1
- package/dist/errors/UnathorizedError.d.ts +2 -3
- package/dist/errors/UnathorizedError.d.ts.map +1 -1
- package/dist/errors/UnathorizedError.js +2 -3
- package/dist/errors/UnathorizedError.js.map +1 -1
- package/dist/errors/ValidationError.d.ts +2 -3
- package/dist/errors/ValidationError.d.ts.map +1 -1
- package/dist/errors/ValidationError.js +2 -3
- package/dist/errors/ValidationError.js.map +1 -1
- package/dist/errors/index.d.ts +20 -19
- package/dist/errors/index.d.ts.map +1 -1
- package/dist/errors/index.js +20 -19
- package/dist/errors/index.js.map +1 -1
- package/dist/exports/i18n.d.ts +2 -0
- package/dist/exports/i18n.d.ts.map +1 -0
- package/dist/exports/i18n.js +3 -0
- package/dist/exports/i18n.js.map +1 -0
- package/dist/fields/config/client.d.ts +1 -1
- package/dist/fields/config/sanitize.d.ts +7 -2
- package/dist/fields/config/sanitize.d.ts.map +1 -1
- package/dist/fields/config/sanitize.js +56 -45
- package/dist/fields/config/sanitize.js.map +1 -1
- package/dist/fields/config/sanitize.spec.js +76 -85
- package/dist/fields/config/sanitize.spec.js.map +1 -1
- package/dist/fields/config/types.d.ts +4 -3
- package/dist/fields/config/types.d.ts.map +1 -1
- package/dist/fields/config/types.js.map +1 -1
- package/dist/fields/hooks/afterRead/promise.d.ts.map +1 -1
- package/dist/fields/hooks/afterRead/promise.js +3 -0
- package/dist/fields/hooks/afterRead/promise.js.map +1 -1
- package/dist/fields/validations.d.ts.map +1 -1
- package/dist/fields/validations.js +3 -0
- package/dist/fields/validations.js.map +1 -1
- package/dist/globals/config/sanitize.d.ts +2 -3
- package/dist/globals/config/sanitize.d.ts.map +1 -1
- package/dist/globals/config/sanitize.js +36 -35
- package/dist/globals/config/sanitize.js.map +1 -1
- package/dist/preferences/operations/delete.js +2 -2
- package/dist/preferences/operations/delete.js.map +1 -1
- package/dist/preferences/operations/update.js +1 -1
- package/dist/preferences/operations/update.js.map +1 -1
- package/dist/uploads/generateFileData.js +2 -2
- package/dist/uploads/generateFileData.js.map +1 -1
- package/dist/uploads/getExternalFile.d.ts.map +1 -1
- package/dist/uploads/getExternalFile.js +5 -2
- package/dist/uploads/getExternalFile.js.map +1 -1
- package/dist/uploads/types.d.ts +4 -0
- package/dist/uploads/types.d.ts.map +1 -1
- package/dist/uploads/types.js.map +1 -1
- package/dist/utilities/checkDuplicateCollections.js +1 -1
- package/dist/utilities/checkDuplicateCollections.js.map +1 -1
- package/dist/utilities/configToJSONSchema.d.ts.map +1 -1
- package/dist/utilities/configToJSONSchema.js +3 -0
- package/dist/utilities/configToJSONSchema.js.map +1 -1
- package/dist/utilities/configToJSONSchema.spec.js +2 -2
- package/dist/utilities/configToJSONSchema.spec.js.map +1 -1
- package/dist/utilities/createLocalReq.d.ts.map +1 -1
- package/dist/utilities/createLocalReq.js +4 -2
- package/dist/utilities/createLocalReq.js.map +1 -1
- package/dist/utilities/importWithoutClientFiles.js +1 -1
- package/dist/utilities/importWithoutClientFiles.js.map +1 -1
- package/dist/utilities/parseCookies.js +1 -1
- package/dist/utilities/parseCookies.js.map +1 -1
- package/dist/utilities/telemetry/index.d.ts +7 -1
- package/dist/utilities/telemetry/index.d.ts.map +1 -1
- package/dist/utilities/telemetry/index.js +41 -19
- package/dist/utilities/telemetry/index.js.map +1 -1
- package/package.json +67 -70
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import MissingEditorProp from '../../errors/MissingEditorProp.js';
|
|
1
|
+
import { MissingEditorProp } from '../../errors/MissingEditorProp.js';
|
|
2
2
|
import { DuplicateFieldName, InvalidFieldName, InvalidFieldRelationship, MissingFieldType } from '../../errors/index.js';
|
|
3
3
|
import { formatLabels, toWords } from '../../utilities/formatLabels.js';
|
|
4
4
|
import { baseBlockFields } from '../baseFields/baseBlockFields.js';
|
|
@@ -6,12 +6,10 @@ import { baseIDField } from '../baseFields/baseIDField.js';
|
|
|
6
6
|
import { setDefaultBeforeDuplicate } from '../setDefaultBeforeDuplicate.js';
|
|
7
7
|
import validations from '../validations.js';
|
|
8
8
|
import { fieldAffectsData, tabHasName } from './types.js';
|
|
9
|
-
export const sanitizeFields = ({ config, existingFieldNames = new Set(), fields, requireFieldLevelRichTextEditor = false, validRelationships })=>{
|
|
9
|
+
export const sanitizeFields = async ({ config, existingFieldNames = new Set(), fields, requireFieldLevelRichTextEditor = false, richTextSanitizationPromises, validRelationships })=>{
|
|
10
10
|
if (!fields) return [];
|
|
11
|
-
|
|
12
|
-
const field =
|
|
13
|
-
...unsanitizedField
|
|
14
|
-
};
|
|
11
|
+
for(let i = 0; i < fields.length; i++){
|
|
12
|
+
const field = fields[i];
|
|
15
13
|
if (!field.type) throw new MissingFieldType(field);
|
|
16
14
|
// assert that field names do not contain forbidden characters
|
|
17
15
|
if (fieldAffectsData(field) && field.name.includes('.')) {
|
|
@@ -88,74 +86,87 @@ export const sanitizeFields = ({ config, existingFieldNames = new Set(), fields,
|
|
|
88
86
|
}
|
|
89
87
|
// Make sure that the richText field has an editor
|
|
90
88
|
if (field.type === 'richText') {
|
|
91
|
-
|
|
92
|
-
if (
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
89
|
+
const sanitizeRichText = async (_config)=>{
|
|
90
|
+
if (!field.editor) {
|
|
91
|
+
if (_config.editor && !requireFieldLevelRichTextEditor) {
|
|
92
|
+
// config.editor should be sanitized at this point
|
|
93
|
+
field.editor = _config.editor;
|
|
94
|
+
} else {
|
|
95
|
+
throw new MissingEditorProp(field);
|
|
96
|
+
}
|
|
96
97
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
98
|
+
if (typeof field.editor === 'function') {
|
|
99
|
+
field.editor = await field.editor({
|
|
100
|
+
config: _config
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
// Add editor adapter hooks to field hooks
|
|
104
|
+
if (!field.hooks) field.hooks = {};
|
|
105
|
+
const mergeHooks = (hookName)=>{
|
|
106
|
+
if (typeof field.editor === 'function') return;
|
|
107
|
+
if (field.editor?.hooks?.[hookName]?.length) {
|
|
108
|
+
field.hooks[hookName] = field.hooks[hookName] ? field.hooks[hookName].concat(field.editor.hooks[hookName]) : [
|
|
109
|
+
...field.editor.hooks[hookName]
|
|
110
|
+
];
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
mergeHooks('afterRead');
|
|
114
|
+
mergeHooks('afterChange');
|
|
115
|
+
mergeHooks('beforeChange');
|
|
116
|
+
mergeHooks('beforeValidate');
|
|
117
|
+
mergeHooks('beforeDuplicate');
|
|
118
|
+
};
|
|
119
|
+
if (richTextSanitizationPromises) {
|
|
120
|
+
richTextSanitizationPromises.push(sanitizeRichText);
|
|
121
|
+
} else {
|
|
122
|
+
await sanitizeRichText(config);
|
|
111
123
|
}
|
|
112
124
|
}
|
|
113
|
-
// TODO: Handle sanitization for any lexical sub-fields here as well
|
|
114
125
|
if ('fields' in field && field.fields) {
|
|
115
|
-
field.fields = sanitizeFields({
|
|
126
|
+
field.fields = await sanitizeFields({
|
|
116
127
|
config,
|
|
117
128
|
existingFieldNames: fieldAffectsData(field) ? new Set() : existingFieldNames,
|
|
118
129
|
fields: field.fields,
|
|
119
130
|
requireFieldLevelRichTextEditor,
|
|
131
|
+
richTextSanitizationPromises,
|
|
120
132
|
validRelationships
|
|
121
133
|
});
|
|
122
134
|
}
|
|
123
135
|
if (field.type === 'tabs') {
|
|
124
|
-
|
|
125
|
-
const
|
|
126
|
-
...tab
|
|
127
|
-
};
|
|
136
|
+
for(let j = 0; j < field.tabs.length; j++){
|
|
137
|
+
const tab = field.tabs[j];
|
|
128
138
|
if (tabHasName(tab) && typeof tab.label === 'undefined') {
|
|
129
|
-
|
|
139
|
+
tab.label = toWords(tab.name);
|
|
130
140
|
}
|
|
131
|
-
|
|
141
|
+
tab.fields = await sanitizeFields({
|
|
132
142
|
config,
|
|
133
143
|
existingFieldNames: tabHasName(tab) ? new Set() : existingFieldNames,
|
|
134
144
|
fields: tab.fields,
|
|
135
145
|
requireFieldLevelRichTextEditor,
|
|
146
|
+
richTextSanitizationPromises,
|
|
136
147
|
validRelationships
|
|
137
148
|
});
|
|
138
|
-
|
|
139
|
-
}
|
|
149
|
+
field.tabs[j] = tab;
|
|
150
|
+
}
|
|
140
151
|
}
|
|
141
152
|
if ('blocks' in field && field.blocks) {
|
|
142
|
-
|
|
143
|
-
const
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
unsanitizedBlock.labels = !unsanitizedBlock.labels ? formatLabels(unsanitizedBlock.slug) : unsanitizedBlock.labels;
|
|
147
|
-
unsanitizedBlock.fields = sanitizeFields({
|
|
153
|
+
for(let j = 0; j < field.blocks.length; j++){
|
|
154
|
+
const block = field.blocks[j];
|
|
155
|
+
block.labels = !block.labels ? formatLabels(block.slug) : block.labels;
|
|
156
|
+
block.fields = await sanitizeFields({
|
|
148
157
|
config,
|
|
149
158
|
existingFieldNames: new Set(),
|
|
150
159
|
fields: block.fields,
|
|
151
160
|
requireFieldLevelRichTextEditor,
|
|
161
|
+
richTextSanitizationPromises,
|
|
152
162
|
validRelationships
|
|
153
163
|
});
|
|
154
|
-
|
|
155
|
-
}
|
|
164
|
+
field.blocks[j] = block;
|
|
165
|
+
}
|
|
156
166
|
}
|
|
157
|
-
|
|
158
|
-
}
|
|
167
|
+
fields[i] = field;
|
|
168
|
+
}
|
|
169
|
+
return fields;
|
|
159
170
|
};
|
|
160
171
|
|
|
161
172
|
//# sourceMappingURL=sanitize.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/fields/config/sanitize.ts"],"sourcesContent":["import type { Config } from '../../config/types.js'\nimport type { Field } from './types.js'\n\nimport MissingEditorProp from '../../errors/MissingEditorProp.js'\nimport {\n DuplicateFieldName,\n InvalidFieldName,\n InvalidFieldRelationship,\n MissingFieldType,\n} from '../../errors/index.js'\nimport { formatLabels, toWords } from '../../utilities/formatLabels.js'\nimport { baseBlockFields } from '../baseFields/baseBlockFields.js'\nimport { baseIDField } from '../baseFields/baseIDField.js'\nimport { setDefaultBeforeDuplicate } from '../setDefaultBeforeDuplicate.js'\nimport validations from '../validations.js'\nimport { fieldAffectsData, tabHasName } from './types.js'\n\ntype Args = {\n config: Config\n existingFieldNames?: Set<string>\n fields: Field[]\n /**\n * If true, a richText field will require an editor property to be set, as the sanitizeFields function will not add it from the payload config if not present.\n *\n * @default false\n */\n requireFieldLevelRichTextEditor?: boolean\n /**\n * If not null, will validate that upload and relationship fields do not relate to a collection that is not in this array.\n * This validation will be skipped if validRelationships is null.\n */\n validRelationships: null | string[]\n}\n\nexport const sanitizeFields = ({\n config,\n existingFieldNames = new Set(),\n fields,\n requireFieldLevelRichTextEditor = false,\n validRelationships,\n}: Args): Field[] => {\n if (!fields) return []\n\n return fields.map((unsanitizedField) => {\n const field: Field = { ...unsanitizedField }\n\n if (!field.type) throw new MissingFieldType(field)\n\n // assert that field names do not contain forbidden characters\n if (fieldAffectsData(field) && field.name.includes('.')) {\n throw new InvalidFieldName(field, field.name)\n }\n\n // Auto-label\n if (\n 'name' in field &&\n field.name &&\n typeof field.label !== 'object' &&\n typeof field.label !== 'string' &&\n field.label !== false\n ) {\n field.label = toWords(field.name)\n }\n\n if (\n field.type === 'checkbox' &&\n typeof field.defaultValue === 'undefined' &&\n field.required === true\n ) {\n field.defaultValue = false\n }\n\n if (field.type === 'relationship' || field.type === 'upload') {\n if (validRelationships) {\n const relationships = Array.isArray(field.relationTo)\n ? field.relationTo\n : [field.relationTo]\n relationships.forEach((relationship: string) => {\n if (!validRelationships.includes(relationship)) {\n throw new InvalidFieldRelationship(field, relationship)\n }\n })\n }\n\n if (field.type === 'relationship') {\n if (field.min && !field.minRows) {\n console.warn(\n `(payload): The \"min\" property is deprecated for the Relationship field \"${field.name}\" and will be removed in a future version. Please use \"minRows\" instead.`,\n )\n }\n if (field.max && !field.maxRows) {\n console.warn(\n `(payload): The \"max\" property is deprecated for the Relationship field \"${field.name}\" and will be removed in a future version. Please use \"maxRows\" instead.`,\n )\n }\n field.minRows = field.minRows || field.min\n field.maxRows = field.maxRows || field.max\n }\n }\n\n if (field.type === 'blocks' && field.blocks) {\n field.blocks = field.blocks.map((block) => ({\n ...block,\n fields: block.fields.concat(baseBlockFields),\n }))\n }\n\n if (field.type === 'array' && field.fields) {\n field.fields.push(baseIDField)\n }\n\n if ((field.type === 'blocks' || field.type === 'array') && field.label) {\n field.labels = field.labels || formatLabels(field.name)\n }\n\n if (fieldAffectsData(field)) {\n if (existingFieldNames.has(field.name)) {\n throw new DuplicateFieldName(field.name)\n } else if (!['blockName', 'id'].includes(field.name)) {\n existingFieldNames.add(field.name)\n }\n\n if (field.localized && !config.localization) delete field.localized\n\n if (typeof field.validate === 'undefined') {\n const defaultValidate = validations[field.type]\n if (defaultValidate) {\n field.validate = (val, options) => defaultValidate(val, { ...field, ...options })\n } else {\n field.validate = () => true\n }\n }\n\n if (!field.hooks) field.hooks = {}\n if (!field.access) field.access = {}\n\n setDefaultBeforeDuplicate(field)\n }\n\n if (!field.admin) {\n field.admin = {}\n }\n\n // Make sure that the richText field has an editor\n if (field.type === 'richText') {\n if (!field.editor) {\n if (config.editor && !requireFieldLevelRichTextEditor) {\n field.editor = config.editor\n } else {\n throw new MissingEditorProp(field)\n }\n }\n\n // Add editor adapter hooks to field hooks\n if (!field.hooks) field.hooks = {}\n\n if (field?.editor?.hooks?.afterRead?.length) {\n field.hooks.afterRead = field.hooks.afterRead\n ? field.hooks.afterRead.concat(field.editor.hooks.afterRead)\n : field.editor.hooks.afterRead\n }\n if (field?.editor?.hooks?.beforeChange?.length) {\n field.hooks.beforeChange = field.hooks.beforeChange\n ? field.hooks.beforeChange.concat(field.editor.hooks.beforeChange)\n : field.editor.hooks.beforeChange\n }\n if (field?.editor?.hooks?.beforeValidate?.length) {\n field.hooks.beforeValidate = field.hooks.beforeValidate\n ? field.hooks.beforeValidate.concat(field.editor.hooks.beforeValidate)\n : field.editor.hooks.beforeValidate\n }\n if (field?.editor?.hooks?.beforeChange?.length) {\n field.hooks.beforeChange = field.hooks.beforeChange\n ? field.hooks.beforeChange.concat(field.editor.hooks.beforeChange)\n : field.editor.hooks.beforeChange\n }\n }\n\n // TODO: Handle sanitization for any lexical sub-fields here as well\n if ('fields' in field && field.fields) {\n field.fields = sanitizeFields({\n config,\n existingFieldNames: fieldAffectsData(field) ? new Set() : existingFieldNames,\n fields: field.fields,\n requireFieldLevelRichTextEditor,\n validRelationships,\n })\n }\n\n if (field.type === 'tabs') {\n field.tabs = field.tabs.map((tab) => {\n const unsanitizedTab = { ...tab }\n if (tabHasName(tab) && typeof tab.label === 'undefined') {\n unsanitizedTab.label = toWords(tab.name)\n }\n\n unsanitizedTab.fields = sanitizeFields({\n config,\n existingFieldNames: tabHasName(tab) ? new Set() : existingFieldNames,\n fields: tab.fields,\n requireFieldLevelRichTextEditor,\n validRelationships,\n })\n\n return unsanitizedTab\n })\n }\n\n if ('blocks' in field && field.blocks) {\n field.blocks = field.blocks.map((block) => {\n const unsanitizedBlock = { ...block }\n unsanitizedBlock.labels = !unsanitizedBlock.labels\n ? formatLabels(unsanitizedBlock.slug)\n : unsanitizedBlock.labels\n\n unsanitizedBlock.fields = sanitizeFields({\n config,\n existingFieldNames: new Set(),\n fields: block.fields,\n requireFieldLevelRichTextEditor,\n validRelationships,\n })\n\n return unsanitizedBlock\n })\n }\n\n return field\n })\n}\n"],"names":["MissingEditorProp","DuplicateFieldName","InvalidFieldName","InvalidFieldRelationship","MissingFieldType","formatLabels","toWords","baseBlockFields","baseIDField","setDefaultBeforeDuplicate","validations","fieldAffectsData","tabHasName","sanitizeFields","config","existingFieldNames","Set","fields","requireFieldLevelRichTextEditor","validRelationships","map","unsanitizedField","field","type","name","includes","label","defaultValue","required","relationships","Array","isArray","relationTo","forEach","relationship","min","minRows","console","warn","max","maxRows","blocks","block","concat","push","labels","has","add","localized","localization","validate","defaultValidate","val","options","hooks","access","admin","editor","afterRead","length","beforeChange","beforeValidate","tabs","tab","unsanitizedTab","unsanitizedBlock","slug"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAGA,OAAOA,uBAAuB,oCAAmC;AACjE,SACEC,kBAAkB,EAClBC,gBAAgB,EAChBC,wBAAwB,EACxBC,gBAAgB,QACX,wBAAuB;AAC9B,SAASC,YAAY,EAAEC,OAAO,QAAQ,kCAAiC;AACvE,SAASC,eAAe,QAAQ,mCAAkC;AAClE,SAASC,WAAW,QAAQ,+BAA8B;AAC1D,SAASC,yBAAyB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D,GAAG;gBAAC;gBAChC,IAAInD,WAAWmD,QAAQ,OAAOA,IAAIrC,KAAK,KAAK,aAAa;oBACvDsC,eAAetC,KAAK,GAAGpB,QAAQyD,IAAIvC,IAAI;gBACzC;gBAEAwC,eAAe/C,MAAM,GAAGJ,eAAe;oBACrCC;oBACAC,oBAAoBH,WAAWmD,OAAO,IAAI/C,QAAQD;oBAClDE,QAAQ8C,IAAI9C,MAAM;oBAClBC;oBACAC;gBACF;gBAEA,OAAO6C;YACT;QACF;QAEA,IAAI,YAAY1C,SAASA,MAAMmB,MAAM,EAAE;YACrCnB,MAAMmB,MAAM,GAAGnB,MAAMmB,MAAM,CAACrB,GAAG,CAAC,CAACsB;gBAC/B,MAAMuB,mBAAmB;oBAAE,GAAGvB,KAAK;gBAAC;gBACpCuB,iBAAiBpB,MAAM,GAAG,CAACoB,iBAAiBpB,MAAM,GAC9CxC,aAAa4D,iBAAiBC,IAAI,IAClCD,iBAAiBpB,MAAM;gBAE3BoB,iBAAiBhD,MAAM,GAAGJ,eAAe;oBACvCC;oBACAC,oBAAoB,IAAIC;oBACxBC,QAAQyB,MAAMzB,MAAM;oBACpBC;oBACAC;gBACF;gBAEA,OAAO8C;YACT;QACF;QAEA,OAAO3C;IACT;AACF,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../../src/fields/config/sanitize.ts"],"sourcesContent":["import type { Config, SanitizedConfig } from '../../config/types.js'\nimport type { Field } from './types.js'\n\nimport { MissingEditorProp } from '../../errors/MissingEditorProp.js'\nimport {\n DuplicateFieldName,\n InvalidFieldName,\n InvalidFieldRelationship,\n MissingFieldType,\n} from '../../errors/index.js'\nimport { formatLabels, toWords } from '../../utilities/formatLabels.js'\nimport { baseBlockFields } from '../baseFields/baseBlockFields.js'\nimport { baseIDField } from '../baseFields/baseIDField.js'\nimport { setDefaultBeforeDuplicate } from '../setDefaultBeforeDuplicate.js'\nimport validations from '../validations.js'\nimport { fieldAffectsData, tabHasName } from './types.js'\n\ntype Args = {\n config: Config\n existingFieldNames?: Set<string>\n fields: Field[]\n /**\n * If true, a richText field will require an editor property to be set, as the sanitizeFields function will not add it from the payload config if not present.\n *\n * @default false\n */\n requireFieldLevelRichTextEditor?: boolean\n /**\n * If this property is set, RichText fields won't be sanitized immediately. Instead, they will be added to this array as promises\n * so that you can sanitize them together, after the config has been sanitized.\n */\n richTextSanitizationPromises?: Array<(config: SanitizedConfig) => Promise<void>>\n\n /**\n * If not null, will validate that upload and relationship fields do not relate to a collection that is not in this array.\n * This validation will be skipped if validRelationships is null.\n */\n validRelationships: null | string[]\n}\n\nexport const sanitizeFields = async ({\n config,\n existingFieldNames = new Set(),\n fields,\n requireFieldLevelRichTextEditor = false,\n richTextSanitizationPromises,\n validRelationships,\n}: Args): Promise<Field[]> => {\n if (!fields) return []\n\n for (let i = 0; i < fields.length; i++) {\n const field = fields[i]\n\n if (!field.type) throw new MissingFieldType(field)\n\n // assert that field names do not contain forbidden characters\n if (fieldAffectsData(field) && field.name.includes('.')) {\n throw new InvalidFieldName(field, field.name)\n }\n\n // Auto-label\n if (\n 'name' in field &&\n field.name &&\n typeof field.label !== 'object' &&\n typeof field.label !== 'string' &&\n field.label !== false\n ) {\n field.label = toWords(field.name)\n }\n\n if (\n field.type === 'checkbox' &&\n typeof field.defaultValue === 'undefined' &&\n field.required === true\n ) {\n field.defaultValue = false\n }\n\n if (field.type === 'relationship' || field.type === 'upload') {\n if (validRelationships) {\n const relationships = Array.isArray(field.relationTo)\n ? field.relationTo\n : [field.relationTo]\n relationships.forEach((relationship: string) => {\n if (!validRelationships.includes(relationship)) {\n throw new InvalidFieldRelationship(field, relationship)\n }\n })\n }\n\n if (field.type === 'relationship') {\n if (field.min && !field.minRows) {\n console.warn(\n `(payload): The \"min\" property is deprecated for the Relationship field \"${field.name}\" and will be removed in a future version. Please use \"minRows\" instead.`,\n )\n }\n if (field.max && !field.maxRows) {\n console.warn(\n `(payload): The \"max\" property is deprecated for the Relationship field \"${field.name}\" and will be removed in a future version. Please use \"maxRows\" instead.`,\n )\n }\n field.minRows = field.minRows || field.min\n field.maxRows = field.maxRows || field.max\n }\n }\n\n if (field.type === 'blocks' && field.blocks) {\n field.blocks = field.blocks.map((block) => ({\n ...block,\n fields: block.fields.concat(baseBlockFields),\n }))\n }\n\n if (field.type === 'array' && field.fields) {\n field.fields.push(baseIDField)\n }\n\n if ((field.type === 'blocks' || field.type === 'array') && field.label) {\n field.labels = field.labels || formatLabels(field.name)\n }\n\n if (fieldAffectsData(field)) {\n if (existingFieldNames.has(field.name)) {\n throw new DuplicateFieldName(field.name)\n } else if (!['blockName', 'id'].includes(field.name)) {\n existingFieldNames.add(field.name)\n }\n\n if (field.localized && !config.localization) delete field.localized\n\n if (typeof field.validate === 'undefined') {\n const defaultValidate = validations[field.type]\n if (defaultValidate) {\n field.validate = (val, options) => defaultValidate(val, { ...field, ...options })\n } else {\n field.validate = () => true\n }\n }\n\n if (!field.hooks) field.hooks = {}\n if (!field.access) field.access = {}\n\n setDefaultBeforeDuplicate(field)\n }\n\n if (!field.admin) {\n field.admin = {}\n }\n\n // Make sure that the richText field has an editor\n if (field.type === 'richText') {\n const sanitizeRichText = async (_config: SanitizedConfig) => {\n if (!field.editor) {\n if (_config.editor && !requireFieldLevelRichTextEditor) {\n // config.editor should be sanitized at this point\n field.editor = _config.editor\n } else {\n throw new MissingEditorProp(field)\n }\n }\n\n if (typeof field.editor === 'function') {\n field.editor = await field.editor({ config: _config })\n }\n\n // Add editor adapter hooks to field hooks\n if (!field.hooks) field.hooks = {}\n\n const mergeHooks = (hookName: keyof typeof field.editor.hooks) => {\n if (typeof field.editor === 'function') return\n\n if (field.editor?.hooks?.[hookName]?.length) {\n field.hooks[hookName] = field.hooks[hookName]\n ? field.hooks[hookName].concat(field.editor.hooks[hookName])\n : [...field.editor.hooks[hookName]]\n }\n }\n\n mergeHooks('afterRead')\n mergeHooks('afterChange')\n mergeHooks('beforeChange')\n mergeHooks('beforeValidate')\n mergeHooks('beforeDuplicate')\n }\n if (richTextSanitizationPromises) {\n richTextSanitizationPromises.push(sanitizeRichText)\n } else {\n await sanitizeRichText(config as unknown as SanitizedConfig)\n }\n }\n\n if ('fields' in field && field.fields) {\n field.fields = await sanitizeFields({\n config,\n existingFieldNames: fieldAffectsData(field) ? new Set() : existingFieldNames,\n fields: field.fields,\n requireFieldLevelRichTextEditor,\n richTextSanitizationPromises,\n validRelationships,\n })\n }\n\n if (field.type === 'tabs') {\n for (let j = 0; j < field.tabs.length; j++) {\n const tab = field.tabs[j]\n if (tabHasName(tab) && typeof tab.label === 'undefined') {\n tab.label = toWords(tab.name)\n }\n\n tab.fields = await sanitizeFields({\n config,\n existingFieldNames: tabHasName(tab) ? new Set() : existingFieldNames,\n fields: tab.fields,\n requireFieldLevelRichTextEditor,\n richTextSanitizationPromises,\n validRelationships,\n })\n field.tabs[j] = tab\n }\n }\n\n if ('blocks' in field && field.blocks) {\n for (let j = 0; j < field.blocks.length; j++) {\n const block = field.blocks[j]\n block.labels = !block.labels ? formatLabels(block.slug) : block.labels\n\n block.fields = await sanitizeFields({\n config,\n existingFieldNames: new Set(),\n fields: block.fields,\n requireFieldLevelRichTextEditor,\n richTextSanitizationPromises,\n validRelationships,\n })\n field.blocks[j] = block\n }\n }\n\n fields[i] = field\n }\n\n return fields\n}\n"],"names":["MissingEditorProp","DuplicateFieldName","InvalidFieldName","InvalidFieldRelationship","MissingFieldType","formatLabels","toWords","baseBlockFields","baseIDField","setDefaultBeforeDuplicate","validations","fieldAffectsData","tabHasName","sanitizeFields","config","existingFieldNames","Set","fields","requireFieldLevelRichTextEditor","richTextSanitizationPromises","validRelationships","i","length","field","type","name","includes","label","defaultValue","required","relationships","Array","isArray","relationTo","forEach","relationship","min","minRows","console","warn","max","maxRows","blocks","map","block","concat","push","labels","has","add","localized","localization","validate","defaultValidate","val","options","hooks","access","admin","sanitizeRichText","_config","editor","mergeHooks","hookName","j","tabs","tab","slug"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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QAAQ;YACzB,IAAK,IAAIwC,IAAI,GAAGA,IAAIzC,MAAM0C,IAAI,CAAC3C,MAAM,EAAE0C,IAAK;gBAC1C,MAAME,MAAM3C,MAAM0C,IAAI,CAACD,EAAE;gBACzB,IAAIpD,WAAWsD,QAAQ,OAAOA,IAAIvC,KAAK,KAAK,aAAa;oBACvDuC,IAAIvC,KAAK,GAAGrB,QAAQ4D,IAAIzC,IAAI;gBAC9B;gBAEAyC,IAAIjD,MAAM,GAAG,MAAMJ,eAAe;oBAChCC;oBACAC,oBAAoBH,WAAWsD,OAAO,IAAIlD,QAAQD;oBAClDE,QAAQiD,IAAIjD,MAAM;oBAClBC;oBACAC;oBACAC;gBACF;gBACAG,MAAM0C,IAAI,CAACD,EAAE,GAAGE;YAClB;QACF;QAEA,IAAI,YAAY3C,SAASA,MAAMmB,MAAM,EAAE;YACrC,IAAK,IAAIsB,IAAI,GAAGA,IAAIzC,MAAMmB,MAAM,CAACpB,MAAM,EAAE0C,IAAK;gBAC5C,MAAMpB,QAAQrB,MAAMmB,MAAM,CAACsB,EAAE;gBAC7BpB,MAAMG,MAAM,GAAG,CAACH,MAAMG,MAAM,GAAG1C,aAAauC,MAAMuB,IAAI,IAAIvB,MAAMG,MAAM;gBAEtEH,MAAM3B,MAAM,GAAG,MAAMJ,eAAe;oBAClCC;oBACAC,oBAAoB,IAAIC;oBACxBC,QAAQ2B,MAAM3B,MAAM;oBACpBC;oBACAC;oBACAC;gBACF;gBACAG,MAAMmB,MAAM,CAACsB,EAAE,GAAGpB;YACpB;QACF;QAEA3B,MAAM,CAACI,EAAE,GAAGE;IACd;IAEA,OAAON;AACT,EAAC"}
|
|
@@ -1,33 +1,24 @@
|
|
|
1
|
-
import { InvalidFieldName, InvalidFieldRelationship, MissingFieldType } from '../../errors';
|
|
2
|
-
import { sanitizeFields } from './sanitize';
|
|
3
|
-
const dummyConfig = {
|
|
4
|
-
collections: [],
|
|
5
|
-
db: {
|
|
6
|
-
defaultIDType: 'text',
|
|
7
|
-
init: ()=>({})
|
|
8
|
-
}
|
|
9
|
-
};
|
|
1
|
+
import { InvalidFieldName, InvalidFieldRelationship, MissingFieldType } from '../../errors/index.js';
|
|
2
|
+
import { sanitizeFields } from './sanitize.js';
|
|
10
3
|
describe('sanitizeFields', ()=>{
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
// @ts-ignore
|
|
4
|
+
const config = {};
|
|
5
|
+
it('should throw on missing type field', async ()=>{
|
|
14
6
|
const fields = [
|
|
7
|
+
// @ts-expect-error
|
|
15
8
|
{
|
|
16
9
|
label: 'some-collection',
|
|
17
10
|
name: 'Some Collection'
|
|
18
11
|
}
|
|
19
12
|
];
|
|
20
|
-
expect(()=>{
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
sanitizeFields({
|
|
24
|
-
config: dummyConfig,
|
|
13
|
+
await expect(async ()=>{
|
|
14
|
+
await sanitizeFields({
|
|
15
|
+
config,
|
|
25
16
|
fields,
|
|
26
17
|
validRelationships: []
|
|
27
18
|
});
|
|
28
|
-
}).toThrow(MissingFieldType);
|
|
19
|
+
}).rejects.toThrow(MissingFieldType);
|
|
29
20
|
});
|
|
30
|
-
it('should throw on invalid field name', ()=>{
|
|
21
|
+
it('should throw on invalid field name', async ()=>{
|
|
31
22
|
const fields = [
|
|
32
23
|
{
|
|
33
24
|
label: 'some.collection',
|
|
@@ -35,32 +26,32 @@ describe('sanitizeFields', ()=>{
|
|
|
35
26
|
type: 'text'
|
|
36
27
|
}
|
|
37
28
|
];
|
|
38
|
-
expect(()=>{
|
|
39
|
-
sanitizeFields({
|
|
40
|
-
config
|
|
29
|
+
await expect(async ()=>{
|
|
30
|
+
await sanitizeFields({
|
|
31
|
+
config,
|
|
41
32
|
fields,
|
|
42
33
|
validRelationships: []
|
|
43
34
|
});
|
|
44
|
-
}).toThrow(InvalidFieldName);
|
|
35
|
+
}).rejects.toThrow(InvalidFieldName);
|
|
45
36
|
});
|
|
46
37
|
describe('auto-labeling', ()=>{
|
|
47
|
-
it('should populate label if missing', ()=>{
|
|
38
|
+
it('should populate label if missing', async ()=>{
|
|
48
39
|
const fields = [
|
|
49
40
|
{
|
|
50
41
|
name: 'someField',
|
|
51
42
|
type: 'text'
|
|
52
43
|
}
|
|
53
44
|
];
|
|
54
|
-
const sanitizedField = sanitizeFields({
|
|
55
|
-
config
|
|
45
|
+
const sanitizedField = (await sanitizeFields({
|
|
46
|
+
config,
|
|
56
47
|
fields,
|
|
57
48
|
validRelationships: []
|
|
58
|
-
})[0];
|
|
49
|
+
}))[0];
|
|
59
50
|
expect(sanitizedField.name).toStrictEqual('someField');
|
|
60
51
|
expect(sanitizedField.label).toStrictEqual('Some Field');
|
|
61
52
|
expect(sanitizedField.type).toStrictEqual('text');
|
|
62
53
|
});
|
|
63
|
-
it('should allow auto-label override', ()=>{
|
|
54
|
+
it('should allow auto-label override', async ()=>{
|
|
64
55
|
const fields = [
|
|
65
56
|
{
|
|
66
57
|
label: 'Do not label',
|
|
@@ -68,17 +59,17 @@ describe('sanitizeFields', ()=>{
|
|
|
68
59
|
type: 'text'
|
|
69
60
|
}
|
|
70
61
|
];
|
|
71
|
-
const sanitizedField = sanitizeFields({
|
|
72
|
-
config
|
|
62
|
+
const sanitizedField = (await sanitizeFields({
|
|
63
|
+
config,
|
|
73
64
|
fields,
|
|
74
65
|
validRelationships: []
|
|
75
|
-
})[0];
|
|
66
|
+
}))[0];
|
|
76
67
|
expect(sanitizedField.name).toStrictEqual('someField');
|
|
77
68
|
expect(sanitizedField.label).toStrictEqual('Do not label');
|
|
78
69
|
expect(sanitizedField.type).toStrictEqual('text');
|
|
79
70
|
});
|
|
80
71
|
describe('opt-out', ()=>{
|
|
81
|
-
it('should allow label opt-out', ()=>{
|
|
72
|
+
it('should allow label opt-out', async ()=>{
|
|
82
73
|
const fields = [
|
|
83
74
|
{
|
|
84
75
|
label: false,
|
|
@@ -86,16 +77,16 @@ describe('sanitizeFields', ()=>{
|
|
|
86
77
|
type: 'text'
|
|
87
78
|
}
|
|
88
79
|
];
|
|
89
|
-
const sanitizedField = sanitizeFields({
|
|
90
|
-
config
|
|
80
|
+
const sanitizedField = (await sanitizeFields({
|
|
81
|
+
config,
|
|
91
82
|
fields,
|
|
92
83
|
validRelationships: []
|
|
93
|
-
})[0];
|
|
84
|
+
}))[0];
|
|
94
85
|
expect(sanitizedField.name).toStrictEqual('someField');
|
|
95
86
|
expect(sanitizedField.label).toStrictEqual(false);
|
|
96
87
|
expect(sanitizedField.type).toStrictEqual('text');
|
|
97
88
|
});
|
|
98
|
-
it('should allow label opt-out for arrays', ()=>{
|
|
89
|
+
it('should allow label opt-out for arrays', async ()=>{
|
|
99
90
|
const arrayField = {
|
|
100
91
|
fields: [
|
|
101
92
|
{
|
|
@@ -107,19 +98,19 @@ describe('sanitizeFields', ()=>{
|
|
|
107
98
|
name: 'items',
|
|
108
99
|
type: 'array'
|
|
109
100
|
};
|
|
110
|
-
const sanitizedField = sanitizeFields({
|
|
111
|
-
config
|
|
101
|
+
const sanitizedField = (await sanitizeFields({
|
|
102
|
+
config,
|
|
112
103
|
fields: [
|
|
113
104
|
arrayField
|
|
114
105
|
],
|
|
115
106
|
validRelationships: []
|
|
116
|
-
})[0];
|
|
107
|
+
}))[0];
|
|
117
108
|
expect(sanitizedField.name).toStrictEqual('items');
|
|
118
109
|
expect(sanitizedField.label).toStrictEqual(false);
|
|
119
110
|
expect(sanitizedField.type).toStrictEqual('array');
|
|
120
111
|
expect(sanitizedField.labels).toBeUndefined();
|
|
121
112
|
});
|
|
122
|
-
it('should allow label opt-out for blocks', ()=>{
|
|
113
|
+
it('should allow label opt-out for blocks', async ()=>{
|
|
123
114
|
const fields = [
|
|
124
115
|
{
|
|
125
116
|
blocks: [
|
|
@@ -138,18 +129,18 @@ describe('sanitizeFields', ()=>{
|
|
|
138
129
|
type: 'blocks'
|
|
139
130
|
}
|
|
140
131
|
];
|
|
141
|
-
const sanitizedField = sanitizeFields({
|
|
142
|
-
config
|
|
132
|
+
const sanitizedField = (await sanitizeFields({
|
|
133
|
+
config,
|
|
143
134
|
fields,
|
|
144
135
|
validRelationships: []
|
|
145
|
-
})[0];
|
|
136
|
+
}))[0];
|
|
146
137
|
expect(sanitizedField.name).toStrictEqual('noLabelBlock');
|
|
147
138
|
expect(sanitizedField.label).toStrictEqual(false);
|
|
148
139
|
expect(sanitizedField.type).toStrictEqual('blocks');
|
|
149
140
|
expect(sanitizedField.labels).toBeUndefined();
|
|
150
141
|
});
|
|
151
142
|
});
|
|
152
|
-
it('should label arrays with plural and singular', ()=>{
|
|
143
|
+
it('should label arrays with plural and singular', async ()=>{
|
|
153
144
|
const fields = [
|
|
154
145
|
{
|
|
155
146
|
fields: [
|
|
@@ -162,11 +153,11 @@ describe('sanitizeFields', ()=>{
|
|
|
162
153
|
type: 'array'
|
|
163
154
|
}
|
|
164
155
|
];
|
|
165
|
-
const sanitizedField = sanitizeFields({
|
|
166
|
-
config
|
|
156
|
+
const sanitizedField = (await sanitizeFields({
|
|
157
|
+
config,
|
|
167
158
|
fields,
|
|
168
159
|
validRelationships: []
|
|
169
|
-
})[0];
|
|
160
|
+
}))[0];
|
|
170
161
|
expect(sanitizedField.name).toStrictEqual('items');
|
|
171
162
|
expect(sanitizedField.label).toStrictEqual('Items');
|
|
172
163
|
expect(sanitizedField.type).toStrictEqual('array');
|
|
@@ -175,7 +166,7 @@ describe('sanitizeFields', ()=>{
|
|
|
175
166
|
singular: 'Item'
|
|
176
167
|
});
|
|
177
168
|
});
|
|
178
|
-
it('should label blocks with plural and singular', ()=>{
|
|
169
|
+
it('should label blocks with plural and singular', async ()=>{
|
|
179
170
|
const fields = [
|
|
180
171
|
{
|
|
181
172
|
blocks: [
|
|
@@ -193,11 +184,11 @@ describe('sanitizeFields', ()=>{
|
|
|
193
184
|
type: 'blocks'
|
|
194
185
|
}
|
|
195
186
|
];
|
|
196
|
-
const sanitizedField = sanitizeFields({
|
|
197
|
-
config
|
|
187
|
+
const sanitizedField = (await sanitizeFields({
|
|
188
|
+
config,
|
|
198
189
|
fields,
|
|
199
190
|
validRelationships: []
|
|
200
|
-
})[0];
|
|
191
|
+
}))[0];
|
|
201
192
|
expect(sanitizedField.name).toStrictEqual('specialBlock');
|
|
202
193
|
expect(sanitizedField.label).toStrictEqual('Special Block');
|
|
203
194
|
expect(sanitizedField.type).toStrictEqual('blocks');
|
|
@@ -209,7 +200,7 @@ describe('sanitizeFields', ()=>{
|
|
|
209
200
|
});
|
|
210
201
|
});
|
|
211
202
|
describe('relationships', ()=>{
|
|
212
|
-
it('should not throw on valid relationship', ()=>{
|
|
203
|
+
it('should not throw on valid relationship', async ()=>{
|
|
213
204
|
const validRelationships = [
|
|
214
205
|
'some-collection'
|
|
215
206
|
];
|
|
@@ -221,15 +212,15 @@ describe('sanitizeFields', ()=>{
|
|
|
221
212
|
type: 'relationship'
|
|
222
213
|
}
|
|
223
214
|
];
|
|
224
|
-
expect(()=>{
|
|
225
|
-
sanitizeFields({
|
|
226
|
-
config
|
|
215
|
+
await expect(async ()=>{
|
|
216
|
+
await sanitizeFields({
|
|
217
|
+
config,
|
|
227
218
|
fields,
|
|
228
219
|
validRelationships
|
|
229
220
|
});
|
|
230
221
|
}).not.toThrow();
|
|
231
222
|
});
|
|
232
|
-
it('should not throw on valid relationship - multiple', ()=>{
|
|
223
|
+
it('should not throw on valid relationship - multiple', async ()=>{
|
|
233
224
|
const validRelationships = [
|
|
234
225
|
'some-collection',
|
|
235
226
|
'another-collection'
|
|
@@ -245,15 +236,15 @@ describe('sanitizeFields', ()=>{
|
|
|
245
236
|
type: 'relationship'
|
|
246
237
|
}
|
|
247
238
|
];
|
|
248
|
-
expect(()=>{
|
|
249
|
-
sanitizeFields({
|
|
250
|
-
config
|
|
239
|
+
await expect(async ()=>{
|
|
240
|
+
await sanitizeFields({
|
|
241
|
+
config,
|
|
251
242
|
fields,
|
|
252
243
|
validRelationships
|
|
253
244
|
});
|
|
254
245
|
}).not.toThrow();
|
|
255
246
|
});
|
|
256
|
-
it('should not throw on valid relationship inside blocks', ()=>{
|
|
247
|
+
it('should not throw on valid relationship inside blocks', async ()=>{
|
|
257
248
|
const validRelationships = [
|
|
258
249
|
'some-collection'
|
|
259
250
|
];
|
|
@@ -278,15 +269,15 @@ describe('sanitizeFields', ()=>{
|
|
|
278
269
|
type: 'blocks'
|
|
279
270
|
}
|
|
280
271
|
];
|
|
281
|
-
expect(()=>{
|
|
282
|
-
sanitizeFields({
|
|
283
|
-
config
|
|
272
|
+
await expect(async ()=>{
|
|
273
|
+
await sanitizeFields({
|
|
274
|
+
config,
|
|
284
275
|
fields,
|
|
285
276
|
validRelationships
|
|
286
277
|
});
|
|
287
278
|
}).not.toThrow();
|
|
288
279
|
});
|
|
289
|
-
it('should throw on invalid relationship', ()=>{
|
|
280
|
+
it('should throw on invalid relationship', async ()=>{
|
|
290
281
|
const validRelationships = [
|
|
291
282
|
'some-collection'
|
|
292
283
|
];
|
|
@@ -298,15 +289,15 @@ describe('sanitizeFields', ()=>{
|
|
|
298
289
|
type: 'relationship'
|
|
299
290
|
}
|
|
300
291
|
];
|
|
301
|
-
expect(()=>{
|
|
302
|
-
sanitizeFields({
|
|
303
|
-
config
|
|
292
|
+
await expect(async ()=>{
|
|
293
|
+
await sanitizeFields({
|
|
294
|
+
config,
|
|
304
295
|
fields,
|
|
305
296
|
validRelationships
|
|
306
297
|
});
|
|
307
|
-
}).toThrow(InvalidFieldRelationship);
|
|
298
|
+
}).rejects.toThrow(InvalidFieldRelationship);
|
|
308
299
|
});
|
|
309
|
-
it('should throw on invalid relationship - multiple', ()=>{
|
|
300
|
+
it('should throw on invalid relationship - multiple', async ()=>{
|
|
310
301
|
const validRelationships = [
|
|
311
302
|
'some-collection',
|
|
312
303
|
'another-collection'
|
|
@@ -322,15 +313,15 @@ describe('sanitizeFields', ()=>{
|
|
|
322
313
|
type: 'relationship'
|
|
323
314
|
}
|
|
324
315
|
];
|
|
325
|
-
expect(()=>{
|
|
326
|
-
sanitizeFields({
|
|
327
|
-
config
|
|
316
|
+
await expect(async ()=>{
|
|
317
|
+
await sanitizeFields({
|
|
318
|
+
config,
|
|
328
319
|
fields,
|
|
329
320
|
validRelationships
|
|
330
321
|
});
|
|
331
|
-
}).toThrow(InvalidFieldRelationship);
|
|
322
|
+
}).rejects.toThrow(InvalidFieldRelationship);
|
|
332
323
|
});
|
|
333
|
-
it('should throw on invalid relationship inside blocks', ()=>{
|
|
324
|
+
it('should throw on invalid relationship inside blocks', async ()=>{
|
|
334
325
|
const validRelationships = [
|
|
335
326
|
'some-collection'
|
|
336
327
|
];
|
|
@@ -355,15 +346,15 @@ describe('sanitizeFields', ()=>{
|
|
|
355
346
|
type: 'blocks'
|
|
356
347
|
}
|
|
357
348
|
];
|
|
358
|
-
expect(()=>{
|
|
359
|
-
sanitizeFields({
|
|
360
|
-
config
|
|
349
|
+
await expect(async ()=>{
|
|
350
|
+
await sanitizeFields({
|
|
351
|
+
config,
|
|
361
352
|
fields,
|
|
362
353
|
validRelationships
|
|
363
354
|
});
|
|
364
|
-
}).toThrow(InvalidFieldRelationship);
|
|
355
|
+
}).rejects.toThrow(InvalidFieldRelationship);
|
|
365
356
|
});
|
|
366
|
-
it('should defaultValue of checkbox to false if required and undefined', ()=>{
|
|
357
|
+
it('should defaultValue of checkbox to false if required and undefined', async ()=>{
|
|
367
358
|
const fields = [
|
|
368
359
|
{
|
|
369
360
|
name: 'My Checkbox',
|
|
@@ -371,16 +362,16 @@ describe('sanitizeFields', ()=>{
|
|
|
371
362
|
type: 'checkbox'
|
|
372
363
|
}
|
|
373
364
|
];
|
|
374
|
-
const sanitizedField = sanitizeFields({
|
|
375
|
-
config
|
|
365
|
+
const sanitizedField = (await sanitizeFields({
|
|
366
|
+
config,
|
|
376
367
|
fields,
|
|
377
368
|
validRelationships: []
|
|
378
|
-
})[0];
|
|
369
|
+
}))[0];
|
|
379
370
|
expect(sanitizedField.defaultValue).toStrictEqual(false);
|
|
380
371
|
});
|
|
381
|
-
it('should return empty field array if no fields', ()=>{
|
|
382
|
-
const sanitizedFields = sanitizeFields({
|
|
383
|
-
config
|
|
372
|
+
it('should return empty field array if no fields', async ()=>{
|
|
373
|
+
const sanitizedFields = await sanitizeFields({
|
|
374
|
+
config,
|
|
384
375
|
fields: [],
|
|
385
376
|
validRelationships: []
|
|
386
377
|
});
|