nodejs-nomer 1.3.2 → 1.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Dockerfile +6 -0
- package/dist/index.js +137 -0
- package/dist/result.js +48 -0
- package/dist/utils.js +76 -0
- package/docker-compose.yml +14 -0
- package/package.json +1 -1
- package/bin/nomer +0 -0
package/Dockerfile
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.Nomer = void 0;
|
|
7
|
+
var _utils = require("./utils");
|
|
8
|
+
var _result = _interopRequireDefault(require("./result"));
|
|
9
|
+
var _propertiesFile = require("properties-file");
|
|
10
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
11
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
12
|
+
function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
|
|
13
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
14
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
15
|
+
function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
|
|
16
|
+
function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
|
|
17
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
18
|
+
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
|
19
|
+
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
|
|
20
|
+
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
|
21
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
22
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
23
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
24
|
+
var Nomer = exports.Nomer = /*#__PURE__*/function () {
|
|
25
|
+
function Nomer() {
|
|
26
|
+
var propertiesPath = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
|
27
|
+
var echoOpt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "";
|
|
28
|
+
_classCallCheck(this, Nomer);
|
|
29
|
+
_defineProperty(this, "propertiesPath", null);
|
|
30
|
+
_defineProperty(this, "echoOpt", "");
|
|
31
|
+
this.propertiesPath = propertiesPath;
|
|
32
|
+
this.echoOpt = echoOpt;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Show version
|
|
37
|
+
* @returns string
|
|
38
|
+
*/
|
|
39
|
+
return _createClass(Nomer, [{
|
|
40
|
+
key: "version",
|
|
41
|
+
value: function version() {
|
|
42
|
+
var res = (0, _utils.runNomer)((0, _utils.getNomerSimpleCmd)());
|
|
43
|
+
return res;
|
|
44
|
+
}
|
|
45
|
+
}, {
|
|
46
|
+
key: "clean",
|
|
47
|
+
value: function clean() {
|
|
48
|
+
var res = (0, _utils.runNomer)((0, _utils.getNomerSimpleCmd)("clean", false, this.getPropertiesPath()));
|
|
49
|
+
return res;
|
|
50
|
+
}
|
|
51
|
+
}, {
|
|
52
|
+
key: "inputSchema",
|
|
53
|
+
value: function inputSchema() {
|
|
54
|
+
var res = (0, _utils.runNomer)((0, _utils.getNomerSimpleCmd)("input-schema", false, this.getPropertiesPath()));
|
|
55
|
+
return res;
|
|
56
|
+
}
|
|
57
|
+
}, {
|
|
58
|
+
key: "outputSchema",
|
|
59
|
+
value: function outputSchema() {
|
|
60
|
+
var res = (0, _utils.runNomer)((0, _utils.getNomerSimpleCmd)("output-schema", false, this.getPropertiesPath()));
|
|
61
|
+
return res;
|
|
62
|
+
}
|
|
63
|
+
}, {
|
|
64
|
+
key: "properties",
|
|
65
|
+
value: function properties() {
|
|
66
|
+
var res = (0, _utils.runNomer)((0, _utils.getNomerSimpleCmd)("properties", false, this.getPropertiesPath()));
|
|
67
|
+
return res;
|
|
68
|
+
}
|
|
69
|
+
}, {
|
|
70
|
+
key: "matcher",
|
|
71
|
+
value: function matcher() {
|
|
72
|
+
var outputFormat = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "tsv";
|
|
73
|
+
var verbose = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
74
|
+
var res = (0, _utils.runNomer)((0, _utils.getNomerSimpleCmd)("matchers", verbose, null, outputFormat));
|
|
75
|
+
return res;
|
|
76
|
+
}
|
|
77
|
+
}, {
|
|
78
|
+
key: "validateTerm",
|
|
79
|
+
value: function validateTerm() {
|
|
80
|
+
var filepath = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "";
|
|
81
|
+
var res = (0, _utils.runNomer)((0, _utils.getNomerValidateCmd)(filepath, "validate-term-link", this.getPropertiesPath()));
|
|
82
|
+
return res;
|
|
83
|
+
}
|
|
84
|
+
}, {
|
|
85
|
+
key: "replace",
|
|
86
|
+
value: function replace() {
|
|
87
|
+
var query = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "";
|
|
88
|
+
var matcher = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "globi-taxon-cache";
|
|
89
|
+
var res = (0, _utils.runNomer)((0, _utils.getNomerMatchCmd)(query, "replace", matcher, this.getPropertiesPath(), null, this.echoOpt));
|
|
90
|
+
return res;
|
|
91
|
+
}
|
|
92
|
+
}, {
|
|
93
|
+
key: "append",
|
|
94
|
+
value: function append() {
|
|
95
|
+
var query = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "";
|
|
96
|
+
var matcher = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "globi-taxon-cache";
|
|
97
|
+
var outputFormat = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "tsv";
|
|
98
|
+
var res = (0, _utils.runNomer)((0, _utils.getNomerMatchCmd)(query, "append", matcher, this.getPropertiesPath(), outputFormat, this.echoOpt), query);
|
|
99
|
+
return res;
|
|
100
|
+
}
|
|
101
|
+
}, {
|
|
102
|
+
key: "appendAsync",
|
|
103
|
+
value: function appendAsync() {
|
|
104
|
+
var matcher = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "globi-taxon-cache";
|
|
105
|
+
var outputFormat = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "tsv";
|
|
106
|
+
return (0, _utils.runNomerAsync)("nomer append ".concat(matcher, " -o ").concat(outputFormat));
|
|
107
|
+
}
|
|
108
|
+
}, {
|
|
109
|
+
key: "getPropertiesPath",
|
|
110
|
+
value: function getPropertiesPath() {
|
|
111
|
+
return this.propertiesPath;
|
|
112
|
+
}
|
|
113
|
+
}, {
|
|
114
|
+
key: "toJson",
|
|
115
|
+
value: function toJson(result) {
|
|
116
|
+
return _result["default"].json(result);
|
|
117
|
+
}
|
|
118
|
+
}, {
|
|
119
|
+
key: "toArray",
|
|
120
|
+
value: function toArray(result) {
|
|
121
|
+
return _result["default"].tsv(result);
|
|
122
|
+
}
|
|
123
|
+
}, {
|
|
124
|
+
key: "toObject",
|
|
125
|
+
value: function toObject(result) {
|
|
126
|
+
var content = this.properties(this.getPropertiesPath());
|
|
127
|
+
var properties = (0, _propertiesFile.getProperties)(content);
|
|
128
|
+
var schemaInput = JSON.parse(properties["nomer.schema.input"]).map(function (i) {
|
|
129
|
+
return i.type + 'Input';
|
|
130
|
+
});
|
|
131
|
+
var schemaAppend = JSON.parse(properties["nomer.append.schema.output"]).map(function (i) {
|
|
132
|
+
return i.type;
|
|
133
|
+
});
|
|
134
|
+
return _result["default"].tsv(result, [].concat(_toConsumableArray(schemaInput), ["matchType"], _toConsumableArray(schemaAppend)));
|
|
135
|
+
}
|
|
136
|
+
}]);
|
|
137
|
+
}();
|
package/dist/result.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.Result = void 0;
|
|
7
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
8
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
9
|
+
function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
|
|
10
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
11
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
12
|
+
function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
|
|
13
|
+
function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
|
|
14
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
15
|
+
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
|
16
|
+
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
|
|
17
|
+
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
|
18
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
19
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
20
|
+
var Result = exports.Result = /*#__PURE__*/function () {
|
|
21
|
+
function Result() {
|
|
22
|
+
_classCallCheck(this, Result);
|
|
23
|
+
}
|
|
24
|
+
return _createClass(Result, null, [{
|
|
25
|
+
key: "json",
|
|
26
|
+
value: function json(result) {
|
|
27
|
+
var arr = [];
|
|
28
|
+
result.split("\n").forEach(function (e) {
|
|
29
|
+
return arr.push(JSON.parse(e));
|
|
30
|
+
});
|
|
31
|
+
return arr;
|
|
32
|
+
}
|
|
33
|
+
}, {
|
|
34
|
+
key: "tsv",
|
|
35
|
+
value: function tsv(result) {
|
|
36
|
+
var columns = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
37
|
+
var arr = [];
|
|
38
|
+
result.split('\n').forEach(function (line) {
|
|
39
|
+
arr.push(line.split('\t'));
|
|
40
|
+
});
|
|
41
|
+
return columns ? arr.map(function (v) {
|
|
42
|
+
return Object.assign.apply(Object, _toConsumableArray(columns.map(function (k, i) {
|
|
43
|
+
return _defineProperty({}, k, v[i]);
|
|
44
|
+
})));
|
|
45
|
+
}) : arr;
|
|
46
|
+
}
|
|
47
|
+
}]);
|
|
48
|
+
}();
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.runNomerAsync = exports.runNomer = exports.getNomerValidateCmd = exports.getNomerSimpleCmd = exports.getNomerMatchCmd = void 0;
|
|
7
|
+
var _require = require('child_process'),
|
|
8
|
+
execSync = _require.execSync,
|
|
9
|
+
spawn = _require.spawn;
|
|
10
|
+
var getNomerValidateCmd = exports.getNomerValidateCmd = function getNomerValidateCmd() {
|
|
11
|
+
var filepath = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "";
|
|
12
|
+
var cmd = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "validate-term";
|
|
13
|
+
var properties = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
|
14
|
+
if (filepath === "") {
|
|
15
|
+
throw new Exception("Filepath cannot be empty string");
|
|
16
|
+
}
|
|
17
|
+
var nomerCmd = "curl -L ".concat(filepath, " | nomer ").concat(cmd);
|
|
18
|
+
if (properties) {
|
|
19
|
+
nomerCmd = "".concat(nomerCmd, " -p ").concat(properties);
|
|
20
|
+
}
|
|
21
|
+
return nomerCmd;
|
|
22
|
+
};
|
|
23
|
+
var getNomerMatchCmd = exports.getNomerMatchCmd = function getNomerMatchCmd() {
|
|
24
|
+
var query = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "";
|
|
25
|
+
var cmd = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "append";
|
|
26
|
+
var matcher = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "globi-taxon-cache";
|
|
27
|
+
var properties = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
|
|
28
|
+
var outputFormat = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : null;
|
|
29
|
+
var echoOpt = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : "-e";
|
|
30
|
+
var nomerCmd = "echo ".concat(echoOpt, " '").concat(query, "' | nomer ").concat(cmd, " ").concat(matcher);
|
|
31
|
+
if (properties) {
|
|
32
|
+
nomerCmd = "".concat(nomerCmd, " -p ").concat(properties);
|
|
33
|
+
}
|
|
34
|
+
if (outputFormat) {
|
|
35
|
+
nomerCmd = "".concat(nomerCmd, " -o ").concat(outputFormat);
|
|
36
|
+
}
|
|
37
|
+
return nomerCmd;
|
|
38
|
+
};
|
|
39
|
+
var getNomerSimpleCmd = exports.getNomerSimpleCmd = function getNomerSimpleCmd() {
|
|
40
|
+
var cmd = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "version";
|
|
41
|
+
var verbose = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
42
|
+
var properties = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
|
43
|
+
var outputFormat = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
|
|
44
|
+
var nomerCmd = "nomer ".concat(cmd);
|
|
45
|
+
if (properties) {
|
|
46
|
+
nomerCmd = "".concat(nomerCmd, " -p ").concat(properties);
|
|
47
|
+
}
|
|
48
|
+
if (outputFormat) {
|
|
49
|
+
nomerCmd = "".concat(nomerCmd, " -o ").concat(outputFormat);
|
|
50
|
+
}
|
|
51
|
+
if (verbose) {
|
|
52
|
+
nomerCmd = "".concat(nomerCmd, " -v");
|
|
53
|
+
}
|
|
54
|
+
return nomerCmd;
|
|
55
|
+
};
|
|
56
|
+
var runNomer = exports.runNomer = function runNomer(nomerCmd) {
|
|
57
|
+
try {
|
|
58
|
+
var result = execSync(nomerCmd, {
|
|
59
|
+
maxBuffer: 4096 * 4096
|
|
60
|
+
}).toString();
|
|
61
|
+
if (result) {
|
|
62
|
+
return result.trimEnd();
|
|
63
|
+
}
|
|
64
|
+
} catch (error) {
|
|
65
|
+
console.log("Error running nomer cmd: " + error.message);
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
var runNomerAsync = exports.runNomerAsync = function runNomerAsync(nomerCmd) {
|
|
70
|
+
var nomerCmdArr = nomerCmd.split(/\s+/);
|
|
71
|
+
var p = spawn(nomerCmdArr[0], nomerCmdArr.slice(1), {
|
|
72
|
+
// maxBuffer: 4096 * 4096
|
|
73
|
+
shell: true
|
|
74
|
+
});
|
|
75
|
+
return p;
|
|
76
|
+
};
|
package/package.json
CHANGED
package/bin/nomer
DELETED
|
Binary file
|