From 16da1ab6af6e3f63f1175e271846b8d2906075ba Mon Sep 17 00:00:00 2001 From: Marius Darila Date: Mon, 16 May 2016 20:54:43 +0300 Subject: [PATCH] feat(ipfs api): extend connector with add and cat data --- IpfsApiHelper.js | 62 +++ IpfsApiHelper.ts | 118 +++++ IpfsConnector.js | 10 + IpfsConnector.ts | 17 +- docs/assets/js/search.js | 2 +- .../_ipfsapihelper_.ipfsapihelper.html | 470 ++++++++++++++++++ docs/classes/_ipfsbin_.ipfsbin.html | 9 +- .../_ipfsconnector_.ipfsconnector.html | 88 +++- docs/globals.html | 4 + docs/index.html | 3 + docs/modules/_ipfsapihelper_.html | 183 +++++++ docs/modules/_ipfsbin_.html | 9 +- docs/modules/_ipfsconnector_.html | 7 +- package.json | 2 + tests/index.js | 18 +- typings/main/definitions/ipfs-api/index.d.ts | 10 +- 16 files changed, 977 insertions(+), 35 deletions(-) create mode 100644 IpfsApiHelper.js create mode 100644 IpfsApiHelper.ts create mode 100644 docs/classes/_ipfsapihelper_.ipfsapihelper.html create mode 100644 docs/modules/_ipfsapihelper_.html diff --git a/IpfsApiHelper.js b/IpfsApiHelper.js new file mode 100644 index 0000000..660077f --- /dev/null +++ b/IpfsApiHelper.js @@ -0,0 +1,62 @@ +"use strict"; +const Promise = require('bluebird'); +class IpfsApiHelper { + constructor(provider) { + this.apiClient = provider; + } + add(source) { + if (Array.isArray(source)) { + return this._addMultiple(source); + } + return this._add(source); + } + cat(hashSource) { + if (Array.isArray(hashSource)) { + return this._catMultiple(hashSource); + } + return this._cat(hashSource); + } + _add(source) { + const options = Object.assign({}, { isPath: false, recursive: false, followSymlinks: false }, source.options); + let contentBody = source.data; + if (!options.isPath) { + contentBody = new Buffer(contentBody); + } + return this.apiClient.add(contentBody, options); + } + _addMultiple(sources = []) { + let data = []; + sources.forEach((source) => { + data.push(this._add(source)); + }); + return Promise.all(data); + } + _cat(source) { + let buf = new Buffer(0); + return new Promise((resolve, reject) => { + return this.apiClient.cat(source.id).then((response) => { + if (response.readable) { + return response.on('error', (err) => { + return reject(err); + }).on('data', (data) => { + buf = Buffer.concat([buf, data]); + }).on('end', () => { + if (source.encoding) { + return resolve(buf.toString(source.encoding)); + } + return resolve(buf); + }); + } + return resolve(response); + }).catch((err) => reject(err)); + }); + } + _catMultiple(hashSources = []) { + let data = []; + hashSources.forEach((hash) => { + data.push(this._cat(hash)); + }); + return Promise.all(data); + } +} +exports.IpfsApiHelper = IpfsApiHelper; diff --git a/IpfsApiHelper.ts b/IpfsApiHelper.ts new file mode 100644 index 0000000..f82dbad --- /dev/null +++ b/IpfsApiHelper.ts @@ -0,0 +1,118 @@ +/// +import * as Promise from 'bluebird'; + +export class IpfsApiHelper { + public apiClient: any; + + constructor (provider: any) { + this.apiClient = provider; + } + + /** + * Add data to ipfs + * @param source + * @returns {Bluebird} + */ + public add (source: { + data: any, + options?: { isPath: boolean, recursive: boolean, followSymlinks: boolean } + }[]): Promise<{} | {}[]> { + if (Array.isArray(source)) { + return this._addMultiple(source); + } + return this._add(source); + } + + /** + * Read data from ipfs + * @param hashSource + * @returns {any} + */ + public cat (hashSource: { + id: string, + encoding?: string + }[]): Promise<{} | {}[]> { + if (Array.isArray(hashSource)) { + return this._catMultiple(hashSource); + } + return this._cat(hashSource); + } + + /** + * + * @param source + * @returns {Bluebird} + * @private + */ + private _add (source: any): Promise<{}> { + const options = Object.assign({}, + { isPath: false, recursive: false, followSymlinks: false }, + source.options); + + let contentBody = source.data; + + if (!options.isPath) { + contentBody = new Buffer(contentBody); + } + + return this.apiClient.add(contentBody, options); + } + + /** + * + * @param sources + * @returns {Bluebird} + * @private + */ + private _addMultiple (sources: {}[] = []): Promise<{}[]> { + + let data: Promise<{}>[] = []; + + sources.forEach((source) => { + data.push(this._add(source)); + }); + + return Promise.all(data); + } + + /** + * + * @param source + * @returns {Bluebird} + * @private + */ + private _cat (source: any): Promise<{}> { + let buf = new Buffer(0); + return new Promise((resolve, reject) => { + return this.apiClient.cat(source.id).then((response: any) => { + if (response.readable) { + return response.on('error', (err: Error) => { + return reject(err); + }).on('data', (data: Buffer) => { + buf = Buffer.concat([buf, data]); + }).on('end', () => { + if (source.encoding) { + return resolve(buf.toString(source.encoding)); + } + return resolve(buf); + }); + } + return resolve(response); + }).catch((err: Error) => reject(err)); + }); + } + + /** + * + * @param hashSources + * @returns {Bluebird} + * @private + */ + private _catMultiple (hashSources: {}[] = []): Promise<{}[]> { + let data: Promise<{}>[] = []; + hashSources.forEach((hash) => { + data.push(this._cat(hash)); + }); + return Promise.all(data); + } +} \ No newline at end of file diff --git a/IpfsConnector.js b/IpfsConnector.js index d5e151c..7d310aa 100644 --- a/IpfsConnector.js +++ b/IpfsConnector.js @@ -2,8 +2,10 @@ const os_1 = require('os'); const Promise = require('bluebird'); const IpfsBin_1 = require('./IpfsBin'); +const IpfsApiHelper_1 = require('./IpfsApiHelper'); const childProcess = require('child_process'); const path = require('path'); +const ipfsApi = require('ipfs-api'); const symbolEnforcer = Symbol(); const symbol = Symbol(); class IpfsConnector { @@ -30,6 +32,13 @@ class IpfsConnector { } return this[symbol]; } + get api() { + if (!this._api) { + let api = ipfsApi(this.options.apiAddress); + this._api = new IpfsApiHelper_1.IpfsApiHelper(api); + } + return this._api; + } setLogger(logger) { this.logger = logger; } @@ -58,6 +67,7 @@ class IpfsConnector { stop(signal = 'SIGINT') { this.process.kill(signal); this.process = null; + this._api = null; this.options.retry = true; } _init() { diff --git a/IpfsConnector.ts b/IpfsConnector.ts index ec2e838..a0eac97 100644 --- a/IpfsConnector.ts +++ b/IpfsConnector.ts @@ -3,10 +3,11 @@ import { homedir } from 'os'; import * as Promise from 'bluebird'; import { IpfsBin } from './IpfsBin'; +import { IpfsApiHelper } from './IpfsApiHelper'; import childProcess = require('child_process'); import path = require('path'); -import ipfsApi = require('ipfs-api'); +import * as ipfsApi from 'ipfs-api'; const symbolEnforcer = Symbol(); const symbol = Symbol(); @@ -15,6 +16,7 @@ export class IpfsConnector { private process: childProcess.ChildProcess; private downloadManager = new IpfsBin(); private logger: any = console; + private _api: IpfsApiHelper; public options = { retry: true, apiAddress: '/ip4/127.0.0.1/tcp/5001', @@ -46,6 +48,18 @@ export class IpfsConnector { return this[symbol]; } + /** + * + * @returns {IpfsApiHelper} + */ + get api (): IpfsApiHelper { + if (!this._api) { + let api = ipfsApi(this.options.apiAddress); + this._api = new IpfsApiHelper(api); + } + return this._api; + } + /** * Set logging object, winston works great * @param logger @@ -101,6 +115,7 @@ export class IpfsConnector { public stop (signal = 'SIGINT'): void { this.process.kill(signal); this.process = null; + this._api = null; this.options.retry = true; } diff --git a/docs/assets/js/search.js b/docs/assets/js/search.js index 2af3a2a..b996328 100644 --- a/docs/assets/js/search.js +++ b/docs/assets/js/search.js @@ -1 +1 @@ -var typedoc = typedoc || {};typedoc.search = typedoc.search || {};typedoc.search.data = {"kinds":{"1":"External module","32":"Variable","128":"Class","512":"Constructor","1024":"Property","2048":"Method","2097152":"Object literal"},"rows":[{"id":0,"kind":1,"name":"\"IpfsConnector\"","url":"modules/_ipfsconnector_.html","classes":"tsd-kind-external-module"},{"id":1,"kind":128,"name":"IpfsConnector","url":"classes/_ipfsconnector_.ipfsconnector.html","classes":"tsd-kind-class tsd-parent-kind-external-module","parent":"\"IpfsConnector\""},{"id":2,"kind":1024,"name":"process","url":"classes/_ipfsconnector_.ipfsconnector.html#process","classes":"tsd-kind-property tsd-parent-kind-class tsd-is-private","parent":"\"IpfsConnector\".IpfsConnector"},{"id":3,"kind":1024,"name":"downloadManager","url":"classes/_ipfsconnector_.ipfsconnector.html#downloadmanager","classes":"tsd-kind-property tsd-parent-kind-class tsd-is-private","parent":"\"IpfsConnector\".IpfsConnector"},{"id":4,"kind":1024,"name":"logger","url":"classes/_ipfsconnector_.ipfsconnector.html#logger","classes":"tsd-kind-property tsd-parent-kind-class tsd-is-private","parent":"\"IpfsConnector\".IpfsConnector"},{"id":5,"kind":2097152,"name":"options","url":"classes/_ipfsconnector_.ipfsconnector.html#options","classes":"tsd-kind-object-literal tsd-parent-kind-class","parent":"\"IpfsConnector\".IpfsConnector"},{"id":6,"kind":32,"name":"retry","url":"classes/_ipfsconnector_.ipfsconnector.html#options.retry","classes":"tsd-kind-variable tsd-parent-kind-object-literal","parent":"\"IpfsConnector\".IpfsConnector.options"},{"id":7,"kind":32,"name":"apiAddress","url":"classes/_ipfsconnector_.ipfsconnector.html#options.apiaddress","classes":"tsd-kind-variable tsd-parent-kind-object-literal","parent":"\"IpfsConnector\".IpfsConnector.options"},{"id":8,"kind":32,"name":"args","url":"classes/_ipfsconnector_.ipfsconnector.html#options.args","classes":"tsd-kind-variable tsd-parent-kind-object-literal","parent":"\"IpfsConnector\".IpfsConnector.options"},{"id":9,"kind":32,"name":"executable","url":"classes/_ipfsconnector_.ipfsconnector.html#options.executable","classes":"tsd-kind-variable tsd-parent-kind-object-literal","parent":"\"IpfsConnector\".IpfsConnector.options"},{"id":10,"kind":2097152,"name":"extra","url":"classes/_ipfsconnector_.ipfsconnector.html#options.extra","classes":"tsd-kind-object-literal tsd-parent-kind-object-literal","parent":"\"IpfsConnector\".IpfsConnector.options"},{"id":11,"kind":32,"name":"env","url":"classes/_ipfsconnector_.ipfsconnector.html#options.extra.env","classes":"tsd-kind-variable tsd-parent-kind-object-literal","parent":"\"IpfsConnector\".IpfsConnector.options.extra"},{"id":12,"kind":32,"name":"detached","url":"classes/_ipfsconnector_.ipfsconnector.html#options.extra.detached","classes":"tsd-kind-variable tsd-parent-kind-object-literal","parent":"\"IpfsConnector\".IpfsConnector.options.extra"},{"id":13,"kind":512,"name":"constructor","url":"classes/_ipfsconnector_.ipfsconnector.html#constructor","classes":"tsd-kind-constructor tsd-parent-kind-class","parent":"\"IpfsConnector\".IpfsConnector"},{"id":14,"kind":2048,"name":"getInstance","url":"classes/_ipfsconnector_.ipfsconnector.html#getinstance","classes":"tsd-kind-method tsd-parent-kind-class tsd-is-static","parent":"\"IpfsConnector\".IpfsConnector"},{"id":15,"kind":2048,"name":"setLogger","url":"classes/_ipfsconnector_.ipfsconnector.html#setlogger","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"IpfsConnector\".IpfsConnector"},{"id":16,"kind":2048,"name":"setConfig","url":"classes/_ipfsconnector_.ipfsconnector.html#setconfig","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"IpfsConnector\".IpfsConnector"},{"id":17,"kind":2048,"name":"checkExecutable","url":"classes/_ipfsconnector_.ipfsconnector.html#checkexecutable","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"IpfsConnector\".IpfsConnector"},{"id":18,"kind":2048,"name":"start","url":"classes/_ipfsconnector_.ipfsconnector.html#start","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"IpfsConnector\".IpfsConnector"},{"id":19,"kind":2048,"name":"stop","url":"classes/_ipfsconnector_.ipfsconnector.html#stop","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"IpfsConnector\".IpfsConnector"},{"id":20,"kind":2048,"name":"_init","url":"classes/_ipfsconnector_.ipfsconnector.html#_init","classes":"tsd-kind-method tsd-parent-kind-class tsd-is-private","parent":"\"IpfsConnector\".IpfsConnector"},{"id":21,"kind":2048,"name":"_start","url":"classes/_ipfsconnector_.ipfsconnector.html#_start","classes":"tsd-kind-method tsd-parent-kind-class tsd-is-private","parent":"\"IpfsConnector\".IpfsConnector"},{"id":22,"kind":32,"name":"symbolEnforcer","url":"modules/_ipfsconnector_.html#symbolenforcer","classes":"tsd-kind-variable tsd-parent-kind-external-module tsd-is-not-exported","parent":"\"IpfsConnector\""},{"id":23,"kind":32,"name":"symbol","url":"modules/_ipfsconnector_.html#symbol","classes":"tsd-kind-variable tsd-parent-kind-external-module tsd-is-not-exported","parent":"\"IpfsConnector\""}]}; \ No newline at end of file +var typedoc = typedoc || {};typedoc.search = typedoc.search || {};typedoc.search.data = {"kinds":{"1":"External module","32":"Variable","128":"Class","512":"Constructor","1024":"Property","2048":"Method","262144":"Accessor","2097152":"Object literal"},"rows":[{"id":0,"kind":1,"name":"\"IpfsConnector\"","url":"modules/_ipfsconnector_.html","classes":"tsd-kind-external-module"},{"id":1,"kind":128,"name":"IpfsConnector","url":"classes/_ipfsconnector_.ipfsconnector.html","classes":"tsd-kind-class tsd-parent-kind-external-module","parent":"\"IpfsConnector\""},{"id":2,"kind":1024,"name":"process","url":"classes/_ipfsconnector_.ipfsconnector.html#process","classes":"tsd-kind-property tsd-parent-kind-class tsd-is-private","parent":"\"IpfsConnector\".IpfsConnector"},{"id":3,"kind":1024,"name":"downloadManager","url":"classes/_ipfsconnector_.ipfsconnector.html#downloadmanager","classes":"tsd-kind-property tsd-parent-kind-class tsd-is-private","parent":"\"IpfsConnector\".IpfsConnector"},{"id":4,"kind":1024,"name":"logger","url":"classes/_ipfsconnector_.ipfsconnector.html#logger","classes":"tsd-kind-property tsd-parent-kind-class tsd-is-private","parent":"\"IpfsConnector\".IpfsConnector"},{"id":5,"kind":1024,"name":"_api","url":"classes/_ipfsconnector_.ipfsconnector.html#_api","classes":"tsd-kind-property tsd-parent-kind-class tsd-is-private","parent":"\"IpfsConnector\".IpfsConnector"},{"id":6,"kind":2097152,"name":"options","url":"classes/_ipfsconnector_.ipfsconnector.html#options","classes":"tsd-kind-object-literal tsd-parent-kind-class","parent":"\"IpfsConnector\".IpfsConnector"},{"id":7,"kind":32,"name":"retry","url":"classes/_ipfsconnector_.ipfsconnector.html#options.retry","classes":"tsd-kind-variable tsd-parent-kind-object-literal","parent":"\"IpfsConnector\".IpfsConnector.options"},{"id":8,"kind":32,"name":"apiAddress","url":"classes/_ipfsconnector_.ipfsconnector.html#options.apiaddress","classes":"tsd-kind-variable tsd-parent-kind-object-literal","parent":"\"IpfsConnector\".IpfsConnector.options"},{"id":9,"kind":32,"name":"args","url":"classes/_ipfsconnector_.ipfsconnector.html#options.args","classes":"tsd-kind-variable tsd-parent-kind-object-literal","parent":"\"IpfsConnector\".IpfsConnector.options"},{"id":10,"kind":32,"name":"executable","url":"classes/_ipfsconnector_.ipfsconnector.html#options.executable","classes":"tsd-kind-variable tsd-parent-kind-object-literal","parent":"\"IpfsConnector\".IpfsConnector.options"},{"id":11,"kind":2097152,"name":"extra","url":"classes/_ipfsconnector_.ipfsconnector.html#options.extra","classes":"tsd-kind-object-literal tsd-parent-kind-object-literal","parent":"\"IpfsConnector\".IpfsConnector.options"},{"id":12,"kind":32,"name":"env","url":"classes/_ipfsconnector_.ipfsconnector.html#options.extra.env","classes":"tsd-kind-variable tsd-parent-kind-object-literal","parent":"\"IpfsConnector\".IpfsConnector.options.extra"},{"id":13,"kind":32,"name":"detached","url":"classes/_ipfsconnector_.ipfsconnector.html#options.extra.detached","classes":"tsd-kind-variable tsd-parent-kind-object-literal","parent":"\"IpfsConnector\".IpfsConnector.options.extra"},{"id":14,"kind":512,"name":"constructor","url":"classes/_ipfsconnector_.ipfsconnector.html#constructor","classes":"tsd-kind-constructor tsd-parent-kind-class","parent":"\"IpfsConnector\".IpfsConnector"},{"id":15,"kind":2048,"name":"getInstance","url":"classes/_ipfsconnector_.ipfsconnector.html#getinstance","classes":"tsd-kind-method tsd-parent-kind-class tsd-is-static","parent":"\"IpfsConnector\".IpfsConnector"},{"id":16,"kind":262144,"name":"api","url":"classes/_ipfsconnector_.ipfsconnector.html#api","classes":"tsd-kind-get-signature tsd-parent-kind-class","parent":"\"IpfsConnector\".IpfsConnector"},{"id":17,"kind":2048,"name":"setLogger","url":"classes/_ipfsconnector_.ipfsconnector.html#setlogger","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"IpfsConnector\".IpfsConnector"},{"id":18,"kind":2048,"name":"setConfig","url":"classes/_ipfsconnector_.ipfsconnector.html#setconfig","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"IpfsConnector\".IpfsConnector"},{"id":19,"kind":2048,"name":"checkExecutable","url":"classes/_ipfsconnector_.ipfsconnector.html#checkexecutable","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"IpfsConnector\".IpfsConnector"},{"id":20,"kind":2048,"name":"start","url":"classes/_ipfsconnector_.ipfsconnector.html#start","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"IpfsConnector\".IpfsConnector"},{"id":21,"kind":2048,"name":"stop","url":"classes/_ipfsconnector_.ipfsconnector.html#stop","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"IpfsConnector\".IpfsConnector"},{"id":22,"kind":2048,"name":"_init","url":"classes/_ipfsconnector_.ipfsconnector.html#_init","classes":"tsd-kind-method tsd-parent-kind-class tsd-is-private","parent":"\"IpfsConnector\".IpfsConnector"},{"id":23,"kind":2048,"name":"_start","url":"classes/_ipfsconnector_.ipfsconnector.html#_start","classes":"tsd-kind-method tsd-parent-kind-class tsd-is-private","parent":"\"IpfsConnector\".IpfsConnector"},{"id":24,"kind":32,"name":"symbolEnforcer","url":"modules/_ipfsconnector_.html#symbolenforcer","classes":"tsd-kind-variable tsd-parent-kind-external-module tsd-is-not-exported","parent":"\"IpfsConnector\""},{"id":25,"kind":32,"name":"symbol","url":"modules/_ipfsconnector_.html#symbol","classes":"tsd-kind-variable tsd-parent-kind-external-module tsd-is-not-exported","parent":"\"IpfsConnector\""}]}; \ No newline at end of file diff --git a/docs/classes/_ipfsapihelper_.ipfsapihelper.html b/docs/classes/_ipfsapihelper_.ipfsapihelper.html new file mode 100644 index 0000000..6aeb021 --- /dev/null +++ b/docs/classes/_ipfsapihelper_.ipfsapihelper.html @@ -0,0 +1,470 @@ + + + + + + IpfsApiHelper | ipfs-connector + + + + + + +
+
+
+
+ +
+
+ Options +
+
+ All +
    +
  • Public
  • +
  • Public/Protected
  • +
  • All
  • +
