Skip to content

Commit

Permalink
Uppercase ValidationsConfig type
Browse files Browse the repository at this point in the history
  • Loading branch information
esbanarango committed Jan 2, 2023
1 parent 4c83766 commit affdd3f
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 17 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
Expand All @@ -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,
},
Expand Down
17 changes: 7 additions & 10 deletions addon/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>(target: T): T & { validate: (options?: validateOptions) => boolean };
export function objectValidator<T>(target: T): T & { validate: (options?: validateOptions) => boolean };
export function modelValidator<T>(target: T): T & { validate: (options?: ValidateOptions) => boolean };
export function objectValidator<T>(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;
}
2 changes: 1 addition & 1 deletion addon/initializers/register-version.js
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions tests/dummy/app/models/fake-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -81,7 +81,7 @@ class FakeModel extends Model {
})
declare dateAfter2014: Date;

validations: validationsConfig = {
validations: ValidationsConfig = {
asyncModel: {
presence: true,
},
Expand Down
4 changes: 2 additions & 2 deletions tests/dummy/app/models/other-model.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
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 {}

@modelValidator
class OtherModel extends Model {
@attr('string') declare name: string;

validations: validationsConfig = {
validations: ValidationsConfig = {
name: {
presence: true,
},
Expand Down

0 comments on commit affdd3f

Please sign in to comment.