54 lines
1.6 KiB
JavaScript
54 lines
1.6 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.Serde = void 0;
|
|
exports.serde = serde;
|
|
exports.getMetadata = getMetadata;
|
|
exports.register = register;
|
|
const options_1 = require("./options");
|
|
const registry_1 = require("./registry");
|
|
exports.Serde = Symbol('Serde');
|
|
function decorateContainer(options, constructor) {
|
|
if (constructor[exports.Serde] == null) {
|
|
constructor[exports.Serde] = new options_1.SerdeOptions(constructor, options);
|
|
}
|
|
else {
|
|
constructor[exports.Serde].options = options;
|
|
}
|
|
return constructor;
|
|
}
|
|
function decorateProperty(options, target, property) {
|
|
let constructor;
|
|
if (typeof target === 'function') {
|
|
constructor = target;
|
|
}
|
|
else {
|
|
constructor = target.constructor;
|
|
}
|
|
if (constructor[exports.Serde] == null) {
|
|
constructor[exports.Serde] = options_1.SerdeOptions.from(target);
|
|
}
|
|
constructor[exports.Serde].properties.set(property, options);
|
|
return target;
|
|
}
|
|
function serde(options) {
|
|
return function (target, property) {
|
|
if (property != null) {
|
|
return decorateProperty(options, target, property);
|
|
}
|
|
else {
|
|
return decorateContainer(options, target);
|
|
}
|
|
};
|
|
}
|
|
function getMetadata(value) {
|
|
return value[exports.Serde];
|
|
}
|
|
function register(registry = registry_1.GlobalRegistry) {
|
|
return function (target) {
|
|
if (target[exports.Serde] == null) {
|
|
target[exports.Serde] = options_1.SerdeOptions.from(target);
|
|
}
|
|
registry.add(target);
|
|
return target;
|
|
};
|
|
}
|