+
+ + + + + + +
+
+ Menu +
+
+
+
+
+
+ +

Class IpfsApiHelper

+
+
+
+
+
+
+
+

Hierarchy

+
    +
  • + IpfsApiHelper +
  • +
+
+
+

Index

+
+
+
+

Constructors

+ +
+
+

Properties

+ +
+
+

Methods

+ +
+
+
+
+
+

Constructors

+
+ +

constructor

+ + +
+
+
+

Properties

+
+ +

apiClient

+
apiClient: any
+ +
+
+
+

Methods

+
+ +

Private _add

+
    +
  • _add(source: any): Promise
  • +
+
    +
  • + +
    +
    +

    Parameters

    +
      +
    • +
      source: any
      +
    • +
    +

    Returns Promise

    +
  • +
+
+
+ +

Private _addMultiple

+
    +
  • _addMultiple(sources?: object[]): Promise
  • +
+
    +
  • + +
    +
    +

    Parameters

    +
      +
    • +
      Default value sources: object[] = []
      +
        +
      +
    • +
    +

    Returns Promise

    +
  • +
+
+
+ +

Private _cat

+
    +
  • _cat(source: any): Promise
  • +
+
    +
  • + +
    +
    +

    Parameters

    +
      +
    • +
      source: any
      +
    • +
    +

    Returns Promise

    +
  • +
