textiot
Version:
A framework for building web and native (IoT) Dapps on the IPFS network
58 lines (57 loc) • 2.63 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());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const api_1 = require("../core/api");
/**
* Config is an API module for controling peer node configuration variables
*
* It works much like 'git config'. The configuration values are stored in a config file
* inside your Textile repository. Getting config values will report the currently active
* config settings. This may differ from the values specifed when setting values.
*
* @extends API
*/
class Config extends api_1.API {
/**
* Report the currently active config settings
*
* The reported settings may differ from the values specifed when setting/patching values.
*
* @param path Config settings path (e.g., Addresses.API). Omit for full config file.
* @returns A JSON representation of the current config setting at the given path
*/
get(path) {
return __awaiter(this, void 0, void 0, function* () {
const cleanPath = path ? `/${path.replace(/\./g, '/')}` : '';
const response = yield this.sendGet(`config${cleanPath}`);
return response.json();
});
}
/**
* Replace or update config settings
*
* See https://tools.ietf.org/html/rfc6902 for details on RFC6902 JSON patch format.
* Be sure to restart the daemon for changes to take effect.
*
* @param path Config settings path (e.g., Addresses.API).
* @param value JSON config settings (can be any valid JSON type)
* @returns Whether the operation was successfull
*/
set(path, value) {
return __awaiter(this, void 0, void 0, function* () {
const cleanPath = `/${path.replace(/\./g, '/')}`;
const patch = [{ op: 'replace', path: cleanPath, value }];
const response = yield this.sendPatch(`config`, undefined, undefined, patch);
return response.status === 204;
});
}
}
exports.default = Config;
;