UNPKG

unifi-client

Version:

NodeJs client for Unifi products (https://www.ui.com/)

175 lines (174 loc) 6.56 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports._ObjectSubController = void 0; var Errors_1 = require("../Errors"); var ObjectWithPrivateValues_1 = require("./ObjectWithPrivateValues"); var Validate_1 = require("./Validate"); var util_1 = require("../util"); var _ObjectSubController = /** @class */ (function (_super) { __extends(_ObjectSubController, _super); function _ObjectSubController(config) { var _this = _super.call(this) || this; if (!config || !config.controller || !config.instance) { throw new Errors_1.ClientError('ObjectSubController not correctly initialized'); } _this.controller = config.controller; _this.controllerInstance = config.instance; _this.config = config; _this.debug = (0, util_1.createDebugger)('_ObjectSubController'); return _this; } Object.defineProperty(_ObjectSubController.prototype, "config", { // this functions are here to delete this value from rest(...) or JSON get: function () { return this.getPrivate('config'); }, set: function (value) { this.setPrivate('config', value); }, enumerable: false, configurable: true }); Object.defineProperty(_ObjectSubController.prototype, "controllerInstance", { get: function () { return this.getPrivate('controllerInstance'); }, set: function (value) { this.setPrivate('controllerInstance', value); }, enumerable: false, configurable: true }); Object.defineProperty(_ObjectSubController.prototype, "controller", { get: function () { return this.getPrivate('controller'); }, set: function (value) { this.setPrivate('controller', value); }, enumerable: false, configurable: true }); Object.defineProperty(_ObjectSubController.prototype, "site", { get: function () { return this.getPrivate('site'); }, set: function (value) { this.setPrivate('site', value); }, enumerable: false, configurable: true }); _ObjectSubController.prototype.toJSON = function () { var ret = {}; Object.entries(this).forEach(function (_a) { var k = _a[0], v = _a[1]; ret[k] = v; }); return ret; }; Object.defineProperty(_ObjectSubController.prototype, "instance", { get: function () { return this.getPrivate('instance'); }, set: function (value) { this.setPrivate('instance', value); }, enumerable: false, configurable: true }); _ObjectSubController.prototype.getInstance = function () { return this.instance; }; _ObjectSubController.prototype.getController = function () { return this.controller; }; // toJSON(): Record<string, any> { // const obj = { ...this }; // //remove circular known parts // delete obj._site; // delete obj._instance; // delete obj._controller; // delete obj._config; // // return obj; // } _ObjectSubController.prototype.checkNeeds = function (minVersion, unifiOs) { return (0, util_1.checkNeeds)(this.controller, minVersion, unifiOs); }; /** * * @param minVersion - the minimal semver version for this object * @param unifiOs - need to be unifiOs ? or Unifi Controller ? if no need, pass undefined * @param parameterName - a name for the parameter */ _ObjectSubController.prototype.checkNeedVersion = function (minVersion, unifiOs, parameterName) { if (parameterName === void 0) { parameterName = ''; } (0, util_1.checkNeedVersion)(this.controller, minVersion, unifiOs, parameterName); }; /** * * @param key - the key object that need to be only supported on some versions * @param value - the value store in this object * @param minVersion - the minimal semver version for this object * @param unifiOs - need to be unifiOs ? or Unifi Controller ? if no need, pass undefined * @param allowUndefined - to undefined check ? */ _ObjectSubController.prototype.needVersion = function (key, value, minVersion, unifiOs, allowUndefined) { if (allowUndefined === void 0) { allowUndefined = false; } try { this.checkNeedVersion(minVersion, unifiOs, "".concat(this.constructor.name, ".").concat(key.toString())); if (Validate_1.Validate.isUndefined(value)) { if (allowUndefined) { // @ts-ignore this[key] = value; } } else { // @ts-ignore this[key] = value; } return true; } catch (e) { Object.defineProperty(this, key, { // Create a new getter for the property get: function () { throw e; }, // Create a new setter for the property set: function () { throw e; } }); } return false; }; Object.defineProperty(_ObjectSubController.prototype, "debug", { get: function () { return this.getPrivate('debug'); }, set: function (value) { this.setPrivate('debug', value); }, enumerable: false, configurable: true }); return _ObjectSubController; }(ObjectWithPrivateValues_1.ObjectWithPrivateValues)); exports._ObjectSubController = _ObjectSubController;