@decaf-ts/db-decorators
Version:
Agnostic database decorators and repository
42 lines • 1.84 kB
JavaScript
import "@decaf-ts/decorator-validation";
import { ModelBuilder as ModelBuilderImpl } from "@decaf-ts/decorator-validation";
import { generated, hash, composed, composedFromKeys, version, transient, } from "./../model/decorators.js";
const builderPrototype = ModelBuilderImpl.prototype;
if (!builderPrototype.decorateClass) {
builderPrototype.decorateClass = function (decorator) {
if (!this._classDecorators) {
this._classDecorators = [];
}
this._classDecorators.push(decorator);
return this;
};
}
const ensureAttributeBuilder = (builder, attr) => {
const attributes = builder.attributes;
if (attributes?.has(attr))
return attributes.get(attr);
return builder.attribute(attr, Object);
};
const applyDecorator = (builder, attr, decorator) => {
ensureAttributeBuilder(builder, attr).decorate(decorator);
return builder;
};
builderPrototype.generated = function (attr, type) {
return applyDecorator(this, attr, generated(type));
};
builderPrototype.hash = function (attr) {
return applyDecorator(this, attr, hash());
};
builderPrototype.composedFromKeys = function (attr, args, separator, filterEmpty, hashValue, prefix, suffix, groupsort) {
return applyDecorator(this, attr, composedFromKeys(args, separator, filterEmpty, hashValue, prefix, suffix, groupsort));
};
builderPrototype.composed = function (attr, args, separator, filterEmpty, hashValue, prefix, suffix, groupsort) {
return applyDecorator(this, attr, composed(args, separator, filterEmpty, hashValue, prefix, suffix, groupsort));
};
builderPrototype.version = function (attr) {
return applyDecorator(this, attr, version());
};
builderPrototype.transient = function (attr) {
return applyDecorator(this, attr, transient());
};
//# sourceMappingURL=ModelBuilderExtensions.js.map