fix conflicts

This commit is contained in:
Elliot DeNolf
2020-11-20 12:02:31 -05:00
parent 5b22d91579
commit 38028dd36b
10 changed files with 122 additions and 38 deletions

View File

@@ -0,0 +1,12 @@
// No labels necessary
const AutoLabel = {
slug: 'auto-label',
fields: [{
name: 'text',
type: 'text',
label: 'Text',
}],
};
module.exports = AutoLabel;

View File

@@ -95,6 +95,7 @@
"passport-local-mongoose": "^6.0.1",
"pino": "^6.4.1",
"pino-pretty": "^4.1.0",
"pluralize": "^8.0.0",
"postcss-loader": "^4.0.4",
"postcss-preset-env": "^6.7.0",
"prismjs": "^1.21.0",

View File

@@ -1,5 +1,4 @@
const merge = require('deepmerge');
const { DuplicateCollection, MissingCollectionLabel } = require('../errors');
const sanitizeFields = require('../fields/sanitize');
const toKebabCase = require('../utilities/toKebabCase');
const baseAuthFields = require('../fields/baseFields/baseFields');
@@ -8,6 +7,7 @@ const baseVerificationFields = require('../fields/baseFields/baseVerificationFie
const baseAccountLockFields = require('../fields/baseFields/baseAccountLockFields');
const baseUploadFields = require('../fields/baseFields/baseUploadFields');
const baseImageUploadFields = require('../fields/baseFields/baseImageUploadFields');
const formatLabels = require('../utilities/formatLabels');
const mergeBaseFields = (fields, baseFields) => {
const mergedFields = [];
@@ -53,25 +53,13 @@ const mergeBaseFields = (fields, baseFields) => {
};
const sanitizeCollection = (collections, collection) => {
// /////////////////////////////////
// Ensure collection is valid
// /////////////////////////////////
if (!collection.labels.singular) {
throw new MissingCollectionLabel(collection);
}
if (collections && collections[collection.labels.singular]) {
throw new DuplicateCollection(collection);
}
// /////////////////////////////////
// Make copy of collection config
// /////////////////////////////////
const sanitized = { ...collection };
sanitized.slug = toKebabCase(sanitized.slug);
sanitized.labels = !sanitized.labels ? formatLabels(sanitized.slug) : sanitized.labels;
// /////////////////////////////////
// Ensure that collection has required object structure

View File

@@ -1,8 +1,8 @@
const APIError = require('./APIError');
class DuplicateCollection extends APIError {
constructor(config) {
super(`Collection name "${config.labels.singular}" is already in use`);
constructor(propertyName, duplicates) {
super(`Collection ${propertyName} already in use: "${duplicates.join(', ')}"`);
}
}

View File

@@ -5,7 +5,6 @@
"type": "object",
"required": [
"slug",
"labels",
"fields"
],
"properties": {

View File

@@ -0,0 +1,16 @@
const { DuplicateCollection } = require('../errors');
const getDuplicates = (arr) => arr.filter((item, index) => arr.indexOf(item) !== index);
const checkDuplicateCollections = (collections) => {
const duplicateSlugs = getDuplicates(collections.map((c) => c.slug));
if (duplicateSlugs.length > 0) {
throw new DuplicateCollection('slug', duplicateSlugs);
}
const duplicateLabels = getDuplicates(collections.map((c) => c.labels.singular));
if (duplicateLabels.length > 0) {
throw new DuplicateCollection('label', duplicateLabels);
}
};
module.exports = checkDuplicateCollections;

View File

@@ -0,0 +1,29 @@
const pluralize = require('pluralize');
const capitalizeFirstLetter = (string) => string.charAt(0).toUpperCase() + string.slice(1);
const toWords = (inputString) => {
const notNullString = inputString || '';
const trimmedString = notNullString.trim();
const arrayOfStrings = trimmedString.split(/[\s-]/);
const splitStringsArray = [];
arrayOfStrings.forEach((tempString) => {
if (tempString !== '') {
const splitWords = tempString.split(/(?=[A-Z])/).join(' ');
splitStringsArray.push(capitalizeFirstLetter(splitWords));
}
});
return splitStringsArray.join(' ');
};
const formatLabels = ((input) => {
const words = toWords(input);
return {
singular: words,
plural: pluralize(words),
};
});
module.exports = formatLabels;

View File

@@ -0,0 +1,31 @@
const formatLabels = require('./formatLabels');
describe('formatLabels', () => {
it('should format single word', () => {
expect(formatLabels('word')).toMatchObject({
singular: 'Word',
plural: 'Words',
});
});
it('should format already plural', () => {
expect(formatLabels('words')).toMatchObject({
singular: 'Words',
plural: 'Words',
});
});
it('should format kebab case', () => {
expect(formatLabels('kebab-item')).toMatchObject({
singular: 'Kebab Item',
plural: 'Kebab Items',
});
});
it('should format camelCase', () => {
expect(formatLabels('camelCaseItem')).toMatchObject({
singular: 'Camel Case Item',
plural: 'Camel Case Items',
});
});
});

View File

@@ -3,6 +3,7 @@ const sanitizeCollection = require('../collections/sanitize');
const { InvalidConfiguration } = require('../errors');
const sanitizeGlobals = require('../globals/sanitize');
const validateSchema = require('../schema/validateSchema');
const checkDuplicateCollections = require('./checkDuplicateCollections');
const sanitizeConfig = (config) => {
const sanitizedConfig = validateSchema({ ...config });
@@ -14,6 +15,7 @@ const sanitizeConfig = (config) => {
if (sanitizedConfig.maxDepth === undefined) sanitizedConfig.maxDepth = 10;
sanitizedConfig.collections = sanitizedConfig.collections.map((collection) => sanitizeCollection(sanitizedConfig.collections, collection));
checkDuplicateCollections(sanitizedConfig.collections);
if (sanitizedConfig.globals) {
sanitizedConfig.globals = sanitizeGlobals(sanitizedConfig.collections, sanitizedConfig.globals);

View File

@@ -1365,9 +1365,9 @@
type-detect "4.0.8"
"@testing-library/dom@^7.27.1":
version "7.27.1"
resolved "https://registry.yarnpkg.com/@testing-library/dom/-/dom-7.27.1.tgz#b760182513357e4448a8461f9565d733a88d71d0"
integrity sha512-AF56RoeUU8bO4DOvLyMI44H3O1LVKZQi2D/m5fNDr+iR4drfOFikTr26hT6IY7YG+l8g69FXsHERa+uThaYYQg==
version "7.28.0"
resolved "https://registry.yarnpkg.com/@testing-library/dom/-/dom-7.28.0.tgz#4d68a39675dbf0fa2f3c53bc2b9ab9e1dd1d55b2"
integrity sha512-jY9wE3eF/fjrxUCC1VTCnMWE/g+aCP582Df4H6H9wQYY0yLglyevTO7TET9pgg0w9Yzm8n7ck0Hxzi18pN5+4w==
dependencies:
"@babel/code-frame" "^7.10.4"
"@babel/runtime" "^7.12.5"
@@ -1532,9 +1532,9 @@
integrity sha512-tjSSOTHhI5mCHTy/OOXYIhi2Wt1qcbHmuXD1Ha7q70CgI/I71afO4XtLb/cVexki1oVYchpul/TOuu3Arcdxrg==
"@types/node@*":
version "14.14.8"
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.14.8.tgz#2127bd81949a95c8b7d3240f3254352d72563aec"
integrity sha512-z/5Yd59dCKI5kbxauAJgw6dLPzW+TNOItNE00PkpzNwUIEwdj/Lsqwq94H5DdYBX7C13aRA0CY32BK76+neEUA==
version "14.14.9"
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.14.9.tgz#04afc9a25c6ff93da14deabd65dc44485b53c8d6"
integrity sha512-JsoLXFppG62tWTklIoO4knA+oDTYsmqWxHRvd4lpmfQRNhX6osheUOWETP2jMoV/2bEHuMra8Pp3Dmo/stBFcw==
"@types/normalize-package-data@^2.4.0":
version "2.4.0"
@@ -2251,9 +2251,9 @@ aws4@^1.8.0:
integrity sha512-xh1Rl34h6Fi1DC2WWKfxUTVqRsNnr6LsKz2+hfwDxQJWmrx8+c7ylaqBMcHfl1U1r2dsifOvKX3LQuLNZ+XSvA==
axe-core@^4.0.2:
version "4.1.0"
resolved "https://registry.yarnpkg.com/axe-core/-/axe-core-4.1.0.tgz#93d395e6262ecdde5cb52a5d06533d0a0c7bb4cd"
integrity sha512-9atDIOTDLsWL+1GbBec6omflaT5Cxh88J0GtJtGfCVIXpI02rXHkju59W5mMqWa7eiC5OR168v3TK3kUKBW98g==
version "4.1.1"
resolved "https://registry.yarnpkg.com/axe-core/-/axe-core-4.1.1.tgz#70a7855888e287f7add66002211a423937063eaf"
integrity sha512-5Kgy8Cz6LPC9DJcNb3yjAXTu3XihQgEdnIg50c//zOC/MyLP0Clg+Y8Sh9ZjjnvBrDZU4DgXS9C3T9r4/scGZQ==
axobject-query@^2.2.0:
version "2.2.0"
@@ -4266,9 +4266,9 @@ ejs@^2.6.1:
integrity sha512-7vmuyh5+kuUyJKePhQfRQBhXV5Ce+RnaeeQArKu1EAMpL3WbgMt5WG6uQZpEVvYSSsxMXRKOewtDk9RaTKXRlA==
electron-to-chromium@^1.3.591:
version "1.3.601"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.601.tgz#881824eaef0b2f97c89e1abb5835fdd224997d34"
integrity sha512-ctRyXD9y0mZu8pgeNwBUhLP3Guyr5YuqkfLKYmpTwYx7o9JtCEJme9JVX4xBXPr5ZNvr/iBXUvHLFEVJQThATg==
version "1.3.603"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.603.tgz#1b71bec27fb940eccd79245f6824c63d5f7e8abf"
integrity sha512-J8OHxOeJkoSLgBXfV9BHgKccgfLMHh+CoeRo6wJsi6m0k3otaxS/5vrHpMNSEYY4MISwewqanPOuhAtuE8riQQ==
elliptic@^6.5.3:
version "6.5.3"
@@ -4808,9 +4808,9 @@ express-graphql@^0.9.0:
raw-body "^2.4.1"
express-rate-limit@^5.1.3:
version "5.1.3"
resolved "https://registry.yarnpkg.com/express-rate-limit/-/express-rate-limit-5.1.3.tgz#656bacce3f093034976346958a0f0199902c9174"
integrity sha512-TINcxve5510pXj4n9/1AMupkj3iWxl3JuZaWhCdYDlZeoCPqweGZrxbrlqTCFb1CT5wli7s8e2SH/Qz2c9GorA==
version "5.2.3"
resolved "https://registry.yarnpkg.com/express-rate-limit/-/express-rate-limit-5.2.3.tgz#ae73b3dc723decd697797611bd96e9b34a912f6c"
integrity sha512-cjQH+oDrEPXxc569XvxhHC6QXqJiuBT6BhZ70X3bdAImcnHnTNMVuMAJaT0TXPoRiEErUrVPRcOTpZpM36VbOQ==
express@^4.16.3, express@^4.17.1:
version "4.17.1"
@@ -8816,6 +8816,11 @@ pkg-dir@^4.1.0, pkg-dir@^4.2.0:
dependencies:
find-up "^4.0.0"
pluralize@^8.0.0:
version "8.0.0"
resolved "https://registry.yarnpkg.com/pluralize/-/pluralize-8.0.0.tgz#1a6fa16a38d12a1901e0320fa017051c539ce3b1"
integrity sha512-Nc3IT5yHzflTfbjgqWcCPpo7DaKy4FnpB0l/zCAW0Tc7jxAiuqSxHasntB3D7887LSrA93kDJ9IXovxJYxyLCA==
pn@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/pn/-/pn-1.1.0.tgz#e2f4cef0e219f463c179ab37463e4e1ecdccbafb"
@@ -10815,7 +10820,7 @@ shellwords@^0.1.1:
resolved "https://registry.yarnpkg.com/shellwords/-/shellwords-0.1.1.tgz#d6b9181c1a48d397324c84871efbcfc73fc0654b"
integrity sha512-vFwSUfQvqybiICwZY5+DAWIPLKsWO31Q91JSKl3UYv+K5c2QRPzn0qzec6QPu1Qc9eHYItiP3NdJqNVqetYAww==
side-channel@^1.0.2:
side-channel@^1.0.2, side-channel@^1.0.3:
version "1.0.3"
resolved "https://registry.yarnpkg.com/side-channel/-/side-channel-1.0.3.tgz#cdc46b057550bbab63706210838df5d4c19519c3"
integrity sha512-A6+ByhlLkksFoUepsGxfj5x1gTSrs+OydsRptUxeNCabQpCFUvcwIczgOigI8vhY/OJCnPnyE9rGiwgvr9cS1g==
@@ -11273,16 +11278,17 @@ string-width@^4.1.0, string-width@^4.2.0:
strip-ansi "^6.0.0"
string.prototype.matchall@^4.0.2:
version "4.0.2"
resolved "https://registry.yarnpkg.com/string.prototype.matchall/-/string.prototype.matchall-4.0.2.tgz#48bb510326fb9fdeb6a33ceaa81a6ea04ef7648e"
integrity sha512-N/jp6O5fMf9os0JU3E72Qhf590RSRZU/ungsL/qJUYVTNv7hTG0P/dbPjxINVN9jpscu3nzYwKESU3P3RY5tOg==
version "4.0.3"
resolved "https://registry.yarnpkg.com/string.prototype.matchall/-/string.prototype.matchall-4.0.3.tgz#24243399bc31b0a49d19e2b74171a15653ec996a"
integrity sha512-OBxYDA2ifZQ2e13cP82dWFMaCV9CGF8GzmN4fljBVw5O5wep0lu4gacm1OL6MjROoUnB8VbkWRThqkV2YFLNxw==
dependencies:
call-bind "^1.0.0"
define-properties "^1.1.3"
es-abstract "^1.17.0"
es-abstract "^1.18.0-next.1"
has-symbols "^1.0.1"
internal-slot "^1.0.2"
regexp.prototype.flags "^1.3.0"
side-channel "^1.0.2"
side-channel "^1.0.3"
string.prototype.trimend@^1.0.1:
version "1.0.2"