import { API } from '../core/api' ; import { streamHandler } from '../helpers/handlers' ; import { Contact , ContactList , QueryOptions , QueryResult } from '../models' ; import { ReadableStream } from 'web-streams-polyfill/ponyfill' ; extends API export default class Contacts extends API { param contact returns async add ( address , contact ) { const response = await this . sendPut ( `contacts/${ address }` , undefined , undefined , contact ) ; return response . status === 204 ; } param address returns async get ( address ) { const response = await this . sendGet ( `contacts/${ address }` ) ; return response . json ( ) as Promise < Contact > ; } returns async list ( ) { const response = await this . sendGet ( 'contacts' ) ; return response . json ( ) as Promise < ContactList > ; } param address returns async remove ( contactId ) { const response = await this . sendDelete ( `contacts/${ contactId }` ) ; return response . status === 204 ; } param name param address param options returns async search ( name ? , address ? , options ? ) { const opts = options || { } ; const cleanOpts = { name : name || '' , address : address || '' , local : opts . local || false , remote : opts . remote || false , limit : opts . limit || 5 , wait : opts . wait || 2 } ; const response = await this . sendPost ( 'contacts/search' , undefined , cleanOpts ) ; if ( ! response . body ) { throw Error ( 'Empty response stream' ) ; } return streamHandler < QueryResult > ( response . body as ReadableStream ) ; } }