textiot
Version:
A framework for building web and native (IoT) Dapps on the IPFS network
71 lines (70 loc) • 2.64 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());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const api_1 = require("../../core/api");
const defaults_1 = __importDefault(require("./defaults"));
/**
* Schemas is an API module for managing Textile schemas
*
* @extends API
*/
class Schemas extends api_1.API {
/**
* Default Textile schemas
* @returns An object with various commonly used schemas
*/
defaults() {
return __awaiter(this, void 0, void 0, function* () {
return defaults_1.default;
});
}
/**
* Default Textile schemas
* @returns An object with various commonly used schemas
*/
defaultByName(name) {
return __awaiter(this, void 0, void 0, function* () {
const key = Object.keys(defaults_1.default).find((known) => known === name);
if (key) {
return defaults_1.default[key];
}
return;
});
}
/**
* Creates and validates a new schema from input JSON
*
* @param schema Input JSON-based thread schema
* @returns The milled schema as a file index
*/
add(schema) {
return __awaiter(this, void 0, void 0, function* () {
const response = yield this.sendPost(`/api/v0/mills/schema`, undefined, undefined, schema, { 'Content-Type': 'application/json' });
return response.json();
});
}
/**
* Retrieves a schema by thread ID
*
* @param thread ID of the thread
* @returns The schema of the target thread
*/
get(thread) {
return __awaiter(this, void 0, void 0, function* () {
const response = yield this.sendGet(`/api/v0/threads/${thread}`);
return (yield response.json()).schema_node;
});
}
}
exports.default = Schemas;
;