+
+
+ +

Private _catMultiple

+
    +
  • _catMultiple(hashSources?: object[]): Promise
  • +
+
    +
  • + +
    +
    +

    Parameters

    +
      +
    • +
      Default value hashSources: object[] = []
      +
        +
      +
    • +
    +

    Returns Promise

    +
  • +
+
+
+ +

add

+
    +
  • add(source: object[]): Promise
  • +
+
    +
  • + +
    +
    +

    Add data to ipfs

    +
    +
    +

    Parameters

    +
      +
    • +
      source: object[]
      +
        +
      • +
        data: any
        +
      • +
      • +
        Optional options?: object
        +
          +
        • +
          followSymlinks: boolean
          +
        • +
        • +
          isPath: boolean
          +
        • +
        • +
          recursive: boolean
          +
        • +
        +
      • +
      +
    • +
    +

    Returns Promise

    +
  • +
+
+
+ +

cat

+
    +
  • cat(hashSource: object[]): Promise
  • +
+
    +
  • + +
    +
    +

    Read data from ipfs

    +
    +
    +

    Parameters

    +
      +
    • +
      hashSource: object[]
      +
        +
      • +
        Optional encoding?: string
        +
      • +
      • +
        id: string
        +
      • +
      +
    • +
    +

    Returns Promise

    +
  • +
