UNPKG

graphql-composer

Version:
55 lines 1.65 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ClassDescriptor = void 0; class ClassDescriptor { static describe(classType, description) { if (!description) { const instance = new classType(); const properties = Object.keys(instance); return properties.map((property) => { return { property, type: ClassDescriptor.convertTypeOfToType(instance[property]), }; }); } else { return Object.keys(description).map((key) => { return { property: key, type: description[key], }; }); } } static convertTypeOfToType(item) { if (Array.isArray(item)) { return [this.convertTypeOfToType(item[0])]; } const typeMap = { string: String, number: Number, boolean: Boolean, function: Function, object: Object, symbol: Symbol, bigint: BigInt, }; return typeMap[typeof item]; } static instanceOf(item, ...possibleIntances) { return possibleIntances.some((i) => { return item instanceof i; }); } static doExtends(classType, extension) { try { const instance = new classType(); return instance instanceof extension; } catch (err) { } return false; } } exports.ClassDescriptor = ClassDescriptor; //# sourceMappingURL=ClassDescriptor.js.map