node-web-mvc
Version:
node spring mvc
34 lines (33 loc) • 1.07 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const constraintsSymbol = Symbol('constraints');
function EMPTY_GROUP() { }
class Constraints {
constructor(info) {
this.groups = EMPTY_GROUP;
const ctor = info.ctor;
if (!ctor[constraintsSymbol]) {
ctor[constraintsSymbol] = [];
}
const constraints = ctor[constraintsSymbol];
constraints.push(info);
}
static getConstraints(clazz, groups) {
const empty = [];
if (!clazz)
return empty;
const constraints = (clazz[constraintsSymbol] || empty);
return constraints.filter((m) => {
const item = m.nativeAnnotation;
if (!item.groups) {
return false;
}
else if (item.groups instanceof Array) {
return !!item.groups.find((m) => groups.indexOf(m) > -1);
}
return groups.indexOf(item.groups) > -1;
});
}
}
Constraints.EMPTY_GROUP = EMPTY_GROUP;
exports.default = Constraints;