Skip to content

Commit

Permalink
use bluebird coroutine instead of co, fixes warnings about promises n…
Browse files Browse the repository at this point in the history
…ot returned in handlers
  • Loading branch information
transcranial committed Nov 13, 2015
1 parent 034cec2 commit 4bbb1e3
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 35 deletions.
13 changes: 6 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "mesh-tree",
"version": "2.1.1",
"version": "2.1.2",
"description": "Utility functions for traversing the Medical Subject Heading (MeSH) tree",
"main": "dist/index.js",
"scripts": {
"initdb-test": "tar -xzf test/fixtures/mesh_subset.nt.tar.gz -C test/fixtures; node_modules/levelgraph-n3/import.js test/fixtures/mesh_subset.nt -o ./dbtest; rm test/fixtures/mesh_subset.nt",
"test": "NODE_ENV=test node_modules/.bin/mocha --reporter spec --compilers js:babel/register",
"test": "node_modules/.bin/mocha --reporter spec --compilers js:babel/register",
"initdb": "node_modules/levelgraph-n3/import.js $PATH_TO_MESH_RDF -o $PATH_TO_MESH_DB",
"initdb-quiet": "node_modules/levelgraph-n3/import.js --quiet $PATH_TO_MESH_RDF -o $PATH_TO_MESH_DB",
"build": "rm -rf dist && node_modules/.bin/babel --optional runtime src --out-dir dist",
Expand Down Expand Up @@ -36,18 +36,17 @@
},
"devDependencies": {
"babel": "^5.8.29",
"babel-eslint": "^4.1.3",
"chai": "^3.4.0",
"babel-eslint": "^4.1.5",
"chai": "^3.4.1",
"coveralls": "^2.11.4",
"eslint": "^1.7.3",
"isparta": "^3.1.0",
"eslint": "^1.9.0",
"isparta": "^3.5.3",
"mocha": "^2.3.3",
"multilevel": "^7.2.0"
},
"dependencies": {
"babel-runtime": "^5.8.29",
"bluebird": "^3.0.2",
"co": "^4.6.0",
"level": "^1.3.0",
"levelgraph": "^1.1.0",
"levelgraph-n3": "^1.0.0",
Expand Down
10 changes: 6 additions & 4 deletions src/helper/wikipedia.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import request from 'request';
import Bluebird from 'bluebird';
import Promise from 'bluebird';

let requestPromise = Bluebird.promisify(request, {multiArgs: true});
let requestPromise = Promise.promisify(request, {multiArgs: true});

export function* getMainSections(articleTitle) {
let getMainSections = Promise.coroutine(function* (articleTitle) {

let url = 'http://en.wikipedia.org/w/api.php?redirects=true&format=json&utf8=true&action=query&titles=' + articleTitle + '&prop=extracts&explaintext=true&exsectionformat=wiki&continue=';

Expand Down Expand Up @@ -80,4 +80,6 @@ export function* getMainSections(articleTitle) {
return sections;
}

}
});

export { getMainSections };
47 changes: 23 additions & 24 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import levelgraph from 'levelgraph';
import levelgraphN3 from 'levelgraph-n3';
import level from 'level';
import _ from 'lodash';
import Bluebird from 'bluebird';
import co from 'co';
import Promise from 'bluebird';
import * as wikipedia from './helper/wikipedia';
import permutations from './helper/permutations';

Expand All @@ -25,7 +24,7 @@ class MeshTree {
}

this.db = levelgraphN3(levelgraph(DB));
this.dbSearch = Bluebird.promisify(this.db.search, {multiArgs: false});
this.dbSearch = Promise.promisify(this.db.search, {multiArgs: false});

}

