fabric8-analytics-lsp-server
Advanced tools
Comparing version 0.4.18 to 0.4.19
@@ -7,3 +7,3 @@ /* -------------------------------------------------------------------------------------------- | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Dependency = exports.ValueType = exports.Variant = exports.KeyValueEntry = void 0; | ||
exports.DependencyMap = exports.SimpleDependency = exports.Dependency = exports.Variant = exports.KeyValueEntry = exports.ValueType = void 0; | ||
/* Determine what is the value */ | ||
@@ -20,4 +20,3 @@ var ValueType; | ||
ValueType[ValueType["Null"] = 7] = "Null"; | ||
})(ValueType || (ValueType = {})); | ||
exports.ValueType = ValueType; | ||
})(ValueType = exports.ValueType || (exports.ValueType = {})); | ||
; | ||
@@ -27,5 +26,7 @@ ; | ||
class KeyValueEntry { | ||
constructor(k, pos) { | ||
constructor(k, pos, v, v_pos) { | ||
this.key = k; | ||
this.key_position = pos; | ||
this.value = v; | ||
this.value_position = v_pos; | ||
} | ||
@@ -53,4 +54,23 @@ } | ||
} | ||
key() { | ||
return `${this.name.value}@${this.version.value}`; | ||
} | ||
} | ||
exports.Dependency = Dependency; | ||
/* Dependency from name, version without position */ | ||
class SimpleDependency extends Dependency { | ||
constructor(name, version) { | ||
super(new KeyValueEntry(name, null, new Variant(ValueType.String, version), null)); | ||
} | ||
} | ||
exports.SimpleDependency = SimpleDependency; | ||
class DependencyMap { | ||
constructor(deps) { | ||
this.mapper = new Map(deps.map(d => [d.key(), d])); | ||
} | ||
get(dep) { | ||
return this.mapper.get(dep.key()); | ||
} | ||
} | ||
exports.DependencyMap = DependencyMap; | ||
//# sourceMappingURL=collector.js.map |
@@ -11,5 +11,8 @@ 'use strict'; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.DependencyCollector = void 0; | ||
const jsonAst = require("json-to-ast"); | ||
const json_to_ast_1 = __importDefault(require("json-to-ast")); | ||
const collector_1 = require("../collector"); | ||
@@ -22,3 +25,3 @@ class DependencyCollector { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const ast = jsonAst(contents); | ||
const ast = json_to_ast_1.default(contents); | ||
return ast.children. | ||
@@ -25,0 +28,0 @@ filter(c => this.classes.includes(c.key.value)). |
{ | ||
"name": "fabric8-analytics-lsp-server", | ||
"description": "LSP Server for Dependency Analytics", | ||
"version": "0.4.18", | ||
"version": "0.4.19", | ||
"author": "Pavel Odvody", | ||
@@ -37,2 +37,3 @@ "contributors": [ | ||
"json-to-ast": "^2.1.0", | ||
"lru-cache": "^6.0.0", | ||
"node-fetch": "^2.6.0", | ||
@@ -45,2 +46,3 @@ "vscode-languageserver": "^5.3.0-next.9", | ||
"@types/chai": "^4.1.7", | ||
"@types/lru-cache": "^5.1.0", | ||
"@types/mocha": "^5.2.7", | ||
@@ -50,2 +52,3 @@ "@types/node": "^12.7.5", | ||
"chai": "^4.2.0", | ||
"fake-exec": "^1.1.0", | ||
"mocha": "^6.2.0", | ||
@@ -55,4 +58,3 @@ "nyc": "^14.1.1", | ||
"ts-node": "^8.3.0", | ||
"typescript": "^3.6.3", | ||
"fake-exec": "^1.1.0" | ||
"typescript": "^3.6.3" | ||
}, | ||
@@ -59,0 +61,0 @@ "scripts": { |
@@ -6,2 +6,21 @@ /* -------------------------------------------------------------------------------------------- | ||
'use strict'; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
@@ -16,6 +35,12 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const path = require("path"); | ||
const fs = require("fs"); | ||
const path = __importStar(require("path")); | ||
const fs = __importStar(require("fs")); | ||
const vscode_languageserver_1 = require("vscode-languageserver"); | ||
const node_fetch_1 = __importDefault(require("node-fetch")); | ||
const url_1 = __importDefault(require("url")); | ||
const winston_1 = __importDefault(require("winston")); | ||
const go_mod_1 = require("./collector/go.mod"); | ||
@@ -25,2 +50,3 @@ const package_json_1 = require("./collector/package.json"); | ||
const requirements_txt_1 = require("./collector/requirements.txt"); | ||
const collector_1 = require("./collector"); | ||
const consumers_1 = require("./consumers"); | ||
@@ -30,15 +56,13 @@ const aggregators_1 = require("./aggregators"); | ||
const config_1 = require("./config"); | ||
const node_fetch_1 = require("node-fetch"); | ||
const url = require('url'); | ||
const winston = require('winston'); | ||
const cache_1 = require("./cache"); | ||
let transport; | ||
try { | ||
transport = new winston.transports.File({ filename: '/workspace-logs/ls-bayesian/bayesian.log' }); | ||
transport = new winston_1.default.transports.File({ filename: '/workspace-logs/ls-bayesian/bayesian.log' }); | ||
} | ||
catch (err) { | ||
transport = new winston.transports.Console({ silent: true }); | ||
transport = new winston_1.default.transports.Console({ silent: true }); | ||
} | ||
const logger = winston.createLogger({ | ||
const logger = winston_1.default.createLogger({ | ||
level: 'debug', | ||
format: winston.format.simple(), | ||
format: winston_1.default.format.simple(), | ||
transports: [transport] | ||
@@ -108,3 +132,3 @@ }); | ||
handle_file_event(uri, contents) { | ||
let path_name = url.parse(uri).pathname; | ||
let path_name = url_1.default.parse(uri).pathname; | ||
let file_name = path.basename(path_name); | ||
@@ -115,3 +139,3 @@ this.files.file_data[uri] = contents; | ||
handle_code_lens_event(uri) { | ||
let path_name = url.parse(uri).pathname; | ||
let path_name = url_1.default.parse(uri).pathname; | ||
let file_name = path.basename(path_name); | ||
@@ -123,3 +147,5 @@ let lenses = []; | ||
} | ||
; | ||
const maxCacheItems = 1000; | ||
const maxCacheAge = 30 * 60 * 1000; | ||
const globalCache = key => cache_1.globalCache(key, maxCacheItems, maxCacheAge); | ||
let files = new AnalysisFiles(); | ||
@@ -208,5 +234,5 @@ let server = new AnalysisLSPServer(connection, files); | ||
/* Runs DiagnosticPileline to consume response and generate Diagnostic[] */ | ||
function runPipeline(response, diagnostics, packageAggregator, diagnosticFilePath, dependencyMap, totalCount) { | ||
function runPipeline(response, diagnostics, packageAggregator, diagnosticFilePath, pkgMap, totalCount) { | ||
response.forEach(r => { | ||
const dependency = dependencyMap.get(r.package + r.version); | ||
const dependency = pkgMap.get(new collector_1.SimpleDependency(r.package, r.version)); | ||
let pipeline = new consumers_1.DiagnosticsPipeline(DiagnosticsEngines, dependency, config_1.config, diagnostics, packageAggregator, diagnosticFilePath); | ||
@@ -260,9 +286,25 @@ pipeline.run(r); | ||
} | ||
const requestPayload = validPackages.map(d => ({ "package": d.name.value, "version": d.version.value })); | ||
const requestMapper = new Map(validPackages.map(d => [d.name.value + d.version.value, d])); | ||
const pkgMap = new collector_1.DependencyMap(validPackages); | ||
const batchSize = 10; | ||
let diagnostics = []; | ||
let totalCount = new TotalCount(); | ||
const diagnostics = []; | ||
const totalCount = new TotalCount(); | ||
const start = new Date().getTime(); | ||
const allRequests = slicePayload(requestPayload, batchSize, ecosystem).map(request => fetchVulnerabilities(request).then(response => runPipeline(response, diagnostics, packageAggregator, diagnosticFilePath, requestMapper, totalCount))); | ||
// Closure which captures common arg to runPipeline. | ||
const pipeline = response => runPipeline(response, diagnostics, packageAggregator, diagnosticFilePath, pkgMap, totalCount); | ||
// Get and fire diagnostics for items found in Cache. | ||
const cache = globalCache(ecosystem); | ||
const cachedItems = cache.get(validPackages); | ||
const cachedValues = cachedItems.filter(c => c.V !== undefined).map(c => c.V); | ||
const missedItems = cachedItems.filter(c => c.V === undefined).map(c => c.K); | ||
connection.console.log(`cache hit: ${cachedValues.length} miss: ${missedItems.length}`); | ||
pipeline(cachedValues); | ||
// Construct request payload for items not in Cache. | ||
const requestPayload = missedItems.map(d => ({ package: d.name.value, version: d.version.value })); | ||
// Closure which adds response into cache before firing diagnostics. | ||
const cacheAndRunPipeline = response => { | ||
cache.add(response); | ||
pipeline(response); | ||
}; | ||
const allRequests = slicePayload(requestPayload, batchSize, ecosystem). | ||
map(request => fetchVulnerabilities(request).then(cacheAndRunPipeline)); | ||
yield Promise.allSettled(allRequests); | ||
@@ -269,0 +311,0 @@ const end = new Date().getTime(); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
111920
28
1157
8
13
+ Addedlru-cache@^6.0.0
+ Addedlru-cache@6.0.0(transitive)
+ Addedyallist@4.0.0(transitive)