From affdd3ff2c777898391dd9a5992a05e76489da01 Mon Sep 17 00:00:00 2001 From: Esteban Arango Medina Date: Mon, 2 Jan 2023 14:11:38 -0500 Subject: [PATCH] Uppercase `ValidationsConfig` type --- README.md | 4 ++-- addon/index.d.ts | 17 +++++++---------- addon/initializers/register-version.js | 2 +- tests/dummy/app/models/fake-model.ts | 4 ++-- tests/dummy/app/models/other-model.ts | 4 ++-- 5 files changed, 14 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 16f5d8d3..a1adad39 100644 --- a/README.md +++ b/README.md @@ -117,7 +117,7 @@ export default class MyComponent extends Component { ```typescript import Model, { attr } from '@ember-data/model'; -import { modelValidator, type validationsConfig, type ValidatedModel } from 'ember-model-validator'; +import { modelValidator, type ValidationsConfig, type ValidatedModel } from 'ember-model-validator'; // https://github.com/microsoft/TypeScript/issues/4881 interface MyModel extends ValidatedModel, Model {} @@ -126,7 +126,7 @@ interface MyModel extends ValidatedModel, Model {} class MyModel extends Model { @attr('string') declare name: string; - validations: validationsConfig = { + validations: ValidationsConfig = { name: { presence: true, }, diff --git a/addon/index.d.ts b/addon/index.d.ts index 7bcc4472..ad50b408 100644 --- a/addon/index.d.ts +++ b/addon/index.d.ts @@ -24,34 +24,31 @@ type ValidationKeys = /** * @decorator * - * Marks a property as tracked. - * - * By including Ember-model-validator's decorator into your model, this will have a validate function available, + * By including Ember-model-validator's decorator into your model, this will add a `validate()` function available, * it is a synchronous function which returns either true or false. * You can also pass an option hash for excluding or forcing certain attributes to be validated, and to prevent * errors to be added. - * */ -export function modelValidator(target: T): T & { validate: (options?: validateOptions) => boolean }; -export function objectValidator(target: T): T & { validate: (options?: validateOptions) => boolean }; +export function modelValidator(target: T): T & { validate: (options?: ValidateOptions) => boolean }; +export function objectValidator(target: T): T & { validate: (options?: ValidateOptions) => boolean }; -export interface validateOptions { +export interface ValidateOptions { except: string[]; only: string[]; addErrors: boolean; } -export interface validationsConfig { +export interface ValidationsConfig { [key: string]: { [K in ValidationKeys]?: any; }; } export interface ValidatedModel { - validate(options?: validateOptions): boolean; + validate(options?: ValidateOptions): boolean; } export interface ValidatedObject { - validate(options?: validateOptions): boolean; + validate(options?: ValidateOptions): boolean; errors: any; } diff --git a/addon/initializers/register-version.js b/addon/initializers/register-version.js index 96c40ac2..3a77b606 100644 --- a/addon/initializers/register-version.js +++ b/addon/initializers/register-version.js @@ -1,7 +1,7 @@ import Ember from 'ember'; export function initialize() { - Ember.libraries.register('Ember Model Validator', '4.1.0'); + Ember.libraries.register('Ember Model Validator', '4.2.0'); } export default { diff --git a/tests/dummy/app/models/fake-model.ts b/tests/dummy/app/models/fake-model.ts index 0461ee07..b08056fc 100644 --- a/tests/dummy/app/models/fake-model.ts +++ b/tests/dummy/app/models/fake-model.ts @@ -7,7 +7,7 @@ import Model, { type SyncHasMany, } from '@ember-data/model'; -import { modelValidator, type validationsConfig, type ValidatedModel } from 'ember-model-validator'; +import { modelValidator, type ValidationsConfig, type ValidatedModel } from 'ember-model-validator'; import type AsyncModel from './async-model'; import type OtherModel from './other-model'; @@ -81,7 +81,7 @@ class FakeModel extends Model { }) declare dateAfter2014: Date; - validations: validationsConfig = { + validations: ValidationsConfig = { asyncModel: { presence: true, }, diff --git a/tests/dummy/app/models/other-model.ts b/tests/dummy/app/models/other-model.ts index 9d66e9c6..c17c1999 100644 --- a/tests/dummy/app/models/other-model.ts +++ b/tests/dummy/app/models/other-model.ts @@ -1,6 +1,6 @@ import Model, { attr } from '@ember-data/model'; -import { modelValidator, type validationsConfig, type ValidatedModel } from 'ember-model-validator'; +import { modelValidator, type ValidationsConfig, type ValidatedModel } from 'ember-model-validator'; interface OtherModel extends ValidatedModel, Model {} @@ -8,7 +8,7 @@ interface OtherModel extends ValidatedModel, Model {} class OtherModel extends Model { @attr('string') declare name: string; - validations: validationsConfig = { + validations: ValidationsConfig = { name: { presence: true, },