+
+
+
+ +
+
+
+
+

Legend

+
+
    +
  • Module
  • +
  • Object literal
  • +
  • Variable
  • +
  • Function
  • +
  • Function with type parameter
  • +
  • Index signature
  • +
  • Type alias
  • +
+
    +
  • Enumeration
  • +
  • Enumeration member
  • +
  • Property
  • +
  • Method
  • +
+
    +
  • Interface
  • +
  • Interface with type parameter
  • +
  • Constructor
  • +
  • Property
  • +
  • Method
  • +
  • Index signature
  • +
+
    +
  • Class
  • +
  • Class with type parameter
  • +
  • Constructor
  • +
  • Property
  • +
  • Method
  • +
  • Accessor
  • +
  • Index signature
  • +
+
    +
  • Inherited constructor
  • +
  • Inherited property
  • +
  • Inherited method
  • +
  • Inherited accessor
  • +
+
    +
  • Protected property
  • +
  • Protected method
  • +
  • Protected accessor
  • +
+
    +
  • Private property
  • +
  • Private method
  • +
  • Private accessor
  • +
+
    +
  • Static property
  • +
  • Static method
  • +
+
+
+
+
+

Generated using TypeDoc

+
+
+ + + + \ No newline at end of file diff --git a/docs/classes/_ipfsbin_.ipfsbin.html b/docs/classes/_ipfsbin_.ipfsbin.html index f6ab6b2..dfc80a4 100644 --- a/docs/classes/_ipfsbin_.ipfsbin.html +++ b/docs/classes/_ipfsbin_.ipfsbin.html @@ -115,7 +115,7 @@

