vault/ui/app/decorators/model-validations.js
Jordan Reimer 681a3b8563
[UI] Ember Data Migration - Form Class (#30232)
* moves validators from model-helpers to forms directory

* creates validate util and updates model-validations directory to use it

* adds form and field classes

* updates validation types

* updates validators import in test

* adds readme for forms

* Update ui/app/utils/forms/validate.ts

Co-authored-by: lane-wetmore <lane.wetmore@hashicorp.com>

---------

Co-authored-by: lane-wetmore <lane.wetmore@hashicorp.com>
2025-04-15 09:35:56 -06:00

28 lines
752 B
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/
import { validate } from 'vault/utils/forms/validate';
// see documentation at ui/docs/model-validations.md for detailed usage information
export function withModelValidations(validations) {
return function decorator(SuperClass) {
return class ModelValidations extends SuperClass {
static _validations;
constructor() {
super(...arguments);
if (!validations || typeof validations !== 'object') {
throw new Error('Validations object must be provided to constructor for setup');
}
this._validations = validations;
}
validate() {
return validate(this, this._validations);
}
};
};
}