UNPKG

textiot

Version:

A framework for building web and native (IoT) Dapps on the IPFS network

94 lines (93 loc) 3.35 kB
"use strict"; 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.cancelSearch = exports.search = exports.threads = exports.remove = exports.list = exports.get = exports.add = void 0; const react_native_1 = require("react-native"); const buffer_1 = require("buffer"); const model_1 = require("./model"); const { ContactsBridge } = react_native_1.NativeModules; /** * Add a new Contact after fetching the Contact information. */ function add(contact) { return __awaiter(this, void 0, void 0, function* () { const payload = model_1.Contact.encode(contact).finish(); yield ContactsBridge.add(buffer_1.Buffer.from(payload).toString('base64')); }); } exports.add = add; /** * Get Contact information by address. */ function get(address) { return __awaiter(this, void 0, void 0, function* () { // This throws an error if no contact is found const result = yield ContactsBridge.get(address); return model_1.Contact.decode(buffer_1.Buffer.from(result, 'base64')); }); } exports.get = get; /** * List all known Contacts. */ function list() { return __awaiter(this, void 0, void 0, function* () { const result = yield ContactsBridge.list(); return model_1.ContactList.decode(buffer_1.Buffer.from(result, 'base64')); }); } exports.list = list; /** * Remove a Contact by their address. */ function remove(address) { return __awaiter(this, void 0, void 0, function* () { return ContactsBridge.remove(address); }); } exports.remove = remove; /** * List all Threads in common with a Contact. * ```typescript * Textile.contacts.threads(address); * ``` */ function threads(address) { return __awaiter(this, void 0, void 0, function* () { const result = yield ContactsBridge.threads(address); return model_1.ThreadList.decode(buffer_1.Buffer.from(result, 'base64')); }); } exports.threads = threads; /** * Search for Contacts over network. * ```typescript * Textile.contacts.search(query, options); * ``` */ function search(query, options) { return __awaiter(this, void 0, void 0, function* () { return ContactsBridge.search(buffer_1.Buffer.from(model_1.ContactQuery.encode(query).finish()).toString('base64'), buffer_1.Buffer.from(model_1.QueryOptions.encode(options).finish()).toString('base64')); }); } exports.search = search; /** * Cancel an ongoing contact search. * ```typescript * Textile.contacts.cancelSearch(); * ``` */ function cancelSearch() { return __awaiter(this, void 0, void 0, function* () { return ContactsBridge.cancelSearch(); }); } exports.cancelSearch = cancelSearch;