textiot
Version:
A framework for building web and native (IoT) Dapps on the IPFS network
145 lines (144 loc) • 4.78 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 });
exports.cancelSearchSnapshots = exports.searchSnapshots = exports.snapshot = exports.remove = exports.peers = exports.list = exports.get = exports.rename = exports.addOrUpdate = exports.add = void 0;
const react_native_1 = require("react-native");
const buffer_1 = require("buffer");
const model_1 = require("./model");
const { ThreadsBridge } = react_native_1.NativeModules;
/**
* Add a new Thread.
* ```typescript
* Textile.threads.add(config);
* ```
*/
function add(config) {
return __awaiter(this, void 0, void 0, function* () {
const payload = model_1.AddThreadConfig.encode(config).finish();
const result = yield ThreadsBridge.add(buffer_1.Buffer.from(payload).toString('base64'));
return model_1.Thread.decode(buffer_1.Buffer.from(result, 'base64'));
});
}
exports.add = add;
/**
* Add a Thread or update metadata if new.
* ```typescript
* Textile.threads.addOrUpdate(thread);
* ```
*/
function addOrUpdate(thread) {
return __awaiter(this, void 0, void 0, function* () {
const payload = model_1.Thread.encode(thread).finish();
return ThreadsBridge.addOrUpdate(buffer_1.Buffer.from(payload).toString('base64'));
});
}
exports.addOrUpdate = addOrUpdate;
/**
* Rename a Thread by ThreadId.
* ```typescript
* Textile.threads.rename(threadId, name);
* ```
*/
function rename(threadId, name) {
return __awaiter(this, void 0, void 0, function* () {
return ThreadsBridge.rename(threadId, name);
});
}
exports.rename = rename;
/**
* Get Thread details by ThreadId.
* ```typescript
* Textile.threads.get(threadId);
* ```
*/
function get(threadId) {
return __awaiter(this, void 0, void 0, function* () {
// This throws an error if no thread is found
const result = yield ThreadsBridge.get(threadId);
return model_1.Thread.decode(buffer_1.Buffer.from(result, 'base64'));
});
}
exports.get = get;
/**
* List all Threads.
* ```typescript
* Textile.threads.list();
* ```
*/
function list() {
return __awaiter(this, void 0, void 0, function* () {
const result = yield ThreadsBridge.list();
return model_1.ThreadList.decode(buffer_1.Buffer.from(result, 'base64'));
});
}
exports.list = list;
/**
* Request all Peers in a Thread by ThreadId.
* ```typescript
* Textile.threads.peers(threadId);
* ```
*/
function peers(threadId) {
return __awaiter(this, void 0, void 0, function* () {
const result = yield ThreadsBridge.peers(threadId);
return model_1.PeerList.decode(buffer_1.Buffer.from(result, 'base64'));
});
}
exports.peers = peers;
/**
* Remove a Thread by ThreadId.
* ```typescript
* Textile.threads.remove(id);
* ```
*/
function remove(id_) {
return __awaiter(this, void 0, void 0, function* () {
const result = yield ThreadsBridge.remove(id_);
return result;
});
}
exports.remove = remove;
/**
* Snapshot all threads for active cafe sessions.
* ```typescript
* Textile.threads.snapshot();
* ```
*/
function snapshot() {
return __awaiter(this, void 0, void 0, function* () {
return ThreadsBridge.snapshot();
});
}
exports.snapshot = snapshot;
/**
* Locate all Thread snapshots.
* ```typescript
* const snapshots = Textile.threads.searchSnapshots(query, options);
* ```
*/
function searchSnapshots(query, options) {
return __awaiter(this, void 0, void 0, function* () {
return ThreadsBridge.searchSnapshots(buffer_1.Buffer.from(model_1.ThreadSnapshotQuery.encode(query).finish()).toString('base64'), buffer_1.Buffer.from(model_1.QueryOptions.encode(options).finish()).toString('base64'));
});
}
exports.searchSnapshots = searchSnapshots;
/**
* Cancel an ongoing thread snapshots search.
* ```typescript
* Textile.threads.cancelSearchSnapshots();
* ```
*/
function cancelSearchSnapshots() {
return __awaiter(this, void 0, void 0, function* () {
return ThreadsBridge.cancelSearchSnapshots();
});
}
exports.cancelSearchSnapshots = cancelSearchSnapshots;
;