diff --git a/.changeset/5d86a313/changes.md b/.changeset/5d86a313/changes.md index 6502292f421..fcfb47b3d67 100644 --- a/.changeset/5d86a313/changes.md +++ b/.changeset/5d86a313/changes.md @@ -1 +1 @@ -- Enable sorting on DateTime fields \ No newline at end of file +- Enable sorting on DateTime fields diff --git a/.changeset/79365e10/changes.json b/.changeset/79365e10/changes.json new file mode 100644 index 00000000000..473e0f25b45 --- /dev/null +++ b/.changeset/79365e10/changes.json @@ -0,0 +1,31 @@ +{ + "releases": [{ "name": "@voussoir/core", "type": "major" }], + "dependents": [ + { "name": "@voussoir/adapter-mongoose", "type": "patch", "dependencies": ["@voussoir/core"] }, + { + "name": "@voussoir/test-utils", + "type": "patch", + "dependencies": ["@voussoir/adapter-mongoose", "@voussoir/core"] + }, + { + "name": "@voussoir/cypress-project-access-control", + "type": "patch", + "dependencies": ["@voussoir/adapter-mongoose", "@voussoir/test-utils", "@voussoir/core"] + }, + { + "name": "@voussoir/cypress-project-basic", + "type": "patch", + "dependencies": ["@voussoir/adapter-mongoose", "@voussoir/test-utils", "@voussoir/core"] + }, + { + "name": "@voussoir/cypress-project-login", + "type": "patch", + "dependencies": ["@voussoir/adapter-mongoose", "@voussoir/test-utils", "@voussoir/core"] + }, + { + "name": "@voussoir/cypress-project-twitter-login", + "type": "patch", + "dependencies": ["@voussoir/adapter-mongoose", "@voussoir/core"] + } + ] +} diff --git a/.changeset/79365e10/changes.md b/.changeset/79365e10/changes.md new file mode 100644 index 00000000000..575ff344713 --- /dev/null +++ b/.changeset/79365e10/changes.md @@ -0,0 +1 @@ +- Field configuration now tasks isRequired and isUnique, rather than required and unique diff --git a/.changeset/a0b53437/changes.json b/.changeset/a0b53437/changes.json new file mode 100644 index 00000000000..a57b448415d --- /dev/null +++ b/.changeset/a0b53437/changes.json @@ -0,0 +1,48 @@ +{ + "releases": [ + { "name": "@voussoir/adapter-mongoose", "type": "major" }, + { "name": "@voussoir/fields", "type": "major" }, + { "name": "@voussoir/cypress-project-basic", "type": "minor" } + ], + "dependents": [ + { + "name": "@voussoir/test-utils", + "type": "patch", + "dependencies": ["@voussoir/core", "@voussoir/adapter-mongoose"] + }, + { + "name": "@voussoir/cypress-project-access-control", + "type": "patch", + "dependencies": [ + "@voussoir/test-utils", + "@voussoir/admin-ui", + "@voussoir/core", + "@voussoir/adapter-mongoose", + "@voussoir/fields" + ] + }, + { + "name": "@voussoir/cypress-project-login", + "type": "patch", + "dependencies": [ + "@voussoir/test-utils", + "@voussoir/admin-ui", + "@voussoir/core", + "@voussoir/adapter-mongoose", + "@voussoir/fields" + ] + }, + { + "name": "@voussoir/cypress-project-twitter-login", + "type": "patch", + "dependencies": [ + "@voussoir/admin-ui", + "@voussoir/core", + "@voussoir/adapter-mongoose", + "@voussoir/fields" + ] + }, + { "name": "@voussoir/admin-ui", "type": "patch", "dependencies": ["@voussoir/fields"] }, + { "name": "@voussoir/core", "type": "patch", "dependencies": ["@voussoir/fields"] } + ] +} diff --git a/.changeset/a0b53437/changes.md b/.changeset/a0b53437/changes.md new file mode 100644 index 00000000000..575ff344713 --- /dev/null +++ b/.changeset/a0b53437/changes.md @@ -0,0 +1 @@ +- Field configuration now tasks isRequired and isUnique, rather than required and unique diff --git a/docs/hooks.md b/docs/hooks.md index 973e7f74f7d..4c38f16068f 100644 --- a/docs/hooks.md +++ b/docs/hooks.md @@ -95,7 +95,7 @@ class Text extends Implementation { keystone.createList('User', { fields: { name: { type: Text, minLength: 3 }, - email: { type: Text, required: true, unique: true }, + email: { type: Text, isRequired: true, isUnique: true }, pass: { type: Password, rejectCommon: true }, }, diff --git a/packages/adapter-mongoose/index.js b/packages/adapter-mongoose/index.js index d85866206e7..37087baab6e 100644 --- a/packages/adapter-mongoose/index.js +++ b/packages/adapter-mongoose/index.js @@ -386,11 +386,11 @@ class MongooseFieldAdapter extends BaseFieldAdapter { addToMongooseSchema() { throw new Error(`Field type [${this.fieldName}] does not implement addToMongooseSchema()`); } - buildValidator(validator, required) { - return required ? validator : a => validator(a) || typeof a === 'undefined' || a === null; + buildValidator(validator, isRequired) { + return isRequired ? validator : a => validator(a) || typeof a === 'undefined' || a === null; } - mergeSchemaOptions(schemaOptions, { unique, mongooseOptions }) { - if (unique) { + mergeSchemaOptions(schemaOptions, { isUnique, mongooseOptions }) { + if (isUnique) { // A value of anything other than `true` causes errors with Mongoose // constantly recreating indexes. Ie; if we just splat `unique` onto the // options object, it would be `undefined`, which would cause Mongoose to diff --git a/packages/fields/types/CalendarDay/Implementation.js b/packages/fields/types/CalendarDay/Implementation.js index cdce7aee8f4..080051663ba 100644 --- a/packages/fields/types/CalendarDay/Implementation.js +++ b/packages/fields/types/CalendarDay/Implementation.js @@ -38,13 +38,13 @@ class CalendarDay extends Implementation { class MongoCalendarDayInterface extends MongooseFieldAdapter { addToMongooseSchema(schema) { const { mongooseOptions = {} } = this.config; - const { required } = mongooseOptions; + const { isRequired } = mongooseOptions; const validator = a => typeof a === 'string' && format(parse(a), 'YYYY-MM-DD') === a; const schemaOptions = { type: String, validate: { - validator: this.buildValidator(validator, required), + validator: this.buildValidator(validator, isRequired), message: '{VALUE} is not an ISO8601 date string (YYYY-MM-DD)', }, }; diff --git a/packages/fields/types/Decimal/Implementation.js b/packages/fields/types/Decimal/Implementation.js index 4e7f4d3a84f..b2ded27fc88 100644 --- a/packages/fields/types/Decimal/Implementation.js +++ b/packages/fields/types/Decimal/Implementation.js @@ -38,13 +38,13 @@ class Decimal extends Implementation { class MongoDecimalInterface extends MongooseFieldAdapter { addToMongooseSchema(schema) { const { mongooseOptions = {} } = this.config; - const { required } = mongooseOptions; + const { isRequired } = mongooseOptions; const validator = a => typeof a === 'object' && /^-?\d*\.?\d*$/.test(a); const schemaOptions = { type: mongoose.Decimal128, validate: { - validator: this.buildValidator(validator, required), + validator: this.buildValidator(validator, isRequired), message: '{VALUE} is not a Decimal value', }, }; diff --git a/packages/fields/types/Integer/Implementation.js b/packages/fields/types/Integer/Implementation.js index 9fc6df7d903..98c620a5a9c 100644 --- a/packages/fields/types/Integer/Implementation.js +++ b/packages/fields/types/Integer/Implementation.js @@ -31,12 +31,15 @@ class Integer extends Implementation { class MongoIntegerInterface extends MongooseFieldAdapter { addToMongooseSchema(schema) { const { mongooseOptions = {} } = this.config; - const { required } = mongooseOptions; + const { isRequired } = mongooseOptions; const schemaOptions = { type: Number, validate: { - validator: this.buildValidator(a => typeof a === 'number' && Number.isInteger(a), required), + validator: this.buildValidator( + a => typeof a === 'number' && Number.isInteger(a), + isRequired + ), message: '{VALUE} is not an integer value', }, }; diff --git a/packages/fields/types/Relationship/Implementation.js b/packages/fields/types/Relationship/Implementation.js index 5651e64bae6..758203e2fe8 100644 --- a/packages/fields/types/Relationship/Implementation.js +++ b/packages/fields/types/Relationship/Implementation.js @@ -163,10 +163,10 @@ class Relationship extends Implementation { } async resolveRelationship(input, item, context, getItem, mutationState) { - const { many, required } = this.config; + const { many, isRequired } = this.config; // Early out for null'd field - if (!required && !input) { + if (!isRequired && !input) { return input; } diff --git a/projects/basic/index.js b/projects/basic/index.js index 1c26f3c5da5..d591a598c9a 100644 --- a/projects/basic/index.js +++ b/projects/basic/index.js @@ -58,7 +58,7 @@ try { keystone.createList('User', { fields: { name: { type: Text }, - email: { type: Text, unique: true }, + email: { type: Text, isUnique: true }, dob: { type: CalendarDay, format: 'Do MMMM YYYY', diff --git a/projects/basic/tests/uniqueness/unique.test.js b/projects/basic/tests/uniqueness/unique.test.js index 2c430d90c87..dd7ff68515a 100644 --- a/projects/basic/tests/uniqueness/unique.test.js +++ b/projects/basic/tests/uniqueness/unique.test.js @@ -9,7 +9,7 @@ function setupKeystone() { keystone.createList('User', { fields: { username: { type: Text }, - email: { type: Text, unique: true }, + email: { type: Text, isUnique: true }, }, }); },