Expand Down Expand Up @@ -59,7 +58,7 @@ class MeshTree {
*
* By default, only TopicalDescriptor and GeographicalDescriptor are included
*/
MeshTree.prototype.getAllDescUIs = co.wrap(function* (opts) {
MeshTree.prototype.getAllDescUIs = Promise.coroutine(function* (opts) {
opts = opts || {};
let format = opts.format || 'rdf';
let classes = opts.classes || ['TopicalDescriptor', 'GeographicalDescriptor'];
Expand All @@ -81,7 +80,7 @@ MeshTree.prototype.getAllDescUIs = co.wrap(function* (opts) {
/*
* Returns array of all chemical supplementary records
*/
MeshTree.prototype.getAllSCRChemicalUIs = co.wrap(function* (opts) {
MeshTree.prototype.getAllSCRChemicalUIs = Promise.coroutine(function* (opts) {
opts = opts || {};
let format = opts.format || 'rdf';

Expand All @@ -98,7 +97,7 @@ MeshTree.prototype.getAllSCRChemicalUIs = co.wrap(function* (opts) {
/*
* Returns array of all disease (rare) supplementary records
*/
MeshTree.prototype.getAllSCRDiseaseUIs = co.wrap(function* (opts) {
MeshTree.prototype.getAllSCRDiseaseUIs = Promise.coroutine(function* (opts) {
opts = opts || {};
let format = opts.format || 'rdf';

Expand All @@ -115,7 +114,7 @@ MeshTree.prototype.getAllSCRDiseaseUIs = co.wrap(function* (opts) {
/*
* Returns array of all protocol (e.g., cancer-related) supplementary records
*/
MeshTree.prototype.getAllSCRProtocolUIs = co.wrap(function* (opts) {
MeshTree.prototype.getAllSCRProtocolUIs = Promise.coroutine(function* (opts) {
opts = opts || {};
let format = opts.format || 'rdf';

Expand All @@ -136,7 +135,7 @@ MeshTree.prototype.getAllSCRProtocolUIs = co.wrap(function* (opts) {
* `0` - abstract only
* `1` - all text
*/
MeshTree.prototype.getWikiEntry = co.wrap(function* (opts) {
MeshTree.prototype.getWikiEntry = Promise.coroutine(function* (opts) {
opts = opts || {};
let descUI = this.formatID(opts.id, 'mesh');
let level = opts.level || 0;
Expand Down Expand Up @@ -180,7 +179,7 @@ MeshTree.prototype.getWikiEntry = co.wrap(function* (opts) {
*
* Example: 'D000001' returns ['D03.438.221.173']
*/
MeshTree.prototype.getTreeNumbers = co.wrap(function* (opts) {
MeshTree.prototype.getTreeNumbers = Promise.coroutine(function* (opts) {
opts = opts || {};
let descUI = this.formatID(opts.id, 'mesh');
let format = opts.format || 'rdf';
Expand All @@ -201,7 +200,7 @@ MeshTree.prototype.getTreeNumbers = co.wrap(function* (opts) {
*
* Example: 'D03.438.221.173' returns 'D000001'
*/
MeshTree.prototype.treeNumberToUI = co.wrap(function* (opts) {
MeshTree.prototype.treeNumberToUI = Promise.coroutine(function* (opts) {
opts = opts || {};
let treeNum = this.formatID(opts.treeNum, 'mesh');
let format = opts.format || 'rdf';
Expand All @@ -225,7 +224,7 @@ MeshTree.prototype.treeNumberToUI = co.wrap(function* (opts) {
*
* Example: 'D000001' returns 'Chemicals and Drugs'
*/
MeshTree.prototype.getCategory = co.wrap(function* (opts) {
MeshTree.prototype.getCategory = Promise.coroutine(function* (opts) {
opts = opts || {};
let descUI = this.formatID(opts.id, 'mesh');

Expand All @@ -245,7 +244,7 @@ MeshTree.prototype.getCategory = co.wrap(function* (opts) {
*
* Example: 'D000001' returns 'Calcimycin'
*/
MeshTree.prototype.getPrefTerm = co.wrap(function* (opts) {
MeshTree.prototype.getPrefTerm = Promise.coroutine(function* (opts) {
opts = opts || {};
let descUI = this.formatID(opts.id, 'mesh');

Expand Down Expand Up @@ -275,7 +274,7 @@ MeshTree.prototype.getPrefTerm = co.wrap(function* (opts) {
*
* Example: 'D000001' returns [ 'A23187, Antibiotic', 'Antibiotic A23187', 'A23187', 'A 23187', 'A-23187', 'Calcimycin' ]
*/
MeshTree.prototype.getAllTerms = co.wrap(function* (opts) {
MeshTree.prototype.getAllTerms = Promise.coroutine(function* (opts) {
opts = opts || {};
let descUI = this.formatID(opts.id, 'mesh');

Expand Down Expand Up @@ -327,7 +326,7 @@ MeshTree.prototype.getAllTerms = co.wrap(function* (opts) {
*
* Example: 'D000001', via concept 'M0000001', returns 'An ionophorous, polyether antibiotic from Streptomyces chartreusensis. It binds and transports CALCIUM and other divalent cations across membranes and uncouples oxidative phosphorylation while inhibiting ATPase of rat liver mitochondria. The substance is used mostly as a biochemical tool to study the role of divalent cations in various biological systems.'
*/
MeshTree.prototype.getScopeNote = co.wrap(function* (opts) {
MeshTree.prototype.getScopeNote = Promise.coroutine(function* (opts) {
opts = opts || {};
let descUI = this.formatID(opts.id, 'mesh');

Expand Down Expand Up @@ -366,7 +365,7 @@ MeshTree.prototype.getScopeNote = co.wrap(function* (opts) {
*
* Example: 'C025735' returns ['D001286', 'D002164', 'D012602']
*/
MeshTree.prototype.getParents = co.wrap(function* (opts) {
MeshTree.prototype.getParents = Promise.coroutine(function* (opts) {
opts = opts || {};
let ui = this.formatID(opts.id, 'mesh');
let format = opts.format || 'rdf';
Expand Down Expand Up @@ -406,7 +405,7 @@ MeshTree.prototype.getParents = co.wrap(function* (opts) {
* Example: 'D000001' returns ['D001583', 'D006574', 'D006571']
* 'D005138' returns ['D005123', 'D006197', 'D005145', 'D012679', 'D034582', 'D006257', 'D001829']
*/
MeshTree.prototype.getAncestors = co.wrap(function* (opts) {
MeshTree.prototype.getAncestors = Promise.coroutine(function* (opts) {
opts = opts || {};
let descUI = this.formatID(opts.id, 'mesh');
let format = opts.format || 'rdf';
Expand Down Expand Up @@ -439,7 +438,7 @@ MeshTree.prototype.getAncestors = co.wrap(function* (opts) {
*
* Example: 'D012343' returns ['D012345', 'D000926', 'D012346']
*/
MeshTree.prototype.getChildren = co.wrap(function* (opts) {
MeshTree.prototype.getChildren = Promise.coroutine(function* (opts) {
opts = opts || {};
let descUI = this.formatID(opts.id, 'mesh');
let format = opts.format || 'rdf';
Expand Down Expand Up @@ -476,7 +475,7 @@ MeshTree.prototype.getChildren = co.wrap(function* (opts) {
*
* Example: 'D015834' returns ['D012345', 'D000926', 'D012346']
*/
MeshTree.prototype.getSiblings = co.wrap(function* (opts) {
MeshTree.prototype.getSiblings = Promise.coroutine(function* (opts) {
opts = opts || {};
let descUI = this.formatID(opts.id, 'mesh');
let format = opts.format || 'rdf';
Expand Down Expand Up @@ -504,7 +503,7 @@ MeshTree.prototype.getSiblings = co.wrap(function* (opts) {
*
* Example: ['D000926', 'D012345'] returns ['D012343']
*/
MeshTree.prototype.getCommonAncestors = co.wrap(function* (opts) {
MeshTree.prototype.getCommonAncestors = Promise.coroutine(function* (opts) {
opts = opts || {};
if (!_.isArray(opts.ids)) throw new Error('opts.ids not an array.');
let descUIArray = opts.ids.map(id => this.formatID(id, 'mesh'));
Expand Down Expand Up @@ -577,7 +576,7 @@ MeshTree.prototype.getCommonAncestors = co.wrap(function* (opts) {
/*
* Tests whether or not id2 is a descendant of id1 (child of >=1 depth)
*/
MeshTree.prototype.isDescendantOf = co.wrap(function* (id1, id2) {
MeshTree.prototype.isDescendantOf = Promise.coroutine(function* (id1, id2) {
let descUI1 = this.formatID(id1, 'mesh');
let descUI2 = this.formatID(id2, 'mesh');

Expand Down Expand Up @@ -612,7 +611,7 @@ MeshTree.prototype.isDescendantOf = co.wrap(function* (id1, id2) {
/*
* Creates a subtree from a flat list of descriptor record UIs (as `@id`s) based on parent-child relationships within the MeSH ontology tree.
*/
MeshTree.prototype.clusterDescUIs = co.wrap(function* (idArray) {
MeshTree.prototype.clusterDescUIs = Promise.coroutine(function* (idArray) {

// input must be array
if (!_.isArray(idArray)) throw new Error('input not an array.');
Expand Down Expand Up @@ -715,7 +714,7 @@ MeshTree.prototype.clusterDescUIs = co.wrap(function* (idArray) {
* Tests whether a descriptor has pharmacological actions (in other words, if the descriptor is a drug).
* If true, returns array of descUI mappings of the pharmacological action, otherwise returns null.
*/
MeshTree.prototype.getPharmacologicalAction = co.wrap(function* (opts) {
MeshTree.prototype.getPharmacologicalAction = Promise.coroutine(function* (opts) {
opts = opts || {};
let ui = this.formatID(opts.id, 'mesh');
let format = opts.format || 'rdf';
Expand All @@ -737,7 +736,7 @@ MeshTree.prototype.getPharmacologicalAction = co.wrap(function* (opts) {
/*
* Performs mapping of MeSH concepts onto Schema.org classes
*/
MeshTree.prototype.getSchemaOrgType = co.wrap(function* (opts) {
MeshTree.prototype.getSchemaOrgType = Promise.coroutine(function* (opts) {
opts = opts || {};
let ui = this.formatID(opts.id, 'mesh');

Expand Down Expand Up @@ -787,7 +786,7 @@ MeshTree.prototype.getSchemaOrgType = co.wrap(function* (opts) {
/*
* Creates properties object from descriptor id
*/
MeshTree.prototype.createPropertiesObject = co.wrap(function* (propRequestObj) {
MeshTree.prototype.createPropertiesObject = Promise.coroutine(function* (propRequestObj) {
let id = propRequestObj['@id'];
let properties = propRequestObj.properties;
let ui = id.replace(MESH, '');
Expand Down

0 comments on commit 4bbb1e3

Please sign in to comment.