@isaac-platform/isaac-integration-sdk
Version:
A Typescript SDK for integrating with ISAAC
82 lines (81 loc) • 3.23 kB
JavaScript
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
import * as util from "util";
// TODO: Update this to user getters and setters like in events.
export class IsaacVariable {
constructor(definition, connection) {
this.definition = definition;
this.isaacConn = connection;
}
// Update the value of a variable.
// TODO: Allow Int, Bool, String, inputs and
setValue(value) {
return __awaiter(this, void 0, void 0, function* () {
this.definition = (yield this.isaacConn.postRequest(`variables/${this.definition._id}/value`, {
'value': value
}));
return this.definition;
});
}
/**
* Refresh
* Retrieves the latest copy of the variable information from ISAAC.
* @returns IsaacVariableType
*/
refresh() {
return __awaiter(this, void 0, void 0, function* () {
this.definition = (yield this.isaacConn.getRequest(`variables/${this.definition._id}`));
return this.definition;
});
}
/**
* Get
* @returns IsaacVariableType
*/
get() {
return this.definition;
}
/**
* Disable
* Disables the variable in the subsystem.
* This is recommended in place of delete as it does not break any user configuration which uses the variable.
* @returns IsaacVariableType
*/
disable() {
return __awaiter(this, void 0, void 0, function* () {
this.definition.availableInSubsystem = false;
this.definition = (yield this.isaacConn.putRequest(`variables/${this.definition._id}`, this.definition));
return this.definition;
});
}
/**
* Enable
* Enables the variable in the subsystem.
* @returns IsaacVariableType
*/
enable() {
return __awaiter(this, void 0, void 0, function* () {
this.definition.availableInSubsystem = true;
this.definition = (yield this.isaacConn.putRequest(`variables/${this.definition._id}`, this.definition));
return this.definition;
});
}
get availableInSubsystem() {
return this.definition.availableInSubsystem;
}
set availableInSubsystem(value) {
this.definition.availableInSubsystem = value;
// update()
}
// Override inspect behavior for logging.
[util.inspect.custom](depth, opts) {
return `${this.definition.subsystemDisplayName || this.definition.subsystemId} - ${this.definition.displayName || this.definition.externalRef} = ${this.definition.lastValue}`;
}
}