import { ContainerOptions, PropertyOptions, SerdeOptions } from "./options" export const Serde = Symbol('Serde') function decorateContainer(options: ContainerOptions, constructor: any) { if (constructor[Serde] == null) { constructor[Serde] = new SerdeOptions(constructor, options) } else { constructor[Serde].options = options } return constructor } function decorateProperty(options: PropertyOptions, target: any, property: PropertyKey) { let constructor: any if (typeof target === 'function') { constructor = target } else { constructor = target.constructor } if (constructor[Serde] == null) { constructor[Serde] = SerdeOptions.from(target) } constructor[Serde].properties.set(property, options) return target } export function serde(options: ContainerOptions | PropertyOptions) { return function(target: any, property?: PropertyKey) { if (property != null) { return decorateProperty(options as PropertyOptions, target, property) } else { return decorateContainer(options, target) } } }