constructor

  • @@ -144,7 +144,7 @@

    wrapper

    wrapper: Wrapper
    @@ -161,7 +161,7 @@

    check

  • @@ -190,6 +190,9 @@

    Returns Promise Externals

  • +
  • + "IpfsApiHelper" +
  • "IpfsBin"
  • diff --git a/docs/classes/_ipfsconnector_.ipfsconnector.html b/docs/classes/_ipfsconnector_.ipfsconnector.html index 643a0cf..5610ee3 100644 --- a/docs/classes/_ipfsconnector_.ipfsconnector.html +++ b/docs/classes/_ipfsconnector_.ipfsconnector.html @@ -91,11 +91,18 @@

    Constructors

    Properties

    +
    +

    Accessors

    + +

    Methods

    @@ -178,11 +195,33 @@

    Private process

    process: ChildProcess
    +
    +

    Accessors

    +
    + +

    api

    + + +
    +

    Methods

    @@ -195,7 +234,7 @@

    Private _init

  • @@ -217,7 +256,7 @@

    Private _start

  • @@ -239,7 +278,7 @@

    checkExecutable

  • @@ -262,7 +301,7 @@

    setConfig

  • @@ -294,7 +333,7 @@

    setLogger

  • @@ -326,7 +365,7 @@

    start

  • @@ -348,7 +387,7 @@

    stop

  • @@ -378,7 +417,7 @@

    Static getInstance

  • @@ -399,7 +438,7 @@

    options

    options: object
    @@ -408,7 +447,7 @@

    apiAddress

    apiAddress: string
    @@ -418,7 +457,7 @@

    args

    args: Array<string>
  • @@ -428,7 +467,7 @@

    executable

    executable: string
    @@ -438,7 +477,7 @@

    retry

    retry: boolean
    @@ -448,7 +487,7 @@

    extra

    extra: object
    @@ -457,7 +496,7 @@

    detached

    detached: boolean
    @@ -467,7 +506,7 @@

    env

    env: any
    @@ -490,6 +529,9 @@

    env

  • Externals
  • +
  • + "IpfsApiHelper" +
  • "IpfsBin"
  • @@ -505,6 +547,9 @@

    env

  • constructor
  • +
  • + _api +
  • downloadManager
  • @@ -514,6 +559,9 @@

    env

  • process
  • +
  • + api +
  • _init
  • diff --git a/docs/globals.html b/docs/globals.html index f987d71..11a83e4 100644 --- a/docs/globals.html +++ b/docs/globals.html @@ -71,6 +71,7 @@

    Index

    External modules

    @@ -94,6 +95,9 @@

    External modules

  • Externals
  • +
  • + "IpfsApiHelper" +
  • "IpfsBin"
  • diff --git a/docs/index.html b/docs/index.html index 2b238d9..4d3766a 100644 --- a/docs/index.html +++ b/docs/index.html @@ -82,6 +82,9 @@

    ipfs-connector

  • Externals
  • +
  • + "IpfsApiHelper" +
  • "IpfsBin"
  • diff --git a/docs/modules/_ipfsapihelper_.html b/docs/modules/_ipfsapihelper_.html new file mode 100644 index 0000000..df437f8 --- /dev/null +++ b/docs/modules/_ipfsapihelper_.html @@ -0,0 +1,183 @@ + + + + + + "IpfsApiHelper" | ipfs-connector + + + + + + +
    +
    +
    +
    + +
    +
    + Options +
    +
    + All +
      +
    • Public
    • +
    • Public/Protected
    • +
    • All
    • +
    +
    + + + + + + +
    +
    + Menu +
    +
    +
    +
    +
    +
    + +

    External module "IpfsApiHelper"

    +
    +
    +
    +
    +
    +
    +
    +

    Index

    +
    +
    +
    +

    Classes

    + +
    +
    +
    +
    +
    + +
    +
    +
    +
    +

    Legend

    +
    +
      +
    • Module
    • +
    • Object literal
    • +
    • Variable
    • +
    • Function
    • +
    • Function with type parameter
    • +
    • Index signature
    • +
    • Type alias
    • +
    +
      +
    • Enumeration
    • +
    • Enumeration member
    • +
    • Property
    • +
    • Method
    • +
    +
      +
    • Interface
    • +
    • Interface with type parameter
    • +
    • Constructor
    • +
    • Property
    • +
    • Method
    • +
    • Index signature
    • +
    +
      +
    • Class
    • +
    • Class with type parameter
    • +
    • Constructor
    • +
    • Property
    • +
    • Method
    • +
    • Accessor
    • +
    • Index signature
    • +
    +
      +
    • Inherited constructor
    • +
    • Inherited property
    • +
    • Inherited method
    • +
    • Inherited accessor
    • +
    +
      +
    • Protected property
    • +
    • Protected method
    • +
    • Protected accessor
    • +
    +
      +
    • Private property
    • +
    • Private method
    • +
    • Private accessor
    • +
    +
      +
    • Static property
    • +
    • Static method
    • +
    +
    +
    +
    +
    +

    Generated using TypeDoc

    +
    +
    + + + + \ No newline at end of file diff --git a/docs/modules/_ipfsbin_.html b/docs/modules/_ipfsbin_.html index 872521c..7f144ef 100644 --- a/docs/modules/_ipfsbin_.html +++ b/docs/modules/_ipfsbin_.html @@ -96,7 +96,7 @@

    base

    base: string
    @@ -106,7 +106,7 @@

    defaultTarget

    defaultTarget: string
    @@ -116,7 +116,7 @@

    version

    version: any
    @@ -137,6 +137,9 @@

    version

  • Externals
  • +
  • + "IpfsApiHelper" +
  • "IpfsBin"
  • diff --git a/docs/modules/_ipfsconnector_.html b/docs/modules/_ipfsconnector_.html index 499d3c9..617a93a 100644 --- a/docs/modules/_ipfsconnector_.html +++ b/docs/modules/_ipfsconnector_.html @@ -95,7 +95,7 @@

    symbol

    symbol: symbol
    @@ -105,7 +105,7 @@

    symbolEnforcer

    symbolEnforcer: symbol
    @@ -126,6 +126,9 @@

    symbolEnforcer

  • Externals
  • +
  • + "IpfsApiHelper" +
  • "IpfsBin"
  • diff --git a/package.json b/package.json index a0f5a54..d357571 100644 --- a/package.json +++ b/package.json @@ -15,9 +15,11 @@ "dependencies": { "bin-wrapper": "^3.0.2", "bluebird": "^3.3.5", + "ipfs-api": "^4.0.2", "winston": "^2.2.0" }, "devDependencies": { + "retire": "^1.1.4", "ts-loader": "^0.8.2", "tslint": "^3.10.1", "typedoc": "sierrasoftworks/typedoc#v1.8.10", diff --git a/tests/index.js b/tests/index.js index 3ea0e64..6f19143 100644 --- a/tests/index.js +++ b/tests/index.js @@ -1,7 +1,21 @@ //this is just a placeholder const { IpfsConnector } = require('../IpfsConnector'); -const x = IpfsConnector.getInstance() +const instance = IpfsConnector.getInstance(); +const x = instance .start() - .then(data=> console.log('final start', data)) + .then(data=> { + instance.api.add([{data:'/home/marius/tst', options:{isPath: true, recursive: true}}, {data: '{}'}]).then(data=>{ + console.log('add', data); + instance.api.cat( + [ + {id: 'QmSepp2GXmctpxr6foVrenivKMLR1Fqma9uUcx6yGBrrnD', encoding: 'utf-8'}, + {id: 'QmbJWAESqCsf4RFCqEY7jecCashj8usXiyDNfKtZCwwzGb', encoding: 'utf-8'} + ] + ).then(data1=> console.log('cat', data1)) + }).catch(err=> console.log('err', err)); + }) .catch(err=> console.log('finalerr', err)); +setTimeout(function(){ + IpfsConnector.getInstance().stop(); +}, 15000); diff --git a/typings/main/definitions/ipfs-api/index.d.ts b/typings/main/definitions/ipfs-api/index.d.ts index e66b9aa..b29acc7 100644 --- a/typings/main/definitions/ipfs-api/index.d.ts +++ b/typings/main/definitions/ipfs-api/index.d.ts @@ -1,7 +1,11 @@ -declare class IpfsApi{ - constructor(options?: any); +declare class IpfsApi { + constructor (options?: any); + + add (arrayOrBufferOrStream: any[] | any, options?: {}): Promise<{}>; + cat (sources: string | string[]): Promise<{}>; } declare module 'ipfs-api' { - export = IpfsApi; + const stub: any; + export = stub; } \ No newline at end of file