UNPKG

molstar

Version:

A comprehensive macromolecular library.

57 lines 2.07 kB
/** * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author David Sehnal <david.sehnal@gmail.com> */ import * as fs from 'fs'; import { ModelServerConfig as Config } from './config'; import { ConsoleLogger } from '../../mol-util/console-logger'; // TODO enable dynamic imports again import * as pdbeProps from './properties/pdbe'; import * as wwpdbProps from './properties/wwpdb'; var attachModelProperties = { pdbe: pdbeProps.attachModelProperties, wwpdb: wwpdbProps.attachModelProperties }; export function createModelPropertiesProviderFromConfig() { return createModelPropertiesProvider(Config.customProperties); } export function createModelPropertiesProvider(configOrPath) { var config; if (typeof configOrPath === 'string') { try { config = JSON.parse(fs.readFileSync(configOrPath, 'utf8')); } catch (_a) { ConsoleLogger.error('Config', "Could not read property provider config file '" + configOrPath + "', ignoring."); return function () { return []; }; } } else { config = configOrPath; } if (!config || !config.sources || config.sources.length === 0) return void 0; var ps = []; for (var _i = 0, _b = config.sources; _i < _b.length; _i++) { var p = _b[_i]; if (p in attachModelProperties) { ps.push(attachModelProperties[p]); } else { ConsoleLogger.error('Config', "Could not find property provider '" + p + "', ignoring."); } } return function (model, cache) { var ret = []; for (var _i = 0, ps_1 = ps; _i < ps_1.length; _i++) { var p = ps_1[_i]; for (var _a = 0, _b = p({ model: model, cache: cache, params: config.params }); _a < _b.length; _a++) { var e = _b[_a]; ret.push(e); } } return ret; }; } //# sourceMappingURL=property-provider.js.map