UNPKG

@iotile/iotile-cloud

Version:

A typescript library for interfacing with the IOTile Cloud API

68 lines 2.35 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var unit_1 = require("./unit"); var VarType = /** @class */ (function () { function VarType(data) { if (data === void 0) { data = {}; } this.availableInputUnits = []; this.availableOutputUnits = []; this.schema = {}; this.name = data.name; this.slug = data.slug; this.unitFullName = data.storage_units_full; this.rawData = data; if ("available_input_units" in data) { var that_1 = this; data["available_input_units"].forEach(function (u) { var unit = new unit_1.Unit(u); that_1.availableInputUnits.push(unit); }); } if ("available_output_units" in data) { var that_2 = this; data["available_output_units"].forEach(function (u) { var unit = new unit_1.Unit(u); that_2.availableOutputUnits.push(unit); }); } if ('schema' in data) { var schema = data['schema']; if (schema && 'keys' in schema) { this.schema = schema.keys; } } } VarType.prototype.toJson = function () { return this.rawData; }; VarType.prototype.getInputUnitForSlug = function (slug) { var resultingUnit = null; this.availableInputUnits.forEach(function (u) { if (u.slug === slug) { resultingUnit = u; } }); return resultingUnit; }; VarType.prototype.getOutputUnitForSlug = function (slug) { var resultingUnit = null; this.availableOutputUnits.forEach(function (u) { if (u.slug === slug) { resultingUnit = u; } }); return resultingUnit; }; VarType.prototype.getASchemaObj = function (schemaKey) { return this.schema && schemaKey in this.schema ? this.schema[schemaKey] : null; }; VarType.prototype.getOutputUnitsForSchema = function (schemaKey) { var schemaObj = this.getASchemaObj(schemaKey); if (schemaObj && 'output_units' in schemaObj) { return schemaObj['output_units']; } }; return VarType; }()); exports.VarType = VarType; //# sourceMappingURL=vartype.js.map