// todo: need unit test
import { XDataDefinition } from "./Data/XDataDefinition";
export class ConfigStorageUtility {
    static getDataDefinitionFromData(data) {
        if (!data)
            return;
        let typeName = Reflect.get(data, this.TYPE_FIELD_NAME);
        if (typeName) {
            let registeredControl = XDataDefinition.TYPEMAP[typeName];
            let prototype = Object.getPrototypeOf(registeredControl);
            let val = new prototype.constructor();
            // @ts-ignore
            let cc = val;
            cc.setStorageData(data);
            return cc;
        }
        throw new Error('Could not create data definition: no type defined');
    }
    static verifyTypeField(d) {
        if (!Reflect.get(d, this.TYPE_FIELD_NAME))
            throw new Error('missing type field');
    }
}
ConfigStorageUtility.TYPE_FIELD_NAME = '__type';
//# sourceMappingURL=ConfigStorageUtility.js.map