This repository was archived by the owner on Dec 3, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
feat: typescript and tests #9
Open
adrianhopebailie
wants to merge
3
commits into
master
Choose a base branch
from
feat/typescript-and-tests
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,11 @@ | ||
node_modules/ | ||
.vscode | ||
node_modules | ||
**/*.js | ||
**/*.js.map | ||
**/*.d.ts | ||
!example.js | ||
!typedoc.js | ||
!scripts/* | ||
coverage | ||
.nyc_output | ||
doc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,23 @@ | ||
# ILP Plugin | ||
> A generic handle to ILP | ||
> An ILP plugin loader | ||
|
||
[](https://npmjs.org/package/ilp-plugin) | ||
[](https://circleci.com/gh/interledgerjs/ilp-plugin) | ||
[](https://standardjs.com) | ||
[](https://snyk.io/test/github/interledgerjs/ilp-plugin) | ||
|
||
The script below will get ILP credentials with no setup whatsoever. You can | ||
The script below will create an instance of an ILP plugin with no setup whatsoever. You can | ||
use this anywhere that you need an ILP plugin created from details in the | ||
environment. | ||
environment or by specifying the detauls in code. | ||
|
||
## Changes in v4 | ||
- The parameter `options.name` has been deprecated. | ||
- The env parameter `ILP_CREDENTIALS` has been deprecated in favour of `ILP_OPTIONS`. | ||
- The module now includes type definitions for `Plugin` and related types and therefore exports both the type definitions and the `createPlugin` and `isPlugin` functions. | ||
|
||
## Examples | ||
|
||
Javascript: | ||
```js | ||
const plugin = require('ilp-plugin')() | ||
|
||
|
@@ -22,9 +30,29 @@ async function run () { | |
run() | ||
``` | ||
|
||
First, the script checks whether `ILP_CREDENTIALS` is defined in the environment. | ||
`ILP_CREDENTIALS` must contain a JSON object with the options passed into the | ||
constructor of `ilp-plugin-btp` or the module name in `ILP_PLUGIN`. | ||
TypeScript: | ||
```typescript | ||
import createPlugin, { DataHandler } from '..' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this is a README example, should it import from |
||
const plugin = createPlugin() | ||
const echo: DataHandler = (data: Buffer) => { | ||
return Promise.resolve(data) | ||
} | ||
|
||
async function run () { | ||
plugin.registerDataHandler(echo) | ||
await plugin.connect() | ||
await plugin.sendData(/* ... */) | ||
process.exit(0) | ||
} | ||
|
||
run() | ||
``` | ||
|
||
If no parameters are provided it will attempt to find the config in environment variables. If these are not found it will load a plugin that attempts to connect to a local moneyd instance on port 7768. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Link to moneyd |
||
|
||
The Environment variables that can be set are: | ||
|
||
`ILP_PLUGIN` : The name/path of the plugin module | ||
`ILP_PLUGIN_OPTIONS` : The options passed to the constructor, serialized as a JSON object. | ||
|
||
By default, a random secret will be generated and the plugin will connect to | ||
`btp+ws://localhost:7768`. | ||
The options object passed is a subset of the account configuration object proveded to `ilp-connector`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
const plugin = require('.')() | ||
|
||
async function run () { | ||
await plugin.connect() | ||
await plugin.sendData(/* ... */) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this example intended to be runnable? If so, there should be some dummy data here. |
||
process.exit(0) | ||
} | ||
|
||
run() |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/detauls/defaults