adopted-ember-addons / adopted-ember-addons/validated-changeset

[rfc]: Externalize schema validation

Đang mở
#166 1 bình luận 0 reaction 0 người được giao Xem trên GitHub
enhancement good first issue
Ngôn ngữ chính
TypeScript
Star
38
Fork
27
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

## RFC

One broad goal we have is to potentially deprecate the use of [ember-changeset-validations](https://github.com/poteto/ember-changeset-validations). Having both `ember-changeset` and `ember-changeset-validations` presents some confusion. If we went forward, `ember-changeset` would be the single library we would use to validate our data.

Currently, at a high level, the changeset API for validations is rather unintuitive and verbose.

e.g. ember-changeset-validations README

> This addon updates the changeset helper by taking in a validation map as a 2nd argument (instead of a validator function).

Do we need this? Here is an example of the migration.

```
import lookupValidator from 'ember-changeset-validations';

const EmployeeValidations = {
email: validateFormat({ type: 'email' }),
password: [
validateLength({ min: 8 }),
validatePasswordStrength({ minScore: 80 })
],
passwordConfirmation: validateConfirmation({ on: 'password' })
};

const changeset = new Changeset(this.model, lookupValidator(EmployeeValidations), EmployeeValidations);
```

Nominally, this could look like the following...

```
let schema = yup.object().shape({
email: yup.string().email().required(),
password: yup.string().required().min(8),
passwordConfirmation: yup.string()
.oneOf([yup.ref('password'), null], 'Passwords must match')
});

const changeset = new Changeset(this.model, schema);
```

As long as schema adhered to the interface we defined (something like `isValid` and/or `validate` methods), then we can detect errors in the current in progress changeset and error appropriately.

https://github.com/jquense/yup

### Upsides
- Less confusion in the changeset ecosystem
- Simpler API

### Downsides
- New API to learn.
- Another library to optionally install that supersedes our relatively simple validations provided - https://github.com/poteto/ember-changeset-validations/tree/master/addon/validators

ref https://github.com/validated-changeset/validated-changeset/issues/166

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.