@aire-ux/aire-condensation
Version:
Client-side serialization library for Aire-UX
42 lines (41 loc) • 1.23 kB
JavaScript
import "reflect-metadata";
import { Condensation } from "./condensation";
export function Configuration(cfg) {
const reg = Condensation.typeRegistry;
return function (type) {
if (!reg.contains(type)) {
RootElement(type);
}
reg.configure(type, cfg);
return type;
};
}
export function RootElement(type) {
const reg = Condensation.typeRegistry;
if (!reg.contains(type)) {
reg.register(type);
}
return type;
}
function isConfiguration(cfg) {
return cfg.type !== undefined;
}
export function Property(configuration) {
return function (target, propertyName) {
const ctor = target.constructor;
RootElement(ctor);
let reg = Condensation.typeRegistry, propertyCtor = Reflect.getMetadata("design:type", target, propertyName), type;
if (configuration) {
if (isConfiguration(configuration)) {
type = configuration.type;
}
else {
type = configuration;
}
}
else {
type = propertyCtor;
}
reg.defineProperty(ctor, propertyName, Object.assign(Object.assign({}, configuration), { type: type }));
};
}